@editorcn/editor 0.4.0 → 0.4.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.
package/dist/index.js CHANGED
@@ -866,7 +866,8 @@ var textItems = [
866
866
  /* @__PURE__ */ jsx18("path", { d: "M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" }),
867
867
  /* @__PURE__ */ jsx18("path", { d: "M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" })
868
868
  ] }) }),
869
- isActive: (s) => s.isBold
869
+ isActive: (s) => s.isBold,
870
+ mark: "bold"
870
871
  },
871
872
  {
872
873
  command: (e) => e.chain().focus().toggleItalic().run(),
@@ -875,7 +876,8 @@ var textItems = [
875
876
  /* @__PURE__ */ jsx18("line", { x1: "14", y1: "20", x2: "5", y2: "20" }),
876
877
  /* @__PURE__ */ jsx18("line", { x1: "15", y1: "4", x2: "9", y2: "20" })
877
878
  ] }) }),
878
- isActive: (s) => s.isItalic
879
+ isActive: (s) => s.isItalic,
880
+ mark: "italic"
879
881
  },
880
882
  {
881
883
  command: (e) => e.chain().focus().toggleUnderline().run(),
@@ -883,7 +885,8 @@ var textItems = [
883
885
  /* @__PURE__ */ jsx18("path", { d: "M6 4v6a6 6 0 0 0 12 0V4" }),
884
886
  /* @__PURE__ */ jsx18("line", { x1: "4", y1: "20", x2: "20", y2: "20" })
885
887
  ] }) }),
886
- isActive: (s) => s.isUnderline
888
+ isActive: (s) => s.isUnderline,
889
+ mark: "underline"
887
890
  },
888
891
  {
889
892
  command: (e) => e.chain().focus().toggleStrike().run(),
@@ -892,7 +895,8 @@ var textItems = [
892
895
  /* @__PURE__ */ jsx18("path", { d: "M14.5 14.6a3.5 3.5 0 0 1-2.9 5.4H8" }),
893
896
  /* @__PURE__ */ jsx18("line", { x1: "4", y1: "12", x2: "20", y2: "12" })
894
897
  ] }) }),
895
- isActive: (s) => s.isStrike
898
+ isActive: (s) => s.isStrike,
899
+ mark: "strike"
896
900
  },
897
901
  {
898
902
  command: (e) => e.chain().focus().toggleCode().run(),
@@ -900,9 +904,11 @@ var textItems = [
900
904
  /* @__PURE__ */ jsx18("polyline", { points: "16 18 22 12 16 6" }),
901
905
  /* @__PURE__ */ jsx18("polyline", { points: "8 6 2 12 8 18" })
902
906
  ] }) }),
903
- isActive: (s) => s.isCode
907
+ isActive: (s) => s.isCode,
908
+ mark: "code"
904
909
  }
905
910
  ];
911
+ var getTextItems = (editor) => textItems.filter((item) => Boolean(editor.schema.marks[item.mark]));
906
912
  var TextButtons = ({ editor }) => {
907
913
  const editorState = useEditorState(
908
914
  editor,
@@ -915,7 +921,7 @@ var TextButtons = ({ editor }) => {
915
921
  }),
916
922
  shallowEqual
917
923
  );
918
- return /* @__PURE__ */ jsx18(RteButtonGroup, { children: textItems.map((item, i) => /* @__PURE__ */ jsx18(
924
+ return /* @__PURE__ */ jsx18(RteButtonGroup, { children: getTextItems(editor).map((item) => /* @__PURE__ */ jsx18(
919
925
  RteButton,
920
926
  {
921
927
  active: item.isActive(editorState),
@@ -923,7 +929,7 @@ var TextButtons = ({ editor }) => {
923
929
  onClick: () => item.command(editor),
924
930
  children: item.icon
925
931
  },
926
- i
932
+ item.mark
927
933
  )) });
928
934
  };
929
935
 
@@ -952,6 +958,13 @@ var BubbleMenu = ({ editor }) => {
952
958
  if (!editor) {
953
959
  return null;
954
960
  }
961
+ const hasText = getTextItems(editor).length > 0;
962
+ const hasColor = editor.extensionManager.extensions.some(
963
+ (ext) => ext.name === "color" || ext.name === "highlight"
964
+ );
965
+ if (!(hasText || hasColor)) {
966
+ return null;
967
+ }
955
968
  return /* @__PURE__ */ jsx19(
956
969
  TiptapBubbleMenu,
957
970
  {
@@ -959,9 +972,9 @@ var BubbleMenu = ({ editor }) => {
959
972
  options: { offset: 8, placement: "top" },
960
973
  shouldShow,
961
974
  children: /* @__PURE__ */ jsxs7("div", { className: "rte-bubble-menu", children: [
962
- /* @__PURE__ */ jsx19(TextButtons, { editor }),
963
- /* @__PURE__ */ jsx19(RteSeparator, {}),
964
- /* @__PURE__ */ jsx19(ColorSelector, { editor })
975
+ hasText && /* @__PURE__ */ jsx19(TextButtons, { editor }),
976
+ hasText && hasColor && /* @__PURE__ */ jsx19(RteSeparator, {}),
977
+ hasColor && /* @__PURE__ */ jsx19(ColorSelector, { editor })
965
978
  ] })
966
979
  }
967
980
  );