@tamagui/dismissable 2.0.0-rc.4 → 2.0.0-rc.40

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 (47) hide show
  1. package/dist/cjs/Dismissable.cjs +331 -158
  2. package/dist/cjs/Dismissable.native.js +46 -28
  3. package/dist/cjs/Dismissable.native.js.map +1 -1
  4. package/dist/cjs/DismissableProps.cjs +7 -5
  5. package/dist/cjs/DismissableProps.native.js +7 -5
  6. package/dist/cjs/DismissableProps.native.js.map +1 -1
  7. package/dist/cjs/index.cjs +7 -5
  8. package/dist/cjs/index.native.js +7 -5
  9. package/dist/cjs/index.native.js.map +1 -1
  10. package/dist/esm/Dismissable.mjs +295 -129
  11. package/dist/esm/Dismissable.mjs.map +1 -1
  12. package/dist/esm/Dismissable.native.js +18 -6
  13. package/dist/esm/Dismissable.native.js.map +1 -1
  14. package/dist/esm/index.js +1 -1
  15. package/dist/esm/index.js.map +1 -6
  16. package/dist/jsx/Dismissable.mjs +295 -129
  17. package/dist/jsx/Dismissable.mjs.map +1 -1
  18. package/dist/jsx/Dismissable.native.js +46 -28
  19. package/dist/jsx/Dismissable.native.js.map +1 -1
  20. package/dist/jsx/DismissableProps.native.js +7 -5
  21. package/dist/jsx/index.js +1 -1
  22. package/dist/jsx/index.js.map +1 -6
  23. package/dist/jsx/index.native.js +7 -5
  24. package/package.json +10 -13
  25. package/src/Dismissable.native.tsx +21 -1
  26. package/src/Dismissable.tsx +187 -33
  27. package/src/DismissableProps.tsx +10 -0
  28. package/types/Dismissable.d.ts +28 -2
  29. package/types/Dismissable.d.ts.map +1 -1
  30. package/types/Dismissable.native.d.ts +4 -0
  31. package/types/Dismissable.native.d.ts.map +1 -1
  32. package/types/DismissableProps.d.ts +10 -0
  33. package/types/DismissableProps.d.ts.map +1 -1
  34. package/dist/cjs/Dismissable.js +0 -179
  35. package/dist/cjs/Dismissable.js.map +0 -6
  36. package/dist/cjs/DismissableProps.js +0 -14
  37. package/dist/cjs/DismissableProps.js.map +0 -6
  38. package/dist/cjs/index.js +0 -15
  39. package/dist/cjs/index.js.map +0 -6
  40. package/dist/esm/Dismissable.js +0 -161
  41. package/dist/esm/Dismissable.js.map +0 -6
  42. package/dist/esm/DismissableProps.js +0 -1
  43. package/dist/esm/DismissableProps.js.map +0 -6
  44. package/dist/jsx/Dismissable.js +0 -161
  45. package/dist/jsx/Dismissable.js.map +0 -6
  46. package/dist/jsx/DismissableProps.js +0 -1
  47. package/dist/jsx/DismissableProps.js.map +0 -6
@@ -2,192 +2,360 @@ var __create = Object.create;
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf,
6
- __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: !0
11
- });
12
- },
13
- __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ 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, {
15
16
  get: () => from[key],
16
17
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
18
  });
18
- return to;
19
- };
19
+ }
20
+ return to;
21
+ };
20
22
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
- value: mod,
27
- enumerable: !0
28
- }) : target, mod)),
29
- __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
30
- value: !0
31
- }), mod);
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
30
+ }) : target, mod));
31
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
+ value: true
33
+ }), mod);
32
34
  var Dismissable_exports = {};
