@cyte-editor/react 1.1.1 → 1.1.2

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,20 +1,20 @@
1
1
  "use strict";/*!
2
- * CyteEditor React Adapter v1.1.1 (@cyte-editor/react)
2
+ * CyteEditor React Adapter v1.1.2 (@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: cf421a8-dirty @ 2026-10-07T06:46:49.092Z
9
+ * Build: cfb1024-dirty @ 2026-10-07T07:54:59.683Z
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 l=require("react/jsx-runtime"),c=require("react"),_=require("@cyte-editor/core"),xn=require("@cyte-editor/license"),Ye=require("react-dom");function qt(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let o=n.child(r),s=e.child(r);if(o==s){t+=o.nodeSize;continue}if(!o.sameMarkup(s))return t;if(o.isText&&o.text!=s.text){for(let i=0;o.text[i]==s.text[i];i++)t++;return t}if(o.content.size||s.content.size){let i=qt(o.content,s.content,t+1);if(i!=null)return i}t+=o.nodeSize}}function Yt(n,e,t,r){for(let o=n.childCount,s=e.childCount;;){if(o==0||s==0)return o==s?null:{a:t,b:r};let i=n.child(--o),a=e.child(--s),u=i.nodeSize;if(i==a){t-=u,r-=u;continue}if(!i.sameMarkup(a))return{a:t,b:r};if(i.isText&&i.text!=a.text){let d=0,p=Math.min(i.text.length,a.text.length);for(;d<p&&i.text[i.text.length-d-1]==a.text[a.text.length-d-1];)d++,t--,r--;return{a:t,b:r}}if(i.content.size||a.content.size){let d=Yt(i.content,a.content,t-1,r-1);if(d)return d}t-=u,r-=u}}class G{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let r=0;r<e.length;r++)this.size+=e[r].nodeSize}nodesBetween(e,t,r,o=0,s){for(let i=0,a=0;a<t;i++){let u=this.content[i],d=a+u.nodeSize;if(d>e&&r(u,o+a,s||null,i)!==!1&&u.content.size){let p=a+1;u.nodesBetween(Math.max(0,e-p),Math.min(u.content.size,t-p),r,o+p)}a=d}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,o){let s="",i=!0;return this.nodesBetween(e,t,(a,u)=>{let d=a.isText?a.text.slice(Math.max(e,u)-u,t-u):a.isLeaf?o?typeof o=="function"?o(a):o:a.type.spec.leafText?a.type.spec.leafText(a):"":"";a.isBlock&&(a.isLeaf&&d||a.isTextblock)&&r&&(i?i=!1:s+=r),s+=d},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,o=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(r)&&(o[o.length-1]=t.withText(t.text+r.text),s=1);s<e.content.length;s++)o.push(e.content[s]);return new G(o,this.size+e.size)}cut(e,t=this.size){if(e==0&&t==this.size)return this;let r=[],o=0;if(t>e)for(let s=0,i=0;i<t;s++){let a=this.content[s],u=i+a.nodeSize;u>e&&((i<e||u>t)&&(a.isText?a=a.cut(Math.max(0,e-i),Math.min(a.text.length,t-i)):a=a.cut(Math.max(0,e-i-1),Math.min(a.content.size,t-i-1))),r.push(a),o+=a.nodeSize),i=u}return new G(r,o)}cutByIndex(e,t){return e==t?G.empty:e==0&&t==this.content.length?this:new G(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let o=this.content.slice(),s=this.size+t.nodeSize-r.nodeSize;return o[e]=t,new G(o,s)}addToStart(e){return new G([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new G(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw new RangeError("Index "+e+" out of range for "+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,r=0;t<this.content.length;t++){let o=this.content[t];e(o,r,t),r+=o.nodeSize}}findDiffStart(e,t=0){return qt(this,e,t)}findDiffEnd(e,t=this.size,r=e.size){return Yt(this,e,t,r)}findIndex(e){if(e==0)return st(0,e);if(e==this.size)return st(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,r=0;;t++){let o=this.child(t),s=r+o.nodeSize;if(s>=e)return s==e?st(t+1,s):st(t,r);r=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return G.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new G(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return G.empty;let t,r=0;for(let o=0;o<e.length;o++){let s=e[o];r+=s.nodeSize,o&&s.isText&&e[o-1].sameMarkup(s)?(t||(t=e.slice(0,o)),t[t.length-1]=s.withText(t[t.length-1].text+s.text)):t&&t.push(s)}return new G(t||e,r)}static from(e){if(!e)return G.empty;if(e instanceof G)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new G([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}G.empty=new G([],0);const yt={index:0,offset:0};function st(n,e){return yt.index=n,yt.offset=e,yt}class yn extends Error{}class q{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=Xt(this.content,e+this.openStart,t);return r&&new q(r,this.openStart,this.openEnd)}removeBetween(e,t){return new q(Gt(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return q.empty;let r=t.openStart||0,o=t.openEnd||0;if(typeof r!="number"||typeof o!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new q(G.fromJSON(e,t.content),r,o)}static maxOpen(e,t=!0){let r=0,o=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)r++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)o++;return new q(e,r,o)}}q.empty=new q(G.empty,0,0);function Gt(n,e,t){let{index:r,offset:o}=n.findIndex(e),s=n.maybeChild(r),{index:i,offset:a}=n.findIndex(t);if(o==e||s.isText){if(a!=t&&!n.child(i).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=i)throw new RangeError("Removing non-flat range");return n.replaceChild(r,s.copy(Gt(s.content,e-o-1,t-o-1)))}function Xt(n,e,t,r){let{index:o,offset:s}=n.findIndex(e),i=n.maybeChild(o);if(s==e||i.isText)return r&&!r.canReplace(o,o,t)?null:n.cut(0,e).append(t).append(n.cut(e));let a=Xt(i.content,e-s-1,t,i);return a&&n.replaceChild(o,i.copy(a))}const Zt=65535,Qt=Math.pow(2,16);function vn(n,e){return n+e*Qt}function $t(n){return n&Zt}function bn(n){return(n-(n&Zt))/Qt}const en=1,tn=2,dt=4,nn=8;class Ht{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&nn)>0}get deletedBefore(){return(this.delInfo&(en|dt))>0}get deletedAfter(){return(this.delInfo&(tn|dt))>0}get deletedAcross(){return(this.delInfo&dt)>0}}class ye{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&ye.empty)return ye.empty}recover(e){let t=0,r=$t(e);if(!this.inverted)for(let o=0;o<r;o++)t+=this.ranges[o*3+2]-this.ranges[o*3+1];return this.ranges[r*3]+t+bn(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,r){let o=0,s=this.inverted?2:1,i=this.inverted?1:2;for(let a=0;a<this.ranges.length;a+=3){let u=this.ranges[a]-(this.inverted?o:0);if(u>e)break;let d=this.ranges[a+s],p=this.ranges[a+i],v=u+d;if(e<=v){let M=d?e==u?-1:e==v?1:t:t,g=u+o+(M<0?0:p);if(r)return g;let b=e==(t<0?u:v)?null:vn(a/3,e-u),x=e==u?tn:e==v?en:dt;return(t<0?e!=u:e!=v)&&(x|=nn),new Ht(g,x,b)}o+=p-d}return r?e+o:new Ht(e+o,0,null)}touches(e,t){let r=0,o=$t(t),s=this.inverted?2:1,i=this.inverted?1:2;for(let a=0;a<this.ranges.length;a+=3){let u=this.ranges[a]-(this.inverted?r:0);if(u>e)break;let d=this.ranges[a+s],p=u+d;if(e<=p&&a==o*3)return!0;r+=this.ranges[a+i]-d}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let o=0,s=0;o<this.ranges.length;o+=3){let i=this.ranges[o],a=i-(this.inverted?s:0),u=i+(this.inverted?0:s),d=this.ranges[o+t],p=this.ranges[o+r];e(a,a+d,u,u+p),s+=p-d}}invert(){return new ye(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?ye.empty:new ye(e<0?[0,-e,0]:[0,0,e])}}ye.empty=new ye([]);const vt=Object.create(null);class me{getMap(){return ye.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=vt[t.stepType];if(!r)throw new RangeError(`No step type ${t.stepType} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in vt)throw new RangeError("Duplicate use of step JSON ID "+e);return vt[e]=t,t.prototype.jsonID=e,t}}class ae{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new ae(e,null)}static fail(e){return new ae(null,e)}static fromReplace(e,t,r,o){try{return ae.ok(e.replace(t,r,o))}catch(s){if(s instanceof yn)return ae.fail(s.message);throw s}}}function Lt(n,e,t){let r=[];for(let o=0;o<n.childCount;o++){let s=n.child(o);s.content.size&&(s=s.copy(Lt(s.content,e,s))),s.isInline&&(s=e(s,t,o)),r.push(s)}return G.fromArray(r)}class ze extends me{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=e.resolve(this.from),o=r.node(r.sharedDepth(this.to)),s=new q(Lt(t.content,(i,a)=>!i.isAtom||!a.type.allowsMarkType(this.mark.type)?i:i.mark(this.mark.addToSet(i.marks)),o),t.openStart,t.openEnd);return ae.fromReplace(e,this.from,this.to,s)}invert(){return new Pe(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new ze(t.pos,r.pos,this.mark)}merge(e){return e instanceof ze&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new ze(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new ze(t.from,t.to,e.markFromJSON(t.mark))}}me.jsonID("addMark",ze);class Pe extends me{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new q(Lt(t.content,o=>o.mark(this.mark.removeFromSet(o.marks)),e),t.openStart,t.openEnd);return ae.fromReplace(e,this.from,this.to,r)}invert(){return new ze(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new Pe(t.pos,r.pos,this.mark)}merge(e){return e instanceof Pe&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Pe(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Pe(t.from,t.to,e.markFromJSON(t.mark))}}me.jsonID("removeMark",Pe);class Fe extends me{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return ae.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return ae.fromReplace(e,this.pos,this.pos+1,new q(G.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let o=0;o<t.marks.length;o++)if(!t.marks[o].isInSet(r))return new Fe(this.pos,t.marks[o]);return new Fe(this.pos,this.mark)}}return new tt(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Fe(t.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new Fe(t.pos,e.markFromJSON(t.mark))}}me.jsonID("addNodeMark",Fe);class tt extends me{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return ae.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return ae.fromReplace(e,this.pos,this.pos+1,new q(G.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new Fe(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new tt(t.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new tt(t.pos,e.markFromJSON(t.mark))}}me.jsonID("removeNodeMark",tt);class Re extends me{constructor(e,t,r,o=!1){super(),this.from=e,this.to=t,this.slice=r,this.structure=o}apply(e){return this.structure&&Rt(e,this.from,this.to)?ae.fail("Structure replace would overwrite content"):ae.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new ye([this.from,this.to-this.from,this.slice.size])}invert(e){return new Re(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deletedAcross&&r.deletedAcross?null:new Re(t.pos,Math.max(t.pos,r.pos),this.slice,this.structure)}merge(e){if(!(e instanceof Re)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let t=this.slice.size+e.slice.size==0?q.empty:new q(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new Re(this.from,this.to+(e.to-e.from),t,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let t=this.slice.size+e.slice.size==0?q.empty:new q(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new Re(e.from,this.to,t,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new Re(t.from,t.to,q.fromJSON(e,t.slice),!!t.structure)}}me.jsonID("replace",Re);class qe extends me{constructor(e,t,r,o,s,i,a=!1){super(),this.from=e,this.to=t,this.gapFrom=r,this.gapTo=o,this.slice=s,this.insert=i,this.structure=a}apply(e){if(this.structure&&(Rt(e,this.from,this.gapFrom)||Rt(e,this.gapTo,this.to)))return ae.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return ae.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,t.content);return r?ae.fromReplace(e,this.from,this.to,r):ae.fail("Content does not fit in gap")}getMap(){return new ye([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let t=this.gapTo-this.gapFrom;return new qe(this.from,this.from+this.slice.size+t,this.from+this.insert,this.from+this.insert+t,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1),o=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),s=this.to==this.gapTo?r.pos:e.map(this.gapTo,1);return t.deletedAcross&&r.deletedAcross||o<t.pos||s>r.pos?null:new qe(t.pos,r.pos,o,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new qe(t.from,t.to,t.gapFrom,t.gapTo,q.fromJSON(e,t.slice),t.insert,!!t.structure)}}me.jsonID("replaceAround",qe);function Rt(n,e,t){let r=n.resolve(e),o=t-e,s=r.depth;for(;o>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,o--;if(o>0){let i=r.node(s).maybeChild(r.indexAfter(s));for(;o>0;){if(!i||i.isLeaf)return!0;i=i.firstChild,o--}}return!1}class et extends me{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return ae.fail("No node at attribute step's position");let r=Object.create(null);for(let s in t.attrs)r[s]=t.attrs[s];r[this.attr]=this.value;let o=t.type.create(r,null,t.marks);return ae.fromReplace(e,this.pos,this.pos+1,new q(G.from(o),0,t.isLeaf?0:1))}getMap(){return ye.empty}invert(e){return new et(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new et(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new et(t.pos,t.attr,t.value)}}me.jsonID("attr",et);class ht extends me{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let o in e.attrs)t[o]=e.attrs[o];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return ae.ok(r)}getMap(){return ye.empty}invert(e){return new ht(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new ht(t.attr,t.value)}}me.jsonID("docAttr",ht);let nt=class extends Error{};nt=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};nt.prototype=Object.create(Error.prototype);nt.prototype.constructor=nt;nt.prototype.name="TransformError";const bt=Object.create(null);class X{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new rn(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t<e.length;t++)if(e[t].$from.pos!=e[t].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,t=q.empty){let r=t.content.lastChild,o=null;for(let a=0;a<t.openEnd;a++)o=r,r=r.lastChild;let s=e.steps.length,i=this.ranges;for(let a=0;a<i.length;a++){let{$from:u,$to:d}=i[a],p=e.mapping.slice(s);e.replaceRange(p.map(u.pos),p.map(d.pos),a?q.empty:t),a==0&&Pt(e,s,(r?r.isInline:o&&o.isTextblock)?-1:1)}}replaceWith(e,t){let r=e.steps.length,o=this.ranges;for(let s=0;s<o.length;s++){let{$from:i,$to:a}=o[s],u=e.mapping.slice(r),d=u.map(i.pos),p=u.map(a.pos);s?e.deleteRange(d,p):(e.replaceRangeWith(d,p,t),Pt(e,r,t.isInline?-1:1))}}static findFrom(e,t,r=!1){let o=e.parent.inlineContent?new ve(e):Ve(e.node(0),e.parent,e.pos,e.index(),t,r);if(o)return o;for(let s=e.depth-1;s>=0;s--){let i=t<0?Ve(e.node(0),e.node(s),e.before(s+1),e.index(s),t,r):Ve(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,r);if(i)return i}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Te(e.node(0))}static atStart(e){return Ve(e,e,0,0,1)||new Te(e)}static atEnd(e){return Ve(e,e,e.content.size,e.childCount,-1)||new Te(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=bt[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in bt)throw new RangeError("Duplicate use of selection JSON ID "+e);return bt[e]=t,t.prototype.jsonID=e,t}getBookmark(){return ve.between(this.$anchor,this.$head).getBookmark()}}X.prototype.visible=!0;class rn{constructor(e,t){this.$from=e,this.$to=t}}let Bt=!1;function zt(n){!Bt&&!n.parent.inlineContent&&(Bt=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}class ve extends X{constructor(e,t=e){zt(e),zt(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return X.near(r);let o=e.resolve(t.map(this.anchor));return new ve(o.parent.inlineContent?o:r,r)}replace(e,t=q.empty){if(super.replace(e,t),t==q.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof ve&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new mt(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new ve(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let o=e.resolve(t);return new this(o,r==t?o:e.resolve(r))}static between(e,t,r){let o=e.pos-t.pos;if((!r||o)&&(r=o>=0?1:-1),!t.parent.inlineContent){let s=X.findFrom(t,r,!0)||X.findFrom(t,-r,!0);if(s)t=s.$head;else return X.near(t,r)}return e.parent.inlineContent||(o==0?e=t:(e=(X.findFrom(e,-r,!0)||X.findFrom(e,r,!0)).$anchor,e.pos<t.pos!=o<0&&(e=t))),new ve(e,t)}}X.jsonID("text",ve);class mt{constructor(e,t){this.anchor=e,this.head=t}map(e){return new mt(e.map(this.anchor),e.map(this.head))}resolve(e){return ve.between(e.resolve(this.anchor),e.resolve(this.head))}}class Se extends X{constructor(e){let t=e.nodeAfter,r=e.node(0).resolve(e.pos+t.nodeSize);super(e,r),this.node=t}map(e,t){let{deleted:r,pos:o}=t.mapResult(this.anchor),s=e.resolve(o);return r?X.near(s):new Se(s)}content(){return new q(G.from(this.node),0,0)}eq(e){return e instanceof Se&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Dt(this.anchor)}static fromJSON(e,t){if(typeof t.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new Se(e.resolve(t.anchor))}static create(e,t){return new Se(e.resolve(t))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}Se.prototype.visible=!1;X.jsonID("node",Se);class Dt{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:r}=e.mapResult(this.anchor);return t?new mt(r,r):new Dt(r)}resolve(e){let t=e.resolve(this.anchor),r=t.nodeAfter;return r&&Se.isSelectable(r)?new Se(t):X.near(t)}}class Te extends X{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=q.empty){if(t==q.empty){e.delete(0,e.doc.content.size);let r=X.atStart(e.doc);r.eq(e.selection)||e.setSelection(r)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new Te(e)}map(e){return new Te(e)}eq(e){return e instanceof Te}getBookmark(){return kn}}X.jsonID("all",Te);const kn={map(){return this},resolve(n){return new Te(n)}};function Ve(n,e,t,r,o,s=!1){if(e.inlineContent)return ve.create(n,t);for(let i=r-(o>0?0:1);o>0?i<e.childCount:i>=0;i+=o){let a=e.child(i);if(a.isAtom){if(!s&&Se.isSelectable(a))return Se.create(n,t-(o<0?a.nodeSize:0))}else{let u=Ve(n,a,t+o,o<0?a.childCount:0,o,s);if(u)return u}t+=a.nodeSize*o}return null}function Pt(n,e,t){let r=n.steps.length-1;if(r<e)return;let o=n.steps[r];if(!(o instanceof Re||o instanceof qe))return;let s=n.mapping.maps[r],i;s.forEach((a,u,d,p)=>{i==null&&(i=p)}),n.setSelection(X.near(n.doc.resolve(i),t))}function Ft(n,e){return!e||!n?n:n.bind(e)}class lt{constructor(e,t,r){this.name=e,this.init=Ft(t.init,r),this.apply=Ft(t.apply,r)}}new lt("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new lt("selection",{init(n,e){return n.selection||X.atStart(e.doc)},apply(n){return n.selection}}),new lt("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new lt("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}});const kt=Object.create(null);function Cn(n){return n in kt?n+"$"+ ++kt[n]:(kt[n]=0,n+"$")}class At{constructor(e="key"){this.key=Cn(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}var Ae={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},pt={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},jn=typeof navigator<"u"&&/Mac/.test(navigator.platform),Sn=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var fe=0;fe<10;fe++)Ae[48+fe]=Ae[96+fe]=String(fe);for(var fe=1;fe<=24;fe++)Ae[fe+111]="F"+fe;for(var fe=65;fe<=90;fe++)Ae[fe]=String.fromCharCode(fe+32),pt[fe]=String.fromCharCode(fe);for(var Ct in Ae)pt.hasOwnProperty(Ct)||(pt[Ct]=Ae[Ct]);function Nn(n){var e=jn&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||Sn&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?pt:Ae)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}const Mn=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),Rn=typeof navigator<"u"&&/Win/.test(navigator.platform);function Tn(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,o,s,i;for(let a=0;a<e.length-1;a++){let u=e[a];if(/^(cmd|meta|m)$/i.test(u))i=!0;else if(/^a(lt)?$/i.test(u))r=!0;else if(/^(c|ctrl|control)$/i.test(u))o=!0;else if(/^s(hift)?$/i.test(u))s=!0;else if(/^mod$/i.test(u))Mn?i=!0:o=!0;else throw new Error("Unrecognized modifier name: "+u)}return r&&(t="Alt-"+t),o&&(t="Ctrl-"+t),i&&(t="Meta-"+t),s&&(t="Shift-"+t),t}function En(n){let e=Object.create(null);for(let t in n)e[Tn(t)]=n[t];return e}function jt(n,e,t=!0){return e.altKey&&(n="Alt-"+n),e.ctrlKey&&(n="Ctrl-"+n),e.metaKey&&(n="Meta-"+n),t&&e.shiftKey&&(n="Shift-"+n),n}function Ln(n){let e=En(n);return function(t,r){let o=Nn(r),s,i=e[jt(o,r)];if(i&&i(t.state,t.dispatch,t))return!0;if(o.length==1&&o!=" "){if(r.shiftKey){let a=e[jt(o,r,!1)];if(a&&a(t.state,t.dispatch,t))return!0}if((r.altKey||r.metaKey||r.ctrlKey)&&!(Rn&&r.ctrlKey&&r.altKey)&&(s=Ae[r.keyCode])&&s!=o){let a=e[jt(s,r)];if(a&&a(t.state,t.dispatch,t))return!0}}return!1}}let Tt,Et;if(typeof WeakMap<"u"){let n=new WeakMap;Tt=e=>n.get(e),Et=(e,t)=>(n.set(e,t),t)}else{const n=[];let t=0;Tt=r=>{for(let o=0;o<n.length;o+=2)if(n[o]==r)return n[o+1]},Et=(r,o)=>(t==10&&(t=0),n[t++]=r,n[t++]=o)}var je=class{constructor(n,e,t,r){this.width=n,this.height=e,this.map=t,this.problems=r}findCell(n){for(let e=0;e<this.map.length;e++){const t=this.map[e];if(t!=n)continue;const r=e%this.width,o=e/this.width|0;let s=r+1,i=o+1;for(let a=1;s<this.width&&this.map[e+a]==t;a++)s++;for(let a=1;i<this.height&&this.map[e+this.width*a]==t;a++)i++;return{left:r,top:o,right:s,bottom:i}}throw new RangeError(`No cell with offset ${n} found`)}colCount(n){for(let e=0;e<this.map.length;e++)if(this.map[e]==n)return e%this.width;throw new RangeError(`No cell with offset ${n} found`)}nextCell(n,e,t){const{left:r,right:o,top:s,bottom:i}=this.findCell(n);return e=="horiz"?(t<0?r==0:o==this.width)?null:this.map[s*this.width+(t<0?r-1:o)]:(t<0?s==0:i==this.height)?null:this.map[r+this.width*(t<0?s-1:i)]}rectBetween(n,e){const{left:t,right:r,top:o,bottom:s}=this.findCell(n),{left:i,right:a,top:u,bottom:d}=this.findCell(e);return{left:Math.min(t,i),top:Math.min(o,u),right:Math.max(r,a),bottom:Math.max(s,d)}}cellsInRect(n){const e=[],t={};for(let r=n.top;r<n.bottom;r++)for(let o=n.left;o<n.right;o++){const s=r*this.width+o,i=this.map[s];t[i]||(t[i]=!0,!(o==n.left&&o&&this.map[s-1]==i||r==n.top&&r&&this.map[s-this.width]==i)&&e.push(i))}return e}positionAt(n,e,t){for(let r=0,o=0;;r++){const s=o+t.child(r).nodeSize;if(r==n){let i=e+n*this.width;const a=(n+1)*this.width;for(;i<a&&this.map[i]<o;)i++;return i==a?s-1:this.map[i]}o=s}}static get(n){return Tt(n)||Et(n,Dn(n))}};function Dn(n){if(n.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+n.type.name);const e=An(n),t=n.childCount,r=[];let o=0,s=null;const i=[];for(let d=0,p=e*t;d<p;d++)r[d]=0;for(let d=0,p=0;d<t;d++){const v=n.child(d);p++;for(let b=0;;b++){for(;o<r.length&&r[o]!=0;)o++;if(b==v.childCount)break;const x=v.child(b),{colspan:S,rowspan:f,colwidth:h}=x.attrs;for(let k=0;k<f;k++){if(k+d>=t){(s||(s=[])).push({type:"overlong_rowspan",pos:p,n:f-k});break}const y=o+k*e;for(let m=0;m<S;m++){r[y+m]==0?r[y+m]=p:(s||(s=[])).push({type:"collision",row:d,pos:p,n:S-m});const C=h&&h[m];if(C){const D=(y+m)%e*2,H=i[D];H==null||H!=C&&i[D+1]==1?(i[D]=C,i[D+1]=1):H==C&&i[D+1]++}}}o+=S,p+=x.nodeSize}const M=(d+1)*e;let g=0;for(;o<M;)r[o++]==0&&g++;g&&(s||(s=[])).push({type:"missing",row:d,n:g}),p++}(e===0||t===0)&&(s||(s=[])).push({type:"zero_sized"});const a=new je(e,t,r,s);let u=!1;for(let d=0;!u&&d<i.length;d+=2)i[d]!=null&&i[d+1]<t&&(u=!0);return u&&In(a,i,n),a}function An(n){let e=-1,t=!1;for(let r=0;r<n.childCount;r++){const o=n.child(r);let s=0;if(t)for(let i=0;i<r;i++){const a=n.child(i);for(let u=0;u<a.childCount;u++){const d=a.child(u);i+d.attrs.rowspan>r&&(s+=d.attrs.colspan)}}for(let i=0;i<o.childCount;i++){const a=o.child(i);s+=a.attrs.colspan,a.attrs.rowspan>1&&(t=!0)}e==-1?e=s:e!=s&&(e=Math.max(e,s))}return e}function In(n,e,t){n.problems||(n.problems=[]);const r={};for(let o=0;o<n.map.length;o++){const s=n.map[o];if(r[s])continue;r[s]=!0;const i=t.nodeAt(s);if(!i)throw new RangeError(`No cell with offset ${s} found`);let a=null;const u=i.attrs;for(let d=0;d<u.colspan;d++){const p=e[(o+d)%n.width*2];p!=null&&(!u.colwidth||u.colwidth[d]!=p)&&((a||(a=On(u)))[d]=p)}a&&n.problems.unshift({type:"colwidth mismatch",pos:s,colwidth:a})}}function On(n){if(n.colwidth)return n.colwidth.slice();const e=[];for(let t=0;t<n.colspan;t++)e.push(0);return e}function It(n){let e=n.cached.tableNodeTypes;if(!e){e=n.cached.tableNodeTypes={};for(const t in n.nodes){const r=n.nodes[t],o=r.spec.tableRole;o&&(e[o]=r)}}return e}new At("selectingCells");function $n(n){for(let e=n.depth-1;e>0;e--)if(n.node(e).type.spec.tableRole=="row")return n.node(0).resolve(n.before(e+1));return null}function on(n){const e=n.selection.$head;for(let t=e.depth;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return!0;return!1}function Hn(n){const e=n.selection;if("$anchorCell"in e&&e.$anchorCell)return e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell;if("node"in e&&e.node&&e.node.type.spec.tableRole=="cell")return e.$anchor;const t=$n(e.$head)||Bn(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function Bn(n){for(let e=n.nodeAfter,t=n.pos;e;e=e.firstChild,t++){const r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t)}for(let e=n.nodeBefore,t=n.pos;e;e=e.lastChild,t--){const r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t-e.nodeSize)}}function Jt(n){return n.parent.type.spec.tableRole=="row"&&!!n.nodeAfter}function sn(n,e){return n.depth==e.depth&&n.pos>=e.start(-1)&&n.pos<=e.end(-1)}function ln(n,e,t){const r=n.node(-1),o=je.get(r),s=n.start(-1),i=o.nextCell(n.pos-s,e,t);return i==null?null:n.node(0).resolve(s+i)}function Wt(n,e,t=1){const r={...n,colspan:n.colspan-t};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,t),r.colwidth.some(o=>o>0)||(r.colwidth=null)),r}var Ee=class Me extends X{constructor(e,t=e){const r=e.node(-1),o=je.get(r),s=e.start(-1),i=o.rectBetween(e.pos-s,t.pos-s),a=e.node(0),u=o.cellsInRect(i).filter(p=>p!=t.pos-s);u.unshift(t.pos-s);const d=u.map(p=>{const v=r.nodeAt(p);if(!v)throw new RangeError(`No cell with offset ${p} found`);const M=s+p+1;return new rn(a.resolve(M),a.resolve(M+v.content.size))});super(d[0].$from,d[0].$to,d),this.$anchorCell=e,this.$headCell=t}map(e,t){const r=e.resolve(t.map(this.$anchorCell.pos)),o=e.resolve(t.map(this.$headCell.pos));if(Jt(r)&&Jt(o)&&sn(r,o)){const s=this.$anchorCell.node(-1)!=r.node(-1);return s&&this.isRowSelection()?Me.rowSelection(r,o):s&&this.isColSelection()?Me.colSelection(r,o):new Me(r,o)}return ve.between(r,o)}content(){const e=this.$anchorCell.node(-1),t=je.get(e),r=this.$anchorCell.start(-1),o=t.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),s={},i=[];for(let u=o.top;u<o.bottom;u++){const d=[];for(let p=u*t.width+o.left,v=o.left;v<o.right;v++,p++){const M=t.map[p];if(s[M])continue;s[M]=!0;const g=t.findCell(M);let b=e.nodeAt(M);if(!b)throw new RangeError(`No cell with offset ${M} found`);const x=o.left-g.left,S=g.right-o.right;if(x>0||S>0){let f=b.attrs;if(x>0&&(f=Wt(f,0,x)),S>0&&(f=Wt(f,f.colspan-S,S)),g.left<o.left){if(b=b.type.createAndFill(f),!b)throw new RangeError(`Could not create cell with attrs ${JSON.stringify(f)}`)}else b=b.type.create(f,b.content)}if(g.top<o.top||g.bottom>o.bottom){const f={...b.attrs,rowspan:Math.min(g.bottom,o.bottom)-Math.max(g.top,o.top)};g.top<o.top?b=b.type.createAndFill(f):b=b.type.create(f,b.content)}d.push(b)}i.push(e.child(u).copy(G.from(d)))}const a=this.isColSelection()&&this.isRowSelection()?e:i;return new q(G.from(a),1,1)}replace(e,t=q.empty){const r=e.steps.length,o=this.ranges;for(let i=0;i<o.length;i++){const{$from:a,$to:u}=o[i],d=e.mapping.slice(r);e.replace(d.map(a.pos),d.map(u.pos),i?q.empty:t)}const s=X.findFrom(e.doc.resolve(e.mapping.slice(r).map(this.to)),-1);s&&e.setSelection(s)}replaceWith(e,t){this.replace(e,new q(G.from(t),0,0))}forEachCell(e){const t=this.$anchorCell.node(-1),r=je.get(t),o=this.$anchorCell.start(-1),s=r.cellsInRect(r.rectBetween(this.$anchorCell.pos-o,this.$headCell.pos-o));for(let i=0;i<s.length;i++)e(t.nodeAt(s[i]),o+s[i])}isColSelection(){const e=this.$anchorCell.index(-1),t=this.$headCell.index(-1);if(Math.min(e,t)>0)return!1;const r=e+this.$anchorCell.nodeAfter.attrs.rowspan,o=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,o)==this.$headCell.node(-1).childCount}static colSelection(e,t=e){const r=e.node(-1),o=je.get(r),s=e.start(-1),i=o.findCell(e.pos-s),a=o.findCell(t.pos-s),u=e.node(0);return i.top<=a.top?(i.top>0&&(e=u.resolve(s+o.map[i.left])),a.bottom<o.height&&(t=u.resolve(s+o.map[o.width*(o.height-1)+a.right-1]))):(a.top>0&&(t=u.resolve(s+o.map[a.left])),i.bottom<o.height&&(e=u.resolve(s+o.map[o.width*(o.height-1)+i.right-1]))),new Me(e,t)}isRowSelection(){const e=this.$anchorCell.node(-1),t=je.get(e),r=this.$anchorCell.start(-1),o=t.colCount(this.$anchorCell.pos-r),s=t.colCount(this.$headCell.pos-r);if(Math.min(o,s)>0)return!1;const i=o+this.$anchorCell.nodeAfter.attrs.colspan,a=s+this.$headCell.nodeAfter.attrs.colspan;return Math.max(i,a)==t.width}eq(e){return e instanceof Me&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,t=e){const r=e.node(-1),o=je.get(r),s=e.start(-1),i=o.findCell(e.pos-s),a=o.findCell(t.pos-s),u=e.node(0);return i.left<=a.left?(i.left>0&&(e=u.resolve(s+o.map[i.top*o.width])),a.right<o.width&&(t=u.resolve(s+o.map[o.width*(a.top+1)-1]))):(a.left>0&&(t=u.resolve(s+o.map[a.top*o.width])),i.right<o.width&&(e=u.resolve(s+o.map[o.width*(i.top+1)-1]))),new Me(e,t)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(e,t){return new Me(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){return new Me(e.resolve(t),e.resolve(r))}getBookmark(){return new zn(this.$anchorCell.pos,this.$headCell.pos)}};Ee.prototype.visible=!1;X.jsonID("cell",Ee);var zn=class an{constructor(e,t){this.anchor=e,this.head=t}map(e){return new an(e.map(this.anchor),e.map(this.head))}resolve(e){const t=e.resolve(this.anchor),r=e.resolve(this.head);return t.parent.type.spec.tableRole=="row"&&r.parent.type.spec.tableRole=="row"&&t.index()<t.parent.childCount&&r.index()<r.parent.childCount&&sn(t,r)?new Ee(t,r):X.near(r,1)}};new At("fix-tables");function cn(n){const e=n.selection,t=Hn(n),r=t.node(-1),o=t.start(-1),s=je.get(r);return{...e instanceof Ee?s.rectBetween(e.$anchorCell.pos-o,e.$headCell.pos-o):s.findCell(t.pos-o),tableStart:o,map:s,table:r}}function Pn(n){return function(e,t){if(!on(e))return!1;if(t){const r=It(e.schema),o=cn(e),s=e.tr,i=o.map.cellsInRect(n=="column"?{left:o.left,top:0,right:o.right,bottom:o.map.height}:n=="row"?{left:0,top:o.top,right:o.map.width,bottom:o.bottom}:o),a=i.map(u=>o.table.nodeAt(u));for(let u=0;u<i.length;u++)a[u].type==r.header_cell&&s.setNodeMarkup(o.tableStart+i[u],r.cell,a[u].attrs);if(s.steps.length===0)for(let u=0;u<i.length;u++)s.setNodeMarkup(o.tableStart+i[u],r.header_cell,a[u].attrs);t(s)}return!0}}function Kt(n,e,t){const r=e.map.cellsInRect({left:0,top:0,right:n=="row"?e.map.width:1,bottom:n=="column"?e.map.height:1});for(let o=0;o<r.length;o++){const s=e.table.nodeAt(r[o]);if(s&&s.type!==t.header_cell)return!1}return!0}function Ot(n,e){return e=e||{useDeprecatedLogic:!1},e.useDeprecatedLogic?Pn(n):function(t,r){if(!on(t))return!1;if(r){const o=It(t.schema),s=cn(t),i=t.tr,a=Kt("row",s,o),u=Kt("column",s,o),d=(n==="column"?a:n==="row"&&u)?1:0,p=n=="column"?{left:0,top:d,right:1,bottom:s.map.height}:n=="row"?{left:d,top:0,right:s.map.width,bottom:1}:s,v=n=="column"?u?o.cell:o.header_cell:n=="row"?a?o.cell:o.header_cell:o.cell;s.map.cellsInRect(p).forEach(M=>{const g=M+s.tableStart,b=i.doc.nodeAt(g);b&&i.setNodeMarkup(g,v,b.attrs)}),r(i)}return!0}}Ot("row",{useDeprecatedLogic:!0});Ot("column",{useDeprecatedLogic:!0});Ot("cell",{useDeprecatedLogic:!0});function it(n,e){const t=n.selection;if(!(t instanceof Ee))return!1;if(e){const r=n.tr,o=It(n.schema).cell.createAndFill().content;t.forEachCell((s,i)=>{s.content.eq(o)||r.replace(r.mapping.map(i+1),r.mapping.map(i+s.nodeSize-1),new q(o,0,0))}),r.docChanged&&e(r)}return!0}Ln({ArrowLeft:at("horiz",-1),ArrowRight:at("horiz",1),ArrowUp:at("vert",-1),ArrowDown:at("vert",1),"Shift-ArrowLeft":ct("horiz",-1),"Shift-ArrowRight":ct("horiz",1),"Shift-ArrowUp":ct("vert",-1),"Shift-ArrowDown":ct("vert",1),Backspace:it,"Mod-Backspace":it,Delete:it,"Mod-Delete":it});function ft(n,e,t){return t.eq(n.selection)?!1:(e&&e(n.tr.setSelection(t).scrollIntoView()),!0)}function at(n,e){return(t,r,o)=>{if(!o)return!1;const s=t.selection;if(s instanceof Ee)return ft(t,r,X.near(s.$headCell,e));if(n!="horiz"&&!s.empty)return!1;const i=un(o,n,e);if(i==null)return!1;if(n=="horiz")return ft(t,r,X.near(t.doc.resolve(s.head+e),e));{const a=t.doc.resolve(i),u=ln(a,n,e);let d;return u?d=X.near(u,1):e<0?d=X.near(t.doc.resolve(a.before(-1)),-1):d=X.near(t.doc.resolve(a.after(-1)),1),ft(t,r,d)}}}function ct(n,e){return(t,r,o)=>{if(!o)return!1;const s=t.selection;let i;if(s instanceof Ee)i=s;else{const u=un(o,n,e);if(u==null)return!1;i=new Ee(t.doc.resolve(u))}const a=ln(i.$headCell,n,e);return a?ft(t,r,new Ee(i.$anchorCell,a)):!1}}function un(n,e,t){if(!(n.state.selection instanceof ve))return null;const{$head:r}=n.state.selection;for(let o=r.depth-1;o>=0;o--){const s=r.node(o);if((t<0?r.index(o):r.indexAfter(o))!=(t<0?0:s.childCount))return null;if(s.type.spec.tableRole=="cell"||s.type.spec.tableRole=="header_cell"){const i=r.before(o),a=e=="vert"?t>0?"down":"up":t>0?"right":"left";return n.endOfTextblock(a)?i:null}}return null}new At("tableColumnResizing");function dn(n){var g,b;const e=c.useRef(null),t=c.useRef(null),[r,o]=c.useState(!1),[s,i]=c.useState(!1),[a,u]=c.useState(!0),d=c.useRef(!1),p=c.useRef(n);p.current=n;const v=c.useCallback((x,S)=>{if(!(d.current||!t.current)){if(S!==void 0){const f=JSON.stringify(t.current.getJSON()),h=JSON.stringify(S);if(f===h)return;t.current.setJSON(S);return}if(x!==void 0){if(x===t.current.getHTML())return;t.current.setContent(x)}}},[]);c.useEffect(()=>{var f,h;const x=e.current;if(!x)return;const S=_.EditorManager.create(x,p.current.config);return t.current=S,u(S.isEmpty()),S.on("update",({html:k})=>{var y,m;u(S.isEmpty()),d.current=!0,(m=(y=p.current).onUpdate)==null||m.call(y,k,S.getJSON()),Promise.resolve().then(()=>{d.current=!1})}),S.on("focus",({event:k})=>{var y,m;i(!0),(m=(y=p.current).onFocus)==null||m.call(y,k)}),S.on("blur",({event:k})=>{var y,m;i(!1),(m=(y=p.current).onBlur)==null||m.call(y,k)}),o(!0),(h=(f=p.current).onReady)==null||h.call(f,S),()=>{S.destroy(),t.current=null,o(!1)}},[]),c.useEffect(()=>{const x=t.current;x&&n.config.readonly!==void 0&&x.setReadonly(n.config.readonly)},[n.config.readonly,n.config.disabled]),c.useEffect(()=>{n.config.locale&&_.I18nManager.getInstance().setLocale(n.config.locale)},[n.config.locale]);const M=c.useRef((g=n.config.license)==null?void 0:g.key);return c.useEffect(()=>{var S;const x=(S=n.config.license)==null?void 0:S.key;x!==M.current&&(M.current=x,x&&t.current&&t.current.updateLicense(n.config.license))},[(b=n.config.license)==null?void 0:b.key]),{manager:t.current,isReady:r,isFocused:s,isEmpty:a,containerRef:e,setContentFromProp:v}}function fn(n){const[e,t]=c.useState({}),[r,o]=c.useState({}),s=c.useCallback(async()=>{if(!n)return;const i=n.getEditor(),a={},u={};for(const[M,g]of Object.entries(_.toolbarItemDefs))g.isActive&&(a[M]=g.isActive(i)),g.isDisabled&&(u[M]=g.isDisabled(i));const d=xn.getLicenseStatus(),p=d==="valid"||d==="expiring_soon",v=await n.hasSnapshots();if(u.compare=!v||!p,!p)for(const[M,g]of Object.entries(_.toolbarItemDefs))g.requiredTier&&M!=="compare"&&(u[M]=!0);for(const[M,g]of Object.entries(_.toolbarItemDefs))g.requiresPlugin&&!n.hasProPlugin(g.requiresPlugin)&&(u[M]=!0);t(a),o(u)},[n]);return c.useEffect(()=>{if(n)return n.on("selectionUpdate",s),n.on("update",s),n.on("transaction",s),n.on("snapshot-created",s),s(),()=>{n.off("selectionUpdate",s),n.off("update",s),n.off("transaction",s),n.off("snapshot-created",s)}},[n,s]),{activeStates:e,disabledStates:r,refresh:s}}function we(){const n=_.I18nManager.getInstance(),[e,t]=c.useState(0);c.useEffect(()=>n.onChange(()=>{t(s=>s+1)}),[n]);function r(o,s){return n.t(o,s)}return{t:r,locale:n.getLocale()}}const Fn={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>'};function Ie(n){return Fn[n]||""}const Jn=({visible:n,targetRect:e,editor:t,savedSelection:r,initialUrl:o,isEditing:s,onConfirm:i,onCancel:a,onClose:u})=>{const{t:d}=we(),[p,v]=c.useState(o||""),[M,g]=c.useState(!1),b=c.useRef(null),[x,S]=c.useState(null),[f,h]=c.useState(""),k=()=>{if(t&&r)try{const{from:j,to:E}=r,A=t.view.coordsAtPos(j),O=t.view.coordsAtPos(E);if(A&&O){S(new DOMRect(A.left,A.top,O.left-A.left,A.bottom-A.top));return}}catch{}S(e||null)};c.useEffect(()=>{const j=()=>{n&&k()};return window.addEventListener("scroll",j,!0),window.addEventListener("resize",j),()=>{window.removeEventListener("scroll",j,!0),window.removeEventListener("resize",j)}},[n,t,r,e]),c.useEffect(()=>{n&&(v(o||""),h(""),k(),setTimeout(()=>{var j,E;(j=b.current)==null||j.focus(),(E=b.current)==null||E.select()},0))},[n]);const y=c.useMemo(()=>{const j=x;if(!j)return{};const E=180,A=8,O=window.innerHeight,V=window.innerWidth;let B=j.bottom+A,P=!1;B+E>O&&(B=j.top-E-A,P=!0),g(P);let z=j.left+j.width/2;const I=320;return z+I/2>V&&(z=V-I/2-16),z<I/2+16&&(z=I/2+16),{top:`${B}px`,left:`${z}px`}},[x]),m=j=>{try{const E=new URL(j);return E.protocol==="http:"||E.protocol==="https:"}catch{return!1}},C=()=>{const j=p.trim();if(s&&j===""){i(""),u();return}if(!j){h(d("link.urlRequired"));return}if(!m(j)){h(d("link.invalidUrl"));return}i(j),u()},D=()=>{i(""),u()},H=()=>{a(),u()};return n?l.jsx("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,zIndex:9998,background:"transparent"},onMouseDown:j=>{j.target===j.currentTarget&&H()},children:l.jsxs("div",{className:`tp-link-popover${M?" is-above":""}`,style:y,onMouseDown:j=>j.stopPropagation(),onKeyDown:j=>{j.key==="Enter"?(j.preventDefault(),C()):j.key==="Escape"&&(j.preventDefault(),H())},children:[l.jsx("div",{className:"tp-popover-arrow"}),l.jsxs("div",{className:"tp-popover-content",children:[l.jsx("div",{className:"tp-popover-header",children:l.jsx("span",{className:"tp-popover-title",children:d(s?"link.editLink":"link.insertLink")})}),l.jsxs("div",{className:"tp-popover-body",children:[l.jsx("label",{className:"tp-popover-label",children:d("link.url")}),l.jsxs("div",{className:"tp-popover-input-row",children:[l.jsx("input",{ref:b,type:"url",className:`tp-popover-input${f?" is-error":""}`,value:p,placeholder:d("link.url"),onChange:j=>v(j.target.value),onKeyDown:j=>{j.key==="Enter"?(j.preventDefault(),C()):j.key==="Escape"&&(j.preventDefault(),H())}}),l.jsx("button",{className:"tp-popover-btn-confirm",onClick:C,children:d("common.confirm")}),s&&l.jsx("button",{className:"tp-popover-btn-unlink",onClick:D,children:d("link.unlink")})]}),f&&l.jsx("div",{className:"tp-link-error-message",children:f})]})]})]})}):null},Wn="#b4d5fe",Kn=({def:n,editor:e,active:t,disabled:r,onCustomClick:o})=>{const{t:s}=we(),[i,a]=c.useState(!1),u=c.useRef(null),d=c.useRef(null),p=c.useRef(""),v=c.useRef(!1),M=f=>{var h;if(f.preventDefault(),n.name==="link"){const{from:k,to:y}=e.state.selection;if(k!==y||e.isActive("link")){if(u.current={from:k,to:y},e.isActive("link")){const m=e.state.selection.$head.marks().find(C=>C.type.name==="link");p.current=((h=m==null?void 0:m.attrs)==null?void 0:h.href)||"",v.current=!0}else p.current="",v.current=!1;if(!e.isActive("link")){const m=window.getSelection();if(m&&m.rangeCount>0){const D=m.getRangeAt(0).getBoundingClientRect();D.width>0&&D.height>0&&(d.current=D)}}}}},g=()=>{var h,k;const f=n.name;if(f==="getHTML"||f==="getJSON"||f==="importWord"||f==="importMarkdown"||f==="exportWord"||f==="exportMarkdown"||f==="snapshot"||f==="compare"||f==="fullscreen"){o==null||o(f);return}if(f==="link"){if(e.isActive("link")){if(!u.current){const{from:m,to:C}=e.state.selection;u.current={from:m,to:C}}const y=e.state.selection.$head.marks().find(m=>m.type.name==="link");if(p.current=((h=y==null?void 0:y.attrs)==null?void 0:h.href)||"",v.current=!0,!d.current&&u.current)try{const{from:m,to:C}=u.current,D=e.view.coordsAtPos(m),H=e.view.coordsAtPos(C);D&&H&&(d.current=new DOMRect(D.left,D.top,H.left-D.left,H.bottom-D.top))}catch{}a(!0);return}if(!u.current){const{from:y,to:m}=e.state.selection;if(y===m)return;u.current={from:y,to:m}}if(p.current="",v.current=!1,!d.current&&u.current)try{const{from:y,to:m}=u.current,C=e.view.coordsAtPos(y),D=e.view.coordsAtPos(m);C&&D&&(d.current=new DOMRect(C.left,C.top,D.left-C.left,C.bottom-C.top))}catch{}if(u.current){const{from:y,to:m}=u.current;e.chain().focus().setTextSelection({from:y,to:m}).setHighlight({color:Wn}).run()}a(!0);return}(k=n.command)==null||k.call(n,e)},b=f=>{if(u.current){const{from:h,to:k}=u.current,y=e.chain().focus().setTextSelection({from:h,to:k}).unsetHighlight();f?y.setLink({href:f}).run():y.unsetLink().run()}u.current=null,d.current=null,p.current="",v.current=!1},x=()=>{if(u.current){const{from:f,to:h}=u.current;e.chain().focus().setTextSelection({from:f,to:h}).unsetHighlight().run()}u.current=null,d.current=null,p.current="",v.current=!1},S=n.name==="getHTML"||n.name==="getJSON";return l.jsxs(l.Fragment,{children:[l.jsx("button",{className:`tp-toolbar-btn${t?" is-active":""}${S?" is-text-btn":""}`,disabled:r,title:s(n.titleKey),onMouseDown:M,onClick:g,children:n.name==="getHTML"?l.jsx("span",{className:"tp-toolbar-text",children:"HTML"}):n.name==="getJSON"?l.jsx("span",{className:"tp-toolbar-text",children:"JSON"}):l.jsx("span",{className:"tp-toolbar-icon",dangerouslySetInnerHTML:{__html:Ie(n.name)}})}),l.jsx(Jn,{visible:i,targetRect:d.current,editor:e,savedSelection:u.current,initialUrl:p.current,isEditing:v.current,onConfirm:b,onCancel:x,onClose:()=>a(!1)})]})},Ut={SimSun:["SimSun","宋体"],宋体:["SimSun","宋体"],"Microsoft YaHei":["Microsoft YaHei","微软雅黑"],微软雅黑:["Microsoft YaHei","微软雅黑"],SimHei:["SimHei","黑体"],黑体:["SimHei","黑体"],KaiTi:["KaiTi","楷体"],楷体:["KaiTi","楷体"]},Un=({def:n,editor:e,active:t,disabled:r,onCustomClick:o})=>{var S;const{t:s}=we(),[i,a]=c.useState(!1),[u,d]=c.useState(0),p=c.useRef(null),v=c.useMemo(()=>{var f;return(f=n.getCurrentValue)==null?void 0:f.call(n,e)},[u,n,e]),M=f=>{const h=String(v),k=String(f);if(n.name==="fontFamily"){const y=Ut[h],m=Ut[k];if(y)return y.includes(k);if(m)return m.includes(h)}return h===k},g=f=>{const h=Number(f);return h===0?"tp-heading-preview-paragraph":h>=1&&h<=6?`tp-heading-preview-h${h}`:""},b=()=>{r||(a(!i),i||d(f=>f+1))},x=f=>{var h;n.isActionMenu?o==null||o(String(f)):(h=n.command)==null||h.call(n,e,f),a(!1)};return c.useEffect(()=>{const f=k=>{p.current&&!p.current.contains(k.target)&&a(!1)},h=()=>d(k=>k+1);return document.addEventListener("pointerdown",f),e.on("transaction",h),()=>{document.removeEventListener("pointerdown",f),e.off("transaction",h)}},[e]),l.jsxs("div",{ref:p,className:"tp-toolbar-dropdown",children:[l.jsxs("button",{className:`tp-toolbar-dropdown-trigger${t?" is-active":""}${r?" is-disabled":""}`,title:s(n.tooltipKey||n.titleKey),disabled:r,onMouseDown:f=>f.preventDefault(),onClick:b,children:[l.jsx("span",{className:"tp-toolbar-icon",dangerouslySetInnerHTML:{__html:Ie(n.name)}}),!n.hideLabel&&l.jsx("span",{className:"tp-toolbar-dropdown-label",children:s(n.titleKey)}),l.jsx("span",{className:"tp-toolbar-dropdown-arrow",children:"▾"})]}),i&&l.jsx("div",{className:"tp-toolbar-dropdown-menu",children:(S=n.options)==null?void 0:S.map(f=>l.jsx("button",{className:`tp-toolbar-dropdown-item${M(f.value)?" is-active":""}${n.name==="heading"?" "+g(f.value):""}`,onMouseDown:h=>h.preventDefault(),onClick:()=>x(f.value),children:f.labelKey?s(f.labelKey):f.label},String(f.value)))})]})},_n=["#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"],Vn=["#ff0000","#ff5e00","#ff9900","#ffff00","#00ff00","#00a8a8","#00ffff","#0000ff","#5f00ff","#9900ff"],qn=({def:n,editor:e,disabled:t})=>{const{t:r}=we(),[o,s]=c.useState(!1),i=c.useRef(null),[a,u]=c.useState(""),[d,p]=c.useState(""),v=n.name==="color",M=v?a:d,g=()=>{const S=e.getAttributes("textStyle");u((S==null?void 0:S.color)||"");const f=e.getAttributes("highlight");p((f==null?void 0:f.color)||"")};c.useEffect(()=>{const S=f=>{i.current&&!i.current.contains(f.target)&&s(!1)};return document.addEventListener("pointerdown",S),e.on("transaction",g),e.on("selectionUpdate",g),g(),()=>{document.removeEventListener("pointerdown",S),e.off("transaction",g),e.off("selectionUpdate",g)}},[e]);const b=S=>{var f;(f=n.command)==null||f.call(n,e,S),setTimeout(g,0),s(!1)},x=()=>{var S;(S=n.command)==null||S.call(n,e,void 0),p(""),s(!1)};return l.jsxs("div",{ref:i,className:"tp-toolbar-dropdown",children:[l.jsxs("button",{className:`tp-toolbar-dropdown-trigger${t?" is-disabled":""}`,title:r(n.titleKey),disabled:t,onMouseDown:S=>S.preventDefault(),onClick:()=>{t||s(!o)},children:[l.jsx("span",{className:v?"tp-color-picker-icon":"tp-bgcolor-picker-icon",children:v?l.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:[l.jsx("text",{x:"4",y:"17",fontSize:"24",fill:"currentColor",stroke:"none",fontFamily:"serif",fontWeight:"bold",children:"A"}),l.jsx("line",{x1:"4",y1:"22",x2:"20",y2:"22",strokeWidth:"5",stroke:a||"#000000"})]}):l.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:[l.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",fill:d||"transparent"}),l.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),l.jsx("text",{x:"6",y:"17",fontSize:"16",fill:"currentColor",stroke:"none",fontFamily:"serif",fontWeight:"bold",children:"A"})]})}),l.jsx("span",{className:"tp-toolbar-dropdown-arrow",children:"▾"})]}),o&&l.jsxs("div",{className:"tp-color-picker-panel",children:[l.jsx("button",{className:"tp-color-default-btn",onMouseDown:S=>S.preventDefault(),onClick:x,children:r("common.default")}),l.jsx("div",{className:"tp-color-grid tp-theme-colors",children:_n.map((S,f)=>l.jsx("button",{className:`tp-color-swatch${M===S?" tp-color-swatch-selected":""}`,style:{backgroundColor:S},title:S,onMouseDown:h=>h.preventDefault(),onClick:()=>b(S)},`theme-${f}`))}),l.jsx("div",{className:"tp-color-section-label",children:r("common.standardColor")}),l.jsx("div",{className:"tp-color-grid tp-standard-colors",children:Vn.map((S,f)=>l.jsx("button",{className:`tp-color-swatch${M===S?" tp-color-swatch-selected":""}`,style:{backgroundColor:S},title:S,onMouseDown:h=>h.preventDefault(),onClick:()=>b(S)},`std-${f}`))})]})]})},_t=()=>l.jsx("div",{className:"tp-toolbar-separator"}),Yn=({visible:n,editor:e,uploadUrl:t,uploadHeaders:r,onUpload:o,initialTab:s,onClose:i})=>{const{t:a}=we(),[u,d]=c.useState(s||"upload"),[p,v]=c.useState(""),[M,g]=c.useState(!1),[b,x]=c.useState(!1),[S,f]=c.useState(0),[h,k]=c.useState(""),y=c.useRef(null);c.useEffect(()=>(n?(v(""),k(""),d(s||"upload"),f(0),document.body.style.overflow="hidden"):document.body.style.overflow="",()=>{document.body.style.overflow=""}),[n,s]);const m=j=>new Promise((E,A)=>{const O=new FileReader;O.onload=()=>E(O.result),O.onerror=A,O.readAsDataURL(j)}),C=j=>{e.chain().focus().setImage({src:j}).run()},D=async j=>{x(!0),f(0),k("");try{let E;o?E=await o(j):t?E=await _.uploadFile(j,{url:t,headers:r,onProgress:f}):E=await m(j),C(E),i()}catch(E){k(E instanceof Error?E.message:a("imageUpload.uploadFailed"))}finally{x(!1),f(0)}},H=()=>{const j=p.trim();if(!j){k(a("imageUpload.urlRequired"));return}try{new URL(j)}catch{k(a("imageUpload.invalidUrl"));return}C(j),i()};return n?l.jsx("div",{className:"tp-image-upload-overlay",onMouseDown:j=>{j.target===j.currentTarget&&i()},children:l.jsxs("div",{className:"tp-image-upload-dialog",onMouseDown:j=>j.stopPropagation(),children:[l.jsxs("div",{className:"tp-dialog-header",children:[l.jsx("span",{className:"tp-dialog-title",children:a("image.upload")}),l.jsx("button",{className:"tp-dialog-close",onClick:i,children:"×"})]}),l.jsxs("div",{className:"tp-dialog-tabs",children:[l.jsx("button",{className:`tp-tab-btn${u==="upload"?" is-active":""}`,onClick:()=>d("upload"),children:a("imageUpload.uploadLocal")}),l.jsx("button",{className:`tp-tab-btn${u==="url"?" is-active":""}`,onClick:()=>d("url"),children:a("imageUpload.inputUrl")})]}),l.jsxs("div",{className:"tp-dialog-body",children:[u==="upload"&&l.jsxs("div",{className:"tp-upload-tab",children:[l.jsx("div",{className:`tp-dropzone${M?" is-dragging":""}${b?" is-uploading":""}`,onDragEnter:j=>{j.preventDefault(),g(!0)},onDragLeave:j=>{j.preventDefault(),g(!1)},onDragOver:j=>j.preventDefault(),onDrop:j=>{var A,O;j.preventDefault(),g(!1);const E=(O=(A=j.dataTransfer)==null?void 0:A.files)==null?void 0:O[0];E!=null&&E.type.startsWith("image/")?D(E):k(a("imageUpload.invalidType"))},onClick:()=>{var j;return(j=y.current)==null?void 0:j.click()},children:b?l.jsxs("div",{className:"tp-upload-progress",children:[l.jsx("div",{className:"tp-progress-bar",children:l.jsx("div",{className:"tp-progress-fill",style:{width:S+"%"}})}),l.jsxs("span",{className:"tp-progress-text",children:[a("imageUpload.uploading")," ",S,"%"]})]}):l.jsxs("div",{className:"tp-dropzone-content",children:[l.jsx("span",{className:"tp-dropzone-icon",children:"📁"}),l.jsx("span",{className:"tp-dropzone-text",children:a("imageUpload.selectFile")}),l.jsx("span",{className:"tp-dropzone-hint",children:a("imageUpload.dragHint")})]})}),l.jsx("input",{ref:y,type:"file",accept:"image/*",style:{display:"none"},onChange:j=>{var A;const E=(A=j.target.files)==null?void 0:A[0];E&&D(E),j.target.value=""}})]}),u==="url"&&l.jsxs("div",{className:"tp-url-tab",children:[l.jsx("label",{className:"tp-input-label",children:a("imageUpload.url")}),l.jsxs("div",{className:"tp-input-row",children:[l.jsx("input",{className:"tp-url-input",type:"url",value:p,placeholder:a("imageUpload.placeholder"),onChange:j=>v(j.target.value),onKeyDown:j=>{j.key==="Enter"&&H(),j.key==="Escape"&&i()}}),l.jsx("button",{className:"tp-confirm-btn",onClick:H,children:a("common.confirm")})]})]}),h&&l.jsx("div",{className:"tp-error-message",children:h})]})]})}):null},Gn=({def:n,editor:e,manager:t,active:r,disabled:o})=>{var f,h,k,y;const{t:s}=we(),[i,a]=c.useState(!1),[u,d]=c.useState(!1),[p,v]=c.useState("upload"),M=c.useRef(null),g=(f=t==null?void 0:t.getConfig().upload)==null?void 0:f.url,b=(h=t==null?void 0:t.getConfig().upload)==null?void 0:h.headers,x=(k=t==null?void 0:t.getConfig().upload)==null?void 0:k.onUpload;c.useEffect(()=>{const m=C=>{M.current&&!M.current.contains(C.target)&&a(!1)};return document.addEventListener("pointerdown",m),()=>document.removeEventListener("pointerdown",m)},[]);const S=m=>{a(!1),m==="upload"?(v("upload"),d(!0)):m==="url"&&(v("url"),d(!0))};return l.jsxs("div",{ref:M,className:"tp-toolbar-dropdown",children:[l.jsxs("button",{className:`tp-toolbar-dropdown-trigger${r?" is-active":""}${o?" is-disabled":""}`,title:s(n.titleKey),disabled:o,onMouseDown:m=>m.preventDefault(),onClick:()=>{o||a(!i)},children:[l.jsx("span",{className:"tp-toolbar-icon",dangerouslySetInnerHTML:{__html:Ie(n.name)}}),l.jsx("span",{className:"tp-toolbar-dropdown-arrow",children:"▾"})]}),i&&l.jsx("div",{className:"tp-toolbar-dropdown-menu",children:(y=n.options)==null?void 0:y.map(m=>l.jsx("button",{className:"tp-toolbar-dropdown-item",onMouseDown:C=>C.preventDefault(),onClick:()=>S(m.value),children:m.labelKey?s(m.labelKey):m.label},String(m.value)))}),l.jsx(Yn,{visible:u,editor:e,uploadUrl:g,uploadHeaders:b,onUpload:x,initialTab:p,onClose:()=>d(!1)})]})},Xn=({visible:n,editor:e,onSuccess:t,onCancel:r,onClose:o})=>{const{t:s}=we(),[i,a]=c.useState(""),[u,d]=c.useState(""),p=c.useRef(null);c.useEffect(()=>(n?(a(""),d(""),document.body.style.overflow="hidden",setTimeout(()=>{var x;return(x=p.current)==null?void 0:x.focus()},100)):document.body.style.overflow="",()=>{document.body.style.overflow=""}),[n]);const v=c.useCallback(()=>{const x=i.trim();if(!x){d(s("video.urlRequired"));return}try{new URL(x)}catch{d(s("video.invalidUrl"));return}e.chain().focus().setVideo({src:x}).run(),t==null||t(x),o()},[i,e,s,t,o]),M=c.useCallback(()=>{r==null||r(),o()},[r,o]),g=c.useCallback(x=>{x.target===x.currentTarget&&M()},[M]),b=c.useCallback(x=>{x.key==="Enter"?(x.preventDefault(),v()):x.key==="Escape"&&(x.preventDefault(),M())},[v,M]);return n?Ye.createPortal(l.jsx("div",{className:"tp-video-dialog-overlay",onMouseDown:g,children:l.jsxs("div",{className:"tp-video-dialog",onMouseDown:x=>x.stopPropagation(),onKeyDown:b,children:[l.jsxs("div",{className:"tp-dialog-header",children:[l.jsx("span",{className:"tp-dialog-title",children:s("video.title")}),l.jsx("button",{className:"tp-dialog-close",onClick:M,children:"×"})]}),l.jsxs("div",{className:"tp-dialog-body",children:[l.jsx("label",{className:"tp-input-label",children:s("video.url")}),l.jsxs("div",{className:"tp-input-row",children:[l.jsx("input",{ref:p,type:"url",className:"tp-url-input",placeholder:s("video.placeholder"),value:i,onChange:x=>a(x.target.value),onKeyDown:b}),l.jsx("button",{className:"tp-confirm-btn",onClick:v,children:s("common.confirm")})]}),l.jsx("p",{className:"tp-hint",children:s("video.hint")}),u&&l.jsx("div",{className:"tp-error-message",children:u})]})]})}),document.body):null},Zn=({def:n,editor:e,active:t,disabled:r})=>{const{t:o}=we(),[s,i]=c.useState(!1),a=()=>{r||i(!0)};return l.jsxs("div",{className:"tp-toolbar-video-btn",children:[l.jsx("button",{className:`tp-toolbar-btn${t?" is-active":""}${r?" is-disabled":""}`,title:o(n.titleKey),disabled:r,onMouseDown:u=>u.preventDefault(),onClick:a,children:l.jsx("span",{className:"tp-toolbar-icon",dangerouslySetInnerHTML:{__html:Ie(n.name)}})}),l.jsx(Xn,{visible:s,editor:e,onSuccess:()=>{},onClose:()=>i(!1)})]})},Qn=10,er=10,tr=({def:n,editor:e,active:t,disabled:r})=>{const{t:o}=we(),[s,i]=c.useState(!1),[a,u]=c.useState({row:0,col:0}),d=c.useRef(null),p=()=>{r||(i(!s),u({row:0,col:0}))},v=(g,b)=>{u({row:g,col:b})},M=(g,b)=>{e.chain().focus().insertTable({rows:g,cols:b,withHeaderRow:!0}).run(),i(!1),u({row:0,col:0})};return c.useEffect(()=>{const g=b=>{d.current&&!d.current.contains(b.target)&&(i(!1),u({row:0,col:0}))};return document.addEventListener("pointerdown",g),()=>document.removeEventListener("pointerdown",g)},[]),l.jsxs("div",{ref:d,className:"tp-toolbar-dropdown",children:[l.jsxs("button",{className:`tp-toolbar-dropdown-trigger${t?" is-active":""}${r?" is-disabled":""}`,title:o(n.titleKey),disabled:r,onMouseDown:g=>g.preventDefault(),onClick:p,children:[l.jsx("span",{className:"tp-toolbar-icon",dangerouslySetInnerHTML:{__html:Ie(n.name)}}),l.jsx("span",{className:"tp-toolbar-dropdown-arrow",children:"▾"})]}),s&&l.jsxs("div",{className:"tp-table-grid-dropdown",children:[l.jsx("div",{className:"tp-table-grid-header",children:a.row>0?`${a.row} × ${a.col}`:o("table.insertHint")}),l.jsx("div",{className:"tp-table-grid",children:Array.from({length:Qn},(g,b)=>l.jsx("div",{className:"tp-table-grid-row",children:Array.from({length:er},(x,S)=>{const f=b+1,h=S+1;return l.jsx("div",{className:`tp-table-grid-cell${f<=a.row&&h<=a.col?" is-hovered":""}${f===a.row&&h===a.col?" is-selected":""}`,onMouseEnter:()=>v(f,h),onClick:()=>M(f,h)},`${f}-${h}`)})},b))})]})]})},nr=({editor:n,disabled:e=!1})=>{const{t}=we(),r=c.useRef("none"),[o,s]=c.useState("none"),i=c.useRef([]),a=c.useRef(null),u=c.useRef(null),d=c.useRef(null),p=c.useRef(void 0),v=c.useRef(null),M=c.useRef(0),g=c.useRef(!1),b=o!=="none",x=c.useCallback(()=>{const{from:E,to:A}=n.state.selection;if(n.isActive("orderedList"))return"orderedList";if(n.isActive("bulletList"))return"bulletList";const O=Math.min(E+1,A),V=n.state.doc.resolve(O);if(V.parent.type.name==="listItem")for(let P=V.depth;P>0;P--){const z=V.node(P);if(z.type.name==="orderedList")return"orderedList";if(z.type.name==="bulletList")return"bulletList"}return null},[n]),S=c.useCallback(()=>{const{from:E,to:A}=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 O=Math.min(E+1,A);if(n.state.doc.resolve(O).parent.type.name==="paragraph")return null},[n]),f=c.useCallback(()=>{const{from:E,to:A,empty:O}=n.state.selection;if(O)return!1;const B=n.state.doc.resolve(Math.min(E+1,A)).marks();i.current=[...B];const P=x();a.current=P;const z=n.getAttributes("textStyle");u.current={color:z.color,fontFamily:z.fontFamily,fontSize:z.fontSize};const I=n.getAttributes("paragraph"),$=n.getAttributes("heading");d.current={textAlign:I.textAlign||$.textAlign,lineHeight:I.lineHeight||$.lineHeight},p.current=S();const J=B.length>0,K=!!z.color||!!z.fontFamily||!!z.fontSize,ee=!!d.current.textAlign||!!d.current.lineHeight;return J||K||ee||P!==null||p.current!==void 0},[n,x,S]),h=c.useCallback(()=>{if(!a.current)return;const E=n.chain().focus();switch(a.current){case"orderedList":n.isActive("orderedList")||(n.isActive("bulletList")&&E.toggleBulletList(),E.toggleOrderedList().run());break;case"bulletList":n.isActive("bulletList")||(n.isActive("orderedList")&&E.toggleOrderedList(),E.toggleBulletList().run());break}},[n]),k=c.useCallback(()=>{if(p.current===void 0)return;const E=n.chain().focus();if(p.current===null)E.setParagraph().run();else{const{schema:A}=n.state;A.nodes.heading&&E.setNode("heading",{level:p.current}).run()}},[n]),y=c.useCallback(()=>{let{state:E}=n,{from:A,to:O,empty:V}=E.selection;if(V)return!1;const{schema:B}=E;if(a.current?h():p.current!==void 0&&k(),d.current){const J=n.chain().focus();d.current.textAlign&&J.setTextAlign(d.current.textAlign),d.current.lineHeight&&J.setLineHeight(d.current.lineHeight),J.run()}E=n.state;const P=E.selection;if(A=P.from,O=P.to,i.current.length===0&&!u.current)return a.current!==null||d.current!==null||p.current!==void 0;const z=E.tr,I=[];if(i.current.forEach(J=>{const K=J.type.name;["bold","italic","underline","strike","superscript","subscript"].includes(K)&&I.push(J)}),u.current){const{color:J,fontFamily:K,fontSize:ee}=u.current,te={};if(J&&(te.color=J),K&&(te.fontFamily=K),ee&&(te.fontSize=ee),Object.keys(te).length>0&&B.marks.textStyle){const Ce=B.marks.textStyle.create(te);I.push(Ce)}}const $=i.current.find(J=>J.type.name==="highlight");return $&&I.push($),I.length===0||(E.doc.nodesBetween(A,O,(J,K)=>{if(J.isText&&K<O&&K+J.nodeSize>A){const ee=Math.max(K,A),te=Math.min(K+J.nodeSize,O);["bold","italic","underline","strike","superscript","subscript","textStyle","highlight"].forEach(ne=>{const he=B.marks[ne];he&&J.marks.some(ue=>ue.type===he)&&z.removeMark(ee,te,he)}),I.forEach(ne=>{z.addMark(ee,te,ne)})}}),z.docChanged&&n.view.dispatch(z)),!0},[n,h,k]),m=c.useCallback(()=>{r.current="none",s("none"),i.current=[],a.current=null,u.current=null,d.current=null,p.current=void 0},[]),C=c.useCallback(()=>{if(r.current==="none")return;const{empty:E}=n.state.selection;E||(y(),r.current==="single"&&m())},[n,y,m]),D=c.useCallback(()=>{if(r.current==="single"||r.current==="multiple"){m();return}f()&&(r.current="single",s("single"))},[f,m]),H=c.useCallback(()=>{if(r.current==="multiple"){m();return}f()&&(r.current="multiple",s("multiple"))},[f,m]),j=c.useCallback(()=>{e||(M.current++,M.current===1?v.current=window.setTimeout(()=>{D(),M.current=0,v.current=null},250):M.current===2&&(v.current&&(clearTimeout(v.current),v.current=null),H(),M.current=0))},[D,H]);return c.useEffect(()=>{e&&(m(),v.current&&(clearTimeout(v.current),v.current=null),M.current=0)},[e,m]),c.useEffect(()=>{const E=B=>{r.current==="none"||B.target.closest(".tp-toolbar-btn")||(g.current=!0)},A=B=>{!g.current||(g.current=!1,r.current==="none")||B.target.closest(".tp-toolbar-btn")||requestAnimationFrame(()=>C())},O=B=>{B.key==="Escape"&&r.current!=="none"&&m()},V=B=>{if(r.current==="none")return;const P=["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"];B.shiftKey&&P.includes(B.key)&&C()};return document.addEventListener("mousedown",E),document.addEventListener("mouseup",A),document.addEventListener("keydown",O),document.addEventListener("keyup",V),()=>{document.removeEventListener("mousedown",E),document.removeEventListener("mouseup",A),document.removeEventListener("keydown",O),document.removeEventListener("keyup",V),v.current&&clearTimeout(v.current)}},[C,m]),l.jsxs("button",{className:`tp-toolbar-btn${b?" is-active":""}${o==="multiple"?" is-locked":""}${e?" is-disabled":""}`,disabled:e,title:t("toolbar.formatPainter"),onClick:j,style:{position:"relative"},children:[l.jsx("span",{className:"tp-toolbar-icon",dangerouslySetInnerHTML:{__html:Ie("formatPainter")}}),o==="multiple"&&l.jsx("span",{className:"tp-format-painter-indicator",children:"🔒"})]})},rr=[{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."]}],or=({def:n,editor:e,active:t,disabled:r})=>{const{t:o}=we(),[s,i]=c.useState(!1),[a,u]=c.useState(0),d=c.useRef(null),p=()=>{const{state:y}=e,m=y.selection.$from;let C=null,D=0;for(let H=m.depth;H>=0;H--){const j=m.node(H);j.type.name==="orderedList"&&(C||(C=j),D++)}return{node:C,depth:D}},v=(()=>{const{node:y,depth:m}=p();return y&&y.attrs.listStyleType?y.attrs.listStyleType:m<=1?"decimal":m===2?"lower-alpha":"lower-roman"})(),M=(()=>{const{node:y}=p(),m=y==null?void 0:y.attrs.start;return m!=null?Number(m):1})(),g=(()=>{const{node:y}=p();return!!(y!=null&&y.attrs.reversed)})(),b=c.useCallback(()=>{var y;(y=n.command)==null||y.call(n,e)},[n,e]),x=c.useCallback(()=>{r||i(y=>!y)},[r]),S=c.useCallback(y=>{e.commands.createStyledOrderedList({listStyleType:y}),e.commands.focus(),i(!1)},[e]),f=c.useCallback(y=>{const m=parseInt(y.target.value,10);isNaN(m)||e.commands.setOrderedListAttrs({start:m})},[e]),h=c.useCallback(y=>{["Backspace","Delete","ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Tab","Home","End"].includes(y.key)||y.key==="-"||y.key==="Minus"||y.key>="0"&&y.key<="9"||y.ctrlKey||y.metaKey||y.preventDefault()},[]),k=c.useCallback(()=>{const y=!g;e.commands.setOrderedListAttrs({reversed:y||null})},[e,g]);return c.useEffect(()=>{const y=C=>{d.current&&!d.current.contains(C.target)&&i(!1)},m=()=>u(C=>C+1);return document.addEventListener("pointerdown",y),e.on("transaction",m),()=>{document.removeEventListener("pointerdown",y),e.off("transaction",m)}},[e]),l.jsxs("div",{ref:d,className:"tp-toolbar-split-btn",children:[l.jsx("button",{className:`tp-toolbar-split-main${t?" is-active":""}`,title:o(n.titleKey),disabled:r,onMouseDown:y=>y.preventDefault(),onClick:b,children:l.jsx("span",{className:"tp-toolbar-icon",dangerouslySetInnerHTML:{__html:Ie(n.name)}})}),l.jsx("button",{className:`tp-toolbar-split-arrow${s?" is-open":""}`,disabled:r,onMouseDown:y=>y.preventDefault(),onClick:x,children:"▾"}),s&&l.jsxs("div",{className:"tp-ol-panel",children:[l.jsx("div",{className:"tp-ol-style-grid",children:rr.map(y=>l.jsx("button",{className:`tp-ol-style-item${v===y.type?" is-active":""}`,onMouseDown:m=>m.preventDefault(),onClick:()=>S(y.type),children:y.lines.map((m,C)=>l.jsxs("span",{className:"tp-ol-style-line",children:[l.jsx("span",{className:"tp-ol-style-marker",children:m}),l.jsx("span",{className:"tp-ol-style-bar"})]},C))},y.type))}),l.jsxs("div",{className:"tp-ol-properties",children:[l.jsx("div",{className:"tp-ol-prop-title",children:o("orderedList.properties")}),l.jsxs("div",{className:"tp-ol-prop-row",children:[l.jsx("label",{children:o("orderedList.startAt")}),l.jsx("input",{type:"number",className:"tp-ol-start-input",defaultValue:M,onChange:f,onKeyDown:h,onMouseDown:y=>y.stopPropagation()})]}),l.jsxs("div",{className:"tp-ol-prop-row",children:[l.jsx("label",{children:o("orderedList.reversed")}),l.jsx("button",{className:`tp-ol-toggle${g?" is-on":""}`,onMouseDown:y=>y.preventDefault(),onClick:k})]})]})]})]})},sr=[{type:"disc",marker:"●"},{type:"circle",marker:"○"},{type:"square",marker:"■"},{type:"none",marker:"—"}],lr=({def:n,editor:e,active:t,disabled:r})=>{const{t:o}=we(),[s,i]=c.useState(!1),[a,u]=c.useState(0),d=c.useRef(null),p=(()=>{const{state:b}=e,x=b.selection.$from;let S=null,f=0;for(let h=x.depth;h>=0;h--){const k=x.node(h);k.type.name==="bulletList"&&(S||(S=k),f++)}return S&&S.attrs.listStyleType?S.attrs.listStyleType:f<=1?"disc":f===2?"circle":"square"})(),v=c.useCallback(()=>{var b;(b=n.command)==null||b.call(n,e)},[n,e]),M=c.useCallback(()=>{r||i(b=>!b)},[r]),g=c.useCallback(b=>{e.commands.createStyledBulletList({listStyleType:b}),e.commands.focus(),i(!1)},[e]);return c.useEffect(()=>{const b=S=>{d.current&&!d.current.contains(S.target)&&i(!1)},x=()=>u(S=>S+1);return document.addEventListener("pointerdown",b),e.on("transaction",x),()=>{document.removeEventListener("pointerdown",b),e.off("transaction",x)}},[e]),l.jsxs("div",{ref:d,className:"tp-toolbar-split-btn",children:[l.jsx("button",{className:`tp-toolbar-split-main${t?" is-active":""}`,title:o(n.titleKey),disabled:r,onMouseDown:b=>b.preventDefault(),onClick:v,children:l.jsx("span",{className:"tp-toolbar-icon",dangerouslySetInnerHTML:{__html:Ie(n.name)}})}),l.jsx("button",{className:`tp-toolbar-split-arrow${s?" is-open":""}`,disabled:r,onMouseDown:b=>b.preventDefault(),onClick:M,children:"▾"}),s&&l.jsx("div",{className:"tp-ol-panel",children:l.jsx("div",{className:"tp-ol-style-grid tp-ul-style-grid",children:sr.map(b=>l.jsx("button",{className:`tp-ol-style-item${p===b.type?" is-active":""}`,onMouseDown:x=>x.preventDefault(),onClick:()=>g(b.type),children:[0,1,2].map(x=>l.jsxs("span",{className:"tp-ol-style-line",children:[l.jsx("span",{className:"tp-ul-style-marker",children:b.marker}),l.jsx("span",{className:"tp-ol-style-bar"})]},x))},b.type))})})]})};function Vt(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 ir=({items:n,manager:e,activeStates:t,disabledStates:r,viewMode:o="normal",onToggleViewMode:s,onToolbarClick:i,prepend:a,append:u})=>{const d=()=>e.getEditor(),p=c.useCallback(f=>{if(f==="getHTML"){s==null||s("html");return}if(f==="getJSON"){s==null||s("json");return}i==null||i(f)},[s,i]),v=f=>o!=="normal"?f==="getHTML"?o==="html":f==="getJSON"?o==="json":!1:f==="getHTML"||f==="getJSON"?!1:t[f]??!1,M=f=>o!=="normal"?f!=="getHTML"&&f!=="getJSON":r[f]??!1,g=c.useMemo(()=>_.groupToolbarItems(n),[n]),b=g.filter(f=>f.category==="meta-left"||f.category==="content"),x=g.filter(f=>f.category==="meta-io"||f.category==="meta-view");function S(f){const h=_.getToolbarItemDef(f);if(!h)return null;const k=d();return f==="imageUpload"?l.jsx(Gn,{def:h,editor:k,manager:e,active:v(f),disabled:M(f)},f):f==="video"?l.jsx(Zn,{def:h,editor:k,active:v(f),disabled:M(f)},f):f==="insertTable"?l.jsx(tr,{def:h,editor:k,active:v(f),disabled:M(f)},f):f==="formatPainter"?l.jsx(nr,{editor:k,disabled:M(f)},f):f==="orderedList"?l.jsx(or,{def:h,editor:k,active:v(f),disabled:M(f)},f):f==="bulletList"?l.jsx(lr,{def:h,editor:k,active:v(f),disabled:M(f)},f):h.type==="button"?l.jsx(Kn,{def:h,editor:k,active:v(f),disabled:M(f),onCustomClick:p},f):h.type==="dropdown"?l.jsx(Un,{def:h,editor:k,active:v(f),disabled:M(f),onCustomClick:p},f):h.type==="color-picker"?l.jsx(qn,{def:h,editor:k,disabled:M(f)},f):null}return l.jsxs("div",{className:"tp-toolbar",children:[a,b.map((f,h)=>l.jsxs(c.Fragment,{children:[h>0&&l.jsx(_t,{}),f.category!=="content"?l.jsx("div",{className:Vt(f.category),children:f.items.map(S)}):l.jsx(l.Fragment,{children:f.items.map(S)})]},`g-${h}`)),x.length>0&&l.jsx("div",{className:"tp-toolbar-right",children:x.map((f,h)=>l.jsxs(c.Fragment,{children:[h>0&&l.jsx(_t,{}),l.jsx("div",{className:Vt(f.category),children:f.items.map(S)})]},`r-${h}`))}),u]})},hn=({editor:n,visible:e,position:t,targetCell:r,onVisibleChange:o,onAction:s})=>{const i=c.useRef(null),[a,u]=c.useState({x:0,y:0}),[d,p]=c.useState(!1),[v,M]=c.useState(!1),g=c.useRef({x:0,y:0}),b=_.I18nManager.getInstance(),x=h=>b.t(h),S=c.useCallback(h=>{if(!i.current)return h;const k=i.current.getBoundingClientRect();return k.width===0||k.height===0?h:_.adjustMenuPosition({x:h.x,y:h.y,width:k.width,height:k.height})},[]);c.useEffect(()=>{if(e){if(u({x:t.x,y:t.y}),r){const h=r.getBoundingClientRect();g.current={x:t.x-h.left,y:t.y-h.top}}p(n.can().mergeCells()),M(n.can().splitCell())}},[e,t,r,n]),c.useLayoutEffect(()=>{if(!e||!i.current)return;const h=i.current.getBoundingClientRect();if(h.width===0||h.height===0)return;const k=_.adjustMenuPosition({x:a.x,y:a.y,width:h.width,height:h.height});(k.x!==a.x||k.y!==a.y)&&u({x:k.x,y:k.y})},[e,a.x,a.y]),c.useEffect(()=>{const h=()=>{if(!e||!r)return;const y=r.getBoundingClientRect();if(y.bottom<0||y.top>window.innerHeight){o(!1);return}const m={x:y.left+g.current.x,y:y.top+g.current.y},C=S(m);u({x:C.x,y:C.y})},k=()=>{e&&h()};return window.addEventListener("scroll",k,!0),window.addEventListener("wheel",k,{passive:!0}),()=>{window.removeEventListener("scroll",k,!0),window.removeEventListener("wheel",k)}},[e,r,o,S]),c.useEffect(()=>{const h=y=>{i.current&&!i.current.contains(y.target)&&o(!1)},k=y=>{y.key==="Escape"&&o(!1)};return document.addEventListener("click",h),document.addEventListener("keydown",k),()=>{document.removeEventListener("click",h),document.removeEventListener("keydown",k)}},[o]);const f=c.useCallback(h=>{s(h),o(!1)},[s,o]);return e?Ye.createPortal(l.jsxs("div",{ref:i,className:"tp-table-context-menu",style:{left:a.x,top:a.y},onClick:h=>h.stopPropagation(),children:[l.jsxs("div",{className:"tp-table-menu-section",children:[l.jsx("div",{className:"tp-table-menu-item",onClick:()=>f("addRowBefore"),children:x("table.addRowBefore")}),l.jsx("div",{className:"tp-table-menu-item",onClick:()=>f("addRowAfter"),children:x("table.addRowAfter")}),l.jsx("div",{className:"tp-table-menu-item",onClick:()=>f("addColumnBefore"),children:x("table.addColumnBefore")}),l.jsx("div",{className:"tp-table-menu-item",onClick:()=>f("addColumnAfter"),children:x("table.addColumnAfter")})]}),l.jsx("div",{className:"tp-table-menu-divider"}),l.jsxs("div",{className:"tp-table-menu-section",children:[l.jsx("div",{className:`tp-table-menu-item${d?"":" disabled"}`,onClick:()=>d&&f("mergeCells"),children:x("table.mergeCells")}),l.jsx("div",{className:`tp-table-menu-item${v?"":" disabled"}`,onClick:()=>v&&f("splitCell"),children:x("table.splitCell")})]}),l.jsx("div",{className:"tp-table-menu-divider"}),l.jsxs("div",{className:"tp-table-menu-section",children:[l.jsx("div",{className:"tp-table-menu-item",onClick:()=>f("deleteRow"),children:x("table.deleteRow")}),l.jsx("div",{className:"tp-table-menu-item",onClick:()=>f("deleteColumn"),children:x("table.deleteColumn")}),l.jsx("div",{className:"tp-table-menu-item tp-table-menu-item-danger",onClick:()=>f("deleteTable"),children:x("table.deleteTable")})]}),l.jsx("div",{className:"tp-table-menu-divider"}),l.jsxs("div",{className:"tp-table-menu-section",children:[l.jsx("div",{className:"tp-table-menu-item",onClick:()=>f("tableSettings"),children:x("table.tableSettings")}),l.jsx("div",{className:"tp-table-menu-item",onClick:()=>f("cellSettings"),children:x("table.cellSettings")})]})]}),document.body):null},ar=["#000000","#1a1a1a","#333333","#4d4d4d","#666666","#808080","#999999","#b3b3b3","#1c4587","#1155cc","#3d85c6","#6fa8dc","#0b5394","#073763","#38761d","#6aa84f","#93c47d","#274e13","#990000","#cc0000","#e06666","#660000"],cr=["#ffffff","#f8f9fa","#f1f3f4","#e8eaed","#dadce0","#bdc1c6","#e6f4ea","#ceead6","#a8dab5","#81c995","#e8f0fe","#d2e3fc","#aecbfa","#8ab4f8","#fef7e0","#feefc3","#fde293","#fdd663","#fce8e6","#fadbd8","#f5aca6","#f28b82"];function ur(n){const e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(n);return e?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null}function St(n,e,t){return"#"+[n,e,t].map(r=>{const o=Math.round(Math.max(0,Math.min(255,r))).toString(16);return o.length===1?"0"+o:o}).join("")}function Nt(n,e,t){n/=255,e/=255,t/=255;const r=Math.max(n,e,t),o=Math.min(n,e,t);let s=0,i=0;const a=(r+o)/2;if(r!==o){const u=r-o;switch(i=a>.5?u/(2-r-o):u/(r+o),r){case n:s=((e-t)/u+(e<t?6:0))/6;break;case e:s=((t-n)/u+2)/6;break;case t:s=((n-e)/u+4)/6;break}}return{h:Math.round(s*360),s:Math.round(i*100),l:Math.round(a*100)}}function Mt(n,e,t){n/=255,e/=255,t/=255;const r=Math.max(n,e,t),o=Math.min(n,e,t);let s=0;const i=r,a=r-o,u=r===0?0:a/r;if(r!==o)switch(r){case n:s=((e-t)/a+(e<t?6:0))/6;break;case e:s=((t-n)/a+2)/6;break;case t:s=((n-e)/a+4)/6;break}return{h:Math.round(s*360),s:Math.round(u*100),v:Math.round(i*100)}}function dr(n,e,t){e/=100,t/=100;const r=Math.floor(n/60)%6,o=n/60-Math.floor(n/60),s=t*(1-e),i=t*(1-o*e),a=t*(1-(1-o)*e);let u=0,d=0,p=0;switch(r){case 0:u=t,d=a,p=s;break;case 1:u=i,d=t,p=s;break;case 2:u=s,d=t,p=a;break;case 3:u=s,d=i,p=t;break;case 4:u=a,d=s,p=t;break;case 5:u=t,d=s,p=i;break}return{r:Math.round(u*255),g:Math.round(d*255),b:Math.round(p*255)}}function fr(n,e,t){n/=360,e/=100,t/=100;let r,o,s;if(e===0)r=o=s=t;else{const i=(d,p,v)=>(v<0&&(v+=1),v>1&&(v-=1),v<.16666666666666666?d+(p-d)*6*v:v<.5?p:v<.6666666666666666?d+(p-d)*(.6666666666666666-v)*6:d),a=t<.5?t*(1+e):t+e-t*e,u=2*t-a;r=i(u,a,n+1/3),o=i(u,a,n),s=i(u,a,n-1/3)}return{r:Math.round(r*255),g:Math.round(o*255),b:Math.round(s*255)}}const rt=c.forwardRef(({value:n,onChange:e,placeholder:t,mode:r="border",beforeOpen:o,onClose:s},i)=>{const[a,u]=c.useState(!1),d=c.useRef(null),p=c.useRef(null),v=c.useRef(null),M=c.useRef(null),g=c.useRef(null),[b,x]=c.useState(-1e4),[S,f]=c.useState(-1e4),[h,k]=c.useState(n),[y,m]=c.useState(n),C=c.useRef(n),[D,H]=c.useState("hex"),[j,E]=c.useState({h:0,s:100,v:100}),[A,O]=c.useState({r:0,g:0,b:0}),[V,B]=c.useState({h:0,s:0,l:0}),[P,z]=c.useState(!1),[I,$]=c.useState(!1),[J,K]=c.useState(!1),ee=c.useCallback(()=>{let R=0;const L=3,Z=()=>{if(R>=L*2){K(!1);return}K(ce=>!ce),R++,setTimeout(Z,100)};Z()},[]);c.useImperativeHandle(i,()=>({triggerButtonFlash:ee}));const te=c.useMemo(()=>r==="background"?cr:ar,[r]),Ce=y||"#d9d9d9",ne=c.useCallback(R=>{k(R),m(R);const L=ur(R);L&&(O(L),B(Nt(L.r,L.g,L.b)),E(Mt(L.r,L.g,L.b)))},[]),he=c.useCallback(()=>{const R=dr(j.h,j.s,j.v),L=St(R.r,R.g,R.b);O(R),B(Nt(R.r,R.g,R.b)),k(L),m(L)},[j]);c.useEffect(()=>{ne(n)},[n,ne]),c.useEffect(()=>{he()},[j,he]);const ue=c.useCallback(R=>{let L=R.parentElement;for(;L;){const Z=window.getComputedStyle(L);if(Z.overflowY==="auto"||Z.overflowY==="scroll")return L;L=L.parentElement}return null},[]),U=c.useCallback(()=>{if(!a||!p.current||!v.current||!d.current)return;const R=p.current,L=v.current,Z=d.current,ce=R.getBoundingClientRect(),de=L.getBoundingClientRect(),Ze=Z.getBoundingClientRect();if(Ze.width===0&&Ze.height===0){requestAnimationFrame(U);return}const We=window.innerWidth,Ke=window.innerHeight,le=8,ot=10,wt=ot/2,Ue=ce.width||260,Le=ce.height||348;R.style.maxHeight="",R.style.overflowY="";let _e=de.top,He,N="right";if(de.right+le+Ue<=We-le)He=de.right+le,N="right";else if(de.left-Ue-le>=le)He=de.left-Ue-le,N="left";else{const ge=We-de.right-le,pe=de.left-le;ge>=pe?(He=Math.max(le,We-Ue-le),N="right"):(He=le,N="left")}_e+Le>Ke-le&&(_e=Math.max(le,Ke-Le-le)),x(_e),f(He),R.dataset.placement=N;let F=de.top+de.height/2-_e-wt;const se=le,oe=Math.max(se,Le-ot-le);F=Math.max(se,Math.min(oe,F)),R.style.setProperty("--triangle-top",`${F}px`)},[a]);c.useEffect(()=>{if(!a)return;const R=requestAnimationFrame(U),L=p.current,Z=L?ue(L):null,ce=()=>requestAnimationFrame(U);return Z&&Z.addEventListener("scroll",ce,!0),()=>{cancelAnimationFrame(R),Z&&Z.removeEventListener("scroll",ce,!0)}},[a,U,ue]),c.useEffect(()=>{a&&requestAnimationFrame(U)},[D,a,U]);const re=c.useCallback(()=>{if(a)s==null||s();else{if(o&&o()===!1)return;C.current=n,m(n),ne(n)}u(!a)},[a,n,ne,o,s]),W=c.useCallback(R=>{ne(R)},[ne]),Y=c.useCallback(R=>{const L=R.target.value;k(L),(/^#[0-9A-Fa-f]{6}$/.test(L)||/^#[0-9A-Fa-f]{3}$/.test(L))&&ne(L)},[ne]),be=c.useCallback(()=>{h!==y&&(/^#[0-9A-Fa-f]{6}$/.test(h)||/^#[0-9A-Fa-f]{3}$/.test(h)?ne(h):(k(y),ne(y)))},[h,y,ne]),Ge=c.useCallback(()=>{const R=St(A.r,A.g,A.b);k(R),m(R),B(Nt(A.r,A.g,A.b)),E(Mt(A.r,A.g,A.b))},[A]),Ne=c.useCallback(()=>{const R=fr(V.h,V.s,V.l),L=St(R.r,R.g,R.b);k(L),m(L),O(R),E(Mt(R.r,R.g,R.b))},[V]),Oe=c.useCallback(R=>{if(!M.current)return;const L=M.current.getBoundingClientRect();let Z=Math.max(0,Math.min(100,(R.clientX-L.left)/L.width*100)),ce=Math.max(0,Math.min(100,(R.clientY-L.top)/L.height*100));E(de=>({...de,s:Z,v:100-ce}))},[]),Je=c.useCallback(R=>{z(!0),Oe(R.nativeEvent)},[Oe]),$e=c.useCallback(R=>{if(!g.current)return;const L=g.current.getBoundingClientRect();let Z=Math.max(0,Math.min(360,(R.clientX-L.left)/L.width*360));E(ce=>({...ce,h:Z}))},[]),Xe=c.useCallback(R=>{$(!0),$e(R.nativeEvent)},[$e]);c.useEffect(()=>{const R=Z=>{P&&Oe(Z),I&&$e(Z)},L=()=>{z(!1),$(!1)};return document.addEventListener("mousemove",R),document.addEventListener("mouseup",L),()=>{document.removeEventListener("mousemove",R),document.removeEventListener("mouseup",L)}},[P,I,Oe,$e]),c.useEffect(()=>{const R=Z=>{if(d.current&&!d.current.contains(Z.target)&&a){const ce=Z.target,de=ce.closest?ce.closest(".tp-color-picker-input"):null;if(de&&de!==d.current)return;Z.stopPropagation(),Z.preventDefault(),ee()}},L=()=>{a&&requestAnimationFrame(U)};return document.addEventListener("pointerdown",R,!0),window.addEventListener("resize",L),window.addEventListener("scroll",L,!0),()=>{document.removeEventListener("pointerdown",R,!0),window.removeEventListener("resize",L),window.removeEventListener("scroll",L,!0)}},[a,U]);const gt=c.useCallback(()=>{e(y),u(!1),s==null||s()},[y,e,s]),w=c.useCallback(()=>{m(C.current),ne(C.current),u(!1),s==null||s()},[ne,s]),Q=c.useCallback(R=>{R.stopPropagation()},[]);return l.jsxs("div",{ref:d,className:`tp-color-picker-input${a?" tp-color-picker-input-open":""}`,onClick:Q,children:[l.jsx("button",{ref:v,type:"button",className:"tp-color-preview",style:{backgroundColor:Ce},onMouseDown:R=>R.preventDefault(),onClick:re}),l.jsx("input",{value:h,type:"text",className:"tp-color-text-input",placeholder:t||"#d9d9d9",onChange:Y,onBlur:be,onMouseDown:Q,onClick:Q}),a&&l.jsxs("div",{ref:p,className:"tp-color-panel",style:{position:"fixed",top:`${b}px`,left:`${S}px`},onClick:Q,children:[l.jsx("div",{ref:M,className:"tp-sv-area",style:{background:`linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, transparent), hsl(${j.h}, 100%, 50%)`},onMouseDown:Je,children:l.jsx("div",{className:"tp-sv-indicator",style:{left:`${j.s}%`,top:`${100-j.v}%`}})}),l.jsx("div",{ref:g,className:"tp-hue-bar",onMouseDown:Xe,children:l.jsx("div",{className:"tp-hue-indicator",style:{left:`${j.h/360*100}%`}})}),l.jsx("div",{className:"tp-color-section-label",children:"常用颜色"}),l.jsx("div",{className:"tp-color-grid tp-common-colors",children:te.map(R=>l.jsx("button",{type:"button",className:`tp-color-swatch${n===R?" tp-color-swatch-selected":""}`,style:{backgroundColor:R},title:R,onMouseDown:L=>L.preventDefault(),onClick:()=>W(R)},R))}),l.jsx("div",{className:"tp-input-mode-tabs",children:["hex","rgb","hsl"].map(R=>l.jsx("button",{type:"button",className:`tp-mode-tab${D===R?" active":""}`,onClick:()=>H(R),children:R.toUpperCase()},R))}),D==="hex"&&l.jsxs("div",{className:"tp-color-input-row",children:[l.jsx("label",{children:"HEX"}),l.jsx("input",{value:h,type:"text",className:"tp-color-input-field",placeholder:"#000000",onChange:Y,onBlur:be,onMouseDown:Q,onClick:Q})]}),D==="rgb"&&l.jsxs("div",{className:"tp-color-input-row tp-rgb-inline-row",children:[l.jsx("label",{children:"R"}),l.jsx("input",{type:"number",min:0,max:255,className:"tp-color-input-field",value:A.r,onChange:R=>{O(L=>({...L,r:Number(R.target.value)})),setTimeout(Ge,0)},onMouseDown:Q,onClick:Q}),l.jsx("label",{children:"G"}),l.jsx("input",{type:"number",min:0,max:255,className:"tp-color-input-field",value:A.g,onChange:R=>{O(L=>({...L,g:Number(R.target.value)})),setTimeout(Ge,0)},onMouseDown:Q,onClick:Q}),l.jsx("label",{children:"B"}),l.jsx("input",{type:"number",min:0,max:255,className:"tp-color-input-field",value:A.b,onChange:R=>{O(L=>({...L,b:Number(R.target.value)})),setTimeout(Ge,0)},onMouseDown:Q,onClick:Q})]}),D==="hsl"&&l.jsxs("div",{className:"tp-color-input-row tp-hsl-inline-row",children:[l.jsx("label",{children:"H"}),l.jsx("input",{type:"number",min:0,max:360,className:"tp-color-input-field",value:V.h,onChange:R=>{B(L=>({...L,h:Number(R.target.value)})),setTimeout(Ne,0)},onMouseDown:Q,onClick:Q}),l.jsx("span",{className:"tp-input-unit",children:"°"}),l.jsx("label",{children:"S"}),l.jsx("input",{type:"number",min:0,max:100,className:"tp-color-input-field",value:V.s,onChange:R=>{B(L=>({...L,s:Number(R.target.value)})),setTimeout(Ne,0)},onMouseDown:Q,onClick:Q}),l.jsx("span",{className:"tp-input-unit",children:"%"}),l.jsx("label",{children:"L"}),l.jsx("input",{type:"number",min:0,max:100,className:"tp-color-input-field",value:V.l,onChange:R=>{B(L=>({...L,l:Number(R.target.value)})),setTimeout(Ne,0)},onMouseDown:Q,onClick:Q}),l.jsx("span",{className:"tp-input-unit",children:"%"})]}),l.jsxs("div",{className:"tp-color-footer-row",children:[l.jsx("div",{className:"tp-color-preview-label",children:"当前颜色"}),l.jsx("div",{className:"tp-color-preview-box",style:{backgroundColor:Ce}}),l.jsxs("div",{className:"tp-color-actions",children:[l.jsx("button",{type:"button",className:`tp-color-btn tp-color-btn-cancel${J?" tp-color-btn-flash":""}`,title:"取消",onMouseDown:R=>R.preventDefault(),onClick:w,children:"✕"}),l.jsx("button",{type:"button",className:`tp-color-btn tp-color-btn-confirm${J?" tp-color-btn-flash":""}`,title:"确认",onMouseDown:R=>R.preventDefault(),onClick:gt,children:"✓"})]})]})]})]})});rt.displayName="ColorPickerInput";const pn=({editor:n,visible:e,onVisibleChange:t})=>{const r=_.I18nManager.getInstance(),o=g=>r.t(g),[s,i]=c.useState({borderColor:"#d9d9d9",borderWidth:1}),[a,u]=c.useState("");c.useEffect(()=>{if(e){document.body.style.overflow="hidden";const{state:g}=n,{$from:b}=g.selection;let x=null;g.doc.nodesBetween(b.start(),b.end(),S=>S.type.name==="table"?(x=S,!1):!0),i(x?{borderColor:x.attrs.borderColor||"#d9d9d9",borderWidth:x.attrs.borderWidth?parseInt(x.attrs.borderWidth,10):1}:{borderColor:"#d9d9d9",borderWidth:1})}else document.body.style.overflow="";return()=>{document.body.style.overflow=""}},[e,n]);const d=c.useCallback(()=>{u("")},[]),p=c.useCallback(g=>(u(g),!0),[]),v=c.useCallback(()=>{a||(n.commands.focus(),t(!1))},[a,n,t]),M=c.useCallback(()=>{a||(n.chain().focus().setTableBorder({color:s.borderColor,width:`${s.borderWidth}px`,style:"solid"}).run(),t(!1))},[a,n,s,t]);return e?Ye.createPortal(l.jsx("div",{className:"tp-modal-overlay",onMouseDown:g=>{g.target===g.currentTarget&&v()},children:l.jsxs("div",{className:"tp-modal",onMouseDown:g=>g.stopPropagation(),children:[l.jsxs("div",{className:"tp-modal-header",children:[l.jsx("h3",{className:"tp-modal-title",children:o("table.tableSettings")}),l.jsx("button",{className:"tp-modal-close",onClick:v,children:"×"})]}),l.jsxs("div",{className:"tp-modal-body",children:[l.jsxs("div",{className:"tp-form-item",children:[l.jsx("label",{className:"tp-form-label",children:o("table.borderColor")}),l.jsx(rt,{value:s.borderColor,onChange:g=>i(b=>({...b,borderColor:g})),mode:"border",placeholder:"#d9d9d9",beforeOpen:()=>p("border"),onClose:d})]}),l.jsxs("div",{className:"tp-form-item",children:[l.jsx("label",{className:"tp-form-label",children:o("table.borderWidth")}),l.jsxs("div",{className:"tp-input-with-suffix",children:[l.jsx("input",{type:"number",className:"tp-text-input",min:0,max:10,value:s.borderWidth,onChange:g=>i(b=>({...b,borderWidth:Number(g.target.value)}))}),l.jsx("span",{className:"tp-input-suffix",children:"px"})]})]})]}),l.jsxs("div",{className:"tp-modal-footer",children:[l.jsx("button",{className:"tp-btn tp-btn-default",onClick:v,children:o("common.cancel")}),l.jsx("button",{className:"tp-btn tp-btn-primary",onClick:M,children:o("common.confirm")})]})]})}),document.body):null},hr=[{value:"left",labelKey:"table.alignLeft"},{value:"center",labelKey:"table.alignCenter"},{value:"right",labelKey:"table.alignRight"},{value:"justify",labelKey:"table.alignJustify"}],pr=[{value:"top",labelKey:"table.valignTop"},{value:"middle",labelKey:"table.valignMiddle"},{value:"bottom",labelKey:"table.valignBottom"}];function mr(n){const e=n.attrs.borderWidth||"1px",t=n.attrs.borderStyle||"solid",r=n.attrs.borderColor||"#d9d9d9";return`${e} ${t} ${r}`}function ke(n,e,t,r,o,s){const i=n===0,a=n+r>=o.height,u=e===0,d=e+t>=o.width;switch(s){case"top":return i;case"bottom":return a;case"left":return u;case"right":return d;default:return!1}}function ut(n,e,t,r,o,s,i,a){const u=n.attrs.colspan||1,d=n.attrs.rowspan||1,p={...n.attrs};switch(i){case"left":p.borderLeft=a;break;case"right":p.borderRight=a;break;case"top":p.borderTop=a;break;case"bottom":p.borderBottom=a;break}return p.borderLeft||(p.borderLeft=ke(e,t,u,d,r,"left")&&o?o:s),p.borderRight||(p.borderRight=ke(e,t,u,d,r,"right")&&o?o:s),p.borderTop||(p.borderTop=ke(e,t,u,d,r,"top")&&o?o:s),p.borderBottom||(p.borderBottom=ke(e,t,u,d,r,"bottom")&&o?o:s),p}function gr(n,e,t,r,o,s,i,a,u,d){const p=n.attrs.colspan||1,v=n.attrs.rowspan||1;return d?{...n.attrs,borderLeft:ke(e,t,p,v,r,"left")&&o?o:s,borderRight:ke(e,t,p,v,r,"right")&&o?o:s,borderTop:ke(e,t,p,v,r,"top")&&o?o:s,borderBottom:ke(e,t,p,v,r,"bottom")&&o?o:s,backgroundColor:i,textAlign:a,verticalAlign:u}:{...n.attrs,backgroundColor:i,textAlign:a,verticalAlign:u}}const mn=({editor:n,visible:e,onVisibleChange:t})=>{const r=_.I18nManager.getInstance(),o=h=>r.t(h),[s,i]=c.useState({borderColor:"#d9d9d9",borderWidth:1,backgroundColor:"#ffffff",textAlign:"left",verticalAlign:"top"}),[a,u]=c.useState({borderColor:"#d9d9d9",borderWidth:1}),[d,p]=c.useState(""),v=c.useRef(null),M=c.useRef(null),g=c.useCallback(()=>{const h=d==="border"?v.current:M.current;h==null||h.triggerButtonFlash()},[d]),b=c.useCallback(h=>d&&d!==h?(g(),!1):(p(h),!0),[d,g]),x=c.useCallback(()=>{const{state:h}=n,{selection:k}=h;if("$anchorCell"in k&&k.$anchorCell){const C=k.$anchorCell;let D=null;return h.doc.nodesBetween(C.pos,C.pos+1,H=>H.type.name==="tableCell"||H.type.name==="tableHeader"?(D=H,!1):!0),(D==null?void 0:D.attrs)||null}const{$from:y}=k;let m=null;return h.doc.nodesBetween(y.pos,y.pos+1,C=>C.type.name==="tableCell"||C.type.name==="tableHeader"?(m=C,!1):!0),(m==null?void 0:m.attrs)||null},[n]);c.useEffect(()=>{var h,k,y,m;if(e){document.body.style.overflow="hidden";const C=x();if(C){const D={borderColor:((k=(h=C.borderLeft)==null?void 0:h.match(/#\w+/))==null?void 0:k[0])||"#d9d9d9",borderWidth:(m=(y=C.borderLeft)==null?void 0:y.match(/(\d+)px/))!=null&&m[1]?parseInt(C.borderLeft.match(/(\d+)px/)[1],10):1,backgroundColor:C.backgroundColor||"#ffffff",textAlign:C.textAlign||"left",verticalAlign:C.verticalAlign||"middle"};i(D),u({borderColor:D.borderColor,borderWidth:D.borderWidth})}else i({borderColor:"#d9d9d9",borderWidth:1,backgroundColor:"#ffffff",textAlign:"left",verticalAlign:"middle"}),u({borderColor:"#d9d9d9",borderWidth:1})}else document.body.style.overflow="";return()=>{document.body.style.overflow=""}},[e,x]);const S=c.useCallback(()=>{d||(n.commands.focus(),t(!1))},[d,n,t]),f=c.useCallback(()=>{if(d)return;const{state:h,dispatch:k}=n.view,{selection:y}=h,m=y,C=h.tr;let D=!1;const H=s.borderColor!==a.borderColor||s.borderWidth!==a.borderWidth,j=`${s.borderWidth}px solid ${s.borderColor}`,E=(P,z,I,$,J,K)=>{const ee=J+1,te=gr(P,I.row,I.col,$,K,j,s.backgroundColor,s.textAlign,s.verticalAlign,H);if(C.setNodeMarkup(z,null,te),D=!0,!H)return;const Ce=P.attrs.colspan||1,ne=P.attrs.rowspan||1,he="1px solid #d9d9d9",ue=new Map;for(let U=0;U<$.height;U++)for(let re=0;re<$.width;re++){const W=$.map[U*$.width+re];ue.has(W)||ue.set(W,{row:U,col:re})}if(I.col>0){const U=$.map[I.row*$.width+I.col-1],re=ee+U,W=C.doc.nodeAt(re);if(W&&(W.type.name==="tableCell"||W.type.name==="tableHeader")){const Y=ue.get(U);if(Y&&!ke(Y.row,Y.col,W.attrs.colspan||1,W.attrs.rowspan||1,$,"right")){const be=ut(W,Y.row,Y.col,$,K,he,"right",te.borderLeft);C.setNodeMarkup(re,null,be)}}}if(I.row>0){const U=$.map[(I.row-1)*$.width+I.col],re=ee+U,W=C.doc.nodeAt(re);if(W&&(W.type.name==="tableCell"||W.type.name==="tableHeader")){const Y=ue.get(U);if(Y&&!ke(Y.row,Y.col,W.attrs.colspan||1,W.attrs.rowspan||1,$,"bottom")){const be=ut(W,Y.row,Y.col,$,K,he,"bottom",te.borderTop);C.setNodeMarkup(re,null,be)}}}if(I.col+(P.attrs.colspan||1)<$.width){const U=$.map[I.row*$.width+I.col+Ce],re=ee+U,W=C.doc.nodeAt(re);if(W&&(W.type.name==="tableCell"||W.type.name==="tableHeader")){const Y=ue.get(U);if(Y&&!ke(Y.row,Y.col,W.attrs.colspan||1,W.attrs.rowspan||1,$,"left")){const be=ut(W,Y.row,Y.col,$,K,he,"left",te.borderRight);C.setNodeMarkup(re,null,be)}}}if(I.row+(P.attrs.rowspan||1)<$.height){const U=$.map[(I.row+ne)*$.width+I.col],re=ee+U,W=C.doc.nodeAt(re);if(W&&(W.type.name==="tableCell"||W.type.name==="tableHeader")){const Y=ue.get(U);if(Y&&!ke(Y.row,Y.col,W.attrs.colspan||1,W.attrs.rowspan||1,$,"top")){const be=ut(W,Y.row,Y.col,$,K,he,"top",te.borderBottom);C.setNodeMarkup(re,null,be)}}}},{$from:A,$to:O}=y;let V=-1,B=null;if(h.doc.nodesBetween(A.pos,O.pos,(P,z)=>P.type.name==="table"?(V=z,B=P,!1):!0),B&&V>=0){const P=mr(B),z=je.get(B),I=V+1,$=new Map;for(let J=0;J<z.height;J++)for(let K=0;K<z.width;K++){const ee=z.map[J*z.width+K];$.has(ee)||$.set(ee,{row:J,col:K})}if("$anchorCell"in y&&y.$anchorCell){const J=y.$anchorCell,K=y.$headCell,ee=J.pos-I,te=K.pos-I,Ce=z.rectBetween(ee,te);z.cellsInRect(Ce).forEach(he=>{const ue=I+he,U=h.doc.nodeAt(ue);if(U&&(U.type.name==="tableCell"||U.type.name==="tableHeader")){const re=$.get(he);re&&E(U,ue,re,z,V,P)}})}else h.doc.nodesBetween(A.pos,O.pos,(J,K)=>{if(J.type.name==="tableCell"||J.type.name==="tableHeader"){const ee=K-I,te=$.get(ee);te&&E(J,K,te,z,V,P)}return!0})}D&&k&&(C.setSelection(m.map(C.doc,C.mapping)),k(C),n.commands.focus()),t(!1)},[d,n,s,a,t]);return e?Ye.createPortal(l.jsx("div",{className:"tp-modal-overlay",onMouseDown:h=>{h.target===h.currentTarget&&S()},children:l.jsxs("div",{className:"tp-modal",onMouseDown:h=>h.stopPropagation(),children:[l.jsxs("div",{className:"tp-modal-header",children:[l.jsx("h3",{className:"tp-modal-title",children:o("table.cellSettings")}),l.jsx("button",{className:"tp-modal-close",onClick:S,children:"×"})]}),l.jsxs("div",{className:"tp-modal-body",children:[l.jsxs("div",{className:"tp-form-item",children:[l.jsx("label",{className:"tp-form-label",children:o("table.borderColor")}),l.jsx(rt,{ref:v,value:s.borderColor,onChange:h=>i(k=>({...k,borderColor:h})),mode:"border",placeholder:"#d9d9d9",beforeOpen:()=>b("border"),onClose:()=>p("")})]}),l.jsxs("div",{className:"tp-form-item",children:[l.jsx("label",{className:"tp-form-label",children:o("table.borderWidth")}),l.jsxs("div",{className:"tp-input-with-suffix",children:[l.jsx("input",{type:"number",className:"tp-text-input",min:0,max:10,value:s.borderWidth,onChange:h=>i(k=>({...k,borderWidth:Number(h.target.value)}))}),l.jsx("span",{className:"tp-input-suffix",children:"px"})]})]}),l.jsxs("div",{className:"tp-form-item",children:[l.jsx("label",{className:"tp-form-label",children:o("table.backgroundColor")}),l.jsx(rt,{ref:M,value:s.backgroundColor,onChange:h=>i(k=>({...k,backgroundColor:h})),mode:"background",placeholder:"transparent",beforeOpen:()=>b("background"),onClose:()=>p("")})]}),l.jsxs("div",{className:"tp-form-item",children:[l.jsx("label",{className:"tp-form-label",children:o("table.textAlign")}),l.jsx("div",{className:"tp-align-options",children:hr.map(h=>l.jsxs("button",{className:`tp-align-btn${s.textAlign===h.value?" active":""}`,onClick:()=>i(k=>({...k,textAlign:h.value})),children:[l.jsxs("span",{className:"tp-align-icon tp-align-icon-svg",children:[h.value==="left"&&l.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:[l.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),l.jsx("line",{x1:"6",y1:"8",x2:"14",y2:"8"}),l.jsx("line",{x1:"6",y1:"12",x2:"11",y2:"12"}),l.jsx("line",{x1:"6",y1:"16",x2:"16",y2:"16"})]}),h.value==="center"&&l.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:[l.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),l.jsx("line",{x1:"7",y1:"8",x2:"17",y2:"8"}),l.jsx("line",{x1:"9",y1:"12",x2:"15",y2:"12"}),l.jsx("line",{x1:"8",y1:"16",x2:"16",y2:"16"})]}),h.value==="right"&&l.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:[l.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),l.jsx("line",{x1:"10",y1:"8",x2:"18",y2:"8"}),l.jsx("line",{x1:"13",y1:"12",x2:"18",y2:"12"}),l.jsx("line",{x1:"8",y1:"16",x2:"18",y2:"16"})]}),h.value==="justify"&&l.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:[l.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),l.jsx("line",{x1:"6",y1:"8",x2:"18",y2:"8"}),l.jsx("line",{x1:"6",y1:"12",x2:"18",y2:"12"}),l.jsx("line",{x1:"6",y1:"16",x2:"18",y2:"16"})]})]}),l.jsx("span",{className:"tp-align-label",children:o(h.labelKey)})]},h.value))})]}),l.jsxs("div",{className:"tp-form-item",children:[l.jsx("label",{className:"tp-form-label",children:o("table.verticalAlign")}),l.jsx("div",{className:"tp-align-options",children:pr.map(h=>l.jsxs("button",{className:`tp-align-btn${s.verticalAlign===h.value?" active":""}`,onClick:()=>i(k=>({...k,verticalAlign:h.value})),children:[l.jsxs("span",{className:"tp-align-icon tp-align-icon-svg",children:[h.value==="top"&&l.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:[l.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),l.jsx("line",{x1:"6",y1:"7",x2:"18",y2:"7"})]}),h.value==="middle"&&l.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:[l.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),l.jsx("line",{x1:"6",y1:"12",x2:"18",y2:"12"})]}),h.value==="bottom"&&l.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:[l.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),l.jsx("line",{x1:"6",y1:"17",x2:"18",y2:"17"})]})]}),l.jsx("span",{className:"tp-align-label",children:o(h.labelKey)})]},h.value))})]})]}),l.jsxs("div",{className:"tp-modal-footer",children:[l.jsx("button",{className:"tp-btn tp-btn-default",onClick:S,children:o("common.cancel")}),l.jsx("button",{className:"tp-btn tp-btn-primary",onClick:f,children:o("common.confirm")})]})]})}),document.body):null},gn=({manager:n,visible:e,onVisibleChange:t})=>{const r=_.I18nManager.getInstance(),[o,s]=c.useState([]),[i,a]=c.useState(""),[u,d]=c.useState(null),[p,v]=c.useState(!1),M=c.useRef(null),g=c.useRef(null),b=c.useRef(null),x=c.useCallback((m,C)=>r.t(m,C)||m,[r]),S=c.useCallback(m=>{try{const C=new Date(m),H=new Date().getTime()-C.getTime(),j=Math.floor(H/6e4),E=Math.floor(H/36e5),A=Math.floor(H/864e5);return j<1?x("compare.justNow"):j<60?x("compare.minutesAgo",{n:String(j)}):E<24?x("compare.hoursAgo",{n:String(E)}):A<7?x("compare.daysAgo",{n:String(A)}):C.toLocaleDateString()+" "+C.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return m}},[x]),f=c.useCallback(m=>{const C={blur:"compare.sourceBlur",baseline:"compare.sourceBaseline",paste:"compare.sourcePaste",import:"compare.sourceImport",manual:"compare.sourceManual",interval:"compare.sourceInterval",imported:"compare.sourceImported"};return C[m]?x(C[m]):m},[x]),h=c.useCallback((m,C)=>`v${o.length-C}.0 - ${S(m.timestamp)} (${f(m.source)})${m.label?` - ${m.label}`:""}`,[S,f,o]);c.useEffect(()=>{if(!e){a(""),d(null);return}let m=!1;return v(!0),n.listVersions().then(C=>{m||(s(C),!i&&C.length>0&&a(C[0].id),v(!1))}).catch(()=>{m||(s([]),v(!1))}),()=>{m=!0}},[e,n]),c.useEffect(()=>{if(!i||!n){d(null);return}n.compareWithVersion(i).then(d).catch(()=>d(null))},[i,n]),c.useEffect(()=>{var m,C;if(u&&M.current&&g.current){(m=b.current)==null||m.detach();const D=new _.ScrollSyncManager(M.current,g.current);D.attach();const H=setTimeout(()=>D.refresh(),0);return b.current=D,()=>{clearTimeout(H),D.detach()}}else(C=b.current)==null||C.detach(),b.current=null},[u]),c.useEffect(()=>{const m=C=>{C.key==="Escape"&&e&&t(!1)};return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[e,t]);const k=c.useCallback(async()=>{const m=await n.createSnapshot(x("compare.createSnapshot"));m?_.showToast(x("compare.snapshotCreated").replace("{time}",m.label||m.timestamp)):_.showToast({message:x("compare.snapshotFailed"),type:"error"});const C=await n.listVersions();s(C)},[n,x]),y=c.useCallback(()=>{t(!1)},[t]);return e?l.jsxs("div",{className:"cyte-compare-overlay",children:[l.jsxs("div",{className:"cyte-compare-header",children:[l.jsxs("div",{className:"cyte-compare-header__title",children:[l.jsxs("svg",{className:"cyte-compare-header__title-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[l.jsx("rect",{x:"3",y:"3",width:"7",height:"18",rx:"1"}),l.jsx("rect",{x:"14",y:"3",width:"7",height:"18",rx:"1"}),l.jsx("line",{x1:"10",y1:"8",x2:"14",y2:"8"}),l.jsx("line",{x1:"10",y1:"12",x2:"14",y2:"12"}),l.jsx("line",{x1:"10",y1:"16",x2:"14",y2:"16"})]}),x("compare.title")]}),l.jsxs("div",{className:"cyte-compare-header__actions",children:[l.jsxs("div",{className:"cyte-compare-version-selector",children:[l.jsxs("span",{className:"cyte-compare-version-selector__label",children:[x("compare.selectVersion"),":"]}),l.jsxs("select",{value:i,onChange:m=>a(m.target.value),className:"cyte-compare-version-selector__select",children:[l.jsx("option",{value:"",disabled:!0,children:x("compare.selectVersion")}),o.map((m,C)=>l.jsx("option",{value:m.id,children:h(m,C)},m.id))]})]}),l.jsx("button",{className:"cyte-compare-btn--close",onClick:y,title:x("compare.close"),children:"✕"})]})]}),u&&l.jsxs("div",{className:"cyte-compare-stats",children:[l.jsxs("div",{className:"cyte-compare-stats__item",children:[l.jsxs("span",{className:"cyte-compare-stats__badge",children:[l.jsx("span",{className:"cyte-compare-stats__dot cyte-compare-stats__dot--added"}),l.jsx("span",{className:"cyte-compare-stats__count cyte-compare-stats__count--added",children:u.stats.added})]}),l.jsx("span",{className:"cyte-compare-stats__label",children:x("compare.statsAdded")})]}),l.jsxs("div",{className:"cyte-compare-stats__item",children:[l.jsxs("span",{className:"cyte-compare-stats__badge",children:[l.jsx("span",{className:"cyte-compare-stats__dot cyte-compare-stats__dot--removed"}),l.jsx("span",{className:"cyte-compare-stats__count cyte-compare-stats__count--removed",children:u.stats.removed})]}),l.jsx("span",{className:"cyte-compare-stats__label",children:x("compare.statsRemoved")})]}),l.jsxs("div",{className:"cyte-compare-stats__item",children:[l.jsxs("span",{className:"cyte-compare-stats__badge",children:[l.jsx("span",{className:"cyte-compare-stats__dot cyte-compare-stats__dot--modified"}),l.jsx("span",{className:"cyte-compare-stats__count cyte-compare-stats__count--modified",children:u.stats.modified})]}),l.jsx("span",{className:"cyte-compare-stats__label",children:x("compare.statsModified")})]}),l.jsxs("div",{className:"cyte-compare-stats__item cyte-compare-stats__item--unchanged",children:[l.jsxs("span",{className:"cyte-compare-stats__badge",children:[l.jsx("span",{className:"cyte-compare-stats__dot cyte-compare-stats__dot--unchanged"}),l.jsx("span",{className:"cyte-compare-stats__count",children:u.stats.unchanged})]}),l.jsx("span",{className:"cyte-compare-stats__label",children:x("compare.statsUnchanged")})]})]}),l.jsxs("div",{className:"cyte-compare-content",children:[o.length===0&&!p&&l.jsxs("div",{className:"cyte-compare-empty",children:[l.jsxs("svg",{className:"cyte-compare-empty__icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[l.jsx("circle",{cx:"12",cy:"12",r:"10"}),l.jsx("path",{d:"M8 12h8M12 8v8"})]}),l.jsx("div",{className:"cyte-compare-empty__text",children:x("compare.noVersions")}),l.jsx("div",{className:"cyte-compare-empty__hint",children:x("compare.noVersionsHint")}),l.jsx("button",{className:"cyte-compare-btn cyte-compare-btn--primary cyte-compare-snapshot-btn",onClick:k,children:x("compare.createSnapshot")})]}),u&&l.jsxs(l.Fragment,{children:[l.jsxs("div",{ref:M,className:"cyte-compare-pane",children:[l.jsx("div",{className:"cyte-compare-pane__header",children:(()=>{const m=o.findIndex(C=>C.id===i);return m===-1?x("compare.leftLabel"):`${x("compare.leftLabel")} - ${h(o[m],m)}`})()}),l.jsx("div",{className:"cyte-compare-pane__body",children:u.left.map(m=>l.jsx("div",{dangerouslySetInnerHTML:{__html:m.html}},m.key))})]}),l.jsxs("div",{ref:g,className:"cyte-compare-pane",children:[l.jsx("div",{className:"cyte-compare-pane__header",children:x("compare.rightLabel")}),l.jsx("div",{className:"cyte-compare-pane__body",children:u.right.map(m=>l.jsx("div",{dangerouslySetInnerHTML:{__html:m.html}},m.key))})]})]}),o.length>0&&!i&&!u&&l.jsx("div",{className:"cyte-compare-empty",children:l.jsx("div",{className:"cyte-compare-empty__text",children:x("compare.selectVersion")})})]})]}):null},wr=({visible:n,defaultFilename:e,onConfirm:t,onCancel:r,onClose:o})=>{const{t:s}=we(),[i,a]=c.useState(""),u=c.useRef(null);c.useEffect(()=>(n?(a(e||"document"),document.body.style.overflow="hidden",setTimeout(()=>{var g,b;(g=u.current)==null||g.focus(),(b=u.current)==null||b.select()},100)):document.body.style.overflow="",()=>{document.body.style.overflow=""}),[n,e]);const d=c.useCallback(()=>{const g=i.trim()||"document";t(g),o()},[i,t,o]),p=c.useCallback(()=>{r==null||r(),o()},[r,o]),v=c.useCallback(g=>{g.target===g.currentTarget&&p()},[p]),M=c.useCallback(g=>{g.key==="Enter"?(g.preventDefault(),d()):g.key==="Escape"&&(g.preventDefault(),p())},[d,p]);return n?Ye.createPortal(l.jsx("div",{className:"tp-export-dialog-overlay",onMouseDown:v,children:l.jsxs("div",{className:"tp-export-dialog",onMouseDown:g=>g.stopPropagation(),onKeyDown:M,children:[l.jsxs("div",{className:"tp-dialog-header",children:[l.jsx("span",{className:"tp-dialog-title",children:s("toolbar.exportWord")}),l.jsx("button",{className:"tp-dialog-close",onClick:p,children:"×"})]}),l.jsxs("div",{className:"tp-dialog-body",children:[l.jsx("label",{className:"tp-input-label",children:s("toolbar.exportWordFilename")}),l.jsxs("div",{className:"tp-input-row",children:[l.jsx("input",{ref:u,type:"text",className:"tp-filename-input",value:i,onChange:g=>a(g.target.value),onKeyDown:M}),l.jsx("span",{className:"tp-filename-suffix",children:".docx"}),l.jsx("button",{className:"tp-confirm-btn",onClick:d,children:s("common.confirm")})]})]})]})}),document.body):null},xr=({visible:n,defaultFilename:e,onConfirm:t,onCancel:r,onClose:o})=>{const{t:s}=we(),[i,a]=c.useState(""),u=c.useRef(null);c.useEffect(()=>(n?(a(e||"document"),document.body.style.overflow="hidden",setTimeout(()=>{var g,b;(g=u.current)==null||g.focus(),(b=u.current)==null||b.select()},100)):document.body.style.overflow="",()=>{document.body.style.overflow=""}),[n,e]);const d=c.useCallback(()=>{const g=i.trim()||"document";t(g),o()},[i,t,o]),p=c.useCallback(()=>{r==null||r(),o()},[r,o]),v=c.useCallback(g=>{g.target===g.currentTarget&&p()},[p]),M=c.useCallback(g=>{g.key==="Enter"?(g.preventDefault(),d()):g.key==="Escape"&&(g.preventDefault(),p())},[d,p]);return n?Ye.createPortal(l.jsx("div",{className:"tp-export-dialog-overlay",onMouseDown:v,children:l.jsxs("div",{className:"tp-export-dialog",onMouseDown:g=>g.stopPropagation(),onKeyDown:M,children:[l.jsxs("div",{className:"tp-dialog-header",children:[l.jsx("span",{className:"tp-dialog-title",children:s("toolbar.exportMarkdown")}),l.jsx("button",{className:"tp-dialog-close",onClick:p,children:"×"})]}),l.jsxs("div",{className:"tp-dialog-body",children:[l.jsx("label",{className:"tp-input-label",children:s("toolbar.exportMarkdownFilename")}),l.jsxs("div",{className:"tp-input-row",children:[l.jsx("input",{ref:u,type:"text",className:"tp-filename-input",value:i,onChange:g=>a(g.target.value),onKeyDown:M}),l.jsx("span",{className:"tp-filename-suffix",children:".md"}),l.jsx("button",{className:"tp-confirm-btn",onClick:d,children:s("common.confirm")})]})]})]})}),document.body):null},wn=c.forwardRef((n,e)=>{const{html:t,json:r,config:o,height:s="300px",minHeight:i,maxHeight:a,autoHeight:u=!1,placeholder:d,toolbar:p,readonly:v=!1,disabled:M=!1,autofocus:g=!1,locale:b,pasteMode:x,uploadUrl:S,onChange:f,onFocus:h,onBlur:k,onReady:y,onViewModeChange:m,onToolbarClick:C,onFullscreenChange:D,toolbarRender:H}=n,[j,E]=c.useState("normal"),A=c.useRef(""),O=c.useRef(null),[V,B]=c.useState(!1),[P,z]=c.useState({x:0,y:0}),[I,$]=c.useState(null),[J,K]=c.useState(!1),[ee,te]=c.useState(!1),[Ce,ne]=c.useState(!1),[he,ue]=c.useState(!1),[U,re]=c.useState("document"),[W,Y]=c.useState(!1),[be,Ge]=c.useState("document"),[Ne,Oe]=c.useState(!1),Je=_.I18nManager.getInstance(),$e=c.useCallback(N=>Je.t(N)||N,[Je]),Xe=c.useMemo(()=>{const T={...o||{}};return s!==void 0&&(T.height=s),i!==void 0&&(T.minHeight=i),a!==void 0&&(T.maxHeight=a),u!==void 0&&(T.autoHeight=u),d!==void 0&&(T.placeholder=d),p!==void 0&&(T.toolbar=p),v!==void 0&&(T.readonly=v),M!==void 0&&(T.disabled=M),g!==void 0&&(T.autofocus=g),b!==void 0&&(T.locale=b),x!==void 0&&(T.paste={...T.paste,mode:x}),S!==void 0&&(T.upload={...T.upload,url:S}),T},[o,s,i,a,u,d,p,v,M,g,b,x,S]),gt=c.useMemo(()=>Xe.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"],[Xe.toolbar]),{manager:w,isReady:Q,isFocused:R,isEmpty:L,containerRef:Z,setContentFromProp:ce}=dn({config:Xe,onUpdate(N,T){f==null||f({html:N,json:T})},onFocus(N){h==null||h(N)},onBlur(N){k==null||k(N)},onReady(N){t?N.setContent(t):r&&N.setJSON(r),ot(N),y==null||y(N)}}),{activeStates:de,disabledStates:Ze}=fn(w);c.useEffect(()=>{t!==void 0&&ce(t)},[t,ce]),c.useEffect(()=>{r!==void 0&&ce(void 0,r)},[r,ce]);const We=c.useCallback(N=>{let T="",F=0;const se=" ",ge=N.replace(/>\s+</g,"><").trim().split(/(<\/?[^>]+>)/g).filter(pe=>pe.trim()!=="");for(let pe=0;pe<ge.length;pe++){const xe=ge[pe];if(xe.match(/^<\/\w/))F=Math.max(0,F-1),T+=se.repeat(F)+xe+`
16
- `;else if(xe.match(/^<\w[^>]*[^\/]>$/)){T+=se.repeat(F)+xe+`
17
- `;const ie=ge[pe+1];ie&&!ie.match(/^<\/\w/)&&F++}else if(xe.match(/^<\w[^>]*\/>$/))T+=se.repeat(F)+xe+`
18
- `;else if(xe.match(/^<\w/))T+=se.repeat(F)+xe+`
19
- `;else{const ie=xe.trim();ie&&(T+=se.repeat(F)+ie+`
20
- `)}}return T.trim()},[]),Ke=c.useCallback(N=>{if(!w)return;const T=w.getEditor();if(j===N){le();return}j!=="normal"?le():(A.current=w.getHTML(),O.current=w.getJSON());const F=N==="html"?w.getHTML():JSON.stringify(w.getJSON(),null,2),se=N==="html"?We(F):F;T.commands.clearContent(),T.commands.insertContent({type:"codeBlock",attrs:{language:N==="html"?"html":"json"},content:[{type:"text",text:se}]}),E(N),m==null||m(N)},[w,j,We,m]),le=c.useCallback(()=>{if(!w)return;const N=w.getEditor();if(j!=="normal"){const T=N.getText(),F=j;if(T)try{if(F==="html"){const se=document.createElement("div");se.innerHTML=T,N.commands.setContent(T)}else if(F==="json"){const se=JSON.parse(T);N.commands.setContent(se)}}catch{alert(F==="html"?"HTML 格式错误,请检查输入内容":"JSON 格式错误,请检查输入内容");return}else O.current?N.commands.setContent(O.current):A.current&&N.commands.setContent(A.current)}else O.current?N.commands.setContent(O.current):A.current&&N.commands.setContent(A.current);E("normal"),m==null||m("normal")},[w,j,m]),ot=c.useCallback(N=>{const T=N.getEditor();T.view.dom.addEventListener("contextmenu",F=>{const oe=F.target.closest("td, th");if(!_.getHoverLineVisible())if(oe){F.preventDefault();const ge=T.state.selection;if("$anchorCell"in ge){let Be=!1;try{ge.forEachCell((Qe,xt)=>{const De=T.view.nodeDOM(xt);De&&De instanceof HTMLElement&&(De===oe||De.contains(oe)||oe.contains(De))&&(Be=!0)})}catch{}Be||_.moveCursorToCell(T,oe),z({x:F.clientX,y:F.clientY}),$(oe),B(!0);return}_.restoreTableSelection(T)||_.moveCursorToCell(T,oe);const ie=V;ie&&B(!1),setTimeout(()=>{z({x:F.clientX,y:F.clientY}),$(oe),B(!0)},ie?0:50)}else B(!1),$(null),_.clearSavedTableSelection()})},[V]),wt=c.useCallback(N=>{if(C==null||C(N),N==="snapshot"){w==null||w.createSnapshot().then(T=>{T?_.showToast(Je.t("compare.snapshotCreated",{time:T.label||T.timestamp})):_.showToast({message:Je.t("compare.snapshotFailed"),type:"error"})});return}if(N==="compare"&&ne(!0),N==="fullscreen"&&Le(),N==="importWord"){const T=document.createElement("input");T.type="file",T.accept=".docx,application/vnd.openxmlformats-officedocument.wordprocessingml.document",T.onchange=async F=>{var oe;const se=(oe=F.target.files)==null?void 0:oe[0];se&&await(w==null?void 0:w.importWordFile(se))},T.click()}if(N==="importMarkdown"){const T=document.createElement("input");T.type="file",T.accept=".md,.markdown,text/markdown",T.onchange=async F=>{var oe;const se=(oe=F.target.files)==null?void 0:oe[0];se&&await(w==null?void 0:w.importMarkdownFile(se))},T.click()}N==="exportWord"&&(re((w==null?void 0:w.getDocumentTitle())||"document"),ue(!0)),N==="exportMarkdown"&&(Ge((w==null?void 0:w.getDocumentTitle())||"document"),Y(!0))},[C,w]),Ue=c.useCallback(N=>{if(!w)return;const T=w.getEditor();switch("$anchorCell"in T.state.selection||(_.restoreTableSelection(T),_.clearSavedTableSelection()),N){case"addRowBefore":w.addTableRowBefore();break;case"addRowAfter":w.addTableRowAfter();break;case"addColumnBefore":w.addTableColumnBefore();break;case"addColumnAfter":w.addTableColumnAfter();break;case"mergeCells":T.chain().mergeCells().run(),setTimeout(()=>{if(I)if(document.contains(I))_.moveCursorToCell(T,I);else{const{state:oe}=T,{selection:ge}=oe;if("$anchorCell"in ge){const pe=ge.$anchorCell.pos;if(oe.doc.nodeAt(pe)){const ie=T.view.nodeDOM(pe);ie&&_.moveCursorToCell(T,ie)}}}},0);break;case"splitCell":{const oe=I;let ge=null;if(oe)try{ge=T.view.posAtDOM(oe,0)}catch{}T.chain().splitCell().run(),setTimeout(()=>{const{state:pe}=T,{selection:xe}=pe;if(xe instanceof ve){T.commands.focus();return}if(ge!==null)try{const ie=T.view.nodeDOM(ge);if(ie&&document.contains(ie)){_.moveCursorToCell(T,ie);return}}catch{}try{let ie=null;if(pe.doc.descendants((Be,Qe)=>Be.type.name==="table"?(ie=Qe,!1):!0),ie!==null){const Be=pe.doc.nodeAt(ie);if(Be){const Qe=je.get(Be);if(Qe.map.length>0){const xt=Qe.map[0]+ie+1,De=T.view.nodeDOM(xt);if(De){_.moveCursorToCell(T,De);return}}}}}catch{}T.commands.focus()},0);break}case"deleteRow":w.deleteTableRow();break;case"deleteColumn":w.deleteTableColumn();break;case"deleteTable":w.deleteTable();break;case"tableSettings":K(!0);break;case"cellSettings":te(!0);break}},[w,I]),Le=c.useCallback(()=>{Oe(N=>{const T=!N;return D==null||D(T),T})},[D]),_e=c.useCallback(N=>{N.key==="Escape"&&Ne&&(Oe(!1),D==null||D(!1))},[Ne,D]),He=c.useMemo(()=>{const N={};return u?(i&&(N.minHeight=typeof i=="number"?`${i}px`:i),a&&(N.maxHeight=typeof a=="number"?`${a}px`:a)):(s&&(N.height=typeof s=="number"?`${s}px`:s),i&&(N.minHeight=typeof i=="number"?`${i}px`:i)),N},[u,s,i,a]);return c.useImperativeHandle(e,()=>({getEditorManager:()=>w,getHTML:()=>(w==null?void 0:w.getHTML())??"",getJSON:()=>(w==null?void 0:w.getJSON())??{type:"doc",content:[]},getText:()=>(w==null?void 0:w.getText())??"",setContent:N=>w==null?void 0:w.setContent(N),setJSON:N=>w==null?void 0:w.setJSON(N),insertHTML:N=>w==null?void 0:w.insertHTML(N),insertText:N=>w==null?void 0:w.insertText(N),focus:()=>w==null?void 0:w.focus(),blur:()=>w==null?void 0:w.blur(),isEmpty:()=>(w==null?void 0:w.isEmpty())??!0,clear:()=>w==null?void 0:w.clear(),undo:()=>w==null?void 0:w.undo(),redo:()=>w==null?void 0:w.redo(),setReadonly:N=>w==null?void 0:w.setReadonly(N),insertTable:(N,T,F)=>w==null?void 0:w.insertTable(N,T,F),insertImage:(N,T,F)=>w==null?void 0:w.insertImage(N,T,F),insertVideo:(N,T,F)=>w==null?void 0:w.insertVideo(N,T,F),exportMarkdown:()=>(w==null?void 0:w.exportMarkdown())??"",exportHTMLDocument:N=>(w==null?void 0:w.exportHTMLDocument(N))??"",exportWordFile:N=>(w==null?void 0:w.exportWordFile(N))??Promise.resolve(),exportMarkdownFile:N=>(w==null?void 0:w.exportMarkdownFile(N))??Promise.resolve(),importMarkdown:N=>w==null?void 0:w.importMarkdown(N),importHTMLFile:N=>(w==null?void 0:w.importHTMLFile(N))??Promise.resolve(),importMarkdownFile:N=>(w==null?void 0:w.importMarkdownFile(N))??Promise.resolve(),importWordFile:N=>(w==null?void 0:w.importWordFile(N))??Promise.resolve({messages:[]}),parseHTML:N=>w==null?void 0:w.parseHTML(N),addSnapshot:(N,T)=>(w==null?void 0:w.addSnapshot(N,T))??Promise.resolve(null),toggleViewMode:Ke,restoreOriginalContent:le,getViewMode:()=>j,toggleFullscreen:Le,isFullscreen:()=>Ne}),[w,Ke,le,j,Le,Ne]),l.jsxs("div",{className:`cyte-editor${M?" is-disabled":""}${v?" is-readonly":""}${R?" is-focused":""}${L?" is-empty":""}${u?" is-auto-height":""}${u&&a?" is-auto-height-limited":""}${Ne?" is-fullscreen":""}`,style:He,onKeyDown:_e,children:[Ne&&l.jsxs("div",{className:"cyte-fullscreen-header",children:[l.jsxs("div",{className:"cyte-fullscreen-header__title",children:[l.jsxs("svg",{className:"cyte-fullscreen-header__title-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[l.jsx("path",{d:"M8 4H4V8M4 4L10 10"}),l.jsx("path",{d:"M16 4H20V8M20 4L14 10"}),l.jsx("path",{d:"M4 16V20H8M4 20L10 14"}),l.jsx("path",{d:"M20 16V20H16M20 20L14 14"})]}),$e("toolbar.fullscreenTitle")]}),l.jsxs("button",{className:"cyte-fullscreen-header__close",onClick:Le,children:["✕ ",$e("toolbar.exitFullscreen")]})]}),H?H({manager:w,activeStates:de,disabledStates:Ze,isReady:Q}):Q&&w&&l.jsx(ir,{items:gt,manager:w,activeStates:de,disabledStates:Ze,viewMode:j,onToggleViewMode:Ke,onToolbarClick:wt}),l.jsx("div",{ref:Z,className:"tp-editor-content"}),Q&&w&&l.jsx(hn,{editor:w.getEditor(),visible:V,position:P,targetCell:I,onVisibleChange:B,onAction:Ue}),Q&&w&&l.jsx(pn,{editor:w.getEditor(),visible:J,onVisibleChange:K}),Q&&w&&l.jsx(mn,{editor:w.getEditor(),visible:ee,onVisibleChange:te}),Q&&w&&l.jsx(gn,{manager:w,visible:Ce,onVisibleChange:ne}),l.jsx(wr,{visible:he,defaultFilename:U,onConfirm:N=>w==null?void 0:w.exportWordFile(N),onClose:()=>ue(!1)}),l.jsx(xr,{visible:W,defaultFilename:be,onConfirm:N=>w==null?void 0:w.exportMarkdownFile(N),onClose:()=>Y(!1)})]})});wn.displayName="CyteEditor";exports.CellSettingsModal=mn;exports.ColorPickerInput=rt;exports.CompareOverlay=gn;exports.CyteEditor=wn;exports.TableContextMenu=hn;exports.TableSettingsModal=pn;exports.useEditor=dn;exports.useI18n=we;exports.useToolbarState=fn;
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),[d,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:d,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(),d={},p={};for(const[T,x]of Object.entries(V.toolbarItemDefs))x.isActive&&(d[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(d),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>'};function ve(n){return nt[n]||""}const st=({visible:n,targetRect:o,editor:c,savedSelection:f,initialUrl:a,isEditing:l,onConfirm:h,onCancel:d,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=()=>{d(),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,d]=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"){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{}d(!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()}d(!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:()=>d(!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,d]=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||(d(!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),d(!1)};return t.useEffect(()=>{const s=k=>{v.current&&!v.current.contains(k.target)&&d(!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),[d,p]=t.useState(""),[m,v]=t.useState(""),C=n.name==="color",T=C?d: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:d||"#000000"})]}):e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",fill:m||"transparent"}),e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("text",{x:"6",y:"17",fontSize:"16",fill:"currentColor",stroke:"none",fontFamily:"serif",fontWeight:"bold",children:"A"})]})}),e.jsx("span",{className:"tp-toolbar-dropdown-arrow",children:"▾"})]}),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:d}=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:d("imageUpload.uploadFailed"))}finally{w(!1),s(0)}},W=()=>{const b=v.trim();if(!b){k(d("imageUpload.urlRequired"));return}try{new URL(b)}catch{k(d("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:d("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:d("imageUpload.uploadLocal")}),e.jsx("button",{className:`tp-tab-btn${p==="url"?" is-active":""}`,onClick:()=>m("url"),children:d("imageUpload.inputUrl")})]}),e.jsxs("div",{className:"tp-dialog-body",children:[p==="upload"&&e.jsxs("div",{className:"tp-upload-tab",children:[e.jsx("div",{className:`tp-dropzone${T?" is-dragging":""}${S?" is-uploading":""}`,onDragEnter: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(d("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:[d("imageUpload.uploading")," ",N,"%"]})]}):e.jsxs("div",{className:"tp-dropzone-content",children:[e.jsx("span",{className:"tp-dropzone-icon",children:"📁"}),e.jsx("span",{className:"tp-dropzone-text",children:d("imageUpload.selectFile")}),e.jsx("span",{className:"tp-dropzone-hint",children:d("imageUpload.dragHint")})]})}),e.jsx("input",{ref: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:d("imageUpload.url")}),e.jsxs("div",{className:"tp-input-row",children:[e.jsx("input",{className:"tp-url-input",type:"url",value:v,placeholder:d("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:d("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,d]=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)&&d(!1)};return document.addEventListener("pointerdown",i),()=>document.removeEventListener("pointerdown",i)},[]);const N=i=>{d(!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||d(!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,d]=t.useState(""),[p,m]=t.useState(""),v=t.useRef(null);t.useEffect(()=>(n?(d(""),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=>d(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),d=()=>{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:d,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),[d,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:d.row>0?`${d.row} × ${d.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<=d.row&&r<=d.col?" is-hovered":""}${s===d.row&&r===d.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([]),d=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();d.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(!d.current)return;const D=n.chain().focus();switch(d.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(d.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 d.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=[],d.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),[d,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),[d,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:d,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:[d,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),[d,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:d.x,y:d.y,width:r.width,height:r.height});(k.x!==d.x||k.y!==d.y)&&p({x:k.x,y:k.y})},[o,d.x,d.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:d.x,top:d.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 d=(f+a)/2;if(f!==a){const p=f-a;switch(h=d>.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(d*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,d=f-a,p=f===0?0:d/f;if(f!==a)switch(f){case n:l=((o-c)/d+(o<c?6:0))/6;break;case o:l=((c-n)/d+2)/6;break;case c:l=((n-o)/d+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),d=c*(1-(1-a)*o);let p=0,m=0,v=0;switch(f){case 0:p=c,m=d,v=l;break;case 1:p=h,m=c,v=l;break;case 2:p=l,m=c,v=d;break;case 3:p=l,m=h,v=c;break;case 4:p=d,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),d=c<.5?c*(1+o):c+o-c*o,p=2*c-d;f=h(p,d,n+1/3),a=h(p,d,n),l=h(p,d,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[d,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(!d||!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`)},[d]);t.useEffect(()=>{if(!d)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)}},[d,z,le]),t.useEffect(()=>{d&&requestAnimationFrame(z)},[H,d,z]);const ee=t.useCallback(()=>{if(d)l==null||l();else{if(a&&a()===!1)return;y.current=n,i(n),Q(n)}p(!d)},[d,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)&&d){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=()=>{d&&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)}},[d,z]);const Ie=t.useCallback(()=>{o(g),p(!1),l==null||l()},[g,o,l]),u=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${d?" 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}),d&&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:u,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}),[d,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(()=>{d||(n.commands.focus(),c(!1))},[d,n,c]),T=t.useCallback(()=>{d||(n.chain().focus().setTableBorder({color:l.borderColor,width:`${l.borderWidth}px`,style:"solid"}).run(),c(!1))},[d,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,d=n+f>=a.height,p=o===0,m=o+c>=a.width;switch(l){case"top":return h;case"bottom":return d;case"left":return p;case"right":return m;default:return!1}}function _e(n,o,c,f,a,l,h,d){const p=n.attrs.colspan||1,m=n.attrs.rowspan||1,v={...n.attrs};switch(h){case"left":v.borderLeft=d;break;case"right":v.borderRight=d;break;case"top":v.borderTop=d;break;case"bottom":v.borderBottom=d;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,d,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:d,verticalAlign:p}:{...n.attrs,backgroundColor:h,textAlign:d,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"}),[d,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!==d.borderColor||l.borderWidth!==d.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,d,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,d]=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){d(""),m(null);return}let i=!1;return C(!0),n.listVersions().then(y=>{i||(l(y),!h&&y.length>0&&d(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=>d(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,d]=t.useState(""),p=t.useRef(null);t.useEffect(()=>(n?(d(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=>d(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,d]=t.useState(""),p=t.useRef(null);t.useEffect(()=>(n?(d(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=>d(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:d,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),d!==void 0&&(L.maxHeight=d),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,d,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"],[Re.toolbar]),{manager:u,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(u);t.useEffect(()=>{c!==void 0&&re(c)},[c,re]),t.useEffect(()=>{f!==void 0&&re(void 0,f)},[f,re]);const Ne=t.useCallback(j=>{let L="",F=0;const ne=" ",de=j.replace(/>\s+</g,"><").trim().split(/(<\/?[^>]+>)/g).filter(ce=>ce.trim()!=="");for(let ce=0;ce<de.length;ce++){const pe=de[ce];if(pe.match(/^<\/\w/))F=Math.max(0,F-1),L+=ne.repeat(F)+pe+`
16
+ `;else if(pe.match(/^<\w[^>]*[^\/]>$/)){L+=ne.repeat(F)+pe+`
17
+ `;const oe=de[ce+1];oe&&!oe.match(/^<\/\w/)&&F++}else if(pe.match(/^<\w[^>]*\/>$/))L+=ne.repeat(F)+pe+`
18
+ `;else if(pe.match(/^<\w/))L+=ne.repeat(F)+pe+`
19
+ `;else{const oe=pe.trim();oe&&(L+=ne.repeat(F)+oe+`
20
+ `)}}return L.trim()},[]),Me=t.useCallback(j=>{if(!u)return;const L=u.getEditor();if(b===j){se();return}b!=="normal"?se():(E.current=u.getHTML(),$.current=u.getJSON());const F=j==="html"?u.getHTML():JSON.stringify(u.getJSON(),null,2),ne=j==="html"?Ne(F):F;L.commands.clearContent(),L.commands.insertContent({type:"codeBlock",attrs:{language:j==="html"?"html":"json"},content:[{type:"text",text:ne}]}),D(j),i==null||i(j)},[u,b,Ne,i]),se=t.useCallback(()=>{if(!u)return;const j=u.getEditor();if(b!=="normal"){const L=j.getText(),F=b;if(L)try{if(F==="html"){const ne=document.createElement("div");ne.innerHTML=L,j.commands.setContent(L)}else if(F==="json"){const ne=JSON.parse(L);j.commands.setContent(ne)}}catch{alert(F==="html"?"HTML 格式错误,请检查输入内容":"JSON 格式错误,请检查输入内容");return}else $.current?j.commands.setContent($.current):E.current&&j.commands.setContent(E.current)}else $.current?j.commands.setContent($.current):E.current&&j.commands.setContent(E.current);D("normal"),i==null||i("normal")},[u,b,i]),$e=t.useCallback(j=>{const L=j.getEditor();L.view.dom.addEventListener("contextmenu",F=>{const te=F.target.closest("td, th");if(!V.getHoverLineVisible())if(te){F.preventDefault();const de=L.state.selection;if("$anchorCell"in de){let je=!1;try{de.forEachCell((He,Pe)=>{const we=L.view.nodeDOM(Pe);we&&we instanceof HTMLElement&&(we===te||we.contains(te)||te.contains(we))&&(je=!0)})}catch{}je||V.moveCursorToCell(L,te),B({x:F.clientX,y:F.clientY}),_(te),I(!0);return}V.restoreTableSelection(L)||V.moveCursorToCell(L,te);const oe=J;oe&&I(!1),setTimeout(()=>{B({x:F.clientX,y:F.clientY}),_(te),I(!0)},oe?0:50)}else I(!1),_(null),V.clearSavedTableSelection()})},[J]),Be=t.useCallback(j=>{if(y==null||y(j),j==="snapshot"){u==null||u.createSnapshot().then(L=>{L?V.showToast(Ce.t("compare.snapshotCreated",{time:L.label||L.timestamp})):V.showToast({message:Ce.t("compare.snapshotFailed"),type:"error"})});return}if(j==="compare"&&Q(!0),j==="fullscreen"&&ge(),j==="importWord"){const L=document.createElement("input");L.type="file",L.accept=".docx,application/vnd.openxmlformats-officedocument.wordprocessingml.document",L.onchange=async F=>{var te;const ne=(te=F.target.files)==null?void 0:te[0];ne&&await(u==null?void 0:u.importWordFile(ne))},L.click()}if(j==="importMarkdown"){const L=document.createElement("input");L.type="file",L.accept=".md,.markdown,text/markdown",L.onchange=async F=>{var te;const ne=(te=F.target.files)==null?void 0:te[0];ne&&await(u==null?void 0:u.importMarkdownFile(ne))},L.click()}j==="exportWord"&&(ee((u==null?void 0:u.getDocumentTitle())||"document"),le(!0)),j==="exportMarkdown"&&(De((u==null?void 0:u.getDocumentTitle())||"document"),q(!0))},[y,u]),Se=t.useCallback(j=>{if(!u)return;const L=u.getEditor();switch("$anchorCell"in L.state.selection||(V.restoreTableSelection(L),V.clearSavedTableSelection()),j){case"addRowBefore":u.addTableRowBefore();break;case"addRowAfter":u.addTableRowAfter();break;case"addColumnBefore":u.addTableColumnBefore();break;case"addColumnAfter":u.addTableColumnAfter();break;case"mergeCells":L.chain().mergeCells().run(),setTimeout(()=>{if(A)if(document.contains(A))V.moveCursorToCell(L,A);else{const{state:te}=L,{selection:de}=te;if("$anchorCell"in de){const ce=de.$anchorCell.pos;if(te.doc.nodeAt(ce)){const oe=L.view.nodeDOM(ce);oe&&V.moveCursorToCell(L,oe)}}}},0);break;case"splitCell":{const te=A;let de=null;if(te)try{de=L.view.posAtDOM(te,0)}catch{}L.chain().splitCell().run(),setTimeout(()=>{const{state:ce}=L,{selection:pe}=ce;if(pe instanceof et.TextSelection){L.commands.focus();return}if(de!==null)try{const oe=L.view.nodeDOM(de);if(oe&&document.contains(oe)){V.moveCursorToCell(L,oe);return}}catch{}try{let oe=null;if(ce.doc.descendants((je,He)=>je.type.name==="table"?(oe=He,!1):!0),oe!==null){const je=ce.doc.nodeAt(oe);if(je){const He=Ve.TableMap.get(je);if(He.map.length>0){const Pe=He.map[0]+oe+1,we=L.view.nodeDOM(Pe);if(we){V.moveCursorToCell(L,we);return}}}}}catch{}L.commands.focus()},0);break}case"deleteRow":u.deleteTableRow();break;case"deleteColumn":u.deleteTableColumn();break;case"deleteTable":u.deleteTable();break;case"tableSettings":K(!0);break;case"cellSettings":Z(!0);break}},[u,A]),ge=t.useCallback(()=>{be(j=>{const L=!j;return H==null||H(L),L})},[H]),Le=t.useCallback(j=>{j.key==="Escape"&&xe&&(be(!1),H==null||H(!1))},[xe,H]),ke=t.useMemo(()=>{const j={};return p?(h&&(j.minHeight=typeof h=="number"?`${h}px`:h),d&&(j.maxHeight=typeof d=="number"?`${d}px`:d)):(l&&(j.height=typeof l=="number"?`${l}px`:l),h&&(j.minHeight=typeof h=="number"?`${h}px`:h)),j},[p,l,h,d]);return t.useImperativeHandle(o,()=>({getEditorManager:()=>u,getHTML:()=>(u==null?void 0:u.getHTML())??"",getJSON:()=>(u==null?void 0:u.getJSON())??{type:"doc",content:[]},getText:()=>(u==null?void 0:u.getText())??"",setContent:j=>u==null?void 0:u.setContent(j),setJSON:j=>u==null?void 0:u.setJSON(j),insertHTML:j=>u==null?void 0:u.insertHTML(j),insertText:j=>u==null?void 0:u.insertText(j),focus:()=>u==null?void 0:u.focus(),blur:()=>u==null?void 0:u.blur(),isEmpty:()=>(u==null?void 0:u.isEmpty())??!0,clear:()=>u==null?void 0:u.clear(),undo:()=>u==null?void 0:u.undo(),redo:()=>u==null?void 0:u.redo(),setReadonly:j=>u==null?void 0:u.setReadonly(j),insertTable:(j,L,F)=>u==null?void 0:u.insertTable(j,L,F),insertImage:(j,L,F)=>u==null?void 0:u.insertImage(j,L,F),insertVideo:(j,L,F)=>u==null?void 0:u.insertVideo(j,L,F),exportMarkdown:()=>(u==null?void 0:u.exportMarkdown())??"",exportHTMLDocument:j=>(u==null?void 0:u.exportHTMLDocument(j))??"",exportWordFile:async j=>{await(u==null?void 0:u.exportWordFile(j))},exportMarkdownFile:j=>(u==null?void 0:u.exportMarkdownFile(j))??Promise.resolve(),importMarkdown:j=>u==null?void 0:u.importMarkdown(j),importHTMLFile:j=>(u==null?void 0:u.importHTMLFile(j))??Promise.resolve(),importMarkdownFile:j=>(u==null?void 0:u.importMarkdownFile(j))??Promise.resolve(),importWordFile:j=>(u==null?void 0:u.importWordFile(j))??Promise.resolve({messages:[]}),parseHTML:j=>u==null?void 0:u.parseHTML(j),addSnapshot:(j,L)=>(u==null?void 0:u.addSnapshot(j,L))??Promise.resolve(null),toggleViewMode:Me,restoreOriginalContent:se,getViewMode:()=>b,toggleFullscreen:ge,isFullscreen:()=>xe}),[u,Me,se,b,ge,xe]),e.jsxs("div",{className:`cyte-editor${T?" is-disabled":""}${C?" is-readonly":""}${M?" is-focused":""}${R?" is-empty":""}${p?" is-auto-height":""}${p&&d?" is-auto-height-limited":""}${xe?" is-fullscreen":""}`,style:ke,onKeyDown:Le,children:[xe&&e.jsxs("div",{className:"cyte-fullscreen-header",children:[e.jsxs("div",{className:"cyte-fullscreen-header__title",children:[e.jsxs("svg",{className:"cyte-fullscreen-header__title-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M8 4H4V8M4 4L10 10"}),e.jsx("path",{d:"M16 4H20V8M20 4L14 10"}),e.jsx("path",{d:"M4 16V20H8M4 20L10 14"}),e.jsx("path",{d:"M20 16V20H16M20 20L14 14"})]}),ye("toolbar.fullscreenTitle")]}),e.jsxs("button",{className:"cyte-fullscreen-header__close",onClick:ge,children:["✕ ",ye("toolbar.exitFullscreen")]})]}),W?W({manager:u,activeStates:ie,disabledStates:Ee,isReady:G}):G&&u&&e.jsx(kt,{items:Ie,manager:u,activeStates:ie,disabledStates:Ee,viewMode:b,onToggleViewMode:Me,onToolbarClick:Be}),e.jsx("div",{ref:Y,className:"tp-editor-content"}),G&&u&&e.jsx(Ye,{editor:u.getEditor(),visible:J,position:P,targetCell:A,onVisibleChange:I,onAction:Se}),G&&u&&e.jsx(Ge,{editor:u.getEditor(),visible:O,onVisibleChange:K}),G&&u&&e.jsx(Xe,{editor:u.getEditor(),visible:X,onVisibleChange:Z}),G&&u&&e.jsx(Ze,{manager:u,visible:me,onVisibleChange:Q}),e.jsx(Et,{visible:ae,defaultFilename:z,onConfirm:j=>u==null?void 0:u.exportWordFile(j),onClose:()=>le(!1)}),e.jsx(Ht,{visible:U,defaultFilename:fe,onConfirm:j=>u==null?void 0:u.exportMarkdownFile(j),onClose:()=>q(!1)})]})});Qe.displayName="CyteEditor";exports.CellSettingsModal=Xe;exports.ColorPickerInput=Ae;exports.CompareOverlay=Ze;exports.CyteEditor=Qe;exports.TableContextMenu=Ye;exports.TableSettingsModal=Ge;exports.useEditor=Je;exports.useI18n=ue;exports.useToolbarState=qe;