@jsenv/navi 0.29.319 → 0.29.321

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.
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { installImportMetaCssBuild, windowHeightSignal, windowWidthSignal, visualViewportHeightSignal, visualViewportWidthSignal, getAppHeight, getAppWidth, coarsePointerSignal, smallTouchScreenSignal } from "./jsenv_navi_side_effects.js";
6
6
  export { disableVirtualKeyboardOverlay } from "./jsenv_navi_side_effects.js";
7
- import { elementIsFocusable, createIterableWeakSet, dispatchInternalCustomEvent, dispatchCustomEvent, getVisuallyVisibleInfo, getFirstVisuallyVisibleAncestor, getElementSignature, createPubSub, findEvent, createValueEffect, findFocusDelegateTarget, findFocusable, scrollIntoViewThroughScrollables, allowWheelThrough, dispatchPublicCustomEvent, resolveCSSColor, ELEMENT_SIZE_CHANGE, findSelfOrAncestorFixedPosition, visibleRectEffect, pickPositionRelativeTo, getBorderSizes, getPaddingSizes, applyNewPosition, measureLongestVisualLineWidth, chainEvent, keepTouchRefusable, isPressDrivenClick, waitForTap, waitForPressHeld, suppressClickAfterGesture, startDragToTravel, markDragSource, refuseDragTo, startDragTo, installPanZoom, createEventGroupLogger, getKeyboardEventDefaultAction, activeElementSignal, normalizeStyle, mergeOneStyle, getPositionedParent, normalizeStyles, createGroupTransitionController, getBorderRadius, preventIntermediateScrollbar, createOpacityTransition, watchWheelTravel, scrollRoomTowards, getScrollContainer, isTouchDrivenEvent, scrollIntoViewScoped, closestOpenableAncestor, isAncestorOpen, isDisplayedDespiteClosedAncestor, observeAncestorOpenState, getAncestorOpenType, findBefore, findAfter, resolveCSSSize, hasCSSSizeUnit, releaseWheelGesture, getScrollIntoViewScopedOffsets, wheelGestureIsTakenFrom, claimWheelGesture, initFocusGroup, stringifyStyle as stringifyStyle$1, resolveOklchLightness, contrastColor, parsePositionArea, snapToPixel, trapFocusInside, trapScrollInside, getVirtualKeyboardOverlayHeight, onAncestorReopen, isPressDisputedByDrag, canScroll, measureWidestChildRow, performTabNavigation, dragAfterIntent, stickyAsRelativeCoords, createDragToMoveGestureController, getDropTargetInfo, setStyles, useActiveElement } from "@jsenv/dom";
7
+ import { elementIsFocusable, createIterableWeakSet, dispatchInternalCustomEvent, dispatchCustomEvent, getVisuallyVisibleInfo, getFirstVisuallyVisibleAncestor, getElementSignature, createPubSub, findEvent, createValueEffect, findFocusDelegateTarget, findFocusable, scrollIntoViewThroughScrollables, allowWheelThrough, dispatchPublicCustomEvent, resolveCSSColor, ELEMENT_SIZE_CHANGE, findSelfOrAncestorFixedPosition, visibleRectEffect, pickPositionRelativeTo, getBorderSizes, getPaddingSizes, applyNewPosition, measureLongestVisualLineWidth, chainEvent, keepTouchRefusable, isPressDrivenClick, waitForTap, waitForPressHeld, suppressClickAfterGesture, startDragToTravel, dragSourceThatStoodDown, markDragSource, refuseDragTo, startDragTo, installPanZoom, createEventGroupLogger, getKeyboardEventDefaultAction, activeElementSignal, normalizeStyle, mergeOneStyle, getPositionedParent, normalizeStyles, createGroupTransitionController, getBorderRadius, preventIntermediateScrollbar, createOpacityTransition, watchWheelTravel, scrollRoomTowards, getScrollContainer, isTouchDrivenEvent, scrollIntoViewScoped, closestOpenableAncestor, isAncestorOpen, isDisplayedDespiteClosedAncestor, observeAncestorOpenState, getAncestorOpenType, findBefore, findAfter, resolveCSSSize, hasCSSSizeUnit, releaseWheelGesture, getScrollIntoViewScopedOffsets, wheelGestureIsTakenFrom, claimWheelGesture, initFocusGroup, stringifyStyle as stringifyStyle$1, resolveOklchLightness, contrastColor, parsePositionArea, snapToPixel, trapFocusInside, trapScrollInside, getVirtualKeyboardOverlayHeight, onAncestorReopen, isPressDisputedByDrag, canScroll, measureWidestChildRow, performTabNavigation, dragAfterIntent, stickyAsRelativeCoords, createDragToMoveGestureController, getDropTargetInfo, setStyles, useActiveElement } from "@jsenv/dom";
8
8
  export { chainEvent, clickIsSuppressed, contrastColor, createDragGestureController, dragAfterIntent, findEvent, markDragSource, startDragTo } from "@jsenv/dom";
