@lexical/react 0.1.8 → 0.1.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 (53) hide show
  1. package/DEPRECATED_useLexical.prod.js +1 -1
  2. package/DEPRECATED_useLexicalAutoFormatter.dev.js +142 -55
  3. package/DEPRECATED_useLexicalAutoFormatter.prod.js +19 -16
  4. package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +1 -1
  5. package/DEPRECATED_useLexicalCharacterLimit.dev.js +1 -2
  6. package/DEPRECATED_useLexicalCharacterLimit.prod.js +3 -3
  7. package/DEPRECATED_useLexicalDecorators.prod.js +1 -1
  8. package/DEPRECATED_useLexicalEditor.prod.js +1 -1
  9. package/DEPRECATED_useLexicalEditorEvents.prod.js +1 -1
  10. package/DEPRECATED_useLexicalHistory.dev.js +17 -14
  11. package/DEPRECATED_useLexicalHistory.prod.js +7 -7
  12. package/DEPRECATED_useLexicalList.prod.js +1 -1
  13. package/DEPRECATED_useLexicalPlainText.dev.js +46 -23
  14. package/DEPRECATED_useLexicalPlainText.prod.js +16 -16
  15. package/DEPRECATED_useLexicalRichText.dev.js +47 -24
  16. package/DEPRECATED_useLexicalRichText.prod.js +27 -27
  17. package/LexicalAutoFormatterPlugin.dev.js +142 -55
  18. package/LexicalAutoFormatterPlugin.prod.js +19 -17
  19. package/LexicalAutoLinkPlugin.prod.js +4 -4
  20. package/LexicalBootstrapPlugin.dev.js +0 -2
  21. package/LexicalBootstrapPlugin.prod.js +2 -2
  22. package/LexicalCharacterLimitPlugin.dev.js +1 -2
  23. package/LexicalCharacterLimitPlugin.prod.js +3 -3
  24. package/LexicalCollaborationPlugin.dev.js +11 -26
  25. package/LexicalCollaborationPlugin.prod.js +7 -8
  26. package/LexicalComposer.prod.js +1 -1
  27. package/LexicalComposerContext.prod.js +1 -1
  28. package/LexicalContentEditable.prod.js +1 -1
  29. package/LexicalHashtagPlugin.prod.js +1 -1
  30. package/LexicalHistoryPlugin.dev.js +17 -14
  31. package/LexicalHistoryPlugin.prod.js +6 -6
  32. package/LexicalHorizontalRuleNode.dev.js +66 -0
  33. package/LexicalHorizontalRuleNode.js +9 -0
  34. package/LexicalHorizontalRuleNode.prod.js +8 -0
  35. package/LexicalLinkPlugin.dev.js +0 -1
  36. package/LexicalLinkPlugin.prod.js +3 -3
  37. package/LexicalListPlugin.prod.js +1 -1
  38. package/LexicalNestedComposer.prod.js +1 -1
  39. package/LexicalOnChangePlugin.prod.js +1 -1
  40. package/LexicalPlainTextPlugin.dev.js +29 -9
  41. package/LexicalPlainTextPlugin.prod.js +12 -11
  42. package/LexicalRichTextPlugin.dev.js +30 -10
  43. package/LexicalRichTextPlugin.prod.js +16 -16
  44. package/LexicalTablePlugin.dev.js +20 -38
  45. package/LexicalTablePlugin.prod.js +3 -3
  46. package/LexicalTreeView.prod.js +1 -1
  47. package/package.json +5 -4
  48. package/useLexicalDecoratorMap.prod.js +1 -1
  49. package/useLexicalIsTextContentEmpty.prod.js +1 -1
  50. package/withSubscriptions.prod.js +1 -1
  51. package/LexicalHorizontalRulePlugin.dev.js +0 -51
  52. package/LexicalHorizontalRulePlugin.js +0 -9
  53. package/LexicalHorizontalRulePlugin.prod.js +0 -7
@@ -4,5 +4,5 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- 'use strict';var b=require("lexical"),g=require("react"),h=require("@lexical/react/DEPRECATED_useLexicalCanShowPlaceholder"),k="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?g.useLayoutEffect:g.useEffect;function l(a,c){const d=h(a),f=g.useCallback(e=>{a.setRootElement(e)},[a]);k(()=>a.addListener("error",c),[a,c]);return[f,d]}function m(a){throw a;}
7
+ var b=require("lexical"),g=require("react"),h=require("@lexical/react/DEPRECATED_useLexicalCanShowPlaceholder"),k="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?g.useLayoutEffect:g.useEffect;function l(a,c){const d=h(a),f=g.useCallback(e=>{a.setRootElement(e)},[a]);k(()=>a.addListener("error",c),[a,c]);return[f,d]}function m(a){throw a;}
8
8
  module.exports=function(a){const c=void 0!==a&&a.onError||m,d=g.useMemo(()=>{if(void 0!==a){const {onError:p,...n}=a;return b.createEditor(n)}return b.createEditor(a)},[a]),[f,e]=l(d,c);return[d,f,e]};
@@ -10,6 +10,7 @@ var list = require('@lexical/list');
10
10
  var lexical = require('lexical');
11
11
  var CodeNode = require('lexical/CodeNode');
12
12
  var react = require('react');
13
+ var LexicalHorizontalRuleNode = require('@lexical/react/LexicalHorizontalRuleNode');
13
14
  var HeadingNode = require('lexical/HeadingNode');
14
15
  var QuoteNode = require('lexical/QuoteNode');
15
16
 
