UNPKG

@lexical/react

Version:

This package provides Lexical components and hooks for React applications.

10 lines (8 loc) 2.2 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"),o=require("react"),r=require("react/jsx-runtime");function n(e){const t=e.transform();return new Set(t?[t]:[])}const s=()=>{},i=()=>{};exports.LexicalNestedComposer=function({initialEditor:a,children:c,initialNodes:l,initialTheme:p,skipCollabChecks:f,skipEditableListener:d}){const u=o.useRef(!1),m=o.useContext(t.LexicalComposerContext);null==m&&function(e,...t){const o=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw o.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${o.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(9);const[x,{getTheme:h}]=m,g=o.useMemo((()=>{const e=p||h()||void 0,o=t.createLexicalComposerContext(m,e);void 0!==e&&(a._config.theme=e),a._parentEditor=a._parentEditor||x;const r=a._createEditorArgs,c=r&&r.namespace;if(l){s(),c||(i(),a._config.namespace=x._config.namespace);for(let e of l){let t=null,o=null;if("function"!=typeof e){const r=e;e=r.replace,t=r.with,o=r.withKlass||null}const r=a._nodes.get(e.getType());a._nodes.set(e.getType(),{exportDOM:r?r.exportDOM:void 0,klass:e,replace:t,replaceWithKlass:o,transforms:n(e)})}}else if(r&&r.nodes)c||(i(),a._config.namespace=x._config.namespace);else{const e=a._nodes=new Map(x._nodes);c||(a._config.namespace=x._config.namespace);for(const[t,o]of e)a._nodes.set(t,{exportDOM:o.exportDOM,klass:o.klass,replace:o.replace,replaceWithKlass:o.replaceWithKlass,transforms:n(o.klass)})}return[a,o]}),[]),{isCollabActive:C,yjsDocMap:_}=e.useCollaborationContext(),v=f||u.current||_.has(a.getKey());return o.useEffect((()=>{v&&(u.current=!0)}),[v]),o.useEffect((()=>{if(!d){const e=e=>a.setEditable(e);return e(x.isEditable()),x.registerEditableListener(e)}}),[a,x,d]),r.jsx(t.LexicalComposerContext.Provider,{value:g,children:!C||v?c:null})};