@pega/cosmos-react-rte 5.0.0-dev.4.9 → 5.0.0-dev.5.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.
Files changed (193) hide show
  1. package/lib/components/DynamicContentEditor/DynamicContentEditor.d.ts +12 -0
  2. package/lib/components/DynamicContentEditor/DynamicContentEditor.d.ts.map +1 -0
  3. package/lib/components/DynamicContentEditor/DynamicContentEditor.js +252 -0
  4. package/lib/components/DynamicContentEditor/DynamicContentEditor.js.map +1 -0
  5. package/lib/components/DynamicContentEditor/DynamicContentEditor.test-ids.d.ts +2 -0
  6. package/lib/components/DynamicContentEditor/DynamicContentEditor.test-ids.d.ts.map +1 -0
  7. package/lib/components/DynamicContentEditor/DynamicContentEditor.test-ids.js +8 -0
  8. package/lib/components/DynamicContentEditor/DynamicContentEditor.test-ids.js.map +1 -0
  9. package/lib/components/DynamicContentEditor/DynamicContentEditor.types.d.ts +35 -0
  10. package/lib/components/DynamicContentEditor/DynamicContentEditor.types.d.ts.map +1 -0
  11. package/lib/components/DynamicContentEditor/DynamicContentEditor.types.js +3 -0
  12. package/lib/components/DynamicContentEditor/DynamicContentEditor.types.js.map +1 -0
  13. package/lib/components/DynamicContentEditor/PegaCustomElement.d.ts +329 -0
  14. package/lib/components/DynamicContentEditor/PegaCustomElement.d.ts.map +1 -0
  15. package/lib/components/DynamicContentEditor/PegaCustomElement.js +27 -0
  16. package/lib/components/DynamicContentEditor/PegaCustomElement.js.map +1 -0
  17. package/lib/components/DynamicContentEditor/index.d.ts +3 -0
  18. package/lib/components/DynamicContentEditor/index.d.ts.map +1 -0
  19. package/lib/components/DynamicContentEditor/index.js +2 -0
  20. package/lib/components/DynamicContentEditor/index.js.map +1 -0
  21. package/lib/components/Editor/Editor.context.d.ts +10 -0
  22. package/lib/components/Editor/Editor.context.d.ts.map +1 -0
  23. package/lib/components/Editor/Editor.context.js +10 -0
  24. package/lib/components/Editor/Editor.context.js.map +1 -0
  25. package/lib/components/Editor/Editor.d.ts +19 -0
  26. package/lib/components/Editor/Editor.d.ts.map +1 -0
  27. package/lib/components/Editor/Editor.js +369 -0
  28. package/lib/components/Editor/Editor.js.map +1 -0
  29. package/lib/components/Editor/Editor.styles.d.ts +5 -0
  30. package/lib/components/Editor/Editor.styles.d.ts.map +1 -0
  31. package/lib/components/Editor/Editor.styles.js +50 -0
  32. package/lib/components/Editor/Editor.styles.js.map +1 -0
  33. package/lib/components/Editor/Editor.test-ids.d.ts +2 -0
  34. package/lib/components/Editor/Editor.test-ids.d.ts.map +1 -0
  35. package/lib/components/Editor/Editor.test-ids.js +8 -0
  36. package/lib/components/Editor/Editor.test-ids.js.map +1 -0
  37. package/lib/components/Editor/Editor.types.d.ts +69 -0
  38. package/lib/components/Editor/Editor.types.d.ts.map +1 -0
  39. package/lib/components/Editor/Editor.types.js +2 -0
  40. package/lib/components/Editor/Editor.types.js.map +1 -0
  41. package/lib/components/Editor/ImageEditor.d.ts +10 -0
  42. package/lib/components/Editor/ImageEditor.d.ts.map +1 -0
  43. package/lib/components/Editor/ImageEditor.js +276 -0
  44. package/lib/components/Editor/ImageEditor.js.map +1 -0
  45. package/lib/components/Editor/Toolbar/AnchorButton.d.ts +10 -0
  46. package/lib/components/Editor/Toolbar/AnchorButton.d.ts.map +1 -0
  47. package/lib/components/Editor/Toolbar/AnchorButton.js +161 -0
  48. package/lib/components/Editor/Toolbar/AnchorButton.js.map +1 -0
  49. package/lib/components/Editor/Toolbar/ImageButton.d.ts +8 -0
  50. package/lib/components/Editor/Toolbar/ImageButton.d.ts.map +1 -0
  51. package/lib/components/Editor/Toolbar/ImageButton.js +30 -0
  52. package/lib/components/Editor/Toolbar/ImageButton.js.map +1 -0
  53. package/lib/components/Editor/Toolbar/TextSelect.d.ts +14 -0
  54. package/lib/components/Editor/Toolbar/TextSelect.d.ts.map +1 -0
  55. package/lib/components/Editor/Toolbar/TextSelect.js +131 -0
  56. package/lib/components/Editor/Toolbar/TextSelect.js.map +1 -0
  57. package/lib/components/Editor/Toolbar/Toolbar.d.ts +17 -0
  58. package/lib/components/Editor/Toolbar/Toolbar.d.ts.map +1 -0
  59. package/lib/components/Editor/Toolbar/Toolbar.js +164 -0
  60. package/lib/components/Editor/Toolbar/Toolbar.js.map +1 -0
  61. package/lib/components/Editor/Toolbar/Toolbar.test-ids.d.ts +3 -0
  62. package/lib/components/Editor/Toolbar/Toolbar.test-ids.d.ts.map +1 -0
  63. package/lib/components/Editor/Toolbar/Toolbar.test-ids.js +16 -0
  64. package/lib/components/Editor/Toolbar/Toolbar.test-ids.js.map +1 -0
  65. package/lib/components/Editor/index.d.ts +4 -0
  66. package/lib/components/Editor/index.d.ts.map +1 -0
  67. package/lib/components/Editor/index.js +3 -0
  68. package/lib/components/Editor/index.js.map +1 -0
  69. package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.d.ts +4 -0
  70. package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.d.ts.map +1 -0
  71. package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.js +15 -0
  72. package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.js.map +1 -0
  73. package/lib/components/RichTextEditor/DecoratorComponents/Image.d.ts +4 -0
  74. package/lib/components/RichTextEditor/DecoratorComponents/Image.d.ts.map +1 -0
  75. package/lib/components/RichTextEditor/DecoratorComponents/Image.js +7 -0
  76. package/lib/components/RichTextEditor/DecoratorComponents/Image.js.map +1 -0
  77. package/lib/components/RichTextEditor/DecoratorComponents/Link.d.ts +4 -0
  78. package/lib/components/RichTextEditor/DecoratorComponents/Link.d.ts.map +1 -0
  79. package/lib/components/RichTextEditor/DecoratorComponents/Link.js +8 -0
  80. package/lib/components/RichTextEditor/DecoratorComponents/Link.js.map +1 -0
  81. package/lib/components/RichTextEditor/DecoratorComponents/Table.d.ts +6 -0
  82. package/lib/components/RichTextEditor/DecoratorComponents/Table.d.ts.map +1 -0
  83. package/lib/components/RichTextEditor/DecoratorComponents/Table.js +24 -0
  84. package/lib/components/RichTextEditor/DecoratorComponents/Table.js.map +1 -0
  85. package/lib/components/RichTextEditor/RichTextEditor.context.d.ts +15 -0
  86. package/lib/components/RichTextEditor/RichTextEditor.context.d.ts.map +1 -0
  87. package/lib/components/RichTextEditor/RichTextEditor.context.js +11 -0
  88. package/lib/components/RichTextEditor/RichTextEditor.context.js.map +1 -0
  89. package/lib/components/RichTextEditor/RichTextEditor.d.ts +6 -0
  90. package/lib/components/RichTextEditor/RichTextEditor.d.ts.map +1 -0
  91. package/lib/components/RichTextEditor/RichTextEditor.js +346 -0
  92. package/lib/components/RichTextEditor/RichTextEditor.js.map +1 -0
  93. package/lib/components/RichTextEditor/RichTextEditor.styles.d.ts +10 -0
  94. package/lib/components/RichTextEditor/RichTextEditor.styles.d.ts.map +1 -0
  95. package/lib/components/RichTextEditor/RichTextEditor.styles.js +73 -0
  96. package/lib/components/RichTextEditor/RichTextEditor.styles.js.map +1 -0
  97. package/lib/components/RichTextEditor/RichTextEditor.types.d.ts +72 -0
  98. package/lib/components/RichTextEditor/RichTextEditor.types.d.ts.map +1 -0
  99. package/lib/components/RichTextEditor/RichTextEditor.types.js +2 -0
  100. package/lib/components/RichTextEditor/RichTextEditor.types.js.map +1 -0
  101. package/lib/components/RichTextEditor/RichTextTreeRenderer.d.ts +9 -0
  102. package/lib/components/RichTextEditor/RichTextTreeRenderer.d.ts.map +1 -0
  103. package/lib/components/RichTextEditor/RichTextTreeRenderer.js +15 -0
  104. package/lib/components/RichTextEditor/RichTextTreeRenderer.js.map +1 -0
  105. package/lib/components/RichTextEditor/RichTextViewer.d.ts +7 -0
  106. package/lib/components/RichTextEditor/RichTextViewer.d.ts.map +1 -0
  107. package/lib/components/RichTextEditor/RichTextViewer.js +38 -0
  108. package/lib/components/RichTextEditor/RichTextViewer.js.map +1 -0
  109. package/lib/components/RichTextEditor/RichTextViewer.types.d.ts +33 -0
  110. package/lib/components/RichTextEditor/RichTextViewer.types.d.ts.map +1 -0
  111. package/lib/components/RichTextEditor/RichTextViewer.types.js +2 -0
  112. package/lib/components/RichTextEditor/RichTextViewer.types.js.map +1 -0
  113. package/lib/components/RichTextEditor/Toolbar/AnchorButton.d.ts +8 -0
  114. package/lib/components/RichTextEditor/Toolbar/AnchorButton.d.ts.map +1 -0
  115. package/lib/components/RichTextEditor/Toolbar/AnchorButton.js +156 -0
  116. package/lib/components/RichTextEditor/Toolbar/AnchorButton.js.map +1 -0
  117. package/lib/components/RichTextEditor/Toolbar/ImageButton.d.ts +5 -0
  118. package/lib/components/RichTextEditor/Toolbar/ImageButton.d.ts.map +1 -0
  119. package/lib/components/RichTextEditor/Toolbar/ImageButton.js +30 -0
  120. package/lib/components/RichTextEditor/Toolbar/ImageButton.js.map +1 -0
  121. package/lib/components/RichTextEditor/Toolbar/IndentButton.d.ts +8 -0
  122. package/lib/components/RichTextEditor/Toolbar/IndentButton.d.ts.map +1 -0
  123. package/lib/components/RichTextEditor/Toolbar/IndentButton.js +31 -0
  124. package/lib/components/RichTextEditor/Toolbar/IndentButton.js.map +1 -0
  125. package/lib/components/RichTextEditor/Toolbar/TableButton.d.ts +5 -0
  126. package/lib/components/RichTextEditor/Toolbar/TableButton.d.ts.map +1 -0
  127. package/lib/components/RichTextEditor/Toolbar/TableButton.js +20 -0
  128. package/lib/components/RichTextEditor/Toolbar/TableButton.js.map +1 -0
  129. package/lib/components/RichTextEditor/Toolbar/TextSelect.d.ts +6 -0
  130. package/lib/components/RichTextEditor/Toolbar/TextSelect.d.ts.map +1 -0
  131. package/lib/components/RichTextEditor/Toolbar/TextSelect.js +119 -0
  132. package/lib/components/RichTextEditor/Toolbar/TextSelect.js.map +1 -0
  133. package/lib/components/RichTextEditor/Toolbar/Toolbar.d.ts +10 -0
  134. package/lib/components/RichTextEditor/Toolbar/Toolbar.d.ts.map +1 -0
  135. package/lib/components/RichTextEditor/Toolbar/Toolbar.js +155 -0
  136. package/lib/components/RichTextEditor/Toolbar/Toolbar.js.map +1 -0
  137. package/lib/components/RichTextEditor/Toolbar/Toolbar.types.d.ts +9 -0
  138. package/lib/components/RichTextEditor/Toolbar/Toolbar.types.d.ts.map +1 -0
  139. package/lib/components/RichTextEditor/Toolbar/Toolbar.types.js +2 -0
  140. package/lib/components/RichTextEditor/Toolbar/Toolbar.types.js.map +1 -0
  141. package/lib/components/RichTextEditor/Toolbar/ToolbarButton.d.ts +14 -0
  142. package/lib/components/RichTextEditor/Toolbar/ToolbarButton.d.ts.map +1 -0
  143. package/lib/components/RichTextEditor/Toolbar/ToolbarButton.js +67 -0
  144. package/lib/components/RichTextEditor/Toolbar/ToolbarButton.js.map +1 -0
  145. package/lib/components/RichTextEditor/Toolbar/utils.d.ts +7 -0
  146. package/lib/components/RichTextEditor/Toolbar/utils.d.ts.map +1 -0
  147. package/lib/components/RichTextEditor/Toolbar/utils.js +13 -0
  148. package/lib/components/RichTextEditor/Toolbar/utils.js.map +1 -0
  149. package/lib/components/RichTextEditor/index.d.ts +9 -0
  150. package/lib/components/RichTextEditor/index.d.ts.map +1 -0
  151. package/lib/components/RichTextEditor/index.js +6 -0
  152. package/lib/components/RichTextEditor/index.js.map +1 -0
  153. package/lib/components/RichTextEditor/utils/EditorCommands.d.ts +34 -0
  154. package/lib/components/RichTextEditor/utils/EditorCommands.d.ts.map +1 -0
  155. package/lib/components/RichTextEditor/utils/EditorCommands.js +447 -0
  156. package/lib/components/RichTextEditor/utils/EditorCommands.js.map +1 -0
  157. package/lib/components/RichTextEditor/utils/ListCommands.d.ts +10 -0
  158. package/lib/components/RichTextEditor/utils/ListCommands.d.ts.map +1 -0
  159. package/lib/components/RichTextEditor/utils/ListCommands.js +346 -0
  160. package/lib/components/RichTextEditor/utils/ListCommands.js.map +1 -0
  161. package/lib/components/RichTextEditor/utils/htmlConverter.d.ts +29 -0
  162. package/lib/components/RichTextEditor/utils/htmlConverter.d.ts.map +1 -0
  163. package/lib/components/RichTextEditor/utils/htmlConverter.js +156 -0
  164. package/lib/components/RichTextEditor/utils/htmlConverter.js.map +1 -0
  165. package/lib/components/RichTextEditor/utils/interactionRenderer.d.ts +6 -0
  166. package/lib/components/RichTextEditor/utils/interactionRenderer.d.ts.map +1 -0
  167. package/lib/components/RichTextEditor/utils/interactionRenderer.js +132 -0
  168. package/lib/components/RichTextEditor/utils/interactionRenderer.js.map +1 -0
  169. package/lib/components/RichTextEditor/utils/markdownConverter.d.ts +6 -0
  170. package/lib/components/RichTextEditor/utils/markdownConverter.d.ts.map +1 -0
  171. package/lib/components/RichTextEditor/utils/markdownConverter.js +130 -0
  172. package/lib/components/RichTextEditor/utils/markdownConverter.js.map +1 -0
  173. package/lib/components/RichTextEditor/utils/renderers.d.ts +22 -0
  174. package/lib/components/RichTextEditor/utils/renderers.d.ts.map +1 -0
  175. package/lib/components/RichTextEditor/utils/renderers.js +163 -0
  176. package/lib/components/RichTextEditor/utils/renderers.js.map +1 -0
  177. package/lib/components/RichTextEditor/utils/search.d.ts +11 -0
  178. package/lib/components/RichTextEditor/utils/search.d.ts.map +1 -0
  179. package/lib/components/RichTextEditor/utils/search.js +37 -0
  180. package/lib/components/RichTextEditor/utils/search.js.map +1 -0
  181. package/lib/components/RichTextEditor/utils/slateConverter.d.ts +25 -0
  182. package/lib/components/RichTextEditor/utils/slateConverter.d.ts.map +1 -0
  183. package/lib/components/RichTextEditor/utils/slateConverter.js +88 -0
  184. package/lib/components/RichTextEditor/utils/slateConverter.js.map +1 -0
  185. package/lib/components/RichTextEditor/utils/utils.types.d.ts +3 -0
  186. package/lib/components/RichTextEditor/utils/utils.types.d.ts.map +1 -0
  187. package/lib/components/RichTextEditor/utils/utils.types.js +3 -0
  188. package/lib/components/RichTextEditor/utils/utils.types.js.map +1 -0
  189. package/lib/index.d.ts +5 -0
  190. package/lib/index.d.ts.map +1 -0
  191. package/lib/index.js +6 -0
  192. package/lib/index.js.map +1 -0
  193. package/package.json +2 -2
