chayns-api 3.0.1 → 3.1.0-beta.1
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/cjs/calls/index.js +4 -1
- package/dist/cjs/calls/visibilityChangeListener.js +4 -4
- package/dist/cjs/components/ChaynsProvider.js +34 -6
- package/dist/cjs/components/withHydrationBoundary.js +2 -2
- package/dist/cjs/constants/index.js +0 -22
- package/dist/cjs/contexts/HistoryLayerContext.js +89 -0
- package/dist/cjs/contexts/index.js +38 -0
- package/dist/cjs/handler/history/FrameHistoryLayer.js +100 -0
- package/dist/cjs/handler/history/HistoryLayer.js +321 -0
- package/dist/cjs/handler/history/index.js +19 -0
- package/dist/cjs/hooks/history.js +454 -0
- package/dist/cjs/hooks/index.js +62 -1
- package/dist/cjs/host/ChaynsHost.js +113 -54
- package/dist/cjs/host/iframe/HostIframe.js +70 -5
- package/dist/cjs/host/module/ModuleHost.js +50 -44
- package/dist/cjs/index.js +139 -6
- package/dist/cjs/types/history.js +1 -0
- package/dist/cjs/umd.index.js +2 -2
- package/dist/cjs/utils/EventBus.js +33 -0
- package/dist/cjs/{util → utils}/appStorage.js +2 -2
- package/dist/cjs/utils/equality.js +19 -0
- package/dist/cjs/utils/history/BlockRegistry.js +153 -0
- package/dist/cjs/utils/history/NavigationQueue.js +389 -0
- package/dist/cjs/utils/history/layerTree.js +32 -0
- package/dist/cjs/utils/history/nativeBackHandling.js +61 -0
- package/dist/cjs/utils/history/navigationIndex.js +74 -0
- package/dist/cjs/utils/history/rootLayer.js +213 -0
- package/dist/cjs/utils/history/segments.js +15 -0
- package/dist/cjs/utils/history/stateProjector.js +156 -0
- package/dist/cjs/utils/history/url.js +47 -0
- package/dist/cjs/utils/history/window.js +9 -0
- package/dist/cjs/wrapper/AppWrapper.js +24 -24
- package/dist/cjs/wrapper/FrameWrapper.js +35 -2
- package/dist/cjs/wrapper/ModuleFederationWrapper.js +2 -0
- package/dist/cjs/wrapper/StaticChaynsApi.js +1 -1
- package/dist/esm/calls/index.js +2 -0
- package/dist/esm/calls/visibilityChangeListener.js +1 -1
- package/dist/esm/components/ChaynsProvider.js +34 -6
- package/dist/esm/components/withHydrationBoundary.js +1 -1
- package/dist/esm/constants/index.js +1 -3
- package/dist/esm/contexts/HistoryLayerContext.js +76 -0
- package/dist/esm/contexts/index.js +3 -0
- package/dist/esm/handler/history/FrameHistoryLayer.js +105 -0
- package/dist/esm/handler/history/HistoryLayer.js +321 -0
- package/dist/esm/handler/history/index.js +2 -0
- package/dist/esm/hooks/history.js +428 -0
- package/dist/esm/hooks/index.js +2 -1
- package/dist/esm/host/ChaynsHost.js +113 -54
- package/dist/esm/host/iframe/HostIframe.js +70 -5
- package/dist/esm/host/module/ModuleHost.js +50 -44
- package/dist/esm/index.js +15 -6
- package/dist/esm/types/history.js +1 -0
- package/dist/esm/umd.index.js +2 -2
- package/dist/esm/utils/EventBus.js +31 -0
- package/dist/esm/{util → utils}/appStorage.js +1 -1
- package/dist/esm/utils/equality.js +12 -0
- package/dist/esm/utils/history/BlockRegistry.js +151 -0
- package/dist/esm/utils/history/NavigationQueue.js +386 -0
- package/dist/esm/utils/history/layerTree.js +24 -0
- package/dist/esm/utils/history/nativeBackHandling.js +59 -0
- package/dist/esm/utils/history/navigationIndex.js +62 -0
- package/dist/esm/utils/history/rootLayer.js +205 -0
- package/dist/esm/utils/history/segments.js +7 -0
- package/dist/esm/utils/history/stateProjector.js +147 -0
- package/dist/esm/utils/history/url.js +40 -0
- package/dist/esm/utils/history/window.js +3 -0
- package/dist/esm/wrapper/AppWrapper.js +6 -6
- package/dist/esm/wrapper/FrameWrapper.js +35 -2
- package/dist/esm/wrapper/ModuleFederationWrapper.js +2 -0
- package/dist/esm/wrapper/StaticChaynsApi.js +2 -1
- package/dist/types/calls/index.d.ts +5 -0
- package/dist/types/components/ChaynsProvider.d.ts +21 -0
- package/dist/types/constants/index.d.ts +0 -2
- package/dist/types/contexts/HistoryLayerContext.d.ts +33 -0
- package/dist/types/contexts/index.d.ts +3 -0
- package/dist/types/handler/history/FrameHistoryLayer.d.ts +99 -0
- package/dist/types/handler/history/HistoryLayer.d.ts +117 -0
- package/dist/types/handler/history/index.d.ts +2 -0
- package/dist/types/hooks/history.d.ts +89 -0
- package/dist/types/hooks/index.d.ts +1 -0
- package/dist/types/host/ChaynsHost.d.ts +12 -0
- package/dist/types/host/iframe/HostIframe.d.ts +4 -0
- package/dist/types/host/module/ModuleHost.d.ts +4 -0
- package/dist/types/index.d.ts +15 -6
- package/dist/types/types/IChaynsReact.d.ts +3 -0
- package/dist/types/types/history.d.ts +74 -0
- package/dist/types/umd.index.d.ts +2 -2
- package/dist/types/utils/EventBus.d.ts +10 -0
- package/dist/types/{util → utils}/collectCssChunks.d.ts +1 -1
- package/dist/types/utils/equality.d.ts +2 -0
- package/dist/types/utils/history/BlockRegistry.d.ts +45 -0
- package/dist/types/utils/history/NavigationQueue.d.ts +118 -0
- package/dist/types/utils/history/layerTree.d.ts +10 -0
- package/dist/types/utils/history/nativeBackHandling.d.ts +47 -0
- package/dist/types/utils/history/navigationIndex.d.ts +17 -0
- package/dist/types/utils/history/rootLayer.d.ts +42 -0
- package/dist/types/utils/history/segments.d.ts +2 -0
- package/dist/types/utils/history/stateProjector.d.ts +24 -0
- package/dist/types/utils/history/url.d.ts +17 -0
- package/dist/types/utils/history/window.d.ts +1 -0
- package/dist/types/wrapper/FrameWrapper.d.ts +1 -0
- package/dist/types/wrapper/StaticChaynsApi.d.ts +1 -0
- package/package.json +2 -1
- /package/dist/cjs/{constants → contexts}/hydrationContext.js +0 -0
- /package/dist/cjs/{constants → contexts}/moduleContext.js +0 -0
- /package/dist/cjs/{helper/apiListenerHelper.js → utils/apiListener.js} +0 -0
- /package/dist/cjs/{util → utils}/appCall.js +0 -0
- /package/dist/cjs/{util → utils}/bindChaynsApi.js +0 -0
- /package/dist/cjs/{util → utils}/collectCssChunks.js +0 -0
- /package/dist/cjs/{util → utils}/deviceHelper.js +0 -0
- /package/dist/cjs/{util → utils}/heightHelper.js +0 -0
- /package/dist/cjs/{util → utils}/initModuleFederationSharing.js +0 -0
- /package/dist/cjs/{util → utils}/is.js +0 -0
- /package/dist/cjs/{util → utils}/postIframeForm.js +0 -0
- /package/dist/cjs/{util → utils}/transferNestedFunctions.js +0 -0
- /package/dist/cjs/{util → utils}/url.js +0 -0
- /package/dist/esm/{constants → contexts}/hydrationContext.js +0 -0
- /package/dist/esm/{constants → contexts}/moduleContext.js +0 -0
- /package/dist/esm/{helper/apiListenerHelper.js → utils/apiListener.js} +0 -0
- /package/dist/esm/{util → utils}/appCall.js +0 -0
- /package/dist/esm/{util → utils}/bindChaynsApi.js +0 -0
- /package/dist/esm/{util → utils}/collectCssChunks.js +0 -0
- /package/dist/esm/{util → utils}/deviceHelper.js +0 -0
- /package/dist/esm/{util → utils}/heightHelper.js +0 -0
- /package/dist/esm/{util → utils}/initModuleFederationSharing.js +0 -0
- /package/dist/esm/{util → utils}/is.js +0 -0
- /package/dist/esm/{util → utils}/postIframeForm.js +0 -0
- /package/dist/esm/{util → utils}/transferNestedFunctions.js +0 -0
- /package/dist/esm/{util → utils}/url.js +0 -0
- /package/dist/types/{constants → contexts}/hydrationContext.d.ts +0 -0
- /package/dist/types/{constants → contexts}/moduleContext.d.ts +0 -0
- /package/dist/types/{helper/apiListenerHelper.d.ts → utils/apiListener.d.ts} +0 -0
- /package/dist/types/{util → utils}/appCall.d.ts +0 -0
- /package/dist/types/{util → utils}/appStorage.d.ts +0 -0
- /package/dist/types/{util → utils}/bindChaynsApi.d.ts +0 -0
- /package/dist/types/{util → utils}/deviceHelper.d.ts +0 -0
- /package/dist/types/{util → utils}/heightHelper.d.ts +0 -0
- /package/dist/types/{util → utils}/initModuleFederationSharing.d.ts +0 -0
- /package/dist/types/{util → utils}/is.d.ts +0 -0
- /package/dist/types/{util → utils}/postIframeForm.d.ts +0 -0
- /package/dist/types/{util → utils}/transferNestedFunctions.d.ts +0 -0
- /package/dist/types/{util → utils}/url.d.ts +0 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { ChaynsHistoryLayer } from '../../handler/history/HistoryLayer';
|
|
2
|
+
import type { ChaynsHistoryActionResult, ChaynsHistoryNavigateOptions, ChaynsHistoryNavigationCommitOptions } from '../../types/history';
|
|
3
|
+
export type NavOp = {
|
|
4
|
+
kind: 'setRoute';
|
|
5
|
+
layerId: string;
|
|
6
|
+
segments: string[];
|
|
7
|
+
opts: ChaynsHistoryNavigateOptions;
|
|
8
|
+
/** @internal Force a change notification even when segments appear unchanged (bootstrap via setSegmentCount). */
|
|
9
|
+
_notifyEvenIfUnchanged?: true;
|
|
10
|
+
/** @internal Notify subscribers without mutating the browser history (used for segment ownership/bootstrap updates). */
|
|
11
|
+
_skipCommit?: true;
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'setState';
|
|
14
|
+
layerId: string;
|
|
15
|
+
state: Record<string, unknown>;
|
|
16
|
+
opts: ChaynsHistoryNavigateOptions;
|
|
17
|
+
} | {
|
|
18
|
+
kind: 'setParams';
|
|
19
|
+
layerId: string;
|
|
20
|
+
params: Record<string, string>;
|
|
21
|
+
opts: ChaynsHistoryNavigationCommitOptions;
|
|
22
|
+
} | {
|
|
23
|
+
kind: 'setHash';
|
|
24
|
+
layerId: string;
|
|
25
|
+
hash: string;
|
|
26
|
+
opts: ChaynsHistoryNavigationCommitOptions;
|
|
27
|
+
} | {
|
|
28
|
+
kind: 'setActiveChild';
|
|
29
|
+
layerId: string;
|
|
30
|
+
childId: string | null;
|
|
31
|
+
init?: {
|
|
32
|
+
route?: string[];
|
|
33
|
+
state?: Record<string, unknown>;
|
|
34
|
+
};
|
|
35
|
+
} | {
|
|
36
|
+
kind: 'navigate';
|
|
37
|
+
layerId: string;
|
|
38
|
+
route?: string[];
|
|
39
|
+
state?: Record<string, unknown>;
|
|
40
|
+
params?: Record<string, string>;
|
|
41
|
+
hash?: string;
|
|
42
|
+
activeChild?: string | null;
|
|
43
|
+
activeChildInit?: {
|
|
44
|
+
route?: string[];
|
|
45
|
+
state?: Record<string, unknown>;
|
|
46
|
+
};
|
|
47
|
+
opts: ChaynsHistoryNavigationCommitOptions;
|
|
48
|
+
} | {
|
|
49
|
+
kind: 'popstate';
|
|
50
|
+
rawState: unknown;
|
|
51
|
+
/**
|
|
52
|
+
* @internal Skips the block check pipeline for this popstate. Used when
|
|
53
|
+
* the popstate was triggered by us right after a native-back callback
|
|
54
|
+
* that already ran `checkActiveBlocks` — re-running it would prompt the
|
|
55
|
+
* user twice.
|
|
56
|
+
*/
|
|
57
|
+
skipBlockCheck?: boolean;
|
|
58
|
+
};
|
|
59
|
+
export type NavResult = ChaynsHistoryActionResult;
|
|
60
|
+
export interface NavigationQueueDeps {
|
|
61
|
+
/** Returns root layer (top window only). */
|
|
62
|
+
getRoot: () => ChaynsHistoryLayer;
|
|
63
|
+
/** Find a layer by id starting at root. */
|
|
64
|
+
findLayer: (id: string) => ChaynsHistoryLayer | undefined;
|
|
65
|
+
/** Run the block check pipeline for a target layer. Returns true if free to proceed. */
|
|
66
|
+
checkBlocks: (target: ChaynsHistoryLayer) => Promise<boolean>;
|
|
67
|
+
/** Project the current memory tree into the URL string. */
|
|
68
|
+
projectUrl: () => string;
|
|
69
|
+
/** Project the current memory tree into the history state object (merged with existing foreign keys). */
|
|
70
|
+
projectState: () => Record<string, unknown>;
|
|
71
|
+
/**
|
|
72
|
+
* Compute which layer ids WOULD change without mutating the tree.
|
|
73
|
+
* Used to identify the block target before applying incoming state.
|
|
74
|
+
*/
|
|
75
|
+
diffIncomingState: (raw: unknown) => {
|
|
76
|
+
changedLayerIds: Set<string>;
|
|
77
|
+
};
|
|
78
|
+
/** Apply an incoming raw `__chaynsHistory` state onto the memory tree. Returns affected layer ids. */
|
|
79
|
+
applyIncomingState: (raw: unknown) => {
|
|
80
|
+
changedLayerIds: Set<string>;
|
|
81
|
+
};
|
|
82
|
+
/** Move history without triggering our normal popstate handling (used to undo blocked navigations). */
|
|
83
|
+
silentGo: (delta: number) => Promise<void>;
|
|
84
|
+
/** Returns the current navigation index (incremented on every push). */
|
|
85
|
+
getCurrentIdx: () => number;
|
|
86
|
+
/** Increments the navigation index and returns the new value. */
|
|
87
|
+
incrementIdx: () => number;
|
|
88
|
+
/** Called after a browser history commit finished. */
|
|
89
|
+
onCommit?: () => void;
|
|
90
|
+
/**
|
|
91
|
+
* Re-parse segments from `window.location.pathname` and apply them to each
|
|
92
|
+
* layer in the active chain based on its `segmentCount`. Called after
|
|
93
|
+
* `applyIncomingState` so the active chain reflects the new `activeChild`.
|
|
94
|
+
* Returns the ids of layers whose segments actually changed.
|
|
95
|
+
*/
|
|
96
|
+
applyUrlSegments: () => {
|
|
97
|
+
changedLayerIds: Set<string>;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
export declare class NavigationQueue {
|
|
101
|
+
private readonly queue;
|
|
102
|
+
private isRunning;
|
|
103
|
+
private readonly deps;
|
|
104
|
+
constructor(deps: NavigationQueueDeps);
|
|
105
|
+
enqueue(op: NavOp): Promise<NavResult>;
|
|
106
|
+
private tick;
|
|
107
|
+
private process;
|
|
108
|
+
private processSetRoute;
|
|
109
|
+
private processSetParams;
|
|
110
|
+
private processSetHash;
|
|
111
|
+
private processSetState;
|
|
112
|
+
private processSetActiveChild;
|
|
113
|
+
private processNavigate;
|
|
114
|
+
private processPopstate;
|
|
115
|
+
private resolveActiveLayer;
|
|
116
|
+
private resolveLowestCommonLayer;
|
|
117
|
+
private commit;
|
|
118
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ChaynsHistoryLayer } from '../../handler/history/HistoryLayer';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the ordered chain of layers from root to the deepest active layer
|
|
4
|
+
* (inclusive of root).
|
|
5
|
+
*/
|
|
6
|
+
export declare function getChaynsHistoryActiveChain(root: ChaynsHistoryLayer): ChaynsHistoryLayer[];
|
|
7
|
+
/** Depth-first search for a layer by id starting at `root`. */
|
|
8
|
+
export declare function findChaynsHistoryLayerById(root: ChaynsHistoryLayer, id: string): ChaynsHistoryLayer | undefined;
|
|
9
|
+
/** Returns true if the layer is reachable via active children from the root. */
|
|
10
|
+
export declare function isInChaynsHistoryActiveChain(layer: ChaynsHistoryLayer): boolean;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ChaynsHistoryLayer } from '../../handler/history/HistoryLayer';
|
|
2
|
+
import type { BlockRegistry } from './BlockRegistry';
|
|
3
|
+
export interface NativeBackHandlerOptions {
|
|
4
|
+
rootLayer: ChaynsHistoryLayer;
|
|
5
|
+
blockRegistry: BlockRegistry;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Coordinates the native swipe-back gesture (Chayns app action 249) with the
|
|
9
|
+
* JS history queue.
|
|
10
|
+
*
|
|
11
|
+
* Why we disable the gesture as soon as the user has navigated inside the app
|
|
12
|
+
* (`getCurrentIdx() > 0`) and not only while a block is registered:
|
|
13
|
+
* The native swipe animation runs independently of our JS handling. Without
|
|
14
|
+
* intercepting it, a swipe-back would (a) play the native pop animation,
|
|
15
|
+
* (b) pop the browser entry, (c) fire popstate, and only THEN would the
|
|
16
|
+
* queue evaluate the block and silently push forward again — producing the
|
|
17
|
+
* "navigate back, then snap forward" jitter described in the bug report.
|
|
18
|
+
* By intercepting from the first own history entry on, every back must come
|
|
19
|
+
* through the registered callback where we can resolve blocks before
|
|
20
|
+
* mutating history.
|
|
21
|
+
*
|
|
22
|
+
* Instances are scoped to a single root layer; module-level state is avoided
|
|
23
|
+
* so re-inits (HMR, tests, multiple roots) cannot desynchronise.
|
|
24
|
+
*/
|
|
25
|
+
export declare class NativeBackHandler {
|
|
26
|
+
private readonly opts;
|
|
27
|
+
private isInterceptionEnabled;
|
|
28
|
+
/**
|
|
29
|
+
* Set to `true` right before `history.back()` is triggered from
|
|
30
|
+
* {@link handleNativeBack}. Consumed by the popstate listener so the
|
|
31
|
+
* queue can skip the duplicate block check (we already ran it).
|
|
32
|
+
*/
|
|
33
|
+
private bypassNextPopstateBlockCheck;
|
|
34
|
+
constructor(opts: NativeBackHandlerOptions);
|
|
35
|
+
/** Re-evaluates the desired native gesture state and pushes it to the app. */
|
|
36
|
+
sync: () => void;
|
|
37
|
+
/**
|
|
38
|
+
* Returns `true` exactly once after a {@link handleNativeBack}-initiated
|
|
39
|
+
* `history.back()`. The popstate listener uses this so the queue can skip
|
|
40
|
+
* the (already performed) block check.
|
|
41
|
+
*/
|
|
42
|
+
consumeBypassFlag(): boolean;
|
|
43
|
+
private static isSupported;
|
|
44
|
+
private shouldEnableInterception;
|
|
45
|
+
private handleNativeBack;
|
|
46
|
+
private runNativeBack;
|
|
47
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Increment the current index (call on every real pushState). Returns the new value. */
|
|
2
|
+
export declare function incrementIdx(): number;
|
|
3
|
+
/** Get current index for stamping real entries or direction comparison. */
|
|
4
|
+
export declare function getCurrentIdx(): number;
|
|
5
|
+
export declare function setCurrentIdx(idx: number): void;
|
|
6
|
+
export declare function extractHistoryIndex(raw: unknown): number | null;
|
|
7
|
+
export declare function syncCurrentIdxFromState(raw: unknown): number | null;
|
|
8
|
+
/**
|
|
9
|
+
* Performs a `history.go(delta)` that is silently ignored by our popstate handler.
|
|
10
|
+
* Returns a promise that resolves when the popstate for this go() fires.
|
|
11
|
+
*/
|
|
12
|
+
export declare function silentGo(delta: number): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Called by the popstate handler. Returns true if this popstate is the silent one
|
|
15
|
+
* and should be suppressed.
|
|
16
|
+
*/
|
|
17
|
+
export declare function consumeSilent(): boolean;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ChaynsHistoryLayer } from '../../handler/history/HistoryLayer';
|
|
2
|
+
/** Parses the URL into a flat segment array and returns all entries after the first `startIndex` entries. */
|
|
3
|
+
export declare function resolveSegmentsFrom(overrideUrl: string | undefined, startIndex: number): string[];
|
|
4
|
+
export interface InitRootChaynsHistoryLayerOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The current page URL used to seed initial route segments.
|
|
7
|
+
* - **Browser**: defaults to `window.location.pathname` — no need to set this.
|
|
8
|
+
* - **SSR**: pass the request URL (e.g. `req.url` or `router.asPath`) so
|
|
9
|
+
* child layers receive the correct initial segments on the server.
|
|
10
|
+
*/
|
|
11
|
+
url?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Number of URL path segments the root layer owns.
|
|
14
|
+
* When provided, segments are resolved from the URL immediately at construction
|
|
15
|
+
* so that `getRoute()` is populated on the very first render.
|
|
16
|
+
*/
|
|
17
|
+
segmentCount?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface InitRootChaynsHistoryLayerResult {
|
|
20
|
+
rootLayer: ChaynsHistoryLayer;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Initializes the root ChaynsHistoryLayer for the top window.
|
|
24
|
+
* - Reads `window.location.pathname` and `window.history.state`.
|
|
25
|
+
* - If `__chaynsHistory` is absent, replaces the current state with an empty tree.
|
|
26
|
+
* - Attaches the global `popstate` listener.
|
|
27
|
+
* - Returns the root ChaynsHistoryLayer instance.
|
|
28
|
+
*
|
|
29
|
+
* Call once at application startup (top window only).
|
|
30
|
+
*/
|
|
31
|
+
export declare function initRootChaynsHistoryLayer(opts?: InitRootChaynsHistoryLayerOptions): InitRootChaynsHistoryLayerResult;
|
|
32
|
+
/**
|
|
33
|
+
* Returns the singleton root ChaynsHistoryLayer for the current window.
|
|
34
|
+
* Creates it on first call; subsequent calls return the same instance.
|
|
35
|
+
*
|
|
36
|
+
* @param url - On SSR, pass the current request URL (e.g. `req.url` or `router.asPath`)
|
|
37
|
+
* so child layers receive the correct initial route segments. Ignored after first call.
|
|
38
|
+
* @param segmentCount - Number of URL segments the root layer owns. When provided the
|
|
39
|
+
* segments are resolved from the URL immediately so `getRoute()` is populated on the
|
|
40
|
+
* very first render without any subsequent `setSegmentCount` call. Ignored after first call.
|
|
41
|
+
*/
|
|
42
|
+
export declare function getOrInitRootChaynsHistoryLayer(url?: string, segmentCount?: number): InitRootChaynsHistoryLayerResult;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ChaynsHistoryLayer } from '../../handler/history/HistoryLayer';
|
|
2
|
+
import type { ChaynsHistoryLayerStateNode } from '../../types/history';
|
|
3
|
+
/**
|
|
4
|
+
* Returns the value to store in `window.history.state`, merging with any
|
|
5
|
+
* pre-existing foreign keys so we never overwrite other consumers' state.
|
|
6
|
+
*/
|
|
7
|
+
export declare function projectToState(root: ChaynsHistoryLayer, existing?: Record<string, unknown>): Record<string, unknown>;
|
|
8
|
+
/**
|
|
9
|
+
* Applies the raw `window.history.state` payload onto the layer tree.
|
|
10
|
+
* Returns the set of layer ids whose segments OR ownState changed.
|
|
11
|
+
*/
|
|
12
|
+
export declare function applyStateToTree(root: ChaynsHistoryLayer, raw: unknown): {
|
|
13
|
+
changedLayerIds: Set<string>;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Like `applyStateToTree` but does NOT mutate the tree.
|
|
17
|
+
* Returns layer ids that WOULD change if the state were applied.
|
|
18
|
+
*/
|
|
19
|
+
export declare function diffIncomingState(root: ChaynsHistoryLayer, raw: unknown): {
|
|
20
|
+
changedLayerIds: Set<string>;
|
|
21
|
+
};
|
|
22
|
+
declare function extractNode(raw: unknown): ChaynsHistoryLayerStateNode | null;
|
|
23
|
+
export { extractNode as _extractNode };
|
|
24
|
+
export declare function hasChaynsHistoryState(raw: unknown): boolean;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ChaynsHistoryLayer } from '../../handler/history/HistoryLayer';
|
|
2
|
+
/**
|
|
3
|
+
* Concatenates all segments along the active chain into a URL with pathname,
|
|
4
|
+
* merged query params, and the deepest explicitly-set hash.
|
|
5
|
+
*/
|
|
6
|
+
export declare function projectToUrl(root: ChaynsHistoryLayer): string;
|
|
7
|
+
export interface ParseResult {
|
|
8
|
+
/** Maps layer id → segments assigned to that layer. */
|
|
9
|
+
perLayerSegments: Map<string, string[]>;
|
|
10
|
+
/** Segments that could not be assigned to any layer's segmentCount. */
|
|
11
|
+
pendingSegments: string[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Splits the incoming URL pathname onto layers based on each layer's `segmentCount`.
|
|
15
|
+
* Traverses the active chain; excess segments go to `pendingSegments`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseFromUrl(url: string, root: ChaynsHistoryLayer): ParseResult;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function hasWindowHistory(): boolean;
|
|
@@ -64,6 +64,7 @@ declare class StaticChaynsApi implements ChaynsReactFunctions {
|
|
|
64
64
|
addAccessTokenChangeListener: ChaynsReactFunctions['addAccessTokenChangeListener'];
|
|
65
65
|
removeAccessTokenChangeListener: ChaynsReactFunctions['removeAccessTokenChangeListener'];
|
|
66
66
|
redirect: ChaynsReactFunctions['redirect'];
|
|
67
|
+
getHistoryLayer: ChaynsReactFunctions['getHistoryLayer'];
|
|
67
68
|
ready: Promise<void>;
|
|
68
69
|
addDataListener: (cb: DataChangeCallback) => () => void;
|
|
69
70
|
private _wrapper;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chayns-api",
|
|
3
|
-
"version": "3.0.1",
|
|
3
|
+
"version": "3.1.0-beta.1",
|
|
4
4
|
"description": "new chayns api",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -74,6 +74,7 @@
|
|
|
74
74
|
"chayns-toolkit": "^4.0.0-beta.0",
|
|
75
75
|
"concurrently": "^9.2.1",
|
|
76
76
|
"cross-env": "^10.1.0",
|
|
77
|
+
"jsdom": "^29.1.1",
|
|
77
78
|
"prettier": "^3.7.4",
|
|
78
79
|
"prettier-plugin-packagejson": "^2.5.20",
|
|
79
80
|
"react": "^18.3.1",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|