UNPKG

@lexical/react

Version:

This package provides Lexical components and hooks for React applications.

12 lines (10 loc) • 2.71 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{ContentEditable as r}from"@lexical/react/LexicalContentEditable";import{LexicalErrorBoundary as e}from"@lexical/react/LexicalErrorBoundary";import{ReactProviderExtension as o}from"@lexical/react/ReactProviderExtension";import{shallowMergeConfig as t}from"lexical";import{LexicalComposerContext as n}from"@lexical/react/LexicalComposerContext";import{useMemo as i,useSyncExternalStore as c,Suspense as a}from"react";import{createPortal as l}from"react-dom";import{jsx as d,jsxs as s,Fragment as m}from"react/jsx-runtime";function f({contentEditable:r,children:e}){ return s(m,{children:[r,e]})}const u={EditorChildrenComponent:f,ErrorBoundary:e,contentEditable:/*#__PURE__*/d(r,{}),decorators:[]},p={build(r,e,t){t.getPeer(o.name)||function(r,...e){throw function(r,...e){const o=new URL("https://lexical.dev/docs/error"),t=new URLSearchParams;t.append("code",r);for(const r of e)t.append("v",r);return o.search=t.toString(),new Error(`Minified Lexical error #${r}; visit ${o.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(r,...e)}(321,[...t.getDirectDependentNames()].join(" "));const m=[r,{getTheme:()=>r._config.theme}],f=function(r,e){const[o]=e,t=r.decorators.map(r=>"function"==typeof r?/*#__PURE__*/d(r,{context:e}):r);return function(m){const{EditorChildrenComponent:f=r.EditorChildrenComponent,ErrorBoundary:u=r.ErrorBoundary,contentEditable:p=r.contentEditable,children:h}=m,E=function(r,e){const[o,t]=i(()=>[e=>r.registerDecoratorListener(e),()=>r.getDecorators()],[r]),n=c(o,t,t),s=function(r){const[e,o]=i(()=>[r.registerRootListener.bind(r),r.getRootElement.bind(r)],[r]);return c(e,o,o)}(r);return i(()=>{const o=e=>r._onError(e),t=[];for(const i in n){const c=r.getElementByKey(i);if(null!==c){const r=/*#__PURE__*/d(e,{onError:o,children:/*#__PURE__*/d(a,{fallback:null,children:n[i]})});t.push(/*#__PURE__*/l(r,c,i))}}return t},[e,n,r,s])}(o,u),x=i(()=>t.map((r,e)=>/*#__PURE__*/d(u,{onError:r=>{o._onError(r)},children:/*#__PURE__*/d(a,{fallback:null,children:r})},e)),[u]); return d(n.Provider,{value:e,children:/*#__PURE__*/s(f,{context:e,contentEditable:p,children:[h,x,E]})})}}(e,m);return{Component:f,context:m}},config:u,mergeConfig(r,e){const o=t(r,e);return e.decorators&&(o.decorators=e.decorators.length>0?[...r.decorators,...e.decorators]:r.decorators),o},name:"@lexical/react/React",peerDependencies:[["@lexical/react/ReactProvider"]]};export{f as DefaultEditorChildrenComponent,p as ReactExtension};