akanjs 3.3.0-rc.23 → 3.3.0-rc.25
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/client/makePageProto.tsx +22 -2
- package/client/sharedContext.ts +3 -1
- package/client/sharedContextKey.ts +2 -0
- package/package.json +1 -1
- package/types/client/makePageProto.d.ts +1 -1
- package/types/client/sharedContextKey.d.ts +2 -0
- package/types/webkit/isDragLift.d.ts +5 -0
- package/webkit/isDragLift.ts +7 -0
- package/webkit/useCsrTransitions.ts +13 -7
package/client/makePageProto.tsx
CHANGED
|
@@ -8,8 +8,11 @@ import {
|
|
|
8
8
|
RequestLocale,
|
|
9
9
|
} from "akanjs/common";
|
|
10
10
|
import { untrackedHeaders, untrackedRequest } from "akanjs/fetch";
|
|
11
|
-
import
|
|
11
|
+
import * as React from "react";
|
|
12
|
+
import { type Context, type ReactNode, use } from "react";
|
|
12
13
|
import { csrLocation } from "./csrLocation";
|
|
14
|
+
import type { PathContextType } from "./csrTypes";
|
|
15
|
+
import { sharedContextKey } from "./sharedContextKey";
|
|
13
16
|
import { Translator } from "./translator";
|
|
14
17
|
|
|
15
18
|
type TransMessage<Locale extends Record<string, unknown>> = {
|
|
@@ -52,6 +55,23 @@ const escapeRichParams = (param: { [key: string]: string | number } | undefined)
|
|
|
52
55
|
]),
|
|
53
56
|
);
|
|
54
57
|
|
|
58
|
+
const reactInternals = (
|
|
59
|
+
React as unknown as { __CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE?: { H: unknown } }
|
|
60
|
+
).__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
|
|
61
|
+
|
|
62
|
+
const entryPathname = (): string | undefined => {
|
|
63
|
+
const context = (globalThis as unknown as { [slot: symbol]: Context<PathContextType> | undefined })[
|
|
64
|
+
sharedContextKey("path")
|
|
65
|
+
];
|
|
66
|
+
if (!context || !reactInternals?.H) return undefined;
|
|
67
|
+
try {
|
|
68
|
+
const { location, followsRouter } = use(context);
|
|
69
|
+
return followsRouter ? undefined : location?.pathname;
|
|
70
|
+
} catch {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
55
75
|
const getPageInfo = (): { locale: string; path: string } => {
|
|
56
76
|
const { defaultLocale, locales } = parseAkanI18nEnv();
|
|
57
77
|
const localeSet = new Set(locales);
|
|
@@ -59,7 +79,7 @@ const getPageInfo = (): { locale: string; path: string } => {
|
|
|
59
79
|
const activePath = Translator.getActivePath();
|
|
60
80
|
if (activePath) return { locale: activeLocale ?? defaultLocale, path: activePath };
|
|
61
81
|
if (getEnv().side !== "server") {
|
|
62
|
-
const pathname = Translator.getRenderPath() ?? csrLocation.pathname;
|
|
82
|
+
const pathname = Translator.getRenderPath() ?? entryPathname() ?? csrLocation.pathname;
|
|
63
83
|
const [, firstSegment = "", ...rest] = pathname.split("/");
|
|
64
84
|
const hasLocalePrefix = localeSet.has(firstSegment);
|
|
65
85
|
|
package/client/sharedContext.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { type Context, createContext } from "react";
|
|
3
3
|
|
|
4
|
+
import { sharedContextKey } from "./sharedContextKey";
|
|
5
|
+
|
|
4
6
|
/** Every framework context is made here: a build inlines modules into each client chunk, so a plain `createContext`
|
|
5
7
|
* copy silently misses a Provider from another chunk. `use-agentic` keeps its own `useAgentic.`-prefixed twin. */
|
|
6
8
|
export const sharedContext = <T>(name: string, initial: T): Context<T> => {
|
|
7
|
-
const key =
|
|
9
|
+
const key = sharedContextKey(name);
|
|
8
10
|
const holder = globalThis as typeof globalThis & { [slot: symbol]: Context<T> | undefined };
|
|
9
11
|
const existing = holder[key];
|
|
10
12
|
if (existing) return existing;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ErrConstructor, type ErrPayload, type ErrRestoreOption } from "akanjs/common";
|
|
2
|
-
import type
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
3
|
export type { ErrPayload } from "akanjs/common";
|
|
4
4
|
/** @deprecated `Err` from `akanjs/common`, the class `makePageProto`'s `Err` is. */
|
|
5
5
|
export interface PageErrInstance extends Error {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a drag ended because the finger or the button let go. A drag the browser or the system takes over (a native
|
|
3
|
+
* scroll, an edge gesture) ends in `pointercancel` with the finger still down, so only a lift may act on its release.
|
|
4
|
+
*/
|
|
5
|
+
export declare const isDragLift: (event: Event | undefined) => boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const liftTypes = new Set(["pointerup", "touchend", "mouseup"]);
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Whether a drag ended because the finger or the button let go. A drag the browser or the system takes over (a native
|
|
5
|
+
* scroll, an edge gesture) ends in `pointercancel` with the finger still down, so only a lift may act on its release.
|
|
6
|
+
*/
|
|
7
|
+
export const isDragLift = (event: Event | undefined) => !!event && liftTypes.has(event.type);
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
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
|
+
import { isDragLift } from "./isDragLift";
|
|
16
17
|
import { STACK_TRANSITION_DURATION_MS } from "./useFrameRuntime";
|
|
17
18
|
|
|
18
19
|
const linearEasing = (t: number) => t;
|
|
@@ -468,7 +469,7 @@ const useStackTrans = (routeState: RouteState): UseCsrTransition => {
|
|
|
468
469
|
const dragOriginRef = useRef(0);
|
|
469
470
|
|
|
470
471
|
const pageBind = useDrag(
|
|
471
|
-
({ first, last, movement: [mx, my], velocity: [vx], direction: [dx], initial: [ix], cancel }) => {
|
|
472
|
+
({ first, last, movement: [mx, my], velocity: [vx], direction: [dx], initial: [ix], cancel, event }) => {
|
|
472
473
|
if (first) {
|
|
473
474
|
gestureIntent.current = "pending";
|
|
474
475
|
stackBackConfigRef.current = null;
|
|
@@ -503,7 +504,8 @@ const useStackTrans = (routeState: RouteState): UseCsrTransition => {
|
|
|
503
504
|
else if (unit > transUnitRange[0]) void transUnit.start(transUnitRange[0], { immediate: true });
|
|
504
505
|
else if (!last) void transUnit.start(unit, { immediate: true });
|
|
505
506
|
if (last) {
|
|
506
|
-
const shouldComplete =
|
|
507
|
+
const shouldComplete =
|
|
508
|
+
isDragLift(event) && (unit > threshold || (dx > 0 && vx > STACK_VELOCITY_DISMISS_THRESHOLD));
|
|
507
509
|
const target = shouldComplete ? transUnitRange[0] : transUnitRange[1];
|
|
508
510
|
const duration = getVelocityAwareDuration(target - unit, vx, shouldComplete ? 150 : 180);
|
|
509
511
|
if (shouldComplete) stackBackConfigRef.current = { duration };
|
|
@@ -519,7 +521,8 @@ const useStackTrans = (routeState: RouteState): UseCsrTransition => {
|
|
|
519
521
|
});
|
|
520
522
|
}
|
|
521
523
|
},
|
|
522
|
-
|
|
524
|
+
|
|
525
|
+
{ filterTaps: true, pointer: { capture: false } },
|
|
523
526
|
);
|
|
524
527
|
|
|
525
528
|
return {
|
|
@@ -585,7 +588,7 @@ const useBottomUpTrans = (routeState: RouteState): UseCsrTransition => {
|
|
|
585
588
|
usePlayOnForward(spring, routeState, { duration: 220, easing: linearEasing });
|
|
586
589
|
|
|
587
590
|
const pageBind = useDrag(
|
|
588
|
-
({ first, last, movement: [, my], initial: [, iy], cancel }) => {
|
|
591
|
+
({ first, last, movement: [, my], initial: [, iy], cancel, event }) => {
|
|
589
592
|
if (iy > initThreshold) {
|
|
590
593
|
cancel();
|
|
591
594
|
return;
|
|
@@ -594,12 +597,15 @@ const useBottomUpTrans = (routeState: RouteState): UseCsrTransition => {
|
|
|
594
597
|
if (my < transUnitRange[1]) void transUnit.start(transUnitRange[1], { immediate: true });
|
|
595
598
|
else if (my > transUnitRange[0]) void transUnit.start(transUnitRange[0], { immediate: true });
|
|
596
599
|
else if (!last) void transUnit.start(my, { immediate: true });
|
|
597
|
-
|
|
598
|
-
if (!
|
|
600
|
+
if (!last) return;
|
|
601
|
+
if (!isDragLift(event) || my <= threshold) {
|
|
602
|
+
void transUnit.start(transUnitRange[1]);
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
599
605
|
clientRouter.back();
|
|
600
606
|
void clientRouter.navigation().catch(() => transUnit.start(transUnitRange[1]));
|
|
601
607
|
},
|
|
602
|
-
{ axis: "y", filterTaps: true, threshold: 10 },
|
|
608
|
+
{ axis: "y", filterTaps: true, threshold: 10, pointer: { capture: false } },
|
|
603
609
|
);
|
|
604
610
|
|
|
605
611
|
return {
|