@tamagui/adapt 1.116.0 → 1.116.2

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,132 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: !0 });
9
+ }, __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from == "object" || typeof from == "function")
11
+ for (let key of __getOwnPropNames(from))
12
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ return to;
14
+ };
15
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
+ // If the importer is in node compatibility mode or this is not an ESM
17
+ // file that has been converted to a CommonJS file using a Babel-
18
+ // compatible transform (i.e. "__esModule" has not been set), then set
19
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
21
+ mod
22
+ )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
23
+ var Adapt_exports = {};
24
+ __export(Adapt_exports, {
25
+ Adapt: () => Adapt,
26
+ AdaptContents: () => AdaptContents,
27
+ AdaptContext: () => AdaptContext,
28
+ AdaptParent: () => AdaptParent,
29
+ AdaptPortalContents: () => AdaptPortalContents,
30
+ useAdaptContext: () => useAdaptContext,
31
+ useAdaptIsActive: () => useAdaptIsActive
32
+ });
33
+ module.exports = __toCommonJS(Adapt_exports);
34
+ var import_constants = require("@tamagui/constants"), import_core = require("@tamagui/core"), import_helpers = require("@tamagui/helpers"), import_portal = require("@tamagui/portal"), import_react = __toESM(require("react")), import_jsx_runtime = require("react/jsx-runtime");
35
+ const CurrentAdaptContextScope = (0, import_react.createContext)(""), AdaptContext = (0, import_core.createStyledContext)({
36
+ Contents: null,
37
+ scopeName: "",
38
+ portalName: "",
39
+ platform: null,
40
+ setPlatform: null,
41
+ when: null,
42
+ setChildren: null,
43
+ setWhen: null
44
+ }), ProvideAdaptContext = ({
45
+ children,
46
+ ...context
47
+ }) => {
48
+ const scope = context.scopeName || "";
49
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CurrentAdaptContextScope.Provider, { value: scope, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AdaptContext.Provider, { scope, ...context, children }) });
50
+ }, useAdaptContext = (scope = "") => {
51
+ const contextScope = (0, import_react.useContext)(CurrentAdaptContextScope);
52
+ return AdaptContext.useStyledContext(
53
+ scope === "" && contextScope || scope
54
+ );
55
+ }, AdaptPortals = /* @__PURE__ */ new Map(), AdaptParent = ({ children, Contents, scope, portal }) => {
56
+ const portalName = `AdaptPortal${scope}`, id = (0, import_react.useId)();
57
+ let FinalContents = Contents || AdaptPortals.get(id);
58
+ FinalContents || (FinalContents = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
59
+ import_portal.PortalHost,
60
+ {
61
+ name: portalName,
62
+ forwardProps: typeof portal == "boolean" ? void 0 : portal?.forwardProps
63
+ }
64
+ ), AdaptPortals.set(id, FinalContents)), (0, import_react.useEffect)(() => () => {
65
+ AdaptPortals.delete(id);
66
+ }, []);
67
+ const [when, setWhen] = import_react.default.useState(null), [platform, setPlatform] = import_react.default.useState(null), [children2, setChildren] = import_react.default.useState(null);
68
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
69
+ ProvideAdaptContext,
70
+ {
71
+ Contents: FinalContents,
72
+ when,
73
+ platform,
74
+ setPlatform,
75
+ setWhen,
76
+ setChildren,
77
+ portalName,
78
+ scopeName: scope,
79
+ children
80
+ }
81
+ );
82
+ }, AdaptContents = ({ scope, ...rest }) => {
83
+ const context = useAdaptContext(scope);
84
+ if (!context?.Contents)
85
+ throw new Error(
86
+ process.env.NODE_ENV === "production" ? "tamagui.dev/docs/intro/errors#warning-002" : "You're rendering a Tamagui <Adapt /> component without nesting it inside a parent that is able to adapt."
87
+ );
88
+ return import_react.default.createElement(context.Contents, { ...rest, key: "stable" });
89
+ };
90
+ AdaptContents.shouldForwardSpace = !0;
91
+ const Adapt = (0, import_helpers.withStaticProperties)(
92
+ function(props) {
93
+ const { platform, when, children, scope } = props, context = useAdaptContext(scope), scopeName = scope ?? context.scopeName, enabled = useAdaptIsActiveGiven(props);
94
+ (0, import_constants.useIsomorphicLayoutEffect)(() => {
95
+ context?.setWhen(when || enabled), context?.setPlatform(platform || null);
96
+ }, [when, platform, context, enabled]), (0, import_constants.useIsomorphicLayoutEffect)(() => () => {
97
+ context?.setWhen(null);
98
+ }, []);
99
+ let output;
100
+ if (typeof children == "function") {
101
+ const Component = context?.Contents;
102
+ output = children(Component ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}) : null);
103
+ } else
104
+ output = children;
105
+ return (0, import_react.useEffect)(() => {
106
+ typeof children == "function" && output !== void 0 && context?.setChildren(output);
107
+ }, [output]), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CurrentAdaptContextScope.Provider, { value: scopeName, children: enabled ? output : null });
108
+ },
109
+ {
110
+ Contents: AdaptContents
111
+ }
112
+ ), AdaptPortalContents = (props) => {
113
+ const { portalName } = useAdaptContext(props.scope);
114
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
115
+ import_portal.PortalItem,
116
+ {
117
+ hostName: portalName,
118
+ children: props.children
119
+ }
120
+ );
121
+ }, useAdaptIsActiveGiven = ({
122
+ when,
123
+ platform
124
+ }) => {
125
+ const media = (0, import_core.useMedia)();
126
+ let enabled = !1;
127
+ 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), when && typeof when == "string" && !media[when] && (enabled = !1), enabled;
128
+ }, useAdaptIsActive = (scope) => {
129
+ const props = useAdaptContext(scope);
130
+ return useAdaptIsActiveGiven(props);
131
+ };
132
+ //# sourceMappingURL=Adapt.js.map
@@ -0,0 +1,15 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from == "object" || typeof from == "function")
7
+ for (let key of __getOwnPropNames(from))
8
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
+ return to;
10
+ }, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
11
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
12
+ var src_exports = {};
13
+ module.exports = __toCommonJS(src_exports);
14
+ __reExport(src_exports, require("./Adapt"), module.exports);
15
+ //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/adapt",
3
- "version": "1.116.0",
3
+ "version": "1.116.2",
4
4
  "types": "./types/index.d.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
@@ -29,13 +29,13 @@
29
29
  }
30
30
  },
31
31
  "dependencies": {
32
- "@tamagui/constants": "1.116.0",
33
- "@tamagui/core": "1.116.0",
34
- "@tamagui/helpers": "1.116.0",
35
- "@tamagui/portal": "1.116.0"
32
+ "@tamagui/constants": "1.116.2",
33
+ "@tamagui/core": "1.116.2",
34
+ "@tamagui/helpers": "1.116.2",
35
+ "@tamagui/portal": "1.116.2"
36
36
  },
37
37
  "devDependencies": {
38
- "@tamagui/build": "1.116.0"
38
+ "@tamagui/build": "1.116.2"
39
39
  },
40
40
  "publishConfig": {
41
41
  "access": "public"
File without changes
File without changes