2017-11-30 01:03:10 +02:00
|
|
|
const React = require('react');
|
|
|
|
const { connect } = require('react-redux');
|
2020-06-10 23:08:59 +02:00
|
|
|
const { themeStyle } = require('lib/theme');
|
2020-09-15 15:01:07 +02:00
|
|
|
const ToolbarButton = require('./ToolbarButton/ToolbarButton.js').default;
|
2018-06-14 09:52:12 +02:00
|
|
|
const ToolbarSpace = require('./ToolbarSpace.min.js');
|
2020-09-15 15:01:07 +02:00
|
|
|
const ToggleEditorsButton = require('./ToggleEditorsButton/ToggleEditorsButton.js').default;
|
2017-11-30 01:03:10 +02:00
|
|
|
|
2020-09-23 11:21:24 +02:00
|
|
|
interface Props {
|
|
|
|
themeId: number,
|
|
|
|
style: any,
|
|
|
|
items: any[],
|
|
|
|
}
|
|
|
|
|
|
|
|
class ToolbarBaseComponent extends React.Component<Props, any> {
|
|
|
|
|
2017-11-30 01:03:10 +02:00
|
|
|
render() {
|
2020-09-15 15:01:07 +02:00
|
|
|
const theme = themeStyle(this.props.themeId);
|
2020-05-03 19:44:49 +02:00
|
|
|
|
2020-09-23 11:21:24 +02:00
|
|
|
const style:any = Object.assign({
|
2020-05-03 19:44:49 +02:00
|
|
|
display: 'flex',
|
|
|
|
flexDirection: 'row',
|
|
|
|
boxSizing: 'border-box',
|
2020-09-15 15:01:07 +02:00
|
|
|
backgroundColor: theme.backgroundColor3,
|
|
|
|
padding: theme.toolbarPadding,
|
|
|
|
paddingRight: theme.mainPadding,
|
2020-05-03 19:44:49 +02:00
|
|
|
}, this.props.style);
|
2017-11-30 01:03:10 +02:00
|
|
|
|
2020-09-23 11:21:24 +02:00
|
|
|
const groupStyle:any = {
|
2020-09-15 15:01:07 +02:00
|
|
|
display: 'flex',
|
|
|
|
flexDirection: 'row',
|
|
|
|
boxSizing: 'border-box',
|
|
|
|
};
|
|
|
|
|
2020-09-23 11:21:24 +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 : '';
|
|
|
|
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
|
|
|
|
2019-07-29 14:13:23 +02:00
|
|
|
const props = Object.assign(
|
|
|
|
{
|
|
|
|
key: key,
|
2020-09-15 15:01:07 +02:00
|
|
|
themeId: this.props.themeId,
|
2019-07-29 14:13:23 +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}
|
|
|
|
value={'markdown'}
|
|
|
|
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>
|
|
|
|
<div style={Object.assign({}, groupStyle, { flex: 1, justifyContent: 'flex-end' })}>
|
|
|
|
{rightItemComps}
|
|
|
|
</div>
|
2017-11-30 01:03:10 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-23 11:21:24 +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);
|