@tiptap/extension-table 3.0.0-next.1 → 3.0.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +37 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -11
- package/dist/index.d.ts +9 -11
- package/dist/index.js +37 -18
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/TableView.ts +38 -27
- package/src/table.ts +1 -0
- package/src/utilities/colStyle.ts +10 -0
- package/src/utilities/createColGroup.ts +27 -5
package/dist/index.cjs
CHANGED
|
@@ -32,34 +32,49 @@ var import_core2 = require("@tiptap/core");
|
|
|
32
32
|
var import_state = require("@tiptap/pm/state");
|
|
33
33
|
var import_tables2 = require("@tiptap/pm/tables");
|
|
34
34
|
|
|
35
|
+
// src/utilities/colStyle.ts
|
|
36
|
+
function getColStyleDeclaration(minWidth, width) {
|
|
37
|
+
if (width) {
|
|
38
|
+
return ["width", `${Math.max(width, minWidth)}px`];
|
|
39
|
+
}
|
|
40
|
+
return ["min-width", `${minWidth}px`];
|
|
41
|
+
}
|
|
42
|
+
|
|
35
43
|
// src/TableView.ts
|
|
36
44
|
function updateColumns(node, colgroup, table, cellMinWidth, overrideCol, overrideValue) {
|
|
45
|
+
var _a;
|
|
37
46
|
let totalWidth = 0;
|
|
38
47
|
let fixedWidth = true;
|
|
39
48
|
let nextDOM = colgroup.firstChild;
|
|
40
49
|
const row = node.firstChild;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
if (row !== null) {
|
|
51
|
+
for (let i = 0, col = 0; i < row.childCount; i += 1) {
|
|
52
|
+
const { colspan, colwidth } = row.child(i).attrs;
|
|
53
|
+
for (let j = 0; j < colspan; j += 1, col += 1) {
|
|
54
|
+
const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j];
|
|
55
|
+
const cssWidth = hasWidth ? `${hasWidth}px` : "";
|
|
56
|
+
totalWidth += hasWidth || cellMinWidth;
|
|
57
|
+
if (!hasWidth) {
|
|
58
|
+
fixedWidth = false;
|
|
59
|
+
}
|
|
60
|
+
if (!nextDOM) {
|
|
61
|
+
const colElement = document.createElement("col");
|
|
62
|
+
const [propertyKey, propertyValue] = getColStyleDeclaration(cellMinWidth, hasWidth);
|
|
63
|
+
colElement.style.setProperty(propertyKey, propertyValue);
|
|
64
|
+
colgroup.appendChild(colElement);
|
|
65
|
+
} else {
|
|
66
|
+
if (nextDOM.style.width !== cssWidth) {
|
|
67
|
+
const [propertyKey, propertyValue] = getColStyleDeclaration(cellMinWidth, hasWidth);
|
|
68
|
+
nextDOM.style.setProperty(propertyKey, propertyValue);
|
|
69
|
+
}
|
|
70
|
+
nextDOM = nextDOM.nextSibling;
|
|
55
71
|
}
|
|
56
|
-
nextDOM = nextDOM.nextSibling;
|
|
57
72
|
}
|
|
58
73
|
}
|
|
59
74
|
}
|
|
60
75
|
while (nextDOM) {
|
|
61
76
|
const after = nextDOM.nextSibling;
|
|
62
|
-
nextDOM.parentNode.removeChild(nextDOM);
|
|
77
|
+
(_a = nextDOM.parentNode) == null ? void 0 : _a.removeChild(nextDOM);
|
|
63
78
|
nextDOM = after;
|
|
64
79
|
}
|
|
65
80
|
if (fixedWidth) {
|
|
@@ -107,12 +122,15 @@ function createColGroup(node, cellMinWidth, overrideCol, overrideValue) {
|
|
|
107
122
|
const { colspan, colwidth } = row.child(i).attrs;
|
|
108
123
|
for (let j = 0; j < colspan; j += 1, col += 1) {
|
|
109
124
|
const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j];
|
|
110
|
-
const cssWidth = hasWidth ? `${hasWidth}px` : "";
|
|
111
125
|
totalWidth += hasWidth || cellMinWidth;
|
|
112
126
|
if (!hasWidth) {
|
|
113
127
|
fixedWidth = false;
|
|
114
128
|
}
|
|
115
|
-
|
|
129
|
+
const [property, value] = getColStyleDeclaration(cellMinWidth, hasWidth);
|
|
130
|
+
cols.push([
|
|
131
|
+
"col",
|
|
132
|
+
{ style: `${property}: ${value}` }
|
|
133
|
+
]);
|
|
116
134
|
}
|
|
117
135
|
}
|
|
118
136
|
const tableWidth = fixedWidth ? `${totalWidth}px` : "";
|
|
@@ -343,6 +361,7 @@ var Table = import_core2.Node.create({
|
|
|
343
361
|
(0, import_tables2.columnResizing)({
|
|
344
362
|
handleWidth: this.options.handleWidth,
|
|
345
363
|
cellMinWidth: this.options.cellMinWidth,
|
|
364
|
+
defaultCellMinWidth: this.options.cellMinWidth,
|
|
346
365
|
View: this.options.View,
|
|
347
366
|
lastColumnResizable: this.options.lastColumnResizable
|
|
348
367
|
})
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/table.ts","../src/TableView.ts","../src/utilities/createColGroup.ts","../src/utilities/createCell.ts","../src/utilities/getTableNodeTypes.ts","../src/utilities/createTable.ts","../src/utilities/deleteTableWhenAllCellsSelected.ts","../src/utilities/isCellSelection.ts"],"sourcesContent":["import { Table } from './table.js'\n\nexport * from './table.js'\nexport * from './utilities/createColGroup.js'\nexport * from './utilities/createTable.js'\n\nexport default Table\n","import {\n callOrReturn, getExtensionField, mergeAttributes, Node, ParentConfig,\n} from '@tiptap/core'\nimport { DOMOutputSpec, Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { TextSelection } from '@tiptap/pm/state'\nimport {\n addColumnAfter,\n addColumnBefore,\n addRowAfter,\n addRowBefore,\n CellSelection,\n columnResizing,\n deleteColumn,\n deleteRow,\n deleteTable,\n fixTables,\n goToNextCell,\n mergeCells,\n setCellAttr,\n splitCell,\n tableEditing,\n toggleHeader,\n toggleHeaderCell,\n} from '@tiptap/pm/tables'\nimport { EditorView, NodeView } from '@tiptap/pm/view'\n\nimport { TableView } from './TableView.js'\nimport { createColGroup } from './utilities/createColGroup.js'\nimport { createTable } from './utilities/createTable.js'\nimport { deleteTableWhenAllCellsSelected } from './utilities/deleteTableWhenAllCellsSelected.js'\n\nexport interface TableOptions {\n /**\n * HTML attributes for the table element.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n\n /**\n * Enables the resizing of tables.\n * @default false\n * @example true\n */\n resizable: boolean\n\n /**\n * The width of the resize handle.\n * @default 5\n * @example 10\n */\n handleWidth: number\n\n /**\n * The minimum width of a cell.\n * @default 25\n * @example 50\n */\n cellMinWidth: number\n\n /**\n * The node view to render the table.\n * @default TableView\n */\n View: (new (node: ProseMirrorNode, cellMinWidth: number, view: EditorView) => NodeView) | null\n\n /**\n * Enables the resizing of the last column.\n * @default true\n * @example false\n */\n lastColumnResizable: boolean\n\n /**\n * Allow table node selection.\n * @default false\n * @example true\n */\n allowTableNodeSelection: boolean\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n table: {\n /**\n * Insert a table\n * @param options The table attributes\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.insertTable({ rows: 3, cols: 3, withHeaderRow: true })\n */\n insertTable: (options?: {\n rows?: number\n cols?: number\n withHeaderRow?: boolean\n }) => ReturnType\n\n /**\n * Add a column before the current column\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.addColumnBefore()\n */\n addColumnBefore: () => ReturnType\n\n /**\n * Add a column after the current column\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.addColumnAfter()\n */\n addColumnAfter: () => ReturnType\n\n /**\n * Delete the current column\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.deleteColumn()\n */\n deleteColumn: () => ReturnType\n\n /**\n * Add a row before the current row\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.addRowBefore()\n */\n addRowBefore: () => ReturnType\n\n /**\n * Add a row after the current row\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.addRowAfter()\n */\n addRowAfter: () => ReturnType\n\n /**\n * Delete the current row\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.deleteRow()\n */\n deleteRow: () => ReturnType\n\n /**\n * Delete the current table\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.deleteTable()\n */\n deleteTable: () => ReturnType\n\n /**\n * Merge the currently selected cells\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.mergeCells()\n */\n mergeCells: () => ReturnType\n\n /**\n * Split the currently selected cell\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.splitCell()\n */\n splitCell: () => ReturnType\n\n /**\n * Toggle the header column\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.toggleHeaderColumn()\n */\n toggleHeaderColumn: () => ReturnType\n\n /**\n * Toggle the header row\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.toggleHeaderRow()\n */\n toggleHeaderRow: () => ReturnType\n\n /**\n * Toggle the header cell\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.toggleHeaderCell()\n */\n toggleHeaderCell: () => ReturnType\n\n /**\n * Merge or split the currently selected cells\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.mergeOrSplit()\n */\n mergeOrSplit: () => ReturnType\n\n /**\n * Set a cell attribute\n * @param name The attribute name\n * @param value The attribute value\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.setCellAttribute('align', 'right')\n */\n setCellAttribute: (name: string, value: any) => ReturnType\n\n /**\n * Moves the selection to the next cell\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.goToNextCell()\n */\n goToNextCell: () => ReturnType\n\n /**\n * Moves the selection to the previous cell\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.goToPreviousCell()\n */\n goToPreviousCell: () => ReturnType\n\n /**\n * Try to fix the table structure if necessary\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.fixTables()\n */\n fixTables: () => ReturnType\n\n /**\n * Set a cell selection inside the current table\n * @param position The cell position\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.setCellSelection({ anchorCell: 1, headCell: 2 })\n */\n setCellSelection: (position: { anchorCell: number; headCell?: number }) => ReturnType\n }\n }\n\n interface NodeConfig<Options, Storage> {\n /**\n * A string or function to determine the role of the table.\n * @default 'table'\n * @example () => 'table'\n */\n tableRole?:\n | string\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options>>['tableRole']\n }) => string)\n }\n}\n\n/**\n * This extension allows you to create tables.\n * @see https://www.tiptap.dev/api/nodes/table\n */\nexport const Table = Node.create<TableOptions>({\n name: 'table',\n\n // @ts-ignore\n addOptions() {\n return {\n HTMLAttributes: {},\n resizable: false,\n handleWidth: 5,\n cellMinWidth: 25,\n // TODO: fix\n View: TableView,\n lastColumnResizable: true,\n allowTableNodeSelection: false,\n }\n },\n\n content: 'tableRow+',\n\n tableRole: 'table',\n\n isolating: true,\n\n group: 'block',\n\n parseHTML() {\n return [{ tag: 'table' }]\n },\n\n renderHTML({ node, HTMLAttributes }) {\n const { colgroup, tableWidth, tableMinWidth } = createColGroup(\n node,\n this.options.cellMinWidth,\n )\n\n const table: DOMOutputSpec = [\n 'table',\n mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {\n style: tableWidth\n ? `width: ${tableWidth}`\n : `min-width: ${tableMinWidth}`,\n }),\n colgroup,\n ['tbody', 0],\n ]\n\n return table\n },\n\n addCommands() {\n return {\n insertTable:\n ({ rows = 3, cols = 3, withHeaderRow = true } = {}) => ({ tr, dispatch, editor }) => {\n const node = createTable(editor.schema, rows, cols, withHeaderRow)\n\n if (dispatch) {\n const offset = tr.selection.from + 1\n\n tr.replaceSelectionWith(node)\n .scrollIntoView()\n .setSelection(TextSelection.near(tr.doc.resolve(offset)))\n }\n\n return true\n },\n addColumnBefore:\n () => ({ state, dispatch }) => {\n return addColumnBefore(state, dispatch)\n },\n addColumnAfter:\n () => ({ state, dispatch }) => {\n return addColumnAfter(state, dispatch)\n },\n deleteColumn:\n () => ({ state, dispatch }) => {\n return deleteColumn(state, dispatch)\n },\n addRowBefore:\n () => ({ state, dispatch }) => {\n return addRowBefore(state, dispatch)\n },\n addRowAfter:\n () => ({ state, dispatch }) => {\n return addRowAfter(state, dispatch)\n },\n deleteRow:\n () => ({ state, dispatch }) => {\n return deleteRow(state, dispatch)\n },\n deleteTable:\n () => ({ state, dispatch }) => {\n return deleteTable(state, dispatch)\n },\n mergeCells:\n () => ({ state, dispatch }) => {\n return mergeCells(state, dispatch)\n },\n splitCell:\n () => ({ state, dispatch }) => {\n return splitCell(state, dispatch)\n },\n toggleHeaderColumn:\n () => ({ state, dispatch }) => {\n return toggleHeader('column')(state, dispatch)\n },\n toggleHeaderRow:\n () => ({ state, dispatch }) => {\n return toggleHeader('row')(state, dispatch)\n },\n toggleHeaderCell:\n () => ({ state, dispatch }) => {\n return toggleHeaderCell(state, dispatch)\n },\n mergeOrSplit:\n () => ({ state, dispatch }) => {\n if (mergeCells(state, dispatch)) {\n return true\n }\n\n return splitCell(state, dispatch)\n },\n setCellAttribute:\n (name, value) => ({ state, dispatch }) => {\n return setCellAttr(name, value)(state, dispatch)\n },\n goToNextCell:\n () => ({ state, dispatch }) => {\n return goToNextCell(1)(state, dispatch)\n },\n goToPreviousCell:\n () => ({ state, dispatch }) => {\n return goToNextCell(-1)(state, dispatch)\n },\n fixTables:\n () => ({ state, dispatch }) => {\n if (dispatch) {\n fixTables(state)\n }\n\n return true\n },\n setCellSelection:\n position => ({ tr, dispatch }) => {\n if (dispatch) {\n const selection = CellSelection.create(tr.doc, position.anchorCell, position.headCell)\n\n // @ts-ignore\n tr.setSelection(selection)\n }\n\n return true\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n Tab: () => {\n if (this.editor.commands.goToNextCell()) {\n return true\n }\n\n if (!this.editor.can().addRowAfter()) {\n return false\n }\n\n return this.editor.chain().addRowAfter().goToNextCell().run()\n },\n 'Shift-Tab': () => this.editor.commands.goToPreviousCell(),\n Backspace: deleteTableWhenAllCellsSelected,\n 'Mod-Backspace': deleteTableWhenAllCellsSelected,\n Delete: deleteTableWhenAllCellsSelected,\n 'Mod-Delete': deleteTableWhenAllCellsSelected,\n }\n },\n\n addProseMirrorPlugins() {\n const isResizable = this.options.resizable && this.editor.isEditable\n\n return [\n ...(isResizable\n ? [\n columnResizing({\n handleWidth: this.options.handleWidth,\n cellMinWidth: this.options.cellMinWidth,\n View: this.options.View,\n lastColumnResizable: this.options.lastColumnResizable,\n }),\n ]\n : []),\n tableEditing({\n allowTableNodeSelection: this.options.allowTableNodeSelection,\n }),\n ]\n },\n\n extendNodeSchema(extension) {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n }\n\n return {\n tableRole: callOrReturn(getExtensionField(extension, 'tableRole', context)),\n }\n },\n})\n","// @ts-nocheck\nimport { Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { NodeView } from '@tiptap/pm/view'\n\nexport function updateColumns(\n node: ProseMirrorNode,\n colgroup: Element,\n table: Element,\n cellMinWidth: number,\n overrideCol?: number,\n overrideValue?: any,\n) {\n let totalWidth = 0\n let fixedWidth = true\n let nextDOM = colgroup.firstChild\n const row = node.firstChild\n\n for (let i = 0, col = 0; i < row.childCount; i += 1) {\n const { colspan, colwidth } = row.child(i).attrs\n\n for (let j = 0; j < colspan; j += 1, col += 1) {\n const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j]\n const cssWidth = hasWidth ? `${hasWidth}px` : ''\n\n totalWidth += hasWidth || cellMinWidth\n\n if (!hasWidth) {\n fixedWidth = false\n }\n\n if (!nextDOM) {\n colgroup.appendChild(document.createElement('col')).style.width = cssWidth\n } else {\n if (nextDOM.style.width !== cssWidth) {\n nextDOM.style.width = cssWidth\n }\n\n nextDOM = nextDOM.nextSibling\n }\n }\n }\n\n while (nextDOM) {\n const after = nextDOM.nextSibling\n\n nextDOM.parentNode.removeChild(nextDOM)\n nextDOM = after\n }\n\n if (fixedWidth) {\n table.style.width = `${totalWidth}px`\n table.style.minWidth = ''\n } else {\n table.style.width = ''\n table.style.minWidth = `${totalWidth}px`\n }\n}\n\nexport class TableView implements NodeView {\n node: ProseMirrorNode\n\n cellMinWidth: number\n\n dom: Element\n\n table: Element\n\n colgroup: Element\n\n contentDOM: Element\n\n constructor(node: ProseMirrorNode, cellMinWidth: number) {\n this.node = node\n this.cellMinWidth = cellMinWidth\n this.dom = document.createElement('div')\n this.dom.className = 'tableWrapper'\n this.table = this.dom.appendChild(document.createElement('table'))\n this.colgroup = this.table.appendChild(document.createElement('colgroup'))\n updateColumns(node, this.colgroup, this.table, cellMinWidth)\n this.contentDOM = this.table.appendChild(document.createElement('tbody'))\n }\n\n update(node: ProseMirrorNode) {\n if (node.type !== this.node.type) {\n return false\n }\n\n this.node = node\n updateColumns(node, this.colgroup, this.table, this.cellMinWidth)\n\n return true\n }\n\n ignoreMutation(mutation: MutationRecord | { type: 'selection'; target: Element }) {\n return (\n mutation.type === 'attributes'\n && (mutation.target === this.table || this.colgroup.contains(mutation.target))\n )\n }\n}\n","import { DOMOutputSpec, Node as ProseMirrorNode } from '@tiptap/pm/model'\n\n/**\n * Creates a colgroup element for a table node in ProseMirror.\n *\n * @param node - The ProseMirror node representing the table.\n * @param cellMinWidth - The minimum width of a cell in the table.\n * @param overrideCol - (Optional) The index of the column to override the width of.\n * @param overrideValue - (Optional) The width value to use for the overridden column.\n * @returns An object containing the colgroup element, the total width of the table, and the minimum width of the table.\n */\nexport function createColGroup(\n node: ProseMirrorNode,\n cellMinWidth: number,\n overrideCol?: number,\n overrideValue?: any,\n) {\n let totalWidth = 0\n let fixedWidth = true\n const cols: DOMOutputSpec[] = []\n const row = node.firstChild\n\n if (!row) {\n return {}\n }\n\n for (let i = 0, col = 0; i < row.childCount; i += 1) {\n const { colspan, colwidth } = row.child(i).attrs\n\n for (let j = 0; j < colspan; j += 1, col += 1) {\n const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j]\n const cssWidth = hasWidth ? `${hasWidth}px` : ''\n\n totalWidth += hasWidth || cellMinWidth\n\n if (!hasWidth) {\n fixedWidth = false\n }\n\n cols.push(['col', cssWidth ? { style: `width: ${cssWidth}` } : {}])\n }\n }\n\n const tableWidth = fixedWidth ? `${totalWidth}px` : ''\n const tableMinWidth = fixedWidth ? '' : `${totalWidth}px`\n\n const colgroup: DOMOutputSpec = ['colgroup', {}, ...cols]\n\n return { colgroup, tableWidth, tableMinWidth }\n}\n","import { Fragment, Node as ProsemirrorNode, NodeType } from '@tiptap/pm/model'\n\nexport function createCell(\n cellType: NodeType,\n cellContent?: Fragment | ProsemirrorNode | Array<ProsemirrorNode>,\n): ProsemirrorNode | null | undefined {\n if (cellContent) {\n return cellType.createChecked(null, cellContent)\n }\n\n return cellType.createAndFill()\n}\n","import { NodeType, Schema } from '@tiptap/pm/model'\n\nexport function getTableNodeTypes(schema: Schema): { [key: string]: NodeType } {\n if (schema.cached.tableNodeTypes) {\n return schema.cached.tableNodeTypes\n }\n\n const roles: { [key: string]: NodeType } = {}\n\n Object.keys(schema.nodes).forEach(type => {\n const nodeType = schema.nodes[type]\n\n if (nodeType.spec.tableRole) {\n roles[nodeType.spec.tableRole] = nodeType\n }\n })\n\n schema.cached.tableNodeTypes = roles\n\n return roles\n}\n","import { Fragment, Node as ProsemirrorNode, Schema } from '@tiptap/pm/model'\n\nimport { createCell } from './createCell.js'\nimport { getTableNodeTypes } from './getTableNodeTypes.js'\n\nexport function createTable(\n schema: Schema,\n rowsCount: number,\n colsCount: number,\n withHeaderRow: boolean,\n cellContent?: Fragment | ProsemirrorNode | Array<ProsemirrorNode>,\n): ProsemirrorNode {\n const types = getTableNodeTypes(schema)\n const headerCells: ProsemirrorNode[] = []\n const cells: ProsemirrorNode[] = []\n\n for (let index = 0; index < colsCount; index += 1) {\n const cell = createCell(types.cell, cellContent)\n\n if (cell) {\n cells.push(cell)\n }\n\n if (withHeaderRow) {\n const headerCell = createCell(types.header_cell, cellContent)\n\n if (headerCell) {\n headerCells.push(headerCell)\n }\n }\n }\n\n const rows: ProsemirrorNode[] = []\n\n for (let index = 0; index < rowsCount; index += 1) {\n rows.push(types.row.createChecked(null, withHeaderRow && index === 0 ? headerCells : cells))\n }\n\n return types.table.createChecked(null, rows)\n}\n","import { findParentNodeClosestToPos, KeyboardShortcutCommand } from '@tiptap/core'\n\nimport { isCellSelection } from './isCellSelection.js'\n\nexport const deleteTableWhenAllCellsSelected: KeyboardShortcutCommand = ({ editor }) => {\n const { selection } = editor.state\n\n if (!isCellSelection(selection)) {\n return false\n }\n\n let cellCount = 0\n const table = findParentNodeClosestToPos(selection.ranges[0].$from, node => {\n return node.type.name === 'table'\n })\n\n table?.node.descendants(node => {\n if (node.type.name === 'table') {\n return false\n }\n\n if (['tableCell', 'tableHeader'].includes(node.type.name)) {\n cellCount += 1\n }\n })\n\n const allCellsSelected = cellCount === selection.ranges.length\n\n if (!allCellsSelected) {\n return false\n }\n\n editor.commands.deleteTable()\n\n return true\n}\n","import { CellSelection } from '@tiptap/pm/tables'\n\nexport function isCellSelection(value: unknown): value is CellSelection {\n return value instanceof CellSelection\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,eAEO;AAEP,mBAA8B;AAC9B,IAAAC,iBAkBO;;;ACnBA,SAAS,cACd,MACA,UACA,OACA,cACA,aACA,eACA;AACA,MAAI,aAAa;AACjB,MAAI,aAAa;AACjB,MAAI,UAAU,SAAS;AACvB,QAAM,MAAM,KAAK;AAEjB,WAAS,IAAI,GAAG,MAAM,GAAG,IAAI,IAAI,YAAY,KAAK,GAAG;AACnD,UAAM,EAAE,SAAS,SAAS,IAAI,IAAI,MAAM,CAAC,EAAE;AAE3C,aAAS,IAAI,GAAG,IAAI,SAAS,KAAK,GAAG,OAAO,GAAG;AAC7C,YAAM,WAAW,gBAAgB,MAAM,gBAAgB,YAAY,SAAS,CAAC;AAC7E,YAAM,WAAW,WAAW,GAAG,QAAQ,OAAO;AAE9C,oBAAc,YAAY;AAE1B,UAAI,CAAC,UAAU;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AE,IAAI;AAAA,MAC9D;AAAA,MACA,aAAa,MAAM,KAAK,OAAO,SAAS,iBAAiB;AAAA,MACzD,WAAW;AAAA,MACX,iBAAiB;AAAA,MACjB,QAAQ;AAAA,MACR,cAAc;AAAA,IAChB;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,UAAM,cAAc,KAAK,QAAQ,aAAa,KAAK,OAAO;AAE1D,WAAO;AAAA,MACL,GAAI,cACA;AAAA,YACA,+BAAe;AAAA,UACb,aAAa,KAAK,QAAQ;AAAA,UAC1B,cAAc,KAAK,QAAQ;AAAA,UAC3B,MAAM,KAAK,QAAQ;AAAA,UACnB,qBAAqB,KAAK,QAAQ;AAAA,QACpC,CAAC;AAAA,MACH,IACE,CAAC;AAAA,UACL,6BAAa;AAAA,QACX,yBAAyB,KAAK,QAAQ;AAAA,MACxC,CAAC;AAAA,IACH;AAAA,EACF;AAAA,EAEA,iBAAiB,WAAW;AAC1B,UAAM,UAAU;AAAA,MACd,MAAM,UAAU;AAAA,MAChB,SAAS,UAAU;AAAA,MACnB,SAAS,UAAU;AAAA,IACrB;AAEA,WAAO;AAAA,MACL,eAAW,+BAAa,gCAAkB,WAAW,aAAa,OAAO,CAAC;AAAA,IAC5E;AAAA,EACF;AACF,CAAC;;;ADjcD,IAAO,cAAQ;","names":["import_core","import_tables"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/table.ts","../src/utilities/colStyle.ts","../src/TableView.ts","../src/utilities/createColGroup.ts","../src/utilities/createCell.ts","../src/utilities/getTableNodeTypes.ts","../src/utilities/createTable.ts","../src/utilities/deleteTableWhenAllCellsSelected.ts","../src/utilities/isCellSelection.ts"],"sourcesContent":["import { Table } from './table.js'\n\nexport * from './table.js'\nexport * from './utilities/createColGroup.js'\nexport * from './utilities/createTable.js'\n\nexport default Table\n","import {\n callOrReturn, getExtensionField, mergeAttributes, Node, ParentConfig,\n} from '@tiptap/core'\nimport { DOMOutputSpec, Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { TextSelection } from '@tiptap/pm/state'\nimport {\n addColumnAfter,\n addColumnBefore,\n addRowAfter,\n addRowBefore,\n CellSelection,\n columnResizing,\n deleteColumn,\n deleteRow,\n deleteTable,\n fixTables,\n goToNextCell,\n mergeCells,\n setCellAttr,\n splitCell,\n tableEditing,\n toggleHeader,\n toggleHeaderCell,\n} from '@tiptap/pm/tables'\nimport { EditorView, NodeView } from '@tiptap/pm/view'\n\nimport { TableView } from './TableView.js'\nimport { createColGroup } from './utilities/createColGroup.js'\nimport { createTable } from './utilities/createTable.js'\nimport { deleteTableWhenAllCellsSelected } from './utilities/deleteTableWhenAllCellsSelected.js'\n\nexport interface TableOptions {\n /**\n * HTML attributes for the table element.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n\n /**\n * Enables the resizing of tables.\n * @default false\n * @example true\n */\n resizable: boolean\n\n /**\n * The width of the resize handle.\n * @default 5\n * @example 10\n */\n handleWidth: number\n\n /**\n * The minimum width of a cell.\n * @default 25\n * @example 50\n */\n cellMinWidth: number\n\n /**\n * The node view to render the table.\n * @default TableView\n */\n View: (new (node: ProseMirrorNode, cellMinWidth: number, view: EditorView) => NodeView) | null\n\n /**\n * Enables the resizing of the last column.\n * @default true\n * @example false\n */\n lastColumnResizable: boolean\n\n /**\n * Allow table node selection.\n * @default false\n * @example true\n */\n allowTableNodeSelection: boolean\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n table: {\n /**\n * Insert a table\n * @param options The table attributes\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.insertTable({ rows: 3, cols: 3, withHeaderRow: true })\n */\n insertTable: (options?: {\n rows?: number\n cols?: number\n withHeaderRow?: boolean\n }) => ReturnType\n\n /**\n * Add a column before the current column\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.addColumnBefore()\n */\n addColumnBefore: () => ReturnType\n\n /**\n * Add a column after the current column\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.addColumnAfter()\n */\n addColumnAfter: () => ReturnType\n\n /**\n * Delete the current column\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.deleteColumn()\n */\n deleteColumn: () => ReturnType\n\n /**\n * Add a row before the current row\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.addRowBefore()\n */\n addRowBefore: () => ReturnType\n\n /**\n * Add a row after the current row\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.addRowAfter()\n */\n addRowAfter: () => ReturnType\n\n /**\n * Delete the current row\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.deleteRow()\n */\n deleteRow: () => ReturnType\n\n /**\n * Delete the current table\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.deleteTable()\n */\n deleteTable: () => ReturnType\n\n /**\n * Merge the currently selected cells\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.mergeCells()\n */\n mergeCells: () => ReturnType\n\n /**\n * Split the currently selected cell\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.splitCell()\n */\n splitCell: () => ReturnType\n\n /**\n * Toggle the header column\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.toggleHeaderColumn()\n */\n toggleHeaderColumn: () => ReturnType\n\n /**\n * Toggle the header row\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.toggleHeaderRow()\n */\n toggleHeaderRow: () => ReturnType\n\n /**\n * Toggle the header cell\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.toggleHeaderCell()\n */\n toggleHeaderCell: () => ReturnType\n\n /**\n * Merge or split the currently selected cells\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.mergeOrSplit()\n */\n mergeOrSplit: () => ReturnType\n\n /**\n * Set a cell attribute\n * @param name The attribute name\n * @param value The attribute value\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.setCellAttribute('align', 'right')\n */\n setCellAttribute: (name: string, value: any) => ReturnType\n\n /**\n * Moves the selection to the next cell\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.goToNextCell()\n */\n goToNextCell: () => ReturnType\n\n /**\n * Moves the selection to the previous cell\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.goToPreviousCell()\n */\n goToPreviousCell: () => ReturnType\n\n /**\n * Try to fix the table structure if necessary\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.fixTables()\n */\n fixTables: () => ReturnType\n\n /**\n * Set a cell selection inside the current table\n * @param position The cell position\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.setCellSelection({ anchorCell: 1, headCell: 2 })\n */\n setCellSelection: (position: { anchorCell: number; headCell?: number }) => ReturnType\n }\n }\n\n interface NodeConfig<Options, Storage> {\n /**\n * A string or function to determine the role of the table.\n * @default 'table'\n * @example () => 'table'\n */\n tableRole?:\n | string\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options>>['tableRole']\n }) => string)\n }\n}\n\n/**\n * This extension allows you to create tables.\n * @see https://www.tiptap.dev/api/nodes/table\n */\nexport const Table = Node.create<TableOptions>({\n name: 'table',\n\n // @ts-ignore\n addOptions() {\n return {\n HTMLAttributes: {},\n resizable: false,\n handleWidth: 5,\n cellMinWidth: 25,\n // TODO: fix\n View: TableView,\n lastColumnResizable: true,\n allowTableNodeSelection: false,\n }\n },\n\n content: 'tableRow+',\n\n tableRole: 'table',\n\n isolating: true,\n\n group: 'block',\n\n parseHTML() {\n return [{ tag: 'table' }]\n },\n\n renderHTML({ node, HTMLAttributes }) {\n const { colgroup, tableWidth, tableMinWidth } = createColGroup(\n node,\n this.options.cellMinWidth,\n )\n\n const table: DOMOutputSpec = [\n 'table',\n mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {\n style: tableWidth\n ? `width: ${tableWidth}`\n : `min-width: ${tableMinWidth}`,\n }),\n colgroup,\n ['tbody', 0],\n ]\n\n return table\n },\n\n addCommands() {\n return {\n insertTable:\n ({ rows = 3, cols = 3, withHeaderRow = true } = {}) => ({ tr, dispatch, editor }) => {\n const node = createTable(editor.schema, rows, cols, withHeaderRow)\n\n if (dispatch) {\n const offset = tr.selection.from + 1\n\n tr.replaceSelectionWith(node)\n .scrollIntoView()\n .setSelection(TextSelection.near(tr.doc.resolve(offset)))\n }\n\n return true\n },\n addColumnBefore:\n () => ({ state, dispatch }) => {\n return addColumnBefore(state, dispatch)\n },\n addColumnAfter:\n () => ({ state, dispatch }) => {\n return addColumnAfter(state, dispatch)\n },\n deleteColumn:\n () => ({ state, dispatch }) => {\n return deleteColumn(state, dispatch)\n },\n addRowBefore:\n () => ({ state, dispatch }) => {\n return addRowBefore(state, dispatch)\n },\n addRowAfter:\n () => ({ state, dispatch }) => {\n return addRowAfter(state, dispatch)\n },\n deleteRow:\n () => ({ state, dispatch }) => {\n return deleteRow(state, dispatch)\n },\n deleteTable:\n () => ({ state, dispatch }) => {\n return deleteTable(state, dispatch)\n },\n mergeCells:\n () => ({ state, dispatch }) => {\n return mergeCells(state, dispatch)\n },\n splitCell:\n () => ({ state, dispatch }) => {\n return splitCell(state, dispatch)\n },\n toggleHeaderColumn:\n () => ({ state, dispatch }) => {\n return toggleHeader('column')(state, dispatch)\n },\n toggleHeaderRow:\n () => ({ state, dispatch }) => {\n return toggleHeader('row')(state, dispatch)\n },\n toggleHeaderCell:\n () => ({ state, dispatch }) => {\n return toggleHeaderCell(state, dispatch)\n },\n mergeOrSplit:\n () => ({ state, dispatch }) => {\n if (mergeCells(state, dispatch)) {\n return true\n }\n\n return splitCell(state, dispatch)\n },\n setCellAttribute:\n (name, value) => ({ state, dispatch }) => {\n return setCellAttr(name, value)(state, dispatch)\n },\n goToNextCell:\n () => ({ state, dispatch }) => {\n return goToNextCell(1)(state, dispatch)\n },\n goToPreviousCell:\n () => ({ state, dispatch }) => {\n return goToNextCell(-1)(state, dispatch)\n },\n fixTables:\n () => ({ state, dispatch }) => {\n if (dispatch) {\n fixTables(state)\n }\n\n return true\n },\n setCellSelection:\n position => ({ tr, dispatch }) => {\n if (dispatch) {\n const selection = CellSelection.create(tr.doc, position.anchorCell, position.headCell)\n\n // @ts-ignore\n tr.setSelection(selection)\n }\n\n return true\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n Tab: () => {\n if (this.editor.commands.goToNextCell()) {\n return true\n }\n\n if (!this.editor.can().addRowAfter()) {\n return false\n }\n\n return this.editor.chain().addRowAfter().goToNextCell().run()\n },\n 'Shift-Tab': () => this.editor.commands.goToPreviousCell(),\n Backspace: deleteTableWhenAllCellsSelected,\n 'Mod-Backspace': deleteTableWhenAllCellsSelected,\n Delete: deleteTableWhenAllCellsSelected,\n 'Mod-Delete': deleteTableWhenAllCellsSelected,\n }\n },\n\n addProseMirrorPlugins() {\n const isResizable = this.options.resizable && this.editor.isEditable\n\n return [\n ...(isResizable\n ? [\n columnResizing({\n handleWidth: this.options.handleWidth,\n cellMinWidth: this.options.cellMinWidth,\n defaultCellMinWidth: this.options.cellMinWidth,\n View: this.options.View,\n lastColumnResizable: this.options.lastColumnResizable,\n }),\n ]\n : []),\n tableEditing({\n allowTableNodeSelection: this.options.allowTableNodeSelection,\n }),\n ]\n },\n\n extendNodeSchema(extension) {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n }\n\n return {\n tableRole: callOrReturn(getExtensionField(extension, 'tableRole', context)),\n }\n },\n})\n","export function getColStyleDeclaration(minWidth: number, width: number | undefined): [string, string] {\n if (width) {\n // apply the stored width unless it is below the configured minimum cell width\n return ['width', `${Math.max(width, minWidth)}px`]\n }\n\n // set the minimum with on the column if it has no stored width\n return ['min-width', `${minWidth}px`]\n\n}\n","import { Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { NodeView, ViewMutationRecord } from '@tiptap/pm/view'\n\nimport { getColStyleDeclaration } from './utilities/colStyle.js'\n\nexport function updateColumns(\n node: ProseMirrorNode,\n colgroup: HTMLTableColElement, // <colgroup> has the same prototype as <col>\n table: HTMLTableElement,\n cellMinWidth: number,\n overrideCol?: number,\n overrideValue?: number,\n) {\n let totalWidth = 0\n let fixedWidth = true\n let nextDOM = colgroup.firstChild\n const row = node.firstChild\n\n if (row !== null) {\n for (let i = 0, col = 0; i < row.childCount; i += 1) {\n const { colspan, colwidth } = row.child(i).attrs\n\n for (let j = 0; j < colspan; j += 1, col += 1) {\n const hasWidth = overrideCol === col ? overrideValue : (colwidth && colwidth[j]) as number | undefined\n const cssWidth = hasWidth ? `${hasWidth}px` : ''\n\n totalWidth += hasWidth || cellMinWidth\n\n if (!hasWidth) {\n fixedWidth = false\n }\n\n if (!nextDOM) {\n const colElement = document.createElement('col')\n\n const [propertyKey, propertyValue] = getColStyleDeclaration(cellMinWidth, hasWidth)\n\n colElement.style.setProperty(propertyKey, propertyValue)\n\n colgroup.appendChild(colElement)\n } else {\n if ((nextDOM as HTMLTableColElement).style.width !== cssWidth) {\n const [propertyKey, propertyValue] = getColStyleDeclaration(cellMinWidth, hasWidth);\n\n (nextDOM as HTMLTableColElement).style.setProperty(propertyKey, propertyValue)\n }\n\n nextDOM = nextDOM.nextSibling\n }\n }\n }\n }\n\n while (nextDOM) {\n const after = nextDOM.nextSibling\n\n nextDOM.parentNode?.removeChild(nextDOM)\n nextDOM = after\n }\n\n if (fixedWidth) {\n table.style.width = `${totalWidth}px`\n table.style.minWidth = ''\n } else {\n table.style.width = ''\n table.style.minWidth = `${totalWidth}px`\n }\n}\n\nexport class TableView implements NodeView {\n node: ProseMirrorNode\n\n cellMinWidth: number\n\n dom: HTMLDivElement\n\n table: HTMLTableElement\n\n colgroup: HTMLTableColElement\n\n contentDOM: HTMLTableSectionElement\n\n constructor(node: ProseMirrorNode, cellMinWidth: number) {\n this.node = node\n this.cellMinWidth = cellMinWidth\n this.dom = document.createElement('div')\n this.dom.className = 'tableWrapper'\n this.table = this.dom.appendChild(document.createElement('table'))\n this.colgroup = this.table.appendChild(document.createElement('colgroup'))\n updateColumns(node, this.colgroup, this.table, cellMinWidth)\n this.contentDOM = this.table.appendChild(document.createElement('tbody'))\n }\n\n update(node: ProseMirrorNode) {\n if (node.type !== this.node.type) {\n return false\n }\n\n this.node = node\n updateColumns(node, this.colgroup, this.table, this.cellMinWidth)\n\n return true\n }\n\n ignoreMutation(mutation: ViewMutationRecord) {\n return (\n mutation.type === 'attributes'\n && (mutation.target === this.table || this.colgroup.contains(mutation.target))\n )\n }\n}\n","import { DOMOutputSpec, Node as ProseMirrorNode } from '@tiptap/pm/model'\n\nimport { getColStyleDeclaration } from './colStyle.js'\n\nexport type ColGroup = {\n colgroup: DOMOutputSpec\n tableWidth: string\n tableMinWidth: string\n} | Record<string, never>;\n\n/**\n * Creates a colgroup element for a table node in ProseMirror.\n *\n * @param node - The ProseMirror node representing the table.\n * @param cellMinWidth - The minimum width of a cell in the table.\n * @param overrideCol - (Optional) The index of the column to override the width of.\n * @param overrideValue - (Optional) The width value to use for the overridden column.\n * @returns An object containing the colgroup element, the total width of the table, and the minimum width of the table.\n */\nexport function createColGroup(\n node: ProseMirrorNode,\n cellMinWidth: number,\n): ColGroup\nexport function createColGroup(\n node: ProseMirrorNode,\n cellMinWidth: number,\n overrideCol: number,\n overrideValue: number,\n): ColGroup\nexport function createColGroup(\n node: ProseMirrorNode,\n cellMinWidth: number,\n overrideCol?: number,\n overrideValue?: number,\n): ColGroup {\n let totalWidth = 0\n let fixedWidth = true\n const cols: DOMOutputSpec[] = []\n const row = node.firstChild\n\n if (!row) {\n return {}\n }\n\n for (let i = 0, col = 0; i < row.childCount; i += 1) {\n const { colspan, colwidth } = row.child(i).attrs\n\n for (let j = 0; j < colspan; j += 1, col += 1) {\n const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j] as number | undefined\n\n totalWidth += hasWidth || cellMinWidth\n\n if (!hasWidth) {\n fixedWidth = false\n }\n\n const [property, value] = getColStyleDeclaration(cellMinWidth, hasWidth)\n\n cols.push([\n 'col',\n { style: `${property}: ${value}` },\n ])\n }\n }\n\n const tableWidth = fixedWidth ? `${totalWidth}px` : ''\n const tableMinWidth = fixedWidth ? '' : `${totalWidth}px`\n\n const colgroup: DOMOutputSpec = ['colgroup', {}, ...cols]\n\n return { colgroup, tableWidth, tableMinWidth }\n}\n","import { Fragment, Node as ProsemirrorNode, NodeType } from '@tiptap/pm/model'\n\nexport function createCell(\n cellType: NodeType,\n cellContent?: Fragment | ProsemirrorNode | Array<ProsemirrorNode>,\n): ProsemirrorNode | null | undefined {\n if (cellContent) {\n return cellType.createChecked(null, cellContent)\n }\n\n return cellType.createAndFill()\n}\n","import { NodeType, Schema } from '@tiptap/pm/model'\n\nexport function getTableNodeTypes(schema: Schema): { [key: string]: NodeType } {\n if (schema.cached.tableNodeTypes) {\n return schema.cached.tableNodeTypes\n }\n\n const roles: { [key: string]: NodeType } = {}\n\n Object.keys(schema.nodes).forEach(type => {\n const nodeType = schema.nodes[type]\n\n if (nodeType.spec.tableRole) {\n roles[nodeType.spec.tableRole] = nodeType\n }\n })\n\n schema.cached.tableNodeTypes = roles\n\n return roles\n}\n","import { Fragment, Node as ProsemirrorNode, Schema } from '@tiptap/pm/model'\n\nimport { createCell } from './createCell.js'\nimport { getTableNodeTypes } from './getTableNodeTypes.js'\n\nexport function createTable(\n schema: Schema,\n rowsCount: number,\n colsCount: number,\n withHeaderRow: boolean,\n cellContent?: Fragment | ProsemirrorNode | Array<ProsemirrorNode>,\n): ProsemirrorNode {\n const types = getTableNodeTypes(schema)\n const headerCells: ProsemirrorNode[] = []\n const cells: ProsemirrorNode[] = []\n\n for (let index = 0; index < colsCount; index += 1) {\n const cell = createCell(types.cell, cellContent)\n\n if (cell) {\n cells.push(cell)\n }\n\n if (withHeaderRow) {\n const headerCell = createCell(types.header_cell, cellContent)\n\n if (headerCell) {\n headerCells.push(headerCell)\n }\n }\n }\n\n const rows: ProsemirrorNode[] = []\n\n for (let index = 0; index < rowsCount; index += 1) {\n rows.push(types.row.createChecked(null, withHeaderRow && index === 0 ? headerCells : cells))\n }\n\n return types.table.createChecked(null, rows)\n}\n","import { findParentNodeClosestToPos, KeyboardShortcutCommand } from '@tiptap/core'\n\nimport { isCellSelection } from './isCellSelection.js'\n\nexport const deleteTableWhenAllCellsSelected: KeyboardShortcutCommand = ({ editor }) => {\n const { selection } = editor.state\n\n if (!isCellSelection(selection)) {\n return false\n }\n\n let cellCount = 0\n const table = findParentNodeClosestToPos(selection.ranges[0].$from, node => {\n return node.type.name === 'table'\n })\n\n table?.node.descendants(node => {\n if (node.type.name === 'table') {\n return false\n }\n\n if (['tableCell', 'tableHeader'].includes(node.type.name)) {\n cellCount += 1\n }\n })\n\n const allCellsSelected = cellCount === selection.ranges.length\n\n if (!allCellsSelected) {\n return false\n }\n\n editor.commands.deleteTable()\n\n return true\n}\n","import { CellSelection } from '@tiptap/pm/tables'\n\nexport function isCellSelection(value: unknown): value is CellSelection {\n return value instanceof CellSelection\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,eAEO;AAEP,mBAA8B;AAC9B,IAAAC,iBAkBO;;;ACvBA,SAAS,uBAAuB,UAAkB,OAA6C;AACpG,MAAI,OAAO;AAET,WAAO,CAAC,SAAS,GAAG,KAAK,IAAI,OAAO,QAAQ,CAAC,IAAI;AAAA,EACnD;AAGA,SAAO,CAAC,aAAa,GAAG,QAAQ,IAAI;AAEtC;;;ACJO,SAAS,cACd,MACA,UACA,OACA,cACA,aACA,eACA;AAZF;AAaE,MAAI,aAAa;AACjB,MAAI,aAAa;AACjB,MAAI,UAAU,SAAS;AACvB,QAAM,MAAM,KAAK;AAEjB,MAAI,QAAQ,MAAM;AAChB,aAAS,IAAI,GAAG,MAAM,GAAG,IAAI,IAAI,YAAY,KAAK,GAAG;AACnD,YAAM,EAAE,SAAS,SAAS,IAAI,IAAI,MAAM,CAAC,EAAE;AAE3C,eAAS,IAAI,GAAG,IAAI,SAAS,KAAK,GAAG,OAAO,GAAG;AAC7C,cAAM,WAAW,gBAAgB,MAAM,gBAAiB,YAAY,SAAS,CAAC;AAC9E,cAAM,WAAW,WAAW,GAAG,QAAQ,OAAO;AAE9C,sBAAc,YAAY;AAE1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ACrB,WAAO;AAAA,MACL,KAAK,MAAM;AACT,YAAI,KAAK,OAAO,SAAS,aAAa,GAAG;AACvC,iBAAO;AAAA,QACT;AAEA,YAAI,CAAC,KAAK,OAAO,IAAI,EAAE,YAAY,GAAG;AACpC,iBAAO;AAAA,QACT;AAEA,eAAO,KAAK,OAAO,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,IAAI;AAAA,MAC9D;AAAA,MACA,aAAa,MAAM,KAAK,OAAO,SAAS,iBAAiB;AAAA,MACzD,WAAW;AAAA,MACX,iBAAiB;AAAA,MACjB,QAAQ;AAAA,MACR,cAAc;AAAA,IAChB;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,UAAM,cAAc,KAAK,QAAQ,aAAa,KAAK,OAAO;AAE1D,WAAO;AAAA,MACL,GAAI,cACA;AAAA,YACA,+BAAe;AAAA,UACb,aAAa,KAAK,QAAQ;AAAA,UAC1B,cAAc,KAAK,QAAQ;AAAA,UAC3B,qBAAqB,KAAK,QAAQ;AAAA,UAClC,MAAM,KAAK,QAAQ;AAAA,UACnB,qBAAqB,KAAK,QAAQ;AAAA,QACpC,CAAC;AAAA,MACH,IACE,CAAC;AAAA,UACL,6BAAa;AAAA,QACX,yBAAyB,KAAK,QAAQ;AAAA,MACxC,CAAC;AAAA,IACH;AAAA,EACF;AAAA,EAEA,iBAAiB,WAAW;AAC1B,UAAM,UAAU;AAAA,MACd,MAAM,UAAU;AAAA,MAChB,SAAS,UAAU;AAAA,MACnB,SAAS,UAAU;AAAA,IACrB;AAEA,WAAO;AAAA,MACL,eAAW,+BAAa,gCAAkB,WAAW,aAAa,OAAO,CAAC;AAAA,IAC5E;AAAA,EACF;AACF,CAAC;;;ADlcD,IAAO,cAAQ;","names":["import_core","import_tables"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ParentConfig, Node as Node$1 } from '@tiptap/core';
|
|
2
|
-
import { Node, Schema, Fragment } from '@tiptap/pm/model';
|
|
2
|
+
import { Node, DOMOutputSpec, Schema, Fragment } from '@tiptap/pm/model';
|
|
3
3
|
import { EditorView, NodeView } from '@tiptap/pm/view';
|
|
4
4
|
|
|
5
5
|
interface TableOptions {
|
|
@@ -195,6 +195,11 @@ declare module '@tiptap/core' {
|
|
|
195
195
|
*/
|
|
196
196
|
declare const Table: Node$1<TableOptions, any>;
|
|
197
197
|
|
|
198
|
+
type ColGroup = {
|
|
199
|
+
colgroup: DOMOutputSpec;
|
|
200
|
+
tableWidth: string;
|
|
201
|
+
tableMinWidth: string;
|
|
202
|
+
} | Record<string, never>;
|
|
198
203
|
/**
|
|
199
204
|
* Creates a colgroup element for a table node in ProseMirror.
|
|
200
205
|
*
|
|
@@ -204,16 +209,9 @@ declare const Table: Node$1<TableOptions, any>;
|
|
|
204
209
|
* @param overrideValue - (Optional) The width value to use for the overridden column.
|
|
205
210
|
* @returns An object containing the colgroup element, the total width of the table, and the minimum width of the table.
|
|
206
211
|
*/
|
|
207
|
-
declare function createColGroup(node: Node, cellMinWidth: number
|
|
208
|
-
|
|
209
|
-
tableWidth?: undefined;
|
|
210
|
-
tableMinWidth?: undefined;
|
|
211
|
-
} | {
|
|
212
|
-
colgroup: readonly [string, ...any[]];
|
|
213
|
-
tableWidth: string;
|
|
214
|
-
tableMinWidth: string;
|
|
215
|
-
};
|
|
212
|
+
declare function createColGroup(node: Node, cellMinWidth: number): ColGroup;
|
|
213
|
+
declare function createColGroup(node: Node, cellMinWidth: number, overrideCol: number, overrideValue: number): ColGroup;
|
|
216
214
|
|
|
217
215
|
declare function createTable(schema: Schema, rowsCount: number, colsCount: number, withHeaderRow: boolean, cellContent?: Fragment | Node | Array<Node>): Node;
|
|
218
216
|
|
|
219
|
-
export { Table, type TableOptions, createColGroup, createTable, Table as default };
|
|
217
|
+
export { type ColGroup, Table, type TableOptions, createColGroup, createTable, Table as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ParentConfig, Node as Node$1 } from '@tiptap/core';
|
|
2
|
-
import { Node, Schema, Fragment } from '@tiptap/pm/model';
|
|
2
|
+
import { Node, DOMOutputSpec, Schema, Fragment } from '@tiptap/pm/model';
|
|
3
3
|
import { EditorView, NodeView } from '@tiptap/pm/view';
|
|
4
4
|
|
|
5
5
|
interface TableOptions {
|
|
@@ -195,6 +195,11 @@ declare module '@tiptap/core' {
|
|
|
195
195
|
*/
|
|
196
196
|
declare const Table: Node$1<TableOptions, any>;
|
|
197
197
|
|
|
198
|
+
type ColGroup = {
|
|
199
|
+
colgroup: DOMOutputSpec;
|
|
200
|
+
tableWidth: string;
|
|
201
|
+
tableMinWidth: string;
|
|
202
|
+
} | Record<string, never>;
|
|
198
203
|
/**
|
|
199
204
|
* Creates a colgroup element for a table node in ProseMirror.
|
|
200
205
|
*
|
|
@@ -204,16 +209,9 @@ declare const Table: Node$1<TableOptions, any>;
|
|
|
204
209
|
* @param overrideValue - (Optional) The width value to use for the overridden column.
|
|
205
210
|
* @returns An object containing the colgroup element, the total width of the table, and the minimum width of the table.
|
|
206
211
|
*/
|
|
207
|
-
declare function createColGroup(node: Node, cellMinWidth: number
|
|
208
|
-
|
|
209
|
-
tableWidth?: undefined;
|
|
210
|
-
tableMinWidth?: undefined;
|
|
211
|
-
} | {
|
|
212
|
-
colgroup: readonly [string, ...any[]];
|
|
213
|
-
tableWidth: string;
|
|
214
|
-
tableMinWidth: string;
|
|
215
|
-
};
|
|
212
|
+
declare function createColGroup(node: Node, cellMinWidth: number): ColGroup;
|
|
213
|
+
declare function createColGroup(node: Node, cellMinWidth: number, overrideCol: number, overrideValue: number): ColGroup;
|
|
216
214
|
|
|
217
215
|
declare function createTable(schema: Schema, rowsCount: number, colsCount: number, withHeaderRow: boolean, cellContent?: Fragment | Node | Array<Node>): Node;
|
|
218
216
|
|
|
219
|
-
export { Table, type TableOptions, createColGroup, createTable, Table as default };
|
|
217
|
+
export { type ColGroup, Table, type TableOptions, createColGroup, createTable, Table as default };
|
package/dist/index.js
CHANGED
|
@@ -26,34 +26,49 @@ import {
|
|
|
26
26
|
toggleHeaderCell
|
|
27
27
|
} from "@tiptap/pm/tables";
|
|
28
28
|
|
|
29
|
+
// src/utilities/colStyle.ts
|
|
30
|
+
function getColStyleDeclaration(minWidth, width) {
|
|
31
|
+
if (width) {
|
|
32
|
+
return ["width", `${Math.max(width, minWidth)}px`];
|
|
33
|
+
}
|
|
34
|
+
return ["min-width", `${minWidth}px`];
|
|
35
|
+
}
|
|
36
|
+
|
|
29
37
|
// src/TableView.ts
|
|
30
38
|
function updateColumns(node, colgroup, table, cellMinWidth, overrideCol, overrideValue) {
|
|
39
|
+
var _a;
|
|
31
40
|
let totalWidth = 0;
|
|
32
41
|
let fixedWidth = true;
|
|
33
42
|
let nextDOM = colgroup.firstChild;
|
|
34
43
|
const row = node.firstChild;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
if (row !== null) {
|
|
45
|
+
for (let i = 0, col = 0; i < row.childCount; i += 1) {
|
|
46
|
+
const { colspan, colwidth } = row.child(i).attrs;
|
|
47
|
+
for (let j = 0; j < colspan; j += 1, col += 1) {
|
|
48
|
+
const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j];
|
|
49
|
+
const cssWidth = hasWidth ? `${hasWidth}px` : "";
|
|
50
|
+
totalWidth += hasWidth || cellMinWidth;
|
|
51
|
+
if (!hasWidth) {
|
|
52
|
+
fixedWidth = false;
|
|
53
|
+
}
|
|
54
|
+
if (!nextDOM) {
|
|
55
|
+
const colElement = document.createElement("col");
|
|
56
|
+
const [propertyKey, propertyValue] = getColStyleDeclaration(cellMinWidth, hasWidth);
|
|
57
|
+
colElement.style.setProperty(propertyKey, propertyValue);
|
|
58
|
+
colgroup.appendChild(colElement);
|
|
59
|
+
} else {
|
|
60
|
+
if (nextDOM.style.width !== cssWidth) {
|
|
61
|
+
const [propertyKey, propertyValue] = getColStyleDeclaration(cellMinWidth, hasWidth);
|
|
62
|
+
nextDOM.style.setProperty(propertyKey, propertyValue);
|
|
63
|
+
}
|
|
64
|
+
nextDOM = nextDOM.nextSibling;
|
|
49
65
|
}
|
|
50
|
-
nextDOM = nextDOM.nextSibling;
|
|
51
66
|
}
|
|
52
67
|
}
|
|
53
68
|
}
|
|
54
69
|
while (nextDOM) {
|
|
55
70
|
const after = nextDOM.nextSibling;
|
|
56
|
-
nextDOM.parentNode.removeChild(nextDOM);
|
|
71
|
+
(_a = nextDOM.parentNode) == null ? void 0 : _a.removeChild(nextDOM);
|
|
57
72
|
nextDOM = after;
|
|
58
73
|
}
|
|
59
74
|
if (fixedWidth) {
|
|
@@ -101,12 +116,15 @@ function createColGroup(node, cellMinWidth, overrideCol, overrideValue) {
|
|
|
101
116
|
const { colspan, colwidth } = row.child(i).attrs;
|
|
102
117
|
for (let j = 0; j < colspan; j += 1, col += 1) {
|
|
103
118
|
const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j];
|
|
104
|
-
const cssWidth = hasWidth ? `${hasWidth}px` : "";
|
|
105
119
|
totalWidth += hasWidth || cellMinWidth;
|
|
106
120
|
if (!hasWidth) {
|
|
107
121
|
fixedWidth = false;
|
|
108
122
|
}
|
|
109
|
-
|
|
123
|
+
const [property, value] = getColStyleDeclaration(cellMinWidth, hasWidth);
|
|
124
|
+
cols.push([
|
|
125
|
+
"col",
|
|
126
|
+
{ style: `${property}: ${value}` }
|
|
127
|
+
]);
|
|
110
128
|
}
|
|
111
129
|
}
|
|
112
130
|
const tableWidth = fixedWidth ? `${totalWidth}px` : "";
|
|
@@ -337,6 +355,7 @@ var Table = Node.create({
|
|
|
337
355
|
columnResizing({
|
|
338
356
|
handleWidth: this.options.handleWidth,
|
|
339
357
|
cellMinWidth: this.options.cellMinWidth,
|
|
358
|
+
defaultCellMinWidth: this.options.cellMinWidth,
|
|
340
359
|
View: this.options.View,
|
|
341
360
|
lastColumnResizable: this.options.lastColumnResizable
|
|
342
361
|
})
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/table.ts","../src/TableView.ts","../src/utilities/createColGroup.ts","../src/utilities/createCell.ts","../src/utilities/getTableNodeTypes.ts","../src/utilities/createTable.ts","../src/utilities/deleteTableWhenAllCellsSelected.ts","../src/utilities/isCellSelection.ts","../src/index.ts"],"sourcesContent":["import {\n callOrReturn, getExtensionField, mergeAttributes, Node, ParentConfig,\n} from '@tiptap/core'\nimport { DOMOutputSpec, Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { TextSelection } from '@tiptap/pm/state'\nimport {\n addColumnAfter,\n addColumnBefore,\n addRowAfter,\n addRowBefore,\n CellSelection,\n columnResizing,\n deleteColumn,\n deleteRow,\n deleteTable,\n fixTables,\n goToNextCell,\n mergeCells,\n setCellAttr,\n splitCell,\n tableEditing,\n toggleHeader,\n toggleHeaderCell,\n} from '@tiptap/pm/tables'\nimport { EditorView, NodeView } from '@tiptap/pm/view'\n\nimport { TableView } from './TableView.js'\nimport { createColGroup } from './utilities/createColGroup.js'\nimport { createTable } from './utilities/createTable.js'\nimport { deleteTableWhenAllCellsSelected } from './utilities/deleteTableWhenAllCellsSelected.js'\n\nexport interface TableOptions {\n /**\n * HTML attributes for the table element.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n\n /**\n * Enables the resizing of tables.\n * @default false\n * @example true\n */\n resizable: boolean\n\n /**\n * The width of the resize handle.\n * @default 5\n * @example 10\n */\n handleWidth: number\n\n /**\n * The minimum width of a cell.\n * @default 25\n * @example 50\n */\n cellMinWidth: number\n\n /**\n * The node view to render the table.\n * @default TableView\n */\n View: (new (node: ProseMirrorNode, cellMinWidth: number, view: EditorView) => NodeView) | null\n\n /**\n * Enables the resizing of the last column.\n * @default true\n * @example false\n */\n lastColumnResizable: boolean\n\n /**\n * Allow table node selection.\n * @default false\n * @example true\n */\n allowTableNodeSelection: boolean\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n table: {\n /**\n * Insert a table\n * @param options The table attributes\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.insertTable({ rows: 3, cols: 3, withHeaderRow: true })\n */\n insertTable: (options?: {\n rows?: number\n cols?: number\n withHeaderRow?: boolean\n }) => ReturnType\n\n /**\n * Add a column before the current column\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.addColumnBefore()\n */\n addColumnBefore: () => ReturnType\n\n /**\n * Add a column after the current column\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.addColumnAfter()\n */\n addColumnAfter: () => ReturnType\n\n /**\n * Delete the current column\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.deleteColumn()\n */\n deleteColumn: () => ReturnType\n\n /**\n * Add a row before the current row\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.addRowBefore()\n */\n addRowBefore: () => ReturnType\n\n /**\n * Add a row after the current row\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.addRowAfter()\n */\n addRowAfter: () => ReturnType\n\n /**\n * Delete the current row\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.deleteRow()\n */\n deleteRow: () => ReturnType\n\n /**\n * Delete the current table\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.deleteTable()\n */\n deleteTable: () => ReturnType\n\n /**\n * Merge the currently selected cells\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.mergeCells()\n */\n mergeCells: () => ReturnType\n\n /**\n * Split the currently selected cell\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.splitCell()\n */\n splitCell: () => ReturnType\n\n /**\n * Toggle the header column\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.toggleHeaderColumn()\n */\n toggleHeaderColumn: () => ReturnType\n\n /**\n * Toggle the header row\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.toggleHeaderRow()\n */\n toggleHeaderRow: () => ReturnType\n\n /**\n * Toggle the header cell\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.toggleHeaderCell()\n */\n toggleHeaderCell: () => ReturnType\n\n /**\n * Merge or split the currently selected cells\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.mergeOrSplit()\n */\n mergeOrSplit: () => ReturnType\n\n /**\n * Set a cell attribute\n * @param name The attribute name\n * @param value The attribute value\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.setCellAttribute('align', 'right')\n */\n setCellAttribute: (name: string, value: any) => ReturnType\n\n /**\n * Moves the selection to the next cell\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.goToNextCell()\n */\n goToNextCell: () => ReturnType\n\n /**\n * Moves the selection to the previous cell\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.goToPreviousCell()\n */\n goToPreviousCell: () => ReturnType\n\n /**\n * Try to fix the table structure if necessary\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.fixTables()\n */\n fixTables: () => ReturnType\n\n /**\n * Set a cell selection inside the current table\n * @param position The cell position\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.setCellSelection({ anchorCell: 1, headCell: 2 })\n */\n setCellSelection: (position: { anchorCell: number; headCell?: number }) => ReturnType\n }\n }\n\n interface NodeConfig<Options, Storage> {\n /**\n * A string or function to determine the role of the table.\n * @default 'table'\n * @example () => 'table'\n */\n tableRole?:\n | string\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options>>['tableRole']\n }) => string)\n }\n}\n\n/**\n * This extension allows you to create tables.\n * @see https://www.tiptap.dev/api/nodes/table\n */\nexport const Table = Node.create<TableOptions>({\n name: 'table',\n\n // @ts-ignore\n addOptions() {\n return {\n HTMLAttributes: {},\n resizable: false,\n handleWidth: 5,\n cellMinWidth: 25,\n // TODO: fix\n View: TableView,\n lastColumnResizable: true,\n allowTableNodeSelection: false,\n }\n },\n\n content: 'tableRow+',\n\n tableRole: 'table',\n\n isolating: true,\n\n group: 'block',\n\n parseHTML() {\n return [{ tag: 'table' }]\n },\n\n renderHTML({ node, HTMLAttributes }) {\n const { colgroup, tableWidth, tableMinWidth } = createColGroup(\n node,\n this.options.cellMinWidth,\n )\n\n const table: DOMOutputSpec = [\n 'table',\n mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {\n style: tableWidth\n ? `width: ${tableWidth}`\n : `min-width: ${tableMinWidth}`,\n }),\n colgroup,\n ['tbody', 0],\n ]\n\n return table\n },\n\n addCommands() {\n return {\n insertTable:\n ({ rows = 3, cols = 3, withHeaderRow = true } = {}) => ({ tr, dispatch, editor }) => {\n const node = createTable(editor.schema, rows, cols, withHeaderRow)\n\n if (dispatch) {\n const offset = tr.selection.from + 1\n\n tr.replaceSelectionWith(node)\n .scrollIntoView()\n .setSelection(TextSelection.near(tr.doc.resolve(offset)))\n }\n\n return true\n },\n addColumnBefore:\n () => ({ state, dispatch }) => {\n return addColumnBefore(state, dispatch)\n },\n addColumnAfter:\n () => ({ state, dispatch }) => {\n return addColumnAfter(state, dispatch)\n },\n deleteColumn:\n () => ({ state, dispatch }) => {\n return deleteColumn(state, dispatch)\n },\n addRowBefore:\n () => ({ state, dispatch }) => {\n return addRowBefore(state, dispatch)\n },\n addRowAfter:\n () => ({ state, dispatch }) => {\n return addRowAfter(state, dispatch)\n },\n deleteRow:\n () => ({ state, dispatch }) => {\n return deleteRow(state, dispatch)\n },\n deleteTable:\n () => ({ state, dispatch }) => {\n return deleteTable(state, dispatch)\n },\n mergeCells:\n () => ({ state, dispatch }) => {\n return mergeCells(state, dispatch)\n },\n splitCell:\n () => ({ state, dispatch }) => {\n return splitCell(state, dispatch)\n },\n toggleHeaderColumn:\n () => ({ state, dispatch }) => {\n return toggleHeader('column')(state, dispatch)\n },\n toggleHeaderRow:\n () => ({ state, dispatch }) => {\n return toggleHeader('row')(state, dispatch)\n },\n toggleHeaderCell:\n () => ({ state, dispatch }) => {\n return toggleHeaderCell(state, dispatch)\n },\n mergeOrSplit:\n () => ({ state, dispatch }) => {\n if (mergeCells(state, dispatch)) {\n return true\n }\n\n return splitCell(state, dispatch)\n },\n setCellAttribute:\n (name, value) => ({ state, dispatch }) => {\n return setCellAttr(name, value)(state, dispatch)\n },\n goToNextCell:\n () => ({ state, dispatch }) => {\n return goToNextCell(1)(state, dispatch)\n },\n goToPreviousCell:\n () => ({ state, dispatch }) => {\n return goToNextCell(-1)(state, dispatch)\n },\n fixTables:\n () => ({ state, dispatch }) => {\n if (dispatch) {\n fixTables(state)\n }\n\n return true\n },\n setCellSelection:\n position => ({ tr, dispatch }) => {\n if (dispatch) {\n const selection = CellSelection.create(tr.doc, position.anchorCell, position.headCell)\n\n // @ts-ignore\n tr.setSelection(selection)\n }\n\n return true\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n Tab: () => {\n if (this.editor.commands.goToNextCell()) {\n return true\n }\n\n if (!this.editor.can().addRowAfter()) {\n return false\n }\n\n return this.editor.chain().addRowAfter().goToNextCell().run()\n },\n 'Shift-Tab': () => this.editor.commands.goToPreviousCell(),\n Backspace: deleteTableWhenAllCellsSelected,\n 'Mod-Backspace': deleteTableWhenAllCellsSelected,\n Delete: deleteTableWhenAllCellsSelected,\n 'Mod-Delete': deleteTableWhenAllCellsSelected,\n }\n },\n\n addProseMirrorPlugins() {\n const isResizable = this.options.resizable && this.editor.isEditable\n\n return [\n ...(isResizable\n ? [\n columnResizing({\n handleWidth: this.options.handleWidth,\n cellMinWidth: this.options.cellMinWidth,\n View: this.options.View,\n lastColumnResizable: this.options.lastColumnResizable,\n }),\n ]\n : []),\n tableEditing({\n allowTableNodeSelection: this.options.allowTableNodeSelection,\n }),\n ]\n },\n\n extendNodeSchema(extension) {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n }\n\n return {\n tableRole: callOrReturn(getExtensionField(extension, 'tableRole', context)),\n }\n },\n})\n","// @ts-nocheck\nimport { Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { NodeView } from '@tiptap/pm/view'\n\nexport function updateColumns(\n node: ProseMirrorNode,\n colgroup: Element,\n table: Element,\n cellMinWidth: number,\n overrideCol?: number,\n overrideValue?: any,\n) {\n let totalWidth = 0\n let fixedWidth = true\n let nextDOM = colgroup.firstChild\n const row = node.firstChild\n\n for (let i = 0, col = 0; i < row.childCount; i += 1) {\n const { colspan, colwidth } = row.child(i).attrs\n\n for (let j = 0; j < colspan; j += 1, col += 1) {\n const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j]\n const cssWidth = hasWidth ? `${hasWidth}px` : ''\n\n totalWidth += hasWidth || cellMinWidth\n\n if (!hasWidth) {\n fixedWidth = false\n }\n\n if (!nextDOM) {\n colgroup.appendChild(document.createElement('col')).style.width = cssWidth\n } else {\n if (nextDOM.style.width !== cssWidth) {\n nextDOM.style.width = cssWidth\n }\n\n nextDOM = nextDOM.nextSibling\n }\n }\n }\n\n while (nextDOM) {\n const after = nextDOM.nextSibling\n\n nextDOM.parentNode.removeChild(nextDOM)\n nextDOM = after\n }\n\n if (fixedWidth) {\n table.style.width = `${totalWidth}px`\n table.style.minWidth = ''\n } else {\n table.style.width = ''\n table.style.minWidth = `${totalWidth}px`\n }\n}\n\nexport class TableView implements NodeView {\n node: ProseMirrorNode\n\n cellMinWidth: number\n\n dom: Element\n\n table: Element\n\n colgroup: Element\n\n contentDOM: Element\n\n constructor(node: ProseMirrorNode, cellMinWidth: number) {\n this.node = node\n this.cellMinWidth = cellMinWidth\n this.dom = document.createElement('div')\n this.dom.className = 'tableWrapper'\n this.table = this.dom.appendChild(document.createElement('table'))\n this.colgroup = this.table.appendChild(document.createElement('colgroup'))\n updateColumns(node, this.colgroup, this.table, cellMinWidth)\n this.contentDOM = this.table.appendChild(document.createElement('tbody'))\n }\n\n update(node: ProseMirrorNode) {\n if (node.type !== this.node.type) {\n return false\n }\n\n this.node = node\n updateColumns(node, this.colgroup, this.table, this.cellMinWidth)\n\n return true\n }\n\n ignoreMutation(mutation: MutationRecord | { type: 'selection'; target: Element }) {\n return (\n mutation.type === 'attributes'\n && (mutation.target === this.table || this.colgroup.contains(mutation.target))\n )\n }\n}\n","import { DOMOutputSpec, Node as ProseMirrorNode } from '@tiptap/pm/model'\n\n/**\n * Creates a colgroup element for a table node in ProseMirror.\n *\n * @param node - The ProseMirror node representing the table.\n * @param cellMinWidth - The minimum width of a cell in the table.\n * @param overrideCol - (Optional) The index of the column to override the width of.\n * @param overrideValue - (Optional) The width value to use for the overridden column.\n * @returns An object containing the colgroup element, the total width of the table, and the minimum width of the table.\n */\nexport function createColGroup(\n node: ProseMirrorNode,\n cellMinWidth: number,\n overrideCol?: number,\n overrideValue?: any,\n) {\n let totalWidth = 0\n let fixedWidth = true\n const cols: DOMOutputSpec[] = []\n const row = node.firstChild\n\n if (!row) {\n return {}\n }\n\n for (let i = 0, col = 0; i < row.childCount; i += 1) {\n const { colspan, colwidth } = row.child(i).attrs\n\n for (let j = 0; j < colspan; j += 1, col += 1) {\n const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j]\n const cssWidth = hasWidth ? `${hasWidth}px` : ''\n\n totalWidth += hasWidth || cellMinWidth\n\n if (!hasWidth) {\n fixedWidth = false\n }\n\n cols.push(['col', cssWidth ? { style: `width: ${cssWidth}` } : {}])\n }\n }\n\n const tableWidth = fixedWidth ? `${totalWidth}px` : ''\n const tableMinWidth = fixedWidth ? '' : `${totalWidth}px`\n\n const colgroup: DOMOutputSpec = ['colgroup', {}, ...cols]\n\n return { colgroup, tableWidth, tableMinWidth }\n}\n","import { Fragment, Node as ProsemirrorNode, NodeType } from '@tiptap/pm/model'\n\nexport function createCell(\n cellType: NodeType,\n cellContent?: Fragment | ProsemirrorNode | Array<ProsemirrorNode>,\n): ProsemirrorNode | null | undefined {\n if (cellContent) {\n return cellType.createChecked(null, cellContent)\n }\n\n return cellType.createAndFill()\n}\n","import { NodeType, Schema } from '@tiptap/pm/model'\n\nexport function getTableNodeTypes(schema: Schema): { [key: string]: NodeType } {\n if (schema.cached.tableNodeTypes) {\n return schema.cached.tableNodeTypes\n }\n\n const roles: { [key: string]: NodeType } = {}\n\n Object.keys(schema.nodes).forEach(type => {\n const nodeType = schema.nodes[type]\n\n if (nodeType.spec.tableRole) {\n roles[nodeType.spec.tableRole] = nodeType\n }\n })\n\n schema.cached.tableNodeTypes = roles\n\n return roles\n}\n","import { Fragment, Node as ProsemirrorNode, Schema } from '@tiptap/pm/model'\n\nimport { createCell } from './createCell.js'\nimport { getTableNodeTypes } from './getTableNodeTypes.js'\n\nexport function createTable(\n schema: Schema,\n rowsCount: number,\n colsCount: number,\n withHeaderRow: boolean,\n cellContent?: Fragment | ProsemirrorNode | Array<ProsemirrorNode>,\n): ProsemirrorNode {\n const types = getTableNodeTypes(schema)\n const headerCells: ProsemirrorNode[] = []\n const cells: ProsemirrorNode[] = []\n\n for (let index = 0; index < colsCount; index += 1) {\n const cell = createCell(types.cell, cellContent)\n\n if (cell) {\n cells.push(cell)\n }\n\n if (withHeaderRow) {\n const headerCell = createCell(types.header_cell, cellContent)\n\n if (headerCell) {\n headerCells.push(headerCell)\n }\n }\n }\n\n const rows: ProsemirrorNode[] = []\n\n for (let index = 0; index < rowsCount; index += 1) {\n rows.push(types.row.createChecked(null, withHeaderRow && index === 0 ? headerCells : cells))\n }\n\n return types.table.createChecked(null, rows)\n}\n","import { findParentNodeClosestToPos, KeyboardShortcutCommand } from '@tiptap/core'\n\nimport { isCellSelection } from './isCellSelection.js'\n\nexport const deleteTableWhenAllCellsSelected: KeyboardShortcutCommand = ({ editor }) => {\n const { selection } = editor.state\n\n if (!isCellSelection(selection)) {\n return false\n }\n\n let cellCount = 0\n const table = findParentNodeClosestToPos(selection.ranges[0].$from, node => {\n return node.type.name === 'table'\n })\n\n table?.node.descendants(node => {\n if (node.type.name === 'table') {\n return false\n }\n\n if (['tableCell', 'tableHeader'].includes(node.type.name)) {\n cellCount += 1\n }\n })\n\n const allCellsSelected = cellCount === selection.ranges.length\n\n if (!allCellsSelected) {\n return false\n }\n\n editor.commands.deleteTable()\n\n return true\n}\n","import { CellSelection } from '@tiptap/pm/tables'\n\nexport function isCellSelection(value: unknown): value is CellSelection {\n return value instanceof CellSelection\n}\n","import { Table } from './table.js'\n\nexport * from './table.js'\nexport * from './utilities/createColGroup.js'\nexport * from './utilities/createTable.js'\n\nexport default Table\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EAAc;AAAA,EAAmB;AAAA,EAAiB;AAAA,OAC7C;AAEP,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,iBAAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACnBA,SAAS,cACd,MACA,UACA,OACA,cACA,aACA,eACA;AACA,MAAI,aAAa;AACjB,MAAI,aAAa;AACjB,MAAI,UAAU,SAAS;AACvB,QAAM,MAAM,KAAK;AAEjB,WAAS,IAAI,GAAG,MAAM,GAAG,IAAI,IAAI,YAAY,KAAK,GAAG;AACnD,UAAM,EAAE,SAAS,SAAS,IAAI,IAAI,MAAM,CAAC,EAAE;AAE3C,aAAS,IAAI,GAAG,IAAI,SAAS,KAAK,GAAG,OAAO,GAAG;AAC7C,YAAM,WAAW,gBAAgB,MAAM,gBAAgB,YAAY,SAAS,CAAC;AAC7E,YAAM,WAAW,WAAW,GAAG,QAAQ,OAAO;AAE9C,oBAAc,YAAY;AAE1B,UAAI,CAAC,UAAU;AACb,qBAAa;AAAA,MACf;AAEA,UAAI,CAAC,SAAS;AACZ,iBAAS,YAAY,SAAS,cAAc,KAAK,CAAC,EAAE,MAAM,QAAQ;AAAA,MACpE,OAAO;AACL,YAAI,QAAQ,MAAM,UAAU,UAAU;AACpC,kBAAQ,MAAM,QAAQ;AAAA,QACxB;AAEA,kBAAU,QAAQ;AAAA,MACpB;AAAA,IACF;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AA,QACA,eAAe;AAAA,UACb,aAAa,KAAK,QAAQ;AAAA,UAC1B,cAAc,KAAK,QAAQ;AAAA,UAC3B,MAAM,KAAK,QAAQ;AAAA,UACnB,qBAAqB,KAAK,QAAQ;AAAA,QACpC,CAAC;AAAA,MACH,IACE,CAAC;AAAA,MACL,aAAa;AAAA,QACX,yBAAyB,KAAK,QAAQ;AAAA,MACxC,CAAC;AAAA,IACH;AAAA,EACF;AAAA,EAEA,iBAAiB,WAAW;AAC1B,UAAM,UAAU;AAAA,MACd,MAAM,UAAU;AAAA,MAChB,SAAS,UAAU;AAAA,MACnB,SAAS,UAAU;AAAA,IACrB;AAEA,WAAO;AAAA,MACL,WAAW,aAAa,kBAAkB,WAAW,aAAa,OAAO,CAAC;AAAA,IAC5E;AAAA,EACF;AACF,CAAC;;;AQjcD,IAAO,cAAQ;","names":["CellSelection","CellSelection"]}
|
|
1
|
+
{"version":3,"sources":["../src/table.ts","../src/utilities/colStyle.ts","../src/TableView.ts","../src/utilities/createColGroup.ts","../src/utilities/createCell.ts","../src/utilities/getTableNodeTypes.ts","../src/utilities/createTable.ts","../src/utilities/deleteTableWhenAllCellsSelected.ts","../src/utilities/isCellSelection.ts","../src/index.ts"],"sourcesContent":["import {\n callOrReturn, getExtensionField, mergeAttributes, Node, ParentConfig,\n} from '@tiptap/core'\nimport { DOMOutputSpec, Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { TextSelection } from '@tiptap/pm/state'\nimport {\n addColumnAfter,\n addColumnBefore,\n addRowAfter,\n addRowBefore,\n CellSelection,\n columnResizing,\n deleteColumn,\n deleteRow,\n deleteTable,\n fixTables,\n goToNextCell,\n mergeCells,\n setCellAttr,\n splitCell,\n tableEditing,\n toggleHeader,\n toggleHeaderCell,\n} from '@tiptap/pm/tables'\nimport { EditorView, NodeView } from '@tiptap/pm/view'\n\nimport { TableView } from './TableView.js'\nimport { createColGroup } from './utilities/createColGroup.js'\nimport { createTable } from './utilities/createTable.js'\nimport { deleteTableWhenAllCellsSelected } from './utilities/deleteTableWhenAllCellsSelected.js'\n\nexport interface TableOptions {\n /**\n * HTML attributes for the table element.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n\n /**\n * Enables the resizing of tables.\n * @default false\n * @example true\n */\n resizable: boolean\n\n /**\n * The width of the resize handle.\n * @default 5\n * @example 10\n */\n handleWidth: number\n\n /**\n * The minimum width of a cell.\n * @default 25\n * @example 50\n */\n cellMinWidth: number\n\n /**\n * The node view to render the table.\n * @default TableView\n */\n View: (new (node: ProseMirrorNode, cellMinWidth: number, view: EditorView) => NodeView) | null\n\n /**\n * Enables the resizing of the last column.\n * @default true\n * @example false\n */\n lastColumnResizable: boolean\n\n /**\n * Allow table node selection.\n * @default false\n * @example true\n */\n allowTableNodeSelection: boolean\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n table: {\n /**\n * Insert a table\n * @param options The table attributes\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.insertTable({ rows: 3, cols: 3, withHeaderRow: true })\n */\n insertTable: (options?: {\n rows?: number\n cols?: number\n withHeaderRow?: boolean\n }) => ReturnType\n\n /**\n * Add a column before the current column\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.addColumnBefore()\n */\n addColumnBefore: () => ReturnType\n\n /**\n * Add a column after the current column\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.addColumnAfter()\n */\n addColumnAfter: () => ReturnType\n\n /**\n * Delete the current column\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.deleteColumn()\n */\n deleteColumn: () => ReturnType\n\n /**\n * Add a row before the current row\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.addRowBefore()\n */\n addRowBefore: () => ReturnType\n\n /**\n * Add a row after the current row\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.addRowAfter()\n */\n addRowAfter: () => ReturnType\n\n /**\n * Delete the current row\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.deleteRow()\n */\n deleteRow: () => ReturnType\n\n /**\n * Delete the current table\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.deleteTable()\n */\n deleteTable: () => ReturnType\n\n /**\n * Merge the currently selected cells\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.mergeCells()\n */\n mergeCells: () => ReturnType\n\n /**\n * Split the currently selected cell\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.splitCell()\n */\n splitCell: () => ReturnType\n\n /**\n * Toggle the header column\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.toggleHeaderColumn()\n */\n toggleHeaderColumn: () => ReturnType\n\n /**\n * Toggle the header row\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.toggleHeaderRow()\n */\n toggleHeaderRow: () => ReturnType\n\n /**\n * Toggle the header cell\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.toggleHeaderCell()\n */\n toggleHeaderCell: () => ReturnType\n\n /**\n * Merge or split the currently selected cells\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.mergeOrSplit()\n */\n mergeOrSplit: () => ReturnType\n\n /**\n * Set a cell attribute\n * @param name The attribute name\n * @param value The attribute value\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.setCellAttribute('align', 'right')\n */\n setCellAttribute: (name: string, value: any) => ReturnType\n\n /**\n * Moves the selection to the next cell\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.goToNextCell()\n */\n goToNextCell: () => ReturnType\n\n /**\n * Moves the selection to the previous cell\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.goToPreviousCell()\n */\n goToPreviousCell: () => ReturnType\n\n /**\n * Try to fix the table structure if necessary\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.fixTables()\n */\n fixTables: () => ReturnType\n\n /**\n * Set a cell selection inside the current table\n * @param position The cell position\n * @returns True if the command was successful, otherwise false\n * @example editor.commands.setCellSelection({ anchorCell: 1, headCell: 2 })\n */\n setCellSelection: (position: { anchorCell: number; headCell?: number }) => ReturnType\n }\n }\n\n interface NodeConfig<Options, Storage> {\n /**\n * A string or function to determine the role of the table.\n * @default 'table'\n * @example () => 'table'\n */\n tableRole?:\n | string\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options>>['tableRole']\n }) => string)\n }\n}\n\n/**\n * This extension allows you to create tables.\n * @see https://www.tiptap.dev/api/nodes/table\n */\nexport const Table = Node.create<TableOptions>({\n name: 'table',\n\n // @ts-ignore\n addOptions() {\n return {\n HTMLAttributes: {},\n resizable: false,\n handleWidth: 5,\n cellMinWidth: 25,\n // TODO: fix\n View: TableView,\n lastColumnResizable: true,\n allowTableNodeSelection: false,\n }\n },\n\n content: 'tableRow+',\n\n tableRole: 'table',\n\n isolating: true,\n\n group: 'block',\n\n parseHTML() {\n return [{ tag: 'table' }]\n },\n\n renderHTML({ node, HTMLAttributes }) {\n const { colgroup, tableWidth, tableMinWidth } = createColGroup(\n node,\n this.options.cellMinWidth,\n )\n\n const table: DOMOutputSpec = [\n 'table',\n mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {\n style: tableWidth\n ? `width: ${tableWidth}`\n : `min-width: ${tableMinWidth}`,\n }),\n colgroup,\n ['tbody', 0],\n ]\n\n return table\n },\n\n addCommands() {\n return {\n insertTable:\n ({ rows = 3, cols = 3, withHeaderRow = true } = {}) => ({ tr, dispatch, editor }) => {\n const node = createTable(editor.schema, rows, cols, withHeaderRow)\n\n if (dispatch) {\n const offset = tr.selection.from + 1\n\n tr.replaceSelectionWith(node)\n .scrollIntoView()\n .setSelection(TextSelection.near(tr.doc.resolve(offset)))\n }\n\n return true\n },\n addColumnBefore:\n () => ({ state, dispatch }) => {\n return addColumnBefore(state, dispatch)\n },\n addColumnAfter:\n () => ({ state, dispatch }) => {\n return addColumnAfter(state, dispatch)\n },\n deleteColumn:\n () => ({ state, dispatch }) => {\n return deleteColumn(state, dispatch)\n },\n addRowBefore:\n () => ({ state, dispatch }) => {\n return addRowBefore(state, dispatch)\n },\n addRowAfter:\n () => ({ state, dispatch }) => {\n return addRowAfter(state, dispatch)\n },\n deleteRow:\n () => ({ state, dispatch }) => {\n return deleteRow(state, dispatch)\n },\n deleteTable:\n () => ({ state, dispatch }) => {\n return deleteTable(state, dispatch)\n },\n mergeCells:\n () => ({ state, dispatch }) => {\n return mergeCells(state, dispatch)\n },\n splitCell:\n () => ({ state, dispatch }) => {\n return splitCell(state, dispatch)\n },\n toggleHeaderColumn:\n () => ({ state, dispatch }) => {\n return toggleHeader('column')(state, dispatch)\n },\n toggleHeaderRow:\n () => ({ state, dispatch }) => {\n return toggleHeader('row')(state, dispatch)\n },\n toggleHeaderCell:\n () => ({ state, dispatch }) => {\n return toggleHeaderCell(state, dispatch)\n },\n mergeOrSplit:\n () => ({ state, dispatch }) => {\n if (mergeCells(state, dispatch)) {\n return true\n }\n\n return splitCell(state, dispatch)\n },\n setCellAttribute:\n (name, value) => ({ state, dispatch }) => {\n return setCellAttr(name, value)(state, dispatch)\n },\n goToNextCell:\n () => ({ state, dispatch }) => {\n return goToNextCell(1)(state, dispatch)\n },\n goToPreviousCell:\n () => ({ state, dispatch }) => {\n return goToNextCell(-1)(state, dispatch)\n },\n fixTables:\n () => ({ state, dispatch }) => {\n if (dispatch) {\n fixTables(state)\n }\n\n return true\n },\n setCellSelection:\n position => ({ tr, dispatch }) => {\n if (dispatch) {\n const selection = CellSelection.create(tr.doc, position.anchorCell, position.headCell)\n\n // @ts-ignore\n tr.setSelection(selection)\n }\n\n return true\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n Tab: () => {\n if (this.editor.commands.goToNextCell()) {\n return true\n }\n\n if (!this.editor.can().addRowAfter()) {\n return false\n }\n\n return this.editor.chain().addRowAfter().goToNextCell().run()\n },\n 'Shift-Tab': () => this.editor.commands.goToPreviousCell(),\n Backspace: deleteTableWhenAllCellsSelected,\n 'Mod-Backspace': deleteTableWhenAllCellsSelected,\n Delete: deleteTableWhenAllCellsSelected,\n 'Mod-Delete': deleteTableWhenAllCellsSelected,\n }\n },\n\n addProseMirrorPlugins() {\n const isResizable = this.options.resizable && this.editor.isEditable\n\n return [\n ...(isResizable\n ? [\n columnResizing({\n handleWidth: this.options.handleWidth,\n cellMinWidth: this.options.cellMinWidth,\n defaultCellMinWidth: this.options.cellMinWidth,\n View: this.options.View,\n lastColumnResizable: this.options.lastColumnResizable,\n }),\n ]\n : []),\n tableEditing({\n allowTableNodeSelection: this.options.allowTableNodeSelection,\n }),\n ]\n },\n\n extendNodeSchema(extension) {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n }\n\n return {\n tableRole: callOrReturn(getExtensionField(extension, 'tableRole', context)),\n }\n },\n})\n","export function getColStyleDeclaration(minWidth: number, width: number | undefined): [string, string] {\n if (width) {\n // apply the stored width unless it is below the configured minimum cell width\n return ['width', `${Math.max(width, minWidth)}px`]\n }\n\n // set the minimum with on the column if it has no stored width\n return ['min-width', `${minWidth}px`]\n\n}\n","import { Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { NodeView, ViewMutationRecord } from '@tiptap/pm/view'\n\nimport { getColStyleDeclaration } from './utilities/colStyle.js'\n\nexport function updateColumns(\n node: ProseMirrorNode,\n colgroup: HTMLTableColElement, // <colgroup> has the same prototype as <col>\n table: HTMLTableElement,\n cellMinWidth: number,\n overrideCol?: number,\n overrideValue?: number,\n) {\n let totalWidth = 0\n let fixedWidth = true\n let nextDOM = colgroup.firstChild\n const row = node.firstChild\n\n if (row !== null) {\n for (let i = 0, col = 0; i < row.childCount; i += 1) {\n const { colspan, colwidth } = row.child(i).attrs\n\n for (let j = 0; j < colspan; j += 1, col += 1) {\n const hasWidth = overrideCol === col ? overrideValue : (colwidth && colwidth[j]) as number | undefined\n const cssWidth = hasWidth ? `${hasWidth}px` : ''\n\n totalWidth += hasWidth || cellMinWidth\n\n if (!hasWidth) {\n fixedWidth = false\n }\n\n if (!nextDOM) {\n const colElement = document.createElement('col')\n\n const [propertyKey, propertyValue] = getColStyleDeclaration(cellMinWidth, hasWidth)\n\n colElement.style.setProperty(propertyKey, propertyValue)\n\n colgroup.appendChild(colElement)\n } else {\n if ((nextDOM as HTMLTableColElement).style.width !== cssWidth) {\n const [propertyKey, propertyValue] = getColStyleDeclaration(cellMinWidth, hasWidth);\n\n (nextDOM as HTMLTableColElement).style.setProperty(propertyKey, propertyValue)\n }\n\n nextDOM = nextDOM.nextSibling\n }\n }\n }\n }\n\n while (nextDOM) {\n const after = nextDOM.nextSibling\n\n nextDOM.parentNode?.removeChild(nextDOM)\n nextDOM = after\n }\n\n if (fixedWidth) {\n table.style.width = `${totalWidth}px`\n table.style.minWidth = ''\n } else {\n table.style.width = ''\n table.style.minWidth = `${totalWidth}px`\n }\n}\n\nexport class TableView implements NodeView {\n node: ProseMirrorNode\n\n cellMinWidth: number\n\n dom: HTMLDivElement\n\n table: HTMLTableElement\n\n colgroup: HTMLTableColElement\n\n contentDOM: HTMLTableSectionElement\n\n constructor(node: ProseMirrorNode, cellMinWidth: number) {\n this.node = node\n this.cellMinWidth = cellMinWidth\n this.dom = document.createElement('div')\n this.dom.className = 'tableWrapper'\n this.table = this.dom.appendChild(document.createElement('table'))\n this.colgroup = this.table.appendChild(document.createElement('colgroup'))\n updateColumns(node, this.colgroup, this.table, cellMinWidth)\n this.contentDOM = this.table.appendChild(document.createElement('tbody'))\n }\n\n update(node: ProseMirrorNode) {\n if (node.type !== this.node.type) {\n return false\n }\n\n this.node = node\n updateColumns(node, this.colgroup, this.table, this.cellMinWidth)\n\n return true\n }\n\n ignoreMutation(mutation: ViewMutationRecord) {\n return (\n mutation.type === 'attributes'\n && (mutation.target === this.table || this.colgroup.contains(mutation.target))\n )\n }\n}\n","import { DOMOutputSpec, Node as ProseMirrorNode } from '@tiptap/pm/model'\n\nimport { getColStyleDeclaration } from './colStyle.js'\n\nexport type ColGroup = {\n colgroup: DOMOutputSpec\n tableWidth: string\n tableMinWidth: string\n} | Record<string, never>;\n\n/**\n * Creates a colgroup element for a table node in ProseMirror.\n *\n * @param node - The ProseMirror node representing the table.\n * @param cellMinWidth - The minimum width of a cell in the table.\n * @param overrideCol - (Optional) The index of the column to override the width of.\n * @param overrideValue - (Optional) The width value to use for the overridden column.\n * @returns An object containing the colgroup element, the total width of the table, and the minimum width of the table.\n */\nexport function createColGroup(\n node: ProseMirrorNode,\n cellMinWidth: number,\n): ColGroup\nexport function createColGroup(\n node: ProseMirrorNode,\n cellMinWidth: number,\n overrideCol: number,\n overrideValue: number,\n): ColGroup\nexport function createColGroup(\n node: ProseMirrorNode,\n cellMinWidth: number,\n overrideCol?: number,\n overrideValue?: number,\n): ColGroup {\n let totalWidth = 0\n let fixedWidth = true\n const cols: DOMOutputSpec[] = []\n const row = node.firstChild\n\n if (!row) {\n return {}\n }\n\n for (let i = 0, col = 0; i < row.childCount; i += 1) {\n const { colspan, colwidth } = row.child(i).attrs\n\n for (let j = 0; j < colspan; j += 1, col += 1) {\n const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j] as number | undefined\n\n totalWidth += hasWidth || cellMinWidth\n\n if (!hasWidth) {\n fixedWidth = false\n }\n\n const [property, value] = getColStyleDeclaration(cellMinWidth, hasWidth)\n\n cols.push([\n 'col',\n { style: `${property}: ${value}` },\n ])\n }\n }\n\n const tableWidth = fixedWidth ? `${totalWidth}px` : ''\n const tableMinWidth = fixedWidth ? '' : `${totalWidth}px`\n\n const colgroup: DOMOutputSpec = ['colgroup', {}, ...cols]\n\n return { colgroup, tableWidth, tableMinWidth }\n}\n","import { Fragment, Node as ProsemirrorNode, NodeType } from '@tiptap/pm/model'\n\nexport function createCell(\n cellType: NodeType,\n cellContent?: Fragment | ProsemirrorNode | Array<ProsemirrorNode>,\n): ProsemirrorNode | null | undefined {\n if (cellContent) {\n return cellType.createChecked(null, cellContent)\n }\n\n return cellType.createAndFill()\n}\n","import { NodeType, Schema } from '@tiptap/pm/model'\n\nexport function getTableNodeTypes(schema: Schema): { [key: string]: NodeType } {\n if (schema.cached.tableNodeTypes) {\n return schema.cached.tableNodeTypes\n }\n\n const roles: { [key: string]: NodeType } = {}\n\n Object.keys(schema.nodes).forEach(type => {\n const nodeType = schema.nodes[type]\n\n if (nodeType.spec.tableRole) {\n roles[nodeType.spec.tableRole] = nodeType\n }\n })\n\n schema.cached.tableNodeTypes = roles\n\n return roles\n}\n","import { Fragment, Node as ProsemirrorNode, Schema } from '@tiptap/pm/model'\n\nimport { createCell } from './createCell.js'\nimport { getTableNodeTypes } from './getTableNodeTypes.js'\n\nexport function createTable(\n schema: Schema,\n rowsCount: number,\n colsCount: number,\n withHeaderRow: boolean,\n cellContent?: Fragment | ProsemirrorNode | Array<ProsemirrorNode>,\n): ProsemirrorNode {\n const types = getTableNodeTypes(schema)\n const headerCells: ProsemirrorNode[] = []\n const cells: ProsemirrorNode[] = []\n\n for (let index = 0; index < colsCount; index += 1) {\n const cell = createCell(types.cell, cellContent)\n\n if (cell) {\n cells.push(cell)\n }\n\n if (withHeaderRow) {\n const headerCell = createCell(types.header_cell, cellContent)\n\n if (headerCell) {\n headerCells.push(headerCell)\n }\n }\n }\n\n const rows: ProsemirrorNode[] = []\n\n for (let index = 0; index < rowsCount; index += 1) {\n rows.push(types.row.createChecked(null, withHeaderRow && index === 0 ? headerCells : cells))\n }\n\n return types.table.createChecked(null, rows)\n}\n","import { findParentNodeClosestToPos, KeyboardShortcutCommand } from '@tiptap/core'\n\nimport { isCellSelection } from './isCellSelection.js'\n\nexport const deleteTableWhenAllCellsSelected: KeyboardShortcutCommand = ({ editor }) => {\n const { selection } = editor.state\n\n if (!isCellSelection(selection)) {\n return false\n }\n\n let cellCount = 0\n const table = findParentNodeClosestToPos(selection.ranges[0].$from, node => {\n return node.type.name === 'table'\n })\n\n table?.node.descendants(node => {\n if (node.type.name === 'table') {\n return false\n }\n\n if (['tableCell', 'tableHeader'].includes(node.type.name)) {\n cellCount += 1\n }\n })\n\n const allCellsSelected = cellCount === selection.ranges.length\n\n if (!allCellsSelected) {\n return false\n }\n\n editor.commands.deleteTable()\n\n return true\n}\n","import { CellSelection } from '@tiptap/pm/tables'\n\nexport function isCellSelection(value: unknown): value is CellSelection {\n return value instanceof CellSelection\n}\n","import { Table } from './table.js'\n\nexport * from './table.js'\nexport * from './utilities/createColGroup.js'\nexport * from './utilities/createTable.js'\n\nexport default Table\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EAAc;AAAA,EAAmB;AAAA,EAAiB;AAAA,OAC7C;AAEP,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,iBAAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACvBA,SAAS,uBAAuB,UAAkB,OAA6C;AACpG,MAAI,OAAO;AAET,WAAO,CAAC,SAAS,GAAG,KAAK,IAAI,OAAO,QAAQ,CAAC,IAAI;AAAA,EACnD;AAGA,SAAO,CAAC,aAAa,GAAG,QAAQ,IAAI;AAEtC;;;ACJO,SAAS,cACd,MACA,UACA,OACA,cACA,aACA,eACA;AAZF;AAaE,MAAI,aAAa;AACjB,MAAI,aAAa;AACjB,MAAI,UAAU,SAAS;AACvB,QAAM,MAAM,KAAK;AAEjB,MAAI,QAAQ,MAAM;AAChB,aAAS,IAAI,GAAG,MAAM,GAAG,IAAI,IAAI,YAAY,KAAK,GAAG;AACnD,YAAM,EAAE,SAAS,SAAS,IAAI,IAAI,MAAM,CAAC,EAAE;AAE3C,eAAS,IAAI,GAAG,IAAI,SAAS,KAAK,GAAG,OAAO,GAAG;AAC7C,cAAM,WAAW,gBAAgB,MAAM,gBAAiB,YAAY,SAAS,CAAC;AAC9E,cAAM,WAAW,WAAW,GAAG,QAAQ,OAAO;AAE9C,sBAAc,YAAY;AAE1B,YAAI,CAAC,UAAU;AACb,uBAAa;AAAA,QACf;AAEA,YAAI,CAAC,SAAS;AACZ,gBAAM,aAAa,SAAS,cAAc,KAAK;A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EAAE,YAAY,GAAG;AACpC,iBAAO;AAAA,QACT;AAEA,eAAO,KAAK,OAAO,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,IAAI;AAAA,MAC9D;AAAA,MACA,aAAa,MAAM,KAAK,OAAO,SAAS,iBAAiB;AAAA,MACzD,WAAW;AAAA,MACX,iBAAiB;AAAA,MACjB,QAAQ;AAAA,MACR,cAAc;AAAA,IAChB;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,UAAM,cAAc,KAAK,QAAQ,aAAa,KAAK,OAAO;AAE1D,WAAO;AAAA,MACL,GAAI,cACA;AAAA,QACA,eAAe;AAAA,UACb,aAAa,KAAK,QAAQ;AAAA,UAC1B,cAAc,KAAK,QAAQ;AAAA,UAC3B,qBAAqB,KAAK,QAAQ;AAAA,UAClC,MAAM,KAAK,QAAQ;AAAA,UACnB,qBAAqB,KAAK,QAAQ;AAAA,QACpC,CAAC;AAAA,MACH,IACE,CAAC;AAAA,MACL,aAAa;AAAA,QACX,yBAAyB,KAAK,QAAQ;AAAA,MACxC,CAAC;AAAA,IACH;AAAA,EACF;AAAA,EAEA,iBAAiB,WAAW;AAC1B,UAAM,UAAU;AAAA,MACd,MAAM,UAAU;AAAA,MAChB,SAAS,UAAU;AAAA,MACnB,SAAS,UAAU;AAAA,IACrB;AAEA,WAAO;AAAA,MACL,WAAW,aAAa,kBAAkB,WAAW,aAAa,OAAO,CAAC;AAAA,IAC5E;AAAA,EACF;AACF,CAAC;;;ASlcD,IAAO,cAAQ;","names":["CellSelection","CellSelection"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/extension-table",
|
|
3
3
|
"description": "table extension for tiptap",
|
|
4
|
-
"version": "3.0.0-next.
|
|
4
|
+
"version": "3.0.0-next.2",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"dist"
|
|
29
29
|
],
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@tiptap/core": "^3.0.0-next.
|
|
32
|
-
"@tiptap/pm": "^3.0.0-next.
|
|
31
|
+
"@tiptap/core": "^3.0.0-next.2",
|
|
32
|
+
"@tiptap/pm": "^3.0.0-next.2"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"@tiptap/core": "^3.0.0-next.1",
|
package/src/TableView.ts
CHANGED
|
@@ -1,41 +1,52 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
1
|
import { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
3
|
-
import { NodeView } from '@tiptap/pm/view'
|
|
2
|
+
import { NodeView, ViewMutationRecord } from '@tiptap/pm/view'
|
|
3
|
+
|
|
4
|
+
import { getColStyleDeclaration } from './utilities/colStyle.js'
|
|
4
5
|
|
|
5
6
|
export function updateColumns(
|
|
6
7
|
node: ProseMirrorNode,
|
|
7
|
-
colgroup:
|
|
8
|
-
table:
|
|
8
|
+
colgroup: HTMLTableColElement, // <colgroup> has the same prototype as <col>
|
|
9
|
+
table: HTMLTableElement,
|
|
9
10
|
cellMinWidth: number,
|
|
10
11
|
overrideCol?: number,
|
|
11
|
-
overrideValue?:
|
|
12
|
+
overrideValue?: number,
|
|
12
13
|
) {
|
|
13
14
|
let totalWidth = 0
|
|
14
15
|
let fixedWidth = true
|
|
15
16
|
let nextDOM = colgroup.firstChild
|
|
16
17
|
const row = node.firstChild
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
for (let j = 0; j < colspan; j += 1, col += 1) {
|
|
22
|
-
const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j]
|
|
23
|
-
const cssWidth = hasWidth ? `${hasWidth}px` : ''
|
|
19
|
+
if (row !== null) {
|
|
20
|
+
for (let i = 0, col = 0; i < row.childCount; i += 1) {
|
|
21
|
+
const { colspan, colwidth } = row.child(i).attrs
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
for (let j = 0; j < colspan; j += 1, col += 1) {
|
|
24
|
+
const hasWidth = overrideCol === col ? overrideValue : (colwidth && colwidth[j]) as number | undefined
|
|
25
|
+
const cssWidth = hasWidth ? `${hasWidth}px` : ''
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
fixedWidth = false
|
|
29
|
-
}
|
|
27
|
+
totalWidth += hasWidth || cellMinWidth
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
} else {
|
|
34
|
-
if (nextDOM.style.width !== cssWidth) {
|
|
35
|
-
nextDOM.style.width = cssWidth
|
|
29
|
+
if (!hasWidth) {
|
|
30
|
+
fixedWidth = false
|
|
36
31
|
}
|
|
37
32
|
|
|
38
|
-
nextDOM
|
|
33
|
+
if (!nextDOM) {
|
|
34
|
+
const colElement = document.createElement('col')
|
|
35
|
+
|
|
36
|
+
const [propertyKey, propertyValue] = getColStyleDeclaration(cellMinWidth, hasWidth)
|
|
37
|
+
|
|
38
|
+
colElement.style.setProperty(propertyKey, propertyValue)
|
|
39
|
+
|
|
40
|
+
colgroup.appendChild(colElement)
|
|
41
|
+
} else {
|
|
42
|
+
if ((nextDOM as HTMLTableColElement).style.width !== cssWidth) {
|
|
43
|
+
const [propertyKey, propertyValue] = getColStyleDeclaration(cellMinWidth, hasWidth);
|
|
44
|
+
|
|
45
|
+
(nextDOM as HTMLTableColElement).style.setProperty(propertyKey, propertyValue)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
nextDOM = nextDOM.nextSibling
|
|
49
|
+
}
|
|
39
50
|
}
|
|
40
51
|
}
|
|
41
52
|
}
|
|
@@ -43,7 +54,7 @@ export function updateColumns(
|
|
|
43
54
|
while (nextDOM) {
|
|
44
55
|
const after = nextDOM.nextSibling
|
|
45
56
|
|
|
46
|
-
nextDOM.parentNode
|
|
57
|
+
nextDOM.parentNode?.removeChild(nextDOM)
|
|
47
58
|
nextDOM = after
|
|
48
59
|
}
|
|
49
60
|
|
|
@@ -61,13 +72,13 @@ export class TableView implements NodeView {
|
|
|
61
72
|
|
|
62
73
|
cellMinWidth: number
|
|
63
74
|
|
|
64
|
-
dom:
|
|
75
|
+
dom: HTMLDivElement
|
|
65
76
|
|
|
66
|
-
table:
|
|
77
|
+
table: HTMLTableElement
|
|
67
78
|
|
|
68
|
-
colgroup:
|
|
79
|
+
colgroup: HTMLTableColElement
|
|
69
80
|
|
|
70
|
-
contentDOM:
|
|
81
|
+
contentDOM: HTMLTableSectionElement
|
|
71
82
|
|
|
72
83
|
constructor(node: ProseMirrorNode, cellMinWidth: number) {
|
|
73
84
|
this.node = node
|
|
@@ -91,7 +102,7 @@ export class TableView implements NodeView {
|
|
|
91
102
|
return true
|
|
92
103
|
}
|
|
93
104
|
|
|
94
|
-
ignoreMutation(mutation:
|
|
105
|
+
ignoreMutation(mutation: ViewMutationRecord) {
|
|
95
106
|
return (
|
|
96
107
|
mutation.type === 'attributes'
|
|
97
108
|
&& (mutation.target === this.table || this.colgroup.contains(mutation.target))
|
package/src/table.ts
CHANGED
|
@@ -431,6 +431,7 @@ export const Table = Node.create<TableOptions>({
|
|
|
431
431
|
columnResizing({
|
|
432
432
|
handleWidth: this.options.handleWidth,
|
|
433
433
|
cellMinWidth: this.options.cellMinWidth,
|
|
434
|
+
defaultCellMinWidth: this.options.cellMinWidth,
|
|
434
435
|
View: this.options.View,
|
|
435
436
|
lastColumnResizable: this.options.lastColumnResizable,
|
|
436
437
|
}),
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function getColStyleDeclaration(minWidth: number, width: number | undefined): [string, string] {
|
|
2
|
+
if (width) {
|
|
3
|
+
// apply the stored width unless it is below the configured minimum cell width
|
|
4
|
+
return ['width', `${Math.max(width, minWidth)}px`]
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// set the minimum with on the column if it has no stored width
|
|
8
|
+
return ['min-width', `${minWidth}px`]
|
|
9
|
+
|
|
10
|
+
}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { DOMOutputSpec, Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
|
+
import { getColStyleDeclaration } from './colStyle.js'
|
|
4
|
+
|
|
5
|
+
export type ColGroup = {
|
|
6
|
+
colgroup: DOMOutputSpec
|
|
7
|
+
tableWidth: string
|
|
8
|
+
tableMinWidth: string
|
|
9
|
+
} | Record<string, never>;
|
|
10
|
+
|
|
3
11
|
/**
|
|
4
12
|
* Creates a colgroup element for a table node in ProseMirror.
|
|
5
13
|
*
|
|
@@ -9,12 +17,22 @@ import { DOMOutputSpec, Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
|
9
17
|
* @param overrideValue - (Optional) The width value to use for the overridden column.
|
|
10
18
|
* @returns An object containing the colgroup element, the total width of the table, and the minimum width of the table.
|
|
11
19
|
*/
|
|
20
|
+
export function createColGroup(
|
|
21
|
+
node: ProseMirrorNode,
|
|
22
|
+
cellMinWidth: number,
|
|
23
|
+
): ColGroup
|
|
24
|
+
export function createColGroup(
|
|
25
|
+
node: ProseMirrorNode,
|
|
26
|
+
cellMinWidth: number,
|
|
27
|
+
overrideCol: number,
|
|
28
|
+
overrideValue: number,
|
|
29
|
+
): ColGroup
|
|
12
30
|
export function createColGroup(
|
|
13
31
|
node: ProseMirrorNode,
|
|
14
32
|
cellMinWidth: number,
|
|
15
33
|
overrideCol?: number,
|
|
16
|
-
overrideValue?:
|
|
17
|
-
) {
|
|
34
|
+
overrideValue?: number,
|
|
35
|
+
): ColGroup {
|
|
18
36
|
let totalWidth = 0
|
|
19
37
|
let fixedWidth = true
|
|
20
38
|
const cols: DOMOutputSpec[] = []
|
|
@@ -28,8 +46,7 @@ export function createColGroup(
|
|
|
28
46
|
const { colspan, colwidth } = row.child(i).attrs
|
|
29
47
|
|
|
30
48
|
for (let j = 0; j < colspan; j += 1, col += 1) {
|
|
31
|
-
const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j]
|
|
32
|
-
const cssWidth = hasWidth ? `${hasWidth}px` : ''
|
|
49
|
+
const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j] as number | undefined
|
|
33
50
|
|
|
34
51
|
totalWidth += hasWidth || cellMinWidth
|
|
35
52
|
|
|
@@ -37,7 +54,12 @@ export function createColGroup(
|
|
|
37
54
|
fixedWidth = false
|
|
38
55
|
}
|
|
39
56
|
|
|
40
|
-
|
|
57
|
+
const [property, value] = getColStyleDeclaration(cellMinWidth, hasWidth)
|
|
58
|
+
|
|
59
|
+
cols.push([
|
|
60
|
+
'col',
|
|
61
|
+
{ style: `${property}: ${value}` },
|
|
62
|
+
])
|
|
41
63
|
}
|
|
42
64
|
}
|
|
43
65
|
|