UNPKG

@progress/kendo-react-editor

Version:

React Editor enables users to create rich text content through a WYSIWYG interface. KendoReact Editor package

9 lines (8 loc) 4.06 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("@progress/kendo-editor-common"),s=require("./utils.js"),N=require("../utils.js"),b="k-colgroup-data",x=(o,e,n)=>{const l={cellWidth:null,widthUnit:""},r=e.node,t=n.start(e.depth);if(!r.attrs[b])return l;const h=new Set;let i="";const y=w.htmlToFragment(r.attrs[b]).firstChild;return o.forEach(a=>{const u=r.resolve(a.pos-t),c=u.parent,C=u.index();let g=0;for(let f=0;f<=C;f++)g+=c.child(f).attrs.colspan;const d=y.children[g-1];d&&(i=d.style.width,h.add(i))}),h.size===1&&i&&(l.cellWidth=parseFloat(i)||null,l.widthUnit=s.getUnit(i)),l},v=(o,e,n)=>{const l={cellHeight:null,heightUnit:""},r=e.node,t=n.start(e.depth),h=new Set;let i="";return o.forEach(y=>{var c;const u=r.resolve(y.pos-t).parent;i=s.parseStyle(((c=u.attrs)==null?void 0:c.style)||"").height||"",h.add(i)}),h.size===1&&i&&(l.cellHeight=parseFloat(i)||null,l.heightUnit=s.getUnit(i)),l},p=(o,e)=>{const n=new Set;let l="";return o.forEach(r=>{var t;l=s.parseStyle(((t=r.node.attrs)==null?void 0:t.style)||"")[e]||"",n.add(l)}),n.size===1&&l?l:""},S=(o,e)=>{const n=new Set;let l="";return o.forEach(r=>{l=(r.node.attrs||{})[e]||"",n.add(l)}),n.size===1&&l?l:""},m={applyToAll:!1,cellWidth:null,widthUnit:"",cellHeight:null,heightUnit:"",alignment:{x:"",y:""},textControl:"",backgroundColor:void 0,cellPadding:null,borderWidth:null,borderColor:void 0,borderStyle:null,id:"",className:""},k=o=>{const e=s.selectedCells(o),n=o.selection.$from,l=e.length?N.parentNode(n,r=>r.type.spec.tableRole==="table"):null;return l?{...m,...x(e,l,n),...v(e,l,n),alignment:{x:p(e,"text-align"),y:p(e,"vertical-align")},textControl:p(e,"white-space"),backgroundColor:p(e,"background-color")||void 0,cellPadding:parseFloat(p(e,"padding"))||null,borderWidth:parseFloat(p(e,"border-width"))||null,borderColor:p(e,"border-color")||void 0,borderStyle:p(e,"border-style")||null,id:S(e,"id"),className:S(e,"class")}:m},W=(o,e,n)=>{const l=o.doc.resolve(e),r=l.parent,t=l.index();let h=0;for(let c=0;c<=t;c++)h+=r.child(c).attrs.colspan;const i=l.node(l.depth-1),y=l.posAtIndex(0,l.depth-1)-1;let a=i.attrs,u;if(a&&a[b]){const c=w.htmlToFragment(a[b]).firstChild;u=c.children[h-1],u.style.width=n,a={...a,[b]:c.outerHTML},o.setNodeMarkup(y,null,a)}else{let c=0;for(let d=0;d<r.childCount;d++)c+=r.child(d).attrs.colspan;const C=document.createElement("colgroup"),g=new Array(c);for(let d=0;d<c;d++)g[d]=document.createElement("col"),C.appendChild(g[d]);u=g[t],u.style.width=n,a={...a,[b]:"<colgroup>"+g.reduce((d,f)=>d+f.outerHTML,"")+"</colgroup>"},o.setNodeMarkup(y,null,a)}},P=(o,e,n)=>{const l=o.doc.resolve(e),r=l.parent,t=l.posAtIndex(0)-1;o.setNodeMarkup(t,null,s.setNodeStyle(r.attrs,"height",n))},U=(o,e,n)=>{n.forEach(({node:l,pos:r})=>{let t={...l.attrs};t=s.setNodeStyle(t,"border-color",e.borderColor||""),t=s.setNodeStyle(t,"border-style",e.borderStyle||""),t=s.setNodeStyle(t,"border-width",typeof e.borderWidth=="number"?e.borderWidth+"px":""),t=s.setNodeStyle(t,"padding",typeof e.cellPadding=="number"?e.cellPadding+"px":""),t=s.setNodeStyle(t,"background-color",e.backgroundColor||""),t=s.setNodeStyle(t,"text-align",e.alignment.x||""),t=s.setNodeStyle(t,"vertical-align",e.alignment.y||""),t=s.setNodeStyle(t,"white-space",e.textControl||""),t.id=e.id||null,t.class=e.className||null,o.setNodeMarkup(r,null,t),typeof e.cellWidth=="number"&&W(o,r,e.cellWidth+(e.widthUnit||"px")),typeof e.cellHeight=="number"&&P(o,r,e.cellHeight+(e.heightUnit||"px"))})},H=(o,e)=>{const n=o.tr,l=e.applyToAll?s.tableCells(o):s.selectedCells(o);return U(n,e,l),n};exports.applyCellsData=H;exports.cellsDefaultData=k;exports.initialCellData=m;