@blocklet/labels 1.6.174 → 1.6.176

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
@@ -13,13 +13,14 @@ import { Tree } from "react-arborist";
13
13
  import { Icon } from "@iconify/react";
14
14
  import omit from "lodash/omit";
15
15
  import Select, { components } from "react-select";
16
- import { ClickAwayListener, Box as Box$1, Chip, IconButton, Button, getContrastRatio, alpha, useTheme, ButtonBase, Popper, Autocomplete, InputBase, autocompleteClasses, darken, TextField } from "@mui/material";
16
+ import { ClickAwayListener, Box as Box$1, Chip, IconButton, Button, getContrastRatio, alpha, useTheme, ButtonBase, Popper, Autocomplete, InputBase, autocompleteClasses, TextField } from "@mui/material";
17
17
  import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
18
- import { useReactive, useRequest } from "ahooks";
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
21
  import CloseIcon from "@mui/icons-material/Close";
22
22
  import DoneIcon from "@mui/icons-material/Done";
23
+ import chroma from "chroma-js";
23
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" }) });
24
25
  const materialSymbolsCheckSmall = (props) => /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", width: "1.2em", height: "1.2em", ...props, children: /* @__PURE__ */ jsx("path", { fill: "currentColor", d: "m10 16.4l-4-4L7.4 11l2.6 2.6L16.6 7L18 8.4Z" }) });
25
26
  const LabelTreeContext = createContext({});
@@ -682,7 +683,7 @@ function LabelsProvider({ fetchLabels, createLabel, children }) {
682
683
  }, [loading, labels, getLabelsById, parseLabelIds, stringifyLabelIds, localizedLabels, getFullLabelName]);
683
684
  return /* @__PURE__ */ jsx(LabelsContext.Provider, { value, children: /* @__PURE__ */ jsx(LabelsContainer.Provider, { initialState: { loading, data, createLabel }, children }) });
684
685
  }
