123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776 |
- 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<emphasis>",
- 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<emphasis>",
- group: "Emphasis"
- });
- n(R.ctx, {
- displayName: "MarkSchemaCtx<emphasis>",
- group: "Emphasis"
- });
- const ee = c("ToggleEmphasis", (t) => () => z(R.type(t)));
- n(ee, {
- displayName: "Command<toggleEmphasisCommand>",
- 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<emphasis>|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<emphasis>|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<emphasis>",
- group: "Emphasis"
- });
- n(te.shortcuts, {
- displayName: "Keymap<emphasis>",
- group: "Emphasis"
- });
- const re = V("strong");
- n(re, {
- displayName: "Attr<strong>",
- 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<strong>",
- group: "Strong"
- });
- n($.ctx, {
- displayName: "MarkSchemaCtx<strong>",
- group: "Strong"
- });
- const ae = c("ToggleStrong", (t) => () => z($.type(t)));
- n(ae, {
- displayName: "Command<toggleStrongCommand>",
- group: "Strong"
- });
- const st = h((t) => G(/(?:\*\*|__)([^*_]+)(?:\*\*|__)$/, $.type(t)));
- n(st, {
- displayName: "InputRule<strong>",
- 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<strong>",
- group: "Strong"
- });
- n(ne.shortcuts, {
- displayName: "Keymap<strong>",
- group: "Strong"
- });
- const oe = V("inlineCode");
- n(oe, {
- displayName: "Attr<inlineCode>",
- 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<inlineCode>",
- group: "InlineCode"
- });
- n(x.ctx, {
- displayName: "MarkSchemaCtx<inlineCode>",
- 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<toggleInlineCodeCommand>",
- group: "InlineCode"
- });
- const lt = h((t) => G(/(?:\`)([^\`]+)(?:\`)$/, x.type(t)));
- n(lt, {
- displayName: "InputRule<inlineCodeInputRule>",
- 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<inlineCode>",
- group: "InlineCode"
- });
- n(le.shortcuts, {
- displayName: "Keymap<inlineCode>",
- group: "InlineCode"
- });
- const ie = V("link");
- n(ie, {
- displayName: "Attr<link>",
- 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<link>",
- group: "Link"
- });
- const it = c("ToggleLink", (t) => (e = {}) => z(B.type(t), e));
- n(it, {
- displayName: "Command<toggleLinkCommand>",
- 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<updateLinkCommand>",
- 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<doc>",
- group: "Doc"
- });
- const de = N("paragraph");
- n(de, {
- displayName: "Attr<paragraph>",
- 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<paragraph>",
- group: "Paragraph"
- });
- n(A.ctx, {
- displayName: "NodeSchemaCtx<paragraph>",
- group: "Paragraph"
- });
- const me = c("TurnIntoText", (t) => () => K(A.type(t)));
- n(me, {
- displayName: "Command<turnIntoTextCommand>",
- 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<paragraph>",
- group: "Paragraph"
- });
- n(pe.shortcuts, {
- displayName: "Keymap<paragraph>",
- 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<HeadingIdGenerator>",
- group: "Heading"
- });
- const ce = N("heading");
- n(ce, {
- displayName: "Attr<heading>",
- 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<heading>",
- group: "Heading"
- });
- n(H.ctx, {
- displayName: "NodeSchemaCtx<heading>",
- group: "Heading"
- });
- const pt = h((t) => Ze(/^(?<hashes>#+)\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<wrapInHeadingInputRule>",
- 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<wrapInHeadingCommand>",
- 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<downgradeHeadingCommand>",
- 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<heading>",
- group: "Heading"
- });
- n(ge.shortcuts, {
- displayName: "Keymap<heading>",
- group: "Heading"
- });
- const ye = N("blockquote");
- n(ye, {
- displayName: "Attr<blockquote>",
- 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<blockquote>",
- group: "Blockquote"
- });
- n(q.ctx, {
- displayName: "NodeSchemaCtx<blockquote>",
- group: "Blockquote"
- });
- const ct = h((t) => Q(/^\s*>\s$/, q.type(t)));
- n(ct, {
- displayName: "InputRule<wrapInBlockquoteInputRule>",
- group: "Blockquote"
- });
- const ke = c("WrapInBlockquote", (t) => () => J(q.type(t)));
- n(ke, {
- displayName: "Command<wrapInBlockquoteCommand>",
- 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<blockquote>",
- group: "Blockquote"
- });
- n(he.shortcuts, {
- displayName: "Keymap<blockquote>",
- group: "Blockquote"
- });
- const fe = N("codeBlock", () => ({
- pre: {},
- code: {}
- }));
- n(fe, {
- displayName: "Attr<codeBlock>",
- 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<codeBlock>",
- group: "CodeBlock"
- });
- n(W.ctx, {
- displayName: "NodeSchemaCtx<codeBlock>",
- group: "CodeBlock"
- });
- const ut = h((t) => Ze(/^```(?<language>[a-z]*)?[\s\n]$/, W.type(t), (e) => {
- var r;
- return {
- language: ((r = e.groups) == null ? void 0 : r.language) ?? ""
- };
- }));
- n(ut, {
- displayName: "InputRule<createCodeBlockInputRule>",
- group: "CodeBlock"
- });
- const Ne = c("CreateCodeBlock", (t) => (e = "") => K(W.type(t), { language: e }));
- n(Ne, {
- displayName: "Command<createCodeBlockCommand>",
- 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<updateCodeBlockLanguageCommand>",
- 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<codeBlock>",
- group: "CodeBlock"
- });
- n(Ie.shortcuts, {
- displayName: "Keymap<codeBlock>",
- group: "CodeBlock"
- });
- const Ce = N("image");
- n(Ce, {
- displayName: "Attr<image>",
- 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<image>",
- group: "Image"
- });
- n(v.ctx, {
- displayName: "NodeSchemaCtx<image>",
- 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<insertImageCommand>",
- 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<updateImageCommand>",
- group: "Image"
- });
- const Pt = h((t) => new et(
- /!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/,
- (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
|