@tamagui/dismissable 2.7.7 → 3.0.0-beta.637.1

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 (53) hide show
  1. package/dist/cjs/Dismissable.cjs +282 -330
  2. package/dist/cjs/Dismissable.native.cjs +61 -0
  3. package/dist/cjs/Dismissable.native.js +33 -37
  4. package/dist/cjs/Dismissable.native.js.map +1 -1
  5. package/dist/cjs/DismissableProps.cjs +10 -11
  6. package/dist/cjs/DismissableProps.native.cjs +19 -0
  7. package/dist/cjs/DismissableProps.native.js +10 -10
  8. package/dist/cjs/DismissableProps.native.js.map +1 -1
  9. package/dist/cjs/index.cjs +10 -11
  10. package/dist/cjs/index.native.cjs +21 -0
  11. package/dist/cjs/index.native.js +10 -10
  12. package/dist/cjs/index.native.js.map +1 -1
  13. package/dist/esm/Dismissable.mjs +261 -301
  14. package/dist/esm/Dismissable.mjs.map +1 -1
  15. package/dist/esm/Dismissable.native.js +12 -9
  16. package/dist/esm/Dismissable.native.js.map +1 -1
  17. package/dist/esm/DismissableProps.mjs +0 -2
  18. package/dist/esm/DismissableProps.native.js +0 -2
  19. package/dist/esm/index.js +1 -2
  20. package/dist/esm/index.mjs +1 -2
  21. package/dist/esm/index.native.js +1 -2
  22. package/dist/jsx/Dismissable.mjs +261 -301
  23. package/dist/jsx/Dismissable.mjs.map +1 -1
  24. package/dist/jsx/Dismissable.native.cjs +61 -0
  25. package/dist/jsx/Dismissable.native.js +33 -37
  26. package/dist/jsx/Dismissable.native.js.map +1 -1
  27. package/dist/jsx/DismissableProps.mjs +0 -2
  28. package/dist/jsx/DismissableProps.native.cjs +19 -0
  29. package/dist/jsx/DismissableProps.native.js +10 -10
  30. package/dist/jsx/DismissableProps.native.js.map +1 -1
  31. package/dist/jsx/index.js +1 -2
  32. package/dist/jsx/index.mjs +1 -2
  33. package/dist/jsx/index.native.cjs +21 -0
  34. package/dist/jsx/index.native.js +10 -10
  35. package/dist/jsx/index.native.js.map +1 -1
  36. package/package.json +7 -7
  37. package/src/Dismissable.native.tsx +3 -2
  38. package/src/Dismissable.tsx +90 -92
  39. package/src/DismissableProps.tsx +31 -10
  40. package/types/Dismissable.d.ts +3 -9
  41. package/types/Dismissable.d.ts.map +1 -1
  42. package/types/Dismissable.native.d.ts +2 -2
  43. package/types/Dismissable.native.d.ts.map +1 -1
  44. package/types/DismissableProps.d.ts +22 -10
  45. package/types/DismissableProps.d.ts.map +1 -1
  46. package/dist/esm/DismissableProps.mjs.map +0 -1
  47. package/dist/esm/DismissableProps.native.js.map +0 -1
  48. package/dist/esm/index.js.map +0 -1
  49. package/dist/esm/index.mjs.map +0 -1
  50. package/dist/esm/index.native.js.map +0 -1
  51. package/dist/jsx/DismissableProps.mjs.map +0 -1
  52. package/dist/jsx/index.js.map +0 -1
  53. package/dist/jsx/index.mjs.map +0 -1
@@ -1,3 +1,4 @@
1
+
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -5,42 +6,35 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
5
6
  var __getProtoOf = Object.getPrototypeOf;
6
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
8
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
11
- });
9
+ for (var name in all) __defProp(target, name, {
10
+ get: all[name],
11
+ enumerable: true
12
+ });
12
13
  };
13
14
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
- get: () => from[key],
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
+ get: () => from[key],
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ return to;
21
22
  };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
