@ariakit/react-core 0.2.14 → 0.2.16

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.
Files changed (203) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/cjs/__chunks/{GHDSJPDP.cjs → 2CBM6TG2.cjs} +9 -1
  3. package/cjs/__chunks/{JQNHOFVL.cjs → 4PH5LF7R.cjs} +4 -4
  4. package/cjs/__chunks/{IMHF4TCR.cjs → 5SFIKBWF.cjs} +2 -2
  5. package/cjs/__chunks/{XE2DJMCI.cjs → 6BAHKJ5K.cjs} +14 -20
  6. package/cjs/__chunks/{G2UVEERG.cjs → AHLK6SVF.cjs} +10 -10
  7. package/cjs/__chunks/{GICQ7PSP.cjs → BIJBAZHT.cjs} +2 -2
  8. package/cjs/__chunks/{AMRCH2Z5.cjs → BW4OCE2W.cjs} +4 -4
  9. package/cjs/__chunks/{ZWMVFMQY.cjs → CHVOMF22.cjs} +4 -4
  10. package/cjs/__chunks/{FWCSM5BC.cjs → CY7GQARX.cjs} +13 -13
  11. package/cjs/__chunks/{SIVNE3PR.cjs → ETK4FMZH.cjs} +12 -12
  12. package/cjs/__chunks/{FNDPLH5R.cjs → EVXAMK7D.cjs} +6 -8
  13. package/cjs/__chunks/{KD3RAGO6.cjs → EWI7RF64.cjs} +5 -5
  14. package/cjs/__chunks/{LE4VG2T4.cjs → EYVMZOCS.cjs} +8 -8
  15. package/cjs/__chunks/{O22LNQHS.cjs → FA3DXDDT.cjs} +2 -2
  16. package/cjs/__chunks/{JMBF4JHZ.cjs → FNKDTHTN.cjs} +4 -4
  17. package/cjs/__chunks/{LZV54A37.cjs → FVVV75ZK.cjs} +2 -2
  18. package/cjs/__chunks/{745H7MDU.cjs → GAQNLEPX.cjs} +6 -6
  19. package/cjs/__chunks/{FSADYSOP.cjs → HTEAWNBY.cjs} +14 -3
  20. package/cjs/__chunks/{HSFSIYIQ.cjs → JLC4GR5L.cjs} +2 -2
  21. package/cjs/__chunks/{HUVFPCMZ.cjs → KJBIRAH5.cjs} +24 -6
  22. package/cjs/__chunks/{OYXMXGQJ.cjs → KKAG47JR.cjs} +2 -2
  23. package/cjs/__chunks/{VBRBBWCP.cjs → NH6Q6YSM.cjs} +2 -2
  24. package/cjs/__chunks/{3MC2XJ5F.cjs → OHBR6IPU.cjs} +45 -33
  25. package/cjs/__chunks/{PRMEV7L5.cjs → PBJASQI6.cjs} +4 -4
  26. package/cjs/__chunks/{TFOIZV2V.cjs → PD5YFDLO.cjs} +3 -2
  27. package/cjs/__chunks/{IQIITEH3.cjs → QCWWP2P4.cjs} +2 -2
  28. package/cjs/__chunks/QW7NAUIX.cjs +113 -0
  29. package/cjs/__chunks/{63OBHNVT.cjs → VB7SPR3I.cjs} +7 -7
  30. package/cjs/__chunks/{LG6XOVBQ.cjs → VGBPLBUZ.cjs} +3 -3
  31. package/cjs/__chunks/{44MSVBJL.cjs → VKPXIX7D.cjs} +3 -3
  32. package/cjs/checkbox/checkbox-store.cjs +3 -3
  33. package/cjs/checkbox/checkbox.cjs +3 -3
  34. package/cjs/collection/collection-item.cjs +2 -2
  35. package/cjs/collection/collection-renderer.cjs +3 -3
  36. package/cjs/collection/collection-store.cjs +3 -3
  37. package/cjs/combobox/combobox-item.cjs +4 -4
  38. package/cjs/combobox/combobox-popover.cjs +12 -12
  39. package/cjs/combobox/combobox-store.cjs +11 -11
  40. package/cjs/combobox/combobox.cjs +3 -3
  41. package/cjs/composite/composite-container.cjs +3 -3
  42. package/cjs/composite/composite-item.cjs +4 -4
  43. package/cjs/composite/composite-overflow-disclosure.cjs +7 -6
  44. package/cjs/composite/composite-overflow-store.cjs +7 -7
  45. package/cjs/composite/composite-overflow.cjs +12 -12
  46. package/cjs/composite/composite-renderer.cjs +4 -4
  47. package/cjs/composite/composite-store.cjs +4 -4
  48. package/cjs/dialog/dialog-backdrop.cjs +6 -6
  49. package/cjs/dialog/dialog-store.cjs +4 -4
  50. package/cjs/dialog/dialog.cjs +11 -11
  51. package/cjs/dialog/utils/disable-accessibility-tree-outside.cjs +3 -3
  52. package/cjs/dialog/utils/disable-tree-outside.cjs +4 -4
  53. package/cjs/dialog/utils/mark-tree-outside.cjs +3 -3
  54. package/cjs/dialog/utils/use-hide-on-interact-outside.cjs +4 -4
  55. package/cjs/dialog/utils/use-hide-on-interact-outside.d.ts +1 -1
  56. package/cjs/dialog/utils/use-nested-dialogs.cjs +2 -2
  57. package/cjs/dialog/utils/walk-tree-outside.cjs +2 -2
  58. package/cjs/dialog/utils/walk-tree-outside.d.ts +1 -1
  59. package/cjs/disclosure/disclosure-store.cjs +3 -3
  60. package/cjs/focusable/focusable.d.ts +52 -13
  61. package/cjs/form/form-checkbox.cjs +8 -8
  62. package/cjs/form/form-description.cjs +2 -2
  63. package/cjs/form/form-error.cjs +2 -2
  64. package/cjs/form/form-field.cjs +3 -3
  65. package/cjs/form/form-input.cjs +3 -3
  66. package/cjs/form/form-label.cjs +2 -2
  67. package/cjs/form/form-push.cjs +2 -2
  68. package/cjs/form/form-radio.cjs +7 -7
  69. package/cjs/form/form-store.cjs +8 -8
  70. package/cjs/hovercard/hovercard-anchor.cjs +2 -2
  71. package/cjs/hovercard/hovercard-disclosure.cjs +12 -14
  72. package/cjs/hovercard/hovercard-store.cjs +6 -6
  73. package/cjs/hovercard/hovercard.cjs +13 -13
  74. package/cjs/menu/menu-bar-store.cjs +6 -6
  75. package/cjs/menu/menu-button.cjs +9 -6
  76. package/cjs/menu/menu-item-checkbox.cjs +9 -9
  77. package/cjs/menu/menu-item-radio.cjs +7 -7
  78. package/cjs/menu/menu-item.cjs +5 -5
  79. package/cjs/menu/menu-list.cjs +3 -3
  80. package/cjs/menu/menu-store.cjs +13 -13
  81. package/cjs/menu/menu.cjs +15 -15
  82. package/cjs/popover/popover-store.cjs +5 -5
  83. package/cjs/popover/popover.cjs +12 -12
  84. package/cjs/radio/radio-store.cjs +7 -7
  85. package/cjs/radio/radio.cjs +5 -5
  86. package/cjs/select/select-item.cjs +4 -4
  87. package/cjs/select/select-popover.cjs +12 -12
  88. package/cjs/select/select-renderer.cjs +7 -7
  89. package/cjs/select/select-store.cjs +11 -11
  90. package/cjs/tab/tab-panel.cjs +5 -5
  91. package/cjs/tab/tab-store.cjs +9 -9
  92. package/cjs/tab/tab.cjs +4 -4
  93. package/cjs/toolbar/toolbar-container.cjs +7 -7
  94. package/cjs/toolbar/toolbar-input.cjs +5 -5
  95. package/cjs/toolbar/toolbar-item.cjs +5 -5
  96. package/cjs/toolbar/toolbar-store.cjs +6 -6
  97. package/cjs/tooltip/tooltip-anchor.cjs +33 -20
  98. package/cjs/tooltip/tooltip-store.cjs +10 -10
  99. package/cjs/tooltip/tooltip.cjs +13 -13
  100. package/cjs/tsconfig.build.tsbuildinfo +1 -1
  101. package/cjs/utils/store.cjs +2 -2
  102. package/esm/__chunks/{7J6H5Y2H.js → 432NLB7J.js} +2 -2
  103. package/esm/__chunks/{FV23EKJL.js → 5M4ITSXL.js} +3 -2
  104. package/esm/__chunks/{6RR2HJXR.js → 5PDNXTAR.js} +1 -1
  105. package/esm/__chunks/{QHXLY5NM.js → 5QHNNZNE.js} +1 -1
  106. package/esm/__chunks/{WEWVELT3.js → 6F6CCCKT.js} +1 -1
  107. package/esm/__chunks/{DCG3EYDE.js → 7SIWUER2.js} +2 -2
  108. package/esm/__chunks/{F6KX6FT7.js → CEBWVZJQ.js} +2 -2
  109. package/esm/__chunks/{DIA4OBYO.js → CU3AKJBN.js} +1 -1
  110. package/esm/__chunks/{5TTSBUCW.js → CYNFBMYS.js} +1 -1
  111. package/esm/__chunks/{4XWTU3WN.js → E5XSMSHD.js} +25 -7
  112. package/esm/__chunks/{6RGH36XF.js → EICJBDBV.js} +2 -2
  113. package/esm/__chunks/{WVP274TO.js → F6PEGR7W.js} +1 -1
  114. package/esm/__chunks/{WKNTOKYS.js → FSTINJD5.js} +1 -1
  115. package/esm/__chunks/{LUUMYNYQ.js → FW5SU7FV.js} +2 -2
  116. package/esm/__chunks/{CYJJUQU3.js → GDORSOK6.js} +1 -1
  117. package/esm/__chunks/{HCTED3MY.js → JD3UVZX5.js} +1 -1
  118. package/esm/__chunks/{HCZMY53N.js → LEBYH5FW.js} +13 -2
  119. package/esm/__chunks/{AR6DTI3S.js → NHPU54IO.js} +2 -2
  120. package/esm/__chunks/{RH5PYIJN.js → ORZC42PG.js} +5 -7
  121. package/esm/__chunks/{OEA63YXU.js → PLOINBVB.js} +14 -20
  122. package/esm/__chunks/{VKYM5S67.js → Q52PUUUL.js} +1 -1
  123. package/esm/__chunks/{HWFO52CA.js → QJUX534W.js} +2 -2
  124. package/esm/__chunks/{OOWNFOTF.js → QPTZ2G2N.js} +51 -28
  125. package/esm/__chunks/{NCSSU46J.js → R4VIEIUH.js} +1 -1
  126. package/esm/__chunks/{GADPWICI.js → TG7IDXTX.js} +38 -26
  127. package/esm/__chunks/{KRFS2JCI.js → TQ5BKSY4.js} +2 -2
  128. package/esm/__chunks/{C2N5FZMW.js → UKOZA6YP.js} +2 -2
  129. package/esm/__chunks/{HGFTMLQ7.js → VFNGSUSF.js} +13 -13
  130. package/esm/__chunks/{5PLAJI33.js → X5CHG5LF.js} +2 -2
  131. package/esm/__chunks/{I3PXTXPI.js → Y5XLHDDM.js} +9 -1
  132. package/esm/checkbox/checkbox-store.js +2 -2
  133. package/esm/checkbox/checkbox.js +2 -2
  134. package/esm/collection/collection-item.js +1 -1
  135. package/esm/collection/collection-renderer.js +2 -2
  136. package/esm/collection/collection-store.js +2 -2
  137. package/esm/combobox/combobox-item.js +3 -3
  138. package/esm/combobox/combobox-popover.js +11 -11
  139. package/esm/combobox/combobox-store.js +6 -6
  140. package/esm/combobox/combobox.js +3 -3
  141. package/esm/composite/composite-container.js +2 -2
  142. package/esm/composite/composite-item.js +3 -3
  143. package/esm/composite/composite-overflow-disclosure.js +6 -5
  144. package/esm/composite/composite-overflow-store.js +4 -4
  145. package/esm/composite/composite-overflow.js +11 -11
  146. package/esm/composite/composite-renderer.js +3 -3
  147. package/esm/composite/composite-store.js +3 -3
  148. package/esm/dialog/dialog-backdrop.js +5 -5
  149. package/esm/dialog/dialog-store.js +3 -3
  150. package/esm/dialog/dialog.js +10 -10
  151. package/esm/dialog/utils/disable-accessibility-tree-outside.js +2 -2
  152. package/esm/dialog/utils/disable-tree-outside.js +3 -3
  153. package/esm/dialog/utils/mark-tree-outside.js +2 -2
  154. package/esm/dialog/utils/use-hide-on-interact-outside.d.ts +1 -1
  155. package/esm/dialog/utils/use-hide-on-interact-outside.js +3 -3
  156. package/esm/dialog/utils/use-nested-dialogs.js +1 -1
  157. package/esm/dialog/utils/walk-tree-outside.d.ts +1 -1
  158. package/esm/dialog/utils/walk-tree-outside.js +1 -1
  159. package/esm/disclosure/disclosure-store.js +2 -2
  160. package/esm/focusable/focusable.d.ts +52 -13
  161. package/esm/form/form-checkbox.js +5 -5
  162. package/esm/form/form-description.js +1 -1
  163. package/esm/form/form-error.js +1 -1
  164. package/esm/form/form-field.js +2 -2
  165. package/esm/form/form-input.js +2 -2
  166. package/esm/form/form-label.js +1 -1
  167. package/esm/form/form-push.js +1 -1
  168. package/esm/form/form-radio.js +5 -5
  169. package/esm/form/form-store.js +2 -2
  170. package/esm/hovercard/hovercard-anchor.js +1 -1
  171. package/esm/hovercard/hovercard-disclosure.js +12 -14
  172. package/esm/hovercard/hovercard-store.js +5 -5
  173. package/esm/hovercard/hovercard.js +12 -12
  174. package/esm/menu/menu-bar-store.js +3 -3
  175. package/esm/menu/menu-button.js +7 -4
  176. package/esm/menu/menu-item-checkbox.js +6 -6
  177. package/esm/menu/menu-item-radio.js +5 -5
  178. package/esm/menu/menu-item.js +4 -4
  179. package/esm/menu/menu-list.js +2 -2
  180. package/esm/menu/menu-store.js +7 -7
  181. package/esm/menu/menu.js +13 -13
  182. package/esm/popover/popover-store.js +4 -4
  183. package/esm/popover/popover.js +11 -11
  184. package/esm/radio/radio-store.js +3 -3
  185. package/esm/radio/radio.js +4 -4
  186. package/esm/select/select-item.js +3 -3
  187. package/esm/select/select-popover.js +11 -11
  188. package/esm/select/select-renderer.js +3 -3
  189. package/esm/select/select-store.js +6 -6
  190. package/esm/tab/tab-panel.js +3 -3
  191. package/esm/tab/tab-store.js +3 -3
  192. package/esm/tab/tab.js +3 -3
  193. package/esm/toolbar/toolbar-container.js +5 -5
  194. package/esm/toolbar/toolbar-input.js +4 -4
  195. package/esm/toolbar/toolbar-item.js +4 -4
  196. package/esm/toolbar/toolbar-store.js +3 -3
  197. package/esm/tooltip/tooltip-anchor.js +34 -21
  198. package/esm/tooltip/tooltip-store.js +5 -5
  199. package/esm/tooltip/tooltip.js +12 -12
  200. package/esm/tsconfig.build.tsbuildinfo +1 -1
  201. package/esm/utils/store.js +1 -1
  202. package/package.json +2 -2
  203. package/cjs/__chunks/KLWT4P56.cjs +0 -90
