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