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/README.md
CHANGED
|
@@ -1,32 +1,41 @@
|
|
|
1
1
|
# Athena UI
|
|
2
2
|
|
|
3
|
-
A small
|
|
3
|
+
A small UI framework for development and education purposes. 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: **
|
|
8
|
+
Current version: **2.0.0**
|
|
9
9
|
|
|
10
10
|
[Quick start](#usage) · [API](#api) · [Components](#charts) · [Themes](#themes) · [Tests](#tests) · [Release notes](#releases)
|
|
11
11
|
|
|
12
12
|
## Status
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
[
|
|
14
|
+
The exported API of `src/athena-ui.js` follows [semantic versioning](https://semver.org/): breaking changes only come with a new major version.
|
|
15
|
+
**Coming from 1.x? Read [docs/migration-2.0.md](docs/migration-2.0.md)** (no jQuery, no globals, no hashing in the browser, native dialogs, CSS layer).
|
|
16
16
|
Known limits are listed below, so you can judge whether it fits your project:
|
|
17
17
|
|
|
18
18
|
- Rich text uses the deprecated `document.execCommand`. Content is sanitized in the browser, but sanitize it on the server too.
|
|
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
|
+
- Athena UI has **no dependencies**: no jQuery, no bundled library, nothing is loaded at run time, and nothing is put on `window` unless you opt in with
|
|
23
|
+
`athena-ui-js/classic`. The older generators (`generateLoginForm`, the layout and the header / footer menu built from `menuItems`) are plain DOM too.
|
|
24
|
+
- The default theme follows the system's dark mode. Put `data-mode="light"` on `<html>` (or use `createThemeManager`) to choose.
|
|
25
|
+
- Dialogs and the accordion use the native `<dialog>` and `<details>` elements, so they need a browser that supports cascade layers and `<dialog>` (2022 or later). The dropdown still has its own menu.
|
|
22
26
|
|
|
23
27
|
## Features
|
|
24
28
|
|
|
25
29
|
- Generated page layout: container, header (logo, title, menu), wrapper, footer (menu, copyright text)
|
|
26
30
|
- Menus built from your own item lists, with a navigation callback
|
|
27
31
|
- 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
|
|
32
|
+
- 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
|
|
33
|
+
- 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
|
|
34
|
+
- 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
|
|
35
|
+
- Sign in, sign up and password forms that password managers understand, and a signed-in state that lives in memory only
|
|
36
|
+
- Themes and modes (light / dark / like the system) with a theme manager, a picker and a no-flash boot script
|
|
37
|
+
- Form dialogs, confirmations (also "type the name to confirm"), date and time ranges with presets, page header, facts list, empty and loading states
|
|
38
|
+
- Safe DOM building (`el`, `createSafeBuilder`): text stays text, no event attributes, no inline style
|
|
30
39
|
- Form builder: text, number, date, textarea, select, radio / checkbox groups, switch, autocomplete, multi select, with validation
|
|
31
40
|
- Buttons, toasts, alerts, spinner, progress bar, alert / confirm / prompt dialogs
|
|
32
41
|
- Tabs, accordion, dropdown, sidebar, breadcrumbs, pagination and a hash / history router
|
|
@@ -37,42 +46,36 @@ Known limits are listed below, so you can judge whether it fits your project:
|
|
|
37
46
|
- Default and dark theme (switchable at runtime), responsive, translations (English, Hungarian), keyboard and ARIA support
|
|
38
47
|
- Modal open / close helpers
|
|
39
48
|
- Themes loaded at runtime, custom stylesheets supported
|
|
40
|
-
- Written as ES modules, no build step
|
|
49
|
+
- Written as ES modules, no build step, no dependencies, TypeScript definitions, one entry point per component, and a cascade layer so your CSS always wins
|
|
50
|
+
- Content-Security-Policy friendly: no inline script, no inline style, text from data is only ever inserted as text (the browser tests run under a strict policy)
|
|
41
51
|
|
|
42
52
|
## Requirements
|
|
43
53
|
|
|
44
|
-
-
|
|
45
|
-
- A browser with ES module support
|
|
54
|
+
- A current browser: ES modules, the native `<dialog>` and `<details>` elements and cascade layers (`@layer`, `@import ... layer()`): Chrome / Edge 99, Safari 15.4, Firefox 97 or later
|
|
46
55
|
- The page has to be served over HTTP(S). Modules do not load from `file://`.
|
|
47
|
-
|
|
48
|
-
Bundled as git submodules:
|
|
49
|
-
|
|
50
|
-
| Library | Version | Used for |
|
|
51
|
-
| --- | --- | --- |
|
|
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
|
-
| [crypto-js](https://github.com/brix/crypto-js) | 4.2.0 | password hashing |
|
|
55
|
-
| [js-cookie](https://github.com/js-cookie/js-cookie) | 3.0.8 | cookie handling |
|
|
56
|
+
- Nothing else: Athena UI has no runtime dependencies. (TypeScript is a dev dependency, used to write the type definitions.)
|
|
56
57
|
|
|
57
58
|
## Installation
|
|
58
59
|
|
|
59
60
|
```sh
|
|
60
|
-
|
|
61
|
+
npm install athena-ui-js
|
|
61
62
|
```
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
git submodule update --init
|
|
64
|
+
```js
|
|
65
|
+
import { init, generateTable } from "athena-ui-js"; // everything
|
|
66
|
+
import { generateTable } from "athena-ui-js/table"; // or only what you use, so the rest is never downloaded
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
The entry points are `table`, `chart`, `dialog`, `menu`, `navigation`, `forms`, `feedback`, `components`, `inputs`, `router`, `session`, `theme`, `i18n`, `format`,
|
|
70
|
+
`validation`, `sanitize`, `csv`, `dom` and `controls`. TypeScript definitions are included (`types/`, generated from the JSDoc with `npm run types`).
|
|
71
|
+
The package has `"sideEffects"` for `classic.js`, `theme-boot.js` and CSS only, so a bundler drops everything you do not import.
|
|
72
|
+
|
|
73
|
+
Without npm, serve the `src` folder with any static web server and open `index.html` to see the example.
|
|
70
74
|
|
|
71
75
|
## Usage
|
|
72
76
|
|
|
73
77
|
```html
|
|
74
|
-
|
|
75
|
-
integrity="sha256-OaVG6prZf4v69dPg6PhVattBXkcOWQB62pdZ3ORyrao=" crossorigin="anonymous"></script>
|
|
78
|
+
<!-- jQuery is not needed -->
|
|
76
79
|
<script type="module">
|
|
77
80
|
import { init, clearWrapper, generateLoginForm } from "./athena-ui.js";
|
|
78
81
|
|
|
@@ -100,6 +103,18 @@ Serve the `src` folder with any static web server and open `index.html` to see t
|
|
|
100
103
|
`init()` returns a Promise that resolves with the effective configuration once the libraries and
|
|
101
104
|
the theme are loaded and the layout is generated.
|
|
102
105
|
|
|
106
|
+
### Inside a page: createApp
|
|
107
|
+
|
|
108
|
+
`init()` builds the page layout into the body. `createApp` builds it into an element of your own page, so Athena UI can be one part of a larger one:
|
|
109
|
+
|
|
110
|
+
```js
|
|
111
|
+
const app = await createApp({ root: "#my-section", config: { generateHeader: false, generateFooter: false } });
|
|
112
|
+
generateTable({ parent: "wrapper", /* ... */ }); // the wrapper of the app is the default parent
|
|
113
|
+
app.destroy();
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
It takes the options of `init()`. The header and footer follow the settings `generateHeader` and `generateFooter`. The parts have fixed ids, so use one app per page.
|
|
117
|
+
|
|
103
118
|
### init options
|
|
104
119
|
|
|
105
120
|
| Option | Description |
|
|
@@ -120,7 +135,7 @@ the theme are loaded and the layout is generated.
|
|
|
120
135
|
| `header_title_text` | `"Athena UI"` | Title in the header |
|
|
121
136
|
| `header_img_url` | | Header logo URL |
|
|
122
137
|
| `copyright` | placeholder text | Footer text, the version is appended |
|
|
123
|
-
| `version` | `"
|
|
138
|
+
| `version` | `"2.0.0"` | Version shown in the footer |
|
|
124
139
|
| `bordered` | `true` | Draw a border around the layout blocks |
|
|
125
140
|
| `generateHeader`, `generateFooter` | `true` | Generate the header / footer block |
|
|
126
141
|
| `generateHeadercontent`, `generateFooterContent`, `generateWrappercontent` | `true` | Generate the content of the block |
|
|
@@ -132,7 +147,6 @@ the theme are loaded and the layout is generated.
|
|
|
132
147
|
| `locale` | `"en"` | Language of the generated texts (`en`, `hu`, or your own, see [Translations](#translations)) |
|
|
133
148
|
| `session_cookie` | `"athena_session"` | Name of the session cookie |
|
|
134
149
|
| `session_days` | `7` | Lifetime of a remembered session in days |
|
|
135
|
-
| `enable_encrypt_password` | `false` | SHA-256 hash the password before it is passed to `login` / `register` |
|
|
136
150
|
| `customLoader` | | URL of an extra classic script, loaded before the layout is generated |
|
|
137
151
|
| `container_class`, `header_class`, `header_menu_class`, `wrapper_class`, `footer_class`, `footer_menu_class`, `loginForm_class`, `registrationForm_class`, `lostPasswordForm_class`, `changePasswordForm_class` | | CSS classes of the generated blocks |
|
|
138
152
|
|
|
@@ -158,6 +172,14 @@ Everything is exported from `athena-ui.js`:
|
|
|
158
172
|
| `showDialog`, `alertDialog`, `confirmDialog`, `promptDialog` | See [Dialogs](#dialogs) |
|
|
159
173
|
| `generateTabs`, `generateBreadcrumbs`, `generatePagination`, `generateAccordion`, `generateDropdown`, `generateSidebar` | See [Navigation](#navigation) |
|
|
160
174
|
| `createRouter(options)` | See [Router](#router) |
|
|
175
|
+
| `generateMenu(options)`, `generateHeaderMenu({ items })` | See [Menu component](#menu-component) |
|
|
176
|
+
| `generateSignInForm`, `generateSignUpForm`, `generatePasswordResetForm`, `generatePasswordChangeForm`, `createAuthState` | See [Signing in](#signing-in-recommended) |
|
|
177
|
+
| `showFormDialog`, `showConfirm` | See [Dialogs](#dialogs) |
|
|
178
|
+
| `createThemeManager`, `generateThemePicker` | See [Themes and modes](#themes-and-modes-light--dark--like-the-system) |
|
|
179
|
+
| `generateDateTimeRange`, `toLocalInput`, `fromLocalInput` | See [Date and time range](#date-and-time-range) |
|
|
180
|
+
| `generatePageHeader`, `generateFacts`, `generateEmptyState`, `generateLoading`, `copyToClipboard` | See [Page parts and formatting](#page-parts-and-formatting) |
|
|
181
|
+
| `formatBytes`, `formatNumber`, `formatDuration`, `formatRelativeTime`, `formatDate` | Format helpers on top of `Intl`, in the current language |
|
|
182
|
+
| `el`, `setContent`, `resolveElement`, `asHandle`, `createSafeBuilder` | See [Safe DOM building](#safe-dom-building) |
|
|
161
183
|
| `generateCard`, `generateSection`, `generateGrid`, `generateBadge`, `generateAvatar`, `generateStat`, `generateLink`, `generateTooltip` | See [Components](#components) |
|
|
162
184
|
| `generateAutocomplete`, `generateMultiSelect`, `generateFileUpload`, `generateDropZone`, `generateStepper`, `generateDateRange`, `generateRichText`, `generateWysiwyg` | See [Inputs](#inputs) |
|
|
163
185
|
| `sanitizeHtml(html)`, `htmlToText(html)`, `isSafeUrl(url)` | The allow-list sanitizer behind the rich text editor |
|
|
@@ -168,27 +190,44 @@ Everything is exported from `athena-ui.js`:
|
|
|
168
190
|
| `setTheme({ id })` | Switch the theme at runtime |
|
|
169
191
|
| `openModal(id)`, `closeModal(id)` | Show / hide a `.modal` element (default id: `myModal`). Elements with the `close` class close their modal. |
|
|
170
192
|
| `loadScript(src)` | Load a classic script once, returns a Promise |
|
|
171
|
-
| `Cookies` |
|
|
172
|
-
| `
|
|
193
|
+
| `Cookies` | `get(name)`, `set(name, value, { expires, path, domain, sameSite, secure })`, `remove(name)`: a small cookie helper (`expires` is days or a Date) |
|
|
194
|
+
| `createApp(options)` | `init` into any element, see [Inside a page](#inside-a-page-createapp) |
|
|
195
|
+
| `HTMLElementGenerator(options)` | Generates a div, span, p, heading or img and appends it to the element with the id `parent` |
|
|
196
|
+
| `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` |
|
|
197
|
+
|
|
198
|
+
HTMLElementGenerator and HTMLControlGenerator used to be projects of their own. They are part of Athena UI now (the calls and options are the
|
|
199
|
+
same, and HTMLControlGenerator has no jQuery in it); the old repositories are no longer developed.
|
|
173
200
|
|
|
174
201
|
### Charts
|
|
175
202
|
|
|
176
203
|
```js
|
|
177
|
-
generateChart({
|
|
178
|
-
type: "
|
|
179
|
-
parent: "wrapper", // id
|
|
204
|
+
const chart = generateChart({
|
|
205
|
+
type: "line", // "bar" | "line" | "area" | "sparkline" | "pie" | "donut"
|
|
206
|
+
parent: "wrapper", // element, id or selector (default "wrapper")
|
|
180
207
|
title: "Revenue",
|
|
181
208
|
labels: ["Q1", "Q2", "Q3"],
|
|
182
209
|
series: [
|
|
183
210
|
{ name: "2025", data: [12, 19, 8] },
|
|
184
211
|
{ name: "2026", data: [14, 17, 12], color: "#e15759" }
|
|
185
|
-
]
|
|
212
|
+
],
|
|
213
|
+
table: true // adds "Show as table" with the values
|
|
186
214
|
});
|
|
187
215
|
```
|
|
188
216
|
|
|
189
|
-
Charts are inline SVG
|
|
190
|
-
|
|
191
|
-
|
|
217
|
+
Charts are inline SVG, nothing is styled inline (a strict Content-Security-Policy works), negative values are supported. `pie` and `donut` use the
|
|
218
|
+
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.
|
|
219
|
+
Other options: `id`, `width` (600), `height` (360), `legend`, `zero: false` (a line chart's value axis may start near the smallest value).
|
|
220
|
+
|
|
221
|
+
- **Colours** come from the theme: `--series-1` ... `--series-8` (see `appearance.css`), so every chart follows light / dark. `color` overrides one series.
|
|
222
|
+
- **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.
|
|
223
|
+
- **Legend**: click (or Enter / Space) on an entry hides and shows that series.
|
|
224
|
+
- **Time axis**: `times: [Date | ms | "2026-11-19T10:00"]` (line and area). Ticks fall on round times, points sit at their real distance.
|
|
225
|
+
- **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,
|
|
226
|
+
0 resets. `chart.zoom(from, to)`, `chart.resetZoom()`, `chart.getZoom()`, `onZoom(range)` and `zoomRange` (ms with `times`, otherwise the point index).
|
|
227
|
+
- **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.
|
|
228
|
+
- **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.
|
|
229
|
+
- `chart.update({ series })` redraws with changes, `chart.destroy()` removes the chart and its table. `generateChart` returns the `<svg>` element that carries these
|
|
230
|
+
methods, or `null` when the options are invalid.
|
|
192
231
|
|
|
193
232
|
### Tables
|
|
194
233
|
|
|
@@ -214,6 +253,13 @@ Click a header to sort (disable with `sortable: false`, or per column). Other op
|
|
|
214
253
|
- 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
254
|
- 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
255
|
- 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.
|
|
256
|
+
- **Rows from a server**: `dataSource: async ({ page, pageSize, cursor, sort, filter }) => ({ rows, total })`. Sorting, the (debounced) filter box and the pager ask it again,
|
|
257
|
+
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
|
|
258
|
+
(`page` is 0-based), or with `nextCursor` for a "Load more" button (`cursor` is what the last answer gave). `table.reload()` asks again.
|
|
259
|
+
- **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
|
|
260
|
+
`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.
|
|
261
|
+
The select-all checkbox only selects the rows that have arrived.
|
|
262
|
+
- `rowActions: [{ label: "Delete", danger: true, onclick: row => remove(row), hidden: row => row.locked, ariaLabel: row => "Delete " + row.name }]` adds a column of buttons.
|
|
217
263
|
- `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
264
|
|
|
219
265
|
### Forms
|
|
@@ -273,6 +319,25 @@ Options: `size` ("small" 360 px, "medium" 480 px, "large" 720 px, "full") and `c
|
|
|
273
319
|
`showDialog` returns a promise that also carries the open dialog: `const dialog = showDialog({ size: "large", ... }); dialog.element; dialog.close(value);`.
|
|
274
320
|
The dialog is shown by a CSS class, not by an inline style, so a strict Content-Security-Policy works.
|
|
275
321
|
|
|
322
|
+
**Form dialog** and **confirmation**:
|
|
323
|
+
|
|
324
|
+
```js
|
|
325
|
+
const saved = await showFormDialog({
|
|
326
|
+
title: "Add host", intro: "The agent connects with this name.", size: "small", submitText: "Add",
|
|
327
|
+
fields: [{ name: "name", label: "Name", required: true }],
|
|
328
|
+
onSubmit: async (values, form) => {
|
|
329
|
+
const answer = await api.addHost(values); // when this throws, the message shows in the dialog and it stays open
|
|
330
|
+
if (answer.errors) throw Object.assign(new Error("Check the fields"), { fields: answer.errors }); // or form.setErrors({ name: "Already taken" })
|
|
331
|
+
}
|
|
332
|
+
}); // true when saved, false when dismissed
|
|
333
|
+
|
|
334
|
+
if (await showConfirm({ title: "Delete host", message: "This cannot be undone.", confirmText: "Delete", danger: true, typeToConfirm: host.name })) { /* ... */ }
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
A dialog is the native `<dialog>` element opened with `showModal()`: the browser puts it above everything (the top layer), makes the page behind it inert, draws the backdrop
|
|
338
|
+
(`dialog.dialog::backdrop`), and gives the focus back. Style `dialog.dialog` and `.dialog-inner`. In tests under jsdom use `installDom` from `athena-ui-js/testing`
|
|
339
|
+
(it adds `showModal()`), and close a dialog with the `cancel` event, as the browser does for Esc.
|
|
340
|
+
|
|
276
341
|
Dialogs trap the focus, close with Esc (resolving `null` / `false`) and restore the focus. Text content is
|
|
277
342
|
never parsed as HTML. `openModal` / `closeModal` got the same focus handling.
|
|
278
343
|
|
|
@@ -310,6 +375,33 @@ init({
|
|
|
310
375
|
A submenu opens with a click, Enter, Space or the Down arrow, closes with Esc, a click outside or by choosing an entry,
|
|
311
376
|
and supports the arrow keys, Home and End. The same works in the footer menu.
|
|
312
377
|
|
|
378
|
+
### Menu component
|
|
379
|
+
|
|
380
|
+
`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.
|
|
381
|
+
|
|
382
|
+
```js
|
|
383
|
+
const menu = generateMenu({
|
|
384
|
+
parent: "header", // an element, an id or a selector
|
|
385
|
+
layout: "responsive", // "bar" | "bottom-tabs" | "responsive" (tabs at the bottom under 700px, groups open as sheets)
|
|
386
|
+
followHash: true, // the item whose href equals location.hash is the active one
|
|
387
|
+
onNavigate: (item, event) => console.log(item.id), // only when a person uses an item, never from select() or while building
|
|
388
|
+
items: [
|
|
389
|
+
{ id: "home", label: "Home", icon: "⌂", href: "#/" },
|
|
390
|
+
{ id: "inbox", label: "Inbox", href: "#/inbox", badge: 3, badgeLabel: "3 unread" },
|
|
391
|
+
{ id: "tools", label: "Tools", children: [
|
|
392
|
+
{ id: "export", label: "Export" },
|
|
393
|
+
{ id: "more", label: "More", children: [{ id: "csv", label: "CSV" }, { id: "json", label: "JSON" }] }
|
|
394
|
+
] },
|
|
395
|
+
{ id: "user", label: "Anna Kiss", avatar: { name: "Anna Kiss" }, align: "end", children: [{ id: "out", label: "Sign out" }] }
|
|
396
|
+
]
|
|
397
|
+
});
|
|
398
|
+
menu.select("inbox"); // marks the current page (class is-active, aria-current="page", has-active on the groups around it)
|
|
399
|
+
menu.setBadge("inbox", { text: 12, tone: "bad" }); // a count, text, or { text, tone: "info" | "ok" | "warn" | "bad" }; 0 / null removes it
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
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
|
|
403
|
+
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.
|
|
404
|
+
|
|
313
405
|
### Router
|
|
314
406
|
|
|
315
407
|
```js
|
|
@@ -327,6 +419,22 @@ router.start();
|
|
|
327
419
|
router.navigate("/users/5?tab=info");
|
|
328
420
|
```
|
|
329
421
|
|
|
422
|
+
Routes can carry the sign-in rules, so a page does not check them itself:
|
|
423
|
+
|
|
424
|
+
```js
|
|
425
|
+
const router = createRouter({
|
|
426
|
+
auth: auth.routerRules({ loginPath: "/login", homePath: "/", forbiddenPath: "/denied" }), // { isSignedIn, hasRole, ... }
|
|
427
|
+
focusContent: true, scrollTop: true, // after a page is shown: focus the outlet, scroll to the top
|
|
428
|
+
onShown: ctx => menu.select(ctx.path), // also onRender (before the page function) and router.onChange(listener)
|
|
429
|
+
routes: {
|
|
430
|
+
"/login": { handler: renderLogin, guestOnly: true }, // a signed-in person goes home
|
|
431
|
+
"/account": { handler: renderAccount, auth: true }, // not signed in: /login?next=%2Faccount
|
|
432
|
+
"/admin": { handler: renderAdmin, auth: true, roles: ["admin"] },
|
|
433
|
+
"/report": { handler: renderReport, guard: ctx => ctx.query.id ? undefined : "/reports" } // false stays, a path redirects
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
```
|
|
437
|
+
|
|
330
438
|
`mode: "history"` uses real paths instead of the hash, the server then has to answer every path with the page.
|
|
331
439
|
Pass `router.navigate` from your `nav` callback to route the menu clicks.
|
|
332
440
|
|
|
@@ -416,24 +524,41 @@ Missing texts fall back to English. See `src/libs/core/i18n.js` for all keys.
|
|
|
416
524
|
|
|
417
525
|
### Usage from classic scripts
|
|
418
526
|
|
|
419
|
-
The
|
|
420
|
-
|
|
527
|
+
The ES module has no side effects. For a page that uses inline handlers or classic scripts there is an opt-in build that puts the whole API on `window`
|
|
528
|
+
(and as `AthenaUI`):
|
|
421
529
|
|
|
422
530
|
```html
|
|
423
|
-
<script>
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
<script type="module" src="athena-ui/src/athena-ui.js"></script>
|
|
427
|
-
<script>
|
|
428
|
-
$(function () {
|
|
429
|
-
init({ theme: { id: 0 } });
|
|
430
|
-
});
|
|
531
|
+
<script type="module" src="node_modules/athena-ui-js/src/classic.js"></script>
|
|
532
|
+
<script type="module">
|
|
533
|
+
init({ theme: { id: 0 } }); // globals: init, generateTable, AthenaUI, HTMLControlGenerator, ...
|
|
431
534
|
</script>
|
|
432
535
|
```
|
|
433
536
|
|
|
434
|
-
The global `appConfig`, `menuItems`, `nav`, `login`, `register` and `lostPassword` are used when the matching `init` option is
|
|
435
|
-
|
|
436
|
-
|
|
537
|
+
The global `appConfig`, `menuItems`, `nav`, `login`, `register` and `lostPassword` are used when the matching `init` option is not given.
|
|
538
|
+
|
|
539
|
+
### Signing in (recommended)
|
|
540
|
+
|
|
541
|
+
`generateSignInForm`, `generateSignUpForm`, `generatePasswordResetForm` and `generatePasswordChangeForm` are real `<form>` elements with the autocomplete tokens
|
|
542
|
+
that password managers look for (`username`, `current-password`, `new-password`, `email`), so Enter submits and the browser can save and fill passwords.
|
|
543
|
+
|
|
544
|
+
```js
|
|
545
|
+
const auth = createAuthState({ restore: () => fetch("/api/me", { credentials: "same-origin" }).then(r => (r.ok ? r.json() : null)) });
|
|
546
|
+
await auth.restore(); // after a reload: ask the server who is signed in
|
|
547
|
+
|
|
548
|
+
generateSignInForm({
|
|
549
|
+
parent: "wrapper", remember: true,
|
|
550
|
+
onSubmit: async ({ username, password, remember }) => {
|
|
551
|
+
const response = await fetch("/api/login", { method: "POST", body: JSON.stringify({ username, password, remember }), credentials: "same-origin" });
|
|
552
|
+
if (!response.ok) throw new Error("Wrong user name or password"); // shown in the form, which stays usable
|
|
553
|
+
auth.signIn(await response.json()); // { name, roles: [...] }
|
|
554
|
+
}
|
|
555
|
+
});
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
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.
|
|
559
|
+
Hashing it in the browser only turns the hash into the password, so Athena UI 2.0 does not do it any more (the setting `enable_encrypt_password` and crypto-js are gone; the old login, registration and change password forms return the password as typed).
|
|
560
|
+
`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,
|
|
561
|
+
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.
|
|
437
562
|
|
|
438
563
|
## Themes
|
|
439
564
|
|
|
@@ -449,6 +574,85 @@ The default theme is in `src/res/themes/default/style.css`; `{ id: 1 }` is a dar
|
|
|
449
574
|
|
|
450
575
|
Switch themes at runtime with `setTheme({ id: 1 })`.
|
|
451
576
|
|
|
577
|
+
### Styling: the cascade layer, tokens and dark mode
|
|
578
|
+
|
|
579
|
+
All rules of the default theme are in the cascade layer `athena`. CSS that is not in a layer (the normal CSS of your application) beats it **whatever the specificity**, so
|
|
580
|
+
`.my-table td { padding: 2px }` or even `td { padding: 2px }` is enough, with no `!important`. The design tokens are in `src/res/themes/tokens.css` and are the way to
|
|
581
|
+
restyle everything at once:
|
|
582
|
+
|
|
583
|
+
```css
|
|
584
|
+
:root { --athena-accent: #8e44ad; --athena-radius: 2px; --athena-space-2: 6px; --athena-dialog-medium: 560px; }
|
|
585
|
+
```
|
|
586
|
+
|
|
587
|
+
The colours come in a light and a dark set. Without the attribute `data-mode` on `<html>` the page follows the system (`prefers-color-scheme`); `data-mode="dark"` or
|
|
588
|
+
`"light"` chooses. [docs/styling.md](docs/styling.md) lists every token and, for every group of rules, the classes and variables it uses (it is generated from the CSS by `npm run docs`).
|
|
589
|
+
|
|
590
|
+
### Themes and modes (light / dark / like the system)
|
|
591
|
+
|
|
592
|
+
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:
|
|
593
|
+
|
|
594
|
+
```html
|
|
595
|
+
<link rel="stylesheet" href="athena-ui/src/res/themes/default/style.css">
|
|
596
|
+
<link rel="stylesheet" href="athena-ui/src/res/themes/appearance.css">
|
|
597
|
+
<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 -->
|
|
598
|
+
```
|
|
599
|
+
|
|
600
|
+
```js
|
|
601
|
+
const manager = createThemeManager({ themes: [{ id: "athena", name: "Athena" }, { id: "contrast", name: "High contrast" }], storageKey: "myapp.appearance",
|
|
602
|
+
themeColorVariable: "--athena-bg" }); // <meta name="theme-color"> follows this variable
|
|
603
|
+
manager.setTheme("contrast"); manager.setMode("dark"); // "system" | "light" | "dark"; saved in localStorage, other tabs follow
|
|
604
|
+
manager.onChange(({ theme, mode, dark }) => redrawChartsOrWhatever());
|
|
605
|
+
generateThemePicker({ parent: "account-page", manager }); // radio groups with a small preview of every theme
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
**The contract of a theme** (also at the top of `appearance.css`): a theme is a pair of CSS blocks that set the tokens
|
|
609
|
+
`--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`:
|
|
610
|
+
|
|
611
|
+
```css
|
|
612
|
+
[data-theme="ocean"][data-mode="light"] { --athena-bg: #f4f9fb; /* ... */ }
|
|
613
|
+
[data-theme="ocean"][data-mode="dark"] { --athena-bg: #0b1c24; /* ... */ }
|
|
614
|
+
```
|
|
615
|
+
|
|
616
|
+
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`.
|
|
617
|
+
Athena and High contrast (light and dark) are included; without the script the page follows the system.
|
|
618
|
+
|
|
619
|
+
### Date and time range
|
|
620
|
+
|
|
621
|
+
```js
|
|
622
|
+
const range = generateDateTimeRange({ parent: "wrapper", label: "Time", preset: "24h", onChange: ({ from, to, preset }) => reload() });
|
|
623
|
+
range.getRange(); // { from: Date, to: Date }. A preset ("15m", "1h", "24h", "7d", "30d") is measured from NOW when this is called
|
|
624
|
+
range.getValue(); // { from: "2026-11-19T08:00", to: "...", preset: "24h" }, the values of the inputs
|
|
625
|
+
```
|
|
626
|
+
|
|
627
|
+
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.
|
|
628
|
+
`toLocalInput(date)` and `fromLocalInput(value)` convert between a Date and the value of such an input.
|
|
629
|
+
|
|
630
|
+
### Page parts and formatting
|
|
631
|
+
|
|
632
|
+
```js
|
|
633
|
+
generatePageHeader({ parent: "wrapper", title: "Hosts", description: "All monitored machines", breadcrumbs: [{ label: "Home", href: "#/" }, { label: "Hosts" }], actions: [addButton] });
|
|
634
|
+
generateFacts({ parent: "wrapper", items: [{ term: "System", description: "Linux" }, { term: "Seen", description: formatRelativeTime(host.lastSeen) }] });
|
|
635
|
+
generateEmptyState({ parent: "wrapper", title: "No hosts yet", message: "Install the agent.", action: { text: "Add host", onclick: add } });
|
|
636
|
+
generateLoading({ parent: "wrapper" }); // spinner + text, a live region
|
|
637
|
+
generateStat({ parent: "wrapper", label: "CPU", value: "91 %", tone: "bad", note: "of 4 cores" }); // tone: "ok" | "warn" | "bad" (colour + a word for screen readers)
|
|
638
|
+
await copyToClipboard(token); // and says "Copied" in a toast
|
|
639
|
+
formatBytes(1536); formatNumber(1234567.891); formatDuration(7500000); formatRelativeTime(date); formatDate(date, { time: true }); // Intl, in the current language
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
### Safe DOM building
|
|
643
|
+
|
|
644
|
+
`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
|
|
645
|
+
nested lists, listeners have to be functions, and `on*` attributes, `style` and `srcdoc`, unsafe addresses (`javascript:`, `data:`) in `href` / `src` / `action`, and properties that
|
|
646
|
+
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
|
|
647
|
+
do not control (a plugin API).
|
|
648
|
+
|
|
649
|
+
### Moved into Athena: HTMLElementGenerator and HTMLControlGenerator
|
|
650
|
+
|
|
651
|
+
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
|
|
652
|
+
`src/libs/core/elementGenerator.js`, `HTMLControlGenerator(options)` / `.create()` / `.register()` in `src/libs/core/controls.js`; both are exported and global as before.
|
|
653
|
+
`HTMLControlGenerator` has no jQuery in it: `create` returns the element (wrap it yourself with `$(...)` if you still need a jQuery object).
|
|
654
|
+
`registerHungarianInputControls()` adds the `hunPIN`, `hunCRID` and `hunTID` input types of its old addon. The old repositories are no longer developed.
|
|
655
|
+
|
|
452
656
|
### Parents and handles
|
|
453
657
|
|
|
454
658
|
Every `parent` option takes an element, an id or a CSS selector (`"wrapper"`, `"#list"`, `".panel > ul"`; an id wins over a selector).
|
|
@@ -482,24 +686,35 @@ npm run test:browser # the components in headless Chrome
|
|
|
482
686
|
The unit tests cover validation, translations, router matching, CSV, pagination, formatting, virtual scrolling math, date ranges and the URL check.
|
|
483
687
|
The browser tests start a small static server, open `tests/browser/index.html` in headless Chrome, Chromium or Edge and run every
|
|
484
688
|
component: forms, dialogs, navigation, submenus, inputs, rich text (sanitizing, toolbar, paste), tables (resizing, virtual scrolling), router,
|
|
485
|
-
session, themes. Set `CHROME_PATH` if the browser is not found
|
|
486
|
-
|
|
689
|
+
session, themes. Set `CHROME_PATH` if the browser is not found. `DEBUG=1` prints the browser log when the page does not report results.
|
|
690
|
+
|
|
691
|
+
- **The page runs under a strict Content-Security-Policy** (`default-src 'none'; script-src 'self'; style-src 'self'`, set by `run.mjs`), and a `securitypolicyviolation` fails the test
|
|
692
|
+
that caused it. That is the guarantee that Athena UI needs no `'unsafe-inline'`. (Three tests that hand the sanitizer hostile markup are let through for the one report Chrome
|
|
693
|
+
makes while it parses an inline handler in an inert document.)
|
|
694
|
+
- One test feeds markup to about 40 components and checks that text from data stays text.
|
|
695
|
+
- `WITH_JQUERY=1 npm run test:browser` loads jQuery from its CDN, to check that an application that still has it works too (`JQUERY_URL` for another address).
|
|
696
|
+
- The unit tests also check that `docs/styling.md` is up to date, and that a TypeScript file using the library compiles against `types/` (needs `npm install` for TypeScript).
|
|
487
697
|
|
|
488
698
|
## Project structure
|
|
489
699
|
|
|
490
700
|
```
|
|
491
701
|
src/
|
|
492
|
-
athena-ui.js
|
|
702
|
+
athena-ui.js the whole API as ES module exports (no side effects)
|
|
703
|
+
classic.js opt-in: the whole API on window, for classic scripts
|
|
704
|
+
table.js, dialog.js, ... one entry point per component (athena-ui-js/table, athena-ui-js/dialog, ...)
|
|
705
|
+
theme-boot.js classic script that sets the saved theme and mode before the page is drawn
|
|
706
|
+
testing.js installDom, until, tick for the tests of an application
|
|
493
707
|
index.html, example.js example page
|
|
494
708
|
libs/
|
|
495
709
|
config/ default configuration, application hooks
|
|
496
|
-
core/ DOM / focus helpers, validation, translations, CSV, formatting, sanitizer,
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
710
|
+
core/ DOM / focus helpers, el, validation, translations, CSV, formatting, sanitizer, cookies, theme manager,
|
|
711
|
+
HTMLElementGenerator, HTMLControlGenerator, table math
|
|
712
|
+
hephaestus/ theme loader, generators (layout, menus, forms, charts, tables, feedback, dialogs, navigation,
|
|
713
|
+
components, inputs), router, session, auth state
|
|
714
|
+
res/themes/ tokens.css, default and dark theme, appearance.css (themes and modes)
|
|
715
|
+
types/ TypeScript definitions (npm run types)
|
|
716
|
+
docs/ styling.md (generated), migration-2.0.md
|
|
717
|
+
tests/ unit tests (Node) and browser tests (headless Chrome, strict CSP)
|
|
503
718
|
```
|
|
504
719
|
|
|
505
720
|
## Authors
|
|
@@ -512,6 +727,43 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
|
512
727
|
|
|
513
728
|
## Releases
|
|
514
729
|
|
|
730
|
+
### 2.0.0
|
|
731
|
+
#### Breaking (see [docs/migration-2.0.md](docs/migration-2.0.md)):
|
|
732
|
+
1. No default export, and nothing on `window` unless you import `athena-ui-js/classic`; `athena-ui.js` has no side effects
|
|
733
|
+
2. No jQuery anywhere (not a peer dependency any more); `HTMLControlGenerator.create` returns the element
|
|
734
|
+
3. crypto-js and js-cookie are removed (own `Cookies` helper), and so are `enable_encrypt_password` and the hashing of passwords in the browser
|
|
735
|
+
4. Nothing is loaded at run time (`libs.js` and `loadLibs` are gone); `customLoader` still loads your own script
|
|
736
|
+
5. `showDialog` and the other dialogs use a native `<dialog>` (`showModal`), the accordion uses `<details>`: the markup and CSS classes changed
|
|
737
|
+
6. All default rules are in the cascade layer `athena`, and the default theme follows the system's dark mode
|
|
738
|
+
7. `package.json` has an `exports` map: deep imports of `src/libs/...` are not possible
|
|
739
|
+
#### Added:
|
|
740
|
+
1. One entry point per component (`athena-ui-js/table`, `/dialog`, `/menu`, ...), `"sideEffects"` for tree shaking
|
|
741
|
+
2. TypeScript definitions (`types/`, generated from the JSDoc)
|
|
742
|
+
3. `createApp({ root })`: the layout into any element
|
|
743
|
+
4. `tokens.css` (radius, spacing, border, focus ring, dialog widths, row height, colours), a built-in dark mode, `docs/styling.md`
|
|
744
|
+
5. Plural forms in messages (`Intl.PluralRules`), `{name:number}` and `{name:date}` in `translate`
|
|
745
|
+
6. The browser tests run under a strict Content-Security-Policy and fail on any violation; one test checks that every component inserts text as text
|
|
746
|
+
7. `docs/migration-2.0.md`
|
|
747
|
+
|
|
748
|
+
### 1.3.0
|
|
749
|
+
#### Added:
|
|
750
|
+
1. Dialogs: `showFormDialog` (async save, errors stay in the dialog, `form.setErrors`) and `showConfirm` (`danger`, `typeToConfirm`)
|
|
751
|
+
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)
|
|
752
|
+
3. `generateMenu`: real links and buttons, groups of any depth, badges, avatar user menu, active item, bar / bottom tabs / responsive; `generateHeaderMenu({ items })`
|
|
753
|
+
4. Tables: `dataSource` (pages, cursor "Load more", loading / empty / error with Retry), `dataSource` together with `virtual`, `rowActions`, `reload()`
|
|
754
|
+
5. Charts: `area` and `sparkline`, time axis, tooltips, clickable legend, table of values, theme colours, zoom, long series thinning, `push()` for streaming
|
|
755
|
+
6. Router: `auth`, `guestOnly`, `roles`, `guard`, `onRender` / `onShown`, `focusContent`, `scrollTop`, `router.onChange`
|
|
756
|
+
7. `generateSignInForm`, `generateSignUpForm`, `generatePasswordResetForm`, `generatePasswordChangeForm`, `createAuthState`
|
|
757
|
+
8. `generateDateTimeRange` with presets, `generatePageHeader`, `generateFacts`, `generateEmptyState`, `generateLoading`, stat `tone` and `note`, `copyToClipboard`, format helpers
|
|
758
|
+
9. `el`, `setContent`, `resolveElement`, `asHandle` and `createSafeBuilder` are exported
|
|
759
|
+
10. HTMLElementGenerator and HTMLControlGenerator (and the Hungarian input addon) are part of Athena UI; no more submodules for them
|
|
760
|
+
#### Changed:
|
|
761
|
+
1. jQuery is optional: init() does not need it, the layout, modal, forms and menus use plain DOM, the browser tests run without it
|
|
762
|
+
2. Only crypto-js can still be loaded as a classic script, and only with `enable_encrypt_password`
|
|
763
|
+
3. `el()` refuses code attributes and unsafe addresses
|
|
764
|
+
#### Deprecated:
|
|
765
|
+
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
|
|
766
|
+
|
|
515
767
|
### 1.2.0
|
|
516
768
|
#### Added:
|
|
517
769
|
1. Dialogs: `size` and `class` options, and the open dialog (`element`, `backdrop`, `close()`) on the returned promise
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Moving from Athena UI 1.x to 2.0
|
|
2
|
+
|
|
3
|
+
2.0 is lighter and has no side effects: no jQuery, no globals, no libraries loaded at run time, and everything is in a cascade layer. Most of what you call
|
|
4
|
+
(`generateTable`, `showDialog`, `createRouter`, ...) is the same. This is the list of what is not, in the order you will probably meet it.
|
|
5
|
+
|
|
6
|
+
## 1. Imports: no default export, no globals
|
|
7
|
+
|
|
8
|
+
`athena-ui.js` is plain ES module exports now. Importing it does not touch the page, and nothing is put on `window`.
|
|
9
|
+
|
|
10
|
+
```js
|
|
11
|
+
// 1.x
|
|
12
|
+
import AthenaUI, { init } from "athena-ui-js"; // the default export is gone
|
|
13
|
+
window.generateTable(...) // the globals are gone
|
|
14
|
+
|
|
15
|
+
// 2.0
|
|
16
|
+
import { init, generateTable } from "athena-ui-js";
|
|
17
|
+
import { generateTable } from "athena-ui-js/table"; // or only what you use, so the rest is never downloaded
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Entry points: `table`, `chart`, `dialog`, `menu`, `navigation`, `forms`, `feedback`, `components`, `inputs`, `router`, `session`, `theme`, `i18n`, `format`,
|
|
21
|
+
`validation`, `sanitize`, `csv`, `dom`, `controls`. Deep imports of files under `src/libs` are not part of the package interface (the `exports` map closes them).
|
|
22
|
+
|
|
23
|
+
**A page that needs the globals** (inline handlers, classic scripts, the `customLoader`) opts in with one line:
|
|
24
|
+
|
|
25
|
+
```html
|
|
26
|
+
<script type="module" src="node_modules/athena-ui-js/src/classic.js"></script> <!-- window.generateTable, window.AthenaUI, ... -->
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 2. jQuery is gone
|
|
30
|
+
|
|
31
|
+
Athena UI has no jQuery code, and `jquery` is not a peer dependency any more. The one place where a jQuery object came back to you,
|
|
32
|
+
`HTMLControlGenerator.create(options)`, returns the element now: use `$(HTMLControlGenerator.create(options))` if you still want a jQuery object.
|
|
33
|
+
`HTMLControlGenerator.register(type, factory)`: the factory returns an element.
|
|
34
|
+
|
|
35
|
+
## 3. crypto-js and js-cookie are gone
|
|
36
|
+
|
|
37
|
+
- **`enable_encrypt_password` is removed.** The login, registration and change password forms return the password as it was typed. Send it over HTTPS and hash
|
|
38
|
+
it on the server (argon2, scrypt, bcrypt). Hashing it in the browser only turns the hash into the password. If your server expects a SHA-256 hash, change
|
|
39
|
+
the server, or hash in your own `login` callback with `crypto.subtle.digest("SHA-256", ...)`.
|
|
40
|
+
- **`Cookies`** is a small helper of our own with `get`, `set` and `remove` (days or a `Date` for `expires`, `path`, `domain`, `sameSite`, `secure`).
|
|
41
|
+
What js-cookie had beyond that (`getJSON`, `withAttributes`, converters) is not there.
|
|
42
|
+
- No script is loaded at run time any more (`libs.js` and `loadLibs` are removed). `customLoader` (your own classic script) still works.
|
|
43
|
+
|
|
44
|
+
## 4. HTMLElementGenerator and HTMLControlGenerator
|
|
45
|
+
|
|
46
|
+
They are part of Athena UI (`athena-ui-js/controls`) and no longer git submodules. The calls are the same; with the classic build they are globals again.
|
|
47
|
+
|
|
48
|
+
## 5. Dialogs and the accordion use native elements
|
|
49
|
+
|
|
50
|
+
- `showDialog` (and `confirmDialog`, `promptDialog`, `showConfirm`, `showFormDialog`) opens a real `<dialog>` with `showModal()`. The browser traps the focus, closes
|
|
51
|
+
it with Esc, draws the backdrop and puts it in the top layer. In your CSS, `.dialog-backdrop` and `.modal-content` are gone from these dialogs: style
|
|
52
|
+
`dialog.dialog`, `dialog.dialog::backdrop` and `.dialog-inner`. `handle.backdrop` is the dialog element too. In a test (jsdom) use `installDom` from
|
|
53
|
+
`athena-ui-js/testing`, which gives jsdom `showModal()`; a synthetic Esc key does not close a native dialog, send the `cancel` event instead.
|
|
54
|
+
- `generateAccordion` is `<details>` and `<summary>`: `.accordion-header` is a `<summary>`, there is no `aria-expanded` on a button, `.accordion-open` is the
|
|
55
|
+
`[open]` attribute and `.accordion-title` is gone. `accordion.toggle(index, open)` works as before.
|
|
56
|
+
- The dropdown keeps its own menu (a top-layer `popover` would need anchor positioning, which not every supported browser has yet).
|
|
57
|
+
|
|
58
|
+
## 6. CSS: a layer, tokens and dark mode
|
|
59
|
+
|
|
60
|
+
- All rules of the default theme are in the cascade layer `athena`, so a plain rule of your application wins without a more specific selector. If you used
|
|
61
|
+
`!important` or a longer selector to beat Athena, you can take it out. If you put Athena's CSS into **your own layer order**, declare `athena` where you want it.
|
|
62
|
+
- The tokens are in `src/res/themes/tokens.css` (radius, spacing, border, focus ring, dialog widths, row height and the colours), see `docs/styling.md` for every
|
|
63
|
+
class and variable. The new tokens are `--athena-focus`, `--athena-focus-width`, `--athena-border-width`, `--athena-space-1` ... `--athena-space-4`,
|
|
64
|
+
`--athena-dialog-small|medium|large` and `--athena-row-height`.
|
|
65
|
+
- **The default theme follows the system now**: on a device that prefers dark colours it is dark unless `data-mode="light"` is on `<html>`. To keep it light
|
|
66
|
+
always, put `data-mode="light"` on `<html>` (or use `createThemeManager`, which does it).
|
|
67
|
+
- `src/res/themes/dark/style.css` (theme `{ id: 1 }`) still works.
|
|
68
|
+
|
|
69
|
+
## 7. Small things
|
|
70
|
+
|
|
71
|
+
- Messages with plural forms: `validation.minLength`, `validation.maxLength` and `validation.maxFiles` are `{ one, other }` objects in the built-in English texts. A message you
|
|
72
|
+
override with `addMessages` can stay a plain string. `translate` knows `{name:number}` and `{name:date}`, and chooses a plural form by `params.count`.
|
|
73
|
+
- `package.json`: `"sideEffects"` lists only `classic.js`, `theme-boot.js` and CSS, so bundlers can drop what you do not use. TypeScript definitions are in `types/`.
|
|
74
|
+
- The browser tests run under a strict Content-Security-Policy (no inline script, no inline style) and fail on any violation: the library does not need `'unsafe-inline'`.
|
|
75
|
+
- `init()` and `createApp({ root })`: `createApp` builds the layout into an element of your page instead of the body.
|
|
76
|
+
|
|
77
|
+
## Upgrade in five steps
|
|
78
|
+
|
|
79
|
+
1. Replace `import AthenaUI from ...` and `window.` calls by named imports, or add the `classic.js` line.
|
|
80
|
+
2. Remove the jQuery script tag if nothing else of yours needs it.
|
|
81
|
+
3. Remove `enable_encrypt_password` and make the server hash the password.
|
|
82
|
+
4. Search your CSS for `.dialog-backdrop`, `.modal-content` (in dialogs) and `.accordion-open`, and for rules that only exist to beat Athena's specificity.
|
|
83
|
+
5. Run your tests, with a Content-Security-Policy on the page if you can: it tells you what still writes inline styles or scripts.
|