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
package/src/libs/core/i18n.js
CHANGED
|
@@ -20,6 +20,38 @@ const messages = {
|
|
|
20
20
|
changePassword: "Change password",
|
|
21
21
|
rememberMe: "Remember me",
|
|
22
22
|
ok: "OK",
|
|
23
|
+
save: "Save",
|
|
24
|
+
"range.preset": "Range",
|
|
25
|
+
"range.custom": "Custom",
|
|
26
|
+
"range.last15m": "Last 15 minutes",
|
|
27
|
+
"range.last1h": "Last hour",
|
|
28
|
+
"range.last24h": "Last 24 hours",
|
|
29
|
+
"range.last7d": "Last 7 days",
|
|
30
|
+
"range.last30d": "Last 30 days",
|
|
31
|
+
copied: "Copied",
|
|
32
|
+
copyFailed: "Copying is not possible here.",
|
|
33
|
+
"tone.ok": "good",
|
|
34
|
+
"tone.warn": "warning",
|
|
35
|
+
"tone.bad": "critical",
|
|
36
|
+
"chart.zoomHint": "Chart plot. Plus and minus zoom, arrow keys move, 0 resets.",
|
|
37
|
+
"chart.resetZoom": "Reset zoom",
|
|
38
|
+
menu: "Main menu",
|
|
39
|
+
showAsTable: "Show as table",
|
|
40
|
+
series: "Series",
|
|
41
|
+
time: "Time",
|
|
42
|
+
"chart.bar": "Bar chart",
|
|
43
|
+
"chart.line": "Line chart",
|
|
44
|
+
"chart.area": "Area chart",
|
|
45
|
+
"chart.sparkline": "Trend",
|
|
46
|
+
"chart.pie": "Pie chart",
|
|
47
|
+
"chart.donut": "Donut chart",
|
|
48
|
+
actions: "Actions",
|
|
49
|
+
retry: "Retry",
|
|
50
|
+
loadMore: "Load more",
|
|
51
|
+
theme: "Theme",
|
|
52
|
+
mode: "Mode",
|
|
53
|
+
typeToConfirm: "Type {text} to confirm:",
|
|
54
|
+
textMismatch: "The text does not match.",
|
|
23
55
|
cancel: "Cancel",
|
|
24
56
|
close: "Close",
|
|
25
57
|
back: "Back",
|
|
@@ -36,15 +68,15 @@ const messages = {
|
|
|
36
68
|
dropFiles: "Drop files here or click to browse",
|
|
37
69
|
"validation.required": "This field is required.",
|
|
38
70
|
"validation.email": "Enter a valid email address.",
|
|
39
|
-
"validation.minLength": "Enter at least {min} characters.",
|
|
40
|
-
"validation.maxLength": "Enter at most {max} characters.",
|
|
71
|
+
"validation.minLength": { one: "Enter at least {min} character.", other: "Enter at least {min} characters." },
|
|
72
|
+
"validation.maxLength": { one: "Enter at most {max} character.", other: "Enter at most {max} characters." },
|
|
41
73
|
"validation.pattern": "The value has an invalid format.",
|
|
42
74
|
"validation.min": "The value must be at least {min}.",
|
|
43
75
|
"validation.max": "The value must be at most {max}.",
|
|
44
76
|
"validation.match": "The values do not match.",
|
|
45
77
|
"validation.invalid": "The value is invalid.",
|
|
46
78
|
"validation.fileSize": "{name} is larger than {max}.",
|
|
47
|
-
"validation.maxFiles": "At most {max} files are accepted.",
|
|
79
|
+
"validation.maxFiles": { one: "At most {max} file is accepted.", other: "At most {max} files are accepted." },
|
|
48
80
|
"validation.url": "Enter a valid address (https://, mailto: or tel:).",
|
|
49
81
|
"validation.dateRange": "The end date must not be before the start date.",
|
|
50
82
|
"validation.dateMin": "The date must be {min} or later.",
|
|
@@ -85,6 +117,38 @@ const messages = {
|
|
|
85
117
|
changePassword: "Jelszó módosítása",
|
|
86
118
|
rememberMe: "Emlékezz rám",
|
|
87
119
|
ok: "OK",
|
|
120
|
+
save: "Mentés",
|
|
121
|
+
"range.preset": "Időszak",
|
|
122
|
+
"range.custom": "Egyéni",
|
|
123
|
+
"range.last15m": "Utolsó 15 perc",
|
|
124
|
+
"range.last1h": "Utolsó óra",
|
|
125
|
+
"range.last24h": "Utolsó 24 óra",
|
|
126
|
+
"range.last7d": "Utolsó 7 nap",
|
|
127
|
+
"range.last30d": "Utolsó 30 nap",
|
|
128
|
+
copied: "Másolva",
|
|
129
|
+
copyFailed: "A másolás itt nem lehetséges.",
|
|
130
|
+
"tone.ok": "rendben",
|
|
131
|
+
"tone.warn": "figyelmeztetés",
|
|
132
|
+
"tone.bad": "kritikus",
|
|
133
|
+
"chart.zoomHint": "A diagram területe. A plusz és a mínusz nagyít, a nyilak mozgatnak, a 0 visszaállít.",
|
|
134
|
+
"chart.resetZoom": "Nagyítás visszaállítása",
|
|
135
|
+
menu: "Főmenü",
|
|
136
|
+
showAsTable: "Megjelenítés táblázatként",
|
|
137
|
+
series: "Adatsor",
|
|
138
|
+
time: "Idő",
|
|
139
|
+
"chart.bar": "Oszlopdiagram",
|
|
140
|
+
"chart.line": "Vonaldiagram",
|
|
141
|
+
"chart.area": "Területdiagram",
|
|
142
|
+
"chart.sparkline": "Trend",
|
|
143
|
+
"chart.pie": "Kördiagram",
|
|
144
|
+
"chart.donut": "Fánkdiagram",
|
|
145
|
+
actions: "Műveletek",
|
|
146
|
+
retry: "Újra",
|
|
147
|
+
loadMore: "Továbbiak betöltése",
|
|
148
|
+
theme: "Téma",
|
|
149
|
+
mode: "Mód",
|
|
150
|
+
typeToConfirm: "A megerősítéshez írja be: {text}",
|
|
151
|
+
textMismatch: "A szöveg nem egyezik.",
|
|
88
152
|
cancel: "Mégse",
|
|
89
153
|
close: "Bezár",
|
|
90
154
|
back: "Vissza",
|
|
@@ -154,11 +218,45 @@ export function addMessages(forLocale, texts) {
|
|
|
154
218
|
messages[forLocale] = { ...messages[forLocale], ...texts };
|
|
155
219
|
}
|
|
156
220
|
|
|
221
|
+
// The plural category of a count in a language ("one", "other", and for some languages "zero", "two", "few", "many"), from Intl.PluralRules.
|
|
222
|
+
function pluralCategory(count) {
|
|
223
|
+
try {
|
|
224
|
+
return new Intl.PluralRules(locale).select(Number(count));
|
|
225
|
+
} catch {
|
|
226
|
+
return "other";
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// A text of a message: a string, or an object with the plural forms ({ one: "...", other: "..." })
|
|
231
|
+
function pick(text, params) {
|
|
232
|
+
if (typeof text === "string" || text == null) return text;
|
|
233
|
+
const count = params.count;
|
|
234
|
+
const category = count == null ? "other" : pluralCategory(count);
|
|
235
|
+
// The exact number wins ("0": "No files"), then the category, then "other"
|
|
236
|
+
return text[String(count)] ?? text[category] ?? text.other ?? Object.values(text)[0];
|
|
237
|
+
}
|
|
238
|
+
|
|
157
239
|
/**
|
|
158
240
|
* Looks a text up in the current locale, then in its base language ("hu-HU" -> "hu"), then in English.
|
|
159
|
-
* Unknown keys are returned as they are.
|
|
241
|
+
* Unknown keys are returned as they are.
|
|
242
|
+
*
|
|
243
|
+
* 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).
|
|
244
|
+
* Plural forms: a message can be an object with the forms of the language, and the form is chosen by `params.count`:
|
|
245
|
+
*
|
|
246
|
+
* addMessages("en", { files: { zero: "No files", one: "{count} file", other: "{count:number} files" } });
|
|
247
|
+
* translate("files", { count: 1200 }) // "1,200 files"
|
|
248
|
+
*
|
|
249
|
+
* The keys are the categories of Intl.PluralRules for the language ("one", "other", and where the language has them "zero", "two", "few", "many"),
|
|
250
|
+
* or an exact number ("0"). "other" is the fallback.
|
|
160
251
|
*/
|
|
161
252
|
export function translate(key, params = {}) {
|
|
162
|
-
const
|
|
163
|
-
|
|
253
|
+
const found = messages[locale]?.[key] ?? messages[locale.split("-")[0]]?.[key] ?? messages.en[key];
|
|
254
|
+
const text = pick(found, params) ?? key;
|
|
255
|
+
return text.replace(/\{(\w+)(?::(number|date))?\}/g, (match, name, format) => {
|
|
256
|
+
const value = params[name];
|
|
257
|
+
if (value == null) return match;
|
|
258
|
+
if (format === "number") return new Intl.NumberFormat(locale).format(Number(value));
|
|
259
|
+
if (format === "date") return new Intl.DateTimeFormat(locale, { dateStyle: "medium" }).format(value instanceof Date ? value : new Date(value));
|
|
260
|
+
return value;
|
|
261
|
+
});
|
|
164
262
|
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
//theme manager for Athena UI
|
|
2
|
+
//Author: Csaba Tóth https://github.com/csabatibortoth/
|
|
3
|
+
//LICENCE: MIT
|
|
4
|
+
//Repository: https://github.com/csabatibortoth/athena-ui
|
|
5
|
+
|
|
6
|
+
// The look of an application: a theme (a set of colours) and a mode (light, dark, or whatever the system uses).
|
|
7
|
+
// Both are a choice of the person at this browser. They are kept in localStorage and put on <html> as
|
|
8
|
+
// data-theme and data-mode, which is what the stylesheets read:
|
|
9
|
+
//
|
|
10
|
+
// <html data-theme="ocean" data-mode="dark">
|
|
11
|
+
//
|
|
12
|
+
// [data-theme="ocean"][data-mode="light"] { --athena-bg: #f4f9fb; ... }
|
|
13
|
+
// [data-theme="ocean"][data-mode="dark"] { --athena-bg: #0b1c24; ... }
|
|
14
|
+
//
|
|
15
|
+
// Nothing is sent to a server. theme-boot.js (a classic script of its own) sets the two attributes before the page is
|
|
16
|
+
// drawn, so the wrong colours never flash.
|
|
17
|
+
|
|
18
|
+
export const DEFAULT_MODES = [
|
|
19
|
+
{ id: "system", name: "Like the system" },
|
|
20
|
+
{ id: "light", name: "Light" },
|
|
21
|
+
{ id: "dark", name: "Dark" }
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {object} options
|
|
26
|
+
* @param {{id: string, name?: string, description?: string}[]} options.themes the first one is the default
|
|
27
|
+
* @param {{id: string, name?: string}[]} [options.modes] default: system, light, dark. Ids "light" and "dark" are the ones that can be resolved
|
|
28
|
+
* @param {string} [options.storageKey="athena.appearance"] localStorage key (also give it to theme-boot.js)
|
|
29
|
+
* @param {string} [options.themeColorVariable] CSS variable whose value becomes <meta name="theme-color"> (the bar of a phone browser)
|
|
30
|
+
* @param {HTMLElement} [options.root] element that gets the attributes (default: <html>)
|
|
31
|
+
* @param {Storage} [options.storage] default: localStorage
|
|
32
|
+
* @returns {{themes, modes, appearance: () => object, setTheme: (id) => boolean, setMode: (id) => boolean,
|
|
33
|
+
* onChange: (listener) => Function, refresh: Function, destroy: Function}}
|
|
34
|
+
*/
|
|
35
|
+
export function createThemeManager(options = {}) {
|
|
36
|
+
const themes = options.themes ?? [];
|
|
37
|
+
if (!themes.length) throw new Error("Athena UI: createThemeManager needs at least one theme");
|
|
38
|
+
const modes = options.modes ?? DEFAULT_MODES;
|
|
39
|
+
const key = options.storageKey ?? "athena.appearance";
|
|
40
|
+
const root = options.root ?? document.documentElement;
|
|
41
|
+
const storage = options.storage ?? globalThis.localStorage;
|
|
42
|
+
const view = root.ownerDocument.defaultView ?? globalThis;
|
|
43
|
+
const listeners = new Set();
|
|
44
|
+
const systemDark = () => view.matchMedia?.("(prefers-color-scheme: dark)");
|
|
45
|
+
|
|
46
|
+
const read = () => {
|
|
47
|
+
try {
|
|
48
|
+
const saved = JSON.parse(storage?.getItem(key) || "{}");
|
|
49
|
+
return {
|
|
50
|
+
theme: themes.some(theme => theme.id === saved.theme) ? saved.theme : themes[0].id,
|
|
51
|
+
mode: modes.some(mode => mode.id === saved.mode) ? saved.mode : "system"
|
|
52
|
+
};
|
|
53
|
+
} catch {
|
|
54
|
+
return { theme: themes[0].id, mode: "system" };
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
let current = read();
|
|
59
|
+
const appearance = () => ({ ...current, dark: root.dataset.mode === "dark" });
|
|
60
|
+
|
|
61
|
+
function apply() {
|
|
62
|
+
const dark = current.mode === "dark" || (current.mode === "system" && Boolean(systemDark()?.matches));
|
|
63
|
+
root.dataset.theme = current.theme;
|
|
64
|
+
root.dataset.mode = dark ? "dark" : "light";
|
|
65
|
+
if (options.themeColorVariable) {
|
|
66
|
+
const doc = root.ownerDocument;
|
|
67
|
+
let meta = doc.querySelector('meta[name="theme-color"]');
|
|
68
|
+
if (!meta) {
|
|
69
|
+
meta = doc.createElement("meta");
|
|
70
|
+
meta.name = "theme-color";
|
|
71
|
+
doc.head.append(meta);
|
|
72
|
+
}
|
|
73
|
+
const color = view.getComputedStyle(root).getPropertyValue(options.themeColorVariable).trim();
|
|
74
|
+
if (color) meta.content = color;
|
|
75
|
+
}
|
|
76
|
+
listeners.forEach(listener => listener(appearance()));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function save(change) {
|
|
80
|
+
current = { ...current, ...change };
|
|
81
|
+
try {
|
|
82
|
+
storage?.setItem(key, JSON.stringify(current));
|
|
83
|
+
} catch {
|
|
84
|
+
// Not saved (private browsing, full storage), but it works until the page is closed
|
|
85
|
+
}
|
|
86
|
+
apply();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const onSystemChange = () => { if (current.mode === "system") apply(); };
|
|
90
|
+
const onStorage = event => {
|
|
91
|
+
if (event.key !== key) return; // another tab changed it
|
|
92
|
+
current = read();
|
|
93
|
+
apply();
|
|
94
|
+
};
|
|
95
|
+
const media = systemDark();
|
|
96
|
+
media?.addEventListener?.("change", onSystemChange);
|
|
97
|
+
view.addEventListener?.("storage", onStorage);
|
|
98
|
+
apply();
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
themes,
|
|
102
|
+
modes,
|
|
103
|
+
appearance,
|
|
104
|
+
/** Chooses a theme. Returns false (and changes nothing) for one that does not exist. */
|
|
105
|
+
setTheme(id) {
|
|
106
|
+
if (!themes.some(theme => theme.id === id)) return false;
|
|
107
|
+
save({ theme: id });
|
|
108
|
+
return true;
|
|
109
|
+
},
|
|
110
|
+
/** Chooses a mode. Returns false (and changes nothing) for one that does not exist. */
|
|
111
|
+
setMode(id) {
|
|
112
|
+
if (!modes.some(mode => mode.id === id)) return false;
|
|
113
|
+
save({ mode: id });
|
|
114
|
+
return true;
|
|
115
|
+
},
|
|
116
|
+
/** Called with { theme, mode, dark } now, and whenever the look changes. Returns a function that stops it. */
|
|
117
|
+
onChange(listener) {
|
|
118
|
+
listeners.add(listener);
|
|
119
|
+
listener(appearance());
|
|
120
|
+
return () => listeners.delete(listener);
|
|
121
|
+
},
|
|
122
|
+
/** The stylesheet may have loaded after the first call: read the colours (theme-color) again. */
|
|
123
|
+
refresh: apply,
|
|
124
|
+
/** Stops listening to the system and to other tabs. */
|
|
125
|
+
destroy() {
|
|
126
|
+
media?.removeEventListener?.("change", onSystemChange);
|
|
127
|
+
view.removeEventListener?.("storage", onStorage);
|
|
128
|
+
listeners.clear();
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
@@ -31,8 +31,8 @@ export function validateValue(value, rules = {}, values = {}) {
|
|
|
31
31
|
if (isEmpty(value)) return rules.required ? translate("validation.required") : "";
|
|
32
32
|
const text = String(value);
|
|
33
33
|
if (rules.email && !EMAIL_PATTERN.test(text)) return translate("validation.email");
|
|
34
|
-
if (rules.minLength != null && text.length < rules.minLength) return translate("validation.minLength", { min: rules.minLength });
|
|
35
|
-
if (rules.maxLength != null && text.length > rules.maxLength) return translate("validation.maxLength", { max: rules.maxLength });
|
|
34
|
+
if (rules.minLength != null && text.length < rules.minLength) return translate("validation.minLength", { min: rules.minLength, count: rules.minLength });
|
|
35
|
+
if (rules.maxLength != null && text.length > rules.maxLength) return translate("validation.maxLength", { max: rules.maxLength, count: rules.maxLength });
|
|
36
36
|
if (rules.pattern != null && !new RegExp(rules.pattern).test(text)) return translate("validation.pattern");
|
|
37
37
|
if (rules.min != null && Number(value) < rules.min) return translate("validation.min", { min: rules.min });
|
|
38
38
|
if (rules.max != null && Number(value) > rules.max) return translate("validation.max", { max: rules.max });
|
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
//LICENCE: MIT
|
|
4
4
|
//Repository: https://github.com/csabatibortoth/athena-ui
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { HTMLElementGenerator } from "../HTMLElementGenerator/src/HTMLElementGenerator.js";
|
|
6
|
+
import { HTMLElementGenerator } from "../../core/elementGenerator.js";
|
|
9
7
|
import config, { withBorder } from "../../config/config.js";
|
|
10
8
|
import { generateHeaderContent } from "./headerContentGenerator.js";
|
|
11
9
|
import { generateWrapperContent } from "./wrapperContentGenerator.js";
|
|
@@ -20,6 +18,14 @@ function generateSection(id, className, parent = "container") {
|
|
|
20
18
|
});
|
|
21
19
|
}
|
|
22
20
|
|
|
21
|
+
// The element (by id) the container is generated into. Empty: the body, like init(). createApp({ root }) sets it.
|
|
22
|
+
let layoutRoot = "";
|
|
23
|
+
|
|
24
|
+
/** Chooses where generateContainer() puts the page layout: the id of an element, or "" for the body. */
|
|
25
|
+
export function setLayoutRoot(id = "") {
|
|
26
|
+
layoutRoot = id;
|
|
27
|
+
}
|
|
28
|
+
|
|
23
29
|
export function generateBasicLayout() {
|
|
24
30
|
generateContainer();
|
|
25
31
|
if (config.generateHeader) generateHeader();
|
|
@@ -28,7 +34,7 @@ export function generateBasicLayout() {
|
|
|
28
34
|
}
|
|
29
35
|
|
|
30
36
|
export function generateContainer() {
|
|
31
|
-
generateSection("container", config.container_class,
|
|
37
|
+
generateSection("container", config.container_class, layoutRoot);
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
/* HEADER ELEMENT GENERATION */
|
|
@@ -39,7 +45,7 @@ export function generateHeader() {
|
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
export function clearHeader() {
|
|
42
|
-
|
|
48
|
+
document.getElementById("header")?.replaceChildren();
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
/* WRAPPER ELEMENT GENERATION */
|
|
@@ -50,7 +56,7 @@ export function generateWrapper() {
|
|
|
50
56
|
}
|
|
51
57
|
|
|
52
58
|
export function clearWrapper() {
|
|
53
|
-
|
|
59
|
+
document.getElementById("wrapper")?.replaceChildren();
|
|
54
60
|
}
|
|
55
61
|
|
|
56
62
|
/* FOOTER ELEMENT GENERATION */
|
|
@@ -61,5 +67,5 @@ export function generateFooter() {
|
|
|
61
67
|
}
|
|
62
68
|
|
|
63
69
|
export function clearFooter() {
|
|
64
|
-
|
|
70
|
+
document.getElementById("footer")?.replaceChildren();
|
|
65
71
|
}
|
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
//LICENCE: MIT
|
|
4
4
|
//Repository: https://github.com/csabatibortoth/athena-ui
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { HTMLElementGenerator } from "../HTMLElementGenerator/src/HTMLElementGenerator.js";
|
|
6
|
+
import { HTMLElementGenerator } from "../../core/elementGenerator.js";
|
|
9
7
|
import config, { withBorder } from "../../config/config.js";
|
|
10
8
|
import { getMenuItems } from "../../config/hooks.js";
|
|
11
9
|
import { generateBasicMenu, defaultMenuItems } from "../MenuGenerator/basicMenuGenerator.js";
|
|
@@ -25,7 +23,7 @@ export function generateFooterMenu() {
|
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
export function clearFooterMenu() {
|
|
28
|
-
|
|
26
|
+
document.getElementById("footer_menu")?.replaceChildren();
|
|
29
27
|
}
|
|
30
28
|
|
|
31
29
|
export function generateFooterCopyrightText() {
|
|
@@ -3,12 +3,11 @@
|
|
|
3
3
|
//LICENCE: MIT
|
|
4
4
|
//Repository: https://github.com/csabatibortoth/athena-ui
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { HTMLElementGenerator } from "../HTMLElementGenerator/src/HTMLElementGenerator.js";
|
|
6
|
+
import { HTMLElementGenerator } from "../../core/elementGenerator.js";
|
|
9
7
|
import config, { withBorder } from "../../config/config.js";
|
|
10
8
|
import { getMenuItems } from "../../config/hooks.js";
|
|
11
9
|
import { generateBasicMenu, defaultMenuItems } from "../MenuGenerator/basicMenuGenerator.js";
|
|
10
|
+
import { generateMenu } from "../MenuGenerator/menuGenerator.js";
|
|
12
11
|
|
|
13
12
|
export function generateHeaderContent() {
|
|
14
13
|
generateContaninerForElements({ parent: "header", id: "header_logo_container", text: "" });
|
|
@@ -19,7 +18,15 @@ export function generateHeaderContent() {
|
|
|
19
18
|
generateHeaderMenu();
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Generates the menu of the header. Without options it is built from the global `menuItems` / nav callback, as before.
|
|
23
|
+
* With `options.items` it is a generateMenu (no globals): `generateHeaderMenu({ items, onNavigate, active, layout, followHash })`.
|
|
24
|
+
*/
|
|
25
|
+
export function generateHeaderMenu(options) {
|
|
26
|
+
if (options?.items) {
|
|
27
|
+
document.getElementById("header_menu_container")?.replaceChildren();
|
|
28
|
+
return generateMenu({ ...options, parent: "header_menu_container", id: options.id ?? "header_menu" });
|
|
29
|
+
}
|
|
23
30
|
generateBasicMenu({
|
|
24
31
|
parent: "header_menu_container",
|
|
25
32
|
menu_id: "header_menu",
|
|
@@ -29,7 +36,7 @@ export function generateHeaderMenu() {
|
|
|
29
36
|
}
|
|
30
37
|
|
|
31
38
|
export function clearHeaderMenu() {
|
|
32
|
-
|
|
39
|
+
document.getElementById("header_menu_container")?.replaceChildren();
|
|
33
40
|
}
|
|
34
41
|
|
|
35
42
|
export function generateHeaderTitle() {
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
//LICENCE: MIT
|
|
4
4
|
//Repository: https://github.com/csabatibortoth/athena-ui
|
|
5
5
|
|
|
6
|
-
/* global HTMLControlGenerator */
|
|
7
6
|
|
|
8
|
-
import { HTMLElementGenerator } from "
|
|
7
|
+
import { HTMLElementGenerator } from "../../core/elementGenerator.js";
|
|
9
8
|
import { BORDERED_CLASS } from "../../config/config.js";
|
|
10
9
|
import { getNav } from "../../config/hooks.js";
|
|
11
10
|
import { el, uid } from "../../core/dom.js";
|
|
11
|
+
import { generateControl } from "../../core/controls.js";
|
|
12
12
|
|
|
13
13
|
// Placeholder items used when the application does not provide menuItems.
|
|
14
14
|
export function defaultMenuItems(menuId, count = 3) {
|
|
@@ -34,7 +34,7 @@ export function generateMenuWireFrame(options) {
|
|
|
34
34
|
const menuClass = [options.menu_class, options.bordered && BORDERED_CLASS, options.class]
|
|
35
35
|
.filter(Boolean)
|
|
36
36
|
.join(" ");
|
|
37
|
-
|
|
37
|
+
generateControl({
|
|
38
38
|
inputType: "ul",
|
|
39
39
|
parent: options.parent,
|
|
40
40
|
id: options.menu_id,
|