@tamagui/dismissable 2.7.7 → 3.0.0-beta.643.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.
- package/dist/cjs/Dismissable.cjs +282 -330
- package/dist/cjs/Dismissable.native.cjs +61 -0
- package/dist/cjs/Dismissable.native.js +33 -37
- package/dist/cjs/Dismissable.native.js.map +1 -1
- package/dist/cjs/DismissableProps.cjs +10 -11
- package/dist/cjs/DismissableProps.native.cjs +19 -0
- package/dist/cjs/DismissableProps.native.js +10 -10
- package/dist/cjs/DismissableProps.native.js.map +1 -1
- package/dist/cjs/index.cjs +10 -11
- package/dist/cjs/index.native.cjs +21 -0
- package/dist/cjs/index.native.js +10 -10
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/Dismissable.mjs +261 -301
- package/dist/esm/Dismissable.mjs.map +1 -1
- package/dist/esm/Dismissable.native.js +12 -9
- package/dist/esm/Dismissable.native.js.map +1 -1
- package/dist/esm/DismissableProps.mjs +0 -2
- package/dist/esm/DismissableProps.native.js +0 -2
- package/dist/esm/index.js +1 -2
- package/dist/esm/index.mjs +1 -2
- package/dist/esm/index.native.js +1 -2
- package/dist/jsx/Dismissable.mjs +261 -301
- package/dist/jsx/Dismissable.mjs.map +1 -1
- package/dist/jsx/Dismissable.native.cjs +61 -0
- package/dist/jsx/Dismissable.native.js +33 -37
- package/dist/jsx/Dismissable.native.js.map +1 -1
- package/dist/jsx/DismissableProps.mjs +0 -2
- package/dist/jsx/DismissableProps.native.cjs +19 -0
- package/dist/jsx/DismissableProps.native.js +10 -10
- package/dist/jsx/DismissableProps.native.js.map +1 -1
- package/dist/jsx/index.js +1 -2
- package/dist/jsx/index.mjs +1 -2
- package/dist/jsx/index.native.cjs +21 -0
- package/dist/jsx/index.native.js +10 -10
- package/dist/jsx/index.native.js.map +1 -1
- package/package.json +7 -7
- package/src/Dismissable.native.tsx +3 -2
- package/src/Dismissable.tsx +90 -92
- package/src/DismissableProps.tsx +31 -10
- package/types/Dismissable.d.ts +3 -9
- package/types/Dismissable.d.ts.map +1 -1
- package/types/Dismissable.native.d.ts +2 -2
- package/types/Dismissable.native.d.ts.map +1 -1
- package/types/DismissableProps.d.ts +22 -10
- package/types/DismissableProps.d.ts.map +1 -1
- package/dist/esm/DismissableProps.mjs.map +0 -1
- package/dist/esm/DismissableProps.native.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
- package/dist/jsx/DismissableProps.mjs.map +0 -1
- package/dist/jsx/index.js.map +0 -1
- package/dist/jsx/index.mjs.map +0 -1
package/dist/cjs/Dismissable.cjs
CHANGED
|
@@ -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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
24
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
57
|
+
for (const listener of layerChangeListeners) {
|
|
58
|
+
listener();
|
|
59
|
+
}
|
|
68
60
|
}
|
|
69
61
|
function getDismissableLayerCount() {
|
|
70
|
-
|
|
62
|
+
return globalLayers.size;
|
|
71
63
|
}
|
|
72
64
|
function debugDismissableLayers() {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
82
|
+
layers: /* @__PURE__ */ new Set(),
|
|
83
|
+
layersWithOutsidePointerEventsDisabled: /* @__PURE__ */ new Set(),
|
|
84
|
+
branches: /* @__PURE__ */ new Set()
|
|
93
85
|
});
|
|
94
86
|
function useIsInsideDismissable(ref) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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 =
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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 =
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
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
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
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
|
-
|
|
364
|
-
|
|
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
|
-
}
|