@@ -72,17 +73,26 @@ function $findNodeWithOffsetFromJoinedText(elementNode, joinedTextLength, offset
72
73
  const children = elementNode.getChildren();
73
74
  const childrenLength = children.length;
74
75
  let runningLength = 0;
76
+ let isPriorNodeTextNode = false;
75
77
 
76
78
  for (let i = 0; i < childrenLength; ++i) {
77
- if (runningLength >= joinedTextLength) {
79
+ // We must examine the offsetInJoinedText that is located
80
+ // at the length of the string.
81
+ // For example, given "hello", the length is 5, yet
82
+ // the caller still wants the node + offset at the
83
+ // right edge of the "o".
84
+ if (runningLength > joinedTextLength) {
78
85
  break;
79
86
  }
80
87
 
81
88
  const child = children[i];
82
- const childContentLength = lexical.$isTextNode(child) ? child.getTextContent().length : separatorLength;
89
+ const isChildNodeTestNode = lexical.$isTextNode(child);
90
+ const childContentLength = isChildNodeTestNode ? child.getTextContent().length : separatorLength;
83
91
  const newRunningLength = runningLength + childContentLength;
92
+ const isJoinedOffsetWithinNode = isPriorNodeTextNode === false && runningLength === offsetInJoinedText || runningLength === 0 && runningLength === offsetInJoinedText || runningLength < offsetInJoinedText && offsetInJoinedText <= newRunningLength;
84
93
 
85
- if (runningLength <= offsetInJoinedText && offsetInJoinedText < newRunningLength && lexical.$isTextNode(child)) {
94
+ if (isJoinedOffsetWithinNode && lexical.$isTextNode(child)) {
95
+ // Check isTextNode again for flow.
86
96
  return {
87
97
  node: child,
88
98
  offset: offsetInJoinedText - runningLength
@@ -90,6 +100,7 @@ function $findNodeWithOffsetFromJoinedText(elementNode, joinedTextLength, offset
90
100
  }
91
101
 
92
102
  runningLength = newRunningLength;
103
+ isPriorNodeTextNode = isChildNodeTestNode;
93
104
  }
94
105
 
95
106
  return null;
@@ -114,8 +125,6 @@ const SEPARATOR_BETWEEN_TEXT_AND_NON_TEXT_NODES = '\u0004'; // Select an unused
114
125
  const autoFormatBase = {
115
126
  nodeTransformationKind: null,
116
127
  regEx: /(?:)/,
117
- regExCaptureGroupsToDelete: null,
118
- regExExpectedCaptureGroupCount: 1,
119
128
  requiresParagraphStart: false
120
129
  };
121
130
  const paragraphStartBase = { ...autoFormatBase,
@@ -151,38 +160,58 @@ const markdownCodeBlock = { ...paragraphStartBase,
151
160
  };
152
161
  const markdownOrderedList = { ...paragraphStartBase,
153
162
  nodeTransformationKind: 'paragraphOrderedList',
154
- regEx: /^(\d+)\.\s/,
155
- regExExpectedCaptureGroupCount: 2
156
- /*e.g. '321. ' returns '321. ' & '321'*/
157
-
163
+ regEx: /^(\d+)\.\s/
164
+ };
165
+ const markdownHorizontalRule = { ...paragraphStartBase,
166
+ nodeTransformationKind: 'horizontalRule',
167
+ regEx: /(?:\*\*\* )/
168
+ };
169
+ const markdownHorizontalRuleUsingDashes = { ...paragraphStartBase,
170
+ nodeTransformationKind: 'horizontalRule',
171
+ regEx: /(?:--- )/
158
172
  };
159
173
  const markdownBold = { ...autoFormatBase,
160
174
  nodeTransformationKind: 'textBold',
161
175
  // regEx: /(\*)(?:\s*\b)(?:[^\*]*)(?:\b\s*)(\*\s)$/, // The $ will find the target at the end of the string.
162
- regEx: /(\*)(\s*\b)([^\*]*)(\b\s*)(\*\s)$/,
163
- // Remove the first and last capture groups. Remeber, the 0th capture group is the entire string.
176
+ regEx: /(\*)(\s*\b)([^\*]*)(\b\s*)(\*\s)$/ // Remove the first and last capture groups. Remeber, the 0th capture group is the entire string.
164
177
  // e.g. "*Hello* " requires removing both "*" as well as bolding "Hello".
165
- regExCaptureGroupsToDelete: [1, 5],
166
- // The $ will find the target at the end of the string.
167
- regExExpectedCaptureGroupCount: 6
178
+
168
179
  };
169
180
  const allAutoFormatCriteriaForTextNodes = [markdownBold];
170
- const allAutoFormatCriteria = [markdownHeader1, markdownHeader2, markdownHeader3, markdownBlockQuote, markdownUnorderedListDash, markdownUnorderedListAsterisk, markdownOrderedList, markdownCodeBlock, ...allAutoFormatCriteriaForTextNodes];
181
+ const allAutoFormatCriteria = [markdownHeader1, markdownHeader2, markdownHeader3, markdownBlockQuote, markdownUnorderedListDash, markdownUnorderedListAsterisk, markdownOrderedList, markdownCodeBlock, markdownHorizontalRule, markdownHorizontalRuleUsingDashes, ...allAutoFormatCriteriaForTextNodes];
171
182
  function getAllAutoFormatCriteriaForTextNodes() {
172
183
  return allAutoFormatCriteriaForTextNodes;
173
184
  }
174
185
  function getAllAutoFormatCriteria() {
175
186
  return allAutoFormatCriteria;
176
187
  }
188
+ function getInitialScanningContext(textNodeWithOffset, triggerState) {
189
+ return {
190
+ autoFormatCriteria: {
191
+ nodeTransformationKind: 'noTransformation',
192
+ regEx: /(?:)/,
193
+ // Empty reg ex will do until the precise criteria is discovered.
194
+ requiresParagraphStart: null
195
+ },
196
+ joinedText: null,
197
+ matchResultContext: {
198
+ offsetInJoinedTextForCollapsedSelection: 0,
199
+ regExCaptureGroups: []
200
+ },
201
+ textNodeWithOffset,
202
+ triggerState
203
+ };
204
+ }
177
205
 
178
- function getMatchResultContextWithRegEx(textToSearch, matchMustAppearAtStartOfString, matchMustAppearAtEndOfString, regEx, regExExpectedCaptureGroupCount, scanningContext) {
206
+ function getMatchResultContextWithRegEx(textToSearch, matchMustAppearAtStartOfString, matchMustAppearAtEndOfString, regEx) {
179
207
  const matchResultContext = {
180
- regExCaptureGroups: [],
181
- triggerState: null
208
+ offsetInJoinedTextForCollapsedSelection: 0,
209
+ regExCaptureGroups: []
182
210
  };
183
211
  const regExMatches = textToSearch.match(regEx);
184
212
 
185
- if (regExMatches !== null && regExMatches.length > 0 && regExMatches.length === regExExpectedCaptureGroupCount && (matchMustAppearAtStartOfString === false || regExMatches.index === 0) && (matchMustAppearAtEndOfString === false || regExMatches.index + regExMatches[0].length === textToSearch.length)) {
213
+ if (regExMatches !== null && regExMatches.length > 0 && (matchMustAppearAtStartOfString === false || regExMatches.index === 0) && (matchMustAppearAtEndOfString === false || regExMatches.index + regExMatches[0].length === textToSearch.length)) {
214
+ matchResultContext.offsetInJoinedTextForCollapsedSelection = textToSearch.length;
186
215
  const captureGroupsCount = regExMatches.length;
187
216
  let runningLength = regExMatches.index;
188
217
 
@@ -214,7 +243,7 @@ function getMatchResultContextForParagraphs(autoFormatCriteria, scanningContext)
214
243
 
215
244
  if (textNodeWithOffset.node.getPreviousSibling() === null) {
216
245
  const textToSearch = scanningContext.textNodeWithOffset.node.getTextContent();
217
- return getMatchResultContextWithRegEx(textToSearch, true, false, autoFormatCriteria.regEx, autoFormatCriteria.regExExpectedCaptureGroupCount);
246
+ return getMatchResultContextWithRegEx(textToSearch, true, false, autoFormatCriteria.regEx);
218
247
  }
219
248
 
220
249
  return null;
@@ -230,7 +259,7 @@ function getMatchResultContextForText(autoFormatCriteria, scanningContext) {
230
259
  scanningContext.joinedText = $joinTextNodesInElementNode(parentNode, SEPARATOR_BETWEEN_TEXT_AND_NON_TEXT_NODES, scanningContext.textNodeWithOffset);
231
260
  }
232
261
 
233
- return getMatchResultContextWithRegEx(scanningContext.joinedText, false, true, autoFormatCriteria.regEx, autoFormatCriteria.regExExpectedCaptureGroupCount);
262
+ return getMatchResultContextWithRegEx(scanningContext.joinedText, false, true, autoFormatCriteria.regEx);
234
263
  } else {
235
264
  {
236
265
  throw Error(`Expected node ${parentNode.__key} to to be a ElementNode.`);
@@ -250,8 +279,11 @@ function getMatchResultContextForCriteria(autoFormatCriteria, scanningContext) {
250
279
  return getMatchResultContextForText(autoFormatCriteria, scanningContext);
251
280
  }
252
281
 
253
- function getNewNodeForCriteria(autoFormatCriteria, matchResultContext, children) {
282
+ function getNewNodeForCriteria(scanningContext, element) {
254
283
  let newNode = null;
284
+ const children = element.getChildren();
285
+ const autoFormatCriteria = scanningContext.autoFormatCriteria;
286
+ const matchResultContext = scanningContext.matchResultContext;
255
287
 
256
288
  if (autoFormatCriteria.nodeTransformationKind != null) {
257
289
  switch (autoFormatCriteria.nodeTransformationKind) {
@@ -306,7 +338,7 @@ function getNewNodeForCriteria(autoFormatCriteria, matchResultContext, children)
306
338
  case 'paragraphCodeBlock':
307
339
  {
308
340
  // Toggle code and paragraph nodes.
309
- if (matchResultContext.triggerState != null && matchResultContext.triggerState.isCodeBlock) {
341
+ if (scanningContext.triggerState != null && scanningContext.triggerState.isCodeBlock) {
310
342
  newNode = lexical.$createParagraphNode();
311
343
  } else {
312
344
  newNode = CodeNode.$createCodeNode();
@@ -315,6 +347,14 @@ function getNewNodeForCriteria(autoFormatCriteria, matchResultContext, children)
315
347
  newNode.append(...children);
316
348
  return newNode;
317
349
  }
350
+
351
+ case 'horizontalRule':
352
+ {
353
+ // return null for newNode. Insert the HR here.
354
+ const horizontalRuleNode = LexicalHorizontalRuleNode.$createHorizontalRuleNode();
355
+ element.insertBefore(horizontalRuleNode);
356
+ break;
357
+ }
318
358
  }
319
359
  }
320
360
 
@@ -330,39 +370,46 @@ function updateTextNode(node, count) {
330
370
  }
331
371
  }
332
372
 
333
- function transformTextNodeForAutoFormatCriteria(scanningContext, autoFormatCriteria, matchResultContext) {
334
- if (autoFormatCriteria.requiresParagraphStart) {
335
- transformTextNodeForParagraphs(scanningContext, autoFormatCriteria, matchResultContext);
373
+ function transformTextNodeForAutoFormatCriteria(scanningContext) {
374
+ if (scanningContext.autoFormatCriteria.requiresParagraphStart) {
375
+ transformTextNodeForParagraphs(scanningContext);
336
376
  } else {
337
- transformTextNodeForText(scanningContext, autoFormatCriteria, matchResultContext);
377
+ transformTextNodeForText(scanningContext);
338
378
  }
339
379
  }
340
380
 
341
- function transformTextNodeForParagraphs(scanningContext, autoFormatCriteria, matchResultContext) {
381
+ function transformTextNodeForParagraphs(scanningContext) {
342
382
  const textNodeWithOffset = scanningContext.textNodeWithOffset;
343
383
  const element = textNodeWithOffset.node.getParentOrThrow();
344
- const text = matchResultContext.regExCaptureGroups[0].text;
384
+ const text = scanningContext.matchResultContext.regExCaptureGroups[0].text;
345
385
  updateTextNode(textNodeWithOffset.node, text.length);
346
- const elementNode = getNewNodeForCriteria(autoFormatCriteria, matchResultContext, element.getChildren());
386
+ const elementNode = getNewNodeForCriteria(scanningContext, element);
347
387
 
348
388
  if (elementNode !== null) {
349
389
  element.replace(elementNode);
350
390
  }
351
391
  }
352
392
 
353
- function transformTextNodeForText(scanningContext, autoFormatCriteria, matchResultContext) {
393
+ function transformTextNodeForText(scanningContext) {
394
+ const autoFormatCriteria = scanningContext.autoFormatCriteria;
395
+ const matchResultContext = scanningContext.matchResultContext;
396
+
354
397
  if (autoFormatCriteria.nodeTransformationKind != null) {
355
398
  switch (autoFormatCriteria.nodeTransformationKind) {
356
399
  case 'textBold':
357
400
  {
358
- matchResultContext.regExCaptureGroups = getCaptureGroupsByResolvingAllDetails(scanningContext, autoFormatCriteria, matchResultContext);
359
-
360
- if (autoFormatCriteria.regExCaptureGroupsToDelete != null) {
361
- // Remove unwanted text in reg ex patterh.
362
- removeTextInCaptureGroups(autoFormatCriteria.regExCaptureGroupsToDelete, matchResultContext);
363
- formatTextInCaptureGroupIndex('bold', 3, matchResultContext);
401
+ if (matchResultContext.regExCaptureGroups.length !== 6) {
402
+ // The expected reg ex pattern for bold should have 6 groups.
403
+ // If it does not, then break and fail silently.
404
+ // e2e tests validate the regEx pattern.
405
+ break;
364
406
  }
365
407
 
408
+ matchResultContext.regExCaptureGroups = getCaptureGroupsByResolvingAllDetails(scanningContext); // Remove unwanted text in reg ex pattern.
409
+
410
+ removeTextInCaptureGroups([1, 5], matchResultContext);
411
+ formatTextInCaptureGroupIndex('bold', 3, matchResultContext);
412
+ makeCollapsedSelectionAtOffsetInJoinedText(matchResultContext.offsetInJoinedTextForCollapsedSelection, matchResultContext.offsetInJoinedTextForCollapsedSelection + 1, scanningContext.textNodeWithOffset.node.getParentOrThrow());
366
413
  break;
367
414
  }
368
415
  }
@@ -372,7 +419,9 @@ function transformTextNodeForText(scanningContext, autoFormatCriteria, matchResu
372
419
  // known, the details may be fully resolved without incurring unwasted performance cost.
373
420
 
374
421
 
375
- function getCaptureGroupsByResolvingAllDetails(scanningContext, autoFormatCriteria, matchResultContext) {
422
+ function getCaptureGroupsByResolvingAllDetails(scanningContext) {
423
+ const autoFormatCriteria = scanningContext.autoFormatCriteria;
424
+ const matchResultContext = scanningContext.matchResultContext;
376
425
  const textNodeWithOffset = scanningContext.textNodeWithOffset;
377
426
  const regExCaptureGroups = matchResultContext.regExCaptureGroups;
378
427
  const captureGroupsCount = regExCaptureGroups.length;
@@ -444,6 +493,12 @@ function removeTextInCaptureGroups(regExCaptureGroupsToDelete, matchResultContex
444
493
  }
445
494
 
446
495
  function shiftCaptureGroupOffsets(delta, applyAtOrAfterOffset, node, startingCaptureGroupIndex, matchResultContext) {
496
+ matchResultContext.offsetInJoinedTextForCollapsedSelection += delta;
497
+
498
+ if (!(matchResultContext.offsetInJoinedTextForCollapsedSelection > 0)) {
499
+ throw Error(`The text content string length does not correlate with insertions/deletions of new text.`);
500
+ }
501
+
447
502
  const regExCaptureGroups = matchResultContext.regExCaptureGroups;
448
503
  const regExCaptureGroupsCount = regExCaptureGroups.length;
449
504
 
@@ -481,10 +536,25 @@ function formatTextInCaptureGroupIndex(formatType, captureGroupIndex, matchResul
481
536
 
482
537
  if (currentSelection != null) {
483
538
  currentSelection.formatText(formatType);
539
+ const finalSelection = lexical.$createRangeSelection();
540
+ finalSelection.anchor.set(focusTextNodeWithOffset.node.getKey(), focusTextNodeWithOffset.offset + 1, 'text');
541
+ finalSelection.focus.set(focusTextNodeWithOffset.node.getKey(), focusTextNodeWithOffset.offset + 1, 'text');
542
+ lexical.$setSelection(finalSelection);
484
543
  }
485
544
  }
486
545
  }
487
546
 
547
+ function makeCollapsedSelectionAtOffsetInJoinedText(offsetInJoinedText, joinedTextLength, parentElementNode) {
548
+ const textNodeWithOffset = $findNodeWithOffsetFromJoinedText(parentElementNode, joinedTextLength, offsetInJoinedText, TRIGGER_STRING_LENGTH);
549
+
550
+ if (textNodeWithOffset != null) {
551
+ const newSelection = lexical.$createRangeSelection();
552
+ newSelection.anchor.set(textNodeWithOffset.node.getKey(), textNodeWithOffset.offset, 'text');
553
+ newSelection.focus.set(textNodeWithOffset.node.getKey(), textNodeWithOffset.offset, 'text');
554
+ lexical.$setSelection(newSelection);
555
+ }
556
+ }
557
+
488
558
  /**
489
559
  * Copyright (c) Meta Platforms, Inc. and affiliates.
490
560
  *
@@ -494,17 +564,17 @@ function formatTextInCaptureGroupIndex(formatType, captureGroupIndex, matchResul
494
564
  *
495
565
  */
496
566
 
497
- function getCriteriaWithMatchResultContext(autoFormatCriteriaArray, currentTriggerState, scanningContext) {
567
+ function getCriteriaWithMatchResultContext(autoFormatCriteriaArray, scanningContext) {
568
+ const currentTriggerState = scanningContext.triggerState;
498
569
  const count = autoFormatCriteriaArray.length;
499
570
 
500
571
  for (let i = 0; i < count; i++) {
501
572
  const autoFormatCriteria = autoFormatCriteriaArray[i]; // Skip code block nodes, unless the nodeTransformationKind calls for toggling the code block.
502
573
 
503
- if (currentTriggerState.isCodeBlock === false || autoFormatCriteria.nodeTransformationKind === 'paragraphCodeBlock') {
574
+ if (currentTriggerState != null && currentTriggerState.isCodeBlock === false || autoFormatCriteria.nodeTransformationKind === 'paragraphCodeBlock') {
504
575
  const matchResultContext = getMatchResultContextForCriteria(autoFormatCriteria, scanningContext);
505
576
 
506
577
  if (matchResultContext != null) {
507
- matchResultContext.triggerState = currentTriggerState;
508
578
  return {
509
579
  autoFormatCriteria: autoFormatCriteria,
510
580
  matchResultContext
@@ -536,8 +606,17 @@ function getTextNodeForAutoFormatting(selection) {
536
606
  };
537
607
  }
538
608
 
539
- function updateAutoFormatting(editor, currentTriggerState) {
609
+ function updateAutoFormatting(editor, scanningContext) {
540
610
  editor.update(() => {
611
+ transformTextNodeForAutoFormatCriteria(scanningContext);
612
+ }, {
613
+ tag: 'history-push'
614
+ });
615
+ }
616
+
617
+ function findScanningContextWithValidMatch(editorState, currentTriggerState) {
618
+ let scanningContext = null;
619
+ editorState.read(() => {
541
620
  const textNodeWithOffset = getTextNodeForAutoFormatting(lexical.$getSelection());
542
621
 
543
622
  if (textNodeWithOffset === null) {
@@ -545,24 +624,25 @@ function updateAutoFormatting(editor, currentTriggerState) {
545
624
  } // Please see the declaration of ScanningContext for a detailed explanation.
546
625
 
547
626
 
548
- const scanningContext = {
549
- joinedText: null,
550
- textNodeWithOffset
551
- };
627
+ const initialScanningContext = getInitialScanningContext(textNodeWithOffset, currentTriggerState);
552
628
  const criteriaWithMatchResultContext = getCriteriaWithMatchResultContext( // Do not apply paragraph node changes like blockQuote or H1 to listNodes. Also, do not attempt to transform a list into a list using * or -.
553
- currentTriggerState.isParentAListItemNode === false ? getAllAutoFormatCriteria() : getAllAutoFormatCriteriaForTextNodes(), currentTriggerState, scanningContext);
629
+ currentTriggerState.isParentAListItemNode === false ? getAllAutoFormatCriteria() : getAllAutoFormatCriteriaForTextNodes(), initialScanningContext);
554
630
 
555
631
  if (criteriaWithMatchResultContext.autoFormatCriteria === null || criteriaWithMatchResultContext.matchResultContext === null) {
556
632
  return;
557
633
  }
558
634
 
559
- transformTextNodeForAutoFormatCriteria(scanningContext, criteriaWithMatchResultContext.autoFormatCriteria, criteriaWithMatchResultContext.matchResultContext);
635
+ scanningContext = initialScanningContext; // Lazy fill-in the particular format criteria and any matching result information.
636
+
637
+ scanningContext.autoFormatCriteria = criteriaWithMatchResultContext.autoFormatCriteria;
638
+ scanningContext.matchResultContext = criteriaWithMatchResultContext.matchResultContext;
560
639
  });
640
+ return scanningContext;
561
641
  }
562
642
 
563
- function shouldAttemptToAutoFormat(currentTriggerState, priorTriggerState) {
643
+ function findScanningContext(editorState, currentTriggerState, priorTriggerState) {
564
644
  if (currentTriggerState == null || priorTriggerState == null) {
565
- return false;
645
+ return null;
566
646
  } // The below checks needs to execute relativey quickly, so perform the light-weight ones first.
567
647
  // The substr check is a quick way to avoid autoformat parsing in that it looks for the autoformat
568
648
  // trigger which is the trigger string (" ").
@@ -571,7 +651,12 @@ function shouldAttemptToAutoFormat(currentTriggerState, priorTriggerState) {
571
651
  const triggerStringLength = TRIGGER_STRING.length;
572
652
  const currentTextContentLength = currentTriggerState.textContent.length;
573
653
  const triggerOffset = currentTriggerState.anchorOffset - triggerStringLength;
574
- return currentTriggerState.hasParentNode === true && currentTriggerState.isSimpleText && currentTriggerState.isSelectionCollapsed && currentTriggerState.nodeKey === priorTriggerState.nodeKey && currentTriggerState.anchorOffset !== priorTriggerState.anchorOffset && triggerOffset >= 0 && triggerOffset + triggerStringLength <= currentTextContentLength && currentTriggerState.textContent.substr(triggerOffset, triggerStringLength) === TRIGGER_STRING && currentTriggerState.textContent !== priorTriggerState.textContent;
654
+
655
+ if ((currentTriggerState.hasParentNode === true && currentTriggerState.isSimpleText && currentTriggerState.isSelectionCollapsed && currentTriggerState.nodeKey === priorTriggerState.nodeKey && currentTriggerState.anchorOffset !== priorTriggerState.anchorOffset && triggerOffset >= 0 && triggerOffset + triggerStringLength <= currentTextContentLength && currentTriggerState.textContent.substr(triggerOffset, triggerStringLength) === TRIGGER_STRING && currentTriggerState.textContent !== priorTriggerState.textContent) === false) {
656
+ return null;
657
+ }
658
+
659
+ return findScanningContextWithValidMatch(editorState, currentTriggerState);
575
660
  }
576
661
 
577
662
  function getTriggerState(editorState) {
@@ -608,15 +693,17 @@ function useAutoFormatter(editor) {
608
693
  // For example, typing "#" and then " ", shoud trigger an format.
609
694
  // However, given "#A B", where the user delets "A" should not.
610
695
  let priorTriggerState = null;
611
- editor.addListener('update', ({
696
+ return editor.addListener('update', ({
612
697
  tags
613
698
  }) => {
614
699
  // Examine historic so that we are not running autoformatting within markdown.
615
700
  if (tags.has('historic') === false) {
616
- const currentTriggerState = getTriggerState(editor.getEditorState());
701
+ const editorState = editor.getEditorState();
702
+ const currentTriggerState = getTriggerState(editorState);
703
+ const scanningContext = currentTriggerState == null ? null : findScanningContext(editorState, currentTriggerState, priorTriggerState);
617
704
 
618
- if (shouldAttemptToAutoFormat(currentTriggerState, priorTriggerState) && currentTriggerState != null) {
619
- updateAutoFormatting(editor, currentTriggerState);
705
+ if (scanningContext != null) {
706
+ updateAutoFormatting(editor, scanningContext);
620
707
  }
621
708
 
622
709
  priorTriggerState = currentTriggerState;
@@ -4,19 +4,22 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- 'use strict';var n=require("@lexical/list"),p=require("lexical"),r=require("lexical/CodeNode"),v=require("react"),x=require("lexical/HeadingNode"),y=require("lexical/QuoteNode");function z(g){throw Error(`Minified Lexical error #${g}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
8
- function A(g,k,b,a){g=g.getChildren();const d=g.length;let e=0;for(let h=0;h<d&&!(e>=k);++h){const f=g[h];var c=p.$isTextNode(f)?f.getTextContent().length:a;c=e+c;if(e<=b&&b<c&&p.$isTextNode(f))return{node:f,offset:b-e};e=c}return null}
9
- const B={nodeTransformationKind:null,regEx:/(?:)/,regExCaptureGroupsToDelete:null,regExExpectedCaptureGroupCount:1,requiresParagraphStart:!1},C={...B,requiresParagraphStart:!0},D=[{...B,nodeTransformationKind:"textBold",regEx:/(\*)(\s*\b)([^\*]*)(\b\s*)(\*\s)$/,regExCaptureGroupsToDelete:[1,5],regExExpectedCaptureGroupCount:6}],F=[{...C,nodeTransformationKind:"paragraphH1",regEx:/(?:# )/},{...C,nodeTransformationKind:"paragraphH2",regEx:/(?:## )/},{...C,nodeTransformationKind:"paragraphH2",regEx:/(?:### )/},
10
- {...C,nodeTransformationKind:"paragraphBlockQuote",regEx:/(?:> )/},{...C,nodeTransformationKind:"paragraphUnorderedList",regEx:/(?:- )/},{...C,nodeTransformationKind:"paragraphUnorderedList",regEx:/(?:\* )/},{...C,nodeTransformationKind:"paragraphOrderedList",regEx:/^(\d+)\.\s/,regExExpectedCaptureGroupCount:2},{...C,nodeTransformationKind:"paragraphCodeBlock",regEx:/(?:``` )/},...D];
11
- function G(g,k,b,a,d){const e={regExCaptureGroups:[],triggerState:null};a=g.match(a);if(null!==a&&0<a.length&&a.length===d&&(!1===k||0===a.index)&&(!1===b||a.index+a[0].length===g.length)){g=a.length;k=a.index;for(b=0;b<g;b++)d=a[b],e.regExCaptureGroups.push({anchorTextNodeWithOffset:null,focusTextNodeWithOffset:null,offsetInParent:k,text:d,textLength:d.length-(b+1===g?1:0)}),0<b&&(k+=d.length);return e}return null}
12
- function H(g,k,b,a,d){d=d.regExCaptureGroups;const e=d.length;for(a+=1;a<e;a++){const c=d[a];null!=c.anchorTextNodeWithOffset&&c.anchorTextNodeWithOffset.offset>=k&&c.anchorTextNodeWithOffset.node.is(b)&&(c.anchorTextNodeWithOffset.offset+=g);null!=c.focusTextNodeWithOffset&&c.focusTextNodeWithOffset.offset>=k&&c.focusTextNodeWithOffset.node.is(b)&&(c.focusTextNodeWithOffset.offset+=g)}}
13
- function I(g,k){g.update(()=>{var b=p.$getSelection();if(null==b)b=null;else{var a=b.anchor.getNode();b=p.$isTextNode(a)?{node:a,offset:b.anchor.offset}:null}if(null!==b){b={joinedText:null,textNodeWithOffset:b};a:{a=!1===k.isParentAListItemNode?F:D;var d=a.length;for(var e=0;e<d;e++){var c=a[e];if(!1===k.isCodeBlock||"paragraphCodeBlock"===c.nodeTransformationKind){var h=c,f=b;if(null!==h.requiresParagraphStart&&!0===h.requiresParagraphStart)null===f.textNodeWithOffset.node.getPreviousSibling()?
14
- (f=f.textNodeWithOffset.node.getTextContent(),h=G(f,!0,!1,h.regEx,h.regExExpectedCaptureGroupCount)):h=null;else b:{if(null==f.joinedText){var q=f.textNodeWithOffset.node.getParentOrThrow();if(p.$isElementNode(q)){if(null==f.joinedText){var l=f,m=f.textNodeWithOffset;let u="";q=q.getChildren();const J=q.length;for(let w=0;w<J;++w){const t=q[w];if(p.$isTextNode(t)){const E=t.getTextContent();if(t.is(m.node)){m.offset>E.length&&z(50,t.__key);u+=t.getTextContent().substr(0,m.offset);break}else u+=E}else u+=
15
- "\u0004"}l.joinedText=u}h=G(f.joinedText,!1,!0,h.regEx,h.regExExpectedCaptureGroupCount);break b}z(52,q.__key)}h=null}if(null!=h){h.triggerState=k;a={autoFormatCriteria:c,matchResultContext:h};break a}}}a={autoFormatCriteria:null,matchResultContext:null}}if(null!==a.autoFormatCriteria&&null!==a.matchResultContext)if(d=a.autoFormatCriteria,a=a.matchResultContext,d.requiresParagraphStart){e=b.textNodeWithOffset;b=e.node.getParentOrThrow();e=e.node.spliceText(0,a.regExCaptureGroups[0].text.length,"",
16
- !0);""===e.getTextContent()&&(e.selectPrevious(),e.remove());e=b.getChildren();c=null;if(null!=d.nodeTransformationKind)switch(d.nodeTransformationKind){case "paragraphH1":c=x.$createHeadingNode("h1");c.append(...e);break;case "paragraphH2":c=x.$createHeadingNode("h2");c.append(...e);break;case "paragraphH3":c=x.$createHeadingNode("h3");c.append(...e);break;case "paragraphBlockQuote":c=y.$createQuoteNode();c.append(...e);break;case "paragraphUnorderedList":c=n.$createListNode("ul");a=n.$createListItemNode();
17
- a.append(...e);c.append(a);break;case "paragraphOrderedList":a=parseInt(1<a.regExCaptureGroups.length?a.regExCaptureGroups[a.regExCaptureGroups.length-1].text:"1",10);c=n.$createListNode("ol",a);a=n.$createListItemNode();a.append(...e);c.append(a);break;case "paragraphCodeBlock":c=null!=a.triggerState&&a.triggerState.isCodeBlock?p.$createParagraphNode():r.$createCodeNode(),c.append(...e)}a=c;null!==a&&b.replace(a)}else if(null!=d.nodeTransformationKind)switch(d.nodeTransformationKind){case "textBold":e=
18
- a.regExCaptureGroups;c=e.length;h=b.textNodeWithOffset.node.getParentOrThrow();if(null==b.joinedText)throw Error("joinedText was not calculated");b=b.joinedText.length;for(f=1;f<c;f++)if(l=e[f],l.anchorTextNodeWithOffset=A(h,b,l.offsetInParent,1),l.focusTextNodeWithOffset=A(h,b,l.offsetInParent+l.textLength,1),0>l.textLength)throw Error(`Bad regEx pattern found for ${d.nodeTransformationKind}`);a.regExCaptureGroups=e;if(null!=d.regExCaptureGroupsToDelete){b=d.regExCaptureGroupsToDelete;d=a.regExCaptureGroups;
19
- e=d.length;for(c=b.length-1;0<=c;c--)if(c<e&&(h=b[c],m=d[h],l=m.anchorTextNodeWithOffset,f=m.focusTextNodeWithOffset,null!=l&&null!=f&&0<m.textLength&&(m=p.$createRangeSelection(),m.anchor.set(l.node.getKey(),l.offset,"text"),m.focus.set(f.node.getKey(),f.offset,"text"),p.$setSelection(m),m=p.$getSelection(),null!=m)))if(m.removeText(),l.node.getKey()===f.node.getKey()){m=f.offset-l.offset;if(!(0<m))throw Error("Expected anchor and focus offsets to have ascending character order.");H(-m,f.offset,
20
- l.node,h,a)}else l=f.offset,0<l&&H(-l,l,f.node,h,a);b=a.regExCaptureGroups;if(!(3<b.length))throw Error("The capture group count in the RegEx does match the actual capture group count.");d=b[3];b=d.anchorTextNodeWithOffset;a=d.focusTextNodeWithOffset;null!=b&&null!=a&&0<d.textLength&&(d=p.$createRangeSelection(),d.anchor.set(b.node.getKey(),b.offset,"text"),d.focus.set(a.node.getKey(),a.offset,"text"),p.$setSelection(d),b=p.$getSelection(),null!=b&&b.formatText("bold"))}}}})}
21
- function K(g){let k=null;g.read(()=>{const b=p.$getSelection();if(null!=b&&b.isCollapsed()){var a=b.anchor.getNode(),d=a.getParent(),e=null!==d&&n.$isListItemNode(d);k={anchorOffset:b.anchor.offset,hasParentNode:null!==d,isCodeBlock:r.$isCodeNode(a),isParentAListItemNode:e,isSelectionCollapsed:b.isCollapsed(),isSimpleText:p.$isTextNode(a)&&a.isSimpleText(),nodeKey:a.getKey(),textContent:a.getTextContent()}}});return k}
22
- function L(g){v.useEffect(()=>{let k=null;g.addListener("update",({tags:b})=>{if(!1===b.has("historic")){b=K(g.getEditorState());var a=b;var d=k;if(null==a||null==d)a=!1;else{var e=a.textContent.length,c=a.anchorOffset-1;a=!0===a.hasParentNode&&a.isSimpleText&&a.isSelectionCollapsed&&a.nodeKey===d.nodeKey&&a.anchorOffset!==d.anchorOffset&&0<=c&&c+1<=e&&" "===a.textContent.substr(c,1)&&a.textContent!==d.textContent}a&&null!=b&&I(g,b);k=b}else k=null})},[g])}module.exports=function(g){L(g)};
7
+ var l=require("@lexical/list"),p=require("lexical"),q=require("lexical/CodeNode"),r=require("react"),v=require("@lexical/react/LexicalHorizontalRuleNode"),w=require("lexical/HeadingNode"),A=require("lexical/QuoteNode");function B(g){throw Error(`Minified Lexical error #${g}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
8
+ function C(g,f,a,b){g=g.getChildren();const c=g.length;let d=0,e=!1;for(let n=0;n<c&&!(d>f);++n){const h=g[n],m=p.$isTextNode(h);var k=m?h.getTextContent().length:b;k=d+k;if((!1===e&&d===a||0===d&&d===a||d<a&&a<=k)&&p.$isTextNode(h))return{node:h,offset:a-d};d=k;e=m}return null}
9
+ const D={nodeTransformationKind:null,regEx:/(?:)/,requiresParagraphStart:!1},E={...D,requiresParagraphStart:!0},G=[{...D,nodeTransformationKind:"textBold",regEx:/(\*)(\s*\b)([^\*]*)(\b\s*)(\*\s)$/}],H=[{...E,nodeTransformationKind:"paragraphH1",regEx:/(?:# )/},{...E,nodeTransformationKind:"paragraphH2",regEx:/(?:## )/},{...E,nodeTransformationKind:"paragraphH2",regEx:/(?:### )/},{...E,nodeTransformationKind:"paragraphBlockQuote",regEx:/(?:> )/},{...E,nodeTransformationKind:"paragraphUnorderedList",
10
+ regEx:/(?:- )/},{...E,nodeTransformationKind:"paragraphUnorderedList",regEx:/(?:\* )/},{...E,nodeTransformationKind:"paragraphOrderedList",regEx:/^(\d+)\.\s/},{...E,nodeTransformationKind:"paragraphCodeBlock",regEx:/(?:``` )/},{...E,nodeTransformationKind:"horizontalRule",regEx:/(?:\*\*\* )/},{...E,nodeTransformationKind:"horizontalRule",regEx:/(?:--- )/},...G];
11
+ function I(g,f,a,b){const c={offsetInJoinedTextForCollapsedSelection:0,regExCaptureGroups:[]};b=g.match(b);if(null!==b&&0<b.length&&(!1===f||0===b.index)&&(!1===a||b.index+b[0].length===g.length)){c.offsetInJoinedTextForCollapsedSelection=g.length;g=b.length;f=b.index;for(a=0;a<g;a++){const d=b[a];c.regExCaptureGroups.push({anchorTextNodeWithOffset:null,focusTextNodeWithOffset:null,offsetInParent:f,text:d,textLength:d.length-(a+1===g?1:0)});0<a&&(f+=d.length)}return c}return null}
12
+ function J(g,f,a,b,c){c.offsetInJoinedTextForCollapsedSelection+=g;0<c.offsetInJoinedTextForCollapsedSelection||B(67);c=c.regExCaptureGroups;const d=c.length;for(b+=1;b<d;b++){const e=c[b];null!=e.anchorTextNodeWithOffset&&e.anchorTextNodeWithOffset.offset>=f&&e.anchorTextNodeWithOffset.node.is(a)&&(e.anchorTextNodeWithOffset.offset+=g);null!=e.focusTextNodeWithOffset&&e.focusTextNodeWithOffset.offset>=f&&e.focusTextNodeWithOffset.node.is(a)&&(e.focusTextNodeWithOffset.offset+=g)}}
13
+ function K(g,f){g.update(()=>{if(f.autoFormatCriteria.requiresParagraphStart){var a=f.textNodeWithOffset,b=a.node.getParentOrThrow();a=a.node.spliceText(0,f.matchResultContext.regExCaptureGroups[0].text.length,"",!0);""===a.getTextContent()&&(a.selectPrevious(),a.remove());var c=b;a=null;var d=c.getChildren(),e=f.autoFormatCriteria,k=f.matchResultContext;if(null!=e.nodeTransformationKind)switch(e.nodeTransformationKind){case "paragraphH1":a=w.$createHeadingNode("h1");a.append(...d);break;case "paragraphH2":a=
14
+ w.$createHeadingNode("h2");a.append(...d);break;case "paragraphH3":a=w.$createHeadingNode("h3");a.append(...d);break;case "paragraphBlockQuote":a=A.$createQuoteNode();a.append(...d);break;case "paragraphUnorderedList":a=l.$createListNode("ul");c=l.$createListItemNode();c.append(...d);a.append(c);break;case "paragraphOrderedList":a=parseInt(1<k.regExCaptureGroups.length?k.regExCaptureGroups[k.regExCaptureGroups.length-1].text:"1",10);a=l.$createListNode("ol",a);c=l.$createListItemNode();c.append(...d);
15
+ a.append(c);break;case "paragraphCodeBlock":a=null!=f.triggerState&&f.triggerState.isCodeBlock?p.$createParagraphNode():q.$createCodeNode();a.append(...d);break;case "horizontalRule":d=v.$createHorizontalRuleNode(),c.insertBefore(d)}null!==a&&b.replace(a)}else if(a=f.autoFormatCriteria,b=f.matchResultContext,null!=a.nodeTransformationKind)switch(a.nodeTransformationKind){case "textBold":if(6===b.regExCaptureGroups.length){a=f.autoFormatCriteria;d=f.matchResultContext.regExCaptureGroups;c=d.length;
16
+ e=f.textNodeWithOffset.node.getParentOrThrow();null==f.joinedText&&B(62);k=f.joinedText.length;for(var n=1;n<c;n++){var h=d[n];h.anchorTextNodeWithOffset=C(e,k,h.offsetInParent,1);h.focusTextNodeWithOffset=C(e,k,h.offsetInParent+h.textLength,1);0>h.textLength&&B(63,a.nodeTransformationKind)}b.regExCaptureGroups=d;a=[1,5];d=b.regExCaptureGroups;c=d.length;for(e=a.length-1;0<=e;e--)if(e<c){k=a[e];var m=d[k];h=m.anchorTextNodeWithOffset;n=m.focusTextNodeWithOffset;null!=h&&null!=n&&0<m.textLength&&(m=
17
+ p.$createRangeSelection(),m.anchor.set(h.node.getKey(),h.offset,"text"),m.focus.set(n.node.getKey(),n.offset,"text"),p.$setSelection(m),m=p.$getSelection(),null!=m&&(m.removeText(),h.node.getKey()===n.node.getKey()?(m=n.offset-h.offset,0<m||B(64),J(-m,n.offset,h.node,k,b)):(h=n.offset,0<h&&J(-h,h,n.node,k,b))))}a=b.regExCaptureGroups;3<a.length||B(65);c=a[3];d=c.anchorTextNodeWithOffset;a=c.focusTextNodeWithOffset;null!=d&&null!=a&&0<c.textLength&&(c=p.$createRangeSelection(),c.anchor.set(d.node.getKey(),
18
+ d.offset,"text"),c.focus.set(a.node.getKey(),a.offset,"text"),p.$setSelection(c),d=p.$getSelection(),null!=d&&(d.formatText("bold"),d=p.$createRangeSelection(),d.anchor.set(a.node.getKey(),a.offset+1,"text"),d.focus.set(a.node.getKey(),a.offset+1,"text"),p.$setSelection(d)));a=f.textNodeWithOffset.node.getParentOrThrow();b=C(a,b.offsetInJoinedTextForCollapsedSelection+1,b.offsetInJoinedTextForCollapsedSelection,1);null!=b&&(a=p.$createRangeSelection(),a.anchor.set(b.node.getKey(),b.offset,"text"),
19
+ a.focus.set(b.node.getKey(),b.offset,"text"),p.$setSelection(a))}}},{tag:"history-push"})}
20
+ function L(g,f){let a=null;g.read(()=>{var b=p.$getSelection();if(null==b)b=null;else{var c=b.anchor.getNode();b=p.$isTextNode(c)?{node:c,offset:b.anchor.offset}:null}if(null!==b){b={autoFormatCriteria:{nodeTransformationKind:"noTransformation",regEx:/(?:)/,requiresParagraphStart:null},joinedText:null,matchResultContext:{offsetInJoinedTextForCollapsedSelection:0,regExCaptureGroups:[]},textNodeWithOffset:b,triggerState:f};a:{c=!1===f.isParentAListItemNode?H:G;const m=b.triggerState,M=c.length;for(let x=
21
+ 0;x<M;x++){const y=c[x];if(null!=m&&!1===m.isCodeBlock||"paragraphCodeBlock"===y.nodeTransformationKind){var d=y,e=b;if(null!==d.requiresParagraphStart&&!0===d.requiresParagraphStart)null===e.textNodeWithOffset.node.getPreviousSibling()?(e=e.textNodeWithOffset.node.getTextContent(),d=I(e,!0,!1,d.regEx)):d=null;else b:{if(null==e.joinedText){var k=e.textNodeWithOffset.node.getParentOrThrow();if(p.$isElementNode(k)){if(null==e.joinedText){var n=e,h=e.textNodeWithOffset;let u="";k=k.getChildren();const N=
22
+ k.length;for(let z=0;z<N;++z){const t=k[z];if(p.$isTextNode(t)){const F=t.getTextContent();if(t.is(h.node)){h.offset>F.length&&B(50,t.__key);u+=t.getTextContent().substr(0,h.offset);break}else u+=F}else u+="\u0004"}n.joinedText=u}d=I(e.joinedText,!1,!0,d.regEx);break b}B(52,k.__key)}d=null}if(null!=d){c={autoFormatCriteria:y,matchResultContext:d};break a}}}c={autoFormatCriteria:null,matchResultContext:null}}null!==c.autoFormatCriteria&&null!==c.matchResultContext&&(a=b,a.autoFormatCriteria=c.autoFormatCriteria,
23
+ a.matchResultContext=c.matchResultContext)}});return a}function O(g){let f=null;g.read(()=>{const a=p.$getSelection();if(null!=a&&a.isCollapsed()){var b=a.anchor.getNode(),c=b.getParent(),d=null!==c&&l.$isListItemNode(c);f={anchorOffset:a.anchor.offset,hasParentNode:null!==c,isCodeBlock:q.$isCodeNode(b),isParentAListItemNode:d,isSelectionCollapsed:a.isCollapsed(),isSimpleText:p.$isTextNode(b)&&b.isSimpleText(),nodeKey:b.getKey(),textContent:b.getTextContent()}}});return f}
24
+ function P(g){r.useEffect(()=>{let f=null;return g.addListener("update",({tags:a})=>{if(!1===a.has("historic")){var b=g.getEditorState();a=O(b);if(null==a)b=null;else{var c=a,d=f;if(null==c||null==d)b=null;else{var e=c.textContent.length,k=c.anchorOffset-1;b=!1===(!0===c.hasParentNode&&c.isSimpleText&&c.isSelectionCollapsed&&c.nodeKey===d.nodeKey&&c.anchorOffset!==d.anchorOffset&&0<=k&&k+1<=e&&" "===c.textContent.substr(k,1)&&c.textContent!==d.textContent)?null:L(b,c)}}null!=b&&K(g,b);f=a}else f=
25
+ null})},[g])}module.exports=function(g){P(g)};
@@ -4,5 +4,5 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- 'use strict';var e=require("lexical"),f=require("react");function k(a,d=!0){if(a)return!1;a=e.$getRoot().getTextContent();d&&(a=a.trim());return""===a}function l(a){if(!k(a,!1))return!1;a=e.$getRoot().getChildren();const d=a.length;if(1<d)return!1;for(let c=0;c<d;c++){var b=a[c];if(e.$isElementNode(b)){if("paragraph"!==b.__type||0!==b.__indent)return!1;b=b.getChildren();const g=b.length;for(let h=0;h<g;h++)if(!e.$isTextNode(b[c]))return!1}}return!0}function m(a){return()=>l(a)}
7
+ var e=require("lexical"),f=require("react");function k(a,d=!0){if(a)return!1;a=e.$getRoot().getTextContent();d&&(a=a.trim());return""===a}function l(a){if(!k(a,!1))return!1;a=e.$getRoot().getChildren();const d=a.length;if(1<d)return!1;for(let c=0;c<d;c++){var b=a[c];if(e.$isElementNode(b)){if("paragraph"!==b.__type||0!==b.__indent)return!1;b=b.getChildren();const g=b.length;for(let h=0;h<g;h++)if(!e.$isTextNode(b[c]))return!1}}return!0}function m(a){return()=>l(a)}
8
8
  var n="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?f.useLayoutEffect:f.useEffect;function p(a){const [d,b]=f.useState(a.getEditorState().read(m(a.isComposing())));n(()=>a.addListener("update",({editorState:c})=>{const g=a.isComposing();c=c.read(m(g));b(c)}),[a]);return d}module.exports=function(a){return p(a)};
@@ -105,10 +105,9 @@ function useCharacterLimit(editor, maxCharacters, optional = Object.freeze({}))
105
105
  if (lastComputedTextLength === null || textLengthAboveThreshold) {
106
106
  const offset = findOffset(text, maxCharacters, strlen);
107
107
  editor.update(() => {
108
- lexical.$log('CharacterLimit');
109
108
  $wrapOverflowedNodes(offset);
110
109
  }, {
111
- tag: 'without-history'
110
+ tag: 'history-merge'
112
111
  });
113
112
  }
114
113
 
@@ -4,11 +4,11 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- 'use strict';var k=require("lexical"),l=require("@lexical/react/withSubscriptions"),n=require("lexical/OverflowNode"),p=require("react");function q(a,e){for(e(a);null!==a;){if(k.$isElementNode(a)&&0<a.getChildrenSize())a=a.getFirstChild();else{let d=null;for(;null===d&&null!==a;)d=a.getNextSibling(),a=null===d?a.getParent():d}null!==a&&(a=e(a))}}function r(){return k.$getRoot().getTextContent()}
7
+ var k=require("lexical"),l=require("@lexical/react/withSubscriptions"),n=require("lexical/OverflowNode"),p=require("react");function q(a,e){for(e(a);null!==a;){if(k.$isElementNode(a)&&0<a.getChildrenSize())a=a.getFirstChild();else{let d=null;for(;null===d&&null!==a;)d=a.getNextSibling(),a=null===d?a.getParent():d}null!==a&&(a=e(a))}}function r(){return k.$getRoot().getTextContent()}
8
8
  function t(a,e,d){var g=Intl.Segmenter;let c=0;var b=0;if("function"===typeof g){a=(new g).segment(a);for(var {segment:f}of a){b+=d(f);if(b>e)break;c+=f.length}}else for(f=Array.from(a),a=f.length,g=0;g<a;g++){const h=f[g];b+=d(h);if(b>e)break;c+=h.length}return c}
9
9
  function u(a){const e=k.$getRoot();let d=0,g=e;q(e,c=>{if(n.$isOverflowNode(c)){var b=d;if(d+c.getTextContentSize()<=a){var f=c.getParent();b=c.getPreviousSibling();var h=c.getNextSibling();v(c);c=k.$getSelection();null===c||c.anchor.getNode().isAttached()&&c.focus.getNode().isAttached()||(k.$isTextNode(b)?b.select():k.$isTextNode(h)?h.select():null!==f&&f.select());return g}if(b<a&&(f=c.getFirstDescendant(),h=null!==f?f.getTextContentSize():0,b+=h,f=k.$isTextNode(f)&&f.isSimpleText(),b=b<=a,f||b))return v(c),
10
10
  g}else k.$isLeafNode(c)&&(b=d,d+=c.getTextContentSize(),d>a&&!n.$isOverflowNode(c.getParent())&&(f=k.$getSelection(),b<a&&k.$isTextNode(c)&&c.isSimpleText()?([,b]=c.splitText(a-b),b=w(b)):b=w(c),null!==f&&k.$setSelection(f),x(b)));return g=c})}function w(a){const e=n.$createOverflowNode();a.insertBefore(e);e.append(a);return e}function v(a){const e=a.getChildren(),d=e.length;for(let g=0;g<d;g++)a.insertBefore(e[g]);a.remove();return 0<d?e[d-1]:null}
11
11
  function x(a){const e=a.getPreviousSibling();if(n.$isOverflowNode(e)){var d=a.getFirstChild(),g=e.getChildren(),c=g.length;if(null===d)a.append(...g);else for(var b=0;b<c;b++)d.insertBefore(g[b]);b=k.$getSelection();if(null!==b){d=b.anchor;g=d.getNode();b=b.focus;const f=d.getNode();g.is(e)?d.set(a.getKey(),d.offset,"element"):g.is(a)&&d.set(a.getKey(),c+d.offset,"element");f.is(e)?b.set(a.getKey(),b.offset,"element"):f.is(a)&&b.set(a.getKey(),c+b.offset,"element")}e.remove()}}
12
12
  exports.mergePrevious=x;
13
- exports.useCharacterLimit=function(a,e,d=Object.freeze({})){const {strlen:g=b=>b.length,remainingCharacters:c=()=>{}}=d;p.useEffect(()=>{if(!a.hasNodes([n.OverflowNode]))throw Error("useCharacterLimit: OverflowNode not registered on editor");},[a]);p.useEffect(()=>{let b=a.getEditorState().read(r),f=0;return l(a.addListener("textcontent",h=>{b=h}),a.addListener("update",({dirtyLeaves:h})=>{var m=a.isComposing();h=0<h.size;if(!m&&h){m=g(b);h=m>e||null!==f&&f>e;c(e-m);if(null===f||h){const y=t(b,e,
14
- g);a.update(()=>{k.$log("CharacterLimit");u(y)},{tag:"without-history"})}f=m}}))},[a,e,c,g])};
13
+ exports.useCharacterLimit=function(a,e,d=Object.freeze({})){const {strlen:g=b=>b.length,remainingCharacters:c=()=>{}}=d;p.useEffect(()=>{if(!a.hasNodes([n.OverflowNode]))throw Error("Minified Lexical error #58; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");},[a]);p.useEffect(()=>{let b=a.getEditorState().read(r),f=0;return l(a.addListener("textcontent",h=>{b=h}),a.addListener("update",({dirtyLeaves:h})=>{var m=a.isComposing();
14
+ h=0<h.size;if(!m&&h){m=g(b);h=m>e||null!==f&&f>e;c(e-m);if(null===f||h){const y=t(b,e,g);a.update(()=>{u(y)},{tag:"history-merge"})}f=m}}))},[a,e,c,g])};
@@ -4,5 +4,5 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- 'use strict';var c=require("react"),g=require("react-dom"),k="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?c.useLayoutEffect:c.useEffect;
7
+ var c=require("react"),g=require("react-dom"),k="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?c.useLayoutEffect:c.useEffect;
8
8
  function l(a){const [e,m]=c.useState(()=>a.getDecorators());k(()=>a.addListener("decorator",d=>{g.flushSync(()=>{m(d)})}),[a]);return c.useMemo(()=>{const d=[],h=Object.keys(e);for(let f=0;f<h.length;f++){var b=h[f];const n=e[b];b=a.getElementByKey(b);null!==b&&d.push(g.createPortal(n,b))}return d},[e,a])}module.exports=function(a){return l(a)};
@@ -4,4 +4,4 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- 'use strict';var b=require("@lexical/react/DEPRECATED_useLexicalCanShowPlaceholder"),d=require("react"),e="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?d.useLayoutEffect:d.useEffect;module.exports=function(a,c){const f=b(a),h=d.useCallback(g=>{a.setRootElement(g)},[a]);e(()=>a.addListener("error",c),[a,c]);return[h,f]};
7
+ var b=require("@lexical/react/DEPRECATED_useLexicalCanShowPlaceholder"),d=require("react"),e="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?d.useLayoutEffect:d.useEffect;module.exports=function(a,c){const f=b(a),h=d.useCallback(g=>{a.setRootElement(g)},[a]);e(()=>a.addListener("error",c),[a,c]);return[h,f]};
@@ -4,5 +4,5 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- 'use strict';var g=require("react"),h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?g.useLayoutEffect:g.useEffect;function p(a,b){return"selectionchange"===a||"keyup"===a||"pointerup"===a||"pointercancel"===a?b.ownerDocument:b}
7
+ var g=require("react"),h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?g.useLayoutEffect:g.useEffect;function p(a,b){return"selectionchange"===a||"keyup"===a||"pointerup"===a||"pointercancel"===a?b.ownerDocument:b}
8
8
  function q(a,b){h(()=>{const k=[],l=[];for(let d=0;d<a.length;d++){const [c,e]=a[d],n=f=>{const m=b.getRootElement();null!==m&&"true"===m.contentEditable&&e(f,b)};k.push(f=>{p(c,f).addEventListener(c,n)});l.push(f=>{p(c,f).removeEventListener(c,n)})}return b.addListener("root",(d,c)=>{null!==c&&l.forEach(e=>e(c));null!==d&&k.forEach(e=>e(d))})},[b,a])}module.exports=function(a,b){q(a,b)};