@inglorious/web 2.0.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/LICENSE +9 -0
- package/README.md +383 -0
- package/package.json +54 -0
- package/src/form.js +371 -0
- package/src/index.js +10 -0
- package/src/list.js +105 -0
- package/src/mount.js +49 -0
- package/src/router.js +268 -0
- package/types/form.d.ts +377 -0
- package/types/index.d.ts +2 -0
- package/types/mount.d.ts +24 -0
- package/types/router.d.ts +111 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A map of route patterns to entity types.
|
|
3
|
+
* The order of routes matters: more specific routes (e.g., `/users/new`)
|
|
4
|
+
* should be defined before more generic ones (e.g., `/users/:id`).
|
|
5
|
+
*
|
|
6
|
+
* A special `'*'` pattern can be used as a fallback for "not found" routes.
|
|
7
|
+
* @example { "/users/:id": "userPage", "/": "homePage" }
|
|
8
|
+
*/
|
|
9
|
+
export type RoutesConfig = Record<string, string>
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* An object containing parameters extracted from the route.
|
|
13
|
+
* @example { id: "123" } for route "/users/:id" and path "/users/123"
|
|
14
|
+
*/
|
|
15
|
+
export type RouteParams = Record<string, string>
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* An object containing query string parameters.
|
|
19
|
+
* @example { sort: "asc" } for path "/users?sort=asc"
|
|
20
|
+
*/
|
|
21
|
+
export type QueryParams = Record<string, string>
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Represents the state of the router entity.
|
|
25
|
+
*/
|
|
26
|
+
export interface RouterEntity {
|
|
27
|
+
/** A unique identifier for the router entity. */
|
|
28
|
+
id: string | number
|
|
29
|
+
/** The route configuration. */
|
|
30
|
+
routes: RoutesConfig
|
|
31
|
+
/** The current active path, without query string or hash. */
|
|
32
|
+
path?: string
|
|
33
|
+
/** The entity type of the current active route. */
|
|
34
|
+
route?: string
|
|
35
|
+
/** The parameters extracted from the current path. */
|
|
36
|
+
params?: RouteParams
|
|
37
|
+
/** The query parameters from the current URL. */
|
|
38
|
+
query?: QueryParams
|
|
39
|
+
/** The hash from the current URL. */
|
|
40
|
+
hash?: string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The payload for the `navigate` function.
|
|
45
|
+
*/
|
|
46
|
+
export interface NavigatePayload {
|
|
47
|
+
/** The path to navigate to, or a number to move in the history stack (e.g., -1 for back). */
|
|
48
|
+
to: string | number
|
|
49
|
+
/** Parameters to build a dynamic path from a pattern. */
|
|
50
|
+
params?: RouteParams
|
|
51
|
+
/** If true, `history.replaceState` will be used instead of `history.pushState`. */
|
|
52
|
+
replace?: boolean
|
|
53
|
+
/** Additional state to be stored in the browser's history. */
|
|
54
|
+
state?: Record<string, any>
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The payload for the `routeSync` event, containing all information about the new route.
|
|
59
|
+
*/
|
|
60
|
+
export interface RouteSyncPayload {
|
|
61
|
+
path: string
|
|
62
|
+
entityType: string
|
|
63
|
+
params: RouteParams
|
|
64
|
+
query: QueryParams
|
|
65
|
+
hash: string
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The API object provided to the router for interacting with the host system.
|
|
70
|
+
*/
|
|
71
|
+
export interface RouterApi {
|
|
72
|
+
/** Retrieves an entity by its ID. */
|
|
73
|
+
getEntity(id: string | number): { routes: RoutesConfig }
|
|
74
|
+
/** Dispatches an event to the system. */
|
|
75
|
+
notify(eventName: "routeSync", payload: RouteSyncPayload): void
|
|
76
|
+
notify(eventName: "navigate", payload: string): void
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The router implementation.
|
|
81
|
+
*/
|
|
82
|
+
export declare const router: {
|
|
83
|
+
/**
|
|
84
|
+
* Initializes the router, sets up a popstate listener to handle browser navigation,
|
|
85
|
+
* and intercepts clicks on local links.
|
|
86
|
+
* @param entity The router state entity.
|
|
87
|
+
* @param payload The initialization payload (currently unused).
|
|
88
|
+
* @param api The API for interacting with the host system.
|
|
89
|
+
*/
|
|
90
|
+
init(entity: RouterEntity, payload: any, api: RouterApi): void
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Navigates to a new route programmatically.
|
|
94
|
+
* @param entity The router state entity.
|
|
95
|
+
* @param payload The navigation details.
|
|
96
|
+
* @param api The API for interacting with the host system.
|
|
97
|
+
*/
|
|
98
|
+
navigate(
|
|
99
|
+
entity: RouterEntity,
|
|
100
|
+
payload: string | number | NavigatePayload,
|
|
101
|
+
api: RouterApi,
|
|
102
|
+
): void
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Synchronizes the router entity's state with the provided route information.
|
|
106
|
+
* Typically called in response to a `popstate` event.
|
|
107
|
+
* @param entity The router state entity.
|
|
108
|
+
* @param payload The new route information.
|
|
109
|
+
*/
|
|
110
|
+
routeSync(entity: RouterEntity, payload: RouteSyncPayload): void
|
|
111
|
+
}
|