@lexical/react
Version:
This package provides Lexical components and hooks for React applications.
10 lines (8 loc) • 2.71 kB
JavaScript
/**
* 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{useLexicalComposerContext as r}from"@lexical/react/LexicalComposerContext";import{useLexicalEditable as e}from"@lexical/react/useLexicalEditable";import{LexicalBuilder as t}from"@lexical/extension/LexicalBuilder";import{ReactProviderExtension as o}from"@lexical/react/ReactProviderExtension";import{useMemo as n,useSyncExternalStore as i,Suspense as c,useLayoutEffect as l,useEffect as a,useState as s}from"react";import{createPortal as u}from"react-dom";import{jsx as f,jsxs as m,Fragment as d}from"react/jsx-runtime";import{$canShowPlaceholderCurry as p}from"@lexical/text";import{CAN_USE_DOM as x,mergeRegister as E}from"lexical";import{registerDragonSupport as h}from"@lexical/dragon";import{registerPlainText as g}from"@lexical/plain-text";function y(r,...e){const t=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",r);for(const r of e)o.append("v",r);throw t.search=o.toString(),Error(`Minified Lexical error #${r}; visit ${t.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function L(r,e){const[t,o]=n(()=>[e=>r.registerDecoratorListener(e),()=>r.getDecorators()],[r]),l=i(t,o,o),a=function(r){const[e,t]=n(()=>[r.registerRootListener.bind(r),r.getRootElement.bind(r)],[r]);return i(e,t,t)}(r);return n(()=>{const t=e=>r._onError(e),o=[];for(const n in l){const i=r.getElementByKey(n);if(null!==i){const r=/*#__PURE__*/f(e,{onError:t,children:/*#__PURE__*/f(c,{fallback:null,children:l[n]})});o.push(/*#__PURE__*/u(r,i,n))}}return o},[e,l,r,a])}function B({editor:r,ErrorBoundary:e}){return L(r,e)}function b({editor:r,ErrorBoundary:e}){return function(r){const e=t.maybeFromEditor(r);if(e&&e.hasExtensionByName(o.name)){for(const r of["@lexical/plain-text","@lexical/rich-text"])e.hasExtensionByName(r)&&y(320,r);return!0}return!1}(r)?null:/*#__PURE__*/f(B,{editor:r,ErrorBoundary:e})}const v=x?l:a;function R(r){return r.read("latest",p(r.isComposing()))}function w({contentEditable:e,placeholder:t=null,ErrorBoundary:o}){const[n]=r();return function(r){v(()=>E(g(r),h(r)),[r])}(n),/*#__PURE__*/m(d,{children:[e,/*#__PURE__*/f(C,{content:t}),/*#__PURE__*/f(b,{editor:n,ErrorBoundary:o})]})}function C({content:t}){const[o]=r(),n=function(r){const[e,t]=s(()=>R(r));return v(()=>{function e(){const e=R(r);t(e)}return e(),E(r.registerUpdateListener(()=>{e()}),r.registerEditableListener(()=>{e()}))},[r]),e}(o),i=e();return n?"function"==typeof t?t(i):t:null}export{w as PlainTextPlugin};