@milkdown/crepe 7.12.1 → 7.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/lib/cjs/feature/block-edit/index.js +248 -229
  2. package/lib/cjs/feature/block-edit/index.js.map +1 -1
  3. package/lib/cjs/feature/latex/index.js +41 -3
  4. package/lib/cjs/feature/latex/index.js.map +1 -1
  5. package/lib/cjs/feature/placeholder/index.js.map +1 -1
  6. package/lib/cjs/feature/toolbar/index.js +213 -160
  7. package/lib/cjs/feature/toolbar/index.js.map +1 -1
  8. package/lib/cjs/index.js +408 -390
  9. package/lib/cjs/index.js.map +1 -1
  10. package/lib/esm/feature/block-edit/index.js +250 -231
  11. package/lib/esm/feature/block-edit/index.js.map +1 -1
  12. package/lib/esm/feature/latex/index.js +42 -4
  13. package/lib/esm/feature/latex/index.js.map +1 -1
  14. package/lib/esm/feature/placeholder/index.js.map +1 -1
  15. package/lib/esm/feature/toolbar/index.js +217 -164
  16. package/lib/esm/feature/toolbar/index.js.map +1 -1
  17. package/lib/esm/index.js +414 -396
  18. package/lib/esm/index.js.map +1 -1
  19. package/lib/tsconfig.tsbuildinfo +1 -1
  20. package/lib/types/feature/block-edit/index.d.ts +78 -38
  21. package/lib/types/feature/block-edit/index.d.ts.map +1 -1
  22. package/lib/types/feature/block-edit/menu/config.d.ts +3 -2
  23. package/lib/types/feature/block-edit/menu/config.d.ts.map +1 -1
  24. package/lib/types/feature/block-edit/menu/utils.d.ts +2 -24
  25. package/lib/types/feature/block-edit/menu/utils.d.ts.map +1 -1
  26. package/lib/types/feature/latex/command.d.ts +2 -0
  27. package/lib/types/feature/latex/command.d.ts.map +1 -0
  28. package/lib/types/feature/latex/index.d.ts.map +1 -1
  29. package/lib/types/feature/toolbar/component.d.ts +1 -1
  30. package/lib/types/feature/toolbar/component.d.ts.map +1 -1
  31. package/lib/types/feature/toolbar/config.d.ts +12 -0
  32. package/lib/types/feature/toolbar/config.d.ts.map +1 -0
  33. package/lib/types/feature/toolbar/index.d.ts +3 -0
  34. package/lib/types/feature/toolbar/index.d.ts.map +1 -1
  35. package/lib/types/utils/checker.d.ts +4 -0
  36. package/lib/types/utils/checker.d.ts.map +1 -0
  37. package/lib/types/utils/group-builder.d.ts +43 -0
  38. package/lib/types/utils/group-builder.d.ts.map +1 -0
  39. package/lib/types/utils/index.d.ts +3 -3
  40. package/lib/types/utils/index.d.ts.map +1 -1
  41. package/lib/types/utils/types.d.ts +4 -0
  42. package/lib/types/utils/types.d.ts.map +1 -0
  43. package/package.json +2 -2
  44. package/src/feature/block-edit/index.ts +78 -38
  45. package/src/feature/block-edit/menu/config.ts +306 -240
  46. package/src/feature/block-edit/menu/utils.ts +1 -106
  47. package/src/feature/latex/command.ts +48 -0
  48. package/src/feature/latex/index.ts +2 -0
  49. package/src/feature/toolbar/component.tsx +44 -194
  50. package/src/feature/toolbar/config.ts +136 -0
  51. package/src/feature/toolbar/index.ts +3 -0
  52. package/src/utils/checker.ts +11 -0
  53. package/src/utils/group-builder.ts +68 -0
  54. package/src/utils/index.ts +3 -11
  55. package/src/utils/types.ts +9 -0
  56. package/lib/types/feature/block-edit/menu/group-builder.d.ts +0 -29
  57. package/lib/types/feature/block-edit/menu/group-builder.d.ts.map +0 -1
  58. package/src/feature/block-edit/menu/group-builder.ts +0 -49
@@ -1,7 +1,7 @@
1
1
  import { blockConfig, block, BlockProvider } from '@milkdown/kit/plugin/block';
2
2
  import { createSlice } from '@milkdown/kit/ctx';
