text-editor-studio-ts
Version:
A powerful mobile-responsive rich text editor built with Lexical and React
3 lines (2 loc) • 2.54 kB
JavaScript
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("react"),n=require("./index-BLOj1UA2.cjs"),r=require("@lexical/utils"),o=require("lexical"),a=require("react-error-boundary");const i=t.forwardRef(function({equation:t,setEquation:n,inline:r},o){const a=e=>{n(e.target.value)};return r&&o instanceof HTMLInputElement?e.jsxs("span",{className:"EquationEditor_inputBackground bg-background-system-body-primary",children:[e.jsx("span",{className:"EquationEditor_dollarSign text-left text-content-system-global-secondary",children:"$"}),e.jsx("input",{className:"EquationEditor_inlineEditor m-0 resize-none border-0 bg-inherit p-0 text-content-system-global-primary outline-none",value:t,onChange:a,autoFocus:!0,ref:o}),e.jsx("span",{className:"EquationEditor_dollarSign text-left text-content-system-global-secondary",children:"$"})]}):e.jsxs("div",{className:"EquationEditor_inputBackground bg-background-system-body-primary",children:[e.jsx("span",{className:"EquationEditor_dollarSign text-left text-content-system-global-secondary",children:"$$\n"}),e.jsx("textarea",{className:"EquationEditor_blockEditor m-0 w-full resize-none border-0 bg-inherit p-0 text-content-system-global-primary outline-none",value:t,onChange:a,ref:o}),e.jsx("span",{className:"EquationEditor_dollarSign text-left text-content-system-global-secondary",children:"\n$$"})]})});exports.default=function({equation:s,inline:l,nodeKey:u}){const[c]=n.o(),d=n.a(),[E,m]=t.useState(s),[g,x]=t.useState(!1),y=t.useRef(null),b=t.useCallback(e=>{x(!1),c.update(()=>{const t=o.$getNodeByKey(u);n.$isEquationNode(t)&&(t.setEquation(E),e&&t.selectNext(0,0))})},[c,E,u]);return t.useEffect(()=>{g||E===s||m(s)},[g,s,E]),t.useEffect(()=>{if(d)return g?r.mergeRegister(c.registerCommand(o.SELECTION_CHANGE_COMMAND,e=>{const t=document.activeElement;return y.current!==t&&b(),!1},o.COMMAND_PRIORITY_HIGH),c.registerCommand(o.KEY_ESCAPE_COMMAND,e=>{const t=document.activeElement;return y.current===t&&(b(!0),!0)},o.COMMAND_PRIORITY_HIGH)):c.registerUpdateListener(({editorState:e})=>{e.read(()=>{const e=o.$getSelection();return o.$isNodeSelection(e)&&e.has(u)&&1===e.getNodes().length})&&x(!0)})},[c,u,b,g,d]),e.jsx(e.Fragment,{children:g&&d?e.jsx(i,{equation:E,setEquation:m,inline:l,ref:y}):e.jsx(a.ErrorBoundary,{onError:e=>c._onError(e),fallback:null,children:e.jsx(n.KatexRenderer,{equation:E,inline:l,onDoubleClick:()=>{d&&x(!0)}})})})};
//# sourceMappingURL=equation-component-CpuvXGaQ.cjs.map