@tiptap/extension-table 3.0.0-next.2 → 3.0.0-next.4

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.
Files changed (57) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +5 -1
  3. package/dist/cell/index.cjs +68 -0
  4. package/dist/cell/index.cjs.map +1 -0
  5. package/dist/cell/index.d.cts +17 -0
  6. package/dist/cell/index.d.ts +17 -0
  7. package/dist/cell/index.js +41 -0
  8. package/dist/cell/index.js.map +1 -0
  9. package/dist/header/index.cjs +68 -0
  10. package/dist/header/index.cjs.map +1 -0
  11. package/dist/header/index.d.cts +17 -0
  12. package/dist/header/index.d.ts +17 -0
  13. package/dist/header/index.js +41 -0
  14. package/dist/header/index.js.map +1 -0
  15. package/dist/index.cjs +148 -31
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +79 -8
  18. package/dist/index.d.ts +79 -8
  19. package/dist/index.js +139 -31
  20. package/dist/index.js.map +1 -1
  21. package/dist/kit/index.cjs +497 -0
  22. package/dist/kit/index.cjs.map +1 -0
  23. package/dist/kit/index.d.cts +249 -0
  24. package/dist/kit/index.d.ts +249 -0
  25. package/dist/kit/index.js +490 -0
  26. package/dist/kit/index.js.map +1 -0
  27. package/dist/row/index.cjs +49 -0
  28. package/dist/row/index.cjs.map +1 -0
  29. package/dist/row/index.d.cts +17 -0
  30. package/dist/row/index.d.ts +17 -0
  31. package/dist/row/index.js +22 -0
  32. package/dist/row/index.js.map +1 -0
  33. package/dist/table/index.cjs +384 -0
  34. package/dist/table/index.cjs.map +1 -0
  35. package/dist/table/index.d.cts +217 -0
  36. package/dist/table/index.d.ts +217 -0
  37. package/dist/table/index.js +373 -0
  38. package/dist/table/index.js.map +1 -0
  39. package/package.json +50 -6
  40. package/src/cell/index.ts +1 -0
  41. package/src/cell/table-cell.ts +58 -0
  42. package/src/header/index.ts +1 -0
  43. package/src/header/table-header.ts +58 -0
  44. package/src/index.ts +5 -7
  45. package/src/kit/index.ts +60 -0
  46. package/src/row/index.ts +1 -0
  47. package/src/row/table-row.ts +36 -0
  48. package/src/{TableView.ts → table/TableView.ts} +4 -7
  49. package/src/table/index.ts +3 -0
  50. package/src/{table.ts → table/table.ts} +55 -47
  51. package/src/{utilities → table/utilities}/colStyle.ts +0 -1
  52. package/src/{utilities → table/utilities}/createColGroup.ts +10 -14
  53. /package/src/{utilities → table/utilities}/createCell.ts +0 -0
  54. /package/src/{utilities → table/utilities}/createTable.ts +0 -0
  55. /package/src/{utilities → table/utilities}/deleteTableWhenAllCellsSelected.ts +0 -0
  56. /package/src/{utilities → table/utilities}/getTableNodeTypes.ts +0 -0
  57. /package/src/{utilities → table/utilities}/isCellSelection.ts +0 -0
