@milkdown/preset-gfm 7.6.3 → 7.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.es.js +882 -709
- package/lib/index.es.js.map +1 -1
- package/lib/node/table/input.d.ts.map +1 -1
- package/lib/node/table/utils.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/node/table/input.ts +4 -6
package/lib/index.es.js
CHANGED
|
@@ -1,759 +1,890 @@
|
|
|
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
|
-
|
|
710
|
-
|
|
711
|
-
), c = t.tr.replaceRangeWith(o, l, s);
|
|
712
|
-
return c.setSelection(Qe.create(c.doc, o + 3)).scrollIntoView();
|
|
838
|
+
const row = Math.max(Number(((_a = match.groups) == null ? void 0 : _a.row) ?? 0), 2);
|
|
839
|
+
const tableNode = createTable(ctx, row, Number((_b = match.groups) == null ? void 0 : _b.col));
|
|
840
|
+
const tr = state.tr.replaceRangeWith(start, end, tableNode);
|
|
841
|
+
return tr.setSelection(TextSelection.create(tr.doc, start + 3)).scrollIntoView();
|
|
713
842
|
}
|
|
714
843
|
)
|
|
715
844
|
);
|
|
716
|
-
|
|
845
|
+
withMeta(insertTableInputRule, {
|
|
717
846
|
displayName: "InputRule<insertTableInputRule>",
|
|
718
847
|
group: "Table"
|
|
719
848
|
});
|
|
720
|
-
const
|
|
849
|
+
const tableKeymap = $useKeymap("tableKeymap", {
|
|
721
850
|
NextCell: {
|
|
722
851
|
shortcuts: ["Mod-]", "Tab"],
|
|
723
|
-
command: (
|
|
724
|
-
const
|
|
725
|
-
return () =>
|
|
852
|
+
command: (ctx) => {
|
|
853
|
+
const commands2 = ctx.get(commandsCtx);
|
|
854
|
+
return () => commands2.call(goToNextTableCellCommand.key);
|
|
726
855
|
}
|
|
727
856
|
},
|
|
728
857
|
PrevCell: {
|
|
729
858
|
shortcuts: ["Mod-[", "Shift-Tab"],
|
|
730
|
-
command: (
|
|
731
|
-
const
|
|
732
|
-
return () =>
|
|
859
|
+
command: (ctx) => {
|
|
860
|
+
const commands2 = ctx.get(commandsCtx);
|
|
861
|
+
return () => commands2.call(goToPrevTableCellCommand.key);
|
|
733
862
|
}
|
|
734
863
|
},
|
|
735
864
|
ExitTable: {
|
|
736
|
-
shortcuts: ["Mod-Enter"],
|
|
737
|
-
command: (
|
|
738
|
-
const
|
|
739
|
-
return () =>
|
|
865
|
+
shortcuts: ["Mod-Enter", "Enter"],
|
|
866
|
+
command: (ctx) => {
|
|
867
|
+
const commands2 = ctx.get(commandsCtx);
|
|
868
|
+
return () => commands2.call(exitTable.key);
|
|
740
869
|
}
|
|
741
870
|
}
|
|
742
871
|
});
|
|
743
|
-
|
|
872
|
+
withMeta(tableKeymap.ctx, {
|
|
744
873
|
displayName: "KeymapCtx<table>",
|
|
745
874
|
group: "Table"
|
|
746
875
|
});
|
|
747
|
-
|
|
876
|
+
withMeta(tableKeymap.shortcuts, {
|
|
748
877
|
displayName: "Keymap<table>",
|
|
749
878
|
group: "Table"
|
|
750
879
|
});
|
|
751
|
-
const
|
|
880
|
+
const id$1 = "footnote_definition";
|
|
881
|
+
const markdownId = "footnoteDefinition";
|
|
882
|
+
const footnoteDefinitionSchema = $nodeSchema(
|
|
752
883
|
"footnote_definition",
|
|
753
884
|
() => ({
|
|
754
885
|
group: "block",
|
|
755
886
|
content: "block+",
|
|
756
|
-
defining:
|
|
887
|
+
defining: true,
|
|
757
888
|
attrs: {
|
|
758
889
|
label: {
|
|
759
890
|
default: ""
|
|
@@ -761,62 +892,63 @@ const B = "footnote_definition", oe = "footnoteDefinition", J = C(
|
|
|
761
892
|
},
|
|
762
893
|
parseDOM: [
|
|
763
894
|
{
|
|
764
|
-
tag: `dl[data-type="${
|
|
765
|
-
getAttrs: (
|
|
766
|
-
if (!(
|
|
895
|
+
tag: `dl[data-type="${id$1}"]`,
|
|
896
|
+
getAttrs: (dom) => {
|
|
897
|
+
if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom);
|
|
767
898
|
return {
|
|
768
|
-
label:
|
|
899
|
+
label: dom.dataset.label
|
|
769
900
|
};
|
|
770
901
|
},
|
|
771
902
|
contentElement: "dd"
|
|
772
903
|
}
|
|
773
904
|
],
|
|
774
|
-
toDOM: (
|
|
775
|
-
const
|
|
905
|
+
toDOM: (node) => {
|
|
906
|
+
const label = node.attrs.label;
|
|
776
907
|
return [
|
|
777
908
|
"dl",
|
|
778
909
|
{
|
|
779
910
|
// TODO: add a prosemirror plugin to sync label on change
|
|
780
|
-
"data-label":
|
|
781
|
-
"data-type":
|
|
911
|
+
"data-label": label,
|
|
912
|
+
"data-type": id$1
|
|
782
913
|
},
|
|
783
|
-
["dt",
|
|
914
|
+
["dt", label],
|
|
784
915
|
["dd", 0]
|
|
785
916
|
];
|
|
786
917
|
},
|
|
787
918
|
parseMarkdown: {
|
|
788
|
-
match: ({ type
|
|
789
|
-
runner: (
|
|
790
|
-
|
|
791
|
-
label:
|
|
792
|
-
}).next(
|
|
919
|
+
match: ({ type }) => type === markdownId,
|
|
920
|
+
runner: (state, node, type) => {
|
|
921
|
+
state.openNode(type, {
|
|
922
|
+
label: node.label
|
|
923
|
+
}).next(node.children).closeNode();
|
|
793
924
|
}
|
|
794
925
|
},
|
|
795
926
|
toMarkdown: {
|
|
796
|
-
match: (
|
|
797
|
-
runner: (
|
|
798
|
-
|
|
799
|
-
label:
|
|
800
|
-
identifier:
|
|
801
|
-
}).next(
|
|
927
|
+
match: (node) => node.type.name === id$1,
|
|
928
|
+
runner: (state, node) => {
|
|
929
|
+
state.openNode(markdownId, void 0, {
|
|
930
|
+
label: node.attrs.label,
|
|
931
|
+
identifier: node.attrs.label
|
|
932
|
+
}).next(node.content).closeNode();
|
|
802
933
|
}
|
|
803
934
|
}
|
|
804
935
|
})
|
|
805
936
|
);
|
|
806
|
-
|
|
937
|
+
withMeta(footnoteDefinitionSchema.ctx, {
|
|
807
938
|
displayName: "NodeSchemaCtx<footnodeDef>",
|
|
808
939
|
group: "footnote"
|
|
809
940
|
});
|
|
810
|
-
|
|
941
|
+
withMeta(footnoteDefinitionSchema.node, {
|
|
811
942
|
displayName: "NodeSchema<footnodeDef>",
|
|
812
943
|
group: "footnote"
|
|
813
944
|
});
|
|
814
|
-
const
|
|
945
|
+
const id = "footnote_reference";
|
|
946
|
+
const footnoteReferenceSchema = $nodeSchema(
|
|
815
947
|
"footnote_reference",
|
|
816
948
|
() => ({
|
|
817
949
|
group: "inline",
|
|
818
|
-
inline:
|
|
819
|
-
atom:
|
|
950
|
+
inline: true,
|
|
951
|
+
atom: true,
|
|
820
952
|
attrs: {
|
|
821
953
|
label: {
|
|
822
954
|
default: ""
|
|
@@ -824,300 +956,341 @@ const L = "footnote_reference", Q = C(
|
|
|
824
956
|
},
|
|
825
957
|
parseDOM: [
|
|
826
958
|
{
|
|
827
|
-
tag: `sup[data-type="${
|
|
828
|
-
getAttrs: (
|
|
829
|
-
if (!(
|
|
959
|
+
tag: `sup[data-type="${id}"]`,
|
|
960
|
+
getAttrs: (dom) => {
|
|
961
|
+
if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom);
|
|
830
962
|
return {
|
|
831
|
-
label:
|
|
963
|
+
label: dom.dataset.label
|
|
832
964
|
};
|
|
833
965
|
}
|
|
834
966
|
}
|
|
835
967
|
],
|
|
836
|
-
toDOM: (
|
|
837
|
-
const
|
|
968
|
+
toDOM: (node) => {
|
|
969
|
+
const label = node.attrs.label;
|
|
838
970
|
return [
|
|
839
971
|
"sup",
|
|
840
972
|
{
|
|
841
973
|
// TODO: add a prosemirror plugin to sync label on change
|
|
842
|
-
"data-label":
|
|
843
|
-
"data-type":
|
|
974
|
+
"data-label": label,
|
|
975
|
+
"data-type": id
|
|
844
976
|
},
|
|
845
|
-
|
|
977
|
+
label
|
|
846
978
|
];
|
|
847
979
|
},
|
|
848
980
|
parseMarkdown: {
|
|
849
|
-
match: ({ type
|
|
850
|
-
runner: (
|
|
851
|
-
|
|
852
|
-
label:
|
|
981
|
+
match: ({ type }) => type === "footnoteReference",
|
|
982
|
+
runner: (state, node, type) => {
|
|
983
|
+
state.addNode(type, {
|
|
984
|
+
label: node.label
|
|
853
985
|
});
|
|
854
986
|
}
|
|
855
987
|
},
|
|
856
988
|
toMarkdown: {
|
|
857
|
-
match: (
|
|
858
|
-
runner: (
|
|
859
|
-
|
|
860
|
-
label:
|
|
861
|
-
identifier:
|
|
989
|
+
match: (node) => node.type.name === id,
|
|
990
|
+
runner: (state, node) => {
|
|
991
|
+
state.addNode("footnoteReference", void 0, void 0, {
|
|
992
|
+
label: node.attrs.label,
|
|
993
|
+
identifier: node.attrs.label
|
|
862
994
|
});
|
|
863
995
|
}
|
|
864
996
|
}
|
|
865
997
|
})
|
|
866
998
|
);
|
|
867
|
-
|
|
999
|
+
withMeta(footnoteReferenceSchema.ctx, {
|
|
868
1000
|
displayName: "NodeSchemaCtx<footnodeRef>",
|
|
869
1001
|
group: "footnote"
|
|
870
1002
|
});
|
|
871
|
-
|
|
1003
|
+
withMeta(footnoteReferenceSchema.node, {
|
|
872
1004
|
displayName: "NodeSchema<footnodeRef>",
|
|
873
1005
|
group: "footnote"
|
|
874
1006
|
});
|
|
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
|
-
};
|
|
1007
|
+
const extendListItemSchemaForTask = listItemSchema.extendSchema(
|
|
1008
|
+
(prev) => {
|
|
1009
|
+
return (ctx) => {
|
|
1010
|
+
const baseSchema = prev(ctx);
|
|
1011
|
+
return {
|
|
1012
|
+
...baseSchema,
|
|
1013
|
+
attrs: {
|
|
1014
|
+
...baseSchema.attrs,
|
|
1015
|
+
checked: {
|
|
1016
|
+
default: null
|
|
897
1017
|
}
|
|
898
1018
|
},
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
1019
|
+
parseDOM: [
|
|
1020
|
+
{
|
|
1021
|
+
tag: 'li[data-item-type="task"]',
|
|
1022
|
+
getAttrs: (dom) => {
|
|
1023
|
+
if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom);
|
|
1024
|
+
return {
|
|
1025
|
+
label: dom.dataset.label,
|
|
1026
|
+
listType: dom.dataset.listType,
|
|
1027
|
+
spread: dom.dataset.spread,
|
|
1028
|
+
checked: dom.dataset.checked ? dom.dataset.checked === "true" : null
|
|
1029
|
+
};
|
|
1030
|
+
}
|
|
1031
|
+
},
|
|
1032
|
+
...(baseSchema == null ? void 0 : baseSchema.parseDOM) || []
|
|
1033
|
+
],
|
|
1034
|
+
toDOM: (node) => {
|
|
1035
|
+
if (baseSchema.toDOM && node.attrs.checked == null)
|
|
1036
|
+
return baseSchema.toDOM(node);
|
|
1037
|
+
return [
|
|
1038
|
+
"li",
|
|
1039
|
+
{
|
|
1040
|
+
"data-item-type": "task",
|
|
1041
|
+
"data-label": node.attrs.label,
|
|
1042
|
+
"data-list-type": node.attrs.listType,
|
|
1043
|
+
"data-spread": node.attrs.spread,
|
|
1044
|
+
"data-checked": node.attrs.checked
|
|
1045
|
+
},
|
|
1046
|
+
0
|
|
1047
|
+
];
|
|
909
1048
|
},
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
1049
|
+
parseMarkdown: {
|
|
1050
|
+
match: ({ type }) => type === "listItem",
|
|
1051
|
+
runner: (state, node, type) => {
|
|
1052
|
+
if (node.checked == null) {
|
|
1053
|
+
baseSchema.parseMarkdown.runner(state, node, type);
|
|
1054
|
+
return;
|
|
1055
|
+
}
|
|
1056
|
+
const label = node.label != null ? `${node.label}.` : "•";
|
|
1057
|
+
const checked = node.checked != null ? Boolean(node.checked) : null;
|
|
1058
|
+
const listType = node.label != null ? "ordered" : "bullet";
|
|
1059
|
+
const spread = node.spread != null ? `${node.spread}` : "true";
|
|
1060
|
+
state.openNode(type, { label, listType, spread, checked });
|
|
1061
|
+
state.next(node.children);
|
|
1062
|
+
state.closeNode();
|
|
918
1063
|
}
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
1064
|
+
},
|
|
1065
|
+
toMarkdown: {
|
|
1066
|
+
match: (node) => node.type.name === "list_item",
|
|
1067
|
+
runner: (state, node) => {
|
|
1068
|
+
if (node.attrs.checked == null) {
|
|
1069
|
+
baseSchema.toMarkdown.runner(state, node);
|
|
1070
|
+
return;
|
|
1071
|
+
}
|
|
1072
|
+
const label = node.attrs.label;
|
|
1073
|
+
const listType = node.attrs.listType;
|
|
1074
|
+
const spread = node.attrs.spread === "true";
|
|
1075
|
+
const checked = node.attrs.checked;
|
|
1076
|
+
state.openNode("listItem", void 0, {
|
|
1077
|
+
label,
|
|
1078
|
+
listType,
|
|
1079
|
+
spread,
|
|
1080
|
+
checked
|
|
1081
|
+
});
|
|
1082
|
+
state.next(node.content);
|
|
1083
|
+
state.closeNode();
|
|
929
1084
|
}
|
|
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
1085
|
}
|
|
938
|
-
}
|
|
1086
|
+
};
|
|
939
1087
|
};
|
|
940
1088
|
}
|
|
941
1089
|
);
|
|
942
|
-
|
|
1090
|
+
withMeta(extendListItemSchemaForTask, {
|
|
943
1091
|
displayName: "NodeSchema<listItem>",
|
|
944
1092
|
group: "ListItem"
|
|
945
1093
|
});
|
|
946
|
-
const
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
checked
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
1094
|
+
const wrapInTaskListInputRule = $inputRule(() => {
|
|
1095
|
+
return new InputRule(
|
|
1096
|
+
/^\[(?<checked>\s|x)\]\s$/,
|
|
1097
|
+
(state, match, start, end) => {
|
|
1098
|
+
var _a;
|
|
1099
|
+
const pos = state.doc.resolve(start);
|
|
1100
|
+
let depth = 0;
|
|
1101
|
+
let node = pos.node(depth);
|
|
1102
|
+
while (node && node.type.name !== "list_item") {
|
|
1103
|
+
depth--;
|
|
1104
|
+
node = pos.node(depth);
|
|
1105
|
+
}
|
|
1106
|
+
if (!node || node.attrs.checked != null) return null;
|
|
1107
|
+
const checked = Boolean(((_a = match.groups) == null ? void 0 : _a.checked) === "x");
|
|
1108
|
+
const finPos = pos.before(depth);
|
|
1109
|
+
const tr = state.tr;
|
|
1110
|
+
tr.deleteRange(start, end).setNodeMarkup(finPos, void 0, {
|
|
1111
|
+
...node.attrs,
|
|
1112
|
+
checked
|
|
1113
|
+
});
|
|
1114
|
+
return tr;
|
|
1115
|
+
}
|
|
1116
|
+
);
|
|
1117
|
+
});
|
|
1118
|
+
withMeta(wrapInTaskListInputRule, {
|
|
963
1119
|
displayName: "InputRule<wrapInTaskListInputRule>",
|
|
964
1120
|
group: "ListItem"
|
|
965
1121
|
});
|
|
966
|
-
const
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
].flat()
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
1122
|
+
const keymap = [
|
|
1123
|
+
strikethroughKeymap,
|
|
1124
|
+
tableKeymap
|
|
1125
|
+
].flat();
|
|
1126
|
+
const inputRules = [
|
|
1127
|
+
insertTableInputRule,
|
|
1128
|
+
wrapInTaskListInputRule
|
|
1129
|
+
];
|
|
1130
|
+
const markInputRules = [strikethroughInputRule];
|
|
1131
|
+
const autoInsertSpanPlugin = $prose(() => imeSpan);
|
|
1132
|
+
withMeta(autoInsertSpanPlugin, {
|
|
974
1133
|
displayName: "Prose<autoInsertSpanPlugin>",
|
|
975
1134
|
group: "Prose"
|
|
976
1135
|
});
|
|
977
|
-
const
|
|
978
|
-
|
|
1136
|
+
const columnResizingPlugin = $prose(() => columnResizing({}));
|
|
1137
|
+
withMeta(columnResizingPlugin, {
|
|
979
1138
|
displayName: "Prose<columnResizingPlugin>",
|
|
980
1139
|
group: "Prose"
|
|
981
1140
|
});
|
|
982
|
-
const
|
|
983
|
-
() =>
|
|
1141
|
+
const tableEditingPlugin = $prose(
|
|
1142
|
+
() => tableEditing({ allowTableNodeSelection: true })
|
|
984
1143
|
);
|
|
985
|
-
|
|
1144
|
+
withMeta(tableEditingPlugin, {
|
|
986
1145
|
displayName: "Prose<tableEditingPlugin>",
|
|
987
1146
|
group: "Prose"
|
|
988
1147
|
});
|
|
989
|
-
const
|
|
990
|
-
|
|
1148
|
+
const remarkGFMPlugin = $remark("remarkGFM", () => remarkGFM);
|
|
1149
|
+
withMeta(remarkGFMPlugin.plugin, {
|
|
991
1150
|
displayName: "Remark<remarkGFMPlugin>",
|
|
992
1151
|
group: "Remark"
|
|
993
1152
|
});
|
|
994
|
-
|
|
1153
|
+
withMeta(remarkGFMPlugin.options, {
|
|
995
1154
|
displayName: "RemarkConfig<remarkGFMPlugin>",
|
|
996
1155
|
group: "Remark"
|
|
997
1156
|
});
|
|
998
|
-
const
|
|
999
|
-
function
|
|
1000
|
-
let
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
})
|
|
1157
|
+
const pluginKey = new PluginKey("MILKDOWN_KEEP_TABLE_ALIGN_PLUGIN");
|
|
1158
|
+
function getChildIndex(node, parent) {
|
|
1159
|
+
let index = 0;
|
|
1160
|
+
parent.forEach((child, _offset, i) => {
|
|
1161
|
+
if (child === node) index = i;
|
|
1162
|
+
});
|
|
1163
|
+
return index;
|
|
1004
1164
|
}
|
|
1005
|
-
const
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1165
|
+
const keepTableAlignPlugin = $prose(() => {
|
|
1166
|
+
return new Plugin({
|
|
1167
|
+
key: pluginKey,
|
|
1168
|
+
appendTransaction: (_tr, oldState, state) => {
|
|
1169
|
+
let tr;
|
|
1170
|
+
const check = (node, pos) => {
|
|
1171
|
+
if (!tr) tr = state.tr;
|
|
1172
|
+
if (node.type.name !== "table_cell") return;
|
|
1173
|
+
const $pos = state.doc.resolve(pos);
|
|
1174
|
+
const tableRow = $pos.node($pos.depth);
|
|
1175
|
+
const table = $pos.node($pos.depth - 1);
|
|
1176
|
+
const tableHeaderRow = table.firstChild;
|
|
1177
|
+
if (!tableHeaderRow) return;
|
|
1178
|
+
const index = getChildIndex(node, tableRow);
|
|
1179
|
+
const headerCell = tableHeaderRow.maybeChild(index);
|
|
1180
|
+
if (!headerCell) return;
|
|
1181
|
+
const align = headerCell.attrs.alignment;
|
|
1182
|
+
const currentAlign = node.attrs.alignment;
|
|
1183
|
+
if (align === currentAlign) return;
|
|
1184
|
+
tr.setNodeMarkup(pos, void 0, { ...node.attrs, alignment: align });
|
|
1185
|
+
};
|
|
1186
|
+
if (oldState.doc !== state.doc) state.doc.descendants(check);
|
|
1187
|
+
return tr;
|
|
1188
|
+
}
|
|
1189
|
+
});
|
|
1190
|
+
});
|
|
1191
|
+
withMeta(keepTableAlignPlugin, {
|
|
1022
1192
|
displayName: "Prose<keepTableAlignPlugin>",
|
|
1023
1193
|
group: "Prose"
|
|
1024
1194
|
});
|
|
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
|
-
|
|
1195
|
+
const plugins = [
|
|
1196
|
+
keepTableAlignPlugin,
|
|
1197
|
+
autoInsertSpanPlugin,
|
|
1198
|
+
remarkGFMPlugin,
|
|
1199
|
+
tableEditingPlugin
|
|
1200
|
+
].flat();
|
|
1201
|
+
const schema = [
|
|
1202
|
+
extendListItemSchemaForTask,
|
|
1203
|
+
tableSchema,
|
|
1204
|
+
tableHeaderRowSchema,
|
|
1205
|
+
tableRowSchema,
|
|
1206
|
+
tableHeaderSchema,
|
|
1207
|
+
tableCellSchema,
|
|
1208
|
+
footnoteDefinitionSchema,
|
|
1209
|
+
footnoteReferenceSchema,
|
|
1210
|
+
strikethroughAttr,
|
|
1211
|
+
strikethroughSchema
|
|
1212
|
+
].flat();
|
|
1213
|
+
const commands = [
|
|
1214
|
+
goToNextTableCellCommand,
|
|
1215
|
+
goToPrevTableCellCommand,
|
|
1216
|
+
exitTable,
|
|
1217
|
+
insertTableCommand,
|
|
1218
|
+
moveRowCommand,
|
|
1219
|
+
moveColCommand,
|
|
1220
|
+
selectRowCommand,
|
|
1221
|
+
selectColCommand,
|
|
1222
|
+
selectTableCommand,
|
|
1223
|
+
deleteSelectedCellsCommand,
|
|
1224
|
+
addRowBeforeCommand,
|
|
1225
|
+
addRowAfterCommand,
|
|
1226
|
+
addColBeforeCommand,
|
|
1227
|
+
addColAfterCommand,
|
|
1228
|
+
setAlignCommand,
|
|
1229
|
+
toggleStrikethroughCommand
|
|
1230
|
+
];
|
|
1231
|
+
const gfm = [
|
|
1232
|
+
schema,
|
|
1233
|
+
inputRules,
|
|
1234
|
+
markInputRules,
|
|
1235
|
+
keymap,
|
|
1236
|
+
commands,
|
|
1237
|
+
plugins
|
|
1065
1238
|
].flat();
|
|
1066
1239
|
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
|
-
|
|
1240
|
+
addColAfterCommand,
|
|
1241
|
+
addColBeforeCommand,
|
|
1242
|
+
addRowAfterCommand,
|
|
1243
|
+
addRowBeforeCommand,
|
|
1244
|
+
addRowWithAlignment,
|
|
1245
|
+
autoInsertSpanPlugin,
|
|
1246
|
+
columnResizingPlugin,
|
|
1247
|
+
commands,
|
|
1248
|
+
createTable,
|
|
1249
|
+
deleteSelectedCellsCommand,
|
|
1250
|
+
exitTable,
|
|
1251
|
+
extendListItemSchemaForTask,
|
|
1252
|
+
findTable,
|
|
1253
|
+
footnoteDefinitionSchema,
|
|
1254
|
+
footnoteReferenceSchema,
|
|
1255
|
+
getAllCellsInTable,
|
|
1256
|
+
getCellsInCol,
|
|
1257
|
+
getCellsInRow,
|
|
1258
|
+
gfm,
|
|
1259
|
+
goToNextTableCellCommand,
|
|
1260
|
+
goToPrevTableCellCommand,
|
|
1261
|
+
inputRules,
|
|
1262
|
+
insertTableCommand,
|
|
1263
|
+
insertTableInputRule,
|
|
1264
|
+
keepTableAlignPlugin,
|
|
1265
|
+
keymap,
|
|
1266
|
+
markInputRules,
|
|
1267
|
+
moveCol,
|
|
1268
|
+
moveColCommand,
|
|
1269
|
+
moveRow,
|
|
1270
|
+
moveRowCommand,
|
|
1271
|
+
plugins,
|
|
1272
|
+
remarkGFMPlugin,
|
|
1273
|
+
schema,
|
|
1274
|
+
selectCol,
|
|
1275
|
+
selectColCommand,
|
|
1276
|
+
selectLine,
|
|
1277
|
+
selectRow,
|
|
1278
|
+
selectRowCommand,
|
|
1279
|
+
selectTable,
|
|
1280
|
+
selectTableCommand,
|
|
1281
|
+
setAlignCommand,
|
|
1282
|
+
strikethroughAttr,
|
|
1283
|
+
strikethroughInputRule,
|
|
1284
|
+
strikethroughKeymap,
|
|
1285
|
+
strikethroughSchema,
|
|
1286
|
+
tableCellSchema,
|
|
1287
|
+
tableEditingPlugin,
|
|
1288
|
+
tableHeaderRowSchema,
|
|
1289
|
+
tableHeaderSchema,
|
|
1290
|
+
tableKeymap,
|
|
1291
|
+
tableRowSchema,
|
|
1292
|
+
tableSchema,
|
|
1293
|
+
toggleStrikethroughCommand,
|
|
1294
|
+
wrapInTaskListInputRule
|
|
1122
1295
|
};
|
|
1123
1296
|
//# sourceMappingURL=index.es.js.map
|