UNPKG

@lexical/react

Version:

This package provides Lexical components and hooks for React applications.

10 lines (8 loc) 2.98 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/extension"),n=require("@lexical/react/ReactExtension"),t=require("@lexical/react/ReactProviderExtension"),o=require("@lexical/utils"),r=require("lexical"),i=require("react"),s=require("react-dom"),u=require("react-dom/client"),c=require("react/jsx-runtime");function a(n,t){e.getExtensionDependencyFromEditor(n,m).output.mountReactPlugin(t)}const l=r.createCommand("REACT_PLUGIN_HOST_MOUNT_ROOT_COMMAND"),d=r.createCommand("REACT_PLUGIN_HOST_MOUNT_PLUGIN_COMMAND");const m=r.defineExtension({build:(n,t,o)=>({mountReactPlugin:e=>{n.dispatchCommand(d,e)},mountReactPluginHost:e=>n.dispatchCommand(l,{root:u.createRoot(e)}),mountedPluginsStore:e.signal({plugins:new Map})}),dependencies:[t.ReactProviderExtension,r.configExtension(n.ReactExtension,{decorators:[function({context:[t]}){const{mountedPluginsStore:o}=e.getExtensionDependencyFromEditor(t,m).output,{ErrorBoundary:r}=e.getExtensionDependencyFromEditor(t,n.ReactExtension).config,u=t._onError.bind(t),[{plugins:a},l]=i.useState(()=>o.peek());i.useEffect(()=>e.effect(()=>l(o.value)),[o]);const d=[];for(const{key:e,element:n,domNode:t}of a.values()){if(!n)continue;const o=c.jsx(r,{onError:u,children:c.jsx(i.Suspense,{fallback:null,children:n})},e);d.push(t?s.createPortal(o,t,e):o)}return d.length>0?c.jsx(c.Fragment,{children:d}):null}]})],name:"@lexical/react/ReactPluginHost",register(t,i,s){let u;const{mountedPluginsStore:a}=s.getOutput(),{Component:m}=s.getDependency(n.ReactExtension).output;return o.mergeRegister(()=>{u&&u.unmount(),e.untracked(()=>{a.value.plugins.clear()})},t.registerCommand(d,n=>(e.untracked(()=>{const{plugins:e}=a.value;e.set(n.key,n),a.value={plugins:e}}),!1),r.COMMAND_PRIORITY_CRITICAL),t.registerCommand(l,e=>(void 0!==u&&function(e,...n){const t=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of n)o.append("v",e);throw t.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${t.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(322),u=e.root,u.render(c.jsx(m,{contentEditable:null})),!0),r.COMMAND_PRIORITY_EDITOR))}});exports.REACT_PLUGIN_HOST_MOUNT_PLUGIN_COMMAND=d,exports.REACT_PLUGIN_HOST_MOUNT_ROOT_COMMAND=l,exports.ReactPluginHostExtension=m,exports.mountReactExtensionComponent=function(n,t){const{props:o,extension:r,...i}=t,{Component:s}=e.getExtensionDependencyFromEditor(n,r).output;a(n,{...i,element:o?c.jsx(s,{...o}):null})},exports.mountReactPluginComponent=function(e,n){const{Component:t,props:o,...r}=n;a(e,{...r,element:o?c.jsx(t,{...o}):null})},exports.mountReactPluginElement=a,exports.mountReactPluginHost=function(n,t){e.getExtensionDependencyFromEditor(n,m).output.mountReactPluginHost(t)};