@lexical/react 0.1.10 → 0.1.11
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_useLexicalAutoFormatter.dev.js +69 -28
- package/DEPRECATED_useLexicalAutoFormatter.prod.js +19 -18
- package/DEPRECATED_useLexicalCharacterLimit.dev.js +20 -17
- package/DEPRECATED_useLexicalCharacterLimit.prod.js +8 -8
- package/DEPRECATED_useLexicalList.dev.js +6 -0
- package/DEPRECATED_useLexicalList.prod.js +1 -1
- package/DEPRECATED_useLexicalPlainText.dev.js +61 -58
- package/DEPRECATED_useLexicalPlainText.prod.js +15 -15
- package/DEPRECATED_useLexicalRichText.dev.js +64 -61
- package/DEPRECATED_useLexicalRichText.prod.js +24 -25
- package/LexicalAutoFormatterPlugin.dev.js +69 -28
- package/LexicalAutoFormatterPlugin.js.flow +10 -0
- package/LexicalAutoFormatterPlugin.prod.js +20 -19
- package/LexicalAutoLinkPlugin.js.flow +23 -0
- package/LexicalCharacterLimitPlugin.dev.js +20 -17
- package/LexicalCharacterLimitPlugin.js.flow +12 -0
- package/LexicalCharacterLimitPlugin.prod.js +9 -8
- package/LexicalClearEditorPlugin.dev.js +52 -0
- package/LexicalClearEditorPlugin.js +9 -0
- package/LexicalClearEditorPlugin.js.flow +14 -0
- package/LexicalClearEditorPlugin.prod.js +7 -0
- package/LexicalCollaborationPlugin.dev.js +21 -11
- package/LexicalCollaborationPlugin.js.flow +55 -0
- package/LexicalCollaborationPlugin.prod.js +7 -7
- package/LexicalComposer.dev.js +7 -0
- package/LexicalComposer.js.flow +23 -0
- package/LexicalComposer.prod.js +3 -2
- package/LexicalComposerContext.js.flow +27 -0
- package/LexicalContentEditable.dev.js +14 -8
- package/LexicalContentEditable.js.flow +35 -0
- package/LexicalContentEditable.prod.js +3 -3
- package/LexicalHashtagPlugin.js.flow +20 -0
- package/LexicalHistoryPlugin.js.flow +34 -0
- package/LexicalHorizontalRuleNode.js.flow +25 -0
- package/LexicalLinkPlugin.js.flow +10 -0
- package/LexicalListPlugin.dev.js +6 -0
- package/LexicalListPlugin.js.flow +10 -0
- package/LexicalListPlugin.prod.js +2 -2
- package/LexicalNestedComposer.js.flow +21 -0
- package/LexicalOnChangePlugin.js.flow +14 -0
- package/LexicalPlainTextPlugin.dev.js +64 -60
- package/LexicalPlainTextPlugin.js.flow +18 -0
- package/LexicalPlainTextPlugin.prod.js +12 -12
- package/LexicalRichTextPlugin.dev.js +65 -61
- package/LexicalRichTextPlugin.js.flow +18 -0
- package/LexicalRichTextPlugin.prod.js +19 -20
- package/LexicalTablePlugin.dev.js +22 -0
- package/LexicalTablePlugin.js.flow +10 -0
- package/LexicalTablePlugin.prod.js +4 -3
- package/LexicalTreeView.js.flow +19 -0
- package/README.md +0 -1
- package/package.json +5 -5
- package/useLexicalDecoratorMap.js.flow +16 -0
- package/useLexicalIsTextContentEmpty.js.flow +15 -0
- package/useLexicalNodeSelection.js.flow +14 -0
- package/withSubscriptions.js.flow +13 -0
- package/LexicalBootstrapPlugin.dev.js +0 -122
- package/LexicalBootstrapPlugin.js +0 -9
- package/LexicalBootstrapPlugin.prod.js +0 -8
|
@@ -542,55 +542,6 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
|
|
|
542
542
|
$moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
|
|
543
543
|
}
|
|
544
544
|
|
|
545
|
-
/**
|
|
546
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
547
|
-
*
|
|
548
|
-
* This source code is licensed under the MIT license found in the
|
|
549
|
-
* LICENSE file in the root directory of this source tree.
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
*/
|
|
553
|
-
function resolveElement(element, isBackward, focusOffset) {
|
|
554
|
-
const parent = element.getParent();
|
|
555
|
-
let offset = focusOffset;
|
|
556
|
-
let block = element;
|
|
557
|
-
|
|
558
|
-
if (parent !== null) {
|
|
559
|
-
if (isBackward && focusOffset === 0) {
|
|
560
|
-
offset = block.getIndexWithinParent();
|
|
561
|
-
block = parent;
|
|
562
|
-
} else if (!isBackward && focusOffset === block.getChildrenSize()) {
|
|
563
|
-
offset = block.getIndexWithinParent() + 1;
|
|
564
|
-
block = parent;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
return block.getChildAtIndex(isBackward ? offset - 1 : offset);
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
function getPossibleDecoratorNode(focus, isBackward) {
|
|
572
|
-
const focusOffset = focus.offset;
|
|
573
|
-
|
|
574
|
-
if (focus.type === 'element') {
|
|
575
|
-
const block = focus.getNode();
|
|
576
|
-
return resolveElement(block, isBackward, focusOffset);
|
|
577
|
-
} else {
|
|
578
|
-
const focusNode = focus.getNode();
|
|
579
|
-
|
|
580
|
-
if (isBackward && focusOffset === 0 || !isBackward && focusOffset === focusNode.getTextContentSize()) {
|
|
581
|
-
const possibleNode = isBackward ? focusNode.getPreviousSibling() : focusNode.getNextSibling();
|
|
582
|
-
|
|
583
|
-
if (possibleNode === null) {
|
|
584
|
-
return resolveElement(focusNode.getParentOrThrow(), isBackward, focusNode.getIndexWithinParent() + (isBackward ? 0 : 1));
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
return possibleNode;
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
return null;
|
|
592
|
-
}
|
|
593
|
-
|
|
594
545
|
/**
|
|
595
546
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
596
547
|
*
|
|
@@ -776,7 +727,7 @@ function $insertDataTransferForPlainText(dataTransfer, selection) {
|
|
|
776
727
|
}
|
|
777
728
|
}
|
|
778
729
|
function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
|
|
779
|
-
const possibleNode =
|
|
730
|
+
const possibleNode = lexical.$getDecoratorNode(selection.focus, isBackward);
|
|
780
731
|
return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
|
|
781
732
|
}
|
|
782
733
|
function onPasteForRichText(event, editor) {
|
|
@@ -834,6 +785,62 @@ function onCopyForRichText(event, editor) {
|
|
|
834
785
|
});
|
|
835
786
|
}
|
|
836
787
|
|
|
788
|
+
/**
|
|
789
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
790
|
+
*
|
|
791
|
+
* This source code is licensed under the MIT license found in the
|
|
792
|
+
* LICENSE file in the root directory of this source tree.
|
|
793
|
+
*
|
|
794
|
+
*
|
|
795
|
+
*/
|
|
796
|
+
// Convoluted logic to make this work with Flow. Order matters.
|
|
797
|
+
const options = {
|
|
798
|
+
tag: 'history-merge'
|
|
799
|
+
};
|
|
800
|
+
const setEditorOptions = options;
|
|
801
|
+
const updateOptions = options;
|
|
802
|
+
function initializeEditor(editor, initialEditorState) {
|
|
803
|
+
if (initialEditorState === null) {
|
|
804
|
+
return;
|
|
805
|
+
} else if (initialEditorState === undefined) {
|
|
806
|
+
editor.update(() => {
|
|
807
|
+
const root = lexical.$getRoot();
|
|
808
|
+
const firstChild = root.getFirstChild();
|
|
809
|
+
|
|
810
|
+
if (firstChild === null) {
|
|
811
|
+
const paragraph = lexical.$createParagraphNode();
|
|
812
|
+
root.append(paragraph);
|
|
813
|
+
const activeElement = document.activeElement;
|
|
814
|
+
|
|
815
|
+
if (lexical.$getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement()) {
|
|
816
|
+
paragraph.select();
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
}, updateOptions);
|
|
820
|
+
} else if (initialEditorState !== null) {
|
|
821
|
+
switch (typeof initialEditorState) {
|
|
822
|
+
case 'string':
|
|
823
|
+
{
|
|
824
|
+
const parsedEditorState = editor.parseEditorState(initialEditorState);
|
|
825
|
+
editor.setEditorState(parsedEditorState, setEditorOptions);
|
|
826
|
+
break;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
case 'object':
|
|
830
|
+
{
|
|
831
|
+
editor.setEditorState(initialEditorState, setEditorOptions);
|
|
832
|
+
break;
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
case 'function':
|
|
836
|
+
{
|
|
837
|
+
editor.update(initialEditorState, updateOptions);
|
|
838
|
+
break;
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
|
|
837
844
|
/**
|
|
838
845
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
839
846
|
*
|
|
@@ -930,8 +937,8 @@ function useLexicalDragonSupport(editor) {
|
|
|
930
937
|
*
|
|
931
938
|
*
|
|
932
939
|
*/
|
|
933
|
-
function useRichTextSetup(editor) {
|
|
934
|
-
react.
|
|
940
|
+
function useRichTextSetup(editor, initialEditorState) {
|
|
941
|
+
react.useLayoutEffect(() => {
|
|
935
942
|
const removeListener = editor.addListener('command', (type, payload) => {
|
|
936
943
|
const selection = lexical.$getSelection();
|
|
937
944
|
|
|
@@ -1170,13 +1177,9 @@ function useRichTextSetup(editor) {
|
|
|
1170
1177
|
|
|
1171
1178
|
return false;
|
|
1172
1179
|
}, 0);
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
console.warn('bootstrapEditor command was not handled. Did you forget to add <BootstrapPlugin />?');
|
|
1177
|
-
}
|
|
1178
|
-
|
|
1179
|
-
return removeListener;
|
|
1180
|
+
initializeEditor(editor, initialEditorState);
|
|
1181
|
+
return removeListener; // We only do this for init
|
|
1182
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1180
1183
|
}, [editor]);
|
|
1181
1184
|
useLexicalDragonSupport(editor);
|
|
1182
1185
|
}
|
|
@@ -1189,8 +1192,8 @@ function useRichTextSetup(editor) {
|
|
|
1189
1192
|
*
|
|
1190
1193
|
*
|
|
1191
1194
|
*/
|
|
1192
|
-
function useLexicalRichText(editor, externalHistoryState) {
|
|
1193
|
-
useRichTextSetup(editor);
|
|
1195
|
+
function useLexicalRichText(editor, externalHistoryState, initialEditorState) {
|
|
1196
|
+
useRichTextSetup(editor, initialEditorState);
|
|
1194
1197
|
useLexicalHistory(editor, externalHistoryState);
|
|
1195
1198
|
}
|
|
1196
1199
|
|
|
@@ -5,28 +5,27 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
var k=require("@lexical/react/withSubscriptions"),w=require("lexical"),y=require("react");
|
|
8
|
-
function z(a,
|
|
9
|
-
g=
|
|
10
|
-
function A(a,
|
|
11
|
-
function B(a,
|
|
12
|
-
{tag:"historic"})}return!0;case "redo":return g=
|
|
13
|
-
r=null===m?null:m.editorState;if(null===m||g!==r){l=
|
|
14
|
-
function D(a){a=a.getLatest();const
|
|
15
|
-
function E(a,
|
|
16
|
-
|
|
17
|
-
function H(a,
|
|
18
|
-
function I(a,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
function
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
b
|
|
31
|
-
|
|
32
|
-
!0;case "copy":return N(b,a),!0;case "cut":return M(b,a),!0;case "paste":return L(b,a),!0;case "drop":case "dragstart":return b.preventDefault(),!0}return!1},0);a.execCommand("bootstrapEditor");return d},[a]);P(a)}module.exports=function(a,d){Q(a);C(a,d)};
|
|
8
|
+
function z(a,e,f,c,d){if(null===a||0===f.size&&0===c.size)return 0;var b=e._selection,g=a._selection;if(d)return 1;if(!(w.$isRangeSelection(b)&&w.$isRangeSelection(g)&&g.isCollapsed()&&b.isCollapsed()))return 0;var h=Array.from(f);c=Array.from(c);f=e._nodeMap;d=[];for(var l=0;l<h.length;l++){const n=f.get(h[l]);void 0!==n&&d.push(n)}for(h=0;h<c.length;h++)c[h][1]&&(l=f.get(c[h][0]),void 0===l||w.$isRootNode(l)||d.push(l));if(0===d.length)return 0;if(1<d.length)return c=e._nodeMap,e=c.get(b.anchor.key),
|
|
9
|
+
g=c.get(g.anchor.key),e&&g&&!a._nodeMap.has(e.__key)&&w.$isTextNode(e)&&1===e.__text.length&&1===b.anchor.offset?2:0;e=d[0];a=a._nodeMap.get(e.__key);if(!w.$isTextNode(a)||!w.$isTextNode(e)||a.__mode!==e.__mode)return 0;a=a.__text;e=e.__text;if(a===e)return 0;b=b.anchor;g=g.anchor;if(b.key!==g.key||"text"!==b.type)return 0;b=b.offset;g=g.offset;a=e.length-a.length;return 1===a&&g===b-1?2:-1===a&&g===b+1?3:-1===a&&g===b?4:0}
|
|
10
|
+
function A(a,e){let f=Date.now(),c=0;return(d,b,g,h,l,n)=>{const p=Date.now();if(n.has("historic"))return c=0,f=p,2;const m=z(d,b,h,l,a.isComposing()),t=(()=>{const q=n.has("history-push");if(!q&&n.has("history-merge"))return 0;if(null===d)return 1;var r=b._selection;const u=d._selection;if(!(0<h.size||0<l.size))return null===u&&null!==r?0:2;r=null===g||g.editor===a;return!1===q&&0!==m&&m===c&&p<f+e&&r?0:1})();f=p;c=m;return t}}
|
|
11
|
+
function B(a,e,f=1E3){const c=y.useMemo(()=>e||{current:null,redoStack:[],undoStack:[]},[e]),d=y.useCallback(()=>{c.undoStack=[];c.redoStack=[];c.current=null},[c]);y.useEffect(()=>{const b=A(a,f);return k(a.addListener("command",g=>{switch(g){case "undo":g=c.redoStack;var h=c.undoStack;if(0!==h.length){var l=c.current;const n=h.pop();null!==l&&(g.push(l),a.execCommand("canRedo",!0));0===h.length&&a.execCommand("canUndo",!1);c.current=n;n.editor.setEditorState(n.editorState.clone(n.undoSelection),
|
|
12
|
+
{tag:"historic"})}return!0;case "redo":return g=c.redoStack,h=c.undoStack,0!==g.length&&(l=c.current,null!==l&&(h.push(l),a.execCommand("canUndo",!0)),h=g.pop(),0===g.length&&a.execCommand("canRedo",!1),c.current=h,h.editor.setEditorState(h.editorState,{tag:"historic"})),!0;case "clearEditor":return d(),!1;case "clearHistory":return d(),!0;default:return!1}},0),a.addListener("update",({editorState:g,prevEditorState:h,dirtyLeaves:l,dirtyElements:n,tags:p})=>{const m=c.current,t=c.redoStack,q=c.undoStack,
|
|
13
|
+
r=null===m?null:m.editorState;if(null===m||g!==r){l=b(h,g,m,l,n,p);if(1===l)0!==t.length&&(c.redoStack=[]),null!==m&&(q.push({...m,undoSelection:h.read(w.$getSelection)}),a.execCommand("canUndo",!0));else if(2===l)return;c.current={editor:a,editorState:g}}}))},[d,f,a,c])}function C(a,e,f=1E3){return B(a,e,f)}
|
|
14
|
+
function D(a){a=a.getLatest();const e=a.constructor.clone(a);e.__parent=a.__parent;w.$isElementNode(a)&&w.$isElementNode(e)?(e.__children=Array.from(a.__children),e.__format=a.__format,e.__indent=a.__indent,e.__dir=a.__dir):w.$isTextNode(a)&&w.$isTextNode(e)?(e.__format=a.__format,e.__style=a.__style,e.__mode=a.__mode,e.__detail=a.__detail):w.$isDecoratorNode(a)&&w.$isDecoratorNode(e)&&(e.__state=a.__state);return e}
|
|
15
|
+
function E(a,e,f,c,d){for(var b=e;null!==a;){for(e=a.getParent();null!==e&&e.excludeFromCopy();)e=e.getParent();if(null===e)break;if(!w.$isElementNode(a)||!a.excludeFromCopy()){const g=a.getKey();let h=d.get(g);const l=void 0===h;l&&(h=D(a),d.set(g,h));!w.$isTextNode(h)||h.isSegmented()||h.isToken()?w.$isElementNode(h)&&(h.__children=h.__children.slice(f?b:0,f?void 0:b+1)):h.__text=h.__text.slice(f?b:0,f?void 0:b);if(w.$isRootNode(e)){l&&c.push(g);break}}b=d.get(e.getKey());b=w.$isElementNode(b)?
|
|
16
|
+
b.__children.indexOf(a.getKey()):a.getIndexWithinParent();a=e}}function F(a){a=a.anchor.getNode();return"rtl"===(w.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function G(a,e){const {nodeName:f}=a;e=e._htmlConversions.get(f.toLowerCase());let c=null;void 0!==e&&e.forEach(d=>{d=d(a);null!==d&&(null===c||c.priority<d.priority)&&(c=d)});return null!==c?c.conversion:null}
|
|
17
|
+
function H(a,e,f=new Map){let c=[],d=null;var b=G(a,e),g=b?b(a):null;b=null;if(null!==g){b=g.after;d=g.node;if(null!==d){c.push(d);var h=Array.from(f.values());for(let l=0;l<h.length;l++)h[l](d)}null!=g.forChild&&f.set(a.nodeName,g.forChild)}a=a.childNodes;g=[];for(h=0;h<a.length;h++)g.push(...H(a[h],e,f));null!=b&&(g=b(g));null==d?c=c.concat(g):w.$isElementNode(d)&&d.append(...g);return c}
|
|
18
|
+
function I(a,e,f){var c=a.getData("application/x-lexical-editor");if(c){var d=f._config.namespace;try{const l=JSON.parse(c);if(l.namespace===d){const {range:n,nodeMap:p}=l.state;var b=new Map(p);c=[];for(d=0;d<n.length;d++){var g=b.get(n[d]);if(void 0!==g){var h=w.$createNodeFromParse(g,b);c.push(h)}}e.insertNodes(c);return}}catch(l){}}if(b=a.getData("text/html")){b=(new DOMParser).parseFromString(b,"text/html");a=[];b=b.body?Array.from(b.body.childNodes):[];g=b.length;for(h=0;h<g;h++)c=H(b[h],f),
|
|
19
|
+
null!==c&&(a=a.concat(c));f=a;a=[];b=null;for(g=0;g<f.length;g++)h=f[g],!w.$isElementNode(h)||h.isInline()?(null===b&&(b=w.$createParagraphNode(),a.push(b)),null!==b&&b.append(h)):(a.push(h),b=null);e.insertNodes(a)}else f=a.getData("text/plain"),null!=f&&e.insertRawText(f)}function J(a,e){a=w.$getDecoratorNode(a.focus,e);return w.$isDecoratorNode(a)&&!a.isIsolated()}
|
|
20
|
+
function K(a,e){a.preventDefault();e.update(()=>{const f=w.$getSelection(),c=a.clipboardData;null!=c&&w.$isRangeSelection(f)&&I(c,f,e)})}function L(a,e){M(a,e);e.update(()=>{const f=w.$getSelection();w.$isRangeSelection(f)&&f.removeText()})}
|
|
21
|
+
function M(a,e){a.preventDefault();e.update(()=>{const f=a.clipboardData;var c=w.$getSelection();if(null!==c&&null!=f){var d=window.getSelection();if(!d.isCollapsed){var b=d.getRangeAt(0);b&&(d=document.createElement("div"),b=b.cloneContents(),d.appendChild(b),f.setData("text/html",d.innerHTML));f.setData("text/plain",c.getTextContent());d=e._config.namespace;b=f.setData;var g=JSON,h=g.stringify;{if(!w.$isRangeSelection(c))throw Error("Minified Lexical error #68; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");
|
|
22
|
+
var l=c.anchor,n=c.focus;var p=l.getCharacterOffset();const x=n.getCharacterOffset();var m=l.getNode(),t=n.getNode(),q=m.getParentOrThrow();if(m===t&&w.$isTextNode(m)&&(q.canBeEmpty()||1<q.getChildrenSize()))c=D(m),m=x>p,c.__text=c.__text.slice(m?p:x,m?x:p),p=c.getKey(),p={nodeMap:[[p,c]],range:[p]};else if(c=c.getNodes(),0===c.length)p={nodeMap:[],range:[]};else{m=c.length;t=c[0];q=t.getParent();if(null!==q&&(!q.canBeEmpty()||w.$isRootNode(q))){var r=q.__children;if(r.length===m){var u=!0;for(var v=
|
|
23
|
+
0;v<r.length;v++)if(r[v]!==c[v].__key){u=!1;break}u&&(m++,c.push(q))}}q=c[m-1];l=l.isBefore(n);n=new Map;r=[];E(t,l?p:x,!0,r,n);for(t=0;t<m;t++)if(u=c[t],v=u.getKey(),!(n.has(v)||w.$isElementNode(u)&&u.excludeFromCopy())){const O=D(u);w.$isRootNode(u.getParent())&&r.push(u.getKey());n.set(v,O)}E(q,l?x:p,!1,r,n);p={nodeMap:Array.from(n.entries()),range:r}}}b.call(f,"application/x-lexical-editor",h.call(g,{namespace:d,state:p}))}}})}const N={tag:"history-merge"};
|
|
24
|
+
function P(a,e){if(null!==e)if(void 0===e)a.update(()=>{var f=w.$getRoot();if(null===f.getFirstChild()){const c=w.$createParagraphNode();f.append(c);f=document.activeElement;(null!==w.$getSelection()||null!==f&&f===a.getRootElement())&&c.select()}},N);else if(null!==e)switch(typeof e){case "string":e=a.parseEditorState(e);a.setEditorState(e,N);break;case "object":a.setEditorState(e,N);break;case "function":a.update(e,N)}}
|
|
25
|
+
function Q(a){y.useEffect(()=>{const e=f=>{var c=a.getRootElement();if(document.activeElement===c&&(c=f.data,"string"===typeof c)){try{var d=JSON.parse(c)}catch(b){return}if(d&&"nuanria_messaging"===d.protocol&&"request"===d.type&&(d=d.payload)&&"makeChanges"===d.functionId&&(d=d.args)){const [b,g,h,l,n]=d;a.update(()=>{const p=w.$getSelection();if(w.$isRangeSelection(p)){var m=p.anchor;let t=m.getNode(),q=0,r=0;w.$isTextNode(t)&&0<=b&&0<=g&&(q=b,r=b+g,p.setTextNodeRange(t,q,t,r));if(q!==r||""!==
|
|
26
|
+
h)p.insertRawText(h),t=m.getNode();w.$isTextNode(t)&&(q=l,r=l+n,m=t.getTextContentSize(),q=q>m?m:q,r=r>m?m:r,p.setTextNodeRange(t,q,t,r));f.stopImmediatePropagation()}})}}};window.addEventListener("message",e,!0);return()=>{window.removeEventListener("message",e,!0)}},[a])}
|
|
27
|
+
function R(a,e){y.useLayoutEffect(()=>{const f=a.addListener("command",(c,d)=>{var b=w.$getSelection();if("click"===c&&w.$isNodeSelection(b))return b.clear(),!0;if(!w.$isRangeSelection(b))return!1;switch(c){case "deleteCharacter":return b.deleteCharacter(d),!0;case "deleteWord":return b.deleteWord(d),!0;case "deleteLine":return b.deleteLine(d),!0;case "insertText":return"string"===typeof d?b.insertText(d):(c=d.dataTransfer,null!=c?I(c,b,a):(d=d.data)&&b.insertText(d)),!0;case "removeText":return b.removeText(),
|
|
28
|
+
!0;case "formatText":return b.formatText(d),!0;case "formatElement":return b=b.anchor.getNode(),(w.$isElementNode(b)?b:b.getParentOrThrow()).setFormat(d),!0;case "insertLineBreak":return b.insertLineBreak(d),!0;case "insertParagraph":return b.insertParagraph(),!0;case "indentContent":return b=b.anchor,b="element"===b.type?b.getNode():b.getNode().getParentOrThrow(),b.canInsertTab()?a.execCommand("insertText","\t"):10!==b.getIndent()&&b.setIndent(b.getIndent()+1),!0;case "outdentContent":return b=b.anchor,
|
|
29
|
+
d=b.getNode(),c="element"===b.type?b.getNode():b.getNode().getParentOrThrow(),c.canInsertTab()?"\t"===d.getTextContent()[b.offset-1]&&a.execCommand("deleteCharacter",!0):0!==c.getIndent()&&c.setIndent(c.getIndent()-1),!0;case "keyArrowLeft":c=d.shiftKey;if(J(b,!0))return d.preventDefault(),d=c,c=F(b),b.modify(d?"extend":"move",!c,"character"),!0;break;case "keyArrowRight":c=d.shiftKey;if(J(b,!1))return d.preventDefault(),d=c,c=F(b),b.modify(d?"extend":"move",c,"character"),!0;break;case "keyBackspace":return d.preventDefault(),
|
|
30
|
+
{anchor:d}=b,b.isCollapsed()&&0===d.offset&&0<("element"===d.type?d.getNode():d.getNode().getParentOrThrow()).getIndent()?a.execCommand("outdentContent"):a.execCommand("deleteCharacter",!0);case "keyDelete":return d.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return d.preventDefault(),d.shiftKey?a.execCommand("insertLineBreak"):a.execCommand("insertParagraph");case "keyTab":return d.preventDefault(),a.execCommand(d.shiftKey?"outdentContent":"indentContent");case "keyEscape":return a.blur(),
|
|
31
|
+
!0;case "copy":return M(d,a),!0;case "cut":return L(d,a),!0;case "paste":return K(d,a),!0;case "drop":case "dragstart":return d.preventDefault(),!0}return!1},0);P(a,e);return f},[a]);Q(a)}module.exports=function(a,e,f){R(a,f);C(a,e)};
|
|
@@ -171,14 +171,33 @@ const markdownHorizontalRuleUsingDashes = { ...paragraphStartBase,
|
|
|
171
171
|
nodeTransformationKind: 'horizontalRule',
|
|
172
172
|
regEx: /(?:--- )/
|
|
173
173
|
};
|
|
174
|
+
const markdownItalic = { ...autoFormatBase,
|
|
175
|
+
nodeTransformationKind: 'italic',
|
|
176
|
+
regEx: /(\*)(\s*\b)([^\*]*)(\b\s*)(\*\s)$/
|
|
177
|
+
};
|
|
174
178
|
const markdownBold = { ...autoFormatBase,
|
|
175
|
-
nodeTransformationKind: '
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
179
|
+
nodeTransformationKind: 'bold',
|
|
180
|
+
regEx: /(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*\s)$/
|
|
181
|
+
};
|
|
182
|
+
const markdownBoldWithUnderlines = { ...autoFormatBase,
|
|
183
|
+
nodeTransformationKind: 'bold',
|
|
184
|
+
regEx: /(__)(\s*)([^__]*)(\s*)(__\s)$/
|
|
185
|
+
};
|
|
186
|
+
const markdownBoldItalic = { ...autoFormatBase,
|
|
187
|
+
nodeTransformationKind: 'bold_italic',
|
|
188
|
+
regEx: /(\*\*\*)(\s*\b)([^\*\*\*]*)(\b\s*)(\*\*\*\s)$/
|
|
189
|
+
}; // Markdown does not support underline, but we can allow folks to use
|
|
190
|
+
// the HTML tags for underline.
|
|
191
|
+
|
|
192
|
+
const fakeMarkdownUnderline = { ...autoFormatBase,
|
|
193
|
+
nodeTransformationKind: 'underline',
|
|
194
|
+
regEx: /(\<u\>)(\s*\b)([^\<]*)(\b\s*)(\<\/u\>\s)$/
|
|
180
195
|
};
|
|
181
|
-
const
|
|
196
|
+
const markdownStrikethrough = { ...autoFormatBase,
|
|
197
|
+
nodeTransformationKind: 'strikethrough',
|
|
198
|
+
regEx: /(~~)(\s*\b)([^~~]*)(\b\s*)(~~\s)$/
|
|
199
|
+
};
|
|
200
|
+
const allAutoFormatCriteriaForTextNodes = [markdownBoldItalic, markdownItalic, markdownBold, markdownBoldWithUnderlines, fakeMarkdownUnderline, markdownStrikethrough];
|
|
182
201
|
const allAutoFormatCriteria = [markdownHeader1, markdownHeader2, markdownHeader3, markdownBlockQuote, markdownUnorderedListDash, markdownUnorderedListAsterisk, markdownOrderedList, markdownCodeBlock, markdownHorizontalRule, markdownHorizontalRuleUsingDashes, ...allAutoFormatCriteriaForTextNodes];
|
|
183
202
|
function getAllAutoFormatCriteriaForTextNodes() {
|
|
184
203
|
return allAutoFormatCriteriaForTextNodes;
|
|
@@ -259,17 +278,14 @@ function getMatchResultContextForText(autoFormatCriteria, scanningContext) {
|
|
|
259
278
|
// Lazy calculate the text to search.
|
|
260
279
|
scanningContext.joinedText = $joinTextNodesInElementNode(parentNode, SEPARATOR_BETWEEN_TEXT_AND_NON_TEXT_NODES, scanningContext.textNodeWithOffset);
|
|
261
280
|
}
|
|
262
|
-
|
|
263
|
-
return getMatchResultContextWithRegEx(scanningContext.joinedText, false, true, autoFormatCriteria.regEx);
|
|
264
281
|
} else {
|
|
265
282
|
{
|
|
266
283
|
throw Error(`Expected node ${parentNode.__key} to to be a ElementNode.`);
|
|
267
284
|
}
|
|
268
285
|
}
|
|
269
|
-
}
|
|
270
|
-
|
|
286
|
+
}
|
|
271
287
|
|
|
272
|
-
return
|
|
288
|
+
return getMatchResultContextWithRegEx(scanningContext.joinedText, false, true, autoFormatCriteria.regEx);
|
|
273
289
|
}
|
|
274
290
|
|
|
275
291
|
function getMatchResultContextForCriteria(autoFormatCriteria, scanningContext) {
|
|
@@ -391,28 +407,50 @@ function transformTextNodeForParagraphs(scanningContext) {
|
|
|
391
407
|
}
|
|
392
408
|
}
|
|
393
409
|
|
|
410
|
+
function getTextFormatType(nodeTransformationKind) {
|
|
411
|
+
switch (nodeTransformationKind) {
|
|
412
|
+
case 'italic':
|
|
413
|
+
case 'bold':
|
|
414
|
+
case 'underline':
|
|
415
|
+
case 'strikethrough':
|
|
416
|
+
return [nodeTransformationKind];
|
|
417
|
+
|
|
418
|
+
case 'bold_italic':
|
|
419
|
+
{
|
|
420
|
+
return ['bold', 'italic'];
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
return null;
|
|
425
|
+
}
|
|
426
|
+
|
|
394
427
|
function transformTextNodeForText(scanningContext) {
|
|
395
428
|
const autoFormatCriteria = scanningContext.autoFormatCriteria;
|
|
396
429
|
const matchResultContext = scanningContext.matchResultContext;
|
|
397
430
|
|
|
398
431
|
if (autoFormatCriteria.nodeTransformationKind != null) {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
break;
|
|
407
|
-
}
|
|
432
|
+
if (matchResultContext.regExCaptureGroups.length !== 6) {
|
|
433
|
+
// For BIUS and other formatts which have a pattern + text + pattern,
|
|
434
|
+
// the expected reg ex pattern should have 6 groups.
|
|
435
|
+
// If it does not, then break and fail silently.
|
|
436
|
+
// e2e tests validate the regEx pattern.
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
408
439
|
|
|
409
|
-
|
|
440
|
+
const formatting = getTextFormatType(autoFormatCriteria.nodeTransformationKind);
|
|
410
441
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
442
|
+
if (formatting != null) {
|
|
443
|
+
const captureGroupsToDelete = [1, 5];
|
|
444
|
+
const formatCaptureGroup = 3;
|
|
445
|
+
matchResultContext.regExCaptureGroups = getCaptureGroupsByResolvingAllDetails(scanningContext);
|
|
446
|
+
|
|
447
|
+
if (captureGroupsToDelete.length > 0) {
|
|
448
|
+
// Remove unwanted text in reg ex pattern.
|
|
449
|
+
removeTextInCaptureGroups(captureGroupsToDelete, matchResultContext);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
formatTextInCaptureGroupIndex(formatting, formatCaptureGroup, matchResultContext);
|
|
453
|
+
makeCollapsedSelectionAtOffsetInJoinedText(matchResultContext.offsetInJoinedTextForCollapsedSelection, matchResultContext.offsetInJoinedTextForCollapsedSelection + 1, scanningContext.textNodeWithOffset.node.getParentOrThrow());
|
|
416
454
|
}
|
|
417
455
|
}
|
|
418
456
|
} // Some Capture Group Details were left lazily unresolved as their calculation
|
|
@@ -516,7 +554,7 @@ function shiftCaptureGroupOffsets(delta, applyAtOrAfterOffset, node, startingCap
|
|
|
516
554
|
}
|
|
517
555
|
}
|
|
518
556
|
|
|
519
|
-
function formatTextInCaptureGroupIndex(
|
|
557
|
+
function formatTextInCaptureGroupIndex(formatTypes, captureGroupIndex, matchResultContext) {
|
|
520
558
|
const regExCaptureGroups = matchResultContext.regExCaptureGroups;
|
|
521
559
|
const regExCaptureGroupsCount = regExCaptureGroups.length;
|
|
522
560
|
|
|
@@ -536,7 +574,10 @@ function formatTextInCaptureGroupIndex(formatType, captureGroupIndex, matchResul
|
|
|
536
574
|
const currentSelection = lexical.$getSelection();
|
|
537
575
|
|
|
538
576
|
if (lexical.$isRangeSelection(currentSelection)) {
|
|
539
|
-
|
|
577
|
+
for (let i = 0; i < formatTypes.length; i++) {
|
|
578
|
+
currentSelection.formatText(formatTypes[i]);
|
|
579
|
+
}
|
|
580
|
+
|
|
540
581
|
const finalSelection = lexical.$createRangeSelection();
|
|
541
582
|
finalSelection.anchor.set(focusTextNodeWithOffset.node.getKey(), focusTextNodeWithOffset.offset + 1, 'text');
|
|
542
583
|
finalSelection.focus.set(focusTextNodeWithOffset.node.getKey(), focusTextNodeWithOffset.offset + 1, 'text');
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
declare export default function LexicalAutoFormatterPlugin(): React$Node;
|
|
@@ -4,23 +4,24 @@
|
|
|
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
|
-
var
|
|
8
|
-
function
|
|
9
|
-
const
|
|
10
|
-
regEx:/(
|
|
11
|
-
|
|
12
|
-
function K(g,f,a,b
|
|
13
|
-
function L(g,f){g.
|
|
14
|
-
|
|
15
|
-
a.append(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
d.
|
|
19
|
-
"text"),
|
|
20
|
-
|
|
21
|
-
N
|
|
22
|
-
|
|
7
|
+
var k=require("@lexical/react/LexicalComposerContext"),q=require("@lexical/list"),r=require("lexical"),t=require("lexical/CodeNode"),u=require("react"),x=require("@lexical/react/LexicalHorizontalRuleNode"),y=require("lexical/HeadingNode"),C=require("lexical/QuoteNode");function D(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 E(g,f,a,b){g=g.getChildren();const c=g.length;let d=0,e=!1;for(let p=0;p<c&&!(d>f);++p){const m=g[p],n=r.$isTextNode(m);var h=n?m.getTextContent().length:b;h=d+h;if((!1===e&&d===a||0===d&&d===a||d<a&&a<=h)&&r.$isTextNode(m))return{node:m,offset:a-d};d=h;e=n}return null}
|
|
9
|
+
const F={nodeTransformationKind:null,regEx:/(?:)/,requiresParagraphStart:!1},H={...F,requiresParagraphStart:!0},I=[{...F,nodeTransformationKind:"bold_italic",regEx:/(\*\*\*)(\s*\b)([^\*\*\*]*)(\b\s*)(\*\*\*\s)$/},{...F,nodeTransformationKind:"italic",regEx:/(\*)(\s*\b)([^\*]*)(\b\s*)(\*\s)$/},{...F,nodeTransformationKind:"bold",regEx:/(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*\s)$/},{...F,nodeTransformationKind:"bold",regEx:/(__)(\s*)([^__]*)(\s*)(__\s)$/},{...F,nodeTransformationKind:"underline",regEx:/(<u>)(\s*\b)([^<]*)(\b\s*)(<\/u>\s)$/},
|
|
10
|
+
{...F,nodeTransformationKind:"strikethrough",regEx:/(~~)(\s*\b)([^~~]*)(\b\s*)(~~\s)$/}],J=[{...H,nodeTransformationKind:"paragraphH1",regEx:/(?:# )/},{...H,nodeTransformationKind:"paragraphH2",regEx:/(?:## )/},{...H,nodeTransformationKind:"paragraphH2",regEx:/(?:### )/},{...H,nodeTransformationKind:"paragraphBlockQuote",regEx:/(?:> )/},{...H,nodeTransformationKind:"paragraphUnorderedList",regEx:/(?:- )/},{...H,nodeTransformationKind:"paragraphUnorderedList",regEx:/(?:\* )/},{...H,nodeTransformationKind:"paragraphOrderedList",
|
|
11
|
+
regEx:/^(\d+)\.\s/},{...H,nodeTransformationKind:"paragraphCodeBlock",regEx:/(?:``` )/},{...H,nodeTransformationKind:"horizontalRule",regEx:/(?:\*\*\* )/},{...H,nodeTransformationKind:"horizontalRule",regEx:/(?:--- )/},...I];
|
|
12
|
+
function K(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}
|
|
13
|
+
function L(g,f,a,b,c){c.offsetInJoinedTextForCollapsedSelection+=g;0<c.offsetInJoinedTextForCollapsedSelection||D(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)}}
|
|
14
|
+
function M(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,h=f.matchResultContext;if(null!=e.nodeTransformationKind)switch(e.nodeTransformationKind){case "paragraphH1":a=y.$createHeadingNode("h1");a.append(...d);break;case "paragraphH2":a=
|
|
15
|
+
y.$createHeadingNode("h2");a.append(...d);break;case "paragraphH3":a=y.$createHeadingNode("h3");a.append(...d);break;case "paragraphBlockQuote":a=C.$createQuoteNode();a.append(...d);break;case "paragraphUnorderedList":a=q.$createListNode("ul");c=q.$createListItemNode();c.append(...d);a.append(c);break;case "paragraphOrderedList":a=parseInt(1<h.regExCaptureGroups.length?h.regExCaptureGroups[h.regExCaptureGroups.length-1].text:"1",10);a=q.$createListNode("ol",a);c=q.$createListItemNode();c.append(...d);
|
|
16
|
+
a.append(c);break;case "paragraphCodeBlock":a=null!=f.triggerState&&f.triggerState.isCodeBlock?r.$createParagraphNode():t.$createCodeNode();a.append(...d);break;case "horizontalRule":d=x.$createHorizontalRuleNode(),c.insertBefore(d)}null!==a&&b.replace(a)}else if(a=f.autoFormatCriteria,b=f.matchResultContext,null!=a.nodeTransformationKind&&6===b.regExCaptureGroups.length){a:{a=a.nodeTransformationKind;switch(a){case "italic":case "bold":case "underline":case "strikethrough":a=[a];break a;case "bold_italic":a=
|
|
17
|
+
["bold","italic"];break a}a=null}if(null!=a){d=[1,5];c=f.autoFormatCriteria;e=f.matchResultContext.regExCaptureGroups;h=e.length;var p=f.textNodeWithOffset.node.getParentOrThrow();null==f.joinedText&&D(62);var m=f.joinedText.length;for(var n=1;n<h;n++){var l=e[n];l.anchorTextNodeWithOffset=E(p,m,l.offsetInParent,1);l.focusTextNodeWithOffset=E(p,m,l.offsetInParent+l.textLength,1);0>l.textLength&&D(63,c.nodeTransformationKind)}b.regExCaptureGroups=e;if(0<d.length)for(c=b.regExCaptureGroups,e=c.length,
|
|
18
|
+
h=d.length-1;0<=h;h--)h<e&&(p=d[h],l=c[p],n=l.anchorTextNodeWithOffset,m=l.focusTextNodeWithOffset,null!=n&&null!=m&&0<l.textLength&&(l=r.$createRangeSelection(),l.anchor.set(n.node.getKey(),n.offset,"text"),l.focus.set(m.node.getKey(),m.offset,"text"),r.$setSelection(l),l=r.$getSelection(),r.$isRangeSelection(l)&&(l.removeText(),n.node.getKey()===m.node.getKey()?(l=m.offset-n.offset,0<l||D(64),L(-l,m.offset,n.node,p,b)):(n=m.offset,0<n&&L(-n,n,m.node,p,b)))));d=b.regExCaptureGroups;3<d.length||D(65);
|
|
19
|
+
e=d[3];c=e.anchorTextNodeWithOffset;d=e.focusTextNodeWithOffset;if(null!=c&&null!=d&&0<e.textLength&&(e=r.$createRangeSelection(),e.anchor.set(c.node.getKey(),c.offset,"text"),e.focus.set(d.node.getKey(),d.offset,"text"),r.$setSelection(e),c=r.$getSelection(),r.$isRangeSelection(c))){for(e=0;e<a.length;e++)c.formatText(a[e]);a=r.$createRangeSelection();a.anchor.set(d.node.getKey(),d.offset+1,"text");a.focus.set(d.node.getKey(),d.offset+1,"text");r.$setSelection(a)}a=f.textNodeWithOffset.node.getParentOrThrow();
|
|
20
|
+
b=E(a,b.offsetInJoinedTextForCollapsedSelection+1,b.offsetInJoinedTextForCollapsedSelection,1);null!=b&&(a=r.$createRangeSelection(),a.anchor.set(b.node.getKey(),b.offset,"text"),a.focus.set(b.node.getKey(),b.offset,"text"),r.$setSelection(a))}}},{tag:"history-push"})}
|
|
21
|
+
function N(g,f){let a=null;g.read(()=>{var b=r.$getSelection();if(r.$isRangeSelection(b)){var c=b.anchor.getNode();b=r.$isTextNode(c)?{node:c,offset:b.anchor.offset}:null}else b=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?J:I;const n=b.triggerState,
|
|
22
|
+
l=c.length;for(let z=0;z<l;z++){const A=c[z];if(null!=n&&!1===n.isCodeBlock||"paragraphCodeBlock"===A.nodeTransformationKind){var d=A,e=b;if(null!==d.requiresParagraphStart&&!0===d.requiresParagraphStart)null===e.textNodeWithOffset.node.getPreviousSibling()?(e=e.textNodeWithOffset.node.getTextContent(),d=K(e,!0,!1,d.regEx)):d=null;else{if(null==e.joinedText){var h=e.textNodeWithOffset.node.getParentOrThrow();if(r.$isElementNode(h)){if(null==e.joinedText){var p=e,m=e.textNodeWithOffset;let w="";h=
|
|
23
|
+
h.getChildren();const O=h.length;for(let B=0;B<O;++B){const v=h[B];if(r.$isTextNode(v)){const G=v.getTextContent();if(v.is(m.node)){m.offset>G.length&&D(50,v.__key);w+=v.getTextContent().substr(0,m.offset);break}else w+=G}else w+="\u0004"}p.joinedText=w}}else D(52,h.__key)}d=K(e.joinedText,!1,!0,d.regEx)}if(null!=d){c={autoFormatCriteria:A,matchResultContext:d};break a}}}c={autoFormatCriteria:null,matchResultContext:null}}null!==c.autoFormatCriteria&&null!==c.matchResultContext&&(a=b,a.autoFormatCriteria=
|
|
23
24
|
c.autoFormatCriteria,a.matchResultContext=c.matchResultContext)}});return a}
|
|
24
|
-
function P(g){let f=null;g.read(()=>{const a=
|
|
25
|
-
function Q(g){
|
|
26
|
-
null})},[g])}module.exports=function(){const [g]=
|
|
25
|
+
function P(g){let f=null;g.read(()=>{const a=r.$getSelection();if(r.$isRangeSelection(a)&&a.isCollapsed()){var b=a.anchor.getNode(),c=b.getParent(),d=null!==c&&q.$isListItemNode(c);f={anchorOffset:a.anchor.offset,hasParentNode:null!==c,isCodeBlock:t.$isCodeNode(b),isParentAListItemNode:d,isSelectionCollapsed:a.isCollapsed(),isSimpleText:r.$isTextNode(b)&&b.isSimpleText(),nodeKey:b.getKey(),textContent:b.getTextContent()}}});return f}
|
|
26
|
+
function Q(g){u.useEffect(()=>{let f=null;return g.addListener("update",({tags:a})=>{if(!1===a.has("historic")){var b=g.getEditorState();a=P(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,h=c.anchorOffset-1;b=!1===(!0===c.hasParentNode&&c.isSimpleText&&c.isSelectionCollapsed&&c.nodeKey===d.nodeKey&&c.anchorOffset!==d.anchorOffset&&0<=h&&h+1<=e&&" "===c.textContent.substr(h,1)&&c.textContent!==d.textContent)?null:N(b,c)}}null!=b&&M(g,b);f=a}else f=
|
|
27
|
+
null})},[g])}module.exports=function(){const [g]=k.useLexicalComposerContext();Q(g);return null};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
type ChangeHandler = (url: string | null, prevUrl: string | null) => void;
|
|
11
|
+
|
|
12
|
+
type LinkMatcherResult = {
|
|
13
|
+
text: string,
|
|
14
|
+
url: string,
|
|
15
|
+
length: number,
|
|
16
|
+
index: number,
|
|
17
|
+
};
|
|
18
|
+
export type LinkMatcher = (text: string) => LinkMatcherResult | null;
|
|
19
|
+
|
|
20
|
+
declare export default function LexicalAutoLinkPlugin(props: {
|
|
21
|
+
matchers: Array<LinkMatcher>,
|
|
22
|
+
onChange?: ChangeHandler,
|
|
23
|
+
}): React$Node;
|