@lexical/react 0.1.10 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DEPRECATED_useLexical.dev.js +3 -7
- package/DEPRECATED_useLexical.prod.js +1 -1
- package/DEPRECATED_useLexicalAutoFormatter.dev.js +83 -37
- package/DEPRECATED_useLexicalAutoFormatter.prod.js +20 -19
- 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 +84 -75
- package/DEPRECATED_useLexicalPlainText.prod.js +15 -15
- package/DEPRECATED_useLexicalRichText.dev.js +96 -438
- package/DEPRECATED_useLexicalRichText.prod.js +17 -26
- package/LexicalAutoFormatterPlugin.d.ts +9 -0
- package/LexicalAutoFormatterPlugin.dev.js +83 -37
- package/LexicalAutoFormatterPlugin.js.flow +10 -0
- package/LexicalAutoFormatterPlugin.prod.js +21 -20
- package/LexicalAutoLinkPlugin.d.ts +20 -0
- package/LexicalAutoLinkPlugin.js.flow +23 -0
- package/LexicalCharacterLimitPlugin.d.ts +11 -0
- package/LexicalCharacterLimitPlugin.dev.js +20 -17
- package/LexicalCharacterLimitPlugin.js.flow +12 -0
- package/LexicalCharacterLimitPlugin.prod.js +9 -8
- package/LexicalClearEditorPlugin.d.ts +14 -0
- package/LexicalClearEditorPlugin.dev.js +73 -0
- package/LexicalClearEditorPlugin.js +9 -0
- package/LexicalClearEditorPlugin.js.flow +14 -0
- package/LexicalClearEditorPlugin.prod.js +8 -0
- package/LexicalCollaborationPlugin.d.ts +49 -0
- package/LexicalCollaborationPlugin.dev.js +21 -13
- package/LexicalCollaborationPlugin.js.flow +55 -0
- package/LexicalCollaborationPlugin.prod.js +7 -7
- package/LexicalComposer.d.ts +22 -0
- package/LexicalComposer.dev.js +32 -3
- package/LexicalComposer.js.flow +24 -0
- package/LexicalComposer.prod.js +3 -2
- package/LexicalComposerContext.d.ts +24 -0
- package/LexicalComposerContext.js.flow +27 -0
- package/LexicalContentEditable.d.ts +32 -0
- package/LexicalContentEditable.dev.js +35 -8
- package/LexicalContentEditable.js.flow +35 -0
- package/LexicalContentEditable.prod.js +3 -3
- package/LexicalHashtagPlugin.d.ts +9 -0
- package/LexicalHashtagPlugin.js.flow +10 -0
- package/LexicalHistoryPlugin.d.ts +29 -0
- package/LexicalHistoryPlugin.js.flow +34 -0
- package/LexicalHorizontalRuleNode.d.ts +23 -0
- package/LexicalHorizontalRuleNode.js.flow +25 -0
- package/LexicalLinkPlugin.d.ts +9 -0
- package/LexicalLinkPlugin.js.flow +10 -0
- package/LexicalListPlugin.d.ts +9 -0
- package/LexicalListPlugin.dev.js +6 -0
- package/LexicalListPlugin.js.flow +10 -0
- package/LexicalListPlugin.prod.js +2 -2
- package/LexicalNestedComposer.d.ts +17 -0
- package/LexicalNestedComposer.dev.js +21 -11
- package/LexicalNestedComposer.js.flow +18 -0
- package/LexicalNestedComposer.prod.js +3 -2
- package/LexicalOnChangePlugin.d.ts +12 -0
- package/LexicalOnChangePlugin.js.flow +14 -0
- package/LexicalPlainTextPlugin.d.ts +15 -0
- package/LexicalPlainTextPlugin.dev.js +73 -84
- package/LexicalPlainTextPlugin.js.flow +18 -0
- package/LexicalPlainTextPlugin.prod.js +12 -12
- package/LexicalRichTextPlugin.d.ts +15 -0
- package/LexicalRichTextPlugin.dev.js +85 -447
- package/LexicalRichTextPlugin.js.flow +18 -0
- package/LexicalRichTextPlugin.prod.js +13 -22
- package/LexicalTablePlugin.d.ts +9 -0
- package/LexicalTablePlugin.dev.js +22 -0
- package/LexicalTablePlugin.js.flow +10 -0
- package/LexicalTablePlugin.prod.js +4 -3
- package/LexicalTreeView.d.ts +17 -0
- package/LexicalTreeView.js.flow +19 -0
- package/README.md +0 -1
- package/package.json +9 -5
- package/useLexicalDecoratorMap.d.ts +14 -0
- package/useLexicalDecoratorMap.js.flow +16 -0
- package/useLexicalIsTextContentEmpty.d.ts +13 -0
- package/useLexicalIsTextContentEmpty.js.flow +15 -0
- package/useLexicalNodeSelection.d.ts +12 -0
- package/useLexicalNodeSelection.js.flow +14 -0
- package/withSubscriptions.d.ts +12 -0
- package/withSubscriptions.js.flow +13 -0
- package/LexicalBootstrapPlugin.dev.js +0 -122
- package/LexicalBootstrapPlugin.js +0 -9
- package/LexicalBootstrapPlugin.prod.js +0 -8
|
@@ -4,29 +4,20 @@
|
|
|
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
|
-
g=
|
|
10
|
-
function
|
|
11
|
-
function
|
|
12
|
-
{tag:"historic"})}return!0;case "redo":return g=
|
|
13
|
-
|
|
14
|
-
function
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var l=b.anchor,n=b.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()))b=D(m),m=x>p,b.__text=b.__text.slice(m?p:x,m?x:p),p=b.getKey(),p={nodeMap:[[p,b]],range:[p]};else if(b=b.getNodes(),0===b.length)p={nodeMap:[],range:[]};else{m=b.length;t=b[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=
|
|
25
|
-
0;v<r.length;v++)if(r[v]!==b[v].__key){u=!1;break}u&&(m++,b.push(q))}}q=b[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=b[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}}}f.call(e,"application/x-lexical-editor",h.call(g,{namespace:c,state:p}))}}})}
|
|
26
|
-
function P(a){y.useEffect(()=>{const d=e=>{var b=a.getRootElement();if(document.activeElement===b&&(b=e.data,"string"===typeof b)){try{var c=JSON.parse(b)}catch(f){return}if(c&&"nuanria_messaging"===c.protocol&&"request"===c.type&&(c=c.payload)&&"makeChanges"===c.functionId&&(c=c.args)){const [f,g,h,l,n]=c;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<=f&&0<=g&&(q=f,r=f+g,p.setTextNodeRange(t,q,t,r));if(q!==r||""!==
|
|
27
|
-
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));e.stopImmediatePropagation()}})}}};window.addEventListener("message",d,!0);return()=>{window.removeEventListener("message",d,!0)}},[a])}
|
|
28
|
-
function Q(a){y.useEffect(()=>{const d=a.addListener("command",(e,b)=>{var c=w.$getSelection();if("click"===e&&w.$isNodeSelection(c))return c.clear(),!0;if(!w.$isRangeSelection(c))return!1;switch(e){case "deleteCharacter":return c.deleteCharacter(b),!0;case "deleteWord":return c.deleteWord(b),!0;case "deleteLine":return c.deleteLine(b),!0;case "insertText":return"string"===typeof b?c.insertText(b):(e=b.dataTransfer,null!=e?J(e,c,a):(b=b.data)&&c.insertText(b)),!0;case "removeText":return c.removeText(),
|
|
29
|
-
!0;case "formatText":return c.formatText(b),!0;case "formatElement":return c=c.anchor.getNode(),(w.$isElementNode(c)?c:c.getParentOrThrow()).setFormat(b),!0;case "insertLineBreak":return c.insertLineBreak(b),!0;case "insertParagraph":return c.insertParagraph(),!0;case "indentContent":return c=c.anchor,c="element"===c.type?c.getNode():c.getNode().getParentOrThrow(),c.canInsertTab()?a.execCommand("insertText","\t"):10!==c.getIndent()&&c.setIndent(c.getIndent()+1),!0;case "outdentContent":return c=c.anchor,
|
|
30
|
-
b=c.getNode(),e="element"===c.type?c.getNode():c.getNode().getParentOrThrow(),e.canInsertTab()?"\t"===b.getTextContent()[c.offset-1]&&a.execCommand("deleteCharacter",!0):0!==e.getIndent()&&e.setIndent(e.getIndent()-1),!0;case "keyArrowLeft":e=b.shiftKey;if(K(c,!0))return b.preventDefault(),b=e,e=F(c),c.modify(b?"extend":"move",!e,"character"),!0;break;case "keyArrowRight":e=b.shiftKey;if(K(c,!1))return b.preventDefault(),b=e,e=F(c),c.modify(b?"extend":"move",e,"character"),!0;break;case "keyBackspace":return b.preventDefault(),
|
|
31
|
-
{anchor:b}=c,c.isCollapsed()&&0===b.offset&&0<("element"===b.type?b.getNode():b.getNode().getParentOrThrow()).getIndent()?a.execCommand("outdentContent"):a.execCommand("deleteCharacter",!0);case "keyDelete":return b.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return b.preventDefault(),b.shiftKey?a.execCommand("insertLineBreak"):a.execCommand("insertParagraph");case "keyTab":return b.preventDefault(),a.execCommand(b.shiftKey?"outdentContent":"indentContent");case "keyEscape":return a.blur(),
|
|
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)};
|
|
7
|
+
var h=require("@lexical/react/withSubscriptions"),u=require("lexical"),v=require("react"),w=require("@lexical/clipboard");
|
|
8
|
+
function x(a,e,f,d,c){if(null===a||0===f.size&&0===d.size)return 0;var b=e._selection,g=a._selection;if(c)return 1;if(!(u.$isRangeSelection(b)&&u.$isRangeSelection(g)&&g.isCollapsed()&&b.isCollapsed()))return 0;var k=Array.from(f);d=Array.from(d);f=e._nodeMap;c=[];for(var l=0;l<k.length;l++){const n=f.get(k[l]);void 0!==n&&c.push(n)}for(k=0;k<d.length;k++)d[k][1]&&(l=f.get(d[k][0]),void 0===l||u.$isRootNode(l)||c.push(l));if(0===c.length)return 0;if(1<c.length)return d=e._nodeMap,e=d.get(b.anchor.key),
|
|
9
|
+
g=d.get(g.anchor.key),e&&g&&!a._nodeMap.has(e.__key)&&u.$isTextNode(e)&&1===e.__text.length&&1===b.anchor.offset?2:0;e=c[0];a=a._nodeMap.get(e.__key);if(!u.$isTextNode(a)||!u.$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 y(a,e){let f=Date.now(),d=0;return(c,b,g,k,l,n)=>{const t=Date.now();if(n.has("historic"))return d=0,f=t,2;const m=x(c,b,k,l,a.isComposing()),r=(()=>{const q=n.has("history-push");if(!q&&n.has("history-merge"))return 0;if(null===c)return 1;var p=b._selection;const D=c._selection;if(!(0<k.size||0<l.size))return null===D&&null!==p?0:2;p=null===g||g.editor===a;return!1===q&&0!==m&&m===d&&t<f+e&&p?0:1})();f=t;d=m;return r}}
|
|
11
|
+
function z(a,e,f=1E3){const d=v.useMemo(()=>e||{current:null,redoStack:[],undoStack:[]},[e]),c=v.useCallback(()=>{d.undoStack=[];d.redoStack=[];d.current=null},[d]);v.useEffect(()=>{const b=y(a,f);return h(a.addListener("command",g=>{switch(g){case "undo":g=d.redoStack;var k=d.undoStack;if(0!==k.length){var l=d.current;const n=k.pop();null!==l&&(g.push(l),a.execCommand("canRedo",!0));0===k.length&&a.execCommand("canUndo",!1);d.current=n;n.editor.setEditorState(n.editorState.clone(n.undoSelection),
|
|
12
|
+
{tag:"historic"})}return!0;case "redo":return g=d.redoStack,k=d.undoStack,0!==g.length&&(l=d.current,null!==l&&(k.push(l),a.execCommand("canUndo",!0)),k=g.pop(),0===g.length&&a.execCommand("canRedo",!1),d.current=k,k.editor.setEditorState(k.editorState,{tag:"historic"})),!0;case "clearEditor":return c(),!1;case "clearHistory":return c(),!0;default:return!1}},0),a.addListener("update",({editorState:g,prevEditorState:k,dirtyLeaves:l,dirtyElements:n,tags:t})=>{const m=d.current,r=d.redoStack,q=d.undoStack,
|
|
13
|
+
p=null===m?null:m.editorState;if(null===m||g!==p){l=b(k,g,m,l,n,t);if(1===l)0!==r.length&&(d.redoStack=[]),null!==m&&(q.push({...m,undoSelection:k.read(u.$getSelection)}),a.execCommand("canUndo",!0));else if(2===l)return;d.current={editor:a,editorState:g}}}))},[c,f,a,d])}function A(a,e,f=1E3){return z(a,e,f)}function B(a){a=a.anchor.getNode();return"rtl"===(u.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}
|
|
14
|
+
function C(a,e){a=u.$getDecoratorNode(a.focus,e);return u.$isDecoratorNode(a)&&!a.isIsolated()}var E="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?v.useLayoutEffect:v.useEffect;function F(a,e){G(a,e);e.update(()=>{const f=u.$getSelection();u.$isRangeSelection(f)&&f.removeText()})}
|
|
15
|
+
function G(a,e){a.preventDefault();e.update(()=>{const f=a.clipboardData,d=u.$getSelection();if(null!==d&&null!=f){const c=w.getHtmlContent(e),b=w.$getLexicalContent(e);null!==c&&f.setData("text/html",c);null!==b&&f.setData("application/x-lexical-editor",b);f.setData("text/plain",d.getTextContent())}})}function H(a,e){a.preventDefault();e.update(()=>{const f=u.$getSelection(),d=a.clipboardData;null!=d&&u.$isRangeSelection(f)&&w.$insertDataTransferForRichText(d,f,e)})}const I={tag:"history-merge"};
|
|
16
|
+
function J(a,e){if(null!==e)if(void 0===e)a.update(()=>{var f=u.$getRoot();if(null===f.getFirstChild()){const d=u.$createParagraphNode();f.append(d);f=document.activeElement;(null!==u.$getSelection()||null!==f&&f===a.getRootElement())&&d.select()}},I);else if(null!==e)switch(typeof e){case "string":e=a.parseEditorState(e);a.setEditorState(e,I);break;case "object":a.setEditorState(e,I);break;case "function":a.update(e,I)}}
|
|
17
|
+
function K(a){v.useEffect(()=>{const e=f=>{var d=a.getRootElement();if(document.activeElement===d&&(d=f.data,"string"===typeof d)){try{var c=JSON.parse(d)}catch(b){return}if(c&&"nuanria_messaging"===c.protocol&&"request"===c.type&&(c=c.payload)&&"makeChanges"===c.functionId&&(c=c.args)){const [b,g,k,l,n]=c;a.update(()=>{const t=u.$getSelection();if(u.$isRangeSelection(t)){var m=t.anchor;let r=m.getNode(),q=0,p=0;u.$isTextNode(r)&&0<=b&&0<=g&&(q=b,p=b+g,t.setTextNodeRange(r,q,r,p));if(q!==p||""!==
|
|
18
|
+
k)t.insertRawText(k),r=m.getNode();u.$isTextNode(r)&&(q=l,p=l+n,m=r.getTextContentSize(),q=q>m?m:q,p=p>m?m:p,t.setTextNodeRange(r,q,r,p));f.stopImmediatePropagation()}})}}};window.addEventListener("message",e,!0);return()=>{window.removeEventListener("message",e,!0)}},[a])}
|
|
19
|
+
function L(a,e){E(()=>{const f=a.addListener("command",(d,c)=>{var b=u.$getSelection();if("click"===d&&u.$isNodeSelection(b))return b.clear(),!0;if(!u.$isRangeSelection(b))return!1;switch(d){case "deleteCharacter":return b.deleteCharacter(c),!0;case "deleteWord":return b.deleteWord(c),!0;case "deleteLine":return b.deleteLine(c),!0;case "insertText":return"string"===typeof c?b.insertText(c):(d=c.dataTransfer,null!=d?w.$insertDataTransferForRichText(d,b,a):(c=c.data)&&b.insertText(c)),!0;case "removeText":return b.removeText(),
|
|
20
|
+
!0;case "formatText":return b.formatText(c),!0;case "formatElement":return b=b.anchor.getNode(),(u.$isElementNode(b)?b:b.getParentOrThrow()).setFormat(c),!0;case "insertLineBreak":return b.insertLineBreak(c),!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,
|
|
21
|
+
c=b.getNode(),d="element"===b.type?b.getNode():b.getNode().getParentOrThrow(),d.canInsertTab()?"\t"===c.getTextContent()[b.offset-1]&&a.execCommand("deleteCharacter",!0):0!==d.getIndent()&&d.setIndent(d.getIndent()-1),!0;case "keyArrowLeft":d=c.shiftKey;if(C(b,!0))return c.preventDefault(),c=d,d=B(b),b.modify(c?"extend":"move",!d,"character"),!0;break;case "keyArrowRight":d=c.shiftKey;if(C(b,!1))return c.preventDefault(),c=d,d=B(b),b.modify(c?"extend":"move",d,"character"),!0;break;case "keyBackspace":return c.preventDefault(),
|
|
22
|
+
{anchor:c}=b,b.isCollapsed()&&0===c.offset&&0<("element"===c.type?c.getNode():c.getNode().getParentOrThrow()).getIndent()?a.execCommand("outdentContent"):a.execCommand("deleteCharacter",!0);case "keyDelete":return c.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return c.preventDefault(),c.shiftKey?a.execCommand("insertLineBreak"):a.execCommand("insertParagraph");case "keyTab":return c.preventDefault(),a.execCommand(c.shiftKey?"outdentContent":"indentContent");case "keyEscape":return a.blur(),
|
|
23
|
+
!0;case "copy":return G(c,a),!0;case "cut":return F(c,a),!0;case "paste":return H(c,a),!0;case "drop":case "dragstart":return c.preventDefault(),!0}return!1},0);J(a,e);return f},[a]);K(a)}module.exports=function(a,e,f){L(a,f);A(a,e)};
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
*/
|
|
8
|
+
|
|
9
|
+
export default function LexicalAutoFormatterPlugin(): React.ReactNode;
|
|
@@ -133,31 +133,31 @@ const paragraphStartBase = { ...autoFormatBase,
|
|
|
133
133
|
};
|
|
134
134
|
const markdownHeader1 = { ...paragraphStartBase,
|
|
135
135
|
nodeTransformationKind: 'paragraphH1',
|
|
136
|
-
regEx:
|
|
136
|
+
regEx: /^(?:# )/
|
|
137
137
|
};
|
|
138
138
|
const markdownHeader2 = { ...paragraphStartBase,
|
|
139
139
|
nodeTransformationKind: 'paragraphH2',
|
|
140
|
-
regEx:
|
|
140
|
+
regEx: /^(?:## )/
|
|
141
141
|
};
|
|
142
142
|
const markdownHeader3 = { ...paragraphStartBase,
|
|
143
143
|
nodeTransformationKind: 'paragraphH2',
|
|
144
|
-
regEx:
|
|
144
|
+
regEx: /^(?:### )/
|
|
145
145
|
};
|
|
146
146
|
const markdownBlockQuote = { ...paragraphStartBase,
|
|
147
147
|
nodeTransformationKind: 'paragraphBlockQuote',
|
|
148
|
-
regEx:
|
|
148
|
+
regEx: /^(?:> )/
|
|
149
149
|
};
|
|
150
150
|
const markdownUnorderedListDash = { ...paragraphStartBase,
|
|
151
151
|
nodeTransformationKind: 'paragraphUnorderedList',
|
|
152
|
-
regEx:
|
|
152
|
+
regEx: /^(?:- )/
|
|
153
153
|
};
|
|
154
154
|
const markdownUnorderedListAsterisk = { ...paragraphStartBase,
|
|
155
155
|
nodeTransformationKind: 'paragraphUnorderedList',
|
|
156
|
-
regEx:
|
|
156
|
+
regEx: /^(?:\* )/
|
|
157
157
|
};
|
|
158
158
|
const markdownCodeBlock = { ...paragraphStartBase,
|
|
159
159
|
nodeTransformationKind: 'paragraphCodeBlock',
|
|
160
|
-
regEx:
|
|
160
|
+
regEx: /^(```)([a-z]*)( )/
|
|
161
161
|
};
|
|
162
162
|
const markdownOrderedList = { ...paragraphStartBase,
|
|
163
163
|
nodeTransformationKind: 'paragraphOrderedList',
|
|
@@ -165,20 +165,39 @@ const markdownOrderedList = { ...paragraphStartBase,
|
|
|
165
165
|
};
|
|
166
166
|
const markdownHorizontalRule = { ...paragraphStartBase,
|
|
167
167
|
nodeTransformationKind: 'horizontalRule',
|
|
168
|
-
regEx:
|
|
168
|
+
regEx: /^(?:\*\*\* )/
|
|
169
169
|
};
|
|
170
170
|
const markdownHorizontalRuleUsingDashes = { ...paragraphStartBase,
|
|
171
171
|
nodeTransformationKind: 'horizontalRule',
|
|
172
|
-
regEx:
|
|
172
|
+
regEx: /^(?:--- )/
|
|
173
|
+
};
|
|
174
|
+
const markdownItalic = { ...autoFormatBase,
|
|
175
|
+
nodeTransformationKind: 'italic',
|
|
176
|
+
regEx: /(\*)(\s*\b)([^\*]*)(\b\s*)(\*\s)$/
|
|
173
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) {
|
|
@@ -343,6 +359,11 @@ function getNewNodeForCriteria(scanningContext, element) {
|
|
|
343
359
|
newNode = lexical.$createParagraphNode();
|
|
344
360
|
} else {
|
|
345
361
|
newNode = CodeNode.$createCodeNode();
|
|
362
|
+
const codingLanguage = matchResultContext.regExCaptureGroups.length >= 3 ? matchResultContext.regExCaptureGroups[2].text : null;
|
|
363
|
+
|
|
364
|
+
if (codingLanguage != null && codingLanguage.length > 0) {
|
|
365
|
+
newNode.setLanguage(codingLanguage);
|
|
366
|
+
}
|
|
346
367
|
}
|
|
347
368
|
|
|
348
369
|
newNode.append(...children);
|
|
@@ -391,28 +412,50 @@ function transformTextNodeForParagraphs(scanningContext) {
|
|
|
391
412
|
}
|
|
392
413
|
}
|
|
393
414
|
|
|
415
|
+
function getTextFormatType(nodeTransformationKind) {
|
|
416
|
+
switch (nodeTransformationKind) {
|
|
417
|
+
case 'italic':
|
|
418
|
+
case 'bold':
|
|
419
|
+
case 'underline':
|
|
420
|
+
case 'strikethrough':
|
|
421
|
+
return [nodeTransformationKind];
|
|
422
|
+
|
|
423
|
+
case 'bold_italic':
|
|
424
|
+
{
|
|
425
|
+
return ['bold', 'italic'];
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
return null;
|
|
430
|
+
}
|
|
431
|
+
|
|
394
432
|
function transformTextNodeForText(scanningContext) {
|
|
395
433
|
const autoFormatCriteria = scanningContext.autoFormatCriteria;
|
|
396
434
|
const matchResultContext = scanningContext.matchResultContext;
|
|
397
435
|
|
|
398
436
|
if (autoFormatCriteria.nodeTransformationKind != null) {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
break;
|
|
407
|
-
}
|
|
437
|
+
if (matchResultContext.regExCaptureGroups.length !== 6) {
|
|
438
|
+
// For BIUS and other formatts which have a pattern + text + pattern,
|
|
439
|
+
// the expected reg ex pattern should have 6 groups.
|
|
440
|
+
// If it does not, then break and fail silently.
|
|
441
|
+
// e2e tests validate the regEx pattern.
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
408
444
|
|
|
409
|
-
|
|
445
|
+
const formatting = getTextFormatType(autoFormatCriteria.nodeTransformationKind);
|
|
410
446
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
447
|
+
if (formatting != null) {
|
|
448
|
+
const captureGroupsToDelete = [1, 5];
|
|
449
|
+
const formatCaptureGroup = 3;
|
|
450
|
+
matchResultContext.regExCaptureGroups = getCaptureGroupsByResolvingAllDetails(scanningContext);
|
|
451
|
+
|
|
452
|
+
if (captureGroupsToDelete.length > 0) {
|
|
453
|
+
// Remove unwanted text in reg ex pattern.
|
|
454
|
+
removeTextInCaptureGroups(captureGroupsToDelete, matchResultContext);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
formatTextInCaptureGroupIndex(formatting, formatCaptureGroup, matchResultContext);
|
|
458
|
+
makeCollapsedSelectionAtOffsetInJoinedText(matchResultContext.offsetInJoinedTextForCollapsedSelection, matchResultContext.offsetInJoinedTextForCollapsedSelection + 1, scanningContext.textNodeWithOffset.node.getParentOrThrow());
|
|
416
459
|
}
|
|
417
460
|
}
|
|
418
461
|
} // Some Capture Group Details were left lazily unresolved as their calculation
|
|
@@ -516,7 +559,7 @@ function shiftCaptureGroupOffsets(delta, applyAtOrAfterOffset, node, startingCap
|
|
|
516
559
|
}
|
|
517
560
|
}
|
|
518
561
|
|
|
519
|
-
function formatTextInCaptureGroupIndex(
|
|
562
|
+
function formatTextInCaptureGroupIndex(formatTypes, captureGroupIndex, matchResultContext) {
|
|
520
563
|
const regExCaptureGroups = matchResultContext.regExCaptureGroups;
|
|
521
564
|
const regExCaptureGroupsCount = regExCaptureGroups.length;
|
|
522
565
|
|
|
@@ -536,7 +579,10 @@ function formatTextInCaptureGroupIndex(formatType, captureGroupIndex, matchResul
|
|
|
536
579
|
const currentSelection = lexical.$getSelection();
|
|
537
580
|
|
|
538
581
|
if (lexical.$isRangeSelection(currentSelection)) {
|
|
539
|
-
|
|
582
|
+
for (let i = 0; i < formatTypes.length; i++) {
|
|
583
|
+
currentSelection.formatText(formatTypes[i]);
|
|
584
|
+
}
|
|
585
|
+
|
|
540
586
|
const finalSelection = lexical.$createRangeSelection();
|
|
541
587
|
finalSelection.anchor.set(focusTextNodeWithOffset.node.getKey(), focusTextNodeWithOffset.offset + 1, 'text');
|
|
542
588
|
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,
|
|
13
|
-
function L(g,f){g.
|
|
14
|
-
|
|
15
|
-
a.append(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"text"),
|
|
20
|
-
|
|
21
|
-
N
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function
|
|
26
|
-
|
|
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,c){g=g.getChildren();const b=g.length;let d=0,e=!1;for(let p=0;p<b&&!(d>f);++p){const m=g[p],n=r.$isTextNode(m);var h=n?m.getTextContent().length:c;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:/^(```)([a-z]*)( )/},{...H,nodeTransformationKind:"horizontalRule",regEx:/^(?:\*\*\* )/},{...H,nodeTransformationKind:"horizontalRule",regEx:/^(?:--- )/},...I];
|
|
12
|
+
function K(g,f,a,c){const b={offsetInJoinedTextForCollapsedSelection:0,regExCaptureGroups:[]};c=g.match(c);if(null!==c&&0<c.length&&(!1===f||0===c.index)&&(!1===a||c.index+c[0].length===g.length)){b.offsetInJoinedTextForCollapsedSelection=g.length;g=c.length;f=c.index;for(a=0;a<g;a++){const d=c[a];b.regExCaptureGroups.push({anchorTextNodeWithOffset:null,focusTextNodeWithOffset:null,offsetInParent:f,text:d,textLength:d.length-(a+1===g?1:0)});0<a&&(f+=d.length)}return b}return null}
|
|
13
|
+
function L(g,f,a,c,b){b.offsetInJoinedTextForCollapsedSelection+=g;0<b.offsetInJoinedTextForCollapsedSelection||D(67);b=b.regExCaptureGroups;const d=b.length;for(c+=1;c<d;c++){const e=b[c];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,c=a.node.getParentOrThrow();a=a.node.spliceText(0,f.matchResultContext.regExCaptureGroups[0].text.length,"",!0);""===a.getTextContent()&&(a.selectPrevious(),a.remove());var b=c;a=null;var d=b.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");b=q.$createListItemNode();b.append(...d);a.append(b);break;case "paragraphOrderedList":a=parseInt(1<h.regExCaptureGroups.length?h.regExCaptureGroups[h.regExCaptureGroups.length-1].text:"1",10);a=q.$createListNode("ol",a);b=q.$createListItemNode();b.append(...d);
|
|
16
|
+
a.append(b);break;case "paragraphCodeBlock":null!=f.triggerState&&f.triggerState.isCodeBlock?a=r.$createParagraphNode():(a=t.$createCodeNode(),b=3<=h.regExCaptureGroups.length?h.regExCaptureGroups[2].text:null,null!=b&&0<b.length&&a.setLanguage(b));a.append(...d);break;case "horizontalRule":d=x.$createHorizontalRuleNode(),b.insertBefore(d)}null!==a&&c.replace(a)}else if(a=f.autoFormatCriteria,c=f.matchResultContext,null!=a.nodeTransformationKind&&6===c.regExCaptureGroups.length){a:{a=a.nodeTransformationKind;
|
|
17
|
+
switch(a){case "italic":case "bold":case "underline":case "strikethrough":a=[a];break a;case "bold_italic":a=["bold","italic"];break a}a=null}if(null!=a){d=[1,5];b=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&&
|
|
18
|
+
D(63,b.nodeTransformationKind)}c.regExCaptureGroups=e;if(0<d.length)for(b=c.regExCaptureGroups,e=b.length,h=d.length-1;0<=h;h--)h<e&&(p=d[h],l=b[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),
|
|
19
|
+
L(-l,m.offset,n.node,p,c)):(n=m.offset,0<n&&L(-n,n,m.node,p,c)))));d=c.regExCaptureGroups;3<d.length||D(65);e=d[3];b=e.anchorTextNodeWithOffset;d=e.focusTextNodeWithOffset;if(null!=b&&null!=d&&0<e.textLength&&(e=r.$createRangeSelection(),e.anchor.set(b.node.getKey(),b.offset,"text"),e.focus.set(d.node.getKey(),d.offset,"text"),r.$setSelection(e),b=r.$getSelection(),r.$isRangeSelection(b))){for(e=0;e<a.length;e++)b.formatText(a[e]);a=r.$createRangeSelection();a.anchor.set(d.node.getKey(),d.offset+
|
|
20
|
+
1,"text");a.focus.set(d.node.getKey(),d.offset+1,"text");r.$setSelection(a)}a=f.textNodeWithOffset.node.getParentOrThrow();c=E(a,c.offsetInJoinedTextForCollapsedSelection+1,c.offsetInJoinedTextForCollapsedSelection,1);null!=c&&(a=r.$createRangeSelection(),a.anchor.set(c.node.getKey(),c.offset,"text"),a.focus.set(c.node.getKey(),c.offset,"text"),r.$setSelection(a))}}},{tag:"history-push"})}
|
|
21
|
+
function N(g,f){let a=null;g.read(()=>{var c=r.$getSelection();if(r.$isRangeSelection(c)){var b=c.anchor.getNode();c=r.$isTextNode(b)?{node:b,offset:c.anchor.offset}:null}else c=null;if(null!==c){c={autoFormatCriteria:{nodeTransformationKind:"noTransformation",regEx:/(?:)/,requiresParagraphStart:null},joinedText:null,matchResultContext:{offsetInJoinedTextForCollapsedSelection:0,regExCaptureGroups:[]},textNodeWithOffset:c,triggerState:f};a:{b=!1===f.isParentAListItemNode?J:I;const n=c.triggerState,
|
|
22
|
+
l=b.length;for(let z=0;z<l;z++){const A=b[z];if(null!=n&&!1===n.isCodeBlock||"paragraphCodeBlock"===A.nodeTransformationKind){var d=A,e=c;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){b={autoFormatCriteria:A,matchResultContext:d};break a}}}b={autoFormatCriteria:null,matchResultContext:null}}null!==b.autoFormatCriteria&&null!==b.matchResultContext&&(a=c,a.autoFormatCriteria=
|
|
24
|
+
b.autoFormatCriteria,a.matchResultContext=b.matchResultContext)}});return a}
|
|
25
|
+
function P(g){let f=null;g.read(()=>{const a=r.$getSelection();if(r.$isRangeSelection(a)&&a.isCollapsed()){var c=a.anchor.getNode(),b=c.getParent(),d=null!==b&&q.$isListItemNode(b);f={anchorOffset:a.anchor.offset,hasParentNode:null!==b,isCodeBlock:t.$isCodeNode(c),isParentAListItemNode:d,isSelectionCollapsed:a.isCollapsed(),isSimpleText:r.$isTextNode(c)&&c.isSimpleText(),nodeKey:c.getKey(),textContent:c.getTextContent()}}});return f}
|
|
26
|
+
function Q(g){u.useEffect(()=>{let f=null;return g.addListener("update",({tags:a})=>{if(!1===a.has("historic")){var c=g.getEditorState();a=P(c);if(null==a)c=null;else{var b=a,d=f;if(null==b||null==d)c=null;else{var e=b.textContent.length,h=b.anchorOffset-1;c=!1===(!0===b.hasParentNode&&b.isSimpleText&&b.isSelectionCollapsed&&b.nodeKey===d.nodeKey&&b.anchorOffset!==d.anchorOffset&&0<=h&&h+1<=e&&" "===b.textContent.substr(h,1)&&b.textContent!==d.textContent)?null:N(c,b)}}null!=c&&M(g,c);f=a}else f=
|
|
27
|
+
null})},[g])}module.exports=function(){const [g]=k.useLexicalComposerContext();Q(g);return null};
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
*/
|
|
8
|
+
|
|
9
|
+
type ChangeHandler = (url: string | null, prevUrl: string | null) => void;
|
|
10
|
+
type LinkMatcherResult = {
|
|
11
|
+
text: string;
|
|
12
|
+
url: string;
|
|
13
|
+
length: number;
|
|
14
|
+
index: number;
|
|
15
|
+
};
|
|
16
|
+
export type LinkMatcher = (text: string) => LinkMatcherResult | null;
|
|
17
|
+
export default function LexicalAutoLinkPlugin(props: {
|
|
18
|
+
matchers: Array<LinkMatcher>;
|
|
19
|
+
onChange?: ChangeHandler;
|
|
20
|
+
}): React.ReactNode;
|
|
@@ -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;
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
*/
|
|
8
|
+
|
|
9
|
+
export default function LexicalCharacterLimitPlugin(props: {
|
|
10
|
+
charset: 'UTF-8' | 'UTF-16';
|
|
11
|
+
}): React.ReactNode;
|
|
@@ -20,11 +20,15 @@ var OverflowNode = require('lexical/OverflowNode');
|
|
|
20
20
|
*
|
|
21
21
|
*
|
|
22
22
|
*/
|
|
23
|
-
function $
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
function $dfs(startingNode, endingNode) {
|
|
24
|
+
const nodes = [];
|
|
25
|
+
const start = (startingNode || lexical.$getRoot()).getLatest();
|
|
26
|
+
const end = endingNode || (lexical.$isElementNode(start) ? start.getLastDescendant() : start);
|
|
27
|
+
let node = start;
|
|
28
|
+
|
|
29
|
+
while (node !== null && !node.is(end)) {
|
|
30
|
+
nodes.push(node);
|
|
26
31
|
|
|
27
|
-
while (node !== null) {
|
|
28
32
|
if (lexical.$isElementNode(node) && node.getChildrenSize() > 0) {
|
|
29
33
|
node = node.getFirstChild();
|
|
30
34
|
} else {
|
|
@@ -41,11 +45,13 @@ function $dfs__DEPRECATED(startingNode, nextNode) {
|
|
|
41
45
|
}
|
|
42
46
|
}
|
|
43
47
|
}
|
|
48
|
+
}
|
|
44
49
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
50
|
+
if (node !== null && node.is(end)) {
|
|
51
|
+
nodes.push(node);
|
|
48
52
|
}
|
|
53
|
+
|
|
54
|
+
return nodes;
|
|
49
55
|
}
|
|
50
56
|
|
|
51
57
|
/**
|
|
@@ -159,10 +165,13 @@ function findOffset(text, maxCharacters, strlen) {
|
|
|
159
165
|
}
|
|
160
166
|
|
|
161
167
|
function $wrapOverflowedNodes(offset) {
|
|
162
|
-
const
|
|
168
|
+
const dfsNodes = $dfs();
|
|
169
|
+
const dfsNodesLength = dfsNodes.length;
|
|
163
170
|
let accumulatedLength = 0;
|
|
164
|
-
|
|
165
|
-
|
|
171
|
+
|
|
172
|
+
for (let i = 0; i < dfsNodesLength; i += 1) {
|
|
173
|
+
const node = dfsNodes[i];
|
|
174
|
+
|
|
166
175
|
if (OverflowNode.$isOverflowNode(node)) {
|
|
167
176
|
const previousLength = accumulatedLength;
|
|
168
177
|
const nextLength = accumulatedLength + node.getTextContentSize();
|
|
@@ -183,8 +192,6 @@ function $wrapOverflowedNodes(offset) {
|
|
|
183
192
|
parent.select();
|
|
184
193
|
}
|
|
185
194
|
}
|
|
186
|
-
|
|
187
|
-
return previousNode;
|
|
188
195
|
} else if (previousLength < offset) {
|
|
189
196
|
const descendant = node.getFirstDescendant();
|
|
190
197
|
const descendantLength = descendant !== null ? descendant.getTextContentSize() : 0;
|
|
@@ -196,7 +203,6 @@ function $wrapOverflowedNodes(offset) {
|
|
|
196
203
|
|
|
197
204
|
if (firstDescendantIsSimpleText || firstDescendantDoesNotOverflow) {
|
|
198
205
|
$unwrapNode(node);
|
|
199
|
-
return previousNode;
|
|
200
206
|
}
|
|
201
207
|
}
|
|
202
208
|
} else if (lexical.$isLeafNode(node)) {
|
|
@@ -222,10 +228,7 @@ function $wrapOverflowedNodes(offset) {
|
|
|
222
228
|
mergePrevious(overflowNode);
|
|
223
229
|
}
|
|
224
230
|
}
|
|
225
|
-
|
|
226
|
-
previousNode = node;
|
|
227
|
-
return node;
|
|
228
|
-
});
|
|
231
|
+
}
|
|
229
232
|
}
|
|
230
233
|
|
|
231
234
|
function $wrapNode(node) {
|
|
@@ -0,0 +1,12 @@
|
|
|
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 LexicalCharacterLimitPlugin(props: {
|
|
11
|
+
charset: 'UTF-8' | 'UTF-16',
|
|
12
|
+
}): React$Node;
|