Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/pluggableWidgets/rich-text-web/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

- We fixed an issue where, with multiple Rich Text widgets on a page, toggling fullscreen or pressing Escape in one editor changed the fullscreen mode of a different editor, and the fullscreen button showed the wrong state.

- We fixed an issue where table and cell border settings had no effect when the style data format was set to "Class".

- We fixed an issue where table, column and cell sizes were saved as inline styles when the style data format was set to "Class".

## [5.1.0] - 2026-09-29

### Added
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @jest-environment node
*/
import { join } from "path";
import { compile } from "sass";

// Class style mode renders table/cell borders purely from CSS, so guard the compiled output:
// Sass treats `or` as a boolean operator and silently drops attr() fallbacks.
describe("RichTextFormatStyle.scss table borders", () => {
const css = compile(join(__dirname, "../ui/RichTextFormatStyle.scss")).css;

it("scopes the border rule to the table, cell and generic border classes", () => {
expect(css).toContain(
".widget-rich-text .has-table-border,\n.widget-rich-text .has-cell-border,\n.widget-rich-text .has-border {"
);
});

it("reads each border property with a typed attr() and its own comma fallback", () => {
expect(css).toContain("border-width: attr(data-border-width type(<length>), 1px);");
expect(css).toContain("border-style: attr(data-border-style type(<custom-ident>), solid);");
expect(css).toContain(
"border-color: attr(data-border-color type(<color>), var(--color-neutral-300, #d9d9d9));"
);
});

it("does not emit the broken unit-typed or fallback-less border declarations", () => {
expect(css).not.toContain("attr(data-border-width px)");
expect(css).not.toContain("border-style: attr(data-border-style type(*));");
expect(css).not.toContain("border-color: attr(data-border-color type(<color>));");
expect(css).not.toMatch(/border-(width|style|color): [^;]*\bor\b/);
});
});