33
35
  __export(Dismissable_exports, {
34
36
  Dismissable: () => Dismissable,
35
37
  DismissableBranch: () => DismissableBranch,
36
- dispatchDiscreteCustomEvent: () => dispatchDiscreteCustomEvent
38
+ debugDismissableLayers: () => debugDismissableLayers,
39
+ dispatchDiscreteCustomEvent: () => dispatchDiscreteCustomEvent,
40
+ getDismissableLayerCount: () => getDismissableLayerCount,
41
+ useDismissableLayersAbove: () => useDismissableLayersAbove,
42
+ useHasDismissableLayers: () => useHasDismissableLayers,
43
+ useIsInsideDismissable: () => useIsInsideDismissable
37
44
  });
38
45
  module.exports = __toCommonJS(Dismissable_exports);
39
- var import_compose_refs = require("@tamagui/compose-refs"),
40
- import_core = require("@tamagui/core"),
41
- import_use_escape_keydown = require("@tamagui/use-escape-keydown"),
42
- import_use_event = require("@tamagui/use-event"),
43
- React = __toESM(require("react"), 1),
44
- ReactDOM = __toESM(require("react-dom"), 1),
45
- import_jsx_runtime = require("react/jsx-runtime");
46
+ var import_compose_refs = require("@tamagui/compose-refs");
47
+ var import_core = require("@tamagui/core");
48
+ var import_use_escape_keydown = require("@tamagui/use-escape-keydown");
49
+ var import_use_event = require("@tamagui/use-event");
50
+ var React = __toESM(require("react"), 1);
51
+ var ReactDOM = __toESM(require("react-dom"), 1);
52
+ var import_jsx_runtime = require("react/jsx-runtime");
46
53
  function dispatchDiscreteCustomEvent(target, event) {
47
- target && ReactDOM.flushSync(() => target.dispatchEvent(event));
54
+ if (target) ReactDOM.flushSync(() => target.dispatchEvent(event));
48
55
  }
49
- const DISMISSABLE_LAYER_NAME = "Dismissable",
50
- CONTEXT_UPDATE = "dismissable.update",
51
- POINTER_DOWN_OUTSIDE = "dismissable.pointerDownOutside",
52
- FOCUS_OUTSIDE = "dismissable.focusOutside";
56
+ const DISMISSABLE_LAYER_NAME = "Dismissable";
57
+ const CONTEXT_UPDATE = "dismissable.update";
58
+ const POINTER_DOWN_OUTSIDE = "dismissable.pointerDownOutside";
59
+ const FOCUS_OUTSIDE = "dismissable.focusOutside";
53
60
  let originalBodyPointerEvents;
