2023-01-19 19:19:06 +02:00
|
|
|
import * as React from 'react';
|
2020-10-21 11:39:53 +02:00
|
|
|
import ToolbarButton from './ToolbarButton/ToolbarButton';
|
|
|
|
import ToggleEditorsButton, { Value } from './ToggleEditorsButton/ToggleEditorsButton';
|
2023-01-19 19:19:06 +02:00
|
|
|
import ToolbarSpace from './ToolbarSpace';
|
2017-11-30 01:03:10 +02:00
|
|
|
const { connect } = require('react-redux');
|
2020-11-07 17:59:37 +02:00
|
|
|
const { themeStyle } = require('@joplin/lib/theme');
|
2017-11-30 01:03:10 +02:00
|
|
|
|
2020-09-23 11:21:24 +02:00
|
|
|
interface Props {
|
2020-11-12 21:29:22 +02:00
|
|
|
themeId: number;
|
|
|
|
style: any;
|
|
|
|
items: any[];
|
2023-07-16 18:42:42 +02:00
|
|
|
disabled: boolean;
|
2020-09-23 11:21:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class ToolbarBaseComponent extends React.Component<Props, any> {
|
|
|
|
|
2023-03-06 16:22:01 +02:00
|
|
|
public render() {
|
2020-09-15 15:01:07 +02:00
|
|
|
const theme = themeStyle(this.props.themeId);
|
2020-05-03 19:44:49 +02:00
|
|
|
|
2023-06-01 13:02:36 +02:00
|
|
|
const style: any = { display: 'flex',
|
2020-05-03 19:44:49 +02:00
|
|
|
flexDirection: 'row',
|
|
|
|
boxSizing: 'border-box',
|
2020-09-15 15:01:07 +02:00
|
|
|
backgroundColor: theme.backgroundColor3,
|
|
|
|
padding: theme.toolbarPadding,
|
2023-06-01 13:02:36 +02:00
|
|
|
paddingRight: theme.mainPadding, ...this.props.style };
|
2017-11-30 01:03:10 +02:00
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
const groupStyle: any = {
|
2020-09-15 15:01:07 +02:00
|
|
|
display: 'flex',
|
|
|
|
flexDirection: 'row',
|
|
|
|
boxSizing: 'border-box',
|
|
|
|
};
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
const leftItemComps: any[] = [];
|
|
|
|
const centerItemComps: any[] = [];
|
|
|
|
const rightItemComps: any[] = [];
|
2017-11-30 01:03:10 +02:00
|
|
|
|
|
|
|
if (this.props.items) {
|
|
|
|
for (let i = 0; i < this.props.items.length; i++) {
|
|
|
|
const o = this.props.items[i];
|
|
|
|
let key = o.iconName ? o.iconName : '';
|
|
|
|
key += o.title ? o.title : '';
|
2020-11-20 18:19:57 +02:00
|
|
|
key += o.name ? o.name : '';
|
2017-11-30 01:03:10 +02:00
|
|
|
const itemType = !('type' in o) ? 'button' : o.type;
|
|
|
|
|
2019-09-19 23:51:18 +02:00
|
|
|
if (!key) key = `${o.type}_${i}`;
|
2018-06-14 09:52:12 +02:00
|
|
|
|
2023-06-01 13:02:36 +02:00
|
|
|
const props = {
|
|
|
|
key: key,
|
|
|
|
themeId: this.props.themeId,
|
2023-07-16 18:42:42 +02:00
|
|
|
disabled: this.props.disabled,
|
2023-06-01 13:02:36 +02:00
|
|
|
...o,
|
|
|
|
};
|
2017-11-30 01:03:10 +02:00
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
if (o.name === 'toggleEditors') {
|
|
|
|
rightItemComps.push(<ToggleEditorsButton
|
|
|
|
key={o.name}
|
2020-10-21 11:39:53 +02:00
|
|
|
value={Value.Markdown}
|
2020-09-15 15:01:07 +02:00
|
|
|
themeId={this.props.themeId}
|
|
|
|
toolbarButtonInfo={o}
|
|
|
|
/>);
|
|
|
|
} else if (itemType === 'button') {
|
2020-10-10 14:32:30 +02:00
|
|
|
const target = ['historyForward', 'historyBackward', 'toggleExternalEditing'].includes(o.name) ? leftItemComps : centerItemComps;
|
2020-09-15 15:01:07 +02:00
|
|
|
target.push(<ToolbarButton {...props} />);
|
2018-06-14 09:52:12 +02:00
|
|
|
} else if (itemType === 'separator') {
|
2020-09-15 15:01:07 +02:00
|
|
|
centerItemComps.push(<ToolbarSpace {...props} />);
|
2017-11-30 01:03:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="editor-toolbar" style={style}>
|
2020-09-15 15:01:07 +02:00
|
|
|
<div style={groupStyle}>
|
|
|
|
{leftItemComps}
|
|
|
|
</div>
|
|
|
|
<div style={groupStyle}>
|
|
|
|
{centerItemComps}
|
|
|
|
</div>
|
2023-06-01 13:02:36 +02:00
|
|
|
<div style={{ ...groupStyle, flex: 1, justifyContent: 'flex-end' }}>
|
2020-09-15 15:01:07 +02:00
|
|
|
{rightItemComps}
|
|
|
|
</div>
|
2017-11-30 01:03:10 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
const mapStateToProps = (state: any) => {
|
2020-09-15 15:01:07 +02:00
|
|
|
return { themeId: state.settings.theme };
|
2017-11-30 01:03:10 +02:00
|
|
|
};
|
|
|
|
|
2020-09-23 11:21:24 +02:00
|
|
|
export default connect(mapStateToProps)(ToolbarBaseComponent);
|