@tiptap/extension-table 2.0.0-beta.21 → 2.0.0-beta.210

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.
package/dist/index.cjs ADDED
@@ -0,0 +1,326 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/table.ts
2
+
3
+
4
+
5
+
6
+
7
+ var _core = require('@tiptap/core');
8
+ var _state = require('@tiptap/pm/state');
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+ var _tables = require('@tiptap/pm/tables');
28
+
29
+ // src/TableView.ts
30
+ function updateColumns(node, colgroup, table, cellMinWidth, overrideCol, overrideValue) {
31
+ let totalWidth = 0;
32
+ let fixedWidth = true;
33
+ let nextDOM = colgroup.firstChild;
34
+ const row = node.firstChild;
35
+ for (let i = 0, col = 0; i < row.childCount; i += 1) {
36
+ const { colspan, colwidth } = row.child(i).attrs;
37
+ for (let j = 0; j < colspan; j += 1, col += 1) {
38
+ const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j];
39
+ const cssWidth = hasWidth ? `${hasWidth}px` : "";
40
+ totalWidth += hasWidth || cellMinWidth;
41
+ if (!hasWidth) {
42
+ fixedWidth = false;
43
+ }
44
+ if (!nextDOM) {
45
+ colgroup.appendChild(document.createElement("col")).style.width = cssWidth;
46
+ } else {
47
+ if (nextDOM.style.width !== cssWidth) {
48
+ nextDOM.style.width = cssWidth;
49
+ }
50
+ nextDOM = nextDOM.nextSibling;
51
+ }
52
+ }
53
+ }
54
+ while (nextDOM) {
55
+ const after = nextDOM.nextSibling;
56
+ nextDOM.parentNode.removeChild(nextDOM);
57
+ nextDOM = after;
58
+ }
59
+ if (fixedWidth) {
60
+ table.style.width = `${totalWidth}px`;
61
+ table.style.minWidth = "";
62
+ } else {
63
+ table.style.width = "";
64
+ table.style.minWidth = `${totalWidth}px`;
65
+ }
66
+ }
67
+ var TableView = class {
68
+ constructor(node, cellMinWidth) {
69
+ this.node = node;
70
+ this.cellMinWidth = cellMinWidth;
71
+ this.dom = document.createElement("div");
72
+ this.dom.className = "tableWrapper";
73
+ this.table = this.dom.appendChild(document.createElement("table"));
74
+ this.colgroup = this.table.appendChild(document.createElement("colgroup"));
75
+ updateColumns(node, this.colgroup, this.table, cellMinWidth);
76
+ this.contentDOM = this.table.appendChild(document.createElement("tbody"));
77
+ }
78
+ update(node) {
79
+ if (node.type !== this.node.type) {
80
+ return false;
81
+ }
82
+ this.node = node;
83
+ updateColumns(node, this.colgroup, this.table, this.cellMinWidth);
84
+ return true;
85
+ }
86
+ ignoreMutation(mutation) {
87
+ return mutation.type === "attributes" && (mutation.target === this.table || this.colgroup.contains(mutation.target));
88
+ }
89
+ };
90
+
91
+ // src/utilities/createCell.ts
92
+ function createCell(cellType, cellContent) {
93
+ if (cellContent) {
94
+ return cellType.createChecked(null, cellContent);
95
+ }
96
+ return cellType.createAndFill();
97
+ }
98
+
99
+ // src/utilities/getTableNodeTypes.ts
100
+ function getTableNodeTypes(schema) {
101
+ if (schema.cached.tableNodeTypes) {
102
+ return schema.cached.tableNodeTypes;
103
+ }
104
+ const roles = {};
105
+ Object.keys(schema.nodes).forEach((type) => {
106
+ const nodeType = schema.nodes[type];
107
+ if (nodeType.spec.tableRole) {
108
+ roles[nodeType.spec.tableRole] = nodeType;
109
+ }
110
+ });
111
+ schema.cached.tableNodeTypes = roles;
112
+ return roles;
113
+ }
114
+
115
+ // src/utilities/createTable.ts
116
+ function createTable(schema, rowsCount, colsCount, withHeaderRow, cellContent) {
117
+ const types = getTableNodeTypes(schema);
118
+ const headerCells = [];
119
+ const cells = [];
120
+ for (let index = 0; index < colsCount; index += 1) {
121
+ const cell = createCell(types.cell, cellContent);
122
+ if (cell) {
123
+ cells.push(cell);
124
+ }
125
+ if (withHeaderRow) {
126
+ const headerCell = createCell(types.header_cell, cellContent);
127
+ if (headerCell) {
128
+ headerCells.push(headerCell);
129
+ }
130
+ }
131
+ }
132
+ const rows = [];
133
+ for (let index = 0; index < rowsCount; index += 1) {
134
+ rows.push(types.row.createChecked(null, withHeaderRow && index === 0 ? headerCells : cells));
135
+ }
136
+ return types.table.createChecked(null, rows);
137
+ }
138
+
139
+ // src/utilities/deleteTableWhenAllCellsSelected.ts
140
+
141
+
142
+ // src/utilities/isCellSelection.ts
143
+
144
+ function isCellSelection(value) {
145
+ return value instanceof _tables.CellSelection;
146
+ }
147
+
148
+ // src/utilities/deleteTableWhenAllCellsSelected.ts
149
+ var deleteTableWhenAllCellsSelected = ({ editor }) => {
150
+ const { selection } = editor.state;
151
+ if (!isCellSelection(selection)) {
152
+ return false;
153
+ }
154
+ let cellCount = 0;
155
+ const table = _core.findParentNodeClosestToPos.call(void 0, selection.ranges[0].$from, (node) => {
156
+ return node.type.name === "table";
157
+ });
158
+ table == null ? void 0 : table.node.descendants((node) => {
159
+ if (node.type.name === "table") {
160
+ return false;
161
+ }
162
+ if (["tableCell", "tableHeader"].includes(node.type.name)) {
163
+ cellCount += 1;
164
+ }
165
+ });
166
+ const allCellsSelected = cellCount === selection.ranges.length;
167
+ if (!allCellsSelected) {
168
+ return false;
169
+ }
170
+ editor.commands.deleteTable();
171
+ return true;
172
+ };
173
+
174
+ // src/table.ts
175
+ var Table = _core.Node.create({
176
+ name: "table",
177
+ addOptions() {
178
+ return {
179
+ HTMLAttributes: {},
180
+ resizable: false,
181
+ handleWidth: 5,
182
+ cellMinWidth: 25,
183
+ View: TableView,
184
+ lastColumnResizable: true,
185
+ allowTableNodeSelection: false
186
+ };
187
+ },
188
+ content: "tableRow+",
189
+ tableRole: "table",
190
+ isolating: true,
191
+ group: "block",
192
+ parseHTML() {
193
+ return [{ tag: "table" }];
194
+ },
195
+ renderHTML({ HTMLAttributes }) {
196
+ return ["table", _core.mergeAttributes.call(void 0, this.options.HTMLAttributes, HTMLAttributes), ["tbody", 0]];
197
+ },
198
+ addCommands() {
199
+ return {
200
+ insertTable: ({ rows = 3, cols = 3, withHeaderRow = true } = {}) => ({ tr, dispatch, editor }) => {
201
+ const node = createTable(editor.schema, rows, cols, withHeaderRow);
202
+ if (dispatch) {
203
+ const offset = tr.selection.anchor + 1;
204
+ tr.replaceSelectionWith(node).scrollIntoView().setSelection(_state.TextSelection.near(tr.doc.resolve(offset)));
205
+ }
206
+ return true;
207
+ },
208
+ addColumnBefore: () => ({ state, dispatch }) => {
209
+ return _tables.addColumnBefore.call(void 0, state, dispatch);
210
+ },
211
+ addColumnAfter: () => ({ state, dispatch }) => {
212
+ return _tables.addColumnAfter.call(void 0, state, dispatch);
213
+ },
214
+ deleteColumn: () => ({ state, dispatch }) => {
215
+ return _tables.deleteColumn.call(void 0, state, dispatch);
216
+ },
217
+ addRowBefore: () => ({ state, dispatch }) => {
218
+ return _tables.addRowBefore.call(void 0, state, dispatch);
219
+ },
220
+ addRowAfter: () => ({ state, dispatch }) => {
221
+ return _tables.addRowAfter.call(void 0, state, dispatch);
222
+ },
223
+ deleteRow: () => ({ state, dispatch }) => {
224
+ return _tables.deleteRow.call(void 0, state, dispatch);
225
+ },
226
+ deleteTable: () => ({ state, dispatch }) => {
227
+ return _tables.deleteTable.call(void 0, state, dispatch);
228
+ },
229
+ mergeCells: () => ({ state, dispatch }) => {
230
+ return _tables.mergeCells.call(void 0, state, dispatch);
231
+ },
232
+ splitCell: () => ({ state, dispatch }) => {
233
+ return _tables.splitCell.call(void 0, state, dispatch);
234
+ },
235
+ toggleHeaderColumn: () => ({ state, dispatch }) => {
236
+ return _tables.toggleHeader.call(void 0, "column")(state, dispatch);
237
+ },
238
+ toggleHeaderRow: () => ({ state, dispatch }) => {
239
+ return _tables.toggleHeader.call(void 0, "row")(state, dispatch);
240
+ },
241
+ toggleHeaderCell: () => ({ state, dispatch }) => {
242
+ return _tables.toggleHeaderCell.call(void 0, state, dispatch);
243
+ },
244
+ mergeOrSplit: () => ({ state, dispatch }) => {
245
+ if (_tables.mergeCells.call(void 0, state, dispatch)) {
246
+ return true;
247
+ }
248
+ return _tables.splitCell.call(void 0, state, dispatch);
249
+ },
250
+ setCellAttribute: (name, value) => ({ state, dispatch }) => {
251
+ return _tables.setCellAttr.call(void 0, name, value)(state, dispatch);
252
+ },
253
+ goToNextCell: () => ({ state, dispatch }) => {
254
+ return _tables.goToNextCell.call(void 0, 1)(state, dispatch);
255
+ },
256
+ goToPreviousCell: () => ({ state, dispatch }) => {
257
+ return _tables.goToNextCell.call(void 0, -1)(state, dispatch);
258
+ },
259
+ fixTables: () => ({ state, dispatch }) => {
260
+ if (dispatch) {
261
+ _tables.fixTables.call(void 0, state);
262
+ }
263
+ return true;
264
+ },
265
+ setCellSelection: (position) => ({ tr, dispatch }) => {
266
+ if (dispatch) {
267
+ const selection = _tables.CellSelection.create(tr.doc, position.anchorCell, position.headCell);
268
+ tr.setSelection(selection);
269
+ }
270
+ return true;
271
+ }
272
+ };
273
+ },
274
+ addKeyboardShortcuts() {
275
+ return {
276
+ Tab: () => {
277
+ if (this.editor.commands.goToNextCell()) {
278
+ return true;
279
+ }
280
+ if (!this.editor.can().addRowAfter()) {
281
+ return false;
282
+ }
283
+ return this.editor.chain().addRowAfter().goToNextCell().run();
284
+ },
285
+ "Shift-Tab": () => this.editor.commands.goToPreviousCell(),
286
+ Backspace: deleteTableWhenAllCellsSelected,
287
+ "Mod-Backspace": deleteTableWhenAllCellsSelected,
288
+ Delete: deleteTableWhenAllCellsSelected,
289
+ "Mod-Delete": deleteTableWhenAllCellsSelected
290
+ };
291
+ },
292
+ addProseMirrorPlugins() {
293
+ const isResizable = this.options.resizable && this.editor.isEditable;
294
+ return [
295
+ ...isResizable ? [
296
+ _tables.columnResizing.call(void 0, {
297
+ handleWidth: this.options.handleWidth,
298
+ cellMinWidth: this.options.cellMinWidth,
299
+ View: this.options.View,
300
+ lastColumnResizable: this.options.lastColumnResizable
301
+ })
302
+ ] : [],
303
+ _tables.tableEditing.call(void 0, {
304
+ allowTableNodeSelection: this.options.allowTableNodeSelection
305
+ })
306
+ ];
307
+ },
308
+ extendNodeSchema(extension) {
309
+ const context = {
310
+ name: extension.name,
311
+ options: extension.options,
312
+ storage: extension.storage
313
+ };
314
+ return {
315
+ tableRole: _core.callOrReturn.call(void 0, _core.getExtensionField.call(void 0, extension, "tableRole", context))
316
+ };
317
+ }
318
+ });
319
+
320
+ // src/index.ts
321
+ var src_default = Table;
322
+
323
+
324
+
325
+
326
+ exports.Table = Table; exports.createTable = createTable; exports.default = src_default;
@@ -0,0 +1,61 @@
1
+ import { ParentConfig, Node } from '@tiptap/core';
2
+ import { NodeView } from '@tiptap/pm/view';
3
+ import { Schema, Fragment, Node as Node$1 } from '@tiptap/pm/model';
4
+
5
+ interface TableOptions {
6
+ HTMLAttributes: Record<string, any>;
7
+ resizable: boolean;
8
+ handleWidth: number;
9
+ cellMinWidth: number;
10
+ View: NodeView;
11
+ lastColumnResizable: boolean;
12
+ allowTableNodeSelection: boolean;
13
+ }
14
+ declare module '@tiptap/core' {
15
+ interface Commands<ReturnType> {
16
+ table: {
17
+ insertTable: (options?: {
18
+ rows?: number;
19
+ cols?: number;
20
+ withHeaderRow?: boolean;
21
+ }) => ReturnType;
22
+ addColumnBefore: () => ReturnType;
23
+ addColumnAfter: () => ReturnType;
24
+ deleteColumn: () => ReturnType;
25
+ addRowBefore: () => ReturnType;
26
+ addRowAfter: () => ReturnType;
27
+ deleteRow: () => ReturnType;
28
+ deleteTable: () => ReturnType;
29
+ mergeCells: () => ReturnType;
30
+ splitCell: () => ReturnType;
31
+ toggleHeaderColumn: () => ReturnType;
32
+ toggleHeaderRow: () => ReturnType;
33
+ toggleHeaderCell: () => ReturnType;
34
+ mergeOrSplit: () => ReturnType;
35
+ setCellAttribute: (name: string, value: any) => ReturnType;
36
+ goToNextCell: () => ReturnType;
37
+ goToPreviousCell: () => ReturnType;
38
+ fixTables: () => ReturnType;
39
+ setCellSelection: (position: {
40
+ anchorCell: number;
41
+ headCell?: number;
42
+ }) => ReturnType;
43
+ };
44
+ }
45
+ interface NodeConfig<Options, Storage> {
46
+ /**
47
+ * Table Role
48
+ */
49
+ tableRole?: string | ((this: {
50
+ name: string;
51
+ options: Options;
52
+ storage: Storage;
53
+ parent: ParentConfig<NodeConfig<Options>>['tableRole'];
54
+ }) => string);
55
+ }
56
+ }
57
+ declare const Table: Node<TableOptions, any>;
58
+
59
+ declare function createTable(schema: Schema, rowsCount: number, colsCount: number, withHeaderRow: boolean, cellContent?: Fragment | Node$1 | Array<Node$1>): Node$1;
60
+
61
+ export { Table, TableOptions, createTable, Table as default };
package/dist/index.js ADDED
@@ -0,0 +1,326 @@
1
+ // src/table.ts
2
+ import {
3
+ callOrReturn,
4
+ getExtensionField,
5
+ mergeAttributes,
6
+ Node
7
+ } from "@tiptap/core";
8
+ import { TextSelection } from "@tiptap/pm/state";
9
+ import {
10
+ addColumnAfter,
11
+ addColumnBefore,
12
+ addRowAfter,
13
+ addRowBefore,
14
+ CellSelection as CellSelection2,
15
+ columnResizing,
16
+ deleteColumn,
17
+ deleteRow,
18
+ deleteTable,
19
+ fixTables,
20
+ goToNextCell,
21
+ mergeCells,
22
+ setCellAttr,
23
+ splitCell,
24
+ tableEditing,
25
+ toggleHeader,
26
+ toggleHeaderCell
27
+ } from "@tiptap/pm/tables";
28
+
29
+ // src/TableView.ts
30
+ function updateColumns(node, colgroup, table, cellMinWidth, overrideCol, overrideValue) {
31
+ let totalWidth = 0;
32
+ let fixedWidth = true;
33
+ let nextDOM = colgroup.firstChild;
34
+ const row = node.firstChild;
35
+ for (let i = 0, col = 0; i < row.childCount; i += 1) {
36
+ const { colspan, colwidth } = row.child(i).attrs;
37
+ for (let j = 0; j < colspan; j += 1, col += 1) {
38
+ const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j];
39
+ const cssWidth = hasWidth ? `${hasWidth}px` : "";
40
+ totalWidth += hasWidth || cellMinWidth;
41
+ if (!hasWidth) {
42
+ fixedWidth = false;
43
+ }
44
+ if (!nextDOM) {
45
+ colgroup.appendChild(document.createElement("col")).style.width = cssWidth;
46
+ } else {
47
+ if (nextDOM.style.width !== cssWidth) {
48
+ nextDOM.style.width = cssWidth;
49
+ }
50
+ nextDOM = nextDOM.nextSibling;
51
+ }
52
+ }
53
+ }
54
+ while (nextDOM) {
55
+ const after = nextDOM.nextSibling;
56
+ nextDOM.parentNode.removeChild(nextDOM);
57
+ nextDOM = after;
58
+ }
59
+ if (fixedWidth) {
60
+ table.style.width = `${totalWidth}px`;
61
+ table.style.minWidth = "";
62
+ } else {
63
+ table.style.width = "";
64
+ table.style.minWidth = `${totalWidth}px`;
65
+ }
66
+ }
67
+ var TableView = class {
68
+ constructor(node, cellMinWidth) {
69
+ this.node = node;
70
+ this.cellMinWidth = cellMinWidth;
71
+ this.dom = document.createElement("div");
72
+ this.dom.className = "tableWrapper";
73
+ this.table = this.dom.appendChild(document.createElement("table"));
74
+ this.colgroup = this.table.appendChild(document.createElement("colgroup"));
75
+ updateColumns(node, this.colgroup, this.table, cellMinWidth);
76
+ this.contentDOM = this.table.appendChild(document.createElement("tbody"));
77
+ }
78
+ update(node) {
79
+ if (node.type !== this.node.type) {
80
+ return false;
81
+ }
82
+ this.node = node;
83
+ updateColumns(node, this.colgroup, this.table, this.cellMinWidth);
84
+ return true;
85
+ }
86
+ ignoreMutation(mutation) {
87
+ return mutation.type === "attributes" && (mutation.target === this.table || this.colgroup.contains(mutation.target));
88
+ }
89
+ };
90
+
91
+ // src/utilities/createCell.ts
92
+ function createCell(cellType, cellContent) {
93
+ if (cellContent) {
94
+ return cellType.createChecked(null, cellContent);
95
+ }
96
+ return cellType.createAndFill();
97
+ }
98
+
99
+ // src/utilities/getTableNodeTypes.ts
100
+ function getTableNodeTypes(schema) {
101
+ if (schema.cached.tableNodeTypes) {
102
+ return schema.cached.tableNodeTypes;
103
+ }
104
+ const roles = {};
105
+ Object.keys(schema.nodes).forEach((type) => {
106
+ const nodeType = schema.nodes[type];
107
+ if (nodeType.spec.tableRole) {
108
+ roles[nodeType.spec.tableRole] = nodeType;
109
+ }
110
+ });
111
+ schema.cached.tableNodeTypes = roles;
112
+ return roles;
113
+ }
114
+
115
+ // src/utilities/createTable.ts
116
+ function createTable(schema, rowsCount, colsCount, withHeaderRow, cellContent) {
117
+ const types = getTableNodeTypes(schema);
118
+ const headerCells = [];
119
+ const cells = [];
120
+ for (let index = 0; index < colsCount; index += 1) {
121
+ const cell = createCell(types.cell, cellContent);
122
+ if (cell) {
123
+ cells.push(cell);
124
+ }
125
+ if (withHeaderRow) {
126
+ const headerCell = createCell(types.header_cell, cellContent);
127
+ if (headerCell) {
128
+ headerCells.push(headerCell);
129
+ }
130
+ }
131
+ }
132
+ const rows = [];
133
+ for (let index = 0; index < rowsCount; index += 1) {
134
+ rows.push(types.row.createChecked(null, withHeaderRow && index === 0 ? headerCells : cells));
135
+ }
136
+ return types.table.createChecked(null, rows);
137
+ }
138
+
139
+ // src/utilities/deleteTableWhenAllCellsSelected.ts
140
+ import { findParentNodeClosestToPos } from "@tiptap/core";
141
+
142
+ // src/utilities/isCellSelection.ts
143
+ import { CellSelection } from "@tiptap/pm/tables";
144
+ function isCellSelection(value) {
145
+ return value instanceof CellSelection;
146
+ }
147
+
148
+ // src/utilities/deleteTableWhenAllCellsSelected.ts
149
+ var deleteTableWhenAllCellsSelected = ({ editor }) => {
150
+ const { selection } = editor.state;
151
+ if (!isCellSelection(selection)) {
152
+ return false;
153
+ }
154
+ let cellCount = 0;
155
+ const table = findParentNodeClosestToPos(selection.ranges[0].$from, (node) => {
156
+ return node.type.name === "table";
157
+ });
158
+ table == null ? void 0 : table.node.descendants((node) => {
159
+ if (node.type.name === "table") {
160
+ return false;
161
+ }
162
+ if (["tableCell", "tableHeader"].includes(node.type.name)) {
163
+ cellCount += 1;
164
+ }
165
+ });
166
+ const allCellsSelected = cellCount === selection.ranges.length;
167
+ if (!allCellsSelected) {
168
+ return false;
169
+ }
170
+ editor.commands.deleteTable();
171
+ return true;
172
+ };
173
+
174
+ // src/table.ts
175
+ var Table = Node.create({
176
+ name: "table",
177
+ addOptions() {
178
+ return {
179
+ HTMLAttributes: {},
180
+ resizable: false,
181
+ handleWidth: 5,
182
+ cellMinWidth: 25,
183
+ View: TableView,
184
+ lastColumnResizable: true,
185
+ allowTableNodeSelection: false
186
+ };
187
+ },
188
+ content: "tableRow+",
189
+ tableRole: "table",
190
+ isolating: true,
191
+ group: "block",
192
+ parseHTML() {
193
+ return [{ tag: "table" }];
194
+ },
195
+ renderHTML({ HTMLAttributes }) {
196
+ return ["table", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), ["tbody", 0]];
197
+ },
198
+ addCommands() {
199
+ return {
200
+ insertTable: ({ rows = 3, cols = 3, withHeaderRow = true } = {}) => ({ tr, dispatch, editor }) => {
201
+ const node = createTable(editor.schema, rows, cols, withHeaderRow);
202
+ if (dispatch) {
203
+ const offset = tr.selection.anchor + 1;
204
+ tr.replaceSelectionWith(node).scrollIntoView().setSelection(TextSelection.near(tr.doc.resolve(offset)));
205
+ }
206
+ return true;
207
+ },
208
+ addColumnBefore: () => ({ state, dispatch }) => {
209
+ return addColumnBefore(state, dispatch);
210
+ },
211
+ addColumnAfter: () => ({ state, dispatch }) => {
212
+ return addColumnAfter(state, dispatch);
213
+ },
214
+ deleteColumn: () => ({ state, dispatch }) => {
215
+ return deleteColumn(state, dispatch);
216
+ },
217
+ addRowBefore: () => ({ state, dispatch }) => {
218
+ return addRowBefore(state, dispatch);
219
+ },
220
+ addRowAfter: () => ({ state, dispatch }) => {
221
+ return addRowAfter(state, dispatch);
222
+ },
223
+ deleteRow: () => ({ state, dispatch }) => {
224
+ return deleteRow(state, dispatch);
225
+ },
226
+ deleteTable: () => ({ state, dispatch }) => {
227
+ return deleteTable(state, dispatch);
228
+ },
229
+ mergeCells: () => ({ state, dispatch }) => {
230
+ return mergeCells(state, dispatch);
231
+ },
232
+ splitCell: () => ({ state, dispatch }) => {
233
+ return splitCell(state, dispatch);
234
+ },
235
+ toggleHeaderColumn: () => ({ state, dispatch }) => {
236
+ return toggleHeader("column")(state, dispatch);
237
+ },
238
+ toggleHeaderRow: () => ({ state, dispatch }) => {
239
+ return toggleHeader("row")(state, dispatch);
240
+ },
241
+ toggleHeaderCell: () => ({ state, dispatch }) => {
242
+ return toggleHeaderCell(state, dispatch);
243
+ },
244
+ mergeOrSplit: () => ({ state, dispatch }) => {
245
+ if (mergeCells(state, dispatch)) {
246
+ return true;
247
+ }
248
+ return splitCell(state, dispatch);
249
+ },
250
+ setCellAttribute: (name, value) => ({ state, dispatch }) => {
251
+ return setCellAttr(name, value)(state, dispatch);
252
+ },
253
+ goToNextCell: () => ({ state, dispatch }) => {
254
+ return goToNextCell(1)(state, dispatch);
255
+ },
256
+ goToPreviousCell: () => ({ state, dispatch }) => {
257
+ return goToNextCell(-1)(state, dispatch);
258
+ },
259
+ fixTables: () => ({ state, dispatch }) => {
260
+ if (dispatch) {
261
+ fixTables(state);
262
+ }
263
+ return true;
264
+ },
265
+ setCellSelection: (position) => ({ tr, dispatch }) => {
266
+ if (dispatch) {
267
+ const selection = CellSelection2.create(tr.doc, position.anchorCell, position.headCell);
268
+ tr.setSelection(selection);
269
+ }
270
+ return true;
271
+ }
272
+ };
273
+ },
274
+ addKeyboardShortcuts() {
275
+ return {
276
+ Tab: () => {
277
+ if (this.editor.commands.goToNextCell()) {
278
+ return true;
279
+ }
280
+ if (!this.editor.can().addRowAfter()) {
281
+ return false;
282
+ }
283
+ return this.editor.chain().addRowAfter().goToNextCell().run();
284
+ },
285
+ "Shift-Tab": () => this.editor.commands.goToPreviousCell(),
286
+ Backspace: deleteTableWhenAllCellsSelected,
287
+ "Mod-Backspace": deleteTableWhenAllCellsSelected,
288
+ Delete: deleteTableWhenAllCellsSelected,
289
+ "Mod-Delete": deleteTableWhenAllCellsSelected
290
+ };
291
+ },
292
+ addProseMirrorPlugins() {
293
+ const isResizable = this.options.resizable && this.editor.isEditable;
294
+ return [
295
+ ...isResizable ? [
296
+ columnResizing({
297
+ handleWidth: this.options.handleWidth,
298
+ cellMinWidth: this.options.cellMinWidth,
299
+ View: this.options.View,
300
+ lastColumnResizable: this.options.lastColumnResizable
301
+ })
302
+ ] : [],
303
+ tableEditing({
304
+ allowTableNodeSelection: this.options.allowTableNodeSelection
305
+ })
306
+ ];
307
+ },
308
+ extendNodeSchema(extension) {
309
+ const context = {
310
+ name: extension.name,
311
+ options: extension.options,
312
+ storage: extension.storage
313
+ };
314
+ return {
315
+ tableRole: callOrReturn(getExtensionField(extension, "tableRole", context))
316
+ };
317
+ }
318
+ });
319
+
320
+ // src/index.ts
321
+ var src_default = Table;
322
+ export {
323
+ Table,
324
+ createTable,
325
+ src_default as default
326
+ };