3
- import { editorViewCtx } from '@milkdown/kit/core';
4
- import { paragraphSchema, headingSchema, blockquoteSchema, hrSchema, bulletListSchema, orderedListSchema, listItemSchema, codeBlockSchema } from '@milkdown/kit/preset/commonmark';
3
+ import { commandsCtx, editorViewCtx } from '@milkdown/kit/core';
4
+ import { paragraphSchema, clearTextInCurrentBlockCommand, setBlockTypeCommand, headingSchema, blockquoteSchema, wrapInBlockTypeCommand, hrSchema, addBlockTypeCommand, bulletListSchema, orderedListSchema, listItemSchema, codeBlockSchema, selectTextNearPosCommand } from '@milkdown/kit/preset/commonmark';
5
5
  import { findParent } from '@milkdown/kit/prose';
6
6
  import { TextSelection } from '@milkdown/kit/prose/state';
7
7
  import { defineComponent, ref, computed, watch, watchEffect, onUnmounted, h, createApp, Fragment } from 'vue';
@@ -10,7 +10,6 @@ import { $ctx } from '@milkdown/kit/utils';
10
10
  import { Icon } from '@milkdown/kit/component';
11
11
  import { imageBlockSchema } from '@milkdown/kit/component/image-block';
12
12
  import { createTable } from '@milkdown/kit/preset/gfm';
13
- import { findWrapping } from '@milkdown/kit/prose/transform';
14
13
 
15
14
  createSlice([], "FeaturesCtx");
16
15
  createSlice({}, "CrepeCtx");
