@pixerate/editor 0.26.1 → 0.27.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.
Files changed (64) hide show
  1. package/README.md +8 -2
  2. package/dist/agent/index.cjs +56 -6
  3. package/dist/agent/index.cjs.map +1 -1
  4. package/dist/agent/index.d.cts +6 -4
  5. package/dist/agent/index.d.ts +6 -4
  6. package/dist/agent/index.js +51 -1
  7. package/dist/agent/index.js.map +1 -1
  8. package/dist/{builtins-Chj6zv_O.d.ts → builtins-haN82vjT.d.ts} +33 -3
  9. package/dist/{builtins-CdPcLwwF.d.cts → builtins-nMXh9sT3.d.cts} +33 -3
  10. package/dist/canvas/index.cjs +372 -8
  11. package/dist/canvas/index.cjs.map +1 -1
  12. package/dist/canvas/index.d.cts +72 -4
  13. package/dist/canvas/index.d.ts +72 -4
  14. package/dist/canvas/index.js +368 -4
  15. package/dist/canvas/index.js.map +1 -1
  16. package/dist/{chunk-UBCFIABU.js → chunk-5H2OPMXZ.js} +183 -6
  17. package/dist/chunk-5H2OPMXZ.js.map +1 -0
  18. package/dist/{chunk-XQFHLT53.js → chunk-6IO7WUSU.js} +17 -3
  19. package/dist/chunk-6IO7WUSU.js.map +1 -0
  20. package/dist/{chunk-LN2POBHT.cjs → chunk-AGR7EVRW.cjs} +24 -10
  21. package/dist/chunk-AGR7EVRW.cjs.map +1 -0
  22. package/dist/chunk-HXDMZQTD.cjs +497 -0
  23. package/dist/chunk-HXDMZQTD.cjs.map +1 -0
  24. package/dist/chunk-IB3ZHQAX.js +497 -0
  25. package/dist/chunk-IB3ZHQAX.js.map +1 -0
  26. package/dist/{chunk-X7HXL2SB.js → chunk-JT7AXQTE.js} +336 -10
  27. package/dist/chunk-JT7AXQTE.js.map +1 -0
  28. package/dist/{chunk-HDYMLS3X.cjs → chunk-MC2LQN5S.cjs} +196 -19
  29. package/dist/chunk-MC2LQN5S.cjs.map +1 -0
  30. package/dist/{chunk-NQF32I6Z.cjs → chunk-YK5TATOF.cjs} +461 -135
  31. package/dist/chunk-YK5TATOF.cjs.map +1 -0
  32. package/dist/commands/index.cjs +30 -410
  33. package/dist/commands/index.cjs.map +1 -1
  34. package/dist/commands/index.d.cts +1 -1
  35. package/dist/commands/index.d.ts +1 -1
  36. package/dist/commands/index.js +17 -397
  37. package/dist/commands/index.js.map +1 -1
  38. package/dist/{controller-CxXGOEmy.d.cts → controller-w6eRTjF8.d.cts} +67 -2
  39. package/dist/{controller-CxXGOEmy.d.ts → controller-w6eRTjF8.d.ts} +67 -2
  40. package/dist/extensions/index.cjs +21 -3
  41. package/dist/extensions/index.cjs.map +1 -1
  42. package/dist/extensions/index.d.cts +1 -1
  43. package/dist/extensions/index.d.ts +1 -1
  44. package/dist/extensions/index.js +21 -3
  45. package/dist/{index-jcJwmBYt.d.cts → index-C6gaQRH0.d.cts} +53 -4
  46. package/dist/{index-B273Zllk.d.ts → index-DXAv_R08.d.ts} +53 -4
  47. package/dist/index.cjs +47 -9
  48. package/dist/index.cjs.map +1 -1
  49. package/dist/index.d.cts +7 -5
  50. package/dist/index.d.ts +7 -5
  51. package/dist/index.js +42 -4
  52. package/dist/index.js.map +1 -1
  53. package/dist/spreadsheet/index.cjs +22 -2
  54. package/dist/spreadsheet/index.cjs.map +1 -1
  55. package/dist/spreadsheet/index.d.cts +76 -3
  56. package/dist/spreadsheet/index.d.ts +76 -3
  57. package/dist/spreadsheet/index.js +21 -1
  58. package/package.json +1 -1
  59. package/dist/chunk-HDYMLS3X.cjs.map +0 -1
  60. package/dist/chunk-LN2POBHT.cjs.map +0 -1
  61. package/dist/chunk-NQF32I6Z.cjs.map +0 -1
  62. package/dist/chunk-UBCFIABU.js.map +0 -1
  63. package/dist/chunk-X7HXL2SB.js.map +0 -1
  64. package/dist/chunk-XQFHLT53.js.map +0 -1
@@ -2,14 +2,179 @@
2
2
 
3
3
  var _chunkIFHKKVXHcjs = require('./chunk-IFHKKVXH.cjs');
4
4
 
