@tamagui/adapt 2.7.7 → 3.0.0-0.canary.1791056644527

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