@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.
- package/DEPRECATED_useLexical.prod.js +1 -1
- package/DEPRECATED_useLexicalAutoFormatter.dev.js +142 -55
- package/DEPRECATED_useLexicalAutoFormatter.prod.js +19 -16
- package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +1 -1
- package/DEPRECATED_useLexicalCharacterLimit.dev.js +1 -2
- package/DEPRECATED_useLexicalCharacterLimit.prod.js +3 -3
- package/DEPRECATED_useLexicalDecorators.prod.js +1 -1
- package/DEPRECATED_useLexicalEditor.prod.js +1 -1
- package/DEPRECATED_useLexicalEditorEvents.prod.js +1 -1
- package/DEPRECATED_useLexicalHistory.dev.js +17 -14
- package/DEPRECATED_useLexicalHistory.prod.js +7 -7
- package/DEPRECATED_useLexicalList.prod.js +1 -1
- package/DEPRECATED_useLexicalPlainText.dev.js +46 -23
- package/DEPRECATED_useLexicalPlainText.prod.js +16 -16
- package/DEPRECATED_useLexicalRichText.dev.js +47 -24
- package/DEPRECATED_useLexicalRichText.prod.js +27 -27
- package/LexicalAutoFormatterPlugin.dev.js +142 -55
- package/LexicalAutoFormatterPlugin.prod.js +19 -17
- package/LexicalAutoLinkPlugin.prod.js +4 -4
- package/LexicalBootstrapPlugin.dev.js +0 -2
- package/LexicalBootstrapPlugin.prod.js +2 -2
- package/LexicalCharacterLimitPlugin.dev.js +1 -2
- package/LexicalCharacterLimitPlugin.prod.js +3 -3
- package/LexicalCollaborationPlugin.dev.js +11 -26
- package/LexicalCollaborationPlugin.prod.js +7 -8
- package/LexicalComposer.prod.js +1 -1
- package/LexicalComposerContext.prod.js +1 -1
- package/LexicalContentEditable.prod.js +1 -1
- package/LexicalHashtagPlugin.prod.js +1 -1
- package/LexicalHistoryPlugin.dev.js +17 -14
- package/LexicalHistoryPlugin.prod.js +6 -6
- package/LexicalHorizontalRuleNode.dev.js +66 -0
- package/LexicalHorizontalRuleNode.js +9 -0
- package/LexicalHorizontalRuleNode.prod.js +8 -0
- package/LexicalLinkPlugin.dev.js +0 -1
- package/LexicalLinkPlugin.prod.js +3 -3
- package/LexicalListPlugin.prod.js +1 -1
- package/LexicalNestedComposer.prod.js +1 -1
- package/LexicalOnChangePlugin.prod.js +1 -1
- package/LexicalPlainTextPlugin.dev.js +29 -9
- package/LexicalPlainTextPlugin.prod.js +12 -11
- package/LexicalRichTextPlugin.dev.js +30 -10
- package/LexicalRichTextPlugin.prod.js +16 -16
- package/LexicalTablePlugin.dev.js +20 -38
- package/LexicalTablePlugin.prod.js +3 -3
- package/LexicalTreeView.prod.js +1 -1
- package/package.json +5 -4
- package/useLexicalDecoratorMap.prod.js +1 -1
- package/useLexicalIsTextContentEmpty.prod.js +1 -1
- package/withSubscriptions.prod.js +1 -1
- package/LexicalHorizontalRulePlugin.dev.js +0 -51
- package/LexicalHorizontalRulePlugin.js +0 -9
- 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
|
-
|
|
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
|
-
|
|
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
|
|
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 (
|
|
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
|
-
|
|
156
|
-
|
|
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
|
-
|
|
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
|
|
206
|
+
function getMatchResultContextWithRegEx(textToSearch, matchMustAppearAtStartOfString, matchMustAppearAtEndOfString, regEx) {
|
|
179
207
|
const matchResultContext = {
|
|
180
|
-
|
|
181
|
-
|
|
208
|
+
offsetInJoinedTextForCollapsedSelection: 0,
|
|
209
|
+
regExCaptureGroups: []
|
|
182
210
|
};
|
|
183
211
|
const regExMatches = textToSearch.match(regEx);
|
|
184
212
|
|
|
185
|
-
if (regExMatches !== null && regExMatches.length > 0 &&
|
|
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
|
|
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
|
|
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(
|
|
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 (
|
|
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
|
|
334
|
-
if (autoFormatCriteria.requiresParagraphStart) {
|
|
335
|
-
transformTextNodeForParagraphs(scanningContext
|
|
373
|
+
function transformTextNodeForAutoFormatCriteria(scanningContext) {
|
|
374
|
+
if (scanningContext.autoFormatCriteria.requiresParagraphStart) {
|
|
375
|
+
transformTextNodeForParagraphs(scanningContext);
|
|
336
376
|
} else {
|
|
337
|
-
transformTextNodeForText(scanningContext
|
|
377
|
+
transformTextNodeForText(scanningContext);
|
|
338
378
|
}
|
|
339
379
|
}
|
|
340
380
|
|
|
341
|
-
function transformTextNodeForParagraphs(scanningContext
|
|
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(
|
|
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
|
|
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
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
//
|
|
362
|
-
|
|
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
|
|
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,
|
|
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,
|
|
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
|
|
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(),
|
|
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
|
-
|
|
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
|
|
643
|
+
function findScanningContext(editorState, currentTriggerState, priorTriggerState) {
|
|
564
644
|
if (currentTriggerState == null || priorTriggerState == null) {
|
|
565
|
-
return
|
|
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
|
-
|
|
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
|
|
701
|
+
const editorState = editor.getEditorState();
|
|
702
|
+
const currentTriggerState = getTriggerState(editorState);
|
|
703
|
+
const scanningContext = currentTriggerState == null ? null : findScanningContext(editorState, currentTriggerState, priorTriggerState);
|
|
617
704
|
|
|
618
|
-
if (
|
|
619
|
-
updateAutoFormatting(editor,
|
|
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
|
-
|
|
8
|
-
function
|
|
9
|
-
const
|
|
10
|
-
{...
|
|
11
|
-
function
|
|
12
|
-
function
|
|
13
|
-
function
|
|
14
|
-
(
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
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: '
|
|
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
|
-
|
|
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("
|
|
14
|
-
g);a.update(()=>{
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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)};
|