- // If the importer is in node compatibility mode or this is not an ESM
24
- // file that has been converted to a CommonJS file using a Babel-
25
- // compatible transform (i.e. "__esModule" has not been set), then set
26
- // "default" to the CommonJS "module.exports" for node compatibility.
27
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
- value: mod,
29
- enumerable: true
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
30
26
  }) : target, mod));
31
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: true
33
- }), mod);
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
28
  var Dismissable_exports = {};
35
29
  __export(Dismissable_exports, {
36
- Dismissable: () => Dismissable,
37
- DismissableBranch: () => DismissableBranch,
38
- debugDismissableLayers: () => debugDismissableLayers,
39
- dispatchDiscreteCustomEvent: () => dispatchDiscreteCustomEvent,
40
- getDismissableLayerCount: () => getDismissableLayerCount,
41
- useDismissableLayersAbove: () => useDismissableLayersAbove,
42
- useHasDismissableLayers: () => useHasDismissableLayers,
43
- useIsInsideDismissable: () => useIsInsideDismissable
30
+ Dismissable: () => Dismissable,
31
+ DismissableBranch: () => DismissableBranch,
32
+ debugDismissableLayers: () => debugDismissableLayers,
33
+ dispatchDiscreteCustomEvent: () => dispatchDiscreteCustomEvent,
34
+ getDismissableLayerCount: () => getDismissableLayerCount,
35
+ useDismissableLayersAbove: () => useDismissableLayersAbove,
36
+ useHasDismissableLayers: () => useHasDismissableLayers,
37
+ useIsInsideDismissable: () => useIsInsideDismissable
44
38
  });
45
39
  module.exports = __toCommonJS(Dismissable_exports);
46
40
  var import_compose_refs = require("@tamagui/compose-refs");
@@ -51,333 +45,291 @@ var React = __toESM(require("react"), 1);
51
45
  var ReactDOM = __toESM(require("react-dom"), 1);
52
46
  var import_jsx_runtime = require("react/jsx-runtime");
53
47
  function dispatchDiscreteCustomEvent(target, event) {
54
- if (target) ReactDOM.flushSync(() => target.dispatchEvent(event));
48
+ if (target) ReactDOM.flushSync(() => target.dispatchEvent(event));
55
49
  }
56
50
  const DISMISSABLE_LAYER_NAME = "Dismissable";
57
51
  const CONTEXT_UPDATE = "dismissable.update";
58
- const POINTER_DOWN_OUTSIDE = "dismissable.pointerDownOutside";
59
- const FOCUS_OUTSIDE = "dismissable.focusOutside";
60
52
  let originalBodyPointerEvents;
61
- const globalLayers = /* @__PURE__ */new Set();
62
- const layerChangeListeners = /* @__PURE__ */new Set();
53
+ const globalLayers = /* @__PURE__ */ new Set();
54
+ const layerChangeListeners = /* @__PURE__ */ new Set();
63
55
  let layersWithPointerEventsDisabledCount = 0;
64
56
  function notifyLayerChange() {
65
- for (const listener of layerChangeListeners) {
66
- listener();
67
- }
57
+ for (const listener of layerChangeListeners) {
58
+ listener();
59
+ }
68
60
  }
69
61
  function getDismissableLayerCount() {
70
- return globalLayers.size;
62
+ return globalLayers.size;
71
63
  }
72
64
  function debugDismissableLayers() {
73
- const layers = Array.from(globalLayers);
74
- console.log("[Dismissable] Active layers:", layers.length, layers);
75
- return layers;
65
+ const layers = Array.from(globalLayers);
66
+ console.log("[Dismissable] Active layers:", layers.length, layers);
67
+ return layers;
76
68
  }
