@tamagui/dismissable 1.88.13 → 1.89.0-1706308641099
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/LICENSE +21 -0
- package/dist/esm/Dismissable.mjs +172 -0
- package/dist/esm/DismissableProps.mjs +0 -0
- package/dist/esm/index.mjs +1 -0
- package/dist/jsx/Dismissable.mjs +172 -0
- package/dist/jsx/DismissableProps.mjs +0 -0
- package/dist/jsx/index.mjs +1 -0
- package/package.json +7 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Nate Wienert
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
2
|
+
import { composeEventHandlers } from "@tamagui/helpers";
|
|
3
|
+
import { useEscapeKeydown } from "@tamagui/use-escape-keydown";
|
|
4
|
+
import { useEvent } from "@tamagui/use-event";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import * as ReactDOM from "react-dom";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
function dispatchDiscreteCustomEvent(target, event) {
|
|
9
|
+
target && ReactDOM.flushSync(() => target.dispatchEvent(event));
|
|
10
|
+
}
|
|
11
|
+
const DISMISSABLE_LAYER_NAME = "Dismissable",
|
|
12
|
+
CONTEXT_UPDATE = "dismissable.update",
|
|
13
|
+
POINTER_DOWN_OUTSIDE = "dismissable.pointerDownOutside",
|
|
14
|
+
FOCUS_OUTSIDE = "dismissable.focusOutside";
|
|
15
|
+
let originalBodyPointerEvents;
|
|
16
|
+
const DismissableContext = React.createContext({
|
|
17
|
+
layers: /* @__PURE__ */new Set(),
|
|
18
|
+
layersWithOutsidePointerEventsDisabled: /* @__PURE__ */new Set(),
|
|
19
|
+
branches: /* @__PURE__ */new Set()
|
|
20
|
+
}),
|
|
21
|
+
Dismissable = React.forwardRef((props, forwardedRef) => {
|
|
22
|
+
const {
|
|
23
|
+
disableOutsidePointerEvents = !1,
|
|
24
|
+
forceUnmount,
|
|
25
|
+
onEscapeKeyDown,
|
|
26
|
+
onPointerDownOutside,
|
|
27
|
+
onFocusOutside,
|
|
28
|
+
onInteractOutside,
|
|
29
|
+
onDismiss,
|
|
30
|
+
...layerProps
|
|
31
|
+
} = props,
|
|
32
|
+
context = React.useContext(DismissableContext),
|
|
33
|
+
[node, setNode] = React.useState(null),
|
|
34
|
+
[, force] = React.useState({}),
|
|
35
|
+
composedRefs = useComposedRefs(forwardedRef, node2 => setNode(node2)),
|
|
36
|
+
layers = Array.from(context.layers),
|
|
37
|
+
[highestLayerWithOutsidePointerEventsDisabled] = [...context.layersWithOutsidePointerEventsDisabled].slice(-1),
|
|
38
|
+
highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled),
|
|
39
|
+
index = node ? layers.indexOf(node) : -1,
|
|
40
|
+
isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0,
|
|
41
|
+
isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex,
|
|
42
|
+
pointerDownOutside = usePointerDownOutside(event => {
|
|
43
|
+
const target = event.target,
|
|
44
|
+
isPointerDownOnBranch = [...context.branches].some(branch => branch.contains(target));
|
|
45
|
+
!isPointerEventsEnabled || isPointerDownOnBranch || (onPointerDownOutside?.(event), onInteractOutside?.(event), event.defaultPrevented || onDismiss?.());
|
|
46
|
+
}),
|
|
47
|
+
focusOutside = useFocusOutside(event => {
|
|
48
|
+
const target = event.target;
|
|
49
|
+
[...context.branches].some(branch => branch.contains(target)) || (onFocusOutside?.(event), onInteractOutside?.(event), event.defaultPrevented || onDismiss?.());
|
|
50
|
+
});
|
|
51
|
+
return useEscapeKeydown(event => {
|
|
52
|
+
index === context.layers.size - 1 && (onEscapeKeyDown?.(event), !event.defaultPrevented && onDismiss && (event.preventDefault(), onDismiss()));
|
|
53
|
+
}), React.useEffect(() => {
|
|
54
|
+
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(), () => {
|
|
55
|
+
disableOutsidePointerEvents && context.layersWithOutsidePointerEventsDisabled.size === 1 && (document.body.style.pointerEvents = originalBodyPointerEvents);
|
|
56
|
+
};
|
|
57
|
+
}, [node, disableOutsidePointerEvents, context]), React.useEffect(() => {
|
|
58
|
+
if (!forceUnmount) return () => {
|
|
59
|
+
node && (context.layers.delete(node), context.layersWithOutsidePointerEventsDisabled.delete(node), dispatchUpdate());
|
|
60
|
+
};
|
|
61
|
+
}, [node, context, forceUnmount]), React.useEffect(() => {
|
|
62
|
+
const handleUpdate = () => {
|
|
63
|
+
force({});
|
|
64
|
+
};
|
|
65
|
+
return document.addEventListener(CONTEXT_UPDATE, handleUpdate), () => document.removeEventListener(CONTEXT_UPDATE, handleUpdate);
|
|
66
|
+
}, []), /* @__PURE__ */jsx("div", {
|
|
67
|
+
...layerProps,
|
|
68
|
+
ref: composedRefs,
|
|
69
|
+
style: {
|
|
70
|
+
display: "contents",
|
|
71
|
+
pointerEvents: isBodyPointerEventsDisabled ? isPointerEventsEnabled ? "auto" : "none" : void 0,
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
...props.style
|
|
74
|
+
},
|
|
75
|
+
onFocusCapture: composeEventHandlers(props.onFocusCapture, focusOutside.onFocusCapture),
|
|
76
|
+
onBlurCapture: composeEventHandlers(props.onBlurCapture, focusOutside.onBlurCapture),
|
|
77
|
+
onPointerDownCapture: composeEventHandlers(props.onPointerDownCapture, pointerDownOutside.onPointerDownCapture)
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
Dismissable.displayName = DISMISSABLE_LAYER_NAME;
|
|
81
|
+
const BRANCH_NAME = "DismissableBranch",
|
|
82
|
+
DismissableBranch = React.forwardRef((props, forwardedRef) => {
|
|
83
|
+
const context = React.useContext(DismissableContext),
|
|
84
|
+
ref = React.useRef(null),
|
|
85
|
+
composedRefs = useComposedRefs(forwardedRef, ref);
|
|
86
|
+
return React.useEffect(() => {
|
|
87
|
+
const node = ref.current;
|
|
88
|
+
if (node) return context.branches.add(node), () => {
|
|
89
|
+
context.branches.delete(node);
|
|
90
|
+
};
|
|
91
|
+
}, [context.branches]), /* @__PURE__ */jsx("div", {
|
|
92
|
+
style: {
|
|
93
|
+
display: "contents"
|
|
94
|
+
},
|
|
95
|
+
...props,
|
|
96
|
+
ref: composedRefs
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
DismissableBranch.displayName = BRANCH_NAME;
|
|
100
|
+
function usePointerDownOutside(onPointerDownOutside) {
|
|
101
|
+
const handlePointerDownOutside = useEvent(onPointerDownOutside),
|
|
102
|
+
isPointerInsideReactTreeRef = React.useRef(!1),
|
|
103
|
+
handleClickRef = React.useRef(() => {});
|
|
104
|
+
return React.useEffect(() => {
|
|
105
|
+
const handlePointerDown = event => {
|
|
106
|
+
if (event.target && !isPointerInsideReactTreeRef.current) {
|
|
107
|
+
let handleAndDispatchPointerDownOutsideEvent = function () {
|
|
108
|
+
handleAndDispatchCustomEvent(POINTER_DOWN_OUTSIDE, handlePointerDownOutside, eventDetail, {
|
|
109
|
+
discrete: !0
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
const eventDetail = {
|
|
113
|
+
originalEvent: event
|
|
114
|
+
};
|
|
115
|
+
event.pointerType === "touch" ? (document.removeEventListener("click", handleClickRef.current), handleClickRef.current = handleAndDispatchPointerDownOutsideEvent, document.addEventListener("click", handleClickRef.current, {
|
|
116
|
+
once: !0
|
|
117
|
+
})) : handleAndDispatchPointerDownOutsideEvent();
|
|
118
|
+
}
|
|
119
|
+
isPointerInsideReactTreeRef.current = !1;
|
|
120
|
+
},
|
|
121
|
+
timerId = setTimeout(() => {
|
|
122
|
+
document.addEventListener("pointerdown", handlePointerDown);
|
|
123
|
+
}, 0);
|
|
124
|
+
return () => {
|
|
125
|
+
window.clearTimeout(timerId), document.removeEventListener("pointerdown", handlePointerDown), document.removeEventListener("click", handleClickRef.current);
|
|
126
|
+
};
|
|
127
|
+
}, [handlePointerDownOutside]), {
|
|
128
|
+
// ensures we check React component tree (not just DOM tree)
|
|
129
|
+
onPointerDownCapture: () => {
|
|
130
|
+
isPointerInsideReactTreeRef.current = !0;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function useFocusOutside(onFocusOutside) {
|
|
135
|
+
const handleFocusOutside = useEvent(onFocusOutside),
|
|
136
|
+
isFocusInsideReactTreeRef = React.useRef(!1);
|
|
137
|
+
return React.useEffect(() => {
|
|
138
|
+
const handleFocus = event => {
|
|
139
|
+
event.target && !isFocusInsideReactTreeRef.current && handleAndDispatchCustomEvent(FOCUS_OUTSIDE, handleFocusOutside, {
|
|
140
|
+
originalEvent: event
|
|
141
|
+
}, {
|
|
142
|
+
discrete: !1
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
return document.addEventListener("focusin", handleFocus), () => document.removeEventListener("focusin", handleFocus);
|
|
146
|
+
}, [handleFocusOutside]), {
|
|
147
|
+
onFocusCapture: () => {
|
|
148
|
+
isFocusInsideReactTreeRef.current = !0;
|
|
149
|
+
},
|
|
150
|
+
onBlurCapture: () => {
|
|
151
|
+
isFocusInsideReactTreeRef.current = !1;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function dispatchUpdate() {
|
|
156
|
+
const event = new CustomEvent(CONTEXT_UPDATE);
|
|
157
|
+
document.dispatchEvent(event);
|
|
158
|
+
}
|
|
159
|
+
function handleAndDispatchCustomEvent(name, handler, detail, {
|
|
160
|
+
discrete
|
|
161
|
+
}) {
|
|
162
|
+
const target = detail.originalEvent.target,
|
|
163
|
+
event = new CustomEvent(name, {
|
|
164
|
+
bubbles: !1,
|
|
165
|
+
cancelable: !0,
|
|
166
|
+
detail
|
|
167
|
+
});
|
|
168
|
+
handler && target.addEventListener(name, handler, {
|
|
169
|
+
once: !0
|
|
170
|
+
}), discrete ? dispatchDiscreteCustomEvent(target, event) : target.dispatchEvent(event);
|
|
171
|
+
}
|
|
172
|
+
export { Dismissable, DismissableBranch, dispatchDiscreteCustomEvent };
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Dismissable.mjs";
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
2
|
+
import { composeEventHandlers } from "@tamagui/helpers";
|
|
3
|
+
import { useEscapeKeydown } from "@tamagui/use-escape-keydown";
|
|
4
|
+
import { useEvent } from "@tamagui/use-event";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import * as ReactDOM from "react-dom";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
function dispatchDiscreteCustomEvent(target, event) {
|
|
9
|
+
target && ReactDOM.flushSync(() => target.dispatchEvent(event));
|
|
10
|
+
}
|
|
11
|
+
const DISMISSABLE_LAYER_NAME = "Dismissable",
|
|
12
|
+
CONTEXT_UPDATE = "dismissable.update",
|
|
13
|
+
POINTER_DOWN_OUTSIDE = "dismissable.pointerDownOutside",
|
|
14
|
+
FOCUS_OUTSIDE = "dismissable.focusOutside";
|
|
15
|
+
let originalBodyPointerEvents;
|
|
16
|
+
const DismissableContext = React.createContext({
|
|
17
|
+
layers: /* @__PURE__ */new Set(),
|
|
18
|
+
layersWithOutsidePointerEventsDisabled: /* @__PURE__ */new Set(),
|
|
19
|
+
branches: /* @__PURE__ */new Set()
|
|
20
|
+
}),
|
|
21
|
+
Dismissable = React.forwardRef((props, forwardedRef) => {
|
|
22
|
+
const {
|
|
23
|
+
disableOutsidePointerEvents = !1,
|
|
24
|
+
forceUnmount,
|
|
25
|
+
onEscapeKeyDown,
|
|
26
|
+
onPointerDownOutside,
|
|
27
|
+
onFocusOutside,
|
|
28
|
+
onInteractOutside,
|
|
29
|
+
onDismiss,
|
|
30
|
+
...layerProps
|
|
31
|
+
} = props,
|
|
32
|
+
context = React.useContext(DismissableContext),
|
|
33
|
+
[node, setNode] = React.useState(null),
|
|
34
|
+
[, force] = React.useState({}),
|
|
35
|
+
composedRefs = useComposedRefs(forwardedRef, node2 => setNode(node2)),
|
|
36
|
+
layers = Array.from(context.layers),
|
|
37
|
+
[highestLayerWithOutsidePointerEventsDisabled] = [...context.layersWithOutsidePointerEventsDisabled].slice(-1),
|
|
38
|
+
highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled),
|
|
39
|
+
index = node ? layers.indexOf(node) : -1,
|
|
40
|
+
isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0,
|
|
41
|
+
isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex,
|
|
42
|
+
pointerDownOutside = usePointerDownOutside(event => {
|
|
43
|
+
const target = event.target,
|
|
44
|
+
isPointerDownOnBranch = [...context.branches].some(branch => branch.contains(target));
|
|
45
|
+
!isPointerEventsEnabled || isPointerDownOnBranch || (onPointerDownOutside?.(event), onInteractOutside?.(event), event.defaultPrevented || onDismiss?.());
|
|
46
|
+
}),
|
|
47
|
+
focusOutside = useFocusOutside(event => {
|
|
48
|
+
const target = event.target;
|
|
49
|
+
[...context.branches].some(branch => branch.contains(target)) || (onFocusOutside?.(event), onInteractOutside?.(event), event.defaultPrevented || onDismiss?.());
|
|
50
|
+
});
|
|
51
|
+
return useEscapeKeydown(event => {
|
|
52
|
+
index === context.layers.size - 1 && (onEscapeKeyDown?.(event), !event.defaultPrevented && onDismiss && (event.preventDefault(), onDismiss()));
|
|
53
|
+
}), React.useEffect(() => {
|
|
54
|
+
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(), () => {
|
|
55
|
+
disableOutsidePointerEvents && context.layersWithOutsidePointerEventsDisabled.size === 1 && (document.body.style.pointerEvents = originalBodyPointerEvents);
|
|
56
|
+
};
|
|
57
|
+
}, [node, disableOutsidePointerEvents, context]), React.useEffect(() => {
|
|
58
|
+
if (!forceUnmount) return () => {
|
|
59
|
+
node && (context.layers.delete(node), context.layersWithOutsidePointerEventsDisabled.delete(node), dispatchUpdate());
|
|
60
|
+
};
|
|
61
|
+
}, [node, context, forceUnmount]), React.useEffect(() => {
|
|
62
|
+
const handleUpdate = () => {
|
|
63
|
+
force({});
|
|
64
|
+
};
|
|
65
|
+
return document.addEventListener(CONTEXT_UPDATE, handleUpdate), () => document.removeEventListener(CONTEXT_UPDATE, handleUpdate);
|
|
66
|
+
}, []), /* @__PURE__ */jsx("div", {
|
|
67
|
+
...layerProps,
|
|
68
|
+
ref: composedRefs,
|
|
69
|
+
style: {
|
|
70
|
+
display: "contents",
|
|
71
|
+
pointerEvents: isBodyPointerEventsDisabled ? isPointerEventsEnabled ? "auto" : "none" : void 0,
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
...props.style
|
|
74
|
+
},
|
|
75
|
+
onFocusCapture: composeEventHandlers(props.onFocusCapture, focusOutside.onFocusCapture),
|
|
76
|
+
onBlurCapture: composeEventHandlers(props.onBlurCapture, focusOutside.onBlurCapture),
|
|
77
|
+
onPointerDownCapture: composeEventHandlers(props.onPointerDownCapture, pointerDownOutside.onPointerDownCapture)
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
Dismissable.displayName = DISMISSABLE_LAYER_NAME;
|
|
81
|
+
const BRANCH_NAME = "DismissableBranch",
|
|
82
|
+
DismissableBranch = React.forwardRef((props, forwardedRef) => {
|
|
83
|
+
const context = React.useContext(DismissableContext),
|
|
84
|
+
ref = React.useRef(null),
|
|
85
|
+
composedRefs = useComposedRefs(forwardedRef, ref);
|
|
86
|
+
return React.useEffect(() => {
|
|
87
|
+
const node = ref.current;
|
|
88
|
+
if (node) return context.branches.add(node), () => {
|
|
89
|
+
context.branches.delete(node);
|
|
90
|
+
};
|
|
91
|
+
}, [context.branches]), /* @__PURE__ */jsx("div", {
|
|
92
|
+
style: {
|
|
93
|
+
display: "contents"
|
|
94
|
+
},
|
|
95
|
+
...props,
|
|
96
|
+
ref: composedRefs
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
DismissableBranch.displayName = BRANCH_NAME;
|
|
100
|
+
function usePointerDownOutside(onPointerDownOutside) {
|
|
101
|
+
const handlePointerDownOutside = useEvent(onPointerDownOutside),
|
|
102
|
+
isPointerInsideReactTreeRef = React.useRef(!1),
|
|
103
|
+
handleClickRef = React.useRef(() => {});
|
|
104
|
+
return React.useEffect(() => {
|
|
105
|
+
const handlePointerDown = event => {
|
|
106
|
+
if (event.target && !isPointerInsideReactTreeRef.current) {
|
|
107
|
+
let handleAndDispatchPointerDownOutsideEvent = function () {
|
|
108
|
+
handleAndDispatchCustomEvent(POINTER_DOWN_OUTSIDE, handlePointerDownOutside, eventDetail, {
|
|
109
|
+
discrete: !0
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
const eventDetail = {
|
|
113
|
+
originalEvent: event
|
|
114
|
+
};
|
|
115
|
+
event.pointerType === "touch" ? (document.removeEventListener("click", handleClickRef.current), handleClickRef.current = handleAndDispatchPointerDownOutsideEvent, document.addEventListener("click", handleClickRef.current, {
|
|
116
|
+
once: !0
|
|
117
|
+
})) : handleAndDispatchPointerDownOutsideEvent();
|
|
118
|
+
}
|
|
119
|
+
isPointerInsideReactTreeRef.current = !1;
|
|
120
|
+
},
|
|
121
|
+
timerId = setTimeout(() => {
|
|
122
|
+
document.addEventListener("pointerdown", handlePointerDown);
|
|
123
|
+
}, 0);
|
|
124
|
+
return () => {
|
|
125
|
+
window.clearTimeout(timerId), document.removeEventListener("pointerdown", handlePointerDown), document.removeEventListener("click", handleClickRef.current);
|
|
126
|
+
};
|
|
127
|
+
}, [handlePointerDownOutside]), {
|
|
128
|
+
// ensures we check React component tree (not just DOM tree)
|
|
129
|
+
onPointerDownCapture: () => {
|
|
130
|
+
isPointerInsideReactTreeRef.current = !0;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function useFocusOutside(onFocusOutside) {
|
|
135
|
+
const handleFocusOutside = useEvent(onFocusOutside),
|
|
136
|
+
isFocusInsideReactTreeRef = React.useRef(!1);
|
|
137
|
+
return React.useEffect(() => {
|
|
138
|
+
const handleFocus = event => {
|
|
139
|
+
event.target && !isFocusInsideReactTreeRef.current && handleAndDispatchCustomEvent(FOCUS_OUTSIDE, handleFocusOutside, {
|
|
140
|
+
originalEvent: event
|
|
141
|
+
}, {
|
|
142
|
+
discrete: !1
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
return document.addEventListener("focusin", handleFocus), () => document.removeEventListener("focusin", handleFocus);
|
|
146
|
+
}, [handleFocusOutside]), {
|
|
147
|
+
onFocusCapture: () => {
|
|
148
|
+
isFocusInsideReactTreeRef.current = !0;
|
|
149
|
+
},
|
|
150
|
+
onBlurCapture: () => {
|
|
151
|
+
isFocusInsideReactTreeRef.current = !1;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function dispatchUpdate() {
|
|
156
|
+
const event = new CustomEvent(CONTEXT_UPDATE);
|
|
157
|
+
document.dispatchEvent(event);
|
|
158
|
+
}
|
|
159
|
+
function handleAndDispatchCustomEvent(name, handler, detail, {
|
|
160
|
+
discrete
|
|
161
|
+
}) {
|
|
162
|
+
const target = detail.originalEvent.target,
|
|
163
|
+
event = new CustomEvent(name, {
|
|
164
|
+
bubbles: !1,
|
|
165
|
+
cancelable: !0,
|
|
166
|
+
detail
|
|
167
|
+
});
|
|
168
|
+
handler && target.addEventListener(name, handler, {
|
|
169
|
+
once: !0
|
|
170
|
+
}), discrete ? dispatchDiscreteCustomEvent(target, event) : target.dispatchEvent(event);
|
|
171
|
+
}
|
|
172
|
+
export { Dismissable, DismissableBranch, dispatchDiscreteCustomEvent };
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Dismissable.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/dismissable",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.89.0-1706308641099",
|
|
4
4
|
"sideEffects": true,
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -30,17 +30,17 @@
|
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@tamagui/compose-refs": "1.
|
|
34
|
-
"@tamagui/core": "1.
|
|
35
|
-
"@tamagui/helpers": "1.
|
|
36
|
-
"@tamagui/use-escape-keydown": "1.
|
|
37
|
-
"@tamagui/use-event": "1.
|
|
33
|
+
"@tamagui/compose-refs": "1.89.0-1706308641099",
|
|
34
|
+
"@tamagui/core": "1.89.0-1706308641099",
|
|
35
|
+
"@tamagui/helpers": "1.89.0-1706308641099",
|
|
36
|
+
"@tamagui/use-escape-keydown": "1.89.0-1706308641099",
|
|
37
|
+
"@tamagui/use-event": "1.89.0-1706308641099"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"react": "*"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@tamagui/build": "1.
|
|
43
|
+
"@tamagui/build": "1.89.0-1706308641099",
|
|
44
44
|
"react": "^18.2.0"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|