@@ -20,12 +20,13 @@ function walkTreeOutside(elements, callback, ancestorCallback) {
20
20
  return maybeAncestor.contains(element);
21
21
  });
22
22
  const doc = getDocument(element);
23
+ const originalElement = element;
23
24
  while (element.parentElement && element !== doc.body) {
24
- ancestorCallback == null ? void 0 : ancestorCallback(element.parentElement);
25
+ ancestorCallback == null ? void 0 : ancestorCallback(element.parentElement, originalElement);
25
26
  if (!hasAncestorAlready) {
26
27
  for (const child of element.parentElement.children) {
27
28
  if (isValidElement(child, elements)) {
28
- callback(child);
29
+ callback(child, originalElement);
29
30
  }
30
31
  }
31
32
  }
@@ -7,7 +7,7 @@ import {
7
7
  } from "./NQJBHION.js";
8
8
  import {
9
9
  useStoreState
10
- } from "./OOWNFOTF.js";
10
+ } from "./QPTZ2G2N.js";
11
11
  import {
12
12
  useBooleanEvent,
13
13
  useEvent,
@@ -3,7 +3,7 @@ import {
3
3
  } from "./P3I4MECH.js";
4
4
  import {
5
5
  useCollectionItem
6
- } from "./HGFTMLQ7.js";
6
+ } from "./VFNGSUSF.js";
7
7
  import {
8
8
  createElement,
9
9
  createHook,
@@ -18,7 +18,7 @@ import {
18
18
  } from "./NQJBHION.js";
19
19
  import {
20
20
  useStoreState
21
- } from "./OOWNFOTF.js";
21
+ } from "./QPTZ2G2N.js";
22
22
  import {
23
23
  useEvent,
24
24
  useId,
@@ -3,7 +3,7 @@ import {
3
3
  } from "./P4RGQGTG.js";
4
4
  import {
5
5
  useCollectionItem
6
- } from "./HGFTMLQ7.js";
6
+ } from "./VFNGSUSF.js";
7
7
  import {
8
8
  focusSilently,
9
9
  getEnabledItem,
@@ -21,7 +21,7 @@ import {
21
21
  } from "./NQJBHION.js";
22
22
  import {
23
23
  useStoreState
24
- } from "./OOWNFOTF.js";
24
+ } from "./QPTZ2G2N.js";
25
25
  import {
26
26
  useBooleanEvent,
27
27
  useEvent,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getCollectionRendererItemId,
3
3
  useCollectionRenderer
4
- } from "./6RR2HJXR.js";
4
+ } from "./5PDNXTAR.js";
5
5
  import {
6
6
  CompositeContext
7
7
  } from "./WJ37OVG2.js";
