@pega/cosmos-react-rte 2.0.0-dev.10.0 → 2.0.0-dev.13.0
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/Table.d.ts +2 -0
- package/lib/components/RichTextEditor/DecoratorComponents/Table.d.ts.map +1 -1
- package/lib/components/RichTextEditor/DecoratorComponents/Table.js +4 -3
- package/lib/components/RichTextEditor/DecoratorComponents/Table.js.map +1 -1
- package/lib/components/RichTextEditor/RichTextEditor.context.d.ts +2 -2
- package/lib/components/RichTextEditor/RichTextEditor.context.d.ts.map +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 +39 -42
- package/lib/components/RichTextEditor/RichTextEditor.js.map +1 -1
- package/lib/components/RichTextEditor/RichTextEditor.styles.d.ts +2 -0
- package/lib/components/RichTextEditor/RichTextEditor.styles.d.ts.map +1 -1
- package/lib/components/RichTextEditor/RichTextEditor.styles.js +96 -45
- package/lib/components/RichTextEditor/RichTextEditor.styles.js.map +1 -1
- package/lib/components/RichTextEditor/RichTextViewer.d.ts.map +1 -1
- package/lib/components/RichTextEditor/RichTextViewer.js +7 -16
- package/lib/components/RichTextEditor/RichTextViewer.js.map +1 -1
- package/lib/components/RichTextEditor/Toolbar/AnchorButton.js +7 -12
- package/lib/components/RichTextEditor/Toolbar/AnchorButton.js.map +1 -1
- package/lib/components/RichTextEditor/Toolbar/ImageButton.js +3 -5
- package/lib/components/RichTextEditor/Toolbar/ImageButton.js.map +1 -1
- package/lib/components/RichTextEditor/Toolbar/TextSelect.js +1 -4
- 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 +5 -16
- package/lib/components/RichTextEditor/Toolbar/Toolbar.js.map +1 -1
- package/lib/components/RichTextEditor/Toolbar/ToolbarButton.js +2 -3
- package/lib/components/RichTextEditor/Toolbar/ToolbarButton.js.map +1 -1
- package/lib/components/RichTextEditor/mocks/RichTextEditor.mocks.d.ts +3 -0
- package/lib/components/RichTextEditor/mocks/RichTextEditor.mocks.d.ts.map +1 -0
- package/lib/components/RichTextEditor/mocks/RichTextEditor.mocks.js +36 -0
- package/lib/components/RichTextEditor/mocks/RichTextEditor.mocks.js.map +1 -0
- package/lib/components/RichTextEditor/utils/EditorCommands.d.ts.map +1 -1
- package/lib/components/RichTextEditor/utils/EditorCommands.js +21 -32
- package/lib/components/RichTextEditor/utils/EditorCommands.js.map +1 -1
- package/lib/components/RichTextEditor/utils/ListCommands.js +8 -12
- 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 +2 -2
- package/lib/components/RichTextEditor/utils/htmlConverter.js.map +1 -1
- package/lib/components/RichTextEditor/utils/interactionRenderer.js +1 -1
- package/lib/components/RichTextEditor/utils/interactionRenderer.js.map +1 -1
- package/lib/components/RichTextEditor/utils/markdownConverter.d.ts.map +1 -1
- package/lib/components/RichTextEditor/utils/markdownConverter.js +4 -7
- package/lib/components/RichTextEditor/utils/markdownConverter.js.map +1 -1
- package/lib/components/RichTextEditor/utils/renderers.js +1 -2
- package/lib/components/RichTextEditor/utils/renderers.js.map +1 -1
- package/lib/components/RichTextEditor/utils/search.js +1 -2
- 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 +14 -12
|
@@ -73,7 +73,6 @@ const commands = {
|
|
|
73
73
|
},
|
|
74
74
|
// Appends a 3x3 table into the editor and adds a blank line to the bottom
|
|
75
75
|
appendTable: (editor) => {
|
|
76
|
-
var _a;
|
|
77
76
|
const baseArr = new Array(3).fill(new Array(3).fill(0));
|
|
78
77
|
const table = [
|
|
79
78
|
{
|
|
@@ -102,7 +101,7 @@ const commands = {
|
|
|
102
101
|
];
|
|
103
102
|
Transforms.insertNodes(editor, table, { mode: 'highest' });
|
|
104
103
|
const [firstTableCell] = Editor.nodes(editor, {
|
|
105
|
-
at:
|
|
104
|
+
at: editor.selection?.anchor.path.slice(0, 1),
|
|
106
105
|
match: n => Element.isElement(n) && n.type === 'paragraph',
|
|
107
106
|
mode: 'highest'
|
|
108
107
|
});
|
|
@@ -213,28 +212,27 @@ const commands = {
|
|
|
213
212
|
* Will re-position cursor to the start/end of the searchResult if arrow navigation is used.
|
|
214
213
|
*/
|
|
215
214
|
checkSearchDownKeys: (editor, e) => {
|
|
216
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
217
215
|
const [text] = Editor.nodes(editor, {
|
|
218
216
|
match: n => Text.isText(n)
|
|
219
217
|
});
|
|
220
218
|
if (text) {
|
|
221
219
|
const [node, path] = text;
|
|
222
|
-
const nextNode =
|
|
223
|
-
const nextPath =
|
|
224
|
-
const previousNode =
|
|
225
|
-
const previousPath =
|
|
220
|
+
const nextNode = Editor.next(editor)?.[0];
|
|
221
|
+
const nextPath = Editor.next(editor)?.[1];
|
|
222
|
+
const previousNode = Editor.previous(editor)?.[0];
|
|
223
|
+
const previousPath = Editor.previous(editor)?.[1];
|
|
226
224
|
const next = nextNode && nextNode.searchResult;
|
|
227
|
-
const nextInline = next && path[0] ===
|
|
225
|
+
const nextInline = next && path[0] === nextPath?.[0];
|
|
228
226
|
const previous = previousNode && previousNode.searchResult;
|
|
229
|
-
const previousInline = previous && path[0] ===
|
|
227
|
+
const previousInline = previous && path[0] === previousPath?.[0];
|
|
230
228
|
// Checks if the current selection is a single cursor point rather than spanning multiple characters
|
|
231
|
-
const singlePointSelection =
|
|
232
|
-
|
|
233
|
-
|
|
229
|
+
const singlePointSelection = editor.selection?.anchor.offset === editor.selection?.focus.offset &&
|
|
230
|
+
editor.selection?.anchor.path[0] === editor.selection?.focus.path[0] &&
|
|
231
|
+
editor.selection?.anchor.path[1] === editor.selection?.focus.path[1];
|
|
234
232
|
// Checks if the current selected node is a search result, or directly adjacent inline with a search result
|
|
235
233
|
if (node.searchResult || (next && nextInline) || (previous && previousInline)) {
|
|
236
|
-
const atStart = node.searchResult &&
|
|
237
|
-
const atEnd = node.searchResult &&
|
|
234
|
+
const atStart = node.searchResult && editor.selection?.anchor.offset === 0;
|
|
235
|
+
const atEnd = node.searchResult && editor.selection?.anchor.offset === node.text.length;
|
|
238
236
|
// Deletes the entire search result only if the cursor is at the end of the search result
|
|
239
237
|
if (e.key === 'Backspace' && (atEnd || (previous && previousInline))) {
|
|
240
238
|
if (singlePointSelection)
|
|
@@ -280,15 +278,14 @@ const commands = {
|
|
|
280
278
|
},
|
|
281
279
|
// Checks arrow navigation key up events around search results
|
|
282
280
|
checkSearchUpKeys: (editor, e) => {
|
|
283
|
-
var _a, _b;
|
|
284
281
|
const [text] = Editor.nodes(editor, {
|
|
285
282
|
match: n => Text.isText(n)
|
|
286
283
|
});
|
|
287
284
|
if (text) {
|
|
288
285
|
const [node, path] = text;
|
|
289
286
|
const cursorInSearchResult = node.searchResult &&
|
|
290
|
-
|
|
291
|
-
|
|
287
|
+
editor.selection?.anchor.path[0] === path[0] &&
|
|
288
|
+
editor.selection?.anchor.path[1] === path[1];
|
|
292
289
|
if (cursorInSearchResult && editor.selection) {
|
|
293
290
|
const distanceToStart = editor.selection.anchor.offset;
|
|
294
291
|
const distanceToEnd = node.text.length - editor.selection.anchor.offset;
|
|
@@ -405,22 +402,14 @@ const commands = {
|
|
|
405
402
|
commandExecuted = true;
|
|
406
403
|
}
|
|
407
404
|
}
|
|
408
|
-
else if (e.
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
commandExecuted = true;
|
|
413
|
-
break;
|
|
414
|
-
default:
|
|
405
|
+
else if (e.keyCode === 77) {
|
|
406
|
+
if (e.shiftKey) {
|
|
407
|
+
commands.unindent(editor);
|
|
408
|
+
commandExecuted = true;
|
|
415
409
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
case 77:
|
|
420
|
-
commands.indent(editor);
|
|
421
|
-
commandExecuted = true;
|
|
422
|
-
break;
|
|
423
|
-
default:
|
|
410
|
+
else {
|
|
411
|
+
commands.indent(editor);
|
|
412
|
+
commandExecuted = true;
|
|
424
413
|
}
|
|
425
414
|
}
|
|
426
415
|
}
|
|
@@ -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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BACjC,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,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 // 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 }\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.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,EA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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 }\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,12 +28,11 @@ 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
|
});
|
|
@@ -42,7 +40,7 @@ const commands = {
|
|
|
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
|
|
@@ -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
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListCommands.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/ListCommands.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAQ,OAAO,EAAE,IAAI,EAAE,UAAU,EAAgB,IAAI,EAAa,MAAM,OAAO,CAAC;AAE/F,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AASvD,MAAM,SAAS,GAAG,CAAC,CAAO,EAAiC,EAAE,CAC3D,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAEtD,MAAM,aAAa,GAAG,CAAC,CAAO,EAAqC,EAAE,CACnE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC;AAEjD,MAAM,gBAAgB,GAAG,CAAC,IAAU,EAAE,EAAE;IACtC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IAClD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,QAAQ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AAM,CAAC,IAAI,KAAI,SAAS;oBAC9C,KAAK,EAAE,SAAS;oBAChB,IAAI,EAAE,QAAQ;iBACf,CAAC,CAAC;gBAEH,IAAI,KAAK,GAAG,CAAC,CAAC;gBACd,oDAAoD;gBACpD,UAAU,CAAC,QAAQ,CACjB,MAAM,EACN;oBACE,QAAQ,EAAE,IAAI,CAAC,EAAE;oBACjB,KAAK;iBACN,EACD;oBACE,KAAK,EAAE,CAAC,CAAC,EAAE;wBACT,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;4BAAE,OAAO,KAAK,CAAC;wBAEpC,IAAI,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,EAAE;4BAAE,KAAK,IAAI,CAAC,CAAC;wBACvC,OAAO,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,EAAE,CAAC;oBAChC,CAAC;iBACF,CACF,CAAC;gBAEF,iEAAiE;gBACjE,KAAK,IAAI,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,EAAE;oBACvE,MAAM,SAAS,GAAG,CAAC,GAAG,iBAAiB,EAAE,CAAC,CAAC,CAAC;oBAC5C,UAAU,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;iBACzE;aACF;YAED,6EAA6E;YAC7E,UAAU,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;YACvD,UAAU,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;SACxD;IACH,CAAC;CACF,CAAC;AAEF,eAAe,QAAQ,CAAC","sourcesContent":["import { KeyboardEvent } from 'react';\nimport { Editor, Node, Element, Path, Transforms, CosmosCustom, Text, NodeEntry } from 'slate';\n\nimport { createUID } from '@pega/cosmos-react-core';\n\nimport { LIST_TYPES, TEXT_TYPES } from './utils.types';\n\ntype FullListItemElement = CosmosCustom.ListItemElement & {\n id: string;\n parentId: string;\n order: number;\n level: number;\n};\n\nconst matchList = (n: Node): n is CosmosCustom.ListElement =>\n Element.isElement(n) && LIST_TYPES.includes(n.type);\n\nconst matchListItem = (n: Node): n is CosmosCustom.ListItemElement =>\n Element.isElement(n) && n.type === 'list-item';\n\nconst getNextPathBelow = (path: Path) => {\n path[path.length - 1] = path[path.length - 1] + 1;\n return path;\n};\n\nconst commands = {\n toggleList: (type: 'unordered-list' | 'ordered-list', editor: Editor) => {\n const [listItemInSelection] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchListItem\n });\n\n if (!listItemInSelection) {\n Transforms.wrapNodes(editor, { type, children: [] });\n Transforms.wrapNodes(editor, {\n type: 'list-item',\n order: 1,\n level: 1,\n id: createUID(),\n children: []\n });\n } else {\n Transforms.setNodes(editor, { type }, { match: matchList });\n }\n },\n checkListEnter: (editor: Editor, event: KeyboardEvent<any>) => {\n /* Gets the list item node at your selection in the lowest part of the tree.\n Your selection could technically be in multiple list items in the tree because\n the lists can be nested. That is what the mode: 'lowest' arg is for. */\n const [listItemNodeEntry] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchListItem,\n mode: 'lowest'\n });\n\n if (['Backspace', 'Delete', 'Enter'].includes(event.key) && listItemNodeEntry) {\n const [listItemNode, listItemPath] = listItemNodeEntry;\n // Getting the text node\n const [[textNode]] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: Text.isText\n });\n // Getting the parent list-item node\n const [[parentNode]] = Editor.nodes(editor, {\n at: editor.selection || undefined,\n match: matchListItem,\n mode: 'highest'\n });\n\n let belowListItemPath;\n try {\n belowListItemPath = Path.next(listItemPath);\n } catch {\n belowListItemPath = undefined;\n }\n\n if (textNode.text !== '') {\n // If the text node the selection is in is not empty, and the key that was pressed is Enter\n if (event.key === 'Enter') {\n event.preventDefault();\n const newId = createUID();\n const copiedChildren: Element[] = [];\n // If this list-item has another list nested inside of it\n if (listItemNode.children.length === 2) {\n // Copy the list nested inside\n const copiedList = { ...listItemNode.children[1] } as CosmosCustom.ListElement;\n // Add a new parentId to all the children in the list\n copiedList.children = copiedList.children.map(node => {\n return { ...node, parentId: newId };\n });\n copiedChildren.push(copiedList);\n // Remove the list\n Transforms.removeNodes(editor, { at: [...listItemPath, 1] });\n }\n /* Create a new list item with the copied children as it's children,\n and insert it into the editor */\n Transforms.insertNodes(editor, {\n type: 'list-item',\n order: listItemNode.order ? listItemNode.order + 1 : 0,\n level: listItemNode.level ? listItemNode.level : 1,\n id: newId,\n parentId: parentNode.id,\n children: [{ type: 'paragraph', children: [{ text: '' }] }, ...copiedChildren]\n });\n /* Nodes needs to be lifted one level higher because it will be inserted\n into the list item itself rather than it's parent list */\n Transforms.liftNodes<CosmosCustom.ListItemElement>(editor, {\n match: n => matchListItem(n) && n.id === newId\n });\n const selectionPoint = { path: [...Path.next(listItemPath), 0, 0], offset: 0 };\n // Set the selection to the new list item created\n Transforms.setSelection(editor, { focus: selectionPoint, anchor: selectionPoint });\n } else {\n commands.unNestList(editor);\n }\n } else if (parentNode && parentNode.children.length > 1) {\n // Un nest this list item from it's parent\n event.preventDefault();\n commands.unNestList(editor);\n } else if (belowListItemPath) {\n // Break out of the list\n event.preventDefault();\n Transforms.unwrapNodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchListItem\n });\n Transforms.liftNodes(editor);\n }\n }\n },\n nestList: (editor: Editor) => {\n const [listItemNodeEntry] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchListItem,\n mode: 'lowest'\n });\n\n let listType: `${'un' | ''}ordered-list` = 'unordered-list';\n const [highestList] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchList,\n mode: 'highest'\n });\n\n if (highestList) {\n listType = highestList[0].type;\n }\n\n const [listItemNode, listItemPath] = (listItemNodeEntry as NodeEntry<FullListItemElement>) || [\n undefined,\n undefined\n ];\n\n // Try to find the path to the node above the selected list item\n let abovePath;\n try {\n abovePath = Path.previous(listItemPath);\n } catch {\n abovePath = undefined;\n }\n\n // Only nest the list if there is a list item above the list item trying to be nested\n if (listItemNode && abovePath && listItemNode.level < 3) {\n // Get the list item and it's path from above the current list item\n const [[aboveListItemNode, aboveListItemPath]] = Editor.nodes<CosmosCustom.ListItemElement>(\n editor,\n {\n at: abovePath,\n match: n => matchListItem(n) && n.level === listItemNode.level\n }\n );\n // Gets the path for the text node above list-item\n const [[, innerTextNodePath]] = Editor.nodes<CosmosCustom.TextElement>(editor, {\n at: abovePath,\n match: n => Element.isElement(n) && TEXT_TYPES.includes(n.type)\n });\n\n let copiedSubListNodes: CosmosCustom.ListItemElement[] = [];\n const newListItemChildren = [listItemNode.children[0]];\n if (listItemNode.children.length && listItemNode.children.length > 1) {\n // Copy the item to be nested's sub list if it has one\n const subList = listItemNode.children[1] as CosmosCustom.ListElement;\n if (subList) {\n copiedSubListNodes = [...subList.children];\n }\n }\n\n // If the above list item has a sub list\n if (aboveListItemNode.children.length > 1) {\n // Get the list items in the sub list of the above list item\n const { children } = aboveListItemNode.children[1] as CosmosCustom.ListElement;\n // Gets the last list item in the above sub list\n const [[parentSubListItem, parentSubListItemPath]] = Editor.nodes<FullListItemElement>(\n editor,\n {\n at: aboveListItemPath,\n match: n =>\n matchListItem(n) &&\n n.order === children.length &&\n (n.level as number) - 1 === listItemNode.level\n }\n );\n\n // Gets the path after the last list item in the above sub list\n const nextParentSubListItemPath = Path.next(parentSubListItemPath);\n\n /* Inserts a copy of the list-item you are nesting below the lowest list item\n in the above sub list, as well as copies of any children the list-item you are\n nesting had. */\n let subOrderCount = parentSubListItem.order + 1;\n Transforms.insertNodes(\n editor,\n [\n {\n ...listItemNode,\n level: listItemNode.level + 1,\n order: parentSubListItem.order + 1,\n parentId: aboveListItemNode.id,\n children: newListItemChildren\n },\n ...copiedSubListNodes.map(n => {\n subOrderCount += 1;\n return {\n ...n,\n level: listItemNode.level + 1,\n order: subOrderCount,\n parentId: aboveListItemNode.id\n };\n })\n ],\n { at: nextParentSubListItemPath }\n );\n } else {\n const nextInnerTextNodePath = getNextPathBelow(innerTextNodePath);\n // Nest the selected list item into a new list and then into the above list item\n let subOrderCount = 1;\n Transforms.insertNodes(\n editor,\n {\n type: listType,\n children: [\n {\n ...listItemNode,\n order: 1,\n level: listItemNode.level + 1,\n parentId: aboveListItemNode.id,\n children: newListItemChildren\n },\n ...copiedSubListNodes.map(n => {\n subOrderCount += 1;\n return {\n ...n,\n level: listItemNode.level + 1,\n order: subOrderCount,\n parentId: aboveListItemNode.id\n };\n })\n ]\n },\n { at: nextInnerTextNodePath, mode: 'lowest' }\n );\n }\n\n // Remove the old list item as we just copied it into the correct place\n Transforms.removeNodes(editor, { at: listItemPath });\n }\n },\n unNestList: (editor: Editor) => {\n // Get the current node to be un nested\n const [[node, nodePath]] = Editor.nodes<FullListItemElement>(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchListItem,\n mode: 'lowest'\n });\n const [singleItemList] = Editor.nodes<CosmosCustom.ListElement>(editor, {\n match: n => matchList(n) && n.children.length === 1,\n mode: 'highest'\n });\n\n if (singleItemList) {\n Transforms.unwrapNodes(editor, { match: matchListItem });\n Transforms.unwrapNodes(editor, { match: matchList });\n return;\n }\n // Attempt to get the highest parent in the nested list if it exists\n const [highestParent] = Editor.nodes<FullListItemElement>(editor, {\n at: editor.selection || undefined,\n match: n => matchListItem(n) && node.level - (n.level as number) === 2,\n mode: 'lowest'\n });\n // Get the parent list node if it exists (list item)\n const [[parentNode]] = Editor.nodes<FullListItemElement>(editor, {\n at: editor.selection || undefined,\n match: n => matchListItem(n) && node.level - (n.level as number) === 1,\n mode: 'lowest'\n });\n // Get the parent list\n const [[parentList]] = Editor.nodes(editor, {\n at: editor.selection || undefined,\n match: matchList,\n mode: 'lowest'\n });\n if (parentNode && parentNode.children.length > 1) {\n let newParentId;\n if (highestParent) {\n const [highestParentNode] = highestParent;\n newParentId = highestParentNode.id;\n }\n\n // Setting the node to un nests new order and level\n Transforms.setNodes<CosmosCustom.ListItemElement>(\n editor,\n {\n level: node.level - 1,\n order: parentNode.order + 1\n },\n { at: nodePath, match: n => matchListItem(n) && n.id === node.id }\n );\n\n // Set the level of any children under the node we are un nesting\n Transforms.setNodes<CosmosCustom.ListItemElement>(\n editor,\n { level: node.level },\n {\n at: nodePath,\n match: n => matchListItem(n) && (n.level as number) > node.level\n }\n );\n\n // If there's a new parent id set it, otherwise unset the parent id entirely\n if (newParentId) {\n Transforms.setNodes<CosmosCustom.ListItemElement>(\n editor,\n { parentId: newParentId },\n { at: nodePath, match: n => matchListItem(n) && n.id === node.id }\n );\n } else {\n Transforms.unsetNodes<CosmosCustom.ListItemElement>(editor, 'parentId', {\n at: nodePath,\n match: n => matchListItem(n) && n.id === node.id\n });\n }\n\n const listItemsExistBelow = node.order < parentList.children.length;\n\n if (listItemsExistBelow) {\n // Getting the inner text node inside of the list item in order to get the next path\n const [[, innerTextNodePath]] = Editor.nodes(editor, {\n at: nodePath,\n match: matchList\n });\n const nextPath = Path.next(innerTextNodePath);\n const copiedChildren = [];\n\n let count = 1;\n // Copy the children from the parent list that are below the list item we are un nesting\n for (let i = node.order; i < parentList.children.length; i += 1) {\n copiedChildren.push({\n ...parentList.children[i],\n parentId: node.id,\n order: count\n });\n count += 1;\n }\n\n // Insert a new list with the copied children into the un nested list item\n Transforms.insertNodes(\n editor,\n {\n type: parentList.type,\n children: [...copiedChildren]\n },\n { at: nextPath }\n );\n\n const [[newParentList, newParentListPath]] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchList,\n mode: 'lowest'\n });\n\n let order = 0;\n // Set the nodes below the list item being un nested\n Transforms.setNodes<CosmosCustom.ListItemElement>(\n editor,\n {\n parentId: node.id,\n order\n },\n {\n match: n => {\n if (!matchListItem(n)) return false;\n\n if (n.parentId === node.id) order += 1;\n return n.parentId === node.id;\n }\n }\n );\n\n // Removing all old nodes from that were under the un nested item\n for (let i = newParentList.children.length - 1; i >= node.order; i -= 1) {\n const childPath = [...newParentListPath, i];\n Transforms.removeNodes(editor, { at: childPath, match: matchListItem });\n }\n }\n\n // Lift the current node at the users selection out of it's parent node twice\n Transforms.liftNodes(editor, { match: matchListItem });\n Transforms.liftNodes(editor, { match: matchListItem });\n }\n }\n};\n\nexport default commands;\n"]}
|
|
1
|
+
{"version":3,"file":"ListCommands.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/ListCommands.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAQ,OAAO,EAAE,IAAI,EAAE,UAAU,EAAgB,IAAI,EAAa,MAAM,OAAO,CAAC;AAE/F,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AASvD,MAAM,SAAS,GAAG,CAAC,CAAO,EAAiC,EAAE,CAC3D,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAEtD,MAAM,aAAa,GAAG,CAAC,CAAO,EAAqC,EAAE,CACnE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC;AAEjD,MAAM,gBAAgB,GAAG,CAAC,IAAU,EAAE,EAAE;IACtC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IAClD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,QAAQ,GAAG;IACf,UAAU,EAAE,CAAC,IAAuC,EAAE,MAAc,EAAE,EAAE;QACtE,MAAM,CAAC,mBAAmB,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC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BACjB,KAAK;iBACN,EACD;oBACE,KAAK,EAAE,CAAC,CAAC,EAAE;wBACT,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;4BAAE,OAAO,KAAK,CAAC;wBAEpC,IAAI,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,EAAE;4BAAE,KAAK,IAAI,CAAC,CAAC;wBACvC,OAAO,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,EAAE,CAAC;oBAChC,CAAC;iBACF,CACF,CAAC;gBAEF,iEAAiE;gBACjE,KAAK,IAAI,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,EAAE;oBACvE,MAAM,SAAS,GAAG,CAAC,GAAG,iBAAiB,EAAE,CAAC,CAAC,CAAC;oBAC5C,UAAU,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;iBACzE;aACF;YAED,6EAA6E;YAC7E,UAAU,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;YACvD,UAAU,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;SACxD;IACH,CAAC;CACF,CAAC;AAEF,eAAe,QAAQ,CAAC","sourcesContent":["import { KeyboardEvent } from 'react';\nimport { Editor, Node, Element, Path, Transforms, CosmosCustom, Text, NodeEntry } from 'slate';\n\nimport { createUID } from '@pega/cosmos-react-core';\n\nimport { LIST_TYPES, TEXT_TYPES } from './utils.types';\n\ntype FullListItemElement = CosmosCustom.ListItemElement & {\n id: string;\n parentId: string;\n order: number;\n level: number;\n};\n\nconst matchList = (n: Node): n is CosmosCustom.ListElement =>\n Element.isElement(n) && LIST_TYPES.includes(n.type);\n\nconst matchListItem = (n: Node): n is CosmosCustom.ListItemElement =>\n Element.isElement(n) && n.type === 'list-item';\n\nconst getNextPathBelow = (path: Path) => {\n path[path.length - 1] = path[path.length - 1] + 1;\n return path;\n};\n\nconst commands = {\n toggleList: (type: 'unordered-list' | 'ordered-list', editor: Editor) => {\n const [listItemInSelection] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchListItem\n });\n\n if (!listItemInSelection) {\n Transforms.wrapNodes(editor, { type, children: [] });\n Transforms.wrapNodes(editor, {\n type: 'list-item',\n order: 1,\n level: 1,\n id: createUID(),\n children: []\n });\n } else {\n Transforms.setNodes(editor, { type }, { match: matchList });\n }\n },\n checkListEnter: (editor: Editor, event: KeyboardEvent<any>) => {\n /* Gets the list item node at your selection in the lowest part of the tree.\n Your selection could technically be in multiple list items in the tree because\n the lists can be nested. That is what the mode: 'lowest' arg is for. */\n const [listItemNodeEntry] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchListItem,\n mode: 'lowest'\n });\n\n if (['Backspace', 'Delete', 'Enter'].includes(event.key) && listItemNodeEntry) {\n const [listItemNode, listItemPath] = listItemNodeEntry;\n // Getting the text node\n const [[textNode]] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: Text.isText\n });\n // Getting the parent list-item node\n const [[parentNode]] = Editor.nodes(editor, {\n at: editor.selection || undefined,\n match: matchListItem,\n mode: 'highest'\n });\n\n let belowListItemPath;\n try {\n belowListItemPath = Path.next(listItemPath);\n } catch {\n belowListItemPath = undefined;\n }\n\n if (textNode.text !== '') {\n // If the text node the selection is in is not empty, and the key that was pressed is Enter\n if (event.key === 'Enter') {\n event.preventDefault();\n const newId = createUID();\n const copiedChildren: Element[] = [];\n // If this list-item has another list nested inside of it\n if (listItemNode.children.length === 2) {\n // Copy the list nested inside\n const copiedList = { ...listItemNode.children[1] } as CosmosCustom.ListElement;\n // Add a new parentId to all the children in the list\n copiedList.children = copiedList.children.map(node => {\n return { ...node, parentId: newId };\n });\n copiedChildren.push(copiedList);\n // Remove the list\n Transforms.removeNodes(editor, { at: [...listItemPath, 1] });\n }\n /* Create a new list item with the copied children as it's children,\n and insert it into the editor */\n Transforms.insertNodes(editor, {\n type: 'list-item',\n order: listItemNode.order ? listItemNode.order + 1 : 0,\n level: listItemNode.level ? listItemNode.level : 1,\n id: newId,\n parentId: parentNode.id,\n children: [{ type: 'paragraph', children: [{ text: '' }] }, ...copiedChildren]\n });\n /* Nodes needs to be lifted one level higher because it will be inserted\n into the list item itself rather than it's parent list */\n Transforms.liftNodes<CosmosCustom.ListItemElement>(editor, {\n match: n => matchListItem(n) && n.id === newId\n });\n const selectionPoint = { path: [...Path.next(listItemPath), 0, 0], offset: 0 };\n // Set the selection to the new list item created\n Transforms.setSelection(editor, { focus: selectionPoint, anchor: selectionPoint });\n } else {\n commands.unNestList(editor);\n }\n } else if (parentNode && parentNode.children.length > 1) {\n // Un nest this list item from it's parent\n event.preventDefault();\n commands.unNestList(editor);\n } else if (belowListItemPath) {\n // Break out of the list\n event.preventDefault();\n Transforms.unwrapNodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchListItem\n });\n Transforms.liftNodes(editor);\n }\n }\n },\n nestList: (editor: Editor) => {\n const [listItemNodeEntry] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchListItem,\n mode: 'lowest'\n });\n\n let listType: `${'un' | ''}ordered-list` = 'unordered-list';\n const [highestList] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchList,\n mode: 'highest'\n });\n\n if (highestList) {\n listType = highestList[0].type;\n }\n\n const [listItemNode, listItemPath] = (listItemNodeEntry as NodeEntry<FullListItemElement>) || [\n undefined,\n undefined\n ];\n\n // Try to find the path to the node above the selected list item\n let abovePath;\n try {\n abovePath = Path.previous(listItemPath);\n } catch {\n abovePath = undefined;\n }\n\n // Only nest the list if there is a list item above the list item trying to be nested\n if (listItemNode && abovePath && listItemNode.level < 3) {\n // Get the list item and it's path from above the current list item\n const [[aboveListItemNode, aboveListItemPath]] = Editor.nodes<CosmosCustom.ListItemElement>(\n editor,\n {\n at: abovePath,\n match: n => matchListItem(n) && n.level === listItemNode.level\n }\n );\n // Gets the path for the text node above list-item\n const [[, innerTextNodePath]] = Editor.nodes<CosmosCustom.TextElement>(editor, {\n at: abovePath,\n match: n => Element.isElement(n) && TEXT_TYPES.includes(n.type)\n });\n\n let copiedSubListNodes: CosmosCustom.ListItemElement[] = [];\n const newListItemChildren = [listItemNode.children[0]];\n if (listItemNode.children.length && listItemNode.children.length > 1) {\n // Copy the item to be nested's sub list if it has one\n const subList = listItemNode.children[1] as CosmosCustom.ListElement;\n if (subList) {\n copiedSubListNodes = [...subList.children];\n }\n }\n\n // If the above list item has a sub list\n if (aboveListItemNode.children.length > 1) {\n // Get the list items in the sub list of the above list item\n const { children } = aboveListItemNode.children[1] as CosmosCustom.ListElement;\n // Gets the last list item in the above sub list\n const [[parentSubListItem, parentSubListItemPath]] = Editor.nodes<FullListItemElement>(\n editor,\n {\n at: aboveListItemPath,\n match: n =>\n matchListItem(n) &&\n n.order === children.length &&\n (n.level as number) - 1 === listItemNode.level\n }\n );\n\n // Gets the path after the last list item in the above sub list\n const nextParentSubListItemPath = Path.next(parentSubListItemPath);\n\n /* Inserts a copy of the list-item you are nesting below the lowest list item\n in the above sub list, as well as copies of any children the list-item you are\n nesting had. */\n let subOrderCount = parentSubListItem.order + 1;\n Transforms.insertNodes(\n editor,\n [\n {\n ...listItemNode,\n level: listItemNode.level + 1,\n order: parentSubListItem.order + 1,\n parentId: aboveListItemNode.id,\n children: newListItemChildren\n },\n ...copiedSubListNodes.map(n => {\n subOrderCount += 1;\n return {\n ...n,\n level: listItemNode.level + 1,\n order: subOrderCount,\n parentId: aboveListItemNode.id\n };\n })\n ],\n { at: nextParentSubListItemPath }\n );\n } else {\n const nextInnerTextNodePath = getNextPathBelow(innerTextNodePath);\n // Nest the selected list item into a new list and then into the above list item\n let subOrderCount = 1;\n Transforms.insertNodes(\n editor,\n {\n type: listType,\n children: [\n {\n ...listItemNode,\n order: 1,\n level: listItemNode.level + 1,\n parentId: aboveListItemNode.id,\n children: newListItemChildren\n },\n ...copiedSubListNodes.map(n => {\n subOrderCount += 1;\n return {\n ...n,\n level: listItemNode.level + 1,\n order: subOrderCount,\n parentId: aboveListItemNode.id\n };\n })\n ]\n },\n { at: nextInnerTextNodePath, mode: 'lowest' }\n );\n }\n\n // Remove the old list item as we just copied it into the correct place\n Transforms.removeNodes(editor, { at: listItemPath });\n }\n },\n unNestList: (editor: Editor) => {\n // Get the current node to be un nested\n const [[node, nodePath]] = Editor.nodes<FullListItemElement>(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchListItem,\n mode: 'lowest'\n });\n const [singleItemList] = Editor.nodes<CosmosCustom.ListElement>(editor, {\n match: n => matchList(n) && n.children.length === 1,\n mode: 'highest'\n });\n\n if (singleItemList) {\n Transforms.unwrapNodes(editor, { match: matchListItem });\n Transforms.unwrapNodes(editor, { match: matchList });\n return;\n }\n // Attempt to get the highest parent in the nested list if it exists\n const [highestParent] = Editor.nodes<FullListItemElement>(editor, {\n at: editor.selection || undefined,\n match: n => matchListItem(n) && node.level - (n.level as number) === 2,\n mode: 'lowest'\n });\n // Get the parent list node if it exists (list item)\n const [[parentNode]] = Editor.nodes<FullListItemElement>(editor, {\n at: editor.selection || undefined,\n match: n => matchListItem(n) && node.level - (n.level as number) === 1,\n mode: 'lowest'\n });\n // Get the parent list\n const [[parentList]] = Editor.nodes(editor, {\n at: editor.selection || undefined,\n match: matchList,\n mode: 'lowest'\n });\n if (parentNode && parentNode.children.length > 1) {\n let newParentId;\n if (highestParent) {\n const [highestParentNode] = highestParent;\n newParentId = highestParentNode.id;\n }\n\n // Setting the node to un nests new order and level\n Transforms.setNodes<CosmosCustom.ListItemElement>(\n editor,\n {\n level: node.level - 1,\n order: parentNode.order + 1\n },\n { at: nodePath, match: n => matchListItem(n) && n.id === node.id }\n );\n\n // Set the level of any children under the node we are un nesting\n Transforms.setNodes<CosmosCustom.ListItemElement>(\n editor,\n { level: node.level },\n {\n at: nodePath,\n match: n => matchListItem(n) && (n.level as number) > node.level\n }\n );\n\n // If there's a new parent id set it, otherwise unset the parent id entirely\n if (newParentId) {\n Transforms.setNodes<CosmosCustom.ListItemElement>(\n editor,\n { parentId: newParentId },\n { at: nodePath, match: n => matchListItem(n) && n.id === node.id }\n );\n } else {\n Transforms.unsetNodes<CosmosCustom.ListItemElement>(editor, 'parentId', {\n at: nodePath,\n match: n => matchListItem(n) && n.id === node.id\n });\n }\n\n const listItemsExistBelow = node.order < parentList.children.length;\n\n if (listItemsExistBelow) {\n // Getting the inner text node inside of the list item in order to get the next path\n const [[, innerTextNodePath]] = Editor.nodes(editor, {\n at: nodePath,\n match: matchList\n });\n const nextPath = Path.next(innerTextNodePath);\n const copiedChildren = [];\n\n let count = 1;\n // Copy the children from the parent list that are below the list item we are un nesting\n for (let i = node.order; i < parentList.children.length; i += 1) {\n copiedChildren.push({\n ...parentList.children[i],\n parentId: node.id,\n order: count\n });\n count += 1;\n }\n\n // Insert a new list with the copied children into the un nested list item\n Transforms.insertNodes(\n editor,\n {\n type: parentList.type,\n children: [...copiedChildren]\n },\n { at: nextPath }\n );\n\n const [[newParentList, newParentListPath]] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchList,\n mode: 'lowest'\n });\n\n let order = 0;\n // Set the nodes below the list item being un nested\n Transforms.setNodes<CosmosCustom.ListItemElement>(\n editor,\n {\n parentId: node.id,\n order\n },\n {\n match: n => {\n if (!matchListItem(n)) return false;\n\n if (n.parentId === node.id) order += 1;\n return n.parentId === node.id;\n }\n }\n );\n\n // Removing all old nodes from that were under the un nested item\n for (let i = newParentList.children.length - 1; i >= node.order; i -= 1) {\n const childPath = [...newParentListPath, i];\n Transforms.removeNodes(editor, { at: childPath, match: matchListItem });\n }\n }\n\n // Lift the current node at the users selection out of it's parent node twice\n Transforms.liftNodes(editor, { match: matchListItem });\n Transforms.liftNodes(editor, { match: matchListItem });\n }\n }\n};\n\nexport default commands;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"htmlConverter.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/htmlConverter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AAEpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAU9D,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;CAkBjB,CAAC;AAGX,eAAO,MAAM,oBAAoB;;;;;CAKvB,CAAC;
|
|
1
|
+
{"version":3,"file":"htmlConverter.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/htmlConverter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AAEpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAU9D,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;CAkBjB,CAAC;AAGX,eAAO,MAAM,oBAAoB;;;;;CAKvB,CAAC;AA8GX,eAAO,MAAM,WAAW,SAChB,MAAM,yBACW,mBAAmB,CAAC,sBAAsB,CAAC,KACjE,CAAC,aAAa,GAAG,UAAU,CAAC,EAU9B,CAAC"}
|
|
@@ -35,6 +35,7 @@ const getAttributes = (node) => {
|
|
|
35
35
|
switch (node.nodeName) {
|
|
36
36
|
case 'li':
|
|
37
37
|
return Object.fromEntries(node.attrs.flatMap(attr => {
|
|
38
|
+
// eslint-disable-next-line sonarjs/no-nested-switch
|
|
38
39
|
switch (attr.name) {
|
|
39
40
|
case 'data-id':
|
|
40
41
|
return [['id', attr.value]];
|
|
@@ -66,7 +67,6 @@ const getAttributes = (node) => {
|
|
|
66
67
|
return {};
|
|
67
68
|
};
|
|
68
69
|
const getSlateNode = (node, parentNode, interactionRenderers) => {
|
|
69
|
-
var _a;
|
|
70
70
|
if (checkTextNode(node)) {
|
|
71
71
|
// Make sure to spread any parent style attributes for slates text nodes
|
|
72
72
|
const children = parseTextToCustomSlateNodes(node.value, interactionRenderers);
|
|
@@ -89,7 +89,7 @@ const getSlateNode = (node, parentNode, interactionRenderers) => {
|
|
|
89
89
|
const style = inlineHtmlToStyleMap[node.nodeName];
|
|
90
90
|
let value = true;
|
|
91
91
|
if (node.nodeName === 'a') {
|
|
92
|
-
const hrefObj =
|
|
92
|
+
const hrefObj = node.attrs?.find(attr => attr.name === 'href');
|
|
93
93
|
value = hrefObj ? hrefObj.value : value;
|
|
94
94
|
}
|
|
95
95
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"htmlConverter.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/htmlConverter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAO/B,OAAO,2BAA2B,MAAM,uBAAuB,CAAC;AAEhE,MAAM,YAAY,GAAG,CAAC,IAAkC,EAA0B,EAAE,CAClF,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,KAAK,OAAO,IAAI,IAAI,CAAC,QAAQ,KAAK,UAAU,CAAC;AACtE,MAAM,aAAa,GAAG,CAAC,IAAkC,EAA2B,EAAE,CACpF,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,KAAK,OAAO,CAAC;AAEtC,iHAAiH;AACjH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,gBAAgB;IACpB,EAAE,EAAE,cAAc;IAClB,EAAE,EAAE,WAAW;IACf,KAAK,EAAE,OAAO;IACd,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,YAAY;IAChB,KAAK,EAAE,YAAY;IACnB,CAAC,EAAE,WAAW;IACd,GAAG,EAAE,OAAO;IACZ,CAAC,EAAE,MAAM;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AC,IAAI,CAAC,EAAE;oBAC7C,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;oBACtC,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;wBAC3B,QAAQ,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;qBACxB;iBACF;gBACD,OAAO,QAAQ,CAAC;aACjB;YACD;gBACE,OAAO,EAAE,CAAC;SACb;KACF;IACD,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,CACnB,IAAsB,EACtB,UAAuC,EACvC,oBAAkE,EACJ,EAAE
|
|
1
|
+
{"version":3,"file":"htmlConverter.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/htmlConverter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAO/B,OAAO,2BAA2B,MAAM,uBAAuB,CAAC;AAEhE,MAAM,YAAY,GAAG,CAAC,IAAkC,EAA0B,EAAE,CAClF,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,KAAK,OAAO,IAAI,IAAI,CAAC,QAAQ,KAAK,UAAU,CAAC;AACtE,MAAM,aAAa,GAAG,CAAC,IAAkC,EAA2B,EAAE,CACpF,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,KAAK,OAAO,CAAC;AAEtC,iHAAiH;AACjH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,gBAAgB;IACpB,EAAE,EAAE,cAAc;IAClB,EAAE,EAAE,WAAW;IACf,KAAK,EAAE,OAAO;IACd,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,YAAY;IAChB,KAAK,EAAE,YAAY;IACnB,CAAC,EAAE,WAAW;IACd,G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AO,UAAU,CAAC;IACpB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,IAAY,EACZ,oBAAkE,EAClC,EAAE;IAClC,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;IAExB,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAC/B,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,CAAC;IAEnC,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAChC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,CAAC;IAEnC,OAAO,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,SAAS,EAAE,oBAAoB,CAAC,CAAC;AACxE,CAAC,CAAC","sourcesContent":["import { parse } from 'parse5';\n// Use namespaced types to more easily differentiate between similar types (ie, ChildNode from parse5 and Node from slate).\nimport type * as parse5 from 'parse5';\nimport type * as slate from 'slate';\n\nimport { RichTextViewerProps } from '../RichTextViewer.types';\n\nimport parseTextToCustomSlateNodes from './interactionRenderer';\n\nconst checkElement = (node: parse5.ChildNode | undefined): node is parse5.Element =>\n !!node && node.nodeName !== '#text' && node.nodeName !== '#comment';\nconst checkTextNode = (node: parse5.ChildNode | undefined): node is parse5.TextNode =>\n !!node && node.nodeName === '#text';\n\n// Mapping of HTML tags to slate types. b, del, i, and a tags are labeled as skip because they need special logic\nexport const htmlToSlateMap = {\n h1: 'heading-1',\n h2: 'heading-2',\n h3: 'heading-3',\n h4: 'heading-4',\n ul: 'unordered-list',\n ol: 'ordered-list',\n li: 'list-item',\n table: 'table',\n tr: 'table-row',\n td: 'table-cell',\n tbody: 'table-body',\n p: 'paragraph',\n img: 'image',\n b: 'skip',\n del: 'skip',\n i: 'skip',\n a: 'skip'\n} as const;\n\n// Inline HTML tags to slate types\nexport const inlineHtmlToStyleMap = {\n b: 'bold',\n del: 'line-through',\n i: 'italic',\n a: 'href'\n} as const;\n\n// Maps HTML Attributes to an object. Right now this is specifically used for list items.\nconst getAttributes = (node: parse5.ChildNode) => {\n if (checkElement(node) && node.attrs.length) {\n switch (node.nodeName) {\n case 'li':\n return Object.fromEntries(\n node.attrs.flatMap(attr => {\n // eslint-disable-next-line sonarjs/no-nested-switch\n switch (attr.name) {\n case 'data-id':\n return [['id', attr.value]];\n case 'data-parent-id':\n return [['parentId', attr.value]];\n case 'data-level':\n return [['level', attr.value]];\n case 'data-order':\n return [['order', attr.value]];\n default:\n return [];\n }\n })\n );\n case 'img': {\n const imgAttrs = ['src', 'alt'];\n const attrsObj: { [key: string]: string } = {};\n for (let i = 0; i < node.attrs.length; i += 1) {\n const { name, value } = node.attrs[i];\n if (imgAttrs.includes(name)) {\n attrsObj[name] = value;\n }\n }\n return attrsObj;\n }\n default:\n return {};\n }\n }\n return {};\n};\n\nconst getSlateNode = (\n node: parse5.ChildNode,\n parentNode?: slate.Element | slate.Text,\n interactionRenderers?: RichTextViewerProps['interactionRenderers']\n): { node: slate.Element | slate.Text; collapseNext?: boolean } => {\n if (checkTextNode(node)) {\n // Make sure to spread any parent style attributes for slates text nodes\n const children = parseTextToCustomSlateNodes(node.value, interactionRenderers);\n if (children.length === 1) {\n return { node: { ...parentNode, ...children[0] } as slate.Text };\n }\n return {\n node: {\n ...parentNode,\n children\n } as slate.Element\n };\n }\n\n const type = htmlToSlateMap[node.nodeName as keyof typeof htmlToSlateMap];\n /*\n If the type of the HTML tag is an inline (b, i, del, a) we want to let the recursive function know\n that it needs to collapse the next node, also we are setting the correct style mark to true\n */\n if (type === 'skip') {\n const style = inlineHtmlToStyleMap[node.nodeName as 'b' | 'i' | 'del' | 'a'];\n let value: string | boolean = true;\n if (node.nodeName === 'a') {\n const hrefObj = node.attrs?.find(attr => attr.name === 'href');\n value = hrefObj ? hrefObj.value : value;\n }\n return {\n node: { ...parentNode, [style]: value, text: '' } as slate.Text,\n collapseNext: true\n };\n }\n\n const attributes = getAttributes(node);\n const nodeObj = { type, ...attributes, children: [{ text: '' }] } as slate.Element;\n return { node: nodeObj };\n};\n\n// Recursive function that will convert Parse5Nodes into Slate compatible nodes\nconst convertNodes = (\n nodes: parse5.ChildNode[],\n parentNode?: slate.Element | slate.Text,\n interactionRenderers?: RichTextViewerProps['interactionRenderers']\n): (slate.Element | slate.Text)[] => {\n return nodes.map(node => {\n const { node: slateNode, collapseNext } = getSlateNode(node, parentNode, interactionRenderers);\n let returnNode = slateNode;\n if (checkElement(node) && node.childNodes && node.childNodes.length) {\n if (collapseNext) {\n returnNode = convertNodes(node.childNodes, slateNode, interactionRenderers)[0];\n } else {\n (slateNode as slate.Element).children = convertNodes(\n node.childNodes,\n undefined,\n interactionRenderers\n );\n returnNode = slateNode;\n }\n }\n\n return returnNode;\n });\n};\n\nexport const convertHtml = (\n html: string,\n interactionRenderers?: RichTextViewerProps['interactionRenderers']\n): (slate.Element | slate.Text)[] => {\n const doc = parse(html);\n\n const root = doc.childNodes[0];\n if (!checkElement(root)) return [];\n\n const body = root.childNodes[1];\n if (!checkElement(body)) return [];\n\n return convertNodes(body.childNodes, undefined, interactionRenderers);\n};\n"]}
|
|
@@ -17,7 +17,7 @@ const checkRegex = (params) => {
|
|
|
17
17
|
// Parses text node to custom slate node
|
|
18
18
|
const parseTextToCustomSlateNodes = (text, renderers) => {
|
|
19
19
|
// Runs through an array of custom renderers and gets the matches
|
|
20
|
-
const positions =
|
|
20
|
+
const positions = renderers?.flatMap(renderer => checkRegex({ text, ...renderer })) || [];
|
|
21
21
|
// Early exit when no matched positions
|
|
22
22
|
if (positions.length === 0) {
|
|
23
23
|
return [{ text }];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interactionRenderer.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/interactionRenderer.ts"],"names":[],"mappings":"AAqBA,oEAAoE;AACpE,MAAM,UAAU,GAAG,CAAC,MAAwB,EAAE,EAAE;IAC9C,MAAM,YAAY,GAAiB,EAAE,CAAC;IACtC,IAAI,GAAG,CAAC;IACR,0CAA0C;IAC1C,OAAO,CAAC,GAAG,GAAG,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE;QAC7D,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;QACxB,YAAY,CAAC,IAAI,CAAC;YAChB,KAAK;YACL,GAAG,EAAE,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM;YAC1B,KAAK,EAAE,GAAG;YACV,GAAG,MAAM;SACV,CAAC,CAAC;KACJ;IACD,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AAEF,wCAAwC;AACxC,MAAM,2BAA2B,GAAG,CAAC,IAAY,EAAE,SAAuB,EAAE,EAAE;IAC5E,iEAAiE;IACjE,MAAM,SAAS,GACb,
|
|
1
|
+
{"version":3,"file":"interactionRenderer.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/interactionRenderer.ts"],"names":[],"mappings":"AAqBA,oEAAoE;AACpE,MAAM,UAAU,GAAG,CAAC,MAAwB,EAAE,EAAE;IAC9C,MAAM,YAAY,GAAiB,EAAE,CAAC;IACtC,IAAI,GAAG,CAAC;IACR,0CAA0C;IAC1C,OAAO,CAAC,GAAG,GAAG,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE;QAC7D,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;QACxB,YAAY,CAAC,IAAI,CAAC;YAChB,KAAK;YACL,GAAG,EAAE,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM;YAC1B,KAAK,EAAE,GAAG;YACV,GAAG,MAAM;SACV,CAAC,CAAC;KACJ;IACD,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AAEF,wCAAwC;AACxC,MAAM,2BA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AAC,IAAI,CAAC;gBACT,IAAI,EAAE,QAAQ;gBACd,SAAS,EAAE,GAAG,CAAC,SAAS;gBACxB,OAAO,EAAE,GAAG,CAAC,KAAK;gBAClB,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;aACzB,CAAC,CAAC;SACJ;aAAM,IAAI,GAAG,CAAC,mBAAmB,EAAE;YAClC,MAAM,YAAY,GAAG,GAAG,CAAC,mBAAmB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACxD,IAAI,YAAY,EAAE;gBAChB,KAAK,CAAC,IAAI,CAAC;oBACT,IAAI,EAAE,YAAY,CAAC,IAAI;oBACvB,YAAY,EAAE;wBACZ,QAAQ,EAAE,YAAY,CAAC,QAAQ;wBAC/B,SAAS,EAAE,YAAY,CAAC,SAAS;wBACjC,KAAK,EAAE,YAAY,CAAC,KAAK;wBACzB,MAAM,EAAE,GAAG,EAAE,CAAC,SAAS;qBACxB;iBACF,CAAC,CAAC;aACJ;SACF;QAED;yDACiD;QACjD,IAAI,CAAC,KAAK,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YAC3D,KAAK,CAAC,IAAI,CAAC;gBACT,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC;aACvC,CAAC,CAAC;SACJ;QACD,OAAO,GAAG,GAAG,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;AACnD,CAAC,CAAC;AAEF,eAAe,2BAA2B,CAAC","sourcesContent":["import type * as slate from 'slate';\n\nimport { SearchRenderers } from '../RichTextEditor.types';\nimport { InteractionRenderers } from '../RichTextViewer.types';\n\ninterface Renderers {\n regexPattern: InteractionRenderers['regexPattern'];\n type?: InteractionRenderers['type'];\n component?: InteractionRenderers['component'];\n getSearchAttributes?: SearchRenderers['getSearchAttributes'];\n}\ninterface RegexMatch extends Renderers {\n start: number;\n end: number;\n match: RegExpExecArray;\n}\n\ninterface CheckRegexParams extends Renderers {\n text: string;\n}\n\n// Checks a string for regex matches and returns an array of matches\nconst checkRegex = (params: CheckRegexParams) => {\n const regexMatches: RegexMatch[] = [];\n let res;\n // eslint-disable-next-line no-cond-assign\n while ((res = params.regexPattern.exec(params.text)) !== null) {\n const start = res.index;\n regexMatches.push({\n start,\n end: start + res[0].length,\n match: res,\n ...params\n });\n }\n return regexMatches;\n};\n\n// Parses text node to custom slate node\nconst parseTextToCustomSlateNodes = (text: string, renderers?: Renderers[]) => {\n // Runs through an array of custom renderers and gets the matches\n const positions: RegexMatch[] =\n renderers?.flatMap(renderer => checkRegex({ text, ...renderer })) || [];\n\n // Early exit when no matched positions\n if (positions.length === 0) {\n return [{ text }];\n }\n\n // Sorts the matches based on the start positions of the matches\n positions.sort((a, b) => a.start - b.start);\n\n const nodes: (slate.Element | slate.CosmosCustom.Text)[] = [];\n\n // Use the regex match positions to slice the text into the correct text nodes and other custom nodes\n let lastPos: RegexMatch;\n positions.forEach((pos, i) => {\n /* If the first regex match isn't at the start of the text node,\n slice the text node up to the first match and insert it into the nodes array */\n\n if (i === 0 && pos.start !== 0) {\n nodes.push({\n text: text.slice(i, pos.start)\n });\n }\n\n /* If there was a last position, slice the text between the last position\n and the new position to insert it as a new text node */\n if (lastPos && lastPos.end < pos.start) {\n nodes.push({\n text: text.slice(lastPos.end, pos.start)\n });\n } else if (i !== 0) {\n nodes.push({\n text: ' '\n });\n }\n\n if (pos.component) {\n nodes.push({\n type: 'custom',\n component: pos.component,\n content: pos.match,\n children: [{ text: '' }]\n });\n } else if (pos.getSearchAttributes) {\n const searchResult = pos.getSearchAttributes(pos.match);\n if (searchResult) {\n nodes.push({\n text: searchResult.text,\n searchResult: {\n markdown: searchResult.markdown,\n component: searchResult.component,\n props: searchResult.props,\n toJSON: () => undefined\n }\n });\n }\n }\n\n /* If we are at the end of the positions array, and there's still text left\n slice the text and add it as a new text node */\n if (i === positions.length - 1 && pos.end < text.length - 1) {\n nodes.push({\n text: text.slice(pos.end, text.length)\n });\n }\n lastPos = pos;\n });\n\n return nodes.length > 0 ? nodes : [{ text: '' }];\n};\n\nexport default parseTextToCustomSlateNodes;\n"]}
|