@@ -420,7 +419,7 @@ class GroupBuilder {
420
419
  const groupInstance = {
421
420
  group,
422
421
  addItem: (key, item) => {
423
- const data = { key, ...item };
422
+ const data = { ...item, key };
424
423
  group.items.push(data);
425
424
  return groupInstance;
426
425
  },
@@ -454,260 +453,280 @@ class GroupBuilder {
454
453
  _groups = new WeakMap();
455
454
  _getGroupInstance = new WeakMap();
456
455
 
457
- function clearRange(tr) {
458
- const { $from, $to } = tr.selection;
459
- const { pos: from } = $from;
460
- const { pos: to } = $to;
461
- tr = tr.deleteRange(from - $from.node().content.size, to);
462
- return tr;
463
- }
464
- function setBlockType(tr, nodeType, attrs = null) {
465
- const { from, to } = tr.selection;
466
- return tr.setBlockType(from, to, nodeType, attrs);
467
- }
468
- function wrapInBlockType(tr, nodeType, attrs = null) {
469
- const { $from, $to } = tr.selection;
470
- const range = $from.blockRange($to);
471
- const wrapping = range && findWrapping(range, nodeType, attrs);
472
- if (!wrapping) return null;
473
- return tr.wrap(range, wrapping);
474
- }
475
- function addBlockType(tr, nodeType, attrs = null) {
476
- const node = nodeType.createAndFill(attrs);
477
- if (!node) return null;
478
- return tr.replaceSelectionWith(node);
479
- }
480
- function clearContentAndSetBlockType(nodeType, attrs = null) {
481
- return (state, dispatch) => {
482
- if (dispatch) {
483
- const tr = setBlockType(clearRange(state.tr), nodeType, attrs);
484
- dispatch(tr.scrollIntoView());
485
- }
486
- return true;
487
- };
488
- }
489
- function clearContentAndWrapInBlockType(nodeType, attrs = null) {
490
- return (state, dispatch) => {
491
- const tr = wrapInBlockType(clearRange(state.tr), nodeType, attrs);
492
- if (!tr) return false;
493
- if (dispatch) dispatch(tr.scrollIntoView());
494
- return true;
495
- };
496
- }
497
- function clearContentAndAddBlockType(nodeType, attrs = null) {
498
- return (state, dispatch) => {
499
- const tr = addBlockType(clearRange(state.tr), nodeType, attrs);
500
- if (!tr) return false;
501
- if (dispatch) dispatch(tr.scrollIntoView());
502
- return true;
503
- };
504
- }
505
-
506
456
  function getGroups(filter, config, ctx) {
507
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J;
457
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma, _Na, _Oa, _Pa, _Qa, _Ra, _Sa, _Ta, _Ua, _Va, _Wa, _Xa, _Ya, _Za, __a, _$a, _ab, _bb, _cb, _db, _eb, _fb, _gb, _hb, _ib, _jb, _kb;
508
458
  const flags = ctx && useCrepeFeatures(ctx).get();
509
459
  const isLatexEnabled = flags == null ? void 0 : flags.includes(CrepeFeature.Latex);
510
460
  const isImageBlockEnabled = flags == null ? void 0 : flags.includes(CrepeFeature.ImageBlock);
511
461
  const isTableEnabled = flags == null ? void 0 : flags.includes(CrepeFeature.Table);
512
462
  const groupBuilder = new GroupBuilder();
513
- groupBuilder.addGroup("text", (_a = config == null ? void 0 : config.slashMenuTextGroupLabel) != null ? _a : "Text").addItem("text", {
514
- label: (_b = config == null ? void 0 : config.slashMenuTextLabel) != null ? _b : "Text",
515
- icon: (_c = config == null ? void 0 : config.slashMenuTextIcon) != null ? _c : textIcon,
516
- onRun: (ctx2) => {
517
- const view = ctx2.get(editorViewCtx);
518
- const { dispatch, state } = view;
519
- const command = clearContentAndSetBlockType(paragraphSchema.type(ctx2));
520
- command(state, dispatch);
463
+ if ((config == null ? void 0 : config.textGroup) !== null) {
464
+ const textGroup = groupBuilder.addGroup(
465
+ "text",
466
+ (_b = (_a = config == null ? void 0 : config.textGroup) == null ? void 0 : _a.label) != null ? _b : "Text"
467
+ );
468
+ if (((_c = config == null ? void 0 : config.textGroup) == null ? void 0 : _c.text) !== null) {
469
+ textGroup.addItem("text", {
470
+ label: (_f = (_e = (_d = config == null ? void 0 : config.textGroup) == null ? void 0 : _d.text) == null ? void 0 : _e.label) != null ? _f : "Text",
471
+ icon: (_i = (_h = (_g = config == null ? void 0 : config.textGroup) == null ? void 0 : _g.text) == null ? void 0 : _h.icon) != null ? _i : textIcon,
472
+ onRun: (ctx2) => {
473
+ const commands = ctx2.get(commandsCtx);
474
+ const paragraph = paragraphSchema.type(ctx2);
475
+ commands.call(clearTextInCurrentBlockCommand.key);
476
+ commands.call(setBlockTypeCommand.key, {
477
+ nodeType: paragraph
478
+ });
479
+ }
480
+ });
521
481
  }
522
- }).addItem("h1", {
523
- label: (_d = config == null ? void 0 : config.slashMenuH1Label) != null ? _d : "Heading 1",
524
- icon: (_e = config == null ? void 0 : config.slashMenuH1Icon) != null ? _e : h1Icon,
525
- onRun: (ctx2) => {
526
- const view = ctx2.get(editorViewCtx);
527
- const { dispatch, state } = view;
528
- const command = clearContentAndSetBlockType(headingSchema.type(ctx2), {
529
- level: 1
482
+ if (((_j = config == null ? void 0 : config.textGroup) == null ? void 0 : _j.h1) !== null) {
483
+ textGroup.addItem("h1", {
484
+ label: (_m = (_l = (_k = config == null ? void 0 : config.textGroup) == null ? void 0 : _k.h1) == null ? void 0 : _l.label) != null ? _m : "Heading 1",
485
+ icon: (_p = (_o = (_n = config == null ? void 0 : config.textGroup) == null ? void 0 : _n.h1) == null ? void 0 : _o.icon) != null ? _p : h1Icon,
486
+ onRun: (ctx2) => {
487
+ const commands = ctx2.get(commandsCtx);
488
+ const heading = headingSchema.type(ctx2);
489
+ commands.call(clearTextInCurrentBlockCommand.key);
490
+ commands.call(setBlockTypeCommand.key, {
491
+ nodeType: heading,
492
+ attrs: {
493
+ level: 1
494
+ }
495
+ });
496
+ }
530
497
  });
531
- command(state, dispatch);
532
498
  }
533
- }).addItem("h2", {
534
- label: (_f = config == null ? void 0 : config.slashMenuH2Label) != null ? _f : "Heading 2",
535
- icon: (_g = config == null ? void 0 : config.slashMenuH2Icon) != null ? _g : h2Icon,
536
- onRun: (ctx2) => {
537
- const view = ctx2.get(editorViewCtx);
538
- const { dispatch, state } = view;
539
- const command = clearContentAndSetBlockType(headingSchema.type(ctx2), {
540
- level: 2
499
+ if (((_q = config == null ? void 0 : config.textGroup) == null ? void 0 : _q.h2) !== null) {
500
+ textGroup.addItem("h2", {
501
+ label: (_t = (_s = (_r = config == null ? void 0 : config.textGroup) == null ? void 0 : _r.h2) == null ? void 0 : _s.label) != null ? _t : "Heading 2",
502
+ icon: (_w = (_v = (_u = config == null ? void 0 : config.textGroup) == null ? void 0 : _u.h2) == null ? void 0 : _v.icon) != null ? _w : h2Icon,
503
+ onRun: (ctx2) => {
504
+ const commands = ctx2.get(commandsCtx);
505
+ const heading = headingSchema.type(ctx2);
506
+ commands.call(clearTextInCurrentBlockCommand.key);
507
+ commands.call(setBlockTypeCommand.key, {
508
+ nodeType: heading,
509
+ attrs: {
510
+ level: 2
511
+ }
512
+ });
513
+ }
541
514
  });
542
- command(state, dispatch);
543
515
  }
544
- }).addItem("h3", {
545
- label: (_h = config == null ? void 0 : config.slashMenuH3Label) != null ? _h : "Heading 3",
546
- icon: (_i = config == null ? void 0 : config.slashMenuH3Icon) != null ? _i : h3Icon,
547
- onRun: (ctx2) => {
548
- const view = ctx2.get(editorViewCtx);
549
- const { dispatch, state } = view;
550
- const command = clearContentAndSetBlockType(headingSchema.type(ctx2), {
551
- level: 3
516
+ if (((_x = config == null ? void 0 : config.textGroup) == null ? void 0 : _x.h3) !== null) {
517
+ textGroup.addItem("h3", {
518
+ label: (_A = (_z = (_y = config == null ? void 0 : config.textGroup) == null ? void 0 : _y.h3) == null ? void 0 : _z.label) != null ? _A : "Heading 3",
519
+ icon: (_D = (_C = (_B = config == null ? void 0 : config.textGroup) == null ? void 0 : _B.h3) == null ? void 0 : _C.icon) != null ? _D : h3Icon,
520
+ onRun: (ctx2) => {
521
+ const commands = ctx2.get(commandsCtx);
522
+ const heading = headingSchema.type(ctx2);
523
+ commands.call(clearTextInCurrentBlockCommand.key);
524
+ commands.call(setBlockTypeCommand.key, {
525
+ nodeType: heading,
526
+ attrs: {
527
+ level: 3
528
+ }
529
+ });
530
+ }
552
531
  });
553
- command(state, dispatch);
554
532
  }
555
- }).addItem("h4", {
556
- label: (_j = config == null ? void 0 : config.slashMenuH4Label) != null ? _j : "Heading 4",
557
- icon: (_k = config == null ? void 0 : config.slashMenuH4Icon) != null ? _k : h4Icon,
558
- onRun: (ctx2) => {
559
- const view = ctx2.get(editorViewCtx);
560
- const { dispatch, state } = view;
561
- const command = clearContentAndSetBlockType(headingSchema.type(ctx2), {
562
- level: 4
533
+ if (((_E = config == null ? void 0 : config.textGroup) == null ? void 0 : _E.h4) !== null) {
534
+ textGroup.addItem("h4", {
535
+ label: (_H = (_G = (_F = config == null ? void 0 : config.textGroup) == null ? void 0 : _F.h4) == null ? void 0 : _G.label) != null ? _H : "Heading 4",
536
+ icon: (_K = (_J = (_I = config == null ? void 0 : config.textGroup) == null ? void 0 : _I.h4) == null ? void 0 : _J.icon) != null ? _K : h4Icon,
537
+ onRun: (ctx2) => {
538
+ const commands = ctx2.get(commandsCtx);
539
+ const heading = headingSchema.type(ctx2);
540
+ commands.call(clearTextInCurrentBlockCommand.key);
541
+ commands.call(setBlockTypeCommand.key, {
542
+ nodeType: heading,
543
+ attrs: {
544
+ level: 4
545
+ }
546
+ });
547
+ }
563
548
  });
564
- command(state, dispatch);
565
549
  }
566
- }).addItem("h5", {
567
- label: (_l = config == null ? void 0 : config.slashMenuH5Label) != null ? _l : "Heading 5",
568
- icon: (_m = config == null ? void 0 : config.slashMenuH5Icon) != null ? _m : h5Icon,
569
- onRun: (ctx2) => {
570
- const view = ctx2.get(editorViewCtx);
571
- const { dispatch, state } = view;
572
- const command = clearContentAndSetBlockType(headingSchema.type(ctx2), {
573
- level: 5
550
+ if (((_L = config == null ? void 0 : config.textGroup) == null ? void 0 : _L.h5) !== null) {
551
+ textGroup.addItem("h5", {
552
+ label: (_O = (_N = (_M = config == null ? void 0 : config.textGroup) == null ? void 0 : _M.h5) == null ? void 0 : _N.label) != null ? _O : "Heading 5",
553
+ icon: (_R = (_Q = (_P = config == null ? void 0 : config.textGroup) == null ? void 0 : _P.h5) == null ? void 0 : _Q.icon) != null ? _R : h5Icon,
554
+ onRun: (ctx2) => {
555
+ const commands = ctx2.get(commandsCtx);
556
+ const heading = headingSchema.type(ctx2);
557
+ commands.call(clearTextInCurrentBlockCommand.key);
558
+ commands.call(setBlockTypeCommand.key, {
559
+ nodeType: heading,
560
+ attrs: {
561
+ level: 5
562
+ }
563
+ });
564
+ }
574
565
  });
575
- command(state, dispatch);
576
566
  }
577
- }).addItem("h6", {
578
- label: (_n = config == null ? void 0 : config.slashMenuH6Label) != null ? _n : "Heading 6",
579
- icon: (_o = config == null ? void 0 : config.slashMenuH6Icon) != null ? _o : h6Icon,
580
- onRun: (ctx2) => {
581
- const view = ctx2.get(editorViewCtx);
582
- const { dispatch, state } = view;
583
- const command = clearContentAndSetBlockType(headingSchema.type(ctx2), {
584
- level: 6
567
+ if (((_S = config == null ? void 0 : config.textGroup) == null ? void 0 : _S.h6) !== null) {
568
+ textGroup.addItem("h6", {
569
+ label: (_V = (_U = (_T = config == null ? void 0 : config.textGroup) == null ? void 0 : _T.h6) == null ? void 0 : _U.label) != null ? _V : "Heading 6",
570
+ icon: (_Y = (_X = (_W = config == null ? void 0 : config.textGroup) == null ? void 0 : _W.h6) == null ? void 0 : _X.icon) != null ? _Y : h6Icon,
571
+ onRun: (ctx2) => {
572
+ const commands = ctx2.get(commandsCtx);
573
+ const heading = headingSchema.type(ctx2);
574
+ commands.call(clearTextInCurrentBlockCommand.key);
575
+ commands.call(setBlockTypeCommand.key, {
576
+ nodeType: heading,
577
+ attrs: {
578
+ level: 6
579
+ }
580
+ });
581
+ }
585
582
  });
586
- command(state, dispatch);
587
583
  }
588
- }).addItem("quote", {
589
- label: (_p = config == null ? void 0 : config.slashMenuQuoteLabel) != null ? _p : "Quote",
590
- icon: (_q = config == null ? void 0 : config.slashMenuQuoteIcon) != null ? _q : quoteIcon,
591
- onRun: (ctx2) => {
592
- const view = ctx2.get(editorViewCtx);
593
- const { dispatch, state } = view;
594
- const command = clearContentAndWrapInBlockType(
595
- blockquoteSchema.type(ctx2)
596
- );
597
- command(state, dispatch);
584
+ if (((_Z = config == null ? void 0 : config.textGroup) == null ? void 0 : _Z.quote) !== null) {
585
+ textGroup.addItem("quote", {
586
+ label: (_aa = (_$ = (__ = config == null ? void 0 : config.textGroup) == null ? void 0 : __.quote) == null ? void 0 : _$.label) != null ? _aa : "Quote",
587
+ icon: (_da = (_ca = (_ba = config == null ? void 0 : config.textGroup) == null ? void 0 : _ba.quote) == null ? void 0 : _ca.icon) != null ? _da : quoteIcon,
588
+ onRun: (ctx2) => {
589
+ const commands = ctx2.get(commandsCtx);
590
+ const blockquote = blockquoteSchema.type(ctx2);
591
+ commands.call(clearTextInCurrentBlockCommand.key);
592
+ commands.call(wrapInBlockTypeCommand.key, {
593
+ nodeType: blockquote
594
+ });
595
+ }
596
+ });
598
597
  }
599
- }).addItem("divider", {
600
- label: (_r = config == null ? void 0 : config.slashMenuDividerLabel) != null ? _r : "Divider",
601
- icon: (_s = config == null ? void 0 : config.slashMenuDividerIcon) != null ? _s : dividerIcon,
602
- onRun: (ctx2) => {
603
- const view = ctx2.get(editorViewCtx);
604
- const { dispatch, state } = view;
605
- const command = clearContentAndAddBlockType(hrSchema.type(ctx2));
606
- command(state, dispatch);
598
+ if (((_ea = config == null ? void 0 : config.textGroup) == null ? void 0 : _ea.divider) !== null) {
599
+ textGroup.addItem("divider", {
600
+ label: (_ha = (_ga = (_fa = config == null ? void 0 : config.textGroup) == null ? void 0 : _fa.divider) == null ? void 0 : _ga.label) != null ? _ha : "Divider",
601
+ icon: (_ka = (_ja = (_ia = config == null ? void 0 : config.textGroup) == null ? void 0 : _ia.divider) == null ? void 0 : _ja.icon) != null ? _ka : dividerIcon,
602
+ onRun: (ctx2) => {
603
+ const commands = ctx2.get(commandsCtx);
604
+ const hr = hrSchema.type(ctx2);
605
+ commands.call(clearTextInCurrentBlockCommand.key);
606
+ commands.call(addBlockTypeCommand.key, {
607
+ nodeType: hr
608
+ });
609
+ }
610
+ });
607
611
  }
608
- });
609
- groupBuilder.addGroup("list", (_t = config == null ? void 0 : config.slashMenuListGroupLabel) != null ? _t : "List").addItem("bullet-list", {
610
- label: (_u = config == null ? void 0 : config.slashMenuBulletListLabel) != null ? _u : "Bullet List",
611
- icon: (_v = config == null ? void 0 : config.slashMenuBulletListIcon) != null ? _v : bulletListIcon,
612
- onRun: (ctx2) => {
613
- const view = ctx2.get(editorViewCtx);
614
- const { dispatch, state } = view;
615
- const command = clearContentAndWrapInBlockType(
616
- bulletListSchema.type(ctx2)
617
- );
618
- command(state, dispatch);
612
+ }
613
+ if ((config == null ? void 0 : config.listGroup) !== null) {
614
+ const listGroup = groupBuilder.addGroup(
615
+ "list",
616
+ (_ma = (_la = config == null ? void 0 : config.listGroup) == null ? void 0 : _la.label) != null ? _ma : "List"
617
+ );
618
+ if (((_na = config == null ? void 0 : config.listGroup) == null ? void 0 : _na.bulletList) !== null) {
619
+ listGroup.addItem("bullet-list", {
620
+ label: (_qa = (_pa = (_oa = config == null ? void 0 : config.listGroup) == null ? void 0 : _oa.bulletList) == null ? void 0 : _pa.label) != null ? _qa : "Bullet List",
621
+ icon: (_ta = (_sa = (_ra = config == null ? void 0 : config.listGroup) == null ? void 0 : _ra.bulletList) == null ? void 0 : _sa.icon) != null ? _ta : bulletListIcon,
622
+ onRun: (ctx2) => {
623
+ const commands = ctx2.get(commandsCtx);
624
+ const bulletList = bulletListSchema.type(ctx2);
625
+ commands.call(clearTextInCurrentBlockCommand.key);
626
+ commands.call(wrapInBlockTypeCommand.key, {
627
+ nodeType: bulletList
628
+ });
629
+ }
630
+ });
619
631
  }
620
- }).addItem("ordered-list", {
621
- label: (_w = config == null ? void 0 : config.slashMenuOrderedListLabel) != null ? _w : "Ordered List",
622
- icon: (_x = config == null ? void 0 : config.slashMenuOrderedListIcon) != null ? _x : orderedListIcon,
623
- onRun: (ctx2) => {
624
- const view = ctx2.get(editorViewCtx);
625
- const { dispatch, state } = view;
626
- const command = clearContentAndWrapInBlockType(
627
- orderedListSchema.type(ctx2)
628
- );
629
- command(state, dispatch);
632
+ if (((_ua = config == null ? void 0 : config.listGroup) == null ? void 0 : _ua.orderedList) !== null) {
633
+ listGroup.addItem("ordered-list", {
634
+ label: (_xa = (_wa = (_va = config == null ? void 0 : config.listGroup) == null ? void 0 : _va.orderedList) == null ? void 0 : _wa.label) != null ? _xa : "Ordered List",
635
+ icon: (_Aa = (_za = (_ya = config == null ? void 0 : config.listGroup) == null ? void 0 : _ya.orderedList) == null ? void 0 : _za.icon) != null ? _Aa : orderedListIcon,
636
+ onRun: (ctx2) => {
637
+ const commands = ctx2.get(commandsCtx);
638
+ const orderedList = orderedListSchema.type(ctx2);
639
+ commands.call(clearTextInCurrentBlockCommand.key);
640
+ commands.call(wrapInBlockTypeCommand.key, {
641
+ nodeType: orderedList
642
+ });
643
+ }
644
+ });
630
645
  }
631
- }).addItem("todo-list", {
632
- label: (_y = config == null ? void 0 : config.slashMenuTaskListLabel) != null ? _y : "Todo List",
633
- icon: (_z = config == null ? void 0 : config.slashMenuTaskListIcon) != null ? _z : todoListIcon,
634
- onRun: (ctx2) => {
635
- const view = ctx2.get(editorViewCtx);
636
- const { dispatch, state } = view;
637
- const command = clearContentAndWrapInBlockType(
638
- listItemSchema.type(ctx2),
639
- { checked: false }
640
- );
641
- command(state, dispatch);
646
+ if (((_Ba = config == null ? void 0 : config.listGroup) == null ? void 0 : _Ba.taskList) !== null) {
647
+ listGroup.addItem("task-list", {
648
+ label: (_Ea = (_Da = (_Ca = config == null ? void 0 : config.listGroup) == null ? void 0 : _Ca.taskList) == null ? void 0 : _Da.label) != null ? _Ea : "Task List",
649
+ icon: (_Ha = (_Ga = (_Fa = config == null ? void 0 : config.listGroup) == null ? void 0 : _Fa.taskList) == null ? void 0 : _Ga.icon) != null ? _Ha : todoListIcon,
650
+ onRun: (ctx2) => {
651
+ const commands = ctx2.get(commandsCtx);
652
+ const listItem = listItemSchema.type(ctx2);
653
+ commands.call(clearTextInCurrentBlockCommand.key);
654
+ commands.call(wrapInBlockTypeCommand.key, {
655
+ nodeType: listItem,
656
+ attrs: { checked: false }
657
+ });
658
+ }
659
+ });
642
660
  }
643
- });
644
- const advancedGroup = groupBuilder.addGroup(
645
- "advanced",
646
- (_A = config == null ? void 0 : config.slashMenuAdvancedGroupLabel) != null ? _A : "Advanced"
647
- );
648
- if (isImageBlockEnabled) {
649
- advancedGroup.addItem("image", {
650
- label: (_B = config == null ? void 0 : config.slashMenuImageLabel) != null ? _B : "Image",
651
- icon: (_C = config == null ? void 0 : config.slashMenuImageIcon) != null ? _C : imageIcon,
652
- onRun: (ctx2) => {
653
- const view = ctx2.get(editorViewCtx);
654
- const { dispatch, state } = view;
655
- const command = clearContentAndAddBlockType(imageBlockSchema.type(ctx2));
656
- command(state, dispatch);
657
- }
658
- });
659
661
  }
660
- advancedGroup.addItem("code", {
661
- label: (_D = config == null ? void 0 : config.slashMenuCodeBlockLabel) != null ? _D : "Code",
662
- icon: (_E = config == null ? void 0 : config.slashMenuCodeBlockIcon) != null ? _E : codeIcon,
663
- onRun: (ctx2) => {
664
- const view = ctx2.get(editorViewCtx);
665
- const { dispatch, state } = view;
666
- const command = clearContentAndAddBlockType(codeBlockSchema.type(ctx2));
667
- command(state, dispatch);
662
+ if ((config == null ? void 0 : config.advancedGroup) !== null) {
663
+ const advancedGroup = groupBuilder.addGroup(
664
+ "advanced",
665
+ (_Ja = (_Ia = config == null ? void 0 : config.advancedGroup) == null ? void 0 : _Ia.label) != null ? _Ja : "Advanced"
666
+ );
667
+ if (((_Ka = config == null ? void 0 : config.advancedGroup) == null ? void 0 : _Ka.image) !== null && isImageBlockEnabled) {
668
+ advancedGroup.addItem("image", {
669
+ label: (_Na = (_Ma = (_La = config == null ? void 0 : config.advancedGroup) == null ? void 0 : _La.image) == null ? void 0 : _Ma.label) != null ? _Na : "Image",
670
+ icon: (_Qa = (_Pa = (_Oa = config == null ? void 0 : config.advancedGroup) == null ? void 0 : _Oa.image) == null ? void 0 : _Pa.icon) != null ? _Qa : imageIcon,
671
+ onRun: (ctx2) => {
672
+ const commands = ctx2.get(commandsCtx);
673
+ const imageBlock = imageBlockSchema.type(ctx2);
674
+ commands.call(clearTextInCurrentBlockCommand.key);
675
+ commands.call(addBlockTypeCommand.key, {
676
+ nodeType: imageBlock
677
+ });
678
+ }
679
+ });
680
+ }
681
+ if (((_Ra = config == null ? void 0 : config.advancedGroup) == null ? void 0 : _Ra.codeBlock) !== null) {
682
+ advancedGroup.addItem("code", {
683
+ label: (_Ua = (_Ta = (_Sa = config == null ? void 0 : config.advancedGroup) == null ? void 0 : _Sa.codeBlock) == null ? void 0 : _Ta.label) != null ? _Ua : "Code",
684
+ icon: (_Xa = (_Wa = (_Va = config == null ? void 0 : config.advancedGroup) == null ? void 0 : _Va.codeBlock) == null ? void 0 : _Wa.icon) != null ? _Xa : codeIcon,
685
+ onRun: (ctx2) => {
686
+ const commands = ctx2.get(commandsCtx);
687
+ const codeBlock = codeBlockSchema.type(ctx2);
688
+ commands.call(clearTextInCurrentBlockCommand.key);
689
+ commands.call(setBlockTypeCommand.key, {
690
+ nodeType: codeBlock
691
+ });
692
+ }
693
+ });
694
+ }
695
+ if (((_Ya = config == null ? void 0 : config.advancedGroup) == null ? void 0 : _Ya.table) !== null && isTableEnabled) {
696
+ advancedGroup.addItem("table", {
697
+ label: (_$a = (__a = (_Za = config == null ? void 0 : config.advancedGroup) == null ? void 0 : _Za.table) == null ? void 0 : __a.label) != null ? _$a : "Table",
698
+ icon: (_cb = (_bb = (_ab = config == null ? void 0 : config.advancedGroup) == null ? void 0 : _ab.table) == null ? void 0 : _bb.icon) != null ? _cb : tableIcon,
699
+ onRun: (ctx2) => {
700
+ const commands = ctx2.get(commandsCtx);
701
+ const view = ctx2.get(editorViewCtx);
702
+ commands.call(clearTextInCurrentBlockCommand.key);
703
+ const { from } = view.state.selection;
704
+ commands.call(addBlockTypeCommand.key, {
705
+ nodeType: createTable(ctx2, 3, 3)
706
+ });
707
+ commands.call(selectTextNearPosCommand.key, {
708
+ pos: from
709
+ });
710
+ }
711
+ });
712
+ }
713
+ if (((_db = config == null ? void 0 : config.advancedGroup) == null ? void 0 : _db.math) !== null && isLatexEnabled) {
714
+ advancedGroup.addItem("math", {
715
+ label: (_gb = (_fb = (_eb = config == null ? void 0 : config.advancedGroup) == null ? void 0 : _eb.math) == null ? void 0 : _fb.label) != null ? _gb : "Math",
716
+ icon: (_jb = (_ib = (_hb = config == null ? void 0 : config.advancedGroup) == null ? void 0 : _hb.math) == null ? void 0 : _ib.icon) != null ? _jb : functionsIcon,
717
+ onRun: (ctx2) => {
718
+ const commands = ctx2.get(commandsCtx);
719
+ const codeBlock = codeBlockSchema.type(ctx2);
720
+ commands.call(clearTextInCurrentBlockCommand.key);
721
+ commands.call(addBlockTypeCommand.key, {
722
+ nodeType: codeBlock,
723
+ attrs: { language: "LaTex" }
724
+ });
725
+ }
726
+ });
668
727
  }
669
- });
670
- if (isTableEnabled) {
671
- advancedGroup.addItem("table", {
672
- label: (_F = config == null ? void 0 : config.slashMenuTableLabel) != null ? _F : "Table",
673
- icon: (_G = config == null ? void 0 : config.slashMenuTableIcon) != null ? _G : tableIcon,
674
- onRun: (ctx2) => {
675
- const view = ctx2.get(editorViewCtx);
676
- const { dispatch, state } = view;
677
- let { tr } = state;
678
- tr = clearRange(tr);
679
- const from = tr.selection.from;
680
- const table = createTable(ctx2, 3, 3);
681
- tr = tr.replaceSelectionWith(table);
682
- dispatch(tr);
683
- requestAnimationFrame(() => {
684
- const docSize = view.state.doc.content.size;
685
- const $pos = view.state.doc.resolve(
686
- from > docSize ? docSize : from < 0 ? 0 : from
687
- );
688
- const selection = TextSelection.near($pos);
689
- const tr2 = view.state.tr;
690
- tr2.setSelection(selection);
691
- dispatch(tr2.scrollIntoView());
692
- });
693
- }
694
- });
695
- }
696
- if (isLatexEnabled) {
697
- advancedGroup.addItem("math", {
698
- label: (_H = config == null ? void 0 : config.slashMenuMathLabel) != null ? _H : "Math",
699
- icon: (_I = config == null ? void 0 : config.slashMenuMathIcon) != null ? _I : functionsIcon,
700
- onRun: (ctx2) => {
701
- const view = ctx2.get(editorViewCtx);
702
- const { dispatch, state } = view;
703
- const command = clearContentAndAddBlockType(codeBlockSchema.type(ctx2), {
704
- language: "LaTex"
705
- });
706
- command(state, dispatch);
707
- }
708
- });
709
728
  }
710
- (_J = config == null ? void 0 : config.buildMenu) == null ? void 0 : _J.call(config, groupBuilder);
729
+ (_kb = config == null ? void 0 : config.buildMenu) == null ? void 0 : _kb.call(config, groupBuilder);
711
730
  let groups = groupBuilder.build();
712
731
  if (filter) {
713
732
  groups = groups.map((group) => {