@@ -11,7 +11,7 @@ import {
11
11
  } from "./NQJBHION.js";
12
12
  import {
13
13
  useStoreState
14
- } from "./OOWNFOTF.js";
14
+ } from "./QPTZ2G2N.js";
15
15
  import {
16
16
  useId
17
17
  } from "./J7Q2EO23.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useDialog
3
- } from "./GADPWICI.js";
3
+ } from "./TG7IDXTX.js";
4
4
  import {
5
5
  PopoverContext
6
6
  } from "./6GS36SYX.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  useStore,
3
3
  useStoreProps
4
- } from "./OOWNFOTF.js";
4
+ } from "./QPTZ2G2N.js";
5
5
 
6
6
  // src/checkbox/checkbox-store.ts
7
7
  import * as Core from "@ariakit/core/checkbox/checkbox-store";
@@ -1,11 +1,12 @@
1
1
  import {
2
2
  isElementMarked
3
- } from "./HCZMY53N.js";
3
+ } from "./LEBYH5FW.js";
4
4
  import {
5
5
  usePreviousMouseDownRef
6
6
  } from "./7JNF6I52.js";
7
7
  import {
8
- useEvent
8
+ useEvent,
9
+ useSafeLayoutEffect
9
10
  } from "./J7Q2EO23.js";
