@real-router/sources 0.15.0 → 0.16.0
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/README.md +13 -11
- package/dist/cjs/index.d.ts +33 -60
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.d.mts +33 -60
- package/dist/esm/index.d.mts.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
[](https://bundlejs.com/?q=@real-router/sources&treeshake=[*])
|
|
6
6
|
[](../../LICENSE)
|
|
7
7
|
|
|
8
|
-
> Framework-agnostic subscription layer for [Real-Router](https://github.com/greydragon888/real-router). Reactive primitives compatible with `useSyncExternalStore
|
|
8
|
+
> Framework-agnostic subscription layer for [Real-Router](https://github.com/greydragon888/real-router) adapters. Reactive primitives compatible with `useSyncExternalStore`.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
**This package is for adapter authors.** Every Real-Router framework adapter — React, Preact, Solid, Vue, Svelte and Angular — is built on it. An application reaches the router through its framework's adapter, not through this package; use it directly only when you write an adapter for another framework.
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
@@ -104,11 +104,13 @@ const source = createActiveRouteSource(router, "users", undefined, undefined, {
|
|
|
104
104
|
| `ignoreQueryParams` | `boolean` | `true` | Whether to drop query-string params before comparing. |
|
|
105
105
|
| `hash` | `string` | `undefined` | When set, source is active iff route matches **and** `state.context.url.hash` equals this value. Requires a URL-publishing plugin (browser/navigation); under hash-plugin or memory-plugin (no `context.url` namespace), a **non-empty** hash is always `false`, while `hash: ""` still matches an active route (the missing namespace reads as "no fragment", #532). |
|
|
106
106
|
|
|
107
|
-
`params` and `search` are each
|
|
107
|
+
`params` and `search` are each keyed with `canonicalJson()`, which spells a value as `@real-router/core` compares it. The bag's own keys are sorted, so `{a: 1, b: 2}` and `{b: 2, a: 1}` hit the same cache entry; a plain object inside the bag keeps its key order, and a `Date` is keyed by its time. A value it cannot spell that way — a `BigInt` or a cycle, a function, `NaN`, a class instance, among others the `canonicalJson` docblock lists — falls back to a fresh non-cached source with a working `destroy()`: call it to release the router subscription.
|
|
108
108
|
|
|
109
109
|
## Usage Examples
|
|
110
110
|
|
|
111
|
-
|
|
111
|
+
How an adapter binds a source to its framework. An application does not write these: it uses its adapter's hooks, which are built exactly this way.
|
|
112
|
+
|
|
113
|
+
### A hook-based framework (`useSyncExternalStore`)
|
|
112
114
|
|
|
113
115
|
```tsx
|
|
114
116
|
import { useSyncExternalStore } from "react";
|
|
@@ -122,7 +124,7 @@ function CurrentRoute() {
|
|
|
122
124
|
}
|
|
123
125
|
```
|
|
124
126
|
|
|
125
|
-
###
|
|
127
|
+
### A plain subscription
|
|
126
128
|
|
|
127
129
|
```typescript
|
|
128
130
|
import { createRouteNodeSource } from "@real-router/sources";
|
|
@@ -187,7 +189,7 @@ primeErrorSource(router);
|
|
|
187
189
|
|
|
188
190
|
```typescript
|
|
189
191
|
try {
|
|
190
|
-
await router.start();
|
|
192
|
+
await router.start("/");
|
|
191
193
|
} catch (err) {
|
|
192
194
|
// boot-time navigation errors surface here, not on a not-yet-mounted boundary
|
|
193
195
|
}
|
|
@@ -202,11 +204,11 @@ This is by design (#1215): the source is a live event stream, symmetric with `cr
|
|
|
202
204
|
|
|
203
205
|
## Related Packages
|
|
204
206
|
|
|
205
|
-
| Package | Description
|
|
206
|
-
| ---------------------------------------------------------------------- |
|
|
207
|
-
| [@real-router/core](https://www.npmjs.com/package/@real-router/core) | Core router (required dependency)
|
|
208
|
-
| [@real-router/react](https://www.npmjs.com/package/@real-router/react) | React
|
|
209
|
-
| [@real-router/rx](https://www.npmjs.com/package/@real-router/rx) | Observable API (`state$`, `events$`)
|
|
207
|
+
| Package | Description |
|
|
208
|
+
| ---------------------------------------------------------------------- | ----------------------------------------------------- |
|
|
209
|
+
| [@real-router/core](https://www.npmjs.com/package/@real-router/core) | Core router (required peer dependency) |
|
|
210
|
+
| [@real-router/react](https://www.npmjs.com/package/@real-router/react) | React adapter — built on sources, like the other five |
|
|
211
|
+
| [@real-router/rx](https://www.npmjs.com/package/@real-router/rx) | Observable API (`state$`, `events$`) |
|
|
210
212
|
|
|
211
213
|
## Contributing
|
|
212
214
|
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Params, Router, RouterError, SearchParams, State } from "@real-router/core";
|
|
2
|
-
//#region src/types.d.ts
|
|
3
2
|
interface RouteSnapshot<P extends Params = Params> {
|
|
4
3
|
route: State<P> | undefined;
|
|
5
4
|
previousRoute: State | undefined;
|
|
@@ -56,8 +55,6 @@ interface DismissableErrorSnapshot {
|
|
|
56
55
|
/** Dismisses the current error. Next error (new version) becomes visible again. */
|
|
57
56
|
resetError: () => void;
|
|
58
57
|
}
|
|
59
|
-
//#endregion
|
|
60
|
-
//#region src/createRouteSource.d.ts
|
|
61
58
|
/**
|
|
62
59
|
* Creates a source for the full route state.
|
|
63
60
|
*
|
|
@@ -66,8 +63,6 @@ interface DismissableErrorSnapshot {
|
|
|
66
63
|
* This is compatible with React's useSyncExternalStore and Strict Mode.
|
|
67
64
|
*/
|
|
68
65
|
export declare function createRouteSource(router: Router): RouterSource<RouteSnapshot>;
|
|
69
|
-
//#endregion
|
|
70
|
-
//#region src/createRouteNodeSource.d.ts
|
|
71
66
|
/**
|
|
72
67
|
* Creates a source scoped to a specific route node.
|
|
73
68
|
*
|
|
@@ -86,8 +81,6 @@ export declare function createRouteSource(router: Router): RouterSource<RouteSna
|
|
|
86
81
|
* can use `buildRouteNodeSource` internally (not exported).
|
|
87
82
|
*/
|
|
88
83
|
export declare function createRouteNodeSource(router: Router, nodeName: string): RouterSource<RouteNodeSnapshot>;
|
|
89
|
-
//#endregion
|
|
90
|
-
//#region src/createActiveRouteSource.d.ts
|
|
91
84
|
/**
|
|
92
85
|
* Creates a source tracking whether a route (with given params/options) is active.
|
|
93
86
|
*
|
|
@@ -104,8 +97,6 @@ export declare function createRouteNodeSource(router: Router, nodeName: string):
|
|
|
104
97
|
* `router.subscribe` handle.
|
|
105
98
|
*/
|
|
106
99
|
export declare function createActiveRouteSource(router: Router, routeName: string, params?: Params, search?: SearchParams, options?: ActiveRouteSourceOptions): RouterSource<boolean>;
|
|
107
|
-
//#endregion
|
|
108
|
-
//#region src/createActiveSource.d.ts
|
|
109
100
|
/**
|
|
110
101
|
* Framework-agnostic fast/slow builder for an adapter `<Link>`'s active-route
|
|
111
102
|
* `RouterSource<boolean>`. An adapter routing its active-state check through
|
|
@@ -144,8 +135,6 @@ export declare function createActiveRouteSource(router: Router, routeName: strin
|
|
|
144
135
|
* the slow path preserves that.
|
|
145
136
|
*/
|
|
146
137
|
export declare function createActiveSource(router: Router, routeName: string, params: Params | undefined, search: SearchParams | undefined, strict: boolean, ignoreQueryParams: boolean, hash: string | undefined): RouterSource<boolean>;
|
|
147
|
-
//#endregion
|
|
148
|
-
//#region src/createTransitionSource.d.ts
|
|
149
138
|
export declare function createTransitionSource(router: Router): RouterSource<RouterTransitionSnapshot>;
|
|
150
139
|
/**
|
|
151
140
|
* Returns a per-router cached transition source shared across all consumers.
|
|
@@ -162,8 +151,6 @@ export declare function createTransitionSource(router: Router): RouterSource<Rou
|
|
|
162
151
|
* a working `destroy()`.
|
|
163
152
|
*/
|
|
164
153
|
export declare function getTransitionSource(router: Router): RouterSource<RouterTransitionSnapshot>;
|
|
165
|
-
//#endregion
|
|
166
|
-
//#region src/createErrorSource.d.ts
|
|
167
154
|
export declare function createErrorSource(router: Router): RouterSource<RouterErrorSnapshot>;
|
|
168
155
|
/**
|
|
169
156
|
* Returns a per-router cached error source shared across all consumers.
|
|
@@ -195,8 +182,6 @@ export declare function getErrorSource(router: Router): RouterSource<RouterError
|
|
|
195
182
|
* genuine invalid-router error there.
|
|
196
183
|
*/
|
|
197
184
|
export declare function primeErrorSource(router: Router): void;
|
|
198
|
-
//#endregion
|
|
199
|
-
//#region src/createDismissableError.d.ts
|
|
200
185
|
/**
|
|
201
186
|
* Returns a per-router cached source that wraps `getErrorSource(router)` with
|
|
202
187
|
* an integrated "dismissed" version counter, exposing a single reactive
|
|
@@ -217,8 +202,6 @@ export declare function primeErrorSource(router: Router): void;
|
|
|
217
202
|
* a no-op. Shared across all `RouterErrorBoundary` consumers.
|
|
218
203
|
*/
|
|
219
204
|
export declare function createDismissableError(router: Router): RouterSource<DismissableErrorSnapshot>;
|
|
220
|
-
//#endregion
|
|
221
|
-
//#region src/createActiveNameSelector.d.ts
|
|
222
205
|
interface ActiveNameSelector {
|
|
223
206
|
/**
|
|
224
207
|
* Subscribes to active-state changes of a specific route name.
|
|
@@ -258,8 +241,6 @@ interface ActiveNameSelector {
|
|
|
258
241
|
* @see Solid reference implementation — `packages/solid/src/RouterProvider.tsx`
|
|
259
242
|
*/
|
|
260
243
|
export declare function createActiveNameSelector(router: Router): ActiveNameSelector;
|
|
261
|
-
//#endregion
|
|
262
|
-
//#region src/normalizeActiveOptions.d.ts
|
|
263
244
|
/**
|
|
264
245
|
* Normalized options shape — booleans are required (filled with defaults),
|
|
265
246
|
* `hash` stays `string | undefined` because `undefined` is the meaningful
|
|
@@ -283,40 +264,30 @@ export declare const DEFAULT_ACTIVE_OPTIONS: Readonly<NormalizedActiveOptions>;
|
|
|
283
264
|
* downstream consumers that require all fields present.
|
|
284
265
|
*/
|
|
285
266
|
export declare function normalizeActiveOptions(options?: ActiveRouteSourceOptions): NormalizedActiveOptions;
|
|
286
|
-
//#endregion
|
|
287
|
-
//#region src/canonicalJson.d.ts
|
|
288
267
|
/**
|
|
289
|
-
* Serializes a
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
* **Divergence from `shared/dom-utils/scroll-restore.canonicalJson` — by
|
|
297
|
-
* design.** That sibling implementation is the cheap navigation-hot-path
|
|
298
|
-
* variant (uses `localeCompare`, plain-object accumulator, native cycle
|
|
299
|
-
* detector) and pairs with `safeKeyOf` for crash-tolerance. This one is the
|
|
300
|
-
* strict cache-key variant: byte-order compare, prototype-less accumulator,
|
|
301
|
-
* bespoke cycle detection — eagerly throws on inputs that would cause
|
|
302
|
-
* collisions or pollution, so callers can fall back to non-cached sources.
|
|
303
|
-
* They are NOT interchangeable; cross-package equivalence is explicitly not
|
|
304
|
-
* a goal (audit-2 / audit-2026-05-17 §2).
|
|
268
|
+
* Serializes a params or search bag into a stable cache key: the bag's own keys
|
|
269
|
+
* are sorted, so `{ a: 1, b: 2 }` and `{ b: 2, a: 1 }` produce the same output.
|
|
270
|
+
*
|
|
271
|
+
* Used as a cache key for `createActiveRouteSource`, so two bags share a
|
|
272
|
+
* cached source only when `@real-router/core` compares them equal: each value
|
|
273
|
+
* is spelled as core compares it (#2905).
|
|
305
274
|
*
|
|
306
275
|
* Edge cases:
|
|
307
|
-
* -
|
|
276
|
+
* - A plain object inside the bag keeps its own key order: core compares it by
|
|
277
|
+
* `JSON.stringify`, which spells `{ a, b }` and `{ b, a }` apart.
|
|
278
|
+
* - An array is read by index, as core compares it, and keeps its order.
|
|
308
279
|
* - `undefined` values are dropped (standard JSON behaviour).
|
|
309
|
-
* - `Date` is
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
280
|
+
* - A `Date` that is a value, or an element of an array value, is spelled by
|
|
281
|
+
* its `getTime()`, apart from every string, because core never equates a
|
|
282
|
+
* `Date` with a string there. Inside a plain object it is its `toJSON` ISO
|
|
283
|
+
* string, as `JSON.stringify` spells it for core.
|
|
284
|
+
* - A function, a symbol, a number that is not finite, and `undefined` in an
|
|
285
|
+
* array value throw: JSON drops them or spells them `null`.
|
|
315
286
|
* - `BigInt` throws via `JSON.stringify` defaults.
|
|
316
|
-
* -
|
|
317
|
-
* `
|
|
318
|
-
*
|
|
319
|
-
*
|
|
287
|
+
* - Any other object that is not a plain one or an array throws: a `Map`, a
|
|
288
|
+
* `Set`, a `RegExp`, a class instance, a `Temporal` value, a `URL`. JSON would
|
|
289
|
+
* spell it by its own enumerable fields, or as `"{}"`, while core compares it
|
|
290
|
+
* by its `toString` or by identity.
|
|
320
291
|
* - Circular references throw `TypeError` (parity with native `JSON.stringify`).
|
|
321
292
|
* The replacer copies each object level into a fresh prototype-less record,
|
|
322
293
|
* so we must run our own cycle detection — the native detector never sees
|
|
@@ -324,12 +295,11 @@ export declare function normalizeActiveOptions(options?: ActiveRouteSourceOption
|
|
|
324
295
|
* - `__proto__` keys are preserved as own properties (no prototype pollution
|
|
325
296
|
* and no silent collision between `{ __proto__: x, b: 1 }` and `{ b: 1 }`).
|
|
326
297
|
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
298
|
+
* A throw sends the caller to its non-cached fallback path. Only a plain
|
|
299
|
+
* object whose single key is `"\u0000Date"` shares a `Date`'s spelling, which
|
|
300
|
+
* is unsupported.
|
|
329
301
|
*/
|
|
330
302
|
export declare function canonicalJson(value: unknown): string;
|
|
331
|
-
//#endregion
|
|
332
|
-
//#region src/createRouteEnterGate.d.ts
|
|
333
303
|
/**
|
|
334
304
|
* Context handed to a route-enter handler once a navigation-driven mount is
|
|
335
305
|
* confirmed. `previousRoute` is **non-nullable** — the gate is the sole bridge
|
|
@@ -384,8 +354,6 @@ type RouteEnterGate = (route: State | undefined, previousRoute: State | undefine
|
|
|
384
354
|
* `isDeactivated`, #1221) compose *before* this gate and stay adapter-side.
|
|
385
355
|
*/
|
|
386
356
|
export declare function createRouteEnterGate(): RouteEnterGate;
|
|
387
|
-
//#endregion
|
|
388
|
-
//#region src/guardLeaveListener.d.ts
|
|
389
357
|
type LeaveFn = Parameters<Router["subscribeLeave"]>[0];
|
|
390
358
|
/**
|
|
391
359
|
* Context handed to a route-exit handler when a genuine departure is approved.
|
|
@@ -423,13 +391,18 @@ type LeaveHandler = (context: RouteExitContext) => void | Promise<void>;
|
|
|
423
391
|
* core's `settleLeavePromises` and **blocks** the activation phase.
|
|
424
392
|
*
|
|
425
393
|
* **Error contract:** a rejected handler Promise rejects `navigate()` with the
|
|
426
|
-
* handler's **original error**
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
* `opts.signal`). A
|
|
430
|
-
*
|
|
394
|
+
* handler's **original error** (a value that is not an `Error` arrives
|
|
395
|
+
* wrapped in one) and emits `TRANSITION_ERROR` — it is NOT re-coded to
|
|
396
|
+
* `TRANSITION_CANCELLED`, which arises when the payload `signal` aborts
|
|
397
|
+
* (supersede / `stop()` / `dispose()` / external `opts.signal`). A handler
|
|
398
|
+
* that rejects with a `RouterError(TRANSITION_CANCELLED)` itself cancels the
|
|
399
|
+
* navigation quietly: `navigate()` rejects with that error and core emits
|
|
400
|
+
* `TRANSITION_CANCEL` instead (#2787). A handler that rejects with the error
|
|
401
|
+
* the router ended ANOTHER navigation with — it awaited that navigation's
|
|
402
|
+
* work — fails this one with `CANNOT_DEACTIVATE` (#2786). A fire-and-forget
|
|
403
|
+
* call here would silently un-block the transition, so arm 3 must stay a
|
|
404
|
+
* passthrough.
|
|
431
405
|
*/
|
|
432
406
|
export declare function guardLeaveListener(handler: LeaveHandler, options?: UseRouteExitOptions): LeaveFn;
|
|
433
|
-
//#endregion
|
|
434
407
|
export type { ActiveNameSelector, ActiveRouteSourceOptions, DismissableErrorSnapshot, RouteEnterContext, RouteEnterGate, RouteExitContext, RouteNodeSnapshot, RouteSnapshot, RouterErrorSnapshot, RouterSource, RouterTransitionSnapshot, UseRouteExitOptions };
|
|
435
408
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/types.ts","../../src/createRouteSource.ts","../../src/createRouteNodeSource.ts","../../src/createActiveRouteSource.ts","../../src/createActiveSource.ts","../../src/createTransitionSource.ts","../../src/createErrorSource.ts","../../src/createDismissableError.ts","../../src/createActiveNameSelector.ts","../../src/normalizeActiveOptions.ts","../../src/canonicalJson.ts","../../src/createRouteEnterGate.ts","../../src/guardLeaveListener.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/types.ts","../../src/createRouteSource.ts","../../src/createRouteNodeSource.ts","../../src/createActiveRouteSource.ts","../../src/createActiveSource.ts","../../src/createTransitionSource.ts","../../src/createErrorSource.ts","../../src/createDismissableError.ts","../../src/createActiveNameSelector.ts","../../src/normalizeActiveOptions.ts","../../src/canonicalJson.ts","../../src/createRouteEnterGate.ts","../../src/guardLeaveListener.ts"],"mappings":";UAEiB,cAAc,UAAU,SAAS;EAChD,OAAO,MAAM;EACb,eAAe;;UAGA,kBAAkB,UAAU,SAAS;EACpD,OAAO,MAAM;EACb,eAAe;;UAGA,aAAa;EAC5B,YAAY;EACZ,mBAAmB;EACnB;;UAGe;EACf;EACA;;;;;;;;;;;;;;;EAeA;;UAGe;EACf;EACA;EACA,SAAS;EACT,WAAW;;UAGI;EACf,OAAO;EACP,SAAS;EACT,WAAW;EACX;;UAGe;;EAEf,OAAO;;EAEP,SAAS;;EAET,WAAW;;EAEX;;EAEA;;;;;;;;;wBCjDc,kBAAkB,QAAQ,SAAS,aAAa;;;;;;;;;;;;;;;;;;wBCgBhD,sBACd,QAAQ,QACR,mBACC,aAAa;;;;;;;;;;;;;;;;wBCDA,wBACd,QAAQ,QACR,mBACA,SAAS,QACT,SAAS,cACT,UAAU,2BACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBCQa,mBACd,QAAQ,QACR,mBACA,QAAQ,oBACR,QAAQ,0BACR,iBACA,4BACA,2BACC;wBCkCa,uBACd,QAAQ,SACP,aAAa;;;;;;;;;;;;;;;wBA8HA,oBACd,QAAQ,SACP,aAAa;wBChMA,kBACd,QAAQ,SACP,aAAa;;;;;;;;;;;;;;;wBA2FA,eACd,QAAQ,SACP,aAAa;;;;;;;;;;;;;;;wBAkCA,iBAAiB,QAAQ;;;;;;;;;;;;;;;;;;;;wBC3HzB,uBACd,QAAQ,SACP,aAAa;UC3BC;;;;;;EAMf,YAAY,mBAAmB;;;;;EAK/B,WAAW;;EAEX;;;;;;;;;;;;;;;;;;;;;;;;;wBA4Bc,yBAAyB,QAAQ,SAAS;;;;;;UCxCzC;EACf;EACA;EACA;;;;;;;qBAQW,wBAAwB,SAAS;;;;;;;wBAa9B,uBACd,UAAU,2BACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBCsBa,cAAc;;;;;;;UC/Cb;;EAEf,OAAO;;EAEP,eAAe;;;;;;;;;;KAWL,kBACV,OAAO,mBACP,eAAe,mBACf,2BACG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAkCW,wBAAwB;KCvDnC,UAAU,WAAW;;;;;;UAOT;;EAEf,OAAO;;EAEP,WAAW;;EAEX,QAAQ;;UAGO;;;;;EAKf;;KAGG,gBAAgB,SAAS,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA6B1C,mBACd,SAAS,cACT,UAAU,sBACT"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@real-router/route-utils"),t=require("@real-router/core"),n=require("@real-router/core/api");var r=class{#e;#t=!1;#n=new Set;#r;#i;#a;constructor(e,t){this.#e=e,this.#r=t?.onFirstSubscribe,this.#i=t?.onLastUnsubscribe,this.#a=t?.onDestroy,this.subscribe=this.subscribe.bind(this),this.getSnapshot=this.getSnapshot.bind(this),this.destroy=this.destroy.bind(this)}subscribe(e){if(this.#t)return()=>{};let t=this.#n.size===0;return this.#n.add(e),t&&this.#r&&this.#r(),()=>{this.#n.delete(e),!this.#t&&this.#n.size===0&&this.#i&&this.#i()}}getSnapshot(){return this.#e}updateSnapshot(e){if(!this.#t){this.#e=e;for(let e of this.#n)try{e()}catch(e){queueMicrotask(()=>{throw e})}}}destroy(){this.#t||(this.#t=!0,this.#a?.(),this.#n.clear())}};function i(e){return(e?.context)?.url?.hash}function a(e,t){return e===t?e:e?.path!==t?.path||i(e)!==i(t)||o(t)?t:e}function o(e){return e?.transition?.reload===!0}function s(e){let t=null,n=()=>{let e=t;t=null,e?.()},i=new r({route:e.getState(),previousRoute:void 0},{onFirstSubscribe:()=>{let n=i.getSnapshot(),r=a(n.route,e.getState());r!==n.route&&i.updateSnapshot({route:r,previousRoute:void 0}),t=e.subscribe(e=>{let t=i.getSnapshot(),n=a(t.route,e.route),r=a(t.previousRoute,e.previousRoute);(n!==t.route||r!==t.previousRoute)&&i.updateSnapshot({route:n,previousRoute:r})})},onLastUnsubscribe:n,onDestroy:n});return i}function c(e,t,n,r){let i=r?.route??t.getState(),o=r?.previousRoute,s=n===``||i!==void 0&&(i.name===n||i.name.startsWith(`${n}.`))?i:void 0;if(s===e.route&&o===e.previousRoute)return e;let c=a(e.route,s),l=a(e.previousRoute,o);return c===e.route&&l===e.previousRoute?e:{route:c,previousRoute:l}}function l(){}const u=new WeakMap;function d(e,t){let n=u.get(e);n||(n=new Map,u.set(e,n));let r=n.get(t);if(!r){let i=f(e,t);r={subscribe:i.subscribe,getSnapshot:i.getSnapshot,destroy:l},n.set(t,r)}return r}function f(e,t){let n=null,i=e.shouldUpdateNode(t),a=new r(c({route:void 0,previousRoute:void 0},e,t),{onFirstSubscribe:()=>{let r=c(a.getSnapshot(),e,t);Object.is(r,a.getSnapshot())||a.updateSnapshot(r),n=e.subscribe(n=>{if(!i(n.route,n.previousRoute))return;let r=c(a.getSnapshot(),e,t,n);Object.is(a.getSnapshot(),r)||a.updateSnapshot(r)})},onLastUnsubscribe:()=>{let e=n;n=null,e?.()}});return a}const p=Object.keys,m=Object.create;function
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@real-router/route-utils"),t=require("@real-router/core"),n=require("@real-router/core/api");var r=class{#e;#t=!1;#n=new Set;#r;#i;#a;constructor(e,t){this.#e=e,this.#r=t?.onFirstSubscribe,this.#i=t?.onLastUnsubscribe,this.#a=t?.onDestroy,this.subscribe=this.subscribe.bind(this),this.getSnapshot=this.getSnapshot.bind(this),this.destroy=this.destroy.bind(this)}subscribe(e){if(this.#t)return()=>{};let t=this.#n.size===0;return this.#n.add(e),t&&this.#r&&this.#r(),()=>{this.#n.delete(e),!this.#t&&this.#n.size===0&&this.#i&&this.#i()}}getSnapshot(){return this.#e}updateSnapshot(e){if(!this.#t){this.#e=e;for(let e of this.#n)try{e()}catch(e){queueMicrotask(()=>{throw e})}}}destroy(){this.#t||(this.#t=!0,this.#a?.(),this.#n.clear())}};function i(e){return(e?.context)?.url?.hash}function a(e,t){return e===t?e:e?.path!==t?.path||i(e)!==i(t)||o(t)?t:e}function o(e){return e?.transition?.reload===!0}function s(e){let t=null,n=()=>{let e=t;t=null,e?.()},i=new r({route:e.getState(),previousRoute:void 0},{onFirstSubscribe:()=>{let n=i.getSnapshot(),r=a(n.route,e.getState());r!==n.route&&i.updateSnapshot({route:r,previousRoute:void 0}),t=e.subscribe(e=>{let t=i.getSnapshot(),n=a(t.route,e.route),r=a(t.previousRoute,e.previousRoute);(n!==t.route||r!==t.previousRoute)&&i.updateSnapshot({route:n,previousRoute:r})})},onLastUnsubscribe:n,onDestroy:n});return i}function c(e,t,n,r){let i=r?.route??t.getState(),o=r?.previousRoute,s=n===``||i!==void 0&&(i.name===n||i.name.startsWith(`${n}.`))?i:void 0;if(s===e.route&&o===e.previousRoute)return e;let c=a(e.route,s),l=a(e.previousRoute,o);return c===e.route&&l===e.previousRoute?e:{route:c,previousRoute:l}}function l(){}const u=new WeakMap;function d(e,t){let n=u.get(e);n||(n=new Map,u.set(e,n));let r=n.get(t);if(!r){let i=f(e,t);r={subscribe:i.subscribe,getSnapshot:i.getSnapshot,destroy:l},n.set(t,r)}return r}function f(e,t){let n=null,i=e.shouldUpdateNode(t),a=new r(c({route:void 0,previousRoute:void 0},e,t),{onFirstSubscribe:()=>{let r=c(a.getSnapshot(),e,t);Object.is(r,a.getSnapshot())||a.updateSnapshot(r),n=e.subscribe(n=>{if(!i(n.route,n.previousRoute))return;let r=c(a.getSnapshot(),e,t,n);Object.is(a.getSnapshot(),r)||a.updateSnapshot(r)})},onLastUnsubscribe:()=>{let e=n;n=null,e?.()}});return a}const p=Object.keys,m=Object.getPrototypeOf,h=Date.prototype.getTime,g=Object.create;function _(e){return JSON.stringify(w(e,new Set,`root`))}function v(e){if(Array.isArray(e))return!0;let t=m(e);return t===null||t===Object.prototype}function y(e,t){return e<t?-1:1}function b(e){return TypeError(`canonicalJson: cannot serialize ${e} — JSON drops it or spells it null, so two values core tells apart would share one cache key.`)}function x(e){let t=g(null);return t[`\0Date`]=h.call(e),t}function S(e){if(typeof e==`function`||typeof e==`symbol`)throw b(`a ${typeof e}`);if(typeof e==`number`&&!Number.isFinite(e))throw b(String(e));return e}function C(e){let t=e.constructor?.name;return TypeError(`canonicalJson: cannot serialize ${typeof t==`string`&&t!==``?t:`an object`} — a cache-key is built only from plain objects, arrays, Dates and JSON values: core compares any other object by its toString or by identity, not by its fields.`)}function w(e,t,n){if(typeof e!=`object`||!e)return S(e);if(e instanceof Date)return n===`field`?e:x(e);if(!v(e))throw C(e);if(t.has(e))throw TypeError(`canonicalJson: cannot serialize circular structure (cycle detected during traversal).`);t.add(e);try{return Array.isArray(e)?E(e,t,n===`field`?`field`:`value`):T(e,t,n)}finally{t.delete(e)}}function T(e,t,n){let r=g(null),i=n===`root`?p(e).toSorted(y):p(e),a=n===`root`?`value`:`field`;for(let n of i)r[n]=w(e[n],t,a);return r}function E(e,t,n){let{length:r}=e,i=[];for(let a=0;a<r;a++){let r=e[a];if(r===void 0&&n===`value`)throw b(`undefined in an array`);i[a]=w(r,t,n)}return i}const D=Object.freeze({strict:!1,ignoreQueryParams:!0,hash:void 0});function O(e){return{strict:e?.strict??D.strict,ignoreQueryParams:e?.ignoreQueryParams??D.ignoreQueryParams,hash:e?.hash}}const k=new WeakMap;function A(e,t,n,r,i){let{strict:a,ignoreQueryParams:o,hash:s}=O(i),c;if(typeof t!=`string`)return M(e,t,n,r,a,o,s);try{let e=s===void 0?``:`#${s}`;c=`${t}|${n===void 0?``:_(n)}|${r===void 0?``:_(r)}|${String(a)}|${String(o)}|${e}`}catch{c=void 0}if(c===void 0)return M(e,t,n,r,a,o,s);let u=k.get(e);u||(u=new Map,k.set(e,u));let d=u.get(c);if(!d){let i=M(e,t,n,r,a,o,s);d={subscribe:i.subscribe,getSnapshot:i.getSnapshot,destroy:l},u.set(c,d)}return d}function j(e,t,n,r,a,o,s){return e.isActiveRoute(t,n,r,a,o)?s===void 0||(i(e.getState())??``)===s:!1}function M(t,n,i,a,o,s,c){let l=j(t,n,i,a,o,s,c),u,d=()=>{let e=u;u=void 0,e?.()},f=new r(l,{onFirstSubscribe:()=>{let r=j(t,n,i,a,o,s,c);Object.is(f.getSnapshot(),r)||f.updateSnapshot(r),u=t.subscribe(r=>{let l=(0,e.areRoutesRelated)(n,r.route.name),u=r.previousRoute&&(0,e.areRoutesRelated)(n,r.previousRoute.name),d=c!==void 0&&(r.route.context?.url?.hashChanged??!1);if(!l&&!u&&!d)return;let p=l&&j(t,n,i,a,o,s,c);Object.is(f.getSnapshot(),p)||f.updateSnapshot(p)})},onLastUnsubscribe:d,onDestroy:d});return f}const N=new WeakMap;function P(t){let n=N.get(t);if(n)return n;let r=new Map,i=new Map,a=null,o=e=>{let n=t.getState();return n?e===``||n.name===e||n.name.startsWith(`${e}.`):!1},s=(t,n,r,a)=>{if(t!==``){let n=(0,e.areRoutesRelated)(t,r),i=a!==void 0&&(0,e.areRoutesRelated)(t,a);if(!n&&!i)return}let s=i.get(t)===!0,c=o(t);if(s!==c){i.set(t,c);for(let e of n)try{e()}catch(e){queueMicrotask(()=>{throw e})}}},c=()=>{a=t.subscribe(e=>{let t=e.route.name,n=e.previousRoute?.name;for(let[e,i]of r)try{s(e,i,t,n)}catch(e){queueMicrotask(()=>{throw e})}})},u=()=>{let e=a;a=null,e?.()},d={subscribe:(e,t)=>{let n=r.get(e);n||(n=new Set,r.set(e,n),i.set(e,o(e))),n.add(t),a||c();let s=!1;return()=>{s||(s=!0,r.get(e)===n&&(n.delete(t),n.size===0&&(r.delete(e),i.delete(e)),r.size===0&&u()))}},isActive:e=>{let t=i.get(e);return t===void 0?o(e):t},destroy:l};return N.set(t,d),d}const F=()=>{};function I(e,t,n,r,i,a,o){if(t!==``&&n===void 0&&r===void 0&&!i&&a&&o===void 0){let n=P(e);return{subscribe:e=>n.subscribe(t,e),getSnapshot:()=>n.isActive(t),destroy:F}}return A(e,t,n,r,o===void 0?{strict:i,ignoreQueryParams:a}:{strict:i,ignoreQueryParams:a,hash:o})}const L=Object.freeze({isTransitioning:!1,isLeaveApproved:!1,toRoute:null,fromRoute:null}),R=new WeakMap;function z(e,t,n){let r=a(e.toRoute,t),i=a(e.fromRoute,n??null);return e.isTransitioning&&r===e.toRoute&&i===e.fromRoute?null:{isTransitioning:!0,isLeaveApproved:!1,toRoute:r,fromRoute:i}}function B(e,t,n){let r=a(e.toRoute,t),i=a(e.fromRoute,n??null);return e.isLeaveApproved&&r===e.toRoute&&i===e.fromRoute?null:{isTransitioning:!0,isLeaveApproved:!0,toRoute:r,fromRoute:i}}function V(e){let i=[],a=new r(L,{onDestroy:()=>{for(let e of i)e()}}),o=(0,n.getPluginApi)(e),s,c=()=>{a.updateSnapshot(L)},l=e=>{e?.context===s?.context&&c()},u=(e,t)=>{s=e;let n=z(a.getSnapshot(),e,t);n!==null&&a.updateSnapshot(n)},d=(e,t)=>{s=e;let n=B(a.getSnapshot(),e,t);n!==null&&a.updateSnapshot(n)};try{i.push(o.addEventListener(t.events.TRANSITION_START,u)),i.push(o.addEventListener(t.events.TRANSITION_LEAVE_APPROVE,d)),i.push(o.addEventListener(t.events.TRANSITION_SUCCESS,c)),i.push(o.addEventListener(t.events.TRANSITION_ERROR,l)),i.push(o.addEventListener(t.events.TRANSITION_CANCEL,c))}catch(e){for(let e of i)e();throw e}return a}function H(e){let t=R.get(e);if(!t){let n=V(e);t={subscribe:n.subscribe,getSnapshot:n.getSnapshot,destroy:l},R.set(e,t)}return t}const U=Object.freeze({error:null,toRoute:null,fromRoute:null,version:0}),W=new WeakMap;function G(e){let i=0,a=!1,o=[],s=new r(U,{onDestroy:()=>{for(let e of o)e()}}),c=(0,n.getPluginApi)(e);try{o.push(c.addEventListener(t.events.TRANSITION_ERROR,(e,t,n)=>{i++,a=!0,s.updateSnapshot({error:n,toRoute:e??null,fromRoute:t??null,version:i})})),o.push(c.addEventListener(t.events.TRANSITION_SUCCESS,()=>{a&&(a=!1,s.updateSnapshot({error:null,toRoute:null,fromRoute:null,version:i}))}))}catch(e){for(let e of o)e();throw e}return s}function K(e){let t=W.get(e);if(!t){let n=G(e);t={subscribe:n.subscribe,getSnapshot:n.getSnapshot,destroy:l},W.set(e,t)}return t}function q(e){try{K(e)}catch{}}const J=new WeakMap;function Y(e){let t=J.get(e);if(t)return t;let n=K(e),i=-1,a=null,o=()=>{let e=n.getSnapshot(),t=e.version<=i;return{error:t?null:e.error,toRoute:t?null:e.toRoute,fromRoute:t?null:e.fromRoute,version:e.version,resetError:c}},s=new r(o(),{onFirstSubscribe:()=>{a=n.subscribe(()=>{s.updateSnapshot(o())});let e=o();e.error!==s.getSnapshot().error&&s.updateSnapshot(e)},onLastUnsubscribe:()=>{u()}});function c(){let e=n.getSnapshot().version;e<=i||(i=e,s.updateSnapshot(o()))}function u(){let e=a;a=null,e?.()}let d={subscribe:s.subscribe,getSnapshot:s.getSnapshot,destroy:l};return J.set(e,d),d}function X(){let e=null;return(t,n,r)=>!t||!t.transition?.from||r&&t.transition.from===t.name||e===t||!n?null:(e=t,{route:t,previousRoute:n})}function Z(e,t){let n=t?.skipSameRoute??!0;return({route:t,nextRoute:r,signal:i})=>{if(!(n&&t.name===r.name)&&!i.aborted)return e({route:t,nextRoute:r,signal:i})}}exports.DEFAULT_ACTIVE_OPTIONS=D,exports.canonicalJson=_,exports.createActiveNameSelector=P,exports.createActiveRouteSource=A,exports.createActiveSource=I,exports.createDismissableError=Y,exports.createErrorSource=G,exports.createRouteEnterGate=X,exports.createRouteNodeSource=d,exports.createRouteSource=s,exports.createTransitionSource=V,exports.getErrorSource=K,exports.getTransitionSource=H,exports.guardLeaveListener=Z,exports.normalizeActiveOptions=O,exports.primeErrorSource=q;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|