@blocklet/labels 1.6.239 → 1.6.241

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
@@ -791,23 +791,198 @@ const useRecentLabels = () => {
791
791
  };
792
792
  return { recentLabels: validLabels, addRecentLabel };
793
793
  };
794
- function LabelChip$1({ name, selected, ...rest }) {
795
- return /* @__PURE__ */ jsx(
796
- Chip,
794
+ const getTextColor = (color) => {
795
+ return chroma(color).hex();
796
+ };
797
+ const getBorderColor = (color) => {
798
+ if (chroma(color).luminance() > 0.5) {
799
+ return chroma(color).darken(3).hex();
800
+ }
801
+ return chroma(color).brighten(0.5).alpha(0.25).hex();
802
+ };
803
+ const getBackgroundColor = (color) => {
804
+ if (chroma(color).luminance() > 0.5) {
805
+ return chroma(color).darken(2.5).hex();
806
+ }
807
+ return chroma(color).brighten(2.5).alpha(0.25).hex();
808
+ };
809
+ const getFilterStyle = (color) => {
810
+ if (chroma(color).luminance() > 0.5) {
811
+ return "brightness(0.85) contrast(1.2)";
812
+ }
813
+ return "brightness(0.85) contrast(1.2)";
814
+ };
815
+ function LabelChip({
816
+ label,
817
+ onDelete,
818
+ sx,
819
+ fullName = true,
820
+ onClick,
821
+ disabled = false,
822
+ renderName = (name) => name
823
+ }) {
824
+ const { getFullLabelName, getLabelName } = LabelsContainer.useContainer();
825
+ const mergedSx = [
797
826
  {
798
- label: name,
799
- variant: selected ? "filled" : "outlined",
800
- color: "primary",
801
- size: "small",
802
- sx: {
803
- fontWeight: "medium",
804
- borderRadius: 0.75,
805
- ...!selected && { bgcolor: "grey.50", borderColor: "grey.300", color: "text.secondary" }
827
+ height: 20,
828
+ borderRadius: 0.5,
829
+ fontSize: 12,
830
+ fontWeight: 500,
831
+ color: `${getTextColor(label.data.color)} !important`,
832
+ bgcolor: `${getBackgroundColor(label.data.color)} !important`,
833
+ transition: "filter 0.2s",
834
+ borderColor: `${getBorderColor(label.data.color)} !important`,
835
+ // -webkit-text-fill-color
836
+ WebkitTextFillColor: `${getTextColor(label.data.color)} !important`,
837
+ ".MuiChip-deleteIcon": {
838
+ color: `${getTextColor(label.data.color)} !important`,
839
+ cursor: "pointer",
840
+ transition: "transform 0.3s",
841
+ "&:hover": {
842
+ transform: "rotate(90deg)"
843
+ }
806
844
  },
807
- ...rest
808
- }
845
+ ".MuiChip-label": {
846
+ px: 0.5,
847
+ maxHeight: 20
848
+ },
849
+ ...onClick && {
850
+ cursor: "pointer",
851
+ "&:hover": {
852
+ filter: getFilterStyle(label.data.color)
853
+ }
854
+ }
855
+ },
856
+ ...Array.isArray(sx) ? sx : [sx]
857
+ ];
858
+ const hasDelete = !disabled && !!onDelete;
859
+ const hasOnClick = !disabled && !!onClick;
860
+ return (
861
+ // @ts-ignore
862
+ /* @__PURE__ */ jsx(
863
+ Chip,
864
+ {
865
+ label: renderName(fullName ? getFullLabelName(label.data.id) : getLabelName(label.data.id)),
866
+ variant: "outlined",
867
+ size: "small",
868
+ ...hasDelete && {
869
+ onDelete: (e) => {
870
+ e.stopPropagation();
871
+ e.preventDefault();
872
+ onDelete(label);
873
+ },
874
+ deleteIcon: /* @__PURE__ */ jsx(CloseOutlineIcon, {})
875
+ },
876
+ ...hasOnClick && {
877
+ onClick: (e) => {
878
+ e.stopPropagation();
879
+ e.preventDefault();
880
+ onClick(label);
881
+ }
882
+ },
883
+ sx: mergedSx
884
+ },
885
+ label.data.id
886
+ )
809
887
  );
810
888
  }
889
+ function Labels2({
890
+ compact = true,
891
+ labels,
892
+ sx,
893
+ renderLabel,
894
+ prepend,
895
+ displaySystemLabels = true,
896
+ onItemClick
897
+ }) {
898
+ const { getLabelsByIds, loading } = LabelsContainer.useContainer();
899
+ const labelsWrapperRef = useRef(null);
900
+ const [overflowIndex, setOverflowIndex] = useState(99999);
901
+ let labelNodes = getLabelsByIds(labels || []);
902
+ const size = useSize(labelsWrapperRef);
903
+ useDeepCompareLayoutEffect(() => {
904
+ if (compact) {
905
+ if (labelsWrapperRef.current) {
906
+ const { right } = labelsWrapperRef.current.getBoundingClientRect();
907
+ const labelElements = labelsWrapperRef.current.querySelectorAll(".MuiChip-root");
908
+ if ((labelElements == null ? void 0 : labelElements.length) > 0) {
909
+ Array.from(labelElements).some((x, i) => {
910
+ const rect = x.getBoundingClientRect();
911
+ if (rect.right > right - 36) {
912
+ setOverflowIndex(i);
913
+ return true;
914
+ }
915
+ return false;
916
+ });
917
+ }
918
+ }
919
+ } else {
920
+ setOverflowIndex(99999);
921
+ }
922
+ }, [size, compact]);
923
+ if (loading) {
924
+ return null;
925
+ }
926
+ if (!displaySystemLabels) {
927
+ labelNodes = labelNodes.filter((x) => x.data.type !== "system");
928
+ }
929
+ const mergedSx = [
930
+ {
931
+ display: "flex",
932
+ gap: 1,
933
+ width: "100%",
934
+ alignItems: "center",
935
+ overflow: "hidden",
936
+ flexWrap: compact ? "no-wrap" : "wrap"
937
+ },
938
+ ...Array.isArray(sx) ? sx : [sx]
939
+ ];
940
+ return /* @__PURE__ */ jsxs(Box$1, { sx: mergedSx, ref: labelsWrapperRef, children: [
941
+ prepend,
942
+ labelNodes.map((item, index) => {
943
+ if (!item) {
944
+ return null;
945
+ }
946
+ const visible = index < overflowIndex;
947
+ let extra = null;
948
+ if (index === overflowIndex) {
949
+ extra = /* @__PURE__ */ jsx(
950
+ Box$1,
951
+ {
952
+ sx: {
953
+ display: "inline-flex",
954
+ ...compact && { height: 20, lineHeight: "20px" },
955
+ color: "text.secondary",
956
+ fontWeight: "bold",
957
+ fontSize: 14
958
+ },
959
+ children: `+${labelNodes.length - overflowIndex}`
960
+ },
961
+ "overflow-label"
962
+ );
963
+ }
964
+ let labelChip = /* @__PURE__ */ jsx(
965
+ LabelChip,
966
+ {
967
+ label: item,
968
+ onClick: onItemClick,
969
+ sx: {
970
+ visibility: visible ? "visible" : "hidden",
971
+ pointerEvents: visible ? "auto" : "none"
972
+ }
973
+ },
974
+ item.data.id
975
+ );
976
+ if (renderLabel) {
977
+ labelChip = renderLabel(item, labelChip);
978
+ }
979
+ if (extra) {
980
+ return [extra, labelChip];
981
+ }
982
+ return labelChip;
983
+ })
984
+ ] });
985
+ }
811
986
  function PopperComponent({
812
987
  disablePortal,
813
988
  anchorEl,
@@ -856,13 +1031,7 @@ function GithubLabelPicker({
856
1031
  }) {
857
1032
  const { t, locale } = useLocaleContext();
858
1033
  const { isAdmin, hasAnyPassport } = useSessionContext();
859
- const {
860
- flattenedLabels: labels,
861
- getLabelsByIds,
862
- loading,
863
- createLabel,
864
- getLabelName
865
- } = LabelsContainer.useContainer();
1034
+ const { flattenedLabels: labels, getLabelsByIds, loading, createLabel } = LabelsContainer.useContainer();
866
1035
  const [anchorEl, setAnchorEl] = useState(null);
867
1036
  const [pendingValue, setPendingValue] = useState([]);
868
1037
  const pendingOptions = useMemo(() => getLabelsByIds(pendingValue), [getLabelsByIds, pendingValue]);
@@ -910,6 +1079,16 @@ function GithubLabelPicker({
910
1079
  };
911
1080
  const open = Boolean(anchorEl);
912
1081
  const id = open ? "github-label-picker" : void 0;
1082
+ const getSelectedSx = (selected) => {
1083
+ if (selected) {
1084
+ return {
1085
+ bgcolor: (theme) => `${theme.palette.primary.main} !important`,
1086
+ color: (theme) => `${theme.palette.primary.contrastText} !important`,
1087
+ WebkitTextFillColor: (theme) => `${theme.palette.primary.contrastText} !important`
1088
+ };
1089
+ }
1090
+ return void 0;
1091
+ };
913
1092
  if (loading) {
914
1093
  return null;
915
1094
  }
@@ -1025,7 +1204,19 @@ function GithubLabelPicker({
1025
1204
  }
1026
1205
  }
1027
1206
  },
1028
- /* @__PURE__ */ jsx(LabelChip$1, { name: getLabelName(label.id), selected })
1207
+ /* @__PURE__ */ jsx(
1208
+ LabelChip,
1209
+ {
1210
+ label: option,
1211
+ sx: {
1212
+ height: 24,
1213
+ lineHeight: "24px",
1214
+ ".MuiChip-label": { maxHeight: 24 },
1215
+ ...getSelectedSx(selected)
1216
+ },
1217
+ fullName: false
1218
+ }
1219
+ )
1029
1220
  );
1030
1221
  },
1031
1222
  groupBy: () => "x",
@@ -1033,15 +1224,21 @@ function GithubLabelPicker({
1033
1224
  return /* @__PURE__ */ jsxs(Fragment$1, { children: [
1034
1225
  !!(initialRecentLabels == null ? void 0 : initialRecentLabels.length) && /* @__PURE__ */ jsxs("li", { children: [
1035
1226
  /* @__PURE__ */ jsx(Box$1, { sx: { mb: 0.5, fontSize: 12, fontWeight: "medium" }, children: t("label.recently") }),
1036
- /* @__PURE__ */ jsx(Box$1, { sx: { display: "flex", flexWrap: "wrap", gap: 0.5 }, children: initialRecentLabels.map((x) => {
1227
+ /* @__PURE__ */ jsx(Box$1, { sx: { display: "flex", flexWrap: "wrap", gap: 0.75, mb: 2 }, children: initialRecentLabels.map((x) => {
1037
1228
  const selected = value == null ? void 0 : value.includes(x);
1038
1229
  return /* @__PURE__ */ jsx(
1039
- LabelChip$1,
1230
+ LabelChip,
1040
1231
  {
1041
- name: getLabelName(x),
1042
- selected,
1232
+ label: getLabelsByIds([x])[0],
1233
+ fullName: false,
1043
1234
  onClick: () => {
1044
1235
  handleChange(selected ? pendingValue.filter((y) => y !== x) : [...pendingValue, x]);
1236
+ },
1237
+ sx: {
1238
+ height: 24,
1239
+ lineHeight: "24px",
1240
+ ".MuiChip-label": { maxHeight: 24 },
1241
+ ...getSelectedSx(selected)
1045
1242
  }
1046
1243
  },
1047
1244
  x
@@ -1049,7 +1246,7 @@ function GithubLabelPicker({
1049
1246
  }) })
1050
1247
  ] }),
1051
1248
  /* @__PURE__ */ jsxs("li", { children: [
1052
- /* @__PURE__ */ jsx(Box$1, { sx: { mt: 1, mb: 0.5, fontSize: 12, fontWeight: "medium" }, children: t("label.title") }),
1249
+ /* @__PURE__ */ jsx(Box$1, { sx: { mb: 0.5, fontSize: 12, fontWeight: "medium" }, children: t("label.title") }),
1053
1250
  /* @__PURE__ */ jsx(
1054
1251
  Box$1,
1055
1252
  {
@@ -1058,7 +1255,7 @@ function GithubLabelPicker({
1058
1255
  display: "flex",
1059
1256
  justifyContent: "flex-start",
1060
1257
  flexWrap: "wrap",
1061
- gap: 0.5,
1258
+ gap: 0.75,
1062
1259
  p: 0
1063
1260
  },
1064
1261
  children: params.children
@@ -1130,198 +1327,6 @@ function GithubLabelPicker({
1130
1327
  )
1131
1328
  ] });
1132
1329
  }
1133
- const getTextColor = (color) => {
1134
- return chroma(color).hex();
1135
- };
1136
- const getBorderColor = (color) => {
1137
- if (chroma(color).luminance() > 0.5) {
1138
- return chroma(color).darken(3).hex();
1139
- }
1140
- return chroma(color).brighten(0.5).alpha(0.25).hex();
1141
- };
1142
- const getBackgroundColor = (color) => {
1143
- if (chroma(color).luminance() > 0.5) {
1144
- return chroma(color).darken(2.5).hex();
1145
- }
1146
- return chroma(color).brighten(2.5).alpha(0.25).hex();
1147
- };
1148
- const getFilterStyle = (color) => {
1149
- if (chroma(color).luminance() > 0.5) {
1150
- return "brightness(0.85) contrast(1.2)";
1151
- }
1152
- return "brightness(0.85) contrast(1.2)";
1153
- };
1154
- function LabelChip({
1155
- label,
1156
- onDelete,
1157
- sx,
1158
- fullName = true,
1159
- onClick,
1160
- disabled = false,
1161
- renderName = (name) => name
1162
- }) {
1163
- const { getFullLabelName, getLabelName } = LabelsContainer.useContainer();
1164
- const mergedSx = [
1165
- {
1166
- height: 20,
1167
- borderRadius: 0.5,
1168
- fontSize: 12,
1169
- fontWeight: 500,
1170
- color: `${getTextColor(label.data.color)} !important`,
1171
- bgcolor: `${getBackgroundColor(label.data.color)} !important`,
1172
- transition: "filter 0.2s",
1173
- borderColor: `${getBorderColor(label.data.color)} !important`,
1174
- // -webkit-text-fill-color
1175
- WebkitTextFillColor: `${getTextColor(label.data.color)} !important`,
1176
- ".MuiChip-deleteIcon": {
1177
- color: `${getTextColor(label.data.color)} !important`,
1178
- cursor: "pointer",
1179
- transition: "transform 0.3s",
1180
- "&:hover": {
1181
- transform: "rotate(90deg)"
1182
- }
1183
- },
1184
- ".MuiChip-label": {
1185
- px: 0.5,
1186
- maxHeight: 20
1187
- },
1188
- ...onClick && {
1189
- cursor: "pointer",
1190
- "&:hover": {
1191
- filter: getFilterStyle(label.data.color)
1192
- }
1193
- }
1194
- },
1195
- ...Array.isArray(sx) ? sx : [sx]
1196
- ];
1197
- const hasDelete = !disabled && !!onDelete;
1198
- const hasOnClick = !disabled && !!onClick;
1199
- return (
1200
- // @ts-ignore
1201
- /* @__PURE__ */ jsx(
1202
- Chip,
1203
- {
1204
- label: renderName(fullName ? getFullLabelName(label.data.id) : getLabelName(label.data.id)),
1205
- variant: "outlined",
1206
- size: "small",
1207
- ...hasDelete && {
1208
- onDelete: (e) => {
1209
- e.stopPropagation();
1210
- e.preventDefault();
1211
- onDelete(label);
1212
- },
1213
- deleteIcon: /* @__PURE__ */ jsx(CloseOutlineIcon, {})
1214
- },
1215
- ...hasOnClick && {
1216
- onClick: (e) => {
1217
- e.stopPropagation();
1218
- e.preventDefault();
1219
- onClick(label);
1220
- }
1221
- },
1222
- sx: mergedSx
1223
- },
1224
- label.data.id
1225
- )
1226
- );
1227
- }
1228
- function Labels2({
1229
- compact = true,
1230
- labels,
1231
- sx,
1232
- renderLabel,
1233
- prepend,
1234
- displaySystemLabels = true,
1235
- onItemClick
1236
- }) {
1237
- const { getLabelsByIds, loading } = LabelsContainer.useContainer();
1238
- const labelsWrapperRef = useRef(null);
1239
- const [overflowIndex, setOverflowIndex] = useState(99999);
1240
- let labelNodes = getLabelsByIds(labels || []);
1241
- const size = useSize(labelsWrapperRef);
1242
- useDeepCompareLayoutEffect(() => {
1243
- if (compact) {
1244
- if (labelsWrapperRef.current) {
1245
- const { right } = labelsWrapperRef.current.getBoundingClientRect();
1246
- const labelElements = labelsWrapperRef.current.querySelectorAll(".MuiChip-root");
1247
- if ((labelElements == null ? void 0 : labelElements.length) > 0) {
1248
- Array.from(labelElements).some((x, i) => {
1249
- const rect = x.getBoundingClientRect();
1250
- if (rect.right > right - 36) {
1251
- setOverflowIndex(i);
1252
- return true;
1253
- }
1254
- return false;
1255
- });
1256
- }
1257
- }
1258
- } else {
1259
- setOverflowIndex(99999);
1260
- }
1261
- }, [size, compact]);
1262
- if (loading) {
1263
- return null;
1264
- }
1265
- if (!displaySystemLabels) {
1266
- labelNodes = labelNodes.filter((x) => x.data.type !== "system");
1267
- }
1268
- const mergedSx = [
1269
- {
1270
- display: "flex",
1271
- gap: 1,
1272
- width: "100%",
1273
- alignItems: "center",
1274
- overflow: "hidden",
1275
- flexWrap: compact ? "no-wrap" : "wrap"
1276
- },
1277
- ...Array.isArray(sx) ? sx : [sx]
1278
- ];
1279
- return /* @__PURE__ */ jsxs(Box$1, { sx: mergedSx, ref: labelsWrapperRef, children: [
1280
- prepend,
1281
- labelNodes.map((item, index) => {
1282
- if (!item) {
1283
- return null;
1284
- }
1285
- const visible = index < overflowIndex;
1286
- let extra = null;
1287
- if (index === overflowIndex) {
1288
- extra = /* @__PURE__ */ jsx(
1289
- Box$1,
1290
- {
1291
- sx: {
1292
- display: "inline-flex",
1293
- ...compact && { height: 20, lineHeight: "20px" },
1294
- color: "text.secondary",
1295
- fontWeight: "bold",
1296
- fontSize: 14
1297
- },
1298
- children: `+${labelNodes.length - overflowIndex}`
1299
- },
1300
- "overflow-label"
1301
- );
1302
- }
1303
- let labelChip = /* @__PURE__ */ jsx(
1304
- LabelChip,
1305
- {
1306
- label: item,
1307
- onClick: onItemClick,
1308
- sx: {
1309
- visibility: visible ? "visible" : "hidden",
1310
- pointerEvents: visible ? "auto" : "none"
1311
- }
1312
- },
1313
- item.data.id
1314
- );
1315
- if (renderLabel) {
1316
- labelChip = renderLabel(item, labelChip);
1317
- }
1318
- if (extra) {
1319
- return [extra, labelChip];
1320
- }
1321
- return labelChip;
1322
- })
1323
- ] });
1324
- }
1325
1330
  function LabelsInput({
1326
1331
  value = [],
1327
1332
  onChange,
package/dist/index.umd.js CHANGED
@@ -778,23 +778,198 @@ var __publicField = (obj, key, value) => {
778
778
  };
779
779
  return { recentLabels: validLabels, addRecentLabel };
780
780
  };
781
- function LabelChip$1({ name, selected, ...rest }) {
782
- return /* @__PURE__ */ jsxRuntime.jsx(
783
- material.Chip,
781
+ const getTextColor = (color) => {
782
+ return chroma(color).hex();
783
+ };
784
+ const getBorderColor = (color) => {
785
+ if (chroma(color).luminance() > 0.5) {
786
+ return chroma(color).darken(3).hex();
787
+ }
788
+ return chroma(color).brighten(0.5).alpha(0.25).hex();
789
+ };
790
+ const getBackgroundColor = (color) => {
791
+ if (chroma(color).luminance() > 0.5) {
792
+ return chroma(color).darken(2.5).hex();
793
+ }
794
+ return chroma(color).brighten(2.5).alpha(0.25).hex();
795
+ };
796
+ const getFilterStyle = (color) => {
797
+ if (chroma(color).luminance() > 0.5) {
798
+ return "brightness(0.85) contrast(1.2)";
799
+ }
800
+ return "brightness(0.85) contrast(1.2)";
801
+ };
802
+ function LabelChip({
803
+ label,
804
+ onDelete,
805
+ sx,
806
+ fullName = true,
807
+ onClick,
808
+ disabled = false,
809
+ renderName = (name) => name
810
+ }) {
811
+ const { getFullLabelName, getLabelName } = LabelsContainer.useContainer();
812
+ const mergedSx = [
784
813
  {
785
- label: name,
786
- variant: selected ? "filled" : "outlined",
787
- color: "primary",
788
- size: "small",
789
- sx: {
790
- fontWeight: "medium",
791
- borderRadius: 0.75,
792
- ...!selected && { bgcolor: "grey.50", borderColor: "grey.300", color: "text.secondary" }
814
+ height: 20,
815
+ borderRadius: 0.5,
816
+ fontSize: 12,
817
+ fontWeight: 500,
818
+ color: `${getTextColor(label.data.color)} !important`,
819
+ bgcolor: `${getBackgroundColor(label.data.color)} !important`,
820
+ transition: "filter 0.2s",
821
+ borderColor: `${getBorderColor(label.data.color)} !important`,
822
+ // -webkit-text-fill-color
823
+ WebkitTextFillColor: `${getTextColor(label.data.color)} !important`,
824
+ ".MuiChip-deleteIcon": {
825
+ color: `${getTextColor(label.data.color)} !important`,
826
+ cursor: "pointer",
827
+ transition: "transform 0.3s",
828
+ "&:hover": {
829
+ transform: "rotate(90deg)"
830
+ }
793
831
  },
794
- ...rest
795
- }
832
+ ".MuiChip-label": {
833
+ px: 0.5,
834
+ maxHeight: 20
835
+ },
836
+ ...onClick && {
837
+ cursor: "pointer",
838
+ "&:hover": {
839
+ filter: getFilterStyle(label.data.color)
840
+ }
841
+ }
842
+ },
843
+ ...Array.isArray(sx) ? sx : [sx]
844
+ ];
845
+ const hasDelete = !disabled && !!onDelete;
846
+ const hasOnClick = !disabled && !!onClick;
847
+ return (
848
+ // @ts-ignore
849
+ /* @__PURE__ */ jsxRuntime.jsx(
850
+ material.Chip,
851
+ {
852
+ label: renderName(fullName ? getFullLabelName(label.data.id) : getLabelName(label.data.id)),
853
+ variant: "outlined",
854
+ size: "small",
855
+ ...hasDelete && {
856
+ onDelete: (e) => {
857
+ e.stopPropagation();
858
+ e.preventDefault();
859
+ onDelete(label);
860
+ },
861
+ deleteIcon: /* @__PURE__ */ jsxRuntime.jsx(CloseOutlineIcon, {})
862
+ },
863
+ ...hasOnClick && {
864
+ onClick: (e) => {
865
+ e.stopPropagation();
866
+ e.preventDefault();
867
+ onClick(label);
868
+ }
869
+ },
870
+ sx: mergedSx
871
+ },
872
+ label.data.id
873
+ )
796
874
  );
797
875
  }
876
+ function Labels2({
877
+ compact = true,
878
+ labels,
879
+ sx,
880
+ renderLabel,
881
+ prepend,
882
+ displaySystemLabels = true,
883
+ onItemClick
884
+ }) {
885
+ const { getLabelsByIds, loading } = LabelsContainer.useContainer();
886
+ const labelsWrapperRef = react.useRef(null);
887
+ const [overflowIndex, setOverflowIndex] = react.useState(99999);
888
+ let labelNodes = getLabelsByIds(labels || []);
889
+ const size = ahooks.useSize(labelsWrapperRef);
890
+ ahooks.useDeepCompareLayoutEffect(() => {
891
+ if (compact) {
892
+ if (labelsWrapperRef.current) {
893
+ const { right } = labelsWrapperRef.current.getBoundingClientRect();
894
+ const labelElements = labelsWrapperRef.current.querySelectorAll(".MuiChip-root");
895
+ if ((labelElements == null ? void 0 : labelElements.length) > 0) {
896
+ Array.from(labelElements).some((x, i) => {
897
+ const rect = x.getBoundingClientRect();
898
+ if (rect.right > right - 36) {
899
+ setOverflowIndex(i);
900
+ return true;
901
+ }
902
+ return false;
903
+ });
904
+ }
905
+ }
906
+ } else {
907
+ setOverflowIndex(99999);
908
+ }
909
+ }, [size, compact]);
910
+ if (loading) {
911
+ return null;
912
+ }
913
+ if (!displaySystemLabels) {
914
+ labelNodes = labelNodes.filter((x) => x.data.type !== "system");
915
+ }
916
+ const mergedSx = [
917
+ {
918
+ display: "flex",
919
+ gap: 1,
920
+ width: "100%",
921
+ alignItems: "center",
922
+ overflow: "hidden",
923
+ flexWrap: compact ? "no-wrap" : "wrap"
924
+ },
925
+ ...Array.isArray(sx) ? sx : [sx]
926
+ ];
927
+ return /* @__PURE__ */ jsxRuntime.jsxs(material.Box, { sx: mergedSx, ref: labelsWrapperRef, children: [
928
+ prepend,
929
+ labelNodes.map((item, index) => {
930
+ if (!item) {
931
+ return null;
932
+ }
933
+ const visible = index < overflowIndex;
934
+ let extra = null;
935
+ if (index === overflowIndex) {
936
+ extra = /* @__PURE__ */ jsxRuntime.jsx(
937
+ material.Box,
938
+ {
939
+ sx: {
940
+ display: "inline-flex",
941
+ ...compact && { height: 20, lineHeight: "20px" },
942
+ color: "text.secondary",
943
+ fontWeight: "bold",
944
+ fontSize: 14
945
+ },
946
+ children: `+${labelNodes.length - overflowIndex}`
947
+ },
948
+ "overflow-label"
949
+ );
950
+ }
951
+ let labelChip = /* @__PURE__ */ jsxRuntime.jsx(
952
+ LabelChip,
953
+ {
954
+ label: item,
955
+ onClick: onItemClick,
956
+ sx: {
957
+ visibility: visible ? "visible" : "hidden",
958
+ pointerEvents: visible ? "auto" : "none"
959
+ }
960
+ },
961
+ item.data.id
962
+ );
963
+ if (renderLabel) {
964
+ labelChip = renderLabel(item, labelChip);
965
+ }
966
+ if (extra) {
967
+ return [extra, labelChip];
968
+ }
969
+ return labelChip;
970
+ })
971
+ ] });
972
+ }
798
973
  function PopperComponent({
799
974
  disablePortal,
800
975
  anchorEl,
@@ -843,13 +1018,7 @@ var __publicField = (obj, key, value) => {
843
1018
  }) {
844
1019
  const { t, locale } = context.useLocaleContext();
845
1020
  const { isAdmin, hasAnyPassport } = useSessionContext();
846
- const {
847
- flattenedLabels: labels,
848
- getLabelsByIds,
849
- loading,
850
- createLabel,
851
- getLabelName
852
- } = LabelsContainer.useContainer();
1021
+ const { flattenedLabels: labels, getLabelsByIds, loading, createLabel } = LabelsContainer.useContainer();
853
1022
  const [anchorEl, setAnchorEl] = react.useState(null);
854
1023
  const [pendingValue, setPendingValue] = react.useState([]);
855
1024
  const pendingOptions = react.useMemo(() => getLabelsByIds(pendingValue), [getLabelsByIds, pendingValue]);
@@ -897,6 +1066,16 @@ var __publicField = (obj, key, value) => {
897
1066
  };
898
1067
  const open = Boolean(anchorEl);
899
1068
  const id = open ? "github-label-picker" : void 0;
1069
+ const getSelectedSx = (selected) => {
1070
+ if (selected) {
1071
+ return {
1072
+ bgcolor: (theme) => `${theme.palette.primary.main} !important`,
1073
+ color: (theme) => `${theme.palette.primary.contrastText} !important`,
1074
+ WebkitTextFillColor: (theme) => `${theme.palette.primary.contrastText} !important`
1075
+ };
1076
+ }
1077
+ return void 0;
1078
+ };
900
1079
  if (loading) {
901
1080
  return null;
902
1081
  }
@@ -1012,7 +1191,19 @@ var __publicField = (obj, key, value) => {
1012
1191
  }
1013
1192
  }
1014
1193
  },
1015
- /* @__PURE__ */ jsxRuntime.jsx(LabelChip$1, { name: getLabelName(label.id), selected })
1194
+ /* @__PURE__ */ jsxRuntime.jsx(
1195
+ LabelChip,
1196
+ {
1197
+ label: option,
1198
+ sx: {
1199
+ height: 24,
1200
+ lineHeight: "24px",
1201
+ ".MuiChip-label": { maxHeight: 24 },
1202
+ ...getSelectedSx(selected)
1203
+ },
1204
+ fullName: false
1205
+ }
1206
+ )
1016
1207
  );
1017
1208
  },
1018
1209
  groupBy: () => "x",
@@ -1020,15 +1211,21 @@ var __publicField = (obj, key, value) => {
1020
1211
  return /* @__PURE__ */ jsxRuntime.jsxs(react.Fragment, { children: [
1021
1212
  !!(initialRecentLabels == null ? void 0 : initialRecentLabels.length) && /* @__PURE__ */ jsxRuntime.jsxs("li", { children: [
1022
1213
  /* @__PURE__ */ jsxRuntime.jsx(material.Box, { sx: { mb: 0.5, fontSize: 12, fontWeight: "medium" }, children: t("label.recently") }),
1023
- /* @__PURE__ */ jsxRuntime.jsx(material.Box, { sx: { display: "flex", flexWrap: "wrap", gap: 0.5 }, children: initialRecentLabels.map((x) => {
1214
+ /* @__PURE__ */ jsxRuntime.jsx(material.Box, { sx: { display: "flex", flexWrap: "wrap", gap: 0.75, mb: 2 }, children: initialRecentLabels.map((x) => {
1024
1215
  const selected = value == null ? void 0 : value.includes(x);
1025
1216
  return /* @__PURE__ */ jsxRuntime.jsx(
1026
- LabelChip$1,
1217
+ LabelChip,
1027
1218
  {
1028
- name: getLabelName(x),
1029
- selected,
1219
+ label: getLabelsByIds([x])[0],
1220
+ fullName: false,
1030
1221
  onClick: () => {
1031
1222
  handleChange(selected ? pendingValue.filter((y) => y !== x) : [...pendingValue, x]);
1223
+ },
1224
+ sx: {
1225
+ height: 24,
1226
+ lineHeight: "24px",
1227
+ ".MuiChip-label": { maxHeight: 24 },
1228
+ ...getSelectedSx(selected)
1032
1229
  }
1033
1230
  },
1034
1231
  x
@@ -1036,7 +1233,7 @@ var __publicField = (obj, key, value) => {
1036
1233
  }) })
1037
1234
  ] }),
1038
1235
  /* @__PURE__ */ jsxRuntime.jsxs("li", { children: [
1039
- /* @__PURE__ */ jsxRuntime.jsx(material.Box, { sx: { mt: 1, mb: 0.5, fontSize: 12, fontWeight: "medium" }, children: t("label.title") }),
1236
+ /* @__PURE__ */ jsxRuntime.jsx(material.Box, { sx: { mb: 0.5, fontSize: 12, fontWeight: "medium" }, children: t("label.title") }),
1040
1237
  /* @__PURE__ */ jsxRuntime.jsx(
1041
1238
  material.Box,
1042
1239
  {
@@ -1045,7 +1242,7 @@ var __publicField = (obj, key, value) => {
1045
1242
  display: "flex",
1046
1243
  justifyContent: "flex-start",
1047
1244
  flexWrap: "wrap",
1048
- gap: 0.5,
1245
+ gap: 0.75,
1049
1246
  p: 0
1050
1247
  },
1051
1248
  children: params.children
@@ -1117,198 +1314,6 @@ var __publicField = (obj, key, value) => {
1117
1314
  )
1118
1315
  ] });
1119
1316
  }
1120
- const getTextColor = (color) => {
1121
- return chroma(color).hex();
1122
- };
1123
- const getBorderColor = (color) => {
1124
- if (chroma(color).luminance() > 0.5) {
1125
- return chroma(color).darken(3).hex();
1126
- }
1127
- return chroma(color).brighten(0.5).alpha(0.25).hex();
1128
- };
1129
- const getBackgroundColor = (color) => {
1130
- if (chroma(color).luminance() > 0.5) {
1131
- return chroma(color).darken(2.5).hex();
1132
- }
1133
- return chroma(color).brighten(2.5).alpha(0.25).hex();
1134
- };
1135
- const getFilterStyle = (color) => {
1136
- if (chroma(color).luminance() > 0.5) {
1137
- return "brightness(0.85) contrast(1.2)";
1138
- }
1139
- return "brightness(0.85) contrast(1.2)";
1140
- };
1141
- function LabelChip({
1142
- label,
1143
- onDelete,
1144
- sx,
1145
- fullName = true,
1146
- onClick,
1147
- disabled = false,
1148
- renderName = (name) => name
1149
- }) {
1150
- const { getFullLabelName, getLabelName } = LabelsContainer.useContainer();
1151
- const mergedSx = [
1152
- {
1153
- height: 20,
1154
- borderRadius: 0.5,
1155
- fontSize: 12,
1156
- fontWeight: 500,
1157
- color: `${getTextColor(label.data.color)} !important`,
1158
- bgcolor: `${getBackgroundColor(label.data.color)} !important`,
1159
- transition: "filter 0.2s",
1160
- borderColor: `${getBorderColor(label.data.color)} !important`,
1161
- // -webkit-text-fill-color
1162
- WebkitTextFillColor: `${getTextColor(label.data.color)} !important`,
1163
- ".MuiChip-deleteIcon": {
1164
- color: `${getTextColor(label.data.color)} !important`,
1165
- cursor: "pointer",
1166
- transition: "transform 0.3s",
1167
- "&:hover": {
1168
- transform: "rotate(90deg)"
1169
- }
1170
- },
1171
- ".MuiChip-label": {
1172
- px: 0.5,
1173
- maxHeight: 20
1174
- },
1175
- ...onClick && {
1176
- cursor: "pointer",
1177
- "&:hover": {
1178
- filter: getFilterStyle(label.data.color)
1179
- }
1180
- }
1181
- },
1182
- ...Array.isArray(sx) ? sx : [sx]
1183
- ];
1184
- const hasDelete = !disabled && !!onDelete;
1185
- const hasOnClick = !disabled && !!onClick;
1186
- return (
1187
- // @ts-ignore
1188
- /* @__PURE__ */ jsxRuntime.jsx(
1189
- material.Chip,
1190
- {
1191
- label: renderName(fullName ? getFullLabelName(label.data.id) : getLabelName(label.data.id)),
1192
- variant: "outlined",
1193
- size: "small",
1194
- ...hasDelete && {
1195
- onDelete: (e) => {
1196
- e.stopPropagation();
1197
- e.preventDefault();
1198
- onDelete(label);
1199
- },
1200
- deleteIcon: /* @__PURE__ */ jsxRuntime.jsx(CloseOutlineIcon, {})
1201
- },
1202
- ...hasOnClick && {
1203
- onClick: (e) => {
1204
- e.stopPropagation();
1205
- e.preventDefault();
1206
- onClick(label);
1207
- }
1208
- },
1209
- sx: mergedSx
1210
- },
1211
- label.data.id
1212
- )
1213
- );
1214
- }
1215
- function Labels2({
1216
- compact = true,
1217
- labels,
1218
- sx,
1219
- renderLabel,
1220
- prepend,
1221
- displaySystemLabels = true,
1222
- onItemClick
1223
- }) {
1224
- const { getLabelsByIds, loading } = LabelsContainer.useContainer();
1225
- const labelsWrapperRef = react.useRef(null);
1226
- const [overflowIndex, setOverflowIndex] = react.useState(99999);
1227
- let labelNodes = getLabelsByIds(labels || []);
1228
- const size = ahooks.useSize(labelsWrapperRef);
1229
- ahooks.useDeepCompareLayoutEffect(() => {
1230
- if (compact) {
1231
- if (labelsWrapperRef.current) {
1232
- const { right } = labelsWrapperRef.current.getBoundingClientRect();
1233
- const labelElements = labelsWrapperRef.current.querySelectorAll(".MuiChip-root");
1234
- if ((labelElements == null ? void 0 : labelElements.length) > 0) {
1235
- Array.from(labelElements).some((x, i) => {
1236
- const rect = x.getBoundingClientRect();
1237
- if (rect.right > right - 36) {
1238
- setOverflowIndex(i);
1239
- return true;
1240
- }
1241
- return false;
1242
- });
1243
- }
1244
- }
1245
- } else {
1246
- setOverflowIndex(99999);
1247
- }
1248
- }, [size, compact]);
1249
- if (loading) {
1250
- return null;
1251
- }
1252
- if (!displaySystemLabels) {
1253
- labelNodes = labelNodes.filter((x) => x.data.type !== "system");
1254
- }
1255
- const mergedSx = [
1256
- {
1257
- display: "flex",
1258
- gap: 1,
1259
- width: "100%",
1260
- alignItems: "center",
1261
- overflow: "hidden",
1262
- flexWrap: compact ? "no-wrap" : "wrap"
1263
- },
1264
- ...Array.isArray(sx) ? sx : [sx]
1265
- ];
1266
- return /* @__PURE__ */ jsxRuntime.jsxs(material.Box, { sx: mergedSx, ref: labelsWrapperRef, children: [
1267
- prepend,
1268
- labelNodes.map((item, index) => {
1269
- if (!item) {
1270
- return null;
1271
- }
1272
- const visible = index < overflowIndex;
1273
- let extra = null;
1274
- if (index === overflowIndex) {
1275
- extra = /* @__PURE__ */ jsxRuntime.jsx(
1276
- material.Box,
1277
- {
1278
- sx: {
1279
- display: "inline-flex",
1280
- ...compact && { height: 20, lineHeight: "20px" },
1281
- color: "text.secondary",
1282
- fontWeight: "bold",
1283
- fontSize: 14
1284
- },
1285
- children: `+${labelNodes.length - overflowIndex}`
1286
- },
1287
- "overflow-label"
1288
- );
1289
- }
1290
- let labelChip = /* @__PURE__ */ jsxRuntime.jsx(
1291
- LabelChip,
1292
- {
1293
- label: item,
1294
- onClick: onItemClick,
1295
- sx: {
1296
- visibility: visible ? "visible" : "hidden",
1297
- pointerEvents: visible ? "auto" : "none"
1298
- }
1299
- },
1300
- item.data.id
1301
- );
1302
- if (renderLabel) {
1303
- labelChip = renderLabel(item, labelChip);
1304
- }
1305
- if (extra) {
1306
- return [extra, labelChip];
1307
- }
1308
- return labelChip;
1309
- })
1310
- ] });
1311
- }
1312
1317
  function LabelsInput({
1313
1318
  value = [],
1314
1319
  onChange,
@@ -1,5 +1,5 @@
1
1
  import { LabelTreeNode } from './tree';
2
- import { SxProps } from '@mui/material';
2
+ import { Theme, SxProps } from '@mui/material';
3
3
 
4
4
  export interface LabelsProps {
5
5
  labels: string[] | undefined | null;
@@ -13,7 +13,7 @@ export interface LabelsProps {
13
13
  export interface LabelChipProps {
14
14
  label: LabelTreeNode;
15
15
  onDelete?: (label: LabelTreeNode) => void;
16
- sx?: SxProps;
16
+ sx?: SxProps<Theme>;
17
17
  fullName?: boolean;
18
18
  onClick?: (label: LabelTreeNode) => void;
19
19
  disabled?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/labels",
3
- "version": "1.6.239",
3
+ "version": "1.6.241",
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.239",
31
+ "@blocklet/translation-input": "1.6.241",
32
32
  "@emotion/css": "^11.10.5",
33
33
  "@emotion/react": "^11.10.5",
34
34
  "@emotion/styled": "^11.10.5",
@@ -83,5 +83,5 @@
83
83
  "resolutions": {
84
84
  "react": "^18.2.0"
85
85
  },
86
- "gitHead": "14c8c180f957d6b4574cefaaf60202b6afeb1a53"
86
+ "gitHead": "12f3e4ffaaa3856d2c71875efcb0268fad0d8a59"
87
87
  }