UNPKG

@lexical/react

Version:

This package provides Lexical components and hooks for React applications.

12 lines (10 loc) • 2.68 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(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])}function u({contentEditable:r,children:e}){ return s(m,{children:[r,e]})}const p={EditorChildrenComponent:u,ErrorBoundary:e,contentEditable:/*#__PURE__*/d(r,{}),decorators:[]},h={build(r,e,t){t.getPeer(o.name)||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);throw o.search=t.toString(),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.`)}(321,[...t.getDirectDependentNames()].join(" "));const c=[r,{getTheme:()=>r._config.theme}],l=function(r,e){const[o]=e,t=r.decorators.map(r=>"function"==typeof r?/*#__PURE__*/d(r,{context:e}):r);return function(c){const{EditorChildrenComponent:l=r.EditorChildrenComponent,ErrorBoundary:m=r.ErrorBoundary,contentEditable:u=r.contentEditable,children:p}=c,h=f(o,m),E=i(()=>t.map((r,e)=>/*#__PURE__*/d(m,{onError:r=>{o._onError(r)},children:/*#__PURE__*/d(a,{fallback:null,children:r})},e)),[m]); return d(n.Provider,{value:e,children:/*#__PURE__*/s(l,{context:e,contentEditable:u,children:[p,E,h]})})}}(e,c);return{Component:l,context:c}},config:p,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{u as DefaultEditorChildrenComponent,h as ReactExtension};