@tiptap/extension-table 2.11.7 → 3.0.0-beta.0

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 (78) 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 +475 -331
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +291 -0
  18. package/dist/index.d.ts +291 -7
  19. package/dist/index.js +462 -324
  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.d.ts → table/index.d.cts} +43 -19
  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 +52 -10
  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 -8
  45. package/src/kit/index.ts +64 -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} +6 -9
  49. package/src/table/index.ts +3 -0
  50. package/src/{table.ts → table/table.ts} +54 -60
  51. package/src/{utilities → table/utilities}/colStyle.ts +0 -1
  52. package/src/{utilities → table/utilities}/createCell.ts +1 -1
  53. package/src/{utilities → table/utilities}/createColGroup.ts +11 -15
  54. package/src/{utilities → table/utilities}/createTable.ts +1 -1
  55. package/src/{utilities → table/utilities}/deleteTableWhenAllCellsSelected.ts +2 -1
  56. package/src/{utilities → table/utilities}/getTableNodeTypes.ts +1 -1
  57. package/src/types.ts +19 -0
  58. package/dist/TableView.d.ts +0 -16
  59. package/dist/TableView.d.ts.map +0 -1
  60. package/dist/index.d.ts.map +0 -1
  61. package/dist/index.umd.js +0 -369
  62. package/dist/index.umd.js.map +0 -1
  63. package/dist/table.d.ts.map +0 -1
  64. package/dist/utilities/colStyle.d.ts +0 -2
  65. package/dist/utilities/colStyle.d.ts.map +0 -1
  66. package/dist/utilities/createCell.d.ts +0 -3
  67. package/dist/utilities/createCell.d.ts.map +0 -1
  68. package/dist/utilities/createColGroup.d.ts +0 -18
  69. package/dist/utilities/createColGroup.d.ts.map +0 -1
  70. package/dist/utilities/createTable.d.ts +0 -3
  71. package/dist/utilities/createTable.d.ts.map +0 -1
  72. package/dist/utilities/deleteTableWhenAllCellsSelected.d.ts +0 -3
  73. package/dist/utilities/deleteTableWhenAllCellsSelected.d.ts.map +0 -1
  74. package/dist/utilities/getTableNodeTypes.d.ts +0 -5
  75. package/dist/utilities/getTableNodeTypes.d.ts.map +0 -1
  76. package/dist/utilities/isCellSelection.d.ts +0 -3
  77. package/dist/utilities/isCellSelection.d.ts.map +0 -1
  78. /package/src/{utilities → table/utilities}/isCellSelection.ts +0 -0
package/dist/index.cjs CHANGED
@@ -1,367 +1,511 @@
1
- 'use strict';
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
2
19
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ Table: () => Table,
24
+ TableCell: () => TableCell,
25
+ TableHeader: () => TableHeader,
26
+ TableKit: () => TableKit,
27
+ TableRow: () => TableRow,
28
+ createColGroup: () => createColGroup,
29
+ createTable: () => createTable
30
+ });
31
+ module.exports = __toCommonJS(index_exports);
4
32
 
5
- var core = require('@tiptap/core');
6
- var state = require('@tiptap/pm/state');
7
- var tables = require('@tiptap/pm/tables');
33
+ // src/cell/table-cell.ts
34
+ var import_core = require("@tiptap/core");
35
+ var TableCell = import_core.Node.create({
36
+ name: "tableCell",
37
+ addOptions() {
38
+ return {
39
+ HTMLAttributes: {}
40
+ };
41
+ },
42
+ content: "block+",
43
+ addAttributes() {
44
+ return {
45
+ colspan: {
46
+ default: 1
47
+ },
48
+ rowspan: {
49
+ default: 1
50
+ },
51
+ colwidth: {
52
+ default: null,
53
+ parseHTML: (element) => {
54
+ const colwidth = element.getAttribute("colwidth");
55
+ const value = colwidth ? colwidth.split(",").map((width) => parseInt(width, 10)) : null;
56
+ return value;
57
+ }
58
+ }
59
+ };
60
+ },
61
+ tableRole: "cell",
62
+ isolating: true,
63
+ parseHTML() {
64
+ return [{ tag: "td" }];
65
+ },
66
+ renderHTML({ HTMLAttributes }) {
67
+ return ["td", (0, import_core.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes), 0];
68
+ }
69
+ });
8
70
 
