@tamagui/adapt 1.130.8 → 1.131.0
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/Adapt.cjs +42 -34
- package/dist/cjs/Adapt.js +39 -24
- package/dist/cjs/Adapt.js.map +1 -1
- package/dist/cjs/Adapt.native.js +48 -33
- package/dist/cjs/Adapt.native.js.map +2 -2
- package/dist/cjs/index.cjs +1 -1
- package/dist/esm/Adapt.js +40 -25
- package/dist/esm/Adapt.js.map +1 -1
- package/dist/esm/Adapt.mjs +42 -34
- package/dist/esm/Adapt.mjs.map +1 -1
- package/dist/esm/Adapt.native.js +44 -38
- package/dist/esm/Adapt.native.js.map +1 -1
- package/package.json +7 -7
- package/src/Adapt.tsx +54 -48
- package/types/Adapt.d.ts +2 -1
- package/types/Adapt.d.ts.map +1 -1
package/dist/cjs/Adapt.cjs
CHANGED
|
@@ -41,15 +41,14 @@ __export(Adapt_exports, {
|
|
|
41
41
|
useAdaptIsActive: () => useAdaptIsActive
|
|
42
42
|
});
|
|
43
43
|
module.exports = __toCommonJS(Adapt_exports);
|
|
44
|
-
var
|
|
45
|
-
import_constants = require("@tamagui/constants"),
|
|
44
|
+
var import_constants = require("@tamagui/constants"),
|
|
46
45
|
import_core = require("@tamagui/core"),
|
|
47
46
|
import_helpers = require("@tamagui/helpers"),
|
|
48
47
|
import_portal = require("@tamagui/portal"),
|
|
48
|
+
import_z_index_stack = require("@tamagui/z-index-stack"),
|
|
49
49
|
import_react = __toESM(require("react")),
|
|
50
50
|
import_jsx_runtime = require("react/jsx-runtime");
|
|
51
|
-
const
|
|
52
|
-
AdaptContext = (0, import_core.createStyledContext)({
|
|
51
|
+
const AdaptContext = (0, import_core.createStyledContext)({
|
|
53
52
|
Contents: null,
|
|
54
53
|
scopeName: "",
|
|
55
54
|
portalName: "",
|
|
@@ -59,23 +58,27 @@ const CurrentAdaptContextScope = (0, import_react.createContext)(""),
|
|
|
59
58
|
setChildren: null,
|
|
60
59
|
setWhen: () => {}
|
|
61
60
|
}),
|
|
61
|
+
LastAdaptContextScope = (0, import_react.createContext)(""),
|
|
62
62
|
ProvideAdaptContext = ({
|
|
63
63
|
children,
|
|
64
64
|
...context
|
|
65
65
|
}) => {
|
|
66
|
-
const scope = context.scopeName || ""
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
const scope = context.scopeName || "",
|
|
67
|
+
lastScope = (0, import_react.useContext)(LastAdaptContextScope);
|
|
68
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(LastAdaptContextScope.Provider, {
|
|
69
|
+
value: lastScope || context.lastScope || "",
|
|
69
70
|
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(AdaptContext.Provider, {
|
|
70
71
|
scope,
|
|
72
|
+
lastScope: lastScope || context.lastScope,
|
|
71
73
|
...context,
|
|
72
74
|
children
|
|
73
75
|
})
|
|
74
76
|
});
|
|
75
77
|
},
|
|
76
|
-
useAdaptContext =
|
|
77
|
-
const
|
|
78
|
-
|
|
78
|
+
useAdaptContext = scope => {
|
|
79
|
+
const lastScope = (0, import_react.useContext)(LastAdaptContextScope),
|
|
80
|
+
adaptScope = scope ?? lastScope;
|
|
81
|
+
return AdaptContext.useStyledContext(adaptScope);
|
|
79
82
|
},
|
|
80
83
|
AdaptPortals = /* @__PURE__ */new Map(),
|
|
81
84
|
AdaptParent = ({
|
|
@@ -84,28 +87,36 @@ const CurrentAdaptContextScope = (0, import_react.createContext)(""),
|
|
|
84
87
|
scope,
|
|
85
88
|
portal
|
|
86
89
|
}) => {
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
90
|
+
const id = (0, import_react.useId)(),
|
|
91
|
+
portalName = `AdaptPortal${scope}${id}`,
|
|
92
|
+
FinalContents = (0, import_react.useMemo)(() => {
|
|
93
|
+
if (Contents) return Contents;
|
|
94
|
+
if (AdaptPortals.has(portalName)) return AdaptPortals.get(portalName);
|
|
95
|
+
const element = () => /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_portal.PortalHost, {
|
|
96
|
+
name: portalName,
|
|
97
|
+
forwardProps: typeof portal == "boolean" ? void 0 : portal?.forwardProps
|
|
98
|
+
}, id);
|
|
99
|
+
return AdaptPortals.set(portalName, element), element;
|
|
100
|
+
}, [portalName, Contents]);
|
|
101
|
+
(0, import_constants.useIsomorphicLayoutEffect)(() => (AdaptPortals.set(portalName, FinalContents), () => {
|
|
102
|
+
AdaptPortals.delete(portalName);
|
|
103
|
+
}), [portalName]);
|
|
96
104
|
const [when, setWhen] = import_react.default.useState(null),
|
|
97
105
|
[platform, setPlatform] = import_react.default.useState(null),
|
|
98
106
|
[children2, setChildren] = import_react.default.useState(null);
|
|
99
|
-
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(LastAdaptContextScope, {
|
|
108
|
+
value: scope,
|
|
109
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ProvideAdaptContext, {
|
|
110
|
+
Contents: FinalContents,
|
|
111
|
+
when,
|
|
112
|
+
platform,
|
|
113
|
+
setPlatform,
|
|
114
|
+
setWhen,
|
|
115
|
+
setChildren,
|
|
116
|
+
portalName,
|
|
117
|
+
scopeName: scope,
|
|
118
|
+
children
|
|
119
|
+
})
|
|
109
120
|
});
|
|
110
121
|
},
|
|
111
122
|
AdaptContents = ({
|
|
@@ -128,7 +139,6 @@ const Adapt = (0, import_helpers.withStaticProperties)(function (props) {
|
|
|
128
139
|
scope
|
|
129
140
|
} = props,
|
|
130
141
|
context = useAdaptContext(scope),
|
|
131
|
-
scopeName = scope ?? context.scopeName,
|
|
132
142
|
enabled = useAdaptIsActiveGiven(props);
|
|
133
143
|
(0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
134
144
|
context?.setWhen?.(when || enabled), context?.setPlatform?.(platform || null);
|
|
@@ -143,10 +153,7 @@ const Adapt = (0, import_helpers.withStaticProperties)(function (props) {
|
|
|
143
153
|
return (0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
144
154
|
typeof children == "function" && output !== void 0 && context?.setChildren(output);
|
|
145
155
|
}, [output]), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_z_index_stack.StackZIndexContext, {
|
|
146
|
-
children:
|
|
147
|
-
value: scopeName,
|
|
148
|
-
children: enabled ? output : null
|
|
149
|
-
})
|
|
156
|
+
children: enabled ? output : null
|
|
150
157
|
});
|
|
151
158
|
}, {
|
|
152
159
|
Contents: AdaptContents
|
|
@@ -168,6 +175,7 @@ const Adapt = (0, import_helpers.withStaticProperties)(function (props) {
|
|
|
168
175
|
}) => {
|
|
169
176
|
const media = (0, import_core.useMedia)();
|
|
170
177
|
if (when == null && platform == null) return !1;
|
|
178
|
+
if (when === !0) return !0;
|
|
171
179
|
let enabled = !1;
|
|
172
180
|
return platform === "touch" ? enabled = import_constants.isTouchable : platform === "native" ? enabled = !import_constants.isWeb : platform === "web" ? enabled = import_constants.isWeb : platform === "ios" ? enabled = import_constants.isIos : platform === "android" && (enabled = import_constants.isAndroid), platform && enabled == !1 ? !1 : (when && typeof when == "string" && (enabled = media[when]), enabled);
|
|
173
181
|
},
|
package/dist/cjs/Adapt.js
CHANGED
|
@@ -32,8 +32,8 @@ __export(Adapt_exports, {
|
|
|
32
32
|
useAdaptIsActive: () => useAdaptIsActive
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(Adapt_exports);
|
|
35
|
-
var
|
|
36
|
-
const
|
|
35
|
+
var import_constants = require("@tamagui/constants"), import_core = require("@tamagui/core"), import_helpers = require("@tamagui/helpers"), import_portal = require("@tamagui/portal"), import_z_index_stack = require("@tamagui/z-index-stack"), import_react = __toESM(require("react")), import_jsx_runtime = require("react/jsx-runtime");
|
|
36
|
+
const AdaptContext = (0, import_core.createStyledContext)({
|
|
37
37
|
Contents: null,
|
|
38
38
|
scopeName: "",
|
|
39
39
|
portalName: "",
|
|
@@ -44,31 +44,44 @@ const CurrentAdaptContextScope = (0, import_react.createContext)(""), AdaptConte
|
|
|
44
44
|
setChildren: null,
|
|
45
45
|
setWhen: () => {
|
|
46
46
|
}
|
|
47
|
-
}), ProvideAdaptContext = ({
|
|
47
|
+
}), LastAdaptContextScope = (0, import_react.createContext)(""), ProvideAdaptContext = ({
|
|
48
48
|
children,
|
|
49
49
|
...context
|
|
50
50
|
}) => {
|
|
51
|
-
const scope = context.scopeName || "";
|
|
52
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
53
|
-
|
|
54
|
-
const contextScope = (0, import_react.useContext)(CurrentAdaptContextScope);
|
|
55
|
-
return AdaptContext.useStyledContext(
|
|
56
|
-
scope === "" && contextScope || scope
|
|
57
|
-
);
|
|
58
|
-
}, AdaptPortals = /* @__PURE__ */ new Map(), AdaptParent = ({ children, Contents, scope, portal }) => {
|
|
59
|
-
const portalName = `AdaptPortal${scope}`, id = (0, import_react.useId)();
|
|
60
|
-
let FinalContents = Contents || AdaptPortals.get(id);
|
|
61
|
-
FinalContents || (FinalContents = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
62
|
-
import_portal.PortalHost,
|
|
51
|
+
const scope = context.scopeName || "", lastScope = (0, import_react.useContext)(LastAdaptContextScope);
|
|
52
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LastAdaptContextScope.Provider, { value: lastScope || context.lastScope || "", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
53
|
+
AdaptContext.Provider,
|
|
63
54
|
{
|
|
64
|
-
|
|
65
|
-
|
|
55
|
+
scope,
|
|
56
|
+
lastScope: lastScope || context.lastScope,
|
|
57
|
+
...context,
|
|
58
|
+
children
|
|
66
59
|
}
|
|
67
|
-
)
|
|
68
|
-
|
|
69
|
-
|
|
60
|
+
) });
|
|
61
|
+
}, useAdaptContext = (scope) => {
|
|
62
|
+
const lastScope = (0, import_react.useContext)(LastAdaptContextScope), adaptScope = scope ?? lastScope;
|
|
63
|
+
return AdaptContext.useStyledContext(adaptScope);
|
|
64
|
+
}, AdaptPortals = /* @__PURE__ */ new Map(), AdaptParent = ({ children, Contents, scope, portal }) => {
|
|
65
|
+
const id = (0, import_react.useId)(), portalName = `AdaptPortal${scope}${id}`, FinalContents = (0, import_react.useMemo)(() => {
|
|
66
|
+
if (Contents)
|
|
67
|
+
return Contents;
|
|
68
|
+
if (AdaptPortals.has(portalName))
|
|
69
|
+
return AdaptPortals.get(portalName);
|
|
70
|
+
const element = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
71
|
+
import_portal.PortalHost,
|
|
72
|
+
{
|
|
73
|
+
name: portalName,
|
|
74
|
+
forwardProps: typeof portal == "boolean" ? void 0 : portal?.forwardProps
|
|
75
|
+
},
|
|
76
|
+
id
|
|
77
|
+
);
|
|
78
|
+
return AdaptPortals.set(portalName, element), element;
|
|
79
|
+
}, [portalName, Contents]);
|
|
80
|
+
(0, import_constants.useIsomorphicLayoutEffect)(() => (AdaptPortals.set(portalName, FinalContents), () => {
|
|
81
|
+
AdaptPortals.delete(portalName);
|
|
82
|
+
}), [portalName]);
|
|
70
83
|
const [when, setWhen] = import_react.default.useState(null), [platform, setPlatform] = import_react.default.useState(null), [children2, setChildren] = import_react.default.useState(null);
|
|
71
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
84
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LastAdaptContextScope, { value: scope, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
72
85
|
ProvideAdaptContext,
|
|
73
86
|
{
|
|
74
87
|
Contents: FinalContents,
|
|
@@ -81,7 +94,7 @@ const CurrentAdaptContextScope = (0, import_react.createContext)(""), AdaptConte
|
|
|
81
94
|
scopeName: scope,
|
|
82
95
|
children
|
|
83
96
|
}
|
|
84
|
-
);
|
|
97
|
+
) });
|
|
85
98
|
}, AdaptContents = ({ scope, ...rest }) => {
|
|
86
99
|
const context = useAdaptContext(scope);
|
|
87
100
|
if (!context?.Contents)
|
|
@@ -93,7 +106,7 @@ const CurrentAdaptContextScope = (0, import_react.createContext)(""), AdaptConte
|
|
|
93
106
|
AdaptContents.shouldForwardSpace = !0;
|
|
94
107
|
const Adapt = (0, import_helpers.withStaticProperties)(
|
|
95
108
|
function(props) {
|
|
96
|
-
const { platform, when, children, scope } = props, context = useAdaptContext(scope),
|
|
109
|
+
const { platform, when, children, scope } = props, context = useAdaptContext(scope), enabled = useAdaptIsActiveGiven(props);
|
|
97
110
|
(0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
98
111
|
context?.setWhen?.(when || enabled), context?.setPlatform?.(platform || null);
|
|
99
112
|
}, [when, platform, enabled, context.setWhen, context.setPlatform]), (0, import_constants.useIsomorphicLayoutEffect)(() => () => {
|
|
@@ -107,7 +120,7 @@ const Adapt = (0, import_helpers.withStaticProperties)(
|
|
|
107
120
|
output = children;
|
|
108
121
|
return (0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
109
122
|
typeof children == "function" && output !== void 0 && context?.setChildren(output);
|
|
110
|
-
}, [output]), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_z_index_stack.StackZIndexContext, { children:
|
|
123
|
+
}, [output]), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_z_index_stack.StackZIndexContext, { children: enabled ? output : null });
|
|
111
124
|
},
|
|
112
125
|
{
|
|
113
126
|
Contents: AdaptContents
|
|
@@ -122,6 +135,8 @@ const Adapt = (0, import_helpers.withStaticProperties)(
|
|
|
122
135
|
const media = (0, import_core.useMedia)();
|
|
123
136
|
if (when == null && platform == null)
|
|
124
137
|
return !1;
|
|
138
|
+
if (when === !0)
|
|
139
|
+
return !0;
|
|
125
140
|
let enabled = !1;
|
|
126
141
|
return platform === "touch" ? enabled = import_constants.isTouchable : platform === "native" ? enabled = !import_constants.isWeb : platform === "web" ? enabled = import_constants.isWeb : platform === "ios" ? enabled = import_constants.isIos : platform === "android" && (enabled = import_constants.isAndroid), platform && enabled == !1 ? !1 : (when && typeof when == "string" && (enabled = media[when]), enabled);
|
|
127
142
|
}, useAdaptIsActive = (scope) => {
|
package/dist/cjs/Adapt.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Adapt.tsx"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAMO,+BAEP,cAA8C,0BAC9C,iBAAqC,6BACrC,gBAAuC,4BACvC,uBAAmC,mCACnC,eAAiE,2BAsD3D;AAtBC,MAAM,mBAAe,iCAAyC;AAAA,EACnE,UAAU;AAAA,EACV,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,UAAU;AAAA,EACV,aAAa,CAAC,MAAqB;AAAA,EAAC;AAAA,EACpC,MAAM;AAAA,EACN,aAAa;AAAA,EACb,SAAS,MAAM;AAAA,EAAC;AAClB,CAAC,GAEK,4BAAwB,4BAAc,EAAE,GAEjC,sBAAsB,CAAC;AAAA,EAClC;AAAA,EACA,GAAG;AACL,MAA+C;AAC7C,QAAM,QAAQ,QAAQ,aAAa,IAC7B,gBAAY,yBAAW,qBAAqB;AAElD,SACE,4CAAC,sBAAsB,UAAtB,EAA+B,OAAO,aAAa,QAAQ,aAAa,IACvE;AAAA,IAAC,aAAa;AAAA,IAAb;AAAA,MACC;AAAA,MACA,WAAW,aAAa,QAAQ;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,QAAM,YAAQ,sBAAS;AAEvB,MAAI,QAAQ,QAAQ,YAAY;AAC9B,WAAO;AAGT,MAAI,SAAS;AACX,WAAO;AAGT,MAAI,UAAU;AAQd,SANI,aAAa,UAAS,UAAU,+BAC3B,aAAa,WAAU,UAAU,CAAC,yBAClC,aAAa,QAAO,UAAU,yBAC9B,aAAa,QAAO,UAAU,yBAC9B,aAAa,cAAW,UAAU,6BAEvC,YAAY,WAAW,KAClB,MAGL,QAAQ,OAAO,QAAS,aAC1B,UAAU,MAAM,IAAI,IAGf;AACT,GAEa,mBAAmB,CAAC,UAAmB;AAClD,QAAM,QAAQ,gBAAgB,KAAK;AACnC,SAAO,sBAAsB,KAAK;AACpC;",
|
|
5
5
|
"names": ["React"]
|
|
6
6
|
}
|
package/dist/cjs/Adapt.native.js
CHANGED
|
@@ -33,7 +33,7 @@ __export(Adapt_exports, {
|
|
|
33
33
|
useAdaptIsActive: () => useAdaptIsActive
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(Adapt_exports);
|
|
36
|
-
var import_jsx_runtime = require("react/jsx-runtime"),
|
|
36
|
+
var import_jsx_runtime = require("react/jsx-runtime"), import_constants = require("@tamagui/constants"), import_core = require("@tamagui/core"), import_helpers = require("@tamagui/helpers"), import_portal = require("@tamagui/portal"), import_z_index_stack = require("@tamagui/z-index-stack"), import_react = __toESM(require("react")), AdaptContext = (0, import_core.createStyledContext)({
|
|
37
37
|
Contents: null,
|
|
38
38
|
scopeName: "",
|
|
39
39
|
portalName: "",
|
|
@@ -44,42 +44,58 @@ var import_jsx_runtime = require("react/jsx-runtime"), import_z_index_stack = re
|
|
|
44
44
|
setChildren: null,
|
|
45
45
|
setWhen: function() {
|
|
46
46
|
}
|
|
47
|
-
}), ProvideAdaptContext = function(param) {
|
|
48
|
-
var { children, ...context } = param, scope = context.scopeName || "";
|
|
49
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
50
|
-
value:
|
|
47
|
+
}), LastAdaptContextScope = /* @__PURE__ */ (0, import_react.createContext)(""), ProvideAdaptContext = function(param) {
|
|
48
|
+
var { children, ...context } = param, scope = context.scopeName || "", lastScope = (0, import_react.useContext)(LastAdaptContextScope);
|
|
49
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LastAdaptContextScope.Provider, {
|
|
50
|
+
value: lastScope || context.lastScope || "",
|
|
51
51
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AdaptContext.Provider, {
|
|
52
52
|
scope,
|
|
53
|
+
lastScope: lastScope || context.lastScope,
|
|
53
54
|
...context,
|
|
54
55
|
children
|
|
55
56
|
})
|
|
56
57
|
});
|
|
57
|
-
}, useAdaptContext = function() {
|
|
58
|
-
var
|
|
59
|
-
return
|
|
58
|
+
}, useAdaptContext = function(scope) {
|
|
59
|
+
var lastScope = (0, import_react.useContext)(LastAdaptContextScope), adaptScope = scope ?? lastScope;
|
|
60
|
+
return AdaptContext.useStyledContext(adaptScope);
|
|
60
61
|
}, AdaptPortals = /* @__PURE__ */ new Map(), AdaptParent = function(param) {
|
|
61
|
-
var { children, Contents, scope, portal } = param, portalName = `AdaptPortal${scope}`,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
var { children, Contents, scope, portal } = param, id = (0, import_react.useId)(), portalName = `AdaptPortal${scope}${id}`, FinalContents = (0, import_react.useMemo)(function() {
|
|
63
|
+
if (Contents)
|
|
64
|
+
return Contents;
|
|
65
|
+
if (AdaptPortals.has(portalName))
|
|
66
|
+
return AdaptPortals.get(portalName);
|
|
67
|
+
var element = function() {
|
|
68
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_portal.PortalHost, {
|
|
69
|
+
name: portalName,
|
|
70
|
+
forwardProps: typeof portal == "boolean" || portal == null ? void 0 : portal.forwardProps
|
|
71
|
+
}, id);
|
|
70
72
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ProvideAdaptContext, {
|
|
74
|
-
Contents: FinalContents,
|
|
75
|
-
when,
|
|
76
|
-
platform,
|
|
77
|
-
setPlatform,
|
|
78
|
-
setWhen,
|
|
79
|
-
setChildren,
|
|
73
|
+
return AdaptPortals.set(portalName, element), element;
|
|
74
|
+
}, [
|
|
80
75
|
portalName,
|
|
81
|
-
|
|
82
|
-
|
|
76
|
+
Contents
|
|
77
|
+
]);
|
|
78
|
+
(0, import_constants.useIsomorphicLayoutEffect)(function() {
|
|
79
|
+
return AdaptPortals.set(portalName, FinalContents), function() {
|
|
80
|
+
AdaptPortals.delete(portalName);
|
|
81
|
+
};
|
|
82
|
+
}, [
|
|
83
|
+
portalName
|
|
84
|
+
]);
|
|
85
|
+
var [when, setWhen] = import_react.default.useState(null), [platform, setPlatform] = import_react.default.useState(null), [children2, setChildren] = import_react.default.useState(null);
|
|
86
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LastAdaptContextScope, {
|
|
87
|
+
value: scope,
|
|
88
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ProvideAdaptContext, {
|
|
89
|
+
Contents: FinalContents,
|
|
90
|
+
when,
|
|
91
|
+
platform,
|
|
92
|
+
setPlatform,
|
|
93
|
+
setWhen,
|
|
94
|
+
setChildren,
|
|
95
|
+
portalName,
|
|
96
|
+
scopeName: scope,
|
|
97
|
+
children
|
|
98
|
+
})
|
|
83
99
|
});
|
|
84
100
|
}, AdaptContents = function(param) {
|
|
85
101
|
var { scope, ...rest } = param, context = useAdaptContext(scope);
|
|
@@ -92,7 +108,7 @@ var import_jsx_runtime = require("react/jsx-runtime"), import_z_index_stack = re
|
|
|
92
108
|
};
|
|
93
109
|
AdaptContents.shouldForwardSpace = !0;
|
|
94
110
|
var Adapt = (0, import_helpers.withStaticProperties)(function(props) {
|
|
95
|
-
var { platform, when, children, scope } = props, context = useAdaptContext(scope),
|
|
111
|
+
var { platform, when, children, scope } = props, context = useAdaptContext(scope), enabled = useAdaptIsActiveGiven(props);
|
|
96
112
|
(0, import_constants.useIsomorphicLayoutEffect)(function() {
|
|
97
113
|
var _context_setWhen, _context_setPlatform;
|
|
98
114
|
context == null || (_context_setWhen = context.setWhen) === null || _context_setWhen === void 0 || _context_setWhen.call(context, when || enabled), context == null || (_context_setPlatform = context.setPlatform) === null || _context_setPlatform === void 0 || _context_setPlatform.call(context, platform || null);
|
|
@@ -119,10 +135,7 @@ var Adapt = (0, import_helpers.withStaticProperties)(function(props) {
|
|
|
119
135
|
}, [
|
|
120
136
|
output
|
|
121
137
|
]), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_z_index_stack.StackZIndexContext, {
|
|
122
|
-
children:
|
|
123
|
-
value: scopeName,
|
|
124
|
-
children: enabled ? output : null
|
|
125
|
-
})
|
|
138
|
+
children: enabled ? output : null
|
|
126
139
|
});
|
|
127
140
|
}, {
|
|
128
141
|
Contents: AdaptContents
|
|
@@ -137,6 +150,8 @@ var Adapt = (0, import_helpers.withStaticProperties)(function(props) {
|
|
|
137
150
|
var { when, platform } = param, media = (0, import_core.useMedia)();
|
|
138
151
|
if (when == null && platform == null)
|
|
139
152
|
return !1;
|
|
153
|
+
if (when === !0)
|
|
154
|
+
return !0;
|
|
140
155
|
var enabled = !1;
|
|
141
156
|
return platform === "touch" ? enabled = import_constants.isTouchable : platform === "native" ? enabled = !import_constants.isWeb : platform === "web" ? enabled = import_constants.isWeb : platform === "ios" ? enabled = import_constants.isIos : platform === "android" && (enabled = import_constants.isAndroid), platform && enabled == !1 ? !1 : (when && typeof when == "string" && (enabled = media[when]), enabled);
|
|
142
157
|
}, useAdaptIsActive = function(scope) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Adapt.tsx"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uDA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AA;AAEd,MAAI9D,QAAQ,QAAQH,YAAY;AAC9B,WAAO;AAGT,MAAIG,SAAS;AACX,WAAO;AAGT,MAAIkD,UAAU;AAQd,SANIrD,aAAa,UAASqD,UAAUa,+BAC3BlE,aAAa,WAAUqD,UAAU,CAACc,yBAClCnE,aAAa,QAAOqD,UAAUc,yBAC9BnE,aAAa,QAAOqD,UAAUe,yBAC9BpE,aAAa,cAAWqD,UAAUgB,6BAEvCrE,YAAYqD,WAAW,KAClB,MAGLlD,QAAQ,OAAOA,QAAS,aAC1BkD,UAAUW,MAAM7D,IAAAA,IAGXkD;AACT,GAEaO,mBAAmB,SAACjD,OAAAA;AAC/B,MAAMyC,QAAQnC,gBAAgBN,KAAAA;AAC9B,SAAO2C,sBAAsBF,KAAAA;AAC/B;",
|
|
5
|
+
"names": ["AdaptContext", "createStyledContext", "Contents", "scopeName", "portalName", "platform", "setPlatform", "x", "when", "setChildren", "setWhen", "LastAdaptContextScope", "createContext", "ProvideAdaptContext", "children", "context", "scope", "lastScope", "useContext", "_jsx", "Provider", "value", "useAdaptContext", "adaptScope", "useStyledContext", "AdaptPortals", "Map", "AdaptParent", "portal", "id", "useId", "FinalContents", "useMemo", "has", "get", "element", "PortalHost", "name", "forwardProps", "undefined", "set", "useIsomorphicLayoutEffect", "delete", "React", "useState", "children2", "AdaptContents", "rest", "Error", "process", "env", "NODE_ENV", "createElement", "key", "shouldForwardSpace", "Adapt", "withStaticProperties", "props", "enabled", "useAdaptIsActiveGiven", "output", "Component", "StackZIndexContext", "AdaptPortalContents", "isActive", "useAdaptIsActive", "PortalItem", "passThrough", "hostName", "media", "useMedia", "isTouchable", "isWeb", "isIos", "isAndroid"]
|
|
6
6
|
}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -15,4 +15,4 @@ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
|
15
15
|
}), mod);
|
|
16
16
|
var index_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(index_exports);
|
|
18
|
-
__reExport(index_exports, require("./Adapt"), module.exports);
|
|
18
|
+
__reExport(index_exports, require("./Adapt.cjs"), module.exports);
|
package/dist/esm/Adapt.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { StackZIndexContext } from "@tamagui/z-index-stack";
|
|
2
1
|
import {
|
|
3
2
|
isAndroid,
|
|
4
3
|
isIos,
|
|
@@ -9,9 +8,10 @@ import {
|
|
|
9
8
|
import { createStyledContext, useMedia } from "@tamagui/core";
|
|
10
9
|
import { withStaticProperties } from "@tamagui/helpers";
|
|
11
10
|
import { PortalHost, PortalItem } from "@tamagui/portal";
|
|
12
|
-
import
|
|
11
|
+
import { StackZIndexContext } from "@tamagui/z-index-stack";
|
|
12
|
+
import React, { createContext, useContext, useId, useMemo } from "react";
|
|
13
13
|
import { jsx } from "react/jsx-runtime";
|
|
14
|
-
const
|
|
14
|
+
const AdaptContext = createStyledContext({
|
|
15
15
|
Contents: null,
|
|
16
16
|
scopeName: "",
|
|
17
17
|
portalName: "",
|
|
@@ -22,31 +22,44 @@ const CurrentAdaptContextScope = createContext(""), AdaptContext = createStyledC
|
|
|
22
22
|
setChildren: null,
|
|
23
23
|
setWhen: () => {
|
|
24
24
|
}
|
|
25
|
-
}), ProvideAdaptContext = ({
|
|
25
|
+
}), LastAdaptContextScope = createContext(""), ProvideAdaptContext = ({
|
|
26
26
|
children,
|
|
27
27
|
...context
|
|
28
28
|
}) => {
|
|
29
|
-
const scope = context.scopeName || "";
|
|
30
|
-
return /* @__PURE__ */ jsx(
|
|
31
|
-
|
|
32
|
-
const contextScope = useContext(CurrentAdaptContextScope);
|
|
33
|
-
return AdaptContext.useStyledContext(
|
|
34
|
-
scope === "" && contextScope || scope
|
|
35
|
-
);
|
|
36
|
-
}, AdaptPortals = /* @__PURE__ */ new Map(), AdaptParent = ({ children, Contents, scope, portal }) => {
|
|
37
|
-
const portalName = `AdaptPortal${scope}`, id = useId();
|
|
38
|
-
let FinalContents = Contents || AdaptPortals.get(id);
|
|
39
|
-
FinalContents || (FinalContents = () => /* @__PURE__ */ jsx(
|
|
40
|
-
PortalHost,
|
|
29
|
+
const scope = context.scopeName || "", lastScope = useContext(LastAdaptContextScope);
|
|
30
|
+
return /* @__PURE__ */ jsx(LastAdaptContextScope.Provider, { value: lastScope || context.lastScope || "", children: /* @__PURE__ */ jsx(
|
|
31
|
+
AdaptContext.Provider,
|
|
41
32
|
{
|
|
42
|
-
|
|
43
|
-
|
|
33
|
+
scope,
|
|
34
|
+
lastScope: lastScope || context.lastScope,
|
|
35
|
+
...context,
|
|
36
|
+
children
|
|
44
37
|
}
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
) });
|
|
39
|
+
}, useAdaptContext = (scope) => {
|
|
40
|
+
const lastScope = useContext(LastAdaptContextScope), adaptScope = scope ?? lastScope;
|
|
41
|
+
return AdaptContext.useStyledContext(adaptScope);
|
|
42
|
+
}, AdaptPortals = /* @__PURE__ */ new Map(), AdaptParent = ({ children, Contents, scope, portal }) => {
|
|
43
|
+
const id = useId(), portalName = `AdaptPortal${scope}${id}`, FinalContents = useMemo(() => {
|
|
44
|
+
if (Contents)
|
|
45
|
+
return Contents;
|
|
46
|
+
if (AdaptPortals.has(portalName))
|
|
47
|
+
return AdaptPortals.get(portalName);
|
|
48
|
+
const element = () => /* @__PURE__ */ jsx(
|
|
49
|
+
PortalHost,
|
|
50
|
+
{
|
|
51
|
+
name: portalName,
|
|
52
|
+
forwardProps: typeof portal == "boolean" ? void 0 : portal?.forwardProps
|
|
53
|
+
},
|
|
54
|
+
id
|
|
55
|
+
);
|
|
56
|
+
return AdaptPortals.set(portalName, element), element;
|
|
57
|
+
}, [portalName, Contents]);
|
|
58
|
+
useIsomorphicLayoutEffect(() => (AdaptPortals.set(portalName, FinalContents), () => {
|
|
59
|
+
AdaptPortals.delete(portalName);
|
|
60
|
+
}), [portalName]);
|
|
48
61
|
const [when, setWhen] = React.useState(null), [platform, setPlatform] = React.useState(null), [children2, setChildren] = React.useState(null);
|
|
49
|
-
return /* @__PURE__ */ jsx(
|
|
62
|
+
return /* @__PURE__ */ jsx(LastAdaptContextScope, { value: scope, children: /* @__PURE__ */ jsx(
|
|
50
63
|
ProvideAdaptContext,
|
|
51
64
|
{
|
|
52
65
|
Contents: FinalContents,
|
|
@@ -59,7 +72,7 @@ const CurrentAdaptContextScope = createContext(""), AdaptContext = createStyledC
|
|
|
59
72
|
scopeName: scope,
|
|
60
73
|
children
|
|
61
74
|
}
|
|
62
|
-
);
|
|
75
|
+
) });
|
|
63
76
|
}, AdaptContents = ({ scope, ...rest }) => {
|
|
64
77
|
const context = useAdaptContext(scope);
|
|
65
78
|
if (!context?.Contents)
|
|
@@ -71,7 +84,7 @@ const CurrentAdaptContextScope = createContext(""), AdaptContext = createStyledC
|
|
|
71
84
|
AdaptContents.shouldForwardSpace = !0;
|
|
72
85
|
const Adapt = withStaticProperties(
|
|
73
86
|
function(props) {
|
|
74
|
-
const { platform, when, children, scope } = props, context = useAdaptContext(scope),
|
|
87
|
+
const { platform, when, children, scope } = props, context = useAdaptContext(scope), enabled = useAdaptIsActiveGiven(props);
|
|
75
88
|
useIsomorphicLayoutEffect(() => {
|
|
76
89
|
context?.setWhen?.(when || enabled), context?.setPlatform?.(platform || null);
|
|
77
90
|
}, [when, platform, enabled, context.setWhen, context.setPlatform]), useIsomorphicLayoutEffect(() => () => {
|
|
@@ -85,7 +98,7 @@ const Adapt = withStaticProperties(
|
|
|
85
98
|
output = children;
|
|
86
99
|
return useIsomorphicLayoutEffect(() => {
|
|
87
100
|
typeof children == "function" && output !== void 0 && context?.setChildren(output);
|
|
88
|
-
}, [output]), /* @__PURE__ */ jsx(StackZIndexContext, { children:
|
|
101
|
+
}, [output]), /* @__PURE__ */ jsx(StackZIndexContext, { children: enabled ? output : null });
|
|
89
102
|
},
|
|
90
103
|
{
|
|
91
104
|
Contents: AdaptContents
|
|
@@ -100,6 +113,8 @@ const Adapt = withStaticProperties(
|
|
|
100
113
|
const media = useMedia();
|
|
101
114
|
if (when == null && platform == null)
|
|
102
115
|
return !1;
|
|
116
|
+
if (when === !0)
|
|
117
|
+
return !0;
|
|
103
118
|
let enabled = !1;
|
|
104
119
|
return platform === "touch" ? enabled = isTouchable : platform === "native" ? enabled = !isWeb : platform === "web" ? enabled = isWeb : platform === "ios" ? enabled = isIos : platform === "android" && (enabled = isAndroid), platform && enabled == !1 ? !1 : (when && typeof when == "string" && (enabled = media[when]), enabled);
|
|
105
120
|
}, useAdaptIsActive = (scope) => {
|
package/dist/esm/Adapt.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Adapt.tsx"],
|
|
4
|
-
"mappings": "AAAA
|
|
4
|
+
"mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,qBAAqB,gBAAgB;AAC9C,SAAS,4BAA4B;AACrC,SAAS,YAAY,kBAAkB;AACvC,SAAS,0BAA0B;AACnC,OAAO,SAAS,eAAe,YAAY,OAAO,eAAe;AAsD3D;AAtBC,MAAM,eAAe,oBAAyC;AAAA,EACnE,UAAU;AAAA,EACV,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,UAAU;AAAA,EACV,aAAa,CAAC,MAAqB;AAAA,EAAC;AAAA,EACpC,MAAM;AAAA,EACN,aAAa;AAAA,EACb,SAAS,MAAM;AAAA,EAAC;AAClB,CAAC,GAEK,wBAAwB,cAAc,EAAE,GAEjC,sBAAsB,CAAC;AAAA,EAClC;AAAA,EACA,GAAG;AACL,MAA+C;AAC7C,QAAM,QAAQ,QAAQ,aAAa,IAC7B,YAAY,WAAW,qBAAqB;AAElD,SACE,oBAAC,sBAAsB,UAAtB,EAA+B,OAAO,aAAa,QAAQ,aAAa,IACvE;AAAA,IAAC,aAAa;AAAA,IAAb;AAAA,MACC;AAAA,MACA,WAAW,aAAa,QAAQ;A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AQ,QAAQ,YAAY;AAC9B,WAAO;AAGT,MAAI,SAAS;AACX,WAAO;AAGT,MAAI,UAAU;AAQd,SANI,aAAa,UAAS,UAAU,cAC3B,aAAa,WAAU,UAAU,CAAC,QAClC,aAAa,QAAO,UAAU,QAC9B,aAAa,QAAO,UAAU,QAC9B,aAAa,cAAW,UAAU,YAEvC,YAAY,WAAW,KAClB,MAGL,QAAQ,OAAO,QAAS,aAC1B,UAAU,MAAM,IAAI,IAGf;AACT,GAEa,mBAAmB,CAAC,UAAmB;AAClD,QAAM,QAAQ,gBAAgB,KAAK;AACnC,SAAO,sBAAsB,KAAK;AACpC;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/dist/esm/Adapt.mjs
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { StackZIndexContext } from "@tamagui/z-index-stack";
|
|
2
1
|
import { isAndroid, isIos, isTouchable, isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
3
2
|
import { createStyledContext, useMedia } from "@tamagui/core";
|
|
4
3
|
import { withStaticProperties } from "@tamagui/helpers";
|
|
5
4
|
import { PortalHost, PortalItem } from "@tamagui/portal";
|
|
6
|
-
import
|
|
5
|
+
import { StackZIndexContext } from "@tamagui/z-index-stack";
|
|
6
|
+
import React, { createContext, useContext, useId, useMemo } from "react";
|
|
7
7
|
import { jsx } from "react/jsx-runtime";
|
|
8
|
-
const
|
|
9
|
-
AdaptContext = createStyledContext({
|
|
8
|
+
const AdaptContext = createStyledContext({
|
|
10
9
|
Contents: null,
|
|
11
10
|
scopeName: "",
|
|
12
11
|
portalName: "",
|
|
@@ -16,23 +15,27 @@ const CurrentAdaptContextScope = createContext(""),
|
|
|
16
15
|
setChildren: null,
|
|
17
16
|
setWhen: () => {}
|
|
18
17
|
}),
|
|
18
|
+
LastAdaptContextScope = createContext(""),
|
|
19
19
|
ProvideAdaptContext = ({
|
|
20
20
|
children,
|
|
21
21
|
...context
|
|
22
22
|
}) => {
|
|
23
|
-
const scope = context.scopeName || ""
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
const scope = context.scopeName || "",
|
|
24
|
+
lastScope = useContext(LastAdaptContextScope);
|
|
25
|
+
return /* @__PURE__ */jsx(LastAdaptContextScope.Provider, {
|
|
26
|
+
value: lastScope || context.lastScope || "",
|
|
26
27
|
children: /* @__PURE__ */jsx(AdaptContext.Provider, {
|
|
27
28
|
scope,
|
|
29
|
+
lastScope: lastScope || context.lastScope,
|
|
28
30
|
...context,
|
|
29
31
|
children
|
|
30
32
|
})
|
|
31
33
|
});
|
|
32
34
|
},
|
|
33
|
-
useAdaptContext =
|
|
34
|
-
const
|
|
35
|
-
|
|
35
|
+
useAdaptContext = scope => {
|
|
36
|
+
const lastScope = useContext(LastAdaptContextScope),
|
|
37
|
+
adaptScope = scope ?? lastScope;
|
|
38
|
+
return AdaptContext.useStyledContext(adaptScope);
|
|
36
39
|
},
|
|
37
40
|
AdaptPortals = /* @__PURE__ */new Map(),
|
|
38
41
|
AdaptParent = ({
|
|
@@ -41,28 +44,36 @@ const CurrentAdaptContextScope = createContext(""),
|
|
|
41
44
|
scope,
|
|
42
45
|
portal
|
|
43
46
|
}) => {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
const id = useId(),
|
|
48
|
+
portalName = `AdaptPortal${scope}${id}`,
|
|
49
|
+
FinalContents = useMemo(() => {
|
|
50
|
+
if (Contents) return Contents;
|
|
51
|
+
if (AdaptPortals.has(portalName)) return AdaptPortals.get(portalName);
|
|
52
|
+
const element = () => /* @__PURE__ */jsx(PortalHost, {
|
|
53
|
+
name: portalName,
|
|
54
|
+
forwardProps: typeof portal == "boolean" ? void 0 : portal?.forwardProps
|
|
55
|
+
}, id);
|
|
56
|
+
return AdaptPortals.set(portalName, element), element;
|
|
57
|
+
}, [portalName, Contents]);
|
|
58
|
+
useIsomorphicLayoutEffect(() => (AdaptPortals.set(portalName, FinalContents), () => {
|
|
59
|
+
AdaptPortals.delete(portalName);
|
|
60
|
+
}), [portalName]);
|
|
53
61
|
const [when, setWhen] = React.useState(null),
|
|
54
62
|
[platform, setPlatform] = React.useState(null),
|
|
55
63
|
[children2, setChildren] = React.useState(null);
|
|
56
|
-
return /* @__PURE__ */jsx(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
return /* @__PURE__ */jsx(LastAdaptContextScope, {
|
|
65
|
+
value: scope,
|
|
66
|
+
children: /* @__PURE__ */jsx(ProvideAdaptContext, {
|
|
67
|
+
Contents: FinalContents,
|
|
68
|
+
when,
|
|
69
|
+
platform,
|
|
70
|
+
setPlatform,
|
|
71
|
+
setWhen,
|
|
72
|
+
setChildren,
|
|
73
|
+
portalName,
|
|
74
|
+
scopeName: scope,
|
|
75
|
+
children
|
|
76
|
+
})
|
|
66
77
|
});
|
|
67
78
|
},
|
|
68
79
|
AdaptContents = ({
|
|
@@ -85,7 +96,6 @@ const Adapt = withStaticProperties(function (props) {
|
|
|
85
96
|
scope
|
|
86
97
|
} = props,
|
|
87
98
|
context = useAdaptContext(scope),
|
|
88
|
-
scopeName = scope ?? context.scopeName,
|
|
89
99
|
enabled = useAdaptIsActiveGiven(props);
|
|
90
100
|
useIsomorphicLayoutEffect(() => {
|
|
91
101
|
context?.setWhen?.(when || enabled), context?.setPlatform?.(platform || null);
|
|
@@ -100,10 +110,7 @@ const Adapt = withStaticProperties(function (props) {
|
|
|
100
110
|
return useIsomorphicLayoutEffect(() => {
|
|
101
111
|
typeof children == "function" && output !== void 0 && context?.setChildren(output);
|
|
102
112
|
}, [output]), /* @__PURE__ */jsx(StackZIndexContext, {
|
|
103
|
-
children:
|
|
104
|
-
value: scopeName,
|
|
105
|
-
children: enabled ? output : null
|
|
106
|
-
})
|
|
113
|
+
children: enabled ? output : null
|
|
107
114
|
});
|
|
108
115
|
}, {
|
|
109
116
|
Contents: AdaptContents
|
|
@@ -125,6 +132,7 @@ const Adapt = withStaticProperties(function (props) {
|
|
|
125
132
|
}) => {
|
|
126
133
|
const media = useMedia();
|
|
127
134
|
if (when == null && platform == null) return !1;
|
|
135
|
+
if (when === !0) return !0;
|
|
128
136
|
let enabled = !1;
|
|
129
137
|
return platform === "touch" ? enabled = isTouchable : platform === "native" ? enabled = !isWeb : platform === "web" ? enabled = isWeb : platform === "ios" ? enabled = isIos : platform === "android" && (enabled = isAndroid), platform && enabled == !1 ? !1 : (when && typeof when == "string" && (enabled = media[when]), enabled);
|
|
130
138
|
},
|
package/dist/esm/Adapt.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["isAndroid","isIos","isTouchable","isWeb","useIsomorphicLayoutEffect","createStyledContext","useMedia","withStaticProperties","PortalHost","PortalItem","StackZIndexContext","React","createContext","useContext","useId","useMemo","jsx","AdaptContext","Contents","scopeName","portalName","platform","setPlatform","x","when","setChildren","setWhen","LastAdaptContextScope","ProvideAdaptContext","children","context","scope","lastScope","Provider","value","useAdaptContext","adaptScope","useStyledContext","AdaptPortals","Map","AdaptParent","portal","id","FinalContents","has","get","element","name","forwardProps","set","delete","useState","children2","AdaptContents","rest","Error","process","env","NODE_ENV","createElement","key","shouldForwardSpace","Adapt","props","enabled","useAdaptIsActiveGiven","output","Component","AdaptPortalContents","isActive","useAdaptIsActive","passThrough","hostName","media"],"sources":["../../src/Adapt.tsx"],"sourcesContent":[null],"mappings":"AAAA,SACEA,SAAA,EACAC,KAAA,EACAC,WAAA,EACAC,KAAA,EACAC,yBAAA,QACK;AAEP,SAASC,mBAAA,EAAqBC,QAAA,QAAgB;AAC9C,SAASC,oBAAA,QAA4B;AACrC,SAASC,UAAA,EAAYC,UAAA,QAAkB;AACvC,SAASC,kBAAA,QAA0B;AACnC,OAAOC,KA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AAgBJ,KAAK;IACnC,OAAOkC,qBAAA,CAAsBF,KAAK;EACpC","ignoreList":[]}
|
package/dist/esm/Adapt.native.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { StackZIndexContext } from "@tamagui/z-index-stack";
|
|
3
2
|
import { isAndroid, isIos, isTouchable, isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
4
3
|
import { createStyledContext, useMedia } from "@tamagui/core";
|
|
5
4
|
import { withStaticProperties } from "@tamagui/helpers";
|
|
6
5
|
import { PortalHost, PortalItem } from "@tamagui/portal";
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
import { StackZIndexContext } from "@tamagui/z-index-stack";
|
|
7
|
+
import React, { createContext, useContext, useId, useMemo } from "react";
|
|
8
|
+
var AdaptContext = createStyledContext({
|
|
10
9
|
Contents: null,
|
|
11
10
|
scopeName: "",
|
|
12
11
|
portalName: "",
|
|
@@ -16,26 +15,28 @@ var CurrentAdaptContextScope = /* @__PURE__ */createContext(""),
|
|
|
16
15
|
setChildren: null,
|
|
17
16
|
setWhen: function () {}
|
|
18
17
|
}),
|
|
18
|
+
LastAdaptContextScope = /* @__PURE__ */createContext(""),
|
|
19
19
|
ProvideAdaptContext = function (param) {
|
|
20
20
|
var {
|
|
21
21
|
children,
|
|
22
22
|
...context
|
|
23
23
|
} = param,
|
|
24
|
-
scope = context.scopeName || ""
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
scope = context.scopeName || "",
|
|
25
|
+
lastScope = useContext(LastAdaptContextScope);
|
|
26
|
+
return /* @__PURE__ */_jsx(LastAdaptContextScope.Provider, {
|
|
27
|
+
value: lastScope || context.lastScope || "",
|
|
27
28
|
children: /* @__PURE__ */_jsx(AdaptContext.Provider, {
|
|
28
29
|
scope,
|
|
30
|
+
lastScope: lastScope || context.lastScope,
|
|
29
31
|
...context,
|
|
30
32
|
children
|
|
31
33
|
})
|
|
32
34
|
});
|
|
33
35
|
},
|
|
34
|
-
useAdaptContext = function () {
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return context;
|
|
36
|
+
useAdaptContext = function (scope) {
|
|
37
|
+
var lastScope = useContext(LastAdaptContextScope),
|
|
38
|
+
adaptScope = scope ?? lastScope;
|
|
39
|
+
return AdaptContext.useStyledContext(adaptScope);
|
|
39
40
|
},
|
|
40
41
|
AdaptPortals = /* @__PURE__ */new Map(),
|
|
41
42
|
AdaptParent = function (param) {
|
|
@@ -45,32 +46,40 @@ var CurrentAdaptContextScope = /* @__PURE__ */createContext(""),
|
|
|
45
46
|
scope,
|
|
46
47
|
portal
|
|
47
48
|
} = param,
|
|
48
|
-
portalName = `AdaptPortal${scope}`,
|
|
49
49
|
id = useId(),
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
50
|
+
portalName = `AdaptPortal${scope}${id}`,
|
|
51
|
+
FinalContents = useMemo(function () {
|
|
52
|
+
if (Contents) return Contents;
|
|
53
|
+
if (AdaptPortals.has(portalName)) return AdaptPortals.get(portalName);
|
|
54
|
+
var element = function () {
|
|
55
|
+
return /* @__PURE__ */_jsx(PortalHost, {
|
|
56
|
+
name: portalName,
|
|
57
|
+
forwardProps: typeof portal == "boolean" ? void 0 : portal?.forwardProps
|
|
58
|
+
}, id);
|
|
59
|
+
};
|
|
60
|
+
return AdaptPortals.set(portalName, element), element;
|
|
61
|
+
}, [portalName, Contents]);
|
|
62
|
+
useIsomorphicLayoutEffect(function () {
|
|
63
|
+
return AdaptPortals.set(portalName, FinalContents), function () {
|
|
64
|
+
AdaptPortals.delete(portalName);
|
|
59
65
|
};
|
|
60
|
-
}, []);
|
|
66
|
+
}, [portalName]);
|
|
61
67
|
var [when, setWhen] = React.useState(null),
|
|
62
68
|
[platform, setPlatform] = React.useState(null),
|
|
63
69
|
[children2, setChildren] = React.useState(null);
|
|
64
|
-
return /* @__PURE__ */_jsx(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
return /* @__PURE__ */_jsx(LastAdaptContextScope, {
|
|
71
|
+
value: scope,
|
|
72
|
+
children: /* @__PURE__ */_jsx(ProvideAdaptContext, {
|
|
73
|
+
Contents: FinalContents,
|
|
74
|
+
when,
|
|
75
|
+
platform,
|
|
76
|
+
setPlatform,
|
|
77
|
+
setWhen,
|
|
78
|
+
setChildren,
|
|
79
|
+
portalName,
|
|
80
|
+
scopeName: scope,
|
|
81
|
+
children
|
|
82
|
+
})
|
|
74
83
|
});
|
|
75
84
|
},
|
|
76
85
|
AdaptContents = function (param) {
|
|
@@ -94,7 +103,6 @@ var Adapt = withStaticProperties(function (props) {
|
|
|
94
103
|
scope
|
|
95
104
|
} = props,
|
|
96
105
|
context = useAdaptContext(scope),
|
|
97
|
-
scopeName = scope ?? context.scopeName,
|
|
98
106
|
enabled = useAdaptIsActiveGiven(props);
|
|
99
107
|
useIsomorphicLayoutEffect(function () {
|
|
100
108
|
var _context_setWhen, _context_setPlatform;
|
|
@@ -113,10 +121,7 @@ var Adapt = withStaticProperties(function (props) {
|
|
|
113
121
|
return useIsomorphicLayoutEffect(function () {
|
|
114
122
|
typeof children == "function" && output !== void 0 && context?.setChildren(output);
|
|
115
123
|
}, [output]), /* @__PURE__ */_jsx(StackZIndexContext, {
|
|
116
|
-
children:
|
|
117
|
-
value: scopeName,
|
|
118
|
-
children: enabled ? output : null
|
|
119
|
-
})
|
|
124
|
+
children: enabled ? output : null
|
|
120
125
|
});
|
|
121
126
|
}, {
|
|
122
127
|
Contents: AdaptContents
|
|
@@ -139,6 +144,7 @@ var Adapt = withStaticProperties(function (props) {
|
|
|
139
144
|
} = param,
|
|
140
145
|
media = useMedia();
|
|
141
146
|
if (when == null && platform == null) return !1;
|
|
147
|
+
if (when === !0) return !0;
|
|
142
148
|
var enabled = !1;
|
|
143
149
|
return platform === "touch" ? enabled = isTouchable : platform === "native" ? enabled = !isWeb : platform === "web" ? enabled = isWeb : platform === "ios" ? enabled = isIos : platform === "android" && (enabled = isAndroid), platform && enabled == !1 ? !1 : (when && typeof when == "string" && (enabled = media[when]), enabled);
|
|
144
150
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["jsx","_jsx","
|
|
1
|
+
{"version":3,"names":["jsx","_jsx","isAndroid","isIos","isTouchable","isWeb","useIsomorphicLayoutEffect","createStyledContext","useMedia","withStaticProperties","PortalHost","PortalItem","StackZIndexContext","React","createContext","useContext","useId","useMemo","AdaptContext","Contents","scopeName","portalName","platform","setPlatform","x","when","setChildren","setWhen","LastAdaptContextScope","ProvideAdaptContext","param","children","context","scope","lastScope","Provider","value","useAdaptContext","adaptScope","useStyledContext","AdaptPortals","Map","AdaptParent","portal","id","FinalContents","has","get","element","name","forwardProps","set","delete","useState","children2","AdaptContents","rest","Error","process","env","NODE_ENV","createElement","key","shouldForwardSpace","Adapt","props","enabled","useAdaptIsActiveGiven","_context_setWhen","_context_setPlatform","call","output","Component","AdaptPortalContents","isActive","useAdaptIsActive","passThrough","hostName","media"],"sources":["../../src/Adapt.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAAAA,GAAA,IAAAC,IAAA;AAAA,SACEC,SAAA,EAAAC,KAAA,EAAAC,WAAA,EAAAC,KAAA,EAAAC,yBAAA;AAAA,SACAC,mBAAA,EAAAC,QAAA;AAAA,SACAC,oBAAA;AAAA,SACAC,UAAA,EAAAC,UAAA;AAAA,SACAC,kBAAA;AAAA,OACKC,KAAA,IAAAC,aAAA,EAAAC,UAAA,EAAAC,KAAA,EAAAC,OAAA;AAEP,IAAAC,YAAS,GAAAX,mBAAqB;IAC9BY,QAAS;IACTC,SAAS;IACTC,UAAS;IACTC,QAAO,MAAS;IAsDVC,WAAA,WAAAA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A6C,MAAA;IACJ,IAGAA,MACE,CAME,kBAAAtE,IAAA,CAAwBW,kBAAC;MAC7BmB,QAAA,EAAAmC,OAAA,GAAAK,MAAA;IACA;EACF;IACEpD,QAAM,EAAAoC;EAEN;EAAAkB,mBAAoB,YAAAA,CAAYR,KAAA;IAC9B,IAAAS,QAAO,GAAAC,gBAAA,CAAAV,KAAA,CAAAhC,KAAA;MAAA;QAAAZ;MAAA,IAAAgB,eAAA,CAAA4B,KAAA,CAAAhC,KAAA;IAGT,OAAI,eAAShC,IAAA,CAAAU,UAAA;MACXiE,WAAO,GAAAF,QAAA;MAGTG,QAAI,EAAAxD,UAAU;MAQdU,QANI,EAAAkC,KAAA,CAAAlC;IAeN,CAEa;EACX;EAAAoC,qBAAc,YAAAA,CAAgBrC,KAAK;IACnC;QAAAL,IAAO;QAAAH;MAAA,IAAAQ,KAAsB;MAAAgD,KAAK,GAAAtE,QAAA;IACpC,IAAAiB,IAAA,YAAAH,QAAA,U","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/adapt",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.131.0",
|
|
4
4
|
"types": "./types/index.d.ts",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -31,14 +31,14 @@
|
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@tamagui/constants": "1.
|
|
35
|
-
"@tamagui/core": "1.
|
|
36
|
-
"@tamagui/helpers": "1.
|
|
37
|
-
"@tamagui/portal": "1.
|
|
38
|
-
"@tamagui/z-index-stack": "1.
|
|
34
|
+
"@tamagui/constants": "1.131.0",
|
|
35
|
+
"@tamagui/core": "1.131.0",
|
|
36
|
+
"@tamagui/helpers": "1.131.0",
|
|
37
|
+
"@tamagui/portal": "1.131.0",
|
|
38
|
+
"@tamagui/z-index-stack": "1.131.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@tamagui/build": "1.
|
|
41
|
+
"@tamagui/build": "1.131.0",
|
|
42
42
|
"react": "*"
|
|
43
43
|
},
|
|
44
44
|
"publishConfig": {
|
package/src/Adapt.tsx
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { StackZIndexContext } from '@tamagui/z-index-stack'
|
|
2
1
|
import {
|
|
3
2
|
isAndroid,
|
|
4
3
|
isIos,
|
|
@@ -10,7 +9,8 @@ import type { AllPlatforms, MediaQueryKey } from '@tamagui/core'
|
|
|
10
9
|
import { createStyledContext, useMedia } from '@tamagui/core'
|
|
11
10
|
import { withStaticProperties } from '@tamagui/helpers'
|
|
12
11
|
import { PortalHost, PortalItem } from '@tamagui/portal'
|
|
13
|
-
import
|
|
12
|
+
import { StackZIndexContext } from '@tamagui/z-index-stack'
|
|
13
|
+
import React, { createContext, useContext, useId, useMemo } from 'react'
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Interfaces
|
|
@@ -28,6 +28,7 @@ export type AdaptParentContextI = {
|
|
|
28
28
|
setWhen: (when: AdaptWhen) => any
|
|
29
29
|
setChildren: (children: any) => any
|
|
30
30
|
portalName?: string
|
|
31
|
+
lastScope?: string
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
type MediaQueryKeyString = MediaQueryKey extends string ? MediaQueryKey : never
|
|
@@ -41,12 +42,6 @@ export type AdaptProps = {
|
|
|
41
42
|
|
|
42
43
|
type Component = (props: any) => any
|
|
43
44
|
|
|
44
|
-
/**
|
|
45
|
-
* Contexts
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
|
-
const CurrentAdaptContextScope = createContext('')
|
|
49
|
-
|
|
50
45
|
export const AdaptContext = createStyledContext<AdaptParentContextI>({
|
|
51
46
|
Contents: null as any,
|
|
52
47
|
scopeName: '',
|
|
@@ -58,27 +53,32 @@ export const AdaptContext = createStyledContext<AdaptParentContextI>({
|
|
|
58
53
|
setWhen: () => {},
|
|
59
54
|
})
|
|
60
55
|
|
|
56
|
+
const LastAdaptContextScope = createContext('')
|
|
57
|
+
|
|
61
58
|
export const ProvideAdaptContext = ({
|
|
62
59
|
children,
|
|
63
60
|
...context
|
|
64
61
|
}: AdaptParentContextI & { children: any }) => {
|
|
65
62
|
const scope = context.scopeName || ''
|
|
63
|
+
const lastScope = useContext(LastAdaptContextScope)
|
|
66
64
|
|
|
67
65
|
return (
|
|
68
|
-
<
|
|
69
|
-
<AdaptContext.Provider
|
|
66
|
+
<LastAdaptContextScope.Provider value={lastScope || context.lastScope || ''}>
|
|
67
|
+
<AdaptContext.Provider
|
|
68
|
+
scope={scope}
|
|
69
|
+
lastScope={lastScope || context.lastScope}
|
|
70
|
+
{...context}
|
|
71
|
+
>
|
|
70
72
|
{children}
|
|
71
73
|
</AdaptContext.Provider>
|
|
72
|
-
</
|
|
74
|
+
</LastAdaptContextScope.Provider>
|
|
73
75
|
)
|
|
74
76
|
}
|
|
75
77
|
|
|
76
|
-
export const useAdaptContext = (scope
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
)
|
|
81
|
-
return context
|
|
78
|
+
export const useAdaptContext = (scope?: string) => {
|
|
79
|
+
const lastScope = useContext(LastAdaptContextScope)
|
|
80
|
+
const adaptScope = scope ?? lastScope
|
|
81
|
+
return AdaptContext.useStyledContext(adaptScope)
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
/**
|
|
@@ -87,8 +87,8 @@ export const useAdaptContext = (scope = '') => {
|
|
|
87
87
|
|
|
88
88
|
type AdaptParentProps = {
|
|
89
89
|
children?: React.ReactNode
|
|
90
|
-
scope: string
|
|
91
90
|
Contents?: AdaptParentContextI['Contents']
|
|
91
|
+
scope: string
|
|
92
92
|
portal?:
|
|
93
93
|
| boolean
|
|
94
94
|
| {
|
|
@@ -99,28 +99,35 @@ type AdaptParentProps = {
|
|
|
99
99
|
const AdaptPortals = new Map()
|
|
100
100
|
|
|
101
101
|
export const AdaptParent = ({ children, Contents, scope, portal }: AdaptParentProps) => {
|
|
102
|
-
const portalName = `AdaptPortal${scope}`
|
|
103
102
|
const id = useId()
|
|
103
|
+
const portalName = `AdaptPortal${scope}${id}`
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
const FinalContents = useMemo(() => {
|
|
106
|
+
if (Contents) {
|
|
107
|
+
return Contents
|
|
108
|
+
}
|
|
109
|
+
if (AdaptPortals.has(portalName)) {
|
|
110
|
+
return AdaptPortals.get(portalName)
|
|
111
|
+
}
|
|
112
|
+
const element = () => {
|
|
109
113
|
return (
|
|
110
114
|
<PortalHost
|
|
115
|
+
key={id}
|
|
111
116
|
name={portalName}
|
|
112
117
|
forwardProps={typeof portal === 'boolean' ? undefined : portal?.forwardProps}
|
|
113
118
|
/>
|
|
114
119
|
)
|
|
115
120
|
}
|
|
116
|
-
AdaptPortals.set(
|
|
117
|
-
|
|
121
|
+
AdaptPortals.set(portalName, element)
|
|
122
|
+
return element
|
|
123
|
+
}, [portalName, Contents])
|
|
118
124
|
|
|
119
|
-
|
|
125
|
+
useIsomorphicLayoutEffect(() => {
|
|
126
|
+
AdaptPortals.set(portalName, FinalContents)
|
|
120
127
|
return () => {
|
|
121
|
-
AdaptPortals.delete(
|
|
128
|
+
AdaptPortals.delete(portalName)
|
|
122
129
|
}
|
|
123
|
-
}, [])
|
|
130
|
+
}, [portalName])
|
|
124
131
|
|
|
125
132
|
const [when, setWhen] = React.useState<AdaptWhen>(null)
|
|
126
133
|
const [platform, setPlatform] = React.useState<AdaptPlatform>(null)
|
|
@@ -129,18 +136,20 @@ export const AdaptParent = ({ children, Contents, scope, portal }: AdaptParentPr
|
|
|
129
136
|
const [children2, setChildren] = React.useState(null)
|
|
130
137
|
|
|
131
138
|
return (
|
|
132
|
-
<
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
139
|
+
<LastAdaptContextScope value={scope}>
|
|
140
|
+
<ProvideAdaptContext
|
|
141
|
+
Contents={FinalContents}
|
|
142
|
+
when={when}
|
|
143
|
+
platform={platform}
|
|
144
|
+
setPlatform={setPlatform}
|
|
145
|
+
setWhen={setWhen}
|
|
146
|
+
setChildren={setChildren}
|
|
147
|
+
portalName={portalName}
|
|
148
|
+
scopeName={scope}
|
|
149
|
+
>
|
|
150
|
+
{children}
|
|
151
|
+
</ProvideAdaptContext>
|
|
152
|
+
</LastAdaptContextScope>
|
|
144
153
|
)
|
|
145
154
|
}
|
|
146
155
|
|
|
@@ -169,7 +178,6 @@ export const Adapt = withStaticProperties(
|
|
|
169
178
|
function Adapt(props: AdaptProps) {
|
|
170
179
|
const { platform, when, children, scope } = props
|
|
171
180
|
const context = useAdaptContext(scope)
|
|
172
|
-
const scopeName = scope ?? context.scopeName
|
|
173
181
|
const enabled = useAdaptIsActiveGiven(props)
|
|
174
182
|
|
|
175
183
|
useIsomorphicLayoutEffect(() => {
|
|
@@ -201,13 +209,7 @@ export const Adapt = withStaticProperties(
|
|
|
201
209
|
}
|
|
202
210
|
}, [output])
|
|
203
211
|
|
|
204
|
-
return
|
|
205
|
-
<StackZIndexContext>
|
|
206
|
-
<CurrentAdaptContextScope.Provider value={scopeName}>
|
|
207
|
-
{!enabled ? null : output}
|
|
208
|
-
</CurrentAdaptContextScope.Provider>
|
|
209
|
-
</StackZIndexContext>
|
|
210
|
-
)
|
|
212
|
+
return <StackZIndexContext>{!enabled ? null : output}</StackZIndexContext>
|
|
211
213
|
},
|
|
212
214
|
{
|
|
213
215
|
Contents: AdaptContents,
|
|
@@ -239,6 +241,10 @@ const useAdaptIsActiveGiven = ({
|
|
|
239
241
|
return false
|
|
240
242
|
}
|
|
241
243
|
|
|
244
|
+
if (when === true) {
|
|
245
|
+
return true
|
|
246
|
+
}
|
|
247
|
+
|
|
242
248
|
let enabled = false
|
|
243
249
|
|
|
244
250
|
if (platform === 'touch') enabled = isTouchable
|
package/types/Adapt.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export type AdaptParentContextI = {
|
|
|
14
14
|
setWhen: (when: AdaptWhen) => any;
|
|
15
15
|
setChildren: (children: any) => any;
|
|
16
16
|
portalName?: string;
|
|
17
|
+
lastScope?: string;
|
|
17
18
|
};
|
|
18
19
|
type MediaQueryKeyString = MediaQueryKey extends string ? MediaQueryKey : never;
|
|
19
20
|
export type AdaptProps = {
|
|
@@ -33,8 +34,8 @@ export declare const useAdaptContext: (scope?: string) => AdaptParentContextI;
|
|
|
33
34
|
*/
|
|
34
35
|
type AdaptParentProps = {
|
|
35
36
|
children?: React.ReactNode;
|
|
36
|
-
scope: string;
|
|
37
37
|
Contents?: AdaptParentContextI['Contents'];
|
|
38
|
+
scope: string;
|
|
38
39
|
portal?: boolean | {
|
|
39
40
|
forwardProps?: any;
|
|
40
41
|
};
|
package/types/Adapt.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Adapt.d.ts","sourceRoot":"","sources":["../src/Adapt.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Adapt.d.ts","sourceRoot":"","sources":["../src/Adapt.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAKhE,OAAO,KAAoD,MAAM,OAAO,CAAA;AAExE;;GAEG;AAEH,MAAM,MAAM,SAAS,GAAG,mBAAmB,GAAG,OAAO,GAAG,IAAI,CAAA;AAC5D,MAAM,MAAM,aAAa,GAAG,YAAY,GAAG,OAAO,GAAG,IAAI,CAAA;AAEzD,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,EAAE,SAAS,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,aAAa,CAAA;IACvB,WAAW,EAAE,CAAC,IAAI,EAAE,aAA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