@blocklet/labels 1.6.205 → 1.6.207
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 +317 -305
- package/dist/index.umd.js +315 -302
- package/dist/label2/github-label-picker.d.ts +2 -2
- package/dist/label2/recent.d.ts +5 -0
- package/package.json +3 -3
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("@
|
|
3
|
-
})(this, function(exports2, jsxRuntime, react, iconsMaterial, Box, styles, reactArborist, react$1, omit, Select, material, context, ahooks, unstatedNext, performantArrayToTree,
|
|
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("@arcblock/did-connect/lib/Session"), require("chroma-js"), require("@mui/icons-material/Close")) : 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", "@arcblock/did-connect/lib/Session", "chroma-js", "@mui/icons-material/Close"], 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.Session, global.chroma, global.CloseOutlineIcon));
|
|
3
|
+
})(this, function(exports2, jsxRuntime, react, iconsMaterial, Box, styles, reactArborist, react$1, omit, Select, material, context, ahooks, unstatedNext, performantArrayToTree, Session, chroma, CloseOutlineIcon) {
|
|
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) => {
|
|
@@ -747,198 +747,6 @@ var __publicField = (obj, key, value) => {
|
|
|
747
747
|
] });
|
|
748
748
|
}
|
|
749
749
|
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" }) });
|
|
750
|
-
const getTextColor = (color) => {
|
|
751
|
-
return chroma(color).hex();
|
|
752
|
-
};
|
|
753
|
-
const getBorderColor = (color) => {
|
|
754
|
-
if (chroma(color).luminance() > 0.5) {
|
|
755
|
-
return chroma(color).darken(3).hex();
|
|
756
|
-
}
|
|
757
|
-
return chroma(color).brighten(0.5).alpha(0.25).hex();
|
|
758
|
-
};
|
|
759
|
-
const getBackgroundColor = (color) => {
|
|
760
|
-
if (chroma(color).luminance() > 0.5) {
|
|
761
|
-
return chroma(color).darken(2.5).hex();
|
|
762
|
-
}
|
|
763
|
-
return chroma(color).brighten(2.5).alpha(0.25).hex();
|
|
764
|
-
};
|
|
765
|
-
const getFilterStyle = (color) => {
|
|
766
|
-
if (chroma(color).luminance() > 0.5) {
|
|
767
|
-
return "brightness(0.85) contrast(1.2)";
|
|
768
|
-
}
|
|
769
|
-
return "brightness(0.85) contrast(1.2)";
|
|
770
|
-
};
|
|
771
|
-
function LabelChip({
|
|
772
|
-
label,
|
|
773
|
-
onDelete,
|
|
774
|
-
sx,
|
|
775
|
-
fullName = true,
|
|
776
|
-
onClick,
|
|
777
|
-
disabled = false,
|
|
778
|
-
renderName = (name) => name
|
|
779
|
-
}) {
|
|
780
|
-
const { getFullLabelName, getLabelName } = LabelsContainer.useContainer();
|
|
781
|
-
const mergedSx = [
|
|
782
|
-
{
|
|
783
|
-
height: 20,
|
|
784
|
-
borderRadius: 0.5,
|
|
785
|
-
fontSize: 12,
|
|
786
|
-
fontWeight: 500,
|
|
787
|
-
color: `${getTextColor(label.data.color)} !important`,
|
|
788
|
-
bgcolor: `${getBackgroundColor(label.data.color)} !important`,
|
|
789
|
-
transition: "filter 0.2s",
|
|
790
|
-
borderColor: `${getBorderColor(label.data.color)} !important`,
|
|
791
|
-
// -webkit-text-fill-color
|
|
792
|
-
WebkitTextFillColor: `${getTextColor(label.data.color)} !important`,
|
|
793
|
-
".MuiChip-deleteIcon": {
|
|
794
|
-
color: `${getTextColor(label.data.color)} !important`,
|
|
795
|
-
cursor: "pointer",
|
|
796
|
-
transition: "transform 0.3s",
|
|
797
|
-
"&:hover": {
|
|
798
|
-
transform: "rotate(90deg)"
|
|
799
|
-
}
|
|
800
|
-
},
|
|
801
|
-
".MuiChip-label": {
|
|
802
|
-
px: 0.5,
|
|
803
|
-
maxHeight: 20
|
|
804
|
-
},
|
|
805
|
-
...onClick && {
|
|
806
|
-
cursor: "pointer",
|
|
807
|
-
"&:hover": {
|
|
808
|
-
filter: getFilterStyle(label.data.color)
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
},
|
|
812
|
-
...Array.isArray(sx) ? sx : [sx]
|
|
813
|
-
];
|
|
814
|
-
const hasDelete = !disabled && !!onDelete;
|
|
815
|
-
const hasOnClick = !disabled && !!onClick;
|
|
816
|
-
return (
|
|
817
|
-
// @ts-ignore
|
|
818
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
819
|
-
material.Chip,
|
|
820
|
-
{
|
|
821
|
-
label: renderName(fullName ? getFullLabelName(label.data.id) : getLabelName(label.data.id)),
|
|
822
|
-
variant: "outlined",
|
|
823
|
-
size: "small",
|
|
824
|
-
...hasDelete && {
|
|
825
|
-
onDelete: (e) => {
|
|
826
|
-
e.stopPropagation();
|
|
827
|
-
e.preventDefault();
|
|
828
|
-
onDelete(label);
|
|
829
|
-
},
|
|
830
|
-
deleteIcon: /* @__PURE__ */ jsxRuntime.jsx(CloseOutlineIcon, {})
|
|
831
|
-
},
|
|
832
|
-
...hasOnClick && {
|
|
833
|
-
onClick: (e) => {
|
|
834
|
-
e.stopPropagation();
|
|
835
|
-
e.preventDefault();
|
|
836
|
-
onClick(label);
|
|
837
|
-
}
|
|
838
|
-
},
|
|
839
|
-
sx: mergedSx
|
|
840
|
-
},
|
|
841
|
-
label.data.id
|
|
842
|
-
)
|
|
843
|
-
);
|
|
844
|
-
}
|
|
845
|
-
function Labels2({
|
|
846
|
-
compact = true,
|
|
847
|
-
labels,
|
|
848
|
-
sx,
|
|
849
|
-
renderLabel,
|
|
850
|
-
prepend,
|
|
851
|
-
displaySystemLabels = true,
|
|
852
|
-
onItemClick
|
|
853
|
-
}) {
|
|
854
|
-
const { getLabelsByIds, loading } = LabelsContainer.useContainer();
|
|
855
|
-
const labelsWrapperRef = react.useRef(null);
|
|
856
|
-
const [overflowIndex, setOverflowIndex] = react.useState(99999);
|
|
857
|
-
let labelNodes = getLabelsByIds(labels || []);
|
|
858
|
-
const size = ahooks.useSize(labelsWrapperRef);
|
|
859
|
-
ahooks.useDeepCompareLayoutEffect(() => {
|
|
860
|
-
if (compact) {
|
|
861
|
-
if (labelsWrapperRef.current) {
|
|
862
|
-
const { right } = labelsWrapperRef.current.getBoundingClientRect();
|
|
863
|
-
const labelElements = labelsWrapperRef.current.querySelectorAll(".MuiChip-root");
|
|
864
|
-
if ((labelElements == null ? void 0 : labelElements.length) > 0) {
|
|
865
|
-
Array.from(labelElements).some((x, i) => {
|
|
866
|
-
const rect = x.getBoundingClientRect();
|
|
867
|
-
if (rect.right > right - 36) {
|
|
868
|
-
setOverflowIndex(i);
|
|
869
|
-
return true;
|
|
870
|
-
}
|
|
871
|
-
return false;
|
|
872
|
-
});
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
} else {
|
|
876
|
-
setOverflowIndex(99999);
|
|
877
|
-
}
|
|
878
|
-
}, [size, compact]);
|
|
879
|
-
if (loading) {
|
|
880
|
-
return null;
|
|
881
|
-
}
|
|
882
|
-
if (!displaySystemLabels) {
|
|
883
|
-
labelNodes = labelNodes.filter((x) => x.data.type !== "system");
|
|
884
|
-
}
|
|
885
|
-
const mergedSx = [
|
|
886
|
-
{
|
|
887
|
-
display: "flex",
|
|
888
|
-
gap: 1,
|
|
889
|
-
width: "100%",
|
|
890
|
-
alignItems: "center",
|
|
891
|
-
overflow: "hidden",
|
|
892
|
-
flexWrap: compact ? "no-wrap" : "wrap"
|
|
893
|
-
},
|
|
894
|
-
...Array.isArray(sx) ? sx : [sx]
|
|
895
|
-
];
|
|
896
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(material.Box, { sx: mergedSx, ref: labelsWrapperRef, children: [
|
|
897
|
-
prepend,
|
|
898
|
-
labelNodes.map((item, index) => {
|
|
899
|
-
if (!item) {
|
|
900
|
-
return null;
|
|
901
|
-
}
|
|
902
|
-
const visible = index < overflowIndex;
|
|
903
|
-
let extra = null;
|
|
904
|
-
if (index === overflowIndex) {
|
|
905
|
-
extra = /* @__PURE__ */ jsxRuntime.jsx(
|
|
906
|
-
material.Box,
|
|
907
|
-
{
|
|
908
|
-
sx: {
|
|
909
|
-
display: "inline-flex",
|
|
910
|
-
...compact && { height: 20, lineHeight: "20px" },
|
|
911
|
-
color: "text.secondary",
|
|
912
|
-
fontWeight: "bold",
|
|
913
|
-
fontSize: 14
|
|
914
|
-
},
|
|
915
|
-
children: `+${labelNodes.length - overflowIndex}`
|
|
916
|
-
},
|
|
917
|
-
"overflow-label"
|
|
918
|
-
);
|
|
919
|
-
}
|
|
920
|
-
let labelChip = /* @__PURE__ */ jsxRuntime.jsx(
|
|
921
|
-
LabelChip,
|
|
922
|
-
{
|
|
923
|
-
label: item,
|
|
924
|
-
onClick: onItemClick,
|
|
925
|
-
sx: {
|
|
926
|
-
visibility: visible ? "visible" : "hidden",
|
|
927
|
-
pointerEvents: visible ? "auto" : "none"
|
|
928
|
-
}
|
|
929
|
-
},
|
|
930
|
-
item.data.id
|
|
931
|
-
);
|
|
932
|
-
if (renderLabel) {
|
|
933
|
-
labelChip = renderLabel(item, labelChip);
|
|
934
|
-
}
|
|
935
|
-
if (extra) {
|
|
936
|
-
return [extra, labelChip];
|
|
937
|
-
}
|
|
938
|
-
return labelChip;
|
|
939
|
-
})
|
|
940
|
-
] });
|
|
941
|
-
}
|
|
942
750
|
const useSessionContext = () => {
|
|
943
751
|
var _a, _b;
|
|
944
752
|
const ctx = react.useContext(Session.SessionContext) || {};
|
|
@@ -955,6 +763,39 @@ var __publicField = (obj, key, value) => {
|
|
|
955
763
|
}
|
|
956
764
|
};
|
|
957
765
|
};
|
|
766
|
+
const useRecentLabels = () => {
|
|
767
|
+
const [recentLabels = [], setRecentLabels] = ahooks.useLocalStorageState("recent-labels", {
|
|
768
|
+
defaultValue: []
|
|
769
|
+
});
|
|
770
|
+
const addRecentLabel = (label) => {
|
|
771
|
+
if (recentLabels.includes(label)) {
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
const newLabels = [label, ...recentLabels].slice(0, 10);
|
|
775
|
+
setRecentLabels(newLabels);
|
|
776
|
+
};
|
|
777
|
+
const addRecentLabels = (labels) => {
|
|
778
|
+
labels.forEach((x) => addRecentLabel(x));
|
|
779
|
+
};
|
|
780
|
+
return { recentLabels, addRecentLabel, addRecentLabels };
|
|
781
|
+
};
|
|
782
|
+
function LabelChip$1({ name, selected, ...rest }) {
|
|
783
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
784
|
+
material.Chip,
|
|
785
|
+
{
|
|
786
|
+
label: name,
|
|
787
|
+
variant: selected ? "filled" : "outlined",
|
|
788
|
+
color: "primary",
|
|
789
|
+
size: "small",
|
|
790
|
+
sx: {
|
|
791
|
+
fontWeight: "medium",
|
|
792
|
+
borderRadius: 0.75,
|
|
793
|
+
...!selected && { bgcolor: "grey.50", borderColor: "grey.300", color: "text.secondary" }
|
|
794
|
+
},
|
|
795
|
+
...rest
|
|
796
|
+
}
|
|
797
|
+
);
|
|
798
|
+
}
|
|
958
799
|
function PopperComponent({
|
|
959
800
|
disablePortal,
|
|
960
801
|
anchorEl,
|
|
@@ -967,25 +808,17 @@ var __publicField = (obj, key, value) => {
|
|
|
967
808
|
...other,
|
|
968
809
|
sx: (theme) => ({
|
|
969
810
|
[`& .${material.autocompleteClasses.paper}`]: {
|
|
811
|
+
width: 360,
|
|
970
812
|
boxShadow: "none",
|
|
971
813
|
margin: 0,
|
|
972
814
|
color: "inherit",
|
|
973
815
|
fontSize: 13
|
|
974
816
|
},
|
|
975
817
|
[`& .${material.autocompleteClasses.listbox}`]: {
|
|
976
|
-
|
|
977
|
-
padding:
|
|
818
|
+
bgcolor: theme.palette.mode === "light" ? "#fff" : "#1c2128",
|
|
819
|
+
padding: 1,
|
|
978
820
|
[`& .${material.autocompleteClasses.option}`]: {
|
|
979
|
-
minHeight: "auto"
|
|
980
|
-
alignItems: "flex-start",
|
|
981
|
-
padding: 1,
|
|
982
|
-
borderBottom: `1px solid ${theme.palette.mode === "light" ? " #eaecef" : "#30363d"}`,
|
|
983
|
-
'&[aria-selected="true"]': {
|
|
984
|
-
backgroundColor: "transparent"
|
|
985
|
-
},
|
|
986
|
-
[`&.${material.autocompleteClasses.focused}, &.${material.autocompleteClasses.focused}[aria-selected="true"]`]: {
|
|
987
|
-
backgroundColor: theme.palette.action.hover
|
|
988
|
-
}
|
|
821
|
+
minHeight: "auto"
|
|
989
822
|
}
|
|
990
823
|
},
|
|
991
824
|
[`&.${material.autocompleteClasses.popperDisablePortal}`]: {
|
|
@@ -998,7 +831,6 @@ var __publicField = (obj, key, value) => {
|
|
|
998
831
|
function GithubLabelPicker({
|
|
999
832
|
value = [],
|
|
1000
833
|
onChange,
|
|
1001
|
-
title,
|
|
1002
834
|
noLabelsText,
|
|
1003
835
|
buttonSx,
|
|
1004
836
|
actions,
|
|
@@ -1009,9 +841,15 @@ var __publicField = (obj, key, value) => {
|
|
|
1009
841
|
disabled = false,
|
|
1010
842
|
enableAccessControl = true
|
|
1011
843
|
}) {
|
|
1012
|
-
const { locale } = context.useLocaleContext();
|
|
844
|
+
const { t, locale } = context.useLocaleContext();
|
|
1013
845
|
const { isAdmin, hasAnyPassport } = useSessionContext();
|
|
1014
|
-
const {
|
|
846
|
+
const {
|
|
847
|
+
flattenedLabels: labels,
|
|
848
|
+
getLabelsByIds,
|
|
849
|
+
loading,
|
|
850
|
+
createLabel,
|
|
851
|
+
getLabelName
|
|
852
|
+
} = LabelsContainer.useContainer();
|
|
1015
853
|
const [anchorEl, setAnchorEl] = react.useState(null);
|
|
1016
854
|
const [pendingValue, setPendingValue] = react.useState([]);
|
|
1017
855
|
const pendingOptions = react.useMemo(() => getLabelsByIds(pendingValue), [getLabelsByIds, pendingValue]);
|
|
@@ -1024,7 +862,8 @@ var __publicField = (obj, key, value) => {
|
|
|
1024
862
|
const excludesSet = new Set(excludes);
|
|
1025
863
|
return labels.filter((x) => !excludesSet.has(x.data.id));
|
|
1026
864
|
}, [labels]);
|
|
1027
|
-
const
|
|
865
|
+
const { recentLabels, addRecentLabels } = useRecentLabels();
|
|
866
|
+
const initialRecentLabels = react.useMemo(() => recentLabels, [anchorEl]);
|
|
1028
867
|
const handleClick = (event) => {
|
|
1029
868
|
if (disabled) {
|
|
1030
869
|
return;
|
|
@@ -1047,6 +886,16 @@ var __publicField = (obj, key, value) => {
|
|
|
1047
886
|
const { id: id2 } = await createLabel(inputValue);
|
|
1048
887
|
setPendingValue([...pendingValue, id2]);
|
|
1049
888
|
};
|
|
889
|
+
const handleChange = (newValue) => {
|
|
890
|
+
setPendingValue(newValue);
|
|
891
|
+
addRecentLabels(newValue);
|
|
892
|
+
if (!multiple) {
|
|
893
|
+
onChange == null ? void 0 : onChange(newValue.length ? [newValue[newValue.length - 1]] : []);
|
|
894
|
+
setAnchorEl(null);
|
|
895
|
+
} else if (updateImmediately) {
|
|
896
|
+
onChange(newValue);
|
|
897
|
+
}
|
|
898
|
+
};
|
|
1050
899
|
const open = Boolean(anchorEl);
|
|
1051
900
|
const id = open ? "github-label-picker" : void 0;
|
|
1052
901
|
if (loading) {
|
|
@@ -1069,7 +918,7 @@ var __publicField = (obj, key, value) => {
|
|
|
1069
918
|
"aria-describedby": id,
|
|
1070
919
|
className: "label-picker-trigger",
|
|
1071
920
|
sx: [
|
|
1072
|
-
(
|
|
921
|
+
() => ({
|
|
1073
922
|
width: "100%",
|
|
1074
923
|
fontSize: 13,
|
|
1075
924
|
color: t.palette.mode === "light" ? "#586069" : "#8b949e",
|
|
@@ -1098,28 +947,18 @@ var __publicField = (obj, key, value) => {
|
|
|
1098
947
|
anchorEl,
|
|
1099
948
|
placement: "bottom-start",
|
|
1100
949
|
disablePortal: true,
|
|
1101
|
-
sx: (
|
|
1102
|
-
border: `1px solid ${
|
|
1103
|
-
boxShadow: `0 8px 24px ${
|
|
1104
|
-
borderRadius:
|
|
1105
|
-
width:
|
|
1106
|
-
|
|
950
|
+
sx: (theme) => ({
|
|
951
|
+
border: `1px solid ${theme.palette.mode === "light" ? "#e1e4e8" : "#30363d"}`,
|
|
952
|
+
boxShadow: `0 8px 24px ${theme.palette.mode === "light" ? "rgba(149, 157, 165, 0.2)" : "rgb(1, 4, 9)"}`,
|
|
953
|
+
borderRadius: 1,
|
|
954
|
+
width: 360,
|
|
955
|
+
overflow: "hidden",
|
|
956
|
+
zIndex: theme.zIndex.modal,
|
|
1107
957
|
fontSize: 13,
|
|
1108
|
-
color:
|
|
1109
|
-
backgroundColor:
|
|
958
|
+
color: theme.palette.mode === "light" ? "#24292e" : "#c9d1d9",
|
|
959
|
+
backgroundColor: theme.palette.mode === "light" ? "#fff" : "#1c2128"
|
|
1110
960
|
}),
|
|
1111
961
|
children: /* @__PURE__ */ jsxRuntime.jsx(material.ClickAwayListener, { onClickAway: handleClose, children: /* @__PURE__ */ jsxRuntime.jsxs(material.Box, { onClick: (e) => e.preventDefault(), children: [
|
|
1112
|
-
title && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1113
|
-
material.Box,
|
|
1114
|
-
{
|
|
1115
|
-
sx: {
|
|
1116
|
-
borderBottom: `1px solid ${theme.palette.mode === "light" ? "#eaecef" : "#30363d"}`,
|
|
1117
|
-
padding: "8px 10px",
|
|
1118
|
-
fontWeight: 600
|
|
1119
|
-
},
|
|
1120
|
-
children: title
|
|
1121
|
-
}
|
|
1122
|
-
),
|
|
1123
962
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1124
963
|
material.Autocomplete,
|
|
1125
964
|
{
|
|
@@ -1143,13 +982,7 @@ var __publicField = (obj, key, value) => {
|
|
|
1143
982
|
if (event.type === "keydown" && event.key === "Backspace" && reason === "removeOption") {
|
|
1144
983
|
return;
|
|
1145
984
|
}
|
|
1146
|
-
|
|
1147
|
-
if (!multiple) {
|
|
1148
|
-
onChange == null ? void 0 : onChange(newValue.length ? [newValue[newValue.length - 1].data.id] : []);
|
|
1149
|
-
setAnchorEl(null);
|
|
1150
|
-
} else if (updateImmediately) {
|
|
1151
|
-
onChange(newValue.map((x) => x.data.id));
|
|
1152
|
-
}
|
|
985
|
+
handleChange(newValue.map((x) => x.data.id));
|
|
1153
986
|
},
|
|
1154
987
|
disableCloseOnSelect: true,
|
|
1155
988
|
PopperComponent,
|
|
@@ -1163,74 +996,62 @@ var __publicField = (obj, key, value) => {
|
|
|
1163
996
|
];
|
|
1164
997
|
const isPermitted = !enableAccessControl || isAdmin || hasAnyPassport(passportsToCheck);
|
|
1165
998
|
if (!isPermitted) {
|
|
1166
|
-
|
|
1167
|
-
};
|
|
1168
|
-
if (!(value == null ? void 0 : value.includes(label.id))) {
|
|
1169
|
-
return null;
|
|
1170
|
-
}
|
|
999
|
+
return null;
|
|
1171
1000
|
}
|
|
1172
1001
|
return /* @__PURE__ */ react.createElement(
|
|
1173
1002
|
material.Box,
|
|
1174
1003
|
{
|
|
1175
1004
|
component: "li",
|
|
1176
1005
|
...props,
|
|
1177
|
-
key:
|
|
1006
|
+
key: label.id,
|
|
1178
1007
|
sx: {
|
|
1179
|
-
|
|
1008
|
+
"&.MuiAutocomplete-option": {
|
|
1009
|
+
p: 0
|
|
1010
|
+
}
|
|
1180
1011
|
}
|
|
1181
1012
|
},
|
|
1182
|
-
/* @__PURE__ */ jsxRuntime.
|
|
1183
|
-
material.Box,
|
|
1184
|
-
{
|
|
1185
|
-
sx: {
|
|
1186
|
-
display: "flex",
|
|
1187
|
-
alignItems: "center",
|
|
1188
|
-
width: 1
|
|
1189
|
-
},
|
|
1190
|
-
children: [
|
|
1191
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1192
|
-
material.Box,
|
|
1193
|
-
{
|
|
1194
|
-
component: DoneIcon,
|
|
1195
|
-
sx: { width: 17, height: 17, mr: "5px", ml: "-2px" },
|
|
1196
|
-
style: {
|
|
1197
|
-
visibility: selected ? "visible" : "hidden"
|
|
1198
|
-
}
|
|
1199
|
-
}
|
|
1200
|
-
),
|
|
1201
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1202
|
-
material.Box,
|
|
1203
|
-
{
|
|
1204
|
-
sx: {
|
|
1205
|
-
flexGrow: 1,
|
|
1206
|
-
alignItems: "center",
|
|
1207
|
-
display: "flex"
|
|
1208
|
-
},
|
|
1209
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(LabelChip, { label: option, disabled: disabled || !isPermitted })
|
|
1210
|
-
}
|
|
1211
|
-
),
|
|
1212
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1213
|
-
material.Box,
|
|
1214
|
-
{
|
|
1215
|
-
component: CloseOutlineIcon,
|
|
1216
|
-
sx: { opacity: 0.6, width: 18, height: 18 },
|
|
1217
|
-
style: {
|
|
1218
|
-
visibility: selected ? "visible" : "hidden"
|
|
1219
|
-
}
|
|
1220
|
-
}
|
|
1221
|
-
)
|
|
1222
|
-
]
|
|
1223
|
-
}
|
|
1224
|
-
)
|
|
1013
|
+
/* @__PURE__ */ jsxRuntime.jsx(LabelChip$1, { name: getLabelName(label.id), selected })
|
|
1225
1014
|
);
|
|
1226
1015
|
},
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1016
|
+
groupBy: () => "x",
|
|
1017
|
+
renderGroup: (params) => {
|
|
1018
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1019
|
+
!!(initialRecentLabels == null ? void 0 : initialRecentLabels.length) && /* @__PURE__ */ jsxRuntime.jsxs("li", { children: [
|
|
1020
|
+
/* @__PURE__ */ jsxRuntime.jsx(material.Box, { sx: { mb: 0.5, fontSize: 12, fontWeight: "medium" }, children: t("label.recently") }),
|
|
1021
|
+
/* @__PURE__ */ jsxRuntime.jsx(material.Box, { sx: { display: "flex", flexWrap: "wrap", gap: 0.5 }, children: initialRecentLabels.map((x) => {
|
|
1022
|
+
const selected = value == null ? void 0 : value.includes(x);
|
|
1023
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1024
|
+
LabelChip$1,
|
|
1025
|
+
{
|
|
1026
|
+
name: getLabelName(x),
|
|
1027
|
+
selected,
|
|
1028
|
+
onClick: () => {
|
|
1029
|
+
handleChange(selected ? pendingValue.filter((y) => y !== x) : [...pendingValue, x]);
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
);
|
|
1033
|
+
}) })
|
|
1034
|
+
] }),
|
|
1035
|
+
/* @__PURE__ */ jsxRuntime.jsxs("li", { children: [
|
|
1036
|
+
/* @__PURE__ */ jsxRuntime.jsx(material.Box, { sx: { mt: 1, mb: 0.5, fontSize: 12, fontWeight: "medium" }, children: t("label.title") }),
|
|
1037
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1038
|
+
material.Box,
|
|
1039
|
+
{
|
|
1040
|
+
component: "ul",
|
|
1041
|
+
sx: {
|
|
1042
|
+
display: "flex",
|
|
1043
|
+
justifyContent: "flex-start",
|
|
1044
|
+
flexWrap: "wrap",
|
|
1045
|
+
gap: 0.5,
|
|
1046
|
+
p: 0
|
|
1047
|
+
},
|
|
1048
|
+
children: params.children
|
|
1049
|
+
}
|
|
1050
|
+
)
|
|
1051
|
+
] })
|
|
1052
|
+
] });
|
|
1053
|
+
},
|
|
1054
|
+
options: filteredLabels,
|
|
1234
1055
|
getOptionLabel: (option) => option.data.getName(locale),
|
|
1235
1056
|
renderInput: (params) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1236
1057
|
material.Box,
|
|
@@ -1240,20 +1061,20 @@ var __publicField = (obj, key, value) => {
|
|
|
1240
1061
|
inputProps: params.inputProps,
|
|
1241
1062
|
autoFocus: true,
|
|
1242
1063
|
placeholder: "Filter labels",
|
|
1243
|
-
sx: (
|
|
1064
|
+
sx: (theme) => ({
|
|
1244
1065
|
padding: 1,
|
|
1245
1066
|
width: "100%",
|
|
1246
|
-
|
|
1067
|
+
bgcolor: "#fff",
|
|
1247
1068
|
"& input": {
|
|
1248
|
-
borderRadius:
|
|
1249
|
-
backgroundColor:
|
|
1069
|
+
borderRadius: 1,
|
|
1070
|
+
backgroundColor: theme.palette.mode === "light" ? "#fff" : "#0d1117",
|
|
1250
1071
|
padding: 1,
|
|
1251
|
-
transition:
|
|
1252
|
-
border: `1px solid ${
|
|
1072
|
+
transition: theme.transitions.create(["border-color", "box-shadow"]),
|
|
1073
|
+
border: `1px solid ${theme.palette.mode === "light" ? "#eaecef" : "#30363d"}`,
|
|
1253
1074
|
fontSize: 14,
|
|
1254
1075
|
"&:focus": {
|
|
1255
|
-
boxShadow: `0px 0px 0px 3px ${
|
|
1256
|
-
borderColor:
|
|
1076
|
+
boxShadow: `0px 0px 0px 3px ${theme.palette.mode === "light" ? material.alpha(theme.palette.primary.light, 0.4) : "rgb(12, 45, 107)"}`,
|
|
1077
|
+
borderColor: theme.palette.mode === "light" ? theme.palette.primary.light : "#388bfd"
|
|
1257
1078
|
}
|
|
1258
1079
|
}
|
|
1259
1080
|
})
|
|
@@ -1293,6 +1114,198 @@ var __publicField = (obj, key, value) => {
|
|
|
1293
1114
|
)
|
|
1294
1115
|
] });
|
|
1295
1116
|
}
|
|
1117
|
+
const getTextColor = (color) => {
|
|
1118
|
+
return chroma(color).hex();
|
|
1119
|
+
};
|
|
1120
|
+
const getBorderColor = (color) => {
|
|
1121
|
+
if (chroma(color).luminance() > 0.5) {
|
|
1122
|
+
return chroma(color).darken(3).hex();
|
|
1123
|
+
}
|
|
1124
|
+
return chroma(color).brighten(0.5).alpha(0.25).hex();
|
|
1125
|
+
};
|
|
1126
|
+
const getBackgroundColor = (color) => {
|
|
1127
|
+
if (chroma(color).luminance() > 0.5) {
|
|
1128
|
+
return chroma(color).darken(2.5).hex();
|
|
1129
|
+
}
|
|
1130
|
+
return chroma(color).brighten(2.5).alpha(0.25).hex();
|
|
1131
|
+
};
|
|
1132
|
+
const getFilterStyle = (color) => {
|
|
1133
|
+
if (chroma(color).luminance() > 0.5) {
|
|
1134
|
+
return "brightness(0.85) contrast(1.2)";
|
|
1135
|
+
}
|
|
1136
|
+
return "brightness(0.85) contrast(1.2)";
|
|
1137
|
+
};
|
|
1138
|
+
function LabelChip({
|
|
1139
|
+
label,
|
|
1140
|
+
onDelete,
|
|
1141
|
+
sx,
|
|
1142
|
+
fullName = true,
|
|
1143
|
+
onClick,
|
|
1144
|
+
disabled = false,
|
|
1145
|
+
renderName = (name) => name
|
|
1146
|
+
}) {
|
|
1147
|
+
const { getFullLabelName, getLabelName } = LabelsContainer.useContainer();
|
|
1148
|
+
const mergedSx = [
|
|
1149
|
+
{
|
|
1150
|
+
height: 20,
|
|
1151
|
+
borderRadius: 0.5,
|
|
1152
|
+
fontSize: 12,
|
|
1153
|
+
fontWeight: 500,
|
|
1154
|
+
color: `${getTextColor(label.data.color)} !important`,
|
|
1155
|
+
bgcolor: `${getBackgroundColor(label.data.color)} !important`,
|
|
1156
|
+
transition: "filter 0.2s",
|
|
1157
|
+
borderColor: `${getBorderColor(label.data.color)} !important`,
|
|
1158
|
+
// -webkit-text-fill-color
|
|
1159
|
+
WebkitTextFillColor: `${getTextColor(label.data.color)} !important`,
|
|
1160
|
+
".MuiChip-deleteIcon": {
|
|
1161
|
+
color: `${getTextColor(label.data.color)} !important`,
|
|
1162
|
+
cursor: "pointer",
|
|
1163
|
+
transition: "transform 0.3s",
|
|
1164
|
+
"&:hover": {
|
|
1165
|
+
transform: "rotate(90deg)"
|
|
1166
|
+
}
|
|
1167
|
+
},
|
|
1168
|
+
".MuiChip-label": {
|
|
1169
|
+
px: 0.5,
|
|
1170
|
+
maxHeight: 20
|
|
1171
|
+
},
|
|
1172
|
+
...onClick && {
|
|
1173
|
+
cursor: "pointer",
|
|
1174
|
+
"&:hover": {
|
|
1175
|
+
filter: getFilterStyle(label.data.color)
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
},
|
|
1179
|
+
...Array.isArray(sx) ? sx : [sx]
|
|
1180
|
+
];
|
|
1181
|
+
const hasDelete = !disabled && !!onDelete;
|
|
1182
|
+
const hasOnClick = !disabled && !!onClick;
|
|
1183
|
+
return (
|
|
1184
|
+
// @ts-ignore
|
|
1185
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1186
|
+
material.Chip,
|
|
1187
|
+
{
|
|
1188
|
+
label: renderName(fullName ? getFullLabelName(label.data.id) : getLabelName(label.data.id)),
|
|
1189
|
+
variant: "outlined",
|
|
1190
|
+
size: "small",
|
|
1191
|
+
...hasDelete && {
|
|
1192
|
+
onDelete: (e) => {
|
|
1193
|
+
e.stopPropagation();
|
|
1194
|
+
e.preventDefault();
|
|
1195
|
+
onDelete(label);
|
|
1196
|
+
},
|
|
1197
|
+
deleteIcon: /* @__PURE__ */ jsxRuntime.jsx(CloseOutlineIcon, {})
|
|
1198
|
+
},
|
|
1199
|
+
...hasOnClick && {
|
|
1200
|
+
onClick: (e) => {
|
|
1201
|
+
e.stopPropagation();
|
|
1202
|
+
e.preventDefault();
|
|
1203
|
+
onClick(label);
|
|
1204
|
+
}
|
|
1205
|
+
},
|
|
1206
|
+
sx: mergedSx
|
|
1207
|
+
},
|
|
1208
|
+
label.data.id
|
|
1209
|
+
)
|
|
1210
|
+
);
|
|
1211
|
+
}
|
|
1212
|
+
function Labels2({
|
|
1213
|
+
compact = true,
|
|
1214
|
+
labels,
|
|
1215
|
+
sx,
|
|
1216
|
+
renderLabel,
|
|
1217
|
+
prepend,
|
|
1218
|
+
displaySystemLabels = true,
|
|
1219
|
+
onItemClick
|
|
1220
|
+
}) {
|
|
1221
|
+
const { getLabelsByIds, loading } = LabelsContainer.useContainer();
|
|
1222
|
+
const labelsWrapperRef = react.useRef(null);
|
|
1223
|
+
const [overflowIndex, setOverflowIndex] = react.useState(99999);
|
|
1224
|
+
let labelNodes = getLabelsByIds(labels || []);
|
|
1225
|
+
const size = ahooks.useSize(labelsWrapperRef);
|
|
1226
|
+
ahooks.useDeepCompareLayoutEffect(() => {
|
|
1227
|
+
if (compact) {
|
|
1228
|
+
if (labelsWrapperRef.current) {
|
|
1229
|
+
const { right } = labelsWrapperRef.current.getBoundingClientRect();
|
|
1230
|
+
const labelElements = labelsWrapperRef.current.querySelectorAll(".MuiChip-root");
|
|
1231
|
+
if ((labelElements == null ? void 0 : labelElements.length) > 0) {
|
|
1232
|
+
Array.from(labelElements).some((x, i) => {
|
|
1233
|
+
const rect = x.getBoundingClientRect();
|
|
1234
|
+
if (rect.right > right - 36) {
|
|
1235
|
+
setOverflowIndex(i);
|
|
1236
|
+
return true;
|
|
1237
|
+
}
|
|
1238
|
+
return false;
|
|
1239
|
+
});
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
} else {
|
|
1243
|
+
setOverflowIndex(99999);
|
|
1244
|
+
}
|
|
1245
|
+
}, [size, compact]);
|
|
1246
|
+
if (loading) {
|
|
1247
|
+
return null;
|
|
1248
|
+
}
|
|
1249
|
+
if (!displaySystemLabels) {
|
|
1250
|
+
labelNodes = labelNodes.filter((x) => x.data.type !== "system");
|
|
1251
|
+
}
|
|
1252
|
+
const mergedSx = [
|
|
1253
|
+
{
|
|
1254
|
+
display: "flex",
|
|
1255
|
+
gap: 1,
|
|
1256
|
+
width: "100%",
|
|
1257
|
+
alignItems: "center",
|
|
1258
|
+
overflow: "hidden",
|
|
1259
|
+
flexWrap: compact ? "no-wrap" : "wrap"
|
|
1260
|
+
},
|
|
1261
|
+
...Array.isArray(sx) ? sx : [sx]
|
|
1262
|
+
];
|
|
1263
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(material.Box, { sx: mergedSx, ref: labelsWrapperRef, children: [
|
|
1264
|
+
prepend,
|
|
1265
|
+
labelNodes.map((item, index) => {
|
|
1266
|
+
if (!item) {
|
|
1267
|
+
return null;
|
|
1268
|
+
}
|
|
1269
|
+
const visible = index < overflowIndex;
|
|
1270
|
+
let extra = null;
|
|
1271
|
+
if (index === overflowIndex) {
|
|
1272
|
+
extra = /* @__PURE__ */ jsxRuntime.jsx(
|
|
1273
|
+
material.Box,
|
|
1274
|
+
{
|
|
1275
|
+
sx: {
|
|
1276
|
+
display: "inline-flex",
|
|
1277
|
+
...compact && { height: 20, lineHeight: "20px" },
|
|
1278
|
+
color: "text.secondary",
|
|
1279
|
+
fontWeight: "bold",
|
|
1280
|
+
fontSize: 14
|
|
1281
|
+
},
|
|
1282
|
+
children: `+${labelNodes.length - overflowIndex}`
|
|
1283
|
+
},
|
|
1284
|
+
"overflow-label"
|
|
1285
|
+
);
|
|
1286
|
+
}
|
|
1287
|
+
let labelChip = /* @__PURE__ */ jsxRuntime.jsx(
|
|
1288
|
+
LabelChip,
|
|
1289
|
+
{
|
|
1290
|
+
label: item,
|
|
1291
|
+
onClick: onItemClick,
|
|
1292
|
+
sx: {
|
|
1293
|
+
visibility: visible ? "visible" : "hidden",
|
|
1294
|
+
pointerEvents: visible ? "auto" : "none"
|
|
1295
|
+
}
|
|
1296
|
+
},
|
|
1297
|
+
item.data.id
|
|
1298
|
+
);
|
|
1299
|
+
if (renderLabel) {
|
|
1300
|
+
labelChip = renderLabel(item, labelChip);
|
|
1301
|
+
}
|
|
1302
|
+
if (extra) {
|
|
1303
|
+
return [extra, labelChip];
|
|
1304
|
+
}
|
|
1305
|
+
return labelChip;
|
|
1306
|
+
})
|
|
1307
|
+
] });
|
|
1308
|
+
}
|
|
1296
1309
|
function LabelsInput({
|
|
1297
1310
|
value = [],
|
|
1298
1311
|
onChange,
|