@tamagui/dismissable 1.114.4 → 1.115.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 +209 -0
- package/dist/cjs/Dismissable.native.cjs +40 -0
- package/dist/cjs/Dismissable.native.cjs.map +6 -0
- package/dist/cjs/DismissableProps.cjs +16 -0
- package/dist/cjs/index.cjs +18 -0
- package/package.json +9 -8
- package/dist/cjs/Dismissable.js +0 -181
- package/dist/cjs/DismissableProps.js +0 -14
- package/dist/cjs/index.js +0 -15
- /package/dist/cjs/{Dismissable.js.map → Dismissable.cjs.map} +0 -0
- /package/dist/cjs/{DismissableProps.js.map → DismissableProps.cjs.map} +0 -0
- /package/dist/cjs/{index.js.map → index.cjs.map} +0 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var Dismissable_exports = {};
|
|
33
|
+
__export(Dismissable_exports, {
|
|
34
|
+
Dismissable: () => Dismissable,
|
|
35
|
+
DismissableBranch: () => DismissableBranch,
|
|
36
|
+
dispatchDiscreteCustomEvent: () => dispatchDiscreteCustomEvent
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(Dismissable_exports);
|
|
39
|
+
var import_compose_refs = require("@tamagui/compose-refs"),
|
|
40
|
+
import_helpers = require("@tamagui/helpers"),
|
|
41
|
+
import_use_escape_keydown = require("@tamagui/use-escape-keydown"),
|
|
42
|
+
import_use_event = require("@tamagui/use-event"),
|
|
43
|
+
React = __toESM(require("react")),
|
|
44
|
+
ReactDOM = __toESM(require("react-dom")),
|
|
45
|
+
import_jsx_runtime = require("react/jsx-runtime");
|
|
46
|
+
function dispatchDiscreteCustomEvent(target, event) {
|
|
47
|
+
target && ReactDOM.flushSync(() => target.dispatchEvent(event));
|
|
48
|
+
}
|
|
49
|
+
const DISMISSABLE_LAYER_NAME = "Dismissable",
|
|
50
|
+
CONTEXT_UPDATE = "dismissable.update",
|
|
51
|
+
POINTER_DOWN_OUTSIDE = "dismissable.pointerDownOutside",
|
|
52
|
+
FOCUS_OUTSIDE = "dismissable.focusOutside";
|
|
53
|
+
let originalBodyPointerEvents;
|
|
54
|
+
const DismissableContext = React.createContext({
|
|
55
|
+
layers: /* @__PURE__ */new Set(),
|
|
56
|
+
layersWithOutsidePointerEventsDisabled: /* @__PURE__ */new Set(),
|
|
57
|
+
branches: /* @__PURE__ */new Set()
|
|
58
|
+
}),
|
|
59
|
+
Dismissable = React.forwardRef((props, forwardedRef) => {
|
|
60
|
+
const {
|
|
61
|
+
disableOutsidePointerEvents = !1,
|
|
62
|
+
forceUnmount,
|
|
63
|
+
onEscapeKeyDown,
|
|
64
|
+
onPointerDownOutside,
|
|
65
|
+
onFocusOutside,
|
|
66
|
+
onInteractOutside,
|
|
67
|
+
onDismiss,
|
|
68
|
+
...layerProps
|
|
69
|
+
} = props,
|
|
70
|
+
context = React.useContext(DismissableContext),
|
|
71
|
+
[node, setNode] = React.useState(null),
|
|
72
|
+
[, force] = React.useState({}),
|
|
73
|
+
composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, node2 => setNode(node2)),
|
|
74
|
+
layers = Array.from(context.layers),
|
|
75
|
+
[highestLayerWithOutsidePointerEventsDisabled] = [...context.layersWithOutsidePointerEventsDisabled].slice(-1),
|
|
76
|
+
highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled),
|
|
77
|
+
index = node ? layers.indexOf(node) : -1,
|
|
78
|
+
isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0,
|
|
79
|
+
isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex,
|
|
80
|
+
pointerDownOutside = usePointerDownOutside(event => {
|
|
81
|
+
const target = event.target,
|
|
82
|
+
isPointerDownOnBranch = [...context.branches].some(branch => branch.contains(target));
|
|
83
|
+
!isPointerEventsEnabled || isPointerDownOnBranch || (onPointerDownOutside?.(event), onInteractOutside?.(event), event.defaultPrevented || onDismiss?.());
|
|
84
|
+
}),
|
|
85
|
+
focusOutside = useFocusOutside(event => {
|
|
86
|
+
const target = event.target;
|
|
87
|
+
[...context.branches].some(branch => branch.contains(target)) || (onFocusOutside?.(event), onInteractOutside?.(event), event.defaultPrevented || onDismiss?.());
|
|
88
|
+
});
|
|
89
|
+
return (0, import_use_escape_keydown.useEscapeKeydown)(event => {
|
|
90
|
+
index === context.layers.size - 1 && (onEscapeKeyDown?.(event), !event.defaultPrevented && onDismiss && (event.preventDefault(), onDismiss()));
|
|
91
|
+
}), React.useEffect(() => {
|
|
92
|
+
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(), () => {
|
|
93
|
+
disableOutsidePointerEvents && context.layersWithOutsidePointerEventsDisabled.size === 1 && (document.body.style.pointerEvents = originalBodyPointerEvents);
|
|
94
|
+
};
|
|
95
|
+
}, [node, disableOutsidePointerEvents, context]), React.useEffect(() => {
|
|
96
|
+
if (!forceUnmount) return () => {
|
|
97
|
+
node && (context.layers.delete(node), context.layersWithOutsidePointerEventsDisabled.delete(node), dispatchUpdate());
|
|
98
|
+
};
|
|
99
|
+
}, [node, context, forceUnmount]), React.useEffect(() => {
|
|
100
|
+
const handleUpdate = () => {
|
|
101
|
+
force({});
|
|
102
|
+
};
|
|
103
|
+
return document.addEventListener(CONTEXT_UPDATE, handleUpdate), () => document.removeEventListener(CONTEXT_UPDATE, handleUpdate);
|
|
104
|
+
}, []), /* @__PURE__ */(0, import_jsx_runtime.jsx)("div", {
|
|
105
|
+
...layerProps,
|
|
106
|
+
ref: composedRefs,
|
|
107
|
+
style: {
|
|
108
|
+
display: "contents",
|
|
109
|
+
pointerEvents: isBodyPointerEventsDisabled ? isPointerEventsEnabled ? "auto" : "none" : void 0,
|
|
110
|
+
// @ts-ignore
|
|
111
|
+
...props.style
|
|
112
|
+
},
|
|
113
|
+
onFocusCapture: (0, import_helpers.composeEventHandlers)(props.onFocusCapture, focusOutside.onFocusCapture),
|
|
114
|
+
onBlurCapture: (0, import_helpers.composeEventHandlers)(props.onBlurCapture, focusOutside.onBlurCapture),
|
|
115
|
+
onPointerDownCapture: (0, import_helpers.composeEventHandlers)(props.onPointerDownCapture, pointerDownOutside.onPointerDownCapture)
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
Dismissable.displayName = DISMISSABLE_LAYER_NAME;
|
|
119
|
+
const BRANCH_NAME = "DismissableBranch",
|
|
120
|
+
DismissableBranch = React.forwardRef((props, forwardedRef) => {
|
|
121
|
+
const context = React.useContext(DismissableContext),
|
|
122
|
+
ref = React.useRef(null),
|
|
123
|
+
composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref);
|
|
124
|
+
return React.useEffect(() => {
|
|
125
|
+
const node = ref.current;
|
|
126
|
+
if (node) return context.branches.add(node), () => {
|
|
127
|
+
context.branches.delete(node);
|
|
128
|
+
};
|
|
129
|
+
}, [context.branches]), /* @__PURE__ */(0, import_jsx_runtime.jsx)("div", {
|
|
130
|
+
style: {
|
|
131
|
+
display: "contents"
|
|
132
|
+
},
|
|
133
|
+
...props,
|
|
134
|
+
ref: composedRefs
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
DismissableBranch.displayName = BRANCH_NAME;
|
|
138
|
+
function usePointerDownOutside(onPointerDownOutside) {
|
|
139
|
+
const handlePointerDownOutside = (0, import_use_event.useEvent)(onPointerDownOutside),
|
|
140
|
+
isPointerInsideReactTreeRef = React.useRef(!1),
|
|
141
|
+
handleClickRef = React.useRef(() => {});
|
|
142
|
+
return React.useEffect(() => {
|
|
143
|
+
const handlePointerDown = event => {
|
|
144
|
+
if (event.target && !isPointerInsideReactTreeRef.current) {
|
|
145
|
+
let handleAndDispatchPointerDownOutsideEvent = function () {
|
|
146
|
+
handleAndDispatchCustomEvent(POINTER_DOWN_OUTSIDE, handlePointerDownOutside, eventDetail, {
|
|
147
|
+
discrete: !0
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
const eventDetail = {
|
|
151
|
+
originalEvent: event
|
|
152
|
+
};
|
|
153
|
+
event.pointerType === "touch" ? (document.removeEventListener("click", handleClickRef.current), handleClickRef.current = handleAndDispatchPointerDownOutsideEvent, document.addEventListener("click", handleClickRef.current, {
|
|
154
|
+
once: !0
|
|
155
|
+
})) : handleAndDispatchPointerDownOutsideEvent();
|
|
156
|
+
}
|
|
157
|
+
isPointerInsideReactTreeRef.current = !1;
|
|
158
|
+
},
|
|
159
|
+
timerId = setTimeout(() => {
|
|
160
|
+
document.addEventListener("pointerdown", handlePointerDown);
|
|
161
|
+
}, 0);
|
|
162
|
+
return () => {
|
|
163
|
+
window.clearTimeout(timerId), document.removeEventListener("pointerdown", handlePointerDown), document.removeEventListener("click", handleClickRef.current);
|
|
164
|
+
};
|
|
165
|
+
}, [handlePointerDownOutside]), {
|
|
166
|
+
// ensures we check React component tree (not just DOM tree)
|
|
167
|
+
onPointerDownCapture: () => {
|
|
168
|
+
isPointerInsideReactTreeRef.current = !0;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function useFocusOutside(onFocusOutside) {
|
|
173
|
+
const handleFocusOutside = (0, import_use_event.useEvent)(onFocusOutside),
|
|
174
|
+
isFocusInsideReactTreeRef = React.useRef(!1);
|
|
175
|
+
return React.useEffect(() => {
|
|
176
|
+
const handleFocus = event => {
|
|
177
|
+
event.target && !isFocusInsideReactTreeRef.current && handleAndDispatchCustomEvent(FOCUS_OUTSIDE, handleFocusOutside, {
|
|
178
|
+
originalEvent: event
|
|
179
|
+
}, {
|
|
180
|
+
discrete: !1
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
return document.addEventListener("focusin", handleFocus), () => document.removeEventListener("focusin", handleFocus);
|
|
184
|
+
}, [handleFocusOutside]), {
|
|
185
|
+
onFocusCapture: () => {
|
|
186
|
+
isFocusInsideReactTreeRef.current = !0;
|
|
187
|
+
},
|
|
188
|
+
onBlurCapture: () => {
|
|
189
|
+
isFocusInsideReactTreeRef.current = !1;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function dispatchUpdate() {
|
|
194
|
+
const event = new CustomEvent(CONTEXT_UPDATE);
|
|
195
|
+
document.dispatchEvent(event);
|
|
196
|
+
}
|
|
197
|
+
function handleAndDispatchCustomEvent(name, handler, detail, {
|
|
198
|
+
discrete
|
|
199
|
+
}) {
|
|
200
|
+
const target = detail.originalEvent.target,
|
|
201
|
+
event = new CustomEvent(name, {
|
|
202
|
+
bubbles: !1,
|
|
203
|
+
cancelable: !0,
|
|
204
|
+
detail
|
|
205
|
+
});
|
|
206
|
+
handler && target.addEventListener(name, handler, {
|
|
207
|
+
once: !0
|
|
208
|
+
}), discrete ? dispatchDiscreteCustomEvent(target, event) : target.dispatchEvent(event);
|
|
209
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var Dismissable_native_exports = {};
|
|
33
|
+
__export(Dismissable_native_exports, {
|
|
34
|
+
Dismissable: () => Dismissable,
|
|
35
|
+
DismissableBranch: () => DismissableBranch
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(Dismissable_native_exports);
|
|
38
|
+
var import_react = __toESM(require("react"));
|
|
39
|
+
const Dismissable = import_react.default.forwardRef((props, _ref) => props.children),
|
|
40
|
+
DismissableBranch = import_react.default.forwardRef((props, _ref) => props.children);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Dismissable.native.tsx"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAIX,MAAM,cAAc,aAAAA,QAAM,WAAW,CAAC,OAAyB,SAC7D,MAAM,QACd,GAEY,oBAAoB,aAAAA,QAAM;AAAA,EACrC,CAAC,OAA+B,SACvB,MAAM;AAEjB;",
|
|
5
|
+
"names": ["React"]
|
|
6
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
7
|
+
get: () => from[key],
|
|
8
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
9
|
+
});
|
|
10
|
+
return to;
|
|
11
|
+
};
|
|
12
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
13
|
+
value: !0
|
|
14
|
+
}), mod);
|
|
15
|
+
var DismissableProps_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(DismissableProps_exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
7
|
+
get: () => from[key],
|
|
8
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
9
|
+
});
|
|
10
|
+
return to;
|
|
11
|
+
},
|
|
12
|
+
__reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
13
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
14
|
+
value: !0
|
|
15
|
+
}), mod);
|
|
16
|
+
var src_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(src_exports);
|
|
18
|
+
__reExport(src_exports, require("./Dismissable.cjs"), module.exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/dismissable",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.115.1",
|
|
4
4
|
"sideEffects": true,
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -27,18 +27,19 @@
|
|
|
27
27
|
"react-native": "./dist/cjs/index.native.js",
|
|
28
28
|
"types": "./types/index.d.ts",
|
|
29
29
|
"import": "./dist/esm/index.mjs",
|
|
30
|
-
"require": "./dist/cjs/index.
|
|
30
|
+
"require": "./dist/cjs/index.cjs",
|
|
31
|
+
"default": "./dist/cjs/index.native.js"
|
|
31
32
|
}
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
34
|
-
"@tamagui/compose-refs": "1.
|
|
35
|
-
"@tamagui/core": "1.
|
|
36
|
-
"@tamagui/helpers": "1.
|
|
37
|
-
"@tamagui/use-escape-keydown": "1.
|
|
38
|
-
"@tamagui/use-event": "1.
|
|
35
|
+
"@tamagui/compose-refs": "1.115.1",
|
|
36
|
+
"@tamagui/core": "1.115.1",
|
|
37
|
+
"@tamagui/helpers": "1.115.1",
|
|
38
|
+
"@tamagui/use-escape-keydown": "1.115.1",
|
|
39
|
+
"@tamagui/use-event": "1.115.1"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
|
-
"@tamagui/build": "1.
|
|
42
|
+
"@tamagui/build": "1.115.1",
|
|
42
43
|
"react": "^18.2.0 || ^19.0.0"
|
|
43
44
|
},
|
|
44
45
|
"publishConfig": {
|
package/dist/cjs/Dismissable.js
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
-
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
-
return to;
|
|
14
|
-
};
|
|
15
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
21
|
-
mod
|
|
22
|
-
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
23
|
-
var Dismissable_exports = {};
|
|
24
|
-
__export(Dismissable_exports, {
|
|
25
|
-
Dismissable: () => Dismissable,
|
|
26
|
-
DismissableBranch: () => DismissableBranch,
|
|
27
|
-
dispatchDiscreteCustomEvent: () => dispatchDiscreteCustomEvent
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(Dismissable_exports);
|
|
30
|
-
var import_compose_refs = require("@tamagui/compose-refs"), import_helpers = require("@tamagui/helpers"), import_use_escape_keydown = require("@tamagui/use-escape-keydown"), import_use_event = require("@tamagui/use-event"), React = __toESM(require("react")), ReactDOM = __toESM(require("react-dom")), import_jsx_runtime = require("react/jsx-runtime");
|
|
31
|
-
function dispatchDiscreteCustomEvent(target, event) {
|
|
32
|
-
target && ReactDOM.flushSync(() => target.dispatchEvent(event));
|
|
33
|
-
}
|
|
34
|
-
const DISMISSABLE_LAYER_NAME = "Dismissable", CONTEXT_UPDATE = "dismissable.update", POINTER_DOWN_OUTSIDE = "dismissable.pointerDownOutside", FOCUS_OUTSIDE = "dismissable.focusOutside";
|
|
35
|
-
let originalBodyPointerEvents;
|
|
36
|
-
const DismissableContext = React.createContext({
|
|
37
|
-
layers: /* @__PURE__ */ new Set(),
|
|
38
|
-
layersWithOutsidePointerEventsDisabled: /* @__PURE__ */ new Set(),
|
|
39
|
-
branches: /* @__PURE__ */ new Set()
|
|
40
|
-
}), Dismissable = React.forwardRef(
|
|
41
|
-
(props, forwardedRef) => {
|
|
42
|
-
const {
|
|
43
|
-
disableOutsidePointerEvents = !1,
|
|
44
|
-
forceUnmount,
|
|
45
|
-
onEscapeKeyDown,
|
|
46
|
-
onPointerDownOutside,
|
|
47
|
-
onFocusOutside,
|
|
48
|
-
onInteractOutside,
|
|
49
|
-
onDismiss,
|
|
50
|
-
...layerProps
|
|
51
|
-
} = props, context = React.useContext(DismissableContext), [node, setNode] = React.useState(null), [, force] = React.useState({}), composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, (node2) => setNode(node2)), layers = Array.from(context.layers), [highestLayerWithOutsidePointerEventsDisabled] = [
|
|
52
|
-
...context.layersWithOutsidePointerEventsDisabled
|
|
53
|
-
].slice(-1), highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(
|
|
54
|
-
highestLayerWithOutsidePointerEventsDisabled
|
|
55
|
-
), index = node ? layers.indexOf(node) : -1, isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0, isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex, pointerDownOutside = usePointerDownOutside((event) => {
|
|
56
|
-
const target = event.target, isPointerDownOnBranch = [...context.branches].some(
|
|
57
|
-
(branch) => branch.contains(target)
|
|
58
|
-
);
|
|
59
|
-
!isPointerEventsEnabled || isPointerDownOnBranch || (onPointerDownOutside?.(event), onInteractOutside?.(event), event.defaultPrevented || onDismiss?.());
|
|
60
|
-
}), focusOutside = useFocusOutside((event) => {
|
|
61
|
-
const target = event.target;
|
|
62
|
-
[...context.branches].some(
|
|
63
|
-
(branch) => branch.contains(target)
|
|
64
|
-
) || (onFocusOutside?.(event), onInteractOutside?.(event), event.defaultPrevented || onDismiss?.());
|
|
65
|
-
});
|
|
66
|
-
return (0, import_use_escape_keydown.useEscapeKeydown)((event) => {
|
|
67
|
-
index === context.layers.size - 1 && (onEscapeKeyDown?.(event), !event.defaultPrevented && onDismiss && (event.preventDefault(), onDismiss()));
|
|
68
|
-
}), React.useEffect(() => {
|
|
69
|
-
if (node)
|
|
70
|
-
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(), () => {
|
|
71
|
-
disableOutsidePointerEvents && context.layersWithOutsidePointerEventsDisabled.size === 1 && (document.body.style.pointerEvents = originalBodyPointerEvents);
|
|
72
|
-
};
|
|
73
|
-
}, [node, disableOutsidePointerEvents, context]), React.useEffect(() => {
|
|
74
|
-
if (!forceUnmount)
|
|
75
|
-
return () => {
|
|
76
|
-
node && (context.layers.delete(node), context.layersWithOutsidePointerEventsDisabled.delete(node), dispatchUpdate());
|
|
77
|
-
};
|
|
78
|
-
}, [node, context, forceUnmount]), React.useEffect(() => {
|
|
79
|
-
const handleUpdate = () => {
|
|
80
|
-
force({});
|
|
81
|
-
};
|
|
82
|
-
return document.addEventListener(CONTEXT_UPDATE, handleUpdate), () => document.removeEventListener(CONTEXT_UPDATE, handleUpdate);
|
|
83
|
-
}, []), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
84
|
-
"div",
|
|
85
|
-
{
|
|
86
|
-
...layerProps,
|
|
87
|
-
ref: composedRefs,
|
|
88
|
-
style: {
|
|
89
|
-
display: "contents",
|
|
90
|
-
pointerEvents: isBodyPointerEventsDisabled ? isPointerEventsEnabled ? "auto" : "none" : void 0,
|
|
91
|
-
// @ts-ignore
|
|
92
|
-
...props.style
|
|
93
|
-
},
|
|
94
|
-
onFocusCapture: (0, import_helpers.composeEventHandlers)(
|
|
95
|
-
props.onFocusCapture,
|
|
96
|
-
focusOutside.onFocusCapture
|
|
97
|
-
),
|
|
98
|
-
onBlurCapture: (0, import_helpers.composeEventHandlers)(
|
|
99
|
-
props.onBlurCapture,
|
|
100
|
-
focusOutside.onBlurCapture
|
|
101
|
-
),
|
|
102
|
-
onPointerDownCapture: (0, import_helpers.composeEventHandlers)(
|
|
103
|
-
props.onPointerDownCapture,
|
|
104
|
-
pointerDownOutside.onPointerDownCapture
|
|
105
|
-
)
|
|
106
|
-
}
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
);
|
|
110
|
-
Dismissable.displayName = DISMISSABLE_LAYER_NAME;
|
|
111
|
-
const BRANCH_NAME = "DismissableBranch", DismissableBranch = React.forwardRef(
|
|
112
|
-
(props, forwardedRef) => {
|
|
113
|
-
const context = React.useContext(DismissableContext), ref = React.useRef(null), composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref);
|
|
114
|
-
return React.useEffect(() => {
|
|
115
|
-
const node = ref.current;
|
|
116
|
-
if (node)
|
|
117
|
-
return context.branches.add(node), () => {
|
|
118
|
-
context.branches.delete(node);
|
|
119
|
-
};
|
|
120
|
-
}, [context.branches]), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { display: "contents" }, ...props, ref: composedRefs });
|
|
121
|
-
}
|
|
122
|
-
);
|
|
123
|
-
DismissableBranch.displayName = BRANCH_NAME;
|
|
124
|
-
function usePointerDownOutside(onPointerDownOutside) {
|
|
125
|
-
const handlePointerDownOutside = (0, import_use_event.useEvent)(onPointerDownOutside), isPointerInsideReactTreeRef = React.useRef(!1), handleClickRef = React.useRef(() => {
|
|
126
|
-
});
|
|
127
|
-
return React.useEffect(() => {
|
|
128
|
-
const handlePointerDown = (event) => {
|
|
129
|
-
if (event.target && !isPointerInsideReactTreeRef.current) {
|
|
130
|
-
let handleAndDispatchPointerDownOutsideEvent = function() {
|
|
131
|
-
handleAndDispatchCustomEvent(
|
|
132
|
-
POINTER_DOWN_OUTSIDE,
|
|
133
|
-
handlePointerDownOutside,
|
|
134
|
-
eventDetail,
|
|
135
|
-
{ discrete: !0 }
|
|
136
|
-
);
|
|
137
|
-
};
|
|
138
|
-
const eventDetail = { originalEvent: event };
|
|
139
|
-
event.pointerType === "touch" ? (document.removeEventListener("click", handleClickRef.current), handleClickRef.current = handleAndDispatchPointerDownOutsideEvent, document.addEventListener("click", handleClickRef.current, { once: !0 })) : handleAndDispatchPointerDownOutsideEvent();
|
|
140
|
-
}
|
|
141
|
-
isPointerInsideReactTreeRef.current = !1;
|
|
142
|
-
}, timerId = setTimeout(() => {
|
|
143
|
-
document.addEventListener("pointerdown", handlePointerDown);
|
|
144
|
-
}, 0);
|
|
145
|
-
return () => {
|
|
146
|
-
window.clearTimeout(timerId), document.removeEventListener("pointerdown", handlePointerDown), document.removeEventListener("click", handleClickRef.current);
|
|
147
|
-
};
|
|
148
|
-
}, [handlePointerDownOutside]), {
|
|
149
|
-
// ensures we check React component tree (not just DOM tree)
|
|
150
|
-
onPointerDownCapture: () => {
|
|
151
|
-
isPointerInsideReactTreeRef.current = !0;
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
function useFocusOutside(onFocusOutside) {
|
|
156
|
-
const handleFocusOutside = (0, import_use_event.useEvent)(onFocusOutside), isFocusInsideReactTreeRef = React.useRef(!1);
|
|
157
|
-
return React.useEffect(() => {
|
|
158
|
-
const handleFocus = (event) => {
|
|
159
|
-
event.target && !isFocusInsideReactTreeRef.current && handleAndDispatchCustomEvent(FOCUS_OUTSIDE, handleFocusOutside, { originalEvent: event }, {
|
|
160
|
-
discrete: !1
|
|
161
|
-
});
|
|
162
|
-
};
|
|
163
|
-
return document.addEventListener("focusin", handleFocus), () => document.removeEventListener("focusin", handleFocus);
|
|
164
|
-
}, [handleFocusOutside]), {
|
|
165
|
-
onFocusCapture: () => {
|
|
166
|
-
isFocusInsideReactTreeRef.current = !0;
|
|
167
|
-
},
|
|
168
|
-
onBlurCapture: () => {
|
|
169
|
-
isFocusInsideReactTreeRef.current = !1;
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
function dispatchUpdate() {
|
|
174
|
-
const event = new CustomEvent(CONTEXT_UPDATE);
|
|
175
|
-
document.dispatchEvent(event);
|
|
176
|
-
}
|
|
177
|
-
function handleAndDispatchCustomEvent(name, handler, detail, { discrete }) {
|
|
178
|
-
const target = detail.originalEvent.target, event = new CustomEvent(name, { bubbles: !1, cancelable: !0, detail });
|
|
179
|
-
handler && target.addEventListener(name, handler, { once: !0 }), discrete ? dispatchDiscreteCustomEvent(target, event) : target.dispatchEvent(event);
|
|
180
|
-
}
|
|
181
|
-
//# sourceMappingURL=Dismissable.js.map
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
|
-
return to;
|
|
10
|
-
};
|
|
11
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
12
|
-
var DismissableProps_exports = {};
|
|
13
|
-
module.exports = __toCommonJS(DismissableProps_exports);
|
|
14
|
-
//# sourceMappingURL=DismissableProps.js.map
|
package/dist/cjs/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
|
-
return to;
|
|
10
|
-
}, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
11
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
12
|
-
var src_exports = {};
|
|
13
|
-
module.exports = __toCommonJS(src_exports);
|
|
14
|
-
__reExport(src_exports, require("./Dismissable"), module.exports);
|
|
15
|
-
//# sourceMappingURL=index.js.map
|
|
File without changes
|
|
File without changes
|
|
File without changes
|