5
+ // src/extensions/table/nesting.ts
6
+ var _model = require('@tiptap/pm/model');
7
+ var _state = require('@tiptap/pm/state');
8
+
9
+
10
+
11
+
12
+ var _tables = require('@tiptap/pm/tables');
13
+ var ALLOW_NESTED_TABLES_META = "allowNestedTables";
14
+ var tableNestingPluginKey = new (0, _state.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 _model.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 _tables.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 (0, _model.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 _tables.CellSelection || _tables.__pastedCells.call(void 0, slice)) {
63
+ if (_tables.handlePaste.call(void 0, 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(_state.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, [..._nullishCoalesce(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 ? _optionalChain([parent, 'access', _ => _.type, 'access', _2 => _2.contentMatch, 'access', _3 => _3.defaultType, 'optionalAccess', _4 => _4.createAndFill, 'call', _5 => _5()]) : 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 = _model.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 (0, _state.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
+
5
170
  // src/extensions/table/extension.ts
6
171
  var _core = require('@tiptap/core');
7
- var _model = require('@tiptap/pm/model');
172
+
8
173
  var _extensiontable = require('@tiptap/extension-table'); var _Table = _interopRequireWildcard(_extensiontable);
9
174
  var _extensiontablerow = require('@tiptap/extension-table-row'); var _TableRow = _interopRequireWildcard(_extensiontablerow);
10
175
  var _extensiontableheader = require('@tiptap/extension-table-header'); var _TableHeader = _interopRequireWildcard(_extensiontableheader);
11
176
  var _extensiontablecell = require('@tiptap/extension-table-cell'); var _TableCell = _interopRequireWildcard(_extensiontablecell);
12
- var resolveExt = (mod, name) => _optionalChain([mod, 'optionalAccess', _ => _[name]]) || _optionalChain([mod, 'optionalAccess', _2 => _2.default, 'optionalAccess', _3 => _3[name]]) || _optionalChain([mod, 'optionalAccess', _4 => _4.default, 'optionalAccess', _5 => _5.default]) || _optionalChain([mod, 'optionalAccess', _6 => _6.default]) || mod;
177
+ var resolveExt = (mod, name) => _optionalChain([mod, 'optionalAccess', _6 => _6[name]]) || _optionalChain([mod, 'optionalAccess', _7 => _7.default, 'optionalAccess', _8 => _8[name]]) || _optionalChain([mod, 'optionalAccess', _9 => _9.default, 'optionalAccess', _10 => _10.default]) || _optionalChain([mod, 'optionalAccess', _11 => _11.default]) || mod;
13
178
  var BaseTable = resolveExt(_Table, "Table");
14
179
  var BaseTableRow = resolveExt(_TableRow, "TableRow");
15
180
  var BaseTableHeader = resolveExt(_TableHeader, "TableHeader");
@@ -29,7 +194,7 @@ function normalizeTableCellColor(value) {
29
194
  var cellAttributes = () => ({
30
195
  align: {
31
196
  default: null,
32
- parseHTML: (element) => normalizeTableCellAlignment(_optionalChain([element, 'access', _7 => _7.style, 'optionalAccess', _8 => _8.textAlign]) || element.getAttribute("align")),
197
+ parseHTML: (element) => normalizeTableCellAlignment(_optionalChain([element, 'access', _12 => _12.style, 'optionalAccess', _13 => _13.textAlign]) || element.getAttribute("align")),
33
198
  renderHTML: (attrs) => {
34
199
  const align = normalizeTableCellAlignment(attrs.align);
35
200
  return align ? { style: `text-align: ${align}` } : {};
@@ -38,7 +203,7 @@ var cellAttributes = () => ({
38
203
  backgroundColor: {
39
204
  default: null,
40
205
  parseHTML: (element) => normalizeTableCellColor(
41
- element.getAttribute("data-background-color") || _optionalChain([element, 'access', _9 => _9.style, 'optionalAccess', _10 => _10.backgroundColor]) || element.getAttribute("bgcolor")
206
+ element.getAttribute("data-background-color") || _optionalChain([element, 'access', _14 => _14.style, 'optionalAccess', _15 => _15.backgroundColor]) || element.getAttribute("bgcolor")
42
207
  ),
43
208
  renderHTML: (attrs) => {
44
209
  const color = normalizeTableCellColor(attrs.backgroundColor);
@@ -107,17 +272,20 @@ var DEFAULT_TABLE_OPTIONS = {
107
272
  var Table = BaseTable.extend({
108
273
  addStorage() {
109
274
  return { markdown: { serialize: serializeTableMarkdown } };
275
+ },
276
+ addProseMirrorPlugins() {
277
+ return [..._nullishCoalesce(_optionalChain([this, 'access', _16 => _16.parent, 'optionalCall', _17 => _17()]), () => ( [])), createTableNestingPlugin()];
110
278
  }
111
279
  });
112
280
  var TableRow = BaseTableRow;
113
281
  var TableCell = BaseTableCell.extend({
114
282
  addAttributes() {
115
- return { ..._optionalChain([this, 'access', _11 => _11.parent, 'optionalCall', _12 => _12()]), ...cellAttributes() };
283
+ return { ..._optionalChain([this, 'access', _18 => _18.parent, 'optionalCall', _19 => _19()]), ...cellAttributes() };
116
284
  }
117
285
  });
118
286
  var TableHeader = BaseTableHeader.extend({
119
287
  addAttributes() {
120
- return { ..._optionalChain([this, 'access', _13 => _13.parent, 'optionalCall', _14 => _14()]), ...cellAttributes() };
288
+ return { ..._optionalChain([this, 'access', _20 => _20.parent, 'optionalCall', _21 => _21()]), ...cellAttributes() };
121
289
  }
122
290
  });
123
291
  function createTableExtensions(options = {}) {
@@ -138,7 +306,7 @@ function createTableExtensions(options = {}) {
138
306
  }
139
307
 
140
308
  // src/extensions/table/actions.ts
141
- var _tables = require('@tiptap/pm/tables');
309
+
142
310
  var TABLE_ACTIONS = [
143
311
  { action: "insertTable", label: "Insert Table", description: "Inserts a table (rows, cols, withHeaderRow) at the cursor.", keywords: ["table", "grid", "new"] },
144
312
  { action: "addRowBefore", label: "Insert Row Above", description: "Adds a row above the current row.", keywords: ["row", "add", "above"] },
@@ -240,13 +408,13 @@ function getTableActionState(editor, action, params = {}) {
240
408
  if (params.align !== void 0 && params.align !== null && !normalizeTableCellAlignment(params.align)) {
241
409
  return 'Alignment must be "left", "center", "right", "justify" or null.';
242
410
  }
243
- if (!_optionalChain([editor, 'access', _15 => _15.schema, 'access', _16 => _16.nodes, 'access', _17 => _17.tableCell, 'optionalAccess', _18 => _18.spec, 'access', _19 => _19.attrs, 'optionalAccess', _20 => _20.align])) return "Cell alignment is not supported by this schema.";
411
+ if (!_optionalChain([editor, 'access', _22 => _22.schema, 'access', _23 => _23.nodes, 'access', _24 => _24.tableCell, 'optionalAccess', _25 => _25.spec, 'access', _26 => _26.attrs, 'optionalAccess', _27 => _27.align])) return "Cell alignment is not supported by this schema.";
244
412
  return true;
245
413
  case "setCellBackground":
246
414
  if (params.color !== void 0 && params.color !== null && !normalizeTableCellColor(params.color)) {
247
415
  return "Color must be a CSS color such as #fde68a, rgb(\u2026) or a color name, or null.";
248
416
  }
249
- if (!_optionalChain([editor, 'access', _21 => _21.schema, 'access', _22 => _22.nodes, 'access', _23 => _23.tableCell, 'optionalAccess', _24 => _24.spec, 'access', _25 => _25.attrs, 'optionalAccess', _26 => _26.backgroundColor])) return "Cell backgrounds are not supported by this schema.";
417
+ if (!_optionalChain([editor, 'access', _28 => _28.schema, 'access', _29 => _29.nodes, 'access', _30 => _30.tableCell, 'optionalAccess', _31 => _31.spec, 'access', _32 => _32.attrs, 'optionalAccess', _33 => _33.backgroundColor])) return "Cell backgrounds are not supported by this schema.";
250
418
  return true;
251
419
  default:
252
420
  return can(editor, (c) => c[action]()) ? true : "This table action is not available here.";
@@ -309,7 +477,7 @@ function getTableState(editor) {
309
477
  const rect = _tables.selectedRect.call(void 0, state);
310
478
  const { map, table } = rect;
311
479
  const cellAt = (row, col) => table.nodeAt(map.map[row * map.width + col]);
312
- const allHeaders = (positions) => positions.length > 0 && positions.every((pos) => _optionalChain([table, 'access', _27 => _27.nodeAt, 'call', _28 => _28(pos), 'optionalAccess', _29 => _29.type, 'access', _30 => _30.name]) === "tableHeader");
480
+ const allHeaders = (positions) => positions.length > 0 && positions.every((pos) => _optionalChain([table, 'access', _34 => _34.nodeAt, 'call', _35 => _35(pos), 'optionalAccess', _36 => _36.type, 'access', _37 => _37.name]) === "tableHeader");
313
481
  const firstRow = map.cellsInRect({ left: 0, right: map.width, top: 0, bottom: 1 });
314
482
  const firstColumn = map.cellsInRect({ left: 0, right: 1, top: 0, bottom: map.height });
315
483
  const cell = cellAt(rect.top, rect.left);
@@ -323,9 +491,9 @@ function getTableState(editor) {
323
491
  column: rect.left,
324
492
  headerRow: allHeaders(firstRow),
325
493
  headerColumn: allHeaders(firstColumn),
326
- headerCell: _optionalChain([cell, 'optionalAccess', _31 => _31.type, 'access', _32 => _32.name]) === "tableHeader",
327
- cellAlignment: normalizeTableCellAlignment(_optionalChain([cell, 'optionalAccess', _33 => _33.attrs, 'access', _34 => _34.align])),
328
- cellBackground: normalizeTableCellColor(_optionalChain([cell, 'optionalAccess', _35 => _35.attrs, 'access', _36 => _36.backgroundColor]))
494
+ headerCell: _optionalChain([cell, 'optionalAccess', _38 => _38.type, 'access', _39 => _39.name]) === "tableHeader",
495
+ cellAlignment: normalizeTableCellAlignment(_optionalChain([cell, 'optionalAccess', _40 => _40.attrs, 'access', _41 => _41.align])),
496
+ cellBackground: normalizeTableCellColor(_optionalChain([cell, 'optionalAccess', _42 => _42.attrs, 'access', _43 => _43.backgroundColor]))
329
497
  };
330
498
  } catch (e2) {
331
499
  return { ...base, inTable: true };
@@ -345,10 +513,10 @@ function createTableStore(editor) {
345
513
  listeners.forEach((listener) => listener());
346
514
  };
347
515
  const detach = () => {
348
- _optionalChain([editor, 'optionalAccess', _37 => _37.off, 'call', _38 => _38("transaction", update)]);
349
- _optionalChain([editor, 'optionalAccess', _39 => _39.off, 'call', _40 => _40("update", update)]);
350
- _optionalChain([editor, 'optionalAccess', _41 => _41.off, 'call', _42 => _42("focus", update)]);
351
- _optionalChain([editor, 'optionalAccess', _43 => _43.off, 'call', _44 => _44("destroy", update)]);
516
+ _optionalChain([editor, 'optionalAccess', _44 => _44.off, 'call', _45 => _45("transaction", update)]);
517
+ _optionalChain([editor, 'optionalAccess', _46 => _46.off, 'call', _47 => _47("update", update)]);
518
+ _optionalChain([editor, 'optionalAccess', _48 => _48.off, 'call', _49 => _49("focus", update)]);
519
+ _optionalChain([editor, 'optionalAccess', _50 => _50.off, 'call', _51 => _51("destroy", update)]);
352
520
  };
353
521
  return {
354
522
  getSnapshot: () => {
@@ -405,5 +573,14 @@ function createTableStore(editor) {
405
573
 
406
574
 
407
575
 
408
- exports.normalizeTableCellAlignment = normalizeTableCellAlignment; exports.normalizeTableCellColor = normalizeTableCellColor; exports.isGfmTable = isGfmTable; exports.DEFAULT_TABLE_OPTIONS = DEFAULT_TABLE_OPTIONS; exports.Table = Table; exports.TableRow = TableRow; exports.TableCell = TableCell; exports.TableHeader = TableHeader; exports.createTableExtensions = createTableExtensions; exports.TABLE_ACTIONS = TABLE_ACTIONS; exports.DEFAULT_TABLE_TOOLBAR = DEFAULT_TABLE_TOOLBAR; exports.MAX_TABLE_ROWS = MAX_TABLE_ROWS; exports.MAX_TABLE_COLUMNS = MAX_TABLE_COLUMNS; exports.isTableEnabled = isTableEnabled; exports.isSelectionInTable = isSelectionInTable; exports.shouldShowTableBubbleMenu = shouldShowTableBubbleMenu; exports.getTableActionState = getTableActionState; exports.runTableAction = runTableAction; exports.EMPTY_TABLE_STATE = EMPTY_TABLE_STATE; exports.getTableState = getTableState; exports.createTableStore = createTableStore;
409
- //# sourceMappingURL=chunk-HDYMLS3X.cjs.map
576
+
577
+
578
+
579
+
580
+
581
+
582
+
583
+
584
+
585
+ exports.ALLOW_NESTED_TABLES_META = ALLOW_NESTED_TABLES_META; exports.tableNestingPluginKey = tableNestingPluginKey; exports.outermostTableDepth = outermostTableDepth; exports.isInTableCell = isInTableCell; exports.sliceContainsTable = sliceContainsTable; exports.insertSliceAfterTable = insertSliceAfterTable; exports.handleTablePasteWithoutNesting = handleTablePasteWithoutNesting; exports.unnestTables = unnestTables; exports.createTableNestingPlugin = createTableNestingPlugin; exports.normalizeTableCellAlignment = normalizeTableCellAlignment; exports.normalizeTableCellColor = normalizeTableCellColor; exports.isGfmTable = isGfmTable; exports.DEFAULT_TABLE_OPTIONS = DEFAULT_TABLE_OPTIONS; exports.Table = Table; exports.TableRow = TableRow; exports.TableCell = TableCell; exports.TableHeader = TableHeader; exports.createTableExtensions = createTableExtensions; exports.TABLE_ACTIONS = TABLE_ACTIONS; exports.DEFAULT_TABLE_TOOLBAR = DEFAULT_TABLE_TOOLBAR; exports.MAX_TABLE_ROWS = MAX_TABLE_ROWS; exports.MAX_TABLE_COLUMNS = MAX_TABLE_COLUMNS; exports.isTableEnabled = isTableEnabled; exports.isSelectionInTable = isSelectionInTable; exports.shouldShowTableBubbleMenu = shouldShowTableBubbleMenu; exports.getTableActionState = getTableActionState; exports.runTableAction = runTableAction; exports.EMPTY_TABLE_STATE = EMPTY_TABLE_STATE; exports.getTableState = getTableState; exports.createTableStore = createTableStore;
586
+ //# sourceMappingURL=chunk-MC2LQN5S.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/editor/editor/packages/core/dist/chunk-MC2LQN5S.cjs","../src/extensions/table/nesting.ts","../src/extensions/table/extension.ts","../src/extensions/table/actions.ts"],"names":["skip","CellSelection"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;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AAA;AACR,EAAA;AAEN,EAAA;AACc,IAAA;AACJ,IAAA;AACR,IAAA;AACV,IAAA;AACL,IAAA;AACoC,IAAA;AAC5C,EAAA;AACqB,EAAA;AACc,oBAAA;AACL,oBAAA;AACD,oBAAA;AACE,oBAAA;AAC/B,EAAA;AAEO,EAAA;AACc,IAAA;AACI,MAAA;AACc,QAAA;AACJ,QAAA;AACR,QAAA;AACR,UAAA;AACL,UAAA;AACR,QAAA;AACF,MAAA;AACO,MAAA;AACT,IAAA;AACoB,IAAA;AACa,MAAA;AACtB,QAAA;AACwB,QAAA;AAEL,QAAA;AACD,QAAA;AACE,QAAA;AAC7B,MAAA;AACsB,MAAA;AACT,MAAA;AACc,QAAA;AACG,QAAA;AAC9B,MAAA;AACF,IAAA;AACU,IAAA;AACD,MAAA;AACS,MAAA;AAClB,IAAA;AACF,EAAA;AACF;AH8ImD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/editor/editor/packages/core/dist/chunk-MC2LQN5S.cjs","sourcesContent":[null,"import { Fragment, Slice, type Node as ProsemirrorNode, type ResolvedPos } from \"@tiptap/pm/model\";\nimport { Plugin, PluginKey, Selection, type Transaction } from \"@tiptap/pm/state\";\nimport type { EditorView } from \"@tiptap/pm/view\";\nimport {\n CellSelection,\n __pastedCells,\n handlePaste as handleTablePaste,\n} from \"@tiptap/pm/tables\";\n\n/**\n * Set this meta on a transaction to let it create tables inside table cells\n * (the nesting guard leaves it alone), e.g. when loading legacy content\n * through a transaction that does not replace the whole document.\n */\nexport const ALLOW_NESTED_TABLES_META = \"allowNestedTables\";\n\nexport const tableNestingPluginKey = new PluginKey(\"tableNesting\");\n\nconst roleOf = (node: ProsemirrorNode) => node.type.spec.tableRole as string | undefined;\nconst isTableNode = (node: ProsemirrorNode) => roleOf(node) === \"table\";\n\n/** Depth of the outermost table around `$pos`, or `-1` outside tables. */\nexport function outermostTableDepth($pos: ResolvedPos): number {\n for (let d = 1; d <= $pos.depth; d++) if (isTableNode($pos.node(d))) return d;\n return -1;\n}\n\n/** Whether `$pos` lies inside a table cell or header cell. */\nexport function isInTableCell($pos: ResolvedPos): boolean {\n for (let d = $pos.depth; d > 0; d--) {\n const role = roleOf($pos.node(d));\n if (role === \"cell\" || role === \"header_cell\") return true;\n }\n return false;\n}\n\n/** Whether a slice or fragment contains a table node at any depth. */\nexport function sliceContainsTable(content: Slice | Fragment): boolean {\n const fragment = content instanceof Slice ? content.content : content;\n let found = false;\n fragment.descendants((node) => {\n if (found) return false;\n if (isTableNode(node)) found = true;\n return !found;\n });\n return found;\n}\n\n/**\n * Inserts `slice` right after the outermost table around `from` instead of\n * inside the cell, deleting `from`–`to` first when both lie in that table.\n * Returns the position right after the inserted content, or `null` (and\n * leaves `tr` unchanged) when `from` is not in a table.\n */\nexport function insertSliceAfterTable(tr: Transaction, from: number, to: number, slice: Slice): number | null {\n const $from = tr.doc.resolve(from);\n const depth = outermostTableDepth($from);\n if (depth < 0) return null;\n const tableStart = $from.before(depth);\n const tableEnd = $from.after(depth);\n if (to > from && to < tableEnd) {\n if (tr.selection instanceof CellSelection && tr.selection.from === from && tr.selection.to === to) {\n tr.deleteSelection();\n } else {\n tr.delete(from, to);\n }\n }\n const table = tr.doc.nodeAt(tableStart);\n if (!table) return null;\n const after = tableStart + table.nodeSize;\n const before = tr.doc.content.size;\n // A closed slice: the content becomes blocks of its own after the table\n // instead of merging into whatever follows it.\n tr.replace(after, after, new Slice(slice.content, 0, 0));\n return after + (tr.doc.content.size - before);\n}\n\n/**\n * Paste handling for slices that contain a table while the selection is in a\n * table: a cell selection or a pasted table (rows, cells) fills the cells from\n * the cursor (prosemirror-tables), and anything else that contains a table is\n * inserted after the outermost table, with the cursor at its end. Returns\n * `false` when the paste needs no special handling.\n */\nexport function handleTablePasteWithoutNesting(view: EditorView, event: ClipboardEvent | null, slice: Slice): boolean {\n const { state } = view;\n const { selection } = state;\n if (outermostTableDepth(selection.$from) < 0) return false;\n if (selection instanceof CellSelection || __pastedCells(slice)) {\n if (handleTablePaste(view, event as ClipboardEvent, slice)) return true;\n }\n if (!sliceContainsTable(slice)) return false;\n const tr = state.tr;\n const end = insertSliceAfterTable(tr, selection.from, selection.to, slice);\n if (end === null) return false;\n tr.setSelection(Selection.near(tr.doc.resolve(end), -1));\n view.dispatch(tr.scrollIntoView().setMeta(\"paste\", true).setMeta(\"uiEvent\", \"paste\"));\n return true;\n}\n\n/**\n * Ranges of the final document that `transactions` changed, leaving out the\n * changes of skipped transactions (their steps still map the other ranges).\n */\nfunction changedRanges(transactions: readonly Transaction[], skip: (tr: Transaction) => boolean): [number, number][] {\n let ranges: [number, number][] = [];\n for (const tr of transactions) {\n const skipped = skip(tr);\n for (const step of tr.steps) {\n const map = step.getMap();\n // Content that later (skipped) steps insert at a range's edge is not\n // part of it; pure deletions leave nothing to check.\n ranges = ranges\n .map(([from, to]): [number, number] => [map.map(from, 1), map.map(to, -1)])\n .filter(([from, to]) => to > from);\n if (skipped) continue;\n map.forEach((_oldStart, _oldEnd, newStart, newEnd) => {\n if (newEnd > newStart) ranges.push([newStart, newEnd]);\n });\n }\n }\n return ranges;\n}\n\n/** Tables starting inside `ranges` that sit in a table cell. */\nfunction findNestedTables(doc: ProsemirrorNode, ranges: [number, number][]): number[] {\n const found = new Set<number>();\n for (const [from, to] of ranges) {\n doc.nodesBetween(from, to, (node, pos) => {\n if (!isTableNode(node) || pos < from) return true;\n if (isInTableCell(doc.resolve(pos))) {\n found.add(pos);\n return false;\n }\n return true;\n });\n }\n // A table inside another found table moves with it.\n const sorted = [...found].sort((a, b) => a - b);\n const outer: number[] = [];\n for (const pos of sorted) {\n const last = outer[outer.length - 1];\n if (last === undefined || pos >= last + doc.nodeAt(last)!.nodeSize) outer.push(pos);\n }\n return outer;\n}\n\n/**\n * Moves tables that sit in table cells (at positions in `ranges`) to right\n * after their outermost table, keeping their content, and repeats for tables\n * nested in the moved ones. A cell left without content gets an empty\n * paragraph. Returns whether `tr` changed.\n */\nexport function unnestTables(tr: Transaction, ranges: [number, number][]): boolean {\n let changed = false;\n for (let round = 0; round < 32 && ranges.length; round++) {\n const nested = findNestedTables(tr.doc, ranges);\n if (!nested.length) break;\n // Group by outermost table; handle later tables first so earlier\n // positions stay valid.\n const groups = new Map<number, number[]>();\n for (const pos of nested) {\n const $pos = tr.doc.resolve(pos);\n const outer = $pos.before(outermostTableDepth($pos));\n groups.set(outer, [...(groups.get(outer) ?? []), pos]);\n }\n const next: [number, number][] = [];\n for (const outer of [...groups.keys()].sort((a, b) => b - a)) {\n const positions = groups.get(outer)!;\n const nodes = positions.map((pos) => tr.doc.nodeAt(pos)!);\n for (let i = positions.length - 1; i >= 0; i--) {\n const pos = positions[i];\n const node = nodes[i];\n const $pos = tr.doc.resolve(pos);\n const parent = $pos.parent;\n const filler = parent.childCount === 1 ? parent.type.contentMatch.defaultType?.createAndFill() : null;\n if (filler) tr.replaceWith(pos, pos + node.nodeSize, filler);\n else tr.delete(pos, pos + node.nodeSize);\n }\n const table = tr.doc.nodeAt(outer)!;\n const after = outer + table.nodeSize;\n const fragment = Fragment.fromArray(nodes);\n tr.insert(after, fragment);\n // Later groups are before this one, so this range stays valid.\n next.push([after, after + fragment.size]);\n changed = true;\n }\n ranges = next;\n }\n return changed;\n}\n\n/**\n * Whether a transaction replaces the whole document (`setContent`, loading):\n * existing documents keep their nested tables.\n */\nfunction replacesDocument(tr: Transaction): boolean {\n return tr.steps.some((step, i) => {\n const { from, to } = step as unknown as { from?: number; to?: number };\n return from === 0 && to !== undefined && to >= tr.docs[i].content.size;\n });\n}\n\nconst skip = (tr: Transaction) =>\n !tr.docChanged ||\n tr.getMeta(ALLOW_NESTED_TABLES_META) === true ||\n // Undo/redo and remote collaborative changes restore what was there.\n !!tr.getMeta(\"history$\") ||\n !!tr.getMeta(\"y-sync$\") ||\n // Other plugins' housekeeping, e.g. Track Changes putting a deleted\n // (nested) table back so the deletion can be reviewed.\n !!tr.getMeta(\"appendedTransaction\") ||\n replacesDocument(tr);\n\n/**\n * Keeps tables out of table cells: paste handling (see\n * `handleTablePasteWithoutNesting`) plus a guard that moves any table a\n * local edit puts into a cell (`insertContent`, `insertTable`, drops) to\n * right after the outermost table. Documents that already contain nested\n * tables (initial content, `setContent`, undo/redo, collaboration, Track\n * Changes restoring a deleted table) are left as they are.\n */\nexport function createTableNestingPlugin(): Plugin {\n return new Plugin({\n key: tableNestingPluginKey,\n props: {\n handlePaste: (view, event, slice) => handleTablePasteWithoutNesting(view, event, slice),\n },\n appendTransaction(transactions, _oldState, newState) {\n if (transactions.every(skip)) return null;\n const ranges = changedRanges(transactions, skip);\n if (!ranges.length) return null;\n const tr = newState.tr;\n if (!unnestTables(tr, ranges)) return null;\n return tr;\n },\n });\n}\n","import { getHTMLFromFragment, type Extensions } from \"@tiptap/core\";\nimport { Fragment, type Node as ProsemirrorNode } from \"@tiptap/pm/model\";\nimport * as _Table from \"@tiptap/extension-table\";\nimport * as _TableRow from \"@tiptap/extension-table-row\";\nimport * as _TableHeader from \"@tiptap/extension-table-header\";\nimport * as _TableCell from \"@tiptap/extension-table-cell\";\nimport { createTableNestingPlugin } from \"./nesting\";\n\nconst resolveExt = (mod: any, name: string) =>\n mod?.[name] || mod?.default?.[name] || mod?.default?.default || mod?.default || mod;\n\nconst BaseTable = resolveExt(_Table, \"Table\");\nconst BaseTableRow = resolveExt(_TableRow, \"TableRow\");\nconst BaseTableHeader = resolveExt(_TableHeader, \"TableHeader\");\nconst BaseTableCell = resolveExt(_TableCell, \"TableCell\");\n\n/** Horizontal alignment of a table cell (`align` attribute). */\nexport type TableCellAlignment = \"left\" | \"center\" | \"right\" | \"justify\";\n\nconst ALIGNMENTS = new Set<TableCellAlignment>([\"left\", \"center\", \"right\", \"justify\"]);\n\n/** Returns a valid cell alignment, or `null`. */\nexport function normalizeTableCellAlignment(value: unknown): TableCellAlignment | null {\n const v = typeof value === \"string\" ? value.trim().toLowerCase() : \"\";\n return ALIGNMENTS.has(v as TableCellAlignment) ? (v as TableCellAlignment) : null;\n}\n\n/**\n * Color values allowed as a cell background: hex, `rgb()/rgba()/hsl()/hsla()`\n * with numeric arguments, or a CSS color keyword. Anything else (e.g.\n * `url(...)`, `expression(...)`, `;`) is rejected because the value ends up in\n * a `style` attribute.\n */\nconst COLOR_REGEX =\n /^(?:#[0-9a-f]{3,8}|(?:rgb|rgba|hsl|hsla)\\(\\s*[-0-9.%\\s,/deg]+\\)|[a-z]{3,20})$/i;\n\n/** Returns a safe CSS color for a cell background, or `null`. */\nexport function normalizeTableCellColor(value: unknown): string | null {\n const v = typeof value === \"string\" ? value.trim() : \"\";\n if (!v || v.length > 64 || !COLOR_REGEX.test(v)) return null;\n if (/^(?:inherit|initial|unset|revert|transparent)$/i.test(v)) return null;\n return v;\n}\n\n/** Cell attributes added on top of TipTap's `colspan` / `rowspan` / `colwidth`. */\nconst cellAttributes = () => ({\n align: {\n default: null,\n parseHTML: (element: HTMLElement) =>\n normalizeTableCellAlignment(element.style?.textAlign || element.getAttribute(\"align\")),\n renderHTML: (attrs: Record<string, any>) => {\n const align = normalizeTableCellAlignment(attrs.align);\n return align ? { style: `text-align: ${align}` } : {};\n },\n },\n backgroundColor: {\n default: null,\n parseHTML: (element: HTMLElement) =>\n normalizeTableCellColor(\n element.getAttribute(\"data-background-color\") ||\n element.style?.backgroundColor ||\n element.getAttribute(\"bgcolor\"),\n ),\n renderHTML: (attrs: Record<string, any>) => {\n const color = normalizeTableCellColor(attrs.backgroundColor);\n return color ? { style: `background-color: ${color}`, \"data-background-color\": color } : {};\n },\n },\n});\n\n// ---------------------------------------------------------------------------\n// Markdown (tiptap-markdown)\n// ---------------------------------------------------------------------------\n\nconst children = (node: ProsemirrorNode) => {\n const list: ProsemirrorNode[] = [];\n node.forEach((child) => list.push(child));\n return list;\n};\n\nconst hasSpan = (cell: ProsemirrorNode) => (cell.attrs.colspan ?? 1) > 1 || (cell.attrs.rowspan ?? 1) > 1;\n\n/**\n * Whether a table can be written as a GFM pipe table: the first row is all\n * header cells, the other rows have none, no cell spans rows or columns, and\n * every cell holds a single paragraph.\n */\nexport function isGfmTable(node: ProsemirrorNode): boolean {\n const rows = children(node);\n if (rows.length === 0) return false;\n const width = rows[0].childCount;\n return rows.every(\n (row, r) =>\n row.childCount === width &&\n children(row).every(\n (cell) =>\n (r === 0 ? cell.type.name === \"tableHeader\" : cell.type.name === \"tableCell\") &&\n !hasSpan(cell) &&\n cell.childCount === 1 &&\n cell.firstChild!.type.name === \"paragraph\",\n ),\n );\n}\n\nconst DELIMITERS: Record<string, string> = { left: \":---\", center: \":---:\", right: \"---:\" };\n\n/**\n * tiptap-markdown serializer for tables: GFM pipe tables (with column\n * alignment from the header cells and `|` escaped) when `isGfmTable`, HTML\n * otherwise (spans, header columns, multi-paragraph cells).\n */\nfunction serializeTableMarkdown(state: any, node: ProsemirrorNode) {\n if (!isGfmTable(node)) {\n const html = getHTMLFromFragment(Fragment.from(node), node.type.schema);\n // An HTML block must start on its own line and contain no blank lines.\n state.write(html.replace(/\\n{2,}/g, \"\\n\"));\n state.closeBlock(node);\n return;\n }\n const previous = state.inTable;\n state.inTable = true;\n children(node).forEach((row, r) => {\n if (r) state.ensureNewLine();\n state.write(\"| \");\n children(row).forEach((cell, c) => {\n if (c) state.write(\" | \");\n const paragraph = cell.firstChild!;\n // Render in place (mid-line, so no block prefix is added), then escape\n // the cell's pipes and line breaks, which would end the cell or row.\n const start = state.out.length;\n if (paragraph.childCount) state.renderInline(paragraph);\n const text: string = state.out.slice(start);\n state.out = state.out.slice(0, start) + text.replace(/\\n/g, \" \").replace(/\\|/g, \"\\\\|\");\n });\n state.write(\" |\");\n if (r === 0) {\n const delimiter = children(row).map((cell) => DELIMITERS[cell.attrs.align] ?? \"---\");\n state.ensureNewLine();\n state.write(`| ${delimiter.join(\" | \")} |`);\n }\n });\n state.inTable = previous;\n state.closeBlock(node);\n}\n\n// ---------------------------------------------------------------------------\n// Extensions\n// ---------------------------------------------------------------------------\n\nexport interface RichTextTableOptions {\n /** Drag column borders to resize columns (stored as `colwidth`). Default `true`. */\n resizable: boolean;\n /** Width of the resize handle in pixels. Default 5. */\n handleWidth: number;\n /** Minimum cell width in pixels. Default 25. */\n cellMinWidth: number;\n /** Whether the last column can be resized. Default `true`. */\n lastColumnResizable: boolean;\n /** Allow selecting the whole table as a node (click its border, Esc from a cell selection). Default `true`. */\n allowTableNodeSelection: boolean;\n /** HTML attributes of the `<table>` element. */\n HTMLAttributes: Record<string, any>;\n /** HTML attributes of `<td>` elements. */\n cellHTMLAttributes: Record<string, any>;\n /** HTML attributes of `<th>` elements. */\n headerHTMLAttributes: Record<string, any>;\n /** HTML attributes of `<tr>` elements. */\n rowHTMLAttributes: Record<string, any>;\n}\n\nexport const DEFAULT_TABLE_OPTIONS: RichTextTableOptions = {\n resizable: true,\n handleWidth: 5,\n cellMinWidth: 25,\n lastColumnResizable: true,\n allowTableNodeSelection: true,\n HTMLAttributes: { class: \"pixerate-table\" },\n cellHTMLAttributes: {},\n headerHTMLAttributes: {},\n rowHTMLAttributes: {},\n};\n\n/**\n * TipTap's `Table` with the GFM-aware markdown serializer and the nesting\n * guard (`createTableNestingPlugin`): tables are never pasted, imported or\n * inserted into table cells.\n */\nexport const Table = BaseTable.extend({\n addStorage() {\n return { markdown: { serialize: serializeTableMarkdown } };\n },\n addProseMirrorPlugins() {\n return [...(this.parent?.() ?? []), createTableNestingPlugin()];\n },\n});\n\nexport const TableRow = BaseTableRow;\n\n/** TipTap's `TableCell` plus `align` and `backgroundColor` attributes. */\nexport const TableCell = BaseTableCell.extend({\n addAttributes() {\n return { ...this.parent?.(), ...cellAttributes() };\n },\n});\n\n/** TipTap's `TableHeader` plus `align` and `backgroundColor` attributes. */\nexport const TableHeader = BaseTableHeader.extend({\n addAttributes() {\n return { ...this.parent?.(), ...cellAttributes() };\n },\n});\n\n/**\n * The table extensions (`table`, `tableRow`, `tableHeader`, `tableCell`)\n * configured for rich documents: resizable columns, header rows, columns and\n * cells, `colspan` / `rowspan` from imported HTML, cell alignment and\n * background, table node selection and GFM markdown. `createRichTextPreset`\n * adds them unless `table: false`.\n */\nexport function createTableExtensions(options: Partial<RichTextTableOptions> = {}): Extensions {\n const o = { ...DEFAULT_TABLE_OPTIONS, ...options };\n return [\n Table.configure({\n resizable: o.resizable,\n handleWidth: o.handleWidth,\n cellMinWidth: o.cellMinWidth,\n lastColumnResizable: o.lastColumnResizable,\n allowTableNodeSelection: o.allowTableNodeSelection,\n HTMLAttributes: o.HTMLAttributes,\n }),\n TableRow.configure({ HTMLAttributes: o.rowHTMLAttributes }),\n TableHeader.configure({ HTMLAttributes: o.headerHTMLAttributes }),\n TableCell.configure({ HTMLAttributes: o.cellHTMLAttributes }),\n ];\n}\n","import type { Editor } from \"@tiptap/core\";\nimport type { EditorState } from \"@tiptap/pm/state\";\nimport { CellSelection, isInTable, selectedRect } from \"@tiptap/pm/tables\";\nimport { isTrackChangesEnabled } from \"../track-changes\";\nimport {\n normalizeTableCellAlignment,\n normalizeTableCellColor,\n type TableCellAlignment,\n} from \"./extension\";\n\n/** Table operations shared by the command registry, the toolbars and agent tools. */\nexport type TableAction =\n | \"insertTable\"\n | \"addRowBefore\"\n | \"addRowAfter\"\n | \"deleteRow\"\n | \"addColumnBefore\"\n | \"addColumnAfter\"\n | \"deleteColumn\"\n | \"deleteTable\"\n | \"mergeCells\"\n | \"splitCell\"\n | \"toggleHeaderRow\"\n | \"toggleHeaderColumn\"\n | \"toggleHeaderCell\"\n | \"goToNextCell\"\n | \"goToPreviousCell\"\n | \"setCellAlignment\"\n | \"setCellBackground\";\n\n/** Parameters of `insertTable`, `setCellAlignment` and `setCellBackground`. */\nexport interface TableActionParams {\n /** `insertTable`: number of rows (1–100, default 3). */\n rows?: number;\n /** `insertTable`: number of columns (1–50, default 3). */\n cols?: number;\n /** `insertTable`: make the first row a header row (default `true`). */\n withHeaderRow?: boolean;\n /** `setCellAlignment`: `left`, `center`, `right`, `justify`, or `null` to clear. */\n align?: TableCellAlignment | null;\n /** `setCellBackground`: a CSS color, or `null` to clear. */\n color?: string | null;\n}\n\nexport interface TableActionInfo {\n action: TableAction;\n label: string;\n description: string;\n keywords: readonly string[];\n}\n\n/** Every table action with its label, in toolbar order. */\nexport const TABLE_ACTIONS: readonly TableActionInfo[] = [\n { action: \"insertTable\", label: \"Insert Table\", description: \"Inserts a table (rows, cols, withHeaderRow) at the cursor.\", keywords: [\"table\", \"grid\", \"new\"] },\n { action: \"addRowBefore\", label: \"Insert Row Above\", description: \"Adds a row above the current row.\", keywords: [\"row\", \"add\", \"above\"] },\n { action: \"addRowAfter\", label: \"Insert Row Below\", description: \"Adds a row below the current row.\", keywords: [\"row\", \"add\", \"below\"] },\n { action: \"deleteRow\", label: \"Delete Row\", description: \"Deletes the selected rows.\", keywords: [\"row\", \"remove\"] },\n { action: \"addColumnBefore\", label: \"Insert Column Left\", description: \"Adds a column left of the current column.\", keywords: [\"column\", \"add\", \"left\", \"before\"] },\n { action: \"addColumnAfter\", label: \"Insert Column Right\", description: \"Adds a column right of the current column.\", keywords: [\"column\", \"add\", \"right\", \"after\"] },\n { action: \"deleteColumn\", label: \"Delete Column\", description: \"Deletes the selected columns.\", keywords: [\"column\", \"remove\"] },\n { action: \"deleteTable\", label: \"Delete Table\", description: \"Deletes the table around the cursor.\", keywords: [\"table\", \"remove\"] },\n { action: \"mergeCells\", label: \"Merge Cells\", description: \"Merges the selected cells into one.\", keywords: [\"combine\", \"join\", \"span\"] },\n { action: \"splitCell\", label: \"Split Cell\", description: \"Splits a merged cell back into single cells.\", keywords: [\"unmerge\", \"span\"] },\n { action: \"toggleHeaderRow\", label: \"Toggle Header Row\", description: \"Turns the first row into header cells, or back.\", keywords: [\"header\", \"row\", \"th\"] },\n { action: \"toggleHeaderColumn\", label: \"Toggle Header Column\", description: \"Turns the first column into header cells, or back.\", keywords: [\"header\", \"column\", \"th\"] },\n { action: \"toggleHeaderCell\", label: \"Toggle Header Cell\", description: \"Turns the selected cells into header cells, or back.\", keywords: [\"header\", \"cell\", \"th\"] },\n { action: \"goToNextCell\", label: \"Next Cell\", description: \"Moves the cursor to the next cell.\", keywords: [\"tab\", \"navigate\"] },\n { action: \"goToPreviousCell\", label: \"Previous Cell\", description: \"Moves the cursor to the previous cell.\", keywords: [\"shift tab\", \"navigate\"] },\n { action: \"setCellAlignment\", label: \"Align Cells…\", description: \"Sets the horizontal alignment (align: left | center | right | justify | null) of the selected cells.\", keywords: [\"align\", \"left\", \"center\", \"right\"] },\n { action: \"setCellBackground\", label: \"Cell Background…\", description: \"Sets the background color (color: CSS color or null) of the selected cells.\", keywords: [\"shading\", \"fill\", \"color\"] },\n];\n\n/** A button of the table toolbars (`TableToolbar` in React and Svelte). */\nexport interface TableToolbarItem {\n /** Unique id (also the button's `data-action`). */\n id: string;\n action: TableAction;\n params?: TableActionParams;\n /** Short button text. */\n label: string;\n /** Accessible name and tooltip. */\n title: string;\n /** Items of one group are separated from the next group. */\n group: string;\n /** Toggle buttons: whether the button shows as pressed. */\n active?: (state: TableState) => boolean;\n}\n\n/** The default table toolbar: rows, columns, cells, headers, alignment, delete. */\nexport const DEFAULT_TABLE_TOOLBAR: readonly TableToolbarItem[] = [\n { id: \"addRowBefore\", action: \"addRowBefore\", label: \"+ Row ↑\", title: \"Insert row above\", group: \"rows\" },\n { id: \"addRowAfter\", action: \"addRowAfter\", label: \"+ Row ↓\", title: \"Insert row below\", group: \"rows\" },\n { id: \"deleteRow\", action: \"deleteRow\", label: \"− Row\", title: \"Delete row\", group: \"rows\" },\n { id: \"addColumnBefore\", action: \"addColumnBefore\", label: \"+ Col ←\", title: \"Insert column left\", group: \"columns\" },\n { id: \"addColumnAfter\", action: \"addColumnAfter\", label: \"+ Col →\", title: \"Insert column right\", group: \"columns\" },\n { id: \"deleteColumn\", action: \"deleteColumn\", label: \"− Col\", title: \"Delete column\", group: \"columns\" },\n { id: \"mergeCells\", action: \"mergeCells\", label: \"Merge\", title: \"Merge cells\", group: \"cells\" },\n { id: \"splitCell\", action: \"splitCell\", label: \"Split\", title: \"Split cell\", group: \"cells\" },\n { id: \"toggleHeaderRow\", action: \"toggleHeaderRow\", label: \"Header row\", title: \"Toggle header row\", group: \"headers\", active: (s) => s.headerRow },\n { id: \"toggleHeaderColumn\", action: \"toggleHeaderColumn\", label: \"Header col\", title: \"Toggle header column\", group: \"headers\", active: (s) => s.headerColumn },\n { id: \"toggleHeaderCell\", action: \"toggleHeaderCell\", label: \"Header cell\", title: \"Toggle header cell\", group: \"headers\", active: (s) => s.headerCell },\n { id: \"alignLeft\", action: \"setCellAlignment\", params: { align: \"left\" }, label: \"Left\", title: \"Align cell left\", group: \"align\", active: (s) => s.cellAlignment === \"left\" },\n { id: \"alignCenter\", action: \"setCellAlignment\", params: { align: \"center\" }, label: \"Center\", title: \"Align cell center\", group: \"align\", active: (s) => s.cellAlignment === \"center\" },\n { id: \"alignRight\", action: \"setCellAlignment\", params: { align: \"right\" }, label: \"Right\", title: \"Align cell right\", group: \"align\", active: (s) => s.cellAlignment === \"right\" },\n { id: \"deleteTable\", action: \"deleteTable\", label: \"Delete table\", title: \"Delete table\", group: \"table\" },\n];\n\nexport const MAX_TABLE_ROWS = 100;\nexport const MAX_TABLE_COLUMNS = 50;\n\nconst live = (editor: Editor | null | undefined): editor is Editor => !!editor && !editor.isDestroyed;\n\n/** Whether the editor's schema has the table nodes (`createRichTextPreset({ table })`). */\nexport function isTableEnabled(editor: Editor | null | undefined): boolean {\n return live(editor) && !!editor.schema.nodes.table && !!editor.schema.nodes.tableRow;\n}\n\n/** Whether the selection (cursor, text or cell selection) is inside a table. */\nexport function isSelectionInTable(state: EditorState): boolean {\n if (!state.schema.nodes.table) return false;\n return state.selection instanceof CellSelection || isInTable(state);\n}\n\n/**\n * `shouldShow` for a table bubble menu (TipTap's `BubbleMenuPlugin`): shown\n * while an editable editor's selection is in a table, even a collapsed cursor.\n */\nexport function shouldShowTableBubbleMenu({ editor, state }: { editor: Editor; state: EditorState }): boolean {\n return editor.isEditable && isSelectionInTable(state);\n}\n\nconst isInt = (value: unknown, min: number, max: number) =>\n typeof value === \"number\" && Number.isInteger(value) && value >= min && value <= max;\n\nconst can = (editor: Editor, run: (chain: any) => any): boolean => {\n try {\n return !!run(editor.can().chain()).run();\n } catch {\n return false;\n }\n};\n\n/**\n * Whether a table action can run: `true`, or the reason it cannot (e.g.\n * \"Place the cursor in a table first.\").\n */\nexport function getTableActionState(\n editor: Editor | null | undefined,\n action: TableAction,\n params: TableActionParams = {},\n): true | string {\n if (!live(editor)) return \"The editor is not available.\";\n if (!isTableEnabled(editor)) return \"Tables are not enabled in this editor.\";\n if (!editor.isEditable) return \"The editor is read-only.\";\n const state = editor.state;\n const inTable = isSelectionInTable(state);\n\n if (action === \"insertTable\") {\n if (inTable) return \"Tables cannot be nested: move the cursor out of the table first.\";\n if (params.rows !== undefined && !isInt(params.rows, 1, MAX_TABLE_ROWS)) {\n return `Rows must be a whole number from 1 to ${MAX_TABLE_ROWS}.`;\n }\n if (params.cols !== undefined && !isInt(params.cols, 1, MAX_TABLE_COLUMNS)) {\n return `Columns must be a whole number from 1 to ${MAX_TABLE_COLUMNS}.`;\n }\n return can(editor, (c) => c.insertTable({ rows: 1, cols: 1 })) ? true : \"A table cannot be inserted here.\";\n }\n\n if (!inTable) return \"Place the cursor in a table first.\";\n\n switch (action) {\n case \"mergeCells\":\n case \"splitCell\": {\n if (isTrackChangesEnabled(editor)) {\n return `${action === \"mergeCells\" ? \"Merging\" : \"Splitting\"} cells cannot be tracked: turn off Track Changes first.`;\n }\n if (action === \"mergeCells\") {\n return can(editor, (c) => c.mergeCells()) ? true : \"Select two or more adjacent cells to merge.\";\n }\n return can(editor, (c) => c.splitCell()) ? true : \"Only a merged cell can be split.\";\n }\n case \"deleteRow\":\n case \"deleteColumn\": {\n // prosemirror-tables only refuses to delete every row/column when dispatching.\n const rect = selectedRect(state);\n const all = action === \"deleteRow\"\n ? rect.top === 0 && rect.bottom === rect.map.height\n : rect.left === 0 && rect.right === rect.map.width;\n const what = action === \"deleteRow\" ? \"rows\" : \"columns\";\n if (all || !can(editor, (c) => c[action]())) return `These are all the ${what}: delete the table instead.`;\n return true;\n }\n case \"goToNextCell\":\n return can(editor, (c) => c.goToNextCell()) ? true : \"This is the last cell.\";\n case \"goToPreviousCell\":\n return can(editor, (c) => c.goToPreviousCell()) ? true : \"This is the first cell.\";\n case \"setCellAlignment\":\n if (params.align !== undefined && params.align !== null && !normalizeTableCellAlignment(params.align)) {\n return 'Alignment must be \"left\", \"center\", \"right\", \"justify\" or null.';\n }\n if (!editor.schema.nodes.tableCell?.spec.attrs?.align) return \"Cell alignment is not supported by this schema.\";\n return true;\n case \"setCellBackground\":\n if (params.color !== undefined && params.color !== null && !normalizeTableCellColor(params.color)) {\n return \"Color must be a CSS color such as #fde68a, rgb(…) or a color name, or null.\";\n }\n if (!editor.schema.nodes.tableCell?.spec.attrs?.backgroundColor) return \"Cell backgrounds are not supported by this schema.\";\n return true;\n default:\n return can(editor, (c) => c[action]()) ? true : \"This table action is not available here.\";\n }\n}\n\nexport interface RunTableActionOptions {\n /** Focus the editor (toolbars). Default `false`. */\n focus?: boolean;\n}\n\n/**\n * Runs a table action. Returns `false` (and changes nothing) when it cannot\n * run; check `getTableActionState` for the reason.\n */\nexport function runTableAction(\n editor: Editor | null | undefined,\n action: TableAction,\n params: TableActionParams = {},\n options: RunTableActionOptions = {},\n): boolean {\n if (getTableActionState(editor, action, params) !== true) return false;\n const ed = editor as Editor;\n let chain: any = ed.chain();\n if (options.focus) chain = chain.focus();\n switch (action) {\n case \"insertTable\":\n chain = chain.insertTable({\n rows: params.rows ?? 3,\n cols: params.cols ?? 3,\n withHeaderRow: params.withHeaderRow ?? true,\n });\n break;\n case \"setCellAlignment\":\n chain = chain.setCellAttribute(\"align\", normalizeTableCellAlignment(params.align));\n break;\n case \"setCellBackground\":\n chain = chain.setCellAttribute(\"backgroundColor\", normalizeTableCellColor(params.color));\n break;\n default:\n chain = chain[action]();\n }\n return !!chain.run();\n}\n\nexport interface TableActionStatus {\n enabled: boolean;\n /** Why the action cannot run (only when `enabled` is false). */\n reason?: string;\n}\n\n/** The table at the selection and what can be done there. */\nexport interface TableState {\n /** The schema has tables. */\n enabled: boolean;\n /** The selection is inside a table. */\n inTable: boolean;\n /** Cells are selected (a `CellSelection`). */\n cellSelection: boolean;\n /** Size of the table (0 outside a table). */\n rows: number;\n columns: number;\n /** Row and column (0-based) of the selection's first cell, or -1. */\n row: number;\n column: number;\n /** The first row / first column are all header cells. */\n headerRow: boolean;\n headerColumn: boolean;\n /** The cell at the selection is a header cell. */\n headerCell: boolean;\n /** Alignment / background of the cell at the selection. */\n cellAlignment: TableCellAlignment | null;\n cellBackground: string | null;\n /** Enablement of every action (with the default params). */\n actions: Record<TableAction, TableActionStatus>;\n}\n\nconst NO_ACTIONS = Object.fromEntries(\n TABLE_ACTIONS.map(({ action }) => [action, { enabled: false, reason: \"The editor is not available.\" }]),\n) as Record<TableAction, TableActionStatus>;\n\nexport const EMPTY_TABLE_STATE: TableState = Object.freeze({\n enabled: false,\n inTable: false,\n cellSelection: false,\n rows: 0,\n columns: 0,\n row: -1,\n column: -1,\n headerRow: false,\n headerColumn: false,\n headerCell: false,\n cellAlignment: null,\n cellBackground: null,\n actions: NO_ACTIONS,\n}) as TableState;\n\n/** Computes the table state at the editor's selection. */\nexport function getTableState(editor: Editor | null | undefined): TableState {\n if (!live(editor)) return EMPTY_TABLE_STATE;\n const actions = Object.fromEntries(\n TABLE_ACTIONS.map(({ action }) => {\n const result = getTableActionState(editor, action);\n return [action, result === true ? { enabled: true } : { enabled: false, reason: result }];\n }),\n ) as Record<TableAction, TableActionStatus>;\n const state = editor.state;\n const base: TableState = { ...EMPTY_TABLE_STATE, enabled: isTableEnabled(editor), actions };\n if (!base.enabled || !isSelectionInTable(state)) return base;\n try {\n const rect = selectedRect(state);\n const { map, table } = rect;\n const cellAt = (row: number, col: number) => table.nodeAt(map.map[row * map.width + col]);\n const allHeaders = (positions: number[]) =>\n positions.length > 0 && positions.every((pos) => table.nodeAt(pos)?.type.name === \"tableHeader\");\n const firstRow = map.cellsInRect({ left: 0, right: map.width, top: 0, bottom: 1 });\n const firstColumn = map.cellsInRect({ left: 0, right: 1, top: 0, bottom: map.height });\n const cell = cellAt(rect.top, rect.left);\n return {\n ...base,\n inTable: true,\n cellSelection: state.selection instanceof CellSelection,\n rows: map.height,\n columns: map.width,\n row: rect.top,\n column: rect.left,\n headerRow: allHeaders(firstRow),\n headerColumn: allHeaders(firstColumn),\n headerCell: cell?.type.name === \"tableHeader\",\n cellAlignment: normalizeTableCellAlignment(cell?.attrs.align),\n cellBackground: normalizeTableCellColor(cell?.attrs.backgroundColor),\n };\n } catch {\n return { ...base, inTable: true };\n }\n}\n\nconst stateKey = (state: TableState) => JSON.stringify(state);\n\nexport interface TableStore {\n getSnapshot(): TableState;\n subscribe(listener: () => void): () => void;\n destroy(): void;\n}\n\n/**\n * An external store of `getTableState(editor)` for UI bindings (React's\n * `useSyncExternalStore`, Svelte runes). The snapshot object only changes\n * when the state does, and the store listens to the editor only while it\n * has subscribers.\n */\nexport function createTableStore(editor: Editor | null | undefined): TableStore {\n const listeners = new Set<() => void>();\n let snapshot = getTableState(editor);\n let key = stateKey(snapshot);\n\n const update = () => {\n const next = getTableState(editor);\n const nextKey = stateKey(next);\n if (nextKey === key) return;\n snapshot = next;\n key = nextKey;\n listeners.forEach((listener) => listener());\n };\n const detach = () => {\n editor?.off(\"transaction\", update);\n editor?.off(\"update\", update);\n editor?.off(\"focus\", update);\n editor?.off(\"destroy\", update);\n };\n\n return {\n getSnapshot: () => {\n if (!listeners.size) {\n const next = getTableState(editor);\n const nextKey = stateKey(next);\n if (nextKey !== key) {\n snapshot = next;\n key = nextKey;\n }\n }\n return snapshot;\n },\n subscribe(listener) {\n if (!listeners.size && editor) {\n update();\n editor.on(\"transaction\", update);\n // `setEditable` emits `update` without a transaction.\n editor.on(\"update\", update);\n editor.on(\"focus\", update);\n editor.on(\"destroy\", update);\n }\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n if (!listeners.size) detach();\n };\n },\n destroy() {\n detach();\n listeners.clear();\n },\n };\n}\n"]}