77
69
  function useHasDismissableLayers() {
78
- const [count, setCount] = React.useState(() => globalLayers.size);
79
- React.useEffect(() => {
80
- setCount(globalLayers.size);
81
- const update = () => setCount(globalLayers.size);
82
- layerChangeListeners.add(update);
83
- return () => {
84
- layerChangeListeners.delete(update);
85
- };
86
- }, []);
87
- return count > 0;
70
+ const [count, setCount] = React.useState(() => globalLayers.size);
71
+ React.useEffect(() => {
72
+ setCount(globalLayers.size);
73
+ const update = () => setCount(globalLayers.size);
74
+ layerChangeListeners.add(update);
75
+ return () => {
76
+ layerChangeListeners.delete(update);
77
+ };
78
+ }, []);
79
+ return count > 0;
88
80
  }
89
81
  const DismissableContext = React.createContext({
90
- layers: /* @__PURE__ */new Set(),
91
- layersWithOutsidePointerEventsDisabled: /* @__PURE__ */new Set(),
92
- branches: /* @__PURE__ */new Set()
82
+ layers: /* @__PURE__ */ new Set(),
83
+ layersWithOutsidePointerEventsDisabled: /* @__PURE__ */ new Set(),
84
+ branches: /* @__PURE__ */ new Set()
93
85
  });
94
86
  function useIsInsideDismissable(ref) {
95
- const context = React.useContext(DismissableContext);
96
- const [isInside, setIsInside] = React.useState(false);
97
- React.useEffect(() => {
98
- const check = () => {
99
- const el = ref.current;
100
- if (!el) {
101
- setIsInside(false);
102
- return;
103
- }
104
- for (const layer of context.layers) {
105
- if (layer.contains(el)) {
106
- setIsInside(true);
107
- return;
108
- }
109
- }
110
- setIsInside(false);
111
- };
112
- check();
113
- document.addEventListener(CONTEXT_UPDATE, check);
114
- return () => document.removeEventListener(CONTEXT_UPDATE, check);
115
- }, [context.layers, ref]);
116
- return isInside;
87
+ const context = React.useContext(DismissableContext);
88
+ const [isInside, setIsInside] = React.useState(false);
89
+ React.useEffect(() => {
90
+ const check = () => {
91
+ const el = ref.current;
92
+ if (!el) {
93
+ setIsInside(false);
94
+ return;
95
+ }
96
+ for (const layer of context.layers) {
97
+ if (layer.contains(el)) {
98
+ setIsInside(true);
99
+ return;
100
+ }
101
+ }
102
+ setIsInside(false);
103
+ };
104
+ check();
105
+ document.addEventListener(CONTEXT_UPDATE, check);
106
+ return () => document.removeEventListener(CONTEXT_UPDATE, check);
107
+ }, [context.layers, ref]);
108
+ return isInside;
117
109
  }
118
110
  function useDismissableLayersAbove(ref) {
119
- const context = React.useContext(DismissableContext);
120
- const [count, setCount] = React.useState(0);
121
- React.useEffect(() => {
122
- const check = () => {
123
- const el = ref.current;
124
- if (!el) {
125
- setCount(0);
126
- return;
127
- }
128
- let above = 0;
129
- for (const layer of context.layers) {
130
- if (layer.contains(el)) {
131
- above++;
132
- }
133
- }
134
- setCount(above);
135
- };
136
- check();
137
- document.addEventListener(CONTEXT_UPDATE, check);
138
- return () => document.removeEventListener(CONTEXT_UPDATE, check);
139
- }, [context.layers, ref]);
140
- return count;
111
+ const context = React.useContext(DismissableContext);
112
+ const [count, setCount] = React.useState(0);
113
+ React.useEffect(() => {
114
+ const check = () => {
115
+ const el = ref.current;
116
+ if (!el) {
117
+ setCount(0);
118
+ return;
119
+ }
120
+ let above = 0;
121
+ for (const layer of context.layers) {
122
+ if (layer.contains(el)) {
123
+ above++;
124
+ }
125
+ }
126
+ setCount(above);
127
+ };
128
+ check();
129
+ document.addEventListener(CONTEXT_UPDATE, check);
130
+ return () => document.removeEventListener(CONTEXT_UPDATE, check);
131
+ }, [context.layers, ref]);
132
+ return count;
141
133
  }
