athena-ui-js 2.0.1 → 2.2.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.
Files changed (30) hide show
  1. package/README.md +58 -4
  2. package/docs/migration-2.0.md +1 -1
  3. package/docs/styling.md +24 -7
  4. package/package.json +5 -1
  5. package/src/athena-ui.js +2 -1
  6. package/src/libs/config/config.js +1 -1
  7. package/src/libs/core/motion.js +358 -0
  8. package/src/libs/core/popover.js +96 -0
  9. package/src/libs/core/theme.js +12 -0
  10. package/src/libs/hephaestus/chartGenerator/chartGenerator.js +9 -5
  11. package/src/libs/hephaestus/componentGenerator/componentGenerator.js +43 -2
  12. package/src/libs/hephaestus/dialogGenerator/dialogGenerator.js +2 -1
  13. package/src/libs/hephaestus/feedbackGenerator/feedbackGenerator.js +3 -1
  14. package/src/libs/hephaestus/navigationGenerator/navigationGenerator.js +45 -9
  15. package/src/libs/hephaestus/router/router.js +18 -9
  16. package/src/libs/hephaestus/tableGenerator/tableGenerator.js +25 -0
  17. package/src/motion.js +6 -0
  18. package/src/res/themes/default/style.css +260 -10
  19. package/src/res/themes/tokens.css +25 -0
  20. package/types/athena-ui.d.ts +97 -96
  21. package/types/libs/config/config.d.ts +3 -3
  22. package/types/libs/core/motion.d.ts +123 -0
  23. package/types/libs/core/popover.d.ts +36 -0
  24. package/types/libs/core/theme.d.ts +41 -39
  25. package/types/libs/hephaestus/chartGenerator/chartGenerator.d.ts +2 -0
  26. package/types/libs/hephaestus/componentGenerator/componentGenerator.d.ts +238 -222
  27. package/types/libs/hephaestus/navigationGenerator/navigationGenerator.d.ts +4 -1
  28. package/types/libs/hephaestus/router/router.d.ts +71 -67
  29. package/types/libs/hephaestus/tableGenerator/tableGenerator.d.ts +123 -120
  30. package/types/motion.d.ts +1 -0
