@lexical/react 0.7.8 → 0.7.9

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 (40) hide show
  1. package/DEPRECATED_useLexical.dev.js +3 -4
  2. package/DEPRECATED_useLexicalCanShowPlaceholder.dev.js +1 -3
  3. package/DEPRECATED_useLexicalCharacterLimit.dev.js +7 -39
  4. package/DEPRECATED_useLexicalEditor.dev.js +1 -3
  5. package/DEPRECATED_useLexicalPlainText.dev.js +4 -1
  6. package/DEPRECATED_useLexicalRichText.dev.js +4 -1
  7. package/LexicalAutoEmbedPlugin.dev.js +0 -11
  8. package/LexicalAutoFocusPlugin.dev.js +0 -1
  9. package/LexicalAutoLinkPlugin.dev.js +7 -50
  10. package/LexicalBlockWithAlignableContents.dev.js +0 -11
  11. package/LexicalCharacterLimitPlugin.dev.js +7 -46
  12. package/LexicalCheckListPlugin.dev.js +10 -48
  13. package/LexicalClearEditorPlugin.dev.js +1 -1
  14. package/LexicalCollaborationContext.dev.js +0 -3
  15. package/LexicalCollaborationPlugin.dev.js +6 -34
  16. package/LexicalComposer.dev.js +6 -10
  17. package/LexicalComposerContext.dev.js +0 -6
  18. package/LexicalContentEditable.dev.js +3 -1
  19. package/LexicalDecoratorBlockNode.dev.js +0 -5
  20. package/LexicalHashtagPlugin.dev.js +73 -43
  21. package/LexicalHorizontalRuleNode.dev.js +0 -22
  22. package/LexicalHorizontalRulePlugin.dev.js +0 -4
  23. package/LexicalLinkPlugin.dev.js +4 -10
  24. package/LexicalListPlugin.dev.js +0 -2
  25. package/LexicalMarkdownShortcutPlugin.dev.js +2 -2
  26. package/LexicalNestedComposer.dev.js +6 -11
  27. package/LexicalNodeEventPlugin.dev.js +5 -3
  28. package/LexicalOnChangePlugin.dev.js +1 -1
  29. package/LexicalPlainTextPlugin.dev.js +8 -12
  30. package/LexicalRichTextPlugin.dev.js +8 -12
  31. package/LexicalTabIndentationPlugin.dev.js +1 -3
  32. package/LexicalTableOfContents__EXPERIMENTAL.dev.js +5 -33
  33. package/LexicalTablePlugin.dev.js +5 -19
  34. package/LexicalTreeView.dev.js +12 -61
  35. package/LexicalTypeaheadMenuPlugin.dev.js +7 -96
  36. package/package.json +19 -19
  37. package/useLexicalEditable.dev.js +1 -5
  38. package/useLexicalIsTextContentEmpty.dev.js +1 -0
  39. package/useLexicalNodeSelection.dev.js +0 -7
  40. package/useLexicalSubscription.dev.js +1 -3
@@ -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,7 +205,6 @@ 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);
@@ -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
- } // TODO Pass via props to allow customizability
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(); // TODO Fix nullish on LinkNode
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(); // TODO Fix nullish on LinkNode
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
- } // No selected characters.
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; // Only one node is being selected.
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
- } // Account for non-single width characters.
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];