9
9
  import { signal, computed, effect, untracked, batch, useComputed, useSignal } from "@preact/signals";
10
10
  import { isValidElement, createContext, render, h, toChildArray, options, cloneElement, Fragment as Fragment$1 } from "preact";
@@ -10911,7 +10911,17 @@ defineInteractionDetector({
10911
10911
  },
10912
10912
  });
10913
10913
  }
10914
- if (hasLongPress) {
10914
+ // A press on something INSIDE this element that is picked up and
10915
+ // carried is that thing's, the same nearer word as the inner hold below:
10916
+ // a finger held still on a piece is the piece's own hold when it drags
10917
+ // by holding, and when it drags by distance it has decided nothing yet
10918
+ // at the delay — a hold answered there is a hold on a piece, and a carry
10919
+ // out of the same press the moment the hand moves. A surface that pans
10920
+ // steps back from the same source at the press (see pan_zoom.js).
10921
+ if (
10922
+ hasLongPress &&
10923
+ !isPressOnDragSourceInside(pointerDownEvent, element)
10924
+ ) {
10915
10925
  // A hold declared INSIDE this element, on this same press: the nearer
10916
10926
  // one answers, the way a click is the innermost target's, and this
10917
10927
  // wait is given up — two sheets opening from one hold is nobody's
@@ -11091,6 +11101,23 @@ const startSwipe = (
11091
11101
  });
11092
11102
  };
11093
11103
 
11104
+ // Whether the press landed on a drag source strictly inside the element — the
11105
+ // element itself being one is the other arrangement, where the grab answers
11106
+ // the hold (see refuseDragTo in @jsenv/dom). A source that stood down from this
11107
+ // press carries nothing, so it is no reason to hold back, and the walk goes on
11108
+ // above it the way a surface's does.
11109
+ const isPressOnDragSourceInside = (pointerDownEvent, element) => {
11110
+ const target = pointerDownEvent.target;
11111
+ if (!target || typeof target.closest !== "function") {
11112
+ return false;
11113
+ }
11114
+ let source = target.closest("[data-drag-source]");
11115
+ if (source && source === dragSourceThatStoodDown(pointerDownEvent)) {
11116
+ source = source.parentElement?.closest("[data-drag-source]") || null;
11117
+ }
11118
+ return Boolean(source) && source !== element && element.contains(source);
11119
+ };
11120
+
11094
11121
  // Whether a press landing now completes the tap before it: the same hand, soon
11095
11122
  // enough, and near enough. Axis by axis rather than as a distance, the way every
11096
11123
  // other slop in this family is read.
