@zuilib/text-editor 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -3
- package/README.md +61 -35
- package/dist/chunk-3KAABUZQ.js +2 -0
- package/dist/chunk-5J4TV6XA.js +2 -0
- package/dist/chunk-6JQG6QDN.js +16 -0
- package/dist/chunk-6LHJXZZ2.js +2 -0
- package/dist/chunk-N6OUUWQO.js +5 -0
- package/dist/comments.js +1 -1
- package/dist/drawing.js +1 -1
- package/dist/index.js +1 -1
- package/dist/lexical.js +1 -1
- package/dist/markdown.js +1 -1
- package/dist/mentions.js +1 -1
- package/dist/styles.css +215 -6
- package/dist/tailwind.css +7 -0
- package/package.json +19 -33
- package/dist/chunk-3TZVOXWX.js +0 -16
- package/dist/chunk-C7VEINKX.js +0 -2
- package/dist/chunk-R5PL4Q7X.js +0 -5
- package/dist/chunk-SDICQI2B.js +0 -2
- package/dist/chunk-XP3MZRCW.js +0 -2
package/dist/chunk-R5PL4Q7X.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import{b as he,c as tt,f as ye,q as ee,r as bt,s as xt,t as Et,u as Tt}from"./chunk-N5JWZ2VW.js";import{b as Q,c as st,d as at,e as j,f as ut,g as ct,h as dt,i as mt,j as ft,k as pt,l as gt,m as ht,n as yt,o as Ct,p as Lt,q as te,r as oe,s as be,t as xe,u as Ce,v as Ee}from"./chunk-AGTPMKLK.js";import{a as nt,b as _,d as rt,e as L,g as it,h as lt,n as O,u as Rt}from"./chunk-LDVPFZCN.js";import{b as ot,c as K}from"./chunk-YFFSTMIR.js";var Te=globalThis;Te.Prism?Te.Prism.manual=!0:Te.Prism={manual:!0};var po=String.raw`[A-Za-z_$][\w$]*`,go=String.raw`\s+`,ho=/^[A-Z][A-Z\d_]+$/,yo=/^[A-Z]/,kt=new WeakMap;function bo(e){return new RegExp(`${e}|`).exec("").length-1}function xo(e){let t=kt.get(e);if(t)return t;let o=[...e.rules,"whitespace","identifier"],r=o.map(c=>c==="whitespace"?go:c==="identifier"?e.identifier??po:c.match),n=[],i=1;for(let c of r)n.push(i),i+=1+bo(c);let l=new RegExp(r.map(c=>`(${c})`).join("|"),e.caseInsensitive?"yi":"y"),s=new Map,u=(c,m)=>{for(let f of c??[])s.set(e.caseInsensitive?f.toLowerCase():f,m)};u(e.builtins,"builtin"),u(e.types,"type"),u(e.constants,"constant"),u(e.keywords,"keyword");let a={regex:l,groupStarts:n,rules:o,words:s};return kt.set(e,a),a}function Co(e,t){let o=t;for(;e[o]===" "||e[o]===" ";)o++;return e[o]==="("}function Eo(e,t,o,r,n){let i=o.get(t.caseInsensitive?e.toLowerCase():e);if(i)return i;if(t.capitalizedIsType){if(ho.test(e))return"constant";if(yo.test(e))return"type"}return t.callIsFunction&&Co(r,n)?"function":"text"}function To(e,t){let{groupStarts:o,rules:r}=t;for(let n=0;n<o.length;n++)if(e[o[n]]!==void 0)return r[n];throw new Error("zui code lexer: no alternative matched")}function ne(e,t){let o=xo(t),r=[],n=(u,a)=>{let c=r[r.length-1];c&&c.type===u?r[r.length-1]={type:u,text:c.text+a}:r.push({type:u,text:a})},i=0,l=0,s=u=>{u>l&&n("text",e.slice(l,u))};for(;i<e.length;){o.regex.lastIndex=i;let u=o.regex.exec(e);if(u===null||u[0].length===0){i+=1;continue}let a=u[0],c=i+a.length,m=To(u,o),f;m==="whitespace"?f="text":m==="identifier"?f=Eo(a,t,o.words,e,c):f=m.type,f!=="text"&&(s(i),n(f,a),l=c),i=c}return s(e.length),r}import{$createLineBreakNode as Ro,$createTabNode as Lo,$nodesOfType as ko}from"lexical";import{$createCodeHighlightNode as So,CodeNode as St,registerCodeHighlighting as wo}from"@lexical/code";import{mergeRegister as vo}from"@lexical/utils";var Po=2e5;function wt(e,t){return e.length>Po?tt:ye(t)}var vt={defaultLanguage:he,tokenize(e,t){return ne(e,wt(e,t)).map(o=>o.type==="text"?o.text:{type:o.type,alias:"",content:o.text})},$tokenize(e,t){let o=e.getTextContent(),r=[];for(let{type:n,text:i}of ne(o,wt(o,t))){let l=n==="text"?void 0:n;for(let s of i.split(/(\n|\t)/))s===`
|
|
3
|
-
`?r.push(Ro()):s===" "?r.push(Lo()):s.length>0&&r.push(So(s,l))}return r}};function No(e){let o=globalThis.Prism?.languages;return!o||Object.prototype.hasOwnProperty.call(o,e)?!1:(o[e]={},!0)}function Re(e){let t=vo(e.registerNodeTransform(St,o=>{let r=o.getLanguage();r&&No(r)&&o.markDirty()}),wo(e,vt));return e.update(()=>{for(let o of ko(St))o.markDirty()},{tag:["history-merge","skip-dom-selection"]}),t}var Le=["comment","string","number","keyword","builtin","type","function","property","variable","constant","operator","punctuation","tag","attr","regex","meta","inserted","deleted"];import{useEffect as Pt,useRef as Nt}from"react";import{useLexicalComposerContext as zo}from"@lexical/react/LexicalComposerContext";import{$convertFromMarkdownString as Mo,$convertToMarkdownString as Io}from"@lexical/markdown";import{$createRangeSelection as $o,$getRoot as Ao,$getSelection as Bo,$isElementNode as ke,$isRangeSelection as Ko,$isTextNode as zt,$setSelection as Oo}from"lexical";var Se="initial-load",Do=8,_o=1e3;function Ho(e,t){if(t.size>0)return!0;for(let o of e.values())if(o)return!0;return!1}var we=class{constructor(t=Do,o=_o,r=()=>Date.now()){this.capacity=t;this.staleMs=o;this.now=r;this.entries=[]}push(t){let o=this.entries.findIndex(r=>r.value===t);o!==-1&&this.entries.splice(o,1),this.entries.push({value:t,at:this.now()}),this.entries.length>this.capacity&&this.entries.shift()}isEcho(t){let o=this.entries.length;if(o===0)return!1;if(this.entries[o-1].value===t)return!0;let r=this.now();return this.entries.some(n=>n.value===t&&r-n.at<=this.staleMs)}get last(){let t=this.entries.length;return t===0?null:this.entries[t-1].value}};function Fo(e){let t=[],o=e;for(;o!==null;){let r=o.getParent();if(r===null)break;t.unshift(o.getIndexWithinParent()),o=r}return t}function Mt(e){return{path:Fo(e.getNode()),offset:e.offset,type:e.type}}function It(e){let t=Ao();for(let r of e.path){if(!ke(t))return null;let n=t.getChildAtIndex(r);if(n===null)return null;t=n}let o=zt(t)?t.getTextContentSize():ke(t)?t.getChildrenSize():0;return e.type==="text"&&!zt(t)||e.type==="element"&&!ke(t)?null:[t,Math.min(e.offset,o)]}function Go(e,t){let o=Bo(),r=Ko(o)?{anchor:Mt(o.anchor),focus:Mt(o.focus)}:null;if(Mo(e,t),r===null)return;let n=It(r.anchor),i=It(r.focus);if(n===null||i===null)return;let l=$o();l.anchor.set(n[0].getKey(),n[1],r.anchor.type),l.focus.set(i[0].getKey(),i[1],r.focus.type),Oo(l)}function Uo(e,t,o){let r=e.getRootElement(),n=r!==null&&typeof document<"u"&&document.activeElement===r;e.update(()=>Go(t,o),{tag:n?[Se]:[Se,"skip-dom-selection"]})}function ve({markdown:e,onValueChange:t,transformers:o}){let[r]=zo(),n=Nt(new we),i=Nt(t);return i.current=t,Pt(()=>{e===void 0||n.current.isEcho(e)||(n.current.push(e),Uo(r,e,o))},[r,e]),Pt(()=>r.registerUpdateListener(({editorState:l,dirtyElements:s,dirtyLeaves:u,tags:a})=>{Ho(s,u)&&(a.has(Se)||l.read(()=>{let c=Io(o);c!==n.current.last&&(n.current.push(c),i.current?.(c))}))}),[r]),null}var Pe={ltr:"text-start",rtl:"text-end",placeholder:"text-muted-foreground opacity-50",paragraph:"zui-paragraph mb-2",heading:{h1:"zui-heading zui-heading-1 text-4xl font-bold mb-4",h2:"zui-heading zui-heading-2 text-3xl font-bold mb-3",h3:"zui-heading zui-heading-3 text-2xl font-bold mb-2",h4:"zui-heading zui-heading-4 text-xl font-bold mb-2",h5:"zui-heading zui-heading-5 text-lg font-bold mb-1",h6:"zui-heading zui-heading-6 text-base font-bold mb-1"},list:{listitem:"ms-8",listitemChecked:"line-through opacity-50",listitemUnchecked:"",nested:{listitem:"ms-8"},checklist:"zui-checklist",ol:"zui-list zui-list-ordered list-decimal ms-4",ul:"zui-list zui-list-unordered list-disc ms-4"},link:"text-primary underline hover:opacity-80 cursor-pointer",text:{bold:"font-bold",code:"bg-muted px-1.5 py-0.5 rounded-sm font-mono text-sm",italic:"italic",strikethrough:"line-through",subscript:"text-xs align-sub",superscript:"text-xs align-super",underline:"underline",underlineStrikethrough:"underline line-through"},code:"zui-code bg-muted rounded-md p-4 font-mono text-sm block my-2 overflow-x-auto",codeHighlight:Object.fromEntries(Le.map(e=>[e,`zui-token zui-token-${e}`])),quote:"zui-quote border-s-4 border-border ps-4 italic",frontmatter:"zui-frontmatter",table:"zui-table",tableCell:"zui-table-cell",tableCellHeader:"zui-table-cell-header",tableSelected:"zui-table-selected",tableSelection:"zui-table-selection",drawing:"zui-drawing"};function $t(e,t){let o={...e};for(let[r,n]of Object.entries(t)){let i=o[r];o[r]=typeof n=="object"&&n!==null&&typeof i=="object"&&i!==null?{...i,...n}:n}return o}import{useEffect as At,useRef as Wo,useState as Bt}from"react";import{useLexicalComposerContext as Yo}from"@lexical/react/LexicalComposerContext";import{$getRoot as Kt}from"lexical";import{Fragment as Vo,jsx as Ot,jsxs as qo}from"react/jsx-runtime";function W({className:e}={}){let[t]=Yo(),{mode:o,rawValue:r,maxLength:n,labels:i}=_(),[l,s]=Bt(()=>t.getEditorState().read(()=>Kt().getTextContentSize())),[u,a]=Bt(""),c=Wo(!1);At(()=>t.registerUpdateListener(({editorState:x})=>{s(x.read(()=>Kt().getTextContentSize()))}),[t]);let m=o==="edit-raw"?r.length:l,f=n!==void 0&&m>n;return At(()=>{f!==c.current&&(c.current=f,n!==void 0&&a(f?i.limitExceeded(n):i.limitRestored(n)))},[f,n,i]),qo(Vo,{children:[Ot("div",{className:`zui-text-editor-count ${f?"is-over":""} ${e??""}`,"data-slot":"count",children:i.count(m,n)}),n!==void 0&&Ot("div",{className:"zui-text-editor-live",role:"status","aria-live":"polite","aria-atomic":"true","data-slot":"count-status",children:u})]})}import{useCallback as Yt,useEffect as le,useMemo as Y,useRef as Z,useState as Ut,useSyncExternalStore as qn}from"react";import{LexicalComposer as Zn}from"@lexical/react/LexicalComposer";import{HistoryPlugin as Xn}from"@lexical/react/LexicalHistoryPlugin";import{ListPlugin as Jn}from"@lexical/react/LexicalListPlugin";import{CheckListPlugin as Qn}from"@lexical/react/LexicalCheckListPlugin";import{LinkPlugin as jn}from"@lexical/react/LexicalLinkPlugin";import{MarkdownShortcutPlugin as er}from"@lexical/react/LexicalMarkdownShortcutPlugin";import{AutoFocusPlugin as tr}from"@lexical/react/LexicalAutoFocusPlugin";import{TablePlugin as or}from"@lexical/react/LexicalTablePlugin";import{$convertFromMarkdownString as nr}from"@lexical/markdown";import{$getRoot as rr,createEditor as ir}from"lexical";import{useLexicalComposerContext as Vt}from"@lexical/react/LexicalComposerContext";import{useEffect as Zo}from"react";import{useLexicalComposerContext as Xo}from"@lexical/react/LexicalComposerContext";import{$isListItemNode as Jo,$isListNode as Dt,ListNode as Qo}from"@lexical/list";import{$getNodeByKey as jo,TextNode as en}from"lexical";var tn=/^\[(\s|x)?\]\s/i;function Ne(){let[e]=Xo();return Zo(()=>{let t=e.registerMutationListener(Qo,r=>{e.getEditorState().read(()=>{for(let[n,i]of r){if(i==="destroyed")continue;let l=e.getElementByKey(n),s=jo(n);l&&Dt(s)&&(l.__lexicalListType=s.getListType())}})}),o=e.registerNodeTransform(en,r=>{let n=r.getParent();if(!Jo(n)||n.getFirstChild()?.getKey()!==r.getKey())return;let i=n.getParent();if(!Dt(i)||i.getListType()==="check")return;let l=r.getTextContent(),s=l.match(tn);if(!s)return;let u=s[1]==="x"||s[1]==="X";r.setTextContent(l.slice(s[0].length)),i.setListType("check"),n.setChecked(u),r.select(0,0)});return()=>{t(),o()}},[e]),null}import{useEffect as on}from"react";import{useLexicalComposerContext as nn}from"@lexical/react/LexicalComposerContext";import{$createParagraphNode as rn,$getSelection as ln,$isLineBreakNode as sn,$isParagraphNode as an,$isRangeSelection as un,$isRootOrShadowRoot as _t,COMMAND_PRIORITY_LOW as cn,KEY_ARROW_DOWN_COMMAND as dn,TextNode as mn}from"lexical";import{$createCodeNode as fn,$isCodeNode as pn}from"@lexical/code";var gn=/^```(\w[\w-]*)?$/;function ze(){let[e]=nn();return on(()=>{let t=e.registerNodeTransform(mn,r=>{let n=r.getParent();if(!an(n)||n.getFirstChild()?.getKey()!==r.getKey())return;let i=n.getParent();if(!i||!_t(i))return;let s=r.getTextContent().trimEnd().match(gn);if(!s)return;let u=s[1]||void 0,a=fn(u);n.replace(a),a.selectEnd()}),o=e.registerCommand(dn,()=>{let r=ln();if(!un(r)||!r.isCollapsed())return!1;let n=r.anchor,i=n.getNode(),l=i;for(;l.getParent()&&!_t(l.getParent());)l=l.getParent();if(!pn(l))return!1;let s=l.getParent();if(!s||s.getLastChild()?.getKey()!==l.getKey())return!1;let u=m=>sn(m)||m.getTextContent().includes(`
|
|
4
|
-
`),a;if(i.getKey()===l.getKey())a=l.getChildren().slice(n.offset).some(u);else if(i.getTextContent().slice(n.offset).includes(`
|
|
5
|
-
`))a=!0;else{let m=i;for(;m.getParent()&&m.getParent().getKey()!==l.getKey();)m=m.getParent();a=m.getNextSiblings().some(u)}if(a)return!1;let c=rn();return l.insertAfter(c),c.selectStart(),!0},cn);return()=>{t(),o()}},[e]),null}import{useEffect as hn}from"react";import{useLexicalComposerContext as yn}from"@lexical/react/LexicalComposerContext";function Me(){let[e]=yn();return hn(()=>Re(e),[e]),null}import{useEffect as bn,useRef as Ht}from"react";import{useLexicalComposerContext as xn}from"@lexical/react/LexicalComposerContext";import{$getRoot as Cn,$getSelection as En,$isRangeSelection as Tn,RootNode as Rn}from"lexical";import{$trimTextContentFromAnchor as Ln}from"@lexical/selection";import{mergeRegister as kn}from"@lexical/utils";function Ie(){return Cn().getTextContentSize()}function $e({maxLength:e,onCharacterCountChange:t}){let[o]=xn(),r=Ht(t);r.current=t;let n=Ht(null);return bn(()=>{let i=s=>{n.current!==s&&(n.current=s,r.current?.(s))},l=!0;return queueMicrotask(()=>{l&&i(o.getEditorState().read(Ie))}),kn(()=>{l=!1},o.registerUpdateListener(({editorState:s,dirtyElements:u,dirtyLeaves:a})=>{u.size===0&&a.size===0||i(s.read(Ie))}),e===void 0?()=>{}:o.registerNodeTransform(Rn,s=>{let u=En();if(!Tn(u)||!u.isCollapsed())return;let a=o.getEditorState().read(Ie),c=s.getTextContentSize();if(c===a)return;let m=c-e;m>0&&Ln(o,u.anchor,m)}))},[o,e]),null}import{useEffect as Sn}from"react";import{useLexicalComposerContext as wn}from"@lexical/react/LexicalComposerContext";import{$hasUpdateTag as vn,PASTE_TAG as Pn}from"lexical";import{LinkNode as Nn}from"@lexical/link";function Ae(){let[e]=wn();return Sn(()=>e.registerNodeTransform(Nn,t=>{if(!(!vn(Pn)||K(t.getURL()))){for(let o of t.getChildren())t.insertBefore(o);t.remove()}}),[e]),null}import{useEffect as Dn}from"react";import{useLexicalComposerContext as _n}from"@lexical/react/LexicalComposerContext";import{$getSelection as Hn,$isRangeSelection as Fn,COMMAND_PRIORITY_HIGH as Gn,KEY_DOWN_COMMAND as Un}from"lexical";import{useEffect as zn,useState as Ft}from"react";import{useLexicalComposerContext as Mn}from"@lexical/react/LexicalComposerContext";import{jsx as In}from"react/jsx-runtime";var re=new Map;function v(e,t){re.get(e)?.(t)}function ie(){let[e]=Mn(),[t,o]=Ft(!1),[r,n]=Ft("");return zn(()=>{if(re.has(e))return;let i=!1;return re.set(e,l=>{i=!i,n(i?l:`${l}\xA0`)}),o(!0),()=>{re.delete(e),o(!1)}},[e]),t?In("div",{className:"zui-text-editor-live",role:"status","aria-live":"polite","aria-atomic":"true",children:r}):null}import{useEffect as $n}from"react";import{useLexicalComposerContext as An}from"@lexical/react/LexicalComposerContext";import{COMMAND_PRIORITY_HIGH as Bn,KEY_DOWN_COMMAND as Kn}from"lexical";function On(e){return!(e.metaKey||e.ctrlKey)||!e.altKey?null:e.key==="Enter"?e.shiftKey?"insert-before":"insert-after":e.key==="Backspace"&&e.shiftKey?"delete":null}function Be({labels:e}={}){let[t]=An(),o=L().table,r=e?.inserted??o.columnInserted,n=e?.deleted??o.columnDeleted;return $n(()=>t.registerCommand(Kn,i=>{let l=On(i);if(!l)return!1;let s=O();return s?(i.preventDefault(),l==="delete"?yt(s)&&v(t,n):ht(s,l==="insert-after"?"after":"before")&&v(t,r),!0):!1},Bn),[t,r,n]),null}import{Fragment as Yn,jsx as Gt,jsxs as Vn}from"react/jsx-runtime";function Wn(e){let t=e.metaKey||e.ctrlKey;return e.altKey?null:e.key==="Enter"&&t?e.shiftKey?"insert-above":"insert-below":e.key==="Backspace"&&t&&e.shiftKey?"delete":e.key==="Tab"&&!t&&!e.shiftKey?"tab":null}function Ke({labels:e,columnLabels:t}={}){let[o]=_n(),r=L().table,n=e?.inserted??r.rowInserted,i=e?.deleted??r.rowDeleted;return Dn(()=>o.registerCommand(Un,l=>{let s=Wn(l);if(!s)return!1;let u=O(),a=Q();if(!u||!a)return!1;if(s==="tab"){let c=Hn();return!(a.row===a.rows-1&&a.column===a.columns-1)||!Fn(c)||!c.isCollapsed()?!1:(l.preventDefault(),j(u,a.rows),v(o,n),!0)}return l.preventDefault(),s==="delete"?dt(u)&&v(o,i):ct(u,s==="insert-above"?"above":"below")&&v(o,n),!0},Gn),[o,n,i]),Vn(Yn,{children:[Gt(Be,{labels:t}),Gt(ie,{})]})}import{Fragment as pr,jsx as E,jsxs as Wt}from"react/jsx-runtime";var lr={};function qt(e){console.error(e)}function sr(e,t){let o=ir({namespace:"ZuiTextEditorInit",nodes:t.nodes,onError:qt});return o.update(()=>nr(e,t.sync),{discrete:!0}),o.getEditorState()}var ar=()=>()=>{};function ur(){return qn(ar,()=>!0,()=>!1)}function cr({state:e}){let t=e.read(()=>rr().getChildren().map(o=>o.getTextContent()));return E("div",{className:"zui-text-editor-body",children:E("div",{className:"zui-text-editor-main",children:E("div",{className:"zui-text-editor-content","aria-readonly":"true",children:t.map((o,r)=>E("p",{children:o},r))})})})}function dr({readOnly:e}){let[t]=Vt();return le(()=>{t.setEditable(!e)},[t,e]),null}function mr({onEditorReady:e}){let[t]=Vt();return le(()=>{e?.(t)},[t,e]),null}function fr(e,t){let o=Z(e);o.current=e;let r=Z(null),n=Z(null);return le(()=>()=>{if(r.current===null)return;clearTimeout(r.current),r.current=null;let i=n.current;n.current=null,i!==null&&o.current?.(i)},[]),Yt(i=>{if(t<=0){o.current?.(i);return}r.current!==null&&clearTimeout(r.current),n.current=i,r.current=setTimeout(()=>{r.current=null,n.current=null,o.current?.(i)},t)},[t])}function Oe({value:e,defaultValue:t,onValueChange:o,debounceMs:r=0,readOnly:n=!1,className:i,mode:l="edit-rich",autoFocus:s=!1,maxTextWidth:u,newBlockWidth:a=lr,drawingStyle:c="clean",onError:m=qt,nodes:f,transformers:x,nodeClassNames:C,onEditorReady:R,labels:y,maxLength:p,onCharacterCountChange:d,id:h,name:g,"aria-label":z,"aria-labelledby":S,"aria-describedby":T,"aria-invalid":M,"aria-required":I,preset:w=ee,children:$}){let[A]=Ut(()=>{let D=bt(w.transformers,x);return{nodes:[...w.nodes,...f??[]],sync:D,shortcuts:xt(D),theme:C?$t(Pe,C):Pe}}),[fe,pe]=Ut(t??""),b=e??fe,k=Z(m);k.current=m;let F=fr(o,r),G=Yt(D=>{pe(D),F(D)},[F]),U=Y(()=>l==="view"?sr(b,A):null,[]),B=Y(()=>({namespace:"ZuiTextEditor",theme:A.theme,onError:D=>k.current(D),nodes:A.nodes,editable:!n&&l!=="view",editorState:U?JSON.stringify(U.toJSON()):void 0}),[]),J=ur(),Je=Y(()=>rt(y),[y]),Qe=Y(()=>({id:h,name:g,"aria-label":z,"aria-labelledby":S,"aria-describedby":T,"aria-invalid":M,"aria-required":I}),[h,g,z,S,T,M,I]),fo=Y(()=>({mode:l,readOnly:n,autoFocus:s,rawValue:b,onRawChange:G,newBlockWidth:a,drawingStyle:c,labels:Je,maxLength:p,field:Qe}),[l,n,s,b,G,a,c,Je,p,Qe]),ge=l==="edit-raw",je=Y(()=>u!==void 0?{"--zui-text-editor-measure":u}:void 0,[u]),et=Z(d);return et.current=d,le(()=>{ge&&et.current?.(b.length)},[ge,b]),U&&!J?E("div",{className:`zui-text-editor ${i??""}`,style:je,children:E(cr,{state:U})}):E(Zn,{initialConfig:B,children:E(nt.Provider,{value:fo,children:Wt("div",{className:`zui-text-editor ${i??""}`,style:je,children:[E(mr,{onEditorReady:R}),$,!ge&&Wt(pr,{children:[E(ve,{markdown:b,onValueChange:G,transformers:A.sync}),(p!==void 0||d!==void 0)&&E($e,{maxLength:p,onCharacterCountChange:d}),E(Xn,{}),E(Jn,{}),E(Qn,{}),E(Ne,{}),E(ze,{}),E(Me,{}),E(or,{}),E(Ke,{}),E(jn,{validateUrl:K}),E(Ae,{}),E(er,{transformers:A.shortcuts}),E(dr,{readOnly:n||l==="view"}),s&&E(tr,{}),w.plugins]})]})})})}import{RichTextPlugin as ei}from"@lexical/react/LexicalRichTextPlugin";import{ContentEditable as ti}from"@lexical/react/LexicalContentEditable";import{LexicalErrorBoundary as oi}from"@lexical/react/LexicalErrorBoundary";import{useCallback as se,useEffect as gr,useLayoutEffect as hr,useRef as De,useState as _e}from"react";import{$getRoot as yr,$getSelection as br,$isRangeSelection as xr}from"lexical";import{useLexicalComposerContext as Cr}from"@lexical/react/LexicalComposerContext";import{$isHeadingNode as He}from"@lexical/rich-text";import{jsx as ae,jsxs as Lr}from"react/jsx-runtime";var Zt={h1:1,h2:2,h3:3,h4:4,h5:5,h6:6},Er={hidden:new Set,headings:[]};function Tr(e,t){if(e.hidden.size!==t.hidden.size||e.headings.length!==t.headings.length)return!1;for(let o of e.hidden)if(!t.hidden.has(o))return!1;return e.headings.every((o,r)=>o.key===t.headings[r].key&&o.folded===t.headings[r].folded)}function Rr(e,t){return e.length===t.length&&e.every((o,r)=>{let n=t[r];return o.key===n.key&&o.folded===n.folded&&o.top===n.top&&o.height===n.height})}function Fe({labels:e}={}){let[t]=Cr(),[o,r]=_e(new Set),[n,i]=_e(Er),[l,s]=_e([]),u=De(o);u.current=o;let a=De(n);a.current=n;let c={...L().collapsibleHeadings,...e},m=se(()=>{t.getEditorState().read(()=>{let y=yr().getChildren(),p=u.current,d=new Set,h=[];for(let S=0;S<y.length;S++){let T=y[S];if(!He(T))continue;let M=Zt[T.getTag()]??6,I=p.has(T.getKey());if(h.push({key:T.getKey(),folded:I}),!!I)for(let w=S+1;w<y.length;w++){let $=y[w];if(He($)&&(Zt[$.getTag()]??6)<=M)break;d.add($.getKey())}}let g=br();if(xr(g)){let S=g.anchor.getNode().getTopLevelElement();if(S&&d.has(S.getKey())){let T=S.getPreviousSibling();for(;T;){if(He(T)&&p.has(T.getKey())){let M=T.getKey();r(I=>{let w=new Set(I);return w.delete(M),w});return}T=T.getPreviousSibling()}}}let z={hidden:d,headings:h};Tr(a.current,z)||(a.current=z,i(z))})},[t]),f=De(new Set),x=se(()=>{let{hidden:y,headings:p}=a.current,d=new Set;for(let h of y){let g=t.getElementByKey(h);g&&(d.add(g),g.style.display!=="none"&&(g.style.display="none"))}for(let h of f.current)!d.has(h)&&h.style.display==="none"&&(h.style.display="");f.current=d;for(let{key:h,folded:g}of p)t.getElementByKey(h)?.classList.toggle("zui-heading-folded",g)},[t]),C=se(()=>{let y=a.current.headings.map(({key:p,folded:d})=>{let h=t.getElementByKey(p);return{key:p,folded:d,top:h?.offsetTop??0,height:h?.offsetHeight??0}});s(p=>Rr(p,y)?p:y)},[t]);hr(()=>{x(),C()},[n,x,C]),gr(()=>{m();let y=()=>{m(),x(),C()},p=t.registerUpdateListener(y),d=t.getRootElement(),h=typeof ResizeObserver<"u"?new ResizeObserver(C):null;return d&&h&&h.observe(d),()=>{p(),h?.disconnect()}},[t,m,x,C,o]);let R=se(y=>{let p=!u.current.has(y);r(d=>{let h=new Set(d);return h.has(y)?h.delete(y):h.add(y),h}),v(t,p?c.collapsed:c.expanded)},[t,c.collapsed,c.expanded]);return Lr("div",{className:"zui-text-editor-fold-gutter",children:[ae(ie,{}),l.map(({key:y,folded:p,top:d,height:h})=>ae("button",{type:"button",className:`zui-text-editor-fold ${p?"is-folded":""}`,style:{top:d+Math.max(0,(Math.min(h,44)-18)/2)},title:p?c.expand:c.collapse,"aria-label":p?c.expand:c.collapse,"aria-expanded":!p,onClick:()=>R(y),children:ae("svg",{viewBox:"0 0 20 20",width:"12",height:"12",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:ae("path",{d:"M6 8l4 4 4-4"})})},y))]})}import{useCallback as kr,useEffect as V,useRef as Xt,useState as Ge}from"react";import{useLexicalComposerContext as Sr}from"@lexical/react/LexicalComposerContext";import{useLexicalEditable as wr}from"@lexical/react/useLexicalEditable";import{$createRangeSelection as vr,$getSelection as Jt,$isRangeSelection as Qt,$setSelection as Pr,COMMAND_PRIORITY_LOW as Nr}from"lexical";import{$isLinkNode as zr,$toggleLink as Mr}from"@lexical/link";import{$findMatchingParent as Ir}from"@lexical/utils";import{jsx as X,jsxs as Ar}from"react/jsx-runtime";function jt(e){return{key:e.key,offset:e.offset,type:e.type}}function eo(e,t){return e.key===t.key&&e.offset===t.offset&&e.type===t.type}function to(e,t){let o=e.getRootElement()?.parentElement;if(!t||!o)return null;let r=o.getBoundingClientRect();return{top:t.bottom-r.top+o.scrollTop+4,insetInlineStart:Math.max(0,t.left-r.left+o.scrollLeft)}}function $r(e,t){let r=e.getRootElement()?.ownerDocument.defaultView?.getSelection();if(r&&r.rangeCount>0){let i=r.getRangeAt(0).getBoundingClientRect();if(i.width>0||i.height>0)return i}let n=e.getElementByKey(t);return n?n.getBoundingClientRect():null}function Ue(){let[e]=Sr(),t=wr(),{link:o,setLink:r}=Ct(),n=L(),[i,l]=Ge(""),[s,u]=Ge(null),[a,c]=Ge(null),m=Xt(null),f=Xt(null),x=o?.key??null,C=o?.url??"";V(()=>{l(C)},[x,C]),V(()=>{x!==null&&c(null)},[x]),V(()=>e.registerCommand(ot,()=>{let d=Jt();if(!Qt(d))return!1;if(Ir(d.anchor.getNode(),zr))return m.current?.focus(),!0;if(d.isCollapsed())return!1;let h=to(e,$r(e,d.anchor.key));return h?(l(""),c({anchor:jt(d.anchor),focus:jt(d.focus),style:h}),!0):!1},Nr),[e]),V(()=>{if(a!==null)return e.registerUpdateListener(({editorState:d})=>{d.read(()=>{let g=Jt();return Qt(g)&&eo(a.anchor,g.anchor)&&eo(a.focus,g.focus)})||c(null)})},[e,a]),V(()=>{a!==null&&m.current?.focus()},[a]),V(()=>{if(a!==null){u(a.style);return}if(x===null){u(null);return}let d=e.getElementByKey(x);u(to(e,d?d.getBoundingClientRect():null))},[e,x,C,a]);let R=kr(()=>c(null),[]);if(!t||s===null||x===null&&a===null)return null;let y=()=>{let d=i.trim();if(a!==null){if(d===""||!K(d))return;c(null),e.update(()=>{let h=vr();h.anchor.set(a.anchor.key,a.anchor.offset,a.anchor.type),h.focus.set(a.focus.key,a.focus.offset,a.focus.type),Pr(h),Mr(d)});return}d===""?r(null):K(d)&&r(d)},p=i.trim()!==""&&!K(i);return Ar("div",{ref:f,className:"zui-text-editor-link-bubble",role:"group","aria-label":n.toolbar.link,style:s,"data-slot":"link-bubble",onBlur:d=>{a!==null&&!(d.relatedTarget instanceof Node&&f.current?.contains(d.relatedTarget))&&R()},children:[X("input",{ref:m,type:"url",className:"zui-text-editor-link-input","aria-label":n.toolbar.linkUrl,"aria-invalid":p||void 0,placeholder:n.toolbar.linkUrlPlaceholder,value:i,onChange:d=>l(d.target.value),onKeyDown:d=>{d.key==="Enter"?(d.preventDefault(),y(),e.focus()):d.key==="Escape"&&(d.preventDefault(),R(),e.focus())}}),X("button",{type:"button",className:"zui-text-editor-toolbar-button",onClick:y,disabled:p,children:n.toolbar.linkApply}),X("button",{type:"button",className:"zui-text-editor-toolbar-button",title:n.toolbar.removeLink,"aria-label":n.toolbar.removeLink,onClick:()=>{a!==null?R():r(null),e.focus()},children:X("svg",{viewBox:"0 0 20 20",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:X("path",{d:"M5 5l10 10M15 5L5 15"})})})]})}import{useCallback as lo}from"react";import{useLexicalComposerContext as Xr}from"@lexical/react/LexicalComposerContext";import{useLexicalEditable as Jr}from"@lexical/react/useLexicalEditable";import{useCallback as oo,useEffect as Br,useRef as Kr,useState as no}from"react";import{useLexicalComposerContext as Or}from"@lexical/react/LexicalComposerContext";import{jsx as q,jsxs as Dr}from"react/jsx-runtime";var We={row:28,column:24};function ue({axis:e,box:t,lanes:o,current:r,insertable:n,canDelete:i,onInsert:l,onDelete:s,labels:u}){let[a]=Or(),c=L().table,m=Kr(null),[f,x]=no(!1),[C,R]=no(null),y=We[e],p=e==="row",d=oo(b=>{if(b<o.length)return o[b].start;let k=o[o.length-1];return k?k.start+k.size:0},[o]),h=oo(b=>{let k=m.current?.getBoundingClientRect();k&&R(p?b.clientY-k.top:b.clientX-k.left)},[p]);if(Br(()=>{let b=m.current;b&&x(getComputedStyle(b).direction==="rtl")},[]),o.length===0)return null;let g=(()=>{if(C===null)return{mode:"insert",index:o.length};let b=o.length,k=Number.POSITIVE_INFINITY;for(let B of n){let J=Math.abs(d(B)-C);J<k&&(k=J,b=B)}let F=o.findIndex(B=>C>=B.start&&C<B.start+B.size),G=o[F],U=G?Math.min(10,G.size*.3):0;return!i||F===-1||k<=U?{mode:"insert",index:b}:{mode:"delete",index:F}})(),z=b=>p?{top:b}:{left:b},S=b=>p?{top:b.start+3,height:Math.max(4,b.size-6)}:{left:b.start+3,width:Math.max(4,b.size-6)},T=p?{insetInlineStart:y,width:t.width}:{top:y,height:t.height},M=f?t.right:t.left,I=o[Math.min(r,o.length-1)],w=g.mode==="insert"&&g.index===o.length,$=g.mode==="delete"?(p?c.deleteRow:c.deleteColumn)(g.index+1):w?p?c.addRow:c.addColumn:(p?c.insertRowBefore:c.insertColumnBefore)(g.index+1),A={inserted:p?c.rowInserted:c.columnInserted,deleted:p?c.rowDeleted:c.columnDeleted,...u},fe=()=>{g.mode==="insert"?l(g.index):s(g.index),v(a,g.mode==="insert"?A.inserted:A.deleted)},pe=g.mode==="insert"?{...z(d(g.index)),...T}:p?{top:o[g.index].start,height:o[g.index].size,...T}:{left:o[g.index].start,width:o[g.index].size,...T};return Dr("div",{ref:m,className:`zui-table-rail is-${e}`,style:p?{top:t.top,insetInlineStart:M-y,width:y,height:t.height}:{top:t.top-y,insetInlineStart:M,width:t.width,height:y},onPointerMove:h,onPointerLeave:()=>R(null),children:[q("div",{className:"zui-table-rail-marker",style:S(I),"aria-hidden":!0}),q("button",{type:"button",className:`zui-table-rail-handle is-${g.mode} ${C===null?"is-resting":""}`,style:z(g.mode==="insert"?d(g.index):o[g.index].start+o[g.index].size/2),title:$,"aria-label":$,onMouseDown:b=>b.preventDefault(),onClick:fe,children:q("svg",{viewBox:"0 0 12 12",width:"12",height:"12",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:g.mode==="insert"?q("path",{d:"M6 2.5v7M2.5 6h7"}):q("path",{d:"M2.5 6h7"})})}),q("div",{className:`zui-table-rail-preview is-${g.mode}`,style:pe,"aria-hidden":!0})]})}import{jsx as ce}from"react/jsx-runtime";function _r({children:e}){return ce("svg",{viewBox:"0 0 20 20",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:e})}function Ye({settings:e,style:t,onSettings:o}){let r=Rt(),n=L();return ce("div",{className:"zui-table-settings",role:"toolbar","aria-label":n.table.settings,style:t,...r,children:Et.map(({preset:i,label:l,icon:s,width:u,density:a})=>ce(oe,{label:n.layout[l],active:Tt(e.width)===i,onClick:()=>o({width:u,density:a}),children:ce(_r,{children:s})},i))})}import{useCallback as Hr,useEffect as ro,useRef as Fr,useState as Gr}from"react";import{useLexicalComposerContext as Ur}from"@lexical/react/LexicalComposerContext";function Wr(e,t){return e.top===t.top&&e.left===t.left&&e.right===t.right&&e.width===t.width&&e.height===t.height}function io(e,t){return e.length===t.length&&e.every((o,r)=>o.start===t[r].start&&o.size===t[r].size)}function Yr(e,t){return e===t?!0:!e||!t?!1:e.key===t.key&&e.settings===t.settings&&e.position===t.position&&Wr(e.box,t.box)&&io(e.rows,t.rows)&&io(e.columns,t.columns)}function Vr(e,t){return e.row===t.row&&e.column===t.column&&e.rows===t.rows&&e.columns===t.columns&&e.hasHeader===t.hasHeader}function qr(e,t){return e.width===t.width&&e.density===t.density}function Zr(e,t,o,r){let n=e.getBoundingClientRect(),i=t.getBoundingClientRect(),l=Array.from(e.querySelectorAll(":scope > tbody > tr, :scope > tr")),s=l.map(m=>{let f=m.getBoundingClientRect();return{start:f.top-n.top,size:f.height}}),u={top:n.top-i.top,left:n.left-i.left,right:i.right-n.right,width:n.width,height:n.height},c=o!==null&&o.key===r&&o.columns.length===(l[0]?.children.length??0)&&o.box.width===u.width&&o.box.height===u.height?o.columns:Array.from(l[0]?.children??[]).map(m=>{let f=m.getBoundingClientRect();return{start:f.left-n.left,size:f.width}});return{box:u,rows:s,columns:c}}function Ve(){let[e]=Ur(),[t,o]=Gr(null),r=Fr(t);r.current=t;let n=Hr(()=>{let l=e.getEditorState().read(()=>{let x=O(),C=Q();return x&&C?{key:x.getKey(),settings:it(x),position:C}:null}),s=l?e.getElementByKey(l.key):null,u=e.getRootElement()?.parentElement,a=r.current;if(!l||!s||!u){a!==null&&o(null);return}let c=a&&a.key===l.key&&qr(a.settings,l.settings)?a.settings:l.settings,m=a&&Vr(a.position,l.position)?a.position:l.position,f={key:l.key,settings:c,position:m,...Zr(s,u,a,l.key)};Yr(a,f)||(r.current=f,o(f))},[e]);ro(()=>{n();let l=e.registerUpdateListener(n),s=e.getRootElement(),u=typeof ResizeObserver<"u"?new ResizeObserver(n):null;return s&&u&&u.observe(s),()=>{l(),u?.disconnect()}},[e,n]);let i=t?.key??null;return ro(()=>{if(i===null||typeof ResizeObserver>"u")return;let l=e.getElementByKey(i);if(!l)return;let s=new ResizeObserver(n);return s.observe(l),()=>s.disconnect()},[e,i,n]),t}import{Fragment as Qr,jsx as qe,jsxs as jr}from"react/jsx-runtime";function Ze(){let[e]=Xr(),t=Jr(),o=Ve(),r=lo(l=>{e.update(()=>{let s=O();s&&l(s)})},[e]),n=lo(l=>r(s=>lt(s,l)),[r]);if(!t||!o)return null;let{position:i}=o;return jr(Qr,{children:[qe(Ye,{settings:o.settings,style:{top:o.box.top-We.column,right:o.box.right},onSettings:n}),qe(ue,{axis:"row",box:o.box,lanes:o.rows,current:i.row,insertable:st(i),canDelete:at(i),onInsert:l=>r(s=>j(s,l,i.column)),onDelete:l=>r(s=>ut(s,l,i.column))}),qe(ue,{axis:"column",box:o.box,lanes:o.columns,current:i.column,insertable:mt(i),canDelete:ft(i),onInsert:l=>r(s=>pt(s,l,i.row)),onDelete:l=>r(s=>gt(s,l,i.row))})]})}import{Fragment as ni,jsx as P,jsxs as Xe}from"react/jsx-runtime";function de({placeholder:e,collapsible:t=!0,showCharacterCount:o=!1,children:r}){let{mode:n,readOnly:i,autoFocus:l,rawValue:s,onRawChange:u,labels:a,maxLength:c,field:m}=_(),f=e??a.placeholder,{name:x,...C}=m;return n==="edit-raw"?Xe(ni,{children:[P("textarea",{...m,className:"zui-text-editor-textarea",value:s,onChange:R=>u(R.target.value),placeholder:f,readOnly:i,autoFocus:l,maxLength:c,spellCheck:!1}),o&&P(W,{})]}):Xe("div",{className:"zui-text-editor-body",children:[Xe("div",{className:"zui-text-editor-main",children:[P(ei,{contentEditable:P(ti,{...C,className:"zui-text-editor-content","aria-placeholder":f,placeholder:P("div",{className:"zui-text-editor-placeholder",children:f})}),ErrorBoundary:oi}),t&&P(Fe,{}),P(Ze,{}),P(Ue,{}),o&&P(W,{}),x!==void 0&&P("input",{type:"hidden",name:x,value:s,readOnly:!0})]}),r]})}import{useCallback as ri,useEffect as ao,useState as so}from"react";import{useLexicalComposerContext as ii}from"@lexical/react/LexicalComposerContext";import{TableOfContentsPlugin as li}from"@lexical/react/LexicalTableOfContentsPlugin";import{jsx as H,jsxs as uo}from"react/jsx-runtime";var si={h1:0,h2:1,h3:2,h4:3,h5:4,h6:5};function ai(e,t){ao(()=>{for(let[o]of t)e.getElementByKey(o)?.setAttribute("data-outline-key",o)},[e,t])}function ui({editor:e,entries:t,activeKey:o,onSelect:r}){ai(e,t);let n=L().outline;return uo("nav",{className:"zui-text-editor-outline-list","aria-label":n.title,children:[t.length===0&&H("div",{className:"zui-text-editor-outline-empty",children:n.empty}),t.map(([i,l,s])=>H("button",{type:"button",className:`zui-text-editor-outline-item ${i===o?"is-active":""}`,style:{paddingInlineStart:`${.5+si[s]*.75}rem`},onClick:()=>r(i),children:l||n.untitled},i))]})}function me(){let[e]=ii(),[t,o]=so(!1),[r,n]=so(null),i=L().outline;ao(()=>{let s=e.getRootElement(),u=s?.closest(".zui-text-editor");if(!s||!(u instanceof HTMLElement))return;let a=0,c=()=>{cancelAnimationFrame(a),a=requestAnimationFrame(()=>{let f=s.querySelectorAll("h1, h2, h3, h4, h5, h6"),x=u.scrollTop+80,C=null;for(let R of f)R.offsetTop<=x&&(C=R.getAttribute("data-outline-key"));n(C)})};c(),u.addEventListener("scroll",c,{passive:!0});let m=e.registerUpdateListener(c);return()=>{cancelAnimationFrame(a),u.removeEventListener("scroll",c),m()}},[e]);let l=ri(s=>{e.getEditorState().read(()=>{e.getElementByKey(s)?.scrollIntoView({behavior:"smooth",block:"start"})})},[e]);return H(li,{children:s=>uo("div",{className:`zui-text-editor-outline ${t?"is-collapsed":""}`,children:[H("button",{type:"button",className:"zui-text-editor-outline-toggle",title:t?i.show:i.hide,"aria-label":t?i.show:i.hide,"aria-expanded":!t,onClick:()=>o(u=>!u),children:H("svg",{viewBox:"0 0 20 20",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:H("path",{d:"M4 5h12M4 10h8M4 15h10"})})}),!t&&H(ui,{editor:e,entries:s,activeKey:r,onSelect:l})]})})}import{jsx as N,jsxs as mo}from"react/jsx-runtime";function co({children:e,className:t}){let{mode:o,readOnly:r}=_();return o!=="edit-rich"||r?null:N(Lt,{className:t,children:e})}function Ea(e=ee){let t=e.plugins!==void 0,o={format:N(be,{}),block:N(xe,{}),insert:N(Ce,{drawing:t}),history:N(Ee,{})};function r(i){return N(Oe,{preset:e,...i})}function n({placeholder:i,toolbar:l=!0,outline:s=!1,collapsible:u=!0,showCharacterCount:a=!1,children:c,...m}){return mo(r,{...m,children:[l===!0&&mo(co,{children:[o.format,N(te,{}),o.block,N(te,{}),o.insert]}),typeof l=="function"&&l(o),N(de,{placeholder:i,collapsible:u,showCharacterCount:a,children:s&&N(me,{})}),c]})}return n.Root=r,n.Content=de,n.Toolbar=co,n.ToolbarButton=oe,n.ToolbarDivider=te,n.FormatButtons=be,n.BlockButtons=xe,n.InsertButtons=Ce,n.HistoryButtons=Ee,n.Outline=me,n.CharacterCount=W,n}export{ne as a,vt as b,Re as c,Le as d,Se as e,Go as f,Uo as g,Pe as h,$t as i,W as j,Ea as k};
|
package/dist/chunk-SDICQI2B.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
function c(o,e,n="below"){let t=o.getRootElement()?.parentElement;if(!t||!e)return null;let l=t.getBoundingClientRect();return{top:n==="below"?e.bottom-l.top+t.scrollTop+4:e.top-l.top+t.scrollTop-4,insetInlineStart:Math.max(0,e.left-l.left+t.scrollLeft),...n==="above"?{transform:"translateY(-100%)"}:{}}}function r(){if(typeof window>"u")return null;let o=window.getSelection();if(!o||o.rangeCount===0)return null;let e=o.getRangeAt(0);if(typeof e.getBoundingClientRect!="function")return null;let n=e.getBoundingClientRect();if(n.width===0&&n.height===0){let t=e.startContainer,l=t instanceof Element?t:t.parentElement;return l?l.getBoundingClientRect():null}return n}function u(o,e){let n=r();if(n)return n;if(e===null)return null;let t=o.getElementByKey(e);return t?t.getBoundingClientRect():null}export{c as a,u as b};
|
package/dist/chunk-XP3MZRCW.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import{b as K,c as Z}from"./chunk-5VRVC56Y.js";import{a as j,b as ee}from"./chunk-SDICQI2B.js";import{useCallback as te,useEffect as y,useId as ge,useMemo as Y,useRef as h,useState as E}from"react";import{useLexicalComposerContext as de}from"@lexical/react/LexicalComposerContext";import{useLexicalEditable as me}from"@lexical/react/useLexicalEditable";import{$createTextNode as ne,$getNodeByKey as fe,$getSelection as le,$isRangeSelection as ae,$isTextNode as ce,COMMAND_PRIORITY_EDITOR as re,COMMAND_PRIORITY_HIGH as x,SELECTION_CHANGE_COMMAND as ye,KEY_ARROW_DOWN_COMMAND as pe,KEY_ARROW_UP_COMMAND as Me,KEY_ENTER_COMMAND as Ne,KEY_ESCAPE_COMMAND as Re,KEY_TAB_COMMAND as Ce,createCommand as he}from"lexical";import{mergeRegister as oe}from"@lexical/utils";import{Fragment as Ie,jsx as v,jsxs as se}from"react/jsx-runtime";var Ee={suggestions:l=>`Suggestions for ${l}`,noResults:"No matches",loading:"Searching"},xe=he("INSERT_MENTION_COMMAND"),ve=40;function ie(l){return l.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function $e(l,a,s){let u=l.slice(0,a);for(let m of s){let c=new RegExp(`(?:^|[\\s(\\[])(${ie(m)})([^\\s${ie(m)}]{0,${ve}})$`).exec(u);if(!c)continue;let r=c.index+c[0].length-c[1].length-c[2].length;return{trigger:m,query:c[2],from:r}}return null}function Ae(l){let a=le();if(!ae(a)||!a.isCollapsed())return null;let s=a.anchor.getNode();if(!ce(s)||Z(s)||s.hasFormat("code")||s.getMode()!=="normal")return null;let u=$e(s.getTextContent(),a.anchor.offset,l);return u?{...u,key:s.getKey()}:null}function _e({trigger:l="@",search:a,render:s,triggers:u,maxItems:m=8,labels:_,onSelect:c}){let[r]=de(),z=me(),I=Y(()=>({...Ee,..._}),[_]),g=Y(()=>u??(a?[{trigger:l,search:a,render:s}]:[]),[u,l,a,s]),p=Y(()=>g.map(e=>e.trigger),[g]),M=ge(),[i,$]=E(null),[N,O]=E([]),[B,A]=E(!1),[R,T]=E(0),[H,U]=E(null),b=h(null),S=h(i);S.current=i;let D=h(N);D.current=N;let G=h(R);G.current=R;let W=h(c);W.current=c,y(()=>{if(!z||p.length===0){$(null);return}let e=()=>{let t=r.getEditorState().read(()=>Ae(p)),o=t?`${t.key}:${t.from}:${t.trigger}:${t.query}`:null;t&&b.current===o||(o!==null&&(b.current=null),$(n=>n&&t&&n.key===t.key&&n.from===t.from&&n.trigger===t.trigger&&n.query===t.query?n:t))};return e(),oe(r.registerUpdateListener(e),r.registerCommand(ye,()=>(e(),!1),re))},[r,z,p]);let q=i?.query??null,L=i?.trigger??null;y(()=>{if(L===null||q===null){O([]),A(!1);return}let e=g.find(o=>o.trigger===L);if(!e)return;let t=!0;return A(!0),e.search(q).then(o=>{t&&(O(o.slice(0,m)),T(0),A(!1))}).catch(()=>{t&&(O([]),A(!1))}),()=>{t=!1}},[g,L,q,m]),y(()=>{if(!i){U(null);return}U(j(r,ee(r,i.key)))},[r,i]);let w=te(()=>{let e=S.current;e&&(b.current=`${e.key}:${e.from}:${e.trigger}:${e.query}`),$(null)},[]),P=te(e=>{let t=S.current;if(!t)return;let o=g.find(n=>n.trigger===t.trigger);r.update(()=>{let n=fe(t.key);if(!ce(n))return;let d=n.getTextContent(),f=t.from+t.trigger.length+t.query.length,Q=d.slice(t.from,f);if(Q!==t.trigger+t.query)return;let X=n.splitText(t.from,f).find(ue=>ue.getTextContent()===Q);if(!X)return;let J=K(e.id,e.name,t.trigger);X.replace(J);let V=ne(" ");J.insertAfter(V),V.select(1,1)}),$(null),o&&W.current?.(e,t.trigger)},[r,g]),C=i!==null;y(()=>{if(!C)return;let e=o=>n=>{let d=D.current.length;return d===0?!1:(n?.preventDefault(),T(f=>(f+o+d)%d),!0)},t=o=>{let n=D.current[G.current];return n?(o?.preventDefault(),P(n),!0):!1};return oe(r.registerCommand(pe,e(1),x),r.registerCommand(Me,e(-1),x),r.registerCommand(Ne,t,x),r.registerCommand(Ce,t,x),r.registerCommand(Re,o=>(o?.preventDefault(),w(),!0),x))},[r,C,P,w]),y(()=>r.registerCommand(xe,({id:e,name:t,trigger:o})=>{let n=le();if(!ae(n))return!1;let d=K(e,t,o??p[0]??"@"),f=ne(" ");return n.insertNodes([d,f]),!0},re),[r,p]);let k=C&&N[R]?`${M}-${R}`:null;if(y(()=>{let e=r.getRootElement();if(e&&C)return e.setAttribute("aria-controls",M),k?e.setAttribute("aria-activedescendant",k):e.removeAttribute("aria-activedescendant"),()=>{e.removeAttribute("aria-controls"),e.removeAttribute("aria-activedescendant")}},[r,C,M,k]),!i||H===null)return null;let F=g.find(e=>e.trigger===i.trigger)?.render;return se("div",{className:"zui-text-editor-mentions",style:H,"data-slot":"mentions",children:[v("div",{role:"listbox",id:M,"aria-label":I.suggestions(i.trigger),"aria-busy":B||void 0,children:N.map((e,t)=>{let o=t===R;return v("div",{id:`${M}-${t}`,role:"option","aria-selected":o,className:`zui-text-editor-mention-option${o?" is-active":""}`,onMouseDown:n=>n.preventDefault(),onMouseMove:()=>T(t),onClick:()=>P(e),children:F?F(e,{active:o,query:i.query,trigger:i.trigger}):se(Ie,{children:[v("span",{className:"zui-text-editor-mention-name",children:e.name}),e.hint&&v("span",{className:"zui-text-editor-mention-hint",children:e.hint})]})},e.id)})}),N.length===0&&v("div",{className:"zui-text-editor-mention-empty",role:"status",children:B?I.loading:I.noResults})]})}export{Ee as a,xe as b,$e as c,_e as d};
|