@milkdown/preset-gfm 7.19.0 → 7.19.2

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.js CHANGED
@@ -1,1124 +1,1049 @@
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, $command, $inputRule, $useKeymap, $nodeSchema, $pasteRule, $prose, $remark } from "@milkdown/utils";
5
- import { tableNodes, findTable, TableMap, CellSelection, addColumnAfter, addColumnBefore, isInTable, selectedRect, goToNextCell, moveTableRow, moveTableColumn, deleteTable, deleteColumn, deleteRow, setCellAttr, columnResizing, tableEditing } from "@milkdown/prose/tables";
6
1
  import { commandsCtx } from "@milkdown/core";
7
- import { markRule, findParentNodeClosestToPos, cloneTr, findParentNodeType } from "@milkdown/prose";
2
+ import { cloneTr, findParentNodeClosestToPos, findParentNodeType, markRule } from "@milkdown/prose";
8
3
  import { toggleMark } from "@milkdown/prose/commands";
9
- import { Slice, Fragment } from "@milkdown/prose/model";
10
- import { Selection, TextSelection, Plugin, PluginKey } from "@milkdown/prose/state";
4
+ import { $command, $inputRule, $markAttr, $markSchema, $nodeSchema, $pasteRule, $prose, $remark, $useKeymap } from "@milkdown/utils";
5
+ import { CellSelection, TableMap, addColumnAfter, addColumnBefore, columnResizing, deleteColumn, deleteRow, deleteTable, findTable, goToNextCell, isInTable, moveTableColumn, moveTableRow, selectedRect, setCellAttr, tableEditing, tableNodes } from "@milkdown/prose/tables";
6
+ import { listItemSchema, paragraphSchema } from "@milkdown/preset-commonmark";
7
+ import { Plugin, PluginKey, Selection, TextSelection } from "@milkdown/prose/state";
8
+ import { InputRule } from "@milkdown/prose/inputrules";
9
+ import { Fragment, Slice } from "@milkdown/prose/model";
10
+ import { expectDomTypeError } from "@milkdown/exception";
11
11
  import { imeSpan } from "prosemirror-safari-ime-span";
12
12
  import remarkGFM from "remark-gfm";
13
+ //#region src/__internal__/with-meta.ts
13
14
  function withMeta(plugin, meta) {
14
- Object.assign(plugin, {
15
- meta: {
16
- package: "@milkdown/preset-gfm",
17
- ...meta
18
- }
19
- });
20
- return plugin;
15
+ Object.assign(plugin, { meta: {
16
+ package: "@milkdown/preset-gfm",
17
+ ...meta
18
+ } });
19
+ return plugin;
21
20
  }
22
- const strikethroughAttr = $markAttr("strike_through");
21
+ //#endregion
22
+ //#region src/mark/strike-through.ts
23
+ var strikethroughAttr = $markAttr("strike_through");
23
24
  withMeta(strikethroughAttr, {
24
- displayName: "Attr<strikethrough>",
25
- group: "Strikethrough"
26
- });
27
- const strikethroughSchema = $markSchema("strike_through", (ctx) => ({
28
- parseDOM: [
29
- { tag: "del" },
30
- {
31
- style: "text-decoration",
32
- getAttrs: (value) => value === "line-through"
33
- }
34
- ],
35
- toDOM: (mark) => ["del", ctx.get(strikethroughAttr.key)(mark)],
36
- parseMarkdown: {
37
- match: (node) => node.type === "delete",
38
- runner: (state, node, markType) => {
39
- state.openMark(markType);
40
- state.next(node.children);
41
- state.closeMark(markType);
42
- }
43
- },
44
- toMarkdown: {
45
- match: (mark) => mark.type.name === "strike_through",
46
- runner: (state, mark) => {
47
- state.withMark(mark, "delete");
48
- }
49
- }
25
+ displayName: "Attr<strikethrough>",
26
+ group: "Strikethrough"
27
+ });
28
+ var strikethroughSchema = $markSchema("strike_through", (ctx) => ({
29
+ parseDOM: [{ tag: "del" }, {
30
+ style: "text-decoration",
31
+ getAttrs: (value) => value === "line-through"
32
+ }],
33
+ toDOM: (mark) => ["del", ctx.get(strikethroughAttr.key)(mark)],
34
+ parseMarkdown: {
35
+ match: (node) => node.type === "delete",
36
+ runner: (state, node, markType) => {
37
+ state.openMark(markType);
38
+ state.next(node.children);
39
+ state.closeMark(markType);
40
+ }
41
+ },
42
+ toMarkdown: {
43
+ match: (mark) => mark.type.name === "strike_through",
44
+ runner: (state, mark) => {
45
+ state.withMark(mark, "delete");
46
+ }
47
+ }
50
48
  }));
51
49
  withMeta(strikethroughSchema.mark, {
52
- displayName: "MarkSchema<strikethrough>",
53
- group: "Strikethrough"
50
+ displayName: "MarkSchema<strikethrough>",
51
+ group: "Strikethrough"
54
52
  });
55
53
  withMeta(strikethroughSchema.ctx, {
56
- displayName: "MarkSchemaCtx<strikethrough>",
57
- group: "Strikethrough"
58
- });
59
- const toggleStrikethroughCommand = $command(
60
- "ToggleStrikeThrough",
61
- (ctx) => () => {
62
- return toggleMark(strikethroughSchema.type(ctx));
63
- }
64
- );
54
+ displayName: "MarkSchemaCtx<strikethrough>",
55
+ group: "Strikethrough"
56
+ });
57
+ var toggleStrikethroughCommand = $command("ToggleStrikeThrough", (ctx) => () => {
58
+ return toggleMark(strikethroughSchema.type(ctx));
59
+ });
65
60
  withMeta(toggleStrikethroughCommand, {
66
- displayName: "Command<ToggleStrikethrough>",
67
- group: "Strikethrough"
61
+ displayName: "Command<ToggleStrikethrough>",
62
+ group: "Strikethrough"
68
63
  });
