athena-ui-js 1.2.0 → 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/README.md +312 -60
- package/docs/migration-2.0.md +83 -0
- package/docs/styling.md +86 -0
- package/package.json +109 -24
- package/src/athena-ui.js +61 -81
- package/src/chart.js +6 -0
- package/src/classic.js +11 -0
- package/src/components.js +6 -0
- package/src/controls.js +8 -0
- package/src/csv.js +6 -0
- package/src/dialog.js +7 -0
- package/src/dom.js +6 -0
- package/src/feedback.js +6 -0
- package/src/format.js +6 -0
- package/src/forms.js +7 -0
- package/src/i18n.js +6 -0
- package/src/inputs.js +9 -0
- package/src/libs/config/config.js +1 -2
- package/src/libs/core/controls.js +145 -0
- package/src/libs/core/cookies.js +55 -0
- package/src/libs/core/dateRange.js +121 -0
- package/src/libs/core/dom.js +58 -8
- package/src/libs/{hephaestus/HTMLElementGenerator/src/HTMLElementGenerator.js → core/elementGenerator.js} +23 -21
- package/src/libs/{hephaestus/HTMLElementGenerator/src → core}/errors.js +7 -5
- package/src/libs/core/format.js +51 -0
- package/src/libs/core/hungarianControls.js +41 -0
- package/src/libs/core/i18n.js +104 -6
- package/src/libs/core/theme.js +131 -0
- package/src/libs/core/validation.js +2 -2
- package/src/libs/hephaestus/LayoutGenerator/basicLayoutGenerator.js +13 -7
- package/src/libs/hephaestus/LayoutGenerator/footerContentGenerator.js +2 -4
- package/src/libs/hephaestus/LayoutGenerator/headerContentGenerator.js +12 -5
- package/src/libs/hephaestus/MenuGenerator/basicMenuGenerator.js +3 -3
- package/src/libs/hephaestus/MenuGenerator/menuGenerator.js +265 -0
- package/src/libs/hephaestus/auth/authState.js +58 -0
- package/src/libs/hephaestus/auth/session.js +1 -1
- package/src/libs/hephaestus/chartGenerator/chartGenerator.js +519 -87
- package/src/libs/hephaestus/componentGenerator/componentGenerator.js +121 -4
- package/src/libs/hephaestus/componentGenerator/themePicker.js +73 -0
- package/src/libs/hephaestus/dialogGenerator/dialogGenerator.js +113 -25
- package/src/libs/hephaestus/feedbackGenerator/feedbackGenerator.js +21 -0
- package/src/libs/hephaestus/formGenerator/authForms.js +130 -0
- package/src/libs/hephaestus/formGenerator/changePasswordFormGenerator.js +4 -4
- package/src/libs/hephaestus/formGenerator/formUtils.js +10 -13
- package/src/libs/hephaestus/formGenerator/loginFormGenerator.js +10 -11
- package/src/libs/hephaestus/formGenerator/registrationFormGenerator.js +3 -3
- package/src/libs/hephaestus/hephaestus.js +0 -5
- package/src/libs/hephaestus/inputGenerator/dropZoneGenerator.js +1 -1
- package/src/libs/hephaestus/inputGenerator/inputGenerator.js +30 -1
- package/src/libs/hephaestus/modalGenerator/modalGenerator.js +25 -12
- package/src/libs/hephaestus/navigationGenerator/navigationGenerator.js +20 -24
- package/src/libs/hephaestus/router/router.js +54 -5
- package/src/libs/hephaestus/tableGenerator/tableGenerator.js +290 -16
- package/src/menu.js +6 -0
- package/src/navigation.js +6 -0
- package/src/res/themes/appearance.css +154 -0
- package/src/res/themes/default/style.css +688 -82
- package/src/res/themes/tokens.css +96 -0
- package/src/router.js +6 -0
- package/src/sanitize.js +6 -0
- package/src/session.js +8 -0
- package/src/table.js +6 -0
- package/src/testing.js +11 -1
- package/src/theme-boot.js +25 -0
- package/src/theme.js +7 -0
- package/src/validation.js +6 -0
- package/types/athena-ui.d.ts +96 -0
- package/types/chart.d.ts +1 -0
- package/types/classic.d.ts +1 -0
- package/types/components.d.ts +1 -0
- package/types/controls.d.ts +3 -0
- package/types/csv.d.ts +1 -0
- package/types/dialog.d.ts +2 -0
- package/types/dom.d.ts +1 -0
- package/types/feedback.d.ts +1 -0
- package/types/format.d.ts +1 -0
- package/types/forms.d.ts +2 -0
- package/types/i18n.d.ts +1 -0
- package/types/inputs.d.ts +4 -0
- package/types/libs/config/config.d.ts +96 -0
- package/types/libs/config/hooks.d.ts +8 -0
- package/types/libs/core/combobox.d.ts +10 -0
- package/types/libs/core/controls.d.ts +28 -0
- package/types/libs/core/cookies.d.ts +27 -0
- package/types/libs/core/csv.d.ts +12 -0
- package/types/libs/core/dateRange.d.ts +72 -0
- package/types/libs/core/dom.d.ts +65 -0
- package/types/libs/core/elementGenerator.d.ts +30 -0
- package/types/libs/core/errors.d.ts +29 -0
- package/types/libs/core/focus.d.ts +6 -0
- package/types/libs/core/format.d.ts +21 -0
- package/types/libs/core/hungarianControls.d.ts +2 -0
- package/types/libs/core/i18n.d.ts +17 -0
- package/types/libs/core/pagination.d.ts +5 -0
- package/types/libs/core/sanitize.d.ts +6 -0
- package/types/libs/core/tableMath.d.ts +26 -0
- package/types/libs/core/theme.d.ts +39 -0
- package/types/libs/core/validation.d.ts +56 -0
- package/types/libs/hephaestus/LayoutGenerator/basicLayoutGenerator.d.ts +10 -0
- package/types/libs/hephaestus/LayoutGenerator/footerContentGenerator.d.ts +4 -0
- package/types/libs/hephaestus/LayoutGenerator/headerContentGenerator.d.ts +20 -0
- package/types/libs/hephaestus/LayoutGenerator/wrapperContentGenerator.d.ts +1 -0
- package/types/libs/hephaestus/MenuGenerator/basicMenuGenerator.d.ts +14 -0
- package/types/libs/hephaestus/MenuGenerator/menuGenerator.d.ts +65 -0
- package/types/libs/hephaestus/auth/authState.d.ts +26 -0
- package/types/libs/hephaestus/auth/session.d.ts +26 -0
- package/types/libs/hephaestus/chartGenerator/chartGenerator.d.ts +91 -0
- package/types/libs/hephaestus/componentGenerator/componentGenerator.d.ts +222 -0
- package/types/libs/hephaestus/componentGenerator/themePicker.d.ts +24 -0
- package/types/libs/hephaestus/dialogGenerator/dialogGenerator.d.ts +120 -0
- package/types/libs/hephaestus/feedbackGenerator/feedbackGenerator.d.ts +86 -0
- package/types/libs/hephaestus/formGenerator/authForms.d.ts +122 -0
- package/types/libs/hephaestus/formGenerator/changePasswordFormGenerator.d.ts +6 -0
- package/types/libs/hephaestus/formGenerator/formBuilder.d.ts +113 -0
- package/types/libs/hephaestus/formGenerator/formUtils.d.ts +8 -0
- package/types/libs/hephaestus/formGenerator/loginFormGenerator.d.ts +11 -0
- package/types/libs/hephaestus/formGenerator/lostPasswordFormGenerator.d.ts +4 -0
- package/types/libs/hephaestus/formGenerator/registrationFormGenerator.d.ts +7 -0
- package/types/libs/hephaestus/hephaestus.d.ts +3 -0
- package/types/libs/hephaestus/inputGenerator/dropZoneGenerator.d.ts +48 -0
- package/types/libs/hephaestus/inputGenerator/inputGenerator.d.ts +185 -0
- package/types/libs/hephaestus/inputGenerator/richTextGenerator.d.ts +49 -0
- package/types/libs/hephaestus/modalGenerator/modalGenerator.d.ts +2 -0
- package/types/libs/hephaestus/navigationGenerator/navigationGenerator.d.ts +150 -0
- package/types/libs/hephaestus/router/matchRoute.d.ts +12 -0
- package/types/libs/hephaestus/router/router.d.ts +67 -0
- package/types/libs/hephaestus/tableGenerator/tableGenerator.d.ts +120 -0
- package/types/menu.d.ts +1 -0
- package/types/navigation.d.ts +1 -0
- package/types/res/themes/themes.d.ts +7 -0
- package/types/router.d.ts +1 -0
- package/types/sanitize.d.ts +1 -0
- package/types/session.d.ts +3 -0
- package/types/table.d.ts +1 -0
- package/types/testing.d.ts +27 -0
- package/types/theme-boot.d.ts +0 -0
- package/types/theme.d.ts +2 -0
- package/types/validation.d.ts +1 -0
- package/src/libs/crypto-js/LICENSE +0 -24
- package/src/libs/crypto-js/crypto-js.js +0 -6657
- package/src/libs/hephaestus/HTMLControlGenerator/LICENSE +0 -21
- package/src/libs/hephaestus/HTMLControlGenerator/src/HTMLControlGenerator.min.js +0 -5
- package/src/libs/hephaestus/HTMLElementGenerator/LICENSE +0 -21
- package/src/libs/js-cookie/LICENSE +0 -21
- package/src/libs/js-cookie/src/api.mjs +0 -103
- package/src/libs/js-cookie/src/assign.mjs +0 -10
- package/src/libs/js-cookie/src/converter.mjs +0 -14
- package/src/libs/libs.js +0 -13
|
@@ -0,0 +1,222 @@
|
|
|
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;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates the appearance picker of an account page: a group of themes with a small preview of each, and a group of modes.
|
|
3
|
+
* The preview is drawn with the colours of the theme itself: the stylesheet of a theme applies to any element that has the
|
|
4
|
+
* attributes data-theme and data-mode, not only to <html>.
|
|
5
|
+
*
|
|
6
|
+
* @param {object} options
|
|
7
|
+
* @param {string|Element} [options.parent]
|
|
8
|
+
* @param {ReturnType<import("../../core/theme.js").createThemeManager>} options.manager
|
|
9
|
+
* @param {string} [options.themeLabel] legend of the theme group (default: translated "Theme")
|
|
10
|
+
* @param {string} [options.modeLabel] legend of the mode group (default: translated "Mode")
|
|
11
|
+
* @param {string} [options.class]
|
|
12
|
+
* @returns {{element: HTMLElement, update: Function, destroy: Function}}
|
|
13
|
+
*/
|
|
14
|
+
export function generateThemePicker(options?: {
|
|
15
|
+
parent?: string | Element;
|
|
16
|
+
manager: ReturnType<typeof import("../../core/theme.js").createThemeManager>;
|
|
17
|
+
themeLabel?: string;
|
|
18
|
+
modeLabel?: string;
|
|
19
|
+
class?: string;
|
|
20
|
+
}): {
|
|
21
|
+
element: HTMLElement;
|
|
22
|
+
update: Function;
|
|
23
|
+
destroy: Function;
|
|
24
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opens a dialog and resolves with the value of the button that was used,
|
|
3
|
+
* or with `null` when it was dismissed (Esc, the close button, a click on the backdrop).
|
|
4
|
+
*
|
|
5
|
+
* @param {object} options
|
|
6
|
+
* @param {string} [options.title]
|
|
7
|
+
* @param {string|Node|Array} [options.content] text is inserted as text, never as HTML
|
|
8
|
+
* @param {{text: string, value?: *, variant?: string, autofocus?: boolean}[]} [options.buttons]
|
|
9
|
+
* @param {boolean} [options.dismissible=true]
|
|
10
|
+
* @param {(value) => (boolean|Promise<boolean>)} [options.beforeClose] return false to keep the dialog open
|
|
11
|
+
* @param {"small"|"medium"|"large"|"full"} [options.size="medium"] width of the dialog (360 / 480 / 720 px / the whole window)
|
|
12
|
+
* @param {string} [options.class] extra CSS class(es) of the dialog element
|
|
13
|
+
* @returns {Promise<*> & {element: HTMLDialogElement, backdrop: HTMLDialogElement, close: (value?) => Promise<void>}}
|
|
14
|
+
* resolves with the pressed button's value; the promise also carries the handle of the open dialog
|
|
15
|
+
*/
|
|
16
|
+
export function showDialog(options?: {
|
|
17
|
+
title?: string;
|
|
18
|
+
content?: string | Node | any[];
|
|
19
|
+
buttons?: {
|
|
20
|
+
text: string;
|
|
21
|
+
value?: any;
|
|
22
|
+
variant?: string;
|
|
23
|
+
autofocus?: boolean;
|
|
24
|
+
}[];
|
|
25
|
+
dismissible?: boolean;
|
|
26
|
+
beforeClose?: (value: any) => (boolean | Promise<boolean>);
|
|
27
|
+
size?: "small" | "medium" | "large" | "full";
|
|
28
|
+
class?: string;
|
|
29
|
+
}): Promise<any> & {
|
|
30
|
+
element: HTMLDialogElement;
|
|
31
|
+
backdrop: HTMLDialogElement;
|
|
32
|
+
close: (value?: any) => Promise<void>;
|
|
33
|
+
};
|
|
34
|
+
/** Message with an OK button. Resolves when it is closed. */
|
|
35
|
+
export function alertDialog(message: any, { title, okText }?: {
|
|
36
|
+
okText?: any;
|
|
37
|
+
}): Promise<void>;
|
|
38
|
+
/** Question with confirm and cancel buttons. Resolves with true / false. See showConfirm for `typeToConfirm`. */
|
|
39
|
+
export function confirmDialog(message: any, options?: {}): Promise<boolean> & {
|
|
40
|
+
element: HTMLElement;
|
|
41
|
+
close: Function;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Asks for a confirmation. Resolves with true when confirmed, false when cancelled or dismissed.
|
|
45
|
+
*
|
|
46
|
+
* @param {object} options
|
|
47
|
+
* @param {string} [options.title]
|
|
48
|
+
* @param {string|Node|Array} options.message
|
|
49
|
+
* @param {string} [options.confirmText]
|
|
50
|
+
* @param {string} [options.cancelText]
|
|
51
|
+
* @param {boolean} [options.danger=false] red confirm button
|
|
52
|
+
* @param {string} [options.typeToConfirm] the person has to type exactly this text before the dialog confirms
|
|
53
|
+
* (for things that cannot be undone: the name of what is deleted)
|
|
54
|
+
* @param {"small"|"medium"|"large"|"full"} [options.size]
|
|
55
|
+
* @returns {Promise<boolean> & {element: HTMLElement, close: Function}}
|
|
56
|
+
*/
|
|
57
|
+
export function showConfirm({ title, message, confirmText, cancelText, danger, typeToConfirm, size }?: {
|
|
58
|
+
title?: string;
|
|
59
|
+
message: string | Node | any[];
|
|
60
|
+
confirmText?: string;
|
|
61
|
+
cancelText?: string;
|
|
62
|
+
danger?: boolean;
|
|
63
|
+
typeToConfirm?: string;
|
|
64
|
+
size?: "small" | "medium" | "large" | "full";
|
|
65
|
+
}): Promise<boolean> & {
|
|
66
|
+
element: HTMLElement;
|
|
67
|
+
close: Function;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* A dialog that holds a form (see generateForm): validation, Enter submits, the button shows a spinner while it saves.
|
|
71
|
+
* `onSubmit(values, form)` saves. When it throws (or rejects) the message is shown in the dialog and the dialog stays open;
|
|
72
|
+
* `form.setErrors({ field: "message" })` marks single fields, for example with errors of the server. When it returns, the dialog closes.
|
|
73
|
+
*
|
|
74
|
+
* @param {object} options
|
|
75
|
+
* @param {string} [options.title]
|
|
76
|
+
* @param {string} [options.intro] text above the fields
|
|
77
|
+
* @param {string|Node|Array} [options.content] nodes above the fields
|
|
78
|
+
* @param {object[]} options.fields field definitions, see generateField
|
|
79
|
+
* @param {string} [options.submitText]
|
|
80
|
+
* @param {string} [options.cancelText]
|
|
81
|
+
* @param {boolean} [options.danger=false] red submit button
|
|
82
|
+
* @param {"small"|"medium"|"large"|"full"} [options.size]
|
|
83
|
+
* @param {(values: object, form: object) => (void|Promise)} options.onSubmit
|
|
84
|
+
* @param {(form: object) => void} [options.onReady] called with the form once it is built
|
|
85
|
+
* @returns {Promise<boolean> & {element: HTMLElement, form: object, close: Function}} resolves with true when it was saved, false when dismissed
|
|
86
|
+
*/
|
|
87
|
+
export function showFormDialog({ title, intro, content, fields, submitText, cancelText, danger, size, onSubmit, onReady }?: {
|
|
88
|
+
title?: string;
|
|
89
|
+
intro?: string;
|
|
90
|
+
content?: string | Node | any[];
|
|
91
|
+
fields: object[];
|
|
92
|
+
submitText?: string;
|
|
93
|
+
cancelText?: string;
|
|
94
|
+
danger?: boolean;
|
|
95
|
+
size?: "small" | "medium" | "large" | "full";
|
|
96
|
+
onSubmit: (values: object, form: object) => (void | Promise<any>);
|
|
97
|
+
onReady?: (form: object) => void;
|
|
98
|
+
}): Promise<boolean> & {
|
|
99
|
+
element: HTMLElement;
|
|
100
|
+
form: object;
|
|
101
|
+
close: Function;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Asks for a text value. Resolves with the entered text, or null when cancelled.
|
|
105
|
+
*
|
|
106
|
+
* @param {string} message
|
|
107
|
+
* @param {object} [options]
|
|
108
|
+
* @param {string} [options.title]
|
|
109
|
+
* @param {string} [options.value] initial value
|
|
110
|
+
* @param {string} [options.placeholder]
|
|
111
|
+
* @param {string} [options.type="text"] input type
|
|
112
|
+
* @param {(value: string) => string} [options.validate] returns an error text, or "" when valid
|
|
113
|
+
*/
|
|
114
|
+
export function promptDialog(message: string, { title, value, placeholder, type, validate, okText, cancelText }?: {
|
|
115
|
+
title?: string;
|
|
116
|
+
value?: string;
|
|
117
|
+
placeholder?: string;
|
|
118
|
+
type?: string;
|
|
119
|
+
validate?: (value: string) => string;
|
|
120
|
+
}): Promise<any>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shows a toast notification in the corner of the page.
|
|
3
|
+
*
|
|
4
|
+
* @param {object|string} options a message, or an options object
|
|
5
|
+
* @param {string} options.message
|
|
6
|
+
* @param {string} [options.title]
|
|
7
|
+
* @param {"info"|"success"|"warning"|"error"} [options.type="info"]
|
|
8
|
+
* @param {number} [options.duration=4000] ms before it disappears, 0 keeps it until it is closed
|
|
9
|
+
* @returns {{close: Function}}
|
|
10
|
+
*/
|
|
11
|
+
export function showToast(options: object | string): {
|
|
12
|
+
close: Function;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Generates an inline alert box.
|
|
16
|
+
*
|
|
17
|
+
* @param {object} options
|
|
18
|
+
* @param {string|Element} [options.parent]
|
|
19
|
+
* @param {string} [options.id]
|
|
20
|
+
* @param {string|Node} options.message
|
|
21
|
+
* @param {string} [options.title]
|
|
22
|
+
* @param {"info"|"success"|"warning"|"error"} [options.type="info"]
|
|
23
|
+
* @param {boolean} [options.dismissible]
|
|
24
|
+
* @returns {HTMLElement}
|
|
25
|
+
*/
|
|
26
|
+
export function generateAlert(options?: {
|
|
27
|
+
parent?: string | Element;
|
|
28
|
+
id?: string;
|
|
29
|
+
message: string | Node;
|
|
30
|
+
title?: string;
|
|
31
|
+
type?: "info" | "success" | "warning" | "error";
|
|
32
|
+
dismissible?: boolean;
|
|
33
|
+
}): HTMLElement;
|
|
34
|
+
/**
|
|
35
|
+
* Copies text to the clipboard and says so in a toast. Resolves with true when it worked (it needs a secure page and a click or key
|
|
36
|
+
* press of the person), false otherwise (a toast with the error is shown).
|
|
37
|
+
*
|
|
38
|
+
* @param {string} text
|
|
39
|
+
* @param {object} [options]
|
|
40
|
+
* @param {string} [options.message] text of the toast (default: the translated "Copied")
|
|
41
|
+
* @param {boolean} [options.toast=true] false copies silently
|
|
42
|
+
* @returns {Promise<boolean>}
|
|
43
|
+
*/
|
|
44
|
+
export function copyToClipboard(text: string, { message, toast }?: {
|
|
45
|
+
message?: string;
|
|
46
|
+
toast?: boolean;
|
|
47
|
+
}): Promise<boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* Generates a loading spinner.
|
|
50
|
+
*
|
|
51
|
+
* @param {object} [options]
|
|
52
|
+
* @param {string|Element} [options.parent]
|
|
53
|
+
* @param {string} [options.id]
|
|
54
|
+
* @param {"small"|"large"} [options.size]
|
|
55
|
+
* @param {string} [options.label] accessible text, defaults to the translated "Loading..."
|
|
56
|
+
* @returns {HTMLElement}
|
|
57
|
+
*/
|
|
58
|
+
export function generateSpinner(options?: {
|
|
59
|
+
parent?: string | Element;
|
|
60
|
+
id?: string;
|
|
61
|
+
size?: "small" | "large";
|
|
62
|
+
label?: string;
|
|
63
|
+
}): HTMLElement;
|
|
64
|
+
/**
|
|
65
|
+
* Generates a progress bar. Without a value it is indeterminate.
|
|
66
|
+
*
|
|
67
|
+
* @param {object} [options]
|
|
68
|
+
* @param {string|Element} [options.parent]
|
|
69
|
+
* @param {string} [options.id]
|
|
70
|
+
* @param {number} [options.value] 0..max
|
|
71
|
+
* @param {number} [options.max=100]
|
|
72
|
+
* @param {string} [options.label] text shown above the bar
|
|
73
|
+
* @param {"info"|"success"|"warning"|"error"} [options.type]
|
|
74
|
+
* @returns {{element: HTMLElement, setValue: (value: number) => void}}
|
|
75
|
+
*/
|
|
76
|
+
export function generateProgress(options?: {
|
|
77
|
+
parent?: string | Element;
|
|
78
|
+
id?: string;
|
|
79
|
+
value?: number;
|
|
80
|
+
max?: number;
|
|
81
|
+
label?: string;
|
|
82
|
+
type?: "info" | "success" | "warning" | "error";
|
|
83
|
+
}): {
|
|
84
|
+
element: HTMLElement;
|
|
85
|
+
setValue: (value: number) => void;
|
|
86
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A sign in form: username (or email), password, and optionally "Remember me".
|
|
3
|
+
*
|
|
4
|
+
* @param {object} options
|
|
5
|
+
* @param {string|Element} [options.parent]
|
|
6
|
+
* @param {(values: {username: string, password: string, remember?: boolean}, form: object) => (void|Promise)} options.onSubmit
|
|
7
|
+
* @param {boolean} [options.remember=false] shows "Remember me"
|
|
8
|
+
* @param {"username"|"email"} [options.identifier="username"] what the first field asks for
|
|
9
|
+
* @param {string} [options.submitText]
|
|
10
|
+
*/
|
|
11
|
+
export function generateSignInForm(options?: {
|
|
12
|
+
parent?: string | Element;
|
|
13
|
+
onSubmit: (values: {
|
|
14
|
+
username: string;
|
|
15
|
+
password: string;
|
|
16
|
+
remember?: boolean;
|
|
17
|
+
}, form: object) => (void | Promise<any>);
|
|
18
|
+
remember?: boolean;
|
|
19
|
+
identifier?: "username" | "email";
|
|
20
|
+
submitText?: string;
|
|
21
|
+
}): {
|
|
22
|
+
element: HTMLFormElement;
|
|
23
|
+
fields: {
|
|
24
|
+
[x: string]: any;
|
|
25
|
+
};
|
|
26
|
+
getValues: Function;
|
|
27
|
+
setValues: Function;
|
|
28
|
+
setErrors: Function;
|
|
29
|
+
validate: Function;
|
|
30
|
+
reset: Function;
|
|
31
|
+
setMessage: Function;
|
|
32
|
+
submitButton: object;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* A registration form: username, email, password and its confirmation.
|
|
36
|
+
*
|
|
37
|
+
* @param {object} options
|
|
38
|
+
* @param {string|Element} [options.parent]
|
|
39
|
+
* @param {(values: {username: string, email: string, password: string}, form: object) => (void|Promise)} options.onSubmit
|
|
40
|
+
* the confirmation is checked here and not sent
|
|
41
|
+
* @param {number} [options.passwordMinLength=8]
|
|
42
|
+
* @param {boolean} [options.username=true] false leaves the username out (sign in with the email)
|
|
43
|
+
* @param {string} [options.submitText]
|
|
44
|
+
*/
|
|
45
|
+
export function generateSignUpForm(options?: {
|
|
46
|
+
parent?: string | Element;
|
|
47
|
+
onSubmit: (values: {
|
|
48
|
+
username: string;
|
|
49
|
+
email: string;
|
|
50
|
+
password: string;
|
|
51
|
+
}, form: object) => (void | Promise<any>);
|
|
52
|
+
passwordMinLength?: number;
|
|
53
|
+
username?: boolean;
|
|
54
|
+
submitText?: string;
|
|
55
|
+
}): {
|
|
56
|
+
element: HTMLFormElement;
|
|
57
|
+
fields: {
|
|
58
|
+
[x: string]: any;
|
|
59
|
+
};
|
|
60
|
+
getValues: Function;
|
|
61
|
+
setValues: Function;
|
|
62
|
+
setErrors: Function;
|
|
63
|
+
validate: Function;
|
|
64
|
+
reset: Function;
|
|
65
|
+
setMessage: Function;
|
|
66
|
+
submitButton: object;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Asks for the email address to send a reset link to.
|
|
70
|
+
*
|
|
71
|
+
* @param {object} options
|
|
72
|
+
* @param {string|Element} [options.parent]
|
|
73
|
+
* @param {(values: {email: string}, form: object) => (void|Promise)} options.onSubmit
|
|
74
|
+
*/
|
|
75
|
+
export function generatePasswordResetForm(options?: {
|
|
76
|
+
parent?: string | Element;
|
|
77
|
+
onSubmit: (values: {
|
|
78
|
+
email: string;
|
|
79
|
+
}, form: object) => (void | Promise<any>);
|
|
80
|
+
}): {
|
|
81
|
+
element: HTMLFormElement;
|
|
82
|
+
fields: {
|
|
83
|
+
[x: string]: any;
|
|
84
|
+
};
|
|
85
|
+
getValues: Function;
|
|
86
|
+
setValues: Function;
|
|
87
|
+
setErrors: Function;
|
|
88
|
+
validate: Function;
|
|
89
|
+
reset: Function;
|
|
90
|
+
setMessage: Function;
|
|
91
|
+
submitButton: object;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Change of the password of the person who is signed in: the current one, the new one and its confirmation.
|
|
95
|
+
*
|
|
96
|
+
* @param {object} options
|
|
97
|
+
* @param {string|Element} [options.parent]
|
|
98
|
+
* @param {(values: {currentPassword: string, newPassword: string}, form: object) => (void|Promise)} options.onSubmit
|
|
99
|
+
* @param {number} [options.passwordMinLength=8]
|
|
100
|
+
* @param {string} [options.username] when given, a hidden username field helps the password manager to update the right entry
|
|
101
|
+
*/
|
|
102
|
+
export function generatePasswordChangeForm(options?: {
|
|
103
|
+
parent?: string | Element;
|
|
104
|
+
onSubmit: (values: {
|
|
105
|
+
currentPassword: string;
|
|
106
|
+
newPassword: string;
|
|
107
|
+
}, form: object) => (void | Promise<any>);
|
|
108
|
+
passwordMinLength?: number;
|
|
109
|
+
username?: string;
|
|
110
|
+
}): {
|
|
111
|
+
element: HTMLFormElement;
|
|
112
|
+
fields: {
|
|
113
|
+
[x: string]: any;
|
|
114
|
+
};
|
|
115
|
+
getValues: Function;
|
|
116
|
+
setValues: Function;
|
|
117
|
+
setErrors: Function;
|
|
118
|
+
validate: Function;
|
|
119
|
+
reset: Function;
|
|
120
|
+
setMessage: Function;
|
|
121
|
+
submitButton: object;
|
|
122
|
+
};
|