@cyte-editor/react 1.3.0 → 1.3.1
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.
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";/*!
|
|
2
|
-
* CyteEditor React Adapter v1.3.
|
|
2
|
+
* CyteEditor React Adapter v1.3.1 (@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: e2f3bc5-dirty @ 2026-11-06T10:10:27.615Z
|
|
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","|","fullscreen","snapshot","compare","autoFormat"],[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+`
|
|
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
16
|
`;else if(pe.match(/^<\w[^>]*[^\/]>$/)){L+=ne.repeat(F)+pe+`
|
|
17
17
|
`;const oe=de[ce+1];oe&&!oe.match(/^<\/\w/)&&F++}else if(pe.match(/^<\w[^>]*\/>$/))L+=ne.repeat(F)+pe+`
|
|
18
18
|
`;else if(pe.match(/^<\w/))L+=ne.repeat(F)+pe+`
|
|
@@ -6,14 +6,14 @@ import { EditorManager as dt, I18nManager as De, toolbarItemDefs as Je, uploadFi
|
|
|
6
6
|
import { getLicenseStatus as gt } from "@cyte-editor/license";
|
|
7
7
|
import { createPortal as _e } from "react-dom";
|
|
8
8
|
/*!
|
|
9
|
-
* CyteEditor React Adapter v1.3.
|
|
9
|
+
* CyteEditor React Adapter v1.3.1 (@cyte-editor/react)
|
|
10
10
|
* (c) 2026 CyteEditor — All Rights Reserved.
|
|
11
11
|
*
|
|
12
12
|
* Commercial Software — NOT Open Source.
|
|
13
13
|
* Licensed under the CyteEditor Commercial License.
|
|
14
14
|
* SEE LICENSE IN ./LICENSE | Full EULA: https://cyteeditor.com/eula
|
|
15
15
|
*
|
|
16
|
-
* Build:
|
|
16
|
+
* Build: e2f3bc5-dirty @ 2026-11-06T10:10:27.615Z
|
|
17
17
|
* Homepage: https://cyteeditor.com
|
|
18
18
|
* Contact: legal@cyteeditor.com (legal) / support@cyteeditor.com (support)
|
|
19
19
|
*
|
|
@@ -2488,10 +2488,10 @@ const Xt = ({ editor: t, visible: o, onVisibleChange: c }) => {
|
|
|
2488
2488
|
"getJSON",
|
|
2489
2489
|
"|",
|
|
2490
2490
|
// H: 视图/版本 (meta-view)
|
|
2491
|
-
"fullscreen",
|
|
2492
2491
|
"snapshot",
|
|
2493
2492
|
"compare",
|
|
2494
|
-
"autoFormat"
|
|
2493
|
+
"autoFormat",
|
|
2494
|
+
"fullscreen"
|
|
2495
2495
|
], [Ie.toolbar]), { manager: a, isReady: Q, isFocused: L, isEmpty: R, containerRef: Z, setContentFromProp: ce } = wt({
|
|
2496
2496
|
config: Ie,
|
|
2497
2497
|
onUpdate(C, D) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cyte-editor/react",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "React adapter for CyteEditor rich text editor",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react editor",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@tiptap/pm": "^2.27.2",
|
|
35
|
-
"@cyte-editor/core": "1.3.
|
|
35
|
+
"@cyte-editor/core": "1.3.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@tiptap/core": "^2.11.0",
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"react": "^18.0.0 || ^19.0.0",
|
|
51
51
|
"react-dom": "^18.0.0 || ^19.0.0",
|
|
52
|
-
"@cyte-editor/pro-paste": "^1.3.
|
|
53
|
-
"@cyte-editor/pro-export": "^1.3.
|
|
54
|
-
"@cyte-editor/pro-revision": "^1.3.
|
|
55
|
-
"@cyte-editor/license": "^1.3.
|
|
52
|
+
"@cyte-editor/pro-paste": "^1.3.1",
|
|
53
|
+
"@cyte-editor/pro-export": "^1.3.1",
|
|
54
|
+
"@cyte-editor/pro-revision": "^1.3.1",
|
|
55
|
+
"@cyte-editor/license": "^1.3.1"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {
|
|
58
58
|
"@cyte-editor/pro-paste": {
|