2020-06-06 17:00:20 +02:00
|
|
|
import * as React from 'react';
|
2020-11-07 17:59:37 +02:00
|
|
|
import CommandService from '@joplin/lib/services/CommandService';
|
2020-09-23 11:21:24 +02:00
|
|
|
import ToolbarBase from '../../../ToolbarBase';
|
2020-11-07 17:59:37 +02:00
|
|
|
import { utils as pluginUtils } from '@joplin/lib/services/plugins/reducer';
|
2020-10-09 19:35:46 +02:00
|
|
|
import { connect } from 'react-redux';
|
2021-09-04 19:11:29 +02:00
|
|
|
import { AppState } from '../../../../app.reducer';
|
2020-11-07 17:59:37 +02:00
|
|
|
import ToolbarButtonUtils, { ToolbarButtonInfo } from '@joplin/lib/services/commands/ToolbarButtonUtils';
|
2020-11-13 19:09:28 +02:00
|
|
|
import stateToWhenClauseContext from '../../../../services/commands/stateToWhenClauseContext';
|
2020-11-07 17:59:37 +02:00
|
|
|
const { buildStyle } = require('@joplin/lib/theme');
|
2020-06-06 17:00:20 +02:00
|
|
|
|
|
|
|
interface ToolbarProps {
|
2020-11-12 21:29:22 +02:00
|
|
|
themeId: number;
|
|
|
|
toolbarButtonInfos: ToolbarButtonInfo[];
|
2023-07-16 18:42:42 +02:00
|
|
|
disabled?: boolean;
|
2020-06-06 17:00:20 +02:00
|
|
|
}
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
function styles_(props: ToolbarProps) {
|
2020-09-15 15:01:07 +02:00
|
|
|
return buildStyle('CodeMirrorToolbar', props.themeId, () => {
|
2020-06-06 17:00:20 +02:00
|
|
|
return {
|
|
|
|
root: {
|
|
|
|
flex: 1,
|
|
|
|
marginBottom: 0,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-09 19:35:46 +02:00
|
|
|
const toolbarButtonUtils = new ToolbarButtonUtils(CommandService.instance());
|
2020-09-15 15:01:07 +02:00
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
function Toolbar(props: ToolbarProps) {
|
2020-10-09 19:35:46 +02:00
|
|
|
const styles = styles_(props);
|
2023-07-16 18:42:42 +02:00
|
|
|
return <ToolbarBase style={styles.root} items={props.toolbarButtonInfos} disabled={!!props.disabled} />;
|
2020-06-06 17:00:20 +02:00
|
|
|
}
|
2020-10-09 19:35:46 +02:00
|
|
|
|
|
|
|
const mapStateToProps = (state: AppState) => {
|
2020-10-18 22:52:10 +02:00
|
|
|
const whenClauseContext = stateToWhenClauseContext(state);
|
|
|
|
|
2020-10-09 19:35:46 +02:00
|
|
|
const commandNames = [
|
|
|
|
'historyBackward',
|
|
|
|
'historyForward',
|
2020-10-10 14:32:30 +02:00
|
|
|
'toggleExternalEditing',
|
2020-10-09 19:35:46 +02:00
|
|
|
'-',
|
|
|
|
'textBold',
|
|
|
|
'textItalic',
|
|
|
|
'-',
|
|
|
|
'textLink',
|
|
|
|
'textCode',
|
|
|
|
'attachFile',
|
|
|
|
'-',
|
|
|
|
'textBulletedList',
|
2020-10-21 11:39:53 +02:00
|
|
|
'textNumberedList',
|
2020-10-09 19:35:46 +02:00
|
|
|
'textCheckbox',
|
|
|
|
'textHeading',
|
|
|
|
'textHorizontalRule',
|
|
|
|
'insertDateTime',
|
|
|
|
'toggleEditors',
|
|
|
|
].concat(pluginUtils.commandNamesFromViews(state.pluginService.plugins, 'editorToolbar'));
|
|
|
|
|
|
|
|
return {
|
2020-10-18 22:52:10 +02:00
|
|
|
toolbarButtonInfos: toolbarButtonUtils.commandsToToolbarButtons(commandNames, whenClauseContext),
|
2020-10-09 19:35:46 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(Toolbar);
|