@tamagui/react-native-web-lite 1.129.3 → 1.129.5-1751174117974
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/Modal/index.cjs +5 -76
- package/dist/cjs/Modal/index.js +3 -74
- package/dist/cjs/Modal/index.js.map +2 -2
- package/dist/cjs/Modal/index.native.js +4 -61
- package/dist/cjs/Modal/index.native.js.map +2 -2
- package/dist/esm/Modal/index.js +1 -69
- package/dist/esm/Modal/index.js.map +1 -1
- package/dist/esm/Modal/index.mjs +1 -61
- package/dist/esm/Modal/index.mjs.map +1 -1
- package/dist/esm/Modal/index.native.js +2 -66
- package/dist/esm/Modal/index.native.js.map +1 -1
- package/package.json +6 -6
- package/src/Modal/index.js +1 -123
- package/dist/cjs/Modal/ModalFocusTrap.cjs +0 -108
- package/dist/cjs/Modal/ModalFocusTrap.js +0 -105
- package/dist/cjs/Modal/ModalFocusTrap.js.map +0 -6
- package/dist/cjs/Modal/ModalFocusTrap.native.js +0 -102
- package/dist/cjs/Modal/ModalFocusTrap.native.js.map +0 -6
- package/dist/esm/Modal/ModalFocusTrap.js +0 -85
- package/dist/esm/Modal/ModalFocusTrap.js.map +0 -6
- package/dist/esm/Modal/ModalFocusTrap.mjs +0 -74
- package/dist/esm/Modal/ModalFocusTrap.mjs.map +0 -1
- package/dist/esm/Modal/ModalFocusTrap.native.js +0 -78
- package/dist/esm/Modal/ModalFocusTrap.native.js.map +0 -1
- package/src/Modal/ModalFocusTrap.js +0 -163
package/src/Modal/index.js
CHANGED
|
@@ -1,123 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Copyright (c) Nicolas Gallagher.
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*/
|
|
10
|
-
import * as React from 'react'
|
|
11
|
-
|
|
12
|
-
import ModalAnimation from './ModalAnimation'
|
|
13
|
-
import ModalContent from './ModalContent'
|
|
14
|
-
import ModalFocusTrap from './ModalFocusTrap'
|
|
15
|
-
import ModalPortal from './ModalPortal'
|
|
16
|
-
|
|
17
|
-
var uniqueModalIdentifier = 0
|
|
18
|
-
var activeModalStack = []
|
|
19
|
-
var activeModalListeners = {}
|
|
20
|
-
|
|
21
|
-
function notifyActiveModalListeners() {
|
|
22
|
-
if (activeModalStack.length === 0) {
|
|
23
|
-
return
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
var activeModalId = activeModalStack[activeModalStack.length - 1]
|
|
27
|
-
activeModalStack.forEach((modalId) => {
|
|
28
|
-
if (modalId in activeModalListeners) {
|
|
29
|
-
activeModalListeners[modalId](modalId === activeModalId)
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function removeActiveModal(modalId) {
|
|
35
|
-
if (modalId in activeModalListeners) {
|
|
36
|
-
// Before removing this listener we should probably tell it
|
|
37
|
-
// that it's no longer the active modal for sure.
|
|
38
|
-
activeModalListeners[modalId](false)
|
|
39
|
-
delete activeModalListeners[modalId]
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
var index = activeModalStack.indexOf(modalId)
|
|
43
|
-
|
|
44
|
-
if (index !== -1) {
|
|
45
|
-
activeModalStack.splice(index, 1)
|
|
46
|
-
notifyActiveModalListeners()
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function addActiveModal(modalId, listener) {
|
|
51
|
-
removeActiveModal(modalId)
|
|
52
|
-
activeModalStack.push(modalId)
|
|
53
|
-
activeModalListeners[modalId] = listener
|
|
54
|
-
notifyActiveModalListeners()
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
var Modal = /*#__PURE__*/ React.forwardRef((props, forwardedRef) => {
|
|
58
|
-
const {
|
|
59
|
-
animationType,
|
|
60
|
-
children,
|
|
61
|
-
onDismiss,
|
|
62
|
-
onRequestClose,
|
|
63
|
-
onShow,
|
|
64
|
-
transparent,
|
|
65
|
-
visible = true,
|
|
66
|
-
...rest
|
|
67
|
-
} = props
|
|
68
|
-
|
|
69
|
-
var modalId = React.useMemo(() => uniqueModalIdentifier++, [])
|
|
70
|
-
|
|
71
|
-
var _React$useState = React.useState(false),
|
|
72
|
-
isActive = _React$useState[0],
|
|
73
|
-
setIsActive = _React$useState[1]
|
|
74
|
-
|
|
75
|
-
var onDismissCallback = React.useCallback(() => {
|
|
76
|
-
removeActiveModal(modalId)
|
|
77
|
-
|
|
78
|
-
if (onDismiss) {
|
|
79
|
-
onDismiss()
|
|
80
|
-
}
|
|
81
|
-
}, [modalId, onDismiss])
|
|
82
|
-
var onShowCallback = React.useCallback(() => {
|
|
83
|
-
addActiveModal(modalId, setIsActive)
|
|
84
|
-
|
|
85
|
-
if (onShow) {
|
|
86
|
-
onShow()
|
|
87
|
-
}
|
|
88
|
-
}, [modalId, onShow])
|
|
89
|
-
React.useEffect(() => {
|
|
90
|
-
return () => removeActiveModal(modalId)
|
|
91
|
-
}, [modalId])
|
|
92
|
-
return /*#__PURE__*/ React.createElement(
|
|
93
|
-
ModalPortal,
|
|
94
|
-
null,
|
|
95
|
-
/*#__PURE__*/ React.createElement(
|
|
96
|
-
ModalAnimation,
|
|
97
|
-
{
|
|
98
|
-
animationType: animationType,
|
|
99
|
-
onDismiss: onDismissCallback,
|
|
100
|
-
onShow: onShowCallback,
|
|
101
|
-
visible: visible,
|
|
102
|
-
},
|
|
103
|
-
/*#__PURE__*/ React.createElement(
|
|
104
|
-
ModalFocusTrap,
|
|
105
|
-
{
|
|
106
|
-
active: isActive,
|
|
107
|
-
},
|
|
108
|
-
/*#__PURE__*/ React.createElement(
|
|
109
|
-
ModalContent,
|
|
110
|
-
{
|
|
111
|
-
...rest,
|
|
112
|
-
active: isActive,
|
|
113
|
-
onRequestClose: onRequestClose,
|
|
114
|
-
ref: forwardedRef,
|
|
115
|
-
transparent: transparent,
|
|
116
|
-
},
|
|
117
|
-
children,
|
|
118
|
-
),
|
|
119
|
-
),
|
|
120
|
-
),
|
|
121
|
-
)
|
|
122
|
-
})
|
|
123
|
-
export default Modal
|
|
1
|
+
export default () => null
|
|
@@ -1,108 +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,
|
|
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 ModalFocusTrap_exports = {};
|
|
33
|
-
__export(ModalFocusTrap_exports, {
|
|
34
|
-
default: () => ModalFocusTrap_default
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(ModalFocusTrap_exports);
|
|
37
|
-
var React = __toESM(require("react")),
|
|
38
|
-
import_react_native_web_internals = require("@tamagui/react-native-web-internals"),
|
|
39
|
-
import_createElement = __toESM(require("../createElement/index.cjs")),
|
|
40
|
-
import_View = __toESM(require("../View/index.cjs")),
|
|
41
|
-
FocusBracket = () => (0, import_createElement.default)("div", {
|
|
42
|
-
accessibilityRole: "none",
|
|
43
|
-
tabIndex: 0,
|
|
44
|
-
style: styles.focusBracket
|
|
45
|
-
});
|
|
46
|
-
function attemptFocus(element) {
|
|
47
|
-
if (!import_react_native_web_internals.canUseDOM) return !1;
|
|
48
|
-
try {
|
|
49
|
-
element.focus();
|
|
50
|
-
} catch {}
|
|
51
|
-
return document.activeElement === element;
|
|
52
|
-
}
|
|
53
|
-
function focusFirstDescendant(element) {
|
|
54
|
-
for (var i = 0; i < element.childNodes.length; i++) {
|
|
55
|
-
var child = element.childNodes[i];
|
|
56
|
-
if (attemptFocus(child) || focusFirstDescendant(child)) return !0;
|
|
57
|
-
}
|
|
58
|
-
return !1;
|
|
59
|
-
}
|
|
60
|
-
function focusLastDescendant(element) {
|
|
61
|
-
for (var i = element.childNodes.length - 1; i >= 0; i--) {
|
|
62
|
-
var child = element.childNodes[i];
|
|
63
|
-
if (attemptFocus(child) || focusLastDescendant(child)) return !0;
|
|
64
|
-
}
|
|
65
|
-
return !1;
|
|
66
|
-
}
|
|
67
|
-
var ModalFocusTrap = _ref => {
|
|
68
|
-
var active = _ref.active,
|
|
69
|
-
children = _ref.children,
|
|
70
|
-
trapElementRef = React.useRef(),
|
|
71
|
-
focusRef = React.useRef({
|
|
72
|
-
trapFocusInProgress: !1,
|
|
73
|
-
lastFocusedElement: null
|
|
74
|
-
});
|
|
75
|
-
return React.useEffect(() => {
|
|
76
|
-
if (import_react_native_web_internals.canUseDOM) {
|
|
77
|
-
var trapFocus = () => {
|
|
78
|
-
if (!(trapElementRef.current == null || focusRef.current.trapFocusInProgress || !active)) {
|
|
79
|
-
try {
|
|
80
|
-
if (focusRef.current.trapFocusInProgress = !0, document.activeElement instanceof Node && !trapElementRef.current.contains(document.activeElement)) {
|
|
81
|
-
var hasFocused = focusFirstDescendant(trapElementRef.current);
|
|
82
|
-
focusRef.current.lastFocusedElement === document.activeElement && (hasFocused = focusLastDescendant(trapElementRef.current)), !hasFocused && trapElementRef.current != null && document.activeElement && import_react_native_web_internals.UIManager.focus(trapElementRef.current);
|
|
83
|
-
}
|
|
84
|
-
} finally {
|
|
85
|
-
focusRef.current.trapFocusInProgress = !1;
|
|
86
|
-
}
|
|
87
|
-
focusRef.current.lastFocusedElement = document.activeElement;
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
return trapFocus(), document.addEventListener("focus", trapFocus, !0), () => document.removeEventListener("focus", trapFocus, !0);
|
|
91
|
-
}
|
|
92
|
-
}, [active]), React.useEffect(function () {
|
|
93
|
-
if (import_react_native_web_internals.canUseDOM) {
|
|
94
|
-
var lastFocusedElementOutsideTrap = document.activeElement;
|
|
95
|
-
return function () {
|
|
96
|
-
lastFocusedElementOutsideTrap && document.contains(lastFocusedElementOutsideTrap) && import_react_native_web_internals.UIManager.focus(lastFocusedElementOutsideTrap);
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
}, []), /* @__PURE__ */React.createElement(React.Fragment, null, /* @__PURE__ */React.createElement(FocusBracket, null), /* @__PURE__ */React.createElement(import_View.default, {
|
|
100
|
-
ref: trapElementRef
|
|
101
|
-
}, children), /* @__PURE__ */React.createElement(FocusBracket, null));
|
|
102
|
-
},
|
|
103
|
-
ModalFocusTrap_default = ModalFocusTrap,
|
|
104
|
-
styles = import_react_native_web_internals.StyleSheet.create({
|
|
105
|
-
focusBracket: {
|
|
106
|
-
outlineStyle: "none"
|
|
107
|
-
}
|
|
108
|
-
});
|
|
@@ -1,105 +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 ModalFocusTrap_exports = {};
|
|
24
|
-
__export(ModalFocusTrap_exports, {
|
|
25
|
-
default: () => ModalFocusTrap_default
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(ModalFocusTrap_exports);
|
|
28
|
-
var React = __toESM(require("react")), import_react_native_web_internals = require("@tamagui/react-native-web-internals"), import_createElement = __toESM(require("../createElement/index")), import_View = __toESM(require("../View")), FocusBracket = () => (0, import_createElement.default)("div", {
|
|
29
|
-
accessibilityRole: "none",
|
|
30
|
-
tabIndex: 0,
|
|
31
|
-
style: styles.focusBracket
|
|
32
|
-
});
|
|
33
|
-
function attemptFocus(element) {
|
|
34
|
-
if (!import_react_native_web_internals.canUseDOM)
|
|
35
|
-
return !1;
|
|
36
|
-
try {
|
|
37
|
-
element.focus();
|
|
38
|
-
} catch {
|
|
39
|
-
}
|
|
40
|
-
return document.activeElement === element;
|
|
41
|
-
}
|
|
42
|
-
function focusFirstDescendant(element) {
|
|
43
|
-
for (var i = 0; i < element.childNodes.length; i++) {
|
|
44
|
-
var child = element.childNodes[i];
|
|
45
|
-
if (attemptFocus(child) || focusFirstDescendant(child))
|
|
46
|
-
return !0;
|
|
47
|
-
}
|
|
48
|
-
return !1;
|
|
49
|
-
}
|
|
50
|
-
function focusLastDescendant(element) {
|
|
51
|
-
for (var i = element.childNodes.length - 1; i >= 0; i--) {
|
|
52
|
-
var child = element.childNodes[i];
|
|
53
|
-
if (attemptFocus(child) || focusLastDescendant(child))
|
|
54
|
-
return !0;
|
|
55
|
-
}
|
|
56
|
-
return !1;
|
|
57
|
-
}
|
|
58
|
-
var ModalFocusTrap = (_ref) => {
|
|
59
|
-
var active = _ref.active, children = _ref.children, trapElementRef = React.useRef(), focusRef = React.useRef({
|
|
60
|
-
trapFocusInProgress: !1,
|
|
61
|
-
lastFocusedElement: null
|
|
62
|
-
});
|
|
63
|
-
return React.useEffect(() => {
|
|
64
|
-
if (import_react_native_web_internals.canUseDOM) {
|
|
65
|
-
var trapFocus = () => {
|
|
66
|
-
if (!(trapElementRef.current == null || focusRef.current.trapFocusInProgress || !active)) {
|
|
67
|
-
try {
|
|
68
|
-
if (focusRef.current.trapFocusInProgress = !0, document.activeElement instanceof Node && !trapElementRef.current.contains(document.activeElement)) {
|
|
69
|
-
var hasFocused = focusFirstDescendant(trapElementRef.current);
|
|
70
|
-
focusRef.current.lastFocusedElement === document.activeElement && (hasFocused = focusLastDescendant(trapElementRef.current)), !hasFocused && trapElementRef.current != null && document.activeElement && import_react_native_web_internals.UIManager.focus(trapElementRef.current);
|
|
71
|
-
}
|
|
72
|
-
} finally {
|
|
73
|
-
focusRef.current.trapFocusInProgress = !1;
|
|
74
|
-
}
|
|
75
|
-
focusRef.current.lastFocusedElement = document.activeElement;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
return trapFocus(), document.addEventListener("focus", trapFocus, !0), () => document.removeEventListener("focus", trapFocus, !0);
|
|
79
|
-
}
|
|
80
|
-
}, [active]), React.useEffect(function() {
|
|
81
|
-
if (import_react_native_web_internals.canUseDOM) {
|
|
82
|
-
var lastFocusedElementOutsideTrap = document.activeElement;
|
|
83
|
-
return function() {
|
|
84
|
-
lastFocusedElementOutsideTrap && document.contains(lastFocusedElementOutsideTrap) && import_react_native_web_internals.UIManager.focus(lastFocusedElementOutsideTrap);
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
}, []), /* @__PURE__ */ React.createElement(
|
|
88
|
-
React.Fragment,
|
|
89
|
-
null,
|
|
90
|
-
/* @__PURE__ */ React.createElement(FocusBracket, null),
|
|
91
|
-
/* @__PURE__ */ React.createElement(
|
|
92
|
-
import_View.default,
|
|
93
|
-
{
|
|
94
|
-
ref: trapElementRef
|
|
95
|
-
},
|
|
96
|
-
children
|
|
97
|
-
),
|
|
98
|
-
/* @__PURE__ */ React.createElement(FocusBracket, null)
|
|
99
|
-
);
|
|
100
|
-
}, ModalFocusTrap_default = ModalFocusTrap, styles = import_react_native_web_internals.StyleSheet.create({
|
|
101
|
-
focusBracket: {
|
|
102
|
-
outlineStyle: "none"
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
//# sourceMappingURL=ModalFocusTrap.js.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/Modal/Modal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e,QAAQ,SAAS,SAAS,aAAa,GACvD;AAOA,kBAAI,aAAa,qBAAqB,eAAe,OAAO;AAE5D,cAAI,SAAS,QAAQ,uBAAuB,SAAS,kBACnD,aAAa,oBAAoB,eAAe,OAAO,IAGrD,CAAC,cAAc,eAAe,WAAW,QAAQ,SAAS,iBAC5D,4CAAU,MAAM,eAAe,OAAO;AAAA,YAE1C;AAAA,UACF,UAAE;AACA,qBAAS,QAAQ,sBAAsB;AAAA,UACzC;AAEA,mBAAS,QAAQ,qBAAqB,SAAS;AAAA;AAAA,MACjD;AAEA,uBAAU,GACV,SAAS,iBAAiB,SAAS,WAAW,EAAI,GAC3C,MAAM,SAAS,oBAAoB,SAAS,WAAW,EAAI;AAAA,IACpE;AAAA,EACF,GAAG,CAAC,MAAM,CAAC,GAGX,MAAM,UAAU,WAAY;AAC1B,QAAI,6CAAW;AACb,UAAI,gCAAgC,SAAS;AAC7C,aAAO,WAAY;AACjB,QACE,iCACA,SAAS,SAAS,6BAA6B,KAE/C,4CAAU,MAAM,6BAA6B;AAAA,MAEjD;AAAA,IACF;AAAA,EACF,GAAG,CAAC,CAAC,GACgB,sBAAM;AAAA,IACzB,MAAM;AAAA,IACN;AAAA,IACc,sBAAM,cAAc,cAAc,IAAI;AAAA,IACtC,sBAAM;AAAA,MAClB,YAAAC;AAAA,MACA;AAAA,QACE,KAAK;AAAA,MACP;AAAA,MACA;AAAA,IACF;AAAA,IACc,sBAAM,cAAc,cAAc,IAAI;AAAA,EACtD;AACF,GAEO,yBAAQ,gBACX,SAAS,6CAAW,OAAO;AAAA,EAC7B,cAAc;AAAA,IACZ,cAAc;AAAA,EAChB;AACF,CAAC;",
|
|
5
|
-
"names": ["createElement", "View"]
|
|
6
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
10
|
-
}, __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
return to;
|
|
15
|
-
};
|
|
16
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
22
|
-
mod
|
|
23
|
-
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
24
|
-
var ModalFocusTrap_exports = {};
|
|
25
|
-
__export(ModalFocusTrap_exports, {
|
|
26
|
-
default: () => ModalFocusTrap_default
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(ModalFocusTrap_exports);
|
|
29
|
-
var React = __toESM(require("react")), import_react_native_web_internals = require("@tamagui/react-native-web-internals"), import_createElement = __toESM(require("../createElement/index")), import_View = __toESM(require("../View")), FocusBracket = function() {
|
|
30
|
-
return (0, import_createElement.default)("div", {
|
|
31
|
-
accessibilityRole: "none",
|
|
32
|
-
tabIndex: 0,
|
|
33
|
-
style: styles.focusBracket
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
function attemptFocus(element) {
|
|
37
|
-
if (!import_react_native_web_internals.canUseDOM)
|
|
38
|
-
return !1;
|
|
39
|
-
try {
|
|
40
|
-
element.focus();
|
|
41
|
-
} catch {
|
|
42
|
-
}
|
|
43
|
-
return document.activeElement === element;
|
|
44
|
-
}
|
|
45
|
-
function focusFirstDescendant(element) {
|
|
46
|
-
for (var i = 0; i < element.childNodes.length; i++) {
|
|
47
|
-
var child = element.childNodes[i];
|
|
48
|
-
if (attemptFocus(child) || focusFirstDescendant(child))
|
|
49
|
-
return !0;
|
|
50
|
-
}
|
|
51
|
-
return !1;
|
|
52
|
-
}
|
|
53
|
-
function focusLastDescendant(element) {
|
|
54
|
-
for (var i = element.childNodes.length - 1; i >= 0; i--) {
|
|
55
|
-
var child = element.childNodes[i];
|
|
56
|
-
if (attemptFocus(child) || focusLastDescendant(child))
|
|
57
|
-
return !0;
|
|
58
|
-
}
|
|
59
|
-
return !1;
|
|
60
|
-
}
|
|
61
|
-
var ModalFocusTrap = function(_ref) {
|
|
62
|
-
var active = _ref.active, children = _ref.children, trapElementRef = React.useRef(), focusRef = React.useRef({
|
|
63
|
-
trapFocusInProgress: !1,
|
|
64
|
-
lastFocusedElement: null
|
|
65
|
-
});
|
|
66
|
-
return React.useEffect(function() {
|
|
67
|
-
if (import_react_native_web_internals.canUseDOM) {
|
|
68
|
-
var trapFocus = function() {
|
|
69
|
-
if (!(trapElementRef.current == null || focusRef.current.trapFocusInProgress || !active)) {
|
|
70
|
-
try {
|
|
71
|
-
if (focusRef.current.trapFocusInProgress = !0, document.activeElement instanceof Node && !trapElementRef.current.contains(document.activeElement)) {
|
|
72
|
-
var hasFocused = focusFirstDescendant(trapElementRef.current);
|
|
73
|
-
focusRef.current.lastFocusedElement === document.activeElement && (hasFocused = focusLastDescendant(trapElementRef.current)), !hasFocused && trapElementRef.current != null && document.activeElement && import_react_native_web_internals.UIManager.focus(trapElementRef.current);
|
|
74
|
-
}
|
|
75
|
-
} finally {
|
|
76
|
-
focusRef.current.trapFocusInProgress = !1;
|
|
77
|
-
}
|
|
78
|
-
focusRef.current.lastFocusedElement = document.activeElement;
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
return trapFocus(), document.addEventListener("focus", trapFocus, !0), function() {
|
|
82
|
-
return document.removeEventListener("focus", trapFocus, !0);
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
}, [
|
|
86
|
-
active
|
|
87
|
-
]), React.useEffect(function() {
|
|
88
|
-
if (import_react_native_web_internals.canUseDOM) {
|
|
89
|
-
var lastFocusedElementOutsideTrap = document.activeElement;
|
|
90
|
-
return function() {
|
|
91
|
-
lastFocusedElementOutsideTrap && document.contains(lastFocusedElementOutsideTrap) && import_react_native_web_internals.UIManager.focus(lastFocusedElementOutsideTrap);
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
}, []), /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(FocusBracket, null), /* @__PURE__ */ React.createElement(import_View.default, {
|
|
95
|
-
ref: trapElementRef
|
|
96
|
-
}, children), /* @__PURE__ */ React.createElement(FocusBracket, null));
|
|
97
|
-
}, ModalFocusTrap_default = ModalFocusTrap, styles = import_react_native_web_internals.StyleSheet.create({
|
|
98
|
-
focusBracket: {
|
|
99
|
-
outlineStyle: "none"
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
//# sourceMappingURL=ModalFocusTrap.js.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/Modal/ModalFocusTrap.js"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;AASA,YAAuB,2BACvB,oCAAiD,gDAEjD,uBAA0B,4CAC1B,cAAiB,6BAUbA,eAAe,WAAA;AACjB,aAAOC,qBAAAA,SAAc,OAAO;IAC1BC,mBAAmB;IACnBC,UAAU;IACVC,O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QAAQpB,SAASC,iBAC5DuB,4CAAUzB,MAAMa,eAAeQ,OAAO;YAE1C;UACF,UAAA;AACEL,qBAASK,QAAQJ,sBAAsB;UACzC;AAEAD,mBAASK,QAAQH,qBAAqBjB,SAASC;;MACjD;AAEAkB,uBAAAA,GACAnB,SAASyB,iBAAiB,SAASN,WAAW,EAAA,GACvC,WAAA;eAAMnB,SAAS0B,oBAAoB,SAASP,WAAW,EAAA;;IAChE;EACF,GAAG;IAACT;GAAO,GAGXG,MAAMK,UAAU,WAAA;AACd,QAAIpB,6CAAW;AACb,UAAI6B,gCAAgC3B,SAASC;AAC7C,aAAO,WAAA;AACL,QACE0B,iCACA3B,SAASsB,SAASK,6BAAAA,KAElBH,4CAAUzB,MAAM4B,6BAAAA;MAEpB;IACF;EACF,GAAG,CAAA,CAAE,GACgBd,sBAAMvB,cACzBuB,MAAMe,UACN,MACcf,sBAAMvB,cAAcD,cAAc,IAAA,GAClCwB,sBAAMvB,cAClBuC,YAAAA,SACA;IACEC,KAAKlB;EACP,GACAD,QAAAA,GAEYE,sBAAMvB,cAAcD,cAAc,IAAA,CAAA;AAEpD,GAEA,yBAAemB,gBACXd,SAASqC,6CAAWC,OAAO;EAC7BrC,cAAc;IACZsC,cAAc;EAChB;AACF,CAAA;",
|
|
5
|
-
"names": ["FocusBracket", "createElement", "accessibilityRole", "tabIndex", "style", "styles", "focusBracket", "attemptFocus", "element", "canUseDOM", "focus", "document", "activeElement", "focusFirstDescendant", "i", "childNodes", "length", "child", "focusLastDescendant", "ModalFocusTrap", "_ref", "active", "children", "trapElementRef", "React", "useRef", "focusRef", "trapFocusInProgress", "lastFocusedElement", "useEffect", "trapFocus", "current", "Node", "contains", "hasFocused", "UIManager", "addEventListener", "removeEventListener", "lastFocusedElementOutsideTrap", "Fragment", "View", "ref", "StyleSheet", "create", "outlineStyle"]
|
|
6
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { StyleSheet, UIManager, canUseDOM } from "@tamagui/react-native-web-internals";
|
|
3
|
-
import createElement from "../createElement/index";
|
|
4
|
-
import View from "../View";
|
|
5
|
-
var FocusBracket = () => createElement("div", {
|
|
6
|
-
accessibilityRole: "none",
|
|
7
|
-
tabIndex: 0,
|
|
8
|
-
style: styles.focusBracket
|
|
9
|
-
});
|
|
10
|
-
function attemptFocus(element) {
|
|
11
|
-
if (!canUseDOM)
|
|
12
|
-
return !1;
|
|
13
|
-
try {
|
|
14
|
-
element.focus();
|
|
15
|
-
} catch {
|
|
16
|
-
}
|
|
17
|
-
return document.activeElement === element;
|
|
18
|
-
}
|
|
19
|
-
function focusFirstDescendant(element) {
|
|
20
|
-
for (var i = 0; i < element.childNodes.length; i++) {
|
|
21
|
-
var child = element.childNodes[i];
|
|
22
|
-
if (attemptFocus(child) || focusFirstDescendant(child))
|
|
23
|
-
return !0;
|
|
24
|
-
}
|
|
25
|
-
return !1;
|
|
26
|
-
}
|
|
27
|
-
function focusLastDescendant(element) {
|
|
28
|
-
for (var i = element.childNodes.length - 1; i >= 0; i--) {
|
|
29
|
-
var child = element.childNodes[i];
|
|
30
|
-
if (attemptFocus(child) || focusLastDescendant(child))
|
|
31
|
-
return !0;
|
|
32
|
-
}
|
|
33
|
-
return !1;
|
|
34
|
-
}
|
|
35
|
-
var ModalFocusTrap = (_ref) => {
|
|
36
|
-
var active = _ref.active, children = _ref.children, trapElementRef = React.useRef(), focusRef = React.useRef({
|
|
37
|
-
trapFocusInProgress: !1,
|
|
38
|
-
lastFocusedElement: null
|
|
39
|
-
});
|
|
40
|
-
return React.useEffect(() => {
|
|
41
|
-
if (canUseDOM) {
|
|
42
|
-
var trapFocus = () => {
|
|
43
|
-
if (!(trapElementRef.current == null || focusRef.current.trapFocusInProgress || !active)) {
|
|
44
|
-
try {
|
|
45
|
-
if (focusRef.current.trapFocusInProgress = !0, document.activeElement instanceof Node && !trapElementRef.current.contains(document.activeElement)) {
|
|
46
|
-
var hasFocused = focusFirstDescendant(trapElementRef.current);
|
|
47
|
-
focusRef.current.lastFocusedElement === document.activeElement && (hasFocused = focusLastDescendant(trapElementRef.current)), !hasFocused && trapElementRef.current != null && document.activeElement && UIManager.focus(trapElementRef.current);
|
|
48
|
-
}
|
|
49
|
-
} finally {
|
|
50
|
-
focusRef.current.trapFocusInProgress = !1;
|
|
51
|
-
}
|
|
52
|
-
focusRef.current.lastFocusedElement = document.activeElement;
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
return trapFocus(), document.addEventListener("focus", trapFocus, !0), () => document.removeEventListener("focus", trapFocus, !0);
|
|
56
|
-
}
|
|
57
|
-
}, [active]), React.useEffect(function() {
|
|
58
|
-
if (canUseDOM) {
|
|
59
|
-
var lastFocusedElementOutsideTrap = document.activeElement;
|
|
60
|
-
return function() {
|
|
61
|
-
lastFocusedElementOutsideTrap && document.contains(lastFocusedElementOutsideTrap) && UIManager.focus(lastFocusedElementOutsideTrap);
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
}, []), /* @__PURE__ */ React.createElement(
|
|
65
|
-
React.Fragment,
|
|
66
|
-
null,
|
|
67
|
-
/* @__PURE__ */ React.createElement(FocusBracket, null),
|
|
68
|
-
/* @__PURE__ */ React.createElement(
|
|
69
|
-
View,
|
|
70
|
-
{
|
|
71
|
-
ref: trapElementRef
|
|
72
|
-
},
|
|
73
|
-
children
|
|
74
|
-
),
|
|
75
|
-
/* @__PURE__ */ React.createElement(FocusBracket, null)
|
|
76
|
-
);
|
|
77
|
-
}, ModalFocusTrap_default = ModalFocusTrap, styles = StyleSheet.create({
|
|
78
|
-
focusBracket: {
|
|
79
|
-
outlineStyle: "none"
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
export {
|
|
83
|
-
ModalFocusTrap_default as default
|
|
84
|
-
};
|
|
85
|
-
//# sourceMappingURL=ModalFocusTrap.js.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources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AS,SAAS,aAAa,GACvD;AAOA,kBAAI,aAAa,qBAAqB,eAAe,OAAO;AAE5D,cAAI,SAAS,QAAQ,uBAAuB,SAAS,kBACnD,aAAa,oBAAoB,eAAe,OAAO,IAGrD,CAAC,cAAc,eAAe,WAAW,QAAQ,SAAS,iBAC5D,UAAU,MAAM,eAAe,OAAO;AAAA,YAE1C;AAAA,UACF,UAAE;AACA,qBAAS,QAAQ,sBAAsB;AAAA,UACzC;AAEA,mBAAS,QAAQ,qBAAqB,SAAS;AAAA;AAAA,MACjD;AAEA,uBAAU,GACV,SAAS,iBAAiB,SAAS,WAAW,EAAI,GAC3C,MAAM,SAAS,oBAAoB,SAAS,WAAW,EAAI;AAAA,IACpE;AAAA,EACF,GAAG,CAAC,MAAM,CAAC,GAGX,MAAM,UAAU,WAAY;AAC1B,QAAI,WAAW;AACb,UAAI,gCAAgC,SAAS;AAC7C,aAAO,WAAY;AACjB,QACE,iCACA,SAAS,SAAS,6BAA6B,KAE/C,UAAU,MAAM,6BAA6B;AAAA,MAEjD;AAAA,IACF;AAAA,EACF,GAAG,CAAC,CAAC,GACgB,sBAAM;AAAA,IACzB,MAAM;AAAA,IACN;AAAA,IACc,sBAAM,cAAc,cAAc,IAAI;AAAA,IACtC,sBAAM;AAAA,MAClB;AAAA,MACA;AAAA,QACE,KAAK;AAAA,MACP;AAAA,MACA;AAAA,IACF;AAAA,IACc,sBAAM,cAAc,cAAc,IAAI;AAAA,EACtD;AACF,GAEO,yBAAQ,gBACX,SAAS,WAAW,OAAO;AAAA,EAC7B,cAAc;AAAA,IACZ,cAAc;AAAA,EAChB;AACF,CAAC;",
|
|
5
|
-
"names": []
|
|
6
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { StyleSheet, UIManager, canUseDOM } from "@tamagui/react-native-web-internals";
|
|
3
|
-
import createElement from "../createElement/index.mjs";
|
|
4
|
-
import View from "../View";
|
|
5
|
-
var FocusBracket = () => createElement("div", {
|
|
6
|
-
accessibilityRole: "none",
|
|
7
|
-
tabIndex: 0,
|
|
8
|
-
style: styles.focusBracket
|
|
9
|
-
});
|
|
10
|
-
function attemptFocus(element) {
|
|
11
|
-
if (!canUseDOM) return !1;
|
|
12
|
-
try {
|
|
13
|
-
element.focus();
|
|
14
|
-
} catch {}
|
|
15
|
-
return document.activeElement === element;
|
|
16
|
-
}
|
|
17
|
-
function focusFirstDescendant(element) {
|
|
18
|
-
for (var i = 0; i < element.childNodes.length; i++) {
|
|
19
|
-
var child = element.childNodes[i];
|
|
20
|
-
if (attemptFocus(child) || focusFirstDescendant(child)) return !0;
|
|
21
|
-
}
|
|
22
|
-
return !1;
|
|
23
|
-
}
|
|
24
|
-
function focusLastDescendant(element) {
|
|
25
|
-
for (var i = element.childNodes.length - 1; i >= 0; i--) {
|
|
26
|
-
var child = element.childNodes[i];
|
|
27
|
-
if (attemptFocus(child) || focusLastDescendant(child)) return !0;
|
|
28
|
-
}
|
|
29
|
-
return !1;
|
|
30
|
-
}
|
|
31
|
-
var ModalFocusTrap = _ref => {
|
|
32
|
-
var active = _ref.active,
|
|
33
|
-
children = _ref.children,
|
|
34
|
-
trapElementRef = React.useRef(),
|
|
35
|
-
focusRef = React.useRef({
|
|
36
|
-
trapFocusInProgress: !1,
|
|
37
|
-
lastFocusedElement: null
|
|
38
|
-
});
|
|
39
|
-
return React.useEffect(() => {
|
|
40
|
-
if (canUseDOM) {
|
|
41
|
-
var trapFocus = () => {
|
|
42
|
-
if (!(trapElementRef.current == null || focusRef.current.trapFocusInProgress || !active)) {
|
|
43
|
-
try {
|
|
44
|
-
if (focusRef.current.trapFocusInProgress = !0, document.activeElement instanceof Node && !trapElementRef.current.contains(document.activeElement)) {
|
|
45
|
-
var hasFocused = focusFirstDescendant(trapElementRef.current);
|
|
46
|
-
focusRef.current.lastFocusedElement === document.activeElement && (hasFocused = focusLastDescendant(trapElementRef.current)), !hasFocused && trapElementRef.current != null && document.activeElement && UIManager.focus(trapElementRef.current);
|
|
47
|
-
}
|
|
48
|
-
} finally {
|
|
49
|
-
focusRef.current.trapFocusInProgress = !1;
|
|
50
|
-
}
|
|
51
|
-
focusRef.current.lastFocusedElement = document.activeElement;
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
return trapFocus(), document.addEventListener("focus", trapFocus, !0), () => document.removeEventListener("focus", trapFocus, !0);
|
|
55
|
-
}
|
|
56
|
-
}, [active]), React.useEffect(function () {
|
|
57
|
-
if (canUseDOM) {
|
|
58
|
-
var lastFocusedElementOutsideTrap = document.activeElement;
|
|
59
|
-
return function () {
|
|
60
|
-
lastFocusedElementOutsideTrap && document.contains(lastFocusedElementOutsideTrap) && UIManager.focus(lastFocusedElementOutsideTrap);
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
}, []), /* @__PURE__ */React.createElement(React.Fragment, null, /* @__PURE__ */React.createElement(FocusBracket, null), /* @__PURE__ */React.createElement(View, {
|
|
64
|
-
ref: trapElementRef
|
|
65
|
-
}, children), /* @__PURE__ */React.createElement(FocusBracket, null));
|
|
66
|
-
},
|
|
67
|
-
ModalFocusTrap_default = ModalFocusTrap,
|
|
68
|
-
styles = StyleSheet.create({
|
|
69
|
-
focusBracket: {
|
|
70
|
-
outlineStyle: "none"
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
export { ModalFocusTrap_default as default };
|
|
74
|
-
//# sourceMappingURL=ModalFocusTrap.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["React","StyleSheet","UIManager","canUseDOM","createElement","View","FocusBracket","accessibilityRole","tabIndex","style","styles","focusBracket","attemptFocus","element","focus","document","activeElement","focusFirstDescendant","i","childNodes","length","child","focusLastDescendant","ModalFocusTrap","_ref","active","children","trapElementRef","useRef","focusRef","trapFocusInProgress","lastFocusedElement","useEffect","trapFocus","current","Node","contains","hasFocused","addEventListener","removeEventListener","lastFocusedElementOutsideTrap","Fragment","ref","ModalFocusTrap_default","create","outlineSt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