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