@@ -0,0 +1,447 @@
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
+ },
64
+ // Gets the highest selected block level node
65
+ getSelectedNode: (editor) => {
66
+ const [node] = Editor.nodes(editor, {
67
+ at: editor.selection || undefined,
68
+ match: n => Element.isElement(n),
69
+ mode: 'highest'
70
+ });
71
+ return node;
72
+ },
73
+ // Appends a 3x3 table into the editor and adds a blank line to the bottom
74
+ appendTable: (editor) => {
75
+ const baseArr = new Array(3).fill(new Array(3).fill(0));
76
+ const table = [
77
+ {
78
+ type: 'table',
79
+ children: [
80
+ {
81
+ type: 'table-body',
82
+ children: baseArr.map(row => {
83
+ return {
84
+ type: 'table-row',
85
+ children: row.map(() => {
86
+ return {
87
+ type: 'table-cell',
88
+ children: [{ type: 'paragraph', children: [{ text: '' }] }]
89
+ };
90
+ })
91
+ };
92
+ })
93
+ }
94
+ ]
95
+ },
96
+ {
97
+ type: 'paragraph',
98
+ children: [{ text: '' }]
99
+ }
100
+ ];
101
+ Transforms.insertNodes(editor, table, { mode: 'highest' });
102
+ const [firstTableCell] = Editor.nodes(editor, {
103
+ at: editor.selection?.anchor.path.slice(0, 1),
104
+ match: n => Element.isElement(n) && n.type === 'paragraph',
105
+ mode: 'highest'
106
+ });
107
+ if (firstTableCell) {
108
+ const [, path] = firstTableCell;
109
+ path.push(0);
110
+ const nextPosition = { path, offset: 0 };
111
+ Transforms.setSelection(editor, { anchor: nextPosition, focus: nextPosition });
112
+ }
113
+ },
114
+ // Finds the image placeholder and replaces it with an image node
115
+ appendImage: (editor, imageData, id) => {
116
+ const [node] = Editor.nodes(editor, {
117
+ match: n => Element.isElement(n) && n.type === 'image-placeholder',
118
+ at: [Number(id)]
119
+ });
120
+ if (node) {
121
+ const [, path] = node;
122
+ Transforms.setNodes(editor, { type: 'image', src: imageData.src, alt: imageData.alt }, { at: path });
123
+ Transforms.unsetNodes(editor, 'id', { at: path });
124
+ return Editor.end(editor, path);
125
+ }
126
+ return null;
127
+ },
128
+ appendImagePlaceholder: (editor) => {
129
+ const node = commands.getSelectedNode(editor);
130
+ if (node) {
131
+ const [, path] = node;
132
+ const next = Path.next(path);
133
+ Transforms.insertNodes(editor, { type: 'image-placeholder', children: [{ text: '' }] }, { at: next });
134
+ return next[0].toString();
135
+ }
136
+ return '';
137
+ },
138
+ // Creates a link at the given selection
139
+ createLink: (editor, text, url, selection) => {
140
+ const linkNode = { text: text || url, href: url };
141
+ if (selection) {
142
+ if (Range.isCollapsed(selection)) {
143
+ const [node] = Editor.node(editor, selection);
144
+ if (Text.isText(node) && node.href) {
145
+ const before = Editor.before(editor, selection, { unit: 'word' });
146
+ const after = Editor.after(editor, selection, { unit: 'word' });
147
+ if (before && after) {
148
+ Transforms.insertNodes(editor, [linkNode], { at: { anchor: before, focus: after } });
149
+ }
150
+ else if (before) {
151
+ const calculatedAfter = Editor.after(editor, before, { unit: 'word' });
152
+ if (calculatedAfter) {
153
+ Transforms.insertNodes(editor, [linkNode], {
154
+ at: { anchor: before, focus: calculatedAfter }
155
+ });
156
+ }
157
+ }
158
+ else if (after) {
159
+ const calculatedBefore = Editor.before(editor, after, { unit: 'word' });
160
+ if (calculatedBefore) {
161
+ Transforms.insertNodes(editor, [linkNode], {
162
+ at: { anchor: calculatedBefore, focus: after }
163
+ });
164
+ }
165
+ }
166
+ }
167
+ else {
168
+ Transforms.insertNodes(editor, [linkNode]);
169
+ }
170
+ }
171
+ else {
172
+ Transforms.insertNodes(editor, [linkNode], {
173
+ at: selection
174
+ });
175
+ }
176
+ }
177
+ else {
178
+ Transforms.insertNodes(editor, [linkNode]);
179
+ }
180
+ },
181
+ // Used to handle the enter key when the cursor is next to an image, inserts a new paragraph
182
+ checkImageEnter: (editor, e) => {
183
+ const [image] = Editor.nodes(editor, {
184
+ match: n => Element.isElement(n) && n.type === 'image'
185
+ });
186
+ if (image) {
187
+ if (e.keyCode < 37 && e.keyCode > 40) {
188
+ e.preventDefault();
189
+ }
190
+ if (e.key === 'Enter') {
191
+ e.preventDefault();
192
+ const [, path] = image;
193
+ const next = Path.next(path);
194
+ Transforms.insertNodes(editor, { type: 'paragraph', children: [{ text: '' }] }, { at: next });
195
+ Transforms.select(editor, next);
196
+ }
197
+ }
198
+ },
199
+ // Turns the href and/or searchResult property off on the text node when space is pressed while on a link or mention
200
+ checkLinkBreak: (editor, e) => {
201
+ const [link] = Editor.nodes(editor, {
202
+ match: n => Text.isText(n) && !!n.href
203
+ });
204
+ const [searchResult] = Editor.nodes(editor, {
205
+ match: n => Text.isText(n) && !!n.searchResult
206
+ });
207
+ if ((link || searchResult) && (e.key === ' ' || e.key === 'Enter')) {
208
+ e.preventDefault();
209
+ Editor.insertNode(editor, { text: e.key === 'Enter' ? '\n' : ' ' });
210
+ Editor.removeMark(editor, link ? 'href' : 'searchResult');
211
+ }
212
+ },
213
+ /**
214
+ * Turns the searchResult property off on the text node when any key is pressed while on a searchResult.
215
+ * Will delete the searchResult node if backspace key is hit.
216
+ * Will re-position cursor to the start/end of the searchResult if arrow navigation is used.
217
+ */
218
+ checkSearchDownKeys: (editor, e) => {
219
+ const [text] = Editor.nodes(editor, {
220
+ match: n => Text.isText(n)
221
+ });
222
+ if (text) {
223
+ const [node, path] = text;
224
+ const nextNode = Editor.next(editor)?.[0];
225
+ const nextPath = Editor.next(editor)?.[1];
226
+ const previousNode = Editor.previous(editor)?.[0];
227
+ const previousPath = Editor.previous(editor)?.[1];
228
+ const next = nextNode && nextNode.searchResult;
229
+ const nextInline = next && path[0] === nextPath?.[0];
230
+ const previous = previousNode && previousNode.searchResult;
231
+ const previousInline = previous && path[0] === previousPath?.[0];
232
+ // Checks if the current selection is a single cursor point rather than spanning multiple characters
233
+ const singlePointSelection = editor.selection?.anchor.offset === editor.selection?.focus.offset &&
234
+ editor.selection?.anchor.path[0] === editor.selection?.focus.path[0] &&
235
+ editor.selection?.anchor.path[1] === editor.selection?.focus.path[1];
236
+ // Checks if the current selected node is a search result, or directly adjacent inline with a search result
237
+ if (node.searchResult || (next && nextInline) || (previous && previousInline)) {
238
+ const atStart = node.searchResult && editor.selection?.anchor.offset === 0;
239
+ const atEnd = node.searchResult && editor.selection?.anchor.offset === node.text.length;
240
+ // Deletes the entire search result only if the cursor is at the end of the search result
241
+ if (e.key === 'Backspace' && (atEnd || (previous && previousInline))) {
242
+ if (singlePointSelection)
243
+ e.preventDefault();
244
+ Transforms.delete(editor, { at: previous ? previousPath : path });
245
+ // Deletes the entire search result only if the cursor is at the start of the search result
246
+ }
247
+ else if (e.key === 'Delete' && (atStart || (next && nextInline))) {
248
+ if (singlePointSelection)
249
+ e.preventDefault();
250
+ Transforms.delete(editor, { at: next ? nextPath : path });
251
+ // Moves cursor to start of search result only if the cursor is at the end of the search result
252
+ }
253
+ else if (e.key === 'ArrowLeft' && (atEnd || (previous && previousInline))) {
254
+ if (singlePointSelection)
255
+ e.preventDefault();
256
+ Transforms.move(editor, {
257
+ distance: previous ? previousNode.text.length : node.text.length,
258
+ unit: 'character',
259
+ reverse: true
260
+ });
261
+ // Moves cursor to end of search result only if the cursor is at the start of the search result
262
+ }
263
+ else if (e.key === 'ArrowRight' && (atStart || (next && nextInline))) {
264
+ if (singlePointSelection)
265
+ e.preventDefault();
266
+ Transforms.move(editor, {
267
+ distance: next ? nextNode.text.length : node.text.length,
268
+ unit: 'character'
269
+ });
270
+ // Ensures all other character (besides special key bindings) are inserted as plain text
271
+ }
272
+ else if (e.key.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey) {
273
+ e.preventDefault();
274
+ Editor.insertNode(editor, { text: e.key === 'Enter' ? '\n' : e.key });
275
+ }
276
+ // Prevents partial search result selections from disabling the searchResult flag
277
+ if (singlePointSelection) {
278
+ Editor.removeMark(editor, 'searchResult');
279
+ }
280
+ }
281
+ }
282
+ },
283
+ // Checks arrow navigation key up events around search results
284
+ checkSearchUpKeys: (editor, e) => {
285
+ const [text] = Editor.nodes(editor, {
286
+ match: n => Text.isText(n)
287
+ });
288
+ if (text) {
289
+ const [node, path] = text;
290
+ const cursorInSearchResult = node.searchResult &&
291
+ editor.selection?.anchor.path[0] === path[0] &&
292
+ editor.selection?.anchor.path[1] === path[1];
293
+ if (cursorInSearchResult && editor.selection) {
294
+ const distanceToStart = editor.selection.anchor.offset;
295
+ const distanceToEnd = node.text.length - editor.selection.anchor.offset;
296
+ // Moves cursor to the start of the search result
297
+ if (e.key === 'ArrowLeft') {
298
+ e.preventDefault();
299
+ Transforms.move(editor, {
300
+ distance: distanceToStart,
301
+ unit: 'character',
302
+ reverse: true
303
+ });
304
+ // Moves cursor to end of search result
305
+ }
306
+ else if (e.key === 'ArrowRight') {
307
+ e.preventDefault();
308
+ Transforms.move(editor, {
309
+ distance: distanceToEnd,
310
+ unit: 'character'
311
+ });
312
+ // Moves cursor to start or end of search result, whichever is closer
313
+ }
314
+ else if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
315
+ e.preventDefault();
316
+ Transforms.move(editor, {
317
+ distance: distanceToStart <= distanceToEnd ? distanceToStart : distanceToEnd,
318
+ unit: 'character',
319
+ reverse: distanceToStart <= distanceToEnd
320
+ });
321
+ }
322
+ }
323
+ }
324
+ },
325
+ // Either adds a tab character or indents a list depending on the selection
326
+ indent: (editor) => {
327
+ const [nodeInListItem] = Editor.nodes(editor, {
328
+ match: n => Element.isElement(n) && n.type === 'list-item'
329
+ });
330
+ if (nodeInListItem) {
331
+ ListCommands.nestList(editor);
332
+ return;
333
+ }
334
+ if (editor.selection) {
335
+ let start = Editor.before(editor, editor.selection, { unit: 'block' });
336
+ start = start || Editor.start(editor, editor.selection);
337
+ Transforms.insertText(editor, '\t', { at: start });
338
+ }
339
+ },
340
+ // Either removes a tab character or un indents a list depending on the selection
341
+ unindent: (editor) => {
342
+ const [nodeInListItem] = Editor.nodes(editor, {
343
+ match: n => Element.isElement(n) && n.type === 'list-item'
344
+ });
345
+ if (nodeInListItem) {
346
+ ListCommands.unNestList(editor);
347
+ return;
348
+ }
349
+ if (editor.selection) {
350
+ let start = Editor.before(editor, editor.selection, { unit: 'block' });
351
+ start = start || Editor.start(editor, editor.selection);
352
+ let end = Editor.after(editor, editor.selection, { unit: 'block' });
353
+ end = end || Editor.end(editor, editor.selection);
354
+ if (start && end) {
355
+ const text = Editor.string(editor, { anchor: start, focus: end });
356
+ const newText = text.replace(/\t/, '');
357
+ Transforms.insertText(editor, newText, { at: { anchor: start, focus: end } });
358
+ }
359
+ }
360
+ },
361
+ checkKeyCommands: (editor, e, markdownOnly) => {
362
+ const cmdOrCtrl = e.metaKey || e.ctrlKey;
363
+ let commandExecuted = false;
364
+ if (cmdOrCtrl && !markdownOnly) {
365
+ // Command or Ctrl + Shift
366
+ if (e.shiftKey) {
367
+ switch (e.key) {
368
+ case 'b':
369
+ commands.toggleFormat('bold', editor);
370
+ commandExecuted = true;
371
+ break;
372
+ case 'i':
373
+ commands.toggleFormat('italic', editor);
374
+ commandExecuted = true;
375
+ break;
376
+ case 'x':
377
+ commands.toggleFormat('line-through', editor);
378
+ commandExecuted = true;
379
+ break;
380
+ case 'l':
381
+ ListCommands.toggleList('unordered-list', editor);
382
+ commandExecuted = true;
383
+ break;
384
+ default:
385
+ }
386
+ // Command or Ctrl but not alt
387
+ }
388
+ else if (!e.shiftKey && !e.altKey) {
389
+ switch (e.key) {
390
+ case 'b':
391
+ commands.toggleFormat('bold', editor);
392
+ commandExecuted = true;
393
+ break;
394
+ case 'i':
395
+ commands.toggleFormat('italic', editor);
396
+ commandExecuted = true;
397
+ break;
398
+ default:
399
+ }
400
+ }
401
+ }
402
+ else if (cmdOrCtrl && markdownOnly && !e.shiftKey && !e.altKey && e.key === 'x') {
403
+ const [searchResult] = Editor.nodes(editor, {
404
+ match: n => Text.isText(n) && !!n.searchResult
405
+ });
406
+ if (searchResult) {
407
+ Editor.removeMark(editor, 'searchResult');
408
+ }
409
+ }
410
+ if (e.altKey && !markdownOnly) {
411
+ if (cmdOrCtrl) {
412
+ if (textKeyCodeMapping[e.keyCode]) {
413
+ commands.setBlock(textKeyCodeMapping[e.keyCode], editor);
414
+ commandExecuted = true;
415
+ }
416
+ }
417
+ else if (e.keyCode === 77) {
418
+ if (e.shiftKey) {
419
+ commands.unindent(editor);
420
+ commandExecuted = true;
421
+ }
422
+ else {
423
+ commands.indent(editor);
424
+ commandExecuted = true;
425
+ }
426
+ }
427
+ }
428
+ if (markdownOnly && e.key === 'Backspace') {
429
+ const [searchResult] = Editor.nodes(editor, {
430
+ match: n => Text.isText(n) && !!n.searchResult
431
+ });
432
+ if (searchResult) {
433
+ Editor.removeMark(editor, 'searchResult');
434
+ }
435
+ if (!editor.selection) {
436
+ Transforms.select(editor, {
437
+ anchor: { offset: 0, path: [0, 0] },
438
+ focus: { offset: 0, path: [0, 0] }
439
+ });
440
+ }
441
+ }
442
+ if (commandExecuted)
443
+ e.preventDefault();
444
+ }
445
+ };
446
+ export default commands;
447
+ //# sourceMappingURL=EditorCommands.js.map
@@ -0,0 +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;AAIf,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,MAAyC,EAAE,MAAc,EAAE,EAAE;QAC5E,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,MAAyC,EAAE,MAAc,EAAE,EAAE;QAC1E,MAAM,YAAY,GAAG,QAAQ,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC7D,IAAI,YAAY,EAAE;YAChB,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;SACnC;aAAM;YACL,M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AAU,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;aAC3C;YACD,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE;gBACrB,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE;oBACxB,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;oBACnC,KAAK,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;iBACnC,CAAC,CAAC;aACJ;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 { ExcludeStrict } from '@pega/cosmos-react-core';\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: ExcludeStrict<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: ExcludeStrict<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 },\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 and/or searchResult property off on the text node when space is pressed while on a link or mention\n checkLinkBreak: (editor: Editor, e: KeyboardEvent) => {\n const [link] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n) && !!n.href\n });\n const [searchResult] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n) && !!n.searchResult\n });\n if ((link || searchResult) && (e.key === ' ' || e.key === 'Enter')) {\n e.preventDefault();\n Editor.insertNode(editor, { text: e.key === 'Enter' ? '\\n' : ' ' });\n Editor.removeMark(editor, link ? 'href' : 'searchResult');\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, markdownOnly?: boolean) => {\n const cmdOrCtrl = e.metaKey || e.ctrlKey;\n let commandExecuted = false;\n if (cmdOrCtrl && !markdownOnly) {\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 } else if (cmdOrCtrl && markdownOnly && !e.shiftKey && !e.altKey && e.key === 'x') {\n const [searchResult] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n) && !!n.searchResult\n });\n if (searchResult) {\n Editor.removeMark(editor, 'searchResult');\n }\n }\n\n if (e.altKey && !markdownOnly) {\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 (markdownOnly && e.key === 'Backspace') {\n const [searchResult] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n) && !!n.searchResult\n });\n if (searchResult) {\n Editor.removeMark(editor, 'searchResult');\n }\n if (!editor.selection) {\n Transforms.select(editor, {\n anchor: { offset: 0, path: [0, 0] },\n focus: { offset: 0, path: [0, 0] }\n });\n }\n }\n\n if (commandExecuted) e.preventDefault();\n }\n};\n\nexport default commands;\n"]}
@@ -0,0 +1,10 @@
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
@@ -0,0 +1 @@
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"}