69
- const strikethroughInputRule = $inputRule((ctx) => {
70
- return markRule(
71
- new RegExp("(?<![\\w:/])(~{1,2})(.+?)\\1(?!\\w|\\/)"),
72
- strikethroughSchema.type(ctx)
73
- );
64
+ var strikethroughInputRule = $inputRule((ctx) => {
65
+ return markRule(/(?<![\w:/])(~{1,2})(.+?)\1(?!\w|\/)/, strikethroughSchema.type(ctx));
74
66
  });
75
67
  withMeta(strikethroughInputRule, {
76
- displayName: "InputRule<strikethrough>",
77
- group: "Strikethrough"
78
- });
79
- const strikethroughKeymap = $useKeymap("strikeThroughKeymap", {
80
- ToggleStrikethrough: {
81
- shortcuts: "Mod-Alt-x",
82
- command: (ctx) => {
83
- const commands2 = ctx.get(commandsCtx);
84
- return () => commands2.call(toggleStrikethroughCommand.key);
85
- }
86
- }
68
+ displayName: "InputRule<strikethrough>",
69
+ group: "Strikethrough"
87
70
  });
71
+ var strikethroughKeymap = $useKeymap("strikeThroughKeymap", { ToggleStrikethrough: {
72
+ shortcuts: "Mod-Alt-x",
73
+ command: (ctx) => {
74
+ const commands = ctx.get(commandsCtx);
75
+ return () => commands.call(toggleStrikethroughCommand.key);
76
+ }
77
+ } });
88
78
  withMeta(strikethroughKeymap.ctx, {
89
- displayName: "KeymapCtx<strikethrough>",
90
- group: "Strikethrough"
79
+ displayName: "KeymapCtx<strikethrough>",
80
+ group: "Strikethrough"
91
81
  });
92
82
  withMeta(strikethroughKeymap.shortcuts, {
93
- displayName: "Keymap<strikethrough>",
94
- group: "Strikethrough"
95
- });
96
- const originalSchema = tableNodes({
97
- tableGroup: "block",
98
- cellContent: "paragraph",
99
- cellAttributes: {
100
- alignment: {
101
- default: "left",
102
- getFromDOM: (dom) => dom.style.textAlign || "left",
103
- setDOMAttr: (value, attrs) => {
104
- attrs.style = `text-align: ${value || "left"}`;
105
- }
106
- }
107
- }
108
- });
109
- const tableSchema = $nodeSchema("table", () => ({
110
- ...originalSchema.table,
111
- content: "table_header_row table_row+",
112
- disableDropCursor: true,
113
- parseMarkdown: {
114
- match: (node) => node.type === "table",
115
- runner: (state, node, type) => {
116
- const align = node.align;
117
- const children = node.children.map((x, i) => ({
118
- ...x,
119
- align,
120
- isHeader: i === 0
121
- }));
122
- state.openNode(type);
123
- state.next(children);
124
- state.closeNode();
125
- }
126
- },
127
- toMarkdown: {
128
- match: (node) => node.type.name === "table",
129
- runner: (state, node) => {
130
- const firstLine = node.content.firstChild?.content;
131
- if (!firstLine) return;
132
- const align = [];
133
- firstLine.forEach((cell) => {
134
- align.push(cell.attrs.alignment);
135
- });
136
- state.openNode("table", void 0, { align });
137
- state.next(node.content);
138
- state.closeNode();
139
- }
140
- }
83
+ displayName: "Keymap<strikethrough>",
84
+ group: "Strikethrough"
85
+ });
86
+ //#endregion
87
+ //#region src/node/table/schema.ts
88
+ var originalSchema = tableNodes({
89
+ tableGroup: "block",
90
+ cellContent: "paragraph",
91
+ cellAttributes: { alignment: {
92
+ default: "left",
93
+ getFromDOM: (dom) => dom.style.textAlign || "left",
94
+ setDOMAttr: (value, attrs) => {
95
+ attrs.style = `text-align: ${value || "left"}`;
96
+ }
97
+ } }
98
+ });
99
+ var tableSchema = $nodeSchema("table", () => ({
100
+ ...originalSchema.table,
101
+ content: "table_header_row table_row+",
102
+ disableDropCursor: true,
103
+ parseMarkdown: {
104
+ match: (node) => node.type === "table",
105
+ runner: (state, node, type) => {
106
+ const align = node.align;
107
+ const children = node.children.map((x, i) => ({
108
+ ...x,
109
+ align,
110
+ isHeader: i === 0
111
+ }));
112
+ state.openNode(type);
113
+ state.next(children);
114
+ state.closeNode();
115
+ }
116
+ },
117
+ toMarkdown: {
118
+ match: (node) => node.type.name === "table",
119
+ runner: (state, node) => {
120
+ const firstLine = node.content.firstChild?.content;
121
+ if (!firstLine) return;
122
+ const align = [];
123
+ firstLine.forEach((cell) => {
124
+ align.push(cell.attrs.alignment);
125
+ });
126
+ state.openNode("table", void 0, { align });
127
+ state.next(node.content);
128
+ state.closeNode();
129
+ }
130
+ }
141
131
  }));
142
132
  withMeta(tableSchema.node, {
143
- displayName: "NodeSchema<table>",
144
- group: "Table"
133
+ displayName: "NodeSchema<table>",
134
+ group: "Table"
145
135
  });
146
136
  withMeta(tableSchema.ctx, {
147
- displayName: "NodeSchemaCtx<table>",
148
- group: "Table"
149
- });
150
- const tableHeaderRowSchema = $nodeSchema("table_header_row", () => ({
151
- ...originalSchema.table_row,
152
- disableDropCursor: true,
153
- content: "(table_header)*",
154
- parseDOM: [
155
- { tag: "tr[data-is-header]" },
156
- {
157
- tag: "tr",
158
- getAttrs: (dom) => {
159
- if (dom instanceof HTMLElement) {
160
- const hasHeader = dom.querySelector("th");
161
- return hasHeader ? {} : false;
162
- }
163
- return false;
164
- }
165
- }
166
- ],
167
- toDOM() {
168
- return ["tr", { "data-is-header": true }, 0];
169
- },
170
- parseMarkdown: {
171
- match: (node) => Boolean(node.type === "tableRow" && node.isHeader),
172
- runner: (state, node, type) => {
173
- const align = node.align;
174
- const children = node.children.map((x, i) => ({
175
- ...x,
176
- align: align[i],
177
- isHeader: node.isHeader
178
- }));
179
- state.openNode(type);
180
- state.next(children);
181
- state.closeNode();
182
- }
183
- },
184
- toMarkdown: {
185
- match: (node) => node.type.name === "table_header_row",
186
- runner: (state, node) => {
187
- state.openNode("tableRow", void 0, { isHeader: true });
188
- state.next(node.content);
189
- state.closeNode();
190
- }
191
- }
137
+ displayName: "NodeSchemaCtx<table>",
138
+ group: "Table"
139
+ });
140
+ var tableHeaderRowSchema = $nodeSchema("table_header_row", () => ({
141
+ ...originalSchema.table_row,
142
+ disableDropCursor: true,
143
+ content: "(table_header)*",
144
+ parseDOM: [{ tag: "tr[data-is-header]" }, {
145
+ tag: "tr",
146
+ getAttrs: (dom) => {
147
+ if (dom instanceof HTMLElement) return dom.querySelector("th") ? {} : false;
148
+ return false;
149
+ }
150
+ }],
151
+ toDOM() {
152
+ return [
153
+ "tr",
154
+ { "data-is-header": true },
155
+ 0
156
+ ];
157
+ },
158
+ parseMarkdown: {
159
+ match: (node) => Boolean(node.type === "tableRow" && node.isHeader),
160
+ runner: (state, node, type) => {
161
+ const align = node.align;
162
+ const children = node.children.map((x, i) => ({
163
+ ...x,
164
+ align: align[i],
165
+ isHeader: node.isHeader
166
+ }));
167
+ state.openNode(type);
168
+ state.next(children);
169
+ state.closeNode();
170
+ }
171
+ },
172
+ toMarkdown: {
173
+ match: (node) => node.type.name === "table_header_row",
174
+ runner: (state, node) => {
175
+ if (node.content.size === 0) return;
176
+ state.openNode("tableRow", void 0, { isHeader: true });
177
+ state.next(node.content);
178
+ state.closeNode();
179
+ }
180
+ }
192
181
  }));
193
182
  withMeta(tableHeaderRowSchema.node, {
194
- displayName: "NodeSchema<tableHeaderRow>",
195
- group: "Table"
183
+ displayName: "NodeSchema<tableHeaderRow>",
184
+ group: "Table"
196
185
  });
197
186
  withMeta(tableHeaderRowSchema.ctx, {
198
- displayName: "NodeSchemaCtx<tableHeaderRow>",
199
- group: "Table"
200
- });
201
- const tableRowSchema = $nodeSchema("table_row", () => ({
202
- ...originalSchema.table_row,
203
- disableDropCursor: true,
204
- content: "(table_cell)*",
205
- parseMarkdown: {
206
- match: (node) => node.type === "tableRow",
207
- runner: (state, node, type) => {
208
- const align = node.align;
209
- const children = node.children.map((x, i) => ({
210
- ...x,
211
- align: align[i]
212
- }));
213
- state.openNode(type);
214
- state.next(children);
215
- state.closeNode();
216
- }
217
- },
218
- toMarkdown: {
219
- match: (node) => node.type.name === "table_row",
220
- runner: (state, node) => {
221
- if (node.content.size === 0) {
222
- return;
223
- }
224
- state.openNode("tableRow");
225
- state.next(node.content);
226
- state.closeNode();
227
- }
228
- }
187
+ displayName: "NodeSchemaCtx<tableHeaderRow>",
188
+ group: "Table"
189
+ });
190
+ var tableRowSchema = $nodeSchema("table_row", () => ({
191
+ ...originalSchema.table_row,
192
+ disableDropCursor: true,
193
+ content: "(table_cell)*",
194
+ parseMarkdown: {
195
+ match: (node) => node.type === "tableRow",
196
+ runner: (state, node, type) => {
197
+ const align = node.align;
198
+ const children = node.children.map((x, i) => ({
199
+ ...x,
200
+ align: align[i]
201
+ }));
202
+ state.openNode(type);
203
+ state.next(children);
204
+ state.closeNode();
205
+ }
206
+ },
207
+ toMarkdown: {
208
+ match: (node) => node.type.name === "table_row",
209
+ runner: (state, node) => {
210
+ if (node.content.size === 0) return;
211
+ state.openNode("tableRow");
212
+ state.next(node.content);
213
+ state.closeNode();
214
+ }
215
+ }
229
216
  }));
230
217
  withMeta(tableRowSchema.node, {
231
- displayName: "NodeSchema<tableRow>",
232
- group: "Table"
218
+ displayName: "NodeSchema<tableRow>",
219
+ group: "Table"
233
220
  });
234
221
  withMeta(tableRowSchema.ctx, {
235
- displayName: "NodeSchemaCtx<tableRow>",
236
- group: "Table"
237
- });
238
- const tableCellSchema = $nodeSchema("table_cell", () => ({
239
- ...originalSchema.table_cell,
240
- disableDropCursor: true,
241
- parseMarkdown: {
242
- match: (node) => node.type === "tableCell" && !node.isHeader,
243
- runner: (state, node, type) => {
244
- const align = node.align;
245
- state.openNode(type, { alignment: align }).openNode(state.schema.nodes.paragraph).next(node.children).closeNode().closeNode();
246
- }
247
- },
248
- toMarkdown: {
249
- match: (node) => node.type.name === "table_cell",
250
- runner: (state, node) => {
251
- state.openNode("tableCell").next(node.content).closeNode();
252
- }
253
- }
222
+ displayName: "NodeSchemaCtx<tableRow>",
223
+ group: "Table"
224
+ });
225
+ var tableCellSchema = $nodeSchema("table_cell", () => ({
226
+ ...originalSchema.table_cell,
227
+ disableDropCursor: true,
228
+ parseMarkdown: {
229
+ match: (node) => node.type === "tableCell" && !node.isHeader,
230
+ runner: (state, node, type) => {
231
+ const align = node.align;
232
+ state.openNode(type, { alignment: align }).openNode(state.schema.nodes.paragraph).next(node.children).closeNode().closeNode();
233
+ }
234
+ },
235
+ toMarkdown: {
236
+ match: (node) => node.type.name === "table_cell",
237
+ runner: (state, node) => {
238
+ state.openNode("tableCell").next(node.content).closeNode();
239
+ }
240
+ }
254
241
  }));
255
242
  withMeta(tableCellSchema.node, {
256
- displayName: "NodeSchema<tableCell>",
257
- group: "Table"
243
+ displayName: "NodeSchema<tableCell>",
244
+ group: "Table"
258
245
  });
259
246
  withMeta(tableCellSchema.ctx, {
260
- displayName: "NodeSchemaCtx<tableCell>",
261
- group: "Table"
262
- });
263
- const tableHeaderSchema = $nodeSchema("table_header", () => ({
264
- ...originalSchema.table_header,
265
- disableDropCursor: true,
266
- parseMarkdown: {
267
- match: (node) => node.type === "tableCell" && !!node.isHeader,
268
- runner: (state, node, type) => {
269
- const align = node.align;
270
- state.openNode(type, { alignment: align });
271
- state.openNode(state.schema.nodes.paragraph);
272
- state.next(node.children);
273
- state.closeNode();
274
- state.closeNode();
275
- }
276
- },
277
- toMarkdown: {
278
- match: (node) => node.type.name === "table_header",
279
- runner: (state, node) => {
280
- state.openNode("tableCell");
281
- state.next(node.content);
282
- state.closeNode();
283
- }
284
- }
247
+ displayName: "NodeSchemaCtx<tableCell>",
248
+ group: "Table"
249
+ });
250
+ var tableHeaderSchema = $nodeSchema("table_header", () => ({
251
+ ...originalSchema.table_header,
252
+ disableDropCursor: true,
253
+ parseMarkdown: {
254
+ match: (node) => node.type === "tableCell" && !!node.isHeader,
255
+ runner: (state, node, type) => {
256
+ const align = node.align;
257
+ state.openNode(type, { alignment: align });
258
+ state.openNode(state.schema.nodes.paragraph);
259
+ state.next(node.children);
260
+ state.closeNode();
261
+ state.closeNode();
262
+ }
263
+ },
264
+ toMarkdown: {
265
+ match: (node) => node.type.name === "table_header",
266
+ runner: (state, node) => {
267
+ state.openNode("tableCell");
268
+ state.next(node.content);
269
+ state.closeNode();
270
+ }
271
+ }
285
272
  }));
286
273
  withMeta(tableHeaderSchema.node, {
287
- displayName: "NodeSchema<tableHeader>",
288
- group: "Table"
274
+ displayName: "NodeSchema<tableHeader>",
275
+ group: "Table"
289
276
  });
290
277
  withMeta(tableHeaderSchema.ctx, {
291
- displayName: "NodeSchemaCtx<tableHeader>",
292
- group: "Table"
278
+ displayName: "NodeSchemaCtx<tableHeader>",
279
+ group: "Table"
293
280
  });
281
+ //#endregion
282
+ //#region src/node/table/utils/create-table.ts
294
283
  function createTable(ctx, rowsCount = 3, colsCount = 3) {
295
- const cells = Array(colsCount).fill(0).map(() => tableCellSchema.type(ctx).createAndFill());
296
- const headerCells = Array(colsCount).fill(0).map(() => tableHeaderSchema.type(ctx).createAndFill());
297
- const rows = Array(rowsCount).fill(0).map(
298
- (_, i) => i === 0 ? tableHeaderRowSchema.type(ctx).create(null, headerCells) : tableRowSchema.type(ctx).create(null, cells)
299
- );
300
- return tableSchema.type(ctx).create(null, rows);
284
+ const cells = Array(colsCount).fill(0).map(() => tableCellSchema.type(ctx).createAndFill());
285
+ const headerCells = Array(colsCount).fill(0).map(() => tableHeaderSchema.type(ctx).createAndFill());
286
+ const rows = Array(rowsCount).fill(0).map((_, i) => i === 0 ? tableHeaderRowSchema.type(ctx).create(null, headerCells) : tableRowSchema.type(ctx).create(null, cells));
287
+ return tableSchema.type(ctx).create(null, rows);
301
288
  }
289
+ //#endregion
290
+ //#region src/node/table/utils/get-cells-in-col.ts
302
291
  function getCellsInCol(columnIndexes, selection) {
303
- const table = findTable(selection.$from);
304
- if (!table) return void 0;
305
- const map = TableMap.get(table.node);
306
- const indexes = Array.isArray(columnIndexes) ? columnIndexes : [columnIndexes];
307
- return indexes.filter((index) => index >= 0 && index <= map.width - 1).flatMap((index) => {
308
- const cells = map.cellsInRect({
309
- left: index,
310
- right: index + 1,
311
- top: 0,
312
- bottom: map.height
313
- });
314
- return cells.map((nodePos) => {
315
- const node = table.node.nodeAt(nodePos);
316
- const pos = nodePos + table.start;
317
- return { pos, start: pos + 1, node, depth: table.depth + 2 };
318
- });
319
- });
292
+ const table = findTable(selection.$from);
293
+ if (!table) return void 0;
294
+ const map = TableMap.get(table.node);
295
+ return (Array.isArray(columnIndexes) ? columnIndexes : [columnIndexes]).filter((index) => index >= 0 && index <= map.width - 1).flatMap((index) => {
296
+ return map.cellsInRect({
297
+ left: index,
298
+ right: index + 1,
299
+ top: 0,
300
+ bottom: map.height
301
+ }).map((nodePos) => {
302
+ const node = table.node.nodeAt(nodePos);
303
+ const pos = nodePos + table.start;
304
+ return {
305
+ pos,
306
+ start: pos + 1,
307
+ node,
308
+ depth: table.depth + 2
309
+ };
310
+ });
311
+ });
320
312
  }
313
+ //#endregion
314
+ //#region src/node/table/utils/get-cells-in-row.ts
321
315
  function getCellsInRow(rowIndex, selection) {
322
- const table = findTable(selection.$from);
323
- if (!table) {
324
- return;
325
- }
326
- const map = TableMap.get(table.node);
327
- const indexes = Array.isArray(rowIndex) ? rowIndex : [rowIndex];
328
- return indexes.filter((index) => index >= 0 && index <= map.height - 1).flatMap((index) => {
329
- const cells = map.cellsInRect({
330
- left: 0,
331
- right: map.width,
332
- top: index,
333
- bottom: index + 1
334
- });
335
- return cells.map((nodePos) => {
336
- const node = table.node.nodeAt(nodePos);
337
- const pos = nodePos + table.start;
338
- return { pos, start: pos + 1, node, depth: table.depth + 2 };
339
- });
340
- });
316
+ const table = findTable(selection.$from);
317
+ if (!table) return;
318
+ const map = TableMap.get(table.node);
319
+ return (Array.isArray(rowIndex) ? rowIndex : [rowIndex]).filter((index) => index >= 0 && index <= map.height - 1).flatMap((index) => {
320
+ return map.cellsInRect({
321
+ left: 0,
322
+ right: map.width,
323
+ top: index,
324
+ bottom: index + 1
325
+ }).map((nodePos) => {
326
+ const node = table.node.nodeAt(nodePos);
327
+ const pos = nodePos + table.start;
328
+ return {
329
+ pos,
330
+ start: pos + 1,
331
+ node,
332
+ depth: table.depth + 2
333
+ };
334
+ });
335
+ });
341
336
  }
337
+ //#endregion
338
+ //#region src/node/table/utils/select-line.ts
342
339
  function selectLine(type) {
343
- return (index, pos) => (tr) => {
344
- pos = pos ?? tr.selection.from;
345
- const $pos = tr.doc.resolve(pos);
346
- const $node = findParentNodeClosestToPos(
347
- (node) => node.type.name === "table"
348
- )($pos);
349
- const table = $node ? {
350
- node: $node.node,
351
- from: $node.start
352
- } : void 0;
353
- const isRowSelection = type === "row";
354
- if (table) {
355
- const map = TableMap.get(table.node);
356
- if (index >= 0 && index < (isRowSelection ? map.height : map.width)) {
357
- const lastCell = map.positionAt(
358
- isRowSelection ? index : map.height - 1,
359
- isRowSelection ? map.width - 1 : index,
360
- table.node
361
- );
362
- const $lastCell = tr.doc.resolve(table.from + lastCell);
363
- const createCellSelection = isRowSelection ? CellSelection.rowSelection : CellSelection.colSelection;
364
- const firstCell = map.positionAt(
365
- isRowSelection ? index : 0,
366
- isRowSelection ? 0 : index,
367
- table.node
368
- );
369
- const $firstCell = tr.doc.resolve(table.from + firstCell);
370
- return cloneTr(
371
- tr.setSelection(
372
- createCellSelection($lastCell, $firstCell)
373
- )
374
- );
375
- }
376
- }
377
- return tr;
378
- };
340
+ return (index, pos) => (tr) => {
341
+ pos = pos ?? tr.selection.from;
342
+ const $pos = tr.doc.resolve(pos);
343
+ const $node = findParentNodeClosestToPos((node) => node.type.name === "table")($pos);
344
+ const table = $node ? {
345
+ node: $node.node,
346
+ from: $node.start
347
+ } : void 0;
348
+ const isRowSelection = type === "row";
349
+ if (table) {
350
+ const map = TableMap.get(table.node);
351
+ if (index >= 0 && index < (isRowSelection ? map.height : map.width)) {
352
+ const lastCell = map.positionAt(isRowSelection ? index : map.height - 1, isRowSelection ? map.width - 1 : index, table.node);
353
+ const $lastCell = tr.doc.resolve(table.from + lastCell);
354
+ const createCellSelection = isRowSelection ? CellSelection.rowSelection : CellSelection.colSelection;
355
+ const firstCell = map.positionAt(isRowSelection ? index : 0, isRowSelection ? 0 : index, table.node);
356
+ const $firstCell = tr.doc.resolve(table.from + firstCell);
357
+ return cloneTr(tr.setSelection(createCellSelection($lastCell, $firstCell)));
358
+ }
359
+ }
360
+ return tr;
361
+ };
379
362
  }
380
- const selectRow = selectLine("row");
381
- const selectCol = selectLine("col");
363
+ var selectRow = selectLine("row");
364
+ var selectCol = selectLine("col");
365
+ //#endregion
366
+ //#region src/node/table/utils/add-row-with-alignment.ts
382
367
  function addRowWithAlignment(ctx, tr, { map, tableStart, table }, row) {
383
- const rowPos = Array(row).fill(0).reduce((acc, _, i) => {
384
- return acc + table.child(i).nodeSize;
385
- }, tableStart);
386
- const cells = Array(map.width).fill(0).map((_, col) => {
387
- const headerCol = table.nodeAt(map.map[col]);
388
- return tableCellSchema.type(ctx).createAndFill({ alignment: headerCol?.attrs.alignment });
389
- });
390
- tr.insert(rowPos, tableRowSchema.type(ctx).create(null, cells));
391
- return tr;
368
+ const rowPos = Array(row).fill(0).reduce((acc, _, i) => {
369
+ return acc + table.child(i).nodeSize;
370
+ }, tableStart);
371
+ const cells = Array(map.width).fill(0).map((_, col) => {
372
+ const headerCol = table.nodeAt(map.map[col]);
373
+ return tableCellSchema.type(ctx).createAndFill({ alignment: headerCol?.attrs.alignment });
374
+ });
375
+ tr.insert(rowPos, tableRowSchema.type(ctx).create(null, cells));
376
+ return tr;
392
377
  }
378
+ //#endregion
379
+ //#region src/node/table/utils/get-all-cells-in-table.ts
393
380
  function getAllCellsInTable(selection) {
394
- const table = findTable(selection.$from);
395
- if (!table) return;
396
- const map = TableMap.get(table.node);
397
- const cells = map.cellsInRect({
398
- left: 0,
399
- right: map.width,
400
- top: 0,
401
- bottom: map.height
402
- });
403
- return cells.map((nodePos) => {
404
- const node = table.node.nodeAt(nodePos);
405
- const pos = nodePos + table.start;
406
- return { pos, start: pos + 1, node };
407
- });
381
+ const table = findTable(selection.$from);
382
+ if (!table) return;
383
+ const map = TableMap.get(table.node);
384
+ return map.cellsInRect({
385
+ left: 0,
386
+ right: map.width,
387
+ top: 0,
388
+ bottom: map.height
389
+ }).map((nodePos) => {
390
+ const node = table.node.nodeAt(nodePos);
391
+ const pos = nodePos + table.start;
392
+ return {
393
+ pos,
394
+ start: pos + 1,
395
+ node
396
+ };
397
+ });
408
398
  }
399
+ //#endregion
400
+ //#region src/node/table/utils/select-table.ts
409
401
  function selectTable(tr) {
410
- const cells = getAllCellsInTable(tr.selection);
411
- if (cells && cells[0]) {
412
- const $firstCell = tr.doc.resolve(cells[0].pos);
413
- const last = cells[cells.length - 1];
414
- if (last) {
415
- const $lastCell = tr.doc.resolve(last.pos);
416
- return cloneTr(tr.setSelection(new CellSelection($lastCell, $firstCell)));
417
- }
418
- }
419
- return tr;
402
+ const cells = getAllCellsInTable(tr.selection);
403
+ if (cells && cells[0]) {
404
+ const $firstCell = tr.doc.resolve(cells[0].pos);
405
+ const last = cells[cells.length - 1];
406
+ if (last) {
407
+ const $lastCell = tr.doc.resolve(last.pos);
408
+ return cloneTr(tr.setSelection(new CellSelection($lastCell, $firstCell)));
409
+ }
410
+ }
411
+ return tr;
420
412
  }
421
- const goToPrevTableCellCommand = $command(
422
- "GoToPrevTableCell",
423
- () => () => goToNextCell(-1)
424
- );
413
+ //#endregion
414
+ //#region src/node/table/command.ts
415
+ var goToPrevTableCellCommand = $command("GoToPrevTableCell", () => () => goToNextCell(-1));
425
416
  withMeta(goToPrevTableCellCommand, {
426
- displayName: "Command<goToPrevTableCellCommand>",
427
- group: "Table"
417
+ displayName: "Command<goToPrevTableCellCommand>",
418
+ group: "Table"
428
419
  });
429
- const goToNextTableCellCommand = $command(
430
- "GoToNextTableCell",
431
- () => () => goToNextCell(1)
432
- );
420
+ var goToNextTableCellCommand = $command("GoToNextTableCell", () => () => goToNextCell(1));
433
421
  withMeta(goToNextTableCellCommand, {
434
- displayName: "Command<goToNextTableCellCommand>",
435
- group: "Table"
436
- });
437
- const exitTable = $command(
438
- "ExitTable",
439
- (ctx) => () => (state, dispatch) => {
440
- if (!isInTable(state)) return false;
441
- const { $head } = state.selection;
442
- const table = findParentNodeType($head, tableSchema.type(ctx));
443
- if (!table) return false;
444
- const { to } = table;
445
- const tr = state.tr.replaceWith(
446
- to,
447
- to,
448
- paragraphSchema.type(ctx).createAndFill()
449
- );
450
- tr.setSelection(Selection.near(tr.doc.resolve(to), 1)).scrollIntoView();
451
- dispatch?.(tr);
452
- return true;
453
- }
454
- );
422
+ displayName: "Command<goToNextTableCellCommand>",
423
+ group: "Table"
424
+ });
425
+ var exitTable = $command("ExitTable", (ctx) => () => (state, dispatch) => {
426
+ if (!isInTable(state)) return false;
427
+ const { $head } = state.selection;
428
+ const table = findParentNodeType($head, tableSchema.type(ctx));
429
+ if (!table) return false;
430
+ const { to } = table;
431
+ const tr = state.tr.replaceWith(to, to, paragraphSchema.type(ctx).createAndFill());
432
+ tr.setSelection(Selection.near(tr.doc.resolve(to), 1)).scrollIntoView();
433
+ dispatch?.(tr);
434
+ return true;
435
+ });
455
436
  withMeta(exitTable, {
456
- displayName: "Command<breakTableCommand>",
457
- group: "Table"
458
- });
459
- const insertTableCommand = $command(
460
- "InsertTable",
461
- (ctx) => ({ row, col } = {}) => (state, dispatch) => {
462
- const { selection, tr } = state;
463
- const { from } = selection;
464
- const table = createTable(ctx, row, col);
465
- const _tr = tr.replaceSelectionWith(table);
466
- const sel = Selection.findFrom(_tr.doc.resolve(from), 1, true);
467
- if (sel) _tr.setSelection(sel);
468
- dispatch?.(_tr);
469
- return true;
470
- }
471
- );
437
+ displayName: "Command<breakTableCommand>",
438
+ group: "Table"
439
+ });
440
+ var insertTableCommand = $command("InsertTable", (ctx) => ({ row, col } = {}) => (state, dispatch) => {
441
+ const { selection, tr } = state;
442
+ const { from } = selection;
443
+ const table = createTable(ctx, row, col);
444
+ const _tr = tr.replaceSelectionWith(table);
445
+ const sel = Selection.findFrom(_tr.doc.resolve(from), 1, true);
446
+ if (sel) _tr.setSelection(sel);
447
+ dispatch?.(_tr);
448
+ return true;
449
+ });
472
450
  withMeta(insertTableCommand, {
473
- displayName: "Command<insertTableCommand>",
474
- group: "Table"
475
- });
476
- const moveRowCommand = $command(
477
- "MoveRow",
478
- () => ({ from, to, pos } = {}) => moveTableRow({
479
- from: from ?? 0,
480
- to: to ?? 0,
481
- pos
482
- })
483
- );
451
+ displayName: "Command<insertTableCommand>",
452
+ group: "Table"
453
+ });
454
+ var moveRowCommand = $command("MoveRow", () => ({ from, to, pos } = {}) => moveTableRow({
455
+ from: from ?? 0,
456
+ to: to ?? 0,
457
+ pos
458
+ }));
484
459
  withMeta(moveRowCommand, {
485
- displayName: "Command<moveRowCommand>",
486
- group: "Table"
487
- });
488
- const moveColCommand = $command(
489
- "MoveCol",
490
- () => ({ from, to, pos } = {}) => moveTableColumn({
491
- from: from ?? 0,
492
- to: to ?? 0,
493
- pos
494
- })
495
- );
460
+ displayName: "Command<moveRowCommand>",
461
+ group: "Table"
462
+ });
463
+ var moveColCommand = $command("MoveCol", () => ({ from, to, pos } = {}) => moveTableColumn({
464
+ from: from ?? 0,
465
+ to: to ?? 0,
466
+ pos
467
+ }));
496
468
  withMeta(moveColCommand, {
497
- displayName: "Command<moveColCommand>",
498
- group: "Table"
499
- });
500
- const selectRowCommand = $command(
501
- "SelectRow",
502
- () => (payload = { index: 0 }) => (state, dispatch) => {
503
- const { tr } = state;
504
- const result = dispatch?.(selectRow(payload.index, payload.pos)(tr));
505
- return Boolean(result);
506
- }
507
- );
469
+ displayName: "Command<moveColCommand>",
470
+ group: "Table"
471
+ });
472
+ var selectRowCommand = $command("SelectRow", () => (payload = { index: 0 }) => (state, dispatch) => {
473
+ const { tr } = state;
474
+ const result = dispatch?.(selectRow(payload.index, payload.pos)(tr));
475
+ return Boolean(result);
476
+ });
508
477
  withMeta(selectRowCommand, {
509
- displayName: "Command<selectRowCommand>",
510
- group: "Table"
511
- });
512
- const selectColCommand = $command(
513
- "SelectCol",
514
- () => (payload = { index: 0 }) => (state, dispatch) => {
515
- const { tr } = state;
516
- const result = dispatch?.(selectCol(payload.index, payload.pos)(tr));
517
- return Boolean(result);
518
- }
519
- );
478
+ displayName: "Command<selectRowCommand>",
479
+ group: "Table"
480
+ });
481
+ var selectColCommand = $command("SelectCol", () => (payload = { index: 0 }) => (state, dispatch) => {
482
+ const { tr } = state;
483
+ const result = dispatch?.(selectCol(payload.index, payload.pos)(tr));
484
+ return Boolean(result);
485
+ });
520
486
  withMeta(selectColCommand, {
521
- displayName: "Command<selectColCommand>",
522
- group: "Table"
523
- });
524
- const selectTableCommand = $command(
525
- "SelectTable",
526
- () => () => (state, dispatch) => {
527
- const { tr } = state;
528
- const result = dispatch?.(selectTable(tr));
529
- return Boolean(result);
530
- }
531
- );
487
+ displayName: "Command<selectColCommand>",
488
+ group: "Table"
489
+ });
490
+ var selectTableCommand = $command("SelectTable", () => () => (state, dispatch) => {
491
+ const { tr } = state;
492
+ const result = dispatch?.(selectTable(tr));
493
+ return Boolean(result);
494
+ });
532
495
  withMeta(selectTableCommand, {
533
- displayName: "Command<selectTableCommand>",
534
- group: "Table"
535
- });
536
- const deleteSelectedCellsCommand = $command(
537
- "DeleteSelectedCells",
538
- () => () => (state, dispatch) => {
539
- const { selection } = state;
540
- if (!(selection instanceof CellSelection)) return false;
541
- const isRow = selection.isRowSelection();
542
- const isCol = selection.isColSelection();
543
- if (isRow && isCol) return deleteTable(state, dispatch);
544
- if (isCol) return deleteColumn(state, dispatch);
545
- else return deleteRow(state, dispatch);
546
- }
547
- );
496
+ displayName: "Command<selectTableCommand>",
497
+ group: "Table"
498
+ });
499
+ var deleteSelectedCellsCommand = $command("DeleteSelectedCells", () => () => (state, dispatch) => {
500
+ const { selection } = state;
501
+ if (!(selection instanceof CellSelection)) return false;
502
+ const isRow = selection.isRowSelection();
503
+ const isCol = selection.isColSelection();
504
+ if (isRow && isCol) return deleteTable(state, dispatch);
505
+ if (isCol) return deleteColumn(state, dispatch);
506
+ else return deleteRow(state, dispatch);
507
+ });
548
508
  withMeta(deleteSelectedCellsCommand, {
549
- displayName: "Command<deleteSelectedCellsCommand>",
550
- group: "Table"
509
+ displayName: "Command<deleteSelectedCellsCommand>",
510
+ group: "Table"
551
511
  });
