@blocklet/labels 1.6.178 → 1.6.180

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.es.js CHANGED
@@ -18,7 +18,7 @@ import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
18
18
  import { useReactive, useRequest, useSize, useDeepCompareLayoutEffect } from "ahooks";
19
19
  import { createContainer } from "unstated-next";
20
20
  import { arrayToTree } from "performant-array-to-tree";
21
- import CloseIcon from "@mui/icons-material/Close";
21
+ import CloseOutlineIcon from "@mui/icons-material/Close";
22
22
  import DoneIcon from "@mui/icons-material/Done";
23
23
  import chroma from "chroma-js";
24
24
  const materialSymbolsLabelRounded = (props) => /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", width: "1.2em", height: "1.2em", ...props, children: /* @__PURE__ */ jsx("path", { fill: "currentColor", d: "M5 19q-.825 0-1.413-.587Q3 17.825 3 17V7q0-.825.587-1.412Q4.175 5 5 5h10q.5 0 .938.225q.437.225.712.625l3.525 5q.375.525.375 1.15q0 .625-.375 1.15l-3.525 5q-.275.4-.712.625Q15.5 19 15 19Z" }) });
@@ -586,6 +586,9 @@ const useLabels = ({ loading, data, createLabel: createLabelAPI }) => {
586
586
  var _a;
587
587
  return ((_a = nodesKeyById[id]) == null ? void 0 : _a.getFullName(locale)) ?? id;
588
588
  };
589
+ const parseLabelsStr = useCallback((labelIdsStr) => {
590
+ return (labelIdsStr == null ? void 0 : labelIdsStr.split(",").filter(Boolean)) || [];
591
+ }, []);
589
592
  return {
590
593
  ...state,
591
594
  flattenedLabels: flattened,
@@ -600,7 +603,8 @@ const useLabels = ({ loading, data, createLabel: createLabelAPI }) => {
600
603
  addLabelNode,
601
604
  updateLabelNode,
602
605
  removeLabelNode,
603
- getFullLabelName
606
+ getFullLabelName,
607
+ parseLabelsStr
604
608
  };
605
609
  };
606
610
  const LabelsContainer = createContainer(useLabels);
@@ -752,6 +756,197 @@ function Labels({ labels, editable, onChange, sx, renderLabel }) {
752
756
  ] });
753
757
  }
754
758
  const mdiTagPlusOutline = (props) => /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", width: "1.2em", height: "1.2em", ...props, children: /* @__PURE__ */ jsx("path", { fill: "currentColor", d: "M6.5 5A1.5 1.5 0 1 0 8 6.5A1.5 1.5 0 0 0 6.5 5m0 0A1.5 1.5 0 1 0 8 6.5A1.5 1.5 0 0 0 6.5 5m14.91 6.58l-9-9A2 2 0 0 0 11 2H4a2 2 0 0 0-2 2v7a2 2 0 0 0 .59 1.42l.41.4a5.62 5.62 0 0 1 2.08-.74L4 11V4h7l9 9l-7 7l-1.08-1.08a5.57 5.57 0 0 1-.74 2.08l.41.41A2 2 0 0 0 13 22a2 2 0 0 0 1.41-.59l7-7A2 2 0 0 0 22 13a2 2 0 0 0-.59-1.42M6.5 5A1.5 1.5 0 1 0 8 6.5A1.5 1.5 0 0 0 6.5 5M10 19H7v3H5v-3H2v-2h3v-3h2v3h3Z" }) });
