@typed/navigation 0.18.0 → 0.18.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/.nvmrc +1 -0
- package/biome.json +39 -0
- package/dist/Blocking.d.ts +23 -0
- package/dist/Blocking.js +41 -0
- package/dist/Blocking.js.map +1 -0
- package/dist/Destination.d.ts +11 -0
- package/dist/Destination.js +10 -0
- package/dist/Destination.js.map +1 -0
- package/dist/Error.d.ts +33 -0
- package/dist/Error.js +22 -0
- package/dist/Error.js.map +1 -0
- package/dist/Event.d.ts +45 -0
- package/dist/Event.js +17 -0
- package/dist/Event.js.map +1 -0
- package/dist/Forms.d.ts +79 -0
- package/dist/Forms.js +111 -0
- package/dist/Forms.js.map +1 -0
- package/dist/Handler.d.ts +6 -0
- package/dist/Handler.js +2 -0
- package/dist/Handler.js.map +1 -0
- package/dist/{dts/Layer.d.ts → Layer.d.ts} +11 -8
- package/dist/{esm/Layer.js → Layer.js} +2 -2
- package/dist/Layer.js.map +1 -0
- package/dist/NavigateOptions.d.ts +7 -0
- package/dist/NavigateOptions.js +7 -0
- package/dist/NavigateOptions.js.map +1 -0
- package/dist/Navigation.d.ts +79 -0
- package/dist/Navigation.js +49 -0
- package/dist/Navigation.js.map +1 -0
- package/dist/NavigationType.d.ts +3 -0
- package/dist/NavigationType.js +3 -0
- package/dist/NavigationType.js.map +1 -0
- package/dist/ProposedDestination.d.ts +13 -0
- package/dist/ProposedDestination.js +4 -0
- package/dist/ProposedDestination.js.map +1 -0
- package/dist/Url.d.ts +13 -0
- package/dist/Url.js +72 -0
- package/dist/Url.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/fromWindow.d.ts +4 -0
- package/dist/{esm/internal → internal}/fromWindow.js +125 -136
- package/dist/internal/fromWindow.js.map +1 -0
- package/dist/internal/memory.d.ts +6 -0
- package/dist/internal/memory.js +59 -0
- package/dist/internal/memory.js.map +1 -0
- package/dist/{dts/internal → internal}/shared.d.ts +44 -46
- package/dist/{esm/internal → internal}/shared.js +121 -168
- package/dist/internal/shared.js.map +1 -0
- package/package.json +35 -53
- package/readme.md +243 -0
- package/src/Blocking.ts +65 -65
- package/src/Destination.ts +14 -0
- package/src/Error.ts +28 -0
- package/src/Event.ts +26 -0
- package/src/Forms.ts +216 -0
- package/src/Handler.ts +16 -0
- package/src/Layer.ts +20 -9
- package/src/NavigateOptions.ts +9 -0
- package/src/Navigation.test.ts +697 -0
- package/src/Navigation.ts +135 -472
- package/src/NavigationType.ts +5 -0
- package/src/ProposedDestination.ts +8 -0
- package/src/Url.ts +106 -0
- package/src/index.ts +12 -17
- package/src/internal/fromWindow.ts +163 -234
- package/src/internal/memory.ts +62 -49
- package/src/internal/shared.ts +218 -377
- package/tsconfig.json +30 -0
- package/Blocking/package.json +0 -6
- package/LICENSE +0 -21
- package/Layer/package.json +0 -6
- package/Navigation/package.json +0 -6
- package/README.md +0 -5
- package/dist/cjs/Blocking.js +0 -58
- package/dist/cjs/Blocking.js.map +0 -1
- package/dist/cjs/Layer.js +0 -27
- package/dist/cjs/Layer.js.map +0 -1
- package/dist/cjs/Navigation.js +0 -278
- package/dist/cjs/Navigation.js.map +0 -1
- package/dist/cjs/index.js +0 -39
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/internal/fromWindow.js +0 -436
- package/dist/cjs/internal/fromWindow.js.map +0 -1
- package/dist/cjs/internal/memory.js +0 -72
- package/dist/cjs/internal/memory.js.map +0 -1
- package/dist/cjs/internal/shared.js +0 -525
- package/dist/cjs/internal/shared.js.map +0 -1
- package/dist/dts/Blocking.d.ts +0 -34
- package/dist/dts/Blocking.d.ts.map +0 -1
- package/dist/dts/Layer.d.ts.map +0 -1
- package/dist/dts/Navigation.d.ts +0 -451
- package/dist/dts/Navigation.d.ts.map +0 -1
- package/dist/dts/index.d.ts +0 -17
- package/dist/dts/index.d.ts.map +0 -1
- package/dist/dts/internal/fromWindow.d.ts +0 -12
- package/dist/dts/internal/fromWindow.d.ts.map +0 -1
- package/dist/dts/internal/memory.d.ts +0 -6
- package/dist/dts/internal/memory.d.ts.map +0 -1
- package/dist/dts/internal/shared.d.ts.map +0 -1
- package/dist/esm/Blocking.js +0 -46
- package/dist/esm/Blocking.js.map +0 -1
- package/dist/esm/Layer.js.map +0 -1
- package/dist/esm/Navigation.js +0 -238
- package/dist/esm/Navigation.js.map +0 -1
- package/dist/esm/index.js +0 -17
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/internal/fromWindow.js.map +0 -1
- package/dist/esm/internal/memory.js +0 -56
- package/dist/esm/internal/memory.js.map +0 -1
- package/dist/esm/internal/shared.js.map +0 -1
- package/dist/esm/package.json +0 -4
package/src/internal/memory.ts
CHANGED
|
@@ -1,82 +1,95 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import * as
|
|
6
|
-
import
|
|
7
|
-
import * as
|
|
8
|
-
import type
|
|
9
|
-
import
|
|
10
|
-
import { Navigation } from "../Navigation.js"
|
|
11
|
-
import type { ModelAndIntent } from "./shared.js"
|
|
1
|
+
import { GetRandomValues } from '@typed/id'
|
|
2
|
+
import * as LazyRef from '@typed/lazy-ref'
|
|
3
|
+
import { Schema } from 'effect'
|
|
4
|
+
import * as Effect from 'effect/Effect'
|
|
5
|
+
import * as Layer from 'effect/Layer'
|
|
6
|
+
import * as Option from 'effect/Option'
|
|
7
|
+
import type * as Scope from 'effect/Scope'
|
|
8
|
+
import type { Commit, InitialMemoryOptions, MemoryOptions } from '../Layer.js'
|
|
9
|
+
import { Navigation } from '../Navigation.js'
|
|
12
10
|
import {
|
|
13
11
|
getOriginFromUrl,
|
|
14
12
|
getUrl,
|
|
15
13
|
makeDestination,
|
|
16
14
|
makeHandlersState,
|
|
17
15
|
NavigationState,
|
|
18
|
-
setupFromModelAndIntent
|
|
19
|
-
|
|
16
|
+
setupFromModelAndIntent,
|
|
17
|
+
type ModelAndIntent,
|
|
18
|
+
} from './shared'
|
|
20
19
|
|
|
21
|
-
export const memory = (options: MemoryOptions): Layer.Layer<Navigation> =>
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
export const memory = (options: MemoryOptions): Layer.Layer<Navigation, never, GetRandomValues> =>
|
|
21
|
+
Layer.scoped(
|
|
22
|
+
Navigation,
|
|
23
|
+
Effect.gen(function* () {
|
|
24
24
|
const getRandomValues = yield* GetRandomValues
|
|
25
25
|
const modelAndIntent = yield* setupMemory(options)
|
|
26
26
|
const current = options.entries[options.currentIndex ?? 0]
|
|
27
27
|
const origin = options.origin ?? getOriginFromUrl(current.url)
|
|
28
|
-
const base = options.base ??
|
|
28
|
+
const base = options.base ?? '/'
|
|
29
29
|
|
|
30
30
|
return setupFromModelAndIntent(modelAndIntent, origin, base, getRandomValues)
|
|
31
|
-
})
|
|
31
|
+
}),
|
|
32
32
|
)
|
|
33
33
|
|
|
34
34
|
export function initialMemory(
|
|
35
|
-
options: InitialMemoryOptions
|
|
36
|
-
): Layer.Layer<Navigation> {
|
|
37
|
-
return
|
|
38
|
-
Effect.gen(function*() {
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
options: InitialMemoryOptions,
|
|
36
|
+
): Layer.Layer<Navigation, never, GetRandomValues> {
|
|
37
|
+
return Layer.unwrapEffect(
|
|
38
|
+
Effect.gen(function* () {
|
|
39
|
+
const origin = getOriginFromUrl(options.url)
|
|
40
|
+
const base = options.base ?? '/'
|
|
41
|
+
const destination = yield* makeDestination(getUrl(origin, options.url, base), options.state, origin)
|
|
42
|
+
|
|
43
|
+
return memory({
|
|
44
|
+
...options,
|
|
45
45
|
origin,
|
|
46
46
|
base,
|
|
47
|
+
entries: [destination],
|
|
47
48
|
currentIndex: 0,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const modelAndIntent = yield* setupMemory(memoryOptions)
|
|
51
|
-
|
|
52
|
-
return setupFromModelAndIntent(modelAndIntent, origin, base, getRandomValues)
|
|
53
|
-
}).pipe(Effect.provide(getRandomValues))
|
|
49
|
+
})
|
|
50
|
+
}),
|
|
54
51
|
)
|
|
55
52
|
}
|
|
56
53
|
|
|
54
|
+
const eq = Schema.equivalence(Schema.typeSchema(NavigationState))
|
|
55
|
+
|
|
56
|
+
const clampNavigationState =
|
|
57
|
+
(maxEntries: number) =>
|
|
58
|
+
(state: NavigationState): NavigationState => {
|
|
59
|
+
const entries = state.entries.slice(-maxEntries)
|
|
60
|
+
const index = Math.min(Math.max(0, state.index), entries.length - 1)
|
|
61
|
+
return {
|
|
62
|
+
entries,
|
|
63
|
+
index,
|
|
64
|
+
transition: state.transition,
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
57
68
|
function setupMemory(
|
|
58
|
-
options: MemoryOptions
|
|
69
|
+
options: MemoryOptions,
|
|
59
70
|
): Effect.Effect<ModelAndIntent, never, GetRandomValues | Scope.Scope> {
|
|
60
|
-
return Effect.gen(function*() {
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
return Effect.gen(function* () {
|
|
72
|
+
const maxEntries = options.maxEntries ?? 50
|
|
73
|
+
const state = LazyRef.transform(
|
|
74
|
+
yield* LazyRef.of<NavigationState>(
|
|
75
|
+
{
|
|
76
|
+
entries: options.entries,
|
|
77
|
+
index: options.currentIndex ?? options.entries.length - 1,
|
|
78
|
+
transition: Option.none(),
|
|
79
|
+
},
|
|
80
|
+
{ eq },
|
|
81
|
+
),
|
|
82
|
+
clampNavigationState(maxEntries),
|
|
83
|
+
clampNavigationState(maxEntries),
|
|
84
|
+
)
|
|
85
|
+
const { beforeHandlers, handlers } = yield* makeHandlersState
|
|
70
86
|
const commit: Commit = options.commit ?? (() => Effect.void)
|
|
71
87
|
|
|
72
88
|
return {
|
|
73
89
|
state,
|
|
74
|
-
canGoBack,
|
|
75
|
-
canGoForward,
|
|
76
90
|
beforeHandlers,
|
|
77
91
|
handlers,
|
|
78
|
-
|
|
79
|
-
commit
|
|
92
|
+
commit,
|
|
80
93
|
} as const
|
|
81
94
|
})
|
|
82
95
|
}
|