552
- const addColBeforeCommand = $command(
553
- "AddColBefore",
554
- () => () => addColumnBefore
555
- );
512
+ var addColBeforeCommand = $command("AddColBefore", () => () => addColumnBefore);
556
513
  withMeta(addColBeforeCommand, {
557
- displayName: "Command<addColBeforeCommand>",
558
- group: "Table"
514
+ displayName: "Command<addColBeforeCommand>",
515
+ group: "Table"
559
516
  });
560
- const addColAfterCommand = $command(
561
- "AddColAfter",
562
- () => () => addColumnAfter
563
- );
517
+ var addColAfterCommand = $command("AddColAfter", () => () => addColumnAfter);
564
518
  withMeta(addColAfterCommand, {
565
- displayName: "Command<addColAfterCommand>",
566
- group: "Table"
567
- });
568
- const addRowBeforeCommand = $command(
569
- "AddRowBefore",
570
- (ctx) => () => (state, dispatch) => {
571
- if (!isInTable(state)) return false;
572
- if (dispatch) {
573
- const rect = selectedRect(state);
574
- dispatch(addRowWithAlignment(ctx, state.tr, rect, rect.top));
575
- }
576
- return true;
577
- }
578
- );
519
+ displayName: "Command<addColAfterCommand>",
520
+ group: "Table"
521
+ });
522
+ var addRowBeforeCommand = $command("AddRowBefore", (ctx) => () => (state, dispatch) => {
523
+ if (!isInTable(state)) return false;
524
+ if (dispatch) {
525
+ const rect = selectedRect(state);
526
+ dispatch(addRowWithAlignment(ctx, state.tr, rect, rect.top));
527
+ }
528
+ return true;
529
+ });
579
530
  withMeta(addRowBeforeCommand, {
580
- displayName: "Command<addRowBeforeCommand>",
581
- group: "Table"
582
- });
583
- const addRowAfterCommand = $command(
584
- "AddRowAfter",
585
- (ctx) => () => (state, dispatch) => {
586
- if (!isInTable(state)) return false;
587
- if (dispatch) {
588
- const rect = selectedRect(state);
589
- dispatch(addRowWithAlignment(ctx, state.tr, rect, rect.bottom));
590
- }
591
- return true;
592
- }
593
- );
531
+ displayName: "Command<addRowBeforeCommand>",
532
+ group: "Table"
533
+ });
534
+ var addRowAfterCommand = $command("AddRowAfter", (ctx) => () => (state, dispatch) => {
535
+ if (!isInTable(state)) return false;
536
+ if (dispatch) {
537
+ const rect = selectedRect(state);
538
+ dispatch(addRowWithAlignment(ctx, state.tr, rect, rect.bottom));
539
+ }
540
+ return true;
541
+ });
594
542
  withMeta(addRowAfterCommand, {
595
- displayName: "Command<addRowAfterCommand>",
596
- group: "Table"
543
+ displayName: "Command<addRowAfterCommand>",
544
+ group: "Table"
597
545
  });
