@jsenv/navi 0.29.364 → 0.29.366

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.
@@ -59390,6 +59390,13 @@ const clipOf = (side, distance) => {
59390
59390
  * (TARGET_WAIT_MS), on the half-strength frame where the anchor is still
59391
59391
  * readable, and lifts the moment it is there.
59392
59392
  *
59393
+ * A closing may land where no opening took off: a dialog opened the plain way
59394
+ * (`animation={{ open, close: "lifting" }}` in dialog.jsx), closing into a box the close
59395
+ * itself brings — the state `onClose` writes renders the place the lifted node
59396
+ * belongs to. So the box a closing comes back to is read once the change is
59397
+ * made, inside the transition, and when the caller named it (`liftAnchor`) it
59398
+ * is waited for (LANDING_WAIT_MS): the new picture is taken once it is there.
59399
+ *
59393
59400
  * One name serves the whole movement, because only one of the two boxes is on
59394
59401
  * screen at a time: it names the anchor while the popup is closed, and the
59395
59402
  * lifted node while it is open.
@@ -59432,6 +59439,12 @@ const ARRIVING_ATTRIBUTE = "data-navi-popup-lift-arriving";
59432
59439
  // stands, without a movement, so a target that never comes cannot keep it
59433
59440
  // unpainted.
59434
59441
  const TARGET_WAIT_MS = 1000;
59442
+ // How long a closing waits for the box it comes back to, when that box is
59443
+ // brought by the close (see this file's top comment). The page is frozen on
59444
+ // the picture of the open popup meanwhile, so the wait is short: what it
59445
+ // covers is a render, not a fetch. Past it the popup's picture plays out on
59446
+ // its own.
59447
+ const LANDING_WAIT_MS = 300;
59435
59448
  // The popup's own animation duration, published on the root because the
59436
59449
  // ::view-transition tree hangs off it and inherits from nowhere else.
59437
59450
  const DURATION_PROPERTY = "--navi-popup-lift-duration";
@@ -59472,14 +59485,16 @@ let releaseScrollHold = null;
59472
59485
  * a view transition morphing the anchor's box into the lifted node's, or back.
59473
59486
  *
59474
59487
  * `opened` says which way: the box being left is the anchor when the popup is
59475
- * opening and the lifted node when it is closing. `lift` is Dialog's own prop
59476
- * of that name.
59488
+ * opening and the lifted node when it is closing. `resolveAnchor` is read on
59489
+ * the spot for an opening, and once the change is made for a closing;
59490
+ * `waitForAnchor` has a closing wait for it when it is not there yet. `lift`
59491
+ * is Dialog's own prop of that name.
59477
59492
  */
59478
59493
  const liftPopupFromAnchor = (
59479
59494
  popupEl,
59480
- anchorElement,
59495
+ resolveAnchor,
59481
59496
  applyChange,
59482
- { opened, lift },
59497
+ { opened, lift, waitForAnchor },
59483
59498
  ) => {
59484
59499
  const startViewTransition = ensureDocumentStartViewTransition();
59485
59500
  // A movement still wearing the name would make the name two elements wide,
@@ -59487,7 +59502,7 @@ const liftPopupFromAnchor = (
59487
59502
  // document.
59488
59503
  releaseLiftInProgress?.();
59489
59504
 
59490
- const elementLeaving = opened ? anchorElement : resolveLiftTarget(popupEl);
59505
+ const elementLeaving = opened ? resolveAnchor() : resolveLiftTarget(popupEl);
59491
59506
  // Read before the first write: the read brings the style up to date, and a
59492
59507
  // write before it would make it bring it up to date once more.
59493
59508
  const duration = getComputedStyle(popupEl)
@@ -59511,12 +59526,14 @@ const liftPopupFromAnchor = (
59511
59526
 
59512
59527
  let giveBackNameArriving = null;
59513
59528
  let stopWaitingForTarget = null;
59529
+ let stopWaitingForAnchor = null;
59514
59530
  const release = () => {
59515
59531
  if (releaseLiftInProgress !== release) {
59516
59532
  return;
59517
59533
  }
59518
59534
  releaseLiftInProgress = null;
59519
59535
  stopWaitingForTarget?.();
59536
+ stopWaitingForAnchor?.();
59520
59537
  boxAnimationInProgress?.cancel();
59521
59538
  boxAnimationInProgress = null;
59522
59539
  releaseScrollHold?.();
@@ -59542,13 +59559,18 @@ const liftPopupFromAnchor = (
59542
59559
  const boxLeaving = room ? elementLeaving.getBoundingClientRect() : null;
59543
59560
  let boxArriving = null;
59544
59561
  let cornersArriving = null;
59545
- const viewTransition = startViewTransition(() => {
59562
+ const viewTransition = startViewTransition(async () => {
59546
59563
  // The name is the arriving box's from here on: worn by both, it is worn
59547
59564
  // by neither. Written rather than removed, so a name the element also
59548
59565
  // has from a stylesheet cannot resurface for the length of the movement.
59549
59566
  elementLeaving.style.setProperty(NAME_PROPERTY, "none");
59550
59567
  change();
59551
- const elementArriving = resolveElementArriving();
59568
+ const elementArriving = await resolveElementArriving();
59569
+ // Replaced while waiting for its landing: the movement replacing it
59570
+ // holds the name now.
59571
+ if (releaseLiftInProgress !== release) {
59572
+ return;
59573
+ }
59552
59574
  if (elementArriving) {
59553
59575
  giveBackNameArriving = wearLiftName(elementArriving);
59554
59576
  cornersArriving = readCorners(elementArriving);
@@ -59573,12 +59595,24 @@ const liftPopupFromAnchor = (
59573
59595
  };
59574
59596
 
59575
59597
  if (!opened) {
59576
- startMovement(applyChange, () =>
59598
+ startMovement(applyChange, () => {
59599
+ const anchorElement = resolveAnchor();
59600
+ if (anchorElement?.isConnected) {
59601
+ return anchorElement;
59602
+ }
59577
59603
  // Gone from the document while the popup was open (the row it stood in
59578
59604
  // was removed): nothing to arrive at, and the browser plays the popup's
59579
59605
  // picture out on its own.
59580
- anchorElement.isConnected ? anchorElement : null,
59581
- );
59606
+ if (!waitForAnchor) {
59607
+ return null;
59608
+ }
59609
+ return new Promise((resolve) => {
59610
+ stopWaitingForAnchor = whenAnchorAppears(resolveAnchor, (element) => {
59611
+ stopWaitingForAnchor = null;
59612
+ resolve(element);
59613
+ });
59614
+ });
59615
+ });
59582
59616
  return;
59583
59617
  }
59584
59618
 
@@ -59712,6 +59746,40 @@ const whenLiftTargetAppears = (popupEl, callback) => {
59712
59746
  return stop;
59713
59747
  };
59714
59748
 
59749
+ // Calls `callback` with the anchor once `resolveAnchor` finds it in the
59750
+ // document, or with null past LANDING_WAIT_MS — or when stopped, since the
59751
+ // transition's update is waiting on it. Returns how to stop.
59752
+ const whenAnchorAppears = (resolveAnchor, callback) => {
59753
+ const observer = new MutationObserver(() => {
59754
+ const anchorElement = resolveAnchor();
59755
+ if (anchorElement?.isConnected) {
59756
+ stop(anchorElement);
59757
+ }
59758
+ });
59759
+ observer.observe(document.documentElement, {
59760
+ childList: true,
59761
+ subtree: true,
59762
+ attributes: true,
59763
+ attributeFilter: ["id"],
59764
+ });
59765
+ const timeout = setTimeout(() => {
59766
+ stop(null);
59767
+ }, LANDING_WAIT_MS);
59768
+ let stopped = false;
59769
+ const stop = (anchorElement = null) => {
59770
+ if (stopped) {
59771
+ return;
59772
+ }
59773
+ stopped = true;
59774
+ observer.disconnect();
59775
+ clearTimeout(timeout);
59776
+ callback(anchorElement);
59777
+ };
59778
+ return () => {
59779
+ stop(null);
59780
+ };
59781
+ };
59782
+
59715
59783
  const ignore = () => {};
59716
59784
 
59717
59785
  // The room the fixed bars leave, in viewport coordinates; null without bars.
@@ -60377,6 +60445,18 @@ const css$E = /* css */`
60377
60445
  opacity: 0;
60378
60446
  }
60379
60447
 
60448
+ /* A closing lift is the dialog leaving as a picture: whatever exit its
60449
+ opening animation arms (animation={{ open, close: "lifting" }}, see
60450
+ popup_css.js) would
60451
+ keep it rendered into the picture of the state it closes into. */
60452
+ :root[data-navi-popup-lift="closing"] {
60453
+ .navi_dialog,
60454
+ .navi_dialog::backdrop,
60455
+ .navi_dialog_backdrop {
60456
+ transition: none;
60457
+ }
60458
+ }
60459
+
60380
60460
  /* While a dialog is lifting out of the element that opened it
60381
60461
  (popup_lift.js). The page around IS taken as a picture, the browser's own
60382
60462
  default, and on purpose: the wall and what the dialog holds around the
@@ -60619,7 +60699,7 @@ const css$E = /* css */`
60619
60699
  * scroll while open (its backdrop only covers the scrollport, so scrolling
60620
60700
  * there would reveal uncovered content); this prop extends the lock to the
60621
60701
  * whole page. Defaults to `true` for a dialog docked by `dockedOnSmallTouchScreen`.
60622
- * @param {boolean|"auto"|"fading"|"scaling"|"sliding"|"lifting"|`slide-from-${string}`} [props.animation]
60702
+ * @param {boolean|"auto"|"fading"|"scaling"|"sliding"|"lifting"|`slide-from-${string}`|{open: boolean|"auto"|"fading"|"scaling"|"sliding"|`slide-from-${string}`, close: "lifting"}} [props.animation]
60623
60703
  * - `true`/`"auto"` resolves to `"scaling"` for a centered `positionArea`,
60624
60704
  * or a concrete `"slide-from-*"` direction otherwise. Any other explicit
60625
60705
  * value is used as-is. `"lifting"` is the odd one out: every other kind
@@ -60638,6 +60718,15 @@ const css$E = /* css */`
60638
60718
  * being what the movement leaves rather than a context to keep readable;
60639
60719
  * `backdropVariant="discrete"` asks for the light wash back. See
60640
60720
  * `popup_lift.js`.
60721
+ * - `{ open, close: "lifting" }`: the close alone lifts. The dialog opens
60722
+ * with `open` (any value above but `"lifting"`), and its `data-lift` node
60723
+ * travels into `liftAnchor` on close — for a dialog that did not come out
60724
+ * of what it lands in (a banner opens a full-screen reveal, closing it puts
60725
+ * the crest in its place on the plate that replaces the banner). The box it
60726
+ * lands in may be rendered by the close itself: `liftAnchor` is read once
60727
+ * `onClose` has run, and waited for a moment when it is not there yet.
60728
+ * `"lifting"` is the only `close` that differs from the opening: every
60729
+ * other kind closes by playing its opening backwards.
60641
60730
  * @param {"box"|"scene"} [props.lift="box"] - Under `animation="lifting"`,
60642
60731
  * what the anchor and what it becomes are to each other, which decides
60643
60732
  * how their pictures sit in the box moving between them. `"box"`: one
@@ -60662,14 +60751,15 @@ const css$E = /* css */`
60662
60751
  * `document.getElementById` when the dialog opens — see popover.jsx's own
60663
60752
  * `anchor` doc for why (mainly `defaultOpen`).
60664
60753
  * @param {Element|{current: Element}|string} [props.liftAnchor] - Under
60665
- * `animation="lifting"`, where the closing brings the box back to, when that
60666
- * is no longer where it came from: a popup one walks through (a row of cards
60667
- * shown one at a time) has something else in front by the time it closes,
60668
- * and the box would otherwise fly back to the card the press opened on. Same
60669
- * grammar as `anchor` (element, ref or id), resolved at the close, so
60670
- * whatever names the card currently in frontan id built from the signal
60671
- * the walk is bound to, a ref moved with it is read then and not at the
60672
- * opening. Left out, the box comes back to the anchor it came out of.
60754
+ * `animation="lifting"` or `animation={{ open, close: "lifting" }}`, where the closing
60755
+ * brings the box back to, when that is not where it came from: a popup one
60756
+ * walks through (a row of cards shown one at a time) has something else in
60757
+ * front by the time it closes, and the box would otherwise fly back to the
60758
+ * card the press opened on. Same grammar as `anchor` (element, ref or id),
60759
+ * resolved once the close is made after `onClose` so whatever names the
60760
+ * card currently in front, or the box the close itself renders, is read
60761
+ * then and not at the opening. Left out, the box comes back to the anchor
60762
+ * it came out of.
60673
60763
  * @param {boolean} [props.sizeFromAnchor=false] - Whether the dialog takes the
60674
60764
  * anchor's width/height as a min-width/min-height floor
60675
60765
  * (`--anchor-width`/`--anchor-height`). Off by default: unlike a popover,
@@ -61152,7 +61242,15 @@ const useDialogProps = props => {
61152
61242
  flushEdges.left = expandX || x === "left" || x === "inset-left";
61153
61243
  flushEdges.right = expandX || x === "right" || x === "inset-right";
61154
61244
  }
61155
- const isAutoAnimation = animation === true || animation === "auto";
61245
+
61246
+ // `{ open, close }` says each way on its own; a single value says both.
61247
+ const {
61248
+ open: openAnimation,
61249
+ close: closeAnimation = openAnimation
61250
+ } = animation !== null && typeof animation === "object" ? animation : {
61251
+ open: animation
61252
+ };
61253
+ const isAutoAnimation = openAnimation === true || openAnimation === "auto";
61156
61254
  // The dialog and the anchor are one box, and what plays between them is the
61157
61255
  // browser's own morph (popup_lift.js) — nothing this dialog does to its own
61158
61256
  // box. So it arms no CSS transition of its own, which is not merely useless
@@ -61160,11 +61258,12 @@ const useDialogProps = props => {
61160
61258
  // with allow-discrete, and a dialog kept rendered for the length of its exit
61161
61259
  // is exactly what the picture taken of the state it closes into must not
61162
61260
  // show.
61163
- const lifting = animation === "lifting";
61261
+ const lifting = openAnimation === "lifting";
61262
+ const liftsOnClose = closeAnimation === "lifting";
61164
61263
  // Dialog never has a real anchor to POSITION against (see this file's top
61165
61264
  // comment), so this is always the "no anchor" path — the same one Popover's
61166
61265
  // own custom renderer falls into when it has no real anchor either.
61167
- const resolvedAnimationKind = isAutoAnimation ? resolveAutoAnimationKind(undefined, parsedPositionArea) : animation;
61266
+ const resolvedAnimationKind = isAutoAnimation ? resolveAutoAnimationKind(undefined, parsedPositionArea) : openAnimation;
61168
61267
  // Not gated on isAutoAnimation — an explicit animation="sliding" needs a
61169
61268
  // concrete direction just as much as an auto-resolved one does (same as
61170
61269
  // Popover's own "sliding"/"expanding" resolution step in openEffect).
@@ -61213,13 +61312,11 @@ const useDialogProps = props => {
61213
61312
  // is in front NOW, which only the caller knows. Resolved at the close for
61214
61313
  // that reason: the element it names changes while the popup is open, so
61215
61314
  // anything read at the opening would be the walk's starting point again.
61315
+ // Silent when it names nothing: the close may be what renders it, and
61316
+ // popup_lift.js asks again until it is there (and warns past that).
61216
61317
  const resolveLiftAnchorElement = () => {
61217
61318
  if (typeof liftAnchor === "string") {
61218
- const liftAnchorElementById = document.getElementById(liftAnchor);
61219
- if (!liftAnchorElementById) {
61220
- console.warn(`Dialog: liftAnchor="${liftAnchor}" did not match any element`);
61221
- }
61222
- return liftAnchorElementById;
61319
+ return document.getElementById(liftAnchor);
61223
61320
  }
61224
61321
  // A ref is unwrapped even when it holds nothing, the same way `anchor` is:
61225
61322
  // the ref object itself has no box to come back to.
@@ -61231,7 +61328,7 @@ const useDialogProps = props => {
61231
61328
  // provided the change happens between its two pictures, which is what
61232
61329
  // handing it to the controller buys (see popup_lift.js and
61233
61330
  // open_controller.js's own transitionChange).
61234
- openController.transitionChange = lifting ? (applyChange, {
61331
+ openController.transitionChange = liftsOnClose ? (applyChange, {
61235
61332
  opened,
61236
61333
  event
61237
61334
  }) => {
@@ -61239,23 +61336,26 @@ const useDialogProps = props => {
61239
61336
  // A mount-time opening was never seen closed (see openEffect's own
61240
61337
  // `silent`): there is no box it comes from, because nothing was shown
61241
61338
  // before it.
61242
- if (!dialogEl || opened && event.detail.silent) {
61339
+ if (!dialogEl || opened && (!lifting || event.detail.silent)) {
61243
61340
  applyChange();
61244
61341
  return;
61245
61342
  }
61246
- let anchorElement;
61247
- if (opened) {
61248
- anchorElement = resolveAnchorElement(event);
61249
- } else if (liftAnchor) {
61250
- anchorElement = resolveLiftAnchorElement();
61251
- } else {
61252
- anchorElement = anchorElementRef.current;
61343
+ if (!opened) {
61344
+ // Read once the close is made (popup_lift.js): the box it lands in
61345
+ // may be one the close itself renders.
61346
+ liftPopupFromAnchor(dialogEl, liftAnchor ? resolveLiftAnchorElement : () => anchorElementRef.current, applyChange, {
61347
+ opened,
61348
+ lift,
61349
+ waitForAnchor: Boolean(liftAnchor)
61350
+ });
61351
+ return;
61253
61352
  }
61353
+ const anchorElement = resolveAnchorElement(event);
61254
61354
  if (!anchorElement) {
61255
61355
  applyChange();
61256
61356
  return;
61257
61357
  }
61258
- liftPopupFromAnchor(dialogEl, anchorElement, applyChange, {
61358
+ liftPopupFromAnchor(dialogEl, () => anchorElement, applyChange, {
61259
61359
  opened,
61260
61360
  lift
61261
61361
  });
@@ -63990,8 +64090,8 @@ const PickerCustom = props => {
63990
64090
  // before computing popupId below, so two Pickers without an explicit id never collide.
63991
64091
  // Captured before the fallback chain below overwrites props.id — needed to
63992
64092
  // know whether the id actually came from the caller (stable) or from
63993
- // useId()/ControlIdContext (not guaranteed stable across a reload), see
63994
- // pickerNavType below.
64093
+ // useId()/ControlIdContext (a generated id names one mount: a reload, or a
64094
+ // return to this page, generates another), see pickerNavType below.
63995
64095
  const hasExplicitId = Boolean(props.id);
63996
64096
  const idDefault = useId();
63997
64097
  const controlId = useContext(ControlIdContext);
@@ -64067,10 +64167,12 @@ const PickerCustom = props => {
64067
64167
  // pushes a history entry so the back button closes it. Every other case
64068
64168
  // (popover mode, or a dialog whose id was auto-generated via useId()/
64069
64169
  // ControlIdContext) replaces the current history state instead — a
64070
- // generated id isn't stable across a reload, so pushing it would either
64071
- // silently drop the entry or, worse, collide with a different
64072
- // component's own generated id (see useNavState's own fallback for the
64073
- // same concern, applied here proactively for the id we control).
64170
+ // generated id names one mount, so pushing it would either leave an entry
64171
+ // nothing reads or, worse, collide with a different component's own
64172
+ // generated id (see useNavState's own fallback for the same concern,
64173
+ // applied here proactively for the id we control). What a generated id
64174
+ // costs either way: the state is written, and the mount coming back to
64175
+ // the page (or a reload) finds it under a key it does not have.
64074
64176
  const pickerNavType = mode === "dialog" && hasExplicitId ? "push" : "replace";
64075
64177
  const [expanded, enterExpanded, leaveExpanded] = useNavState(popupId, {
64076
64178
  type: pickerNavType,
@@ -64596,6 +64698,7 @@ const PickerContentInsidePopup = props => {
64596
64698
  popupWidthFitContent,
64597
64699
  animation,
64598
64700
  lift,
64701
+ liftAnchor,
64599
64702
  animationDuration,
64600
64703
  // mode="callout": what the callout says about what it holds, and paints
64601
64704
  // in its border and icon — "none" for a plain tooltip (see the callout
@@ -64692,6 +64795,7 @@ const PickerContentInsidePopup = props => {
64692
64795
  dockedOnSmallTouchScreen: isPopover ? undefined : dockedOnSmallTouchScreen,
64693
64796
  sizeFromAnchor: isPopover ? undefined : dialogSizeFromAnchor,
64694
64797
  lift: isPopover ? undefined : lift,
64798
+ liftAnchor: isPopover ? undefined : liftAnchor,
64695
64799
  children: jsx(PopupModeContext.Provider, {
64696
64800
  value: mode,
64697
64801
  children: children