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.
Files changed (124) hide show
  1. package/README.md +100 -54
  2. package/docs/migration-2.0.md +83 -0
  3. package/docs/styling.md +86 -0
  4. package/package.json +108 -25
  5. package/src/athena-ui.js +54 -97
  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 -9
  19. package/src/libs/core/controls.js +6 -14
  20. package/src/libs/core/cookies.js +55 -0
  21. package/src/libs/core/i18n.js +40 -6
  22. package/src/libs/core/validation.js +2 -2
  23. package/src/libs/hephaestus/LayoutGenerator/basicLayoutGenerator.js +9 -1
  24. package/src/libs/hephaestus/MenuGenerator/menuGenerator.js +16 -4
  25. package/src/libs/hephaestus/auth/session.js +1 -1
  26. package/src/libs/hephaestus/dialogGenerator/dialogGenerator.js +25 -17
  27. package/src/libs/hephaestus/formGenerator/changePasswordFormGenerator.js +4 -4
  28. package/src/libs/hephaestus/formGenerator/formUtils.js +0 -4
  29. package/src/libs/hephaestus/formGenerator/loginFormGenerator.js +2 -3
  30. package/src/libs/hephaestus/formGenerator/registrationFormGenerator.js +3 -3
  31. package/src/libs/hephaestus/hephaestus.js +0 -10
  32. package/src/libs/hephaestus/inputGenerator/dropZoneGenerator.js +1 -1
  33. package/src/libs/hephaestus/modalGenerator/modalGenerator.js +13 -6
  34. package/src/libs/hephaestus/navigationGenerator/navigationGenerator.js +20 -24
  35. package/src/menu.js +6 -0
  36. package/src/navigation.js +6 -0
  37. package/src/res/themes/default/style.css +97 -100
  38. package/src/res/themes/tokens.css +96 -0
  39. package/src/router.js +6 -0
  40. package/src/sanitize.js +6 -0
  41. package/src/session.js +8 -0
  42. package/src/table.js +6 -0
  43. package/src/testing.js +11 -1
  44. package/src/theme.js +7 -0
  45. package/src/validation.js +6 -0
  46. package/types/athena-ui.d.ts +96 -0
  47. package/types/chart.d.ts +1 -0
  48. package/types/classic.d.ts +1 -0
  49. package/types/components.d.ts +1 -0
  50. package/types/controls.d.ts +3 -0
  51. package/types/csv.d.ts +1 -0
  52. package/types/dialog.d.ts +2 -0
  53. package/types/dom.d.ts +1 -0
  54. package/types/feedback.d.ts +1 -0
  55. package/types/format.d.ts +1 -0
  56. package/types/forms.d.ts +2 -0
  57. package/types/i18n.d.ts +1 -0
  58. package/types/inputs.d.ts +4 -0
  59. package/types/libs/config/config.d.ts +96 -0
  60. package/types/libs/config/hooks.d.ts +8 -0
  61. package/types/libs/core/combobox.d.ts +10 -0
  62. package/types/libs/core/controls.d.ts +28 -0
  63. package/types/libs/core/cookies.d.ts +27 -0
  64. package/types/libs/core/csv.d.ts +12 -0
  65. package/types/libs/core/dateRange.d.ts +72 -0
  66. package/types/libs/core/dom.d.ts +65 -0
  67. package/types/libs/core/elementGenerator.d.ts +30 -0
  68. package/types/libs/core/errors.d.ts +29 -0
  69. package/types/libs/core/focus.d.ts +6 -0
  70. package/types/libs/core/format.d.ts +21 -0
  71. package/types/libs/core/hungarianControls.d.ts +2 -0
  72. package/types/libs/core/i18n.d.ts +17 -0
  73. package/types/libs/core/pagination.d.ts +5 -0
  74. package/types/libs/core/sanitize.d.ts +6 -0
  75. package/types/libs/core/tableMath.d.ts +26 -0
  76. package/types/libs/core/theme.d.ts +39 -0
  77. package/types/libs/core/validation.d.ts +56 -0
  78. package/types/libs/hephaestus/LayoutGenerator/basicLayoutGenerator.d.ts +10 -0
  79. package/types/libs/hephaestus/LayoutGenerator/footerContentGenerator.d.ts +4 -0
  80. package/types/libs/hephaestus/LayoutGenerator/headerContentGenerator.d.ts +20 -0
  81. package/types/libs/hephaestus/LayoutGenerator/wrapperContentGenerator.d.ts +1 -0
  82. package/types/libs/hephaestus/MenuGenerator/basicMenuGenerator.d.ts +14 -0
  83. package/types/libs/hephaestus/MenuGenerator/menuGenerator.d.ts +65 -0
  84. package/types/libs/hephaestus/auth/authState.d.ts +26 -0
  85. package/types/libs/hephaestus/auth/session.d.ts +26 -0
  86. package/types/libs/hephaestus/chartGenerator/chartGenerator.d.ts +91 -0
  87. package/types/libs/hephaestus/componentGenerator/componentGenerator.d.ts +222 -0
  88. package/types/libs/hephaestus/componentGenerator/themePicker.d.ts +24 -0
  89. package/types/libs/hephaestus/dialogGenerator/dialogGenerator.d.ts +120 -0
  90. package/types/libs/hephaestus/feedbackGenerator/feedbackGenerator.d.ts +86 -0
  91. package/types/libs/hephaestus/formGenerator/authForms.d.ts +122 -0
  92. package/types/libs/hephaestus/formGenerator/changePasswordFormGenerator.d.ts +6 -0
  93. package/types/libs/hephaestus/formGenerator/formBuilder.d.ts +113 -0
  94. package/types/libs/hephaestus/formGenerator/formUtils.d.ts +8 -0
  95. package/types/libs/hephaestus/formGenerator/loginFormGenerator.d.ts +11 -0
  96. package/types/libs/hephaestus/formGenerator/lostPasswordFormGenerator.d.ts +4 -0
  97. package/types/libs/hephaestus/formGenerator/registrationFormGenerator.d.ts +7 -0
  98. package/types/libs/hephaestus/hephaestus.d.ts +3 -0
  99. package/types/libs/hephaestus/inputGenerator/dropZoneGenerator.d.ts +48 -0
  100. package/types/libs/hephaestus/inputGenerator/inputGenerator.d.ts +185 -0
  101. package/types/libs/hephaestus/inputGenerator/richTextGenerator.d.ts +49 -0
  102. package/types/libs/hephaestus/modalGenerator/modalGenerator.d.ts +2 -0
  103. package/types/libs/hephaestus/navigationGenerator/navigationGenerator.d.ts +150 -0
  104. package/types/libs/hephaestus/router/matchRoute.d.ts +12 -0
  105. package/types/libs/hephaestus/router/router.d.ts +67 -0
  106. package/types/libs/hephaestus/tableGenerator/tableGenerator.d.ts +120 -0
  107. package/types/menu.d.ts +1 -0
  108. package/types/navigation.d.ts +1 -0
  109. package/types/res/themes/themes.d.ts +7 -0
  110. package/types/router.d.ts +1 -0
  111. package/types/sanitize.d.ts +1 -0
  112. package/types/session.d.ts +3 -0
  113. package/types/table.d.ts +1 -0
  114. package/types/testing.d.ts +27 -0
  115. package/types/theme-boot.d.ts +0 -0
  116. package/types/theme.d.ts +2 -0
  117. package/types/validation.d.ts +1 -0
  118. package/src/libs/crypto-js/LICENSE +0 -24
  119. package/src/libs/crypto-js/crypto-js.js +0 -6657
  120. package/src/libs/js-cookie/LICENSE +0 -21
  121. package/src/libs/js-cookie/src/api.mjs +0 -103
  122. package/src/libs/js-cookie/src/assign.mjs +0 -10
  123. package/src/libs/js-cookie/src/converter.mjs +0 -14
  124. package/src/libs/libs.js +0 -13
