"use strict";var b=Object.defineProperty;var p=(s,e,t)=>e in s?b(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var o=(s,e,t)=>(p(s,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("../blots/block.js"),f=require("../blots/container.js"),d=class d extends w.default{static create(e){const t=super.create();return e?t.setAttribute("data-row",e):t.setAttribute("data-row",m()),t}static formats(e){if(e.hasAttribute("data-row"))return e.getAttribute("data-row")}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}format(e,t){e===d.blotName&&t?this.domNode.setAttribute("data-row",t):super.format(e,t)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}};o(d,"blotName","table"),o(d,"tagName","TD");let a=d;class c extends f.default{checkMerge(){if(super.checkMerge()&&this.next.children.head!=null){const e=this.children.head.formats(),t=this.children.tail.formats(),r=this.next.children.head.formats(),n=this.next.children.tail.formats();return e.table===t.table&&e.table===r.table&&e.table===n.table}return!1}optimize(e){super.optimize(e),this.children.forEach(t=>{if(t.next==null)return;const r=t.formats(),n=t.next.formats();if(r.table!==n.table){const l=this.splitAfter(t);l&&l.optimize(),this.prev&&this.prev.optimize()}})}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}o(c,"blotName","table-row"),o(c,"tagName","TR");class i extends f.default{}o(i,"blotName","table-body"),o(i,"tagName","TBODY");class h extends f.default{balanceCells(){const e=this.descendants(c),t=e.reduce((r,n)=>Math.max(n.children.length,r),0);e.forEach(r=>{new Array(t-r.children.length).fill(0).forEach(()=>{let n;r.children.head!=null&&(n=a.formats(r.children.head.domNode));const l=this.scroll.create(a.blotName,n);r.appendChild(l),l.optimize()})})}cells(e){return this.rows().map(t=>t.children.at(e))}deleteColumn(e){const[t]=this.descendant(i);t==null||t.children.head==null||t.children.forEach(r=>{const n=r.children.at(e);n!=null&&n.remove()})}insertColumn(e){const[t]=this.descendant(i);t==null||t.children.head==null||t.children.forEach(r=>{const n=r.children.at(e),l=a.formats(r.children.head.domNode),u=this.scroll.create(a.blotName,l);r.insertBefore(u,n)})}insertRow(e){const[t]=this.descendant(i);if(t==null||t.children.head==null)return;const r=m(),n=this.scroll.create(c.blotName);t.children.head.children.forEach(()=>{const u=this.scroll.create(a.blotName,r);n.appendChild(u)});const l=t.children.at(e);t.insertBefore(n,l)}rows(){const e=this.children.head;return e==null?[]:e.children.map(t=>t)}}o(h,"blotName","table-container"),o(h,"tagName","TABLE");h.allowedChildren=[i];i.requiredContainer=h;i.allowedChildren=[c];c.requiredContainer=i;c.allowedChildren=[a];a.requiredContainer=c;function m(){return`row-${Math.random().toString(36).slice(2,6)}`}exports.TableBody=i;exports.TableCell=a;exports.TableContainer=h;exports.TableRow=c;exports.tableId=m;
