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

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