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