@tamagui/adapt 2.7.6 → 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.
@@ -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, useMemo } from "react";
9
- function createAdaptChildrenStore() {
10
- var children = null;
11
- var listeners = /* @__PURE__ */new Set();
12
- return {
13
- set(c) {
14
- children = c;
15
- var _iteratorNormalCompletion = true,
16
- _didIteratorError = false,
17
- _iteratorError = void 0;
18
- try {
19
- for (var _iterator = listeners[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
20
- var l = _step.value;
21
- l();
22
- }
23
- } catch (err) {
24
- _didIteratorError = true;
25
- _iteratorError = err;
26
- } finally {
27
- try {
28
- if (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();
29
- } finally {
30
- if (_didIteratorError) throw _iteratorError;
31
- }
32
- }
33
- },
34
- get: function () {
35
- return children;
36
- },
37
- subscribe(callback) {
38
- listeners.add(callback);
39
- return function () {
40
- return listeners.delete(callback);
41
- };
42
- }
43
- };
44
- }
45
- var AdaptChildrenStoreContext = /* @__PURE__ */createContext(null);
46
- var emptySubscribe = function () {
47
- return function () {};
48
- };
49
- var emptyGet = function () {
50
- return null;
51
- };
52
- function TeleportAdaptContents() {
53
- var store = useContext(AdaptChildrenStoreContext);
54
- var _store_subscribe, _store_get, _store_get1;
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
- Contents: null,
61
- scopeName: "",
62
- portalName: "",
63
- platform: null,
64
- setPlatform: function (x) {},
65
- when: null,
66
- setWhen: function () {}
67
- });
68
- var LastAdaptContextScope = /* @__PURE__ */createContext("");
69
- var ProvideAdaptContext = function (param) {
70
- var {
71
- children,
72
- ...context
73
- } = param;
74
- var scope = context.scopeName || "";
75
- var lastScope = useContext(LastAdaptContextScope);
76
- return /* @__PURE__ */jsx(LastAdaptContextScope.Provider, {
77
- value: lastScope || context.lastScope || "",
78
- children: /* @__PURE__ */jsx(AdaptContext.Provider, {
79
- scope,
80
- lastScope: lastScope || context.lastScope,
81
- ...context,
82
- children
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 (scope) {
87
- var lastScope = useContext(LastAdaptContextScope);
88
- var adaptScope = scope !== null && scope !== void 0 ? scope : lastScope;
89
- return AdaptContext.useStyledContext(adaptScope);
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 AdaptPortals = /* @__PURE__ */new Map();
92
- var AdaptParent = function (param) {
93
- var {
94
- children,
95
- Contents,
96
- scope,
97
- portal
98
- } = param;
99
- var id = useId();
100
- var portalName = `AdaptPortal${scope}${id}`;
101
- var childrenStoreRef = React.useRef(null);
102
- if (!childrenStoreRef.current) childrenStoreRef.current = createAdaptChildrenStore();
103
- var isTeleport = getPortal().state.type === "teleport";
104
- var FinalContents = useMemo(function () {
105
- if (Contents) return Contents;
106
- if (isTeleport) return TeleportAdaptContents;
107
- if (AdaptPortals.has(portalName)) return AdaptPortals.get(portalName);
108
- var element = function () {
109
- return /* @__PURE__ */jsx(PortalHost, {
110
- name: portalName,
111
- forwardProps: typeof portal === "boolean" ? void 0 : portal === null || portal === void 0 ? void 0 : portal.forwardProps
112
- }, id);
113
- };
114
- AdaptPortals.set(portalName, element);
115
- return element;
116
- }, [portalName, Contents, isTeleport]);
117
- useIsomorphicLayoutEffect(function () {
118
- if (!isTeleport) {
119
- AdaptPortals.set(portalName, FinalContents);
120
- return function () {
121
- AdaptPortals.delete(portalName);
122
- };
123
- }
124
- }, [portalName, isTeleport]);
125
- var [when, setWhen] = React.useState(null);
126
- var [platform, setPlatform] = React.useState(null);
127
- return /* @__PURE__ */jsx(AdaptChildrenStoreContext.Provider, {
128
- value: childrenStoreRef.current,
129
- children: /* @__PURE__ */jsx(LastAdaptContextScope.Provider, {
130
- value: scope,
131
- children: /* @__PURE__ */jsx(ProvideAdaptContext, {
132
- Contents: FinalContents,
133
- when,
134
- platform,
135
- setPlatform,
136
- setWhen,
137
- portalName,
138
- scopeName: scope,
139
- children
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 (param) {
145
- var {
146
- scope,
147
- ...rest
148
- } = param;
149
- var context = useAdaptContext(scope);
150
- if (!(context === null || context === void 0 ? void 0 : 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.`);
151
- return /* @__PURE__ */React.createElement(context.Contents, {
152
- ...rest,
153
- key: `stable`
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
- var {
159
- platform,
160
- when,
161
- children,
162
- scope
163
- } = props;
164
- var context = useAdaptContext(scope);
165
- var enabled = useAdaptIsActiveGiven(props);
166
- useIsomorphicLayoutEffect(function () {
167
- var _context_setWhen, _context_setPlatform;
168
- context === null || context === void 0 || (_context_setWhen = context.setWhen) == null || _context_setWhen.call(context, when || enabled);
169
- context === null || context === void 0 || (_context_setPlatform = context.setPlatform) == null || _context_setPlatform.call(context, platform || null);
170
- }, [when, platform, enabled, context.setWhen, context.setPlatform]);
171
- useIsomorphicLayoutEffect(function () {
172
- return function () {
173
- var _context_setWhen, _context_setPlatform;
174
- context === null || context === void 0 || (_context_setWhen = context.setWhen) == null || _context_setWhen.call(context, null);
175
- context === null || context === void 0 || (_context_setPlatform = context.setPlatform) == null || _context_setPlatform.call(context, null);
176
- };
177
- }, []);
178
- var output;
179
- if (typeof children === "function") {
180
- var Component = context === null || context === void 0 ? void 0 : context.Contents;
181
- output = children(Component ? /* @__PURE__ */jsx(Component, {}) : null);
182
- } else output = children;
183
- return /* @__PURE__ */jsx(StackZIndexContext, {
184
- children: !enabled ? null : output
185
- });
186
- }, {
187
- Contents: AdaptContents
188
- });
189
- var AdaptPortalContents = function (props) {
190
- var isActive = useAdaptIsActive(props.scope);
191
- var {
192
- portalName
193
- } = useAdaptContext(props.scope);
194
- var childrenStore = useContext(AdaptChildrenStoreContext);
195
- if (!isWeb && getPortal().state.type === "teleport" && childrenStore) return /* @__PURE__ */jsx(AdaptPortalTeleport, {
196
- isActive,
197
- store: childrenStore,
198
- children: props.children
199
- });
200
- return /* @__PURE__ */jsx(PortalItem, {
201
- passThrough: !isActive,
202
- hostName: portalName,
203
- children: props.children
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 AdaptPortalTeleport(param) {
207
- var {
208
- isActive,
209
- store,
210
- children
211
- } = param;
212
- useIsomorphicLayoutEffect(function () {
213
- if (isActive) store.set(children);else store.set(null);
214
- });
215
- useIsomorphicLayoutEffect(function () {
216
- return function () {
217
- return store.set(null);
218
- };
219
- }, [store]);
220
- return isActive ? null : /* @__PURE__ */jsx(Fragment, {
221
- children
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 useAdaptIsActiveGiven = function (param) {
225
- var {
226
- when,
227
- platform
228
- } = param;
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;
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 useAdaptIsActive = function (scope) {
239
- return useAdaptIsActiveGiven(useAdaptContext(scope));
468
+ var useAdaptedCapabilities = function() {
469
+ return useContext(AdaptCapabilitiesContext);
240
470
  };
241
- export { Adapt, AdaptContents, AdaptContext, AdaptParent, AdaptPortalContents, ProvideAdaptContext, useAdaptContext, useAdaptIsActive };
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