@react-fabric/lexical 1.0.0-beta.60 → 1.0.0-beta.61

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 (127) hide show
  1. package/dist/cjs/{packages/lexical/src/components → components}/StickyComponent.js +2 -3
  2. package/dist/cjs/{packages/lexical/src/editor → editor}/LexicalEditor.js +5 -5
  3. package/dist/cjs/{packages/lexical/src/hooks → hooks}/useFormatWatcher.js +101 -95
  4. package/dist/cjs/i18n/ar.json.js +24 -0
  5. package/dist/cjs/i18n/en.json.js +24 -0
  6. package/dist/cjs/i18n/index.js +33 -0
  7. package/dist/cjs/{packages/lexical/src/index.js → index.js} +1 -0
  8. package/dist/cjs/{packages/lexical/src/plugins → plugins}/DraggableBlockPlugin.js +5 -5
  9. package/dist/cjs/{packages/lexical/src/plugins → plugins}/ToolbarPlugin.js +35 -22
  10. package/dist/esm/{packages/lexical/src/components → components}/StickyComponent.js +2 -3
  11. package/dist/esm/{packages/lexical/src/editor → editor}/LexicalEditor.js +4 -4
  12. package/dist/esm/{packages/lexical/src/hooks → hooks}/useFormatWatcher.js +43 -37
  13. package/dist/esm/i18n/ar.json.js +21 -0
  14. package/dist/esm/i18n/en.json.js +21 -0
  15. package/dist/esm/i18n/index.js +33 -0
  16. package/dist/esm/{packages/lexical/src/index.js → index.js} +1 -0
  17. package/dist/esm/{packages/lexical/src/plugins → plugins}/DraggableBlockPlugin.js +2 -2
  18. package/dist/esm/{packages/lexical/src/plugins → plugins}/ToolbarPlugin.js +36 -23
  19. package/dist/types/hooks/useFormatWatcher.d.ts +1 -0
  20. package/dist/types/i18n/index.d.ts +1 -0
  21. package/dist/types/index.d.ts +1 -0
  22. package/package.json +5 -5
  23. package/src/components/StickyComponent.tsx +2 -3
  24. package/src/hooks/useFormatWatcher.ts +3 -0
  25. package/src/i18n/ar.json +16 -0
  26. package/src/i18n/en.json +16 -0
  27. package/src/i18n/index.ts +28 -0
  28. package/src/index.ts +2 -0
  29. package/src/plugins/ToolbarPlugin.tsx +34 -23
  30. package/dist/cjs/_virtual/prism.js +0 -5
  31. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +0 -474
  32. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.js +0 -21
  33. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +0 -27
  34. package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +0 -1537
  35. package/dist/cjs/node_modules/@lexical/code/LexicalCode.js +0 -25
  36. package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +0 -57
  37. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +0 -252
  38. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.js +0 -19
  39. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +0 -18
  40. package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +0 -572
  41. package/dist/cjs/node_modules/@lexical/link/LexicalLink.js +0 -17
  42. package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +0 -25
  43. package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +0 -1614
  44. package/dist/cjs/node_modules/@lexical/list/LexicalList.js +0 -29
  45. package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +0 -36
  46. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +0 -838
  47. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.js +0 -29
  48. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +0 -26
  49. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +0 -1057
  50. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +0 -39
  51. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +0 -45
  52. package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +0 -4207
  53. package/dist/cjs/node_modules/@lexical/table/LexicalTable.js +0 -23
  54. package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +0 -68
  55. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +0 -1166
  56. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +0 -47
  57. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +0 -81
  58. package/dist/cjs/node_modules/@mdi/js/mdi.js +0 -8
  59. package/dist/cjs/node_modules/prismjs/components/prism-c.js +0 -82
  60. package/dist/cjs/node_modules/prismjs/components/prism-clike.js +0 -33
  61. package/dist/cjs/node_modules/prismjs/components/prism-cpp.js +0 -101
  62. package/dist/cjs/node_modules/prismjs/components/prism-css.js +0 -66
  63. package/dist/cjs/node_modules/prismjs/components/prism-java.js +0 -126
  64. package/dist/cjs/node_modules/prismjs/components/prism-javascript.js +0 -174
  65. package/dist/cjs/node_modules/prismjs/components/prism-markdown.js +0 -417
  66. package/dist/cjs/node_modules/prismjs/components/prism-markup.js +0 -188
  67. package/dist/cjs/node_modules/prismjs/components/prism-objectivec.js +0 -14
  68. package/dist/cjs/node_modules/prismjs/components/prism-powershell.js +0 -60
  69. package/dist/cjs/node_modules/prismjs/components/prism-python.js +0 -67
  70. package/dist/cjs/node_modules/prismjs/components/prism-rust.js +0 -130
  71. package/dist/cjs/node_modules/prismjs/components/prism-sql.js +0 -34
  72. package/dist/cjs/node_modules/prismjs/components/prism-swift.js +0 -150
  73. package/dist/cjs/node_modules/prismjs/components/prism-typescript.js +0 -62
  74. package/dist/cjs/node_modules/prismjs/prism.js +0 -1951
  75. package/dist/esm/_virtual/prism.js +0 -5
  76. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +0 -465
  77. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.js +0 -19
  78. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +0 -18
  79. package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +0 -1512
  80. package/dist/esm/node_modules/@lexical/code/LexicalCode.js +0 -21
  81. package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +0 -32
  82. package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +0 -251
  83. package/dist/esm/node_modules/@lexical/html/LexicalHtml.js +0 -18
  84. package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +0 -17
  85. package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +0 -563
  86. package/dist/esm/node_modules/@lexical/link/LexicalLink.js +0 -17
  87. package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +0 -16
  88. package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +0 -1595
  89. package/dist/esm/node_modules/@lexical/list/LexicalList.js +0 -23
  90. package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +0 -17
  91. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +0 -830
  92. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.js +0 -23
  93. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +0 -18
  94. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +0 -1028
  95. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +0 -28
  96. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +0 -16
  97. package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +0 -4156
  98. package/dist/esm/node_modules/@lexical/table/LexicalTable.js +0 -20
  99. package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +0 -17
  100. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +0 -1102
  101. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +0 -32
  102. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +0 -17
  103. package/dist/esm/node_modules/@mdi/js/mdi.js +0 -7
  104. package/dist/esm/node_modules/prismjs/components/prism-c.js +0 -82
  105. package/dist/esm/node_modules/prismjs/components/prism-clike.js +0 -33
  106. package/dist/esm/node_modules/prismjs/components/prism-cpp.js +0 -101
  107. package/dist/esm/node_modules/prismjs/components/prism-css.js +0 -66
  108. package/dist/esm/node_modules/prismjs/components/prism-java.js +0 -126
  109. package/dist/esm/node_modules/prismjs/components/prism-javascript.js +0 -174
  110. package/dist/esm/node_modules/prismjs/components/prism-markdown.js +0 -417
  111. package/dist/esm/node_modules/prismjs/components/prism-markup.js +0 -188
  112. package/dist/esm/node_modules/prismjs/components/prism-objectivec.js +0 -14
  113. package/dist/esm/node_modules/prismjs/components/prism-powershell.js +0 -60
  114. package/dist/esm/node_modules/prismjs/components/prism-python.js +0 -67
  115. package/dist/esm/node_modules/prismjs/components/prism-rust.js +0 -130
  116. package/dist/esm/node_modules/prismjs/components/prism-sql.js +0 -34
  117. package/dist/esm/node_modules/prismjs/components/prism-swift.js +0 -150
  118. package/dist/esm/node_modules/prismjs/components/prism-typescript.js +0 -62
  119. package/dist/esm/node_modules/prismjs/prism.js +0 -1951
  120. /package/dist/cjs/{packages/lexical/src/editor → editor}/theme.js +0 -0
  121. /package/dist/cjs/{packages/lexical/src/nodes → nodes}/StickyNode.js +0 -0
  122. /package/dist/cjs/{packages/lexical/src/plugins → plugins}/StickyPlugin.js +0 -0
  123. /package/dist/cjs/{packages/lexical/src/utils → utils}/index.js +0 -0
  124. /package/dist/esm/{packages/lexical/src/editor → editor}/theme.js +0 -0
  125. /package/dist/esm/{packages/lexical/src/nodes → nodes}/StickyNode.js +0 -0
  126. /package/dist/esm/{packages/lexical/src/plugins → plugins}/StickyPlugin.js +0 -0
  127. /package/dist/esm/{packages/lexical/src/utils → utils}/index.js +0 -0
