@tamagui/dismissable 1.88.13 → 1.88.14
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/cjs/index.js.map +1 -1
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/Dismissable.mjs +172 -0
- package/dist/esm/DismissableProps.mjs +0 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +1 -0
- package/dist/esm/index.native.js.map +1 -1
- package/dist/jsx/Dismissable.mjs +172 -0
- package/dist/jsx/DismissableProps.mjs +0 -0
- package/dist/jsx/index.js.map +1 -1
- package/dist/jsx/index.mjs +1 -0
- package/dist/jsx/index.native.js.map +1 -1
- package/package.json +7 -7
- package/src/Dismissable.native.tsx +1 -1
- package/src/Dismissable.tsx +1 -1
- package/src/DismissableProps.tsx +2 -2
- package/types/Dismissable.d.ts +1 -1
- package/types/Dismissable.d.ts.map +1 -1
- package/types/Dismissable.native.d.ts +1 -1
- package/types/Dismissable.native.d.ts.map +1 -1
- package/types/DismissableProps.d.ts +2 -2
- package/types/DismissableProps.d.ts.map +1 -1
- package/types/index.d.ts.map +1 -1
- /package/src/{index.tsx → index.ts} +0 -0
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.
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -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
|
package/dist/esm/index.js.map
CHANGED
|
@@ -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
|
package/dist/jsx/index.js.map
CHANGED
|
@@ -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.88.
|
|
3
|
+
"version": "1.88.14",
|
|
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.88.
|
|
34
|
-
"@tamagui/core": "1.88.
|
|
35
|
-
"@tamagui/helpers": "1.88.
|
|
36
|
-
"@tamagui/use-escape-keydown": "1.88.
|
|
37
|
-
"@tamagui/use-event": "1.88.
|
|
33
|
+
"@tamagui/compose-refs": "1.88.14",
|
|
34
|
+
"@tamagui/core": "1.88.14",
|
|
35
|
+
"@tamagui/helpers": "1.88.14",
|
|
36
|
+
"@tamagui/use-escape-keydown": "1.88.14",
|
|
37
|
+
"@tamagui/use-event": "1.88.14"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"react": "*"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@tamagui/build": "1.88.
|
|
43
|
+
"@tamagui/build": "1.88.14",
|
|
44
44
|
"react": "^18.2.0"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { forwardRef } from 'react'
|
|
2
2
|
|
|
3
|
-
import { DismissableBranchProps, DismissableProps } from './DismissableProps'
|
|
3
|
+
import type { DismissableBranchProps, DismissableProps } from './DismissableProps'
|
|
4
4
|
|
|
5
5
|
export const Dismissable = forwardRef((props: DismissableProps, _ref) => {
|
|
6
6
|
return props.children as any
|
package/src/Dismissable.tsx
CHANGED
|
@@ -8,7 +8,7 @@ import { useEvent } from '@tamagui/use-event'
|
|
|
8
8
|
import * as React from 'react'
|
|
9
9
|
import * as ReactDOM from 'react-dom'
|
|
10
10
|
|
|
11
|
-
import { DismissableBranchProps, DismissableProps } from './DismissableProps'
|
|
11
|
+
import type { DismissableBranchProps, DismissableProps } from './DismissableProps'
|
|
12
12
|
|
|
13
13
|
export function dispatchDiscreteCustomEvent<E extends CustomEvent>(
|
|
14
14
|
target: E['target'],
|
package/src/DismissableProps.tsx
CHANGED
package/types/Dismissable.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { DismissableBranchProps, DismissableProps } from './DismissableProps';
|
|
2
|
+
import type { DismissableBranchProps, DismissableProps } from './DismissableProps';
|
|
3
3
|
export declare function dispatchDiscreteCustomEvent<E extends CustomEvent>(target: E['target'], event: E): void;
|
|
4
4
|
declare const Dismissable: React.ForwardRefExoticComponent<DismissableProps & React.RefAttributes<HTMLDivElement>>;
|
|
5
5
|
declare const DismissableBranch: React.ForwardRefExoticComponent<DismissableBranchProps & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dismissable.d.ts","sourceRoot":"","sources":["../src/Dismissable.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"Dismissable.d.ts","sourceRoot":"","sources":["../src/Dismissable.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,KAAK,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAElF,wBAAgB,2BAA2B,CAAC,CAAC,SAAS,WAAW,EAC/D,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,EACnB,KAAK,EAAE,CAAC,QAGT;AAmBD,QAAA,MAAM,WAAW,yFA0IhB,CAAA;AAUD,QAAA,MAAM,iBAAiB,+FAkBtB,CAAA;AAMD,MAAM,MAAM,uBAAuB,GAAG,WAAW,CAAC;IAAE,aAAa,EAAE,YAAY,CAAA;CAAE,CAAC,CAAA;AAClF,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC;IAAE,aAAa,EAAE,UAAU,CAAA;CAAE,CAAC,CAAA;AAsI1E,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,CAAA;AAEzC,YAAY,EAAE,gBAAgB,EAAE,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { DismissableBranchProps, DismissableProps } from './DismissableProps';
|
|
2
|
+
import type { DismissableBranchProps, DismissableProps } from './DismissableProps';
|
|
3
3
|
export declare const Dismissable: import("react").ForwardRefExoticComponent<DismissableProps & import("react").RefAttributes<unknown>>;
|
|
4
4
|
export declare const DismissableBranch: import("react").ForwardRefExoticComponent<DismissableBranchProps & import("react").RefAttributes<unknown>>;
|
|
5
5
|
//# sourceMappingURL=Dismissable.native.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dismissable.native.d.ts","sourceRoot":"","sources":["../src/Dismissable.native.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"Dismissable.native.d.ts","sourceRoot":"","sources":["../src/Dismissable.native.tsx"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAElF,eAAO,MAAM,WAAW,sGAEtB,CAAA;AAEF,eAAO,MAAM,iBAAiB,4GAE5B,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { FocusOutsideEvent, PointerDownOutsideEvent } from './Dismissable';
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { FocusOutsideEvent, PointerDownOutsideEvent } from './Dismissable';
|
|
3
3
|
export interface DismissableProps {
|
|
4
4
|
/**
|
|
5
5
|
* When `true`, hover/focus/click interactions will be disabled on elements outside
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DismissableProps.d.ts","sourceRoot":"","sources":["../src/DismissableProps.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"DismissableProps.d.ts","sourceRoot":"","sources":["../src/DismissableProps.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,KAAK,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AAE/E,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,2BAA2B,CAAC,EAAE,OAAO,CAAA;IACrC;;;OAGG;IACH,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAA;IAChD;;;OAGG;IACH,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,uBAAuB,KAAK,IAAI,CAAA;IAC/D;;;OAGG;IACH,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAA;IACnD;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,uBAAuB,GAAG,iBAAiB,KAAK,IAAI,CAAA;IAEhF;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;IAEtB;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;IAEtB,oBAAoB,CAAC,EAAE,GAAG,CAAA;IAC1B,aAAa,CAAC,EAAE,GAAG,CAAA;IACnB,cAAc,CAAC,EAAE,GAAG,CAAA;IAEpB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC3B;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC3B"}
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA"}
|
|
File without changes
|