UNPKG

@lexical/react

Version:

This package provides Lexical components and hooks for React applications.

10 lines (8 loc) • 2.95 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{effect as e,untracked as n,signal as o}from"@lexical/extension/signals";import{getExtensionDependencyFromEditor as t}from"@lexical/extension/getExtensionDependencyFromEditor";import{ReactExtension as r}from"@lexical/react/ReactExtension";import{ReactProviderExtension as i}from"@lexical/react/ReactProviderExtension";import{createCommand as l,mergeRegister as u,COMMAND_PRIORITY_CRITICAL as c,COMMAND_PRIORITY_EDITOR as s}from"lexical";import{useState as a,useEffect as m,Suspense as p}from"react";import{createPortal as d}from"react-dom";import{createRoot as f}from"react-dom/client";import{jsx as g,Fragment as x}from"react/jsx-runtime";function h(e,n){const{props:o,extension:r,...i}=n,{Component:l}=t(e,r).output;v(e,{...i,element:o?/*#__PURE__*/g(l,{...o}):null})}function P(e,n){const{Component:o,props:t,...r}=n;v(e,{...r,element:t?/*#__PURE__*/g(o,{...t}):null})}function v(e,n){t(e,_).output.mountReactPlugin(n)}function R(e,n){t(e,_).output.mountReactPluginHost(n)}const C=/* @__PURE__ */l("REACT_PLUGIN_HOST_MOUNT_ROOT_COMMAND"),E=/* @__PURE__ */l("REACT_PLUGIN_HOST_MOUNT_PLUGIN_COMMAND");const _={build:(e,n,t)=>({mountReactPlugin:n=>{e.dispatchCommand(E,n)},mountReactPluginHost:n=>e.dispatchCommand(C,{root:f(n)}),mountedPluginsStore:o({plugins:new Map})}),dependencies:[i,[r,{decorators:[function({context:[n]}){const{mountedPluginsStore:o}=t(n,_).output,{ErrorBoundary:i}=t(n,r).config,l=n._onError.bind(n),[{plugins:u},c]=a(()=>o.peek());m(()=>e(()=>c(o.value)),[o]);const s=[];for(const{key:e,element:n,domNode:o}of u.values()){if(!n)continue;const t=/*#__PURE__*/g(i,{onError:l,children:/*#__PURE__*/g(p,{fallback:null,children:n})},e);s.push(o?/*#__PURE__*/d(t,o,e):t)}return s.length>0?/*#__PURE__*/g(x,{children:s}):null}]}]],name:"@lexical/react/ReactPluginHost",register(e,o,t){let i;const{mountedPluginsStore:l}=t.getOutput(),{Component:a}=t.getDependency(r).output;return u(()=>{i&&i.unmount(),n(()=>{l.value.plugins.clear()})},e.registerCommand(E,e=>(n(()=>{const{plugins:n}=l.value;n.set(e.key,e),l.value={plugins:n}}),!1),c),e.registerCommand(C,e=>(void 0!==i&&function(e,...n){const o=new URL("https://lexical.dev/docs/error"),t=new URLSearchParams;t.append("code",e);for(const e of n)t.append("v",e);throw o.search=t.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.`)}(322),i=e.root,i.render(/*#__PURE__*/g(a,{contentEditable:null})),!0),s))}};export{E as REACT_PLUGIN_HOST_MOUNT_PLUGIN_COMMAND,C as REACT_PLUGIN_HOST_MOUNT_ROOT_COMMAND,_ as ReactPluginHostExtension,h as mountReactExtensionComponent,P as mountReactPluginComponent,v as mountReactPluginElement,R as mountReactPluginHost};