61
+ const globalLayers = /* @__PURE__ */new Set();
62
+ const layerChangeListeners = /* @__PURE__ */new Set();
63
+ let layersWithPointerEventsDisabledCount = 0;
64
+ function notifyLayerChange() {
65
+ for (const listener of layerChangeListeners) {
66
+ listener();
67
+ }
68
+ }
69
+ function getDismissableLayerCount() {
70
+ return globalLayers.size;
71
+ }
72
+ function debugDismissableLayers() {
73
+ const layers = Array.from(globalLayers);
74
+ console.log("[Dismissable] Active layers:", layers.length, layers);
75
+ return layers;
76
+ }
77
+ 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;
88
+ }
54
89
  const DismissableContext = React.createContext({
55
- layers: /* @__PURE__ */new Set(),
56
- layersWithOutsidePointerEventsDisabled: /* @__PURE__ */new Set(),
57
- branches: /* @__PURE__ */new Set()
58
- }),
59
- Dismissable = React.forwardRef((props, forwardedRef) => {
60
- const {
61
- disableOutsidePointerEvents = !1,
62
- forceUnmount,
63
- onEscapeKeyDown,
64
- onPointerDownOutside,
65
- onFocusOutside,
66
- onInteractOutside,
67
- onDismiss,
68
- asChild,
69
- children,
70
- ...layerProps
71
- } = props,
72
- Comp = asChild ? import_core.Slot : import_core.View,
73
- context = React.useContext(DismissableContext),
74
- [node, setNode] = React.useState(null),
75
- [, force] = React.useState({}),
76
- composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, node2 => setNode(node2)),
77
- layers = Array.from(context.layers),
78
- [highestLayerWithOutsidePointerEventsDisabled] = [...context.layersWithOutsidePointerEventsDisabled].slice(-1),
79
- highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled),
80
- index = node ? layers.indexOf(node) : -1,
81
- isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0,
82
- isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex,
83
- pointerDownOutside = usePointerDownOutside(event => {
84
- const target = event.target,
85
- isPointerDownOnBranch = [...context.branches].some(branch => branch.contains(target));
86
- !isPointerEventsEnabled || isPointerDownOnBranch || (onPointerDownOutside?.(event), onInteractOutside?.(event), event.defaultPrevented || onDismiss?.());
87
- }),
88
- focusOutside = useFocusOutside(event => {
89
- const target = event.target;
90
- [...context.branches].some(branch => branch.contains(target)) || (onFocusOutside?.(event), onInteractOutside?.(event), event.defaultPrevented || onDismiss?.());
91
- });
92
- return (0, import_use_escape_keydown.useEscapeKeydown)(event => {
93
- const currentLayers = Array.from(context.layers);
94
- (node ? currentLayers.indexOf(node) : -1) === currentLayers.length - 1 && (onEscapeKeyDown?.(event), !event.defaultPrevented && onDismiss && (event.preventDefault(), onDismiss()));
95
- }), React.useEffect(() => {
96
- if (node) return disableOutsidePointerEvents && (context.layersWithOutsidePointerEventsDisabled.size === 0 && (originalBodyPointerEvents = document.body.style.pointerEvents, document.body.style.pointerEvents = "none"), context.layersWithOutsidePointerEventsDisabled.add(node)), context.layers.add(node), dispatchUpdate(), () => {
97
- disableOutsidePointerEvents && context.layersWithOutsidePointerEventsDisabled.size === 1 && (document.body.style.pointerEvents = originalBodyPointerEvents);
98
- };
99
- }, [node, disableOutsidePointerEvents, context]), React.useEffect(() => {
100
- if (!forceUnmount) return () => {
101
- node && (context.layers.delete(node), context.layersWithOutsidePointerEventsDisabled.delete(node), dispatchUpdate());
102
- };
103
- }, [node, context, forceUnmount]), React.useEffect(() => {
104
- const handleUpdate = () => {
90
+ layers: /* @__PURE__ */new Set(),
91
+ layersWithOutsidePointerEventsDisabled: /* @__PURE__ */new Set(),
92
+ branches: /* @__PURE__ */new Set()
93
+ });
94
+ 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;
117
+ }
118
+ 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;
141
+ }
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) {
105
246
  force({});
106
- };
107
- return document.addEventListener(CONTEXT_UPDATE, handleUpdate), () => document.removeEventListener(CONTEXT_UPDATE, handleUpdate);
108
- }, []), /* @__PURE__ */(0, import_jsx_runtime.jsx)(Comp, {
109
- ...layerProps,
110
- ref: composedRefs,
111
- display: "contents",
112
- pointerEvents: isBodyPointerEventsDisabled ? isPointerEventsEnabled ? "auto" : "none" : void 0,
113
- onFocusCapture: (0, import_core.composeEventHandlers)(props.onFocusCapture, focusOutside.onFocusCapture),
114
- onBlurCapture: (0, import_core.composeEventHandlers)(props.onBlurCapture, focusOutside.onBlurCapture),
115
- onPointerDownCapture: (0, import_core.composeEventHandlers)(props.onPointerDownCapture, pointerDownOutside.onPointerDownCapture),
116
- children
117
- });
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
118
263
  });
264
+ });
119
265
  Dismissable.displayName = DISMISSABLE_LAYER_NAME;
120
- const BRANCH_NAME = "DismissableBranch",
121
- DismissableBranch = React.forwardRef((props, forwardedRef) => {
122
- const context = React.useContext(DismissableContext),
123
- ref = React.useRef(null),
124
- composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref);
125
- return React.useEffect(() => {
126
- const node = ref.current;
127
- if (node) return context.branches.add(node), () => {
128
- context.branches.delete(node);
266
+ 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);
129
283
  };
130
- }, [context.branches]), /* @__PURE__ */(0, import_jsx_runtime.jsx)("div", {
131
- style: {
132
- display: "contents"
133
- },
134
- ...props,
135
- ref: composedRefs
136
- });
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
137
290
  });