71
+ // src/header/table-header.ts
72
+ var import_core2 = require("@tiptap/core");
73
+ var TableHeader = import_core2.Node.create({
74
+ name: "tableHeader",
75
+ addOptions() {
76
+ return {
77
+ HTMLAttributes: {}
78
+ };
79
+ },
80
+ content: "block+",
81
+ addAttributes() {
82
+ return {
83
+ colspan: {
84
+ default: 1
85
+ },
86
+ rowspan: {
87
+ default: 1
88
+ },
89
+ colwidth: {
90
+ default: null,
91
+ parseHTML: (element) => {
92
+ const colwidth = element.getAttribute("colwidth");
93
+ const value = colwidth ? colwidth.split(",").map((width) => parseInt(width, 10)) : null;
94
+ return value;
95
+ }
96
+ }
97
+ };
98
+ },
99
+ tableRole: "header_cell",
100
+ isolating: true,
101
+ parseHTML() {
102
+ return [{ tag: "th" }];
103
+ },
104
+ renderHTML({ HTMLAttributes }) {
105
+ return ["th", (0, import_core2.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes), 0];
106
+ }
107
+ });
108
+
109
+ // src/kit/index.ts
110
+ var import_core6 = require("@tiptap/core");
111
+
112
+ // src/row/table-row.ts
113
+ var import_core3 = require("@tiptap/core");
114
+ var TableRow = import_core3.Node.create({
115
+ name: "tableRow",
116
+ addOptions() {
117
+ return {
118
+ HTMLAttributes: {}
119
+ };
120
+ },
121
+ content: "(tableCell | tableHeader)*",
122
+ tableRole: "row",
123
+ parseHTML() {
124
+ return [{ tag: "tr" }];
125
+ },
126
+ renderHTML({ HTMLAttributes }) {
127
+ return ["tr", (0, import_core3.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes), 0];
128
+ }
129
+ });
130
+
131
+ // src/table/table.ts
132
+ var import_core5 = require("@tiptap/core");
133
+ var import_state = require("@tiptap/pm/state");
134
+ var import_tables2 = require("@tiptap/pm/tables");
135
+
136
+ // src/table/utilities/colStyle.ts
9
137
  function getColStyleDeclaration(minWidth, width) {
10
- if (width) {
11
- // apply the stored width unless it is below the configured minimum cell width
12
- return ['width', `${Math.max(width, minWidth)}px`];
13
- }
14
- // set the minimum with on the column if it has no stored width
15
- return ['min-width', `${minWidth}px`];
138
+ if (width) {
139
+ return ["width", `${Math.max(width, minWidth)}px`];
140
+ }
141
+ return ["min-width", `${minWidth}px`];
16
142
  }
17
143
 
