@tamagui/adapt 2.0.0-rc.9 → 2.0.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.
- package/dist/cjs/Adapt.cjs +192 -188
- package/dist/cjs/Adapt.native.js +217 -207
- package/dist/cjs/Adapt.native.js.map +1 -1
- package/dist/cjs/index.cjs +7 -5
- package/dist/cjs/index.native.js +7 -5
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/Adapt.mjs +160 -158
- package/dist/esm/Adapt.mjs.map +1 -1
- package/dist/esm/Adapt.native.js +185 -178
- package/dist/esm/Adapt.native.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -6
- package/package.json +9 -8
- package/src/Adapt.tsx +19 -21
- package/types/Adapt.d.ts +0 -1
- package/types/Adapt.d.ts.map +1 -1
- package/dist/cjs/Adapt.js +0 -188
- package/dist/cjs/Adapt.js.map +0 -6
- package/dist/cjs/index.js +0 -15
- package/dist/cjs/index.js.map +0 -6
- package/dist/esm/Adapt.js +0 -177
- package/dist/esm/Adapt.js.map +0 -6
package/dist/cjs/Adapt.cjs
CHANGED
|
@@ -2,33 +2,35 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
6
|
-
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: true
|
|
33
|
+
}), mod);
|
|
32
34
|
var Adapt_exports = {};
|
|
33
35
|
__export(Adapt_exports, {
|
|
34
36
|
Adapt: () => Adapt,
|
|
@@ -41,14 +43,14 @@ __export(Adapt_exports, {
|
|
|
41
43
|
useAdaptIsActive: () => useAdaptIsActive
|
|
42
44
|
});
|
|
43
45
|
module.exports = __toCommonJS(Adapt_exports);
|
|
44
|
-
var import_constants = require("@tamagui/constants")
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
var import_constants = require("@tamagui/constants");
|
|
47
|
+
var import_core = require("@tamagui/core");
|
|
48
|
+
var import_helpers = require("@tamagui/helpers");
|
|
49
|
+
var import_native = require("@tamagui/native");
|
|
50
|
+
var import_portal = require("@tamagui/portal");
|
|
51
|
+
var import_z_index_stack = require("@tamagui/z-index-stack");
|
|
52
|
+
var import_react = __toESM(require("react"), 1);
|
|
53
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
52
54
|
function createAdaptChildrenStore() {
|
|
53
55
|
let children = null;
|
|
54
56
|
const listeners = /* @__PURE__ */new Set();
|
|
@@ -59,177 +61,179 @@ function createAdaptChildrenStore() {
|
|
|
59
61
|
},
|
|
60
62
|
get: () => children,
|
|
61
63
|
subscribe(callback) {
|
|
62
|
-
|
|
64
|
+
listeners.add(callback);
|
|
65
|
+
return () => listeners.delete(callback);
|
|
63
66
|
}
|
|
64
67
|
};
|
|
65
68
|
}
|
|
66
|
-
const AdaptChildrenStoreContext = (0, import_react.createContext)(null)
|
|
67
|
-
emptySubscribe = () => () => {},
|
|
68
|
-
emptyGet = () => null;
|
|
69
|
-
function TeleportAdaptContents() {
|
|
70
|
-
const store = (0, import_react.useContext)(AdaptChildrenStoreContext),
|
|
71
|
-
children = import_react.default.useSyncExternalStore(store?.subscribe ?? emptySubscribe, store?.get ?? emptyGet, store?.get ?? emptyGet);
|
|
72
|
-
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
73
|
-
children
|
|
74
|
-
});
|
|
75
|
-
}
|
|
69
|
+
const AdaptChildrenStoreContext = (0, import_react.createContext)(null);
|
|
76
70
|
const AdaptContext = (0, import_core.createStyledContext)({
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
71
|
+
Contents: null,
|
|
72
|
+
scopeName: "",
|
|
73
|
+
portalName: "",
|
|
74
|
+
platform: null,
|
|
75
|
+
setPlatform: x => {},
|
|
76
|
+
when: null,
|
|
77
|
+
setWhen: () => {}
|
|
78
|
+
});
|
|
79
|
+
const LastAdaptContextScope = (0, import_react.createContext)("");
|
|
80
|
+
const ProvideAdaptContext = ({
|
|
81
|
+
children,
|
|
82
|
+
...context
|
|
83
|
+
}) => {
|
|
84
|
+
const scope = context.scopeName || "";
|
|
85
|
+
const lastScope = (0, import_react.useContext)(LastAdaptContextScope);
|
|
86
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(LastAdaptContextScope.Provider, {
|
|
87
|
+
value: lastScope || context.lastScope || "",
|
|
88
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(AdaptContext.Provider, {
|
|
89
|
+
scope,
|
|
90
|
+
lastScope: lastScope || context.lastScope,
|
|
91
|
+
...context,
|
|
92
|
+
children
|
|
93
|
+
})
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
const useAdaptContext = scope => {
|
|
97
|
+
const lastScope = (0, import_react.useContext)(LastAdaptContextScope);
|
|
98
|
+
const adaptScope = scope ?? lastScope;
|
|
99
|
+
return AdaptContext.useStyledContext(adaptScope);
|
|
100
|
+
};
|
|
101
|
+
const AdaptPortals = /* @__PURE__ */new Map();
|
|
102
|
+
const AdaptParent = ({
|
|
103
|
+
children,
|
|
104
|
+
Contents,
|
|
105
|
+
scope,
|
|
106
|
+
portal
|
|
107
|
+
}) => {
|
|
108
|
+
const id = (0, import_react.useId)();
|
|
109
|
+
const portalName = `AdaptPortal${scope}${id}`;
|
|
110
|
+
const childrenStoreRef = import_react.default.useRef(null);
|
|
111
|
+
if (!childrenStoreRef.current) childrenStoreRef.current = createAdaptChildrenStore();
|
|
112
|
+
const isTeleport = false;
|
|
113
|
+
const FinalContents = (0, import_react.useMemo)(() => {
|
|
114
|
+
if (Contents) return Contents;
|
|
115
|
+
if (AdaptPortals.has(portalName)) return AdaptPortals.get(portalName);
|
|
116
|
+
const element = () => {
|
|
117
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_portal.PortalHost, {
|
|
118
|
+
name: portalName,
|
|
119
|
+
forwardProps: typeof portal === "boolean" ? void 0 : portal?.forwardProps
|
|
120
|
+
}, id);
|
|
121
|
+
};
|
|
122
|
+
AdaptPortals.set(portalName, element);
|
|
123
|
+
return element;
|
|
124
|
+
}, [portalName, Contents, isTeleport]);
|
|
125
|
+
(0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
126
|
+
AdaptPortals.set(portalName, FinalContents);
|
|
127
|
+
return () => {
|
|
128
|
+
AdaptPortals.delete(portalName);
|
|
129
|
+
};
|
|
130
|
+
}, [portalName, isTeleport]);
|
|
131
|
+
const [when, setWhen] = import_react.default.useState(null);
|
|
132
|
+
const [platform, setPlatform] = import_react.default.useState(null);
|
|
133
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(AdaptChildrenStoreContext.Provider, {
|
|
134
|
+
value: childrenStoreRef.current,
|
|
135
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(LastAdaptContextScope.Provider, {
|
|
136
|
+
value: scope,
|
|
137
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ProvideAdaptContext, {
|
|
138
|
+
Contents: FinalContents,
|
|
139
|
+
when,
|
|
140
|
+
platform,
|
|
141
|
+
setPlatform,
|
|
142
|
+
setWhen,
|
|
143
|
+
portalName,
|
|
144
|
+
scopeName: scope,
|
|
99
145
|
children
|
|
100
146
|
})
|
|
101
|
-
})
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
147
|
+
})
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
const AdaptContents = ({
|
|
151
|
+
scope,
|
|
152
|
+
...rest
|
|
153
|
+
}) => {
|
|
154
|
+
const context = useAdaptContext(scope);
|
|
155
|
+
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.`);
|
|
156
|
+
return import_react.default.createElement(context.Contents, {
|
|
157
|
+
...rest,
|
|
158
|
+
key: `stable`
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
AdaptContents.shouldForwardSpace = true;
|
|
162
|
+
const Adapt = (0, import_helpers.withStaticProperties)(function Adapt2(props) {
|
|
163
|
+
const {
|
|
164
|
+
platform,
|
|
165
|
+
when,
|
|
110
166
|
children,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
})
|
|
154
|
-
});
|
|
155
|
-
},
|
|
156
|
-
AdaptContents = ({
|
|
157
|
-
scope,
|
|
158
|
-
...rest
|
|
159
|
-
}) => {
|
|
160
|
-
const context = useAdaptContext(scope);
|
|
161
|
-
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.");
|
|
162
|
-
return import_react.default.createElement(context.Contents, {
|
|
163
|
-
...rest,
|
|
164
|
-
key: "stable"
|
|
165
|
-
});
|
|
166
|
-
};
|
|
167
|
-
AdaptContents.shouldForwardSpace = !0;
|
|
168
|
-
const Adapt = (0, import_helpers.withStaticProperties)(function (props) {
|
|
169
|
-
const {
|
|
170
|
-
platform,
|
|
171
|
-
when,
|
|
172
|
-
children,
|
|
173
|
-
scope
|
|
174
|
-
} = props,
|
|
175
|
-
context = useAdaptContext(scope),
|
|
176
|
-
enabled = useAdaptIsActiveGiven(props);
|
|
177
|
-
(0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
178
|
-
context?.setWhen?.(when || enabled), context?.setPlatform?.(platform || null);
|
|
179
|
-
}, [when, platform, enabled, context.setWhen, context.setPlatform]), (0, import_constants.useIsomorphicLayoutEffect)(() => () => {
|
|
180
|
-
context?.setWhen?.(null), context?.setPlatform?.(null);
|
|
181
|
-
}, []);
|
|
182
|
-
let output;
|
|
183
|
-
if (typeof children == "function") {
|
|
184
|
-
const Component = context?.Contents;
|
|
185
|
-
output = children(Component ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(Component, {}) : null);
|
|
186
|
-
} else output = children;
|
|
187
|
-
return (0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
188
|
-
typeof children == "function" && output !== void 0 && context?.setChildren(output);
|
|
189
|
-
}, [output]), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_z_index_stack.StackZIndexContext, {
|
|
190
|
-
children: enabled ? output : null
|
|
191
|
-
});
|
|
192
|
-
}, {
|
|
193
|
-
Contents: AdaptContents
|
|
194
|
-
}),
|
|
195
|
-
AdaptPortalContents = props => {
|
|
196
|
-
const isActive = useAdaptIsActive(props.scope),
|
|
197
|
-
{
|
|
198
|
-
portalName
|
|
199
|
-
} = useAdaptContext(props.scope),
|
|
200
|
-
childrenStore = (0, import_react.useContext)(AdaptChildrenStoreContext);
|
|
201
|
-
return !import_constants.isWeb && (0, import_native.getPortal)().state.type === "teleport" && childrenStore ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(AdaptPortalTeleport, {
|
|
202
|
-
isActive,
|
|
203
|
-
store: childrenStore,
|
|
204
|
-
children: props.children
|
|
205
|
-
}) : /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_portal.PortalItem, {
|
|
206
|
-
passThrough: !isActive,
|
|
207
|
-
hostName: portalName,
|
|
208
|
-
children: props.children
|
|
209
|
-
});
|
|
210
|
-
};
|
|
167
|
+
scope
|
|
168
|
+
} = props;
|
|
169
|
+
const context = useAdaptContext(scope);
|
|
170
|
+
const enabled = useAdaptIsActiveGiven(props);
|
|
171
|
+
(0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
172
|
+
context?.setWhen?.(when || enabled);
|
|
173
|
+
context?.setPlatform?.(platform || null);
|
|
174
|
+
}, [when, platform, enabled, context.setWhen, context.setPlatform]);
|
|
175
|
+
(0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
176
|
+
return () => {
|
|
177
|
+
context?.setWhen?.(null);
|
|
178
|
+
context?.setPlatform?.(null);
|
|
179
|
+
};
|
|
180
|
+
}, []);
|
|
181
|
+
let output;
|
|
182
|
+
if (typeof children === "function") {
|
|
183
|
+
const Component = context?.Contents;
|
|
184
|
+
output = children(Component ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(Component, {}) : null);
|
|
185
|
+
} else output = children;
|
|
186
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_z_index_stack.StackZIndexContext, {
|
|
187
|
+
children: !enabled ? null : output
|
|
188
|
+
});
|
|
189
|
+
}, {
|
|
190
|
+
Contents: AdaptContents
|
|
191
|
+
});
|
|
192
|
+
const AdaptPortalContents = props => {
|
|
193
|
+
const isActive = useAdaptIsActive(props.scope);
|
|
194
|
+
const {
|
|
195
|
+
portalName
|
|
196
|
+
} = useAdaptContext(props.scope);
|
|
197
|
+
const childrenStore = (0, import_react.useContext)(AdaptChildrenStoreContext);
|
|
198
|
+
if (!import_constants.isWeb && (0, import_native.getPortal)().state.type === "teleport" && childrenStore) return /* @__PURE__ */(0, import_jsx_runtime.jsx)(AdaptPortalTeleport, {
|
|
199
|
+
isActive,
|
|
200
|
+
store: childrenStore,
|
|
201
|
+
children: props.children
|
|
202
|
+
});
|
|
203
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_portal.PortalItem, {
|
|
204
|
+
passThrough: !isActive,
|
|
205
|
+
hostName: portalName,
|
|
206
|
+
children: props.children
|
|
207
|
+
});
|
|
208
|
+
};
|
|
211
209
|
function AdaptPortalTeleport({
|
|
212
210
|
isActive,
|
|
213
211
|
store,
|
|
214
212
|
children
|
|
215
213
|
}) {
|
|
216
|
-
|
|
217
|
-
if (isActive)
|
|
218
|
-
})
|
|
214
|
+
(0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
215
|
+
if (isActive) store.set(children);else store.set(null);
|
|
216
|
+
});
|
|
217
|
+
(0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
218
|
+
return () => store.set(null);
|
|
219
|
+
}, [store]);
|
|
220
|
+
return isActive ? null : /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
219
221
|
children
|
|
220
222
|
});
|
|
221
223
|
}
|
|
222
224
|
const useAdaptIsActiveGiven = ({
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
225
|
+
when,
|
|
226
|
+
platform
|
|
227
|
+
}) => {
|
|
228
|
+
const media = (0, import_core.useMedia)();
|
|
229
|
+
if (when == null && platform == null) return false;
|
|
230
|
+
if (when === true) return true;
|
|
231
|
+
let enabled = false;
|
|
232
|
+
if (platform === "touch") enabled = import_constants.isTouchable;else if (platform === "native") enabled = !import_constants.isWeb;else if (platform === "web") enabled = import_constants.isWeb;else if (platform === "ios") enabled = import_constants.isIos;else if (platform === "android") enabled = import_constants.isAndroid;
|
|
233
|
+
if (platform && enabled == false) return false;
|
|
234
|
+
if (when && typeof when === "string") enabled = media[when];
|
|
235
|
+
return enabled;
|
|
236
|
+
};
|
|
237
|
+
const useAdaptIsActive = scope => {
|
|
238
|
+
return useAdaptIsActiveGiven(useAdaptContext(scope));
|
|
239
|
+
};
|