/*!
Copyright (c) 2026 Lenovo SSG BASD. All rights reserved.
@license Proprietary

This software is the confidential and proprietary property of Lenovo SSG BASD.
You shall not disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement.

--- Build Info ---
Version: 1.1.1
Build Time: 2026/2/26 17:21:00
Build Commit: 81e556ed827e2f043668506dae6fae8dbb9ef395
*/
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../core/dist/index.js"),t=require("../../../prosemirror-state/dist/index.js"),o=require("../../../prosemirror-tables/dist/index.js");var l=e.Node.create({name:"tableCell",addOptions:()=>({HTMLAttributes:{}}),content:"block+",addAttributes:()=>({colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:e=>{var t,o;const l=e.getAttribute("colwidth"),s=l?l.split(",").map(e=>parseInt(e,10)):null;if(!s){const l=null==(t=e.closest("table"))?void 0:t.querySelectorAll("colgroup > col"),s=Array.from((null==(o=e.parentElement)?void 0:o.children)||[]).indexOf(e);if(s&&s>-1&&l&&l[s]){const e=l[s].getAttribute("width");return e?[parseInt(e,10)]:null}}return s}}}),tableRole:"cell",isolating:!0,parseHTML:()=>[{tag:"td"}],renderHTML({HTMLAttributes:t}){return["td",e.mergeAttributes(this.options.HTMLAttributes,t),0]}}),s=e.Node.create({name:"tableHeader",addOptions:()=>({HTMLAttributes:{}}),content:"block+",addAttributes:()=>({colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:e=>{const t=e.getAttribute("colwidth");return t?t.split(",").map(e=>parseInt(e,10)):null}}}),tableRole:"header_cell",isolating:!0,parseHTML:()=>[{tag:"th"}],renderHTML({HTMLAttributes:t}){return["th",e.mergeAttributes(this.options.HTMLAttributes,t),0]}}),r=e.Node.create({name:"tableRow",addOptions:()=>({HTMLAttributes:{}}),content:"(tableCell | tableHeader)*",tableRole:"row",parseHTML:()=>[{tag:"tr"}],renderHTML({HTMLAttributes:t}){return["tr",e.mergeAttributes(this.options.HTMLAttributes,t),0]}});function n(e,t){return t?["width",`${Math.max(t,e)}px`]:["min-width",`${e}px`]}function a(e,t,o,l,s,r){var a;let i=0,d=!0,c=t.firstChild;const p=e.firstChild;if(null!==p)for(let u=0,b=0;u<p.childCount;u+=1){const{colspan:e,colwidth:o}=p.child(u).attrs;for(let a=0;a<e;a+=1,b+=1){const e=s===b?r:o&&o[a],p=e?`${e}px`:"";if(i+=e||l,e||(d=!1),c){if(c.style.width!==p){const[t,o]=n(l,e);c.style.setProperty(t,o)}c=c.nextSibling}else{const o=document.createElement("col"),[s,r]=n(l,e);o.style.setProperty(s,r),t.appendChild(o)}}}for(;c;){const e=c.nextSibling;null==(a=c.parentNode)||a.removeChild(c),c=e}const h=e.attrs.style&&"string"==typeof e.attrs.style&&/\bwidth\s*:/i.test(e.attrs.style);d&&!h?(o.style.width=`${i}px`,o.style.minWidth=""):(o.style.width="",o.style.minWidth=`${i}px`)}var i=class{constructor(e,t){this.node=e,this.cellMinWidth=t,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),e.attrs.style&&(this.table.style.cssText=e.attrs.style),this.colgroup=this.table.appendChild(document.createElement("colgroup")),a(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(e){return e.type===this.node.type&&(this.node=e,a(e,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(e){const t=e.target,o=this.dom.contains(t),l=this.contentDOM.contains(t);return!(!o||l||"attributes"!==e.type&&"childList"!==e.type&&"characterData"!==e.type)}};function d(e,t,o,l){let s=0,r=!0;const a=[],i=e.firstChild;if(!i)return{};for(let p=0,h=0;p<i.childCount;p+=1){const{colspan:e,colwidth:d}=i.child(p).attrs;for(let i=0;i<e;i+=1,h+=1){const e=o===h?l:d&&d[i];s+=e||t,e||(r=!1);const[c,p]=n(t,e);a.push(["col",{style:`${c}: ${p}`}])}}const d=r?`${s}px`:"",c=r?"":`${s}px`;return{colgroup:["colgroup",{},...a],tableWidth:d,tableMinWidth:c}}function c(e,t){return e.createAndFill()}function p(e,t,o,l,s){const r=function(e){if(e.cached.tableNodeTypes)return e.cached.tableNodeTypes;const t={};return Object.keys(e.nodes).forEach(o=>{const l=e.nodes[o];l.spec.tableRole&&(t[l.spec.tableRole]=l)}),e.cached.tableNodeTypes=t,t}(e),n=[],a=[];for(let d=0;d<o;d+=1){const e=c(r.cell);if(e&&a.push(e),l){const e=c(r.header_cell);e&&n.push(e)}}const i=[];for(let d=0;d<t;d+=1)i.push(r.row.createChecked(null,l&&0===d?n:a));return r.table.createChecked(null,i)}var h=({editor:t})=>{const{selection:l}=t.state;if(!(l instanceof o.CellSelection))return!1;let s=0;const r=e.findParentNodeClosestToPos(l.ranges[0].$from,e=>"table"===e.type.name);null==r||r.node.descendants(e=>{if("table"===e.type.name)return!1;["tableCell","tableHeader"].includes(e.type.name)&&(s+=1)});return s===l.ranges.length&&(t.commands.deleteTable(),!0)};function u(e,t,o={}){var l;const s=null!=(l=o.cellLineSeparator)?l:"";if(!e||!e.content||0===e.content.length)return"";const r=[];e.content.forEach(e=>{const o=[];e.content&&e.content.forEach(e=>{let l="";if(e.content&&Array.isArray(e.content)&&e.content.length>1){l=e.content.map(e=>t.renderChildren(e)).join(s)}else l=e.content?t.renderChildren(e.content):"";const r=(l||"").replace(/\s+/g," ").trim();const n="tableHeader"===e.type;o.push({text:r,isHeader:n})}),r.push(o)});const n=r.reduce((e,t)=>Math.max(e,t.length),0);if(0===n)return"";const a=new Array(n).fill(0);r.forEach(e=>{var t;for(let o=0;o<n;o+=1){const l=((null==(t=e[o])?void 0:t.text)||"").length;l>a[o]&&(a[o]=l),a[o]<3&&(a[o]=3)}});const i=(e,t)=>e+" ".repeat(Math.max(0,t-e.length)),d=r[0],c=d.some(e=>e.isHeader);let p="\n";const h=new Array(n).fill(0).map((e,t)=>c&&d[t]&&d[t].text||"");p+=`| ${h.map((e,t)=>i(e,a[t])).join(" | ")} |\n`,p+=`| ${a.map(e=>"-".repeat(Math.max(3,e))).join(" | ")} |\n`;return(c?r.slice(1):r).forEach(e=>{p+=`| ${new Array(n).fill(0).map((t,o)=>i(e[o]&&e[o].text||"",a[o])).join(" | ")} |\n`}),p}var b=u,m=e.Node.create({name:"table",addOptions:()=>({HTMLAttributes:{},resizable:!1,renderWrapper:!1,handleWidth:5,cellMinWidth:25,View:i,lastColumnResizable:!0,allowTableNodeSelection:!1}),content:"tableRow+",tableRole:"table",isolating:!0,group:"block",parseHTML:()=>[{tag:"table"}],renderHTML({node:t,HTMLAttributes:o}){const{colgroup:l,tableWidth:s,tableMinWidth:r}=d(t,this.options.cellMinWidth),n=o.style;const a=["table",e.mergeAttributes(this.options.HTMLAttributes,o,{style:n||(s?`width: ${s}`:`min-width: ${r}`)}),l,["tbody",0]];return this.options.renderWrapper?["div",{class:"tableWrapper"},a]:a},parseMarkdown:(e,t)=>{const o=[];if(e.header){const l=[];e.header.forEach(e=>{l.push(t.createNode("tableHeader",{},[{type:"paragraph",content:t.parseInline(e.tokens)}]))}),o.push(t.createNode("tableRow",{},l))}return e.rows&&e.rows.forEach(e=>{const l=[];e.forEach(e=>{l.push(t.createNode("tableCell",{},[{type:"paragraph",content:t.parseInline(e.tokens)}]))}),o.push(t.createNode("tableRow",{},l))}),t.createNode("table",void 0,o)},renderMarkdown:(e,t)=>b(e,t),addCommands:()=>({insertTable:({rows:e=3,cols:o=3,withHeaderRow:l=!0}={})=>({tr:s,dispatch:r,editor:n})=>{const a=p(n.schema,e,o,l);if(r){const e=s.selection.from+1;s.replaceSelectionWith(a).scrollIntoView().setSelection(t.TextSelection.near(s.doc.resolve(e)))}return!0},addColumnBefore:()=>({state:e,dispatch:t})=>o.addColumnBefore(e,t),addColumnAfter:()=>({state:e,dispatch:t})=>o.addColumnAfter(e,t),deleteColumn:()=>({state:e,dispatch:t})=>o.deleteColumn(e,t),addRowBefore:()=>({state:e,dispatch:t})=>o.addRowBefore(e,t),addRowAfter:()=>({state:e,dispatch:t})=>o.addRowAfter(e,t),deleteRow:()=>({state:e,dispatch:t})=>o.deleteRow(e,t),deleteTable:()=>({state:e,dispatch:t})=>o.deleteTable(e,t),mergeCells:()=>({state:e,dispatch:t})=>o.mergeCells(e,t),splitCell:()=>({state:e,dispatch:t})=>o.splitCell(e,t),toggleHeaderColumn:()=>({state:e,dispatch:t})=>o.toggleHeader("column")(e,t),toggleHeaderRow:()=>({state:e,dispatch:t})=>o.toggleHeader("row")(e,t),toggleHeaderCell:()=>({state:e,dispatch:t})=>o.toggleHeaderCell(e,t),mergeOrSplit:()=>({state:e,dispatch:t})=>!!o.mergeCells(e,t)||o.splitCell(e,t),setCellAttribute:(e,t)=>({state:l,dispatch:s})=>o.setCellAttr(e,t)(l,s),goToNextCell:()=>({state:e,dispatch:t})=>o.goToNextCell(1)(e,t),goToPreviousCell:()=>({state:e,dispatch:t})=>o.goToNextCell(-1)(e,t),fixTables:()=>({state:e,dispatch:t})=>(t&&o.fixTables(e),!0),setCellSelection:e=>({tr:t,dispatch:l})=>{if(l){const l=o.CellSelection.create(t.doc,e.anchorCell,e.headCell);t.setSelection(l)}return!0}}),addKeyboardShortcuts(){return{Tab:()=>!!this.editor.commands.goToNextCell()||!!this.editor.can().addRowAfter()&&this.editor.chain().addRowAfter().goToNextCell().run(),"Shift-Tab":()=>this.editor.commands.goToPreviousCell(),Backspace:h,"Mod-Backspace":h,Delete:h,"Mod-Delete":h}},addProseMirrorPlugins(){return[...this.options.resizable&&this.editor.isEditable?[o.columnResizing({handleWidth:this.options.handleWidth,cellMinWidth:this.options.cellMinWidth,defaultCellMinWidth:this.options.cellMinWidth,View:this.options.View,lastColumnResizable:this.options.lastColumnResizable})]:[],o.tableEditing({allowTableNodeSelection:this.options.allowTableNodeSelection})]},extendNodeSchema(t){const o={name:t.name,options:t.options,storage:t.storage};return{tableRole:e.callOrReturn(e.getExtensionField(t,"tableRole",o))}}}),f=e.Extension.create({name:"tableKit",addExtensions(){const e=[];return!1!==this.options.table&&e.push(m.configure(this.options.table)),!1!==this.options.tableCell&&e.push(l.configure(this.options.tableCell)),!1!==this.options.tableHeader&&e.push(s.configure(this.options.tableHeader)),!1!==this.options.tableRow&&e.push(r.configure(this.options.tableRow)),e}});exports.DEFAULT_CELL_LINE_SEPARATOR="",exports.Table=m,exports.TableCell=l,exports.TableHeader=s,exports.TableKit=f,exports.TableRow=r,exports.TableView=i,exports.createColGroup=d,exports.createTable=p,exports.renderTableToMarkdown=u,exports.updateColumns=a;