@@ -68,15 +68,15 @@ const messages = {
68
68
  dropFiles: "Drop files here or click to browse",
69
69
  "validation.required": "This field is required.",
70
70
  "validation.email": "Enter a valid email address.",
71
- "validation.minLength": "Enter at least {min} characters.",
72
- "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." },
73
73
  "validation.pattern": "The value has an invalid format.",
74
74
  "validation.min": "The value must be at least {min}.",
75
75
  "validation.max": "The value must be at most {max}.",
76
76
  "validation.match": "The values do not match.",
77
77
  "validation.invalid": "The value is invalid.",
78
78
  "validation.fileSize": "{name} is larger than {max}.",
79
- "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." },
80
80
  "validation.url": "Enter a valid address (https://, mailto: or tel:).",
81
81
  "validation.dateRange": "The end date must not be before the start date.",
82
82
  "validation.dateMin": "The date must be {min} or later.",
@@ -218,11 +218,45 @@ export function addMessages(forLocale, texts) {
218
218
  messages[forLocale] = { ...messages[forLocale], ...texts };
219
219
  }
220
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
+
221
239
  /**
222
240
  * Looks a text up in the current locale, then in its base language ("hu-HU" -> "hu"), then in English.
223
- * Unknown keys are returned as they are. {name} placeholders are replaced from params.
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.
224
251
  */