@@ -1,5 +0,0 @@
1
- 'use client';
2
-
3
- var prism = {exports: {}};
4
-
5
- export { prism as __module };
@@ -1,465 +0,0 @@
1
- 'use client';
2
-
3
- import { $generateHtmlFromNodes, $generateNodesFromDOM } from '../html/LexicalHtml.js';
4
- import { $addNodeStyle, $sliceSelectedTextNodeContent } from '../selection/LexicalSelection.js';
5
- import { objectKlassEquals } from '../utils/LexicalUtils.js';
6
- import { $isRangeSelection, $getSelection, $createTabNode, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, $caretFromPoint, $isTextPointCaret, $getCaretRange, $getChildCaret, $getRoot, $isTextNode, $isElementNode, $parseSerializedNode, getDOMSelection, COPY_COMMAND, COMMAND_PRIORITY_CRITICAL, isSelectionWithinEditor, $getEditor, $cloneWithProperties } from 'lexical';
7
-
8
- /**
9
- * Copyright (c) Meta Platforms, Inc. and affiliates.
10
- *
11
- * This source code is licensed under the MIT license found in the
12
- * LICENSE file in the root directory of this source tree.
13
- *
14
- */
15
-
16
-
17
- /**
18
- * Copyright (c) Meta Platforms, Inc. and affiliates.
19
- *
20
- * This source code is licensed under the MIT license found in the
21
- * LICENSE file in the root directory of this source tree.
22
- *
23
- */
24
-
25
- // Do not require this module directly! Use normal `invariant` calls.
26
-
27
- function formatDevErrorMessage(message) {
28
- throw new Error(message);
29
- }
30
-
31
- /**
32
- * Returns the *currently selected* Lexical content as an HTML string, relying on the
33
- * logic defined in the exportDOM methods on the LexicalNode classes. Note that
34
- * this will not return the HTML content of the entire editor (unless all the content is included
35
- * in the current selection).
36
- *
37
- * @param editor - LexicalEditor instance to get HTML content from
38
- * @param selection - The selection to use (default is $getSelection())
39
- * @returns a string of HTML content
40
- */
41
- function $getHtmlContent(editor, selection = $getSelection()) {
42
- if (selection == null) {
43
- {
44
- formatDevErrorMessage(`Expected valid LexicalSelection`);
45
- }
46
- }
47
-
48
- // If we haven't selected anything
49
- if ($isRangeSelection(selection) && selection.isCollapsed() || selection.getNodes().length === 0) {
50
- return '';
51
- }
52
- return $generateHtmlFromNodes(editor, selection);
53
- }
54
-
55
- /**
56
- * Returns the *currently selected* Lexical content as a JSON string, relying on the
57
- * logic defined in the exportJSON methods on the LexicalNode classes. Note that
58
- * this will not return the JSON content of the entire editor (unless all the content is included
59
- * in the current selection).
60
- *
61
- * @param editor - LexicalEditor instance to get the JSON content from
62
- * @param selection - The selection to use (default is $getSelection())
63
- * @returns
64
- */
65
- function $getLexicalContent(editor, selection = $getSelection()) {
66
- if (selection == null) {
67
- {
68
- formatDevErrorMessage(`Expected valid LexicalSelection`);
69
- }
70
- }
71
-
72
- // If we haven't selected anything
73
- if ($isRangeSelection(selection) && selection.isCollapsed() || selection.getNodes().length === 0) {
74
- return null;
75
- }
76
- return JSON.stringify($generateJSONFromSelectedNodes(editor, selection));
77
- }
78
-
79
- /**
80
- * Attempts to insert content of the mime-types text/plain or text/uri-list from
81
- * the provided DataTransfer object into the editor at the provided selection.
82
- * text/uri-list is only used if text/plain is not also provided.
83
- *
84
- * @param dataTransfer an object conforming to the [DataTransfer interface] (https://html.spec.whatwg.org/multipage/dnd.html#the-datatransfer-interface)
85
- * @param selection the selection to use as the insertion point for the content in the DataTransfer object
86
- */
87
- function $insertDataTransferForPlainText(dataTransfer, selection) {
88
- const text = dataTransfer.getData('text/plain') || dataTransfer.getData('text/uri-list');
89
- if (text != null) {
90
- selection.insertRawText(text);
91
- }
92
- }
93
-
94
- /**
95
- * Attempts to insert content of the mime-types application/x-lexical-editor, text/html,
96
- * text/plain, or text/uri-list (in descending order of priority) from the provided DataTransfer
97
- * object into the editor at the provided selection.
98
- *
99
- * @param dataTransfer an object conforming to the [DataTransfer interface] (https://html.spec.whatwg.org/multipage/dnd.html#the-datatransfer-interface)
100
- * @param selection the selection to use as the insertion point for the content in the DataTransfer object
101
- * @param editor the LexicalEditor the content is being inserted into.
102
- */
103
- function $insertDataTransferForRichText(dataTransfer, selection, editor) {
104
- const lexicalString = dataTransfer.getData('application/x-lexical-editor');
105
- if (lexicalString) {
106
- try {
107
- const payload = JSON.parse(lexicalString);
108
- if (payload.namespace === editor._config.namespace && Array.isArray(payload.nodes)) {
109
- const nodes = $generateNodesFromSerializedNodes(payload.nodes);
110
- return $insertGeneratedNodes(editor, nodes, selection);
111
- }
112
- } catch (_unused) {
113
- // Fail silently.
114
- }
115
- }
116
- const htmlString = dataTransfer.getData('text/html');
117
- const plainString = dataTransfer.getData('text/plain');
118
-
119
- // Skip HTML handling if it matches the plain text representation.
120
- // This avoids unnecessary processing for plain text strings created by
121
- // iOS Safari autocorrect, which incorrectly includes a `text/html` type.
122
- if (htmlString && plainString !== htmlString) {
123
- try {
124
- const parser = new DOMParser();
125
- const dom = parser.parseFromString(trustHTML(htmlString), 'text/html');
126
- const nodes = $generateNodesFromDOM(editor, dom);
127
- return $insertGeneratedNodes(editor, nodes, selection);
128
- } catch (_unused2) {
129
- // Fail silently.
130
- }
131
- }
132
-
133
- // Multi-line plain text in rich text mode pasted as separate paragraphs
134
- // instead of single paragraph with linebreaks.
135
- // Webkit-specific: Supports read 'text/uri-list' in clipboard.
136
- const text = plainString || dataTransfer.getData('text/uri-list');
137
- if (text != null) {
138
- if ($isRangeSelection(selection)) {
139
- const parts = text.split(/(\r?\n|\t)/);
140
- if (parts[parts.length - 1] === '') {
141
- parts.pop();
142
- }
143
- for (let i = 0; i < parts.length; i++) {
144
- const currentSelection = $getSelection();
145
- if ($isRangeSelection(currentSelection)) {
146
- const part = parts[i];
147
- if (part === '\n' || part === '\r\n') {
148
- currentSelection.insertParagraph();
149
- } else if (part === '\t') {
150
- currentSelection.insertNodes([$createTabNode()]);
151
- } else {
152
- currentSelection.insertText(part);
153
- }
154
- }
155
- }
156
- } else {
157
- selection.insertRawText(text);
158
- }
159
- }
160
- }
161
- function trustHTML(html) {
162
- if (window.trustedTypes && window.trustedTypes.createPolicy) {
163
- const policy = window.trustedTypes.createPolicy('lexical', {
164
- createHTML: input => input
165
- });
166
- return policy.createHTML(html);
167
- }
168
- return html;
169
- }
170
-
171
- /**
172
- * Inserts Lexical nodes into the editor using different strategies depending on
173
- * some simple selection-based heuristics. If you're looking for a generic way to
174
- * to insert nodes into the editor at a specific selection point, you probably want
175
- * {@link lexical.$insertNodes}
176
- *
177
- * @param editor LexicalEditor instance to insert the nodes into.
178
- * @param nodes The nodes to insert.
179
- * @param selection The selection to insert the nodes into.
180
- */
181
- function $insertGeneratedNodes(editor, nodes, selection) {
182
- if (!editor.dispatchCommand(SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, {
183
- nodes,
184
- selection
185
- })) {
186
- selection.insertNodes(nodes);
187
- $updateSelectionOnInsert(selection);
188
- }
189
- return;
190
- }
191
- function $updateSelectionOnInsert(selection) {
192
- if ($isRangeSelection(selection) && selection.isCollapsed()) {
193
- const anchor = selection.anchor;
194
- let nodeToInspect = null;
195
- const anchorCaret = $caretFromPoint(anchor, 'previous');
196
- if (anchorCaret) {
197
- if ($isTextPointCaret(anchorCaret)) {
198
- nodeToInspect = anchorCaret.origin;
199
- } else {
200
- const range = $getCaretRange(anchorCaret, $getChildCaret($getRoot(), 'next').getFlipped());
201
- for (const caret of range) {
202
- if ($isTextNode(caret.origin)) {
203
- nodeToInspect = caret.origin;
204
- break;
205
- } else if ($isElementNode(caret.origin) && !caret.origin.isInline()) {
206
- break;
207
- }
208
- }
209
- }
210
- }
211
- if (nodeToInspect && $isTextNode(nodeToInspect)) {
212
- const newFormat = nodeToInspect.getFormat();
213
- const newStyle = nodeToInspect.getStyle();
214
- if (selection.format !== newFormat || selection.style !== newStyle) {
215
- selection.format = newFormat;
216
- selection.style = newStyle;
217
- selection.dirty = true;
218
- }
219
- }
220
- }
221
- }
222
- function exportNodeToJSON(node) {
223
- const serializedNode = node.exportJSON();
224
- const nodeClass = node.constructor;
225
- if (serializedNode.type !== nodeClass.getType()) {
226
- {
227
- formatDevErrorMessage(`LexicalNode: Node ${nodeClass.name} does not implement .exportJSON().`);
228
- }
229
- }
230
- if ($isElementNode(node)) {
231
- const serializedChildren = serializedNode.children;
232
- if (!Array.isArray(serializedChildren)) {
233
- {
234
- formatDevErrorMessage(`LexicalNode: Node ${nodeClass.name} is an element but .exportJSON() does not have a children array.`);
235
- }
236
- }
237
- }
238
- return serializedNode;
239
- }
240
- function $appendNodesToJSON(editor, selection, currentNode, targetArray = []) {
241
- let shouldInclude = selection !== null ? currentNode.isSelected(selection) : true;
242
- const shouldExclude = $isElementNode(currentNode) && currentNode.excludeFromCopy('html');
243
- let target = currentNode;
244
- if (selection !== null) {
245
- let clone = $cloneWithProperties(currentNode);
246
- clone = $isTextNode(clone) && selection !== null ? $sliceSelectedTextNodeContent(selection, clone) : clone;
247
- target = clone;
248
- }
249
- const children = $isElementNode(target) ? target.getChildren() : [];
250
- const serializedNode = exportNodeToJSON(target);
251
-
252
- // TODO: TextNode calls getTextContent() (NOT node.__text) within its exportJSON method
253
- // which uses getLatest() to get the text from the original node with the same key.
254
- // This is a deeper issue with the word "clone" here, it's still a reference to the
255
- // same node as far as the LexicalEditor is concerned since it shares a key.
256
- // We need a way to create a clone of a Node in memory with its own key, but
257
- // until then this hack will work for the selected text extract use case.
258
- if ($isTextNode(target)) {
259
- const text = target.__text;
260
- // If an uncollapsed selection ends or starts at the end of a line of specialized,
261
- // TextNodes, such as code tokens, we will get a 'blank' TextNode here, i.e., one
262
- // with text of length 0. We don't want this, it makes a confusing mess. Reset!
263
- if (text.length > 0) {
264
- serializedNode.text = text;
265
- } else {
266
- shouldInclude = false;
267
- }
268
- }
269
- for (let i = 0; i < children.length; i++) {
270
- const childNode = children[i];
271
- const shouldIncludeChild = $appendNodesToJSON(editor, selection, childNode, serializedNode.children);
272
- if (!shouldInclude && $isElementNode(currentNode) && shouldIncludeChild && currentNode.extractWithChild(childNode, selection, 'clone')) {
273
- shouldInclude = true;
274
- }
275
- }
276
- if (shouldInclude && !shouldExclude) {
277
- targetArray.push(serializedNode);
278
- } else if (Array.isArray(serializedNode.children)) {
279
- for (let i = 0; i < serializedNode.children.length; i++) {
280
- const serializedChildNode = serializedNode.children[i];
281
- targetArray.push(serializedChildNode);
282
- }
283
- }
284
- return shouldInclude;
285
- }
286
-
287
- // TODO why $ function with Editor instance?
288
- /**
289
- * Gets the Lexical JSON of the nodes inside the provided Selection.
290
- *
291
- * @param editor LexicalEditor to get the JSON content from.
292
- * @param selection Selection to get the JSON content from.
293
- * @returns an object with the editor namespace and a list of serializable nodes as JavaScript objects.
294
- */
295
- function $generateJSONFromSelectedNodes(editor, selection) {
296
- const nodes = [];
297
- const root = $getRoot();
298
- const topLevelChildren = root.getChildren();
299
- for (let i = 0; i < topLevelChildren.length; i++) {
300
- const topLevelNode = topLevelChildren[i];
301
- $appendNodesToJSON(editor, selection, topLevelNode, nodes);
302
- }
303
- return {
304
- namespace: editor._config.namespace,
305
- nodes
306
- };
307
- }
308
-
309
- /**
310
- * This method takes an array of objects conforming to the BaseSerializedNode interface and returns
311
- * an Array containing instances of the corresponding LexicalNode classes registered on the editor.
312
- * Normally, you'd get an Array of BaseSerialized nodes from {@link $generateJSONFromSelectedNodes}
313
- *
314
- * @param serializedNodes an Array of objects conforming to the BaseSerializedNode interface.
315
- * @returns an Array of Lexical Node objects.
316
- */
317
- function $generateNodesFromSerializedNodes(serializedNodes) {
318
- const nodes = [];
319
- for (let i = 0; i < serializedNodes.length; i++) {
320
- const serializedNode = serializedNodes[i];
321
- const node = $parseSerializedNode(serializedNode);
322
- if ($isTextNode(node)) {
323
- $addNodeStyle(node);
324
- }
325
- nodes.push(node);
326
- }
327
- return nodes;
328
- }
329
- const EVENT_LATENCY = 50;
330
- let clipboardEventTimeout = null;
331
-
332
- // TODO custom selection
333
- // TODO potentially have a node customizable version for plain text
334
- /**
335
- * Copies the content of the current selection to the clipboard in
336
- * text/plain, text/html, and application/x-lexical-editor (Lexical JSON)
337
- * formats.
338
- *
339
- * @param editor the LexicalEditor instance to copy content from
340
- * @param event the native browser ClipboardEvent to add the content to.
341
- * @returns
342
- */
343
- async function copyToClipboard(editor, event, data) {
344
- if (clipboardEventTimeout !== null) {
345
- // Prevent weird race conditions that can happen when this function is run multiple times
346
- // synchronously. In the future, we can do better, we can cancel/override the previously running job.
347
- return false;
348
- }
349
- if (event !== null) {
350
- return new Promise((resolve, reject) => {
351
- editor.update(() => {
352
- resolve($copyToClipboardEvent(editor, event, data));
353
- });
354
- });
355
- }
356
- const rootElement = editor.getRootElement();
357
- const editorWindow = editor._window || window;
358
- const windowDocument = window.document;
359
- const domSelection = getDOMSelection(editorWindow);
360
- if (rootElement === null || domSelection === null) {
361
- return false;
362
- }
363
- const element = windowDocument.createElement('span');
364
- element.style.cssText = 'position: fixed; top: -1000px;';
365
- element.append(windowDocument.createTextNode('#'));
366
- rootElement.append(element);
367
- const range = new Range();
368
- range.setStart(element, 0);
369
- range.setEnd(element, 1);
370
- domSelection.removeAllRanges();
371
- domSelection.addRange(range);
372
- return new Promise((resolve, reject) => {
373
- const removeListener = editor.registerCommand(COPY_COMMAND, secondEvent => {
374
- if (objectKlassEquals(secondEvent, ClipboardEvent)) {
375
- removeListener();
376
- if (clipboardEventTimeout !== null) {
377
- window.clearTimeout(clipboardEventTimeout);
378
- clipboardEventTimeout = null;
379
- }
380
- resolve($copyToClipboardEvent(editor, secondEvent, data));
381
- }
382
- // Block the entire copy flow while we wait for the next ClipboardEvent
383
- return true;
384
- }, COMMAND_PRIORITY_CRITICAL);
385
- // If the above hack execCommand hack works, this timeout code should never fire. Otherwise,
386
- // the listener will be quickly freed so that the user can reuse it again
387
- clipboardEventTimeout = window.setTimeout(() => {
388
- removeListener();
389
- clipboardEventTimeout = null;
390
- resolve(false);
391
- }, EVENT_LATENCY);
392
- windowDocument.execCommand('copy');
393
- element.remove();
394
- });
395
- }
396
-
397
- // TODO shouldn't pass editor (pass namespace directly)
398
- function $copyToClipboardEvent(editor, event, data) {
399
- if (data === undefined) {
400
- const domSelection = getDOMSelection(editor._window);
401
- if (!domSelection) {
402
- return false;
403
- }
404
- const anchorDOM = domSelection.anchorNode;
405
- const focusDOM = domSelection.focusNode;
406
- if (anchorDOM !== null && focusDOM !== null && !isSelectionWithinEditor(editor, anchorDOM, focusDOM)) {
407
- return false;
408
- }
409
- const selection = $getSelection();
410
- if (selection === null) {
411
- return false;
412
- }
413
- data = $getClipboardDataFromSelection(selection);
414
- }
415
- event.preventDefault();
416
- const clipboardData = event.clipboardData;
417
- if (clipboardData === null) {
418
- return false;
419
- }
420
- setLexicalClipboardDataTransfer(clipboardData, data);
421
- return true;
422
- }
423
- const clipboardDataFunctions = [['text/html', $getHtmlContent], ['application/x-lexical-editor', $getLexicalContent]];
424
-
425
- /**
426
- * Serialize the content of the current selection to strings in
427
- * text/plain, text/html, and application/x-lexical-editor (Lexical JSON)
428
- * formats (as available).
429
- *
430
- * @param selection the selection to serialize (defaults to $getSelection())
431
- * @returns LexicalClipboardData
432
- */
433
- function $getClipboardDataFromSelection(selection = $getSelection()) {
434
- const clipboardData = {
435
- 'text/plain': selection ? selection.getTextContent() : ''
436
- };
437
- if (selection) {
438
- const editor = $getEditor();
439
- for (const [mimeType, $editorFn] of clipboardDataFunctions) {
440
- const v = $editorFn(editor, selection);
441
- if (v !== null) {
442
- clipboardData[mimeType] = v;
443
- }
444
- }
445
- }
446
- return clipboardData;
447
- }
448
-
449
- /**
450
- * Call setData on the given clipboardData for each MIME type present
451
- * in the given data (from {@link $getClipboardDataFromSelection})
452
- *
453
- * @param clipboardData the event.clipboardData to populate from data
454
- * @param data The lexical data
455
- */
456
- function setLexicalClipboardDataTransfer(clipboardData, data) {
457
- for (const k in data) {
458
- const v = data[k];
459
- if (v !== undefined) {
460
- clipboardData.setData(k, v);
461
- }
462
- }
463
- }
464
-
465
- export { $generateJSONFromSelectedNodes, $generateNodesFromSerializedNodes, $getClipboardDataFromSelection, $getHtmlContent, $getLexicalContent, $insertDataTransferForPlainText, $insertDataTransferForRichText, $insertGeneratedNodes, copyToClipboard, setLexicalClipboardDataTransfer };
@@ -1,19 +0,0 @@
1
- 'use client';
2
-
3
- import * as LexicalClipboard_dev from './LexicalClipboard.dev.js';
4
- import * as LexicalClipboard_prod from './LexicalClipboard.prod.js';
5
-
6
- /**
7
- * Copyright (c) Meta Platforms, Inc. and affiliates.
8
- *
9
- * This source code is licensed under the MIT license found in the
10
- * LICENSE file in the root directory of this source tree.
11
- *
12
- */
13
-
14
- const mod = process.env.NODE_ENV !== 'production' ? LexicalClipboard_dev : LexicalClipboard_prod;
15
- const $getClipboardDataFromSelection = mod.$getClipboardDataFromSelection;
16
- const $insertDataTransferForRichText = mod.$insertDataTransferForRichText;
17
- const copyToClipboard = mod.copyToClipboard;
18
-
19
- export { $getClipboardDataFromSelection, $insertDataTransferForRichText, copyToClipboard };
@@ -1,18 +0,0 @@
1
- 'use client';
2
-
3
- import { $generateHtmlFromNodes, $generateNodesFromDOM } from '../html/LexicalHtml.js';
4
- import { $addNodeStyle, $sliceSelectedTextNodeContent } from '../selection/LexicalSelection.js';
5
- import { objectKlassEquals } from '../utils/LexicalUtils.js';
6
- import { $isRangeSelection, $getSelection, $createTabNode, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, $caretFromPoint, $isTextPointCaret, $getCaretRange, $getChildCaret, $getRoot, $isTextNode, $isElementNode, $parseSerializedNode, getDOMSelection, COPY_COMMAND, COMMAND_PRIORITY_CRITICAL, isSelectionWithinEditor, $getEditor, $cloneWithProperties } from 'lexical';
7
-
8
- /**
9
- * Copyright (c) Meta Platforms, Inc. and affiliates.
10
- *
11
- * This source code is licensed under the MIT license found in the
12
- * LICENSE file in the root directory of this source tree.
13
- *
14
- */
15
-
16
- function D(t,...e){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",t);for(const t of e)o.append("v",t);throw n.search=o.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function N(e,n=$getSelection()){return null==n&&D(166),$isRangeSelection(n)&&n.isCollapsed()||0===n.getNodes().length?"":$generateHtmlFromNodes(e,n)}function S(t,e=$getSelection()){return null==e&&D(166),$isRangeSelection(e)&&e.isCollapsed()||0===e.getNodes().length?null:JSON.stringify(E(t,e))}function R(t,e){const n=t.getData("text/plain")||t.getData("text/uri-list");null!=n&&e.insertRawText(n);}function A(t,n,o){const r=t.getData("application/x-lexical-editor");if(r)try{const t=JSON.parse(r);if(t.namespace===o._config.namespace&&Array.isArray(t.nodes)){return P(o,L(t.nodes),n)}}catch(t){}const c=t.getData("text/html"),a=t.getData("text/plain");if(c&&a!==c)try{const t=(new DOMParser).parseFromString(function(t){if(window.trustedTypes&&window.trustedTypes.createPolicy){return window.trustedTypes.createPolicy("lexical",{createHTML:t=>t}).createHTML(t)}return t}(c),"text/html");return P(o,$generateNodesFromDOM(o,t),n)}catch(t){}const u=a||t.getData("text/uri-list");if(null!=u)if($isRangeSelection(n)){const t=u.split(/(\r?\n|\t)/);""===t[t.length-1]&&t.pop();for(let e=0;e<t.length;e++){const n=$getSelection();if($isRangeSelection(n)){const o=t[e];"\n"===o||"\r\n"===o?n.insertParagraph():"\t"===o?n.insertNodes([$createTabNode()]):n.insertText(o);}}}else n.insertRawText(u);}function P(t,e,n){t.dispatchCommand(SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,{nodes:e,selection:n})||(n.insertNodes(e),function(t){if($isRangeSelection(t)&&t.isCollapsed()){const e=t.anchor;let n=null;const o=$caretFromPoint(e,"previous");if(o)if($isTextPointCaret(o))n=o.origin;else {const t=$getCaretRange(o,$getChildCaret($getRoot(),"next").getFlipped());for(const e of t){if($isTextNode(e.origin)){n=e.origin;break}if($isElementNode(e.origin)&&!e.origin.isInline())break}}if(n&&$isTextNode(n)){const e=n.getFormat(),o=n.getStyle();t.format===e&&t.style===o||(t.format=e,t.style=o,t.dirty=!0);}}}(n));}function _(t,e,n,r=[]){let i=null===e||n.isSelected(e);const l=$isElementNode(n)&&n.excludeFromCopy("html");let s=n;if(null!==e){let t=$cloneWithProperties(n);t=$isTextNode(t)&&null!==e?$sliceSelectedTextNodeContent(e,t):t,s=t;}const c=$isElementNode(s)?s.getChildren():[],a=function(t){const e=t.exportJSON(),n=t.constructor;if(e.type!==n.getType()&&D(58,n.name),$isElementNode(t)){const t=e.children;Array.isArray(t)||D(59,n.name);}return e}(s);if($isTextNode(s)){const t=s.__text;t.length>0?a.text=t:i=!1;}for(let o=0;o<c.length;o++){const r=c[o],l=_(t,e,r,a.children);!i&&$isElementNode(n)&&l&&n.extractWithChild(r,e,"clone")&&(i=!0);}if(i&&!l)r.push(a);else if(Array.isArray(a.children))for(let t=0;t<a.children.length;t++){const e=a.children[t];r.push(e);}return i}function E(t,e){const n=[],o=$getRoot().getChildren();for(let r=0;r<o.length;r++){_(t,e,o[r],n);}return {namespace:t._config.namespace,nodes:n}}function L(t){const e=[];for(let o=0;o<t.length;o++){const r=t[o],i=$parseSerializedNode(r);$isTextNode(i)&&$addNodeStyle(i),e.push(i);}return e}let b=null;async function F(t,e,n){if(null!==b)return !1;if(null!==e)return new Promise(((o,r)=>{t.update((()=>{o(M(t,e,n));}));}));const o=t.getRootElement(),i=t._window||window,l=window.document,s=getDOMSelection(i);if(null===o||null===s)return !1;const c=l.createElement("span");c.style.cssText="position: fixed; top: -1000px;",c.append(l.createTextNode("#")),o.append(c);const a=new Range;return a.setStart(c,0),a.setEnd(c,1),s.removeAllRanges(),s.addRange(a),new Promise(((e,o)=>{const i=t.registerCommand(COPY_COMMAND,(o=>(objectKlassEquals(o,ClipboardEvent)&&(i(),null!==b&&(window.clearTimeout(b),b=null),e(M(t,o,n))),!0)),COMMAND_PRIORITY_CRITICAL);b=window.setTimeout((()=>{i(),b=null,e(!1);}),50),l.execCommand("copy"),c.remove();}))}function M(t,e,n){if(void 0===n){const e=getDOMSelection(t._window);if(!e)return !1;const o=e.anchorNode,r=e.focusNode;if(null!==o&&null!==r&&!isSelectionWithinEditor(t,o,r))return !1;const i=$getSelection();if(null===i)return !1;n=J(i);}e.preventDefault();const o=e.clipboardData;return null!==o&&(k(o,n),!0)}const O=[["text/html",N],["application/x-lexical-editor",S]];function J(t=$getSelection()){const e={"text/plain":t?t.getTextContent():""};if(t){const n=$getEditor();for(const[o,r]of O){const i=r(n,t);null!==i&&(e[o]=i);}}return e}function k(t,e){for(const n in e){const o=e[n];void 0!==o&&t.setData(n,o);}}
17
-
18
- export { E as $generateJSONFromSelectedNodes, L as $generateNodesFromSerializedNodes, J as $getClipboardDataFromSelection, N as $getHtmlContent, S as $getLexicalContent, R as $insertDataTransferForPlainText, A as $insertDataTransferForRichText, P as $insertGeneratedNodes, F as copyToClipboard, k as setLexicalClipboardDataTransfer };