akanjs 3.3.0-rc.35 → 3.3.0-rc.37
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.
- package/package.json +1 -1
- package/types/ui/System/isSamePathValue.d.ts +2 -0
- package/types/webkit/scrollerTakesDrag.d.ts +3 -0
- package/ui/System/Client.tsx +8 -3
- package/ui/System/isSamePathValue.ts +13 -0
- package/webkit/scrollerTakesDrag.ts +31 -0
- package/webkit/useCsrNavigation.ts +10 -2
- package/webkit/useCsrTransitions.ts +20 -9
package/package.json
CHANGED
package/ui/System/Client.tsx
CHANGED
|
@@ -54,6 +54,7 @@ import { readRscRoutePatch, subscribeRscRoutePatch } from "../../client/rscRoute
|
|
|
54
54
|
import { FrameRootVars } from "../../webkit/FrameRootVars";
|
|
55
55
|
import { useTransitionStore } from "../../webkit/useTransitionStore";
|
|
56
56
|
import { getFrameCssVars, isResponsiveFrame } from "./Common";
|
|
57
|
+
import { isSamePathValue } from "./isSamePathValue";
|
|
57
58
|
import { Messages } from "./Messages";
|
|
58
59
|
import { Reconnect } from "./Reconnect";
|
|
59
60
|
|
|
@@ -185,12 +186,13 @@ export const ClientPathWrapper = ({
|
|
|
185
186
|
renderLayouts: [],
|
|
186
187
|
};
|
|
187
188
|
const csr = useCsr();
|
|
189
|
+
const isPending = pageType === "pending";
|
|
188
190
|
const registerFrameSlot = useCallback(
|
|
189
191
|
(slot: Parameters<NonNullable<typeof csr.registerFrameSlot>>[1]) =>
|
|
190
192
|
typeof csr.registerFrameSlot === "function"
|
|
191
|
-
? csr.registerFrameSlot(pathRoute.path, slot,
|
|
193
|
+
? csr.registerFrameSlot(pathRoute.path, slot, isPending ? "pending" : "active")
|
|
192
194
|
: () => undefined,
|
|
193
|
-
[csr.registerFrameSlot, pathRoute.path,
|
|
195
|
+
[csr.registerFrameSlot, pathRoute.path, isPending],
|
|
194
196
|
);
|
|
195
197
|
|
|
196
198
|
const [gestureEnabled, setGestureEnabled] = useState(true);
|
|
@@ -247,8 +249,11 @@ export const ClientPathWrapper = ({
|
|
|
247
249
|
registerFrameSlot,
|
|
248
250
|
],
|
|
249
251
|
);
|
|
252
|
+
|
|
253
|
+
const shownValue = useRef(pathValue);
|
|
254
|
+
if (activity !== "hidden" && !isSamePathValue(shownValue.current, pathValue)) shownValue.current = pathValue;
|
|
250
255
|
return (
|
|
251
|
-
<pathContext.Provider value={
|
|
256
|
+
<pathContext.Provider value={shownValue.current}>
|
|
252
257
|
<pageActivityContext.Provider value={pageActivity}>
|
|
253
258
|
<Frame
|
|
254
259
|
{...bindProps}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PathContextType } from "akanjs/client";
|
|
2
|
+
|
|
3
|
+
export const isSamePathValue = (shown: PathContextType, next: PathContextType) =>
|
|
4
|
+
shown.pageKey === next.pageKey &&
|
|
5
|
+
shown.location.href === next.location.href &&
|
|
6
|
+
shown.location.hash === next.location.hash &&
|
|
7
|
+
shown.location.pathRoute.path === next.location.pathRoute.path &&
|
|
8
|
+
shown.location.pathRoute.renderPage === next.location.pathRoute.renderPage &&
|
|
9
|
+
shown.location.entryId === next.location.entryId &&
|
|
10
|
+
shown.followsRouter === next.followsRouter &&
|
|
11
|
+
shown.prefix === next.prefix &&
|
|
12
|
+
shown.gestureEnabled === next.gestureEnabled &&
|
|
13
|
+
shown.registerFrameSlot === next.registerFrameSlot;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
type DragAxis = "x" | "y";
|
|
2
|
+
|
|
3
|
+
const isScrollable = (overflow: string) => overflow === "auto" || overflow === "scroll";
|
|
4
|
+
|
|
5
|
+
const isReversed = (style: CSSStyleDeclaration, axis: DragAxis) =>
|
|
6
|
+
axis === "y"
|
|
7
|
+
? style.flexDirection === "column-reverse"
|
|
8
|
+
: (style.flexDirection === "row-reverse") !== (style.direction === "rtl");
|
|
9
|
+
|
|
10
|
+
const takes = (node: Element, style: CSSStyleDeclaration, axis: DragAxis, movement: number) => {
|
|
11
|
+
if (!isScrollable(axis === "x" ? style.overflowX : style.overflowY)) return false;
|
|
12
|
+
const span = axis === "x" ? node.scrollWidth - node.clientWidth : node.scrollHeight - node.clientHeight;
|
|
13
|
+
if (span < 1) return false;
|
|
14
|
+
|
|
15
|
+
const offset = Math.abs(axis === "x" ? node.scrollLeft : node.scrollTop);
|
|
16
|
+
const fromStart = isReversed(style, axis) ? span - offset : offset;
|
|
17
|
+
return movement > 0 ? fromStart >= 1 : span - fromStart >= 1;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const scrollerTakesDrag = (
|
|
21
|
+
target: EventTarget | null,
|
|
22
|
+
frame: Element | null,
|
|
23
|
+
axis: DragAxis,
|
|
24
|
+
movement: number,
|
|
25
|
+
) => {
|
|
26
|
+
for (let node = target instanceof Element ? target : null; node; node = node.parentElement) {
|
|
27
|
+
if (takes(node, getComputedStyle(node), axis, movement)) return true;
|
|
28
|
+
if (node === frame) return false;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
};
|
|
@@ -241,11 +241,19 @@ export const useCsrNavigation = (input: CsrNavigationInput) => {
|
|
|
241
241
|
(kind: "push" | "replace", href: string, { scrollToTop }: RouteOptions = {}) => {
|
|
242
242
|
const fromLocation = getCurrentLocation();
|
|
243
243
|
const target = getLocation(href);
|
|
244
|
-
|
|
244
|
+
const cached = target.pathRoute.pageState.cache
|
|
245
|
+
? nav.history.current.cachedLocationMap.get(target.pathRoute.path)
|
|
246
|
+
: undefined;
|
|
247
|
+
|
|
245
248
|
const toLocation =
|
|
246
249
|
kind === "replace" && target.pathRoute.path === fromLocation.pathRoute.path
|
|
247
250
|
? { ...target, entryId: fromLocation.entryId }
|
|
248
|
-
:
|
|
251
|
+
: cached &&
|
|
252
|
+
cached.pathname === target.pathname &&
|
|
253
|
+
cached.search === target.search &&
|
|
254
|
+
cached.hash === target.hash
|
|
255
|
+
? cached
|
|
256
|
+
: target;
|
|
249
257
|
const scrollTop = pageContentRef.current?.scrollTop ?? 0;
|
|
250
258
|
const slides =
|
|
251
259
|
CsrStack.keyOf(toLocation) !== CsrStack.keyOf(fromLocation) &&
|
|
@@ -14,6 +14,7 @@ import { clamp } from "akanjs/common";
|
|
|
14
14
|
import { type RefObject, useCallback, useEffect, useLayoutEffect, useMemo, useRef } from "react";
|
|
15
15
|
import { CsrSlide, type CsrSlideFrame } from "./csrSlide";
|
|
16
16
|
import { isDragLift } from "./isDragLift";
|
|
17
|
+
import { scrollerTakesDrag } from "./scrollerTakesDrag";
|
|
17
18
|
import { STACK_TRANSITION_DURATION_MS } from "./useFrameRuntime";
|
|
18
19
|
|
|
19
20
|
const linearEasing = (t: number) => t;
|
|
@@ -469,7 +470,7 @@ const useStackTrans = (routeState: RouteState): UseCsrTransition => {
|
|
|
469
470
|
const dragOriginRef = useRef(0);
|
|
470
471
|
|
|
471
472
|
const pageBind = useDrag(
|
|
472
|
-
({ first, last, movement: [mx, my], velocity: [vx], direction: [dx], initial: [ix], cancel, event }) => {
|
|
473
|
+
({ first, last, movement: [mx, my], velocity: [vx], direction: [dx], initial: [ix], cancel, event, target }) => {
|
|
473
474
|
if (first) {
|
|
474
475
|
gestureIntent.current = "pending";
|
|
475
476
|
stackBackConfigRef.current = null;
|
|
@@ -483,13 +484,15 @@ const useStackTrans = (routeState: RouteState): UseCsrTransition => {
|
|
|
483
484
|
if (gestureIntent.current === "pending") {
|
|
484
485
|
const absX = Math.abs(mx);
|
|
485
486
|
const absY = Math.abs(my);
|
|
486
|
-
|
|
487
|
+
const isVertical = absY >= GESTURE_INTENT_THRESHOLD && absY > absX * GESTURE_AXIS_LOCK_RATIO;
|
|
488
|
+
const isHorizontal = absX >= GESTURE_INTENT_THRESHOLD && absX > absY * GESTURE_AXIS_LOCK_RATIO;
|
|
489
|
+
if (isVertical || (isHorizontal && scrollerTakesDrag(target, pageContentRef.current, "x", mx))) {
|
|
487
490
|
gestureIntent.current = "scroll";
|
|
488
491
|
void transUnit.start(transUnitRange[1], { immediate: true });
|
|
489
492
|
cancel();
|
|
490
493
|
return;
|
|
491
494
|
}
|
|
492
|
-
if (
|
|
495
|
+
if (!isHorizontal) return;
|
|
493
496
|
gestureIntent.current = "gesture";
|
|
494
497
|
dragOriginRef.current = holdSlide();
|
|
495
498
|
lockPageScroll();
|
|
@@ -499,6 +502,7 @@ const useStackTrans = (routeState: RouteState): UseCsrTransition => {
|
|
|
499
502
|
cancel();
|
|
500
503
|
return;
|
|
501
504
|
}
|
|
505
|
+
if (event.cancelable) event.preventDefault();
|
|
502
506
|
const unit = dragOriginRef.current + mx;
|
|
503
507
|
if (unit < transUnitRange[1]) void transUnit.start(transUnitRange[1], { immediate: true });
|
|
504
508
|
else if (unit > transUnitRange[0]) void transUnit.start(transUnitRange[0], { immediate: true });
|
|
@@ -521,8 +525,8 @@ const useStackTrans = (routeState: RouteState): UseCsrTransition => {
|
|
|
521
525
|
});
|
|
522
526
|
}
|
|
523
527
|
},
|
|
524
|
-
|
|
525
|
-
{ filterTaps: true, pointer: { capture: false } },
|
|
528
|
+
|
|
529
|
+
{ filterTaps: true, pointer: { touch: true, capture: false }, eventOptions: { passive: false } },
|
|
526
530
|
);
|
|
527
531
|
|
|
528
532
|
return {
|
|
@@ -573,7 +577,7 @@ const useStackTrans = (routeState: RouteState): UseCsrTransition => {
|
|
|
573
577
|
};
|
|
574
578
|
|
|
575
579
|
const useBottomUpTrans = (routeState: RouteState): UseCsrTransition => {
|
|
576
|
-
const { clientHeight, location, prevLocation, onBack } = routeState;
|
|
580
|
+
const { clientHeight, location, prevLocation, onBack, pageContentRef } = routeState;
|
|
577
581
|
const spring = useSlideSpring(clientHeight);
|
|
578
582
|
const { transUnit, transUnitRange, transProgress } = spring;
|
|
579
583
|
const initThreshold = useMemo(() => Math.floor(clientHeight / 3), [clientHeight]);
|
|
@@ -588,11 +592,12 @@ const useBottomUpTrans = (routeState: RouteState): UseCsrTransition => {
|
|
|
588
592
|
usePlayOnForward(spring, routeState, { duration: 220, easing: linearEasing });
|
|
589
593
|
|
|
590
594
|
const pageBind = useDrag(
|
|
591
|
-
({ first, last, movement: [, my], initial: [, iy], cancel, event }) => {
|
|
592
|
-
if (iy > initThreshold) {
|
|
595
|
+
({ first, last, movement: [, my], initial: [, iy], cancel, event, target }) => {
|
|
596
|
+
if (iy > initThreshold || (first && scrollerTakesDrag(target, pageContentRef.current, "y", my))) {
|
|
593
597
|
cancel();
|
|
594
598
|
return;
|
|
595
599
|
}
|
|
600
|
+
if (event.cancelable) event.preventDefault();
|
|
596
601
|
if (first) void Device.getDevice().hideKeyboard();
|
|
597
602
|
if (my < transUnitRange[1]) void transUnit.start(transUnitRange[1], { immediate: true });
|
|
598
603
|
else if (my > transUnitRange[0]) void transUnit.start(transUnitRange[0], { immediate: true });
|
|
@@ -605,7 +610,13 @@ const useBottomUpTrans = (routeState: RouteState): UseCsrTransition => {
|
|
|
605
610
|
clientRouter.back();
|
|
606
611
|
void clientRouter.navigation().catch(() => transUnit.start(transUnitRange[1]));
|
|
607
612
|
},
|
|
608
|
-
{
|
|
613
|
+
{
|
|
614
|
+
axis: "y",
|
|
615
|
+
filterTaps: true,
|
|
616
|
+
threshold: 10,
|
|
617
|
+
pointer: { touch: true, capture: false },
|
|
618
|
+
eventOptions: { passive: false },
|
|
619
|
+
},
|
|
609
620
|
);
|
|
610
621
|
|
|
611
622
|
return {
|