598
- const setAlignCommand = $command(
599
- "SetAlign",
600
- () => (alignment = "left") => setCellAttr("alignment", alignment)
601
- );
546
+ var setAlignCommand = $command("SetAlign", () => (alignment = "left") => setCellAttr("alignment", alignment));
602
547
  withMeta(setAlignCommand, {
603
- displayName: "Command<setAlignCommand>",
604
- group: "Table"
605
- });
606
- const insertTableInputRule = $inputRule(
607
- (ctx) => new InputRule(
608
- /^\|(?<col>\d+)[xX](?<row>\d+)\|\s$/,
609
- (state, match, start, end) => {
610
- const $start = state.doc.resolve(start);
611
- if (!$start.node(-1).canReplaceWith(
612
- $start.index(-1),
613
- $start.indexAfter(-1),
614
- tableSchema.type(ctx)
615
- ))
616
- return null;
617
- const row = Math.max(Number(match.groups?.row ?? 0), 2);
618
- const tableNode = createTable(ctx, row, Number(match.groups?.col));
619
- const tr = state.tr.replaceRangeWith(start, end, tableNode);
620
- return tr.setSelection(TextSelection.create(tr.doc, start + 3)).scrollIntoView();
621
- }
622
- )
623
- );
624
- withMeta(insertTableInputRule, {
625
- displayName: "InputRule<insertTableInputRule>",
626
- group: "Table"
627
- });
628
- const tablePasteRule = $pasteRule((ctx) => ({
629
- run: (slice, _view, isPlainText) => {
630
- if (isPlainText) {
631
- return slice;
632
- }
633
- let fragment = slice.content;
634
- slice.content.forEach((node, _offset, index) => {
635
- if (node?.type !== tableSchema.type(ctx)) {
636
- return;
637
- }
638
- const rowsCount = node.childCount;
639
- const colsCount = node.lastChild?.childCount ?? 0;
640
- if (rowsCount === 0 || colsCount === 0) {
641
- fragment = fragment.replaceChild(
642
- index,
643
- paragraphSchema.type(ctx).create()
644
- );
645
- return;
646
- }
647
- const headerRow = node.firstChild;
648
- const needToFixHeaderRow = colsCount > 0 && headerRow && headerRow.childCount === 0;
649
- if (!needToFixHeaderRow) {
650
- return;
651
- }
652
- const headerCells = Array(colsCount).fill(0).map(() => tableHeaderSchema.type(ctx).createAndFill());
653
- const tableCells = new Slice(Fragment.from(headerCells), 0, 0);
654
- const newHeaderRow = headerRow.replace(0, 0, tableCells);
655
- const newTable = node.replace(
656
- 0,
657
- headerRow.nodeSize,
658
- new Slice(Fragment.from(newHeaderRow), 0, 0)
659
- );
660
- fragment = fragment.replaceChild(index, newTable);
661
- });
662
- return new Slice(Fragment.from(fragment), slice.openStart, slice.openEnd);
663
- }
548
+ displayName: "Command<setAlignCommand>",
549
+ group: "Table"
550
+ });
551
+ //#endregion
552
+ //#region src/node/table/input.ts
553
+ var insertTableInputRule = $inputRule((ctx) => new InputRule(/^\|(?<col>\d+)[xX](?<row>\d+)\|\s$/, (state, match, start, end) => {
554
+ const $start = state.doc.resolve(start);
555
+ if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), tableSchema.type(ctx))) return null;
556
+ const tableNode = createTable(ctx, Math.max(Number(match.groups?.row ?? 0), 2), Number(match.groups?.col));
557
+ const tr = state.tr.replaceRangeWith(start, end, tableNode);
558
+ return tr.setSelection(TextSelection.create(tr.doc, start + 3)).scrollIntoView();
664
559
  }));