225
252
  export function translate(key, params = {}) {
226
- const text = messages[locale]?.[key] ?? messages[locale.split("-")[0]]?.[key] ?? messages.en[key] ?? key;
227
- return text.replace(/\{(\w+)\}/g, (match, name) => params[name] ?? match);
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
+ });
228
262
  }
@@ -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 });
@@ -18,6 +18,14 @@ function generateSection(id, className, parent = "container") {
18
18
  });
19
19
  }
20
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
+
21
29
  export function generateBasicLayout() {
22
30
  generateContainer();
23
31
  if (config.generateHeader) generateHeader();
@@ -26,7 +34,7 @@ export function generateBasicLayout() {
26
34
  }
27
35
 
28
36
  export function generateContainer() {
29
- generateSection("container", config.container_class, "");
37
+ generateSection("container", config.container_class, layoutRoot);
30
38
  }
31
39
 
32
40
  /* HEADER ELEMENT GENERATION */
@@ -8,6 +8,20 @@ import { translate } from "../../core/i18n.js";
8
8
  import { isSafeUrl } from "../../core/sanitize.js";
9
9
  import { initialsOf } from "../componentGenerator/componentGenerator.js";
10
10
 
11
+ /**
12
+ * @typedef {object} MenuItem
13
+ * @property {string} id
14
+ * @property {string} label
15
+ * @property {string|Node} [icon]
16
+ * @property {string} [href]
17
+ * @property {boolean} [disabled]
18
+ * @property {"end"} [align]
19
+ * @property {number|string|{text: (number|string), tone?: "info"|"ok"|"warn"|"bad"}} [badge]
20
+ * @property {string} [badgeLabel]
21
+ * @property {{name: string, src?: string}} [avatar]
22
+ * @property {MenuItem[]} [children]
23
+ */
24
+
11
25
  const ENABLED = "[role=menuitem]:not([aria-disabled=true]):not(:disabled)";
12
26
 
13
27
  /** The text of a badge: numbers above 99 become "99+", 0 / null / false / "" mean no badge. */
@@ -22,15 +36,13 @@ export function badgeText(value) {
22
36
  *
23
37
  * @param {object} options
24
38
  * @param {string|Element} [options.parent]
25
- * @param {{id: string, label: string, icon?: string|Node, href?: string, disabled?: boolean, align?: "end",
26
- * badge?: number|string|{text: (number|string), tone?: "info"|"ok"|"warn"|"bad"}, badgeLabel?: string,
27
- * avatar?: {name: string, src?: string}, children?: object[]}[]} options.items
39
+ * @param {MenuItem[]} options.items
28
40
  * `icon` is shown before the label (text, or a Node such as an SVG; it is hidden from screen readers).
29
41
  * `badge` is a small count or word after the label (0, null and "" show nothing, numbers above 99 show "99+").
30
42
  * `badgeLabel` is what a screen reader hears for it ("3 unread"); without it the badge text is read after the label.
31
43
  * `avatar` shows the picture (or the initials) of a person: for the user menu, usually with `align: "end"` and children.
32
44
  * An item with `children` opens a group; a child can have children too (a group inside a group, any depth).
33
- * @param {(item: object, event: Event) => void} [options.onNavigate] called when a PERSON uses an item (click, Enter, Space).
45
+ * @param {(item: MenuItem, event: Event) => void} [options.onNavigate] called when a PERSON uses an item (click, Enter, Space).
34
46
  * It is never called by select() or while the menu is built.
35
47
  * @param {string} [options.active] id of the item that is the current page at the start
36
48
  * @param {boolean} [options.followHash=false] the item whose `href` equals location.hash is the active one, and follows hashchange
@@ -4,7 +4,7 @@
4
4
  //Repository: https://github.com/csabatibortoth/athena-ui
5
5
 
6
6
  import config from "../../config/config.js";
7
- import Cookies from "../../js-cookie/src/api.mjs";
7
+ import Cookies from "../../core/cookies.js";
8
8
 
9
9
  // The session is kept in a cookie, so the page knows after a reload who is logged in.
10
10
  // A cookie written from script can be read by any script of the page: keep only what the UI needs
@@ -4,7 +4,6 @@
4
4
  //Repository: https://github.com/csabatibortoth/athena-ui
5
5
 
6
6
  import { cx, el, setContent, uid } from "../../core/dom.js";
7
- import { trapFocus } from "../../core/focus.js";
8
7
  import { translate } from "../../core/i18n.js";
9
8
  import { generateButton, generateForm } from "../formGenerator/formBuilder.js";
10
9
 
@@ -20,7 +19,7 @@ import { generateButton, generateForm } from "../formGenerator/formBuilder.js";
20
19
  * @param {(value) => (boolean|Promise<boolean>)} [options.beforeClose] return false to keep the dialog open
21
20
  * @param {"small"|"medium"|"large"|"full"} [options.size="medium"] width of the dialog (360 / 480 / 720 px / the whole window)
22
21
  * @param {string} [options.class] extra CSS class(es) of the dialog element
23
- * @returns {Promise<*> & {element: HTMLElement, backdrop: HTMLElement, close: (value?) => Promise<void>}}
22
+ * @returns {Promise<*> & {element: HTMLDialogElement, backdrop: HTMLDialogElement, close: (value?) => Promise<void>}}
24
23
  * resolves with the pressed button's value; the promise also carries the handle of the open dialog
25
24
  */
26
25
  export function showDialog(options = {}) {
@@ -30,15 +29,16 @@ export function showDialog(options = {}) {
30
29
  const titleId = uid("dialog-title");
31
30
  const body = setContent(el("div", { class: "dialog-body" }), content);
32
31
  const footer = el("div", { class: "dialog-footer" });
33
- const dialog = el("div", {
34
- class: cx("modal-content dialog", options.size && `dialog-${options.size}`, options.class),
35
- attrs: { role: "dialog", "aria-modal": "true", "aria-labelledby": title ? titleId : null }
36
- });
37
- if (title) dialog.append(el("h2", { class: "dialog-title", id: titleId, text: title }));
38
- dialog.append(body, footer);
39
- const backdrop = el("div", { class: "modal dialog-backdrop" }, dialog);
32
+ // A native <dialog>, opened with showModal(): the browser traps the focus, closes it with Esc, puts it above everything (the top layer),
33
+ // makes the page behind it inert, draws the backdrop (::backdrop) and gives the focus back. No inline style is needed.
34
+ const inner = el("div", { class: "dialog-inner" });
35
+ const dialog = el("dialog", {
36
+ class: cx("dialog", options.size && `dialog-${options.size}`, options.class),
37
+ attrs: { "aria-labelledby": title ? titleId : null }
38
+ }, inner);
39
+ if (title) inner.append(el("h2", { class: "dialog-title", id: titleId, text: title }));
40
+ inner.append(body, footer);
40
41
 
41
- let release = () => {};
42
42
  let closing = false;
43
43
  const close = async value => {
44
44
  if (closing) return;
@@ -47,19 +47,25 @@ export function showDialog(options = {}) {
47
47
  closing = false;
48
48
  return;
49
49
  }
50
- release();
51
- backdrop.remove();
50
+ if (dialog.open) dialog.close();
51
+ dialog.remove();
52
52
  resolve(value);
53
53
  };
54
54
 
55
+ // Esc: the browser asks (cancel); a dialog that cannot be dismissed stays, and beforeClose can still say no
56
+ dialog.addEventListener("cancel", event => {
57
+ event.preventDefault();
58
+ if (dismissible) close(null);
59
+ });
55
60
  if (dismissible) {
56
- dialog.prepend(el("button", {
61
+ inner.prepend(el("button", {
57
62
  class: "dialog-close",
58
63
  text: "×",
59
64
  attrs: { type: "button", "aria-label": translate("close") },
60
65
  on: { click: () => close(null) }
61
66
  }));
62
- backdrop.addEventListener("mousedown", event => { if (event.target === backdrop) close(null); });
67
+ // A click on the backdrop lands on the dialog element itself (its content fills it up to the edge)
68
+ dialog.addEventListener("mousedown", event => { if (event.target === dialog) close(null); });
63
69
  }
64
70
  for (const spec of buttons) {
65
71
  const { element } = generateButton({
@@ -71,10 +77,12 @@ export function showDialog(options = {}) {
71
77
  if (spec.autofocus) element.dataset.autofocus = "true";
72
78
  }
73
79
 
74
- document.body.append(backdrop);
75
- release = trapFocus(dialog, { onEscape: dismissible ? () => close(null) : undefined });
80
+ document.body.append(dialog);
81
+ // Without showModal (an old browser, or jsdom without athena-ui-js/testing) it is opened as a plain, non-modal dialog.
82
+ if (typeof dialog.showModal === "function") dialog.showModal();
83
+ else dialog.setAttribute("open", "");
76
84
  dialog.querySelector("[data-autofocus]")?.focus();
77
- handle = { element: dialog, backdrop, close: value => close(value ?? null) };
85
+ handle = { element: dialog, backdrop: dialog, close: value => close(value ?? null) };
78
86
  });
79
87
  // The executor above runs synchronously, so the handle exists here.
80
88
  return Object.assign(promise, handle);
@@ -7,15 +7,15 @@ import config from "../../config/config.js";
7
7
  import { getChangePassword } from "../../config/hooks.js";
8
8
  import { translate } from "../../core/i18n.js";
9
9
  import { validateAll } from "../../core/validation.js";
10
- import { generateButton, generateField, generateFormDiv, generateMessage, hashPassword, readControl, showMessage } from "./formUtils.js";
10
+ import { generateButton, generateField, generateFormDiv, generateMessage, readControl, showMessage } from "./formUtils.js";
11
11
 
12
12
  const FORM_ID = "changePasswordForm";
13
13
 
14
- // Reads the form. Both passwords are SHA-256 hashed when enable_encrypt_password is set.
14
+ // Reads the form. The passwords are returned as typed: send them over HTTPS and hash them on the server.
15
15
  export function getChangePasswordFormData() {
16
16
  return {
17
- currentPassword: hashPassword(readControl(FORM_ID, "current")),
18
- newPassword: hashPassword(readControl(FORM_ID, "new"))
17
+ currentPassword: readControl(FORM_ID, "current"),
18
+ newPassword: readControl(FORM_ID, "new")
19
19
  };
20
20
  }
21
21
 
@@ -61,7 +61,3 @@ export function showMessage(formId, text, isError = true) {
61
61
  export function readControl(formId, name) {
62
62
  return document.getElementById(`${formId}-${name}-control`)?.value ?? "";
63
63
  }
64
-
65
- export function hashPassword(password) {
66
- return config.enable_encrypt_password ? CryptoJS.SHA256(password).toString() : password;
67
- }
@@ -41,12 +41,11 @@ function generateField(name, label, inputType) {
41
41
  });
42
42
  }
43
43
 
44
- // Reads the form. The password is SHA-256 hashed when enable_encrypt_password is set.
44
+ // Reads the form. The password is returned as typed: send it over HTTPS and hash it on the server.
45
45
  // `remember` is included when the login_remember_me setting shows the checkbox.
46
46
  export function getLoginFormData() {
47
47
  const username = document.getElementById(`${FORM_ID}-username-control`)?.value;
48
- let password = document.getElementById(`${FORM_ID}-password-control`)?.value;
49
- if (config.enable_encrypt_password) password = CryptoJS.SHA256(password).toString();
48
+ const password = document.getElementById(`${FORM_ID}-password-control`)?.value;
50
49
  const data = { username, password };
51
50
  const remember = document.getElementById(`${FORM_ID}-remember-control`);
52
51
  if (remember) data.remember = remember.checked;
@@ -7,16 +7,16 @@ import config from "../../config/config.js";
7
7
  import { getRegister } from "../../config/hooks.js";
8
8
  import { translate } from "../../core/i18n.js";
9
9
  import { validateAll } from "../../core/validation.js";
10
- import { generateButton, generateField, generateFormDiv, generateMessage, hashPassword, readControl, showMessage } from "./formUtils.js";
10
+ import { generateButton, generateField, generateFormDiv, generateMessage, readControl, showMessage } from "./formUtils.js";
11
11
 
12
12
  const FORM_ID = "registrationForm";
13
13
 
14
- // Reads the form. The password is SHA-256 hashed when enable_encrypt_password is set.
14
+ // Reads the form. The password is returned as typed: send it over HTTPS and hash it on the server.
15
15
  export function getRegistrationFormData() {
16
16
  return {
17
17
  username: readControl(FORM_ID, "username"),
18
18
  email: readControl(FORM_ID, "email"),
19
- password: hashPassword(readControl(FORM_ID, "password"))
19
+ password: readControl(FORM_ID, "password")
20
20
  };
21
21
  }
22
22
 
@@ -3,7 +3,6 @@
3
3
  //LICENCE: MIT
4
4
  //Repository: https://github.com/csabatibortoth/athena-ui
5
5
 
6
- import libs from "../libs.js";
7
6
  import themes from "../../res/themes/themes.js";
8
7
 
9
8
  const loadedScripts = new Map();
@@ -28,15 +27,6 @@ export function loadScript(src) {
28
27
  return loadedScripts.get(src);
29
28
  }
30
29
 
31
- /**
32
- * Loads the classic scripts that are still needed: only crypto-js, and only when the deprecated enable_encrypt_password is on.
33
- * Athena UI has no other classic script, and does not need jQuery.
34
- */
35
- export function loadLibs(extraScripts = [], { crypto = false } = {}) {
36
- const wanted = libs.filter(lib => (lib.needs === "crypto" ? crypto : true));
37
- return Promise.all([...wanted.map(lib => lib.src), ...extraScripts].map(loadScript));
38
- }
39
-
40
30
  // Accepts { id } of a registered theme or a custom { href }. Falls back to the default theme.
41
31
  export function resolveTheme(selected) {
42
32
  if (selected?.href) return selected;
@@ -57,7 +57,7 @@ export function createDropZone(options = {}) {
57
57
  for (const file of list) {
58
58
  if (!matchesAccept(file, accept)) rejected.push({ file, reason: `${translate("validation.pattern")} (${file.name})` });
59
59
  else if (maxSize != null && file.size > maxSize) rejected.push({ file, reason: translate("validation.fileSize", { name: file.name, max: formatBytes(maxSize) }) });
60
- else if (maxFiles != null && valid.length >= maxFiles) rejected.push({ file, reason: translate("validation.maxFiles", { max: maxFiles }) });
60
+ else if (maxFiles != null && valid.length >= maxFiles) rejected.push({ file, reason: translate("validation.maxFiles", { max: maxFiles, count: maxFiles }) });
61
61
  else valid.push(file);
62
62
  }
63
63
  if (valid.length) options.onDrop?.(valid);
@@ -13,6 +13,7 @@ const releases = new Map();
13
13
  export function openModal(id = DEFAULT_MODAL_ID) {
14
14
  const modal = document.getElementById(id);
15
15
  if (!modal) return;
16
+ installCloseHandler();
16
17
  modal.classList.add("is-open");
17
18
  modal.style.display = "block";
18
19
  modal.setAttribute("role", "dialog");
@@ -31,9 +32,15 @@ export function closeModal(id = DEFAULT_MODAL_ID) {
31
32
  }
32
33
 
33
34
  // One delegated handler serves every close button (x), including modals added later.
34
- // One delegated handler serves every close button (x), including modals added later.
35
- document.addEventListener("click", event => {
36
- const button = event.target.closest?.(".close");
37
- if (!button) return;
38
- closeModal(button.closest(".modal")?.id || DEFAULT_MODAL_ID);
39
- });
35
+ // One delegated handler serves every close button (x), including modals added later. It is installed when the first modal is opened,
36
+ // so importing this file has no side effect.
37
+ let closeHandlerInstalled = false;
38
+ function installCloseHandler() {
39
+ if (closeHandlerInstalled) return;
40
+ closeHandlerInstalled = true;
41
+ document.addEventListener("click", event => {
42
+ const button = event.target.closest?.(".close");
43
+ if (!button) return;
44
+ closeModal(button.closest(".modal")?.id || DEFAULT_MODAL_ID);
45
+ });
46
+ }
@@ -193,37 +193,33 @@ export function generatePagination(options = {}) {
193
193
  */
194
194
  export function generateAccordion(options = {}) {
195
195
  const element = el("div", { id: options.id, class: cx("accordion", options.class) });
196
+ const group = options.multiple ? null : uid("accordion-group"); // details elements with the same name open one at a time
196
197
  const sections = [];
197
198
 
198
- function toggle(index, open) {
199
- const section = sections[index];
200
- const willOpen = open ?? section.button.getAttribute("aria-expanded") !== "true";
201
- if (willOpen && !options.multiple) sections.forEach((other, i) => i !== index && setOpen(other, false));
202
- setOpen(section, willOpen);
203
- }
204
- function setOpen(section, open) {
205
- section.button.setAttribute("aria-expanded", String(open));
206
- section.panel.hidden = !open;
207
- section.item.classList.toggle("accordion-open", open);
199
+ // The browser does the rest (the keyboard, aria-expanded, find in page). The name attribute closes the others where it is supported;
200
+ // this does it in the browsers that do not know it yet.
201
+ function onToggle(section) {
202
+ if (!section.item.open || options.multiple) return;
203
+ for (const other of sections) if (other !== section && other.item.open) other.item.open = false;
208
204
  }
209
205
 
210
- (options.items ?? []).forEach((item, index) => {
211
- const base = uid("accordion");
212
- const button = el("button", {
213
- class: "accordion-header",
214
- id: `${base}-header`,
215
- attrs: { type: "button", "aria-controls": `${base}-panel` },
216
- on: { click: () => toggle(index) }
217
- }, el("span", { text: item.title }), el("span", { class: "accordion-icon", attrs: { "aria-hidden": "true" } }));
218
- const panel = el("div", { class: "accordion-panel", id: `${base}-panel`, attrs: { role: "region", "aria-labelledby": button.id } });
206
+ (options.items ?? []).forEach(item => {
207
+ const summary = el("summary", { class: "accordion-header" }, el("span", { text: item.title }), el("span", { class: "accordion-icon", attrs: { "aria-hidden": "true" } }));
208
+ const panel = el("div", { class: "accordion-panel" });
219
209
  setContent(panel, item.content);
220
- const wrapper = el("div", { class: "accordion-item" }, el("h3", { class: "accordion-title" }, button), panel);
221
- const section = { item: wrapper, button, panel };
210
+ const details = el("details", { class: "accordion-item", attrs: { name: group, open: item.open ? true : null } }, summary, panel);
211
+ const section = { item: details, summary, panel };
212
+ details.addEventListener("toggle", () => onToggle(section));
222
213
  sections.push(section);
223
- element.append(wrapper);
224
- setOpen(section, false);
214
+ element.append(details);
225
215
  });
226
- (options.items ?? []).forEach((item, index) => { if (item.open) toggle(index, true); });
216
+ // With several items marked open and one at a time, the first one wins
217
+ if (!options.multiple) sections.filter(section => section.item.open).slice(1).forEach(section => { section.item.open = false; });
218
+
219
+ function toggle(index, open) {
220
+ const section = sections[index];
221
+ if (section) section.item.open = open ?? !section.item.open;
222
+ }
227
223
 
228
224
  mount(options.parent, element);
229
225
  return asHandle({ element, toggle });
package/src/menu.js ADDED
@@ -0,0 +1,6 @@
1
+ //menu entry of Athena UI: generateMenu
2
+ //Import only what you use: `import { generateTable } from "athena-ui-js/menu"`.
3
+ //LICENCE: MIT
4
+ //Repository: https://github.com/csabatibortoth/athena-ui
5
+
6
+ export * from "./libs/hephaestus/MenuGenerator/menuGenerator.js";
@@ -0,0 +1,6 @@
1
+ //navigation entry of Athena UI: tabs, breadcrumbs, pagination, accordion, dropdown, sidebar
2
+ //Import only what you use: `import { generateTable } from "athena-ui-js/navigation"`.
3
+ //LICENCE: MIT
4
+ //Repository: https://github.com/csabatibortoth/athena-ui
5
+
6
+ export * from "./libs/hephaestus/navigationGenerator/navigationGenerator.js";