@tamagui/adapt 1.0.1-rc.1.4 → 1.0.1-rc.10

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.
@@ -0,0 +1,91 @@
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
+ return (props) => {
49
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AdaptParentContext.Provider, {
50
+ value: context,
51
+ children: props.children
52
+ });
53
+ };
54
+ }, [Contents]);
55
+ return {
56
+ AdaptProvider,
57
+ when
58
+ };
59
+ };
60
+ const Adapt = (0, import_core.withStaticProperties)(
61
+ function Adapt2({ platform, when, children }) {
62
+ const context = (0, import_react.useContext)(AdaptParentContext);
63
+ let enabled = !platform;
64
+ if (platform === "touch")
65
+ enabled = import_core.isTouchable;
66
+ if (platform === "native")
67
+ enabled = !import_core.isWeb;
68
+ if (platform === "web")
69
+ enabled = import_core.isWeb;
70
+ (0, import_core.useIsomorphicLayoutEffect)(() => {
71
+ if (!enabled)
72
+ return;
73
+ context == null ? void 0 : context.setWhen(when);
74
+ }, [when, context, enabled]);
75
+ if (!enabled) {
76
+ return null;
77
+ }
78
+ return children;
79
+ },
80
+ {
81
+ Contents: AdaptContents
82
+ }
83
+ );
84
+ // Annotate the CommonJS export names for ESM import in node:
85
+ 0 && (module.exports = {
86
+ Adapt,
87
+ AdaptContents,
88
+ AdaptParentContext,
89
+ useAdaptParent
90
+ });
91
+ //# sourceMappingURL=Adapt.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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\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
+ "names": ["Adapt"]
7
+ }
package/dist/cjs/index.js CHANGED
@@ -3,10 +3,6 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
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
6
  var __copyProps = (to, from, except, desc) => {
11
7
  if (from && typeof from === "object" || typeof from === "function") {
12
8
  for (let key of __getOwnPropNames(from))
@@ -15,70 +11,9 @@ var __copyProps = (to, from, except, desc) => {
15
11
  }
16
12
  return to;
17
13
  };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
15
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
16
  var src_exports = {};
20
- __export(src_exports, {
21
- Adapt: () => Adapt,
22
- AdaptContents: () => AdaptContents,
23
- useAdaptParent: () => useAdaptParent
24
- });
25
17
  module.exports = __toCommonJS(src_exports);
26
- var import_jsx_runtime = require("react/jsx-runtime");
27
- var import_core = require("@tamagui/core");
28
- var import_react = require("react");
29
- const AdaptParentContext = (0, import_react.createContext)(null);
30
- const AdaptContents = () => {
31
- const context = (0, import_react.useContext)(AdaptParentContext);
32
- if (!context || !context.Contents) {
33
- throw new Error(`Missing parent adapatable component, Adapt not supported here`);
34
- }
35
- return (0, import_react.createElement)(context.Contents);
36
- };
37
- const useAdaptParent = ({ Contents }) => {
38
- const [when, setWhen] = (0, import_react.useState)(null);
39
- const AdaptProvider = (0, import_react.useMemo)(() => {
40
- const context = {
41
- Contents,
42
- setWhen
43
- };
44
- return (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AdaptParentContext.Provider, {
45
- value: context,
46
- children: props.children
47
- });
48
- }, [Contents]);
49
- return {
50
- AdaptProvider,
51
- when
52
- };
53
- };
54
- const Adapt = (0, import_core.withStaticProperties)(
55
- function Adapt2({ platform, when, children }) {
56
- const context = (0, import_react.useContext)(AdaptParentContext);
57
- let enabled = !platform;
58
- if (platform === "touch")
59
- enabled = import_core.isTouchable;
60
- if (platform === "native")
61
- enabled = !import_core.isWeb;
62
- if (platform === "web")
63
- enabled = import_core.isWeb;
64
- (0, import_core.useIsomorphicLayoutEffect)(() => {
65
- if (!enabled)
66
- return;
67
- context == null ? void 0 : context.setWhen(when);
68
- }, [when, context, enabled]);
69
- if (!enabled) {
70
- return null;
71
- }
72
- return children;
73
- },
74
- {
75
- Contents: AdaptContents
76
- }
77
- );
78
- // Annotate the CommonJS export names for ESM import in node:
79
- 0 && (module.exports = {
80
- Adapt,
81
- AdaptContents,
82
- useAdaptParent
83
- });
18
+ __reExport(src_exports, require("./Adapt"), module.exports);
84
19
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.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\nconst AdaptParentContext = createContext<AdaptParentContextI | null>(null)\n\nexport const AdaptContents = () => {\n const context = useContext(AdaptParentContext)\n if (!context || !context.Contents) {\n throw new Error(`Missing parent adapatable component, Adapt not supported here`)\n }\n return createElement(context.Contents)\n}\n\nexport const useAdaptParent = ({ Contents }: { Contents: AdaptParentContextI['Contents'] }) => {\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 <AdaptParentContext.Provider value={context}>{props.children}</AdaptParentContext.Provider>\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;AAyCM;AAzCN,kBAMO;AACP,mBAA4E;AAc5E,MAAM,yBAAqB,4BAA0C,IAAI;AAElE,MAAM,gBAAgB,MAAM;AACjC,QAAM,cAAU,yBAAW,kBAAkB;AAC7C,MAAI,CAAC,WAAW,CAAC,QAAQ,UAAU;AACjC,UAAM,IAAI,MAAM,+DAA+D;AAAA,EACjF;AACA,aAAO,4BAAc,QAAQ,QAAQ;AACvC;AAEO,MAAM,iBAAiB,CAAC,EAAE,SAAS,MAAqD;AAC7F,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,UACN,4CAAC,mBAAmB,UAAnB;AAAA,MAA4B,OAAO;AAAA,MAAU,gBAAM;AAAA,KAAS;AAAA,EAEjE,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
- "names": ["Adapt"]
4
+ "sourcesContent": ["export * from './Adapt'\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,oBAAd;",
6
+ "names": []
7
7
  }
@@ -0,0 +1,69 @@
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
+ return (props) => {
28
+ return /* @__PURE__ */ jsx(AdaptParentContext.Provider, {
29
+ value: context,
30
+ children: props.children
31
+ });
32
+ };
33
+ }, [Contents]);
34
+ return {
35
+ AdaptProvider,
36
+ when
37
+ };
38
+ };
39
+ const Adapt = withStaticProperties(
40
+ function Adapt2({ platform, when, children }) {
41
+ const context = useContext(AdaptParentContext);
42
+ let enabled = !platform;
43
+ if (platform === "touch")
44
+ enabled = isTouchable;
45
+ if (platform === "native")
46
+ enabled = !isWeb;
47
+ if (platform === "web")
48
+ enabled = isWeb;
49
+ useIsomorphicLayoutEffect(() => {
50
+ if (!enabled)
51
+ return;
52
+ context == null ? void 0 : context.setWhen(when);
53
+ }, [when, context, enabled]);
54
+ if (!enabled) {
55
+ return null;
56
+ }
57
+ return children;
58
+ },
59
+ {
60
+ Contents: AdaptContents
61
+ }
62
+ );
63
+ export {
64
+ Adapt,
65
+ AdaptContents,
66
+ AdaptParentContext,
67
+ useAdaptParent
68
+ };
69
+ //# sourceMappingURL=Adapt.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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\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
+ "names": ["Adapt"]
7
+ }
package/dist/esm/index.js CHANGED
@@ -1,63 +1,2 @@
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 = () => {
11
- const context = useContext(AdaptParentContext);
12
- if (!context || !context.Contents) {
13
- throw new Error(`Missing parent adapatable component, Adapt not supported here`);
14
- }
15
- return createElement(context.Contents);
16
- };
17
- const useAdaptParent = ({ Contents }) => {
18
- const [when, setWhen] = useState(null);
19
- const AdaptProvider = useMemo(() => {
20
- const context = {
21
- Contents,
22
- setWhen
23
- };
24
- return (props) => /* @__PURE__ */ jsx(AdaptParentContext.Provider, {
25
- value: context,
26
- children: props.children
27
- });
28
- }, [Contents]);
29
- return {
30
- AdaptProvider,
31
- when
32
- };
33
- };
34
- const Adapt = withStaticProperties(
35
- function Adapt2({ platform, when, children }) {
36
- const context = useContext(AdaptParentContext);
37
- let enabled = !platform;
38
- if (platform === "touch")
39
- enabled = isTouchable;
40
- if (platform === "native")
41
- enabled = !isWeb;
42
- if (platform === "web")
43
- enabled = isWeb;
44
- useIsomorphicLayoutEffect(() => {
45
- if (!enabled)
46
- return;
47
- context == null ? void 0 : context.setWhen(when);
48
- }, [when, context, enabled]);
49
- if (!enabled) {
50
- return null;
51
- }
52
- return children;
53
- },
54
- {
55
- Contents: AdaptContents
56
- }
57
- );
58
- export {
59
- Adapt,
60
- AdaptContents,
61
- useAdaptParent
62
- };
1
+ export * from "./Adapt";
63
2
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.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\nconst AdaptParentContext = createContext<AdaptParentContextI | null>(null)\n\nexport const AdaptContents = () => {\n const context = useContext(AdaptParentContext)\n if (!context || !context.Contents) {\n throw new Error(`Missing parent adapatable component, Adapt not supported here`)\n }\n return createElement(context.Contents)\n}\n\nexport const useAdaptParent = ({ Contents }: { Contents: AdaptParentContextI['Contents'] }) => {\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 <AdaptParentContext.Provider value={context}>{props.children}</AdaptParentContext.Provider>\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": "AAyCM;AAzCN;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,eAAe,eAAe,YAAY,SAAS,gBAAgB;AAc5E,MAAM,qBAAqB,cAA0C,IAAI;AAElE,MAAM,gBAAgB,MAAM;AACjC,QAAM,UAAU,WAAW,kBAAkB;AAC7C,MAAI,CAAC,WAAW,CAAC,QAAQ,UAAU;AACjC,UAAM,IAAI,MAAM,+DAA+D;AAAA,EACjF;AACA,SAAO,cAAc,QAAQ,QAAQ;AACvC;AAEO,MAAM,iBAAiB,CAAC,EAAE,SAAS,MAAqD;AAC7F,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,UACN,oBAAC,mBAAmB,UAAnB;AAAA,MAA4B,OAAO;AAAA,MAAU,gBAAM;AAAA,KAAS;AAAA,EAEjE,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
- "names": ["Adapt"]
4
+ "sourcesContent": ["export * from './Adapt'\n"],
5
+ "mappings": "AAAA,cAAc;",
6
+ "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/adapt",
3
- "version": "1.0.1-rc.1.4",
3
+ "version": "1.0.1-rc.10",
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": "eslint src",
16
- "lint:fix": "yarn 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.1.4"
21
+ "@tamagui/core": "^1.0.1-rc.10"
22
22
  },
