@furystack/shades 12.3.0 → 12.4.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/CHANGELOG.md +53 -0
- package/esm/components/lazy-load.d.ts +2 -0
- package/esm/components/lazy-load.d.ts.map +1 -1
- package/esm/components/lazy-load.js +8 -3
- package/esm/components/lazy-load.js.map +1 -1
- package/esm/components/lazy-load.spec.js +59 -1
- package/esm/components/lazy-load.spec.js.map +1 -1
- package/esm/components/nested-router.d.ts +20 -0
- package/esm/components/nested-router.d.ts.map +1 -1
- package/esm/components/nested-router.js +34 -12
- package/esm/components/nested-router.js.map +1 -1
- package/esm/components/nested-router.spec.js +167 -1
- package/esm/components/nested-router.spec.js.map +1 -1
- package/esm/index.d.ts +1 -0
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/esm/view-transition.d.ts +38 -0
- package/esm/view-transition.d.ts.map +1 -0
- package/esm/view-transition.js +50 -0
- package/esm/view-transition.js.map +1 -0
- package/esm/view-transition.spec.d.ts +2 -0
- package/esm/view-transition.spec.d.ts.map +1 -0
- package/esm/view-transition.spec.js +184 -0
- package/esm/view-transition.spec.js.map +1 -0
- package/package.json +1 -1
- package/src/components/lazy-load.spec.tsx +78 -1
- package/src/components/lazy-load.tsx +10 -3
- package/src/components/nested-router.spec.tsx +249 -0
- package/src/components/nested-router.tsx +57 -12
- package/src/index.ts +1 -0
- package/src/view-transition.spec.ts +218 -0
- package/src/view-transition.ts +66 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for the View Transition API integration.
|
|
3
|
+
* When provided as an object, allows specifying transition types for CSS targeting
|
|
4
|
+
* via the `:active-view-transition-type()` pseudo-class.
|
|
5
|
+
*/
|
|
6
|
+
export type ViewTransitionConfig = {
|
|
7
|
+
types?: string[]
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Wraps a DOM update in `document.startViewTransition()` when the View Transition API
|
|
12
|
+
* is available and `config` is truthy. Falls back to calling `update()` directly otherwise.
|
|
13
|
+
*
|
|
14
|
+
* Returns the `updateCallbackDone` promise when a transition is started, allowing callers
|
|
15
|
+
* that need to wait for the DOM update (e.g. to run lifecycle hooks) to `await` the result.
|
|
16
|
+
* Returns `undefined` when no transition is used (the update runs synchronously).
|
|
17
|
+
*
|
|
18
|
+
* @param config - The view transition configuration (boolean or object with types)
|
|
19
|
+
* @param update - The synchronous DOM update callback
|
|
20
|
+
* @returns A promise that resolves after the update callback completes inside the transition, or `undefined`
|
|
21
|
+
*/
|
|
22
|
+
export const maybeViewTransition = (
|
|
23
|
+
config: boolean | ViewTransitionConfig | undefined,
|
|
24
|
+
update: () => void,
|
|
25
|
+
): Promise<void> | undefined => {
|
|
26
|
+
if (config && document.startViewTransition) {
|
|
27
|
+
const types = typeof config === 'object' && config.types?.length ? config.types : undefined
|
|
28
|
+
const transition = types ? document.startViewTransition({ update, types }) : document.startViewTransition(update)
|
|
29
|
+
return transition.updateCallbackDone
|
|
30
|
+
} else {
|
|
31
|
+
update()
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Keeps a "displayed" copy of `value` that is updated through a view transition
|
|
37
|
+
* whenever the value changes and `shouldTransition` returns true.
|
|
38
|
+
*
|
|
39
|
+
* When the transition is skipped (config is falsy or `shouldTransition` returns false),
|
|
40
|
+
* the displayed value is updated synchronously without an animation.
|
|
41
|
+
*
|
|
42
|
+
* @param useState - The component's `useState` hook
|
|
43
|
+
* @param key - Unique state key for caching the displayed value
|
|
44
|
+
* @param value - The latest source value (e.g. from `useObservable` or derived from props)
|
|
45
|
+
* @param config - View transition configuration forwarded to `maybeViewTransition`
|
|
46
|
+
* @param shouldTransition - Predicate that decides whether a value change warrants a transition.
|
|
47
|
+
* Defaults to `() => true` (always transition).
|
|
48
|
+
* @returns The currently displayed value
|
|
49
|
+
*/
|
|
50
|
+
export const transitionedValue = <T>(
|
|
51
|
+
useState: <S>(key: string, initialValue: S) => [S, (v: S) => void],
|
|
52
|
+
key: string,
|
|
53
|
+
value: T,
|
|
54
|
+
config: boolean | ViewTransitionConfig | undefined,
|
|
55
|
+
shouldTransition: (prev: T, next: T) => boolean = () => true,
|
|
56
|
+
): T => {
|
|
57
|
+
const [displayed, setDisplayed] = useState(key, value)
|
|
58
|
+
if (value !== displayed) {
|
|
59
|
+
if (shouldTransition(displayed, value)) {
|
|
60
|
+
void maybeViewTransition(config, () => setDisplayed(value))
|
|
61
|
+
} else {
|
|
62
|
+
setDisplayed(value)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return displayed
|
|
66
|
+
}
|