@lexical/react 0.1.0
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/LICENSE +21 -0
- package/LexicalAutoFormatterPlugin.js +1 -0
- package/LexicalCharacterLimitPlugin.js +3 -0
- package/LexicalCollaborationPlugin.js +9 -0
- package/LexicalComposer.js +2 -0
- package/LexicalComposerContentEditable.js +3 -0
- package/LexicalComposerContext.js +1 -0
- package/LexicalHashtagPlugin.js +4 -0
- package/LexicalHistoryPlugin.js +1 -0
- package/LexicalPlainTextPlugin.js +29 -0
- package/LexicalRichTextPlugin.js +39 -0
- package/LexicalTreeView.js +12 -0
- package/README.md +3 -0
- package/package.json +30 -0
- package/useLexical.js +2 -0
- package/useLexicalAutoFormatter.js +4 -0
- package/useLexicalCanShowPlaceholder.js +4 -0
- package/useLexicalCharacterLimit.js +9 -0
- package/useLexicalDecorators.js +2 -0
- package/useLexicalEditor.js +2 -0
- package/useLexicalEditorEvents.js +3 -0
- package/useLexicalHistory.js +7 -0
- package/useLexicalIsTextContentEmpty.js +2 -0
- package/useLexicalList.js +12 -0
- package/useLexicalPlainText.js +33 -0
- package/useLexicalRichText.js +43 -0
- package/withSubscriptions.js +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Dominic Gannaway
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var a=require("@lexical/react/LexicalComposerContext"),b=require("@lexical/react/useLexicalAutoFormatter");module.exports=function(){const [c]=a.useLexicalComposerContext();b(c);return null};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
'use strict';var c=require("@lexical/react/LexicalComposerContext"),d=require("@lexical/react/useLexicalCharacterLimit"),g=require("react");let h=null;
|
|
2
|
+
module.exports=function({charset:e="UTF-16"}){const [k]=c.useLexicalComposerContext(),[f,l]=g.useState(0),m=g.useMemo(()=>({remainingCharacters:l,strlen:a=>{if("UTF-8"===e){if(void 0===window.TextEncoder)var b=null;else null===h&&(h=new window.TextEncoder),b=h;null===b?(b=encodeURIComponent(a).match(/%[89ABab]/g),a=a.length+(b?b.length:0)):a=b.encode(a).length;return a}if("UTF-16"===e)return a.length;throw Error("Unrecognized charset");}}),[e]);d.useCharacterLimit(k,5,m);return g.createElement("span",
|
|
3
|
+
{className:`characters-limit ${0>f?"characters-limit-exceeded":""}`},f)};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';var d=require("react"),g=require("@lexical/react/LexicalComposerContext"),l=require("react-dom"),u=require("@lexical/yjs"),A=require("lexical"),B=require("lexical/ParagraphNode");const C="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,D=C&&"documentMode"in document?document.documentMode:null;C&&/Win/.test(navigator.platform);C&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream;C&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
|
2
|
+
C&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);C&&/Version\/[\d\.]+.*Safari/.test(navigator.userAgent);C&&/^(?=.*Chrome).*/i.test(navigator.userAgent);C&&"InputEvent"in window&&!D&&new window.InputEvent("input");function E(b){b.update(()=>{A.$log("initEditor");var c=A.$getRoot();if(null===c.getFirstChild()){const a=B.$createParagraphNode();c.append(a);c=document.activeElement;(null!==A.$getSelection()||null!==c&&c===b.getRootElement())&&a.select()}})}
|
|
3
|
+
function F(b,c,a,e,h,m,r){const f=d.useMemo(()=>u.createBinding(b,a,c,e),[b,a,c,e]),n=d.useCallback(()=>{a.connect()},[a]),p=d.useCallback(()=>{try{a.disconnect()}catch(k){}},[a]);d.useEffect(()=>{const {root:k}=f,{awareness:t}=a,w=({status:q})=>{b.execCommand("connected","connected"===q)},x=q=>{!r&&q&&k.isEmpty()&&0===k._xmlText._length&&E(b)},y=()=>{u.syncCursorPositions(f,a)},z=(q,v)=>{v.origin!==f&&u.syncYjsChangesToLexical(f,a,q)};u.initLocalState(a,h,m,document.activeElement===b.getRootElement());
|
|
4
|
+
a.on("status",w);a.on("sync",x);t.on("update",y);k.getSharedType().observeDeep(z);const O=b.addListener("update",({prevEditorState:q,editorState:v,dirtyLeaves:K,dirtyElements:L,normalizedNodes:M,tags:N})=>{u.syncLexicalUpdateToYjs(f,a,q,v,L,K,M,N)});n();return()=>{p();a.off("sync",x);a.off("status",w);t.off("update",y);k.getSharedType().unobserveDeep(z);O()}},[f,m,n,p,b,h,a,r]);const P=d.useMemo(()=>l.createPortal(d.createElement("div",{ref:k=>{f.cursorsContainer=k}}),document.body),[f]);d.useEffect(()=>
|
|
5
|
+
b.addListener("command",(k,t)=>{"toggleConnect"===k&&void 0!==n&&void 0!==p&&(t?(console.log("Collaboration connected!"),n()):(console.log("Collaboration disconnected!"),p()));return!1},0),[n,p,b]);return[P,f]}
|
|
6
|
+
function G(b,c){d.useEffect(()=>{const a=()=>{u.setLocalStateFocus(c,!1)},e=()=>{u.setLocalStateFocus(c,!0)};return b.addListener("root",(h,m)=>{null!==m&&(m.removeEventListener("blur",a),m.removeEventListener("focus",e));null!==h&&(document.activeElement===h&&u.setLocalStateFocus(c,!0),h.addEventListener("blur",a),h.addEventListener("focus",e))})},[b,c,c.awareness])}
|
|
7
|
+
function H(b,c){const a=d.useMemo(()=>u.createUndoManager(c,c.root.getSharedType()),[c]);d.useEffect(()=>b.addListener("command",e=>"undo"===e?(a.undo(),!0):"redo"===e?(a.redo(),!0):!1,0));return d.useCallback(()=>{a.clear()},[a])}
|
|
8
|
+
const I=[["Cat","255,165,0"],["Dog","0,200,55"],["Rabbit","160,0,200"],["Frog","0,172,200"],["Fox","197,200,0"],["Hedgehog","31,200,0"],["Pigeon","200,0,0"],["Squirrel","200,0,148"],["Bear","255,235,0"],["Tiger","86,255,0"],["Leopard","0,255,208"],["Zebra","0,243,255"],["Wolf","0,102,255"],["Owl","147,0,255"],["Gull","255,0,153"],["Squid","0,220,255"]],J=I[Math.floor(Math.random()*(I.length-1+1))],Q=d.createContext({yjsDocMap:new Map,name:J[0],color:J[1]});function R(){return d.useContext(Q)}
|
|
9
|
+
exports.CollaborationContext=Q;exports.CollaborationPlugin=function({id:b,providerFactory:c,skipInit:a}){const {yjsDocMap:e,name:h,color:m}=R(),[r]=g.useLexicalComposerContext(),f=d.useMemo(()=>c(b,e),[b,c,e]),[n,p]=F(r,b,f,e,h,m,a||!1);H(r,p);G(r,f);return n};exports.useCollaborationContext=R;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var e=require("lexical"),f=require("@lexical/react/LexicalComposerContext"),k=require("react");
|
|
2
|
+
module.exports=function({children:l,initialEditorStateRef:h,theme:g}){const c=k.useContext(f.LexicalComposerContext),m=k.useMemo(()=>{if(null!=g)var a=g;else if(null!=c){var d=c[0];var b=c[1].getTheme();null!=b&&(a=b)}d={theme:a||{},parentEditor:d};a=f.createLexicalComposerContext(c,a);b=void 0!==h?h._editor:null;null===b?b=e.createEditor({...d,context:a}):b._config={...d,context:a};return[b,a]},[g]);return k.createElement(f.LexicalComposerContext.Provider,{value:m},l)};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
'use strict';var b=require("react"),e=require("@lexical/react/LexicalComposerContext");
|
|
2
|
+
module.exports=function({ariaActiveDescendantID:f,ariaAutoComplete:g,ariaControls:h,ariaDescribedBy:k,ariaExpanded:l,ariaLabel:m,ariaLabelledBy:n,ariaMultiline:p,ariaOwneeID:q,ariaRequired:r,autoCapitalize:t,autoComplete:u,autoCorrect:v,className:w,readOnly:a=!1,role:c="textbox",spellCheck:x=!1,tabIndex:y,testid:z}){const [d]=e.useLexicalComposerContext(),B=b.useCallback(A=>{d.setRootElement(A)},[d]);return b.createElement("div",{"aria-activedescendant":a?null:f,"aria-autocomplete":a?null:g,"aria-controls":a?
|
|
3
|
+
null:h,"aria-describedby":k,"aria-expanded":a?null:"combobox"===c?!!l:null,"aria-label":m,"aria-labelledby":n,"aria-multiline":p,"aria-owns":a?null:q,"aria-required":r,autoCapitalize:t,autoComplete:u,autoCorrect:v,className:w,contentEditable:!a,"data-testid":z,ref:B,role:a?null:c,spellCheck:x,tabIndex:y})};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var c=require("react");const d=c.createContext(null);exports.LexicalComposerContext=d;exports.createLexicalComposerContext=function(a,e){let b=null;null!=a&&(b=a[1]);return{getTheme:function(){return null!=e?e:null!=b?b.getTheme():null}}};exports.useLexicalComposerContext=function(){const a=c.useContext(d);if(null==a)throw Error("Minified Lexical error #0; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return a};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
'use strict';var c=require("lexical"),h=require("@lexical/react/LexicalComposerContext"),k=require("react"),l=require("lexical/HashtagNode"),m=RegExp;
|
|
2
|
+
const n=String.fromCharCode,p="A-Za-z\u00aa\u00b5\u00ba\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u0241\u0250-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ee\u037a\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03ce\u03d0-\u03f5\u03f7-\u0481\u048a-\u04ce\u04d0-\u04f9\u0500-\u050f\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0621-\u063a\u0640-\u064a\u066e-\u066f\u0671-\u06d3\u06d5\u06e5-\u06e6\u06ee-\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u076d\u0780-\u07a5\u07b1\u0904-\u0939\u093d\u0950\u0958-\u0961\u097d\u0985-\u098c\u098f-\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc-\u09dd\u09df-\u09e1\u09f0-\u09f1\u0a05-\u0a0a\u0a0f-\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32-\u0a33\u0a35-\u0a36\u0a38-\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2-\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0-\u0ae1\u0b05-\u0b0c\u0b0f-\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32-\u0b33\u0b35-\u0b39\u0b3d\u0b5c-\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99-\u0b9a\u0b9c\u0b9e-\u0b9f\u0ba3-\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c33\u0c35-\u0c39\u0c60-\u0c61\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0-\u0ce1\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d28\u0d2a-\u0d39\u0d60-\u0d61\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32-\u0e33\u0e40-\u0e46\u0e81-\u0e82\u0e84\u0e87-\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa-\u0eab\u0ead-\u0eb0\u0eb2-\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edd\u0f00\u0f40-\u0f47\u0f49-\u0f6a\u0f88-\u0f8b\u1000-\u1021\u1023-\u1027\u1029-\u102a\u1050-\u1055\u10a0-\u10c5\u10d0-\u10fa\u10fc\u1100-\u1159\u115f-\u11a2\u11a8-\u11f9\u1200-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f4\u1401-\u166c\u166f-\u1676\u1681-\u169a\u16a0-\u16ea\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u1900-\u191c\u1950-\u196d\u1970-\u1974\u1980-\u19a9\u19c1-\u19c7\u1a00-\u1a16\u1d00-\u1dbf\u1e00-\u1e9b\u1ea0-\u1ef9\u1f00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u2094\u2102\u2107\u210a-\u2113\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2131\u2133-\u2139\u213c-\u213f\u2145-\u2149\u2c00-\u2c2e\u2c30-\u2c5e\u2c80-\u2ce4\u2d00-\u2d25\u2d30-\u2d65\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3006\u3031-\u3035\u303b-\u303c\u3041-\u3096\u309d-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312c\u3131-\u318e\u31a0-\u31b7\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fbb\ua000-\ua48c\ua800-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\uac00-\ud7a3\uf900-\ufa2d\ufa30-\ufa6a\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc\u0300-\u036f\u0483-\u0486\u0591-\u05b9\u05bb-\u05bd\u05bf\u05c1-\u05c2\u05c4-\u05c5\u05c7\u0610-\u0615\u064b-\u065e\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7-\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u0901-\u0903\u093c\u093e-\u094d\u0951-\u0954\u0962-\u0963\u0981-\u0983\u09bc\u09be-\u09c4\u09c7-\u09c8\u09cb-\u09cd\u09d7\u09e2-\u09e3\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47-\u0a48\u0a4b-\u0a4d\u0a70-\u0a71\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2-\u0ae3\u0b01-\u0b03\u0b3c\u0b3e-\u0b43\u0b47-\u0b48\u0b4b-\u0b4d\u0b56-\u0b57\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0c01-\u0c03\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55-\u0c56\u0c82-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5-\u0cd6\u0d02-\u0d03\u0d3e-\u0d43\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d82-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0df2-\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb-\u0ebc\u0ec8-\u0ecd\u0f18-\u0f19\u0f35\u0f37\u0f39\u0f3e-\u0f3f\u0f71-\u0f84\u0f86-\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102c-\u1032\u1036-\u1039\u1056-\u1059\u135f\u1712-\u1714\u1732-\u1734\u1752-\u1753\u1772-\u1773\u17b6-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u192b\u1930-\u193b\u19b0-\u19c0\u19c8-\u19c9\u1a17-\u1a1b\u1dc0-\u1dc3\u20d0-\u20dc\u20e1\u20e5-\u20eb\u302a-\u302f\u3099-\u309a\ua802\ua806\ua80b\ua823-\ua827\ufb1e\ufe00-\ufe0f\ufe20-\ufe23\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u00ff\u0100-\u024f\u0253-\u0254\u0256-\u0257\u0259\u025b\u0263\u0268\u026f\u0272\u0289\u028b\u02bb\u0300-\u036f\u1e00-\u1eff\u0400-\u04ff\u0500-\u0527\u2de0-\u2dff\ua640-\ua69f\u0591-\u05bf\u05c1-\u05c2\u05c4-\u05c5\u05c7\u05d0-\u05ea\u05f0-\u05f4\ufb12-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufb4f\u0610-\u061a\u0620-\u065f\u066e-\u06d3\u06d5-\u06dc\u06de-\u06e8\u06ea-\u06ef\u06fa-\u06fc\u06ff\u0750-\u077f\u08a0\u08a2-\u08ac\u08e4-\u08fe\ufb50-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\u200c-\u200c\u0e01-\u0e3a\u0e40-\u0e4e\u1100-\u11ff\u3130-\u3185\ua960-\ua97f\uac00-\ud7af\ud7b0-\ud7ff\uffa1-\uffdc\u30a1-\u30fa\u30fc-\u30fe\uff66-\uff9f\uff10-\uff19\uff21-\uff3a\uff41-\uff5a\u3041-\u3096\u3099-\u309e\u3400-\u4dbf\u4e00-\u9fff"+(n(173824)+
|
|
3
|
+
"-"+n(177983)+n(177984)+"-"+n(178207)+n(194560)+"-"+n(195103)+"\u3003\u3005\u303b"),{alpha:q,alphanumeric:r,hashChars:t}={alpha:p,alphanumeric:p+"0-9\u0660-\u0669\u06f0-\u06f9\u0966-\u096f\u09e6-\u09ef\u0a66-\u0a6f\u0ae6-\u0aef\u0b66-\u0b6f\u0be6-\u0bef\u0c66-\u0c6f\u0ce6-\u0cef\u0d66-\u0d6f\u0e50-\u0e59\u0ed0-\u0ed9\u0f20-\u0f29\u1040-\u1049\u17e0-\u17e9\u1810-\u1819\u1946-\u194f\u19d0-\u19d9\uff10-\uff19_",hashChars:"#\\uFF03"},u="["+r+"]",v=new m("(^|$|[^&/"+(r+"])([")+(t+"])(")+u+"*["+(q+"]")+
|
|
4
|
+
u+"*)","ig");function w(a){if(a.isSimpleText())for(var e=a.getTextContent(),d=0;;){var b=v.exec(e);if(null===b)break;const f=b.index+b[1].length-d;b=f+(b[3].length+1);let g;0===f?[g,a]=a.splitText(b):[,g,a]=a.splitText(f,b);d+=b;l.$toggleHashtag(g)}}function x(a){k.useEffect(()=>{const e=a.registerNodes([l.HashtagNode]),d=a.addTransform(c.TextNode,w);return()=>{e();d()}},[a])}module.exports=function(){const [a]=h.useLexicalComposerContext();x(a);return null};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var a=require("@lexical/react/LexicalComposerContext"),b=require("@lexical/react/useLexicalHistory");module.exports=function({externalHistoryState:c}){const [d]=a.useLexicalComposerContext();b.useLexicalHistory(d,c);return null};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';var g=require("react"),l=require("@lexical/react/LexicalComposerContext"),m=require("lexical"),n=require("lexical/ParagraphNode"),v=require("@lexical/react/withSubscriptions"),y=require("react-dom");const z="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,A=z&&"documentMode"in document?document.documentMode:null;z&&/Win/.test(navigator.platform);z&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream;
|
|
2
|
+
const B=z&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),C=z&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);z&&/Version\/[\d\.]+.*Safari/.test(navigator.userAgent);z&&/^(?=.*Chrome).*/i.test(navigator.userAgent);const D=z&&"InputEvent"in window&&!A?"getTargetRanges"in new window.InputEvent("input"):!1;var E=z?g.useLayoutEffect:g.useEffect;function F(a,b){return"selectionchange"===a||"keyup"===a||"pointerup"===a||"pointercancel"===a?b.ownerDocument:b}
|
|
3
|
+
function G(a,b){E(()=>{const c=[],e=[];for(let d=0;d<a.length;d++){const [f,h]=a[d],k=p=>{const x=b.getRootElement();null!==x&&"true"===x.contentEditable&&h(p,b)};c.push(p=>{F(f,p).addEventListener(f,k)});e.push(p=>{F(f,p).removeEventListener(f,k)})}return b.addListener("root",(d,f)=>{null!==f&&e.forEach(h=>h(f));null!==d&&c.forEach(h=>h(d))})},[b,a])}
|
|
4
|
+
function H(a,b){const c=b.split(/\r?\n/);if(1===c.length)a.insertText(b);else{b=[];const e=c.length;for(let d=0;d<e;d++){const f=c[d];""!==f&&b.push(m.$createTextNode(f));d!==e-1&&b.push(m.$createLineBreakNode())}a.insertNodes(b)}}
|
|
5
|
+
function I(a){g.useEffect(()=>{const b=c=>{var e=a.getRootElement();if(document.activeElement===e&&(e=c.data,"string"===typeof e)){try{var d=JSON.parse(e)}catch(f){return}if(d&&"nuanria_messaging"===d.protocol&&"request"===d.type&&(d=d.payload)&&"makeChanges"===d.functionId&&(d=d.args)){const [f,h,k,p,x]=d;a.update(()=>{m.$log("useLexicalDragonSupport");const w=m.$getSelection();if(null!==w){var u=w.anchor;let q=u.getNode(),r=0,t=0;m.$isTextNode(q)&&0<=f&&0<=h&&(r=f,t=f+h,w.setTextNodeRange(q,r,q,
|
|
6
|
+
t));if(r!==t||""!==k)H(w,k),q=u.getNode();m.$isTextNode(q)&&(r=p,t=p+x,u=q.getTextContentSize(),r=r>u?u:r,t=t>u?u:t,w.setTextNodeRange(q,r,q,t));c.stopImmediatePropagation()}})}}};window.addEventListener("message",b,!0);return()=>{window.removeEventListener("message",b,!0)}},[a])}function J(a){return a.isToken()||a.isInert()}let K=!1;function L(a,b){a=a.getData("text/plain");null!=a&&H(b,a)}
|
|
7
|
+
function M(a,b){var c=a.focus;a=c.offset;"element"===c.type?b=c.getNode().getChildAtIndex(b?a-1:a):(c=c.getNode(),b=b&&0===a||!b&&a===c.getTextContentSize()?b?c.getPreviousSibling():c.getNextSibling():null);return m.$isDecoratorNode(b)}function N(a){a.preventDefault()}
|
|
8
|
+
function O(a,b){a.preventDefault();b.update(()=>{m.$log("onCopyForPlainText");const c=a.clipboardData,e=m.$getSelection();if(null!==e&&null!=c){var d=window.getSelection();if(!d.isCollapsed){var f=d.getRangeAt(0);f&&(d=document.createElement("div"),f=f.cloneContents(),d.appendChild(f),c.setData("text/html",d.innerHTML));c.setData("text/plain",e.getTextContent())}}})}function P(a,b){b.update(()=>{m.$log("onCompositionEnd");m.$setCompositionKey(null);Q(b,!0)})}
|
|
9
|
+
function R(a){return a.getEditorState().read(()=>m.$getSelection())}
|
|
10
|
+
function S(a,b,c,e,d){if(a.isAttached()&&(d||!a.isDirty())){const f=a.isComposing();let h=b;(f||d)&&"\u00a0"===b[b.length-1]&&(h=b.slice(0,-1));if(d||h!==a.getTextContent())""===h?(f&&m.$setCompositionKey(null),a.remove()):J(a)||null!==m.$getCompositionKey()&&!f?a.markDirty():(b=m.$getSelection(),null!==b&&null!==c&&null!==e&&(b.setTextNodeRange(a,c,a,e),a.isSegmented()&&(c=a.getTextContent(),c=m.$createTextNode(c),a.replace(c),a=c)),a.setTextContent(h))}}
|
|
11
|
+
function T(a,b,c){var e=a.anchor;const d=a.focus;var f=e.getNode();(b=e.key!==d.key||e.offset!==d.offset&&!f.isComposing()||(c||f.isDirty())&&1<b.length||!m.$isTextNode(f)||f.getFormat()!==a.format)||(f.isSegmented()?b=!0:a.isCollapsed()?(b=a.anchor.offset,c=f.getParentOrThrow(),e=f.isToken(),a=0===b&&(!f.canInsertTextBefore()||!c.canInsertTextBefore()||e),f=f.getTextContentSize()===b&&(!f.canInsertTextBefore()||!c.canInsertTextBefore()||e),b=a||f):b=!1);return b}
|
|
12
|
+
function U(a,b){const c=a.inputType;"deleteCompositionText"!==c&&"insertCompositionText"!==c&&b.update(()=>{m.$log("onBeforeInputForRichText");const e=m.$getSelection();if(null!==e)if("deleteContentBackward"===c)m.$setCompositionKey(null),a.preventDefault(),b.execCommand("deleteCharacter",!0);else{var d=a.data;if(!e.dirty&&e.isCollapsed()&&a.getTargetRanges){var f=a.getTargetRanges()[0];f&&e.applyDOMRange(f)}var h=e.focus;f=e.anchor.getNode();h=h.getNode();if("insertText"===c)"\n"===d?(a.preventDefault(),
|
|
13
|
+
b.execCommand("insertLineBreak")):"\n\n"===d?(a.preventDefault(),b.execCommand("insertParagraph")):null==d&&a.dataTransfer?(d=a.dataTransfer.getData("text/plain"),a.preventDefault(),H(e,d)):null!=d&&T(e,d,!0)&&(a.preventDefault(),b.execCommand("insertText",d));else switch(a.preventDefault(),c){case "insertFromComposition":d&&(m.$setCompositionKey(null),b.execCommand("insertText",d));break;case "insertLineBreak":m.$setCompositionKey(null);b.execCommand("insertLineBreak");break;case "insertParagraph":m.$setCompositionKey(null);
|
|
14
|
+
b.execCommand("insertParagraph");break;case "insertFromYank":case "insertFromDrop":case "insertReplacementText":case "insertFromPaste":f=a.dataTransfer;null!=f?L(f,e):d&&b.execCommand("insertText",d);break;case "deleteByComposition":f===h&&!m.$isElementNode(f)&&!m.$isElementNode(h)&&J(f)&&J(h)||b.execCommand("removeText");break;case "deleteByDrag":case "deleteByCut":b.execCommand("removeText");break;case "deleteContent":b.execCommand("deleteCharacter",!1);break;case "deleteWordBackward":b.execCommand("deleteWord",
|
|
15
|
+
!0);break;case "deleteWordForward":b.execCommand("deleteWord",!1);break;case "deleteHardLineBackward":case "deleteSoftLineBackward":b.execCommand("deleteLine",!0);break;case "deleteContentForward":case "deleteHardLineForward":case "deleteSoftLineForward":b.execCommand("deleteLine",!1);break;case "formatStrikeThrough":b.execCommand("formatText","strikethrough");break;case "formatBold":b.execCommand("formatText","bold");break;case "formatItalic":b.execCommand("formatText","italic");break;case "formatUnderline":b.execCommand("formatText",
|
|
16
|
+
"underline");break;case "historyUndo":b.execCommand("undo");break;case "historyRedo":b.execCommand("redo")}}})}function Q(a,b){a=window.getSelection();if(null!==a){var {anchorNode:c,anchorOffset:e,focusOffset:d}=a;null!==c&&3===c.nodeType&&(a=m.$getNearestNodeFromDOMNode(c),m.$isTextNode(a)&&S(a,c.nodeValue,e,d,b))}}function V(a){S(a.node,a.text,a.anchorOffset,a.focusOffset,!1)}
|
|
17
|
+
const W=[["selectionchange",function(a,b){a=window.getSelection();const c=b.getRootElement();c&&!c.contains(a.anchorNode)||b.update(()=>{m.$log("onSelectionChange");const e=m.$getSelection();if(null!==e&&e.isCollapsed()){var d=e.anchor;"text"===d.type?(d=d.getNode(),e.format=d.getFormat()):"element"===d.type&&(e.format=0)}b.execCommand("selectionChange")})}],["keydown",function(a,b){K="Unidentified"===a.key&&229===a.keyCode;b.isComposing()||b.update(()=>{m.$log("onKeyDown");if(null!==m.$getSelection()){var {keyCode:c,
|
|
18
|
+
shiftKey:e,ctrlKey:d,metaKey:f,altKey:h}=a;if(39!==c||d||f||h)if(37!==c||d||f||h)if(38!==c||d||f||h)if(40!==c||d||f||h)if(13===c&&e)b.execCommand("keyEnter",a);else if(B&&d&&79===c)a.preventDefault(),b.execCommand("insertLineBreak",!0);else if(13!==c||e){var k=B?h||f?!1:8===c||72===c&&d:d||h||f?!1:8===c;k?8===c?b.execCommand("keyBackspace",a):b.execCommand("deleteCharacter",!0):(k=B?e||h||f?!1:46===c||68===c&&d:d||h||f?!1:46===c,k?46===c?b.execCommand("keyDelete",a):b.execCommand("deleteCharacter",
|
|
19
|
+
!1):8===c&&(B?h:d)?(a.preventDefault(),b.execCommand("deleteWord",!0)):46===c&&(B?h:d)?(a.preventDefault(),b.execCommand("deleteWord",!1)):B&&f&&8===c?(a.preventDefault(),b.execCommand("deleteLine",!0)):B&&f&&46===c?(a.preventDefault(),b.execCommand("deleteLine",!1)):66===c&&(B?f:d)?(a.preventDefault(),b.execCommand("formatText","bold")):85===c&&(B?f:d)?(a.preventDefault(),b.execCommand("formatText","underline")):73===c&&(B?f:d)?(a.preventDefault(),b.execCommand("formatText","italic")):9!==c||h||
|
|
20
|
+
d||f?90===c&&!e&&(B?f:d)?(a.preventDefault(),b.execCommand("undo")):(k=B?90===c&&f&&e:89===c&&d||90===c&&d&&e,k&&(a.preventDefault(),b.execCommand("redo"))):b.execCommand("keyTab",a))}else b.execCommand("keyEnter",a);else b.execCommand("keyArrowDown",a);else b.execCommand("keyArrowUp",a);else b.execCommand("keyArrowLeft",a);else b.execCommand("keyArrowRight",a)}})}],["compositionstart",function(a,b){b.update(()=>{m.$log("onCompositionStart");const c=m.$getSelection();if(null!==c&&!b.isComposing()){const e=
|
|
21
|
+
c.anchor;m.$setCompositionKey(e.key);null==a.data||K&&"element"!==e.type&&c.isCollapsed()||b.execCommand("insertText"," ")}})}],["compositionend",function(a,b){C?setTimeout(()=>{P(a,b)},0):P(a,b)}],["cut",function(a,b){O(a,b);b.update(()=>{m.$log("onCutForPlainText");const c=m.$getSelection();null!==c&&c.removeText()})}],["copy",O],["dragstart",function(a){a.preventDefault()}],["paste",function(a,b){a.preventDefault();b.update(()=>{m.$log("onPasteForPlainText");const c=m.$getSelection(),e=a.clipboardData;
|
|
22
|
+
null!=e&&null!==c&&L(e,c)})}],["input",function(a,b){a.stopPropagation();b.update(()=>{m.$log("onInput");const c=m.$getSelection(),e=a.data;null!=e&&null!==c&&T(c,e,!1)?b.execCommand("insertText",e):Q(b,!1);m.$flushMutations()})}],["click",function(a,b){b.update(()=>{m.$log("onClick");const c=m.$getSelection();if(null!==c){var e=c.anchor;"element"===e.type&&0===e.offset&&c.isCollapsed()&&1===m.$getRoot().getChildrenSize()&&e.getNode().getTopLevelElementOrThrow().isEmpty()&&(e=R(b),null!==e&&c.is(e)&&
|
|
23
|
+
(window.getSelection().removeAllRanges(),c.dirty=!0))}})}]];D?W.push(["beforeinput",U]):W.push(["drop",N]);function X(a,b){const c=n.$createParagraphNode();a.append(c);a=document.activeElement;(null!==m.$getSelection()||null!==a&&a===b.getRootElement())&&c.select()}function Y(a){a.update(()=>{m.$log("initEditor");const b=m.$getRoot();null===b.getFirstChild()&&X(b,a)})}function aa(a,b){a.update(()=>{m.$log("clearEditor");const c=m.$getRoot();c.clear();X(c,a)},{onUpdate:b})}
|
|
24
|
+
function ba(a,b){E(()=>{const c=v(a.registerNodes([n.ParagraphNode]),a.addListener("textmutation",V),a.addListener("command",(e,d)=>{const f=m.$getSelection();if(null===f)return!1;switch(e){case "deleteCharacter":return f.deleteCharacter(d),!0;case "deleteWord":return f.deleteWord(d),!0;case "deleteLine":return f.deleteLine(d),!0;case "insertText":return f.insertText(d),!0;case "removeText":return f.removeText(),!0;case "insertLineBreak":return f.insertLineBreak(d),!0;case "insertParagraph":return f.insertLineBreak(),
|
|
25
|
+
!0;case "indentContent":case "outdentContent":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":e=d.shiftKey;if(M(f,!0))return d.preventDefault(),d=e,e="rtl"===f.anchor.getNode().getParentOrThrow().getDirection(),f.modify(d?"extend":"move",!e,"character"),!0;break;case "keyArrowRight":e=d.shiftKey;if(M(f,!1))return d.preventDefault(),d=e,e="rtl"===f.anchor.getNode().getParentOrThrow().getDirection(),f.modify(d?"extend":"move",e,"character"),
|
|
26
|
+
!0;break;case "keyBackspace":return d.preventDefault(),a.execCommand("deleteCharacter",!0);case "keyDelete":return d.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return d.preventDefault(),a.execCommand("insertLineBreak");case "clearEditor":aa(a)}return!1},0));b&&Y(a);return c},[a,b]);G(W,a);I(a)}
|
|
27
|
+
function ca(a){const [b,c]=g.useState(()=>a.getDecorators());E(()=>a.addListener("decorator",e=>{y.flushSync(()=>{c(e)})}),[a]);return g.useMemo(()=>{const e=[],d=Object.keys(b);for(let h=0;h<d.length;h++){var f=d[h];const k=b[f];f=a.getElementByKey(f);null!==f&&e.push(y.createPortal(k,f))}return e},[b,a])}function da(a,b=!0){if(a)return!1;a=m.$getRoot().getTextContent();b&&(a=a.trim());return""===a}
|
|
28
|
+
function ea(a){if(!da(a,!1))return!1;a=m.$getRoot().getChildren();const b=a.length;if(1<b)return!1;for(let e=0;e<b;e++){var c=a[e];if(m.$isElementNode(c)){if("paragraph"!==c.__type||0!==c.__indent)return!1;c=c.getChildren();const d=c.length;for(let f=0;f<d;f++)if(!m.$isTextNode(c[e]))return!1}}return!0}function Z(a){return()=>ea(a)}
|
|
29
|
+
function fa(a){const [b,c]=g.useState(a.getEditorState().read(Z(a.isComposing())));E(()=>a.addListener("update",({editorState:e})=>{const d=a.isComposing();e=e.read(Z(d));c(e)}),[a]);return b}function ha(a){throw a;}module.exports=function({contentEditable:a,placeholder:b,skipInit:c,onError:e}){const [d]=l.useLexicalComposerContext(),f=fa(d);ba(d,!c);c=ca(d);E(()=>d.addListener("error",e||ha),[d,e]);return g.createElement(g.Fragment,null,a,f&&b,c)};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';var g=require("react"),u=require("@lexical/react/LexicalComposerContext"),v=require("lexical"),w=require("lexical/HeadingNode"),y=require("lexical/ListNode"),z=require("lexical/QuoteNode"),B=require("lexical/CodeNode"),C=require("lexical/ParagraphNode"),D=require("lexical/ListItemNode"),E=require("lexical/LinkNode"),aa=require("@lexical/react/withSubscriptions"),F=require("react-dom");
|
|
2
|
+
const G="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,ba=G&&"documentMode"in document?document.documentMode:null;G&&/Win/.test(navigator.platform);G&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream;const H=G&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),ca=G&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);G&&/Version\/[\d\.]+.*Safari/.test(navigator.userAgent);G&&/^(?=.*Chrome).*/i.test(navigator.userAgent);
|
|
3
|
+
const da=G&&"InputEvent"in window&&!ba?"getTargetRanges"in new window.InputEvent("input"):!1;var I=G?g.useLayoutEffect:g.useEffect;function J(a,b){return"selectionchange"===a||"keyup"===a||"pointerup"===a||"pointercancel"===a?b.ownerDocument:b}
|
|
4
|
+
function ea(a,b){I(()=>{const e=[],f=[];for(let d=0;d<a.length;d++){const [c,h]=a[d],k=l=>{const m=b.getRootElement();null!==m&&"true"===m.contentEditable&&h(l,b)};e.push(l=>{J(c,l).addEventListener(c,k)});f.push(l=>{J(c,l).removeEventListener(c,k)})}return b.addListener("root",(d,c)=>{null!==c&&f.forEach(h=>h(c));null!==d&&e.forEach(h=>h(d))})},[b,a])}
|
|
5
|
+
function K(a){a=a.getLatest();const b=a.constructor.clone(a);b.__parent=a.__parent;v.$isElementNode(a)&&v.$isElementNode(b)?(b.__children=Array.from(a.__children),b.__format=a.__format,b.__indent=a.__indent,b.__dir=a.__dir):v.$isTextNode(a)&&v.$isTextNode(b)?(b.__format=a.__format,b.__style=a.__style,b.__mode=a.__mode,b.__detail=a.__detail):v.$isDecoratorNode(a)&&v.$isDecoratorNode(b)&&(b.__ref=a.__ref);return b}
|
|
6
|
+
function L(a,b,e,f,d){for(var c=b;null!==a;){for(b=a.getParent();null!==b&&b.excludeFromCopy();)b=b.getParent();if(null===b)break;if(!v.$isElementNode(a)||!a.excludeFromCopy()){const h=a.getKey();let k=d.get(h);const l=void 0===k;l&&(k=K(a),d.set(h,k));!v.$isTextNode(k)||k.isSegmented()||k.isToken()?v.$isElementNode(k)&&(k.__children=k.__children.slice(e?c:0,e?void 0:c+1)):k.__text=k.__text.slice(e?c:0,e?void 0:c);if(v.$isRootNode(b)){l&&f.push(h);break}}c=d.get(b.getKey());c=v.$isElementNode(c)?
|
|
7
|
+
c.__children.indexOf(a.getKey()):a.getIndexWithinParent();a=b}}function M(a,b){const e=b.split(/\r?\n/);if(1===e.length)a.insertText(b);else{b=[];const f=e.length;for(let d=0;d<f;d++){const c=e[d];""!==c&&b.push(v.$createTextNode(c));d!==f-1&&b.push(v.$createLineBreakNode())}a.insertNodes(b)}}
|
|
8
|
+
function fa(a){g.useEffect(()=>{const b=e=>{var f=a.getRootElement();if(document.activeElement===f&&(f=e.data,"string"===typeof f)){try{var d=JSON.parse(f)}catch(c){return}if(d&&"nuanria_messaging"===d.protocol&&"request"===d.type&&(d=d.payload)&&"makeChanges"===d.functionId&&(d=d.args)){const [c,h,k,l,m]=d;a.update(()=>{v.$log("useLexicalDragonSupport");const n=v.$getSelection();if(null!==n){var t=n.anchor;let p=t.getNode(),r=0,q=0;v.$isTextNode(p)&&0<=c&&0<=h&&(r=c,q=c+h,n.setTextNodeRange(p,r,
|
|
9
|
+
p,q));if(r!==q||""!==k)M(n,k),p=t.getNode();v.$isTextNode(p)&&(r=l,q=l+m,t=p.getTextContentSize(),r=r>t?t:r,q=q>t?t:q,n.setTextNodeRange(p,r,p,q));e.stopImmediatePropagation()}})}}};window.addEventListener("message",b,!0);return()=>{window.removeEventListener("message",b,!0)}},[a])}function N(a){return a.isToken()||a.isInert()}const ha={bold:1,underline:8,strikethrough:4,italic:2,code:16,subscript:32,superscript:64};let O=!1;
|
|
10
|
+
const ia={ul:()=>({node:y.$createListNode("ul")}),ol:()=>({node:y.$createListNode("ol")}),li:()=>({node:D.$createListItemNode()}),h1:()=>({node:w.$createHeadingNode("h1")}),h2:()=>({node:w.$createHeadingNode("h2")}),h3:()=>({node:w.$createHeadingNode("h3")}),h4:()=>({node:w.$createHeadingNode("h4")}),h5:()=>({node:w.$createHeadingNode("h5")}),p:()=>({node:C.$createParagraphNode()}),br:()=>({node:v.$createLineBreakNode()}),a:a=>({node:a instanceof HTMLAnchorElement?E.$createLinkNode(a.href):v.$createTextNode(a.textContent)}),
|
|
11
|
+
u:()=>({node:null,format:"underline"}),b:()=>({node:null,format:"bold"}),strong:()=>({node:null,format:"bold"}),i:()=>({node:null,format:"italic"}),em:()=>({node:null,format:"italic"}),"#text":a=>({node:v.$createTextNode(a.textContent)})};
|
|
12
|
+
function P(a,b,e,f){let d=[],c=null;var h=a.nodeName.toLowerCase();h=(h=(e._config.htmlTransforms||{})[h]||b[h])?h(a):null;null!==h&&(c=h.node,h.format&&(h=ha[h.format],f=f?f^h:h),null!==c&&(v.$isTextNode(c)&&void 0!==f&&c.setFormat(f),d.push(c)));a=a.childNodes;for(h=0;h<a.length;h++){const k=P(a[h],b,e,f);v.$isElementNode(c)?c.append(...k):null===c&&(d=d.concat(k))}return d}function Q(a,b){a=a.getData("text/plain");null!=a&&M(b,a)}
|
|
13
|
+
function R(a,b){var e=a.focus;a=e.offset;"element"===e.type?b=e.getNode().getChildAtIndex(b?a-1:a):(e=e.getNode(),b=b&&0===a||!b&&a===e.getTextContentSize()?b?e.getPreviousSibling():e.getNextSibling():null);return v.$isDecoratorNode(b)}function ja(a){a.preventDefault()}
|
|
14
|
+
function S(a,b){a.preventDefault();b.update(()=>{v.$log("onCopyForRichText");const e=a.clipboardData;var f=v.$getSelection();if(null!==f&&null!=e){var d=window.getSelection();if(!d.isCollapsed){var c=d.getRangeAt(0);c&&(d=document.createElement("div"),c=c.cloneContents(),d.appendChild(c),e.setData("text/html",d.innerHTML));e.setData("text/plain",f.getTextContent());d=e.setData;c=JSON;var h=c.stringify;{var k=f.anchor,l=f.focus;var m=k.getCharacterOffset();const A=l.getCharacterOffset();var n=k.getNode(),
|
|
15
|
+
t=l.getNode(),p=n.getParentOrThrow();if(n===t&&v.$isTextNode(n)&&(p.canBeEmpty()||1<p.getChildrenSize()))f=K(n),n=A>m,f.__text=f.__text.slice(n?m:A,n?A:m),m=f.getKey(),m={range:[m],nodeMap:[[m,f]]};else if(f=f.getNodes(),0===f.length)m={range:[],nodeMap:[]};else{n=f.length;t=f[0];p=t.getParent();if(null!==p&&!p.canBeEmpty()){var r=p.__children;if(r.length===n){var q=!0;for(var x=0;x<r.length;x++)if(r[x]!==f[x].__key){q=!1;break}q&&(n++,f.push(p))}}p=f[n-1];k=k.isBefore(l);l=new Map;r=[];L(t,k?m:A,
|
|
16
|
+
!0,r,l);for(t=0;t<n;t++)if(q=f[t],x=q.getKey(),!(l.has(x)||v.$isElementNode(q)&&q.excludeFromCopy())){const ka=K(q);v.$isRootNode(q.getParent())&&r.push(q.getKey());l.set(x,ka)}L(p,k?A:m,!1,r,l);m={range:r,nodeMap:Array.from(l.entries())}}}d.call(e,"application/x-lexical-nodes",h.call(c,m))}}})}function T(a,b){b.update(()=>{v.$log("onCompositionEnd");v.$setCompositionKey(null);U(b,!0)})}function la(a){return a.getEditorState().read(()=>v.$getSelection())}
|
|
17
|
+
function V(a,b,e,f,d){if(a.isAttached()&&(d||!a.isDirty())){const c=a.isComposing();let h=b;(c||d)&&"\u00a0"===b[b.length-1]&&(h=b.slice(0,-1));if(d||h!==a.getTextContent())""===h?(c&&v.$setCompositionKey(null),a.remove()):N(a)||null!==v.$getCompositionKey()&&!c?a.markDirty():(b=v.$getSelection(),null!==b&&null!==e&&null!==f&&(b.setTextNodeRange(a,e,a,f),a.isSegmented()&&(e=a.getTextContent(),e=v.$createTextNode(e),a.replace(e),a=e)),a.setTextContent(h))}}
|
|
18
|
+
function W(a,b,e){var f=a.anchor;const d=a.focus;var c=f.getNode();(b=f.key!==d.key||f.offset!==d.offset&&!c.isComposing()||(e||c.isDirty())&&1<b.length||!v.$isTextNode(c)||c.getFormat()!==a.format)||(c.isSegmented()?b=!0:a.isCollapsed()?(b=a.anchor.offset,e=c.getParentOrThrow(),f=c.isToken(),a=0===b&&(!c.canInsertTextBefore()||!e.canInsertTextBefore()||f),c=c.getTextContentSize()===b&&(!c.canInsertTextBefore()||!e.canInsertTextBefore()||f),b=a||c):b=!1);return b}
|
|
19
|
+
function ma(a,b){const e=a.inputType;"deleteCompositionText"!==e&&"insertCompositionText"!==e&&b.update(()=>{v.$log("onBeforeInputForRichText");const f=v.$getSelection();if(null!==f)if("deleteContentBackward"===e)v.$setCompositionKey(null),a.preventDefault(),b.execCommand("deleteCharacter",!0);else{var d=a.data;if(!f.dirty&&f.isCollapsed()&&a.getTargetRanges){var c=a.getTargetRanges()[0];c&&f.applyDOMRange(c)}var h=f.focus;c=f.anchor.getNode();h=h.getNode();if("insertText"===e)"\n"===d?(a.preventDefault(),
|
|
20
|
+
b.execCommand("insertLineBreak")):"\n\n"===d?(a.preventDefault(),b.execCommand("insertParagraph")):null==d&&a.dataTransfer?(d=a.dataTransfer.getData("text/plain"),a.preventDefault(),M(f,d)):null!=d&&W(f,d,!0)&&(a.preventDefault(),b.execCommand("insertText",d));else switch(a.preventDefault(),e){case "insertFromComposition":d&&(v.$setCompositionKey(null),b.execCommand("insertText",d));break;case "insertLineBreak":v.$setCompositionKey(null);b.execCommand("insertLineBreak");break;case "insertParagraph":v.$setCompositionKey(null);
|
|
21
|
+
b.execCommand("insertParagraph");break;case "insertFromYank":case "insertFromDrop":case "insertReplacementText":case "insertFromPaste":c=a.dataTransfer;null!=c?Q(c,f):d&&b.execCommand("insertText",d);break;case "deleteByComposition":c===h&&!v.$isElementNode(c)&&!v.$isElementNode(h)&&N(c)&&N(h)||b.execCommand("removeText");break;case "deleteByDrag":case "deleteByCut":b.execCommand("removeText");break;case "deleteContent":b.execCommand("deleteCharacter",!1);break;case "deleteWordBackward":b.execCommand("deleteWord",
|
|
22
|
+
!0);break;case "deleteWordForward":b.execCommand("deleteWord",!1);break;case "deleteHardLineBackward":case "deleteSoftLineBackward":b.execCommand("deleteLine",!0);break;case "deleteContentForward":case "deleteHardLineForward":case "deleteSoftLineForward":b.execCommand("deleteLine",!1);break;case "formatStrikeThrough":b.execCommand("formatText","strikethrough");break;case "formatBold":b.execCommand("formatText","bold");break;case "formatItalic":b.execCommand("formatText","italic");break;case "formatUnderline":b.execCommand("formatText",
|
|
23
|
+
"underline");break;case "historyUndo":b.execCommand("undo");break;case "historyRedo":b.execCommand("redo")}}})}function U(a,b){a=window.getSelection();if(null!==a){var {anchorNode:e,anchorOffset:f,focusOffset:d}=a;null!==e&&3===e.nodeType&&(a=v.$getNearestNodeFromDOMNode(e),v.$isTextNode(a)&&V(a,e.nodeValue,f,d,b))}}function na(a){V(a.node,a.text,a.anchorOffset,a.focusOffset,!1)}
|
|
24
|
+
const X=[["selectionchange",function(a,b){a=window.getSelection();const e=b.getRootElement();e&&!e.contains(a.anchorNode)||b.update(()=>{v.$log("onSelectionChange");const f=v.$getSelection();if(null!==f&&f.isCollapsed()){var d=f.anchor;"text"===d.type?(d=d.getNode(),f.format=d.getFormat()):"element"===d.type&&(f.format=0)}b.execCommand("selectionChange")})}],["keydown",function(a,b){O="Unidentified"===a.key&&229===a.keyCode;b.isComposing()||b.update(()=>{v.$log("onKeyDown");if(null!==v.$getSelection()){var {keyCode:e,
|
|
25
|
+
shiftKey:f,ctrlKey:d,metaKey:c,altKey:h}=a;if(39!==e||d||c||h)if(37!==e||d||c||h)if(38!==e||d||c||h)if(40!==e||d||c||h)if(13===e&&f)b.execCommand("keyEnter",a);else if(H&&d&&79===e)a.preventDefault(),b.execCommand("insertLineBreak",!0);else if(13!==e||f){var k=H?h||c?!1:8===e||72===e&&d:d||h||c?!1:8===e;k?8===e?b.execCommand("keyBackspace",a):b.execCommand("deleteCharacter",!0):(k=H?f||h||c?!1:46===e||68===e&&d:d||h||c?!1:46===e,k?46===e?b.execCommand("keyDelete",a):b.execCommand("deleteCharacter",
|
|
26
|
+
!1):8===e&&(H?h:d)?(a.preventDefault(),b.execCommand("deleteWord",!0)):46===e&&(H?h:d)?(a.preventDefault(),b.execCommand("deleteWord",!1)):H&&c&&8===e?(a.preventDefault(),b.execCommand("deleteLine",!0)):H&&c&&46===e?(a.preventDefault(),b.execCommand("deleteLine",!1)):66===e&&(H?c:d)?(a.preventDefault(),b.execCommand("formatText","bold")):85===e&&(H?c:d)?(a.preventDefault(),b.execCommand("formatText","underline")):73===e&&(H?c:d)?(a.preventDefault(),b.execCommand("formatText","italic")):9!==e||h||
|
|
27
|
+
d||c?90===e&&!f&&(H?c:d)?(a.preventDefault(),b.execCommand("undo")):(k=H?90===e&&c&&f:89===e&&d||90===e&&d&&f,k&&(a.preventDefault(),b.execCommand("redo"))):b.execCommand("keyTab",a))}else b.execCommand("keyEnter",a);else b.execCommand("keyArrowDown",a);else b.execCommand("keyArrowUp",a);else b.execCommand("keyArrowLeft",a);else b.execCommand("keyArrowRight",a)}})}],["compositionstart",function(a,b){b.update(()=>{v.$log("onCompositionStart");const e=v.$getSelection();if(null!==e&&!b.isComposing()){const f=
|
|
28
|
+
e.anchor;v.$setCompositionKey(f.key);null==a.data||O&&"element"!==f.type&&e.isCollapsed()||b.execCommand("insertText"," ")}})}],["compositionend",function(a,b){ca?setTimeout(()=>{T(a,b)},0):T(a,b)}],["cut",function(a,b){S(a,b);b.update(()=>{v.$log("onCutForRichText");const e=v.$getSelection();null!==e&&e.removeText()})}],["copy",S],["dragstart",function(a){a.preventDefault()}],["paste",function(a,b){a.preventDefault();b.update(()=>{v.$log("onPasteForRichText");const e=v.$getSelection();var f=a.clipboardData;
|
|
29
|
+
if(null!=f&&null!==e)a:{var d=f.getData("application/x-lexical-nodes");if(d)try{var c=JSON.parse(d);const {range:m,nodeMap:n}=c;var h=new Map(n);d=[];for(c=0;c<m.length;c++){var k=h.get(m[c]);if(void 0!==k){var l=v.$createNodeFromParse(k,h);d.push(l)}}e.insertNodes(d);break a}catch(m){}if(h=f.getData("text/html")){h=(new DOMParser).parseFromString(h,"text/html");f=[];h=h.body?Array.from(h.body.childNodes):[];k=h.length;for(l=0;l<k;l++)d=P(h[l],ia,b),null!==d&&(f=f.concat(d));h=[];k=null;for(l=0;l<
|
|
30
|
+
f.length;l++)d=f[l],!v.$isElementNode(d)||d.isInline()?(null===k&&(k=C.$createParagraphNode(),h.push(k)),null!==k&&k.append(d)):(h.push(d),k=null);e.insertNodes(h)}else Q(f,e)}})}],["input",function(a,b){a.stopPropagation();b.update(()=>{v.$log("onInput");const e=v.$getSelection(),f=a.data;null!=f&&null!==e&&W(e,f,!1)?b.execCommand("insertText",f):U(b,!1);v.$flushMutations()})}],["click",function(a,b){b.update(()=>{v.$log("onClick");const e=v.$getSelection();if(null!==e){var f=e.anchor;"element"===
|
|
31
|
+
f.type&&0===f.offset&&e.isCollapsed()&&1===v.$getRoot().getChildrenSize()&&f.getNode().getTopLevelElementOrThrow().isEmpty()&&(f=la(b),null!==f&&e.is(f)&&(window.getSelection().removeAllRanges(),e.dirty=!0))}})}]];da?X.push(["beforeinput",ma]):X.push(["drop",ja]);function Y(a,b){const e=C.$createParagraphNode();a.append(e);a=document.activeElement;(null!==v.$getSelection()||null!==a&&a===b.getRootElement())&&e.select()}
|
|
32
|
+
function oa(a){a.update(()=>{v.$log("initEditor");const b=v.$getRoot();null===b.getFirstChild()&&Y(b,a)})}function pa(a,b){a.update(()=>{v.$log("clearEditor");const e=v.$getRoot();e.clear();Y(e,a)},{onUpdate:b})}
|
|
33
|
+
function qa(a,b){I(()=>{const e=aa(a.registerNodes([w.HeadingNode,y.ListNode,z.QuoteNode,B.CodeNode,C.ParagraphNode,D.ListItemNode]),a.addListener("textmutation",na),a.addListener("command",(f,d)=>{var c=v.$getSelection();if(null===c)return!1;switch(f){case "deleteCharacter":return c.deleteCharacter(d),!0;case "deleteWord":return c.deleteWord(d),!0;case "deleteLine":return c.deleteLine(d),!0;case "insertText":return c.insertText(d),!0;case "removeText":return c.removeText(),!0;case "formatText":return c.formatText(d),
|
|
34
|
+
!0;case "formatElement":return c=c.anchor.getNode(),(v.$isElementNode(c)?c:c.getParentOrThrow()).setFormat(d),!0;case "insertLineBreak":return c.insertLineBreak(d),!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,d=c.getNode(),f="element"===c.type?c.getNode():
|
|
35
|
+
c.getNode().getParentOrThrow(),f.canInsertTab()?"\t"===d.getTextContent()[c.offset-1]&&a.execCommand("deleteCharacter",!0):0!==f.getIndent()&&f.setIndent(f.getIndent()-1),!0;case "keyArrowLeft":f=d.shiftKey;if(R(c,!0))return d.preventDefault(),d=f,f="rtl"===c.anchor.getNode().getParentOrThrow().getDirection(),c.modify(d?"extend":"move",!f,"character"),!0;break;case "keyArrowRight":f=d.shiftKey;if(R(c,!1))return d.preventDefault(),d=f,f="rtl"===c.anchor.getNode().getParentOrThrow().getDirection(),
|
|
36
|
+
c.modify(d?"extend":"move",f,"character"),!0;break;case "keyBackspace":return d.preventDefault(),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 "clearEditor":pa(a)}return!1},0));b&&oa(a);return e},[a,b]);ea(X,a);
|
|
37
|
+
fa(a)}function ra(a){const [b,e]=g.useState(()=>a.getDecorators());I(()=>a.addListener("decorator",f=>{F.flushSync(()=>{e(f)})}),[a]);return g.useMemo(()=>{const f=[],d=Object.keys(b);for(let h=0;h<d.length;h++){var c=d[h];const k=b[c];c=a.getElementByKey(c);null!==c&&f.push(F.createPortal(k,c))}return f},[b,a])}function sa(a,b=!0){if(a)return!1;a=v.$getRoot().getTextContent();b&&(a=a.trim());return""===a}
|
|
38
|
+
function ta(a){if(!sa(a,!1))return!1;a=v.$getRoot().getChildren();const b=a.length;if(1<b)return!1;for(let f=0;f<b;f++){var e=a[f];if(v.$isElementNode(e)){if("paragraph"!==e.__type||0!==e.__indent)return!1;e=e.getChildren();const d=e.length;for(let c=0;c<d;c++)if(!v.$isTextNode(e[f]))return!1}}return!0}function Z(a){return()=>ta(a)}
|
|
39
|
+
function ua(a){const [b,e]=g.useState(a.getEditorState().read(Z(a.isComposing())));I(()=>a.addListener("update",({editorState:f})=>{const d=a.isComposing();f=f.read(Z(d));e(f)}),[a]);return b}function va(a){throw a;}module.exports=function({contentEditable:a,placeholder:b,skipInit:e,onError:f}){const [d]=u.useLexicalComposerContext(),c=ua(d);qa(d,!e);e=ra(d);I(()=>d.addListener("error",f||va),[d,f]);return g.createElement(g.Fragment,null,a,c&&b,e)};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';var k=require("lexical"),q=require("react");const w=Object.freeze({"\n":"\\n","\t":"\\t"}),C=new RegExp(Object.keys(w).join("|"),"g"),D=Object.freeze({hasNextSibling:"\u251c",isLastChild:"\u2514",ancestorHasNextSibling:"|",ancestorIsLastChild:" ",selectedChar:"^",selectedLine:">"});
|
|
2
|
+
function E(a){let b="";const c=F(a),f=a.anchor;a=a.focus;const d=f.offset,g=a.offset;b=b+`${""!==c?" - "+c:""}`+`\n \u251c anchor { key: ${f.key}, offset: ${null===d?"null":d}, type: ${f.type} }`;return b+=`\n \u2514 focus { key: ${a.key}, offset: ${null===g?"null":g}, type: ${a.type} }`}
|
|
3
|
+
function G(a){let b=" root\n";a=a.read(()=>{const c=k.$getSelection();I(k.$getRoot(),(f,d)=>{const g=`(${f.getKey()})`,e=f.getType()||"",m=f.isSelected();var v=b,t=m?D.selectedLine:" ",r=d.join(" ");if(k.$isTextNode(f)){var n=f.getTextContent(!0);n=0===n.length?"(empty)":`"${J(n)}"`;const l=K(f);n=[n,0!==l.length?`- ${l}`:null].filter(Boolean).join(" ").trim()}else n="";b=v+`${t} ${r} ${g} ${e} ${n}\n`;b+=L({isSelected:m,indent:d,node:f,nodeKeyDisplay:g,selection:c,typeDisplay:e})});return null===
|
|
4
|
+
c?": null":E(c)});return b+"\n selection"+a}function I(a,b,c=[]){a=a.getChildren();const f=a.length;a.forEach((d,g)=>{b(d,c.concat(g===f-1?D.isLastChild:D.hasNextSibling));k.$isElementNode(d)&&I(d,b,c.concat(g===f-1?D.ancestorIsLastChild:D.ancestorHasNextSibling))})}function J(a){return Object.entries(w).reduce((b,[c,f])=>b.replace(new RegExp(c,"g"),String(f)),a)}
|
|
5
|
+
const M=[a=>a.hasFormat("bold")&&"Bold",a=>a.hasFormat("code")&&"Code",a=>a.hasFormat("italic")&&"Italic",a=>a.hasFormat("strikethrough")&&"Strikethrough",a=>a.hasFormat("underline")&&"Underline"],N=[a=>a.isToken()&&"Token",a=>a.isSegmented()&&"Segmented",a=>a.isInert()&&"Inert",a=>a.isDirectionless()&&"Directionless",a=>a.isUnmergeable()&&"Unmergeable"];function K(a){return[...M,...N].map(b=>b(a)).filter(Boolean).join(", ")}function F(a){return M.map(b=>b(a)).filter(Boolean).join(", ")}
|
|
6
|
+
function L({indent:a,isSelected:b,node:c,nodeKeyDisplay:f,selection:d,typeDisplay:g}){if(!k.$isTextNode(c)||null===d||!b||k.$isElementNode(c))return"";b=d.anchor;var e=d.focus;if(""===c.getTextContent()||b.getNode()===d.focus.getNode()&&b.offset===e.offset)return"";e=d.anchor;const m=d.focus,v=c.getTextContent(!0),t=v.length;b=d=-1;if("text"===e.type&&"text"===m.type){const l=e.getNode(),u=m.getNode();l===u&&c===l&&e.offset!==m.offset?[d,b]=e.offset<m.offset?[e.offset,m.offset]:[m.offset,e.offset]:
|
|
7
|
+
c===l?[d,b]=l.isBefore(u)?[e.offset,t]:[0,e.offset]:c===u?[d,b]=u.isBefore(l)?[m.offset,t]:[0,m.offset]:[d,b]=[0,t]}c=(v.slice(0,d).match(C)||[]).length;e=(v.slice(d,b).match(C)||[]).length;const [r,n]=[d+c,b+c+e];if(r===n)return"";c=a[a.length-1]===D.hasNextSibling?D.ancestorHasNextSibling:D.ancestorIsLastChild;a=[...a.slice(0,a.length-1),c];c=Array(r).fill(" ");d=Array(n-r).fill(D.selectedChar);f=Array(f.length+(g.length+3)).fill(" ");return[D.selectedLine,a.join(" "),[...f,...c,...d].join("")].join(" ")+
|
|
8
|
+
"\n"}
|
|
9
|
+
module.exports=function({timeTravelButtonClassName:a,timeTravelPanelSliderClassName:b,timeTravelPanelButtonClassName:c,viewClassName:f,timeTravelPanelClassName:d,editor:g}){const [e,m]=q.useState([]),[v,t]=q.useState(""),[r,n]=q.useState(!1),l=q.useRef(0),u=q.useRef(null),[z,B]=q.useState(!1);q.useEffect(()=>{t(G(g.getEditorState()));return g.addListener("update",({editorState:h})=>{const p=g._compositionKey,x=G(g.getEditorState());t([x,null!==p&&`Composition key: ${p}`].filter(Boolean).join("\n\n"));r||
|
|
10
|
+
m(A=>[...A,[Date.now(),h]])})},[r,g]);const y=e.length;q.useEffect(()=>{if(z){let h;const p=()=>{const x=l.current;x===y-1?B(!1):h=setTimeout(()=>{l.current++;const A=l.current,H=u.current;null!==H&&(H.value=String(A));g.setEditorState(e[A][1]);p()},e[x+1][0]-e[x][0])};p();return()=>{window.clearTimeout(h)}}},[e,z,g,y]);return q.createElement("div",{className:f},!r&&2<y&&q.createElement("button",{onClick:()=>{const h=g.getRootElement();null!==h&&(h.contentEditable="false",l.current=y-1,n(!0))},className:a},
|
|
11
|
+
"Time Travel"),q.createElement("pre",null,v),r&&q.createElement("div",{className:d},q.createElement("button",{className:c,onClick:()=>{B(!z)}},z?"Pause":"Play"),q.createElement("input",{className:b,ref:u,onChange:h=>{h=Number(h.target.value);const p=e[h];p&&(l.current=h,g.setEditorState(p[1]))},type:"range",min:"1",max:y-1}),q.createElement("button",{className:c,onClick:()=>{var h=g.getRootElement();if(null!==h){h.contentEditable="true";h=e.length-1;g.setEditorState(e[h][1]);const p=u.current;null!==
|
|
12
|
+
p&&(p.value=String(h));n(!1);B(!1)}}},"Exit")))};
|
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lexical/react",
|
|
3
|
+
"author": {
|
|
4
|
+
"name": "Dominic Gannaway",
|
|
5
|
+
"email": "dg@domgan.com"
|
|
6
|
+
},
|
|
7
|
+
"description": "This package provides Lexical components and hooks for React applications.",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"react",
|
|
10
|
+
"lexical",
|
|
11
|
+
"editor",
|
|
12
|
+
"rich-text"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"version": "0.1.0",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"lexical": "0.1.0",
|
|
18
|
+
"@lexical/helpers": "0.1.0",
|
|
19
|
+
"@lexical/yjs": "0.1.0"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"react": ">=17.x",
|
|
23
|
+
"react-dom": ">=17.x"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/facebook/lexical",
|
|
28
|
+
"directory": "packages/lexical-react"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/useLexical.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var b=require("lexical"),c=require("react"),h=require("@lexical/react/useLexicalCanShowPlaceholder");const k="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,l=k&&"documentMode"in document?document.documentMode:null;k&&/Win/.test(navigator.platform);k&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream;k&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);k&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
|
|
2
|
+
k&&/Version\/[\d\.]+.*Safari/.test(navigator.userAgent);k&&/^(?=.*Chrome).*/i.test(navigator.userAgent);k&&"InputEvent"in window&&!l?"getTargetRanges"in new window.InputEvent("input"):!1;var m=k?c.useLayoutEffect:c.useEffect;function n(a,d){const e=h(a),g=c.useCallback(f=>{a.setRootElement(f)},[a]);m(()=>a.addListener("error",d),[a,d]);return[g,e]}function p(a){throw a;}module.exports=function(a){const d=void 0!==a&&a.onError||p,e=c.useMemo(()=>b.createEditor(a),[a]),[g,f]=n(e,d);return[e,g,f]};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
'use strict';var e=require("react"),g=require("lexical"),h=require("lexical/ParagraphNode"),k=require("lexical/ListItemNode"),m=require("lexical/HeadingNode"),n=require("lexical/ListNode"),p=require("lexical/QuoteNode"),q=require("lexical/CodeNode");function r(a,c){a=a.spliceText(0,c,"",!0);""===a.getTextContent()&&(a.selectPrevious(),a.remove())}
|
|
2
|
+
function t(a){const c=a.getParentOrThrow();if(null!==c&&null===a.getPreviousSibling()&&h.$isParagraphNode(c)){var b=a.getTextContent(),d=b[0];const f=b[1],l=b[2];if(1<b.length&&" "===f)if("#"===d)r(a,2),a=m.$createHeadingNode("h1"),b=c.getChildren(),a.append(...b),c.replace(a);else if(">"===d)r(a,2),a=p.$createQuoteNode(),b=c.getChildren(),a.append(...b),c.replace(a);else{if("-"===d||"*"===d)r(a,2),a=n.$createListNode("ul"),b=k.$createListItemNode(),d=c.getChildren(),b.append(...d),a.append(b),c.replace(a)}else 2<
|
|
3
|
+
b.length&&("#"===d&&"#"===f&&" "===l?(r(a,3),a=m.$createHeadingNode("h2"),b=c.getChildren(),a.append(...b),c.replace(a)):parseInt(d,10)?(b=b.match(/^(\d+)\.\s/),null!==b&&0===b.index&&2===b.length&&(d=parseInt(b[1],10),r(a,b[0].length),a=n.$createListNode("ol",d),b=k.$createListItemNode(),d=c.getChildren(),b.append(...d),a.append(b),c.replace(a))):"`"===d&&"`"===f&&"`"===l&&(r(a,3),a=q.$createCodeNode(),a.append(...c.getChildren()),c.replace(a)))}}
|
|
4
|
+
module.exports=function(a){e.useEffect(()=>a.addTransform(g.TextNode,t),[a])};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
'use strict';var b=require("react"),f=require("lexical");const g="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,l=g&&"documentMode"in document?document.documentMode:null;g&&/Win/.test(navigator.platform);g&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream;g&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);g&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);g&&/Version\/[\d\.]+.*Safari/.test(navigator.userAgent);
|
|
2
|
+
g&&/^(?=.*Chrome).*/i.test(navigator.userAgent);g&&"InputEvent"in window&&!l?"getTargetRanges"in new window.InputEvent("input"):!1;var m=g?b.useLayoutEffect:b.useEffect;function n(a,e=!0){if(a)return!1;a=f.$getRoot().getTextContent();e&&(a=a.trim());return""===a}
|
|
3
|
+
function p(a){if(!n(a,!1))return!1;a=f.$getRoot().getChildren();const e=a.length;if(1<e)return!1;for(let d=0;d<e;d++){var c=a[d];if(f.$isElementNode(c)){if("paragraph"!==c.__type||0!==c.__indent)return!1;c=c.getChildren();const h=c.length;for(let k=0;k<h;k++)if(!f.$isTextNode(c[d]))return!1}}return!0}function q(a){return()=>p(a)}
|
|
4
|
+
module.exports=function(a){const [e,c]=b.useState(a.getEditorState().read(q(a.isComposing())));m(()=>a.addListener("update",({editorState:d})=>{const h=a.isComposing();d=d.read(q(h));c(d)}),[a]);return e};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';var k=require("lexical"),l=require("react"),n=require("@lexical/react/withSubscriptions");function p(a,c){for(c(a);null!==a;){if(k.$isElementNode(a)&&0<a.getChildrenSize())a=a.getFirstChild();else{let e=null;for(;null===e&&null!==a;)e=a.getNextSibling(),a=null===e?a.getParent():e}null!==a&&(a=c(a))}}function q(){return k.$getRoot().getTextContent()}
|
|
2
|
+
function r(a,c,e){var g=Intl.Segmenter;let d=0;var b=0;if("function"===typeof g){a=(new g).segment(a);for(var {segment:f}of a){b+=e(f);if(b>c)break;d+=f.length}}else for(f=Array.from(a),a=f.length,g=0;g<a;g++){const h=f[g];b+=e(h);if(b>c)break;d+=h.length}return d}
|
|
3
|
+
function t(a){const c=k.$getRoot();let e=0,g=c;p(c,d=>{if(u(d)){var b=e;if(e+d.getTextContentSize()<=a){var f=d.getParent();b=d.getPreviousSibling();var h=d.getNextSibling();v(d);d=k.$getSelection();null===d||d.anchor.getNode().isAttached()&&d.focus.getNode().isAttached()||(k.$isTextNode(b)?b.select():k.$isTextNode(h)?h.select():null!==f&&f.select());return g}if(b<a&&(f=d.getFirstDescendant(),h=null!==f?f.getTextContentSize():0,b+=h,f=k.$isTextNode(f)&&f.isSimpleText(),b=b<=a,f||b))return v(d),g}else k.$isLeafNode(d)&&
|
|
4
|
+
(b=e,e+=d.getTextContentSize(),e>a&&!u(d.getParent())&&(f=k.$getSelection(),b<a&&k.$isTextNode(d)&&d.isSimpleText()?([,b]=d.splitText(a-b),b=w(b)):b=w(d),null!==f&&k.$setSelection(f),x(b)));return g=d})}
|
|
5
|
+
class y extends k.ElementNode{static getType(){return"overflow"}static clone(a){return new y(a.__key)}constructor(a){super(a);this.__type="overflow"}createDOM(a){const c=document.createElement("div");a=a.theme.characterLimit;"string"===typeof a&&(c.className=a);return c}updateDOM(){return!1}insertNewAfter(a){return this.getParentOrThrow().insertNewAfter(a)}excludeFromCopy(){return!0}}function z(){return new y}function u(a){return a instanceof y}
|
|
6
|
+
function w(a){const c=z();a.insertBefore(c);c.append(a);return c}function v(a){const c=a.getChildren(),e=c.length;for(let g=0;g<e;g++)a.insertBefore(c[g]);a.remove();return 0<e?c[e-1]:null}
|
|
7
|
+
function x(a){const c=a.getPreviousSibling();if(u(c)){var e=a.getFirstChild(),g=c.getChildren(),d=g.length;if(null===e)a.append(...g);else for(var b=0;b<d;b++)e.insertBefore(g[b]);b=k.$getSelection();if(null!==b){e=b.anchor;g=e.getNode();b=b.focus;const f=e.getNode();g.is(c)?e.set(a.getKey(),e.offset,"element"):g.is(a)&&e.set(a.getKey(),d+e.offset,"element");f.is(c)?b.set(a.getKey(),b.offset,"element"):f.is(a)&&b.set(a.getKey(),d+b.offset,"element")}c.remove()}}exports.$createOverflowNode=z;
|
|
8
|
+
exports.OverflowNode=y;exports.isOverflowNode=u;exports.mergePrevious=x;
|
|
9
|
+
exports.useCharacterLimit=function(a,c,e={}){const {strlen:g=b=>b.length,remainingCharacters:d=()=>{}}=e;l.useEffect(()=>a.registerNodes([y]),[a]);l.useEffect(()=>{let b=a.getEditorState().read(q),f=0;return n(a.addListener("textcontent",h=>{b=h}),a.addListener("update",({dirtyLeaves:h})=>{var m=a.isComposing();h=0<h.size;if(!m&&h){m=g(b);h=m>c||null!==f&&f>c;d(c-m);if(null===f||h){const A=r(b,c,g);a.update(()=>{k.$log("CharacterLimit");t(A)},{tag:"without-history"})}f=m}}))},[a,c,d,g])};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var a=require("react-dom"),d=require("react");const h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,l=h&&"documentMode"in document?document.documentMode:null;h&&/Win/.test(navigator.platform);h&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream;h&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);h&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);h&&/Version\/[\d\.]+.*Safari/.test(navigator.userAgent);
|
|
2
|
+
h&&/^(?=.*Chrome).*/i.test(navigator.userAgent);h&&"InputEvent"in window&&!l?"getTargetRanges"in new window.InputEvent("input"):!1;var m=h?d.useLayoutEffect:d.useEffect;module.exports=function(b){const [f,n]=d.useState(()=>b.getDecorators());m(()=>b.addListener("decorator",e=>{a.flushSync(()=>{n(e)})}),[b]);return d.useMemo(()=>{const e=[],k=Object.keys(f);for(let g=0;g<k.length;g++){var c=k[g];const p=f[c];c=b.getElementByKey(c);null!==c&&e.push(a.createPortal(p,c))}return e},[f,b])};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var a=require("react"),c=require("@lexical/react/useLexicalCanShowPlaceholder");const e="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,f=e&&"documentMode"in document?document.documentMode:null;e&&/Win/.test(navigator.platform);e&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream;e&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);e&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);e&&/Version\/[\d\.]+.*Safari/.test(navigator.userAgent);
|
|
2
|
+
e&&/^(?=.*Chrome).*/i.test(navigator.userAgent);e&&"InputEvent"in window&&!f?"getTargetRanges"in new window.InputEvent("input"):!1;var g=e?a.useLayoutEffect:a.useEffect;module.exports=function(b,d){const h=c(b),l=a.useCallback(k=>{b.setRootElement(k)},[b]);g(()=>b.addListener("error",d),[b,d]);return[l,h]};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
'use strict';var a=require("react");const h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,k=h&&"documentMode"in document?document.documentMode:null;h&&/Win/.test(navigator.platform);h&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream;h&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);h&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);h&&/Version\/[\d\.]+.*Safari/.test(navigator.userAgent);h&&/^(?=.*Chrome).*/i.test(navigator.userAgent);
|
|
2
|
+
h&&"InputEvent"in window&&!k?"getTargetRanges"in new window.InputEvent("input"):!1;var q=h?a.useLayoutEffect:a.useEffect;function r(b,c){return"selectionchange"===b||"keyup"===b||"pointerup"===b||"pointercancel"===b?c.ownerDocument:c}
|
|
3
|
+
module.exports=function(b,c){q(()=>{const l=[],m=[];for(let e=0;e<b.length;e++){const [d,f]=b[e],p=g=>{const n=c.getRootElement();null!==n&&"true"===n.contentEditable&&f(g,c)};l.push(g=>{r(d,g).addEventListener(d,p)});m.push(g=>{r(d,g).removeEventListener(d,p)})}return c.addListener("root",(e,d)=>{null!==d&&m.forEach(f=>f(d));null!==e&&l.forEach(f=>f(e))})},[c,b])};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
'use strict';var n=require("lexical"),r=require("react"),v=require("@lexical/react/withSubscriptions");function w(a,b,f){b=Array.from(b);f=Array.from(f);a=a._nodeMap;const c=[];for(var h=0;h<b.length;h++){const e=a.get(b[h]);void 0!==e&&c.push(e)}for(b=0;b<f.length;b++)f[b][1]&&(h=a.get(f[b][0]),void 0===h||n.$isRootNode(h)||c.push(h));return c}
|
|
2
|
+
function x(a,b,f,c,h){if(null===a||0===f.size&&0===c.size)return 0;var e=b._selection,d=a._selection;if(h)return 1;if(null===e||null===d||!d.isCollapsed()||!e.isCollapsed())return 0;f=w(b,f,c);if(0===f.length)return 0;if(1<f.length){b=b._nodeMap;d=b.get(d.anchor.key);const g=b.get(e.anchor.key);return n.$isTextNode(g)&&n.$isElementNode(d)&&!a._nodeMap.has(g.__key)&&1===g.__text.length&&1===e.anchor.offset?f.every(k=>k===g||!n.$isTextNode(k))?2:0:0}b=f[0];a=a._nodeMap.get(b.__key);if(!n.$isTextNode(a)||
|
|
3
|
+
!n.$isTextNode(b)||a.__mode!==b.__mode)return 0;a=a.__text;b=b.__text;if(a===b)return 0;e=e.anchor;d=d.anchor;if(e.key!==d.key||"text"!==e.type)return 0;e=e.offset;d=d.offset;a=b.length-a.length;return 1===a&&d===e-1?2:-1===a&&d===e+1?3:-1===a&&d===e?4:0}
|
|
4
|
+
function y(a,b){let f=Date.now(),c=0;return(h,e,d,g,k,m)=>{const p=Date.now();if(m.has("historic"))return c=0,f=p,2;const l=x(h,e,g,k,a.isComposing()),u=(()=>{if(m.has("without-history"))return 0;if(null===h)return 1;var q=e._selection;const t=h._selection;if(!(0<g.size||0<k.size))return null===t&&null!==q?0:2;q=null===d||d.editor===a;return 0!==l&&l===c&&p<f+b&&q?0:1})();f=p;c=l;return u}}function z(){return{current:null,redoStack:[],undoStack:[]}}exports.createEmptyHistoryState=z;
|
|
5
|
+
exports.useLexicalHistory=function(a,b,f=1E3){const c=r.useMemo(()=>b||z(),[b]),h=r.useCallback(()=>{c.undoStack=[];c.redoStack=[];c.current=null},[c]);r.useEffect(()=>{const e=y(a,f);return v(a.addListener("command",d=>{switch(d){case "undo":d=c.redoStack;var g=c.undoStack;if(0!==g.length){var k=c.current;const m=g.pop();null!==k&&(d.push(k),a.execCommand("canRedo",!0));0===g.length&&a.execCommand("canUndo",!1);c.current=m;m.editor.setEditorState(m.editorState.clone(m.undoSelection),{tag:"historic"})}return!0;
|
|
6
|
+
case "redo":return d=c.redoStack,g=c.undoStack,0!==d.length&&(k=c.current,null!==k&&(g.push(k),a.execCommand("canUndo",!0)),g=d.pop(),0===d.length&&a.execCommand("canRedo",!1),c.current=g,g.editor.setEditorState(g.editorState,{tag:"historic"})),!0;case "clearEditor":case "clearHistory":return h(),!0;default:return!1}},0),a.addListener("update",({editorState:d,prevEditorState:g,dirtyLeaves:k,dirtyElements:m,tags:p})=>{const l=c.current,u=c.redoStack,q=c.undoStack,t=null===l?null:l.editorState;if(null===
|
|
7
|
+
l||d!==t){k=e(g,d,l,k,m,p);if(1===k)0!==u.length&&(c.redoStack=[]),null!==l&&(q.push({...l,undoSelection:g.read(n.$getSelection)}),a.execCommand("canUndo",!0));else if(2===k)return;c.current={editor:a,editorState:d}}}))},[h,f,a,c])};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var b=require("react"),d=require("lexical");const f="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,g=f&&"documentMode"in document?document.documentMode:null;f&&/Win/.test(navigator.platform);f&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream;f&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);f&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);f&&/Version\/[\d\.]+.*Safari/.test(navigator.userAgent);
|
|
2
|
+
f&&/^(?=.*Chrome).*/i.test(navigator.userAgent);f&&"InputEvent"in window&&!g?"getTargetRanges"in new window.InputEvent("input"):!1;var h=f?b.useLayoutEffect:b.useEffect;function k(a,c=!0){if(a)return!1;a=d.$getRoot().getTextContent();c&&(a=a.trim());return""===a}function l(a,c){return()=>k(a,c)}module.exports=function(a,c){const [m,n]=b.useState(a.getEditorState().read(l(a.isComposing(),c)));h(()=>a.addListener("update",({editorState:e})=>{const p=a.isComposing();e=e.read(l(p,c));n(e)}),[a,c]);return m};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';var g=require("react"),l=require("lexical"),m=require("lexical/ListItemNode"),p=require("lexical/ListNode"),q=require("lexical/ParagraphNode");function r(d){d=d.getParent();if(!p.$isListNode(d))throw Error("Minified Lexical error #2; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");let a=d;for(;null!==a;)a=a.getParent(),p.$isListNode(a)&&(d=a);return d}
|
|
2
|
+
function t(d){let a=[];d=d.getChildren().filter(m.$isListItemNode);for(let b=0;b<d.length;b++){const c=d[b],e=c.getFirstChild();p.$isListNode(e)?a=a.concat(t(e)):a.push(c)}return a}function u(d,a){for(;null!=d&&!(d instanceof a);)d=d.getParent();return d}
|
|
3
|
+
function v(d){d.update(()=>{l.$log("removeList");var a=l.$getSelection();if(null!==a){const c=new Set,e=a.getNodes();a=a.anchor.getNode();if(0===e.length&&m.$isListItemNode(a))c.add(r(a));else for(a=0;a<e.length;a++){var b=e[a];l.$isLeafNode(b)&&(b=u(b,m.ListItemNode),null!=b&&c.add(r(b)))}c.forEach(f=>{let h=f;t(f).forEach(k=>{if(null!=k){const n=q.$createParagraphNode();n.append(...k.getChildren());h.insertAfter(n);h=n;k.remove()}});f.remove()})}})}
|
|
4
|
+
function w(d,a){if(p.$isListNode(d))return d;const b=d.getPreviousSibling(),c=d.getNextSibling(),e=m.$createListItemNode();if(p.$isListNode(b))return e.append(d),b.append(e),p.$isListNode(c)&&(b.append(...c.getChildren()),c.remove()),b;if(p.$isListNode(c))return e.append(d),c.getFirstChildOrThrow().insertBefore(e),c;a=p.$createListNode(a);a.append(e);d.replace(a);e.append(d);return a}
|
|
5
|
+
function x(d,a){d.update(()=>{l.$log("formatList");var b=l.$getSelection();if(null!==b){var c=b.getNodes();b=b.anchor.getNode();var e=b.getParent();if(0===c.length)c=p.$createListNode(a),l.$isRootNode(e)?(b.replace(c),b=m.$createListItemNode(),c.append(b)):m.$isListItemNode(b)&&(b=b.getParentOrThrow(),c.append(...b.getChildren()),b.replace(c));else for(b=new Set,e=0;e<c.length;e++){var f=c[e];if(l.$isElementNode(f)&&f.isEmpty()&&!b.has(f.getKey()))w(f,a);else if(l.$isLeafNode(f))for(f=f.getParent();null!=
|
|
6
|
+
f;){const k=f.getKey();if(p.$isListNode(f)){if(!b.has(k)){var h=p.$createListNode(a);h.append(...f.getChildren());f.replace(h);b.add(k)}break}else{h=f.getParent();if(l.$isRootNode(h)&&!b.has(k)){b.add(k);w(f,a);break}f=h}}}}})}
|
|
7
|
+
function y(d){var a=l.$getSelection();if(null===a)return!1;var b=a.getNodes(),c=[];0===b.length&&b.push(a.anchor.getNode());if(1===b.length){a:{for(b=b[0];null!==b;){if(m.$isListItemNode(b))break a;b=b.getParent()}b=null}null!==b&&(c=[b])}else{c=new Set;for(a=0;a<b.length;a++){const e=b[a];m.$isListItemNode(e)&&c.add(e)}c=Array.from(c)}return 0<c.length?("indent"===d?z(c):A(c),!0):!1}function B(d){return m.$isListItemNode(d)&&p.$isListNode(d.getFirstChild())}
|
|
8
|
+
function z(d){d.forEach(a=>{if(!B(a)){var b=a.getParent(),c=a.getNextSibling(),e=a.getPreviousSibling();if(B(c)&&B(e))e=e.getFirstChild(),p.$isListNode(e)&&(e.append(a),a=c.getFirstChild(),p.$isListNode(a)&&(c=a.getChildren(),e.append(...c),a.remove()),e.getChildren().forEach(f=>f.markDirty()));else if(B(c))c=c.getFirstChild(),p.$isListNode(c)&&(e=c.getFirstChild(),null!==e&&e.insertBefore(a),c.getChildren().forEach(f=>f.markDirty()));else if(B(e))c=e.getFirstChild(),p.$isListNode(c)&&(c.append(a),
|
|
9
|
+
c.getChildren().forEach(f=>f.markDirty()));else if(p.$isListNode(b)){const f=m.$createListItemNode(),h=p.$createListNode(b.getTag());f.append(h);h.append(a);e?e.insertAfter(f):c?c.insertBefore(f):b.append(f)}p.$isListNode(b)&&b.getChildren().forEach(f=>f.markDirty())}})}
|
|
10
|
+
function A(d){d.forEach(a=>{if(!B(a)){var b=a.getParent(),c=b?b.getParent():void 0,e=c?c.getParent():void 0;if(p.$isListNode(e)&&m.$isListItemNode(c)&&p.$isListNode(b)){var f=b?b.getFirstChild():void 0,h=b?b.getLastChild():void 0;if(a.is(f))c.insertBefore(a),b.isEmpty()&&c.remove();else if(a.is(h))c.insertAfter(a),b.isEmpty()&&c.remove();else{var k=b.getTag();f=m.$createListItemNode();const n=p.$createListNode(k);f.append(n);a.getPreviousSiblings().forEach(C=>n.append(C));h=m.$createListItemNode();
|
|
11
|
+
k=p.$createListNode(k);h.append(k);k.append(...a.getNextSiblings());c.insertBefore(f);c.insertAfter(h);c.replace(a)}b.getChildren().forEach(n=>n.markDirty());e.getChildren().forEach(n=>n.markDirty())}}})}
|
|
12
|
+
module.exports=function(d){g.useEffect(()=>d.addListener("command",a=>{if("indentContent"===a){if(y("indent"))return!0}else if("outdentContent"===a){if(y("outdent"))return!0}else{if("insertOrderedList"===a)return x(d,"ol"),!0;if("insertUnorderedList"===a)return x(d,"ul"),!0;if("removeList"===a)return v(d),!0}return!1},1),[d])};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';var h=require("lexical"),q=require("react"),v=require("lexical/ParagraphNode"),w=require("@lexical/react/withSubscriptions");const x="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,y=x&&"documentMode"in document?document.documentMode:null;x&&/Win/.test(navigator.platform);x&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream;const z=x&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),A=x&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
|
|
2
|
+
x&&/Version\/[\d\.]+.*Safari/.test(navigator.userAgent);x&&/^(?=.*Chrome).*/i.test(navigator.userAgent);const B=x&&"InputEvent"in window&&!y?"getTargetRanges"in new window.InputEvent("input"):!1;var C=x?q.useLayoutEffect:q.useEffect;function D(a,b){return"selectionchange"===a||"keyup"===a||"pointerup"===a||"pointercancel"===a?b.ownerDocument:b}
|
|
3
|
+
function E(a,b){C(()=>{const c=[],e=[];for(let d=0;d<a.length;d++){const [f,g]=a[d],k=l=>{const n=b.getRootElement();null!==n&&"true"===n.contentEditable&&g(l,b)};c.push(l=>{D(f,l).addEventListener(f,k)});e.push(l=>{D(f,l).removeEventListener(f,k)})}return b.addListener("root",(d,f)=>{null!==f&&e.forEach(g=>g(f));null!==d&&c.forEach(g=>g(d))})},[b,a])}
|
|
4
|
+
function F(a,b){const c=b.split(/\r?\n/);if(1===c.length)a.insertText(b);else{b=[];const e=c.length;for(let d=0;d<e;d++){const f=c[d];""!==f&&b.push(h.$createTextNode(f));d!==e-1&&b.push(h.$createLineBreakNode())}a.insertNodes(b)}}
|
|
5
|
+
function G(a){q.useEffect(()=>{const b=c=>{var e=a.getRootElement();if(document.activeElement===e&&(e=c.data,"string"===typeof e)){try{var d=JSON.parse(e)}catch(f){return}if(d&&"nuanria_messaging"===d.protocol&&"request"===d.type&&(d=d.payload)&&"makeChanges"===d.functionId&&(d=d.args)){const [f,g,k,l,n]=d;a.update(()=>{h.$log("useLexicalDragonSupport");const u=h.$getSelection();if(null!==u){var m=u.anchor;let r=m.getNode(),p=0,t=0;h.$isTextNode(r)&&0<=f&&0<=g&&(p=f,t=f+g,u.setTextNodeRange(r,p,r,
|
|
6
|
+
t));if(p!==t||""!==k)F(u,k),r=m.getNode();h.$isTextNode(r)&&(p=l,t=l+n,m=r.getTextContentSize(),p=p>m?m:p,t=t>m?m:t,u.setTextNodeRange(r,p,r,t));c.stopImmediatePropagation()}})}}};window.addEventListener("message",b,!0);return()=>{window.removeEventListener("message",b,!0)}},[a])}function H(a){return a.isToken()||a.isInert()}let I=!1;function J(a,b){a=a.getData("text/plain");null!=a&&F(b,a)}
|
|
7
|
+
function K(a,b){var c=a.focus;a=c.offset;"element"===c.type?b=c.getNode().getChildAtIndex(b?a-1:a):(c=c.getNode(),b=b&&0===a||!b&&a===c.getTextContentSize()?b?c.getPreviousSibling():c.getNextSibling():null);return h.$isDecoratorNode(b)}function L(a){a.preventDefault()}
|
|
8
|
+
function M(a,b){a.preventDefault();b.update(()=>{h.$log("onCopyForPlainText");const c=a.clipboardData,e=h.$getSelection();if(null!==e&&null!=c){var d=window.getSelection();if(!d.isCollapsed){var f=d.getRangeAt(0);f&&(d=document.createElement("div"),f=f.cloneContents(),d.appendChild(f),c.setData("text/html",d.innerHTML));c.setData("text/plain",e.getTextContent())}}})}function N(a,b){b.update(()=>{h.$log("onCompositionEnd");h.$setCompositionKey(null);O(b,!0)})}
|
|
9
|
+
function P(a){return a.getEditorState().read(()=>h.$getSelection())}
|
|
10
|
+
function Q(a,b,c,e,d){if(a.isAttached()&&(d||!a.isDirty())){const f=a.isComposing();let g=b;(f||d)&&"\u00a0"===b[b.length-1]&&(g=b.slice(0,-1));if(d||g!==a.getTextContent())""===g?(f&&h.$setCompositionKey(null),a.remove()):H(a)||null!==h.$getCompositionKey()&&!f?a.markDirty():(b=h.$getSelection(),null!==b&&null!==c&&null!==e&&(b.setTextNodeRange(a,c,a,e),a.isSegmented()&&(c=a.getTextContent(),c=h.$createTextNode(c),a.replace(c),a=c)),a.setTextContent(g))}}
|
|
11
|
+
function R(a,b,c){var e=a.anchor;const d=a.focus;var f=e.getNode();(b=e.key!==d.key||e.offset!==d.offset&&!f.isComposing()||(c||f.isDirty())&&1<b.length||!h.$isTextNode(f)||f.getFormat()!==a.format)||(f.isSegmented()?b=!0:a.isCollapsed()?(b=a.anchor.offset,c=f.getParentOrThrow(),e=f.isToken(),a=0===b&&(!f.canInsertTextBefore()||!c.canInsertTextBefore()||e),f=f.getTextContentSize()===b&&(!f.canInsertTextBefore()||!c.canInsertTextBefore()||e),b=a||f):b=!1);return b}
|
|
12
|
+
function S(a,b){const c=a.inputType;"deleteCompositionText"!==c&&"insertCompositionText"!==c&&b.update(()=>{h.$log("onBeforeInputForRichText");const e=h.$getSelection();if(null!==e)if("deleteContentBackward"===c)h.$setCompositionKey(null),a.preventDefault(),b.execCommand("deleteCharacter",!0);else{var d=a.data;if(!e.dirty&&e.isCollapsed()&&a.getTargetRanges){var f=a.getTargetRanges()[0];f&&e.applyDOMRange(f)}var g=e.focus;f=e.anchor.getNode();g=g.getNode();if("insertText"===c)"\n"===d?(a.preventDefault(),
|
|
13
|
+
b.execCommand("insertLineBreak")):"\n\n"===d?(a.preventDefault(),b.execCommand("insertParagraph")):null==d&&a.dataTransfer?(d=a.dataTransfer.getData("text/plain"),a.preventDefault(),F(e,d)):null!=d&&R(e,d,!0)&&(a.preventDefault(),b.execCommand("insertText",d));else switch(a.preventDefault(),c){case "insertFromComposition":d&&(h.$setCompositionKey(null),b.execCommand("insertText",d));break;case "insertLineBreak":h.$setCompositionKey(null);b.execCommand("insertLineBreak");break;case "insertParagraph":h.$setCompositionKey(null);
|
|
14
|
+
b.execCommand("insertParagraph");break;case "insertFromYank":case "insertFromDrop":case "insertReplacementText":case "insertFromPaste":f=a.dataTransfer;null!=f?J(f,e):d&&b.execCommand("insertText",d);break;case "deleteByComposition":f===g&&!h.$isElementNode(f)&&!h.$isElementNode(g)&&H(f)&&H(g)||b.execCommand("removeText");break;case "deleteByDrag":case "deleteByCut":b.execCommand("removeText");break;case "deleteContent":b.execCommand("deleteCharacter",!1);break;case "deleteWordBackward":b.execCommand("deleteWord",
|
|
15
|
+
!0);break;case "deleteWordForward":b.execCommand("deleteWord",!1);break;case "deleteHardLineBackward":case "deleteSoftLineBackward":b.execCommand("deleteLine",!0);break;case "deleteContentForward":case "deleteHardLineForward":case "deleteSoftLineForward":b.execCommand("deleteLine",!1);break;case "formatStrikeThrough":b.execCommand("formatText","strikethrough");break;case "formatBold":b.execCommand("formatText","bold");break;case "formatItalic":b.execCommand("formatText","italic");break;case "formatUnderline":b.execCommand("formatText",
|
|
16
|
+
"underline");break;case "historyUndo":b.execCommand("undo");break;case "historyRedo":b.execCommand("redo")}}})}function O(a,b){a=window.getSelection();if(null!==a){var {anchorNode:c,anchorOffset:e,focusOffset:d}=a;null!==c&&3===c.nodeType&&(a=h.$getNearestNodeFromDOMNode(c),h.$isTextNode(a)&&Q(a,c.nodeValue,e,d,b))}}function T(a){Q(a.node,a.text,a.anchorOffset,a.focusOffset,!1)}
|
|
17
|
+
const U=[["selectionchange",function(a,b){a=window.getSelection();const c=b.getRootElement();c&&!c.contains(a.anchorNode)||b.update(()=>{h.$log("onSelectionChange");const e=h.$getSelection();if(null!==e&&e.isCollapsed()){var d=e.anchor;"text"===d.type?(d=d.getNode(),e.format=d.getFormat()):"element"===d.type&&(e.format=0)}b.execCommand("selectionChange")})}],["keydown",function(a,b){I="Unidentified"===a.key&&229===a.keyCode;b.isComposing()||b.update(()=>{h.$log("onKeyDown");if(null!==h.$getSelection()){var {keyCode:c,
|
|
18
|
+
shiftKey:e,ctrlKey:d,metaKey:f,altKey:g}=a;if(39!==c||d||f||g)if(37!==c||d||f||g)if(38!==c||d||f||g)if(40!==c||d||f||g)if(13===c&&e)b.execCommand("keyEnter",a);else if(z&&d&&79===c)a.preventDefault(),b.execCommand("insertLineBreak",!0);else if(13!==c||e){var k=z?g||f?!1:8===c||72===c&&d:d||g||f?!1:8===c;k?8===c?b.execCommand("keyBackspace",a):b.execCommand("deleteCharacter",!0):(k=z?e||g||f?!1:46===c||68===c&&d:d||g||f?!1:46===c,k?46===c?b.execCommand("keyDelete",a):b.execCommand("deleteCharacter",
|
|
19
|
+
!1):8===c&&(z?g:d)?(a.preventDefault(),b.execCommand("deleteWord",!0)):46===c&&(z?g:d)?(a.preventDefault(),b.execCommand("deleteWord",!1)):z&&f&&8===c?(a.preventDefault(),b.execCommand("deleteLine",!0)):z&&f&&46===c?(a.preventDefault(),b.execCommand("deleteLine",!1)):66===c&&(z?f:d)?(a.preventDefault(),b.execCommand("formatText","bold")):85===c&&(z?f:d)?(a.preventDefault(),b.execCommand("formatText","underline")):73===c&&(z?f:d)?(a.preventDefault(),b.execCommand("formatText","italic")):9!==c||g||
|
|
20
|
+
d||f?90===c&&!e&&(z?f:d)?(a.preventDefault(),b.execCommand("undo")):(k=z?90===c&&f&&e:89===c&&d||90===c&&d&&e,k&&(a.preventDefault(),b.execCommand("redo"))):b.execCommand("keyTab",a))}else b.execCommand("keyEnter",a);else b.execCommand("keyArrowDown",a);else b.execCommand("keyArrowUp",a);else b.execCommand("keyArrowLeft",a);else b.execCommand("keyArrowRight",a)}})}],["compositionstart",function(a,b){b.update(()=>{h.$log("onCompositionStart");const c=h.$getSelection();if(null!==c&&!b.isComposing()){const e=
|
|
21
|
+
c.anchor;h.$setCompositionKey(e.key);null==a.data||I&&"element"!==e.type&&c.isCollapsed()||b.execCommand("insertText"," ")}})}],["compositionend",function(a,b){A?setTimeout(()=>{N(a,b)},0):N(a,b)}],["cut",function(a,b){M(a,b);b.update(()=>{h.$log("onCutForPlainText");const c=h.$getSelection();null!==c&&c.removeText()})}],["copy",M],["dragstart",function(a){a.preventDefault()}],["paste",function(a,b){a.preventDefault();b.update(()=>{h.$log("onPasteForPlainText");const c=h.$getSelection(),e=a.clipboardData;
|
|
22
|
+
null!=e&&null!==c&&J(e,c)})}],["input",function(a,b){a.stopPropagation();b.update(()=>{h.$log("onInput");const c=h.$getSelection(),e=a.data;null!=e&&null!==c&&R(c,e,!1)?b.execCommand("insertText",e):O(b,!1);h.$flushMutations()})}],["click",function(a,b){b.update(()=>{h.$log("onClick");const c=h.$getSelection();if(null!==c){var e=c.anchor;"element"===e.type&&0===e.offset&&c.isCollapsed()&&1===h.$getRoot().getChildrenSize()&&e.getNode().getTopLevelElementOrThrow().isEmpty()&&(e=P(b),null!==e&&c.is(e)&&
|
|
23
|
+
(window.getSelection().removeAllRanges(),c.dirty=!0))}})}]];B?U.push(["beforeinput",S]):U.push(["drop",L]);function V(a,b){const c=v.$createParagraphNode();a.append(c);a=document.activeElement;(null!==h.$getSelection()||null!==a&&a===b.getRootElement())&&c.select()}function W(a){a.update(()=>{h.$log("initEditor");const b=h.$getRoot();null===b.getFirstChild()&&V(b,a)})}function X(a,b){a.update(()=>{h.$log("clearEditor");const c=h.$getRoot();c.clear();V(c,a)},{onUpdate:b})}
|
|
24
|
+
function Y(a,b){C(()=>{const c=w(a.registerNodes([v.ParagraphNode]),a.addListener("textmutation",T),a.addListener("command",(e,d)=>{const f=h.$getSelection();if(null===f)return!1;switch(e){case "deleteCharacter":return f.deleteCharacter(d),!0;case "deleteWord":return f.deleteWord(d),!0;case "deleteLine":return f.deleteLine(d),!0;case "insertText":return f.insertText(d),!0;case "removeText":return f.removeText(),!0;case "insertLineBreak":return f.insertLineBreak(d),!0;case "insertParagraph":return f.insertLineBreak(),
|
|
25
|
+
!0;case "indentContent":case "outdentContent":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":e=d.shiftKey;if(K(f,!0))return d.preventDefault(),d=e,e="rtl"===f.anchor.getNode().getParentOrThrow().getDirection(),f.modify(d?"extend":"move",!e,"character"),!0;break;case "keyArrowRight":e=d.shiftKey;if(K(f,!1))return d.preventDefault(),d=e,e="rtl"===f.anchor.getNode().getParentOrThrow().getDirection(),f.modify(d?"extend":"move",e,"character"),
|
|
26
|
+
!0;break;case "keyBackspace":return d.preventDefault(),a.execCommand("deleteCharacter",!0);case "keyDelete":return d.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return d.preventDefault(),a.execCommand("insertLineBreak");case "clearEditor":X(a)}return!1},0));b&&W(a);return c},[a,b]);E(U,a);G(a)}
|
|
27
|
+
function Z(a,b,c){b=Array.from(b);c=Array.from(c);a=a._nodeMap;const e=[];for(var d=0;d<b.length;d++){const f=a.get(b[d]);void 0!==f&&e.push(f)}for(b=0;b<c.length;b++)c[b][1]&&(d=a.get(c[b][0]),void 0===d||h.$isRootNode(d)||e.push(d));return e}
|
|
28
|
+
function aa(a,b,c,e,d){if(null===a||0===c.size&&0===e.size)return 0;var f=b._selection,g=a._selection;if(d)return 1;if(null===f||null===g||!g.isCollapsed()||!f.isCollapsed())return 0;c=Z(b,c,e);if(0===c.length)return 0;if(1<c.length){b=b._nodeMap;g=b.get(g.anchor.key);const k=b.get(f.anchor.key);return h.$isTextNode(k)&&h.$isElementNode(g)&&!a._nodeMap.has(k.__key)&&1===k.__text.length&&1===f.anchor.offset?c.every(l=>l===k||!h.$isTextNode(l))?2:0:0}b=c[0];a=a._nodeMap.get(b.__key);if(!h.$isTextNode(a)||
|
|
29
|
+
!h.$isTextNode(b)||a.__mode!==b.__mode)return 0;a=a.__text;b=b.__text;if(a===b)return 0;f=f.anchor;g=g.anchor;if(f.key!==g.key||"text"!==f.type)return 0;f=f.offset;g=g.offset;a=b.length-a.length;return 1===a&&g===f-1?2:-1===a&&g===f+1?3:-1===a&&g===f?4:0}
|
|
30
|
+
function ba(a,b){let c=Date.now(),e=0;return(d,f,g,k,l,n)=>{const u=Date.now();if(n.has("historic"))return e=0,c=u,2;const m=aa(d,f,k,l,a.isComposing()),r=(()=>{if(n.has("without-history"))return 0;if(null===d)return 1;var p=f._selection;const t=d._selection;if(!(0<k.size||0<l.size))return null===t&&null!==p?0:2;p=null===g||g.editor===a;return 0!==m&&m===e&&u<c+b&&p?0:1})();c=u;e=m;return r}}
|
|
31
|
+
function ca(a,b,c=1E3){const e=q.useMemo(()=>b||{current:null,redoStack:[],undoStack:[]},[b]),d=q.useCallback(()=>{e.undoStack=[];e.redoStack=[];e.current=null},[e]);q.useEffect(()=>{const f=ba(a,c);return w(a.addListener("command",g=>{switch(g){case "undo":g=e.redoStack;var k=e.undoStack;if(0!==k.length){var l=e.current;const n=k.pop();null!==l&&(g.push(l),a.execCommand("canRedo",!0));0===k.length&&a.execCommand("canUndo",!1);e.current=n;n.editor.setEditorState(n.editorState.clone(n.undoSelection),
|
|
32
|
+
{tag:"historic"})}return!0;case "redo":return g=e.redoStack,k=e.undoStack,0!==g.length&&(l=e.current,null!==l&&(k.push(l),a.execCommand("canUndo",!0)),k=g.pop(),0===g.length&&a.execCommand("canRedo",!1),e.current=k,k.editor.setEditorState(k.editorState,{tag:"historic"})),!0;case "clearEditor":case "clearHistory":return d(),!0;default:return!1}},0),a.addListener("update",({editorState:g,prevEditorState:k,dirtyLeaves:l,dirtyElements:n,tags:u})=>{const m=e.current,r=e.redoStack,p=e.undoStack,t=null===
|
|
33
|
+
m?null:m.editorState;if(null===m||g!==t){l=f(k,g,m,l,n,u);if(1===l)0!==r.length&&(e.redoStack=[]),null!==m&&(p.push({...m,undoSelection:k.read(h.$getSelection)}),a.execCommand("canUndo",!0));else if(2===l)return;e.current={editor:a,editorState:g}}}))},[d,c,a,e])}module.exports=function(a,b){Y(a,!0);ca(a,b)};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';var h=require("lexical"),u=require("react"),v=require("lexical/HeadingNode"),x=require("lexical/ListNode"),y=require("lexical/QuoteNode"),A=require("lexical/CodeNode"),B=require("lexical/ParagraphNode"),C=require("lexical/ListItemNode"),D=require("lexical/LinkNode"),E=require("@lexical/react/withSubscriptions");
|
|
2
|
+
const F="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,G=F&&"documentMode"in document?document.documentMode:null;F&&/Win/.test(navigator.platform);F&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream;const H=F&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),I=F&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);F&&/Version\/[\d\.]+.*Safari/.test(navigator.userAgent);F&&/^(?=.*Chrome).*/i.test(navigator.userAgent);
|
|
3
|
+
const aa=F&&"InputEvent"in window&&!G?"getTargetRanges"in new window.InputEvent("input"):!1;var J=F?u.useLayoutEffect:u.useEffect;function K(a,b){return"selectionchange"===a||"keyup"===a||"pointerup"===a||"pointercancel"===a?b.ownerDocument:b}
|
|
4
|
+
function ba(a,b){J(()=>{const f=[],d=[];for(let e=0;e<a.length;e++){const [c,g]=a[e],k=l=>{const m=b.getRootElement();null!==m&&"true"===m.contentEditable&&g(l,b)};f.push(l=>{K(c,l).addEventListener(c,k)});d.push(l=>{K(c,l).removeEventListener(c,k)})}return b.addListener("root",(e,c)=>{null!==c&&d.forEach(g=>g(c));null!==e&&f.forEach(g=>g(e))})},[b,a])}
|
|
5
|
+
function L(a){a=a.getLatest();const b=a.constructor.clone(a);b.__parent=a.__parent;h.$isElementNode(a)&&h.$isElementNode(b)?(b.__children=Array.from(a.__children),b.__format=a.__format,b.__indent=a.__indent,b.__dir=a.__dir):h.$isTextNode(a)&&h.$isTextNode(b)?(b.__format=a.__format,b.__style=a.__style,b.__mode=a.__mode,b.__detail=a.__detail):h.$isDecoratorNode(a)&&h.$isDecoratorNode(b)&&(b.__ref=a.__ref);return b}
|
|
6
|
+
function M(a,b,f,d,e){for(var c=b;null!==a;){for(b=a.getParent();null!==b&&b.excludeFromCopy();)b=b.getParent();if(null===b)break;if(!h.$isElementNode(a)||!a.excludeFromCopy()){const g=a.getKey();let k=e.get(g);const l=void 0===k;l&&(k=L(a),e.set(g,k));!h.$isTextNode(k)||k.isSegmented()||k.isToken()?h.$isElementNode(k)&&(k.__children=k.__children.slice(f?c:0,f?void 0:c+1)):k.__text=k.__text.slice(f?c:0,f?void 0:c);if(h.$isRootNode(b)){l&&d.push(g);break}}c=e.get(b.getKey());c=h.$isElementNode(c)?
|
|
7
|
+
c.__children.indexOf(a.getKey()):a.getIndexWithinParent();a=b}}function N(a,b){const f=b.split(/\r?\n/);if(1===f.length)a.insertText(b);else{b=[];const d=f.length;for(let e=0;e<d;e++){const c=f[e];""!==c&&b.push(h.$createTextNode(c));e!==d-1&&b.push(h.$createLineBreakNode())}a.insertNodes(b)}}
|
|
8
|
+
function ca(a){u.useEffect(()=>{const b=f=>{var d=a.getRootElement();if(document.activeElement===d&&(d=f.data,"string"===typeof d)){try{var e=JSON.parse(d)}catch(c){return}if(e&&"nuanria_messaging"===e.protocol&&"request"===e.type&&(e=e.payload)&&"makeChanges"===e.functionId&&(e=e.args)){const [c,g,k,l,m]=e;a.update(()=>{h.$log("useLexicalDragonSupport");const p=h.$getSelection();if(null!==p){var n=p.anchor;let r=n.getNode(),q=0,t=0;h.$isTextNode(r)&&0<=c&&0<=g&&(q=c,t=c+g,p.setTextNodeRange(r,q,
|
|
9
|
+
r,t));if(q!==t||""!==k)N(p,k),r=n.getNode();h.$isTextNode(r)&&(q=l,t=l+m,n=r.getTextContentSize(),q=q>n?n:q,t=t>n?n:t,p.setTextNodeRange(r,q,r,t));f.stopImmediatePropagation()}})}}};window.addEventListener("message",b,!0);return()=>{window.removeEventListener("message",b,!0)}},[a])}function O(a){return a.isToken()||a.isInert()}const da={bold:1,underline:8,strikethrough:4,italic:2,code:16,subscript:32,superscript:64};let P=!1;
|
|
10
|
+
const ea={ul:()=>({node:x.$createListNode("ul")}),ol:()=>({node:x.$createListNode("ol")}),li:()=>({node:C.$createListItemNode()}),h1:()=>({node:v.$createHeadingNode("h1")}),h2:()=>({node:v.$createHeadingNode("h2")}),h3:()=>({node:v.$createHeadingNode("h3")}),h4:()=>({node:v.$createHeadingNode("h4")}),h5:()=>({node:v.$createHeadingNode("h5")}),p:()=>({node:B.$createParagraphNode()}),br:()=>({node:h.$createLineBreakNode()}),a:a=>({node:a instanceof HTMLAnchorElement?D.$createLinkNode(a.href):h.$createTextNode(a.textContent)}),
|
|
11
|
+
u:()=>({node:null,format:"underline"}),b:()=>({node:null,format:"bold"}),strong:()=>({node:null,format:"bold"}),i:()=>({node:null,format:"italic"}),em:()=>({node:null,format:"italic"}),"#text":a=>({node:h.$createTextNode(a.textContent)})};
|
|
12
|
+
function Q(a,b,f,d){let e=[],c=null;var g=a.nodeName.toLowerCase();g=(g=(f._config.htmlTransforms||{})[g]||b[g])?g(a):null;null!==g&&(c=g.node,g.format&&(g=da[g.format],d=d?d^g:g),null!==c&&(h.$isTextNode(c)&&void 0!==d&&c.setFormat(d),e.push(c)));a=a.childNodes;for(g=0;g<a.length;g++){const k=Q(a[g],b,f,d);h.$isElementNode(c)?c.append(...k):null===c&&(e=e.concat(k))}return e}function R(a,b){a=a.getData("text/plain");null!=a&&N(b,a)}
|
|
13
|
+
function S(a,b){var f=a.focus;a=f.offset;"element"===f.type?b=f.getNode().getChildAtIndex(b?a-1:a):(f=f.getNode(),b=b&&0===a||!b&&a===f.getTextContentSize()?b?f.getPreviousSibling():f.getNextSibling():null);return h.$isDecoratorNode(b)}function fa(a){a.preventDefault()}
|
|
14
|
+
function T(a,b){a.preventDefault();b.update(()=>{h.$log("onCopyForRichText");const f=a.clipboardData;var d=h.$getSelection();if(null!==d&&null!=f){var e=window.getSelection();if(!e.isCollapsed){var c=e.getRangeAt(0);c&&(e=document.createElement("div"),c=c.cloneContents(),e.appendChild(c),f.setData("text/html",e.innerHTML));f.setData("text/plain",d.getTextContent());e=f.setData;c=JSON;var g=c.stringify;{var k=d.anchor,l=d.focus;var m=k.getCharacterOffset();const z=l.getCharacterOffset();var p=k.getNode(),
|
|
15
|
+
n=l.getNode(),r=p.getParentOrThrow();if(p===n&&h.$isTextNode(p)&&(r.canBeEmpty()||1<r.getChildrenSize()))d=L(p),p=z>m,d.__text=d.__text.slice(p?m:z,p?z:m),m=d.getKey(),m={range:[m],nodeMap:[[m,d]]};else if(d=d.getNodes(),0===d.length)m={range:[],nodeMap:[]};else{p=d.length;n=d[0];r=n.getParent();if(null!==r&&!r.canBeEmpty()){var q=r.__children;if(q.length===p){var t=!0;for(var w=0;w<q.length;w++)if(q[w]!==d[w].__key){t=!1;break}t&&(p++,d.push(r))}}r=d[p-1];k=k.isBefore(l);l=new Map;q=[];M(n,k?m:z,
|
|
16
|
+
!0,q,l);for(n=0;n<p;n++)if(t=d[n],w=t.getKey(),!(l.has(w)||h.$isElementNode(t)&&t.excludeFromCopy())){const ha=L(t);h.$isRootNode(t.getParent())&&q.push(t.getKey());l.set(w,ha)}M(r,k?z:m,!1,q,l);m={range:q,nodeMap:Array.from(l.entries())}}}e.call(f,"application/x-lexical-nodes",g.call(c,m))}}})}function U(a,b){b.update(()=>{h.$log("onCompositionEnd");h.$setCompositionKey(null);V(b,!0)})}function ia(a){return a.getEditorState().read(()=>h.$getSelection())}
|
|
17
|
+
function W(a,b,f,d,e){if(a.isAttached()&&(e||!a.isDirty())){const c=a.isComposing();let g=b;(c||e)&&"\u00a0"===b[b.length-1]&&(g=b.slice(0,-1));if(e||g!==a.getTextContent())""===g?(c&&h.$setCompositionKey(null),a.remove()):O(a)||null!==h.$getCompositionKey()&&!c?a.markDirty():(b=h.$getSelection(),null!==b&&null!==f&&null!==d&&(b.setTextNodeRange(a,f,a,d),a.isSegmented()&&(f=a.getTextContent(),f=h.$createTextNode(f),a.replace(f),a=f)),a.setTextContent(g))}}
|
|
18
|
+
function X(a,b,f){var d=a.anchor;const e=a.focus;var c=d.getNode();(b=d.key!==e.key||d.offset!==e.offset&&!c.isComposing()||(f||c.isDirty())&&1<b.length||!h.$isTextNode(c)||c.getFormat()!==a.format)||(c.isSegmented()?b=!0:a.isCollapsed()?(b=a.anchor.offset,f=c.getParentOrThrow(),d=c.isToken(),a=0===b&&(!c.canInsertTextBefore()||!f.canInsertTextBefore()||d),c=c.getTextContentSize()===b&&(!c.canInsertTextBefore()||!f.canInsertTextBefore()||d),b=a||c):b=!1);return b}
|
|
19
|
+
function ja(a,b){const f=a.inputType;"deleteCompositionText"!==f&&"insertCompositionText"!==f&&b.update(()=>{h.$log("onBeforeInputForRichText");const d=h.$getSelection();if(null!==d)if("deleteContentBackward"===f)h.$setCompositionKey(null),a.preventDefault(),b.execCommand("deleteCharacter",!0);else{var e=a.data;if(!d.dirty&&d.isCollapsed()&&a.getTargetRanges){var c=a.getTargetRanges()[0];c&&d.applyDOMRange(c)}var g=d.focus;c=d.anchor.getNode();g=g.getNode();if("insertText"===f)"\n"===e?(a.preventDefault(),
|
|
20
|
+
b.execCommand("insertLineBreak")):"\n\n"===e?(a.preventDefault(),b.execCommand("insertParagraph")):null==e&&a.dataTransfer?(e=a.dataTransfer.getData("text/plain"),a.preventDefault(),N(d,e)):null!=e&&X(d,e,!0)&&(a.preventDefault(),b.execCommand("insertText",e));else switch(a.preventDefault(),f){case "insertFromComposition":e&&(h.$setCompositionKey(null),b.execCommand("insertText",e));break;case "insertLineBreak":h.$setCompositionKey(null);b.execCommand("insertLineBreak");break;case "insertParagraph":h.$setCompositionKey(null);
|
|
21
|
+
b.execCommand("insertParagraph");break;case "insertFromYank":case "insertFromDrop":case "insertReplacementText":case "insertFromPaste":c=a.dataTransfer;null!=c?R(c,d):e&&b.execCommand("insertText",e);break;case "deleteByComposition":c===g&&!h.$isElementNode(c)&&!h.$isElementNode(g)&&O(c)&&O(g)||b.execCommand("removeText");break;case "deleteByDrag":case "deleteByCut":b.execCommand("removeText");break;case "deleteContent":b.execCommand("deleteCharacter",!1);break;case "deleteWordBackward":b.execCommand("deleteWord",
|
|
22
|
+
!0);break;case "deleteWordForward":b.execCommand("deleteWord",!1);break;case "deleteHardLineBackward":case "deleteSoftLineBackward":b.execCommand("deleteLine",!0);break;case "deleteContentForward":case "deleteHardLineForward":case "deleteSoftLineForward":b.execCommand("deleteLine",!1);break;case "formatStrikeThrough":b.execCommand("formatText","strikethrough");break;case "formatBold":b.execCommand("formatText","bold");break;case "formatItalic":b.execCommand("formatText","italic");break;case "formatUnderline":b.execCommand("formatText",
|
|
23
|
+
"underline");break;case "historyUndo":b.execCommand("undo");break;case "historyRedo":b.execCommand("redo")}}})}function V(a,b){a=window.getSelection();if(null!==a){var {anchorNode:f,anchorOffset:d,focusOffset:e}=a;null!==f&&3===f.nodeType&&(a=h.$getNearestNodeFromDOMNode(f),h.$isTextNode(a)&&W(a,f.nodeValue,d,e,b))}}function ka(a){W(a.node,a.text,a.anchorOffset,a.focusOffset,!1)}
|
|
24
|
+
const Y=[["selectionchange",function(a,b){a=window.getSelection();const f=b.getRootElement();f&&!f.contains(a.anchorNode)||b.update(()=>{h.$log("onSelectionChange");const d=h.$getSelection();if(null!==d&&d.isCollapsed()){var e=d.anchor;"text"===e.type?(e=e.getNode(),d.format=e.getFormat()):"element"===e.type&&(d.format=0)}b.execCommand("selectionChange")})}],["keydown",function(a,b){P="Unidentified"===a.key&&229===a.keyCode;b.isComposing()||b.update(()=>{h.$log("onKeyDown");if(null!==h.$getSelection()){var {keyCode:f,
|
|
25
|
+
shiftKey:d,ctrlKey:e,metaKey:c,altKey:g}=a;if(39!==f||e||c||g)if(37!==f||e||c||g)if(38!==f||e||c||g)if(40!==f||e||c||g)if(13===f&&d)b.execCommand("keyEnter",a);else if(H&&e&&79===f)a.preventDefault(),b.execCommand("insertLineBreak",!0);else if(13!==f||d){var k=H?g||c?!1:8===f||72===f&&e:e||g||c?!1:8===f;k?8===f?b.execCommand("keyBackspace",a):b.execCommand("deleteCharacter",!0):(k=H?d||g||c?!1:46===f||68===f&&e:e||g||c?!1:46===f,k?46===f?b.execCommand("keyDelete",a):b.execCommand("deleteCharacter",
|
|
26
|
+
!1):8===f&&(H?g:e)?(a.preventDefault(),b.execCommand("deleteWord",!0)):46===f&&(H?g:e)?(a.preventDefault(),b.execCommand("deleteWord",!1)):H&&c&&8===f?(a.preventDefault(),b.execCommand("deleteLine",!0)):H&&c&&46===f?(a.preventDefault(),b.execCommand("deleteLine",!1)):66===f&&(H?c:e)?(a.preventDefault(),b.execCommand("formatText","bold")):85===f&&(H?c:e)?(a.preventDefault(),b.execCommand("formatText","underline")):73===f&&(H?c:e)?(a.preventDefault(),b.execCommand("formatText","italic")):9!==f||g||
|
|
27
|
+
e||c?90===f&&!d&&(H?c:e)?(a.preventDefault(),b.execCommand("undo")):(k=H?90===f&&c&&d:89===f&&e||90===f&&e&&d,k&&(a.preventDefault(),b.execCommand("redo"))):b.execCommand("keyTab",a))}else b.execCommand("keyEnter",a);else b.execCommand("keyArrowDown",a);else b.execCommand("keyArrowUp",a);else b.execCommand("keyArrowLeft",a);else b.execCommand("keyArrowRight",a)}})}],["compositionstart",function(a,b){b.update(()=>{h.$log("onCompositionStart");const f=h.$getSelection();if(null!==f&&!b.isComposing()){const d=
|
|
28
|
+
f.anchor;h.$setCompositionKey(d.key);null==a.data||P&&"element"!==d.type&&f.isCollapsed()||b.execCommand("insertText"," ")}})}],["compositionend",function(a,b){I?setTimeout(()=>{U(a,b)},0):U(a,b)}],["cut",function(a,b){T(a,b);b.update(()=>{h.$log("onCutForRichText");const f=h.$getSelection();null!==f&&f.removeText()})}],["copy",T],["dragstart",function(a){a.preventDefault()}],["paste",function(a,b){a.preventDefault();b.update(()=>{h.$log("onPasteForRichText");const f=h.$getSelection();var d=a.clipboardData;
|
|
29
|
+
if(null!=d&&null!==f)a:{var e=d.getData("application/x-lexical-nodes");if(e)try{var c=JSON.parse(e);const {range:m,nodeMap:p}=c;var g=new Map(p);e=[];for(c=0;c<m.length;c++){var k=g.get(m[c]);if(void 0!==k){var l=h.$createNodeFromParse(k,g);e.push(l)}}f.insertNodes(e);break a}catch(m){}if(g=d.getData("text/html")){g=(new DOMParser).parseFromString(g,"text/html");d=[];g=g.body?Array.from(g.body.childNodes):[];k=g.length;for(l=0;l<k;l++)e=Q(g[l],ea,b),null!==e&&(d=d.concat(e));g=[];k=null;for(l=0;l<
|
|
30
|
+
d.length;l++)e=d[l],!h.$isElementNode(e)||e.isInline()?(null===k&&(k=B.$createParagraphNode(),g.push(k)),null!==k&&k.append(e)):(g.push(e),k=null);f.insertNodes(g)}else R(d,f)}})}],["input",function(a,b){a.stopPropagation();b.update(()=>{h.$log("onInput");const f=h.$getSelection(),d=a.data;null!=d&&null!==f&&X(f,d,!1)?b.execCommand("insertText",d):V(b,!1);h.$flushMutations()})}],["click",function(a,b){b.update(()=>{h.$log("onClick");const f=h.$getSelection();if(null!==f){var d=f.anchor;"element"===
|
|
31
|
+
d.type&&0===d.offset&&f.isCollapsed()&&1===h.$getRoot().getChildrenSize()&&d.getNode().getTopLevelElementOrThrow().isEmpty()&&(d=ia(b),null!==d&&f.is(d)&&(window.getSelection().removeAllRanges(),f.dirty=!0))}})}]];aa?Y.push(["beforeinput",ja]):Y.push(["drop",fa]);function Z(a,b){const f=B.$createParagraphNode();a.append(f);a=document.activeElement;(null!==h.$getSelection()||null!==a&&a===b.getRootElement())&&f.select()}
|
|
32
|
+
function la(a){a.update(()=>{h.$log("initEditor");const b=h.$getRoot();null===b.getFirstChild()&&Z(b,a)})}function ma(a,b){a.update(()=>{h.$log("clearEditor");const f=h.$getRoot();f.clear();Z(f,a)},{onUpdate:b})}
|
|
33
|
+
function na(a,b){J(()=>{const f=E(a.registerNodes([v.HeadingNode,x.ListNode,y.QuoteNode,A.CodeNode,B.ParagraphNode,C.ListItemNode]),a.addListener("textmutation",ka),a.addListener("command",(d,e)=>{var c=h.$getSelection();if(null===c)return!1;switch(d){case "deleteCharacter":return c.deleteCharacter(e),!0;case "deleteWord":return c.deleteWord(e),!0;case "deleteLine":return c.deleteLine(e),!0;case "insertText":return c.insertText(e),!0;case "removeText":return c.removeText(),!0;case "formatText":return c.formatText(e),
|
|
34
|
+
!0;case "formatElement":return c=c.anchor.getNode(),(h.$isElementNode(c)?c:c.getParentOrThrow()).setFormat(e),!0;case "insertLineBreak":return c.insertLineBreak(e),!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,e=c.getNode(),d="element"===c.type?c.getNode():
|
|
35
|
+
c.getNode().getParentOrThrow(),d.canInsertTab()?"\t"===e.getTextContent()[c.offset-1]&&a.execCommand("deleteCharacter",!0):0!==d.getIndent()&&d.setIndent(d.getIndent()-1),!0;case "keyArrowLeft":d=e.shiftKey;if(S(c,!0))return e.preventDefault(),e=d,d="rtl"===c.anchor.getNode().getParentOrThrow().getDirection(),c.modify(e?"extend":"move",!d,"character"),!0;break;case "keyArrowRight":d=e.shiftKey;if(S(c,!1))return e.preventDefault(),e=d,d="rtl"===c.anchor.getNode().getParentOrThrow().getDirection(),
|
|
36
|
+
c.modify(e?"extend":"move",d,"character"),!0;break;case "keyBackspace":return e.preventDefault(),a.execCommand("deleteCharacter",!0);case "keyDelete":return e.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return e.preventDefault(),e.shiftKey?a.execCommand("insertLineBreak"):a.execCommand("insertParagraph");case "keyTab":return e.preventDefault(),a.execCommand(e.shiftKey?"outdentContent":"indentContent");case "clearEditor":ma(a)}return!1},0));b&&la(a);return f},[a,b]);ba(Y,a);
|
|
37
|
+
ca(a)}function oa(a,b,f){b=Array.from(b);f=Array.from(f);a=a._nodeMap;const d=[];for(var e=0;e<b.length;e++){const c=a.get(b[e]);void 0!==c&&d.push(c)}for(b=0;b<f.length;b++)f[b][1]&&(e=a.get(f[b][0]),void 0===e||h.$isRootNode(e)||d.push(e));return d}
|
|
38
|
+
function pa(a,b,f,d,e){if(null===a||0===f.size&&0===d.size)return 0;var c=b._selection,g=a._selection;if(e)return 1;if(null===c||null===g||!g.isCollapsed()||!c.isCollapsed())return 0;f=oa(b,f,d);if(0===f.length)return 0;if(1<f.length){b=b._nodeMap;g=b.get(g.anchor.key);const k=b.get(c.anchor.key);return h.$isTextNode(k)&&h.$isElementNode(g)&&!a._nodeMap.has(k.__key)&&1===k.__text.length&&1===c.anchor.offset?f.every(l=>l===k||!h.$isTextNode(l))?2:0:0}b=f[0];a=a._nodeMap.get(b.__key);if(!h.$isTextNode(a)||
|
|
39
|
+
!h.$isTextNode(b)||a.__mode!==b.__mode)return 0;a=a.__text;b=b.__text;if(a===b)return 0;c=c.anchor;g=g.anchor;if(c.key!==g.key||"text"!==c.type)return 0;c=c.offset;g=g.offset;a=b.length-a.length;return 1===a&&g===c-1?2:-1===a&&g===c+1?3:-1===a&&g===c?4:0}
|
|
40
|
+
function qa(a,b){let f=Date.now(),d=0;return(e,c,g,k,l,m)=>{const p=Date.now();if(m.has("historic"))return d=0,f=p,2;const n=pa(e,c,k,l,a.isComposing()),r=(()=>{if(m.has("without-history"))return 0;if(null===e)return 1;var q=c._selection;const t=e._selection;if(!(0<k.size||0<l.size))return null===t&&null!==q?0:2;q=null===g||g.editor===a;return 0!==n&&n===d&&p<f+b&&q?0:1})();f=p;d=n;return r}}
|
|
41
|
+
function ra(a,b,f=1E3){const d=u.useMemo(()=>b||{current:null,redoStack:[],undoStack:[]},[b]),e=u.useCallback(()=>{d.undoStack=[];d.redoStack=[];d.current=null},[d]);u.useEffect(()=>{const c=qa(a,f);return E(a.addListener("command",g=>{switch(g){case "undo":g=d.redoStack;var k=d.undoStack;if(0!==k.length){var l=d.current;const m=k.pop();null!==l&&(g.push(l),a.execCommand("canRedo",!0));0===k.length&&a.execCommand("canUndo",!1);d.current=m;m.editor.setEditorState(m.editorState.clone(m.undoSelection),
|
|
42
|
+
{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":case "clearHistory":return e(),!0;default:return!1}},0),a.addListener("update",({editorState:g,prevEditorState:k,dirtyLeaves:l,dirtyElements:m,tags:p})=>{const n=d.current,r=d.redoStack,q=d.undoStack,t=null===
|
|
43
|
+
n?null:n.editorState;if(null===n||g!==t){l=c(k,g,n,l,m,p);if(1===l)0!==r.length&&(d.redoStack=[]),null!==n&&(q.push({...n,undoSelection:k.read(h.$getSelection)}),a.execCommand("canUndo",!0));else if(2===l)return;d.current={editor:a,editorState:g}}}))},[e,f,a,d])}module.exports=function(a,b){na(a,!0);ra(a,b)};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';module.exports=function(...a){return()=>{a.forEach(b=>b())}};
|