560
+ withMeta(insertTableInputRule, {
561
+ displayName: "InputRule<insertTableInputRule>",
562
+ group: "Table"
563
+ });
564
+ var tablePasteRule = $pasteRule((ctx) => ({ run: (slice, _view, isPlainText) => {
565
+ if (isPlainText) return slice;
566
+ function fixTable(node) {
567
+ const rowsCount = node.childCount;
568
+ const colsCount = node.lastChild?.childCount ?? 0;
569
+ if (rowsCount === 0 || colsCount === 0) return paragraphSchema.type(ctx).create();
570
+ const headerRow = node.firstChild;
571
+ if (!(colsCount > 0 && headerRow && headerRow.childCount === 0)) return node;
572
+ if (rowsCount >= 3) {
573
+ const firstDataRow = node.child(1);
574
+ const headerCells = [];
575
+ for (let i = 0; i < firstDataRow.childCount; i++) {
576
+ const cell = firstDataRow.child(i);
577
+ headerCells.push(tableHeaderSchema.type(ctx).create(cell.attrs, cell.content, cell.marks));
578
+ }
579
+ const newHeaderRow = headerRow.type.create(headerRow.attrs, headerCells);
580
+ const remainingRows = [];
581
+ for (let i = 2; i < rowsCount; i++) remainingRows.push(node.child(i));
582
+ return node.type.create(node.attrs, [newHeaderRow, ...remainingRows]);
583
+ }
584
+ const headerCells = Array(colsCount).fill(0).map(() => tableHeaderSchema.type(ctx).createAndFill());
585
+ const tableCells = new Slice(Fragment.from(headerCells), 0, 0);
586
+ const newHeaderRow = headerRow.replace(0, 0, tableCells);
587
+ return node.replace(0, headerRow.nodeSize, new Slice(Fragment.from(newHeaderRow), 0, 0));
588
+ }
589
+ function wrapOrphanedRows(fragment) {
590
+ const rowType = tableRowSchema.type(ctx);
591
+ const nodes = [];
592
+ let pendingRows = [];
593
+ let hasOrphans = false;
594
+ function flushPendingRows() {
595
+ if (pendingRows.length === 0) return;
596
+ const emptyHeaderRow = tableHeaderRowSchema.type(ctx).createAndFill();
597
+ const table = tableSchema.type(ctx).create(null, [emptyHeaderRow, ...pendingRows]);
598
+ nodes.push(fixTable(table));
599
+ pendingRows = [];
600
+ }
601
+ fragment.forEach((node) => {
602
+ if (node.type === rowType) {
603
+ hasOrphans = true;
604
+ pendingRows.push(node);
605
+ } else {
606
+ flushPendingRows();
607
+ nodes.push(node);
608
+ }
609
+ });
610
+ flushPendingRows();
611
+ return hasOrphans ? Fragment.from(nodes) : fragment;
612
+ }
613
+ function fixFragment(fragment) {
614
+ let result = wrapOrphanedRows(fragment);
615
+ let changed = result !== fragment;
616
+ const fixed = [];
617
+ result.forEach((node) => {
618
+ if (node.type === tableSchema.type(ctx)) {
619
+ const fixedNode = fixTable(node);
620
+ if (fixedNode !== node) changed = true;
621
+ fixed.push(fixedNode);
622
+ } else if (node.childCount > 0) {
623
+ const fixedContent = fixFragment(node.content);
624
+ if (fixedContent !== node.content) {
625
+ changed = true;
626
+ fixed.push(node.copy(fixedContent));
627
+ } else fixed.push(node);
628
+ } else fixed.push(node);
629
+ });
630
+ return changed ? Fragment.from(fixed) : fragment;
631
+ }
632
+ function cleanEmptyParagraphs(fragment) {
633
+ const nodes = [];
634
+ const allNodes = [];
635
+ fragment.forEach((node) => allNodes.push(node));
636
+ for (let i = 0; i < allNodes.length; i++) {
637
+ const node = allNodes[i];
638
+ const next = allNodes[i + 1];
639
+ if (node.type === paragraphSchema.type(ctx) && node.content.size === 0 && next && next.type === tableSchema.type(ctx)) continue;
640
+ nodes.push(node);
641
+ }
642
+ return nodes.length < allNodes.length ? Fragment.from(nodes) : fragment;
643
+ }
644
+ let fragment = fixFragment(slice.content);
645
+ fragment = cleanEmptyParagraphs(fragment);
646
+ return new Slice(Fragment.from(fragment), slice.openStart, slice.openEnd);
647
+ } }));
665
648
  withMeta(tablePasteRule, {
666
- displayName: "PasteRule<table>",
667
- group: "Table"
668
- });
669
- const tableKeymap = $useKeymap("tableKeymap", {
670
- NextCell: {
671
- priority: 100,
672
- shortcuts: ["Mod-]", "Tab"],
673
- command: (ctx) => {
674
- const commands2 = ctx.get(commandsCtx);
675
- return () => commands2.call(goToNextTableCellCommand.key);
676
- }
677
- },
678
- PrevCell: {
679
- shortcuts: ["Mod-[", "Shift-Tab"],
680
- command: (ctx) => {
681
- const commands2 = ctx.get(commandsCtx);
682
- return () => commands2.call(goToPrevTableCellCommand.key);
683
- }
684
- },
685
- ExitTable: {
686
- shortcuts: ["Mod-Enter", "Enter"],
687
- command: (ctx) => {
688
- const commands2 = ctx.get(commandsCtx);
689
- return () => commands2.call(exitTable.key);
690
- }
691
- }
649
+ displayName: "PasteRule<table>",
650
+ group: "Table"
651
+ });
652
+ var tableKeymap = $useKeymap("tableKeymap", {
653
+ NextCell: {
654
+ priority: 100,
655
+ shortcuts: ["Mod-]", "Tab"],
656
+ command: (ctx) => {
657
+ const commands = ctx.get(commandsCtx);
658
+ return () => commands.call(goToNextTableCellCommand.key);
659
+ }
660
+ },
661
+ PrevCell: {
662
+ shortcuts: ["Mod-[", "Shift-Tab"],
663
+ command: (ctx) => {
664
+ const commands = ctx.get(commandsCtx);
665
+ return () => commands.call(goToPrevTableCellCommand.key);
666
+ }
667
+ },
668
+ ExitTable: {
669
+ shortcuts: ["Mod-Enter", "Enter"],
670
+ command: (ctx) => {
671
+ const commands = ctx.get(commandsCtx);
672
+ return () => commands.call(exitTable.key);
673
+ }
674
+ }
692
675
  });
