@progress/kendo-angular-editor
Version:
Kendo UI Editor for Angular
63 lines (62 loc) • 4.45 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the project root for more information
*-------------------------------------------------------------------------------------------*/
import { alignBlocks, alignLeftRules, alignCenterRules, alignRightRules, alignJustifyRules, alignRemoveRules, indent, outdent, setHtml, getHtml, insertImage, insertText, applyLink, removeLink, expandToWordWrap, blockquote,
//marks
bold, italic, underline, strikethrough, subscript, superscript, link, toggleInlineFormat, applyInlineStyle, formatBlockElements, toggleOrderedList, toggleUnorderedList, isAligned, undo, redo, cleanFormatting, selectAll, addColumnBefore, addColumnAfter, addRowBefore, addRowAfter, deleteRow, deleteColumn, deleteTable, mergeCells, splitCell } from '@progress/kendo-editor-common';
import { insertTable } from './table-commands';
const alignRemove = (state, dispatch) => alignBlocks(alignRemoveRules)(state, dispatch);
const inlineCommand = {
bold: (applyToWord) => expandToWordWrap(toggleInlineFormat, { ...bold, applyToWord }),
cleanFormatting: (options) => cleanFormatting(options),
createLink: attrs => expandToWordWrap(applyLink, { mark: 'link', attrs: attrs.value, applyToWord: attrs.applyToWord }),
fontFamily: attrs => expandToWordWrap(applyInlineStyle, { style: 'font-family', value: attrs.value, applyToWord: attrs.applyToWord }),
fontSize: attrs => expandToWordWrap(applyInlineStyle, { style: 'font-size', value: attrs.value, applyToWord: attrs.applyToWord }),
insertFile: attrs => expandToWordWrap(applyLink, { mark: 'link', attrs: attrs, applyToWord: attrs.applyToWord }),
insertText: text => insertText(text),
italic: (applyToWord) => expandToWordWrap(toggleInlineFormat, { ...italic, applyToWord }),
strikethrough: (applyToWord) => expandToWordWrap(toggleInlineFormat, { ...strikethrough, applyToWord }),
subscript: (applyToWord) => expandToWordWrap(toggleInlineFormat, { ...subscript, applyToWord }),
superscript: (applyToWord) => expandToWordWrap(toggleInlineFormat, { ...superscript, applyToWord }),
underline: (applyToWord) => expandToWordWrap(toggleInlineFormat, { ...underline, applyToWord }),
unlink: () => removeLink(link),
foreColor: attrs => expandToWordWrap(applyInlineStyle, { style: 'color', value: attrs.value, applyToWord: attrs.applyToWord }),
backColor: attrs => expandToWordWrap(applyInlineStyle, { style: 'background-color', value: attrs.value, applyToWord: attrs.applyToWord }),
selectAll: () => (state, dispatch) => selectAll(state, dispatch)
};
const blockCommand = {
alignCenter: () => (state, dispatch) => isAligned(state, alignCenterRules) ? alignRemove(state, dispatch) : alignBlocks(alignCenterRules)(state, dispatch),
alignJustify: () => (state, dispatch) => isAligned(state, alignJustifyRules) ? alignRemove(state, dispatch) : alignBlocks(alignJustifyRules)(state, dispatch),
alignLeft: () => (state, dispatch) => isAligned(state, alignLeftRules) ? alignRemove(state, dispatch) : alignBlocks(alignLeftRules)(state, dispatch),
alignRight: () => (state, dispatch) => isAligned(state, alignRightRules) ? alignRemove(state, dispatch) : alignBlocks(alignRightRules)(state, dispatch),
format: formatAttr => formatBlockElements(formatAttr.tag),
getHTML: () => getHtml,
indent: () => indent,
insertImage: attrs => insertImage(attrs),
// think about changing the command name.
insertOrderedList: () => toggleOrderedList,
// think about changing the command name.
insertUnorderedList: () => toggleUnorderedList,
outdent: () => outdent,
redo: () => redo,
setHTML: ({ content, parseOptions }) => setHtml(content, 'setHTML', parseOptions),
undo: () => undo,
blockquote: () => blockquote
};
const tableCommand = {
insertTable: attr => insertTable(attr),
addColumnBefore: () => addColumnBefore,
addColumnAfter: () => addColumnAfter,
addRowBefore: () => addRowBefore,
addRowAfter: () => addRowAfter,
deleteRow: () => deleteRow,
deleteColumn: () => deleteColumn,
mergeCells: () => mergeCells,
splitCell: () => splitCell,
deleteTable: () => deleteTable
};
/**
* @hidden
*/
export const editorCommands = Object.assign({}, inlineCommand, blockCommand, tableCommand);