UNPKG

@lexical/react

Version:

This package provides Lexical components and hooks for React applications.

10 lines (8 loc) 2.32 kB
/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ "use strict";var e=require("@lexical/react/LexicalCollaborationContext"),t=require("@lexical/react/LexicalComposerContext"),r=require("lexical"),o=require("react"),s=require("react/jsx-runtime");function n(e){const t=e.transform();return new Set(t?[t]:[])}const a=()=>{},i=()=>{};exports.LexicalNestedComposer=function({initialEditor:c,children:l,initialNodes:d,initialTheme:p,skipCollabChecks:f,skipEditableListener:u}){const x=o.useRef(!1),m=o.useContext(t.LexicalComposerContext);null==m&&function(e,...t){const r=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw r.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${r.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(9);const[h,{getTheme:g}]=m,C=o.useMemo((()=>{const e=p||g()||void 0,o=t.createLexicalComposerContext(m,e);void 0!==e&&(c._config.theme=e),c._parentEditor=c._parentEditor||h;const s=c._createEditorArgs,l=s&&s.namespace;if(d){a(),l||(i(),c._config.namespace=h._config.namespace);for(let e of d){let t=null,o=null;if("function"!=typeof e){const r=e;e=r.replace,t=r.with,o=r.withKlass||null}const s=r.getRegisteredNode(c,e.getType());c._nodes.set(e.getType(),{exportDOM:s?s.exportDOM:void 0,klass:e,replace:t,replaceWithKlass:o,sharedNodeState:r.createSharedNodeState(e),transforms:n(e)})}}else if(s&&s.nodes)l||(i(),c._config.namespace=h._config.namespace);else{const e=c._nodes=new Map(h._nodes);l||(c._config.namespace=h._config.namespace);for(const[t,o]of e)c._nodes.set(t,{exportDOM:o.exportDOM,klass:o.klass,replace:o.replace,replaceWithKlass:o.replaceWithKlass,sharedNodeState:r.createSharedNodeState(o.klass),transforms:n(o.klass)})}return[c,o]}),[]),{isCollabActive:_,yjsDocMap:v}=e.useCollaborationContext(),E=f||x.current||v.has(c.getKey());return o.useEffect((()=>{E&&(x.current=!0)}),[E]),o.useEffect((()=>{if(!u){const e=e=>c.setEditable(e);return e(h.isEditable()),h.registerEditableListener(e)}}),[c,h,u]),s.jsx(t.LexicalComposerContext.Provider,{value:C,children:!_||E?l:null})};