@tamagui/adapt 1.0.1-beta.228

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,72 @@
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 src_exports = {};
20
+ __export(src_exports, {
21
+ Adapt: () => Adapt,
22
+ AdaptContents: () => AdaptContents,
23
+ useAdaptParent: () => useAdaptParent
24
+ });
25
+ 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({ when, children }) {
56
+ const context = (0, import_react.useContext)(AdaptParentContext);
57
+ (0, import_react.useLayoutEffect)(() => {
58
+ context == null ? void 0 : context.setWhen(when);
59
+ }, [when, context]);
60
+ return children;
61
+ },
62
+ {
63
+ Contents: AdaptContents
64
+ }
65
+ );
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ Adapt,
69
+ AdaptContents,
70
+ useAdaptParent
71
+ });
72
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.tsx"],
4
+ "sourcesContent": ["import { MediaQueryKey, withStaticProperties } from '@tamagui/core'\nimport { createContext, createElement, useContext, useLayoutEffect, useMemo, useState } from 'react'\n\nexport type AdaptProps = {\n when?: MediaQueryKey\n children?: any\n}\n\ntype Component = (props: any) => any\n\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({ when, children }: AdaptProps) {\n const context = useContext(AdaptParentContext)\n\n useLayoutEffect(() => {\n context?.setWhen(when as MediaQueryKey)\n }, [when, context])\n\n return children\n },\n {\n Contents: AdaptContents,\n }\n)\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmCM;AAnCN,kBAAoD;AACpD,mBAA6F;AAc7F,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,MAAM,SAAS,GAAe;AAC7C,UAAM,cAAU,yBAAW,kBAAkB;AAE7C,sCAAgB,MAAM;AACpB,yCAAS,QAAQ;AAAA,IACnB,GAAG,CAAC,MAAM,OAAO,CAAC;AAElB,WAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,UAAU;AAAA,EACZ;AACF;",
6
+ "names": ["Adapt"]
7
+ }
@@ -0,0 +1,46 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { withStaticProperties } from "@tamagui/core";
3
+ import { createContext, createElement, useContext, useLayoutEffect, useMemo, useState } from "react";
4
+ const AdaptParentContext = createContext(null);
5
+ const AdaptContents = () => {
6
+ const context = useContext(AdaptParentContext);
7
+ if (!context || !context.Contents) {
8
+ throw new Error(`Missing parent adapatable component, Adapt not supported here`);
9
+ }
10
+ return createElement(context.Contents);
11
+ };
12
+ const useAdaptParent = ({ Contents }) => {
13
+ const [when, setWhen] = useState(null);
14
+ const AdaptProvider = useMemo(() => {
15
+ const context = {
16
+ Contents,
17
+ setWhen
18
+ };
19
+ return (props) => /* @__PURE__ */ jsx(AdaptParentContext.Provider, {
20
+ value: context,
21
+ children: props.children
22
+ });
23
+ }, [Contents]);
24
+ return {
25
+ AdaptProvider,
26
+ when
27
+ };
28
+ };
29
+ const Adapt = withStaticProperties(
30
+ function Adapt2({ when, children }) {
31
+ const context = useContext(AdaptParentContext);
32
+ useLayoutEffect(() => {
33
+ context == null ? void 0 : context.setWhen(when);
34
+ }, [when, context]);
35
+ return children;
36
+ },
37
+ {
38
+ Contents: AdaptContents
39
+ }
40
+ );
41
+ export {
42
+ Adapt,
43
+ AdaptContents,
44
+ useAdaptParent
45
+ };
46
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.tsx"],
4
+ "sourcesContent": ["import { MediaQueryKey, withStaticProperties } from '@tamagui/core'\nimport { createContext, createElement, useContext, useLayoutEffect, useMemo, useState } from 'react'\n\nexport type AdaptProps = {\n when?: MediaQueryKey\n children?: any\n}\n\ntype Component = (props: any) => any\n\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({ when, children }: AdaptProps) {\n const context = useContext(AdaptParentContext)\n\n useLayoutEffect(() => {\n context?.setWhen(when as MediaQueryKey)\n }, [when, context])\n\n return children\n },\n {\n Contents: AdaptContents,\n }\n)\n"],
5
+ "mappings": "AAmCM;AAnCN,SAAwB,4BAA4B;AACpD,SAAS,eAAe,eAAe,YAAY,iBAAiB,SAAS,gBAAgB;AAc7F,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,MAAM,SAAS,GAAe;AAC7C,UAAM,UAAU,WAAW,kBAAkB;AAE7C,oBAAgB,MAAM;AACpB,yCAAS,QAAQ;AAAA,IACnB,GAAG,CAAC,MAAM,OAAO,CAAC;AAElB,WAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,UAAU;AAAA,EACZ;AACF;",
6
+ "names": ["Adapt"]
7
+ }
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@tamagui/adapt",
3
+ "version": "1.0.1-beta.228",
4
+ "types": "./types/index.d.ts",
5
+ "main": "dist/cjs",
6
+ "module": "dist/esm",
7
+ "files": [
8
+ "src",
9
+ "types",
10
+ "dist"
11
+ ],
12
+ "scripts": {
13
+ "build": "tamagui-build",
14
+ "watch": "tamagui-build --watch",
15
+ "lint": "eslint src",
16
+ "lint:fix": "yarn lint --fix",
17
+ "clean": "tamagui-build clean",
18
+ "clean:build": "tamagui-build clean:build"
19
+ },
20
+ "dependencies": {
21
+ "@tamagui/core": "^1.0.1-beta.228"
22
+ },
23
+ "devDependencies": {
24
+ "@tamagui/build": "^1.0.1-beta.228"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ }
29
+ }
package/src/index.tsx ADDED
@@ -0,0 +1,59 @@
1
+ import { MediaQueryKey, withStaticProperties } from '@tamagui/core'
2
+ import { createContext, createElement, useContext, useLayoutEffect, useMemo, useState } from 'react'
3
+
4
+ export type AdaptProps = {
5
+ when?: MediaQueryKey
6
+ children?: any
7
+ }
8
+
9
+ type Component = (props: any) => any
10
+
11
+ type AdaptParentContextI = {
12
+ Contents: Component
13
+ setWhen: (when: MediaQueryKey) => any
14
+ }
15
+
16
+ const AdaptParentContext = createContext<AdaptParentContextI | null>(null)
17
+
18
+ export const AdaptContents = () => {
19
+ const context = useContext(AdaptParentContext)
20
+ if (!context || !context.Contents) {
21
+ throw new Error(`Missing parent adapatable component, Adapt not supported here`)
22
+ }
23
+ return createElement(context.Contents)
24
+ }
25
+
26
+ export const useAdaptParent = ({ Contents }: { Contents: AdaptParentContextI['Contents'] }) => {
27
+ const [when, setWhen] = useState<MediaQueryKey | null>(null)
28
+
29
+ const AdaptProvider = useMemo(() => {
30
+ const context: AdaptParentContextI = {
31
+ Contents,
32
+ setWhen,
33
+ }
34
+
35
+ return (props: { children?: any }) => (
36
+ <AdaptParentContext.Provider value={context}>{props.children}</AdaptParentContext.Provider>
37
+ )
38
+ }, [Contents])
39
+
40
+ return {
41
+ AdaptProvider,
42
+ when,
43
+ }
44
+ }
45
+
46
+ export const Adapt = withStaticProperties(
47
+ function Adapt({ when, children }: AdaptProps) {
48
+ const context = useContext(AdaptParentContext)
49
+
50
+ useLayoutEffect(() => {
51
+ context?.setWhen(when as MediaQueryKey)
52
+ }, [when, context])
53
+
54
+ return children
55
+ },
56
+ {
57
+ Contents: AdaptContents,
58
+ }
59
+ )
@@ -0,0 +1,25 @@
1
+ /// <reference types="react" />
2
+ import { MediaQueryKey } from '@tamagui/core';
3
+ export declare type AdaptProps = {
4
+ when?: MediaQueryKey;
5
+ children?: any;
6
+ };
7
+ declare type Component = (props: any) => any;
8
+ declare type AdaptParentContextI = {
9
+ Contents: Component;
10
+ setWhen: (when: MediaQueryKey) => any;
11
+ };
12
+ export declare const AdaptContents: () => import("react").FunctionComponentElement<any>;
13
+ export declare const useAdaptParent: ({ Contents }: {
14
+ Contents: AdaptParentContextI['Contents'];
15
+ }) => {
16
+ AdaptProvider: (props: {
17
+ children?: any;
18
+ }) => JSX.Element;
19
+ when: string | number | null;
20
+ };
21
+ export declare const Adapt: (({ when, children }: AdaptProps) => any) & {
22
+ Contents: () => import("react").FunctionComponentElement<any>;
23
+ };
24
+ export {};
25
+ //# sourceMappingURL=index.d.ts.map