@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,252 @@
1
+ import { ParentConfig, Extension } from '@tiptap/core';
2
+ import { Node } 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 TableCellOptions {
22
+ /**
23
+ * The HTML attributes for a table cell node.
24
+ * @default {}
25
+ * @example { class: 'foo' }
26
+ */
27
+ HTMLAttributes: Record<string, any>;
28
+ }
29
+
30
+ interface TableHeaderOptions {
31
+ /**
32
+ * The HTML attributes for a table header node.
33
+ * @default {}
34
+ * @example { class: 'foo' }
35
+ */
36
+ HTMLAttributes: Record<string, any>;
37
+ }
38
+
39
+ interface TableRowOptions {
40
+ /**
41
+ * The HTML attributes for a table row node.
42
+ * @default {}
43
+ * @example { class: 'foo' }
44
+ */
45
+ HTMLAttributes: Record<string, any>;
46
+ }
47
+
48
+ interface TableOptions {
49
+ /**
50
+ * HTML attributes for the table element.
51
+ * @default {}
52
+ * @example { class: 'foo' }
53
+ */
54
+ HTMLAttributes: Record<string, any>;
55
+ /**
56
+ * Enables the resizing of tables.
57
+ * @default false
58
+ * @example true
59
+ */
60
+ resizable: boolean;
61
+ /**
62
+ * The width of the resize handle.
63
+ * @default 5
64
+ * @example 10
65
+ */
66
+ handleWidth: number;
67
+ /**
68
+ * The minimum width of a cell.
69
+ * @default 25
70
+ * @example 50
71
+ */
72
+ cellMinWidth: number;
73
+ /**
74
+ * The node view to render the table.
75
+ * @default TableView
76
+ */
77
+ View: (new (node: Node, cellMinWidth: number, view: EditorView) => NodeView) | null;
78
+ /**
79
+ * Enables the resizing of the last column.
80
+ * @default true
81
+ * @example false
82
+ */
83
+ lastColumnResizable: boolean;
84
+ /**
85
+ * Allow table node selection.
86
+ * @default false
87
+ * @example true
88
+ */
89
+ allowTableNodeSelection: boolean;
90
+ }
91
+ declare module '@tiptap/core' {
92
+ interface Commands<ReturnType> {
93
+ table: {
94
+ /**
95
+ * Insert a table
96
+ * @param options The table attributes
97
+ * @returns True if the command was successful, otherwise false
98
+ * @example editor.commands.insertTable({ rows: 3, cols: 3, withHeaderRow: true })
99
+ */
100
+ insertTable: (options?: {
101
+ rows?: number;
102
+ cols?: number;
103
+ withHeaderRow?: boolean;
104
+ }) => ReturnType;
105
+ /**
106
+ * Add a column before the current column
107
+ * @returns True if the command was successful, otherwise false
108
+ * @example editor.commands.addColumnBefore()
109
+ */
110
+ addColumnBefore: () => ReturnType;
111
+ /**
112
+ * Add a column after the current column
113
+ * @returns True if the command was successful, otherwise false
114
+ * @example editor.commands.addColumnAfter()
115
+ */
116
+ addColumnAfter: () => ReturnType;
117
+ /**
118
+ * Delete the current column
119
+ * @returns True if the command was successful, otherwise false
120
+ * @example editor.commands.deleteColumn()
121
+ */
122
+ deleteColumn: () => ReturnType;
123
+ /**
124
+ * Add a row before the current row
125
+ * @returns True if the command was successful, otherwise false
126
+ * @example editor.commands.addRowBefore()
127
+ */
128
+ addRowBefore: () => ReturnType;
129
+ /**
130
+ * Add a row after the current row
131
+ * @returns True if the command was successful, otherwise false
132
+ * @example editor.commands.addRowAfter()
133
+ */
134
+ addRowAfter: () => ReturnType;
135
+ /**
136
+ * Delete the current row
137
+ * @returns True if the command was successful, otherwise false
138
+ * @example editor.commands.deleteRow()
139
+ */
140
+ deleteRow: () => ReturnType;
141
+ /**
142
+ * Delete the current table
143
+ * @returns True if the command was successful, otherwise false
144
+ * @example editor.commands.deleteTable()
145
+ */
146
+ deleteTable: () => ReturnType;
147
+ /**
148
+ * Merge the currently selected cells
149
+ * @returns True if the command was successful, otherwise false
150
+ * @example editor.commands.mergeCells()
151
+ */
152
+ mergeCells: () => ReturnType;
153
+ /**
154
+ * Split the currently selected cell
155
+ * @returns True if the command was successful, otherwise false
156
+ * @example editor.commands.splitCell()
157
+ */
158
+ splitCell: () => ReturnType;
159
+ /**
160
+ * Toggle the header column
161
+ * @returns True if the command was successful, otherwise false
162
+ * @example editor.commands.toggleHeaderColumn()
163
+ */
164
+ toggleHeaderColumn: () => ReturnType;
165
+ /**
166
+ * Toggle the header row
167
+ * @returns True if the command was successful, otherwise false
168
+ * @example editor.commands.toggleHeaderRow()
169
+ */
170
+ toggleHeaderRow: () => ReturnType;
171
+ /**
172
+ * Toggle the header cell
173
+ * @returns True if the command was successful, otherwise false
174
+ * @example editor.commands.toggleHeaderCell()
175
+ */
176
+ toggleHeaderCell: () => ReturnType;
177
+ /**
178
+ * Merge or split the currently selected cells
179
+ * @returns True if the command was successful, otherwise false
180
+ * @example editor.commands.mergeOrSplit()
181
+ */
182
+ mergeOrSplit: () => ReturnType;
183
+ /**
184
+ * Set a cell attribute
185
+ * @param name The attribute name
186
+ * @param value The attribute value
187
+ * @returns True if the command was successful, otherwise false
188
+ * @example editor.commands.setCellAttribute('align', 'right')
189
+ */
190
+ setCellAttribute: (name: string, value: any) => ReturnType;
191
+ /**
192
+ * Moves the selection to the next cell
193
+ * @returns True if the command was successful, otherwise false
194
+ * @example editor.commands.goToNextCell()
195
+ */
196
+ goToNextCell: () => ReturnType;
197
+ /**
198
+ * Moves the selection to the previous cell
199
+ * @returns True if the command was successful, otherwise false
200
+ * @example editor.commands.goToPreviousCell()
201
+ */
202
+ goToPreviousCell: () => ReturnType;
203
+ /**
204
+ * Try to fix the table structure if necessary
205
+ * @returns True if the command was successful, otherwise false
206
+ * @example editor.commands.fixTables()
207
+ */
208
+ fixTables: () => ReturnType;
209
+ /**
210
+ * Set a cell selection inside the current table
211
+ * @param position The cell position
212
+ * @returns True if the command was successful, otherwise false
213
+ * @example editor.commands.setCellSelection({ anchorCell: 1, headCell: 2 })
214
+ */
215
+ setCellSelection: (position: {
216
+ anchorCell: number;
217
+ headCell?: number;
218
+ }) => ReturnType;
219
+ };
220
+ }
221
+ }
222
+
223
+ interface TableKitOptions {
224
+ /**
225
+ * If set to false, the table extension will not be registered
226
+ * @example table: false
227
+ */
228
+ table: Partial<TableOptions> | false;
229
+ /**
230
+ * If set to false, the table extension will not be registered
231
+ * @example tableCell: false
232
+ */
233
+ tableCell: Partial<TableCellOptions> | false;
234
+ /**
235
+ * If set to false, the table extension will not be registered
236
+ * @example tableHeader: false
237
+ */
238
+ tableHeader: Partial<TableHeaderOptions> | false;
239
+ /**
240
+ * If set to false, the table extension will not be registered
241
+ * @example tableRow: false
242
+ */
243
+ tableRow: Partial<TableRowOptions> | false;
244
+ }
245
+ /**
246
+ * The table kit is a collection of table editor extensions.
247
+ *
248
+ * It’s a good starting point for building your own table in Tiptap.
249
+ */
250
+ declare const TableKit: Extension<TableKitOptions, any>;
251
+
252
+ export { TableKit, type TableKitOptions };
@@ -0,0 +1,252 @@
1
+ import { ParentConfig, Extension } from '@tiptap/core';
2
+ import { Node } 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 TableCellOptions {
22
+ /**
23
+ * The HTML attributes for a table cell node.
24
+ * @default {}
25
+ * @example { class: 'foo' }
26
+ */
27
+ HTMLAttributes: Record<string, any>;
28
+ }
29
+
30
+ interface TableHeaderOptions {
31
+ /**
32
+ * The HTML attributes for a table header node.
33
+ * @default {}
34
+ * @example { class: 'foo' }
35
+ */
36
+ HTMLAttributes: Record<string, any>;
37
+ }
38
+
39
+ interface TableRowOptions {
40
+ /**
41
+ * The HTML attributes for a table row node.
42
+ * @default {}
43
+ * @example { class: 'foo' }
44
+ */
45
+ HTMLAttributes: Record<string, any>;
46
+ }
47
+
48
+ interface TableOptions {
49
+ /**
50
+ * HTML attributes for the table element.
51
+ * @default {}
52
+ * @example { class: 'foo' }
53
+ */
54
+ HTMLAttributes: Record<string, any>;
55
+ /**
56
+ * Enables the resizing of tables.
57
+ * @default false
58
+ * @example true
59
+ */
60
+ resizable: boolean;
61
+ /**
62
+ * The width of the resize handle.
63
+ * @default 5
64
+ * @example 10
65
+ */
66
+ handleWidth: number;
67
+ /**
68
+ * The minimum width of a cell.
69
+ * @default 25
70
+ * @example 50
71
+ */
72
+ cellMinWidth: number;
73
+ /**
74
+ * The node view to render the table.
75
+ * @default TableView
76
+ */
77
+ View: (new (node: Node, cellMinWidth: number, view: EditorView) => NodeView) | null;
78
+ /**
79
+ * Enables the resizing of the last column.
80
+ * @default true
81
+ * @example false
82
+ */
83
+ lastColumnResizable: boolean;
84
+ /**
85
+ * Allow table node selection.
86
+ * @default false
87
+ * @example true
88
+ */
89
+ allowTableNodeSelection: boolean;
90
+ }
91
+ declare module '@tiptap/core' {
92
+ interface Commands<ReturnType> {
93
+ table: {
94
+ /**
95
+ * Insert a table
96
+ * @param options The table attributes
97
+ * @returns True if the command was successful, otherwise false
98
+ * @example editor.commands.insertTable({ rows: 3, cols: 3, withHeaderRow: true })
99
+ */
100
+ insertTable: (options?: {
101
+ rows?: number;
102
+ cols?: number;
103
+ withHeaderRow?: boolean;
104
+ }) => ReturnType;
105
+ /**
106
+ * Add a column before the current column
107
+ * @returns True if the command was successful, otherwise false
108
+ * @example editor.commands.addColumnBefore()
109
+ */
110
+ addColumnBefore: () => ReturnType;
111
+ /**
112
+ * Add a column after the current column
113
+ * @returns True if the command was successful, otherwise false
114
+ * @example editor.commands.addColumnAfter()
115
+ */
116
+ addColumnAfter: () => ReturnType;
117
+ /**
118
+ * Delete the current column
119
+ * @returns True if the command was successful, otherwise false
120
+ * @example editor.commands.deleteColumn()
121
+ */
122
+ deleteColumn: () => ReturnType;
123
+ /**
124
+ * Add a row before the current row
125
+ * @returns True if the command was successful, otherwise false
126
+ * @example editor.commands.addRowBefore()
127
+ */
128
+ addRowBefore: () => ReturnType;
129
+ /**
130
+ * Add a row after the current row
131
+ * @returns True if the command was successful, otherwise false
132
+ * @example editor.commands.addRowAfter()
133
+ */
134
+ addRowAfter: () => ReturnType;
135
+ /**
136
+ * Delete the current row
137
+ * @returns True if the command was successful, otherwise false
138
+ * @example editor.commands.deleteRow()
139
+ */
140
+ deleteRow: () => ReturnType;
141
+ /**
142
+ * Delete the current table
143
+ * @returns True if the command was successful, otherwise false
144
+ * @example editor.commands.deleteTable()
145
+ */
146
+ deleteTable: () => ReturnType;
147
+ /**
148
+ * Merge the currently selected cells
149
+ * @returns True if the command was successful, otherwise false
150
+ * @example editor.commands.mergeCells()
151
+ */
152
+ mergeCells: () => ReturnType;
153
+ /**
154
+ * Split the currently selected cell
155
+ * @returns True if the command was successful, otherwise false
156
+ * @example editor.commands.splitCell()
157
+ */
158
+ splitCell: () => ReturnType;
159
+ /**
160
+ * Toggle the header column
161
+ * @returns True if the command was successful, otherwise false
162
+ * @example editor.commands.toggleHeaderColumn()
163
+ */
164
+ toggleHeaderColumn: () => ReturnType;
165
+ /**
166
+ * Toggle the header row
167
+ * @returns True if the command was successful, otherwise false
168
+ * @example editor.commands.toggleHeaderRow()
169
+ */
170
+ toggleHeaderRow: () => ReturnType;
171
+ /**
172
+ * Toggle the header cell
173
+ * @returns True if the command was successful, otherwise false
174
+ * @example editor.commands.toggleHeaderCell()
175
+ */
176
+ toggleHeaderCell: () => ReturnType;
177
+ /**
178
+ * Merge or split the currently selected cells
179
+ * @returns True if the command was successful, otherwise false
180
+ * @example editor.commands.mergeOrSplit()
181
+ */
182
+ mergeOrSplit: () => ReturnType;
183
+ /**
184
+ * Set a cell attribute
185
+ * @param name The attribute name
186
+ * @param value The attribute value
187
+ * @returns True if the command was successful, otherwise false
188
+ * @example editor.commands.setCellAttribute('align', 'right')
189
+ */
190
+ setCellAttribute: (name: string, value: any) => ReturnType;
191
+ /**
192
+ * Moves the selection to the next cell
193
+ * @returns True if the command was successful, otherwise false
194
+ * @example editor.commands.goToNextCell()
195
+ */
196
+ goToNextCell: () => ReturnType;
197
+ /**
198
+ * Moves the selection to the previous cell
199
+ * @returns True if the command was successful, otherwise false
200
+ * @example editor.commands.goToPreviousCell()
201
+ */
202
+ goToPreviousCell: () => ReturnType;
203
+ /**
204
+ * Try to fix the table structure if necessary
205
+ * @returns True if the command was successful, otherwise false
206
+ * @example editor.commands.fixTables()
207
+ */
208
+ fixTables: () => ReturnType;
209
+ /**
210
+ * Set a cell selection inside the current table
211
+ * @param position The cell position
212
+ * @returns True if the command was successful, otherwise false
213
+ * @example editor.commands.setCellSelection({ anchorCell: 1, headCell: 2 })
214
+ */
215
+ setCellSelection: (position: {
216
+ anchorCell: number;
217
+ headCell?: number;
218
+ }) => ReturnType;
219
+ };
220
+ }
221
+ }
222
+
223
+ interface TableKitOptions {
224
+ /**
225
+ * If set to false, the table extension will not be registered
226
+ * @example table: false
227
+ */
228
+ table: Partial<TableOptions> | false;
229
+ /**
230
+ * If set to false, the table extension will not be registered
231
+ * @example tableCell: false
232
+ */
233
+ tableCell: Partial<TableCellOptions> | false;
234
+ /**
235
+ * If set to false, the table extension will not be registered
236
+ * @example tableHeader: false
237
+ */
238
+ tableHeader: Partial<TableHeaderOptions> | false;
239
+ /**
240
+ * If set to false, the table extension will not be registered
241
+ * @example tableRow: false
242
+ */
243
+ tableRow: Partial<TableRowOptions> | false;
244
+ }
245
+ /**
246
+ * The table kit is a collection of table editor extensions.
247
+ *
248
+ * It’s a good starting point for building your own table in Tiptap.
249
+ */
250
+ declare const TableKit: Extension<TableKitOptions, any>;
251
+
252
+ export { TableKit, type TableKitOptions };