759
+ const getTextColor = (color) => {
760
+ return chroma(color).hex();
761
+ };
762
+ const getBorderColor = (color) => {
763
+ if (chroma(color).luminance() > 0.5) {
764
+ return chroma(color).darken(3).hex();
765
+ }
766
+ return chroma(color).brighten(0.5).alpha(0.25).hex();
767
+ };
768
+ const getBackgroundColor = (color) => {
769
+ if (chroma(color).luminance() > 0.5) {
770
+ return chroma(color).darken(2.5).hex();
771
+ }
772
+ return chroma(color).brighten(2.5).alpha(0.25).hex();
773
+ };
774
+ const getFilterStyle = (color) => {
775
+ if (chroma(color).luminance() > 0.5) {
776
+ return "brightness(0.85) contrast(1.2)";
777
+ }
778
+ return "brightness(0.85) contrast(1.2)";
779
+ };
780
+ function LabelChip({
781
+ label,
782
+ onDelete,
783
+ sx,
784
+ fullName = true,
785
+ onClick,
786
+ disabled = false
787
+ }) {
788
+ const { getFullLabelName, getLabelName } = LabelsContainer.useContainer();
789
+ const mergedSx = [
790
+ {
791
+ height: 20,
792
+ borderRadius: 0.5,
793
+ fontSize: 12,
794
+ fontWeight: 500,
795
+ color: `${getTextColor(label.data.color)} !important`,
796
+ bgcolor: `${getBackgroundColor(label.data.color)} !important`,
797
+ transition: "filter 0.2s",
798
+ borderColor: `${getBorderColor(label.data.color)} !important`,
799
+ // -webkit-text-fill-color
800
+ WebkitTextFillColor: `${getTextColor(label.data.color)} !important`,
801
+ ".MuiChip-deleteIcon": {
802
+ color: `${getTextColor(label.data.color)} !important`,
803
+ cursor: "pointer",
804
+ transition: "transform 0.3s",
805
+ "&:hover": {
806
+ transform: "rotate(90deg)"
807
+ }
808
+ },
809
+ ".MuiChip-label": {
810
+ px: 0.5,
811
+ maxHeight: 20
812
+ },
813
+ ...onClick && {
814
+ cursor: "pointer",
815
+ "&:hover": {
816
+ filter: getFilterStyle(label.data.color)
817
+ }
818
+ }
819
+ },
820
+ ...Array.isArray(sx) ? sx : [sx]
821
+ ];
822
+ const hasDelete = !disabled && !!onDelete;
823
+ const hasOnClick = !disabled && !!onClick;
824
+ return (
825
+ // @ts-ignore
826
+ /* @__PURE__ */ jsx(
827
+ Chip,
828
+ {
829
+ label: fullName ? getFullLabelName(label.data.id) : getLabelName(label.data.id),
830
+ variant: "outlined",
831
+ size: "small",
832
+ ...hasDelete && {
833
+ onDelete: (e) => {
834
+ e.stopPropagation();
835
+ e.preventDefault();
836
+ onDelete(label);
837
+ },
838
+ deleteIcon: /* @__PURE__ */ jsx(CloseOutlineIcon, {})
839
+ },
840
+ ...hasOnClick && {
841
+ onClick: (e) => {
842
+ e.stopPropagation();
843
+ e.preventDefault();
844
+ onClick(label);
845
+ }
846
+ },
847
+ sx: mergedSx
848
+ },
849
+ label.data.id
850
+ )
851
+ );
852
+ }
853
+ function Labels2({
854
+ compact = true,
855
+ labels,
856
+ sx,
857
+ renderLabel,
858
+ prepend,
859
+ displaySystemLabels = true,
860
+ onItemClick
861
+ }) {
862
+ const { getLabelsByIds, loading } = LabelsContainer.useContainer();
863
+ const labelsWrapperRef = useRef(null);
864
+ const [overflowIndex, setOverflowIndex] = useState(99999);
865
+ let labelNodes = getLabelsByIds(labels || []);
866
+ const size = useSize(labelsWrapperRef);
867
+ useDeepCompareLayoutEffect(() => {
868
+ if (compact) {
869
+ if (labelsWrapperRef.current) {
870
+ const { right } = labelsWrapperRef.current.getBoundingClientRect();
871
+ const labelElements = labelsWrapperRef.current.querySelectorAll(".MuiChip-root");
872
+ if ((labelElements == null ? void 0 : labelElements.length) > 0) {
873
+ Array.from(labelElements).some((x, i) => {
874
+ const rect = x.getBoundingClientRect();
875
+ if (rect.right > right - 36) {
876
+ setOverflowIndex(i);
877
+ return true;
878
+ }
879
+ return false;
880
+ });
881
+ }
882
+ }
883
+ } else {
884
+ setOverflowIndex(99999);
885
+ }
886
+ }, [size, compact]);
887
+ if (loading) {
888
+ return null;
889
+ }
890
+ if (!displaySystemLabels) {
891
+ labelNodes = labelNodes.filter((x) => !x.data.id.startsWith("system:"));
892
+ }
893
+ const mergedSx = [
894
+ {
895
+ display: "flex",
896
+ gap: 1,
897
+ width: "100%",
898
+ alignItems: "center",
899
+ overflow: "hidden",
900
+ flexWrap: compact ? "no-wrap" : "wrap"
901
+ },
902
+ ...Array.isArray(sx) ? sx : [sx]
903
+ ];
904
+ return /* @__PURE__ */ jsxs(Box$1, { sx: mergedSx, ref: labelsWrapperRef, children: [
905
+ prepend,
906
+ labelNodes.map((item, index) => {
907
+ if (!item) {
908
+ return null;
909
+ }
910
+ const visible = index < overflowIndex;
911
+ let extra = null;
912
+ if (index === overflowIndex) {
913
+ extra = /* @__PURE__ */ jsx(
914
+ Box$1,
915
+ {
916
+ sx: {
917
+ display: "inline-flex",
918
+ ...compact && { height: 20, lineHeight: "20px" },
919
+ color: "text.secondary",
920
+ fontWeight: "bold",
921
+ fontSize: 14
922
+ },
923
+ children: `+${labelNodes.length - overflowIndex}`
924
+ },
925
+ "overflow-label"
926
+ );
927
+ }
928
+ let labelChip = /* @__PURE__ */ jsx(
929
+ LabelChip,
930
+ {
931
+ label: item,
932
+ onClick: onItemClick,
933
+ sx: {
934
+ visibility: visible ? "visible" : "hidden",
935
+ pointerEvents: visible ? "auto" : "none"
936
+ }
937
+ },
938
+ item.data.id
939
+ );
940
+ if (renderLabel) {
941
+ labelChip = renderLabel(item, labelChip);
942
+ }
943
+ if (extra) {
944
+ return [extra, labelChip];
945
+ }
946
+ return labelChip;
947
+ })
948
+ ] });
949
+ }
755
950
  function PopperComponent({
756
951
  disablePortal,
757
952
  anchorEl,
@@ -802,7 +997,8 @@ function GithubLabelPicker({
802
997
  trigger,
803
998
  multiple = true,
804
999
  updateImmediately = true,
805
- excludes = []
1000
+ excludes = [],
1001
+ disabled = false
806
1002
  }) {
807
1003
  const { locale } = useLocaleContext();
808
1004
  const { flattenedLabels: labels, getLabelsByIds, loading, createLabel } = LabelsContainer.useContainer();
@@ -820,6 +1016,9 @@ function GithubLabelPicker({
820
1016
  }, [labels]);
821
1017
  const theme = useTheme();
822
1018
  const handleClick = (event) => {
1019
+ if (disabled) {
1020
+ return;
1021
+ }
823
1022
  event.preventDefault();
824
1023
  setPendingValue(value);
825
1024
  setAnchorEl(event.currentTarget);
@@ -961,8 +1160,8 @@ function GithubLabelPicker({
961
1160
  {
962
1161
  component: "span",
963
1162
  sx: {
964
- width: 14,
965
- height: 14,
1163
+ width: 16,
1164
+ height: 16,
966
1165
  flexShrink: 0,
967
1166
  borderRadius: "3px",
968
1167
  mr: 1
@@ -975,17 +1174,16 @@ function GithubLabelPicker({
975
1174
  {
976
1175
  sx: {
977
1176
  flexGrow: 1,
978
- "& span": {
979
- color: theme.palette.mode === "light" ? "#586069" : "#8b949e"
980
- }
1177
+ alignItems: "center",
1178
+ display: "flex"
981
1179
  },
982
- children: option.getFullName(locale)
1180
+ children: /* @__PURE__ */ jsx(LabelChip, { label: option, disabled })
983
1181
  }
984
1182
  ),
985
1183
  /* @__PURE__ */ jsx(
986
1184
  Box$1,
987
1185
  {
988
- component: CloseIcon,
1186
+ component: CloseOutlineIcon,
989
1187
  sx: { opacity: 0.6, width: 18, height: 18 },
990
1188
  style: {
991
1189
  visibility: selected ? "visible" : "hidden"
@@ -1062,184 +1260,6 @@ function GithubLabelPicker({
1062
1260
  )
1063
1261
  ] });
1064
1262
  }
1065
- const getTextColor = (color) => {
1066
- return chroma(color).hex();
1067
- };
1068
- const getBorderColor = (color) => {
1069
- if (chroma(color).luminance() > 0.5) {
1070
- return chroma(color).darken(3).hex();
1071
- }
1072
- return chroma(color).brighten(0.5).alpha(0.25).hex();
1073
- };
1074
- const getBackgroundColor = (color) => {
1075
- if (chroma(color).luminance() > 0.5) {
1076
- return chroma(color).darken(2.5).hex();
1077
- }
1078
- return chroma(color).brighten(2.5).alpha(0.25).hex();
1079
- };
1080
- const getFilterStyle = (color) => {
1081
- if (chroma(color).luminance() > 0.5) {
1082
- return "brightness(0.85) contrast(1.2)";
1083
- }
1084
- return "brightness(0.85) contrast(1.2)";
1085
- };
1086
- function LabelChip({
1087
- label,
1088
- onDelete,
1089
- sx,
1090
- fullName = true,
1091
- onClick
1092
- }) {
1093
- const { getFullLabelName, getLabelName } = LabelsContainer.useContainer();
1094
- const mergedSx = [
1095
- {
1096
- height: 20,
1097
- borderRadius: 0.5,
1098
- fontSize: 12,
1099
- fontWeight: 500,
1100
- color: `${getTextColor(label.data.color)} !important`,
1101
- bgcolor: `${getBackgroundColor(label.data.color)} !important`,
1102
- transition: "filter 0.2s",
1103
- borderColor: `${getBorderColor(label.data.color)} !important`,
1104
- ".MuiChip-label": {
1105
- p: 0.5
1106
- },
1107
- span: {},
1108
- ...onClick && {
1109
- cursor: "pointer",
1110
- "&:hover": {
1111
- filter: getFilterStyle(label.data.color)
1112
- }
1113
- }
1114
- },
1115
- ...Array.isArray(sx) ? sx : [sx]
1116
- ];
1117
- return (
1118
- // @ts-ignore
1119
- /* @__PURE__ */ jsx(
1120
- Chip,
1121
- {
1122
- label: fullName ? getFullLabelName(label.data.id) : getLabelName(label.data.id),
1123
- variant: "outlined",
1124
- size: "small",
1125
- ...onDelete && {
1126
- onDelete: (e) => {
1127
- e.stopPropagation();
1128
- e.preventDefault();
1129
- onDelete(label);
1130
- },
1131
- deleteIcon: /* @__PURE__ */ jsx(CloseIcon, {})
1132
- },
1133
- ...onClick && {
1134
- onClick: (e) => {
1135
- e.stopPropagation();
1136
- e.preventDefault();
1137
- onClick(label);
1138
- }
1139
- },
1140
- sx: mergedSx
1141
- },
1142
- label.data.id
1143
- )
1144
- );
1145
- }
1146
- function Labels2({
1147
- compact = true,
1148
- labels,
1149
- sx,
1150
- renderLabel,
1151
- prepend,
1152
- displaySystemLabels = true,
1153
- onItemClick
1154
- }) {
1155
- const { getLabelsByIds, loading } = LabelsContainer.useContainer();
1156
- const labelsWrapperRef = useRef(null);
1157
- const [overflowIndex, setOverflowIndex] = useState(99999);
1158
- let labelNodes = getLabelsByIds(labels || []);
1159
- const size = useSize(labelsWrapperRef);
1160
- useDeepCompareLayoutEffect(() => {
1161
- if (compact) {
1162
- if (labelsWrapperRef.current) {
1163
- const { right } = labelsWrapperRef.current.getBoundingClientRect();
1164
- const labelElements = labelsWrapperRef.current.querySelectorAll(".MuiChip-root");
1165
- if ((labelElements == null ? void 0 : labelElements.length) > 0) {
1166
- Array.from(labelElements).some((x, i) => {
1167
- const rect = x.getBoundingClientRect();
1168
- if (rect.right > right - 36) {
1169
- setOverflowIndex(i);
1170
- return true;
1171
- }
1172
- return false;
1173
- });
1174
- }
1175
- }
1176
- } else {
1177
- setOverflowIndex(99999);
1178
- }
1179
- }, [size, compact]);
1180
- if (loading) {
1181
- return null;
1182
- }
1183
- if (!displaySystemLabels) {
1184
- labelNodes = labelNodes.filter((x) => !x.data.id.startsWith("system:"));
1185
- }
1186
- const mergedSx = [
1187
- {
1188
- display: "flex",
1189
- gap: 1,
1190
- width: "100%",
1191
- alignItems: "center",
1192
- overflow: "hidden",
1193
- flexWrap: compact ? "no-wrap" : "wrap"
1194
- },
1195
- ...Array.isArray(sx) ? sx : [sx]
1196
- ];
1197
- return /* @__PURE__ */ jsxs(Box$1, { sx: mergedSx, ref: labelsWrapperRef, children: [
1198
- prepend,
1199
- labelNodes.map((item, index) => {
1200
- if (!item) {
1201
- return null;
1202
- }
1203
- const visible = index < overflowIndex;
1204
- let extra = null;
1205
- if (index === overflowIndex) {
1206
- extra = /* @__PURE__ */ jsx(
1207
- Box$1,
1208
- {
1209
- sx: {
1210
- display: "inline-flex",
1211
- ...compact && { height: 20, lineHeight: "20px" },
1212
- color: "text.secondary",
1213
- fontWeight: "bold",
1214
- fontSize: 14
1215
- },
1216
- children: `+${labelNodes.length - overflowIndex}`
1217
- },
1218
- "overflow-label"
1219
- );
1220
- }
1221
- let labelChip = /* @__PURE__ */ jsx(
1222
- LabelChip,
1223
- {
1224
- label: item,
1225
- onClick: onItemClick,
1226
- sx: {
1227
- visibility: visible ? "visible" : "hidden",
1228
- pointerEvents: visible ? "auto" : "none"
1229
- }
1230
- },
1231
- item.data.id
1232
- );
1233
- if (renderLabel) {
1234
- labelChip = renderLabel(item, labelChip);
1235
- }
1236
- if (extra) {
1237
- return [extra, labelChip];
1238
- }
1239
- return labelChip;
1240
- })
1241
- ] });
1242
- }
1243
1263
  function LabelsInput({
1244
1264
  value = [],
1245
1265
  onChange,
package/dist/index.umd.js CHANGED
@@ -1,6 +1,6 @@
1
1
  (function(global, factory) {
2
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react/jsx-runtime"), require("react"), require("@mui/icons-material"), require("@mui/material/Box"), require("@mui/material/styles"), require("react-arborist"), require("@iconify/react"), require("lodash/omit"), require("react-select"), require("@mui/material"), require("@arcblock/ux/lib/Locale/context"), require("ahooks"), require("unstated-next"), require("performant-array-to-tree"), require("@mui/icons-material/Close"), require("@mui/icons-material/Done"), require("chroma-js")) : typeof define === "function" && define.amd ? define(["exports", "react/jsx-runtime", "react", "@mui/icons-material", "@mui/material/Box", "@mui/material/styles", "react-arborist", "@iconify/react", "lodash/omit", "react-select", "@mui/material", "@arcblock/ux/lib/Locale/context", "ahooks", "unstated-next", "performant-array-to-tree", "@mui/icons-material/Close", "@mui/icons-material/Done", "chroma-js"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.BlockletLabels = {}, global.jsxRuntime, global.react, global.iconsMaterial, global.Box, global.styles, global.reactArborist, global.react$1, global.omit, global.Select, global.material, global.context, global.ahooks, global.unstatedNext, global.performantArrayToTree, global.CloseIcon, global.DoneIcon, global.chroma));
3
- })(this, function(exports2, jsxRuntime, react, iconsMaterial, Box, styles, reactArborist, react$1, omit, Select, material, context, ahooks, unstatedNext, performantArrayToTree, CloseIcon, DoneIcon, chroma) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react/jsx-runtime"), require("react"), require("@mui/icons-material"), require("@mui/material/Box"), require("@mui/material/styles"), require("react-arborist"), require("@iconify/react"), require("lodash/omit"), require("react-select"), require("@mui/material"), require("@arcblock/ux/lib/Locale/context"), require("ahooks"), require("unstated-next"), require("performant-array-to-tree"), require("@mui/icons-material/Close"), require("@mui/icons-material/Done"), require("chroma-js")) : typeof define === "function" && define.amd ? define(["exports", "react/jsx-runtime", "react", "@mui/icons-material", "@mui/material/Box", "@mui/material/styles", "react-arborist", "@iconify/react", "lodash/omit", "react-select", "@mui/material", "@arcblock/ux/lib/Locale/context", "ahooks", "unstated-next", "performant-array-to-tree", "@mui/icons-material/Close", "@mui/icons-material/Done", "chroma-js"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.BlockletLabels = {}, global.jsxRuntime, global.react, global.iconsMaterial, global.Box, global.styles, global.reactArborist, global.react$1, global.omit, global.Select, global.material, global.context, global.ahooks, global.unstatedNext, global.performantArrayToTree, global.CloseOutlineIcon, global.DoneIcon, global.chroma));
3
+ })(this, function(exports2, jsxRuntime, react, iconsMaterial, Box, styles, reactArborist, react$1, omit, Select, material, context, ahooks, unstatedNext, performantArrayToTree, CloseOutlineIcon, DoneIcon, chroma) {
4
4
  "use strict";var __defProp = Object.defineProperty;
5
5
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
6
  var __publicField = (obj, key, value) => {
@@ -573,6 +573,9 @@ var __publicField = (obj, key, value) => {
573
573
  var _a;
574
574
  return ((_a = nodesKeyById[id]) == null ? void 0 : _a.getFullName(locale)) ?? id;
575
575
  };
576
+ const parseLabelsStr = react.useCallback((labelIdsStr) => {
577
+ return (labelIdsStr == null ? void 0 : labelIdsStr.split(",").filter(Boolean)) || [];
578
+ }, []);
576
579
  return {
577
580
  ...state,
578
581
  flattenedLabels: flattened,
@@ -587,7 +590,8 @@ var __publicField = (obj, key, value) => {
587
590
  addLabelNode,
588
591
  updateLabelNode,
589
592
  removeLabelNode,
590
- getFullLabelName
593
+ getFullLabelName,
594
+ parseLabelsStr
591
595
  };
592
596
  };
593
597
  const LabelsContainer = unstatedNext.createContainer(useLabels);
@@ -739,6 +743,197 @@ var __publicField = (obj, key, value) => {
739
743
  ] });
740
744
  }
741
745
  const mdiTagPlusOutline = (props) => /* @__PURE__ */ jsxRuntime.jsx("svg", { viewBox: "0 0 24 24", width: "1.2em", height: "1.2em", ...props, children: /* @__PURE__ */ jsxRuntime.jsx("path", { fill: "currentColor", d: "M6.5 5A1.5 1.5 0 1 0 8 6.5A1.5 1.5 0 0 0 6.5 5m0 0A1.5 1.5 0 1 0 8 6.5A1.5 1.5 0 0 0 6.5 5m14.91 6.58l-9-9A2 2 0 0 0 11 2H4a2 2 0 0 0-2 2v7a2 2 0 0 0 .59 1.42l.41.4a5.62 5.62 0 0 1 2.08-.74L4 11V4h7l9 9l-7 7l-1.08-1.08a5.57 5.57 0 0 1-.74 2.08l.41.41A2 2 0 0 0 13 22a2 2 0 0 0 1.41-.59l7-7A2 2 0 0 0 22 13a2 2 0 0 0-.59-1.42M6.5 5A1.5 1.5 0 1 0 8 6.5A1.5 1.5 0 0 0 6.5 5M10 19H7v3H5v-3H2v-2h3v-3h2v3h3Z" }) });
746
+ const getTextColor = (color) => {
747
+ return chroma(color).hex();
748
+ };
749
+ const getBorderColor = (color) => {
750
+ if (chroma(color).luminance() > 0.5) {
751
+ return chroma(color).darken(3).hex();
752
+ }
753
+ return chroma(color).brighten(0.5).alpha(0.25).hex();
754
+ };
755
+ const getBackgroundColor = (color) => {
756
+ if (chroma(color).luminance() > 0.5) {
757
+ return chroma(color).darken(2.5).hex();
758
+ }
759
+ return chroma(color).brighten(2.5).alpha(0.25).hex();
760
+ };
761
+ const getFilterStyle = (color) => {
762
+ if (chroma(color).luminance() > 0.5) {
763
+ return "brightness(0.85) contrast(1.2)";
764
+ }
765
+ return "brightness(0.85) contrast(1.2)";
766
+ };
767
+ function LabelChip({
768
+ label,
769
+ onDelete,
770
+ sx,
771
+ fullName = true,
772
+ onClick,
773
+ disabled = false
774
+ }) {
775
+ const { getFullLabelName, getLabelName } = LabelsContainer.useContainer();
776
+ const mergedSx = [
777
+ {
778
+ height: 20,
779
+ borderRadius: 0.5,
780
+ fontSize: 12,
781
+ fontWeight: 500,
782
+ color: `${getTextColor(label.data.color)} !important`,
783
+ bgcolor: `${getBackgroundColor(label.data.color)} !important`,
784
+ transition: "filter 0.2s",
785
+ borderColor: `${getBorderColor(label.data.color)} !important`,
786
+ // -webkit-text-fill-color
787
+ WebkitTextFillColor: `${getTextColor(label.data.color)} !important`,
788
+ ".MuiChip-deleteIcon": {
789
+ color: `${getTextColor(label.data.color)} !important`,
790
+ cursor: "pointer",
791
+ transition: "transform 0.3s",
792
+ "&:hover": {
793
+ transform: "rotate(90deg)"
794
+ }
795
+ },
796
+ ".MuiChip-label": {
797
+ px: 0.5,
798
+ maxHeight: 20
799
+ },
800
+ ...onClick && {
801
+ cursor: "pointer",
802
+ "&:hover": {
803
+ filter: getFilterStyle(label.data.color)
804
+ }
805
+ }
806
+ },
807
+ ...Array.isArray(sx) ? sx : [sx]
808
+ ];
809
+ const hasDelete = !disabled && !!onDelete;
810
+ const hasOnClick = !disabled && !!onClick;
811
+ return (
812
+ // @ts-ignore
813
+ /* @__PURE__ */ jsxRuntime.jsx(
814
+ material.Chip,
815
+ {
816
+ label: fullName ? getFullLabelName(label.data.id) : getLabelName(label.data.id),
817
+ variant: "outlined",
818
+ size: "small",
819
+ ...hasDelete && {
820
+ onDelete: (e) => {
821
+ e.stopPropagation();
822
+ e.preventDefault();
823
+ onDelete(label);
824
+ },
825
+ deleteIcon: /* @__PURE__ */ jsxRuntime.jsx(CloseOutlineIcon, {})
826
+ },
827
+ ...hasOnClick && {
828
+ onClick: (e) => {
829
+ e.stopPropagation();
830
+ e.preventDefault();
831
+ onClick(label);
832
+ }
833
+ },
834
+ sx: mergedSx
835
+ },
836
+ label.data.id
837
+ )
838
+ );
839
+ }
840
+ function Labels2({
841
+ compact = true,
842
+ labels,
843
+ sx,
844
+ renderLabel,
845
+ prepend,
846
+ displaySystemLabels = true,
847
+ onItemClick
848
+ }) {
849
+ const { getLabelsByIds, loading } = LabelsContainer.useContainer();
850
+ const labelsWrapperRef = react.useRef(null);
851
+ const [overflowIndex, setOverflowIndex] = react.useState(99999);
852
+ let labelNodes = getLabelsByIds(labels || []);
853
+ const size = ahooks.useSize(labelsWrapperRef);
854
+ ahooks.useDeepCompareLayoutEffect(() => {
855
+ if (compact) {
856
+ if (labelsWrapperRef.current) {
857
+ const { right } = labelsWrapperRef.current.getBoundingClientRect();
858
+ const labelElements = labelsWrapperRef.current.querySelectorAll(".MuiChip-root");
859
+ if ((labelElements == null ? void 0 : labelElements.length) > 0) {
860
+ Array.from(labelElements).some((x, i) => {
861
+ const rect = x.getBoundingClientRect();
862
+ if (rect.right > right - 36) {
863
+ setOverflowIndex(i);
864
+ return true;
865
+ }
866
+ return false;
867
+ });
868
+ }
869
+ }
870
+ } else {
871
+ setOverflowIndex(99999);
872
+ }
873
+ }, [size, compact]);
874
+ if (loading) {
875
+ return null;
876
+ }
877
+ if (!displaySystemLabels) {
878
+ labelNodes = labelNodes.filter((x) => !x.data.id.startsWith("system:"));
879
+ }
880
+ const mergedSx = [
881
+ {
882
+ display: "flex",
883
+ gap: 1,
884
+ width: "100%",
885
+ alignItems: "center",
886
+ overflow: "hidden",
887
+ flexWrap: compact ? "no-wrap" : "wrap"
888
+ },
889
+ ...Array.isArray(sx) ? sx : [sx]
890
+ ];
891
+ return /* @__PURE__ */ jsxRuntime.jsxs(material.Box, { sx: mergedSx, ref: labelsWrapperRef, children: [
892
+ prepend,
893
+ labelNodes.map((item, index) => {
894
+ if (!item) {
895
+ return null;
896
+ }
897
+ const visible = index < overflowIndex;
898
+ let extra = null;
899
+ if (index === overflowIndex) {
900
+ extra = /* @__PURE__ */ jsxRuntime.jsx(
901
+ material.Box,
902
+ {
903
+ sx: {
904
+ display: "inline-flex",
905
+ ...compact && { height: 20, lineHeight: "20px" },
906
+ color: "text.secondary",
907
+ fontWeight: "bold",
908
+ fontSize: 14
909
+ },
910
+ children: `+${labelNodes.length - overflowIndex}`
911
+ },
912
+ "overflow-label"
913
+ );
914
+ }
915
+ let labelChip = /* @__PURE__ */ jsxRuntime.jsx(
916
+ LabelChip,
917
+ {
918
+ label: item,
919
+ onClick: onItemClick,
920
+ sx: {
921
+ visibility: visible ? "visible" : "hidden",
922
+ pointerEvents: visible ? "auto" : "none"
923
+ }
924
+ },
925
+ item.data.id
926
+ );
927
+ if (renderLabel) {
928
+ labelChip = renderLabel(item, labelChip);
929
+ }
930
+ if (extra) {
931
+ return [extra, labelChip];
932
+ }
933
+ return labelChip;
934
+ })
935
+ ] });
936
+ }
742
937
  function PopperComponent({
743
938
  disablePortal,
744
939
  anchorEl,
@@ -789,7 +984,8 @@ var __publicField = (obj, key, value) => {
789
984
  trigger,
790
985
  multiple = true,
791
986
  updateImmediately = true,
792
- excludes = []
987
+ excludes = [],
988
+ disabled = false
793
989
  }) {
794
990
  const { locale } = context.useLocaleContext();
795
991
  const { flattenedLabels: labels, getLabelsByIds, loading, createLabel } = LabelsContainer.useContainer();
@@ -807,6 +1003,9 @@ var __publicField = (obj, key, value) => {
807
1003
  }, [labels]);
808
1004
  const theme = material.useTheme();
809
1005
  const handleClick = (event) => {
1006
+ if (disabled) {
1007
+ return;
1008
+ }
810
1009
  event.preventDefault();
811
1010
  setPendingValue(value);
812
1011
  setAnchorEl(event.currentTarget);
@@ -948,8 +1147,8 @@ var __publicField = (obj, key, value) => {
948
1147
  {
949
1148
  component: "span",
950
1149
  sx: {
951
- width: 14,
952
- height: 14,
1150
+ width: 16,
1151
+ height: 16,
953
1152
  flexShrink: 0,
954
1153
  borderRadius: "3px",
955
1154
  mr: 1
@@ -962,17 +1161,16 @@ var __publicField = (obj, key, value) => {
962
1161
  {
963
1162
  sx: {
964
1163
  flexGrow: 1,
965
- "& span": {
966
- color: theme.palette.mode === "light" ? "#586069" : "#8b949e"
967
- }
1164
+ alignItems: "center",
1165
+ display: "flex"
968
1166
  },
969
- children: option.getFullName(locale)
1167
+ children: /* @__PURE__ */ jsxRuntime.jsx(LabelChip, { label: option, disabled })
970
1168
  }
971
1169
  ),
972
1170
  /* @__PURE__ */ jsxRuntime.jsx(
973
1171
  material.Box,
974
1172
  {
975
- component: CloseIcon,
1173
+ component: CloseOutlineIcon,
976
1174
  sx: { opacity: 0.6, width: 18, height: 18 },
977
1175
  style: {
978
1176
  visibility: selected ? "visible" : "hidden"
@@ -1049,184 +1247,6 @@ var __publicField = (obj, key, value) => {
1049
1247
  )
1050
1248
  ] });
1051
1249
  }
1052
- const getTextColor = (color) => {
1053
- return chroma(color).hex();
1054
- };
1055
- const getBorderColor = (color) => {
1056
- if (chroma(color).luminance() > 0.5) {
1057
- return chroma(color).darken(3).hex();
1058
- }
1059
- return chroma(color).brighten(0.5).alpha(0.25).hex();
1060
- };
1061
- const getBackgroundColor = (color) => {
1062
- if (chroma(color).luminance() > 0.5) {
1063
- return chroma(color).darken(2.5).hex();
1064
- }
1065
- return chroma(color).brighten(2.5).alpha(0.25).hex();
1066
- };
1067
- const getFilterStyle = (color) => {
1068
- if (chroma(color).luminance() > 0.5) {
1069
- return "brightness(0.85) contrast(1.2)";
1070
- }
1071
- return "brightness(0.85) contrast(1.2)";
1072
- };
1073
- function LabelChip({
1074
- label,
1075
- onDelete,
1076
- sx,
1077
- fullName = true,
1078
- onClick
1079
- }) {
1080
- const { getFullLabelName, getLabelName } = LabelsContainer.useContainer();
1081
- const mergedSx = [
1082
- {
1083
- height: 20,
1084
- borderRadius: 0.5,
1085
- fontSize: 12,
1086
- fontWeight: 500,
1087
- color: `${getTextColor(label.data.color)} !important`,
1088
- bgcolor: `${getBackgroundColor(label.data.color)} !important`,
1089
- transition: "filter 0.2s",
1090
- borderColor: `${getBorderColor(label.data.color)} !important`,
1091
- ".MuiChip-label": {
1092
- p: 0.5
1093
- },
1094
- span: {},
1095
- ...onClick && {
1096
- cursor: "pointer",
1097
- "&:hover": {
1098
- filter: getFilterStyle(label.data.color)
1099
- }
1100
- }
1101
- },
1102
- ...Array.isArray(sx) ? sx : [sx]
1103
- ];
1104
- return (
1105
- // @ts-ignore
1106
- /* @__PURE__ */ jsxRuntime.jsx(
1107
- material.Chip,
1108
- {
1109
- label: fullName ? getFullLabelName(label.data.id) : getLabelName(label.data.id),
1110
- variant: "outlined",
1111
- size: "small",
1112
- ...onDelete && {
1113
- onDelete: (e) => {
1114
- e.stopPropagation();
1115
- e.preventDefault();
1116
- onDelete(label);
1117
- },
1118
- deleteIcon: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon, {})
1119
- },
1120
- ...onClick && {
1121
- onClick: (e) => {
1122
- e.stopPropagation();
1123
- e.preventDefault();
1124
- onClick(label);
1125
- }
1126
- },
1127
- sx: mergedSx
1128
- },
1129
- label.data.id
1130
- )
1131
- );
1132
- }
1133
- function Labels2({
1134
- compact = true,
1135
- labels,
1136
- sx,
1137
- renderLabel,
1138
- prepend,
1139
- displaySystemLabels = true,
1140
- onItemClick
1141
- }) {
1142
- const { getLabelsByIds, loading } = LabelsContainer.useContainer();
1143
- const labelsWrapperRef = react.useRef(null);
1144
- const [overflowIndex, setOverflowIndex] = react.useState(99999);
1145
- let labelNodes = getLabelsByIds(labels || []);
1146
- const size = ahooks.useSize(labelsWrapperRef);
1147
- ahooks.useDeepCompareLayoutEffect(() => {
1148
- if (compact) {
1149
- if (labelsWrapperRef.current) {
1150
- const { right } = labelsWrapperRef.current.getBoundingClientRect();
1151
- const labelElements = labelsWrapperRef.current.querySelectorAll(".MuiChip-root");
1152
- if ((labelElements == null ? void 0 : labelElements.length) > 0) {
1153
- Array.from(labelElements).some((x, i) => {
1154
- const rect = x.getBoundingClientRect();
1155
- if (rect.right > right - 36) {
1156
- setOverflowIndex(i);
1157
- return true;
1158
- }
1159
- return false;
1160
- });
1161
- }
1162
- }
1163
- } else {
1164
- setOverflowIndex(99999);
1165
- }
1166
- }, [size, compact]);
1167
- if (loading) {
1168
- return null;
1169
- }
1170
- if (!displaySystemLabels) {
1171
- labelNodes = labelNodes.filter((x) => !x.data.id.startsWith("system:"));
1172
- }
1173
- const mergedSx = [
1174
- {
1175
- display: "flex",
1176
- gap: 1,
1177
- width: "100%",
1178
- alignItems: "center",
1179
- overflow: "hidden",
1180
- flexWrap: compact ? "no-wrap" : "wrap"
1181
- },
1182
- ...Array.isArray(sx) ? sx : [sx]
1183
- ];
1184
- return /* @__PURE__ */ jsxRuntime.jsxs(material.Box, { sx: mergedSx, ref: labelsWrapperRef, children: [
1185
- prepend,
1186
- labelNodes.map((item, index) => {
1187
- if (!item) {
1188
- return null;
1189
- }
1190
- const visible = index < overflowIndex;
1191
- let extra = null;
1192
- if (index === overflowIndex) {
1193
- extra = /* @__PURE__ */ jsxRuntime.jsx(
1194
- material.Box,
1195
- {
1196
- sx: {
1197
- display: "inline-flex",
1198
- ...compact && { height: 20, lineHeight: "20px" },
1199
- color: "text.secondary",
1200
- fontWeight: "bold",
1201
- fontSize: 14
1202
- },
1203
- children: `+${labelNodes.length - overflowIndex}`
1204
- },
1205
- "overflow-label"
1206
- );
1207
- }
1208
- let labelChip = /* @__PURE__ */ jsxRuntime.jsx(
1209
- LabelChip,
1210
- {
1211
- label: item,
1212
- onClick: onItemClick,
1213
- sx: {
1214
- visibility: visible ? "visible" : "hidden",
1215
- pointerEvents: visible ? "auto" : "none"
1216
- }
1217
- },
1218
- item.data.id
1219
- );
1220
- if (renderLabel) {
1221
- labelChip = renderLabel(item, labelChip);
1222
- }
1223
- if (extra) {
1224
- return [extra, labelChip];
1225
- }
1226
- return labelChip;
1227
- })
1228
- ] });
1229
- }
1230
1250
  function LabelsInput({
1231
1251
  value = [],
1232
1252
  onChange,
@@ -11,5 +11,6 @@ export interface GithubLabelPickerProps {
11
11
  multiple?: boolean;
12
12
  updateImmediately?: boolean;
13
13
  excludes?: string[];
14
+ disabled?: boolean;
14
15
  }
15
- export declare function GithubLabelPicker({ value, onChange, title, noLabelsText, buttonSx, actions, trigger, multiple, updateImmediately, excludes, }: GithubLabelPickerProps): import("react/jsx-runtime").JSX.Element | null;
16
+ export declare function GithubLabelPicker({ value, onChange, title, noLabelsText, buttonSx, actions, trigger, multiple, updateImmediately, excludes, disabled, }: GithubLabelPickerProps): import("react/jsx-runtime").JSX.Element | null;
@@ -55,6 +55,7 @@ export declare const LabelsContainer: import("unstated-next").Container<{
55
55
  updateLabelNode: (id: string, payload: LabelPayload) => void;
56
56
  removeLabelNode: (id: string) => void;
57
57
  getFullLabelName: (id: string) => string;
58
+ parseLabelsStr: (labelIdsStr: string) => string[];
58
59
  loading: boolean;
59
60
  tree: LabelTreeNode;
60
61
  stats: {
@@ -10,12 +10,13 @@ interface LabelsProps {
10
10
  onItemClick?: (label: LabelTreeNode) => void;
11
11
  compact?: boolean;
12
12
  }
13
- export declare function LabelChip({ label, onDelete, sx, fullName, onClick, }: {
13
+ export declare function LabelChip({ label, onDelete, sx, fullName, onClick, disabled, }: {
14
14
  label: LabelTreeNode;
15
15
  onDelete?: (label: LabelTreeNode) => void;
16
16
  sx?: SxProps;
17
17
  fullName?: boolean;
18
18
  onClick?: (label: LabelTreeNode) => void;
19
+ disabled?: boolean;
19
20
  }): import("react/jsx-runtime").JSX.Element;
20
21
  export declare function Labels2({ compact, labels, sx, renderLabel, prepend, displaySystemLabels, onItemClick, }: LabelsProps): import("react/jsx-runtime").JSX.Element | null;
21
22
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/labels",
3
- "version": "1.6.178",
3
+ "version": "1.6.180",
4
4
  "files": [
5
5
  "dist"
6
6
  ],
@@ -28,7 +28,7 @@
28
28
  "access": "public"
29
29
  },
30
30
  "dependencies": {
31
- "@blocklet/translation-input": "1.6.178",
31
+ "@blocklet/translation-input": "1.6.180",
32
32
  "@emotion/css": "^11.10.5",
33
33
  "@emotion/react": "^11.10.5",
34
34
  "@emotion/styled": "^11.10.5",
@@ -82,5 +82,5 @@
82
82
  "resolutions": {
83
83
  "react": "^18.2.0"
84
84
  },
85
- "gitHead": "48e04a03997f3131441515fe23863ed721b99366"
85
+ "gitHead": "87889daed2a12027c6d43c52ca59c1bdbacc764c"
86
86
  }