685
- const getContrastTextColor$1 = (bgcolor) => {
686
+ const getContrastTextColor = (bgcolor) => {
686
687
  try {
687
688
  const ratio = getContrastRatio(bgcolor, "#fff");
688
689
  return ratio > 2.7 ? "#fff" : "#111";
@@ -690,7 +691,7 @@ const getContrastTextColor$1 = (bgcolor) => {
690
691
  return "#111";
691
692
  }
692
693
  };
693
- const getAlphaColor$1 = (color, alpha$1) => {
694
+ const getAlphaColor = (color, alpha$1) => {
694
695
  try {
695
696
  if (color) {
696
697
  return alpha(color, alpha$1);
@@ -739,8 +740,8 @@ function Labels({ labels, editable, onChange, sx, renderLabel }) {
739
740
  height: 20,
740
741
  borderRadius: 1,
741
742
  fontSize: 12,
742
- bgcolor: getAlphaColor$1(item.color || "#ddd", 0.8),
743
- color: getContrastTextColor$1(item.color || "#ddd")
743
+ bgcolor: getAlphaColor(item.color || "#ddd", 0.8),
744
+ color: getContrastTextColor(item.color || "#ddd")
744
745
  }
745
746
  },
746
747
  item.id
@@ -1061,45 +1062,33 @@ function GithubLabelPicker({
1061
1062
  )
1062
1063
  ] });
1063
1064
  }
1064
- const getContrastTextColor = (bgcolor) => {
1065
- try {
1066
- const ratio = getContrastRatio(bgcolor, "#fff");
1067
- return ratio > 2.7 ? "#fff" : "#111";
1068
- } catch {
1069
- return "#111";
1070
- }
1065
+ const getTextColor = (color) => {
1066
+ return chroma(color).hex();
1071
1067
  };
1072
- const getTextColor = (bgcolor) => {
1073
- try {
1074
- const dark = darken(bgcolor, 0.5);
1075
- const ratio = getContrastRatio(bgcolor, dark);
1076
- return ratio > 2.4 ? dark : getContrastTextColor(bgcolor);
1077
- } catch {
1078
- return getContrastTextColor(bgcolor);
1068
+ const getBorderColor = (color) => {
1069
+ if (chroma(color).luminance() > 0.5) {
1070
+ return chroma(color).darken(3).hex();
1079
1071
  }
1072
+ return chroma(color).brighten(0.5).alpha(0.25).hex();
1080
1073
  };
1081
- const getBorderColor = (bgcolor) => {
1082
- try {
1083
- return darken(bgcolor, 0.05);
1084
- } catch {
1085
- return bgcolor;
1074
+ const getBackgroundColor = (color) => {
1075
+ if (chroma(color).luminance() > 0.5) {
1076
+ return chroma(color).darken(2.5).hex();
1086
1077
  }
1078
+ return chroma(color).brighten(2.5).alpha(0.25).hex();
1087
1079
  };
1088
- const getAlphaColor = (color, alpha$1) => {
1089
- try {
1090
- if (color) {
1091
- return alpha(color, alpha$1);
1092
- }
1093
- } catch {
1094
- return color;
1080
+ const getFilterStyle = (color) => {
1081
+ if (chroma(color).luminance() > 0.5) {
1082
+ return "brightness(0.85) contrast(1.2)";
1095
1083
  }
1096
- return color;
1084
+ return "brightness(0.85) contrast(1.2)";
1097
1085
  };
1098
1086
  function LabelChip({
1099
1087
  label,
1100
1088
  onDelete,
1101
1089
  sx,
1102
- fullName = true
1090
+ fullName = true,
1091
+ onClick
1103
1092
  }) {
1104
1093
  const { getFullLabelName, getLabelName } = LabelsContainer.useContainer();
1105
1094
  const mergedSx = [
@@ -1107,51 +1096,145 @@ function LabelChip({
1107
1096
  height: 20,
1108
1097
  borderRadius: 0.5,
1109
1098
  fontSize: 12,
1110
- fontWeight: "medium",
1111
- bgcolor: getAlphaColor(label.data.color, 0.8),
1112
- color: getTextColor(label.data.color),
1113
- border: 1,
1114
- borderColor: getBorderColor(label.data.color)
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
+ }
1115
1114
  },
1116
1115
  ...Array.isArray(sx) ? sx : [sx]
1117
1116
  ];
1118
- return /* @__PURE__ */ jsx(
1119
- Chip,
1120
- {
1121
- label: fullName ? getFullLabelName(label.data.id) : getLabelName(label.data.id),
1122
- variant: "filled",
1123
- size: "small",
1124
- ...onDelete && {
1125
- onDelete,
1126
- deleteIcon: /* @__PURE__ */ jsx(CloseIcon, {})
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
1127
1141
  },
1128
- sx: mergedSx
1129
- },
1130
- label.data.id
1142
+ label.data.id
1143
+ )
1131
1144
  );
1132
1145
  }
1133
- function Labels2({ labels, sx, renderLabel, prepend, displaySystemLabels = true }) {
1146
+ function Labels2({
1147
+ compact = true,
1148
+ labels,
1149
+ sx,
1150
+ renderLabel,
1151
+ prepend,
1152
+ displaySystemLabels = true,
1153
+ onItemClick
1154
+ }) {
1134
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]);
1135
1180
  if (loading) {
1136
1181
  return null;
1137
1182
  }
1138
- let labelNodes = getLabelsByIds(labels || []);
1139
1183
  if (!displaySystemLabels) {
1140
1184
  labelNodes = labelNodes.filter((x) => !x.data.id.startsWith("system:"));
1141
1185
  }
1142
1186
  const mergedSx = [
1143
- { display: "flex", gap: 1, alignItems: "center", flexWrap: "wrap" },
1187
+ {
1188
+ display: "flex",
1189
+ gap: 1,
1190
+ width: "100%",
1191
+ alignItems: "center",
1192
+ overflow: "hidden",
1193
+ flexWrap: compact ? "no-wrap" : "wrap"
1194
+ },
1144
1195
  ...Array.isArray(sx) ? sx : [sx]
1145
1196
  ];
1146
- return /* @__PURE__ */ jsxs(Box$1, { sx: mergedSx, children: [
1197
+ return /* @__PURE__ */ jsxs(Box$1, { sx: mergedSx, ref: labelsWrapperRef, children: [
1147
1198
  prepend,
1148
- labelNodes.map((item) => {
1199
+ labelNodes.map((item, index) => {
1149
1200
  if (!item) {
1150
1201
  return null;
1151
1202
  }
1152
- const labelChip = /* @__PURE__ */ jsx(LabelChip, { label: item }, item.data.id);
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
+ );
1153
1233
  if (renderLabel) {
1154
- return renderLabel(item, labelChip);
1234
+ labelChip = renderLabel(item, labelChip);
1235
+ }
1236
+ if (extra) {
1237
+ return [extra, labelChip];
1155
1238
  }
1156
1239
  return labelChip;
1157
1240
  })
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")) : 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"], 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));
3
- })(this, function(exports2, jsxRuntime, react, iconsMaterial, Box, styles, reactArborist, react$1, omit, Select, material, context, ahooks, unstatedNext, performantArrayToTree, CloseIcon, DoneIcon) {
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) {
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) => {
@@ -670,7 +670,7 @@ var __publicField = (obj, key, value) => {
670
670
  }, [loading, labels, getLabelsById, parseLabelIds, stringifyLabelIds, localizedLabels, getFullLabelName]);
671
671
  return /* @__PURE__ */ jsxRuntime.jsx(LabelsContext.Provider, { value, children: /* @__PURE__ */ jsxRuntime.jsx(LabelsContainer.Provider, { initialState: { loading, data, createLabel }, children }) });
672
672
  }
673
- const getContrastTextColor$1 = (bgcolor) => {
673
+ const getContrastTextColor = (bgcolor) => {
674
674
  try {
675
675
  const ratio = material.getContrastRatio(bgcolor, "#fff");
676
676
  return ratio > 2.7 ? "#fff" : "#111";
@@ -678,7 +678,7 @@ var __publicField = (obj, key, value) => {
678
678
  return "#111";
679
679
  }
680
680
  };
681
- const getAlphaColor$1 = (color, alpha) => {
681
+ const getAlphaColor = (color, alpha) => {
682
682
  try {
683
683
  if (color) {
684
684
  return material.alpha(color, alpha);
@@ -727,8 +727,8 @@ var __publicField = (obj, key, value) => {
727
727
  height: 20,
728
728
  borderRadius: 1,
729
729
  fontSize: 12,
730
- bgcolor: getAlphaColor$1(item.color || "#ddd", 0.8),
731
- color: getContrastTextColor$1(item.color || "#ddd")
730
+ bgcolor: getAlphaColor(item.color || "#ddd", 0.8),
731
+ color: getContrastTextColor(item.color || "#ddd")
732
732
  }
733
733
  },
734
734
  item.id
@@ -1049,45 +1049,33 @@ var __publicField = (obj, key, value) => {
1049
1049
  )
1050
1050
  ] });
1051
1051
  }
1052
- const getContrastTextColor = (bgcolor) => {
1053
- try {
1054
- const ratio = material.getContrastRatio(bgcolor, "#fff");
1055
- return ratio > 2.7 ? "#fff" : "#111";
1056
- } catch {
1057
- return "#111";
1058
- }
1052
+ const getTextColor = (color) => {
1053
+ return chroma(color).hex();
1059
1054
  };
1060
- const getTextColor = (bgcolor) => {
1061
- try {
1062
- const dark = material.darken(bgcolor, 0.5);
1063
- const ratio = material.getContrastRatio(bgcolor, dark);
1064
- return ratio > 2.4 ? dark : getContrastTextColor(bgcolor);
1065
- } catch {
1066
- return getContrastTextColor(bgcolor);
1055
+ const getBorderColor = (color) => {
1056
+ if (chroma(color).luminance() > 0.5) {
1057
+ return chroma(color).darken(3).hex();
1067
1058
  }
1059
+ return chroma(color).brighten(0.5).alpha(0.25).hex();
1068
1060
  };
1069
- const getBorderColor = (bgcolor) => {
1070
- try {
1071
- return material.darken(bgcolor, 0.05);
1072
- } catch {
1073
- return bgcolor;
1061
+ const getBackgroundColor = (color) => {
1062
+ if (chroma(color).luminance() > 0.5) {
1063
+ return chroma(color).darken(2.5).hex();
1074
1064
  }
1065
+ return chroma(color).brighten(2.5).alpha(0.25).hex();
1075
1066
  };
1076
- const getAlphaColor = (color, alpha) => {
1077
- try {
1078
- if (color) {
1079
- return material.alpha(color, alpha);
1080
- }
1081
- } catch {
1082
- return color;
1067
+ const getFilterStyle = (color) => {
1068
+ if (chroma(color).luminance() > 0.5) {
1069
+ return "brightness(0.85) contrast(1.2)";
1083
1070
  }
1084
- return color;
1071
+ return "brightness(0.85) contrast(1.2)";
1085
1072
  };
1086
1073
  function LabelChip({
1087
1074
  label,
1088
1075
  onDelete,
1089
1076
  sx,
1090
- fullName = true
1077
+ fullName = true,
1078
+ onClick
1091
1079
  }) {
1092
1080
  const { getFullLabelName, getLabelName } = LabelsContainer.useContainer();
1093
1081
  const mergedSx = [
@@ -1095,51 +1083,145 @@ var __publicField = (obj, key, value) => {
1095
1083
  height: 20,
1096
1084
  borderRadius: 0.5,
1097
1085
  fontSize: 12,
1098
- fontWeight: "medium",
1099
- bgcolor: getAlphaColor(label.data.color, 0.8),
1100
- color: getTextColor(label.data.color),
1101
- border: 1,
1102
- borderColor: getBorderColor(label.data.color)
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
+ }
1103
1101
  },
1104
1102
  ...Array.isArray(sx) ? sx : [sx]
1105
1103
  ];
1106
- return /* @__PURE__ */ jsxRuntime.jsx(
1107
- material.Chip,
1108
- {
1109
- label: fullName ? getFullLabelName(label.data.id) : getLabelName(label.data.id),
1110
- variant: "filled",
1111
- size: "small",
1112
- ...onDelete && {
1113
- onDelete,
1114
- deleteIcon: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon, {})
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
1115
1128
  },
1116
- sx: mergedSx
1117
- },
1118
- label.data.id
1129
+ label.data.id
1130
+ )
1119
1131
  );
1120
1132
  }
1121
- function Labels2({ labels, sx, renderLabel, prepend, displaySystemLabels = true }) {
1133
+ function Labels2({
1134
+ compact = true,
1135
+ labels,
1136
+ sx,
1137
+ renderLabel,
1138
+ prepend,
1139
+ displaySystemLabels = true,
1140
+ onItemClick
1141
+ }) {
1122
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]);
1123
1167
  if (loading) {
1124
1168
  return null;
1125
1169
  }
1126
- let labelNodes = getLabelsByIds(labels || []);
1127
1170
  if (!displaySystemLabels) {
1128
1171
  labelNodes = labelNodes.filter((x) => !x.data.id.startsWith("system:"));
1129
1172
  }
1130
1173
  const mergedSx = [
1131
- { display: "flex", gap: 1, alignItems: "center", flexWrap: "wrap" },
1174
+ {
1175
+ display: "flex",
1176
+ gap: 1,
1177
+ width: "100%",
1178
+ alignItems: "center",
1179
+ overflow: "hidden",
1180
+ flexWrap: compact ? "no-wrap" : "wrap"
1181
+ },
1132
1182
  ...Array.isArray(sx) ? sx : [sx]
1133
1183
  ];
1134
- return /* @__PURE__ */ jsxRuntime.jsxs(material.Box, { sx: mergedSx, children: [
1184
+ return /* @__PURE__ */ jsxRuntime.jsxs(material.Box, { sx: mergedSx, ref: labelsWrapperRef, children: [
1135
1185
  prepend,
1136
- labelNodes.map((item) => {
1186
+ labelNodes.map((item, index) => {
1137
1187
  if (!item) {
1138
1188
  return null;
1139
1189
  }
1140
- const labelChip = /* @__PURE__ */ jsxRuntime.jsx(LabelChip, { label: item }, item.data.id);
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
+ );
1141
1220
  if (renderLabel) {
1142
- return renderLabel(item, labelChip);
1221
+ labelChip = renderLabel(item, labelChip);
1222
+ }
1223
+ if (extra) {
1224
+ return [extra, labelChip];
1143
1225
  }
1144
1226
  return labelChip;
1145
1227
  })
@@ -7,12 +7,15 @@ interface LabelsProps {
7
7
  renderLabel?: (label: LabelTreeNode, labelChip: React.ReactElement) => JSX.Element;
8
8
  prepend?: React.ReactNode;
9
9
  displaySystemLabels?: boolean;
10
+ onItemClick?: (label: LabelTreeNode) => void;
11
+ compact?: boolean;
10
12
  }
11
- export declare function LabelChip({ label, onDelete, sx, fullName, }: {
13
+ export declare function LabelChip({ label, onDelete, sx, fullName, onClick, }: {
12
14
  label: LabelTreeNode;
13
- onDelete?: () => void;
15
+ onDelete?: (label: LabelTreeNode) => void;
14
16
  sx?: SxProps;
15
17
  fullName?: boolean;
18
+ onClick?: (label: LabelTreeNode) => void;
16
19
  }): import("react/jsx-runtime").JSX.Element;
17
- export declare function Labels2({ labels, sx, renderLabel, prepend, displaySystemLabels }: LabelsProps): import("react/jsx-runtime").JSX.Element | null;
20
+ export declare function Labels2({ compact, labels, sx, renderLabel, prepend, displaySystemLabels, onItemClick, }: LabelsProps): import("react/jsx-runtime").JSX.Element | null;
18
21
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/labels",
3
- "version": "1.6.174",
3
+ "version": "1.6.176",
4
4
  "files": [
5
5
  "dist"
6
6
  ],
@@ -28,12 +28,13 @@
28
28
  "access": "public"
29
29
  },
30
30
  "dependencies": {
31
- "@blocklet/translation-input": "1.6.174",
31
+ "@blocklet/translation-input": "1.6.176",
32
32
  "@emotion/css": "^11.10.5",
33
33
  "@emotion/react": "^11.10.5",
34
34
  "@emotion/styled": "^11.10.5",
35
35
  "@iconify/react": "^4.0.1",
36
36
  "ahooks": "^3.7.8",
37
+ "chroma-js": "^2.4.2",
37
38
  "performant-array-to-tree": "^1.11.0",
38
39
  "react-arborist": "^2.2.0",
39
40
  "react-color": "^2.19.3",
@@ -63,6 +64,7 @@
63
64
  "@storybook/react": "^6.5.13",
64
65
  "@storybook/testing-library": "^0.0.13",
65
66
  "@svgr/core": "^6.5.1",
67
+ "@types/chroma-js": "^2.4.4",
66
68
  "@types/react": "^18.0.24",
67
69
  "@types/react-color": "^3.0.6",
68
70
  "@types/react-dom": "^18.0.8",
@@ -80,5 +82,5 @@
80
82
  "resolutions": {
81
83
  "react": "^18.2.0"
82
84
  },
83
- "gitHead": "9b83dcf0a862c283cc7c926fb8bbe4f49caeff2e"
85
+ "gitHead": "83c2397ed6c3f8ed577de50cd0868642c9212f4b"
84
86
  }