@pega/cosmos-react-rte 2.1.3 → 2.1.6

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.
Files changed (153) hide show
  1. package/package.json +4 -4
  2. package/lib/components/Editor/Editor.context.d.ts +0 -10
  3. package/lib/components/Editor/Editor.context.d.ts.map +0 -1
  4. package/lib/components/Editor/Editor.context.js +0 -10
  5. package/lib/components/Editor/Editor.context.js.map +0 -1
  6. package/lib/components/Editor/Editor.d.ts +0 -10
  7. package/lib/components/Editor/Editor.d.ts.map +0 -1
  8. package/lib/components/Editor/Editor.js +0 -187
  9. package/lib/components/Editor/Editor.js.map +0 -1
  10. package/lib/components/Editor/Editor.types.d.ts +0 -48
  11. package/lib/components/Editor/Editor.types.d.ts.map +0 -1
  12. package/lib/components/Editor/Editor.types.js +0 -2
  13. package/lib/components/Editor/Editor.types.js.map +0 -1
  14. package/lib/components/Editor/Toolbar/AnchorButton.d.ts +0 -10
  15. package/lib/components/Editor/Toolbar/AnchorButton.d.ts.map +0 -1
  16. package/lib/components/Editor/Toolbar/AnchorButton.js +0 -141
  17. package/lib/components/Editor/Toolbar/AnchorButton.js.map +0 -1
  18. package/lib/components/Editor/Toolbar/ImageButton.d.ts +0 -8
  19. package/lib/components/Editor/Toolbar/ImageButton.d.ts.map +0 -1
  20. package/lib/components/Editor/Toolbar/ImageButton.js +0 -30
  21. package/lib/components/Editor/Toolbar/ImageButton.js.map +0 -1
  22. package/lib/components/Editor/Toolbar/TextSelect.d.ts +0 -14
  23. package/lib/components/Editor/Toolbar/TextSelect.d.ts.map +0 -1
  24. package/lib/components/Editor/Toolbar/TextSelect.js +0 -117
  25. package/lib/components/Editor/Toolbar/TextSelect.js.map +0 -1
  26. package/lib/components/Editor/Toolbar/Toolbar.d.ts +0 -13
  27. package/lib/components/Editor/Toolbar/Toolbar.d.ts.map +0 -1
  28. package/lib/components/Editor/Toolbar/Toolbar.js +0 -142
  29. package/lib/components/Editor/Toolbar/Toolbar.js.map +0 -1
  30. package/lib/components/Editor/index.d.ts +0 -4
  31. package/lib/components/Editor/index.d.ts.map +0 -1
  32. package/lib/components/Editor/index.js +0 -3
  33. package/lib/components/Editor/index.js.map +0 -1
  34. package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.d.ts +0 -4
  35. package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.d.ts.map +0 -1
  36. package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.js +0 -15
  37. package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.js.map +0 -1
  38. package/lib/components/RichTextEditor/DecoratorComponents/Image.d.ts +0 -4
  39. package/lib/components/RichTextEditor/DecoratorComponents/Image.d.ts.map +0 -1
  40. package/lib/components/RichTextEditor/DecoratorComponents/Image.js +0 -7
  41. package/lib/components/RichTextEditor/DecoratorComponents/Image.js.map +0 -1
  42. package/lib/components/RichTextEditor/DecoratorComponents/Link.d.ts +0 -4
  43. package/lib/components/RichTextEditor/DecoratorComponents/Link.d.ts.map +0 -1
  44. package/lib/components/RichTextEditor/DecoratorComponents/Link.js +0 -8
  45. package/lib/components/RichTextEditor/DecoratorComponents/Link.js.map +0 -1
  46. package/lib/components/RichTextEditor/DecoratorComponents/Table.d.ts +0 -8
  47. package/lib/components/RichTextEditor/DecoratorComponents/Table.d.ts.map +0 -1
  48. package/lib/components/RichTextEditor/DecoratorComponents/Table.js +0 -51
  49. package/lib/components/RichTextEditor/DecoratorComponents/Table.js.map +0 -1
  50. package/lib/components/RichTextEditor/RichTextEditor.context.d.ts +0 -15
  51. package/lib/components/RichTextEditor/RichTextEditor.context.d.ts.map +0 -1
  52. package/lib/components/RichTextEditor/RichTextEditor.context.js +0 -11
  53. package/lib/components/RichTextEditor/RichTextEditor.context.js.map +0 -1
  54. package/lib/components/RichTextEditor/RichTextEditor.d.ts +0 -6
  55. package/lib/components/RichTextEditor/RichTextEditor.d.ts.map +0 -1
  56. package/lib/components/RichTextEditor/RichTextEditor.js +0 -292
  57. package/lib/components/RichTextEditor/RichTextEditor.js.map +0 -1
  58. package/lib/components/RichTextEditor/RichTextEditor.styles.d.ts +0 -15
  59. package/lib/components/RichTextEditor/RichTextEditor.styles.d.ts.map +0 -1
  60. package/lib/components/RichTextEditor/RichTextEditor.styles.js +0 -189
  61. package/lib/components/RichTextEditor/RichTextEditor.styles.js.map +0 -1
  62. package/lib/components/RichTextEditor/RichTextEditor.types.d.ts +0 -80
  63. package/lib/components/RichTextEditor/RichTextEditor.types.d.ts.map +0 -1
  64. package/lib/components/RichTextEditor/RichTextEditor.types.js +0 -2
  65. package/lib/components/RichTextEditor/RichTextEditor.types.js.map +0 -1
  66. package/lib/components/RichTextEditor/RichTextViewer.d.ts +0 -6
  67. package/lib/components/RichTextEditor/RichTextViewer.d.ts.map +0 -1
  68. package/lib/components/RichTextEditor/RichTextViewer.js +0 -52
  69. package/lib/components/RichTextEditor/RichTextViewer.js.map +0 -1
  70. package/lib/components/RichTextEditor/RichTextViewer.types.d.ts +0 -26
  71. package/lib/components/RichTextEditor/RichTextViewer.types.d.ts.map +0 -1
  72. package/lib/components/RichTextEditor/RichTextViewer.types.js +0 -2
  73. package/lib/components/RichTextEditor/RichTextViewer.types.js.map +0 -1
  74. package/lib/components/RichTextEditor/Toolbar/AnchorButton.d.ts +0 -8
  75. package/lib/components/RichTextEditor/Toolbar/AnchorButton.d.ts.map +0 -1
  76. package/lib/components/RichTextEditor/Toolbar/AnchorButton.js +0 -156
  77. package/lib/components/RichTextEditor/Toolbar/AnchorButton.js.map +0 -1
  78. package/lib/components/RichTextEditor/Toolbar/ImageButton.d.ts +0 -5
  79. package/lib/components/RichTextEditor/Toolbar/ImageButton.d.ts.map +0 -1
  80. package/lib/components/RichTextEditor/Toolbar/ImageButton.js +0 -30
  81. package/lib/components/RichTextEditor/Toolbar/ImageButton.js.map +0 -1
  82. package/lib/components/RichTextEditor/Toolbar/IndentButton.d.ts +0 -8
  83. package/lib/components/RichTextEditor/Toolbar/IndentButton.d.ts.map +0 -1
  84. package/lib/components/RichTextEditor/Toolbar/IndentButton.js +0 -28
  85. package/lib/components/RichTextEditor/Toolbar/IndentButton.js.map +0 -1
  86. package/lib/components/RichTextEditor/Toolbar/TableButton.d.ts +0 -5
  87. package/lib/components/RichTextEditor/Toolbar/TableButton.d.ts.map +0 -1
  88. package/lib/components/RichTextEditor/Toolbar/TableButton.js +0 -20
  89. package/lib/components/RichTextEditor/Toolbar/TableButton.js.map +0 -1
  90. package/lib/components/RichTextEditor/Toolbar/TextSelect.d.ts +0 -6
  91. package/lib/components/RichTextEditor/Toolbar/TextSelect.d.ts.map +0 -1
  92. package/lib/components/RichTextEditor/Toolbar/TextSelect.js +0 -119
  93. package/lib/components/RichTextEditor/Toolbar/TextSelect.js.map +0 -1
  94. package/lib/components/RichTextEditor/Toolbar/Toolbar.d.ts +0 -10
  95. package/lib/components/RichTextEditor/Toolbar/Toolbar.d.ts.map +0 -1
  96. package/lib/components/RichTextEditor/Toolbar/Toolbar.js +0 -140
  97. package/lib/components/RichTextEditor/Toolbar/Toolbar.js.map +0 -1
  98. package/lib/components/RichTextEditor/Toolbar/Toolbar.types.d.ts +0 -9
  99. package/lib/components/RichTextEditor/Toolbar/Toolbar.types.d.ts.map +0 -1
  100. package/lib/components/RichTextEditor/Toolbar/Toolbar.types.js +0 -2
  101. package/lib/components/RichTextEditor/Toolbar/Toolbar.types.js.map +0 -1
  102. package/lib/components/RichTextEditor/Toolbar/ToolbarButton.d.ts +0 -14
  103. package/lib/components/RichTextEditor/Toolbar/ToolbarButton.d.ts.map +0 -1
  104. package/lib/components/RichTextEditor/Toolbar/ToolbarButton.js +0 -66
  105. package/lib/components/RichTextEditor/Toolbar/ToolbarButton.js.map +0 -1
  106. package/lib/components/RichTextEditor/Toolbar/utils.d.ts +0 -7
  107. package/lib/components/RichTextEditor/Toolbar/utils.d.ts.map +0 -1
  108. package/lib/components/RichTextEditor/Toolbar/utils.js +0 -13
  109. package/lib/components/RichTextEditor/Toolbar/utils.js.map +0 -1
  110. package/lib/components/RichTextEditor/index.d.ts +0 -8
  111. package/lib/components/RichTextEditor/index.d.ts.map +0 -1
  112. package/lib/components/RichTextEditor/index.js +0 -5
  113. package/lib/components/RichTextEditor/index.js.map +0 -1
  114. package/lib/components/RichTextEditor/utils/EditorCommands.d.ts +0 -33
  115. package/lib/components/RichTextEditor/utils/EditorCommands.d.ts.map +0 -1
  116. package/lib/components/RichTextEditor/utils/EditorCommands.js +0 -423
  117. package/lib/components/RichTextEditor/utils/EditorCommands.js.map +0 -1
  118. package/lib/components/RichTextEditor/utils/ListCommands.d.ts +0 -10
  119. package/lib/components/RichTextEditor/utils/ListCommands.d.ts.map +0 -1
  120. package/lib/components/RichTextEditor/utils/ListCommands.js +0 -346
  121. package/lib/components/RichTextEditor/utils/ListCommands.js.map +0 -1
  122. package/lib/components/RichTextEditor/utils/htmlConverter.d.ts +0 -29
  123. package/lib/components/RichTextEditor/utils/htmlConverter.d.ts.map +0 -1
  124. package/lib/components/RichTextEditor/utils/htmlConverter.js +0 -155
  125. package/lib/components/RichTextEditor/utils/htmlConverter.js.map +0 -1
  126. package/lib/components/RichTextEditor/utils/interactionRenderer.d.ts +0 -12
  127. package/lib/components/RichTextEditor/utils/interactionRenderer.d.ts.map +0 -1
  128. package/lib/components/RichTextEditor/utils/interactionRenderer.js +0 -105
  129. package/lib/components/RichTextEditor/utils/interactionRenderer.js.map +0 -1
  130. package/lib/components/RichTextEditor/utils/markdownConverter.d.ts +0 -7
  131. package/lib/components/RichTextEditor/utils/markdownConverter.d.ts.map +0 -1
  132. package/lib/components/RichTextEditor/utils/markdownConverter.js +0 -130
  133. package/lib/components/RichTextEditor/utils/markdownConverter.js.map +0 -1
  134. package/lib/components/RichTextEditor/utils/renderers.d.ts +0 -5
  135. package/lib/components/RichTextEditor/utils/renderers.d.ts.map +0 -1
  136. package/lib/components/RichTextEditor/utils/renderers.js +0 -68
  137. package/lib/components/RichTextEditor/utils/renderers.js.map +0 -1
  138. package/lib/components/RichTextEditor/utils/search.d.ts +0 -11
  139. package/lib/components/RichTextEditor/utils/search.d.ts.map +0 -1
  140. package/lib/components/RichTextEditor/utils/search.js +0 -29
  141. package/lib/components/RichTextEditor/utils/search.js.map +0 -1
  142. package/lib/components/RichTextEditor/utils/slateConverter.d.ts +0 -24
  143. package/lib/components/RichTextEditor/utils/slateConverter.d.ts.map +0 -1
  144. package/lib/components/RichTextEditor/utils/slateConverter.js +0 -87
  145. package/lib/components/RichTextEditor/utils/slateConverter.js.map +0 -1
  146. package/lib/components/RichTextEditor/utils/utils.types.d.ts +0 -3
  147. package/lib/components/RichTextEditor/utils/utils.types.d.ts.map +0 -1
  148. package/lib/components/RichTextEditor/utils/utils.types.js +0 -3
  149. package/lib/components/RichTextEditor/utils/utils.types.js.map +0 -1
  150. package/lib/index.d.ts +0 -3
  151. package/lib/index.d.ts.map +0 -1
  152. package/lib/index.js +0 -4
  153. package/lib/index.js.map +0 -1