10
11
  import {
11
12
  __spreadProps,
@@ -13,7 +14,7 @@ import {
13
14
  } from "./PNRLI7OV.js";
14
15
 
15
16
  // src/dialog/utils/use-hide-on-interact-outside.ts
16
- import { useEffect } from "react";
17
+ import { useEffect, useRef } from "react";
17
18
  import { contains, getDocument, isVisible } from "@ariakit/core/utils/dom";
18
19
  import { addGlobalEventListener } from "@ariakit/core/utils/events";
19
20
  function isInDocument(target) {
@@ -47,10 +48,26 @@ function useEventOutside({
47
48
  store,
48
49
  type,
49
50
  listener,
50
- capture
51
+ capture,
52
+ domReady
51
53
  }) {
52
54
  const callListener = useEvent(listener);
53
55
  const open = store.useState("open");
56
+ const focusedRef = useRef(false);
57
+ useSafeLayoutEffect(() => {
58
+ if (!open)
59
+ return;
60
+ if (!domReady)
61
+ return;
62
+ const { contentElement } = store.getState();
63
+ if (!contentElement)
64
+ return;
65
+ const onFocus = () => {
66
+ focusedRef.current = true;
67
+ };
68
+ contentElement.addEventListener("focusin", onFocus, true);
69
+ return () => contentElement.removeEventListener("focusin", onFocus, true);
70
+ }, [store, open, domReady]);
54
71
  useEffect(() => {
55
72
  if (!open)
56
73
  return;
@@ -71,7 +88,8 @@ function useEventOutside({
71
88
  return;
72
89
  if (isMouseEventOnDialog(event, contentElement))
73
90
  return;
74
- if (!isElementMarked(target, contentElement.id))
91
+ const focused = focusedRef.current;
92
+ if (focused && !isElementMarked(target, contentElement.id))
75
93
  return;
76
94
  callListener(event);
77
95
  };
@@ -84,10 +102,10 @@ function shouldHideOnInteractOutside(hideOnInteractOutside, event) {
84
102
  }
85
103
  return !!hideOnInteractOutside;
86
104
  }
87
- function useHideOnInteractOutside(store, hideOnInteractOutside) {
105
+ function useHideOnInteractOutside(store, hideOnInteractOutside, domReady) {
88
106
  const open = store.useState("open");
89
107
  const previousMouseDownRef = usePreviousMouseDownRef(open);
90
- const props = { store, capture: true };
108
+ const props = { store, domReady, capture: true };
91
109
  useEventOutside(__spreadProps(__spreadValues({}, props), {
92
110
  type: "click",
93
111
  listener: (event) => {
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  useDialogStoreOptions,
3
3
  useDialogStoreProps
4
- } from "./LUUMYNYQ.js";
4
+ } from "./FW5SU7FV.js";
5
5
  import {
6
6
  useStore,
7
7
  useStoreProps
8
- } from "./OOWNFOTF.js";
8
+ } from "./QPTZ2G2N.js";
9
9
  import {
10
10
  __spreadValues
11
11
  } from "./PNRLI7OV.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  useStore,
3
3
  useStoreProps
4
- } from "./OOWNFOTF.js";
4
+ } from "./QPTZ2G2N.js";
5
5
  import {
6
6
  __spreadValues
7
7
  } from "./PNRLI7OV.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  useStore,
3
3
  useStoreProps
4
- } from "./OOWNFOTF.js";
4
+ } from "./QPTZ2G2N.js";
5
5
  import {
6
6
  __spreadValues
7
7
  } from "./PNRLI7OV.js";
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  useDisclosureStoreOptions,
3
3
  useDisclosureStoreProps
4
- } from "./WVP274TO.js";
4
+ } from "./F6PEGR7W.js";
5
5
  import {
6
6
  useStore
7
- } from "./OOWNFOTF.js";
7
+ } from "./QPTZ2G2N.js";
8
8
  import {
9
9
  __spreadValues
10
10
  } from "./PNRLI7OV.js";
@@ -6,7 +6,7 @@ import {
6
6
  } from "./FW6QFGFT.js";
7
7
  import {
8
8
  walkTreeOutside
9
- } from "./FV23EKJL.js";
9
+ } from "./5M4ITSXL.js";
10
10
 
