@tiptap/extension-table 2.11.7 → 3.0.0-beta.0

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 (78) 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 +33 -0
  6. package/dist/cell/index.d.ts +33 -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 +33 -0
  12. package/dist/header/index.d.ts +33 -0
  13. package/dist/header/index.js +41 -0
  14. package/dist/header/index.js.map +1 -0
  15. package/dist/index.cjs +475 -331
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +291 -0
  18. package/dist/index.d.ts +291 -7
  19. package/dist/index.js +462 -324
  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 +252 -0
  24. package/dist/kit/index.d.ts +252 -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 +33 -0
  30. package/dist/row/index.d.ts +33 -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.d.ts → table/index.d.cts} +43 -19
  36. package/dist/table/index.d.ts +220 -0
  37. package/dist/table/index.js +373 -0
  38. package/dist/table/index.js.map +1 -0
  39. package/package.json +52 -10
  40. package/src/cell/index.ts +1 -0
  41. package/src/cell/table-cell.ts +60 -0
  42. package/src/header/index.ts +1 -0
  43. package/src/header/table-header.ts +60 -0
  44. package/src/index.ts +5 -8
  45. package/src/kit/index.ts +64 -0
  46. package/src/row/index.ts +1 -0
  47. package/src/row/table-row.ts +38 -0
  48. package/src/{TableView.ts → table/TableView.ts} +6 -9
  49. package/src/table/index.ts +3 -0
  50. package/src/{table.ts → table/table.ts} +54 -60
  51. package/src/{utilities → table/utilities}/colStyle.ts +0 -1
  52. package/src/{utilities → table/utilities}/createCell.ts +1 -1
  53. package/src/{utilities → table/utilities}/createColGroup.ts +11 -15
  54. package/src/{utilities → table/utilities}/createTable.ts +1 -1
  55. package/src/{utilities → table/utilities}/deleteTableWhenAllCellsSelected.ts +2 -1
  56. package/src/{utilities → table/utilities}/getTableNodeTypes.ts +1 -1
  57. package/src/types.ts +19 -0
  58. package/dist/TableView.d.ts +0 -16
  59. package/dist/TableView.d.ts.map +0 -1
  60. package/dist/index.d.ts.map +0 -1
  61. package/dist/index.umd.js +0 -369
  62. package/dist/index.umd.js.map +0 -1
  63. package/dist/table.d.ts.map +0 -1
  64. package/dist/utilities/colStyle.d.ts +0 -2
  65. package/dist/utilities/colStyle.d.ts.map +0 -1
  66. package/dist/utilities/createCell.d.ts +0 -3
  67. package/dist/utilities/createCell.d.ts.map +0 -1
  68. package/dist/utilities/createColGroup.d.ts +0 -18
  69. package/dist/utilities/createColGroup.d.ts.map +0 -1
  70. package/dist/utilities/createTable.d.ts +0 -3
  71. package/dist/utilities/createTable.d.ts.map +0 -1
  72. package/dist/utilities/deleteTableWhenAllCellsSelected.d.ts +0 -3
  73. package/dist/utilities/deleteTableWhenAllCellsSelected.d.ts.map +0 -1
  74. package/dist/utilities/getTableNodeTypes.d.ts +0 -5
  75. package/dist/utilities/getTableNodeTypes.d.ts.map +0 -1
  76. package/dist/utilities/isCellSelection.d.ts +0 -3
  77. package/dist/utilities/isCellSelection.d.ts.map +0 -1
  78. /package/src/{utilities → table/utilities}/isCellSelection.ts +0 -0
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": "2.11.7",
4
+ "version": "3.0.0-beta.0",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -15,26 +15,68 @@
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": {
18
- "types": "./dist/index.d.ts",
18
+ "types": {
19
+ "import": "./dist/index.d.ts",
20
+ "require": "./dist/index.d.cts"
21
+ },
19
22
  "import": "./dist/index.js",
20
23
  "require": "./dist/index.cjs"
