@cyte-editor/react 1.3.1 → 1.4.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/dist/cyte-editor-react.cjs +8 -8
- package/dist/cyte-editor-react.js +1572 -1521
- package/dist/style.css +1 -1
- package/package.json +6 -6
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
"use strict";/*!
|
|
2
|
-
* CyteEditor React Adapter v1.
|
|
2
|
+
* CyteEditor React Adapter v1.4.0 (@cyte-editor/react)
|
|
3
3
|
* (c) 2026 CyteEditor — All Rights Reserved.
|
|
4
4
|
*
|
|
5
5
|
* Commercial Software — NOT Open Source.
|
|
6
6
|
* Licensed under the CyteEditor Commercial License.
|
|
7
7
|
* SEE LICENSE IN ./LICENSE | Full EULA: https://cyteeditor.com/eula
|
|
8
8
|
*
|
|
9
|
-
* Build:
|
|
9
|
+
* Build: 1851043-dirty @ 2026-12-05T08:07:11.684Z
|
|
10
10
|
* Homepage: https://cyteeditor.com
|
|
11
11
|
* Contact: legal@cyteeditor.com (legal) / support@cyteeditor.com (support)
|
|
12
12
|
*
|
|
13
13
|
* UNAUTHORIZED COPYING, MODIFICATION, REDISTRIBUTION,
|
|
14
14
|
* REVERSE-ENGINEERING OR REMOVAL OF THIS NOTICE IS STRICTLY PROHIBITED.
|
|
15
|
-
*/Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("react"),et=require("@tiptap/pm/state"),Ve=require("@tiptap/pm/tables"),V=require("@cyte-editor/core"),tt=require("@cyte-editor/license"),Te=require("react-dom");function Je(n){var x,S;const o=t.useRef(null),c=t.useRef(null),[f,a]=t.useState(!1),[l,h]=t.useState(!1),[u,p]=t.useState(!0),m=t.useRef(!1),v=t.useRef(n);v.current=n;const C=t.useCallback((w,N)=>{if(!(m.current||!c.current)){if(N!==void 0){const s=JSON.stringify(c.current.getJSON()),r=JSON.stringify(N);if(s===r)return;c.current.setJSON(N);return}if(w!==void 0){if(w===c.current.getHTML())return;c.current.setContent(w)}}},[]);t.useEffect(()=>{var s,r;const w=o.current;if(!w)return;const N=V.EditorManager.create(w,v.current.config);return c.current=N,p(N.isEmpty()),N.on("update",({html:k})=>{var g,i;p(N.isEmpty()),m.current=!0,(i=(g=v.current).onUpdate)==null||i.call(g,k,N.getJSON()),Promise.resolve().then(()=>{m.current=!1})}),N.on("focus",({event:k})=>{var g,i;h(!0),(i=(g=v.current).onFocus)==null||i.call(g,k)}),N.on("blur",({event:k})=>{var g,i;h(!1),(i=(g=v.current).onBlur)==null||i.call(g,k)}),a(!0),(r=(s=v.current).onReady)==null||r.call(s,N),()=>{N.destroy(),c.current=null,a(!1)}},[]),t.useEffect(()=>{const w=c.current;w&&n.config.readonly!==void 0&&w.setReadonly(n.config.readonly)},[n.config.readonly,n.config.disabled]),t.useEffect(()=>{n.config.locale&&V.I18nManager.getInstance().setLocale(n.config.locale)},[n.config.locale]);const T=t.useRef((x=n.config.license)==null?void 0:x.key);return t.useEffect(()=>{var N;const w=(N=n.config.license)==null?void 0:N.key;w!==T.current&&(T.current=w,w&&c.current&&c.current.updateLicense(n.config.license))},[(S=n.config.license)==null?void 0:S.key]),{manager:c.current,isReady:f,isFocused:l,isEmpty:u,containerRef:o,setContentFromProp:C}}function qe(n){const[o,c]=t.useState({}),[f,a]=t.useState({}),l=t.useCallback(async()=>{if(!n)return;const h=n.getEditor(),u={},p={};for(const[T,x]of Object.entries(V.toolbarItemDefs))x.isActive&&(u[T]=x.isActive(h)),x.isDisabled&&(p[T]=x.isDisabled(h));const m=tt.getLicenseStatus(),v=m==="valid"||m==="expiring_soon",C=await n.hasSnapshots();if(p.compare=!C||!v,!v)for(const[T,x]of Object.entries(V.toolbarItemDefs))x.requiredTier&&T!=="compare"&&(p[T]=!0);for(const[T,x]of Object.entries(V.toolbarItemDefs))x.requiresPlugin&&!n.hasProPlugin(x.requiresPlugin)&&(p[T]=!0);c(u),a(p)},[n]);return t.useEffect(()=>{if(n)return n.on("selectionUpdate",l),n.on("update",l),n.on("transaction",l),n.on("snapshot-created",l),l(),()=>{n.off("selectionUpdate",l),n.off("update",l),n.off("transaction",l),n.off("snapshot-created",l)}},[n,l]),{activeStates:o,disabledStates:f,refresh:l}}function ue(){const n=V.I18nManager.getInstance(),[o,c]=t.useState(0);t.useEffect(()=>n.onChange(()=>{c(l=>l+1)}),[n]);function f(a,l){return n.t(a,l)}return{t:f,locale:n.getLocale()}}const nt={undo:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 7v6h6"/><path d="M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13"/></svg>',redo:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 7v6h-6"/><path d="M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3L21 13"/></svg>',bold:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"/><path d="M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"/></svg>',italic:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="4" x2="10" y2="4"/><line x1="14" y1="20" x2="5" y2="20"/><line x1="15" y1="4" x2="9" y2="20"/></svg>',underline:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 4v6a6 6 0 0 0 12 0V4"/><line x1="4" y1="20" x2="20" y2="20"/></svg>',strikethrough:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 4H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H7"/><line x1="3" y1="12" x2="21" y2="12"/></svg>',link:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>',image:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg>',table:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><line x1="3" y1="9" x2="21" y2="9"/><line x1="3" y1="15" x2="21" y2="15"/><line x1="9" y1="3" x2="9" y2="21"/><line x1="15" y1="3" x2="15" y2="21"/></svg>',video:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="16" height="16" rx="2"/><polygon points="9 8.5 14 12 9 15.5" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg>',bulletList:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="8" y1="4" x2="21" y2="4"/><line x1="8" y1="10" x2="21" y2="10"/><line x1="8" y1="16" x2="21" y2="16"/><line x1="8" y1="22" x2="21" y2="22"/><circle cx="4" cy="4" r="1" fill="currentColor"/><circle cx="4" cy="10" r="1" fill="currentColor"/><circle cx="4" cy="16" r="1" fill="currentColor"/><circle cx="4" cy="22" r="1" fill="currentColor"/></svg>',orderedList:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="8" y1="4" x2="21" y2="4"/><line x1="8" y1="10" x2="21" y2="10"/><line x1="8" y1="16" x2="21" y2="16"/><line x1="8" y1="22" x2="21" y2="22"/><text x="1" y="7" font-size="7" font-weight="bold" fill="currentColor" stroke="none" font-family="sans-serif">1</text><text x="1" y="13" font-size="7" font-weight="bold" fill="currentColor" stroke="none" font-family="sans-serif">2</text><text x="1" y="19" font-size="7" font-weight="bold" fill="currentColor" stroke="none" font-family="sans-serif">3</text><text x="1" y="25" font-size="7" font-weight="bold" fill="currentColor" stroke="none" font-family="sans-serif">4</text></svg>',outdent:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="7 8 3 12 7 16"/><line x1="21" y1="12" x2="11" y2="12"/><line x1="21" y1="6" x2="11" y2="6"/><line x1="21" y1="18" x2="11" y2="18"/></svg>',indent:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 8 7 12 3 16"/><line x1="21" y1="12" x2="11" y2="12"/><line x1="21" y1="6" x2="11" y2="6"/><line x1="21" y1="18" x2="11" y2="18"/></svg>',blockquote:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24"><path d="M4.58341 17.3211C3.55316 16.2275 3 15 3 13.0104C3 9.51092 5.45651 6.37372 9.03059 4.82324L9.92328 6.20085C6.58804 8.00545 5.93618 10.3461 5.67564 11.8221C6.21263 11.5444 6.91558 11.4467 7.60471 11.5106C9.40908 11.6778 10.8312 13.1591 10.8312 15C10.8312 16.933 9.26416 18.5 7.33116 18.5C6.2581 18.5 5.23196 18.0096 4.58341 17.3211ZM14.5834 17.3211C13.5532 16.2275 13 15 13 13.0104C13 9.51092 15.4565 6.37372 19.0306 4.82324L19.9233 6.20085C16.588 8.00545 15.9362 10.3461 15.6756 11.8221C16.2126 11.5444 16.9156 11.4467 17.6047 11.5106C19.4091 11.6778 20.8312 13.1591 20.8312 15C20.8312 16.933 19.2642 18.5 17.3312 18.5C16.2581 18.5 15.232 18.0096 14.5834 17.3211Z" fill="currentColor"/></svg>',codeBlock:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>',color:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3l6.5 13H5.5L12 3z"/><line x1="4" y1="21" x2="20" y2="21" stroke-width="3"/></svg>',bgColor:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="14" rx="2"/><line x1="4" y1="21" x2="20" y2="21" stroke-width="3"/></svg>',heading:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 4v16"/><path d="M18 4v16"/><path d="M6 12h12"/></svg>',align:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="3" y1="4" x2="21" y2="4"/><line x1="3" y1="10" x2="15" y2="10"/><line x1="3" y1="16" x2="21" y2="16"/><line x1="3" y1="22" x2="15" y2="22"/></svg>',fontFamily:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 20 L9 5 L15 20"/><line x1="6.2" y1="12" x2="11.8" y2="12"/><rect x="11" y="14" width="12" height="10" fill="white" stroke="none"/><line x1="14" y1="16" x2="20" y2="16"/><line x1="14" y1="19" x2="20" y2="19"/><line x1="14" y1="22" x2="20" y2="22"/></svg>',fontSize:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 40 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><text x="4" y="22" font-size="42" fill="currentColor" stroke="none" font-family="serif" font-weight="bold">A</text><rect x="20" y="10" width="16" height="16" fill="white" stroke="none"/><text x="24" y="25" font-size="36" fill="currentColor" stroke="none" font-family="serif" font-weight="bold">a</text></svg>',lineHeight:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="9" y1="4" x2="21" y2="4"/><line x1="9" y1="10" x2="21" y2="10"/><line x1="9" y1="16" x2="21" y2="16"/><line x1="9" y1="22" x2="21" y2="22"/><polyline points="3 10 3 4"/><polyline points="1 7 3 4 5 7"/><polyline points="3 16 3 22"/><polyline points="1 19 3 22 5 19"/></svg>',getHTML:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>',getJSON:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/><polyline points="10 9 9 9 8 9"/></svg>',importWord:'<svg xmlns="http://www.w3.org/2000/svg" width="26" height="26" viewBox="0 0 36 36" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M20 4H7a3 3 0 0 0-3 3v22a3 3 0 0 0 3 3h22a3 3 0 0 0 3-3V13z"/><polyline points="20 4 20 13 32 13"/><text x="8" y="27" font-size="16" font-weight="bold" fill="currentColor" stroke="none" font-family="sans-serif">W</text><path d="M28 28v-9m0 0l-3 3m3-3l3 3"/></svg>',importMarkdown:'<svg xmlns="http://www.w3.org/2000/svg" width="26" height="26" viewBox="0 0 36 36" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M20 4H7a3 3 0 0 0-3 3v22a3 3 0 0 0 3 3h22a3 3 0 0 0 3-3V13z"/><polyline points="20 4 20 13 32 13"/><text x="9" y="27" font-size="16" font-weight="bold" fill="currentColor" stroke="none" font-family="sans-serif">#</text><path d="M28 28v-9m0 0l-3 3m3-3l3 3"/></svg>',exportWord:'<svg xmlns="http://www.w3.org/2000/svg" width="26" height="26" viewBox="0 0 36 36" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M20 4H7a3 3 0 0 0-3 3v22a3 3 0 0 0 3 3h22a3 3 0 0 0 3-3V13z"/><polyline points="20 4 20 13 32 13"/><text x="8" y="27" font-size="16" font-weight="bold" fill="currentColor" stroke="none" font-family="sans-serif">W</text><path d="M28 19v9m0 0l-3-3m3 3l3-3"/></svg>',exportMarkdown:'<svg xmlns="http://www.w3.org/2000/svg" width="26" height="26" viewBox="0 0 36 36" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M20 4H7a3 3 0 0 0-3 3v22a3 3 0 0 0 3 3h22a3 3 0 0 0 3-3V13z"/><polyline points="20 4 20 13 32 13"/><text x="9" y="27" font-size="16" font-weight="bold" fill="currentColor" stroke="none" font-family="sans-serif">#</text><path d="M28 19v9m0 0l-3-3m3 3l3-3"/></svg>',imageUpload:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8" cy="8" r="1.5" fill="currentColor" stroke="none"/><polyline points="5 17 10 11 14 14 19 8"/></svg>',superscript:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24"><text x="2" y="20" font-size="20" fill="currentColor" stroke="none" font-family="serif" font-weight="bold">x</text><text x="14" y="12" font-size="11" fill="currentColor" stroke="none" font-family="serif" font-weight="bold">2</text></svg>',subscript:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24"><text x="2" y="20" font-size="20" fill="currentColor" stroke="none" font-family="serif" font-weight="bold">x</text><text x="14" y="22" font-size="11" fill="currentColor" stroke="none" font-family="serif" font-weight="bold">2</text></svg>',insertTable:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><line x1="3" y1="9" x2="21" y2="9"/><line x1="3" y1="15" x2="21" y2="15"/><line x1="9" y1="3" x2="9" y2="21"/><line x1="15" y1="3" x2="15" y2="21"/></svg>',formatPainter:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="5" width="14" height="7" rx="1"/><path d="M16 7.5h1.5c1.5 0 2.5 1 2.5 2.5v2.5c0 1.5-1 2.5-2.5 2.5h-4c-1.5 0-2.5 1-2.5 2.5V18"/><rect x="10" y="18" width="2" height="4.5" rx="0.5"/></svg>',compare:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="7" height="18" rx="1"/><rect x="14" y="3" width="7" height="18" rx="1"/><line x1="10" y1="8" x2="14" y2="8"/><line x1="10" y1="12" x2="14" y2="12"/><line x1="10" y1="16" x2="14" y2="16"/></svg>',snapshot:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"/><circle cx="12" cy="13" r="4"/></svg>',fullscreen:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 4H4V8M4 4L10 10"/><path d="M16 4H20V8M20 4L14 10"/><path d="M4 16V20H8M4 20L10 14"/><path d="M20 16V20H16M20 20L14 14"/></svg>',import:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 3h5a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-5"/><polyline points="9 8 14 12 9 16"/><line x1="3" y1="12" x2="14" y2="12"/></svg>',export:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h5"/><polyline points="16 8 21 12 16 16"/><line x1="10" y1="12" x2="21" y2="12"/></svg>',formula:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24"><text x="1" y="20" font-size="20" fill="currentColor" stroke="none" font-family="serif" font-weight="bold">Σ</text><text x="14" y="22" font-size="9" fill="currentColor" stroke="none" font-family="serif">x</text></svg>',structure:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="12 2.5 20 7 20 17 12 21.5 4 17 4 7"/><circle cx="12" cy="12" r="4"/></svg>',autoFormat:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 4V2"/><path d="M15 16v-2"/><path d="M8 9h2"/><path d="M20 9h2"/><path d="M17.8 11.8 19 13"/><path d="M17.8 6.2 19 5"/><path d="M3 21l9-9"/><path d="M12.2 6.2 11 5"/></svg>'};function ve(n){return nt[n]||""}const st=({visible:n,targetRect:o,editor:c,savedSelection:f,initialUrl:a,isEditing:l,onConfirm:h,onCancel:u,onClose:p})=>{const{t:m}=ue(),[v,C]=t.useState(a||""),[T,x]=t.useState(!1),S=t.useRef(null),[w,N]=t.useState(null),[s,r]=t.useState(""),k=()=>{if(c&&f)try{const{from:b,to:D}=f,E=c.view.coordsAtPos(b),$=c.view.coordsAtPos(D);if(E&&$){N(new DOMRect(E.left,E.top,$.left-E.left,E.bottom-E.top));return}}catch{}N(o||null)};t.useEffect(()=>{const b=()=>{n&&k()};return window.addEventListener("scroll",b,!0),window.addEventListener("resize",b),()=>{window.removeEventListener("scroll",b,!0),window.removeEventListener("resize",b)}},[n,c,f,o]),t.useEffect(()=>{n&&(C(a||""),r(""),k(),setTimeout(()=>{var b,D;(b=S.current)==null||b.focus(),(D=S.current)==null||D.select()},0))},[n]);const g=t.useMemo(()=>{const b=w;if(!b)return{};const D=180,E=8,$=window.innerHeight,J=window.innerWidth;let I=b.bottom+E,P=!1;I+D>$&&(I=b.top-D-E,P=!0),x(P);let B=b.left+b.width/2;const A=320;return B+A/2>J&&(B=J-A/2-16),B<A/2+16&&(B=A/2+16),{top:`${I}px`,left:`${B}px`}},[w]),i=b=>{try{const D=new URL(b);return D.protocol==="http:"||D.protocol==="https:"}catch{return!1}},y=()=>{const b=v.trim();if(l&&b===""){h(""),p();return}if(!b){r(m("link.urlRequired"));return}if(!i(b)){r(m("link.invalidUrl"));return}h(b),p()},H=()=>{h(""),p()},W=()=>{u(),p()};return n?e.jsx("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,zIndex:9998,background:"transparent"},onMouseDown:b=>{b.target===b.currentTarget&&W()},children:e.jsxs("div",{className:`tp-link-popover${T?" is-above":""}`,style:g,onMouseDown:b=>b.stopPropagation(),onKeyDown:b=>{b.key==="Enter"?(b.preventDefault(),y()):b.key==="Escape"&&(b.preventDefault(),W())},children:[e.jsx("div",{className:"tp-popover-arrow"}),e.jsxs("div",{className:"tp-popover-content",children:[e.jsx("div",{className:"tp-popover-header",children:e.jsx("span",{className:"tp-popover-title",children:m(l?"link.editLink":"link.insertLink")})}),e.jsxs("div",{className:"tp-popover-body",children:[e.jsx("label",{className:"tp-popover-label",children:m("link.url")}),e.jsxs("div",{className:"tp-popover-input-row",children:[e.jsx("input",{ref:S,type:"url",className:`tp-popover-input${s?" is-error":""}`,value:v,placeholder:m("link.url"),onChange:b=>C(b.target.value),onKeyDown:b=>{b.key==="Enter"?(b.preventDefault(),y()):b.key==="Escape"&&(b.preventDefault(),W())}}),e.jsx("button",{className:"tp-popover-btn-confirm",onClick:y,children:m("common.confirm")}),l&&e.jsx("button",{className:"tp-popover-btn-unlink",onClick:H,children:m("link.unlink")})]}),s&&e.jsx("div",{className:"tp-link-error-message",children:s})]})]})]})}):null},ot="#b4d5fe",rt=({def:n,editor:o,active:c,disabled:f,onCustomClick:a})=>{const{t:l}=ue(),[h,u]=t.useState(!1),p=t.useRef(null),m=t.useRef(null),v=t.useRef(""),C=t.useRef(!1),T=s=>{var r;if(s.preventDefault(),n.name==="link"){const{from:k,to:g}=o.state.selection;if(k!==g||o.isActive("link")){if(p.current={from:k,to:g},o.isActive("link")){const i=o.state.selection.$head.marks().find(y=>y.type.name==="link");v.current=((r=i==null?void 0:i.attrs)==null?void 0:r.href)||"",C.current=!0}else v.current="",C.current=!1;if(!o.isActive("link")){const i=window.getSelection();if(i&&i.rangeCount>0){const H=i.getRangeAt(0).getBoundingClientRect();H.width>0&&H.height>0&&(m.current=H)}}}}},x=()=>{var r,k;const s=n.name;if(s==="getHTML"||s==="getJSON"||s==="importWord"||s==="importMarkdown"||s==="exportWord"||s==="exportMarkdown"||s==="snapshot"||s==="compare"||s==="fullscreen"||s==="autoFormat"){a==null||a(s);return}if(s==="link"){if(o.isActive("link")){if(!p.current){const{from:i,to:y}=o.state.selection;p.current={from:i,to:y}}const g=o.state.selection.$head.marks().find(i=>i.type.name==="link");if(v.current=((r=g==null?void 0:g.attrs)==null?void 0:r.href)||"",C.current=!0,!m.current&&p.current)try{const{from:i,to:y}=p.current,H=o.view.coordsAtPos(i),W=o.view.coordsAtPos(y);H&&W&&(m.current=new DOMRect(H.left,H.top,W.left-H.left,W.bottom-H.top))}catch{}u(!0);return}if(!p.current){const{from:g,to:i}=o.state.selection;if(g===i)return;p.current={from:g,to:i}}if(v.current="",C.current=!1,!m.current&&p.current)try{const{from:g,to:i}=p.current,y=o.view.coordsAtPos(g),H=o.view.coordsAtPos(i);y&&H&&(m.current=new DOMRect(y.left,y.top,H.left-y.left,y.bottom-y.top))}catch{}if(p.current){const{from:g,to:i}=p.current;o.chain().focus().setTextSelection({from:g,to:i}).setHighlight({color:ot}).run()}u(!0);return}(k=n.command)==null||k.call(n,o)},S=s=>{if(p.current){const{from:r,to:k}=p.current,g=o.chain().focus().setTextSelection({from:r,to:k}).unsetHighlight();s?g.setLink({href:s}).run():g.unsetLink().run()}p.current=null,m.current=null,v.current="",C.current=!1},w=()=>{if(p.current){const{from:s,to:r}=p.current;o.chain().focus().setTextSelection({from:s,to:r}).unsetHighlight().run()}p.current=null,m.current=null,v.current="",C.current=!1},N=n.name==="getHTML"||n.name==="getJSON";return e.jsxs(e.Fragment,{children:[e.jsx("button",{className:`tp-toolbar-btn${c?" is-active":""}${N?" is-text-btn":""}`,disabled:f,title:l(n.titleKey),onMouseDown:T,onClick:x,children:n.name==="getHTML"?e.jsx("span",{className:"tp-toolbar-text",children:"HTML"}):n.name==="getJSON"?e.jsx("span",{className:"tp-toolbar-text",children:"JSON"}):e.jsx("span",{className:"tp-toolbar-icon",dangerouslySetInnerHTML:{__html:ve(n.name)}})}),e.jsx(st,{visible:h,targetRect:m.current,editor:o,savedSelection:p.current,initialUrl:v.current,isEditing:C.current,onConfirm:S,onCancel:w,onClose:()=>u(!1)})]})},Ue={SimSun:["SimSun","宋体"],宋体:["SimSun","宋体"],"Microsoft YaHei":["Microsoft YaHei","微软雅黑"],微软雅黑:["Microsoft YaHei","微软雅黑"],SimHei:["SimHei","黑体"],黑体:["SimHei","黑体"],KaiTi:["KaiTi","楷体"],楷体:["KaiTi","楷体"]},lt=({def:n,editor:o,active:c,disabled:f,onCustomClick:a})=>{var N;const{t:l}=ue(),[h,u]=t.useState(!1),[p,m]=t.useState(0),v=t.useRef(null),C=t.useMemo(()=>{var s;return(s=n.getCurrentValue)==null?void 0:s.call(n,o)},[p,n,o]),T=s=>{const r=String(C),k=String(s);if(n.name==="fontFamily"){const g=Ue[r],i=Ue[k];if(g)return g.includes(k);if(i)return i.includes(r)}return r===k},x=s=>{const r=Number(s);return r===0?"tp-heading-preview-paragraph":r>=1&&r<=6?`tp-heading-preview-h${r}`:""},S=()=>{f||(u(!h),h||m(s=>s+1))},w=s=>{var r;n.isActionMenu?a==null||a(String(s)):(r=n.command)==null||r.call(n,o,s),u(!1)};return t.useEffect(()=>{const s=k=>{v.current&&!v.current.contains(k.target)&&u(!1)},r=()=>m(k=>k+1);return document.addEventListener("pointerdown",s),o.on("transaction",r),()=>{document.removeEventListener("pointerdown",s),o.off("transaction",r)}},[o]),e.jsxs("div",{ref:v,className:"tp-toolbar-dropdown",children:[e.jsxs("button",{className:`tp-toolbar-dropdown-trigger${c?" is-active":""}${f?" is-disabled":""}`,title:l(n.tooltipKey||n.titleKey),disabled:f,onMouseDown:s=>s.preventDefault(),onClick:S,children:[e.jsx("span",{className:"tp-toolbar-icon",dangerouslySetInnerHTML:{__html:ve(n.name)}}),!n.hideLabel&&e.jsx("span",{className:"tp-toolbar-dropdown-label",children:l(n.titleKey)}),e.jsx("span",{className:"tp-toolbar-dropdown-arrow",children:"▾"})]}),h&&e.jsx("div",{className:"tp-toolbar-dropdown-menu",children:(N=n.options)==null?void 0:N.map(s=>e.jsx("button",{className:`tp-toolbar-dropdown-item${T(s.value)?" is-active":""}${n.name==="heading"?" "+x(s.value):""}`,onMouseDown:r=>r.preventDefault(),onClick:()=>w(s.value),children:s.labelKey?l(s.labelKey):s.label},String(s.value)))})]})},it=["#ffffff","#f3f3f3","#fce5cd","#c9daf8","#d0e0e3","#f4cccc","#d9ead3","#d9d2e9","#cfe2f3","#fff2cc","#efefef","#b7b7b7","#f6b26b","#6d9eeb","#a2c4c9","#ea9999","#b6d7a8","#b4a7d6","#9fc5e8","#ffe599","#d9d9d9","#999999","#e69138","#3c78d8","#76a5af","#e06666","#93c47d","#8e7cc3","#6fa8dc","#ffd966","#cccccc","#666666","#b45f06","#1155cc","#45818e","#cc0000","#6aa84f","#674ea7","#3d85c6","#f1c232","#b7b7b7","#434343","#783f04","#1c4587","#134f5c","#990000","#38761d","#351c75","#0b5394","#bf9000","#999999","#000000","#5b0f00","#073763","#0c343d","#660000","#274e13","#20124d","#073763","#7f6000"],at=["#ff0000","#ff5e00","#ff9900","#ffff00","#00ff00","#00a8a8","#00ffff","#0000ff","#5f00ff","#9900ff"],ct=({def:n,editor:o,disabled:c})=>{const{t:f}=ue(),[a,l]=t.useState(!1),h=t.useRef(null),[u,p]=t.useState(""),[m,v]=t.useState(""),C=n.name==="color",T=C?u:m,x=()=>{const N=o.getAttributes("textStyle");p((N==null?void 0:N.color)||"");const s=o.getAttributes("highlight");v((s==null?void 0:s.color)||"")};t.useEffect(()=>{const N=s=>{h.current&&!h.current.contains(s.target)&&l(!1)};return document.addEventListener("pointerdown",N),o.on("transaction",x),o.on("selectionUpdate",x),x(),()=>{document.removeEventListener("pointerdown",N),o.off("transaction",x),o.off("selectionUpdate",x)}},[o]);const S=N=>{var s;(s=n.command)==null||s.call(n,o,N),setTimeout(x,0),l(!1)},w=()=>{var N;(N=n.command)==null||N.call(n,o,void 0),v(""),l(!1)};return e.jsxs("div",{ref:h,className:"tp-toolbar-dropdown",children:[e.jsxs("button",{className:`tp-toolbar-dropdown-trigger${c?" is-disabled":""}`,title:f(n.titleKey),disabled:c,onMouseDown:N=>N.preventDefault(),onClick:()=>{c||l(!a)},children:[e.jsx("span",{className:C?"tp-color-picker-icon":"tp-bgcolor-picker-icon",children:C?e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("text",{x:"4",y:"17",fontSize:"24",fill:"currentColor",stroke:"none",fontFamily:"serif",fontWeight:"bold",children:"A"}),e.jsx("line",{x1:"4",y1:"22",x2:"20",y2:"22",strokeWidth:"5",stroke:u||"#000000"})]}):e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",fill:m||"transparent"}),e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("text",{x:"6",y:"17",fontSize:"16",fill:"currentColor",stroke:"none",fontFamily:"serif",fontWeight:"bold",children:"A"})]})}),e.jsx("span",{className:"tp-toolbar-dropdown-arrow",children:"▾"})]}),a&&e.jsxs("div",{className:"tp-color-picker-panel",children:[e.jsx("button",{className:"tp-color-default-btn",onMouseDown:N=>N.preventDefault(),onClick:w,children:f("common.default")}),e.jsx("div",{className:"tp-color-grid tp-theme-colors",children:it.map((N,s)=>e.jsx("button",{className:`tp-color-swatch${T===N?" tp-color-swatch-selected":""}`,style:{backgroundColor:N},title:N,onMouseDown:r=>r.preventDefault(),onClick:()=>S(N)},`theme-${s}`))}),e.jsx("div",{className:"tp-color-section-label",children:f("common.standardColor")}),e.jsx("div",{className:"tp-color-grid tp-standard-colors",children:at.map((N,s)=>e.jsx("button",{className:`tp-color-swatch${T===N?" tp-color-swatch-selected":""}`,style:{backgroundColor:N},title:N,onMouseDown:r=>r.preventDefault(),onClick:()=>S(N)},`std-${s}`))})]})]})},Ke=()=>e.jsx("div",{className:"tp-toolbar-separator"}),dt=({visible:n,editor:o,uploadUrl:c,uploadHeaders:f,onUpload:a,initialTab:l,onClose:h})=>{const{t:u}=ue(),[p,m]=t.useState(l||"upload"),[v,C]=t.useState(""),[T,x]=t.useState(!1),[S,w]=t.useState(!1),[N,s]=t.useState(0),[r,k]=t.useState(""),g=t.useRef(null);t.useEffect(()=>(n?(C(""),k(""),m(l||"upload"),s(0),document.body.style.overflow="hidden"):document.body.style.overflow="",()=>{document.body.style.overflow=""}),[n,l]);const i=b=>new Promise((D,E)=>{const $=new FileReader;$.onload=()=>D($.result),$.onerror=E,$.readAsDataURL(b)}),y=b=>{o.chain().focus().setImage({src:b}).run()},H=async b=>{w(!0),s(0),k("");try{let D;a?D=await a(b):c?D=await V.uploadFile(b,{url:c,headers:f,onProgress:s}):D=await i(b),y(D),h()}catch(D){k(D instanceof Error?D.message:u("imageUpload.uploadFailed"))}finally{w(!1),s(0)}},W=()=>{const b=v.trim();if(!b){k(u("imageUpload.urlRequired"));return}try{new URL(b)}catch{k(u("imageUpload.invalidUrl"));return}y(b),h()};return n?e.jsx("div",{className:"tp-image-upload-overlay",onMouseDown:b=>{b.target===b.currentTarget&&h()},children:e.jsxs("div",{className:"tp-image-upload-dialog",onMouseDown:b=>b.stopPropagation(),children:[e.jsxs("div",{className:"tp-dialog-header",children:[e.jsx("span",{className:"tp-dialog-title",children:u("image.upload")}),e.jsx("button",{className:"tp-dialog-close",onClick:h,children:"×"})]}),e.jsxs("div",{className:"tp-dialog-tabs",children:[e.jsx("button",{className:`tp-tab-btn${p==="upload"?" is-active":""}`,onClick:()=>m("upload"),children:u("imageUpload.uploadLocal")}),e.jsx("button",{className:`tp-tab-btn${p==="url"?" is-active":""}`,onClick:()=>m("url"),children:u("imageUpload.inputUrl")})]}),e.jsxs("div",{className:"tp-dialog-body",children:[p==="upload"&&e.jsxs("div",{className:"tp-upload-tab",children:[e.jsx("div",{className:`tp-dropzone${T?" is-dragging":""}${S?" is-uploading":""}`,onDragEnter:b=>{b.preventDefault(),x(!0)},onDragLeave:b=>{b.preventDefault(),x(!1)},onDragOver:b=>b.preventDefault(),onDrop:b=>{var E,$;b.preventDefault(),x(!1);const D=($=(E=b.dataTransfer)==null?void 0:E.files)==null?void 0:$[0];D!=null&&D.type.startsWith("image/")?H(D):k(u("imageUpload.invalidType"))},onClick:()=>{var b;return(b=g.current)==null?void 0:b.click()},children:S?e.jsxs("div",{className:"tp-upload-progress",children:[e.jsx("div",{className:"tp-progress-bar",children:e.jsx("div",{className:"tp-progress-fill",style:{width:N+"%"}})}),e.jsxs("span",{className:"tp-progress-text",children:[u("imageUpload.uploading")," ",N,"%"]})]}):e.jsxs("div",{className:"tp-dropzone-content",children:[e.jsx("span",{className:"tp-dropzone-icon",children:"📁"}),e.jsx("span",{className:"tp-dropzone-text",children:u("imageUpload.selectFile")}),e.jsx("span",{className:"tp-dropzone-hint",children:u("imageUpload.dragHint")})]})}),e.jsx("input",{ref:g,type:"file",accept:"image/*",style:{display:"none"},onChange:b=>{var E;const D=(E=b.target.files)==null?void 0:E[0];D&&H(D),b.target.value=""}})]}),p==="url"&&e.jsxs("div",{className:"tp-url-tab",children:[e.jsx("label",{className:"tp-input-label",children:u("imageUpload.url")}),e.jsxs("div",{className:"tp-input-row",children:[e.jsx("input",{className:"tp-url-input",type:"url",value:v,placeholder:u("imageUpload.placeholder"),onChange:b=>C(b.target.value),onKeyDown:b=>{b.key==="Enter"&&W(),b.key==="Escape"&&h()}}),e.jsx("button",{className:"tp-confirm-btn",onClick:W,children:u("common.confirm")})]})]}),r&&e.jsx("div",{className:"tp-error-message",children:r})]})]})}):null},ut=({def:n,editor:o,manager:c,active:f,disabled:a})=>{var s,r,k,g;const{t:l}=ue(),[h,u]=t.useState(!1),[p,m]=t.useState(!1),[v,C]=t.useState("upload"),T=t.useRef(null),x=(s=c==null?void 0:c.getConfig().upload)==null?void 0:s.url,S=(r=c==null?void 0:c.getConfig().upload)==null?void 0:r.headers,w=(k=c==null?void 0:c.getConfig().upload)==null?void 0:k.onUpload;t.useEffect(()=>{const i=y=>{T.current&&!T.current.contains(y.target)&&u(!1)};return document.addEventListener("pointerdown",i),()=>document.removeEventListener("pointerdown",i)},[]);const N=i=>{u(!1),i==="upload"?(C("upload"),m(!0)):i==="url"&&(C("url"),m(!0))};return e.jsxs("div",{ref:T,className:"tp-toolbar-dropdown",children:[e.jsxs("button",{className:`tp-toolbar-dropdown-trigger${f?" is-active":""}${a?" is-disabled":""}`,title:l(n.titleKey),disabled:a,onMouseDown:i=>i.preventDefault(),onClick:()=>{a||u(!h)},children:[e.jsx("span",{className:"tp-toolbar-icon",dangerouslySetInnerHTML:{__html:ve(n.name)}}),e.jsx("span",{className:"tp-toolbar-dropdown-arrow",children:"▾"})]}),h&&e.jsx("div",{className:"tp-toolbar-dropdown-menu",children:(g=n.options)==null?void 0:g.map(i=>e.jsx("button",{className:"tp-toolbar-dropdown-item",onMouseDown:y=>y.preventDefault(),onClick:()=>N(i.value),children:i.labelKey?l(i.labelKey):i.label},String(i.value)))}),e.jsx(dt,{visible:p,editor:o,uploadUrl:x,uploadHeaders:S,onUpload:w,initialTab:v,onClose:()=>m(!1)})]})},pt=({visible:n,editor:o,onSuccess:c,onCancel:f,onClose:a})=>{const{t:l}=ue(),[h,u]=t.useState(""),[p,m]=t.useState(""),v=t.useRef(null);t.useEffect(()=>(n?(u(""),m(""),document.body.style.overflow="hidden",setTimeout(()=>{var w;return(w=v.current)==null?void 0:w.focus()},100)):document.body.style.overflow="",()=>{document.body.style.overflow=""}),[n]);const C=t.useCallback(()=>{const w=h.trim();if(!w){m(l("video.urlRequired"));return}try{new URL(w)}catch{m(l("video.invalidUrl"));return}o.chain().focus().setVideo({src:w}).run(),c==null||c(w),a()},[h,o,l,c,a]),T=t.useCallback(()=>{f==null||f(),a()},[f,a]),x=t.useCallback(w=>{w.target===w.currentTarget&&T()},[T]),S=t.useCallback(w=>{w.key==="Enter"?(w.preventDefault(),C()):w.key==="Escape"&&(w.preventDefault(),T())},[C,T]);return n?Te.createPortal(e.jsx("div",{className:"tp-video-dialog-overlay",onMouseDown:x,children:e.jsxs("div",{className:"tp-video-dialog",onMouseDown:w=>w.stopPropagation(),onKeyDown:S,children:[e.jsxs("div",{className:"tp-dialog-header",children:[e.jsx("span",{className:"tp-dialog-title",children:l("video.title")}),e.jsx("button",{className:"tp-dialog-close",onClick:T,children:"×"})]}),e.jsxs("div",{className:"tp-dialog-body",children:[e.jsx("label",{className:"tp-input-label",children:l("video.url")}),e.jsxs("div",{className:"tp-input-row",children:[e.jsx("input",{ref:v,type:"url",className:"tp-url-input",placeholder:l("video.placeholder"),value:h,onChange:w=>u(w.target.value),onKeyDown:S}),e.jsx("button",{className:"tp-confirm-btn",onClick:C,children:l("common.confirm")})]}),e.jsx("p",{className:"tp-hint",children:l("video.hint")}),p&&e.jsx("div",{className:"tp-error-message",children:p})]})]})}),document.body):null},ft=({def:n,editor:o,active:c,disabled:f})=>{const{t:a}=ue(),[l,h]=t.useState(!1),u=()=>{f||h(!0)};return e.jsxs("div",{className:"tp-toolbar-video-btn",children:[e.jsx("button",{className:`tp-toolbar-btn${c?" is-active":""}${f?" is-disabled":""}`,title:a(n.titleKey),disabled:f,onMouseDown:p=>p.preventDefault(),onClick:u,children:e.jsx("span",{className:"tp-toolbar-icon",dangerouslySetInnerHTML:{__html:ve(n.name)}})}),e.jsx(pt,{visible:l,editor:o,onSuccess:()=>{},onClose:()=>h(!1)})]})},ht=10,mt=10,xt=({def:n,editor:o,active:c,disabled:f})=>{const{t:a}=ue(),[l,h]=t.useState(!1),[u,p]=t.useState({row:0,col:0}),m=t.useRef(null),v=()=>{f||(h(!l),p({row:0,col:0}))},C=(x,S)=>{p({row:x,col:S})},T=(x,S)=>{o.chain().focus().insertTable({rows:x,cols:S,withHeaderRow:!0}).run(),h(!1),p({row:0,col:0})};return t.useEffect(()=>{const x=S=>{m.current&&!m.current.contains(S.target)&&(h(!1),p({row:0,col:0}))};return document.addEventListener("pointerdown",x),()=>document.removeEventListener("pointerdown",x)},[]),e.jsxs("div",{ref:m,className:"tp-toolbar-dropdown",children:[e.jsxs("button",{className:`tp-toolbar-dropdown-trigger${c?" is-active":""}${f?" is-disabled":""}`,title:a(n.titleKey),disabled:f,onMouseDown:x=>x.preventDefault(),onClick:v,children:[e.jsx("span",{className:"tp-toolbar-icon",dangerouslySetInnerHTML:{__html:ve(n.name)}}),e.jsx("span",{className:"tp-toolbar-dropdown-arrow",children:"▾"})]}),l&&e.jsxs("div",{className:"tp-table-grid-dropdown",children:[e.jsx("div",{className:"tp-table-grid-header",children:u.row>0?`${u.row} × ${u.col}`:a("table.insertHint")}),e.jsx("div",{className:"tp-table-grid",children:Array.from({length:ht},(x,S)=>e.jsx("div",{className:"tp-table-grid-row",children:Array.from({length:mt},(w,N)=>{const s=S+1,r=N+1;return e.jsx("div",{className:`tp-table-grid-cell${s<=u.row&&r<=u.col?" is-hovered":""}${s===u.row&&r===u.col?" is-selected":""}`,onMouseEnter:()=>C(s,r),onClick:()=>T(s,r)},`${s}-${r}`)})},S))})]})]})},gt=({editor:n,disabled:o=!1})=>{const{t:c}=ue(),f=t.useRef("none"),[a,l]=t.useState("none"),h=t.useRef([]),u=t.useRef(null),p=t.useRef(null),m=t.useRef(null),v=t.useRef(void 0),C=t.useRef(null),T=t.useRef(0),x=t.useRef(!1),S=a!=="none",w=t.useCallback(()=>{const{from:D,to:E}=n.state.selection;if(n.isActive("orderedList"))return"orderedList";if(n.isActive("bulletList"))return"bulletList";const $=Math.min(D+1,E),J=n.state.doc.resolve($);if(J.parent.type.name==="listItem")for(let P=J.depth;P>0;P--){const B=J.node(P);if(B.type.name==="orderedList")return"orderedList";if(B.type.name==="bulletList")return"bulletList"}return null},[n]),N=t.useCallback(()=>{const{from:D,to:E}=n.state.selection;if(n.isActive("orderedList")||n.isActive("bulletList"))return;for(let P=1;P<=6;P++)if(n.isActive("heading",{level:P}))return P;const $=Math.min(D+1,E);if(n.state.doc.resolve($).parent.type.name==="paragraph")return null},[n]),s=t.useCallback(()=>{const{from:D,to:E,empty:$}=n.state.selection;if($)return!1;const I=n.state.doc.resolve(Math.min(D+1,E)).marks();h.current=[...I];const P=w();u.current=P;const B=n.getAttributes("textStyle");p.current={color:B.color,fontFamily:B.fontFamily,fontSize:B.fontSize};const A=n.getAttributes("paragraph"),_=n.getAttributes("heading");m.current={textAlign:A.textAlign||_.textAlign,lineHeight:A.lineHeight||_.lineHeight},v.current=N();const O=I.length>0,K=!!B.color||!!B.fontFamily||!!B.fontSize,X=!!m.current.textAlign||!!m.current.lineHeight;return O||K||X||P!==null||v.current!==void 0},[n,w,N]),r=t.useCallback(()=>{if(!u.current)return;const D=n.chain().focus();switch(u.current){case"orderedList":n.isActive("orderedList")||(n.isActive("bulletList")&&D.toggleBulletList(),D.toggleOrderedList().run());break;case"bulletList":n.isActive("bulletList")||(n.isActive("orderedList")&&D.toggleOrderedList(),D.toggleBulletList().run());break}},[n]),k=t.useCallback(()=>{if(v.current===void 0)return;const D=n.chain().focus();if(v.current===null)D.setParagraph().run();else{const{schema:E}=n.state;E.nodes.heading&&D.setNode("heading",{level:v.current}).run()}},[n]),g=t.useCallback(()=>{let{state:D}=n,{from:E,to:$,empty:J}=D.selection;if(J)return!1;const{schema:I}=D;if(u.current?r():v.current!==void 0&&k(),m.current){const O=n.chain().focus();m.current.textAlign&&O.setTextAlign(m.current.textAlign),m.current.lineHeight&&O.setLineHeight(m.current.lineHeight),O.run()}D=n.state;const P=D.selection;if(E=P.from,$=P.to,h.current.length===0&&!p.current)return u.current!==null||m.current!==null||v.current!==void 0;const B=D.tr,A=[];if(h.current.forEach(O=>{const K=O.type.name;["bold","italic","underline","strike","superscript","subscript"].includes(K)&&A.push(O)}),p.current){const{color:O,fontFamily:K,fontSize:X}=p.current,Z={};if(O&&(Z.color=O),K&&(Z.fontFamily=K),X&&(Z.fontSize=X),Object.keys(Z).length>0&&I.marks.textStyle){const me=I.marks.textStyle.create(Z);A.push(me)}}const _=h.current.find(O=>O.type.name==="highlight");return _&&A.push(_),A.length===0||(D.doc.nodesBetween(E,$,(O,K)=>{if(O.isText&&K<$&&K+O.nodeSize>E){const X=Math.max(K,E),Z=Math.min(K+O.nodeSize,$);["bold","italic","underline","strike","superscript","subscript","textStyle","highlight"].forEach(Q=>{const ae=I.marks[Q];ae&&O.marks.some(le=>le.type===ae)&&B.removeMark(X,Z,ae)}),A.forEach(Q=>{B.addMark(X,Z,Q)})}}),B.docChanged&&n.view.dispatch(B)),!0},[n,r,k]),i=t.useCallback(()=>{f.current="none",l("none"),h.current=[],u.current=null,p.current=null,m.current=null,v.current=void 0},[]),y=t.useCallback(()=>{if(f.current==="none")return;const{empty:D}=n.state.selection;D||(g(),f.current==="single"&&i())},[n,g,i]),H=t.useCallback(()=>{if(f.current==="single"||f.current==="multiple"){i();return}s()&&(f.current="single",l("single"))},[s,i]),W=t.useCallback(()=>{if(f.current==="multiple"){i();return}s()&&(f.current="multiple",l("multiple"))},[s,i]),b=t.useCallback(()=>{o||(T.current++,T.current===1?C.current=window.setTimeout(()=>{H(),T.current=0,C.current=null},250):T.current===2&&(C.current&&(clearTimeout(C.current),C.current=null),W(),T.current=0))},[H,W]);return t.useEffect(()=>{o&&(i(),C.current&&(clearTimeout(C.current),C.current=null),T.current=0)},[o,i]),t.useEffect(()=>{const D=I=>{f.current==="none"||I.target.closest(".tp-toolbar-btn")||(x.current=!0)},E=I=>{!x.current||(x.current=!1,f.current==="none")||I.target.closest(".tp-toolbar-btn")||requestAnimationFrame(()=>y())},$=I=>{I.key==="Escape"&&f.current!=="none"&&i()},J=I=>{if(f.current==="none")return;const P=["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"];I.shiftKey&&P.includes(I.key)&&y()};return document.addEventListener("mousedown",D),document.addEventListener("mouseup",E),document.addEventListener("keydown",$),document.addEventListener("keyup",J),()=>{document.removeEventListener("mousedown",D),document.removeEventListener("mouseup",E),document.removeEventListener("keydown",$),document.removeEventListener("keyup",J),C.current&&clearTimeout(C.current)}},[y,i]),e.jsxs("button",{className:`tp-toolbar-btn${S?" is-active":""}${a==="multiple"?" is-locked":""}${o?" is-disabled":""}`,disabled:o,title:c("toolbar.formatPainter"),onClick:b,style:{position:"relative"},children:[e.jsx("span",{className:"tp-toolbar-icon",dangerouslySetInnerHTML:{__html:ve("formatPainter")}}),a==="multiple"&&e.jsx("span",{className:"tp-format-painter-indicator",children:"🔒"})]})},wt=[{type:"decimal",lines:["1.","2.","3."]},{type:"decimal-leading-zero",lines:["01.","02.","03."]},{type:"lower-roman",lines:["i.","ii.","iii."]},{type:"upper-roman",lines:["I.","II.","III."]},{type:"lower-alpha",lines:["a.","b.","c."]},{type:"upper-alpha",lines:["A.","B.","C."]}],vt=({def:n,editor:o,active:c,disabled:f})=>{const{t:a}=ue(),[l,h]=t.useState(!1),[u,p]=t.useState(0),m=t.useRef(null),v=()=>{const{state:g}=o,i=g.selection.$from;let y=null,H=0;for(let W=i.depth;W>=0;W--){const b=i.node(W);b.type.name==="orderedList"&&(y||(y=b),H++)}return{node:y,depth:H}},C=(()=>{const{node:g,depth:i}=v();return g&&g.attrs.listStyleType?g.attrs.listStyleType:i<=1?"decimal":i===2?"lower-alpha":"lower-roman"})(),T=(()=>{const{node:g}=v(),i=g==null?void 0:g.attrs.start;return i!=null?Number(i):1})(),x=(()=>{const{node:g}=v();return!!(g!=null&&g.attrs.reversed)})(),S=t.useCallback(()=>{var g;(g=n.command)==null||g.call(n,o)},[n,o]),w=t.useCallback(()=>{f||h(g=>!g)},[f]),N=t.useCallback(g=>{o.commands.createStyledOrderedList({listStyleType:g}),o.commands.focus(),h(!1)},[o]),s=t.useCallback(g=>{const i=parseInt(g.target.value,10);isNaN(i)||o.commands.setOrderedListAttrs({start:i})},[o]),r=t.useCallback(g=>{["Backspace","Delete","ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Tab","Home","End"].includes(g.key)||g.key==="-"||g.key==="Minus"||g.key>="0"&&g.key<="9"||g.ctrlKey||g.metaKey||g.preventDefault()},[]),k=t.useCallback(()=>{const g=!x;o.commands.setOrderedListAttrs({reversed:g||null})},[o,x]);return t.useEffect(()=>{const g=y=>{m.current&&!m.current.contains(y.target)&&h(!1)},i=()=>p(y=>y+1);return document.addEventListener("pointerdown",g),o.on("transaction",i),()=>{document.removeEventListener("pointerdown",g),o.off("transaction",i)}},[o]),e.jsxs("div",{ref:m,className:"tp-toolbar-split-btn",children:[e.jsx("button",{className:`tp-toolbar-split-main${c?" is-active":""}`,title:a(n.titleKey),disabled:f,onMouseDown:g=>g.preventDefault(),onClick:S,children:e.jsx("span",{className:"tp-toolbar-icon",dangerouslySetInnerHTML:{__html:ve(n.name)}})}),e.jsx("button",{className:`tp-toolbar-split-arrow${l?" is-open":""}`,disabled:f,onMouseDown:g=>g.preventDefault(),onClick:w,children:"▾"}),l&&e.jsxs("div",{className:"tp-ol-panel",children:[e.jsx("div",{className:"tp-ol-style-grid",children:wt.map(g=>e.jsx("button",{className:`tp-ol-style-item${C===g.type?" is-active":""}`,onMouseDown:i=>i.preventDefault(),onClick:()=>N(g.type),children:g.lines.map((i,y)=>e.jsxs("span",{className:"tp-ol-style-line",children:[e.jsx("span",{className:"tp-ol-style-marker",children:i}),e.jsx("span",{className:"tp-ol-style-bar"})]},y))},g.type))}),e.jsxs("div",{className:"tp-ol-properties",children:[e.jsx("div",{className:"tp-ol-prop-title",children:a("orderedList.properties")}),e.jsxs("div",{className:"tp-ol-prop-row",children:[e.jsx("label",{children:a("orderedList.startAt")}),e.jsx("input",{type:"number",className:"tp-ol-start-input",defaultValue:T,onChange:s,onKeyDown:r,onMouseDown:g=>g.stopPropagation()})]}),e.jsxs("div",{className:"tp-ol-prop-row",children:[e.jsx("label",{children:a("orderedList.reversed")}),e.jsx("button",{className:`tp-ol-toggle${x?" is-on":""}`,onMouseDown:g=>g.preventDefault(),onClick:k})]})]})]})]})},bt=[{type:"disc",marker:"●"},{type:"circle",marker:"○"},{type:"square",marker:"■"},{type:"none",marker:"—"}],yt=({def:n,editor:o,active:c,disabled:f})=>{const{t:a}=ue(),[l,h]=t.useState(!1),[u,p]=t.useState(0),m=t.useRef(null),v=(()=>{const{state:S}=o,w=S.selection.$from;let N=null,s=0;for(let r=w.depth;r>=0;r--){const k=w.node(r);k.type.name==="bulletList"&&(N||(N=k),s++)}return N&&N.attrs.listStyleType?N.attrs.listStyleType:s<=1?"disc":s===2?"circle":"square"})(),C=t.useCallback(()=>{var S;(S=n.command)==null||S.call(n,o)},[n,o]),T=t.useCallback(()=>{f||h(S=>!S)},[f]),x=t.useCallback(S=>{o.commands.createStyledBulletList({listStyleType:S}),o.commands.focus(),h(!1)},[o]);return t.useEffect(()=>{const S=N=>{m.current&&!m.current.contains(N.target)&&h(!1)},w=()=>p(N=>N+1);return document.addEventListener("pointerdown",S),o.on("transaction",w),()=>{document.removeEventListener("pointerdown",S),o.off("transaction",w)}},[o]),e.jsxs("div",{ref:m,className:"tp-toolbar-split-btn",children:[e.jsx("button",{className:`tp-toolbar-split-main${c?" is-active":""}`,title:a(n.titleKey),disabled:f,onMouseDown:S=>S.preventDefault(),onClick:C,children:e.jsx("span",{className:"tp-toolbar-icon",dangerouslySetInnerHTML:{__html:ve(n.name)}})}),e.jsx("button",{className:`tp-toolbar-split-arrow${l?" is-open":""}`,disabled:f,onMouseDown:S=>S.preventDefault(),onClick:T,children:"▾"}),l&&e.jsx("div",{className:"tp-ol-panel",children:e.jsx("div",{className:"tp-ol-style-grid tp-ul-style-grid",children:bt.map(S=>e.jsx("button",{className:`tp-ol-style-item${v===S.type?" is-active":""}`,onMouseDown:w=>w.preventDefault(),onClick:()=>x(S.type),children:[0,1,2].map(w=>e.jsxs("span",{className:"tp-ol-style-line",children:[e.jsx("span",{className:"tp-ul-style-marker",children:S.marker}),e.jsx("span",{className:"tp-ol-style-bar"})]},w))},S.type))})})]})};function ze(n){return n==="meta-left"?"tp-toolbar-capsule tp-toolbar-capsule-left":n==="meta-io"?"tp-toolbar-capsule tp-toolbar-capsule-io":n==="meta-view"?"tp-toolbar-capsule tp-toolbar-capsule-view":""}const kt=({items:n,manager:o,activeStates:c,disabledStates:f,viewMode:a="normal",onToggleViewMode:l,onToolbarClick:h,prepend:u,append:p})=>{const m=()=>o.getEditor(),v=t.useCallback(s=>{if(s==="getHTML"){l==null||l("html");return}if(s==="getJSON"){l==null||l("json");return}h==null||h(s)},[l,h]),C=s=>a!=="normal"?s==="getHTML"?a==="html":s==="getJSON"?a==="json":!1:s==="getHTML"||s==="getJSON"?!1:c[s]??!1,T=s=>a!=="normal"?s!=="getHTML"&&s!=="getJSON":f[s]??!1,x=t.useMemo(()=>V.groupToolbarItems(n),[n]),S=x.filter(s=>s.category==="meta-left"||s.category==="content"),w=x.filter(s=>s.category==="meta-io"||s.category==="meta-view");function N(s){const r=V.getToolbarItemDef(s);if(!r)return null;const k=m();return s==="imageUpload"?e.jsx(ut,{def:r,editor:k,manager:o,active:C(s),disabled:T(s)},s):s==="video"?e.jsx(ft,{def:r,editor:k,active:C(s),disabled:T(s)},s):s==="insertTable"?e.jsx(xt,{def:r,editor:k,active:C(s),disabled:T(s)},s):s==="formatPainter"?e.jsx(gt,{editor:k,disabled:T(s)},s):s==="orderedList"?e.jsx(vt,{def:r,editor:k,active:C(s),disabled:T(s)},s):s==="bulletList"?e.jsx(yt,{def:r,editor:k,active:C(s),disabled:T(s)},s):r.type==="button"?e.jsx(rt,{def:r,editor:k,active:C(s),disabled:T(s),onCustomClick:v},s):r.type==="dropdown"?e.jsx(lt,{def:r,editor:k,active:C(s),disabled:T(s),onCustomClick:v},s):r.type==="color-picker"?e.jsx(ct,{def:r,editor:k,disabled:T(s)},s):null}return e.jsxs("div",{className:"tp-toolbar",children:[u,S.map((s,r)=>e.jsxs(t.Fragment,{children:[r>0&&e.jsx(Ke,{}),s.category!=="content"?e.jsx("div",{className:ze(s.category),children:s.items.map(N)}):e.jsx(e.Fragment,{children:s.items.map(N)})]},`g-${r}`)),w.length>0&&e.jsx("div",{className:"tp-toolbar-right",children:w.map((s,r)=>e.jsxs(t.Fragment,{children:[r>0&&e.jsx(Ke,{}),e.jsx("div",{className:ze(s.category),children:s.items.map(N)})]},`r-${r}`))}),p]})},Ye=({editor:n,visible:o,position:c,targetCell:f,onVisibleChange:a,onAction:l})=>{const h=t.useRef(null),[u,p]=t.useState({x:0,y:0}),[m,v]=t.useState(!1),[C,T]=t.useState(!1),x=t.useRef({x:0,y:0}),S=V.I18nManager.getInstance(),w=r=>S.t(r),N=t.useCallback(r=>{if(!h.current)return r;const k=h.current.getBoundingClientRect();return k.width===0||k.height===0?r:V.adjustMenuPosition({x:r.x,y:r.y,width:k.width,height:k.height})},[]);t.useEffect(()=>{if(o){if(p({x:c.x,y:c.y}),f){const r=f.getBoundingClientRect();x.current={x:c.x-r.left,y:c.y-r.top}}v(n.can().mergeCells()),T(n.can().splitCell())}},[o,c,f,n]),t.useLayoutEffect(()=>{if(!o||!h.current)return;const r=h.current.getBoundingClientRect();if(r.width===0||r.height===0)return;const k=V.adjustMenuPosition({x:u.x,y:u.y,width:r.width,height:r.height});(k.x!==u.x||k.y!==u.y)&&p({x:k.x,y:k.y})},[o,u.x,u.y]),t.useEffect(()=>{const r=()=>{if(!o||!f)return;const g=f.getBoundingClientRect();if(g.bottom<0||g.top>window.innerHeight){a(!1);return}const i={x:g.left+x.current.x,y:g.top+x.current.y},y=N(i);p({x:y.x,y:y.y})},k=()=>{o&&r()};return window.addEventListener("scroll",k,!0),window.addEventListener("wheel",k,{passive:!0}),()=>{window.removeEventListener("scroll",k,!0),window.removeEventListener("wheel",k)}},[o,f,a,N]),t.useEffect(()=>{const r=g=>{h.current&&!h.current.contains(g.target)&&a(!1)},k=g=>{g.key==="Escape"&&a(!1)};return document.addEventListener("click",r),document.addEventListener("keydown",k),()=>{document.removeEventListener("click",r),document.removeEventListener("keydown",k)}},[a]);const s=t.useCallback(r=>{l(r),a(!1)},[l,a]);return o?Te.createPortal(e.jsxs("div",{ref:h,className:"tp-table-context-menu",style:{left:u.x,top:u.y},onClick:r=>r.stopPropagation(),children:[e.jsxs("div",{className:"tp-table-menu-section",children:[e.jsx("div",{className:"tp-table-menu-item",onClick:()=>s("addRowBefore"),children:w("table.addRowBefore")}),e.jsx("div",{className:"tp-table-menu-item",onClick:()=>s("addRowAfter"),children:w("table.addRowAfter")}),e.jsx("div",{className:"tp-table-menu-item",onClick:()=>s("addColumnBefore"),children:w("table.addColumnBefore")}),e.jsx("div",{className:"tp-table-menu-item",onClick:()=>s("addColumnAfter"),children:w("table.addColumnAfter")})]}),e.jsx("div",{className:"tp-table-menu-divider"}),e.jsxs("div",{className:"tp-table-menu-section",children:[e.jsx("div",{className:`tp-table-menu-item${m?"":" disabled"}`,onClick:()=>m&&s("mergeCells"),children:w("table.mergeCells")}),e.jsx("div",{className:`tp-table-menu-item${C?"":" disabled"}`,onClick:()=>C&&s("splitCell"),children:w("table.splitCell")})]}),e.jsx("div",{className:"tp-table-menu-divider"}),e.jsxs("div",{className:"tp-table-menu-section",children:[e.jsx("div",{className:"tp-table-menu-item",onClick:()=>s("deleteRow"),children:w("table.deleteRow")}),e.jsx("div",{className:"tp-table-menu-item",onClick:()=>s("deleteColumn"),children:w("table.deleteColumn")}),e.jsx("div",{className:"tp-table-menu-item tp-table-menu-item-danger",onClick:()=>s("deleteTable"),children:w("table.deleteTable")})]}),e.jsx("div",{className:"tp-table-menu-divider"}),e.jsxs("div",{className:"tp-table-menu-section",children:[e.jsx("div",{className:"tp-table-menu-item",onClick:()=>s("tableSettings"),children:w("table.tableSettings")}),e.jsx("div",{className:"tp-table-menu-item",onClick:()=>s("cellSettings"),children:w("table.cellSettings")})]})]}),document.body):null},jt=["#000000","#1a1a1a","#333333","#4d4d4d","#666666","#808080","#999999","#b3b3b3","#1c4587","#1155cc","#3d85c6","#6fa8dc","#0b5394","#073763","#38761d","#6aa84f","#93c47d","#274e13","#990000","#cc0000","#e06666","#660000"],Ct=["#ffffff","#f8f9fa","#f1f3f4","#e8eaed","#dadce0","#bdc1c6","#e6f4ea","#ceead6","#a8dab5","#81c995","#e8f0fe","#d2e3fc","#aecbfa","#8ab4f8","#fef7e0","#feefc3","#fde293","#fdd663","#fce8e6","#fadbd8","#f5aca6","#f28b82"];function Nt(n){const o=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(n);return o?{r:parseInt(o[1],16),g:parseInt(o[2],16),b:parseInt(o[3],16)}:null}function Fe(n,o,c){return"#"+[n,o,c].map(f=>{const a=Math.round(Math.max(0,Math.min(255,f))).toString(16);return a.length===1?"0"+a:a}).join("")}function Oe(n,o,c){n/=255,o/=255,c/=255;const f=Math.max(n,o,c),a=Math.min(n,o,c);let l=0,h=0;const u=(f+a)/2;if(f!==a){const p=f-a;switch(h=u>.5?p/(2-f-a):p/(f+a),f){case n:l=((o-c)/p+(o<c?6:0))/6;break;case o:l=((c-n)/p+2)/6;break;case c:l=((n-o)/p+4)/6;break}}return{h:Math.round(l*360),s:Math.round(h*100),l:Math.round(u*100)}}function We(n,o,c){n/=255,o/=255,c/=255;const f=Math.max(n,o,c),a=Math.min(n,o,c);let l=0;const h=f,u=f-a,p=f===0?0:u/f;if(f!==a)switch(f){case n:l=((o-c)/u+(o<c?6:0))/6;break;case o:l=((c-n)/u+2)/6;break;case c:l=((n-o)/u+4)/6;break}return{h:Math.round(l*360),s:Math.round(p*100),v:Math.round(h*100)}}function Mt(n,o,c){o/=100,c/=100;const f=Math.floor(n/60)%6,a=n/60-Math.floor(n/60),l=c*(1-o),h=c*(1-a*o),u=c*(1-(1-a)*o);let p=0,m=0,v=0;switch(f){case 0:p=c,m=u,v=l;break;case 1:p=h,m=c,v=l;break;case 2:p=l,m=c,v=u;break;case 3:p=l,m=h,v=c;break;case 4:p=u,m=l,v=c;break;case 5:p=c,m=l,v=h;break}return{r:Math.round(p*255),g:Math.round(m*255),b:Math.round(v*255)}}function St(n,o,c){n/=360,o/=100,c/=100;let f,a,l;if(o===0)f=a=l=c;else{const h=(m,v,C)=>(C<0&&(C+=1),C>1&&(C-=1),C<.16666666666666666?m+(v-m)*6*C:C<.5?v:C<.6666666666666666?m+(v-m)*(.6666666666666666-C)*6:m),u=c<.5?c*(1+o):c+o-c*o,p=2*c-u;f=h(p,u,n+1/3),a=h(p,u,n),l=h(p,u,n-1/3)}return{r:Math.round(f*255),g:Math.round(a*255),b:Math.round(l*255)}}const Ae=t.forwardRef(({value:n,onChange:o,placeholder:c,mode:f="border",beforeOpen:a,onClose:l},h)=>{const[u,p]=t.useState(!1),m=t.useRef(null),v=t.useRef(null),C=t.useRef(null),T=t.useRef(null),x=t.useRef(null),[S,w]=t.useState(-1e4),[N,s]=t.useState(-1e4),[r,k]=t.useState(n),[g,i]=t.useState(n),y=t.useRef(n),[H,W]=t.useState("hex"),[b,D]=t.useState({h:0,s:100,v:100}),[E,$]=t.useState({r:0,g:0,b:0}),[J,I]=t.useState({h:0,s:0,l:0}),[P,B]=t.useState(!1),[A,_]=t.useState(!1),[O,K]=t.useState(!1),X=t.useCallback(()=>{let M=0;const R=3,Y=()=>{if(M>=R*2){K(!1);return}K(re=>!re),M++,setTimeout(Y,100)};Y()},[]);t.useImperativeHandle(h,()=>({triggerButtonFlash:X}));const Z=t.useMemo(()=>f==="background"?Ct:jt,[f]),me=g||"#d9d9d9",Q=t.useCallback(M=>{k(M),i(M);const R=Nt(M);R&&($(R),I(Oe(R.r,R.g,R.b)),D(We(R.r,R.g,R.b)))},[]),ae=t.useCallback(()=>{const M=Mt(b.h,b.s,b.v),R=Fe(M.r,M.g,M.b);$(M),I(Oe(M.r,M.g,M.b)),k(R),i(R)},[b]);t.useEffect(()=>{Q(n)},[n,Q]),t.useEffect(()=>{ae()},[b,ae]);const le=t.useCallback(M=>{let R=M.parentElement;for(;R;){const Y=window.getComputedStyle(R);if(Y.overflowY==="auto"||Y.overflowY==="scroll")return R;R=R.parentElement}return null},[]),z=t.useCallback(()=>{if(!u||!v.current||!C.current||!m.current)return;const M=v.current,R=C.current,Y=m.current,re=M.getBoundingClientRect(),ie=R.getBoundingClientRect(),Ee=Y.getBoundingClientRect();if(Ee.width===0&&Ee.height===0){requestAnimationFrame(z);return}const Ne=window.innerWidth,Me=window.innerHeight,se=8,$e=10,Be=$e/2,Se=re.width||260,ge=re.height||348;M.style.maxHeight="",M.style.overflowY="";let Le=ie.top,ke,j="right";if(ie.right+se+Se<=Ne-se)ke=ie.right+se,j="right";else if(ie.left-Se-se>=se)ke=ie.left-Se-se,j="left";else{const de=Ne-ie.right-se,ce=ie.left-se;de>=ce?(ke=Math.max(se,Ne-Se-se),j="right"):(ke=se,j="left")}Le+ge>Me-se&&(Le=Math.max(se,Me-ge-se)),w(Le),s(ke),M.dataset.placement=j;let F=ie.top+ie.height/2-Le-Be;const ne=se,te=Math.max(ne,ge-$e-se);F=Math.max(ne,Math.min(te,F)),M.style.setProperty("--triangle-top",`${F}px`)},[u]);t.useEffect(()=>{if(!u)return;const M=requestAnimationFrame(z),R=v.current,Y=R?le(R):null,re=()=>requestAnimationFrame(z);return Y&&Y.addEventListener("scroll",re,!0),()=>{cancelAnimationFrame(M),Y&&Y.removeEventListener("scroll",re,!0)}},[u,z,le]),t.useEffect(()=>{u&&requestAnimationFrame(z)},[H,u,z]);const ee=t.useCallback(()=>{if(u)l==null||l();else{if(a&&a()===!1)return;y.current=n,i(n),Q(n)}p(!u)},[u,n,Q,a,l]),U=t.useCallback(M=>{Q(M)},[Q]),q=t.useCallback(M=>{const R=M.target.value;k(R),(/^#[0-9A-Fa-f]{6}$/.test(R)||/^#[0-9A-Fa-f]{3}$/.test(R))&&Q(R)},[Q]),fe=t.useCallback(()=>{r!==g&&(/^#[0-9A-Fa-f]{6}$/.test(r)||/^#[0-9A-Fa-f]{3}$/.test(r)?Q(r):(k(g),Q(g)))},[r,g,Q]),De=t.useCallback(()=>{const M=Fe(E.r,E.g,E.b);k(M),i(M),I(Oe(E.r,E.g,E.b)),D(We(E.r,E.g,E.b))},[E]),xe=t.useCallback(()=>{const M=St(J.h,J.s,J.l),R=Fe(M.r,M.g,M.b);k(R),i(R),$(M),D(We(M.r,M.g,M.b))},[J]),be=t.useCallback(M=>{if(!T.current)return;const R=T.current.getBoundingClientRect();let Y=Math.max(0,Math.min(100,(M.clientX-R.left)/R.width*100)),re=Math.max(0,Math.min(100,(M.clientY-R.top)/R.height*100));D(ie=>({...ie,s:Y,v:100-re}))},[]),Ce=t.useCallback(M=>{B(!0),be(M.nativeEvent)},[be]),ye=t.useCallback(M=>{if(!x.current)return;const R=x.current.getBoundingClientRect();let Y=Math.max(0,Math.min(360,(M.clientX-R.left)/R.width*360));D(re=>({...re,h:Y}))},[]),Re=t.useCallback(M=>{_(!0),ye(M.nativeEvent)},[ye]);t.useEffect(()=>{const M=Y=>{P&&be(Y),A&&ye(Y)},R=()=>{B(!1),_(!1)};return document.addEventListener("mousemove",M),document.addEventListener("mouseup",R),()=>{document.removeEventListener("mousemove",M),document.removeEventListener("mouseup",R)}},[P,A,be,ye]),t.useEffect(()=>{const M=Y=>{if(m.current&&!m.current.contains(Y.target)&&u){const re=Y.target,ie=re.closest?re.closest(".tp-color-picker-input"):null;if(ie&&ie!==m.current)return;Y.stopPropagation(),Y.preventDefault(),X()}},R=()=>{u&&requestAnimationFrame(z)};return document.addEventListener("pointerdown",M,!0),window.addEventListener("resize",R),window.addEventListener("scroll",R,!0),()=>{document.removeEventListener("pointerdown",M,!0),window.removeEventListener("resize",R),window.removeEventListener("scroll",R,!0)}},[u,z]);const Ie=t.useCallback(()=>{o(g),p(!1),l==null||l()},[g,o,l]),d=t.useCallback(()=>{i(y.current),Q(y.current),p(!1),l==null||l()},[Q,l]),G=t.useCallback(M=>{M.stopPropagation()},[]);return e.jsxs("div",{ref:m,className:`tp-color-picker-input${u?" tp-color-picker-input-open":""}`,onClick:G,children:[e.jsx("button",{ref:C,type:"button",className:"tp-color-preview",style:{backgroundColor:me},onMouseDown:M=>M.preventDefault(),onClick:ee}),e.jsx("input",{value:r,type:"text",className:"tp-color-text-input",placeholder:c||"#d9d9d9",onChange:q,onBlur:fe,onMouseDown:G,onClick:G}),u&&e.jsxs("div",{ref:v,className:"tp-color-panel",style:{position:"fixed",top:`${S}px`,left:`${N}px`},onClick:G,children:[e.jsx("div",{ref:T,className:"tp-sv-area",style:{background:`linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, transparent), hsl(${b.h}, 100%, 50%)`},onMouseDown:Ce,children:e.jsx("div",{className:"tp-sv-indicator",style:{left:`${b.s}%`,top:`${100-b.v}%`}})}),e.jsx("div",{ref:x,className:"tp-hue-bar",onMouseDown:Re,children:e.jsx("div",{className:"tp-hue-indicator",style:{left:`${b.h/360*100}%`}})}),e.jsx("div",{className:"tp-color-section-label",children:"常用颜色"}),e.jsx("div",{className:"tp-color-grid tp-common-colors",children:Z.map(M=>e.jsx("button",{type:"button",className:`tp-color-swatch${n===M?" tp-color-swatch-selected":""}`,style:{backgroundColor:M},title:M,onMouseDown:R=>R.preventDefault(),onClick:()=>U(M)},M))}),e.jsx("div",{className:"tp-input-mode-tabs",children:["hex","rgb","hsl"].map(M=>e.jsx("button",{type:"button",className:`tp-mode-tab${H===M?" active":""}`,onClick:()=>W(M),children:M.toUpperCase()},M))}),H==="hex"&&e.jsxs("div",{className:"tp-color-input-row",children:[e.jsx("label",{children:"HEX"}),e.jsx("input",{value:r,type:"text",className:"tp-color-input-field",placeholder:"#000000",onChange:q,onBlur:fe,onMouseDown:G,onClick:G})]}),H==="rgb"&&e.jsxs("div",{className:"tp-color-input-row tp-rgb-inline-row",children:[e.jsx("label",{children:"R"}),e.jsx("input",{type:"number",min:0,max:255,className:"tp-color-input-field",value:E.r,onChange:M=>{$(R=>({...R,r:Number(M.target.value)})),setTimeout(De,0)},onMouseDown:G,onClick:G}),e.jsx("label",{children:"G"}),e.jsx("input",{type:"number",min:0,max:255,className:"tp-color-input-field",value:E.g,onChange:M=>{$(R=>({...R,g:Number(M.target.value)})),setTimeout(De,0)},onMouseDown:G,onClick:G}),e.jsx("label",{children:"B"}),e.jsx("input",{type:"number",min:0,max:255,className:"tp-color-input-field",value:E.b,onChange:M=>{$(R=>({...R,b:Number(M.target.value)})),setTimeout(De,0)},onMouseDown:G,onClick:G})]}),H==="hsl"&&e.jsxs("div",{className:"tp-color-input-row tp-hsl-inline-row",children:[e.jsx("label",{children:"H"}),e.jsx("input",{type:"number",min:0,max:360,className:"tp-color-input-field",value:J.h,onChange:M=>{I(R=>({...R,h:Number(M.target.value)})),setTimeout(xe,0)},onMouseDown:G,onClick:G}),e.jsx("span",{className:"tp-input-unit",children:"°"}),e.jsx("label",{children:"S"}),e.jsx("input",{type:"number",min:0,max:100,className:"tp-color-input-field",value:J.s,onChange:M=>{I(R=>({...R,s:Number(M.target.value)})),setTimeout(xe,0)},onMouseDown:G,onClick:G}),e.jsx("span",{className:"tp-input-unit",children:"%"}),e.jsx("label",{children:"L"}),e.jsx("input",{type:"number",min:0,max:100,className:"tp-color-input-field",value:J.l,onChange:M=>{I(R=>({...R,l:Number(M.target.value)})),setTimeout(xe,0)},onMouseDown:G,onClick:G}),e.jsx("span",{className:"tp-input-unit",children:"%"})]}),e.jsxs("div",{className:"tp-color-footer-row",children:[e.jsx("div",{className:"tp-color-preview-label",children:"当前颜色"}),e.jsx("div",{className:"tp-color-preview-box",style:{backgroundColor:me}}),e.jsxs("div",{className:"tp-color-actions",children:[e.jsx("button",{type:"button",className:`tp-color-btn tp-color-btn-cancel${O?" tp-color-btn-flash":""}`,title:"取消",onMouseDown:M=>M.preventDefault(),onClick:d,children:"✕"}),e.jsx("button",{type:"button",className:`tp-color-btn tp-color-btn-confirm${O?" tp-color-btn-flash":""}`,title:"确认",onMouseDown:M=>M.preventDefault(),onClick:Ie,children:"✓"})]})]})]})]})});Ae.displayName="ColorPickerInput";const Ge=({editor:n,visible:o,onVisibleChange:c})=>{const f=V.I18nManager.getInstance(),a=x=>f.t(x),[l,h]=t.useState({borderColor:"#d9d9d9",borderWidth:1}),[u,p]=t.useState("");t.useEffect(()=>{if(o){document.body.style.overflow="hidden";const{state:x}=n,{$from:S}=x.selection;let w=null;x.doc.nodesBetween(S.start(),S.end(),N=>N.type.name==="table"?(w=N,!1):!0),h(w?{borderColor:w.attrs.borderColor||"#d9d9d9",borderWidth:w.attrs.borderWidth?parseInt(w.attrs.borderWidth,10):1}:{borderColor:"#d9d9d9",borderWidth:1})}else document.body.style.overflow="";return()=>{document.body.style.overflow=""}},[o,n]);const m=t.useCallback(()=>{p("")},[]),v=t.useCallback(x=>(p(x),!0),[]),C=t.useCallback(()=>{u||(n.commands.focus(),c(!1))},[u,n,c]),T=t.useCallback(()=>{u||(n.chain().focus().setTableBorder({color:l.borderColor,width:`${l.borderWidth}px`,style:"solid"}).run(),c(!1))},[u,n,l,c]);return o?Te.createPortal(e.jsx("div",{className:"tp-modal-overlay",onMouseDown:x=>{x.target===x.currentTarget&&C()},children:e.jsxs("div",{className:"tp-modal",onMouseDown:x=>x.stopPropagation(),children:[e.jsxs("div",{className:"tp-modal-header",children:[e.jsx("h3",{className:"tp-modal-title",children:a("table.tableSettings")}),e.jsx("button",{className:"tp-modal-close",onClick:C,children:"×"})]}),e.jsxs("div",{className:"tp-modal-body",children:[e.jsxs("div",{className:"tp-form-item",children:[e.jsx("label",{className:"tp-form-label",children:a("table.borderColor")}),e.jsx(Ae,{value:l.borderColor,onChange:x=>h(S=>({...S,borderColor:x})),mode:"border",placeholder:"#d9d9d9",beforeOpen:()=>v("border"),onClose:m})]}),e.jsxs("div",{className:"tp-form-item",children:[e.jsx("label",{className:"tp-form-label",children:a("table.borderWidth")}),e.jsxs("div",{className:"tp-input-with-suffix",children:[e.jsx("input",{type:"number",className:"tp-text-input",min:0,max:10,value:l.borderWidth,onChange:x=>h(S=>({...S,borderWidth:Number(x.target.value)}))}),e.jsx("span",{className:"tp-input-suffix",children:"px"})]})]})]}),e.jsxs("div",{className:"tp-modal-footer",children:[e.jsx("button",{className:"tp-btn tp-btn-default",onClick:C,children:a("common.cancel")}),e.jsx("button",{className:"tp-btn tp-btn-primary",onClick:T,children:a("common.confirm")})]})]})}),document.body):null},Lt=[{value:"left",labelKey:"table.alignLeft"},{value:"center",labelKey:"table.alignCenter"},{value:"right",labelKey:"table.alignRight"},{value:"justify",labelKey:"table.alignJustify"}],Tt=[{value:"top",labelKey:"table.valignTop"},{value:"middle",labelKey:"table.valignMiddle"},{value:"bottom",labelKey:"table.valignBottom"}];function Dt(n){const o=n.attrs.borderWidth||"1px",c=n.attrs.borderStyle||"solid",f=n.attrs.borderColor||"#d9d9d9";return`${o} ${c} ${f}`}function he(n,o,c,f,a,l){const h=n===0,u=n+f>=a.height,p=o===0,m=o+c>=a.width;switch(l){case"top":return h;case"bottom":return u;case"left":return p;case"right":return m;default:return!1}}function _e(n,o,c,f,a,l,h,u){const p=n.attrs.colspan||1,m=n.attrs.rowspan||1,v={...n.attrs};switch(h){case"left":v.borderLeft=u;break;case"right":v.borderRight=u;break;case"top":v.borderTop=u;break;case"bottom":v.borderBottom=u;break}return v.borderLeft||(v.borderLeft=he(o,c,p,m,f,"left")&&a?a:l),v.borderRight||(v.borderRight=he(o,c,p,m,f,"right")&&a?a:l),v.borderTop||(v.borderTop=he(o,c,p,m,f,"top")&&a?a:l),v.borderBottom||(v.borderBottom=he(o,c,p,m,f,"bottom")&&a?a:l),v}function Rt(n,o,c,f,a,l,h,u,p,m){const v=n.attrs.colspan||1,C=n.attrs.rowspan||1;return m?{...n.attrs,borderLeft:he(o,c,v,C,f,"left")&&a?a:l,borderRight:he(o,c,v,C,f,"right")&&a?a:l,borderTop:he(o,c,v,C,f,"top")&&a?a:l,borderBottom:he(o,c,v,C,f,"bottom")&&a?a:l,backgroundColor:h,textAlign:u,verticalAlign:p}:{...n.attrs,backgroundColor:h,textAlign:u,verticalAlign:p}}const Xe=({editor:n,visible:o,onVisibleChange:c})=>{const f=V.I18nManager.getInstance(),a=r=>f.t(r),[l,h]=t.useState({borderColor:"#d9d9d9",borderWidth:1,backgroundColor:"#ffffff",textAlign:"left",verticalAlign:"top"}),[u,p]=t.useState({borderColor:"#d9d9d9",borderWidth:1}),[m,v]=t.useState(""),C=t.useRef(null),T=t.useRef(null),x=t.useCallback(()=>{const r=m==="border"?C.current:T.current;r==null||r.triggerButtonFlash()},[m]),S=t.useCallback(r=>m&&m!==r?(x(),!1):(v(r),!0),[m,x]),w=t.useCallback(()=>{const{state:r}=n,{selection:k}=r;if("$anchorCell"in k&&k.$anchorCell){const y=k.$anchorCell;let H=null;return r.doc.nodesBetween(y.pos,y.pos+1,W=>W.type.name==="tableCell"||W.type.name==="tableHeader"?(H=W,!1):!0),(H==null?void 0:H.attrs)||null}const{$from:g}=k;let i=null;return r.doc.nodesBetween(g.pos,g.pos+1,y=>y.type.name==="tableCell"||y.type.name==="tableHeader"?(i=y,!1):!0),(i==null?void 0:i.attrs)||null},[n]);t.useEffect(()=>{var r,k,g,i;if(o){document.body.style.overflow="hidden";const y=w();if(y){const H={borderColor:((k=(r=y.borderLeft)==null?void 0:r.match(/#\w+/))==null?void 0:k[0])||"#d9d9d9",borderWidth:(i=(g=y.borderLeft)==null?void 0:g.match(/(\d+)px/))!=null&&i[1]?parseInt(y.borderLeft.match(/(\d+)px/)[1],10):1,backgroundColor:y.backgroundColor||"#ffffff",textAlign:y.textAlign||"left",verticalAlign:y.verticalAlign||"middle"};h(H),p({borderColor:H.borderColor,borderWidth:H.borderWidth})}else h({borderColor:"#d9d9d9",borderWidth:1,backgroundColor:"#ffffff",textAlign:"left",verticalAlign:"middle"}),p({borderColor:"#d9d9d9",borderWidth:1})}else document.body.style.overflow="";return()=>{document.body.style.overflow=""}},[o,w]);const N=t.useCallback(()=>{m||(n.commands.focus(),c(!1))},[m,n,c]),s=t.useCallback(()=>{if(m)return;const{state:r,dispatch:k}=n.view,{selection:g}=r,i=g,y=r.tr;let H=!1;const W=l.borderColor!==u.borderColor||l.borderWidth!==u.borderWidth,b=`${l.borderWidth}px solid ${l.borderColor}`,D=(P,B,A,_,O,K)=>{const X=O+1,Z=Rt(P,A.row,A.col,_,K,b,l.backgroundColor,l.textAlign,l.verticalAlign,W);if(y.setNodeMarkup(B,null,Z),H=!0,!W)return;const me=P.attrs.colspan||1,Q=P.attrs.rowspan||1,ae="1px solid #d9d9d9",le=new Map;for(let z=0;z<_.height;z++)for(let ee=0;ee<_.width;ee++){const U=_.map[z*_.width+ee];le.has(U)||le.set(U,{row:z,col:ee})}if(A.col>0){const z=_.map[A.row*_.width+A.col-1],ee=X+z,U=y.doc.nodeAt(ee);if(U&&(U.type.name==="tableCell"||U.type.name==="tableHeader")){const q=le.get(z);if(q&&!he(q.row,q.col,U.attrs.colspan||1,U.attrs.rowspan||1,_,"right")){const fe=_e(U,q.row,q.col,_,K,ae,"right",Z.borderLeft);y.setNodeMarkup(ee,null,fe)}}}if(A.row>0){const z=_.map[(A.row-1)*_.width+A.col],ee=X+z,U=y.doc.nodeAt(ee);if(U&&(U.type.name==="tableCell"||U.type.name==="tableHeader")){const q=le.get(z);if(q&&!he(q.row,q.col,U.attrs.colspan||1,U.attrs.rowspan||1,_,"bottom")){const fe=_e(U,q.row,q.col,_,K,ae,"bottom",Z.borderTop);y.setNodeMarkup(ee,null,fe)}}}if(A.col+(P.attrs.colspan||1)<_.width){const z=_.map[A.row*_.width+A.col+me],ee=X+z,U=y.doc.nodeAt(ee);if(U&&(U.type.name==="tableCell"||U.type.name==="tableHeader")){const q=le.get(z);if(q&&!he(q.row,q.col,U.attrs.colspan||1,U.attrs.rowspan||1,_,"left")){const fe=_e(U,q.row,q.col,_,K,ae,"left",Z.borderRight);y.setNodeMarkup(ee,null,fe)}}}if(A.row+(P.attrs.rowspan||1)<_.height){const z=_.map[(A.row+Q)*_.width+A.col],ee=X+z,U=y.doc.nodeAt(ee);if(U&&(U.type.name==="tableCell"||U.type.name==="tableHeader")){const q=le.get(z);if(q&&!he(q.row,q.col,U.attrs.colspan||1,U.attrs.rowspan||1,_,"top")){const fe=_e(U,q.row,q.col,_,K,ae,"top",Z.borderBottom);y.setNodeMarkup(ee,null,fe)}}}},{$from:E,$to:$}=g;let J=-1,I=null;if(r.doc.nodesBetween(E.pos,$.pos,(P,B)=>P.type.name==="table"?(J=B,I=P,!1):!0),I&&J>=0){const P=Dt(I),B=Ve.TableMap.get(I),A=J+1,_=new Map;for(let O=0;O<B.height;O++)for(let K=0;K<B.width;K++){const X=B.map[O*B.width+K];_.has(X)||_.set(X,{row:O,col:K})}if("$anchorCell"in g&&g.$anchorCell){const O=g.$anchorCell,K=g.$headCell,X=O.pos-A,Z=K.pos-A,me=B.rectBetween(X,Z);B.cellsInRect(me).forEach(ae=>{const le=A+ae,z=r.doc.nodeAt(le);if(z&&(z.type.name==="tableCell"||z.type.name==="tableHeader")){const ee=_.get(ae);ee&&D(z,le,ee,B,J,P)}})}else r.doc.nodesBetween(E.pos,$.pos,(O,K)=>{if(O.type.name==="tableCell"||O.type.name==="tableHeader"){const X=K-A,Z=_.get(X);Z&&D(O,K,Z,B,J,P)}return!0})}H&&k&&(y.setSelection(i.map(y.doc,y.mapping)),k(y),n.commands.focus()),c(!1)},[m,n,l,u,c]);return o?Te.createPortal(e.jsx("div",{className:"tp-modal-overlay",onMouseDown:r=>{r.target===r.currentTarget&&N()},children:e.jsxs("div",{className:"tp-modal",onMouseDown:r=>r.stopPropagation(),children:[e.jsxs("div",{className:"tp-modal-header",children:[e.jsx("h3",{className:"tp-modal-title",children:a("table.cellSettings")}),e.jsx("button",{className:"tp-modal-close",onClick:N,children:"×"})]}),e.jsxs("div",{className:"tp-modal-body",children:[e.jsxs("div",{className:"tp-form-item",children:[e.jsx("label",{className:"tp-form-label",children:a("table.borderColor")}),e.jsx(Ae,{ref:C,value:l.borderColor,onChange:r=>h(k=>({...k,borderColor:r})),mode:"border",placeholder:"#d9d9d9",beforeOpen:()=>S("border"),onClose:()=>v("")})]}),e.jsxs("div",{className:"tp-form-item",children:[e.jsx("label",{className:"tp-form-label",children:a("table.borderWidth")}),e.jsxs("div",{className:"tp-input-with-suffix",children:[e.jsx("input",{type:"number",className:"tp-text-input",min:0,max:10,value:l.borderWidth,onChange:r=>h(k=>({...k,borderWidth:Number(r.target.value)}))}),e.jsx("span",{className:"tp-input-suffix",children:"px"})]})]}),e.jsxs("div",{className:"tp-form-item",children:[e.jsx("label",{className:"tp-form-label",children:a("table.backgroundColor")}),e.jsx(Ae,{ref:T,value:l.backgroundColor,onChange:r=>h(k=>({...k,backgroundColor:r})),mode:"background",placeholder:"transparent",beforeOpen:()=>S("background"),onClose:()=>v("")})]}),e.jsxs("div",{className:"tp-form-item",children:[e.jsx("label",{className:"tp-form-label",children:a("table.textAlign")}),e.jsx("div",{className:"tp-align-options",children:Lt.map(r=>e.jsxs("button",{className:`tp-align-btn${l.textAlign===r.value?" active":""}`,onClick:()=>h(k=>({...k,textAlign:r.value})),children:[e.jsxs("span",{className:"tp-align-icon tp-align-icon-svg",children:[r.value==="left"&&e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"6",y1:"8",x2:"14",y2:"8"}),e.jsx("line",{x1:"6",y1:"12",x2:"11",y2:"12"}),e.jsx("line",{x1:"6",y1:"16",x2:"16",y2:"16"})]}),r.value==="center"&&e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"7",y1:"8",x2:"17",y2:"8"}),e.jsx("line",{x1:"9",y1:"12",x2:"15",y2:"12"}),e.jsx("line",{x1:"8",y1:"16",x2:"16",y2:"16"})]}),r.value==="right"&&e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"10",y1:"8",x2:"18",y2:"8"}),e.jsx("line",{x1:"13",y1:"12",x2:"18",y2:"12"}),e.jsx("line",{x1:"8",y1:"16",x2:"18",y2:"16"})]}),r.value==="justify"&&e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"6",y1:"8",x2:"18",y2:"8"}),e.jsx("line",{x1:"6",y1:"12",x2:"18",y2:"12"}),e.jsx("line",{x1:"6",y1:"16",x2:"18",y2:"16"})]})]}),e.jsx("span",{className:"tp-align-label",children:a(r.labelKey)})]},r.value))})]}),e.jsxs("div",{className:"tp-form-item",children:[e.jsx("label",{className:"tp-form-label",children:a("table.verticalAlign")}),e.jsx("div",{className:"tp-align-options",children:Tt.map(r=>e.jsxs("button",{className:`tp-align-btn${l.verticalAlign===r.value?" active":""}`,onClick:()=>h(k=>({...k,verticalAlign:r.value})),children:[e.jsxs("span",{className:"tp-align-icon tp-align-icon-svg",children:[r.value==="top"&&e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"6",y1:"7",x2:"18",y2:"7"})]}),r.value==="middle"&&e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"6",y1:"12",x2:"18",y2:"12"})]}),r.value==="bottom"&&e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"6",y1:"17",x2:"18",y2:"17"})]})]}),e.jsx("span",{className:"tp-align-label",children:a(r.labelKey)})]},r.value))})]})]}),e.jsxs("div",{className:"tp-modal-footer",children:[e.jsx("button",{className:"tp-btn tp-btn-default",onClick:N,children:a("common.cancel")}),e.jsx("button",{className:"tp-btn tp-btn-primary",onClick:s,children:a("common.confirm")})]})]})}),document.body):null},Ze=({manager:n,visible:o,onVisibleChange:c})=>{const f=V.I18nManager.getInstance(),[a,l]=t.useState([]),[h,u]=t.useState(""),[p,m]=t.useState(null),[v,C]=t.useState(!1),T=t.useRef(null),x=t.useRef(null),S=t.useRef(null),w=t.useCallback((i,y)=>f.t(i,y)||i,[f]),N=t.useCallback(i=>{try{const y=new Date(i),W=new Date().getTime()-y.getTime(),b=Math.floor(W/6e4),D=Math.floor(W/36e5),E=Math.floor(W/864e5);return b<1?w("compare.justNow"):b<60?w("compare.minutesAgo",{n:String(b)}):D<24?w("compare.hoursAgo",{n:String(D)}):E<7?w("compare.daysAgo",{n:String(E)}):y.toLocaleDateString()+" "+y.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return i}},[w]),s=t.useCallback(i=>{const y={blur:"compare.sourceBlur",baseline:"compare.sourceBaseline",paste:"compare.sourcePaste",import:"compare.sourceImport",manual:"compare.sourceManual",interval:"compare.sourceInterval",imported:"compare.sourceImported"};return y[i]?w(y[i]):i},[w]),r=t.useCallback((i,y)=>`v${a.length-y}.0 - ${N(i.timestamp)} (${s(i.source)})${i.label?` - ${i.label}`:""}`,[N,s,a]);t.useEffect(()=>{if(!o){u(""),m(null);return}let i=!1;return C(!0),n.listVersions().then(y=>{i||(l(y),!h&&y.length>0&&u(y[0].id),C(!1))}).catch(()=>{i||(l([]),C(!1))}),()=>{i=!0}},[o,n]),t.useEffect(()=>{if(!h||!n){m(null);return}n.compareWithVersion(h).then(m).catch(()=>m(null))},[h,n]),t.useEffect(()=>{var i,y;if(p&&T.current&&x.current){(i=S.current)==null||i.detach();const H=new V.ScrollSyncManager(T.current,x.current);H.attach();const W=setTimeout(()=>H.refresh(),0);return S.current=H,()=>{clearTimeout(W),H.detach()}}else(y=S.current)==null||y.detach(),S.current=null},[p]),t.useEffect(()=>{const i=y=>{y.key==="Escape"&&o&&c(!1)};return document.addEventListener("keydown",i),()=>document.removeEventListener("keydown",i)},[o,c]);const k=t.useCallback(async()=>{const i=await n.createSnapshot(w("compare.createSnapshot"));i?V.showToast(w("compare.snapshotCreated").replace("{time}",i.label||i.timestamp)):V.showToast({message:w("compare.snapshotFailed"),type:"error"});const y=await n.listVersions();l(y)},[n,w]),g=t.useCallback(()=>{c(!1)},[c]);return o?e.jsxs("div",{className:"cyte-compare-overlay",children:[e.jsxs("div",{className:"cyte-compare-header",children:[e.jsxs("div",{className:"cyte-compare-header__title",children:[e.jsxs("svg",{className:"cyte-compare-header__title-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"18",rx:"1"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"18",rx:"1"}),e.jsx("line",{x1:"10",y1:"8",x2:"14",y2:"8"}),e.jsx("line",{x1:"10",y1:"12",x2:"14",y2:"12"}),e.jsx("line",{x1:"10",y1:"16",x2:"14",y2:"16"})]}),w("compare.title")]}),e.jsxs("div",{className:"cyte-compare-header__actions",children:[e.jsxs("div",{className:"cyte-compare-version-selector",children:[e.jsxs("span",{className:"cyte-compare-version-selector__label",children:[w("compare.selectVersion"),":"]}),e.jsxs("select",{value:h,onChange:i=>u(i.target.value),className:"cyte-compare-version-selector__select",children:[e.jsx("option",{value:"",disabled:!0,children:w("compare.selectVersion")}),a.map((i,y)=>e.jsx("option",{value:i.id,children:r(i,y)},i.id))]})]}),e.jsx("button",{className:"cyte-compare-btn--close",onClick:g,title:w("compare.close"),children:"✕"})]})]}),p&&e.jsxs("div",{className:"cyte-compare-stats",children:[e.jsxs("div",{className:"cyte-compare-stats__item",children:[e.jsxs("span",{className:"cyte-compare-stats__badge",children:[e.jsx("span",{className:"cyte-compare-stats__dot cyte-compare-stats__dot--added"}),e.jsx("span",{className:"cyte-compare-stats__count cyte-compare-stats__count--added",children:p.stats.added})]}),e.jsx("span",{className:"cyte-compare-stats__label",children:w("compare.statsAdded")})]}),e.jsxs("div",{className:"cyte-compare-stats__item",children:[e.jsxs("span",{className:"cyte-compare-stats__badge",children:[e.jsx("span",{className:"cyte-compare-stats__dot cyte-compare-stats__dot--removed"}),e.jsx("span",{className:"cyte-compare-stats__count cyte-compare-stats__count--removed",children:p.stats.removed})]}),e.jsx("span",{className:"cyte-compare-stats__label",children:w("compare.statsRemoved")})]}),e.jsxs("div",{className:"cyte-compare-stats__item",children:[e.jsxs("span",{className:"cyte-compare-stats__badge",children:[e.jsx("span",{className:"cyte-compare-stats__dot cyte-compare-stats__dot--modified"}),e.jsx("span",{className:"cyte-compare-stats__count cyte-compare-stats__count--modified",children:p.stats.modified})]}),e.jsx("span",{className:"cyte-compare-stats__label",children:w("compare.statsModified")})]}),e.jsxs("div",{className:"cyte-compare-stats__item cyte-compare-stats__item--unchanged",children:[e.jsxs("span",{className:"cyte-compare-stats__badge",children:[e.jsx("span",{className:"cyte-compare-stats__dot cyte-compare-stats__dot--unchanged"}),e.jsx("span",{className:"cyte-compare-stats__count",children:p.stats.unchanged})]}),e.jsx("span",{className:"cyte-compare-stats__label",children:w("compare.statsUnchanged")})]})]}),e.jsxs("div",{className:"cyte-compare-content",children:[a.length===0&&!v&&e.jsxs("div",{className:"cyte-compare-empty",children:[e.jsxs("svg",{className:"cyte-compare-empty__icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M8 12h8M12 8v8"})]}),e.jsx("div",{className:"cyte-compare-empty__text",children:w("compare.noVersions")}),e.jsx("div",{className:"cyte-compare-empty__hint",children:w("compare.noVersionsHint")}),e.jsx("button",{className:"cyte-compare-btn cyte-compare-btn--primary cyte-compare-snapshot-btn",onClick:k,children:w("compare.createSnapshot")})]}),p&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:T,className:"cyte-compare-pane",children:[e.jsx("div",{className:"cyte-compare-pane__header",children:(()=>{const i=a.findIndex(y=>y.id===h);return i===-1?w("compare.leftLabel"):`${w("compare.leftLabel")} - ${r(a[i],i)}`})()}),e.jsx("div",{className:"cyte-compare-pane__body",children:p.left.map(i=>e.jsx("div",{dangerouslySetInnerHTML:{__html:i.html}},i.key))})]}),e.jsxs("div",{ref:x,className:"cyte-compare-pane",children:[e.jsx("div",{className:"cyte-compare-pane__header",children:w("compare.rightLabel")}),e.jsx("div",{className:"cyte-compare-pane__body",children:p.right.map(i=>e.jsx("div",{dangerouslySetInnerHTML:{__html:i.html}},i.key))})]})]}),a.length>0&&!h&&!p&&e.jsx("div",{className:"cyte-compare-empty",children:e.jsx("div",{className:"cyte-compare-empty__text",children:w("compare.selectVersion")})})]})]}):null},Et=({visible:n,defaultFilename:o,onConfirm:c,onCancel:f,onClose:a})=>{const{t:l}=ue(),[h,u]=t.useState(""),p=t.useRef(null);t.useEffect(()=>(n?(u(o||"document"),document.body.style.overflow="hidden",setTimeout(()=>{var x,S;(x=p.current)==null||x.focus(),(S=p.current)==null||S.select()},100)):document.body.style.overflow="",()=>{document.body.style.overflow=""}),[n,o]);const m=t.useCallback(()=>{const x=h.trim()||"document";c(x),a()},[h,c,a]),v=t.useCallback(()=>{f==null||f(),a()},[f,a]),C=t.useCallback(x=>{x.target===x.currentTarget&&v()},[v]),T=t.useCallback(x=>{x.key==="Enter"?(x.preventDefault(),m()):x.key==="Escape"&&(x.preventDefault(),v())},[m,v]);return n?Te.createPortal(e.jsx("div",{className:"tp-export-dialog-overlay",onMouseDown:C,children:e.jsxs("div",{className:"tp-export-dialog",onMouseDown:x=>x.stopPropagation(),onKeyDown:T,children:[e.jsxs("div",{className:"tp-dialog-header",children:[e.jsx("span",{className:"tp-dialog-title",children:l("toolbar.exportWord")}),e.jsx("button",{className:"tp-dialog-close",onClick:v,children:"×"})]}),e.jsxs("div",{className:"tp-dialog-body",children:[e.jsx("label",{className:"tp-input-label",children:l("toolbar.exportWordFilename")}),e.jsxs("div",{className:"tp-input-row",children:[e.jsx("input",{ref:p,type:"text",className:"tp-filename-input",value:h,onChange:x=>u(x.target.value),onKeyDown:T}),e.jsx("span",{className:"tp-filename-suffix",children:".docx"}),e.jsx("button",{className:"tp-confirm-btn",onClick:m,children:l("common.confirm")})]})]})]})}),document.body):null},Ht=({visible:n,defaultFilename:o,onConfirm:c,onCancel:f,onClose:a})=>{const{t:l}=ue(),[h,u]=t.useState(""),p=t.useRef(null);t.useEffect(()=>(n?(u(o||"document"),document.body.style.overflow="hidden",setTimeout(()=>{var x,S;(x=p.current)==null||x.focus(),(S=p.current)==null||S.select()},100)):document.body.style.overflow="",()=>{document.body.style.overflow=""}),[n,o]);const m=t.useCallback(()=>{const x=h.trim()||"document";c(x),a()},[h,c,a]),v=t.useCallback(()=>{f==null||f(),a()},[f,a]),C=t.useCallback(x=>{x.target===x.currentTarget&&v()},[v]),T=t.useCallback(x=>{x.key==="Enter"?(x.preventDefault(),m()):x.key==="Escape"&&(x.preventDefault(),v())},[m,v]);return n?Te.createPortal(e.jsx("div",{className:"tp-export-dialog-overlay",onMouseDown:C,children:e.jsxs("div",{className:"tp-export-dialog",onMouseDown:x=>x.stopPropagation(),onKeyDown:T,children:[e.jsxs("div",{className:"tp-dialog-header",children:[e.jsx("span",{className:"tp-dialog-title",children:l("toolbar.exportMarkdown")}),e.jsx("button",{className:"tp-dialog-close",onClick:v,children:"×"})]}),e.jsxs("div",{className:"tp-dialog-body",children:[e.jsx("label",{className:"tp-input-label",children:l("toolbar.exportMarkdownFilename")}),e.jsxs("div",{className:"tp-input-row",children:[e.jsx("input",{ref:p,type:"text",className:"tp-filename-input",value:h,onChange:x=>u(x.target.value),onKeyDown:T}),e.jsx("span",{className:"tp-filename-suffix",children:".md"}),e.jsx("button",{className:"tp-confirm-btn",onClick:m,children:l("common.confirm")})]})]})]})}),document.body):null},Qe=t.forwardRef((n,o)=>{const{html:c,json:f,config:a,height:l="300px",minHeight:h,maxHeight:u,autoHeight:p=!1,placeholder:m,toolbar:v,readonly:C=!1,disabled:T=!1,autofocus:x=!1,locale:S,pasteMode:w,uploadUrl:N,onChange:s,onFocus:r,onBlur:k,onReady:g,onViewModeChange:i,onToolbarClick:y,onFullscreenChange:H,toolbarRender:W}=n,[b,D]=t.useState("normal"),E=t.useRef(""),$=t.useRef(null),[J,I]=t.useState(!1),[P,B]=t.useState({x:0,y:0}),[A,_]=t.useState(null),[O,K]=t.useState(!1),[X,Z]=t.useState(!1),[me,Q]=t.useState(!1),[ae,le]=t.useState(!1),[z,ee]=t.useState("document"),[U,q]=t.useState(!1),[fe,De]=t.useState("document"),[xe,be]=t.useState(!1),Ce=V.I18nManager.getInstance(),ye=t.useCallback(j=>Ce.t(j)||j,[Ce]),Re=t.useMemo(()=>{const L={...a||{}};return l!==void 0&&(L.height=l),h!==void 0&&(L.minHeight=h),u!==void 0&&(L.maxHeight=u),p!==void 0&&(L.autoHeight=p),m!==void 0&&(L.placeholder=m),v!==void 0&&(L.toolbar=v),C!==void 0&&(L.readonly=C),T!==void 0&&(L.disabled=T),x!==void 0&&(L.autofocus=x),S!==void 0&&(L.locale=S),w!==void 0&&(L.paste={...L.paste,mode:w}),N!==void 0&&(L.upload={...L.upload,url:N}),L},[a,l,h,u,p,m,v,C,T,x,S,w,N]),Ie=t.useMemo(()=>Re.toolbar||["undo","redo","formatPainter","|","bold","italic","underline","strikethrough","superscript","subscript","|","fontFamily","fontSize","color","bgColor","|","heading","align","lineHeight","bulletList","orderedList","outdent","indent","|","link","insertTable","imageUpload","video","formula","structure","|","blockquote","codeBlock","|","import","export","getHTML","getJSON","|","snapshot","compare","autoFormat","fullscreen"],[Re.toolbar]),{manager:d,isReady:G,isFocused:M,isEmpty:R,containerRef:Y,setContentFromProp:re}=Je({config:Re,onUpdate(j,L){s==null||s({html:j,json:L})},onFocus(j){r==null||r(j)},onBlur(j){k==null||k(j)},onReady(j){c?j.setContent(c):f&&j.setJSON(f),$e(j),g==null||g(j)}}),{activeStates:ie,disabledStates:Ee}=qe(d);t.useEffect(()=>{c!==void 0&&re(c)},[c,re]),t.useEffect(()=>{f!==void 0&&re(void 0,f)},[f,re]);const Ne=t.useCallback(j=>{let L="",F=0;const ne=" ",de=j.replace(/>\s+</g,"><").trim().split(/(<\/?[^>]+>)/g).filter(ce=>ce.trim()!=="");for(let ce=0;ce<de.length;ce++){const pe=de[ce];if(pe.match(/^<\/\w/))F=Math.max(0,F-1),L+=ne.repeat(F)+pe+`
|
|
16
|
-
`;else if(
|
|
17
|
-
`;const oe=
|
|
18
|
-
`;else if(
|
|
19
|
-
`;else{const oe=
|
|
20
|
-
`)}}return
|
|
15
|
+
*/Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("react"),ot=require("@tiptap/pm/state"),Ye=require("@tiptap/pm/tables"),A=require("@cyte-editor/core"),rt=require("@cyte-editor/license"),Ee=require("react-dom");function Ge(n){var f,S;const r=t.useRef(null),u=t.useRef(null),[h,c]=t.useState(!1),[i,x]=t.useState(!1),[d,p]=t.useState(!0),m=t.useRef(!1),w=t.useRef(n);w.current=n;const M=t.useCallback((b,N)=>{if(!(m.current||!u.current)){if(N!==void 0){const g=JSON.stringify(u.current.getJSON()),o=JSON.stringify(N);if(g===o)return;u.current.setJSON(N);return}if(b!==void 0){if(b===u.current.getHTML())return;u.current.setContent(b)}}},[]);t.useEffect(()=>{var g,o;const b=r.current;if(!b)return;const N=A.EditorManager.create(b,w.current.config);return u.current=N,p(N.isEmpty()),N.on("update",({html:y})=>{var a,l;p(N.isEmpty()),m.current=!0,(l=(a=w.current).onUpdate)==null||l.call(a,y,N.getJSON()),Promise.resolve().then(()=>{m.current=!1})}),N.on("focus",({event:y})=>{var a,l;x(!0),(l=(a=w.current).onFocus)==null||l.call(a,y)}),N.on("blur",({event:y})=>{var a,l;x(!1),(l=(a=w.current).onBlur)==null||l.call(a,y)}),c(!0),(o=(g=w.current).onReady)==null||o.call(g,N),()=>{N.destroy(),u.current=null,c(!1)}},[]),t.useEffect(()=>{const b=u.current;b&&n.config.readonly!==void 0&&b.setReadonly(n.config.readonly)},[n.config.readonly,n.config.disabled]),t.useEffect(()=>{n.config.locale&&A.I18nManager.getInstance().setLocale(n.config.locale)},[n.config.locale]);const T=t.useRef((f=n.config.license)==null?void 0:f.key);return t.useEffect(()=>{var N;const b=(N=n.config.license)==null?void 0:N.key;b!==T.current&&(T.current=b,b&&u.current&&u.current.updateLicense(n.config.license))},[(S=n.config.license)==null?void 0:S.key]),{manager:u.current,isReady:h,isFocused:i,isEmpty:d,containerRef:r,setContentFromProp:M}}function Xe(n){const[r,u]=t.useState({}),[h,c]=t.useState({}),i=t.useCallback(async()=>{if(!n)return;const x=n.getEditor(),d={},p={};for(const[T,f]of Object.entries(A.toolbarItemDefs))f.isActive&&(d[T]=f.isActive(x)),f.isDisabled&&(p[T]=f.isDisabled(x));const m=rt.getLicenseStatus(),w=m==="valid"||m==="expiring_soon",M=await n.hasSnapshots();if(p.compare=!M||!w,!w)for(const[T,f]of Object.entries(A.toolbarItemDefs))f.requiredTier&&T!=="compare"&&(p[T]=!0);for(const[T,f]of Object.entries(A.toolbarItemDefs))f.requiresPlugin&&!n.hasProPlugin(f.requiresPlugin)&&(p[T]=!0);u(d),c(p)},[n]);return t.useEffect(()=>{if(n)return n.on("selectionUpdate",i),n.on("update",i),n.on("transaction",i),n.on("snapshot-created",i),i(),()=>{n.off("selectionUpdate",i),n.off("update",i),n.off("transaction",i),n.off("snapshot-created",i)}},[n,i]),{activeStates:r,disabledStates:h,refresh:i}}function de(){const n=A.I18nManager.getInstance(),[r,u]=t.useState(0);t.useEffect(()=>n.onChange(()=>{u(i=>i+1)}),[n]);function h(c,i){return n.t(c,i)}return{t:h,locale:n.getLocale()}}const lt={undo:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 7v6h6"/><path d="M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13"/></svg>',redo:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 7v6h-6"/><path d="M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3L21 13"/></svg>',bold:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"/><path d="M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"/></svg>',italic:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="4" x2="10" y2="4"/><line x1="14" y1="20" x2="5" y2="20"/><line x1="15" y1="4" x2="9" y2="20"/></svg>',underline:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 4v6a6 6 0 0 0 12 0V4"/><line x1="4" y1="20" x2="20" y2="20"/></svg>',strikethrough:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 4H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H7"/><line x1="3" y1="12" x2="21" y2="12"/></svg>',link:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>',image:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg>',table:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><line x1="3" y1="9" x2="21" y2="9"/><line x1="3" y1="15" x2="21" y2="15"/><line x1="9" y1="3" x2="9" y2="21"/><line x1="15" y1="3" x2="15" y2="21"/></svg>',video:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="16" height="16" rx="2"/><polygon points="9 8.5 14 12 9 15.5" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg>',bulletList:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="8" y1="4" x2="21" y2="4"/><line x1="8" y1="10" x2="21" y2="10"/><line x1="8" y1="16" x2="21" y2="16"/><line x1="8" y1="22" x2="21" y2="22"/><circle cx="4" cy="4" r="1" fill="currentColor"/><circle cx="4" cy="10" r="1" fill="currentColor"/><circle cx="4" cy="16" r="1" fill="currentColor"/><circle cx="4" cy="22" r="1" fill="currentColor"/></svg>',orderedList:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="8" y1="4" x2="21" y2="4"/><line x1="8" y1="10" x2="21" y2="10"/><line x1="8" y1="16" x2="21" y2="16"/><line x1="8" y1="22" x2="21" y2="22"/><text x="1" y="7" font-size="7" font-weight="bold" fill="currentColor" stroke="none" font-family="sans-serif">1</text><text x="1" y="13" font-size="7" font-weight="bold" fill="currentColor" stroke="none" font-family="sans-serif">2</text><text x="1" y="19" font-size="7" font-weight="bold" fill="currentColor" stroke="none" font-family="sans-serif">3</text><text x="1" y="25" font-size="7" font-weight="bold" fill="currentColor" stroke="none" font-family="sans-serif">4</text></svg>',outdent:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="7 8 3 12 7 16"/><line x1="21" y1="12" x2="11" y2="12"/><line x1="21" y1="6" x2="11" y2="6"/><line x1="21" y1="18" x2="11" y2="18"/></svg>',indent:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 8 7 12 3 16"/><line x1="21" y1="12" x2="11" y2="12"/><line x1="21" y1="6" x2="11" y2="6"/><line x1="21" y1="18" x2="11" y2="18"/></svg>',blockquote:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24"><path d="M4.58341 17.3211C3.55316 16.2275 3 15 3 13.0104C3 9.51092 5.45651 6.37372 9.03059 4.82324L9.92328 6.20085C6.58804 8.00545 5.93618 10.3461 5.67564 11.8221C6.21263 11.5444 6.91558 11.4467 7.60471 11.5106C9.40908 11.6778 10.8312 13.1591 10.8312 15C10.8312 16.933 9.26416 18.5 7.33116 18.5C6.2581 18.5 5.23196 18.0096 4.58341 17.3211ZM14.5834 17.3211C13.5532 16.2275 13 15 13 13.0104C13 9.51092 15.4565 6.37372 19.0306 4.82324L19.9233 6.20085C16.588 8.00545 15.9362 10.3461 15.6756 11.8221C16.2126 11.5444 16.9156 11.4467 17.6047 11.5106C19.4091 11.6778 20.8312 13.1591 20.8312 15C20.8312 16.933 19.2642 18.5 17.3312 18.5C16.2581 18.5 15.232 18.0096 14.5834 17.3211Z" fill="currentColor"/></svg>',codeBlock:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>',color:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3l6.5 13H5.5L12 3z"/><line x1="4" y1="21" x2="20" y2="21" stroke-width="3"/></svg>',bgColor:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="14" rx="2"/><line x1="4" y1="21" x2="20" y2="21" stroke-width="3"/></svg>',heading:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 4v16"/><path d="M18 4v16"/><path d="M6 12h12"/></svg>',align:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="3" y1="4" x2="21" y2="4"/><line x1="3" y1="10" x2="15" y2="10"/><line x1="3" y1="16" x2="21" y2="16"/><line x1="3" y1="22" x2="15" y2="22"/></svg>',fontFamily:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 20 L9 5 L15 20"/><line x1="6.2" y1="12" x2="11.8" y2="12"/><rect x="11" y="14" width="12" height="10" fill="white" stroke="none"/><line x1="14" y1="16" x2="20" y2="16"/><line x1="14" y1="19" x2="20" y2="19"/><line x1="14" y1="22" x2="20" y2="22"/></svg>',fontSize:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 40 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><text x="4" y="22" font-size="42" fill="currentColor" stroke="none" font-family="serif" font-weight="bold">A</text><rect x="20" y="10" width="16" height="16" fill="white" stroke="none"/><text x="24" y="25" font-size="36" fill="currentColor" stroke="none" font-family="serif" font-weight="bold">a</text></svg>',lineHeight:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="9" y1="4" x2="21" y2="4"/><line x1="9" y1="10" x2="21" y2="10"/><line x1="9" y1="16" x2="21" y2="16"/><line x1="9" y1="22" x2="21" y2="22"/><polyline points="3 10 3 4"/><polyline points="1 7 3 4 5 7"/><polyline points="3 16 3 22"/><polyline points="1 19 3 22 5 19"/></svg>',getHTML:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>',getJSON:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/><polyline points="10 9 9 9 8 9"/></svg>',importWord:'<svg xmlns="http://www.w3.org/2000/svg" width="26" height="26" viewBox="0 0 36 36" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M20 4H7a3 3 0 0 0-3 3v22a3 3 0 0 0 3 3h22a3 3 0 0 0 3-3V13z"/><polyline points="20 4 20 13 32 13"/><text x="8" y="27" font-size="16" font-weight="bold" fill="currentColor" stroke="none" font-family="sans-serif">W</text><path d="M28 28v-9m0 0l-3 3m3-3l3 3"/></svg>',importMarkdown:'<svg xmlns="http://www.w3.org/2000/svg" width="26" height="26" viewBox="0 0 36 36" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M20 4H7a3 3 0 0 0-3 3v22a3 3 0 0 0 3 3h22a3 3 0 0 0 3-3V13z"/><polyline points="20 4 20 13 32 13"/><text x="9" y="27" font-size="16" font-weight="bold" fill="currentColor" stroke="none" font-family="sans-serif">#</text><path d="M28 28v-9m0 0l-3 3m3-3l3 3"/></svg>',exportWord:'<svg xmlns="http://www.w3.org/2000/svg" width="26" height="26" viewBox="0 0 36 36" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M20 4H7a3 3 0 0 0-3 3v22a3 3 0 0 0 3 3h22a3 3 0 0 0 3-3V13z"/><polyline points="20 4 20 13 32 13"/><text x="8" y="27" font-size="16" font-weight="bold" fill="currentColor" stroke="none" font-family="sans-serif">W</text><path d="M28 19v9m0 0l-3-3m3 3l3-3"/></svg>',exportMarkdown:'<svg xmlns="http://www.w3.org/2000/svg" width="26" height="26" viewBox="0 0 36 36" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M20 4H7a3 3 0 0 0-3 3v22a3 3 0 0 0 3 3h22a3 3 0 0 0 3-3V13z"/><polyline points="20 4 20 13 32 13"/><text x="9" y="27" font-size="16" font-weight="bold" fill="currentColor" stroke="none" font-family="sans-serif">#</text><path d="M28 19v9m0 0l-3-3m3 3l3-3"/></svg>',imageUpload:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8" cy="8" r="1.5" fill="currentColor" stroke="none"/><polyline points="5 17 10 11 14 14 19 8"/></svg>',superscript:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24"><text x="2" y="20" font-size="20" fill="currentColor" stroke="none" font-family="serif" font-weight="bold">x</text><text x="14" y="12" font-size="11" fill="currentColor" stroke="none" font-family="serif" font-weight="bold">2</text></svg>',subscript:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24"><text x="2" y="20" font-size="20" fill="currentColor" stroke="none" font-family="serif" font-weight="bold">x</text><text x="14" y="22" font-size="11" fill="currentColor" stroke="none" font-family="serif" font-weight="bold">2</text></svg>',insertTable:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><line x1="3" y1="9" x2="21" y2="9"/><line x1="3" y1="15" x2="21" y2="15"/><line x1="9" y1="3" x2="9" y2="21"/><line x1="15" y1="3" x2="15" y2="21"/></svg>',formatPainter:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="5" width="14" height="7" rx="1"/><path d="M16 7.5h1.5c1.5 0 2.5 1 2.5 2.5v2.5c0 1.5-1 2.5-2.5 2.5h-4c-1.5 0-2.5 1-2.5 2.5V18"/><rect x="10" y="18" width="2" height="4.5" rx="0.5"/></svg>',compare:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="7" height="18" rx="1"/><rect x="14" y="3" width="7" height="18" rx="1"/><line x1="10" y1="8" x2="14" y2="8"/><line x1="10" y1="12" x2="14" y2="12"/><line x1="10" y1="16" x2="14" y2="16"/></svg>',snapshot:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"/><circle cx="12" cy="13" r="4"/></svg>',fullscreen:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 4H4V8M4 4L10 10"/><path d="M16 4H20V8M20 4L14 10"/><path d="M4 16V20H8M4 20L10 14"/><path d="M20 16V20H16M20 20L14 14"/></svg>',import:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 3h5a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-5"/><polyline points="9 8 14 12 9 16"/><line x1="3" y1="12" x2="14" y2="12"/></svg>',export:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h5"/><polyline points="16 8 21 12 16 16"/><line x1="10" y1="12" x2="21" y2="12"/></svg>',formula:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24"><text x="1" y="20" font-size="20" fill="currentColor" stroke="none" font-family="serif" font-weight="bold">Σ</text><text x="14" y="22" font-size="9" fill="currentColor" stroke="none" font-family="serif">x</text></svg>',structure:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="12 2.5 20 7 20 17 12 21.5 4 17 4 7"/><circle cx="12" cy="12" r="4"/></svg>',autoFormat:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 4V2"/><path d="M15 16v-2"/><path d="M8 9h2"/><path d="M20 9h2"/><path d="M17.8 11.8 19 13"/><path d="M17.8 6.2 19 5"/><path d="M3 21l9-9"/><path d="M12.2 6.2 11 5"/></svg>'};function ge(n){return lt[n]||""}const it=({visible:n,targetRect:r,editor:u,savedSelection:h,initialUrl:c,isEditing:i,onConfirm:x,onCancel:d,onClose:p})=>{const{t:m}=de(),[w,M]=t.useState(c||""),[T,f]=t.useState(!1),S=t.useRef(null),[b,N]=t.useState(null),[g,o]=t.useState(""),y=()=>{if(u&&h)try{const{from:k,to:L}=h,E=u.view.coordsAtPos(k),$=u.view.coordsAtPos(L);if(E&&$){N(new DOMRect(E.left,E.top,$.left-E.left,E.bottom-E.top));return}}catch{}N(r||null)};t.useEffect(()=>{const k=()=>{n&&y()};return window.addEventListener("scroll",k,!0),window.addEventListener("resize",k),()=>{window.removeEventListener("scroll",k,!0),window.removeEventListener("resize",k)}},[n,u,h,r]),t.useEffect(()=>{n&&(M(c||""),o(""),y(),setTimeout(()=>{var k,L;(k=S.current)==null||k.focus(),(L=S.current)==null||L.select()},0))},[n]);const a=t.useMemo(()=>{const k=b;if(!k)return{};const L=180,E=8,$=window.innerHeight,U=window.innerWidth;let P=k.bottom+E,W=!1;P+L>$&&(P=k.top-L-E,W=!0),f(W);let F=k.left+k.width/2;const H=320;return F+H/2>U&&(F=U-H/2-16),F<H/2+16&&(F=H/2+16),{top:`${P}px`,left:`${F}px`}},[b]),l=k=>{try{const L=new URL(k);return L.protocol==="http:"||L.protocol==="https:"}catch{return!1}},v=()=>{const k=w.trim();if(i&&k===""){x(""),p();return}if(!k){o(m("link.urlRequired"));return}if(!l(k)){o(m("link.invalidUrl"));return}x(k),p()},D=()=>{x(""),p()},B=()=>{d(),p()};return n?e.jsx("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,zIndex:9998,background:"transparent"},onMouseDown:k=>{k.target===k.currentTarget&&B()},children:e.jsxs("div",{className:`tp-link-popover${T?" is-above":""}`,style:a,onMouseDown:k=>k.stopPropagation(),onKeyDown:k=>{k.key==="Enter"?(k.preventDefault(),v()):k.key==="Escape"&&(k.preventDefault(),B())},children:[e.jsx("div",{className:"tp-popover-arrow"}),e.jsxs("div",{className:"tp-popover-content",children:[e.jsx("div",{className:"tp-popover-header",children:e.jsx("span",{className:"tp-popover-title",children:m(i?"link.editLink":"link.insertLink")})}),e.jsxs("div",{className:"tp-popover-body",children:[e.jsx("label",{className:"tp-popover-label",children:m("link.url")}),e.jsxs("div",{className:"tp-popover-input-row",children:[e.jsx("input",{ref:S,type:"url",className:`tp-popover-input${g?" is-error":""}`,value:w,placeholder:m("link.url"),onChange:k=>M(k.target.value),onKeyDown:k=>{k.key==="Enter"?(k.preventDefault(),v()):k.key==="Escape"&&(k.preventDefault(),B())}}),e.jsx("button",{className:"tp-popover-btn-confirm",onClick:v,children:m("common.confirm")}),i&&e.jsx("button",{className:"tp-popover-btn-unlink",onClick:D,children:m("link.unlink")})]}),g&&e.jsx("div",{className:"tp-link-error-message",children:g})]})]})]})}):null},at="#b4d5fe",ct=({def:n,editor:r,active:u,disabled:h,onCustomClick:c})=>{const{t:i}=de(),[x,d]=t.useState(!1),p=t.useRef(null),m=t.useRef(null),w=t.useRef(""),M=t.useRef(!1),T=g=>{var o;if(g.preventDefault(),n.name==="link"){const{from:y,to:a}=r.state.selection;if(y!==a||r.isActive("link")){if(p.current={from:y,to:a},r.isActive("link")){const l=r.state.selection.$head.marks().find(v=>v.type.name==="link");w.current=((o=l==null?void 0:l.attrs)==null?void 0:o.href)||"",M.current=!0}else w.current="",M.current=!1;if(!r.isActive("link")){const l=window.getSelection();if(l&&l.rangeCount>0){const D=l.getRangeAt(0).getBoundingClientRect();D.width>0&&D.height>0&&(m.current=D)}}}}},f=()=>{var o,y;const g=n.name;if(g==="getHTML"||g==="getJSON"||g==="importWord"||g==="importMarkdown"||g==="exportWord"||g==="exportMarkdown"||g==="snapshot"||g==="compare"||g==="fullscreen"||g==="autoFormat"){c==null||c(g);return}if(g==="link"){if(r.isActive("link")){if(!p.current){const{from:l,to:v}=r.state.selection;p.current={from:l,to:v}}const a=r.state.selection.$head.marks().find(l=>l.type.name==="link");if(w.current=((o=a==null?void 0:a.attrs)==null?void 0:o.href)||"",M.current=!0,!m.current&&p.current)try{const{from:l,to:v}=p.current,D=r.view.coordsAtPos(l),B=r.view.coordsAtPos(v);D&&B&&(m.current=new DOMRect(D.left,D.top,B.left-D.left,B.bottom-D.top))}catch{}d(!0);return}if(!p.current){const{from:a,to:l}=r.state.selection;if(a===l)return;p.current={from:a,to:l}}if(w.current="",M.current=!1,!m.current&&p.current)try{const{from:a,to:l}=p.current,v=r.view.coordsAtPos(a),D=r.view.coordsAtPos(l);v&&D&&(m.current=new DOMRect(v.left,v.top,D.left-v.left,v.bottom-v.top))}catch{}if(p.current){const{from:a,to:l}=p.current;r.chain().focus().setTextSelection({from:a,to:l}).setHighlight({color:at}).run()}d(!0);return}(y=n.command)==null||y.call(n,r)},S=g=>{if(p.current){const{from:o,to:y}=p.current,a=r.chain().focus().setTextSelection({from:o,to:y}).unsetHighlight();g?a.setLink({href:g}).run():a.unsetLink().run()}p.current=null,m.current=null,w.current="",M.current=!1},b=()=>{if(p.current){const{from:g,to:o}=p.current;r.chain().focus().setTextSelection({from:g,to:o}).unsetHighlight().run()}p.current=null,m.current=null,w.current="",M.current=!1},N=n.name==="getHTML"||n.name==="getJSON";return e.jsxs(e.Fragment,{children:[e.jsx("button",{className:`tp-toolbar-btn${u?" is-active":""}${N?" is-text-btn":""}`,disabled:h,title:i(n.titleKey),onMouseDown:T,onClick:f,children:n.name==="getHTML"?e.jsx("span",{className:"tp-toolbar-text",children:"HTML"}):n.name==="getJSON"?e.jsx("span",{className:"tp-toolbar-text",children:"JSON"}):e.jsx("span",{className:"tp-toolbar-icon",dangerouslySetInnerHTML:{__html:ge(n.name)}})}),e.jsx(it,{visible:x,targetRect:m.current,editor:r,savedSelection:p.current,initialUrl:w.current,isEditing:M.current,onConfirm:S,onCancel:b,onClose:()=>d(!1)})]})},Ke={SimSun:["SimSun","宋体"],宋体:["SimSun","宋体"],"Microsoft YaHei":["Microsoft YaHei","微软雅黑"],微软雅黑:["Microsoft YaHei","微软雅黑"],SimHei:["SimHei","黑体"],黑体:["SimHei","黑体"],KaiTi:["KaiTi","楷体"],楷体:["KaiTi","楷体"]},ut=({def:n,editor:r,active:u,disabled:h,onCustomClick:c})=>{var N;const{t:i}=de(),[x,d]=t.useState(!1),[p,m]=t.useState(0),w=t.useRef(null),M=t.useMemo(()=>{var g;return(g=n.getCurrentValue)==null?void 0:g.call(n,r)},[p,n,r]),T=g=>{const o=String(M),y=String(g);if(n.name==="fontFamily"){const a=Ke[o],l=Ke[y];if(a)return a.includes(y);if(l)return l.includes(o)}return o===y},f=g=>{const o=Number(g);return o===0?"tp-heading-preview-paragraph":o>=1&&o<=6?`tp-heading-preview-h${o}`:""},S=()=>{h||(d(!x),x||m(g=>g+1))},b=g=>{var o;n.isActionMenu?c==null||c(String(g)):(o=n.command)==null||o.call(n,r,g),d(!1)};return t.useEffect(()=>{const g=y=>{w.current&&!w.current.contains(y.target)&&d(!1)},o=()=>m(y=>y+1);return document.addEventListener("pointerdown",g),r.on("transaction",o),()=>{document.removeEventListener("pointerdown",g),r.off("transaction",o)}},[r]),e.jsxs("div",{ref:w,className:"tp-toolbar-dropdown",children:[e.jsxs("button",{className:`tp-toolbar-dropdown-trigger${u?" is-active":""}${h?" is-disabled":""}`,title:i(n.tooltipKey||n.titleKey),disabled:h,onMouseDown:g=>g.preventDefault(),onClick:S,children:[e.jsx("span",{className:"tp-toolbar-icon",dangerouslySetInnerHTML:{__html:ge(n.name)}}),!n.hideLabel&&e.jsx("span",{className:"tp-toolbar-dropdown-label",children:i(n.titleKey)}),e.jsx("span",{className:"tp-toolbar-dropdown-arrow",children:"▾"})]}),x&&e.jsx("div",{className:"tp-toolbar-dropdown-menu",children:(N=n.options)==null?void 0:N.map(g=>e.jsx("button",{className:`tp-toolbar-dropdown-item${T(g.value)?" is-active":""}${n.name==="heading"?" "+f(g.value):""}`,onMouseDown:o=>o.preventDefault(),onClick:()=>b(g.value),children:g.labelKey?i(g.labelKey):g.label},String(g.value)))})]})},dt=["#ffffff","#f3f3f3","#fce5cd","#c9daf8","#d0e0e3","#f4cccc","#d9ead3","#d9d2e9","#cfe2f3","#fff2cc","#efefef","#b7b7b7","#f6b26b","#6d9eeb","#a2c4c9","#ea9999","#b6d7a8","#b4a7d6","#9fc5e8","#ffe599","#d9d9d9","#999999","#e69138","#3c78d8","#76a5af","#e06666","#93c47d","#8e7cc3","#6fa8dc","#ffd966","#cccccc","#666666","#b45f06","#1155cc","#45818e","#cc0000","#6aa84f","#674ea7","#3d85c6","#f1c232","#b7b7b7","#434343","#783f04","#1c4587","#134f5c","#990000","#38761d","#351c75","#0b5394","#bf9000","#999999","#000000","#5b0f00","#073763","#0c343d","#660000","#274e13","#20124d","#073763","#7f6000"],pt=["#ff0000","#ff5e00","#ff9900","#ffff00","#00ff00","#00a8a8","#00ffff","#0000ff","#5f00ff","#9900ff"],ft=({def:n,editor:r,disabled:u})=>{const{t:h}=de(),[c,i]=t.useState(!1),x=t.useRef(null),[d,p]=t.useState(""),[m,w]=t.useState(""),M=n.name==="color",T=M?d:m,f=()=>{const N=r.getAttributes("textStyle");p((N==null?void 0:N.color)||"");const g=r.getAttributes("highlight");w((g==null?void 0:g.color)||"")};t.useEffect(()=>{const N=g=>{x.current&&!x.current.contains(g.target)&&i(!1)};return document.addEventListener("pointerdown",N),r.on("transaction",f),r.on("selectionUpdate",f),f(),()=>{document.removeEventListener("pointerdown",N),r.off("transaction",f),r.off("selectionUpdate",f)}},[r]);const S=N=>{var g;(g=n.command)==null||g.call(n,r,N),setTimeout(f,0),i(!1)},b=()=>{var N;(N=n.command)==null||N.call(n,r,void 0),w(""),i(!1)};return e.jsxs("div",{ref:x,className:"tp-toolbar-dropdown",children:[e.jsxs("button",{className:`tp-toolbar-dropdown-trigger${u?" is-disabled":""}`,title:h(n.titleKey),disabled:u,onMouseDown:N=>N.preventDefault(),onClick:()=>{u||i(!c)},children:[e.jsx("span",{className:M?"tp-color-picker-icon":"tp-bgcolor-picker-icon",children:M?e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("text",{x:"4",y:"17",fontSize:"24",fill:"currentColor",stroke:"none",fontFamily:"serif",fontWeight:"bold",children:"A"}),e.jsx("line",{x1:"4",y1:"22",x2:"20",y2:"22",strokeWidth:"5",stroke:d||"#000000"})]}):e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",fill:m||"transparent"}),e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("text",{x:"6",y:"17",fontSize:"16",fill:"currentColor",stroke:"none",fontFamily:"serif",fontWeight:"bold",children:"A"})]})}),e.jsx("span",{className:"tp-toolbar-dropdown-arrow",children:"▾"})]}),c&&e.jsxs("div",{className:"tp-color-picker-panel",children:[e.jsx("button",{className:"tp-color-default-btn",onMouseDown:N=>N.preventDefault(),onClick:b,children:h("common.default")}),e.jsx("div",{className:"tp-color-grid tp-theme-colors",children:dt.map((N,g)=>e.jsx("button",{className:`tp-color-swatch${T===N?" tp-color-swatch-selected":""}`,style:{backgroundColor:N},title:N,onMouseDown:o=>o.preventDefault(),onClick:()=>S(N)},`theme-${g}`))}),e.jsx("div",{className:"tp-color-section-label",children:h("common.standardColor")}),e.jsx("div",{className:"tp-color-grid tp-standard-colors",children:pt.map((N,g)=>e.jsx("button",{className:`tp-color-swatch${T===N?" tp-color-swatch-selected":""}`,style:{backgroundColor:N},title:N,onMouseDown:o=>o.preventDefault(),onClick:()=>S(N)},`std-${g}`))})]})]})},Je=()=>e.jsx("div",{className:"tp-toolbar-separator"}),ht=({visible:n,editor:r,uploadUrl:u,uploadHeaders:h,onUpload:c,initialTab:i,onClose:x})=>{const{t:d}=de(),[p,m]=t.useState(i||"upload"),[w,M]=t.useState(""),[T,f]=t.useState(!1),[S,b]=t.useState(!1),[N,g]=t.useState(0),[o,y]=t.useState(""),a=t.useRef(null);t.useEffect(()=>(n?(M(""),y(""),m(i||"upload"),g(0),document.body.style.overflow="hidden"):document.body.style.overflow="",()=>{document.body.style.overflow=""}),[n,i]);const l=k=>new Promise((L,E)=>{const $=new FileReader;$.onload=()=>L($.result),$.onerror=E,$.readAsDataURL(k)}),v=k=>{r.chain().focus().setImage({src:k}).run()},D=async k=>{b(!0),g(0),y("");try{let L;c?L=await c(k):u?L=await A.uploadFile(k,{url:u,headers:h,onProgress:g}):L=await l(k),v(L),x()}catch(L){y(L instanceof Error?L.message:d("imageUpload.uploadFailed"))}finally{b(!1),g(0)}},B=()=>{const k=w.trim();if(!k){y(d("imageUpload.urlRequired"));return}try{new URL(k)}catch{y(d("imageUpload.invalidUrl"));return}v(k),x()};return n?e.jsx("div",{className:"tp-image-upload-overlay",onMouseDown:k=>{k.target===k.currentTarget&&x()},children:e.jsxs("div",{className:"tp-image-upload-dialog",onMouseDown:k=>k.stopPropagation(),children:[e.jsxs("div",{className:"tp-dialog-header",children:[e.jsx("span",{className:"tp-dialog-title",children:d("image.upload")}),e.jsx("button",{className:"tp-dialog-close",onClick:x,children:"×"})]}),e.jsxs("div",{className:"tp-dialog-tabs",children:[e.jsx("button",{className:`tp-tab-btn${p==="upload"?" is-active":""}`,onClick:()=>m("upload"),children:d("imageUpload.uploadLocal")}),e.jsx("button",{className:`tp-tab-btn${p==="url"?" is-active":""}`,onClick:()=>m("url"),children:d("imageUpload.inputUrl")})]}),e.jsxs("div",{className:"tp-dialog-body",children:[p==="upload"&&e.jsxs("div",{className:"tp-upload-tab",children:[e.jsx("div",{className:`tp-dropzone${T?" is-dragging":""}${S?" is-uploading":""}`,onDragEnter:k=>{k.preventDefault(),f(!0)},onDragLeave:k=>{k.preventDefault(),f(!1)},onDragOver:k=>k.preventDefault(),onDrop:k=>{var E,$;k.preventDefault(),f(!1);const L=($=(E=k.dataTransfer)==null?void 0:E.files)==null?void 0:$[0];L!=null&&L.type.startsWith("image/")?D(L):y(d("imageUpload.invalidType"))},onClick:()=>{var k;return(k=a.current)==null?void 0:k.click()},children:S?e.jsxs("div",{className:"tp-upload-progress",children:[e.jsx("div",{className:"tp-progress-bar",children:e.jsx("div",{className:"tp-progress-fill",style:{width:N+"%"}})}),e.jsxs("span",{className:"tp-progress-text",children:[d("imageUpload.uploading")," ",N,"%"]})]}):e.jsxs("div",{className:"tp-dropzone-content",children:[e.jsx("span",{className:"tp-dropzone-icon",children:"📁"}),e.jsx("span",{className:"tp-dropzone-text",children:d("imageUpload.selectFile")}),e.jsx("span",{className:"tp-dropzone-hint",children:d("imageUpload.dragHint")})]})}),e.jsx("input",{ref:a,type:"file",accept:"image/*",style:{display:"none"},onChange:k=>{var E;const L=(E=k.target.files)==null?void 0:E[0];L&&D(L),k.target.value=""}})]}),p==="url"&&e.jsxs("div",{className:"tp-url-tab",children:[e.jsx("label",{className:"tp-input-label",children:d("imageUpload.url")}),e.jsxs("div",{className:"tp-input-row",children:[e.jsx("input",{className:"tp-url-input",type:"url",value:w,placeholder:d("imageUpload.placeholder"),onChange:k=>M(k.target.value),onKeyDown:k=>{k.key==="Enter"&&B(),k.key==="Escape"&&x()}}),e.jsx("button",{className:"tp-confirm-btn",onClick:B,children:d("common.confirm")})]})]}),o&&e.jsx("div",{className:"tp-error-message",children:o})]})]})}):null},mt=({def:n,editor:r,manager:u,active:h,disabled:c})=>{var g,o,y,a;const{t:i}=de(),[x,d]=t.useState(!1),[p,m]=t.useState(!1),[w,M]=t.useState("upload"),T=t.useRef(null),f=(g=u==null?void 0:u.getConfig().upload)==null?void 0:g.url,S=(o=u==null?void 0:u.getConfig().upload)==null?void 0:o.headers,b=(y=u==null?void 0:u.getConfig().upload)==null?void 0:y.onUpload;t.useEffect(()=>{const l=v=>{T.current&&!T.current.contains(v.target)&&d(!1)};return document.addEventListener("pointerdown",l),()=>document.removeEventListener("pointerdown",l)},[]);const N=l=>{d(!1),l==="upload"?(M("upload"),m(!0)):l==="url"&&(M("url"),m(!0))};return e.jsxs("div",{ref:T,className:"tp-toolbar-dropdown",children:[e.jsxs("button",{className:`tp-toolbar-dropdown-trigger${h?" is-active":""}${c?" is-disabled":""}`,title:i(n.titleKey),disabled:c,onMouseDown:l=>l.preventDefault(),onClick:()=>{c||d(!x)},children:[e.jsx("span",{className:"tp-toolbar-icon",dangerouslySetInnerHTML:{__html:ge(n.name)}}),e.jsx("span",{className:"tp-toolbar-dropdown-arrow",children:"▾"})]}),x&&e.jsx("div",{className:"tp-toolbar-dropdown-menu",children:(a=n.options)==null?void 0:a.map(l=>e.jsx("button",{className:"tp-toolbar-dropdown-item",onMouseDown:v=>v.preventDefault(),onClick:()=>N(l.value),children:l.labelKey?i(l.labelKey):l.label},String(l.value)))}),e.jsx(ht,{visible:p,editor:r,uploadUrl:f,uploadHeaders:S,onUpload:b,initialTab:w,onClose:()=>m(!1)})]})},xt=({visible:n,editor:r,onSuccess:u,onCancel:h,onClose:c})=>{const{t:i}=de(),[x,d]=t.useState(""),[p,m]=t.useState(""),w=t.useRef(null);t.useEffect(()=>(n?(d(""),m(""),document.body.style.overflow="hidden",setTimeout(()=>{var b;return(b=w.current)==null?void 0:b.focus()},100)):document.body.style.overflow="",()=>{document.body.style.overflow=""}),[n]);const M=t.useCallback(()=>{const b=x.trim();if(!b){m(i("video.urlRequired"));return}try{new URL(b)}catch{m(i("video.invalidUrl"));return}r.chain().focus().setVideo({src:b}).run(),u==null||u(b),c()},[x,r,i,u,c]),T=t.useCallback(()=>{h==null||h(),c()},[h,c]),f=t.useCallback(b=>{b.target===b.currentTarget&&T()},[T]),S=t.useCallback(b=>{b.key==="Enter"?(b.preventDefault(),M()):b.key==="Escape"&&(b.preventDefault(),T())},[M,T]);return n?Ee.createPortal(e.jsx("div",{className:"tp-video-dialog-overlay",onMouseDown:f,children:e.jsxs("div",{className:"tp-video-dialog",onMouseDown:b=>b.stopPropagation(),onKeyDown:S,children:[e.jsxs("div",{className:"tp-dialog-header",children:[e.jsx("span",{className:"tp-dialog-title",children:i("video.title")}),e.jsx("button",{className:"tp-dialog-close",onClick:T,children:"×"})]}),e.jsxs("div",{className:"tp-dialog-body",children:[e.jsx("label",{className:"tp-input-label",children:i("video.url")}),e.jsxs("div",{className:"tp-input-row",children:[e.jsx("input",{ref:w,type:"url",className:"tp-url-input",placeholder:i("video.placeholder"),value:x,onChange:b=>d(b.target.value),onKeyDown:S}),e.jsx("button",{className:"tp-confirm-btn",onClick:M,children:i("common.confirm")})]}),e.jsx("p",{className:"tp-hint",children:i("video.hint")}),p&&e.jsx("div",{className:"tp-error-message",children:p})]})]})}),document.body):null},gt=({def:n,editor:r,active:u,disabled:h})=>{const{t:c}=de(),[i,x]=t.useState(!1),d=()=>{h||x(!0)};return e.jsxs("div",{className:"tp-toolbar-video-btn",children:[e.jsx("button",{className:`tp-toolbar-btn${u?" is-active":""}${h?" is-disabled":""}`,title:c(n.titleKey),disabled:h,onMouseDown:p=>p.preventDefault(),onClick:d,children:e.jsx("span",{className:"tp-toolbar-icon",dangerouslySetInnerHTML:{__html:ge(n.name)}})}),e.jsx(xt,{visible:i,editor:r,onSuccess:()=>{},onClose:()=>x(!1)})]})},wt=10,vt=10,bt=({def:n,editor:r,active:u,disabled:h})=>{const{t:c}=de(),[i,x]=t.useState(!1),[d,p]=t.useState({row:0,col:0}),m=t.useRef(null),w=()=>{h||(x(!i),p({row:0,col:0}))},M=(f,S)=>{p({row:f,col:S})},T=(f,S)=>{r.chain().focus().insertTable({rows:f,cols:S,withHeaderRow:!0}).run(),x(!1),p({row:0,col:0})};return t.useEffect(()=>{const f=S=>{m.current&&!m.current.contains(S.target)&&(x(!1),p({row:0,col:0}))};return document.addEventListener("pointerdown",f),()=>document.removeEventListener("pointerdown",f)},[]),e.jsxs("div",{ref:m,className:"tp-toolbar-dropdown",children:[e.jsxs("button",{className:`tp-toolbar-dropdown-trigger${u?" is-active":""}${h?" is-disabled":""}`,title:c(n.titleKey),disabled:h,onMouseDown:f=>f.preventDefault(),onClick:w,children:[e.jsx("span",{className:"tp-toolbar-icon",dangerouslySetInnerHTML:{__html:ge(n.name)}}),e.jsx("span",{className:"tp-toolbar-dropdown-arrow",children:"▾"})]}),i&&e.jsxs("div",{className:"tp-table-grid-dropdown",children:[e.jsx("div",{className:"tp-table-grid-header",children:d.row>0?`${d.row} × ${d.col}`:c("table.insertHint")}),e.jsx("div",{className:"tp-table-grid",children:Array.from({length:wt},(f,S)=>e.jsx("div",{className:"tp-table-grid-row",children:Array.from({length:vt},(b,N)=>{const g=S+1,o=N+1;return e.jsx("div",{className:`tp-table-grid-cell${g<=d.row&&o<=d.col?" is-hovered":""}${g===d.row&&o===d.col?" is-selected":""}`,onMouseEnter:()=>M(g,o),onClick:()=>T(g,o)},`${g}-${o}`)})},S))})]})]})},yt=({editor:n,disabled:r=!1})=>{const{t:u}=de(),h=t.useRef("none"),[c,i]=t.useState("none"),x=t.useRef([]),d=t.useRef(null),p=t.useRef(null),m=t.useRef(null),w=t.useRef(void 0),M=t.useRef(null),T=t.useRef(0),f=t.useRef(!1),S=c!=="none",b=t.useCallback(()=>{const{from:L,to:E}=n.state.selection;if(n.isActive("orderedList"))return"orderedList";if(n.isActive("bulletList"))return"bulletList";const $=Math.min(L+1,E),U=n.state.doc.resolve($);if(U.parent.type.name==="listItem")for(let W=U.depth;W>0;W--){const F=U.node(W);if(F.type.name==="orderedList")return"orderedList";if(F.type.name==="bulletList")return"bulletList"}return null},[n]),N=t.useCallback(()=>{const{from:L,to:E}=n.state.selection;if(n.isActive("orderedList")||n.isActive("bulletList"))return;for(let W=1;W<=6;W++)if(n.isActive("heading",{level:W}))return W;const $=Math.min(L+1,E);if(n.state.doc.resolve($).parent.type.name==="paragraph")return null},[n]),g=t.useCallback(()=>{const{from:L,to:E,empty:$}=n.state.selection;if($)return!1;const P=n.state.doc.resolve(Math.min(L+1,E)).marks();x.current=[...P];const W=b();d.current=W;const F=n.getAttributes("textStyle");p.current={color:F.color,fontFamily:F.fontFamily,fontSize:F.fontSize};const H=n.getAttributes("paragraph"),_=n.getAttributes("heading");m.current={textAlign:H.textAlign||_.textAlign,lineHeight:H.lineHeight||_.lineHeight},w.current=N();const I=P.length>0,O=!!F.color||!!F.fontFamily||!!F.fontSize,G=!!m.current.textAlign||!!m.current.lineHeight;return I||O||G||W!==null||w.current!==void 0},[n,b,N]),o=t.useCallback(()=>{if(!d.current)return;const L=n.chain().focus();switch(d.current){case"orderedList":n.isActive("orderedList")||(n.isActive("bulletList")&&L.toggleBulletList(),L.toggleOrderedList().run());break;case"bulletList":n.isActive("bulletList")||(n.isActive("orderedList")&&L.toggleOrderedList(),L.toggleBulletList().run());break}},[n]),y=t.useCallback(()=>{if(w.current===void 0)return;const L=n.chain().focus();if(w.current===null)L.setParagraph().run();else{const{schema:E}=n.state;E.nodes.heading&&L.setNode("heading",{level:w.current}).run()}},[n]),a=t.useCallback(()=>{let{state:L}=n,{from:E,to:$,empty:U}=L.selection;if(U)return!1;const{schema:P}=L;if(d.current?o():w.current!==void 0&&y(),m.current){const I=n.chain().focus();m.current.textAlign&&I.setTextAlign(m.current.textAlign),m.current.lineHeight&&I.setLineHeight(m.current.lineHeight),I.run()}L=n.state;const W=L.selection;if(E=W.from,$=W.to,x.current.length===0&&!p.current)return d.current!==null||m.current!==null||w.current!==void 0;const F=L.tr,H=[];if(x.current.forEach(I=>{const O=I.type.name;["bold","italic","underline","strike","superscript","subscript"].includes(O)&&H.push(I)}),p.current){const{color:I,fontFamily:O,fontSize:G}=p.current,X={};if(I&&(X.color=I),O&&(X.fontFamily=O),G&&(X.fontSize=G),Object.keys(X).length>0&&P.marks.textStyle){const he=P.marks.textStyle.create(X);H.push(he)}}const _=x.current.find(I=>I.type.name==="highlight");return _&&H.push(_),H.length===0||(L.doc.nodesBetween(E,$,(I,O)=>{if(I.isText&&O<$&&O+I.nodeSize>E){const G=Math.max(O,E),X=Math.min(O+I.nodeSize,$);["bold","italic","underline","strike","superscript","subscript","textStyle","highlight"].forEach(Q=>{const ae=P.marks[Q];ae&&I.marks.some(le=>le.type===ae)&&F.removeMark(G,X,ae)}),H.forEach(Q=>{F.addMark(G,X,Q)})}}),F.docChanged&&n.view.dispatch(F)),!0},[n,o,y]),l=t.useCallback(()=>{h.current="none",i("none"),x.current=[],d.current=null,p.current=null,m.current=null,w.current=void 0},[]),v=t.useCallback(()=>{if(h.current==="none")return;const{empty:L}=n.state.selection;L||(a(),h.current==="single"&&l())},[n,a,l]),D=t.useCallback(()=>{if(h.current==="single"||h.current==="multiple"){l();return}g()&&(h.current="single",i("single"))},[g,l]),B=t.useCallback(()=>{if(h.current==="multiple"){l();return}g()&&(h.current="multiple",i("multiple"))},[g,l]),k=t.useCallback(()=>{r||(T.current++,T.current===1?M.current=window.setTimeout(()=>{D(),T.current=0,M.current=null},250):T.current===2&&(M.current&&(clearTimeout(M.current),M.current=null),B(),T.current=0))},[D,B]);return t.useEffect(()=>{r&&(l(),M.current&&(clearTimeout(M.current),M.current=null),T.current=0)},[r,l]),t.useEffect(()=>{const L=P=>{h.current==="none"||P.target.closest(".tp-toolbar-btn")||(f.current=!0)},E=P=>{!f.current||(f.current=!1,h.current==="none")||P.target.closest(".tp-toolbar-btn")||requestAnimationFrame(()=>v())},$=P=>{P.key==="Escape"&&h.current!=="none"&&l()},U=P=>{if(h.current==="none")return;const W=["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"];P.shiftKey&&W.includes(P.key)&&v()};return document.addEventListener("mousedown",L),document.addEventListener("mouseup",E),document.addEventListener("keydown",$),document.addEventListener("keyup",U),()=>{document.removeEventListener("mousedown",L),document.removeEventListener("mouseup",E),document.removeEventListener("keydown",$),document.removeEventListener("keyup",U),M.current&&clearTimeout(M.current)}},[v,l]),e.jsxs("button",{className:`tp-toolbar-btn${S?" is-active":""}${c==="multiple"?" is-locked":""}${r?" is-disabled":""}`,disabled:r,title:u("toolbar.formatPainter"),onClick:k,style:{position:"relative"},children:[e.jsx("span",{className:"tp-toolbar-icon",dangerouslySetInnerHTML:{__html:ge("formatPainter")}}),c==="multiple"&&e.jsx("span",{className:"tp-format-painter-indicator",children:"🔒"})]})},kt=[{type:"decimal",lines:["1.","2.","3."]},{type:"decimal-leading-zero",lines:["01.","02.","03."]},{type:"lower-roman",lines:["i.","ii.","iii."]},{type:"upper-roman",lines:["I.","II.","III."]},{type:"lower-alpha",lines:["a.","b.","c."]},{type:"upper-alpha",lines:["A.","B.","C."]}],Ct=({def:n,editor:r,active:u,disabled:h})=>{const{t:c}=de(),[i,x]=t.useState(!1),[d,p]=t.useState(0),m=t.useRef(null),w=()=>{const{state:a}=r,l=a.selection.$from;let v=null,D=0;for(let B=l.depth;B>=0;B--){const k=l.node(B);k.type.name==="orderedList"&&(v||(v=k),D++)}return{node:v,depth:D}},M=(()=>{const{node:a,depth:l}=w();return a&&a.attrs.listStyleType?a.attrs.listStyleType:l<=1?"decimal":l===2?"lower-alpha":"lower-roman"})(),T=(()=>{const{node:a}=w(),l=a==null?void 0:a.attrs.start;return l!=null?Number(l):1})(),f=(()=>{const{node:a}=w();return!!(a!=null&&a.attrs.reversed)})(),S=t.useCallback(()=>{var a;(a=n.command)==null||a.call(n,r)},[n,r]),b=t.useCallback(()=>{h||x(a=>!a)},[h]),N=t.useCallback(a=>{r.commands.createStyledOrderedList({listStyleType:a}),r.commands.focus(),x(!1)},[r]),g=t.useCallback(a=>{const l=parseInt(a.target.value,10);isNaN(l)||r.commands.setOrderedListAttrs({start:l})},[r]),o=t.useCallback(a=>{["Backspace","Delete","ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Tab","Home","End"].includes(a.key)||a.key==="-"||a.key==="Minus"||a.key>="0"&&a.key<="9"||a.ctrlKey||a.metaKey||a.preventDefault()},[]),y=t.useCallback(()=>{const a=!f;r.commands.setOrderedListAttrs({reversed:a||null})},[r,f]);return t.useEffect(()=>{const a=v=>{m.current&&!m.current.contains(v.target)&&x(!1)},l=()=>p(v=>v+1);return document.addEventListener("pointerdown",a),r.on("transaction",l),()=>{document.removeEventListener("pointerdown",a),r.off("transaction",l)}},[r]),e.jsxs("div",{ref:m,className:"tp-toolbar-split-btn",children:[e.jsx("button",{className:`tp-toolbar-split-main${u?" is-active":""}`,title:c(n.titleKey),disabled:h,onMouseDown:a=>a.preventDefault(),onClick:S,children:e.jsx("span",{className:"tp-toolbar-icon",dangerouslySetInnerHTML:{__html:ge(n.name)}})}),e.jsx("button",{className:`tp-toolbar-split-arrow${i?" is-open":""}`,disabled:h,onMouseDown:a=>a.preventDefault(),onClick:b,children:"▾"}),i&&e.jsxs("div",{className:"tp-ol-panel",children:[e.jsx("div",{className:"tp-ol-style-grid",children:kt.map(a=>e.jsx("button",{className:`tp-ol-style-item${M===a.type?" is-active":""}`,onMouseDown:l=>l.preventDefault(),onClick:()=>N(a.type),children:a.lines.map((l,v)=>e.jsxs("span",{className:"tp-ol-style-line",children:[e.jsx("span",{className:"tp-ol-style-marker",children:l}),e.jsx("span",{className:"tp-ol-style-bar"})]},v))},a.type))}),e.jsxs("div",{className:"tp-ol-properties",children:[e.jsx("div",{className:"tp-ol-prop-title",children:c("orderedList.properties")}),e.jsxs("div",{className:"tp-ol-prop-row",children:[e.jsx("label",{children:c("orderedList.startAt")}),e.jsx("input",{type:"number",className:"tp-ol-start-input",defaultValue:T,onChange:g,onKeyDown:o,onMouseDown:a=>a.stopPropagation()})]}),e.jsxs("div",{className:"tp-ol-prop-row",children:[e.jsx("label",{children:c("orderedList.reversed")}),e.jsx("button",{className:`tp-ol-toggle${f?" is-on":""}`,onMouseDown:a=>a.preventDefault(),onClick:y})]})]})]})]})},jt=[{type:"disc",marker:"●"},{type:"circle",marker:"○"},{type:"square",marker:"■"},{type:"none",marker:"—"}],Nt=({def:n,editor:r,active:u,disabled:h})=>{const{t:c}=de(),[i,x]=t.useState(!1),[d,p]=t.useState(0),m=t.useRef(null),w=(()=>{const{state:S}=r,b=S.selection.$from;let N=null,g=0;for(let o=b.depth;o>=0;o--){const y=b.node(o);y.type.name==="bulletList"&&(N||(N=y),g++)}return N&&N.attrs.listStyleType?N.attrs.listStyleType:g<=1?"disc":g===2?"circle":"square"})(),M=t.useCallback(()=>{var S;(S=n.command)==null||S.call(n,r)},[n,r]),T=t.useCallback(()=>{h||x(S=>!S)},[h]),f=t.useCallback(S=>{r.commands.createStyledBulletList({listStyleType:S}),r.commands.focus(),x(!1)},[r]);return t.useEffect(()=>{const S=N=>{m.current&&!m.current.contains(N.target)&&x(!1)},b=()=>p(N=>N+1);return document.addEventListener("pointerdown",S),r.on("transaction",b),()=>{document.removeEventListener("pointerdown",S),r.off("transaction",b)}},[r]),e.jsxs("div",{ref:m,className:"tp-toolbar-split-btn",children:[e.jsx("button",{className:`tp-toolbar-split-main${u?" is-active":""}`,title:c(n.titleKey),disabled:h,onMouseDown:S=>S.preventDefault(),onClick:M,children:e.jsx("span",{className:"tp-toolbar-icon",dangerouslySetInnerHTML:{__html:ge(n.name)}})}),e.jsx("button",{className:`tp-toolbar-split-arrow${i?" is-open":""}`,disabled:h,onMouseDown:S=>S.preventDefault(),onClick:T,children:"▾"}),i&&e.jsx("div",{className:"tp-ol-panel",children:e.jsx("div",{className:"tp-ol-style-grid tp-ul-style-grid",children:jt.map(S=>e.jsx("button",{className:`tp-ol-style-item${w===S.type?" is-active":""}`,onMouseDown:b=>b.preventDefault(),onClick:()=>f(S.type),children:[0,1,2].map(b=>e.jsxs("span",{className:"tp-ol-style-line",children:[e.jsx("span",{className:"tp-ul-style-marker",children:S.marker}),e.jsx("span",{className:"tp-ol-style-bar"})]},b))},S.type))})})]})};function qe(n){return n==="meta-left"?"tp-toolbar-capsule tp-toolbar-capsule-left":n==="meta-io"?"tp-toolbar-capsule tp-toolbar-capsule-io":n==="meta-view"?"tp-toolbar-capsule tp-toolbar-capsule-view":""}const Mt=({items:n,manager:r,activeStates:u,disabledStates:h,viewMode:c="normal",onToggleViewMode:i,onToolbarClick:x,prepend:d,append:p})=>{const m=()=>r.getEditor(),w=t.useRef(null);t.useEffect(()=>A.installToolbarPanelPlacement(w.current,{getEditor:m}),[]);const M=t.useCallback(o=>{if(o==="getHTML"){i==null||i("html");return}if(o==="getJSON"){i==null||i("json");return}x==null||x(o)},[i,x]),T=o=>c!=="normal"?o==="getHTML"?c==="html":o==="getJSON"?c==="json":!1:o==="getHTML"||o==="getJSON"?!1:u[o]??!1,f=o=>c!=="normal"?o!=="getHTML"&&o!=="getJSON":h[o]??!1,S=t.useMemo(()=>A.groupToolbarItems(n),[n]),b=S.filter(o=>o.category==="meta-left"||o.category==="content"),N=S.filter(o=>o.category==="meta-io"||o.category==="meta-view");function g(o){const y=A.getToolbarItemDef(o);if(!y)return null;const a=m();return o==="imageUpload"?e.jsx(mt,{def:y,editor:a,manager:r,active:T(o),disabled:f(o)},o):o==="video"?e.jsx(gt,{def:y,editor:a,active:T(o),disabled:f(o)},o):o==="insertTable"?e.jsx(bt,{def:y,editor:a,active:T(o),disabled:f(o)},o):o==="formatPainter"?e.jsx(yt,{editor:a,disabled:f(o)},o):o==="orderedList"?e.jsx(Ct,{def:y,editor:a,active:T(o),disabled:f(o)},o):o==="bulletList"?e.jsx(Nt,{def:y,editor:a,active:T(o),disabled:f(o)},o):y.type==="button"?e.jsx(ct,{def:y,editor:a,active:T(o),disabled:f(o),onCustomClick:M},o):y.type==="dropdown"?e.jsx(ut,{def:y,editor:a,active:T(o),disabled:f(o),onCustomClick:M},o):y.type==="color-picker"?e.jsx(ft,{def:y,editor:a,disabled:f(o)},o):null}return e.jsxs("div",{className:"tp-toolbar",ref:w,children:[d,b.map((o,y)=>e.jsxs(t.Fragment,{children:[y>0&&e.jsx(Je,{}),o.category!=="content"?e.jsx("div",{className:qe(o.category),children:o.items.map(g)}):e.jsx(e.Fragment,{children:o.items.map(g)})]},`g-${y}`)),N.length>0&&e.jsx("div",{className:"tp-toolbar-right",children:N.map((o,y)=>e.jsxs(t.Fragment,{children:[y>0&&e.jsx(Je,{}),e.jsx("div",{className:qe(o.category),children:o.items.map(g)})]},`r-${y}`))}),p]})},Ze=({editor:n,visible:r,position:u,targetCell:h,onVisibleChange:c,onAction:i})=>{const x=t.useRef(null),[d,p]=t.useState({x:0,y:0}),[m,w]=t.useState(0),[M,T]=t.useState(!1),[f,S]=t.useState(!1),b=t.useRef({x:0,y:0}),N=A.I18nManager.getInstance(),g=a=>N.t(a),o=t.useCallback(a=>{if(!x.current)return null;const l=x.current,v=l.getBoundingClientRect(),D=l.offsetHeight-l.clientHeight,B=Math.max(v.height,l.scrollHeight+D);return v.width===0||B===0?null:A.adjustMenuPosition({x:a.x,y:a.y,width:v.width,height:B})},[]);t.useEffect(()=>{if(r){if(p({x:u.x,y:u.y}),h){const a=h.getBoundingClientRect();b.current={x:u.x-a.left,y:u.y-a.top}}T(n.can().mergeCells()),S(n.can().splitCell())}},[r,u,h,n]),t.useLayoutEffect(()=>{if(!r||!x.current)return;const a=o(d);a&&((a.x!==d.x||a.y!==d.y)&&p({x:a.x,y:a.y}),w(a.maxHeight))},[r,d,o]),t.useEffect(()=>{var B,k;const a=()=>{if(!r||!h)return;const L=h.getBoundingClientRect(),E=A.getVisualBand();if(L.bottom<E.top||L.top>E.bottom){c(!1);return}const $={x:L.left+b.current.x,y:L.top+b.current.y},U=o($);U&&(p({x:U.x,y:U.y}),w(U.maxHeight))},l=L=>{const E=L.target;return!!E&&typeof E.closest=="function"&&!!E.closest(".tp-table-context-menu")},v=L=>{r&&!l(L)&&a()},D=()=>{r&&a()};return window.addEventListener("scroll",v,!0),window.addEventListener("wheel",v,{passive:!0}),window.addEventListener("resize",D),(B=window.visualViewport)==null||B.addEventListener("resize",D),(k=window.visualViewport)==null||k.addEventListener("scroll",D),()=>{var L,E;window.removeEventListener("scroll",v,!0),window.removeEventListener("wheel",v),window.removeEventListener("resize",D),(L=window.visualViewport)==null||L.removeEventListener("resize",D),(E=window.visualViewport)==null||E.removeEventListener("scroll",D)}},[r,h,c,o]),t.useEffect(()=>{const a=v=>{x.current&&!x.current.contains(v.target)&&c(!1)},l=v=>{v.key==="Escape"&&c(!1)};return document.addEventListener("click",a),document.addEventListener("keydown",l),()=>{document.removeEventListener("click",a),document.removeEventListener("keydown",l)}},[c]);const y=t.useCallback(a=>{i(a),c(!1)},[i,c]);return r?Ee.createPortal(e.jsxs("div",{ref:x,className:"tp-table-context-menu",style:{left:d.x,top:d.y,maxHeight:m>0?m:void 0},onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{className:"tp-table-menu-section",children:[e.jsx("div",{className:"tp-table-menu-item",onClick:()=>y("addRowBefore"),children:g("table.addRowBefore")}),e.jsx("div",{className:"tp-table-menu-item",onClick:()=>y("addRowAfter"),children:g("table.addRowAfter")}),e.jsx("div",{className:"tp-table-menu-item",onClick:()=>y("addColumnBefore"),children:g("table.addColumnBefore")}),e.jsx("div",{className:"tp-table-menu-item",onClick:()=>y("addColumnAfter"),children:g("table.addColumnAfter")})]}),e.jsx("div",{className:"tp-table-menu-divider"}),e.jsxs("div",{className:"tp-table-menu-section",children:[e.jsx("div",{className:"tp-table-menu-item",onClick:()=>y("selectRow"),children:g("table.selectRow")}),e.jsx("div",{className:"tp-table-menu-item",onClick:()=>y("selectColumn"),children:g("table.selectColumn")}),e.jsx("div",{className:"tp-table-menu-item",onClick:()=>y("selectTable"),children:g("table.selectTable")}),e.jsx("div",{className:"tp-table-menu-item",onClick:()=>y("extendSelection"),children:g("table.extendSelection")})]}),e.jsx("div",{className:"tp-table-menu-divider"}),e.jsxs("div",{className:"tp-table-menu-section",children:[e.jsx("div",{className:`tp-table-menu-item${M?"":" disabled"}`,onClick:()=>M&&y("mergeCells"),children:g("table.mergeCells")}),e.jsx("div",{className:`tp-table-menu-item${f?"":" disabled"}`,onClick:()=>f&&y("splitCell"),children:g("table.splitCell")})]}),e.jsx("div",{className:"tp-table-menu-divider"}),e.jsxs("div",{className:"tp-table-menu-section",children:[e.jsx("div",{className:"tp-table-menu-item",onClick:()=>y("deleteRow"),children:g("table.deleteRow")}),e.jsx("div",{className:"tp-table-menu-item",onClick:()=>y("deleteColumn"),children:g("table.deleteColumn")}),e.jsx("div",{className:"tp-table-menu-item tp-table-menu-item-danger",onClick:()=>y("deleteTable"),children:g("table.deleteTable")})]}),e.jsx("div",{className:"tp-table-menu-divider"}),e.jsxs("div",{className:"tp-table-menu-section",children:[e.jsx("div",{className:"tp-table-menu-item",onClick:()=>y("tableSettings"),children:g("table.tableSettings")}),e.jsx("div",{className:"tp-table-menu-item",onClick:()=>y("cellSettings"),children:g("table.cellSettings")})]})]}),document.body):null},St=["#000000","#1a1a1a","#333333","#4d4d4d","#666666","#808080","#999999","#b3b3b3","#1c4587","#1155cc","#3d85c6","#6fa8dc","#0b5394","#073763","#38761d","#6aa84f","#93c47d","#274e13","#990000","#cc0000","#e06666","#660000"],Lt=["#ffffff","#f8f9fa","#f1f3f4","#e8eaed","#dadce0","#bdc1c6","#e6f4ea","#ceead6","#a8dab5","#81c995","#e8f0fe","#d2e3fc","#aecbfa","#8ab4f8","#fef7e0","#feefc3","#fde293","#fdd663","#fce8e6","#fadbd8","#f5aca6","#f28b82"];function Tt(n){const r=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(n);return r?{r:parseInt(r[1],16),g:parseInt(r[2],16),b:parseInt(r[3],16)}:null}function We(n,r,u){return"#"+[n,r,u].map(h=>{const c=Math.round(Math.max(0,Math.min(255,h))).toString(16);return c.length===1?"0"+c:c}).join("")}function Ue(n,r,u){n/=255,r/=255,u/=255;const h=Math.max(n,r,u),c=Math.min(n,r,u);let i=0,x=0;const d=(h+c)/2;if(h!==c){const p=h-c;switch(x=d>.5?p/(2-h-c):p/(h+c),h){case n:i=((r-u)/p+(r<u?6:0))/6;break;case r:i=((u-n)/p+2)/6;break;case u:i=((n-r)/p+4)/6;break}}return{h:Math.round(i*360),s:Math.round(x*100),l:Math.round(d*100)}}function Ve(n,r,u){n/=255,r/=255,u/=255;const h=Math.max(n,r,u),c=Math.min(n,r,u);let i=0;const x=h,d=h-c,p=h===0?0:d/h;if(h!==c)switch(h){case n:i=((r-u)/d+(r<u?6:0))/6;break;case r:i=((u-n)/d+2)/6;break;case u:i=((n-r)/d+4)/6;break}return{h:Math.round(i*360),s:Math.round(p*100),v:Math.round(x*100)}}function Et(n,r,u){r/=100,u/=100;const h=Math.floor(n/60)%6,c=n/60-Math.floor(n/60),i=u*(1-r),x=u*(1-c*r),d=u*(1-(1-c)*r);let p=0,m=0,w=0;switch(h){case 0:p=u,m=d,w=i;break;case 1:p=x,m=u,w=i;break;case 2:p=i,m=u,w=d;break;case 3:p=i,m=x,w=u;break;case 4:p=d,m=i,w=u;break;case 5:p=u,m=i,w=x;break}return{r:Math.round(p*255),g:Math.round(m*255),b:Math.round(w*255)}}function Rt(n,r,u){n/=360,r/=100,u/=100;let h,c,i;if(r===0)h=c=i=u;else{const x=(m,w,M)=>(M<0&&(M+=1),M>1&&(M-=1),M<.16666666666666666?m+(w-m)*6*M:M<.5?w:M<.6666666666666666?m+(w-m)*(.6666666666666666-M)*6:m),d=u<.5?u*(1+r):u+r-u*r,p=2*u-d;h=x(p,d,n+1/3),c=x(p,d,n),i=x(p,d,n-1/3)}return{r:Math.round(h*255),g:Math.round(c*255),b:Math.round(i*255)}}const Ie=t.forwardRef(({value:n,onChange:r,placeholder:u,mode:h="border",beforeOpen:c,onClose:i},x)=>{const[d,p]=t.useState(!1),m=t.useRef(null),w=t.useRef(null),M=t.useRef(null),T=t.useRef(null),f=t.useRef(null),[S,b]=t.useState(-1e4),[N,g]=t.useState(-1e4),[o,y]=t.useState(n),[a,l]=t.useState(n),v=t.useRef(n),[D,B]=t.useState("hex"),[k,L]=t.useState({h:0,s:100,v:100}),[E,$]=t.useState({r:0,g:0,b:0}),[U,P]=t.useState({h:0,s:0,l:0}),[W,F]=t.useState(!1),[H,_]=t.useState(!1),[I,O]=t.useState(!1),G=t.useCallback(()=>{let s=0;const R=3,Y=()=>{if(s>=R*2){O(!1);return}O(ce=>!ce),s++,setTimeout(Y,100)};Y()},[]);t.useImperativeHandle(x,()=>({triggerButtonFlash:G}));const X=t.useMemo(()=>h==="background"?Lt:St,[h]),he=a||"#d9d9d9",Q=t.useCallback(s=>{y(s),l(s);const R=Tt(s);R&&($(R),P(Ue(R.r,R.g,R.b)),L(Ve(R.r,R.g,R.b)))},[]),ae=t.useCallback(()=>{const s=Et(k.h,k.s,k.v),R=We(s.r,s.g,s.b);$(s),P(Ue(s.r,s.g,s.b)),y(R),l(R)},[k]);t.useEffect(()=>{Q(n)},[n,Q]),t.useEffect(()=>{ae()},[k,ae]);const le=t.useCallback(s=>{let R=s.parentElement;for(;R;){const Y=window.getComputedStyle(R);if(Y.overflowY==="auto"||Y.overflowY==="scroll")return R;R=R.parentElement}return null},[]),z=t.useCallback(()=>{if(!d||!w.current||!M.current||!m.current)return;const s=w.current,R=M.current,Y=m.current,ce=s.getBoundingClientRect(),ue=R.getBoundingClientRect(),ve=Y.getBoundingClientRect();if(ve.width===0&&ve.height===0){requestAnimationFrame(z);return}const Ne=window.innerWidth,He=window.innerHeight,re=8,Me=10,Se=Me/2,Le=ce.width||260,Ae=ce.height||348;s.style.maxHeight="",s.style.overflowY="";let Te=ue.top,me,be="right";if(ue.right+re+Le<=Ne-re)me=ue.right+re,be="right";else if(ue.left-Le-re>=re)me=ue.left-Le-re,be="left";else{const ee=Ne-ue.right-re,q=ue.left-re;ee>=q?(me=Math.max(re,Ne-Le-re),be="right"):(me=re,be="left")}Te+Ae>He-re&&(Te=Math.max(re,He-Ae-re)),b(Te),g(me),s.dataset.placement=be;let C=ue.top+ue.height/2-Te-Se;const j=re,K=Math.max(j,Ae-Me-re);C=Math.max(j,Math.min(K,C)),s.style.setProperty("--triangle-top",`${C}px`)},[d]);t.useEffect(()=>{if(!d)return;const s=requestAnimationFrame(z),R=w.current,Y=R?le(R):null,ce=()=>requestAnimationFrame(z);return Y&&Y.addEventListener("scroll",ce,!0),()=>{cancelAnimationFrame(s),Y&&Y.removeEventListener("scroll",ce,!0)}},[d,z,le]),t.useEffect(()=>{d&&requestAnimationFrame(z)},[D,d,z]);const Z=t.useCallback(()=>{if(d)i==null||i();else{if(c&&c()===!1)return;v.current=n,l(n),Q(n)}p(!d)},[d,n,Q,c,i]),V=t.useCallback(s=>{Q(s)},[Q]),J=t.useCallback(s=>{const R=s.target.value;y(R),(/^#[0-9A-Fa-f]{6}$/.test(R)||/^#[0-9A-Fa-f]{3}$/.test(R))&&Q(R)},[Q]),pe=t.useCallback(()=>{o!==a&&(/^#[0-9A-Fa-f]{6}$/.test(o)||/^#[0-9A-Fa-f]{3}$/.test(o)?Q(o):(y(a),Q(a)))},[o,a,Q]),ke=t.useCallback(()=>{const s=We(E.r,E.g,E.b);y(s),l(s),P(Ue(E.r,E.g,E.b)),L(Ve(E.r,E.g,E.b))},[E]),Re=t.useCallback(()=>{const s=Rt(U.h,U.s,U.l),R=We(s.r,s.g,s.b);y(R),l(R),$(s),L(Ve(s.r,s.g,s.b))},[U]),Ce=t.useCallback(s=>{if(!T.current)return;const R=T.current.getBoundingClientRect();let Y=Math.max(0,Math.min(100,(s.clientX-R.left)/R.width*100)),ce=Math.max(0,Math.min(100,(s.clientY-R.top)/R.height*100));L(ue=>({...ue,s:Y,v:100-ce}))},[]),xe=t.useCallback(s=>{F(!0),Ce(s.nativeEvent)},[Ce]),we=t.useCallback(s=>{if(!f.current)return;const R=f.current.getBoundingClientRect();let Y=Math.max(0,Math.min(360,(s.clientX-R.left)/R.width*360));L(ce=>({...ce,h:Y}))},[]),je=t.useCallback(s=>{_(!0),we(s.nativeEvent)},[we]);t.useEffect(()=>{const s=Y=>{W&&Ce(Y),H&&we(Y)},R=()=>{F(!1),_(!1)};return document.addEventListener("mousemove",s),document.addEventListener("mouseup",R),()=>{document.removeEventListener("mousemove",s),document.removeEventListener("mouseup",R)}},[W,H,Ce,we]),t.useEffect(()=>{const s=Y=>{if(m.current&&!m.current.contains(Y.target)&&d){const ce=Y.target,ue=ce.closest?ce.closest(".tp-color-picker-input"):null;if(ue&&ue!==m.current)return;Y.stopPropagation(),Y.preventDefault(),G()}},R=()=>{d&&requestAnimationFrame(z)};return document.addEventListener("pointerdown",s,!0),window.addEventListener("resize",R),window.addEventListener("scroll",R,!0),()=>{document.removeEventListener("pointerdown",s,!0),window.removeEventListener("resize",R),window.removeEventListener("scroll",R,!0)}},[d,z]);const Pe=t.useCallback(()=>{r(a),p(!1),i==null||i()},[a,r,i]),De=t.useCallback(()=>{l(v.current),Q(v.current),p(!1),i==null||i()},[Q,i]),se=t.useCallback(s=>{s.stopPropagation()},[]);return e.jsxs("div",{ref:m,className:`tp-color-picker-input${d?" tp-color-picker-input-open":""}`,onClick:se,children:[e.jsx("button",{ref:M,type:"button",className:"tp-color-preview",style:{backgroundColor:he},onMouseDown:s=>s.preventDefault(),onClick:Z}),e.jsx("input",{value:o,type:"text",className:"tp-color-text-input",placeholder:u||"#d9d9d9",onChange:J,onBlur:pe,onMouseDown:se,onClick:se}),d&&e.jsxs("div",{ref:w,className:"tp-color-panel",style:{position:"fixed",top:`${S}px`,left:`${N}px`},onClick:se,children:[e.jsx("div",{ref:T,className:"tp-sv-area",style:{background:`linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, transparent), hsl(${k.h}, 100%, 50%)`},onMouseDown:xe,children:e.jsx("div",{className:"tp-sv-indicator",style:{left:`${k.s}%`,top:`${100-k.v}%`}})}),e.jsx("div",{ref:f,className:"tp-hue-bar",onMouseDown:je,children:e.jsx("div",{className:"tp-hue-indicator",style:{left:`${k.h/360*100}%`}})}),e.jsx("div",{className:"tp-color-section-label",children:"常用颜色"}),e.jsx("div",{className:"tp-color-grid tp-common-colors",children:X.map(s=>e.jsx("button",{type:"button",className:`tp-color-swatch${n===s?" tp-color-swatch-selected":""}`,style:{backgroundColor:s},title:s,onMouseDown:R=>R.preventDefault(),onClick:()=>V(s)},s))}),e.jsx("div",{className:"tp-input-mode-tabs",children:["hex","rgb","hsl"].map(s=>e.jsx("button",{type:"button",className:`tp-mode-tab${D===s?" active":""}`,onClick:()=>B(s),children:s.toUpperCase()},s))}),D==="hex"&&e.jsxs("div",{className:"tp-color-input-row",children:[e.jsx("label",{children:"HEX"}),e.jsx("input",{value:o,type:"text",className:"tp-color-input-field",placeholder:"#000000",onChange:J,onBlur:pe,onMouseDown:se,onClick:se})]}),D==="rgb"&&e.jsxs("div",{className:"tp-color-input-row tp-rgb-inline-row",children:[e.jsx("label",{children:"R"}),e.jsx("input",{type:"number",min:0,max:255,className:"tp-color-input-field",value:E.r,onChange:s=>{$(R=>({...R,r:Number(s.target.value)})),setTimeout(ke,0)},onMouseDown:se,onClick:se}),e.jsx("label",{children:"G"}),e.jsx("input",{type:"number",min:0,max:255,className:"tp-color-input-field",value:E.g,onChange:s=>{$(R=>({...R,g:Number(s.target.value)})),setTimeout(ke,0)},onMouseDown:se,onClick:se}),e.jsx("label",{children:"B"}),e.jsx("input",{type:"number",min:0,max:255,className:"tp-color-input-field",value:E.b,onChange:s=>{$(R=>({...R,b:Number(s.target.value)})),setTimeout(ke,0)},onMouseDown:se,onClick:se})]}),D==="hsl"&&e.jsxs("div",{className:"tp-color-input-row tp-hsl-inline-row",children:[e.jsx("label",{children:"H"}),e.jsx("input",{type:"number",min:0,max:360,className:"tp-color-input-field",value:U.h,onChange:s=>{P(R=>({...R,h:Number(s.target.value)})),setTimeout(Re,0)},onMouseDown:se,onClick:se}),e.jsx("span",{className:"tp-input-unit",children:"°"}),e.jsx("label",{children:"S"}),e.jsx("input",{type:"number",min:0,max:100,className:"tp-color-input-field",value:U.s,onChange:s=>{P(R=>({...R,s:Number(s.target.value)})),setTimeout(Re,0)},onMouseDown:se,onClick:se}),e.jsx("span",{className:"tp-input-unit",children:"%"}),e.jsx("label",{children:"L"}),e.jsx("input",{type:"number",min:0,max:100,className:"tp-color-input-field",value:U.l,onChange:s=>{P(R=>({...R,l:Number(s.target.value)})),setTimeout(Re,0)},onMouseDown:se,onClick:se}),e.jsx("span",{className:"tp-input-unit",children:"%"})]}),e.jsxs("div",{className:"tp-color-footer-row",children:[e.jsx("div",{className:"tp-color-preview-label",children:"当前颜色"}),e.jsx("div",{className:"tp-color-preview-box",style:{backgroundColor:he}}),e.jsxs("div",{className:"tp-color-actions",children:[e.jsx("button",{type:"button",className:`tp-color-btn tp-color-btn-cancel${I?" tp-color-btn-flash":""}`,title:"取消",onMouseDown:s=>s.preventDefault(),onClick:De,children:"✕"}),e.jsx("button",{type:"button",className:`tp-color-btn tp-color-btn-confirm${I?" tp-color-btn-flash":""}`,title:"确认",onMouseDown:s=>s.preventDefault(),onClick:Pe,children:"✓"})]})]})]})]})});Ie.displayName="ColorPickerInput";const Qe=({editor:n,visible:r,onVisibleChange:u})=>{const h=A.I18nManager.getInstance(),c=f=>h.t(f),[i,x]=t.useState({borderColor:"#d9d9d9",borderWidth:1}),[d,p]=t.useState("");t.useEffect(()=>{if(r){document.body.style.overflow="hidden";const{state:f}=n,{$from:S}=f.selection;let b=null;f.doc.nodesBetween(S.start(),S.end(),N=>N.type.name==="table"?(b=N,!1):!0),x(b?{borderColor:b.attrs.borderColor||"#d9d9d9",borderWidth:b.attrs.borderWidth?parseInt(b.attrs.borderWidth,10):1}:{borderColor:"#d9d9d9",borderWidth:1})}else document.body.style.overflow="";return()=>{document.body.style.overflow=""}},[r,n]);const m=t.useCallback(()=>{p("")},[]),w=t.useCallback(f=>(p(f),!0),[]),M=t.useCallback(()=>{d||(n.commands.focus(),u(!1))},[d,n,u]),T=t.useCallback(()=>{d||(n.chain().focus().setTableBorder({color:i.borderColor,width:`${i.borderWidth}px`,style:"solid"}).run(),u(!1))},[d,n,i,u]);return r?Ee.createPortal(e.jsx("div",{className:"tp-modal-overlay",onMouseDown:f=>{f.target===f.currentTarget&&M()},children:e.jsxs("div",{className:"tp-modal",onMouseDown:f=>f.stopPropagation(),children:[e.jsxs("div",{className:"tp-modal-header",children:[e.jsx("h3",{className:"tp-modal-title",children:c("table.tableSettings")}),e.jsx("button",{className:"tp-modal-close",onClick:M,children:"×"})]}),e.jsxs("div",{className:"tp-modal-body",children:[e.jsxs("div",{className:"tp-form-item",children:[e.jsx("label",{className:"tp-form-label",children:c("table.borderColor")}),e.jsx(Ie,{value:i.borderColor,onChange:f=>x(S=>({...S,borderColor:f})),mode:"border",placeholder:"#d9d9d9",beforeOpen:()=>w("border"),onClose:m})]}),e.jsxs("div",{className:"tp-form-item",children:[e.jsx("label",{className:"tp-form-label",children:c("table.borderWidth")}),e.jsxs("div",{className:"tp-input-with-suffix",children:[e.jsx("input",{type:"number",className:"tp-text-input",min:0,max:10,value:i.borderWidth,onChange:f=>x(S=>({...S,borderWidth:Number(f.target.value)}))}),e.jsx("span",{className:"tp-input-suffix",children:"px"})]})]})]}),e.jsxs("div",{className:"tp-modal-footer",children:[e.jsx("button",{className:"tp-btn tp-btn-default",onClick:M,children:c("common.cancel")}),e.jsx("button",{className:"tp-btn tp-btn-primary",onClick:T,children:c("common.confirm")})]})]})}),document.body):null},Dt=[{value:"left",labelKey:"table.alignLeft"},{value:"center",labelKey:"table.alignCenter"},{value:"right",labelKey:"table.alignRight"},{value:"justify",labelKey:"table.alignJustify"}],Ht=[{value:"top",labelKey:"table.valignTop"},{value:"middle",labelKey:"table.valignMiddle"},{value:"bottom",labelKey:"table.valignBottom"}];function At(n){const r=n.attrs.borderWidth||"1px",u=n.attrs.borderStyle||"solid",h=n.attrs.borderColor||"#d9d9d9";return`${r} ${u} ${h}`}function fe(n,r,u,h,c,i){const x=n===0,d=n+h>=c.height,p=r===0,m=r+u>=c.width;switch(i){case"top":return x;case"bottom":return d;case"left":return p;case"right":return m;default:return!1}}function Fe(n,r,u,h,c,i,x,d){const p=n.attrs.colspan||1,m=n.attrs.rowspan||1,w={...n.attrs};switch(x){case"left":w.borderLeft=d;break;case"right":w.borderRight=d;break;case"top":w.borderTop=d;break;case"bottom":w.borderBottom=d;break}return w.borderLeft||(w.borderLeft=fe(r,u,p,m,h,"left")&&c?c:i),w.borderRight||(w.borderRight=fe(r,u,p,m,h,"right")&&c?c:i),w.borderTop||(w.borderTop=fe(r,u,p,m,h,"top")&&c?c:i),w.borderBottom||(w.borderBottom=fe(r,u,p,m,h,"bottom")&&c?c:i),w}function $t(n,r,u,h,c,i,x,d,p,m){const w=n.attrs.colspan||1,M=n.attrs.rowspan||1;return m?{...n.attrs,borderLeft:fe(r,u,w,M,h,"left")&&c?c:i,borderRight:fe(r,u,w,M,h,"right")&&c?c:i,borderTop:fe(r,u,w,M,h,"top")&&c?c:i,borderBottom:fe(r,u,w,M,h,"bottom")&&c?c:i,backgroundColor:x,textAlign:d,verticalAlign:p}:{...n.attrs,backgroundColor:x,textAlign:d,verticalAlign:p}}const et=({editor:n,visible:r,onVisibleChange:u})=>{const h=A.I18nManager.getInstance(),c=o=>h.t(o),[i,x]=t.useState({borderColor:"#d9d9d9",borderWidth:1,backgroundColor:"#ffffff",textAlign:"left",verticalAlign:"top"}),[d,p]=t.useState({borderColor:"#d9d9d9",borderWidth:1}),[m,w]=t.useState(""),M=t.useRef(null),T=t.useRef(null),f=t.useCallback(()=>{const o=m==="border"?M.current:T.current;o==null||o.triggerButtonFlash()},[m]),S=t.useCallback(o=>m&&m!==o?(f(),!1):(w(o),!0),[m,f]),b=t.useCallback(()=>{const{state:o}=n,{selection:y}=o;if("$anchorCell"in y&&y.$anchorCell){const v=y.$anchorCell;let D=null;return o.doc.nodesBetween(v.pos,v.pos+1,B=>B.type.name==="tableCell"||B.type.name==="tableHeader"?(D=B,!1):!0),(D==null?void 0:D.attrs)||null}const{$from:a}=y;let l=null;return o.doc.nodesBetween(a.pos,a.pos+1,v=>v.type.name==="tableCell"||v.type.name==="tableHeader"?(l=v,!1):!0),(l==null?void 0:l.attrs)||null},[n]);t.useEffect(()=>{var o,y,a,l;if(r){document.body.style.overflow="hidden";const v=b();if(v){const D={borderColor:((y=(o=v.borderLeft)==null?void 0:o.match(/#\w+/))==null?void 0:y[0])||"#d9d9d9",borderWidth:(l=(a=v.borderLeft)==null?void 0:a.match(/(\d+)px/))!=null&&l[1]?parseInt(v.borderLeft.match(/(\d+)px/)[1],10):1,backgroundColor:v.backgroundColor||"#ffffff",textAlign:v.textAlign||"left",verticalAlign:v.verticalAlign||"middle"};x(D),p({borderColor:D.borderColor,borderWidth:D.borderWidth})}else x({borderColor:"#d9d9d9",borderWidth:1,backgroundColor:"#ffffff",textAlign:"left",verticalAlign:"middle"}),p({borderColor:"#d9d9d9",borderWidth:1})}else document.body.style.overflow="";return()=>{document.body.style.overflow=""}},[r,b]);const N=t.useCallback(()=>{m||(n.commands.focus(),u(!1))},[m,n,u]),g=t.useCallback(()=>{if(m)return;const{state:o,dispatch:y}=n.view,{selection:a}=o,l=a,v=o.tr;let D=!1;const B=i.borderColor!==d.borderColor||i.borderWidth!==d.borderWidth,k=`${i.borderWidth}px solid ${i.borderColor}`,L=(W,F,H,_,I,O)=>{const G=I+1,X=$t(W,H.row,H.col,_,O,k,i.backgroundColor,i.textAlign,i.verticalAlign,B);if(v.setNodeMarkup(F,null,X),D=!0,!B)return;const he=W.attrs.colspan||1,Q=W.attrs.rowspan||1,ae="1px solid #d9d9d9",le=new Map;for(let z=0;z<_.height;z++)for(let Z=0;Z<_.width;Z++){const V=_.map[z*_.width+Z];le.has(V)||le.set(V,{row:z,col:Z})}if(H.col>0){const z=_.map[H.row*_.width+H.col-1],Z=G+z,V=v.doc.nodeAt(Z);if(V&&(V.type.name==="tableCell"||V.type.name==="tableHeader")){const J=le.get(z);if(J&&!fe(J.row,J.col,V.attrs.colspan||1,V.attrs.rowspan||1,_,"right")){const pe=Fe(V,J.row,J.col,_,O,ae,"right",X.borderLeft);v.setNodeMarkup(Z,null,pe)}}}if(H.row>0){const z=_.map[(H.row-1)*_.width+H.col],Z=G+z,V=v.doc.nodeAt(Z);if(V&&(V.type.name==="tableCell"||V.type.name==="tableHeader")){const J=le.get(z);if(J&&!fe(J.row,J.col,V.attrs.colspan||1,V.attrs.rowspan||1,_,"bottom")){const pe=Fe(V,J.row,J.col,_,O,ae,"bottom",X.borderTop);v.setNodeMarkup(Z,null,pe)}}}if(H.col+(W.attrs.colspan||1)<_.width){const z=_.map[H.row*_.width+H.col+he],Z=G+z,V=v.doc.nodeAt(Z);if(V&&(V.type.name==="tableCell"||V.type.name==="tableHeader")){const J=le.get(z);if(J&&!fe(J.row,J.col,V.attrs.colspan||1,V.attrs.rowspan||1,_,"left")){const pe=Fe(V,J.row,J.col,_,O,ae,"left",X.borderRight);v.setNodeMarkup(Z,null,pe)}}}if(H.row+(W.attrs.rowspan||1)<_.height){const z=_.map[(H.row+Q)*_.width+H.col],Z=G+z,V=v.doc.nodeAt(Z);if(V&&(V.type.name==="tableCell"||V.type.name==="tableHeader")){const J=le.get(z);if(J&&!fe(J.row,J.col,V.attrs.colspan||1,V.attrs.rowspan||1,_,"top")){const pe=Fe(V,J.row,J.col,_,O,ae,"top",X.borderBottom);v.setNodeMarkup(Z,null,pe)}}}},{$from:E,$to:$}=a;let U=-1,P=null;if(o.doc.nodesBetween(E.pos,$.pos,(W,F)=>W.type.name==="table"?(U=F,P=W,!1):!0),P&&U>=0){const W=At(P),F=Ye.TableMap.get(P),H=U+1,_=new Map;for(let I=0;I<F.height;I++)for(let O=0;O<F.width;O++){const G=F.map[I*F.width+O];_.has(G)||_.set(G,{row:I,col:O})}if("$anchorCell"in a&&a.$anchorCell){const I=a.$anchorCell,O=a.$headCell,G=I.pos-H,X=O.pos-H,he=F.rectBetween(G,X);F.cellsInRect(he).forEach(ae=>{const le=H+ae,z=o.doc.nodeAt(le);if(z&&(z.type.name==="tableCell"||z.type.name==="tableHeader")){const Z=_.get(ae);Z&&L(z,le,Z,F,U,W)}})}else o.doc.nodesBetween(E.pos,$.pos,(I,O)=>{if(I.type.name==="tableCell"||I.type.name==="tableHeader"){const G=O-H,X=_.get(G);X&&L(I,O,X,F,U,W)}return!0})}D&&y&&(v.setSelection(l.map(v.doc,v.mapping)),y(v),n.commands.focus()),u(!1)},[m,n,i,d,u]);return r?Ee.createPortal(e.jsx("div",{className:"tp-modal-overlay",onMouseDown:o=>{o.target===o.currentTarget&&N()},children:e.jsxs("div",{className:"tp-modal",onMouseDown:o=>o.stopPropagation(),children:[e.jsxs("div",{className:"tp-modal-header",children:[e.jsx("h3",{className:"tp-modal-title",children:c("table.cellSettings")}),e.jsx("button",{className:"tp-modal-close",onClick:N,children:"×"})]}),e.jsxs("div",{className:"tp-modal-body",children:[e.jsxs("div",{className:"tp-form-item",children:[e.jsx("label",{className:"tp-form-label",children:c("table.borderColor")}),e.jsx(Ie,{ref:M,value:i.borderColor,onChange:o=>x(y=>({...y,borderColor:o})),mode:"border",placeholder:"#d9d9d9",beforeOpen:()=>S("border"),onClose:()=>w("")})]}),e.jsxs("div",{className:"tp-form-item",children:[e.jsx("label",{className:"tp-form-label",children:c("table.borderWidth")}),e.jsxs("div",{className:"tp-input-with-suffix",children:[e.jsx("input",{type:"number",className:"tp-text-input",min:0,max:10,value:i.borderWidth,onChange:o=>x(y=>({...y,borderWidth:Number(o.target.value)}))}),e.jsx("span",{className:"tp-input-suffix",children:"px"})]})]}),e.jsxs("div",{className:"tp-form-item",children:[e.jsx("label",{className:"tp-form-label",children:c("table.backgroundColor")}),e.jsx(Ie,{ref:T,value:i.backgroundColor,onChange:o=>x(y=>({...y,backgroundColor:o})),mode:"background",placeholder:"transparent",beforeOpen:()=>S("background"),onClose:()=>w("")})]}),e.jsxs("div",{className:"tp-form-item",children:[e.jsx("label",{className:"tp-form-label",children:c("table.textAlign")}),e.jsx("div",{className:"tp-align-options",children:Dt.map(o=>e.jsxs("button",{className:`tp-align-btn${i.textAlign===o.value?" active":""}`,onClick:()=>x(y=>({...y,textAlign:o.value})),children:[e.jsxs("span",{className:"tp-align-icon tp-align-icon-svg",children:[o.value==="left"&&e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"6",y1:"8",x2:"14",y2:"8"}),e.jsx("line",{x1:"6",y1:"12",x2:"11",y2:"12"}),e.jsx("line",{x1:"6",y1:"16",x2:"16",y2:"16"})]}),o.value==="center"&&e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"7",y1:"8",x2:"17",y2:"8"}),e.jsx("line",{x1:"9",y1:"12",x2:"15",y2:"12"}),e.jsx("line",{x1:"8",y1:"16",x2:"16",y2:"16"})]}),o.value==="right"&&e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"10",y1:"8",x2:"18",y2:"8"}),e.jsx("line",{x1:"13",y1:"12",x2:"18",y2:"12"}),e.jsx("line",{x1:"8",y1:"16",x2:"18",y2:"16"})]}),o.value==="justify"&&e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"6",y1:"8",x2:"18",y2:"8"}),e.jsx("line",{x1:"6",y1:"12",x2:"18",y2:"12"}),e.jsx("line",{x1:"6",y1:"16",x2:"18",y2:"16"})]})]}),e.jsx("span",{className:"tp-align-label",children:c(o.labelKey)})]},o.value))})]}),e.jsxs("div",{className:"tp-form-item",children:[e.jsx("label",{className:"tp-form-label",children:c("table.verticalAlign")}),e.jsx("div",{className:"tp-align-options",children:Ht.map(o=>e.jsxs("button",{className:`tp-align-btn${i.verticalAlign===o.value?" active":""}`,onClick:()=>x(y=>({...y,verticalAlign:o.value})),children:[e.jsxs("span",{className:"tp-align-icon tp-align-icon-svg",children:[o.value==="top"&&e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"6",y1:"7",x2:"18",y2:"7"})]}),o.value==="middle"&&e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"6",y1:"12",x2:"18",y2:"12"})]}),o.value==="bottom"&&e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"6",y1:"17",x2:"18",y2:"17"})]})]}),e.jsx("span",{className:"tp-align-label",children:c(o.labelKey)})]},o.value))})]})]}),e.jsxs("div",{className:"tp-modal-footer",children:[e.jsx("button",{className:"tp-btn tp-btn-default",onClick:N,children:c("common.cancel")}),e.jsx("button",{className:"tp-btn tp-btn-primary",onClick:g,children:c("common.confirm")})]})]})}),document.body):null},tt=({manager:n,visible:r,onVisibleChange:u})=>{const h=A.I18nManager.getInstance(),[c,i]=t.useState([]),[x,d]=t.useState(""),[p,m]=t.useState(null),[w,M]=t.useState(!1),T=t.useRef(null),f=t.useRef(null),S=t.useRef(null),b=t.useCallback((l,v)=>h.t(l,v)||l,[h]),N=t.useCallback(l=>{try{const v=new Date(l),B=new Date().getTime()-v.getTime(),k=Math.floor(B/6e4),L=Math.floor(B/36e5),E=Math.floor(B/864e5);return k<1?b("compare.justNow"):k<60?b("compare.minutesAgo",{n:String(k)}):L<24?b("compare.hoursAgo",{n:String(L)}):E<7?b("compare.daysAgo",{n:String(E)}):v.toLocaleDateString()+" "+v.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return l}},[b]),g=t.useCallback(l=>{const v={blur:"compare.sourceBlur",baseline:"compare.sourceBaseline",paste:"compare.sourcePaste",import:"compare.sourceImport",manual:"compare.sourceManual",interval:"compare.sourceInterval",imported:"compare.sourceImported"};return v[l]?b(v[l]):l},[b]),o=t.useCallback((l,v)=>`v${c.length-v}.0 - ${N(l.timestamp)} (${g(l.source)})${l.label?` - ${l.label}`:""}`,[N,g,c]);t.useEffect(()=>{if(!r){d(""),m(null);return}let l=!1;return M(!0),n.listVersions().then(v=>{l||(i(v),!x&&v.length>0&&d(v[0].id),M(!1))}).catch(()=>{l||(i([]),M(!1))}),()=>{l=!0}},[r,n]),t.useEffect(()=>{if(!x||!n){m(null);return}n.compareWithVersion(x).then(m).catch(()=>m(null))},[x,n]),t.useEffect(()=>{var l,v;if(p&&T.current&&f.current){(l=S.current)==null||l.detach();const D=new A.ScrollSyncManager(T.current,f.current);D.attach();const B=setTimeout(()=>D.refresh(),0);return S.current=D,()=>{clearTimeout(B),D.detach()}}else(v=S.current)==null||v.detach(),S.current=null},[p]),t.useEffect(()=>{const l=v=>{v.key==="Escape"&&r&&u(!1)};return document.addEventListener("keydown",l),()=>document.removeEventListener("keydown",l)},[r,u]);const y=t.useCallback(async()=>{const l=await n.createSnapshot(b("compare.createSnapshot"));l?A.showToast(b("compare.snapshotCreated").replace("{time}",l.label||l.timestamp)):A.showToast({message:b("compare.snapshotFailed"),type:"error"});const v=await n.listVersions();i(v)},[n,b]),a=t.useCallback(()=>{u(!1)},[u]);return r?e.jsxs("div",{className:"cyte-compare-overlay",children:[e.jsxs("div",{className:"cyte-compare-header",children:[e.jsxs("div",{className:"cyte-compare-header__title",children:[e.jsxs("svg",{className:"cyte-compare-header__title-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"18",rx:"1"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"18",rx:"1"}),e.jsx("line",{x1:"10",y1:"8",x2:"14",y2:"8"}),e.jsx("line",{x1:"10",y1:"12",x2:"14",y2:"12"}),e.jsx("line",{x1:"10",y1:"16",x2:"14",y2:"16"})]}),b("compare.title")]}),e.jsxs("div",{className:"cyte-compare-header__actions",children:[e.jsxs("div",{className:"cyte-compare-version-selector",children:[e.jsxs("span",{className:"cyte-compare-version-selector__label",children:[b("compare.selectVersion"),":"]}),e.jsxs("select",{value:x,onChange:l=>d(l.target.value),className:"cyte-compare-version-selector__select",children:[e.jsx("option",{value:"",disabled:!0,children:b("compare.selectVersion")}),c.map((l,v)=>e.jsx("option",{value:l.id,children:o(l,v)},l.id))]})]}),e.jsx("button",{className:"cyte-compare-btn--close",onClick:a,title:b("compare.close"),children:"✕"})]})]}),p&&e.jsxs("div",{className:"cyte-compare-stats",children:[e.jsxs("div",{className:"cyte-compare-stats__item",children:[e.jsxs("span",{className:"cyte-compare-stats__badge",children:[e.jsx("span",{className:"cyte-compare-stats__dot cyte-compare-stats__dot--added"}),e.jsx("span",{className:"cyte-compare-stats__count cyte-compare-stats__count--added",children:p.stats.added})]}),e.jsx("span",{className:"cyte-compare-stats__label",children:b("compare.statsAdded")})]}),e.jsxs("div",{className:"cyte-compare-stats__item",children:[e.jsxs("span",{className:"cyte-compare-stats__badge",children:[e.jsx("span",{className:"cyte-compare-stats__dot cyte-compare-stats__dot--removed"}),e.jsx("span",{className:"cyte-compare-stats__count cyte-compare-stats__count--removed",children:p.stats.removed})]}),e.jsx("span",{className:"cyte-compare-stats__label",children:b("compare.statsRemoved")})]}),e.jsxs("div",{className:"cyte-compare-stats__item",children:[e.jsxs("span",{className:"cyte-compare-stats__badge",children:[e.jsx("span",{className:"cyte-compare-stats__dot cyte-compare-stats__dot--modified"}),e.jsx("span",{className:"cyte-compare-stats__count cyte-compare-stats__count--modified",children:p.stats.modified})]}),e.jsx("span",{className:"cyte-compare-stats__label",children:b("compare.statsModified")})]}),e.jsxs("div",{className:"cyte-compare-stats__item cyte-compare-stats__item--unchanged",children:[e.jsxs("span",{className:"cyte-compare-stats__badge",children:[e.jsx("span",{className:"cyte-compare-stats__dot cyte-compare-stats__dot--unchanged"}),e.jsx("span",{className:"cyte-compare-stats__count",children:p.stats.unchanged})]}),e.jsx("span",{className:"cyte-compare-stats__label",children:b("compare.statsUnchanged")})]})]}),e.jsxs("div",{className:"cyte-compare-content",children:[c.length===0&&!w&&e.jsxs("div",{className:"cyte-compare-empty",children:[e.jsxs("svg",{className:"cyte-compare-empty__icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M8 12h8M12 8v8"})]}),e.jsx("div",{className:"cyte-compare-empty__text",children:b("compare.noVersions")}),e.jsx("div",{className:"cyte-compare-empty__hint",children:b("compare.noVersionsHint")}),e.jsx("button",{className:"cyte-compare-btn cyte-compare-btn--primary cyte-compare-snapshot-btn",onClick:y,children:b("compare.createSnapshot")})]}),p&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:T,className:"cyte-compare-pane",children:[e.jsx("div",{className:"cyte-compare-pane__header",children:(()=>{const l=c.findIndex(v=>v.id===x);return l===-1?b("compare.leftLabel"):`${b("compare.leftLabel")} - ${o(c[l],l)}`})()}),e.jsx("div",{className:"cyte-compare-pane__body",children:p.left.map(l=>e.jsx("div",{dangerouslySetInnerHTML:{__html:l.html}},l.key))})]}),e.jsxs("div",{ref:f,className:"cyte-compare-pane",children:[e.jsx("div",{className:"cyte-compare-pane__header",children:b("compare.rightLabel")}),e.jsx("div",{className:"cyte-compare-pane__body",children:p.right.map(l=>e.jsx("div",{dangerouslySetInnerHTML:{__html:l.html}},l.key))})]})]}),c.length>0&&!x&&!p&&e.jsx("div",{className:"cyte-compare-empty",children:e.jsx("div",{className:"cyte-compare-empty__text",children:b("compare.selectVersion")})})]})]}):null},_t=({visible:n,defaultFilename:r,onConfirm:u,onCancel:h,onClose:c})=>{const{t:i}=de(),[x,d]=t.useState(""),p=t.useRef(null);t.useEffect(()=>(n?(d(r||"document"),document.body.style.overflow="hidden",setTimeout(()=>{var f,S;(f=p.current)==null||f.focus(),(S=p.current)==null||S.select()},100)):document.body.style.overflow="",()=>{document.body.style.overflow=""}),[n,r]);const m=t.useCallback(()=>{const f=x.trim()||"document";u(f),c()},[x,u,c]),w=t.useCallback(()=>{h==null||h(),c()},[h,c]),M=t.useCallback(f=>{f.target===f.currentTarget&&w()},[w]),T=t.useCallback(f=>{f.key==="Enter"?(f.preventDefault(),m()):f.key==="Escape"&&(f.preventDefault(),w())},[m,w]);return n?Ee.createPortal(e.jsx("div",{className:"tp-export-dialog-overlay",onMouseDown:M,children:e.jsxs("div",{className:"tp-export-dialog",onMouseDown:f=>f.stopPropagation(),onKeyDown:T,children:[e.jsxs("div",{className:"tp-dialog-header",children:[e.jsx("span",{className:"tp-dialog-title",children:i("toolbar.exportWord")}),e.jsx("button",{className:"tp-dialog-close",onClick:w,children:"×"})]}),e.jsxs("div",{className:"tp-dialog-body",children:[e.jsx("label",{className:"tp-input-label",children:i("toolbar.exportWordFilename")}),e.jsxs("div",{className:"tp-input-row",children:[e.jsx("input",{ref:p,type:"text",className:"tp-filename-input",value:x,onChange:f=>d(f.target.value),onKeyDown:T}),e.jsx("span",{className:"tp-filename-suffix",children:".docx"}),e.jsx("button",{className:"tp-confirm-btn",onClick:m,children:i("common.confirm")})]})]})]})}),document.body):null},It=({visible:n,defaultFilename:r,onConfirm:u,onCancel:h,onClose:c})=>{const{t:i}=de(),[x,d]=t.useState(""),p=t.useRef(null);t.useEffect(()=>(n?(d(r||"document"),document.body.style.overflow="hidden",setTimeout(()=>{var f,S;(f=p.current)==null||f.focus(),(S=p.current)==null||S.select()},100)):document.body.style.overflow="",()=>{document.body.style.overflow=""}),[n,r]);const m=t.useCallback(()=>{const f=x.trim()||"document";u(f),c()},[x,u,c]),w=t.useCallback(()=>{h==null||h(),c()},[h,c]),M=t.useCallback(f=>{f.target===f.currentTarget&&w()},[w]),T=t.useCallback(f=>{f.key==="Enter"?(f.preventDefault(),m()):f.key==="Escape"&&(f.preventDefault(),w())},[m,w]);return n?Ee.createPortal(e.jsx("div",{className:"tp-export-dialog-overlay",onMouseDown:M,children:e.jsxs("div",{className:"tp-export-dialog",onMouseDown:f=>f.stopPropagation(),onKeyDown:T,children:[e.jsxs("div",{className:"tp-dialog-header",children:[e.jsx("span",{className:"tp-dialog-title",children:i("toolbar.exportMarkdown")}),e.jsx("button",{className:"tp-dialog-close",onClick:w,children:"×"})]}),e.jsxs("div",{className:"tp-dialog-body",children:[e.jsx("label",{className:"tp-input-label",children:i("toolbar.exportMarkdownFilename")}),e.jsxs("div",{className:"tp-input-row",children:[e.jsx("input",{ref:p,type:"text",className:"tp-filename-input",value:x,onChange:f=>d(f.target.value),onKeyDown:T}),e.jsx("span",{className:"tp-filename-suffix",children:".md"}),e.jsx("button",{className:"tp-confirm-btn",onClick:m,children:i("common.confirm")})]})]})]})}),document.body):null},nt=t.forwardRef((n,r)=>{const{html:u,json:h,config:c,height:i="300px",minHeight:x,maxHeight:d,autoHeight:p=!1,placeholder:m,toolbar:w,readonly:M=!1,disabled:T=!1,autofocus:f=!1,locale:S,pasteMode:b,uploadUrl:N,onChange:g,onFocus:o,onBlur:y,onReady:a,onViewModeChange:l,onToolbarClick:v,onFullscreenChange:D,toolbarRender:B}=n,[k,L]=t.useState("normal"),E=t.useRef(""),$=t.useRef(null),[U,P]=t.useState(!1),[W,F]=t.useState({x:0,y:0}),[H,_]=t.useState(null),I=t.useRef(null),O=t.useRef(null);t.useEffect(()=>()=>{var C,j;(C=I.current)==null||C.call(I),I.current=null,(j=O.current)==null||j.call(O),O.current=null},[]);const[G,X]=t.useState(!1),[he,Q]=t.useState(!1),[ae,le]=t.useState(!1),[z,Z]=t.useState(!1),[V,J]=t.useState("document"),[pe,ke]=t.useState(!1),[Re,Ce]=t.useState("document"),[xe,we]=t.useState(!1),je=A.I18nManager.getInstance(),Pe=t.useCallback(C=>je.t(C)||C,[je]),De=t.useMemo(()=>{const j={...c||{}};return i!==void 0&&(j.height=i),x!==void 0&&(j.minHeight=x),d!==void 0&&(j.maxHeight=d),p!==void 0&&(j.autoHeight=p),m!==void 0&&(j.placeholder=m),w!==void 0&&(j.toolbar=w),M!==void 0&&(j.readonly=M),T!==void 0&&(j.disabled=T),f!==void 0&&(j.autofocus=f),S!==void 0&&(j.locale=S),b!==void 0&&(j.paste={...j.paste,mode:b}),N!==void 0&&(j.upload={...j.upload,url:N}),j},[c,i,x,d,p,m,w,M,T,f,S,b,N]),se=t.useMemo(()=>De.toolbar||["undo","redo","formatPainter","|","bold","italic","underline","strikethrough","superscript","subscript","|","fontFamily","fontSize","color","bgColor","|","heading","align","lineHeight","bulletList","orderedList","outdent","indent","|","link","insertTable","imageUpload","video","formula","structure","|","blockquote","codeBlock","|","import","export","getHTML","getJSON","|","snapshot","compare","autoFormat","fullscreen"],[De.toolbar]),{manager:s,isReady:R,isFocused:Y,isEmpty:ce,containerRef:ue,setContentFromProp:ve}=Ge({config:De,onUpdate(C,j){g==null||g({html:C,json:j})},onFocus(C){o==null||o(C)},onBlur(C){y==null||y(C)},onReady(C){u?C.setContent(u):h&&C.setJSON(h),Le(C),a==null||a(C)}}),{activeStates:Ne,disabledStates:He}=Xe(s);t.useEffect(()=>{u!==void 0&&ve(u)},[u,ve]),t.useEffect(()=>{h!==void 0&&ve(void 0,h)},[h,ve]);const re=t.useCallback(C=>{let j="",K=0;const ee=" ",te=C.replace(/>\s+</g,"><").trim().split(/(<\/?[^>]+>)/g).filter(ie=>ie.trim()!=="");for(let ie=0;ie<te.length;ie++){const ne=te[ie];if(ne.match(/^<\/\w/))K=Math.max(0,K-1),j+=ee.repeat(K)+ne+`
|
|
16
|
+
`;else if(ne.match(/^<\w[^>]*[^\/]>$/)){j+=ee.repeat(K)+ne+`
|
|
17
|
+
`;const oe=te[ie+1];oe&&!oe.match(/^<\/\w/)&&K++}else if(ne.match(/^<\w[^>]*\/>$/))j+=ee.repeat(K)+ne+`
|
|
18
|
+
`;else if(ne.match(/^<\w/))j+=ee.repeat(K)+ne+`
|
|
19
|
+
`;else{const oe=ne.trim();oe&&(j+=ee.repeat(K)+oe+`
|
|
20
|
+
`)}}return j.trim()},[]),Me=t.useCallback(C=>{if(!s)return;const j=s.getEditor();if(k===C){Se();return}k!=="normal"?Se():(E.current=s.getHTML(),$.current=s.getJSON());const K=C==="html"?s.getHTML():JSON.stringify(s.getJSON(),null,2),ee=C==="html"?re(K):K;j.commands.clearContent(),j.commands.insertContent({type:"codeBlock",attrs:{language:C==="html"?"html":"json"},content:[{type:"text",text:ee}]}),L(C),l==null||l(C)},[s,k,re,l]),Se=t.useCallback(()=>{if(!s)return;const C=s.getEditor();if(k!=="normal"){const j=C.getText(),K=k;if(j)try{if(K==="html"){const ee=document.createElement("div");ee.innerHTML=j,C.commands.setContent(j)}else if(K==="json"){const ee=JSON.parse(j);C.commands.setContent(ee)}}catch{alert(K==="html"?"HTML 格式错误,请检查输入内容":"JSON 格式错误,请检查输入内容");return}else $.current?C.commands.setContent($.current):E.current&&C.commands.setContent(E.current)}else $.current?C.commands.setContent($.current):E.current&&C.commands.setContent(E.current);L("normal"),l==null||l("normal")},[s,k,l]),Le=t.useCallback(C=>{var ee,q;const j=C.getEditor(),K=(te,ie)=>{A.getHoverLineVisible()||(A.syncTableSelectionForCell(j,te),_(te),P(!1),setTimeout(()=>{F({x:ie.right,y:ie.bottom+6}),_(te),P(!0)},0))};(ee=I.current)==null||ee.call(I),I.current=A.installTableTouchHandle(j,{onOpen:K,shouldShow:()=>!A.getHoverLineVisible(),shouldOpen:()=>!A.getHoverLineVisible()}),(q=O.current)==null||q.call(O),O.current=A.installContextMenuTouchTracking(j.view.dom),j.view.dom.addEventListener("contextmenu",te=>{if(A.isTouchOriginatedContextMenu()){P(!1);return}const ne=te.target.closest("td, th");if(!A.getHoverLineVisible())if(ne){te.preventDefault();const oe=j.state.selection;if("$anchorCell"in oe){let Be=!1;try{oe.forEachCell((Oe,st)=>{const _e=j.view.nodeDOM(st);_e&&_e instanceof HTMLElement&&(_e===ne||_e.contains(ne)||ne.contains(_e))&&(Be=!0)})}catch{}Be||A.moveCursorToCell(j,ne),F({x:te.clientX,y:te.clientY}),_(ne),P(!0);return}A.syncTableSelectionForCell(j,ne);const ye=U;ye&&P(!1),setTimeout(()=>{F({x:te.clientX,y:te.clientY}),_(ne),P(!0)},ye?0:50)}else P(!1),_(null),A.clearSavedTableSelection()})},[U]),Ae=t.useCallback(C=>{if(v==null||v(C),C==="snapshot"){s==null||s.createSnapshot().then(j=>{j?A.showToast(je.t("compare.snapshotCreated",{time:j.label||j.timestamp})):A.showToast({message:je.t("compare.snapshotFailed"),type:"error"})});return}if(C==="compare"&&le(!0),C==="fullscreen"&&me(),C==="autoFormat"&&(s==null||s.toggleAutoFormatPanel()),C==="importWord"){const j=document.createElement("input");j.type="file",j.accept=".docx,application/vnd.openxmlformats-officedocument.wordprocessingml.document",j.onchange=async K=>{var q;const ee=(q=K.target.files)==null?void 0:q[0];ee&&await(s==null?void 0:s.importWordFile(ee))},j.click()}if(C==="importMarkdown"){const j=document.createElement("input");j.type="file",j.accept=".md,.markdown,text/markdown",j.onchange=async K=>{var q;const ee=(q=K.target.files)==null?void 0:q[0];ee&&await(s==null?void 0:s.importMarkdownFile(ee))},j.click()}C==="exportWord"&&(J((s==null?void 0:s.getDocumentTitle())||"document"),Z(!0)),C==="exportMarkdown"&&(Ce((s==null?void 0:s.getDocumentTitle())||"document"),ke(!0))},[v,s]),Te=t.useCallback(C=>{if(!s)return;const j=s.getEditor();switch("$anchorCell"in j.state.selection||(A.restoreTableSelection(j),A.clearSavedTableSelection()),C){case"addRowBefore":s.addTableRowBefore();break;case"addRowAfter":s.addTableRowAfter();break;case"addColumnBefore":s.addTableColumnBefore();break;case"addColumnAfter":s.addTableColumnAfter();break;case"selectRow":{const q=H??A.getCurrentTableCell(j);q&&A.selectTableRow(j,q);break}case"selectColumn":{const q=H??A.getCurrentTableCell(j);q&&A.selectTableColumn(j,q);break}case"selectTable":{const q=H??A.getCurrentTableCell(j);q&&A.selectTableAll(j,q);break}case"extendSelection":{const q=H??A.getCurrentTableCell(j);A.beginTableRangeSelection(j,q??void 0);break}case"mergeCells":j.chain().mergeCells().run(),setTimeout(()=>{if(H)if(document.contains(H))A.moveCursorToCell(j,H);else{const{state:q}=j,{selection:te}=q;if("$anchorCell"in te){const ie=te.$anchorCell.pos;if(q.doc.nodeAt(ie)){const oe=j.view.nodeDOM(ie);oe&&A.moveCursorToCell(j,oe)}}}},0);break;case"splitCell":{const q=H;let te=null;if(q)try{te=j.view.posAtDOM(q,0)}catch{}j.chain().splitCell().run(),setTimeout(()=>{const{state:ie}=j,{selection:ne}=ie;if(ne instanceof ot.TextSelection){j.commands.focus();return}if(te!==null)try{const oe=j.view.nodeDOM(te);if(oe&&document.contains(oe)){A.moveCursorToCell(j,oe);return}}catch{}try{let oe=null;if(ie.doc.descendants(($e,ye)=>$e.type.name==="table"?(oe=ye,!1):!0),oe!==null){const $e=ie.doc.nodeAt(oe);if($e){const ye=Ye.TableMap.get($e);if(ye.map.length>0){const Be=ye.map[0]+oe+1,Oe=j.view.nodeDOM(Be);if(Oe){A.moveCursorToCell(j,Oe);return}}}}}catch{}j.commands.focus()},0);break}case"deleteRow":s.deleteTableRow();break;case"deleteColumn":s.deleteTableColumn();break;case"deleteTable":s.deleteTable();break;case"tableSettings":X(!0);break;case"cellSettings":Q(!0);break}},[s,H]),me=t.useCallback(()=>{we(C=>{const j=!C;return D==null||D(j),j})},[D]),be=t.useCallback(C=>{C.key==="Escape"&&xe&&(we(!1),D==null||D(!1))},[xe,D]),ze=t.useMemo(()=>{const C={};return p?(x&&(C.minHeight=typeof x=="number"?`${x}px`:x),d&&(C.maxHeight=typeof d=="number"?`${d}px`:d)):(i&&(C.height=typeof i=="number"?`${i}px`:i),x&&(C.minHeight=typeof x=="number"?`${x}px`:x)),C},[p,i,x,d]);return t.useImperativeHandle(r,()=>({getEditorManager:()=>s,getHTML:()=>(s==null?void 0:s.getHTML())??"",getJSON:()=>(s==null?void 0:s.getJSON())??{type:"doc",content:[]},getText:()=>(s==null?void 0:s.getText())??"",setContent:C=>s==null?void 0:s.setContent(C),setJSON:C=>s==null?void 0:s.setJSON(C),insertHTML:C=>s==null?void 0:s.insertHTML(C),insertText:C=>s==null?void 0:s.insertText(C),focus:()=>s==null?void 0:s.focus(),blur:()=>s==null?void 0:s.blur(),isEmpty:()=>(s==null?void 0:s.isEmpty())??!0,clear:()=>s==null?void 0:s.clear(),undo:()=>s==null?void 0:s.undo(),redo:()=>s==null?void 0:s.redo(),setReadonly:C=>s==null?void 0:s.setReadonly(C),insertTable:(C,j,K)=>s==null?void 0:s.insertTable(C,j,K),insertImage:(C,j,K)=>s==null?void 0:s.insertImage(C,j,K),insertVideo:(C,j,K)=>s==null?void 0:s.insertVideo(C,j,K),exportMarkdown:()=>(s==null?void 0:s.exportMarkdown())??"",exportHTMLDocument:C=>(s==null?void 0:s.exportHTMLDocument(C))??"",exportWordFile:async C=>{await(s==null?void 0:s.exportWordFile(C))},exportMarkdownFile:C=>(s==null?void 0:s.exportMarkdownFile(C))??Promise.resolve(),importMarkdown:C=>s==null?void 0:s.importMarkdown(C),importHTMLFile:C=>(s==null?void 0:s.importHTMLFile(C))??Promise.resolve(),importMarkdownFile:C=>(s==null?void 0:s.importMarkdownFile(C))??Promise.resolve(),importWordFile:C=>(s==null?void 0:s.importWordFile(C))??Promise.resolve({messages:[]}),parseHTML:C=>s==null?void 0:s.parseHTML(C),addSnapshot:(C,j)=>(s==null?void 0:s.addSnapshot(C,j))??Promise.resolve(null),toggleViewMode:Me,restoreOriginalContent:Se,getViewMode:()=>k,toggleFullscreen:me,isFullscreen:()=>xe}),[s,Me,Se,k,me,xe]),e.jsxs("div",{className:`cyte-editor${T?" is-disabled":""}${M?" is-readonly":""}${Y?" is-focused":""}${ce?" is-empty":""}${p?" is-auto-height":""}${p&&d?" is-auto-height-limited":""}${xe?" is-fullscreen":""}`,style:ze,onKeyDown:be,children:[xe&&e.jsxs("div",{className:"cyte-fullscreen-header",children:[e.jsxs("div",{className:"cyte-fullscreen-header__title",children:[e.jsxs("svg",{className:"cyte-fullscreen-header__title-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M8 4H4V8M4 4L10 10"}),e.jsx("path",{d:"M16 4H20V8M20 4L14 10"}),e.jsx("path",{d:"M4 16V20H8M4 20L10 14"}),e.jsx("path",{d:"M20 16V20H16M20 20L14 14"})]}),Pe("toolbar.fullscreenTitle")]}),e.jsxs("button",{className:"cyte-fullscreen-header__close",onClick:me,children:["✕ ",Pe("toolbar.exitFullscreen")]})]}),B?B({manager:s,activeStates:Ne,disabledStates:He,isReady:R}):R&&s&&e.jsx(Mt,{items:se,manager:s,activeStates:Ne,disabledStates:He,viewMode:k,onToggleViewMode:Me,onToolbarClick:Ae}),e.jsx("div",{ref:ue,className:"tp-editor-content"}),R&&s&&e.jsx(Ze,{editor:s.getEditor(),visible:U,position:W,targetCell:H,onVisibleChange:P,onAction:Te}),R&&s&&e.jsx(Qe,{editor:s.getEditor(),visible:G,onVisibleChange:X}),R&&s&&e.jsx(et,{editor:s.getEditor(),visible:he,onVisibleChange:Q}),R&&s&&e.jsx(tt,{manager:s,visible:ae,onVisibleChange:le}),e.jsx(_t,{visible:z,defaultFilename:V,onConfirm:C=>s==null?void 0:s.exportWordFile(C),onClose:()=>Z(!1)}),e.jsx(It,{visible:pe,defaultFilename:Re,onConfirm:C=>s==null?void 0:s.exportMarkdownFile(C),onClose:()=>ke(!1)})]})});nt.displayName="CyteEditor";exports.CellSettingsModal=et;exports.ColorPickerInput=Ie;exports.CompareOverlay=tt;exports.CyteEditor=nt;exports.TableContextMenu=Ze;exports.TableSettingsModal=Qe;exports.useEditor=Ge;exports.useI18n=de;exports.useToolbarState=Xe;
|