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) 2.46 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 y=require("@progress/kendo-editor-common"),i=require("../utils.js"),d=/[\D]+$/,f=e=>{const t=e.match(d);return t?t[0]:""},b=(e,t)=>{var n;const s=u(((n=e.attrs)==null?void 0:n.style)||"")[t]||"";return{[t]:parseFloat(s)||null,[t+"Unit"]:f(s)}},u=e=>(e||"").split(/\s*;\s*/).filter(Boolean).map(s=>{const n=s.split(/\s*:\s*/);return{[n[0]]:n[1]}}).reduce((s,n)=>({...s,...n}),{}),m=(e,t)=>{const s=t.style,n=t.value,l=t.newValue;if(!e)return{changed:!1,style:null};const o=e.split(/\s*;\s*/).filter(c=>!!c),r=o.filter(c=>{const a=c.split(/\s*:\s*/);return!(a[0].toLowerCase()===s&&n.test(a[1]))});return l&&r.push(`${s}: ${l}`),{style:r.join("; ")+(r.length?";":""),changed:!!l||r.length!==o.length}},g=/^.+$/;function $(e,t,s){let n;if(new RegExp("[^-]?"+t+":").test(e.style||"")){const{style:l}=m(e.style||"",{style:t,value:g,newValue:s});n={...e,style:l}}else if(e.style){const l=u(e.style);l[t]=s,n={...e,style:Object.keys(l).filter(o=>!!l[o]).reduce((o,r)=>o+r+": "+l[r]+"; ","").trim()}}else s?n={...e,style:t+": "+s+";"}:n={...e};return n}const N=e=>{const{doc:t,selection:s}=e,n=[];return s.ranges.forEach(l=>{const o=l.$from.pos,r=l.$to.pos;t.nodesBetween(o,r,(c,a,p,S)=>{(c.type.name==="table_cell"||c.type.name==="table_header")&&n.push({node:c,pos:a})})}),n},h=e=>{const t=i.parentNode(e.selection.$from,n=>n.type.name==="table"),s=i.parentNode(e.selection.$to,n=>n.type.name==="table");return t&&s&&t.depth===s.depth&&t.node.eq(s.node)?N(e).filter(({pos:l})=>{const o=i.parentNode(e.doc.resolve(l),r=>r.type.name==="table");return o&&o.depth===t.depth&&t.node.eq(o.node)}):[]},C=e=>{const t=[];if(h(e).length){const s=e.selection.$from,n=i.parentNode(s,a=>a.type.spec.tableRole==="table");if(n===null)return t;const l=s.start(n.depth),o=n.node,r=y.TableMap.get(o),c=e.doc;r.map.forEach(a=>{const p=a+l;t.push({pos:p,node:c.nodeAt(p)})})}return t};exports.getUnit=f;exports.nodeSize=b;exports.parseStyle=u;exports.reUnit=d;exports.selectedCells=h;exports.setNodeStyle=$;exports.tableCells=C;