1// [email protected] downloaded from https://ga.jspm.io/npm:[email protected]/dist/index.js 2 3import{PluginKey as t,Selection as e,SelectionRange as n,TextSelection as o,NodeSelection as l,Plugin as r}from"prosemirror-state";import{Fragment as s,Slice as c}from"prosemirror-model";import{Decoration as i,DecorationSet as a}from"prosemirror-view";import{keydownHandler as d}from"prosemirror-keymap";import{Transform as p}from"prosemirror-transform";let f;let h;if(typeof WeakMap!="undefined"){let t=new WeakMap;f=e=>t.get(e);h=(e,n)=>{t.set(e,n);return n}}else{const t=[];const e=10;let n=0;f=e=>{for(let n=0;n<t.length;n+=2)if(t[n]==e)return t[n+1]};h=(o,l)=>{n==e&&(n=0);t[n++]=o;return t[n++]=l}}var u=class{constructor(t,e,n,o){this.width=t;this.height=e;this.map=n;this.problems=o}findCell(t){for(let e=0;e<this.map.length;e++){const n=this.map[e];if(n!=t)continue;const o=e%this.width;const l=e/this.width|0;let r=o+1;let s=l+1;for(let t=1;r<this.width&&this.map[e+t]==n;t++)r++;for(let t=1;s<this.height&&this.map[e+this.width*t]==n;t++)s++;return{left:o,top:l,right:r,bottom:s}}throw new RangeError(`No cell with offset ${t} found`)}colCount(t){for(let e=0;e<this.map.length;e++)if(this.map[e]==t)return e%this.width;throw new RangeError(`No cell with offset ${t} found`)}nextCell(t,e,n){const{left:o,right:l,top:r,bottom:s}=this.findCell(t);return e=="horiz"?(n<0?o==0:l==this.width)?null:this.map[r*this.width+(n<0?o-1:l)]:(n<0?r==0:s==this.height)?null:this.map[o+this.width*(n<0?r-1:s)]}rectBetween(t,e){const{left:n,right:o,top:l,bottom:r}=this.findCell(t);const{left:s,right:c,top:i,bottom:a}=this.findCell(e);return{left:Math.min(n,s),top:Math.min(l,i),right:Math.max(o,c),bottom:Math.max(r,a)}}cellsInRect(t){const e=[];const n={};for(let o=t.top;o<t.bottom;o++)for(let l=t.left;l<t.right;l++){const r=o*this.width+l;const s=this.map[r];if(!n[s]){n[s]=true;l==t.left&&l&&this.map[r-1]==s||o==t.top&&o&&this.map[r-this.width]==s||e.push(s)}}return e}positionAt(t,e,n){for(let o=0,l=0;;o++){const r=l+n.child(o).nodeSize;if(o==t){let n=e+t*this.width;const o=(t+1)*this.width;while(n<o&&this.map[n]<l)n++;return n==o?r-1:this.map[n]}l=r}}static get(t){return f(t)||h(t,m(t))}};function m(t){if(t.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+t.type.name);const e=w(t),n=t.childCount;const o=[];let l=0;let r=null;const s=[];for(let t=0,l=e*n;t<l;t++)o[t]=0;for(let c=0,i=0;c<n;c++){const a=t.child(c);i++;for(let t=0;;t++){while(l<o.length&&o[l]!=0)l++;if(t==a.childCount)break;const d=a.child(t);const{colspan:p,rowspan:f,colwidth:h}=d.attrs;for(let t=0;t<f;t++){if(t+c>=n){(r||(r=[])).push({type:"overlong_rowspan",pos:i,n:f-t});break}const a=l+t*e;for(let t=0;t<p;t++){o[a+t]==0?o[a+t]=i:(r||(r=[])).push({type:"collision",row:c,pos:i,n:p-t});const n=h&&h[t];if(n){const o=(a+t)%e*2,l=s[o];if(l==null||l!=n&&s[o+1]==1){s[o]=n;s[o+1]=1}else l==n&&s[o+1]++}}}l+=p;i+=d.nodeSize}const d=(c+1)*e;let p=0;while(l<d)o[l++]==0&&p++;p&&(r||(r=[])).push({type:"missing",row:c,n:p});i++}e!==0&&n!==0||(r||(r=[])).push({type:"zero_sized"});const c=new u(e,n,o,r);let i=false;for(let t=0;!i&&t<s.length;t+=2)s[t]!=null&&s[t+1]<n&&(i=true);i&&g(c,s,t);return c}function w(t){let e=-1;let n=false;for(let o=0;o<t.childCount;o++){const l=t.child(o);let r=0;if(n)for(let e=0;e<o;e++){const n=t.child(e);for(let t=0;t<n.childCount;t++){const l=n.child(t);e+l.attrs.rowspan>o&&(r+=l.attrs.colspan)}}for(let t=0;t<l.childCount;t++){const e=l.child(t);r+=e.attrs.colspan;e.attrs.rowspan>1&&(n=true)}e==-1?e=r:e!=r&&(e=Math.max(e,r))}return e}function g(t,e,n){t.problems||(t.problems=[]);const o={};for(let l=0;l<t.map.length;l++){const r=t.map[l];if(o[r])continue;o[r]=true;const s=n.nodeAt(r);if(!s)throw new RangeError(`No cell with offset ${r} found`);let c=null;const i=s.attrs;for(let n=0;n<i.colspan;n++){const o=e[(l+n)%t.width*2];o==null||i.colwidth&&i.colwidth[n]==o||((c||(c=b(i)))[n]=o)}c&&t.problems.unshift({type:"colwidth mismatch",pos:r,colwidth:c})}}function b(t){if(t.colwidth)return t.colwidth.slice();const e=[];for(let n=0;n<t.colspan;n++)e.push(0);return e}function v(t,e){if(typeof t==="string")return{};const n=t.getAttribute("data-colwidth");const o=n&&/^\d+(,\d+)*$/.test(n)?n.split(",").map((t=>Number(t))):null;const l=Number(t.getAttribute("colspan")||1);
3const r={colspan:l,rowspan:Number(t.getAttribute("rowspan")||1),colwidth:o&&o.length==l?o:null};for(const n in e){const o=e[n].getFromDOM;const l=o&&o(t);l!=null&&(r[n]=l)}return r}function C(t,e){const n={};t.attrs.colspan!=1&&(n.colspan=t.attrs.colspan);t.attrs.rowspan!=1&&(n.rowspan=t.attrs.rowspan);t.attrs.colwidth&&(n["data-colwidth"]=t.attrs.colwidth.join(","));for(const o in e){const l=e[o].setDOMAttr;l&&l(t.attrs[o],n)}return n}function y(t){if(t!==null){if(!Array.isArray(t))throw new TypeError("colwidth must be null or an array");for(const e of t)if(typeof e!=="number")throw new TypeError("colwidth must be null or an array of numbers")}}function S(t){const e=t.cellAttributes||{};const n={colspan:{default:1,validate:"number"},rowspan:{default:1,validate:"number"},colwidth:{default:null,validate:y}};for(const t in e)n[t]={default:e[t].default,validate:e[t].validate};return{table:{content:"table_row+",tableRole:"table",isolating:true,group:t.tableGroup,parseDOM:[{tag:"table"}],toDOM(){return["table",["tbody",0]]}},table_row:{content:"(table_cell | table_header)*",tableRole:"row",parseDOM:[{tag:"tr"}],toDOM(){return["tr",0]}},table_cell:{content:t.cellContent,attrs:n,tableRole:"cell",isolating:true,parseDOM:[{tag:"td",getAttrs:t=>v(t,e)}],toDOM(t){return["td",C(t,e),0]}},table_header:{content:t.cellContent,attrs:n,tableRole:"header_cell",isolating:true,parseDOM:[{tag:"th",getAttrs:t=>v(t,e)}],toDOM(t){return["th",C(t,e),0]}}}}function A(t){let e=t.cached.tableNodeTypes;if(!e){e=t.cached.tableNodeTypes={};for(const n in t.nodes){const o=t.nodes[n],l=o.spec.tableRole;l&&(e[l]=o)}}return e}const $=new t("selectingCells");function M(t){for(let e=t.depth-1;e>0;e--)if(t.node(e).type.spec.tableRole=="row")return t.node(0).resolve(t.before(e+1));return null}function R(t){for(let e=t.depth;e>0;e--){const n=t.node(e).type.spec.tableRole;if(n==="cell"||n==="header_cell")return t.node(e)}return null}function z(t){const e=t.selection.$head;for(let t=e.depth;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return true;return false}function k(t){const e=t.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 n=M(e.$head)||x(e.$head);if(n)return n;throw new RangeError(`No cell found around position ${e.head}`)}function x(t){for(let e=t.nodeAfter,n=t.pos;e;e=e.firstChild,n++){const o=e.type.spec.tableRole;if(o=="cell"||o=="header_cell")return t.doc.resolve(n)}for(let e=t.nodeBefore,n=t.pos;e;e=e.lastChild,n--){const o=e.type.spec.tableRole;if(o=="cell"||o=="header_cell")return t.doc.resolve(n-e.nodeSize)}}function N(t){return t.parent.type.spec.tableRole=="row"&&!!t.nodeAfter}function E(t){return t.node(0).resolve(t.pos+t.nodeAfter.nodeSize)}function _(t,e){return t.depth==e.depth&&t.pos>=e.start(-1)&&t.pos<=e.end(-1)}function D(t){return u.get(t.node(-1)).findCell(t.pos-t.start(-1))}function H(t){return u.get(t.node(-1)).colCount(t.pos-t.start(-1))}function I(t,e,n){const o=t.node(-1);const l=u.get(o);const r=t.start(-1);const s=l.nextCell(t.pos-r,e,n);return s==null?null:t.node(0).resolve(r+s)}function L(t,e,n=1){const o={...t,colspan:t.colspan-n};if(o.colwidth){o.colwidth=o.colwidth.slice();o.colwidth.splice(e,n);o.colwidth.some((t=>t>0))||(o.colwidth=null)}return o}function O(t,e,n=1){const o={...t,colspan:t.colspan+n};if(o.colwidth){o.colwidth=o.colwidth.slice();for(let t=0;t<n;t++)o.colwidth.splice(e,0,0)}return o}function B(t,e,n){const o=A(e.type.schema).header_cell;for(let l=0;l<t.height;l++)if(e.nodeAt(t.map[n+l*t.width]).type!=o)return false;return true}var F=class CellSelection extends e{constructor(t,e=t){const o=t.node(-1);const l=u.get(o);const r=t.start(-1);const s=l.rectBetween(t.pos-r,e.pos-r);const c=t.node(0);const i=l.cellsInRect(s).filter((t=>t!=e.pos-r));i.unshift(e.pos-r);const a=i.map((t=>{const e=o.nodeAt(t);if(!e)throw new RangeError(`No cell with offset ${t} found`);const l=r+t+1;return new n(c.resolve(l),c.resolve(l+e.content.size))}));super(a[0].$from,a[0].$to,a);this.$anchorCell=t;this.$headCell=e}map(t,e){const n=t.resolve(e.map(this.$anchorCell.pos));const l=t.resolve(e.map(this.$headCell.pos));if(N(n)&&N(l)&&_(n,l)){const t=this.$anchorCell.node(-1)!=n.node(-1);return t&&this.isRowSelection()?CellSelection.rowSelection(n,l):t&&this.isColSelection()?CellSelection.colSelection(n,l):new CellSelection(n,l)}return o.between(n,l)}content(){const t=this.$anchorCell.node(-1);const e=u.get(t);const n=this.$anchorCell.start(-1);const o=e.rectBetween(this.$anchorCell.pos-n,this.$headCell.pos-n);const l={};const r=[];for(let n=o.top;n<o.bottom;n++){const c=[];for(let r=n*e.width+o.left,s=o.left;s<o.right;s++,r++){const n=e.map[r];if(l[n])continue;l[n]=true;const s=e.findCell(n);let i=t.nodeAt(n);if(!i)throw new RangeError(`No cell with offset ${n} found`);const a=o.left-s.left;const d=s.right-o.right;if(a>0||d>0){let t=i.attrs;a>0&&(t=L(t,0,a));d>0&&(t=L(t,t.colspan-d,d));if(s.left<o.left){i=i.type.createAndFill(t);if(!i)throw new RangeError(`Could not create cell with attrs ${JSON.stringify(t)}`)}else i=i.type.create(t,i.content)}if(s.top<o.top||s.bottom>o.bottom){const t={...i.attrs,rowspan:Math.min(s.bottom,o.bottom)-Math.max(s.top,o.top)};i=s.top<o.top?i.type.createAndFill(t):i.type.create(t,i.content)}c.push(i)}r.push(t.child(n).copy(s.from(c)))}const i=this.isColSelection()&&this.isRowSelection()?t:r;return new c(s.from(i),1,1)}replace(t,n=c.empty){const o=t.steps.length,l=this.ranges;for(let e=0;e<l.length;e++){const{$from:r,$to:s}=l[e],i=t.mapping.slice(o);t.replace(i.map(r.pos),i.map(s.pos),e?c.empty:n)}const r=e.findFrom(t.doc.resolve(t.mapping.slice(o).map(this.to)),-1);r&&t.setSelection(r)}replaceWith(t,e){this.replace(t,new c(s.from(e),0,0))}forEachCell(t){const e=this.$anchorCell.node(-1);const n=u.get(e);const o=this.$anchorCell.start(-1);const l=n.cellsInRect(n.rectBetween(this.$anchorCell.pos-o,this.$headCell.pos-o));for(let n=0;n<l.length;n++)t(e.nodeAt(l[n]),o+l[n])}isColSelection(){const t=this.$anchorCell.index(-1);const e=this.$headCell.index(-1);if(Math.min(t,e)>0)return false;const n=t+this.$anchorCell.nodeAfter.attrs.rowspan;const o=e+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(n,o)==this.$headCell.node(-1).childCount}static colSelection(t,e=t){const n=t.node(-1);const o=u.get(n);const l=t.start(-1);const r=o.findCell(t.pos-l);const s=o.findCell(e.pos-l);const c=t.node(0);if(r.top<=s.top){r.top>0&&(t=c.resolve(l+o.map[r.left]));s.bottom<o.height&&(e=c.resolve(l+o.map[o.width*(o.height-1)+s.right-1]))}else{s.top>0&&(e=c.resolve(l+o.map[s.left]));r.bottom<o.height&&(t=c.resolve(l+o.map[o.width*(o.height-1)+r.right-1]))}return new CellSelection(t,e)}isRowSelection(){const t=this.$anchorCell.node(-1);const e=u.get(t);const n=this.$anchorCell.start(-1);const o=e.colCount(this.$anchorCell.pos-n);const l=e.colCount(this.$headCell.pos-n);
3if(Math.min(o,l)>0)return false;const r=o+this.$anchorCell.nodeAfter.attrs.colspan;const s=l+this.$headCell.nodeAfter.attrs.colspan;return Math.max(r,s)==e.width}eq(t){return t instanceof CellSelection&&t.$anchorCell.pos==this.$anchorCell.pos&&t.$headCell.pos==this.$headCell.pos}static rowSelection(t,e=t){const n=t.node(-1);const o=u.get(n);const l=t.start(-1);const r=o.findCell(t.pos-l);const s=o.findCell(e.pos-l);const c=t.node(0);if(r.left<=s.left){r.left>0&&(t=c.resolve(l+o.map[r.top*o.width]));s.right<o.width&&(e=c.resolve(l+o.map[o.width*(s.top+1)-1]))}else{s.left>0&&(e=c.resolve(l+o.map[s.top*o.width]));r.right<o.width&&(t=c.resolve(l+o.map[o.width*(r.top+1)-1]))}return new CellSelection(t,e)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(t,e){return new CellSelection(t.resolve(e.anchor),t.resolve(e.head))}static create(t,e,n=e){return new CellSelection(t.resolve(e),t.resolve(n))}getBookmark(){return new W(this.$anchorCell.pos,this.$headCell.pos)}};F.prototype.visible=false;e.jsonID("cell",F);var W=class CellBookmark{constructor(t,e){this.anchor=t;this.head=e}map(t){return new CellBookmark(t.map(this.anchor),t.map(this.head))}resolve(t){const n=t.resolve(this.anchor),o=t.resolve(this.head);return n.parent.type.spec.tableRole=="row"&&o.parent.type.spec.tableRole=="row"&&n.index()<n.parent.childCount&&o.index()<o.parent.childCount&&_(n,o)?new F(n,o):e.near(o,1)}};function T(t){if(!(t.selection instanceof F))return null;const e=[];t.selection.forEachCell(((t,n)=>{e.push(i.node(n,n+t.nodeSize,{class:"selectedCell"}))}));return a.create(t.doc,e)}function X({$from:t,$to:e}){if(t.pos==e.pos||t.pos<e.pos-6)return false;let n=t.pos;let o=e.pos;let l=t.depth;for(;l>=0;l--,n++)if(t.after(l+1)<t.end(l))break;for(let t=e.depth;t>=0;t--,o--)if(e.before(t+1)>e.start(t))break;return n==o&&/row|table/.test(t.node(l).type.spec.tableRole)}function V({$from:t,$to:e}){let n;let o;for(let e=t.depth;e>0;e--){const o=t.node(e);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){n=o;break}}for(let t=e.depth;t>0;t--){const n=e.node(t);if(n.type.spec.tableRole==="cell"||n.type.spec.tableRole==="header_cell"){o=n;break}}return n!==o&&e.parentOffset===0}function K(t,e,n){const r=(e||t).selection;const s=(e||t).doc;let c;let i;if(r instanceof l&&(i=r.node.type.spec.tableRole)){if(i=="cell"||i=="header_cell")c=F.create(s,r.from);else if(i=="row"){const t=s.resolve(r.from+1);c=F.rowSelection(t,t)}else if(!n){const t=u.get(r.node);const e=r.from+1;const n=e+t.map[t.width*t.height-1];c=F.create(s,e+1,n)}}else r instanceof o&&X(r)?c=o.create(s,r.from):r instanceof o&&V(r)&&(c=o.create(s,r.$from.start(),r.$from.end()));c&&(e||(e=t.tr)).setSelection(c);return e}const P=new t("fix-tables");function q(t,e,n,o){const l=t.childCount,r=e.childCount;t:for(let s=0,c=0;s<r;s++){const r=e.child(s);for(let e=c,o=Math.min(l,s+3);e<o;e++)if(t.child(e)==r){c=e+1;n+=r.nodeSize;continue t}o(r,n);c<l&&t.child(c).sameMarkup(r)?q(t.child(c),r,n+1,o):r.nodesBetween(0,r.content.size,o,n+1);n+=r.nodeSize}}function J(t,e){let n;const o=(e,o)=>{e.type.spec.tableRole=="table"&&(n=j(t,e,o,n))};e?e.doc!=t.doc&&q(e.doc,t.doc,0,o):t.doc.descendants(o);return n}function j(t,e,n,o){const l=u.get(e);if(!l.problems)return o;o||(o=t.tr);const r=[];for(let t=0;t<l.height;t++)r.push(0);for(let t=0;t<l.problems.length;t++){const s=l.problems[t];if(s.type=="collision"){const t=e.nodeAt(s.pos);if(!t)continue;const l=t.attrs;for(let t=0;t<l.rowspan;t++)r[s.row+t]+=s.n;o.setNodeMarkup(o.mapping.map(n+1+s.pos),null,L(l,l.colspan-s.n,s.n))}else if(s.type=="missing")r[s.row]+=s.n;else if(s.type=="overlong_rowspan"){const t=e.nodeAt(s.pos);if(!t)continue;o.setNodeMarkup(o.mapping.map(n+1+s.pos),null,{...t.attrs,rowspan:t.attrs.rowspan-s.n})}else if(s.type=="colwidth mismatch"){const t=e.nodeAt(s.pos);if(!t)continue;o.setNodeMarkup(o.mapping.map(n+1+s.pos),null,{...t.attrs,colwidth:s.colwidth})}else if(s.type=="zero_sized"){const t=o.mapping.map(n);o.delete(t,t+e.nodeSize)}}let s,c;for(let t=0;t<r.length;t++)if(r[t]){s==null&&(s=t);c=t}for(let i=0,a=n+1;i<l.height;i++){const n=e.child(i);const l=a+n.nodeSize;const d=r[i];if(d>0){let e="cell";n.firstChild&&(e=n.firstChild.type.spec.tableRole);const r=[];for(let n=0;n<d;n++){const n=A(t.schema)[e].createAndFill();n&&r.push(n)}const p=i!=0&&s!=i-1||c!=i?l-1:a+1;o.insert(o.mapping.map(p),r)}a=l}return o.setMeta(P,{fixTables:true})}function U(t){const e=u.get(t);const n=[];const o=e.height;const l=e.width;for(let r=0;r<o;r++){const o=[];for(let n=0;n<l;n++){const s=r*l+n;const c=e.map[s];if(r>0){const t=s-l;if(c===e.map[t]){o.push(null);continue}}if(n>0){const t=s-1;if(c===e.map[t]){o.push(null);continue}}
3o.push(t.nodeAt(c))}n.push(o)}return n}function Y(t,e){const n=[];const o=u.get(t);const l=o.height;const r=o.width;for(let s=0;s<l;s++){const l=t.child(s);const c=[];for(let n=0;n<r;n++){const l=e[s][n];if(!l)continue;const r=o.map[s*o.width+n];const i=t.nodeAt(r);if(!i)continue;const a=i.type.createChecked(l.attrs,l.content,l.marks);c.push(a)}const i=l.type.createChecked(l.attrs,c,l.marks);n.push(i)}return t.type.createChecked(t.attrs,n,t.marks)}function G(t,e,n,o){const l=e[0]>n[0]?-1:1;const r=t.splice(e[0],e.length);const s=r.length%2===0?1:0;let c;c=o===-1&&l===1?n[0]-1:o===1&&l===-1?n[n.length-1]-s+1:l===-1?n[0]:n[n.length-1]-s;t.splice(c,0,...r);return t}function Q(t){return t instanceof F}function Z(t){return nt((t=>t.type.spec.tableRole==="table"),t)}function tt(t,e,n){var o,l;if(e==null&&n==null&&Q(t))return[t.$anchorCell,t.$headCell];const r=(o=e!==null&&e!==void 0?e:n)!==null&&o!==void 0?o:t.anchor;const s=(l=n!==null&&n!==void 0?n:e)!==null&&l!==void 0?l:t.head;const c=t.$head.doc;const i=et(c,r);const a=et(c,s);return i&&a&&_(i,a)?[i,a]:null}function et(t,e){const n=t.resolve(e);return M(n)||x(n)}function nt(t,e){for(let n=e.depth;n>=0;n-=1){const o=e.node(n);if(t(o))return{node:o,pos:n===0?0:e.before(n),start:e.start(n),depth:n}}return null}function ot(t,e){const n=Z(e.$from);if(!n)return;const o=u.get(n.node);return t<0||t>o.width-1?void 0:o.cellsInRect({left:t,right:t+1,top:0,bottom:o.height}).map((t=>{const e=n.node.nodeAt(t);const o=t+n.start;return{pos:o,start:o+1,node:e,depth:n.depth+2}}))}function lt(t,e){const n=Z(e.$from);if(!n)return;const o=u.get(n.node);return t<0||t>o.height-1?void 0:o.cellsInRect({left:0,right:o.width,top:t,bottom:t+1}).map((t=>{const e=n.node.nodeAt(t);const o=t+n.start;return{pos:o,start:o+1,node:e,depth:n.depth+2}}))}function rt(t,e,n=e){let o=e;let l=n;for(let n=e;n>=0;n--){const e=ot(n,t.selection);e&&e.forEach((t=>{const e=t.node.attrs.colspan+n-1;e>=o&&(o=n);e>l&&(l=e)}))}for(let n=e;n<=l;n++){const e=ot(n,t.selection);e&&e.forEach((t=>{const e=t.node.attrs.colspan+n-1;t.node.attrs.colspan>1&&e>l&&(l=e)}))}const r=[];for(let e=o;e<=l;e++){const n=ot(e,t.selection);n&&n.length>0&&r.push(e)}o=r[0];l=r[r.length-1];const s=ot(o,t.selection);const c=lt(0,t.selection);if(!s||!c)return;const i=t.doc.resolve(s[s.length-1].pos);let a;for(let e=l;e>=o;e--){const n=ot(e,t.selection);if(n&&n.length>0){for(let t=c.length-1;t>=0;t--)if(c[t].pos===n[0].pos){a=n[0];break}if(a)break}}return a?{$anchor:i,$head:t.doc.resolve(a.pos),indexes:r}:void 0}function st(t,e,n=e){let o=e;let l=n;for(let n=e;n>=0;n--){const e=lt(n,t.selection);e&&e.forEach((t=>{const e=t.node.attrs.rowspan+n-1;e>=o&&(o=n);e>l&&(l=e)}))}for(let n=e;n<=l;n++){const e=lt(n,t.selection);e&&e.forEach((t=>{const e=t.node.attrs.rowspan+n-1;t.node.attrs.rowspan>1&&e>l&&(l=e)}))}const r=[];for(let e=o;e<=l;e++){const n=lt(e,t.selection);n&&n.length>0&&r.push(e)}o=r[0];l=r[r.length-1];const s=lt(o,t.selection);const c=ot(0,t.selection);if(!s||!c)return;const i=t.doc.resolve(s[s.length-1].pos);let a;for(let e=l;e>=o;e--){const n=lt(e,t.selection);if(n&&n.length>0){for(let t=c.length-1;t>=0;t--)if(c[t].pos===n[0].pos){a=n[0];break}if(a)break}}return a?{$anchor:i,$head:t.doc.resolve(a.pos),indexes:r}:void 0}function ct(t){return t[0].map(((e,n)=>t.map((t=>t[n]))))}function it(t){var e,n;const{tr:o,originIndex:l,targetIndex:r,select:s,pos:c}=t;const i=Z(o.doc.resolve(c));if(!i)return false;const a=(e=rt(o,l))===null||e===void 0?void 0:e.indexes;const d=(n=rt(o,r))===null||n===void 0?void 0:n.indexes;if(!a||!d)return false;if(a.includes(r))return false;const p=at(i.node,a,d,0);o.replaceWith(i.pos,i.pos+i.node.nodeSize,p);if(!s)return true;const f=u.get(p);const h=i.start;const m=r;const w=f.positionAt(f.height-1,m,p);const g=o.doc.resolve(h+w);const b=f.positionAt(0,m,p);const v=o.doc.resolve(h+b);o.setSelection(F.colSelection(g,v));return true}function at(t,e,n,o){let l=ct(U(t));l=G(l,e,n,o);l=ct(l);return Y(t,l)}function dt(t){var e,n;const{tr:o,originIndex:l,targetIndex:r,select:s,pos:c}=t;const i=Z(o.doc.resolve(c));if(!i)return false;const a=(e=st(o,l))===null||e===void 0?void 0:e.indexes;const d=(n=st(o,r))===null||n===void 0?void 0:n.indexes;if(!a||!d)return false;if(a.includes(r))return false;const p=pt(i.node,a,d,0);o.replaceWith(i.pos,i.pos+i.node.nodeSize,p);if(!s)return true;const f=u.get(p);const h=i.start;const m=r;const w=f.positionAt(m,f.width-1,p);const g=o.doc.resolve(h+w);const b=f.positionAt(m,0,p);const v=o.doc.resolve(h+b);o.setSelection(F.rowSelection(g,v));return true}function pt(t,e,n,o){let l=U(t);l=G(l,e,n,o);return Y(t,l)}function ft(t){const e=t.selection;const n=k(t);const o=n.node(-1);const l=n.start(-1);const r=u.get(o);return{...e instanceof F?r.rectBetween(e.$anchorCell.pos-l,e.$headCell.pos-l):r.findCell(n.pos-l),tableStart:l,map:r,table:o}}function ht(t,{map:e,tableStart:n,table:o},l){let r=l>0?-1:0;B(e,o,l+r)&&(r=l==0||l==e.width?null:0);for(let s=0;s<e.height;s++){const c=s*e.width+l;if(l>0&&l<e.width&&e.map[c-1]==e.map[c]){const r=e.map[c];const i=o.nodeAt(r);t.setNodeMarkup(t.mapping.map(n+r),null,O(i.attrs,l-e.colCount(r)));s+=i.attrs.rowspan-1}else{const i=r==null?A(o.type.schema).cell:o.nodeAt(e.map[c+r]).type;const a=e.positionAt(s,l,o);t.insert(t.mapping.map(n+a),i.createAndFill())}}return t}function ut(t,e){if(!z(t))return false;if(e){const n=ft(t);e(ht(t.tr,n,n.left))}return true}function mt(t,e){if(!z(t))return false;if(e){const n=ft(t);e(ht(t.tr,n,n.right))}return true}function wt(t,{map:e,table:n,tableStart:o},l){const r=t.mapping.maps.length;for(let s=0;s<e.height;){const c=s*e.width+l;const i=e.map[c];const a=n.nodeAt(i);const d=a.attrs;if(l>0&&e.map[c-1]==i||l<e.width-1&&e.map[c+1]==i)t.setNodeMarkup(t.mapping.slice(r).map(o+i),null,L(d,l-e.colCount(i)));else{const e=t.mapping.slice(r).map(o+i);t.delete(e,e+a.nodeSize)}s+=d.rowspan}
3}function gt(t,e){if(!z(t))return false;if(e){const n=ft(t);const o=t.tr;if(n.left==0&&n.right==n.map.width)return false;for(let t=n.right-1;;t--){wt(o,n,t);if(t==n.left)break;const e=n.tableStart?o.doc.nodeAt(n.tableStart-1):o.doc;if(!e)throw new RangeError("No table found");n.table=e;n.map=u.get(e)}e(o)}return true}function bt(t,e,n){var o;const l=A(e.type.schema).header_cell;for(let r=0;r<t.width;r++)if(((o=e.nodeAt(t.map[r+n*t.width]))===null||o===void 0?void 0:o.type)!=l)return false;return true}function vt(t,{map:e,tableStart:n,table:o},l){let r=n;for(let t=0;t<l;t++)r+=o.child(t).nodeSize;const s=[];let c=l>0?-1:0;bt(e,o,l+c)&&(c=l==0||l==e.height?null:0);for(let r=0,a=e.width*l;r<e.width;r++,a++)if(l>0&&l<e.height&&e.map[a]==e.map[a-e.width]){const l=e.map[a];const s=o.nodeAt(l).attrs;t.setNodeMarkup(n+l,null,{...s,rowspan:s.rowspan+1});r+=s.colspan-1}else{var i;const t=c==null?A(o.type.schema).cell:(i=o.nodeAt(e.map[a+c*e.width]))===null||i===void 0?void 0:i.type;const n=t===null||t===void 0?void 0:t.createAndFill();n&&s.push(n)}t.insert(r,A(o.type.schema).row.create(null,s));return t}function Ct(t,e){if(!z(t))return false;if(e){const n=ft(t);e(vt(t.tr,n,n.top))}return true}function yt(t,e){if(!z(t))return false;if(e){const n=ft(t);e(vt(t.tr,n,n.bottom))}return true}function St(t,{map:e,table:n,tableStart:o},l){let r=0;for(let t=0;t<l;t++)r+=n.child(t).nodeSize;const s=r+n.child(l).nodeSize;const c=t.mapping.maps.length;t.delete(r+o,s+o);const i=new Set;for(let r=0,s=l*e.width;r<e.width;r++,s++){const a=e.map[s];if(!i.has(a)){i.add(a);if(l>0&&a==e.map[s-e.width]){const e=n.nodeAt(a).attrs;t.setNodeMarkup(t.mapping.slice(c).map(a+o),null,{...e,rowspan:e.rowspan-1});r+=e.colspan-1}else if(l<e.height&&a==e.map[s+e.width]){const s=n.nodeAt(a);const i=s.attrs;const d=s.type.create({...i,rowspan:s.attrs.rowspan-1},s.content);const p=e.positionAt(l+1,r,n);t.insert(t.mapping.slice(c).map(o+p),d);r+=i.colspan-1}}}}function At(t,e){if(!z(t))return false;if(e){const n=ft(t),o=t.tr;if(n.top==0&&n.bottom==n.map.height)return false;for(let t=n.bottom-1;;t--){St(o,n,t);if(t==n.top)break;const e=n.tableStart?o.doc.nodeAt(n.tableStart-1):o.doc;if(!e)throw new RangeError("No table found");n.table=e;n.map=u.get(n.table)}e(o)}return true}function $t(t){const e=t.content;return e.childCount==1&&e.child(0).isTextblock&&e.child(0).childCount==0}function Mt({width:t,height:e,map:n},o){let l=o.top*t+o.left,r=l;let s=(o.bottom-1)*t+o.left,c=l+(o.right-o.left-1);for(let e=o.top;e<o.bottom;e++){if(o.left>0&&n[r]==n[r-1]||o.right<t&&n[c]==n[c+1])return true;r+=t;c+=t}for(let r=o.left;r<o.right;r++){if(o.top>0&&n[l]==n[l-t]||o.bottom<e&&n[s]==n[s+t])return true;l++;s++}return false}function Rt(t,e){const n=t.selection;if(!(n instanceof F)||n.$anchorCell.pos==n.$headCell.pos)return false;const o=ft(t),{map:l}=o;if(Mt(l,o))return false;if(e){const n=t.tr;const r={};let c=s.empty;let i;let a;for(let t=o.top;t<o.bottom;t++)for(let e=o.left;e<o.right;e++){const s=l.map[t*l.width+e];const d=o.table.nodeAt(s);if(!r[s]&&d){r[s]=true;if(i==null){i=s;a=d}else{$t(d)||(c=c.append(d.content));const t=n.mapping.map(s+o.tableStart);n.delete(t,t+d.nodeSize)}}}if(i==null||a==null)return true;n.setNodeMarkup(i+o.tableStart,null,{...O(a.attrs,a.attrs.colspan,o.right-o.left-a.attrs.colspan),rowspan:o.bottom-o.top});if(c.size>0){const t=i+1+a.content.size;const e=$t(a)?i+1:t;n.replaceWith(e+o.tableStart,t+o.tableStart,c)}n.setSelection(new F(n.doc.resolve(i+o.tableStart)));e(n)}return true}function zt(t,e){const n=A(t.schema);return kt((({node:t})=>n[t.type.spec.tableRole]))(t,e)}function kt(t){return(e,n)=>{const o=e.selection;let l;let r;if(o instanceof F){if(o.$anchorCell.pos!=o.$headCell.pos)return false;l=o.$anchorCell.nodeAfter;r=o.$anchorCell.pos}else{var s;l=R(o.$from);if(!l)return false;r=(s=M(o.$from))===null||s===void 0?void 0:s.pos}if(l==null||r==null)return false;if(l.attrs.colspan==1&&l.attrs.rowspan==1)return false;if(n){let s=l.attrs;const c=[];const i=s.colwidth;s.rowspan>1&&(s={...s,rowspan:1});s.colspan>1&&(s={...s,colspan:1});const a=ft(e),d=e.tr;for(let t=0;t<a.right-a.left;
3t++)c.push(i?{...s,colwidth:i&&i[t]?[i[t]]:null}:s);let p;for(let e=a.top;e<a.bottom;e++){let n=a.map.positionAt(e,a.left,a.table);e==a.top&&(n+=l.nodeSize);for(let o=a.left,r=0;o<a.right;o++,r++)o==a.left&&e==a.top||d.insert(p=d.mapping.map(n+a.tableStart,1),t({node:l,row:e,col:o}).createAndFill(c[r]))}d.setNodeMarkup(r,t({node:l,row:a.top,col:a.left}),c[0]);o instanceof F&&d.setSelection(new F(d.doc.resolve(o.$anchorCell.pos),p?d.doc.resolve(p):void 0));n(d)}return true}}function xt(t,e){return function(n,o){if(!z(n))return false;const l=k(n);if(l.nodeAfter.attrs[t]===e)return false;if(o){const r=n.tr;n.selection instanceof F?n.selection.forEachCell(((n,o)=>{n.attrs[t]!==e&&r.setNodeMarkup(o,null,{...n.attrs,[t]:e})})):r.setNodeMarkup(l.pos,null,{...l.nodeAfter.attrs,[t]:e});o(r)}return true}}function Nt(t){return function(e,n){if(!z(e))return false;if(n){const o=A(e.schema);const l=ft(e),r=e.tr;const s=l.map.cellsInRect(t=="column"?{left:l.left,top:0,right:l.right,bottom:l.map.height}:t=="row"?{left:0,top:l.top,right:l.map.width,bottom:l.bottom}:l);const c=s.map((t=>l.table.nodeAt(t)));for(let t=0;t<s.length;t++)c[t].type==o.header_cell&&r.setNodeMarkup(l.tableStart+s[t],o.cell,c[t].attrs);if(r.steps.length===0)for(let t=0;t<s.length;t++)r.setNodeMarkup(l.tableStart+s[t],o.header_cell,c[t].attrs);n(r)}return true}}function Et(t,e,n){const o=e.map.cellsInRect({left:0,top:0,right:t=="row"?e.map.width:1,bottom:t=="column"?e.map.height:1});for(let t=0;t<o.length;t++){const l=e.table.nodeAt(o[t]);if(l&&l.type!==n.header_cell)return false}return true}function _t(t,e){e=e||{useDeprecatedLogic:false};return e.useDeprecatedLogic?Nt(t):function(e,n){if(!z(e))return false;if(n){const o=A(e.schema);const l=ft(e),r=e.tr;const s=Et("row",l,o);const c=Et("column",l,o);const i=(t==="column"?s:t==="row"&&c)?1:0;const a=t=="column"?{left:0,top:i,right:1,bottom:l.map.height}:t=="row"?{left:i,top:0,right:l.map.width,bottom:1}:l;const d=t=="column"?c?o.cell:o.header_cell:t=="row"?s?o.cell:o.header_cell:o.cell;l.map.cellsInRect(a).forEach((t=>{const e=t+l.tableStart;const n=r.doc.nodeAt(e);n&&r.setNodeMarkup(e,d,n.attrs)}));n(r)}return true}}const Dt=_t("row",{useDeprecatedLogic:true});const Ht=_t("column",{useDeprecatedLogic:true});const It=_t("cell",{useDeprecatedLogic:true});function Lt(t,e){if(e<0){const e=t.nodeBefore;if(e)return t.pos-e.nodeSize;for(let e=t.index(-1)-1,n=t.before();e>=0;e--){const o=t.node(-1).child(e);const l=o.lastChild;if(l)return n-1-l.nodeSize;n-=o.nodeSize}}else{if(t.index()<t.parent.childCount-1)return t.pos+t.nodeAfter.nodeSize;const e=t.node(-1);for(let n=t.indexAfter(-1),o=t.after();n<e.childCount;n++){const t=e.child(n);if(t.childCount)return o+1;o+=t.nodeSize}}return null}function Ot(t){return function(e,n){if(!z(e))return false;const l=Lt(k(e),t);if(l==null)return false;if(n){const t=e.doc.resolve(l);n(e.tr.setSelection(o.between(t,E(t))).scrollIntoView())}return true}}function Bt(t,e){const n=t.selection.$anchor;for(let o=n.depth;o>0;o--)if(n.node(o).type.spec.tableRole=="table"){e&&e(t.tr.delete(n.before(o),n.after(o)).scrollIntoView());return true}return false}function Ft(t,e){const n=t.selection;if(!(n instanceof F))return false;if(e){const o=t.tr;const l=A(t.schema).cell.createAndFill().content;n.forEachCell(((t,e)=>{t.content.eq(l)||o.replace(o.mapping.map(e+1),o.mapping.map(e+t.nodeSize-1),new c(l,0,0))}));o.docChanged&&e(o)}return true}function Wt(t){return(e,n)=>{const{from:o,to:l,select:r=true,pos:s=e.selection.from}=t;const c=e.tr;if(dt({tr:c,originIndex:o,targetIndex:l,select:r,pos:s})){n===null||n===void 0||n(c);return true}return false}}function Tt(t){return(e,n)=>{const{from:o,to:l,select:r=true,pos:s=e.selection.from}=t;const c=e.tr;if(it({tr:c,originIndex:o,targetIndex:l,select:r,pos:s})){n===null||n===void 0||n(c);return true}return false}}function Xt(t){if(t.size===0)return null;let{content:e,openStart:n,openEnd:o}=t;while(e.childCount==1&&(n>0&&o>0||e.child(0).type.spec.tableRole=="table")){n--;o--;e=e.child(0).content}const l=e.child(0);const r=l.type.spec.tableRole;const s=l.type.schema,i=[];if(r=="row")for(let t=0;t<e.childCount;t++){let l=e.child(t).content;const r=t?0:Math.max(0,n-1);const a=t<e.childCount-1?0:Math.max(0,o-1);(r||a)&&(l=Kt(A(s).row,new c(l,r,a)).content);i.push(l)}else{if(r!="cell"&&r!="header_cell")return null;i.push(n||o?Kt(A(s).row,new c(e,n,o)).content:e)}return Vt(s,i)}function Vt(t,e){const n=[];for(let t=0;t<e.length;t++){const o=e[t];for(let e=o.childCount-1;e>=0;e--){const{rowspan:l,colspan:r}=o.child(e).attrs;for(let e=t;e<t+l;e++)n[e]=(n[e]||0)+r}}let o=0;for(let t=0;t<n.length;t++)o=Math.max(o,n[t]);for(let l=0;l<n.length;l++){l>=e.length&&e.push(s.empty);if(n[l]<o){const r=A(t).cell.createAndFill();const c=[];for(let t=n[l];t<o;t++)c.push(r);e[l]=e[l].append(s.from(c))}}return{height:e.length,width:o,rows:e}}function Kt(t,e){const n=t.createAndFill();return new p(n).replace(0,n.content.size,e).doc}function Pt({width:t,height:e,rows:n},o,l){if(t!=o){const e=[];const l=[];for(let t=0;t<n.length;
3t++){const r=n[t],c=[];for(let n=e[t]||0,l=0;n<o;l++){let s=r.child(l%r.childCount);n+s.attrs.colspan>o&&(s=s.type.createChecked(L(s.attrs,s.attrs.colspan,n+s.attrs.colspan-o),s.content));c.push(s);n+=s.attrs.colspan;for(let n=1;n<s.attrs.rowspan;n++)e[t+n]=(e[t+n]||0)+s.attrs.colspan}l.push(s.from(c))}n=l;t=o}if(e!=l){const t=[];for(let o=0,r=0;o<l;o++,r++){const c=[],i=n[r%e];for(let t=0;t<i.childCount;t++){let e=i.child(t);o+e.attrs.rowspan>l&&(e=e.type.create({...e.attrs,rowspan:Math.max(1,l-e.attrs.rowspan)},e.content));c.push(e)}t.push(s.from(c))}n=t;e=l}return{width:t,height:e,rows:n}}function qt(t,e,n,o,l,r,c){const i=t.doc.type.schema;const a=A(i);let d;let p;if(l>e.width)for(let r=0,s=0;r<e.height;r++){const i=n.child(r);s+=i.nodeSize;const f=[];let h;h=i.lastChild==null||i.lastChild.type==a.cell?d||(d=a.cell.createAndFill()):p||(p=a.header_cell.createAndFill());for(let t=e.width;t<l;t++)f.push(h);t.insert(t.mapping.slice(c).map(s-1+o),f)}if(r>e.height){const i=[];for(let t=0,o=(e.height-1)*e.width;t<Math.max(e.width,l);t++){const l=!(t>=e.width)&&n.nodeAt(e.map[o+t]).type==a.header_cell;i.push(l?p||(p=a.header_cell.createAndFill()):d||(d=a.cell.createAndFill()))}const f=a.row.create(null,s.from(i)),h=[];for(let t=e.height;t<r;t++)h.push(f);t.insert(t.mapping.slice(c).map(o+n.nodeSize-2),h)}return!!(d||p)}function Jt(t,e,n,o,l,r,s,c){if(s==0||s==e.height)return false;let i=false;for(let a=l;a<r;a++){const l=s*e.width+a,r=e.map[l];if(e.map[l-e.width]==r){i=true;const l=n.nodeAt(r);const{top:d,left:p}=e.findCell(r);t.setNodeMarkup(t.mapping.slice(c).map(r+o),null,{...l.attrs,rowspan:s-d});t.insert(t.mapping.slice(c).map(e.positionAt(s,p,n)),l.type.createAndFill({...l.attrs,rowspan:d+l.attrs.rowspan-s}));a+=l.attrs.colspan-1}}return i}function jt(t,e,n,o,l,r,s,c){if(s==0||s==e.width)return false;let i=false;for(let a=l;a<r;a++){const l=a*e.width+s,r=e.map[l];if(e.map[l-1]==r){i=true;const l=n.nodeAt(r);const d=e.colCount(r);const p=t.mapping.slice(c).map(r+o);t.setNodeMarkup(p,null,L(l.attrs,s-d,l.attrs.colspan-(s-d)));t.insert(p+l.nodeSize,l.type.createAndFill(L(l.attrs,0,s-d)));a+=l.attrs.rowspan-1}}return i}function Ut(t,e,n,o,l){let r=n?t.doc.nodeAt(n-1):t.doc;if(!r)throw new Error("No table found");let s=u.get(r);const{top:i,left:a}=o;const d=a+l.width,p=i+l.height;const f=t.tr;let h=0;function m(){r=n?f.doc.nodeAt(n-1):f.doc;if(!r)throw new Error("No table found");s=u.get(r);h=f.mapping.maps.length}qt(f,s,r,n,d,p,h)&&m();Jt(f,s,r,n,a,d,i,h)&&m();Jt(f,s,r,n,a,d,p,h)&&m();jt(f,s,r,n,i,p,a,h)&&m();jt(f,s,r,n,i,p,d,h)&&m();for(let t=i;t<p;t++){const e=s.positionAt(t,a,r),o=s.positionAt(t,d,r);f.replace(f.mapping.slice(h).map(e+n),f.mapping.slice(h).map(o+n),new c(l.rows[t-i],0,0))}m();f.setSelection(new F(f.doc.resolve(n+s.positionAt(i,a,r)),f.doc.resolve(n+s.positionAt(p-1,d-1,r))));e(f)}const Yt=d({ArrowLeft:Qt("horiz",-1),ArrowRight:Qt("horiz",1),ArrowUp:Qt("vert",-1),ArrowDown:Qt("vert",1),"Shift-ArrowLeft":Zt("horiz",-1),"Shift-ArrowRight":Zt("horiz",1),"Shift-ArrowUp":Zt("vert",-1),"Shift-ArrowDown":Zt("vert",1),Backspace:Ft,"Mod-Backspace":Ft,Delete:Ft,"Mod-Delete":Ft});function Gt(t,e,n){if(n.eq(t.selection))return false;e&&e(t.tr.setSelection(n).scrollIntoView());return true}function Qt(t,n){return(o,l,r)=>{if(!r)return false;const s=o.selection;if(s instanceof F)return Gt(o,l,e.near(s.$headCell,n));if(t!="horiz"&&!s.empty)return false;const c=oe(r,t,n);if(c==null)return false;if(t=="horiz")return Gt(o,l,e.near(o.doc.resolve(s.head+n),n));{const r=o.doc.resolve(c);const s=I(r,t,n);let i;i=s?e.near(s,1):n<0?e.near(o.doc.resolve(r.before(-1)),-1):e.near(o.doc.resolve(r.after(-1)),1);return Gt(o,l,i)}}}function Zt(t,e){return(n,o,l)=>{if(!l)return false;const r=n.selection;let s;if(r instanceof F)s=r;else{const o=oe(l,t,e);if(o==null)return false;s=new F(n.doc.resolve(o))}const c=I(s.$headCell,t,e);return!!c&&Gt(n,o,new F(s.$anchorCell,c))}}function te(t,e){const n=t.state.doc,o=M(n.resolve(e));if(!o)return false;t.dispatch(t.state.tr.setSelection(new F(o)));return true}function ee(t,e,n){if(!z(t.state))return false;let o=Xt(n);const l=t.state.selection;if(l instanceof F){o||(o={width:1,height:1,rows:[s.from(Kt(A(t.state.schema).cell,n))]});const e=l.$anchorCell.node(-1);const r=l.$anchorCell.start(-1);const c=u.get(e).rectBetween(l.$anchorCell.pos-r,l.$headCell.pos-r);o=Pt(o,c.right-c.left,c.bottom-c.top);Ut(t.state,t.dispatch,r,c,o);return true}if(o){const e=k(t.state);const n=e.start(-1);Ut(t.state,t.dispatch,n,u.get(e.node(-1)).findCell(e.pos-n),o);return true}return false}function ne(t,e){var n;if(e.button!=0)return;if(e.ctrlKey||e.metaKey)return;const o=le(t,e.target);let l;if(e.shiftKey&&t.state.selection instanceof F){r(t.state.selection.$anchorCell,e);e.preventDefault()}else if(e.shiftKey&&o&&(l=M(t.state.selection.$anchor))!=null&&((n=re(t,e))===null||n===void 0?void 0:n.pos)!=l.pos){r(l,e);e.preventDefault()}else if(!o)return;function r(e,n){let o=re(t,n);const l=$.getState(t.state)==null;if(!o||!_(e,o)){if(!l)return;o=e}const r=new F(e,o);if(l||!t.state.selection.eq(r)){const n=t.state.tr.setSelection(r);l&&n.setMeta($,e.pos);t.dispatch(n)}}function s(){t.root.removeEventListener("mouseup",s);t.root.removeEventListener("dragstart",s);t.root.removeEventListener("mousemove",c);
3$.getState(t.state)!=null&&t.dispatch(t.state.tr.setMeta($,-1))}function c(n){const l=n;const c=$.getState(t.state);let i;if(c!=null)i=t.state.doc.resolve(c);else if(le(t,l.target)!=o){i=re(t,e);if(!i)return s()}i&&r(i,l)}t.root.addEventListener("mouseup",s);t.root.addEventListener("dragstart",s);t.root.addEventListener("mousemove",c)}function oe(t,e,n){if(!(t.state.selection instanceof o))return null;const{$head:l}=t.state.selection;for(let o=l.depth-1;o>=0;o--){const r=l.node(o);if((n<0?l.index(o):l.indexAfter(o))!=(n<0?0:r.childCount))return null;if(r.type.spec.tableRole=="cell"||r.type.spec.tableRole=="header_cell"){const r=l.before(o);const s=e=="vert"?n>0?"down":"up":n>0?"right":"left";return t.endOfTextblock(s)?r:null}}return null}function le(t,e){for(;e&&e!=t.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function re(t,e){const n=t.posAtCoords({left:e.clientX,top:e.clientY});if(!n)return null;let{inside:o,pos:l}=n;return o>=0&&M(t.state.doc.resolve(o))||M(t.state.doc.resolve(l))}var se=class{constructor(t,e){this.node=t;this.defaultCellMinWidth=e;this.dom=document.createElement("div");this.dom.className="tableWrapper";this.table=this.dom.appendChild(document.createElement("table"));this.table.style.setProperty("--default-cell-min-width",`${e}px`);this.colgroup=this.table.appendChild(document.createElement("colgroup"));ce(t,this.colgroup,this.table,e);this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(t){if(t.type!=this.node.type)return false;this.node=t;ce(t,this.colgroup,this.table,this.defaultCellMinWidth);return true}ignoreMutation(t){return t.type=="attributes"&&(t.target==this.table||this.colgroup.contains(t.target))}};function ce(t,e,n,o,l,r){let s=0;let c=true;let i=e.firstChild;const a=t.firstChild;if(a){for(let t=0,n=0;t<a.childCount;t++){const{colspan:d,colwidth:p}=a.child(t).attrs;for(let t=0;t<d;t++,n++){const a=l==n?r:p&&p[t];const d=a?a+"px":"";s+=a||o;a||(c=false);if(i){i.style.width!=d&&(i.style.width=d);i=i.nextSibling}else{const t=document.createElement("col");t.style.width=d;e.appendChild(t)}}}while(i){var d;const t=i.nextSibling;(d=i.parentNode)===null||d===void 0||d.removeChild(i);i=t}if(c){n.style.width=s+"px";n.style.minWidth=""}else{n.style.width="";n.style.minWidth=s+"px"}}}const ie=new t("tableColumnResizing");function ae({handleWidth:t=5,cellMinWidth:e=25,defaultCellMinWidth:n=100,View:o=se,lastColumnResizable:l=true}={}){const s=new r({key:ie,state:{init(t,e){var l;const r=(l=s.spec)===null||l===void 0||(l=l.props)===null||l===void 0?void 0:l.nodeViews;const c=A(e.schema).table.name;o&&r&&(r[c]=(t,e)=>new o(t,n,e));return new de(-1,false)},apply(t,e){return e.apply(t)}},props:{attributes:t=>{const e=ie.getState(t);return e&&e.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(e,n)=>{pe(e,n,t,l)},mouseleave:t=>{fe(t)},mousedown:(t,o)=>{he(t,o,e,n)}},decorations:t=>{const e=ie.getState(t);if(e&&e.activeHandle>-1)return Se(t,e.activeHandle)},nodeViews:{}}});return s}var de=class ResizeState{constructor(t,e){this.activeHandle=t;this.dragging=e}apply(t){const e=this;const n=t.getMeta(ie);if(n&&n.setHandle!=null)return new ResizeState(n.setHandle,false);if(n&&n.setDragging!==void 0)return new ResizeState(e.activeHandle,n.setDragging);if(e.activeHandle>-1&&t.docChanged){let n=t.mapping.map(e.activeHandle,-1);N(t.doc.resolve(n))||(n=-1);return new ResizeState(n,e.dragging)}return e}};function pe(t,e,n,o){if(!t.editable)return;const l=ie.getState(t.state);if(l&&!l.dragging){const r=me(e.target);let s=-1;if(r){const{left:o,right:l}=r.getBoundingClientRect();e.clientX-o<=n?s=we(t,e,"left",n):l-e.clientX<=n&&(s=we(t,e,"right",n))}if(s!=l.activeHandle){if(!o&&s!==-1){const e=t.state.doc.resolve(s);const n=e.node(-1);const o=u.get(n);const l=e.start(-1);if(o.colCount(e.pos-l)+e.nodeAfter.attrs.colspan-1==o.width-1)return}be(t,s)}}}function fe(t){if(!t.editable)return;const e=ie.getState(t.state);e&&e.activeHandle>-1&&!e.dragging&&be(t,-1)}function he(t,e,n,o){var l;if(!t.editable)return false;const r=(l=t.dom.ownerDocument.defaultView)!==null&&l!==void 0?l:window;const s=ie.getState(t.state);if(!s||s.activeHandle==-1||s.dragging)return false;const c=t.state.doc.nodeAt(s.activeHandle);const i=ue(t,s.activeHandle,c.attrs);t.dispatch(t.state.tr.setMeta(ie,{setDragging:{startX:e.clientX,startWidth:i}}));function a(e){r.removeEventListener("mouseup",a);r.removeEventListener("mousemove",d);const o=ie.getState(t.state);if(o===null||o===void 0?void 0:o.dragging){ve(t,o.activeHandle,ge(o.dragging,e,n));t.dispatch(t.state.tr.setMeta(ie,{setDragging:null}))}}function d(e){if(!e.which)return a(e);const l=ie.getState(t.state);if(l&&l.dragging){const r=ge(l.dragging,e,n);Ce(t,l.activeHandle,r,o)}}Ce(t,s.activeHandle,i,o);r.addEventListener("mouseup",a);r.addEventListener("mousemove",d);e.preventDefault();return true}function ue(t,e,{colspan:n,colwidth:o}){const l=o&&o[o.length-1];if(l)return l;const r=t.domAtPos(e);
3let s=r.node.childNodes[r.offset].offsetWidth,c=n;if(o)for(let t=0;t<n;t++)if(o[t]){s-=o[t];c--}return s/c}function me(t){while(t&&t.nodeName!="TD"&&t.nodeName!="TH")t=t.classList&&t.classList.contains("ProseMirror")?null:t.parentNode;return t}function we(t,e,n,o){const l=n=="right"?-o:o;const r=t.posAtCoords({left:e.clientX+l,top:e.clientY});if(!r)return-1;const{pos:s}=r;const c=M(t.state.doc.resolve(s));if(!c)return-1;if(n=="right")return c.pos;const i=u.get(c.node(-1)),a=c.start(-1);const d=i.map.indexOf(c.pos-a);return d%i.width==0?-1:a+i.map[d-1]}function ge(t,e,n){const o=e.clientX-t.startX;return Math.max(n,t.startWidth+o)}function be(t,e){t.dispatch(t.state.tr.setMeta(ie,{setHandle:e}))}function ve(t,e,n){const o=t.state.doc.resolve(e);const l=o.node(-1),r=u.get(l),s=o.start(-1);const c=r.colCount(o.pos-s)+o.nodeAfter.attrs.colspan-1;const i=t.state.tr;for(let t=0;t<r.height;t++){const e=t*r.width+c;if(t&&r.map[e]==r.map[e-r.width])continue;const o=r.map[e];const a=l.nodeAt(o).attrs;const d=a.colspan==1?0:c-r.colCount(o);if(a.colwidth&&a.colwidth[d]==n)continue;const p=a.colwidth?a.colwidth.slice():ye(a.colspan);p[d]=n;i.setNodeMarkup(s+o,null,{...a,colwidth:p})}i.docChanged&&t.dispatch(i)}function Ce(t,e,n,o){const l=t.state.doc.resolve(e);const r=l.node(-1),s=l.start(-1);const c=u.get(r).colCount(l.pos-s)+l.nodeAfter.attrs.colspan-1;let i=t.domAtPos(l.start(-1)).node;while(i&&i.nodeName!="TABLE")i=i.parentNode;i&&ce(r,i.firstChild,i,o,c,n)}function ye(t){return Array(t).fill(0)}function Se(t,e){const n=[];const o=t.doc.resolve(e);const l=o.node(-1);if(!l)return a.empty;const r=u.get(l);const s=o.start(-1);const c=r.colCount(o.pos-s)+o.nodeAfter.attrs.colspan-1;for(let e=0;e<r.height;e++){const o=c+e*r.width;if((c==r.width-1||r.map[o]!=r.map[o+1])&&(e==0||r.map[o]!=r.map[o-r.width])){var d;const e=r.map[o];const c=s+e+l.nodeAt(e).nodeSize-1;const a=document.createElement("div");a.className="column-resize-handle";((d=ie.getState(t))===null||d===void 0?void 0:d.dragging)&&n.push(i.node(s+e,s+e+l.nodeAt(e).nodeSize,{class:"column-resize-dragging"}));n.push(i.widget(c,a))}}return a.create(t.doc,n)}function Ae({allowTableNodeSelection:t=false}={}){return new r({key:$,state:{init(){return null},apply(t,e){const n=t.getMeta($);if(n!=null)return n==-1?null:n;if(e==null||!t.docChanged)return e;const{deleted:o,pos:l}=t.mapping.mapResult(e);return o?null:l}},props:{decorations:T,handleDOMEvents:{mousedown:ne},createSelectionBetween(t){return $.getState(t.state)!=null?t.state.selection:null},handleTripleClick:te,handleKeyDown:Yt,handlePaste:ee},appendTransaction(e,n,o){return K(o,J(o,n),t)}})}export{W as CellBookmark,F as CellSelection,de as ResizeState,u as TableMap,se as TableView,Pt as __clipCells,Ut as __insertCells,Xt as __pastedCells,O as addColSpan,ht as addColumn,mt as addColumnAfter,ut as addColumnBefore,vt as addRow,yt as addRowAfter,Ct as addRowBefore,M as cellAround,x as cellNear,H as colCount,B as columnIsHeader,ae as columnResizing,ie as columnResizingPluginKey,Ft as deleteCellSelection,gt as deleteColumn,At as deleteRow,Bt as deleteTable,D as findCell,et as findCellPos,tt as findCellRange,Z as findTable,J as fixTables,P as fixTablesKey,Ot as goToNextCell,ee as handlePaste,_ as inSameTable,z as isInTable,Rt as mergeCells,E as moveCellForward,Tt as moveTableColumn,Wt as moveTableRow,I as nextCell,N as pointsAtCell,L as removeColSpan,wt as removeColumn,St as removeRow,bt as rowIsHeader,ft as selectedRect,k as selectionCell,xt as setCellAttr,zt as splitCell,kt as splitCellWithType,Ae as tableEditing,$ as tableEditingKey,A as tableNodeTypes,S as tableNodes,_t as toggleHeader,It as toggleHeaderCell,Ht as toggleHeaderColumn,Dt as toggleHeaderRow,ce as updateColumnsOnResize}; 4
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.