@blocklet/labels 1.6.227 → 1.6.228

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
@@ -777,20 +777,19 @@ const useSessionContext = () => {
777
777
  };
778
778
  };
779
779
  const useRecentLabels = () => {
780
+ const { labelExists } = LabelsContainer.useContainer();
780
781
  const [recentLabels = [], setRecentLabels] = useLocalStorageState("recent-labels", {
781
782
  defaultValue: []
782
783
  });
784
+ const validLabels = recentLabels.filter((x) => labelExists(x));
783
785
  const addRecentLabel = (label) => {
784
- if (recentLabels.includes(label)) {
786
+ if (!label || validLabels.includes(label)) {
785
787
  return;
786
788
  }
787
- const newLabels = [label, ...recentLabels].slice(0, 10);
789
+ const newLabels = [label, ...validLabels].slice(0, 10);
788
790
  setRecentLabels(newLabels);
789
791
  };
790
- const addRecentLabels = (labels) => {
791
- labels.forEach((x) => addRecentLabel(x));
792
- };
793
- return { recentLabels, addRecentLabel, addRecentLabels };
792
+ return { recentLabels: validLabels, addRecentLabel };
794
793
  };
795
794
  function LabelChip$1({ name, selected, ...rest }) {
796
795
  return /* @__PURE__ */ jsx(
@@ -876,7 +875,7 @@ function GithubLabelPicker({
876
875
  const excludesSet = new Set(excludes);
877
876
  return labels.filter((x) => !excludesSet.has(x.data.id));
878
877
  }, [labels]);
879
- const { recentLabels, addRecentLabels } = useRecentLabels();
878
+ const { recentLabels, addRecentLabel } = useRecentLabels();
880
879
  const initialRecentLabels = useMemo(() => recentLabels, [anchorEl]);
881
880
  const handleClick = (event) => {
882
881
  if (disabled) {
@@ -902,7 +901,6 @@ function GithubLabelPicker({
902
901
  };
903
902
  const handleChange = (newValue) => {
904
903
  setPendingValue(newValue);
905
- addRecentLabels(newValue);
906
904
  if (!multiple) {
907
905
  onChange == null ? void 0 : onChange(newValue.length ? [newValue[newValue.length - 1]] : []);
908
906
  setAnchorEl(null);
@@ -996,6 +994,9 @@ function GithubLabelPicker({
996
994
  if (event.type === "keydown" && event.key === "Backspace" && reason === "removeOption") {
997
995
  return;
998
996
  }
997
+ if (reason === "selectOption") {
998
+ addRecentLabel(newValue[newValue.length - 1].data.id);
999
+ }
999
1000
  handleChange(newValue.map((x) => x.data.id));
1000
1001
  },
1001
1002
  disableCloseOnSelect: true,
package/dist/index.umd.js CHANGED
@@ -764,20 +764,19 @@ var __publicField = (obj, key, value) => {
764
764
  };
765
765
  };
766
766
  const useRecentLabels = () => {
767
+ const { labelExists } = LabelsContainer.useContainer();
767
768
  const [recentLabels = [], setRecentLabels] = ahooks.useLocalStorageState("recent-labels", {
768
769
  defaultValue: []
769
770
  });
771
+ const validLabels = recentLabels.filter((x) => labelExists(x));
770
772
  const addRecentLabel = (label) => {
771
- if (recentLabels.includes(label)) {
773
+ if (!label || validLabels.includes(label)) {
772
774
  return;
773
775
  }
774
- const newLabels = [label, ...recentLabels].slice(0, 10);
776
+ const newLabels = [label, ...validLabels].slice(0, 10);
775
777
  setRecentLabels(newLabels);
776
778
  };
777
- const addRecentLabels = (labels) => {
778
- labels.forEach((x) => addRecentLabel(x));
779
- };
780
- return { recentLabels, addRecentLabel, addRecentLabels };
779
+ return { recentLabels: validLabels, addRecentLabel };
781
780
  };
782
781
  function LabelChip$1({ name, selected, ...rest }) {
783
782
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -863,7 +862,7 @@ var __publicField = (obj, key, value) => {
863
862
  const excludesSet = new Set(excludes);
864
863
  return labels.filter((x) => !excludesSet.has(x.data.id));
865
864
  }, [labels]);
866
- const { recentLabels, addRecentLabels } = useRecentLabels();
865
+ const { recentLabels, addRecentLabel } = useRecentLabels();
867
866
  const initialRecentLabels = react.useMemo(() => recentLabels, [anchorEl]);
868
867
  const handleClick = (event) => {
869
868
  if (disabled) {
@@ -889,7 +888,6 @@ var __publicField = (obj, key, value) => {
889
888
  };
890
889
  const handleChange = (newValue) => {
891
890
  setPendingValue(newValue);
892
- addRecentLabels(newValue);
893
891
  if (!multiple) {
894
892
  onChange == null ? void 0 : onChange(newValue.length ? [newValue[newValue.length - 1]] : []);
895
893
  setAnchorEl(null);
@@ -983,6 +981,9 @@ var __publicField = (obj, key, value) => {
983
981
  if (event.type === "keydown" && event.key === "Backspace" && reason === "removeOption") {
984
982
  return;
985
983
  }
984
+ if (reason === "selectOption") {
985
+ addRecentLabel(newValue[newValue.length - 1].data.id);
986
+ }
986
987
  handleChange(newValue.map((x) => x.data.id));
987
988
  },
988
989
  disableCloseOnSelect: true,
@@ -1,5 +1,4 @@
1
1
  export declare const useRecentLabels: () => {
2
2
  recentLabels: string[];
3
- addRecentLabel: (label: string) => void;
4
- addRecentLabels: (labels: string[]) => void;
3
+ addRecentLabel: (label?: string) => void;
5
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/labels",
3
- "version": "1.6.227",
3
+ "version": "1.6.228",
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.227",
31
+ "@blocklet/translation-input": "1.6.228",
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": "7a206969add11cc56110f55fe86837322e2d7591"
86
+ "gitHead": "06637438fe38e74912996e17e7c78fedee89cfdd"
87
87
  }