@@ -1,222 +1,238 @@
1
- /**
2
- * Generates a link. External links open in a new tab and get `rel="noopener noreferrer"`.
3
- * With `onclick` and no `href` it behaves as an in-page action.
4
- *
5
- * @param {object} options
6
- * @param {string|Element} [options.parent]
7
- * @param {string} options.text
8
- * @param {string} [options.href]
9
- * @param {boolean} [options.external]
10
- * @param {(event: Event) => void} [options.onclick]
11
- * @returns {HTMLAnchorElement}
12
- */
13
- export function generateLink(options?: {
14
- parent?: string | Element;
15
- text: string;
16
- href?: string;
17
- external?: boolean;
18
- onclick?: (event: Event) => void;
19
- }): HTMLAnchorElement;
20
- /**
21
- * Generates a section with an optional heading. Returns the section, fill it through `content`
22
- * or append to it.
23
- *
24
- * @param {object} options
25
- * @param {string|Element} [options.parent]
26
- * @param {string} [options.title]
27
- * @param {number} [options.level=2] heading level 1..6
28
- * @param {string|Node|Array|Function} [options.content]
29
- * @returns {HTMLElement}
30
- */
31
- export function generateSection(options?: {
32
- parent?: string | Element;
33
- title?: string;
34
- level?: number;
35
- content?: string | Node | any[] | Function;
36
- }): HTMLElement;
37
- /**
38
- * Generates a card.
39
- *
40
- * @param {object} options
41
- * @param {string|Element} [options.parent]
42
- * @param {string} [options.title]
43
- * @param {string} [options.image] image URL shown on top
44
- * @param {string} [options.imageAlt]
45
- * @param {string|Node|Array|Function} [options.content]
46
- * @param {string|Node|Array|Function} [options.footer]
47
- * @returns {{element: HTMLElement, body: HTMLElement}} append to `body` to add more content
48
- */
49
- export function generateCard(options?: {
50
- parent?: string | Element;
51
- title?: string;
52
- image?: string;
53
- imageAlt?: string;
54
- content?: string | Node | any[] | Function;
55
- footer?: string | Node | any[] | Function;
56
- }): {
57
- element: HTMLElement;
58
- body: HTMLElement;
59
- };
60
- /**
61
- * Generates a small label.
62
- *
63
- * @param {object} options
64
- * @param {string|Element} [options.parent]
65
- * @param {string} options.text
66
- * @param {"neutral"|"info"|"success"|"warning"|"error"} [options.variant="neutral"]
67
- * @param {boolean} [options.pill]
68
- * @returns {HTMLElement}
69
- */
70
- export function generateBadge(options?: {
71
- parent?: string | Element;
72
- text: string;
73
- variant?: "neutral" | "info" | "success" | "warning" | "error";
74
- pill?: boolean;
75
- }): HTMLElement;
76
- export function initialsOf(name?: string): string;
77
- /**
78
- * Generates an avatar: the image, or the initials of the name when there is no (working) image.
79
- *
80
- * @param {object} options
81
- * @param {string|Element} [options.parent]
82
- * @param {string} [options.name]
83
- * @param {string} [options.src]
84
- * @param {"small"|"large"} [options.size]
85
- * @returns {HTMLElement}
86
- */
87
- export function generateAvatar(options?: {
88
- parent?: string | Element;
89
- name?: string;
90
- src?: string;
91
- size?: "small" | "large";
92
- }): HTMLElement;
93
- /**
94
- * Generates a KPI tile: a label, a big value and an optional change.
95
- *
96
- * @param {object} options
97
- * @param {string|Element} [options.parent]
98
- * @param {string} options.label
99
- * @param {string|number} options.value
100
- * @param {number} [options.delta] change in percent, shown with an arrow
101
- * @param {boolean} [options.invertDelta] a falling value is good news (costs, errors)
102
- * @param {"ok"|"warn"|"bad"} [options.tone] colours the tile (the class is-ok / is-warn / is-bad) and adds the word to the screen reader text
103
- * @param {string} [options.note] small text under the value ("of 120 hosts", "updated 2 min ago")
104
- * @returns {{element: HTMLElement, setValue: Function, setNote: Function, setTone: Function}}
105
- */
106
- export function generateStat(options?: {
107
- parent?: string | Element;
108
- label: string;
109
- value: string | number;
110
- delta?: number;
111
- invertDelta?: boolean;
112
- tone?: "ok" | "warn" | "bad";
113
- note?: string;
114
- }): {
115
- element: HTMLElement;
116
- setValue: Function;
117
- setNote: Function;
118
- setTone: Function;
119
- };
120
- /**
121
- * Generates a responsive grid. The columns collapse to one on small screens.
122
- *
123
- * @param {object} options
124
- * @param {string|Element} [options.parent]
125
- * @param {number} [options.columns=3]
126
- * @param {string} [options.gap] any CSS length
127
- * @returns {HTMLElement} append the cells to it
128
- */
129
- export function generateGrid(options?: {
130
- parent?: string | Element;
131
- columns?: number;
132
- gap?: string;
133
- }): HTMLElement;
134
- /**
135
- * Adds a tooltip to an element. It shows on hover and on keyboard focus.
136
- *
137
- * @param {Element|string} target element or id
138
- * @param {string} text
139
- */
140
- export function generateTooltip(target: Element | string, text: string): HTMLElement;
141
- /**
142
- * The top of a page: breadcrumbs, the title (a heading), a description and the actions of the page.
143
- *
144
- * @param {object} options
145
- * @param {string|Element} [options.parent]
146
- * @param {string} options.title
147
- * @param {string} [options.description]
148
- * @param {{label: string, href?: string, onclick?: Function}[]} [options.breadcrumbs] see generateBreadcrumbs
149
- * @param {(Node|string)[]|Node} [options.actions] buttons, shown at the end of the header
150
- * @param {1|2|3} [options.level=1] heading level
151
- * @returns {{element: HTMLElement, setTitle: Function, setDescription: Function, actions: HTMLElement}}
152
- */
153
- export function generatePageHeader(options?: {
154
- parent?: string | Element;
155
- title: string;
156
- description?: string;
157
- breadcrumbs?: {
158
- label: string;
159
- href?: string;
160
- onclick?: Function;
161
- }[];
162
- actions?: (Node | string)[] | Node;
163
- level?: 1 | 2 | 3;
164
- }): {
165
- element: HTMLElement;
166
- setTitle: Function;
167
- setDescription: Function;
168
- actions: HTMLElement;
169
- };
170
- /**
171
- * A list of facts: a term and its description, in pairs (a <dl>).
172
- *
173
- * @param {object} options
174
- * @param {string|Element} [options.parent]
175
- * @param {{term: string, description: (string|number|Node|Array), title?: string}[]} options.items text is inserted as text
176
- * @param {boolean} [options.inline=false] terms and descriptions side by side
177
- * @returns {{element: HTMLElement, setItems: Function}}
178
- */
179
- export function generateFacts(options?: {
180
- parent?: string | Element;
181
- items: {
182
- term: string;
183
- description: (string | number | Node | any[]);
184
- title?: string;
185
- }[];
186
- inline?: boolean;
187
- }): {
188
- element: HTMLElement;
189
- setItems: Function;
190
- };
191
- /**
192
- * What a list shows when there is nothing in it: a title, a short explanation and what to do about it.
193
- *
194
- * @param {object} options
195
- * @param {string|Element} [options.parent]
196
- * @param {string} options.title
197
- * @param {string} [options.message]
198
- * @param {string|Node} [options.icon] decorative
199
- * @param {{text: string, onclick: Function, variant?: string}} [options.action] a button
200
- */
201
- export function generateEmptyState(options?: {
202
- parent?: string | Element;
203
- title: string;
204
- message?: string;
205
- icon?: string | Node;
206
- action?: {
207
- text: string;
208
- onclick: Function;
209
- variant?: string;
210
- };
211
- }): any;
212
- /**
213
- * A placeholder while something loads: a spinner and a text (a live region, so a screen reader says it).
214
- *
215
- * @param {object} [options]
216
- * @param {string|Element} [options.parent]
217
- * @param {string} [options.text] default: the translated "Loading..."
218
- */
219
- export function generateLoading(options?: {
220
- parent?: string | Element;
221
- text?: string;
222
- }): any;
1
+ /**
2
+ * Generates a link. External links open in a new tab and get `rel="noopener noreferrer"`.
3
+ * With `onclick` and no `href` it behaves as an in-page action.
4
+ *
5
+ * @param {object} options
6
+ * @param {string|Element} [options.parent]
7
+ * @param {string} options.text
8
+ * @param {string} [options.href]
9
+ * @param {boolean} [options.external]
10
+ * @param {(event: Event) => void} [options.onclick]
11
+ * @returns {HTMLAnchorElement}
12
+ */
13
+ export function generateLink(options?: {
14
+ parent?: string | Element;
15
+ text: string;
16
+ href?: string;
17
+ external?: boolean;
18
+ onclick?: (event: Event) => void;
19
+ }): HTMLAnchorElement;
20
+ /**
21
+ * Generates a section with an optional heading. Returns the section, fill it through `content`
22
+ * or append to it.
23
+ *
24
+ * @param {object} options
25
+ * @param {string|Element} [options.parent]
26
+ * @param {string} [options.title]
27
+ * @param {number} [options.level=2] heading level 1..6
28
+ * @param {string|Node|Array|Function} [options.content]
29
+ * @returns {HTMLElement}
30
+ */
31
+ export function generateSection(options?: {
32
+ parent?: string | Element;
33
+ title?: string;
34
+ level?: number;
35
+ content?: string | Node | any[] | Function;
36
+ }): HTMLElement;
37
+ /**
38
+ * Generates a card.
39
+ *
40
+ * @param {object} options
41
+ * @param {string|Element} [options.parent]
42
+ * @param {string} [options.title]
43
+ * @param {string} [options.image] image URL shown on top
44
+ * @param {string} [options.imageAlt]
45
+ * @param {string|Node|Array|Function} [options.content]
46
+ * @param {string|Node|Array|Function} [options.footer]
47
+ * @returns {{element: HTMLElement, body: HTMLElement}} append to `body` to add more content
48
+ */
49
+ export function generateCard(options?: {
50
+ parent?: string | Element;
51
+ title?: string;
52
+ image?: string;
53
+ imageAlt?: string;
54
+ content?: string | Node | any[] | Function;
55
+ footer?: string | Node | any[] | Function;
56
+ }): {
57
+ element: HTMLElement;
58
+ body: HTMLElement;
59
+ };
60
+ /**
61
+ * Generates a small label.
62
+ *
63
+ * @param {object} options
64
+ * @param {string|Element} [options.parent]
65
+ * @param {string} options.text
66
+ * @param {"neutral"|"info"|"success"|"warning"|"error"} [options.variant="neutral"]
67
+ * @param {boolean} [options.pill]
68
+ * @returns {HTMLElement}
69
+ */
70
+ export function generateBadge(options?: {
71
+ parent?: string | Element;
72
+ text: string;
73
+ variant?: "neutral" | "info" | "success" | "warning" | "error";
74
+ pill?: boolean;
75
+ }): HTMLElement;
76
+ export function initialsOf(name?: string): string;
77
+ /**
78
+ * Generates an avatar: the image, or the initials of the name when there is no (working) image.
79
+ *
80
+ * @param {object} options
81
+ * @param {string|Element} [options.parent]
82
+ * @param {string} [options.name]
83
+ * @param {string} [options.src]
84
+ * @param {"small"|"large"} [options.size]
85
+ * @returns {HTMLElement}
86
+ */
87
+ export function generateAvatar(options?: {
88
+ parent?: string | Element;
89
+ name?: string;
90
+ src?: string;
91
+ size?: "small" | "large";
92
+ }): HTMLElement;
93
+ /**
94
+ * Generates a KPI tile: a label, a big value and an optional change.
95
+ *
96
+ * @param {object} options
97
+ * @param {string|Element} [options.parent]
98
+ * @param {string} options.label
99
+ * @param {string|number} options.value
100
+ * @param {number} [options.delta] change in percent, shown with an arrow
101
+ * @param {boolean} [options.invertDelta] a falling value is good news (costs, errors)
102
+ * @param {"ok"|"warn"|"bad"} [options.tone] colours the tile (the class is-ok / is-warn / is-bad) and adds the word to the screen reader text
103
+ * @param {string} [options.note] small text under the value ("of 120 hosts", "updated 2 min ago")
104
+ * @returns {{element: HTMLElement, setValue: Function, setNote: Function, setTone: Function}}
105
+ */
106
+ export function generateStat(options?: {
107
+ parent?: string | Element;
108
+ label: string;
109
+ value: string | number;
110
+ delta?: number;
111
+ invertDelta?: boolean;
112
+ tone?: "ok" | "warn" | "bad";
113
+ note?: string;
114
+ }): {
115
+ element: HTMLElement;
116
+ setValue: Function;
117
+ setNote: Function;
118
+ setTone: Function;
119
+ };
120
+ /**
121
+ * Generates a responsive grid. The columns collapse to one on small screens.
122
+ *
123
+ * @param {object} options
124
+ * @param {string|Element} [options.parent]
125
+ * @param {number} [options.columns=3]
126
+ * @param {string} [options.gap] any CSS length
127
+ * @returns {HTMLElement} append the cells to it
128
+ */
129
+ export function generateGrid(options?: {
130
+ parent?: string | Element;
131
+ columns?: number;
132
+ gap?: string;
133
+ }): HTMLElement;
134
+ /**
135
+ * Adds a tooltip to an element. It shows on hover and on keyboard focus, and Esc hides it.
136
+ * It is a native popover (`popover="manual"`), so it is drawn above everything and never cut off by a parent with `overflow: hidden`. A touch
137
+ * does not show it (a tap would hide the thing it describes). Browsers without the popover API show it with CSS, as before.
138
+ *
139
+ * @param {Element|string} target element or id
140
+ * @param {string} text
141
+ */
142
+ export function generateTooltip(target: Element | string, text: string): HTMLElement;
143
+ /**
144
+ * The top of a page: breadcrumbs, the title (a heading), a description and the actions of the page.
145
+ *
146
+ * @param {object} options
147
+ * @param {string|Element} [options.parent]
148
+ * @param {string} options.title
149
+ * @param {string} [options.description]
150
+ * @param {{label: string, href?: string, onclick?: Function}[]} [options.breadcrumbs] see generateBreadcrumbs
151
+ * @param {(Node|string)[]|Node} [options.actions] buttons, shown at the end of the header
152
+ * @param {1|2|3} [options.level=1] heading level
153
+ * @returns {{element: HTMLElement, setTitle: Function, setDescription: Function, actions: HTMLElement}}
154
+ */
155
+ export function generatePageHeader(options?: {
156
+ parent?: string | Element;
157
+ title: string;
158
+ description?: string;
159
+ breadcrumbs?: {
160
+ label: string;
161
+ href?: string;
162
+ onclick?: Function;
163
+ }[];
164
+ actions?: (Node | string)[] | Node;
165
+ level?: 1 | 2 | 3;
166
+ }): {
167
+ element: HTMLElement;
168
+ setTitle: Function;
169
+ setDescription: Function;
170
+ actions: HTMLElement;
171
+ };
172
+ /**
173
+ * A list of facts: a term and its description, in pairs (a <dl>).
174
+ *
175
+ * @param {object} options
176
+ * @param {string|Element} [options.parent]
177
+ * @param {{term: string, description: (string|number|Node|Array), title?: string}[]} options.items text is inserted as text
178
+ * @param {boolean} [options.inline=false] terms and descriptions side by side
179
+ * @returns {{element: HTMLElement, setItems: Function}}
180
+ */
181
+ export function generateFacts(options?: {
182
+ parent?: string | Element;
183
+ items: {
184
+ term: string;
185
+ description: (string | number | Node | any[]);
186
+ title?: string;
187
+ }[];
188
+ inline?: boolean;
189
+ }): {
190
+ element: HTMLElement;
191
+ setItems: Function;
192
+ };
193
+ /**
194
+ * What a list shows when there is nothing in it: a title, a short explanation and what to do about it.
195
+ *
196
+ * @param {object} options
197
+ * @param {string|Element} [options.parent]
198
+ * @param {string} options.title
199
+ * @param {string} [options.message]
200
+ * @param {string|Node} [options.icon] decorative
201
+ * @param {{text: string, onclick: Function, variant?: string}} [options.action] a button
202
+ */
203
+ export function generateEmptyState(options?: {
204
+ parent?: string | Element;
205
+ title: string;
206
+ message?: string;
207
+ icon?: string | Node;
208
+ action?: {
209
+ text: string;
210
+ onclick: Function;
211
+ variant?: string;
212
+ };
213
+ }): any;
214
+ /**
215
+ * A skeleton: grey lines with a shimmer where text or a card will be, so the page does not jump when it arrives. It is a live region that says
216
+ * "Loading..." to a screen reader; the shimmer stops under reduced motion.
217
+ *
218
+ * @param {object} [options]
219
+ * @param {string|Element} [options.parent]
220
+ * @param {number} [options.lines=3] the last of several lines is shorter
221
+ * @param {string} [options.class] e.g. "skeleton-card" in your own CSS gives the box a height
222
+ */
223
+ export function generateSkeleton(options?: {
224
+ parent?: string | Element;
225
+ lines?: number;
226
+ class?: string;
227
+ }): any;
228
+ /**
229
+ * A placeholder while something loads: a spinner and a text (a live region, so a screen reader says it).
230
+ *
231
+ * @param {object} [options]
232
+ * @param {string|Element} [options.parent]
233
+ * @param {string} [options.text] default: the translated "Loading..."
234
+ */
235
+ export function generateLoading(options?: {
236
+ parent?: string | Element;
237
+ text?: string;
238
+ }): any;
@@ -89,7 +89,10 @@ export function generateAccordion(options?: {
89
89
  toggle: (index: number, open?: boolean) => void;
90
90
  };
91
91
  /**
92
- * Generates a button that opens a menu. Arrow keys move through the items, Esc closes it.
92
+ * Generates a button that opens a menu. Arrow keys move through the items, Esc closes it, and so does a click outside.
93
+ * The menu is a native popover (the `popover` attribute): it is drawn above everything, so no parent can cut it off, and the browser takes care of the
94
+ * light dismiss and of the focus. It is placed next to the button, below it, or above it when there is no room below. Browsers without the popover API
95
+ * get a plain menu that is shown and hidden with `hidden`.
93
96
  *
94
97
  * @param {object} options
95
98
  * @param {string|Element} [options.parent]
@@ -1,67 +1,71 @@
1
- /**
2
- * Creates a router that renders a page function into an outlet element.
3
- *
4
- * @param {object} options
5
- * @param {Object<string, Function|{handler: Function, title?: string}>} options.routes path pattern -> page
6
- * function. Patterns support `:param` segments and a trailing `*`. A page function is called with
7
- * `{ path, params, query }` after the outlet was emptied, and may return a promise.
8
- * @param {string} [options.outlet="wrapper"] id of the element the pages are rendered into
9
- * @param {"hash"|"history"} [options.mode="hash"] "history" needs the server to answer every path with the page
10
- * @param {(context) => void} [options.notFound] called when no route matches
11
- * @param {(context) => (boolean|string|void|Promise)} [options.beforeEach] guard: return false to cancel,
12
- * or a path to redirect to (login redirect)
13
- * @param {(context) => void} [options.afterEach] same as onShown
14
- * @param {(context, route) => void} [options.onRender] called after the outlet was emptied, before the page function runs
15
- * @param {(context, route) => void} [options.onShown] called after the page function finished (and it was not replaced by a newer
16
- * navigation): the place to set the title, move the focus to the content, scroll to the top
17
- * @param {boolean} [options.focusContent=false] after a page is shown the outlet gets the focus (it is made focusable for that), so a
18
- * screen reader starts reading the new page and the keyboard continues there
19
- * @param {boolean} [options.scrollTop=false] scroll to the top after a page is shown
20
- * @param {object} [options.auth] sign-in rules for routes, see the route options below
21
- * @param {() => boolean} [options.auth.isSignedIn]
22
- * @param {(role: string) => boolean} [options.auth.hasRole]
23
- * @param {string} [options.auth.loginPath="/login"] where `auth: true` routes send a visitor who is not signed in (with `?next=<path>`)
24
- * @param {string} [options.auth.homePath="/"] where `guestOnly` routes send a signed-in person
25
- * @param {string} [options.auth.forbiddenPath] where a person without the role goes (default: homePath)
26
- * @param {string} [options.titlePrefix] document title is `${titlePrefix}${route.title}`
27
- *
28
- * A route is a page function, or an object: `{ handler, title, auth: true, guestOnly: true, roles: ["admin"], guard(context) }`.
29
- * `auth`, `guestOnly` and `roles` are checked with options.auth; `guard` is a function that gets the same context and returns
30
- * false (stay where you are), a path (redirect) or anything else (go on); it runs after the rules.
31
- * @returns {{start: Function, stop: Function, navigate: Function, current: Function, href: Function,
32
- * onChange: (listener: (context) => void) => Function}}
33
- * `onChange(listener)` is called with the context after every page that is shown (menus and breadcrumbs follow the router
34
- * with it) and returns a function that stops it.
35
- */
36
- export function createRouter(options?: {
37
- routes: {
38
- [x: string]: Function | {
39
- handler: Function;
40
- title?: string;
41
- };
42
- };
43
- outlet?: string;
44
- mode?: "hash" | "history";
45
- notFound?: (context: any) => void;
46
- beforeEach?: (context: any) => (boolean | string | void | Promise<any>);
47
- afterEach?: (context: any) => void;
48
- onRender?: (context: any, route: any) => void;
49
- onShown?: (context: any, route: any) => void;
50
- focusContent?: boolean;
51
- scrollTop?: boolean;
52
- auth?: {
53
- isSignedIn?: () => boolean;
54
- hasRole?: (role: string) => boolean;
55
- loginPath?: string;
56
- homePath?: string;
57
- forbiddenPath?: string;
58
- };
59
- titlePrefix?: string;
60
- }): {
61
- start: Function;
62
- stop: Function;
63
- navigate: Function;
64
- current: Function;
65
- href: Function;
66
- onChange: (listener: (context: any) => void) => Function;
67
- };
1
+ /**
2
+ * Creates a router that renders a page function into an outlet element.
3
+ *
4
+ * @param {object} options
5
+ * @param {Object<string, Function|{handler: Function, title?: string}>} options.routes path pattern -> page
6
+ * function. Patterns support `:param` segments and a trailing `*`. A page function is called with
7
+ * `{ path, params, query }` after the outlet was emptied, and may return a promise.
8
+ * @param {string} [options.outlet="wrapper"] id of the element the pages are rendered into
9
+ * @param {"hash"|"history"} [options.mode="hash"] "history" needs the server to answer every path with the page
10
+ * @param {(context) => void} [options.notFound] called when no route matches
11
+ * @param {(context) => (boolean|string|void|Promise)} [options.beforeEach] guard: return false to cancel,
12
+ * or a path to redirect to (login redirect)
13
+ * @param {(context) => void} [options.afterEach] same as onShown
14
+ * @param {(context, route) => void} [options.onRender] called after the outlet was emptied, before the page function runs
15
+ * @param {(context, route) => void} [options.onShown] called after the page function finished (and it was not replaced by a newer
16
+ * navigation): the place to set the title, move the focus to the content, scroll to the top
17
+ * @param {boolean} [options.focusContent=false] after a page is shown the outlet gets the focus (it is made focusable for that), so a
18
+ * screen reader starts reading the new page and the keyboard continues there
19
+ * @param {boolean} [options.scrollTop=false] scroll to the top after a page is shown
20
+ * @param {boolean} [options.transition=false] a page change is a view transition (document.startViewTransition): the old page cross-fades into the new one,
21
+ * and elements with a `view-transition-name` move from one page to the next. Without the API, or under reduced motion, nothing changes. The old page
22
+ * stays on the screen until the page function of the new one is done, so pages that need long to build should draw something quickly.
23
+ * @param {object} [options.auth] sign-in rules for routes, see the route options below
24
+ * @param {() => boolean} [options.auth.isSignedIn]
25
+ * @param {(role: string) => boolean} [options.auth.hasRole]
26
+ * @param {string} [options.auth.loginPath="/login"] where `auth: true` routes send a visitor who is not signed in (with `?next=<path>`)
27
+ * @param {string} [options.auth.homePath="/"] where `guestOnly` routes send a signed-in person
28
+ * @param {string} [options.auth.forbiddenPath] where a person without the role goes (default: homePath)
29
+ * @param {string} [options.titlePrefix] document title is `${titlePrefix}${route.title}`
30
+ *
31
+ * A route is a page function, or an object: `{ handler, title, auth: true, guestOnly: true, roles: ["admin"], guard(context) }`.
32
+ * `auth`, `guestOnly` and `roles` are checked with options.auth; `guard` is a function that gets the same context and returns
33
+ * false (stay where you are), a path (redirect) or anything else (go on); it runs after the rules.
34
+ * @returns {{start: Function, stop: Function, navigate: Function, current: Function, href: Function,
35
+ * onChange: (listener: (context) => void) => Function}}
36
+ * `onChange(listener)` is called with the context after every page that is shown (menus and breadcrumbs follow the router
37
+ * with it) and returns a function that stops it.
38
+ */
39
+ export function createRouter(options?: {
40
+ routes: {
41
+ [x: string]: Function | {
42
+ handler: Function;
43
+ title?: string;
44
+ };
45
+ };
46
+ outlet?: string;
47
+ mode?: "hash" | "history";
48
+ notFound?: (context: any) => void;
49
+ beforeEach?: (context: any) => (boolean | string | void | Promise<any>);
50
+ afterEach?: (context: any) => void;
51
+ onRender?: (context: any, route: any) => void;
52
+ onShown?: (context: any, route: any) => void;
53
+ focusContent?: boolean;
54
+ scrollTop?: boolean;
55
+ transition?: boolean;
56
+ auth?: {
57
+ isSignedIn?: () => boolean;
58
+ hasRole?: (role: string) => boolean;
59
+ loginPath?: string;
60
+ homePath?: string;
61
+ forbiddenPath?: string;
62
+ };
63
+ titlePrefix?: string;
64
+ }): {
65
+ start: Function;
66
+ stop: Function;
67
+ navigate: Function;
68
+ current: Function;
69
+ href: Function;
70
+ onChange: (listener: (context: any) => void) => Function;
71
+ };