@@ -1,423 +0,0 @@
1
- import { Editor, Transforms, Range, Path, Element, Text } from 'slate';
2
- import ListCommands from './ListCommands';
3
- const textKeyCodeMapping = {
4
- 48: 'paragraph',
5
- 49: 'heading-1',
6
- 50: 'heading-2',
7
- 51: 'heading-3',
8
- 52: 'heading-4'
9
- };
10
- const commands = {
11
- // Checks if an inline format is active
12
- isFormatActive: (format, editor) => {
13
- const marks = Editor.marks(editor);
14
- return marks ? marks[format] === true : false;
15
- },
16
- // Toggles an inline format on or off
17
- toggleFormat: (format, editor) => {
18
- const formatActive = commands.isFormatActive(format, editor);
19
- if (formatActive) {
20
- Editor.removeMark(editor, format);
21
- }
22
- else {
23
- Editor.addMark(editor, format, true);
24
- }
25
- },
26
- // Checks if a block level format is active
27
- isBlockActive: (format, editor) => {
28
- const [match] = Editor.nodes(editor, {
29
- match: n => Element.isElement(n) && n.type === format
30
- });
31
- return !!match;
32
- },
33
- // Gets the active block level type
34
- getActiveBlockType: (editor) => {
35
- const [match] = Editor.nodes(editor, {
36
- at: editor.selection || undefined,
37
- match: Element.isElement,
38
- mode: 'lowest'
39
- });
40
- if (match) {
41
- return match[0].type;
42
- }
43
- return '';
44
- },
45
- // Sets the block type of the currently selected block
46
- setBlock: (format, editor) => {
47
- Transforms.setNodes(editor, { type: format }, { mode: 'lowest' });
48
- },
49
- // Replaces a target in the editor with the given text
50
- replaceWithText: (editor, target, text) => {
51
- if (target) {
52
- Transforms.select(editor, target);
53
- }
54
- Transforms.insertText(editor, text);
55
- Transforms.move(editor);
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
- },
65
- // Gets the highest selected block level node
66
- getSelectedNode: (editor) => {
67
- const [node] = Editor.nodes(editor, {
68
- at: editor.selection || undefined,
69
- match: n => Element.isElement(n),
70
- mode: 'highest'
71
- });
72
- return node;
73
- },
74
- // Appends a 3x3 table into the editor and adds a blank line to the bottom
75
- appendTable: (editor) => {
76
- const baseArr = new Array(3).fill(new Array(3).fill(0));
77
- const table = [
78
- {
79
- type: 'table',
80
- children: [
81
- {
82
- type: 'table-body',
83
- children: baseArr.map(row => {
84
- return {
85
- type: 'table-row',
86
- children: row.map(() => {
87
- return {
88
- type: 'table-cell',
89
- children: [{ type: 'paragraph', children: [{ text: '' }] }]
90
- };
91
- })
92
- };
93
- })
94
- }
95
- ]
96
- },
97
- {
98
- type: 'paragraph',
99
- children: [{ text: '' }]
100
- }
101
- ];
102
- Transforms.insertNodes(editor, table, { mode: 'highest' });
103
- const [firstTableCell] = Editor.nodes(editor, {
104
- at: editor.selection?.anchor.path.slice(0, 1),
105
- match: n => Element.isElement(n) && n.type === 'paragraph',
106
- mode: 'highest'
107
- });
108
- if (firstTableCell) {
109
- const [, path] = firstTableCell;
110
- path.push(0);
111
- const nextPosition = { path, offset: 0 };
112
- Transforms.setSelection(editor, { anchor: nextPosition, focus: nextPosition });
113
- }
114
- },
115
- // Finds the image placeholder and replaces it with an image node
116
- appendImage: (editor, imageData, id) => {
117
- const [node] = Editor.nodes(editor, {
118
- match: n => Element.isElement(n) && n.type === 'image-placeholder',
119
- at: [Number(id)]
120
- });
121
- if (node) {
122
- const [, path] = node;
123
- Transforms.setNodes(editor, { type: 'image', src: imageData.src, alt: imageData.alt }, { at: path });
124
- Transforms.unsetNodes(editor, 'id', { at: path });
125
- return Editor.end(editor, path);
126
- }
127
- return null;
128
- },
129
- appendImagePlaceholder: (editor) => {
130
- const node = commands.getSelectedNode(editor);
131
- if (node) {
132
- const [, path] = node;
133
- const next = Path.next(path);
134
- Transforms.insertNodes(editor, { type: 'image-placeholder', children: [{ text: '' }] }, { at: next });
135
- return next[0].toString();
136
- }
137
- return '';
138
- },
139
- // Creates a link at the given selection
140
- createLink: (editor, text, url, selection) => {
141
- const linkNode = { text: text || url, href: url };
142
- if (selection) {
143
- if (Range.isCollapsed(selection)) {
144
- const [node] = Editor.node(editor, selection);
145
- if (Text.isText(node) && node.href) {
146
- const before = Editor.before(editor, selection, { unit: 'word' });
147
- const after = Editor.after(editor, selection, { unit: 'word' });
148
- if (before && after) {
149
- Transforms.insertNodes(editor, [linkNode], { at: { anchor: before, focus: after } });
150
- }
151
- else if (before) {
152
- const calculatedAfter = Editor.after(editor, before, { unit: 'word' });
153
- if (calculatedAfter) {
154
- Transforms.insertNodes(editor, [linkNode], {
155
- at: { anchor: before, focus: calculatedAfter }
156
- });
157
- }
158
- }
159
- else if (after) {
160
- const calculatedBefore = Editor.before(editor, after, { unit: 'word' });
161
- if (calculatedBefore) {
162
- Transforms.insertNodes(editor, [linkNode], {
163
- at: { anchor: calculatedBefore, focus: after }
164
- });
165
- }
166
- }
167
- }
168
- else {
169
- Transforms.insertNodes(editor, [linkNode]);
170
- }
171
- }
172
- else {
173
- Transforms.insertNodes(editor, [linkNode], {
174
- at: selection
175
- });
176
- }
177
- }
178
- else {
179
- Transforms.insertNodes(editor, [linkNode]);
180
- }
181
- },
182
- // Used to handle the enter key when the cursor is next to an image, inserts a new paragraph
183
- checkImageEnter: (editor, e) => {
184
- const [image] = Editor.nodes(editor, {
185
- match: n => Element.isElement(n) && n.type === 'image'
186
- });
187
- if (image) {
188
- if (e.keyCode < 37 && e.keyCode > 40) {
189
- e.preventDefault();
190
- }
191
- if (e.key === 'Enter') {
192
- e.preventDefault();
193
- const [, path] = image;
194
- const next = Path.next(path);
195
- Transforms.insertNodes(editor, { type: 'paragraph', children: [{ text: '' }] }, { at: next });
196
- Transforms.select(editor, next);
197
- }
198
- }
199
- },
200
- // Turns the href property off on the text node when space is pressed while on a link
201
- checkLinkBreak: (editor, e) => {
202
- const [link] = Editor.nodes(editor, {
203
- match: n => Text.isText(n) && !!n.href
204
- });
205
- if (link && (e.key === ' ' || e.key === 'Enter')) {
206
- e.preventDefault();
207
- Editor.insertNode(editor, { text: e.key === 'Enter' ? '\n' : ' ' });
208
- Editor.removeMark(editor, 'href');
209
- }
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
- },
323
- // Either adds a tab character or indents a list depending on the selection
324
- indent: (editor) => {
325
- const [nodeInListItem] = Editor.nodes(editor, {
326
- match: n => Element.isElement(n) && n.type === 'list-item'
327
- });
328
- if (nodeInListItem) {
329
- ListCommands.nestList(editor);
330
- return;
331
- }
332
- if (editor.selection) {
333
- let start = Editor.before(editor, editor.selection, { unit: 'block' });
334
- start = start || Editor.start(editor, editor.selection);
335
- Transforms.insertText(editor, '\t', { at: start });
336
- }
337
- },
338
- // Either removes a tab character or un indents a list depending on the selection
339
- unindent: (editor) => {
340
- const [nodeInListItem] = Editor.nodes(editor, {
341
- match: n => Element.isElement(n) && n.type === 'list-item'
342
- });
343
- if (nodeInListItem) {
344
- ListCommands.unNestList(editor);
345
- return;
346
- }
347
- if (editor.selection) {
348
- let start = Editor.before(editor, editor.selection, { unit: 'block' });
349
- start = start || Editor.start(editor, editor.selection);
350
- let end = Editor.after(editor, editor.selection, { unit: 'block' });
351
- end = end || Editor.end(editor, editor.selection);
352
- if (start && end) {
353
- const text = Editor.string(editor, { anchor: start, focus: end });
354
- const newText = text.replace(/\t/, '');
355
- Transforms.insertText(editor, newText, { at: { anchor: start, focus: end } });
356
- }
357
- }
358
- },
359
- checkKeyCommands: (editor, e) => {
360
- const cmdOrCtrl = e.metaKey || e.ctrlKey;
361
- let commandExecuted = false;
362
- if (cmdOrCtrl) {
363
- // Command or Ctrl + Shift
364
- if (e.shiftKey) {
365
- switch (e.key) {
366
- case 'b':
367
- commands.toggleFormat('bold', editor);
368
- commandExecuted = true;
369
- break;
370
- case 'i':
371
- commands.toggleFormat('italic', editor);
372
- commandExecuted = true;
373
- break;
374
- case 'x':
375
- commands.toggleFormat('line-through', editor);
376
- commandExecuted = true;
377
- break;
378
- case 'l':
379
- ListCommands.toggleList('unordered-list', editor);
380
- commandExecuted = true;
381
- break;
382
- default:
383
- }
384
- // Command or Ctrl but not alt
385
- }
386
- else if (!e.shiftKey && !e.altKey) {
387
- switch (e.key) {
388
- case 'b':
389
- commands.toggleFormat('bold', editor);
390
- commandExecuted = true;
391
- break;
392
- case 'i':
393
- commands.toggleFormat('italic', editor);
394
- commandExecuted = true;
395
- break;
396
- default:
397
- }
398
- }
399
- }
400
- if (e.altKey) {
401
- if (cmdOrCtrl) {
402
- if (textKeyCodeMapping[e.keyCode]) {
403
- commands.setBlock(textKeyCodeMapping[e.keyCode], editor);
404
- commandExecuted = true;
405
- }
406
- }
407
- else if (e.keyCode === 77) {
408
- if (e.shiftKey) {
409
- commands.unindent(editor);
410
- commandExecuted = true;
411
- }
412
- else {
413
- commands.indent(editor);
414
- commandExecuted = true;
415
- }
416
- }
417
- }
418
- if (commandExecuted)
419
- e.preventDefault();
420
- }
421
- };
422
- export default commands;
423
- //# sourceMappingURL=EditorCommands.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EditorCommands.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/EditorCommands.ts"],"names":[],"mappings":"AAC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} 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"]}
@@ -1,10 +0,0 @@
1
- import { KeyboardEvent } from 'react';
2
- import { Editor } from 'slate';
3
- declare const commands: {
4
- toggleList: (type: 'unordered-list' | 'ordered-list', editor: Editor) => void;
5
- checkListEnter: (editor: Editor, event: KeyboardEvent<any>) => void;
6
- nestList: (editor: Editor) => void;
7
- unNestList: (editor: Editor) => void;
8
- };
9
- export default commands;
10
- //# sourceMappingURL=ListCommands.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ListCommands.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/ListCommands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,MAAM,EAAkE,MAAM,OAAO,CAAC;AAwB/F,QAAA,MAAM,QAAQ;uBACO,gBAAgB,GAAG,cAAc,UAAU,MAAM;6BAmB3C,MAAM,SAAS,cAAc,GAAG,CAAC;uBAqFvC,MAAM;yBAyIJ,MAAM;CAgJ5B,CAAC;AAEF,eAAe,QAAQ,CAAC"}