@milkdown/preset-commonmark 6.1.5 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +2 -6
- package/lib/index.d.ts.map +1 -1
- package/lib/index.es.js +105 -17
- package/lib/index.es.js.map +1 -1
- package/lib/mark/code-inline.d.ts +1 -5
- package/lib/mark/code-inline.d.ts.map +1 -1
- package/lib/mark/em.d.ts +1 -5
- package/lib/mark/em.d.ts.map +1 -1
- package/lib/mark/link.d.ts +1 -5
- package/lib/mark/link.d.ts.map +1 -1
- package/lib/mark/strong.d.ts +1 -5
- package/lib/mark/strong.d.ts.map +1 -1
- package/lib/node/blockquote.d.ts +1 -5
- package/lib/node/blockquote.d.ts.map +1 -1
- package/lib/node/bullet-list.d.ts +1 -5
- package/lib/node/bullet-list.d.ts.map +1 -1
- package/lib/node/code-fence.d.ts +1 -5
- package/lib/node/code-fence.d.ts.map +1 -1
- package/lib/node/doc.d.ts +1 -5
- package/lib/node/doc.d.ts.map +1 -1
- package/lib/node/hardbreak.d.ts +1 -5
- package/lib/node/hardbreak.d.ts.map +1 -1
- package/lib/node/heading.d.ts +4 -5
- package/lib/node/heading.d.ts.map +1 -1
- package/lib/node/hr.d.ts +1 -5
- package/lib/node/hr.d.ts.map +1 -1
- package/lib/node/image.d.ts +1 -5
- package/lib/node/image.d.ts.map +1 -1
- package/lib/node/index.d.ts +2 -3
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/list-item.d.ts +1 -5
- package/lib/node/list-item.d.ts.map +1 -1
- package/lib/node/ordered-list.d.ts +1 -5
- package/lib/node/ordered-list.d.ts.map +1 -1
- package/lib/node/paragraph.d.ts +1 -5
- package/lib/node/paragraph.d.ts.map +1 -1
- package/lib/node/text.d.ts +1 -5
- package/lib/node/text.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/mark/link.ts +53 -8
- package/src/node/code-fence.ts +3 -3
- package/src/node/hardbreak.ts +16 -2
- package/src/node/heading.ts +36 -5
- package/src/node/hr.ts +4 -2
- package/src/node/image.ts +2 -2
- package/src/node/index.ts +3 -1
- package/src/node/paragraph.ts +12 -2
- package/src/plugin/inline-nodes-cursor.ts +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -3,13 +3,9 @@ import { commonmarkPlugins } from './plugin';
|
|
|
3
3
|
export * from './mark';
|
|
4
4
|
export * from './node';
|
|
5
5
|
export * from './supported-keys';
|
|
6
|
-
export declare const commonmarkNodes: AtomList<
|
|
7
|
-
languageList?: string[] | undefined;
|
|
8
|
-
}>> & import("@milkdown/core").MilkdownPlugin) | (import("@milkdown/utils").Metadata<import("@milkdown/utils").GetPlugin<string, import("./node").ImageOptions>> & import("@milkdown/core").MilkdownPlugin)>;
|
|
6
|
+
export declare const commonmarkNodes: AtomList<import("@milkdown/utils").AtomPlugin>;
|
|
9
7
|
export { commonmarkPlugins };
|
|
10
|
-
export declare const commonmark: AtomList<
|
|
11
|
-
languageList?: string[] | undefined;
|
|
12
|
-
}>> & import("@milkdown/core").MilkdownPlugin) | (import("@milkdown/utils").Metadata<import("@milkdown/utils").GetPlugin<string, import("./node").ImageOptions>> & import("@milkdown/core").MilkdownPlugin)>;
|
|
8
|
+
export declare const commonmark: AtomList<import("@milkdown/utils").AtomPlugin>;
|
|
13
9
|
export declare const commands: {
|
|
14
10
|
readonly ToggleInlineCode: import("@milkdown/core").CmdKey<undefined>;
|
|
15
11
|
readonly ToggleItalic: import("@milkdown/core").CmdKey<undefined>;
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAmB3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,kBAAkB,CAAC;AAEjC,eAAO,MAAM,eAAe
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAmB3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,kBAAkB,CAAC;AAEjC,eAAO,MAAM,eAAe,gDAAwC,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAC7B,eAAO,MAAM,UAAU,gDAA8D,CAAC;AAEtF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;CAwBX,CAAC;AACX,oBAAY,QAAQ,GAAG,OAAO,QAAQ,CAAC"}
|
package/lib/index.es.js
CHANGED
|
@@ -19,10 +19,10 @@ var __spreadValues = (a, b) => {
|
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
20
|
import { createMark, createShortcut, createNode, createPlugin, AtomList } from "@milkdown/utils";
|
|
21
21
|
import { createCmdKey, createCmd, schemaCtx, commandsCtx, editorViewCtx } from "@milkdown/core";
|
|
22
|
-
import { markRule, findSelectedNodeOfType } from "@milkdown/prose";
|
|
22
|
+
import { markRule, calculateTextPosition, findSelectedNodeOfType } from "@milkdown/prose";
|
|
23
23
|
import { toggleMark, wrapIn, setBlockType } from "@milkdown/prose/commands";
|
|
24
24
|
import { InputRule, wrappingInputRule, textblockTypeInputRule } from "@milkdown/prose/inputrules";
|
|
25
|
-
import { PluginKey, TextSelection, Plugin, Selection } from "@milkdown/prose/state";
|
|
25
|
+
import { PluginKey, TextSelection, Plugin, NodeSelection, Selection } from "@milkdown/prose/state";
|
|
26
26
|
import { Fragment } from "@milkdown/prose/model";
|
|
27
27
|
import { ReplaceStep, AddMarkStep } from "@milkdown/prose/transform";
|
|
28
28
|
import { splitListItem, sinkListItem, liftListItem } from "@milkdown/prose/schema-list";
|
|
@@ -164,14 +164,17 @@ const link = createMark((utils, options) => {
|
|
|
164
164
|
commands: (markType) => [
|
|
165
165
|
createCmd(ToggleLink, (href = "") => toggleMark(markType, { href })),
|
|
166
166
|
createCmd(ModifyLink, (href = "") => (state, dispatch) => {
|
|
167
|
+
var _a;
|
|
167
168
|
if (!dispatch)
|
|
168
169
|
return false;
|
|
169
170
|
const { marks: marks2 } = state.schema;
|
|
170
171
|
let node;
|
|
171
172
|
let pos = -1;
|
|
172
173
|
const { selection } = state;
|
|
173
|
-
|
|
174
|
-
|
|
174
|
+
const { from, to } = selection;
|
|
175
|
+
state.doc.nodesBetween(from, from === to ? to + 1 : to, (n, p) => {
|
|
176
|
+
var _a2;
|
|
177
|
+
if ((_a2 = marks2["link"]) == null ? void 0 : _a2.isInSet(n.marks)) {
|
|
175
178
|
node = n;
|
|
176
179
|
pos = p;
|
|
177
180
|
return false;
|
|
@@ -186,7 +189,9 @@ const link = createMark((utils, options) => {
|
|
|
186
189
|
const start = pos;
|
|
187
190
|
const end = pos + node.nodeSize;
|
|
188
191
|
const { tr } = state;
|
|
189
|
-
const linkMark = marks2
|
|
192
|
+
const linkMark = (_a = marks2["link"]) == null ? void 0 : _a.create(__spreadProps(__spreadValues({}, mark.attrs), { href }));
|
|
193
|
+
if (!linkMark)
|
|
194
|
+
return false;
|
|
190
195
|
dispatch(tr.removeMark(start, end, mark).addMark(start, end, linkMark).setSelection(new TextSelection(tr.selection.$anchor)).scrollIntoView());
|
|
191
196
|
return true;
|
|
192
197
|
})
|
|
@@ -203,6 +208,7 @@ const link = createMark((utils, options) => {
|
|
|
203
208
|
})
|
|
204
209
|
],
|
|
205
210
|
prosePlugins: (type, ctx) => {
|
|
211
|
+
let renderOnTop = false;
|
|
206
212
|
return [
|
|
207
213
|
new Plugin({
|
|
208
214
|
key: key$1,
|
|
@@ -213,6 +219,23 @@ const link = createMark((utils, options) => {
|
|
|
213
219
|
buttonText: (_c = options == null ? void 0 : options.input) == null ? void 0 : _c.buttonText,
|
|
214
220
|
onUpdate: (value) => {
|
|
215
221
|
ctx.get(commandsCtx).call(ModifyLink, value);
|
|
222
|
+
},
|
|
223
|
+
calculatePosition: (view, input) => {
|
|
224
|
+
calculateTextPosition(view, input, (start, end, target, parent) => {
|
|
225
|
+
const $editor = view.dom.parentElement;
|
|
226
|
+
if (!$editor) {
|
|
227
|
+
throw new Error();
|
|
228
|
+
}
|
|
229
|
+
const selectionWidth = end.left - start.left;
|
|
230
|
+
let left = start.left - parent.left - (target.width - selectionWidth) / 2;
|
|
231
|
+
let top = start.bottom - parent.top + 14 + $editor.scrollTop;
|
|
232
|
+
if (renderOnTop) {
|
|
233
|
+
top = start.top - parent.top - target.height - 14 + $editor.scrollTop;
|
|
234
|
+
}
|
|
235
|
+
if (left < 0)
|
|
236
|
+
left = 0;
|
|
237
|
+
return [top, left];
|
|
238
|
+
});
|
|
216
239
|
}
|
|
217
240
|
});
|
|
218
241
|
if (!inputChipRenderer)
|
|
@@ -220,7 +243,21 @@ const link = createMark((utils, options) => {
|
|
|
220
243
|
const shouldDisplay = (view) => {
|
|
221
244
|
const { selection, doc: doc2 } = view.state;
|
|
222
245
|
const { from, to } = selection;
|
|
223
|
-
|
|
246
|
+
if (!view.hasFocus()) {
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
if (selection.empty && selection instanceof TextSelection && to < doc2.content.size && from < doc2.content.size && doc2.rangeHasMark(from, from === to ? to + 1 : to, type)) {
|
|
250
|
+
renderOnTop = false;
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
if (selection instanceof NodeSelection) {
|
|
254
|
+
const { node } = selection;
|
|
255
|
+
if (node.type.name === "image" && node.marks.findIndex((mark) => mark.type.name === id$8) > -1) {
|
|
256
|
+
renderOnTop = true;
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return false;
|
|
224
261
|
};
|
|
225
262
|
const getCurrentLink = (view) => {
|
|
226
263
|
const { selection } = view.state;
|
|
@@ -260,7 +297,9 @@ const link = createMark((utils, options) => {
|
|
|
260
297
|
const isEqualSelection = (prevState == null ? void 0 : prevState.doc.eq(view.state.doc)) && prevState.selection.eq(view.state.selection);
|
|
261
298
|
if (isEqualSelection)
|
|
262
299
|
return;
|
|
263
|
-
|
|
300
|
+
requestAnimationFrame(() => {
|
|
301
|
+
renderByView(view);
|
|
302
|
+
});
|
|
264
303
|
},
|
|
265
304
|
destroy: () => {
|
|
266
305
|
inputChipRenderer.destroy();
|
|
@@ -623,7 +662,16 @@ const hardbreak = createNode((utils) => {
|
|
|
623
662
|
}),
|
|
624
663
|
commands: (type) => [
|
|
625
664
|
createCmd(InsertHardbreak, () => (state, dispatch) => {
|
|
626
|
-
|
|
665
|
+
var _a;
|
|
666
|
+
const { selection, tr } = state;
|
|
667
|
+
if (selection.empty) {
|
|
668
|
+
const node = selection.$from.node();
|
|
669
|
+
if (node.childCount > 0 && ((_a = node.lastChild) == null ? void 0 : _a.type.name) === "hardbreak") {
|
|
670
|
+
dispatch == null ? void 0 : dispatch(tr.replaceRangeWith(selection.to - 1, selection.to, state.schema.node("paragraph")).setSelection(Selection.near(tr.doc.resolve(selection.to))).scrollIntoView());
|
|
671
|
+
return true;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
dispatch == null ? void 0 : dispatch(tr.setMeta("hardbreak", true).replaceSelectionWith(type.create()).scrollIntoView());
|
|
627
675
|
return true;
|
|
628
676
|
})
|
|
629
677
|
],
|
|
@@ -669,8 +717,10 @@ const headingIndex = Array(6).fill(0).map((_, i) => i + 1);
|
|
|
669
717
|
const TurnIntoHeading = createCmdKey("TurnIntoHeading");
|
|
670
718
|
const headingPluginKey = new PluginKey("MILKDOWN_ID");
|
|
671
719
|
const createId = (node) => node.textContent.replace(/[\p{P}\p{S}]/gu, "").replace(/\s/g, "-").toLowerCase().trim();
|
|
672
|
-
const heading = createNode((utils) => {
|
|
720
|
+
const heading = createNode((utils, options) => {
|
|
721
|
+
var _a;
|
|
673
722
|
const id2 = "heading";
|
|
723
|
+
const getId = (_a = options == null ? void 0 : options.getId) != null ? _a : createId;
|
|
674
724
|
return {
|
|
675
725
|
id: id2,
|
|
676
726
|
schema: () => ({
|
|
@@ -698,7 +748,7 @@ const heading = createNode((utils) => {
|
|
|
698
748
|
return [
|
|
699
749
|
`h${node.attrs["level"]}`,
|
|
700
750
|
{
|
|
701
|
-
id: node.attrs["id"] ||
|
|
751
|
+
id: node.attrs["id"] || getId(node),
|
|
702
752
|
class: utils.getClassName(node.attrs, `heading h${node.attrs["level"]}`)
|
|
703
753
|
},
|
|
704
754
|
0
|
|
@@ -716,8 +766,21 @@ const heading = createNode((utils) => {
|
|
|
716
766
|
toMarkdown: {
|
|
717
767
|
match: (node) => node.type.name === id2,
|
|
718
768
|
runner: (state, node) => {
|
|
769
|
+
var _a2;
|
|
719
770
|
state.openNode("heading", void 0, { depth: node.attrs["level"] });
|
|
720
|
-
|
|
771
|
+
const lastIsHardbreak = node.childCount >= 1 && ((_a2 = node.lastChild) == null ? void 0 : _a2.type.name) === "hardbreak";
|
|
772
|
+
if (lastIsHardbreak) {
|
|
773
|
+
const contentArr = [];
|
|
774
|
+
node.content.forEach((n, _, i) => {
|
|
775
|
+
if (i === node.childCount - 1) {
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
contentArr.push(n);
|
|
779
|
+
});
|
|
780
|
+
state.next(Fragment.fromArray(contentArr));
|
|
781
|
+
} else {
|
|
782
|
+
state.next(node.content);
|
|
783
|
+
}
|
|
721
784
|
state.closeNode();
|
|
722
785
|
}
|
|
723
786
|
}
|
|
@@ -744,7 +807,7 @@ const heading = createNode((utils) => {
|
|
|
744
807
|
return;
|
|
745
808
|
}
|
|
746
809
|
const attrs = node.attrs;
|
|
747
|
-
const id22 =
|
|
810
|
+
const id22 = getId(node);
|
|
748
811
|
if (attrs["id"] !== id22) {
|
|
749
812
|
tr.setMeta(headingPluginKey, true).setNodeMarkup(pos, void 0, __spreadProps(__spreadValues({}, attrs), {
|
|
750
813
|
id: id22
|
|
@@ -781,6 +844,21 @@ const heading = createNode((utils) => {
|
|
|
781
844
|
});
|
|
782
845
|
}
|
|
783
846
|
return tr;
|
|
847
|
+
},
|
|
848
|
+
view: (view) => {
|
|
849
|
+
const doc2 = view.state.doc;
|
|
850
|
+
let tr = view.state.tr;
|
|
851
|
+
doc2.descendants((node, pos) => {
|
|
852
|
+
if (node.type.name === "heading" && node.attrs["level"]) {
|
|
853
|
+
if (!node.attrs["id"]) {
|
|
854
|
+
tr = tr.setNodeMarkup(pos, void 0, __spreadProps(__spreadValues({}, node.attrs), {
|
|
855
|
+
id: getId(node)
|
|
856
|
+
}));
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
});
|
|
860
|
+
view.dispatch(tr);
|
|
861
|
+
return {};
|
|
784
862
|
}
|
|
785
863
|
})
|
|
786
864
|
];
|
|
@@ -822,13 +900,14 @@ const hr = createNode((utils) => {
|
|
|
822
900
|
createCmd(InsertHr, () => (state, dispatch) => {
|
|
823
901
|
if (!dispatch)
|
|
824
902
|
return true;
|
|
903
|
+
const paragraph2 = ctx.get(schemaCtx).node("paragraph");
|
|
825
904
|
const { tr, selection } = state;
|
|
826
|
-
const from = selection
|
|
905
|
+
const { from } = selection;
|
|
827
906
|
const node = type.create();
|
|
828
907
|
if (!node) {
|
|
829
908
|
return true;
|
|
830
909
|
}
|
|
831
|
-
const _tr = tr.replaceSelectionWith(node).insert(from,
|
|
910
|
+
const _tr = tr.replaceSelectionWith(node).insert(from, paragraph2);
|
|
832
911
|
const sel = Selection.findFrom(_tr.doc.resolve(from), 1, true);
|
|
833
912
|
if (!sel) {
|
|
834
913
|
return true;
|
|
@@ -1148,8 +1227,17 @@ const paragraph = createNode((utils) => {
|
|
|
1148
1227
|
runner: (state, node) => {
|
|
1149
1228
|
var _a;
|
|
1150
1229
|
state.openNode("paragraph");
|
|
1151
|
-
const
|
|
1152
|
-
if (
|
|
1230
|
+
const lastIsHardbreak = node.childCount >= 1 && ((_a = node.lastChild) == null ? void 0 : _a.type.name) === "hardbreak";
|
|
1231
|
+
if (lastIsHardbreak) {
|
|
1232
|
+
const contentArr = [];
|
|
1233
|
+
node.content.forEach((n, _, i) => {
|
|
1234
|
+
if (i === node.childCount - 1) {
|
|
1235
|
+
return;
|
|
1236
|
+
}
|
|
1237
|
+
contentArr.push(n);
|
|
1238
|
+
});
|
|
1239
|
+
state.next(Fragment.fromArray(contentArr));
|
|
1240
|
+
} else {
|
|
1153
1241
|
state.next(node.content);
|
|
1154
1242
|
}
|
|
1155
1243
|
state.closeNode();
|
|
@@ -1255,7 +1343,7 @@ const inlineNodesCursorPlugin = new Plugin({
|
|
|
1255
1343
|
handleDOMEvents: {
|
|
1256
1344
|
beforeinput: (view, e) => {
|
|
1257
1345
|
const active = inlineNodesCursorPlugin.getState(view.state);
|
|
1258
|
-
if (active) {
|
|
1346
|
+
if (active && e instanceof InputEvent) {
|
|
1259
1347
|
const from = view.state.selection.from;
|
|
1260
1348
|
e.preventDefault();
|
|
1261
1349
|
view.dispatch(view.state.tr.insertText(e.data || "", from));
|