@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.
- package/dist/cjs/Dismissable.cjs +331 -158
- package/dist/cjs/Dismissable.native.js +46 -28
- package/dist/cjs/Dismissable.native.js.map +1 -1
- package/dist/cjs/DismissableProps.cjs +7 -5
- package/dist/cjs/DismissableProps.native.js +7 -5
- package/dist/cjs/DismissableProps.native.js.map +1 -1
- package/dist/cjs/index.cjs +7 -5
- package/dist/cjs/index.native.js +7 -5
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/Dismissable.mjs +295 -129
- package/dist/esm/Dismissable.mjs.map +1 -1
- package/dist/esm/Dismissable.native.js +18 -6
- package/dist/esm/Dismissable.native.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -6
- package/dist/jsx/Dismissable.mjs +295 -129
- package/dist/jsx/Dismissable.mjs.map +1 -1
- package/dist/jsx/Dismissable.native.js +46 -28
- package/dist/jsx/Dismissable.native.js.map +1 -1
- package/dist/jsx/DismissableProps.native.js +7 -5
- package/dist/jsx/index.js +1 -1
- package/dist/jsx/index.js.map +1 -6
- package/dist/jsx/index.native.js +7 -5
- package/package.json +10 -13
- package/src/Dismissable.native.tsx +21 -1
- package/src/Dismissable.tsx +187 -33
- package/src/DismissableProps.tsx +10 -0
- package/types/Dismissable.d.ts +28 -2
- package/types/Dismissable.d.ts.map +1 -1
- package/types/Dismissable.native.d.ts +4 -0
- package/types/Dismissable.native.d.ts.map +1 -1
- package/types/DismissableProps.d.ts +10 -0
- package/types/DismissableProps.d.ts.map +1 -1
- package/dist/cjs/Dismissable.js +0 -179
- package/dist/cjs/Dismissable.js.map +0 -6
- package/dist/cjs/DismissableProps.js +0 -14
- package/dist/cjs/DismissableProps.js.map +0 -6
- package/dist/cjs/index.js +0 -15
- package/dist/cjs/index.js.map +0 -6
- package/dist/esm/Dismissable.js +0 -161
- package/dist/esm/Dismissable.js.map +0 -6
- package/dist/esm/DismissableProps.js +0 -1
- package/dist/esm/DismissableProps.js.map +0 -6
- package/dist/jsx/Dismissable.js +0 -161
- package/dist/jsx/Dismissable.js.map +0 -6
- package/dist/jsx/DismissableProps.js +0 -1
- package/dist/jsx/DismissableProps.js.map +0 -6
package/dist/cjs/Dismissable.cjs
CHANGED
|
@@ -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
|
-
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
|
54
|
+
if (target) ReactDOM.flushSync(() => target.dispatchEvent(event));
|
|
48
55
|
}
|
|
49
|
-
const DISMISSABLE_LAYER_NAME = "Dismissable"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
317
|
+
}
|
|
318
|
+
isPointerInsideReactTreeRef.current = false;
|
|
319
|
+
};
|
|
320
|
+
const timerId = setTimeout(() => {
|
|
321
|
+
document.addEventListener("pointerdown", handlePointerDown);
|
|
322
|
+
}, 0);
|
|
163
323
|
return () => {
|
|
164
|
-
window.clearTimeout(timerId)
|
|
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 =
|
|
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
|
-
|
|
176
|
-
|
|
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
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
-
|
|
185
|
-
|
|
350
|
+
document.addEventListener("focusin", handleFocus);
|
|
351
|
+
return () => document.removeEventListener("focusin", handleFocus);
|
|
352
|
+
}, [handleFocusOutside]);
|
|
353
|
+
return {
|
|
186
354
|
onFocusCapture: () => {
|
|
187
|
-
isFocusInsideReactTreeRef.current =
|
|
355
|
+
isFocusInsideReactTreeRef.current = true;
|
|
188
356
|
},
|
|
189
357
|
onBlurCapture: () => {
|
|
190
|
-
isFocusInsideReactTreeRef.current =
|
|
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
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
handler
|
|
208
|
-
once:
|
|
209
|
-
})
|
|
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
|
-
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
9
|
var __export = (target, all) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
21
|
-
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
22
24
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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","
|
|
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":[]}
|