@tempots/ui 0.12.0 → 0.13.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/index.cjs +1 -1
- package/index.js +955 -953
- package/package.json +2 -2
- package/renderables/anchor.d.ts +10 -1
- package/renderables/appearance.d.ts +5 -1
- package/renderables/async-result-view.d.ts +44 -3
- package/renderables/autofocus.d.ts +7 -0
- package/renderables/autoselect.d.ts +6 -0
- package/renderables/hidden-when-empty.d.ts +7 -0
- package/renderables/html-title.d.ts +8 -1
- package/renderables/inviewport.d.ts +27 -1
- package/renderables/pop-over.d.ts +47 -9
- package/renderables/result-view.d.ts +31 -3
- package/renderables/router/location.d.ts +83 -13
- package/renderables/router/match.d.ts +35 -3
- package/renderables/router/route-info.d.ts +92 -7
- package/renderables/router/router.d.ts +9 -3
- package/renderables/select-on-focus.d.ts +7 -1
- package/renderables/size.d.ts +15 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tempots/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.cjs",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@floating-ui/dom": "^1.6.7"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@tempots/dom": "
|
|
43
|
+
"@tempots/dom": "19.1.0",
|
|
44
44
|
"@tempots/std": "0.10.7"
|
|
45
45
|
}
|
|
46
46
|
}
|
package/renderables/anchor.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
import { TNode, Value } from '@tempots/dom';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Creates an anchor element with the specified href and children.
|
|
5
|
+
* When the anchor element is clicked, the location is updated to the specified href.
|
|
6
|
+
*
|
|
7
|
+
* @param href - The href attribute of the anchor element.
|
|
8
|
+
* @param children - The child elements of the anchor element.
|
|
9
|
+
* @returns The anchor element.
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export declare const Anchor: (href: Value<string>, ...children: TNode[]) => import('@tempots/dom').Renderable;
|
|
@@ -2,11 +2,13 @@ import { Signal, TNode } from '@tempots/dom';
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Defines the possible appearance types for the application.
|
|
5
|
-
*
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
6
7
|
*/
|
|
7
8
|
export type AppearanceType = 'light' | 'dark';
|
|
8
9
|
/**
|
|
9
10
|
* A provider mark for a signal representing the current appearance type.
|
|
11
|
+
* @public
|
|
10
12
|
*/
|
|
11
13
|
export declare const appearanceMarker: import('@tempots/dom').ProviderMark<Signal<AppearanceType>>;
|
|
12
14
|
/**
|
|
@@ -19,6 +21,7 @@ export declare const appearanceMarker: import('@tempots/dom').ProviderMark<Signa
|
|
|
19
21
|
*
|
|
20
22
|
* @param child - The child component to be provided with the appearance context.
|
|
21
23
|
* @returns The child component with the appearance context.
|
|
24
|
+
* @public
|
|
22
25
|
*/
|
|
23
26
|
export declare const ProvideAppearance: (child: TNode) => TNode;
|
|
24
27
|
/**
|
|
@@ -27,5 +30,6 @@ export declare const ProvideAppearance: (child: TNode) => TNode;
|
|
|
27
30
|
*
|
|
28
31
|
* @param fn - A function that accepts the `AppearanceType` signal and returns a `TNode` element.
|
|
29
32
|
* @returns The `TNode` element returned by the provided function.
|
|
33
|
+
* @public
|
|
30
34
|
*/
|
|
31
35
|
export declare const UseAppearance: (fn: (appearance: Signal<AppearanceType>) => TNode) => TNode;
|
|
@@ -1,9 +1,50 @@
|
|
|
1
|
-
import { TNode, Signal, Value } from '@tempots/dom';
|
|
1
|
+
import { TNode, Signal, Value, Renderable } from '@tempots/dom';
|
|
2
2
|
import { AsyncResult } from '@tempots/std';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Represents the options for rendering an asynchronous result view.
|
|
6
|
+
*
|
|
7
|
+
* @typeParam T - The type of the success value.
|
|
8
|
+
* @typeParam E - The type of the error value.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export type AsyncResultViewOptions<T, E> = {
|
|
12
|
+
/**
|
|
13
|
+
* The function to render the view when the operation succeeds.
|
|
14
|
+
* @param value - The value of the success result.
|
|
15
|
+
* @returns The rendered view.
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
5
18
|
success: (value: Signal<T>) => TNode;
|
|
19
|
+
/**
|
|
20
|
+
* The function to render the view when the operation fails.
|
|
21
|
+
* @param error - The error of the failure result.
|
|
22
|
+
* @returns The rendered view.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
6
25
|
failure?: (error: Signal<E>) => TNode;
|
|
26
|
+
/**
|
|
27
|
+
* The function to render the view when the operation is not requested yet.
|
|
28
|
+
* @returns The rendered view.
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
7
31
|
notAsked?: () => TNode;
|
|
32
|
+
/**
|
|
33
|
+
* The function to render the view when the operation is in progress.
|
|
34
|
+
* @param previousValue - The previous value.
|
|
35
|
+
* @returns The rendered view.
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
8
38
|
loading?: (previousValue: Signal<T | undefined>) => TNode;
|
|
9
|
-
}
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Renders the view based on the result of an asynchronous operation.
|
|
42
|
+
*
|
|
43
|
+
* @typeParam T - The type of the success value.
|
|
44
|
+
* @typeParam E - The type of the error value.
|
|
45
|
+
* @param result - The result of the asynchronous operation.
|
|
46
|
+
* @param options - The options object or a function that returns a TNode.
|
|
47
|
+
* @returns The rendered view.
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
export declare const AsyncResultView: <T, E>(result: Value<AsyncResult<T, E>>, options: AsyncResultViewOptions<T, E> | ((value: Signal<T>) => TNode)) => Renderable;
|
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import { Renderable } from '@tempots/dom';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Creates a renderable function that focuses on the element after a specified delay.
|
|
5
|
+
*
|
|
6
|
+
* @param delay - The delay in milliseconds before focusing on the element. Default is 10 milliseconds.
|
|
7
|
+
* @returns A renderable function that focuses on the element.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
3
10
|
export declare const AutoFocus: (delay?: number) => Renderable;
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import { Renderable } from '@tempots/dom';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Creates a renderable function that automatically selects the content of an input element after a specified delay.
|
|
5
|
+
* @param delay - The delay in milliseconds before selecting the content. Default is 10 milliseconds.
|
|
6
|
+
* @returns A renderable function that can be used with a DOMContext.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
3
9
|
export declare const AutoSelect: (delay?: number) => Renderable;
|
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import { Renderable } from '@tempots/dom';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Hides the element when it is empty and restores its initial state when necessary.
|
|
5
|
+
*
|
|
6
|
+
* @param ctx - The DOM context.
|
|
7
|
+
* @returns A function that can be used to restore the initial state of the element.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
3
10
|
export declare const HiddenWhenEmpty: Renderable;
|
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import { Value } from '@tempots/dom';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Creates an HTML title element with the specified title.
|
|
5
|
+
*
|
|
6
|
+
* @param title - The title to be set for the HTML title element.
|
|
7
|
+
* @returns The created HTML title element.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export declare const HTMLTitle: (title: Value<string>) => import('@tempots/dom').Renderable;
|
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
import { Signal, TNode, Renderable } from '@tempots/dom';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Represents the mode for determining if an element is in the viewport.
|
|
5
|
+
*
|
|
6
|
+
* - `partial`: Indicates that the element is considered in the viewport if any part of it is visible.
|
|
7
|
+
* - `full`: Indicates that the element is considered in the viewport only if it is fully visible.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
3
11
|
export type InViewportMode = 'partial' | 'full';
|
|
4
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Creates a renderable component that tracks whether the element is in the viewport.
|
|
14
|
+
*
|
|
15
|
+
* @param mode - The mode for tracking the element's visibility in the viewport.
|
|
16
|
+
* @param fn - A function that returns the renderable component based on the visibility signal.
|
|
17
|
+
* @returns The renderable component that tracks the element's visibility in the viewport.
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export declare const InViewport: (mode: InViewportMode, fn: (value: Signal<boolean>) => TNode) => Renderable;
|
|
21
|
+
/**
|
|
22
|
+
* Executes the provided `then` function when the element is in the viewport.
|
|
23
|
+
* Optionally, executes the `otherwise` function when the element is not in the viewport.
|
|
24
|
+
*
|
|
25
|
+
* @param mode - The mode to determine when the element is considered in the viewport.
|
|
26
|
+
* @param then - The function to execute when the element is in the viewport.
|
|
27
|
+
* @param otherwise - The function to execute when the element is not in the viewport.
|
|
28
|
+
* @returns The result of executing the `then` function or the `otherwise` function.
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
5
31
|
export declare const WhenInViewport: (mode: InViewportMode, then: TNode, otherwise?: TNode) => Renderable;
|
|
@@ -1,13 +1,51 @@
|
|
|
1
1
|
import { TNode, DOMContext, Value } from '@tempots/dom';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Represents the placement options for a pop-over.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
3
8
|
export type Placement = 'top' | 'top-start' | 'top-end' | 'right' | 'right-start' | 'right-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'left' | 'left-start' | 'left-end';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Represents the properties for a PopOver component.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export type PopOverOptions = {
|
|
15
|
+
/**
|
|
16
|
+
* Specifies whether the PopOver is open or closed.
|
|
17
|
+
*/
|
|
18
|
+
readonly open: Value<boolean>;
|
|
19
|
+
/**
|
|
20
|
+
* Specifies the content of the PopOver.
|
|
21
|
+
* This should be a function that returns a TNode.
|
|
22
|
+
*/
|
|
23
|
+
readonly content: () => TNode;
|
|
24
|
+
/**
|
|
25
|
+
* Specifies the placement of the PopOver.
|
|
26
|
+
* This is an optional property.
|
|
27
|
+
*/
|
|
28
|
+
readonly placement?: Placement;
|
|
29
|
+
/**
|
|
30
|
+
* Specifies the offset of the PopOver.
|
|
31
|
+
* This is an optional property.
|
|
32
|
+
*/
|
|
33
|
+
readonly offset?: {
|
|
34
|
+
/**
|
|
35
|
+
* Specifies the offset on the main axis.
|
|
36
|
+
*/
|
|
37
|
+
readonly mainAxis?: number;
|
|
38
|
+
/**
|
|
39
|
+
* Specifies the offset on the cross axis.
|
|
40
|
+
*/
|
|
41
|
+
readonly crossAxis?: number;
|
|
11
42
|
};
|
|
12
|
-
}
|
|
13
|
-
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Renders a PopOver component.
|
|
46
|
+
*
|
|
47
|
+
* @param props - The properties for the PopOver component.
|
|
48
|
+
* @returns The rendered PopOver component.
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
export declare const PopOver: ({ content, open, placement, offset: { mainAxis, crossAxis }, }: PopOverOptions) => (ctx: DOMContext) => import('@tempots/dom').Clear;
|
|
@@ -1,7 +1,35 @@
|
|
|
1
|
-
import { TNode, Signal, Value } from '@tempots/dom';
|
|
1
|
+
import { TNode, Signal, Value, Renderable } from '@tempots/dom';
|
|
2
2
|
import { Result } from '@tempots/std';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Represents the signal for a result.
|
|
6
|
+
*
|
|
7
|
+
* @typeParam T - The type of the success value.
|
|
8
|
+
* @typeParam E - The type of the error value.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export type ResultViewOptions<T, E> = {
|
|
12
|
+
/**
|
|
13
|
+
* The function to render the view when the computation succeeds.
|
|
14
|
+
* @param value - The signal for the success value.
|
|
15
|
+
* @returns The rendered view.
|
|
16
|
+
*/
|
|
5
17
|
success: (value: Signal<T>) => TNode;
|
|
18
|
+
/**
|
|
19
|
+
* The function to render the view when the computation fails.
|
|
20
|
+
* @param error - The signal for the error value.
|
|
21
|
+
* @returns The rendered view.
|
|
22
|
+
*/
|
|
6
23
|
failure?: (error: Signal<E>) => TNode;
|
|
7
|
-
}
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Renders a view based on the result of a computation.
|
|
27
|
+
*
|
|
28
|
+
* @typeParam T - The type of the success value.
|
|
29
|
+
* @typeParam E - The type of the error value.
|
|
30
|
+
* @param result - The result of the computation.
|
|
31
|
+
* @param options - The options for rendering the view.
|
|
32
|
+
* @returns The rendered view.
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export declare const ResultView: <T, E>(result: Value<Result<T, E>>, options: ResultViewOptions<T, E> | ((value: Signal<T>) => TNode)) => Renderable;
|
|
@@ -1,16 +1,86 @@
|
|
|
1
1
|
import { TNode, Prop } from '@tempots/dom';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Represents the data for a location.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export type LocationData = {
|
|
9
|
+
/**
|
|
10
|
+
* The pathname of the location.
|
|
11
|
+
*/
|
|
12
|
+
readonly pathname: string;
|
|
13
|
+
/**
|
|
14
|
+
* The search parameters of the location.
|
|
15
|
+
*/
|
|
16
|
+
readonly search: Record<string, string>;
|
|
17
|
+
/**
|
|
18
|
+
* The hash of the location.
|
|
19
|
+
*/
|
|
20
|
+
readonly hash?: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Marker for the LocationProvider.
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
8
27
|
export declare const LocationProviderMarker: import('@tempots/dom').ProviderMark<Prop<LocationData>>;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export declare
|
|
15
|
-
|
|
16
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Creates a location object based on the current browser location.
|
|
30
|
+
* @returns The location object representing the current browser location.
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
export declare const _makeLocation: () => LocationData;
|
|
34
|
+
/**
|
|
35
|
+
* Compares two location objects and returns true if they are equal, false otherwise.
|
|
36
|
+
* @param a - The first location object to compare.
|
|
37
|
+
* @param b - The second location object to compare.
|
|
38
|
+
* @returns True if the location objects are equal, false otherwise.
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
export declare const areLocationsEqual: (a: LocationData, b: LocationData) => boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Converts a URL string into a LocationData object.
|
|
44
|
+
* @param url - The URL string to convert.
|
|
45
|
+
* @returns The LocationData object representing the URL.
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
export declare const locationFromURL: (url: string) => LocationData;
|
|
49
|
+
/**
|
|
50
|
+
* Sets the location from the given URL and updates the specified property.
|
|
51
|
+
* @param prop - The property to update with the new location.
|
|
52
|
+
* @param url - The URL from which to extract the location.
|
|
53
|
+
* @returns The updated property.
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
export declare const setLocationFromUrl: (prop: Prop<LocationData>, url: string) => Prop<LocationData>;
|
|
57
|
+
/**
|
|
58
|
+
* Returns the full URL based on the provided location data.
|
|
59
|
+
*
|
|
60
|
+
* @param location - The location data object.
|
|
61
|
+
* @returns The full URL string.
|
|
62
|
+
* @public
|
|
63
|
+
*/
|
|
64
|
+
export declare const urlFromLocation: (location: LocationData) => string;
|
|
65
|
+
/**
|
|
66
|
+
* Creates a location prop that represents the current browser location.
|
|
67
|
+
* The location prop is updated whenever the browser location changes.
|
|
68
|
+
*
|
|
69
|
+
* @returns The location prop.
|
|
70
|
+
* @internal
|
|
71
|
+
*/
|
|
72
|
+
export declare const _makeLocationProp: () => Prop<LocationData>;
|
|
73
|
+
/**
|
|
74
|
+
* Provides the location context to the child component.
|
|
75
|
+
* @param child - The child component to be wrapped with the location context.
|
|
76
|
+
* @returns The wrapped component with the location context.
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
export declare const ProvideLocation: (child: TNode) => import('@tempots/dom').Renderable;
|
|
80
|
+
/**
|
|
81
|
+
* A hook that provides the current location data to the given function.
|
|
82
|
+
* @param fn - The function that receives the location data.
|
|
83
|
+
* @returns A function that can be used to clean up the resources when the location changes.
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
86
|
+
export declare const UseLocation: (fn: (location: Prop<LocationData>) => TNode) => import('@tempots/dom').Renderable;
|
|
@@ -1,14 +1,46 @@
|
|
|
1
1
|
import { ExtractParams, Route } from './route-info';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* The result of a route match.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
3
8
|
export type MatchResult<P extends string> = {
|
|
4
9
|
params: ExtractParams<P>;
|
|
5
10
|
path: P;
|
|
6
11
|
} | null;
|
|
12
|
+
/**
|
|
13
|
+
* The result of a route match with the matched route.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
7
17
|
export type MatchResultWithRoute<P extends string, R extends string> = {
|
|
8
18
|
params: ExtractParams<P>;
|
|
9
19
|
route: R;
|
|
10
20
|
path: P;
|
|
11
21
|
} | null;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Matches a path against a route.
|
|
24
|
+
*
|
|
25
|
+
* @param route - The route to match against.
|
|
26
|
+
* @param path - The path to match.
|
|
27
|
+
* @returns The match result.
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export declare const matchesRoute: <P extends string>(route: Route, path: P) => MatchResult<P>;
|
|
31
|
+
/**
|
|
32
|
+
* Parses a route string into an array of route segments.
|
|
33
|
+
*
|
|
34
|
+
* @param route - The route string to parse.
|
|
35
|
+
* @returns An array of route segments.
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
export declare const _parseRouteSegments: (route: string) => Route;
|
|
39
|
+
/**
|
|
40
|
+
* Creates a route matcher function that can be used to match paths against a list of routes.
|
|
41
|
+
*
|
|
42
|
+
* @param routes - An array of route strings.
|
|
43
|
+
* @returns A function that can be used to match paths against the provided routes.
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
export declare const _makeRouteMatcher: <Routes extends string[]>(routes: Routes) => <S extends string>(path: S) => MatchResultWithRoute<S, Routes[number]>;
|
|
@@ -1,27 +1,112 @@
|
|
|
1
1
|
import { SplitLiteral, TupleToUnion } from '@tempots/std';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Represents information about a route.
|
|
5
|
+
*
|
|
6
|
+
* @typeParam P - The type of the route parameters.
|
|
7
|
+
* @typeParam R - The type of the route.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export type RouteInfo<P, R = string> = {
|
|
11
|
+
/**
|
|
12
|
+
* The parameters of the route.
|
|
13
|
+
*/
|
|
14
|
+
readonly params: P;
|
|
15
|
+
/**
|
|
16
|
+
* The route that was matched.
|
|
17
|
+
*/
|
|
18
|
+
readonly route: R;
|
|
19
|
+
/**
|
|
20
|
+
* The path that was matched.
|
|
21
|
+
*/
|
|
22
|
+
readonly path: string;
|
|
23
|
+
/**
|
|
24
|
+
* The search parameters of the route.
|
|
25
|
+
*/
|
|
26
|
+
readonly search: Record<string, string>;
|
|
27
|
+
/**
|
|
28
|
+
* The hash of the route.
|
|
29
|
+
*/
|
|
30
|
+
readonly hash?: string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Represents a route parameter.
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
10
37
|
export type RouteParam = {
|
|
38
|
+
/**
|
|
39
|
+
* The type of the route parameter.
|
|
40
|
+
*/
|
|
11
41
|
type: 'param';
|
|
42
|
+
/**
|
|
43
|
+
* The name of the route parameter.
|
|
44
|
+
*/
|
|
12
45
|
name: string;
|
|
13
46
|
};
|
|
47
|
+
/**
|
|
48
|
+
* Represents a literal route.
|
|
49
|
+
*
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
14
52
|
export type RouteLiteral = {
|
|
53
|
+
/**
|
|
54
|
+
* The type of the route literal.
|
|
55
|
+
*/
|
|
15
56
|
type: 'literal';
|
|
57
|
+
/**
|
|
58
|
+
* The value of the route literal
|
|
59
|
+
*/
|
|
16
60
|
value: string;
|
|
17
61
|
};
|
|
62
|
+
/**
|
|
63
|
+
* Represents a catch-all route.
|
|
64
|
+
*
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
18
67
|
export type RouteCatchAll = {
|
|
68
|
+
/**
|
|
69
|
+
* The type of the catch-all
|
|
70
|
+
*/
|
|
19
71
|
type: 'catch-all';
|
|
20
72
|
};
|
|
73
|
+
/**
|
|
74
|
+
* Represents a segment of a route.
|
|
75
|
+
*
|
|
76
|
+
* @public
|
|
77
|
+
*/
|
|
21
78
|
export type RouteSegment = RouteParam | RouteLiteral | RouteCatchAll;
|
|
79
|
+
/**
|
|
80
|
+
* Represents a route in the application.
|
|
81
|
+
*
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
22
84
|
export type Route = RouteSegment[];
|
|
85
|
+
/**
|
|
86
|
+
* Represents a type that transforms a tuple of strings into an object with string keys.
|
|
87
|
+
* If the input type is a tuple, each element of the tuple will become a key in the resulting object,
|
|
88
|
+
* with the corresponding value being a string.
|
|
89
|
+
* If the input type is not a tuple, the resulting type will be `never`.
|
|
90
|
+
*
|
|
91
|
+
* @typeparam P - The input type, which can be a tuple of strings or any other type.
|
|
92
|
+
* @returns - If `P` is a tuple, an object with string keys. Otherwise, `never`.
|
|
93
|
+
* @public
|
|
94
|
+
*/
|
|
23
95
|
export type MakeParams<P> = P extends string[] ? {
|
|
24
96
|
[K in TupleToUnion<P>]: string;
|
|
25
97
|
} : never;
|
|
98
|
+
/**
|
|
99
|
+
* Extracts the parameter names from a tuple type.
|
|
100
|
+
*
|
|
101
|
+
* @typeParam S - The tuple type from which to extract the parameter names.
|
|
102
|
+
* @returns An array of parameter names extracted from the tuple type.
|
|
103
|
+
* @public
|
|
104
|
+
*/
|
|
26
105
|
export type ExtractParamsFromTuple<S extends unknown[]> = S extends [] ? [] : S extends [infer H, ...infer R] ? H extends `:${infer P}` ? [P, ...ExtractParamsFromTuple<R>] : ExtractParamsFromTuple<R> : never;
|
|
106
|
+
/**
|
|
107
|
+
* Extracts the parameters from a string literal representing a route path.
|
|
108
|
+
* @typeParam S - The string literal representing the route path.
|
|
109
|
+
* @returns The extracted parameters from the route path.
|
|
110
|
+
* @public
|
|
111
|
+
*/
|
|
27
112
|
export type ExtractParams<S extends string> = SplitLiteral<S, '/'> extends infer T ? T extends unknown[] ? ExtractParamsFromTuple<T> : never : never;
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { TNode, Renderable, Signal } from '@tempots/dom';
|
|
2
2
|
import { ExtractParams, MakeParams, RouteInfo } from './route-info';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Creates a router that maps routes to corresponding renderable components.
|
|
6
|
+
*
|
|
7
|
+
* @typeParam T - The type of the routes object.
|
|
8
|
+
* @param routes - An object containing route handlers.
|
|
9
|
+
* @returns - The router renderable.
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export declare const Router: <T extends { [K in keyof T]: (info: K extends string ? Signal<RouteInfo<MakeParams<ExtractParams<K>>, K>> : never) => TNode; }>(routes: T) => Renderable;
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Selects the text inside an input element when it receives focus.
|
|
3
|
+
*
|
|
4
|
+
* @returns A renderable function that selects the text inside an input element when it receives focus.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare const SelectOnFocus: () => import('@tempots/dom').Renderable;
|
package/renderables/size.d.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { DOMContext, Signal, TNode, Size } from '@tempots/dom';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Creates a renderable function that monitors the size of an element and provides it as a signal.
|
|
5
|
+
*
|
|
6
|
+
* @param fn - The renderable function that receives the size signal and returns a TNode.
|
|
7
|
+
* @returns A function that takes a DOMContext and returns a renderable function.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export declare const ElementSize: (fn: (size: Signal<Size>) => TNode) => (ctx: DOMContext) => (removeTree: boolean) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a renderable function that monitors the window size and invokes the provided function with the current size.
|
|
13
|
+
* @param fn - The function to be invoked with the current window size.
|
|
14
|
+
* @returns A renderable function that monitors the window size.
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export declare const WindowSize: (fn: (size: Signal<Size>) => TNode) => (ctx: DOMContext) => (removeTree: boolean) => void;
|