24
+ },
25
+ "./table": {
26
+ "types": {
27
+ "import": "./dist/table/index.d.ts",
28
+ "require": "./dist/table/index.d.cts"
29
+ },
30
+ "import": "./dist/table/index.js",
31
+ "require": "./dist/table/index.cjs"
32
+ },
33
+ "./cell": {
34
+ "types": {
35
+ "import": "./dist/cell/index.d.ts",
36
+ "require": "./dist/cell/index.d.cts"
37
+ },
38
+ "import": "./dist/cell/index.js",
39
+ "require": "./dist/cell/index.cjs"
40
+ },
41
+ "./header": {
42
+ "types": {
43
+ "import": "./dist/header/index.d.ts",
44
+ "require": "./dist/header/index.d.cts"
45
+ },
46
+ "import": "./dist/header/index.js",
47
+ "require": "./dist/header/index.cjs"
48
+ },
49
+ "./kit": {
50
+ "types": {
51
+ "import": "./dist/kit/index.d.ts",
52
+ "require": "./dist/kit/index.d.cts"
53
+ },
54
+ "import": "./dist/kit/index.js",
55
+ "require": "./dist/kit/index.cjs"
56
+ },
57
+ "./row": {
58
+ "types": {
59
+ "import": "./dist/row/index.d.ts",
60
+ "require": "./dist/row/index.d.cts"
61
+ },
62
+ "import": "./dist/row/index.js",
63
+ "require": "./dist/row/index.cjs"
21
64
  }
22
65
  },
23
66
  "main": "dist/index.cjs",
24
67
  "module": "dist/index.js",
25
- "umd": "dist/index.umd.js",
26
68
  "types": "dist/index.d.ts",
27
69
  "files": [
28
70
  "src",
29
71
  "dist"
30
72
  ],
31
73
  "devDependencies": {
32
- "@tiptap/core": "^2.11.7",
33
- "@tiptap/pm": "^2.11.7"
74
+ "@tiptap/core": "^3.0.0-beta.0",
75
+ "@tiptap/pm": "^3.0.0-beta.0"
34
76
  },
35
77
  "peerDependencies": {
36
- "@tiptap/core": "^2.7.0",
37
- "@tiptap/pm": "^2.7.0"
78
+ "@tiptap/core": "^3.0.0-beta.0",
79
+ "@tiptap/pm": "^3.0.0-beta.0"
38
80
  },
39
81
  "repository": {
40
82
  "type": "git",
@@ -42,7 +84,7 @@
42
84
  "directory": "packages/extension-table"
43
85
  },
44
86
  "scripts": {
45
- "clean": "rm -rf dist",
46
- "build": "npm run clean && rollup -c"
87
+ "build": "tsup",
88
+ "lint": "prettier ./src/ --check && eslint --cache --quiet --no-error-on-unmatched-pattern ./src/"
47
89
  }
