@tamagui/adapt 1.14.1 → 1.14.3
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.js +88 -1
- package/dist/cjs/Adapt.js.map +2 -2
- package/dist/cjs/index.js +18 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/esm/Adapt.js +66 -1
- package/dist/esm/Adapt.js.map +2 -2
- package/dist/esm/Adapt.mjs +66 -1
- package/dist/esm/Adapt.mjs.map +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/cjs/Adapt.js
CHANGED
|
@@ -1,2 +1,89 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var Adapt_exports = {};
|
|
20
|
+
__export(Adapt_exports, {
|
|
21
|
+
Adapt: () => Adapt,
|
|
22
|
+
AdaptContents: () => AdaptContents,
|
|
23
|
+
AdaptParentContext: () => AdaptParentContext,
|
|
24
|
+
useAdaptParent: () => useAdaptParent
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(Adapt_exports);
|
|
27
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
28
|
+
var import_core = require("@tamagui/core");
|
|
29
|
+
var import_react = require("react");
|
|
30
|
+
const AdaptParentContext = (0, import_react.createContext)(null);
|
|
31
|
+
const AdaptContents = (props) => {
|
|
32
|
+
const context = (0, import_react.useContext)(AdaptParentContext);
|
|
33
|
+
if (!(context == null ? void 0 : context.Contents)) {
|
|
34
|
+
throw new Error("Adapt not supported by this component");
|
|
35
|
+
}
|
|
36
|
+
return (0, import_react.createElement)(context.Contents, props);
|
|
37
|
+
};
|
|
38
|
+
AdaptContents["shouldForwardSpace"] = true;
|
|
39
|
+
const useAdaptParent = ({
|
|
40
|
+
Contents
|
|
41
|
+
}) => {
|
|
42
|
+
const [when, setWhen] = (0, import_react.useState)(null);
|
|
43
|
+
const AdaptProvider = (0, import_react.useMemo)(() => {
|
|
44
|
+
const context = {
|
|
45
|
+
Contents,
|
|
46
|
+
setWhen
|
|
47
|
+
};
|
|
48
|
+
function AdaptProviderView(props) {
|
|
49
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AdaptParentContext.Provider, { value: context, children: props.children });
|
|
50
|
+
}
|
|
51
|
+
return AdaptProviderView;
|
|
52
|
+
}, [Contents]);
|
|
53
|
+
return {
|
|
54
|
+
AdaptProvider,
|
|
55
|
+
when
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
const Adapt = (0, import_core.withStaticProperties)(
|
|
59
|
+
function Adapt2({ platform, when, children }) {
|
|
60
|
+
const context = (0, import_react.useContext)(AdaptParentContext);
|
|
61
|
+
let enabled = !platform;
|
|
62
|
+
if (platform === "touch")
|
|
63
|
+
enabled = import_core.isTouchable;
|
|
64
|
+
if (platform === "native")
|
|
65
|
+
enabled = !import_core.isWeb;
|
|
66
|
+
if (platform === "web")
|
|
67
|
+
enabled = import_core.isWeb;
|
|
68
|
+
(0, import_core.useIsomorphicLayoutEffect)(() => {
|
|
69
|
+
if (!enabled)
|
|
70
|
+
return;
|
|
71
|
+
context == null ? void 0 : context.setWhen(when || enabled);
|
|
72
|
+
}, [when, context, enabled]);
|
|
73
|
+
if (!enabled) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
return children;
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
Contents: AdaptContents
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
83
|
+
0 && (module.exports = {
|
|
84
|
+
Adapt,
|
|
85
|
+
AdaptContents,
|
|
86
|
+
AdaptParentContext,
|
|
87
|
+
useAdaptParent
|
|
88
|
+
});
|
|
2
89
|
//# sourceMappingURL=Adapt.js.map
|
package/dist/cjs/Adapt.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Adapt.tsx"],
|
|
4
4
|
"sourcesContent": ["import {\n MediaQueryKey,\n isTouchable,\n isWeb,\n useIsomorphicLayoutEffect,\n withStaticProperties,\n} from '@tamagui/core'\nimport { createContext, createElement, useContext, useMemo, useState } from 'react'\n\ntype MediaQueryKeyString = MediaQueryKey extends string ? MediaQueryKey : never\n\nexport type AdaptProps = {\n when?: MediaQueryKeyString\n platform?: 'native' | 'web' | 'touch'\n children?: any\n}\n\ntype When = MediaQueryKeyString | boolean | null\n\ntype Component = (props: any) => any\ntype AdaptParentContextI = {\n Contents: Component\n setWhen: (when: When) => any\n}\n\nexport const AdaptParentContext = createContext<AdaptParentContextI | null>(null)\n\n// forward props\nexport const AdaptContents = (props: any) => {\n const context = useContext(AdaptParentContext)\n if (!context?.Contents) {\n throw new Error('Adapt not supported by this component')\n }\n return createElement(context.Contents, props)\n}\n\nAdaptContents['shouldForwardSpace'] = true\n\nexport const useAdaptParent = ({\n Contents,\n}: {\n Contents: AdaptParentContextI['Contents']\n}) => {\n const [when, setWhen] = useState<When>(null)\n\n const AdaptProvider = useMemo(() => {\n const context: AdaptParentContextI = {\n Contents,\n setWhen,\n }\n\n function AdaptProviderView(props: { children?: any }) {\n return (\n <AdaptParentContext.Provider value={context}>\n {props.children}\n </AdaptParentContext.Provider>\n )\n }\n\n return AdaptProviderView\n }, [Contents])\n\n return {\n AdaptProvider,\n when,\n }\n}\n\nexport const Adapt = withStaticProperties(\n function Adapt({ platform, when, children }: AdaptProps) {\n const context = useContext(AdaptParentContext)\n\n let enabled = !platform\n if (platform === 'touch') enabled = isTouchable\n if (platform === 'native') enabled = !isWeb\n if (platform === 'web') enabled = isWeb\n\n useIsomorphicLayoutEffect(() => {\n if (!enabled) return\n context?.setWhen((when || enabled) as When)\n }, [when, context, enabled])\n\n if (!enabled) {\n return null\n }\n\n return children\n },\n {\n Contents: AdaptContents,\n }\n)\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqDQ;AArDR,kBAMO;AACP,mBAA4E;AAkBrE,MAAM,yBAAqB,4BAA0C,IAAI;AAGzE,MAAM,gBAAgB,CAAC,UAAe;AAC3C,QAAM,cAAU,yBAAW,kBAAkB;AAC7C,MAAI,EAAC,mCAAS,WAAU;AACtB,UAAM,IAAI,MAAM,uCAAuC;AAAA,EACzD;AACA,aAAO,4BAAc,QAAQ,UAAU,KAAK;AAC9C;AAEA,cAAc,oBAAoB,IAAI;AAE/B,MAAM,iBAAiB,CAAC;AAAA,EAC7B;AACF,MAEM;AACJ,QAAM,CAAC,MAAM,OAAO,QAAI,uBAAe,IAAI;AAE3C,QAAM,oBAAgB,sBAAQ,MAAM;AAClC,UAAM,UAA+B;AAAA,MACnC;AAAA,MACA;AAAA,IACF;AAEA,aAAS,kBAAkB,OAA2B;AACpD,aACE,4CAAC,mBAAmB,UAAnB,EAA4B,OAAO,SACjC,gBAAM,UACT;AAAA,IAEJ;AAEA,WAAO;AAAA,EACT,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEO,MAAM,YAAQ;AAAA,EACnB,SAASA,OAAM,EAAE,UAAU,MAAM,SAAS,GAAe;AACvD,UAAM,cAAU,yBAAW,kBAAkB;AAE7C,QAAI,UAAU,CAAC;AACf,QAAI,aAAa;AAAS,gBAAU;AACpC,QAAI,aAAa;AAAU,gBAAU,CAAC;AACtC,QAAI,aAAa;AAAO,gBAAU;AAElC,+CAA0B,MAAM;AAC9B,UAAI,CAAC;AAAS;AACd,yCAAS,QAAS,QAAQ;AAAA,IAC5B,GAAG,CAAC,MAAM,SAAS,OAAO,CAAC;AAE3B,QAAI,CAAC,SAAS;AACZ,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,UAAU;AAAA,EACZ;AACF;",
|
|
6
|
+
"names": ["Adapt"]
|
|
7
7
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,2 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var src_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(src_exports);
|
|
18
|
+
__reExport(src_exports, require("./Adapt"), module.exports);
|
|
2
19
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.tsx"],
|
|
4
4
|
"sourcesContent": ["export * from './Adapt'\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,oBAAd;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
package/dist/esm/Adapt.js
CHANGED
|
@@ -1,2 +1,67 @@
|
|
|
1
|
-
import{jsx
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
isTouchable,
|
|
4
|
+
isWeb,
|
|
5
|
+
useIsomorphicLayoutEffect,
|
|
6
|
+
withStaticProperties
|
|
7
|
+
} from "@tamagui/core";
|
|
8
|
+
import { createContext, createElement, useContext, useMemo, useState } from "react";
|
|
9
|
+
const AdaptParentContext = createContext(null);
|
|
10
|
+
const AdaptContents = (props) => {
|
|
11
|
+
const context = useContext(AdaptParentContext);
|
|
12
|
+
if (!(context == null ? void 0 : context.Contents)) {
|
|
13
|
+
throw new Error("Adapt not supported by this component");
|
|
14
|
+
}
|
|
15
|
+
return createElement(context.Contents, props);
|
|
16
|
+
};
|
|
17
|
+
AdaptContents["shouldForwardSpace"] = true;
|
|
18
|
+
const useAdaptParent = ({
|
|
19
|
+
Contents
|
|
20
|
+
}) => {
|
|
21
|
+
const [when, setWhen] = useState(null);
|
|
22
|
+
const AdaptProvider = useMemo(() => {
|
|
23
|
+
const context = {
|
|
24
|
+
Contents,
|
|
25
|
+
setWhen
|
|
26
|
+
};
|
|
27
|
+
function AdaptProviderView(props) {
|
|
28
|
+
return /* @__PURE__ */ jsx(AdaptParentContext.Provider, { value: context, children: props.children });
|
|
29
|
+
}
|
|
30
|
+
return AdaptProviderView;
|
|
31
|
+
}, [Contents]);
|
|
32
|
+
return {
|
|
33
|
+
AdaptProvider,
|
|
34
|
+
when
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
const Adapt = withStaticProperties(
|
|
38
|
+
function Adapt2({ platform, when, children }) {
|
|
39
|
+
const context = useContext(AdaptParentContext);
|
|
40
|
+
let enabled = !platform;
|
|
41
|
+
if (platform === "touch")
|
|
42
|
+
enabled = isTouchable;
|
|
43
|
+
if (platform === "native")
|
|
44
|
+
enabled = !isWeb;
|
|
45
|
+
if (platform === "web")
|
|
46
|
+
enabled = isWeb;
|
|
47
|
+
useIsomorphicLayoutEffect(() => {
|
|
48
|
+
if (!enabled)
|
|
49
|
+
return;
|
|
50
|
+
context == null ? void 0 : context.setWhen(when || enabled);
|
|
51
|
+
}, [when, context, enabled]);
|
|
52
|
+
if (!enabled) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
return children;
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
Contents: AdaptContents
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
export {
|
|
62
|
+
Adapt,
|
|
63
|
+
AdaptContents,
|
|
64
|
+
AdaptParentContext,
|
|
65
|
+
useAdaptParent
|
|
66
|
+
};
|
|
2
67
|
//# sourceMappingURL=Adapt.js.map
|
package/dist/esm/Adapt.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Adapt.tsx"],
|
|
4
4
|
"sourcesContent": ["import {\n MediaQueryKey,\n isTouchable,\n isWeb,\n useIsomorphicLayoutEffect,\n withStaticProperties,\n} from '@tamagui/core'\nimport { createContext, createElement, useContext, useMemo, useState } from 'react'\n\ntype MediaQueryKeyString = MediaQueryKey extends string ? MediaQueryKey : never\n\nexport type AdaptProps = {\n when?: MediaQueryKeyString\n platform?: 'native' | 'web' | 'touch'\n children?: any\n}\n\ntype When = MediaQueryKeyString | boolean | null\n\ntype Component = (props: any) => any\ntype AdaptParentContextI = {\n Contents: Component\n setWhen: (when: When) => any\n}\n\nexport const AdaptParentContext = createContext<AdaptParentContextI | null>(null)\n\n// forward props\nexport const AdaptContents = (props: any) => {\n const context = useContext(AdaptParentContext)\n if (!context?.Contents) {\n throw new Error('Adapt not supported by this component')\n }\n return createElement(context.Contents, props)\n}\n\nAdaptContents['shouldForwardSpace'] = true\n\nexport const useAdaptParent = ({\n Contents,\n}: {\n Contents: AdaptParentContextI['Contents']\n}) => {\n const [when, setWhen] = useState<When>(null)\n\n const AdaptProvider = useMemo(() => {\n const context: AdaptParentContextI = {\n Contents,\n setWhen,\n }\n\n function AdaptProviderView(props: { children?: any }) {\n return (\n <AdaptParentContext.Provider value={context}>\n {props.children}\n </AdaptParentContext.Provider>\n )\n }\n\n return AdaptProviderView\n }, [Contents])\n\n return {\n AdaptProvider,\n when,\n }\n}\n\nexport const Adapt = withStaticProperties(\n function Adapt({ platform, when, children }: AdaptProps) {\n const context = useContext(AdaptParentContext)\n\n let enabled = !platform\n if (platform === 'touch') enabled = isTouchable\n if (platform === 'native') enabled = !isWeb\n if (platform === 'web') enabled = isWeb\n\n useIsomorphicLayoutEffect(() => {\n if (!enabled) return\n context?.setWhen((when || enabled) as When)\n }, [when, context, enabled])\n\n if (!enabled) {\n return null\n }\n\n return children\n },\n {\n Contents: AdaptContents,\n }\n)\n"],
|
|
5
|
-
"mappings": "AAqDQ,
|
|
6
|
-
"names": ["
|
|
5
|
+
"mappings": "AAqDQ;AArDR;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,eAAe,eAAe,YAAY,SAAS,gBAAgB;AAkBrE,MAAM,qBAAqB,cAA0C,IAAI;AAGzE,MAAM,gBAAgB,CAAC,UAAe;AAC3C,QAAM,UAAU,WAAW,kBAAkB;AAC7C,MAAI,EAAC,mCAAS,WAAU;AACtB,UAAM,IAAI,MAAM,uCAAuC;AAAA,EACzD;AACA,SAAO,cAAc,QAAQ,UAAU,KAAK;AAC9C;AAEA,cAAc,oBAAoB,IAAI;AAE/B,MAAM,iBAAiB,CAAC;AAAA,EAC7B;AACF,MAEM;AACJ,QAAM,CAAC,MAAM,OAAO,IAAI,SAAe,IAAI;AAE3C,QAAM,gBAAgB,QAAQ,MAAM;AAClC,UAAM,UAA+B;AAAA,MACnC;AAAA,MACA;AAAA,IACF;AAEA,aAAS,kBAAkB,OAA2B;AACpD,aACE,oBAAC,mBAAmB,UAAnB,EAA4B,OAAO,SACjC,gBAAM,UACT;AAAA,IAEJ;AAEA,WAAO;AAAA,EACT,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEO,MAAM,QAAQ;AAAA,EACnB,SAASA,OAAM,EAAE,UAAU,MAAM,SAAS,GAAe;AACvD,UAAM,UAAU,WAAW,kBAAkB;AAE7C,QAAI,UAAU,CAAC;AACf,QAAI,aAAa;AAAS,gBAAU;AACpC,QAAI,aAAa;AAAU,gBAAU,CAAC;AACtC,QAAI,aAAa;AAAO,gBAAU;AAElC,8BAA0B,MAAM;AAC9B,UAAI,CAAC;AAAS;AACd,yCAAS,QAAS,QAAQ;AAAA,IAC5B,GAAG,CAAC,MAAM,SAAS,OAAO,CAAC;AAE3B,QAAI,CAAC,SAAS;AACZ,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,UAAU;AAAA,EACZ;AACF;",
|
|
6
|
+
"names": ["Adapt"]
|
|
7
7
|
}
|
package/dist/esm/Adapt.mjs
CHANGED
|
@@ -1,2 +1,67 @@
|
|
|
1
|
-
import{jsx
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
isTouchable,
|
|
4
|
+
isWeb,
|
|
5
|
+
useIsomorphicLayoutEffect,
|
|
6
|
+
withStaticProperties
|
|
7
|
+
} from "@tamagui/core";
|
|
8
|
+
import { createContext, createElement, useContext, useMemo, useState } from "react";
|
|
9
|
+
const AdaptParentContext = createContext(null);
|
|
10
|
+
const AdaptContents = (props) => {
|
|
11
|
+
const context = useContext(AdaptParentContext);
|
|
12
|
+
if (!(context == null ? void 0 : context.Contents)) {
|
|
13
|
+
throw new Error("Adapt not supported by this component");
|
|
14
|
+
}
|
|
15
|
+
return createElement(context.Contents, props);
|
|
16
|
+
};
|
|
17
|
+
AdaptContents["shouldForwardSpace"] = true;
|
|
18
|
+
const useAdaptParent = ({
|
|
19
|
+
Contents
|
|
20
|
+
}) => {
|
|
21
|
+
const [when, setWhen] = useState(null);
|
|
22
|
+
const AdaptProvider = useMemo(() => {
|
|
23
|
+
const context = {
|
|
24
|
+
Contents,
|
|
25
|
+
setWhen
|
|
26
|
+
};
|
|
27
|
+
function AdaptProviderView(props) {
|
|
28
|
+
return /* @__PURE__ */ jsx(AdaptParentContext.Provider, { value: context, children: props.children });
|
|
29
|
+
}
|
|
30
|
+
return AdaptProviderView;
|
|
31
|
+
}, [Contents]);
|
|
32
|
+
return {
|
|
33
|
+
AdaptProvider,
|
|
34
|
+
when
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
const Adapt = withStaticProperties(
|
|
38
|
+
function Adapt2({ platform, when, children }) {
|
|
39
|
+
const context = useContext(AdaptParentContext);
|
|
40
|
+
let enabled = !platform;
|
|
41
|
+
if (platform === "touch")
|
|
42
|
+
enabled = isTouchable;
|
|
43
|
+
if (platform === "native")
|
|
44
|
+
enabled = !isWeb;
|
|
45
|
+
if (platform === "web")
|
|
46
|
+
enabled = isWeb;
|
|
47
|
+
useIsomorphicLayoutEffect(() => {
|
|
48
|
+
if (!enabled)
|
|
49
|
+
return;
|
|
50
|
+
context == null ? void 0 : context.setWhen(when || enabled);
|
|
51
|
+
}, [when, context, enabled]);
|
|
52
|
+
if (!enabled) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
return children;
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
Contents: AdaptContents
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
export {
|
|
62
|
+
Adapt,
|
|
63
|
+
AdaptContents,
|
|
64
|
+
AdaptParentContext,
|
|
65
|
+
useAdaptParent
|
|
66
|
+
};
|
|
2
67
|
//# sourceMappingURL=Adapt.mjs.map
|
package/dist/esm/Adapt.mjs.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Adapt.tsx"],
|
|
4
4
|
"sourcesContent": ["import {\n MediaQueryKey,\n isTouchable,\n isWeb,\n useIsomorphicLayoutEffect,\n withStaticProperties,\n} from '@tamagui/core'\nimport { createContext, createElement, useContext, useMemo, useState } from 'react'\n\ntype MediaQueryKeyString = MediaQueryKey extends string ? MediaQueryKey : never\n\nexport type AdaptProps = {\n when?: MediaQueryKeyString\n platform?: 'native' | 'web' | 'touch'\n children?: any\n}\n\ntype When = MediaQueryKeyString | boolean | null\n\ntype Component = (props: any) => any\ntype AdaptParentContextI = {\n Contents: Component\n setWhen: (when: When) => any\n}\n\nexport const AdaptParentContext = createContext<AdaptParentContextI | null>(null)\n\n// forward props\nexport const AdaptContents = (props: any) => {\n const context = useContext(AdaptParentContext)\n if (!context?.Contents) {\n throw new Error('Adapt not supported by this component')\n }\n return createElement(context.Contents, props)\n}\n\nAdaptContents['shouldForwardSpace'] = true\n\nexport const useAdaptParent = ({\n Contents,\n}: {\n Contents: AdaptParentContextI['Contents']\n}) => {\n const [when, setWhen] = useState<When>(null)\n\n const AdaptProvider = useMemo(() => {\n const context: AdaptParentContextI = {\n Contents,\n setWhen,\n }\n\n function AdaptProviderView(props: { children?: any }) {\n return (\n <AdaptParentContext.Provider value={context}>\n {props.children}\n </AdaptParentContext.Provider>\n )\n }\n\n return AdaptProviderView\n }, [Contents])\n\n return {\n AdaptProvider,\n when,\n }\n}\n\nexport const Adapt = withStaticProperties(\n function Adapt({ platform, when, children }: AdaptProps) {\n const context = useContext(AdaptParentContext)\n\n let enabled = !platform\n if (platform === 'touch') enabled = isTouchable\n if (platform === 'native') enabled = !isWeb\n if (platform === 'web') enabled = isWeb\n\n useIsomorphicLayoutEffect(() => {\n if (!enabled) return\n context?.setWhen((when || enabled) as When)\n }, [when, context, enabled])\n\n if (!enabled) {\n return null\n }\n\n return children\n },\n {\n Contents: AdaptContents,\n }\n)\n"],
|
|
5
|
-
"mappings": "AAqDQ,
|
|
6
|
-
"names": ["
|
|
5
|
+
"mappings": "AAqDQ;AArDR;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,eAAe,eAAe,YAAY,SAAS,gBAAgB;AAkBrE,MAAM,qBAAqB,cAA0C,IAAI;AAGzE,MAAM,gBAAgB,CAAC,UAAe;AAC3C,QAAM,UAAU,WAAW,kBAAkB;AAC7C,MAAI,EAAC,mCAAS,WAAU;AACtB,UAAM,IAAI,MAAM,uCAAuC;AAAA,EACzD;AACA,SAAO,cAAc,QAAQ,UAAU,KAAK;AAC9C;AAEA,cAAc,oBAAoB,IAAI;AAE/B,MAAM,iBAAiB,CAAC;AAAA,EAC7B;AACF,MAEM;AACJ,QAAM,CAAC,MAAM,OAAO,IAAI,SAAe,IAAI;AAE3C,QAAM,gBAAgB,QAAQ,MAAM;AAClC,UAAM,UAA+B;AAAA,MACnC;AAAA,MACA;AAAA,IACF;AAEA,aAAS,kBAAkB,OAA2B;AACpD,aACE,oBAAC,mBAAmB,UAAnB,EAA4B,OAAO,SACjC,gBAAM,UACT;AAAA,IAEJ;AAEA,WAAO;AAAA,EACT,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEO,MAAM,QAAQ;AAAA,EACnB,SAASA,OAAM,EAAE,UAAU,MAAM,SAAS,GAAe;AACvD,UAAM,UAAU,WAAW,kBAAkB;AAE7C,QAAI,UAAU,CAAC;AACf,QAAI,aAAa;AAAS,gBAAU;AACpC,QAAI,aAAa;AAAU,gBAAU,CAAC;AACtC,QAAI,aAAa;AAAO,gBAAU;AAElC,8BAA0B,MAAM;AAC9B,UAAI,CAAC;AAAS;AACd,yCAAS,QAAS,QAAQ;AAAA,IAC5B,GAAG,CAAC,MAAM,SAAS,OAAO,CAAC;AAE3B,QAAI,CAAC,SAAS;AACZ,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,UAAU;AAAA,EACZ;AACF;",
|
|
6
|
+
"names": ["Adapt"]
|
|
7
7
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export*from"./Adapt";
|
|
1
|
+
export * from "./Adapt";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
package/dist/esm/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export*from"./Adapt";
|
|
1
|
+
export * from "./Adapt";
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/adapt",
|
|
3
|
-
"version": "1.14.
|
|
3
|
+
"version": "1.14.3",
|
|
4
4
|
"types": "./types/index.d.ts",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@tamagui/core": "1.14.
|
|
29
|
+
"@tamagui/core": "1.14.3"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@tamagui/build": "1.14.
|
|
32
|
+
"@tamagui/build": "1.14.3"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|