@cyte-editor/react 1.0.7 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,20 +1,20 @@
1
1
  "use strict";/*!
2
- * CyteEditor React Adapter v1.0.7 (@cyte-editor/react)
2
+ * CyteEditor React Adapter v1.1.1 (@cyte-editor/react)
3
3
  * (c) 2026 CyteEditor — All Rights Reserved.
4
4
  *
5
5
  * Commercial Software — NOT Open Source.
6
6
  * Licensed under the CyteEditor Commercial License.
7
7
  * SEE LICENSE IN ./LICENSE | Full EULA: https://cyteeditor.com/eula
8
8
  *
9
- * Build: 6a7bb7c-dirty @ 2026-09-22T13:03:53.682Z
9
+ * Build: cf421a8-dirty @ 2026-10-07T06:46:49.092Z
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"),V=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 s=n.child(r),o=e.child(r);if(s==o){t+=s.nodeSize;continue}if(!s.sameMarkup(o))return t;if(s.isText&&s.text!=o.text){for(let i=0;s.text[i]==o.text[i];i++)t++;return t}if(s.content.size||o.content.size){let i=qt(s.content,o.content,t+1);if(i!=null)return i}t+=s.nodeSize}}function Yt(n,e,t,r){for(let s=n.childCount,o=e.childCount;;){if(s==0||o==0)return s==o?null:{a:t,b:r};let i=n.child(--s),a=e.child(--o),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,s=0,o){for(let i=0,a=0;a<t;i++){let u=this.content[i],d=a+u.nodeSize;if(d>e&&r(u,s+a,o||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,s+p)}a=d}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,s){let o="",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?s?typeof s=="function"?s(a):s:a.type.spec.leafText?a.type.spec.leafText(a):"":"";a.isBlock&&(a.isLeaf&&d||a.isTextblock)&&r&&(i?i=!1:o+=r),o+=d},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,s=this.content.slice(),o=0;for(t.isText&&t.sameMarkup(r)&&(s[s.length-1]=t.withText(t.text+r.text),o=1);o<e.content.length;o++)s.push(e.content[o]);return new G(s,this.size+e.size)}cut(e,t=this.size){if(e==0&&t==this.size)return this;let r=[],s=0;if(t>e)for(let o=0,i=0;i<t;o++){let a=this.content[o],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),s+=a.nodeSize),i=u}return new G(r,s)}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 s=this.content.slice(),o=this.size+t.nodeSize-r.nodeSize;return s[e]=t,new G(s,o)}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 s=this.content[t];e(s,r,t),r+=s.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 ot(0,e);if(e==this.size)return ot(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 s=this.child(t),o=r+s.nodeSize;if(o>=e)return o==e?ot(t+1,o):ot(t,r);r=o}}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 s=0;s<e.length;s++){let o=e[s];r+=o.nodeSize,s&&o.isText&&e[s-1].sameMarkup(o)?(t||(t=e.slice(0,s)),t[t.length-1]=o.withText(t[t.length-1].text+o.text)):t&&t.push(o)}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 ot(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,s=t.openEnd||0;if(typeof r!="number"||typeof s!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new q(G.fromJSON(e,t.content),r,s)}static maxOpen(e,t=!0){let r=0,s=0;for(let o=e.firstChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.lastChild)s++;return new q(e,r,s)}}q.empty=new q(G.empty,0,0);function Gt(n,e,t){let{index:r,offset:s}=n.findIndex(e),o=n.maybeChild(r),{index:i,offset:a}=n.findIndex(t);if(s==e||o.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,o.copy(Gt(o.content,e-s-1,t-s-1)))}function Xt(n,e,t,r){let{index:s,offset:o}=n.findIndex(e),i=n.maybeChild(s);if(o==e||i.isText)return r&&!r.canReplace(s,s,t)?null:n.cut(0,e).append(t).append(n.cut(e));let a=Xt(i.content,e-o-1,t,i);return a&&n.replaceChild(s,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 s=0;s<r;s++)t+=this.ranges[s*3+2]-this.ranges[s*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 s=0,o=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?s:0);if(u>e)break;let d=this.ranges[a+o],p=this.ranges[a+i],v=u+d;if(e<=v){let M=d?e==u?-1:e==v?1:t:t,g=u+s+(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)}s+=p-d}return r?e+s:new Ht(e+s,0,null)}touches(e,t){let r=0,s=$t(t),o=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+o],p=u+d;if(e<=p&&a==s*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 s=0,o=0;s<this.ranges.length;s+=3){let i=this.ranges[s],a=i-(this.inverted?o:0),u=i+(this.inverted?0:o),d=this.ranges[s+t],p=this.ranges[s+r];e(a,a+d,u,u+p),o+=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,s){try{return ae.ok(e.replace(t,r,s))}catch(o){if(o instanceof yn)return ae.fail(o.message);throw o}}}function Lt(n,e,t){let r=[];for(let s=0;s<n.childCount;s++){let o=n.child(s);o.content.size&&(o=o.copy(Lt(o.content,e,o))),o.isInline&&(o=e(o,t,s)),r.push(o)}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),s=r.node(r.sharedDepth(this.to)),o=new q(Lt(t.content,(i,a)=>!i.isAtom||!a.type.allowsMarkType(this.mark.type)?i:i.mark(this.mark.addToSet(i.marks)),s),t.openStart,t.openEnd);return ae.fromReplace(e,this.from,this.to,o)}invert(){return new Fe(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 Fe 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,s=>s.mark(this.mark.removeFromSet(s.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 Fe(t.pos,r.pos,this.mark)}merge(e){return e instanceof Fe&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Fe(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 Fe(t.from,t.to,e.markFromJSON(t.mark))}}me.jsonID("removeMark",Fe);class Pe 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 s=0;s<t.marks.length;s++)if(!t.marks[s].isInSet(r))return new Pe(this.pos,t.marks[s]);return new Pe(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 Pe(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 Pe(t.pos,e.markFromJSON(t.mark))}}me.jsonID("addNodeMark",Pe);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 Pe(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,s=!1){super(),this.from=e,this.to=t,this.slice=r,this.structure=s}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,s,o,i,a=!1){super(),this.from=e,this.to=t,this.gapFrom=r,this.gapTo=s,this.slice=o,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),s=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),o=this.to==this.gapTo?r.pos:e.map(this.gapTo,1);return t.deletedAcross&&r.deletedAcross||s<t.pos||o>r.pos?null:new qe(t.pos,r.pos,s,o,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),s=t-e,o=r.depth;for(;s>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,s--;if(s>0){let i=r.node(o).maybeChild(r.indexAfter(o));for(;s>0;){if(!i||i.isLeaf)return!0;i=i.firstChild,s--}}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 o in t.attrs)r[o]=t.attrs[o];r[this.attr]=this.value;let s=t.type.create(r,null,t.marks);return ae.fromReplace(e,this.pos,this.pos+1,new q(G.from(s),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 s in e.attrs)t[s]=e.attrs[s];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,s=null;for(let a=0;a<t.openEnd;a++)s=r,r=r.lastChild;let o=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(o);e.replaceRange(p.map(u.pos),p.map(d.pos),a?q.empty:t),a==0&&Ft(e,o,(r?r.isInline:s&&s.isTextblock)?-1:1)}}replaceWith(e,t){let r=e.steps.length,s=this.ranges;for(let o=0;o<s.length;o++){let{$from:i,$to:a}=s[o],u=e.mapping.slice(r),d=u.map(i.pos),p=u.map(a.pos);o?e.deleteRange(d,p):(e.replaceRangeWith(d,p,t),Ft(e,r,t.isInline?-1:1))}}static findFrom(e,t,r=!1){let s=e.parent.inlineContent?new ve(e):Ve(e.node(0),e.parent,e.pos,e.index(),t,r);if(s)return s;for(let o=e.depth-1;o>=0;o--){let i=t<0?Ve(e.node(0),e.node(o),e.before(o+1),e.index(o),t,r):Ve(e.node(0),e.node(o),e.after(o+1),e.index(o)+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 s=e.resolve(t.map(this.anchor));return new ve(s.parent.inlineContent?s: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 s=e.resolve(t);return new this(s,r==t?s:e.resolve(r))}static between(e,t,r){let s=e.pos-t.pos;if((!r||s)&&(r=s>=0?1:-1),!t.parent.inlineContent){let o=X.findFrom(t,r,!0)||X.findFrom(t,-r,!0);if(o)t=o.$head;else return X.near(t,r)}return e.parent.inlineContent||(s==0?e=t:(e=(X.findFrom(e,-r,!0)||X.findFrom(e,r,!0)).$anchor,e.pos<t.pos!=s<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:s}=t.mapResult(this.anchor),o=e.resolve(s);return r?X.near(o):new Se(o)}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,s,o=!1){if(e.inlineContent)return ve.create(n,t);for(let i=r-(s>0?0:1);s>0?i<e.childCount:i>=0;i+=s){let a=e.child(i);if(a.isAtom){if(!o&&Se.isSelectable(a))return Se.create(n,t-(s<0?a.nodeSize:0))}else{let u=Ve(n,a,t+s,s<0?a.childCount:0,s,o);if(u)return u}t+=a.nodeSize*s}return null}function Ft(n,e,t){let r=n.steps.length-1;if(r<e)return;let s=n.steps[r];if(!(s instanceof Re||s instanceof qe))return;let o=n.mapping.maps[r],i;o.forEach((a,u,d,p)=>{i==null&&(i=p)}),n.setSelection(X.near(n.doc.resolve(i),t))}function Pt(n,e){return!e||!n?n:n.bind(e)}class lt{constructor(e,t,r){this.name=e,this.init=Pt(t.init,r),this.apply=Pt(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,s,o,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))s=!0;else if(/^s(hift)?$/i.test(u))o=!0;else if(/^mod$/i.test(u))Mn?i=!0:s=!0;else throw new Error("Unrecognized modifier name: "+u)}return r&&(t="Alt-"+t),s&&(t="Ctrl-"+t),i&&(t="Meta-"+t),o&&(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 s=Nn(r),o,i=e[jt(s,r)];if(i&&i(t.state,t.dispatch,t))return!0;if(s.length==1&&s!=" "){if(r.shiftKey){let a=e[jt(s,r,!1)];if(a&&a(t.state,t.dispatch,t))return!0}if((r.altKey||r.metaKey||r.ctrlKey)&&!(Rn&&r.ctrlKey&&r.altKey)&&(o=Ae[r.keyCode])&&o!=s){let a=e[jt(o,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 s=0;s<n.length;s+=2)if(n[s]==r)return n[s+1]},Et=(r,s)=>(t==10&&(t=0),n[t++]=r,n[t++]=s)}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,s=e/this.width|0;let o=r+1,i=s+1;for(let a=1;o<this.width&&this.map[e+a]==t;a++)o++;for(let a=1;i<this.height&&this.map[e+this.width*a]==t;a++)i++;return{left:r,top:s,right:o,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:s,top:o,bottom:i}=this.findCell(n);return e=="horiz"?(t<0?r==0:s==this.width)?null:this.map[o*this.width+(t<0?r-1:s)]:(t<0?o==0:i==this.height)?null:this.map[r+this.width*(t<0?o-1:i)]}rectBetween(n,e){const{left:t,right:r,top:s,bottom:o}=this.findCell(n),{left:i,right:a,top:u,bottom:d}=this.findCell(e);return{left:Math.min(t,i),top:Math.min(s,u),right:Math.max(r,a),bottom:Math.max(o,d)}}cellsInRect(n){const e=[],t={};for(let r=n.top;r<n.bottom;r++)for(let s=n.left;s<n.right;s++){const o=r*this.width+s,i=this.map[o];t[i]||(t[i]=!0,!(s==n.left&&s&&this.map[o-1]==i||r==n.top&&r&&this.map[o-this.width]==i)&&e.push(i))}return e}positionAt(n,e,t){for(let r=0,s=0;;r++){const o=s+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]<s;)i++;return i==a?o-1:this.map[i]}s=o}}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 s=0,o=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(;s<r.length&&r[s]!=0;)s++;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){(o||(o=[])).push({type:"overlong_rowspan",pos:p,n:f-k});break}const y=s+k*e;for(let m=0;m<S;m++){r[y+m]==0?r[y+m]=p:(o||(o=[])).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]++}}}s+=S,p+=x.nodeSize}const M=(d+1)*e;let g=0;for(;s<M;)r[s++]==0&&g++;g&&(o||(o=[])).push({type:"missing",row:d,n:g}),p++}(e===0||t===0)&&(o||(o=[])).push({type:"zero_sized"});const a=new je(e,t,r,o);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 s=n.child(r);let o=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&&(o+=d.attrs.colspan)}}for(let i=0;i<s.childCount;i++){const a=s.child(i);o+=a.attrs.colspan,a.attrs.rowspan>1&&(t=!0)}e==-1?e=o:e!=o&&(e=Math.max(e,o))}return e}function In(n,e,t){n.problems||(n.problems=[]);const r={};for(let s=0;s<n.map.length;s++){const o=n.map[s];if(r[o])continue;r[o]=!0;const i=t.nodeAt(o);if(!i)throw new RangeError(`No cell with offset ${o} found`);let a=null;const u=i.attrs;for(let d=0;d<u.colspan;d++){const p=e[(s+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:o,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],s=r.spec.tableRole;s&&(e[s]=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 sn(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 on(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),s=je.get(r),o=n.start(-1),i=s.nextCell(n.pos-o,e,t);return i==null?null:n.node(0).resolve(o+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(s=>s>0)||(r.colwidth=null)),r}var Ee=class Me extends X{constructor(e,t=e){const r=e.node(-1),s=je.get(r),o=e.start(-1),i=s.rectBetween(e.pos-o,t.pos-o),a=e.node(0),u=s.cellsInRect(i).filter(p=>p!=t.pos-o);u.unshift(t.pos-o);const d=u.map(p=>{const v=r.nodeAt(p);if(!v)throw new RangeError(`No cell with offset ${p} found`);const M=o+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)),s=e.resolve(t.map(this.$headCell.pos));if(Jt(r)&&Jt(s)&&on(r,s)){const o=this.$anchorCell.node(-1)!=r.node(-1);return o&&this.isRowSelection()?Me.rowSelection(r,s):o&&this.isColSelection()?Me.colSelection(r,s):new Me(r,s)}return ve.between(r,s)}content(){const e=this.$anchorCell.node(-1),t=je.get(e),r=this.$anchorCell.start(-1),s=t.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),o={},i=[];for(let u=s.top;u<s.bottom;u++){const d=[];for(let p=u*t.width+s.left,v=s.left;v<s.right;v++,p++){const M=t.map[p];if(o[M])continue;o[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=s.left-g.left,S=g.right-s.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<s.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<s.top||g.bottom>s.bottom){const f={...b.attrs,rowspan:Math.min(g.bottom,s.bottom)-Math.max(g.top,s.top)};g.top<s.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,s=this.ranges;for(let i=0;i<s.length;i++){const{$from:a,$to:u}=s[i],d=e.mapping.slice(r);e.replace(d.map(a.pos),d.map(u.pos),i?q.empty:t)}const o=X.findFrom(e.doc.resolve(e.mapping.slice(r).map(this.to)),-1);o&&e.setSelection(o)}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),s=this.$anchorCell.start(-1),o=r.cellsInRect(r.rectBetween(this.$anchorCell.pos-s,this.$headCell.pos-s));for(let i=0;i<o.length;i++)e(t.nodeAt(o[i]),s+o[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,s=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,s)==this.$headCell.node(-1).childCount}static colSelection(e,t=e){const r=e.node(-1),s=je.get(r),o=e.start(-1),i=s.findCell(e.pos-o),a=s.findCell(t.pos-o),u=e.node(0);return i.top<=a.top?(i.top>0&&(e=u.resolve(o+s.map[i.left])),a.bottom<s.height&&(t=u.resolve(o+s.map[s.width*(s.height-1)+a.right-1]))):(a.top>0&&(t=u.resolve(o+s.map[a.left])),i.bottom<s.height&&(e=u.resolve(o+s.map[s.width*(s.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),s=t.colCount(this.$anchorCell.pos-r),o=t.colCount(this.$headCell.pos-r);if(Math.min(s,o)>0)return!1;const i=s+this.$anchorCell.nodeAfter.attrs.colspan,a=o+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),s=je.get(r),o=e.start(-1),i=s.findCell(e.pos-o),a=s.findCell(t.pos-o),u=e.node(0);return i.left<=a.left?(i.left>0&&(e=u.resolve(o+s.map[i.top*s.width])),a.right<s.width&&(t=u.resolve(o+s.map[s.width*(a.top+1)-1]))):(a.left>0&&(t=u.resolve(o+s.map[a.top*s.width])),i.right<s.width&&(e=u.resolve(o+s.map[s.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&&on(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),s=t.start(-1),o=je.get(r);return{...e instanceof Ee?o.rectBetween(e.$anchorCell.pos-s,e.$headCell.pos-s):o.findCell(t.pos-s),tableStart:s,map:o,table:r}}function Fn(n){return function(e,t){if(!sn(e))return!1;if(t){const r=It(e.schema),s=cn(e),o=e.tr,i=s.map.cellsInRect(n=="column"?{left:s.left,top:0,right:s.right,bottom:s.map.height}:n=="row"?{left:0,top:s.top,right:s.map.width,bottom:s.bottom}:s),a=i.map(u=>s.table.nodeAt(u));for(let u=0;u<i.length;u++)a[u].type==r.header_cell&&o.setNodeMarkup(s.tableStart+i[u],r.cell,a[u].attrs);if(o.steps.length===0)for(let u=0;u<i.length;u++)o.setNodeMarkup(s.tableStart+i[u],r.header_cell,a[u].attrs);t(o)}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 s=0;s<r.length;s++){const o=e.table.nodeAt(r[s]);if(o&&o.type!==t.header_cell)return!1}return!0}function Ot(n,e){return e=e||{useDeprecatedLogic:!1},e.useDeprecatedLogic?Fn(n):function(t,r){if(!sn(t))return!1;if(r){const s=It(t.schema),o=cn(t),i=t.tr,a=Kt("row",o,s),u=Kt("column",o,s),d=(n==="column"?a:n==="row"&&u)?1:0,p=n=="column"?{left:0,top:d,right:1,bottom:o.map.height}:n=="row"?{left:d,top:0,right:o.map.width,bottom:1}:o,v=n=="column"?u?s.cell:s.header_cell:n=="row"?a?s.cell:s.header_cell:s.cell;o.map.cellsInRect(p).forEach(M=>{const g=M+o.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,s=It(n.schema).cell.createAndFill().content;t.forEachCell((o,i)=>{o.content.eq(s)||r.replace(r.mapping.map(i+1),r.mapping.map(i+o.nodeSize-1),new q(s,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,s)=>{if(!s)return!1;const o=t.selection;if(o instanceof Ee)return ft(t,r,X.near(o.$headCell,e));if(n!="horiz"&&!o.empty)return!1;const i=un(s,n,e);if(i==null)return!1;if(n=="horiz")return ft(t,r,X.near(t.doc.resolve(o.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,s)=>{if(!s)return!1;const o=t.selection;let i;if(o instanceof Ee)i=o;else{const u=un(s,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 s=r.depth-1;s>=0;s--){const o=r.node(s);if((t<0?r.index(s):r.indexAfter(s))!=(t<0?0:o.childCount))return null;if(o.type.spec.tableRole=="cell"||o.type.spec.tableRole=="header_cell"){const i=r.before(s),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,s]=c.useState(!1),[o,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=V.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)}),s(!0),(h=(f=p.current).onReady)==null||h.call(f,S),()=>{S.destroy(),t.current=null,s(!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&&V.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:o,isEmpty:a,containerRef:e,setContentFromProp:v}}function fn(n){const[e,t]=c.useState({}),[r,s]=c.useState({}),o=c.useCallback(async()=>{if(!n)return;const i=n.getEditor(),a={},u={};for(const[M,g]of Object.entries(V.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(V.toolbarItemDefs))g.requiredTier&&M!=="compare"&&(u[M]=!0);t(a),s(u)},[n]);return c.useEffect(()=>{if(n)return n.on("selectionUpdate",o),n.on("update",o),n.on("transaction",o),n.on("snapshot-created",o),o(),()=>{n.off("selectionUpdate",o),n.off("update",o),n.off("transaction",o),n.off("snapshot-created",o)}},[n,o]),{activeStates:e,disabledStates:r,refresh:o}}function we(){const n=V.I18nManager.getInstance(),[e,t]=c.useState(0);c.useEffect(()=>n.onChange(()=>{t(o=>o+1)}),[n]);function r(s,o){return n.t(s,o)}return{t:r,locale:n.getLocale()}}const Pn={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>'};function Ie(n){return Pn[n]||""}const Jn=({visible:n,targetRect:e,editor:t,savedSelection:r,initialUrl:s,isEditing:o,onConfirm:i,onCancel:a,onClose:u})=>{const{t:d}=we(),[p,v]=c.useState(s||""),[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(s||""),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,_=window.innerWidth;let B=j.bottom+A,F=!1;B+E>O&&(B=j.top-E-A,F=!0),g(F);let z=j.left+j.width/2;const I=320;return z+I/2>_&&(z=_-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(o&&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(o?"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")}),o&&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:s})=>{const{t:o}=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"){s==null||s(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:o(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:s})=>{var S;const{t:o}=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?s==null||s(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:o(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:o(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?o(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(),[s,o]=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)&&o(!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),o(!1)},x=()=>{var S;(S=n.command)==null||S.call(n,e,void 0),p(""),o(!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||o(!s)},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:"▾"})]}),s&&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:s,initialTab:o,onClose:i})=>{const{t:a}=we(),[u,d]=c.useState(o||"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(o||"upload"),f(0),document.body.style.overflow="hidden"):document.body.style.overflow="",()=>{document.body.style.overflow=""}),[n,o]);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;s?E=await s(j):t?E=await V.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:s})=>{var f,h,k,y;const{t:o}=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":""}${s?" is-disabled":""}`,title:o(n.titleKey),disabled:s,onMouseDown:m=>m.preventDefault(),onClick:()=>{s||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?o(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:s})=>{const{t:o}=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(o("video.urlRequired"));return}try{new URL(x)}catch{d(o("video.invalidUrl"));return}e.chain().focus().setVideo({src:x}).run(),t==null||t(x),s()},[i,e,o,t,s]),M=c.useCallback(()=>{r==null||r(),s()},[r,s]),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:o("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:o("video.url")}),l.jsxs("div",{className:"tp-input-row",children:[l.jsx("input",{ref:p,type:"url",className:"tp-url-input",placeholder:o("video.placeholder"),value:i,onChange:x=>a(x.target.value),onKeyDown:b}),l.jsx("button",{className:"tp-confirm-btn",onClick:v,children:o("common.confirm")})]}),l.jsx("p",{className:"tp-hint",children:o("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:s}=we(),[o,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:s(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:o,editor:e,onSuccess:()=>{},onClose:()=>i(!1)})]})},Qn=10,er=10,tr=({def:n,editor:e,active:t,disabled:r})=>{const{t:s}=we(),[o,i]=c.useState(!1),[a,u]=c.useState({row:0,col:0}),d=c.useRef(null),p=()=>{r||(i(!o),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:s(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:"▾"})]}),o&&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}`:s("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"),[s,o]=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=s!=="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),_=n.state.doc.resolve(O);if(_.parent.type.name==="listItem")for(let F=_.depth;F>0;F--){const z=_.node(F);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 F=1;F<=6;F++)if(n.isActive("heading",{level:F}))return F;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 F=x();a.current=F;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||F!==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:_}=E.selection;if(_)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 F=E.selection;if(A=F.from,O=F.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",o("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",o("single"))},[f,m]),H=c.useCallback(()=>{if(r.current==="multiple"){m();return}f()&&(r.current="multiple",o("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()},_=B=>{if(r.current==="none")return;const F=["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"];B.shiftKey&&F.includes(B.key)&&C()};return document.addEventListener("mousedown",E),document.addEventListener("mouseup",A),document.addEventListener("keydown",O),document.addEventListener("keyup",_),()=>{document.removeEventListener("mousedown",E),document.removeEventListener("mouseup",A),document.removeEventListener("keydown",O),document.removeEventListener("keyup",_),v.current&&clearTimeout(v.current)}},[C,m]),l.jsxs("button",{className:`tp-toolbar-btn${b?" is-active":""}${s==="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")}}),s==="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."]}],sr=({def:n,editor:e,active:t,disabled:r})=>{const{t:s}=we(),[o,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:s(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${o?" is-open":""}`,disabled:r,onMouseDown:y=>y.preventDefault(),onClick:x,children:"▾"}),o&&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:s("orderedList.properties")}),l.jsxs("div",{className:"tp-ol-prop-row",children:[l.jsx("label",{children:s("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:s("orderedList.reversed")}),l.jsx("button",{className:`tp-ol-toggle${g?" is-on":""}`,onMouseDown:y=>y.preventDefault(),onClick:k})]})]})]})]})},or=[{type:"disc",marker:"●"},{type:"circle",marker:"○"},{type:"square",marker:"■"},{type:"none",marker:"—"}],lr=({def:n,editor:e,active:t,disabled:r})=>{const{t:s}=we(),[o,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:s(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${o?" is-open":""}`,disabled:r,onMouseDown:b=>b.preventDefault(),onClick:M,children:"▾"}),o&&l.jsx("div",{className:"tp-ol-panel",children:l.jsx("div",{className:"tp-ol-style-grid tp-ul-style-grid",children:or.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:s="normal",onToggleViewMode:o,onToolbarClick:i,prepend:a,append:u})=>{const d=()=>e.getEditor(),p=c.useCallback(f=>{if(f==="getHTML"){o==null||o("html");return}if(f==="getJSON"){o==null||o("json");return}i==null||i(f)},[o,i]),v=f=>s!=="normal"?f==="getHTML"?s==="html":f==="getJSON"?s==="json":!1:f==="getHTML"||f==="getJSON"?!1:t[f]??!1,M=f=>s!=="normal"?f!=="getHTML"&&f!=="getJSON":r[f]??!1,g=c.useMemo(()=>V.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=V.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(sr,{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:s,onAction:o})=>{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=V.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:V.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=V.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){s(!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,s,S]),c.useEffect(()=>{const h=y=>{i.current&&!i.current.contains(y.target)&&s(!1)},k=y=>{y.key==="Escape"&&s(!1)};return document.addEventListener("click",h),document.addEventListener("keydown",k),()=>{document.removeEventListener("click",h),document.removeEventListener("keydown",k)}},[s]);const f=c.useCallback(h=>{o(h),s(!1)},[o,s]);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 s=Math.round(Math.max(0,Math.min(255,r))).toString(16);return s.length===1?"0"+s:s}).join("")}function Nt(n,e,t){n/=255,e/=255,t/=255;const r=Math.max(n,e,t),s=Math.min(n,e,t);let o=0,i=0;const a=(r+s)/2;if(r!==s){const u=r-s;switch(i=a>.5?u/(2-r-s):u/(r+s),r){case n:o=((e-t)/u+(e<t?6:0))/6;break;case e:o=((t-n)/u+2)/6;break;case t:o=((n-e)/u+4)/6;break}}return{h:Math.round(o*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),s=Math.min(n,e,t);let o=0;const i=r,a=r-s,u=r===0?0:a/r;if(r!==s)switch(r){case n:o=((e-t)/a+(e<t?6:0))/6;break;case e:o=((t-n)/a+2)/6;break;case t:o=((n-e)/a+4)/6;break}return{h:Math.round(o*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,s=n/60-Math.floor(n/60),o=t*(1-e),i=t*(1-s*e),a=t*(1-(1-s)*e);let u=0,d=0,p=0;switch(r){case 0:u=t,d=a,p=o;break;case 1:u=i,d=t,p=o;break;case 2:u=o,d=t,p=a;break;case 3:u=o,d=i,p=t;break;case 4:u=a,d=o,p=t;break;case 5:u=t,d=o,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,s,o;if(e===0)r=s=o=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),s=i(u,a,n),o=i(u,a,n-1/3)}return{r:Math.round(r*255),g:Math.round(s*255),b:Math.round(o*255)}}const rt=c.forwardRef(({value:n,onChange:e,placeholder:t,mode:r="border",beforeOpen:s,onClose:o},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}),[_,B]=c.useState({h:0,s:0,l:0}),[F,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,st=10,wt=st/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 P=de.top+de.height/2-_e-wt;const oe=le,se=Math.max(oe,Le-st-le);P=Math.max(oe,Math.min(se,P)),R.style.setProperty("--triangle-top",`${P}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)o==null||o();else{if(s&&s()===!1)return;C.current=n,m(n),ne(n)}u(!a)},[a,n,ne,s,o]),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(_.h,_.s,_.l),L=St(R.r,R.g,R.b);k(L),m(L),O(R),E(Mt(R.r,R.g,R.b))},[_]),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=>{F&&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)}},[F,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),o==null||o()},[y,e,o]),w=c.useCallback(()=>{m(C.current),ne(C.current),u(!1),o==null||o()},[ne,o]),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:_.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:_.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:_.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=V.I18nManager.getInstance(),s=g=>r.t(g),[o,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:o.borderColor,width:`${o.borderWidth}px`,style:"solid"}).run(),t(!1))},[a,n,o,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:s("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:s("table.borderColor")}),l.jsx(rt,{value:o.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:s("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:o.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:s("common.cancel")}),l.jsx("button",{className:"tp-btn tp-btn-primary",onClick:M,children:s("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,s,o){const i=n===0,a=n+r>=s.height,u=e===0,d=e+t>=s.width;switch(o){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,s,o,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")&&s?s:o),p.borderRight||(p.borderRight=ke(e,t,u,d,r,"right")&&s?s:o),p.borderTop||(p.borderTop=ke(e,t,u,d,r,"top")&&s?s:o),p.borderBottom||(p.borderBottom=ke(e,t,u,d,r,"bottom")&&s?s:o),p}function gr(n,e,t,r,s,o,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")&&s?s:o,borderRight:ke(e,t,p,v,r,"right")&&s?s:o,borderTop:ke(e,t,p,v,r,"top")&&s?s:o,borderBottom:ke(e,t,p,v,r,"bottom")&&s?s:o,backgroundColor:i,textAlign:a,verticalAlign:u}:{...n.attrs,backgroundColor:i,textAlign:a,verticalAlign:u}}const mn=({editor:n,visible:e,onVisibleChange:t})=>{const r=V.I18nManager.getInstance(),s=h=>r.t(h),[o,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=o.borderColor!==a.borderColor||o.borderWidth!==a.borderWidth,j=`${o.borderWidth}px solid ${o.borderColor}`,E=(F,z,I,$,J,K)=>{const ee=J+1,te=gr(F,I.row,I.col,$,K,j,o.backgroundColor,o.textAlign,o.verticalAlign,H);if(C.setNodeMarkup(z,null,te),D=!0,!H)return;const Ce=F.attrs.colspan||1,ne=F.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+(F.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+(F.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 _=-1,B=null;if(h.doc.nodesBetween(A.pos,O.pos,(F,z)=>F.type.name==="table"?(_=z,B=F,!1):!0),B&&_>=0){const F=mr(B),z=je.get(B),I=_+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,_,F)}})}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,_,F)}return!0})}D&&k&&(C.setSelection(m.map(C.doc,C.mapping)),k(C),n.commands.focus()),t(!1)},[d,n,o,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:s("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:s("table.borderColor")}),l.jsx(rt,{ref:v,value:o.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:s("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:o.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:s("table.backgroundColor")}),l.jsx(rt,{ref:M,value:o.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:s("table.textAlign")}),l.jsx("div",{className:"tp-align-options",children:hr.map(h=>l.jsxs("button",{className:`tp-align-btn${o.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:s(h.labelKey)})]},h.value))})]}),l.jsxs("div",{className:"tp-form-item",children:[l.jsx("label",{className:"tp-form-label",children:s("table.verticalAlign")}),l.jsx("div",{className:"tp-align-options",children:pr.map(h=>l.jsxs("button",{className:`tp-align-btn${o.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:s(h.labelKey)})]},h.value))})]})]}),l.jsxs("div",{className:"tp-modal-footer",children:[l.jsx("button",{className:"tp-btn tp-btn-default",onClick:S,children:s("common.cancel")}),l.jsx("button",{className:"tp-btn tp-btn-primary",onClick:f,children:s("common.confirm")})]})]})}),document.body):null},gn=({manager:n,visible:e,onVisibleChange:t})=>{const r=V.I18nManager.getInstance(),[s,o]=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${s.length-C}.0 - ${S(m.timestamp)} (${f(m.source)})${m.label?` - ${m.label}`:""}`,[S,f,s]);c.useEffect(()=>{if(!e){a(""),d(null);return}let m=!1;return v(!0),n.listVersions().then(C=>{m||(o(C),!i&&C.length>0&&a(C[0].id),v(!1))}).catch(()=>{m||(o([]),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 V.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?V.showToast(x("compare.snapshotCreated").replace("{time}",m.label||m.timestamp)):V.showToast({message:x("compare.snapshotFailed"),type:"error"});const C=await n.listVersions();o(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")}),s.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:[s.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=s.findIndex(C=>C.id===i);return m===-1?x("compare.leftLabel"):`${x("compare.leftLabel")} - ${h(s[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))})]})]}),s.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:s})=>{const{t:o}=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),s()},[i,t,s]),p=c.useCallback(()=>{r==null||r(),s()},[r,s]),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:o("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:o("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:o("common.confirm")})]})]})]})}),document.body):null},xr=({visible:n,defaultFilename:e,onConfirm:t,onCancel:r,onClose:s})=>{const{t:o}=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),s()},[i,t,s]),p=c.useCallback(()=>{r==null||r(),s()},[r,s]),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:o("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:o("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:o("common.confirm")})]})]})]})}),document.body):null},wn=c.forwardRef((n,e)=>{const{html:t,json:r,config:s,height:o="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),[_,B]=c.useState(!1),[F,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=V.I18nManager.getInstance(),$e=c.useCallback(N=>Je.t(N)||N,[Je]),Xe=c.useMemo(()=>{const T={...s||{}};return o!==void 0&&(T.height=o),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},[s,o,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","|","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),st(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="",P=0;const oe=" ",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/))P=Math.max(0,P-1),T+=oe.repeat(P)+xe+`
16
- `;else if(xe.match(/^<\w[^>]*[^\/]>$/)){T+=oe.repeat(P)+xe+`
17
- `;const ie=ge[pe+1];ie&&!ie.match(/^<\/\w/)&&P++}else if(xe.match(/^<\w[^>]*\/>$/))T+=oe.repeat(P)+xe+`
18
- `;else if(xe.match(/^<\w/))T+=oe.repeat(P)+xe+`
19
- `;else{const ie=xe.trim();ie&&(T+=oe.repeat(P)+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 P=N==="html"?w.getHTML():JSON.stringify(w.getJSON(),null,2),oe=N==="html"?We(P):P;T.commands.clearContent(),T.commands.insertContent({type:"codeBlock",attrs:{language:N==="html"?"html":"json"},content:[{type:"text",text:oe}]}),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(),P=j;if(T)try{if(P==="html"){const oe=document.createElement("div");oe.innerHTML=T,N.commands.setContent(T)}else if(P==="json"){const oe=JSON.parse(T);N.commands.setContent(oe)}}catch{alert(P==="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]),st=c.useCallback(N=>{const T=N.getEditor();T.view.dom.addEventListener("contextmenu",P=>{const se=P.target.closest("td, th");if(!V.getHoverLineVisible())if(se){P.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===se||De.contains(se)||se.contains(De))&&(Be=!0)})}catch{}Be||V.moveCursorToCell(T,se),z({x:P.clientX,y:P.clientY}),$(se),B(!0);return}V.restoreTableSelection(T)||V.moveCursorToCell(T,se);const ie=_;ie&&B(!1),setTimeout(()=>{z({x:P.clientX,y:P.clientY}),$(se),B(!0)},ie?0:50)}else B(!1),$(null),V.clearSavedTableSelection()})},[_]),wt=c.useCallback(N=>{if(C==null||C(N),N==="snapshot"){w==null||w.createSnapshot().then(T=>{T?V.showToast(Je.t("compare.snapshotCreated",{time:T.label||T.timestamp})):V.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 P=>{var se;const oe=(se=P.target.files)==null?void 0:se[0];oe&&await(w==null?void 0:w.importWordFile(oe))},T.click()}if(N==="importMarkdown"){const T=document.createElement("input");T.type="file",T.accept=".md,.markdown,text/markdown",T.onchange=async P=>{var se;const oe=(se=P.target.files)==null?void 0:se[0];oe&&await(w==null?void 0:w.importMarkdownFile(oe))},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||(V.restoreTableSelection(T),V.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))V.moveCursorToCell(T,I);else{const{state:se}=T,{selection:ge}=se;if("$anchorCell"in ge){const pe=ge.$anchorCell.pos;if(se.doc.nodeAt(pe)){const ie=T.view.nodeDOM(pe);ie&&V.moveCursorToCell(T,ie)}}}},0);break;case"splitCell":{const se=I;let ge=null;if(se)try{ge=T.view.posAtDOM(se,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)){V.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){V.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)):(o&&(N.height=typeof o=="number"?`${o}px`:o),i&&(N.minHeight=typeof i=="number"?`${i}px`:i)),N},[u,o,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,P)=>w==null?void 0:w.insertTable(N,T,P),insertImage:(N,T,P)=>w==null?void 0:w.insertImage(N,T,P),insertVideo:(N,T,P)=>w==null?void 0:w.insertVideo(N,T,P),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:_,position:F,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 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;