142
- const Dismissable = React.forwardRef((props, forwardedRef) => {
143
- const {
144
- disableOutsidePointerEvents = false,
145
- forceUnmount,
146
- onEscapeKeyDown,
147
- onPointerDownOutside,
148
- onFocusOutside,
149
- onInteractOutside,
150
- onDismiss,
151
- asChild,
152
- children,
153
- branches: branchesProp,
154
- ...layerProps
155
- } = props;
156
- const Comp = asChild ? import_core.Slot : import_core.View;
157
- const context = React.useContext(DismissableContext);
158
- const [node, setNode] = React.useState(null);
159
- const [, force] = React.useState({});
160
- const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, node2 => setNode(node2));
161
- const layers = Array.from(context.layers);
162
- const [highestLayerWithOutsidePointerEventsDisabled] = [...context.layersWithOutsidePointerEventsDisabled].slice(-1);
163
- const highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled);
164
- const index = node ? layers.indexOf(node) : -1;
165
- const isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0;
166
- const isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex;
167
- const pointerDownOutside = usePointerDownOutside(event => {
168
- const target = event.target;
169
- const branches = branchesProp || context.branches;
170
- const isPointerDownOnBranch = [...branches].some(branch => branch.contains(target));
171
- if (!isPointerEventsEnabled || isPointerDownOnBranch) return;
172
- onPointerDownOutside?.(event);
173
- onInteractOutside?.(event);
174
- if (!event.defaultPrevented) onDismiss?.();
175
- });
176
- const focusOutside = useFocusOutside(event => {
177
- const target = event.target;
178
- const branches = branchesProp || context.branches;
179
- const isFocusInBranch = [...branches].some(branch => branch.contains(target));
180
- if (isFocusInBranch) return;
181
- onFocusOutside?.(event);
182
- onInteractOutside?.(event);
183
- if (!event.defaultPrevented) onDismiss?.();
184
- });
185
- const forceUnmountRef = React.useRef(forceUnmount);
186
- React.useEffect(() => {
187
- forceUnmountRef.current = forceUnmount;
188
- }, [forceUnmount]);
189
- (0, import_use_escape_keydown.useEscapeKeydown)(event => {
190
- if (forceUnmountRef.current) return;
191
- const currentLayers = Array.from(context.layers);
192
- const currentIndex = node ? currentLayers.indexOf(node) : -1;
193
- const isHighestLayer = currentIndex === currentLayers.length - 1;
194
- if (!isHighestLayer) return;
195
- onEscapeKeyDown?.(event);
196
- if (!event.defaultPrevented && onDismiss) {
197
- event.preventDefault();
198
- onDismiss();
199
- }
200
- });
201
- React.useEffect(() => {
202
- if (!node) return;
203
- if (forceUnmount) return;
204
- if (disableOutsidePointerEvents) {
205
- if (context.layersWithOutsidePointerEventsDisabled.size === 0) {
206
- originalBodyPointerEvents = document.body.style.pointerEvents;
207
- document.body.style.pointerEvents = "none";
208
- }
209
- context.layersWithOutsidePointerEventsDisabled.add(node);
210
- layersWithPointerEventsDisabledCount++;
211
- }
212
- context.layers.add(node);
213
- globalLayers.add(node);
214
- if (disableOutsidePointerEvents || layersWithPointerEventsDisabledCount > 0) {
215
- dispatchUpdate();
216
- }
217
- notifyLayerChange();
218
- return () => {
219
- if (disableOutsidePointerEvents) {
220
- if (context.layersWithOutsidePointerEventsDisabled.size === 1) {
221
- document.body.style.pointerEvents = originalBodyPointerEvents;
222
- }
223
- }
224
- };
225
- }, [node, disableOutsidePointerEvents, forceUnmount, context]);
226
- React.useEffect(() => {
227
- if (forceUnmount) return;
228
- return () => {
229
- if (!node) return;
230
- const hadPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.has(node);
231
- context.layers.delete(node);
232
- context.layersWithOutsidePointerEventsDisabled.delete(node);
233
- globalLayers.delete(node);
234
- if (layersWithPointerEventsDisabledCount > 0) {
235
- dispatchUpdate();
236
- }
237
- notifyLayerChange();
238
- if (hadPointerEventsDisabled) {
239
- layersWithPointerEventsDisabledCount--;
240
- }
241
- };
242
- }, [node, context, forceUnmount]);
243
- React.useEffect(() => {
244
- const handleUpdate = () => {
245
- if (layersWithPointerEventsDisabledCount > 0) {
246
- force({});
247
- }
248
- };
249
- document.addEventListener(CONTEXT_UPDATE, handleUpdate);
250
- return () => document.removeEventListener(CONTEXT_UPDATE, handleUpdate);
251
- }, []);
252
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Comp, {
253
- ...layerProps,
254
- ref: composedRefs,
255
- ...(!asChild && {
256
- display: "contents"
257
- }),
258
- pointerEvents: isBodyPointerEventsDisabled ? isPointerEventsEnabled ? "auto" : "none" : void 0,
259
- onFocusCapture: (0, import_core.composeEventHandlers)(props.onFocusCapture, focusOutside.onFocusCapture),
260
- onBlurCapture: (0, import_core.composeEventHandlers)(props.onBlurCapture, focusOutside.onBlurCapture),
261
- onPointerDownCapture: (0, import_core.composeEventHandlers)(props.onPointerDownCapture, pointerDownOutside.onPointerDownCapture),
262
- children
263
- });
134
+ const Dismissable = (0, import_core.createRefComponent)((props, forwardedRef) => {
135
+ const { disableOutsidePointerEvents = false, forceUnmount, onEscapeKeyDown, onPointerDownOutside, onFocusOutside, onInteractOutside, onDismiss, asChild, children, branches: branchesProp, ...layerProps } = props;
136
+ const Comp = asChild ? import_core.Slot : import_core.View;
137
+ const context = React.useContext(DismissableContext);
138
+ const [node, setNode] = React.useState(null);
139
+ const [, force] = React.useState({});
140
+ const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, (node2) => setNode(node2));
141
+ const layers = Array.from(context.layers);
142
+ const [highestLayerWithOutsidePointerEventsDisabled] = [...context.layersWithOutsidePointerEventsDisabled].slice(-1);
143
+ const highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled);
144
+ const index = node ? layers.indexOf(node) : -1;
145
+ const isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0;
146
+ const isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex;
147
+ const pointerDownOutside = usePointerDownOutside((event) => {
148
+ const target = event.target;
149
+ const branches = branchesProp || context.branches;
150
+ const isPointerDownOnBranch = [...branches].some((branch) => branch.contains(target));
151
+ if (!isPointerEventsEnabled || isPointerDownOnBranch) return;
152
+ const details = (0, import_core.createChangeEventDetails)("outside-press", event, event.target, { interaction: "pointer" });
153
+ onPointerDownOutside?.(details);
154
+ onInteractOutside?.(details);
155
+ if (!details.isCanceled) onDismiss?.(details);
156
+ });
157
+ const focusOutside = useFocusOutside((event) => {
158
+ const target = event.target;
159
+ const branches = branchesProp || context.branches;
160
+ const isFocusInBranch = [...branches].some((branch) => branch.contains(target));
161
+ if (isFocusInBranch) return;
162
+ if (node && target.contains(node)) return;
163
+ const details = (0, import_core.createChangeEventDetails)("focus-out", event, event.target, { interaction: "focus" });
164
+ onFocusOutside?.(details);
165
+ onInteractOutside?.(details);
166
+ if (!details.isCanceled) onDismiss?.(details);
167
+ });
168
+ const forceUnmountRef = React.useRef(forceUnmount);
169
+ React.useEffect(() => {
170
+ forceUnmountRef.current = forceUnmount;
171
+ }, [forceUnmount]);
172
+ (0, import_use_escape_keydown.useEscapeKeydown)((event) => {
173
+ if (event.defaultPrevented) return;
174
+ if (forceUnmountRef.current) return;
175
+ const currentLayers = Array.from(context.layers);
176
+ const currentIndex = node ? currentLayers.indexOf(node) : -1;
177
+ const isHighestLayer = currentIndex === currentLayers.length - 1;
178
+ if (!isHighestLayer) return;
179
+ const details = (0, import_core.createChangeEventDetails)("escape-key", event, event.target);
180
+ onEscapeKeyDown?.(details);
181
+ if (!details.isCanceled && onDismiss) {
182
+ event.preventDefault();
183
+ onDismiss(details);
184
+ }
185
+ });
186
+ React.useEffect(() => {
187
+ if (!node) return;
188
+ if (forceUnmount) return;
189
+ context.layers.add(node);
190
+ globalLayers.add(node);
191
+ dispatchUpdate();
192
+ notifyLayerChange();
193
+ return () => {
194
+ context.layers.delete(node);
195
+ globalLayers.delete(node);
196
+ dispatchUpdate();
197
+ notifyLayerChange();
198
+ };
199
+ }, [
200
+ node,
201
+ forceUnmount,
202
+ context
203
+ ]);
204
+ React.useEffect(() => {
205
+ if (!node) return;
206
+ if (forceUnmount) return;
207
+ if (!disableOutsidePointerEvents) return;
208
+ if (context.layersWithOutsidePointerEventsDisabled.size === 0) {
209
+ originalBodyPointerEvents = document.body.style.pointerEvents;
210
+ document.body.style.pointerEvents = "none";
211
+ }
212
+ context.layersWithOutsidePointerEventsDisabled.add(node);
213
+ layersWithPointerEventsDisabledCount++;
214
+ dispatchUpdate();
215
+ notifyLayerChange();
216
+ return () => {
217
+ context.layersWithOutsidePointerEventsDisabled.delete(node);
218
+ if (context.layersWithOutsidePointerEventsDisabled.size === 0) {
219
+ document.body.style.pointerEvents = originalBodyPointerEvents;
220
+ }
221
+ dispatchUpdate();
222
+ notifyLayerChange();
223
+ layersWithPointerEventsDisabledCount--;
224
+ };
225
+ }, [
226
+ node,
227
+ disableOutsidePointerEvents,
228
+ forceUnmount,
229
+ context
230
+ ]);
231
+ React.useEffect(() => {
232
+ const handleUpdate = () => {
233
+ if (layersWithPointerEventsDisabledCount > 0) {
234
+ force({});
235
+ }
236
+ };
237
+ document.addEventListener(CONTEXT_UPDATE, handleUpdate);
238
+ return () => document.removeEventListener(CONTEXT_UPDATE, handleUpdate);
239
+ }, []);
240
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Comp, {
241
+ ...layerProps,
242
+ ref: composedRefs,
243
+ ...!asChild && { display: "contents" },
244
+ pointerEvents: isBodyPointerEventsDisabled ? isPointerEventsEnabled ? "auto" : "none" : void 0,
245
+ onFocusCapture: (0, import_core.composeEventHandlers)(props.onFocusCapture, focusOutside.onFocusCapture),
246
+ onBlurCapture: (0, import_core.composeEventHandlers)(props.onBlurCapture, focusOutside.onBlurCapture),
247
+ onPointerDownCapture: (0, import_core.composeEventHandlers)(props.onPointerDownCapture, pointerDownOutside.onPointerDownCapture),
248
+ children
249
+ });
264
250
  });
