@wallavi/widget 1.4.2 → 1.4.4

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.js CHANGED
@@ -850,9 +850,21 @@ function BubbleWidget({
850
850
  const [internalOpen, setInternalOpen] = react.useState(false);
851
851
  const open = isControlled ? isOpenProp : internalOpen;
852
852
  const setOpen = react.useCallback((valueOrUpdater) => {
853
- const next = typeof valueOrUpdater === "function" ? valueOrUpdater(open) : valueOrUpdater;
854
- if (!isControlled) setInternalOpen(next);
855
- onOpenChange?.(next);
853
+ if (!isControlled) {
854
+ if (typeof valueOrUpdater === "function") {
855
+ setInternalOpen((prev) => {
856
+ const next = valueOrUpdater(prev);
857
+ onOpenChange?.(next);
858
+ return next;
859
+ });
860
+ } else {
861
+ setInternalOpen(valueOrUpdater);
862
+ onOpenChange?.(valueOrUpdater);
863
+ }
864
+ } else {
865
+ const next = typeof valueOrUpdater === "function" ? valueOrUpdater(open) : valueOrUpdater;
866
+ onOpenChange?.(next);
867
+ }
856
868
  }, [isControlled, open, onOpenChange]);
857
869
  const [expanded, setExpanded] = react.useState(false);
858
870
  const panelRef = react.useRef(null);
@@ -907,12 +919,16 @@ function BubbleWidget({
907
919
  setOpen(true);
908
920
  }
909
921
  }, [resolvedAutoOpen]);
922
+ const setOpenRef = react.useRef(setOpen);
923
+ react.useEffect(() => {
924
+ setOpenRef.current = setOpen;
925
+ });
910
926
  react.useEffect(() => {
911
927
  if (!resolvedKeyboardShortcut) return;
912
928
  const onKey = (e) => {
913
929
  if ((e.metaKey || e.ctrlKey) && e.key === shortcutKey) {
914
930
  e.preventDefault();
915
- setOpen((v) => !v);
931
+ setOpenRef.current((v) => !v);
916
932
  }
917
933
  };
918
934
  window.addEventListener("keydown", onKey);
package/dist/index.mjs CHANGED
@@ -824,9 +824,21 @@ function BubbleWidget({
824
824
  const [internalOpen, setInternalOpen] = useState(false);
825
825
  const open = isControlled ? isOpenProp : internalOpen;
826
826
  const setOpen = useCallback((valueOrUpdater) => {
827
- const next = typeof valueOrUpdater === "function" ? valueOrUpdater(open) : valueOrUpdater;
828
- if (!isControlled) setInternalOpen(next);
829
- onOpenChange?.(next);
827
+ if (!isControlled) {
828
+ if (typeof valueOrUpdater === "function") {
829
+ setInternalOpen((prev) => {
830
+ const next = valueOrUpdater(prev);
831
+ onOpenChange?.(next);
832
+ return next;
833
+ });
834
+ } else {
835
+ setInternalOpen(valueOrUpdater);
836
+ onOpenChange?.(valueOrUpdater);
837
+ }
838
+ } else {
839
+ const next = typeof valueOrUpdater === "function" ? valueOrUpdater(open) : valueOrUpdater;
840
+ onOpenChange?.(next);
841
+ }
830
842
  }, [isControlled, open, onOpenChange]);
831
843
  const [expanded, setExpanded] = useState(false);
832
844
  const panelRef = useRef(null);
@@ -881,12 +893,16 @@ function BubbleWidget({
881
893
  setOpen(true);
882
894
  }
883
895
  }, [resolvedAutoOpen]);
896
+ const setOpenRef = useRef(setOpen);
897
+ useEffect(() => {
898
+ setOpenRef.current = setOpen;
899
+ });
884
900
  useEffect(() => {
885
901
  if (!resolvedKeyboardShortcut) return;
886
902
  const onKey = (e) => {
887
903
  if ((e.metaKey || e.ctrlKey) && e.key === shortcutKey) {
888
904
  e.preventDefault();
889
- setOpen((v) => !v);
905
+ setOpenRef.current((v) => !v);
890
906
  }
891
907
  };
892
908
  window.addEventListener("keydown", onKey);
package/package.json CHANGED
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "private": false,
35
35
  "types": "./dist/index.d.ts",
36
- "version": "1.4.2",
36
+ "version": "1.4.4",
37
37
  "scripts": {
38
38
  "build": "tsup",
39
39
  "typecheck": "tsc --noEmit"