Files
edentext/tests/unit/column-weight-refill.test.ts
Steffen Becker 611ec76ba4 fix: the editor holds no shape either file would drop
A page break reaches the file only from a body block or a list item — a cell,
a frame and a note body all drop it — and an indent on a list item's paragraph
is the same; a plugin sweeps both. A note anchor keeps no marks and stays out
of a text box. Sub- and superscript exclude each other, a font stack the
contenteditable leaves behind keeps its first family, and a weight Bold already
claims is no second attribute. A table's first row is all header cells or none
(the promotion carrying each cell's own attrs), a replace into a table reads the
lost column weight back from the column, and a list item holds no table.
2026-09-06 19:07:20 +02:00

39 lines
2.1 KiB
TypeScript

// A cell rebuilt by a replace loses its column weight; the plugin reads it back from
// the column's other rows, so undo/redo and the saved widths stay put.
import { describe, it, expect } from 'vitest';
import { getSchema } from '@tiptap/core';
import { EditorState } from '@tiptap/pm/state';
import Document from '@tiptap/extension-document';
import Paragraph from '@tiptap/extension-paragraph';
import Text from '@tiptap/extension-text';
import { Table, TableCell, TableHeader } from '@tiptap/extension-table';
import { ResizableTableRow } from '../../src/lib/editor/extensions/tableRow';
import { TableColumnResize } from '../../src/lib/editor/extensions/tableColumnResize';
type N = any;
const schema = getSchema([Document, Paragraph, Text, Table, ResizableTableRow, TableCell, TableHeader, TableColumnResize]);
const cell = (w: number[] | null, t: string): N => ({ type: 'tableCell', attrs: { colspan: 1, rowspan: 1, colwidth: w },
content: [{ type: 'paragraph', content: [{ type: 'text', text: t }] }] });
const row = (...cells: N[]): N => ({ type: 'tableRow', content: cells });
const widths = (doc: N): unknown[] => {
const out: unknown[] = [];
doc.descendants((n: N) => { if (n.type.name === 'tableCell') { out.push(n.attrs.colwidth); return false; } });
return out;
};
describe('column weight refill', () => {
it('fills a lost weight from the column and leaves a new column alone', () => {
const doc = schema.nodeFromJSON({ type: 'doc', content: [
{ type: 'paragraph', content: [{ type: 'text', text: 'x' }] },
{ type: 'table', content: [
row(cell(null, 'a'), cell([20000], 'b'), cell(null, 'c')),
row(cell([30000], 'd'), cell([20000], 'e'), cell(null, 'f'))] }] });
const plugins = (TableColumnResize as N).config.addProseMirrorPlugins.call({ options: {} });
let state = EditorState.create({ schema, doc, plugins });
state = state.apply(state.tr.insertText('!', 1));
// The first column's weight comes back from row two; the third has none anywhere.
expect(widths(state.doc)).toEqual([[30000], [20000], null, [30000], [20000], null]);
});
});