265
251
  Dismissable.displayName = DISMISSABLE_LAYER_NAME;
266
252
  const BRANCH_NAME = "DismissableBranch";
267
- const DismissableBranch = React.forwardRef((props, forwardedRef) => {
268
- const {
269
- branches: branchesProp,
270
- ...rest
271
- } = props;
272
- const context = React.useContext(DismissableContext);
273
- const ref = React.useRef(null);
274
- const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref);
275
- React.useEffect(() => {
276
- const node = ref.current;
277
- if (!(node instanceof HTMLElement)) return;
278
- const branches = branchesProp || context.branches;
279
- if (node && branches) {
280
- branches.add(node);
281
- return () => {
282
- branches.delete(node);
283
- };
284
- }
285
- }, [branchesProp, context.branches]);
286
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
287
- asChild: "except-style",
288
- ...rest,
289
- ref: composedRefs
290
- });
253
+ const DismissableBranch = (0, import_core.createRefComponent)((props, forwardedRef) => {
254
+ const { branches: branchesProp, ...rest } = props;
255
+ const context = React.useContext(DismissableContext);
256
+ const ref = React.useRef(null);
257
+ const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref);
258
+ React.useEffect(() => {
259
+ const node = ref.current;
260
+ if (!(node instanceof HTMLElement)) return;
261
+ const branches = branchesProp || context.branches;
262
+ if (node && branches) {
263
+ branches.add(node);
264
+ return () => {
265
+ branches.delete(node);
266
+ };
267
+ }
268
+ }, [branchesProp, context.branches]);
269
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.View, {
270
+ asChild: "except-style",
271
+ ...rest,
272
+ ref: composedRefs
273
+ });
291
274
  });
