@tamagui/adapt 1.115.4 → 1.116.0

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.
@@ -1,56 +1,130 @@
1
- import React from "react";
2
1
  import { isAndroid, isIos, isTouchable, isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
3
- import { useMedia } from "@tamagui/core";
2
+ import { createStyledContext, useMedia } from "@tamagui/core";
4
3
  import { withStaticProperties } from "@tamagui/helpers";
4
+ import { PortalHost, PortalItem } from "@tamagui/portal";
5
+ import React, { createContext, useContext, useEffect, useId } from "react";
5
6
  import { jsx } from "react/jsx-runtime";
6
- const AdaptParentContext = React.createContext(null),
7
- AdaptContents = props => {
8
- const context = React.useContext(AdaptParentContext);
7
+ const CurrentAdaptContextScope = createContext(""),
8
+ AdaptContext = createStyledContext({
9
+ Contents: null,
10
+ scopeName: "",
11
+ portalName: "",
12
+ platform: null,
13
+ setPlatform: null,
14
+ when: null,
15
+ setChildren: null,
16
+ setWhen: null
17
+ }),
18
+ ProvideAdaptContext = ({
19
+ children,
20
+ ...context
21
+ }) => {
22
+ const scope = context.scopeName || "";
23
+ return /* @__PURE__ */jsx(CurrentAdaptContextScope.Provider, {
24
+ value: scope,
25
+ children: /* @__PURE__ */jsx(AdaptContext.Provider, {
26
+ scope,
27
+ ...context,
28
+ children
29
+ })
30
+ });
31
+ },
32
+ useAdaptContext = (scope = "") => {
33
+ const contextScope = useContext(CurrentAdaptContextScope);
34
+ return AdaptContext.useStyledContext(scope === "" && contextScope || scope);
35
+ },
36
+ AdaptPortals = /* @__PURE__ */new Map(),
37
+ AdaptParent = ({
38
+ children,
39
+ Contents,
40
+ scope,
41
+ portal
42
+ }) => {
43
+ const portalName = `AdaptPortal${scope}`,
44
+ id = useId();
45
+ let FinalContents = Contents || AdaptPortals.get(id);
46
+ FinalContents || (FinalContents = () => /* @__PURE__ */jsx(PortalHost, {
47
+ name: portalName,
48
+ forwardProps: typeof portal == "boolean" ? void 0 : portal?.forwardProps
49
+ }), AdaptPortals.set(id, FinalContents)), useEffect(() => () => {
50
+ AdaptPortals.delete(id);
51
+ }, []);
52
+ const [when, setWhen] = React.useState(null),
53
+ [platform, setPlatform] = React.useState(null),
54
+ [children2, setChildren] = React.useState(null);
55
+ return /* @__PURE__ */jsx(ProvideAdaptContext, {
56
+ Contents: FinalContents,
57
+ when,
58
+ platform,
59
+ setPlatform,
60
+ setWhen,
61
+ setChildren,
62
+ portalName,
63
+ scopeName: scope,
64
+ children
65
+ });
66
+ },
67
+ AdaptContents = ({
68
+ scope,
69
+ ...rest
70
+ }) => {
71
+ const context = useAdaptContext(scope);
9
72
  if (!context?.Contents) throw new Error(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.");
10
- return React.createElement(context.Contents, props);
73
+ return React.createElement(context.Contents, {
74
+ ...rest,
75
+ key: "stable"
76
+ });
11
77
  };
12
78
  AdaptContents.shouldForwardSpace = !0;
13
- const useAdaptParent = ({
14
- Contents
15
- }) => {
16
- const [when, setWhen] = React.useState(null);
17
- return {
18
- AdaptProvider: React.useMemo(() => {
19
- const context = {
20
- Contents,
21
- setWhen
22
- };
23
- function AdaptProviderView(props) {
24
- return /* @__PURE__ */jsx(AdaptParentContext.Provider, {
25
- value: context,
26
- children: props.children
27
- });
28
- }
29
- return AdaptProviderView;
30
- }, [Contents]),
31
- when
32
- };
79
+ const Adapt = withStaticProperties(function (props) {
80
+ const {
81
+ platform,
82
+ when,
83
+ children,
84
+ scope
85
+ } = props,
86
+ context = useAdaptContext(scope),
87
+ scopeName = scope ?? context.scopeName,
88
+ enabled = useAdaptIsActiveGiven(props);
89
+ useIsomorphicLayoutEffect(() => {
90
+ context?.setWhen(when || enabled), context?.setPlatform(platform || null);
91
+ }, [when, platform, context, enabled]), useIsomorphicLayoutEffect(() => () => {
92
+ context?.setWhen(null);
93
+ }, []);
94
+ let output;
95
+ if (typeof children == "function") {
96
+ const Component = context?.Contents;
97
+ output = children(Component ? /* @__PURE__ */jsx(Component, {}) : null);
98
+ } else output = children;
99
+ return useEffect(() => {
100
+ typeof children == "function" && output !== void 0 && context?.setChildren(output);
101
+ }, [output]), /* @__PURE__ */jsx(CurrentAdaptContextScope.Provider, {
102
+ value: scopeName,
103
+ children: enabled ? output : null
104
+ });
105
+ }, {
106
+ Contents: AdaptContents
107
+ }),
108
+ AdaptPortalContents = props => {
109
+ const {
110
+ portalName
111
+ } = useAdaptContext(props.scope);
112
+ return /* @__PURE__ */jsx(PortalItem, {
113
+ hostName: portalName,
114
+ children: props.children
115
+ });
33
116
  },
34
- Adapt = withStaticProperties(function ({
35
- platform,
117
+ useAdaptIsActiveGiven = ({
36
118
  when,
37
- children
38
- }) {
39
- const context = React.useContext(AdaptParentContext),
40
- media = useMedia();
119
+ platform
120
+ }) => {
121
+ const media = useMedia();
41
122
  let enabled = !1;
42
- return typeof when == "function" ? enabled = when({
43
- media
44
- }) : (enabled = !platform, platform === "touch" && (enabled = isTouchable), platform === "native" && (enabled = !isWeb), platform === "web" && (enabled = isWeb), platform === "ios" && (enabled = isIos), platform === "android" && (enabled = isAndroid), when && !media[when] && (enabled = !1)), useIsomorphicLayoutEffect(() => {
45
- if (enabled) return context?.setWhen(when || enabled), () => {
46
- context?.setWhen(null);
47
- };
48
- }, [when, context, enabled]), enabled ? typeof children == "function" ? children({
49
- enabled,
50
- media
51
- }) : children : null;
52
- }, {
53
- Contents: AdaptContents
54
- });
55
- export { Adapt, AdaptContents, AdaptParentContext, useAdaptParent };
123
+ return platform === "touch" && (enabled = isTouchable), platform === "native" && (enabled = !isWeb), platform === "web" && (enabled = isWeb), platform === "ios" && (enabled = isIos), platform === "android" && (enabled = isAndroid), when && typeof when == "string" && !media[when] && (enabled = !1), enabled;
124
+ },
125
+ useAdaptIsActive = scope => {
126
+ const props = useAdaptContext(scope);
127
+ return useAdaptIsActiveGiven(props);
128
+ };
129
+ export { Adapt, AdaptContents, AdaptContext, AdaptParent, AdaptPortalContents, useAdaptContext, useAdaptIsActive };
56
130
  //# sourceMappingURL=Adapt.mjs.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","isAndroid","isIos","isTouchable","isWeb","useIsomorphicLayoutEffect","useMedia","withStaticProperties","jsx","AdaptParentContext","createContext","AdaptContents","props","context","useContext","Contents","Error","process","env","NODE_ENV","createElement","shouldForwardSpace","useAdaptParent","when","setWhen","useState","AdaptProvider","useMemo","AdaptProviderView","Provider","value","children","Adapt","platform","media","enabled"],"sources":["../../src/Adapt.tsx"],"sourcesContent":[null],"mappings":"AAAA,OAAOA,KAAA,MAAW;AAClB,SACEC,SAAA,EACAC,KAAA,EACAC,WAAA,EACAC,KAAA,EACAC,yBAAA,QACK;AAEP,SAASC,QAAA,QAAgB;AACzB,SAASC,oBAAA,QAA4B;AAkD7B,SAAAC,GAAA;AA9BD,MAAMC,kBAAA,GAAqBT,KAAA,CAAMU,aAAA,CAA0C,IAAI;EAGzEC,aAAA,GAAiBC,KAAA,IAAe;IAC3C,MAAMC,OAAA,GAAUb,KAAA,CAAMc,UAAA,CAAWL,kBAAkB;IACnD,IAAI,CAACI,OAAA,EAASE,QAAA,EACZ,MAAM,IAAIC,KAAA,CACRC,OAAA,CAAQC,GAAA,CAAIC,QAAA,KAAa,eACrB,8CACA,0GACN;IAEF,OAAOnB,KAAA,CAAMoB,aAAA,CAAcP,OAAA,CAAQE,QAAA,EAAUH,KAAK;EACpD;AAEAD,aAAA,CAAcU,kBAAA,GAAqB;AAE5B,MAAMC,cAAA,GAAiBA,CAAC;IAC7BP;EACF,MAAqD;IACnD,MAAM,CAACQ,IAAA,EAAMC,OAAO,IAAIxB,KAAA,CAAMyB,QAAA,CAAe,IAAI;IAmBjD,OAAO;MACLC,aAAA,EAlBoB1B,KAAA,CAAM2B,OAAA,CAAQ,MAAM;QACxC,MAAMd,OAAA,GAA+B;UACnCE,QAAA;UACAS;QACF;QAEA,SAASI,kBAAkBhB,K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AUJ;EACZ,CACF","ignoreList":[]}
1
+ {"version":3,"names":["isAndroid","isIos","isTouchable","isWeb","useIsomorphicLayoutEffect","createStyledContext","useMedia","withStaticProperties","PortalHost","PortalItem","React","createContext","useContext","useEffect","useId","jsx","CurrentAdaptContextScope","AdaptContext","Contents","scopeName","portalName","platform","setPlatform","when","setChildren","setWhen","ProvideAdaptContext","children","context","scope","Provider","value","useAdaptContext","contextScope","useStyledContext","AdaptPortals","Map","AdaptParent","portal","id","FinalContents","get","name","forwardProps","set","delete","useState","children2","AdaptContents","rest","Error","process","env","NODE_ENV","createElement","key","shouldForwardSpace","Adapt","props","enabled","useAdaptIsActiveGiven","output","Component","AdaptPortalContents","hostName","media","useAdaptIsActive"],"sources":["../../src/Adapt.tsx"],"sourcesContent":[null],"mappings":"AAAA,SACEA,SAAA,EACAC,KAAA,EACAC,WAAA,EACAC,KAAA,EACAC,yBAAA,QACK;AAEP,SAASC,mBAAA,EAAqBC,QAAA,QAAgB;AAC9C,SAASC,oBAAA,QAA4B;AACrC,SAASC,UAAA,EAAYC,UAAA,QAAkB;AACvC,OAAOC,KAAA,IAASC,aAAA,EAAeC,UAAA,EAAYC,SAAA,EAAWC,KAAA,QAAa;AAwD7D,SAAAC,GAAA;AArBN,MAAMC,wBAAA,GAA2BL,aAAA,CAAc,EAAE;EAEpCM,YAAA,GAAeZ,mBAAA,CAAyC;IACnEa,QAAA,EAAU;IACVC,SAAA,EAAW;IACXC,UAAA,EAAY;IACZC,QAAA,EAAU;IACVC,WAAA,EAAa;IACbC,IAAA,EAAM;IACNC,WAAA,EAAa;IACbC,OAAA,EAAS;EACX,CAAC;EAEKC,mBAAA,GAAsBA,CAAC;IAC3BC,QAAA;IACA,GAAGC;EACL,MAA+C;IAC7C,MAAMC,KAAA,GAAQD,OAAA,CAAQT,SAAA,IAAa;IAEnC,OACE,eAAAJ,GAAA,CAACC,wBAAA,CAAyBc,QAAA,EAAzB;MAAkCC,KAAA,EAAOF,KAAA;MACxCF,QAA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AK;IACnC,OAAO+B,qBAAA,CAAsBF,KAAK;EACpC","ignoreList":[]}
@@ -1,59 +1,116 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import React from "react";
3
2
  import { isAndroid, isIos, isTouchable, isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
4
- import { useMedia } from "@tamagui/core";
3
+ import { createStyledContext, useMedia } from "@tamagui/core";
5
4
  import { withStaticProperties } from "@tamagui/helpers";
6
- var AdaptParentContext = /* @__PURE__ */ React.createContext(null), AdaptContents = function(props) {
7
- var context = React.useContext(AdaptParentContext);
5
+ import { PortalHost, PortalItem } from "@tamagui/portal";
6
+ import React, { createContext, useContext, useEffect, useId } from "react";
7
+ var CurrentAdaptContextScope = /* @__PURE__ */ createContext(""), AdaptContext = createStyledContext({
8
+ Contents: null,
9
+ scopeName: "",
10
+ portalName: "",
11
+ platform: null,
12
+ setPlatform: null,
13
+ when: null,
14
+ setChildren: null,
15
+ setWhen: null
16
+ }), ProvideAdaptContext = function(param) {
17
+ var { children, ...context } = param, scope = context.scopeName || "";
18
+ return /* @__PURE__ */ _jsx(CurrentAdaptContextScope.Provider, {
19
+ value: scope,
20
+ children: /* @__PURE__ */ _jsx(AdaptContext.Provider, {
21
+ scope,
22
+ ...context,
23
+ children
24
+ })
25
+ });
26
+ }, useAdaptContext = function() {
27
+ var scope = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "", contextScope = useContext(CurrentAdaptContextScope), context = AdaptContext.useStyledContext(scope === "" && contextScope || scope);
28
+ return context;
29
+ }, AdaptPortals = /* @__PURE__ */ new Map(), AdaptParent = function(param) {
30
+ var { children, Contents, scope, portal } = param, portalName = `AdaptPortal${scope}`, id = useId(), FinalContents = Contents || AdaptPortals.get(id);
31
+ FinalContents || (FinalContents = function() {
32
+ return /* @__PURE__ */ _jsx(PortalHost, {
33
+ name: portalName,
34
+ forwardProps: typeof portal == "boolean" ? void 0 : portal?.forwardProps
35
+ });
36
+ }, AdaptPortals.set(id, FinalContents)), useEffect(function() {
37
+ return function() {
38
+ AdaptPortals.delete(id);
39
+ };
40
+ }, []);
41
+ var [when, setWhen] = React.useState(null), [platform, setPlatform] = React.useState(null), [children2, setChildren] = React.useState(null);
42
+ return /* @__PURE__ */ _jsx(ProvideAdaptContext, {
43
+ Contents: FinalContents,
44
+ when,
45
+ platform,
46
+ setPlatform,
47
+ setWhen,
48
+ setChildren,
49
+ portalName,
50
+ scopeName: scope,
51
+ children
52
+ });
53
+ }, AdaptContents = function(param) {
54
+ var { scope, ...rest } = param, context = useAdaptContext(scope);
8
55
  if (!context?.Contents)
9
56
  throw new Error(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.");
10
- return /* @__PURE__ */ React.createElement(context.Contents, props);
57
+ return /* @__PURE__ */ React.createElement(context.Contents, {
58
+ ...rest,
59
+ key: "stable"
60
+ });
11
61
  };
12
62
  AdaptContents.shouldForwardSpace = !0;
13
- var useAdaptParent = function(param) {
14
- var { Contents } = param, [when, setWhen] = React.useState(null), AdaptProvider = React.useMemo(function() {
15
- var context = {
16
- Contents,
17
- setWhen
18
- };
19
- function AdaptProviderView(props) {
20
- return /* @__PURE__ */ _jsx(AdaptParentContext.Provider, {
21
- value: context,
22
- children: props.children
23
- });
24
- }
25
- return AdaptProviderView;
26
- }, [
27
- Contents
28
- ]);
29
- return {
30
- AdaptProvider,
31
- when
32
- };
33
- }, Adapt = withStaticProperties(function(param) {
34
- var { platform, when, children } = param, context = React.useContext(AdaptParentContext), media = useMedia(), enabled = !1;
35
- return typeof when == "function" ? enabled = when({
36
- media
37
- }) : (enabled = !platform, platform === "touch" && (enabled = isTouchable), platform === "native" && (enabled = !isWeb), platform === "web" && (enabled = isWeb), platform === "ios" && (enabled = isIos), platform === "android" && (enabled = isAndroid), when && !media[when] && (enabled = !1)), useIsomorphicLayoutEffect(function() {
38
- if (enabled)
39
- return context?.setWhen(when || enabled), function() {
40
- context?.setWhen(null);
41
- };
63
+ var Adapt = withStaticProperties(function(props) {
64
+ var { platform, when, children, scope } = props, context = useAdaptContext(scope), scopeName = scope ?? context.scopeName, enabled = useAdaptIsActiveGiven(props);
65
+ useIsomorphicLayoutEffect(function() {
66
+ context?.setWhen(when || enabled), context?.setPlatform(platform || null);
42
67
  }, [
43
68
  when,
69
+ platform,
44
70
  context,
45
71
  enabled
46
- ]), enabled ? typeof children == "function" ? children({
47
- enabled,
48
- media
49
- }) : children : null;
72
+ ]), useIsomorphicLayoutEffect(function() {
73
+ return function() {
74
+ context?.setWhen(null);
75
+ };
76
+ }, []);
77
+ var output;
78
+ if (typeof children == "function") {
79
+ var Component = context?.Contents;
80
+ output = children(Component ? /* @__PURE__ */ _jsx(Component, {}) : null);
81
+ } else
82
+ output = children;
83
+ return useEffect(function() {
84
+ typeof children == "function" && output !== void 0 && context?.setChildren(output);
85
+ }, [
86
+ output
87
+ ]), /* @__PURE__ */ _jsx(CurrentAdaptContextScope.Provider, {
88
+ value: scopeName,
89
+ children: enabled ? output : null
90
+ });
50
91
  }, {
51
92
  Contents: AdaptContents
52
- });
93
+ }), AdaptPortalContents = function(props) {
94
+ var { portalName } = useAdaptContext(props.scope);
95
+ return /* @__PURE__ */ _jsx(PortalItem, {
96
+ // passthrough={!isWeb && !isActive}
97
+ hostName: portalName,
98
+ children: props.children
99
+ });
100
+ }, useAdaptIsActiveGiven = function(param) {
101
+ var { when, platform } = param, media = useMedia(), enabled = !1;
102
+ return platform === "touch" && (enabled = isTouchable), platform === "native" && (enabled = !isWeb), platform === "web" && (enabled = isWeb), platform === "ios" && (enabled = isIos), platform === "android" && (enabled = isAndroid), when && typeof when == "string" && !media[when] && (enabled = !1), enabled;
103
+ }, useAdaptIsActive = function(scope) {
104
+ var props = useAdaptContext(scope);
105
+ return useAdaptIsActiveGiven(props);
106
+ };
53
107
  export {
54
108
  Adapt,
55
109
  AdaptContents,
56
- AdaptParentContext,
57
- useAdaptParent
110
+ AdaptContext,
111
+ AdaptParent,
112
+ AdaptPortalContents,
113
+ useAdaptContext,
114
+ useAdaptIsActive
58
115
  };
59
116
  //# sourceMappingURL=Adapt.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Users/n8/tamagui/code/ui/adapt/src/Adapt.tsx"],
4
- "mappings": ";AAAA,OAAOA,WAAW;AAClB,SACEC,WACAC,OACAC,aACAC,OACAC,iCACK;AAEP,SAASC,gBAAgB;AACzB,SAASC,4BAA4B;AAoB9B,IAAMC,qBAAqBR,sBAAMS,cAA0C,IAAA,GAGrEC,gBAAgB,SAACC,OAAAA;AAC5B,MAAMC,UAAUZ,MAAMa,WAAWL,kBAAAA;AACjC,MAAI,CAACI,SAASE;AACZ,UAAM,IAAIC,MACRC,QAAQC,IAAIC,aAAa,eACrB,8CACA,0GAA0G;AAGlH,SAAOlB,sBAAMmB,cAAcP,QAAQE,UAAUH,KAAAA;AAC/C;AAEAD,cAAcU,qBAAqB;AAE5B,IAAMC,iBAAiB,SAAA,OAAA;MAAC,EAC7BP,SAAQ,IACsC,OACxC,CAACQ,MAAMC,OAAAA,IAAWvB,MAAMwB,SAAe,IAAA,GAEvCC,gBAAgBzB,MAAM0B,QAAQ,WAAA;AAClC,QAAMd,UAA+B;MACnCE;MACAS;IACF;AAEA,aAASI,kBAAkBhB,OAAyB;AAClD,aACE,qBAACH,mBAAmBoB,UAAQ;QAACC,OAAOjB;kBACjCD,MAAMmB;;IAGb;AAEA,WAAOH;EACT,GAAG;IAACb;GAAS;AAEb,SAAO;IACLW;IACAH;EACF;AACF,GAEaS,QAAQxB,qBACnB,SAAe,OAAwC;MAAxC,EAAEyB,UAAUV,MAAMQ,SAAQ,IAA1B,OACPlB,UAAUZ,MAAMa,WAAWL,kBAAAA,GAC3ByB,QAAQ3B,SAAAA,GAEV4B,UAAU;AA2Bd,SAzBI,OAAOZ,QAAS,aAClBY,UAAUZ,KAAK;IAAEW;EAAM,CAAA,KAEvBC,UAAU,CAACF,UAEPA,aAAa,YAASE,UAAU/B,cAChC6B,aAAa,aAAUE,UAAU,CAAC9B,QAClC4B,aAAa,UAAOE,UAAU9B,QAC9B4B,aAAa,UAAOE,UAAUhC,QAC9B8B,aAAa,cAAWE,UAAUjC,YAElCqB,QAAQ,CAACW,MAAMX,IAAAA,MACjBY,UAAU,MAId7B,0BAA0B,WAAA;AACxB,QAAK6B;AACLtB,aAAAA,SAASW,QAASD,QAAQY,OAAAA,GAEnB,WAAA;AACLtB,QAAAA,SAASW,QAAQ,IAAA;MACnB;EACF,GAAG;IAACD;IAAMV;IAASsB;GAAQ,GAEtBA,UAID,OAAOJ,YAAa,aACfA,SAAS;IAAEI;IAASD;EAAM,CAAA,IAG5BH,WAPE;AAQX,GACA;EACEhB,UAAUJ;AACZ,CAAA;",
5
- "names": ["React", "isAndroid", "isIos", "isTouchable", "isWeb", "useIsomorphicLayoutEffect", "useMedia", "withStaticProperties", "AdaptParentContext", "createContext", "AdaptContents", "props", "context", "useContext", "Contents", "Error", "process", "env", "NODE_ENV", "createElement", "shouldForwardSpace", "useAdaptParent", "when", "setWhen", "useState", "AdaptProvider", "useMemo", "AdaptProviderView", "Provider", "value", "children", "Adapt", "platform", "media", "enabled"]
4
+ "mappings": ";AAAA,SACEA,WACAC,OACAC,aACAC,OACAC,iCACK;AAEP,SAASC,qBAAqBC,gBAAgB;AAC9C,SAASC,4BAA4B;AACrC,SAASC,YAAYC,kBAAkB;AACvC,OAAOC,SAASC,eAAeC,YAAYC,WAAWC,aAAa;AAmCnE,IAAMC,2BAA2BJ,8BAAc,EAAA,GAElCK,eAAeX,oBAAyC;EACnEY,UAAU;EACVC,WAAW;EACXC,YAAY;EACZC,UAAU;EACVC,aAAa;EACbC,MAAM;EACNC,aAAa;EACbC,SAAS;AACX,CAAA,GAEMC,sBAAsB,SAAA,OAAA;MAAC,EAC3BC,UACA,GAAGC,QAAAA,IACqC,OAClCC,QAAQD,QAAQT,aAAa;AAEnC,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6C,QAAQ3D,SAAAA,GAEVqD,UAAU;AAEd,SAAIvC,aAAa,YAASuC,UAAUzD,cAChCkB,aAAa,aAAUuC,UAAU,CAACxD,QAClCiB,aAAa,UAAOuC,UAAUxD,QAC9BiB,aAAa,UAAOuC,UAAU1D,QAC9BmB,aAAa,cAAWuC,UAAU3D,YAElCsB,QAAQ,OAAOA,QAAS,YAAY,CAAC2C,MAAM3C,IAAAA,MAC7CqC,UAAU,KAGLA;AACT,GAEaO,mBAAmB,SAACtC,OAAAA;AAC/B,MAAM8B,QAAQ3B,gBAAgBH,KAAAA;AAC9B,SAAOgC,sBAAsBF,KAAAA;AAC/B;",
5
+ "names": ["isAndroid", "isIos", "isTouchable", "isWeb", "useIsomorphicLayoutEffect", "createStyledContext", "useMedia", "withStaticProperties", "PortalHost", "PortalItem", "React", "createContext", "useContext", "useEffect", "useId", "CurrentAdaptContextScope", "AdaptContext", "Contents", "scopeName", "portalName", "platform", "setPlatform", "when", "setChildren", "setWhen", "ProvideAdaptContext", "children", "context", "scope", "Provider", "value", "useAdaptContext", "contextScope", "useStyledContext", "AdaptPortals", "Map", "AdaptParent", "portal", "id", "FinalContents", "get", "name", "forwardProps", "undefined", "set", "delete", "useState", "children2", "AdaptContents", "rest", "Error", "process", "env", "NODE_ENV", "createElement", "key", "shouldForwardSpace", "Adapt", "props", "enabled", "useAdaptIsActiveGiven", "output", "Component", "AdaptPortalContents", "hostName", "media", "useAdaptIsActive"]
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/adapt",
3
- "version": "1.115.4",
3
+ "version": "1.116.0",
4
4
  "types": "./types/index.d.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
@@ -29,12 +29,13 @@
29
29
  }
30
30
  },
31
31
  "dependencies": {
32
- "@tamagui/constants": "1.115.4",
33
- "@tamagui/core": "1.115.4",
34
- "@tamagui/helpers": "1.115.4"
32
+ "@tamagui/constants": "1.116.0",
33
+ "@tamagui/core": "1.116.0",
34
+ "@tamagui/helpers": "1.116.0",
35
+ "@tamagui/portal": "1.116.0"
35
36
  },
36
37
  "devDependencies": {
37
- "@tamagui/build": "1.115.4"
38
+ "@tamagui/build": "1.116.0"
38
39
  },
39
40
  "publishConfig": {
40
41
  "access": "public"