11
11
  // src/dialog/utils/disable-accessibility-tree-outside.ts
12
12
  function hideElementFromAccessibilityTree(element) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useCompositeItem
3
- } from "./DCG3EYDE.js";
3
+ } from "./7SIWUER2.js";
4
4
  import {
5
5
  createElement,
6
6
  createHook,
@@ -6,7 +6,7 @@ import {
6
6
  } from "./FW6QFGFT.js";
7
7
  import {
8
8
  walkTreeOutside
9
- } from "./FV23EKJL.js";
9
+ } from "./5M4ITSXL.js";
10
10
 
11
11
  // src/dialog/utils/mark-tree-outside.ts
12
12
  import { chain } from "@ariakit/core/utils/misc";
@@ -15,12 +15,18 @@ function getPropertyName(id = "", ancestor = false) {
15
15
  }
16
16
  function markElement(element, id = "") {
17
17
  return chain(
18
+ // Debug
19
+ // setAttribute(element, getPropertyName(), "true"),
20
+ // setAttribute(element, getPropertyName(id), "true"),
18
21
  setProperty(element, getPropertyName(), true),
19
22
  setProperty(element, getPropertyName(id), true)
20
23
  );
21
24
  }
22
25
  function markAncestor(element, id = "") {
23
26
  return chain(
27
+ // Debug
28
+ // setAttribute(element, getPropertyName("", true), "true"),
29
+ // setAttribute(element, getPropertyName(id, true), "true"),
24
30
  setProperty(element, getPropertyName("", true), true),
25
31
  setProperty(element, getPropertyName(id, true), true)
26
32
  );
@@ -48,7 +54,12 @@ function markTreeOutside(dialogId, ...elements) {
48
54
  return;
49
55
  cleanups.unshift(markElement(element, dialogId));
50
56
  },
51
- (ancestor) => cleanups.unshift(markAncestor(ancestor, dialogId))
57
+ (ancestor, element) => {
58
+ const isAnotherDialogAncestor = element.hasAttribute("data-dialog") && element.id !== dialogId;
59
+ if (isAnotherDialogAncestor)
60
+ return;
61
+ cleanups.unshift(markAncestor(ancestor, dialogId));
62
+ }
52
63
  );