292
275
  DismissableBranch.displayName = BRANCH_NAME;
293
276
  function usePointerDownOutside(onPointerDownOutside) {
294
- const handlePointerDownOutside = (0, import_use_event.useEvent)(onPointerDownOutside);
295
- const isPointerInsideReactTreeRef = React.useRef(false);
296
- const handleClickRef = React.useRef(() => {});
297
- React.useEffect(() => {
298
- const handlePointerDown = event => {
299
- if (event.target && !isPointerInsideReactTreeRef.current) {
300
- let handleAndDispatchPointerDownOutsideEvent = function () {
301
- handleAndDispatchCustomEvent(POINTER_DOWN_OUTSIDE, handlePointerDownOutside, eventDetail, {
302
- discrete: true
303
- });
304
- };
305
- const eventDetail = {
306
- originalEvent: event
307
- };
308
- if (event.pointerType === "touch") {
309
- document.removeEventListener("click", handleClickRef.current);
310
- handleClickRef.current = handleAndDispatchPointerDownOutsideEvent;
311
- document.addEventListener("click", handleClickRef.current, {
312
- once: true
313
- });
314
- } else {
315
- handleAndDispatchPointerDownOutsideEvent();
316
- }
317
- }
318
- isPointerInsideReactTreeRef.current = false;
319
- };
320
- const timerId = setTimeout(() => {
321
- document.addEventListener("pointerdown", handlePointerDown);
322
- }, 0);
323
- return () => {
324
- window.clearTimeout(timerId);
325
- document.removeEventListener("pointerdown", handlePointerDown);
326
- document.removeEventListener("click", handleClickRef.current);
327
- };
328
- }, [handlePointerDownOutside]);
329
- return {
330
- // ensures we check React component tree (not just DOM tree)
331
- onPointerDownCapture: () => {
332
- isPointerInsideReactTreeRef.current = true;
333
- }
334
- };
277
+ const handlePointerDownOutside = (0, import_use_event.useEvent)(onPointerDownOutside);
278
+ const isPointerInsideReactTreeRef = React.useRef(false);
279
+ const handleClickRef = React.useRef(() => {});
280
+ React.useEffect(() => {
281
+ const handlePointerDown = (event) => {
282
+ if (event.target && !isPointerInsideReactTreeRef.current) {
283
+ let handlePointerDownOutsideEvent = function() {
284
+ if (handlePointerDownOutside) {
285
+ ReactDOM.flushSync(() => handlePointerDownOutside(event));
286
+ }
287
+ };
288
+ if (event.pointerType === "touch") {
289
+ document.removeEventListener("click", handleClickRef.current);
290
+ handleClickRef.current = handlePointerDownOutsideEvent;
291
+ document.addEventListener("click", handleClickRef.current, { once: true });
292
+ } else {
293
+ handlePointerDownOutsideEvent();
294
+ }
295
+ }
296
+ isPointerInsideReactTreeRef.current = false;
297
+ };
298
+ const timerId = setTimeout(() => {
299
+ document.addEventListener("pointerdown", handlePointerDown);
300
+ }, 0);
301
+ return () => {
302
+ window.clearTimeout(timerId);
303
+ document.removeEventListener("pointerdown", handlePointerDown);
304
+ document.removeEventListener("click", handleClickRef.current);
305
+ };
306
+ }, [handlePointerDownOutside]);
307
+ return { onPointerDownCapture: () => {
308
+ isPointerInsideReactTreeRef.current = true;
309
+ } };
335
310
  }