48
- }
90
+ }
@@ -0,0 +1 @@
1
+ export * from './table-cell.js'
@@ -0,0 +1,60 @@
1
+ import '../types.js'
2
+
3
+ import { mergeAttributes, Node } from '@tiptap/core'
4
+
5
+ export 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
+ /**
15
+ * This extension allows you to create table cells.
16
+ * @see https://www.tiptap.dev/api/nodes/table-cell
17
+ */
18
+ export const TableCell = Node.create<TableCellOptions>({
19
+ name: 'tableCell',
20
+
21
+ addOptions() {
22
+ return {
23
+ HTMLAttributes: {},
24
+ }
25
+ },
26
+
27
+ content: 'block+',
28
+
29
+ addAttributes() {
30
+ return {
31
+ colspan: {
32
+ default: 1,
33
+ },
34
+ rowspan: {
35
+ default: 1,
36
+ },
37
+ colwidth: {
38
+ default: null,
39
+ parseHTML: element => {
40
+ const colwidth = element.getAttribute('colwidth')
41
+ const value = colwidth ? colwidth.split(',').map(width => parseInt(width, 10)) : null
42
+
43
+ return value
44
+ },
45
+ },
46
+ }
47
+ },
48
+
49
+ tableRole: 'cell',
50
+
51
+ isolating: true,
52
+
53
+ parseHTML() {
54
+ return [{ tag: 'td' }]
55
+ },
56
+
57
+ renderHTML({ HTMLAttributes }) {
58
+ return ['td', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
59
+ },
60
+ })
@@ -0,0 +1 @@
1
+ export * from './table-header.js'
@@ -0,0 +1,60 @@
1
+ import '../types.js'
2
+
3
+ import { mergeAttributes, Node } from '@tiptap/core'
4
+
5
+ export interface TableHeaderOptions {
6
+ /**
7
+ * The HTML attributes for a table header node.
8
+ * @default {}
9
+ * @example { class: 'foo' }
10
+ */
11
+ HTMLAttributes: Record<string, any>
12
+ }
13
+
14
+ /**
15
+ * This extension allows you to create table headers.
16
+ * @see https://www.tiptap.dev/api/nodes/table-header
17
+ */
18
+ export const TableHeader = Node.create<TableHeaderOptions>({
19
+ name: 'tableHeader',
20
+
21
+ addOptions() {
22
+ return {
23
+ HTMLAttributes: {},
24
+ }
25
+ },
26
+
27
+ content: 'block+',
28
+
29
+ addAttributes() {
30
+ return {
31
+ colspan: {
32
+ default: 1,
33
+ },
34
+ rowspan: {
35
+ default: 1,
36
+ },
37
+ colwidth: {
38
+ default: null,
39
+ parseHTML: element => {
40
+ const colwidth = element.getAttribute('colwidth')
41
+ const value = colwidth ? colwidth.split(',').map(width => parseInt(width, 10)) : null
42
+
43
+ return value
44
+ },
45
+ },
46
+ }
47
+ },
48
+
49
+ tableRole: 'header_cell',
50
+
51
+ isolating: true,
52
+
53
+ parseHTML() {
54
+ return [{ tag: 'th' }]
55
+ },
56
+
57
+ renderHTML({ HTMLAttributes }) {
58
+ return ['th', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
59
+ },
60
+ })
package/src/index.ts CHANGED
@@ -1,8 +1,5 @@
1
- import { Table } from './table.js'
2
-
3
- export * from './table.js'
4
- export * from './TableView.js'
5
- export * from './utilities/createColGroup.js'
6
- export * from './utilities/createTable.js'
7
-
8
- export default Table
1
+ export * from './cell/index.js'
2
+ export * from './header/index.js'
3
+ export * from './kit/index.js'
4
+ export * from './row/index.js'
5
+ export * from './table/index.js'
@@ -0,0 +1,64 @@
1
+ import { Extension } from '@tiptap/core'
2
+
3
+ import type { TableCellOptions } from '../cell/index.js'
4
+ import { TableCell } from '../cell/index.js'
5
+ import type { TableHeaderOptions } from '../header/index.js'
6
+ import { TableHeader } from '../header/index.js'
7
+ import type { TableRowOptions } from '../row/index.js'
8
+ import { TableRow } from '../row/index.js'
9
+ import type { TableOptions } from '../table/index.js'
10
+ import { Table } from '../table/index.js'
11
+
12
+ export interface TableKitOptions {
13
+ /**
14
+ * If set to false, the table extension will not be registered
15
+ * @example table: false
16
+ */
17
+ table: Partial<TableOptions> | false
18
+ /**
19
+ * If set to false, the table extension will not be registered
20
+ * @example tableCell: false
21
+ */
22
+ tableCell: Partial<TableCellOptions> | false
23
+ /**
24
+ * If set to false, the table extension will not be registered
25
+ * @example tableHeader: false
26
+ */
27
+ tableHeader: Partial<TableHeaderOptions> | false
28
+ /**
29
+ * If set to false, the table extension will not be registered
30
+ * @example tableRow: false
31
+ */
32
+ tableRow: Partial<TableRowOptions> | false
33
+ }
34
+
35
+ /**
36
+ * The table kit is a collection of table editor extensions.
37
+ *
38
+ * It’s a good starting point for building your own table in Tiptap.
39
+ */
40
+ export const TableKit = Extension.create<TableKitOptions>({
41
+ name: 'tableKit',
42
+
43
+ addExtensions() {
44
+ const extensions = []
45
+
46
+ if (this.options.table !== false) {
47
+ extensions.push(Table.configure(this.options.table))
48
+ }
49
+
50
+ if (this.options.tableCell !== false) {
51
+ extensions.push(TableCell.configure(this.options.tableCell))
52
+ }
53
+
54
+ if (this.options.tableHeader !== false) {
55
+ extensions.push(TableHeader.configure(this.options.tableHeader))
56
+ }
57
+
58
+ if (this.options.tableRow !== false) {
59
+ extensions.push(TableRow.configure(this.options.tableRow))
60
+ }
61
+
62
+ return extensions
63
+ },
64
+ })
@@ -0,0 +1 @@
1
+ export * from './table-row.js'
@@ -0,0 +1,38 @@
1
+ import '../types.js'
2
+
3
+ import { mergeAttributes, Node } from '@tiptap/core'
4
+
5
+ export interface TableRowOptions {
6
+ /**
7
+ * The HTML attributes for a table row node.
8
+ * @default {}
9
+ * @example { class: 'foo' }
10
+ */
11
+ HTMLAttributes: Record<string, any>
12
+ }
13
+
14
+ /**
15
+ * This extension allows you to create table rows.
16
+ * @see https://www.tiptap.dev/api/nodes/table-row
17
+ */
18
+ export const TableRow = Node.create<TableRowOptions>({
19
+ name: 'tableRow',
20
+
21
+ addOptions() {
22
+ return {
23
+ HTMLAttributes: {},
24
+ }
25
+ },
26
+
27
+ content: '(tableCell | tableHeader)*',
28
+
29
+ tableRole: 'row',
30
+
31
+ parseHTML() {
32
+ return [{ tag: 'tr' }]
33
+ },
34
+
35
+ renderHTML({ HTMLAttributes }) {
36
+ return ['tr', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
37
+ },
38
+ })
@@ -1,5 +1,5 @@
1
- import { Node as ProseMirrorNode } from '@tiptap/pm/model'
2
- import { NodeView, ViewMutationRecord } from '@tiptap/pm/view'
1
+ import type { Node as ProseMirrorNode } from '@tiptap/pm/model'
2
+ import type { NodeView, ViewMutationRecord } from '@tiptap/pm/view'
3
3
 
4
4
  import { getColStyleDeclaration } from './utilities/colStyle.js'
5
5
 
@@ -21,7 +21,7 @@ export function updateColumns(
21
21
  const { colspan, colwidth } = row.child(i).attrs
22
22
 
23
23
  for (let j = 0; j < colspan; j += 1, col += 1) {
24
- const hasWidth = overrideCol === col ? overrideValue : (colwidth && colwidth[j]) as number | undefined
24
+ const hasWidth = overrideCol === col ? overrideValue : ((colwidth && colwidth[j]) as number | undefined)
25
25
  const cssWidth = hasWidth ? `${hasWidth}px` : ''
26
26
 
27
27
  totalWidth += hasWidth || cellMinWidth
@@ -40,9 +40,9 @@ export function updateColumns(
40
40
  colgroup.appendChild(colElement)
41
41
  } else {
42
42
  if ((nextDOM as HTMLTableColElement).style.width !== cssWidth) {
43
- const [propertyKey, propertyValue] = getColStyleDeclaration(cellMinWidth, hasWidth);
43
+ const [propertyKey, propertyValue] = getColStyleDeclaration(cellMinWidth, hasWidth)
44
44
 
45
- (nextDOM as HTMLTableColElement).style.setProperty(propertyKey, propertyValue)
45
+ ;(nextDOM as HTMLTableColElement).style.setProperty(propertyKey, propertyValue)
46
46
  }
47
47
 
48
48
  nextDOM = nextDOM.nextSibling
@@ -103,9 +103,6 @@ export class TableView implements NodeView {
103
103
  }
104
104
 
105
105
  ignoreMutation(mutation: ViewMutationRecord) {
106
- return (
107
- mutation.type === 'attributes'
108
- && (mutation.target === this.table || this.colgroup.contains(mutation.target))
109
- )
106
+ return mutation.type === 'attributes' && (mutation.target === this.table || this.colgroup.contains(mutation.target))
110
107
  }
111
108
  }
@@ -0,0 +1,3 @@
1
+ export * from './table.js'
2
+ export * from './utilities/createColGroup.js'
3
+ export * from './utilities/createTable.js'
@@ -1,7 +1,7 @@
1
- import {
2
- callOrReturn, getExtensionField, mergeAttributes, Node, ParentConfig,
3
- } from '@tiptap/core'
4
- import { DOMOutputSpec, Node as ProseMirrorNode } from '@tiptap/pm/model'
1
+ import '../types.js'
2
+
3
+ import { callOrReturn, getExtensionField, mergeAttributes, Node } from '@tiptap/core'
4
+ import type { DOMOutputSpec, Node as ProseMirrorNode } from '@tiptap/pm/model'
5
5
  import { TextSelection } from '@tiptap/pm/state'
6
6
  import {
7
7
  addColumnAfter,
@@ -22,7 +22,7 @@ import {
22
22
  toggleHeader,
23
23
  toggleHeaderCell,
24
24
  } from '@tiptap/pm/tables'
25
- import { EditorView, NodeView } from '@tiptap/pm/view'
25
+ import type { EditorView, NodeView } from '@tiptap/pm/view'
26
26
 
27
27
  import { TableView } from './TableView.js'
28
28
  import { createColGroup } from './utilities/createColGroup.js'
@@ -88,11 +88,7 @@ declare module '@tiptap/core' {
88
88
  * @returns True if the command was successful, otherwise false
89
89
  * @example editor.commands.insertTable({ rows: 3, cols: 3, withHeaderRow: true })
90
90
  */
91
- insertTable: (options?: {
92
- rows?: number
93
- cols?: number
94
- withHeaderRow?: boolean
95
- }) => ReturnType
91
+ insertTable: (options?: { rows?: number; cols?: number; withHeaderRow?: boolean }) => ReturnType
96
92
 
97
93
  /**
98
94
  * Add a column before the current column
@@ -224,22 +220,6 @@ declare module '@tiptap/core' {
224
220
  setCellSelection: (position: { anchorCell: number; headCell?: number }) => ReturnType
225
221
  }
226
222
  }
227
-
228
- interface NodeConfig<Options, Storage> {
229
- /**
230
- * A string or function to determine the role of the table.
231
- * @default 'table'
232
- * @example () => 'table'
233
- */
234
- tableRole?:
235
- | string
236
- | ((this: {
237
- name: string
238
- options: Options
239
- storage: Storage
240
- parent: ParentConfig<NodeConfig<Options>>['tableRole']
241
- }) => string)
242
- }
243
223
  }
244
224
 
245
225
  /**
@@ -276,17 +256,12 @@ export const Table = Node.create<TableOptions>({
276
256
  },
277
257
 
278
258
  renderHTML({ node, HTMLAttributes }) {
279
- const { colgroup, tableWidth, tableMinWidth } = createColGroup(
280
- node,
281
- this.options.cellMinWidth,
282
- )
259
+ const { colgroup, tableWidth, tableMinWidth } = createColGroup(node, this.options.cellMinWidth)
283
260
 
284
261
  const table: DOMOutputSpec = [
285
262
  'table',
286
263
  mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
287
- style: tableWidth
288
- ? `width: ${tableWidth}`
289
- : `min-width: ${tableMinWidth}`,
264
+ style: tableWidth ? `width: ${tableWidth}` : `min-width: ${tableMinWidth}`,
290
265
  }),
291
266
  colgroup,
292
267
  ['tbody', 0],
@@ -298,7 +273,8 @@ export const Table = Node.create<TableOptions>({
298
273
  addCommands() {
299
274
  return {
300
275
  insertTable:
301
- ({ rows = 3, cols = 3, withHeaderRow = true } = {}) => ({ tr, dispatch, editor }) => {
276
+ ({ rows = 3, cols = 3, withHeaderRow = true } = {}) =>
277
+ ({ tr, dispatch, editor }) => {
302
278
  const node = createTable(editor.schema, rows, cols, withHeaderRow)
303
279
 
304
280
  if (dispatch) {
@@ -312,55 +288,68 @@ export const Table = Node.create<TableOptions>({
312
288
  return true
313
289
  },
314
290
  addColumnBefore:
315
- () => ({ state, dispatch }) => {
291
+ () =>
292
+ ({ state, dispatch }) => {
316
293
  return addColumnBefore(state, dispatch)
317
294
  },
318
295
  addColumnAfter:
319
- () => ({ state, dispatch }) => {
296
+ () =>
297
+ ({ state, dispatch }) => {
320
298
  return addColumnAfter(state, dispatch)
321
299
  },
322
300
  deleteColumn:
323
- () => ({ state, dispatch }) => {
301
+ () =>
302
+ ({ state, dispatch }) => {
324
303
  return deleteColumn(state, dispatch)
325
304
  },
326
305
  addRowBefore:
327
- () => ({ state, dispatch }) => {
306
+ () =>
307
+ ({ state, dispatch }) => {
328
308
  return addRowBefore(state, dispatch)
329
309
  },
330
310
  addRowAfter:
331
- () => ({ state, dispatch }) => {
311
+ () =>
312
+ ({ state, dispatch }) => {
332
313
  return addRowAfter(state, dispatch)
333
314
  },
334
315
  deleteRow:
335
- () => ({ state, dispatch }) => {
316
+ () =>
317
+ ({ state, dispatch }) => {
336
318
  return deleteRow(state, dispatch)
337
319
  },
338
320
  deleteTable:
339
- () => ({ state, dispatch }) => {
321
+ () =>
322
+ ({ state, dispatch }) => {
340
323
  return deleteTable(state, dispatch)
341
324
  },
342
325
  mergeCells:
343
- () => ({ state, dispatch }) => {
326
+ () =>
327
+ ({ state, dispatch }) => {
344
328
  return mergeCells(state, dispatch)
345
329
  },
346
330
  splitCell:
347
- () => ({ state, dispatch }) => {
331
+ () =>
332
+ ({ state, dispatch }) => {
348
333
  return splitCell(state, dispatch)
349
334
  },
350
335
  toggleHeaderColumn:
351
- () => ({ state, dispatch }) => {
336
+ () =>
337
+ ({ state, dispatch }) => {
352
338
  return toggleHeader('column')(state, dispatch)
353
339
  },
354
340
  toggleHeaderRow:
355
- () => ({ state, dispatch }) => {
341
+ () =>
342
+ ({ state, dispatch }) => {
356
343
  return toggleHeader('row')(state, dispatch)
357
344
  },
358
345
  toggleHeaderCell:
359
- () => ({ state, dispatch }) => {
346
+ () =>
347
+ ({ state, dispatch }) => {
360
348
  return toggleHeaderCell(state, dispatch)
361
349
  },
362
350
  mergeOrSplit:
363
- () => ({ state, dispatch }) => {
351
+ () =>
352
+ ({ state, dispatch }) => {
364
353
  if (mergeCells(state, dispatch)) {
365
354
  return true
366
355
  }
@@ -368,19 +357,23 @@ export const Table = Node.create<TableOptions>({
368
357
  return splitCell(state, dispatch)
369
358
  },
370
359
  setCellAttribute:
371
- (name, value) => ({ state, dispatch }) => {
360
+ (name, value) =>
361
+ ({ state, dispatch }) => {
372
362
  return setCellAttr(name, value)(state, dispatch)
373
363
  },
374
364
  goToNextCell:
375
- () => ({ state, dispatch }) => {
365
+ () =>
366
+ ({ state, dispatch }) => {
376
367
  return goToNextCell(1)(state, dispatch)
377
368
  },
378
369
  goToPreviousCell:
379
- () => ({ state, dispatch }) => {
370
+ () =>
371
+ ({ state, dispatch }) => {
380
372
  return goToNextCell(-1)(state, dispatch)
381
373
  },
382
374
  fixTables:
383
- () => ({ state, dispatch }) => {
375
+ () =>
376
+ ({ state, dispatch }) => {
384
377
  if (dispatch) {
385
378
  fixTables(state)
386
379
  }
@@ -388,7 +381,8 @@ export const Table = Node.create<TableOptions>({
388
381
  return true
389
382
  },
390
383
  setCellSelection:
391
- position => ({ tr, dispatch }) => {
384
+ position =>
385
+ ({ tr, dispatch }) => {
392
386
  if (dispatch) {
393
387
  const selection = CellSelection.create(tr.doc, position.anchorCell, position.headCell)
394
388
 
@@ -428,14 +422,14 @@ export const Table = Node.create<TableOptions>({
428
422
  return [
429
423
  ...(isResizable
430
424
  ? [
431
- columnResizing({
432
- handleWidth: this.options.handleWidth,
433
- cellMinWidth: this.options.cellMinWidth,
434
- defaultCellMinWidth: this.options.cellMinWidth,
435
- View: this.options.View,
436
- lastColumnResizable: this.options.lastColumnResizable,
437
- }),
438
- ]
425
+ columnResizing({
426
+ handleWidth: this.options.handleWidth,
427
+ cellMinWidth: this.options.cellMinWidth,
428
+ defaultCellMinWidth: this.options.cellMinWidth,
429
+ View: this.options.View,
430
+ lastColumnResizable: this.options.lastColumnResizable,
431
+ }),
432
+ ]
439
433
  : []),
440
434
  tableEditing({
441
435
  allowTableNodeSelection: this.options.allowTableNodeSelection,
@@ -6,5 +6,4 @@ export function getColStyleDeclaration(minWidth: number, width: number | undefin
6
6
 
7
7
  // set the minimum with on the column if it has no stored width
8
8
  return ['min-width', `${minWidth}px`]
9
-
10
9
  }
@@ -1,4 +1,4 @@
1
- import { Fragment, Node as ProsemirrorNode, NodeType } from '@tiptap/pm/model'
1
+ import type { Fragment, Node as ProsemirrorNode, NodeType } from '@tiptap/pm/model'
2
2
 
3
3
  export function createCell(
4
4
  cellType: NodeType,
@@ -1,12 +1,14 @@
1
- import { DOMOutputSpec, Node as ProseMirrorNode } from '@tiptap/pm/model'
1
+ import type { DOMOutputSpec, Node as ProseMirrorNode } from '@tiptap/pm/model'
2
2
 
3
3
  import { getColStyleDeclaration } from './colStyle.js'
4
4
 
5
- export type ColGroup = {
6
- colgroup: DOMOutputSpec
7
- tableWidth: string
8
- tableMinWidth: string
9
- } | Record<string, never>;
5
+ export type ColGroup =
6
+ | {
7
+ colgroup: DOMOutputSpec
8
+ tableWidth: string
9
+ tableMinWidth: string
10
+ }
11
+ | Record<string, never>
10
12
 
11
13
  /**
12
14
  * Creates a colgroup element for a table node in ProseMirror.
@@ -17,10 +19,7 @@ export type ColGroup = {
17
19
  * @param overrideValue - (Optional) The width value to use for the overridden column.
18
20
  * @returns An object containing the colgroup element, the total width of the table, and the minimum width of the table.
19
21
  */
20
- export function createColGroup(
21
- node: ProseMirrorNode,
22
- cellMinWidth: number,
23
- ): ColGroup
22
+ export function createColGroup(node: ProseMirrorNode, cellMinWidth: number): ColGroup
24
23
  export function createColGroup(
25
24
  node: ProseMirrorNode,
26
25
  cellMinWidth: number,
@@ -46,7 +45,7 @@ export function createColGroup(
46
45
  const { colspan, colwidth } = row.child(i).attrs
47
46
 
48
47
  for (let j = 0; j < colspan; j += 1, col += 1) {
49
- const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j] as number | undefined
48
+ const hasWidth = overrideCol === col ? overrideValue : colwidth && (colwidth[j] as number | undefined)
50
49
 
51
50
  totalWidth += hasWidth || cellMinWidth
52
51
 
@@ -56,10 +55,7 @@ export function createColGroup(
56
55
 
57
56
  const [property, value] = getColStyleDeclaration(cellMinWidth, hasWidth)
58
57
 
59
- cols.push([
60
- 'col',
61
- { style: `${property}: ${value}` },
62
- ])
58
+ cols.push(['col', { style: `${property}: ${value}` }])
63
59
  }
64
60
  }
65
61