@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.
- package/dist/cell/index.cjs +77 -0
- package/dist/cell/index.cjs.map +1 -0
- package/dist/cell/index.d.cts +33 -0
- package/dist/cell/index.d.ts +33 -0
- package/dist/cell/index.js +50 -0
- package/dist/cell/index.js.map +1 -0
- package/dist/header/index.cjs +68 -0
- package/dist/header/index.cjs.map +1 -0
- package/dist/header/index.d.cts +33 -0
- package/dist/header/index.d.ts +33 -0
- package/dist/header/index.js +41 -0
- package/dist/header/index.js.map +1 -0
- package/dist/index.cjs +637 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +317 -0
- package/dist/index.d.ts +317 -0
- package/dist/index.js +623 -0
- package/dist/index.js.map +1 -0
- package/dist/kit/index.cjs +615 -0
- package/dist/kit/index.cjs.map +1 -0
- package/dist/kit/index.d.cts +259 -0
- package/dist/kit/index.d.ts +259 -0
- package/dist/kit/index.js +613 -0
- package/dist/kit/index.js.map +1 -0
- package/dist/row/index.cjs +49 -0
- package/dist/row/index.cjs.map +1 -0
- package/dist/row/index.d.cts +33 -0
- package/dist/row/index.d.ts +33 -0
- package/dist/row/index.js +22 -0
- package/dist/row/index.js.map +1 -0
- package/dist/table/index.cjs +497 -0
- package/dist/table/index.cjs.map +1 -0
- package/dist/table/index.d.cts +232 -0
- package/dist/table/index.d.ts +232 -0
- package/dist/table/index.js +489 -0
- package/dist/table/index.js.map +1 -0
- package/package.json +5 -5
package/dist/index.js
ADDED
|
@@ -0,0 +1,623 @@
|
|
|
1
|
+
// src/cell/table-cell.ts
|
|
2
|
+
import { mergeAttributes, Node } from "@tiptap/core";
|
|
3
|
+
var TableCell = Node.create({
|
|
4
|
+
name: "tableCell",
|
|
5
|
+
addOptions() {
|
|
6
|
+
return {
|
|
7
|
+
HTMLAttributes: {}
|
|
8
|
+
};
|
|
9
|
+
},
|
|
10
|
+
content: "block+",
|
|
11
|
+
addAttributes() {
|
|
12
|
+
return {
|
|
13
|
+
colspan: {
|
|
14
|
+
default: 1
|
|
15
|
+
},
|
|
16
|
+
rowspan: {
|
|
17
|
+
default: 1
|
|
18
|
+
},
|
|
19
|
+
colwidth: {
|
|
20
|
+
default: null,
|
|
21
|
+
parseHTML: (element) => {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
const colwidth = element.getAttribute("colwidth");
|
|
24
|
+
const value = colwidth ? colwidth.split(",").map((width) => parseInt(width, 10)) : null;
|
|
25
|
+
if (!value) {
|
|
26
|
+
const cols = (_a = element.closest("table")) == null ? void 0 : _a.querySelectorAll("colgroup > col");
|
|
27
|
+
const cellIndex = Array.from(((_b = element.parentElement) == null ? void 0 : _b.children) || []).indexOf(element);
|
|
28
|
+
if (cellIndex && cellIndex > -1 && cols && cols[cellIndex]) {
|
|
29
|
+
const colWidth = cols[cellIndex].getAttribute("width");
|
|
30
|
+
return colWidth ? [parseInt(colWidth, 10)] : null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
tableRole: "cell",
|
|
39
|
+
isolating: true,
|
|
40
|
+
parseHTML() {
|
|
41
|
+
return [{ tag: "td" }];
|
|
42
|
+
},
|
|
43
|
+
renderHTML({ HTMLAttributes }) {
|
|
44
|
+
return ["td", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// src/header/table-header.ts
|
|
49
|
+
import { mergeAttributes as mergeAttributes2, Node as Node2 } from "@tiptap/core";
|
|
50
|
+
var TableHeader = Node2.create({
|
|
51
|
+
name: "tableHeader",
|
|
52
|
+
addOptions() {
|
|
53
|
+
return {
|
|
54
|
+
HTMLAttributes: {}
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
content: "block+",
|
|
58
|
+
addAttributes() {
|
|
59
|
+
return {
|
|
60
|
+
colspan: {
|
|
61
|
+
default: 1
|
|
62
|
+
},
|
|
63
|
+
rowspan: {
|
|
64
|
+
default: 1
|
|
65
|
+
},
|
|
66
|
+
colwidth: {
|
|
67
|
+
default: null,
|
|
68
|
+
parseHTML: (element) => {
|
|
69
|
+
const colwidth = element.getAttribute("colwidth");
|
|
70
|
+
const value = colwidth ? colwidth.split(",").map((width) => parseInt(width, 10)) : null;
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
tableRole: "header_cell",
|
|
77
|
+
isolating: true,
|
|
78
|
+
parseHTML() {
|
|
79
|
+
return [{ tag: "th" }];
|
|
80
|
+
},
|
|
81
|
+
renderHTML({ HTMLAttributes }) {
|
|
82
|
+
return ["th", mergeAttributes2(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// src/kit/index.ts
|
|
87
|
+
import { Extension } from "@tiptap/core";
|
|
88
|
+
|
|
89
|
+
// src/row/table-row.ts
|
|
90
|
+
import { mergeAttributes as mergeAttributes3, Node as Node3 } from "@tiptap/core";
|
|
91
|
+
var TableRow = Node3.create({
|
|
92
|
+
name: "tableRow",
|
|
93
|
+
addOptions() {
|
|
94
|
+
return {
|
|
95
|
+
HTMLAttributes: {}
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
content: "(tableCell | tableHeader)*",
|
|
99
|
+
tableRole: "row",
|
|
100
|
+
parseHTML() {
|
|
101
|
+
return [{ tag: "tr" }];
|
|
102
|
+
},
|
|
103
|
+
renderHTML({ HTMLAttributes }) {
|
|
104
|
+
return ["tr", mergeAttributes3(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// src/table/table.ts
|
|
109
|
+
import {
|
|
110
|
+
callOrReturn,
|
|
111
|
+
getExtensionField,
|
|
112
|
+
mergeAttributes as mergeAttributes4,
|
|
113
|
+
Node as Node4
|
|
114
|
+
} from "@tiptap/core";
|
|
115
|
+
import { TextSelection } from "@tiptap/pm/state";
|
|
116
|
+
import {
|
|
117
|
+
addColumnAfter,
|
|
118
|
+
addColumnBefore,
|
|
119
|
+
addRowAfter,
|
|
120
|
+
addRowBefore,
|
|
121
|
+
CellSelection as CellSelection2,
|
|
122
|
+
columnResizing,
|
|
123
|
+
deleteColumn,
|
|
124
|
+
deleteRow,
|
|
125
|
+
deleteTable,
|
|
126
|
+
fixTables,
|
|
127
|
+
goToNextCell,
|
|
128
|
+
mergeCells,
|
|
129
|
+
setCellAttr,
|
|
130
|
+
splitCell,
|
|
131
|
+
tableEditing,
|
|
132
|
+
toggleHeader,
|
|
133
|
+
toggleHeaderCell
|
|
134
|
+
} from "@tiptap/pm/tables";
|
|
135
|
+
|
|
136
|
+
// src/table/utilities/colStyle.ts
|
|
137
|
+
function getColStyleDeclaration(minWidth, width) {
|
|
138
|
+
if (width) {
|
|
139
|
+
return ["width", `${Math.max(width, minWidth)}px`];
|
|
140
|
+
}
|
|
141
|
+
return ["min-width", `${minWidth}px`];
|
|
142
|
+
}
|
|
143
|
+
|
|
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;
|
|
160
|
+
}
|
|
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;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
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
|
+
const hasUserWidth = node.attrs.style && typeof node.attrs.style === "string" && /\bwidth\s*:/i.test(node.attrs.style);
|
|
182
|
+
if (fixedWidth && !hasUserWidth) {
|
|
183
|
+
table.style.width = `${totalWidth}px`;
|
|
184
|
+
table.style.minWidth = "";
|
|
185
|
+
} else {
|
|
186
|
+
table.style.width = "";
|
|
187
|
+
table.style.minWidth = `${totalWidth}px`;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
var TableView = class {
|
|
191
|
+
constructor(node, cellMinWidth) {
|
|
192
|
+
this.node = node;
|
|
193
|
+
this.cellMinWidth = cellMinWidth;
|
|
194
|
+
this.dom = document.createElement("div");
|
|
195
|
+
this.dom.className = "tableWrapper";
|
|
196
|
+
this.table = this.dom.appendChild(document.createElement("table"));
|
|
197
|
+
if (node.attrs.style) {
|
|
198
|
+
this.table.style.cssText = node.attrs.style;
|
|
199
|
+
}
|
|
200
|
+
this.colgroup = this.table.appendChild(document.createElement("colgroup"));
|
|
201
|
+
updateColumns(node, this.colgroup, this.table, cellMinWidth);
|
|
202
|
+
this.contentDOM = this.table.appendChild(document.createElement("tbody"));
|
|
203
|
+
}
|
|
204
|
+
update(node) {
|
|
205
|
+
if (node.type !== this.node.type) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
this.node = node;
|
|
209
|
+
updateColumns(node, this.colgroup, this.table, this.cellMinWidth);
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
ignoreMutation(mutation) {
|
|
213
|
+
const target = mutation.target;
|
|
214
|
+
const isInsideWrapper = this.dom.contains(target);
|
|
215
|
+
const isInsideContent = this.contentDOM.contains(target);
|
|
216
|
+
if (isInsideWrapper && !isInsideContent) {
|
|
217
|
+
if (mutation.type === "attributes" || mutation.type === "childList" || mutation.type === "characterData") {
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
// src/table/utilities/createColGroup.ts
|
|
226
|
+
function createColGroup(node, cellMinWidth, overrideCol, overrideValue) {
|
|
227
|
+
let totalWidth = 0;
|
|
228
|
+
let fixedWidth = true;
|
|
229
|
+
const cols = [];
|
|
230
|
+
const row = node.firstChild;
|
|
231
|
+
if (!row) {
|
|
232
|
+
return {};
|
|
233
|
+
}
|
|
234
|
+
for (let i = 0, col = 0; i < row.childCount; i += 1) {
|
|
235
|
+
const { colspan, colwidth } = row.child(i).attrs;
|
|
236
|
+
for (let j = 0; j < colspan; j += 1, col += 1) {
|
|
237
|
+
const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j];
|
|
238
|
+
totalWidth += hasWidth || cellMinWidth;
|
|
239
|
+
if (!hasWidth) {
|
|
240
|
+
fixedWidth = false;
|
|
241
|
+
}
|
|
242
|
+
const [property, value] = getColStyleDeclaration(cellMinWidth, hasWidth);
|
|
243
|
+
cols.push(["col", { style: `${property}: ${value}` }]);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
const tableWidth = fixedWidth ? `${totalWidth}px` : "";
|
|
247
|
+
const tableMinWidth = fixedWidth ? "" : `${totalWidth}px`;
|
|
248
|
+
const colgroup = ["colgroup", {}, ...cols];
|
|
249
|
+
return { colgroup, tableWidth, tableMinWidth };
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// src/table/utilities/createCell.ts
|
|
253
|
+
function createCell(cellType, cellContent) {
|
|
254
|
+
if (cellContent) {
|
|
255
|
+
return cellType.createChecked(null, cellContent);
|
|
256
|
+
}
|
|
257
|
+
return cellType.createAndFill();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// src/table/utilities/getTableNodeTypes.ts
|
|
261
|
+
function getTableNodeTypes(schema) {
|
|
262
|
+
if (schema.cached.tableNodeTypes) {
|
|
263
|
+
return schema.cached.tableNodeTypes;
|
|
264
|
+
}
|
|
265
|
+
const roles = {};
|
|
266
|
+
Object.keys(schema.nodes).forEach((type) => {
|
|
267
|
+
const nodeType = schema.nodes[type];
|
|
268
|
+
if (nodeType.spec.tableRole) {
|
|
269
|
+
roles[nodeType.spec.tableRole] = nodeType;
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
schema.cached.tableNodeTypes = roles;
|
|
273
|
+
return roles;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// src/table/utilities/createTable.ts
|
|
277
|
+
function createTable(schema, rowsCount, colsCount, withHeaderRow, cellContent) {
|
|
278
|
+
const types = getTableNodeTypes(schema);
|
|
279
|
+
const headerCells = [];
|
|
280
|
+
const cells = [];
|
|
281
|
+
for (let index = 0; index < colsCount; index += 1) {
|
|
282
|
+
const cell = createCell(types.cell, cellContent);
|
|
283
|
+
if (cell) {
|
|
284
|
+
cells.push(cell);
|
|
285
|
+
}
|
|
286
|
+
if (withHeaderRow) {
|
|
287
|
+
const headerCell = createCell(types.header_cell, cellContent);
|
|
288
|
+
if (headerCell) {
|
|
289
|
+
headerCells.push(headerCell);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
const rows = [];
|
|
294
|
+
for (let index = 0; index < rowsCount; index += 1) {
|
|
295
|
+
rows.push(types.row.createChecked(null, withHeaderRow && index === 0 ? headerCells : cells));
|
|
296
|
+
}
|
|
297
|
+
return types.table.createChecked(null, rows);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// src/table/utilities/deleteTableWhenAllCellsSelected.ts
|
|
301
|
+
import { findParentNodeClosestToPos } from "@tiptap/core";
|
|
302
|
+
|
|
303
|
+
// src/table/utilities/isCellSelection.ts
|
|
304
|
+
import { CellSelection } from "@tiptap/pm/tables";
|
|
305
|
+
function isCellSelection(value) {
|
|
306
|
+
return value instanceof CellSelection;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// src/table/utilities/deleteTableWhenAllCellsSelected.ts
|
|
310
|
+
var deleteTableWhenAllCellsSelected = ({ editor }) => {
|
|
311
|
+
const { selection } = editor.state;
|
|
312
|
+
if (!isCellSelection(selection)) {
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
let cellCount = 0;
|
|
316
|
+
const table = findParentNodeClosestToPos(selection.ranges[0].$from, (node) => {
|
|
317
|
+
return node.type.name === "table";
|
|
318
|
+
});
|
|
319
|
+
table == null ? void 0 : table.node.descendants((node) => {
|
|
320
|
+
if (node.type.name === "table") {
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
if (["tableCell", "tableHeader"].includes(node.type.name)) {
|
|
324
|
+
cellCount += 1;
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
const allCellsSelected = cellCount === selection.ranges.length;
|
|
328
|
+
if (!allCellsSelected) {
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
editor.commands.deleteTable();
|
|
332
|
+
return true;
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
// src/table/utilities/markdown.ts
|
|
336
|
+
var DEFAULT_CELL_LINE_SEPARATOR = "";
|
|
337
|
+
function collapseWhitespace(s) {
|
|
338
|
+
return (s || "").replace(/\s+/g, " ").trim();
|
|
339
|
+
}
|
|
340
|
+
function renderTableToMarkdown(node, h, options = {}) {
|
|
341
|
+
var _a;
|
|
342
|
+
const cellSep = (_a = options.cellLineSeparator) != null ? _a : DEFAULT_CELL_LINE_SEPARATOR;
|
|
343
|
+
if (!node || !node.content || node.content.length === 0) {
|
|
344
|
+
return "";
|
|
345
|
+
}
|
|
346
|
+
const rows = [];
|
|
347
|
+
node.content.forEach((rowNode) => {
|
|
348
|
+
const cells = [];
|
|
349
|
+
if (rowNode.content) {
|
|
350
|
+
rowNode.content.forEach((cellNode) => {
|
|
351
|
+
let raw = "";
|
|
352
|
+
if (cellNode.content && Array.isArray(cellNode.content) && cellNode.content.length > 1) {
|
|
353
|
+
const parts = cellNode.content.map((child) => h.renderChildren(child));
|
|
354
|
+
raw = parts.join(cellSep);
|
|
355
|
+
} else {
|
|
356
|
+
raw = cellNode.content ? h.renderChildren(cellNode.content) : "";
|
|
357
|
+
}
|
|
358
|
+
const text = collapseWhitespace(raw);
|
|
359
|
+
const isHeader = cellNode.type === "tableHeader";
|
|
360
|
+
cells.push({ text, isHeader });
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
rows.push(cells);
|
|
364
|
+
});
|
|
365
|
+
const columnCount = rows.reduce((max, r) => Math.max(max, r.length), 0);
|
|
366
|
+
if (columnCount === 0) {
|
|
367
|
+
return "";
|
|
368
|
+
}
|
|
369
|
+
const colWidths = new Array(columnCount).fill(0);
|
|
370
|
+
rows.forEach((r) => {
|
|
371
|
+
var _a2;
|
|
372
|
+
for (let i = 0; i < columnCount; i += 1) {
|
|
373
|
+
const cell = ((_a2 = r[i]) == null ? void 0 : _a2.text) || "";
|
|
374
|
+
const len = cell.length;
|
|
375
|
+
if (len > colWidths[i]) {
|
|
376
|
+
colWidths[i] = len;
|
|
377
|
+
}
|
|
378
|
+
if (colWidths[i] < 3) {
|
|
379
|
+
colWidths[i] = 3;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
const pad = (s, width) => s + " ".repeat(Math.max(0, width - s.length));
|
|
384
|
+
const headerRow = rows[0];
|
|
385
|
+
const hasHeader = headerRow.some((c) => c.isHeader);
|
|
386
|
+
let out = "\n";
|
|
387
|
+
const headerTexts = new Array(columnCount).fill(0).map((_, i) => hasHeader ? headerRow[i] && headerRow[i].text || "" : "");
|
|
388
|
+
out += `| ${headerTexts.map((t, i) => pad(t, colWidths[i])).join(" | ")} |
|
|
389
|
+
`;
|
|
390
|
+
out += `| ${colWidths.map((w) => "-".repeat(Math.max(3, w))).join(" | ")} |
|
|
391
|
+
`;
|
|
392
|
+
const body = hasHeader ? rows.slice(1) : rows;
|
|
393
|
+
body.forEach((r) => {
|
|
394
|
+
out += `| ${new Array(columnCount).fill(0).map((_, i) => pad(r[i] && r[i].text || "", colWidths[i])).join(" | ")} |
|
|
395
|
+
`;
|
|
396
|
+
});
|
|
397
|
+
return out;
|
|
398
|
+
}
|
|
399
|
+
var markdown_default = renderTableToMarkdown;
|
|
400
|
+
|
|
401
|
+
// src/table/table.ts
|
|
402
|
+
var Table = Node4.create({
|
|
403
|
+
name: "table",
|
|
404
|
+
// @ts-ignore
|
|
405
|
+
addOptions() {
|
|
406
|
+
return {
|
|
407
|
+
HTMLAttributes: {},
|
|
408
|
+
resizable: false,
|
|
409
|
+
renderWrapper: false,
|
|
410
|
+
handleWidth: 5,
|
|
411
|
+
cellMinWidth: 25,
|
|
412
|
+
// TODO: fix
|
|
413
|
+
View: TableView,
|
|
414
|
+
lastColumnResizable: true,
|
|
415
|
+
allowTableNodeSelection: false
|
|
416
|
+
};
|
|
417
|
+
},
|
|
418
|
+
content: "tableRow+",
|
|
419
|
+
tableRole: "table",
|
|
420
|
+
isolating: true,
|
|
421
|
+
group: "block",
|
|
422
|
+
parseHTML() {
|
|
423
|
+
return [{ tag: "table" }];
|
|
424
|
+
},
|
|
425
|
+
renderHTML({ node, HTMLAttributes }) {
|
|
426
|
+
const { colgroup, tableWidth, tableMinWidth } = createColGroup(node, this.options.cellMinWidth);
|
|
427
|
+
const userStyles = HTMLAttributes.style;
|
|
428
|
+
function getTableStyle() {
|
|
429
|
+
if (userStyles) {
|
|
430
|
+
return userStyles;
|
|
431
|
+
}
|
|
432
|
+
return tableWidth ? `width: ${tableWidth}` : `min-width: ${tableMinWidth}`;
|
|
433
|
+
}
|
|
434
|
+
const table = [
|
|
435
|
+
"table",
|
|
436
|
+
mergeAttributes4(this.options.HTMLAttributes, HTMLAttributes, {
|
|
437
|
+
style: getTableStyle()
|
|
438
|
+
}),
|
|
439
|
+
colgroup,
|
|
440
|
+
["tbody", 0]
|
|
441
|
+
];
|
|
442
|
+
return this.options.renderWrapper ? ["div", { class: "tableWrapper" }, table] : table;
|
|
443
|
+
},
|
|
444
|
+
parseMarkdown: (token, h) => {
|
|
445
|
+
const rows = [];
|
|
446
|
+
if (token.header) {
|
|
447
|
+
const headerCells = [];
|
|
448
|
+
token.header.forEach((cell) => {
|
|
449
|
+
headerCells.push(h.createNode("tableHeader", {}, [{ type: "paragraph", content: h.parseInline(cell.tokens) }]));
|
|
450
|
+
});
|
|
451
|
+
rows.push(h.createNode("tableRow", {}, headerCells));
|
|
452
|
+
}
|
|
453
|
+
if (token.rows) {
|
|
454
|
+
token.rows.forEach((row) => {
|
|
455
|
+
const bodyCells = [];
|
|
456
|
+
row.forEach((cell) => {
|
|
457
|
+
bodyCells.push(h.createNode("tableCell", {}, [{ type: "paragraph", content: h.parseInline(cell.tokens) }]));
|
|
458
|
+
});
|
|
459
|
+
rows.push(h.createNode("tableRow", {}, bodyCells));
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
return h.createNode("table", void 0, rows);
|
|
463
|
+
},
|
|
464
|
+
renderMarkdown: (node, h) => {
|
|
465
|
+
return markdown_default(node, h);
|
|
466
|
+
},
|
|
467
|
+
addCommands() {
|
|
468
|
+
return {
|
|
469
|
+
insertTable: ({ rows = 3, cols = 3, withHeaderRow = true } = {}) => ({ tr, dispatch, editor }) => {
|
|
470
|
+
const node = createTable(editor.schema, rows, cols, withHeaderRow);
|
|
471
|
+
if (dispatch) {
|
|
472
|
+
const offset = tr.selection.from + 1;
|
|
473
|
+
tr.replaceSelectionWith(node).scrollIntoView().setSelection(TextSelection.near(tr.doc.resolve(offset)));
|
|
474
|
+
}
|
|
475
|
+
return true;
|
|
476
|
+
},
|
|
477
|
+
addColumnBefore: () => ({ state, dispatch }) => {
|
|
478
|
+
return addColumnBefore(state, dispatch);
|
|
479
|
+
},
|
|
480
|
+
addColumnAfter: () => ({ state, dispatch }) => {
|
|
481
|
+
return addColumnAfter(state, dispatch);
|
|
482
|
+
},
|
|
483
|
+
deleteColumn: () => ({ state, dispatch }) => {
|
|
484
|
+
return deleteColumn(state, dispatch);
|
|
485
|
+
},
|
|
486
|
+
addRowBefore: () => ({ state, dispatch }) => {
|
|
487
|
+
return addRowBefore(state, dispatch);
|
|
488
|
+
},
|
|
489
|
+
addRowAfter: () => ({ state, dispatch }) => {
|
|
490
|
+
return addRowAfter(state, dispatch);
|
|
491
|
+
},
|
|
492
|
+
deleteRow: () => ({ state, dispatch }) => {
|
|
493
|
+
return deleteRow(state, dispatch);
|
|
494
|
+
},
|
|
495
|
+
deleteTable: () => ({ state, dispatch }) => {
|
|
496
|
+
return deleteTable(state, dispatch);
|
|
497
|
+
},
|
|
498
|
+
mergeCells: () => ({ state, dispatch }) => {
|
|
499
|
+
return mergeCells(state, dispatch);
|
|
500
|
+
},
|
|
501
|
+
splitCell: () => ({ state, dispatch }) => {
|
|
502
|
+
return splitCell(state, dispatch);
|
|
503
|
+
},
|
|
504
|
+
toggleHeaderColumn: () => ({ state, dispatch }) => {
|
|
505
|
+
return toggleHeader("column")(state, dispatch);
|
|
506
|
+
},
|
|
507
|
+
toggleHeaderRow: () => ({ state, dispatch }) => {
|
|
508
|
+
return toggleHeader("row")(state, dispatch);
|
|
509
|
+
},
|
|
510
|
+
toggleHeaderCell: () => ({ state, dispatch }) => {
|
|
511
|
+
return toggleHeaderCell(state, dispatch);
|
|
512
|
+
},
|
|
513
|
+
mergeOrSplit: () => ({ state, dispatch }) => {
|
|
514
|
+
if (mergeCells(state, dispatch)) {
|
|
515
|
+
return true;
|
|
516
|
+
}
|
|
517
|
+
return splitCell(state, dispatch);
|
|
518
|
+
},
|
|
519
|
+
setCellAttribute: (name, value) => ({ state, dispatch }) => {
|
|
520
|
+
return setCellAttr(name, value)(state, dispatch);
|
|
521
|
+
},
|
|
522
|
+
goToNextCell: () => ({ state, dispatch }) => {
|
|
523
|
+
return goToNextCell(1)(state, dispatch);
|
|
524
|
+
},
|
|
525
|
+
goToPreviousCell: () => ({ state, dispatch }) => {
|
|
526
|
+
return goToNextCell(-1)(state, dispatch);
|
|
527
|
+
},
|
|
528
|
+
fixTables: () => ({ state, dispatch }) => {
|
|
529
|
+
if (dispatch) {
|
|
530
|
+
fixTables(state);
|
|
531
|
+
}
|
|
532
|
+
return true;
|
|
533
|
+
},
|
|
534
|
+
setCellSelection: (position) => ({ tr, dispatch }) => {
|
|
535
|
+
if (dispatch) {
|
|
536
|
+
const selection = CellSelection2.create(tr.doc, position.anchorCell, position.headCell);
|
|
537
|
+
tr.setSelection(selection);
|
|
538
|
+
}
|
|
539
|
+
return true;
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
},
|
|
543
|
+
addKeyboardShortcuts() {
|
|
544
|
+
return {
|
|
545
|
+
Tab: () => {
|
|
546
|
+
if (this.editor.commands.goToNextCell()) {
|
|
547
|
+
return true;
|
|
548
|
+
}
|
|
549
|
+
if (!this.editor.can().addRowAfter()) {
|
|
550
|
+
return false;
|
|
551
|
+
}
|
|
552
|
+
return this.editor.chain().addRowAfter().goToNextCell().run();
|
|
553
|
+
},
|
|
554
|
+
"Shift-Tab": () => this.editor.commands.goToPreviousCell(),
|
|
555
|
+
Backspace: deleteTableWhenAllCellsSelected,
|
|
556
|
+
"Mod-Backspace": deleteTableWhenAllCellsSelected,
|
|
557
|
+
Delete: deleteTableWhenAllCellsSelected,
|
|
558
|
+
"Mod-Delete": deleteTableWhenAllCellsSelected
|
|
559
|
+
};
|
|
560
|
+
},
|
|
561
|
+
addProseMirrorPlugins() {
|
|
562
|
+
const isResizable = this.options.resizable && this.editor.isEditable;
|
|
563
|
+
return [
|
|
564
|
+
...isResizable ? [
|
|
565
|
+
columnResizing({
|
|
566
|
+
handleWidth: this.options.handleWidth,
|
|
567
|
+
cellMinWidth: this.options.cellMinWidth,
|
|
568
|
+
defaultCellMinWidth: this.options.cellMinWidth,
|
|
569
|
+
View: this.options.View,
|
|
570
|
+
lastColumnResizable: this.options.lastColumnResizable
|
|
571
|
+
})
|
|
572
|
+
] : [],
|
|
573
|
+
tableEditing({
|
|
574
|
+
allowTableNodeSelection: this.options.allowTableNodeSelection
|
|
575
|
+
})
|
|
576
|
+
];
|
|
577
|
+
},
|
|
578
|
+
extendNodeSchema(extension) {
|
|
579
|
+
const context = {
|
|
580
|
+
name: extension.name,
|
|
581
|
+
options: extension.options,
|
|
582
|
+
storage: extension.storage
|
|
583
|
+
};
|
|
584
|
+
return {
|
|
585
|
+
tableRole: callOrReturn(getExtensionField(extension, "tableRole", context))
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
// src/kit/index.ts
|
|
591
|
+
var TableKit = Extension.create({
|
|
592
|
+
name: "tableKit",
|
|
593
|
+
addExtensions() {
|
|
594
|
+
const extensions = [];
|
|
595
|
+
if (this.options.table !== false) {
|
|
596
|
+
extensions.push(Table.configure(this.options.table));
|
|
597
|
+
}
|
|
598
|
+
if (this.options.tableCell !== false) {
|
|
599
|
+
extensions.push(TableCell.configure(this.options.tableCell));
|
|
600
|
+
}
|
|
601
|
+
if (this.options.tableHeader !== false) {
|
|
602
|
+
extensions.push(TableHeader.configure(this.options.tableHeader));
|
|
603
|
+
}
|
|
604
|
+
if (this.options.tableRow !== false) {
|
|
605
|
+
extensions.push(TableRow.configure(this.options.tableRow));
|
|
606
|
+
}
|
|
607
|
+
return extensions;
|
|
608
|
+
}
|
|
609
|
+
});
|
|
610
|
+
export {
|
|
611
|
+
DEFAULT_CELL_LINE_SEPARATOR,
|
|
612
|
+
Table,
|
|
613
|
+
TableCell,
|
|
614
|
+
TableHeader,
|
|
615
|
+
TableKit,
|
|
616
|
+
TableRow,
|
|
617
|
+
TableView,
|
|
618
|
+
createColGroup,
|
|
619
|
+
createTable,
|
|
620
|
+
renderTableToMarkdown,
|
|
621
|
+
updateColumns
|
|
622
|
+
};
|
|
623
|
+
//# sourceMappingURL=index.js.map
|