@react-fabric/lexical 1.0.0-beta.6 → 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 (134) hide show
  1. package/{src/editor/Lexical.module.css → css/_lexical.css} +8 -4
  2. package/css/styles.css +24 -0
  3. package/dist/cjs/{packages/lexical/src/components → components}/StickyComponent.js +3 -4
  4. package/dist/cjs/{packages/lexical/src/editor → editor}/LexicalEditor.js +35 -10
  5. package/dist/cjs/{packages/lexical/src/hooks → hooks}/useFormatWatcher.js +154 -145
  6. package/dist/cjs/i18n/ar.json.js +24 -0
  7. package/dist/cjs/i18n/en.json.js +24 -0
  8. package/dist/cjs/i18n/index.js +33 -0
  9. package/dist/cjs/{packages/lexical/src/index.js → index.js} +1 -0
  10. package/dist/cjs/{packages/lexical/src/plugins → plugins}/DraggableBlockPlugin.js +5 -5
  11. package/dist/cjs/{packages/lexical/src/plugins → plugins}/ToolbarPlugin.js +55 -34
  12. package/dist/esm/{packages/lexical/src/components → components}/StickyComponent.js +3 -4
  13. package/dist/esm/{packages/lexical/src/editor → editor}/LexicalEditor.js +34 -9
  14. package/dist/esm/{packages/lexical/src/hooks → hooks}/useFormatWatcher.js +102 -93
  15. package/dist/esm/i18n/ar.json.js +21 -0
  16. package/dist/esm/i18n/en.json.js +21 -0
  17. package/dist/esm/i18n/index.js +33 -0
  18. package/dist/esm/{packages/lexical/src/index.js → index.js} +1 -0
  19. package/dist/esm/{packages/lexical/src/plugins → plugins}/DraggableBlockPlugin.js +2 -2
  20. package/dist/esm/{packages/lexical/src/plugins → plugins}/ToolbarPlugin.js +56 -35
  21. package/dist/types/editor/LexicalEditor.d.ts +25 -0
  22. package/dist/types/hooks/useFormatWatcher.d.ts +3 -2
  23. package/dist/types/i18n/index.d.ts +1 -0
  24. package/dist/types/index.d.ts +1 -0
  25. package/dist/types/nodes/StickyNode.d.ts +0 -1
  26. package/package.json +14 -13
  27. package/src/components/StickyComponent.tsx +4 -5
  28. package/src/editor/LexicalEditor.tsx +57 -26
  29. package/src/hooks/useFormatWatcher.ts +38 -31
  30. package/src/i18n/ar.json +16 -0
  31. package/src/i18n/en.json +16 -0
  32. package/src/i18n/index.ts +28 -0
  33. package/src/index.ts +2 -0
  34. package/src/plugins/ToolbarPlugin.tsx +56 -35
  35. package/dist/cjs/_virtual/prism.js +0 -5
  36. package/dist/cjs/editor/Lexical.module.css +0 -1
  37. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +0 -432
  38. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.js +0 -21
  39. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +0 -27
  40. package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +0 -1139
  41. package/dist/cjs/node_modules/@lexical/code/LexicalCode.js +0 -25
  42. package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +0 -50
  43. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +0 -245
  44. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.js +0 -19
  45. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +0 -18
  46. package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +0 -471
  47. package/dist/cjs/node_modules/@lexical/link/LexicalLink.js +0 -17
  48. package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +0 -24
  49. package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +0 -1275
  50. package/dist/cjs/node_modules/@lexical/list/LexicalList.js +0 -29
  51. package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +0 -29
  52. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +0 -789
  53. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.js +0 -29
  54. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +0 -26
  55. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +0 -976
  56. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +0 -35
  57. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +0 -35
  58. package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +0 -2792
  59. package/dist/cjs/node_modules/@lexical/table/LexicalTable.js +0 -23
  60. package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +0 -55
  61. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +0 -888
  62. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +0 -35
  63. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +0 -66
  64. package/dist/cjs/node_modules/@mdi/js/mdi.js +0 -8
  65. package/dist/cjs/node_modules/prismjs/components/prism-c.js +0 -82
  66. package/dist/cjs/node_modules/prismjs/components/prism-clike.js +0 -33
  67. package/dist/cjs/node_modules/prismjs/components/prism-cpp.js +0 -101
  68. package/dist/cjs/node_modules/prismjs/components/prism-css.js +0 -66
  69. package/dist/cjs/node_modules/prismjs/components/prism-java.js +0 -126
  70. package/dist/cjs/node_modules/prismjs/components/prism-javascript.js +0 -174
  71. package/dist/cjs/node_modules/prismjs/components/prism-markdown.js +0 -417
  72. package/dist/cjs/node_modules/prismjs/components/prism-markup.js +0 -188
  73. package/dist/cjs/node_modules/prismjs/components/prism-objectivec.js +0 -14
  74. package/dist/cjs/node_modules/prismjs/components/prism-powershell.js +0 -60
  75. package/dist/cjs/node_modules/prismjs/components/prism-python.js +0 -67
  76. package/dist/cjs/node_modules/prismjs/components/prism-rust.js +0 -130
  77. package/dist/cjs/node_modules/prismjs/components/prism-sql.js +0 -34
  78. package/dist/cjs/node_modules/prismjs/components/prism-swift.js +0 -150
  79. package/dist/cjs/node_modules/prismjs/components/prism-typescript.js +0 -62
  80. package/dist/cjs/node_modules/prismjs/prism.js +0 -1951
  81. package/dist/esm/_virtual/prism.js +0 -5
  82. package/dist/esm/editor/Lexical.module.css +0 -1
  83. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +0 -423
  84. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.js +0 -19
  85. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +0 -18
  86. package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +0 -1121
  87. package/dist/esm/node_modules/@lexical/code/LexicalCode.js +0 -21
  88. package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +0 -32
  89. package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +0 -244
  90. package/dist/esm/node_modules/@lexical/html/LexicalHtml.js +0 -18
  91. package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +0 -17
  92. package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +0 -463
  93. package/dist/esm/node_modules/@lexical/link/LexicalLink.js +0 -17
  94. package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +0 -16
  95. package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +0 -1262
  96. package/dist/esm/node_modules/@lexical/list/LexicalList.js +0 -23
  97. package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +0 -16
  98. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +0 -781
  99. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.js +0 -23
  100. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +0 -18
  101. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +0 -957
  102. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +0 -26
  103. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +0 -16
  104. package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +0 -2754
  105. package/dist/esm/node_modules/@lexical/table/LexicalTable.js +0 -20
  106. package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +0 -17
  107. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +0 -839
  108. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +0 -26
  109. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +0 -17
  110. package/dist/esm/node_modules/@mdi/js/mdi.js +0 -7
  111. package/dist/esm/node_modules/prismjs/components/prism-c.js +0 -82
  112. package/dist/esm/node_modules/prismjs/components/prism-clike.js +0 -33
  113. package/dist/esm/node_modules/prismjs/components/prism-cpp.js +0 -101
  114. package/dist/esm/node_modules/prismjs/components/prism-css.js +0 -66
  115. package/dist/esm/node_modules/prismjs/components/prism-java.js +0 -126
  116. package/dist/esm/node_modules/prismjs/components/prism-javascript.js +0 -174
  117. package/dist/esm/node_modules/prismjs/components/prism-markdown.js +0 -417
  118. package/dist/esm/node_modules/prismjs/components/prism-markup.js +0 -188
  119. package/dist/esm/node_modules/prismjs/components/prism-objectivec.js +0 -14
  120. package/dist/esm/node_modules/prismjs/components/prism-powershell.js +0 -60
  121. package/dist/esm/node_modules/prismjs/components/prism-python.js +0 -67
  122. package/dist/esm/node_modules/prismjs/components/prism-rust.js +0 -130
  123. package/dist/esm/node_modules/prismjs/components/prism-sql.js +0 -34
  124. package/dist/esm/node_modules/prismjs/components/prism-swift.js +0 -150
  125. package/dist/esm/node_modules/prismjs/components/prism-typescript.js +0 -62
  126. package/dist/esm/node_modules/prismjs/prism.js +0 -1951
  127. /package/dist/cjs/{packages/lexical/src/editor → editor}/theme.js +0 -0
  128. /package/dist/cjs/{packages/lexical/src/nodes → nodes}/StickyNode.js +0 -0
  129. /package/dist/cjs/{packages/lexical/src/plugins → plugins}/StickyPlugin.js +0 -0
  130. /package/dist/cjs/{packages/lexical/src/utils → utils}/index.js +0 -0
  131. /package/dist/esm/{packages/lexical/src/editor → editor}/theme.js +0 -0
  132. /package/dist/esm/{packages/lexical/src/nodes → nodes}/StickyNode.js +0 -0
  133. /package/dist/esm/{packages/lexical/src/plugins → plugins}/StickyPlugin.js +0 -0
  134. /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 +0,0 @@
