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.
Files changed (148) hide show
  1. package/README.md +312 -60
  2. package/docs/migration-2.0.md +83 -0
  3. package/docs/styling.md +86 -0
  4. package/package.json +109 -24
  5. package/src/athena-ui.js +61 -81
  6. package/src/chart.js +6 -0
  7. package/src/classic.js +11 -0
  8. package/src/components.js +6 -0
  9. package/src/controls.js +8 -0
  10. package/src/csv.js +6 -0
  11. package/src/dialog.js +7 -0
  12. package/src/dom.js +6 -0
  13. package/src/feedback.js +6 -0
  14. package/src/format.js +6 -0
  15. package/src/forms.js +7 -0
  16. package/src/i18n.js +6 -0
  17. package/src/inputs.js +9 -0
  18. package/src/libs/config/config.js +1 -2
  19. package/src/libs/core/controls.js +145 -0
  20. package/src/libs/core/cookies.js +55 -0
  21. package/src/libs/core/dateRange.js +121 -0
  22. package/src/libs/core/dom.js +58 -8
  23. package/src/libs/{hephaestus/HTMLElementGenerator/src/HTMLElementGenerator.js → core/elementGenerator.js} +23 -21
  24. package/src/libs/{hephaestus/HTMLElementGenerator/src → core}/errors.js +7 -5
  25. package/src/libs/core/format.js +51 -0
  26. package/src/libs/core/hungarianControls.js +41 -0
  27. package/src/libs/core/i18n.js +104 -6
  28. package/src/libs/core/theme.js +131 -0
  29. package/src/libs/core/validation.js +2 -2
  30. package/src/libs/hephaestus/LayoutGenerator/basicLayoutGenerator.js +13 -7
  31. package/src/libs/hephaestus/LayoutGenerator/footerContentGenerator.js +2 -4
  32. package/src/libs/hephaestus/LayoutGenerator/headerContentGenerator.js +12 -5
  33. package/src/libs/hephaestus/MenuGenerator/basicMenuGenerator.js +3 -3
  34. package/src/libs/hephaestus/MenuGenerator/menuGenerator.js +265 -0
  35. package/src/libs/hephaestus/auth/authState.js +58 -0
  36. package/src/libs/hephaestus/auth/session.js +1 -1
  37. package/src/libs/hephaestus/chartGenerator/chartGenerator.js +519 -87
  38. package/src/libs/hephaestus/componentGenerator/componentGenerator.js +121 -4
  39. package/src/libs/hephaestus/componentGenerator/themePicker.js +73 -0
  40. package/src/libs/hephaestus/dialogGenerator/dialogGenerator.js +113 -25
  41. package/src/libs/hephaestus/feedbackGenerator/feedbackGenerator.js +21 -0
  42. package/src/libs/hephaestus/formGenerator/authForms.js +130 -0
  43. package/src/libs/hephaestus/formGenerator/changePasswordFormGenerator.js +4 -4
  44. package/src/libs/hephaestus/formGenerator/formUtils.js +10 -13
  45. package/src/libs/hephaestus/formGenerator/loginFormGenerator.js +10 -11
  46. package/src/libs/hephaestus/formGenerator/registrationFormGenerator.js +3 -3
  47. package/src/libs/hephaestus/hephaestus.js +0 -5
  48. package/src/libs/hephaestus/inputGenerator/dropZoneGenerator.js +1 -1
  49. package/src/libs/hephaestus/inputGenerator/inputGenerator.js +30 -1
  50. package/src/libs/hephaestus/modalGenerator/modalGenerator.js +25 -12
  51. package/src/libs/hephaestus/navigationGenerator/navigationGenerator.js +20 -24
  52. package/src/libs/hephaestus/router/router.js +54 -5
  53. package/src/libs/hephaestus/tableGenerator/tableGenerator.js +290 -16
  54. package/src/menu.js +6 -0
  55. package/src/navigation.js +6 -0
  56. package/src/res/themes/appearance.css +154 -0
  57. package/src/res/themes/default/style.css +688 -82
  58. package/src/res/themes/tokens.css +96 -0
  59. package/src/router.js +6 -0
  60. package/src/sanitize.js +6 -0
  61. package/src/session.js +8 -0
  62. package/src/table.js +6 -0
  63. package/src/testing.js +11 -1
  64. package/src/theme-boot.js +25 -0
  65. package/src/theme.js +7 -0
  66. package/src/validation.js +6 -0
  67. package/types/athena-ui.d.ts +96 -0
  68. package/types/chart.d.ts +1 -0
  69. package/types/classic.d.ts +1 -0
  70. package/types/components.d.ts +1 -0
  71. package/types/controls.d.ts +3 -0
  72. package/types/csv.d.ts +1 -0
  73. package/types/dialog.d.ts +2 -0
  74. package/types/dom.d.ts +1 -0
  75. package/types/feedback.d.ts +1 -0
  76. package/types/format.d.ts +1 -0
  77. package/types/forms.d.ts +2 -0
  78. package/types/i18n.d.ts +1 -0
  79. package/types/inputs.d.ts +4 -0
  80. package/types/libs/config/config.d.ts +96 -0
  81. package/types/libs/config/hooks.d.ts +8 -0
  82. package/types/libs/core/combobox.d.ts +10 -0
  83. package/types/libs/core/controls.d.ts +28 -0
  84. package/types/libs/core/cookies.d.ts +27 -0
  85. package/types/libs/core/csv.d.ts +12 -0
  86. package/types/libs/core/dateRange.d.ts +72 -0
  87. package/types/libs/core/dom.d.ts +65 -0
  88. package/types/libs/core/elementGenerator.d.ts +30 -0
  89. package/types/libs/core/errors.d.ts +29 -0
  90. package/types/libs/core/focus.d.ts +6 -0
  91. package/types/libs/core/format.d.ts +21 -0
  92. package/types/libs/core/hungarianControls.d.ts +2 -0
  93. package/types/libs/core/i18n.d.ts +17 -0
  94. package/types/libs/core/pagination.d.ts +5 -0
  95. package/types/libs/core/sanitize.d.ts +6 -0
  96. package/types/libs/core/tableMath.d.ts +26 -0
  97. package/types/libs/core/theme.d.ts +39 -0
  98. package/types/libs/core/validation.d.ts +56 -0
  99. package/types/libs/hephaestus/LayoutGenerator/basicLayoutGenerator.d.ts +10 -0
  100. package/types/libs/hephaestus/LayoutGenerator/footerContentGenerator.d.ts +4 -0
  101. package/types/libs/hephaestus/LayoutGenerator/headerContentGenerator.d.ts +20 -0
  102. package/types/libs/hephaestus/LayoutGenerator/wrapperContentGenerator.d.ts +1 -0
  103. package/types/libs/hephaestus/MenuGenerator/basicMenuGenerator.d.ts +14 -0
  104. package/types/libs/hephaestus/MenuGenerator/menuGenerator.d.ts +65 -0
  105. package/types/libs/hephaestus/auth/authState.d.ts +26 -0
  106. package/types/libs/hephaestus/auth/session.d.ts +26 -0
  107. package/types/libs/hephaestus/chartGenerator/chartGenerator.d.ts +91 -0
  108. package/types/libs/hephaestus/componentGenerator/componentGenerator.d.ts +222 -0
  109. package/types/libs/hephaestus/componentGenerator/themePicker.d.ts +24 -0
  110. package/types/libs/hephaestus/dialogGenerator/dialogGenerator.d.ts +120 -0
  111. package/types/libs/hephaestus/feedbackGenerator/feedbackGenerator.d.ts +86 -0
  112. package/types/libs/hephaestus/formGenerator/authForms.d.ts +122 -0
  113. package/types/libs/hephaestus/formGenerator/changePasswordFormGenerator.d.ts +6 -0
  114. package/types/libs/hephaestus/formGenerator/formBuilder.d.ts +113 -0
  115. package/types/libs/hephaestus/formGenerator/formUtils.d.ts +8 -0
  116. package/types/libs/hephaestus/formGenerator/loginFormGenerator.d.ts +11 -0
  117. package/types/libs/hephaestus/formGenerator/lostPasswordFormGenerator.d.ts +4 -0
  118. package/types/libs/hephaestus/formGenerator/registrationFormGenerator.d.ts +7 -0
  119. package/types/libs/hephaestus/hephaestus.d.ts +3 -0
  120. package/types/libs/hephaestus/inputGenerator/dropZoneGenerator.d.ts +48 -0
  121. package/types/libs/hephaestus/inputGenerator/inputGenerator.d.ts +185 -0
  122. package/types/libs/hephaestus/inputGenerator/richTextGenerator.d.ts +49 -0
  123. package/types/libs/hephaestus/modalGenerator/modalGenerator.d.ts +2 -0
  124. package/types/libs/hephaestus/navigationGenerator/navigationGenerator.d.ts +150 -0
  125. package/types/libs/hephaestus/router/matchRoute.d.ts +12 -0
  126. package/types/libs/hephaestus/router/router.d.ts +67 -0
  127. package/types/libs/hephaestus/tableGenerator/tableGenerator.d.ts +120 -0
  128. package/types/menu.d.ts +1 -0
  129. package/types/navigation.d.ts +1 -0
  130. package/types/res/themes/themes.d.ts +7 -0
  131. package/types/router.d.ts +1 -0
  132. package/types/sanitize.d.ts +1 -0
  133. package/types/session.d.ts +3 -0
  134. package/types/table.d.ts +1 -0
  135. package/types/testing.d.ts +27 -0
  136. package/types/theme-boot.d.ts +0 -0
  137. package/types/theme.d.ts +2 -0
  138. package/types/validation.d.ts +1 -0
  139. package/src/libs/crypto-js/LICENSE +0 -24
  140. package/src/libs/crypto-js/crypto-js.js +0 -6657
  141. package/src/libs/hephaestus/HTMLControlGenerator/LICENSE +0 -21
  142. package/src/libs/hephaestus/HTMLControlGenerator/src/HTMLControlGenerator.min.js +0 -5
  143. package/src/libs/hephaestus/HTMLElementGenerator/LICENSE +0 -21
  144. package/src/libs/js-cookie/LICENSE +0 -21
  145. package/src/libs/js-cookie/src/api.mjs +0 -103
  146. package/src/libs/js-cookie/src/assign.mjs +0 -10
  147. package/src/libs/js-cookie/src/converter.mjs +0 -14
  148. package/src/libs/libs.js +0 -13
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Creates an element. This is the safe way to write pages: text is only ever inserted as text, attributes that run code
3
+ * (on*, style, srcdoc) and unsafe addresses (javascript:, data:, ...) in href / src / action are refused, listeners have to be
4
+ * functions, and children can be given as nested lists.
5
+ *
6
+ * @param {string} tag
7
+ * @param {object} [props]
8
+ * @param {string} [props.class]
9
+ * @param {string} [props.id]
10
+ * @param {string} [props.text] set as textContent (never parsed as HTML)
11
+ * @param {Object<string, string|boolean|number>} [props.attrs] attributes, false / null / undefined are skipped
12
+ * @param {Object<string, Function>} [props.on] event listeners (a value that is not a function throws a TypeError)
13
+ * @param {Object<string, *>} [props.prop] DOM properties (value, checked, disabled, ...), not the ones that parse HTML
14
+ * @param {...(Node|string|number|Array|null|false)} children text, nodes, or lists of them
15
+ */
16
+ export function el(tag: string, props?: {
17
+ class?: string;
18
+ id?: string;
19
+ text?: string;
20
+ attrs?: {
21
+ [x: string]: string | boolean | number;
22
+ };
23
+ on?: {
24
+ [x: string]: Function;
25
+ };
26
+ prop?: {
27
+ [x: string]: any;
28
+ };
29
+ }, ...children: (Node | string | number | any[] | null | false)[]): HTMLElement;
30
+ /**
31
+ * Fills a node with content. Strings are inserted as text, never as HTML.
32
+ * Accepts a string / number, a Node, an array of those, or a function returning one.
33
+ */
34
+ export function setContent(node: any, content: any): any;
35
+ /**
36
+ * Finds an element from an element, an id or a CSS selector ("#list", ".panel > ul").
37
+ * An id wins over a selector with the same text. Returns null when nothing matches.
38
+ */
39
+ export function resolveElement(target: any): Element;
40
+ export function mount(parent: any, node: any): any;
41
+ /**
42
+ * Gives a component the same handle as every other one: { element, update(), destroy() }.
43
+ * What the component already has is kept. `update` does nothing unless the component supports it
44
+ * (it returns the handle), `destroy` removes the element (and `also`, e.g. a wrapper around it).
45
+ */
46
+ export function asHandle(handle: any, { element, also }?: {
47
+ element?: any;
48
+ }): any;
49
+ /**
50
+ * A stricter el(): only the tags and attributes on your lists are allowed, everything else is refused (a tag throws, an attribute is
51
+ * skipped with a warning). For pages that are built from data you do not control, such as a plugin API. The refusals of el() still apply.
52
+ *
53
+ * @param {object} allow
54
+ * @param {string[]} [allow.tags] allowed tag names (default: any)
55
+ * @param {string[]} allow.attributes allowed attribute names, lower case: ["class", "title", "href"]
56
+ * @param {boolean} [allow.dataAndAria=true] data-* and aria-* attributes are allowed too
57
+ * @returns {typeof el}
58
+ */
59
+ export function createSafeBuilder({ tags, attributes, dataAndAria }?: {
60
+ tags?: string[];
61
+ attributes: string[];
62
+ dataAndAria?: boolean;
63
+ }): typeof el;
64
+ export function uid(prefix?: string): string;
65
+ export function cx(...classes: any[]): string;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Generates an HTML element and appends it to its parent.
3
+ *
4
+ * @param {object} options
5
+ * @param {string} options.elementType one of `supportedElements`
6
+ * @param {string} [options.parent] id of the parent element; omitted or '' appends to body
7
+ * @param {string} [options.id]
8
+ * @param {string} [options.class]
9
+ * @param {string} [options.text]
10
+ * @param {string} [options.src] img only
11
+ * @param {string} [options.alt] img only
12
+ * @param {*} [options.data] passed to the onclick / onchange handlers
13
+ * @param {(data: *) => void} [options.onclick]
14
+ * @param {(data: *) => void} [options.onchange]
15
+ * @returns {HTMLElement|null} the generated element, or null when generation failed
16
+ */
17
+ export function HTMLElementGenerator(options: {
18
+ elementType: string;
19
+ parent?: string;
20
+ id?: string;
21
+ class?: string;
22
+ text?: string;
23
+ src?: string;
24
+ alt?: string;
25
+ data?: any;
26
+ onclick?: (data: any) => void;
27
+ onchange?: (data: any) => void;
28
+ }): HTMLElement | null;
29
+ export const supportedElements: readonly string[];
30
+ export default HTMLElementGenerator;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Logs the error and, when the page has a body, shows a short message in it.
3
+ * Always returns null so callers can `return reportError(...)`.
4
+ */
5
+ export function reportError(error: any): any;
6
+ export const ErrorCode: Readonly<{
7
+ UNDEFINED: 0;
8
+ WRONG_INPUT_TYPE: 1;
9
+ NO_BODY_OR_PARENT: 2;
10
+ }>;
11
+ export function undefinedError(variable: any, functionName: any): {
12
+ errorCode: 0;
13
+ errorString: string;
14
+ errorVariable: any;
15
+ errorFunction: any;
16
+ };
17
+ export function wrongInputTypeError(variable: any, functionName: any, inputOptions: any): {
18
+ errorCode: 1;
19
+ errorString: string;
20
+ errorVariable: any;
21
+ errorFunction: any;
22
+ errorMiscInfo: any;
23
+ };
24
+ export function noBodyOrParentError(variable: any, functionName: any): {
25
+ errorCode: 2;
26
+ errorString: string;
27
+ errorVariable: any;
28
+ errorFunction: any;
29
+ };
@@ -0,0 +1,6 @@
1
+ export function focusableIn(container: any): any[];
2
+ /**
3
+ * Keeps Tab inside the container, calls onEscape on Esc and moves the focus into the container.
4
+ * Returns a release function that restores the previous focus.
5
+ */
6
+ export function trapFocus(container: any, { onEscape }?: {}): () => void;
@@ -0,0 +1,21 @@
1
+ export function formatBytes(bytes: any): string;
2
+ /**
3
+ * Checks a file against an `accept` list like ".png,image/*,application/pdf". An empty list accepts everything.
4
+ */
5
+ export function matchesAccept(file: any, accept: any): boolean;
6
+ /** 1234567.891 -> "1,234,567.89" (the separators of the current language). */
7
+ export function formatNumber(value: any, options?: {}): string;
8
+ /**
9
+ * A length of time in milliseconds as short text: 350 -> "350 ms", 45000 -> "45 sec", 7500000 -> "2 hr, 5 min".
10
+ * At most `parts` units are shown (default 2). The unit names follow the current language.
11
+ */
12
+ export function formatDuration(ms: any, { parts }?: {
13
+ parts?: number;
14
+ }): string;
15
+ /** "2 min ago", "in 3 days", "yesterday": the time between `date` and `now`, in the current language. */
16
+ export function formatRelativeTime(date: any, now?: number): string;
17
+ /** A date (and time) for people: formatDate(d) -> "Nov 19, 2026"; formatDate(d, { time: true }) adds the time. */
18
+ export function formatDate(date: any, { time, style }?: {
19
+ time?: boolean;
20
+ style?: string;
21
+ }): string;
@@ -0,0 +1,2 @@
1
+ /** Adds the input types hunPIN, hunCRID and hunTID (Hungarian personal insurance, company registration and tax numbers, in segments). */
2
+ export function registerHungarianInputControls(): void;
@@ -0,0 +1,17 @@
1
+ export function setLocale(newLocale: any): void;
2
+ export function getLocale(): string;
3
+ export function addMessages(forLocale: any, texts: any): void;
4
+ /**
5
+ * Looks a text up in the current locale, then in its base language ("hu-HU" -> "hu"), then in English.
6
+ * Unknown keys are returned as they are.
7
+ *
8
+ * Placeholders: {name} is replaced from params as it is, {name:number} is formatted as a number and {name:date} as a date, in the current language (Intl).
9
+ * Plural forms: a message can be an object with the forms of the language, and the form is chosen by `params.count`:
10
+ *
11
+ * addMessages("en", { files: { zero: "No files", one: "{count} file", other: "{count:number} files" } });
12
+ * translate("files", { count: 1200 }) // "1,200 files"
13
+ *
14
+ * The keys are the categories of Intl.PluralRules for the language ("one", "other", and where the language has them "zero", "two", "few", "many"),
15
+ * or an exact number ("0"). "other" is the fallback.
16
+ */
17
+ export function translate(key: any, params?: {}): any;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Page buttons to show: first and last page, the current page with its neighbours, "…" for the gaps.
3
+ * pageRange(5, 10, 1) -> [1, "…", 4, 5, 6, "…", 10]
4
+ */
5
+ export function pageRange(page: any, pages: any, siblings?: number): any[];
@@ -0,0 +1,6 @@
1
+ /** True for http(s), mailto, tel, anchors and relative paths. Rejects javascript:, data:, vbscript: and the like. */
2
+ export function isSafeUrl(url: any): boolean;
3
+ /** Cleans HTML from the editor, the clipboard or the application. Returns the safe HTML string. */
4
+ export function sanitizeHtml(html: any): string;
5
+ /** The text of an HTML string, without tags. */
6
+ export function htmlToText(html: any): string;
@@ -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,4 @@
1
+ export function generateFooterContent(): void;
2
+ export function generateFooterMenu(): void;
3
+ export function clearFooterMenu(): void;
4
+ export function generateFooterCopyrightText(): 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;