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