@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.
@@ -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, 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
+ "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
- 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
- });
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 (scope) {
87
- var lastScope = useContext(LastAdaptContextScope);
88
- var adaptScope = scope !== null && scope !== void 0 ? scope : lastScope;
89
- return AdaptContext.useStyledContext(adaptScope);
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
- 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
- });
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 (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
- });
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
- 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
- });
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 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
- });
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 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;
420
+ var emptySubscribe = function() {
421
+ return function() {};
422
+ };
423
+ var emptySnapshot = function() {
424
+ return 0;
237
425
  };
238
- var useAdaptIsActive = function (scope) {
239
- return useAdaptIsActiveGiven(useAdaptContext(scope));
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
- export { Adapt, AdaptContents, AdaptContext, AdaptParent, AdaptPortalContents, ProvideAdaptContext, useAdaptContext, useAdaptIsActive };
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