1
- @layer util{.lexicalEditor,.lexicalToolbar{margin:0 auto;width:21cm}.lexicalEditor :global{.editor-container.editor-container.editor-container{background-color:#fff;color:#0f172a;font-family:Sakkal Majalla;font-size:18px}.editor-heading-h1{font-size:1.5em;margin-bottom:1.5em;text-transform:capitalize}.editor-heading-h1,.editor-heading-h2{font-weight:600;line-height:1.5;margin-top:1.5em;padding:0 4px}.editor-heading-h2{font-size:1.25em;margin-bottom:1em}.editor-heading-h6{color:#b45309;font-size:.875em;font-weight:600;line-height:1.25;margin-bottom:1.5em;margin-top:1.5em}.editor-paragraph{font-size:1em}.editor-paragraph,.editor-quote{line-height:1.5;margin-bottom:1.5em;margin-top:1.5em}.editor-quote{border-color:#64748b;padding-inline-start:1em}.editor-code,.editor-quote{border-inline-start-width:4px;color:#1e293b;display:block;font-size:1.125em}.editor-code{background-color:#e2e8f0;line-height:1.5;margin-bottom:1.5em;margin-top:1.5em;padding:1em}.editor-textUnderline{text-decoration:underline}.editor-textStrikethrough{text-decoration:line-through}.editor-textUnderlineStrikethrough{text-decoration:underline line-through}.editor-page-break{page-break-after:always}.editor-no-break{page-break-inside:avoid}.editor-textSmall{font-size:.875em}.editor-textBold{font-weight:600}.editor-textItalic{font-style:italic}.editor-textMuted{color:#4b5563}.editor-list-ul{list-style:disc;padding-inline-start:.5em}.editor-list-ol{list-style:decimal;padding-inline-start:.5em}.editor-listItem{margin-inline-start:1em;text-align:start}@media print{body,html{margin:0;min-height:100vh}div,h1,h2,h3,h4,h5,h6,p,span{box-sizing:border-box}body.report-template{background-size:0;min-height:100vh}body:after{background-image:inherit;content:"";height:100vh;inset:0;margin:0 auto;max-width:21cm;position:fixed;-webkit-print-color-adjust:exact;print-color-adjust:exact;width:100vw;z-index:10}.editor-page-break>div,.sticky__container{display:none}.editor-container{position:relative}.editor-editor{box-sizing:border-box;padding:0 2cm}}}}
@@ -1,423 +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, $getRoot, $parseSerializedNode, $isTextNode, COPY_COMMAND, COMMAND_PRIORITY_CRITICAL, isSelectionWithinEditor, $getEditor, $isElementNode, $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
- const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
26
-
27
- /**
28
- * Copyright (c) Meta Platforms, Inc. and affiliates.
29
- *
30
- * This source code is licensed under the MIT license found in the
31
- * LICENSE file in the root directory of this source tree.
32
- *
33
- */
34
-
35
- const getDOMSelection = targetWindow => CAN_USE_DOM ? (targetWindow || window).getSelection() : null;
36
- /**
37
- * Returns the *currently selected* Lexical content as an HTML string, relying on the
38
- * logic defined in the exportDOM methods on the LexicalNode classes. Note that
39
- * this will not return the HTML content of the entire editor (unless all the content is included
40
- * in the current selection).
41
- *
42
- * @param editor - LexicalEditor instance to get HTML content from
43
- * @param selection - The selection to use (default is $getSelection())
44
- * @returns a string of HTML content
45
- */
46
- function $getHtmlContent(editor, selection = $getSelection()) {
47
- if (selection == null) {
48
- {
49
- throw Error(`Expected valid LexicalSelection`);
50
- }
51
- }
52
-
53
- // If we haven't selected anything
54
- if ($isRangeSelection(selection) && selection.isCollapsed() || selection.getNodes().length === 0) {
55
- return '';
56
- }
57
- return $generateHtmlFromNodes(editor, selection);
58
- }
59
-
60
- /**
61
- * Returns the *currently selected* Lexical content as a JSON string, relying on the
62
- * logic defined in the exportJSON methods on the LexicalNode classes. Note that
63
- * this will not return the JSON content of the entire editor (unless all the content is included
64
- * in the current selection).
65
- *
66
- * @param editor - LexicalEditor instance to get the JSON content from
67
- * @param selection - The selection to use (default is $getSelection())
68
- * @returns
69
- */
70
- function $getLexicalContent(editor, selection = $getSelection()) {
71
- if (selection == null) {
72
- {
73
- throw Error(`Expected valid LexicalSelection`);
74
- }
75
- }
76
-
77
- // If we haven't selected anything
78
- if ($isRangeSelection(selection) && selection.isCollapsed() || selection.getNodes().length === 0) {
79
- return null;
80
- }
81
- return JSON.stringify($generateJSONFromSelectedNodes(editor, selection));
82
- }
83
-
84
- /**
85
- * Attempts to insert content of the mime-types text/plain or text/uri-list from
86
- * the provided DataTransfer object into the editor at the provided selection.
87
- * text/uri-list is only used if text/plain is not also provided.
88
- *
89
- * @param dataTransfer an object conforming to the [DataTransfer interface] (https://html.spec.whatwg.org/multipage/dnd.html#the-datatransfer-interface)
90
- * @param selection the selection to use as the insertion point for the content in the DataTransfer object
91
- */
92
- function $insertDataTransferForPlainText(dataTransfer, selection) {
93
- const text = dataTransfer.getData('text/plain') || dataTransfer.getData('text/uri-list');
94
- if (text != null) {
95
- selection.insertRawText(text);
96
- }
97
- }
98
-
99
- /**
100
- * Attempts to insert content of the mime-types application/x-lexical-editor, text/html,
101
- * text/plain, or text/uri-list (in descending order of priority) from the provided DataTransfer
102
- * object into the editor at the provided selection.
103
- *
104
- * @param dataTransfer an object conforming to the [DataTransfer interface] (https://html.spec.whatwg.org/multipage/dnd.html#the-datatransfer-interface)
105
- * @param selection the selection to use as the insertion point for the content in the DataTransfer object
106
- * @param editor the LexicalEditor the content is being inserted into.
107
- */
108
- function $insertDataTransferForRichText(dataTransfer, selection, editor) {
109
- const lexicalString = dataTransfer.getData('application/x-lexical-editor');
110
- if (lexicalString) {
111
- try {
112
- const payload = JSON.parse(lexicalString);
113
- if (payload.namespace === editor._config.namespace && Array.isArray(payload.nodes)) {
114
- const nodes = $generateNodesFromSerializedNodes(payload.nodes);
115
- return $insertGeneratedNodes(editor, nodes, selection);
116
- }
117
- } catch (_unused) {
118
- // Fail silently.
119
- }
120
- }
121
- const htmlString = dataTransfer.getData('text/html');
122
- if (htmlString) {
123
- try {
124
- const parser = new DOMParser();
125
- const dom = parser.parseFromString(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 = dataTransfer.getData('text/plain') || 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
-
162
- /**
163
- * Inserts Lexical nodes into the editor using different strategies depending on
164
- * some simple selection-based heuristics. If you're looking for a generic way to
165
- * to insert nodes into the editor at a specific selection point, you probably want
166
- * {@link lexical.$insertNodes}
167
- *
168
- * @param editor LexicalEditor instance to insert the nodes into.
169
- * @param nodes The nodes to insert.
170
- * @param selection The selection to insert the nodes into.
171
- */
172
- function $insertGeneratedNodes(editor, nodes, selection) {
173
- if (!editor.dispatchCommand(SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, {
174
- nodes,
175
- selection
176
- })) {
177
- selection.insertNodes(nodes);
178
- }
179
- return;
180
- }
181
- function exportNodeToJSON(node) {
182
- const serializedNode = node.exportJSON();
183
- const nodeClass = node.constructor;
184
- if (serializedNode.type !== nodeClass.getType()) {
185
- {
186
- throw Error(`LexicalNode: Node ${nodeClass.name} does not implement .exportJSON().`);
187
- }
188
- }
189
- if ($isElementNode(node)) {
190
- const serializedChildren = serializedNode.children;
191
- if (!Array.isArray(serializedChildren)) {
192
- {
193
- throw Error(`LexicalNode: Node ${nodeClass.name} is an element but .exportJSON() does not have a children array.`);
194
- }
195
- }
196
- }
197
- return serializedNode;
198
- }
199
- function $appendNodesToJSON(editor, selection, currentNode, targetArray = []) {
200
- let shouldInclude = selection !== null ? currentNode.isSelected(selection) : true;
201
- const shouldExclude = $isElementNode(currentNode) && currentNode.excludeFromCopy('html');
202
- let target = currentNode;
203
- if (selection !== null) {
204
- let clone = $cloneWithProperties(currentNode);
205
- clone = $isTextNode(clone) && selection !== null ? $sliceSelectedTextNodeContent(selection, clone) : clone;
206
- target = clone;
207
- }
208
- const children = $isElementNode(target) ? target.getChildren() : [];
209
- const serializedNode = exportNodeToJSON(target);
210
-
211
- // TODO: TextNode calls getTextContent() (NOT node.__text) within its exportJSON method
212
- // which uses getLatest() to get the text from the original node with the same key.
213
- // This is a deeper issue with the word "clone" here, it's still a reference to the
214
- // same node as far as the LexicalEditor is concerned since it shares a key.
215
- // We need a way to create a clone of a Node in memory with its own key, but
216
- // until then this hack will work for the selected text extract use case.
217
- if ($isTextNode(target)) {
218
- const text = target.__text;
219
- // If an uncollapsed selection ends or starts at the end of a line of specialized,
220
- // TextNodes, such as code tokens, we will get a 'blank' TextNode here, i.e., one
221
- // with text of length 0. We don't want this, it makes a confusing mess. Reset!
222
- if (text.length > 0) {
223
- serializedNode.text = text;
224
- } else {
225
- shouldInclude = false;
226
- }
227
- }
228
- for (let i = 0; i < children.length; i++) {
229
- const childNode = children[i];
230
- const shouldIncludeChild = $appendNodesToJSON(editor, selection, childNode, serializedNode.children);
231
- if (!shouldInclude && $isElementNode(currentNode) && shouldIncludeChild && currentNode.extractWithChild(childNode, selection, 'clone')) {
232
- shouldInclude = true;
233
- }
234
- }
235
- if (shouldInclude && !shouldExclude) {
236
- targetArray.push(serializedNode);
237
- } else if (Array.isArray(serializedNode.children)) {
238
- for (let i = 0; i < serializedNode.children.length; i++) {
239
- const serializedChildNode = serializedNode.children[i];
240
- targetArray.push(serializedChildNode);
241
- }
242
- }
243
- return shouldInclude;
244
- }
245
-
246
- // TODO why $ function with Editor instance?
247
- /**
248
- * Gets the Lexical JSON of the nodes inside the provided Selection.
249
- *
250
- * @param editor LexicalEditor to get the JSON content from.
251
- * @param selection Selection to get the JSON content from.
252
- * @returns an object with the editor namespace and a list of serializable nodes as JavaScript objects.
253
- */
254
- function $generateJSONFromSelectedNodes(editor, selection) {
255
- const nodes = [];
256
- const root = $getRoot();
257
- const topLevelChildren = root.getChildren();
258
- for (let i = 0; i < topLevelChildren.length; i++) {
259
- const topLevelNode = topLevelChildren[i];
260
- $appendNodesToJSON(editor, selection, topLevelNode, nodes);
261
- }
262
- return {
263
- namespace: editor._config.namespace,
264
- nodes
265
- };
266
- }
267
-
268
- /**
269
- * This method takes an array of objects conforming to the BaseSeralizedNode interface and returns
270
- * an Array containing instances of the corresponding LexicalNode classes registered on the editor.
271
- * Normally, you'd get an Array of BaseSerialized nodes from {@link $generateJSONFromSelectedNodes}
272
- *
273
- * @param serializedNodes an Array of objects conforming to the BaseSerializedNode interface.
274
- * @returns an Array of Lexical Node objects.
275
- */
276
- function $generateNodesFromSerializedNodes(serializedNodes) {
277
- const nodes = [];
278
- for (let i = 0; i < serializedNodes.length; i++) {
279
- const serializedNode = serializedNodes[i];
280
- const node = $parseSerializedNode(serializedNode);
281
- if ($isTextNode(node)) {
282
- $addNodeStyle(node);
283
- }
284
- nodes.push(node);
285
- }
286
- return nodes;
287
- }
288
- const EVENT_LATENCY = 50;
289
- let clipboardEventTimeout = null;
290
-
291
- // TODO custom selection
292
- // TODO potentially have a node customizable version for plain text
293
- /**
294
- * Copies the content of the current selection to the clipboard in
295
- * text/plain, text/html, and application/x-lexical-editor (Lexical JSON)
296
- * formats.
297
- *
298
- * @param editor the LexicalEditor instance to copy content from
299
- * @param event the native browser ClipboardEvent to add the content to.
300
- * @returns
301
- */
302
- async function copyToClipboard(editor, event, data) {
303
- if (clipboardEventTimeout !== null) {
304
- // Prevent weird race conditions that can happen when this function is run multiple times
305
- // synchronously. In the future, we can do better, we can cancel/override the previously running job.
306
- return false;
307
- }
308
- if (event !== null) {
309
- return new Promise((resolve, reject) => {
310
- editor.update(() => {
311
- resolve($copyToClipboardEvent(editor, event, data));
312
- });
313
- });
314
- }
315
- const rootElement = editor.getRootElement();
316
- const windowDocument = editor._window == null ? window.document : editor._window.document;
317
- const domSelection = getDOMSelection(editor._window);
318
- if (rootElement === null || domSelection === null) {
319
- return false;
320
- }
321
- const element = windowDocument.createElement('span');
322
- element.style.cssText = 'position: fixed; top: -1000px;';
323
- element.append(windowDocument.createTextNode('#'));
324
- rootElement.append(element);
325
- const range = new Range();
326
- range.setStart(element, 0);
327
- range.setEnd(element, 1);
328
- domSelection.removeAllRanges();
329
- domSelection.addRange(range);
330
- return new Promise((resolve, reject) => {
331
- const removeListener = editor.registerCommand(COPY_COMMAND, secondEvent => {
332
- if (objectKlassEquals(secondEvent, ClipboardEvent)) {
333
- removeListener();
334
- if (clipboardEventTimeout !== null) {
335
- window.clearTimeout(clipboardEventTimeout);
336
- clipboardEventTimeout = null;
337
- }
338
- resolve($copyToClipboardEvent(editor, secondEvent, data));
339
- }
340
- // Block the entire copy flow while we wait for the next ClipboardEvent
341
- return true;
342
- }, COMMAND_PRIORITY_CRITICAL);
343
- // If the above hack execCommand hack works, this timeout code should never fire. Otherwise,
344
- // the listener will be quickly freed so that the user can reuse it again
345
- clipboardEventTimeout = window.setTimeout(() => {
346
- removeListener();
347
- clipboardEventTimeout = null;
348
- resolve(false);
349
- }, EVENT_LATENCY);
350
- windowDocument.execCommand('copy');
351
- element.remove();
352
- });
353
- }
354
-
355
- // TODO shouldn't pass editor (pass namespace directly)
356
- function $copyToClipboardEvent(editor, event, data) {
357
- if (data === undefined) {
358
- const domSelection = getDOMSelection(editor._window);
359
- if (!domSelection) {
360
- return false;
361
- }
362
- const anchorDOM = domSelection.anchorNode;
363
- const focusDOM = domSelection.focusNode;
364
- if (anchorDOM !== null && focusDOM !== null && !isSelectionWithinEditor(editor, anchorDOM, focusDOM)) {
365
- return false;
366
- }
367
- const selection = $getSelection();
368
- if (selection === null) {
369
- return false;
370
- }
371
- data = $getClipboardDataFromSelection(selection);
372
- }
373
- event.preventDefault();
374
- const clipboardData = event.clipboardData;
375
- if (clipboardData === null) {
376
- return false;
377
- }
378
- setLexicalClipboardDataTransfer(clipboardData, data);
379
- return true;
380
- }
381
- const clipboardDataFunctions = [['text/html', $getHtmlContent], ['application/x-lexical-editor', $getLexicalContent]];
382
-
383
- /**
384
- * Serialize the content of the current selection to strings in
385
- * text/plain, text/html, and application/x-lexical-editor (Lexical JSON)
386
- * formats (as available).
387
- *
388
- * @param selection the selection to serialize (defaults to $getSelection())
389
- * @returns LexicalClipboardData
390
- */
391
- function $getClipboardDataFromSelection(selection = $getSelection()) {
392
- const clipboardData = {
393
- 'text/plain': selection ? selection.getTextContent() : ''
394
- };
395
- if (selection) {
396
- const editor = $getEditor();
397
- for (const [mimeType, $editorFn] of clipboardDataFunctions) {
398
- const v = $editorFn(editor, selection);
399
- if (v !== null) {
400
- clipboardData[mimeType] = v;
401
- }
402
- }
403
- }
404
- return clipboardData;
405
- }
406
-
407
- /**
408
- * Call setData on the given clipboardData for each MIME type present
409
- * in the given data (from {@link $getClipboardDataFromSelection})
410
- *
411
- * @param clipboardData the event.clipboardData to populate from data
412
- * @param data The lexical data
413
- */
414
- function setLexicalClipboardDataTransfer(clipboardData, data) {
415
- for (const k in data) {
416
- const v = data[k];
417
- if (v !== undefined) {
418
- clipboardData.setData(k, v);
419
- }
420
- }
421
- }
422
-
423
- 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 === 'development' ? 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, $getRoot, $parseSerializedNode, $isTextNode, COPY_COMMAND, COMMAND_PRIORITY_CRITICAL, isSelectionWithinEditor, $getEditor, $isElementNode, $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 w(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var y=w((function(t){const e=new URLSearchParams;e.append("code",t);for(let t=1;t<arguments.length;t++)e.append("v",arguments[t]);throw Error(`Minified Lexical error #${t}; visit https://lexical.dev/docs/error?${e} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));const v="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,C=t=>v?(t||window).getSelection():null;function D(e,n=$getSelection()){return null==n&&y(166),$isRangeSelection(n)&&n.isCollapsed()||0===n.getNodes().length?"":$generateHtmlFromNodes(e,n)}function N(t,e=$getSelection()){return null==e&&y(166),$isRangeSelection(e)&&e.isCollapsed()||0===e.getNodes().length?null:JSON.stringify(R(t,e))}function _(t,e){const n=t.getData("text/plain")||t.getData("text/uri-list");null!=n&&e.insertRawText(n);}function T(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 S(o,E(t.nodes),n)}}catch(t){}const s=t.getData("text/html");if(s)try{const t=(new DOMParser).parseFromString(s,"text/html");return S(o,$generateNodesFromDOM(o,t),n)}catch(t){}const a=t.getData("text/plain")||t.getData("text/uri-list");if(null!=a)if($isRangeSelection(n)){const t=a.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(a);}function S(t,e,n){t.dispatchCommand(SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,{nodes:e,selection:n})||n.insertNodes(e);}function A(t,e,n,r=[]){let l=null===e||n.isSelected(e);const i=$isElementNode(n)&&n.excludeFromCopy("html");let c=n;if(null!==e){let t=$cloneWithProperties(n);t=$isTextNode(t)&&null!==e?$sliceSelectedTextNodeContent(e,t):t,c=t;}const s=$isElementNode(c)?c.getChildren():[],a=function(t){const e=t.exportJSON(),n=t.constructor;if(e.type!==n.getType()&&y(58,n.name),$isElementNode(t)){const t=e.children;Array.isArray(t)||y(59,n.name);}return e}(c);if($isTextNode(c)){const t=c.__text;t.length>0?a.text=t:l=!1;}for(let o=0;o<s.length;o++){const r=s[o],i=A(t,e,r,a.children);!l&&$isElementNode(n)&&i&&n.extractWithChild(r,e,"clone")&&(l=!0);}if(l&&!i)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 l}function R(t,e){const n=[],o=$getRoot().getChildren();for(let r=0;r<o.length;r++){A(t,e,o[r],n);}return {namespace:t._config.namespace,nodes:n}}function E(t){const e=[];for(let o=0;o<t.length;o++){const r=t[o],l=$parseSerializedNode(r);$isTextNode(l)&&$addNodeStyle(l),e.push(l);}return e}let O=null;async function P(t,e,n){if(null!==O)return !1;if(null!==e)return new Promise(((o,r)=>{t.update((()=>{o(b(t,e,n));}));}));const o=t.getRootElement(),l=null==t._window?window.document:t._window.document,i=C(t._window);if(null===o||null===i)return !1;const c=l.createElement("span");c.style.cssText="position: fixed; top: -1000px;",c.append(l.createTextNode("#")),o.append(c);const s=new Range;return s.setStart(c,0),s.setEnd(c,1),i.removeAllRanges(),i.addRange(s),new Promise(((e,o)=>{const i=t.registerCommand(COPY_COMMAND,(o=>(objectKlassEquals(o,ClipboardEvent)&&(i(),null!==O&&(window.clearTimeout(O),O=null),e(b(t,o,n))),!0)),COMMAND_PRIORITY_CRITICAL);O=window.setTimeout((()=>{i(),O=null,e(!1);}),50),l.execCommand("copy"),c.remove();}))}function b(t,e,n){if(void 0===n){const e=C(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 l=$getSelection();if(null===l)return !1;n=M(l);}e.preventDefault();const o=e.clipboardData;return null!==o&&(F(o,n),!0)}const J=[["text/html",D],["application/x-lexical-editor",N]];function M(t=$getSelection()){const e={"text/plain":t?t.getTextContent():""};if(t){const n=$getEditor();for(const[o,r]of J){const l=r(n,t);null!==l&&(e[o]=l);}}return e}function F(t,e){for(const n in e){const o=e[n];void 0!==o&&t.setData(n,o);}}
17
-
18
- export { R as $generateJSONFromSelectedNodes, E as $generateNodesFromSerializedNodes, M as $getClipboardDataFromSelection, D as $getHtmlContent, N as $getLexicalContent, _ as $insertDataTransferForPlainText, T as $insertDataTransferForRichText, S as $insertGeneratedNodes, P as copyToClipboard, F as setLexicalClipboardDataTransfer };