693
676
  withMeta(tableKeymap.ctx, {
694
- displayName: "KeymapCtx<table>",
695
- group: "Table"
677
+ displayName: "KeymapCtx<table>",
678
+ group: "Table"
696
679
  });
697
680
  withMeta(tableKeymap.shortcuts, {
698
- displayName: "Keymap<table>",
699
- group: "Table"
700
- });
701
- const id$1 = "footnote_definition";
702
- const markdownId = "footnoteDefinition";
703
- const footnoteDefinitionSchema = $nodeSchema(
704
- "footnote_definition",
705
- () => ({
706
- group: "block",
707
- content: "block+",
708
- defining: true,
709
- attrs: {
710
- label: {
711
- default: "",
712
- validate: "string"
713
- }
714
- },
715
- parseDOM: [
716
- {
717
- tag: `dl[data-type="${id$1}"]`,
718
- getAttrs: (dom) => {
719
- if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom);
720
- return {
721
- label: dom.dataset.label
722
- };
723
- },
724
- contentElement: "dd"
725
- }
726
- ],
727
- toDOM: (node) => {
728
- const label = node.attrs.label;
729
- return [
730
- "dl",
731
- {
732
- // TODO: add a prosemirror plugin to sync label on change
733
- "data-label": label,
734
- "data-type": id$1
735
- },
736
- ["dt", label],
737
- ["dd", 0]
738
- ];
739
- },
740
- parseMarkdown: {
741
- match: ({ type }) => type === markdownId,
742
- runner: (state, node, type) => {
743
- state.openNode(type, {
744
- label: node.label
745
- }).next(node.children).closeNode();
746
- }
747
- },
748
- toMarkdown: {
749
- match: (node) => node.type.name === id$1,
750
- runner: (state, node) => {
751
- state.openNode(markdownId, void 0, {
752
- label: node.attrs.label,
753
- identifier: node.attrs.label
754
- }).next(node.content).closeNode();
755
- }
756
- }
757
- })
758
- );
681
+ displayName: "Keymap<table>",
682
+ group: "Table"
683
+ });
684
+ //#endregion
685
+ //#region src/node/footnote/definition.ts
686
+ var id$1 = "footnote_definition";
687
+ var markdownId = "footnoteDefinition";
688
+ var footnoteDefinitionSchema = $nodeSchema("footnote_definition", () => ({
689
+ group: "block",
690
+ content: "block+",
691
+ defining: true,
692
+ attrs: { label: {
693
+ default: "",
694
+ validate: "string"
695
+ } },
696
+ parseDOM: [{
697
+ tag: `dl[data-type="${id$1}"]`,
698
+ getAttrs: (dom) => {
699
+ if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom);
700
+ return { label: dom.dataset.label };
701
+ },
702
+ contentElement: "dd"
703
+ }],
704
+ toDOM: (node) => {
705
+ const label = node.attrs.label;
706
+ return [
707
+ "dl",
708
+ {
709
+ "data-label": label,
710
+ "data-type": id$1
711
+ },
712
+ ["dt", label],
713
+ ["dd", 0]
714
+ ];
715
+ },
716
+ parseMarkdown: {
717
+ match: ({ type }) => type === markdownId,
718
+ runner: (state, node, type) => {
719
+ state.openNode(type, { label: node.label }).next(node.children).closeNode();
720
+ }
721
+ },
722
+ toMarkdown: {
723
+ match: (node) => node.type.name === id$1,
724
+ runner: (state, node) => {
725
+ state.openNode(markdownId, void 0, {
726
+ label: node.attrs.label,
727
+ identifier: node.attrs.label
728
+ }).next(node.content).closeNode();
729
+ }
730
+ }
731
+ }));
759
732
  withMeta(footnoteDefinitionSchema.ctx, {
760
- displayName: "NodeSchemaCtx<footnodeDef>",
761
- group: "footnote"
733
+ displayName: "NodeSchemaCtx<footnodeDef>",
734
+ group: "footnote"
762
735
  });
763
736
  withMeta(footnoteDefinitionSchema.node, {
764
- displayName: "NodeSchema<footnodeDef>",
765
- group: "footnote"
766
- });
767
- const id = "footnote_reference";
768
- const footnoteReferenceSchema = $nodeSchema(
769
- "footnote_reference",
770
- () => ({
771
- group: "inline",
772
- inline: true,
773
- atom: true,
774
- attrs: {
775
- label: {
776
- default: "",
777
- validate: "string"
778
- }
779
- },
780
- parseDOM: [
781
- {
782
- tag: `sup[data-type="${id}"]`,
783
- getAttrs: (dom) => {
784
- if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom);
785
- return {
786
- label: dom.dataset.label
787
- };
788
- }
789
- }
790
- ],
791
- toDOM: (node) => {
792
- const label = node.attrs.label;
793
- return [
794
- "sup",
795
- {
796
- // TODO: add a prosemirror plugin to sync label on change
797
- "data-label": label,
798
- "data-type": id
799
- },
800
- label
801
- ];
802
- },
803
- parseMarkdown: {
804
- match: ({ type }) => type === "footnoteReference",
805
- runner: (state, node, type) => {
806
- state.addNode(type, {
807
- label: node.label
808
- });
809
- }
810
- },
811
- toMarkdown: {
812
- match: (node) => node.type.name === id,
813
- runner: (state, node) => {
814
- state.addNode("footnoteReference", void 0, void 0, {
815
- label: node.attrs.label,
816
- identifier: node.attrs.label
817
- });
818
- }
819
- }
820
- })
821
- );
737
+ displayName: "NodeSchema<footnodeDef>",
738
+ group: "footnote"
739
+ });
740
+ //#endregion
741
+ //#region src/node/footnote/reference.ts
742
+ var id = "footnote_reference";
743
+ var footnoteReferenceSchema = $nodeSchema("footnote_reference", () => ({
744
+ group: "inline",
745
+ inline: true,
746
+ atom: true,
747
+ attrs: { label: {
748
+ default: "",
749
+ validate: "string"
750
+ } },
751
+ parseDOM: [{
752
+ tag: `sup[data-type="${id}"]`,
753
+ getAttrs: (dom) => {
754
+ if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom);
755
+ return { label: dom.dataset.label };
756
+ }
757
+ }],
758
+ toDOM: (node) => {
759
+ const label = node.attrs.label;
760
+ return [
761
+ "sup",
762
+ {
763
+ "data-label": label,
764
+ "data-type": id
765
+ },
766
+ label
767
+ ];
768
+ },
769
+ parseMarkdown: {
770
+ match: ({ type }) => type === "footnoteReference",
771
+ runner: (state, node, type) => {
772
+ state.addNode(type, { label: node.label });
773
+ }
774
+ },
775
+ toMarkdown: {
776
+ match: (node) => node.type.name === id,
777
+ runner: (state, node) => {
778
+ state.addNode("footnoteReference", void 0, void 0, {
779
+ label: node.attrs.label,
780
+ identifier: node.attrs.label
781
+ });
782
+ }
783
+ }
784
+ }));
822
785
  withMeta(footnoteReferenceSchema.ctx, {
823
- displayName: "NodeSchemaCtx<footnodeRef>",
824
- group: "footnote"
786
+ displayName: "NodeSchemaCtx<footnodeRef>",
787
+ group: "footnote"
825
788
  });