23
23
  "devDependencies": {
24
- "@tamagui/build": "^1.0.1-rc.1.4"
24
+ "@tamagui/build": "^1.0.1-rc.10"
25
25
  },
26
26
  "publishConfig": {
27
27
  "access": "public"
package/src/Adapt.tsx ADDED
@@ -0,0 +1,86 @@
1
+ import {
2
+ MediaQueryKey,
3
+ isTouchable,
4
+ isWeb,
5
+ useIsomorphicLayoutEffect,
6
+ withStaticProperties,
7
+ } from '@tamagui/core'
8
+ import { createContext, createElement, useContext, useMemo, useState } from 'react'
9
+
10
+ export type AdaptProps = {
11
+ when?: MediaQueryKey
12
+ platform?: 'native' | 'web' | 'touch'
13
+ children?: any
14
+ }
15
+
16
+ type Component = (props: any) => any
17
+ type AdaptParentContextI = {
18
+ Contents: Component
19
+ setWhen: (when: MediaQueryKey) => any
20
+ }
21
+
22
+ export const AdaptParentContext = createContext<AdaptParentContextI | null>(null)
23
+
24
+ // forward props
25
+ export const AdaptContents = (props: any) => {
26
+ const context = useContext(AdaptParentContext)
27
+ if (!context?.Contents) {
28
+ throw new Error('Adapt not supported by this component')
29
+ }
30
+ return createElement(context.Contents, props)
31
+ }
32
+
33
+ AdaptContents['shouldForwardSpace'] = true
34
+
35
+ export const useAdaptParent = ({
36
+ Contents,
37
+ }: {
38
+ Contents: AdaptParentContextI['Contents']
39
+ }) => {
40
+ const [when, setWhen] = useState<MediaQueryKey | null>(null)
41
+
42
+ const AdaptProvider = useMemo(() => {
43
+ const context: AdaptParentContextI = {
44
+ Contents,
45
+ setWhen,
46
+ }
47
+
48
+ return (props: { children?: any }) => {
49
+ return (
50
+ <AdaptParentContext.Provider value={context}>
51
+ {props.children}
52
+ </AdaptParentContext.Provider>
53
+ )
54
+ }
55
+ }, [Contents])
56
+
57
+ return {
58
+ AdaptProvider,
59
+ when,
60
+ }
61
+ }
62
+
63
+ export const Adapt = withStaticProperties(
64
+ function Adapt({ platform, when, children }: AdaptProps) {
65
+ const context = useContext(AdaptParentContext)
66
+
67
+ let enabled = !platform
68
+ if (platform === 'touch') enabled = isTouchable
69
+ if (platform === 'native') enabled = !isWeb
70
+ if (platform === 'web') enabled = isWeb
71
+
72
+ useIsomorphicLayoutEffect(() => {
73
+ if (!enabled) return
74
+ context?.setWhen(when as MediaQueryKey)
75
+ }, [when, context, enabled])
76
+
77
+ if (!enabled) {
78
+ return null
79
+ }
80
+
81
+ return children
82
+ },
83
+ {
84
+ Contents: AdaptContents,
85
+ }
86
+ )
package/src/index.tsx CHANGED
@@ -1,75 +1 @@
1
- import {
2
- MediaQueryKey,
3
- isTouchable,
4
- isWeb,
5
- useIsomorphicLayoutEffect,
6
- withStaticProperties,
7
- } from '@tamagui/core'
8
- import { createContext, createElement, useContext, useMemo, useState } from 'react'
9
-
10
- export type AdaptProps = {
11
- when?: MediaQueryKey
12
- platform?: 'native' | 'web' | 'touch'
13
- children?: any
14
- }
15
-
16
- type Component = (props: any) => any
17
- type AdaptParentContextI = {
18
- Contents: Component
19
- setWhen: (when: MediaQueryKey) => any
20
- }
21
-
22
- const AdaptParentContext = createContext<AdaptParentContextI | null>(null)
23
-
24
- export const AdaptContents = () => {
25
- const context = useContext(AdaptParentContext)
26
- if (!context || !context.Contents) {
27
- throw new Error(`Missing parent adapatable component, Adapt not supported here`)
28
- }
29
- return createElement(context.Contents)
30
- }
31
-
32
- export const useAdaptParent = ({ Contents }: { Contents: AdaptParentContextI['Contents'] }) => {
33
- const [when, setWhen] = useState<MediaQueryKey | null>(null)
34
-
35
- const AdaptProvider = useMemo(() => {
36
- const context: AdaptParentContextI = {
37
- Contents,
38
- setWhen,
39
- }
40
-
41
- return (props: { children?: any }) => (
42
- <AdaptParentContext.Provider value={context}>{props.children}</AdaptParentContext.Provider>
43
- )
44
- }, [Contents])
45
-
46
- return {
47
- AdaptProvider,
48
- when,
49
- }
50
- }
51
-
52
- export const Adapt = withStaticProperties(
53
- function Adapt({ platform, when, children }: AdaptProps) {
54
- const context = useContext(AdaptParentContext)
55
-
56
- let enabled = !platform
57
- if (platform === 'touch') enabled = isTouchable
58
- if (platform === 'native') enabled = !isWeb
59
- if (platform === 'web') enabled = isWeb
60
-
61
- useIsomorphicLayoutEffect(() => {
62
- if (!enabled) return
63
- context?.setWhen(when as MediaQueryKey)
64
- }, [when, context, enabled])
65
-
66
- if (!enabled) {
67
- return null
68
- }
69
-
70
- return children
71
- },
72
- {
73
- Contents: AdaptContents,
74
- }
75
- )
1
+ export * from './Adapt'
@@ -0,0 +1,33 @@
1
+ /// <reference types="react" />
2
+ import { MediaQueryKey } from '@tamagui/core';
3
+ export type AdaptProps = {
4
+ when?: MediaQueryKey;
5
+ platform?: 'native' | 'web' | 'touch';
6
+ children?: any;
7
+ };
8
+ type Component = (props: any) => any;
9
+ type AdaptParentContextI = {
10
+ Contents: Component;
11
+ setWhen: (when: MediaQueryKey) => any;
12
+ };
13
+ export declare const AdaptParentContext: import("react").Context<AdaptParentContextI | null>;
14
+ export declare const AdaptContents: {
15
+ (props: any): import("react").FunctionComponentElement<any>;
16
+ shouldForwardSpace: boolean;
17
+ };
18
+ export declare const useAdaptParent: ({ Contents, }: {
19
+ Contents: AdaptParentContextI['Contents'];
20
+ }) => {
21
+ AdaptProvider: (props: {
22
+ children?: any;
23
+ }) => JSX.Element;
24
+ when: string | number | null;
25
+ };
26
+ export declare const Adapt: (({ platform, when, children }: AdaptProps) => any) & {
27
+ Contents: {
28
+ (props: any): import("react").FunctionComponentElement<any>;
29
+ shouldForwardSpace: boolean;
30
+ };
31
+ };
32
+ export {};
33
+ //# sourceMappingURL=Adapt.d.ts.map
package/types/index.d.ts CHANGED
@@ -1,26 +1,2 @@
1
- /// <reference types="react" />
2
- import { MediaQueryKey } from '@tamagui/core';
3
- export type AdaptProps = {
4
- when?: MediaQueryKey;
5
- platform?: 'native' | 'web' | 'touch';
6
- children?: any;
7
- };
8
- type Component = (props: any) => any;
9
- type AdaptParentContextI = {
10
- Contents: Component;
11
- setWhen: (when: MediaQueryKey) => any;
12
- };
13
- export declare const AdaptContents: () => import("react").FunctionComponentElement<any>;
14
- export declare const useAdaptParent: ({ Contents }: {
15
- Contents: AdaptParentContextI['Contents'];
16
- }) => {
17
- AdaptProvider: (props: {
18
- children?: any;
19
- }) => JSX.Element;
20
- when: string | number | null;
21
- };
22
- export declare const Adapt: (({ platform, when, children }: AdaptProps) => any) & {
23
- Contents: () => import("react").FunctionComponentElement<any>;
24
- };
25
- export {};
1
+ export * from './Adapt';
26
2
  //# sourceMappingURL=index.d.ts.map