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