index.es.js 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776
  1. 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";
  2. import { remarkStringifyOptionsCtx as Ye, commandsCtx as u, editorViewCtx as wt } from "@milkdown/core";
  3. import { toggleMark as z, setBlockType as K, wrapIn as J } from "@milkdown/prose/commands";
  4. import { Fragment as At } from "@milkdown/prose/model";
  5. import { expectDomTypeError as w } from "@milkdown/exception";
  6. import { textblockTypeInputRule as Ze, wrappingInputRule as Q, InputRule as et } from "@milkdown/prose/inputrules";
  7. import Ht from "@sindresorhus/slugify";
  8. import { TextSelection as X, Selection as tt, PluginKey as E, Plugin as P } from "@milkdown/prose/state";
  9. import { markRule as G, findSelectedNodeOfType as Bt } from "@milkdown/prose";
  10. import { sinkListItem as Rt, liftListItem as rt, splitListItem as vt } from "@milkdown/prose/schema-list";
  11. import { ReplaceStep as Ot, AddMarkStep as Tt } from "@milkdown/prose/transform";
  12. import { Decoration as ze, DecorationSet as Je } from "@milkdown/prose/view";
  13. import { visit as Y } from "unist-util-visit";
  14. import Kt from "remark-inline-links";
  15. function at(t, e) {
  16. var o;
  17. if (!(e.childCount >= 1 && ((o = e.lastChild) == null ? void 0 : o.type.name) === "hardbreak")) {
  18. t.next(e.content);
  19. return;
  20. }
  21. const a = [];
  22. e.content.forEach((s, l, i) => {
  23. i !== e.childCount - 1 && a.push(s);
  24. }), t.next(At.fromArray(a));
  25. }
  26. function n(t, e) {
  27. return Object.assign(t, {
  28. meta: {
  29. package: "@milkdown/preset-commonmark",
  30. ...e
  31. }
  32. }), t;
  33. }
  34. const Z = V("emphasis");
  35. n(Z, {
  36. displayName: "Attr<emphasis>",
  37. group: "Emphasis"
  38. });
  39. const R = U("emphasis", (t) => ({
  40. attrs: {
  41. marker: {
  42. default: t.get(Ye).emphasis || "*"
  43. }
  44. },
  45. parseDOM: [
  46. { tag: "i" },
  47. { tag: "em" },
  48. { style: "font-style", getAttrs: (e) => e === "italic" }
  49. ],
  50. toDOM: (e) => ["em", t.get(Z.key)(e)],
  51. parseMarkdown: {
  52. match: (e) => e.type === "emphasis",
  53. runner: (e, r, a) => {
  54. e.openMark(a, { marker: r.marker }), e.next(r.children), e.closeMark(a);
  55. }
  56. },
  57. toMarkdown: {
  58. match: (e) => e.type.name === "emphasis",
  59. runner: (e, r) => {
  60. e.withMark(r, "emphasis", void 0, {
  61. marker: r.attrs.marker
  62. });
  63. }
  64. }
  65. }));
  66. n(R.mark, {
  67. displayName: "MarkSchema<emphasis>",
  68. group: "Emphasis"
  69. });
  70. n(R.ctx, {
  71. displayName: "MarkSchemaCtx<emphasis>",
  72. group: "Emphasis"
  73. });
  74. const ee = c("ToggleEmphasis", (t) => () => z(R.type(t)));
  75. n(ee, {
  76. displayName: "Command<toggleEmphasisCommand>",
  77. group: "Emphasis"
  78. });
  79. const nt = h((t) => G(/(?:^|[^*])\*([^*]+)\*$/, R.type(t), {
  80. updateCaptured: ({ fullMatch: e, start: r }) => e.startsWith("*") ? {} : { fullMatch: e.slice(1), start: r + 1 }
  81. }));
  82. n(nt, {
  83. displayName: "InputRule<emphasis>|Star",
  84. group: "Emphasis"
  85. });
  86. const ot = h((t) => G(/(?:^|[^_])_([^_]+)_$/, R.type(t), {
  87. updateCaptured: ({ fullMatch: e, start: r }) => e.startsWith("_") ? {} : { fullMatch: e.slice(1), start: r + 1 }
  88. }));
  89. n(ot, {
  90. displayName: "InputRule<emphasis>|Underscore",
  91. group: "Emphasis"
  92. });
  93. const te = f("emphasisKeymap", {
  94. ToggleEmphasis: {
  95. shortcuts: "Mod-i",
  96. command: (t) => {
  97. const e = t.get(u);
  98. return () => e.call(ee.key);
  99. }
  100. }
  101. });
  102. n(te.ctx, {
  103. displayName: "KeymapCtx<emphasis>",
  104. group: "Emphasis"
  105. });
  106. n(te.shortcuts, {
  107. displayName: "Keymap<emphasis>",
  108. group: "Emphasis"
  109. });
  110. const re = V("strong");
  111. n(re, {
  112. displayName: "Attr<strong>",
  113. group: "Strong"
  114. });
  115. const $ = U("strong", (t) => ({
  116. attrs: {
  117. marker: {
  118. default: t.get(Ye).strong || "*"
  119. }
  120. },
  121. parseDOM: [
  122. { tag: "b" },
  123. { tag: "strong" },
  124. { style: "font-style", getAttrs: (e) => e === "bold" }
  125. ],
  126. toDOM: (e) => ["strong", t.get(re.key)(e)],
  127. parseMarkdown: {
  128. match: (e) => e.type === "strong",
  129. runner: (e, r, a) => {
  130. e.openMark(a, { marker: r.marker }), e.next(r.children), e.closeMark(a);
  131. }
  132. },
  133. toMarkdown: {
  134. match: (e) => e.type.name === "strong",
  135. runner: (e, r) => {
  136. e.withMark(r, "strong", void 0, {
  137. marker: r.attrs.marker
  138. });
  139. }
  140. }
  141. }));
  142. n($.mark, {
  143. displayName: "MarkSchema<strong>",
  144. group: "Strong"
  145. });
  146. n($.ctx, {
  147. displayName: "MarkSchemaCtx<strong>",
  148. group: "Strong"
  149. });
  150. const ae = c("ToggleStrong", (t) => () => z($.type(t)));
  151. n(ae, {
  152. displayName: "Command<toggleStrongCommand>",
  153. group: "Strong"
  154. });
  155. const st = h((t) => G(/(?:\*\*|__)([^*_]+)(?:\*\*|__)$/, $.type(t)));
  156. n(st, {
  157. displayName: "InputRule<strong>",
  158. group: "Strong"
  159. });
  160. const ne = f("strongKeymap", {
  161. ToggleBold: {
  162. shortcuts: ["Mod-b"],
  163. command: (t) => {
  164. const e = t.get(u);
  165. return () => e.call(ae.key);
  166. }
  167. }
  168. });
  169. n(ne.ctx, {
  170. displayName: "KeymapCtx<strong>",
  171. group: "Strong"
  172. });
  173. n(ne.shortcuts, {
  174. displayName: "Keymap<strong>",
  175. group: "Strong"
  176. });
  177. const oe = V("inlineCode");
  178. n(oe, {
  179. displayName: "Attr<inlineCode>",
  180. group: "InlineCode"
  181. });
  182. const x = U("inlineCode", (t) => ({
  183. priority: 100,
  184. code: !0,
  185. inclusive: !1,
  186. parseDOM: [{ tag: "code" }],
  187. toDOM: (e) => ["code", t.get(oe.key)(e)],
  188. parseMarkdown: {
  189. match: (e) => e.type === "inlineCode",
  190. runner: (e, r, a) => {
  191. e.openMark(a), e.addText(r.value), e.closeMark(a);
  192. }
  193. },
  194. toMarkdown: {
  195. match: (e) => e.type.name === "inlineCode",
  196. runner: (e, r, a) => {
  197. e.withMark(r, "inlineCode", a.text || "");
  198. }
  199. }
  200. }));
  201. n(x.mark, {
  202. displayName: "MarkSchema<inlineCode>",
  203. group: "InlineCode"
  204. });
  205. n(x.ctx, {
  206. displayName: "MarkSchemaCtx<inlineCode>",
  207. group: "InlineCode"
  208. });
  209. const se = c("ToggleInlineCode", (t) => () => (e, r) => {
  210. const { selection: a, tr: o } = e;
  211. if (a.empty)
  212. return !1;
  213. const { from: s, to: l } = a;
  214. 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) => {
  215. o.removeMark(s, l, m);
  216. }), r == null || r(o.addMark(s, l, x.type(t).create())), !0);
  217. });
  218. n(se, {
  219. displayName: "Command<toggleInlineCodeCommand>",
  220. group: "InlineCode"
  221. });
  222. const lt = h((t) => G(/(?:\`)([^\`]+)(?:\`)$/, x.type(t)));
  223. n(lt, {
  224. displayName: "InputRule<inlineCodeInputRule>",
  225. group: "InlineCode"
  226. });
  227. const le = f("inlineCodeKeymap", {
  228. ToggleInlineCode: {
  229. shortcuts: "Mod-e",
  230. command: (t) => {
  231. const e = t.get(u);
  232. return () => e.call(se.key);
  233. }
  234. }
  235. });
  236. n(le.ctx, {
  237. displayName: "KeymapCtx<inlineCode>",
  238. group: "InlineCode"
  239. });
  240. n(le.shortcuts, {
  241. displayName: "Keymap<inlineCode>",
  242. group: "InlineCode"
  243. });
  244. const ie = V("link");
  245. n(ie, {
  246. displayName: "Attr<link>",
  247. group: "Link"
  248. });
  249. const B = U("link", (t) => ({
  250. attrs: {
  251. href: {},
  252. title: { default: null }
  253. },
  254. parseDOM: [
  255. {
  256. tag: "a[href]",
  257. getAttrs: (e) => {
  258. if (!(e instanceof HTMLElement))
  259. throw w(e);
  260. return { href: e.getAttribute("href"), title: e.getAttribute("title") };
  261. }
  262. }
  263. ],
  264. toDOM: (e) => ["a", { ...t.get(ie.key)(e), ...e.attrs }],
  265. parseMarkdown: {
  266. match: (e) => e.type === "link",
  267. runner: (e, r, a) => {
  268. const o = r.url, s = r.title;
  269. e.openMark(a, { href: o, title: s }), e.next(r.children), e.closeMark(a);
  270. }
  271. },
  272. toMarkdown: {
  273. match: (e) => e.type.name === "link",
  274. runner: (e, r) => {
  275. e.withMark(r, "link", void 0, {
  276. title: r.attrs.title,
  277. url: r.attrs.href
  278. });
  279. }
  280. }
  281. }));
  282. n(B.mark, {
  283. displayName: "MarkSchema<link>",
  284. group: "Link"
  285. });
  286. const it = c("ToggleLink", (t) => (e = {}) => z(B.type(t), e));
  287. n(it, {
  288. displayName: "Command<toggleLinkCommand>",
  289. group: "Link"
  290. });
  291. const dt = c("UpdateLink", (t) => (e = {}) => (r, a) => {
  292. if (!a)
  293. return !1;
  294. let o, s = -1;
  295. const { selection: l } = r, { from: i, to: d } = l;
  296. if (r.doc.nodesBetween(i, i === d ? d + 1 : d, (y, b) => {
  297. if (B.type(t).isInSet(y.marks))
  298. return o = y, s = b, !1;
  299. }), !o)
  300. return !1;
  301. const m = o.marks.find(({ type: y }) => y === B.type(t));
  302. if (!m)
  303. return !1;
  304. const p = s, k = s + o.nodeSize, { tr: g } = r, C = B.type(t).create({ ...m.attrs, ...e });
  305. return C ? (a(
  306. g.removeMark(p, k, m).addMark(p, k, C).setSelection(new X(g.selection.$anchor)).scrollIntoView()
  307. ), !0) : !1;
  308. });
  309. n(dt, {
  310. displayName: "Command<updateLinkCommand>",
  311. group: "Link"
  312. });
  313. const mt = Qe("doc", () => ({
  314. content: "block+",
  315. parseMarkdown: {
  316. match: ({ type: t }) => t === "root",
  317. runner: (t, e, r) => {
  318. t.injectRoot(e, r);
  319. }
  320. },
  321. toMarkdown: {
  322. match: (t) => t.type.name === "doc",
  323. runner: (t, e) => {
  324. t.openNode("root"), t.next(e.content);
  325. }
  326. }
  327. }));
  328. n(mt, {
  329. displayName: "NodeSchema<doc>",
  330. group: "Doc"
  331. });
  332. const de = N("paragraph");
  333. n(de, {
  334. displayName: "Attr<paragraph>",
  335. group: "Paragraph"
  336. });
  337. const A = I("paragraph", (t) => ({
  338. content: "inline*",
  339. group: "block",
  340. parseDOM: [{ tag: "p" }],
  341. toDOM: (e) => ["p", t.get(de.key)(e), 0],
  342. parseMarkdown: {
  343. match: (e) => e.type === "paragraph",
  344. runner: (e, r, a) => {
  345. e.openNode(a), r.children ? e.next(r.children) : e.addText(r.value || ""), e.closeNode();
  346. }
  347. },
  348. toMarkdown: {
  349. match: (e) => e.type.name === "paragraph",
  350. runner: (e, r) => {
  351. e.openNode("paragraph"), at(e, r), e.closeNode();
  352. }
  353. }
  354. }));
  355. n(A.node, {
  356. displayName: "NodeSchema<paragraph>",
  357. group: "Paragraph"
  358. });
  359. n(A.ctx, {
  360. displayName: "NodeSchemaCtx<paragraph>",
  361. group: "Paragraph"
  362. });
  363. const me = c("TurnIntoText", (t) => () => K(A.type(t)));
  364. n(me, {
  365. displayName: "Command<turnIntoTextCommand>",
  366. group: "Paragraph"
  367. });
  368. const pe = f("paragraphKeymap", {
  369. TurnIntoText: {
  370. shortcuts: "Mod-Alt-0",
  371. command: (t) => {
  372. const e = t.get(u);
  373. return () => e.call(me.key);
  374. }
  375. }
  376. });
  377. n(pe.ctx, {
  378. displayName: "KeymapCtx<paragraph>",
  379. group: "Paragraph"
  380. });
  381. n(pe.shortcuts, {
  382. displayName: "Keymap<paragraph>",
  383. group: "Paragraph"
  384. });
  385. const Dt = Array(6).fill(0).map((t, e) => e + 1);
  386. function _t(t) {
  387. return Ht(t.textContent);
  388. }
  389. const j = Xe(_t, "headingIdGenerator");
  390. n(j, {
  391. displayName: "Ctx<HeadingIdGenerator>",
  392. group: "Heading"
  393. });
  394. const ce = N("heading");
  395. n(ce, {
  396. displayName: "Attr<heading>",
  397. group: "Heading"
  398. });
  399. const H = I("heading", (t) => {
  400. const e = t.get(j.key);
  401. return {
  402. content: "inline*",
  403. group: "block",
  404. defining: !0,
  405. attrs: {
  406. id: {
  407. default: ""
  408. },
  409. level: {
  410. default: 1
  411. }
  412. },
  413. parseDOM: Dt.map((r) => ({
  414. tag: `h${r}`,
  415. getAttrs: (a) => {
  416. if (!(a instanceof HTMLElement))
  417. throw w(a);
  418. return { level: r, id: a.id };
  419. }
  420. })),
  421. toDOM: (r) => [
  422. `h${r.attrs.level}`,
  423. {
  424. ...t.get(ce.key)(r),
  425. id: r.attrs.id || e(r)
  426. },
  427. 0
  428. ],
  429. parseMarkdown: {
  430. match: ({ type: r }) => r === "heading",
  431. runner: (r, a, o) => {
  432. const s = a.depth;
  433. r.openNode(o, { level: s }), r.next(a.children), r.closeNode();
  434. }
  435. },
  436. toMarkdown: {
  437. match: (r) => r.type.name === "heading",
  438. runner: (r, a) => {
  439. r.openNode("heading", void 0, { depth: a.attrs.level }), at(r, a), r.closeNode();
  440. }
  441. }
  442. };
  443. });
  444. n(H.node, {
  445. displayName: "NodeSchema<heading>",
  446. group: "Heading"
  447. });
  448. n(H.ctx, {
  449. displayName: "NodeSchemaCtx<heading>",
  450. group: "Heading"
  451. });
  452. const pt = h((t) => Ze(/^(?<hashes>#+)\s$/, H.type(t), (e) => {
  453. var l, i;
  454. 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();
  455. if (s.type.name === "heading") {
  456. let d = Number(s.attrs.level) + Number(r);
  457. return d > 6 && (d = 6), { level: d };
  458. }
  459. return { level: r };
  460. }));
  461. n(pt, {
  462. displayName: "InputRule<wrapInHeadingInputRule>",
  463. group: "Heading"
  464. });
  465. const L = c("WrapInHeading", (t) => (e) => (e ?? (e = 1), e < 1 ? K(A.type(t)) : K(H.type(t), { level: e })));
  466. n(L, {
  467. displayName: "Command<wrapInHeadingCommand>",
  468. group: "Heading"
  469. });
  470. const ue = c("DowngradeHeading", (t) => () => (e, r, a) => {
  471. const { $from: o } = e.selection, s = o.node();
  472. if (s.type !== H.type(t) || !e.selection.empty || o.parentOffset !== 0)
  473. return !1;
  474. const l = s.attrs.level - 1;
  475. return l ? (r == null || r(
  476. e.tr.setNodeMarkup(e.selection.$from.before(), void 0, {
  477. ...s.attrs,
  478. level: l
  479. })
  480. ), !0) : K(A.type(t))(e, r, a);
  481. });
  482. n(ue, {
  483. displayName: "Command<downgradeHeadingCommand>",
  484. group: "Heading"
  485. });
  486. const ge = f("headingKeymap", {
  487. TurnIntoH1: {
  488. shortcuts: "Mod-Alt-1",
  489. command: (t) => {
  490. const e = t.get(u);
  491. return () => e.call(L.key, 1);
  492. }
  493. },
  494. TurnIntoH2: {
  495. shortcuts: "Mod-Alt-2",
  496. command: (t) => {
  497. const e = t.get(u);
  498. return () => e.call(L.key, 2);
  499. }
  500. },
  501. TurnIntoH3: {
  502. shortcuts: "Mod-Alt-3",
  503. command: (t) => {
  504. const e = t.get(u);
  505. return () => e.call(L.key, 3);
  506. }
  507. },
  508. TurnIntoH4: {
  509. shortcuts: "Mod-Alt-4",
  510. command: (t) => {
  511. const e = t.get(u);
  512. return () => e.call(L.key, 4);
  513. }
  514. },
  515. TurnIntoH5: {
  516. shortcuts: "Mod-Alt-5",
  517. command: (t) => {
  518. const e = t.get(u);
  519. return () => e.call(L.key, 5);
  520. }
  521. },
  522. TurnIntoH6: {
  523. shortcuts: "Mod-Alt-6",
  524. command: (t) => {
  525. const e = t.get(u);
  526. return () => e.call(L.key, 6);
  527. }
  528. },
  529. DowngradeHeading: {
  530. shortcuts: ["Delete", "Backspace"],
  531. command: (t) => {
  532. const e = t.get(u);
  533. return () => e.call(ue.key);
  534. }
  535. }
  536. });
  537. n(ge.ctx, {
  538. displayName: "KeymapCtx<heading>",
  539. group: "Heading"
  540. });
  541. n(ge.shortcuts, {
  542. displayName: "Keymap<heading>",
  543. group: "Heading"
  544. });
  545. const ye = N("blockquote");
  546. n(ye, {
  547. displayName: "Attr<blockquote>",
  548. group: "Blockquote"
  549. });
  550. const q = I("blockquote", (t) => ({
  551. content: "block+",
  552. group: "block",
  553. defining: !0,
  554. parseDOM: [{ tag: "blockquote" }],
  555. toDOM: (e) => ["blockquote", t.get(ye.key)(e), 0],
  556. parseMarkdown: {
  557. match: ({ type: e }) => e === "blockquote",
  558. runner: (e, r, a) => {
  559. e.openNode(a).next(r.children).closeNode();
  560. }
  561. },
  562. toMarkdown: {
  563. match: (e) => e.type.name === "blockquote",
  564. runner: (e, r) => {
  565. e.openNode("blockquote").next(r.content).closeNode();
  566. }
  567. }
  568. }));
  569. n(q.node, {
  570. displayName: "NodeSchema<blockquote>",
  571. group: "Blockquote"
  572. });
  573. n(q.ctx, {
  574. displayName: "NodeSchemaCtx<blockquote>",
  575. group: "Blockquote"
  576. });
  577. const ct = h((t) => Q(/^\s*>\s$/, q.type(t)));
  578. n(ct, {
  579. displayName: "InputRule<wrapInBlockquoteInputRule>",
  580. group: "Blockquote"
  581. });
  582. const ke = c("WrapInBlockquote", (t) => () => J(q.type(t)));
  583. n(ke, {
  584. displayName: "Command<wrapInBlockquoteCommand>",
  585. group: "Blockquote"
  586. });
  587. const he = f("blockquoteKeymap", {
  588. WrapInBlockquote: {
  589. shortcuts: "Mod-Shift-b",
  590. command: (t) => {
  591. const e = t.get(u);
  592. return () => e.call(ke.key);
  593. }
  594. }
  595. });
  596. n(he.ctx, {
  597. displayName: "KeymapCtx<blockquote>",
  598. group: "Blockquote"
  599. });
  600. n(he.shortcuts, {
  601. displayName: "Keymap<blockquote>",
  602. group: "Blockquote"
  603. });
  604. const fe = N("codeBlock", () => ({
  605. pre: {},
  606. code: {}
  607. }));
  608. n(fe, {
  609. displayName: "Attr<codeBlock>",
  610. group: "CodeBlock"
  611. });
  612. const W = I("code_block", (t) => ({
  613. content: "text*",
  614. group: "block",
  615. marks: "",
  616. defining: !0,
  617. code: !0,
  618. attrs: {
  619. language: {
  620. default: ""
  621. }
  622. },
  623. parseDOM: [
  624. {
  625. tag: "pre",
  626. preserveWhitespace: "full",
  627. getAttrs: (e) => {
  628. if (!(e instanceof HTMLElement))
  629. throw w(e);
  630. return { language: e.dataset.language };
  631. }
  632. }
  633. ],
  634. toDOM: (e) => {
  635. const r = t.get(fe.key)(e);
  636. return [
  637. "pre",
  638. {
  639. ...r.pre,
  640. "data-language": e.attrs.language
  641. },
  642. ["code", r.code, 0]
  643. ];
  644. },
  645. parseMarkdown: {
  646. match: ({ type: e }) => e === "code",
  647. runner: (e, r, a) => {
  648. const o = r.lang, s = r.value;
  649. e.openNode(a, { language: o }), s && e.addText(s), e.closeNode();
  650. }
  651. },
  652. toMarkdown: {
  653. match: (e) => e.type.name === "code_block",
  654. runner: (e, r) => {
  655. var a;
  656. e.addNode("code", void 0, ((a = r.content.firstChild) == null ? void 0 : a.text) || "", {
  657. lang: r.attrs.language
  658. });
  659. }
  660. }
  661. }));
  662. n(W.node, {
  663. displayName: "NodeSchema<codeBlock>",
  664. group: "CodeBlock"
  665. });
  666. n(W.ctx, {
  667. displayName: "NodeSchemaCtx<codeBlock>",
  668. group: "CodeBlock"
  669. });
  670. const ut = h((t) => Ze(/^```(?<language>[a-z]*)?[\s\n]$/, W.type(t), (e) => {
  671. var r;
  672. return {
  673. language: ((r = e.groups) == null ? void 0 : r.language) ?? ""
  674. };
  675. }));
  676. n(ut, {
  677. displayName: "InputRule<createCodeBlockInputRule>",
  678. group: "CodeBlock"
  679. });
  680. const Ne = c("CreateCodeBlock", (t) => (e = "") => K(W.type(t), { language: e }));
  681. n(Ne, {
  682. displayName: "Command<createCodeBlockCommand>",
  683. group: "CodeBlock"
  684. });
  685. 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);
  686. n(Et, {
  687. displayName: "Command<updateCodeBlockLanguageCommand>",
  688. group: "CodeBlock"
  689. });
  690. const Ie = f("codeBlockKeymap", {
  691. CreateCodeBlock: {
  692. shortcuts: "Mod-Alt-c",
  693. command: (t) => {
  694. const e = t.get(u);
  695. return () => e.call(Ne.key);
  696. }
  697. }
  698. });
  699. n(Ie.ctx, {
  700. displayName: "KeymapCtx<codeBlock>",
  701. group: "CodeBlock"
  702. });
  703. n(Ie.shortcuts, {
  704. displayName: "Keymap<codeBlock>",
  705. group: "CodeBlock"
  706. });
  707. const Ce = N("image");
  708. n(Ce, {
  709. displayName: "Attr<image>",
  710. group: "Image"
  711. });
  712. const v = I("image", (t) => ({
  713. inline: !0,
  714. group: "inline",
  715. selectable: !0,
  716. draggable: !0,
  717. marks: "",
  718. atom: !0,
  719. defining: !0,
  720. isolating: !0,
  721. attrs: {
  722. src: { default: "" },
  723. alt: { default: "" },
  724. title: { default: "" }
  725. },
  726. parseDOM: [
  727. {
  728. tag: "img[src]",
  729. getAttrs: (e) => {
  730. if (!(e instanceof HTMLElement))
  731. throw w(e);
  732. return {
  733. src: e.getAttribute("src") || "",
  734. alt: e.getAttribute("alt") || "",
  735. title: e.getAttribute("title") || e.getAttribute("alt") || ""
  736. };
  737. }
  738. }
  739. ],
  740. toDOM: (e) => ["img", { ...t.get(Ce.key)(e), ...e.attrs }],
  741. parseMarkdown: {
  742. match: ({ type: e }) => e === "image",
  743. runner: (e, r, a) => {
  744. const o = r.url, s = r.alt, l = r.title;
  745. e.addNode(a, {
  746. src: o,
  747. alt: s,
  748. title: l
  749. });
  750. }
  751. },
  752. toMarkdown: {
  753. match: (e) => e.type.name === "image",
  754. runner: (e, r) => {
  755. e.addNode("image", void 0, void 0, {
  756. title: r.attrs.title,
  757. url: r.attrs.src,
  758. alt: r.attrs.alt
  759. });
  760. }
  761. }
  762. }));
  763. n(v.node, {
  764. displayName: "NodeSchema<image>",
  765. group: "Image"
  766. });
  767. n(v.ctx, {
  768. displayName: "NodeSchemaCtx<image>",
  769. group: "Image"
  770. });
  771. const gt = c("InsertImage", (t) => (e = {}) => (r, a) => {
  772. if (!a)
  773. return !0;
  774. const { src: o = "", alt: s = "", title: l = "" } = e, i = v.type(t).create({ src: o, alt: s, title: l });
  775. return i && a(r.tr.replaceSelectionWith(i).scrollIntoView()), !0;
  776. });
  777. n(gt, {
  778. displayName: "Command<insertImageCommand>",
  779. group: "Image"
  780. });
  781. const yt = c("UpdateImage", (t) => (e = {}) => (r, a) => {
  782. const o = Bt(r.selection, v.type(t));
  783. if (!o)
  784. return !1;
  785. const { node: s, pos: l } = o, i = { ...s.attrs }, { src: d, alt: m, title: p } = e;
  786. 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;
  787. });
  788. n(yt, {
  789. displayName: "Command<updateImageCommand>",
  790. group: "Image"
  791. });
  792. const Pt = h((t) => new et(
  793. /!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/,
  794. (e, r, a, o) => {
  795. const [s, l, i = "", d] = r;
  796. return s ? e.tr.replaceWith(a, o, v.type(t).create({ src: i, alt: l, title: d })) : null;
  797. }
  798. ));
  799. n(Pt, {
  800. displayName: "InputRule<insertImageInputRule>",
  801. group: "Image"
  802. });
  803. const Me = N("hardbreak", (t) => ({
  804. "data-is-inline": t.attrs.isInline
  805. }));
  806. n(Me, {
  807. displayName: "Attr<hardbreak>",
  808. group: "Hardbreak"
  809. });
  810. const S = I("hardbreak", (t) => ({
  811. inline: !0,
  812. group: "inline",
  813. attrs: {
  814. isInline: {
  815. default: !1
  816. }
  817. },
  818. selectable: !1,
  819. parseDOM: [{ tag: "br" }],
  820. toDOM: (e) => ["br", t.get(Me.key)(e)],
  821. parseMarkdown: {
  822. match: ({ type: e }) => e === "break",
  823. runner: (e, r, a) => {
  824. var o;
  825. e.addNode(a, { isInline: !!((o = r.data) != null && o.isInline) });
  826. }
  827. },
  828. leafText: () => `
  829. `,
  830. toMarkdown: {
  831. match: (e) => e.type.name === "hardbreak",
  832. runner: (e, r) => {
  833. r.attrs.isInline ? e.addNode("text", void 0, `
  834. `) : e.addNode("break");
  835. }
  836. }
  837. }));
  838. n(S.node, {
  839. displayName: "NodeSchema<hardbreak>",
  840. group: "Hardbreak"
  841. });
  842. n(S.ctx, {
  843. displayName: "NodeSchemaCtx<hardbreak>",
  844. group: "Hardbreak"
  845. });
  846. const be = c("InsertHardbreak", (t) => () => (e, r) => {
  847. var s;
  848. const { selection: a, tr: o } = e;
  849. if (!(a instanceof X))
  850. return !1;
  851. if (a.empty) {
  852. const l = a.$from.node();
  853. if (l.childCount > 0 && ((s = l.lastChild) == null ? void 0 : s.type.name) === "hardbreak")
  854. return r == null || r(
  855. o.replaceRangeWith(a.to - 1, a.to, e.schema.node("paragraph")).setSelection(tt.near(o.doc.resolve(a.to))).scrollIntoView()
  856. ), !0;
  857. }
  858. return r == null || r(o.setMeta("hardbreak", !0).replaceSelectionWith(S.type(t).create()).scrollIntoView()), !0;
  859. });
  860. n(be, {
  861. displayName: "Command<insertHardbreakCommand>",
  862. group: "Hardbreak"
  863. });
  864. const Le = f("hardbreakKeymap", {
  865. InsertHardbreak: {
  866. shortcuts: "Shift-Enter",
  867. command: (t) => {
  868. const e = t.get(u);
  869. return () => e.call(be.key);
  870. }
  871. }
  872. });
  873. n(Le.ctx, {
  874. displayName: "KeymapCtx<hardbreak>",
  875. group: "Hardbreak"
  876. });
  877. n(Le.shortcuts, {
  878. displayName: "Keymap<hardbreak>",
  879. group: "Hardbreak"
  880. });
  881. const xe = N("hr");
  882. n(xe, {
  883. displayName: "Attr<hr>",
  884. group: "Hr"
  885. });
  886. const F = I("hr", (t) => ({
  887. group: "block",
  888. parseDOM: [{ tag: "hr" }],
  889. toDOM: (e) => ["hr", t.get(xe.key)(e)],
  890. parseMarkdown: {
  891. match: ({ type: e }) => e === "thematicBreak",
  892. runner: (e, r, a) => {
  893. e.addNode(a);
  894. }
  895. },
  896. toMarkdown: {
  897. match: (e) => e.type.name === "hr",
  898. runner: (e) => {
  899. e.addNode("thematicBreak");
  900. }
  901. }
  902. }));
  903. n(F.node, {
  904. displayName: "NodeSchema<hr>",
  905. group: "Hr"
  906. });
  907. n(F.ctx, {
  908. displayName: "NodeSchemaCtx<hr>",
  909. group: "Hr"
  910. });
  911. const kt = h((t) => new et(
  912. /^(?:---|___\s|\*\*\*\s)$/,
  913. (e, r, a, o) => {
  914. const { tr: s } = e;
  915. return r[0] && s.replaceWith(a - 1, o, F.type(t).create()), s;
  916. }
  917. ));
  918. n(kt, {
  919. displayName: "InputRule<insertHrInputRule>",
  920. group: "Hr"
  921. });
  922. const ht = c("InsertHr", (t) => () => (e, r) => {
  923. if (!r)
  924. return !0;
  925. const a = A.node.type(t).create(), { tr: o, selection: s } = e, { from: l } = s, i = F.type(t).create();
  926. if (!i)
  927. return !0;
  928. const d = o.replaceSelectionWith(i).insert(l, a), m = tt.findFrom(d.doc.resolve(l), 1, !0);
  929. return m && r(d.setSelection(m).scrollIntoView()), !0;
  930. });
  931. n(ht, {
  932. displayName: "Command<insertHrCommand>",
  933. group: "Hr"
  934. });
  935. const Se = N("bulletList");
  936. n(Se, {
  937. displayName: "Attr<bulletList>",
  938. group: "BulletList"
  939. });
  940. const O = I("bullet_list", (t) => ({
  941. content: "listItem+",
  942. group: "block",
  943. attrs: {
  944. spread: {
  945. default: !1
  946. }
  947. },
  948. parseDOM: [
  949. {
  950. tag: "ul",
  951. getAttrs: (e) => {
  952. if (!(e instanceof HTMLElement))
  953. throw w(e);
  954. return {
  955. spread: e.dataset.spread
  956. };
  957. }
  958. }
  959. ],
  960. toDOM: (e) => [
  961. "ul",
  962. {
  963. ...t.get(Se.key)(e),
  964. "data-spread": e.attrs.spread
  965. },
  966. 0
  967. ],
  968. parseMarkdown: {
  969. match: ({ type: e, ordered: r }) => e === "list" && !r,
  970. runner: (e, r, a) => {
  971. const o = r.spread != null ? `${r.spread}` : "false";
  972. e.openNode(a, { spread: o }).next(r.children).closeNode();
  973. }
  974. },
  975. toMarkdown: {
  976. match: (e) => e.type.name === "bullet_list",
  977. runner: (e, r) => {
  978. e.openNode("list", void 0, { ordered: !1, spread: r.attrs.spread === "true" }).next(r.content).closeNode();
  979. }
  980. }
  981. }));
  982. n(O.node, {
  983. displayName: "NodeSchema<bulletList>",
  984. group: "BulletList"
  985. });
  986. n(O.ctx, {
  987. displayName: "NodeSchemaCtx<bulletList>",
  988. group: "BulletList"
  989. });
  990. const ft = h((t) => Q(/^\s*([-+*])\s$/, O.type(t)));
  991. n(ft, {
  992. displayName: "InputRule<wrapInBulletListInputRule>",
  993. group: "BulletList"
  994. });
  995. const we = c("WrapInBulletList", (t) => () => J(O.type(t)));
  996. n(we, {
  997. displayName: "Command<wrapInBulletListCommand>",
  998. group: "BulletList"
  999. });
  1000. const Ae = f("bulletListKeymap", {
  1001. WrapInBulletList: {
  1002. shortcuts: "Mod-Alt-8",
  1003. command: (t) => {
  1004. const e = t.get(u);
  1005. return () => e.call(we.key);
  1006. }
  1007. }
  1008. });
  1009. n(Ae.ctx, {
  1010. displayName: "KeymapCtx<bulletListKeymap>",
  1011. group: "BulletList"
  1012. });
  1013. n(Ae.shortcuts, {
  1014. displayName: "Keymap<bulletListKeymap>",
  1015. group: "BulletList"
  1016. });
  1017. const He = N("orderedList");
  1018. n(He, {
  1019. displayName: "Attr<orderedList>",
  1020. group: "OrderedList"
  1021. });
  1022. const T = I("ordered_list", (t) => ({
  1023. content: "listItem+",
  1024. group: "block",
  1025. attrs: {
  1026. order: {
  1027. default: 1
  1028. },
  1029. spread: {
  1030. default: !1
  1031. }
  1032. },
  1033. parseDOM: [
  1034. {
  1035. tag: "ol",
  1036. getAttrs: (e) => {
  1037. if (!(e instanceof HTMLElement))
  1038. throw w(e);
  1039. return {
  1040. spread: e.dataset.spread,
  1041. order: e.hasAttribute("start") ? Number(e.getAttribute("start")) : 1
  1042. };
  1043. }
  1044. }
  1045. ],
  1046. toDOM: (e) => [
  1047. "ol",
  1048. {
  1049. ...t.get(He.key)(e),
  1050. ...e.attrs.order === 1 ? {} : e.attrs.order,
  1051. "data-spread": e.attrs.spread
  1052. },
  1053. 0
  1054. ],
  1055. parseMarkdown: {
  1056. match: ({ type: e, ordered: r }) => e === "list" && !!r,
  1057. runner: (e, r, a) => {
  1058. const o = r.spread != null ? `${r.spread}` : "true";
  1059. e.openNode(a, { spread: o }).next(r.children).closeNode();
  1060. }
  1061. },
  1062. toMarkdown: {
  1063. match: (e) => e.type.name === "ordered_list",
  1064. runner: (e, r) => {
  1065. e.openNode("list", void 0, { ordered: !0, start: 1, spread: r.attrs.spread === "true" }), e.next(r.content), e.closeNode();
  1066. }
  1067. }
  1068. }));
  1069. n(T.node, {
  1070. displayName: "NodeSchema<orderedList>",
  1071. group: "OrderedList"
  1072. });
  1073. n(T.ctx, {
  1074. displayName: "NodeSchemaCtx<orderedList>",
  1075. group: "OrderedList"
  1076. });
  1077. const Nt = h((t) => Q(
  1078. /^\s*(\d+)\.\s$/,
  1079. T.type(t),
  1080. (e) => ({ order: Number(e[1]) }),
  1081. (e, r) => r.childCount + r.attrs.order === Number(e[1])
  1082. ));
  1083. n(Nt, {
  1084. displayName: "InputRule<wrapInOrderedListInputRule>",
  1085. group: "OrderedList"
  1086. });
  1087. const Be = c("WrapInOrderedList", (t) => () => J(T.type(t)));
  1088. n(Be, {
  1089. displayName: "Command<wrapInOrderedListCommand>",
  1090. group: "OrderedList"
  1091. });
  1092. const Re = f("orderedListKeymap", {
  1093. WrapInOrderedList: {
  1094. shortcuts: "Mod-Alt-7",
  1095. command: (t) => {
  1096. const e = t.get(u);
  1097. return () => e.call(Be.key);
  1098. }
  1099. }
  1100. });
  1101. n(Re.ctx, {
  1102. displayName: "KeymapCtx<orderedList>",
  1103. group: "OrderedList"
  1104. });
  1105. n(Re.shortcuts, {
  1106. displayName: "Keymap<orderedList>",
  1107. group: "OrderedList"
  1108. });
  1109. const ve = N("listItem");
  1110. n(ve, {
  1111. displayName: "Attr<listItem>",
  1112. group: "ListItem"
  1113. });
  1114. const M = I("list_item", (t) => ({
  1115. group: "listItem",
  1116. content: "paragraph block*",
  1117. attrs: {
  1118. label: {
  1119. default: "•"
  1120. },
  1121. listType: {
  1122. default: "bullet"
  1123. },
  1124. spread: {
  1125. default: "true"
  1126. }
  1127. },
  1128. defining: !0,
  1129. parseDOM: [
  1130. {
  1131. tag: "li",
  1132. getAttrs: (e) => {
  1133. if (!(e instanceof HTMLElement))
  1134. throw w(e);
  1135. return {
  1136. label: e.dataset.label,
  1137. listType: e.dataset["list-type"],
  1138. spread: e.dataset.spread
  1139. };
  1140. }
  1141. }
  1142. ],
  1143. toDOM: (e) => [
  1144. "li",
  1145. {
  1146. ...t.get(ve.key)(e),
  1147. "data-label": e.attrs.label,
  1148. "data-list-type": e.attrs.listType,
  1149. "data-spread": e.attrs.spread
  1150. },
  1151. 0
  1152. ],
  1153. parseMarkdown: {
  1154. match: ({ type: e }) => e === "listItem",
  1155. runner: (e, r, a) => {
  1156. const o = r.label != null ? `${r.label}.` : "•", s = r.label != null ? "ordered" : "bullet", l = r.spread != null ? `${r.spread}` : "true";
  1157. e.openNode(a, { label: o, listType: s, spread: l }), e.next(r.children), e.closeNode();
  1158. }
  1159. },
  1160. toMarkdown: {
  1161. match: (e) => e.type.name === "list_item",
  1162. runner: (e, r) => {
  1163. e.openNode("listItem", void 0, { spread: r.attrs.spread === "true" }), e.next(r.content), e.closeNode();
  1164. }
  1165. }
  1166. }));
  1167. n(M.node, {
  1168. displayName: "NodeSchema<listItem>",
  1169. group: "ListItem"
  1170. });
  1171. n(M.ctx, {
  1172. displayName: "NodeSchemaCtx<listItem>",
  1173. group: "ListItem"
  1174. });
  1175. const Oe = c("SinkListItem", (t) => () => Rt(M.type(t)));
  1176. n(Oe, {
  1177. displayName: "Command<sinkListItemCommand>",
  1178. group: "ListItem"
  1179. });
  1180. const Te = c("SplitListItem", (t) => () => rt(M.type(t)));
  1181. n(Te, {
  1182. displayName: "Command<liftListItemCommand>",
  1183. group: "ListItem"
  1184. });
  1185. const Ke = c("SplitListItem", (t) => () => vt(M.type(t)));
  1186. n(Ke, {
  1187. displayName: "Command<splitListItemCommand>",
  1188. group: "ListItem"
  1189. });
  1190. function $t(t) {
  1191. return (e, r, a) => {
  1192. const { selection: o } = e;
  1193. if (!(o instanceof X))
  1194. return !1;
  1195. const { empty: s, $from: l } = o;
  1196. if (!s || l.parentOffset !== 0)
  1197. return !1;
  1198. const i = l.node(-1);
  1199. return i.type !== M.type(t) || i.firstChild !== l.node() || l.node(-2).childCount > 1 ? !1 : rt(M.type(t))(e, r, a);
  1200. };
  1201. }
  1202. const De = c("LiftFirstListItem", (t) => () => $t(t));
  1203. n(De, {
  1204. displayName: "Command<liftFirstListItemCommand>",
  1205. group: "ListItem"
  1206. });
  1207. const _e = f("listItemKeymap", {
  1208. NextListItem: {
  1209. shortcuts: "Enter",
  1210. command: (t) => {
  1211. const e = t.get(u);
  1212. return () => e.call(Ke.key);
  1213. }
  1214. },
  1215. SinkListItem: {
  1216. shortcuts: ["Tab", "Mod-]"],
  1217. command: (t) => {
  1218. const e = t.get(u);
  1219. return () => e.call(Oe.key);
  1220. }
  1221. },
  1222. LiftListItem: {
  1223. shortcuts: ["Shift-Tab", "Mod-["],
  1224. command: (t) => {
  1225. const e = t.get(u);
  1226. return () => e.call(Te.key);
  1227. }
  1228. },
  1229. LiftFirstListItem: {
  1230. shortcuts: ["Backspace", "Delete"],
  1231. command: (t) => {
  1232. const e = t.get(u);
  1233. return () => e.call(De.key);
  1234. }
  1235. }
  1236. });
  1237. n(_e.ctx, {
  1238. displayName: "KeymapCtx<listItem>",
  1239. group: "ListItem"
  1240. });
  1241. n(_e.shortcuts, {
  1242. displayName: "Keymap<listItem>",
  1243. group: "ListItem"
  1244. });
  1245. const It = Qe("text", () => ({
  1246. group: "inline",
  1247. parseMarkdown: {
  1248. match: ({ type: t }) => t === "text",
  1249. runner: (t, e) => {
  1250. t.addText(e.value);
  1251. }
  1252. },
  1253. toMarkdown: {
  1254. match: (t) => t.type.name === "text",
  1255. runner: (t, e) => {
  1256. t.addNode("text", void 0, e.text);
  1257. }
  1258. }
  1259. }));
  1260. n(It, {
  1261. displayName: "NodeSchema<text>",
  1262. group: "Text"
  1263. });
  1264. const Ee = N("html");
  1265. n(Ee, {
  1266. displayName: "Attr<html>",
  1267. group: "Html"
  1268. });
  1269. const Pe = I("html", (t) => ({
  1270. atom: !0,
  1271. group: "inline",
  1272. inline: !0,
  1273. attrs: {
  1274. value: {
  1275. default: ""
  1276. }
  1277. },
  1278. toDOM: (e) => {
  1279. const r = document.createElement("span"), a = {
  1280. ...t.get(Ee.key)(e),
  1281. "data-value": e.attrs.value,
  1282. "data-type": "html"
  1283. };
  1284. return r.textContent = e.attrs.value, ["span", a, e.attrs.value];
  1285. },
  1286. parseDOM: [{
  1287. tag: 'span[data-type="html"]',
  1288. getAttrs: (e) => ({
  1289. value: e.dataset.value ?? ""
  1290. })
  1291. }],
  1292. parseMarkdown: {
  1293. match: ({ type: e }) => e === "html",
  1294. runner: (e, r, a) => {
  1295. e.addNode(a, { value: r.value });
  1296. }
  1297. },
  1298. toMarkdown: {
  1299. match: (e) => e.type.name === "html",
  1300. runner: (e, r) => {
  1301. e.addNode("html", void 0, r.attrs.value);
  1302. }
  1303. }
  1304. }));
  1305. n(Pe.node, {
  1306. displayName: "NodeSchema<html>",
  1307. group: "Html"
  1308. });
  1309. n(Pe.ctx, {
  1310. displayName: "NodeSchemaCtx<html>",
  1311. group: "Html"
  1312. });
  1313. const qt = [
  1314. mt,
  1315. de,
  1316. A,
  1317. j,
  1318. ce,
  1319. H,
  1320. Me,
  1321. S,
  1322. ye,
  1323. q,
  1324. fe,
  1325. W,
  1326. xe,
  1327. F,
  1328. Ce,
  1329. v,
  1330. Se,
  1331. O,
  1332. He,
  1333. T,
  1334. ve,
  1335. M,
  1336. Z,
  1337. R,
  1338. re,
  1339. $,
  1340. oe,
  1341. x,
  1342. ie,
  1343. B,
  1344. Ee,
  1345. Pe,
  1346. It
  1347. ].flat(), Wt = [
  1348. ct,
  1349. ft,
  1350. Nt,
  1351. ut,
  1352. kt,
  1353. pt
  1354. ].flat(), Ft = [
  1355. nt,
  1356. ot,
  1357. lt,
  1358. st
  1359. ], Vt = [
  1360. me,
  1361. ke,
  1362. L,
  1363. ue,
  1364. Ne,
  1365. be,
  1366. ht,
  1367. gt,
  1368. yt,
  1369. Be,
  1370. we,
  1371. Oe,
  1372. Ke,
  1373. Te,
  1374. De,
  1375. ee,
  1376. se,
  1377. ae,
  1378. it,
  1379. dt
  1380. ], Ut = [
  1381. he,
  1382. Ie,
  1383. Le,
  1384. ge,
  1385. _e,
  1386. Re,
  1387. Ae,
  1388. pe,
  1389. te,
  1390. le,
  1391. ne
  1392. ].flat(), $e = D("remarkAddOrderInList", () => () => (t) => {
  1393. Y(t, "list", (e) => {
  1394. if (e.ordered) {
  1395. const r = e.start ?? 1;
  1396. e.children.forEach((a, o) => {
  1397. a.label = o + r;
  1398. });
  1399. }
  1400. });
  1401. });
  1402. n($e.plugin, {
  1403. displayName: "Remark<remarkAddOrderInListPlugin>",
  1404. group: "Remark"
  1405. });
  1406. n($e.options, {
  1407. displayName: "RemarkConfig<remarkAddOrderInListPlugin>",
  1408. group: "Remark"
  1409. });
  1410. const qe = D("remarkLineBreak", () => () => (t) => {
  1411. const e = /[\t ]*(?:\r?\n|\r)/g;
  1412. Y(t, "text", (r, a, o) => {
  1413. if (!r.value || typeof r.value != "string")
  1414. return;
  1415. const s = [];
  1416. let l = 0;
  1417. e.lastIndex = 0;
  1418. let i = e.exec(r.value);
  1419. for (; i; ) {
  1420. const m = i.index;
  1421. 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);
  1422. }
  1423. if (s.length > 0 && o && typeof a == "number")
  1424. return l < r.value.length && s.push({ type: "text", value: r.value.slice(l) }), o.children.splice(a, 1, ...s), a + s.length;
  1425. });
  1426. });
  1427. n(qe.plugin, {
  1428. displayName: "Remark<remarkLineBreak>",
  1429. group: "Remark"
  1430. });
  1431. n(qe.options, {
  1432. displayName: "RemarkConfig<remarkLineBreak>",
  1433. group: "Remark"
  1434. });
  1435. const We = D("remarkInlineLink", () => Kt);
  1436. n(We.plugin, {
  1437. displayName: "Remark<remarkInlineLinkPlugin>",
  1438. group: "Remark"
  1439. });
  1440. n(We.options, {
  1441. displayName: "RemarkConfig<remarkInlineLinkPlugin>",
  1442. group: "Remark"
  1443. });
  1444. const Gt = (t) => !!t.children, jt = (t) => t.type === "html";
  1445. function zt(t, e) {
  1446. return r(t, 0, null)[0];
  1447. function r(a, o, s) {
  1448. if (Gt(a)) {
  1449. const l = [];
  1450. for (let i = 0, d = a.children.length; i < d; i++) {
  1451. const m = a.children[i];
  1452. if (m) {
  1453. const p = r(m, i, a);
  1454. if (p)
  1455. for (let k = 0, g = p.length; k < g; k++) {
  1456. const C = p[k];
  1457. C && l.push(C);
  1458. }
  1459. }
  1460. }
  1461. a.children = l;
  1462. }
  1463. return e(a, o, s);
  1464. }
  1465. }
  1466. const Fe = D("remarkHTMLTransformer", () => () => (t) => {
  1467. 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]);
  1468. });
  1469. n(Fe.plugin, {
  1470. displayName: "Remark<remarkHtmlTransformer>",
  1471. group: "Remark"
  1472. });
  1473. n(Fe.options, {
  1474. displayName: "RemarkConfig<remarkHtmlTransformer>",
  1475. group: "Remark"
  1476. });
  1477. const Ve = D("remarkMarker", () => () => (t, e) => {
  1478. const r = (a) => e.value.charAt(a.position.start.offset);
  1479. Y(t, (a) => ["strong", "emphasis"].includes(a.type), (a) => {
  1480. a.marker = r(a);
  1481. });
  1482. });
  1483. n(Ve.plugin, {
  1484. displayName: "Remark<remarkMarker>",
  1485. group: "Remark"
  1486. });
  1487. n(Ve.options, {
  1488. displayName: "RemarkConfig<remarkMarker>",
  1489. group: "Remark"
  1490. });
  1491. const Ct = _(() => {
  1492. let t = !1;
  1493. const e = new E("MILKDOWN_INLINE_NODES_CURSOR"), r = new P({
  1494. key: e,
  1495. state: {
  1496. init() {
  1497. return !1;
  1498. },
  1499. apply(a) {
  1500. if (!a.selection.empty)
  1501. return !1;
  1502. const o = a.selection.$from, s = o.nodeBefore, l = o.nodeAfter;
  1503. return !!(s && l && s.isInline && !s.isText && l.isInline && !l.isText);
  1504. }
  1505. },
  1506. props: {
  1507. handleDOMEvents: {
  1508. compositionend: (a, o) => t ? (t = !1, requestAnimationFrame(() => {
  1509. if (r.getState(a.state)) {
  1510. const l = a.state.selection.from;
  1511. o.preventDefault(), a.dispatch(a.state.tr.insertText(o.data || "", l));
  1512. }
  1513. }), !0) : !1,
  1514. compositionstart: (a) => (r.getState(a.state) && (t = !0), !1),
  1515. beforeinput: (a, o) => {
  1516. if (r.getState(a.state) && o instanceof InputEvent && o.data && !t) {
  1517. const l = a.state.selection.from;
  1518. return o.preventDefault(), a.dispatch(a.state.tr.insertText(o.data || "", l)), !0;
  1519. }
  1520. return !1;
  1521. }
  1522. },
  1523. decorations(a) {
  1524. if (r.getState(a)) {
  1525. const l = a.selection.$from.pos, i = document.createElement("span"), d = ze.widget(l, i, {
  1526. side: -1
  1527. }), m = document.createElement("span"), p = ze.widget(l, m);
  1528. return setTimeout(() => {
  1529. i.contentEditable = "true", m.contentEditable = "true";
  1530. }), Je.create(a.doc, [d, p]);
  1531. }
  1532. return Je.empty;
  1533. }
  1534. }
  1535. });
  1536. return r;
  1537. });
  1538. n(Ct, {
  1539. displayName: "Prose<inlineNodesCursorPlugin>",
  1540. group: "Prose"
  1541. });
  1542. const Mt = _((t) => new P({
  1543. key: new E("MILKDOWN_HARDBREAK_MARKS"),
  1544. appendTransaction: (e, r, a) => {
  1545. if (!e.length)
  1546. return;
  1547. const [o] = e;
  1548. if (!o)
  1549. return;
  1550. const [s] = o.steps;
  1551. if (o.getMeta("hardbreak")) {
  1552. if (!(s instanceof Ot))
  1553. return;
  1554. const { from: d } = s;
  1555. return a.tr.setNodeMarkup(d, S.type(t), void 0, []);
  1556. }
  1557. if (s instanceof Tt) {
  1558. let d = a.tr;
  1559. const { from: m, to: p } = s;
  1560. return a.doc.nodesBetween(m, p, (k, g) => {
  1561. k.type === S.type(t) && (d = d.setNodeMarkup(g, S.type(t), void 0, []));
  1562. }), d;
  1563. }
  1564. }
  1565. }));
  1566. n(Mt, {
  1567. displayName: "Prose<hardbreakClearMarkPlugin>",
  1568. group: "Prose"
  1569. });
  1570. const Ue = Xe(["table", "code_block"], "hardbreakFilterNodes");
  1571. n(Ue, {
  1572. displayName: "Ctx<hardbreakFilterNodes>",
  1573. group: "Prose"
  1574. });
  1575. const bt = _((t) => {
  1576. const e = t.get(Ue.key);
  1577. return new P({
  1578. key: new E("MILKDOWN_HARDBREAK_FILTER"),
  1579. filterTransaction: (r, a) => {
  1580. const o = r.getMeta("hardbreak"), [s] = r.steps;
  1581. if (o && s) {
  1582. const { from: l } = s, i = a.doc.resolve(l);
  1583. let d = i.depth, m = !0;
  1584. for (; d > 0; )
  1585. e.includes(i.node(d).type.name) && (m = !1), d--;
  1586. return m;
  1587. }
  1588. return !0;
  1589. }
  1590. });
  1591. });
  1592. n(bt, {
  1593. displayName: "Prose<hardbreakFilterPlugin>",
  1594. group: "Prose"
  1595. });
  1596. const Lt = _((t) => {
  1597. const e = new E("MILKDOWN_HEADING_ID"), r = (a) => {
  1598. if (a.composing || !a.editable)
  1599. return;
  1600. const o = t.get(j.key), s = a.state.tr.setMeta("addToHistory", !1);
  1601. let l = !1;
  1602. a.state.doc.descendants((i, d) => {
  1603. if (i.type === H.type(t)) {
  1604. if (i.textContent.trim().length === 0)
  1605. return;
  1606. const m = i.attrs, p = o(i);
  1607. m.id !== p && (l = !0, s.setMeta(e, !0).setNodeMarkup(d, void 0, {
  1608. ...m,
  1609. id: p
  1610. }));
  1611. }
  1612. }), l && a.dispatch(s);
  1613. };
  1614. return new P({
  1615. key: e,
  1616. view: (a) => (r(a), {
  1617. update: (o) => {
  1618. r(o);
  1619. }
  1620. })
  1621. });
  1622. });
  1623. n(Lt, {
  1624. displayName: "Prose<syncHeadingIdPlugin>",
  1625. group: "Prose"
  1626. });
  1627. const xt = _((t) => {
  1628. const e = (r) => {
  1629. if (r.composing || !r.editable)
  1630. return;
  1631. const a = T.type(t), o = O.type(t), s = M.type(t), l = r.state, i = (p, k) => {
  1632. let g = !1;
  1633. const C = `${k + 1}.`;
  1634. return p.label !== C && (p.label = C, g = !0), g;
  1635. };
  1636. let d = l.tr, m = !1;
  1637. l.doc.descendants((p, k, g, C) => {
  1638. if (p.type === o) {
  1639. const y = p.maybeChild(0);
  1640. (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) => {
  1641. if (b.type === s) {
  1642. const je = { ...b.attrs };
  1643. i(je, St) && (d = d.setNodeMarkup(Ge, void 0, je));
  1644. }
  1645. return !1;
  1646. }));
  1647. } else if (p.type === s && (g == null ? void 0 : g.type) === a) {
  1648. const y = { ...p.attrs };
  1649. let b = !1;
  1650. 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);
  1651. }
  1652. }), m && r.dispatch(d.setMeta("addToHistory", !1));
  1653. };
  1654. return new P({
  1655. key: new E("MILKDOWN_KEEP_LIST_ORDER"),
  1656. view: (r) => (e(r), {
  1657. update: (a) => {
  1658. e(a);
  1659. }
  1660. })
  1661. });
  1662. });
  1663. n(xt, {
  1664. displayName: "Prose<syncListOrderPlugin>",
  1665. group: "Prose"
  1666. });
  1667. const Jt = [
  1668. Mt,
  1669. Ue,
  1670. bt,
  1671. Ct,
  1672. $e,
  1673. We,
  1674. qe,
  1675. Fe,
  1676. Ve,
  1677. Lt,
  1678. xt
  1679. ].flat(), cr = [qt, Wt, Ft, Vt, Ut, Jt].flat();
  1680. export {
  1681. ye as blockquoteAttr,
  1682. he as blockquoteKeymap,
  1683. q as blockquoteSchema,
  1684. Se as bulletListAttr,
  1685. Ae as bulletListKeymap,
  1686. O as bulletListSchema,
  1687. fe as codeBlockAttr,
  1688. Ie as codeBlockKeymap,
  1689. W as codeBlockSchema,
  1690. Vt as commands,
  1691. cr as commonmark,
  1692. Ne as createCodeBlockCommand,
  1693. ut as createCodeBlockInputRule,
  1694. mt as docSchema,
  1695. ue as downgradeHeadingCommand,
  1696. Z as emphasisAttr,
  1697. te as emphasisKeymap,
  1698. R as emphasisSchema,
  1699. nt as emphasisStarInputRule,
  1700. ot as emphasisUnderscoreInputRule,
  1701. Me as hardbreakAttr,
  1702. Mt as hardbreakClearMarkPlugin,
  1703. Ue as hardbreakFilterNodes,
  1704. bt as hardbreakFilterPlugin,
  1705. Le as hardbreakKeymap,
  1706. S as hardbreakSchema,
  1707. ce as headingAttr,
  1708. j as headingIdGenerator,
  1709. ge as headingKeymap,
  1710. H as headingSchema,
  1711. xe as hrAttr,
  1712. F as hrSchema,
  1713. Ee as htmlAttr,
  1714. Pe as htmlSchema,
  1715. Ce as imageAttr,
  1716. v as imageSchema,
  1717. oe as inlineCodeAttr,
  1718. lt as inlineCodeInputRule,
  1719. le as inlineCodeKeymap,
  1720. x as inlineCodeSchema,
  1721. Ct as inlineNodesCursorPlugin,
  1722. Wt as inputRules,
  1723. be as insertHardbreakCommand,
  1724. ht as insertHrCommand,
  1725. kt as insertHrInputRule,
  1726. gt as insertImageCommand,
  1727. Pt as insertImageInputRule,
  1728. Ut as keymap,
  1729. De as liftFirstListItemCommand,
  1730. Te as liftListItemCommand,
  1731. ie as linkAttr,
  1732. B as linkSchema,
  1733. ve as listItemAttr,
  1734. _e as listItemKeymap,
  1735. M as listItemSchema,
  1736. Ft as markInputRules,
  1737. He as orderedListAttr,
  1738. Re as orderedListKeymap,
  1739. T as orderedListSchema,
  1740. de as paragraphAttr,
  1741. pe as paragraphKeymap,
  1742. A as paragraphSchema,
  1743. Jt as plugins,
  1744. $e as remarkAddOrderInListPlugin,
  1745. Fe as remarkHtmlTransformer,
  1746. We as remarkInlineLinkPlugin,
  1747. qe as remarkLineBreak,
  1748. Ve as remarkMarker,
  1749. qt as schema,
  1750. Oe as sinkListItemCommand,
  1751. Ke as splitListItemCommand,
  1752. re as strongAttr,
  1753. st as strongInputRule,
  1754. ne as strongKeymap,
  1755. $ as strongSchema,
  1756. Lt as syncHeadingIdPlugin,
  1757. xt as syncListOrderPlugin,
  1758. It as textSchema,
  1759. ee as toggleEmphasisCommand,
  1760. se as toggleInlineCodeCommand,
  1761. it as toggleLinkCommand,
  1762. ae as toggleStrongCommand,
  1763. me as turnIntoTextCommand,
  1764. Et as updateCodeBlockLanguageCommand,
  1765. yt as updateImageCommand,
  1766. dt as updateLinkCommand,
  1767. ke as wrapInBlockquoteCommand,
  1768. ct as wrapInBlockquoteInputRule,
  1769. we as wrapInBulletListCommand,
  1770. ft as wrapInBulletListInputRule,
  1771. L as wrapInHeadingCommand,
  1772. pt as wrapInHeadingInputRule,
  1773. Be as wrapInOrderedListCommand,
  1774. Nt as wrapInOrderedListInputRule
  1775. };
  1776. //# sourceMappingURL=index.es.js.map