@@ -1 +1 @@
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;AAE1B,YAAI,CAAC,UAAU;AACb,uBAAa;AAAA,QACf;AAEA,YAAI,CAAC,SAAS;AACZ,gBAAM,aAAa,SAAS,cAAc,KAAK;AAE/C,gBAAM,CAAC,aAAa,aAAa,IAAI,uBAAuB,cAAc,QAAQ;AAElF,qBAAW,MAAM,YAAY,aAAa,aAAa;AAEvD,mBAAS,YAAY,UAAU;AAAA,QACjC,OAAO;AACL,cAAK,QAAgC,MAAM,UAAU,UAAU;AAC7D,kBAAM,CAAC,aAAa,aAAa,IAAI,uBAAuB,cAAc,QAAQ;AAElF,YAAC,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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"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/cell/table-cell.ts","../src/header/table-header.ts","../src/kit/index.ts","../src/row/table-row.ts","../src/table/table.ts","../src/table/utilities/colStyle.ts","../src/table/TableView.ts","../src/table/utilities/createColGroup.ts","../src/table/utilities/createCell.ts","../src/table/utilities/getTableNodeTypes.ts","../src/table/utilities/createTable.ts","../src/table/utilities/deleteTableWhenAllCellsSelected.ts","../src/table/utilities/isCellSelection.ts"],"sourcesContent":["export * from './cell/index.js'\nexport * from './header/index.js'\nexport * from './kit/index.js'\nexport * from './row/index.js'\nexport * from './table/index.js'\n","import { mergeAttributes, Node } from '@tiptap/core'\n\nexport interface TableCellOptions {\n /**\n * The HTML attributes for a table cell node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n}\n\n/**\n * This extension allows you to create table cells.\n * @see https://www.tiptap.dev/api/nodes/table-cell\n */\nexport const TableCell = Node.create<TableCellOptions>({\n name: 'tableCell',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n }\n },\n\n content: 'block+',\n\n addAttributes() {\n return {\n colspan: {\n default: 1,\n },\n rowspan: {\n default: 1,\n },\n colwidth: {\n default: null,\n parseHTML: element => {\n const colwidth = element.getAttribute('colwidth')\n const value = colwidth ? colwidth.split(',').map(width => parseInt(width, 10)) : null\n\n return value\n },\n },\n }\n },\n\n tableRole: 'cell',\n\n isolating: true,\n\n parseHTML() {\n return [{ tag: 'td' }]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['td', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n})\n","import { mergeAttributes, Node } from '@tiptap/core'\n\nexport interface TableHeaderOptions {\n /**\n * The HTML attributes for a table header node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n}\n\n/**\n * This extension allows you to create table headers.\n * @see https://www.tiptap.dev/api/nodes/table-header\n */\nexport const TableHeader = Node.create<TableHeaderOptions>({\n name: 'tableHeader',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n }\n },\n\n content: 'block+',\n\n addAttributes() {\n return {\n colspan: {\n default: 1,\n },\n rowspan: {\n default: 1,\n },\n colwidth: {\n default: null,\n parseHTML: element => {\n const colwidth = element.getAttribute('colwidth')\n const value = colwidth ? colwidth.split(',').map(width => parseInt(width, 10)) : null\n\n return value\n },\n },\n }\n },\n\n tableRole: 'header_cell',\n\n isolating: true,\n\n parseHTML() {\n return [{ tag: 'th' }]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['th', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n})\n","import { Extension } from '@tiptap/core'\n\nimport { TableCell, TableCellOptions } from '../cell/index.js'\nimport { TableHeader, TableHeaderOptions } from '../header/index.js'\nimport { TableRow, TableRowOptions } from '../row/index.js'\nimport { Table, TableOptions } from '../table/index.js'\n\nexport interface TableKitOptions {\n /**\n * If set to false, the table extension will not be registered\n * @example table: false\n */\n table: Partial<TableOptions> | false\n /**\n * If set to false, the table extension will not be registered\n * @example tableCell: false\n */\n tableCell: Partial<TableCellOptions> | false\n /**\n * If set to false, the table extension will not be registered\n * @example tableHeader: false\n */\n tableHeader: Partial<TableHeaderOptions> | false\n /**\n * If set to false, the table extension will not be registered\n * @example tableRow: false\n */\n tableRow: Partial<TableRowOptions> | false\n}\n\n/**\n * The table kit is a collection of table editor extensions.\n *\n * It’s a good starting point for building your own table in Tiptap.\n */\nexport const TableKit = Extension.create<TableKitOptions>({\n name: 'tableKit',\n\n addExtensions() {\n const extensions = []\n\n if (this.options.table !== false) {\n extensions.push(Table.configure(this.options.table))\n }\n\n if (this.options.tableCell !== false) {\n extensions.push(TableCell.configure(this.options.tableCell))\n }\n\n if (this.options.tableHeader !== false) {\n extensions.push(TableHeader.configure(this.options.tableHeader))\n }\n\n if (this.options.tableRow !== false) {\n extensions.push(TableRow.configure(this.options.tableRow))\n }\n\n return extensions\n },\n})\n","import { mergeAttributes, Node } from '@tiptap/core'\n\nexport interface TableRowOptions {\n /**\n * The HTML attributes for a table row node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n}\n\n/**\n * This extension allows you to create table rows.\n * @see https://www.tiptap.dev/api/nodes/table-row\n */\nexport const TableRow = Node.create<TableRowOptions>({\n name: 'tableRow',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n }\n },\n\n content: '(tableCell | tableHeader)*',\n\n tableRole: 'row',\n\n parseHTML() {\n return [{ tag: 'tr' }]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['tr', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n})\n","import { callOrReturn, getExtensionField, mergeAttributes, Node, ParentConfig } 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?: { rows?: number; cols?: number; withHeaderRow?: boolean }) => 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(node, this.options.cellMinWidth)\n\n const table: DOMOutputSpec = [\n 'table',\n mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {\n style: tableWidth ? `width: ${tableWidth}` : `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 } = {}) =>\n ({ 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 () =>\n ({ state, dispatch }) => {\n return addColumnBefore(state, dispatch)\n },\n addColumnAfter:\n () =>\n ({ state, dispatch }) => {\n return addColumnAfter(state, dispatch)\n },\n deleteColumn:\n () =>\n ({ state, dispatch }) => {\n return deleteColumn(state, dispatch)\n },\n addRowBefore:\n () =>\n ({ state, dispatch }) => {\n return addRowBefore(state, dispatch)\n },\n addRowAfter:\n () =>\n ({ state, dispatch }) => {\n return addRowAfter(state, dispatch)\n },\n deleteRow:\n () =>\n ({ state, dispatch }) => {\n return deleteRow(state, dispatch)\n },\n deleteTable:\n () =>\n ({ state, dispatch }) => {\n return deleteTable(state, dispatch)\n },\n mergeCells:\n () =>\n ({ state, dispatch }) => {\n return mergeCells(state, dispatch)\n },\n splitCell:\n () =>\n ({ state, dispatch }) => {\n return splitCell(state, dispatch)\n },\n toggleHeaderColumn:\n () =>\n ({ state, dispatch }) => {\n return toggleHeader('column')(state, dispatch)\n },\n toggleHeaderRow:\n () =>\n ({ state, dispatch }) => {\n return toggleHeader('row')(state, dispatch)\n },\n toggleHeaderCell:\n () =>\n ({ state, dispatch }) => {\n return toggleHeaderCell(state, dispatch)\n },\n mergeOrSplit:\n () =>\n ({ state, dispatch }) => {\n if (mergeCells(state, dispatch)) {\n return true\n }\n\n return splitCell(state, dispatch)\n },\n setCellAttribute:\n (name, value) =>\n ({ state, dispatch }) => {\n return setCellAttr(name, value)(state, dispatch)\n },\n goToNextCell:\n () =>\n ({ state, dispatch }) => {\n return goToNextCell(1)(state, dispatch)\n },\n goToPreviousCell:\n () =>\n ({ state, dispatch }) => {\n return goToNextCell(-1)(state, dispatch)\n },\n fixTables:\n () =>\n ({ state, dispatch }) => {\n if (dispatch) {\n fixTables(state)\n }\n\n return true\n },\n setCellSelection:\n position =>\n ({ 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","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 mutation.type === 'attributes' && (mutation.target === this.table || this.colgroup.contains(mutation.target))\n }\n}\n","import { DOMOutputSpec, Node as ProseMirrorNode } from '@tiptap/pm/model'\n\nimport { getColStyleDeclaration } from './colStyle.js'\n\nexport type ColGroup =\n | {\n colgroup: DOMOutputSpec\n tableWidth: string\n tableMinWidth: string\n }\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(node: ProseMirrorNode, cellMinWidth: number): 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(['col', { style: `${property}: ${value}` }])\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;AAAA;AAAA;AAAA;;;ACAA,kBAAsC;AAe/B,IAAM,YAAY,iBAAK,OAAyB;AAAA,EACrD,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,gBAAgB,CAAC;AAAA,IACnB;AAAA,EACF;AAAA,EAEA,SAAS;AAAA,EAET,gBAAgB;AACd,WAAO;AAAA,MACL,SAAS;AAAA,QACP,SAAS;AAAA,MACX;AAAA,MACA,SAAS;AAAA,QACP,SAAS;AAAA,MACX;AAAA,MACA,UAAU;AAAA,QACR,SAAS;AAAA,QACT,WAAW,aAAW;AACpB,gBAAM,WAAW,QAAQ,aAAa,UAAU;AAChD,gBAAM,QAAQ,WAAW,SAAS,MAAM,GAAG,EAAE,IAAI,WAAS,SAAS,OAAO,EAAE,CAAC,IAAI;AAEjF,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,WAAW;AAAA,EAEX,WAAW;AAAA,EAEX,YAAY;AACV,WAAO,CAAC,EAAE,KAAK,KAAK,CAAC;AAAA,EACvB;AAAA,EAEA,WAAW,EAAE,eAAe,GAAG;AAC7B,WAAO,CAAC,UA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AAA,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,IACA,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;;;AF7aM,IAAM,WAAW,uBAAU,OAAwB;AAAA,EACxD,MAAM;AAAA,EAEN,gBAAgB;AACd,UAAM,aAAa,CAAC;AAEpB,QAAI,KAAK,QAAQ,UAAU,OAAO;AAChC,iBAAW,KAAK,MAAM,UAAU,KAAK,QAAQ,KAAK,CAAC;AAAA,IACrD;AAEA,QAAI,KAAK,QAAQ,cAAc,OAAO;AACpC,iBAAW,KAAK,UAAU,UAAU,KAAK,QAAQ,SAAS,CAAC;AAAA,IAC7D;AAEA,QAAI,KAAK,QAAQ,gBAAgB,OAAO;AACtC,iBAAW,KAAK,YAAY,UAAU,KAAK,QAAQ,WAAW,CAAC;AAAA,IACjE;AAEA,QAAI,KAAK,QAAQ,aAAa,OAAO;AACnC,iBAAW,KAAK,SAAS,UAAU,KAAK,QAAQ,QAAQ,CAAC;AAAA,IAC3D;AAEA,WAAO;AAAA,EACT;AACF,CAAC;","names":["import_core","import_core","import_core","import_core","import_tables","import_core"]}
package/dist/index.d.cts CHANGED
@@ -1,7 +1,49 @@
1
- import { ParentConfig, Node as Node$1 } from '@tiptap/core';
2
- import { Node, DOMOutputSpec, Schema, Fragment } from '@tiptap/pm/model';
1
+ import { Node, ParentConfig, Extension } from '@tiptap/core';
2
+ import { Node as Node$1, DOMOutputSpec, Schema, Fragment } from '@tiptap/pm/model';
3
3
  import { EditorView, NodeView } from '@tiptap/pm/view';
