@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
package/lib/cjs/index.js CHANGED
@@ -15,7 +15,6 @@ var utils = require('@milkdown/kit/utils');
15
15
  var component = require('@milkdown/kit/component');
16
16
  var imageBlock$1 = require('@milkdown/kit/component/image-block');
17
17
  var gfm = require('@milkdown/kit/preset/gfm');
18
- var transform = require('@milkdown/kit/prose/transform');
19
18
  var commands = require('@codemirror/commands');
20
19
  var view = require('@codemirror/view');
21
20
  var codeBlock = require('@milkdown/kit/component/code-block');
@@ -790,7 +789,7 @@ class GroupBuilder {
790
789
  const groupInstance = {
791
790
  group,
792
791
  addItem: (key, item) => {
793
- const data = { key, ...item };
792
+ const data = { ...item, key };
794
793
  group.items.push(data);
795
794
  return groupInstance;
796
795
  },
@@ -824,260 +823,280 @@ class GroupBuilder {
824
823
  _groups = new WeakMap();
825
824
  _getGroupInstance = new WeakMap();
826
825
 
827
- function clearRange(tr) {
828
- const { $from, $to } = tr.selection;
829
- const { pos: from } = $from;
830
- const { pos: to } = $to;
831
- tr = tr.deleteRange(from - $from.node().content.size, to);
832
- return tr;
833
- }
834
- function setBlockType(tr, nodeType, attrs = null) {
835
- const { from, to } = tr.selection;
836
- return tr.setBlockType(from, to, nodeType, attrs);
837
- }
838
- function wrapInBlockType(tr, nodeType, attrs = null) {
839
- const { $from, $to } = tr.selection;
840
- const range = $from.blockRange($to);
841
- const wrapping = range && transform.findWrapping(range, nodeType, attrs);
842
- if (!wrapping) return null;
843
- return tr.wrap(range, wrapping);
844
- }
845
- function addBlockType(tr, nodeType, attrs = null) {
846
- const node = nodeType.createAndFill(attrs);
847
- if (!node) return null;
848
- return tr.replaceSelectionWith(node);
849
- }
850
- function clearContentAndSetBlockType(nodeType, attrs = null) {
851
- return (state, dispatch) => {
852
- if (dispatch) {
853
- const tr = setBlockType(clearRange(state.tr), nodeType, attrs);
854
- dispatch(tr.scrollIntoView());
855
- }
856
- return true;
857
- };
858
- }
859
- function clearContentAndWrapInBlockType(nodeType, attrs = null) {
860
- return (state, dispatch) => {
861
- const tr = wrapInBlockType(clearRange(state.tr), nodeType, attrs);
862
- if (!tr) return false;
863
- if (dispatch) dispatch(tr.scrollIntoView());
864
- return true;
865
- };
866
- }
867
- function clearContentAndAddBlockType(nodeType, attrs = null) {
868
- return (state, dispatch) => {
869
- const tr = addBlockType(clearRange(state.tr), nodeType, attrs);
870
- if (!tr) return false;
871
- if (dispatch) dispatch(tr.scrollIntoView());
872
- return true;
873
- };
874
- }
875
-
876
- function getGroups(filter, config, ctx) {
877
- 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;
826
+ function getGroups$1(filter, config, ctx) {
827
+ 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;
878
828
  const flags = ctx && useCrepeFeatures(ctx).get();
879
829
  const isLatexEnabled = flags == null ? void 0 : flags.includes(CrepeFeature.Latex);
880
830
  const isImageBlockEnabled = flags == null ? void 0 : flags.includes(CrepeFeature.ImageBlock);
881
831
  const isTableEnabled = flags == null ? void 0 : flags.includes(CrepeFeature.Table);
882
832
  const groupBuilder = new GroupBuilder();
883
- groupBuilder.addGroup("text", (_a = config == null ? void 0 : config.slashMenuTextGroupLabel) != null ? _a : "Text").addItem("text", {
884
- label: (_b = config == null ? void 0 : config.slashMenuTextLabel) != null ? _b : "Text",
885
- icon: (_c = config == null ? void 0 : config.slashMenuTextIcon) != null ? _c : textIcon,
886
- onRun: (ctx2) => {
887
- const view = ctx2.get(core.editorViewCtx);
888
- const { dispatch, state } = view;
889
- const command = clearContentAndSetBlockType(commonmark.paragraphSchema.type(ctx2));
890
- command(state, dispatch);
833
+ if ((config == null ? void 0 : config.textGroup) !== null) {
834
+ const textGroup = groupBuilder.addGroup(
835
+ "text",
836
+ (_b = (_a = config == null ? void 0 : config.textGroup) == null ? void 0 : _a.label) != null ? _b : "Text"
837
+ );
838
+ if (((_c = config == null ? void 0 : config.textGroup) == null ? void 0 : _c.text) !== null) {
839
+ textGroup.addItem("text", {
840
+ label: (_f = (_e = (_d = config == null ? void 0 : config.textGroup) == null ? void 0 : _d.text) == null ? void 0 : _e.label) != null ? _f : "Text",
841
+ icon: (_i = (_h = (_g = config == null ? void 0 : config.textGroup) == null ? void 0 : _g.text) == null ? void 0 : _h.icon) != null ? _i : textIcon,
842
+ onRun: (ctx2) => {
843
+ const commands = ctx2.get(core.commandsCtx);
844
+ const paragraph = commonmark.paragraphSchema.type(ctx2);
845
+ commands.call(commonmark.clearTextInCurrentBlockCommand.key);
846
+ commands.call(commonmark.setBlockTypeCommand.key, {
847
+ nodeType: paragraph
848
+ });
849
+ }
850
+ });
891
851
  }
892
- }).addItem("h1", {
893
- label: (_d = config == null ? void 0 : config.slashMenuH1Label) != null ? _d : "Heading 1",
894
- icon: (_e = config == null ? void 0 : config.slashMenuH1Icon) != null ? _e : h1Icon,
895
- onRun: (ctx2) => {
896
- const view = ctx2.get(core.editorViewCtx);
897
- const { dispatch, state } = view;
898
- const command = clearContentAndSetBlockType(commonmark.headingSchema.type(ctx2), {
899
- level: 1
852
+ if (((_j = config == null ? void 0 : config.textGroup) == null ? void 0 : _j.h1) !== null) {
853
+ textGroup.addItem("h1", {
854
+ label: (_m = (_l = (_k = config == null ? void 0 : config.textGroup) == null ? void 0 : _k.h1) == null ? void 0 : _l.label) != null ? _m : "Heading 1",
855
+ icon: (_p = (_o = (_n = config == null ? void 0 : config.textGroup) == null ? void 0 : _n.h1) == null ? void 0 : _o.icon) != null ? _p : h1Icon,
856
+ onRun: (ctx2) => {
857
+ const commands = ctx2.get(core.commandsCtx);
858
+ const heading = commonmark.headingSchema.type(ctx2);
859
+ commands.call(commonmark.clearTextInCurrentBlockCommand.key);
860
+ commands.call(commonmark.setBlockTypeCommand.key, {
861
+ nodeType: heading,
862
+ attrs: {
863
+ level: 1
864
+ }
865
+ });
866
+ }
900
867
  });
901
- command(state, dispatch);
902
868
  }
903
- }).addItem("h2", {
904
- label: (_f = config == null ? void 0 : config.slashMenuH2Label) != null ? _f : "Heading 2",
905
- icon: (_g = config == null ? void 0 : config.slashMenuH2Icon) != null ? _g : h2Icon,
906
- onRun: (ctx2) => {
907
- const view = ctx2.get(core.editorViewCtx);
908
- const { dispatch, state } = view;
909
- const command = clearContentAndSetBlockType(commonmark.headingSchema.type(ctx2), {
910
- level: 2
869
+ if (((_q = config == null ? void 0 : config.textGroup) == null ? void 0 : _q.h2) !== null) {
870
+ textGroup.addItem("h2", {
871
+ label: (_t = (_s = (_r = config == null ? void 0 : config.textGroup) == null ? void 0 : _r.h2) == null ? void 0 : _s.label) != null ? _t : "Heading 2",
872
+ icon: (_w = (_v = (_u = config == null ? void 0 : config.textGroup) == null ? void 0 : _u.h2) == null ? void 0 : _v.icon) != null ? _w : h2Icon,
873
+ onRun: (ctx2) => {
874
+ const commands = ctx2.get(core.commandsCtx);
875
+ const heading = commonmark.headingSchema.type(ctx2);
876
+ commands.call(commonmark.clearTextInCurrentBlockCommand.key);
877
+ commands.call(commonmark.setBlockTypeCommand.key, {
878
+ nodeType: heading,
879
+ attrs: {
880
+ level: 2
881
+ }
882
+ });
883
+ }
911
884
  });
912
- command(state, dispatch);
913
885
  }
914
- }).addItem("h3", {
915
- label: (_h = config == null ? void 0 : config.slashMenuH3Label) != null ? _h : "Heading 3",
916
- icon: (_i = config == null ? void 0 : config.slashMenuH3Icon) != null ? _i : h3Icon,
917
- onRun: (ctx2) => {
918
- const view = ctx2.get(core.editorViewCtx);
919
- const { dispatch, state } = view;
920
- const command = clearContentAndSetBlockType(commonmark.headingSchema.type(ctx2), {
921
- level: 3
886
+ if (((_x = config == null ? void 0 : config.textGroup) == null ? void 0 : _x.h3) !== null) {
887
+ textGroup.addItem("h3", {
888
+ label: (_A = (_z = (_y = config == null ? void 0 : config.textGroup) == null ? void 0 : _y.h3) == null ? void 0 : _z.label) != null ? _A : "Heading 3",
889
+ icon: (_D = (_C = (_B = config == null ? void 0 : config.textGroup) == null ? void 0 : _B.h3) == null ? void 0 : _C.icon) != null ? _D : h3Icon,
890
+ onRun: (ctx2) => {
891
+ const commands = ctx2.get(core.commandsCtx);
892
+ const heading = commonmark.headingSchema.type(ctx2);
893
+ commands.call(commonmark.clearTextInCurrentBlockCommand.key);
894
+ commands.call(commonmark.setBlockTypeCommand.key, {
895
+ nodeType: heading,
896
+ attrs: {
897
+ level: 3
898
+ }
899
+ });
900
+ }
922
901
  });
923
- command(state, dispatch);
924
902
  }
925
- }).addItem("h4", {
926
- label: (_j = config == null ? void 0 : config.slashMenuH4Label) != null ? _j : "Heading 4",
927
- icon: (_k = config == null ? void 0 : config.slashMenuH4Icon) != null ? _k : h4Icon,
928
- onRun: (ctx2) => {
929
- const view = ctx2.get(core.editorViewCtx);
930
- const { dispatch, state } = view;
931
- const command = clearContentAndSetBlockType(commonmark.headingSchema.type(ctx2), {
932
- level: 4
903
+ if (((_E = config == null ? void 0 : config.textGroup) == null ? void 0 : _E.h4) !== null) {
904
+ textGroup.addItem("h4", {
905
+ label: (_H = (_G = (_F = config == null ? void 0 : config.textGroup) == null ? void 0 : _F.h4) == null ? void 0 : _G.label) != null ? _H : "Heading 4",
906
+ icon: (_K = (_J = (_I = config == null ? void 0 : config.textGroup) == null ? void 0 : _I.h4) == null ? void 0 : _J.icon) != null ? _K : h4Icon,
907
+ onRun: (ctx2) => {
908
+ const commands = ctx2.get(core.commandsCtx);
909
+ const heading = commonmark.headingSchema.type(ctx2);
910
+ commands.call(commonmark.clearTextInCurrentBlockCommand.key);
911
+ commands.call(commonmark.setBlockTypeCommand.key, {
912
+ nodeType: heading,
913
+ attrs: {
914
+ level: 4
915
+ }
916
+ });
917
+ }
933
918
  });
934
- command(state, dispatch);
935
919
  }
936
- }).addItem("h5", {
937
- label: (_l = config == null ? void 0 : config.slashMenuH5Label) != null ? _l : "Heading 5",
938
- icon: (_m = config == null ? void 0 : config.slashMenuH5Icon) != null ? _m : h5Icon,
939
- onRun: (ctx2) => {
940
- const view = ctx2.get(core.editorViewCtx);
941
- const { dispatch, state } = view;
942
- const command = clearContentAndSetBlockType(commonmark.headingSchema.type(ctx2), {
943
- level: 5
920
+ if (((_L = config == null ? void 0 : config.textGroup) == null ? void 0 : _L.h5) !== null) {
921
+ textGroup.addItem("h5", {
922
+ label: (_O = (_N = (_M = config == null ? void 0 : config.textGroup) == null ? void 0 : _M.h5) == null ? void 0 : _N.label) != null ? _O : "Heading 5",
923
+ icon: (_R = (_Q = (_P = config == null ? void 0 : config.textGroup) == null ? void 0 : _P.h5) == null ? void 0 : _Q.icon) != null ? _R : h5Icon,
924
+ onRun: (ctx2) => {
925
+ const commands = ctx2.get(core.commandsCtx);
926
+ const heading = commonmark.headingSchema.type(ctx2);
927
+ commands.call(commonmark.clearTextInCurrentBlockCommand.key);
928
+ commands.call(commonmark.setBlockTypeCommand.key, {
929
+ nodeType: heading,
930
+ attrs: {
931
+ level: 5
932
+ }
933
+ });
934
+ }
944
935
  });
945
- command(state, dispatch);
946
936
  }
947
- }).addItem("h6", {
948
- label: (_n = config == null ? void 0 : config.slashMenuH6Label) != null ? _n : "Heading 6",
949
- icon: (_o = config == null ? void 0 : config.slashMenuH6Icon) != null ? _o : h6Icon,
950
- onRun: (ctx2) => {
951
- const view = ctx2.get(core.editorViewCtx);
952
- const { dispatch, state } = view;
953
- const command = clearContentAndSetBlockType(commonmark.headingSchema.type(ctx2), {
954
- level: 6
937
+ if (((_S = config == null ? void 0 : config.textGroup) == null ? void 0 : _S.h6) !== null) {
938
+ textGroup.addItem("h6", {
939
+ label: (_V = (_U = (_T = config == null ? void 0 : config.textGroup) == null ? void 0 : _T.h6) == null ? void 0 : _U.label) != null ? _V : "Heading 6",
940
+ icon: (_Y = (_X = (_W = config == null ? void 0 : config.textGroup) == null ? void 0 : _W.h6) == null ? void 0 : _X.icon) != null ? _Y : h6Icon,
941
+ onRun: (ctx2) => {
942
+ const commands = ctx2.get(core.commandsCtx);
943
+ const heading = commonmark.headingSchema.type(ctx2);
944
+ commands.call(commonmark.clearTextInCurrentBlockCommand.key);
945
+ commands.call(commonmark.setBlockTypeCommand.key, {
946
+ nodeType: heading,
947
+ attrs: {
948
+ level: 6
949
+ }
950
+ });
951
+ }
955
952
  });
956
- command(state, dispatch);
957
953
  }
958
- }).addItem("quote", {
959
- label: (_p = config == null ? void 0 : config.slashMenuQuoteLabel) != null ? _p : "Quote",
960
- icon: (_q = config == null ? void 0 : config.slashMenuQuoteIcon) != null ? _q : quoteIcon,
961
- onRun: (ctx2) => {
962
- const view = ctx2.get(core.editorViewCtx);
963
- const { dispatch, state } = view;
964
- const command = clearContentAndWrapInBlockType(
965
- commonmark.blockquoteSchema.type(ctx2)
966
- );
967
- command(state, dispatch);
954
+ if (((_Z = config == null ? void 0 : config.textGroup) == null ? void 0 : _Z.quote) !== null) {
955
+ textGroup.addItem("quote", {
956
+ label: (_aa = (_$ = (__ = config == null ? void 0 : config.textGroup) == null ? void 0 : __.quote) == null ? void 0 : _$.label) != null ? _aa : "Quote",
957
+ icon: (_da = (_ca = (_ba = config == null ? void 0 : config.textGroup) == null ? void 0 : _ba.quote) == null ? void 0 : _ca.icon) != null ? _da : quoteIcon,
958
+ onRun: (ctx2) => {
959
+ const commands = ctx2.get(core.commandsCtx);
960
+ const blockquote = commonmark.blockquoteSchema.type(ctx2);
961
+ commands.call(commonmark.clearTextInCurrentBlockCommand.key);
962
+ commands.call(commonmark.wrapInBlockTypeCommand.key, {
963
+ nodeType: blockquote
964
+ });
965
+ }
966
+ });
968
967
  }
969
- }).addItem("divider", {
970
- label: (_r = config == null ? void 0 : config.slashMenuDividerLabel) != null ? _r : "Divider",
971
- icon: (_s = config == null ? void 0 : config.slashMenuDividerIcon) != null ? _s : dividerIcon,
972
- onRun: (ctx2) => {
973
- const view = ctx2.get(core.editorViewCtx);
974
- const { dispatch, state } = view;
975
- const command = clearContentAndAddBlockType(commonmark.hrSchema.type(ctx2));
976
- command(state, dispatch);
968
+ if (((_ea = config == null ? void 0 : config.textGroup) == null ? void 0 : _ea.divider) !== null) {
969
+ textGroup.addItem("divider", {
970
+ label: (_ha = (_ga = (_fa = config == null ? void 0 : config.textGroup) == null ? void 0 : _fa.divider) == null ? void 0 : _ga.label) != null ? _ha : "Divider",
971
+ icon: (_ka = (_ja = (_ia = config == null ? void 0 : config.textGroup) == null ? void 0 : _ia.divider) == null ? void 0 : _ja.icon) != null ? _ka : dividerIcon,
972
+ onRun: (ctx2) => {
973
+ const commands = ctx2.get(core.commandsCtx);
974
+ const hr = commonmark.hrSchema.type(ctx2);
975
+ commands.call(commonmark.clearTextInCurrentBlockCommand.key);
976
+ commands.call(commonmark.addBlockTypeCommand.key, {
977
+ nodeType: hr
978
+ });
979
+ }
980
+ });
977
981
  }
978
- });
979
- groupBuilder.addGroup("list", (_t = config == null ? void 0 : config.slashMenuListGroupLabel) != null ? _t : "List").addItem("bullet-list", {
980
- label: (_u = config == null ? void 0 : config.slashMenuBulletListLabel) != null ? _u : "Bullet List",
981
- icon: (_v = config == null ? void 0 : config.slashMenuBulletListIcon) != null ? _v : bulletListIcon,
982
- onRun: (ctx2) => {
983
- const view = ctx2.get(core.editorViewCtx);
984
- const { dispatch, state } = view;
985
- const command = clearContentAndWrapInBlockType(
986
- commonmark.bulletListSchema.type(ctx2)
987
- );
988
- command(state, dispatch);
982
+ }
983
+ if ((config == null ? void 0 : config.listGroup) !== null) {
984
+ const listGroup = groupBuilder.addGroup(
985
+ "list",
986
+ (_ma = (_la = config == null ? void 0 : config.listGroup) == null ? void 0 : _la.label) != null ? _ma : "List"
987
+ );
988
+ if (((_na = config == null ? void 0 : config.listGroup) == null ? void 0 : _na.bulletList) !== null) {
989
+ listGroup.addItem("bullet-list", {
990
+ label: (_qa = (_pa = (_oa = config == null ? void 0 : config.listGroup) == null ? void 0 : _oa.bulletList) == null ? void 0 : _pa.label) != null ? _qa : "Bullet List",
991
+ icon: (_ta = (_sa = (_ra = config == null ? void 0 : config.listGroup) == null ? void 0 : _ra.bulletList) == null ? void 0 : _sa.icon) != null ? _ta : bulletListIcon,
992
+ onRun: (ctx2) => {
993
+ const commands = ctx2.get(core.commandsCtx);
994
+ const bulletList = commonmark.bulletListSchema.type(ctx2);
995
+ commands.call(commonmark.clearTextInCurrentBlockCommand.key);
996
+ commands.call(commonmark.wrapInBlockTypeCommand.key, {
997
+ nodeType: bulletList
998
+ });
999
+ }
1000
+ });
989
1001
  }
990
- }).addItem("ordered-list", {
991
- label: (_w = config == null ? void 0 : config.slashMenuOrderedListLabel) != null ? _w : "Ordered List",
992
- icon: (_x = config == null ? void 0 : config.slashMenuOrderedListIcon) != null ? _x : orderedListIcon,
993
- onRun: (ctx2) => {
994
- const view = ctx2.get(core.editorViewCtx);
995
- const { dispatch, state } = view;
996
- const command = clearContentAndWrapInBlockType(
997
- commonmark.orderedListSchema.type(ctx2)
998
- );
999
- command(state, dispatch);
1002
+ if (((_ua = config == null ? void 0 : config.listGroup) == null ? void 0 : _ua.orderedList) !== null) {
1003
+ listGroup.addItem("ordered-list", {
1004
+ label: (_xa = (_wa = (_va = config == null ? void 0 : config.listGroup) == null ? void 0 : _va.orderedList) == null ? void 0 : _wa.label) != null ? _xa : "Ordered List",
1005
+ icon: (_Aa = (_za = (_ya = config == null ? void 0 : config.listGroup) == null ? void 0 : _ya.orderedList) == null ? void 0 : _za.icon) != null ? _Aa : orderedListIcon,
1006
+ onRun: (ctx2) => {
1007
+ const commands = ctx2.get(core.commandsCtx);
1008
+ const orderedList = commonmark.orderedListSchema.type(ctx2);
1009
+ commands.call(commonmark.clearTextInCurrentBlockCommand.key);
1010
+ commands.call(commonmark.wrapInBlockTypeCommand.key, {
1011
+ nodeType: orderedList
1012
+ });
1013
+ }
1014
+ });
1000
1015
  }
1001
- }).addItem("todo-list", {
1002
- label: (_y = config == null ? void 0 : config.slashMenuTaskListLabel) != null ? _y : "Todo List",
1003
- icon: (_z = config == null ? void 0 : config.slashMenuTaskListIcon) != null ? _z : todoListIcon,
1004
- onRun: (ctx2) => {
1005
- const view = ctx2.get(core.editorViewCtx);
1006
- const { dispatch, state } = view;
1007
- const command = clearContentAndWrapInBlockType(
1008
- commonmark.listItemSchema.type(ctx2),
1009
- { checked: false }
1010
- );
1011
- command(state, dispatch);
1016
+ if (((_Ba = config == null ? void 0 : config.listGroup) == null ? void 0 : _Ba.taskList) !== null) {
1017
+ listGroup.addItem("task-list", {
1018
+ label: (_Ea = (_Da = (_Ca = config == null ? void 0 : config.listGroup) == null ? void 0 : _Ca.taskList) == null ? void 0 : _Da.label) != null ? _Ea : "Task List",
1019
+ icon: (_Ha = (_Ga = (_Fa = config == null ? void 0 : config.listGroup) == null ? void 0 : _Fa.taskList) == null ? void 0 : _Ga.icon) != null ? _Ha : todoListIcon,
1020
+ onRun: (ctx2) => {
1021
+ const commands = ctx2.get(core.commandsCtx);
1022
+ const listItem = commonmark.listItemSchema.type(ctx2);
1023
+ commands.call(commonmark.clearTextInCurrentBlockCommand.key);
1024
+ commands.call(commonmark.wrapInBlockTypeCommand.key, {
1025
+ nodeType: listItem,
1026
+ attrs: { checked: false }
1027
+ });
1028
+ }
1029
+ });
1012
1030
  }
1013
- });
1014
- const advancedGroup = groupBuilder.addGroup(
1015
- "advanced",
1016
- (_A = config == null ? void 0 : config.slashMenuAdvancedGroupLabel) != null ? _A : "Advanced"
1017
- );
1018
- if (isImageBlockEnabled) {
1019
- advancedGroup.addItem("image", {
1020
- label: (_B = config == null ? void 0 : config.slashMenuImageLabel) != null ? _B : "Image",
1021
- icon: (_C = config == null ? void 0 : config.slashMenuImageIcon) != null ? _C : imageIcon,
1022
- onRun: (ctx2) => {
1023
- const view = ctx2.get(core.editorViewCtx);
1024
- const { dispatch, state } = view;
1025
- const command = clearContentAndAddBlockType(imageBlock$1.imageBlockSchema.type(ctx2));
1026
- command(state, dispatch);
1027
- }
1028
- });
1029
1031
  }
1030
- advancedGroup.addItem("code", {
1031
- label: (_D = config == null ? void 0 : config.slashMenuCodeBlockLabel) != null ? _D : "Code",
1032
- icon: (_E = config == null ? void 0 : config.slashMenuCodeBlockIcon) != null ? _E : codeIcon,
1033
- onRun: (ctx2) => {
1034
- const view = ctx2.get(core.editorViewCtx);
1035
- const { dispatch, state } = view;
1036
- const command = clearContentAndAddBlockType(commonmark.codeBlockSchema.type(ctx2));
1037
- command(state, dispatch);
1032
+ if ((config == null ? void 0 : config.advancedGroup) !== null) {
1033
+ const advancedGroup = groupBuilder.addGroup(
1034
+ "advanced",
1035
+ (_Ja = (_Ia = config == null ? void 0 : config.advancedGroup) == null ? void 0 : _Ia.label) != null ? _Ja : "Advanced"
1036
+ );
1037
+ if (((_Ka = config == null ? void 0 : config.advancedGroup) == null ? void 0 : _Ka.image) !== null && isImageBlockEnabled) {
1038
+ advancedGroup.addItem("image", {
1039
+ label: (_Na = (_Ma = (_La = config == null ? void 0 : config.advancedGroup) == null ? void 0 : _La.image) == null ? void 0 : _Ma.label) != null ? _Na : "Image",
1040
+ icon: (_Qa = (_Pa = (_Oa = config == null ? void 0 : config.advancedGroup) == null ? void 0 : _Oa.image) == null ? void 0 : _Pa.icon) != null ? _Qa : imageIcon,
1041
+ onRun: (ctx2) => {
1042
+ const commands = ctx2.get(core.commandsCtx);
1043
+ const imageBlock = imageBlock$1.imageBlockSchema.type(ctx2);
1044
+ commands.call(commonmark.clearTextInCurrentBlockCommand.key);
1045
+ commands.call(commonmark.addBlockTypeCommand.key, {
1046
+ nodeType: imageBlock
1047
+ });
1048
+ }
1049
+ });
1050
+ }
1051
+ if (((_Ra = config == null ? void 0 : config.advancedGroup) == null ? void 0 : _Ra.codeBlock) !== null) {
1052
+ advancedGroup.addItem("code", {
1053
+ label: (_Ua = (_Ta = (_Sa = config == null ? void 0 : config.advancedGroup) == null ? void 0 : _Sa.codeBlock) == null ? void 0 : _Ta.label) != null ? _Ua : "Code",
1054
+ icon: (_Xa = (_Wa = (_Va = config == null ? void 0 : config.advancedGroup) == null ? void 0 : _Va.codeBlock) == null ? void 0 : _Wa.icon) != null ? _Xa : codeIcon,
1055
+ onRun: (ctx2) => {
1056
+ const commands = ctx2.get(core.commandsCtx);
1057
+ const codeBlock = commonmark.codeBlockSchema.type(ctx2);
1058
+ commands.call(commonmark.clearTextInCurrentBlockCommand.key);
1059
+ commands.call(commonmark.setBlockTypeCommand.key, {
1060
+ nodeType: codeBlock
1061
+ });
1062
+ }
1063
+ });
1064
+ }
1065
+ if (((_Ya = config == null ? void 0 : config.advancedGroup) == null ? void 0 : _Ya.table) !== null && isTableEnabled) {
1066
+ advancedGroup.addItem("table", {
1067
+ label: (_$a = (__a = (_Za = config == null ? void 0 : config.advancedGroup) == null ? void 0 : _Za.table) == null ? void 0 : __a.label) != null ? _$a : "Table",
1068
+ icon: (_cb = (_bb = (_ab = config == null ? void 0 : config.advancedGroup) == null ? void 0 : _ab.table) == null ? void 0 : _bb.icon) != null ? _cb : tableIcon,
1069
+ onRun: (ctx2) => {
1070
+ const commands = ctx2.get(core.commandsCtx);
1071
+ const view = ctx2.get(core.editorViewCtx);
1072
+ commands.call(commonmark.clearTextInCurrentBlockCommand.key);
1073
+ const { from } = view.state.selection;
1074
+ commands.call(commonmark.addBlockTypeCommand.key, {
1075
+ nodeType: gfm.createTable(ctx2, 3, 3)
1076
+ });
1077
+ commands.call(commonmark.selectTextNearPosCommand.key, {
1078
+ pos: from
1079
+ });
1080
+ }
1081
+ });
1082
+ }
1083
+ if (((_db = config == null ? void 0 : config.advancedGroup) == null ? void 0 : _db.math) !== null && isLatexEnabled) {
1084
+ advancedGroup.addItem("math", {
1085
+ label: (_gb = (_fb = (_eb = config == null ? void 0 : config.advancedGroup) == null ? void 0 : _eb.math) == null ? void 0 : _fb.label) != null ? _gb : "Math",
1086
+ icon: (_jb = (_ib = (_hb = config == null ? void 0 : config.advancedGroup) == null ? void 0 : _hb.math) == null ? void 0 : _ib.icon) != null ? _jb : functionsIcon,
1087
+ onRun: (ctx2) => {
1088
+ const commands = ctx2.get(core.commandsCtx);
1089
+ const codeBlock = commonmark.codeBlockSchema.type(ctx2);
1090
+ commands.call(commonmark.clearTextInCurrentBlockCommand.key);
1091
+ commands.call(commonmark.addBlockTypeCommand.key, {
1092
+ nodeType: codeBlock,
1093
+ attrs: { language: "LaTex" }
1094
+ });
1095
+ }
1096
+ });
1038
1097
  }
1039
- });
1040
- if (isTableEnabled) {
1041
- advancedGroup.addItem("table", {
1042
- label: (_F = config == null ? void 0 : config.slashMenuTableLabel) != null ? _F : "Table",
1043
- icon: (_G = config == null ? void 0 : config.slashMenuTableIcon) != null ? _G : tableIcon,
1044
- onRun: (ctx2) => {
1045
- const view = ctx2.get(core.editorViewCtx);
1046
- const { dispatch, state: state$1 } = view;
1047
- let { tr } = state$1;
1048
- tr = clearRange(tr);
1049
- const from = tr.selection.from;
1050
- const table = gfm.createTable(ctx2, 3, 3);
1051
- tr = tr.replaceSelectionWith(table);
1052
- dispatch(tr);
1053
- requestAnimationFrame(() => {
1054
- const docSize = view.state.doc.content.size;
1055
- const $pos = view.state.doc.resolve(
1056
- from > docSize ? docSize : from < 0 ? 0 : from
1057
- );
1058
- const selection = state.TextSelection.near($pos);
1059
- const tr2 = view.state.tr;
1060
- tr2.setSelection(selection);
1061
- dispatch(tr2.scrollIntoView());
1062
- });
1063
- }
1064
- });
1065
- }
1066
- if (isLatexEnabled) {
1067
- advancedGroup.addItem("math", {
1068
- label: (_H = config == null ? void 0 : config.slashMenuMathLabel) != null ? _H : "Math",
1069
- icon: (_I = config == null ? void 0 : config.slashMenuMathIcon) != null ? _I : functionsIcon,
1070
- onRun: (ctx2) => {
1071
- const view = ctx2.get(core.editorViewCtx);
1072
- const { dispatch, state } = view;
1073
- const command = clearContentAndAddBlockType(commonmark.codeBlockSchema.type(ctx2), {
1074
- language: "LaTex"
1075
- });
1076
- command(state, dispatch);
1077
- }
1078
- });
1079
1098
  }
1080
- (_J = config == null ? void 0 : config.buildMenu) == null ? void 0 : _J.call(config, groupBuilder);
1099
+ (_kb = config == null ? void 0 : config.buildMenu) == null ? void 0 : _kb.call(config, groupBuilder);
1081
1100
  let groups = groupBuilder.build();
1082
1101
  if (filter) {
1083
1102
  groups = groups.map((group) => {
@@ -1132,7 +1151,7 @@ const Menu = vue.defineComponent({
1132
1151
  },
1133
1152
  setup({ ctx, show, filter, hide, config }) {
1134
1153
  const host = vue.ref();
1135
- const groupInfo = vue.computed(() => getGroups(filter.value, config, ctx));
1154
+ const groupInfo = vue.computed(() => getGroups$1(filter.value, config, ctx));
1136
1155
  const hoverIndex = vue.ref(0);
1137
1156
  const prevMousePosition = vue.ref({ x: -999, y: -999 });
1138
1157
  const onPointerMove = (e) => {
@@ -1676,6 +1695,44 @@ const mathInlineSchema = utils.$nodeSchema(mathInlineId, () => ({
1676
1695
  }
1677
1696
  }));
1678
1697
 
1698
+ const toggleLatexCommand = utils.$command("ToggleLatex", (ctx) => {
1699
+ return () => (state$1, dispatch) => {
1700
+ const {
1701
+ hasNode: hasLatex,
1702
+ pos: latexPos,
1703
+ target: latexNode
1704
+ } = prose.findNodeInSelection(state$1, mathInlineSchema.type(ctx));
1705
+ const { selection, doc, tr } = state$1;
1706
+ if (!hasLatex) {
1707
+ const text = doc.textBetween(selection.from, selection.to);
1708
+ let _tr2 = tr.replaceSelectionWith(
1709
+ mathInlineSchema.type(ctx).create({
1710
+ value: text
1711
+ })
1712
+ );
1713
+ if (dispatch) {
1714
+ dispatch(
1715
+ _tr2.setSelection(state.NodeSelection.create(_tr2.doc, selection.from))
1716
+ );
1717
+ }
1718
+ return true;
1719
+ }
1720
+ const { from, to } = selection;
1721
+ if (!latexNode || latexPos < 0) return false;
1722
+ let _tr = tr.delete(latexPos, latexPos + 1);
1723
+ const content = latexNode.attrs.value;
1724
+ _tr = _tr.insertText(content, latexPos);
1725
+ if (dispatch) {
1726
+ dispatch(
1727
+ _tr.setSelection(
1728
+ state.TextSelection.create(_tr.doc, from, to + content.length - 1)
1729
+ )
1730
+ );
1731
+ }
1732
+ return true;
1733
+ };
1734
+ });
1735
+
1679
1736
  const inlineLatexTooltip = tooltip.tooltipFactory("INLINE_LATEX");
1680
1737
 
1681
1738
  const LatexTooltip = vue.defineComponent({
@@ -1903,7 +1960,7 @@ const latex = (editor, config) => {
1903
1960
  });
1904
1961
  }
1905
1962
  });
1906
- }).use(remarkMathPlugin).use(remarkMathBlockPlugin).use(mathInlineSchema).use(inlineLatexTooltip).use(mathInlineInputRule).use(mathBlockInputRule).use(blockLatexSchema);
1963
+ }).use(remarkMathPlugin).use(remarkMathBlockPlugin).use(mathInlineSchema).use(inlineLatexTooltip).use(mathInlineInputRule).use(mathBlockInputRule).use(blockLatexSchema).use(toggleLatexCommand);
1907
1964
  };
1908
1965
  function renderLatex(content, options) {
1909
1966
  const html = katex.renderToString(content, {
@@ -2036,6 +2093,94 @@ const table = (editor, config) => {
2036
2093
  }).use(tableBlock.tableBlock);
2037
2094
  };
2038
2095
 
2096
+ function getGroups(config, ctx) {
2097
+ var _a, _b, _c, _d, _e, _f, _g;
2098
+ const groupBuilder = new GroupBuilder();
2099
+ groupBuilder.addGroup("formatting", "Formatting").addItem("bold", {
2100
+ icon: (_a = config == null ? void 0 : config.boldIcon) != null ? _a : boldIcon,
2101
+ active: (ctx2) => {
2102
+ const commands = ctx2.get(core.commandsCtx);
2103
+ return commands.call(commonmark.isMarkSelectedCommand.key, commonmark.strongSchema.type(ctx2));
2104
+ },
2105
+ onRun: (ctx2) => {
2106
+ const commands = ctx2.get(core.commandsCtx);
2107
+ commands.call(commonmark.toggleStrongCommand.key);
2108
+ }
2109
+ }).addItem("italic", {
2110
+ icon: (_b = config == null ? void 0 : config.italicIcon) != null ? _b : italicIcon,
2111
+ active: (ctx2) => {
2112
+ const commands = ctx2.get(core.commandsCtx);
2113
+ return commands.call(
2114
+ commonmark.isMarkSelectedCommand.key,
2115
+ commonmark.emphasisSchema.type(ctx2)
2116
+ );
2117
+ },
2118
+ onRun: (ctx2) => {
2119
+ const commands = ctx2.get(core.commandsCtx);
2120
+ commands.call(commonmark.toggleEmphasisCommand.key);
2121
+ }
2122
+ }).addItem("strikethrough", {
2123
+ icon: (_c = config == null ? void 0 : config.strikethroughIcon) != null ? _c : strikethroughIcon,
2124
+ active: (ctx2) => {
2125
+ const commands = ctx2.get(core.commandsCtx);
2126
+ return commands.call(
2127
+ commonmark.isMarkSelectedCommand.key,
2128
+ gfm.strikethroughSchema.type(ctx2)
2129
+ );
2130
+ },
2131
+ onRun: (ctx2) => {
2132
+ const commands = ctx2.get(core.commandsCtx);
2133
+ commands.call(gfm.toggleStrikethroughCommand.key);
2134
+ }
2135
+ });
2136
+ const functionGroup = groupBuilder.addGroup("function", "Function");
2137
+ functionGroup.addItem("code", {
2138
+ icon: (_d = config == null ? void 0 : config.codeIcon) != null ? _d : codeIcon,
2139
+ active: (ctx2) => {
2140
+ const commands = ctx2.get(core.commandsCtx);
2141
+ return commands.call(
2142
+ commonmark.isMarkSelectedCommand.key,
2143
+ commonmark.inlineCodeSchema.type(ctx2)
2144
+ );
2145
+ },
2146
+ onRun: (ctx2) => {
2147
+ const commands = ctx2.get(core.commandsCtx);
2148
+ commands.call(commonmark.toggleInlineCodeCommand.key);
2149
+ }
2150
+ });
2151
+ const flags = ctx && useCrepeFeatures(ctx).get();
2152
+ const isLatexEnabled = flags == null ? void 0 : flags.includes(CrepeFeature.Latex);
2153
+ if (isLatexEnabled) {
2154
+ functionGroup.addItem("latex", {
2155
+ icon: (_e = config == null ? void 0 : config.latexIcon) != null ? _e : functionsIcon,
2156
+ active: (ctx2) => {
2157
+ const commands = ctx2.get(core.commandsCtx);
2158
+ return commands.call(
2159
+ commonmark.isNodeSelectedCommand.key,
2160
+ mathInlineSchema.type(ctx2)
2161
+ );
2162
+ },
2163
+ onRun: (ctx2) => {
2164
+ const commands = ctx2.get(core.commandsCtx);
2165
+ commands.call(toggleLatexCommand.key);
2166
+ }
2167
+ });
2168
+ }
2169
+ functionGroup.addItem("link", {
2170
+ icon: (_f = config == null ? void 0 : config.linkIcon) != null ? _f : linkIcon,
2171
+ active: (ctx2) => {
2172
+ const commands = ctx2.get(core.commandsCtx);
2173
+ return commands.call(commonmark.isMarkSelectedCommand.key, commonmark.linkSchema.type(ctx2));
2174
+ },
2175
+ onRun: (ctx2) => {
2176
+ const commands = ctx2.get(core.commandsCtx);
2177
+ commands.call(linkTooltip$1.toggleLinkCommand.key);
2178
+ }
2179
+ });
2180
+ (_g = config == null ? void 0 : config.buildToolbar) == null ? void 0 : _g.call(config, groupBuilder);
2181
+ return groupBuilder.build();
2182
+ }
2183
+
2039
2184
  const Toolbar = vue.defineComponent({
2040
2185
  props: {
2041
2186
  ctx: {
@@ -2060,169 +2205,42 @@ const Toolbar = vue.defineComponent({
2060
2205
  }
2061
2206
  },
2062
2207
  setup(props) {
2063
- const { ctx, hide, config } = props;
2208
+ const { ctx, config } = props;
2064
2209
  const onClick = (fn) => (e) => {
2065
2210
  e.preventDefault();
2066
2211
  ctx && fn(ctx);
2067
2212
  };
2068
- const isActive = (mark) => {
2069
- const selection = props.selection.value;
2070
- if (!ctx || !selection) return false;
2071
- const { state } = ctx.get(core.editorViewCtx);
2072
- if (!state) return false;
2073
- const { doc } = state;
2074
- return doc.rangeHasMark(selection.from, selection.to, mark);
2075
- };
2076
- const containsNode = (node) => {
2077
- const selection = props.selection.value;
2078
- if (!ctx || !selection) return false;
2079
- const { state: state$1 } = ctx.get(core.editorViewCtx);
2080
- if (!state$1) return false;
2081
- const { doc } = state$1;
2082
- if (selection instanceof state.NodeSelection) {
2083
- return selection.node.type === node;
2084
- }
2085
- const { from, to } = selection;
2086
- let hasNode = false;
2087
- doc.nodesBetween(from, to, (n) => {
2088
- if (n.type === node) {
2089
- hasNode = true;
2090
- return false;
2091
- }
2092
- return true;
2093
- });
2094
- return hasNode;
2095
- };
2096
- const flags = useCrepeFeatures(ctx).get();
2097
- const isLatexEnabled = flags == null ? void 0 : flags.includes(CrepeFeature.Latex);
2098
- const toggleLatex = (ctx2) => {
2099
- const hasLatex = containsNode(mathInlineSchema.type(ctx2));
2100
- const view = ctx2.get(core.editorViewCtx);
2101
- const { selection, doc, tr } = view.state;
2102
- if (!hasLatex) {
2103
- const text = doc.textBetween(selection.from, selection.to);
2104
- let _tr2 = tr.replaceSelectionWith(
2105
- mathInlineSchema.type(ctx2).create({
2106
- value: text
2107
- })
2108
- );
2109
- view.dispatch(
2110
- _tr2.setSelection(state.NodeSelection.create(_tr2.doc, selection.from))
2111
- );
2112
- return;
2113
- }
2114
- const { from, to } = selection;
2115
- let pos = -1;
2116
- let node = null;
2117
- doc.nodesBetween(from, to, (n, p) => {
2118
- if (node) return false;
2119
- if (n.type === mathInlineSchema.type(ctx2)) {
2120
- pos = p;
2121
- node = n;
2122
- return false;
2123
- }
2124
- return true;
2125
- });
2126
- if (!node || pos < 0) return;
2127
- let _tr = tr.delete(pos, pos + 1);
2128
- const content = node.attrs.value;
2129
- _tr = _tr.insertText(content, pos);
2130
- view.dispatch(
2131
- _tr.setSelection(
2132
- state.TextSelection.create(_tr.doc, from, to + content.length - 1)
2133
- )
2134
- );
2135
- };
2213
+ function checkActive(checker) {
2214
+ props.selection.value;
2215
+ const status = ctx.get(core.editorCtx).status;
2216
+ if (status !== core.EditorStatus.Created) return false;
2217
+ return checker(ctx);
2218
+ }
2219
+ const groupInfo = vue.computed(() => getGroups(config, ctx));
2136
2220
  return () => {
2137
- var _a, _b, _c, _d, _e, _f;
2138
- return /* @__PURE__ */ vue.h(vue.Fragment, null, /* @__PURE__ */ vue.h(
2139
- "button",
2140
- {
2141
- type: "button",
2142
- class: clsx(
2143
- "toolbar-item",
2144
- ctx && isActive(commonmark.strongSchema.type(ctx)) && "active"
2145
- ),
2146
- onPointerdown: onClick((ctx2) => {
2147
- const commands = ctx2.get(core.commandsCtx);
2148
- commands.call(commonmark.toggleStrongCommand.key);
2149
- })
2150
- },
2151
- /* @__PURE__ */ vue.h(component.Icon, { icon: (_a = config == null ? void 0 : config.boldIcon) != null ? _a : boldIcon })
2152
- ), /* @__PURE__ */ vue.h(
2153
- "button",
2154
- {
2155
- type: "button",
2156
- class: clsx(
2157
- "toolbar-item",
2158
- ctx && isActive(commonmark.emphasisSchema.type(ctx)) && "active"
2159
- ),
2160
- onPointerdown: onClick((ctx2) => {
2161
- const commands = ctx2.get(core.commandsCtx);
2162
- commands.call(commonmark.toggleEmphasisCommand.key);
2163
- })
2164
- },
2165
- /* @__PURE__ */ vue.h(component.Icon, { icon: (_b = config == null ? void 0 : config.italicIcon) != null ? _b : italicIcon })
2166
- ), /* @__PURE__ */ vue.h(
2167
- "button",
2168
- {
2169
- type: "button",
2170
- class: clsx(
2171
- "toolbar-item",
2172
- ctx && isActive(gfm.strikethroughSchema.type(ctx)) && "active"
2173
- ),
2174
- onPointerdown: onClick((ctx2) => {
2175
- const commands = ctx2.get(core.commandsCtx);
2176
- commands.call(gfm.toggleStrikethroughCommand.key);
2177
- })
2178
- },
2179
- /* @__PURE__ */ vue.h(component.Icon, { icon: (_c = config == null ? void 0 : config.strikethroughIcon) != null ? _c : strikethroughIcon })
2180
- ), /* @__PURE__ */ vue.h("div", { class: "divider" }), /* @__PURE__ */ vue.h(
2181
- "button",
2182
- {
2183
- type: "button",
2184
- class: clsx(
2185
- "toolbar-item",
2186
- ctx && isActive(commonmark.inlineCodeSchema.type(ctx)) && "active"
2187
- ),
2188
- onPointerdown: onClick((ctx2) => {
2189
- const commands = ctx2.get(core.commandsCtx);
2190
- commands.call(commonmark.toggleInlineCodeCommand.key);
2191
- })
2192
- },
2193
- /* @__PURE__ */ vue.h(component.Icon, { icon: (_d = config == null ? void 0 : config.codeIcon) != null ? _d : codeIcon })
2194
- ), isLatexEnabled && /* @__PURE__ */ vue.h(
2195
- "button",
2196
- {
2197
- type: "button",
2198
- class: clsx(
2199
- "toolbar-item",
2200
- ctx && containsNode(mathInlineSchema.type(ctx)) && "active"
2201
- ),
2202
- onPointerdown: onClick(toggleLatex)
2203
- },
2204
- /* @__PURE__ */ vue.h(component.Icon, { icon: (_e = config == null ? void 0 : config.latexIcon) != null ? _e : functionsIcon })
2205
- ), /* @__PURE__ */ vue.h(
2206
- "button",
2207
- {
2208
- type: "button",
2209
- class: clsx(
2210
- "toolbar-item",
2211
- ctx && isActive(commonmark.linkSchema.type(ctx)) && "active"
2212
- ),
2213
- onPointerdown: onClick((ctx2) => {
2214
- const view = ctx2.get(core.editorViewCtx);
2215
- const { selection } = view.state;
2216
- if (isActive(commonmark.linkSchema.type(ctx2))) {
2217
- ctx2.get(linkTooltip$1.linkTooltipAPI.key).removeLink(selection.from, selection.to);
2218
- return;
2219
- }
2220
- ctx2.get(linkTooltip$1.linkTooltipAPI.key).addLink(selection.from, selection.to);
2221
- hide == null ? void 0 : hide();
2222
- })
2223
- },
2224
- /* @__PURE__ */ vue.h(component.Icon, { icon: (_f = config == null ? void 0 : config.linkIcon) != null ? _f : linkIcon })
2225
- ));
2221
+ return /* @__PURE__ */ vue.h(vue.Fragment, null, groupInfo.value.map((group) => {
2222
+ return group.items.map((item) => {
2223
+ return /* @__PURE__ */ vue.h(
2224
+ "button",
2225
+ {
2226
+ type: "button",
2227
+ class: clsx(
2228
+ "toolbar-item",
2229
+ ctx && checkActive(item.active) && "active"
2230
+ ),
2231
+ onPointerdown: onClick(item.onRun)
2232
+ },
2233
+ /* @__PURE__ */ vue.h(component.Icon, { icon: item.icon })
2234
+ );
2235
+ });
2236
+ }).reduce((acc, curr, index) => {
2237
+ if (index === 0) {
2238
+ acc.push(...curr);
2239
+ } else {
2240
+ acc.push(/* @__PURE__ */ vue.h("div", { class: "divider" }), ...curr);
2241
+ }
2242
+ return acc;
2243
+ }, []));
2226
2244
  };
2227
2245
  }
2228
2246
  });