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