@tamagui/adapt 3.0.0-beta.924.1 → 3.0.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.
@@ -36,6 +36,7 @@ __export(Adapt_exports, {
36
36
  useAdaptContext: () => useAdaptContext,
37
37
  useAdaptIsActive: () => useAdaptIsActive,
38
38
  useAdaptTarget: () => useAdaptTarget,
39
+ useAdaptTargetScope: () => useAdaptTargetScope,
39
40
  useAdaptedCapabilities: () => useAdaptedCapabilities
40
41
  });
41
42
  module.exports = __toCommonJS(Adapt_exports);
@@ -78,13 +79,8 @@ const adaptContextKeys = [
78
79
  "Contents",
79
80
  "scopeName",
80
81
  "portalName",
81
- "platform",
82
- "setPlatform",
83
- "when",
84
- "setWhen",
85
82
  "active",
86
- "rawActive",
87
- "setRawActive",
83
+ "setAdaptConfig",
88
84
  "slot",
89
85
  "handoff",
90
86
  "targetFullyHidden",
@@ -99,13 +95,8 @@ const AdaptContext = (0, import_core.createStyledContext)({
99
95
  Contents: null,
100
96
  scopeName: "",
101
97
  portalName: "",
102
- platform: null,
103
- setPlatform: (x) => {},
104
- when: null,
105
- setWhen: () => {},
106
98
  active: false,
107
- rawActive: false,
108
- setRawActive: () => {},
99
+ setAdaptConfig: () => {},
109
100
  slot: null,
110
101
  handoff: {
111
102
  hidden: true,
@@ -121,6 +112,8 @@ const AdaptContext = (0, import_core.createStyledContext)({
121
112
  }, { keys: adaptContextKeys });
122
113
  const AdaptCapabilitiesContext = (0, import_react.createContext)({});
123
114
  const LastAdaptContextScope = (0, import_react.createContext)("");
115
+ const AdaptTargetScope = (0, import_react.createContext)(null);
116
+ const useAdaptTargetScope = () => (0, import_react.useContext)(AdaptTargetScope);
124
117
  const ProvideAdaptContext = ({ children, ...context }) => {
125
118
  const scope = context.scopeName || "";
126
119
  const lastScope = (0, import_react.useContext)(LastAdaptContextScope);
@@ -139,16 +132,43 @@ const useAdaptContext = (scope) => {
139
132
  const adaptScope = scope ?? lastScope;
140
133
  return AdaptContext.useStyledContext(adaptScope);
141
134
  };
142
- const AdaptParent = ({ children, Contents, scope, open, onOpenChange, state }) => {
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 }) => {
143
153
  const id = (0, import_react.useId)();
144
154
  const portalName = `AdaptPortal${scope}${id}`;
145
155
  const slotRef = import_react.default.useRef(null);
146
156
  if (!slotRef.current) {
147
157
  slotRef.current = createAdaptSlotStore();
148
158
  }
149
- const [when, setWhen] = import_react.default.useState(null);
150
- const [platform, setPlatform] = import_react.default.useState(null);
151
- const [rawActive, setRawActive] = import_react.default.useState(false);
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
+ }, []);
152
172
  const [exiting, setExiting] = import_react.default.useState(false);
153
173
  const [present, setPresent] = import_react.default.useState(false);
154
174
  const [targetFullyHidden, setTargetFullyHidden] = import_react.default.useState(!open);
@@ -163,12 +183,6 @@ const AdaptParent = ({ children, Contents, scope, open, onOpenChange, state }) =
163
183
  const active = rawActive || exiting || shouldStartExit;
164
184
  const targetHidden = !rawActive;
165
185
  const skipNextAnimation = Boolean(rawActive && wasTargetHiddenRef.current && hasHadActiveTargetRef.current && open);
166
- rawActiveRef.current = rawActive;
167
- openRef.current = open;
168
- if (rawActive) {
169
- hasHadActiveTargetRef.current = true;
170
- }
171
- wasTargetHiddenRef.current = targetHidden;
172
186
  const releasePresenceLatch = import_react.default.useCallback(() => {
173
187
  setExiting(false);
174
188
  if (!rawActiveRef.current) {
@@ -181,6 +195,12 @@ const AdaptParent = ({ children, Contents, scope, open, onOpenChange, state }) =
181
195
  }
182
196
  }, [shouldStartExit]);
183
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;
184
204
  if (open && rawActive) {
185
205
  setTargetFullyHidden(false);
186
206
  return;
@@ -191,7 +211,8 @@ const AdaptParent = ({ children, Contents, scope, open, onOpenChange, state }) =
191
211
  }, [
192
212
  active,
193
213
  open,
194
- rawActive
214
+ rawActive,
215
+ targetHidden
195
216
  ]);
196
217
  (0, import_constants.useIsomorphicLayoutEffect)(() => {
197
218
  if (rawActive) {
@@ -264,13 +285,8 @@ const AdaptParent = ({ children, Contents, scope, open, onOpenChange, state }) =
264
285
  value: scope,
265
286
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ProvideAdaptContext, {
266
287
  Contents: FinalContents,
267
- when,
268
- platform,
269
- setPlatform,
270
- setWhen,
271
288
  active,
272
- rawActive,
273
- setRawActive,
289
+ setAdaptConfig,
274
290
  portalName,
275
291
  scopeName: scope,
276
292
  slot: slotRef.current,
@@ -305,30 +321,32 @@ const AdaptContents = ({ scope, ...rest }) => {
305
321
  context.registerContents,
306
322
  context.unregisterContents
307
323
  ]);
308
- return import_react.default.createElement(context.Contents, {
309
- ...rest,
310
- scope,
311
- key: `stable`
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
+ })
312
331
  });
313
332
  };
314
- AdaptContents.shouldForwardSpace = true;
315
333
  const Adapt = (0, import_helpers.withStaticProperties)(function Adapt2(props) {
316
- const { platform, when, children, scope } = props;
334
+ const { children, platform, scope, when } = props;
317
335
  const context = useAdaptContext(scope);
318
- const rawEnabled = useAdaptIsActiveGiven(props);
319
- const enabled = rawEnabled || context.active;
336
+ const enabled = context.active;
320
337
  const isRenderCallback = typeof children === "function";
321
338
  (0, import_constants.useIsomorphicLayoutEffect)(() => {
322
- context?.setWhen?.(when || rawEnabled);
323
- context?.setPlatform?.(platform || null);
324
- context?.setRawActive?.(rawEnabled);
339
+ context.setAdaptConfig({
340
+ when,
341
+ platform
342
+ });
343
+ return () => {
344
+ context.setAdaptConfig(null);
345
+ };
325
346
  }, [
326
347
  when,
327
348
  platform,
328
- rawEnabled,
329
- context.setWhen,
330
- context.setPlatform,
331
- context.setRawActive
349
+ context.setAdaptConfig
332
350
  ]);
333
351
  (0, import_constants.useIsomorphicLayoutEffect)(() => {
334
352
  if (!enabled || !isRenderCallback) return;
@@ -342,13 +360,6 @@ const Adapt = (0, import_helpers.withStaticProperties)(function Adapt2(props) {
342
360
  context.registerRenderCallback,
343
361
  context.unregisterRenderCallback
344
362
  ]);
345
- (0, import_constants.useIsomorphicLayoutEffect)(() => {
346
- return () => {
347
- context?.setWhen?.(null);
348
- context?.setPlatform?.(null);
349
- context?.setRawActive?.(false);
350
- };
351
- }, []);
352
363
  let output;
353
364
  if (isRenderCallback) {
354
365
  const Component = context?.Contents;
@@ -356,7 +367,10 @@ const Adapt = (0, import_helpers.withStaticProperties)(function Adapt2(props) {
356
367
  } else {
357
368
  output = children;
358
369
  }
359
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_z_index_stack.StackZIndexContext, { children: !enabled ? null : output });
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
+ });
360
374
  }, { Contents: AdaptContents });
361
375
  const AdaptPortalContents = (props) => {
362
376
  const isActive = useAdaptIsActive(props.scope);
@@ -373,39 +387,44 @@ function AdaptSlotContents({ scope }) {
373
387
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: slot?.element ?? null });
374
388
  }
375
389
  function AdaptSlotPublisher({ isActive, slot, children }) {
376
- const publishedRef = import_react.default.useRef(false);
390
+ const publishedRef = import_react.default.useRef(null);
377
391
  (0, import_constants.useIsomorphicLayoutEffect)(() => {
378
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
+ };
379
401
  if (isActive) {
380
402
  slot.publish(children);
381
- publishedRef.current = true;
382
403
  } else {
383
404
  slot.clear();
384
- publishedRef.current = false;
385
405
  }
386
406
  slot.notify();
387
407
  });
388
408
  (0, import_constants.useIsomorphicLayoutEffect)(() => {
389
409
  return () => {
390
- if (publishedRef.current) {
410
+ if (publishedRef.current?.isActive) {
391
411
  slot?.clear();
392
412
  slot?.notify();
393
- publishedRef.current = false;
394
413
  }
414
+ publishedRef.current = null;
395
415
  };
396
416
  }, [slot]);
397
417
  return isActive ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
398
418
  }
399
419
  const emptySubscribe = () => () => {};
400
420
  const emptySnapshot = () => 0;
401
- const useAdaptIsActiveGiven = ({ when, platform }) => {
421
+ const useAdaptIsActiveGiven = (config) => {
402
422
  const media = (0, import_core.useMedia)();
423
+ const when = config?.when;
424
+ const platform = config?.platform;
403
425
  if (when == null && platform == null) {
404
426
  return false;
405
427
  }
406
- if (when === true) {
407
- return true;
408
- }
409
428
  let enabled = false;
410
429
  if (platform === "touch") enabled = import_constants.isTouchable;
411
430
  else if (platform === "native") enabled = !import_constants.isWeb;
@@ -415,20 +434,23 @@ const useAdaptIsActiveGiven = ({ when, platform }) => {
415
434
  if (platform && enabled == false) {
416
435
  return false;
417
436
  }
437
+ if (when === true) {
438
+ return true;
439
+ }
418
440
  if (when && typeof when === "string") {
419
441
  enabled = media[when];
420
442
  }
421
443
  return enabled;
422
444
  };
423
445
  const useAdaptIsActive = (scope) => {
424
- const props = useAdaptContext(scope);
425
- const isActiveGiven = useAdaptIsActiveGiven(props);
426
- return props.active || isActiveGiven;
446
+ return useAdaptContext(scope).active;
427
447
  };
428
448
  function useAdaptTarget(scope) {
429
449
  const context = useAdaptContext(scope);
450
+ const targetScope = useAdaptTargetScope();
451
+ const isTarget = scope !== void 0 || targetScope === context.scopeName;
430
452
  (0, import_constants.useIsomorphicLayoutEffect)(() => {
431
- if (!context.active) return;
453
+ if (!context.active || !isTarget) return;
432
454
  context.registerTarget();
433
455
  return () => {
434
456
  context.unregisterTarget();
@@ -436,9 +458,10 @@ function useAdaptTarget(scope) {
436
458
  }, [
437
459
  context.active,
438
460
  context.registerTarget,
439
- context.unregisterTarget
461
+ context.unregisterTarget,
462
+ isTarget
440
463
  ]);
441
- if (!context.active) {
464
+ if (!context.active || !isTarget) {
442
465
  return null;
443
466
  }
444
467
  return {
@@ -38,6 +38,7 @@ __export(Adapt_exports, {
38
38
  useAdaptContext: () => useAdaptContext,
39
39
  useAdaptIsActive: () => useAdaptIsActive,
40
40
  useAdaptTarget: () => useAdaptTarget,
41
+ useAdaptTargetScope: () => useAdaptTargetScope,
41
42
  useAdaptedCapabilities: () => useAdaptedCapabilities
42
43
  });
43
44
  module.exports = __toCommonJS(Adapt_exports);
@@ -97,13 +98,8 @@ var adaptContextKeys = [
97
98
  "Contents",
98
99
  "scopeName",
99
100
  "portalName",
100
- "platform",
101
- "setPlatform",
102
- "when",
103
- "setWhen",
104
101
  "active",
105
- "rawActive",
106
- "setRawActive",
102
+ "setAdaptConfig",
107
103
  "slot",
108
104
  "handoff",
109
105
  "targetFullyHidden",
@@ -118,13 +114,8 @@ var AdaptContext = (0, import_core.createStyledContext)({
118
114
  Contents: null,
119
115
  scopeName: "",
120
116
  portalName: "",
121
- platform: null,
122
- setPlatform: function(x) {},
123
- when: null,
124
- setWhen: function() {},
125
117
  active: false,
126
- rawActive: false,
127
- setRawActive: function() {},
118
+ setAdaptConfig: function() {},
128
119
  slot: null,
129
120
  handoff: {
130
121
  hidden: true,
@@ -140,6 +131,10 @@ var AdaptContext = (0, import_core.createStyledContext)({
140
131
  }, { keys: adaptContextKeys });
141
132
  var AdaptCapabilitiesContext = /* @__PURE__ */ (0, import_react.createContext)({});
142
133
  var LastAdaptContextScope = /* @__PURE__ */ (0, import_react.createContext)("");
134
+ var AdaptTargetScope = /* @__PURE__ */ (0, import_react.createContext)(null);
135
+ var useAdaptTargetScope = function() {
136
+ return (0, import_react.useContext)(AdaptTargetScope);
137
+ };
143
138
  var ProvideAdaptContext = function(param) {
144
139
  var { children, ...context } = param;
145
140
  var scope = context.scopeName || "";
@@ -159,17 +154,64 @@ var useAdaptContext = function(scope) {
159
154
  var adaptScope = scope !== null && scope !== void 0 ? scope : lastScope;
160
155
  return AdaptContext.useStyledContext(adaptScope);
161
156
  };
157
+ function findAdaptConfig(children, scope) {
158
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
159
+ try {
160
+ for (var _iterator = import_react.default.Children.toArray(children)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
161
+ var child = _step.value;
162
+ if (!/* @__PURE__ */ import_react.default.isValidElement(child)) continue;
163
+ if (child.type === import_react.default.Fragment) {
164
+ var found = findAdaptConfig(child.props.children, scope);
165
+ if (found) return found;
166
+ continue;
167
+ }
168
+ if (child.type === Adapt) {
169
+ var childProps = child.props;
170
+ if (childProps.scope == null || childProps.scope === scope) {
171
+ return childProps;
172
+ }
173
+ }
174
+ }
175
+ } catch (err) {
176
+ _didIteratorError = true;
177
+ _iteratorError = err;
178
+ } finally {
179
+ try {
180
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
181
+ _iterator.return();
182
+ }
183
+ } finally {
184
+ if (_didIteratorError) {
185
+ throw _iteratorError;
186
+ }
187
+ }
188
+ }
189
+ return null;
190
+ }
162
191
  var AdaptParent = function(param) {
163
- var { children, Contents, scope, open, onOpenChange, state } = param;
192
+ var { children, adaptChildren, Contents, scope, open, onOpenChange, state } = param;
164
193
  var id = (0, import_react.useId)();
165
194
  var portalName = `AdaptPortal${scope}${id}`;
166
195
  var slotRef = import_react.default.useRef(null);
167
196
  if (!slotRef.current) {
168
197
  slotRef.current = createAdaptSlotStore();
169
198
  }
170
- var [when, setWhen] = import_react.default.useState(null);
171
- var [platform, setPlatform] = import_react.default.useState(null);
172
- var [rawActive, setRawActive] = import_react.default.useState(false);
199
+ var staticConfig = import_react.default.useMemo(function() {
200
+ var _findAdaptConfig;
201
+ return (_findAdaptConfig = findAdaptConfig(adaptChildren, scope)) !== null && _findAdaptConfig !== void 0 ? _findAdaptConfig : findAdaptConfig(children, scope);
202
+ }, [
203
+ adaptChildren,
204
+ children,
205
+ scope
206
+ ]);
207
+ var [publishedConfig, setPublishedConfig] = import_react.default.useState(null);
208
+ var rawActive = useAdaptIsActiveGiven(staticConfig !== null && staticConfig !== void 0 ? staticConfig : publishedConfig);
209
+ var staticConfigRef = import_react.default.useRef(staticConfig);
210
+ staticConfigRef.current = staticConfig;
211
+ var setAdaptConfig = import_react.default.useCallback(function(config) {
212
+ if (staticConfigRef.current) return;
213
+ setPublishedConfig(config);
214
+ }, []);
173
215
  var [exiting, setExiting] = import_react.default.useState(false);
174
216
  var [present, setPresent] = import_react.default.useState(false);
175
217
  var [targetFullyHidden, setTargetFullyHidden] = import_react.default.useState(!open);
@@ -184,12 +226,6 @@ var AdaptParent = function(param) {
184
226
  var active = rawActive || exiting || shouldStartExit;
185
227
  var targetHidden = !rawActive;
186
228
  var skipNextAnimation = Boolean(rawActive && wasTargetHiddenRef.current && hasHadActiveTargetRef.current && open);
187
- rawActiveRef.current = rawActive;
188
- openRef.current = open;
189
- if (rawActive) {
190
- hasHadActiveTargetRef.current = true;
191
- }
192
- wasTargetHiddenRef.current = targetHidden;
193
229
  var releasePresenceLatch = import_react.default.useCallback(function() {
194
230
  setExiting(false);
195
231
  if (!rawActiveRef.current) {
@@ -202,6 +238,12 @@ var AdaptParent = function(param) {
202
238
  }
203
239
  }, [shouldStartExit]);
204
240
  (0, import_constants.useIsomorphicLayoutEffect)(function() {
241
+ rawActiveRef.current = rawActive;
242
+ openRef.current = open;
243
+ if (rawActive) {
244
+ hasHadActiveTargetRef.current = true;
245
+ }
246
+ wasTargetHiddenRef.current = targetHidden;
205
247
  if (open && rawActive) {
206
248
  setTargetFullyHidden(false);
207
249
  return;
@@ -212,7 +254,8 @@ var AdaptParent = function(param) {
212
254
  }, [
213
255
  active,
214
256
  open,
215
- rawActive
257
+ rawActive,
258
+ targetHidden
216
259
  ]);
217
260
  (0, import_constants.useIsomorphicLayoutEffect)(function() {
218
261
  if (rawActive) {
@@ -289,13 +332,8 @@ var AdaptParent = function(param) {
289
332
  value: scope,
290
333
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ProvideAdaptContext, {
291
334
  Contents: FinalContents,
292
- when,
293
- platform,
294
- setPlatform,
295
- setWhen,
296
335
  active,
297
- rawActive,
298
- setRawActive,
336
+ setAdaptConfig,
299
337
  portalName,
300
338
  scopeName: scope,
301
339
  slot: slotRef.current,
@@ -331,31 +369,32 @@ var AdaptContents = function(param) {
331
369
  context.registerContents,
332
370
  context.unregisterContents
333
371
  ]);
334
- return /* @__PURE__ */ import_react.default.createElement(context.Contents, {
335
- ...rest,
336
- scope,
337
- key: `stable`
372
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AdaptTargetScope.Provider, {
373
+ value: null,
374
+ children: /* @__PURE__ */ import_react.default.createElement(context.Contents, {
375
+ ...rest,
376
+ scope,
377
+ key: `stable`
378
+ })
338
379
  });
339
380
  };
340
- AdaptContents.shouldForwardSpace = true;
341
381
  var Adapt = (0, import_helpers.withStaticProperties)(function Adapt2(props) {
342
- var { platform, when, children, scope } = props;
382
+ var { children, platform, scope, when } = props;
343
383
  var context = useAdaptContext(scope);
344
- var rawEnabled = useAdaptIsActiveGiven(props);
345
- var enabled = rawEnabled || context.active;
384
+ var enabled = context.active;
346
385
  var isRenderCallback = typeof children === "function";
347
386
  (0, import_constants.useIsomorphicLayoutEffect)(function() {
348
- var _context_setWhen, _context_setPlatform, _context_setRawActive;
349
- context === null || context === void 0 ? void 0 : (_context_setWhen = context.setWhen) === null || _context_setWhen === void 0 ? void 0 : _context_setWhen.call(context, when || rawEnabled);
350
- context === null || context === void 0 ? void 0 : (_context_setPlatform = context.setPlatform) === null || _context_setPlatform === void 0 ? void 0 : _context_setPlatform.call(context, platform || null);
351
- context === null || context === void 0 ? void 0 : (_context_setRawActive = context.setRawActive) === null || _context_setRawActive === void 0 ? void 0 : _context_setRawActive.call(context, rawEnabled);
387
+ context.setAdaptConfig({
388
+ when,
389
+ platform
390
+ });
391
+ return function() {
392
+ context.setAdaptConfig(null);
393
+ };
352
394
  }, [
353
395
  when,
354
396
  platform,
355
- rawEnabled,
356
- context.setWhen,
357
- context.setPlatform,
358
- context.setRawActive
397
+ context.setAdaptConfig
359
398
  ]);
360
399
  (0, import_constants.useIsomorphicLayoutEffect)(function() {
361
400
  if (!enabled || !isRenderCallback) return;
@@ -369,14 +408,6 @@ var Adapt = (0, import_helpers.withStaticProperties)(function Adapt2(props) {
369
408
  context.registerRenderCallback,
370
409
  context.unregisterRenderCallback
371
410
  ]);
372
- (0, import_constants.useIsomorphicLayoutEffect)(function() {
373
- return function() {
374
- var _context_setWhen, _context_setPlatform, _context_setRawActive;
375
- context === null || context === void 0 ? void 0 : (_context_setWhen = context.setWhen) === null || _context_setWhen === void 0 ? void 0 : _context_setWhen.call(context, null);
376
- context === null || context === void 0 ? void 0 : (_context_setPlatform = context.setPlatform) === null || _context_setPlatform === void 0 ? void 0 : _context_setPlatform.call(context, null);
377
- context === null || context === void 0 ? void 0 : (_context_setRawActive = context.setRawActive) === null || _context_setRawActive === void 0 ? void 0 : _context_setRawActive.call(context, false);
378
- };
379
- }, []);
380
411
  var output;
381
412
  if (isRenderCallback) {
382
413
  var Component = context === null || context === void 0 ? void 0 : context.Contents;
@@ -384,7 +415,10 @@ var Adapt = (0, import_helpers.withStaticProperties)(function Adapt2(props) {
384
415
  } else {
385
416
  output = children;
386
417
  }
387
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_z_index_stack.StackZIndexContext, { children: !enabled ? null : output });
418
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AdaptTargetScope.Provider, {
419
+ value: context.scopeName,
420
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_z_index_stack.StackZIndexContext, { children: !enabled ? null : output })
421
+ });
388
422
  }, { Contents: AdaptContents });
389
423
  var AdaptPortalContents = function(props) {
390
424
  var isActive = useAdaptIsActive(props.scope);
@@ -405,25 +439,32 @@ function AdaptSlotContents(param) {
405
439
  }
406
440
  function AdaptSlotPublisher(param) {
407
441
  var { isActive, slot, children } = param;
408
- var publishedRef = import_react.default.useRef(false);
442
+ var publishedRef = import_react.default.useRef(null);
409
443
  (0, import_constants.useIsomorphicLayoutEffect)(function() {
410
444
  if (!slot) return;
445
+ var published = publishedRef.current;
446
+ if (published && published.isActive === isActive && published.element === children) {
447
+ return;
448
+ }
449
+ publishedRef.current = {
450
+ isActive,
451
+ element: children
452
+ };
411
453
  if (isActive) {
412
454
  slot.publish(children);
413
- publishedRef.current = true;
414
455
  } else {
415
456
  slot.clear();
416
- publishedRef.current = false;
417
457
  }
418
458
  slot.notify();
419
459
  });
420
460
  (0, import_constants.useIsomorphicLayoutEffect)(function() {
421
461
  return function() {
422
- if (publishedRef.current) {
462
+ var _publishedRef_current;
463
+ if ((_publishedRef_current = publishedRef.current) === null || _publishedRef_current === void 0 ? void 0 : _publishedRef_current.isActive) {
423
464
  slot === null || slot === void 0 ? void 0 : slot.clear();
424
465
  slot === null || slot === void 0 ? void 0 : slot.notify();
425
- publishedRef.current = false;
426
466
  }
467
+ publishedRef.current = null;
427
468
  };
428
469
  }, [slot]);
429
470
  return isActive ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
@@ -434,15 +475,13 @@ var emptySubscribe = function() {
434
475
  var emptySnapshot = function() {
435
476
  return 0;
436
477
  };
437
- var useAdaptIsActiveGiven = function(param) {
438
- var { when, platform } = param;
478
+ var useAdaptIsActiveGiven = function(config) {
439
479
  var media = (0, import_core.useMedia)();
480
+ var when = config === null || config === void 0 ? void 0 : config.when;
481
+ var platform = config === null || config === void 0 ? void 0 : config.platform;
440
482
  if (when == null && platform == null) {
441
483
  return false;
442
484
  }
443
- if (when === true) {
444
- return true;
445
- }
446
485
  var enabled = false;
447
486
  if (platform === "touch") enabled = import_constants.isTouchable;
448
487
  else if (platform === "native") enabled = !import_constants.isWeb;
@@ -452,20 +491,23 @@ var useAdaptIsActiveGiven = function(param) {
452
491
  if (platform && enabled == false) {
453
492
  return false;
454
493
  }
494
+ if (when === true) {
495
+ return true;
496
+ }
455
497
  if (when && typeof when === "string") {
456
498
  enabled = media[when];
457
499
  }
458
500
  return enabled;
459
501
  };
460
502
  var useAdaptIsActive = function(scope) {
461
- var props = useAdaptContext(scope);
462
- var isActiveGiven = useAdaptIsActiveGiven(props);
463
- return props.active || isActiveGiven;
503
+ return useAdaptContext(scope).active;
464
504
  };
465
505
  function useAdaptTarget(scope) {
466
506
  var context = useAdaptContext(scope);
507
+ var targetScope = useAdaptTargetScope();
508
+ var isTarget = scope !== void 0 || targetScope === context.scopeName;
467
509
  (0, import_constants.useIsomorphicLayoutEffect)(function() {
468
- if (!context.active) return;
510
+ if (!context.active || !isTarget) return;
469
511
  context.registerTarget();
470
512
  return function() {
471
513
  context.unregisterTarget();
@@ -473,9 +515,10 @@ function useAdaptTarget(scope) {
473
515
  }, [
474
516
  context.active,
475
517
  context.registerTarget,
476
- context.unregisterTarget
518
+ context.unregisterTarget,
519
+ isTarget
477
520
  ]);
478
- if (!context.active) {
521
+ if (!context.active || !isTarget) {
479
522
  return null;
480
523
  }
481
524
  return {