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