athena-ui-js 2.0.0 → 2.0.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/README.md +28 -4
- package/package.json +5 -2
- package/src/athena-ui.js +1 -1
- package/src/libs/config/config.js +1 -1
- package/src/libs/hephaestus/chartGenerator/chartGenerator.js +26 -2
- package/types/athena-ui.d.ts +96 -96
- package/types/chart.d.ts +1 -1
- package/types/classic.d.ts +1 -1
- package/types/components.d.ts +1 -1
- package/types/controls.d.ts +3 -3
- package/types/csv.d.ts +1 -1
- package/types/dialog.d.ts +2 -2
- package/types/dom.d.ts +1 -1
- package/types/feedback.d.ts +1 -1
- package/types/format.d.ts +1 -1
- package/types/forms.d.ts +2 -2
- package/types/i18n.d.ts +1 -1
- package/types/inputs.d.ts +4 -4
- package/types/libs/config/config.d.ts +3 -3
- package/types/libs/config/hooks.d.ts +8 -8
- package/types/libs/core/combobox.d.ts +10 -10
- package/types/libs/core/controls.d.ts +28 -28
- package/types/libs/core/cookies.d.ts +27 -27
- package/types/libs/core/csv.d.ts +12 -12
- package/types/libs/core/dateRange.d.ts +72 -72
- package/types/libs/core/dom.d.ts +65 -65
- package/types/libs/core/elementGenerator.d.ts +30 -30
- package/types/libs/core/errors.d.ts +29 -29
- package/types/libs/core/focus.d.ts +6 -6
- package/types/libs/core/format.d.ts +21 -21
- package/types/libs/core/hungarianControls.d.ts +2 -2
- package/types/libs/core/i18n.d.ts +17 -17
- package/types/libs/core/pagination.d.ts +5 -5
- package/types/libs/core/sanitize.d.ts +6 -6
- package/types/libs/core/tableMath.d.ts +26 -26
- package/types/libs/core/theme.d.ts +39 -39
- package/types/libs/core/validation.d.ts +56 -56
- package/types/libs/hephaestus/LayoutGenerator/basicLayoutGenerator.d.ts +10 -10
- package/types/libs/hephaestus/LayoutGenerator/footerContentGenerator.d.ts +4 -4
- package/types/libs/hephaestus/LayoutGenerator/headerContentGenerator.d.ts +20 -20
- package/types/libs/hephaestus/LayoutGenerator/wrapperContentGenerator.d.ts +1 -1
- package/types/libs/hephaestus/MenuGenerator/basicMenuGenerator.d.ts +14 -14
- package/types/libs/hephaestus/MenuGenerator/menuGenerator.d.ts +65 -65
- package/types/libs/hephaestus/auth/authState.d.ts +26 -26
- package/types/libs/hephaestus/auth/session.d.ts +26 -26
- package/types/libs/hephaestus/chartGenerator/chartGenerator.d.ts +2 -0
- package/types/libs/hephaestus/componentGenerator/componentGenerator.d.ts +222 -222
- package/types/libs/hephaestus/componentGenerator/themePicker.d.ts +24 -24
- package/types/libs/hephaestus/dialogGenerator/dialogGenerator.d.ts +120 -120
- package/types/libs/hephaestus/feedbackGenerator/feedbackGenerator.d.ts +86 -86
- package/types/libs/hephaestus/formGenerator/authForms.d.ts +122 -122
- package/types/libs/hephaestus/formGenerator/changePasswordFormGenerator.d.ts +6 -6
- package/types/libs/hephaestus/formGenerator/formBuilder.d.ts +113 -113
- package/types/libs/hephaestus/formGenerator/formUtils.d.ts +8 -8
- package/types/libs/hephaestus/formGenerator/loginFormGenerator.d.ts +11 -11
- package/types/libs/hephaestus/formGenerator/lostPasswordFormGenerator.d.ts +4 -4
- package/types/libs/hephaestus/formGenerator/registrationFormGenerator.d.ts +7 -7
- package/types/libs/hephaestus/hephaestus.d.ts +3 -3
- package/types/libs/hephaestus/inputGenerator/dropZoneGenerator.d.ts +48 -48
- package/types/libs/hephaestus/inputGenerator/inputGenerator.d.ts +185 -185
- package/types/libs/hephaestus/inputGenerator/richTextGenerator.d.ts +49 -49
- package/types/libs/hephaestus/modalGenerator/modalGenerator.d.ts +2 -2
- package/types/libs/hephaestus/navigationGenerator/navigationGenerator.d.ts +150 -150
- package/types/libs/hephaestus/router/matchRoute.d.ts +12 -12
- package/types/libs/hephaestus/router/router.d.ts +67 -67
- package/types/libs/hephaestus/tableGenerator/tableGenerator.d.ts +120 -120
- package/types/menu.d.ts +1 -1
- package/types/navigation.d.ts +1 -1
- package/types/res/themes/themes.d.ts +7 -7
- package/types/router.d.ts +1 -1
- package/types/sanitize.d.ts +1 -1
- package/types/session.d.ts +3 -3
- package/types/table.d.ts +1 -1
- package/types/testing.d.ts +27 -27
- package/types/theme.d.ts +2 -2
- package/types/validation.d.ts +1 -1
|
@@ -1,150 +1,150 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generates tabs. Arrow keys, Home and End move between the tabs.
|
|
3
|
-
*
|
|
4
|
-
* @param {object} options
|
|
5
|
-
* @param {string|Element} [options.parent]
|
|
6
|
-
* @param {string} [options.id]
|
|
7
|
-
* @param {{id: string, label: string, content: *, disabled?: boolean}[]} options.tabs content is text, a Node,
|
|
8
|
-
* an array, or a function called once when the tab is first shown (lazy content)
|
|
9
|
-
* @param {string} [options.active] id of the initially active tab (default: the first)
|
|
10
|
-
* @param {(id: string) => void} [options.onChange]
|
|
11
|
-
* @returns {{element: HTMLElement, select: (id: string) => void, getActive: () => string}}
|
|
12
|
-
*/
|
|
13
|
-
export function generateTabs(options?: {
|
|
14
|
-
parent?: string | Element;
|
|
15
|
-
id?: string;
|
|
16
|
-
tabs: {
|
|
17
|
-
id: string;
|
|
18
|
-
label: string;
|
|
19
|
-
content: any;
|
|
20
|
-
disabled?: boolean;
|
|
21
|
-
}[];
|
|
22
|
-
active?: string;
|
|
23
|
-
onChange?: (id: string) => void;
|
|
24
|
-
}): {
|
|
25
|
-
element: HTMLElement;
|
|
26
|
-
select: (id: string) => void;
|
|
27
|
-
getActive: () => string;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Generates breadcrumbs. The last item is the current page.
|
|
31
|
-
*
|
|
32
|
-
* @param {object} options
|
|
33
|
-
* @param {string|Element} [options.parent]
|
|
34
|
-
* @param {{label: string, href?: string, onclick?: Function}[]} options.items
|
|
35
|
-
*/
|
|
36
|
-
export function generateBreadcrumbs(options?: {
|
|
37
|
-
parent?: string | Element;
|
|
38
|
-
items: {
|
|
39
|
-
label: string;
|
|
40
|
-
href?: string;
|
|
41
|
-
onclick?: Function;
|
|
42
|
-
}[];
|
|
43
|
-
}): any;
|
|
44
|
-
/**
|
|
45
|
-
* Generates a page selector.
|
|
46
|
-
*
|
|
47
|
-
* @param {object} options
|
|
48
|
-
* @param {string|Element} [options.parent]
|
|
49
|
-
* @param {number} options.total number of items
|
|
50
|
-
* @param {number} [options.pageSize=10]
|
|
51
|
-
* @param {number} [options.page=1]
|
|
52
|
-
* @param {number} [options.siblings=1] page buttons shown next to the current page
|
|
53
|
-
* @param {(page: number) => void} [options.onChange]
|
|
54
|
-
* @returns {{element: HTMLElement, setPage: Function, setTotal: Function, getPage: Function}}
|
|
55
|
-
*/
|
|
56
|
-
export function generatePagination(options?: {
|
|
57
|
-
parent?: string | Element;
|
|
58
|
-
total: number;
|
|
59
|
-
pageSize?: number;
|
|
60
|
-
page?: number;
|
|
61
|
-
siblings?: number;
|
|
62
|
-
onChange?: (page: number) => void;
|
|
63
|
-
}): {
|
|
64
|
-
element: HTMLElement;
|
|
65
|
-
setPage: Function;
|
|
66
|
-
setTotal: Function;
|
|
67
|
-
getPage: Function;
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* Generates collapsible panels.
|
|
71
|
-
*
|
|
72
|
-
* @param {object} options
|
|
73
|
-
* @param {string|Element} [options.parent]
|
|
74
|
-
* @param {{id?: string, title: string, content: *, open?: boolean}[]} options.items
|
|
75
|
-
* @param {boolean} [options.multiple=false] allow several panels to be open at once
|
|
76
|
-
* @returns {{element: HTMLElement, toggle: (index: number, open?: boolean) => void}}
|
|
77
|
-
*/
|
|
78
|
-
export function generateAccordion(options?: {
|
|
79
|
-
parent?: string | Element;
|
|
80
|
-
items: {
|
|
81
|
-
id?: string;
|
|
82
|
-
title: string;
|
|
83
|
-
content: any;
|
|
84
|
-
open?: boolean;
|
|
85
|
-
}[];
|
|
86
|
-
multiple?: boolean;
|
|
87
|
-
}): {
|
|
88
|
-
element: HTMLElement;
|
|
89
|
-
toggle: (index: number, open?: boolean) => void;
|
|
90
|
-
};
|
|
91
|
-
/**
|
|
92
|
-
* Generates a button that opens a menu. Arrow keys move through the items, Esc closes it.
|
|
93
|
-
*
|
|
94
|
-
* @param {object} options
|
|
95
|
-
* @param {string|Element} [options.parent]
|
|
96
|
-
* @param {string} [options.label] button text (leave it out for an icon-only button, and give `ariaLabel`)
|
|
97
|
-
* @param {string|Node} [options.icon] shown before the label, text or a Node (e.g. an SVG); hidden from screen readers
|
|
98
|
-
* @param {string} [options.ariaLabel] accessible name, needed when there is no label
|
|
99
|
-
* @param {boolean} [options.caret=false] show a small arrow after the label
|
|
100
|
-
* @param {string} [options.toggleClass] extra CSS class(es) of the toggle button
|
|
101
|
-
* @param {{label?: string, onclick?: Function, href?: string, disabled?: boolean, divider?: boolean}[]} options.items
|
|
102
|
-
* @param {"left"|"right"} [options.align="left"]
|
|
103
|
-
* @returns {{element: HTMLElement, open: Function, close: Function}}
|
|
104
|
-
*/
|
|
105
|
-
export function generateDropdown(options?: {
|
|
106
|
-
parent?: string | Element;
|
|
107
|
-
label?: string;
|
|
108
|
-
icon?: string | Node;
|
|
109
|
-
ariaLabel?: string;
|
|
110
|
-
caret?: boolean;
|
|
111
|
-
toggleClass?: string;
|
|
112
|
-
items: {
|
|
113
|
-
label?: string;
|
|
114
|
-
onclick?: Function;
|
|
115
|
-
href?: string;
|
|
116
|
-
disabled?: boolean;
|
|
117
|
-
divider?: boolean;
|
|
118
|
-
}[];
|
|
119
|
-
align?: "left" | "right";
|
|
120
|
-
}): {
|
|
121
|
-
element: HTMLElement;
|
|
122
|
-
open: Function;
|
|
123
|
-
close: Function;
|
|
124
|
-
};
|
|
125
|
-
/**
|
|
126
|
-
* Generates a vertical navigation with nested items. On small screens it collapses behind a toggle button.
|
|
127
|
-
*
|
|
128
|
-
* @param {object} options
|
|
129
|
-
* @param {string|Element} [options.parent]
|
|
130
|
-
* @param {{id: string, label: string, icon?: string, href?: string, children?: object[]}[]} options.items
|
|
131
|
-
* @param {(item: object) => void} [options.onSelect]
|
|
132
|
-
* @param {string} [options.active] id of the initially selected item
|
|
133
|
-
* @returns {{element: HTMLElement, select: (id: string) => void, toggle: Function}}
|
|
134
|
-
*/
|
|
135
|
-
export function generateSidebar(options?: {
|
|
136
|
-
parent?: string | Element;
|
|
137
|
-
items: {
|
|
138
|
-
id: string;
|
|
139
|
-
label: string;
|
|
140
|
-
icon?: string;
|
|
141
|
-
href?: string;
|
|
142
|
-
children?: object[];
|
|
143
|
-
}[];
|
|
144
|
-
onSelect?: (item: object) => void;
|
|
145
|
-
active?: string;
|
|
146
|
-
}): {
|
|
147
|
-
element: HTMLElement;
|
|
148
|
-
select: (id: string) => void;
|
|
149
|
-
toggle: Function;
|
|
150
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* Generates tabs. Arrow keys, Home and End move between the tabs.
|
|
3
|
+
*
|
|
4
|
+
* @param {object} options
|
|
5
|
+
* @param {string|Element} [options.parent]
|
|
6
|
+
* @param {string} [options.id]
|
|
7
|
+
* @param {{id: string, label: string, content: *, disabled?: boolean}[]} options.tabs content is text, a Node,
|
|
8
|
+
* an array, or a function called once when the tab is first shown (lazy content)
|
|
9
|
+
* @param {string} [options.active] id of the initially active tab (default: the first)
|
|
10
|
+
* @param {(id: string) => void} [options.onChange]
|
|
11
|
+
* @returns {{element: HTMLElement, select: (id: string) => void, getActive: () => string}}
|
|
12
|
+
*/
|
|
13
|
+
export function generateTabs(options?: {
|
|
14
|
+
parent?: string | Element;
|
|
15
|
+
id?: string;
|
|
16
|
+
tabs: {
|
|
17
|
+
id: string;
|
|
18
|
+
label: string;
|
|
19
|
+
content: any;
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
}[];
|
|
22
|
+
active?: string;
|
|
23
|
+
onChange?: (id: string) => void;
|
|
24
|
+
}): {
|
|
25
|
+
element: HTMLElement;
|
|
26
|
+
select: (id: string) => void;
|
|
27
|
+
getActive: () => string;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Generates breadcrumbs. The last item is the current page.
|
|
31
|
+
*
|
|
32
|
+
* @param {object} options
|
|
33
|
+
* @param {string|Element} [options.parent]
|
|
34
|
+
* @param {{label: string, href?: string, onclick?: Function}[]} options.items
|
|
35
|
+
*/
|
|
36
|
+
export function generateBreadcrumbs(options?: {
|
|
37
|
+
parent?: string | Element;
|
|
38
|
+
items: {
|
|
39
|
+
label: string;
|
|
40
|
+
href?: string;
|
|
41
|
+
onclick?: Function;
|
|
42
|
+
}[];
|
|
43
|
+
}): any;
|
|
44
|
+
/**
|
|
45
|
+
* Generates a page selector.
|
|
46
|
+
*
|
|
47
|
+
* @param {object} options
|
|
48
|
+
* @param {string|Element} [options.parent]
|
|
49
|
+
* @param {number} options.total number of items
|
|
50
|
+
* @param {number} [options.pageSize=10]
|
|
51
|
+
* @param {number} [options.page=1]
|
|
52
|
+
* @param {number} [options.siblings=1] page buttons shown next to the current page
|
|
53
|
+
* @param {(page: number) => void} [options.onChange]
|
|
54
|
+
* @returns {{element: HTMLElement, setPage: Function, setTotal: Function, getPage: Function}}
|
|
55
|
+
*/
|
|
56
|
+
export function generatePagination(options?: {
|
|
57
|
+
parent?: string | Element;
|
|
58
|
+
total: number;
|
|
59
|
+
pageSize?: number;
|
|
60
|
+
page?: number;
|
|
61
|
+
siblings?: number;
|
|
62
|
+
onChange?: (page: number) => void;
|
|
63
|
+
}): {
|
|
64
|
+
element: HTMLElement;
|
|
65
|
+
setPage: Function;
|
|
66
|
+
setTotal: Function;
|
|
67
|
+
getPage: Function;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Generates collapsible panels.
|
|
71
|
+
*
|
|
72
|
+
* @param {object} options
|
|
73
|
+
* @param {string|Element} [options.parent]
|
|
74
|
+
* @param {{id?: string, title: string, content: *, open?: boolean}[]} options.items
|
|
75
|
+
* @param {boolean} [options.multiple=false] allow several panels to be open at once
|
|
76
|
+
* @returns {{element: HTMLElement, toggle: (index: number, open?: boolean) => void}}
|
|
77
|
+
*/
|
|
78
|
+
export function generateAccordion(options?: {
|
|
79
|
+
parent?: string | Element;
|
|
80
|
+
items: {
|
|
81
|
+
id?: string;
|
|
82
|
+
title: string;
|
|
83
|
+
content: any;
|
|
84
|
+
open?: boolean;
|
|
85
|
+
}[];
|
|
86
|
+
multiple?: boolean;
|
|
87
|
+
}): {
|
|
88
|
+
element: HTMLElement;
|
|
89
|
+
toggle: (index: number, open?: boolean) => void;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Generates a button that opens a menu. Arrow keys move through the items, Esc closes it.
|
|
93
|
+
*
|
|
94
|
+
* @param {object} options
|
|
95
|
+
* @param {string|Element} [options.parent]
|
|
96
|
+
* @param {string} [options.label] button text (leave it out for an icon-only button, and give `ariaLabel`)
|
|
97
|
+
* @param {string|Node} [options.icon] shown before the label, text or a Node (e.g. an SVG); hidden from screen readers
|
|
98
|
+
* @param {string} [options.ariaLabel] accessible name, needed when there is no label
|
|
99
|
+
* @param {boolean} [options.caret=false] show a small arrow after the label
|
|
100
|
+
* @param {string} [options.toggleClass] extra CSS class(es) of the toggle button
|
|
101
|
+
* @param {{label?: string, onclick?: Function, href?: string, disabled?: boolean, divider?: boolean}[]} options.items
|
|
102
|
+
* @param {"left"|"right"} [options.align="left"]
|
|
103
|
+
* @returns {{element: HTMLElement, open: Function, close: Function}}
|
|
104
|
+
*/
|
|
105
|
+
export function generateDropdown(options?: {
|
|
106
|
+
parent?: string | Element;
|
|
107
|
+
label?: string;
|
|
108
|
+
icon?: string | Node;
|
|
109
|
+
ariaLabel?: string;
|
|
110
|
+
caret?: boolean;
|
|
111
|
+
toggleClass?: string;
|
|
112
|
+
items: {
|
|
113
|
+
label?: string;
|
|
114
|
+
onclick?: Function;
|
|
115
|
+
href?: string;
|
|
116
|
+
disabled?: boolean;
|
|
117
|
+
divider?: boolean;
|
|
118
|
+
}[];
|
|
119
|
+
align?: "left" | "right";
|
|
120
|
+
}): {
|
|
121
|
+
element: HTMLElement;
|
|
122
|
+
open: Function;
|
|
123
|
+
close: Function;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Generates a vertical navigation with nested items. On small screens it collapses behind a toggle button.
|
|
127
|
+
*
|
|
128
|
+
* @param {object} options
|
|
129
|
+
* @param {string|Element} [options.parent]
|
|
130
|
+
* @param {{id: string, label: string, icon?: string, href?: string, children?: object[]}[]} options.items
|
|
131
|
+
* @param {(item: object) => void} [options.onSelect]
|
|
132
|
+
* @param {string} [options.active] id of the initially selected item
|
|
133
|
+
* @returns {{element: HTMLElement, select: (id: string) => void, toggle: Function}}
|
|
134
|
+
*/
|
|
135
|
+
export function generateSidebar(options?: {
|
|
136
|
+
parent?: string | Element;
|
|
137
|
+
items: {
|
|
138
|
+
id: string;
|
|
139
|
+
label: string;
|
|
140
|
+
icon?: string;
|
|
141
|
+
href?: string;
|
|
142
|
+
children?: object[];
|
|
143
|
+
}[];
|
|
144
|
+
onSelect?: (item: object) => void;
|
|
145
|
+
active?: string;
|
|
146
|
+
}): {
|
|
147
|
+
element: HTMLElement;
|
|
148
|
+
select: (id: string) => void;
|
|
149
|
+
toggle: Function;
|
|
150
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export function normalizePath(path: any): string;
|
|
2
|
-
export function parseQuery(search: any): {
|
|
3
|
-
[k: string]: string;
|
|
4
|
-
};
|
|
5
|
-
/**
|
|
6
|
-
* Matches a path against a pattern. `:name` segments capture a value, a trailing `*` matches the rest.
|
|
7
|
-
*
|
|
8
|
-
* @returns {Object<string, string>|null} the captured params, or null when the path does not match
|
|
9
|
-
*/
|
|
10
|
-
export function matchRoute(pattern: any, path: any): {
|
|
11
|
-
[x: string]: string;
|
|
12
|
-
} | null;
|
|
1
|
+
export function normalizePath(path: any): string;
|
|
2
|
+
export function parseQuery(search: any): {
|
|
3
|
+
[k: string]: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Matches a path against a pattern. `:name` segments capture a value, a trailing `*` matches the rest.
|
|
7
|
+
*
|
|
8
|
+
* @returns {Object<string, string>|null} the captured params, or null when the path does not match
|
|
9
|
+
*/
|
|
10
|
+
export function matchRoute(pattern: any, path: any): {
|
|
11
|
+
[x: string]: string;
|
|
12
|
+
} | null;
|
|
@@ -1,67 +1,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 {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 {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
|
+
};
|