UNPKG

@lexical/react

Version:

This package provides Lexical components and hooks for React applications.

12 lines (10 loc) • 2.36 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. * */ import{CollaborationContext as e}from"@lexical/react/LexicalCollaborationContext";import{LexicalComposerContext as t,createLexicalComposerContext as r}from"@lexical/react/LexicalComposerContext";import{getTransformSetFromKlass as o,createSharedNodeState as n,getRegisteredNode as i}from"lexical";import{useRef as s,useContext as a,useMemo as l,useEffect as c}from"react";import{jsx as p}from"react/jsx-runtime"; /*@__INLINE__*/ function f(e){return()=>{}}const d=/* @__PURE__ */f(),m=/* @__PURE__ */f();function h({initialEditor:f,children:h,initialNodes:u,initialTheme:g,skipCollabChecks:x,skipEditableListener:_}){const v=s(!1),E=a(t);null==E&&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[k,{getTheme:b}]=E,w=l(()=>{const e=g||b()||void 0,t=r(E,e);void 0!==e&&(f._config.theme=e),f._parentEditor=f._parentEditor||k;const s=f._createEditorArgs,a=s&&s.namespace;if(u){d(),a||(m(),f._config.namespace=k._config.namespace);for(let e of u){let t=null,r=null;if("function"!=typeof e){const o=e;e=o.replace,t=o.with,r=o.withKlass||null}const s=i(f,e.getType());f._nodes.set(e.getType(),{exportDOM:s?s.exportDOM:void 0,klass:e,replace:t,replaceWithKlass:r,sharedNodeState:n(e),transforms:o(e)})}}else if(s&&s.nodes)a||(m(),f._config.namespace=k._config.namespace);else{const e=f._nodes=new Map(k._nodes);a||(f._config.namespace=k._config.namespace);for(const[t,r]of e)f._nodes.set(t,{exportDOM:r.exportDOM,klass:r.klass,replace:r.replace,replaceWithKlass:r.replaceWithKlass,sharedNodeState:n(r.klass),transforms:o(r.klass)})}return[f,t]},[]),C=a(e),{isCollabActive:L,yjsDocMap:M}=C??{},y=x||v.current||M&&M.has(f.getKey());return c(()=>{y&&(v.current=!0)},[y]),c(()=>{if(!_){const e=e=>f.setEditable(e);return e(k.isEditable()),k.registerEditableListener(e)}},[f,k,_]),/*#__PURE__*/p(t.Provider,{value:w,children:!L||y?h:null})}export{h as LexicalNestedComposer};