@lexical/react
Version:
This package provides Lexical components and hooks for React applications.
10 lines (8 loc) • 2.74 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 n}from"@lexical/react/ReactProviderExtension";import{useMemo as o,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){throw function(r,...e){const t=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",r);for(const r of e)n.append("v",r);return t.search=n.toString(),new 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.`)}(r,...e)}function L({editor:r,ErrorBoundary:e}){return function(r,e){const[t,n]=o(()=>[e=>r.registerDecoratorListener(e),()=>r.getDecorators()],[r]),l=i(t,n,n),a=function(r){const[e,t]=o(()=>[r.registerRootListener.bind(r),r.getRootElement.bind(r)],[r]);return i(e,t,t)}(r);return o(()=>{const t=e=>r._onError(e),n=[];for(const o in l){const i=r.getElementByKey(o);if(null!==i){const r=/*#__PURE__*/f(e,{onError:t,children:/*#__PURE__*/f(c,{fallback:null,children:l[o]})});n.push(/*#__PURE__*/u(r,i,o))}}return n},[e,l,r,a])}(r,e)}function B({editor:r,ErrorBoundary:e}){return function(r){const e=t.maybeFromEditor(r);if(e&&e.hasExtensionByName(n.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(L,{editor:r,ErrorBoundary:e})}const b=x?l:a;function v(r){return r.read("latest",p(r.isComposing()))}function w({contentEditable:e,placeholder:t=null,ErrorBoundary:n}){const[o]=r();return function(r){b(()=>E(g(r),h(r)),[r])}(o),/*#__PURE__*/m(d,{children:[e,/*#__PURE__*/f(R,{content:t}),/*#__PURE__*/f(B,{editor:o,ErrorBoundary:n})]})}function R({content:t}){const[n]=r(),o=function(r){const[e,t]=s(()=>v(r));return b(()=>{function e(){const e=v(r);t(e)}return e(),E(r.registerUpdateListener(()=>{e()}),r.registerEditableListener(()=>{e()}))},[r]),e}(n),i=e();return o?"function"==typeof t?t(i):t:null}export{w as PlainTextPlugin};