import { $markAttr as V, $markSchema as U, $command as c, $inputRule as h, $useKeymap as f, $node as Qe, $nodeAttr as N, $nodeSchema as I, $ctx as Xe, $remark as D, $prose as _ } from "@milkdown/utils"; import { remarkStringifyOptionsCtx as Ye, commandsCtx as u, editorViewCtx as wt } from "@milkdown/core"; import { toggleMark as z, setBlockType as K, wrapIn as J } from "@milkdown/prose/commands"; import { Fragment as At } from "@milkdown/prose/model"; import { expectDomTypeError as w } from "@milkdown/exception"; import { textblockTypeInputRule as Ze, wrappingInputRule as Q, InputRule as et } from "@milkdown/prose/inputrules"; import Ht from "@sindresorhus/slugify"; import { TextSelection as X, Selection as tt, PluginKey as E, Plugin as P } from "@milkdown/prose/state"; import { markRule as G, findSelectedNodeOfType as Bt } from "@milkdown/prose"; import { sinkListItem as Rt, liftListItem as rt, splitListItem as vt } from "@milkdown/prose/schema-list"; import { ReplaceStep as Ot, AddMarkStep as Tt } from "@milkdown/prose/transform"; import { Decoration as ze, DecorationSet as Je } from "@milkdown/prose/view"; import { visit as Y } from "unist-util-visit"; import Kt from "remark-inline-links"; function at(t, e) { var o; if (!(e.childCount >= 1 && ((o = e.lastChild) == null ? void 0 : o.type.name) === "hardbreak")) { t.next(e.content); return; } const a = []; e.content.forEach((s, l, i) => { i !== e.childCount - 1 && a.push(s); }), t.next(At.fromArray(a)); } function n(t, e) { return Object.assign(t, { meta: { package: "@milkdown/preset-commonmark", ...e } }), t; } const Z = V("emphasis"); n(Z, { displayName: "Attr", group: "Emphasis" }); const R = U("emphasis", (t) => ({ attrs: { marker: { default: t.get(Ye).emphasis || "*" } }, parseDOM: [ { tag: "i" }, { tag: "em" }, { style: "font-style", getAttrs: (e) => e === "italic" } ], toDOM: (e) => ["em", t.get(Z.key)(e)], parseMarkdown: { match: (e) => e.type === "emphasis", runner: (e, r, a) => { e.openMark(a, { marker: r.marker }), e.next(r.children), e.closeMark(a); } }, toMarkdown: { match: (e) => e.type.name === "emphasis", runner: (e, r) => { e.withMark(r, "emphasis", void 0, { marker: r.attrs.marker }); } } })); n(R.mark, { displayName: "MarkSchema", group: "Emphasis" }); n(R.ctx, { displayName: "MarkSchemaCtx", group: "Emphasis" }); const ee = c("ToggleEmphasis", (t) => () => z(R.type(t))); n(ee, { displayName: "Command", group: "Emphasis" }); const nt = h((t) => G(/(?:^|[^*])\*([^*]+)\*$/, R.type(t), { updateCaptured: ({ fullMatch: e, start: r }) => e.startsWith("*") ? {} : { fullMatch: e.slice(1), start: r + 1 } })); n(nt, { displayName: "InputRule|Star", group: "Emphasis" }); const ot = h((t) => G(/(?:^|[^_])_([^_]+)_$/, R.type(t), { updateCaptured: ({ fullMatch: e, start: r }) => e.startsWith("_") ? {} : { fullMatch: e.slice(1), start: r + 1 } })); n(ot, { displayName: "InputRule|Underscore", group: "Emphasis" }); const te = f("emphasisKeymap", { ToggleEmphasis: { shortcuts: "Mod-i", command: (t) => { const e = t.get(u); return () => e.call(ee.key); } } }); n(te.ctx, { displayName: "KeymapCtx", group: "Emphasis" }); n(te.shortcuts, { displayName: "Keymap", group: "Emphasis" }); const re = V("strong"); n(re, { displayName: "Attr", group: "Strong" }); const $ = U("strong", (t) => ({ attrs: { marker: { default: t.get(Ye).strong || "*" } }, parseDOM: [ { tag: "b" }, { tag: "strong" }, { style: "font-style", getAttrs: (e) => e === "bold" } ], toDOM: (e) => ["strong", t.get(re.key)(e)], parseMarkdown: { match: (e) => e.type === "strong", runner: (e, r, a) => { e.openMark(a, { marker: r.marker }), e.next(r.children), e.closeMark(a); } }, toMarkdown: { match: (e) => e.type.name === "strong", runner: (e, r) => { e.withMark(r, "strong", void 0, { marker: r.attrs.marker }); } } })); n($.mark, { displayName: "MarkSchema", group: "Strong" }); n($.ctx, { displayName: "MarkSchemaCtx", group: "Strong" }); const ae = c("ToggleStrong", (t) => () => z($.type(t))); n(ae, { displayName: "Command", group: "Strong" }); const st = h((t) => G(/(?:\*\*|__)([^*_]+)(?:\*\*|__)$/, $.type(t))); n(st, { displayName: "InputRule", group: "Strong" }); const ne = f("strongKeymap", { ToggleBold: { shortcuts: ["Mod-b"], command: (t) => { const e = t.get(u); return () => e.call(ae.key); } } }); n(ne.ctx, { displayName: "KeymapCtx", group: "Strong" }); n(ne.shortcuts, { displayName: "Keymap", group: "Strong" }); const oe = V("inlineCode"); n(oe, { displayName: "Attr", group: "InlineCode" }); const x = U("inlineCode", (t) => ({ priority: 100, code: !0, inclusive: !1, parseDOM: [{ tag: "code" }], toDOM: (e) => ["code", t.get(oe.key)(e)], parseMarkdown: { match: (e) => e.type === "inlineCode", runner: (e, r, a) => { e.openMark(a), e.addText(r.value), e.closeMark(a); } }, toMarkdown: { match: (e) => e.type.name === "inlineCode", runner: (e, r, a) => { e.withMark(r, "inlineCode", a.text || ""); } } })); n(x.mark, { displayName: "MarkSchema", group: "InlineCode" }); n(x.ctx, { displayName: "MarkSchemaCtx", group: "InlineCode" }); const se = c("ToggleInlineCode", (t) => () => (e, r) => { const { selection: a, tr: o } = e; if (a.empty) return !1; const { from: s, to: l } = a; return e.doc.rangeHasMark(s, l, x.type(t)) ? (r == null || r(o.removeMark(s, l, x.type(t))), !0) : (Object.keys(e.schema.marks).filter((m) => m !== x.type.name).map((m) => e.schema.marks[m]).forEach((m) => { o.removeMark(s, l, m); }), r == null || r(o.addMark(s, l, x.type(t).create())), !0); }); n(se, { displayName: "Command", group: "InlineCode" }); const lt = h((t) => G(/(?:\`)([^\`]+)(?:\`)$/, x.type(t))); n(lt, { displayName: "InputRule", group: "InlineCode" }); const le = f("inlineCodeKeymap", { ToggleInlineCode: { shortcuts: "Mod-e", command: (t) => { const e = t.get(u); return () => e.call(se.key); } } }); n(le.ctx, { displayName: "KeymapCtx", group: "InlineCode" }); n(le.shortcuts, { displayName: "Keymap", group: "InlineCode" }); const ie = V("link"); n(ie, { displayName: "Attr", group: "Link" }); const B = U("link", (t) => ({ attrs: { href: {}, title: { default: null } }, parseDOM: [ { tag: "a[href]", getAttrs: (e) => { if (!(e instanceof HTMLElement)) throw w(e); return { href: e.getAttribute("href"), title: e.getAttribute("title") }; } } ], toDOM: (e) => ["a", { ...t.get(ie.key)(e), ...e.attrs }], parseMarkdown: { match: (e) => e.type === "link", runner: (e, r, a) => { const o = r.url, s = r.title; e.openMark(a, { href: o, title: s }), e.next(r.children), e.closeMark(a); } }, toMarkdown: { match: (e) => e.type.name === "link", runner: (e, r) => { e.withMark(r, "link", void 0, { title: r.attrs.title, url: r.attrs.href }); } } })); n(B.mark, { displayName: "MarkSchema", group: "Link" }); const it = c("ToggleLink", (t) => (e = {}) => z(B.type(t), e)); n(it, { displayName: "Command", group: "Link" }); const dt = c("UpdateLink", (t) => (e = {}) => (r, a) => { if (!a) return !1; let o, s = -1; const { selection: l } = r, { from: i, to: d } = l; if (r.doc.nodesBetween(i, i === d ? d + 1 : d, (y, b) => { if (B.type(t).isInSet(y.marks)) return o = y, s = b, !1; }), !o) return !1; const m = o.marks.find(({ type: y }) => y === B.type(t)); if (!m) return !1; const p = s, k = s + o.nodeSize, { tr: g } = r, C = B.type(t).create({ ...m.attrs, ...e }); return C ? (a( g.removeMark(p, k, m).addMark(p, k, C).setSelection(new X(g.selection.$anchor)).scrollIntoView() ), !0) : !1; }); n(dt, { displayName: "Command", group: "Link" }); const mt = Qe("doc", () => ({ content: "block+", parseMarkdown: { match: ({ type: t }) => t === "root", runner: (t, e, r) => { t.injectRoot(e, r); } }, toMarkdown: { match: (t) => t.type.name === "doc", runner: (t, e) => { t.openNode("root"), t.next(e.content); } } })); n(mt, { displayName: "NodeSchema", group: "Doc" }); const de = N("paragraph"); n(de, { displayName: "Attr", group: "Paragraph" }); const A = I("paragraph", (t) => ({ content: "inline*", group: "block", parseDOM: [{ tag: "p" }], toDOM: (e) => ["p", t.get(de.key)(e), 0], parseMarkdown: { match: (e) => e.type === "paragraph", runner: (e, r, a) => { e.openNode(a), r.children ? e.next(r.children) : e.addText(r.value || ""), e.closeNode(); } }, toMarkdown: { match: (e) => e.type.name === "paragraph", runner: (e, r) => { e.openNode("paragraph"), at(e, r), e.closeNode(); } } })); n(A.node, { displayName: "NodeSchema", group: "Paragraph" }); n(A.ctx, { displayName: "NodeSchemaCtx", group: "Paragraph" }); const me = c("TurnIntoText", (t) => () => K(A.type(t))); n(me, { displayName: "Command", group: "Paragraph" }); const pe = f("paragraphKeymap", { TurnIntoText: { shortcuts: "Mod-Alt-0", command: (t) => { const e = t.get(u); return () => e.call(me.key); } } }); n(pe.ctx, { displayName: "KeymapCtx", group: "Paragraph" }); n(pe.shortcuts, { displayName: "Keymap", group: "Paragraph" }); const Dt = Array(6).fill(0).map((t, e) => e + 1); function _t(t) { return Ht(t.textContent); } const j = Xe(_t, "headingIdGenerator"); n(j, { displayName: "Ctx", group: "Heading" }); const ce = N("heading"); n(ce, { displayName: "Attr", group: "Heading" }); const H = I("heading", (t) => { const e = t.get(j.key); return { content: "inline*", group: "block", defining: !0, attrs: { id: { default: "" }, level: { default: 1 } }, parseDOM: Dt.map((r) => ({ tag: `h${r}`, getAttrs: (a) => { if (!(a instanceof HTMLElement)) throw w(a); return { level: r, id: a.id }; } })), toDOM: (r) => [ `h${r.attrs.level}`, { ...t.get(ce.key)(r), id: r.attrs.id || e(r) }, 0 ], parseMarkdown: { match: ({ type: r }) => r === "heading", runner: (r, a, o) => { const s = a.depth; r.openNode(o, { level: s }), r.next(a.children), r.closeNode(); } }, toMarkdown: { match: (r) => r.type.name === "heading", runner: (r, a) => { r.openNode("heading", void 0, { depth: a.attrs.level }), at(r, a), r.closeNode(); } } }; }); n(H.node, { displayName: "NodeSchema", group: "Heading" }); n(H.ctx, { displayName: "NodeSchemaCtx", group: "Heading" }); const pt = h((t) => Ze(/^(?#+)\s$/, H.type(t), (e) => { var l, i; const r = ((i = (l = e.groups) == null ? void 0 : l.hashes) == null ? void 0 : i.length) || 0, a = t.get(wt), { $from: o } = a.state.selection, s = o.node(); if (s.type.name === "heading") { let d = Number(s.attrs.level) + Number(r); return d > 6 && (d = 6), { level: d }; } return { level: r }; })); n(pt, { displayName: "InputRule", group: "Heading" }); const L = c("WrapInHeading", (t) => (e) => (e ?? (e = 1), e < 1 ? K(A.type(t)) : K(H.type(t), { level: e }))); n(L, { displayName: "Command", group: "Heading" }); const ue = c("DowngradeHeading", (t) => () => (e, r, a) => { const { $from: o } = e.selection, s = o.node(); if (s.type !== H.type(t) || !e.selection.empty || o.parentOffset !== 0) return !1; const l = s.attrs.level - 1; return l ? (r == null || r( e.tr.setNodeMarkup(e.selection.$from.before(), void 0, { ...s.attrs, level: l }) ), !0) : K(A.type(t))(e, r, a); }); n(ue, { displayName: "Command", group: "Heading" }); const ge = f("headingKeymap", { TurnIntoH1: { shortcuts: "Mod-Alt-1", command: (t) => { const e = t.get(u); return () => e.call(L.key, 1); } }, TurnIntoH2: { shortcuts: "Mod-Alt-2", command: (t) => { const e = t.get(u); return () => e.call(L.key, 2); } }, TurnIntoH3: { shortcuts: "Mod-Alt-3", command: (t) => { const e = t.get(u); return () => e.call(L.key, 3); } }, TurnIntoH4: { shortcuts: "Mod-Alt-4", command: (t) => { const e = t.get(u); return () => e.call(L.key, 4); } }, TurnIntoH5: { shortcuts: "Mod-Alt-5", command: (t) => { const e = t.get(u); return () => e.call(L.key, 5); } }, TurnIntoH6: { shortcuts: "Mod-Alt-6", command: (t) => { const e = t.get(u); return () => e.call(L.key, 6); } }, DowngradeHeading: { shortcuts: ["Delete", "Backspace"], command: (t) => { const e = t.get(u); return () => e.call(ue.key); } } }); n(ge.ctx, { displayName: "KeymapCtx", group: "Heading" }); n(ge.shortcuts, { displayName: "Keymap", group: "Heading" }); const ye = N("blockquote"); n(ye, { displayName: "Attr
", group: "Blockquote" }); const q = I("blockquote", (t) => ({ content: "block+", group: "block", defining: !0, parseDOM: [{ tag: "blockquote" }], toDOM: (e) => ["blockquote", t.get(ye.key)(e), 0], parseMarkdown: { match: ({ type: e }) => e === "blockquote", runner: (e, r, a) => { e.openNode(a).next(r.children).closeNode(); } }, toMarkdown: { match: (e) => e.type.name === "blockquote", runner: (e, r) => { e.openNode("blockquote").next(r.content).closeNode(); } } })); n(q.node, { displayName: "NodeSchema
", group: "Blockquote" }); n(q.ctx, { displayName: "NodeSchemaCtx
", group: "Blockquote" }); const ct = h((t) => Q(/^\s*>\s$/, q.type(t))); n(ct, { displayName: "InputRule", group: "Blockquote" }); const ke = c("WrapInBlockquote", (t) => () => J(q.type(t))); n(ke, { displayName: "Command", group: "Blockquote" }); const he = f("blockquoteKeymap", { WrapInBlockquote: { shortcuts: "Mod-Shift-b", command: (t) => { const e = t.get(u); return () => e.call(ke.key); } } }); n(he.ctx, { displayName: "KeymapCtx
", group: "Blockquote" }); n(he.shortcuts, { displayName: "Keymap
", group: "Blockquote" }); const fe = N("codeBlock", () => ({ pre: {}, code: {} })); n(fe, { displayName: "Attr", group: "CodeBlock" }); const W = I("code_block", (t) => ({ content: "text*", group: "block", marks: "", defining: !0, code: !0, attrs: { language: { default: "" } }, parseDOM: [ { tag: "pre", preserveWhitespace: "full", getAttrs: (e) => { if (!(e instanceof HTMLElement)) throw w(e); return { language: e.dataset.language }; } } ], toDOM: (e) => { const r = t.get(fe.key)(e); return [ "pre", { ...r.pre, "data-language": e.attrs.language }, ["code", r.code, 0] ]; }, parseMarkdown: { match: ({ type: e }) => e === "code", runner: (e, r, a) => { const o = r.lang, s = r.value; e.openNode(a, { language: o }), s && e.addText(s), e.closeNode(); } }, toMarkdown: { match: (e) => e.type.name === "code_block", runner: (e, r) => { var a; e.addNode("code", void 0, ((a = r.content.firstChild) == null ? void 0 : a.text) || "", { lang: r.attrs.language }); } } })); n(W.node, { displayName: "NodeSchema", group: "CodeBlock" }); n(W.ctx, { displayName: "NodeSchemaCtx", group: "CodeBlock" }); const ut = h((t) => Ze(/^```(?[a-z]*)?[\s\n]$/, W.type(t), (e) => { var r; return { language: ((r = e.groups) == null ? void 0 : r.language) ?? "" }; })); n(ut, { displayName: "InputRule", group: "CodeBlock" }); const Ne = c("CreateCodeBlock", (t) => (e = "") => K(W.type(t), { language: e })); n(Ne, { displayName: "Command", group: "CodeBlock" }); const Et = c("UpdateCodeBlockLanguage", () => ({ pos: t, language: e } = { pos: -1, language: "" }) => (r, a) => t >= 0 ? (a == null || a(r.tr.setNodeAttribute(t, "language", e)), !0) : !1); n(Et, { displayName: "Command", group: "CodeBlock" }); const Ie = f("codeBlockKeymap", { CreateCodeBlock: { shortcuts: "Mod-Alt-c", command: (t) => { const e = t.get(u); return () => e.call(Ne.key); } } }); n(Ie.ctx, { displayName: "KeymapCtx", group: "CodeBlock" }); n(Ie.shortcuts, { displayName: "Keymap", group: "CodeBlock" }); const Ce = N("image"); n(Ce, { displayName: "Attr", group: "Image" }); const v = I("image", (t) => ({ inline: !0, group: "inline", selectable: !0, draggable: !0, marks: "", atom: !0, defining: !0, isolating: !0, attrs: { src: { default: "" }, alt: { default: "" }, title: { default: "" } }, parseDOM: [ { tag: "img[src]", getAttrs: (e) => { if (!(e instanceof HTMLElement)) throw w(e); return { src: e.getAttribute("src") || "", alt: e.getAttribute("alt") || "", title: e.getAttribute("title") || e.getAttribute("alt") || "" }; } } ], toDOM: (e) => ["img", { ...t.get(Ce.key)(e), ...e.attrs }], parseMarkdown: { match: ({ type: e }) => e === "image", runner: (e, r, a) => { const o = r.url, s = r.alt, l = r.title; e.addNode(a, { src: o, alt: s, title: l }); } }, toMarkdown: { match: (e) => e.type.name === "image", runner: (e, r) => { e.addNode("image", void 0, void 0, { title: r.attrs.title, url: r.attrs.src, alt: r.attrs.alt }); } } })); n(v.node, { displayName: "NodeSchema", group: "Image" }); n(v.ctx, { displayName: "NodeSchemaCtx", group: "Image" }); const gt = c("InsertImage", (t) => (e = {}) => (r, a) => { if (!a) return !0; const { src: o = "", alt: s = "", title: l = "" } = e, i = v.type(t).create({ src: o, alt: s, title: l }); return i && a(r.tr.replaceSelectionWith(i).scrollIntoView()), !0; }); n(gt, { displayName: "Command", group: "Image" }); const yt = c("UpdateImage", (t) => (e = {}) => (r, a) => { const o = Bt(r.selection, v.type(t)); if (!o) return !1; const { node: s, pos: l } = o, i = { ...s.attrs }, { src: d, alt: m, title: p } = e; return d !== void 0 && (i.src = d), m !== void 0 && (i.alt = m), p !== void 0 && (i.title = p), a == null || a(r.tr.setNodeMarkup(l, void 0, i).scrollIntoView()), !0; }); n(yt, { displayName: "Command", group: "Image" }); const Pt = h((t) => new et( /!\[(?.*?)]\((?.*?)\s*(?="|\))"?(?[^"]+)?"?\)/, (e, r, a, o) => { const [s, l, i = "", d] = r; return s ? e.tr.replaceWith(a, o, v.type(t).create({ src: i, alt: l, title: d })) : null; } )); n(Pt, { displayName: "InputRule<insertImageInputRule>", group: "Image" }); const Me = N("hardbreak", (t) => ({ "data-is-inline": t.attrs.isInline })); n(Me, { displayName: "Attr<hardbreak>", group: "Hardbreak" }); const S = I("hardbreak", (t) => ({ inline: !0, group: "inline", attrs: { isInline: { default: !1 } }, selectable: !1, parseDOM: [{ tag: "br" }], toDOM: (e) => ["br", t.get(Me.key)(e)], parseMarkdown: { match: ({ type: e }) => e === "break", runner: (e, r, a) => { var o; e.addNode(a, { isInline: !!((o = r.data) != null && o.isInline) }); } }, leafText: () => ` `, toMarkdown: { match: (e) => e.type.name === "hardbreak", runner: (e, r) => { r.attrs.isInline ? e.addNode("text", void 0, ` `) : e.addNode("break"); } } })); n(S.node, { displayName: "NodeSchema<hardbreak>", group: "Hardbreak" }); n(S.ctx, { displayName: "NodeSchemaCtx<hardbreak>", group: "Hardbreak" }); const be = c("InsertHardbreak", (t) => () => (e, r) => { var s; const { selection: a, tr: o } = e; if (!(a instanceof X)) return !1; if (a.empty) { const l = a.$from.node(); if (l.childCount > 0 && ((s = l.lastChild) == null ? void 0 : s.type.name) === "hardbreak") return r == null || r( o.replaceRangeWith(a.to - 1, a.to, e.schema.node("paragraph")).setSelection(tt.near(o.doc.resolve(a.to))).scrollIntoView() ), !0; } return r == null || r(o.setMeta("hardbreak", !0).replaceSelectionWith(S.type(t).create()).scrollIntoView()), !0; }); n(be, { displayName: "Command<insertHardbreakCommand>", group: "Hardbreak" }); const Le = f("hardbreakKeymap", { InsertHardbreak: { shortcuts: "Shift-Enter", command: (t) => { const e = t.get(u); return () => e.call(be.key); } } }); n(Le.ctx, { displayName: "KeymapCtx<hardbreak>", group: "Hardbreak" }); n(Le.shortcuts, { displayName: "Keymap<hardbreak>", group: "Hardbreak" }); const xe = N("hr"); n(xe, { displayName: "Attr<hr>", group: "Hr" }); const F = I("hr", (t) => ({ group: "block", parseDOM: [{ tag: "hr" }], toDOM: (e) => ["hr", t.get(xe.key)(e)], parseMarkdown: { match: ({ type: e }) => e === "thematicBreak", runner: (e, r, a) => { e.addNode(a); } }, toMarkdown: { match: (e) => e.type.name === "hr", runner: (e) => { e.addNode("thematicBreak"); } } })); n(F.node, { displayName: "NodeSchema<hr>", group: "Hr" }); n(F.ctx, { displayName: "NodeSchemaCtx<hr>", group: "Hr" }); const kt = h((t) => new et( /^(?:---|___\s|\*\*\*\s)$/, (e, r, a, o) => { const { tr: s } = e; return r[0] && s.replaceWith(a - 1, o, F.type(t).create()), s; } )); n(kt, { displayName: "InputRule<insertHrInputRule>", group: "Hr" }); const ht = c("InsertHr", (t) => () => (e, r) => { if (!r) return !0; const a = A.node.type(t).create(), { tr: o, selection: s } = e, { from: l } = s, i = F.type(t).create(); if (!i) return !0; const d = o.replaceSelectionWith(i).insert(l, a), m = tt.findFrom(d.doc.resolve(l), 1, !0); return m && r(d.setSelection(m).scrollIntoView()), !0; }); n(ht, { displayName: "Command<insertHrCommand>", group: "Hr" }); const Se = N("bulletList"); n(Se, { displayName: "Attr<bulletList>", group: "BulletList" }); const O = I("bullet_list", (t) => ({ content: "listItem+", group: "block", attrs: { spread: { default: !1 } }, parseDOM: [ { tag: "ul", getAttrs: (e) => { if (!(e instanceof HTMLElement)) throw w(e); return { spread: e.dataset.spread }; } } ], toDOM: (e) => [ "ul", { ...t.get(Se.key)(e), "data-spread": e.attrs.spread }, 0 ], parseMarkdown: { match: ({ type: e, ordered: r }) => e === "list" && !r, runner: (e, r, a) => { const o = r.spread != null ? `${r.spread}` : "false"; e.openNode(a, { spread: o }).next(r.children).closeNode(); } }, toMarkdown: { match: (e) => e.type.name === "bullet_list", runner: (e, r) => { e.openNode("list", void 0, { ordered: !1, spread: r.attrs.spread === "true" }).next(r.content).closeNode(); } } })); n(O.node, { displayName: "NodeSchema<bulletList>", group: "BulletList" }); n(O.ctx, { displayName: "NodeSchemaCtx<bulletList>", group: "BulletList" }); const ft = h((t) => Q(/^\s*([-+*])\s$/, O.type(t))); n(ft, { displayName: "InputRule<wrapInBulletListInputRule>", group: "BulletList" }); const we = c("WrapInBulletList", (t) => () => J(O.type(t))); n(we, { displayName: "Command<wrapInBulletListCommand>", group: "BulletList" }); const Ae = f("bulletListKeymap", { WrapInBulletList: { shortcuts: "Mod-Alt-8", command: (t) => { const e = t.get(u); return () => e.call(we.key); } } }); n(Ae.ctx, { displayName: "KeymapCtx<bulletListKeymap>", group: "BulletList" }); n(Ae.shortcuts, { displayName: "Keymap<bulletListKeymap>", group: "BulletList" }); const He = N("orderedList"); n(He, { displayName: "Attr<orderedList>", group: "OrderedList" }); const T = I("ordered_list", (t) => ({ content: "listItem+", group: "block", attrs: { order: { default: 1 }, spread: { default: !1 } }, parseDOM: [ { tag: "ol", getAttrs: (e) => { if (!(e instanceof HTMLElement)) throw w(e); return { spread: e.dataset.spread, order: e.hasAttribute("start") ? Number(e.getAttribute("start")) : 1 }; } } ], toDOM: (e) => [ "ol", { ...t.get(He.key)(e), ...e.attrs.order === 1 ? {} : e.attrs.order, "data-spread": e.attrs.spread }, 0 ], parseMarkdown: { match: ({ type: e, ordered: r }) => e === "list" && !!r, runner: (e, r, a) => { const o = r.spread != null ? `${r.spread}` : "true"; e.openNode(a, { spread: o }).next(r.children).closeNode(); } }, toMarkdown: { match: (e) => e.type.name === "ordered_list", runner: (e, r) => { e.openNode("list", void 0, { ordered: !0, start: 1, spread: r.attrs.spread === "true" }), e.next(r.content), e.closeNode(); } } })); n(T.node, { displayName: "NodeSchema<orderedList>", group: "OrderedList" }); n(T.ctx, { displayName: "NodeSchemaCtx<orderedList>", group: "OrderedList" }); const Nt = h((t) => Q( /^\s*(\d+)\.\s$/, T.type(t), (e) => ({ order: Number(e[1]) }), (e, r) => r.childCount + r.attrs.order === Number(e[1]) )); n(Nt, { displayName: "InputRule<wrapInOrderedListInputRule>", group: "OrderedList" }); const Be = c("WrapInOrderedList", (t) => () => J(T.type(t))); n(Be, { displayName: "Command<wrapInOrderedListCommand>", group: "OrderedList" }); const Re = f("orderedListKeymap", { WrapInOrderedList: { shortcuts: "Mod-Alt-7", command: (t) => { const e = t.get(u); return () => e.call(Be.key); } } }); n(Re.ctx, { displayName: "KeymapCtx<orderedList>", group: "OrderedList" }); n(Re.shortcuts, { displayName: "Keymap<orderedList>", group: "OrderedList" }); const ve = N("listItem"); n(ve, { displayName: "Attr<listItem>", group: "ListItem" }); const M = I("list_item", (t) => ({ group: "listItem", content: "paragraph block*", attrs: { label: { default: "•" }, listType: { default: "bullet" }, spread: { default: "true" } }, defining: !0, parseDOM: [ { tag: "li", getAttrs: (e) => { if (!(e instanceof HTMLElement)) throw w(e); return { label: e.dataset.label, listType: e.dataset["list-type"], spread: e.dataset.spread }; } } ], toDOM: (e) => [ "li", { ...t.get(ve.key)(e), "data-label": e.attrs.label, "data-list-type": e.attrs.listType, "data-spread": e.attrs.spread }, 0 ], parseMarkdown: { match: ({ type: e }) => e === "listItem", runner: (e, r, a) => { const o = r.label != null ? `${r.label}.` : "•", s = r.label != null ? "ordered" : "bullet", l = r.spread != null ? `${r.spread}` : "true"; e.openNode(a, { label: o, listType: s, spread: l }), e.next(r.children), e.closeNode(); } }, toMarkdown: { match: (e) => e.type.name === "list_item", runner: (e, r) => { e.openNode("listItem", void 0, { spread: r.attrs.spread === "true" }), e.next(r.content), e.closeNode(); } } })); n(M.node, { displayName: "NodeSchema<listItem>", group: "ListItem" }); n(M.ctx, { displayName: "NodeSchemaCtx<listItem>", group: "ListItem" }); const Oe = c("SinkListItem", (t) => () => Rt(M.type(t))); n(Oe, { displayName: "Command<sinkListItemCommand>", group: "ListItem" }); const Te = c("SplitListItem", (t) => () => rt(M.type(t))); n(Te, { displayName: "Command<liftListItemCommand>", group: "ListItem" }); const Ke = c("SplitListItem", (t) => () => vt(M.type(t))); n(Ke, { displayName: "Command<splitListItemCommand>", group: "ListItem" }); function $t(t) { return (e, r, a) => { const { selection: o } = e; if (!(o instanceof X)) return !1; const { empty: s, $from: l } = o; if (!s || l.parentOffset !== 0) return !1; const i = l.node(-1); return i.type !== M.type(t) || i.firstChild !== l.node() || l.node(-2).childCount > 1 ? !1 : rt(M.type(t))(e, r, a); }; } const De = c("LiftFirstListItem", (t) => () => $t(t)); n(De, { displayName: "Command<liftFirstListItemCommand>", group: "ListItem" }); const _e = f("listItemKeymap", { NextListItem: { shortcuts: "Enter", command: (t) => { const e = t.get(u); return () => e.call(Ke.key); } }, SinkListItem: { shortcuts: ["Tab", "Mod-]"], command: (t) => { const e = t.get(u); return () => e.call(Oe.key); } }, LiftListItem: { shortcuts: ["Shift-Tab", "Mod-["], command: (t) => { const e = t.get(u); return () => e.call(Te.key); } }, LiftFirstListItem: { shortcuts: ["Backspace", "Delete"], command: (t) => { const e = t.get(u); return () => e.call(De.key); } } }); n(_e.ctx, { displayName: "KeymapCtx<listItem>", group: "ListItem" }); n(_e.shortcuts, { displayName: "Keymap<listItem>", group: "ListItem" }); const It = Qe("text", () => ({ group: "inline", parseMarkdown: { match: ({ type: t }) => t === "text", runner: (t, e) => { t.addText(e.value); } }, toMarkdown: { match: (t) => t.type.name === "text", runner: (t, e) => { t.addNode("text", void 0, e.text); } } })); n(It, { displayName: "NodeSchema<text>", group: "Text" }); const Ee = N("html"); n(Ee, { displayName: "Attr<html>", group: "Html" }); const Pe = I("html", (t) => ({ atom: !0, group: "inline", inline: !0, attrs: { value: { default: "" } }, toDOM: (e) => { const r = document.createElement("span"), a = { ...t.get(Ee.key)(e), "data-value": e.attrs.value, "data-type": "html" }; return r.textContent = e.attrs.value, ["span", a, e.attrs.value]; }, parseDOM: [{ tag: 'span[data-type="html"]', getAttrs: (e) => ({ value: e.dataset.value ?? "" }) }], parseMarkdown: { match: ({ type: e }) => e === "html", runner: (e, r, a) => { e.addNode(a, { value: r.value }); } }, toMarkdown: { match: (e) => e.type.name === "html", runner: (e, r) => { e.addNode("html", void 0, r.attrs.value); } } })); n(Pe.node, { displayName: "NodeSchema<html>", group: "Html" }); n(Pe.ctx, { displayName: "NodeSchemaCtx<html>", group: "Html" }); const qt = [ mt, de, A, j, ce, H, Me, S, ye, q, fe, W, xe, F, Ce, v, Se, O, He, T, ve, M, Z, R, re, $, oe, x, ie, B, Ee, Pe, It ].flat(), Wt = [ ct, ft, Nt, ut, kt, pt ].flat(), Ft = [ nt, ot, lt, st ], Vt = [ me, ke, L, ue, Ne, be, ht, gt, yt, Be, we, Oe, Ke, Te, De, ee, se, ae, it, dt ], Ut = [ he, Ie, Le, ge, _e, Re, Ae, pe, te, le, ne ].flat(), $e = D("remarkAddOrderInList", () => () => (t) => { Y(t, "list", (e) => { if (e.ordered) { const r = e.start ?? 1; e.children.forEach((a, o) => { a.label = o + r; }); } }); }); n($e.plugin, { displayName: "Remark<remarkAddOrderInListPlugin>", group: "Remark" }); n($e.options, { displayName: "RemarkConfig<remarkAddOrderInListPlugin>", group: "Remark" }); const qe = D("remarkLineBreak", () => () => (t) => { const e = /[\t ]*(?:\r?\n|\r)/g; Y(t, "text", (r, a, o) => { if (!r.value || typeof r.value != "string") return; const s = []; let l = 0; e.lastIndex = 0; let i = e.exec(r.value); for (; i; ) { const m = i.index; l !== m && s.push({ type: "text", value: r.value.slice(l, m) }), s.push({ type: "break", data: { isInline: !0 } }), l = m + i[0].length, i = e.exec(r.value); } if (s.length > 0 && o && typeof a == "number") return l < r.value.length && s.push({ type: "text", value: r.value.slice(l) }), o.children.splice(a, 1, ...s), a + s.length; }); }); n(qe.plugin, { displayName: "Remark<remarkLineBreak>", group: "Remark" }); n(qe.options, { displayName: "RemarkConfig<remarkLineBreak>", group: "Remark" }); const We = D("remarkInlineLink", () => Kt); n(We.plugin, { displayName: "Remark<remarkInlineLinkPlugin>", group: "Remark" }); n(We.options, { displayName: "RemarkConfig<remarkInlineLinkPlugin>", group: "Remark" }); const Gt = (t) => !!t.children, jt = (t) => t.type === "html"; function zt(t, e) { return r(t, 0, null)[0]; function r(a, o, s) { if (Gt(a)) { const l = []; for (let i = 0, d = a.children.length; i < d; i++) { const m = a.children[i]; if (m) { const p = r(m, i, a); if (p) for (let k = 0, g = p.length; k < g; k++) { const C = p[k]; C && l.push(C); } } } a.children = l; } return e(a, o, s); } } const Fe = D("remarkHTMLTransformer", () => () => (t) => { zt(t, (e, r, a) => jt(e) ? ((a == null ? void 0 : a.type) === "root" && (e.children = [{ ...e }], delete e.value, e.type = "paragraph"), [e]) : [e]); }); n(Fe.plugin, { displayName: "Remark<remarkHtmlTransformer>", group: "Remark" }); n(Fe.options, { displayName: "RemarkConfig<remarkHtmlTransformer>", group: "Remark" }); const Ve = D("remarkMarker", () => () => (t, e) => { const r = (a) => e.value.charAt(a.position.start.offset); Y(t, (a) => ["strong", "emphasis"].includes(a.type), (a) => { a.marker = r(a); }); }); n(Ve.plugin, { displayName: "Remark<remarkMarker>", group: "Remark" }); n(Ve.options, { displayName: "RemarkConfig<remarkMarker>", group: "Remark" }); const Ct = _(() => { let t = !1; const e = new E("MILKDOWN_INLINE_NODES_CURSOR"), r = new P({ key: e, state: { init() { return !1; }, apply(a) { if (!a.selection.empty) return !1; const o = a.selection.$from, s = o.nodeBefore, l = o.nodeAfter; return !!(s && l && s.isInline && !s.isText && l.isInline && !l.isText); } }, props: { handleDOMEvents: { compositionend: (a, o) => t ? (t = !1, requestAnimationFrame(() => { if (r.getState(a.state)) { const l = a.state.selection.from; o.preventDefault(), a.dispatch(a.state.tr.insertText(o.data || "", l)); } }), !0) : !1, compositionstart: (a) => (r.getState(a.state) && (t = !0), !1), beforeinput: (a, o) => { if (r.getState(a.state) && o instanceof InputEvent && o.data && !t) { const l = a.state.selection.from; return o.preventDefault(), a.dispatch(a.state.tr.insertText(o.data || "", l)), !0; } return !1; } }, decorations(a) { if (r.getState(a)) { const l = a.selection.$from.pos, i = document.createElement("span"), d = ze.widget(l, i, { side: -1 }), m = document.createElement("span"), p = ze.widget(l, m); return setTimeout(() => { i.contentEditable = "true", m.contentEditable = "true"; }), Je.create(a.doc, [d, p]); } return Je.empty; } } }); return r; }); n(Ct, { displayName: "Prose<inlineNodesCursorPlugin>", group: "Prose" }); const Mt = _((t) => new P({ key: new E("MILKDOWN_HARDBREAK_MARKS"), appendTransaction: (e, r, a) => { if (!e.length) return; const [o] = e; if (!o) return; const [s] = o.steps; if (o.getMeta("hardbreak")) { if (!(s instanceof Ot)) return; const { from: d } = s; return a.tr.setNodeMarkup(d, S.type(t), void 0, []); } if (s instanceof Tt) { let d = a.tr; const { from: m, to: p } = s; return a.doc.nodesBetween(m, p, (k, g) => { k.type === S.type(t) && (d = d.setNodeMarkup(g, S.type(t), void 0, [])); }), d; } } })); n(Mt, { displayName: "Prose<hardbreakClearMarkPlugin>", group: "Prose" }); const Ue = Xe(["table", "code_block"], "hardbreakFilterNodes"); n(Ue, { displayName: "Ctx<hardbreakFilterNodes>", group: "Prose" }); const bt = _((t) => { const e = t.get(Ue.key); return new P({ key: new E("MILKDOWN_HARDBREAK_FILTER"), filterTransaction: (r, a) => { const o = r.getMeta("hardbreak"), [s] = r.steps; if (o && s) { const { from: l } = s, i = a.doc.resolve(l); let d = i.depth, m = !0; for (; d > 0; ) e.includes(i.node(d).type.name) && (m = !1), d--; return m; } return !0; } }); }); n(bt, { displayName: "Prose<hardbreakFilterPlugin>", group: "Prose" }); const Lt = _((t) => { const e = new E("MILKDOWN_HEADING_ID"), r = (a) => { if (a.composing || !a.editable) return; const o = t.get(j.key), s = a.state.tr.setMeta("addToHistory", !1); let l = !1; a.state.doc.descendants((i, d) => { if (i.type === H.type(t)) { if (i.textContent.trim().length === 0) return; const m = i.attrs, p = o(i); m.id !== p && (l = !0, s.setMeta(e, !0).setNodeMarkup(d, void 0, { ...m, id: p })); } }), l && a.dispatch(s); }; return new P({ key: e, view: (a) => (r(a), { update: (o) => { r(o); } }) }); }); n(Lt, { displayName: "Prose<syncHeadingIdPlugin>", group: "Prose" }); const xt = _((t) => { const e = (r) => { if (r.composing || !r.editable) return; const a = T.type(t), o = O.type(t), s = M.type(t), l = r.state, i = (p, k) => { let g = !1; const C = `${k + 1}.`; return p.label !== C && (p.label = C, g = !0), g; }; let d = l.tr, m = !1; l.doc.descendants((p, k, g, C) => { if (p.type === o) { const y = p.maybeChild(0); (y == null ? void 0 : y.type) === s && y.attrs.listType === "ordered" && (m = !0, d.setNodeMarkup(k, a, { spread: "true" }), p.descendants((b, Ge, Qt, St) => { if (b.type === s) { const je = { ...b.attrs }; i(je, St) && (d = d.setNodeMarkup(Ge, void 0, je)); } return !1; })); } else if (p.type === s && (g == null ? void 0 : g.type) === a) { const y = { ...p.attrs }; let b = !1; y.listType !== "ordered" && (y.listType = "ordered", b = !0), (g == null ? void 0 : g.maybeChild(0)) && (b = i(y, C)), b && (d = d.setNodeMarkup(k, void 0, y), m = !0); } }), m && r.dispatch(d.setMeta("addToHistory", !1)); }; return new P({ key: new E("MILKDOWN_KEEP_LIST_ORDER"), view: (r) => (e(r), { update: (a) => { e(a); } }) }); }); n(xt, { displayName: "Prose<syncListOrderPlugin>", group: "Prose" }); const Jt = [ Mt, Ue, bt, Ct, $e, We, qe, Fe, Ve, Lt, xt ].flat(), cr = [qt, Wt, Ft, Vt, Ut, Jt].flat(); export { ye as blockquoteAttr, he as blockquoteKeymap, q as blockquoteSchema, Se as bulletListAttr, Ae as bulletListKeymap, O as bulletListSchema, fe as codeBlockAttr, Ie as codeBlockKeymap, W as codeBlockSchema, Vt as commands, cr as commonmark, Ne as createCodeBlockCommand, ut as createCodeBlockInputRule, mt as docSchema, ue as downgradeHeadingCommand, Z as emphasisAttr, te as emphasisKeymap, R as emphasisSchema, nt as emphasisStarInputRule, ot as emphasisUnderscoreInputRule, Me as hardbreakAttr, Mt as hardbreakClearMarkPlugin, Ue as hardbreakFilterNodes, bt as hardbreakFilterPlugin, Le as hardbreakKeymap, S as hardbreakSchema, ce as headingAttr, j as headingIdGenerator, ge as headingKeymap, H as headingSchema, xe as hrAttr, F as hrSchema, Ee as htmlAttr, Pe as htmlSchema, Ce as imageAttr, v as imageSchema, oe as inlineCodeAttr, lt as inlineCodeInputRule, le as inlineCodeKeymap, x as inlineCodeSchema, Ct as inlineNodesCursorPlugin, Wt as inputRules, be as insertHardbreakCommand, ht as insertHrCommand, kt as insertHrInputRule, gt as insertImageCommand, Pt as insertImageInputRule, Ut as keymap, De as liftFirstListItemCommand, Te as liftListItemCommand, ie as linkAttr, B as linkSchema, ve as listItemAttr, _e as listItemKeymap, M as listItemSchema, Ft as markInputRules, He as orderedListAttr, Re as orderedListKeymap, T as orderedListSchema, de as paragraphAttr, pe as paragraphKeymap, A as paragraphSchema, Jt as plugins, $e as remarkAddOrderInListPlugin, Fe as remarkHtmlTransformer, We as remarkInlineLinkPlugin, qe as remarkLineBreak, Ve as remarkMarker, qt as schema, Oe as sinkListItemCommand, Ke as splitListItemCommand, re as strongAttr, st as strongInputRule, ne as strongKeymap, $ as strongSchema, Lt as syncHeadingIdPlugin, xt as syncListOrderPlugin, It as textSchema, ee as toggleEmphasisCommand, se as toggleInlineCodeCommand, it as toggleLinkCommand, ae as toggleStrongCommand, me as turnIntoTextCommand, Et as updateCodeBlockLanguageCommand, yt as updateImageCommand, dt as updateLinkCommand, ke as wrapInBlockquoteCommand, ct as wrapInBlockquoteInputRule, we as wrapInBulletListCommand, ft as wrapInBulletListInputRule, L as wrapInHeadingCommand, pt as wrapInHeadingInputRule, Be as wrapInOrderedListCommand, Nt as wrapInOrderedListInputRule }; //# sourceMappingURL=index.es.js.map