@tamagui/adapt 2.7.7 → 3.0.0-beta.1093.1
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 +460 -206
- package/dist/cjs/Adapt.native.cjs +551 -0
- package/dist/cjs/Adapt.native.js +517 -253
- package/dist/cjs/Adapt.native.js.map +1 -1
- package/dist/cjs/index.cjs +9 -11
- package/dist/cjs/index.native.cjs +20 -0
- package/dist/cjs/index.native.js +9 -10
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/Adapt.mjs +437 -177
- package/dist/esm/Adapt.mjs.map +1 -1
- package/dist/esm/Adapt.native.js +494 -224
- package/dist/esm/Adapt.native.js.map +1 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/index.mjs +1 -2
- package/dist/esm/index.native.js +1 -2
- package/package.json +9 -8
- package/src/Adapt.tsx +505 -152
- package/types/Adapt.d.ts +74 -29
- package/types/Adapt.d.ts.map +1 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
package/dist/esm/Adapt.native.js
CHANGED
|
@@ -2,241 +2,511 @@ import { Fragment, jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { isAndroid, isIos, isTouchable, isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
3
3
|
import { createStyledContext, useMedia } from "@tamagui/core";
|
|
4
4
|
import { withStaticProperties } from "@tamagui/helpers";
|
|
5
|
-
import { getPortal } from "@tamagui/native";
|
|
6
|
-
import { PortalHost, PortalItem } from "@tamagui/portal";
|
|
7
5
|
import { StackZIndexContext } from "@tamagui/z-index-stack";
|
|
8
|
-
import React, { createContext, useContext, useId
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return /* @__PURE__ */jsx(Fragment, {
|
|
56
|
-
children: React.useSyncExternalStore((_store_subscribe = store === null || store === void 0 ? void 0 : store.subscribe) !== null && _store_subscribe !== void 0 ? _store_subscribe : emptySubscribe, (_store_get = store === null || store === void 0 ? void 0 : store.get) !== null && _store_get !== void 0 ? _store_get : emptyGet, (_store_get1 = store === null || store === void 0 ? void 0 : store.get) !== null && _store_get1 !== void 0 ? _store_get1 : emptyGet)
|
|
57
|
-
});
|
|
6
|
+
import React, { createContext, useContext, useId } from "react";
|
|
7
|
+
|
|
8
|
+
function createAdaptSlotStore() {
|
|
9
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
10
|
+
var store = {
|
|
11
|
+
element: null,
|
|
12
|
+
version: 0,
|
|
13
|
+
publish(element) {
|
|
14
|
+
store.element = element;
|
|
15
|
+
},
|
|
16
|
+
clear() {
|
|
17
|
+
store.element = null;
|
|
18
|
+
},
|
|
19
|
+
notify() {
|
|
20
|
+
store.version += 1;
|
|
21
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
22
|
+
try {
|
|
23
|
+
for (var _iterator = listeners[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
24
|
+
var listener = _step.value;
|
|
25
|
+
listener();
|
|
26
|
+
}
|
|
27
|
+
} catch (err) {
|
|
28
|
+
_didIteratorError = true;
|
|
29
|
+
_iteratorError = err;
|
|
30
|
+
} finally {
|
|
31
|
+
try {
|
|
32
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
33
|
+
_iterator.return();
|
|
34
|
+
}
|
|
35
|
+
} finally {
|
|
36
|
+
if (_didIteratorError) {
|
|
37
|
+
throw _iteratorError;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
getSnapshot() {
|
|
43
|
+
return store.version;
|
|
44
|
+
},
|
|
45
|
+
subscribe(callback) {
|
|
46
|
+
listeners.add(callback);
|
|
47
|
+
return function() {
|
|
48
|
+
listeners.delete(callback);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
return store;
|
|
58
53
|
}
|
|
54
|
+
var adaptContextKeys = [
|
|
55
|
+
"Contents",
|
|
56
|
+
"scopeName",
|
|
57
|
+
"portalName",
|
|
58
|
+
"active",
|
|
59
|
+
"setAdaptConfig",
|
|
60
|
+
"slot",
|
|
61
|
+
"handoff",
|
|
62
|
+
"targetFullyHidden",
|
|
63
|
+
"registerTarget",
|
|
64
|
+
"unregisterTarget",
|
|
65
|
+
"registerContents",
|
|
66
|
+
"unregisterContents",
|
|
67
|
+
"registerRenderCallback",
|
|
68
|
+
"unregisterRenderCallback"
|
|
69
|
+
];
|
|
59
70
|
var AdaptContext = createStyledContext({
|
|
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
|
-
|
|
71
|
+
Contents: null,
|
|
72
|
+
scopeName: "",
|
|
73
|
+
portalName: "",
|
|
74
|
+
active: false,
|
|
75
|
+
setAdaptConfig: function() {},
|
|
76
|
+
slot: null,
|
|
77
|
+
handoff: {
|
|
78
|
+
hidden: true,
|
|
79
|
+
onTransition: function() {}
|
|
80
|
+
},
|
|
81
|
+
targetFullyHidden: true,
|
|
82
|
+
registerTarget: function() {},
|
|
83
|
+
unregisterTarget: function() {},
|
|
84
|
+
registerContents: function() {},
|
|
85
|
+
unregisterContents: function() {},
|
|
86
|
+
registerRenderCallback: function() {},
|
|
87
|
+
unregisterRenderCallback: function() {}
|
|
88
|
+
}, { keys: adaptContextKeys });
|
|
89
|
+
var AdaptCapabilitiesContext = /* @__PURE__ */ createContext({});
|
|
90
|
+
var LastAdaptContextScope = /* @__PURE__ */ createContext("");
|
|
91
|
+
var ProvideAdaptContext = function(param) {
|
|
92
|
+
var { children, ...context } = param;
|
|
93
|
+
var scope = context.scopeName || "";
|
|
94
|
+
var lastScope = useContext(LastAdaptContextScope);
|
|
95
|
+
return /* @__PURE__ */ jsx(LastAdaptContextScope.Provider, {
|
|
96
|
+
value: lastScope || context.lastScope || "",
|
|
97
|
+
children: /* @__PURE__ */ jsx(AdaptContext.Provider, {
|
|
98
|
+
scope,
|
|
99
|
+
lastScope: lastScope || context.lastScope,
|
|
100
|
+
...context,
|
|
101
|
+
children
|
|
102
|
+
})
|
|
103
|
+
});
|
|
85
104
|
};
|
|
86
|
-
var useAdaptContext = function
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
105
|
+
var useAdaptContext = function(scope) {
|
|
106
|
+
var lastScope = useContext(LastAdaptContextScope);
|
|
107
|
+
var adaptScope = scope !== null && scope !== void 0 ? scope : lastScope;
|
|
108
|
+
return AdaptContext.useStyledContext(adaptScope);
|
|
90
109
|
};
|
|
91
|
-
|
|
92
|
-
var
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
110
|
+
function findAdaptConfig(children, scope) {
|
|
111
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
112
|
+
try {
|
|
113
|
+
for (var _iterator = React.Children.toArray(children)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
114
|
+
var child = _step.value;
|
|
115
|
+
if (!/* @__PURE__ */ React.isValidElement(child)) continue;
|
|
116
|
+
if (child.type === React.Fragment) {
|
|
117
|
+
var found = findAdaptConfig(child.props.children, scope);
|
|
118
|
+
if (found) return found;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (child.type === Adapt) {
|
|
122
|
+
var childProps = child.props;
|
|
123
|
+
if (childProps.scope == null || childProps.scope === scope) {
|
|
124
|
+
return childProps;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
} catch (err) {
|
|
129
|
+
_didIteratorError = true;
|
|
130
|
+
_iteratorError = err;
|
|
131
|
+
} finally {
|
|
132
|
+
try {
|
|
133
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
134
|
+
_iterator.return();
|
|
135
|
+
}
|
|
136
|
+
} finally {
|
|
137
|
+
if (_didIteratorError) {
|
|
138
|
+
throw _iteratorError;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
var AdaptParent = function(param) {
|
|
145
|
+
var { children, adaptChildren, Contents, scope, open, onOpenChange, state } = param;
|
|
146
|
+
var id = useId();
|
|
147
|
+
var portalName = `AdaptPortal${scope}${id}`;
|
|
148
|
+
var slotRef = React.useRef(null);
|
|
149
|
+
if (!slotRef.current) {
|
|
150
|
+
slotRef.current = createAdaptSlotStore();
|
|
151
|
+
}
|
|
152
|
+
var staticConfig = React.useMemo(function() {
|
|
153
|
+
var _findAdaptConfig;
|
|
154
|
+
return (_findAdaptConfig = findAdaptConfig(adaptChildren, scope)) !== null && _findAdaptConfig !== void 0 ? _findAdaptConfig : findAdaptConfig(children, scope);
|
|
155
|
+
}, [
|
|
156
|
+
adaptChildren,
|
|
157
|
+
children,
|
|
158
|
+
scope
|
|
159
|
+
]);
|
|
160
|
+
var [publishedConfig, setPublishedConfig] = React.useState(null);
|
|
161
|
+
var rawActive = useAdaptIsActiveGiven(staticConfig !== null && staticConfig !== void 0 ? staticConfig : publishedConfig);
|
|
162
|
+
var staticConfigRef = React.useRef(staticConfig);
|
|
163
|
+
staticConfigRef.current = staticConfig;
|
|
164
|
+
var setAdaptConfig = React.useCallback(function(config) {
|
|
165
|
+
if (staticConfigRef.current) return;
|
|
166
|
+
setPublishedConfig(config);
|
|
167
|
+
}, []);
|
|
168
|
+
var [exiting, setExiting] = React.useState(false);
|
|
169
|
+
var [present, setPresent] = React.useState(false);
|
|
170
|
+
var [targetFullyHidden, setTargetFullyHidden] = React.useState(!open);
|
|
171
|
+
var targetCountRef = React.useRef(0);
|
|
172
|
+
var contentsCountRef = React.useRef(0);
|
|
173
|
+
var renderCallbackCountRef = React.useRef(0);
|
|
174
|
+
var rawActiveRef = React.useRef(false);
|
|
175
|
+
var openRef = React.useRef(open);
|
|
176
|
+
var wasTargetHiddenRef = React.useRef(!rawActive);
|
|
177
|
+
var hasHadActiveTargetRef = React.useRef(false);
|
|
178
|
+
var shouldStartExit = !rawActive && present && Boolean(open);
|
|
179
|
+
var active = rawActive || exiting || shouldStartExit;
|
|
180
|
+
var targetHidden = !rawActive;
|
|
181
|
+
var skipNextAnimation = Boolean(rawActive && wasTargetHiddenRef.current && hasHadActiveTargetRef.current && open);
|
|
182
|
+
var releasePresenceLatch = React.useCallback(function() {
|
|
183
|
+
setExiting(false);
|
|
184
|
+
if (!rawActiveRef.current) {
|
|
185
|
+
setPresent(false);
|
|
186
|
+
}
|
|
187
|
+
}, []);
|
|
188
|
+
useIsomorphicLayoutEffect(function() {
|
|
189
|
+
if (shouldStartExit) {
|
|
190
|
+
setExiting(true);
|
|
191
|
+
}
|
|
192
|
+
}, [shouldStartExit]);
|
|
193
|
+
useIsomorphicLayoutEffect(function() {
|
|
194
|
+
rawActiveRef.current = rawActive;
|
|
195
|
+
openRef.current = open;
|
|
196
|
+
if (rawActive) {
|
|
197
|
+
hasHadActiveTargetRef.current = true;
|
|
198
|
+
}
|
|
199
|
+
wasTargetHiddenRef.current = targetHidden;
|
|
200
|
+
if (open && rawActive) {
|
|
201
|
+
setTargetFullyHidden(false);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (!open && !active) {
|
|
205
|
+
setTargetFullyHidden(true);
|
|
206
|
+
}
|
|
207
|
+
}, [
|
|
208
|
+
active,
|
|
209
|
+
open,
|
|
210
|
+
rawActive,
|
|
211
|
+
targetHidden
|
|
212
|
+
]);
|
|
213
|
+
useIsomorphicLayoutEffect(function() {
|
|
214
|
+
if (rawActive) {
|
|
215
|
+
setPresent(true);
|
|
216
|
+
} else if (!active) {
|
|
217
|
+
setPresent(false);
|
|
218
|
+
}
|
|
219
|
+
if (rawActive && exiting) {
|
|
220
|
+
setExiting(false);
|
|
221
|
+
}
|
|
222
|
+
}, [
|
|
223
|
+
active,
|
|
224
|
+
exiting,
|
|
225
|
+
rawActive
|
|
226
|
+
]);
|
|
227
|
+
var handoff = React.useMemo(function() {
|
|
228
|
+
return {
|
|
229
|
+
hidden: targetHidden,
|
|
230
|
+
skipNextAnimation,
|
|
231
|
+
onTransition(e) {
|
|
232
|
+
if (e.phase !== "end" || e.finished === false) return;
|
|
233
|
+
if (e.cause !== "close") {
|
|
234
|
+
setTargetFullyHidden(false);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (openRef.current && rawActiveRef.current) {
|
|
238
|
+
setTargetFullyHidden(false);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
setTargetFullyHidden(true);
|
|
242
|
+
releasePresenceLatch();
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
}, [
|
|
246
|
+
releasePresenceLatch,
|
|
247
|
+
skipNextAnimation,
|
|
248
|
+
targetHidden
|
|
249
|
+
]);
|
|
250
|
+
var registerTarget = React.useCallback(function() {
|
|
251
|
+
targetCountRef.current += 1;
|
|
252
|
+
if (process.env.NODE_ENV === "development" && targetCountRef.current > 1) {
|
|
253
|
+
console.error(`Adapt expected exactly one target in scope "${scope}", but ${targetCountRef.current} targets registered.`);
|
|
254
|
+
}
|
|
255
|
+
}, [scope]);
|
|
256
|
+
var unregisterTarget = React.useCallback(function() {
|
|
257
|
+
targetCountRef.current = Math.max(0, targetCountRef.current - 1);
|
|
258
|
+
}, []);
|
|
259
|
+
var registerContents = React.useCallback(function() {
|
|
260
|
+
contentsCountRef.current += 1;
|
|
261
|
+
}, []);
|
|
262
|
+
var unregisterContents = React.useCallback(function() {
|
|
263
|
+
contentsCountRef.current = Math.max(0, contentsCountRef.current - 1);
|
|
264
|
+
}, []);
|
|
265
|
+
var registerRenderCallback = React.useCallback(function() {
|
|
266
|
+
renderCallbackCountRef.current += 1;
|
|
267
|
+
}, []);
|
|
268
|
+
var unregisterRenderCallback = React.useCallback(function() {
|
|
269
|
+
renderCallbackCountRef.current = Math.max(0, renderCallbackCountRef.current - 1);
|
|
270
|
+
}, []);
|
|
271
|
+
React.useEffect(function() {
|
|
272
|
+
if (process.env.NODE_ENV !== "development") return;
|
|
273
|
+
if (!active) return;
|
|
274
|
+
var timer = setTimeout(function() {
|
|
275
|
+
if (rawActiveRef.current && targetCountRef.current === 0 && contentsCountRef.current === 0 && renderCallbackCountRef.current === 0) {
|
|
276
|
+
console.error(`Adapt is active in scope "${scope}" but no target registered with useAdaptTarget(), Adapt.Contents marker, or render callback consumed it.`);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
return function() {
|
|
280
|
+
return clearTimeout(timer);
|
|
281
|
+
};
|
|
282
|
+
}, [active, scope]);
|
|
283
|
+
var FinalContents = Contents || AdaptSlotContents;
|
|
284
|
+
return /* @__PURE__ */ jsx(LastAdaptContextScope.Provider, {
|
|
285
|
+
value: scope,
|
|
286
|
+
children: /* @__PURE__ */ jsx(ProvideAdaptContext, {
|
|
287
|
+
Contents: FinalContents,
|
|
288
|
+
active,
|
|
289
|
+
setAdaptConfig,
|
|
290
|
+
portalName,
|
|
291
|
+
scopeName: scope,
|
|
292
|
+
slot: slotRef.current,
|
|
293
|
+
open,
|
|
294
|
+
onOpenChange,
|
|
295
|
+
state,
|
|
296
|
+
handoff,
|
|
297
|
+
targetFullyHidden,
|
|
298
|
+
registerTarget,
|
|
299
|
+
unregisterTarget,
|
|
300
|
+
registerContents,
|
|
301
|
+
unregisterContents,
|
|
302
|
+
registerRenderCallback,
|
|
303
|
+
unregisterRenderCallback,
|
|
304
|
+
children
|
|
305
|
+
})
|
|
306
|
+
});
|
|
143
307
|
};
|
|
144
|
-
var AdaptContents = function
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
308
|
+
var AdaptContents = function(param) {
|
|
309
|
+
var { scope, ...rest } = param;
|
|
310
|
+
var context = useAdaptContext(scope);
|
|
311
|
+
if (!(context === null || context === void 0 ? void 0 : context.Contents)) {
|
|
312
|
+
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.`);
|
|
313
|
+
}
|
|
314
|
+
useIsomorphicLayoutEffect(function() {
|
|
315
|
+
if (!context.active) return;
|
|
316
|
+
context.registerContents();
|
|
317
|
+
return function() {
|
|
318
|
+
context.unregisterContents();
|
|
319
|
+
};
|
|
320
|
+
}, [
|
|
321
|
+
context.active,
|
|
322
|
+
context.registerContents,
|
|
323
|
+
context.unregisterContents
|
|
324
|
+
]);
|
|
325
|
+
return /* @__PURE__ */ React.createElement(context.Contents, {
|
|
326
|
+
...rest,
|
|
327
|
+
scope,
|
|
328
|
+
key: `stable`
|
|
329
|
+
});
|
|
155
330
|
};
|
|
156
331
|
AdaptContents.shouldForwardSpace = true;
|
|
157
332
|
var Adapt = withStaticProperties(function Adapt2(props) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
var
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
});
|
|
333
|
+
var { children, platform, scope, when } = props;
|
|
334
|
+
var context = useAdaptContext(scope);
|
|
335
|
+
var enabled = context.active;
|
|
336
|
+
var isRenderCallback = typeof children === "function";
|
|
337
|
+
useIsomorphicLayoutEffect(function() {
|
|
338
|
+
context.setAdaptConfig({
|
|
339
|
+
when,
|
|
340
|
+
platform
|
|
341
|
+
});
|
|
342
|
+
return function() {
|
|
343
|
+
context.setAdaptConfig(null);
|
|
344
|
+
};
|
|
345
|
+
}, [
|
|
346
|
+
when,
|
|
347
|
+
platform,
|
|
348
|
+
context.setAdaptConfig
|
|
349
|
+
]);
|
|
350
|
+
useIsomorphicLayoutEffect(function() {
|
|
351
|
+
if (!enabled || !isRenderCallback) return;
|
|
352
|
+
context.registerRenderCallback();
|
|
353
|
+
return function() {
|
|
354
|
+
context.unregisterRenderCallback();
|
|
355
|
+
};
|
|
356
|
+
}, [
|
|
357
|
+
enabled,
|
|
358
|
+
isRenderCallback,
|
|
359
|
+
context.registerRenderCallback,
|
|
360
|
+
context.unregisterRenderCallback
|
|
361
|
+
]);
|
|
362
|
+
var output;
|
|
363
|
+
if (isRenderCallback) {
|
|
364
|
+
var Component = context === null || context === void 0 ? void 0 : context.Contents;
|
|
365
|
+
output = children(Component ? /* @__PURE__ */ jsx(Component, {}) : null, getAdaptRenderState(context));
|
|
366
|
+
} else {
|
|
367
|
+
output = children;
|
|
368
|
+
}
|
|
369
|
+
return /* @__PURE__ */ jsx(StackZIndexContext, { children: !enabled ? null : output });
|
|
370
|
+
}, { Contents: AdaptContents });
|
|
371
|
+
var AdaptPortalContents = function(props) {
|
|
372
|
+
var isActive = useAdaptIsActive(props.scope);
|
|
373
|
+
var { slot } = useAdaptContext(props.scope);
|
|
374
|
+
return /* @__PURE__ */ jsx(AdaptSlotPublisher, {
|
|
375
|
+
isActive,
|
|
376
|
+
slot,
|
|
377
|
+
children: props.children
|
|
378
|
+
});
|
|
205
379
|
};
|
|
206
|
-
function
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
380
|
+
function AdaptSlotContents(param) {
|
|
381
|
+
var { scope } = param;
|
|
382
|
+
var { slot } = useAdaptContext(scope);
|
|
383
|
+
var _slot_subscribe, _slot_getSnapshot, _slot_getSnapshot1;
|
|
384
|
+
React.useSyncExternalStore((_slot_subscribe = slot === null || slot === void 0 ? void 0 : slot.subscribe) !== null && _slot_subscribe !== void 0 ? _slot_subscribe : emptySubscribe, (_slot_getSnapshot = slot === null || slot === void 0 ? void 0 : slot.getSnapshot) !== null && _slot_getSnapshot !== void 0 ? _slot_getSnapshot : emptySnapshot, (_slot_getSnapshot1 = slot === null || slot === void 0 ? void 0 : slot.getSnapshot) !== null && _slot_getSnapshot1 !== void 0 ? _slot_getSnapshot1 : emptySnapshot);
|
|
385
|
+
var _slot_element;
|
|
386
|
+
return /* @__PURE__ */ jsx(Fragment, { children: (_slot_element = slot === null || slot === void 0 ? void 0 : slot.element) !== null && _slot_element !== void 0 ? _slot_element : null });
|
|
387
|
+
}
|
|
388
|
+
function AdaptSlotPublisher(param) {
|
|
389
|
+
var { isActive, slot, children } = param;
|
|
390
|
+
var publishedRef = React.useRef(null);
|
|
391
|
+
useIsomorphicLayoutEffect(function() {
|
|
392
|
+
if (!slot) return;
|
|
393
|
+
var published = publishedRef.current;
|
|
394
|
+
if (published && published.isActive === isActive && published.element === children) {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
publishedRef.current = {
|
|
398
|
+
isActive,
|
|
399
|
+
element: children
|
|
400
|
+
};
|
|
401
|
+
if (isActive) {
|
|
402
|
+
slot.publish(children);
|
|
403
|
+
} else {
|
|
404
|
+
slot.clear();
|
|
405
|
+
}
|
|
406
|
+
slot.notify();
|
|
407
|
+
});
|
|
408
|
+
useIsomorphicLayoutEffect(function() {
|
|
409
|
+
return function() {
|
|
410
|
+
var _publishedRef_current;
|
|
411
|
+
if ((_publishedRef_current = publishedRef.current) === null || _publishedRef_current === void 0 ? void 0 : _publishedRef_current.isActive) {
|
|
412
|
+
slot === null || slot === void 0 ? void 0 : slot.clear();
|
|
413
|
+
slot === null || slot === void 0 ? void 0 : slot.notify();
|
|
414
|
+
}
|
|
415
|
+
publishedRef.current = null;
|
|
416
|
+
};
|
|
417
|
+
}, [slot]);
|
|
418
|
+
return isActive ? null : /* @__PURE__ */ jsx(Fragment, { children });
|
|
223
419
|
}
|
|
224
|
-
var
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
var media = useMedia();
|
|
230
|
-
if (when == null && platform == null) return false;
|
|
231
|
-
if (when === true) return true;
|
|
232
|
-
var enabled = false;
|
|
233
|
-
if (platform === "touch") enabled = isTouchable;else if (platform === "native") enabled = !isWeb;else if (platform === "web") enabled = isWeb;else if (platform === "ios") enabled = isIos;else if (platform === "android") enabled = isAndroid;
|
|
234
|
-
if (platform && enabled == false) return false;
|
|
235
|
-
if (when && typeof when === "string") enabled = media[when];
|
|
236
|
-
return enabled;
|
|
420
|
+
var emptySubscribe = function() {
|
|
421
|
+
return function() {};
|
|
422
|
+
};
|
|
423
|
+
var emptySnapshot = function() {
|
|
424
|
+
return 0;
|
|
237
425
|
};
|
|
238
|
-
var
|
|
239
|
-
|
|
426
|
+
var useAdaptIsActiveGiven = function(config) {
|
|
427
|
+
var media = useMedia();
|
|
428
|
+
var when = config === null || config === void 0 ? void 0 : config.when;
|
|
429
|
+
var platform = config === null || config === void 0 ? void 0 : config.platform;
|
|
430
|
+
if (when == null && platform == null) {
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
if (when === true) {
|
|
434
|
+
return true;
|
|
435
|
+
}
|
|
436
|
+
var enabled = false;
|
|
437
|
+
if (platform === "touch") enabled = isTouchable;
|
|
438
|
+
else if (platform === "native") enabled = !isWeb;
|
|
439
|
+
else if (platform === "web") enabled = isWeb;
|
|
440
|
+
else if (platform === "ios") enabled = isIos;
|
|
441
|
+
else if (platform === "android") enabled = isAndroid;
|
|
442
|
+
if (platform && enabled == false) {
|
|
443
|
+
return false;
|
|
444
|
+
}
|
|
445
|
+
if (when && typeof when === "string") {
|
|
446
|
+
enabled = media[when];
|
|
447
|
+
}
|
|
448
|
+
return enabled;
|
|
240
449
|
};
|
|
241
|
-
|
|
450
|
+
var useAdaptIsActive = function(scope) {
|
|
451
|
+
return useAdaptContext(scope).active;
|
|
452
|
+
};
|
|
453
|
+
function useAdaptTarget(scope) {
|
|
454
|
+
var context = useAdaptContext(scope);
|
|
455
|
+
useIsomorphicLayoutEffect(function() {
|
|
456
|
+
if (!context.active) return;
|
|
457
|
+
context.registerTarget();
|
|
458
|
+
return function() {
|
|
459
|
+
context.unregisterTarget();
|
|
460
|
+
};
|
|
461
|
+
}, [
|
|
462
|
+
context.active,
|
|
463
|
+
context.registerTarget,
|
|
464
|
+
context.unregisterTarget
|
|
465
|
+
]);
|
|
466
|
+
if (!context.active) {
|
|
467
|
+
return null;
|
|
468
|
+
}
|
|
469
|
+
return {
|
|
470
|
+
open: context.open,
|
|
471
|
+
onOpenChange: context.onOpenChange,
|
|
472
|
+
handoff: context.handoff,
|
|
473
|
+
state: context.state
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
var AdaptCapabilities = function(param) {
|
|
477
|
+
var { children, scroll, overlay, dismiss } = param;
|
|
478
|
+
var parent = useContext(AdaptCapabilitiesContext);
|
|
479
|
+
var value = React.useMemo(function() {
|
|
480
|
+
return {
|
|
481
|
+
scroll: scroll !== null && scroll !== void 0 ? scroll : parent.scroll,
|
|
482
|
+
overlay: overlay !== null && overlay !== void 0 ? overlay : parent.overlay,
|
|
483
|
+
dismiss: dismiss !== null && dismiss !== void 0 ? dismiss : parent.dismiss
|
|
484
|
+
};
|
|
485
|
+
}, [
|
|
486
|
+
dismiss,
|
|
487
|
+
overlay,
|
|
488
|
+
parent.dismiss,
|
|
489
|
+
parent.overlay,
|
|
490
|
+
parent.scroll,
|
|
491
|
+
scroll
|
|
492
|
+
]);
|
|
493
|
+
return /* @__PURE__ */ jsx(AdaptCapabilitiesContext.Provider, {
|
|
494
|
+
value,
|
|
495
|
+
children
|
|
496
|
+
});
|
|
497
|
+
};
|
|
498
|
+
var useAdaptedCapabilities = function() {
|
|
499
|
+
return useContext(AdaptCapabilitiesContext);
|
|
500
|
+
};
|
|
501
|
+
function getAdaptRenderState(context) {
|
|
502
|
+
return {
|
|
503
|
+
active: context.active,
|
|
504
|
+
open: context.open,
|
|
505
|
+
onOpenChange: context.onOpenChange,
|
|
506
|
+
state: context.state,
|
|
507
|
+
handoff: context.handoff
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
export { Adapt, AdaptCapabilities, AdaptContents, AdaptContext, AdaptParent, AdaptPortalContents, ProvideAdaptContext, useAdaptContext, useAdaptIsActive, useAdaptTarget, useAdaptedCapabilities };
|
|
242
512
|
//# sourceMappingURL=Adapt.native.js.map
|