athena-ui-js 1.2.0 → 1.3.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 (39) hide show
  1. package/README.md +228 -22
  2. package/package.json +9 -7
  3. package/src/athena-ui.js +33 -10
  4. package/src/libs/config/config.js +8 -1
  5. package/src/libs/core/controls.js +153 -0
  6. package/src/libs/core/dateRange.js +121 -0
  7. package/src/libs/core/dom.js +58 -8
  8. package/src/libs/{hephaestus/HTMLElementGenerator/src/HTMLElementGenerator.js → core/elementGenerator.js} +23 -21
  9. package/src/libs/{hephaestus/HTMLElementGenerator/src → core}/errors.js +7 -5
  10. package/src/libs/core/format.js +51 -0
  11. package/src/libs/core/hungarianControls.js +41 -0
  12. package/src/libs/core/i18n.js +64 -0
  13. package/src/libs/core/theme.js +131 -0
  14. package/src/libs/hephaestus/LayoutGenerator/basicLayoutGenerator.js +4 -6
  15. package/src/libs/hephaestus/LayoutGenerator/footerContentGenerator.js +2 -4
  16. package/src/libs/hephaestus/LayoutGenerator/headerContentGenerator.js +12 -5
  17. package/src/libs/hephaestus/MenuGenerator/basicMenuGenerator.js +3 -3
  18. package/src/libs/hephaestus/MenuGenerator/menuGenerator.js +253 -0
  19. package/src/libs/hephaestus/auth/authState.js +58 -0
  20. package/src/libs/hephaestus/chartGenerator/chartGenerator.js +519 -87
  21. package/src/libs/hephaestus/componentGenerator/componentGenerator.js +121 -4
  22. package/src/libs/hephaestus/componentGenerator/themePicker.js +73 -0
  23. package/src/libs/hephaestus/dialogGenerator/dialogGenerator.js +88 -8
  24. package/src/libs/hephaestus/feedbackGenerator/feedbackGenerator.js +21 -0
  25. package/src/libs/hephaestus/formGenerator/authForms.js +130 -0
  26. package/src/libs/hephaestus/formGenerator/formUtils.js +10 -9
  27. package/src/libs/hephaestus/formGenerator/loginFormGenerator.js +9 -9
  28. package/src/libs/hephaestus/hephaestus.js +7 -2
  29. package/src/libs/hephaestus/inputGenerator/inputGenerator.js +30 -1
  30. package/src/libs/hephaestus/modalGenerator/modalGenerator.js +17 -11
  31. package/src/libs/hephaestus/router/router.js +54 -5
  32. package/src/libs/hephaestus/tableGenerator/tableGenerator.js +290 -16
  33. package/src/libs/libs.js +3 -3
  34. package/src/res/themes/appearance.css +154 -0
  35. package/src/res/themes/default/style.css +609 -0
  36. package/src/theme-boot.js +25 -0
  37. package/src/libs/hephaestus/HTMLControlGenerator/LICENSE +0 -21
  38. package/src/libs/hephaestus/HTMLControlGenerator/src/HTMLControlGenerator.min.js +0 -5
  39. package/src/libs/hephaestus/HTMLElementGenerator/LICENSE +0 -21
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # Athena UI
2
2
 
3
- A small jQuery based UI framework for development and education purposes. It generates a page
3
+ A small UI framework for development and education purposes (jQuery is optional). It generates a page
4
4
  layout (header, menu, content wrapper, footer) from a single `init()` call, loads its own libraries
5
5
  and theme, and ships the building blocks of a multipurpose application: forms, tables, charts,
6
6
  feedback, navigation, a router and more.
7
7
 
8
- Current version: **1.2.0**
8
+ Current version: **1.3.0**
9
9
 
