@lexical/react 0.7.8 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DEPRECATED_useLexical.dev.js +3 -4
- package/DEPRECATED_useLexicalCanShowPlaceholder.dev.js +1 -3
- package/DEPRECATED_useLexicalCharacterLimit.dev.js +7 -39
- package/DEPRECATED_useLexicalEditor.dev.js +1 -3
- package/DEPRECATED_useLexicalPlainText.dev.js +4 -1
- package/DEPRECATED_useLexicalRichText.dev.js +4 -1
- package/LexicalAutoEmbedPlugin.dev.js +0 -11
- package/LexicalAutoFocusPlugin.dev.js +0 -1
- package/LexicalAutoLinkPlugin.dev.js +7 -50
- package/LexicalBlockWithAlignableContents.d.ts +1 -1
- package/LexicalBlockWithAlignableContents.dev.js +0 -11
- package/LexicalCharacterLimitPlugin.dev.js +7 -46
- package/LexicalCheckListPlugin.dev.js +10 -48
- package/LexicalClearEditorPlugin.dev.js +1 -1
- package/LexicalCollaborationContext.dev.js +0 -3
- package/LexicalCollaborationPlugin.dev.js +11 -36
- package/LexicalCollaborationPlugin.prod.js +9 -9
- package/LexicalComposer.dev.js +6 -10
- package/LexicalComposerContext.dev.js +0 -6
- package/LexicalContentEditable.d.ts +16 -25
- package/LexicalContentEditable.dev.js +10 -14
- package/LexicalContentEditable.js.flow +15 -20
- package/LexicalContentEditable.prod.js +3 -3
- package/LexicalDecoratorBlockNode.dev.js +0 -5
- package/LexicalHashtagPlugin.dev.js +73 -43
- package/LexicalHorizontalRuleNode.dev.js +0 -22
- package/LexicalHorizontalRulePlugin.dev.js +0 -4
- package/LexicalLinkPlugin.dev.js +4 -10
- package/LexicalListPlugin.dev.js +1 -9
- package/LexicalListPlugin.prod.js +2 -2
- package/LexicalMarkdownShortcutPlugin.dev.js +2 -2
- package/LexicalNestedComposer.dev.js +8 -11
- package/LexicalNestedComposer.prod.js +3 -3
- package/LexicalNodeEventPlugin.dev.js +5 -3
- package/LexicalOnChangePlugin.dev.js +1 -1
- package/LexicalPlainTextPlugin.dev.js +8 -12
- package/LexicalRichTextPlugin.dev.js +8 -12
- package/LexicalTabIndentationPlugin.dev.js +1 -3
- package/LexicalTableOfContents__EXPERIMENTAL.dev.js +5 -33
- package/LexicalTablePlugin.dev.js +5 -19
- package/LexicalTreeView.dev.js +13 -62
- package/LexicalTreeView.prod.js +13 -13
- package/LexicalTypeaheadMenuPlugin.dev.js +7 -96
- package/package.json +19 -19
- package/shared/useYjsCollaboration.d.ts +1 -1
- package/useLexicalEditable.dev.js +1 -5
- package/useLexicalIsTextContentEmpty.dev.js +1 -0
- package/useLexicalNodeSelection.dev.js +0 -7
- package/useLexicalSubscription.dev.js +1 -3
package/LexicalTreeView.dev.js
CHANGED
|
@@ -53,14 +53,12 @@ function TreeView({
|
|
|
53
53
|
const generateTree = React.useCallback(editorState => {
|
|
54
54
|
const treeText = generateContent(editor.getEditorState(), editor._config, editor._compositionKey, editor._editable);
|
|
55
55
|
setContent(treeText);
|
|
56
|
-
|
|
57
56
|
if (!timeTravelEnabled) {
|
|
58
57
|
setTimeStampedEditorStates(currentEditorStates => [...currentEditorStates, [Date.now(), editorState]]);
|
|
59
58
|
}
|
|
60
59
|
}, [editor, timeTravelEnabled]);
|
|
61
60
|
React.useEffect(() => {
|
|
62
61
|
const editorState = editor.getEditorState();
|
|
63
|
-
|
|
64
62
|
if (!showLimited && editorState._nodeMap.size > 1000) {
|
|
65
63
|
setContent(generateContent(editorState, editor._config, editor._compositionKey, editor._editable));
|
|
66
64
|
}
|
|
@@ -72,12 +70,10 @@ function TreeView({
|
|
|
72
70
|
if (!showLimited && editorState._nodeMap.size > 1000) {
|
|
73
71
|
lastEditorStateRef.current = editorState;
|
|
74
72
|
setIsLimited(true);
|
|
75
|
-
|
|
76
73
|
if (!showLimited) {
|
|
77
74
|
return;
|
|
78
75
|
}
|
|
79
76
|
}
|
|
80
|
-
|
|
81
77
|
generateTree(editorState);
|
|
82
78
|
}), editor.registerEditableListener(() => {
|
|
83
79
|
const treeText = generateContent(editor.getEditorState(), editor._config, editor._compositionKey, editor._editable);
|
|
@@ -88,15 +84,12 @@ function TreeView({
|
|
|
88
84
|
React.useEffect(() => {
|
|
89
85
|
if (isPlaying) {
|
|
90
86
|
let timeoutId;
|
|
91
|
-
|
|
92
87
|
const play = () => {
|
|
93
88
|
const currentIndex = playingIndexRef.current;
|
|
94
|
-
|
|
95
89
|
if (currentIndex === totalEditorStates - 1) {
|
|
96
90
|
setIsPlaying(false);
|
|
97
91
|
return;
|
|
98
92
|
}
|
|
99
|
-
|
|
100
93
|
const currentTime = timeStampedEditorStates[currentIndex][0];
|
|
101
94
|
const nextTime = timeStampedEditorStates[currentIndex + 1][0];
|
|
102
95
|
const timeDiff = nextTime - currentTime;
|
|
@@ -104,16 +97,13 @@ function TreeView({
|
|
|
104
97
|
playingIndexRef.current++;
|
|
105
98
|
const index = playingIndexRef.current;
|
|
106
99
|
const input = inputRef.current;
|
|
107
|
-
|
|
108
100
|
if (input !== null) {
|
|
109
101
|
input.value = String(index);
|
|
110
102
|
}
|
|
111
|
-
|
|
112
103
|
editor.setEditorState(timeStampedEditorStates[index][1]);
|
|
113
104
|
play();
|
|
114
105
|
}, timeDiff);
|
|
115
106
|
};
|
|
116
|
-
|
|
117
107
|
play();
|
|
118
108
|
return () => {
|
|
119
109
|
clearTimeout(timeoutId);
|
|
@@ -122,7 +112,6 @@ function TreeView({
|
|
|
122
112
|
}, [timeStampedEditorStates, isPlaying, editor, totalEditorStates]);
|
|
123
113
|
React.useEffect(() => {
|
|
124
114
|
const element = treeElementRef.current;
|
|
125
|
-
|
|
126
115
|
if (element !== null) {
|
|
127
116
|
// @ts-ignore Internal field
|
|
128
117
|
element.__lexicalEditor = editor;
|
|
@@ -146,7 +135,6 @@ function TreeView({
|
|
|
146
135
|
onClick: () => {
|
|
147
136
|
setShowLimited(true);
|
|
148
137
|
const editorState = lastEditorStateRef.current;
|
|
149
|
-
|
|
150
138
|
if (editorState !== null) {
|
|
151
139
|
lastEditorStateRef.current = null;
|
|
152
140
|
generateTree(editorState);
|
|
@@ -162,7 +150,6 @@ function TreeView({
|
|
|
162
150
|
}, "Show full tree")) : null, !timeTravelEnabled && (showLimited || !isLimited) && totalEditorStates > 2 && /*#__PURE__*/React.createElement("button", {
|
|
163
151
|
onClick: () => {
|
|
164
152
|
const rootElement = editor.getRootElement();
|
|
165
|
-
|
|
166
153
|
if (rootElement !== null) {
|
|
167
154
|
rootElement.contentEditable = 'false';
|
|
168
155
|
playingIndexRef.current = totalEditorStates - 1;
|
|
@@ -181,7 +168,6 @@ function TreeView({
|
|
|
181
168
|
if (playingIndexRef.current === totalEditorStates - 1) {
|
|
182
169
|
playingIndexRef.current = 1;
|
|
183
170
|
}
|
|
184
|
-
|
|
185
171
|
setIsPlaying(!isPlaying);
|
|
186
172
|
},
|
|
187
173
|
type: "button"
|
|
@@ -191,7 +177,6 @@ function TreeView({
|
|
|
191
177
|
onChange: event => {
|
|
192
178
|
const editorStateIndex = Number(event.target.value);
|
|
193
179
|
const timeStampedEditorState = timeStampedEditorStates[editorStateIndex];
|
|
194
|
-
|
|
195
180
|
if (timeStampedEditorState) {
|
|
196
181
|
playingIndexRef.current = editorStateIndex;
|
|
197
182
|
editor.setEditorState(timeStampedEditorState[1]);
|
|
@@ -204,18 +189,15 @@ function TreeView({
|
|
|
204
189
|
className: timeTravelPanelButtonClassName,
|
|
205
190
|
onClick: () => {
|
|
206
191
|
const rootElement = editor.getRootElement();
|
|
207
|
-
|
|
208
192
|
if (rootElement !== null) {
|
|
209
193
|
rootElement.contentEditable = 'true';
|
|
210
194
|
const index = timeStampedEditorStates.length - 1;
|
|
211
195
|
const timeStampedEditorState = timeStampedEditorStates[index];
|
|
212
196
|
editor.setEditorState(timeStampedEditorState[1]);
|
|
213
197
|
const input = inputRef.current;
|
|
214
|
-
|
|
215
198
|
if (input !== null) {
|
|
216
199
|
input.value = String(index);
|
|
217
200
|
}
|
|
218
|
-
|
|
219
201
|
setTimeTravelEnabled(false);
|
|
220
202
|
setIsPlaying(false);
|
|
221
203
|
}
|
|
@@ -223,11 +205,10 @@ function TreeView({
|
|
|
223
205
|
type: "button"
|
|
224
206
|
}, "Exit")));
|
|
225
207
|
}
|
|
226
|
-
|
|
227
208
|
function printRangeSelection(selection) {
|
|
228
209
|
let res = '';
|
|
229
210
|
const formatText = printFormatProperties(selection);
|
|
230
|
-
res += `: range ${formatText !== '' ? `{ ${formatText} }` : ''}`;
|
|
211
|
+
res += `: range ${formatText !== '' ? `{ ${formatText} }` : ''} ${selection.style !== '' ? `{ style: ${selection.style} } ` : ''}`;
|
|
231
212
|
const anchor = selection.anchor;
|
|
232
213
|
const focus = selection.focus;
|
|
233
214
|
const anchorOffset = anchor.offset;
|
|
@@ -236,15 +217,12 @@ function printRangeSelection(selection) {
|
|
|
236
217
|
res += `\n └ focus { key: ${focus.key}, offset: ${focusOffset === null ? 'null' : focusOffset}, type: ${focus.type} }`;
|
|
237
218
|
return res;
|
|
238
219
|
}
|
|
239
|
-
|
|
240
220
|
function printObjectSelection(selection) {
|
|
241
221
|
return `: node\n └ [${Array.from(selection._nodes).join(', ')}]`;
|
|
242
222
|
}
|
|
243
|
-
|
|
244
223
|
function printGridSelection(selection) {
|
|
245
224
|
return `: grid\n └ { grid: ${selection.gridKey}, anchorCell: ${selection.anchor.key}, focusCell: ${selection.focus.key} }`;
|
|
246
225
|
}
|
|
247
|
-
|
|
248
226
|
function generateContent(editorState, editorConfig, compositionKey, editable) {
|
|
249
227
|
let res = ' root\n';
|
|
250
228
|
const selectionString = editorState.read(() => {
|
|
@@ -270,32 +248,27 @@ function generateContent(editorState, editorConfig, compositionKey, editable) {
|
|
|
270
248
|
res += '\n selection' + selectionString;
|
|
271
249
|
res += '\n\n editor:';
|
|
272
250
|
res += `\n └ namespace ${editorConfig.namespace}`;
|
|
273
|
-
|
|
274
251
|
if (compositionKey !== null) {
|
|
275
252
|
res += `\n └ compositionKey ${compositionKey}`;
|
|
276
253
|
}
|
|
277
|
-
|
|
278
254
|
res += `\n └ editable ${String(editable)}`;
|
|
279
255
|
return res;
|
|
280
256
|
}
|
|
281
|
-
|
|
282
257
|
function visitTree(currentNode, visitor, indent = []) {
|
|
283
258
|
const childNodes = currentNode.getChildren();
|
|
284
259
|
const childNodesLength = childNodes.length;
|
|
285
260
|
childNodes.forEach((childNode, i) => {
|
|
286
261
|
visitor(childNode, indent.concat(i === childNodesLength - 1 ? SYMBOLS.isLastChild : SYMBOLS.hasNextSibling));
|
|
287
|
-
|
|
288
262
|
if (lexical.$isElementNode(childNode)) {
|
|
289
263
|
visitTree(childNode, visitor, indent.concat(i === childNodesLength - 1 ? SYMBOLS.ancestorIsLastChild : SYMBOLS.ancestorHasNextSibling));
|
|
290
264
|
}
|
|
291
265
|
});
|
|
292
266
|
}
|
|
293
|
-
|
|
294
267
|
function normalize(text) {
|
|
295
268
|
return Object.entries(NON_SINGLE_WIDTH_CHARS_REPLACEMENT).reduce((acc, [key, value]) => acc.replace(new RegExp(key, 'g'), String(value)), text);
|
|
296
|
-
}
|
|
297
|
-
|
|
269
|
+
}
|
|
298
270
|
|
|
271
|
+
// TODO Pass via props to allow customizability
|
|
299
272
|
function printNode(node) {
|
|
300
273
|
if (lexical.$isTextNode(node)) {
|
|
301
274
|
const text = node.getTextContent();
|
|
@@ -311,69 +284,52 @@ function printNode(node) {
|
|
|
311
284
|
return '';
|
|
312
285
|
}
|
|
313
286
|
}
|
|
314
|
-
|
|
315
287
|
const FORMAT_PREDICATES = [node => node.hasFormat('bold') && 'Bold', node => node.hasFormat('code') && 'Code', node => node.hasFormat('italic') && 'Italic', node => node.hasFormat('strikethrough') && 'Strikethrough', node => node.hasFormat('subscript') && 'Subscript', node => node.hasFormat('superscript') && 'Superscript', node => node.hasFormat('underline') && 'Underline'];
|
|
316
288
|
const DETAIL_PREDICATES = [node => node.isDirectionless() && 'Directionless', node => node.isUnmergeable() && 'Unmergeable'];
|
|
317
289
|
const MODE_PREDICATES = [node => node.isToken() && 'Token', node => node.isSegmented() && 'Segmented'];
|
|
318
|
-
|
|
319
290
|
function printAllTextNodeProperties(node) {
|
|
320
291
|
return [printFormatProperties(node), printDetailProperties(node), printModeProperties(node)].filter(Boolean).join(', ');
|
|
321
292
|
}
|
|
322
|
-
|
|
323
293
|
function printAllLinkNodeProperties(node) {
|
|
324
294
|
return [printTargetProperties(node), printRelProperties(node)].filter(Boolean).join(', ');
|
|
325
295
|
}
|
|
326
|
-
|
|
327
296
|
function printDetailProperties(nodeOrSelection) {
|
|
328
297
|
let str = DETAIL_PREDICATES.map(predicate => predicate(nodeOrSelection)).filter(Boolean).join(', ').toLocaleLowerCase();
|
|
329
|
-
|
|
330
298
|
if (str !== '') {
|
|
331
299
|
str = 'detail: ' + str;
|
|
332
300
|
}
|
|
333
|
-
|
|
334
301
|
return str;
|
|
335
302
|
}
|
|
336
|
-
|
|
337
303
|
function printModeProperties(nodeOrSelection) {
|
|
338
304
|
let str = MODE_PREDICATES.map(predicate => predicate(nodeOrSelection)).filter(Boolean).join(', ').toLocaleLowerCase();
|
|
339
|
-
|
|
340
305
|
if (str !== '') {
|
|
341
306
|
str = 'mode: ' + str;
|
|
342
307
|
}
|
|
343
|
-
|
|
344
308
|
return str;
|
|
345
309
|
}
|
|
346
|
-
|
|
347
310
|
function printFormatProperties(nodeOrSelection) {
|
|
348
311
|
let str = FORMAT_PREDICATES.map(predicate => predicate(nodeOrSelection)).filter(Boolean).join(', ').toLocaleLowerCase();
|
|
349
|
-
|
|
350
312
|
if (str !== '') {
|
|
351
313
|
str = 'format: ' + str;
|
|
352
314
|
}
|
|
353
|
-
|
|
354
315
|
return str;
|
|
355
316
|
}
|
|
356
|
-
|
|
357
317
|
function printTargetProperties(node) {
|
|
358
|
-
let str = node.getTarget();
|
|
359
|
-
|
|
318
|
+
let str = node.getTarget();
|
|
319
|
+
// TODO Fix nullish on LinkNode
|
|
360
320
|
if (str != null) {
|
|
361
321
|
str = 'target: ' + str;
|
|
362
322
|
}
|
|
363
|
-
|
|
364
323
|
return str;
|
|
365
324
|
}
|
|
366
|
-
|
|
367
325
|
function printRelProperties(node) {
|
|
368
|
-
let str = node.getRel();
|
|
369
|
-
|
|
326
|
+
let str = node.getRel();
|
|
327
|
+
// TODO Fix nullish on LinkNode
|
|
370
328
|
if (str != null) {
|
|
371
329
|
str = 'rel: ' + str;
|
|
372
330
|
}
|
|
373
|
-
|
|
374
331
|
return str;
|
|
375
332
|
}
|
|
376
|
-
|
|
377
333
|
function printSelectedCharsLine({
|
|
378
334
|
indent,
|
|
379
335
|
isSelected,
|
|
@@ -385,22 +341,18 @@ function printSelectedCharsLine({
|
|
|
385
341
|
// No selection or node is not selected.
|
|
386
342
|
if (!lexical.$isTextNode(node) || !lexical.$isRangeSelection(selection) || !isSelected || lexical.$isElementNode(node)) {
|
|
387
343
|
return '';
|
|
388
|
-
}
|
|
389
|
-
|
|
344
|
+
}
|
|
390
345
|
|
|
346
|
+
// No selected characters.
|
|
391
347
|
const anchor = selection.anchor;
|
|
392
348
|
const focus = selection.focus;
|
|
393
|
-
|
|
394
349
|
if (node.getTextContent() === '' || anchor.getNode() === selection.focus.getNode() && anchor.offset === focus.offset) {
|
|
395
350
|
return '';
|
|
396
351
|
}
|
|
397
|
-
|
|
398
352
|
const [start, end] = $getSelectionStartEnd(node, selection);
|
|
399
|
-
|
|
400
353
|
if (start === end) {
|
|
401
354
|
return '';
|
|
402
355
|
}
|
|
403
|
-
|
|
404
356
|
const selectionLastIndent = indent[indent.length - 1] === SYMBOLS.hasNextSibling ? SYMBOLS.ancestorHasNextSibling : SYMBOLS.ancestorIsLastChild;
|
|
405
357
|
const indentionChars = [...indent.slice(0, indent.length - 1), selectionLastIndent];
|
|
406
358
|
const unselectedChars = Array(start + 1).fill(' ');
|
|
@@ -410,19 +362,18 @@ function printSelectedCharsLine({
|
|
|
410
362
|
const nodePrintSpaces = Array(nodeKeyDisplay.length + paddingLength).fill(' ');
|
|
411
363
|
return [SYMBOLS.selectedLine, indentionChars.join(' '), [...nodePrintSpaces, ...unselectedChars, ...selectedChars].join('')].join(' ') + '\n';
|
|
412
364
|
}
|
|
413
|
-
|
|
414
365
|
function $getSelectionStartEnd(node, selection) {
|
|
415
366
|
const anchor = selection.anchor;
|
|
416
367
|
const focus = selection.focus;
|
|
417
368
|
const textContent = node.getTextContent();
|
|
418
369
|
const textLength = textContent.length;
|
|
419
370
|
let start = -1;
|
|
420
|
-
let end = -1;
|
|
371
|
+
let end = -1;
|
|
421
372
|
|
|
373
|
+
// Only one node is being selected.
|
|
422
374
|
if (anchor.type === 'text' && focus.type === 'text') {
|
|
423
375
|
const anchorNode = anchor.getNode();
|
|
424
376
|
const focusNode = focus.getNode();
|
|
425
|
-
|
|
426
377
|
if (anchorNode === focusNode && node === anchorNode && anchor.offset !== focus.offset) {
|
|
427
378
|
[start, end] = anchor.offset < focus.offset ? [anchor.offset, focus.offset] : [focus.offset, anchor.offset];
|
|
428
379
|
} else if (node === anchorNode) {
|
|
@@ -433,9 +384,9 @@ function $getSelectionStartEnd(node, selection) {
|
|
|
433
384
|
// Node is within selection but not the anchor nor focus.
|
|
434
385
|
[start, end] = [0, textLength];
|
|
435
386
|
}
|
|
436
|
-
}
|
|
437
|
-
|
|
387
|
+
}
|
|
438
388
|
|
|
389
|
+
// Account for non-single width characters.
|
|
439
390
|
const numNonSingleWidthCharBeforeSelection = (textContent.slice(0, start).match(NON_SINGLE_WIDTH_CHARS_REGEX) || []).length;
|
|
440
391
|
const numNonSingleWidthCharInSelection = (textContent.slice(start, end).match(NON_SINGLE_WIDTH_CHARS_REGEX) || []).length;
|
|
441
392
|
return [start + numNonSingleWidthCharBeforeSelection, end + numNonSingleWidthCharBeforeSelection + numNonSingleWidthCharInSelection];
|
package/LexicalTreeView.prod.js
CHANGED
|
@@ -5,18 +5,18 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict';var h=require("@lexical/link"),r=require("@lexical/mark"),v=require("@lexical/utils"),F=require("lexical"),I=require("react");let J=Object.freeze({"\t":"\\t","\n":"\\n"}),K=new RegExp(Object.keys(J).join("|"),"g"),L=Object.freeze({ancestorHasNextSibling:"|",ancestorIsLastChild:" ",hasNextSibling:"\u251c",isLastChild:"\u2514",selectedChar:"^",selectedLine:">"});
|
|
8
|
-
function M(a){let c=""
|
|
9
|
-
function Q(a,c,
|
|
10
|
-
k=0===k.length?"(empty)":`"${S(k)}"`;p=
|
|
11
|
-
`: node\n \u2514 [${Array.from(b._nodes).join(", ")}]`});f+="\n selection"+a;f+="\n\n editor:";f+=`\n \u2514 namespace ${c.namespace}`;null!==
|
|
12
|
-
function S(a){return Object.entries(J).reduce((c,[
|
|
8
|
+
function M(a){let c="";var d=P(a);c+=`: range ${""!==d?`{ ${d} }`:""} ${""!==a.style?`{ style: ${a.style} } `:""}`;d=a.anchor;a=a.focus;let l=d.offset,f=a.offset;c+=`\n \u251c anchor { key: ${d.key}, offset: ${null===l?"null":l}, type: ${d.type} }`;return c+=`\n \u2514 focus { key: ${a.key}, offset: ${null===f?"null":f}, type: ${a.type} }`}
|
|
9
|
+
function Q(a,c,d,l){let f=" root\n";a=a.read(()=>{const b=F.$getSelection();R(F.$getRoot(),(e,n)=>{const y=`(${e.getKey()})`,t=e.getType()||"",q=e.isSelected(),z=r.$isMarkNode(e)?` id: [ ${e.getIDs().join(", ")} ] `:"";var m=f,w=q?L.selectedLine:" ",D=n.join(" ");if(F.$isTextNode(e)){var k=e.getTextContent();var p=0===k.length?"(empty)":`"${S(k)}"`;k=[P(e),T(e),U(e)].filter(Boolean).join(", ");k=[p,0!==k.length?`{ ${k} }`:null].filter(Boolean).join(" ").trim()}else if(h.$isLinkNode(e)){k=e.getURL();
|
|
10
|
+
k=0===k.length?"(empty)":`"${S(k)}"`;p=e.getTarget();null!=p&&(p="target: "+p);var A=Boolean;let B=e.getRel();null!=B&&(B="rel: "+B);p=[p,B].filter(A).join(", ");k=[k,0!==p.length?`{ ${p} }`:null].filter(Boolean).join(" ").trim()}else k="";f=m+`${w} ${D} ${y} ${t} ${z} ${k}\n`;f+=V({indent:n,isSelected:q,node:e,nodeKeyDisplay:y,selection:b,typeDisplay:t})});return null===b?": null":F.$isRangeSelection(b)?M(b):F.DEPRECATED_$isGridSelection(b)?`: grid\n \u2514 { grid: ${b.gridKey}, anchorCell: ${b.anchor.key}, focusCell: ${b.focus.key} }`:
|
|
11
|
+
`: node\n \u2514 [${Array.from(b._nodes).join(", ")}]`});f+="\n selection"+a;f+="\n\n editor:";f+=`\n \u2514 namespace ${c.namespace}`;null!==d&&(f+=`\n \u2514 compositionKey ${d}`);return f+=`\n \u2514 editable ${String(l)}`}function R(a,c,d=[]){a=a.getChildren();let l=a.length;a.forEach((f,b)=>{c(f,d.concat(b===l-1?L.isLastChild:L.hasNextSibling));F.$isElementNode(f)&&R(f,c,d.concat(b===l-1?L.ancestorIsLastChild:L.ancestorHasNextSibling))})}
|
|
12
|
+
function S(a){return Object.entries(J).reduce((c,[d,l])=>c.replace(new RegExp(d,"g"),String(l)),a)}
|
|
13
13
|
let W=[a=>a.hasFormat("bold")&&"Bold",a=>a.hasFormat("code")&&"Code",a=>a.hasFormat("italic")&&"Italic",a=>a.hasFormat("strikethrough")&&"Strikethrough",a=>a.hasFormat("subscript")&&"Subscript",a=>a.hasFormat("superscript")&&"Superscript",a=>a.hasFormat("underline")&&"Underline"],X=[a=>a.isDirectionless()&&"Directionless",a=>a.isUnmergeable()&&"Unmergeable"],Y=[a=>a.isToken()&&"Token",a=>a.isSegmented()&&"Segmented"];
|
|
14
|
-
function T(a){let c=X.map(
|
|
15
|
-
function V({indent:a,isSelected:c,node:
|
|
16
|
-
|
|
14
|
+
function T(a){let c=X.map(d=>d(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==c&&(c="detail: "+c);return c}function U(a){let c=Y.map(d=>d(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==c&&(c="mode: "+c);return c}function P(a){let c=W.map(d=>d(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==c&&(c="format: "+c);return c}
|
|
15
|
+
function V({indent:a,isSelected:c,node:d,nodeKeyDisplay:l,selection:f,typeDisplay:b}){if(!F.$isTextNode(d)||!F.$isRangeSelection(f)||!c||F.$isElementNode(d))return"";c=f.anchor;var e=f.focus;if(""===d.getTextContent()||c.getNode()===f.focus.getNode()&&c.offset===e.offset)return"";e=f.anchor;let n=f.focus,y=d.getTextContent(),t=y.length;c=f=-1;if("text"===e.type&&"text"===n.type){let m=e.getNode(),w=n.getNode();m===w&&d===m&&e.offset!==n.offset?[f,c]=e.offset<n.offset?[e.offset,n.offset]:[n.offset,
|
|
16
|
+
e.offset]:d===m?[f,c]=m.isBefore(w)?[e.offset,t]:[0,e.offset]:d===w?[f,c]=w.isBefore(m)?[n.offset,t]:[0,n.offset]:[f,c]=[0,t]}d=(y.slice(0,f).match(K)||[]).length;e=(y.slice(f,c).match(K)||[]).length;let [q,z]=[f+d,c+d+e];if(q===z)return"";d=a[a.length-1]===L.hasNextSibling?L.ancestorHasNextSibling:L.ancestorIsLastChild;a=[...a.slice(0,a.length-1),d];d=Array(q+1).fill(" ");f=Array(z-q).fill(L.selectedChar);l=Array(l.length+(b.length+3)).fill(" ");return[L.selectedLine,a.join(" "),[...l,...d,...f].join("")].join(" ")+
|
|
17
17
|
"\n"}
|
|
18
|
-
exports.TreeView=function({timeTravelButtonClassName:a,timeTravelPanelSliderClassName:c,timeTravelPanelButtonClassName:
|
|
19
|
-
I.useEffect(()=>{let g=b.getEditorState();!x&&1E3<g._nodeMap.size&&t(Q(g,b._config,b._compositionKey,b._editable))},[b,x]);I.useEffect(()=>v.mergeRegister(b.registerUpdateListener(({editorState:g})=>{if(!x&&1E3<g._nodeMap.size&&(G.current=g,B(!0),!x))return;H(g)}),b.registerEditableListener(()=>{let g=Q(b.getEditorState(),b._config,b._compositionKey,b._editable);t(g)})),[b,A,H,x]);let C=
|
|
20
|
-
m.current,O=D.current;null!==O&&(O.value=String(N));b.setEditorState(
|
|
21
|
-
{Z(!0);let g=G.current;null!==g&&(G.current=null,H(g))},style:{background:"transparent",border:"1px solid white",color:"white",cursor:"pointer",padding:5}},"Show full tree")):null,!q&&(x||!A)&&2<C&&I.createElement("button",{onClick:()=>{let g=b.getRootElement();null!==g&&(g.contentEditable="false",m.current=C-1,z(!0))},className:a,type:"button"},"Time Travel"),(x||!A)&&I.createElement("pre",{ref:w},y),q&&(x||!A)&&I.createElement("div",{className:f},I.createElement("button",{className:
|
|
22
|
-
{m.current===C-1&&(m.current=1);p(!k)},type:"button"},k?"Pause":"Play"),I.createElement("input",{className:c,ref:D,onChange:g=>{g=Number(g.target.value);let u=
|
|
18
|
+
exports.TreeView=function({timeTravelButtonClassName:a,timeTravelPanelSliderClassName:c,timeTravelPanelButtonClassName:d,viewClassName:l,timeTravelPanelClassName:f,editor:b}){let [e,n]=I.useState([]),[y,t]=I.useState(""),[q,z]=I.useState(!1),m=I.useRef(0),w=I.useRef(null),D=I.useRef(null),[k,p]=I.useState(!1),[A,B]=I.useState(!1),[x,Z]=I.useState(!1),G=I.useRef(null),H=I.useCallback(g=>{const u=Q(b.getEditorState(),b._config,b._compositionKey,b._editable);t(u);q||n(E=>[...E,[Date.now(),g]])},[b,q]);
|
|
19
|
+
I.useEffect(()=>{let g=b.getEditorState();!x&&1E3<g._nodeMap.size&&t(Q(g,b._config,b._compositionKey,b._editable))},[b,x]);I.useEffect(()=>v.mergeRegister(b.registerUpdateListener(({editorState:g})=>{if(!x&&1E3<g._nodeMap.size&&(G.current=g,B(!0),!x))return;H(g)}),b.registerEditableListener(()=>{let g=Q(b.getEditorState(),b._config,b._compositionKey,b._editable);t(g)})),[b,A,H,x]);let C=e.length;I.useEffect(()=>{if(k){let g,u=()=>{const E=m.current;E===C-1?p(!1):g=setTimeout(()=>{m.current++;const N=
|
|
20
|
+
m.current,O=D.current;null!==O&&(O.value=String(N));b.setEditorState(e[N][1]);u()},e[E+1][0]-e[E][0])};u();return()=>{clearTimeout(g)}}},[e,k,b,C]);I.useEffect(()=>{let g=w.current;if(null!==g)return g.__lexicalEditor=b,()=>{g.__lexicalEditor=null}},[b]);return I.createElement("div",{className:l},!x&&A?I.createElement("div",{style:{padding:20}},I.createElement("span",{style:{marginRight:20}},"Detected large EditorState, this can impact debugging performance."),I.createElement("button",{onClick:()=>
|
|
21
|
+
{Z(!0);let g=G.current;null!==g&&(G.current=null,H(g))},style:{background:"transparent",border:"1px solid white",color:"white",cursor:"pointer",padding:5}},"Show full tree")):null,!q&&(x||!A)&&2<C&&I.createElement("button",{onClick:()=>{let g=b.getRootElement();null!==g&&(g.contentEditable="false",m.current=C-1,z(!0))},className:a,type:"button"},"Time Travel"),(x||!A)&&I.createElement("pre",{ref:w},y),q&&(x||!A)&&I.createElement("div",{className:f},I.createElement("button",{className:d,onClick:()=>
|
|
22
|
+
{m.current===C-1&&(m.current=1);p(!k)},type:"button"},k?"Pause":"Play"),I.createElement("input",{className:c,ref:D,onChange:g=>{g=Number(g.target.value);let u=e[g];u&&(m.current=g,b.setEditorState(u[1]))},type:"range",min:"1",max:C-1}),I.createElement("button",{className:d,onClick:()=>{var g=b.getRootElement();if(null!==g){g.contentEditable="true";g=e.length-1;b.setEditorState(e[g][1]);let u=D.current;null!==u&&(u.value=String(g));z(!1);p(!1)}},type:"button"},"Exit")))}
|