@tryghost/koenig-lexical 0.0.3 → 0.0.4
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.
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
*
|
|
29
29
|
* This source code is licensed under the MIT license found in the
|
|
30
30
|
* LICENSE file in the root directory of this source tree.
|
|
31
|
-
*/var vs=se.default,Ns=Symbol.for("react.element"),Cs=Symbol.for("react.fragment"),Ts=Object.prototype.hasOwnProperty,Ss=vs.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,ws={key:!0,ref:!0,__self:!0,__source:!0};function Bo(t,e,n){var r,i={},o=null,l=null;n!==void 0&&(o=""+n),e.key!==void 0&&(o=""+e.key),e.ref!==void 0&&(l=e.ref);for(r in e)Ts.call(e,r)&&!ws.hasOwnProperty(r)&&(i[r]=e[r]);if(t&&t.defaultProps)for(r in e=t.defaultProps,e)i[r]===void 0&&(i[r]=e[r]);return{$$typeof:Ns,type:t,key:o,ref:l,props:i,_owner:Ss.current}}kn.Fragment=Cs,kn.jsx=Bo,kn.jsxs=Bo,function(t){t.exports=kn}(pr);const Pe=pr.exports.jsx,Es=pr.exports.jsxs,Os=[hr.HeadingNode,fn.ListNode,fn.ListItemNode,hr.QuoteNode,ys.LinkNode];function $s(t){console.error(t)}const Ms={namespace:"KoenigEditor",theme:ks},Ds=({nodes:t=[...Os],onError:e=$s,children:n})=>{const r=se.default.useMemo(()=>Object.assign({},Ms,{nodes:t,onError:e}),[t,e]);return Pe(Ul.LexicalComposer,{initialConfig:r,children:n})};var zo={},ue={},J=ne;function _r(t,e=!0){return t?!1:(t=Ko(),e&&(t=t.trim()),t==="")}function Ko(){return J.$getRoot().getTextContent()}function Wo(t,e=!0){if(!e||!_r(t,!1)||(t=J.$getRoot().getChildren(),e=t.length,1<e))return!1;for(let r=0;r<e;r++){var n=t[r];if(J.$isElementNode(n)){if(n.__type!=="paragraph"||n.__indent!==0)return!1;n=n.getChildren();let i=n.length;for(let o=0;o<i;o++)if(!J.$isTextNode(n[r]))return!1}}return!0}ue.$canShowPlaceholder=Wo,ue.$canShowPlaceholderCurry=function(t,e=!0){return()=>Wo(t,e)},ue.$findNodeWithOffsetFromJoinedText=function(t,e,n,r){r=r.getChildren();let i=r.length,o=0,l=!1;for(let a=0;a<i&&!(o>e);++a){let d=r[a],u=J.$isTextNode(d);var s=u?d.getTextContent().length:n;if(s=o+s,(l===!1&&o===t||o===0&&o===t||o<t&&t<=s)&&J.$isTextNode(d))return{node:d,offset:t-o};o=s,l=u}return null},ue.$findTextIntersectionFromCharacters=function(t,e){var n=t.getFirstChild();t=0;e:for(;n!==null;){if(J.$isElementNode(n)){var r=n.getFirstChild();if(r!==null){n=r;continue}}else if(J.$isTextNode(n)){if(r=n.getTextContentSize(),t+r>e)return{node:n,offset:e-t};t+=r}if(r=n.getNextSibling(),r!==null)n=r;else{for(n=n.getParent();n!==null;){if(r=n.getNextSibling(),r!==null){n=r;continue e}n=n.getParent()}break}}return null},ue.$isRootTextContentEmpty=_r,ue.$isRootTextContentEmptyCurry=function(t,e){return()=>_r(t,e)},ue.$joinTextNodesInElementNode=function(t,e,n){let r="";t=t.getChildren();let i=t.length;for(let o=0;o<i;++o){let l=t[o];if(J.$isTextNode(l)){let s=l.getTextContent();if(l.is(n.node)){if(n.offset>s.length)throw Error("Minified Lexical error #2; visit https://lexical.dev/docs/error?code=2 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");r+=l.getTextContent().substr(0,n.offset);break}else r+=s}else r+=e}return r},ue.$rootTextContent=Ko,ue.registerLexicalTextEntity=function(t,e,n,r){let i=l=>{const s=J.$createTextNode(l.getTextContent());s.setFormat(l.getFormat()),l.replace(s)},o=t.registerNodeTransform(J.TextNode,l=>{if(l.isSimpleText()){var s=l.getPreviousSibling(),a=l.getTextContent(),d=l;if(J.$isTextNode(s)){var u=s.getTextContent(),g=e(u+a);if(s instanceof n){if(g===null||s.getLatest().__mode!==0){i(s);return}if(g=g.end-u.length,0<g){d=a.slice(0,g),d=u+d,s.select(),s.setTextContent(d),g===a.length?l.remove():(s=a.slice(g),l.setTextContent(s));return}}else if(g===null||g.start<u.length)return}for(;;){if(l=e(a),a=g=l===null?"":a.slice(l.end),g===""){if(u=d.getNextSibling(),J.$isTextNode(u)){if(g=d.getTextContent()+u.getTextContent(),g=e(g),g===null){u instanceof n?i(u):u.markDirty();break}else if(g.start!==0)break}}else if(u=e(g),u!==null&&u.start===0)break;if(l===null)break;if(l.start===0&&J.$isTextNode(s)&&s.isTextEntity())continue;let c;if(l.start===0?[c,d]=d.splitText(l.end):[,c,d]=d.splitText(l.start,l.end),l=r(c),c.replace(l),d==null)break}}});return t=t.registerNodeTransform(n,l=>{var s=l.getTextContent();const a=e(s);a===null||a.start!==0?i(l):s.length>a.end?l.splitText(a.end):(s=l.getPreviousSibling(),J.$isTextNode(s)&&s.isTextEntity()&&(i(s),i(l)),s=l.getNextSibling(),J.$isTextNode(s)&&s.isTextEntity()&&(i(s),l instanceof n&&i(l)))}),[o,t]};var Rs=ue,Yo={},vn=ne;Yo.registerDragonSupport=function(t){let e=n=>{var r=t.getRootElement();if(document.activeElement===r&&(r=n.data,typeof r=="string")){try{var i=JSON.parse(r)}catch{return}if(i&&i.protocol==="nuanria_messaging"&&i.type==="request"&&(i=i.payload)&&i.functionId==="makeChanges"&&(i=i.args)){const[o,l,s,a,d]=i;t.update(()=>{const u=vn.$getSelection();if(vn.$isRangeSelection(u)){var g=u.anchor;let c=g.getNode(),f=0,_=0;vn.$isTextNode(c)&&0<=o&&0<=l&&(f=o,_=o+l,u.setTextNodeRange(c,f,c,_)),(f!==_||s!=="")&&(u.insertRawText(s),c=g.getNode()),vn.$isTextNode(c)&&(f=a,_=a+d,g=c.getTextContentSize(),f=f>g?g:f,_=_>g?g:_,u.setTextNodeRange(c,f,c,_)),n.stopImmediatePropagation()}})}}};return window.addEventListener("message",e,!0),()=>{window.removeEventListener("message",e,!0)}};var As=Yo,Ls=Fe,Ce=se.default,Ps=Rs,bo=De,Ho=rl.default,Is=As,Fs=hr,mr=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u"?Ce.useLayoutEffect:Ce.useEffect;function Uo(t){return t.getEditorState().read(Ps.$canShowPlaceholderCurry(t.isComposing(),t.isEditable()))}function Bs(t){let[e,n]=Ce.useState(()=>Uo(t));return mr(()=>{function r(){let i=Uo(t);n(i)}return r(),bo.mergeRegister(t.registerUpdateListener(()=>{r()}),t.registerEditableListener(()=>{r()}))},[t]),e}function zs(t){let[e,n]=Ce.useState(()=>t.getDecorators());return mr(()=>t.registerDecoratorListener(r=>{Ho.flushSync(()=>{n(r)})}),[t]),Ce.useEffect(()=>{n(t.getDecorators())},[t]),Ce.useMemo(()=>{let r=[],i=Object.keys(e);for(let l=0;l<i.length;l++){var o=i[l];let s=e[o];o=t.getElementByKey(o),o!==null&&r.push(Ho.createPortal(s,o))}return r},[e,t])}function Ks(t,e){mr(()=>bo.mergeRegister(Fs.registerRichText(t,e),Is.registerDragonSupport(t)),[t])}zo.RichTextPlugin=function({contentEditable:t,placeholder:e,initialEditorState:n}){let[r]=Ls.useLexicalComposerContext(),i=Bs(r),o=zs(r);return Ks(r,n),Ce.createElement(Ce.Fragment,null,t,i&&e,o)};var Ws=zo,Go={},Ys=Fe,Kt=se.default,bs=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u"?Kt.useLayoutEffect:Kt.useEffect;Go.ContentEditable=function({ariaActiveDescendantID:t,ariaAutoComplete:e,ariaControls:n,ariaDescribedBy:r,ariaExpanded:i,ariaLabel:o,ariaLabelledBy:l,ariaMultiline:s,ariaOwneeID:a,ariaRequired:d,autoCapitalize:u,autoComplete:g,autoCorrect:c,className:f,id:_,role:v="textbox",spellCheck:C=!0,style:$,tabIndex:M,testid:P}){let[W]=Ys.useLexicalComposerContext(),[le,Wt]=Kt.useState(!0),Te=Kt.useCallback(ot=>{W.setRootElement(ot)},[W]);return bs(()=>(Wt(W.isEditable()),W.registerEditableListener(ot=>{Wt(ot)})),[W]),Kt.createElement("div",{"aria-activedescendant":le?t:null,"aria-autocomplete":le?e:null,"aria-controls":le?n:null,"aria-describedby":r,"aria-expanded":le&&v==="combobox"?!!i:null,"aria-label":o,"aria-labelledby":l,"aria-multiline":s,"aria-owns":le?a:null,"aria-required":d,autoCapitalize:u!==void 0?String(u):void 0,autoComplete:g,autoCorrect:c!==void 0?String(c):void 0,className:f,contentEditable:le,"data-testid":P,id:_,ref:Te,role:le?v:void 0,spellCheck:C,style:$,tabIndex:M})};var Hs=Go,xr={},yr={},Us=De,L=ne;function Gs(t,e,n,r,i){if(t===null||n.size===0&&r.size===0&&!i)return 0;var o=e._selection,l=t._selection;if(i)return 1;if(!(L.$isRangeSelection(o)&&L.$isRangeSelection(l)&&l.isCollapsed()&&o.isCollapsed()))return 0;i=e._nodeMap;let s=[];for(let a of n)n=i.get(a),n!==void 0&&s.push(n);for(let[a,d]of r)d&&(r=i.get(a),r===void 0||L.$isRootNode(r)||s.push(r));return s.length===0?0:1<s.length?(r=e._nodeMap,e=r.get(o.anchor.key),l=r.get(l.anchor.key),e&&l&&!t._nodeMap.has(e.__key)&&L.$isTextNode(e)&&e.__text.length===1&&o.anchor.offset===1?2:0):(e=s[0],t=t._nodeMap.get(e.__key),!L.$isTextNode(t)||!L.$isTextNode(e)||t.__mode!==e.__mode||(t=t.__text,e=e.__text,t===e)||(o=o.anchor,l=l.anchor,o.key!==l.key||o.type!=="text")?0:(o=o.offset,l=l.offset,t=e.length-t.length,t===1&&l===o-1?2:t===-1&&l===o+1?3:t===-1&&l===o?4:0))}function Js(t,e){let n=Date.now(),r=0;return(i,o,l,s,a,d)=>{let u=Date.now();if(d.has("historic"))return r=0,n=u,2;let g=Gs(i,o,s,a,t.isComposing()),c=(()=>{var f=l===null||l.editor===t,_=d.has("history-push");if(!_&&f&&d.has("history-merge"))return 0;if(i===null)return 1;const v=o._selection,C=i._selection;return 0<s.size||0<a.size?_===!1&&g!==0&&g===r&&u<n+e&&f||s.size===1&&(_=Array.from(s)[0],f=i._nodeMap.get(_),_=o._nodeMap.get(_),f=L.$isTextNode(f)&&L.$isTextNode(_)?f.__type===_.__type&&f.__text===_.__text&&f.__mode===_.__mode&&f.__detail===_.__detail&&f.__style===_.__style&&f.__format===_.__format&&f.__parent===_.__parent:!1,f)?0:1:C===null&&v!==null?0:2})();return n=u,r=g,c}}yr.createEmptyHistoryState=function(){return{current:null,redoStack:[],undoStack:[]}},yr.registerHistory=function(t,e,n){let r=Js(t,n);n=({editorState:l,prevEditorState:s,dirtyLeaves:a,dirtyElements:d,tags:u})=>{const g=e.current,c=e.redoStack,f=e.undoStack,_=g===null?null:g.editorState;if(g===null||l!==_){if(a=r(s,l,g,a,d,u),a===1)c.length!==0&&(e.redoStack=[]),g!==null&&(f.push({...g,undoSelection:s.read(L.$getSelection)}),t.dispatchCommand(L.CAN_UNDO_COMMAND,!0));else if(a===2)return;e.current={editor:t,editorState:l}}};let i=Us.mergeRegister(t.registerCommand(L.UNDO_COMMAND,()=>{let l=e.redoStack,s=e.undoStack;if(s.length!==0){let a=e.current,d=s.pop();a!==null&&(l.push(a),t.dispatchCommand(L.CAN_REDO_COMMAND,!0)),s.length===0&&t.dispatchCommand(L.CAN_UNDO_COMMAND,!1),e.current=d||null,d&&d.editor.setEditorState(d.editorState.clone(d.undoSelection),{tag:"historic"})}return!0},L.COMMAND_PRIORITY_EDITOR),t.registerCommand(L.REDO_COMMAND,()=>{let l=e.redoStack;var s=e.undoStack;if(l.length!==0){let a=e.current;a!==null&&(s.push(a),t.dispatchCommand(L.CAN_UNDO_COMMAND,!0)),s=l.pop(),l.length===0&&t.dispatchCommand(L.CAN_REDO_COMMAND,!1),e.current=s||null,s&&s.editor.setEditorState(s.editorState,{tag:"historic"})}return!0},L.COMMAND_PRIORITY_EDITOR),t.registerCommand(L.CLEAR_EDITOR_COMMAND,()=>(e.undoStack=[],e.redoStack=[],e.current=null,!1),L.COMMAND_PRIORITY_EDITOR),t.registerCommand(L.CLEAR_HISTORY_COMMAND,()=>(e.undoStack=[],e.redoStack=[],e.current=null,!0),L.COMMAND_PRIORITY_EDITOR),t.registerUpdateListener(n)),o=t.registerUpdateListener(n);return()=>{i(),o()}};var Vs=yr,js=Fe,kr=Vs,Jo=se.default;function qs(t,e,n=1e3){let r=Jo.useMemo(()=>e||kr.createEmptyHistoryState(),[e]);Jo.useEffect(()=>kr.registerHistory(t,r,n),[n,t,r])}xr.createEmptyHistoryState=kr.createEmptyHistoryState,xr.HistoryPlugin=function({externalHistoryState:t}){let[e]=js.useLexicalComposerContext();return qs(e,t),null};var Xs=xr,Vo={},Qs=Fe,jo=se.default,Zs=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u"?jo.useLayoutEffect:jo.useEffect;Vo.OnChangePlugin=function({ignoreHistoryMergeTagChange:t=!1,ignoreInitialChange:e=!0,ignoreSelectionChange:n=!1,onChange:r}){let[i]=Qs.useLexicalComposerContext();return Zs(()=>{if(r)return i.registerUpdateListener(({editorState:o,dirtyElements:l,dirtyLeaves:s,prevEditorState:a,tags:d})=>{n&&l.size===0&&s.size===0||t&&d.has("history-merge")||e&&a.isEmpty()||r(o,i)})},[i,t,e,n,r]),null};var ea=Vo,qo={},oe=fn,ta=Fe,Xo=se.default,na=De,me=ne;function ra(t){Xo.useEffect(()=>na.mergeRegister(t.registerCommand(me.INDENT_CONTENT_COMMAND,()=>(oe.indentList(),!1),me.COMMAND_PRIORITY_LOW),t.registerCommand(me.OUTDENT_CONTENT_COMMAND,()=>(oe.outdentList(),!1),me.COMMAND_PRIORITY_LOW),t.registerCommand(oe.INSERT_ORDERED_LIST_COMMAND,()=>(oe.insertList(t,"number"),!0),me.COMMAND_PRIORITY_LOW),t.registerCommand(oe.INSERT_UNORDERED_LIST_COMMAND,()=>(oe.insertList(t,"bullet"),!0),me.COMMAND_PRIORITY_LOW),t.registerCommand(oe.REMOVE_LIST_COMMAND,()=>(oe.removeList(t),!0),me.COMMAND_PRIORITY_LOW),t.registerCommand(me.INSERT_PARAGRAPH_COMMAND,()=>!!oe.$handleListInsertParagraph(),me.COMMAND_PRIORITY_LOW)),[t])}qo.ListPlugin=function(){let[t]=ta.useLexicalComposerContext();return Xo.useEffect(()=>{if(!t.hasNodes([oe.ListNode,oe.ListItemNode]))throw Error("ListPlugin: ListNode and/or ListItemNode not registered on editor")},[t]),ra(t),null};var ia=qo;const Ea="",oa=({onChange:t})=>{const e=se.default.useCallback(n=>{const r=n.toJSON();t==null||t(r)},[t]);return Es("div",{className:"koenig-lexical",children:[Pe(Ws.RichTextPlugin,{contentEditable:Pe(Hs.ContentEditable,{className:"kg-prose"}),placeholder:Pe("div",{className:"pointer-events-none absolute top-0 left-0 min-w-full cursor-text",children:"Enter some text..."})}),Pe(ea.OnChangePlugin,{onChange:e}),Pe(Xs.HistoryPlugin,{})," ",Pe(ia.ListPlugin,{})," "]})};ce.KoenigComposer=Ds,ce.KoenigEditor=oa,Object.defineProperties(ce,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
31
|
+
*/var vs=se.default,Ns=Symbol.for("react.element"),Cs=Symbol.for("react.fragment"),Ts=Object.prototype.hasOwnProperty,Ss=vs.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,ws={key:!0,ref:!0,__self:!0,__source:!0};function Bo(t,e,n){var r,i={},o=null,l=null;n!==void 0&&(o=""+n),e.key!==void 0&&(o=""+e.key),e.ref!==void 0&&(l=e.ref);for(r in e)Ts.call(e,r)&&!ws.hasOwnProperty(r)&&(i[r]=e[r]);if(t&&t.defaultProps)for(r in e=t.defaultProps,e)i[r]===void 0&&(i[r]=e[r]);return{$$typeof:Ns,type:t,key:o,ref:l,props:i,_owner:Ss.current}}kn.Fragment=Cs,kn.jsx=Bo,kn.jsxs=Bo,function(t){t.exports=kn}(pr);const Pe=pr.exports.jsx,Es=pr.exports.jsxs,Os=[hr.HeadingNode,fn.ListNode,fn.ListItemNode,hr.QuoteNode,ys.LinkNode];function $s(t){console.error(t)}const Ms={namespace:"KoenigEditor",theme:ks},Ds=({initialEditorState:t,nodes:e=[...Os],onError:n=$s,children:r})=>{const i=se.default.useMemo(()=>Object.assign({},Ms,{nodes:e,editorState:t,onError:n}),[t,e,n]);return Pe(Ul.LexicalComposer,{initialConfig:i,children:r})};var zo={},ue={},J=ne;function _r(t,e=!0){return t?!1:(t=Ko(),e&&(t=t.trim()),t==="")}function Ko(){return J.$getRoot().getTextContent()}function Wo(t,e=!0){if(!e||!_r(t,!1)||(t=J.$getRoot().getChildren(),e=t.length,1<e))return!1;for(let r=0;r<e;r++){var n=t[r];if(J.$isElementNode(n)){if(n.__type!=="paragraph"||n.__indent!==0)return!1;n=n.getChildren();let i=n.length;for(let o=0;o<i;o++)if(!J.$isTextNode(n[r]))return!1}}return!0}ue.$canShowPlaceholder=Wo,ue.$canShowPlaceholderCurry=function(t,e=!0){return()=>Wo(t,e)},ue.$findNodeWithOffsetFromJoinedText=function(t,e,n,r){r=r.getChildren();let i=r.length,o=0,l=!1;for(let a=0;a<i&&!(o>e);++a){let d=r[a],u=J.$isTextNode(d);var s=u?d.getTextContent().length:n;if(s=o+s,(l===!1&&o===t||o===0&&o===t||o<t&&t<=s)&&J.$isTextNode(d))return{node:d,offset:t-o};o=s,l=u}return null},ue.$findTextIntersectionFromCharacters=function(t,e){var n=t.getFirstChild();t=0;e:for(;n!==null;){if(J.$isElementNode(n)){var r=n.getFirstChild();if(r!==null){n=r;continue}}else if(J.$isTextNode(n)){if(r=n.getTextContentSize(),t+r>e)return{node:n,offset:e-t};t+=r}if(r=n.getNextSibling(),r!==null)n=r;else{for(n=n.getParent();n!==null;){if(r=n.getNextSibling(),r!==null){n=r;continue e}n=n.getParent()}break}}return null},ue.$isRootTextContentEmpty=_r,ue.$isRootTextContentEmptyCurry=function(t,e){return()=>_r(t,e)},ue.$joinTextNodesInElementNode=function(t,e,n){let r="";t=t.getChildren();let i=t.length;for(let o=0;o<i;++o){let l=t[o];if(J.$isTextNode(l)){let s=l.getTextContent();if(l.is(n.node)){if(n.offset>s.length)throw Error("Minified Lexical error #2; visit https://lexical.dev/docs/error?code=2 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");r+=l.getTextContent().substr(0,n.offset);break}else r+=s}else r+=e}return r},ue.$rootTextContent=Ko,ue.registerLexicalTextEntity=function(t,e,n,r){let i=l=>{const s=J.$createTextNode(l.getTextContent());s.setFormat(l.getFormat()),l.replace(s)},o=t.registerNodeTransform(J.TextNode,l=>{if(l.isSimpleText()){var s=l.getPreviousSibling(),a=l.getTextContent(),d=l;if(J.$isTextNode(s)){var u=s.getTextContent(),g=e(u+a);if(s instanceof n){if(g===null||s.getLatest().__mode!==0){i(s);return}if(g=g.end-u.length,0<g){d=a.slice(0,g),d=u+d,s.select(),s.setTextContent(d),g===a.length?l.remove():(s=a.slice(g),l.setTextContent(s));return}}else if(g===null||g.start<u.length)return}for(;;){if(l=e(a),a=g=l===null?"":a.slice(l.end),g===""){if(u=d.getNextSibling(),J.$isTextNode(u)){if(g=d.getTextContent()+u.getTextContent(),g=e(g),g===null){u instanceof n?i(u):u.markDirty();break}else if(g.start!==0)break}}else if(u=e(g),u!==null&&u.start===0)break;if(l===null)break;if(l.start===0&&J.$isTextNode(s)&&s.isTextEntity())continue;let c;if(l.start===0?[c,d]=d.splitText(l.end):[,c,d]=d.splitText(l.start,l.end),l=r(c),c.replace(l),d==null)break}}});return t=t.registerNodeTransform(n,l=>{var s=l.getTextContent();const a=e(s);a===null||a.start!==0?i(l):s.length>a.end?l.splitText(a.end):(s=l.getPreviousSibling(),J.$isTextNode(s)&&s.isTextEntity()&&(i(s),i(l)),s=l.getNextSibling(),J.$isTextNode(s)&&s.isTextEntity()&&(i(s),l instanceof n&&i(l)))}),[o,t]};var Rs=ue,Yo={},vn=ne;Yo.registerDragonSupport=function(t){let e=n=>{var r=t.getRootElement();if(document.activeElement===r&&(r=n.data,typeof r=="string")){try{var i=JSON.parse(r)}catch{return}if(i&&i.protocol==="nuanria_messaging"&&i.type==="request"&&(i=i.payload)&&i.functionId==="makeChanges"&&(i=i.args)){const[o,l,s,a,d]=i;t.update(()=>{const u=vn.$getSelection();if(vn.$isRangeSelection(u)){var g=u.anchor;let c=g.getNode(),f=0,_=0;vn.$isTextNode(c)&&0<=o&&0<=l&&(f=o,_=o+l,u.setTextNodeRange(c,f,c,_)),(f!==_||s!=="")&&(u.insertRawText(s),c=g.getNode()),vn.$isTextNode(c)&&(f=a,_=a+d,g=c.getTextContentSize(),f=f>g?g:f,_=_>g?g:_,u.setTextNodeRange(c,f,c,_)),n.stopImmediatePropagation()}})}}};return window.addEventListener("message",e,!0),()=>{window.removeEventListener("message",e,!0)}};var As=Yo,Ls=Fe,Ce=se.default,Ps=Rs,bo=De,Ho=rl.default,Is=As,Fs=hr,mr=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u"?Ce.useLayoutEffect:Ce.useEffect;function Uo(t){return t.getEditorState().read(Ps.$canShowPlaceholderCurry(t.isComposing(),t.isEditable()))}function Bs(t){let[e,n]=Ce.useState(()=>Uo(t));return mr(()=>{function r(){let i=Uo(t);n(i)}return r(),bo.mergeRegister(t.registerUpdateListener(()=>{r()}),t.registerEditableListener(()=>{r()}))},[t]),e}function zs(t){let[e,n]=Ce.useState(()=>t.getDecorators());return mr(()=>t.registerDecoratorListener(r=>{Ho.flushSync(()=>{n(r)})}),[t]),Ce.useEffect(()=>{n(t.getDecorators())},[t]),Ce.useMemo(()=>{let r=[],i=Object.keys(e);for(let l=0;l<i.length;l++){var o=i[l];let s=e[o];o=t.getElementByKey(o),o!==null&&r.push(Ho.createPortal(s,o))}return r},[e,t])}function Ks(t,e){mr(()=>bo.mergeRegister(Fs.registerRichText(t,e),Is.registerDragonSupport(t)),[t])}zo.RichTextPlugin=function({contentEditable:t,placeholder:e,initialEditorState:n}){let[r]=Ls.useLexicalComposerContext(),i=Bs(r),o=zs(r);return Ks(r,n),Ce.createElement(Ce.Fragment,null,t,i&&e,o)};var Ws=zo,Go={},Ys=Fe,Kt=se.default,bs=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u"?Kt.useLayoutEffect:Kt.useEffect;Go.ContentEditable=function({ariaActiveDescendantID:t,ariaAutoComplete:e,ariaControls:n,ariaDescribedBy:r,ariaExpanded:i,ariaLabel:o,ariaLabelledBy:l,ariaMultiline:s,ariaOwneeID:a,ariaRequired:d,autoCapitalize:u,autoComplete:g,autoCorrect:c,className:f,id:_,role:v="textbox",spellCheck:C=!0,style:$,tabIndex:M,testid:P}){let[W]=Ys.useLexicalComposerContext(),[le,Wt]=Kt.useState(!0),Te=Kt.useCallback(ot=>{W.setRootElement(ot)},[W]);return bs(()=>(Wt(W.isEditable()),W.registerEditableListener(ot=>{Wt(ot)})),[W]),Kt.createElement("div",{"aria-activedescendant":le?t:null,"aria-autocomplete":le?e:null,"aria-controls":le?n:null,"aria-describedby":r,"aria-expanded":le&&v==="combobox"?!!i:null,"aria-label":o,"aria-labelledby":l,"aria-multiline":s,"aria-owns":le?a:null,"aria-required":d,autoCapitalize:u!==void 0?String(u):void 0,autoComplete:g,autoCorrect:c!==void 0?String(c):void 0,className:f,contentEditable:le,"data-testid":P,id:_,ref:Te,role:le?v:void 0,spellCheck:C,style:$,tabIndex:M})};var Hs=Go,xr={},yr={},Us=De,L=ne;function Gs(t,e,n,r,i){if(t===null||n.size===0&&r.size===0&&!i)return 0;var o=e._selection,l=t._selection;if(i)return 1;if(!(L.$isRangeSelection(o)&&L.$isRangeSelection(l)&&l.isCollapsed()&&o.isCollapsed()))return 0;i=e._nodeMap;let s=[];for(let a of n)n=i.get(a),n!==void 0&&s.push(n);for(let[a,d]of r)d&&(r=i.get(a),r===void 0||L.$isRootNode(r)||s.push(r));return s.length===0?0:1<s.length?(r=e._nodeMap,e=r.get(o.anchor.key),l=r.get(l.anchor.key),e&&l&&!t._nodeMap.has(e.__key)&&L.$isTextNode(e)&&e.__text.length===1&&o.anchor.offset===1?2:0):(e=s[0],t=t._nodeMap.get(e.__key),!L.$isTextNode(t)||!L.$isTextNode(e)||t.__mode!==e.__mode||(t=t.__text,e=e.__text,t===e)||(o=o.anchor,l=l.anchor,o.key!==l.key||o.type!=="text")?0:(o=o.offset,l=l.offset,t=e.length-t.length,t===1&&l===o-1?2:t===-1&&l===o+1?3:t===-1&&l===o?4:0))}function Js(t,e){let n=Date.now(),r=0;return(i,o,l,s,a,d)=>{let u=Date.now();if(d.has("historic"))return r=0,n=u,2;let g=Gs(i,o,s,a,t.isComposing()),c=(()=>{var f=l===null||l.editor===t,_=d.has("history-push");if(!_&&f&&d.has("history-merge"))return 0;if(i===null)return 1;const v=o._selection,C=i._selection;return 0<s.size||0<a.size?_===!1&&g!==0&&g===r&&u<n+e&&f||s.size===1&&(_=Array.from(s)[0],f=i._nodeMap.get(_),_=o._nodeMap.get(_),f=L.$isTextNode(f)&&L.$isTextNode(_)?f.__type===_.__type&&f.__text===_.__text&&f.__mode===_.__mode&&f.__detail===_.__detail&&f.__style===_.__style&&f.__format===_.__format&&f.__parent===_.__parent:!1,f)?0:1:C===null&&v!==null?0:2})();return n=u,r=g,c}}yr.createEmptyHistoryState=function(){return{current:null,redoStack:[],undoStack:[]}},yr.registerHistory=function(t,e,n){let r=Js(t,n);n=({editorState:l,prevEditorState:s,dirtyLeaves:a,dirtyElements:d,tags:u})=>{const g=e.current,c=e.redoStack,f=e.undoStack,_=g===null?null:g.editorState;if(g===null||l!==_){if(a=r(s,l,g,a,d,u),a===1)c.length!==0&&(e.redoStack=[]),g!==null&&(f.push({...g,undoSelection:s.read(L.$getSelection)}),t.dispatchCommand(L.CAN_UNDO_COMMAND,!0));else if(a===2)return;e.current={editor:t,editorState:l}}};let i=Us.mergeRegister(t.registerCommand(L.UNDO_COMMAND,()=>{let l=e.redoStack,s=e.undoStack;if(s.length!==0){let a=e.current,d=s.pop();a!==null&&(l.push(a),t.dispatchCommand(L.CAN_REDO_COMMAND,!0)),s.length===0&&t.dispatchCommand(L.CAN_UNDO_COMMAND,!1),e.current=d||null,d&&d.editor.setEditorState(d.editorState.clone(d.undoSelection),{tag:"historic"})}return!0},L.COMMAND_PRIORITY_EDITOR),t.registerCommand(L.REDO_COMMAND,()=>{let l=e.redoStack;var s=e.undoStack;if(l.length!==0){let a=e.current;a!==null&&(s.push(a),t.dispatchCommand(L.CAN_UNDO_COMMAND,!0)),s=l.pop(),l.length===0&&t.dispatchCommand(L.CAN_REDO_COMMAND,!1),e.current=s||null,s&&s.editor.setEditorState(s.editorState,{tag:"historic"})}return!0},L.COMMAND_PRIORITY_EDITOR),t.registerCommand(L.CLEAR_EDITOR_COMMAND,()=>(e.undoStack=[],e.redoStack=[],e.current=null,!1),L.COMMAND_PRIORITY_EDITOR),t.registerCommand(L.CLEAR_HISTORY_COMMAND,()=>(e.undoStack=[],e.redoStack=[],e.current=null,!0),L.COMMAND_PRIORITY_EDITOR),t.registerUpdateListener(n)),o=t.registerUpdateListener(n);return()=>{i(),o()}};var Vs=yr,js=Fe,kr=Vs,Jo=se.default;function qs(t,e,n=1e3){let r=Jo.useMemo(()=>e||kr.createEmptyHistoryState(),[e]);Jo.useEffect(()=>kr.registerHistory(t,r,n),[n,t,r])}xr.createEmptyHistoryState=kr.createEmptyHistoryState,xr.HistoryPlugin=function({externalHistoryState:t}){let[e]=js.useLexicalComposerContext();return qs(e,t),null};var Xs=xr,Vo={},Qs=Fe,jo=se.default,Zs=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u"?jo.useLayoutEffect:jo.useEffect;Vo.OnChangePlugin=function({ignoreHistoryMergeTagChange:t=!1,ignoreInitialChange:e=!0,ignoreSelectionChange:n=!1,onChange:r}){let[i]=Qs.useLexicalComposerContext();return Zs(()=>{if(r)return i.registerUpdateListener(({editorState:o,dirtyElements:l,dirtyLeaves:s,prevEditorState:a,tags:d})=>{n&&l.size===0&&s.size===0||t&&d.has("history-merge")||e&&a.isEmpty()||r(o,i)})},[i,t,e,n,r]),null};var ea=Vo,qo={},oe=fn,ta=Fe,Xo=se.default,na=De,me=ne;function ra(t){Xo.useEffect(()=>na.mergeRegister(t.registerCommand(me.INDENT_CONTENT_COMMAND,()=>(oe.indentList(),!1),me.COMMAND_PRIORITY_LOW),t.registerCommand(me.OUTDENT_CONTENT_COMMAND,()=>(oe.outdentList(),!1),me.COMMAND_PRIORITY_LOW),t.registerCommand(oe.INSERT_ORDERED_LIST_COMMAND,()=>(oe.insertList(t,"number"),!0),me.COMMAND_PRIORITY_LOW),t.registerCommand(oe.INSERT_UNORDERED_LIST_COMMAND,()=>(oe.insertList(t,"bullet"),!0),me.COMMAND_PRIORITY_LOW),t.registerCommand(oe.REMOVE_LIST_COMMAND,()=>(oe.removeList(t),!0),me.COMMAND_PRIORITY_LOW),t.registerCommand(me.INSERT_PARAGRAPH_COMMAND,()=>!!oe.$handleListInsertParagraph(),me.COMMAND_PRIORITY_LOW)),[t])}qo.ListPlugin=function(){let[t]=ta.useLexicalComposerContext();return Xo.useEffect(()=>{if(!t.hasNodes([oe.ListNode,oe.ListItemNode]))throw Error("ListPlugin: ListNode and/or ListItemNode not registered on editor")},[t]),ra(t),null};var ia=qo;const Ea="",oa=({onChange:t})=>{const e=se.default.useCallback(n=>{const r=n.toJSON();t==null||t(r)},[t]);return Es("div",{className:"koenig-lexical",children:[Pe(Ws.RichTextPlugin,{contentEditable:Pe(Hs.ContentEditable,{className:"kg-prose"}),placeholder:Pe("div",{className:"pointer-events-none absolute top-0 left-0 min-w-full cursor-text",children:"Enter some text..."})}),Pe(ea.OnChangePlugin,{onChange:e}),Pe(Xs.HistoryPlugin,{})," ",Pe(ia.ListPlugin,{})," "]})};ce.KoenigComposer=Ds,ce.KoenigEditor=oa,Object.defineProperties(ce,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
32
32
|
//# sourceMappingURL=koenig-lexical.umd.js.map
|