2024-12-11 14:31:05 +02:00
|
|
|
import { EditorCommandType } from '@joplin/editor/types';
|
|
|
|
import { _ } from '@joplin/lib/locale';
|
2024-03-11 17:02:15 +02:00
|
|
|
import { CommandDeclaration } from '@joplin/lib/services/CommandService';
|
|
|
|
|
|
|
|
export const enabledCondition = (_commandName: string) => {
|
|
|
|
const output = [
|
|
|
|
'!noteIsReadOnly',
|
|
|
|
];
|
|
|
|
|
|
|
|
return output.filter(c => !!c).join(' && ');
|
|
|
|
};
|
|
|
|
|
2024-12-11 14:31:05 +02:00
|
|
|
const headerDeclarations = () => {
|
|
|
|
const result: CommandDeclaration[] = [];
|
|
|
|
for (let level = 1; level <= 5; level++) {
|
|
|
|
result.push({
|
|
|
|
name: `editor.textHeading${level}`,
|
|
|
|
iconName: `material format-header-${level}`,
|
|
|
|
label: () => _('Header %d', level),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
2024-03-11 17:02:15 +02:00
|
|
|
const declarations: CommandDeclaration[] = [
|
|
|
|
{
|
|
|
|
name: 'insertText',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'editor.undo',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'editor.redo',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'selectedText',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'replaceSelection',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'editor.setText',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'editor.focus',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'editor.execCommand',
|
|
|
|
},
|
2024-12-11 14:31:05 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
name: EditorCommandType.ToggleBolded,
|
|
|
|
label: () => _('Bold'),
|
|
|
|
iconName: 'material format-bold',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: EditorCommandType.ToggleItalicized,
|
|
|
|
label: () => _('Italic'),
|
|
|
|
iconName: 'material format-italic',
|
|
|
|
},
|
|
|
|
...headerDeclarations(),
|
|
|
|
{
|
|
|
|
name: EditorCommandType.ToggleCode,
|
|
|
|
label: () => _('Code'),
|
|
|
|
iconName: 'material code-json',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// The 'editor.' prefix needs to be included because ToggleMath is not a legacy
|
|
|
|
// editor command. Without this, ToggleMath is not recognised as an editor command.
|
|
|
|
name: `editor.${EditorCommandType.ToggleMath}`,
|
|
|
|
label: () => _('Math'),
|
|
|
|
iconName: 'material sigma',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: EditorCommandType.ToggleNumberedList,
|
|
|
|
label: () => _('Ordered list'),
|
|
|
|
iconName: 'material format-list-numbered',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: EditorCommandType.ToggleBulletedList,
|
|
|
|
label: () => _('Unordered list'),
|
|
|
|
iconName: 'material format-list-bulleted',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: EditorCommandType.ToggleCheckList,
|
|
|
|
label: () => _('Task list'),
|
|
|
|
iconName: 'material format-list-checks',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: EditorCommandType.IndentLess,
|
|
|
|
label: () => _('Decrease indent level'),
|
|
|
|
iconName: 'ant indent-left',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: EditorCommandType.IndentMore,
|
|
|
|
label: () => _('Increase indent level'),
|
|
|
|
iconName: 'ant indent-right',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: EditorCommandType.ToggleSearch,
|
|
|
|
label: () => _('Search'),
|
|
|
|
iconName: 'material magnify',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: EditorCommandType.EditLink,
|
|
|
|
label: () => _('Link'),
|
|
|
|
iconName: 'material link',
|
|
|
|
},
|
2024-03-11 17:02:15 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
export default declarations;
|