291
+ });
138
292
  DismissableBranch.displayName = BRANCH_NAME;
139
293
  function usePointerDownOutside(onPointerDownOutside) {
140
- const handlePointerDownOutside = (0, import_use_event.useEvent)(onPointerDownOutside),
141
- isPointerInsideReactTreeRef = React.useRef(!1),
142
- handleClickRef = React.useRef(() => {});
143
- return React.useEffect(() => {
294
+ const handlePointerDownOutside = (0, import_use_event.useEvent)(onPointerDownOutside);
295
+ const isPointerInsideReactTreeRef = React.useRef(false);
296
+ const handleClickRef = React.useRef(() => {});
297
+ React.useEffect(() => {
144
298
  const handlePointerDown = event => {
145
- if (event.target && !isPointerInsideReactTreeRef.current) {
146
- let handleAndDispatchPointerDownOutsideEvent = function () {
147
- handleAndDispatchCustomEvent(POINTER_DOWN_OUTSIDE, handlePointerDownOutside, eventDetail, {
148
- discrete: !0
149
- });
150
- };
151
- const eventDetail = {
152
- originalEvent: event
153
- };
154
- event.pointerType === "touch" ? (document.removeEventListener("click", handleClickRef.current), handleClickRef.current = handleAndDispatchPointerDownOutsideEvent, document.addEventListener("click", handleClickRef.current, {
155
- once: !0
156
- })) : handleAndDispatchPointerDownOutsideEvent();
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();
157
316
  }
158
- isPointerInsideReactTreeRef.current = !1;
159
- },
160
- timerId = setTimeout(() => {
161
- document.addEventListener("pointerdown", handlePointerDown);
162
- }, 0);
317
+ }
318
+ isPointerInsideReactTreeRef.current = false;
319
+ };
320
+ const timerId = setTimeout(() => {
321
+ document.addEventListener("pointerdown", handlePointerDown);
322
+ }, 0);
163
323
  return () => {
164
- window.clearTimeout(timerId), document.removeEventListener("pointerdown", handlePointerDown), document.removeEventListener("click", handleClickRef.current);
324
+ window.clearTimeout(timerId);
325
+ document.removeEventListener("pointerdown", handlePointerDown);
326
+ document.removeEventListener("click", handleClickRef.current);
165
327
  };
166
- }, [handlePointerDownOutside]), {
328
+ }, [handlePointerDownOutside]);
329
+ return {
167
330
  // ensures we check React component tree (not just DOM tree)
168
331
  onPointerDownCapture: () => {
169
- isPointerInsideReactTreeRef.current = !0;
332
+ isPointerInsideReactTreeRef.current = true;
170
333
  }
171
334
  };
172
335
  }