10
10
  [Quick start](#usage) · [API](#api) · [Components](#charts) · [Themes](#themes) · [Tests](#tests) · [Release notes](#releases)
11
11
 
@@ -19,14 +19,21 @@ Known limits are listed below, so you can judge whether it fits your project:
19
19
  - The session cookie is readable from JavaScript. It is a UI state, not a security boundary: authenticate on the server.
20
20
  - Virtual table rows have to be a fixed height, one line per cell (set it with `virtual.rowHeight`; the CSS variable `--row-height` follows).
21
21
  - Translations: English and Hungarian.
22
+ - jQuery is optional since 1.3.0. The older generators (`generateLoginForm`, the layout and the header / footer menu built from `menuItems`) still work, and
23
+ they no longer need it. Everything new (`generateMenu`, the sign in forms, dialogs, charts, tables, ...) is plain DOM.
22
24
 
23
25
  ## Features
24
26
 
25
27
  - Generated page layout: container, header (logo, title, menu), wrapper, footer (menu, copyright text)
26
28
  - Menus built from your own item lists, with a navigation callback
27
29
  - Login, registration and lost password forms with optional SHA-256 password hashing
28
- - SVG charts (bar, line, pie, donut) without extra dependencies
29
- - Tables with sortable columns, filter box, pagination, row selection, inline editing, resizable columns, virtual scrolling for thousands of rows and CSV export
30
+ - SVG charts (bar, line, area, sparkline, pie, donut) with a time axis, tooltips, zoom, a clickable legend, a table of values and streaming, without extra dependencies
31
+ - Tables with sortable columns, filter box, pagination, row selection, inline editing, resizable columns, virtual scrolling for thousands of rows, rows loaded from a server (pages, "Load more", or scrolling through a data source), row actions and CSV export
32
+ - Navigation menu (`generateMenu`): real links and buttons, groups of any depth, badges, a user menu with an avatar, tabs at the bottom on a phone
33
+ - Sign in, sign up and password forms that password managers understand, and a signed-in state that lives in memory only
34
+ - Themes and modes (light / dark / like the system) with a theme manager, a picker and a no-flash boot script
35
+ - Form dialogs, confirmations (also "type the name to confirm"), date and time ranges with presets, page header, facts list, empty and loading states
36
+ - Safe DOM building (`el`, `createSafeBuilder`): text stays text, no event attributes, no inline style
30
37
  - Form builder: text, number, date, textarea, select, radio / checkbox groups, switch, autocomplete, multi select, with validation
31
38
  - Buttons, toasts, alerts, spinner, progress bar, alert / confirm / prompt dialogs
32
39
  - Tabs, accordion, dropdown, sidebar, breadcrumbs, pagination and a hash / history router
@@ -41,16 +48,14 @@ Known limits are listed below, so you can judge whether it fits your project:
41
48
 
42
49
  ## Requirements
43
50
 
44
- - [jQuery](https://jquery.com/) v4.0.0, loaded before Athena UI
51
+ - jQuery is optional (v4.0.0, only if your own code or an older application uses it). Athena UI itself does not need it.
45
52
  - A browser with ES module support
46
53
  - The page has to be served over HTTP(S). Modules do not load from `file://`.
47
54
 
48
- Bundled as git submodules:
55
+ Bundled as git submodules (third party):
49
56
 
50
57
  | Library | Version | Used for |
51
58
  | --- | --- | --- |
52
- | [HTMLControlGenerator](https://github.com/csabatibortoth/HTMLControlGenerator) | 0.4.0 | inputs, lists |
53
- | [HTMLElementGenerator](https://github.com/csabatibortoth/HTMLElementGenerator) | 0.3.0 | divs, headings, images |
54
59
  | [crypto-js](https://github.com/brix/crypto-js) | 4.2.0 | password hashing |
55
60
  | [js-cookie](https://github.com/js-cookie/js-cookie) | 3.0.8 | cookie handling |
56
61
 
@@ -71,8 +76,7 @@ Serve the `src` folder with any static web server and open `index.html` to see t
71
76
  ## Usage
72
77
 
73
78
  ```html
74
- <script src="https://code.jquery.com/jquery-4.0.0.min.js"
75
- integrity="sha256-OaVG6prZf4v69dPg6PhVattBXkcOWQB62pdZ3ORyrao=" crossorigin="anonymous"></script>
79
+ <!-- jQuery is not needed -->
76
80
  <script type="module">
77
81
  import { init, clearWrapper, generateLoginForm } from "./athena-ui.js";
78
82
 
@@ -120,7 +124,7 @@ the theme are loaded and the layout is generated.
120
124
  | `header_title_text` | `"Athena UI"` | Title in the header |
121
125
  | `header_img_url` | | Header logo URL |
122
126
  | `copyright` | placeholder text | Footer text, the version is appended |
123
- | `version` | `"1.2.0"` | Version shown in the footer |
127
+ | `version` | `"1.3.0"` | Version shown in the footer |
124
128
  | `bordered` | `true` | Draw a border around the layout blocks |
125
129
  | `generateHeader`, `generateFooter` | `true` | Generate the header / footer block |
126
130
  | `generateHeadercontent`, `generateFooterContent`, `generateWrappercontent` | `true` | Generate the content of the block |
@@ -158,6 +162,14 @@ Everything is exported from `athena-ui.js`:
158
162
  | `showDialog`, `alertDialog`, `confirmDialog`, `promptDialog` | See [Dialogs](#dialogs) |
159
163
  | `generateTabs`, `generateBreadcrumbs`, `generatePagination`, `generateAccordion`, `generateDropdown`, `generateSidebar` | See [Navigation](#navigation) |
160
164
  | `createRouter(options)` | See [Router](#router) |
165
+ | `generateMenu(options)`, `generateHeaderMenu({ items })` | See [Menu component](#menu-component) |
166
+ | `generateSignInForm`, `generateSignUpForm`, `generatePasswordResetForm`, `generatePasswordChangeForm`, `createAuthState` | See [Signing in](#signing-in-recommended) |
167
+ | `showFormDialog`, `showConfirm` | See [Dialogs](#dialogs) |
168
+ | `createThemeManager`, `generateThemePicker` | See [Themes and modes](#themes-and-modes-light--dark--like-the-system) |
169
+ | `generateDateTimeRange`, `toLocalInput`, `fromLocalInput` | See [Date and time range](#date-and-time-range) |
170
+ | `generatePageHeader`, `generateFacts`, `generateEmptyState`, `generateLoading`, `copyToClipboard` | See [Page parts and formatting](#page-parts-and-formatting) |
171
+ | `formatBytes`, `formatNumber`, `formatDuration`, `formatRelativeTime`, `formatDate` | Format helpers on top of `Intl`, in the current language |
172
+ | `el`, `setContent`, `resolveElement`, `asHandle`, `createSafeBuilder` | See [Safe DOM building](#safe-dom-building) |
161
173
  | `generateCard`, `generateSection`, `generateGrid`, `generateBadge`, `generateAvatar`, `generateStat`, `generateLink`, `generateTooltip` | See [Components](#components) |
162
174
  | `generateAutocomplete`, `generateMultiSelect`, `generateFileUpload`, `generateDropZone`, `generateStepper`, `generateDateRange`, `generateRichText`, `generateWysiwyg` | See [Inputs](#inputs) |
163
175
  | `sanitizeHtml(html)`, `htmlToText(html)`, `isSafeUrl(url)` | The allow-list sanitizer behind the rich text editor |
@@ -169,26 +181,42 @@ Everything is exported from `athena-ui.js`:
169
181
  | `openModal(id)`, `closeModal(id)` | Show / hide a `.modal` element (default id: `myModal`). Elements with the `close` class close their modal. |
170
182
  | `loadScript(src)` | Load a classic script once, returns a Promise |
171
183
  | `Cookies` | The [js-cookie](https://github.com/js-cookie/js-cookie) API |
172
- | `HTMLElementGenerator(options)` | The [HTMLElementGenerator](https://github.com/csabatibortoth/HTMLElementGenerator) function |
184
+ | `HTMLElementGenerator(options)` | Generates a div, span, p, heading or img and appends it to the element with the id `parent` |
185
+ | `HTMLControlGenerator(options)`, `HTMLControlGenerator.create(options)`, `HTMLControlGenerator.register(type, factory)` | Generates inputs, selects and lists from an options object. `create` builds without appending and returns the element (a jQuery object when the page has jQuery). `registerHungarianInputControls()` adds the types `hunPIN`, `hunCRID` and `hunTID` |
186
+
187
+ HTMLElementGenerator and HTMLControlGenerator used to be projects of their own. They are part of Athena UI now (the calls and options are the
188
+ same, and HTMLControlGenerator no longer needs jQuery); the old repositories are no longer developed.
173
189
 
174
190
  ### Charts
175
191
 
176
192
  ```js
177
- generateChart({
178
- type: "bar", // "bar" | "line" | "pie" | "donut"
179
- parent: "wrapper", // id of the parent element (default)
193
+ const chart = generateChart({
194
+ type: "line", // "bar" | "line" | "area" | "sparkline" | "pie" | "donut"
195
+ parent: "wrapper", // element, id or selector (default "wrapper")
180
196
  title: "Revenue",
181
197
  labels: ["Q1", "Q2", "Q3"],
182
198
  series: [
183
199
  { name: "2025", data: [12, 19, 8] },
184
200
  { name: "2026", data: [14, 17, 12], color: "#e15759" }
185
- ]
201
+ ],
202
+ table: true // adds "Show as table" with the values
186
203
  });
187
204
  ```
188
205
 
189
- Charts are inline SVG and support negative values. `pie` and `donut` use the first series, one slice per
190
- label. Other options: `id`, `width` (600), `height` (360), `legend` (shown for several series and for
191
- pie / donut). Returns the `<svg>` element, or `null` when the options are invalid.
206
+ Charts are inline SVG, nothing is styled inline (a strict Content-Security-Policy works), negative values are supported. `pie` and `donut` use the
207
+ first series, one slice per label. `sparkline` is a small line without axes (120 x 32 by default) for a table cell or a tile.
208
+ Other options: `id`, `width` (600), `height` (360), `legend`, `zero: false` (a line chart's value axis may start near the smallest value).
209
+
210
+ - **Colours** come from the theme: `--series-1` ... `--series-8` (see `appearance.css`), so every chart follows light / dark. `color` overrides one series.
211
+ - **Tooltips** show on hover and on keyboard focus (every point and bar is focusable and named). In a long line chart the tooltip follows the pointer.
212
+ - **Legend**: click (or Enter / Space) on an entry hides and shows that series.
213
+ - **Time axis**: `times: [Date | ms | "2026-11-19T10:00"]` (line and area). Ticks fall on round times, points sit at their real distance.
214
+ - **Zoom** (`zoom: true`, line and area): drag over the plot, double click or the reset button zoom out. On the plot, + and - zoom, the arrow keys pan,
215
+ 0 resets. `chart.zoom(from, to)`, `chart.resetZoom()`, `chart.getZoom()`, `onZoom(range)` and `zoomRange` (ms with `times`, otherwise the point index).
216
+ - **Long series** are thinned to the width of the plot (the lowest and the highest value of every slice stay, so peaks are not lost), and dots are only drawn up to 80 points in view.
217
+ - **Streaming**: `chart.push({ x: Date.now(), values: [12, 3] }, { maxPoints: 500 })` adds a point to every series, drops the oldest ones and redraws at most once per frame.
218
+ - `chart.update({ series })` redraws with changes, `chart.destroy()` removes the chart and its table. `generateChart` returns the `<svg>` element that carries these
219
+ methods, or `null` when the options are invalid.
192
220
 
193
221
  ### Tables
194
222
 
@@ -214,6 +242,13 @@ Click a header to sort (disable with `sortable: false`, or per column). Other op
214
242
  - Hooks and looks: `cellClass(row, column)` and `rowClass(row)` return a class name (or a list) for a cell or a row. `focusableRows: true` makes rows reachable with Tab (`rowLabel(row)` is their aria-label); together with `onRowClick` they open with Enter and Space. `density: "compact"`, and `wrap: true | false` (long text wraps, or stays on one line with an ellipsis). The pager is hidden when there is only one page.
215
243
  - Column extras: `render(row, value)` returns text or a Node (built by you, so it is safe by construction), `align: "left" | "center" | "right"`. Text longer than 24 characters gets its full text as a tooltip (`title: false` switches it off).
216
244
  - A virtual table that starts empty draws a full window as soon as it gets rows, and measures again when the scroll area changes size.
245
+ - **Rows from a server**: `dataSource: async ({ page, pageSize, cursor, sort, filter }) => ({ rows, total })`. Sorting, the (debounced) filter box and the pager ask it again,
246
+ a slow request shows a loading state, a failed one an error with a Retry button, and an answer that comes too late is ignored. Answer with `total` for numbered pages
247
+ (`page` is 0-based), or with `nextCursor` for a "Load more" button (`cursor` is what the last answer gave). `table.reload()` asks again.
248
+ - **Rows from a server and virtual scrolling**: `dataSource` together with `virtual` (every answer needs `total`) scrolls through `total` rows. The rows in view are asked for in chunks of
249
+ `chunkSize` (default 50, `page` is the chunk number), chunks you scroll past are skipped, rows that have not arrived yet show a placeholder, and a failed chunk can be retried.
250
+ The select-all checkbox only selects the rows that have arrived.
251
+ - `rowActions: [{ label: "Delete", danger: true, onclick: row => remove(row), hidden: row => row.locked, ariaLabel: row => "Delete " + row.name }]` adds a column of buttons.
217
252
  - `exportCsv()` downloads the filtered and sorted rows. Cells that start with `=`, `+`, `-` or `@` are prefixed with `'` so a spreadsheet does not run them as formulas.
218
253
 
219
254
  ### Forms
@@ -273,6 +308,21 @@ Options: `size` ("small" 360 px, "medium" 480 px, "large" 720 px, "full") and `c
273
308
  `showDialog` returns a promise that also carries the open dialog: `const dialog = showDialog({ size: "large", ... }); dialog.element; dialog.close(value);`.
274
309
  The dialog is shown by a CSS class, not by an inline style, so a strict Content-Security-Policy works.
275
310
 
311
+ **Form dialog** and **confirmation**:
312
+
313
+ ```js
314
+ const saved = await showFormDialog({
315
+ title: "Add host", intro: "The agent connects with this name.", size: "small", submitText: "Add",
316
+ fields: [{ name: "name", label: "Name", required: true }],
317
+ onSubmit: async (values, form) => {
318
+ const answer = await api.addHost(values); // when this throws, the message shows in the dialog and it stays open
319
+ if (answer.errors) throw Object.assign(new Error("Check the fields"), { fields: answer.errors }); // or form.setErrors({ name: "Already taken" })
320
+ }
321
+ }); // true when saved, false when dismissed
322
+
323
+ if (await showConfirm({ title: "Delete host", message: "This cannot be undone.", confirmText: "Delete", danger: true, typeToConfirm: host.name })) { /* ... */ }
324
+ ```
325
+
276
326
  Dialogs trap the focus, close with Esc (resolving `null` / `false`) and restore the focus. Text content is
277
327
  never parsed as HTML. `openModal` / `closeModal` got the same focus handling.
278
328
 
@@ -310,6 +360,33 @@ init({
310
360
  A submenu opens with a click, Enter, Space or the Down arrow, closes with Esc, a click outside or by choosing an entry,
311
361
  and supports the arrow keys, Home and End. The same works in the footer menu.
312
362
 
363
+ ### Menu component
364
+
365
+ `generateMenu` is a navigation menu that does not use globals. Items are real links (`href`) or buttons, so Tab, Enter and Space work, and screen readers hear what they are.
366
+
367
+ ```js
368
+ const menu = generateMenu({
369
+ parent: "header", // an element, an id or a selector
370
+ layout: "responsive", // "bar" | "bottom-tabs" | "responsive" (tabs at the bottom under 700px, groups open as sheets)
371
+ followHash: true, // the item whose href equals location.hash is the active one
372
+ onNavigate: (item, event) => console.log(item.id), // only when a person uses an item, never from select() or while building
373
+ items: [
374
+ { id: "home", label: "Home", icon: "⌂", href: "#/" },
375
+ { id: "inbox", label: "Inbox", href: "#/inbox", badge: 3, badgeLabel: "3 unread" },
376
+ { id: "tools", label: "Tools", children: [
377
+ { id: "export", label: "Export" },
378
+ { id: "more", label: "More", children: [{ id: "csv", label: "CSV" }, { id: "json", label: "JSON" }] }
379
+ ] },
380
+ { id: "user", label: "Anna Kiss", avatar: { name: "Anna Kiss" }, align: "end", children: [{ id: "out", label: "Sign out" }] }
381
+ ]
382
+ });
383
+ menu.select("inbox"); // marks the current page (class is-active, aria-current="page", has-active on the groups around it)
384
+ menu.setBadge("inbox", { text: 12, tone: "bad" }); // a count, text, or { text, tone: "info" | "ok" | "warn" | "bad" }; 0 / null removes it
385
+ ```
386
+
387
+ Groups nest to any depth: ArrowDown / ArrowUp open the first level, ArrowRight opens a deeper group and ArrowLeft closes it, Esc closes the innermost group
388
+ first, Home / End jump, a click outside closes everything. A badge above 99 shows "99+". `generateHeaderMenu({ items, onNavigate })` puts the same menu into the header.
389
+
313
390
  ### Router
314
391
 
315
392
  ```js
@@ -327,6 +404,22 @@ router.start();
327
404
  router.navigate("/users/5?tab=info");
328
405
  ```
329
406
 
407
+ Routes can carry the sign-in rules, so a page does not check them itself:
408
+
409
+ ```js
410
+ const router = createRouter({
411
+ auth: auth.routerRules({ loginPath: "/login", homePath: "/", forbiddenPath: "/denied" }), // { isSignedIn, hasRole, ... }
412
+ focusContent: true, scrollTop: true, // after a page is shown: focus the outlet, scroll to the top
413
+ onShown: ctx => menu.select(ctx.path), // also onRender (before the page function) and router.onChange(listener)
414
+ routes: {
415
+ "/login": { handler: renderLogin, guestOnly: true }, // a signed-in person goes home
416
+ "/account": { handler: renderAccount, auth: true }, // not signed in: /login?next=%2Faccount
417
+ "/admin": { handler: renderAdmin, auth: true, roles: ["admin"] },
418
+ "/report": { handler: renderReport, guard: ctx => ctx.query.id ? undefined : "/reports" } // false stays, a path redirects
419
+ }
420
+ });
421
+ ```
422
+
330
423
  `mode: "history"` uses real paths instead of the hash, the server then has to answer every path with the page.
331
424
  Pass `router.navigate` from your `nav` callback to route the menu clicks.
332
425
 
@@ -435,6 +528,30 @@ The global `appConfig`, `menuItems`, `nav`, `login`, `register` and `lostPasswor
435
528
  not given. `appConfig.athenaUIFolder` is not needed anymore, paths are resolved relative to
436
529
  `athena-ui.js`.
437
530
 
531
+ ### Signing in (recommended)
532
+
533
+ `generateSignInForm`, `generateSignUpForm`, `generatePasswordResetForm` and `generatePasswordChangeForm` are real `<form>` elements with the autocomplete tokens
534
+ that password managers look for (`username`, `current-password`, `new-password`, `email`), so Enter submits and the browser can save and fill passwords.
535
+
536
+ ```js
537
+ const auth = createAuthState({ restore: () => fetch("/api/me", { credentials: "same-origin" }).then(r => (r.ok ? r.json() : null)) });
538
+ await auth.restore(); // after a reload: ask the server who is signed in
539
+
540
+ generateSignInForm({
541
+ parent: "wrapper", remember: true,
542
+ onSubmit: async ({ username, password, remember }) => {
543
+ const response = await fetch("/api/login", { method: "POST", body: JSON.stringify({ username, password, remember }), credentials: "same-origin" });
544
+ if (!response.ok) throw new Error("Wrong user name or password"); // shown in the form, which stays usable
545
+ auth.signIn(await response.json()); // { name, roles: [...] }
546
+ }
547
+ });
548
+ ```
549
+
550
+ An error with a `fields` object (`{ username: "Already taken" }`) marks those fields as well. The password is sent as typed, over HTTPS: hash it on the server.
551
+ Hashing it in the browser (`enable_encrypt_password`) only turns the hash into the password, so that setting is **deprecated** and will be removed in 2.0.
552
+ `createAuthState` keeps who is signed in **in memory only**: nothing readable is written to a cookie or the storage, the session itself is a server set `HttpOnly` cookie,
553
+ and the server decides what a person may do. `auth.hasRole(role)`, `auth.onChange(listener)` and `auth.routerRules()` connect it to menus and the router.
554
+
438
555
  ## Themes
439
556
 
440
557
  A theme is a single stylesheet. Register it in `src/res/themes/themes.js` and select it with
@@ -449,6 +566,72 @@ The default theme is in `src/res/themes/default/style.css`; `{ id: 1 }` is a dar
449
566
 
450
567
  Switch themes at runtime with `setTheme({ id: 1 })`.
451
568
 
569
+ ### Themes and modes (light / dark / like the system)
570
+
571
+ A second system lets people choose a theme **and** a mode. It is just two attributes on `<html>` that `src/res/themes/appearance.css` reads:
572
+
573
+ ```html
574
+ <link rel="stylesheet" href="athena-ui/src/res/themes/default/style.css">
575
+ <link rel="stylesheet" href="athena-ui/src/res/themes/appearance.css">
576
+ <script src="athena-ui/src/theme-boot.js" data-key="myapp.appearance" data-theme="athena"></script> <!-- before the page is drawn: no flash of the wrong colours -->
577
+ ```
578
+
579
+ ```js
580
+ const manager = createThemeManager({ themes: [{ id: "athena", name: "Athena" }, { id: "contrast", name: "High contrast" }], storageKey: "myapp.appearance",
581
+ themeColorVariable: "--athena-bg" }); // <meta name="theme-color"> follows this variable
582
+ manager.setTheme("contrast"); manager.setMode("dark"); // "system" | "light" | "dark"; saved in localStorage, other tabs follow
583
+ manager.onChange(({ theme, mode, dark }) => redrawChartsOrWhatever());
584
+ generateThemePicker({ parent: "account-page", manager }); // radio groups with a small preview of every theme
585
+ ```
586
+
587
+ **The contract of a theme** (also at the top of `appearance.css`): a theme is a pair of CSS blocks that set the tokens
588
+ `--athena-bg`, `-fg`, `-muted`, `-line`, `-border`, `-surface`, `-surface-alt`, `-hover`, `-overlay`, `-accent`, `-accent-fg`, `-focus`, `-danger`, `-success`, `-warning`, `-info`, `-shadow` and `--series-1` ... `--series-8`:
589
+
590
+ ```css
591
+ [data-theme="ocean"][data-mode="light"] { --athena-bg: #f4f9fb; /* ... */ }
592
+ [data-theme="ocean"][data-mode="dark"] { --athena-bg: #0b1c24; /* ... */ }
593
+ ```
594
+
595
+ The selectors match any element with the two attributes, so a preview or a dark panel on a light page is just an element with `data-theme` and `data-mode`.
596
+ Athena and High contrast (light and dark) are included; without the script the page follows the system.
597
+
598
+ ### Date and time range
599
+
600
+ ```js
601
+ const range = generateDateTimeRange({ parent: "wrapper", label: "Time", preset: "24h", onChange: ({ from, to, preset }) => reload() });
602
+ range.getRange(); // { from: Date, to: Date }. A preset ("15m", "1h", "24h", "7d", "30d") is measured from NOW when this is called
603
+ range.getValue(); // { from: "2026-11-19T08:00", to: "...", preset: "24h" }, the values of the inputs
604
+ ```
605
+
606
+ Two `datetime-local` inputs and a list of presets (your own with `presets: [{ id, label, minutes }]`). Typing in an input makes it a custom range.
607
+ `toLocalInput(date)` and `fromLocalInput(value)` convert between a Date and the value of such an input.
608
+
609
+ ### Page parts and formatting
610
+
611
+ ```js
612
+ generatePageHeader({ parent: "wrapper", title: "Hosts", description: "All monitored machines", breadcrumbs: [{ label: "Home", href: "#/" }, { label: "Hosts" }], actions: [addButton] });
613
+ generateFacts({ parent: "wrapper", items: [{ term: "System", description: "Linux" }, { term: "Seen", description: formatRelativeTime(host.lastSeen) }] });
614
+ generateEmptyState({ parent: "wrapper", title: "No hosts yet", message: "Install the agent.", action: { text: "Add host", onclick: add } });
615
+ generateLoading({ parent: "wrapper" }); // spinner + text, a live region
616
+ generateStat({ parent: "wrapper", label: "CPU", value: "91 %", tone: "bad", note: "of 4 cores" }); // tone: "ok" | "warn" | "bad" (colour + a word for screen readers)
617
+ await copyToClipboard(token); // and says "Copied" in a toast
618
+ formatBytes(1536); formatNumber(1234567.891); formatDuration(7500000); formatRelativeTime(date); formatDate(date, { time: true }); // Intl, in the current language
619
+ ```
620
+
621
+ ### Safe DOM building
622
+
623
+ `el(tag, { class, id, text, attrs, on, prop }, ...children)` is the way Athena builds its own pages, and it is exported. Strings are only ever inserted as **text**, children can be
624
+ nested lists, listeners have to be functions, and `on*` attributes, `style` and `srcdoc`, unsafe addresses (`javascript:`, `data:`) in `href` / `src` / `action`, and properties that
625
+ parse HTML (`innerHTML`) are refused. `createSafeBuilder({ tags: [...], attributes: [...] })` returns an `el` that only allows what is on your lists, for pages built from data you
626
+ do not control (a plugin API).
627
+
628
+ ### Moved into Athena: HTMLElementGenerator and HTMLControlGenerator
629
+
630
+ Both used to be projects of their own and are part of Athena UI since 1.3.0 (same calls and options, MIT, same author). `HTMLElementGenerator(options)` is in
631
+ `src/libs/core/elementGenerator.js`, `HTMLControlGenerator(options)` / `.create()` / `.register()` in `src/libs/core/controls.js`; both are exported and global as before.
632
+ `HTMLControlGenerator` no longer needs jQuery (`create` returns a jQuery object when the page has jQuery, otherwise the element).
633
+ `registerHungarianInputControls()` adds the `hunPIN`, `hunCRID` and `hunTID` input types of its old addon. The old repositories are no longer developed.
634
+
452
635
  ### Parents and handles
453
636
 
454
637
  Every `parent` option takes an element, an id or a CSS selector (`"wrapper"`, `"#list"`, `".panel > ul"`; an id wins over a selector).
@@ -485,6 +668,8 @@ component: forms, dialogs, navigation, submenus, inputs, rich text (sanitizing,
485
668
  session, themes. Set `CHROME_PATH` if the browser is not found, and `JQUERY_URL` to load jQuery from somewhere else than the CDN
486
669
  (the machine needs internet access otherwise). `DEBUG=1` prints the browser log when the page does not report results.
487
670
 
671
+ A test run without jQuery is the default; `WITH_JQUERY=1 npm run test:browser` loads jQuery from its CDN to check that an application that still has it works too.
672
+
488
673
  ## Project structure
489
674
 
490
675
  ```
@@ -496,9 +681,11 @@ src/
496
681
  core/ DOM / focus helpers, validation, translations, CSV, formatting, sanitizer, table math
497
682
  hephaestus/ script and theme loader, generators (layout, menu, forms, charts, tables, feedback,
498
683
  dialogs, navigation, components, inputs), router, session
499
- crypto-js/, js-cookie/ submodules
500
- libs.js classic scripts loaded at runtime
501
- res/themes/ default and dark theme
684
+ crypto-js/, js-cookie/ submodules (third party)
685
+ libs.js classic scripts loaded at runtime (only crypto-js, and only with the deprecated enable_encrypt_password)
686
+ res/themes/ default and dark theme, appearance.css (themes and modes)
687
+ theme-boot.js classic script that sets the saved theme and mode before the page is drawn
688
+ testing.js installDom, until, tick for the tests of an application
502
689
  tests/ unit tests (Node) and browser tests (headless Chrome)
503
690
  ```
504
691
 
@@ -512,6 +699,25 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
512
699
 
513
700
  ## Releases
514
701
 
702
+ ### 1.3.0
703
+ #### Added:
704
+ 1. Dialogs: `showFormDialog` (async save, errors stay in the dialog, `form.setErrors`) and `showConfirm` (`danger`, `typeToConfirm`)
705
+ 2. Themes: `createThemeManager`, `generateThemePicker`, `theme-boot.js` and `appearance.css` (the contract: `data-theme` + `data-mode`, the tokens, Athena and High contrast in light and dark)
706
+ 3. `generateMenu`: real links and buttons, groups of any depth, badges, avatar user menu, active item, bar / bottom tabs / responsive; `generateHeaderMenu({ items })`
707
+ 4. Tables: `dataSource` (pages, cursor "Load more", loading / empty / error with Retry), `dataSource` together with `virtual`, `rowActions`, `reload()`
708
+ 5. Charts: `area` and `sparkline`, time axis, tooltips, clickable legend, table of values, theme colours, zoom, long series thinning, `push()` for streaming
709
+ 6. Router: `auth`, `guestOnly`, `roles`, `guard`, `onRender` / `onShown`, `focusContent`, `scrollTop`, `router.onChange`
710
+ 7. `generateSignInForm`, `generateSignUpForm`, `generatePasswordResetForm`, `generatePasswordChangeForm`, `createAuthState`
711
+ 8. `generateDateTimeRange` with presets, `generatePageHeader`, `generateFacts`, `generateEmptyState`, `generateLoading`, stat `tone` and `note`, `copyToClipboard`, format helpers
712
+ 9. `el`, `setContent`, `resolveElement`, `asHandle` and `createSafeBuilder` are exported
713
+ 10. HTMLElementGenerator and HTMLControlGenerator (and the Hungarian input addon) are part of Athena UI; no more submodules for them
714
+ #### Changed:
715
+ 1. jQuery is optional: init() does not need it, the layout, modal, forms and menus use plain DOM, the browser tests run without it
716
+ 2. Only crypto-js can still be loaded as a classic script, and only with `enable_encrypt_password`
717
+ 3. `el()` refuses code attributes and unsafe addresses
718
+ #### Deprecated:
719
+ 1. `enable_encrypt_password` and the hashing of the old login forms (removed in 2.0): send the password over HTTPS and hash it on the server
720
+
515
721
  ### 1.2.0
516
722
  #### Added:
517
723
  1. Dialogs: `size` and `class` options, and the open dialog (`element`, `backdrop`, `close()`) on the returned promise
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "athena-ui-js",
3
- "version": "1.2.0",
4
- "description": "A small jQuery based UI framework: generated page layout, menus, login / registration / lost password forms, charts, tables, modals and themes, written as ES modules.",
3
+ "version": "1.3.0",
4
+ "description": "A small UI framework (jQuery is optional): generated page layout, menus, login / registration / lost password forms, charts, tables, modals and themes, written as ES modules.",
5
5
  "type": "module",
6
6
  "main": "./src/athena-ui.js",
7
7
  "scripts": {
@@ -11,12 +11,14 @@
11
11
  "exports": {
12
12
  ".": "./src/athena-ui.js",
13
13
  "./testing": "./src/testing.js",
14
+ "./theme-boot.js": "./src/theme-boot.js",
14
15
  "./themes/*": "./src/res/themes/*",
15
16
  "./package.json": "./package.json"
16
17
  },
17
18
  "files": [
18
19
  "src/athena-ui.js",
19
20
  "src/testing.js",
21
+ "src/theme-boot.js",
20
22
  "src/libs/libs.js",
21
23
  "src/libs/config",
22
24
  "src/libs/hephaestus/hephaestus.js",
@@ -34,11 +36,6 @@
34
36
  "src/libs/hephaestus/chartGenerator",
35
37
  "src/libs/hephaestus/tableGenerator",
36
38
  "src/libs/hephaestus/modalGenerator",
37
- "src/libs/hephaestus/HTMLControlGenerator/LICENSE",
38
- "src/libs/hephaestus/HTMLControlGenerator/src/HTMLControlGenerator.min.js",
39
- "src/libs/hephaestus/HTMLElementGenerator/LICENSE",
40
- "src/libs/hephaestus/HTMLElementGenerator/src/HTMLElementGenerator.js",
41
- "src/libs/hephaestus/HTMLElementGenerator/src/errors.js",
42
39
  "src/libs/crypto-js/LICENSE",
43
40
  "src/libs/crypto-js/crypto-js.js",
44
41
  "src/libs/js-cookie/LICENSE",
@@ -70,6 +67,11 @@
70
67
  "peerDependencies": {
71
68
  "jquery": "^4.0.0"
72
69
  },
70
+ "peerDependenciesMeta": {
71
+ "jquery": {
72
+ "optional": true
73
+ }
74
+ },
73
75
  "publishConfig": {
74
76
  "access": "public"
75
77
  },
package/src/athena-ui.js CHANGED
@@ -2,9 +2,7 @@
2
2
  //Author: Csaba Tóth https://github.com/csabatibortoth/
3
3
  //LICENCE: MIT
4
4
  //Repository: https://github.com/csabatibortoth/athena-ui
5
- //Version: 1.2.0
6
-
7
- /* global $ */
5
+ //Version: 1.3.0
8
6
 
9
7
  import config, { applyConfig } from "./libs/config/config.js";
10
8
  import { getAppConfig, setHooks } from "./libs/config/hooks.js";
@@ -14,6 +12,7 @@ import * as header from "./libs/hephaestus/LayoutGenerator/headerContentGenerato
14
12
  import * as wrapper from "./libs/hephaestus/LayoutGenerator/wrapperContentGenerator.js";
15
13
  import * as footer from "./libs/hephaestus/LayoutGenerator/footerContentGenerator.js";
16
14
  import * as menu from "./libs/hephaestus/MenuGenerator/basicMenuGenerator.js";
15
+ import * as menuGenerator from "./libs/hephaestus/MenuGenerator/menuGenerator.js";
17
16
  import * as loginForm from "./libs/hephaestus/formGenerator/loginFormGenerator.js";
18
17
  import * as registrationForm from "./libs/hephaestus/formGenerator/registrationFormGenerator.js";
19
18
  import * as lostPasswordForm from "./libs/hephaestus/formGenerator/lostPasswordFormGenerator.js";
@@ -31,16 +30,21 @@ import * as richText from "./libs/hephaestus/inputGenerator/richTextGenerator.js
31
30
  import * as sanitize from "./libs/core/sanitize.js";
32
31
  import * as router from "./libs/hephaestus/router/router.js";
33
32
  import * as session from "./libs/hephaestus/auth/session.js";
33
+ import * as authState from "./libs/hephaestus/auth/authState.js";
34
+ import * as authForms from "./libs/hephaestus/formGenerator/authForms.js";
34
35
  import * as i18n from "./libs/core/i18n.js";
35
36
  import * as validation from "./libs/core/validation.js";
37
+ import * as format from "./libs/core/format.js";
38
+ import * as dateRange from "./libs/core/dateRange.js";
36
39
  import * as csv from "./libs/core/csv.js";
40
+ import * as theme from "./libs/core/theme.js";
41
+ import * as themePicker from "./libs/hephaestus/componentGenerator/themePicker.js";
37
42
  import * as modal from "./libs/hephaestus/modalGenerator/modalGenerator.js";
38
43
  import Cookies from "./libs/js-cookie/src/api.mjs";
39
- import { HTMLElementGenerator } from "./libs/hephaestus/HTMLElementGenerator/src/HTMLElementGenerator.js";
44
+ import { HTMLElementGenerator } from "./libs/core/elementGenerator.js";
45
+ import { HTMLControlGenerator, registerControl, generateControl } from "./libs/core/controls.js";
46
+ import { registerHungarianInputControls } from "./libs/core/hungarianControls.js";
40
47
 
41
- if (typeof $ !== "function") {
42
- throw new Error("Athena UI: jQuery has to be loaded before athena-ui.js");
43
- }
44
48
 
45
49
  /**
46
50
  * Loads the libraries and the theme in parallel, then generates the layout.
@@ -62,9 +66,9 @@ export async function init(options = {}) {
62
66
  setHooks(options);
63
67
 
64
68
  await Promise.all([
65
- loadLibs(config.customLoader ? [config.customLoader] : []),
69
+ loadLibs(config.customLoader ? [config.customLoader] : [], { crypto: config.enable_encrypt_password }),
66
70
  loadTheme(options.theme ?? options.themes),
67
- new Promise(resolve => $(resolve))
71
+ new Promise(resolve => (document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", resolve, { once: true }) : resolve()))
68
72
  ]);
69
73
 
70
74
  layout.generateBasicLayout();
@@ -85,11 +89,16 @@ const AthenaUI = {
85
89
  loadScript,
86
90
  Cookies,
87
91
  HTMLElementGenerator,
92
+ HTMLControlGenerator,
93
+ registerControl,
94
+ generateControl,
95
+ registerHungarianInputControls,
88
96
  ...layout,
89
97
  ...header,
90
98
  ...wrapper,
91
99
  ...footer,
92
100
  ...menu,
101
+ ...menuGenerator,
93
102
  ...loginForm,
94
103
  ...registrationForm,
95
104
  ...lostPasswordForm,
@@ -105,12 +114,18 @@ const AthenaUI = {
105
114
  ...sanitize,
106
115
  ...router,
107
116
  ...session,
117
+ ...authState,
118
+ ...authForms,
108
119
  ...i18n,
109
120
  ...validation,
110
121
  ...csv,
122
+ ...dateRange,
123
+ ...format,
111
124
  setTheme,
112
125
  ...chart,
113
126
  ...table,
127
+ ...theme,
128
+ ...themePicker,
114
129
  ...modal
115
130
  };
116
131
 
@@ -118,12 +133,13 @@ const AthenaUI = {
118
133
  // stays reachable as globals, like in the pre-module versions.
119
134
  Object.assign(globalThis, AthenaUI, { AthenaUI });
120
135
 
121
- export { config, loadScript, Cookies, HTMLElementGenerator };
136
+ export { config, loadScript, Cookies, HTMLElementGenerator, HTMLControlGenerator, registerControl, generateControl, registerHungarianInputControls };
122
137
  export * from "./libs/hephaestus/LayoutGenerator/basicLayoutGenerator.js";
123
138
  export * from "./libs/hephaestus/LayoutGenerator/headerContentGenerator.js";
124
139
  export * from "./libs/hephaestus/LayoutGenerator/wrapperContentGenerator.js";
125
140
  export * from "./libs/hephaestus/LayoutGenerator/footerContentGenerator.js";
126
141
  export * from "./libs/hephaestus/MenuGenerator/basicMenuGenerator.js";
142
+ export * from "./libs/hephaestus/MenuGenerator/menuGenerator.js";
127
143
  export * from "./libs/hephaestus/formGenerator/loginFormGenerator.js";
128
144
  export * from "./libs/hephaestus/formGenerator/registrationFormGenerator.js";
129
145
  export * from "./libs/hephaestus/formGenerator/lostPasswordFormGenerator.js";
@@ -138,11 +154,18 @@ export * from "./libs/hephaestus/componentGenerator/componentGenerator.js";
138
154
  export * from "./libs/hephaestus/inputGenerator/inputGenerator.js";
139
155
  export * from "./libs/hephaestus/inputGenerator/dropZoneGenerator.js";
140
156
  export * from "./libs/hephaestus/inputGenerator/richTextGenerator.js";
157
+ export { el, setContent, resolveElement, asHandle, createSafeBuilder } from "./libs/core/dom.js";
141
158
  export * from "./libs/core/sanitize.js";
142
159
  export * from "./libs/hephaestus/router/router.js";
143
160
  export * from "./libs/hephaestus/auth/session.js";
161
+ export * from "./libs/hephaestus/auth/authState.js";
162
+ export * from "./libs/hephaestus/formGenerator/authForms.js";
144
163
  export * from "./libs/core/i18n.js";
145
164
  export * from "./libs/core/validation.js";
146
165
  export * from "./libs/core/csv.js";
166
+ export * from "./libs/core/dateRange.js";
167
+ export * from "./libs/core/format.js";
147
168
  export * from "./libs/hephaestus/modalGenerator/modalGenerator.js";
169
+ export * from "./libs/core/theme.js";
170
+ export * from "./libs/hephaestus/componentGenerator/themePicker.js";
148
171
  export default AthenaUI;
@@ -6,7 +6,7 @@
6
6
  export const BORDERED_CLASS = "default-cointainer-bordered";
7
7
 
8
8
  export const defaults = Object.freeze({
9
- version: "1.2.0",
9
+ version: "1.3.0",
10
10
  container_class: "container",
11
11
  header_class: "header-container",
12
12
  header_menu_class: "header-menu menu",
@@ -50,6 +50,8 @@ const config = { ...defaults };
50
50
 
51
51
  export default config;
52
52
 
53
+ let warnedEncrypt = false;
54
+
53
55
  // Copies every known setting that is defined in the given sources onto the live config.
54
56
  export function applyConfig(...sources) {
55
57
  for (const source of sources) {
@@ -58,6 +60,11 @@ export function applyConfig(...sources) {
58
60
  if (source[key] !== undefined) config[key] = source[key];
59
61
  }
60
62
  }
63
+ if (config.enable_encrypt_password && !warnedEncrypt) {
64
+ warnedEncrypt = true;
65
+ console.warn("Athena UI: enable_encrypt_password is deprecated and will be removed in 2.0. Hashing a password in the browser only turns the hash "
66
+ + "into the password. Send it over HTTPS and hash it on the server. generateSignInForm / generateSignUpForm do not hash.");
67
+ }
61
68
  return config;
62
69
  }
63
70