UNPKG

@wordpress/block-library

Version:
82 lines (81 loc) • 2.24 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); let _wordpress_blocks = require("@wordpress/blocks"); let __utils_js = require("./utils.cjs"); // packages/block-library/src/table/transforms.js const tableContentPasteSchema = ({ phrasingContentSchema }) => ({ tr: { allowEmpty: true, children: { th: { allowEmpty: true, children: phrasingContentSchema, attributes: [ "scope", "colspan", "rowspan", "style" ] }, td: { allowEmpty: true, children: phrasingContentSchema, attributes: [ "colspan", "rowspan", "style" ] } } } }); const tablePasteSchema = (args) => ({ table: { children: { thead: { allowEmpty: true, children: tableContentPasteSchema(args) }, tfoot: { allowEmpty: true, children: tableContentPasteSchema(args) }, tbody: { allowEmpty: true, children: tableContentPasteSchema(args) } } } }); const transforms = { from: [{ type: "raw", selector: "table", schema: tablePasteSchema, transform: (node) => { const attributes = Array.from(node.children).reduce((sectionAcc, section) => { if (!section.children.length) return sectionAcc; const sectionName = section.nodeName.toLowerCase().slice(1); sectionAcc[sectionName] = Array.from(section.children).reduce((rowAcc, row) => { if (!row.children.length) return rowAcc; const rowAttributes = Array.from(row.children).reduce((colAcc, col) => { const rowspan = (0, __utils_js.normalizeRowColSpan)(col.getAttribute("rowspan")); const colspan = (0, __utils_js.normalizeRowColSpan)(col.getAttribute("colspan")); const { textAlign } = col.style || {}; let align; if (textAlign === "left" || textAlign === "center" || textAlign === "right") align = textAlign; colAcc.push({ tag: col.nodeName.toLowerCase(), content: col.innerHTML, rowspan, colspan, align }); return colAcc; }, []); rowAcc.push({ cells: rowAttributes }); return rowAcc; }, []); return sectionAcc; }, {}); return (0, _wordpress_blocks.createBlock)("core/table", attributes); } }] }; exports.default = transforms; //# sourceMappingURL=transforms.cjs.map