@pixerate/editor 0.44.0 → 0.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -2
- package/dist/agent/index.cjs +548 -45
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.d.cts +47 -17
- package/dist/agent/index.d.ts +47 -17
- package/dist/agent/index.js +536 -33
- package/dist/agent/index.js.map +1 -1
- package/dist/{builtins-BLud97fC.d.cts → builtins-CZW-aYKS.d.cts} +1 -1
- package/dist/{builtins-D0BDyAgw.d.ts → builtins-DghNQbT-.d.ts} +1 -1
- package/dist/{chunk-I6BZB5ZH.cjs → chunk-EFDCLENW.cjs} +73 -6
- package/dist/chunk-EFDCLENW.cjs.map +1 -0
- package/dist/chunk-HHQ4XJWT.js +826 -0
- package/dist/chunk-HHQ4XJWT.js.map +1 -0
- package/dist/chunk-J3R2OWOE.cjs +1465 -0
- package/dist/chunk-J3R2OWOE.cjs.map +1 -0
- package/dist/chunk-K2LVZ4FA.cjs +826 -0
- package/dist/chunk-K2LVZ4FA.cjs.map +1 -0
- package/dist/{chunk-6MDQKHRH.cjs → chunk-N4MLNJPO.cjs} +21 -899
- package/dist/chunk-N4MLNJPO.cjs.map +1 -0
- package/dist/chunk-PQM5W7ZN.js +168 -0
- package/dist/chunk-PQM5W7ZN.js.map +1 -0
- package/dist/{chunk-DDADOHJW.js → chunk-Q25ZS4F7.js} +5 -883
- package/dist/chunk-Q25ZS4F7.js.map +1 -0
- package/dist/chunk-TK2XZK6Z.js +1465 -0
- package/dist/chunk-TK2XZK6Z.js.map +1 -0
- package/dist/commands/index.cjs +3 -2
- package/dist/commands/index.cjs.map +1 -1
- package/dist/commands/index.d.cts +5 -5
- package/dist/commands/index.d.ts +5 -5
- package/dist/commands/index.js +2 -1
- package/dist/commands/index.js.map +1 -1
- package/dist/extensions/index.cjs +4 -4
- package/dist/extensions/index.cjs.map +1 -1
- package/dist/extensions/index.d.cts +3 -3
- package/dist/extensions/index.d.ts +3 -3
- package/dist/extensions/index.js +12 -12
- package/dist/generation/index.cjs +2 -2
- package/dist/generation/index.d.cts +4 -4
- package/dist/generation/index.d.ts +4 -4
- package/dist/generation/index.js +1 -1
- package/dist/image-editor/index.cjs +24 -24
- package/dist/image-editor/index.cjs.map +1 -1
- package/dist/image-editor/index.d.cts +2 -2
- package/dist/image-editor/index.d.ts +2 -2
- package/dist/image-editor/index.js +24 -24
- package/dist/image-editor/index.js.map +1 -1
- package/dist/{index-C6gaQRH0.d.cts → index-CfOQf70b.d.cts} +1 -1
- package/dist/{index-DXAv_R08.d.ts → index-jwJ_onWf.d.ts} +1 -1
- package/dist/index.cjs +9 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +12 -12
- package/dist/parameters/index.d.cts +2 -2
- package/dist/parameters/index.d.ts +2 -2
- package/dist/{registry-DnzpgY27.d.cts → registry-B4l-lYts.d.cts} +1 -1
- package/dist/{registry-DhVUZioj.d.ts → registry-BfVD-vVg.d.ts} +1 -1
- package/dist/{registry-BDe-vlv3.d.ts → registry-CSlH4iUn.d.ts} +1 -1
- package/dist/{registry-D0GADKc7.d.cts → registry-vz6HOiiy.d.cts} +1 -1
- package/dist/{schema-DYDGdYL9.d.cts → schema-Di0CS6Pe.d.cts} +26 -2
- package/dist/{schema-DYDGdYL9.d.ts → schema-Di0CS6Pe.d.ts} +26 -2
- package/dist/tools/index.cjs +37 -3
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.d.cts +871 -11
- package/dist/tools/index.d.ts +871 -11
- package/dist/tools/index.js +36 -2
- package/dist/vector/index.d.cts +2 -2
- package/dist/vector/index.d.ts +2 -2
- package/package.json +1 -1
- package/dist/chunk-36BLROHV.js +0 -438
- package/dist/chunk-36BLROHV.js.map +0 -1
- package/dist/chunk-5H2OPMXZ.js +0 -586
- package/dist/chunk-5H2OPMXZ.js.map +0 -1
- package/dist/chunk-6MDQKHRH.cjs.map +0 -1
- package/dist/chunk-D6S5M7HV.js +0 -101
- package/dist/chunk-D6S5M7HV.js.map +0 -1
- package/dist/chunk-DDADOHJW.js.map +0 -1
- package/dist/chunk-I6BZB5ZH.cjs.map +0 -1
- package/dist/chunk-MC2LQN5S.cjs +0 -586
- package/dist/chunk-MC2LQN5S.cjs.map +0 -1
- package/dist/chunk-V7CC7RZ6.cjs +0 -438
- package/dist/chunk-V7CC7RZ6.cjs.map +0 -1
package/dist/chunk-5H2OPMXZ.js
DELETED
|
@@ -1,586 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
isTrackChangesEnabled
|
|
3
|
-
} from "./chunk-SWE3NPOU.js";
|
|
4
|
-
|
|
5
|
-
// src/extensions/table/nesting.ts
|
|
6
|
-
import { Fragment, Slice } from "@tiptap/pm/model";
|
|
7
|
-
import { Plugin, PluginKey, Selection } from "@tiptap/pm/state";
|
|
8
|
-
import {
|
|
9
|
-
CellSelection,
|
|
10
|
-
__pastedCells,
|
|
11
|
-
handlePaste as handleTablePaste
|
|
12
|
-
} from "@tiptap/pm/tables";
|
|
13
|
-
var ALLOW_NESTED_TABLES_META = "allowNestedTables";
|
|
14
|
-
var tableNestingPluginKey = new PluginKey("tableNesting");
|
|
15
|
-
var roleOf = (node) => node.type.spec.tableRole;
|
|
16
|
-
var isTableNode = (node) => roleOf(node) === "table";
|
|
17
|
-
function outermostTableDepth($pos) {
|
|
18
|
-
for (let d = 1; d <= $pos.depth; d++) if (isTableNode($pos.node(d))) return d;
|
|
19
|
-
return -1;
|
|
20
|
-
}
|
|
21
|
-
function isInTableCell($pos) {
|
|
22
|
-
for (let d = $pos.depth; d > 0; d--) {
|
|
23
|
-
const role = roleOf($pos.node(d));
|
|
24
|
-
if (role === "cell" || role === "header_cell") return true;
|
|
25
|
-
}
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
function sliceContainsTable(content) {
|
|
29
|
-
const fragment = content instanceof Slice ? content.content : content;
|
|
30
|
-
let found = false;
|
|
31
|
-
fragment.descendants((node) => {
|
|
32
|
-
if (found) return false;
|
|
33
|
-
if (isTableNode(node)) found = true;
|
|
34
|
-
return !found;
|
|
35
|
-
});
|
|
36
|
-
return found;
|
|
37
|
-
}
|
|
38
|
-
function insertSliceAfterTable(tr, from, to, slice) {
|
|
39
|
-
const $from = tr.doc.resolve(from);
|
|
40
|
-
const depth = outermostTableDepth($from);
|
|
41
|
-
if (depth < 0) return null;
|
|
42
|
-
const tableStart = $from.before(depth);
|
|
43
|
-
const tableEnd = $from.after(depth);
|
|
44
|
-
if (to > from && to < tableEnd) {
|
|
45
|
-
if (tr.selection instanceof CellSelection && tr.selection.from === from && tr.selection.to === to) {
|
|
46
|
-
tr.deleteSelection();
|
|
47
|
-
} else {
|
|
48
|
-
tr.delete(from, to);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
const table = tr.doc.nodeAt(tableStart);
|
|
52
|
-
if (!table) return null;
|
|
53
|
-
const after = tableStart + table.nodeSize;
|
|
54
|
-
const before = tr.doc.content.size;
|
|
55
|
-
tr.replace(after, after, new Slice(slice.content, 0, 0));
|
|
56
|
-
return after + (tr.doc.content.size - before);
|
|
57
|
-
}
|
|
58
|
-
function handleTablePasteWithoutNesting(view, event, slice) {
|
|
59
|
-
const { state } = view;
|
|
60
|
-
const { selection } = state;
|
|
61
|
-
if (outermostTableDepth(selection.$from) < 0) return false;
|
|
62
|
-
if (selection instanceof CellSelection || __pastedCells(slice)) {
|
|
63
|
-
if (handleTablePaste(view, event, slice)) return true;
|
|
64
|
-
}
|
|
65
|
-
if (!sliceContainsTable(slice)) return false;
|
|
66
|
-
const tr = state.tr;
|
|
67
|
-
const end = insertSliceAfterTable(tr, selection.from, selection.to, slice);
|
|
68
|
-
if (end === null) return false;
|
|
69
|
-
tr.setSelection(Selection.near(tr.doc.resolve(end), -1));
|
|
70
|
-
view.dispatch(tr.scrollIntoView().setMeta("paste", true).setMeta("uiEvent", "paste"));
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
function changedRanges(transactions, skip2) {
|
|
74
|
-
let ranges = [];
|
|
75
|
-
for (const tr of transactions) {
|
|
76
|
-
const skipped = skip2(tr);
|
|
77
|
-
for (const step of tr.steps) {
|
|
78
|
-
const map = step.getMap();
|
|
79
|
-
ranges = ranges.map(([from, to]) => [map.map(from, 1), map.map(to, -1)]).filter(([from, to]) => to > from);
|
|
80
|
-
if (skipped) continue;
|
|
81
|
-
map.forEach((_oldStart, _oldEnd, newStart, newEnd) => {
|
|
82
|
-
if (newEnd > newStart) ranges.push([newStart, newEnd]);
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return ranges;
|
|
87
|
-
}
|
|
88
|
-
function findNestedTables(doc, ranges) {
|
|
89
|
-
const found = /* @__PURE__ */ new Set();
|
|
90
|
-
for (const [from, to] of ranges) {
|
|
91
|
-
doc.nodesBetween(from, to, (node, pos) => {
|
|
92
|
-
if (!isTableNode(node) || pos < from) return true;
|
|
93
|
-
if (isInTableCell(doc.resolve(pos))) {
|
|
94
|
-
found.add(pos);
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
return true;
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
const sorted = [...found].sort((a, b) => a - b);
|
|
101
|
-
const outer = [];
|
|
102
|
-
for (const pos of sorted) {
|
|
103
|
-
const last = outer[outer.length - 1];
|
|
104
|
-
if (last === void 0 || pos >= last + doc.nodeAt(last).nodeSize) outer.push(pos);
|
|
105
|
-
}
|
|
106
|
-
return outer;
|
|
107
|
-
}
|
|
108
|
-
function unnestTables(tr, ranges) {
|
|
109
|
-
let changed = false;
|
|
110
|
-
for (let round = 0; round < 32 && ranges.length; round++) {
|
|
111
|
-
const nested = findNestedTables(tr.doc, ranges);
|
|
112
|
-
if (!nested.length) break;
|
|
113
|
-
const groups = /* @__PURE__ */ new Map();
|
|
114
|
-
for (const pos of nested) {
|
|
115
|
-
const $pos = tr.doc.resolve(pos);
|
|
116
|
-
const outer = $pos.before(outermostTableDepth($pos));
|
|
117
|
-
groups.set(outer, [...groups.get(outer) ?? [], pos]);
|
|
118
|
-
}
|
|
119
|
-
const next = [];
|
|
120
|
-
for (const outer of [...groups.keys()].sort((a, b) => b - a)) {
|
|
121
|
-
const positions = groups.get(outer);
|
|
122
|
-
const nodes = positions.map((pos) => tr.doc.nodeAt(pos));
|
|
123
|
-
for (let i = positions.length - 1; i >= 0; i--) {
|
|
124
|
-
const pos = positions[i];
|
|
125
|
-
const node = nodes[i];
|
|
126
|
-
const $pos = tr.doc.resolve(pos);
|
|
127
|
-
const parent = $pos.parent;
|
|
128
|
-
const filler = parent.childCount === 1 ? parent.type.contentMatch.defaultType?.createAndFill() : null;
|
|
129
|
-
if (filler) tr.replaceWith(pos, pos + node.nodeSize, filler);
|
|
130
|
-
else tr.delete(pos, pos + node.nodeSize);
|
|
131
|
-
}
|
|
132
|
-
const table = tr.doc.nodeAt(outer);
|
|
133
|
-
const after = outer + table.nodeSize;
|
|
134
|
-
const fragment = Fragment.fromArray(nodes);
|
|
135
|
-
tr.insert(after, fragment);
|
|
136
|
-
next.push([after, after + fragment.size]);
|
|
137
|
-
changed = true;
|
|
138
|
-
}
|
|
139
|
-
ranges = next;
|
|
140
|
-
}
|
|
141
|
-
return changed;
|
|
142
|
-
}
|
|
143
|
-
function replacesDocument(tr) {
|
|
144
|
-
return tr.steps.some((step, i) => {
|
|
145
|
-
const { from, to } = step;
|
|
146
|
-
return from === 0 && to !== void 0 && to >= tr.docs[i].content.size;
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
var skip = (tr) => !tr.docChanged || tr.getMeta(ALLOW_NESTED_TABLES_META) === true || // Undo/redo and remote collaborative changes restore what was there.
|
|
150
|
-
!!tr.getMeta("history$") || !!tr.getMeta("y-sync$") || // Other plugins' housekeeping, e.g. Track Changes putting a deleted
|
|
151
|
-
// (nested) table back so the deletion can be reviewed.
|
|
152
|
-
!!tr.getMeta("appendedTransaction") || replacesDocument(tr);
|
|
153
|
-
function createTableNestingPlugin() {
|
|
154
|
-
return new Plugin({
|
|
155
|
-
key: tableNestingPluginKey,
|
|
156
|
-
props: {
|
|
157
|
-
handlePaste: (view, event, slice) => handleTablePasteWithoutNesting(view, event, slice)
|
|
158
|
-
},
|
|
159
|
-
appendTransaction(transactions, _oldState, newState) {
|
|
160
|
-
if (transactions.every(skip)) return null;
|
|
161
|
-
const ranges = changedRanges(transactions, skip);
|
|
162
|
-
if (!ranges.length) return null;
|
|
163
|
-
const tr = newState.tr;
|
|
164
|
-
if (!unnestTables(tr, ranges)) return null;
|
|
165
|
-
return tr;
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// src/extensions/table/extension.ts
|
|
171
|
-
import { getHTMLFromFragment } from "@tiptap/core";
|
|
172
|
-
import { Fragment as Fragment2 } from "@tiptap/pm/model";
|
|
173
|
-
import * as _Table from "@tiptap/extension-table";
|
|
174
|
-
import * as _TableRow from "@tiptap/extension-table-row";
|
|
175
|
-
import * as _TableHeader from "@tiptap/extension-table-header";
|
|
176
|
-
import * as _TableCell from "@tiptap/extension-table-cell";
|
|
177
|
-
var resolveExt = (mod, name) => mod?.[name] || mod?.default?.[name] || mod?.default?.default || mod?.default || mod;
|
|
178
|
-
var BaseTable = resolveExt(_Table, "Table");
|
|
179
|
-
var BaseTableRow = resolveExt(_TableRow, "TableRow");
|
|
180
|
-
var BaseTableHeader = resolveExt(_TableHeader, "TableHeader");
|
|
181
|
-
var BaseTableCell = resolveExt(_TableCell, "TableCell");
|
|
182
|
-
var ALIGNMENTS = /* @__PURE__ */ new Set(["left", "center", "right", "justify"]);
|
|
183
|
-
function normalizeTableCellAlignment(value) {
|
|
184
|
-
const v = typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
185
|
-
return ALIGNMENTS.has(v) ? v : null;
|
|
186
|
-
}
|
|
187
|
-
var COLOR_REGEX = /^(?:#[0-9a-f]{3,8}|(?:rgb|rgba|hsl|hsla)\(\s*[-0-9.%\s,/deg]+\)|[a-z]{3,20})$/i;
|
|
188
|
-
function normalizeTableCellColor(value) {
|
|
189
|
-
const v = typeof value === "string" ? value.trim() : "";
|
|
190
|
-
if (!v || v.length > 64 || !COLOR_REGEX.test(v)) return null;
|
|
191
|
-
if (/^(?:inherit|initial|unset|revert|transparent)$/i.test(v)) return null;
|
|
192
|
-
return v;
|
|
193
|
-
}
|
|
194
|
-
var cellAttributes = () => ({
|
|
195
|
-
align: {
|
|
196
|
-
default: null,
|
|
197
|
-
parseHTML: (element) => normalizeTableCellAlignment(element.style?.textAlign || element.getAttribute("align")),
|
|
198
|
-
renderHTML: (attrs) => {
|
|
199
|
-
const align = normalizeTableCellAlignment(attrs.align);
|
|
200
|
-
return align ? { style: `text-align: ${align}` } : {};
|
|
201
|
-
}
|
|
202
|
-
},
|
|
203
|
-
backgroundColor: {
|
|
204
|
-
default: null,
|
|
205
|
-
parseHTML: (element) => normalizeTableCellColor(
|
|
206
|
-
element.getAttribute("data-background-color") || element.style?.backgroundColor || element.getAttribute("bgcolor")
|
|
207
|
-
),
|
|
208
|
-
renderHTML: (attrs) => {
|
|
209
|
-
const color = normalizeTableCellColor(attrs.backgroundColor);
|
|
210
|
-
return color ? { style: `background-color: ${color}`, "data-background-color": color } : {};
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
var children = (node) => {
|
|
215
|
-
const list = [];
|
|
216
|
-
node.forEach((child) => list.push(child));
|
|
217
|
-
return list;
|
|
218
|
-
};
|
|
219
|
-
var hasSpan = (cell) => (cell.attrs.colspan ?? 1) > 1 || (cell.attrs.rowspan ?? 1) > 1;
|
|
220
|
-
function isGfmTable(node) {
|
|
221
|
-
const rows = children(node);
|
|
222
|
-
if (rows.length === 0) return false;
|
|
223
|
-
const width = rows[0].childCount;
|
|
224
|
-
return rows.every(
|
|
225
|
-
(row, r) => row.childCount === width && children(row).every(
|
|
226
|
-
(cell) => (r === 0 ? cell.type.name === "tableHeader" : cell.type.name === "tableCell") && !hasSpan(cell) && cell.childCount === 1 && cell.firstChild.type.name === "paragraph"
|
|
227
|
-
)
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
|
-
var DELIMITERS = { left: ":---", center: ":---:", right: "---:" };
|
|
231
|
-
function serializeTableMarkdown(state, node) {
|
|
232
|
-
if (!isGfmTable(node)) {
|
|
233
|
-
const html = getHTMLFromFragment(Fragment2.from(node), node.type.schema);
|
|
234
|
-
state.write(html.replace(/\n{2,}/g, "\n"));
|
|
235
|
-
state.closeBlock(node);
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
const previous = state.inTable;
|
|
239
|
-
state.inTable = true;
|
|
240
|
-
children(node).forEach((row, r) => {
|
|
241
|
-
if (r) state.ensureNewLine();
|
|
242
|
-
state.write("| ");
|
|
243
|
-
children(row).forEach((cell, c) => {
|
|
244
|
-
if (c) state.write(" | ");
|
|
245
|
-
const paragraph = cell.firstChild;
|
|
246
|
-
const start = state.out.length;
|
|
247
|
-
if (paragraph.childCount) state.renderInline(paragraph);
|
|
248
|
-
const text = state.out.slice(start);
|
|
249
|
-
state.out = state.out.slice(0, start) + text.replace(/\n/g, " ").replace(/\|/g, "\\|");
|
|
250
|
-
});
|
|
251
|
-
state.write(" |");
|
|
252
|
-
if (r === 0) {
|
|
253
|
-
const delimiter = children(row).map((cell) => DELIMITERS[cell.attrs.align] ?? "---");
|
|
254
|
-
state.ensureNewLine();
|
|
255
|
-
state.write(`| ${delimiter.join(" | ")} |`);
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
state.inTable = previous;
|
|
259
|
-
state.closeBlock(node);
|
|
260
|
-
}
|
|
261
|
-
var DEFAULT_TABLE_OPTIONS = {
|
|
262
|
-
resizable: true,
|
|
263
|
-
handleWidth: 5,
|
|
264
|
-
cellMinWidth: 25,
|
|
265
|
-
lastColumnResizable: true,
|
|
266
|
-
allowTableNodeSelection: true,
|
|
267
|
-
HTMLAttributes: { class: "pixerate-table" },
|
|
268
|
-
cellHTMLAttributes: {},
|
|
269
|
-
headerHTMLAttributes: {},
|
|
270
|
-
rowHTMLAttributes: {}
|
|
271
|
-
};
|
|
272
|
-
var Table = BaseTable.extend({
|
|
273
|
-
addStorage() {
|
|
274
|
-
return { markdown: { serialize: serializeTableMarkdown } };
|
|
275
|
-
},
|
|
276
|
-
addProseMirrorPlugins() {
|
|
277
|
-
return [...this.parent?.() ?? [], createTableNestingPlugin()];
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
var TableRow = BaseTableRow;
|
|
281
|
-
var TableCell = BaseTableCell.extend({
|
|
282
|
-
addAttributes() {
|
|
283
|
-
return { ...this.parent?.(), ...cellAttributes() };
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
var TableHeader = BaseTableHeader.extend({
|
|
287
|
-
addAttributes() {
|
|
288
|
-
return { ...this.parent?.(), ...cellAttributes() };
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
function createTableExtensions(options = {}) {
|
|
292
|
-
const o = { ...DEFAULT_TABLE_OPTIONS, ...options };
|
|
293
|
-
return [
|
|
294
|
-
Table.configure({
|
|
295
|
-
resizable: o.resizable,
|
|
296
|
-
handleWidth: o.handleWidth,
|
|
297
|
-
cellMinWidth: o.cellMinWidth,
|
|
298
|
-
lastColumnResizable: o.lastColumnResizable,
|
|
299
|
-
allowTableNodeSelection: o.allowTableNodeSelection,
|
|
300
|
-
HTMLAttributes: o.HTMLAttributes
|
|
301
|
-
}),
|
|
302
|
-
TableRow.configure({ HTMLAttributes: o.rowHTMLAttributes }),
|
|
303
|
-
TableHeader.configure({ HTMLAttributes: o.headerHTMLAttributes }),
|
|
304
|
-
TableCell.configure({ HTMLAttributes: o.cellHTMLAttributes })
|
|
305
|
-
];
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// src/extensions/table/actions.ts
|
|
309
|
-
import { CellSelection as CellSelection2, isInTable, selectedRect } from "@tiptap/pm/tables";
|
|
310
|
-
var TABLE_ACTIONS = [
|
|
311
|
-
{ action: "insertTable", label: "Insert Table", description: "Inserts a table (rows, cols, withHeaderRow) at the cursor.", keywords: ["table", "grid", "new"] },
|
|
312
|
-
{ action: "addRowBefore", label: "Insert Row Above", description: "Adds a row above the current row.", keywords: ["row", "add", "above"] },
|
|
313
|
-
{ action: "addRowAfter", label: "Insert Row Below", description: "Adds a row below the current row.", keywords: ["row", "add", "below"] },
|
|
314
|
-
{ action: "deleteRow", label: "Delete Row", description: "Deletes the selected rows.", keywords: ["row", "remove"] },
|
|
315
|
-
{ action: "addColumnBefore", label: "Insert Column Left", description: "Adds a column left of the current column.", keywords: ["column", "add", "left", "before"] },
|
|
316
|
-
{ action: "addColumnAfter", label: "Insert Column Right", description: "Adds a column right of the current column.", keywords: ["column", "add", "right", "after"] },
|
|
317
|
-
{ action: "deleteColumn", label: "Delete Column", description: "Deletes the selected columns.", keywords: ["column", "remove"] },
|
|
318
|
-
{ action: "deleteTable", label: "Delete Table", description: "Deletes the table around the cursor.", keywords: ["table", "remove"] },
|
|
319
|
-
{ action: "mergeCells", label: "Merge Cells", description: "Merges the selected cells into one.", keywords: ["combine", "join", "span"] },
|
|
320
|
-
{ action: "splitCell", label: "Split Cell", description: "Splits a merged cell back into single cells.", keywords: ["unmerge", "span"] },
|
|
321
|
-
{ action: "toggleHeaderRow", label: "Toggle Header Row", description: "Turns the first row into header cells, or back.", keywords: ["header", "row", "th"] },
|
|
322
|
-
{ action: "toggleHeaderColumn", label: "Toggle Header Column", description: "Turns the first column into header cells, or back.", keywords: ["header", "column", "th"] },
|
|
323
|
-
{ action: "toggleHeaderCell", label: "Toggle Header Cell", description: "Turns the selected cells into header cells, or back.", keywords: ["header", "cell", "th"] },
|
|
324
|
-
{ action: "goToNextCell", label: "Next Cell", description: "Moves the cursor to the next cell.", keywords: ["tab", "navigate"] },
|
|
325
|
-
{ action: "goToPreviousCell", label: "Previous Cell", description: "Moves the cursor to the previous cell.", keywords: ["shift tab", "navigate"] },
|
|
326
|
-
{ action: "setCellAlignment", label: "Align Cells\u2026", description: "Sets the horizontal alignment (align: left | center | right | justify | null) of the selected cells.", keywords: ["align", "left", "center", "right"] },
|
|
327
|
-
{ action: "setCellBackground", label: "Cell Background\u2026", description: "Sets the background color (color: CSS color or null) of the selected cells.", keywords: ["shading", "fill", "color"] }
|
|
328
|
-
];
|
|
329
|
-
var DEFAULT_TABLE_TOOLBAR = [
|
|
330
|
-
{ id: "addRowBefore", action: "addRowBefore", label: "+ Row \u2191", title: "Insert row above", group: "rows" },
|
|
331
|
-
{ id: "addRowAfter", action: "addRowAfter", label: "+ Row \u2193", title: "Insert row below", group: "rows" },
|
|
332
|
-
{ id: "deleteRow", action: "deleteRow", label: "\u2212 Row", title: "Delete row", group: "rows" },
|
|
333
|
-
{ id: "addColumnBefore", action: "addColumnBefore", label: "+ Col \u2190", title: "Insert column left", group: "columns" },
|
|
334
|
-
{ id: "addColumnAfter", action: "addColumnAfter", label: "+ Col \u2192", title: "Insert column right", group: "columns" },
|
|
335
|
-
{ id: "deleteColumn", action: "deleteColumn", label: "\u2212 Col", title: "Delete column", group: "columns" },
|
|
336
|
-
{ id: "mergeCells", action: "mergeCells", label: "Merge", title: "Merge cells", group: "cells" },
|
|
337
|
-
{ id: "splitCell", action: "splitCell", label: "Split", title: "Split cell", group: "cells" },
|
|
338
|
-
{ id: "toggleHeaderRow", action: "toggleHeaderRow", label: "Header row", title: "Toggle header row", group: "headers", active: (s) => s.headerRow },
|
|
339
|
-
{ id: "toggleHeaderColumn", action: "toggleHeaderColumn", label: "Header col", title: "Toggle header column", group: "headers", active: (s) => s.headerColumn },
|
|
340
|
-
{ id: "toggleHeaderCell", action: "toggleHeaderCell", label: "Header cell", title: "Toggle header cell", group: "headers", active: (s) => s.headerCell },
|
|
341
|
-
{ id: "alignLeft", action: "setCellAlignment", params: { align: "left" }, label: "Left", title: "Align cell left", group: "align", active: (s) => s.cellAlignment === "left" },
|
|
342
|
-
{ id: "alignCenter", action: "setCellAlignment", params: { align: "center" }, label: "Center", title: "Align cell center", group: "align", active: (s) => s.cellAlignment === "center" },
|
|
343
|
-
{ id: "alignRight", action: "setCellAlignment", params: { align: "right" }, label: "Right", title: "Align cell right", group: "align", active: (s) => s.cellAlignment === "right" },
|
|
344
|
-
{ id: "deleteTable", action: "deleteTable", label: "Delete table", title: "Delete table", group: "table" }
|
|
345
|
-
];
|
|
346
|
-
var MAX_TABLE_ROWS = 100;
|
|
347
|
-
var MAX_TABLE_COLUMNS = 50;
|
|
348
|
-
var live = (editor) => !!editor && !editor.isDestroyed;
|
|
349
|
-
function isTableEnabled(editor) {
|
|
350
|
-
return live(editor) && !!editor.schema.nodes.table && !!editor.schema.nodes.tableRow;
|
|
351
|
-
}
|
|
352
|
-
function isSelectionInTable(state) {
|
|
353
|
-
if (!state.schema.nodes.table) return false;
|
|
354
|
-
return state.selection instanceof CellSelection2 || isInTable(state);
|
|
355
|
-
}
|
|
356
|
-
function shouldShowTableBubbleMenu({ editor, state }) {
|
|
357
|
-
return editor.isEditable && isSelectionInTable(state);
|
|
358
|
-
}
|
|
359
|
-
var isInt = (value, min, max) => typeof value === "number" && Number.isInteger(value) && value >= min && value <= max;
|
|
360
|
-
var can = (editor, run) => {
|
|
361
|
-
try {
|
|
362
|
-
return !!run(editor.can().chain()).run();
|
|
363
|
-
} catch {
|
|
364
|
-
return false;
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
function getTableActionState(editor, action, params = {}) {
|
|
368
|
-
if (!live(editor)) return "The editor is not available.";
|
|
369
|
-
if (!isTableEnabled(editor)) return "Tables are not enabled in this editor.";
|
|
370
|
-
if (!editor.isEditable) return "The editor is read-only.";
|
|
371
|
-
const state = editor.state;
|
|
372
|
-
const inTable = isSelectionInTable(state);
|
|
373
|
-
if (action === "insertTable") {
|
|
374
|
-
if (inTable) return "Tables cannot be nested: move the cursor out of the table first.";
|
|
375
|
-
if (params.rows !== void 0 && !isInt(params.rows, 1, MAX_TABLE_ROWS)) {
|
|
376
|
-
return `Rows must be a whole number from 1 to ${MAX_TABLE_ROWS}.`;
|
|
377
|
-
}
|
|
378
|
-
if (params.cols !== void 0 && !isInt(params.cols, 1, MAX_TABLE_COLUMNS)) {
|
|
379
|
-
return `Columns must be a whole number from 1 to ${MAX_TABLE_COLUMNS}.`;
|
|
380
|
-
}
|
|
381
|
-
return can(editor, (c) => c.insertTable({ rows: 1, cols: 1 })) ? true : "A table cannot be inserted here.";
|
|
382
|
-
}
|
|
383
|
-
if (!inTable) return "Place the cursor in a table first.";
|
|
384
|
-
switch (action) {
|
|
385
|
-
case "mergeCells":
|
|
386
|
-
case "splitCell": {
|
|
387
|
-
if (isTrackChangesEnabled(editor)) {
|
|
388
|
-
return `${action === "mergeCells" ? "Merging" : "Splitting"} cells cannot be tracked: turn off Track Changes first.`;
|
|
389
|
-
}
|
|
390
|
-
if (action === "mergeCells") {
|
|
391
|
-
return can(editor, (c) => c.mergeCells()) ? true : "Select two or more adjacent cells to merge.";
|
|
392
|
-
}
|
|
393
|
-
return can(editor, (c) => c.splitCell()) ? true : "Only a merged cell can be split.";
|
|
394
|
-
}
|
|
395
|
-
case "deleteRow":
|
|
396
|
-
case "deleteColumn": {
|
|
397
|
-
const rect = selectedRect(state);
|
|
398
|
-
const all = action === "deleteRow" ? rect.top === 0 && rect.bottom === rect.map.height : rect.left === 0 && rect.right === rect.map.width;
|
|
399
|
-
const what = action === "deleteRow" ? "rows" : "columns";
|
|
400
|
-
if (all || !can(editor, (c) => c[action]())) return `These are all the ${what}: delete the table instead.`;
|
|
401
|
-
return true;
|
|
402
|
-
}
|
|
403
|
-
case "goToNextCell":
|
|
404
|
-
return can(editor, (c) => c.goToNextCell()) ? true : "This is the last cell.";
|
|
405
|
-
case "goToPreviousCell":
|
|
406
|
-
return can(editor, (c) => c.goToPreviousCell()) ? true : "This is the first cell.";
|
|
407
|
-
case "setCellAlignment":
|
|
408
|
-
if (params.align !== void 0 && params.align !== null && !normalizeTableCellAlignment(params.align)) {
|
|
409
|
-
return 'Alignment must be "left", "center", "right", "justify" or null.';
|
|
410
|
-
}
|
|
411
|
-
if (!editor.schema.nodes.tableCell?.spec.attrs?.align) return "Cell alignment is not supported by this schema.";
|
|
412
|
-
return true;
|
|
413
|
-
case "setCellBackground":
|
|
414
|
-
if (params.color !== void 0 && params.color !== null && !normalizeTableCellColor(params.color)) {
|
|
415
|
-
return "Color must be a CSS color such as #fde68a, rgb(\u2026) or a color name, or null.";
|
|
416
|
-
}
|
|
417
|
-
if (!editor.schema.nodes.tableCell?.spec.attrs?.backgroundColor) return "Cell backgrounds are not supported by this schema.";
|
|
418
|
-
return true;
|
|
419
|
-
default:
|
|
420
|
-
return can(editor, (c) => c[action]()) ? true : "This table action is not available here.";
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
function runTableAction(editor, action, params = {}, options = {}) {
|
|
424
|
-
if (getTableActionState(editor, action, params) !== true) return false;
|
|
425
|
-
const ed = editor;
|
|
426
|
-
let chain = ed.chain();
|
|
427
|
-
if (options.focus) chain = chain.focus();
|
|
428
|
-
switch (action) {
|
|
429
|
-
case "insertTable":
|
|
430
|
-
chain = chain.insertTable({
|
|
431
|
-
rows: params.rows ?? 3,
|
|
432
|
-
cols: params.cols ?? 3,
|
|
433
|
-
withHeaderRow: params.withHeaderRow ?? true
|
|
434
|
-
});
|
|
435
|
-
break;
|
|
436
|
-
case "setCellAlignment":
|
|
437
|
-
chain = chain.setCellAttribute("align", normalizeTableCellAlignment(params.align));
|
|
438
|
-
break;
|
|
439
|
-
case "setCellBackground":
|
|
440
|
-
chain = chain.setCellAttribute("backgroundColor", normalizeTableCellColor(params.color));
|
|
441
|
-
break;
|
|
442
|
-
default:
|
|
443
|
-
chain = chain[action]();
|
|
444
|
-
}
|
|
445
|
-
return !!chain.run();
|
|
446
|
-
}
|
|
447
|
-
var NO_ACTIONS = Object.fromEntries(
|
|
448
|
-
TABLE_ACTIONS.map(({ action }) => [action, { enabled: false, reason: "The editor is not available." }])
|
|
449
|
-
);
|
|
450
|
-
var EMPTY_TABLE_STATE = Object.freeze({
|
|
451
|
-
enabled: false,
|
|
452
|
-
inTable: false,
|
|
453
|
-
cellSelection: false,
|
|
454
|
-
rows: 0,
|
|
455
|
-
columns: 0,
|
|
456
|
-
row: -1,
|
|
457
|
-
column: -1,
|
|
458
|
-
headerRow: false,
|
|
459
|
-
headerColumn: false,
|
|
460
|
-
headerCell: false,
|
|
461
|
-
cellAlignment: null,
|
|
462
|
-
cellBackground: null,
|
|
463
|
-
actions: NO_ACTIONS
|
|
464
|
-
});
|
|
465
|
-
function getTableState(editor) {
|
|
466
|
-
if (!live(editor)) return EMPTY_TABLE_STATE;
|
|
467
|
-
const actions = Object.fromEntries(
|
|
468
|
-
TABLE_ACTIONS.map(({ action }) => {
|
|
469
|
-
const result = getTableActionState(editor, action);
|
|
470
|
-
return [action, result === true ? { enabled: true } : { enabled: false, reason: result }];
|
|
471
|
-
})
|
|
472
|
-
);
|
|
473
|
-
const state = editor.state;
|
|
474
|
-
const base = { ...EMPTY_TABLE_STATE, enabled: isTableEnabled(editor), actions };
|
|
475
|
-
if (!base.enabled || !isSelectionInTable(state)) return base;
|
|
476
|
-
try {
|
|
477
|
-
const rect = selectedRect(state);
|
|
478
|
-
const { map, table } = rect;
|
|
479
|
-
const cellAt = (row, col) => table.nodeAt(map.map[row * map.width + col]);
|
|
480
|
-
const allHeaders = (positions) => positions.length > 0 && positions.every((pos) => table.nodeAt(pos)?.type.name === "tableHeader");
|
|
481
|
-
const firstRow = map.cellsInRect({ left: 0, right: map.width, top: 0, bottom: 1 });
|
|
482
|
-
const firstColumn = map.cellsInRect({ left: 0, right: 1, top: 0, bottom: map.height });
|
|
483
|
-
const cell = cellAt(rect.top, rect.left);
|
|
484
|
-
return {
|
|
485
|
-
...base,
|
|
486
|
-
inTable: true,
|
|
487
|
-
cellSelection: state.selection instanceof CellSelection2,
|
|
488
|
-
rows: map.height,
|
|
489
|
-
columns: map.width,
|
|
490
|
-
row: rect.top,
|
|
491
|
-
column: rect.left,
|
|
492
|
-
headerRow: allHeaders(firstRow),
|
|
493
|
-
headerColumn: allHeaders(firstColumn),
|
|
494
|
-
headerCell: cell?.type.name === "tableHeader",
|
|
495
|
-
cellAlignment: normalizeTableCellAlignment(cell?.attrs.align),
|
|
496
|
-
cellBackground: normalizeTableCellColor(cell?.attrs.backgroundColor)
|
|
497
|
-
};
|
|
498
|
-
} catch {
|
|
499
|
-
return { ...base, inTable: true };
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
var stateKey = (state) => JSON.stringify(state);
|
|
503
|
-
function createTableStore(editor) {
|
|
504
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
505
|
-
let snapshot = getTableState(editor);
|
|
506
|
-
let key = stateKey(snapshot);
|
|
507
|
-
const update = () => {
|
|
508
|
-
const next = getTableState(editor);
|
|
509
|
-
const nextKey = stateKey(next);
|
|
510
|
-
if (nextKey === key) return;
|
|
511
|
-
snapshot = next;
|
|
512
|
-
key = nextKey;
|
|
513
|
-
listeners.forEach((listener) => listener());
|
|
514
|
-
};
|
|
515
|
-
const detach = () => {
|
|
516
|
-
editor?.off("transaction", update);
|
|
517
|
-
editor?.off("update", update);
|
|
518
|
-
editor?.off("focus", update);
|
|
519
|
-
editor?.off("destroy", update);
|
|
520
|
-
};
|
|
521
|
-
return {
|
|
522
|
-
getSnapshot: () => {
|
|
523
|
-
if (!listeners.size) {
|
|
524
|
-
const next = getTableState(editor);
|
|
525
|
-
const nextKey = stateKey(next);
|
|
526
|
-
if (nextKey !== key) {
|
|
527
|
-
snapshot = next;
|
|
528
|
-
key = nextKey;
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
return snapshot;
|
|
532
|
-
},
|
|
533
|
-
subscribe(listener) {
|
|
534
|
-
if (!listeners.size && editor) {
|
|
535
|
-
update();
|
|
536
|
-
editor.on("transaction", update);
|
|
537
|
-
editor.on("update", update);
|
|
538
|
-
editor.on("focus", update);
|
|
539
|
-
editor.on("destroy", update);
|
|
540
|
-
}
|
|
541
|
-
listeners.add(listener);
|
|
542
|
-
return () => {
|
|
543
|
-
listeners.delete(listener);
|
|
544
|
-
if (!listeners.size) detach();
|
|
545
|
-
};
|
|
546
|
-
},
|
|
547
|
-
destroy() {
|
|
548
|
-
detach();
|
|
549
|
-
listeners.clear();
|
|
550
|
-
}
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
export {
|
|
555
|
-
ALLOW_NESTED_TABLES_META,
|
|
556
|
-
tableNestingPluginKey,
|
|
557
|
-
outermostTableDepth,
|
|
558
|
-
isInTableCell,
|
|
559
|
-
sliceContainsTable,
|
|
560
|
-
insertSliceAfterTable,
|
|
561
|
-
handleTablePasteWithoutNesting,
|
|
562
|
-
unnestTables,
|
|
563
|
-
createTableNestingPlugin,
|
|
564
|
-
normalizeTableCellAlignment,
|
|
565
|
-
normalizeTableCellColor,
|
|
566
|
-
isGfmTable,
|
|
567
|
-
DEFAULT_TABLE_OPTIONS,
|
|
568
|
-
Table,
|
|
569
|
-
TableRow,
|
|
570
|
-
TableCell,
|
|
571
|
-
TableHeader,
|
|
572
|
-
createTableExtensions,
|
|
573
|
-
TABLE_ACTIONS,
|
|
574
|
-
DEFAULT_TABLE_TOOLBAR,
|
|
575
|
-
MAX_TABLE_ROWS,
|
|
576
|
-
MAX_TABLE_COLUMNS,
|
|
577
|
-
isTableEnabled,
|
|
578
|
-
isSelectionInTable,
|
|
579
|
-
shouldShowTableBubbleMenu,
|
|
580
|
-
getTableActionState,
|
|
581
|
-
runTableAction,
|
|
582
|
-
EMPTY_TABLE_STATE,
|
|
583
|
-
getTableState,
|
|
584
|
-
createTableStore
|
|
585
|
-
};
|
|
586
|
-
//# sourceMappingURL=chunk-5H2OPMXZ.js.map
|