@oomfware/stacker 0.1.1 → 0.1.2
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/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as HistoryLocation, i as HistoryListener, n as HistoryAction, o as HistoryNavigateOptions, r as HistoryEntry, s as
|
|
1
|
+
import { a as HistoryLocation, c as HistoryUpdate, i as HistoryListener, n as HistoryAction, o as HistoryNavigateOptions, r as HistoryEntry, s as HistoryScrollBehavior, t as History } from "./types-KOb6CZ7N.mjs";
|
|
2
2
|
import { AnchorHTMLAttributes, ComponentType, EffectCallback, ReactElement, ReactNode } from "react";
|
|
3
3
|
//#region src/codec.d.ts
|
|
4
4
|
/**
|
|
@@ -364,6 +364,8 @@ interface RouterOptions<R extends RouteRegistry<unknown>> {
|
|
|
364
364
|
readonly pins?: readonly string[];
|
|
365
365
|
/** compiled route registry. */
|
|
366
366
|
readonly routes: R;
|
|
367
|
+
/** window whose scroll position the router restores, defaulting to the global one where there is one. */
|
|
368
|
+
readonly window?: Window;
|
|
367
369
|
}
|
|
368
370
|
/**
|
|
369
371
|
* manages navigation state, history subscriptions, and active views.
|
|
@@ -555,4 +557,4 @@ interface LinkProps extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'
|
|
|
555
557
|
*/
|
|
556
558
|
declare const Link: ({ children, onClick, replace, to, ...rest }: LinkProps) => ReactElement;
|
|
557
559
|
//#endregion
|
|
558
|
-
export { type BuildParamsOf, type Codec, type DefaultedCodec, type History, type HistoryAction, type HistoryEntry, type HistoryListener, type HistoryLocation, type HistoryNavigateOptions, type HistoryUpdate, type Infer, type InstanceNode, type LayoutConfig, type LayoutNode, type LeafType, Link, type LinkProps, type MatchedNode, NavigationHistory, type NavigationHistoryOptions, type OptionalCodec, Outlet, type ParamsOf, type QueryPatchOf, type ReadonlyURLSearchParams, type ResolvedLeaf, type ResolvedNode, type RouteChildren, type RouteConfig, type RouteLeaf, type RouteMatch, type RouteMeta, type RouteName, type RouteNode, type RouteRegistry, Router, type RouterHooks, type RouterOptions, RouterView, type View, type WhenContext, boolean, createRouterHooks, defineRoutes, enumOf, integer, layout, nonEmpty, optional, resolveMeta, route, string, useFocusEffect, useIsFocused, useLocation, useParams, useRoute, useRouter, withDefault };
|
|
560
|
+
export { type BuildParamsOf, type Codec, type DefaultedCodec, type History, type HistoryAction, type HistoryEntry, type HistoryListener, type HistoryLocation, type HistoryNavigateOptions, type HistoryScrollBehavior, type HistoryUpdate, type Infer, type InstanceNode, type LayoutConfig, type LayoutNode, type LeafType, Link, type LinkProps, type MatchedNode, NavigationHistory, type NavigationHistoryOptions, type OptionalCodec, Outlet, type ParamsOf, type QueryPatchOf, type ReadonlyURLSearchParams, type ResolvedLeaf, type ResolvedNode, type RouteChildren, type RouteConfig, type RouteLeaf, type RouteMatch, type RouteMeta, type RouteName, type RouteNode, type RouteRegistry, Router, type RouterHooks, type RouterOptions, RouterView, type View, type WhenContext, boolean, createRouterHooks, defineRoutes, enumOf, integer, layout, nonEmpty, optional, resolveMeta, route, string, useFocusEffect, useIsFocused, useLocation, useParams, useRoute, useRouter, withDefault };
|
package/dist/index.mjs
CHANGED
|
@@ -409,6 +409,7 @@ var NavigationHistory = class {
|
|
|
409
409
|
this.#ignore = options.ignore;
|
|
410
410
|
this.#location = this.#read();
|
|
411
411
|
this.#nav.addEventListener("navigate", this.#onNavigate);
|
|
412
|
+
this.#win.history.scrollRestoration = "manual";
|
|
412
413
|
}
|
|
413
414
|
get location() {
|
|
414
415
|
return this.#location;
|
|
@@ -494,16 +495,18 @@ var NavigationHistory = class {
|
|
|
494
495
|
if (action !== "traverse" && this.#ignore?.(new URL(event.destination.url))) return;
|
|
495
496
|
const envelope = isEnvelope(event.info) ? event.info : void 0;
|
|
496
497
|
const info = envelope === void 0 ? event.info : envelope.info;
|
|
497
|
-
const
|
|
498
|
+
const scroll = envelope?.scroll ?? "auto";
|
|
499
|
+
const preserve = scroll === "preserve";
|
|
498
500
|
event.intercept({
|
|
499
501
|
focusReset: preserve ? "manual" : "after-transition",
|
|
500
|
-
scroll:
|
|
502
|
+
scroll: "manual",
|
|
501
503
|
handler: async () => {
|
|
502
504
|
this.#location = this.#read();
|
|
503
505
|
const update = {
|
|
504
506
|
action,
|
|
505
507
|
info,
|
|
506
|
-
location: this.#location
|
|
508
|
+
location: this.#location,
|
|
509
|
+
scroll
|
|
507
510
|
};
|
|
508
511
|
await Promise.all([...this.#listeners].map(async (listener) => listener(update)));
|
|
509
512
|
}
|
|
@@ -659,6 +662,10 @@ const computeView = (cached, pinned, activeKey) => {
|
|
|
659
662
|
//#endregion
|
|
660
663
|
//#region src/router.ts
|
|
661
664
|
const DefaultNotFound = () => null;
|
|
665
|
+
const TOP = {
|
|
666
|
+
x: 0,
|
|
667
|
+
y: 0
|
|
668
|
+
};
|
|
662
669
|
/**
|
|
663
670
|
* manages navigation state, history subscriptions, and active views.
|
|
664
671
|
*
|
|
@@ -674,6 +681,7 @@ var Router = class {
|
|
|
674
681
|
#defaultFallback;
|
|
675
682
|
#notFound;
|
|
676
683
|
#pins;
|
|
684
|
+
#win;
|
|
677
685
|
#updates = new SimpleEventEmitter();
|
|
678
686
|
#unlisten;
|
|
679
687
|
#activePins = /* @__PURE__ */ new Set();
|
|
@@ -692,18 +700,34 @@ var Router = class {
|
|
|
692
700
|
this.#defaultFallback = options.defaultFallback;
|
|
693
701
|
this.#notFound = makeNotFound(options.notFound ?? DefaultNotFound);
|
|
694
702
|
this.#pins = new Map((options.pins ?? []).map((name) => [name, this.#makePin(name)]));
|
|
703
|
+
this.#win = options.window ?? (typeof window === "undefined" ? null : window);
|
|
695
704
|
const location = this.#history.location;
|
|
696
705
|
this.#activeKey = location.key;
|
|
697
|
-
this.#record(location);
|
|
706
|
+
this.#record(location, TOP);
|
|
698
707
|
this.#view = this.#recompute();
|
|
699
|
-
this.#unlisten = this.#history.listen(async ({ location: next }) => {
|
|
708
|
+
this.#unlisten = this.#history.listen(async ({ action, location: next, scroll }) => {
|
|
709
|
+
const win = this.#win;
|
|
710
|
+
const restoring = scroll === "auto" && win !== null;
|
|
711
|
+
if (restoring) {
|
|
712
|
+
const outgoing = this.#entries.get(this.#activeKey);
|
|
713
|
+
if (outgoing !== void 0) outgoing.scrollPos = {
|
|
714
|
+
x: win.scrollX,
|
|
715
|
+
y: win.scrollY
|
|
716
|
+
};
|
|
717
|
+
}
|
|
700
718
|
this.#prune();
|
|
701
|
-
this.#
|
|
719
|
+
const target = (action === "traverse" ? this.#entries.get(next.key)?.scrollPos : void 0) ?? TOP;
|
|
720
|
+
this.#record(next, target);
|
|
702
721
|
this.#activeKey = next.key;
|
|
703
722
|
this.#view = this.#recompute();
|
|
704
723
|
const committed = this.#awaitCommit();
|
|
705
724
|
this.#updates.emit();
|
|
706
725
|
await committed;
|
|
726
|
+
if (restoring) win.scrollTo({
|
|
727
|
+
behavior: "instant",
|
|
728
|
+
left: target.x,
|
|
729
|
+
top: target.y
|
|
730
|
+
});
|
|
707
731
|
});
|
|
708
732
|
}
|
|
709
733
|
/** current view structure. */
|
|
@@ -882,11 +906,12 @@ var Router = class {
|
|
|
882
906
|
const live = new Set(this.#history.entries().map((entry) => entry.key));
|
|
883
907
|
for (const key of this.#entries.keys()) if (!live.has(key)) this.#entries.delete(key);
|
|
884
908
|
}
|
|
885
|
-
#record(location) {
|
|
909
|
+
#record(location, scrollPos) {
|
|
886
910
|
const entry = {
|
|
887
911
|
index: location.index,
|
|
888
912
|
key: location.key,
|
|
889
|
-
match: this.#match(location)
|
|
913
|
+
match: this.#match(location),
|
|
914
|
+
scrollPos
|
|
890
915
|
};
|
|
891
916
|
this.#entries.set(location.key, entry);
|
|
892
917
|
this.#recency = [entry.key, ...this.#recency.filter((key) => key !== entry.key)];
|
package/dist/testing.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as HistoryLocation, i as HistoryListener, o as HistoryNavigateOptions, r as HistoryEntry, t as History } from "./types-
|
|
1
|
+
import { a as HistoryLocation, i as HistoryListener, o as HistoryNavigateOptions, r as HistoryEntry, t as History } from "./types-KOb6CZ7N.mjs";
|
|
2
2
|
//#region src/history/memory.d.ts
|
|
3
3
|
/** options for the memory history constructor. */
|
|
4
4
|
interface MemoryHistoryOptions {
|
package/dist/testing.mjs
CHANGED
|
@@ -50,7 +50,8 @@ var MemoryHistory = class {
|
|
|
50
50
|
this.#emit({
|
|
51
51
|
action: "push",
|
|
52
52
|
info: options.info,
|
|
53
|
-
location
|
|
53
|
+
location,
|
|
54
|
+
scroll: options.scroll ?? "auto"
|
|
54
55
|
});
|
|
55
56
|
}
|
|
56
57
|
replace(to, options = {}) {
|
|
@@ -60,7 +61,8 @@ var MemoryHistory = class {
|
|
|
60
61
|
this.#emit({
|
|
61
62
|
action: "replace",
|
|
62
63
|
info: options.info,
|
|
63
|
-
location
|
|
64
|
+
location,
|
|
65
|
+
scroll: options.scroll ?? "auto"
|
|
64
66
|
});
|
|
65
67
|
}
|
|
66
68
|
traverseTo(key) {
|
|
@@ -75,7 +77,8 @@ var MemoryHistory = class {
|
|
|
75
77
|
this.#emit({
|
|
76
78
|
action: "traverse",
|
|
77
79
|
info: void 0,
|
|
78
|
-
location: this.#current()
|
|
80
|
+
location: this.#current(),
|
|
81
|
+
scroll: "auto"
|
|
79
82
|
});
|
|
80
83
|
}
|
|
81
84
|
back() {
|
|
@@ -40,11 +40,11 @@ interface HistoryLocation {
|
|
|
40
40
|
readonly state: unknown;
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
|
-
* how a history write treats the user's place on the page — scroll position and focus, which
|
|
44
|
-
*
|
|
43
|
+
* how a history write treats the user's place on the page — scroll position and focus, which a write cannot
|
|
44
|
+
* sensibly split apart.
|
|
45
45
|
*
|
|
46
|
-
* - `auto` — a new screen.
|
|
47
|
-
* to the new content.
|
|
46
|
+
* - `auto` — a new screen. scroll is restored on a traversal if the offset is still known and reset to the top
|
|
47
|
+
* otherwise, and focus moves to the new content.
|
|
48
48
|
* - `preserve` — the same screen with different state, like an in-place parameter patch. scroll and focus are
|
|
49
49
|
* both left exactly where the user put them.
|
|
50
50
|
*/
|
|
@@ -64,11 +64,13 @@ interface HistoryUpdate {
|
|
|
64
64
|
/** metadata passed to the write operation. */
|
|
65
65
|
readonly info: unknown;
|
|
66
66
|
readonly location: HistoryLocation;
|
|
67
|
+
/** viewport behavior, which listeners apply. */
|
|
68
|
+
readonly scroll: HistoryScrollBehavior;
|
|
67
69
|
}
|
|
68
70
|
/**
|
|
69
71
|
* history update callback subscriber.
|
|
70
72
|
*
|
|
71
|
-
* listeners can return a promise to defer
|
|
73
|
+
* listeners can return a promise to defer focus resets.
|
|
72
74
|
*/
|
|
73
75
|
type HistoryListener = (update: HistoryUpdate) => void | Promise<void>;
|
|
74
76
|
/** history manager interface modeled on the web navigation API. */
|
|
@@ -126,4 +128,4 @@ interface History {
|
|
|
126
128
|
traverseTo(key: string): void;
|
|
127
129
|
}
|
|
128
130
|
//#endregion
|
|
129
|
-
export { HistoryLocation as a, HistoryListener as i, HistoryAction as n, HistoryNavigateOptions as o, HistoryEntry as r,
|
|
131
|
+
export { HistoryLocation as a, HistoryUpdate as c, HistoryListener as i, HistoryAction as n, HistoryNavigateOptions as o, HistoryEntry as r, HistoryScrollBehavior as s, History as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oomfware/stacker",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "type-safe stack router for React",
|
|
5
5
|
"license": "0BSD",
|
|
6
6
|
"repository": {
|
|
@@ -42,13 +42,13 @@
|
|
|
42
42
|
"bumpp": "^11.1.0",
|
|
43
43
|
"oxfmt": "^0.59.0",
|
|
44
44
|
"oxlint": "^1.74.0",
|
|
45
|
-
"oxlint-tsgolint": "^0.
|
|
45
|
+
"oxlint-tsgolint": "^0.25.0",
|
|
46
46
|
"playwright": "^1.61.1",
|
|
47
47
|
"react": "^19.2.7",
|
|
48
48
|
"react-dom": "^19.2.7",
|
|
49
|
-
"tsdown": "^0.22.
|
|
49
|
+
"tsdown": "^0.22.9",
|
|
50
50
|
"typescript": "^7.0.2",
|
|
51
|
-
"vite": "^8.1.
|
|
51
|
+
"vite": "^8.1.5",
|
|
52
52
|
"vitest": "^4.1.10"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|