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