53
64
  const restoreAccessibilityTree = () => {
54
65
  cleanups.forEach((fn) => fn());
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  hideElementFromAccessibilityTree
3
- } from "./CYJJUQU3.js";
3
+ } from "./GDORSOK6.js";
4
4
  import {
5
5
  isBackdrop
6
6
  } from "./IXXFVVA2.js";
@@ -14,7 +14,7 @@ import {
14
14
  } from "./FW6QFGFT.js";
15
15
  import {
16
16
  walkTreeOutside
17
- } from "./FV23EKJL.js";
17
+ } from "./5M4ITSXL.js";
18
18
 
19
19
  // src/dialog/utils/disable-tree-outside.ts
20
20
  import { contains } from "@ariakit/core/utils/dom";
@@ -5,7 +5,7 @@ import {
5
5
  } from "./X7FKJQME.js";
6
6
  import {
7
7
  usePopover
8
- } from "./DIA4OBYO.js";
8
+ } from "./CU3AKJBN.js";
9
9
  import {
10
10
  createComponent,
11
11
  createElement,
@@ -39,6 +39,7 @@ import { contains } from "@ariakit/core/utils/dom";
39
39
  import { addGlobalEventListener } from "@ariakit/core/utils/events";
40
40
  import { hasFocusWithin } from "@ariakit/core/utils/focus";
41
41
  import { chain, isFalsyBooleanCallback } from "@ariakit/core/utils/misc";
42
+ import { sync } from "@ariakit/core/utils/store";
42
43
  import { jsx } from "react/jsx-runtime";
43
44
  function isMovingOnHovercard(target, card, anchor, nested) {
44
45
  if (hasFocusWithin(card))
@@ -95,12 +96,9 @@ function useAutoFocusOnHide(_a) {
95
96
  });
96
97
  const finalFocusRef = useRef(null);
97
98
  useEffect(() => {
98
- return store.sync(
99
- (state) => {
100
- finalFocusRef.current = state.anchorElement;
101
- },
102
- ["anchorElement"]
103
- );
99
+ return sync(store, ["anchorElement"], (state) => {
100
+ finalFocusRef.current = state.anchorElement;
101
+ });
104
102
  }, []);
105
103
  props = __spreadProps(__spreadValues({
106
104
  autoFocusOnHide,
@@ -11,6 +11,7 @@ import {
11
11
  useState
12
12
  } from "react";
13
13
  import { chain } from "@ariakit/core/utils/misc";
14
+ import { sync } from "@ariakit/core/utils/store";
14
15
  import { jsx } from "react/jsx-runtime";
15
16
  var NestedDialogsContext = createContext({});
16
17
  function useNestedDialogs(store) {
@@ -27,28 +28,21 @@ function useNestedDialogs(store) {
27
28
  [context]
28
29
  );
29
30
  useSafeLayoutEffect(() => {
30
- return store.sync(
31
- (state) => {
32
- var _a;
33
- if (!state.open)
34
- return;
35
- if (!state.contentElement)
36
- return;
37
- return (_a = context.add) == null ? void 0 : _a.call(context, store);
38
- },
39
- ["open", "contentElement"]
40
- );
31
+ return sync(store, ["open", "contentElement"], (state) => {
32
+ var _a;
33
+ if (!state.open)
34
+ return;
35
+ if (!state.contentElement)
36
+ return;
37
+ return (_a = context.add) == null ? void 0 : _a.call(context, store);
38
+ });
41
39
  }, [store, context]);
42
40
  useSafeLayoutEffect(() => {
43
- var _a;
44
- return (_a = context.store) == null ? void 0 : _a.sync(
45
- (state) => {
46
- if (state.open)
47
- return;
48
- store.hide();
49
- },
50
- ["open"]
51
- );
41
+ return sync(context.store, ["open"], (state) => {
42
+ if (state.open)
43
+ return;
44
+ store.hide();
45
+ });
52
46
  }, [context, store]);
53
47
  const providerValue = useMemo(() => ({ store, add }), [store, add]);
54
48
  const wrapElement = useCallback(
@@ -11,7 +11,7 @@ import {
11
11
  } from "./NQJBHION.js";
12
12
  import {
13
13
  useStoreState
14
- } from "./OOWNFOTF.js";
14
+ } from "./QPTZ2G2N.js";
15
15
  import {
16
16
  useEvent,
17
17
  useMergeRefs
@@ -3,7 +3,7 @@ import {
3
3
  } from "./6I2PARRP.js";
4
4
  import {
5
5
  useCompositeItem
6
- } from "./DCG3EYDE.js";
6
+ } from "./7SIWUER2.js";
7
7
  import {
8
8
  createElement,
9
9
  createHook,
@@ -11,7 +11,7 @@ import {
11
11
  } from "./NQJBHION.js";
12
12
  import {
13
13
  useStoreState
14
- } from "./OOWNFOTF.js";
14
+ } from "./QPTZ2G2N.js";
15
15
  import {
16
16
  useEvent,
17
17
  useId,
@@ -9,13 +9,44 @@ import {
9
9
  } from "./PNRLI7OV.js";
10
10
 
11
11
  // src/utils/store.tsx
12
- import { useCallback, useMemo } from "react";
12
+ import * as React from "react";
13
13
  import { hasOwnProperty, identity } from "@ariakit/core/utils/misc";
14
+ import { batch, init, subscribe, sync } from "@ariakit/core/utils/store";
14
15
  import { flushSync } from "react-dom";
15
16
  import { useSyncExternalStore } from "use-sync-external-store/shim/index.js";
16
17
  var noopSubscribe = () => () => {
17
18
  };
19
+ var inFlushSyncContext = false;
20
+ function safeFlushSync(fn, canFlushSync = true) {
21
+ if (inFlushSyncContext || !canFlushSync) {
22
+ fn();
23
+ return;
24
+ }
25
+ inFlushSyncContext = true;
26
+ const originalError = console.error;
27
+ if (process.env.NODE_ENV !== "production") {
28
+ console.error = (msg) => {
29
+ if (msg.startsWith("Warning: flushSync"))
30
+ return;
31
+ originalError(msg);
32
+ };
33
+ }
34
+ try {
35
+ flushSync(fn);
36
+ } finally {
37
+ console.error = originalError;
38
+ inFlushSyncContext = false;
39
+ }
40
+ }
18
41
  function useStoreState(store, keyOrSelector = identity) {
42
+ const storeSubscribe = React.useCallback(
43
+ (callback) => {
44
+ if (!store)
45
+ return noopSubscribe();
46
+ return subscribe(store, null, callback);
47
+ },
48
+ [store]
49
+ );
19
50
  const getSnapshot = () => {
20
51
  if (!store)
21
52
  return;
@@ -30,11 +61,7 @@ function useStoreState(store, keyOrSelector = identity) {
30
61
  return;
31
62
  return state[key];
32
63
  };
33
- return useSyncExternalStore(
34
- (store == null ? void 0 : store.subscribe) || noopSubscribe,
35
- getSnapshot,
36
- getSnapshot
37
- );
64
+ return useSyncExternalStore(storeSubscribe, getSnapshot, getSnapshot);
38
65
  }
39
66
  function useStoreProps(store, props, key, setKey) {
40
67
  const value = hasOwnProperty(props, key) ? props[key] : void 0;
@@ -47,40 +74,36 @@ function useStoreProps(store, props, key, setKey) {
47
74
  queueMicrotask(() => {
48
75
  canFlushSync = true;
49
76
  });
50
- return store.sync(
51
- (state, prev) => {
52
- const { value: value2, setValue } = propsRef.current;
53
- if (!setValue)
54
- return;
55
- if (state[key] === prev[key])
56
- return;
57
- if (state[key] === value2)
58
- return;
59
- if (canFlushSync) {
60
- flushSync(() => setValue(state[key]));
61
- } else {
62
- setValue(state[key]);
63
- }
64
- },
65
- [key]
66
- );
77
+ return sync(store, [key], (state, prev) => {
78
+ const { value: value2, setValue } = propsRef.current;
79
+ if (!setValue)
80
+ return;
81
+ if (state[key] === prev[key])
82
+ return;
83
+ if (state[key] === value2)
84
+ return;
85
+ safeFlushSync(() => setValue(state[key]), canFlushSync);
86
+ });
67
87
  }, [store, key]);
68
88
  useSafeLayoutEffect(() => {
69
- return store.sync(() => {
89
+ return batch(store, [key], () => {
70
90
  if (value === void 0)
71
91
  return;
72
92
  store.setState(key, value);
73
- }, [key]);
93
+ });
74
94
  }, [store, key, value]);
75
95
  }
76
96
  function useStore(createStore) {
77
97
  const store = useLazyValue(createStore);
78
- useSafeLayoutEffect(() => store.init(), [store]);
79
- const useState = useCallback(
98
+ useSafeLayoutEffect(() => init(store), [store]);
99
+ const useState = React.useCallback(
80
100
  (keyOrSelector) => useStoreState(store, keyOrSelector),
81
101
  [store]
82
102
  );
83
- return useMemo(() => __spreadProps(__spreadValues({}, store), { useState }), [store, useState]);
103
+ return React.useMemo(
104
+ () => __spreadProps(__spreadValues({}, store), { useState }),
105
+ [store, useState]
106
+ );
84
107
  }
85
108
 
86
109
  export {
@@ -11,7 +11,7 @@ import {
11
11
  } from "./NQJBHION.js";
12
12
  import {
13
13
  useStoreState
14
- } from "./OOWNFOTF.js";
14
+ } from "./QPTZ2G2N.js";
15
15
  import {
16
16
  useEvent,
17
17
  useMergeRefs,