173
336
  function useFocusOutside(onFocusOutside) {
174
- const handleFocusOutside = (0, import_use_event.useEvent)(onFocusOutside),
175
- isFocusInsideReactTreeRef = React.useRef(!1);
176
- return React.useEffect(() => {
337
+ const handleFocusOutside = (0, import_use_event.useEvent)(onFocusOutside);
338
+ const isFocusInsideReactTreeRef = React.useRef(false);
339
+ React.useEffect(() => {
177
340
  const handleFocus = event => {
178
- event.target && !isFocusInsideReactTreeRef.current && handleAndDispatchCustomEvent(FOCUS_OUTSIDE, handleFocusOutside, {
179
- originalEvent: event
180
- }, {
181
- discrete: !1
182
- });
341
+ if (event.target && !isFocusInsideReactTreeRef.current) {
342
+ const eventDetail = {
343
+ originalEvent: event
344
+ };
345
+ handleAndDispatchCustomEvent(FOCUS_OUTSIDE, handleFocusOutside, eventDetail, {
346
+ discrete: false
347
+ });
348
+ }
183
349
  };
184
- return document.addEventListener("focusin", handleFocus), () => document.removeEventListener("focusin", handleFocus);
185
- }, [handleFocusOutside]), {
350
+ document.addEventListener("focusin", handleFocus);
351
+ return () => document.removeEventListener("focusin", handleFocus);
352
+ }, [handleFocusOutside]);
353
+ return {
186
354
  onFocusCapture: () => {
187
- isFocusInsideReactTreeRef.current = !0;
355
+ isFocusInsideReactTreeRef.current = true;
188
356
  },
189
357
  onBlurCapture: () => {
190
- isFocusInsideReactTreeRef.current = !1;
358
+ isFocusInsideReactTreeRef.current = false;
191
359
  }
192
360
  };
193
361
  }
@@ -198,13 +366,18 @@ function dispatchUpdate() {
198
366
  function handleAndDispatchCustomEvent(name, handler, detail, {
199
367
  discrete
200
368
  }) {
201
- const target = detail.originalEvent.target,
202
- event = new CustomEvent(name, {
203
- bubbles: !1,
204
- cancelable: !0,
205
- detail
206
- });
207
- handler && target.addEventListener(name, handler, {
208
- once: !0
209
- }), discrete ? dispatchDiscreteCustomEvent(target, event) : target.dispatchEvent(event);
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
+ }
210
383
  }
@@ -4,46 +4,64 @@ var __create = Object.create;
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf,
8
- __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var __export = (target, all) => {
10
- for (var name in all) __defProp(target, name, {
11
- get: all[name],
12
- enumerable: !0
13
- });
14
- },
15
- __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: true
13
+ });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
18
  get: () => from[key],
18
19
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
20
  });
20
- return to;
21
- };
21
+ }
22
+ return to;
23
+ };
22
24
  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: !0
30
- }) : target, mod)),
31
- __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: !0
33
- }), mod);
25
+ // If the importer is in node compatibility mode or this is not an ESM
26
+ // file that has been converted to a CommonJS file using a Babel-
27
+ // compatible transform (i.e. "__esModule" has not been set), then set
28
+ // "default" to the CommonJS "module.exports" for node compatibility.
29
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
30
+ value: mod,
31
+ enumerable: true
32
+ }) : target, mod));
33
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
34
+ value: true
35
+ }), mod);
34
36
  var Dismissable_native_exports = {};
35
37
  __export(Dismissable_native_exports, {
36
38
  Dismissable: () => Dismissable,
37
39
  DismissableBranch: () => DismissableBranch,
38
- dispatchDiscreteCustomEvent: () => dispatchDiscreteCustomEvent
40
+ dispatchDiscreteCustomEvent: () => dispatchDiscreteCustomEvent,
41
+ getDismissableLayerCount: () => getDismissableLayerCount,
42
+ useDismissableLayersAbove: () => useDismissableLayersAbove,
43
+ useHasDismissableLayers: () => useHasDismissableLayers,
44
+ useIsInsideDismissable: () => useIsInsideDismissable
39
45
  });
40
46
  module.exports = __toCommonJS(Dismissable_native_exports);
41
47
  var import_react = __toESM(require("react"), 1);
42
48
  function dispatchDiscreteCustomEvent(_target, _event) {}
