@tamagui/adapt 2.0.0-rc.4 → 2.0.0-rc.40
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 +203 -150
- package/dist/cjs/Adapt.native.js +250 -162
- 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 +173 -122
- package/dist/esm/Adapt.mjs.map +1 -1
- package/dist/esm/Adapt.native.js +218 -133
- 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 +10 -13
- package/src/Adapt.tsx +118 -32
- package/types/Adapt.d.ts +0 -1
- package/types/Adapt.d.ts.map +1 -1
- package/dist/cjs/Adapt.js +0 -146
- 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 -134
- 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,70 +43,96 @@ __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
|
-
|
|
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");
|
|
54
|
+
function createAdaptChildrenStore() {
|
|
55
|
+
let children = null;
|
|
56
|
+
const listeners = /* @__PURE__ */new Set();
|
|
57
|
+
return {
|
|
58
|
+
set(c) {
|
|
59
|
+
children = c;
|
|
60
|
+
for (const l of listeners) l();
|
|
61
|
+
},
|
|
62
|
+
get: () => children,
|
|
63
|
+
subscribe(callback) {
|
|
64
|
+
listeners.add(callback);
|
|
65
|
+
return () => listeners.delete(callback);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const AdaptChildrenStoreContext = (0, import_react.createContext)(null);
|
|
51
70
|
const AdaptContext = (0, import_core.createStyledContext)({
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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 () => {
|
|
102
128
|
AdaptPortals.delete(portalName);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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, {
|
|
108
136
|
value: scope,
|
|
109
137
|
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ProvideAdaptContext, {
|
|
110
138
|
Contents: FinalContents,
|
|
@@ -112,74 +140,99 @@ const AdaptContext = (0, import_core.createStyledContext)({
|
|
|
112
140
|
platform,
|
|
113
141
|
setPlatform,
|
|
114
142
|
setWhen,
|
|
115
|
-
setChildren,
|
|
116
143
|
portalName,
|
|
117
144
|
scopeName: scope,
|
|
118
145
|
children
|
|
119
146
|
})
|
|
120
|
-
})
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
children,
|
|
139
|
-
scope
|
|
140
|
-
} = props,
|
|
141
|
-
context = useAdaptContext(scope),
|
|
142
|
-
enabled = useAdaptIsActiveGiven(props);
|
|
143
|
-
(0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
144
|
-
context?.setWhen?.(when || enabled), context?.setPlatform?.(platform || null);
|
|
145
|
-
}, [when, platform, enabled, context.setWhen, context.setPlatform]), (0, import_constants.useIsomorphicLayoutEffect)(() => () => {
|
|
146
|
-
context?.setWhen?.(null), context?.setPlatform?.(null);
|
|
147
|
-
}, []);
|
|
148
|
-
let output;
|
|
149
|
-
if (typeof children == "function") {
|
|
150
|
-
const Component = context?.Contents;
|
|
151
|
-
output = children(Component ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(Component, {}) : null);
|
|
152
|
-
} else output = children;
|
|
153
|
-
return (0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
154
|
-
typeof children == "function" && output !== void 0 && context?.setChildren(output);
|
|
155
|
-
}, [output]), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_z_index_stack.StackZIndexContext, {
|
|
156
|
-
children: enabled ? output : null
|
|
157
|
-
});
|
|
158
|
-
}, {
|
|
159
|
-
Contents: AdaptContents
|
|
160
|
-
}),
|
|
161
|
-
AdaptPortalContents = props => {
|
|
162
|
-
const isActive = useAdaptIsActive(props.scope),
|
|
163
|
-
{
|
|
164
|
-
portalName
|
|
165
|
-
} = useAdaptContext(props.scope);
|
|
166
|
-
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_portal.PortalItem, {
|
|
167
|
-
passThrough: !isActive,
|
|
168
|
-
hostName: portalName,
|
|
169
|
-
children: props.children
|
|
170
|
-
});
|
|
171
|
-
},
|
|
172
|
-
useAdaptIsActiveGiven = ({
|
|
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,
|
|
173
165
|
when,
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
return
|
|
185
|
-
|
|
166
|
+
children,
|
|
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
|
+
};
|
|
209
|
+
function AdaptPortalTeleport({
|
|
210
|
+
isActive,
|
|
211
|
+
store,
|
|
212
|
+
children
|
|
213
|
+
}) {
|
|
214
|
+
(0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
215
|
+
if (!isActive) return;
|
|
216
|
+
store.set(children);
|
|
217
|
+
return () => store.set(null);
|
|
218
|
+
});
|
|
219
|
+
return isActive ? null : /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
220
|
+
children
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
const useAdaptIsActiveGiven = ({
|
|
224
|
+
when,
|
|
225
|
+
platform
|
|
226
|
+
}) => {
|
|
227
|
+
const media = (0, import_core.useMedia)();
|
|
228
|
+
if (when == null && platform == null) return false;
|
|
229
|
+
if (when === true) return true;
|
|
230
|
+
let enabled = false;
|
|
231
|
+
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;
|
|
232
|
+
if (platform && enabled == false) return false;
|
|
233
|
+
if (when && typeof when === "string") enabled = media[when];
|
|
234
|
+
return enabled;
|
|
235
|
+
};
|
|
236
|
+
const useAdaptIsActive = scope => {
|
|
237
|
+
return useAdaptIsActiveGiven(useAdaptContext(scope));
|
|
238
|
+
};
|