@wordpress/block-library
Version:
Block library for the WordPress editor.
71 lines (70 loc) • 2.46 kB
JavaScript
import clsx from "clsx";
import { RichText, __experimentalGetBorderClassesAndStyles, __experimentalGetColorClassesAndStyles, __experimentalGetElementClassName, getBackgroundClassesAndStyles, useBlockProps } from "@wordpress/block-editor";
import { jsx, jsxs } from "react/jsx-runtime";
// packages/block-library/src/table/save.jsx
function save({ attributes }) {
const { hasFixedLayout, head, body, foot, caption, style } = attributes;
if (!head.length && !body.length && !foot.length) return null;
const colorProps = __experimentalGetColorClassesAndStyles({
...attributes,
style: {
...style,
elements: void 0
}
});
const borderProps = __experimentalGetBorderClassesAndStyles(attributes);
const backgroundProps = getBackgroundClassesAndStyles(attributes);
const textAlign = style?.typography?.textAlign;
const classes = clsx(colorProps.className, borderProps.className, backgroundProps.className, {
"has-fixed-layout": hasFixedLayout,
[`has-text-align-${textAlign}`]: textAlign
});
const hasCaption = !RichText.isEmpty(caption);
const Section = ({ type, rows }) => {
if (!rows.length) return null;
const Tag = `t${type}`;
return /* @__PURE__ */ jsx(Tag, { children: rows.map(({ cells }, rowIndex) => /* @__PURE__ */ jsx("tr", { children: cells.map(({ content, tag, scope, align, colspan, rowspan }, cellIndex) => {
const cellClasses = clsx({ [`has-text-align-${align}`]: align });
return /* @__PURE__ */ jsx(RichText.Content, {
className: cellClasses ? cellClasses : void 0,
"data-align": align,
tagName: tag,
value: content,
scope: tag === "th" ? scope : void 0,
colSpan: colspan,
rowSpan: rowspan
}, cellIndex);
}) }, rowIndex)) });
};
return /* @__PURE__ */ jsxs("figure", {
...useBlockProps.save(),
children: [/* @__PURE__ */ jsxs("table", {
className: classes === "" ? void 0 : classes,
style: {
...colorProps.style,
...borderProps.style,
...backgroundProps.style
},
children: [
/* @__PURE__ */ jsx(Section, {
type: "head",
rows: head
}),
/* @__PURE__ */ jsx(Section, {
type: "body",
rows: body
}),
/* @__PURE__ */ jsx(Section, {
type: "foot",
rows: foot
})
]
}), hasCaption && /* @__PURE__ */ jsx(RichText.Content, {
tagName: "figcaption",
value: caption,
className: __experimentalGetElementClassName("caption")
})]
});
}
export { save as default };
//# sourceMappingURL=save.mjs.map