336
311
  function useFocusOutside(onFocusOutside) {
337
- const handleFocusOutside = (0, import_use_event.useEvent)(onFocusOutside);
338
- const isFocusInsideReactTreeRef = React.useRef(false);
339
- React.useEffect(() => {
340
- const handleFocus = event => {
341
- if (event.target && !isFocusInsideReactTreeRef.current) {
342
- const eventDetail = {
343
- originalEvent: event
344
- };
345
- handleAndDispatchCustomEvent(FOCUS_OUTSIDE, handleFocusOutside, eventDetail, {
346
- discrete: false
347
- });
348
- }
349
- };
350
- document.addEventListener("focusin", handleFocus);
351
- return () => document.removeEventListener("focusin", handleFocus);
352
- }, [handleFocusOutside]);
353
- return {
354
- onFocusCapture: () => {
355
- isFocusInsideReactTreeRef.current = true;
356
- },
357
- onBlurCapture: () => {
358
- isFocusInsideReactTreeRef.current = false;
359
- }
360
- };
312
+ const handleFocusOutside = (0, import_use_event.useEvent)(onFocusOutside);
313
+ const isFocusInsideReactTreeRef = React.useRef(false);
314
+ React.useEffect(() => {
315
+ const handleFocus = (event) => {
316
+ if (event.target && !isFocusInsideReactTreeRef.current) {
317
+ handleFocusOutside?.(event);
318
+ }
319
+ };
320
+ document.addEventListener("focusin", handleFocus);
321
+ return () => document.removeEventListener("focusin", handleFocus);
322
+ }, [handleFocusOutside]);
323
+ return {
324
+ onFocusCapture: () => {
325
+ isFocusInsideReactTreeRef.current = true;
326
+ },
327
+ onBlurCapture: () => {
328
+ isFocusInsideReactTreeRef.current = false;
329
+ }
330
+ };
361
331
  }
362
332
  function dispatchUpdate() {
363
- const event = new CustomEvent(CONTEXT_UPDATE);
364
- document.dispatchEvent(event);
333
+ const event = new CustomEvent(CONTEXT_UPDATE);
334
+ document.dispatchEvent(event);
365
335
  }
366
- function handleAndDispatchCustomEvent(name, handler, detail, {
367
- discrete
368
- }) {
369
- const target = detail.originalEvent.target;
370
- const event = new CustomEvent(name, {
371
- bubbles: false,
372
- cancelable: true,
373
- detail
374
- });
375
- if (handler) target.addEventListener(name, handler, {
376
- once: true
377
- });
378
- if (discrete) {
379
- dispatchDiscreteCustomEvent(target, event);
380
- } else {
381
- target.dispatchEvent(event);
382
- }
383
- }