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