826
789
  withMeta(footnoteReferenceSchema.node, {
827
- displayName: "NodeSchema<footnodeRef>",
828
- group: "footnote"
829
- });
830
- const extendListItemSchemaForTask = listItemSchema.extendSchema(
831
- (prev) => {
832
- return (ctx) => {
833
- const baseSchema = prev(ctx);
834
- return {
835
- ...baseSchema,
836
- attrs: {
837
- ...baseSchema.attrs,
838
- checked: {
839
- default: null,
840
- validate: "boolean|null"
841
- }
842
- },
843
- parseDOM: [
844
- {
845
- tag: 'li[data-item-type="task"]',
846
- getAttrs: (dom) => {
847
- if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom);
848
- return {
849
- label: dom.dataset.label,
850
- listType: dom.dataset.listType,
851
- spread: dom.dataset.spread,
852
- checked: dom.dataset.checked ? dom.dataset.checked === "true" : null
853
- };
854
- }
855
- },
856
- ...baseSchema?.parseDOM || []
857
- ],
858
- toDOM: (node) => {
859
- if (baseSchema.toDOM && node.attrs.checked == null)
860
- return baseSchema.toDOM(node);
861
- return [
862
- "li",
863
- {
864
- "data-item-type": "task",
865
- "data-label": node.attrs.label,
866
- "data-list-type": node.attrs.listType,
867
- "data-spread": node.attrs.spread,
868
- "data-checked": node.attrs.checked
869
- },
870
- 0
871
- ];
872
- },
873
- parseMarkdown: {
874
- match: ({ type }) => type === "listItem",
875
- runner: (state, node, type) => {
876
- if (node.checked == null) {
877
- baseSchema.parseMarkdown.runner(state, node, type);
878
- return;
879
- }
880
- const label = node.label != null ? `${node.label}.` : "";
881
- const checked = node.checked != null ? Boolean(node.checked) : null;
882
- const listType = node.label != null ? "ordered" : "bullet";
883
- const spread = node.spread != null ? `${node.spread}` : "true";
884
- state.openNode(type, { label, listType, spread, checked });
885
- state.next(node.children);
886
- state.closeNode();
887
- }
888
- },
889
- toMarkdown: {
890
- match: (node) => node.type.name === "list_item",
891
- runner: (state, node) => {
892
- if (node.attrs.checked == null) {
893
- baseSchema.toMarkdown.runner(state, node);
894
- return;
895
- }
896
- const label = node.attrs.label;
897
- const listType = node.attrs.listType;
898
- const spread = node.attrs.spread === "true";
899
- const checked = node.attrs.checked;
900
- state.openNode("listItem", void 0, {
901
- label,
902
- listType,
903
- spread,
904
- checked
905
- });
906
- state.next(node.content);
907
- state.closeNode();
908
- }
909
- }
910
- };
911
- };
912
- }
913
- );
790
+ displayName: "NodeSchema<footnodeRef>",
791
+ group: "footnote"
792
+ });
793
+ //#endregion
794
+ //#region src/node/task-list-item.ts
795
+ var extendListItemSchemaForTask = listItemSchema.extendSchema((prev) => {
796
+ return (ctx) => {
797
+ const baseSchema = prev(ctx);
798
+ return {
799
+ ...baseSchema,
800
+ attrs: {
801
+ ...baseSchema.attrs,
802
+ checked: {
803
+ default: null,
804
+ validate: "boolean|null"
805
+ }
806
+ },
807
+ parseDOM: [{
808
+ tag: "li[data-item-type=\"task\"]",
809
+ getAttrs: (dom) => {
810
+ if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom);
811
+ return {
812
+ label: dom.dataset.label,
813
+ listType: dom.dataset.listType,
814
+ spread: dom.dataset.spread,
815
+ checked: dom.dataset.checked ? dom.dataset.checked === "true" : null
816
+ };
817
+ }
818
+ }, ...baseSchema?.parseDOM || []],
819
+ toDOM: (node) => {
820
+ if (baseSchema.toDOM && node.attrs.checked == null) return baseSchema.toDOM(node);
821
+ return [
822
+ "li",
823
+ {
824
+ "data-item-type": "task",
825
+ "data-label": node.attrs.label,
826
+ "data-list-type": node.attrs.listType,
827
+ "data-spread": node.attrs.spread,
828
+ "data-checked": node.attrs.checked
829
+ },
830
+ 0
831
+ ];
832
+ },
833
+ parseMarkdown: {
834
+ match: ({ type }) => type === "listItem",
835
+ runner: (state, node, type) => {
836
+ if (node.checked == null) {
837
+ baseSchema.parseMarkdown.runner(state, node, type);
838
+ return;
839
+ }
840
+ const label = node.label != null ? `${node.label}.` : "•";
841
+ const checked = node.checked != null ? Boolean(node.checked) : null;
842
+ const listType = node.label != null ? "ordered" : "bullet";
843
+ const spread = node.spread != null ? `${node.spread}` : "true";
844
+ state.openNode(type, {
845
+ label,
846
+ listType,
847
+ spread,
848
+ checked
849
+ });
850
+ state.next(node.children);
851
+ state.closeNode();
852
+ }
853
+ },
854
+ toMarkdown: {
855
+ match: (node) => node.type.name === "list_item",
856
+ runner: (state, node) => {
857
+ if (node.attrs.checked == null) {
858
+ baseSchema.toMarkdown.runner(state, node);
859
+ return;
860
+ }
861
+ const label = node.attrs.label;
862
+ const listType = node.attrs.listType;
863
+ const spread = node.attrs.spread === "true";
864
+ const checked = node.attrs.checked;
865
+ state.openNode("listItem", void 0, {
866
+ label,
867
+ listType,
868
+ spread,
869
+ checked
870
+ });
871
+ state.next(node.content);
872
+ state.closeNode();
873
+ }
874
+ }
875
+ };
876
+ };
877
+ });
914
878
  withMeta(extendListItemSchemaForTask.node, {
915
- displayName: "NodeSchema<taskListItem>",
916
- group: "ListItem"
879
+ displayName: "NodeSchema<taskListItem>",
880
+ group: "ListItem"
917
881
  });
918
882
  withMeta(extendListItemSchemaForTask.ctx, {
919
- displayName: "NodeSchemaCtx<taskListItem>",
920
- group: "ListItem"
921
- });
922
- const wrapInTaskListInputRule = $inputRule(() => {
923
- return new InputRule(
924
- /^\[(?<checked>\s|x)\]\s$/,
925
- (state, match, start, end) => {
926
- const pos = state.doc.resolve(start);
927
- let depth = 0;
928
- let node = pos.node(depth);
929
- while (node && node.type.name !== "list_item") {
930
- depth--;
931
- node = pos.node(depth);
932
- }
933
- if (!node || node.attrs.checked != null) return null;
934
- const checked = Boolean(match.groups?.checked === "x");
935
- const finPos = pos.before(depth);
936
- const tr = state.tr;
937
- tr.deleteRange(start, end).setNodeMarkup(finPos, void 0, {
938
- ...node.attrs,
939
- checked
940
- });
941
- return tr;
942
- }
943
- );
883
+ displayName: "NodeSchemaCtx<taskListItem>",
884
+ group: "ListItem"
885
+ });
886
+ var wrapInTaskListInputRule = $inputRule(() => {
887
+ return new InputRule(/^\[(?<checked>\s|x)\]\s$/, (state, match, start, end) => {
888
+ const pos = state.doc.resolve(start);
889
+ let depth = 0;
890
+ let node = pos.node(depth);
891
+ while (node && node.type.name !== "list_item") {
892
+ depth--;
893
+ node = pos.node(depth);
894
+ }
895
+ if (!node || node.attrs.checked != null) return null;
896
+ const checked = Boolean(match.groups?.checked === "x");
897
+ const finPos = pos.before(depth);
898
+ const tr = state.tr;
899
+ tr.deleteRange(start, end).setNodeMarkup(finPos, void 0, {
900
+ ...node.attrs,
901
+ checked
902
+ });
903
+ return tr;
904
+ });
944
905
  });
945
906
  withMeta(wrapInTaskListInputRule, {
946
- displayName: "InputRule<wrapInTaskListInputRule>",
947
- group: "ListItem"
907
+ displayName: "InputRule<wrapInTaskListInputRule>",
908
+ group: "ListItem"
948
909
  });
949
- const keymap = [
950
- strikethroughKeymap,
951
- tableKeymap
952
- ].flat();
953
- const inputRules = [
954
- insertTableInputRule,
955
- wrapInTaskListInputRule
956
- ];
957
- const markInputRules = [strikethroughInputRule];
958
- const pasteRules = [tablePasteRule];
959
- const autoInsertSpanPlugin = $prose(() => imeSpan);
910
+ //#endregion
911
+ //#region src/composed/keymap.ts
912
+ var keymap = [strikethroughKeymap, tableKeymap].flat();
913
+ //#endregion
914
+ //#region src/composed/inputrules.ts
915
+ var inputRules = [insertTableInputRule, wrapInTaskListInputRule];
916
+ var markInputRules = [strikethroughInputRule];
917
+ //#endregion
918
+ //#region src/composed/pasterules.ts
919
+ var pasteRules = [tablePasteRule];
920
+ //#endregion
921
+ //#region src/plugin/auto-insert-span-plugin.ts
922
+ var autoInsertSpanPlugin = $prose(() => imeSpan);
960
923
  withMeta(autoInsertSpanPlugin, {
961
- displayName: "Prose<autoInsertSpanPlugin>",
962
- group: "Prose"
924
+ displayName: "Prose<autoInsertSpanPlugin>",
925
+ group: "Prose"
963
926
  });
964
- const columnResizingPlugin = $prose(() => columnResizing({}));
927
+ //#endregion
928
+ //#region src/plugin/column-resizing-plugin.ts
929
+ var columnResizingPlugin = $prose(() => columnResizing({}));
965
930
  withMeta(columnResizingPlugin, {
966
- displayName: "Prose<columnResizingPlugin>",
967
- group: "Prose"
931
+ displayName: "Prose<columnResizingPlugin>",
932
+ group: "Prose"
968
933
  });
969
- const tableEditingPlugin = $prose(
970
- () => tableEditing({ allowTableNodeSelection: true })
971
- );
934
+ //#endregion
935
+ //#region src/plugin/table-editing-plugin.ts
936
+ var tableEditingPlugin = $prose(() => tableEditing({ allowTableNodeSelection: true }));
972
937
  withMeta(tableEditingPlugin, {
973
- displayName: "Prose<tableEditingPlugin>",
974
- group: "Prose"
938
+ displayName: "Prose<tableEditingPlugin>",
939
+ group: "Prose"
975
940
  });