4
4
 
5
+ interface TableCellOptions {
6
+ /**
7
+ * The HTML attributes for a table cell node.
8
+ * @default {}
9
+ * @example { class: 'foo' }
10
+ */
11
+ HTMLAttributes: Record<string, any>;
12
+ }
13
+ /**
14
+ * This extension allows you to create table cells.
15
+ * @see https://www.tiptap.dev/api/nodes/table-cell
16
+ */
17
+ declare const TableCell: Node<TableCellOptions, any>;
18
+
19
+ interface TableHeaderOptions {
20
+ /**
21
+ * The HTML attributes for a table header node.
22
+ * @default {}
23
+ * @example { class: 'foo' }
24
+ */
25
+ HTMLAttributes: Record<string, any>;
26
+ }
27
+ /**
28
+ * This extension allows you to create table headers.
29
+ * @see https://www.tiptap.dev/api/nodes/table-header
30
+ */
31
+ declare const TableHeader: Node<TableHeaderOptions, any>;
32
+
33
+ interface TableRowOptions {
34
+ /**
35
+ * The HTML attributes for a table row node.
36
+ * @default {}
37
+ * @example { class: 'foo' }
38
+ */
39
+ HTMLAttributes: Record<string, any>;
40
+ }
41
+ /**
42
+ * This extension allows you to create table rows.
43
+ * @see https://www.tiptap.dev/api/nodes/table-row
44
+ */
45
+ declare const TableRow: Node<TableRowOptions, any>;
46
+
5
47
  interface TableOptions {
6
48
  /**
7
49
  * HTML attributes for the table element.
@@ -31,7 +73,7 @@ interface TableOptions {
31
73
  * The node view to render the table.
32
74
  * @default TableView
33
75
  */
34
- View: (new (node: Node, cellMinWidth: number, view: EditorView) => NodeView) | null;
76
+ View: (new (node: Node$1, cellMinWidth: number, view: EditorView) => NodeView) | null;
35
77
  /**
36
78
  * Enables the resizing of the last column.
37
79
  * @default true
@@ -193,7 +235,7 @@ declare module '@tiptap/core' {
193
235
  * This extension allows you to create tables.
194
236
  * @see https://www.tiptap.dev/api/nodes/table
195
237
  */
196
- declare const Table: Node$1<TableOptions, any>;
238
+ declare const Table: Node<TableOptions, any>;
197
239
 
198
240
  type ColGroup = {
199
241
  colgroup: DOMOutputSpec;
@@ -209,9 +251,38 @@ type ColGroup = {
209
251
  * @param overrideValue - (Optional) The width value to use for the overridden column.
210
252
  * @returns An object containing the colgroup element, the total width of the table, and the minimum width of the table.
211
253
  */
212
- declare function createColGroup(node: Node, cellMinWidth: number): ColGroup;
213
- declare function createColGroup(node: Node, cellMinWidth: number, overrideCol: number, overrideValue: number): ColGroup;
254
+ declare function createColGroup(node: Node$1, cellMinWidth: number): ColGroup;
255
+ declare function createColGroup(node: Node$1, cellMinWidth: number, overrideCol: number, overrideValue: number): ColGroup;
256
+
257
+ declare function createTable(schema: Schema, rowsCount: number, colsCount: number, withHeaderRow: boolean, cellContent?: Fragment | Node$1 | Array<Node$1>): Node$1;
214
258
 
215
- declare function createTable(schema: Schema, rowsCount: number, colsCount: number, withHeaderRow: boolean, cellContent?: Fragment | Node | Array<Node>): Node;
259
+ interface TableKitOptions {
260
+ /**
261
+ * If set to false, the table extension will not be registered
262
+ * @example table: false
263
+ */
264
+ table: Partial<TableOptions> | false;
265
+ /**
266
+ * If set to false, the table extension will not be registered
267
+ * @example tableCell: false
268
+ */
269
+ tableCell: Partial<TableCellOptions> | false;
270
+ /**
271
+ * If set to false, the table extension will not be registered
272
+ * @example tableHeader: false
273
+ */
274
+ tableHeader: Partial<TableHeaderOptions> | false;
275
+ /**
276
+ * If set to false, the table extension will not be registered
277
+ * @example tableRow: false
278
+ */
279
+ tableRow: Partial<TableRowOptions> | false;
280
+ }
281
+ /**
282
+ * The table kit is a collection of table editor extensions.
283
+ *
284
+ * It’s a good starting point for building your own table in Tiptap.
285
+ */
286
+ declare const TableKit: Extension<TableKitOptions, any>;
216
287
 
217
- export { type ColGroup, Table, type TableOptions, createColGroup, createTable, Table as default };
288
+ export { type ColGroup, Table, TableCell, type TableCellOptions, TableHeader, type TableHeaderOptions, TableKit, type TableKitOptions, type TableOptions, TableRow, type TableRowOptions, createColGroup, createTable };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,49 @@
1
- import { ParentConfig, Node as Node$1 } from '@tiptap/core';
2
- import { Node, DOMOutputSpec, Schema, Fragment } from '@tiptap/pm/model';
1
+ import { Node, ParentConfig, Extension } from '@tiptap/core';
2
+ import { Node as Node$1, DOMOutputSpec, Schema, Fragment } from '@tiptap/pm/model';
3
3
  import { EditorView, NodeView } from '@tiptap/pm/view';
4
4
 
5
+ interface TableCellOptions {
6
+ /**
7
+ * The HTML attributes for a table cell node.
8
+ * @default {}
9
+ * @example { class: 'foo' }
10
+ */
11
+ HTMLAttributes: Record<string, any>;
12
+ }
13
+ /**
14
+ * This extension allows you to create table cells.
15
+ * @see https://www.tiptap.dev/api/nodes/table-cell
16
+ */
17
+ declare const TableCell: Node<TableCellOptions, any>;
18
+
19
+ interface TableHeaderOptions {
20
+ /**
21
+ * The HTML attributes for a table header node.
22
+ * @default {}
23
+ * @example { class: 'foo' }
24
+ */
25
+ HTMLAttributes: Record<string, any>;
26
+ }
27
+ /**
28
+ * This extension allows you to create table headers.
29
+ * @see https://www.tiptap.dev/api/nodes/table-header
30
+ */
31
+ declare const TableHeader: Node<TableHeaderOptions, any>;
32
+
33
+ interface TableRowOptions {
34
+ /**
35
+ * The HTML attributes for a table row node.
36
+ * @default {}
37
+ * @example { class: 'foo' }
38
+ */
39
+ HTMLAttributes: Record<string, any>;
40
+ }
41
+ /**
42
+ * This extension allows you to create table rows.
43
+ * @see https://www.tiptap.dev/api/nodes/table-row
44
+ */
45
+ declare const TableRow: Node<TableRowOptions, any>;
46
+
5
47
  interface TableOptions {
6
48
  /**
7
49
  * HTML attributes for the table element.
@@ -31,7 +73,7 @@ interface TableOptions {
31
73
  * The node view to render the table.
32
74
  * @default TableView
33
75
  */
34
- View: (new (node: Node, cellMinWidth: number, view: EditorView) => NodeView) | null;
76
+ View: (new (node: Node$1, cellMinWidth: number, view: EditorView) => NodeView) | null;
35
77
  /**
36
78
  * Enables the resizing of the last column.
37
79
  * @default true
@@ -193,7 +235,7 @@ declare module '@tiptap/core' {
193
235
  * This extension allows you to create tables.
194
236
  * @see https://www.tiptap.dev/api/nodes/table
195
237
  */
196
- declare const Table: Node$1<TableOptions, any>;
238
+ declare const Table: Node<TableOptions, any>;
197
239
 
198
240
  type ColGroup = {
199
241
  colgroup: DOMOutputSpec;
@@ -209,9 +251,38 @@ type ColGroup = {
209
251
  * @param overrideValue - (Optional) The width value to use for the overridden column.
210
252
  * @returns An object containing the colgroup element, the total width of the table, and the minimum width of the table.
211
253
  */
212
- declare function createColGroup(node: Node, cellMinWidth: number): ColGroup;
213
- declare function createColGroup(node: Node, cellMinWidth: number, overrideCol: number, overrideValue: number): ColGroup;
254
+ declare function createColGroup(node: Node$1, cellMinWidth: number): ColGroup;
255
+ declare function createColGroup(node: Node$1, cellMinWidth: number, overrideCol: number, overrideValue: number): ColGroup;
256
+
257
+ declare function createTable(schema: Schema, rowsCount: number, colsCount: number, withHeaderRow: boolean, cellContent?: Fragment | Node$1 | Array<Node$1>): Node$1;
214
258
 
215
- declare function createTable(schema: Schema, rowsCount: number, colsCount: number, withHeaderRow: boolean, cellContent?: Fragment | Node | Array<Node>): Node;
259
+ interface TableKitOptions {
260
+ /**
261
+ * If set to false, the table extension will not be registered
262
+ * @example table: false
263
+ */
264
+ table: Partial<TableOptions> | false;
265
+ /**
266
+ * If set to false, the table extension will not be registered
267
+ * @example tableCell: false
268
+ */
269
+ tableCell: Partial<TableCellOptions> | false;
270
+ /**
271
+ * If set to false, the table extension will not be registered
272
+ * @example tableHeader: false
273
+ */
274
+ tableHeader: Partial<TableHeaderOptions> | false;
275
+ /**
276
+ * If set to false, the table extension will not be registered
277
+ * @example tableRow: false
278
+ */
279
+ tableRow: Partial<TableRowOptions> | false;
280
+ }
281
+ /**
282
+ * The table kit is a collection of table editor extensions.
283
+ *
284
+ * It’s a good starting point for building your own table in Tiptap.
285
+ */
286
+ declare const TableKit: Extension<TableKitOptions, any>;
216
287
 
217
- export { type ColGroup, Table, type TableOptions, createColGroup, createTable, Table as default };
288
+ export { type ColGroup, Table, TableCell, type TableCellOptions, TableHeader, type TableHeaderOptions, TableKit, type TableKitOptions, type TableOptions, TableRow, type TableRowOptions, createColGroup, createTable };
package/dist/index.js CHANGED
@@ -1,10 +1,103 @@
1
- // src/table.ts
2
- import {
3
- callOrReturn,
4
- getExtensionField,
5
- mergeAttributes,
6
- Node
7
- } from "@tiptap/core";
1
+ // src/cell/table-cell.ts
2
+ import { mergeAttributes, Node } from "@tiptap/core";
3
+ var TableCell = Node.create({
4
+ name: "tableCell",
5
+ addOptions() {
6
+ return {
7
+ HTMLAttributes: {}
8
+ };
9
+ },
10
+ content: "block+",
11
+ addAttributes() {
12
+ return {
13
+ colspan: {
14
+ default: 1
15
+ },
16
+ rowspan: {
17
+ default: 1
18
+ },
19
+ colwidth: {
20
+ default: null,
21
+ parseHTML: (element) => {
22
+ const colwidth = element.getAttribute("colwidth");
23
+ const value = colwidth ? colwidth.split(",").map((width) => parseInt(width, 10)) : null;
24
+ return value;
25
+ }
26
+ }
27
+ };
28
+ },
29
+ tableRole: "cell",
30
+ isolating: true,
31
+ parseHTML() {
32
+ return [{ tag: "td" }];
33
+ },
34
+ renderHTML({ HTMLAttributes }) {
35
+ return ["td", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
36
+ }
37
+ });
38
+
39
+ // src/header/table-header.ts
40
+ import { mergeAttributes as mergeAttributes2, Node as Node2 } from "@tiptap/core";
41
+ var TableHeader = Node2.create({
42
+ name: "tableHeader",
43
+ addOptions() {
44
+ return {
45
+ HTMLAttributes: {}
46
+ };
47
+ },
48
+ content: "block+",
49
+ addAttributes() {
50
+ return {
51
+ colspan: {
52
+ default: 1
53
+ },
54
+ rowspan: {
55
+ default: 1
56
+ },
57
+ colwidth: {
58
+ default: null,
59
+ parseHTML: (element) => {
60
+ const colwidth = element.getAttribute("colwidth");
61
+ const value = colwidth ? colwidth.split(",").map((width) => parseInt(width, 10)) : null;
62
+ return value;
63
+ }
64
+ }
65
+ };
66
+ },
67
+ tableRole: "header_cell",
68
+ isolating: true,
69
+ parseHTML() {
70
+ return [{ tag: "th" }];
71
+ },
72
+ renderHTML({ HTMLAttributes }) {
73
+ return ["th", mergeAttributes2(this.options.HTMLAttributes, HTMLAttributes), 0];
74
+ }
75
+ });
76
+
77
+ // src/kit/index.ts
78
+ import { Extension } from "@tiptap/core";
79
+
80
+ // src/row/table-row.ts
81
+ import { mergeAttributes as mergeAttributes3, Node as Node3 } from "@tiptap/core";
82
+ var TableRow = Node3.create({
83
+ name: "tableRow",
84
+ addOptions() {
85
+ return {
86
+ HTMLAttributes: {}
87
+ };
88
+ },
89
+ content: "(tableCell | tableHeader)*",
90
+ tableRole: "row",
91
+ parseHTML() {
92
+ return [{ tag: "tr" }];
93
+ },
94
+ renderHTML({ HTMLAttributes }) {
95
+ return ["tr", mergeAttributes3(this.options.HTMLAttributes, HTMLAttributes), 0];
96
+ }
97
+ });
98
+
99
+ // src/table/table.ts
100
+ import { callOrReturn, getExtensionField, mergeAttributes as mergeAttributes4, Node as Node4 } from "@tiptap/core";
8
101
  import { TextSelection } from "@tiptap/pm/state";
9
102
  import {
10
103
  addColumnAfter,
@@ -26,7 +119,7 @@ import {
26
119
  toggleHeaderCell
27
120
  } from "@tiptap/pm/tables";
28
121
 
29
- // src/utilities/colStyle.ts
122
+ // src/table/utilities/colStyle.ts
30
123
  function getColStyleDeclaration(minWidth, width) {
31
124
  if (width) {
32
125
  return ["width", `${Math.max(width, minWidth)}px`];
@@ -34,7 +127,7 @@ function getColStyleDeclaration(minWidth, width) {
34
127
  return ["min-width", `${minWidth}px`];
35
128
  }
36
129
 
37
- // src/TableView.ts
130
+ // src/table/TableView.ts
38
131
  function updateColumns(node, colgroup, table, cellMinWidth, overrideCol, overrideValue) {
39
132
  var _a;
40
133
  let totalWidth = 0;
@@ -103,7 +196,7 @@ var TableView = class {
103
196
  }
104
197
  };
105
198
 
106
- // src/utilities/createColGroup.ts
199
+ // src/table/utilities/createColGroup.ts
107
200
  function createColGroup(node, cellMinWidth, overrideCol, overrideValue) {
108
201
  let totalWidth = 0;
109
202
  let fixedWidth = true;
@@ -121,10 +214,7 @@ function createColGroup(node, cellMinWidth, overrideCol, overrideValue) {
121
214
  fixedWidth = false;
122
215
  }
123
216
  const [property, value] = getColStyleDeclaration(cellMinWidth, hasWidth);
124
- cols.push([
125
- "col",
126
- { style: `${property}: ${value}` }
127
- ]);
217
+ cols.push(["col", { style: `${property}: ${value}` }]);
128
218
  }
129
219
  }
130
220
  const tableWidth = fixedWidth ? `${totalWidth}px` : "";
@@ -133,7 +223,7 @@ function createColGroup(node, cellMinWidth, overrideCol, overrideValue) {
133
223
  return { colgroup, tableWidth, tableMinWidth };
134
224
  }
135
225
 
136
- // src/utilities/createCell.ts
226
+ // src/table/utilities/createCell.ts
137
227
  function createCell(cellType, cellContent) {
138
228
  if (cellContent) {
139
229
  return cellType.createChecked(null, cellContent);
@@ -141,7 +231,7 @@ function createCell(cellType, cellContent) {
141
231
  return cellType.createAndFill();
142
232
  }
143
233
 
144
- // src/utilities/getTableNodeTypes.ts
234
+ // src/table/utilities/getTableNodeTypes.ts
145
235
  function getTableNodeTypes(schema) {
146
236
  if (schema.cached.tableNodeTypes) {
147
237
  return schema.cached.tableNodeTypes;
@@ -157,7 +247,7 @@ function getTableNodeTypes(schema) {
157
247
  return roles;
158
248
  }
159
249
 
160
- // src/utilities/createTable.ts
250
+ // src/table/utilities/createTable.ts
161
251
  function createTable(schema, rowsCount, colsCount, withHeaderRow, cellContent) {
162
252
  const types = getTableNodeTypes(schema);
163
253
  const headerCells = [];
@@ -181,16 +271,16 @@ function createTable(schema, rowsCount, colsCount, withHeaderRow, cellContent) {
181
271
  return types.table.createChecked(null, rows);
182
272
  }
183
273
 
184
- // src/utilities/deleteTableWhenAllCellsSelected.ts
274
+ // src/table/utilities/deleteTableWhenAllCellsSelected.ts
185
275
  import { findParentNodeClosestToPos } from "@tiptap/core";
186
276
 
187
- // src/utilities/isCellSelection.ts
277
+ // src/table/utilities/isCellSelection.ts
188
278
  import { CellSelection } from "@tiptap/pm/tables";
189
279
  function isCellSelection(value) {
190
280
  return value instanceof CellSelection;
191
281
  }
192
282
 
193
- // src/utilities/deleteTableWhenAllCellsSelected.ts
283
+ // src/table/utilities/deleteTableWhenAllCellsSelected.ts
194
284
  var deleteTableWhenAllCellsSelected = ({ editor }) => {
195
285
  const { selection } = editor.state;
196
286
  if (!isCellSelection(selection)) {
@@ -216,8 +306,8 @@ var deleteTableWhenAllCellsSelected = ({ editor }) => {
216
306
  return true;
217
307
  };
218
308
 
219
- // src/table.ts
220
- var Table = Node.create({
309
+ // src/table/table.ts
310
+ var Table = Node4.create({
221
311
  name: "table",
222
312
  // @ts-ignore
223
313
  addOptions() {
@@ -240,13 +330,10 @@ var Table = Node.create({
240
330
  return [{ tag: "table" }];
241
331
  },
242
332
  renderHTML({ node, HTMLAttributes }) {
243
- const { colgroup, tableWidth, tableMinWidth } = createColGroup(
244
- node,
245
- this.options.cellMinWidth
246
- );
333
+ const { colgroup, tableWidth, tableMinWidth } = createColGroup(node, this.options.cellMinWidth);
247
334
  const table = [
248
335
  "table",
249
- mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
336
+ mergeAttributes4(this.options.HTMLAttributes, HTMLAttributes, {
250
337
  style: tableWidth ? `width: ${tableWidth}` : `min-width: ${tableMinWidth}`
251
338
  }),
252
339
  colgroup,
@@ -377,12 +464,33 @@ var Table = Node.create({
377
464
  }
378
465
  });
379
466
 
380
- // src/index.ts
381
- var src_default = Table;
467
+ // src/kit/index.ts
468
+ var TableKit = Extension.create({
469
+ name: "tableKit",
470
+ addExtensions() {
471
+ const extensions = [];
472
+ if (this.options.table !== false) {
473
+ extensions.push(Table.configure(this.options.table));
474
+ }
475
+ if (this.options.tableCell !== false) {
476
+ extensions.push(TableCell.configure(this.options.tableCell));
477
+ }
478
+ if (this.options.tableHeader !== false) {
479
+ extensions.push(TableHeader.configure(this.options.tableHeader));
480
+ }
481
+ if (this.options.tableRow !== false) {
482
+ extensions.push(TableRow.configure(this.options.tableRow));
483
+ }
484
+ return extensions;
485
+ }
486
+ });
382
487
  export {
383
488
  Table,
489
+ TableCell,
490
+ TableHeader,
491
+ TableKit,
492
+ TableRow,
384
493
  createColGroup,
385
- createTable,
386
- src_default as default
494
+ createTable
387
495
  };
388
496
  //# sourceMappingURL=index.js.map