@tamagui/adapt 1.0.1-rc.5.1 → 1.0.1-rc.7
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 +7 -3
- package/dist/cjs/Adapt.js.map +2 -2
- package/dist/esm/Adapt.js +6 -3
- package/dist/esm/Adapt.js.map +2 -2
- package/package.json +5 -5
- package/src/Adapt.tsx +11 -5
- package/types/Adapt.d.ts +2 -1
package/dist/cjs/Adapt.js
CHANGED
|
@@ -20,6 +20,7 @@ var Adapt_exports = {};
|
|
|
20
20
|
__export(Adapt_exports, {
|
|
21
21
|
Adapt: () => Adapt,
|
|
22
22
|
AdaptContents: () => AdaptContents,
|
|
23
|
+
AdaptParentContext: () => AdaptParentContext,
|
|
23
24
|
useAdaptParent: () => useAdaptParent
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(Adapt_exports);
|
|
@@ -29,13 +30,15 @@ var import_react = require("react");
|
|
|
29
30
|
const AdaptParentContext = (0, import_react.createContext)(null);
|
|
30
31
|
const AdaptContents = (props) => {
|
|
31
32
|
const context = (0, import_react.useContext)(AdaptParentContext);
|
|
32
|
-
if (!context
|
|
33
|
-
throw new Error(
|
|
33
|
+
if (!(context == null ? void 0 : context.Contents)) {
|
|
34
|
+
throw new Error("Adapt not supported by this component");
|
|
34
35
|
}
|
|
35
36
|
return (0, import_react.createElement)(context.Contents, props);
|
|
36
37
|
};
|
|
37
38
|
AdaptContents["shouldForwardSpace"] = true;
|
|
38
|
-
const useAdaptParent = ({
|
|
39
|
+
const useAdaptParent = ({
|
|
40
|
+
Contents
|
|
41
|
+
}) => {
|
|
39
42
|
const [when, setWhen] = (0, import_react.useState)(null);
|
|
40
43
|
const AdaptProvider = (0, import_react.useMemo)(() => {
|
|
41
44
|
const context = {
|
|
@@ -82,6 +85,7 @@ const Adapt = (0, import_core.withStaticProperties)(
|
|
|
82
85
|
0 && (module.exports = {
|
|
83
86
|
Adapt,
|
|
84
87
|
AdaptContents,
|
|
88
|
+
AdaptParentContext,
|
|
85
89
|
useAdaptParent
|
|
86
90
|
});
|
|
87
91
|
//# sourceMappingURL=Adapt.js.map
|
package/dist/cjs/Adapt.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Adapt.tsx"],
|
|
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\nexport type AdaptProps = {\n when?: MediaQueryKey\n platform?: 'native' | 'web' | 'touch'\n children?: any\n}\n\ntype Component = (props: any) => any\ntype AdaptParentContextI = {\n Contents: Component\n setWhen: (when: MediaQueryKey) => any\n}\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
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\nexport type AdaptProps = {\n when?: MediaQueryKey\n platform?: 'native' | 'web' | 'touch'\n children?: any\n}\n\ntype Component = (props: any) => any\ntype AdaptParentContextI = {\n Contents: Component\n setWhen: (when: MediaQueryKey) => 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<MediaQueryKey | null>(null)\n\n const AdaptProvider = useMemo(() => {\n const context: AdaptParentContextI = {\n Contents,\n setWhen,\n }\n\n return (props: { children?: any }) => {\n return (\n <AdaptParentContext.Provider value={context}>\n {props.children}\n </AdaptParentContext.Provider>\n )\n }\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 as MediaQueryKey)\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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiDQ;AAjDR,kBAMO;AACP,mBAA4E;AAcrE,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,wBAAwB;AAE/B,MAAM,iBAAiB,CAAC;AAAA,EAC7B;AACF,MAEM;AACJ,QAAM,CAAC,MAAM,OAAO,QAAI,uBAA+B,IAAI;AAE3D,QAAM,oBAAgB,sBAAQ,MAAM;AAClC,UAAM,UAA+B;AAAA,MACnC;AAAA,MACA;AAAA,IACF;AAEA,WAAO,CAAC,UAA8B;AACpC,aACE,4CAAC,mBAAmB,UAAnB;AAAA,QAA4B,OAAO;AAAA,QACjC,gBAAM;AAAA,OACT;AAAA,IAEJ;AAAA,EACF,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,QAAQ;AAAA,IACnB,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
6
|
"names": ["Adapt"]
|
|
7
7
|
}
|
package/dist/esm/Adapt.js
CHANGED
|
@@ -9,13 +9,15 @@ import { createContext, createElement, useContext, useMemo, useState } from "rea
|
|
|
9
9
|
const AdaptParentContext = createContext(null);
|
|
10
10
|
const AdaptContents = (props) => {
|
|
11
11
|
const context = useContext(AdaptParentContext);
|
|
12
|
-
if (!context
|
|
13
|
-
throw new Error(
|
|
12
|
+
if (!(context == null ? void 0 : context.Contents)) {
|
|
13
|
+
throw new Error("Adapt not supported by this component");
|
|
14
14
|
}
|
|
15
15
|
return createElement(context.Contents, props);
|
|
16
16
|
};
|
|
17
17
|
AdaptContents["shouldForwardSpace"] = true;
|
|
18
|
-
const useAdaptParent = ({
|
|
18
|
+
const useAdaptParent = ({
|
|
19
|
+
Contents
|
|
20
|
+
}) => {
|
|
19
21
|
const [when, setWhen] = useState(null);
|
|
20
22
|
const AdaptProvider = useMemo(() => {
|
|
21
23
|
const context = {
|
|
@@ -61,6 +63,7 @@ const Adapt = withStaticProperties(
|
|
|
61
63
|
export {
|
|
62
64
|
Adapt,
|
|
63
65
|
AdaptContents,
|
|
66
|
+
AdaptParentContext,
|
|
64
67
|
useAdaptParent
|
|
65
68
|
};
|
|
66
69
|
//# sourceMappingURL=Adapt.js.map
|
package/dist/esm/Adapt.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Adapt.tsx"],
|
|
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\nexport type AdaptProps = {\n when?: MediaQueryKey\n platform?: 'native' | 'web' | 'touch'\n children?: any\n}\n\ntype Component = (props: any) => any\ntype AdaptParentContextI = {\n Contents: Component\n setWhen: (when: MediaQueryKey) => any\n}\n\
|
|
5
|
-
"mappings": "
|
|
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\nexport type AdaptProps = {\n when?: MediaQueryKey\n platform?: 'native' | 'web' | 'touch'\n children?: any\n}\n\ntype Component = (props: any) => any\ntype AdaptParentContextI = {\n Contents: Component\n setWhen: (when: MediaQueryKey) => 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<MediaQueryKey | null>(null)\n\n const AdaptProvider = useMemo(() => {\n const context: AdaptParentContextI = {\n Contents,\n setWhen,\n }\n\n return (props: { children?: any }) => {\n return (\n <AdaptParentContext.Provider value={context}>\n {props.children}\n </AdaptParentContext.Provider>\n )\n }\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 as MediaQueryKey)\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": "AAiDQ;AAjDR;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,eAAe,eAAe,YAAY,SAAS,gBAAgB;AAcrE,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,wBAAwB;AAE/B,MAAM,iBAAiB,CAAC;AAAA,EAC7B;AACF,MAEM;AACJ,QAAM,CAAC,MAAM,OAAO,IAAI,SAA+B,IAAI;AAE3D,QAAM,gBAAgB,QAAQ,MAAM;AAClC,UAAM,UAA+B;AAAA,MACnC;AAAA,MACA;AAAA,IACF;AAEA,WAAO,CAAC,UAA8B;AACpC,aACE,oBAAC,mBAAmB,UAAnB;AAAA,QAA4B,OAAO;AAAA,QACjC,gBAAM;AAAA,OACT;AAAA,IAEJ;AAAA,EACF,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,QAAQ;AAAA,IACnB,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
6
|
"names": ["Adapt"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/adapt",
|
|
3
|
-
"version": "1.0.1-rc.
|
|
3
|
+
"version": "1.0.1-rc.7",
|
|
4
4
|
"types": "./types/index.d.ts",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -12,16 +12,16 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"build": "tamagui-build",
|
|
14
14
|
"watch": "tamagui-build --watch",
|
|
15
|
-
"lint": "
|
|
16
|
-
"lint:fix": "
|
|
15
|
+
"lint": "../../node_modules/.bin/rome check src",
|
|
16
|
+
"lint:fix": "../../node_modules/.bin/rome check --apply-suggested src",
|
|
17
17
|
"clean": "tamagui-build clean",
|
|
18
18
|
"clean:build": "tamagui-build clean:build"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@tamagui/core": "^1.0.1-rc.
|
|
21
|
+
"@tamagui/core": "^1.0.1-rc.7"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@tamagui/build": "^1.0.1-rc.
|
|
24
|
+
"@tamagui/build": "^1.0.1-rc.7"
|
|
25
25
|
},
|
|
26
26
|
"publishConfig": {
|
|
27
27
|
"access": "public"
|
package/src/Adapt.tsx
CHANGED
|
@@ -19,20 +19,24 @@ type AdaptParentContextI = {
|
|
|
19
19
|
setWhen: (when: MediaQueryKey) => any
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const AdaptParentContext = createContext<AdaptParentContextI | null>(null)
|
|
22
|
+
export const AdaptParentContext = createContext<AdaptParentContextI | null>(null)
|
|
23
23
|
|
|
24
24
|
// forward props
|
|
25
25
|
export const AdaptContents = (props: any) => {
|
|
26
26
|
const context = useContext(AdaptParentContext)
|
|
27
|
-
if (!context
|
|
28
|
-
throw new Error(
|
|
27
|
+
if (!context?.Contents) {
|
|
28
|
+
throw new Error('Adapt not supported by this component')
|
|
29
29
|
}
|
|
30
30
|
return createElement(context.Contents, props)
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
AdaptContents['shouldForwardSpace'] = true
|
|
34
34
|
|
|
35
|
-
export const useAdaptParent = ({
|
|
35
|
+
export const useAdaptParent = ({
|
|
36
|
+
Contents,
|
|
37
|
+
}: {
|
|
38
|
+
Contents: AdaptParentContextI['Contents']
|
|
39
|
+
}) => {
|
|
36
40
|
const [when, setWhen] = useState<MediaQueryKey | null>(null)
|
|
37
41
|
|
|
38
42
|
const AdaptProvider = useMemo(() => {
|
|
@@ -43,7 +47,9 @@ export const useAdaptParent = ({ Contents }: { Contents: AdaptParentContextI['Co
|
|
|
43
47
|
|
|
44
48
|
return (props: { children?: any }) => {
|
|
45
49
|
return (
|
|
46
|
-
<AdaptParentContext.Provider value={context}>
|
|
50
|
+
<AdaptParentContext.Provider value={context}>
|
|
51
|
+
{props.children}
|
|
52
|
+
</AdaptParentContext.Provider>
|
|
47
53
|
)
|
|
48
54
|
}
|
|
49
55
|
}, [Contents])
|
package/types/Adapt.d.ts
CHANGED
|
@@ -10,11 +10,12 @@ type AdaptParentContextI = {
|
|
|
10
10
|
Contents: Component;
|
|
11
11
|
setWhen: (when: MediaQueryKey) => any;
|
|
12
12
|
};
|
|
13
|
+
export declare const AdaptParentContext: import("react").Context<AdaptParentContextI | null>;
|
|
13
14
|
export declare const AdaptContents: {
|
|
14
15
|
(props: any): import("react").FunctionComponentElement<any>;
|
|
15
16
|
shouldForwardSpace: boolean;
|
|
16
17
|
};
|
|
17
|
-
export declare const useAdaptParent: ({ Contents }: {
|
|
18
|
+
export declare const useAdaptParent: ({ Contents, }: {
|
|
18
19
|
Contents: AdaptParentContextI['Contents'];
|
|
19
20
|
}) => {
|
|
20
21
|
AdaptProvider: (props: {
|