49
+ function getDismissableLayerCount() {
50
+ return 0;
51
+ }
52
+ function useHasDismissableLayers() {
53
+ return false;
54
+ }
55
+ function useIsInsideDismissable(_ref) {
56
+ return false;
57
+ }
58
+ function useDismissableLayersAbove(_ref) {
59
+ return 0;
60
+ }
43
61
  var Dismissable = /* @__PURE__ */import_react.default.forwardRef(function (props, _ref) {
44
- return props.children;
45
- }),
46
- DismissableBranch = /* @__PURE__ */import_react.default.forwardRef(function (props, _ref) {
47
- return props.children;
48
- });
62
+ return props.children;
63
+ });
64
+ var DismissableBranch = /* @__PURE__ */import_react.default.forwardRef(function (props, _ref) {
65
+ return props.children;
66
+ });
49
67
  //# sourceMappingURL=Dismissable.native.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Dismissable_native_exports","__export","Dismissable","DismissableBranch","dispatchDiscreteCustomEvent","module","exports","__toCommonJS","import_react","__toESM","require","_target","_event","default","forwardRef","props","_ref","children"],"sources":["../../src/Dismissable.native.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,0BAAA;AAAAC,QAAA,CAAAD,0BAAA;EAAAE,WAAA,EAAAA,CAAA,KAAAA,WAAA;EAAAC,iBAAA,EAAAA,CAAA,KAAAA,iBAAA;EAAAC,2BAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAC,YAAA,CAAAP,0BAAA;AAAA,IAAAQ,YAAA,GAAkBC,OAAA,CAAAC,OAAA;AAEX,SAASN,4BAA4BO,OAAA,EAASC,MAAA,EAAQ,CAAC;AACvD,IAAIV,WAAA,GAA4B,eAAAM,YAAA,CAAAK,OAAA,CAAMC,UAAA,CAAW,UAASC,KAAA,EAAOC,IAAA,EAAM;IAC1E,OAAOD,KAAA,CAAME,QAAA;EACjB,CAAC;EACUd,iBAAA,GAAkC,eAAAK,YAAA,CAAAK,OAAA,CAAMC,UAAA,CAAW,UAASC,KAAA,EAAOC,IAAA,EAAM;IAChF,OAAOD,KAAA,CAAME,QAAA;EACjB,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["Dismissable_native_exports","__export","Dismissable","DismissableBranch","dispatchDiscreteCustomEvent","getDismissableLayerCount","useDismissableLayersAbove","useHasDismissableLayers","useIsInsideDismissable","module","exports","__toCommonJS","import_react","__toESM","require","_target","_event","_ref","default","forwardRef","props","children"],"sources":["../../src/Dismissable.native.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,0BAAA;AAAAC,QAAA,CAAAD,0BAAA;EAAAE,WAAA,EAAAA,CAAA,KAAAA,WAAA;EAAAC,iBAAA,EAAAA,CAAA,KAAAA,iBAAA;EAAAC,2BAAA,EAAAA,CAAA,KAAAA,2BAAA;EAAAC,wBAAA,EAAAA,CAAA,KAAAA,wBAAA;EAAAC,yBAAA,EAAAA,CAAA,KAAAA,yBAAA;EAAAC,uBAAA,EAAAA,CAAA,KAAAA,uBAAA;EAAAC,sBAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAC,YAAA,CAAAX,0BAAA;AAAA,IAAAY,YAAA,GAAkBC,OAAA,CAAAC,OAAA;AAEX,SAASV,4BAA4BW,OAAA,EAASC,MAAA,EAAQ,CAAC;AACvD,SAASX,yBAAA,EAA2B;EACvC,OAAO;AACX;AACO,SAASE,wBAAA,EAA0B;EACtC,OAAO;AACX;AACO,SAASC,uBAAuBS,IAAA,EAAM;EACzC,OAAO;AACX;AACO,SAASX,0BAA0BW,IAAA,EAAM;EAC5C,OAAO;AACX;AACO,IAAIf,WAAA,GAA4B,eAAAU,YAAA,CAAAM,OAAA,CAAMC,UAAA,CAAW,UAASC,KAAA,EAAOH,IAAA,EAAM;EAC1E,OAAOG,KAAA,CAAMC,QAAA;AACjB,CAAC;AACM,IAAIlB,iBAAA,GAAkC,eAAAS,YAAA,CAAAM,OAAA,CAAMC,UAAA,CAAW,UAASC,KAAA,EAAOH,IAAA,EAAM;EAChF,OAAOG,KAAA,CAAMC,QAAA;AACjB,CAAC","ignoreList":[]}