@@ -27799,14 +27826,35 @@ Consider using unique IDs for each component instance.`,
27799
27826
 
27800
27827
  const NO_OP = () => {};
27801
27828
  const NO_ID_GIVEN = [undefined, NO_OP, NO_OP];
27829
+ // What the computed below answers for a key the document state does not hold:
27830
+ // key presence is the flag, and the value under a present key may be anything,
27831
+ // undefined included.
27832
+ const KEY_NOT_IN_STATE = Symbol("key_not_in_state");
27802
27833
  const useNavStateBasic = (
27803
27834
  id,
27804
27835
  { debug, type = "replace", onLeave, defaultValue } = {},
27805
27836
  ) => {
27806
27837
  // Hooks must be called unconditionally — before the !id early return.
27807
- const state = documentStateSignal.value;
27808
- // Key presence is the flag — the value may be anything, including undefined.
27809
- const keyInState = Boolean(id && state && Object.hasOwn(state, id));
27838
+ //
27839
+ // Subscribed to this one key, through a computed, rather than to the state
27840
+ // as a whole: every popup with a nav state reads here, and a document state
27841
+ // is written whenever any of them opens — a list of forty names each with a
27842
+ // tooltip would re-render forty pickers, chains included, for the sheet
27843
+ // around them opening. The computed only wakes this component when what
27844
+ // sits under its own key changes.
27845
+ const keyValueComputed = useMemo(
27846
+ () =>
27847
+ computed(() => {
27848
+ const state = documentStateSignal.value;
27849
+ if (id && state && Object.hasOwn(state, id)) {
27850
+ return state[id];
27851
+ }
27852
+ return KEY_NOT_IN_STATE;
27853
+ }),
27854
+ [id],
27855
+ );
27856
+ const keyValue = keyValueComputed.value;
27857
+ const keyInState = keyValue !== KEY_NOT_IN_STATE;
27810
27858
  const onLeaveRef = useRef(onLeave);
27811
27859
  onLeaveRef.current = onLeave;
27812
27860
  const prevKeyInStateRef = useRef(keyInState);
@@ -27841,7 +27889,7 @@ const useNavStateBasic = (
27841
27889
  effectiveType = "replace";
27842
27890
  }
27843
27891
 
27844
- const currentValue = keyInState ? state[id] : defaultValue;
27892
+ const currentValue = keyInState ? keyValue : defaultValue;
27845
27893
 
27846
27894
  if (debug) {
27847
27895
  console.debug(`useNavState(${id}) current value is ${currentValue}`);
@@ -35465,6 +35513,18 @@ const MOUNT_DEFAULT = "from-first-open";
35465
35513
  const popupsMountingContentForOpen = new Set();
35466
35514
  const isMountingContentForOpen = (popupElement) =>
35467
35515
  popupsMountingContentForOpen.has(popupElement);
35516
+ // The popup being built that holds `element` somewhere below it, or null. For
35517
+ // an element whose own openable ancestor is something else (a closed trigger
35518
+ // inside the popup): what the layout would say about it is what it says about
35519
+ // the whole popup — nothing is on screen there yet.
35520
+ const findPopupMountingContentAround = (element) => {
35521
+ for (const popupElement of popupsMountingContentForOpen) {
35522
+ if (popupElement !== element && popupElement.contains(element)) {
35523
+ return popupElement;
35524
+ }
35525
+ }
35526
+ return null;
35527
+ };
35468
35528
 
35469
35529
  // requestIdleCallback is missing from Safari; a timeout is close enough there.
35470
35530
  const requestIdle = (callback) =>
@@ -35634,6 +35694,9 @@ const useDisplayedLayoutEffect = (ref, callback, deps) => {
35634
35694
  // Set by the mount effect below for an element that lives in its openable
35635
35695
  // ancestor's façade rather than in what that ancestor opens.
35636
35696
  const displayedWhileAncestorClosedRef = useRef(false);
35697
+ // The popup whose opening will answer what the mount could not — see the
35698
+ // mount effect below.
35699
+ const decisionDeferredToRef = useRef(null);
35637
35700
 
35638
35701
  // Run on mount (or when deps change) — but only if the element is visible.
35639
35702
  useLayoutEffect(() => {
@@ -35647,14 +35710,26 @@ const useDisplayedLayoutEffect = (ref, callback, deps) => {
35647
35710
  return;
35648
35711
  }
35649
35712
  if (!isAncestorOpen(ancestor)) {
35650
- if (
35713
+ if (isMountingContentForOpen(ancestor)) {
35651
35714
  // The popup building its content for its own opening: nothing in it
35652
35715
  // is on screen, and the open about to follow reveals all of it. Known
35653
35716
  // without asking the layout, which a synchronous mount would have to
35654
- // bring up to date once per element asking.
35655
- isMountingContentForOpen(ancestor) ||
35656
- !isDisplayedDespiteClosedAncestor(el, ancestor)
35657
- ) {
35717
+ // bring up to date once per element asking; the observer below fires
35718
+ // once it opens.
35719
+ return;
35720
+ }
35721
+ const popupMounting = findPopupMountingContentAround(el);
35722
+ if (popupMounting) {
35723
+ // Under a closed trigger — a picker's façade, an expandable's header —
35724
+ // inside a popup being built. Whether this element is on screen once
35725
+ // that popup is open is exactly what the layout cannot say while the
35726
+ // popup, and everything in it, is display:none: it would answer "hidden"
35727
+ // for a façade that the opening is about to show. Asked again when the
35728
+ // popup opens (see the observer effect below).
35729
+ decisionDeferredToRef.current = popupMounting;
35730
+ return;
35731
+ }
35732
+ if (!isDisplayedDespiteClosedAncestor(el, ancestor)) {
35658
35733
  // Ancestor is closed and took this element off screen with it — skip
35659
35734
  // now; the observeAncestorOpenState call below will fire once it
35660
35735
  // opens.
@@ -35678,19 +35753,63 @@ const useDisplayedLayoutEffect = (ref, callback, deps) => {
35678
35753
  if (!ancestor) {
35679
35754
  return undefined;
35680
35755
  }
35681
- return observeAncestorOpenState(ancestor, ({ isOpen }) => {
35682
- if (!isOpen) {
35683
- return;
35684
- }
35685
- if (displayedWhileAncestorClosedRef.current) {
35686
- // Façade content: on screen the whole time, so this opening reveals
35687
- // nothing here — and `becauseAncestorOpened: true` about it would be
35688
- // false in a way consumers act on (see use_auto_focus.js).
35689
- return;
35690
- }
35691
- const lastEl = ref.current;
35692
- callbackRef.current(lastEl, createDisplayedEvent(ancestor, true));
35693
- });
35756
+ const stopObservingAncestor = observeAncestorOpenState(
35757
+ ancestor,
35758
+ ({ isOpen }) => {
35759
+ if (!isOpen) {
35760
+ return;
35761
+ }
35762
+ if (displayedWhileAncestorClosedRef.current) {
35763
+ // Façade content: on screen the whole time, so this opening reveals
35764
+ // nothing here — and `becauseAncestorOpened: true` about it would be
35765
+ // false in a way consumers act on (see use_auto_focus.js).
35766
+ return;
35767
+ }
35768
+ const lastEl = ref.current;
35769
+ callbackRef.current(lastEl, createDisplayedEvent(ancestor, true));
35770
+ },
35771
+ );
35772
+ const popupMounting = decisionDeferredToRef.current;
35773
+ if (!popupMounting) {
35774
+ return stopObservingAncestor;
35775
+ }
35776
+ // The mount deferred its decision to this popup's opening (see above):
35777
+ // once it is open, the layout answers for what the closed ancestor keeps
35778
+ // on screen. A façade element is then displayed, by that opening — which
35779
+ // owns it, the way it owns everything the popup reveals. An element the
35780
+ // closed ancestor genuinely hides stays with the observer above.
35781
+ const stopObservingPopup = observeAncestorOpenState(
35782
+ popupMounting,
35783
+ ({ isOpen }) => {
35784
+ if (!isOpen) {
35785
+ return;
35786
+ }
35787
+ stopObservingPopup();
35788
+ decisionDeferredToRef.current = null;
35789
+ const lastEl = ref.current;
35790
+ if (!lastEl) {
35791
+ return;
35792
+ }
35793
+ if (isAncestorOpen(ancestor)) {
35794
+ callbackRef.current(
35795
+ lastEl,
35796
+ createDisplayedEvent(popupMounting, true),
35797
+ );
35798
+ return;
35799
+ }
35800
+ if (isDisplayedDespiteClosedAncestor(lastEl, ancestor)) {
35801
+ displayedWhileAncestorClosedRef.current = true;
35802
+ callbackRef.current(
35803
+ lastEl,
35804
+ createDisplayedEvent(popupMounting, true),
35805
+ );
35806
+ }
35807
+ },
35808
+ );
35809
+ return () => {
35810
+ stopObservingAncestor();
35811
+ stopObservingPopup();
35812
+ };
35694
35813
  }, []);
35695
35814
  };
35696
35815
 
@@ -70059,6 +70178,7 @@ const ListItems = ({
70059
70178
  const virtual = useContext(ListVirtualContext);
70060
70179
  const slotId = useContext(ListSlotContext);
70061
70180
  const renderWindow = useContext(RenderWindowContext);
70181
+ const separator = useContext(SeparatorContext);
70062
70182
  // The vnode drawn for a row, kept by item: a run rendering again (its window
70063
70183
  // moving, its first paint's budget giving way to the full one) hands preact
70064
70184
  // the same vnode for a row that has not changed, and preact leaves that
@@ -70067,14 +70187,14 @@ const ListItems = ({
70067
70187
  // row at the same index, in the same refreshing state: everything the
70068
70188
  // function is given.
70069
70189
  const rowVnodesRef = useRef(null);
70070
- if (!rowVnodesRef.current || rowVnodesRef.current.renderItem !== renderItem) {
70190
+ if (!rowVnodesRef.current || rowVnodesRef.current.renderItem !== renderItem || rowVnodesRef.current.separator !== separator) {
70071
70191
  rowVnodesRef.current = {
70072
70192
  renderItem,
70193
+ separator,
70073
70194
  byItem: new Map()
70074
70195
  };
70075
70196
  }
70076
70197
  const rowVnodesByItem = rowVnodesRef.current.byItem;
70077
- const separator = useContext(SeparatorContext);
70078
70198
  const store = useItemStore({
70079
70199
  items,
70080
70200
  count,
@@ -70304,17 +70424,33 @@ const ListItems = ({
70304
70424
  const item = getItemAt(rowIndex);
70305
70425
  const key = item === undefined ? `${ownerId}_skeleton_${rowIndex}` : idOf(item, rowIndex);
70306
70426
  let rowVnode;
70427
+ let rowContextValue;
70428
+ let rowKept = null;
70307
70429
  if (item !== undefined) {
70308
70430
  const rowVnodeKept = rowVnodesByItem.get(item);
70309
70431
  if (rowVnodeKept && rowVnodeKept.rowIndex === rowIndex && rowVnodeKept.refreshing === renderItemState.refreshing) {
70310
70432
  rowVnode = rowVnodeKept.vnode;
70433
+ rowContextValue = rowVnodeKept.rowContextValue;
70434
+ rowKept = rowVnodeKept;
70311
70435
  } else {
70312
70436
  rowVnode = renderItem(item, rowIndex, renderItemState);
70313
- rowVnodesByItem.set(item, {
70437
+ // Kept with the vnode, for the same reason: a context value that is a
70438
+ // fresh object on every render forces every consumer of it to render,
70439
+ // which is the row's own chain — the vnode handed back unchanged would
70440
+ // then buy nothing.
70441
+ rowContextValue = {
70442
+ id: key,
70443
+ index: rowIndex,
70444
+ item
70445
+ };
70446
+ rowKept = {
70314
70447
  vnode: rowVnode,
70448
+ rowContextValue,
70315
70449
  rowIndex,
70316
- refreshing: renderItemState.refreshing
70317
- });
70450
+ refreshing: renderItemState.refreshing,
70451
+ separatorVnode: null
70452
+ };
70453
+ rowVnodesByItem.set(item, rowKept);
70318
70454
  }
70319
70455
  } else if (renderRowSkeleton === false) {
70320
70456
  // The row must still take its room: without it the rows below would
@@ -70338,20 +70474,25 @@ const ListItems = ({
70338
70474
  // as a hairline under the label.
70339
70475
  const drawSeparator = separator && rowIndex > 0 && !opensGroup(groupKeyOf(item, rowIndex));
70340
70476
  if (drawSeparator) {
70341
- pushRow(cloneElement(resolveSeparatorVnode(separator, rowIndex - 1), {
70342
- key: `${key}_separator`
70343
- }), item, rowIndex);
70477
+ // Kept with the row too: a separator built again is a separator
70478
+ // rendered again.
70479
+ let separatorVnode = rowKept ? rowKept.separatorVnode : null;
70480
+ if (!separatorVnode) {
70481
+ separatorVnode = cloneElement(resolveSeparatorVnode(separator, rowIndex - 1), {
70482
+ key: `${key}_separator`
70483
+ });
70484
+ if (rowKept) {
70485
+ rowKept.separatorVnode = separatorVnode;
70486
+ }
70487
+ }
70488
+ pushRow(separatorVnode, item, rowIndex);
70344
70489
  }
70345
70490
  pushRow(jsx(ListRowContext.Provider, {
70346
70491
  value: item === undefined ? {
70347
70492
  id: key,
70348
70493
  index: rowIndex,
70349
70494
  ...getSkeletonRow()
70350
- } : {
70351
- id: key,
70352
- index: rowIndex,
70353
- item
70354
- },
70495
+ } : rowContextValue,
70355
70496
  children: rowVnode
70356
70497
  }, key), item, rowIndex);
70357
70498
  }