@tamagui/adapt 2.7.7 → 3.0.0-beta.637.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 +449 -206
- package/dist/cjs/Adapt.native.cjs +522 -0
- package/dist/cjs/Adapt.native.js +488 -253
- package/dist/cjs/Adapt.native.js.map +1 -1
- package/dist/cjs/index.cjs +10 -11
- package/dist/cjs/index.native.cjs +21 -0
- package/dist/cjs/index.native.js +10 -10
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/Adapt.mjs +425 -177
- package/dist/esm/Adapt.mjs.map +1 -1
- package/dist/esm/Adapt.native.js +464 -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 +7 -7
- package/src/Adapt.tsx +463 -133
- package/types/Adapt.d.ts +73 -21
- 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,481 @@ 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
|
+
"platform",
|
|
59
|
+
"setPlatform",
|
|
60
|
+
"when",
|
|
61
|
+
"setWhen",
|
|
62
|
+
"active",
|
|
63
|
+
"rawActive",
|
|
64
|
+
"setRawActive",
|
|
65
|
+
"slot",
|
|
66
|
+
"handoff",
|
|
67
|
+
"targetFullyHidden",
|
|
68
|
+
"registerTarget",
|
|
69
|
+
"unregisterTarget",
|
|
70
|
+
"registerContents",
|
|
71
|
+
"unregisterContents",
|
|
72
|
+
"registerRenderCallback",
|
|
73
|
+
"unregisterRenderCallback"
|
|
74
|
+
];
|
|
59
75
|
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
|
-
|
|
76
|
+
Contents: null,
|
|
77
|
+
scopeName: "",
|
|
78
|
+
portalName: "",
|
|
79
|
+
platform: null,
|
|
80
|
+
setPlatform: function(x) {},
|
|
81
|
+
when: null,
|
|
82
|
+
setWhen: function() {},
|
|
83
|
+
active: false,
|
|
84
|
+
rawActive: false,
|
|
85
|
+
setRawActive: function() {},
|
|
86
|
+
slot: null,
|
|
87
|
+
handoff: {
|
|
88
|
+
hidden: true,
|
|
89
|
+
onTransition: function() {}
|
|
90
|
+
},
|
|
91
|
+
targetFullyHidden: true,
|
|
92
|
+
registerTarget: function() {},
|
|
93
|
+
unregisterTarget: function() {},
|
|
94
|
+
registerContents: function() {},
|
|
95
|
+
unregisterContents: function() {},
|
|
96
|
+
registerRenderCallback: function() {},
|
|
97
|
+
unregisterRenderCallback: function() {}
|
|
98
|
+
}, { keys: adaptContextKeys });
|
|
99
|
+
var AdaptCapabilitiesContext = /* @__PURE__ */ createContext({});
|
|
100
|
+
var LastAdaptContextScope = /* @__PURE__ */ createContext("");
|
|
101
|
+
var ProvideAdaptContext = function(param) {
|
|
102
|
+
var { children, ...context } = param;
|
|
103
|
+
var scope = context.scopeName || "";
|
|
104
|
+
var lastScope = useContext(LastAdaptContextScope);
|
|
105
|
+
return /* @__PURE__ */ jsx(LastAdaptContextScope.Provider, {
|
|
106
|
+
value: lastScope || context.lastScope || "",
|
|
107
|
+
children: /* @__PURE__ */ jsx(AdaptContext.Provider, {
|
|
108
|
+
scope,
|
|
109
|
+
lastScope: lastScope || context.lastScope,
|
|
110
|
+
...context,
|
|
111
|
+
children
|
|
112
|
+
})
|
|
113
|
+
});
|
|
85
114
|
};
|
|
86
|
-
var useAdaptContext = function
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
115
|
+
var useAdaptContext = function(scope) {
|
|
116
|
+
var lastScope = useContext(LastAdaptContextScope);
|
|
117
|
+
var adaptScope = scope !== null && scope !== void 0 ? scope : lastScope;
|
|
118
|
+
return AdaptContext.useStyledContext(adaptScope);
|
|
90
119
|
};
|
|
91
|
-
var
|
|
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
|
-
|
|
120
|
+
var AdaptParent = function(param) {
|
|
121
|
+
var { children, Contents, scope, open, onOpenChange, state } = param;
|
|
122
|
+
var id = useId();
|
|
123
|
+
var portalName = `AdaptPortal${scope}${id}`;
|
|
124
|
+
var slotRef = React.useRef(null);
|
|
125
|
+
if (!slotRef.current) {
|
|
126
|
+
slotRef.current = createAdaptSlotStore();
|
|
127
|
+
}
|
|
128
|
+
var [when, setWhen] = React.useState(null);
|
|
129
|
+
var [platform, setPlatform] = React.useState(null);
|
|
130
|
+
var [rawActive, setRawActive] = React.useState(false);
|
|
131
|
+
var [exiting, setExiting] = React.useState(false);
|
|
132
|
+
var [present, setPresent] = React.useState(false);
|
|
133
|
+
var [targetFullyHidden, setTargetFullyHidden] = React.useState(!open);
|
|
134
|
+
var targetCountRef = React.useRef(0);
|
|
135
|
+
var contentsCountRef = React.useRef(0);
|
|
136
|
+
var renderCallbackCountRef = React.useRef(0);
|
|
137
|
+
var rawActiveRef = React.useRef(false);
|
|
138
|
+
var openRef = React.useRef(open);
|
|
139
|
+
var wasTargetHiddenRef = React.useRef(!rawActive);
|
|
140
|
+
var hasHadActiveTargetRef = React.useRef(false);
|
|
141
|
+
var shouldStartExit = !rawActive && present && Boolean(open);
|
|
142
|
+
var active = rawActive || exiting || shouldStartExit;
|
|
143
|
+
var targetHidden = !rawActive;
|
|
144
|
+
var skipNextAnimation = Boolean(rawActive && wasTargetHiddenRef.current && hasHadActiveTargetRef.current && open);
|
|
145
|
+
rawActiveRef.current = rawActive;
|
|
146
|
+
openRef.current = open;
|
|
147
|
+
if (rawActive) {
|
|
148
|
+
hasHadActiveTargetRef.current = true;
|
|
149
|
+
}
|
|
150
|
+
wasTargetHiddenRef.current = targetHidden;
|
|
151
|
+
var releasePresenceLatch = React.useCallback(function() {
|
|
152
|
+
setExiting(false);
|
|
153
|
+
if (!rawActiveRef.current) {
|
|
154
|
+
setPresent(false);
|
|
155
|
+
}
|
|
156
|
+
}, []);
|
|
157
|
+
useIsomorphicLayoutEffect(function() {
|
|
158
|
+
if (shouldStartExit) {
|
|
159
|
+
setExiting(true);
|
|
160
|
+
}
|
|
161
|
+
}, [shouldStartExit]);
|
|
162
|
+
useIsomorphicLayoutEffect(function() {
|
|
163
|
+
if (open && rawActive) {
|
|
164
|
+
setTargetFullyHidden(false);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (!open && !active) {
|
|
168
|
+
setTargetFullyHidden(true);
|
|
169
|
+
}
|
|
170
|
+
}, [
|
|
171
|
+
active,
|
|
172
|
+
open,
|
|
173
|
+
rawActive
|
|
174
|
+
]);
|
|
175
|
+
useIsomorphicLayoutEffect(function() {
|
|
176
|
+
if (rawActive) {
|
|
177
|
+
setPresent(true);
|
|
178
|
+
} else if (!active) {
|
|
179
|
+
setPresent(false);
|
|
180
|
+
}
|
|
181
|
+
if (rawActive && exiting) {
|
|
182
|
+
setExiting(false);
|
|
183
|
+
}
|
|
184
|
+
}, [
|
|
185
|
+
active,
|
|
186
|
+
exiting,
|
|
187
|
+
rawActive
|
|
188
|
+
]);
|
|
189
|
+
var handoff = React.useMemo(function() {
|
|
190
|
+
return {
|
|
191
|
+
hidden: targetHidden,
|
|
192
|
+
skipNextAnimation,
|
|
193
|
+
onTransition(e) {
|
|
194
|
+
if (e.phase !== "end" || e.finished === false) return;
|
|
195
|
+
if (e.cause !== "close") {
|
|
196
|
+
setTargetFullyHidden(false);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (openRef.current && rawActiveRef.current) {
|
|
200
|
+
setTargetFullyHidden(false);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
setTargetFullyHidden(true);
|
|
204
|
+
releasePresenceLatch();
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
}, [
|
|
208
|
+
releasePresenceLatch,
|
|
209
|
+
skipNextAnimation,
|
|
210
|
+
targetHidden
|
|
211
|
+
]);
|
|
212
|
+
var registerTarget = React.useCallback(function() {
|
|
213
|
+
targetCountRef.current += 1;
|
|
214
|
+
if (process.env.NODE_ENV === "development" && targetCountRef.current > 1) {
|
|
215
|
+
console.error(`Adapt expected exactly one target in scope "${scope}", but ${targetCountRef.current} targets registered.`);
|
|
216
|
+
}
|
|
217
|
+
}, [scope]);
|
|
218
|
+
var unregisterTarget = React.useCallback(function() {
|
|
219
|
+
targetCountRef.current = Math.max(0, targetCountRef.current - 1);
|
|
220
|
+
}, []);
|
|
221
|
+
var registerContents = React.useCallback(function() {
|
|
222
|
+
contentsCountRef.current += 1;
|
|
223
|
+
}, []);
|
|
224
|
+
var unregisterContents = React.useCallback(function() {
|
|
225
|
+
contentsCountRef.current = Math.max(0, contentsCountRef.current - 1);
|
|
226
|
+
}, []);
|
|
227
|
+
var registerRenderCallback = React.useCallback(function() {
|
|
228
|
+
renderCallbackCountRef.current += 1;
|
|
229
|
+
}, []);
|
|
230
|
+
var unregisterRenderCallback = React.useCallback(function() {
|
|
231
|
+
renderCallbackCountRef.current = Math.max(0, renderCallbackCountRef.current - 1);
|
|
232
|
+
}, []);
|
|
233
|
+
React.useEffect(function() {
|
|
234
|
+
if (process.env.NODE_ENV !== "development") return;
|
|
235
|
+
if (!active) return;
|
|
236
|
+
var timer = setTimeout(function() {
|
|
237
|
+
if (rawActiveRef.current && targetCountRef.current === 0 && contentsCountRef.current === 0 && renderCallbackCountRef.current === 0) {
|
|
238
|
+
console.error(`Adapt is active in scope "${scope}" but no target registered with useAdaptTarget(), Adapt.Contents marker, or render callback consumed it.`);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
return function() {
|
|
242
|
+
return clearTimeout(timer);
|
|
243
|
+
};
|
|
244
|
+
}, [active, scope]);
|
|
245
|
+
var FinalContents = Contents || AdaptSlotContents;
|
|
246
|
+
return /* @__PURE__ */ jsx(LastAdaptContextScope.Provider, {
|
|
247
|
+
value: scope,
|
|
248
|
+
children: /* @__PURE__ */ jsx(ProvideAdaptContext, {
|
|
249
|
+
Contents: FinalContents,
|
|
250
|
+
when,
|
|
251
|
+
platform,
|
|
252
|
+
setPlatform,
|
|
253
|
+
setWhen,
|
|
254
|
+
active,
|
|
255
|
+
rawActive,
|
|
256
|
+
setRawActive,
|
|
257
|
+
portalName,
|
|
258
|
+
scopeName: scope,
|
|
259
|
+
slot: slotRef.current,
|
|
260
|
+
open,
|
|
261
|
+
onOpenChange,
|
|
262
|
+
state,
|
|
263
|
+
handoff,
|
|
264
|
+
targetFullyHidden,
|
|
265
|
+
registerTarget,
|
|
266
|
+
unregisterTarget,
|
|
267
|
+
registerContents,
|
|
268
|
+
unregisterContents,
|
|
269
|
+
registerRenderCallback,
|
|
270
|
+
unregisterRenderCallback,
|
|
271
|
+
children
|
|
272
|
+
})
|
|
273
|
+
});
|
|
143
274
|
};
|
|
144
|
-
var AdaptContents = function
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
275
|
+
var AdaptContents = function(param) {
|
|
276
|
+
var { scope, ...rest } = param;
|
|
277
|
+
var context = useAdaptContext(scope);
|
|
278
|
+
if (!(context === null || context === void 0 ? void 0 : context.Contents)) {
|
|
279
|
+
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.`);
|
|
280
|
+
}
|
|
281
|
+
useIsomorphicLayoutEffect(function() {
|
|
282
|
+
if (!context.active) return;
|
|
283
|
+
context.registerContents();
|
|
284
|
+
return function() {
|
|
285
|
+
context.unregisterContents();
|
|
286
|
+
};
|
|
287
|
+
}, [
|
|
288
|
+
context.active,
|
|
289
|
+
context.registerContents,
|
|
290
|
+
context.unregisterContents
|
|
291
|
+
]);
|
|
292
|
+
return /* @__PURE__ */ React.createElement(context.Contents, {
|
|
293
|
+
...rest,
|
|
294
|
+
scope,
|
|
295
|
+
key: `stable`
|
|
296
|
+
});
|
|
155
297
|
};
|
|
156
298
|
AdaptContents.shouldForwardSpace = true;
|
|
157
299
|
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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
300
|
+
var { platform, when, children, scope } = props;
|
|
301
|
+
var context = useAdaptContext(scope);
|
|
302
|
+
var rawEnabled = useAdaptIsActiveGiven(props);
|
|
303
|
+
var enabled = rawEnabled || context.active;
|
|
304
|
+
var isRenderCallback = typeof children === "function";
|
|
305
|
+
useIsomorphicLayoutEffect(function() {
|
|
306
|
+
var _context_setWhen, _context_setPlatform, _context_setRawActive;
|
|
307
|
+
context === null || context === void 0 ? void 0 : (_context_setWhen = context.setWhen) === null || _context_setWhen === void 0 ? void 0 : _context_setWhen.call(context, when || rawEnabled);
|
|
308
|
+
context === null || context === void 0 ? void 0 : (_context_setPlatform = context.setPlatform) === null || _context_setPlatform === void 0 ? void 0 : _context_setPlatform.call(context, platform || null);
|
|
309
|
+
context === null || context === void 0 ? void 0 : (_context_setRawActive = context.setRawActive) === null || _context_setRawActive === void 0 ? void 0 : _context_setRawActive.call(context, rawEnabled);
|
|
310
|
+
}, [
|
|
311
|
+
when,
|
|
312
|
+
platform,
|
|
313
|
+
rawEnabled,
|
|
314
|
+
context.setWhen,
|
|
315
|
+
context.setPlatform,
|
|
316
|
+
context.setRawActive
|
|
317
|
+
]);
|
|
318
|
+
useIsomorphicLayoutEffect(function() {
|
|
319
|
+
if (!enabled || !isRenderCallback) return;
|
|
320
|
+
context.registerRenderCallback();
|
|
321
|
+
return function() {
|
|
322
|
+
context.unregisterRenderCallback();
|
|
323
|
+
};
|
|
324
|
+
}, [
|
|
325
|
+
enabled,
|
|
326
|
+
isRenderCallback,
|
|
327
|
+
context.registerRenderCallback,
|
|
328
|
+
context.unregisterRenderCallback
|
|
329
|
+
]);
|
|
330
|
+
useIsomorphicLayoutEffect(function() {
|
|
331
|
+
return function() {
|
|
332
|
+
var _context_setWhen, _context_setPlatform, _context_setRawActive;
|
|
333
|
+
context === null || context === void 0 ? void 0 : (_context_setWhen = context.setWhen) === null || _context_setWhen === void 0 ? void 0 : _context_setWhen.call(context, null);
|
|
334
|
+
context === null || context === void 0 ? void 0 : (_context_setPlatform = context.setPlatform) === null || _context_setPlatform === void 0 ? void 0 : _context_setPlatform.call(context, null);
|
|
335
|
+
context === null || context === void 0 ? void 0 : (_context_setRawActive = context.setRawActive) === null || _context_setRawActive === void 0 ? void 0 : _context_setRawActive.call(context, false);
|
|
336
|
+
};
|
|
337
|
+
}, []);
|
|
338
|
+
var output;
|
|
339
|
+
if (isRenderCallback) {
|
|
340
|
+
var Component = context === null || context === void 0 ? void 0 : context.Contents;
|
|
341
|
+
output = children(Component ? /* @__PURE__ */ jsx(Component, {}) : null, getAdaptRenderState(context));
|
|
342
|
+
} else {
|
|
343
|
+
output = children;
|
|
344
|
+
}
|
|
345
|
+
return /* @__PURE__ */ jsx(StackZIndexContext, { children: !enabled ? null : output });
|
|
346
|
+
}, { Contents: AdaptContents });
|
|
347
|
+
var AdaptPortalContents = function(props) {
|
|
348
|
+
var isActive = useAdaptIsActive(props.scope);
|
|
349
|
+
var { slot } = useAdaptContext(props.scope);
|
|
350
|
+
return /* @__PURE__ */ jsx(AdaptSlotPublisher, {
|
|
351
|
+
isActive,
|
|
352
|
+
slot,
|
|
353
|
+
children: props.children
|
|
354
|
+
});
|
|
355
|
+
};
|
|
356
|
+
function AdaptSlotContents(param) {
|
|
357
|
+
var { scope } = param;
|
|
358
|
+
var { slot } = useAdaptContext(scope);
|
|
359
|
+
var _slot_subscribe, _slot_getSnapshot, _slot_getSnapshot1;
|
|
360
|
+
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);
|
|
361
|
+
var _slot_element;
|
|
362
|
+
return /* @__PURE__ */ jsx(Fragment, { children: (_slot_element = slot === null || slot === void 0 ? void 0 : slot.element) !== null && _slot_element !== void 0 ? _slot_element : null });
|
|
363
|
+
}
|
|
364
|
+
function AdaptSlotPublisher(param) {
|
|
365
|
+
var { isActive, slot, children } = param;
|
|
366
|
+
var publishedRef = React.useRef(false);
|
|
367
|
+
useIsomorphicLayoutEffect(function() {
|
|
368
|
+
if (!slot) return;
|
|
369
|
+
if (isActive) {
|
|
370
|
+
slot.publish(children);
|
|
371
|
+
publishedRef.current = true;
|
|
372
|
+
} else {
|
|
373
|
+
slot.clear();
|
|
374
|
+
publishedRef.current = false;
|
|
375
|
+
}
|
|
376
|
+
slot.notify();
|
|
377
|
+
});
|
|
378
|
+
useIsomorphicLayoutEffect(function() {
|
|
379
|
+
return function() {
|
|
380
|
+
if (publishedRef.current) {
|
|
381
|
+
slot === null || slot === void 0 ? void 0 : slot.clear();
|
|
382
|
+
slot === null || slot === void 0 ? void 0 : slot.notify();
|
|
383
|
+
publishedRef.current = false;
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
}, [slot]);
|
|
387
|
+
return isActive ? null : /* @__PURE__ */ jsx(Fragment, { children });
|
|
388
|
+
}
|
|
389
|
+
var emptySubscribe = function() {
|
|
390
|
+
return function() {};
|
|
391
|
+
};
|
|
392
|
+
var emptySnapshot = function() {
|
|
393
|
+
return 0;
|
|
394
|
+
};
|
|
395
|
+
var useAdaptIsActiveGiven = function(param) {
|
|
396
|
+
var { when, platform } = param;
|
|
397
|
+
var media = useMedia();
|
|
398
|
+
if (when == null && platform == null) {
|
|
399
|
+
return false;
|
|
400
|
+
}
|
|
401
|
+
if (when === true) {
|
|
402
|
+
return true;
|
|
403
|
+
}
|
|
404
|
+
var enabled = false;
|
|
405
|
+
if (platform === "touch") enabled = isTouchable;
|
|
406
|
+
else if (platform === "native") enabled = !isWeb;
|
|
407
|
+
else if (platform === "web") enabled = isWeb;
|
|
408
|
+
else if (platform === "ios") enabled = isIos;
|
|
409
|
+
else if (platform === "android") enabled = isAndroid;
|
|
410
|
+
if (platform && enabled == false) {
|
|
411
|
+
return false;
|
|
412
|
+
}
|
|
413
|
+
if (when && typeof when === "string") {
|
|
414
|
+
enabled = media[when];
|
|
415
|
+
}
|
|
416
|
+
return enabled;
|
|
205
417
|
};
|
|
206
|
-
function
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
418
|
+
var useAdaptIsActive = function(scope) {
|
|
419
|
+
var props = useAdaptContext(scope);
|
|
420
|
+
var isActiveGiven = useAdaptIsActiveGiven(props);
|
|
421
|
+
return props.active || isActiveGiven;
|
|
422
|
+
};
|
|
423
|
+
function useAdaptTarget(scope) {
|
|
424
|
+
var context = useAdaptContext(scope);
|
|
425
|
+
useIsomorphicLayoutEffect(function() {
|
|
426
|
+
if (!context.active) return;
|
|
427
|
+
context.registerTarget();
|
|
428
|
+
return function() {
|
|
429
|
+
context.unregisterTarget();
|
|
430
|
+
};
|
|
431
|
+
}, [
|
|
432
|
+
context.active,
|
|
433
|
+
context.registerTarget,
|
|
434
|
+
context.unregisterTarget
|
|
435
|
+
]);
|
|
436
|
+
if (!context.active) {
|
|
437
|
+
return null;
|
|
438
|
+
}
|
|
439
|
+
return {
|
|
440
|
+
open: context.open,
|
|
441
|
+
onOpenChange: context.onOpenChange,
|
|
442
|
+
handoff: context.handoff,
|
|
443
|
+
state: context.state
|
|
444
|
+
};
|
|
223
445
|
}
|
|
224
|
-
var
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
446
|
+
var AdaptCapabilities = function(param) {
|
|
447
|
+
var { children, scroll, overlay, dismiss } = param;
|
|
448
|
+
var parent = useContext(AdaptCapabilitiesContext);
|
|
449
|
+
var value = React.useMemo(function() {
|
|
450
|
+
return {
|
|
451
|
+
scroll: scroll !== null && scroll !== void 0 ? scroll : parent.scroll,
|
|
452
|
+
overlay: overlay !== null && overlay !== void 0 ? overlay : parent.overlay,
|
|
453
|
+
dismiss: dismiss !== null && dismiss !== void 0 ? dismiss : parent.dismiss
|
|
454
|
+
};
|
|
455
|
+
}, [
|
|
456
|
+
dismiss,
|
|
457
|
+
overlay,
|
|
458
|
+
parent.dismiss,
|
|
459
|
+
parent.overlay,
|
|
460
|
+
parent.scroll,
|
|
461
|
+
scroll
|
|
462
|
+
]);
|
|
463
|
+
return /* @__PURE__ */ jsx(AdaptCapabilitiesContext.Provider, {
|
|
464
|
+
value,
|
|
465
|
+
children
|
|
466
|
+
});
|
|
237
467
|
};
|
|
238
|
-
var
|
|
239
|
-
|
|
468
|
+
var useAdaptedCapabilities = function() {
|
|
469
|
+
return useContext(AdaptCapabilitiesContext);
|
|
240
470
|
};
|
|
241
|
-
|
|
471
|
+
function getAdaptRenderState(context) {
|
|
472
|
+
return {
|
|
473
|
+
active: context.active,
|
|
474
|
+
open: context.open,
|
|
475
|
+
onOpenChange: context.onOpenChange,
|
|
476
|
+
state: context.state,
|
|
477
|
+
handoff: context.handoff
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
export { Adapt, AdaptCapabilities, AdaptContents, AdaptContext, AdaptParent, AdaptPortalContents, ProvideAdaptContext, useAdaptContext, useAdaptIsActive, useAdaptTarget, useAdaptedCapabilities };
|
|
242
482
|
//# sourceMappingURL=Adapt.native.js.map
|