// Class style mode saves table, column and cell sizes as data attributes only (no `style`
// attribute), so the sizes must come from these rules. The attribute selectors keep them
// off inline-mode tables.
describe("RichTextFormatStyle.scss table sizes", () => {
const css = compile(join(__dirname, "../ui/RichTextFormatStyle.scss")).css;

it.each([
[".widget-rich-text table[data-width] {", "width: attr(data-width type(<length-percentage>));"],
[".widget-rich-text table[data-min-height] {", "min-height: attr(data-min-height type(<length-percentage>));"],
[".widget-rich-text col[data-col-width] {", "width: attr(data-col-width type(<length-percentage>));"],
[
".widget-rich-text td[data-cell-width],\n.widget-rich-text th[data-cell-width] {",
"width: attr(data-cell-width type(<length-percentage>));"
],
[
".widget-rich-text td[data-cell-height],\n.widget-rich-text th[data-cell-height] {",
"height: attr(data-cell-height type(<length-percentage>));"
]
])("renders %s from a typed attr()", (selector, declaration) => {
expect(css).toContain(`${selector}\n ${declaration}\n}`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ declare module "@tiptap/core" {
}
}

// Helper to create colgroup (copied from TipTap source)
// Helper to create colgroup (copied from TipTap source).
// Inline format puts each column width in the <col> `style`; class format stores it in
// `data-col-width` instead and RichTextFormatStyle.scss renders it.
function createColGroup(
node: any,
cellMinWidth: number
cellMinWidth: number,
styleDataFormat: "inline" | "class" = "inline"
): { colgroup: any[]; tableWidth: string; tableMinWidth: string } {
let totalWidth = 0;
let fixedWidth = true;
Expand Down Expand Up @@ -50,7 +53,11 @@ function createColGroup(
}

const safeCssWidth = safeSize(cssWidth);
cols.push(["col", safeCssWidth ? { style: `width: ${safeCssWidth}` } : {}]);
if (styleDataFormat === "class") {
cols.push(["col", safeCssWidth ? { "data-col-width": safeCssWidth } : {}]);
} else {
cols.push(["col", safeCssWidth ? { style: `width: ${safeCssWidth}` } : {}]);
}
}
}

Expand Down Expand Up @@ -241,7 +248,11 @@ export const TableBackgroundColor = Table.extend<TableBackgroundColorOptions>({
},

renderHTML({ node, HTMLAttributes }): DOMOutputSpec {
const { colgroup, tableWidth, tableMinWidth } = createColGroup(node, this.options.cellMinWidth || 25);
const { colgroup, tableWidth, tableMinWidth } = createColGroup(
node,
this.options.cellMinWidth || 25,
this.options.styleDataFormat
);

// Get style attributes from node (all validated before entering the style string)
const explicitWidth = safeSize(node.attrs.width);
Expand All @@ -251,22 +262,22 @@ export const TableBackgroundColor = Table.extend<TableBackgroundColorOptions>({
// Build the style string by merging table width, background, and border properties
const segments: string[] = [];

// Explicit table width wins as the footprint; otherwise fall back to the
// colwidth-derived width/min-width. Per-column min-width still comes from colgroup.
if (explicitWidth) {
segments.push(`width: ${explicitWidth}`);
} else if (tableWidth) {
segments.push(`width: ${tableWidth}`);
} else if (tableMinWidth) {
segments.push(`min-width: ${tableMinWidth}`);
}
if (this.options.styleDataFormat === "inline") {
// Explicit table width wins as the footprint; otherwise fall back to the
// colwidth-derived width/min-width. Per-column min-width still comes from colgroup.
if (explicitWidth) {
segments.push(`width: ${explicitWidth}`);
} else if (tableWidth) {
segments.push(`width: ${tableWidth}`);
} else if (tableMinWidth) {
segments.push(`min-width: ${tableMinWidth}`);
}

// Explicit table minimum height (rows still grow with content)
if (minHeight) {
segments.push(`min-height: ${minHeight}`);
}
// Explicit table minimum height (rows still grow with content)
if (minHeight) {
segments.push(`min-height: ${minHeight}`);
}

if (this.options.styleDataFormat === "inline") {
// Add background color if present
if (backgroundColor) {
segments.push(`background-color: ${backgroundColor}`);
Expand All @@ -279,7 +290,9 @@ export const TableBackgroundColor = Table.extend<TableBackgroundColorOptions>({

const styleString = segments.join("; ");

// Build class-based attributes for border properties
// Build class-based attributes. Class mode never emits a `style` attribute: explicit
// sizes are stored as data attributes (rendered by RichTextFormatStyle.scss) and the
// colwidth-derived width/min-width is not stored because it is recomputed.
const classAttrs: Record<string, any> = {};
if (this.options.styleDataFormat === "class") {
const borderColor = safeColor(node.attrs.borderColor);
Expand Down Expand Up @@ -580,7 +593,7 @@ class TableBackgroundColorNodeView implements NodeView {
}

// Create new colgroup
const { colgroup } = createColGroup(this.node, this.cellMinWidth);
const { colgroup } = createColGroup(this.node, this.cellMinWidth, this.styleDataFormat);
const colgroupElement = this.createElementFromSpec(colgroup as unknown as DOMOutputSpec);
this.table.insertBefore(colgroupElement, this.contentDOM);
}
Expand Down Expand Up @@ -653,18 +666,21 @@ class TableBackgroundColorNodeView implements NodeView {
this.table.classList.remove("has-background-color");
}

// Border properties
if (borderColor || borderStyle || borderWidth) {
if (borderColor) this.table.setAttribute("data-border-color", borderColor);
if (borderStyle) this.table.setAttribute("data-border-style", borderStyle);
if (borderWidth) this.table.setAttribute("data-border-width", borderWidth);
this.table.classList.add("has-table-border");
} else {
this.table.removeAttribute("data-border-color");
this.table.removeAttribute("data-border-style");
this.table.removeAttribute("data-border-width");
this.table.classList.remove("has-table-border");
// Border properties. Sync each attribute on its own so clearing one property
// (e.g. the color) does not leave a stale value behind for the CSS to pick up.
const borderAttrs: Array<[string, string | null]> = [
["data-border-color", borderColor],
["data-border-style", borderStyle],
["data-border-width", borderWidth]
];
for (const [name, value] of borderAttrs) {
if (value) {
this.table.setAttribute(name, value);
} else {
this.table.removeAttribute(name);
}
}
this.table.classList.toggle("has-table-border", Boolean(borderColor || borderStyle || borderWidth));
}
}

Expand Down
Loading
Loading