2020-05-02 17:41:07 +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';
|
|
|
|
import ToolbarButtonUtils, { ToolbarButtonInfo } from '@joplin/lib/services/commands/ToolbarButtonUtils';
|
2020-11-13 19:09:28 +02:00
|
|
|
import stateToWhenClauseContext from '../../services/commands/stateToWhenClauseContext';
|
2020-05-03 19:44:49 +02:00
|
|
|
const { connect } = require('react-redux');
|
2024-04-11 09:35:20 +02:00
|
|
|
import { buildStyle } from '@joplin/lib/theme';
|
2024-08-03 17:42:46 +02:00
|
|
|
import { _ } from '@joplin/lib/locale';
|
2020-05-02 17:41:07 +02:00
|
|
|
|
|
|
|
interface NoteToolbarProps {
|
2020-11-12 21:29:22 +02:00
|
|
|
themeId: number;
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-12 21:29:22 +02:00
|
|
|
style: any;
|
|
|
|
toolbarButtonInfos: ToolbarButtonInfo[];
|
2023-07-16 18:42:42 +02:00
|
|
|
disabled: boolean;
|
2020-05-02 17:41:07 +02:00
|
|
|
}
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
function styles_(props: NoteToolbarProps) {
|
2024-04-11 09:35:20 +02:00
|
|
|
return buildStyle('NoteToolbar', props.themeId, theme => {
|
2020-05-02 17:41:07 +02:00
|
|
|
return {
|
|
|
|
root: {
|
|
|
|
...props.style,
|
2020-05-03 19:44:49 +02:00
|
|
|
borderBottom: 'none',
|
2020-09-15 15:01:07 +02:00
|
|
|
backgroundColor: theme.backgroundColor,
|
2020-05-02 17:41:07 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
function NoteToolbar(props: NoteToolbarProps) {
|
2020-07-03 23:32:39 +02:00
|
|
|
const styles = styles_(props);
|
2024-08-03 17:42:46 +02:00
|
|
|
return (
|
|
|
|
<ToolbarBase
|
|
|
|
style={styles.root}
|
|
|
|
items={props.toolbarButtonInfos}
|
|
|
|
disabled={props.disabled}
|
|
|
|
aria-label={_('Note')}
|
|
|
|
/>
|
|
|
|
);
|
2020-05-02 17:41:07 +02:00
|
|
|
}
|
2020-05-03 19:44:49 +02:00
|
|
|
|
2020-10-09 19:35:46 +02:00
|
|
|
const toolbarButtonUtils = new ToolbarButtonUtils(CommandService.instance());
|
|
|
|
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-12 21:13:28 +02:00
|
|
|
const mapStateToProps = (state: any) => {
|
2020-10-18 22:52:10 +02:00
|
|
|
const whenClauseContext = stateToWhenClauseContext(state);
|
|
|
|
|
2020-05-03 19:44:49 +02:00
|
|
|
return {
|
2020-10-18 22:52:10 +02:00
|
|
|
toolbarButtonInfos: toolbarButtonUtils.commandsToToolbarButtons([
|
2020-11-08 03:08:33 +02:00
|
|
|
'showSpellCheckerMenu',
|
2020-10-09 19:35:46 +02:00
|
|
|
'editAlarm',
|
|
|
|
'toggleVisiblePanes',
|
|
|
|
'showNoteProperties',
|
2020-10-18 22:52:10 +02:00
|
|
|
].concat(pluginUtils.commandNamesFromViews(state.pluginService.plugins, 'noteToolbar')), whenClauseContext),
|
2020-05-03 19:44:49 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(NoteToolbar);
|