@pega/cosmos-react-rte 2.0.0-dev.9.2 → 2.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.js +2 -2
- package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.js.map +1 -1
- package/lib/components/RichTextEditor/DecoratorComponents/Image.js +1 -1
- package/lib/components/RichTextEditor/DecoratorComponents/Image.js.map +1 -1
- package/lib/components/RichTextEditor/DecoratorComponents/Link.js +1 -1
- package/lib/components/RichTextEditor/DecoratorComponents/Link.js.map +1 -1
- package/lib/components/RichTextEditor/DecoratorComponents/Table.d.ts +2 -0
- package/lib/components/RichTextEditor/DecoratorComponents/Table.d.ts.map +1 -1
- package/lib/components/RichTextEditor/DecoratorComponents/Table.js +8 -7
- package/lib/components/RichTextEditor/DecoratorComponents/Table.js.map +1 -1
- package/lib/components/RichTextEditor/RichTextEditor.context.d.ts +3 -3
- package/lib/components/RichTextEditor/RichTextEditor.context.d.ts.map +1 -1
- package/lib/components/RichTextEditor/RichTextEditor.context.js +1 -1
- package/lib/components/RichTextEditor/RichTextEditor.context.js.map +1 -1
- package/lib/components/RichTextEditor/RichTextEditor.d.ts.map +1 -1
- package/lib/components/RichTextEditor/RichTextEditor.js +91 -65
- package/lib/components/RichTextEditor/RichTextEditor.js.map +1 -1
- package/lib/components/RichTextEditor/RichTextEditor.styles.d.ts +3 -0
- package/lib/components/RichTextEditor/RichTextEditor.styles.d.ts.map +1 -1
- package/lib/components/RichTextEditor/RichTextEditor.styles.js +121 -51
- package/lib/components/RichTextEditor/RichTextEditor.styles.js.map +1 -1
- package/lib/components/RichTextEditor/RichTextEditor.types.d.ts +29 -1
- package/lib/components/RichTextEditor/RichTextEditor.types.d.ts.map +1 -1
- package/lib/components/RichTextEditor/RichTextEditor.types.js.map +1 -1
- package/lib/components/RichTextEditor/RichTextViewer.d.ts.map +1 -1
- package/lib/components/RichTextEditor/RichTextViewer.js +18 -7
- package/lib/components/RichTextEditor/RichTextViewer.js.map +1 -1
- package/lib/components/RichTextEditor/RichTextViewer.types.d.ts +3 -1
- package/lib/components/RichTextEditor/RichTextViewer.types.d.ts.map +1 -1
- package/lib/components/RichTextEditor/RichTextViewer.types.js.map +1 -1
- package/lib/components/RichTextEditor/Toolbar/AnchorButton.d.ts.map +1 -1
- package/lib/components/RichTextEditor/Toolbar/AnchorButton.js +14 -17
- package/lib/components/RichTextEditor/Toolbar/AnchorButton.js.map +1 -1
- package/lib/components/RichTextEditor/Toolbar/ImageButton.d.ts.map +1 -1
- package/lib/components/RichTextEditor/Toolbar/ImageButton.js +8 -13
- package/lib/components/RichTextEditor/Toolbar/ImageButton.js.map +1 -1
- package/lib/components/RichTextEditor/Toolbar/IndentButton.d.ts.map +1 -1
- package/lib/components/RichTextEditor/Toolbar/IndentButton.js +5 -2
- package/lib/components/RichTextEditor/Toolbar/IndentButton.js.map +1 -1
- package/lib/components/RichTextEditor/Toolbar/TableButton.d.ts.map +1 -1
- package/lib/components/RichTextEditor/Toolbar/TableButton.js +5 -3
- package/lib/components/RichTextEditor/Toolbar/TableButton.js.map +1 -1
- package/lib/components/RichTextEditor/Toolbar/TextSelect.d.ts.map +1 -1
- package/lib/components/RichTextEditor/Toolbar/TextSelect.js +35 -18
- package/lib/components/RichTextEditor/Toolbar/TextSelect.js.map +1 -1
- package/lib/components/RichTextEditor/Toolbar/Toolbar.d.ts.map +1 -1
- package/lib/components/RichTextEditor/Toolbar/Toolbar.js +11 -20
- package/lib/components/RichTextEditor/Toolbar/Toolbar.js.map +1 -1
- package/lib/components/RichTextEditor/Toolbar/ToolbarButton.js +3 -4
- package/lib/components/RichTextEditor/Toolbar/ToolbarButton.js.map +1 -1
- package/lib/components/RichTextEditor/utils/EditorCommands.d.ts +9 -1
- package/lib/components/RichTextEditor/utils/EditorCommands.d.ts.map +1 -1
- package/lib/components/RichTextEditor/utils/EditorCommands.js +130 -17
- package/lib/components/RichTextEditor/utils/EditorCommands.js.map +1 -1
- package/lib/components/RichTextEditor/utils/ListCommands.js +10 -14
- package/lib/components/RichTextEditor/utils/ListCommands.js.map +1 -1
- package/lib/components/RichTextEditor/utils/htmlConverter.d.ts.map +1 -1
- package/lib/components/RichTextEditor/utils/htmlConverter.js +45 -21
- package/lib/components/RichTextEditor/utils/htmlConverter.js.map +1 -1
- package/lib/components/RichTextEditor/utils/interactionRenderer.d.ts +9 -2
- package/lib/components/RichTextEditor/utils/interactionRenderer.d.ts.map +1 -1
- package/lib/components/RichTextEditor/utils/interactionRenderer.js +40 -5
- package/lib/components/RichTextEditor/utils/interactionRenderer.js.map +1 -1
- package/lib/components/RichTextEditor/utils/markdownConverter.d.ts +2 -0
- package/lib/components/RichTextEditor/utils/markdownConverter.d.ts.map +1 -1
- package/lib/components/RichTextEditor/utils/markdownConverter.js +26 -7
- package/lib/components/RichTextEditor/utils/markdownConverter.js.map +1 -1
- package/lib/components/RichTextEditor/utils/renderers.d.ts.map +1 -1
- package/lib/components/RichTextEditor/utils/renderers.js +22 -19
- package/lib/components/RichTextEditor/utils/renderers.js.map +1 -1
- package/lib/components/RichTextEditor/utils/search.d.ts.map +1 -1
- package/lib/components/RichTextEditor/utils/search.js +7 -3
- package/lib/components/RichTextEditor/utils/search.js.map +1 -1
- package/lib/components/RichTextEditor/utils/slateConverter.d.ts.map +1 -1
- package/lib/components/RichTextEditor/utils/slateConverter.js +1 -0
- package/lib/components/RichTextEditor/utils/slateConverter.js.map +1 -1
- package/package.json +17 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toolbar.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/Toolbar/Toolbar.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAM,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAExD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAChE,OA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c,CAAC,gBAAgB,CAAC,IAAI,CACnC,KAAC,IAAI,kBAAC,SAAS,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,gBAAG,kBAAkB,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG,CAAC,YAAQ,CACpF,aACI,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,OAAO,CAAC","sourcesContent":["import { FC, useState, useEffect, useRef } from 'react';\nimport { Text } from 'slate';\nimport { useSlate, useFocused, ReactEditor } from 'slate-react';\nimport styled, { css } from 'styled-components';\n\nimport {\n Flex,\n Icon,\n useArrows,\n useI18n,\n defaultThemeProp,\n TranslationPack\n} from '@pega/cosmos-react-core';\nimport { TranslationFunction } from '@pega/cosmos-react-core/lib/i18n/translate';\n\nimport EditorCommands from '../utils/EditorCommands';\nimport ListCommands from '../utils/ListCommands';\n\nimport ToolbarButton from './ToolbarButton';\nimport { StyleType, Features } from './Toolbar.types';\nimport TableButton from './TableButton';\nimport AnchorButton from './AnchorButton';\nimport ImageButton from './ImageButton';\nimport TextSelect from './TextSelect';\nimport IndentButton from './IndentButton';\nimport { getKeyCommand } from './utils';\n\nconst StyledToolbar = styled.div<{ sticky?: boolean }>`\n background-color: ${props => props.theme.base.palette['primary-background']};\n border-radius: calc(0.25 * ${props => props.theme.base['border-radius']});\n ${props =>\n props.sticky &&\n css`\n position: sticky;\n bottom: 0;\n `}\n`;\n\nStyledToolbar.defaultProps = defaultThemeProp;\n\nexport interface ToolbarProps {\n features: Features[];\n sticky?: boolean;\n setFocusableBtn: (el: HTMLElement) => void;\n}\n\ntype StyleButtonType = {\n style: StyleType;\n text: string;\n icon?: string;\n label?: string;\n format: Exclude<keyof Text, 'text'>;\n tooltip: string;\n};\n\n// Function that returns the text styling buttons\nfunction renderStyleButtons(\n editor: ReactEditor,\n t: TranslationFunction<TranslationPack>,\n focused: boolean,\n osx: boolean\n) {\n const inlineStyleButtons: StyleButtonType[] = [\n {\n style: 'BOLD',\n text: 'B',\n format: 'bold',\n label: t('rte_bold'),\n tooltip: getKeyCommand(\n osx,\n ({ ctrl, shift }) => `${t('rte_bold')} (${ctrl}B, ${ctrl}${shift}B)`\n )\n },\n {\n style: 'ITALIC',\n text: 'I',\n format: 'italic',\n label: t('rte_italic'),\n tooltip: getKeyCommand(\n osx,\n ({ ctrl, shift }) => `${t('rte_italic')} (${ctrl}I, ${ctrl}${shift}I)`\n )\n },\n {\n style: 'STRIKE-THROUGH',\n text: 'S',\n format: 'line-through',\n label: t('rte_strike_through'),\n tooltip: getKeyCommand(\n osx,\n ({ ctrl, shift }) => `${t('rte_strike_through')} (${ctrl}${shift}X)`\n )\n }\n ];\n\n return inlineStyleButtons.map(({ format, style, text, label, tooltip }) => {\n return (\n <ToolbarButton\n key={style}\n onMouseDown={e => {\n e.preventDefault();\n if (!focused) {\n ReactEditor.focus(editor);\n }\n setTimeout(() => {\n EditorCommands.toggleFormat(format, editor);\n }, 0);\n }}\n styleType={style}\n active={EditorCommands.isFormatActive(format, editor)}\n tooltip={tooltip}\n label={label}\n >\n {text}\n </ToolbarButton>\n );\n });\n}\n\n// Function that returns the cut, copy and paste buttons\nfunction renderCutCopyPaste(\n editor: ReactEditor,\n t: TranslationFunction<TranslationPack>,\n osx: boolean\n) {\n const CutCopyPasteButtons = [\n {\n text: 'Cut',\n icon: 'scissors',\n label: t('rte_cut'),\n func: () => {\n document.execCommand('cut');\n },\n tooltip: getKeyCommand(osx, ({ ctrl }) => `${t('rte_cut')} (${ctrl}X)`)\n },\n {\n text: 'Copy',\n icon: 'copy',\n label: t('rte_copy'),\n func: () => {\n document.execCommand('copy');\n },\n tooltip: getKeyCommand(osx, ({ ctrl }) => `${t('rte_copy')} (${ctrl}C)`)\n },\n {\n text: 'Paste',\n icon: 'clipboard-data',\n label: t('rte_paste'),\n func: () => {\n navigator.clipboard.readText().then(text => {\n EditorCommands.replaceWithText(editor, editor.selection, text);\n });\n },\n tooltip: getKeyCommand(osx, ({ ctrl }) => `${t('rte_paste')} (${ctrl}V)`)\n }\n ];\n\n return CutCopyPasteButtons.map(btn => {\n return (\n <ToolbarButton\n onMouseDown={e => {\n e.preventDefault();\n btn.func();\n }}\n key={btn.text}\n tooltip={btn.tooltip}\n label={btn.label}\n >\n <Icon name={btn.icon} />\n </ToolbarButton>\n );\n });\n}\n\n// Takes the features array and transforms it into a map for faster lookup\nfunction createActiveFeaturesMap(features: Features[]) {\n const featuresMap = features.reduce((acc, feature) => {\n return { ...acc, [feature]: true };\n }, {} as { [F in Features]: boolean });\n\n return featuresMap;\n}\n\nconst Toolbar: FC<ToolbarProps> = (props: ToolbarProps) => {\n const { features, sticky, setFocusableBtn } = props;\n const editor = useSlate();\n const focused = useFocused();\n const t = useI18n();\n const [osx, setOsx] = useState(false);\n const toolbarRef = useRef<HTMLElement>(null);\n\n useArrows(toolbarRef, { selector: 'button', dir: 'left-right' });\n\n const [activeFeatures, setActiveFeatures] = useState(createActiveFeaturesMap(features));\n\n useEffect(() => {\n const btn = toolbarRef?.current?.querySelector('button');\n if (btn) setFocusableBtn(btn);\n }, [toolbarRef.current]);\n\n useEffect(() => {\n setActiveFeatures(createActiveFeaturesMap(features));\n }, [features]);\n\n useEffect(() => {\n if (navigator.appVersion.includes('Mac')) setOsx(true);\n }, []);\n\n return (\n <Flex as={StyledToolbar} sticky={sticky} container={{ justify: 'between' }} ref={toolbarRef}>\n <Flex container={{ alignItems: 'end' }}>\n <TextSelect osx={osx} />\n {activeFeatures['inline-styling'] && renderStyleButtons(editor, t, focused, osx)}\n {activeFeatures.lists && (\n <>\n <ToolbarButton\n onMouseDown={e => {\n e.preventDefault();\n ListCommands.toggleList('unordered-list', editor);\n }}\n active={EditorCommands.isBlockActive('unordered-list', editor)}\n tooltip={getKeyCommand(\n osx,\n ({ ctrl, shift }) => `${t('rte_bulleted_list')} (${ctrl}${shift}L)`\n )}\n label={t('rte_bulleted_list')}\n >\n <Icon name='list' />\n </ToolbarButton>\n <ToolbarButton\n onMouseDown={e => {\n e.preventDefault();\n ListCommands.toggleList('ordered-list', editor);\n }}\n active={EditorCommands.isBlockActive('ordered-list', editor)}\n tooltip={t('rte_numbered_list')}\n label={t('rte_numbered_list')}\n >\n <Icon name='list-number' />\n </ToolbarButton>\n </>\n )}\n {activeFeatures.indentation && (\n <>\n <IndentButton type='indent' osx={osx} />\n <IndentButton type='unindent' osx={osx} />\n </>\n )}\n {activeFeatures.tables && <TableButton />}\n </Flex>\n <Flex container={{ alignItems: 'end' }}>\n {activeFeatures.links && <AnchorButton osx={osx} />}\n {activeFeatures.images && <ImageButton />}\n </Flex>\n {activeFeatures['cut-copy-paste'] && (\n <Flex container={{ alignItems: 'end' }}>{renderCutCopyPaste(editor, t, osx)}</Flex>\n )}\n </Flex>\n );\n};\n\nexport default Toolbar;\n"]}
|
|
1
|
+
{"version":3,"file":"Toolbar.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/Toolbar/Toolbar.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAM,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAExD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,OAAO,EACP,gBAAgB,EAEjB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,cAAc,MAAM,yBAAyB,CAAC;AACrD,OAAO,YAAY,MAAM,uBAAuB,CAAC;AAEjD,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAE5C,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,UAAU,MAAM,cAAc,CAAC;AACtC,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,SA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,aAAa,CAAC,cAAc,EAAE,MAAM,CAAC,EAC5D,OAAO,EAAE,CAAC,CAAC,mBAAmB,CAAC,EAC/B,KAAK,EAAE,CAAC,CAAC,mBAAmB,CAAC,YAE7B,KAAC,IAAI,IAAC,IAAI,EAAC,aAAa,WAAG,WACb,YACf,CACJ,EACA,cAAc,CAAC,WAAW,IAAI,CAC7B,8BACE,KAAC,YAAY,IAAC,IAAI,EAAC,QAAQ,EAAC,GAAG,EAAE,GAAG,WAAI,EACxC,KAAC,YAAY,IAAC,IAAI,EAAC,UAAU,EAAC,GAAG,EAAE,GAAG,WAAI,YACzC,CACJ,EACA,cAAc,CAAC,MAAM,IAAI,KAAC,WAAW,aAAG,YACpC,EACP,MAAC,IAAI,IAAC,SAAS,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,aACnC,cAAc,CAAC,KAAK,IAAI,KAAC,YAAY,IAAC,GAAG,EAAE,GAAG,WAAI,EAClD,cAAc,CAAC,MAAM,IAAI,KAAC,WAAW,aAAG,YACpC,EACN,cAAc,CAAC,gBAAgB,CAAC,IAAI,CACnC,KAAC,IAAI,IAAC,SAAS,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,YAAG,kBAAkB,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG,CAAC,WAAQ,CACpF,YACI,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,OAAO,CAAC","sourcesContent":["import { FC, useState, useEffect, useRef } from 'react';\nimport { Text } from 'slate';\nimport { useSlate, useFocused, ReactEditor } from 'slate-react';\nimport styled, { css } from 'styled-components';\n\nimport {\n Flex,\n Icon,\n useArrows,\n useI18n,\n defaultThemeProp,\n TranslationPack\n} from '@pega/cosmos-react-core';\nimport { TranslationFunction } from '@pega/cosmos-react-core/lib/i18n/translate';\n\nimport EditorCommands from '../utils/EditorCommands';\nimport ListCommands from '../utils/ListCommands';\n\nimport ToolbarButton from './ToolbarButton';\nimport { StyleType, Features } from './Toolbar.types';\nimport TableButton from './TableButton';\nimport AnchorButton from './AnchorButton';\nimport ImageButton from './ImageButton';\nimport TextSelect from './TextSelect';\nimport IndentButton from './IndentButton';\nimport { getKeyCommand } from './utils';\n\nconst StyledToolbar = styled.div<{ sticky?: boolean }>`\n background-color: ${props => props.theme.base.palette['primary-background']};\n border-radius: calc(0.25 * ${props => props.theme.base['border-radius']});\n overflow: auto;\n padding: 0.125rem;\n ${props =>\n props.sticky &&\n css`\n position: sticky;\n bottom: 0;\n `}\n`;\n\nStyledToolbar.defaultProps = defaultThemeProp;\n\nexport interface ToolbarProps {\n features: Features[];\n sticky?: boolean;\n setFocusableBtn: (el: HTMLElement) => void;\n}\n\ntype StyleButtonType = {\n style: StyleType;\n text: string;\n icon?: string;\n label?: string;\n format: Exclude<keyof Text, 'text'>;\n tooltip: string;\n};\n\n// Function that returns the text styling buttons\nfunction renderStyleButtons(\n editor: ReactEditor,\n t: TranslationFunction<TranslationPack>,\n focused: boolean,\n osx: boolean\n) {\n const inlineStyleButtons: StyleButtonType[] = [\n {\n style: 'BOLD',\n text: 'B',\n format: 'bold',\n label: t('rte_bold'),\n tooltip: getKeyCommand(\n osx,\n ({ ctrl, shift }) => `${t('rte_bold')} (${ctrl}B, ${ctrl}${shift}B)`\n )\n },\n {\n style: 'ITALIC',\n text: 'I',\n format: 'italic',\n label: t('rte_italic'),\n tooltip: getKeyCommand(\n osx,\n ({ ctrl, shift }) => `${t('rte_italic')} (${ctrl}I, ${ctrl}${shift}I)`\n )\n },\n {\n style: 'STRIKE-THROUGH',\n text: 'S',\n format: 'line-through',\n label: t('rte_strike_through'),\n tooltip: getKeyCommand(\n osx,\n ({ ctrl, shift }) => `${t('rte_strike_through')} (${ctrl}${shift}X)`\n )\n }\n ];\n\n return inlineStyleButtons.map(({ format, style, text, label, tooltip }) => {\n return (\n <ToolbarButton\n key={style}\n onMouseDown={e => {\n e.preventDefault();\n if (!focused) {\n ReactEditor.focus(editor);\n }\n setTimeout(() => {\n EditorCommands.toggleFormat(format, editor);\n }, 0);\n }}\n styleType={style}\n active={EditorCommands.isFormatActive(format, editor)}\n tooltip={tooltip}\n label={label}\n >\n {text}\n </ToolbarButton>\n );\n });\n}\n\n// Function that returns the cut, copy and paste buttons\nfunction renderCutCopyPaste(\n editor: ReactEditor,\n t: TranslationFunction<TranslationPack>,\n osx: boolean\n) {\n const CutCopyPasteButtons = [\n {\n text: 'Cut',\n icon: 'scissors',\n label: t('rte_cut'),\n func: () => {\n document.execCommand('cut');\n },\n tooltip: getKeyCommand(osx, ({ ctrl }) => `${t('rte_cut')} (${ctrl}X)`)\n },\n {\n text: 'Copy',\n icon: 'copy',\n label: t('rte_copy'),\n func: () => {\n document.execCommand('copy');\n },\n tooltip: getKeyCommand(osx, ({ ctrl }) => `${t('rte_copy')} (${ctrl}C)`)\n },\n {\n text: 'Paste',\n icon: 'clipboard-data',\n label: t('rte_paste'),\n func: () => {\n navigator.clipboard.readText().then(text => {\n EditorCommands.replaceWithText(editor, editor.selection, text);\n });\n },\n tooltip: getKeyCommand(osx, ({ ctrl }) => `${t('rte_paste')} (${ctrl}V)`)\n }\n ];\n\n return CutCopyPasteButtons.map(btn => {\n return (\n <ToolbarButton\n onMouseDown={e => {\n e.preventDefault();\n btn.func();\n }}\n key={btn.text}\n tooltip={btn.tooltip}\n label={btn.label}\n >\n <Icon name={btn.icon} />\n </ToolbarButton>\n );\n });\n}\n\n// Takes the features array and transforms it into a map for faster lookup\nfunction createActiveFeaturesMap(features: Features[]) {\n return features.reduce((acc, feature) => {\n return { ...acc, [feature]: true };\n }, {} as { [F in Features]: boolean });\n}\n\nconst Toolbar: FC<ToolbarProps> = (props: ToolbarProps) => {\n const { features, sticky, setFocusableBtn } = props;\n const editor = useSlate();\n const focused = useFocused();\n const t = useI18n();\n const [osx, setOsx] = useState(false);\n const toolbarRef = useRef<HTMLElement>(null);\n\n useArrows(toolbarRef, { selector: 'button', dir: 'left-right' });\n\n const [activeFeatures, setActiveFeatures] = useState(createActiveFeaturesMap(features));\n\n useEffect(() => {\n const btn = toolbarRef?.current?.querySelector('button');\n if (btn) setFocusableBtn(btn);\n }, [toolbarRef.current]);\n\n useEffect(() => {\n setActiveFeatures(createActiveFeaturesMap(features));\n }, [features]);\n\n useEffect(() => {\n if (navigator.appVersion.includes('Mac')) setOsx(true);\n }, []);\n\n return (\n <Flex as={StyledToolbar} sticky={sticky} container={{ justify: 'between' }} ref={toolbarRef}>\n <Flex container={{ alignItems: 'end' }}>\n <TextSelect osx={osx} />\n {activeFeatures['inline-styling'] && renderStyleButtons(editor, t, focused, osx)}\n {activeFeatures.lists && (\n <>\n <ToolbarButton\n onMouseDown={e => {\n e.preventDefault();\n ListCommands.toggleList('unordered-list', editor);\n }}\n active={EditorCommands.isBlockActive('unordered-list', editor)}\n tooltip={getKeyCommand(\n osx,\n ({ ctrl, shift }) => `${t('rte_bulleted_list')} (${ctrl}${shift}L)`\n )}\n label={t('rte_bulleted_list')}\n >\n <Icon name='list' />\n </ToolbarButton>\n <ToolbarButton\n onMouseDown={e => {\n e.preventDefault();\n ListCommands.toggleList('ordered-list', editor);\n }}\n active={EditorCommands.isBlockActive('ordered-list', editor)}\n tooltip={t('rte_numbered_list')}\n label={t('rte_numbered_list')}\n >\n <Icon name='list-number' />\n </ToolbarButton>\n </>\n )}\n {activeFeatures.indentation && (\n <>\n <IndentButton type='indent' osx={osx} />\n <IndentButton type='unindent' osx={osx} />\n </>\n )}\n {activeFeatures.tables && <TableButton />}\n </Flex>\n <Flex container={{ alignItems: 'end' }}>\n {activeFeatures.links && <AnchorButton osx={osx} />}\n {activeFeatures.images && <ImageButton />}\n </Flex>\n {activeFeatures['cut-copy-paste'] && (\n <Flex container={{ alignItems: 'end' }}>{renderCutCopyPaste(editor, t, osx)}</Flex>\n )}\n </Flex>\n );\n};\n\nexport default Toolbar;\n"]}
|
|
@@ -56,12 +56,11 @@ const ToolbarButton = forwardRef(({ tooltip, active, styleType, disabled, label,
|
|
|
56
56
|
const { disabled: contextDisabled } = useRTEContext();
|
|
57
57
|
const [el, setEl] = useElement();
|
|
58
58
|
const toolBarRef = useConsolidatedRef(setEl, ref);
|
|
59
|
-
return (_jsxs(_Fragment, { children: [_jsx(StyledToolbarButton,
|
|
59
|
+
return (_jsxs(_Fragment, { children: [_jsx(StyledToolbarButton, { active: active, styleType: styleType, ref: toolBarRef, disabled: contextDisabled || disabled, tabIndex: -1, onKeyPress: (e) => {
|
|
60
60
|
if (e.key === 'Enter') {
|
|
61
|
-
onMouseDown
|
|
61
|
+
onMouseDown?.(e);
|
|
62
62
|
}
|
|
63
|
-
}, onMouseDown: onMouseDown, type: 'button', "aria-label": `${label} ${active ? 'active' : ''}`, "aria-pressed": active },
|
|
64
|
-
el && tooltip && (_jsx(Tooltip, Object.assign({ target: el, showDelay: 'none', hideDelay: 'none' }, { children: tooltip }), void 0))] }, void 0));
|
|
63
|
+
}, onMouseDown: onMouseDown, type: 'button', "aria-label": `${label} ${active ? 'active' : ''}`, "aria-pressed": active, ...restProps }, void 0), el && tooltip && (_jsx(Tooltip, { target: el, showDelay: 'none', hideDelay: 'none', children: tooltip }, void 0))] }, void 0));
|
|
65
64
|
});
|
|
66
65
|
export default ToolbarButton;
|
|
67
66
|
//# sourceMappingURL=ToolbarButton.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToolbarButton.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/Toolbar/ToolbarButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAM,UAAU,EAAkC,MAAM,OAAO,CAAC;AACvE,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,OAAO,EACL,gBAAgB,EAEhB,OAAO,EACP,QAAQ,EACR,kBAAkB,EAClB,UAAU,EACX,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAa1D,MAAM,mBAAmB,GAAG,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AQ,CAAC,CAAC,CAAC,EAAE,EAAE,kBAClC,MAAM,KAChB,SAAS,WACb,EACD,EAAE,IAAI,OAAO,IAAI,CAChB,KAAC,OAAO,IAAC,MAAM,EAAE,EAAE,EAAE,SAAS,EAAC,MAAM,EAAC,SAAS,EAAC,MAAM,YACnD,OAAO,WACA,CACX,YACA,CACJ,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { FC, forwardRef, KeyboardEvent, MouseEvent, Ref } from 'react';\nimport styled, { css } from 'styled-components';\nimport { mix } from 'polished';\n\nimport {\n defaultThemeProp,\n ForwardProps,\n Tooltip,\n tryCatch,\n useConsolidatedRef,\n useElement\n} from '@pega/cosmos-react-core';\n\nimport { useRTEContext } from '../RichTextEditor.context';\n\nimport { StyleType } from './Toolbar.types';\n\nexport interface ToolBarButtonProps {\n tooltip?: string;\n active?: boolean;\n styleType?: StyleType;\n disabled?: boolean;\n label?: string;\n onMouseDown?: (e: MouseEvent | KeyboardEvent) => void;\n}\n\nconst StyledToolbarButton = styled.button<ToolBarButtonProps>(props => {\n const { active, theme, styleType } = props;\n const size = `calc(4 * ${props.theme.base.spacing})`;\n const activeColor = tryCatch(() =>\n mix(0.85, theme.base.palette['primary-background'], theme.base.palette.interactive)\n );\n return css`\n background-color: ${active ? activeColor : 'transparent'};\n border: none;\n color: ${active ? theme.base.palette.interactive : theme.base.palette['foreground-color']};\n outline: none;\n display: inline-flex;\n line-height: 1;\n align-items: center;\n justify-content: center;\n height: ${size};\n min-width: ${size};\n opacity: ${active ? 'inherit' : '0.7'};\n cursor: pointer;\n\n &:focus {\n box-shadow: ${theme.base.shadow.focus};\n }\n\n &:hover {\n opacity: 1;\n }\n\n &:disabled {\n cursor: not-allowed;\n box-shadow: none;\n }\n\n ${styleType === 'BOLD' &&\n css`\n font-weight: bold;\n `}\n\n ${styleType === 'ITALIC' &&\n css`\n font-style: italic;\n `}\n\n ${styleType === 'STRIKE-THROUGH' &&\n css`\n text-decoration: line-through;\n `}\n `;\n});\n\nStyledToolbarButton.defaultProps = defaultThemeProp;\n\nconst ToolbarButton: FC<ToolBarButtonProps & ForwardProps> = forwardRef(\n (\n { tooltip, active, styleType, disabled, label, onMouseDown, ...restProps },\n ref: Ref<HTMLButtonElement>\n ) => {\n const { disabled: contextDisabled } = useRTEContext();\n const [el, setEl] = useElement();\n const toolBarRef = useConsolidatedRef<HTMLButtonElement>(setEl, ref);\n return (\n <>\n <StyledToolbarButton\n active={active}\n styleType={styleType}\n ref={toolBarRef}\n disabled={contextDisabled || disabled}\n tabIndex={-1}\n onKeyPress={(e: KeyboardEvent) => {\n if (e.key === 'Enter') {\n onMouseDown?.(e);\n }\n }}\n onMouseDown={onMouseDown}\n type='button'\n aria-label={`${label} ${active ? 'active' : ''}`}\n aria-pressed={active}\n {...restProps}\n />\n {el && tooltip && (\n <Tooltip target={el} showDelay='none' hideDelay='none'>\n {tooltip}\n </Tooltip>\n )}\n </>\n );\n }\n);\n\nexport default ToolbarButton;\n"]}
|
|
@@ -7,16 +7,24 @@ declare const commands: {
|
|
|
7
7
|
getActiveBlockType: (editor: Editor) => string;
|
|
8
8
|
setBlock: (format: Element['type'], editor: Editor) => void;
|
|
9
9
|
replaceWithText: (editor: Editor, target: Range | null, text: string) => void;
|
|
10
|
+
replaceWithNodes: (editor: Editor, target: Range | null, node: Node) => void;
|
|
10
11
|
getSelectedNode: (editor: Editor) => NodeEntry<Node>;
|
|
11
12
|
appendTable: (editor: Editor) => void;
|
|
12
13
|
appendImage: (editor: Editor, imageData: {
|
|
13
14
|
src: string;
|
|
14
15
|
alt: string;
|
|
15
|
-
}, id: string) =>
|
|
16
|
+
}, id: string) => import("slate").BasePoint | null;
|
|
16
17
|
appendImagePlaceholder: (editor: Editor) => string;
|
|
17
18
|
createLink: (editor: Editor, text: string, url: string, selection: Range | null) => void;
|
|
18
19
|
checkImageEnter: (editor: Editor, e: KeyboardEvent) => void;
|
|
19
20
|
checkLinkBreak: (editor: Editor, e: KeyboardEvent) => void;
|
|
21
|
+
/**
|
|
22
|
+
* Turns the searchResult property off on the text node when any key is pressed while on a searchResult.
|
|
23
|
+
* Will delete the searchResult node if backspace key is hit.
|
|
24
|
+
* Will re-position cursor to the start/end of the searchResult if arrow navigation is used.
|
|
25
|
+
*/
|
|
26
|
+
checkSearchDownKeys: (editor: Editor, e: KeyboardEvent) => void;
|
|
27
|
+
checkSearchUpKeys: (editor: Editor, e: KeyboardEvent) => void;
|
|
20
28
|
indent: (editor: Editor) => void;
|
|
21
29
|
unindent: (editor: Editor) => void;
|
|
22
30
|
checkKeyCommands: (editor: Editor, e: KeyboardEvent) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorCommands.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/EditorCommands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EACL,MAAM,EAEN,KAAK,EAEL,SAAS,EACT,IAAI,EACJ,OAAO,EACP,IAAI,EAEL,MAAM,OAAO,CAAC;AAYf,QAAA,MAAM,QAAQ;6BAEa,QAAQ,MAAM,IAAI,EAAE,MAAM,CAAC,UAAU,MAAM;2BAK7C,QAAQ,MAAM,IAAI,EAAE,MAAM,CAAC,UAAU,MAAM;4BAS1C,OAAO,CAAC,MAAM,CAAC,UAAU,MAAM;iCAQ1B,MAAM,KAAG,MAAM;uBAazB,OAAO,CAAC,MAAM,CAAC,UAAU,MAAM;8BAIxB,MAAM,UAAU,KAAK,GAAG,IAAI,QAAQ,MAAM;
|
|
1
|
+
{"version":3,"file":"EditorCommands.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/EditorCommands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EACL,MAAM,EAEN,KAAK,EAEL,SAAS,EACT,IAAI,EACJ,OAAO,EACP,IAAI,EAEL,MAAM,OAAO,CAAC;AAYf,QAAA,MAAM,QAAQ;6BAEa,QAAQ,MAAM,IAAI,EAAE,MAAM,CAAC,UAAU,MAAM;2BAK7C,QAAQ,MAAM,IAAI,EAAE,MAAM,CAAC,UAAU,MAAM;4BAS1C,OAAO,CAAC,MAAM,CAAC,UAAU,MAAM;iCAQ1B,MAAM,KAAG,MAAM;uBAazB,OAAO,CAAC,MAAM,CAAC,UAAU,MAAM;8BAIxB,MAAM,UAAU,KAAK,GAAG,IAAI,QAAQ,MAAM;+BAQzC,MAAM,UAAU,KAAK,GAAG,IAAI,QAAQ,IAAI;8BAQzC,MAAM;0BASV,MAAM;0BA0CN,MAAM,aAAa;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,MAAM,MAAM;qCAkBhD,MAAM,KAAG,MAAM;yBAgB3B,MAAM,QAAQ,MAAM,OAAO,MAAM,aAAa,KAAK,GAAG,IAAI;8BAuCrD,MAAM,KAAK,aAAa;6BAsBzB,MAAM,KAAK,aAAa;IAUjD;;;;OAIG;kCAC2B,MAAM,KAAK,aAAa;gCAiE1B,MAAM,KAAK,aAAa;qBA4CnC,MAAM;uBAiBJ,MAAM;+BAsBE,MAAM,KAAK,aAAa;CA4DpD,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -54,6 +54,14 @@ const commands = {
|
|
|
54
54
|
Transforms.insertText(editor, text);
|
|
55
55
|
Transforms.move(editor);
|
|
56
56
|
},
|
|
57
|
+
// Replaces a target in the editor with the given node
|
|
58
|
+
replaceWithNodes: (editor, target, node) => {
|
|
59
|
+
if (target) {
|
|
60
|
+
Transforms.select(editor, target);
|
|
61
|
+
}
|
|
62
|
+
Transforms.insertNodes(editor, node);
|
|
63
|
+
Transforms.move(editor);
|
|
64
|
+
},
|
|
57
65
|
// Gets the highest selected block level node
|
|
58
66
|
getSelectedNode: (editor) => {
|
|
59
67
|
const [node] = Editor.nodes(editor, {
|
|
@@ -65,7 +73,6 @@ const commands = {
|
|
|
65
73
|
},
|
|
66
74
|
// Appends a 3x3 table into the editor and adds a blank line to the bottom
|
|
67
75
|
appendTable: (editor) => {
|
|
68
|
-
var _a;
|
|
69
76
|
const baseArr = new Array(3).fill(new Array(3).fill(0));
|
|
70
77
|
const table = [
|
|
71
78
|
{
|
|
@@ -94,7 +101,7 @@ const commands = {
|
|
|
94
101
|
];
|
|
95
102
|
Transforms.insertNodes(editor, table, { mode: 'highest' });
|
|
96
103
|
const [firstTableCell] = Editor.nodes(editor, {
|
|
97
|
-
at:
|
|
104
|
+
at: editor.selection?.anchor.path.slice(0, 1),
|
|
98
105
|
match: n => Element.isElement(n) && n.type === 'paragraph',
|
|
99
106
|
mode: 'highest'
|
|
100
107
|
});
|
|
@@ -115,7 +122,9 @@ const commands = {
|
|
|
115
122
|
const [, path] = node;
|
|
116
123
|
Transforms.setNodes(editor, { type: 'image', src: imageData.src, alt: imageData.alt }, { at: path });
|
|
117
124
|
Transforms.unsetNodes(editor, 'id', { at: path });
|
|
125
|
+
return Editor.end(editor, path);
|
|
118
126
|
}
|
|
127
|
+
return null;
|
|
119
128
|
},
|
|
120
129
|
appendImagePlaceholder: (editor) => {
|
|
121
130
|
const node = commands.getSelectedNode(editor);
|
|
@@ -199,6 +208,118 @@ const commands = {
|
|
|
199
208
|
Editor.removeMark(editor, 'href');
|
|
200
209
|
}
|
|
201
210
|
},
|
|
211
|
+
/**
|
|
212
|
+
* Turns the searchResult property off on the text node when any key is pressed while on a searchResult.
|
|
213
|
+
* Will delete the searchResult node if backspace key is hit.
|
|
214
|
+
* Will re-position cursor to the start/end of the searchResult if arrow navigation is used.
|
|
215
|
+
*/
|
|
216
|
+
checkSearchDownKeys: (editor, e) => {
|
|
217
|
+
const [text] = Editor.nodes(editor, {
|
|
218
|
+
match: n => Text.isText(n)
|
|
219
|
+
});
|
|
220
|
+
if (text) {
|
|
221
|
+
const [node, path] = text;
|
|
222
|
+
const nextNode = Editor.next(editor)?.[0];
|
|
223
|
+
const nextPath = Editor.next(editor)?.[1];
|
|
224
|
+
const previousNode = Editor.previous(editor)?.[0];
|
|
225
|
+
const previousPath = Editor.previous(editor)?.[1];
|
|
226
|
+
const next = nextNode && nextNode.searchResult;
|
|
227
|
+
const nextInline = next && path[0] === nextPath?.[0];
|
|
228
|
+
const previous = previousNode && previousNode.searchResult;
|
|
229
|
+
const previousInline = previous && path[0] === previousPath?.[0];
|
|
230
|
+
// Checks if the current selection is a single cursor point rather than spanning multiple characters
|
|
231
|
+
const singlePointSelection = editor.selection?.anchor.offset === editor.selection?.focus.offset &&
|
|
232
|
+
editor.selection?.anchor.path[0] === editor.selection?.focus.path[0] &&
|
|
233
|
+
editor.selection?.anchor.path[1] === editor.selection?.focus.path[1];
|
|
234
|
+
// Checks if the current selected node is a search result, or directly adjacent inline with a search result
|
|
235
|
+
if (node.searchResult || (next && nextInline) || (previous && previousInline)) {
|
|
236
|
+
const atStart = node.searchResult && editor.selection?.anchor.offset === 0;
|
|
237
|
+
const atEnd = node.searchResult && editor.selection?.anchor.offset === node.text.length;
|
|
238
|
+
// Deletes the entire search result only if the cursor is at the end of the search result
|
|
239
|
+
if (e.key === 'Backspace' && (atEnd || (previous && previousInline))) {
|
|
240
|
+
if (singlePointSelection)
|
|
241
|
+
e.preventDefault();
|
|
242
|
+
Transforms.delete(editor, { at: previous ? previousPath : path });
|
|
243
|
+
// Deletes the entire search result only if the cursor is at the start of the search result
|
|
244
|
+
}
|
|
245
|
+
else if (e.key === 'Delete' && (atStart || (next && nextInline))) {
|
|
246
|
+
if (singlePointSelection)
|
|
247
|
+
e.preventDefault();
|
|
248
|
+
Transforms.delete(editor, { at: next ? nextPath : path });
|
|
249
|
+
// Moves cursor to start of search result only if the cursor is at the end of the search result
|
|
250
|
+
}
|
|
251
|
+
else if (e.key === 'ArrowLeft' && (atEnd || (previous && previousInline))) {
|
|
252
|
+
if (singlePointSelection)
|
|
253
|
+
e.preventDefault();
|
|
254
|
+
Transforms.move(editor, {
|
|
255
|
+
distance: previous ? previousNode.text.length : node.text.length,
|
|
256
|
+
unit: 'character',
|
|
257
|
+
reverse: true
|
|
258
|
+
});
|
|
259
|
+
// Moves cursor to end of search result only if the cursor is at the start of the search result
|
|
260
|
+
}
|
|
261
|
+
else if (e.key === 'ArrowRight' && (atStart || (next && nextInline))) {
|
|
262
|
+
if (singlePointSelection)
|
|
263
|
+
e.preventDefault();
|
|
264
|
+
Transforms.move(editor, {
|
|
265
|
+
distance: next ? nextNode.text.length : node.text.length,
|
|
266
|
+
unit: 'character'
|
|
267
|
+
});
|
|
268
|
+
// Ensures all other character (besides special key bindings) are inserted as plain text
|
|
269
|
+
}
|
|
270
|
+
else if (e.key.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey) {
|
|
271
|
+
e.preventDefault();
|
|
272
|
+
Editor.insertNode(editor, { text: e.key === 'Enter' ? '\n' : e.key });
|
|
273
|
+
}
|
|
274
|
+
// Prevents partial search result selections from disabling the searchResult flag
|
|
275
|
+
if (singlePointSelection) {
|
|
276
|
+
Editor.removeMark(editor, 'searchResult');
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
// Checks arrow navigation key up events around search results
|
|
282
|
+
checkSearchUpKeys: (editor, e) => {
|
|
283
|
+
const [text] = Editor.nodes(editor, {
|
|
284
|
+
match: n => Text.isText(n)
|
|
285
|
+
});
|
|
286
|
+
if (text) {
|
|
287
|
+
const [node, path] = text;
|
|
288
|
+
const cursorInSearchResult = node.searchResult &&
|
|
289
|
+
editor.selection?.anchor.path[0] === path[0] &&
|
|
290
|
+
editor.selection?.anchor.path[1] === path[1];
|
|
291
|
+
if (cursorInSearchResult && editor.selection) {
|
|
292
|
+
const distanceToStart = editor.selection.anchor.offset;
|
|
293
|
+
const distanceToEnd = node.text.length - editor.selection.anchor.offset;
|
|
294
|
+
// Moves cursor to the start of the search result
|
|
295
|
+
if (e.key === 'ArrowLeft') {
|
|
296
|
+
e.preventDefault();
|
|
297
|
+
Transforms.move(editor, {
|
|
298
|
+
distance: distanceToStart,
|
|
299
|
+
unit: 'character',
|
|
300
|
+
reverse: true
|
|
301
|
+
});
|
|
302
|
+
// Moves cursor to end of search result
|
|
303
|
+
}
|
|
304
|
+
else if (e.key === 'ArrowRight') {
|
|
305
|
+
e.preventDefault();
|
|
306
|
+
Transforms.move(editor, {
|
|
307
|
+
distance: distanceToEnd,
|
|
308
|
+
unit: 'character'
|
|
309
|
+
});
|
|
310
|
+
// Moves cursor to start or end of search result, whichever is closer
|
|
311
|
+
}
|
|
312
|
+
else if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
|
|
313
|
+
e.preventDefault();
|
|
314
|
+
Transforms.move(editor, {
|
|
315
|
+
distance: distanceToStart <= distanceToEnd ? distanceToStart : distanceToEnd,
|
|
316
|
+
unit: 'character',
|
|
317
|
+
reverse: distanceToStart <= distanceToEnd
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
},
|
|
202
323
|
// Either adds a tab character or indents a list depending on the selection
|
|
203
324
|
indent: (editor) => {
|
|
204
325
|
const [nodeInListItem] = Editor.nodes(editor, {
|
|
@@ -283,22 +404,14 @@ const commands = {
|
|
|
283
404
|
commandExecuted = true;
|
|
284
405
|
}
|
|
285
406
|
}
|
|
286
|
-
else if (e.
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
commandExecuted = true;
|
|
291
|
-
break;
|
|
292
|
-
default:
|
|
407
|
+
else if (e.keyCode === 77) {
|
|
408
|
+
if (e.shiftKey) {
|
|
409
|
+
commands.unindent(editor);
|
|
410
|
+
commandExecuted = true;
|
|
293
411
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
case 77:
|
|
298
|
-
commands.indent(editor);
|
|
299
|
-
commandExecuted = true;
|
|
300
|
-
break;
|
|
301
|
-
default:
|
|
412
|
+
else {
|
|
413
|
+
commands.indent(editor);
|
|
414
|
+
commandExecuted = true;
|
|
302
415
|
}
|
|
303
416
|
}
|
|
304
417
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorCommands.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/EditorCommands.ts"],"names":[],"mappings":"AACA,OAAO,EACL,MAAM,EACN,UAAU,EACV,KAAK,EACL,IAAI,EAGJ,OAAO,EACP,IAAI,EAEL,MAAM,OAAO,CAAC;AAEf,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAE1C,MAAM,kBAAkB,GAAuC;IAC7D,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;CAChB,CAAC;AAEF,MAAM,QAAQ,GAAG;IACf,uCAAuC;IACvC,cAAc,EAAE,CAAC,MAAmC,EAAE,MAAc,EAAE,EAAE;QACtE,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACnC,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;IAChD,CAAC;IACD,qCAAqC;IACrC,YAAY,EAAE,CAAC,MAAmC,EAAE,MAAc,EAAE,EAAE;QACpE,MAAM,YAAY,GAAG,QAAQ,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC7D,IAAI,YAAY,EAAE;YAChB,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;SACnC;aAAM;YACL,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;SACtC;IACH,CAAC;IACD,2CAA2C;IAC3C,aAAa,EAAE,CAAC,MAAuB,EAAE,MAAc,EAAE,EAAE;QACzD,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAU,MAAM,EAAE;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AC;iBACxB;aACF;iBAAM,IAAI,CAAC,CAAC,QAAQ,EAAE;gBACrB,QAAQ,CAAC,CAAC,OAAO,EAAE;oBACjB,KAAK,EAAE;wBACL,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;wBAC1B,eAAe,GAAG,IAAI,CAAC;wBACvB,MAAM;oBACR,QAAQ;iBACT;aACF;iBAAM;gBACL,QAAQ,CAAC,CAAC,OAAO,EAAE;oBACjB,KAAK,EAAE;wBACL,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;wBACxB,eAAe,GAAG,IAAI,CAAC;wBACvB,MAAM;oBACR,QAAQ;iBACT;aACF;SACF;QAED,IAAI,eAAe;YAAE,CAAC,CAAC,cAAc,EAAE,CAAC;IAC1C,CAAC;CACF,CAAC;AAEF,eAAe,QAAQ,CAAC","sourcesContent":["import { KeyboardEvent } from 'react';\nimport {\n Editor,\n Transforms,\n Range,\n Path,\n NodeEntry,\n Node,\n Element,\n Text,\n CosmosCustom\n} from 'slate';\n\nimport ListCommands from './ListCommands';\n\nconst textKeyCodeMapping: { [key: number]: Element['type'] } = {\n 48: 'paragraph',\n 49: 'heading-1',\n 50: 'heading-2',\n 51: 'heading-3',\n 52: 'heading-4'\n};\n\nconst commands = {\n // Checks if an inline format is active\n isFormatActive: (format: Exclude<keyof Text, 'text'>, editor: Editor) => {\n const marks = Editor.marks(editor);\n return marks ? marks[format] === true : false;\n },\n // Toggles an inline format on or off\n toggleFormat: (format: Exclude<keyof Text, 'text'>, editor: Editor) => {\n const formatActive = commands.isFormatActive(format, editor);\n if (formatActive) {\n Editor.removeMark(editor, format);\n } else {\n Editor.addMark(editor, format, true);\n }\n },\n // Checks if a block level format is active\n isBlockActive: (format: Element['type'], editor: Editor) => {\n const [match] = Editor.nodes<Element>(editor, {\n match: n => Element.isElement(n) && n.type === format\n });\n\n return !!match;\n },\n // Gets the active block level type\n getActiveBlockType: (editor: Editor): string => {\n const [match] = Editor.nodes<Element>(editor, {\n at: editor.selection || undefined,\n match: Element.isElement,\n mode: 'lowest'\n });\n\n if (match) {\n return match[0].type;\n }\n return '';\n },\n // Sets the block type of the currently selected block\n setBlock: (format: Element['type'], editor: Editor) => {\n Transforms.setNodes(editor, { type: format }, { mode: 'lowest' });\n },\n // Replaces a target in the editor with the given text\n replaceWithText: (editor: Editor, target: Range | null, text: string) => {\n if (target) {\n Transforms.select(editor, target);\n }\n Transforms.insertText(editor, text);\n Transforms.move(editor);\n },\n // Gets the highest selected block level node\n getSelectedNode: (editor: Editor): NodeEntry<Node> => {\n const [node] = Editor.nodes<Element>(editor, {\n at: editor.selection || undefined,\n match: n => Element.isElement(n),\n mode: 'highest'\n });\n return node;\n },\n // Appends a 3x3 table into the editor and adds a blank line to the bottom\n appendTable: (editor: Editor) => {\n const baseArr: unknown[][] = new Array(3).fill(new Array(3).fill(0));\n const table: [CosmosCustom.TableElement, CosmosCustom.ParagraphElement] = [\n {\n type: 'table',\n children: [\n {\n type: 'table-body',\n children: baseArr.map(row => {\n return {\n type: 'table-row',\n children: row.map(() => {\n return {\n type: 'table-cell',\n children: [{ type: 'paragraph', children: [{ text: '' }] }]\n };\n })\n };\n })\n }\n ]\n },\n {\n type: 'paragraph',\n children: [{ text: '' }]\n }\n ];\n\n Transforms.insertNodes(editor, table, { mode: 'highest' });\n const [firstTableCell] = Editor.nodes<CosmosCustom.ParagraphElement>(editor, {\n at: editor.selection?.anchor.path.slice(0, 1),\n match: n => Element.isElement(n) && n.type === 'paragraph',\n mode: 'highest'\n });\n if (firstTableCell) {\n const [, path] = firstTableCell;\n path.push(0);\n const nextPosition = { path, offset: 0 };\n Transforms.setSelection(editor, { anchor: nextPosition, focus: nextPosition });\n }\n },\n // Finds the image placeholder and replaces it with an image node\n appendImage: (editor: Editor, imageData: { src: string; alt: string }, id: string) => {\n const [node] = Editor.nodes<CosmosCustom.ImagePlaceholderElement>(editor, {\n match: n => Element.isElement(n) && n.type === 'image-placeholder',\n at: [Number(id)]\n });\n\n if (node) {\n const [, path] = node;\n Transforms.setNodes(\n editor,\n { type: 'image', src: imageData.src, alt: imageData.alt },\n { at: path }\n );\n Transforms.unsetNodes(editor, 'id', { at: path });\n }\n },\n appendImagePlaceholder: (editor: Editor): string => {\n const node = commands.getSelectedNode(editor);\n\n if (node) {\n const [, path] = node;\n const next = Path.next(path);\n Transforms.insertNodes(\n editor,\n { type: 'image-placeholder', children: [{ text: '' }] },\n { at: next }\n );\n return next[0].toString();\n }\n return '';\n },\n // Creates a link at the given selection\n createLink: (editor: Editor, text: string, url: string, selection: Range | null) => {\n const linkNode = { text: text || url, href: url };\n if (selection) {\n if (Range.isCollapsed(selection)) {\n const [node] = Editor.node(editor, selection);\n if (Text.isText(node) && node.href) {\n const before = Editor.before(editor, selection, { unit: 'word' });\n const after = Editor.after(editor, selection, { unit: 'word' });\n\n if (before && after) {\n Transforms.insertNodes(editor, [linkNode], { at: { anchor: before, focus: after } });\n } else if (before) {\n const calculatedAfter = Editor.after(editor, before, { unit: 'word' });\n if (calculatedAfter) {\n Transforms.insertNodes(editor, [linkNode], {\n at: { anchor: before, focus: calculatedAfter }\n });\n }\n } else if (after) {\n const calculatedBefore = Editor.before(editor, after, { unit: 'word' });\n if (calculatedBefore) {\n Transforms.insertNodes(editor, [linkNode], {\n at: { anchor: calculatedBefore, focus: after }\n });\n }\n }\n } else {\n Transforms.insertNodes(editor, [linkNode]);\n }\n } else {\n Transforms.insertNodes(editor, [linkNode], {\n at: selection\n });\n }\n } else {\n Transforms.insertNodes(editor, [linkNode]);\n }\n },\n // Used to handle the enter key when the cursor is next to an image, inserts a new paragraph\n checkImageEnter: (editor: Editor, e: KeyboardEvent) => {\n const [image] = Editor.nodes<CosmosCustom.ImageElement>(editor, {\n match: n => Element.isElement(n) && n.type === 'image'\n });\n if (image) {\n if (e.keyCode < 37 && e.keyCode > 40) {\n e.preventDefault();\n }\n if (e.key === 'Enter') {\n e.preventDefault();\n const [, path] = image;\n const next = Path.next(path);\n Transforms.insertNodes(\n editor,\n { type: 'paragraph', children: [{ text: '' }] },\n { at: next }\n );\n Transforms.select(editor, next);\n }\n }\n },\n // Turns the href property off on the text node when space is pressed while on a link\n checkLinkBreak: (editor: Editor, e: KeyboardEvent) => {\n const [link] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n) && !!n.href\n });\n if (link && (e.key === ' ' || e.key === 'Enter')) {\n e.preventDefault();\n Editor.insertNode(editor, { text: e.key === 'Enter' ? '\\n' : ' ' });\n Editor.removeMark(editor, 'href');\n }\n },\n // Either adds a tab character or indents a list depending on the selection\n indent: (editor: Editor) => {\n const [nodeInListItem] = Editor.nodes<CosmosCustom.ListElement>(editor, {\n match: n => Element.isElement(n) && n.type === 'list-item'\n });\n\n if (nodeInListItem) {\n ListCommands.nestList(editor);\n return;\n }\n\n if (editor.selection) {\n let start = Editor.before(editor, editor.selection, { unit: 'block' });\n start = start || Editor.start(editor, editor.selection);\n Transforms.insertText(editor, '\\t', { at: start });\n }\n },\n // Either removes a tab character or un indents a list depending on the selection\n unindent: (editor: Editor) => {\n const [nodeInListItem] = Editor.nodes<CosmosCustom.ListItemElement>(editor, {\n match: n => Element.isElement(n) && n.type === 'list-item'\n });\n\n if (nodeInListItem) {\n ListCommands.unNestList(editor);\n return;\n }\n\n if (editor.selection) {\n let start = Editor.before(editor, editor.selection, { unit: 'block' });\n start = start || Editor.start(editor, editor.selection);\n let end = Editor.after(editor, editor.selection, { unit: 'block' });\n end = end || Editor.end(editor, editor.selection);\n if (start && end) {\n const text = Editor.string(editor, { anchor: start, focus: end });\n const newText = text.replace(/\\t/, '');\n Transforms.insertText(editor, newText, { at: { anchor: start, focus: end } });\n }\n }\n },\n checkKeyCommands: (editor: Editor, e: KeyboardEvent) => {\n const cmdOrCtrl = e.metaKey || e.ctrlKey;\n let commandExecuted = false;\n if (cmdOrCtrl) {\n // Command or Ctrl + Shift\n if (e.shiftKey) {\n switch (e.key) {\n case 'b':\n commands.toggleFormat('bold', editor);\n commandExecuted = true;\n break;\n case 'i':\n commands.toggleFormat('italic', editor);\n commandExecuted = true;\n break;\n case 'x':\n commands.toggleFormat('line-through', editor);\n commandExecuted = true;\n break;\n case 'l':\n ListCommands.toggleList('unordered-list', editor);\n commandExecuted = true;\n break;\n default:\n }\n // Command or Ctrl but not alt\n } else if (!e.shiftKey && !e.altKey) {\n switch (e.key) {\n case 'b':\n commands.toggleFormat('bold', editor);\n commandExecuted = true;\n break;\n case 'i':\n commands.toggleFormat('italic', editor);\n commandExecuted = true;\n break;\n default:\n }\n }\n }\n\n if (e.altKey) {\n if (cmdOrCtrl) {\n if (textKeyCodeMapping[e.keyCode]) {\n commands.setBlock(textKeyCodeMapping[e.keyCode], editor);\n commandExecuted = true;\n }\n } else if (e.shiftKey) {\n switch (e.keyCode) {\n case 77:\n commands.unindent(editor);\n commandExecuted = true;\n break;\n default:\n }\n } else {\n switch (e.keyCode) {\n case 77:\n commands.indent(editor);\n commandExecuted = true;\n break;\n default:\n }\n }\n }\n\n if (commandExecuted) e.preventDefault();\n }\n};\n\nexport default commands;\n"]}
|
|
1
|
+
{"version":3,"file":"EditorCommands.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/EditorCommands.ts"],"names":[],"mappings":"AACA,OAAO,EACL,MAAM,EACN,UAAU,EACV,KAAK,EACL,IAAI,EAGJ,OAAO,EACP,IAAI,EAEL,MAAM,OAAO,CAAC;AAEf,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAE1C,MAAM,kBAAkB,GAAuC;IAC7D,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;CAChB,CAAC;AAEF,MAAM,QAAQ,GAAG;IACf,uCAAuC;IACvC,cAAc,EAAE,CAAC,MAAmC,EAAE,MAAc,EAAE,EAAE;QACtE,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACnC,OAAO,KAAK,CA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aACF;SACF;QAED,IAAI,CAAC,CAAC,MAAM,EAAE;YACZ,IAAI,SAAS,EAAE;gBACb,IAAI,kBAAkB,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE;oBACjC,QAAQ,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC;oBACzD,eAAe,GAAG,IAAI,CAAC;iBACxB;aACF;iBAAM,IAAI,CAAC,CAAC,OAAO,KAAK,EAAE,EAAE;gBAC3B,IAAI,CAAC,CAAC,QAAQ,EAAE;oBACd,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;oBAC1B,eAAe,GAAG,IAAI,CAAC;iBACxB;qBAAM;oBACL,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;oBACxB,eAAe,GAAG,IAAI,CAAC;iBACxB;aACF;SACF;QAED,IAAI,eAAe;YAAE,CAAC,CAAC,cAAc,EAAE,CAAC;IAC1C,CAAC;CACF,CAAC;AAEF,eAAe,QAAQ,CAAC","sourcesContent":["import { KeyboardEvent } from 'react';\nimport {\n Editor,\n Transforms,\n Range,\n Path,\n NodeEntry,\n Node,\n Element,\n Text,\n CosmosCustom\n} from 'slate';\n\nimport ListCommands from './ListCommands';\n\nconst textKeyCodeMapping: { [key: number]: Element['type'] } = {\n 48: 'paragraph',\n 49: 'heading-1',\n 50: 'heading-2',\n 51: 'heading-3',\n 52: 'heading-4'\n};\n\nconst commands = {\n // Checks if an inline format is active\n isFormatActive: (format: Exclude<keyof Text, 'text'>, editor: Editor) => {\n const marks = Editor.marks(editor);\n return marks ? marks[format] === true : false;\n },\n // Toggles an inline format on or off\n toggleFormat: (format: Exclude<keyof Text, 'text'>, editor: Editor) => {\n const formatActive = commands.isFormatActive(format, editor);\n if (formatActive) {\n Editor.removeMark(editor, format);\n } else {\n Editor.addMark(editor, format, true);\n }\n },\n // Checks if a block level format is active\n isBlockActive: (format: Element['type'], editor: Editor) => {\n const [match] = Editor.nodes<Element>(editor, {\n match: n => Element.isElement(n) && n.type === format\n });\n\n return !!match;\n },\n // Gets the active block level type\n getActiveBlockType: (editor: Editor): string => {\n const [match] = Editor.nodes<Element>(editor, {\n at: editor.selection || undefined,\n match: Element.isElement,\n mode: 'lowest'\n });\n\n if (match) {\n return match[0].type;\n }\n return '';\n },\n // Sets the block type of the currently selected block\n setBlock: (format: Element['type'], editor: Editor) => {\n Transforms.setNodes(editor, { type: format }, { mode: 'lowest' });\n },\n // Replaces a target in the editor with the given text\n replaceWithText: (editor: Editor, target: Range | null, text: string) => {\n if (target) {\n Transforms.select(editor, target);\n }\n Transforms.insertText(editor, text);\n Transforms.move(editor);\n },\n // Replaces a target in the editor with the given node\n replaceWithNodes: (editor: Editor, target: Range | null, node: Node) => {\n if (target) {\n Transforms.select(editor, target);\n }\n Transforms.insertNodes(editor, node);\n Transforms.move(editor);\n },\n // Gets the highest selected block level node\n getSelectedNode: (editor: Editor): NodeEntry<Node> => {\n const [node] = Editor.nodes<Element>(editor, {\n at: editor.selection || undefined,\n match: n => Element.isElement(n),\n mode: 'highest'\n });\n return node;\n },\n // Appends a 3x3 table into the editor and adds a blank line to the bottom\n appendTable: (editor: Editor) => {\n const baseArr: unknown[][] = new Array(3).fill(new Array(3).fill(0));\n const table: [CosmosCustom.TableElement, CosmosCustom.ParagraphElement] = [\n {\n type: 'table',\n children: [\n {\n type: 'table-body',\n children: baseArr.map(row => {\n return {\n type: 'table-row',\n children: row.map(() => {\n return {\n type: 'table-cell',\n children: [{ type: 'paragraph', children: [{ text: '' }] }]\n };\n })\n };\n })\n }\n ]\n },\n {\n type: 'paragraph',\n children: [{ text: '' }]\n }\n ];\n\n Transforms.insertNodes(editor, table, { mode: 'highest' });\n const [firstTableCell] = Editor.nodes<CosmosCustom.ParagraphElement>(editor, {\n at: editor.selection?.anchor.path.slice(0, 1),\n match: n => Element.isElement(n) && n.type === 'paragraph',\n mode: 'highest'\n });\n if (firstTableCell) {\n const [, path] = firstTableCell;\n path.push(0);\n const nextPosition = { path, offset: 0 };\n Transforms.setSelection(editor, { anchor: nextPosition, focus: nextPosition });\n }\n },\n // Finds the image placeholder and replaces it with an image node\n appendImage: (editor: Editor, imageData: { src: string; alt: string }, id: string) => {\n const [node] = Editor.nodes<CosmosCustom.ImagePlaceholderElement>(editor, {\n match: n => Element.isElement(n) && n.type === 'image-placeholder',\n at: [Number(id)]\n });\n\n if (node) {\n const [, path] = node;\n Transforms.setNodes(\n editor,\n { type: 'image', src: imageData.src, alt: imageData.alt },\n { at: path }\n );\n Transforms.unsetNodes(editor, 'id', { at: path });\n return Editor.end(editor, path);\n }\n return null;\n },\n appendImagePlaceholder: (editor: Editor): string => {\n const node = commands.getSelectedNode(editor);\n\n if (node) {\n const [, path] = node;\n const next = Path.next(path);\n Transforms.insertNodes(\n editor,\n { type: 'image-placeholder', children: [{ text: '' }] },\n { at: next }\n );\n return next[0].toString();\n }\n return '';\n },\n // Creates a link at the given selection\n createLink: (editor: Editor, text: string, url: string, selection: Range | null) => {\n const linkNode = { text: text || url, href: url };\n if (selection) {\n if (Range.isCollapsed(selection)) {\n const [node] = Editor.node(editor, selection);\n if (Text.isText(node) && node.href) {\n const before = Editor.before(editor, selection, { unit: 'word' });\n const after = Editor.after(editor, selection, { unit: 'word' });\n\n if (before && after) {\n Transforms.insertNodes(editor, [linkNode], { at: { anchor: before, focus: after } });\n } else if (before) {\n const calculatedAfter = Editor.after(editor, before, { unit: 'word' });\n if (calculatedAfter) {\n Transforms.insertNodes(editor, [linkNode], {\n at: { anchor: before, focus: calculatedAfter }\n });\n }\n } else if (after) {\n const calculatedBefore = Editor.before(editor, after, { unit: 'word' });\n if (calculatedBefore) {\n Transforms.insertNodes(editor, [linkNode], {\n at: { anchor: calculatedBefore, focus: after }\n });\n }\n }\n } else {\n Transforms.insertNodes(editor, [linkNode]);\n }\n } else {\n Transforms.insertNodes(editor, [linkNode], {\n at: selection\n });\n }\n } else {\n Transforms.insertNodes(editor, [linkNode]);\n }\n },\n // Used to handle the enter key when the cursor is next to an image, inserts a new paragraph\n checkImageEnter: (editor: Editor, e: KeyboardEvent) => {\n const [image] = Editor.nodes<CosmosCustom.ImageElement>(editor, {\n match: n => Element.isElement(n) && n.type === 'image'\n });\n if (image) {\n if (e.keyCode < 37 && e.keyCode > 40) {\n e.preventDefault();\n }\n if (e.key === 'Enter') {\n e.preventDefault();\n const [, path] = image;\n const next = Path.next(path);\n Transforms.insertNodes(\n editor,\n { type: 'paragraph', children: [{ text: '' }] },\n { at: next }\n );\n Transforms.select(editor, next);\n }\n }\n },\n // Turns the href property off on the text node when space is pressed while on a link\n checkLinkBreak: (editor: Editor, e: KeyboardEvent) => {\n const [link] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n) && !!n.href\n });\n if (link && (e.key === ' ' || e.key === 'Enter')) {\n e.preventDefault();\n Editor.insertNode(editor, { text: e.key === 'Enter' ? '\\n' : ' ' });\n Editor.removeMark(editor, 'href');\n }\n },\n /**\n * Turns the searchResult property off on the text node when any key is pressed while on a searchResult.\n * Will delete the searchResult node if backspace key is hit.\n * Will re-position cursor to the start/end of the searchResult if arrow navigation is used.\n */\n checkSearchDownKeys: (editor: Editor, e: KeyboardEvent) => {\n const [text] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n)\n });\n\n if (text) {\n const [node, path] = text;\n const nextNode = Editor.next(editor)?.[0] as Text;\n const nextPath = Editor.next(editor)?.[1];\n const previousNode = Editor.previous(editor)?.[0] as Text;\n const previousPath = Editor.previous(editor)?.[1];\n\n const next = nextNode && nextNode.searchResult;\n const nextInline = next && path[0] === nextPath?.[0];\n const previous = previousNode && previousNode.searchResult;\n const previousInline = previous && path[0] === previousPath?.[0];\n\n // Checks if the current selection is a single cursor point rather than spanning multiple characters\n const singlePointSelection =\n editor.selection?.anchor.offset === editor.selection?.focus.offset &&\n editor.selection?.anchor.path[0] === editor.selection?.focus.path[0] &&\n editor.selection?.anchor.path[1] === editor.selection?.focus.path[1];\n\n // Checks if the current selected node is a search result, or directly adjacent inline with a search result\n if (node.searchResult || (next && nextInline) || (previous && previousInline)) {\n const atStart = node.searchResult && editor.selection?.anchor.offset === 0;\n const atEnd = node.searchResult && editor.selection?.anchor.offset === node.text.length;\n\n // Deletes the entire search result only if the cursor is at the end of the search result\n if (e.key === 'Backspace' && (atEnd || (previous && previousInline))) {\n if (singlePointSelection) e.preventDefault();\n Transforms.delete(editor, { at: previous ? previousPath : path });\n // Deletes the entire search result only if the cursor is at the start of the search result\n } else if (e.key === 'Delete' && (atStart || (next && nextInline))) {\n if (singlePointSelection) e.preventDefault();\n Transforms.delete(editor, { at: next ? nextPath : path });\n // Moves cursor to start of search result only if the cursor is at the end of the search result\n } else if (e.key === 'ArrowLeft' && (atEnd || (previous && previousInline))) {\n if (singlePointSelection) e.preventDefault();\n Transforms.move(editor, {\n distance: previous ? previousNode.text.length : node.text.length,\n unit: 'character',\n reverse: true\n });\n // Moves cursor to end of search result only if the cursor is at the start of the search result\n } else if (e.key === 'ArrowRight' && (atStart || (next && nextInline))) {\n if (singlePointSelection) e.preventDefault();\n Transforms.move(editor, {\n distance: next ? nextNode.text.length : node.text.length,\n unit: 'character'\n });\n // Ensures all other character (besides special key bindings) are inserted as plain text\n } else if (e.key.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey) {\n e.preventDefault();\n Editor.insertNode(editor, { text: e.key === 'Enter' ? '\\n' : e.key });\n }\n\n // Prevents partial search result selections from disabling the searchResult flag\n if (singlePointSelection) {\n Editor.removeMark(editor, 'searchResult');\n }\n }\n }\n },\n // Checks arrow navigation key up events around search results\n checkSearchUpKeys: (editor: Editor, e: KeyboardEvent) => {\n const [text] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n)\n });\n\n if (text) {\n const [node, path] = text;\n\n const cursorInSearchResult =\n node.searchResult &&\n editor.selection?.anchor.path[0] === path[0] &&\n editor.selection?.anchor.path[1] === path[1];\n\n if (cursorInSearchResult && editor.selection) {\n const distanceToStart = editor.selection.anchor.offset;\n const distanceToEnd = node.text.length - editor.selection.anchor.offset;\n // Moves cursor to the start of the search result\n if (e.key === 'ArrowLeft') {\n e.preventDefault();\n Transforms.move(editor, {\n distance: distanceToStart,\n unit: 'character',\n reverse: true\n });\n // Moves cursor to end of search result\n } else if (e.key === 'ArrowRight') {\n e.preventDefault();\n Transforms.move(editor, {\n distance: distanceToEnd,\n unit: 'character'\n });\n // Moves cursor to start or end of search result, whichever is closer\n } else if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {\n e.preventDefault();\n Transforms.move(editor, {\n distance: distanceToStart <= distanceToEnd ? distanceToStart : distanceToEnd,\n unit: 'character',\n reverse: distanceToStart <= distanceToEnd\n });\n }\n }\n }\n },\n // Either adds a tab character or indents a list depending on the selection\n indent: (editor: Editor) => {\n const [nodeInListItem] = Editor.nodes<CosmosCustom.ListElement>(editor, {\n match: n => Element.isElement(n) && n.type === 'list-item'\n });\n\n if (nodeInListItem) {\n ListCommands.nestList(editor);\n return;\n }\n\n if (editor.selection) {\n let start = Editor.before(editor, editor.selection, { unit: 'block' });\n start = start || Editor.start(editor, editor.selection);\n Transforms.insertText(editor, '\\t', { at: start });\n }\n },\n // Either removes a tab character or un indents a list depending on the selection\n unindent: (editor: Editor) => {\n const [nodeInListItem] = Editor.nodes<CosmosCustom.ListItemElement>(editor, {\n match: n => Element.isElement(n) && n.type === 'list-item'\n });\n\n if (nodeInListItem) {\n ListCommands.unNestList(editor);\n return;\n }\n\n if (editor.selection) {\n let start = Editor.before(editor, editor.selection, { unit: 'block' });\n start = start || Editor.start(editor, editor.selection);\n let end = Editor.after(editor, editor.selection, { unit: 'block' });\n end = end || Editor.end(editor, editor.selection);\n if (start && end) {\n const text = Editor.string(editor, { anchor: start, focus: end });\n const newText = text.replace(/\\t/, '');\n Transforms.insertText(editor, newText, { at: { anchor: start, focus: end } });\n }\n }\n },\n checkKeyCommands: (editor: Editor, e: KeyboardEvent) => {\n const cmdOrCtrl = e.metaKey || e.ctrlKey;\n let commandExecuted = false;\n if (cmdOrCtrl) {\n // Command or Ctrl + Shift\n if (e.shiftKey) {\n switch (e.key) {\n case 'b':\n commands.toggleFormat('bold', editor);\n commandExecuted = true;\n break;\n case 'i':\n commands.toggleFormat('italic', editor);\n commandExecuted = true;\n break;\n case 'x':\n commands.toggleFormat('line-through', editor);\n commandExecuted = true;\n break;\n case 'l':\n ListCommands.toggleList('unordered-list', editor);\n commandExecuted = true;\n break;\n default:\n }\n // Command or Ctrl but not alt\n } else if (!e.shiftKey && !e.altKey) {\n switch (e.key) {\n case 'b':\n commands.toggleFormat('bold', editor);\n commandExecuted = true;\n break;\n case 'i':\n commands.toggleFormat('italic', editor);\n commandExecuted = true;\n break;\n default:\n }\n }\n }\n\n if (e.altKey) {\n if (cmdOrCtrl) {\n if (textKeyCodeMapping[e.keyCode]) {\n commands.setBlock(textKeyCodeMapping[e.keyCode], editor);\n commandExecuted = true;\n }\n } else if (e.keyCode === 77) {\n if (e.shiftKey) {\n commands.unindent(editor);\n commandExecuted = true;\n } else {\n commands.indent(editor);\n commandExecuted = true;\n }\n }\n }\n\n if (commandExecuted) e.preventDefault();\n }\n};\n\nexport default commands;\n"]}
|
|
@@ -9,9 +9,8 @@ const getNextPathBelow = (path) => {
|
|
|
9
9
|
};
|
|
10
10
|
const commands = {
|
|
11
11
|
toggleList: (type, editor) => {
|
|
12
|
-
var _a;
|
|
13
12
|
const [listItemInSelection] = Editor.nodes(editor, {
|
|
14
|
-
at:
|
|
13
|
+
at: editor.selection?.anchor.path || undefined,
|
|
15
14
|
match: matchListItem
|
|
16
15
|
});
|
|
17
16
|
if (!listItemInSelection) {
|
|
@@ -29,20 +28,19 @@ const commands = {
|
|
|
29
28
|
}
|
|
30
29
|
},
|
|
31
30
|
checkListEnter: (editor, event) => {
|
|
32
|
-
var _a, _b, _c;
|
|
33
31
|
/* Gets the list item node at your selection in the lowest part of the tree.
|
|
34
32
|
Your selection could technically be in multiple list items in the tree because
|
|
35
33
|
the lists can be nested. That is what the mode: 'lowest' arg is for. */
|
|
36
34
|
const [listItemNodeEntry] = Editor.nodes(editor, {
|
|
37
|
-
at:
|
|
35
|
+
at: editor.selection?.anchor.path || undefined,
|
|
38
36
|
match: matchListItem,
|
|
39
37
|
mode: 'lowest'
|
|
40
38
|
});
|
|
41
|
-
if (['Backspace', '
|
|
39
|
+
if (['Backspace', 'Enter'].includes(event.key) && listItemNodeEntry) {
|
|
42
40
|
const [listItemNode, listItemPath] = listItemNodeEntry;
|
|
43
41
|
// Getting the text node
|
|
44
42
|
const [[textNode]] = Editor.nodes(editor, {
|
|
45
|
-
at:
|
|
43
|
+
at: editor.selection?.anchor.path || undefined,
|
|
46
44
|
match: Text.isText
|
|
47
45
|
});
|
|
48
46
|
// Getting the parent list-item node
|
|
@@ -95,7 +93,7 @@ const commands = {
|
|
|
95
93
|
// Set the selection to the new list item created
|
|
96
94
|
Transforms.setSelection(editor, { focus: selectionPoint, anchor: selectionPoint });
|
|
97
95
|
}
|
|
98
|
-
else {
|
|
96
|
+
else if (editor.selection?.anchor.offset === 0) {
|
|
99
97
|
commands.unNestList(editor);
|
|
100
98
|
}
|
|
101
99
|
}
|
|
@@ -108,7 +106,7 @@ const commands = {
|
|
|
108
106
|
// Break out of the list
|
|
109
107
|
event.preventDefault();
|
|
110
108
|
Transforms.unwrapNodes(editor, {
|
|
111
|
-
at:
|
|
109
|
+
at: editor.selection?.anchor.path || undefined,
|
|
112
110
|
match: matchListItem
|
|
113
111
|
});
|
|
114
112
|
Transforms.liftNodes(editor);
|
|
@@ -116,15 +114,14 @@ const commands = {
|
|
|
116
114
|
}
|
|
117
115
|
},
|
|
118
116
|
nestList: (editor) => {
|
|
119
|
-
var _a, _b;
|
|
120
117
|
const [listItemNodeEntry] = Editor.nodes(editor, {
|
|
121
|
-
at:
|
|
118
|
+
at: editor.selection?.anchor.path || undefined,
|
|
122
119
|
match: matchListItem,
|
|
123
120
|
mode: 'lowest'
|
|
124
121
|
});
|
|
125
122
|
let listType = 'unordered-list';
|
|
126
123
|
const [highestList] = Editor.nodes(editor, {
|
|
127
|
-
at:
|
|
124
|
+
at: editor.selection?.anchor.path || undefined,
|
|
128
125
|
match: matchList,
|
|
129
126
|
mode: 'highest'
|
|
130
127
|
});
|
|
@@ -231,10 +228,9 @@ const commands = {
|
|
|
231
228
|
}
|
|
232
229
|
},
|
|
233
230
|
unNestList: (editor) => {
|
|
234
|
-
var _a, _b;
|
|
235
231
|
// Get the current node to be un nested
|
|
236
232
|
const [[node, nodePath]] = Editor.nodes(editor, {
|
|
237
|
-
at:
|
|
233
|
+
at: editor.selection?.anchor.path || undefined,
|
|
238
234
|
match: matchListItem,
|
|
239
235
|
mode: 'lowest'
|
|
240
236
|
});
|
|
@@ -316,7 +312,7 @@ const commands = {
|
|
|
316
312
|
children: [...copiedChildren]
|
|
317
313
|
}, { at: nextPath });
|
|
318
314
|
const [[newParentList, newParentListPath]] = Editor.nodes(editor, {
|
|
319
|
-
at:
|
|
315
|
+
at: editor.selection?.anchor.path || undefined,
|
|
320
316
|
match: matchList,
|
|
321
317
|
mode: 'lowest'
|
|
322
318
|
});
|