@milkdown/preset-gfm 7.6.3 → 7.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.es.js CHANGED
@@ -1,759 +1,893 @@
1
- import { expectDomTypeError as K } from "@milkdown/exception";
2
- import { paragraphSchema as De, listItemSchema as Ee } from "@milkdown/preset-commonmark";
3
- import { InputRule as ne } from "@milkdown/prose/inputrules";
4
- import { $markAttr as Oe, $markSchema as He, $inputRule as F, $useKeymap as le, $command as g, $nodeSchema as C, $prose as v, $remark as Be } from "@milkdown/utils";
5
- import { tableNodes as Le, TableMap as h, CellSelection as k, goToNextCell as re, isInTable as G, deleteTable as Ke, deleteColumn as Fe, deleteRow as Ge, selectedRect as ae, addColumnBefore as We, addColumnAfter as ze, setCellAttr as je, columnResizing as Ve, tableEditing as Ue } from "@milkdown/prose/tables";
6
- import { commandsCtx as A } from "@milkdown/core";
7
- import { toggleMark as Xe } from "@milkdown/prose/commands";
8
- import { markRule as qe, findParentNodeClosestToPos as se, cloneTr as _, findParentNodeType as Je } from "@milkdown/prose";
9
- import { Selection as ce, TextSelection as Qe, Plugin as Ye, PluginKey as Ze } from "@milkdown/prose/state";
10
- import { imeSpan as et } from "prosemirror-safari-ime-span";
11
- import tt from "remark-gfm";
12
- function i(e, t) {
13
- return Object.assign(e, {
1
+ import { expectDomTypeError } from "@milkdown/exception";
2
+ import { paragraphSchema, listItemSchema } from "@milkdown/preset-commonmark";
3
+ import { InputRule } from "@milkdown/prose/inputrules";
4
+ import { $markAttr, $markSchema, $inputRule, $useKeymap, $command, $nodeSchema, $prose, $remark } from "@milkdown/utils";
5
+ import { tableNodes, TableMap, CellSelection, goToNextCell, isInTable, deleteTable, deleteColumn, deleteRow, selectedRect, addColumnBefore, addColumnAfter, setCellAttr, columnResizing, tableEditing } from "@milkdown/prose/tables";
6
+ import { commandsCtx } from "@milkdown/core";
7
+ import { toggleMark } from "@milkdown/prose/commands";
8
+ import { markRule, findParentNodeClosestToPos, cloneTr, findParentNodeType } from "@milkdown/prose";
9
+ import { Selection, TextSelection, Plugin, PluginKey } from "@milkdown/prose/state";
10
+ import { imeSpan } from "prosemirror-safari-ime-span";
11
+ import remarkGFM from "remark-gfm";
12
+ function withMeta(plugin, meta) {
13
+ Object.assign(plugin, {
14
14
  meta: {
15
15
  package: "@milkdown/preset-gfm",
16
- ...t
16
+ ...meta
17
17
  }
18
- }), e;
18
+ });
19
+ return plugin;
19
20
  }
20
- const W = Oe("strike_through");
21
- i(W, {
21
+ const strikethroughAttr = $markAttr("strike_through");
22
+ withMeta(strikethroughAttr, {
22
23
  displayName: "Attr<strikethrough>",
23
24
  group: "Strikethrough"
24
25
  });
25
- const T = He("strike_through", (e) => ({
26
+ const strikethroughSchema = $markSchema("strike_through", (ctx) => ({
26
27
  parseDOM: [
27
28
  { tag: "del" },
28
29
  {
29
30
  style: "text-decoration",
30
- getAttrs: (t) => t === "line-through"
31
+ getAttrs: (value) => value === "line-through"
31
32
  }
32
33
  ],
33
- toDOM: (t) => ["del", e.get(W.key)(t)],
34
+ toDOM: (mark) => ["del", ctx.get(strikethroughAttr.key)(mark)],
34
35
  parseMarkdown: {
35
- match: (t) => t.type === "delete",
36
- runner: (t, n, o) => {
37
- t.openMark(o), t.next(n.children), t.closeMark(o);
36
+ match: (node) => node.type === "delete",
37
+ runner: (state, node, markType) => {
38
+ state.openMark(markType);
39
+ state.next(node.children);
40
+ state.closeMark(markType);
38
41
  }
39
42
  },
40
43
  toMarkdown: {
41
- match: (t) => t.type.name === "strike_through",
42
- runner: (t, n) => {
43
- t.withMark(n, "delete");
44
+ match: (mark) => mark.type.name === "strike_through",
45
+ runner: (state, mark) => {
46
+ state.withMark(mark, "delete");
44
47
  }
45
48
  }
46
49
  }));
47
- i(T.mark, {
50
+ withMeta(strikethroughSchema.mark, {
48
51
  displayName: "MarkSchema<strikethrough>",
49
52
  group: "Strikethrough"
50
53
  });
51
- i(T.ctx, {
54
+ withMeta(strikethroughSchema.ctx, {
52
55
  displayName: "MarkSchemaCtx<strikethrough>",
53
56
  group: "Strikethrough"
54
57
  });
55
- const z = g(
58
+ const toggleStrikethroughCommand = $command(
56
59
  "ToggleStrikeThrough",
57
- (e) => () => Xe(T.type(e))
60
+ (ctx) => () => {
61
+ return toggleMark(strikethroughSchema.type(ctx));
62
+ }
58
63
  );
59
- i(z, {
64
+ withMeta(toggleStrikethroughCommand, {
60
65
  displayName: "Command<ToggleStrikethrough>",
61
66
  group: "Strikethrough"
62
67
  });
63
- const ie = F((e) => qe(/~([^~]+)~$/, T.type(e)));
64
- i(ie, {
68
+ const strikethroughInputRule = $inputRule((ctx) => {
69
+ return markRule(/~([^~]+)~$/, strikethroughSchema.type(ctx));
70
+ });
71
+ withMeta(strikethroughInputRule, {
65
72
  displayName: "InputRule<strikethrough>",
66
73
  group: "Strikethrough"
67
74
  });
68
- const j = le("strikeThroughKeymap", {
75
+ const strikethroughKeymap = $useKeymap("strikeThroughKeymap", {
69
76
  ToggleStrikethrough: {
70
77
  shortcuts: "Mod-Alt-x",
71
- command: (e) => {
72
- const t = e.get(A);
73
- return () => t.call(z.key);
78
+ command: (ctx) => {
79
+ const commands2 = ctx.get(commandsCtx);
80
+ return () => commands2.call(toggleStrikethroughCommand.key);
74
81
  }
75
82
  }
76
83
  });
77
- i(j.ctx, {
84
+ withMeta(strikethroughKeymap.ctx, {
78
85
  displayName: "KeymapCtx<strikethrough>",
79
86
  group: "Strikethrough"
80
87
  });
81
- i(j.shortcuts, {
88
+ withMeta(strikethroughKeymap.shortcuts, {
82
89
  displayName: "Keymap<strikethrough>",
83
90
  group: "Strikethrough"
84
91
  });
85
- const S = Le({
92
+ const originalSchema = tableNodes({
86
93
  tableGroup: "block",
87
94
  cellContent: "paragraph",
88
95
  cellAttributes: {
89
96
  alignment: {
90
97
  default: "left",
91
- getFromDOM: (e) => e.style.textAlign || "left",
92
- setDOMAttr: (e, t) => {
93
- t.style = `text-align: ${e || "left"}`;
98
+ getFromDOM: (dom) => dom.style.textAlign || "left",
99
+ setDOMAttr: (value, attrs) => {
100
+ attrs.style = `text-align: ${value || "left"}`;
94
101
  }
95
102
  }
96
103
  }
97
- }), N = C("table", () => ({
98
- ...S.table,
104
+ });
105
+ const tableSchema = $nodeSchema("table", () => ({
106
+ ...originalSchema.table,
99
107
  content: "table_header_row table_row+",
100
- disableDropCursor: !0,
108
+ disableDropCursor: true,
101
109
  parseMarkdown: {
102
- match: (e) => e.type === "table",
103
- runner: (e, t, n) => {
104
- const o = t.align, l = t.children.map((r, s) => ({
105
- ...r,
106
- align: o,
107
- isHeader: s === 0
110
+ match: (node) => node.type === "table",
111
+ runner: (state, node, type) => {
112
+ const align = node.align;
113
+ const children = node.children.map((x, i) => ({
114
+ ...x,
115
+ align,
116
+ isHeader: i === 0
108
117
  }));
109
- e.openNode(n), e.next(l), e.closeNode();
118
+ state.openNode(type);
119
+ state.next(children);
120
+ state.closeNode();
110
121
  }
111
122
  },
112
123
  toMarkdown: {
113
- match: (e) => e.type.name === "table",
114
- runner: (e, t) => {
115
- var l;
116
- const n = (l = t.content.firstChild) == null ? void 0 : l.content;
117
- if (!n) return;
118
- const o = [];
119
- n.forEach((r) => {
120
- o.push(r.attrs.alignment);
121
- }), e.openNode("table", void 0, { align: o }), e.next(t.content), e.closeNode();
124
+ match: (node) => node.type.name === "table",
125
+ runner: (state, node) => {
126
+ var _a;
127
+ const firstLine = (_a = node.content.firstChild) == null ? void 0 : _a.content;
128
+ if (!firstLine) return;
129
+ const align = [];
130
+ firstLine.forEach((cell) => {
131
+ align.push(cell.attrs.alignment);
132
+ });
133
+ state.openNode("table", void 0, { align });
134
+ state.next(node.content);
135
+ state.closeNode();
122
136
  }
123
137
  }
124
138
  }));
125
- i(N.node, {
139
+ withMeta(tableSchema.node, {
126
140
  displayName: "NodeSchema<table>",
127
141
  group: "Table"
128
142
  });
129
- i(N.ctx, {
143
+ withMeta(tableSchema.ctx, {
130
144
  displayName: "NodeSchemaCtx<table>",
131
145
  group: "Table"
132
146
  });
133
- const $ = C("table_header_row", () => ({
134
- ...S.table_row,
135
- disableDropCursor: !0,
147
+ const tableHeaderRowSchema = $nodeSchema("table_header_row", () => ({
148
+ ...originalSchema.table_row,
149
+ disableDropCursor: true,
136
150
  content: "(table_header)*",
137
151
  parseDOM: [{ tag: "tr[data-is-header]" }],
138
152
  toDOM() {
139
- return ["tr", { "data-is-header": !0 }, 0];
153
+ return ["tr", { "data-is-header": true }, 0];
140
154
  },
141
155
  parseMarkdown: {
142
- match: (e) => !!(e.type === "tableRow" && e.isHeader),
143
- runner: (e, t, n) => {
144
- const o = t.align, l = t.children.map((r, s) => ({
145
- ...r,
146
- align: o[s],
147
- isHeader: t.isHeader
156
+ match: (node) => Boolean(node.type === "tableRow" && node.isHeader),
157
+ runner: (state, node, type) => {
158
+ const align = node.align;
159
+ const children = node.children.map((x, i) => ({
160
+ ...x,
161
+ align: align[i],
162
+ isHeader: node.isHeader
148
163
  }));
149
- e.openNode(n), e.next(l), e.closeNode();
164
+ state.openNode(type);
165
+ state.next(children);
166
+ state.closeNode();
150
167
  }
151
168
  },
152
169
  toMarkdown: {
153
- match: (e) => e.type.name === "table_header_row",
154
- runner: (e, t) => {
155
- e.openNode("tableRow", void 0, { isHeader: !0 }), e.next(t.content), e.closeNode();
170
+ match: (node) => node.type.name === "table_header_row",
171
+ runner: (state, node) => {
172
+ state.openNode("tableRow", void 0, { isHeader: true });
173
+ state.next(node.content);
174
+ state.closeNode();
156
175
  }
157
176
  }
158
177
  }));
159
- i($.node, {
178
+ withMeta(tableHeaderRowSchema.node, {
160
179
  displayName: "NodeSchema<tableHeaderRow>",
161
180
  group: "Table"
162
181
  });
163
- i($.ctx, {
182
+ withMeta(tableHeaderRowSchema.ctx, {
164
183
  displayName: "NodeSchemaCtx<tableHeaderRow>",
165
184
  group: "Table"
166
185
  });
167
- const R = C("table_row", () => ({
168
- ...S.table_row,
169
- disableDropCursor: !0,
186
+ const tableRowSchema = $nodeSchema("table_row", () => ({
187
+ ...originalSchema.table_row,
188
+ disableDropCursor: true,
170
189
  content: "(table_cell)*",
171
190
  parseMarkdown: {
172
- match: (e) => e.type === "tableRow",
173
- runner: (e, t, n) => {
174
- const o = t.align, l = t.children.map((r, s) => ({
175
- ...r,
176
- align: o[s]
191
+ match: (node) => node.type === "tableRow",
192
+ runner: (state, node, type) => {
193
+ const align = node.align;
194
+ const children = node.children.map((x, i) => ({
195
+ ...x,
196
+ align: align[i]
177
197
  }));
178
- e.openNode(n), e.next(l), e.closeNode();
198
+ state.openNode(type);
199
+ state.next(children);
200
+ state.closeNode();
179
201
  }
180
202
  },
181
203
  toMarkdown: {
182
- match: (e) => e.type.name === "table_row",
183
- runner: (e, t) => {
184
- e.openNode("tableRow"), e.next(t.content), e.closeNode();
204
+ match: (node) => node.type.name === "table_row",
205
+ runner: (state, node) => {
206
+ state.openNode("tableRow");
207
+ state.next(node.content);
208
+ state.closeNode();
185
209
  }
186
210
  }
187
211
  }));
188
- i(R.node, {
212
+ withMeta(tableRowSchema.node, {
189
213
  displayName: "NodeSchema<tableRow>",
190
214
  group: "Table"
191
215
  });
192
- i(R.ctx, {
216
+ withMeta(tableRowSchema.ctx, {
193
217
  displayName: "NodeSchemaCtx<tableRow>",
194
218
  group: "Table"
195
219
  });
196
- const x = C("table_cell", () => ({
197
- ...S.table_cell,
198
- disableDropCursor: !0,
220
+ const tableCellSchema = $nodeSchema("table_cell", () => ({
221
+ ...originalSchema.table_cell,
222
+ disableDropCursor: true,
199
223
  parseMarkdown: {
200
- match: (e) => e.type === "tableCell" && !e.isHeader,
201
- runner: (e, t, n) => {
202
- const o = t.align;
203
- e.openNode(n, { alignment: o }).openNode(e.schema.nodes.paragraph).next(t.children).closeNode().closeNode();
224
+ match: (node) => node.type === "tableCell" && !node.isHeader,
225
+ runner: (state, node, type) => {
226
+ const align = node.align;
227
+ state.openNode(type, { alignment: align }).openNode(state.schema.nodes.paragraph).next(node.children).closeNode().closeNode();
204
228
  }
205
229
  },
206
230
  toMarkdown: {
207
- match: (e) => e.type.name === "table_cell",
208
- runner: (e, t) => {
209
- e.openNode("tableCell").next(t.content).closeNode();
231
+ match: (node) => node.type.name === "table_cell",
232
+ runner: (state, node) => {
233
+ state.openNode("tableCell").next(node.content).closeNode();
210
234
  }
211
235
  }
212
236
  }));
213
- i(x.node, {
237
+ withMeta(tableCellSchema.node, {
214
238
  displayName: "NodeSchema<tableCell>",
215
239
  group: "Table"
216
240
  });
217
- i(x.ctx, {
241
+ withMeta(tableCellSchema.ctx, {
218
242
  displayName: "NodeSchemaCtx<tableCell>",
219
243
  group: "Table"
220
244
  });
221
- const I = C("table_header", () => ({
222
- ...S.table_header,
223
- disableDropCursor: !0,
245
+ const tableHeaderSchema = $nodeSchema("table_header", () => ({
246
+ ...originalSchema.table_header,
247
+ disableDropCursor: true,
224
248
  parseMarkdown: {
225
- match: (e) => e.type === "tableCell" && !!e.isHeader,
226
- runner: (e, t, n) => {
227
- const o = t.align;
228
- e.openNode(n, { alignment: o }), e.openNode(e.schema.nodes.paragraph), e.next(t.children), e.closeNode(), e.closeNode();
249
+ match: (node) => node.type === "tableCell" && !!node.isHeader,
250
+ runner: (state, node, type) => {
251
+ const align = node.align;
252
+ state.openNode(type, { alignment: align });
253
+ state.openNode(state.schema.nodes.paragraph);
254
+ state.next(node.children);
255
+ state.closeNode();
256
+ state.closeNode();
229
257
  }
230
258
  },
231
259
  toMarkdown: {
232
- match: (e) => e.type.name === "table_header",
233
- runner: (e, t) => {
234
- e.openNode("tableCell"), e.next(t.content), e.closeNode();
260
+ match: (node) => node.type.name === "table_header",
261
+ runner: (state, node) => {
262
+ state.openNode("tableCell");
263
+ state.next(node.content);
264
+ state.closeNode();
235
265
  }
236
266
  }
237
267
  }));
238
- i(I.node, {
268
+ withMeta(tableHeaderSchema.node, {
239
269
  displayName: "NodeSchema<tableHeader>",
240
270
  group: "Table"
241
271
  });
242
- i(I.ctx, {
272
+ withMeta(tableHeaderSchema.ctx, {
243
273
  displayName: "NodeSchemaCtx<tableHeader>",
244
274
  group: "Table"
245
275
  });
246
- function de(e, t = 3, n = 3) {
247
- const o = Array(n).fill(0).map(() => x.type(e).createAndFill()), l = Array(n).fill(0).map(() => I.type(e).createAndFill()), r = Array(t).fill(0).map(
248
- (s, c) => c === 0 ? $.type(e).create(null, l) : R.type(e).create(null, o)
276
+ function createTable(ctx, rowsCount = 3, colsCount = 3) {
277
+ const cells = Array(colsCount).fill(0).map(() => tableCellSchema.type(ctx).createAndFill());
278
+ const headerCells = Array(colsCount).fill(0).map(() => tableHeaderSchema.type(ctx).createAndFill());
279
+ const rows = Array(rowsCount).fill(0).map(
280
+ (_, i) => i === 0 ? tableHeaderRowSchema.type(ctx).create(null, headerCells) : tableRowSchema.type(ctx).create(null, cells)
249
281
  );
250
- return N.type(e).create(null, r);
282
+ return tableSchema.type(ctx).create(null, rows);
251
283
  }
252
- function M(e) {
253
- return se(
254
- (t) => t.type.spec.tableRole === "table"
255
- )(e);
284
+ function findTable($pos) {
285
+ return findParentNodeClosestToPos(
286
+ (node) => node.type.spec.tableRole === "table"
287
+ )($pos);
256
288
  }
257
- function y(e, t) {
258
- const n = M(t.$from);
259
- if (!n) return;
260
- const o = h.get(n.node);
261
- if (!(e < 0 || e >= o.width))
262
- return o.cellsInRect({
263
- left: e,
264
- right: e + 1,
265
- top: 0,
266
- bottom: o.height
267
- }).map((l) => {
268
- const r = n.node.nodeAt(l);
269
- if (!r) return;
270
- const s = l + n.start;
271
- return {
272
- pos: s,
273
- start: s + 1,
274
- node: r
275
- };
276
- }).filter((l) => l != null);
289
+ function getCellsInCol(columnIndex, selection) {
290
+ const table = findTable(selection.$from);
291
+ if (!table) return void 0;
292
+ const map = TableMap.get(table.node);
293
+ if (columnIndex < 0 || columnIndex >= map.width) return void 0;
294
+ return map.cellsInRect({
295
+ left: columnIndex,
296
+ right: columnIndex + 1,
297
+ top: 0,
298
+ bottom: map.height
299
+ }).map((pos) => {
300
+ const node = table.node.nodeAt(pos);
301
+ if (!node) return void 0;
302
+ const start = pos + table.start;
303
+ return {
304
+ pos: start,
305
+ start: start + 1,
306
+ node
307
+ };
308
+ }).filter((x) => x != null);
277
309
  }
278
- function w(e, t) {
279
- const n = M(t.$from);
280
- if (!n) return;
281
- const o = h.get(n.node);
282
- if (!(e < 0 || e >= o.height))
283
- return o.cellsInRect({
284
- left: 0,
285
- right: o.width,
286
- top: e,
287
- bottom: e + 1
288
- }).map((l) => {
289
- const r = n.node.nodeAt(l);
290
- if (!r) return;
291
- const s = l + n.start;
292
- return {
293
- pos: s,
294
- start: s + 1,
295
- node: r
296
- };
297
- }).filter((l) => l != null);
310
+ function getCellsInRow(rowIndex, selection) {
311
+ const table = findTable(selection.$from);
312
+ if (!table) return void 0;
313
+ const map = TableMap.get(table.node);
314
+ if (rowIndex < 0 || rowIndex >= map.height) return void 0;
315
+ return map.cellsInRect({
316
+ left: 0,
317
+ right: map.width,
318
+ top: rowIndex,
319
+ bottom: rowIndex + 1
320
+ }).map((pos) => {
321
+ const node = table.node.nodeAt(pos);
322
+ if (!node) return void 0;
323
+ const start = pos + table.start;
324
+ return {
325
+ pos: start,
326
+ start: start + 1,
327
+ node
328
+ };
329
+ }).filter((x) => x != null);
298
330
  }
299
- function ot(e) {
300
- const t = M(e.$from);
301
- if (!t) return;
302
- const n = h.get(t.node);
303
- return n.cellsInRect({
331
+ function getAllCellsInTable(selection) {
332
+ const table = findTable(selection.$from);
333
+ if (!table) return;
334
+ const map = TableMap.get(table.node);
335
+ const cells = map.cellsInRect({
304
336
  left: 0,
305
- right: n.width,
337
+ right: map.width,
306
338
  top: 0,
307
- bottom: n.height
308
- }).map((l) => {
309
- const r = t.node.nodeAt(l), s = l + t.start;
310
- return { pos: s, start: s + 1, node: r };
339
+ bottom: map.height
340
+ });
341
+ return cells.map((nodePos) => {
342
+ const node = table.node.nodeAt(nodePos);
343
+ const pos = nodePos + table.start;
344
+ return { pos, start: pos + 1, node };
311
345
  });
312
346
  }
313
- function nt(e) {
314
- const t = ot(e.selection);
315
- if (t && t[0]) {
316
- const n = e.doc.resolve(t[0].pos), o = t[t.length - 1];
317
- if (o) {
318
- const l = e.doc.resolve(o.pos);
319
- return _(e.setSelection(new k(l, n)));
347
+ function selectTable(tr) {
348
+ const cells = getAllCellsInTable(tr.selection);
349
+ if (cells && cells[0]) {
350
+ const $firstCell = tr.doc.resolve(cells[0].pos);
351
+ const last = cells[cells.length - 1];
352
+ if (last) {
353
+ const $lastCell = tr.doc.resolve(last.pos);
354
+ return cloneTr(tr.setSelection(new CellSelection($lastCell, $firstCell)));
320
355
  }
321
356
  }
322
- return e;
357
+ return tr;
323
358
  }
324
- function me(e, t, { map: n, tableStart: o, table: l }, r) {
325
- const s = Array(r).fill(0).reduce((d, p, a) => d + l.child(a).nodeSize, o), c = Array(n.width).fill(0).map((d, p) => {
326
- const a = l.nodeAt(n.map[p]);
327
- return x.type(e).createAndFill({ alignment: a == null ? void 0 : a.attrs.alignment });
359
+ function addRowWithAlignment(ctx, tr, { map, tableStart, table }, row) {
360
+ const rowPos = Array(row).fill(0).reduce((acc, _, i) => {
361
+ return acc + table.child(i).nodeSize;
362
+ }, tableStart);
363
+ const cells = Array(map.width).fill(0).map((_, col) => {
364
+ const headerCol = table.nodeAt(map.map[col]);
365
+ return tableCellSchema.type(ctx).createAndFill({ alignment: headerCol == null ? void 0 : headerCol.attrs.alignment });
328
366
  });
329
- return t.insert(s, R.type(e).create(null, c)), t;
367
+ tr.insert(rowPos, tableRowSchema.type(ctx).create(null, cells));
368
+ return tr;
330
369
  }
331
- function ue(e) {
332
- return (t, n) => (o) => {
333
- n = n ?? o.selection.from;
334
- const l = o.doc.resolve(n), r = se(
335
- (d) => d.type.name === "table"
336
- )(l), s = r ? {
337
- node: r.node,
338
- from: r.start
339
- } : void 0, c = e === "row";
340
- if (s) {
341
- const d = h.get(s.node);
342
- if (t >= 0 && t < (c ? d.height : d.width)) {
343
- const p = d.positionAt(
344
- c ? t : d.height - 1,
345
- c ? d.width - 1 : t,
346
- s.node
347
- ), a = o.doc.resolve(s.from + p), m = c ? k.rowSelection : k.colSelection, u = d.positionAt(
348
- c ? t : 0,
349
- c ? 0 : t,
350
- s.node
351
- ), f = o.doc.resolve(s.from + u);
352
- return _(
353
- o.setSelection(
354
- m(a, f)
370
+ function selectLine(type) {
371
+ return (index, pos) => (tr) => {
372
+ pos = pos ?? tr.selection.from;
373
+ const $pos = tr.doc.resolve(pos);
374
+ const $node = findParentNodeClosestToPos(
375
+ (node) => node.type.name === "table"
376
+ )($pos);
377
+ const table = $node ? {
378
+ node: $node.node,
379
+ from: $node.start
380
+ } : void 0;
381
+ const isRowSelection = type === "row";
382
+ if (table) {
383
+ const map = TableMap.get(table.node);
384
+ if (index >= 0 && index < (isRowSelection ? map.height : map.width)) {
385
+ const lastCell = map.positionAt(
386
+ isRowSelection ? index : map.height - 1,
387
+ isRowSelection ? map.width - 1 : index,
388
+ table.node
389
+ );
390
+ const $lastCell = tr.doc.resolve(table.from + lastCell);
391
+ const createCellSelection = isRowSelection ? CellSelection.rowSelection : CellSelection.colSelection;
392
+ const firstCell = map.positionAt(
393
+ isRowSelection ? index : 0,
394
+ isRowSelection ? 0 : index,
395
+ table.node
396
+ );
397
+ const $firstCell = tr.doc.resolve(table.from + firstCell);
398
+ return cloneTr(
399
+ tr.setSelection(
400
+ createCellSelection($lastCell, $firstCell)
355
401
  )
356
402
  );
357
403
  }
358
404
  }
359
- return o;
405
+ return tr;
360
406
  };
361
407
  }
362
- const lt = ue("row"), rt = ue("col");
363
- function Z(e) {
364
- return e[0].map((t, n) => e.map((o) => o[n]));
408
+ const selectRow = selectLine("row");
409
+ const selectCol = selectLine("col");
410
+ function transpose(array) {
411
+ return array[0].map((_, i) => {
412
+ return array.map((column) => column[i]);
413
+ });
365
414
  }
366
- function pe(e, t) {
367
- const n = [], o = h.get(e);
368
- for (let r = 0; r < o.height; r++) {
369
- const s = e.child(r), c = [];
370
- for (let d = 0; d < o.width; d++) {
371
- if (!t[r][d]) continue;
372
- const p = o.map[r * o.width + d], a = t[r][d], u = e.nodeAt(p).type.createChecked(
373
- Object.assign({}, a.attrs),
374
- a.content,
375
- a.marks
415
+ function convertArrayOfRowsToTableNode(tableNode, arrayOfNodes) {
416
+ const rowsPM = [];
417
+ const map = TableMap.get(tableNode);
418
+ for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
419
+ const row = tableNode.child(rowIndex);
420
+ const rowCells = [];
421
+ for (let colIndex = 0; colIndex < map.width; colIndex++) {
422
+ if (!arrayOfNodes[rowIndex][colIndex]) continue;
423
+ const cellPos = map.map[rowIndex * map.width + colIndex];
424
+ const cell = arrayOfNodes[rowIndex][colIndex];
425
+ const oldCell = tableNode.nodeAt(cellPos);
426
+ const newCell = oldCell.type.createChecked(
427
+ Object.assign({}, cell.attrs),
428
+ cell.content,
429
+ cell.marks
376
430
  );
377
- c.push(u);
431
+ rowCells.push(newCell);
378
432
  }
379
- n.push(s.type.createChecked(s.attrs, c, s.marks));
433
+ rowsPM.push(row.type.createChecked(row.attrs, rowCells, row.marks));
380
434
  }
381
- return e.type.createChecked(
382
- e.attrs,
383
- n,
384
- e.marks
435
+ const newTable = tableNode.type.createChecked(
436
+ tableNode.attrs,
437
+ rowsPM,
438
+ tableNode.marks
385
439
  );
440
+ return newTable;
386
441
  }
387
- function fe(e) {
388
- const t = h.get(e), n = [];
389
- for (let o = 0; o < t.height; o++) {
390
- const l = [], r = {};
391
- for (let s = 0; s < t.width; s++) {
392
- const c = t.map[o * t.width + s], d = e.nodeAt(c), p = t.findCell(c);
393
- if (r[c] || p.top !== o) {
394
- l.push(null);
442
+ function convertTableNodeToArrayOfRows(tableNode) {
443
+ const map = TableMap.get(tableNode);
444
+ const rows = [];
445
+ for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
446
+ const rowCells = [];
447
+ const seen = {};
448
+ for (let colIndex = 0; colIndex < map.width; colIndex++) {
449
+ const cellPos = map.map[rowIndex * map.width + colIndex];
450
+ const cell = tableNode.nodeAt(cellPos);
451
+ const rect = map.findCell(cellPos);
452
+ if (seen[cellPos] || rect.top !== rowIndex) {
453
+ rowCells.push(null);
395
454
  continue;
396
455
  }
397
- r[c] = !0, l.push(d);
456
+ seen[cellPos] = true;
457
+ rowCells.push(cell);
398
458
  }
399
- n.push(l);
459
+ rows.push(rowCells);
400
460
  }
401
- return n;
461
+ return rows;
402
462
  }
403
- function ge(e, t, n, o) {
404
- const l = t[0] > n[0] ? -1 : 1, r = e.splice(t[0], t.length), s = r.length % 2 === 0 ? 1 : 0;
405
- let c;
406
- return c = l === -1 ? n[0] : n[n.length - 1] - s, e.splice(c, 0, ...r), e;
463
+ function moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, directionOverride) {
464
+ const direction = indexesOrigin[0] > indexesTarget[0] ? -1 : 1;
465
+ const rowsExtracted = rows.splice(indexesOrigin[0], indexesOrigin.length);
466
+ const positionOffset = rowsExtracted.length % 2 === 0 ? 1 : 0;
467
+ let target;
468
+ {
469
+ target = direction === -1 ? indexesTarget[0] : indexesTarget[indexesTarget.length - 1] - positionOffset;
470
+ }
471
+ rows.splice(target, 0, ...rowsExtracted);
472
+ return rows;
407
473
  }
408
- function at(e, t, n, o) {
409
- let l = Z(fe(e.node));
410
- return l = ge(l, t, n), l = Z(l), pe(e.node, l);
474
+ function moveTableColumn(table, indexesOrigin, indexesTarget, direction) {
475
+ let rows = transpose(convertTableNodeToArrayOfRows(table.node));
476
+ rows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget);
477
+ rows = transpose(rows);
478
+ return convertArrayOfRowsToTableNode(table.node, rows);
411
479
  }
412
- function st(e, t, n, o) {
413
- let l = fe(e.node);
414
- return l = ge(l, t, n), pe(e.node, l);
480
+ function moveTableRow(table, indexesOrigin, indexesTarget, direction) {
481
+ let rows = convertTableNodeToArrayOfRows(table.node);
482
+ rows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget);
483
+ return convertArrayOfRowsToTableNode(table.node, rows);
415
484
  }
416
- function ee(e, t) {
417
- let n = e, o = e;
418
- for (let a = e; a >= 0; a--) {
419
- const m = y(a, t.selection);
420
- m && m.forEach((u) => {
421
- const f = u.node.attrs.colspan + a - 1;
422
- f >= n && (n = a), f > o && (o = f);
423
- });
485
+ function getSelectionRangeInColumn(columnIndex, tr) {
486
+ let startIndex = columnIndex;
487
+ let endIndex = columnIndex;
488
+ for (let i = columnIndex; i >= 0; i--) {
489
+ const cells = getCellsInCol(i, tr.selection);
490
+ if (cells) {
491
+ cells.forEach((cell) => {
492
+ const maybeEndIndex = cell.node.attrs.colspan + i - 1;
493
+ if (maybeEndIndex >= startIndex) startIndex = i;
494
+ if (maybeEndIndex > endIndex) endIndex = maybeEndIndex;
495
+ });
496
+ }
424
497
  }
425
- for (let a = e; a <= o; a++) {
426
- const m = y(a, t.selection);
427
- m && m.forEach((u) => {
428
- const f = u.node.attrs.colspan + a - 1;
429
- u.node.attrs.colspan > 1 && f > o && (o = f);
430
- });
498
+ for (let i = columnIndex; i <= endIndex; i++) {
499
+ const cells = getCellsInCol(i, tr.selection);
500
+ if (cells) {
501
+ cells.forEach((cell) => {
502
+ const maybeEndIndex = cell.node.attrs.colspan + i - 1;
503
+ if (cell.node.attrs.colspan > 1 && maybeEndIndex > endIndex)
504
+ endIndex = maybeEndIndex;
505
+ });
506
+ }
431
507
  }
432
- const l = [];
433
- for (let a = n; a <= o; a++) {
434
- const m = y(a, t.selection);
435
- m && m.length && l.push(a);
508
+ const indexes = [];
509
+ for (let i = startIndex; i <= endIndex; i++) {
510
+ const maybeCells = getCellsInCol(i, tr.selection);
511
+ if (maybeCells && maybeCells.length) indexes.push(i);
436
512
  }
437
- n = l[0], o = l[l.length - 1];
438
- const r = y(n, t.selection), s = w(0, t.selection), c = t.doc.resolve(
439
- r[r.length - 1].pos
513
+ startIndex = indexes[0];
514
+ endIndex = indexes[indexes.length - 1];
515
+ const firstSelectedColumnCells = getCellsInCol(startIndex, tr.selection);
516
+ const firstRowCells = getCellsInRow(0, tr.selection);
517
+ const $anchor = tr.doc.resolve(
518
+ firstSelectedColumnCells[firstSelectedColumnCells.length - 1].pos
440
519
  );
441
- let d;
442
- for (let a = o; a >= n; a--) {
443
- const m = y(a, t.selection);
444
- if (m && m.length) {
445
- for (let u = s.length - 1; u >= 0; u--)
446
- if (s[u].pos === m[0].pos) {
447
- d = m[0];
520
+ let headCell;
521
+ for (let i = endIndex; i >= startIndex; i--) {
522
+ const columnCells = getCellsInCol(i, tr.selection);
523
+ if (columnCells && columnCells.length) {
524
+ for (let j = firstRowCells.length - 1; j >= 0; j--) {
525
+ if (firstRowCells[j].pos === columnCells[0].pos) {
526
+ headCell = columnCells[0];
448
527
  break;
449
528
  }
450
- if (d) break;
529
+ }
530
+ if (headCell) break;
451
531
  }
452
532
  }
453
- const p = t.doc.resolve(d.pos);
454
- return { $anchor: c, $head: p, indexes: l };
533
+ const $head = tr.doc.resolve(headCell.pos);
534
+ return { $anchor, $head, indexes };
455
535
  }
456
- function te(e, t) {
457
- let n = e, o = e;
458
- for (let a = e; a >= 0; a--)
459
- w(a, t.selection).forEach((u) => {
460
- const f = u.node.attrs.rowspan + a - 1;
461
- f >= n && (n = a), f > o && (o = f);
536
+ function getSelectionRangeInRow(rowIndex, tr) {
537
+ let startIndex = rowIndex;
538
+ let endIndex = rowIndex;
539
+ for (let i = rowIndex; i >= 0; i--) {
540
+ const cells = getCellsInRow(i, tr.selection);
541
+ cells.forEach((cell) => {
542
+ const maybeEndIndex = cell.node.attrs.rowspan + i - 1;
543
+ if (maybeEndIndex >= startIndex) startIndex = i;
544
+ if (maybeEndIndex > endIndex) endIndex = maybeEndIndex;
462
545
  });
463
- for (let a = e; a <= o; a++)
464
- w(a, t.selection).forEach((u) => {
465
- const f = u.node.attrs.rowspan + a - 1;
466
- u.node.attrs.rowspan > 1 && f > o && (o = f);
546
+ }
547
+ for (let i = rowIndex; i <= endIndex; i++) {
548
+ const cells = getCellsInRow(i, tr.selection);
549
+ cells.forEach((cell) => {
550
+ const maybeEndIndex = cell.node.attrs.rowspan + i - 1;
551
+ if (cell.node.attrs.rowspan > 1 && maybeEndIndex > endIndex)
552
+ endIndex = maybeEndIndex;
467
553
  });
468
- const l = [];
469
- for (let a = n; a <= o; a++) {
470
- const m = w(a, t.selection);
471
- m && m.length && l.push(a);
472
554
  }
473
- n = l[0], o = l[l.length - 1];
474
- const r = w(n, t.selection), s = y(0, t.selection), c = t.doc.resolve(
475
- r[r.length - 1].pos
555
+ const indexes = [];
556
+ for (let i = startIndex; i <= endIndex; i++) {
557
+ const maybeCells = getCellsInRow(i, tr.selection);
558
+ if (maybeCells && maybeCells.length) indexes.push(i);
559
+ }
560
+ startIndex = indexes[0];
561
+ endIndex = indexes[indexes.length - 1];
562
+ const firstSelectedRowCells = getCellsInRow(startIndex, tr.selection);
563
+ const firstColumnCells = getCellsInCol(0, tr.selection);
564
+ const $anchor = tr.doc.resolve(
565
+ firstSelectedRowCells[firstSelectedRowCells.length - 1].pos
476
566
  );
477
- let d;
478
- for (let a = o; a >= n; a--) {
479
- const m = w(a, t.selection);
480
- if (m && m.length) {
481
- for (let u = s.length - 1; u >= 0; u--)
482
- if (s[u].pos === m[0].pos) {
483
- d = m[0];
567
+ let headCell;
568
+ for (let i = endIndex; i >= startIndex; i--) {
569
+ const rowCells = getCellsInRow(i, tr.selection);
570
+ if (rowCells && rowCells.length) {
571
+ for (let j = firstColumnCells.length - 1; j >= 0; j--) {
572
+ if (firstColumnCells[j].pos === rowCells[0].pos) {
573
+ headCell = rowCells[0];
484
574
  break;
485
575
  }
486
- if (d) break;
576
+ }
577
+ if (headCell) break;
487
578
  }
488
579
  }
489
- const p = t.doc.resolve(d.pos);
490
- return { $anchor: c, $head: p, indexes: l };
580
+ const $head = tr.doc.resolve(headCell.pos);
581
+ return { $anchor, $head, indexes };
491
582
  }
492
- function ct(e) {
493
- const { tr: t, origin: n, target: o, select: l = !0, pos: r } = e, s = r != null ? t.doc.resolve(r) : t.selection.$from, c = M(s);
494
- if (!c) return t;
495
- const { indexes: d } = ee(n, t), { indexes: p } = ee(o, t);
496
- if (d.includes(o)) return t;
497
- const a = at(
498
- c,
499
- d,
500
- p
501
- ), m = _(t).replaceWith(
502
- c.pos,
503
- c.pos + c.node.nodeSize,
504
- a
583
+ function moveCol(moveColParams) {
584
+ const { tr, origin, target, select = true, pos } = moveColParams;
585
+ const $pos = pos != null ? tr.doc.resolve(pos) : tr.selection.$from;
586
+ const table = findTable($pos);
587
+ if (!table) return tr;
588
+ const { indexes: indexesOriginColumn } = getSelectionRangeInColumn(origin, tr);
589
+ const { indexes: indexesTargetColumn } = getSelectionRangeInColumn(target, tr);
590
+ if (indexesOriginColumn.includes(target)) return tr;
591
+ const newTable = moveTableColumn(
592
+ table,
593
+ indexesOriginColumn,
594
+ indexesTargetColumn
595
+ );
596
+ const _tr = cloneTr(tr).replaceWith(
597
+ table.pos,
598
+ table.pos + table.node.nodeSize,
599
+ newTable
505
600
  );
506
- if (!l) return m;
507
- const u = h.get(a), f = c.start, b = o, P = u.positionAt(u.height - 1, b, a), D = m.doc.resolve(f + P), E = k.colSelection, O = u.positionAt(0, b, a), H = m.doc.resolve(f + O);
508
- return m.setSelection(E(D, H));
601
+ if (!select) return _tr;
602
+ const map = TableMap.get(newTable);
603
+ const start = table.start;
604
+ const index = target;
605
+ const lastCell = map.positionAt(map.height - 1, index, newTable);
606
+ const $lastCell = _tr.doc.resolve(start + lastCell);
607
+ const createCellSelection = CellSelection.colSelection;
608
+ const firstCell = map.positionAt(0, index, newTable);
609
+ const $firstCell = _tr.doc.resolve(start + firstCell);
610
+ return _tr.setSelection(createCellSelection($lastCell, $firstCell));
509
611
  }
510
- function it(e) {
511
- const { tr: t, origin: n, target: o, select: l = !0, pos: r } = e, s = r != null ? t.doc.resolve(r) : t.selection.$from, c = M(s);
512
- if (!c) return t;
513
- const { indexes: d } = te(n, t), { indexes: p } = te(o, t);
514
- if (d.includes(o)) return t;
515
- const a = st(c, d, p), m = _(t).replaceWith(
516
- c.pos,
517
- c.pos + c.node.nodeSize,
518
- a
612
+ function moveRow(moveRowParams) {
613
+ const { tr, origin, target, select = true, pos } = moveRowParams;
614
+ const $pos = pos != null ? tr.doc.resolve(pos) : tr.selection.$from;
615
+ const table = findTable($pos);
616
+ if (!table) return tr;
617
+ const { indexes: indexesOriginRow } = getSelectionRangeInRow(origin, tr);
618
+ const { indexes: indexesTargetRow } = getSelectionRangeInRow(target, tr);
619
+ if (indexesOriginRow.includes(target)) return tr;
620
+ const newTable = moveTableRow(table, indexesOriginRow, indexesTargetRow);
621
+ const _tr = cloneTr(tr).replaceWith(
622
+ table.pos,
623
+ table.pos + table.node.nodeSize,
624
+ newTable
519
625
  );
520
- if (!l) return m;
521
- const u = h.get(a), f = c.start, b = o, P = u.positionAt(b, u.width - 1, a), D = m.doc.resolve(f + P), E = k.rowSelection, O = u.positionAt(b, 0, a), H = m.doc.resolve(f + O);
522
- return m.setSelection(E(D, H));
626
+ if (!select) return _tr;
627
+ const map = TableMap.get(newTable);
628
+ const start = table.start;
629
+ const index = target;
630
+ const lastCell = map.positionAt(index, map.width - 1, newTable);
631
+ const $lastCell = _tr.doc.resolve(start + lastCell);
632
+ const createCellSelection = CellSelection.rowSelection;
633
+ const firstCell = map.positionAt(index, 0, newTable);
634
+ const $firstCell = _tr.doc.resolve(start + firstCell);
635
+ return _tr.setSelection(createCellSelection($lastCell, $firstCell));
523
636
  }
524
- const V = g(
637
+ const goToPrevTableCellCommand = $command(
525
638
  "GoToPrevTableCell",
526
- () => () => re(-1)
639
+ () => () => goToNextCell(-1)
527
640
  );
528
- i(V, {
641
+ withMeta(goToPrevTableCellCommand, {
529
642
  displayName: "Command<goToPrevTableCellCommand>",
530
643
  group: "Table"
531
644
  });
532
- const U = g(
645
+ const goToNextTableCellCommand = $command(
533
646
  "GoToNextTableCell",
534
- () => () => re(1)
647
+ () => () => goToNextCell(1)
535
648
  );
536
- i(U, {
649
+ withMeta(goToNextTableCellCommand, {
537
650
  displayName: "Command<goToNextTableCellCommand>",
538
651
  group: "Table"
539
652
  });
540
- const X = g(
653
+ const exitTable = $command(
541
654
  "ExitTable",
542
- (e) => () => (t, n) => {
543
- if (!G(t)) return !1;
544
- const { $head: o } = t.selection, l = Je(o, N.type(e));
545
- if (!l) return !1;
546
- const { to: r } = l, s = t.tr.replaceWith(
547
- r,
548
- r,
549
- De.type(e).createAndFill()
655
+ (ctx) => () => (state, dispatch) => {
656
+ if (!isInTable(state)) return false;
657
+ const { $head } = state.selection;
658
+ const table = findParentNodeType($head, tableSchema.type(ctx));
659
+ if (!table) return false;
660
+ const { to } = table;
661
+ const tr = state.tr.replaceWith(
662
+ to,
663
+ to,
664
+ paragraphSchema.type(ctx).createAndFill()
550
665
  );
551
- return s.setSelection(ce.near(s.doc.resolve(r), 1)).scrollIntoView(), n == null || n(s), !0;
666
+ tr.setSelection(Selection.near(tr.doc.resolve(to), 1)).scrollIntoView();
667
+ dispatch == null ? void 0 : dispatch(tr);
668
+ return true;
552
669
  }
553
670
  );
554
- i(X, {
671
+ withMeta(exitTable, {
555
672
  displayName: "Command<breakTableCommand>",
556
673
  group: "Table"
557
674
  });
558
- const he = g(
675
+ const insertTableCommand = $command(
559
676
  "InsertTable",
560
- (e) => ({ row: t, col: n } = {}) => (o, l) => {
561
- const { selection: r, tr: s } = o, { from: c } = r, d = de(e, t, n), p = s.replaceSelectionWith(d), a = ce.findFrom(p.doc.resolve(c), 1, !0);
562
- return a && p.setSelection(a), l == null || l(p), !0;
677
+ (ctx) => ({ row, col } = {}) => (state, dispatch) => {
678
+ const { selection, tr } = state;
679
+ const { from } = selection;
680
+ const table = createTable(ctx, row, col);
681
+ const _tr = tr.replaceSelectionWith(table);
682
+ const sel = Selection.findFrom(_tr.doc.resolve(from), 1, true);
683
+ if (sel) _tr.setSelection(sel);
684
+ dispatch == null ? void 0 : dispatch(_tr);
685
+ return true;
563
686
  }
564
687
  );
565
- i(he, {
688
+ withMeta(insertTableCommand, {
566
689
  displayName: "Command<insertTableCommand>",
567
690
  group: "Table"
568
691
  });
569
- const be = g(
692
+ const moveRowCommand = $command(
570
693
  "MoveRow",
571
- () => ({ from: e, to: t, pos: n } = {}) => (o, l) => {
572
- const { tr: r } = o;
573
- return !!(l == null ? void 0 : l(
574
- it({ tr: r, origin: e ?? 0, target: t ?? 0, pos: n, select: !0 })
575
- ));
694
+ () => ({ from, to, pos } = {}) => (state, dispatch) => {
695
+ const { tr } = state;
696
+ const result = dispatch == null ? void 0 : dispatch(
697
+ moveRow({ tr, origin: from ?? 0, target: to ?? 0, pos, select: true })
698
+ );
699
+ return Boolean(result);
576
700
  }
577
701
  );
578
- i(be, {
702
+ withMeta(moveRowCommand, {
579
703
  displayName: "Command<moveRowCommand>",
580
704
  group: "Table"
581
705
  });
582
- const Ce = g(
706
+ const moveColCommand = $command(
583
707
  "MoveCol",
584
- () => ({ from: e, to: t, pos: n } = {}) => (o, l) => {
585
- const { tr: r } = o;
586
- return !!(l == null ? void 0 : l(
587
- ct({ tr: r, origin: e ?? 0, target: t ?? 0, pos: n, select: !0 })
588
- ));
708
+ () => ({ from, to, pos } = {}) => (state, dispatch) => {
709
+ const { tr } = state;
710
+ const result = dispatch == null ? void 0 : dispatch(
711
+ moveCol({ tr, origin: from ?? 0, target: to ?? 0, pos, select: true })
712
+ );
713
+ return Boolean(result);
589
714
  }
590
715
  );
591
- i(Ce, {
716
+ withMeta(moveColCommand, {
592
717
  displayName: "Command<moveColCommand>",
593
718
  group: "Table"
594
719
  });
595
- const ye = g(
720
+ const selectRowCommand = $command(
596
721
  "SelectRow",
597
- () => (e = { index: 0 }) => (t, n) => {
598
- const { tr: o } = t;
599
- return !!(n == null ? void 0 : n(lt(e.index, e.pos)(o)));
722
+ () => (payload = { index: 0 }) => (state, dispatch) => {
723
+ const { tr } = state;
724
+ const result = dispatch == null ? void 0 : dispatch(selectRow(payload.index, payload.pos)(tr));
725
+ return Boolean(result);
600
726
  }
601
727
  );
602
- i(ye, {
728
+ withMeta(selectRowCommand, {
603
729
  displayName: "Command<selectRowCommand>",
604
730
  group: "Table"
605
731
  });
606
- const we = g(
732
+ const selectColCommand = $command(
607
733
  "SelectCol",
608
- () => (e = { index: 0 }) => (t, n) => {
609
- const { tr: o } = t;
610
- return !!(n == null ? void 0 : n(rt(e.index, e.pos)(o)));
734
+ () => (payload = { index: 0 }) => (state, dispatch) => {
735
+ const { tr } = state;
736
+ const result = dispatch == null ? void 0 : dispatch(selectCol(payload.index, payload.pos)(tr));
737
+ return Boolean(result);
611
738
  }
612
739
  );
613
- i(we, {
740
+ withMeta(selectColCommand, {
614
741
  displayName: "Command<selectColCommand>",
615
742
  group: "Table"
616
743
  });
617
- const ke = g(
744
+ const selectTableCommand = $command(
618
745
  "SelectTable",
619
- () => () => (e, t) => {
620
- const { tr: n } = e;
621
- return !!(t == null ? void 0 : t(nt(n)));
746
+ () => () => (state, dispatch) => {
747
+ const { tr } = state;
748
+ const result = dispatch == null ? void 0 : dispatch(selectTable(tr));
749
+ return Boolean(result);
622
750
  }
623
751
  );
624
- i(ke, {
752
+ withMeta(selectTableCommand, {
625
753
  displayName: "Command<selectTableCommand>",
626
754
  group: "Table"
627
755
  });
628
- const Ne = g(
756
+ const deleteSelectedCellsCommand = $command(
629
757
  "DeleteSelectedCells",
630
- () => () => (e, t) => {
631
- const { selection: n } = e;
632
- if (!(n instanceof k)) return !1;
633
- const o = n.isRowSelection(), l = n.isColSelection();
634
- return o && l ? Ke(e, t) : l ? Fe(e, t) : Ge(e, t);
758
+ () => () => (state, dispatch) => {
759
+ const { selection } = state;
760
+ if (!(selection instanceof CellSelection)) return false;
761
+ const isRow = selection.isRowSelection();
762
+ const isCol = selection.isColSelection();
763
+ if (isRow && isCol) return deleteTable(state, dispatch);
764
+ if (isCol) return deleteColumn(state, dispatch);
765
+ else return deleteRow(state, dispatch);
635
766
  }
636
767
  );
637
- i(Ne, {
768
+ withMeta(deleteSelectedCellsCommand, {
638
769
  displayName: "Command<deleteSelectedCellsCommand>",
639
770
  group: "Table"
640
771
  });
641
- const Te = g(
772
+ const addColBeforeCommand = $command(
642
773
  "AddColBefore",
643
- () => () => We
774
+ () => () => addColumnBefore
644
775
  );
645
- i(Te, {
776
+ withMeta(addColBeforeCommand, {
646
777
  displayName: "Command<addColBeforeCommand>",
647
778
  group: "Table"
648
779
  });
649
- const Se = g(
780
+ const addColAfterCommand = $command(
650
781
  "AddColAfter",
651
- () => () => ze
782
+ () => () => addColumnAfter
652
783
  );
653
- i(Se, {
784
+ withMeta(addColAfterCommand, {
654
785
  displayName: "Command<addColAfterCommand>",
655
786
  group: "Table"
656
787
  });
657
- const Re = g(
788
+ const addRowBeforeCommand = $command(
658
789
  "AddRowBefore",
659
- (e) => () => (t, n) => {
660
- if (!G(t)) return !1;
661
- if (n) {
662
- const o = ae(t);
663
- n(me(e, t.tr, o, o.top));
790
+ (ctx) => () => (state, dispatch) => {
791
+ if (!isInTable(state)) return false;
792
+ if (dispatch) {
793
+ const rect = selectedRect(state);
794
+ dispatch(addRowWithAlignment(ctx, state.tr, rect, rect.top));
664
795
  }
665
- return !0;
796
+ return true;
666
797
  }
667
798
  );
668
- i(Re, {
799
+ withMeta(addRowBeforeCommand, {
669
800
  displayName: "Command<addRowBeforeCommand>",
670
801
  group: "Table"
671
802
  });
672
- const xe = g(
803
+ const addRowAfterCommand = $command(
673
804
  "AddRowAfter",
674
- (e) => () => (t, n) => {
675
- if (!G(t)) return !1;
676
- if (n) {
677
- const o = ae(t);
678
- n(me(e, t.tr, o, o.bottom));
805
+ (ctx) => () => (state, dispatch) => {
806
+ if (!isInTable(state)) return false;
807
+ if (dispatch) {
808
+ const rect = selectedRect(state);
809
+ dispatch(addRowWithAlignment(ctx, state.tr, rect, rect.bottom));
679
810
  }
680
- return !0;
811
+ return true;
681
812
  }
682
813
  );
683
- i(xe, {
814
+ withMeta(addRowAfterCommand, {
684
815
  displayName: "Command<addRowAfterCommand>",
685
816
  group: "Table"
686
817
  });
687
- const Me = g(
818
+ const setAlignCommand = $command(
688
819
  "SetAlign",
689
- () => (e = "left") => je("alignment", e)
820
+ () => (alignment = "left") => setCellAttr("alignment", alignment)
690
821
  );
691
- i(Me, {
822
+ withMeta(setAlignCommand, {
692
823
  displayName: "Command<setAlignCommand>",
693
824
  group: "Table"
694
825
  });
695
- const Ae = F(
696
- (e) => new ne(
826
+ const insertTableInputRule = $inputRule(
827
+ (ctx) => new InputRule(
697
828
  /^\|(?<col>\d+)[xX](?<row>\d+)\|\s$/,
698
- (t, n, o, l) => {
699
- var d, p;
700
- const r = t.doc.resolve(o);
701
- if (!r.node(-1).canReplaceWith(
702
- r.index(-1),
703
- r.indexAfter(-1),
704
- N.type(e)
829
+ (state, match, start, end) => {
830
+ var _a, _b;
831
+ const $start = state.doc.resolve(start);
832
+ if (!$start.node(-1).canReplaceWith(
833
+ $start.index(-1),
834
+ $start.indexAfter(-1),
835
+ tableSchema.type(ctx)
705
836
  ))
706
837
  return null;
707
- const s = de(
708
- e,
709
- Number((d = n.groups) == null ? void 0 : d.row),
710
- Number((p = n.groups) == null ? void 0 : p.col)
711
- ), c = t.tr.replaceRangeWith(o, l, s);
712
- return c.setSelection(Qe.create(c.doc, o + 3)).scrollIntoView();
838
+ const tableNode = createTable(
839
+ ctx,
840
+ Number((_a = match.groups) == null ? void 0 : _a.row),
841
+ Number((_b = match.groups) == null ? void 0 : _b.col)
842
+ );
843
+ const tr = state.tr.replaceRangeWith(start, end, tableNode);
844
+ return tr.setSelection(TextSelection.create(tr.doc, start + 3)).scrollIntoView();
713
845
  }
714
846
  )
715
847
  );
716
- i(Ae, {
848
+ withMeta(insertTableInputRule, {
717
849
  displayName: "InputRule<insertTableInputRule>",
718
850
  group: "Table"
719
851
  });
720
- const q = le("tableKeymap", {
852
+ const tableKeymap = $useKeymap("tableKeymap", {
721
853
  NextCell: {
722
854
  shortcuts: ["Mod-]", "Tab"],
723
- command: (e) => {
724
- const t = e.get(A);
725
- return () => t.call(U.key);
855
+ command: (ctx) => {
856
+ const commands2 = ctx.get(commandsCtx);
857
+ return () => commands2.call(goToNextTableCellCommand.key);
726
858
  }
727
859
  },
728
860
  PrevCell: {
729
861
  shortcuts: ["Mod-[", "Shift-Tab"],
730
- command: (e) => {
731
- const t = e.get(A);
732
- return () => t.call(V.key);
862
+ command: (ctx) => {
863
+ const commands2 = ctx.get(commandsCtx);
864
+ return () => commands2.call(goToPrevTableCellCommand.key);
733
865
  }
734
866
  },
735
867
  ExitTable: {
736
868
  shortcuts: ["Mod-Enter"],
737
- command: (e) => {
738
- const t = e.get(A);
739
- return () => t.call(X.key);
869
+ command: (ctx) => {
870
+ const commands2 = ctx.get(commandsCtx);
871
+ return () => commands2.call(exitTable.key);
740
872
  }
741
873
  }
742
874
  });
743
- i(q.ctx, {
875
+ withMeta(tableKeymap.ctx, {
744
876
  displayName: "KeymapCtx<table>",
745
877
  group: "Table"
746
878
  });
747
- i(q.shortcuts, {
879
+ withMeta(tableKeymap.shortcuts, {
748
880
  displayName: "Keymap<table>",
749
881
  group: "Table"
750
882
  });
751
- const B = "footnote_definition", oe = "footnoteDefinition", J = C(
883
+ const id$1 = "footnote_definition";
884
+ const markdownId = "footnoteDefinition";
885
+ const footnoteDefinitionSchema = $nodeSchema(
752
886
  "footnote_definition",
753
887
  () => ({
754
888
  group: "block",
755
889
  content: "block+",
756
- defining: !0,
890
+ defining: true,
757
891
  attrs: {
758
892
  label: {
759
893
  default: ""
@@ -761,62 +895,63 @@ const B = "footnote_definition", oe = "footnoteDefinition", J = C(
761
895
  },
762
896
  parseDOM: [
763
897
  {
764
- tag: `dl[data-type="${B}"]`,
765
- getAttrs: (e) => {
766
- if (!(e instanceof HTMLElement)) throw K(e);
898
+ tag: `dl[data-type="${id$1}"]`,
899
+ getAttrs: (dom) => {
900
+ if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom);
767
901
  return {
768
- label: e.dataset.label
902
+ label: dom.dataset.label
769
903
  };
770
904
  },
771
905
  contentElement: "dd"
772
906
  }
773
907
  ],
774
- toDOM: (e) => {
775
- const t = e.attrs.label;
908
+ toDOM: (node) => {
909
+ const label = node.attrs.label;
776
910
  return [
777
911
  "dl",
778
912
  {
779
913
  // TODO: add a prosemirror plugin to sync label on change
780
- "data-label": t,
781
- "data-type": B
914
+ "data-label": label,
915
+ "data-type": id$1
782
916
  },
783
- ["dt", t],
917
+ ["dt", label],
784
918
  ["dd", 0]
785
919
  ];
786
920
  },
787
921
  parseMarkdown: {
788
- match: ({ type: e }) => e === oe,
789
- runner: (e, t, n) => {
790
- e.openNode(n, {
791
- label: t.label
792
- }).next(t.children).closeNode();
922
+ match: ({ type }) => type === markdownId,
923
+ runner: (state, node, type) => {
924
+ state.openNode(type, {
925
+ label: node.label
926
+ }).next(node.children).closeNode();
793
927
  }
794
928
  },
795
929
  toMarkdown: {
796
- match: (e) => e.type.name === B,
797
- runner: (e, t) => {
798
- e.openNode(oe, void 0, {
799
- label: t.attrs.label,
800
- identifier: t.attrs.label
801
- }).next(t.content).closeNode();
930
+ match: (node) => node.type.name === id$1,
931
+ runner: (state, node) => {
932
+ state.openNode(markdownId, void 0, {
933
+ label: node.attrs.label,
934
+ identifier: node.attrs.label
935
+ }).next(node.content).closeNode();
802
936
  }
803
937
  }
804
938
  })
805
939
  );
806
- i(J.ctx, {
940
+ withMeta(footnoteDefinitionSchema.ctx, {
807
941
  displayName: "NodeSchemaCtx<footnodeDef>",
808
942
  group: "footnote"
809
943
  });
810
- i(J.node, {
944
+ withMeta(footnoteDefinitionSchema.node, {
811
945
  displayName: "NodeSchema<footnodeDef>",
812
946
  group: "footnote"
813
947
  });
814
- const L = "footnote_reference", Q = C(
948
+ const id = "footnote_reference";
949
+ const footnoteReferenceSchema = $nodeSchema(
815
950
  "footnote_reference",
816
951
  () => ({
817
952
  group: "inline",
818
- inline: !0,
819
- atom: !0,
953
+ inline: true,
954
+ atom: true,
820
955
  attrs: {
821
956
  label: {
822
957
  default: ""
@@ -824,300 +959,341 @@ const L = "footnote_reference", Q = C(
824
959
  },
825
960
  parseDOM: [
826
961
  {
827
- tag: `sup[data-type="${L}"]`,
828
- getAttrs: (e) => {
829
- if (!(e instanceof HTMLElement)) throw K(e);
962
+ tag: `sup[data-type="${id}"]`,
963
+ getAttrs: (dom) => {
964
+ if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom);
830
965
  return {
831
- label: e.dataset.label
966
+ label: dom.dataset.label
832
967
  };
833
968
  }
834
969
  }
835
970
  ],
836
- toDOM: (e) => {
837
- const t = e.attrs.label;
971
+ toDOM: (node) => {
972
+ const label = node.attrs.label;
838
973
  return [
839
974
  "sup",
840
975
  {
841
976
  // TODO: add a prosemirror plugin to sync label on change
842
- "data-label": t,
843
- "data-type": L
977
+ "data-label": label,
978
+ "data-type": id
844
979
  },
845
- t
980
+ label
846
981
  ];
847
982
  },
848
983
  parseMarkdown: {
849
- match: ({ type: e }) => e === "footnoteReference",
850
- runner: (e, t, n) => {
851
- e.addNode(n, {
852
- label: t.label
984
+ match: ({ type }) => type === "footnoteReference",
985
+ runner: (state, node, type) => {
986
+ state.addNode(type, {
987
+ label: node.label
853
988
  });
854
989
  }
855
990
  },
856
991
  toMarkdown: {
857
- match: (e) => e.type.name === L,
858
- runner: (e, t) => {
859
- e.addNode("footnoteReference", void 0, void 0, {
860
- label: t.attrs.label,
861
- identifier: t.attrs.label
992
+ match: (node) => node.type.name === id,
993
+ runner: (state, node) => {
994
+ state.addNode("footnoteReference", void 0, void 0, {
995
+ label: node.attrs.label,
996
+ identifier: node.attrs.label
862
997
  });
863
998
  }
864
999
  }
865
1000
  })
866
1001
  );
867
- i(Q.ctx, {
1002
+ withMeta(footnoteReferenceSchema.ctx, {
868
1003
  displayName: "NodeSchemaCtx<footnodeRef>",
869
1004
  group: "footnote"
870
1005
  });
871
- i(Q.node, {
1006
+ withMeta(footnoteReferenceSchema.node, {
872
1007
  displayName: "NodeSchema<footnodeRef>",
873
1008
  group: "footnote"
874
1009
  });
875
- const ve = Ee.extendSchema(
876
- (e) => (t) => {
877
- const n = e(t);
878
- return {
879
- ...n,
880
- attrs: {
881
- ...n.attrs,
882
- checked: {
883
- default: null
884
- }
885
- },
886
- parseDOM: [
887
- {
888
- tag: 'li[data-item-type="task"]',
889
- getAttrs: (o) => {
890
- if (!(o instanceof HTMLElement)) throw K(o);
891
- return {
892
- label: o.dataset.label,
893
- listType: o.dataset.listType,
894
- spread: o.dataset.spread,
895
- checked: o.dataset.checked ? o.dataset.checked === "true" : null
896
- };
1010
+ const extendListItemSchemaForTask = listItemSchema.extendSchema(
1011
+ (prev) => {
1012
+ return (ctx) => {
1013
+ const baseSchema = prev(ctx);
1014
+ return {
1015
+ ...baseSchema,
1016
+ attrs: {
1017
+ ...baseSchema.attrs,
1018
+ checked: {
1019
+ default: null
897
1020
  }
898
1021
  },
899
- ...(n == null ? void 0 : n.parseDOM) || []
900
- ],
901
- toDOM: (o) => n.toDOM && o.attrs.checked == null ? n.toDOM(o) : [
902
- "li",
903
- {
904
- "data-item-type": "task",
905
- "data-label": o.attrs.label,
906
- "data-list-type": o.attrs.listType,
907
- "data-spread": o.attrs.spread,
908
- "data-checked": o.attrs.checked
1022
+ parseDOM: [
1023
+ {
1024
+ tag: 'li[data-item-type="task"]',
1025
+ getAttrs: (dom) => {
1026
+ if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom);
1027
+ return {
1028
+ label: dom.dataset.label,
1029
+ listType: dom.dataset.listType,
1030
+ spread: dom.dataset.spread,
1031
+ checked: dom.dataset.checked ? dom.dataset.checked === "true" : null
1032
+ };
1033
+ }
1034
+ },
1035
+ ...(baseSchema == null ? void 0 : baseSchema.parseDOM) || []
1036
+ ],
1037
+ toDOM: (node) => {
1038
+ if (baseSchema.toDOM && node.attrs.checked == null)
1039
+ return baseSchema.toDOM(node);
1040
+ return [
1041
+ "li",
1042
+ {
1043
+ "data-item-type": "task",
1044
+ "data-label": node.attrs.label,
1045
+ "data-list-type": node.attrs.listType,
1046
+ "data-spread": node.attrs.spread,
1047
+ "data-checked": node.attrs.checked
1048
+ },
1049
+ 0
1050
+ ];
909
1051
  },
910
- 0
911
- ],
912
- parseMarkdown: {
913
- match: ({ type: o }) => o === "listItem",
914
- runner: (o, l, r) => {
915
- if (l.checked == null) {
916
- n.parseMarkdown.runner(o, l, r);
917
- return;
1052
+ parseMarkdown: {
1053
+ match: ({ type }) => type === "listItem",
1054
+ runner: (state, node, type) => {
1055
+ if (node.checked == null) {
1056
+ baseSchema.parseMarkdown.runner(state, node, type);
1057
+ return;
1058
+ }
1059
+ const label = node.label != null ? `${node.label}.` : "•";
1060
+ const checked = node.checked != null ? Boolean(node.checked) : null;
1061
+ const listType = node.label != null ? "ordered" : "bullet";
1062
+ const spread = node.spread != null ? `${node.spread}` : "true";
1063
+ state.openNode(type, { label, listType, spread, checked });
1064
+ state.next(node.children);
1065
+ state.closeNode();
918
1066
  }
919
- const s = l.label != null ? `${l.label}.` : "•", c = l.checked != null ? !!l.checked : null, d = l.label != null ? "ordered" : "bullet", p = l.spread != null ? `${l.spread}` : "true";
920
- o.openNode(r, { label: s, listType: d, spread: p, checked: c }), o.next(l.children), o.closeNode();
921
- }
922
- },
923
- toMarkdown: {
924
- match: (o) => o.type.name === "list_item",
925
- runner: (o, l) => {
926
- if (l.attrs.checked == null) {
927
- n.toMarkdown.runner(o, l);
928
- return;
1067
+ },
1068
+ toMarkdown: {
1069
+ match: (node) => node.type.name === "list_item",
1070
+ runner: (state, node) => {
1071
+ if (node.attrs.checked == null) {
1072
+ baseSchema.toMarkdown.runner(state, node);
1073
+ return;
1074
+ }
1075
+ const label = node.attrs.label;
1076
+ const listType = node.attrs.listType;
1077
+ const spread = node.attrs.spread === "true";
1078
+ const checked = node.attrs.checked;
1079
+ state.openNode("listItem", void 0, {
1080
+ label,
1081
+ listType,
1082
+ spread,
1083
+ checked
1084
+ });
1085
+ state.next(node.content);
1086
+ state.closeNode();
929
1087
  }
930
- const r = l.attrs.label, s = l.attrs.listType, c = l.attrs.spread === "true", d = l.attrs.checked;
931
- o.openNode("listItem", void 0, {
932
- label: r,
933
- listType: s,
934
- spread: c,
935
- checked: d
936
- }), o.next(l.content), o.closeNode();
937
1088
  }
938
- }
1089
+ };
939
1090
  };
940
1091
  }
941
1092
  );
942
- i(ve, {
1093
+ withMeta(extendListItemSchemaForTask, {
943
1094
  displayName: "NodeSchema<listItem>",
944
1095
  group: "ListItem"
945
1096
  });
946
- const _e = F(() => new ne(
947
- /^\[(?<checked>\s|x)\]\s$/,
948
- (e, t, n, o) => {
949
- var a;
950
- const l = e.doc.resolve(n);
951
- let r = 0, s = l.node(r);
952
- for (; s && s.type.name !== "list_item"; )
953
- r--, s = l.node(r);
954
- if (!s || s.attrs.checked != null) return null;
955
- const c = ((a = t.groups) == null ? void 0 : a.checked) === "x", d = l.before(r), p = e.tr;
956
- return p.deleteRange(n, o).setNodeMarkup(d, void 0, {
957
- ...s.attrs,
958
- checked: c
959
- }), p;
960
- }
961
- ));
962
- i(_e, {
1097
+ const wrapInTaskListInputRule = $inputRule(() => {
1098
+ return new InputRule(
1099
+ /^\[(?<checked>\s|x)\]\s$/,
1100
+ (state, match, start, end) => {
1101
+ var _a;
1102
+ const pos = state.doc.resolve(start);
1103
+ let depth = 0;
1104
+ let node = pos.node(depth);
1105
+ while (node && node.type.name !== "list_item") {
1106
+ depth--;
1107
+ node = pos.node(depth);
1108
+ }
1109
+ if (!node || node.attrs.checked != null) return null;
1110
+ const checked = Boolean(((_a = match.groups) == null ? void 0 : _a.checked) === "x");
1111
+ const finPos = pos.before(depth);
1112
+ const tr = state.tr;
1113
+ tr.deleteRange(start, end).setNodeMarkup(finPos, void 0, {
1114
+ ...node.attrs,
1115
+ checked
1116
+ });
1117
+ return tr;
1118
+ }
1119
+ );
1120
+ });
1121
+ withMeta(wrapInTaskListInputRule, {
963
1122
  displayName: "InputRule<wrapInTaskListInputRule>",
964
1123
  group: "ListItem"
965
1124
  });
966
- const dt = [
967
- j,
968
- q
969
- ].flat(), mt = [
970
- Ae,
971
- _e
972
- ], ut = [ie], $e = v(() => et);
973
- i($e, {
1125
+ const keymap = [
1126
+ strikethroughKeymap,
1127
+ tableKeymap
1128
+ ].flat();
1129
+ const inputRules = [
1130
+ insertTableInputRule,
1131
+ wrapInTaskListInputRule
1132
+ ];
1133
+ const markInputRules = [strikethroughInputRule];
1134
+ const autoInsertSpanPlugin = $prose(() => imeSpan);
1135
+ withMeta(autoInsertSpanPlugin, {
974
1136
  displayName: "Prose<autoInsertSpanPlugin>",
975
1137
  group: "Prose"
976
1138
  });
977
- const pt = v(() => Ve({}));
978
- i(pt, {
1139
+ const columnResizingPlugin = $prose(() => columnResizing({}));
1140
+ withMeta(columnResizingPlugin, {
979
1141
  displayName: "Prose<columnResizingPlugin>",
980
1142
  group: "Prose"
981
1143
  });
982
- const Ie = v(
983
- () => Ue({ allowTableNodeSelection: !0 })
1144
+ const tableEditingPlugin = $prose(
1145
+ () => tableEditing({ allowTableNodeSelection: true })
984
1146
  );
985
- i(Ie, {
1147
+ withMeta(tableEditingPlugin, {
986
1148
  displayName: "Prose<tableEditingPlugin>",
987
1149
  group: "Prose"
988
1150
  });
989
- const Y = Be("remarkGFM", () => tt);
990
- i(Y.plugin, {
1151
+ const remarkGFMPlugin = $remark("remarkGFM", () => remarkGFM);
1152
+ withMeta(remarkGFMPlugin.plugin, {
991
1153
  displayName: "Remark<remarkGFMPlugin>",
992
1154
  group: "Remark"
993
1155
  });
994
- i(Y.options, {
1156
+ withMeta(remarkGFMPlugin.options, {
995
1157
  displayName: "RemarkConfig<remarkGFMPlugin>",
996
1158
  group: "Remark"
997
1159
  });
998
- const ft = new Ze("MILKDOWN_KEEP_TABLE_ALIGN_PLUGIN");
999
- function gt(e, t) {
1000
- let n = 0;
1001
- return t.forEach((o, l, r) => {
1002
- o === e && (n = r);
1003
- }), n;
1160
+ const pluginKey = new PluginKey("MILKDOWN_KEEP_TABLE_ALIGN_PLUGIN");
1161
+ function getChildIndex(node, parent) {
1162
+ let index = 0;
1163
+ parent.forEach((child, _offset, i) => {
1164
+ if (child === node) index = i;
1165
+ });
1166
+ return index;
1004
1167
  }
1005
- const Pe = v(() => new Ye({
1006
- key: ft,
1007
- appendTransaction: (e, t, n) => {
1008
- let o;
1009
- const l = (r, s) => {
1010
- if (o || (o = n.tr), r.type.name !== "table_cell") return;
1011
- const c = n.doc.resolve(s), d = c.node(c.depth), a = c.node(c.depth - 1).firstChild;
1012
- if (!a) return;
1013
- const m = gt(r, d), u = a.maybeChild(m);
1014
- if (!u) return;
1015
- const f = u.attrs.alignment, b = r.attrs.alignment;
1016
- f !== b && o.setNodeMarkup(s, void 0, { ...r.attrs, alignment: f });
1017
- };
1018
- return t.doc !== n.doc && n.doc.descendants(l), o;
1019
- }
1020
- }));
1021
- i(Pe, {
1168
+ const keepTableAlignPlugin = $prose(() => {
1169
+ return new Plugin({
1170
+ key: pluginKey,
1171
+ appendTransaction: (_tr, oldState, state) => {
1172
+ let tr;
1173
+ const check = (node, pos) => {
1174
+ if (!tr) tr = state.tr;
1175
+ if (node.type.name !== "table_cell") return;
1176
+ const $pos = state.doc.resolve(pos);
1177
+ const tableRow = $pos.node($pos.depth);
1178
+ const table = $pos.node($pos.depth - 1);
1179
+ const tableHeaderRow = table.firstChild;
1180
+ if (!tableHeaderRow) return;
1181
+ const index = getChildIndex(node, tableRow);
1182
+ const headerCell = tableHeaderRow.maybeChild(index);
1183
+ if (!headerCell) return;
1184
+ const align = headerCell.attrs.alignment;
1185
+ const currentAlign = node.attrs.alignment;
1186
+ if (align === currentAlign) return;
1187
+ tr.setNodeMarkup(pos, void 0, { ...node.attrs, alignment: align });
1188
+ };
1189
+ if (oldState.doc !== state.doc) state.doc.descendants(check);
1190
+ return tr;
1191
+ }
1192
+ });
1193
+ });
1194
+ withMeta(keepTableAlignPlugin, {
1022
1195
  displayName: "Prose<keepTableAlignPlugin>",
1023
1196
  group: "Prose"
1024
1197
  });
1025
- const ht = [
1026
- Pe,
1027
- $e,
1028
- Y,
1029
- Ie
1030
- ].flat(), bt = [
1031
- ve,
1032
- N,
1033
- $,
1034
- R,
1035
- I,
1036
- x,
1037
- J,
1038
- Q,
1039
- W,
1040
- T
1041
- ].flat(), Ct = [
1042
- U,
1043
- V,
1044
- X,
1045
- he,
1046
- be,
1047
- Ce,
1048
- ye,
1049
- we,
1050
- ke,
1051
- Ne,
1052
- Re,
1053
- xe,
1054
- Te,
1055
- Se,
1056
- Me,
1057
- z
1058
- ], _t = [
1059
- bt,
1060
- mt,
1061
- ut,
1062
- dt,
1063
- Ct,
1064
- ht
1198
+ const plugins = [
1199
+ keepTableAlignPlugin,
1200
+ autoInsertSpanPlugin,
1201
+ remarkGFMPlugin,
1202
+ tableEditingPlugin
1203
+ ].flat();
1204
+ const schema = [
1205
+ extendListItemSchemaForTask,
1206
+ tableSchema,
1207
+ tableHeaderRowSchema,
1208
+ tableRowSchema,
1209
+ tableHeaderSchema,
1210
+ tableCellSchema,
1211
+ footnoteDefinitionSchema,
1212
+ footnoteReferenceSchema,
1213
+ strikethroughAttr,
1214
+ strikethroughSchema
1215
+ ].flat();
1216
+ const commands = [
1217
+ goToNextTableCellCommand,
1218
+ goToPrevTableCellCommand,
1219
+ exitTable,
1220
+ insertTableCommand,
1221
+ moveRowCommand,
1222
+ moveColCommand,
1223
+ selectRowCommand,
1224
+ selectColCommand,
1225
+ selectTableCommand,
1226
+ deleteSelectedCellsCommand,
1227
+ addRowBeforeCommand,
1228
+ addRowAfterCommand,
1229
+ addColBeforeCommand,
1230
+ addColAfterCommand,
1231
+ setAlignCommand,
1232
+ toggleStrikethroughCommand
1233
+ ];
1234
+ const gfm = [
1235
+ schema,
1236
+ inputRules,
1237
+ markInputRules,
1238
+ keymap,
1239
+ commands,
1240
+ plugins
1065
1241
  ].flat();
1066
1242
  export {
1067
- Se as addColAfterCommand,
1068
- Te as addColBeforeCommand,
1069
- xe as addRowAfterCommand,
1070
- Re as addRowBeforeCommand,
1071
- me as addRowWithAlignment,
1072
- $e as autoInsertSpanPlugin,
1073
- pt as columnResizingPlugin,
1074
- Ct as commands,
1075
- de as createTable,
1076
- Ne as deleteSelectedCellsCommand,
1077
- X as exitTable,
1078
- ve as extendListItemSchemaForTask,
1079
- M as findTable,
1080
- J as footnoteDefinitionSchema,
1081
- Q as footnoteReferenceSchema,
1082
- ot as getAllCellsInTable,
1083
- y as getCellsInCol,
1084
- w as getCellsInRow,
1085
- _t as gfm,
1086
- U as goToNextTableCellCommand,
1087
- V as goToPrevTableCellCommand,
1088
- mt as inputRules,
1089
- he as insertTableCommand,
1090
- Ae as insertTableInputRule,
1091
- Pe as keepTableAlignPlugin,
1092
- dt as keymap,
1093
- ut as markInputRules,
1094
- ct as moveCol,
1095
- Ce as moveColCommand,
1096
- it as moveRow,
1097
- be as moveRowCommand,
1098
- ht as plugins,
1099
- Y as remarkGFMPlugin,
1100
- bt as schema,
1101
- rt as selectCol,
1102
- we as selectColCommand,
1103
- ue as selectLine,
1104
- lt as selectRow,
1105
- ye as selectRowCommand,
1106
- nt as selectTable,
1107
- ke as selectTableCommand,
1108
- Me as setAlignCommand,
1109
- W as strikethroughAttr,
1110
- ie as strikethroughInputRule,
1111
- j as strikethroughKeymap,
1112
- T as strikethroughSchema,
1113
- x as tableCellSchema,
1114
- Ie as tableEditingPlugin,
1115
- $ as tableHeaderRowSchema,
1116
- I as tableHeaderSchema,
1117
- q as tableKeymap,
1118
- R as tableRowSchema,
1119
- N as tableSchema,
1120
- z as toggleStrikethroughCommand,
1121
- _e as wrapInTaskListInputRule
1243
+ addColAfterCommand,
1244
+ addColBeforeCommand,
1245
+ addRowAfterCommand,
1246
+ addRowBeforeCommand,
1247
+ addRowWithAlignment,
1248
+ autoInsertSpanPlugin,
1249
+ columnResizingPlugin,
1250
+ commands,
1251
+ createTable,
1252
+ deleteSelectedCellsCommand,
1253
+ exitTable,
1254
+ extendListItemSchemaForTask,
1255
+ findTable,
1256
+ footnoteDefinitionSchema,
1257
+ footnoteReferenceSchema,
1258
+ getAllCellsInTable,
1259
+ getCellsInCol,
1260
+ getCellsInRow,
1261
+ gfm,
1262
+ goToNextTableCellCommand,
1263
+ goToPrevTableCellCommand,
1264
+ inputRules,
1265
+ insertTableCommand,
1266
+ insertTableInputRule,
1267
+ keepTableAlignPlugin,
1268
+ keymap,
1269
+ markInputRules,
1270
+ moveCol,
1271
+ moveColCommand,
1272
+ moveRow,
1273
+ moveRowCommand,
1274
+ plugins,
1275
+ remarkGFMPlugin,
1276
+ schema,
1277
+ selectCol,
1278
+ selectColCommand,
1279
+ selectLine,
1280
+ selectRow,
1281
+ selectRowCommand,
1282
+ selectTable,
1283
+ selectTableCommand,
1284
+ setAlignCommand,
1285
+ strikethroughAttr,
1286
+ strikethroughInputRule,
1287
+ strikethroughKeymap,
1288
+ strikethroughSchema,
1289
+ tableCellSchema,
1290
+ tableEditingPlugin,
1291
+ tableHeaderRowSchema,
1292
+ tableHeaderSchema,
1293
+ tableKeymap,
1294
+ tableRowSchema,
1295
+ tableSchema,
1296
+ toggleStrikethroughCommand,
1297
+ wrapInTaskListInputRule
1122
1298
  };
1123
1299
  //# sourceMappingURL=index.es.js.map