@tiptap/extension-table 3.0.0-next.3 → 3.0.0-next.5

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 (58) 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 +148 -31
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +95 -21
  18. package/dist/index.d.ts +95 -21
  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 +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/index.d.cts +220 -0
  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 +50 -6
  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 -7
  45. package/src/kit/index.ts +60 -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} +4 -7
  49. package/src/table/index.ts +3 -0
  50. package/src/{table.ts → table/table.ts} +52 -58
  51. package/src/{utilities → table/utilities}/colStyle.ts +0 -1
  52. package/src/{utilities → table/utilities}/createColGroup.ts +10 -14
  53. package/src/types.ts +19 -0
  54. /package/src/{utilities → table/utilities}/createCell.ts +0 -0
  55. /package/src/{utilities → table/utilities}/createTable.ts +0 -0
  56. /package/src/{utilities → table/utilities}/deleteTableWhenAllCellsSelected.ts +0 -0
  57. /package/src/{utilities → table/utilities}/getTableNodeTypes.ts +0 -0
  58. /package/src/{utilities → table/utilities}/isCellSelection.ts +0 -0
@@ -0,0 +1,220 @@
1
+ import { ParentConfig, Node as Node$1 } from '@tiptap/core';
2
+ import { Node, DOMOutputSpec, Schema, Fragment } from '@tiptap/pm/model';
3
+ import { EditorView, NodeView } from '@tiptap/pm/view';
4
+
5
+ declare module '@tiptap/core' {
6
+ interface NodeConfig<Options, Storage> {
7
+ /**
8
+ * A string or function to determine the role of the table.
9
+ * @default 'table'
10
+ * @example () => 'table'
11
+ */
12
+ tableRole?: string | ((this: {
13
+ name: string;
14
+ options: Options;
15
+ storage: Storage;
16
+ parent: ParentConfig<NodeConfig<Options>>['tableRole'];
17
+ }) => string);
18
+ }
19
+ }
20
+
21
+ interface TableOptions {
22
+ /**
23
+ * HTML attributes for the table element.
24
+ * @default {}
25
+ * @example { class: 'foo' }
26
+ */
27
+ HTMLAttributes: Record<string, any>;
28
+ /**
29
+ * Enables the resizing of tables.
30
+ * @default false
31
+ * @example true
32
+ */
33
+ resizable: boolean;
34
+ /**
35
+ * The width of the resize handle.
36
+ * @default 5
37
+ * @example 10
38
+ */
39
+ handleWidth: number;
40
+ /**
41
+ * The minimum width of a cell.
42
+ * @default 25
43
+ * @example 50
44
+ */
45
+ cellMinWidth: number;
46
+ /**
47
+ * The node view to render the table.
48
+ * @default TableView
49
+ */
50
+ View: (new (node: Node, cellMinWidth: number, view: EditorView) => NodeView) | null;
51
+ /**
52
+ * Enables the resizing of the last column.
53
+ * @default true
54
+ * @example false
55
+ */
56
+ lastColumnResizable: boolean;
57
+ /**
58
+ * Allow table node selection.
59
+ * @default false
60
+ * @example true
61
+ */
62
+ allowTableNodeSelection: boolean;
63
+ }
64
+ declare module '@tiptap/core' {
65
+ interface Commands<ReturnType> {
66
+ table: {
67
+ /**
68
+ * Insert a table
69
+ * @param options The table attributes
70
+ * @returns True if the command was successful, otherwise false
71
+ * @example editor.commands.insertTable({ rows: 3, cols: 3, withHeaderRow: true })
72
+ */
73
+ insertTable: (options?: {
74
+ rows?: number;
75
+ cols?: number;
76
+ withHeaderRow?: boolean;
77
+ }) => ReturnType;
78
+ /**
79
+ * Add a column before the current column
80
+ * @returns True if the command was successful, otherwise false
81
+ * @example editor.commands.addColumnBefore()
82
+ */
83
+ addColumnBefore: () => ReturnType;
84
+ /**
85
+ * Add a column after the current column
86
+ * @returns True if the command was successful, otherwise false
87
+ * @example editor.commands.addColumnAfter()
88
+ */
89
+ addColumnAfter: () => ReturnType;
90
+ /**
91
+ * Delete the current column
92
+ * @returns True if the command was successful, otherwise false
93
+ * @example editor.commands.deleteColumn()
94
+ */
95
+ deleteColumn: () => ReturnType;
96
+ /**
97
+ * Add a row before the current row
98
+ * @returns True if the command was successful, otherwise false
99
+ * @example editor.commands.addRowBefore()
100
+ */
101
+ addRowBefore: () => ReturnType;
102
+ /**
103
+ * Add a row after the current row
104
+ * @returns True if the command was successful, otherwise false
105
+ * @example editor.commands.addRowAfter()
106
+ */
107
+ addRowAfter: () => ReturnType;
108
+ /**
109
+ * Delete the current row
110
+ * @returns True if the command was successful, otherwise false
111
+ * @example editor.commands.deleteRow()
112
+ */
113
+ deleteRow: () => ReturnType;
114
+ /**
115
+ * Delete the current table
116
+ * @returns True if the command was successful, otherwise false
117
+ * @example editor.commands.deleteTable()
118
+ */
119
+ deleteTable: () => ReturnType;
120
+ /**
121
+ * Merge the currently selected cells
122
+ * @returns True if the command was successful, otherwise false
123
+ * @example editor.commands.mergeCells()
124
+ */
125
+ mergeCells: () => ReturnType;
126
+ /**
127
+ * Split the currently selected cell
128
+ * @returns True if the command was successful, otherwise false
129
+ * @example editor.commands.splitCell()
130
+ */
131
+ splitCell: () => ReturnType;
132
+ /**
133
+ * Toggle the header column
134
+ * @returns True if the command was successful, otherwise false
135
+ * @example editor.commands.toggleHeaderColumn()
136
+ */
137
+ toggleHeaderColumn: () => ReturnType;
138
+ /**
139
+ * Toggle the header row
140
+ * @returns True if the command was successful, otherwise false
141
+ * @example editor.commands.toggleHeaderRow()
142
+ */
143
+ toggleHeaderRow: () => ReturnType;
144
+ /**
145
+ * Toggle the header cell
146
+ * @returns True if the command was successful, otherwise false
147
+ * @example editor.commands.toggleHeaderCell()
148
+ */
149
+ toggleHeaderCell: () => ReturnType;
150
+ /**
151
+ * Merge or split the currently selected cells
152
+ * @returns True if the command was successful, otherwise false
153
+ * @example editor.commands.mergeOrSplit()
154
+ */
155
+ mergeOrSplit: () => ReturnType;
156
+ /**
157
+ * Set a cell attribute
158
+ * @param name The attribute name
159
+ * @param value The attribute value
160
+ * @returns True if the command was successful, otherwise false
161
+ * @example editor.commands.setCellAttribute('align', 'right')
162
+ */
163
+ setCellAttribute: (name: string, value: any) => ReturnType;
164
+ /**
165
+ * Moves the selection to the next cell
166
+ * @returns True if the command was successful, otherwise false
167
+ * @example editor.commands.goToNextCell()
168
+ */
169
+ goToNextCell: () => ReturnType;
170
+ /**
171
+ * Moves the selection to the previous cell
172
+ * @returns True if the command was successful, otherwise false
173
+ * @example editor.commands.goToPreviousCell()
174
+ */
175
+ goToPreviousCell: () => ReturnType;
176
+ /**
177
+ * Try to fix the table structure if necessary
178
+ * @returns True if the command was successful, otherwise false
179
+ * @example editor.commands.fixTables()
180
+ */
181
+ fixTables: () => ReturnType;
182
+ /**
183
+ * Set a cell selection inside the current table
184
+ * @param position The cell position
185
+ * @returns True if the command was successful, otherwise false
186
+ * @example editor.commands.setCellSelection({ anchorCell: 1, headCell: 2 })
187
+ */
188
+ setCellSelection: (position: {
189
+ anchorCell: number;
190
+ headCell?: number;
191
+ }) => ReturnType;
192
+ };
193
+ }
194
+ }
195
+ /**
196
+ * This extension allows you to create tables.
197
+ * @see https://www.tiptap.dev/api/nodes/table
198
+ */
199
+ declare const Table: Node$1<TableOptions, any>;
200
+
201
+ type ColGroup = {
202
+ colgroup: DOMOutputSpec;
203
+ tableWidth: string;
204
+ tableMinWidth: string;
205
+ } | Record<string, never>;
206
+ /**
207
+ * Creates a colgroup element for a table node in ProseMirror.
208
+ *
209
+ * @param node - The ProseMirror node representing the table.
210
+ * @param cellMinWidth - The minimum width of a cell in the table.
211
+ * @param overrideCol - (Optional) The index of the column to override the width of.
212
+ * @param overrideValue - (Optional) The width value to use for the overridden column.
213
+ * @returns An object containing the colgroup element, the total width of the table, and the minimum width of the table.
214
+ */
215
+ declare function createColGroup(node: Node, cellMinWidth: number): ColGroup;
216
+ declare function createColGroup(node: Node, cellMinWidth: number, overrideCol: number, overrideValue: number): ColGroup;
217
+
218
+ declare function createTable(schema: Schema, rowsCount: number, colsCount: number, withHeaderRow: boolean, cellContent?: Fragment | Node | Array<Node>): Node;
219
+
220
+ export { type ColGroup, Table, type TableOptions, createColGroup, createTable };
@@ -0,0 +1,220 @@
1
+ import { ParentConfig, Node as Node$1 } from '@tiptap/core';
2
+ import { Node, DOMOutputSpec, Schema, Fragment } from '@tiptap/pm/model';
3
+ import { EditorView, NodeView } from '@tiptap/pm/view';
4
+
5
+ declare module '@tiptap/core' {
6
+ interface NodeConfig<Options, Storage> {
7
+ /**
8
+ * A string or function to determine the role of the table.
9
+ * @default 'table'
10
+ * @example () => 'table'
11
+ */
12
+ tableRole?: string | ((this: {
13
+ name: string;
14
+ options: Options;
15
+ storage: Storage;
16
+ parent: ParentConfig<NodeConfig<Options>>['tableRole'];
17
+ }) => string);
18
+ }
19
+ }
20
+
21
+ interface TableOptions {
22
+ /**
23
+ * HTML attributes for the table element.
24
+ * @default {}
25
+ * @example { class: 'foo' }
26
+ */
27
+ HTMLAttributes: Record<string, any>;
28
+ /**
29
+ * Enables the resizing of tables.
30
+ * @default false
31
+ * @example true
32
+ */
33
+ resizable: boolean;
34
+ /**
35
+ * The width of the resize handle.
36
+ * @default 5
37
+ * @example 10
38
+ */
39
+ handleWidth: number;
40
+ /**
41
+ * The minimum width of a cell.
42
+ * @default 25
43
+ * @example 50
44
+ */
45
+ cellMinWidth: number;
46
+ /**
47
+ * The node view to render the table.
48
+ * @default TableView
49
+ */
50
+ View: (new (node: Node, cellMinWidth: number, view: EditorView) => NodeView) | null;
51
+ /**
52
+ * Enables the resizing of the last column.
53
+ * @default true
54
+ * @example false
55
+ */
56
+ lastColumnResizable: boolean;
57
+ /**
58
+ * Allow table node selection.
59
+ * @default false
60
+ * @example true
61
+ */
62
+ allowTableNodeSelection: boolean;
63
+ }
64
+ declare module '@tiptap/core' {
65
+ interface Commands<ReturnType> {
66
+ table: {
67
+ /**
68
+ * Insert a table
69
+ * @param options The table attributes
70
+ * @returns True if the command was successful, otherwise false
71
+ * @example editor.commands.insertTable({ rows: 3, cols: 3, withHeaderRow: true })
72
+ */
73
+ insertTable: (options?: {
74
+ rows?: number;
75
+ cols?: number;
76
+ withHeaderRow?: boolean;
77
+ }) => ReturnType;
78
+ /**
79
+ * Add a column before the current column
80
+ * @returns True if the command was successful, otherwise false
81
+ * @example editor.commands.addColumnBefore()
82
+ */
83
+ addColumnBefore: () => ReturnType;
84
+ /**
85
+ * Add a column after the current column
86
+ * @returns True if the command was successful, otherwise false
87
+ * @example editor.commands.addColumnAfter()
88
+ */
89
+ addColumnAfter: () => ReturnType;
90
+ /**
91
+ * Delete the current column
92
+ * @returns True if the command was successful, otherwise false
93
+ * @example editor.commands.deleteColumn()
94
+ */
95
+ deleteColumn: () => ReturnType;
96
+ /**
97
+ * Add a row before the current row
98
+ * @returns True if the command was successful, otherwise false
99
+ * @example editor.commands.addRowBefore()
100
+ */
101
+ addRowBefore: () => ReturnType;
102
+ /**
103
+ * Add a row after the current row
104
+ * @returns True if the command was successful, otherwise false
105
+ * @example editor.commands.addRowAfter()
106
+ */
107
+ addRowAfter: () => ReturnType;
108
+ /**
109
+ * Delete the current row
110
+ * @returns True if the command was successful, otherwise false
111
+ * @example editor.commands.deleteRow()
112
+ */
113
+ deleteRow: () => ReturnType;
114
+ /**
115
+ * Delete the current table
116
+ * @returns True if the command was successful, otherwise false
117
+ * @example editor.commands.deleteTable()
118
+ */
119
+ deleteTable: () => ReturnType;
120
+ /**
121
+ * Merge the currently selected cells
122
+ * @returns True if the command was successful, otherwise false
123
+ * @example editor.commands.mergeCells()
124
+ */
125
+ mergeCells: () => ReturnType;
126
+ /**
127
+ * Split the currently selected cell
128
+ * @returns True if the command was successful, otherwise false
129
+ * @example editor.commands.splitCell()
130
+ */
131
+ splitCell: () => ReturnType;
132
+ /**
133
+ * Toggle the header column
134
+ * @returns True if the command was successful, otherwise false
135
+ * @example editor.commands.toggleHeaderColumn()
136
+ */
137
+ toggleHeaderColumn: () => ReturnType;
138
+ /**
139
+ * Toggle the header row
140
+ * @returns True if the command was successful, otherwise false
141
+ * @example editor.commands.toggleHeaderRow()
142
+ */
143
+ toggleHeaderRow: () => ReturnType;
144
+ /**
145
+ * Toggle the header cell
146
+ * @returns True if the command was successful, otherwise false
147
+ * @example editor.commands.toggleHeaderCell()
148
+ */
149
+ toggleHeaderCell: () => ReturnType;
150
+ /**
151
+ * Merge or split the currently selected cells
152
+ * @returns True if the command was successful, otherwise false
153
+ * @example editor.commands.mergeOrSplit()
154
+ */
155
+ mergeOrSplit: () => ReturnType;
156
+ /**
157
+ * Set a cell attribute
158
+ * @param name The attribute name
159
+ * @param value The attribute value
160
+ * @returns True if the command was successful, otherwise false
161
+ * @example editor.commands.setCellAttribute('align', 'right')
162
+ */
163
+ setCellAttribute: (name: string, value: any) => ReturnType;
164
+ /**
165
+ * Moves the selection to the next cell
166
+ * @returns True if the command was successful, otherwise false
167
+ * @example editor.commands.goToNextCell()
168
+ */
169
+ goToNextCell: () => ReturnType;
170
+ /**
171
+ * Moves the selection to the previous cell
172
+ * @returns True if the command was successful, otherwise false
173
+ * @example editor.commands.goToPreviousCell()
174
+ */
175
+ goToPreviousCell: () => ReturnType;
176
+ /**
177
+ * Try to fix the table structure if necessary
178
+ * @returns True if the command was successful, otherwise false
179
+ * @example editor.commands.fixTables()
180
+ */
181
+ fixTables: () => ReturnType;
182
+ /**
183
+ * Set a cell selection inside the current table
184
+ * @param position The cell position
185
+ * @returns True if the command was successful, otherwise false
186
+ * @example editor.commands.setCellSelection({ anchorCell: 1, headCell: 2 })
187
+ */
188
+ setCellSelection: (position: {
189
+ anchorCell: number;
190
+ headCell?: number;
191
+ }) => ReturnType;
192
+ };
193
+ }
194
+ }
195
+ /**
196
+ * This extension allows you to create tables.
197
+ * @see https://www.tiptap.dev/api/nodes/table
198
+ */
199
+ declare const Table: Node$1<TableOptions, any>;
200
+
201
+ type ColGroup = {
202
+ colgroup: DOMOutputSpec;
203
+ tableWidth: string;
204
+ tableMinWidth: string;
205
+ } | Record<string, never>;
206
+ /**
207
+ * Creates a colgroup element for a table node in ProseMirror.
208
+ *
209
+ * @param node - The ProseMirror node representing the table.
210
+ * @param cellMinWidth - The minimum width of a cell in the table.
211
+ * @param overrideCol - (Optional) The index of the column to override the width of.
212
+ * @param overrideValue - (Optional) The width value to use for the overridden column.
213
+ * @returns An object containing the colgroup element, the total width of the table, and the minimum width of the table.
214
+ */
215
+ declare function createColGroup(node: Node, cellMinWidth: number): ColGroup;
216
+ declare function createColGroup(node: Node, cellMinWidth: number, overrideCol: number, overrideValue: number): ColGroup;
217
+
218
+ declare function createTable(schema: Schema, rowsCount: number, colsCount: number, withHeaderRow: boolean, cellContent?: Fragment | Node | Array<Node>): Node;
219
+
220
+ export { type ColGroup, Table, type TableOptions, createColGroup, createTable };