18
- function updateColumns(node, colgroup, // <colgroup> has the same prototype as <col>
19
- table, cellMinWidth, overrideCol, overrideValue) {
20
- var _a;
21
- let totalWidth = 0;
22
- let fixedWidth = true;
23
- let nextDOM = colgroup.firstChild;
24
- const row = node.firstChild;
25
- if (row !== null) {
26
- for (let i = 0, col = 0; i < row.childCount; i += 1) {
27
- const { colspan, colwidth } = row.child(i).attrs;
28
- for (let j = 0; j < colspan; j += 1, col += 1) {
29
- const hasWidth = overrideCol === col ? overrideValue : (colwidth && colwidth[j]);
30
- const cssWidth = hasWidth ? `${hasWidth}px` : '';
31
- totalWidth += hasWidth || cellMinWidth;
32
- if (!hasWidth) {
33
- fixedWidth = false;
34
- }
35
- if (!nextDOM) {
36
- const colElement = document.createElement('col');
37
- const [propertyKey, propertyValue] = getColStyleDeclaration(cellMinWidth, hasWidth);
38
- colElement.style.setProperty(propertyKey, propertyValue);
39
- colgroup.appendChild(colElement);
40
- }
41
- else {
42
- if (nextDOM.style.width !== cssWidth) {
43
- const [propertyKey, propertyValue] = getColStyleDeclaration(cellMinWidth, hasWidth);
44
- nextDOM.style.setProperty(propertyKey, propertyValue);
45
- }
46
- nextDOM = nextDOM.nextSibling;
47
- }
48
- }
144
+ // src/table/TableView.ts
145
+ function updateColumns(node, colgroup, table, cellMinWidth, overrideCol, overrideValue) {
146
+ var _a;
147
+ let totalWidth = 0;
148
+ let fixedWidth = true;
149
+ let nextDOM = colgroup.firstChild;
150
+ const row = node.firstChild;
151
+ if (row !== null) {
152
+ for (let i = 0, col = 0; i < row.childCount; i += 1) {
153
+ const { colspan, colwidth } = row.child(i).attrs;
154
+ for (let j = 0; j < colspan; j += 1, col += 1) {
155
+ const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j];
156
+ const cssWidth = hasWidth ? `${hasWidth}px` : "";
157
+ totalWidth += hasWidth || cellMinWidth;
158
+ if (!hasWidth) {
159
+ fixedWidth = false;
49
160
  }
50
- }
51
- while (nextDOM) {
52
- const after = nextDOM.nextSibling;
53
- (_a = nextDOM.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(nextDOM);
54
- nextDOM = after;
55
- }
56
- if (fixedWidth) {
57
- table.style.width = `${totalWidth}px`;
58
- table.style.minWidth = '';
59
- }
60
- else {
61
- table.style.width = '';
62
- table.style.minWidth = `${totalWidth}px`;
63
- }
64
- }
65
- class TableView {
66
- constructor(node, cellMinWidth) {
67
- this.node = node;
68
- this.cellMinWidth = cellMinWidth;
69
- this.dom = document.createElement('div');
70
- this.dom.className = 'tableWrapper';
71
- this.table = this.dom.appendChild(document.createElement('table'));
72
- this.colgroup = this.table.appendChild(document.createElement('colgroup'));
73
- updateColumns(node, this.colgroup, this.table, cellMinWidth);
74
- this.contentDOM = this.table.appendChild(document.createElement('tbody'));
75
- }
76
- update(node) {
77
- if (node.type !== this.node.type) {
78
- return false;
161
+ if (!nextDOM) {
162
+ const colElement = document.createElement("col");
163
+ const [propertyKey, propertyValue] = getColStyleDeclaration(cellMinWidth, hasWidth);
164
+ colElement.style.setProperty(propertyKey, propertyValue);
165
+ colgroup.appendChild(colElement);
166
+ } else {
167
+ if (nextDOM.style.width !== cssWidth) {
168
+ const [propertyKey, propertyValue] = getColStyleDeclaration(cellMinWidth, hasWidth);
169
+ nextDOM.style.setProperty(propertyKey, propertyValue);
170
+ }
171
+ nextDOM = nextDOM.nextSibling;
79
172
  }
80
- this.node = node;
81
- updateColumns(node, this.colgroup, this.table, this.cellMinWidth);
82
- return true;
83
- }
84
- ignoreMutation(mutation) {
85
- return (mutation.type === 'attributes'
86
- && (mutation.target === this.table || this.colgroup.contains(mutation.target)));
173
+ }
87
174
  }
175
+ }
176
+ while (nextDOM) {
177
+ const after = nextDOM.nextSibling;
178
+ (_a = nextDOM.parentNode) == null ? void 0 : _a.removeChild(nextDOM);
179
+ nextDOM = after;
180
+ }
181
+ if (fixedWidth) {
182
+ table.style.width = `${totalWidth}px`;
183
+ table.style.minWidth = "";
184
+ } else {
185
+ table.style.width = "";
186
+ table.style.minWidth = `${totalWidth}px`;
187
+ }
88
188
  }
189
+ var TableView = class {
190
+ constructor(node, cellMinWidth) {
191
+ this.node = node;
192
+ this.cellMinWidth = cellMinWidth;
193
+ this.dom = document.createElement("div");
194
+ this.dom.className = "tableWrapper";
195
+ this.table = this.dom.appendChild(document.createElement("table"));
196
+ this.colgroup = this.table.appendChild(document.createElement("colgroup"));
197
+ updateColumns(node, this.colgroup, this.table, cellMinWidth);
198
+ this.contentDOM = this.table.appendChild(document.createElement("tbody"));
199
+ }
200
+ update(node) {
201
+ if (node.type !== this.node.type) {
202
+ return false;
203
+ }
204
+ this.node = node;
205
+ updateColumns(node, this.colgroup, this.table, this.cellMinWidth);
206
+ return true;
207
+ }
208
+ ignoreMutation(mutation) {
209
+ return mutation.type === "attributes" && (mutation.target === this.table || this.colgroup.contains(mutation.target));
210
+ }
211
+ };
89
212
 
213
+ // src/table/utilities/createColGroup.ts
90
214
  function createColGroup(node, cellMinWidth, overrideCol, overrideValue) {
91
- let totalWidth = 0;
92
- let fixedWidth = true;
93
- const cols = [];
94
- const row = node.firstChild;
95
- if (!row) {
96
- return {};
215
+ let totalWidth = 0;
216
+ let fixedWidth = true;
217
+ const cols = [];
218
+ const row = node.firstChild;
219
+ if (!row) {
220
+ return {};
221
+ }
222
+ for (let i = 0, col = 0; i < row.childCount; i += 1) {
223
+ const { colspan, colwidth } = row.child(i).attrs;
224
+ for (let j = 0; j < colspan; j += 1, col += 1) {
225
+ const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j];
226
+ totalWidth += hasWidth || cellMinWidth;
227
+ if (!hasWidth) {
228
+ fixedWidth = false;
229
+ }
230
+ const [property, value] = getColStyleDeclaration(cellMinWidth, hasWidth);
231
+ cols.push(["col", { style: `${property}: ${value}` }]);
97
232
  }
98
- for (let i = 0, col = 0; i < row.childCount; i += 1) {
99
- const { colspan, colwidth } = row.child(i).attrs;
100
- for (let j = 0; j < colspan; j += 1, col += 1) {
101
- const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j];
102
- totalWidth += hasWidth || cellMinWidth;
103
- if (!hasWidth) {
104
- fixedWidth = false;
105
- }
106
- const [property, value] = getColStyleDeclaration(cellMinWidth, hasWidth);
107
- cols.push([
108
- 'col',
109
- { style: `${property}: ${value}` },
110
- ]);
111
- }
112
- }
113
- const tableWidth = fixedWidth ? `${totalWidth}px` : '';
114
- const tableMinWidth = fixedWidth ? '' : `${totalWidth}px`;
115
- const colgroup = ['colgroup', {}, ...cols];
116
- return { colgroup, tableWidth, tableMinWidth };
233
+ }
234
+ const tableWidth = fixedWidth ? `${totalWidth}px` : "";
235
+ const tableMinWidth = fixedWidth ? "" : `${totalWidth}px`;
236
+ const colgroup = ["colgroup", {}, ...cols];
237
+ return { colgroup, tableWidth, tableMinWidth };
117
238
  }
118
239
 
240
+ // src/table/utilities/createCell.ts
119
241
  function createCell(cellType, cellContent) {
120
- if (cellContent) {
121
- return cellType.createChecked(null, cellContent);
122
- }
123
- return cellType.createAndFill();
242
+ if (cellContent) {
243
+ return cellType.createChecked(null, cellContent);
244
+ }
245
+ return cellType.createAndFill();
124
246
  }
125
247
 
248
+ // src/table/utilities/getTableNodeTypes.ts
126
249
  function getTableNodeTypes(schema) {
127
- if (schema.cached.tableNodeTypes) {
128
- return schema.cached.tableNodeTypes;
250
+ if (schema.cached.tableNodeTypes) {
251
+ return schema.cached.tableNodeTypes;
252
+ }
253
+ const roles = {};
254
+ Object.keys(schema.nodes).forEach((type) => {
255
+ const nodeType = schema.nodes[type];
256
+ if (nodeType.spec.tableRole) {
257
+ roles[nodeType.spec.tableRole] = nodeType;
129
258
  }
130
- const roles = {};
131
- Object.keys(schema.nodes).forEach(type => {
132
- const nodeType = schema.nodes[type];
133
- if (nodeType.spec.tableRole) {
134
- roles[nodeType.spec.tableRole] = nodeType;
135
- }
136
- });
137
- schema.cached.tableNodeTypes = roles;
138
- return roles;
259
+ });
260
+ schema.cached.tableNodeTypes = roles;
261
+ return roles;
139
262
  }
140
263
 
264
+ // src/table/utilities/createTable.ts
141
265
  function createTable(schema, rowsCount, colsCount, withHeaderRow, cellContent) {
142
- const types = getTableNodeTypes(schema);
143
- const headerCells = [];
144
- const cells = [];
145
- for (let index = 0; index < colsCount; index += 1) {
146
- const cell = createCell(types.cell, cellContent);
147
- if (cell) {
148
- cells.push(cell);
149
- }
150
- if (withHeaderRow) {
151
- const headerCell = createCell(types.header_cell, cellContent);
152
- if (headerCell) {
153
- headerCells.push(headerCell);
154
- }
155
- }
266
+ const types = getTableNodeTypes(schema);
267
+ const headerCells = [];
268
+ const cells = [];
269
+ for (let index = 0; index < colsCount; index += 1) {
270
+ const cell = createCell(types.cell, cellContent);
271
+ if (cell) {
272
+ cells.push(cell);
156
273
  }
157
- const rows = [];
158
- for (let index = 0; index < rowsCount; index += 1) {
159
- rows.push(types.row.createChecked(null, withHeaderRow && index === 0 ? headerCells : cells));
274
+ if (withHeaderRow) {
275
+ const headerCell = createCell(types.header_cell, cellContent);
276
+ if (headerCell) {
277
+ headerCells.push(headerCell);
278
+ }
160
279
  }
161
- return types.table.createChecked(null, rows);
280
+ }
281
+ const rows = [];
282
+ for (let index = 0; index < rowsCount; index += 1) {
283
+ rows.push(types.row.createChecked(null, withHeaderRow && index === 0 ? headerCells : cells));
284
+ }
285
+ return types.table.createChecked(null, rows);
162
286
  }
163
287
 
288
+ // src/table/utilities/deleteTableWhenAllCellsSelected.ts
289
+ var import_core4 = require("@tiptap/core");
290
+
291
+ // src/table/utilities/isCellSelection.ts
292
+ var import_tables = require("@tiptap/pm/tables");
164
293
  function isCellSelection(value) {
165
- return value instanceof tables.CellSelection;
294
+ return value instanceof import_tables.CellSelection;
166
295
  }
167
296
 
168
- const deleteTableWhenAllCellsSelected = ({ editor }) => {
169
- const { selection } = editor.state;
170
- if (!isCellSelection(selection)) {
171
- return false;
297
+ // src/table/utilities/deleteTableWhenAllCellsSelected.ts
298
+ var deleteTableWhenAllCellsSelected = ({ editor }) => {
299
+ const { selection } = editor.state;
300
+ if (!isCellSelection(selection)) {
301
+ return false;
302
+ }
303
+ let cellCount = 0;
304
+ const table = (0, import_core4.findParentNodeClosestToPos)(selection.ranges[0].$from, (node) => {
305
+ return node.type.name === "table";
306
+ });
307
+ table == null ? void 0 : table.node.descendants((node) => {
308
+ if (node.type.name === "table") {
309
+ return false;
172
310
  }
173
- let cellCount = 0;
174
- const table = core.findParentNodeClosestToPos(selection.ranges[0].$from, node => {
175
- return node.type.name === 'table';
176
- });
177
- table === null || table === void 0 ? void 0 : table.node.descendants(node => {
178
- if (node.type.name === 'table') {
179
- return false;
180
- }
181
- if (['tableCell', 'tableHeader'].includes(node.type.name)) {
182
- cellCount += 1;
183
- }
184
- });
185
- const allCellsSelected = cellCount === selection.ranges.length;
186
- if (!allCellsSelected) {
187
- return false;
311
+ if (["tableCell", "tableHeader"].includes(node.type.name)) {
312
+ cellCount += 1;
188
313
  }
189
- editor.commands.deleteTable();
190
- return true;
314
+ });
315
+ const allCellsSelected = cellCount === selection.ranges.length;
316
+ if (!allCellsSelected) {
317
+ return false;
318
+ }
319
+ editor.commands.deleteTable();
320
+ return true;
191
321
  };
192
322
 
193
- /**
194
- * This extension allows you to create tables.
195
- * @see https://www.tiptap.dev/api/nodes/table
196
- */
197
- const Table = core.Node.create({
198
- name: 'table',
199
- // @ts-ignore
200
- addOptions() {
201
- return {
202
- HTMLAttributes: {},
203
- resizable: false,
204
- handleWidth: 5,
205
- cellMinWidth: 25,
206
- // TODO: fix
207
- View: TableView,
208
- lastColumnResizable: true,
209
- allowTableNodeSelection: false,
210
- };
211
- },
212
- content: 'tableRow+',
213
- tableRole: 'table',
214
- isolating: true,
215
- group: 'block',
216
- parseHTML() {
217
- return [{ tag: 'table' }];
218
- },
219
- renderHTML({ node, HTMLAttributes }) {
220
- const { colgroup, tableWidth, tableMinWidth } = createColGroup(node, this.options.cellMinWidth);
221
- const table = [
222
- 'table',
223
- core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
224
- style: tableWidth
225
- ? `width: ${tableWidth}`
226
- : `min-width: ${tableMinWidth}`,
227
- }),
228
- colgroup,
229
- ['tbody', 0],
230
- ];
231
- return table;
232
- },
233
- addCommands() {
234
- return {
235
- insertTable: ({ rows = 3, cols = 3, withHeaderRow = true } = {}) => ({ tr, dispatch, editor }) => {
236
- const node = createTable(editor.schema, rows, cols, withHeaderRow);
237
- if (dispatch) {
238
- const offset = tr.selection.from + 1;
239
- tr.replaceSelectionWith(node)
240
- .scrollIntoView()
241
- .setSelection(state.TextSelection.near(tr.doc.resolve(offset)));
242
- }
243
- return true;
244
- },
245
- addColumnBefore: () => ({ state, dispatch }) => {
246
- return tables.addColumnBefore(state, dispatch);
247
- },
248
- addColumnAfter: () => ({ state, dispatch }) => {
249
- return tables.addColumnAfter(state, dispatch);
250
- },
251
- deleteColumn: () => ({ state, dispatch }) => {
252
- return tables.deleteColumn(state, dispatch);
253
- },
254
- addRowBefore: () => ({ state, dispatch }) => {
255
- return tables.addRowBefore(state, dispatch);
256
- },
257
- addRowAfter: () => ({ state, dispatch }) => {
258
- return tables.addRowAfter(state, dispatch);
259
- },
260
- deleteRow: () => ({ state, dispatch }) => {
261
- return tables.deleteRow(state, dispatch);
262
- },
263
- deleteTable: () => ({ state, dispatch }) => {
264
- return tables.deleteTable(state, dispatch);
265
- },
266
- mergeCells: () => ({ state, dispatch }) => {
267
- return tables.mergeCells(state, dispatch);
268
- },
269
- splitCell: () => ({ state, dispatch }) => {
270
- return tables.splitCell(state, dispatch);
271
- },
272
- toggleHeaderColumn: () => ({ state, dispatch }) => {
273
- return tables.toggleHeader('column')(state, dispatch);
274
- },
275
- toggleHeaderRow: () => ({ state, dispatch }) => {
276
- return tables.toggleHeader('row')(state, dispatch);
277
- },
278
- toggleHeaderCell: () => ({ state, dispatch }) => {
279
- return tables.toggleHeaderCell(state, dispatch);
280
- },
281
- mergeOrSplit: () => ({ state, dispatch }) => {
282
- if (tables.mergeCells(state, dispatch)) {
283
- return true;
284
- }
285
- return tables.splitCell(state, dispatch);
286
- },
287
- setCellAttribute: (name, value) => ({ state, dispatch }) => {
288
- return tables.setCellAttr(name, value)(state, dispatch);
289
- },
290
- goToNextCell: () => ({ state, dispatch }) => {
291
- return tables.goToNextCell(1)(state, dispatch);
292
- },
293
- goToPreviousCell: () => ({ state, dispatch }) => {
294
- return tables.goToNextCell(-1)(state, dispatch);
295
- },
296
- fixTables: () => ({ state, dispatch }) => {
297
- if (dispatch) {
298
- tables.fixTables(state);
299
- }
300
- return true;
301
- },
302
- setCellSelection: position => ({ tr, dispatch }) => {
303
- if (dispatch) {
304
- const selection = tables.CellSelection.create(tr.doc, position.anchorCell, position.headCell);
305
- // @ts-ignore
306
- tr.setSelection(selection);
307
- }
308
- return true;
309
- },
310
- };
311
- },
312
- addKeyboardShortcuts() {
313
- return {
314
- Tab: () => {
315
- if (this.editor.commands.goToNextCell()) {
316
- return true;
317
- }
318
- if (!this.editor.can().addRowAfter()) {
319
- return false;
320
- }
321
- return this.editor.chain().addRowAfter().goToNextCell().run();
322
- },
323
- 'Shift-Tab': () => this.editor.commands.goToPreviousCell(),
324
- Backspace: deleteTableWhenAllCellsSelected,
325
- 'Mod-Backspace': deleteTableWhenAllCellsSelected,
326
- Delete: deleteTableWhenAllCellsSelected,
327
- 'Mod-Delete': deleteTableWhenAllCellsSelected,
328
- };
329
- },
330
- addProseMirrorPlugins() {
331
- const isResizable = this.options.resizable && this.editor.isEditable;
332
- return [
333
- ...(isResizable
334
- ? [
335
- tables.columnResizing({
336
- handleWidth: this.options.handleWidth,
337
- cellMinWidth: this.options.cellMinWidth,
338
- defaultCellMinWidth: this.options.cellMinWidth,
339
- View: this.options.View,
340
- lastColumnResizable: this.options.lastColumnResizable,
341
- }),
342
- ]
343
- : []),
344
- tables.tableEditing({
345
- allowTableNodeSelection: this.options.allowTableNodeSelection,
346
- }),
347
- ];
348
- },
349
- extendNodeSchema(extension) {
350
- const context = {
351
- name: extension.name,
352
- options: extension.options,
353
- storage: extension.storage,
354
- };
355
- return {
356
- tableRole: core.callOrReturn(core.getExtensionField(extension, 'tableRole', context)),
357
- };
358
- },
323
+ // src/table/table.ts
324
+ var Table = import_core5.Node.create({
325
+ name: "table",
326
+ // @ts-ignore
327
+ addOptions() {
328
+ return {
329
+ HTMLAttributes: {},
330
+ resizable: false,
331
+ handleWidth: 5,
332
+ cellMinWidth: 25,
333
+ // TODO: fix
334
+ View: TableView,
335
+ lastColumnResizable: true,
336
+ allowTableNodeSelection: false
337
+ };
338
+ },
339
+ content: "tableRow+",
340
+ tableRole: "table",
341
+ isolating: true,
342
+ group: "block",
343
+ parseHTML() {
344
+ return [{ tag: "table" }];
345
+ },
346
+ renderHTML({ node, HTMLAttributes }) {
347
+ const { colgroup, tableWidth, tableMinWidth } = createColGroup(node, this.options.cellMinWidth);
348
+ const table = [
349
+ "table",
350
+ (0, import_core5.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, {
351
+ style: tableWidth ? `width: ${tableWidth}` : `min-width: ${tableMinWidth}`
352
+ }),
353
+ colgroup,
354
+ ["tbody", 0]
355
+ ];
356
+ return table;
357
+ },
358
+ addCommands() {
359
+ return {
360
+ insertTable: ({ rows = 3, cols = 3, withHeaderRow = true } = {}) => ({ tr, dispatch, editor }) => {
361
+ const node = createTable(editor.schema, rows, cols, withHeaderRow);
362
+ if (dispatch) {
363
+ const offset = tr.selection.from + 1;
364
+ tr.replaceSelectionWith(node).scrollIntoView().setSelection(import_state.TextSelection.near(tr.doc.resolve(offset)));
365
+ }
366
+ return true;
367
+ },
368
+ addColumnBefore: () => ({ state, dispatch }) => {
369
+ return (0, import_tables2.addColumnBefore)(state, dispatch);
370
+ },
371
+ addColumnAfter: () => ({ state, dispatch }) => {
372
+ return (0, import_tables2.addColumnAfter)(state, dispatch);
373
+ },
374
+ deleteColumn: () => ({ state, dispatch }) => {
375
+ return (0, import_tables2.deleteColumn)(state, dispatch);
376
+ },
377
+ addRowBefore: () => ({ state, dispatch }) => {
378
+ return (0, import_tables2.addRowBefore)(state, dispatch);
379
+ },
380
+ addRowAfter: () => ({ state, dispatch }) => {
381
+ return (0, import_tables2.addRowAfter)(state, dispatch);
382
+ },
383
+ deleteRow: () => ({ state, dispatch }) => {
384
+ return (0, import_tables2.deleteRow)(state, dispatch);
385
+ },
386
+ deleteTable: () => ({ state, dispatch }) => {
387
+ return (0, import_tables2.deleteTable)(state, dispatch);
388
+ },
389
+ mergeCells: () => ({ state, dispatch }) => {
390
+ return (0, import_tables2.mergeCells)(state, dispatch);
391
+ },
392
+ splitCell: () => ({ state, dispatch }) => {
393
+ return (0, import_tables2.splitCell)(state, dispatch);
394
+ },
395
+ toggleHeaderColumn: () => ({ state, dispatch }) => {
396
+ return (0, import_tables2.toggleHeader)("column")(state, dispatch);
397
+ },
398
+ toggleHeaderRow: () => ({ state, dispatch }) => {
399
+ return (0, import_tables2.toggleHeader)("row")(state, dispatch);
400
+ },
401
+ toggleHeaderCell: () => ({ state, dispatch }) => {
402
+ return (0, import_tables2.toggleHeaderCell)(state, dispatch);
403
+ },
404
+ mergeOrSplit: () => ({ state, dispatch }) => {
405
+ if ((0, import_tables2.mergeCells)(state, dispatch)) {
406
+ return true;
407
+ }
408
+ return (0, import_tables2.splitCell)(state, dispatch);
409
+ },
410
+ setCellAttribute: (name, value) => ({ state, dispatch }) => {
411
+ return (0, import_tables2.setCellAttr)(name, value)(state, dispatch);
412
+ },
413
+ goToNextCell: () => ({ state, dispatch }) => {
414
+ return (0, import_tables2.goToNextCell)(1)(state, dispatch);
415
+ },
416
+ goToPreviousCell: () => ({ state, dispatch }) => {
417
+ return (0, import_tables2.goToNextCell)(-1)(state, dispatch);
418
+ },
419
+ fixTables: () => ({ state, dispatch }) => {
420
+ if (dispatch) {
421
+ (0, import_tables2.fixTables)(state);
422
+ }
423
+ return true;
424
+ },
425
+ setCellSelection: (position) => ({ tr, dispatch }) => {
426
+ if (dispatch) {
427
+ const selection = import_tables2.CellSelection.create(tr.doc, position.anchorCell, position.headCell);
428
+ tr.setSelection(selection);
429
+ }
430
+ return true;
431
+ }
432
+ };
433
+ },
434
+ addKeyboardShortcuts() {
435
+ return {
436
+ Tab: () => {
437
+ if (this.editor.commands.goToNextCell()) {
438
+ return true;
439
+ }
440
+ if (!this.editor.can().addRowAfter()) {
441
+ return false;
442
+ }
443
+ return this.editor.chain().addRowAfter().goToNextCell().run();
444
+ },
445
+ "Shift-Tab": () => this.editor.commands.goToPreviousCell(),
446
+ Backspace: deleteTableWhenAllCellsSelected,
447
+ "Mod-Backspace": deleteTableWhenAllCellsSelected,
448
+ Delete: deleteTableWhenAllCellsSelected,
449
+ "Mod-Delete": deleteTableWhenAllCellsSelected
450
+ };
451
+ },
452
+ addProseMirrorPlugins() {
453
+ const isResizable = this.options.resizable && this.editor.isEditable;
454
+ return [
455
+ ...isResizable ? [
456
+ (0, import_tables2.columnResizing)({
457
+ handleWidth: this.options.handleWidth,
458
+ cellMinWidth: this.options.cellMinWidth,
459
+ defaultCellMinWidth: this.options.cellMinWidth,
460
+ View: this.options.View,
461
+ lastColumnResizable: this.options.lastColumnResizable
462
+ })
463
+ ] : [],
464
+ (0, import_tables2.tableEditing)({
465
+ allowTableNodeSelection: this.options.allowTableNodeSelection
466
+ })
467
+ ];
468
+ },
469
+ extendNodeSchema(extension) {
470
+ const context = {
471
+ name: extension.name,
472
+ options: extension.options,
473
+ storage: extension.storage
474
+ };
475
+ return {
476
+ tableRole: (0, import_core5.callOrReturn)((0, import_core5.getExtensionField)(extension, "tableRole", context))
477
+ };
478
+ }
359
479
  });
360
480
 
361
- exports.Table = Table;
362
- exports.TableView = TableView;
363
- exports.createColGroup = createColGroup;
364
- exports.createTable = createTable;
365
- exports.default = Table;
366
- exports.updateColumns = updateColumns;
367
- //# sourceMappingURL=index.cjs.map
481
+ // src/kit/index.ts
482
+ var TableKit = import_core6.Extension.create({
483
+ name: "tableKit",
484
+ addExtensions() {
485
+ const extensions = [];
486
+ if (this.options.table !== false) {
487
+ extensions.push(Table.configure(this.options.table));
488
+ }
489
+ if (this.options.tableCell !== false) {
490
+ extensions.push(TableCell.configure(this.options.tableCell));
491
+ }
492
+ if (this.options.tableHeader !== false) {
493
+ extensions.push(TableHeader.configure(this.options.tableHeader));
494
+ }
495
+ if (this.options.tableRow !== false) {
496
+ extensions.push(TableRow.configure(this.options.tableRow));
497
+ }
498
+ return extensions;
499
+ }
500
+ });
501
+ // Annotate the CommonJS export names for ESM import in node:
502
+ 0 && (module.exports = {
503
+ Table,
504
+ TableCell,
505
+ TableHeader,
506
+ TableKit,
507
+ TableRow,
508
+ createColGroup,
509
+ createTable
510
+ });
511
+ //# sourceMappingURL=index.cjs.map