@milkdown/preset-gfm 5.5.0 → 6.0.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/README.md +4 -4
- package/lib/{src/auto-link.d.ts → auto-link.d.ts} +0 -0
- package/lib/auto-link.d.ts.map +1 -0
- package/lib/footnote/definition.d.ts +7 -0
- package/lib/footnote/definition.d.ts.map +1 -0
- package/lib/footnote/index.d.ts +3 -0
- package/lib/footnote/index.d.ts.map +1 -0
- package/lib/footnote/reference.d.ts +7 -0
- package/lib/footnote/reference.d.ts.map +1 -0
- package/lib/footnote/utils.d.ts +3 -0
- package/lib/footnote/utils.d.ts.map +1 -0
- package/lib/index.d.ts +37 -1
- package/lib/index.d.ts.map +1 -0
- package/lib/index.es.js +569 -426
- package/lib/index.es.js.map +1 -1
- package/lib/{src/strike-through.d.ts → strike-through.d.ts} +1 -1
- package/lib/strike-through.d.ts.map +1 -0
- package/lib/{src/supported-keys.d.ts → supported-keys.d.ts} +0 -0
- package/lib/supported-keys.d.ts.map +1 -0
- package/lib/{src/table → table}/command.d.ts +0 -0
- package/lib/table/command.d.ts.map +1 -0
- package/lib/{src/table → table}/index.d.ts +0 -0
- package/lib/table/index.d.ts.map +1 -0
- package/lib/{src/table → table}/nodes/index.d.ts +3 -3
- package/lib/table/nodes/index.d.ts.map +1 -0
- package/lib/{src/table → table}/nodes/schema.d.ts +0 -0
- package/lib/table/nodes/schema.d.ts.map +1 -0
- package/lib/{src/table → table}/operator-plugin/actions.d.ts +0 -0
- package/lib/table/operator-plugin/actions.d.ts.map +1 -0
- package/lib/{src/table → table}/operator-plugin/calc-pos.d.ts +0 -0
- package/lib/table/operator-plugin/calc-pos.d.ts.map +1 -0
- package/lib/{src/table → table}/operator-plugin/constant.d.ts +0 -0
- package/lib/table/operator-plugin/constant.d.ts.map +1 -0
- package/lib/{src/table → table}/operator-plugin/helper.d.ts +0 -0
- package/lib/table/operator-plugin/helper.d.ts.map +1 -0
- package/lib/{src/table → table}/operator-plugin/index.d.ts +0 -0
- package/lib/table/operator-plugin/index.d.ts.map +1 -0
- package/lib/table/operator-plugin/style.d.ts +3 -0
- package/lib/table/operator-plugin/style.d.ts.map +1 -0
- package/lib/{src/table → table}/operator-plugin/widget.d.ts +0 -0
- package/lib/table/operator-plugin/widget.d.ts.map +1 -0
- package/lib/{src/table → table}/utils.d.ts +1 -0
- package/lib/table/utils.d.ts.map +1 -0
- package/lib/{src/task-list-item.d.ts → task-list-item.d.ts} +1 -1
- package/lib/task-list-item.d.ts.map +1 -0
- package/package.json +36 -12
- package/src/footnote/definition.ts +184 -0
- package/src/footnote/index.ts +3 -0
- package/src/footnote/reference.ts +171 -0
- package/src/footnote/utils.ts +4 -0
- package/src/index.ts +5 -0
- package/src/strike-through.ts +2 -9
- package/src/table/nodes/index.ts +0 -2
- package/src/table/operator-plugin/actions.ts +9 -9
- package/src/table/operator-plugin/index.ts +9 -8
- package/src/table/operator-plugin/style.ts +109 -37
- package/src/table/operator-plugin/widget.ts +3 -4
- package/src/task-list-item.ts +62 -127
- package/lib/src/auto-link.d.ts.map +0 -1
- package/lib/src/index.d.ts +0 -36
- package/lib/src/index.d.ts.map +0 -1
- package/lib/src/strike-through.d.ts.map +0 -1
- package/lib/src/supported-keys.d.ts.map +0 -1
- package/lib/src/table/command.d.ts.map +0 -1
- package/lib/src/table/index.d.ts.map +0 -1
- package/lib/src/table/nodes/index.d.ts.map +0 -1
- package/lib/src/table/nodes/schema.d.ts.map +0 -1
- package/lib/src/table/nodes/style.d.ts +0 -3
- package/lib/src/table/nodes/style.d.ts.map +0 -1
- package/lib/src/table/operator-plugin/actions.d.ts.map +0 -1
- package/lib/src/table/operator-plugin/calc-pos.d.ts.map +0 -1
- package/lib/src/table/operator-plugin/constant.d.ts.map +0 -1
- package/lib/src/table/operator-plugin/helper.d.ts.map +0 -1
- package/lib/src/table/operator-plugin/index.d.ts.map +0 -1
- package/lib/src/table/operator-plugin/style.d.ts +0 -3
- package/lib/src/table/operator-plugin/style.d.ts.map +0 -1
- package/lib/src/table/operator-plugin/widget.d.ts.map +0 -1
- package/lib/src/table/utils.d.ts.map +0 -1
- package/lib/src/task-list-item.d.ts.map +0 -1
- package/src/table/nodes/style.ts +0 -170
package/lib/index.es.js
CHANGED
|
@@ -4,7 +4,7 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
|
4
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj,
|
|
7
|
+
var __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp(obj, key2, { enumerable: true, configurable: true, writable: true, value }) : obj[key2] = value;
|
|
8
8
|
var __spreadValues = (a, b) => {
|
|
9
9
|
for (var prop in b || (b = {}))
|
|
10
10
|
if (__hasOwnProp.call(b, prop))
|
|
@@ -19,10 +19,10 @@ var __spreadValues = (a, b) => {
|
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
20
|
import { SupportedKeys as SupportedKeys$2, commonmark, commands as commands$1 } from "@milkdown/preset-commonmark";
|
|
21
21
|
export { InsertHardbreak, InsertHr, InsertImage, LiftListItem, ModifyImage, ModifyLink, SinkListItem, SplitListItem, ToggleBold, ToggleInlineCode, ToggleItalic, ToggleLink, TurnIntoCodeFence, TurnIntoHeading, TurnIntoText, WrapInBlockquote, WrapInBulletList, WrapInOrderedList, blockquote, bulletList, codeFence, codeInline, commonmark, commonmarkNodes, commonmarkPlugins, doc, em, hardbreak, heading, hr, image, link, listItem, orderedList, paragraph, strong, text } from "@milkdown/preset-commonmark";
|
|
22
|
-
import { $prose, createPlugin, createShortcut, createMark,
|
|
22
|
+
import { $prose, createNode, createPlugin, createShortcut, createMark, AtomList, $remark } from "@milkdown/utils";
|
|
23
23
|
import remarkGFM from "remark-gfm";
|
|
24
|
-
import { inputRules, InputRule, isInTable, Selection, findParentNode, TableMap,
|
|
25
|
-
import {
|
|
24
|
+
import { inputRules, InputRule, PluginKey, NodeSelection, findSelectedNodeOfType, wrappingInputRule, Plugin, isInTable, Selection, findParentNode, TableMap, CellSelection, cloneTr, tableNodeTypes, addColumnBefore, addColumnAfter, selectedRect, setCellAttr, deleteTable, deleteColumn, deleteRow, calculateNodePosition, Decoration, DecorationSet, tableNodes, TextSelection, goToNextCell, columnResizing, tableEditing, markRule, toggleMark, splitListItem, sinkListItem, liftListItem, wrapIn } from "@milkdown/prose";
|
|
25
|
+
import { createCmdKey, editorViewCtx, createCmd, commandsCtx, themeManagerCtx, ThemeIcon, ThemeBorder, ThemeShadow, getPalette, ThemeSize, schemaCtx } from "@milkdown/core";
|
|
26
26
|
const urlRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)$/;
|
|
27
27
|
const proseUrlPlugin = () => inputRules({
|
|
28
28
|
rules: [
|
|
@@ -36,6 +36,315 @@ const proseUrlPlugin = () => inputRules({
|
|
|
36
36
|
]
|
|
37
37
|
});
|
|
38
38
|
const urlPlugin = $prose(() => proseUrlPlugin());
|
|
39
|
+
const getFootnoteRefId = (label) => `footnote-ref-${label}`;
|
|
40
|
+
const getFootnoteDefId = (label) => `footnote-def-${label}`;
|
|
41
|
+
const key$1 = new PluginKey("MILKDOWN_PLUGIN_FOOTNOTE_DEF_INPUT");
|
|
42
|
+
const ModifyFootnoteDef = createCmdKey("ModifyFootnoteDef");
|
|
43
|
+
const footnoteDefinition = createNode((utils) => {
|
|
44
|
+
const id2 = "footnote_definition";
|
|
45
|
+
const markdownId = "footnoteDefinition";
|
|
46
|
+
return {
|
|
47
|
+
id: id2,
|
|
48
|
+
schema: (ctx) => ({
|
|
49
|
+
group: "block",
|
|
50
|
+
content: "block+",
|
|
51
|
+
defining: true,
|
|
52
|
+
attrs: {
|
|
53
|
+
label: {
|
|
54
|
+
default: ""
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
parseDOM: [
|
|
58
|
+
{
|
|
59
|
+
tag: `div[data-type="${id2}"]`,
|
|
60
|
+
getAttrs: (dom) => {
|
|
61
|
+
if (!(dom instanceof HTMLElement)) {
|
|
62
|
+
throw new Error();
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
label: dom.dataset["label"]
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
],
|
|
70
|
+
toDOM: (node) => {
|
|
71
|
+
const label = node.attrs["label"];
|
|
72
|
+
const className = utils.getClassName(node.attrs, "footnote-definition");
|
|
73
|
+
const dt = document.createElement("dt");
|
|
74
|
+
dt.textContent = `[${label}]:`;
|
|
75
|
+
dt.onclick = () => {
|
|
76
|
+
const view = ctx.get(editorViewCtx);
|
|
77
|
+
const selection = NodeSelection.create(view.state.doc, view.state.selection.from - 2);
|
|
78
|
+
view.dispatch(view.state.tr.setSelection(selection));
|
|
79
|
+
};
|
|
80
|
+
const a = document.createElement("a");
|
|
81
|
+
a.href = `#${getFootnoteRefId(label)}`;
|
|
82
|
+
a.contentEditable = "false";
|
|
83
|
+
a.textContent = "\u21A9";
|
|
84
|
+
a.onmousedown = (e) => {
|
|
85
|
+
e.preventDefault();
|
|
86
|
+
};
|
|
87
|
+
return [
|
|
88
|
+
"div",
|
|
89
|
+
{
|
|
90
|
+
class: className,
|
|
91
|
+
"data-label": label,
|
|
92
|
+
"data-type": id2,
|
|
93
|
+
id: getFootnoteDefId(label)
|
|
94
|
+
},
|
|
95
|
+
["div", { class: "footnote-definition_content" }, dt, ["dd", 0]],
|
|
96
|
+
["div", { class: "footnote-definition_anchor" }, a]
|
|
97
|
+
];
|
|
98
|
+
},
|
|
99
|
+
parseMarkdown: {
|
|
100
|
+
match: ({ type }) => type === markdownId,
|
|
101
|
+
runner: (state, node, type) => {
|
|
102
|
+
state.openNode(type, {
|
|
103
|
+
label: node["label"]
|
|
104
|
+
}).next(node.children).closeNode();
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
toMarkdown: {
|
|
108
|
+
match: (node) => node.type.name === id2,
|
|
109
|
+
runner: (state, node) => {
|
|
110
|
+
state.openNode(markdownId, void 0, {
|
|
111
|
+
label: node.attrs["label"],
|
|
112
|
+
identifier: node.attrs["label"]
|
|
113
|
+
}).next(node.content).closeNode();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}),
|
|
117
|
+
commands: (nodeType) => [
|
|
118
|
+
createCmd(ModifyFootnoteDef, (label = "") => (state, dispatch) => {
|
|
119
|
+
const node = findSelectedNodeOfType(state.selection, nodeType);
|
|
120
|
+
if (!node)
|
|
121
|
+
return false;
|
|
122
|
+
const { tr } = state;
|
|
123
|
+
const _tr = tr.setNodeMarkup(node.pos, void 0, __spreadProps(__spreadValues({}, node.node.attrs), { label }));
|
|
124
|
+
dispatch == null ? void 0 : dispatch(_tr.setSelection(NodeSelection.create(_tr.doc, node.pos)));
|
|
125
|
+
return true;
|
|
126
|
+
})
|
|
127
|
+
],
|
|
128
|
+
inputRules: (nodeType) => [
|
|
129
|
+
wrappingInputRule(/(?:\[\^)([^:]+)(?::)$/, nodeType, (match) => {
|
|
130
|
+
var _a;
|
|
131
|
+
const label = (_a = match[1]) != null ? _a : "footnote";
|
|
132
|
+
return {
|
|
133
|
+
label
|
|
134
|
+
};
|
|
135
|
+
}, () => false)
|
|
136
|
+
],
|
|
137
|
+
prosePlugins: (type, ctx) => {
|
|
138
|
+
return [
|
|
139
|
+
new Plugin({
|
|
140
|
+
key: key$1,
|
|
141
|
+
view: (editorView) => {
|
|
142
|
+
const inputChipRenderer = utils.themeManager.get("input-chip", {
|
|
143
|
+
width: "12em",
|
|
144
|
+
placeholder: "Input Footnote Label",
|
|
145
|
+
onUpdate: (value) => {
|
|
146
|
+
ctx.get(commandsCtx).call(ModifyFootnoteDef, value);
|
|
147
|
+
},
|
|
148
|
+
isBindMode: true
|
|
149
|
+
});
|
|
150
|
+
if (!inputChipRenderer)
|
|
151
|
+
return {};
|
|
152
|
+
const shouldDisplay = (view) => {
|
|
153
|
+
return Boolean(type && findSelectedNodeOfType(view.state.selection, type));
|
|
154
|
+
};
|
|
155
|
+
const getCurrentLabel = (view) => {
|
|
156
|
+
const result = findSelectedNodeOfType(view.state.selection, type);
|
|
157
|
+
if (!result)
|
|
158
|
+
return;
|
|
159
|
+
const value = result.node.attrs["label"];
|
|
160
|
+
return value;
|
|
161
|
+
};
|
|
162
|
+
const renderByView = (view) => {
|
|
163
|
+
if (!view.editable) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const display = shouldDisplay(view);
|
|
167
|
+
if (display) {
|
|
168
|
+
inputChipRenderer.show(view);
|
|
169
|
+
inputChipRenderer.update(getCurrentLabel(view));
|
|
170
|
+
} else {
|
|
171
|
+
inputChipRenderer.hide();
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
inputChipRenderer.init(editorView);
|
|
175
|
+
renderByView(editorView);
|
|
176
|
+
return {
|
|
177
|
+
update: (view, prevState) => {
|
|
178
|
+
const isEqualSelection = (prevState == null ? void 0 : prevState.doc.eq(view.state.doc)) && prevState.selection.eq(view.state.selection);
|
|
179
|
+
if (isEqualSelection)
|
|
180
|
+
return;
|
|
181
|
+
renderByView(view);
|
|
182
|
+
},
|
|
183
|
+
destroy: () => {
|
|
184
|
+
inputChipRenderer.destroy();
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
})
|
|
189
|
+
];
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
});
|
|
193
|
+
const ModifyFootnoteRef = createCmdKey("ModifyFootnoteRef");
|
|
194
|
+
const key = new PluginKey("MILKDOWN_PLUGIN_FOOTNOTE_REF_INPUT");
|
|
195
|
+
const footnoteReference = createNode((utils) => {
|
|
196
|
+
const id2 = "footnote_reference";
|
|
197
|
+
return {
|
|
198
|
+
id: id2,
|
|
199
|
+
schema: (ctx) => ({
|
|
200
|
+
group: "inline",
|
|
201
|
+
inline: true,
|
|
202
|
+
atom: true,
|
|
203
|
+
attrs: {
|
|
204
|
+
label: {
|
|
205
|
+
default: ""
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
parseDOM: [
|
|
209
|
+
{
|
|
210
|
+
tag: `sup[data-type="${id2}"]`,
|
|
211
|
+
getAttrs: (dom) => {
|
|
212
|
+
if (!(dom instanceof HTMLElement)) {
|
|
213
|
+
throw new Error();
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
label: dom.dataset["label"]
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
],
|
|
221
|
+
toDOM: (node) => {
|
|
222
|
+
const label = node.attrs["label"];
|
|
223
|
+
const a = document.createElement("a");
|
|
224
|
+
const href = `#${getFootnoteDefId(label)}`;
|
|
225
|
+
a.href = href;
|
|
226
|
+
a.textContent = `[${label}]`;
|
|
227
|
+
a.onclick = (e) => {
|
|
228
|
+
const view = ctx.get(editorViewCtx);
|
|
229
|
+
if (view.editable) {
|
|
230
|
+
e.preventDefault();
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
a.ondblclick = () => {
|
|
234
|
+
const view = ctx.get(editorViewCtx);
|
|
235
|
+
if (view.editable) {
|
|
236
|
+
window.location.href = href;
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
return [
|
|
240
|
+
"sup",
|
|
241
|
+
{
|
|
242
|
+
"data-label": label,
|
|
243
|
+
"data-type": id2,
|
|
244
|
+
id: getFootnoteRefId(label)
|
|
245
|
+
},
|
|
246
|
+
a
|
|
247
|
+
];
|
|
248
|
+
},
|
|
249
|
+
parseMarkdown: {
|
|
250
|
+
match: ({ type }) => type === "footnoteReference",
|
|
251
|
+
runner: (state, node, type) => {
|
|
252
|
+
state.addNode(type, {
|
|
253
|
+
label: node["label"]
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
toMarkdown: {
|
|
258
|
+
match: (node) => node.type.name === id2,
|
|
259
|
+
runner: (state, node) => {
|
|
260
|
+
state.addNode("footnoteReference", void 0, void 0, {
|
|
261
|
+
label: node.attrs["label"],
|
|
262
|
+
identifier: node.attrs["label"]
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}),
|
|
267
|
+
commands: (nodeType) => [
|
|
268
|
+
createCmd(ModifyFootnoteRef, (label = "") => (state, dispatch) => {
|
|
269
|
+
const node = findSelectedNodeOfType(state.selection, nodeType);
|
|
270
|
+
if (!node)
|
|
271
|
+
return false;
|
|
272
|
+
const { tr } = state;
|
|
273
|
+
const _tr = tr.setNodeMarkup(node.pos, void 0, __spreadProps(__spreadValues({}, node.node.attrs), { label }));
|
|
274
|
+
dispatch == null ? void 0 : dispatch(_tr.setSelection(NodeSelection.create(_tr.doc, node.pos)));
|
|
275
|
+
return true;
|
|
276
|
+
})
|
|
277
|
+
],
|
|
278
|
+
inputRules: (nodeType) => [
|
|
279
|
+
new InputRule(/(?:\[\^)([^\]]+)(?:\])$/, (state, match, start, end) => {
|
|
280
|
+
const $start = state.doc.resolve(start);
|
|
281
|
+
const index = $start.index();
|
|
282
|
+
const $end = state.doc.resolve(end);
|
|
283
|
+
if (!$start.parent.canReplaceWith(index, $end.index(), nodeType)) {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
const label = match[1];
|
|
287
|
+
return state.tr.replaceRangeWith(start, end, nodeType.create({
|
|
288
|
+
label
|
|
289
|
+
}));
|
|
290
|
+
})
|
|
291
|
+
],
|
|
292
|
+
prosePlugins: (type, ctx) => {
|
|
293
|
+
const inputChipRenderer = utils.themeManager.get("input-chip", {
|
|
294
|
+
width: "12em",
|
|
295
|
+
placeholder: "Input Footnote Label",
|
|
296
|
+
onUpdate: (value) => {
|
|
297
|
+
ctx.get(commandsCtx).call(ModifyFootnoteRef, value);
|
|
298
|
+
},
|
|
299
|
+
isBindMode: true
|
|
300
|
+
});
|
|
301
|
+
if (!inputChipRenderer)
|
|
302
|
+
return [];
|
|
303
|
+
const shouldDisplay = (view) => {
|
|
304
|
+
return Boolean(type && findSelectedNodeOfType(view.state.selection, type));
|
|
305
|
+
};
|
|
306
|
+
const getCurrentLabel = (view) => {
|
|
307
|
+
const result = findSelectedNodeOfType(view.state.selection, type);
|
|
308
|
+
if (!result)
|
|
309
|
+
return;
|
|
310
|
+
const value = result.node.attrs["label"];
|
|
311
|
+
return value;
|
|
312
|
+
};
|
|
313
|
+
const renderByView = (view) => {
|
|
314
|
+
if (!view.editable) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
const display = shouldDisplay(view);
|
|
318
|
+
if (display) {
|
|
319
|
+
inputChipRenderer.show(view);
|
|
320
|
+
inputChipRenderer.update(getCurrentLabel(view));
|
|
321
|
+
} else {
|
|
322
|
+
inputChipRenderer.hide();
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
return [
|
|
326
|
+
new Plugin({
|
|
327
|
+
key,
|
|
328
|
+
view: (editorView) => {
|
|
329
|
+
inputChipRenderer.init(editorView);
|
|
330
|
+
renderByView(editorView);
|
|
331
|
+
return {
|
|
332
|
+
update: (view, prevState) => {
|
|
333
|
+
const isEqualSelection = (prevState == null ? void 0 : prevState.doc.eq(view.state.doc)) && prevState.selection.eq(view.state.selection);
|
|
334
|
+
if (isEqualSelection)
|
|
335
|
+
return;
|
|
336
|
+
renderByView(view);
|
|
337
|
+
},
|
|
338
|
+
destroy: () => {
|
|
339
|
+
inputChipRenderer.destroy();
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
})
|
|
344
|
+
];
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
});
|
|
39
348
|
const exitTable = (node) => (state, dispatch) => {
|
|
40
349
|
if (!isInTable(state)) {
|
|
41
350
|
return false;
|
|
@@ -182,95 +491,87 @@ const calculateItem = (actions, view) => {
|
|
|
182
491
|
item.$.classList.remove("hide");
|
|
183
492
|
});
|
|
184
493
|
};
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
Action2[Action2["AlignCenter"] = 5] = "AlignCenter";
|
|
193
|
-
Action2[Action2["AlignRight"] = 6] = "AlignRight";
|
|
194
|
-
Action2[Action2["Delete"] = 7] = "Delete";
|
|
195
|
-
})(Action || (Action = {}));
|
|
196
|
-
const createActions = (ctx) => ({
|
|
197
|
-
[0]: {
|
|
198
|
-
$: ctx.get(themeToolCtx).slots.icon("leftArrow"),
|
|
199
|
-
command: () => addColumnBefore,
|
|
200
|
-
disable: (view) => !getCellSelection(view).isColSelection()
|
|
201
|
-
},
|
|
202
|
-
[1]: {
|
|
203
|
-
$: ctx.get(themeToolCtx).slots.icon("rightArrow"),
|
|
204
|
-
command: () => addColumnAfter,
|
|
205
|
-
disable: (view) => !getCellSelection(view).isColSelection()
|
|
206
|
-
},
|
|
207
|
-
[2]: {
|
|
208
|
-
$: ctx.get(themeToolCtx).slots.icon("upArrow"),
|
|
209
|
-
command: () => (state, dispatch) => {
|
|
210
|
-
if (!isInTable(state))
|
|
211
|
-
return false;
|
|
212
|
-
if (dispatch) {
|
|
213
|
-
const rect = selectedRect(state);
|
|
214
|
-
dispatch(addRowWithAlignment(state.tr, rect, rect.top));
|
|
215
|
-
}
|
|
216
|
-
return true;
|
|
494
|
+
const createActions = (ctx) => {
|
|
495
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
496
|
+
return {
|
|
497
|
+
[0]: {
|
|
498
|
+
$: (_a = ctx.get(themeManagerCtx).get(ThemeIcon, "leftArrow")) == null ? void 0 : _a.dom,
|
|
499
|
+
command: () => addColumnBefore,
|
|
500
|
+
disable: (view) => !getCellSelection(view).isColSelection()
|
|
217
501
|
},
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
command: () => (state, dispatch) => {
|
|
223
|
-
if (!isInTable(state))
|
|
224
|
-
return false;
|
|
225
|
-
if (dispatch) {
|
|
226
|
-
const rect = selectedRect(state);
|
|
227
|
-
dispatch(addRowWithAlignment(state.tr, rect, rect.bottom));
|
|
228
|
-
}
|
|
229
|
-
return true;
|
|
502
|
+
[1]: {
|
|
503
|
+
$: (_b = ctx.get(themeManagerCtx).get(ThemeIcon, "rightArrow")) == null ? void 0 : _b.dom,
|
|
504
|
+
command: () => addColumnAfter,
|
|
505
|
+
disable: (view) => !getCellSelection(view).isColSelection()
|
|
230
506
|
},
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
[6]: {
|
|
244
|
-
$: ctx.get(themeToolCtx).slots.icon("alignRight"),
|
|
245
|
-
command: () => setCellAttr("alignment", "right"),
|
|
246
|
-
disable: (view) => !getCellSelection(view).isColSelection()
|
|
247
|
-
},
|
|
248
|
-
[7]: {
|
|
249
|
-
$: ctx.get(themeToolCtx).slots.icon("delete"),
|
|
250
|
-
command: (_, view) => {
|
|
251
|
-
const selection = getCellSelection(view);
|
|
252
|
-
const isCol = selection.isColSelection();
|
|
253
|
-
const isRow = selection.isRowSelection();
|
|
254
|
-
if (isCol && isRow) {
|
|
255
|
-
return deleteTable;
|
|
256
|
-
}
|
|
257
|
-
if (isCol) {
|
|
258
|
-
return deleteColumn;
|
|
259
|
-
}
|
|
260
|
-
return deleteRow;
|
|
507
|
+
[2]: {
|
|
508
|
+
$: (_c = ctx.get(themeManagerCtx).get(ThemeIcon, "upArrow")) == null ? void 0 : _c.dom,
|
|
509
|
+
command: () => (state, dispatch) => {
|
|
510
|
+
if (!isInTable(state))
|
|
511
|
+
return false;
|
|
512
|
+
if (dispatch) {
|
|
513
|
+
const rect = selectedRect(state);
|
|
514
|
+
dispatch(addRowWithAlignment(state.tr, rect, rect.top));
|
|
515
|
+
}
|
|
516
|
+
return true;
|
|
517
|
+
},
|
|
518
|
+
disable: (view) => !getCellSelection(view).isRowSelection() || getCellSelection(view).$head.parent.type.name === "table_header"
|
|
261
519
|
},
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
if (
|
|
520
|
+
[3]: {
|
|
521
|
+
$: (_d = ctx.get(themeManagerCtx).get(ThemeIcon, "downArrow")) == null ? void 0 : _d.dom,
|
|
522
|
+
command: () => (state, dispatch) => {
|
|
523
|
+
if (!isInTable(state))
|
|
266
524
|
return false;
|
|
525
|
+
if (dispatch) {
|
|
526
|
+
const rect = selectedRect(state);
|
|
527
|
+
dispatch(addRowWithAlignment(state.tr, rect, rect.bottom));
|
|
267
528
|
}
|
|
268
|
-
return
|
|
529
|
+
return true;
|
|
530
|
+
},
|
|
531
|
+
disable: (view) => !getCellSelection(view).isRowSelection()
|
|
532
|
+
},
|
|
533
|
+
[4]: {
|
|
534
|
+
$: (_e = ctx.get(themeManagerCtx).get(ThemeIcon, "alignLeft")) == null ? void 0 : _e.dom,
|
|
535
|
+
command: () => setCellAttr("alignment", "left"),
|
|
536
|
+
disable: (view) => !getCellSelection(view).isColSelection()
|
|
537
|
+
},
|
|
538
|
+
[5]: {
|
|
539
|
+
$: (_f = ctx.get(themeManagerCtx).get(ThemeIcon, "alignCenter")) == null ? void 0 : _f.dom,
|
|
540
|
+
command: () => setCellAttr("alignment", "center"),
|
|
541
|
+
disable: (view) => !getCellSelection(view).isColSelection()
|
|
542
|
+
},
|
|
543
|
+
[6]: {
|
|
544
|
+
$: (_g = ctx.get(themeManagerCtx).get(ThemeIcon, "alignRight")) == null ? void 0 : _g.dom,
|
|
545
|
+
command: () => setCellAttr("alignment", "right"),
|
|
546
|
+
disable: (view) => !getCellSelection(view).isColSelection()
|
|
547
|
+
},
|
|
548
|
+
[7]: {
|
|
549
|
+
$: (_h = ctx.get(themeManagerCtx).get(ThemeIcon, "delete")) == null ? void 0 : _h.dom,
|
|
550
|
+
command: (_, view) => {
|
|
551
|
+
const selection = getCellSelection(view);
|
|
552
|
+
const isCol = selection.isColSelection();
|
|
553
|
+
const isRow = selection.isRowSelection();
|
|
554
|
+
if (isCol && isRow) {
|
|
555
|
+
return deleteTable;
|
|
556
|
+
}
|
|
557
|
+
if (isCol) {
|
|
558
|
+
return deleteColumn;
|
|
559
|
+
}
|
|
560
|
+
return deleteRow;
|
|
561
|
+
},
|
|
562
|
+
disable: (view) => {
|
|
563
|
+
const selection = getCellSelection(view);
|
|
564
|
+
if (selection.isRowSelection()) {
|
|
565
|
+
if (selection.isColSelection()) {
|
|
566
|
+
return false;
|
|
567
|
+
}
|
|
568
|
+
return isFirstRowSelected(selection);
|
|
569
|
+
}
|
|
570
|
+
return false;
|
|
269
571
|
}
|
|
270
|
-
return false;
|
|
271
572
|
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
573
|
+
};
|
|
574
|
+
};
|
|
274
575
|
const calculatePosition = (view, dom) => {
|
|
275
576
|
const { selection } = view.state;
|
|
276
577
|
const isCol = selection.isColSelection();
|
|
@@ -288,61 +589,128 @@ const calculatePosition = (view, dom) => {
|
|
|
288
589
|
return [top, left];
|
|
289
590
|
});
|
|
290
591
|
};
|
|
291
|
-
var ToolTipPos
|
|
292
|
-
(function(ToolTipPos2) {
|
|
592
|
+
var ToolTipPos = /* @__PURE__ */ ((ToolTipPos2) => {
|
|
293
593
|
ToolTipPos2["Left"] = "Left";
|
|
294
594
|
ToolTipPos2["Top"] = "Top";
|
|
295
595
|
ToolTipPos2["Point"] = "Point";
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
596
|
+
return ToolTipPos2;
|
|
597
|
+
})(ToolTipPos || {});
|
|
598
|
+
const injectStyle = (themeManager, { css, injectGlobal }) => {
|
|
599
|
+
const palette = getPalette(themeManager);
|
|
600
|
+
const radius = themeManager.get(ThemeSize, "radius");
|
|
601
|
+
const lineWidth = themeManager.get(ThemeSize, "lineWidth");
|
|
602
|
+
injectGlobal`
|
|
603
|
+
.milkdown {
|
|
604
|
+
.tableWrapper {
|
|
605
|
+
table {
|
|
606
|
+
width: calc(100% - 2em) !important;
|
|
607
|
+
margin: 1em 0 1em 1em !important;
|
|
608
|
+
|
|
609
|
+
.milkdown-cell-left,
|
|
610
|
+
.milkdown-cell-point,
|
|
611
|
+
.milkdown-cell-top {
|
|
612
|
+
position: absolute;
|
|
613
|
+
|
|
614
|
+
&::after {
|
|
615
|
+
cursor: pointer;
|
|
616
|
+
position: absolute;
|
|
617
|
+
top: 0;
|
|
618
|
+
left: 0;
|
|
619
|
+
height: 100%;
|
|
620
|
+
width: 100%;
|
|
621
|
+
display: block;
|
|
622
|
+
transition: all 0.2s ease-in-out;
|
|
623
|
+
background: ${palette("secondary", 0.12)};
|
|
624
|
+
content: '';
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
&:hover::after {
|
|
628
|
+
background: ${palette("secondary", 0.38)};
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
.milkdown-cell-left {
|
|
633
|
+
left: calc(-6px - 0.5em);
|
|
634
|
+
top: 0;
|
|
635
|
+
bottom: 0;
|
|
636
|
+
width: 0.5em;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
.milkdown-cell-top {
|
|
640
|
+
left: 0;
|
|
641
|
+
right: 0;
|
|
642
|
+
top: calc(-6px - 0.5em);
|
|
643
|
+
height: 0.5em;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
.milkdown-cell-point {
|
|
647
|
+
left: calc(-2px - 1em);
|
|
648
|
+
top: calc(-2px - 1em);
|
|
649
|
+
width: 1em;
|
|
650
|
+
height: 1em;
|
|
651
|
+
|
|
652
|
+
.icon {
|
|
653
|
+
position: absolute;
|
|
654
|
+
top: 0;
|
|
655
|
+
bottom: 0;
|
|
656
|
+
left: 0;
|
|
657
|
+
right: 0;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
`;
|
|
299
664
|
return css`
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
665
|
+
display: inline-flex;
|
|
666
|
+
cursor: pointer;
|
|
667
|
+
z-index: 2;
|
|
303
668
|
|
|
304
|
-
|
|
669
|
+
justify-content: space-evenly;
|
|
305
670
|
|
|
306
|
-
|
|
671
|
+
position: absolute;
|
|
307
672
|
|
|
308
|
-
|
|
673
|
+
border-radius: ${radius};
|
|
309
674
|
|
|
310
|
-
|
|
675
|
+
${themeManager.get(ThemeBorder, void 0)};
|
|
676
|
+
${themeManager.get(ThemeShadow, void 0)};
|
|
311
677
|
|
|
312
|
-
|
|
678
|
+
overflow: hidden;
|
|
679
|
+
background: ${palette("surface")};
|
|
313
680
|
|
|
314
|
-
|
|
315
|
-
|
|
681
|
+
.icon {
|
|
682
|
+
position: relative;
|
|
683
|
+
color: ${palette("solid", 0.87)};
|
|
316
684
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
685
|
+
width: 2em;
|
|
686
|
+
line-height: 2em;
|
|
687
|
+
text-align: center;
|
|
688
|
+
transition: all 0.4s ease-in-out;
|
|
320
689
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
690
|
+
&:hover {
|
|
691
|
+
background-color: ${palette("secondary", 0.12)};
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
&.active {
|
|
695
|
+
color: ${palette("primary")};
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
&:not(:last-child)::after {
|
|
699
|
+
content: '';
|
|
700
|
+
position: absolute;
|
|
701
|
+
right: 0;
|
|
702
|
+
top: 0;
|
|
703
|
+
width: ${lineWidth};
|
|
704
|
+
bottom: 0;
|
|
705
|
+
background: ${palette("line")};
|
|
706
|
+
}
|
|
330
707
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
top: 0;
|
|
336
|
-
width: ${size.lineWidth};
|
|
337
|
-
bottom: 0;
|
|
338
|
-
background: ${palette("line")};
|
|
708
|
+
|
|
709
|
+
&.hide,
|
|
710
|
+
.hide {
|
|
711
|
+
display: none;
|
|
339
712
|
}
|
|
340
|
-
|
|
341
|
-
&.hide,
|
|
342
|
-
.hide {
|
|
343
|
-
display: none;
|
|
344
|
-
}
|
|
345
|
-
`;
|
|
713
|
+
`;
|
|
346
714
|
};
|
|
347
715
|
const calculateClassName = (pos) => {
|
|
348
716
|
switch (pos) {
|
|
@@ -359,11 +727,12 @@ const calculateClassName = (pos) => {
|
|
|
359
727
|
}
|
|
360
728
|
};
|
|
361
729
|
function createWidget(ctx, cell, pos, index = 0) {
|
|
362
|
-
|
|
730
|
+
return Decoration.widget(cell.pos + 1, (view) => {
|
|
731
|
+
var _a;
|
|
363
732
|
const div = document.createElement("div");
|
|
364
733
|
div.classList.add(calculateClassName(pos));
|
|
365
734
|
if (pos === ToolTipPos.Point) {
|
|
366
|
-
div.appendChild(ctx.get(
|
|
735
|
+
div.appendChild((_a = ctx.get(themeManagerCtx).get(ThemeIcon, "select")) == null ? void 0 : _a.dom);
|
|
367
736
|
}
|
|
368
737
|
div.addEventListener("mousedown", (e) => {
|
|
369
738
|
if (!view)
|
|
@@ -386,16 +755,8 @@ function createWidget(ctx, cell, pos, index = 0) {
|
|
|
386
755
|
});
|
|
387
756
|
return div;
|
|
388
757
|
});
|
|
389
|
-
return widget;
|
|
390
758
|
}
|
|
391
759
|
const operatorPlugin = (ctx, utils) => {
|
|
392
|
-
const items = createActions(ctx);
|
|
393
|
-
const tooltip = document.createElement("div");
|
|
394
|
-
const style = utils.getStyle(injectStyle$1);
|
|
395
|
-
if (style) {
|
|
396
|
-
tooltip.classList.add(style);
|
|
397
|
-
}
|
|
398
|
-
tooltip.classList.add("table-tooltip", "hide");
|
|
399
760
|
return new Plugin({
|
|
400
761
|
key: new PluginKey("MILKDOWN_TABLE_OP"),
|
|
401
762
|
props: {
|
|
@@ -420,6 +781,15 @@ const operatorPlugin = (ctx, utils) => {
|
|
|
420
781
|
},
|
|
421
782
|
view: (editorView) => {
|
|
422
783
|
var _a;
|
|
784
|
+
const items = Object.fromEntries(Object.entries(createActions(ctx)).filter(([, value]) => value.$ != null));
|
|
785
|
+
const tooltip = document.createElement("div");
|
|
786
|
+
utils.themeManager.onFlush(() => {
|
|
787
|
+
const style = utils.getStyle((emotion) => injectStyle(utils.themeManager, emotion));
|
|
788
|
+
if (style) {
|
|
789
|
+
tooltip.classList.add(style);
|
|
790
|
+
}
|
|
791
|
+
});
|
|
792
|
+
tooltip.classList.add("table-tooltip", "hide");
|
|
423
793
|
Object.values(items).forEach(({ $ }) => tooltip.appendChild($));
|
|
424
794
|
(_a = editorView.dom.parentNode) == null ? void 0 : _a.appendChild(tooltip);
|
|
425
795
|
const listener = (e) => {
|
|
@@ -476,172 +846,6 @@ const schema = tableNodes({
|
|
|
476
846
|
}
|
|
477
847
|
}
|
|
478
848
|
});
|
|
479
|
-
const proseTableStyle = ({ css }) => css`
|
|
480
|
-
/* copy from https://github.com/ProseMirror/prosemirror-tables/blob/master/style/tables.css */
|
|
481
|
-
.ProseMirror .tableWrapper {
|
|
482
|
-
overflow-x: auto;
|
|
483
|
-
}
|
|
484
|
-
.ProseMirror table {
|
|
485
|
-
border-collapse: collapse;
|
|
486
|
-
table-layout: fixed;
|
|
487
|
-
width: 100%;
|
|
488
|
-
overflow: hidden;
|
|
489
|
-
}
|
|
490
|
-
.ProseMirror td,
|
|
491
|
-
.ProseMirror th {
|
|
492
|
-
vertical-align: top;
|
|
493
|
-
box-sizing: border-box;
|
|
494
|
-
position: relative;
|
|
495
|
-
}
|
|
496
|
-
.ProseMirror .column-resize-handle {
|
|
497
|
-
position: absolute;
|
|
498
|
-
right: -2px;
|
|
499
|
-
top: 0;
|
|
500
|
-
bottom: 0;
|
|
501
|
-
width: 4px;
|
|
502
|
-
z-index: 20;
|
|
503
|
-
background-color: #adf;
|
|
504
|
-
pointer-events: none;
|
|
505
|
-
}
|
|
506
|
-
.ProseMirror.resize-cursor {
|
|
507
|
-
cursor: ew-resize;
|
|
508
|
-
cursor: col-resize;
|
|
509
|
-
}
|
|
510
|
-
/* Give selected cells a blue overlay */
|
|
511
|
-
.ProseMirror .selectedCell:after {
|
|
512
|
-
z-index: 2;
|
|
513
|
-
position: absolute;
|
|
514
|
-
content: '';
|
|
515
|
-
left: 0;
|
|
516
|
-
right: 0;
|
|
517
|
-
top: 0;
|
|
518
|
-
bottom: 0;
|
|
519
|
-
background: rgba(200, 200, 255, 0.4);
|
|
520
|
-
pointer-events: none;
|
|
521
|
-
}
|
|
522
|
-
`;
|
|
523
|
-
const injectStyle = (utils) => {
|
|
524
|
-
return utils.getStyle(({ size, palette, mixin }, emotion) => {
|
|
525
|
-
var _a, _b, _c;
|
|
526
|
-
const css = emotion.injectGlobal;
|
|
527
|
-
css`
|
|
528
|
-
${proseTableStyle(emotion)}
|
|
529
|
-
|
|
530
|
-
.tableWrapper {
|
|
531
|
-
margin: 0 !important;
|
|
532
|
-
|
|
533
|
-
${(_a = mixin.scrollbar) == null ? void 0 : _a.call(mixin, "x")};
|
|
534
|
-
|
|
535
|
-
width: 100%;
|
|
536
|
-
|
|
537
|
-
table {
|
|
538
|
-
width: calc(100% - 2rem) !important;
|
|
539
|
-
border-radius: ${size.radius};
|
|
540
|
-
box-sizing: border-box;
|
|
541
|
-
margin: 1rem 0 1rem 1rem !important;
|
|
542
|
-
overflow: auto !important;
|
|
543
|
-
* {
|
|
544
|
-
margin: 0 !important;
|
|
545
|
-
box-sizing: border-box;
|
|
546
|
-
font-size: 1rem;
|
|
547
|
-
}
|
|
548
|
-
tr {
|
|
549
|
-
${(_b = mixin.border) == null ? void 0 : _b.call(mixin, "bottom")};
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
th {
|
|
553
|
-
background: ${palette("background", 0.5)};
|
|
554
|
-
font-weight: 400;
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
th,
|
|
558
|
-
td {
|
|
559
|
-
min-width: 100px;
|
|
560
|
-
${(_c = mixin.border) == null ? void 0 : _c.call(mixin)};
|
|
561
|
-
text-align: left;
|
|
562
|
-
position: relative;
|
|
563
|
-
line-height: 3rem;
|
|
564
|
-
box-sizing: border-box;
|
|
565
|
-
height: 3rem;
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
.selectedCell {
|
|
569
|
-
&::after {
|
|
570
|
-
background: ${palette("secondary", 0.38)};
|
|
571
|
-
}
|
|
572
|
-
& ::selection {
|
|
573
|
-
background: transparent;
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
.column-resize-handle {
|
|
578
|
-
background: ${palette("primary")};
|
|
579
|
-
width: ${size.lineWidth};
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
th,
|
|
583
|
-
td {
|
|
584
|
-
padding: 0 1rem;
|
|
585
|
-
p {
|
|
586
|
-
line-height: unset !important;
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
.milkdown-cell-left,
|
|
591
|
-
.milkdown-cell-point,
|
|
592
|
-
.milkdown-cell-top {
|
|
593
|
-
position: absolute;
|
|
594
|
-
|
|
595
|
-
&::after {
|
|
596
|
-
cursor: pointer;
|
|
597
|
-
position: absolute;
|
|
598
|
-
top: 0;
|
|
599
|
-
left: 0;
|
|
600
|
-
height: 100%;
|
|
601
|
-
width: 100%;
|
|
602
|
-
display: block;
|
|
603
|
-
transition: all 0.2s ease-in-out;
|
|
604
|
-
background: ${palette("secondary", 0.12)};
|
|
605
|
-
content: '';
|
|
606
|
-
}
|
|
607
|
-
&:hover::after {
|
|
608
|
-
background: ${palette("secondary", 0.38)};
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
.milkdown-cell-left {
|
|
613
|
-
left: calc(-6px - 0.5rem);
|
|
614
|
-
top: 0;
|
|
615
|
-
bottom: 0;
|
|
616
|
-
width: 0.5rem;
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
.milkdown-cell-top {
|
|
620
|
-
left: 0;
|
|
621
|
-
right: 0;
|
|
622
|
-
top: calc(-6px - 0.5rem);
|
|
623
|
-
height: 0.5rem;
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
.milkdown-cell-point {
|
|
627
|
-
left: calc(-2px - 1rem);
|
|
628
|
-
top: calc(-2px - 1rem);
|
|
629
|
-
width: 1rem;
|
|
630
|
-
height: 1rem;
|
|
631
|
-
|
|
632
|
-
.icon {
|
|
633
|
-
position: absolute;
|
|
634
|
-
top: 0;
|
|
635
|
-
bottom: 0;
|
|
636
|
-
left: 0;
|
|
637
|
-
right: 0;
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
`;
|
|
643
|
-
});
|
|
644
|
-
};
|
|
645
849
|
const SupportedKeys$1 = {
|
|
646
850
|
NextCell: "NextCell",
|
|
647
851
|
PrevCell: "PrevCell",
|
|
@@ -652,7 +856,6 @@ const NextCell = createCmdKey("NextCell");
|
|
|
652
856
|
const BreakTable = createCmdKey("BreakTable");
|
|
653
857
|
const InsertTable = createCmdKey("InsertTable");
|
|
654
858
|
const table = createPlugin((utils) => {
|
|
655
|
-
injectStyle(utils);
|
|
656
859
|
return {
|
|
657
860
|
schema: () => ({
|
|
658
861
|
node: {
|
|
@@ -789,11 +992,8 @@ const SupportedKeys = __spreadProps(__spreadValues(__spreadValues({}, SupportedK
|
|
|
789
992
|
TaskList: "TaskList"
|
|
790
993
|
});
|
|
791
994
|
const ToggleStrikeThrough = createCmdKey("ToggleStrikeThrough");
|
|
995
|
+
const id = "strike_through";
|
|
792
996
|
const strikeThrough = createMark((utils) => {
|
|
793
|
-
const id = "strike_through";
|
|
794
|
-
const style = utils.getStyle((themeTool, { css }) => css`
|
|
795
|
-
text-decoration-color: ${themeTool.palette("secondary")};
|
|
796
|
-
`);
|
|
797
997
|
return {
|
|
798
998
|
id,
|
|
799
999
|
schema: () => ({
|
|
@@ -801,7 +1001,7 @@ const strikeThrough = createMark((utils) => {
|
|
|
801
1001
|
{ tag: "del" },
|
|
802
1002
|
{ style: "text-decoration", getAttrs: (value) => value === "line-through" }
|
|
803
1003
|
],
|
|
804
|
-
toDOM: (mark) => ["del", { class: utils.getClassName(mark.attrs, "strike-through"
|
|
1004
|
+
toDOM: (mark) => ["del", { class: utils.getClassName(mark.attrs, "strike-through") }],
|
|
805
1005
|
parseMarkdown: {
|
|
806
1006
|
match: (node) => node.type === "delete",
|
|
807
1007
|
runner: (state, node, markType) => {
|
|
@@ -832,56 +1032,10 @@ const SinkTaskListItem = createCmdKey("SinkTaskListItem");
|
|
|
832
1032
|
const LiftTaskListItem = createCmdKey("LiftTaskListItem");
|
|
833
1033
|
const TurnIntoTaskList = createCmdKey("TurnIntoTaskList");
|
|
834
1034
|
const taskListItem = createNode((utils) => {
|
|
835
|
-
const
|
|
836
|
-
const style = utils.getStyle(({ palette, size }, { css }) => css`
|
|
837
|
-
list-style-type: none;
|
|
838
|
-
position: relative;
|
|
839
|
-
|
|
840
|
-
& > div {
|
|
841
|
-
overflow: hidden;
|
|
842
|
-
padding: 0 2px;
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
label {
|
|
846
|
-
position: absolute;
|
|
847
|
-
top: 0;
|
|
848
|
-
left: -2rem;
|
|
849
|
-
display: inline-block;
|
|
850
|
-
width: 1.5rem;
|
|
851
|
-
height: 1.5rem;
|
|
852
|
-
margin: 0.5rem 0;
|
|
853
|
-
input {
|
|
854
|
-
visibility: hidden;
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
label:before {
|
|
858
|
-
position: absolute;
|
|
859
|
-
top: 0;
|
|
860
|
-
right: 0;
|
|
861
|
-
bottom: 0;
|
|
862
|
-
left: 0;
|
|
863
|
-
border-radius: ${size.radius};
|
|
864
|
-
}
|
|
865
|
-
label:hover:before {
|
|
866
|
-
background: ${palette("background")};
|
|
867
|
-
}
|
|
868
|
-
&[data-checked='true'] {
|
|
869
|
-
label {
|
|
870
|
-
color: ${palette("primary")};
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
&[data-checked='false'] {
|
|
874
|
-
label {
|
|
875
|
-
color: ${palette("solid", 0.87)};
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
.paragraph {
|
|
879
|
-
margin: 0.5rem 0;
|
|
880
|
-
}
|
|
881
|
-
`);
|
|
1035
|
+
const id2 = "task_list_item";
|
|
882
1036
|
return {
|
|
883
|
-
id,
|
|
884
|
-
schema: () => ({
|
|
1037
|
+
id: id2,
|
|
1038
|
+
schema: (ctx) => ({
|
|
885
1039
|
group: "listItem",
|
|
886
1040
|
content: "paragraph block*",
|
|
887
1041
|
defining: true,
|
|
@@ -902,15 +1056,40 @@ const taskListItem = createNode((utils) => {
|
|
|
902
1056
|
}
|
|
903
1057
|
}
|
|
904
1058
|
],
|
|
905
|
-
toDOM: (node) =>
|
|
906
|
-
"
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
1059
|
+
toDOM: (node) => {
|
|
1060
|
+
const checkbox = document.createElement("input");
|
|
1061
|
+
checkbox.type = "checkbox";
|
|
1062
|
+
checkbox.checked = node.attrs["checked"];
|
|
1063
|
+
checkbox.className = utils.getClassName(node.attrs, "task-list-item_checkbox");
|
|
1064
|
+
checkbox.onchange = (event) => {
|
|
1065
|
+
const target = event.target;
|
|
1066
|
+
if (!(target instanceof HTMLInputElement))
|
|
1067
|
+
return;
|
|
1068
|
+
const view = ctx.get(editorViewCtx);
|
|
1069
|
+
if (!view.editable) {
|
|
1070
|
+
checkbox.checked = !checkbox.checked;
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
const { top, left } = target.getBoundingClientRect();
|
|
1074
|
+
const result = view.posAtCoords({ top, left });
|
|
1075
|
+
if (!result)
|
|
1076
|
+
return;
|
|
1077
|
+
const { tr } = view.state;
|
|
1078
|
+
view.dispatch(tr.setNodeMarkup(result.inside, void 0, {
|
|
1079
|
+
checked: target.checked
|
|
1080
|
+
}));
|
|
1081
|
+
};
|
|
1082
|
+
return [
|
|
1083
|
+
"li",
|
|
1084
|
+
{
|
|
1085
|
+
"data-type": "task-item",
|
|
1086
|
+
"data-checked": node.attrs["checked"] ? "true" : "false",
|
|
1087
|
+
class: utils.getClassName(node.attrs, "task-list-item")
|
|
1088
|
+
},
|
|
1089
|
+
checkbox,
|
|
1090
|
+
["span", { class: utils.getClassName(node.attrs, "task-list-item_body") }, 0]
|
|
1091
|
+
];
|
|
1092
|
+
},
|
|
914
1093
|
parseMarkdown: {
|
|
915
1094
|
match: ({ type, checked }) => {
|
|
916
1095
|
return type === "listItem" && checked !== null;
|
|
@@ -922,7 +1101,7 @@ const taskListItem = createNode((utils) => {
|
|
|
922
1101
|
}
|
|
923
1102
|
},
|
|
924
1103
|
toMarkdown: {
|
|
925
|
-
match: (node) => node.type.name ===
|
|
1104
|
+
match: (node) => node.type.name === id2,
|
|
926
1105
|
runner: (state, node) => {
|
|
927
1106
|
state.openNode("listItem", void 0, { checked: node.attrs["checked"] });
|
|
928
1107
|
state.next(node.content);
|
|
@@ -947,68 +1126,30 @@ const taskListItem = createNode((utils) => {
|
|
|
947
1126
|
[SupportedKeys.LiftListItem]: createShortcut(LiftTaskListItem, "Mod-["),
|
|
948
1127
|
[SupportedKeys.TaskList]: createShortcut(TurnIntoTaskList, "Mod-Alt-9")
|
|
949
1128
|
},
|
|
950
|
-
view: (
|
|
951
|
-
|
|
952
|
-
const
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
const setIcon = (name) => {
|
|
960
|
-
const nextIcon = createIcon(name);
|
|
961
|
-
checkboxWrapper.replaceChild(nextIcon, icon);
|
|
962
|
-
icon = nextIcon;
|
|
963
|
-
};
|
|
964
|
-
checkboxWrapper.contentEditable = "false";
|
|
965
|
-
checkbox.type = "checkbox";
|
|
966
|
-
const onChange = (event) => {
|
|
967
|
-
const target = event.target;
|
|
968
|
-
if (!(target instanceof HTMLInputElement))
|
|
969
|
-
return;
|
|
970
|
-
if (!view.editable) {
|
|
971
|
-
checkbox.checked = !checkbox.checked;
|
|
972
|
-
return;
|
|
1129
|
+
view: () => (node, view, getPos) => {
|
|
1130
|
+
let currNode = node;
|
|
1131
|
+
const renderer = utils.themeManager.get("task-list-item", {
|
|
1132
|
+
editable: () => view.editable,
|
|
1133
|
+
onChange: (selected) => {
|
|
1134
|
+
const { tr } = view.state;
|
|
1135
|
+
view.dispatch(tr.setNodeMarkup(getPos(), void 0, {
|
|
1136
|
+
checked: selected
|
|
1137
|
+
}));
|
|
973
1138
|
}
|
|
974
|
-
const { tr } = view.state;
|
|
975
|
-
view.dispatch(tr.setNodeMarkup(getPos(), void 0, {
|
|
976
|
-
checked: target.checked
|
|
977
|
-
}));
|
|
978
|
-
};
|
|
979
|
-
checkbox.addEventListener("change", onChange);
|
|
980
|
-
listItem2.dataset["checked"] = node.attrs["checked"];
|
|
981
|
-
if (node.attrs["checked"]) {
|
|
982
|
-
checkbox.setAttribute("checked", "checked");
|
|
983
|
-
}
|
|
984
|
-
checkboxWrapper.append(checkbox, checkboxStyler);
|
|
985
|
-
listItem2.append(checkboxWrapper, content);
|
|
986
|
-
const attributes = {
|
|
987
|
-
"data-type": "task-item",
|
|
988
|
-
"data-checked": node.attrs["checked"] ? "true" : "false",
|
|
989
|
-
class: utils.getClassName(node.attrs, "task-list-item", style)
|
|
990
|
-
};
|
|
991
|
-
Object.entries(attributes).forEach(([key, value]) => {
|
|
992
|
-
listItem2.setAttribute(key, value);
|
|
993
1139
|
});
|
|
994
|
-
|
|
1140
|
+
if (!renderer)
|
|
1141
|
+
return {};
|
|
1142
|
+
const { dom, contentDOM, onUpdate } = renderer;
|
|
1143
|
+
onUpdate(currNode);
|
|
995
1144
|
return {
|
|
996
|
-
dom
|
|
997
|
-
contentDOM
|
|
1145
|
+
dom,
|
|
1146
|
+
contentDOM,
|
|
998
1147
|
update: (updatedNode) => {
|
|
999
|
-
if (updatedNode.type.name !==
|
|
1148
|
+
if (updatedNode.type.name !== id2)
|
|
1000
1149
|
return false;
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
checkbox.setAttribute("checked", "checked");
|
|
1004
|
-
} else {
|
|
1005
|
-
checkbox.removeAttribute("checked");
|
|
1006
|
-
}
|
|
1007
|
-
setIcon(updatedNode.attrs["checked"] ? "checked" : "unchecked");
|
|
1150
|
+
currNode = updatedNode;
|
|
1151
|
+
onUpdate(currNode);
|
|
1008
1152
|
return true;
|
|
1009
|
-
},
|
|
1010
|
-
destroy: () => {
|
|
1011
|
-
checkbox.removeEventListener("change", onChange);
|
|
1012
1153
|
}
|
|
1013
1154
|
};
|
|
1014
1155
|
}
|
|
@@ -1020,7 +1161,9 @@ const gfm = AtomList.create([
|
|
|
1020
1161
|
table(),
|
|
1021
1162
|
urlPlugin,
|
|
1022
1163
|
strikeThrough(),
|
|
1023
|
-
taskListItem()
|
|
1164
|
+
taskListItem(),
|
|
1165
|
+
footnoteReference(),
|
|
1166
|
+
footnoteDefinition()
|
|
1024
1167
|
]);
|
|
1025
1168
|
const commands = __spreadProps(__spreadValues({}, commands$1), {
|
|
1026
1169
|
ToggleStrikeThrough,
|
|
@@ -1029,5 +1172,5 @@ const commands = __spreadProps(__spreadValues({}, commands$1), {
|
|
|
1029
1172
|
LiftTaskListItem,
|
|
1030
1173
|
SplitTaskListItem
|
|
1031
1174
|
});
|
|
1032
|
-
export { BreakTable, InsertTable, LiftTaskListItem, NextCell, PrevCell, SinkTaskListItem, SplitTaskListItem, SupportedKeys, ToggleStrikeThrough, TurnIntoTaskList, commands, createTable, gfm, strikeThrough, table, taskListItem };
|
|
1175
|
+
export { BreakTable, InsertTable, LiftTaskListItem, ModifyFootnoteDef, ModifyFootnoteRef, NextCell, PrevCell, SinkTaskListItem, SplitTaskListItem, SupportedKeys, ToggleStrikeThrough, TurnIntoTaskList, commands, createTable, footnoteDefinition, footnoteReference, gfm, strikeThrough, table, taskListItem };
|
|
1033
1176
|
//# sourceMappingURL=index.es.js.map
|