976
- const remarkGFMPlugin = $remark("remarkGFM", () => remarkGFM);
941
+ //#endregion
942
+ //#region src/plugin/remark-gfm-plugin.ts
943
+ var remarkGFMPlugin = $remark("remarkGFM", () => remarkGFM);
977
944
  withMeta(remarkGFMPlugin.plugin, {
978
- displayName: "Remark<remarkGFMPlugin>",
979
- group: "Remark"
945
+ displayName: "Remark<remarkGFMPlugin>",
946
+ group: "Remark"
980
947
  });
981
948
  withMeta(remarkGFMPlugin.options, {
982
- displayName: "RemarkConfig<remarkGFMPlugin>",
983
- group: "Remark"
949
+ displayName: "RemarkConfig<remarkGFMPlugin>",
950
+ group: "Remark"
984
951
  });
985
- const pluginKey = new PluginKey("MILKDOWN_KEEP_TABLE_ALIGN_PLUGIN");
952
+ //#endregion
953
+ //#region src/plugin/keep-table-align-plugin.ts
954
+ var pluginKey = new PluginKey("MILKDOWN_KEEP_TABLE_ALIGN_PLUGIN");
986
955
  function getChildIndex(node, parent) {
987
- let index = 0;
988
- parent.forEach((child, _offset, i) => {
989
- if (child === node) index = i;
990
- });
991
- return index;
956
+ let index = 0;
957
+ parent.forEach((child, _offset, i) => {
958
+ if (child === node) index = i;
959
+ });
960
+ return index;
992
961
  }
993
- const keepTableAlignPlugin = $prose(() => {
994
- return new Plugin({
995
- key: pluginKey,
996
- appendTransaction: (_tr, oldState, state) => {
997
- let tr;
998
- const check = (node, pos) => {
999
- if (!tr) tr = state.tr;
1000
- if (node.type.name !== "table_cell") return;
1001
- const $pos = state.doc.resolve(pos);
1002
- const tableRow = $pos.node($pos.depth);
1003
- const table = $pos.node($pos.depth - 1);
1004
- const tableHeaderRow = table.firstChild;
1005
- if (!tableHeaderRow) return;
1006
- const index = getChildIndex(node, tableRow);
1007
- const headerCell = tableHeaderRow.maybeChild(index);
1008
- if (!headerCell) return;
1009
- const align = headerCell.attrs.alignment;
1010
- const currentAlign = node.attrs.alignment;
1011
- if (align === currentAlign) return;
1012
- tr.setNodeMarkup(pos, void 0, { ...node.attrs, alignment: align });
1013
- };
1014
- if (oldState.doc !== state.doc) state.doc.descendants(check);
1015
- return tr;
1016
- }
1017
- });
962
+ var keepTableAlignPlugin = $prose(() => {
963
+ return new Plugin({
964
+ key: pluginKey,
965
+ appendTransaction: (_tr, oldState, state) => {
966
+ let tr;
967
+ const check = (node, pos) => {
968
+ if (!tr) tr = state.tr;
969
+ if (node.type.name !== "table_cell") return;
970
+ const $pos = state.doc.resolve(pos);
971
+ const tableRow = $pos.node($pos.depth);
972
+ const tableHeaderRow = $pos.node($pos.depth - 1).firstChild;
973
+ if (!tableHeaderRow) return;
974
+ const index = getChildIndex(node, tableRow);
975
+ const headerCell = tableHeaderRow.maybeChild(index);
976
+ if (!headerCell) return;
977
+ const align = headerCell.attrs.alignment;
978
+ if (align === node.attrs.alignment) return;
979
+ tr.setNodeMarkup(pos, void 0, {
980
+ ...node.attrs,
981
+ alignment: align
982
+ });
983
+ };
984
+ if (oldState.doc !== state.doc) state.doc.descendants(check);
985
+ return tr;
986
+ }
987
+ });
1018
988
  });
1019
989
  withMeta(keepTableAlignPlugin, {
1020
- displayName: "Prose<keepTableAlignPlugin>",
1021
- group: "Prose"
1022
- });
1023
- const plugins = [
1024
- keepTableAlignPlugin,
1025
- autoInsertSpanPlugin,
1026
- remarkGFMPlugin,
1027
- tableEditingPlugin
990
+ displayName: "Prose<keepTableAlignPlugin>",
991
+ group: "Prose"
992
+ });
993
+ //#endregion
994
+ //#region src/composed/plugins.ts
995
+ var plugins = [
996
+ keepTableAlignPlugin,
997
+ autoInsertSpanPlugin,
998
+ remarkGFMPlugin,
999
+ tableEditingPlugin
1028
1000
  ].flat();
1029
- const schema = [
1030
- extendListItemSchemaForTask,
1031
- tableSchema,
1032
- tableHeaderRowSchema,
1033
- tableRowSchema,
1034
- tableHeaderSchema,
1035
- tableCellSchema,
1036
- footnoteDefinitionSchema,
1037
- footnoteReferenceSchema,
1038
- strikethroughAttr,
1039
- strikethroughSchema
1001
+ //#endregion
1002
+ //#region src/composed/schema.ts
1003
+ var schema = [
1004
+ extendListItemSchemaForTask,
1005
+ tableSchema,
1006
+ tableHeaderRowSchema,
1007
+ tableRowSchema,
1008
+ tableHeaderSchema,
1009
+ tableCellSchema,
1010
+ footnoteDefinitionSchema,
1011
+ footnoteReferenceSchema,
1012
+ strikethroughAttr,
1013
+ strikethroughSchema
1040
1014
  ].flat();
1041
- const commands = [
1042
- goToNextTableCellCommand,
1043
- goToPrevTableCellCommand,
1044
- exitTable,
1045
- insertTableCommand,
1046
- moveRowCommand,
1047
- moveColCommand,
1048
- selectRowCommand,
1049
- selectColCommand,
1050
- selectTableCommand,
1051
- deleteSelectedCellsCommand,
1052
- addRowBeforeCommand,
1053
- addRowAfterCommand,
1054
- addColBeforeCommand,
1055
- addColAfterCommand,
1056
- setAlignCommand,
1057
- toggleStrikethroughCommand
1015
+ //#endregion
1016
+ //#region src/composed/commands.ts
1017
+ var commands = [
1018
+ goToNextTableCellCommand,
1019
+ goToPrevTableCellCommand,
1020
+ exitTable,
1021
+ insertTableCommand,
1022
+ moveRowCommand,
1023
+ moveColCommand,
1024
+ selectRowCommand,
1025
+ selectColCommand,
1026
+ selectTableCommand,
1027
+ deleteSelectedCellsCommand,
1028
+ addRowBeforeCommand,
1029
+ addRowAfterCommand,
1030
+ addColBeforeCommand,
1031
+ addColAfterCommand,
1032
+ setAlignCommand,
1033
+ toggleStrikethroughCommand
1058
1034
  ];
1059
- const gfm = [
1060
- schema,
1061
- inputRules,
1062
- pasteRules,
1063
- markInputRules,
1064
- keymap,
1065
- commands,
1066
- plugins
1035
+ //#endregion
1036
+ //#region src/index.ts
1037
+ var gfm = [
1038
+ schema,
1039
+ inputRules,
1040
+ pasteRules,
1041
+ markInputRules,
1042
+ keymap,
1043
+ commands,
1044
+ plugins
1067
1045
  ].flat();
1068
- export {
1069
- addColAfterCommand,
1070
- addColBeforeCommand,
1071
- addRowAfterCommand,
1072
- addRowBeforeCommand,
1073
- addRowWithAlignment,
1074
- autoInsertSpanPlugin,
1075
- columnResizingPlugin,
1076
- commands,
1077
- createTable,
1078
- deleteSelectedCellsCommand,
1079
- exitTable,
1080
- extendListItemSchemaForTask,
1081
- footnoteDefinitionSchema,
1082
- footnoteReferenceSchema,
1083
- getAllCellsInTable,
1084
- getCellsInCol,
1085
- getCellsInRow,
1086
- gfm,
1087
- goToNextTableCellCommand,
1088
- goToPrevTableCellCommand,
1089
- inputRules,
1090
- insertTableCommand,
1091
- insertTableInputRule,
1092
- keepTableAlignPlugin,
1093
- keymap,
1094
- markInputRules,
1095
- moveColCommand,
1096
- moveRowCommand,
1097
- pasteRules,
1098
- plugins,
1099
- remarkGFMPlugin,
1100
- schema,
1101
- selectCol,
1102
- selectColCommand,
1103
- selectLine,
1104
- selectRow,
1105
- selectRowCommand,
1106
- selectTable,
1107
- selectTableCommand,
1108
- setAlignCommand,
1109
- strikethroughAttr,
1110
- strikethroughInputRule,
1111
- strikethroughKeymap,
1112
- strikethroughSchema,
1113
- tableCellSchema,
1114
- tableEditingPlugin,
1115
- tableHeaderRowSchema,
1116
- tableHeaderSchema,
1117
- tableKeymap,
1118
- tablePasteRule,
1119
- tableRowSchema,
1120
- tableSchema,
1121
- toggleStrikethroughCommand,
1122
- wrapInTaskListInputRule
1123
- };
1124
- //# sourceMappingURL=index.js.map
1046
+ //#endregion
1047
+ export { addColAfterCommand, addColBeforeCommand, addRowAfterCommand, addRowBeforeCommand, addRowWithAlignment, autoInsertSpanPlugin, columnResizingPlugin, commands, createTable, deleteSelectedCellsCommand, exitTable, extendListItemSchemaForTask, footnoteDefinitionSchema, footnoteReferenceSchema, getAllCellsInTable, getCellsInCol, getCellsInRow, gfm, goToNextTableCellCommand, goToPrevTableCellCommand, inputRules, insertTableCommand, insertTableInputRule, keepTableAlignPlugin, keymap, markInputRules, moveColCommand, moveRowCommand, pasteRules, plugins, remarkGFMPlugin, schema, selectCol, selectColCommand, selectLine, selectRow, selectRowCommand, selectTable, selectTableCommand, setAlignCommand, strikethroughAttr, strikethroughInputRule, strikethroughKeymap, strikethroughSchema, tableCellSchema, tableEditingPlugin, tableHeaderRowSchema, tableHeaderSchema, tableKeymap, tablePasteRule, tableRowSchema, tableSchema, toggleStrikethroughCommand, wrapInTaskListInputRule };
1048
+
1049
+ //# sourceMappingURL=index.js.map