@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 +884 -708
- package/lib/index.es.js.map +1 -1
- package/lib/node/table/utils.d.ts.map +1 -1
- package/package.json +8 -8
package/lib/index.es.js
CHANGED
|
@@ -1,759 +1,893 @@
|
|
|
1
|
-
import { expectDomTypeError
|
|
2
|
-
import { paragraphSchema
|
|
3
|
-
import { InputRule
|
|
4
|
-
import { $markAttr
|
|
5
|
-
import { tableNodes
|
|
6
|
-
import { commandsCtx
|
|
7
|
-
import { toggleMark
|
|
8
|
-
import { markRule
|
|
9
|
-
import { Selection
|
|
10
|
-
import { imeSpan
|
|
11
|
-
import
|
|
12
|
-
function
|
|
13
|
-
|
|
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
|
-
...
|
|
16
|
+
...meta
|
|
17
17
|
}
|
|
18
|
-
})
|
|
18
|
+
});
|
|
19
|
+
return plugin;
|
|
19
20
|
}
|
|
20
|
-
const
|
|
21
|
-
|
|
21
|
+
const strikethroughAttr = $markAttr("strike_through");
|
|
22
|
+
withMeta(strikethroughAttr, {
|
|
22
23
|
displayName: "Attr<strikethrough>",
|
|
23
24
|
group: "Strikethrough"
|
|
24
25
|
});
|
|
25
|
-
const
|
|
26
|
+
const strikethroughSchema = $markSchema("strike_through", (ctx) => ({
|
|
26
27
|
parseDOM: [
|
|
27
28
|
{ tag: "del" },
|
|
28
29
|
{
|
|
29
30
|
style: "text-decoration",
|
|
30
|
-
getAttrs: (
|
|
31
|
+
getAttrs: (value) => value === "line-through"
|
|
31
32
|
}
|
|
32
33
|
],
|
|
33
|
-
toDOM: (
|
|
34
|
+
toDOM: (mark) => ["del", ctx.get(strikethroughAttr.key)(mark)],
|
|
34
35
|
parseMarkdown: {
|
|
35
|
-
match: (
|
|
36
|
-
runner: (
|
|
37
|
-
|
|
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: (
|
|
42
|
-
runner: (
|
|
43
|
-
|
|
44
|
+
match: (mark) => mark.type.name === "strike_through",
|
|
45
|
+
runner: (state, mark) => {
|
|
46
|
+
state.withMark(mark, "delete");
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
49
|
}));
|
|
47
|
-
|
|
50
|
+
withMeta(strikethroughSchema.mark, {
|
|
48
51
|
displayName: "MarkSchema<strikethrough>",
|
|
49
52
|
group: "Strikethrough"
|
|
50
53
|
});
|
|
51
|
-
|
|
54
|
+
withMeta(strikethroughSchema.ctx, {
|
|
52
55
|
displayName: "MarkSchemaCtx<strikethrough>",
|
|
53
56
|
group: "Strikethrough"
|
|
54
57
|
});
|
|
55
|
-
const
|
|
58
|
+
const toggleStrikethroughCommand = $command(
|
|
56
59
|
"ToggleStrikeThrough",
|
|
57
|
-
(
|
|
60
|
+
(ctx) => () => {
|
|
61
|
+
return toggleMark(strikethroughSchema.type(ctx));
|
|
62
|
+
}
|
|
58
63
|
);
|
|
59
|
-
|
|
64
|
+
withMeta(toggleStrikethroughCommand, {
|
|
60
65
|
displayName: "Command<ToggleStrikethrough>",
|
|
61
66
|
group: "Strikethrough"
|
|
62
67
|
});
|
|
63
|
-
const
|
|
64
|
-
|
|
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
|
|
75
|
+
const strikethroughKeymap = $useKeymap("strikeThroughKeymap", {
|
|
69
76
|
ToggleStrikethrough: {
|
|
70
77
|
shortcuts: "Mod-Alt-x",
|
|
71
|
-
command: (
|
|
72
|
-
const
|
|
73
|
-
return () =>
|
|
78
|
+
command: (ctx) => {
|
|
79
|
+
const commands2 = ctx.get(commandsCtx);
|
|
80
|
+
return () => commands2.call(toggleStrikethroughCommand.key);
|
|
74
81
|
}
|
|
75
82
|
}
|
|
76
83
|
});
|
|
77
|
-
|
|
84
|
+
withMeta(strikethroughKeymap.ctx, {
|
|
78
85
|
displayName: "KeymapCtx<strikethrough>",
|
|
79
86
|
group: "Strikethrough"
|
|
80
87
|
});
|
|
81
|
-
|
|
88
|
+
withMeta(strikethroughKeymap.shortcuts, {
|
|
82
89
|
displayName: "Keymap<strikethrough>",
|
|
83
90
|
group: "Strikethrough"
|
|
84
91
|
});
|
|
85
|
-
const
|
|
92
|
+
const originalSchema = tableNodes({
|
|
86
93
|
tableGroup: "block",
|
|
87
94
|
cellContent: "paragraph",
|
|
88
95
|
cellAttributes: {
|
|
89
96
|
alignment: {
|
|
90
97
|
default: "left",
|
|
91
|
-
getFromDOM: (
|
|
92
|
-
setDOMAttr: (
|
|
93
|
-
|
|
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
|
-
})
|
|
98
|
-
|
|
104
|
+
});
|
|
105
|
+
const tableSchema = $nodeSchema("table", () => ({
|
|
106
|
+
...originalSchema.table,
|
|
99
107
|
content: "table_header_row table_row+",
|
|
100
|
-
disableDropCursor:
|
|
108
|
+
disableDropCursor: true,
|
|
101
109
|
parseMarkdown: {
|
|
102
|
-
match: (
|
|
103
|
-
runner: (
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
118
|
+
state.openNode(type);
|
|
119
|
+
state.next(children);
|
|
120
|
+
state.closeNode();
|
|
110
121
|
}
|
|
111
122
|
},
|
|
112
123
|
toMarkdown: {
|
|
113
|
-
match: (
|
|
114
|
-
runner: (
|
|
115
|
-
var
|
|
116
|
-
const
|
|
117
|
-
if (!
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
})
|
|
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
|
-
|
|
139
|
+
withMeta(tableSchema.node, {
|
|
126
140
|
displayName: "NodeSchema<table>",
|
|
127
141
|
group: "Table"
|
|
128
142
|
});
|
|
129
|
-
|
|
143
|
+
withMeta(tableSchema.ctx, {
|
|
130
144
|
displayName: "NodeSchemaCtx<table>",
|
|
131
145
|
group: "Table"
|
|
132
146
|
});
|
|
133
|
-
const
|
|
134
|
-
...
|
|
135
|
-
disableDropCursor:
|
|
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":
|
|
153
|
+
return ["tr", { "data-is-header": true }, 0];
|
|
140
154
|
},
|
|
141
155
|
parseMarkdown: {
|
|
142
|
-
match: (
|
|
143
|
-
runner: (
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
164
|
+
state.openNode(type);
|
|
165
|
+
state.next(children);
|
|
166
|
+
state.closeNode();
|
|
150
167
|
}
|
|
151
168
|
},
|
|
152
169
|
toMarkdown: {
|
|
153
|
-
match: (
|
|
154
|
-
runner: (
|
|
155
|
-
|
|
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
|
-
|
|
178
|
+
withMeta(tableHeaderRowSchema.node, {
|
|
160
179
|
displayName: "NodeSchema<tableHeaderRow>",
|
|
161
180
|
group: "Table"
|
|
162
181
|
});
|
|
163
|
-
|
|
182
|
+
withMeta(tableHeaderRowSchema.ctx, {
|
|
164
183
|
displayName: "NodeSchemaCtx<tableHeaderRow>",
|
|
165
184
|
group: "Table"
|
|
166
185
|
});
|
|
167
|
-
const
|
|
168
|
-
...
|
|
169
|
-
disableDropCursor:
|
|
186
|
+
const tableRowSchema = $nodeSchema("table_row", () => ({
|
|
187
|
+
...originalSchema.table_row,
|
|
188
|
+
disableDropCursor: true,
|
|
170
189
|
content: "(table_cell)*",
|
|
171
190
|
parseMarkdown: {
|
|
172
|
-
match: (
|
|
173
|
-
runner: (
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
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
|
-
|
|
198
|
+
state.openNode(type);
|
|
199
|
+
state.next(children);
|
|
200
|
+
state.closeNode();
|
|
179
201
|
}
|
|
180
202
|
},
|
|
181
203
|
toMarkdown: {
|
|
182
|
-
match: (
|
|
183
|
-
runner: (
|
|
184
|
-
|
|
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
|
-
|
|
212
|
+
withMeta(tableRowSchema.node, {
|
|
189
213
|
displayName: "NodeSchema<tableRow>",
|
|
190
214
|
group: "Table"
|
|
191
215
|
});
|
|
192
|
-
|
|
216
|
+
withMeta(tableRowSchema.ctx, {
|
|
193
217
|
displayName: "NodeSchemaCtx<tableRow>",
|
|
194
218
|
group: "Table"
|
|
195
219
|
});
|
|
196
|
-
const
|
|
197
|
-
...
|
|
198
|
-
disableDropCursor:
|
|
220
|
+
const tableCellSchema = $nodeSchema("table_cell", () => ({
|
|
221
|
+
...originalSchema.table_cell,
|
|
222
|
+
disableDropCursor: true,
|
|
199
223
|
parseMarkdown: {
|
|
200
|
-
match: (
|
|
201
|
-
runner: (
|
|
202
|
-
const
|
|
203
|
-
|
|
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: (
|
|
208
|
-
runner: (
|
|
209
|
-
|
|
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
|
-
|
|
237
|
+
withMeta(tableCellSchema.node, {
|
|
214
238
|
displayName: "NodeSchema<tableCell>",
|
|
215
239
|
group: "Table"
|
|
216
240
|
});
|
|
217
|
-
|
|
241
|
+
withMeta(tableCellSchema.ctx, {
|
|
218
242
|
displayName: "NodeSchemaCtx<tableCell>",
|
|
219
243
|
group: "Table"
|
|
220
244
|
});
|
|
221
|
-
const
|
|
222
|
-
...
|
|
223
|
-
disableDropCursor:
|
|
245
|
+
const tableHeaderSchema = $nodeSchema("table_header", () => ({
|
|
246
|
+
...originalSchema.table_header,
|
|
247
|
+
disableDropCursor: true,
|
|
224
248
|
parseMarkdown: {
|
|
225
|
-
match: (
|
|
226
|
-
runner: (
|
|
227
|
-
const
|
|
228
|
-
|
|
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: (
|
|
233
|
-
runner: (
|
|
234
|
-
|
|
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
|
-
|
|
268
|
+
withMeta(tableHeaderSchema.node, {
|
|
239
269
|
displayName: "NodeSchema<tableHeader>",
|
|
240
270
|
group: "Table"
|
|
241
271
|
});
|
|
242
|
-
|
|
272
|
+
withMeta(tableHeaderSchema.ctx, {
|
|
243
273
|
displayName: "NodeSchemaCtx<tableHeader>",
|
|
244
274
|
group: "Table"
|
|
245
275
|
});
|
|
246
|
-
function
|
|
247
|
-
const
|
|
248
|
-
|
|
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
|
|
282
|
+
return tableSchema.type(ctx).create(null, rows);
|
|
251
283
|
}
|
|
252
|
-
function
|
|
253
|
-
return
|
|
254
|
-
(
|
|
255
|
-
)(
|
|
284
|
+
function findTable($pos) {
|
|
285
|
+
return findParentNodeClosestToPos(
|
|
286
|
+
(node) => node.type.spec.tableRole === "table"
|
|
287
|
+
)($pos);
|
|
256
288
|
}
|
|
257
|
-
function
|
|
258
|
-
const
|
|
259
|
-
if (!
|
|
260
|
-
const
|
|
261
|
-
if (
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
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
|
|
279
|
-
const
|
|
280
|
-
if (!
|
|
281
|
-
const
|
|
282
|
-
if (
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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
|
|
300
|
-
const
|
|
301
|
-
if (!
|
|
302
|
-
const
|
|
303
|
-
|
|
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:
|
|
337
|
+
right: map.width,
|
|
306
338
|
top: 0,
|
|
307
|
-
bottom:
|
|
308
|
-
})
|
|
309
|
-
|
|
310
|
-
|
|
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
|
|
314
|
-
const
|
|
315
|
-
if (
|
|
316
|
-
const
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
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
|
|
357
|
+
return tr;
|
|
323
358
|
}
|
|
324
|
-
function
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
|
|
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
|
-
|
|
367
|
+
tr.insert(rowPos, tableRowSchema.type(ctx).create(null, cells));
|
|
368
|
+
return tr;
|
|
330
369
|
}
|
|
331
|
-
function
|
|
332
|
-
return (
|
|
333
|
-
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
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
|
|
405
|
+
return tr;
|
|
360
406
|
};
|
|
361
407
|
}
|
|
362
|
-
const
|
|
363
|
-
|
|
364
|
-
|
|
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
|
|
367
|
-
const
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
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
|
-
|
|
431
|
+
rowCells.push(newCell);
|
|
378
432
|
}
|
|
379
|
-
|
|
433
|
+
rowsPM.push(row.type.createChecked(row.attrs, rowCells, row.marks));
|
|
380
434
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
435
|
+
const newTable = tableNode.type.createChecked(
|
|
436
|
+
tableNode.attrs,
|
|
437
|
+
rowsPM,
|
|
438
|
+
tableNode.marks
|
|
385
439
|
);
|
|
440
|
+
return newTable;
|
|
386
441
|
}
|
|
387
|
-
function
|
|
388
|
-
const
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
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
|
-
|
|
456
|
+
seen[cellPos] = true;
|
|
457
|
+
rowCells.push(cell);
|
|
398
458
|
}
|
|
399
|
-
|
|
459
|
+
rows.push(rowCells);
|
|
400
460
|
}
|
|
401
|
-
return
|
|
461
|
+
return rows;
|
|
402
462
|
}
|
|
403
|
-
function
|
|
404
|
-
const
|
|
405
|
-
|
|
406
|
-
|
|
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
|
|
409
|
-
let
|
|
410
|
-
|
|
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
|
|
413
|
-
let
|
|
414
|
-
|
|
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
|
|
417
|
-
let
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
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
|
|
426
|
-
const
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
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
|
|
433
|
-
for (let
|
|
434
|
-
const
|
|
435
|
-
|
|
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
|
-
|
|
438
|
-
|
|
439
|
-
|
|
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
|
|
442
|
-
for (let
|
|
443
|
-
const
|
|
444
|
-
if (
|
|
445
|
-
for (let
|
|
446
|
-
if (
|
|
447
|
-
|
|
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
|
-
|
|
529
|
+
}
|
|
530
|
+
if (headCell) break;
|
|
451
531
|
}
|
|
452
532
|
}
|
|
453
|
-
const
|
|
454
|
-
return { $anchor
|
|
533
|
+
const $head = tr.doc.resolve(headCell.pos);
|
|
534
|
+
return { $anchor, $head, indexes };
|
|
455
535
|
}
|
|
456
|
-
function
|
|
457
|
-
let
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
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
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
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
|
-
|
|
474
|
-
|
|
475
|
-
|
|
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
|
|
478
|
-
for (let
|
|
479
|
-
const
|
|
480
|
-
if (
|
|
481
|
-
for (let
|
|
482
|
-
if (
|
|
483
|
-
|
|
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
|
-
|
|
576
|
+
}
|
|
577
|
+
if (headCell) break;
|
|
487
578
|
}
|
|
488
579
|
}
|
|
489
|
-
const
|
|
490
|
-
return { $anchor
|
|
580
|
+
const $head = tr.doc.resolve(headCell.pos);
|
|
581
|
+
return { $anchor, $head, indexes };
|
|
491
582
|
}
|
|
492
|
-
function
|
|
493
|
-
const { tr
|
|
494
|
-
|
|
495
|
-
const
|
|
496
|
-
if (
|
|
497
|
-
const
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
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 (!
|
|
507
|
-
const
|
|
508
|
-
|
|
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
|
|
511
|
-
const { tr
|
|
512
|
-
|
|
513
|
-
const
|
|
514
|
-
if (
|
|
515
|
-
const
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
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 (!
|
|
521
|
-
const
|
|
522
|
-
|
|
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
|
|
637
|
+
const goToPrevTableCellCommand = $command(
|
|
525
638
|
"GoToPrevTableCell",
|
|
526
|
-
() => () =>
|
|
639
|
+
() => () => goToNextCell(-1)
|
|
527
640
|
);
|
|
528
|
-
|
|
641
|
+
withMeta(goToPrevTableCellCommand, {
|
|
529
642
|
displayName: "Command<goToPrevTableCellCommand>",
|
|
530
643
|
group: "Table"
|
|
531
644
|
});
|
|
532
|
-
const
|
|
645
|
+
const goToNextTableCellCommand = $command(
|
|
533
646
|
"GoToNextTableCell",
|
|
534
|
-
() => () =>
|
|
647
|
+
() => () => goToNextCell(1)
|
|
535
648
|
);
|
|
536
|
-
|
|
649
|
+
withMeta(goToNextTableCellCommand, {
|
|
537
650
|
displayName: "Command<goToNextTableCellCommand>",
|
|
538
651
|
group: "Table"
|
|
539
652
|
});
|
|
540
|
-
const
|
|
653
|
+
const exitTable = $command(
|
|
541
654
|
"ExitTable",
|
|
542
|
-
(
|
|
543
|
-
if (!
|
|
544
|
-
const { $head
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
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
|
-
|
|
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
|
-
|
|
671
|
+
withMeta(exitTable, {
|
|
555
672
|
displayName: "Command<breakTableCommand>",
|
|
556
673
|
group: "Table"
|
|
557
674
|
});
|
|
558
|
-
const
|
|
675
|
+
const insertTableCommand = $command(
|
|
559
676
|
"InsertTable",
|
|
560
|
-
(
|
|
561
|
-
const { selection
|
|
562
|
-
|
|
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
|
-
|
|
688
|
+
withMeta(insertTableCommand, {
|
|
566
689
|
displayName: "Command<insertTableCommand>",
|
|
567
690
|
group: "Table"
|
|
568
691
|
});
|
|
569
|
-
const
|
|
692
|
+
const moveRowCommand = $command(
|
|
570
693
|
"MoveRow",
|
|
571
|
-
() => ({ from
|
|
572
|
-
const { tr
|
|
573
|
-
|
|
574
|
-
|
|
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
|
-
|
|
702
|
+
withMeta(moveRowCommand, {
|
|
579
703
|
displayName: "Command<moveRowCommand>",
|
|
580
704
|
group: "Table"
|
|
581
705
|
});
|
|
582
|
-
const
|
|
706
|
+
const moveColCommand = $command(
|
|
583
707
|
"MoveCol",
|
|
584
|
-
() => ({ from
|
|
585
|
-
const { tr
|
|
586
|
-
|
|
587
|
-
|
|
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
|
-
|
|
716
|
+
withMeta(moveColCommand, {
|
|
592
717
|
displayName: "Command<moveColCommand>",
|
|
593
718
|
group: "Table"
|
|
594
719
|
});
|
|
595
|
-
const
|
|
720
|
+
const selectRowCommand = $command(
|
|
596
721
|
"SelectRow",
|
|
597
|
-
() => (
|
|
598
|
-
const { tr
|
|
599
|
-
|
|
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
|
-
|
|
728
|
+
withMeta(selectRowCommand, {
|
|
603
729
|
displayName: "Command<selectRowCommand>",
|
|
604
730
|
group: "Table"
|
|
605
731
|
});
|
|
606
|
-
const
|
|
732
|
+
const selectColCommand = $command(
|
|
607
733
|
"SelectCol",
|
|
608
|
-
() => (
|
|
609
|
-
const { tr
|
|
610
|
-
|
|
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
|
-
|
|
740
|
+
withMeta(selectColCommand, {
|
|
614
741
|
displayName: "Command<selectColCommand>",
|
|
615
742
|
group: "Table"
|
|
616
743
|
});
|
|
617
|
-
const
|
|
744
|
+
const selectTableCommand = $command(
|
|
618
745
|
"SelectTable",
|
|
619
|
-
() => () => (
|
|
620
|
-
const { tr
|
|
621
|
-
|
|
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
|
-
|
|
752
|
+
withMeta(selectTableCommand, {
|
|
625
753
|
displayName: "Command<selectTableCommand>",
|
|
626
754
|
group: "Table"
|
|
627
755
|
});
|
|
628
|
-
const
|
|
756
|
+
const deleteSelectedCellsCommand = $command(
|
|
629
757
|
"DeleteSelectedCells",
|
|
630
|
-
() => () => (
|
|
631
|
-
const { selection
|
|
632
|
-
if (!(
|
|
633
|
-
const
|
|
634
|
-
|
|
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
|
-
|
|
768
|
+
withMeta(deleteSelectedCellsCommand, {
|
|
638
769
|
displayName: "Command<deleteSelectedCellsCommand>",
|
|
639
770
|
group: "Table"
|
|
640
771
|
});
|
|
641
|
-
const
|
|
772
|
+
const addColBeforeCommand = $command(
|
|
642
773
|
"AddColBefore",
|
|
643
|
-
() => () =>
|
|
774
|
+
() => () => addColumnBefore
|
|
644
775
|
);
|
|
645
|
-
|
|
776
|
+
withMeta(addColBeforeCommand, {
|
|
646
777
|
displayName: "Command<addColBeforeCommand>",
|
|
647
778
|
group: "Table"
|
|
648
779
|
});
|
|
649
|
-
const
|
|
780
|
+
const addColAfterCommand = $command(
|
|
650
781
|
"AddColAfter",
|
|
651
|
-
() => () =>
|
|
782
|
+
() => () => addColumnAfter
|
|
652
783
|
);
|
|
653
|
-
|
|
784
|
+
withMeta(addColAfterCommand, {
|
|
654
785
|
displayName: "Command<addColAfterCommand>",
|
|
655
786
|
group: "Table"
|
|
656
787
|
});
|
|
657
|
-
const
|
|
788
|
+
const addRowBeforeCommand = $command(
|
|
658
789
|
"AddRowBefore",
|
|
659
|
-
(
|
|
660
|
-
if (!
|
|
661
|
-
if (
|
|
662
|
-
const
|
|
663
|
-
|
|
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
|
|
796
|
+
return true;
|
|
666
797
|
}
|
|
667
798
|
);
|
|
668
|
-
|
|
799
|
+
withMeta(addRowBeforeCommand, {
|
|
669
800
|
displayName: "Command<addRowBeforeCommand>",
|
|
670
801
|
group: "Table"
|
|
671
802
|
});
|
|
672
|
-
const
|
|
803
|
+
const addRowAfterCommand = $command(
|
|
673
804
|
"AddRowAfter",
|
|
674
|
-
(
|
|
675
|
-
if (!
|
|
676
|
-
if (
|
|
677
|
-
const
|
|
678
|
-
|
|
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
|
|
811
|
+
return true;
|
|
681
812
|
}
|
|
682
813
|
);
|
|
683
|
-
|
|
814
|
+
withMeta(addRowAfterCommand, {
|
|
684
815
|
displayName: "Command<addRowAfterCommand>",
|
|
685
816
|
group: "Table"
|
|
686
817
|
});
|
|
687
|
-
const
|
|
818
|
+
const setAlignCommand = $command(
|
|
688
819
|
"SetAlign",
|
|
689
|
-
() => (
|
|
820
|
+
() => (alignment = "left") => setCellAttr("alignment", alignment)
|
|
690
821
|
);
|
|
691
|
-
|
|
822
|
+
withMeta(setAlignCommand, {
|
|
692
823
|
displayName: "Command<setAlignCommand>",
|
|
693
824
|
group: "Table"
|
|
694
825
|
});
|
|
695
|
-
const
|
|
696
|
-
(
|
|
826
|
+
const insertTableInputRule = $inputRule(
|
|
827
|
+
(ctx) => new InputRule(
|
|
697
828
|
/^\|(?<col>\d+)[xX](?<row>\d+)\|\s$/,
|
|
698
|
-
(
|
|
699
|
-
var
|
|
700
|
-
const
|
|
701
|
-
if (
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
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
|
|
708
|
-
|
|
709
|
-
Number((
|
|
710
|
-
Number((
|
|
711
|
-
)
|
|
712
|
-
|
|
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
|
-
|
|
848
|
+
withMeta(insertTableInputRule, {
|
|
717
849
|
displayName: "InputRule<insertTableInputRule>",
|
|
718
850
|
group: "Table"
|
|
719
851
|
});
|
|
720
|
-
const
|
|
852
|
+
const tableKeymap = $useKeymap("tableKeymap", {
|
|
721
853
|
NextCell: {
|
|
722
854
|
shortcuts: ["Mod-]", "Tab"],
|
|
723
|
-
command: (
|
|
724
|
-
const
|
|
725
|
-
return () =>
|
|
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: (
|
|
731
|
-
const
|
|
732
|
-
return () =>
|
|
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: (
|
|
738
|
-
const
|
|
739
|
-
return () =>
|
|
869
|
+
command: (ctx) => {
|
|
870
|
+
const commands2 = ctx.get(commandsCtx);
|
|
871
|
+
return () => commands2.call(exitTable.key);
|
|
740
872
|
}
|
|
741
873
|
}
|
|
742
874
|
});
|
|
743
|
-
|
|
875
|
+
withMeta(tableKeymap.ctx, {
|
|
744
876
|
displayName: "KeymapCtx<table>",
|
|
745
877
|
group: "Table"
|
|
746
878
|
});
|
|
747
|
-
|
|
879
|
+
withMeta(tableKeymap.shortcuts, {
|
|
748
880
|
displayName: "Keymap<table>",
|
|
749
881
|
group: "Table"
|
|
750
882
|
});
|
|
751
|
-
const
|
|
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:
|
|
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="${
|
|
765
|
-
getAttrs: (
|
|
766
|
-
if (!(
|
|
898
|
+
tag: `dl[data-type="${id$1}"]`,
|
|
899
|
+
getAttrs: (dom) => {
|
|
900
|
+
if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom);
|
|
767
901
|
return {
|
|
768
|
-
label:
|
|
902
|
+
label: dom.dataset.label
|
|
769
903
|
};
|
|
770
904
|
},
|
|
771
905
|
contentElement: "dd"
|
|
772
906
|
}
|
|
773
907
|
],
|
|
774
|
-
toDOM: (
|
|
775
|
-
const
|
|
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":
|
|
781
|
-
"data-type":
|
|
914
|
+
"data-label": label,
|
|
915
|
+
"data-type": id$1
|
|
782
916
|
},
|
|
783
|
-
["dt",
|
|
917
|
+
["dt", label],
|
|
784
918
|
["dd", 0]
|
|
785
919
|
];
|
|
786
920
|
},
|
|
787
921
|
parseMarkdown: {
|
|
788
|
-
match: ({ type
|
|
789
|
-
runner: (
|
|
790
|
-
|
|
791
|
-
label:
|
|
792
|
-
}).next(
|
|
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: (
|
|
797
|
-
runner: (
|
|
798
|
-
|
|
799
|
-
label:
|
|
800
|
-
identifier:
|
|
801
|
-
}).next(
|
|
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
|
-
|
|
940
|
+
withMeta(footnoteDefinitionSchema.ctx, {
|
|
807
941
|
displayName: "NodeSchemaCtx<footnodeDef>",
|
|
808
942
|
group: "footnote"
|
|
809
943
|
});
|
|
810
|
-
|
|
944
|
+
withMeta(footnoteDefinitionSchema.node, {
|
|
811
945
|
displayName: "NodeSchema<footnodeDef>",
|
|
812
946
|
group: "footnote"
|
|
813
947
|
});
|
|
814
|
-
const
|
|
948
|
+
const id = "footnote_reference";
|
|
949
|
+
const footnoteReferenceSchema = $nodeSchema(
|
|
815
950
|
"footnote_reference",
|
|
816
951
|
() => ({
|
|
817
952
|
group: "inline",
|
|
818
|
-
inline:
|
|
819
|
-
atom:
|
|
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="${
|
|
828
|
-
getAttrs: (
|
|
829
|
-
if (!(
|
|
962
|
+
tag: `sup[data-type="${id}"]`,
|
|
963
|
+
getAttrs: (dom) => {
|
|
964
|
+
if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom);
|
|
830
965
|
return {
|
|
831
|
-
label:
|
|
966
|
+
label: dom.dataset.label
|
|
832
967
|
};
|
|
833
968
|
}
|
|
834
969
|
}
|
|
835
970
|
],
|
|
836
|
-
toDOM: (
|
|
837
|
-
const
|
|
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":
|
|
843
|
-
"data-type":
|
|
977
|
+
"data-label": label,
|
|
978
|
+
"data-type": id
|
|
844
979
|
},
|
|
845
|
-
|
|
980
|
+
label
|
|
846
981
|
];
|
|
847
982
|
},
|
|
848
983
|
parseMarkdown: {
|
|
849
|
-
match: ({ type
|
|
850
|
-
runner: (
|
|
851
|
-
|
|
852
|
-
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: (
|
|
858
|
-
runner: (
|
|
859
|
-
|
|
860
|
-
label:
|
|
861
|
-
identifier:
|
|
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
|
-
|
|
1002
|
+
withMeta(footnoteReferenceSchema.ctx, {
|
|
868
1003
|
displayName: "NodeSchemaCtx<footnodeRef>",
|
|
869
1004
|
group: "footnote"
|
|
870
1005
|
});
|
|
871
|
-
|
|
1006
|
+
withMeta(footnoteReferenceSchema.node, {
|
|
872
1007
|
displayName: "NodeSchema<footnodeRef>",
|
|
873
1008
|
group: "footnote"
|
|
874
1009
|
});
|
|
875
|
-
const
|
|
876
|
-
(
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
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
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
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
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
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
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
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
|
-
|
|
1093
|
+
withMeta(extendListItemSchemaForTask, {
|
|
943
1094
|
displayName: "NodeSchema<listItem>",
|
|
944
1095
|
group: "ListItem"
|
|
945
1096
|
});
|
|
946
|
-
const
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
checked
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
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
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
].flat()
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
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
|
|
978
|
-
|
|
1139
|
+
const columnResizingPlugin = $prose(() => columnResizing({}));
|
|
1140
|
+
withMeta(columnResizingPlugin, {
|
|
979
1141
|
displayName: "Prose<columnResizingPlugin>",
|
|
980
1142
|
group: "Prose"
|
|
981
1143
|
});
|
|
982
|
-
const
|
|
983
|
-
() =>
|
|
1144
|
+
const tableEditingPlugin = $prose(
|
|
1145
|
+
() => tableEditing({ allowTableNodeSelection: true })
|
|
984
1146
|
);
|
|
985
|
-
|
|
1147
|
+
withMeta(tableEditingPlugin, {
|
|
986
1148
|
displayName: "Prose<tableEditingPlugin>",
|
|
987
1149
|
group: "Prose"
|
|
988
1150
|
});
|
|
989
|
-
const
|
|
990
|
-
|
|
1151
|
+
const remarkGFMPlugin = $remark("remarkGFM", () => remarkGFM);
|
|
1152
|
+
withMeta(remarkGFMPlugin.plugin, {
|
|
991
1153
|
displayName: "Remark<remarkGFMPlugin>",
|
|
992
1154
|
group: "Remark"
|
|
993
1155
|
});
|
|
994
|
-
|
|
1156
|
+
withMeta(remarkGFMPlugin.options, {
|
|
995
1157
|
displayName: "RemarkConfig<remarkGFMPlugin>",
|
|
996
1158
|
group: "Remark"
|
|
997
1159
|
});
|
|
998
|
-
const
|
|
999
|
-
function
|
|
1000
|
-
let
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
})
|
|
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
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
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
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
].flat()
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
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
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
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
|