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