athena-ui-js 1.3.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 +100 -54
- package/docs/migration-2.0.md +83 -0
- package/docs/styling.md +86 -0
- package/package.json +108 -25
- package/src/athena-ui.js +54 -97
- 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 -9
- package/src/libs/core/controls.js +6 -14
- package/src/libs/core/cookies.js +55 -0
- package/src/libs/core/i18n.js +40 -6
- package/src/libs/core/validation.js +2 -2
- package/src/libs/hephaestus/LayoutGenerator/basicLayoutGenerator.js +9 -1
- package/src/libs/hephaestus/MenuGenerator/menuGenerator.js +16 -4
- package/src/libs/hephaestus/auth/session.js +1 -1
- package/src/libs/hephaestus/dialogGenerator/dialogGenerator.js +25 -17
- package/src/libs/hephaestus/formGenerator/changePasswordFormGenerator.js +4 -4
- package/src/libs/hephaestus/formGenerator/formUtils.js +0 -4
- package/src/libs/hephaestus/formGenerator/loginFormGenerator.js +2 -3
- package/src/libs/hephaestus/formGenerator/registrationFormGenerator.js +3 -3
- package/src/libs/hephaestus/hephaestus.js +0 -10
- package/src/libs/hephaestus/inputGenerator/dropZoneGenerator.js +1 -1
- package/src/libs/hephaestus/modalGenerator/modalGenerator.js +13 -6
- package/src/libs/hephaestus/navigationGenerator/navigationGenerator.js +20 -24
- package/src/menu.js +6 -0
- package/src/navigation.js +6 -0
- package/src/res/themes/default/style.css +97 -100
- 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.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/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,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which rows of a long list have to be in the DOM for the current scroll position.
|
|
3
|
+
* The rows before and after the window are replaced by spacers of `offsetTop` / `offsetBottom` pixels,
|
|
4
|
+
* so the scroll bar keeps the size of the whole list.
|
|
5
|
+
*
|
|
6
|
+
* @param {object} options
|
|
7
|
+
* @param {number} options.scrollTop
|
|
8
|
+
* @param {number} options.viewportHeight
|
|
9
|
+
* @param {number} options.rowHeight
|
|
10
|
+
* @param {number} options.total number of rows
|
|
11
|
+
* @param {number} [options.overscan=5] extra rows above and below, so fast scrolling does not show gaps
|
|
12
|
+
* @returns {{start: number, end: number, offsetTop: number, offsetBottom: number}} rows start..end-1 are rendered
|
|
13
|
+
*/
|
|
14
|
+
export function virtualWindow({ scrollTop, viewportHeight, rowHeight, total, overscan }: {
|
|
15
|
+
scrollTop: number;
|
|
16
|
+
viewportHeight: number;
|
|
17
|
+
rowHeight: number;
|
|
18
|
+
total: number;
|
|
19
|
+
overscan?: number;
|
|
20
|
+
}): {
|
|
21
|
+
start: number;
|
|
22
|
+
end: number;
|
|
23
|
+
offsetTop: number;
|
|
24
|
+
offsetBottom: number;
|
|
25
|
+
};
|
|
26
|
+
export function clampWidth(width: any, min?: number, max?: number): number;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {object} options
|
|
3
|
+
* @param {{id: string, name?: string, description?: string}[]} options.themes the first one is the default
|
|
4
|
+
* @param {{id: string, name?: string}[]} [options.modes] default: system, light, dark. Ids "light" and "dark" are the ones that can be resolved
|
|
5
|
+
* @param {string} [options.storageKey="athena.appearance"] localStorage key (also give it to theme-boot.js)
|
|
6
|
+
* @param {string} [options.themeColorVariable] CSS variable whose value becomes <meta name="theme-color"> (the bar of a phone browser)
|
|
7
|
+
* @param {HTMLElement} [options.root] element that gets the attributes (default: <html>)
|
|
8
|
+
* @param {Storage} [options.storage] default: localStorage
|
|
9
|
+
* @returns {{themes, modes, appearance: () => object, setTheme: (id) => boolean, setMode: (id) => boolean,
|
|
10
|
+
* onChange: (listener) => Function, refresh: Function, destroy: Function}}
|
|
11
|
+
*/
|
|
12
|
+
export function createThemeManager(options?: {
|
|
13
|
+
themes: {
|
|
14
|
+
id: string;
|
|
15
|
+
name?: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
}[];
|
|
18
|
+
modes?: {
|
|
19
|
+
id: string;
|
|
20
|
+
name?: string;
|
|
21
|
+
}[];
|
|
22
|
+
storageKey?: string;
|
|
23
|
+
themeColorVariable?: string;
|
|
24
|
+
root?: HTMLElement;
|
|
25
|
+
storage?: Storage;
|
|
26
|
+
}): {
|
|
27
|
+
themes: any;
|
|
28
|
+
modes: any;
|
|
29
|
+
appearance: () => object;
|
|
30
|
+
setTheme: (id: any) => boolean;
|
|
31
|
+
setMode: (id: any) => boolean;
|
|
32
|
+
onChange: (listener: any) => Function;
|
|
33
|
+
refresh: Function;
|
|
34
|
+
destroy: Function;
|
|
35
|
+
};
|
|
36
|
+
export const DEFAULT_MODES: {
|
|
37
|
+
id: string;
|
|
38
|
+
name: string;
|
|
39
|
+
}[];
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates one value. Returns the (translated) error text, or "" when the value is valid.
|
|
3
|
+
* Empty values only fail `required`, so optional fields can stay empty.
|
|
4
|
+
*
|
|
5
|
+
* @param {*} value a string, boolean (checkbox) or array (multiple choice)
|
|
6
|
+
* @param {object} [rules]
|
|
7
|
+
* @param {boolean} [rules.required]
|
|
8
|
+
* @param {boolean} [rules.email]
|
|
9
|
+
* @param {number} [rules.minLength]
|
|
10
|
+
* @param {number} [rules.maxLength]
|
|
11
|
+
* @param {RegExp|string} [rules.pattern]
|
|
12
|
+
* @param {number} [rules.min] numeric minimum
|
|
13
|
+
* @param {number} [rules.max] numeric maximum
|
|
14
|
+
* @param {string} [rules.match] name of another field that has to hold the same value
|
|
15
|
+
* @param {(value, values) => (string|boolean|undefined)} [rules.validate] custom rule: a string is the error
|
|
16
|
+
* text, false is a generic error, anything else is valid
|
|
17
|
+
* @param {object} [values] all values of the form, for `match` and `validate`
|
|
18
|
+
*/
|
|
19
|
+
export function validateValue(value: any, rules?: {
|
|
20
|
+
required?: boolean;
|
|
21
|
+
email?: boolean;
|
|
22
|
+
minLength?: number;
|
|
23
|
+
maxLength?: number;
|
|
24
|
+
pattern?: RegExp | string;
|
|
25
|
+
min?: number;
|
|
26
|
+
max?: number;
|
|
27
|
+
match?: string;
|
|
28
|
+
validate?: (value: any, values: any) => (string | boolean | undefined);
|
|
29
|
+
}, values?: object): any;
|
|
30
|
+
/**
|
|
31
|
+
* Checks a date range given as ISO dates ("2026-01-31"; they compare correctly as text).
|
|
32
|
+
* Returns the (translated) error text, or "" when the range is valid. Empty dates are not an error.
|
|
33
|
+
*
|
|
34
|
+
* @param {string} from
|
|
35
|
+
* @param {string} to
|
|
36
|
+
* @param {{min?: string, max?: string}} [limits]
|
|
37
|
+
*/
|
|
38
|
+
export function validateDateRange(from: string, to: string, { min, max }?: {
|
|
39
|
+
min?: string;
|
|
40
|
+
max?: string;
|
|
41
|
+
}): any;
|
|
42
|
+
/**
|
|
43
|
+
* Validates a whole form.
|
|
44
|
+
*
|
|
45
|
+
* @param {Object<string, object>} ruleSet rules by field name
|
|
46
|
+
* @param {Object<string, *>} values
|
|
47
|
+
* @returns {Object<string, string>} error text by field name, only for invalid fields
|
|
48
|
+
*/
|
|
49
|
+
export function validateAll(ruleSet: {
|
|
50
|
+
[x: string]: any;
|
|
51
|
+
}, values: {
|
|
52
|
+
[x: string]: any;
|
|
53
|
+
}): {
|
|
54
|
+
[x: string]: string;
|
|
55
|
+
};
|
|
56
|
+
export const EMAIL_PATTERN: RegExp;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Chooses where generateContainer() puts the page layout: the id of an element, or "" for the body. */
|
|
2
|
+
export function setLayoutRoot(id?: string): void;
|
|
3
|
+
export function generateBasicLayout(): void;
|
|
4
|
+
export function generateContainer(): void;
|
|
5
|
+
export function generateHeader(): void;
|
|
6
|
+
export function clearHeader(): void;
|
|
7
|
+
export function generateWrapper(): void;
|
|
8
|
+
export function clearWrapper(): void;
|
|
9
|
+
export function generateFooter(): void;
|
|
10
|
+
export function clearFooter(): void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function generateHeaderContent(): void;
|
|
2
|
+
/**
|
|
3
|
+
* Generates the menu of the header. Without options it is built from the global `menuItems` / nav callback, as before.
|
|
4
|
+
* With `options.items` it is a generateMenu (no globals): `generateHeaderMenu({ items, onNavigate, active, layout, followHash })`.
|
|
5
|
+
*/
|
|
6
|
+
export function generateHeaderMenu(options: any): {
|
|
7
|
+
element: HTMLElement;
|
|
8
|
+
select: (id: string | null) => void;
|
|
9
|
+
getActive: () => string | null;
|
|
10
|
+
setBadge: (id: string, badge: any) => void;
|
|
11
|
+
close: Function;
|
|
12
|
+
update: (changes?: {
|
|
13
|
+
items?: object[];
|
|
14
|
+
}) => object;
|
|
15
|
+
destroy: Function;
|
|
16
|
+
};
|
|
17
|
+
export function clearHeaderMenu(): void;
|
|
18
|
+
export function generateHeaderTitle(): void;
|
|
19
|
+
export function generateHeaderLogo(): void;
|
|
20
|
+
export function generateContaninerForElements(params: any): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function generateWrapperContent(): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function defaultMenuItems(menuId: any, count?: number): {
|
|
2
|
+
id: string;
|
|
3
|
+
class: string;
|
|
4
|
+
text: string;
|
|
5
|
+
inner_text: string;
|
|
6
|
+
}[];
|
|
7
|
+
/**
|
|
8
|
+
* Generates a menu. An item with `children: [{ inner_text, disabled? }]` opens a submenu on click, Enter, Space
|
|
9
|
+
* or the Down arrow. Esc, a click outside, or choosing an entry closes it. Choosing an entry calls the
|
|
10
|
+
* nav callback with its `inner_text`, like a top level item.
|
|
11
|
+
*/
|
|
12
|
+
export function generateBasicMenu(options: any): void;
|
|
13
|
+
export function generateMenuWireFrame(options: any): void;
|
|
14
|
+
export function addMenuItemToWireFrame(options: any): void;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** The text of a badge: numbers above 99 become "99+", 0 / null / false / "" mean no badge. */
|
|
2
|
+
export function badgeText(value: any): string;
|
|
3
|
+
/**
|
|
4
|
+
* Generates a navigation menu. Items are real links (`href`) or buttons, so the keyboard and screen readers work without help:
|
|
5
|
+
* Tab reaches every item, Enter and Space use it, the arrow keys move inside a group, Esc closes it.
|
|
6
|
+
*
|
|
7
|
+
* @param {object} options
|
|
8
|
+
* @param {string|Element} [options.parent]
|
|
9
|
+
* @param {MenuItem[]} options.items
|
|
10
|
+
* `icon` is shown before the label (text, or a Node such as an SVG; it is hidden from screen readers).
|
|
11
|
+
* `badge` is a small count or word after the label (0, null and "" show nothing, numbers above 99 show "99+").
|
|
12
|
+
* `badgeLabel` is what a screen reader hears for it ("3 unread"); without it the badge text is read after the label.
|
|
13
|
+
* `avatar` shows the picture (or the initials) of a person: for the user menu, usually with `align: "end"` and children.
|
|
14
|
+
* An item with `children` opens a group; a child can have children too (a group inside a group, any depth).
|
|
15
|
+
* @param {(item: MenuItem, event: Event) => void} [options.onNavigate] called when a PERSON uses an item (click, Enter, Space).
|
|
16
|
+
* It is never called by select() or while the menu is built.
|
|
17
|
+
* @param {string} [options.active] id of the item that is the current page at the start
|
|
18
|
+
* @param {boolean} [options.followHash=false] the item whose `href` equals location.hash is the active one, and follows hashchange
|
|
19
|
+
* @param {"bar"|"bottom-tabs"|"responsive"} [options.layout="bar"] "bottom-tabs": a bar of tabs at the bottom of the screen,
|
|
20
|
+
* groups open as sheets above it. "responsive": a bar on wide screens, bottom tabs on a tablet or phone (max 700px).
|
|
21
|
+
* @param {string} [options.label] accessible name of the navigation
|
|
22
|
+
* @param {string} [options.id]
|
|
23
|
+
* @param {string} [options.class]
|
|
24
|
+
* @returns {{element: HTMLElement, select: (id: string|null) => void, getActive: () => string|null, setBadge: (id: string, badge) => void,
|
|
25
|
+
* close: Function, update: (changes?: {items?: object[]}) => object, destroy: Function}}
|
|
26
|
+
*/
|
|
27
|
+
export function generateMenu(options?: {
|
|
28
|
+
parent?: string | Element;
|
|
29
|
+
items: MenuItem[];
|
|
30
|
+
onNavigate?: (item: MenuItem, event: Event) => void;
|
|
31
|
+
active?: string;
|
|
32
|
+
followHash?: boolean;
|
|
33
|
+
layout?: "bar" | "bottom-tabs" | "responsive";
|
|
34
|
+
label?: string;
|
|
35
|
+
id?: string;
|
|
36
|
+
class?: string;
|
|
37
|
+
}): {
|
|
38
|
+
element: HTMLElement;
|
|
39
|
+
select: (id: string | null) => void;
|
|
40
|
+
getActive: () => string | null;
|
|
41
|
+
setBadge: (id: string, badge: any) => void;
|
|
42
|
+
close: Function;
|
|
43
|
+
update: (changes?: {
|
|
44
|
+
items?: object[];
|
|
45
|
+
}) => object;
|
|
46
|
+
destroy: Function;
|
|
47
|
+
};
|
|
48
|
+
export type MenuItem = {
|
|
49
|
+
id: string;
|
|
50
|
+
label: string;
|
|
51
|
+
icon?: string | Node;
|
|
52
|
+
href?: string;
|
|
53
|
+
disabled?: boolean;
|
|
54
|
+
align?: "end";
|
|
55
|
+
badge?: number | string | {
|
|
56
|
+
text: (number | string);
|
|
57
|
+
tone?: "info" | "ok" | "warn" | "bad";
|
|
58
|
+
};
|
|
59
|
+
badgeLabel?: string;
|
|
60
|
+
avatar?: {
|
|
61
|
+
name: string;
|
|
62
|
+
src?: string;
|
|
63
|
+
};
|
|
64
|
+
children?: MenuItem[];
|
|
65
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who is signed in, kept in memory only. Nothing is written to a cookie or to the storage, so a script (an injected one too) cannot read
|
|
3
|
+
* a credential from here: the real session is a cookie that only the server can read (HttpOnly). This object is the UI's copy of the
|
|
4
|
+
* answer to "who am I", for menus, route guards and the page. The server decides what a person may do.
|
|
5
|
+
*
|
|
6
|
+
* After a reload the state is empty until restore() has asked the server.
|
|
7
|
+
*
|
|
8
|
+
* @param {object} [options]
|
|
9
|
+
* @param {() => Promise<(object|null)>} [options.restore] asks the server who is signed in (for example GET /api/me with the cookie):
|
|
10
|
+
* resolves with the user object, or with null / throws when nobody is
|
|
11
|
+
* @returns {{signIn: (user: object) => void, signOut: () => void, restore: () => Promise<object|null>, isSignedIn: () => boolean,
|
|
12
|
+
* getUser: () => (object|null), hasRole: (role: string) => boolean, onChange: (listener: Function) => Function,
|
|
13
|
+
* routerRules: (paths?: object) => object}}
|
|
14
|
+
*/
|
|
15
|
+
export function createAuthState(options?: {
|
|
16
|
+
restore?: () => Promise<(object | null)>;
|
|
17
|
+
}): {
|
|
18
|
+
signIn: (user: object) => void;
|
|
19
|
+
signOut: () => void;
|
|
20
|
+
restore: () => Promise<object | null>;
|
|
21
|
+
isSignedIn: () => boolean;
|
|
22
|
+
getUser: () => (object | null);
|
|
23
|
+
hasRole: (role: string) => boolean;
|
|
24
|
+
onChange: (listener: Function) => Function;
|
|
25
|
+
routerRules: (paths?: object) => object;
|
|
26
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stores the session after a successful login.
|
|
3
|
+
*
|
|
4
|
+
* @param {object} session
|
|
5
|
+
* @param {*} [session.user] anything JSON serializable: name, roles, ...
|
|
6
|
+
* @param {string} [session.token]
|
|
7
|
+
* @param {boolean} [session.remember=false] keep the session after the browser closes
|
|
8
|
+
* @param {number} [session.days] lifetime of a remembered session (default: the `session_days` setting)
|
|
9
|
+
*/
|
|
10
|
+
export function setSession({ user, token, remember, days }?: {
|
|
11
|
+
user?: any;
|
|
12
|
+
token?: string;
|
|
13
|
+
remember?: boolean;
|
|
14
|
+
days?: number;
|
|
15
|
+
}): void;
|
|
16
|
+
/** The stored session ({ user, token, at }), or null when nobody is logged in. */
|
|
17
|
+
export function getSession(): any;
|
|
18
|
+
export function isLoggedIn(): boolean;
|
|
19
|
+
/** Ends the session. */
|
|
20
|
+
export function logout(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Calls the listener with the session (or null) whenever somebody logs in or out.
|
|
23
|
+
*
|
|
24
|
+
* @returns {() => void} unsubscribe function
|
|
25
|
+
*/
|
|
26
|
+
export function onSessionChange(listener: any): () => void;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/** Tick positions (ms) at round times between `from` and `to`, about `count` of them. */
|
|
2
|
+
export function timeTicks(from: any, to: any, count?: number): {
|
|
3
|
+
ticks: number[];
|
|
4
|
+
step: number;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Keeps about `buckets` x positions of a long series: of every bucket the lowest and the highest value stay (in their order),
|
|
8
|
+
* so peaks are not lost. Returns the kept indices.
|
|
9
|
+
*/
|
|
10
|
+
export function decimate(indices: any, values: any, buckets: any): any;
|
|
11
|
+
/**
|
|
12
|
+
* Draws a chart as inline SVG and appends it to its parent.
|
|
13
|
+
*
|
|
14
|
+
* @param {object} options
|
|
15
|
+
* @param {"bar"|"line"|"area"|"sparkline"|"pie"|"donut"} [options.type="bar"]
|
|
16
|
+
* @param {string|Element} [options.parent] element, id or selector, defaults to "wrapper"
|
|
17
|
+
* @param {string} [options.id] id of the svg element
|
|
18
|
+
* @param {string} [options.title] drawn above the chart, and its accessible name
|
|
19
|
+
* @param {string[]} [options.labels] category labels
|
|
20
|
+
* @param {(number|Date|string)[]} [options.times] line and area charts: the time of every value (Date, ms or a date string).
|
|
21
|
+
* The x axis becomes a time axis with ticks at round times, and the points sit at their real distance.
|
|
22
|
+
* @param {{name?: string, data: number[], color?: string}[]} options.series pie / donut / sparkline use the first series only.
|
|
23
|
+
* Colours come from the theme (--series-1 ... --series-8); `color` is an override for one series.
|
|
24
|
+
* @param {number} [options.width=600] (a sparkline: 120)
|
|
25
|
+
* @param {number} [options.height=360] (a sparkline: 32)
|
|
26
|
+
* @param {boolean} [options.legend] default: shown for several series, and for pie / donut. Clicking an entry hides / shows its series.
|
|
27
|
+
* @param {boolean} [options.table=false] adds a "Show as table" section with the values below the chart
|
|
28
|
+
* @param {boolean} [options.zero=true] line charts: false lets the value axis start near the smallest value
|
|
29
|
+
* @param {boolean} [options.zoom=false] line and area charts: drag over the plot to zoom into that range, double click (or the
|
|
30
|
+
* reset button, or 0 / Esc) to zoom out; with the keyboard on the plot: + and - zoom, the arrow keys pan
|
|
31
|
+
* @param {{from: number, to: number}|null} [options.zoomRange] the range in view, in the units of the x axis: milliseconds with
|
|
32
|
+
* `times`, otherwise the index of the point (-0.5 is the left edge of the first point)
|
|
33
|
+
* @param {(range: ({from: number, to: number}|null)) => void} [options.onZoom] called when a person zooms or resets
|
|
34
|
+
* @param {number} [options.maxPoints] `push` keeps at most this many points per series (the oldest are dropped)
|
|
35
|
+
* @param {boolean} [options.interactive=true] line and area charts: false leaves out the pointer layer (tooltip that follows the pointer, zoom)
|
|
36
|
+
* @returns {(SVGElement & {element: SVGElement, update: (options?: object) => SVGElement, destroy: () => void,
|
|
37
|
+
* zoom: (from: number, to: number) => void, resetZoom: () => void, getZoom: () => ({from: number, to: number}|null),
|
|
38
|
+
* push: (point: {x?: (number|Date|string), label?: string, values: (number|number[])}, config?: {maxPoints?: number}) => void,
|
|
39
|
+
* dataTable: (HTMLElement|null)})|null}
|
|
40
|
+
* the SVG element, which also carries the handle ({ element, update(options), destroy() }) of the other
|
|
41
|
+
* components; null when the options are invalid. `parent` is an element, an id or a selector.
|
|
42
|
+
* `push` adds a point to every series (a number for the first series, or one value per series; `x` is the time with
|
|
43
|
+
* `times`, `label` the category) and draws the chart again at most once per frame, however often it is called.
|
|
44
|
+
*/
|
|
45
|
+
export function generateChart(options?: {
|
|
46
|
+
type?: "bar" | "line" | "area" | "sparkline" | "pie" | "donut";
|
|
47
|
+
parent?: string | Element;
|
|
48
|
+
id?: string;
|
|
49
|
+
title?: string;
|
|
50
|
+
labels?: string[];
|
|
51
|
+
times?: (number | Date | string)[];
|
|
52
|
+
series: {
|
|
53
|
+
name?: string;
|
|
54
|
+
data: number[];
|
|
55
|
+
color?: string;
|
|
56
|
+
}[];
|
|
57
|
+
width?: number;
|
|
58
|
+
height?: number;
|
|
59
|
+
legend?: boolean;
|
|
60
|
+
table?: boolean;
|
|
61
|
+
zero?: boolean;
|
|
62
|
+
zoom?: boolean;
|
|
63
|
+
zoomRange?: {
|
|
64
|
+
from: number;
|
|
65
|
+
to: number;
|
|
66
|
+
} | null;
|
|
67
|
+
onZoom?: (range: ({
|
|
68
|
+
from: number;
|
|
69
|
+
to: number;
|
|
70
|
+
} | null)) => void;
|
|
71
|
+
maxPoints?: number;
|
|
72
|
+
interactive?: boolean;
|
|
73
|
+
}): (SVGElement & {
|
|
74
|
+
element: SVGElement;
|
|
75
|
+
update: (options?: object) => SVGElement;
|
|
76
|
+
destroy: () => void;
|
|
77
|
+
zoom: (from: number, to: number) => void;
|
|
78
|
+
resetZoom: () => void;
|
|
79
|
+
getZoom: () => ({
|
|
80
|
+
from: number;
|
|
81
|
+
to: number;
|
|
82
|
+
} | null);
|
|
83
|
+
push: (point: {
|
|
84
|
+
x?: (number | Date | string);
|
|
85
|
+
label?: string;
|
|
86
|
+
values: (number | number[]);
|
|
87
|
+
}, config?: {
|
|
88
|
+
maxPoints?: number;
|
|
89
|
+
}) => void;
|
|
90
|
+
dataTable: (HTMLElement | null);
|
|
91
|
+
}) | null;
|
|
@@ -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
|
+
};
|