athena-ui-js 2.5.0 → 2.5.1
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 +1128 -1122
- package/package.json +172 -189
- package/src/athena-ui.js +135 -135
- package/src/libs/config/config.js +66 -66
package/README.md
CHANGED
|
@@ -1,1122 +1,1128 @@
|
|
|
1
|
-
# Athena UI
|
|
2
|
-
|
|
3
|
-
A small UI framework for development and education purposes. It generates a page
|
|
4
|
-
layout (header, menu, content wrapper, footer) from a single `init()` call, loads its own libraries
|
|
5
|
-
and theme, and ships the building blocks of a multipurpose application: forms, tables, charts,
|
|
6
|
-
feedback, navigation, a router and more.
|
|
7
|
-
|
|
8
|
-
Current version: **2.5.
|
|
9
|
-
|
|
10
|
-
[Quick start](#usage) · [API](#api) · [Components](#charts) · [Themes](#themes) · [Tests](#tests) · [Release notes](#releases)
|
|
11
|
-
|
|
12
|
-
## Status
|
|
13
|
-
|
|
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
|
-
Known limits are listed below, so you can judge whether it fits your project:
|
|
17
|
-
|
|
18
|
-
- Rich text uses the deprecated `document.execCommand`. Content is sanitized in the browser, but sanitize it on the server too.
|
|
19
|
-
- The session cookie is readable from JavaScript. It is a UI state, not a security boundary: authenticate on the server.
|
|
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
|
-
- 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, the accordion, the dropdown menu and tooltips use the native `<dialog>`, `<details>` and popover elements, so they need a browser that supports cascade layers and `<dialog>` (2022 or later). The dropdown menu and the tooltips are native popovers (the `popover` attribute) in browsers that have them (Chrome / Edge 114, Safari 17, Firefox 125), and a plain fallback in older ones.
|
|
26
|
-
|
|
27
|
-
## Features
|
|
28
|
-
|
|
29
|
-
- Generated page layout: container, header (logo, title, menu), wrapper, footer (menu, copyright text)
|
|
30
|
-
- Menus built from your own item lists, with a navigation callback
|
|
31
|
-
- Login, registration and lost password forms with optional SHA-256 password hashing
|
|
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
|
|
39
|
-
- Form builder: text, number, date, textarea, select, radio / checkbox groups, switch, autocomplete, multi select, with validation
|
|
40
|
-
- Buttons, toasts, alerts, spinner, progress bar, alert / confirm / prompt dialogs
|
|
41
|
-
- Tabs, accordion, dropdown, sidebar, breadcrumbs, pagination and a hash / history router
|
|
42
|
-
- Cards, grid, badges, avatars, KPI tiles, tooltips, links, sections
|
|
43
|
-
- File upload with progress, drag-and-drop area, stepper (wizard), date range picker, rich text and WYSIWYG editor
|
|
44
|
-
- Menus with submenus
|
|
45
|
-
- Session handling (login state in a cookie), change password form
|
|
46
|
-
- Default and dark theme (switchable at runtime), responsive, translations (English, Hungarian), keyboard and ARIA support
|
|
47
|
-
- Modal open / close helpers
|
|
48
|
-
- Themes loaded at runtime, custom stylesheets supported
|
|
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)
|
|
51
|
-
|
|
52
|
-
## Requirements
|
|
53
|
-
|
|
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
|
|
55
|
-
- The page has to be served over HTTP(S). Modules do not load from `file://`.
|
|
56
|
-
- Nothing else: Athena UI has no runtime dependencies. (TypeScript is a dev dependency, used to write the type definitions.)
|
|
57
|
-
|
|
58
|
-
## Installation
|
|
59
|
-
|
|
60
|
-
```sh
|
|
61
|
-
npm install athena-ui-js
|
|
62
|
-
```
|
|
63
|
-
|
|
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
|
-
```
|
|
68
|
-
|
|
69
|
-
The entry points are `table`, `chart`, `dialog`, `menu`, `navigation`, `forms`, `feedback`, `components`, `inputs`, `router`, `session`, `theme`, `i18n`, `format`,
|
|
70
|
-
`validation`, `motion`, `widgets`, `code`, `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.
|
|
74
|
-
|
|
75
|
-
### The demo application
|
|
76
|
-
|
|
77
|
-
**Try it live: https://athena-ui-js-demo-duc7dncrfhg5fxfs.northeurope-01.azurewebsites.net** (sign in with `demo` / `demo-pass`, or `admin` / `admin-pass`; the app sleeps when nobody visits, so the first request can take a few seconds).
|
|
78
|
-
|
|
79
|
-
`demo/` is a demo and test application: tables with 100,000 rows from a server, a streaming chart, every field type, native dialogs, a menu with groups inside groups, themes
|
|
80
|
-
and modes, and a real sign in, served by a small Node server (no dependencies) under a strict Content-Security-Policy.
|
|
81
|
-
|
|
82
|
-
```sh
|
|
83
|
-
npm run demo # http://localhost:3000
|
|
84
|
-
npm run test:demo # the server, the API and every page in a real browser
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
GitHub Actions tests it and deploys it to an Azure App Service: [demo/README.md](demo/README.md) has the one-time set up.
|
|
88
|
-
|
|
89
|
-
## Usage
|
|
90
|
-
|
|
91
|
-
```html
|
|
92
|
-
<!-- jQuery is not needed -->
|
|
93
|
-
<script type="module">
|
|
94
|
-
import { init, clearWrapper, generateLoginForm } from "./athena-ui.js";
|
|
95
|
-
|
|
96
|
-
init({
|
|
97
|
-
theme: { id: 0 },
|
|
98
|
-
config: { header_title_text: "My App", login_enabled: true },
|
|
99
|
-
menuItems: {
|
|
100
|
-
headerMenu: [
|
|
101
|
-
{ id: "menu-home", class: "menu-item", text: "", inner_text: "Home" },
|
|
102
|
-
{ id: "menu-login", class: "menu-item", text: "", inner_text: "Login" }
|
|
103
|
-
],
|
|
104
|
-
footerMenu: []
|
|
105
|
-
},
|
|
106
|
-
nav: page => {
|
|
107
|
-
if (page === "Login") {
|
|
108
|
-
clearWrapper();
|
|
109
|
-
generateLoginForm();
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
login: ({ username, password }) => console.log(`${username} logged in`)
|
|
113
|
-
});
|
|
114
|
-
</script>
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
`init()` returns a Promise that resolves with the effective configuration once the libraries and
|
|
118
|
-
the theme are loaded and the layout is generated.
|
|
119
|
-
|
|
120
|
-
### Inside a page: createApp
|
|
121
|
-
|
|
122
|
-
`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:
|
|
123
|
-
|
|
124
|
-
```js
|
|
125
|
-
const app = await createApp({ root: "#my-section", config: { generateHeader: false, generateFooter: false } });
|
|
126
|
-
generateTable({ parent: "wrapper", /* ... */ }); // the wrapper of the app is the default parent
|
|
127
|
-
app.destroy();
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
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.
|
|
131
|
-
|
|
132
|
-
### init options
|
|
133
|
-
|
|
134
|
-
| Option | Description |
|
|
135
|
-
| --- | --- |
|
|
136
|
-
| `theme` | `{ id }` of a theme registered in `res/themes/themes.js`, or `{ href }` of a custom stylesheet. Defaults to the default theme. |
|
|
137
|
-
| `config` | Settings overriding the defaults, see [Configuration](#configuration). |
|
|
138
|
-
| `menuItems` | `{ headerMenu, footerMenu }`, arrays of `{ id, class, text, inner_text }`. Placeholder items are generated without it. |
|
|
139
|
-
| `nav` | Called without arguments when the wrapper is generated, and with the `inner_text` of the item on menu clicks. |
|
|
140
|
-
| `login` | Called with `{ username, password }` when the login button is clicked and `login_enabled` is set. |
|
|
141
|
-
| `register` | Called with `{ username, email, password }` when a valid registration form is submitted and `registration_enabled` is set. |
|
|
142
|
-
| `lostPassword` | Called with `{ email }` when a valid lost password form is submitted and `lost_password_enabled` is set. |
|
|
143
|
-
| `changePassword` | Called with `{ currentPassword, newPassword }` when a valid change password form is submitted and `change_password_enabled` is set. |
|
|
144
|
-
|
|
145
|
-
### Configuration
|
|
146
|
-
|
|
147
|
-
| Setting | Default | Description |
|
|
148
|
-
| --- | --- | --- |
|
|
149
|
-
| `header_title_text` | `"Athena UI"` | Title in the header |
|
|
150
|
-
| `header_img_url` | | Header logo URL |
|
|
151
|
-
| `copyright` | placeholder text | Footer text, the version is appended |
|
|
152
|
-
| `version` | `"2.5.
|
|
153
|
-
| `bordered` | `true` | Draw a border around the layout blocks |
|
|
154
|
-
| `generateHeader`, `generateFooter` | `true` | Generate the header / footer block |
|
|
155
|
-
| `generateHeadercontent`, `generateFooterContent`, `generateWrappercontent` | `true` | Generate the content of the block |
|
|
156
|
-
| `login_enabled` | `false` | Call the `login` callback from the login form |
|
|
157
|
-
| `registration_enabled` | `false` | Call the `register` callback from the registration form |
|
|
158
|
-
| `lost_password_enabled` | `false` | Call the `lostPassword` callback from the lost password form |
|
|
159
|
-
| `change_password_enabled` | `false` | Call the `changePassword` callback from the change password form |
|
|
160
|
-
| `login_remember_me` | `false` | Show a "Remember me" checkbox in the login form, passed to `login` as `remember` |
|
|
161
|
-
| `locale` | `"en"` | Language of the generated texts (`en`, `hu`, or your own, see [Translations](#translations)) |
|
|
162
|
-
| `session_cookie` | `"athena_session"` | Name of the session cookie |
|
|
163
|
-
| `session_days` | `7` | Lifetime of a remembered session in days |
|
|
164
|
-
| `customLoader` | | URL of an extra classic script, loaded before the layout is generated |
|
|
165
|
-
| `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 |
|
|
166
|
-
|
|
167
|
-
### API
|
|
168
|
-
|
|
169
|
-
Everything is exported from `athena-ui.js`:
|
|
170
|
-
|
|
171
|
-
| Export | Description |
|
|
172
|
-
| --- | --- |
|
|
173
|
-
| `init(options)` | Loads everything and generates the layout |
|
|
174
|
-
| `config` | The live configuration object |
|
|
175
|
-
| `generateBasicLayout()`, `generateHeader()`, `generateWrapper()`, `generateFooter()` | Layout generation |
|
|
176
|
-
| `clearHeader()`, `clearWrapper()`, `clearFooter()`, `clearHeaderMenu()`, `clearFooterMenu()` | Empty a block |
|
|
177
|
-
| `generateBasicMenu(options)` | Generate a menu into any parent |
|
|
178
|
-
| `generateLoginForm()`, `getLoginFormData()` | Login form into the wrapper, and its current values |
|
|
179
|
-
| `generateRegistrationForm(parent)`, `getRegistrationFormData()`, `validateRegistrationForm()` | Registration form (username, email, password, confirmation) into `parent` (default `wrapper`). Validated before the callback is called. |
|
|
180
|
-
| `generateLostPasswordForm(parent)`, `getLostPasswordFormData()` | Lost password form (email) |
|
|
181
|
-
| `generateChart(options)` | Draw a chart, see [Charts](#charts) |
|
|
182
|
-
| `generateTable(options)` | Draw a table, see [Tables](#tables) |
|
|
183
|
-
| `generateChangePasswordForm(parent)`, `getChangePasswordFormData()`, `validateChangePasswordForm()` | Change password form |
|
|
184
|
-
| `generateForm`, `generateField`, `generateButton` | Form builder, see [Forms](#forms) |
|
|
185
|
-
| `showToast`, `generateAlert`, `generateSpinner`, `generateProgress` | See [Feedback](#feedback) |
|
|
186
|
-
| `showDialog`, `alertDialog`, `confirmDialog`, `promptDialog` | See [Dialogs](#dialogs) |
|
|
187
|
-
| `generateTabs`, `generateBreadcrumbs`, `generatePagination`, `generateAccordion`, `generateDropdown`, `generateSidebar` | See [Navigation](#navigation) |
|
|
188
|
-
| `createRouter(options)` | See [Router](#router) |
|
|
189
|
-
| `generateMenu(options)`, `generateHeaderMenu({ items })` | See [Menu component](#menu-component) |
|
|
190
|
-
| `generateSignInForm`, `generateSignUpForm`, `generatePasswordResetForm`, `generatePasswordChangeForm`, `createAuthState` | See [Signing in](#signing-in-recommended) |
|
|
191
|
-
| `showFormDialog`, `showConfirm` | See [Dialogs](#dialogs) |
|
|
192
|
-
| `createThemeManager`, `generateThemePicker` | See [Themes and modes](#themes-and-modes-light--dark--like-the-system) |
|
|
193
|
-
| `generateDateTimeRange`, `toLocalInput`, `fromLocalInput` | See [Date and time range](#date-and-time-range) |
|
|
194
|
-
| `generatePageHeader`, `generateFacts`, `generateEmptyState`, `generateLoading`, `copyToClipboard` | See [Page parts and formatting](#page-parts-and-formatting) |
|
|
195
|
-
| `formatBytes`, `formatNumber`, `formatDuration`, `formatRelativeTime`, `formatDate` | Format helpers on top of `Intl`, in the current language |
|
|
196
|
-
| `el`, `setContent`, `resolveElement`, `asHandle`, `createSafeBuilder` | See [Safe DOM building](#safe-dom-building) |
|
|
197
|
-
| `animate`, `flip`, `stagger`, `spring`, `tween`, `transition`, `viewTransition`, `setMotion`, `prefersReducedMotion`, `easings`, `generateSkeleton` | See [Motion](#motion-animations-and-transitions) |
|
|
198
|
-
| `registerWidget`, `createWidgetGrid`, `getWidgetTypes`, `placeItem`, `compact`, `findFreeSpot`, `normalize` | See [Widgets](#widgets-a-dashboard-that-can-be-built) |
|
|
199
|
-
| `highlightCode`, `generateCodeBlock`, `createCodeEditor`, `createDiffView`, `registerLanguage`, `tokenize`, `diffLines` | See [Code](#code-highlighting-an-editor-and-a-diff) |
|
|
200
|
-
| `generateCard`, `generateSection`, `generateGrid`, `generateBadge`, `generateAvatar`, `generateStat`, `generateLink`, `generateTooltip` | See [Components](#components) |
|
|
201
|
-
| `generateAutocomplete`, `generateMultiSelect`, `generateFileUpload`, `generateDropZone`, `generateStepper`, `generateDateRange`, `generateRichText`, `generateWysiwyg` | See [Inputs](#inputs) |
|
|
202
|
-
| `sanitizeHtml(html)`, `htmlToText(html)`, `isSafeUrl(url)` | The allow-list sanitizer behind the rich text editor |
|
|
203
|
-
| `setSession`, `getSession`, `isLoggedIn`, `logout`, `onSessionChange` | See [Session](#session) |
|
|
204
|
-
| `translate`, `setLocale`, `getLocale`, `addMessages` | See [Translations](#translations) |
|
|
205
|
-
| `validateValue`, `validateAll` | The validator behind the form builder |
|
|
206
|
-
| `toCsv(columns, rows)`, `downloadFile(name, text)` | CSV helpers |
|
|
207
|
-
| `setTheme({ id })` | Switch the theme at runtime |
|
|
208
|
-
| `openModal(id)`, `closeModal(id)` | Show / hide a `.modal` element (default id: `myModal`). Elements with the `close` class close their modal. |
|
|
209
|
-
| `loadScript(src)` | Load a classic script once, returns a Promise |
|
|
210
|
-
| `Cookies` | `get(name)`, `set(name, value, { expires, path, domain, sameSite, secure })`, `remove(name)`: a small cookie helper (`expires` is days or a Date) |
|
|
211
|
-
| `createApp(options)` | `init` into any element, see [Inside a page](#inside-a-page-createapp) |
|
|
212
|
-
| `HTMLElementGenerator(options)` | Generates a div, span, p, heading or img and appends it to the element with the id `parent` |
|
|
213
|
-
| `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` |
|
|
214
|
-
|
|
215
|
-
HTMLElementGenerator and HTMLControlGenerator used to be projects of their own. They are part of Athena UI now (the calls and options are the
|
|
216
|
-
same, and HTMLControlGenerator has no jQuery in it); the old repositories are no longer developed.
|
|
217
|
-
|
|
218
|
-
### Charts
|
|
219
|
-
|
|
220
|
-
```js
|
|
221
|
-
const chart = generateChart({
|
|
222
|
-
type: "line", // "bar" | "line" | "area" | "sparkline" | "pie" | "donut"
|
|
223
|
-
parent: "wrapper", // element, id or selector (default "wrapper")
|
|
224
|
-
title: "Revenue",
|
|
225
|
-
labels: ["Q1", "Q2", "Q3"],
|
|
226
|
-
series: [
|
|
227
|
-
{ name: "2025", data: [12, 19, 8] },
|
|
228
|
-
{ name: "2026", data: [14, 17, 12], color: "#e15759" }
|
|
229
|
-
],
|
|
230
|
-
table: true // adds "Show as table" with the values
|
|
231
|
-
});
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
Charts are inline SVG, nothing is styled inline (a strict Content-Security-Policy works), negative values are supported. `pie` and `donut` use the
|
|
235
|
-
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.
|
|
236
|
-
Other options: `id`, `width` (600), `height` (360), `legend`, `zero: false` (a line chart's value axis may start near the smallest value).
|
|
237
|
-
|
|
238
|
-
- **Colours** come from the theme: `--series-1` ... `--series-8` (see `appearance.css`), so every chart follows light / dark. `color` overrides one series.
|
|
239
|
-
- **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.
|
|
240
|
-
- **Legend**: click (or Enter / Space) on an entry hides and shows that series.
|
|
241
|
-
- **Time axis**: `times: [Date | ms | "2026-11-19T10:00"]` (line and area). Ticks fall on round times, points sit at their real distance.
|
|
242
|
-
- **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,
|
|
243
|
-
0 resets. `chart.zoom(from, to)`, `chart.resetZoom()`, `chart.getZoom()`, `onZoom(range)` and `zoomRange` (ms with `times`, otherwise the point index).
|
|
244
|
-
- **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.
|
|
245
|
-
- **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.
|
|
246
|
-
- `chart.update({ series })` redraws with changes, `chart.destroy()` removes the chart and its table. `generateChart` returns the `<svg>` element that carries these
|
|
247
|
-
methods, or `null` when the options are invalid.
|
|
248
|
-
|
|
249
|
-
### Tables
|
|
250
|
-
|
|
251
|
-
```js
|
|
252
|
-
const { setRows } = generateTable({
|
|
253
|
-
parent: "wrapper",
|
|
254
|
-
caption: "Users",
|
|
255
|
-
columns: [{ key: "name", label: "Name" }, { key: "age", label: "Age", format: v => `${v} y` }],
|
|
256
|
-
rows: [{ name: "Anna", age: 31 }, { name: "Béla", age: 27 }],
|
|
257
|
-
filter: true, // text filter box
|
|
258
|
-
pageSize: 10, // 0 = no pagination
|
|
259
|
-
onRowClick: row => console.log(row)
|
|
260
|
-
});
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
Click a header to sort (disable with `sortable: false`, or per column). Other options: `id`, `class`,
|
|
264
|
-
`emptyText`. Returns `{ element, setRows(rows), getSelected(), clearSelection(), toCsv(), exportCsv(filename) }`.
|
|
265
|
-
|
|
266
|
-
- `selectable: true` adds a checkbox column (the header checkbox selects every filtered row), `onSelectionChange(rows)` reports changes.
|
|
267
|
-
- A column with `editable: true` can be edited with a double click, or Enter / F2 on the focused cell. `onEdit(row, key, value, oldValue)` is called after the edit; return `false` to reject it. Numeric cells stay numbers.
|
|
268
|
-
- `resizableColumns: true` puts a drag handle on every header edge. The handle is focusable too: Left / Right resize by 10 px, Shift by 50 px, double click resets the column to its configured `width`. Columns take `width`, `minWidth` and `maxWidth`; `onColumnResize(key, width)` and `getColumnWidths()` let you persist the layout.
|
|
269
|
-
- `virtual: { height: 400, rowHeight: 36, overscan: 5 }` (or `virtual: true`) renders only the rows in view and keeps the scroll bar the size of the whole list, so 10 000+ rows stay fast. Rows have a fixed height (the theme enforces it, one line per cell), the table scrolls inside `height` and its header stays visible. It replaces pagination; filtering, sorting, selection, editing and CSV export work as usual.
|
|
270
|
-
- 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.
|
|
271
|
-
- 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).
|
|
272
|
-
- 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.
|
|
273
|
-
- **Rows from a server**: `dataSource: async ({ page, pageSize, cursor, sort, filter }) => ({ rows, total })`. Sorting, the (debounced) filter box and the pager ask it again,
|
|
274
|
-
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
|
|
275
|
-
(`page` is 0-based), or with `nextCursor` for a "Load more" button (`cursor` is what the last answer gave). `table.reload()` asks again.
|
|
276
|
-
- **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
|
|
277
|
-
`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.
|
|
278
|
-
The select-all checkbox only selects the rows that have arrived.
|
|
279
|
-
- `rowActions: [{ label: "Delete", danger: true, onclick: row => remove(row), hidden: row => row.locked, ariaLabel: row => "Delete " + row.name }]` adds a column of buttons.
|
|
280
|
-
- `exportCsv()` downloads the filtered and sorted rows. Cells that start with `=`, `+`, `-` or `@` are prefixed with `'` so a spreadsheet does not run them as formulas.
|
|
281
|
-
|
|
282
|
-
### Forms
|
|
283
|
-
|
|
284
|
-
```js
|
|
285
|
-
const form = generateForm({
|
|
286
|
-
parent: "wrapper",
|
|
287
|
-
submitText: "Save",
|
|
288
|
-
fields: [
|
|
289
|
-
{ name: "name", label: "Name", required: true, minLength: 2, help: "At least 2 characters" },
|
|
290
|
-
{ name: "email", label: "Email", type: "email", required: true },
|
|
291
|
-
{ name: "password", label: "Password", type: "password", required: true },
|
|
292
|
-
{ name: "password2", label: "Repeat", type: "password", match: "password" },
|
|
293
|
-
{ name: "country", label: "Country", type: "select", placeholder: "Choose...", options: ["Hungary", "Italy"] },
|
|
294
|
-
{ name: "plan", type: "radio", label: "Plan", options: ["Free", "Pro"], value: "Free" },
|
|
295
|
-
{ name: "news", type: "switch", label: "Newsletter" }
|
|
296
|
-
],
|
|
297
|
-
onSubmit: async values => { await save(values); } // called when every field is valid
|
|
298
|
-
});
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
Field types: `text`, `password`, `email`, `number`, `date`, `datetime-local`, `time`, `month`, `week`, `url`, `tel`,
|
|
302
|
-
`search`, `color`, `range`, `file`, `hidden`, `textarea`, `select` (`multiple`), `checkbox`, `switch`, `radio`,
|
|
303
|
-
`checkboxes`, `autocomplete`, `multiselect`, `daterange` (value `{ from, to }`), `richtext` and `wysiwyg` (value: safe HTML).
|
|
304
|
-
The date, time and color types use the native pickers of the browser.
|
|
305
|
-
|
|
306
|
-
Rules (`required`, `email`, `minLength`, `maxLength`, `pattern`, `min`, `max`, `match`, `validate(value, values)`) can be
|
|
307
|
-
given on the field or in `rules`. A field is validated when it loses focus, then on every change. A rejected
|
|
308
|
-
`onSubmit` promise is shown as form message and the submit button shows a spinner while it runs.
|
|
309
|
-
|
|
310
|
-
The returned form has `getValues()`, `setValues()`, `setErrors({ name: "Taken" })` (server side errors),
|
|
311
|
-
`validate()`, `reset()`, `setMessage(text)`, `fields` and `submitButton`. `generateField(options)` builds a single field.
|
|
312
|
-
|
|
313
|
-
`generateButton({ text, variant, loading, disabled, onclick })` has the variants `primary`, `secondary`, `danger` and
|
|
314
|
-
`link`, and returns `{ element, setLoading, setDisabled, setText }`.
|
|
315
|
-
|
|
316
|
-
### Feedback
|
|
317
|
-
|
|
318
|
-
```js
|
|
319
|
-
showToast({ title: "Saved", message: "All good", type: "success", duration: 4000 }); // info | success | warning | error
|
|
320
|
-
generateAlert({ parent: "wrapper", type: "error", message: "Failed", dismissible: true });
|
|
321
|
-
generateSpinner({ parent: "wrapper", size: "large" });
|
|
322
|
-
const progress = generateProgress({ parent: "wrapper", label: "Upload", value: 20 }); // no value: indeterminate
|
|
323
|
-
progress.setValue(60);
|
|
324
|
-
```
|
|
325
|
-
|
|
326
|
-
### Dialogs
|
|
327
|
-
|
|
328
|
-
```js
|
|
329
|
-
await alertDialog("Saved");
|
|
330
|
-
if (await confirmDialog("Delete the item?", { title: "Delete", confirmText: "Delete", danger: true })) { /* ... */ }
|
|
331
|
-
const name = await promptDialog("Your name", { validate: v => v ? "" : "Required" }); // null when cancelled
|
|
332
|
-
const choice = await showDialog({ title: "Custom", content: "Pick one", buttons: [{ text: "A", value: "a" }, { text: "B", value: "b" }] });
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
Options: `size` ("small" 360 px, "medium" 480 px, "large" 720 px, "full") and `class` (extra class on the dialog).
|
|
336
|
-
`showDialog` returns a promise that also carries the open dialog: `const dialog = showDialog({ size: "large", ... }); dialog.element; dialog.close(value);`.
|
|
337
|
-
The dialog is shown by a CSS class, not by an inline style, so a strict Content-Security-Policy works.
|
|
338
|
-
|
|
339
|
-
**Form dialog** and **confirmation**:
|
|
340
|
-
|
|
341
|
-
```js
|
|
342
|
-
const saved = await showFormDialog({
|
|
343
|
-
title: "Add host", intro: "The agent connects with this name.", size: "small", submitText: "Add",
|
|
344
|
-
fields: [{ name: "name", label: "Name", required: true }],
|
|
345
|
-
onSubmit: async (values, form) => {
|
|
346
|
-
const answer = await api.addHost(values); // when this throws, the message shows in the dialog and it stays open
|
|
347
|
-
if (answer.errors) throw Object.assign(new Error("Check the fields"), { fields: answer.errors }); // or form.setErrors({ name: "Already taken" })
|
|
348
|
-
}
|
|
349
|
-
}); // true when saved, false when dismissed
|
|
350
|
-
|
|
351
|
-
if (await showConfirm({ title: "Delete host", message: "This cannot be undone.", confirmText: "Delete", danger: true, typeToConfirm: host.name })) { /* ... */ }
|
|
352
|
-
```
|
|
353
|
-
|
|
354
|
-
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
|
|
355
|
-
(`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`
|
|
356
|
-
(it adds `showModal()`), and close a dialog with the `cancel` event, as the browser does for Esc.
|
|
357
|
-
|
|
358
|
-
Dialogs trap the focus, close with Esc (resolving `null` / `false`) and restore the focus. Text content is
|
|
359
|
-
never parsed as HTML. `openModal` / `closeModal` got the same focus handling.
|
|
360
|
-
|
|
361
|
-
### Navigation
|
|
362
|
-
|
|
363
|
-
The **dropdown** menu and the **tooltip** are native popovers: they are drawn in the top layer, so no parent with `overflow: hidden` can cut them off and no `z-index` fight is possible;
|
|
364
|
-
a click outside and Esc close the dropdown, and the focus goes back to its button. They are placed next to their button by a small helper (it sets two CSS variables, which a strict
|
|
365
|
-
Content-Security-Policy allows): below, or above when there is no room below, and always kept inside the window. A tooltip shows on hover and on focus and goes on Esc; a touch does not show it.
|
|
366
|
-
Without the popover API the dropdown is a plain menu that is shown and hidden with `hidden`, and the tooltip a CSS one.
|
|
367
|
-
|
|
368
|
-
```js
|
|
369
|
-
generateTabs({ parent: "wrapper", tabs: [{ id: "a", label: "A", content: "First" }, { id: "b", label: "B", content: () => lazyNode() }] });
|
|
370
|
-
generateAccordion({ parent: "wrapper", items: [{ title: "Q", content: "A", open: true }], multiple: false });
|
|
371
|
-
generateDropdown({ parent: "wrapper", label: "Actions", items: [{ label: "Edit", onclick }, { divider: true }, { label: "Delete", onclick }] });
|
|
372
|
-
generateDropdown({ parent: "wrapper", icon: "⋮", ariaLabel: "More actions", items: [{ label: "Edit", onclick }] }); // icon only; also caret: true, toggleClass
|
|
373
|
-
generatePagination({ parent: "wrapper", total: 200, pageSize: 10, onChange: page => load(page) });
|
|
374
|
-
generateBreadcrumbs({ parent: "wrapper", items: [{ label: "Home", href: "#/" }, { label: "Users" }] });
|
|
375
|
-
generateSidebar({ parent: "wrapper", active: "home", onSelect: item => go(item.id),
|
|
376
|
-
items: [{ id: "home", label: "Home" }, { id: "reports", label: "Reports", children: [{ id: "daily", label: "Daily" }] }] });
|
|
377
|
-
```
|
|
378
|
-
|
|
379
|
-
Tabs, dropdown and the combobox inputs follow the WAI-ARIA keyboard patterns (arrow keys, Home / End, Esc).
|
|
380
|
-
The sidebar collapses behind a toggle button on small screens.
|
|
381
|
-
|
|
382
|
-
### Menus with submenus
|
|
383
|
-
|
|
384
|
-
```js
|
|
385
|
-
init({
|
|
386
|
-
menuItems: {
|
|
387
|
-
headerMenu: [
|
|
388
|
-
{ id: "menu-home", class: "menu-item", text: "", inner_text: "Home" },
|
|
389
|
-
{ id: "menu-more", class: "menu-item", text: "", inner_text: "More", children: [{ inner_text: "Reports" }, { inner_text: "Archive", disabled: true }] }
|
|
390
|
-
],
|
|
391
|
-
footerMenu: []
|
|
392
|
-
},
|
|
393
|
-
nav: name => router.navigate(`/${name.toLowerCase()}`) // called with the entry's inner_text
|
|
394
|
-
});
|
|
395
|
-
```
|
|
396
|
-
|
|
397
|
-
A submenu opens with a click, Enter, Space or the Down arrow, closes with Esc, a click outside or by choosing an entry,
|
|
398
|
-
and supports the arrow keys, Home and End. The same works in the footer menu.
|
|
399
|
-
|
|
400
|
-
### Menu component
|
|
401
|
-
|
|
402
|
-
`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.
|
|
403
|
-
|
|
404
|
-
```js
|
|
405
|
-
const menu = generateMenu({
|
|
406
|
-
parent: "header", // an element, an id or a selector
|
|
407
|
-
layout: "responsive", // "bar" | "bottom-tabs" | "responsive" (tabs at the bottom under 700px, groups open as sheets)
|
|
408
|
-
followHash: true, // the item whose href equals location.hash is the active one
|
|
409
|
-
onNavigate: (item, event) => console.log(item.id), // only when a person uses an item, never from select() or while building
|
|
410
|
-
items: [
|
|
411
|
-
{ id: "home", label: "Home", icon: "⌂", href: "#/" },
|
|
412
|
-
{ id: "inbox", label: "Inbox", href: "#/inbox", badge: 3, badgeLabel: "3 unread" },
|
|
413
|
-
{ id: "tools", label: "Tools", children: [
|
|
414
|
-
{ id: "export", label: "Export" },
|
|
415
|
-
{ id: "more", label: "More", children: [{ id: "csv", label: "CSV" }, { id: "json", label: "JSON" }] }
|
|
416
|
-
] },
|
|
417
|
-
{ id: "user", label: "Anna Kiss", avatar: { name: "Anna Kiss" }, align: "end", children: [{ id: "out", label: "Sign out" }] }
|
|
418
|
-
]
|
|
419
|
-
});
|
|
420
|
-
menu.select("inbox"); // marks the current page (class is-active, aria-current="page", has-active on the groups around it)
|
|
421
|
-
menu.setBadge("inbox", { text: 12, tone: "bad" }); // a count, text, or { text, tone: "info" | "ok" | "warn" | "bad" }; 0 / null removes it
|
|
422
|
-
```
|
|
423
|
-
|
|
424
|
-
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
|
|
425
|
-
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.
|
|
426
|
-
|
|
427
|
-
### Router
|
|
428
|
-
|
|
429
|
-
```js
|
|
430
|
-
const router = createRouter({
|
|
431
|
-
routes: {
|
|
432
|
-
"/": () => renderHome(),
|
|
433
|
-
"/users/:id": ({ params, query }) => renderUser(params.id),
|
|
434
|
-
"/admin": { handler: renderAdmin, title: "Admin" }
|
|
435
|
-
},
|
|
436
|
-
outlet: "wrapper", // emptied before every page
|
|
437
|
-
beforeEach: ({ path }) => path === "/admin" && !isLoggedIn() ? "/login" : undefined, // false cancels, a path redirects
|
|
438
|
-
notFound: () => renderNotFound()
|
|
439
|
-
});
|
|
440
|
-
router.start();
|
|
441
|
-
router.navigate("/users/5?tab=info");
|
|
442
|
-
```
|
|
443
|
-
|
|
444
|
-
Routes can carry the sign-in rules, so a page does not check them itself:
|
|
445
|
-
|
|
446
|
-
```js
|
|
447
|
-
const router = createRouter({
|
|
448
|
-
auth: auth.routerRules({ loginPath: "/login", homePath: "/", forbiddenPath: "/denied" }), // { isSignedIn, hasRole, ... }
|
|
449
|
-
focusContent: true, scrollTop: true, // after a page is shown: focus the outlet, scroll to the top
|
|
450
|
-
onShown: ctx => menu.select(ctx.path), // also onRender (before the page function) and router.onChange(listener)
|
|
451
|
-
routes: {
|
|
452
|
-
"/login": { handler: renderLogin, guestOnly: true }, // a signed-in person goes home
|
|
453
|
-
"/account": { handler: renderAccount, auth: true }, // not signed in: /login?next=%2Faccount
|
|
454
|
-
"/admin": { handler: renderAdmin, auth: true, roles: ["admin"] },
|
|
455
|
-
"/report": { handler: renderReport, guard: ctx => ctx.query.id ? undefined : "/reports" } // false stays, a path redirects
|
|
456
|
-
}
|
|
457
|
-
});
|
|
458
|
-
```
|
|
459
|
-
|
|
460
|
-
`mode: "history"` uses real paths instead of the hash, the server then has to answer every path with the page.
|
|
461
|
-
Pass `router.navigate` from your `nav` callback to route the menu clicks.
|
|
462
|
-
|
|
463
|
-
### Components
|
|
464
|
-
|
|
465
|
-
```js
|
|
466
|
-
const grid = generateGrid({ parent: "wrapper", columns: 3 }); // one column on small screens
|
|
467
|
-
generateStat({ parent: grid, label: "Revenue", value: "$12k", delta: 8.2 });
|
|
468
|
-
generateCard({ parent: grid, title: "Title", content: "Text or a Node", footer: "Footer", image: "a.jpg" });
|
|
469
|
-
generateBadge({ parent: "wrapper", text: "new", variant: "success", pill: true });
|
|
470
|
-
generateAvatar({ parent: "wrapper", name: "Ada Lovelace", src: "ada.png" }); // initials without a working image
|
|
471
|
-
generateTooltip(buttonElement, "Saves the form");
|
|
472
|
-
generateLink({ parent: "wrapper", text: "Docs", href: "https://example.com", external: true });
|
|
473
|
-
generateSection({ parent: "wrapper", title: "Section", level: 2, content: "..." });
|
|
474
|
-
```
|
|
475
|
-
|
|
476
|
-
`parent` is the id of an element or the element itself. String content is always inserted as text.
|
|
477
|
-
|
|
478
|
-
### Inputs
|
|
479
|
-
|
|
480
|
-
```js
|
|
481
|
-
generateAutocomplete({ parent: "wrapper", label: "Country", options: ["Hungary", "Italy"] });
|
|
482
|
-
generateAutocomplete({ parent: "wrapper", options: async query => fetchSuggestions(query), minChars: 2 }); // remote data
|
|
483
|
-
generateMultiSelect({ parent: "wrapper", options: [{ value: "h", text: "Hungary" }], value: ["h"] }); // getValue(): array
|
|
484
|
-
generateFileUpload({ parent: "wrapper", accept: ".png,.pdf", maxSize: 2 * 1024 * 1024, url: "/upload",
|
|
485
|
-
onProgress: (file, percent) => {}, onComplete: (file, response) => {}, onError: (file, error) => {} });
|
|
486
|
-
generateStepper({ parent: "wrapper", onFinish: () => {}, steps: [
|
|
487
|
-
{ title: "Account", content: () => buildStep1(), validate: () => valid || "Fix the errors" },
|
|
488
|
-
{ title: "Done", content: "Finished" }
|
|
489
|
-
] });
|
|
490
|
-
```
|
|
491
|
-
|
|
492
|
-
```js
|
|
493
|
-
generateDateRange({ parent: "wrapper", label: "Stay", from: "2026-06-01", min: "2026-01-01", onChange: ({ from, to }) => {} });
|
|
494
|
-
const editor = generateRichText({ parent: "wrapper", label: "Description", placeholder: "Write...", value: "<p>Hello</p>",
|
|
495
|
-
toolbar: ["bold", "italic", "|", "ul", "ol", "link"], onChange: html => {} });
|
|
496
|
-
editor.getValue(); // safe HTML, "" when empty
|
|
497
|
-
```
|
|
498
|
-
|
|
499
|
-
The date range uses the native date pickers; the end picker starts at the chosen start date and a reversed range typed by
|
|
500
|
-
hand is reported. The rich text editor produces a restricted set of HTML (paragraphs, headings, bold / italic / underline /
|
|
501
|
-
strike, lists, quotes, code, links). Everything else (scripts, styles, iframes, images, event attributes, `javascript:` and
|
|
502
|
-
`data:` links) is removed when the content is set, pasted, dropped and read, so the value is safe to store and show with
|
|
503
|
-
`innerHTML`; links get `rel="noopener noreferrer"`. Toolbar buttons: `bold`, `italic`, `underline`, `strike`, `h2`, `h3`,
|
|
504
|
-
`quote`, `ul`, `ol`, `link`, `unlink`, `clear`, `undo`, `redo`. The editor is built on `contenteditable` and
|
|
505
|
-
`document.execCommand`, which every browser still supports; sanitize on the server as well, as with any HTML you accept.
|
|
506
|
-
|
|
507
|
-
```js
|
|
508
|
-
generateDropZone({ parent: "wrapper", accept: "image/*", maxSize: 2 * 1024 * 1024, maxFiles: 3,
|
|
509
|
-
onDrop: files => {}, onReject: rejected => rejected.forEach(({ file, reason }) => {}) });
|
|
510
|
-
const wysiwyg = generateWysiwyg({ parent: "wrapper", label: "Body", value: "<p>Hello</p>" }); // rich text + HTML source view
|
|
511
|
-
```
|
|
512
|
-
|
|
513
|
-
`generateDropZone` is a bare drag-and-drop area (also reachable with Enter / Space and the file dialog). Dropped files are
|
|
514
|
-
checked against `accept`, `maxSize` and `maxFiles`; valid ones go to `onDrop`, the others to `onReject` with a reason. It
|
|
515
|
-
reads and sends nothing, and `setDisabled(true)` turns it off. `generateWysiwyg` is the rich text editor plus a `source`
|
|
516
|
-
toolbar button that shows the sanitized HTML; what is typed there is sanitized again when you switch back.
|
|
517
|
-
|
|
518
|
-
Files are sent as a multipart POST (`fieldName`, `headers` are configurable). Without `url` the files are only collected,
|
|
519
|
-
read them with `getFiles()`.
|
|
520
|
-
|
|
521
|
-
### Session
|
|
522
|
-
|
|
523
|
-
```js
|
|
524
|
-
login: async ({ username, password, remember }) => {
|
|
525
|
-
const user = await api.login(username, password);
|
|
526
|
-
setSession({ user, token: user.token, remember }); // a session cookie, or `session_days` days when remembered
|
|
527
|
-
router.navigate("/");
|
|
528
|
-
}
|
|
529
|
-
isLoggedIn(); getSession(); logout();
|
|
530
|
-
onSessionChange(session => updateMenu(session));
|
|
531
|
-
```
|
|
532
|
-
|
|
533
|
-
The session lives in a cookie written from script, so any script of the page can read it. Keep only what the UI needs in it
|
|
534
|
-
and let the server enforce authorization; a server set `HttpOnly` cookie is the safer place for real credentials.
|
|
535
|
-
|
|
536
|
-
### Translations
|
|
537
|
-
|
|
538
|
-
```js
|
|
539
|
-
init({ config: { locale: "hu" } }); // English and Hungarian are included
|
|
540
|
-
setLocale("en"); // switch at runtime, texts of new components follow
|
|
541
|
-
addMessages("de", { login: "Anmelden", "validation.required": "Pflichtfeld" });
|
|
542
|
-
translate("login");
|
|
543
|
-
```
|
|
544
|
-
|
|
545
|
-
Missing texts fall back to English. See `src/libs/core/i18n.js` for all keys.
|
|
546
|
-
|
|
547
|
-
### Usage from classic scripts
|
|
548
|
-
|
|
549
|
-
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`
|
|
550
|
-
(and as `AthenaUI`):
|
|
551
|
-
|
|
552
|
-
```html
|
|
553
|
-
<script type="module" src="node_modules/athena-ui-js/src/classic.js"></script>
|
|
554
|
-
<script type="module">
|
|
555
|
-
init({ theme: { id: 0 } }); // globals: init, generateTable, AthenaUI, HTMLControlGenerator, ...
|
|
556
|
-
</script>
|
|
557
|
-
```
|
|
558
|
-
|
|
559
|
-
The global `appConfig`, `menuItems`, `nav`, `login`, `register` and `lostPassword` are used when the matching `init` option is not given.
|
|
560
|
-
|
|
561
|
-
### Signing in (recommended)
|
|
562
|
-
|
|
563
|
-
`generateSignInForm`, `generateSignUpForm`, `generatePasswordResetForm` and `generatePasswordChangeForm` are real `<form>` elements with the autocomplete tokens
|
|
564
|
-
that password managers look for (`username`, `current-password`, `new-password`, `email`), so Enter submits and the browser can save and fill passwords.
|
|
565
|
-
|
|
566
|
-
```js
|
|
567
|
-
const auth = createAuthState({ restore: () => fetch("/api/me", { credentials: "same-origin" }).then(r => (r.ok ? r.json() : null)) });
|
|
568
|
-
await auth.restore(); // after a reload: ask the server who is signed in
|
|
569
|
-
|
|
570
|
-
generateSignInForm({
|
|
571
|
-
parent: "wrapper", remember: true,
|
|
572
|
-
onSubmit: async ({ username, password, remember }) => {
|
|
573
|
-
const response = await fetch("/api/login", { method: "POST", body: JSON.stringify({ username, password, remember }), credentials: "same-origin" });
|
|
574
|
-
if (!response.ok) throw new Error("Wrong user name or password"); // shown in the form, which stays usable
|
|
575
|
-
auth.signIn(await response.json()); // { name, roles: [...] }
|
|
576
|
-
}
|
|
577
|
-
});
|
|
578
|
-
```
|
|
579
|
-
|
|
580
|
-
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.
|
|
581
|
-
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).
|
|
582
|
-
`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,
|
|
583
|
-
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.
|
|
584
|
-
|
|
585
|
-
## Themes
|
|
586
|
-
|
|
587
|
-
A theme is a single stylesheet. Register it in `src/res/themes/themes.js` and select it with
|
|
588
|
-
`theme: { id }`, or pass any stylesheet directly with `theme: { href: "css/my-theme.css" }`.
|
|
589
|
-
The default theme is in `src/res/themes/default/style.css`; `{ id: 1 }` is a dark theme. All colors are CSS variables
|
|
590
|
-
(`--athena-bg`, `--athena-fg`, `--athena-accent`, ...), so a custom theme can import the default one and override them:
|
|
591
|
-
|
|
592
|
-
```css
|
|
593
|
-
@import url("athena-ui/src/res/themes/default/style.css");
|
|
594
|
-
:root { --athena-accent: #8e44ad; }
|
|
595
|
-
```
|
|
596
|
-
|
|
597
|
-
Switch themes at runtime with `setTheme({ id: 1 })`.
|
|
598
|
-
|
|
599
|
-
### Styling: the cascade layer, tokens and dark mode
|
|
600
|
-
|
|
601
|
-
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
|
|
602
|
-
`.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
|
|
603
|
-
restyle everything at once:
|
|
604
|
-
|
|
605
|
-
```css
|
|
606
|
-
:root { --athena-accent: #8e44ad; --athena-radius: 2px; --athena-space-2: 6px; --athena-dialog-medium: 560px; }
|
|
607
|
-
```
|
|
608
|
-
|
|
609
|
-
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
|
|
610
|
-
`"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`).
|
|
611
|
-
|
|
612
|
-
### Themes and modes (light / dark / like the system)
|
|
613
|
-
|
|
614
|
-
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:
|
|
615
|
-
|
|
616
|
-
```html
|
|
617
|
-
<link rel="stylesheet" href="athena-ui/src/res/themes/default/style.css">
|
|
618
|
-
<link rel="stylesheet" href="athena-ui/src/res/themes/appearance.css">
|
|
619
|
-
<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 -->
|
|
620
|
-
```
|
|
621
|
-
|
|
622
|
-
```js
|
|
623
|
-
const manager = createThemeManager({ themes: [{ id: "athena", name: "Athena" }, { id: "contrast", name: "High contrast" }], storageKey: "myapp.appearance",
|
|
624
|
-
themeColorVariable: "--athena-bg" }); // <meta name="theme-color"> follows this variable
|
|
625
|
-
manager.setTheme("contrast"); manager.setMode("dark"); // "system" | "light" | "dark"; saved in localStorage, other tabs follow
|
|
626
|
-
manager.onChange(({ theme, mode, dark }) => redrawChartsOrWhatever());
|
|
627
|
-
generateThemePicker({ parent: "account-page", manager }); // radio groups with a small preview of every theme
|
|
628
|
-
```
|
|
629
|
-
|
|
630
|
-
**The contract of a theme** (also at the top of `appearance.css`): a theme is a pair of CSS blocks that set the tokens
|
|
631
|
-
`--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`:
|
|
632
|
-
|
|
633
|
-
```css
|
|
634
|
-
[data-theme="ocean"][data-mode="light"] { --athena-bg: #f4f9fb; /* ... */ }
|
|
635
|
-
[data-theme="ocean"][data-mode="dark"] { --athena-bg: #0b1c24; /* ... */ }
|
|
636
|
-
```
|
|
637
|
-
|
|
638
|
-
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`.
|
|
639
|
-
Athena and High contrast (light and dark) are included; without the script the page follows the system.
|
|
640
|
-
|
|
641
|
-
### Date and time range
|
|
642
|
-
|
|
643
|
-
```js
|
|
644
|
-
const range = generateDateTimeRange({ parent: "wrapper", label: "Time", preset: "24h", onChange: ({ from, to, preset }) => reload() });
|
|
645
|
-
range.getRange(); // { from: Date, to: Date }. A preset ("15m", "1h", "24h", "7d", "30d") is measured from NOW when this is called
|
|
646
|
-
range.getValue(); // { from: "2026-11-19T08:00", to: "...", preset: "24h" }, the values of the inputs
|
|
647
|
-
```
|
|
648
|
-
|
|
649
|
-
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.
|
|
650
|
-
`toLocalInput(date)` and `fromLocalInput(value)` convert between a Date and the value of such an input.
|
|
651
|
-
|
|
652
|
-
### Page parts and formatting
|
|
653
|
-
|
|
654
|
-
```js
|
|
655
|
-
generatePageHeader({ parent: "wrapper", title: "Hosts", description: "All monitored machines", breadcrumbs: [{ label: "Home", href: "#/" }, { label: "Hosts" }], actions: [addButton] });
|
|
656
|
-
generateFacts({ parent: "wrapper", items: [{ term: "System", description: "Linux" }, { term: "Seen", description: formatRelativeTime(host.lastSeen) }] });
|
|
657
|
-
generateEmptyState({ parent: "wrapper", title: "No hosts yet", message: "Install the agent.", action: { text: "Add host", onclick: add } });
|
|
658
|
-
generateLoading({ parent: "wrapper" }); // spinner + text, a live region
|
|
659
|
-
generateStat({ parent: "wrapper", label: "CPU", value: "91 %", tone: "bad", note: "of 4 cores" }); // tone: "ok" | "warn" | "bad" (colour + a word for screen readers)
|
|
660
|
-
await copyToClipboard(token); // and says "Copied" in a toast
|
|
661
|
-
formatBytes(1536); formatNumber(1234567.891); formatDuration(7500000); formatRelativeTime(date); formatDate(date, { time: true }); // Intl, in the current language
|
|
662
|
-
```
|
|
663
|
-
|
|
664
|
-
### Motion: animations and transitions
|
|
665
|
-
|
|
666
|
-
Motion is an enhancement. Every transition and animation of Athena UI reads the tokens `--athena-duration-fast` (120 ms), `--athena-duration-base` (200 ms) and `--athena-duration-slow` (360 ms),
|
|
667
|
-
and `--athena-ease-standard`, `-in`, `-out` and `-spring`, so one variable slows down or switches off all of it. They are **0 under reduced motion**: when the system asks for it
|
|
668
|
-
(`prefers-reduced-motion`), or the person does (`data-motion="reduce"` on `<html>`, which `setMotion("reduce")` sets; `"full"` keeps the motion although the system asks for less).
|
|
669
|
-
Nothing waits for a transition before it works, and nothing needs an inline style (a strict Content-Security-Policy is fine: CSS classes, custom properties and the Web Animations API).
|
|
670
|
-
|
|
671
|
-
What the components do by themselves:
|
|
672
|
-
- a **dialog** fades and rises in and fades out; the **dropdown menu** and the **tooltip** fade; a **toast** slides in and out; an **accordion** opens smoothly;
|
|
673
|
-
a **progress bar** moves smoothly; a **skeleton** (`generateSkeleton`) shimmers;
|
|
674
|
-
- a **chart** draws itself the first time (bars grow, the line is drawn, slices pop in; `animate: false` turns it off, and it never replays while streaming or zooming);
|
|
675
|
-
- the **theme manager** cross-fades colours when the theme or the mode changes (`createThemeManager({ transition: false })` turns it off);
|
|
676
|
-
- a **table** with `animateRows: true` slides its rows to their new place when sorted, filtered or paged (at most 60 rows, not in a virtual table);
|
|
677
|
-
- the **router** with `transition: true` makes a page change a view transition (`document.startViewTransition`): the old page cross-fades into the new one, and elements with a
|
|
678
|
-
`view-transition-name` move from one page to the next. The old page stays until the page function of the new one has finished, so a page that needs long should draw something first.
|
|
679
|
-
|
|
680
|
-
`athena-ui-js/motion` has the same tools for your own code; all of them resolve at once under reduced motion:
|
|
681
|
-
|
|
682
|
-
```js
|
|
683
|
-
import { animate, flip, stagger, spring, tween, easings, transition, viewTransition, setMotion, prefersReducedMotion } from "athena-ui-js/motion";
|
|
684
|
-
|
|
685
|
-
await animate(card, [{ opacity: 0, translate: "0 16px" }, { opacity: 1, translate: "0 0" }]); // the Web Animations API, with the tokens as defaults; resolves at the end
|
|
686
|
-
await flip(list, () => list.append(...sorted)); // rows slide from where they were to where they are; new ones fade in
|
|
687
|
-
await stagger(items, (item, index, delay) => animate(item, frames, { delay }), { step: 40 }); // one after the other
|
|
688
|
-
const { easing, duration } = spring({ stiffness: 220, damping: 12 }); // a spring as a CSS easing (linear()), it overshoots
|
|
689
|
-
await animate(ball, [{ translate: "0 0" }, { translate: "240px 0" }], { easing, duration });
|
|
690
|
-
tween({ from: 0, to: 100, duration: 600, easing: easings.easeOutCubic, onUpdate: value => counter.textContent = Math.round(value) }); // numbers over time (games, counters)
|
|
691
|
-
await transition(panel, () => panel.classList.add("open")); // a change made with CSS: resolves when its transition is over
|
|
692
|
-
await viewTransition(() => swapContent()); // cross-fades the change where the browser can
|
|
693
|
-
setMotion("reduce"); // "system" | "reduce" | "full"
|
|
694
|
-
```
|
|
695
|
-
|
|
696
|
-
In a page that is not drawn (a hidden tab) there are no frames: `animate` and `tween` finish by a timer, so nothing hangs. Dialogs and toasts stay in the page for the length of their
|
|
697
|
-
exit transition (none under reduced motion); in your tests call `setMotion("reduce")` first, so they are gone at once.
|
|
698
|
-
|
|
699
|
-
### Widgets: a dashboard that can be built
|
|
700
|
-
|
|
701
|
-
`athena-ui-js/widgets`: a grid of widgets that can be added, configured, moved, resized, locked, saved and loaded. No dependency, no drag library, no inline style.
|
|
702
|
-
|
|
703
|
-
```js
|
|
704
|
-
import { registerWidget, createWidgetGrid } from "athena-ui-js/widgets";
|
|
705
|
-
|
|
706
|
-
// a type of widget: a function that draws into the body it is given, and cleans up after itself
|
|
707
|
-
registerWidget("clock", {
|
|
708
|
-
title: "Clock", defaultSize: { w: 3, h: 2 }, minSize: { w: 2, h: 1 }, defaultConfig: { seconds: true },
|
|
709
|
-
configForm: [{ name: "seconds", label: "Show seconds", type: "checkbox" }], // the settings dialog (showFormDialog)
|
|
710
|
-
render(context) { // called when the widget is first seen (IntersectionObserver)
|
|
711
|
-
const time = el("p");
|
|
712
|
-
context.element.append(time);
|
|
713
|
-
const show = () => time.textContent = new Date().toLocaleTimeString();
|
|
714
|
-
const timer = setInterval(show, 1000);
|
|
715
|
-
return { update: show, destroy: () => clearInterval(timer) }; // update(): config or title changed (throttled), destroy(): removed
|
|
716
|
-
}
|
|
717
|
-
});
|
|
718
|
-
|
|
719
|
-
const grid = createWidgetGrid({
|
|
720
|
-
element: "dashboard", columns: 12, rowHeight: 80, gap: 12, editable: true,
|
|
721
|
-
breakpoints: { wide: { minWidth: 900, columns: 12 }, narrow: { minWidth: 0, columns: 6 } }, // optional: a layout per width
|
|
722
|
-
widgets: [{ type: "clock", x: 0, y: 0 }],
|
|
723
|
-
onChange: (layout, reason) => localStorage.setItem("dashboard", JSON.stringify(layout)) // "move", "resize", "add", "remove", "settings", "undo", ...
|
|
724
|
-
});
|
|
725
|
-
grid.setLayout(JSON.parse(localStorage.getItem("dashboard"))); // plain, versioned JSON ({ version: 1, widgets: [...] })
|
|
726
|
-
```
|
|
727
|
-
|
|
728
|
-
- **Layout** is CSS grid. The columns, the row height, the gap and the place of every widget are CSS classes written into a constructed style sheet, so a strict
|
|
729
|
-
Content-Security-Policy (no `style` attribute) is fine. Widgets fall upwards (`compact: false` keeps the gaps) and slide to their new places (not under reduced motion).
|
|
730
|
-
- **Edit mode** (`setEditable(true)`): drag by the handle, resize by any edge or corner, snap to cells, push other widgets out of the way. Settings, duplicate and remove buttons.
|
|
731
|
-
A **locked** widget (`lockWidget(id)`) is not moved, not resized, not pushed, and nothing can be put on it.
|
|
732
|
-
- **Keyboard**: focus the handle, Space or Enter picks the widget up, arrow keys move it, Shift with arrow keys resizes it, Enter drops it, Escape cancels. Every step is announced
|
|
733
|
-
in a live region ("Column 2, row 1, 3 wide, 2 high"). Pointer Events: mouse, pen and touch work the same.
|
|
734
|
-
- **Undo and redo** of every change (`undo()`, `redo()`, `canUndo()`); `updateWidget(id, { config })` is for data from code and is not an undo step.
|
|
735
|
-
- **Layouts** (`getLayout()` / `setLayout(json)`) are plain JSON and the application decides where they are stored. Loading is checked: a bad entry is skipped (reported in the result),
|
|
736
|
-
duplicate ids are replaced, places are clamped and made free of overlaps, `__proto__`-style keys are dropped, and a type that is not registered is shown as a placeholder (its data is kept, nothing is executed).
|
|
737
|
-
- **Performance**: a widget is rendered only when it is first seen, `resize(context, size)` is called throttled when its body changes size, and nothing re-renders while it is out of view.
|
|
738
|
-
- The grid maths (`placeItem`, `compact`, `findFreeSpot`, `normalize`, `collides`) is exported as well, for your own layouts.
|
|
739
|
-
|
|
740
|
-
### Code: highlighting, an editor and a diff
|
|
741
|
-
|
|
742
|
-
`athena-ui-js/code`: no dependency, no inline style, and nothing is parsed as markup (the code is built with `el()`, so a `<img onerror>` in a comment stays text).
|
|
743
|
-
|
|
744
|
-
```js
|
|
745
|
-
import { highlightCode, generateCodeBlock, createCodeEditor, createDiffView, registerLanguage } from "athena-ui-js/code";
|
|
746
|
-
|
|
747
|
-
// read only
|
|
748
|
-
document.body.append(highlightCode("const a = 1;", "js", { lineNumbers: true, highlightLines: [1] })); // a <pre><code> with token spans
|
|
749
|
-
generateCodeBlock({ parent: "docs", code: sql, language: "sql", lineNumbers: true }); // + the language label and a copy button
|
|
750
|
-
|
|
751
|
-
// an editor
|
|
752
|
-
const editor = createCodeEditor({
|
|
753
|
-
element: "editor", value: source, language: "ts", onChange: value => save(value),
|
|
754
|
-
markers: [{ line: 3, message: "Unexpected token", level: "error" }], // lint markers, shown in the status line
|
|
755
|
-
readOnlyRanges: [{ from: 1, to: 2 }], // lines that cannot be changed
|
|
756
|
-
provideCompletions: ({ prefix }) => words.filter(word => word.startsWith(prefix)).map(label => ({ label }))
|
|
757
|
-
});
|
|
758
|
-
|
|
759
|
-
// what changed
|
|
760
|
-
createDiffView({ parent: "review", original: before, modified: after, language: "json", mode: "split", context: 3 });
|
|
761
|
-
```
|
|
762
|
-
|
|
763
|
-
- **Languages**: `javascript` (`js`), `typescript` (`ts`), `json`, `html` (`xml`, `svg`), `css` (`scss`, `less`), `sql`, `shell` (`sh`, `bash`), `yaml`, `csharp` (`c#`, `cs`), `python` (`py`).
|
|
764
|
-
A language is a plain object (`registerLanguage({ name, aliases, rules: [{ type, pattern }], lineComment, blockComment, pairs, indentAfter })`), so your own are one call.
|
|
765
|
-
The tokenizer is a set of regular expressions, not a parser: it is fast and tolerant (unfinished code still gets colours) but it does not know nested `${}` of a template string or the `<script>` inside HTML.
|
|
766
|
-
- **Colours** are the tokens `--athena-tok-comment`, `-string`, `-keyword` ... (light and dark); a test keeps every one at 4.5:1 contrast or more.
|
|
767
|
-
- **The editor is a real `<textarea>`** with the highlighted text behind it, so native input, selection, spell-check off, mobile keyboards, IME and screen readers all work.
|
|
768
|
-
Tab and Shift+Tab indent and outdent (also several lines), Enter keeps the indentation (and goes one level deeper after `{`, `(`, `:`), brackets and quotes are closed, stepped over, wrapped around a selection and
|
|
769
|
-
deleted together, Ctrl+/ comments, Alt+Up / Alt+Down move lines, Ctrl+Z / Ctrl+Y undo and redo (typing is grouped), Ctrl+F finds and Ctrl+H replaces (case, regular expression, all matches
|
|
770
|
-
highlighted, replace all is one undo step), Ctrl+Space suggests. The matching bracket is highlighted (CSS Custom Highlight API where the browser has it).
|
|
771
|
-
**Escape, then Tab, leaves the editor** (so the keyboard is never trapped); the way out is read to screen readers.
|
|
772
|
-
- **Size**: only the lines around a change are tokenized again, and a test checks that this gives exactly what tokenizing everything gives. On the (slow) development machine the work of the editor per key press is
|
|
773
|
-
about 13 ms in a 5,000 line file; the browser's own layout of two large text blocks is the larger part (about 90 ms per key at 5,000 lines; smaller files were not measured separately). Texts longer than 300,000 characters
|
|
774
|
-
(`maxHighlightLength`) are shown without highlighting. Not there yet: multiple cursors, minimap, folding.
|
|
775
|
-
|
|
776
|
-
### Safe DOM building
|
|
777
|
-
|
|
778
|
-
`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
|
|
779
|
-
nested lists, listeners have to be functions, and `on*` attributes, `style` and `srcdoc`, unsafe addresses (`javascript:`, `data:`) in `href` / `src` / `action`, and properties that
|
|
780
|
-
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
|
|
781
|
-
do not control (a plugin API).
|
|
782
|
-
|
|
783
|
-
### Moved into Athena: HTMLElementGenerator and HTMLControlGenerator
|
|
784
|
-
|
|
785
|
-
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
|
|
786
|
-
`src/libs/core/elementGenerator.js`, `HTMLControlGenerator(options)` / `.create()` / `.register()` in `src/libs/core/controls.js`; both are exported and global as before.
|
|
787
|
-
`HTMLControlGenerator` has no jQuery in it: `create` returns the element (wrap it yourself with `$(...)` if you still need a jQuery object).
|
|
788
|
-
`registerHungarianInputControls()` adds the `hunPIN`, `hunCRID` and `hunTID` input types of its old addon. The old repositories are no longer developed.
|
|
789
|
-
|
|
790
|
-
### Parents and handles
|
|
791
|
-
|
|
792
|
-
Every `parent` option takes an element, an id or a CSS selector (`"wrapper"`, `"#list"`, `".panel > ul"`; an id wins over a selector).
|
|
793
|
-
The components return the same kind of handle: `{ element, update(), destroy() }`, plus their own methods. `destroy()` removes the
|
|
794
|
-
component. `update()` redraws it where that makes sense (`table.update({ rows })`, `chart.update({ series })`, `stat.update({ value })`,
|
|
795
|
-
`progress.update({ value })`) and otherwise just returns the handle. `generateChart` still returns the SVG element, which also carries
|
|
796
|
-
`element`, `update(options)` and `destroy()`.
|
|
797
|
-
|
|
798
|
-
### Testing your application
|
|
799
|
-
|
|
800
|
-
```js
|
|
801
|
-
import { JSDOM } from "jsdom";
|
|
802
|
-
import { installDom, until, tick } from "athena-ui-js/testing";
|
|
803
|
-
|
|
804
|
-
const dom = installDom(JSDOM); // window, document, Node, Event, ... become global
|
|
805
|
-
generateDropdown({ parent: "#wrapper", icon: "x", ariaLabel: "More", items: [] });
|
|
806
|
-
await until(() => document.querySelector(".dropdown"), { message: "the dropdown" });
|
|
807
|
-
dom.uninstall();
|
|
808
|
-
```
|
|
809
|
-
|
|
810
|
-
`installDom` takes your own `JSDOM` class, so Athena UI has no dependency on jsdom. Athena creates its events from the element's own
|
|
811
|
-
window, so they work in jsdom without a global `Event`.
|
|
812
|
-
|
|
813
|
-
## Tests
|
|
814
|
-
|
|
815
|
-
```sh
|
|
816
|
-
npm test # unit tests of the pure modules, run in Node
|
|
817
|
-
npm run test:browser # the components in headless Chrome
|
|
818
|
-
```
|
|
819
|
-
|
|
820
|
-
The unit tests cover validation, translations, router matching, CSV, pagination, formatting, virtual scrolling math, date ranges and the URL check.
|
|
821
|
-
The browser tests start a small static server, open `tests/browser/index.html` in headless Chrome, Chromium or Edge and run every
|
|
822
|
-
component: forms, dialogs, navigation, submenus, inputs, rich text (sanitizing, toolbar, paste), tables (resizing, virtual scrolling), router,
|
|
823
|
-
session, themes. Set `CHROME_PATH` if the browser is not found. `DEBUG=1` prints the browser log when the page does not report results.
|
|
824
|
-
|
|
825
|
-
- **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
|
|
826
|
-
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 reports Chrome
|
|
827
|
-
makes while it parses an inline handler, a style attribute or a `<style>` element in an inert document.)
|
|
828
|
-
- One test feeds markup to about 40 components and checks that text from data stays text.
|
|
829
|
-
- `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).
|
|
830
|
-
- 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).
|
|
831
|
-
|
|
832
|
-
## Project structure
|
|
833
|
-
|
|
834
|
-
```
|
|
835
|
-
src/
|
|
836
|
-
athena-ui.js the whole API as ES module exports (no side effects)
|
|
837
|
-
classic.js opt-in: the whole API on window, for classic scripts
|
|
838
|
-
table.js, dialog.js, ... one entry point per component (athena-ui-js/table, athena-ui-js/dialog, ...)
|
|
839
|
-
theme-boot.js classic script that sets the saved theme and mode before the page is drawn
|
|
840
|
-
testing.js installDom, until, tick for the tests of an application
|
|
841
|
-
index.html, example.js example page
|
|
842
|
-
libs/
|
|
843
|
-
config/ default configuration, application hooks
|
|
844
|
-
core/ DOM / focus helpers, el, validation, translations, CSV, formatting, sanitizer, cookies, theme manager,
|
|
845
|
-
HTMLElementGenerator, HTMLControlGenerator, table math
|
|
846
|
-
hephaestus/ theme loader, generators (layout, menus, forms, charts, tables, feedback, dialogs, navigation,
|
|
847
|
-
components, inputs), router, session, auth state
|
|
848
|
-
res/themes/ tokens.css, default and dark theme, appearance.css (themes and modes)
|
|
849
|
-
types/ TypeScript definitions (npm run types)
|
|
850
|
-
docs/ styling.md (generated), migration-2.0.md
|
|
851
|
-
demo/ the demo and test application (server, API, pages, end to end tests), deployed to Azure by GitHub Actions
|
|
852
|
-
.github/workflows/ ci.yml (tests) and demo-deploy.yml
|
|
853
|
-
tests/ unit tests (Node) and browser tests (headless Chrome, strict CSP)
|
|
854
|
-
```
|
|
855
|
-
|
|
856
|
-
## Authors
|
|
857
|
-
|
|
858
|
-
* **Csaba Tóth** - *Initial work* - [csabatibortoth](https://github.com/csabatibortoth)
|
|
859
|
-
|
|
860
|
-
## License
|
|
861
|
-
|
|
862
|
-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
|
|
863
|
-
|
|
864
|
-
## Releases
|
|
865
|
-
|
|
866
|
-
### 2.5.
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
### 2.4.
|
|
881
|
-
####
|
|
882
|
-
1.
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
### 2.
|
|
897
|
-
####
|
|
898
|
-
1.
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
#### Added:
|
|
909
|
-
1. `
|
|
910
|
-
2.
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
####
|
|
915
|
-
1. `
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
####
|
|
962
|
-
1.
|
|
963
|
-
2.
|
|
964
|
-
3.
|
|
965
|
-
4.
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
####
|
|
989
|
-
1.
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
####
|
|
1010
|
-
1.
|
|
1011
|
-
2. `
|
|
1012
|
-
3. `
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
####
|
|
1023
|
-
1.
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
####
|
|
1027
|
-
1.
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
####
|
|
1033
|
-
1.
|
|
1034
|
-
2.
|
|
1035
|
-
3.
|
|
1036
|
-
4.
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
####
|
|
1046
|
-
1.
|
|
1047
|
-
|
|
1048
|
-
### 0.3.
|
|
1049
|
-
#### Added:
|
|
1050
|
-
1.
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1
|
+
# Athena UI
|
|
2
|
+
|
|
3
|
+
A small UI framework for development and education purposes. It generates a page
|
|
4
|
+
layout (header, menu, content wrapper, footer) from a single `init()` call, loads its own libraries
|
|
5
|
+
and theme, and ships the building blocks of a multipurpose application: forms, tables, charts,
|
|
6
|
+
feedback, navigation, a router and more.
|
|
7
|
+
|
|
8
|
+
Current version: **2.5.1**
|
|
9
|
+
|
|
10
|
+
[Quick start](#usage) · [API](#api) · [Components](#charts) · [Themes](#themes) · [Tests](#tests) · [Release notes](#releases)
|
|
11
|
+
|
|
12
|
+
## Status
|
|
13
|
+
|
|
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
|
+
Known limits are listed below, so you can judge whether it fits your project:
|
|
17
|
+
|
|
18
|
+
- Rich text uses the deprecated `document.execCommand`. Content is sanitized in the browser, but sanitize it on the server too.
|
|
19
|
+
- The session cookie is readable from JavaScript. It is a UI state, not a security boundary: authenticate on the server.
|
|
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
|
+
- 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, the accordion, the dropdown menu and tooltips use the native `<dialog>`, `<details>` and popover elements, so they need a browser that supports cascade layers and `<dialog>` (2022 or later). The dropdown menu and the tooltips are native popovers (the `popover` attribute) in browsers that have them (Chrome / Edge 114, Safari 17, Firefox 125), and a plain fallback in older ones.
|
|
26
|
+
|
|
27
|
+
## Features
|
|
28
|
+
|
|
29
|
+
- Generated page layout: container, header (logo, title, menu), wrapper, footer (menu, copyright text)
|
|
30
|
+
- Menus built from your own item lists, with a navigation callback
|
|
31
|
+
- Login, registration and lost password forms with optional SHA-256 password hashing
|
|
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
|
|
39
|
+
- Form builder: text, number, date, textarea, select, radio / checkbox groups, switch, autocomplete, multi select, with validation
|
|
40
|
+
- Buttons, toasts, alerts, spinner, progress bar, alert / confirm / prompt dialogs
|
|
41
|
+
- Tabs, accordion, dropdown, sidebar, breadcrumbs, pagination and a hash / history router
|
|
42
|
+
- Cards, grid, badges, avatars, KPI tiles, tooltips, links, sections
|
|
43
|
+
- File upload with progress, drag-and-drop area, stepper (wizard), date range picker, rich text and WYSIWYG editor
|
|
44
|
+
- Menus with submenus
|
|
45
|
+
- Session handling (login state in a cookie), change password form
|
|
46
|
+
- Default and dark theme (switchable at runtime), responsive, translations (English, Hungarian), keyboard and ARIA support
|
|
47
|
+
- Modal open / close helpers
|
|
48
|
+
- Themes loaded at runtime, custom stylesheets supported
|
|
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)
|
|
51
|
+
|
|
52
|
+
## Requirements
|
|
53
|
+
|
|
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
|
|
55
|
+
- The page has to be served over HTTP(S). Modules do not load from `file://`.
|
|
56
|
+
- Nothing else: Athena UI has no runtime dependencies. (TypeScript is a dev dependency, used to write the type definitions.)
|
|
57
|
+
|
|
58
|
+
## Installation
|
|
59
|
+
|
|
60
|
+
```sh
|
|
61
|
+
npm install athena-ui-js
|
|
62
|
+
```
|
|
63
|
+
|
|
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
|
+
```
|
|
68
|
+
|
|
69
|
+
The entry points are `table`, `chart`, `dialog`, `menu`, `navigation`, `forms`, `feedback`, `components`, `inputs`, `router`, `session`, `theme`, `i18n`, `format`,
|
|
70
|
+
`validation`, `motion`, `widgets`, `code`, `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.
|
|
74
|
+
|
|
75
|
+
### The demo application
|
|
76
|
+
|
|
77
|
+
**Try it live: https://athena-ui-js-demo-duc7dncrfhg5fxfs.northeurope-01.azurewebsites.net** (sign in with `demo` / `demo-pass`, or `admin` / `admin-pass`; the app sleeps when nobody visits, so the first request can take a few seconds).
|
|
78
|
+
|
|
79
|
+
`demo/` is a demo and test application: tables with 100,000 rows from a server, a streaming chart, every field type, native dialogs, a menu with groups inside groups, themes
|
|
80
|
+
and modes, and a real sign in, served by a small Node server (no dependencies) under a strict Content-Security-Policy.
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
npm run demo # http://localhost:3000
|
|
84
|
+
npm run test:demo # the server, the API and every page in a real browser
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
GitHub Actions tests it and deploys it to an Azure App Service: [demo/README.md](demo/README.md) has the one-time set up.
|
|
88
|
+
|
|
89
|
+
## Usage
|
|
90
|
+
|
|
91
|
+
```html
|
|
92
|
+
<!-- jQuery is not needed -->
|
|
93
|
+
<script type="module">
|
|
94
|
+
import { init, clearWrapper, generateLoginForm } from "./athena-ui.js";
|
|
95
|
+
|
|
96
|
+
init({
|
|
97
|
+
theme: { id: 0 },
|
|
98
|
+
config: { header_title_text: "My App", login_enabled: true },
|
|
99
|
+
menuItems: {
|
|
100
|
+
headerMenu: [
|
|
101
|
+
{ id: "menu-home", class: "menu-item", text: "", inner_text: "Home" },
|
|
102
|
+
{ id: "menu-login", class: "menu-item", text: "", inner_text: "Login" }
|
|
103
|
+
],
|
|
104
|
+
footerMenu: []
|
|
105
|
+
},
|
|
106
|
+
nav: page => {
|
|
107
|
+
if (page === "Login") {
|
|
108
|
+
clearWrapper();
|
|
109
|
+
generateLoginForm();
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
login: ({ username, password }) => console.log(`${username} logged in`)
|
|
113
|
+
});
|
|
114
|
+
</script>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
`init()` returns a Promise that resolves with the effective configuration once the libraries and
|
|
118
|
+
the theme are loaded and the layout is generated.
|
|
119
|
+
|
|
120
|
+
### Inside a page: createApp
|
|
121
|
+
|
|
122
|
+
`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:
|
|
123
|
+
|
|
124
|
+
```js
|
|
125
|
+
const app = await createApp({ root: "#my-section", config: { generateHeader: false, generateFooter: false } });
|
|
126
|
+
generateTable({ parent: "wrapper", /* ... */ }); // the wrapper of the app is the default parent
|
|
127
|
+
app.destroy();
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
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.
|
|
131
|
+
|
|
132
|
+
### init options
|
|
133
|
+
|
|
134
|
+
| Option | Description |
|
|
135
|
+
| --- | --- |
|
|
136
|
+
| `theme` | `{ id }` of a theme registered in `res/themes/themes.js`, or `{ href }` of a custom stylesheet. Defaults to the default theme. |
|
|
137
|
+
| `config` | Settings overriding the defaults, see [Configuration](#configuration). |
|
|
138
|
+
| `menuItems` | `{ headerMenu, footerMenu }`, arrays of `{ id, class, text, inner_text }`. Placeholder items are generated without it. |
|
|
139
|
+
| `nav` | Called without arguments when the wrapper is generated, and with the `inner_text` of the item on menu clicks. |
|
|
140
|
+
| `login` | Called with `{ username, password }` when the login button is clicked and `login_enabled` is set. |
|
|
141
|
+
| `register` | Called with `{ username, email, password }` when a valid registration form is submitted and `registration_enabled` is set. |
|
|
142
|
+
| `lostPassword` | Called with `{ email }` when a valid lost password form is submitted and `lost_password_enabled` is set. |
|
|
143
|
+
| `changePassword` | Called with `{ currentPassword, newPassword }` when a valid change password form is submitted and `change_password_enabled` is set. |
|
|
144
|
+
|
|
145
|
+
### Configuration
|
|
146
|
+
|
|
147
|
+
| Setting | Default | Description |
|
|
148
|
+
| --- | --- | --- |
|
|
149
|
+
| `header_title_text` | `"Athena UI"` | Title in the header |
|
|
150
|
+
| `header_img_url` | | Header logo URL |
|
|
151
|
+
| `copyright` | placeholder text | Footer text, the version is appended |
|
|
152
|
+
| `version` | `"2.5.1"` | Version shown in the footer |
|
|
153
|
+
| `bordered` | `true` | Draw a border around the layout blocks |
|
|
154
|
+
| `generateHeader`, `generateFooter` | `true` | Generate the header / footer block |
|
|
155
|
+
| `generateHeadercontent`, `generateFooterContent`, `generateWrappercontent` | `true` | Generate the content of the block |
|
|
156
|
+
| `login_enabled` | `false` | Call the `login` callback from the login form |
|
|
157
|
+
| `registration_enabled` | `false` | Call the `register` callback from the registration form |
|
|
158
|
+
| `lost_password_enabled` | `false` | Call the `lostPassword` callback from the lost password form |
|
|
159
|
+
| `change_password_enabled` | `false` | Call the `changePassword` callback from the change password form |
|
|
160
|
+
| `login_remember_me` | `false` | Show a "Remember me" checkbox in the login form, passed to `login` as `remember` |
|
|
161
|
+
| `locale` | `"en"` | Language of the generated texts (`en`, `hu`, or your own, see [Translations](#translations)) |
|
|
162
|
+
| `session_cookie` | `"athena_session"` | Name of the session cookie |
|
|
163
|
+
| `session_days` | `7` | Lifetime of a remembered session in days |
|
|
164
|
+
| `customLoader` | | URL of an extra classic script, loaded before the layout is generated |
|
|
165
|
+
| `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 |
|
|
166
|
+
|
|
167
|
+
### API
|
|
168
|
+
|
|
169
|
+
Everything is exported from `athena-ui.js`:
|
|
170
|
+
|
|
171
|
+
| Export | Description |
|
|
172
|
+
| --- | --- |
|
|
173
|
+
| `init(options)` | Loads everything and generates the layout |
|
|
174
|
+
| `config` | The live configuration object |
|
|
175
|
+
| `generateBasicLayout()`, `generateHeader()`, `generateWrapper()`, `generateFooter()` | Layout generation |
|
|
176
|
+
| `clearHeader()`, `clearWrapper()`, `clearFooter()`, `clearHeaderMenu()`, `clearFooterMenu()` | Empty a block |
|
|
177
|
+
| `generateBasicMenu(options)` | Generate a menu into any parent |
|
|
178
|
+
| `generateLoginForm()`, `getLoginFormData()` | Login form into the wrapper, and its current values |
|
|
179
|
+
| `generateRegistrationForm(parent)`, `getRegistrationFormData()`, `validateRegistrationForm()` | Registration form (username, email, password, confirmation) into `parent` (default `wrapper`). Validated before the callback is called. |
|
|
180
|
+
| `generateLostPasswordForm(parent)`, `getLostPasswordFormData()` | Lost password form (email) |
|
|
181
|
+
| `generateChart(options)` | Draw a chart, see [Charts](#charts) |
|
|
182
|
+
| `generateTable(options)` | Draw a table, see [Tables](#tables) |
|
|
183
|
+
| `generateChangePasswordForm(parent)`, `getChangePasswordFormData()`, `validateChangePasswordForm()` | Change password form |
|
|
184
|
+
| `generateForm`, `generateField`, `generateButton` | Form builder, see [Forms](#forms) |
|
|
185
|
+
| `showToast`, `generateAlert`, `generateSpinner`, `generateProgress` | See [Feedback](#feedback) |
|
|
186
|
+
| `showDialog`, `alertDialog`, `confirmDialog`, `promptDialog` | See [Dialogs](#dialogs) |
|
|
187
|
+
| `generateTabs`, `generateBreadcrumbs`, `generatePagination`, `generateAccordion`, `generateDropdown`, `generateSidebar` | See [Navigation](#navigation) |
|
|
188
|
+
| `createRouter(options)` | See [Router](#router) |
|
|
189
|
+
| `generateMenu(options)`, `generateHeaderMenu({ items })` | See [Menu component](#menu-component) |
|
|
190
|
+
| `generateSignInForm`, `generateSignUpForm`, `generatePasswordResetForm`, `generatePasswordChangeForm`, `createAuthState` | See [Signing in](#signing-in-recommended) |
|
|
191
|
+
| `showFormDialog`, `showConfirm` | See [Dialogs](#dialogs) |
|
|
192
|
+
| `createThemeManager`, `generateThemePicker` | See [Themes and modes](#themes-and-modes-light--dark--like-the-system) |
|
|
193
|
+
| `generateDateTimeRange`, `toLocalInput`, `fromLocalInput` | See [Date and time range](#date-and-time-range) |
|
|
194
|
+
| `generatePageHeader`, `generateFacts`, `generateEmptyState`, `generateLoading`, `copyToClipboard` | See [Page parts and formatting](#page-parts-and-formatting) |
|
|
195
|
+
| `formatBytes`, `formatNumber`, `formatDuration`, `formatRelativeTime`, `formatDate` | Format helpers on top of `Intl`, in the current language |
|
|
196
|
+
| `el`, `setContent`, `resolveElement`, `asHandle`, `createSafeBuilder` | See [Safe DOM building](#safe-dom-building) |
|
|
197
|
+
| `animate`, `flip`, `stagger`, `spring`, `tween`, `transition`, `viewTransition`, `setMotion`, `prefersReducedMotion`, `easings`, `generateSkeleton` | See [Motion](#motion-animations-and-transitions) |
|
|
198
|
+
| `registerWidget`, `createWidgetGrid`, `getWidgetTypes`, `placeItem`, `compact`, `findFreeSpot`, `normalize` | See [Widgets](#widgets-a-dashboard-that-can-be-built) |
|
|
199
|
+
| `highlightCode`, `generateCodeBlock`, `createCodeEditor`, `createDiffView`, `registerLanguage`, `tokenize`, `diffLines` | See [Code](#code-highlighting-an-editor-and-a-diff) |
|
|
200
|
+
| `generateCard`, `generateSection`, `generateGrid`, `generateBadge`, `generateAvatar`, `generateStat`, `generateLink`, `generateTooltip` | See [Components](#components) |
|
|
201
|
+
| `generateAutocomplete`, `generateMultiSelect`, `generateFileUpload`, `generateDropZone`, `generateStepper`, `generateDateRange`, `generateRichText`, `generateWysiwyg` | See [Inputs](#inputs) |
|
|
202
|
+
| `sanitizeHtml(html)`, `htmlToText(html)`, `isSafeUrl(url)` | The allow-list sanitizer behind the rich text editor |
|
|
203
|
+
| `setSession`, `getSession`, `isLoggedIn`, `logout`, `onSessionChange` | See [Session](#session) |
|
|
204
|
+
| `translate`, `setLocale`, `getLocale`, `addMessages` | See [Translations](#translations) |
|
|
205
|
+
| `validateValue`, `validateAll` | The validator behind the form builder |
|
|
206
|
+
| `toCsv(columns, rows)`, `downloadFile(name, text)` | CSV helpers |
|
|
207
|
+
| `setTheme({ id })` | Switch the theme at runtime |
|
|
208
|
+
| `openModal(id)`, `closeModal(id)` | Show / hide a `.modal` element (default id: `myModal`). Elements with the `close` class close their modal. |
|
|
209
|
+
| `loadScript(src)` | Load a classic script once, returns a Promise |
|
|
210
|
+
| `Cookies` | `get(name)`, `set(name, value, { expires, path, domain, sameSite, secure })`, `remove(name)`: a small cookie helper (`expires` is days or a Date) |
|
|
211
|
+
| `createApp(options)` | `init` into any element, see [Inside a page](#inside-a-page-createapp) |
|
|
212
|
+
| `HTMLElementGenerator(options)` | Generates a div, span, p, heading or img and appends it to the element with the id `parent` |
|
|
213
|
+
| `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` |
|
|
214
|
+
|
|
215
|
+
HTMLElementGenerator and HTMLControlGenerator used to be projects of their own. They are part of Athena UI now (the calls and options are the
|
|
216
|
+
same, and HTMLControlGenerator has no jQuery in it); the old repositories are no longer developed.
|
|
217
|
+
|
|
218
|
+
### Charts
|
|
219
|
+
|
|
220
|
+
```js
|
|
221
|
+
const chart = generateChart({
|
|
222
|
+
type: "line", // "bar" | "line" | "area" | "sparkline" | "pie" | "donut"
|
|
223
|
+
parent: "wrapper", // element, id or selector (default "wrapper")
|
|
224
|
+
title: "Revenue",
|
|
225
|
+
labels: ["Q1", "Q2", "Q3"],
|
|
226
|
+
series: [
|
|
227
|
+
{ name: "2025", data: [12, 19, 8] },
|
|
228
|
+
{ name: "2026", data: [14, 17, 12], color: "#e15759" }
|
|
229
|
+
],
|
|
230
|
+
table: true // adds "Show as table" with the values
|
|
231
|
+
});
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
Charts are inline SVG, nothing is styled inline (a strict Content-Security-Policy works), negative values are supported. `pie` and `donut` use the
|
|
235
|
+
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.
|
|
236
|
+
Other options: `id`, `width` (600), `height` (360), `legend`, `zero: false` (a line chart's value axis may start near the smallest value).
|
|
237
|
+
|
|
238
|
+
- **Colours** come from the theme: `--series-1` ... `--series-8` (see `appearance.css`), so every chart follows light / dark. `color` overrides one series.
|
|
239
|
+
- **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.
|
|
240
|
+
- **Legend**: click (or Enter / Space) on an entry hides and shows that series.
|
|
241
|
+
- **Time axis**: `times: [Date | ms | "2026-11-19T10:00"]` (line and area). Ticks fall on round times, points sit at their real distance.
|
|
242
|
+
- **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,
|
|
243
|
+
0 resets. `chart.zoom(from, to)`, `chart.resetZoom()`, `chart.getZoom()`, `onZoom(range)` and `zoomRange` (ms with `times`, otherwise the point index).
|
|
244
|
+
- **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.
|
|
245
|
+
- **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.
|
|
246
|
+
- `chart.update({ series })` redraws with changes, `chart.destroy()` removes the chart and its table. `generateChart` returns the `<svg>` element that carries these
|
|
247
|
+
methods, or `null` when the options are invalid.
|
|
248
|
+
|
|
249
|
+
### Tables
|
|
250
|
+
|
|
251
|
+
```js
|
|
252
|
+
const { setRows } = generateTable({
|
|
253
|
+
parent: "wrapper",
|
|
254
|
+
caption: "Users",
|
|
255
|
+
columns: [{ key: "name", label: "Name" }, { key: "age", label: "Age", format: v => `${v} y` }],
|
|
256
|
+
rows: [{ name: "Anna", age: 31 }, { name: "Béla", age: 27 }],
|
|
257
|
+
filter: true, // text filter box
|
|
258
|
+
pageSize: 10, // 0 = no pagination
|
|
259
|
+
onRowClick: row => console.log(row)
|
|
260
|
+
});
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Click a header to sort (disable with `sortable: false`, or per column). Other options: `id`, `class`,
|
|
264
|
+
`emptyText`. Returns `{ element, setRows(rows), getSelected(), clearSelection(), toCsv(), exportCsv(filename) }`.
|
|
265
|
+
|
|
266
|
+
- `selectable: true` adds a checkbox column (the header checkbox selects every filtered row), `onSelectionChange(rows)` reports changes.
|
|
267
|
+
- A column with `editable: true` can be edited with a double click, or Enter / F2 on the focused cell. `onEdit(row, key, value, oldValue)` is called after the edit; return `false` to reject it. Numeric cells stay numbers.
|
|
268
|
+
- `resizableColumns: true` puts a drag handle on every header edge. The handle is focusable too: Left / Right resize by 10 px, Shift by 50 px, double click resets the column to its configured `width`. Columns take `width`, `minWidth` and `maxWidth`; `onColumnResize(key, width)` and `getColumnWidths()` let you persist the layout.
|
|
269
|
+
- `virtual: { height: 400, rowHeight: 36, overscan: 5 }` (or `virtual: true`) renders only the rows in view and keeps the scroll bar the size of the whole list, so 10 000+ rows stay fast. Rows have a fixed height (the theme enforces it, one line per cell), the table scrolls inside `height` and its header stays visible. It replaces pagination; filtering, sorting, selection, editing and CSV export work as usual.
|
|
270
|
+
- 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.
|
|
271
|
+
- 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).
|
|
272
|
+
- 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.
|
|
273
|
+
- **Rows from a server**: `dataSource: async ({ page, pageSize, cursor, sort, filter }) => ({ rows, total })`. Sorting, the (debounced) filter box and the pager ask it again,
|
|
274
|
+
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
|
|
275
|
+
(`page` is 0-based), or with `nextCursor` for a "Load more" button (`cursor` is what the last answer gave). `table.reload()` asks again.
|
|
276
|
+
- **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
|
|
277
|
+
`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.
|
|
278
|
+
The select-all checkbox only selects the rows that have arrived.
|
|
279
|
+
- `rowActions: [{ label: "Delete", danger: true, onclick: row => remove(row), hidden: row => row.locked, ariaLabel: row => "Delete " + row.name }]` adds a column of buttons.
|
|
280
|
+
- `exportCsv()` downloads the filtered and sorted rows. Cells that start with `=`, `+`, `-` or `@` are prefixed with `'` so a spreadsheet does not run them as formulas.
|
|
281
|
+
|
|
282
|
+
### Forms
|
|
283
|
+
|
|
284
|
+
```js
|
|
285
|
+
const form = generateForm({
|
|
286
|
+
parent: "wrapper",
|
|
287
|
+
submitText: "Save",
|
|
288
|
+
fields: [
|
|
289
|
+
{ name: "name", label: "Name", required: true, minLength: 2, help: "At least 2 characters" },
|
|
290
|
+
{ name: "email", label: "Email", type: "email", required: true },
|
|
291
|
+
{ name: "password", label: "Password", type: "password", required: true },
|
|
292
|
+
{ name: "password2", label: "Repeat", type: "password", match: "password" },
|
|
293
|
+
{ name: "country", label: "Country", type: "select", placeholder: "Choose...", options: ["Hungary", "Italy"] },
|
|
294
|
+
{ name: "plan", type: "radio", label: "Plan", options: ["Free", "Pro"], value: "Free" },
|
|
295
|
+
{ name: "news", type: "switch", label: "Newsletter" }
|
|
296
|
+
],
|
|
297
|
+
onSubmit: async values => { await save(values); } // called when every field is valid
|
|
298
|
+
});
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
Field types: `text`, `password`, `email`, `number`, `date`, `datetime-local`, `time`, `month`, `week`, `url`, `tel`,
|
|
302
|
+
`search`, `color`, `range`, `file`, `hidden`, `textarea`, `select` (`multiple`), `checkbox`, `switch`, `radio`,
|
|
303
|
+
`checkboxes`, `autocomplete`, `multiselect`, `daterange` (value `{ from, to }`), `richtext` and `wysiwyg` (value: safe HTML).
|
|
304
|
+
The date, time and color types use the native pickers of the browser.
|
|
305
|
+
|
|
306
|
+
Rules (`required`, `email`, `minLength`, `maxLength`, `pattern`, `min`, `max`, `match`, `validate(value, values)`) can be
|
|
307
|
+
given on the field or in `rules`. A field is validated when it loses focus, then on every change. A rejected
|
|
308
|
+
`onSubmit` promise is shown as form message and the submit button shows a spinner while it runs.
|
|
309
|
+
|
|
310
|
+
The returned form has `getValues()`, `setValues()`, `setErrors({ name: "Taken" })` (server side errors),
|
|
311
|
+
`validate()`, `reset()`, `setMessage(text)`, `fields` and `submitButton`. `generateField(options)` builds a single field.
|
|
312
|
+
|
|
313
|
+
`generateButton({ text, variant, loading, disabled, onclick })` has the variants `primary`, `secondary`, `danger` and
|
|
314
|
+
`link`, and returns `{ element, setLoading, setDisabled, setText }`.
|
|
315
|
+
|
|
316
|
+
### Feedback
|
|
317
|
+
|
|
318
|
+
```js
|
|
319
|
+
showToast({ title: "Saved", message: "All good", type: "success", duration: 4000 }); // info | success | warning | error
|
|
320
|
+
generateAlert({ parent: "wrapper", type: "error", message: "Failed", dismissible: true });
|
|
321
|
+
generateSpinner({ parent: "wrapper", size: "large" });
|
|
322
|
+
const progress = generateProgress({ parent: "wrapper", label: "Upload", value: 20 }); // no value: indeterminate
|
|
323
|
+
progress.setValue(60);
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
### Dialogs
|
|
327
|
+
|
|
328
|
+
```js
|
|
329
|
+
await alertDialog("Saved");
|
|
330
|
+
if (await confirmDialog("Delete the item?", { title: "Delete", confirmText: "Delete", danger: true })) { /* ... */ }
|
|
331
|
+
const name = await promptDialog("Your name", { validate: v => v ? "" : "Required" }); // null when cancelled
|
|
332
|
+
const choice = await showDialog({ title: "Custom", content: "Pick one", buttons: [{ text: "A", value: "a" }, { text: "B", value: "b" }] });
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
Options: `size` ("small" 360 px, "medium" 480 px, "large" 720 px, "full") and `class` (extra class on the dialog).
|
|
336
|
+
`showDialog` returns a promise that also carries the open dialog: `const dialog = showDialog({ size: "large", ... }); dialog.element; dialog.close(value);`.
|
|
337
|
+
The dialog is shown by a CSS class, not by an inline style, so a strict Content-Security-Policy works.
|
|
338
|
+
|
|
339
|
+
**Form dialog** and **confirmation**:
|
|
340
|
+
|
|
341
|
+
```js
|
|
342
|
+
const saved = await showFormDialog({
|
|
343
|
+
title: "Add host", intro: "The agent connects with this name.", size: "small", submitText: "Add",
|
|
344
|
+
fields: [{ name: "name", label: "Name", required: true }],
|
|
345
|
+
onSubmit: async (values, form) => {
|
|
346
|
+
const answer = await api.addHost(values); // when this throws, the message shows in the dialog and it stays open
|
|
347
|
+
if (answer.errors) throw Object.assign(new Error("Check the fields"), { fields: answer.errors }); // or form.setErrors({ name: "Already taken" })
|
|
348
|
+
}
|
|
349
|
+
}); // true when saved, false when dismissed
|
|
350
|
+
|
|
351
|
+
if (await showConfirm({ title: "Delete host", message: "This cannot be undone.", confirmText: "Delete", danger: true, typeToConfirm: host.name })) { /* ... */ }
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
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
|
|
355
|
+
(`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`
|
|
356
|
+
(it adds `showModal()`), and close a dialog with the `cancel` event, as the browser does for Esc.
|
|
357
|
+
|
|
358
|
+
Dialogs trap the focus, close with Esc (resolving `null` / `false`) and restore the focus. Text content is
|
|
359
|
+
never parsed as HTML. `openModal` / `closeModal` got the same focus handling.
|
|
360
|
+
|
|
361
|
+
### Navigation
|
|
362
|
+
|
|
363
|
+
The **dropdown** menu and the **tooltip** are native popovers: they are drawn in the top layer, so no parent with `overflow: hidden` can cut them off and no `z-index` fight is possible;
|
|
364
|
+
a click outside and Esc close the dropdown, and the focus goes back to its button. They are placed next to their button by a small helper (it sets two CSS variables, which a strict
|
|
365
|
+
Content-Security-Policy allows): below, or above when there is no room below, and always kept inside the window. A tooltip shows on hover and on focus and goes on Esc; a touch does not show it.
|
|
366
|
+
Without the popover API the dropdown is a plain menu that is shown and hidden with `hidden`, and the tooltip a CSS one.
|
|
367
|
+
|
|
368
|
+
```js
|
|
369
|
+
generateTabs({ parent: "wrapper", tabs: [{ id: "a", label: "A", content: "First" }, { id: "b", label: "B", content: () => lazyNode() }] });
|
|
370
|
+
generateAccordion({ parent: "wrapper", items: [{ title: "Q", content: "A", open: true }], multiple: false });
|
|
371
|
+
generateDropdown({ parent: "wrapper", label: "Actions", items: [{ label: "Edit", onclick }, { divider: true }, { label: "Delete", onclick }] });
|
|
372
|
+
generateDropdown({ parent: "wrapper", icon: "⋮", ariaLabel: "More actions", items: [{ label: "Edit", onclick }] }); // icon only; also caret: true, toggleClass
|
|
373
|
+
generatePagination({ parent: "wrapper", total: 200, pageSize: 10, onChange: page => load(page) });
|
|
374
|
+
generateBreadcrumbs({ parent: "wrapper", items: [{ label: "Home", href: "#/" }, { label: "Users" }] });
|
|
375
|
+
generateSidebar({ parent: "wrapper", active: "home", onSelect: item => go(item.id),
|
|
376
|
+
items: [{ id: "home", label: "Home" }, { id: "reports", label: "Reports", children: [{ id: "daily", label: "Daily" }] }] });
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
Tabs, dropdown and the combobox inputs follow the WAI-ARIA keyboard patterns (arrow keys, Home / End, Esc).
|
|
380
|
+
The sidebar collapses behind a toggle button on small screens.
|
|
381
|
+
|
|
382
|
+
### Menus with submenus
|
|
383
|
+
|
|
384
|
+
```js
|
|
385
|
+
init({
|
|
386
|
+
menuItems: {
|
|
387
|
+
headerMenu: [
|
|
388
|
+
{ id: "menu-home", class: "menu-item", text: "", inner_text: "Home" },
|
|
389
|
+
{ id: "menu-more", class: "menu-item", text: "", inner_text: "More", children: [{ inner_text: "Reports" }, { inner_text: "Archive", disabled: true }] }
|
|
390
|
+
],
|
|
391
|
+
footerMenu: []
|
|
392
|
+
},
|
|
393
|
+
nav: name => router.navigate(`/${name.toLowerCase()}`) // called with the entry's inner_text
|
|
394
|
+
});
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
A submenu opens with a click, Enter, Space or the Down arrow, closes with Esc, a click outside or by choosing an entry,
|
|
398
|
+
and supports the arrow keys, Home and End. The same works in the footer menu.
|
|
399
|
+
|
|
400
|
+
### Menu component
|
|
401
|
+
|
|
402
|
+
`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.
|
|
403
|
+
|
|
404
|
+
```js
|
|
405
|
+
const menu = generateMenu({
|
|
406
|
+
parent: "header", // an element, an id or a selector
|
|
407
|
+
layout: "responsive", // "bar" | "bottom-tabs" | "responsive" (tabs at the bottom under 700px, groups open as sheets)
|
|
408
|
+
followHash: true, // the item whose href equals location.hash is the active one
|
|
409
|
+
onNavigate: (item, event) => console.log(item.id), // only when a person uses an item, never from select() or while building
|
|
410
|
+
items: [
|
|
411
|
+
{ id: "home", label: "Home", icon: "⌂", href: "#/" },
|
|
412
|
+
{ id: "inbox", label: "Inbox", href: "#/inbox", badge: 3, badgeLabel: "3 unread" },
|
|
413
|
+
{ id: "tools", label: "Tools", children: [
|
|
414
|
+
{ id: "export", label: "Export" },
|
|
415
|
+
{ id: "more", label: "More", children: [{ id: "csv", label: "CSV" }, { id: "json", label: "JSON" }] }
|
|
416
|
+
] },
|
|
417
|
+
{ id: "user", label: "Anna Kiss", avatar: { name: "Anna Kiss" }, align: "end", children: [{ id: "out", label: "Sign out" }] }
|
|
418
|
+
]
|
|
419
|
+
});
|
|
420
|
+
menu.select("inbox"); // marks the current page (class is-active, aria-current="page", has-active on the groups around it)
|
|
421
|
+
menu.setBadge("inbox", { text: 12, tone: "bad" }); // a count, text, or { text, tone: "info" | "ok" | "warn" | "bad" }; 0 / null removes it
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
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
|
|
425
|
+
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.
|
|
426
|
+
|
|
427
|
+
### Router
|
|
428
|
+
|
|
429
|
+
```js
|
|
430
|
+
const router = createRouter({
|
|
431
|
+
routes: {
|
|
432
|
+
"/": () => renderHome(),
|
|
433
|
+
"/users/:id": ({ params, query }) => renderUser(params.id),
|
|
434
|
+
"/admin": { handler: renderAdmin, title: "Admin" }
|
|
435
|
+
},
|
|
436
|
+
outlet: "wrapper", // emptied before every page
|
|
437
|
+
beforeEach: ({ path }) => path === "/admin" && !isLoggedIn() ? "/login" : undefined, // false cancels, a path redirects
|
|
438
|
+
notFound: () => renderNotFound()
|
|
439
|
+
});
|
|
440
|
+
router.start();
|
|
441
|
+
router.navigate("/users/5?tab=info");
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
Routes can carry the sign-in rules, so a page does not check them itself:
|
|
445
|
+
|
|
446
|
+
```js
|
|
447
|
+
const router = createRouter({
|
|
448
|
+
auth: auth.routerRules({ loginPath: "/login", homePath: "/", forbiddenPath: "/denied" }), // { isSignedIn, hasRole, ... }
|
|
449
|
+
focusContent: true, scrollTop: true, // after a page is shown: focus the outlet, scroll to the top
|
|
450
|
+
onShown: ctx => menu.select(ctx.path), // also onRender (before the page function) and router.onChange(listener)
|
|
451
|
+
routes: {
|
|
452
|
+
"/login": { handler: renderLogin, guestOnly: true }, // a signed-in person goes home
|
|
453
|
+
"/account": { handler: renderAccount, auth: true }, // not signed in: /login?next=%2Faccount
|
|
454
|
+
"/admin": { handler: renderAdmin, auth: true, roles: ["admin"] },
|
|
455
|
+
"/report": { handler: renderReport, guard: ctx => ctx.query.id ? undefined : "/reports" } // false stays, a path redirects
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
`mode: "history"` uses real paths instead of the hash, the server then has to answer every path with the page.
|
|
461
|
+
Pass `router.navigate` from your `nav` callback to route the menu clicks.
|
|
462
|
+
|
|
463
|
+
### Components
|
|
464
|
+
|
|
465
|
+
```js
|
|
466
|
+
const grid = generateGrid({ parent: "wrapper", columns: 3 }); // one column on small screens
|
|
467
|
+
generateStat({ parent: grid, label: "Revenue", value: "$12k", delta: 8.2 });
|
|
468
|
+
generateCard({ parent: grid, title: "Title", content: "Text or a Node", footer: "Footer", image: "a.jpg" });
|
|
469
|
+
generateBadge({ parent: "wrapper", text: "new", variant: "success", pill: true });
|
|
470
|
+
generateAvatar({ parent: "wrapper", name: "Ada Lovelace", src: "ada.png" }); // initials without a working image
|
|
471
|
+
generateTooltip(buttonElement, "Saves the form");
|
|
472
|
+
generateLink({ parent: "wrapper", text: "Docs", href: "https://example.com", external: true });
|
|
473
|
+
generateSection({ parent: "wrapper", title: "Section", level: 2, content: "..." });
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
`parent` is the id of an element or the element itself. String content is always inserted as text.
|
|
477
|
+
|
|
478
|
+
### Inputs
|
|
479
|
+
|
|
480
|
+
```js
|
|
481
|
+
generateAutocomplete({ parent: "wrapper", label: "Country", options: ["Hungary", "Italy"] });
|
|
482
|
+
generateAutocomplete({ parent: "wrapper", options: async query => fetchSuggestions(query), minChars: 2 }); // remote data
|
|
483
|
+
generateMultiSelect({ parent: "wrapper", options: [{ value: "h", text: "Hungary" }], value: ["h"] }); // getValue(): array
|
|
484
|
+
generateFileUpload({ parent: "wrapper", accept: ".png,.pdf", maxSize: 2 * 1024 * 1024, url: "/upload",
|
|
485
|
+
onProgress: (file, percent) => {}, onComplete: (file, response) => {}, onError: (file, error) => {} });
|
|
486
|
+
generateStepper({ parent: "wrapper", onFinish: () => {}, steps: [
|
|
487
|
+
{ title: "Account", content: () => buildStep1(), validate: () => valid || "Fix the errors" },
|
|
488
|
+
{ title: "Done", content: "Finished" }
|
|
489
|
+
] });
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
```js
|
|
493
|
+
generateDateRange({ parent: "wrapper", label: "Stay", from: "2026-06-01", min: "2026-01-01", onChange: ({ from, to }) => {} });
|
|
494
|
+
const editor = generateRichText({ parent: "wrapper", label: "Description", placeholder: "Write...", value: "<p>Hello</p>",
|
|
495
|
+
toolbar: ["bold", "italic", "|", "ul", "ol", "link"], onChange: html => {} });
|
|
496
|
+
editor.getValue(); // safe HTML, "" when empty
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
The date range uses the native date pickers; the end picker starts at the chosen start date and a reversed range typed by
|
|
500
|
+
hand is reported. The rich text editor produces a restricted set of HTML (paragraphs, headings, bold / italic / underline /
|
|
501
|
+
strike, lists, quotes, code, links). Everything else (scripts, styles, iframes, images, event attributes, `javascript:` and
|
|
502
|
+
`data:` links) is removed when the content is set, pasted, dropped and read, so the value is safe to store and show with
|
|
503
|
+
`innerHTML`; links get `rel="noopener noreferrer"`. Toolbar buttons: `bold`, `italic`, `underline`, `strike`, `h2`, `h3`,
|
|
504
|
+
`quote`, `ul`, `ol`, `link`, `unlink`, `clear`, `undo`, `redo`. The editor is built on `contenteditable` and
|
|
505
|
+
`document.execCommand`, which every browser still supports; sanitize on the server as well, as with any HTML you accept.
|
|
506
|
+
|
|
507
|
+
```js
|
|
508
|
+
generateDropZone({ parent: "wrapper", accept: "image/*", maxSize: 2 * 1024 * 1024, maxFiles: 3,
|
|
509
|
+
onDrop: files => {}, onReject: rejected => rejected.forEach(({ file, reason }) => {}) });
|
|
510
|
+
const wysiwyg = generateWysiwyg({ parent: "wrapper", label: "Body", value: "<p>Hello</p>" }); // rich text + HTML source view
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
`generateDropZone` is a bare drag-and-drop area (also reachable with Enter / Space and the file dialog). Dropped files are
|
|
514
|
+
checked against `accept`, `maxSize` and `maxFiles`; valid ones go to `onDrop`, the others to `onReject` with a reason. It
|
|
515
|
+
reads and sends nothing, and `setDisabled(true)` turns it off. `generateWysiwyg` is the rich text editor plus a `source`
|
|
516
|
+
toolbar button that shows the sanitized HTML; what is typed there is sanitized again when you switch back.
|
|
517
|
+
|
|
518
|
+
Files are sent as a multipart POST (`fieldName`, `headers` are configurable). Without `url` the files are only collected,
|
|
519
|
+
read them with `getFiles()`.
|
|
520
|
+
|
|
521
|
+
### Session
|
|
522
|
+
|
|
523
|
+
```js
|
|
524
|
+
login: async ({ username, password, remember }) => {
|
|
525
|
+
const user = await api.login(username, password);
|
|
526
|
+
setSession({ user, token: user.token, remember }); // a session cookie, or `session_days` days when remembered
|
|
527
|
+
router.navigate("/");
|
|
528
|
+
}
|
|
529
|
+
isLoggedIn(); getSession(); logout();
|
|
530
|
+
onSessionChange(session => updateMenu(session));
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
The session lives in a cookie written from script, so any script of the page can read it. Keep only what the UI needs in it
|
|
534
|
+
and let the server enforce authorization; a server set `HttpOnly` cookie is the safer place for real credentials.
|
|
535
|
+
|
|
536
|
+
### Translations
|
|
537
|
+
|
|
538
|
+
```js
|
|
539
|
+
init({ config: { locale: "hu" } }); // English and Hungarian are included
|
|
540
|
+
setLocale("en"); // switch at runtime, texts of new components follow
|
|
541
|
+
addMessages("de", { login: "Anmelden", "validation.required": "Pflichtfeld" });
|
|
542
|
+
translate("login");
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
Missing texts fall back to English. See `src/libs/core/i18n.js` for all keys.
|
|
546
|
+
|
|
547
|
+
### Usage from classic scripts
|
|
548
|
+
|
|
549
|
+
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`
|
|
550
|
+
(and as `AthenaUI`):
|
|
551
|
+
|
|
552
|
+
```html
|
|
553
|
+
<script type="module" src="node_modules/athena-ui-js/src/classic.js"></script>
|
|
554
|
+
<script type="module">
|
|
555
|
+
init({ theme: { id: 0 } }); // globals: init, generateTable, AthenaUI, HTMLControlGenerator, ...
|
|
556
|
+
</script>
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
The global `appConfig`, `menuItems`, `nav`, `login`, `register` and `lostPassword` are used when the matching `init` option is not given.
|
|
560
|
+
|
|
561
|
+
### Signing in (recommended)
|
|
562
|
+
|
|
563
|
+
`generateSignInForm`, `generateSignUpForm`, `generatePasswordResetForm` and `generatePasswordChangeForm` are real `<form>` elements with the autocomplete tokens
|
|
564
|
+
that password managers look for (`username`, `current-password`, `new-password`, `email`), so Enter submits and the browser can save and fill passwords.
|
|
565
|
+
|
|
566
|
+
```js
|
|
567
|
+
const auth = createAuthState({ restore: () => fetch("/api/me", { credentials: "same-origin" }).then(r => (r.ok ? r.json() : null)) });
|
|
568
|
+
await auth.restore(); // after a reload: ask the server who is signed in
|
|
569
|
+
|
|
570
|
+
generateSignInForm({
|
|
571
|
+
parent: "wrapper", remember: true,
|
|
572
|
+
onSubmit: async ({ username, password, remember }) => {
|
|
573
|
+
const response = await fetch("/api/login", { method: "POST", body: JSON.stringify({ username, password, remember }), credentials: "same-origin" });
|
|
574
|
+
if (!response.ok) throw new Error("Wrong user name or password"); // shown in the form, which stays usable
|
|
575
|
+
auth.signIn(await response.json()); // { name, roles: [...] }
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
```
|
|
579
|
+
|
|
580
|
+
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.
|
|
581
|
+
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).
|
|
582
|
+
`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,
|
|
583
|
+
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.
|
|
584
|
+
|
|
585
|
+
## Themes
|
|
586
|
+
|
|
587
|
+
A theme is a single stylesheet. Register it in `src/res/themes/themes.js` and select it with
|
|
588
|
+
`theme: { id }`, or pass any stylesheet directly with `theme: { href: "css/my-theme.css" }`.
|
|
589
|
+
The default theme is in `src/res/themes/default/style.css`; `{ id: 1 }` is a dark theme. All colors are CSS variables
|
|
590
|
+
(`--athena-bg`, `--athena-fg`, `--athena-accent`, ...), so a custom theme can import the default one and override them:
|
|
591
|
+
|
|
592
|
+
```css
|
|
593
|
+
@import url("athena-ui/src/res/themes/default/style.css");
|
|
594
|
+
:root { --athena-accent: #8e44ad; }
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
Switch themes at runtime with `setTheme({ id: 1 })`.
|
|
598
|
+
|
|
599
|
+
### Styling: the cascade layer, tokens and dark mode
|
|
600
|
+
|
|
601
|
+
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
|
|
602
|
+
`.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
|
|
603
|
+
restyle everything at once:
|
|
604
|
+
|
|
605
|
+
```css
|
|
606
|
+
:root { --athena-accent: #8e44ad; --athena-radius: 2px; --athena-space-2: 6px; --athena-dialog-medium: 560px; }
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
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
|
|
610
|
+
`"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`).
|
|
611
|
+
|
|
612
|
+
### Themes and modes (light / dark / like the system)
|
|
613
|
+
|
|
614
|
+
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:
|
|
615
|
+
|
|
616
|
+
```html
|
|
617
|
+
<link rel="stylesheet" href="athena-ui/src/res/themes/default/style.css">
|
|
618
|
+
<link rel="stylesheet" href="athena-ui/src/res/themes/appearance.css">
|
|
619
|
+
<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 -->
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
```js
|
|
623
|
+
const manager = createThemeManager({ themes: [{ id: "athena", name: "Athena" }, { id: "contrast", name: "High contrast" }], storageKey: "myapp.appearance",
|
|
624
|
+
themeColorVariable: "--athena-bg" }); // <meta name="theme-color"> follows this variable
|
|
625
|
+
manager.setTheme("contrast"); manager.setMode("dark"); // "system" | "light" | "dark"; saved in localStorage, other tabs follow
|
|
626
|
+
manager.onChange(({ theme, mode, dark }) => redrawChartsOrWhatever());
|
|
627
|
+
generateThemePicker({ parent: "account-page", manager }); // radio groups with a small preview of every theme
|
|
628
|
+
```
|
|
629
|
+
|
|
630
|
+
**The contract of a theme** (also at the top of `appearance.css`): a theme is a pair of CSS blocks that set the tokens
|
|
631
|
+
`--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`:
|
|
632
|
+
|
|
633
|
+
```css
|
|
634
|
+
[data-theme="ocean"][data-mode="light"] { --athena-bg: #f4f9fb; /* ... */ }
|
|
635
|
+
[data-theme="ocean"][data-mode="dark"] { --athena-bg: #0b1c24; /* ... */ }
|
|
636
|
+
```
|
|
637
|
+
|
|
638
|
+
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`.
|
|
639
|
+
Athena and High contrast (light and dark) are included; without the script the page follows the system.
|
|
640
|
+
|
|
641
|
+
### Date and time range
|
|
642
|
+
|
|
643
|
+
```js
|
|
644
|
+
const range = generateDateTimeRange({ parent: "wrapper", label: "Time", preset: "24h", onChange: ({ from, to, preset }) => reload() });
|
|
645
|
+
range.getRange(); // { from: Date, to: Date }. A preset ("15m", "1h", "24h", "7d", "30d") is measured from NOW when this is called
|
|
646
|
+
range.getValue(); // { from: "2026-11-19T08:00", to: "...", preset: "24h" }, the values of the inputs
|
|
647
|
+
```
|
|
648
|
+
|
|
649
|
+
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.
|
|
650
|
+
`toLocalInput(date)` and `fromLocalInput(value)` convert between a Date and the value of such an input.
|
|
651
|
+
|
|
652
|
+
### Page parts and formatting
|
|
653
|
+
|
|
654
|
+
```js
|
|
655
|
+
generatePageHeader({ parent: "wrapper", title: "Hosts", description: "All monitored machines", breadcrumbs: [{ label: "Home", href: "#/" }, { label: "Hosts" }], actions: [addButton] });
|
|
656
|
+
generateFacts({ parent: "wrapper", items: [{ term: "System", description: "Linux" }, { term: "Seen", description: formatRelativeTime(host.lastSeen) }] });
|
|
657
|
+
generateEmptyState({ parent: "wrapper", title: "No hosts yet", message: "Install the agent.", action: { text: "Add host", onclick: add } });
|
|
658
|
+
generateLoading({ parent: "wrapper" }); // spinner + text, a live region
|
|
659
|
+
generateStat({ parent: "wrapper", label: "CPU", value: "91 %", tone: "bad", note: "of 4 cores" }); // tone: "ok" | "warn" | "bad" (colour + a word for screen readers)
|
|
660
|
+
await copyToClipboard(token); // and says "Copied" in a toast
|
|
661
|
+
formatBytes(1536); formatNumber(1234567.891); formatDuration(7500000); formatRelativeTime(date); formatDate(date, { time: true }); // Intl, in the current language
|
|
662
|
+
```
|
|
663
|
+
|
|
664
|
+
### Motion: animations and transitions
|
|
665
|
+
|
|
666
|
+
Motion is an enhancement. Every transition and animation of Athena UI reads the tokens `--athena-duration-fast` (120 ms), `--athena-duration-base` (200 ms) and `--athena-duration-slow` (360 ms),
|
|
667
|
+
and `--athena-ease-standard`, `-in`, `-out` and `-spring`, so one variable slows down or switches off all of it. They are **0 under reduced motion**: when the system asks for it
|
|
668
|
+
(`prefers-reduced-motion`), or the person does (`data-motion="reduce"` on `<html>`, which `setMotion("reduce")` sets; `"full"` keeps the motion although the system asks for less).
|
|
669
|
+
Nothing waits for a transition before it works, and nothing needs an inline style (a strict Content-Security-Policy is fine: CSS classes, custom properties and the Web Animations API).
|
|
670
|
+
|
|
671
|
+
What the components do by themselves:
|
|
672
|
+
- a **dialog** fades and rises in and fades out; the **dropdown menu** and the **tooltip** fade; a **toast** slides in and out; an **accordion** opens smoothly;
|
|
673
|
+
a **progress bar** moves smoothly; a **skeleton** (`generateSkeleton`) shimmers;
|
|
674
|
+
- a **chart** draws itself the first time (bars grow, the line is drawn, slices pop in; `animate: false` turns it off, and it never replays while streaming or zooming);
|
|
675
|
+
- the **theme manager** cross-fades colours when the theme or the mode changes (`createThemeManager({ transition: false })` turns it off);
|
|
676
|
+
- a **table** with `animateRows: true` slides its rows to their new place when sorted, filtered or paged (at most 60 rows, not in a virtual table);
|
|
677
|
+
- the **router** with `transition: true` makes a page change a view transition (`document.startViewTransition`): the old page cross-fades into the new one, and elements with a
|
|
678
|
+
`view-transition-name` move from one page to the next. The old page stays until the page function of the new one has finished, so a page that needs long should draw something first.
|
|
679
|
+
|
|
680
|
+
`athena-ui-js/motion` has the same tools for your own code; all of them resolve at once under reduced motion:
|
|
681
|
+
|
|
682
|
+
```js
|
|
683
|
+
import { animate, flip, stagger, spring, tween, easings, transition, viewTransition, setMotion, prefersReducedMotion } from "athena-ui-js/motion";
|
|
684
|
+
|
|
685
|
+
await animate(card, [{ opacity: 0, translate: "0 16px" }, { opacity: 1, translate: "0 0" }]); // the Web Animations API, with the tokens as defaults; resolves at the end
|
|
686
|
+
await flip(list, () => list.append(...sorted)); // rows slide from where they were to where they are; new ones fade in
|
|
687
|
+
await stagger(items, (item, index, delay) => animate(item, frames, { delay }), { step: 40 }); // one after the other
|
|
688
|
+
const { easing, duration } = spring({ stiffness: 220, damping: 12 }); // a spring as a CSS easing (linear()), it overshoots
|
|
689
|
+
await animate(ball, [{ translate: "0 0" }, { translate: "240px 0" }], { easing, duration });
|
|
690
|
+
tween({ from: 0, to: 100, duration: 600, easing: easings.easeOutCubic, onUpdate: value => counter.textContent = Math.round(value) }); // numbers over time (games, counters)
|
|
691
|
+
await transition(panel, () => panel.classList.add("open")); // a change made with CSS: resolves when its transition is over
|
|
692
|
+
await viewTransition(() => swapContent()); // cross-fades the change where the browser can
|
|
693
|
+
setMotion("reduce"); // "system" | "reduce" | "full"
|
|
694
|
+
```
|
|
695
|
+
|
|
696
|
+
In a page that is not drawn (a hidden tab) there are no frames: `animate` and `tween` finish by a timer, so nothing hangs. Dialogs and toasts stay in the page for the length of their
|
|
697
|
+
exit transition (none under reduced motion); in your tests call `setMotion("reduce")` first, so they are gone at once.
|
|
698
|
+
|
|
699
|
+
### Widgets: a dashboard that can be built
|
|
700
|
+
|
|
701
|
+
`athena-ui-js/widgets`: a grid of widgets that can be added, configured, moved, resized, locked, saved and loaded. No dependency, no drag library, no inline style.
|
|
702
|
+
|
|
703
|
+
```js
|
|
704
|
+
import { registerWidget, createWidgetGrid } from "athena-ui-js/widgets";
|
|
705
|
+
|
|
706
|
+
// a type of widget: a function that draws into the body it is given, and cleans up after itself
|
|
707
|
+
registerWidget("clock", {
|
|
708
|
+
title: "Clock", defaultSize: { w: 3, h: 2 }, minSize: { w: 2, h: 1 }, defaultConfig: { seconds: true },
|
|
709
|
+
configForm: [{ name: "seconds", label: "Show seconds", type: "checkbox" }], // the settings dialog (showFormDialog)
|
|
710
|
+
render(context) { // called when the widget is first seen (IntersectionObserver)
|
|
711
|
+
const time = el("p");
|
|
712
|
+
context.element.append(time);
|
|
713
|
+
const show = () => time.textContent = new Date().toLocaleTimeString();
|
|
714
|
+
const timer = setInterval(show, 1000);
|
|
715
|
+
return { update: show, destroy: () => clearInterval(timer) }; // update(): config or title changed (throttled), destroy(): removed
|
|
716
|
+
}
|
|
717
|
+
});
|
|
718
|
+
|
|
719
|
+
const grid = createWidgetGrid({
|
|
720
|
+
element: "dashboard", columns: 12, rowHeight: 80, gap: 12, editable: true,
|
|
721
|
+
breakpoints: { wide: { minWidth: 900, columns: 12 }, narrow: { minWidth: 0, columns: 6 } }, // optional: a layout per width
|
|
722
|
+
widgets: [{ type: "clock", x: 0, y: 0 }],
|
|
723
|
+
onChange: (layout, reason) => localStorage.setItem("dashboard", JSON.stringify(layout)) // "move", "resize", "add", "remove", "settings", "undo", ...
|
|
724
|
+
});
|
|
725
|
+
grid.setLayout(JSON.parse(localStorage.getItem("dashboard"))); // plain, versioned JSON ({ version: 1, widgets: [...] })
|
|
726
|
+
```
|
|
727
|
+
|
|
728
|
+
- **Layout** is CSS grid. The columns, the row height, the gap and the place of every widget are CSS classes written into a constructed style sheet, so a strict
|
|
729
|
+
Content-Security-Policy (no `style` attribute) is fine. Widgets fall upwards (`compact: false` keeps the gaps) and slide to their new places (not under reduced motion).
|
|
730
|
+
- **Edit mode** (`setEditable(true)`): drag by the handle, resize by any edge or corner, snap to cells, push other widgets out of the way. Settings, duplicate and remove buttons.
|
|
731
|
+
A **locked** widget (`lockWidget(id)`) is not moved, not resized, not pushed, and nothing can be put on it.
|
|
732
|
+
- **Keyboard**: focus the handle, Space or Enter picks the widget up, arrow keys move it, Shift with arrow keys resizes it, Enter drops it, Escape cancels. Every step is announced
|
|
733
|
+
in a live region ("Column 2, row 1, 3 wide, 2 high"). Pointer Events: mouse, pen and touch work the same.
|
|
734
|
+
- **Undo and redo** of every change (`undo()`, `redo()`, `canUndo()`); `updateWidget(id, { config })` is for data from code and is not an undo step.
|
|
735
|
+
- **Layouts** (`getLayout()` / `setLayout(json)`) are plain JSON and the application decides where they are stored. Loading is checked: a bad entry is skipped (reported in the result),
|
|
736
|
+
duplicate ids are replaced, places are clamped and made free of overlaps, `__proto__`-style keys are dropped, and a type that is not registered is shown as a placeholder (its data is kept, nothing is executed).
|
|
737
|
+
- **Performance**: a widget is rendered only when it is first seen, `resize(context, size)` is called throttled when its body changes size, and nothing re-renders while it is out of view.
|
|
738
|
+
- The grid maths (`placeItem`, `compact`, `findFreeSpot`, `normalize`, `collides`) is exported as well, for your own layouts.
|
|
739
|
+
|
|
740
|
+
### Code: highlighting, an editor and a diff
|
|
741
|
+
|
|
742
|
+
`athena-ui-js/code`: no dependency, no inline style, and nothing is parsed as markup (the code is built with `el()`, so a `<img onerror>` in a comment stays text).
|
|
743
|
+
|
|
744
|
+
```js
|
|
745
|
+
import { highlightCode, generateCodeBlock, createCodeEditor, createDiffView, registerLanguage } from "athena-ui-js/code";
|
|
746
|
+
|
|
747
|
+
// read only
|
|
748
|
+
document.body.append(highlightCode("const a = 1;", "js", { lineNumbers: true, highlightLines: [1] })); // a <pre><code> with token spans
|
|
749
|
+
generateCodeBlock({ parent: "docs", code: sql, language: "sql", lineNumbers: true }); // + the language label and a copy button
|
|
750
|
+
|
|
751
|
+
// an editor
|
|
752
|
+
const editor = createCodeEditor({
|
|
753
|
+
element: "editor", value: source, language: "ts", onChange: value => save(value),
|
|
754
|
+
markers: [{ line: 3, message: "Unexpected token", level: "error" }], // lint markers, shown in the status line
|
|
755
|
+
readOnlyRanges: [{ from: 1, to: 2 }], // lines that cannot be changed
|
|
756
|
+
provideCompletions: ({ prefix }) => words.filter(word => word.startsWith(prefix)).map(label => ({ label }))
|
|
757
|
+
});
|
|
758
|
+
|
|
759
|
+
// what changed
|
|
760
|
+
createDiffView({ parent: "review", original: before, modified: after, language: "json", mode: "split", context: 3 });
|
|
761
|
+
```
|
|
762
|
+
|
|
763
|
+
- **Languages**: `javascript` (`js`), `typescript` (`ts`), `json`, `html` (`xml`, `svg`), `css` (`scss`, `less`), `sql`, `shell` (`sh`, `bash`), `yaml`, `csharp` (`c#`, `cs`), `python` (`py`).
|
|
764
|
+
A language is a plain object (`registerLanguage({ name, aliases, rules: [{ type, pattern }], lineComment, blockComment, pairs, indentAfter })`), so your own are one call.
|
|
765
|
+
The tokenizer is a set of regular expressions, not a parser: it is fast and tolerant (unfinished code still gets colours) but it does not know nested `${}` of a template string or the `<script>` inside HTML.
|
|
766
|
+
- **Colours** are the tokens `--athena-tok-comment`, `-string`, `-keyword` ... (light and dark); a test keeps every one at 4.5:1 contrast or more.
|
|
767
|
+
- **The editor is a real `<textarea>`** with the highlighted text behind it, so native input, selection, spell-check off, mobile keyboards, IME and screen readers all work.
|
|
768
|
+
Tab and Shift+Tab indent and outdent (also several lines), Enter keeps the indentation (and goes one level deeper after `{`, `(`, `:`), brackets and quotes are closed, stepped over, wrapped around a selection and
|
|
769
|
+
deleted together, Ctrl+/ comments, Alt+Up / Alt+Down move lines, Ctrl+Z / Ctrl+Y undo and redo (typing is grouped), Ctrl+F finds and Ctrl+H replaces (case, regular expression, all matches
|
|
770
|
+
highlighted, replace all is one undo step), Ctrl+Space suggests. The matching bracket is highlighted (CSS Custom Highlight API where the browser has it).
|
|
771
|
+
**Escape, then Tab, leaves the editor** (so the keyboard is never trapped); the way out is read to screen readers.
|
|
772
|
+
- **Size**: only the lines around a change are tokenized again, and a test checks that this gives exactly what tokenizing everything gives. On the (slow) development machine the work of the editor per key press is
|
|
773
|
+
about 13 ms in a 5,000 line file; the browser's own layout of two large text blocks is the larger part (about 90 ms per key at 5,000 lines; smaller files were not measured separately). Texts longer than 300,000 characters
|
|
774
|
+
(`maxHighlightLength`) are shown without highlighting. Not there yet: multiple cursors, minimap, folding.
|
|
775
|
+
|
|
776
|
+
### Safe DOM building
|
|
777
|
+
|
|
778
|
+
`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
|
|
779
|
+
nested lists, listeners have to be functions, and `on*` attributes, `style` and `srcdoc`, unsafe addresses (`javascript:`, `data:`) in `href` / `src` / `action`, and properties that
|
|
780
|
+
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
|
|
781
|
+
do not control (a plugin API).
|
|
782
|
+
|
|
783
|
+
### Moved into Athena: HTMLElementGenerator and HTMLControlGenerator
|
|
784
|
+
|
|
785
|
+
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
|
|
786
|
+
`src/libs/core/elementGenerator.js`, `HTMLControlGenerator(options)` / `.create()` / `.register()` in `src/libs/core/controls.js`; both are exported and global as before.
|
|
787
|
+
`HTMLControlGenerator` has no jQuery in it: `create` returns the element (wrap it yourself with `$(...)` if you still need a jQuery object).
|
|
788
|
+
`registerHungarianInputControls()` adds the `hunPIN`, `hunCRID` and `hunTID` input types of its old addon. The old repositories are no longer developed.
|
|
789
|
+
|
|
790
|
+
### Parents and handles
|
|
791
|
+
|
|
792
|
+
Every `parent` option takes an element, an id or a CSS selector (`"wrapper"`, `"#list"`, `".panel > ul"`; an id wins over a selector).
|
|
793
|
+
The components return the same kind of handle: `{ element, update(), destroy() }`, plus their own methods. `destroy()` removes the
|
|
794
|
+
component. `update()` redraws it where that makes sense (`table.update({ rows })`, `chart.update({ series })`, `stat.update({ value })`,
|
|
795
|
+
`progress.update({ value })`) and otherwise just returns the handle. `generateChart` still returns the SVG element, which also carries
|
|
796
|
+
`element`, `update(options)` and `destroy()`.
|
|
797
|
+
|
|
798
|
+
### Testing your application
|
|
799
|
+
|
|
800
|
+
```js
|
|
801
|
+
import { JSDOM } from "jsdom";
|
|
802
|
+
import { installDom, until, tick } from "athena-ui-js/testing";
|
|
803
|
+
|
|
804
|
+
const dom = installDom(JSDOM); // window, document, Node, Event, ... become global
|
|
805
|
+
generateDropdown({ parent: "#wrapper", icon: "x", ariaLabel: "More", items: [] });
|
|
806
|
+
await until(() => document.querySelector(".dropdown"), { message: "the dropdown" });
|
|
807
|
+
dom.uninstall();
|
|
808
|
+
```
|
|
809
|
+
|
|
810
|
+
`installDom` takes your own `JSDOM` class, so Athena UI has no dependency on jsdom. Athena creates its events from the element's own
|
|
811
|
+
window, so they work in jsdom without a global `Event`.
|
|
812
|
+
|
|
813
|
+
## Tests
|
|
814
|
+
|
|
815
|
+
```sh
|
|
816
|
+
npm test # unit tests of the pure modules, run in Node
|
|
817
|
+
npm run test:browser # the components in headless Chrome
|
|
818
|
+
```
|
|
819
|
+
|
|
820
|
+
The unit tests cover validation, translations, router matching, CSV, pagination, formatting, virtual scrolling math, date ranges and the URL check.
|
|
821
|
+
The browser tests start a small static server, open `tests/browser/index.html` in headless Chrome, Chromium or Edge and run every
|
|
822
|
+
component: forms, dialogs, navigation, submenus, inputs, rich text (sanitizing, toolbar, paste), tables (resizing, virtual scrolling), router,
|
|
823
|
+
session, themes. Set `CHROME_PATH` if the browser is not found. `DEBUG=1` prints the browser log when the page does not report results.
|
|
824
|
+
|
|
825
|
+
- **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
|
|
826
|
+
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 reports Chrome
|
|
827
|
+
makes while it parses an inline handler, a style attribute or a `<style>` element in an inert document.)
|
|
828
|
+
- One test feeds markup to about 40 components and checks that text from data stays text.
|
|
829
|
+
- `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).
|
|
830
|
+
- 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).
|
|
831
|
+
|
|
832
|
+
## Project structure
|
|
833
|
+
|
|
834
|
+
```
|
|
835
|
+
src/
|
|
836
|
+
athena-ui.js the whole API as ES module exports (no side effects)
|
|
837
|
+
classic.js opt-in: the whole API on window, for classic scripts
|
|
838
|
+
table.js, dialog.js, ... one entry point per component (athena-ui-js/table, athena-ui-js/dialog, ...)
|
|
839
|
+
theme-boot.js classic script that sets the saved theme and mode before the page is drawn
|
|
840
|
+
testing.js installDom, until, tick for the tests of an application
|
|
841
|
+
index.html, example.js example page
|
|
842
|
+
libs/
|
|
843
|
+
config/ default configuration, application hooks
|
|
844
|
+
core/ DOM / focus helpers, el, validation, translations, CSV, formatting, sanitizer, cookies, theme manager,
|
|
845
|
+
HTMLElementGenerator, HTMLControlGenerator, table math
|
|
846
|
+
hephaestus/ theme loader, generators (layout, menus, forms, charts, tables, feedback, dialogs, navigation,
|
|
847
|
+
components, inputs), router, session, auth state
|
|
848
|
+
res/themes/ tokens.css, default and dark theme, appearance.css (themes and modes)
|
|
849
|
+
types/ TypeScript definitions (npm run types)
|
|
850
|
+
docs/ styling.md (generated), migration-2.0.md
|
|
851
|
+
demo/ the demo and test application (server, API, pages, end to end tests), deployed to Azure by GitHub Actions
|
|
852
|
+
.github/workflows/ ci.yml (tests) and demo-deploy.yml
|
|
853
|
+
tests/ unit tests (Node) and browser tests (headless Chrome, strict CSP)
|
|
854
|
+
```
|
|
855
|
+
|
|
856
|
+
## Authors
|
|
857
|
+
|
|
858
|
+
* **Csaba Tóth** - *Initial work* - [csabatibortoth](https://github.com/csabatibortoth)
|
|
859
|
+
|
|
860
|
+
## License
|
|
861
|
+
|
|
862
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
|
|
863
|
+
|
|
864
|
+
## Releases
|
|
865
|
+
|
|
866
|
+
### 2.5.1
|
|
867
|
+
#### Changed:
|
|
868
|
+
1. The `files` list of package.json is `src` (with `example.js` and `index.html` left out) instead of a list of folders: a new folder under `src` can no longer be forgotten, which is what broke 2.3.0 and 2.4.0. The package holds exactly the same files as 2.5.0
|
|
869
|
+
#### Added:
|
|
870
|
+
1. `npm run smoke:package` (`scripts/smoke-package.mjs`): packs the library, installs the tarball in an empty folder and imports all 26 entry points of the `exports` map the way an application does; it runs in CI after `check:package`
|
|
871
|
+
|
|
872
|
+
### 2.5.0
|
|
873
|
+
(what the user interface of Odin NS Manager asked for when it moved onto Athena UI 2.x)
|
|
874
|
+
#### Added:
|
|
875
|
+
1. Charts: `gaps` (a missing value breaks the line, a lone point is a dot), `timeRange` (the range of the time axis when it is not the one the data covers), `format` (how a value is written on the axis, in the tooltips and in the table of values), `tickFormat` (the axis only), `margin` (room around the plot) and `responsive` (as wide as the parent, following it)
|
|
876
|
+
2. Tables: the `render` of a column (an element in a cell) is documented, and every cell has `data-label` with the label of its column, so a stylesheet can show a row as a block on a narrow screen
|
|
877
|
+
3. Forms: a field can have `show: (values) => boolean` (a field that is not shown is not validated and not in the values), `label: (values) => string`, `send: false`, `trim` and `empty: "omit" | "null" | "empty"`; the form has `nested` (a field called `soa.host` is `values.soa.host`), `getRawValues()` and `arrange()`; a rejection of `onSubmit` with `details` ({ field: message }) puts the messages at their fields; `field.setLabel(text)`
|
|
878
|
+
4. `showFormDialog` focuses the first field that is shown
|
|
879
|
+
|
|
880
|
+
### 2.4.1
|
|
881
|
+
#### Fixed:
|
|
882
|
+
1. **2.3.0 and 2.4.0 were published without two folders** (`src/libs/hephaestus/widgetGrid` and `.../codeGenerator`): `import "athena-ui-js"`, `athena-ui-js/widgets` and `athena-ui-js/code` failed with "module not found". Both folders are in the package now. **Use 2.4.1 or later**; 2.3.0 and 2.4.0 should be deprecated.
|
|
883
|
+
#### Added:
|
|
884
|
+
1. `npm run check:package` (`scripts/check-package.mjs`): reads what `npm pack --dry-run` would publish and follows the imports of every entry point through that list; it runs in CI and in `npm test`, so a folder that is not on the `files` list fails the build instead of the users
|
|
885
|
+
|
|
886
|
+
### 2.4.0
|
|
887
|
+
#### Added:
|
|
888
|
+
1. `athena-ui-js/code`: `highlightCode`, `generateCodeBlock` (language label, copy button), `createDiffView`, `createCodeEditor` (a textarea over highlighted lines: indentation, closing brackets, comments, find and replace, completions, markers, read-only lines, own undo), ten languages and `registerLanguage`; token colours are theme tokens with a contrast test
|
|
889
|
+
2. The Code page of the demo
|
|
890
|
+
|
|
891
|
+
### 2.3.0
|
|
892
|
+
#### Added:
|
|
893
|
+
1. `athena-ui-js/widgets`: `registerWidget` and `createWidgetGrid`: a dashboard of widgets that can be added, configured, moved and resized with the pointer or the keyboard, locked, undone, saved and loaded as validated JSON, with a layout per breakpoint
|
|
894
|
+
2. The grid maths (`placeItem`, `compact`, `findFreeSpot`, `normalize`) as exports, and the Widgets page of the demo
|
|
895
|
+
|
|
896
|
+
### 2.2.0
|
|
897
|
+
#### Added:
|
|
898
|
+
1. Motion: the tokens `--athena-duration-*` and `--athena-ease-*` (0 under reduced motion), `athena-ui-js/motion` (`animate`, `flip`, `stagger`, `spring`, `tween`, `viewTransition`, `setMotion`), transitions of dialogs, toasts, popovers, the accordion and the menu, the first drawing of charts, a cross-fade of theme changes, `createRouter({ transition: true })`, `generateTable({ animateRows: true })` and `generateSkeleton`
|
|
899
|
+
#### Changed:
|
|
900
|
+
1. The blanket `transition: none` under reduced motion is gone: the durations are 0 instead; a closed dialog or toast stays in the page for the length of its exit transition (none under reduced motion)
|
|
901
|
+
|
|
902
|
+
### 2.1.0
|
|
903
|
+
#### Changed:
|
|
904
|
+
1. The dropdown menu is a native popover (`popover="auto"`, opened by its button through `popovertarget`): it is drawn in the top layer, so no parent with `overflow: hidden` cuts it off; a click outside and Esc close it and the focus goes back to the button; `aria-expanded` follows every way of opening and closing it. Markup: the menu has the attribute `popover` and no `hidden` any more (use `:popover-open`)
|
|
905
|
+
2. The tooltip is a native popover (`popover="manual"`): shown on hover and on keyboard focus, hidden on leave, blur and Esc, never shown by a touch, and never cut off by a parent
|
|
906
|
+
3. Both are placed next to their button by a small helper that sets two CSS variables (`--athena-popover-left`, `--athena-popover-top`; allowed by a strict Content-Security-Policy): below, or above when there is no room below, centred or aligned to an edge, and always kept inside the window; they follow the button when the page scrolls or resizes
|
|
907
|
+
4. Browsers without the popover API keep the previous behaviour (a plain menu shown with `hidden` and closed by a click outside, a CSS tooltip)
|
|
908
|
+
#### Added:
|
|
909
|
+
1. `src/libs/core/popover.js` (placement helpers) and the CSS class `.athena-popover`
|
|
910
|
+
2. The address of the live demo in the READMEs
|
|
911
|
+
3. Section 3 ("Make it lighter") of the to-do list is complete: the native elements are `<dialog>`, `<details>` and the popover
|
|
912
|
+
|
|
913
|
+
### 2.0.1
|
|
914
|
+
#### Added:
|
|
915
|
+
1. `demo/`: a demo and test application of Athena UI (tables with 100,000 rows from a server, streaming charts, forms, dialogs, menus, themes, sign in) with a dependency free Node server, and end to end tests that drive a real browser (DevTools protocol) under a strict Content-Security-Policy
|
|
916
|
+
2. GitHub Actions: `ci.yml` (unit, browser and demo tests on every push and pull request) and `demo-deploy.yml` (tests, builds `demo/dist`, deploys to an Azure App Service, checks the site)
|
|
917
|
+
#### Fixed (found by the end to end tests of the demo):
|
|
918
|
+
1. A chart that redraws (streaming `push`, zoom) no longer loses the keyboard focus: it moves to the same place in the new SVG
|
|
919
|
+
2. The series a person hid with the legend stay hidden when the chart redraws (`hiddenSeries` option)
|
|
920
|
+
#### Changed:
|
|
921
|
+
1. `package-lock.json` is part of the repository (CI uses `npm ci`)
|
|
922
|
+
|
|
923
|
+
### 2.0.0
|
|
924
|
+
#### Breaking (see [docs/migration-2.0.md](docs/migration-2.0.md)):
|
|
925
|
+
1. No default export, and nothing on `window` unless you import `athena-ui-js/classic`; `athena-ui.js` has no side effects
|
|
926
|
+
2. No jQuery anywhere (not a peer dependency any more); `HTMLControlGenerator.create` returns the element
|
|
927
|
+
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
|
|
928
|
+
4. Nothing is loaded at run time (`libs.js` and `loadLibs` are gone); `customLoader` still loads your own script
|
|
929
|
+
5. `showDialog` and the other dialogs use a native `<dialog>` (`showModal`), the accordion uses `<details>`: the markup and CSS classes changed
|
|
930
|
+
6. All default rules are in the cascade layer `athena`, and the default theme follows the system's dark mode
|
|
931
|
+
7. `package.json` has an `exports` map: deep imports of `src/libs/...` are not possible
|
|
932
|
+
#### Added:
|
|
933
|
+
1. One entry point per component (`athena-ui-js/table`, `/dialog`, `/menu`, ...), `"sideEffects"` for tree shaking
|
|
934
|
+
2. TypeScript definitions (`types/`, generated from the JSDoc)
|
|
935
|
+
3. `createApp({ root })`: the layout into any element
|
|
936
|
+
4. `tokens.css` (radius, spacing, border, focus ring, dialog widths, row height, colours), a built-in dark mode, `docs/styling.md`
|
|
937
|
+
5. Plural forms in messages (`Intl.PluralRules`), `{name:number}` and `{name:date}` in `translate`
|
|
938
|
+
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
|
|
939
|
+
7. `docs/migration-2.0.md`
|
|
940
|
+
|
|
941
|
+
### 1.3.0
|
|
942
|
+
#### Added:
|
|
943
|
+
1. Dialogs: `showFormDialog` (async save, errors stay in the dialog, `form.setErrors`) and `showConfirm` (`danger`, `typeToConfirm`)
|
|
944
|
+
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)
|
|
945
|
+
3. `generateMenu`: real links and buttons, groups of any depth, badges, avatar user menu, active item, bar / bottom tabs / responsive; `generateHeaderMenu({ items })`
|
|
946
|
+
4. Tables: `dataSource` (pages, cursor "Load more", loading / empty / error with Retry), `dataSource` together with `virtual`, `rowActions`, `reload()`
|
|
947
|
+
5. Charts: `area` and `sparkline`, time axis, tooltips, clickable legend, table of values, theme colours, zoom, long series thinning, `push()` for streaming
|
|
948
|
+
6. Router: `auth`, `guestOnly`, `roles`, `guard`, `onRender` / `onShown`, `focusContent`, `scrollTop`, `router.onChange`
|
|
949
|
+
7. `generateSignInForm`, `generateSignUpForm`, `generatePasswordResetForm`, `generatePasswordChangeForm`, `createAuthState`
|
|
950
|
+
8. `generateDateTimeRange` with presets, `generatePageHeader`, `generateFacts`, `generateEmptyState`, `generateLoading`, stat `tone` and `note`, `copyToClipboard`, format helpers
|
|
951
|
+
9. `el`, `setContent`, `resolveElement`, `asHandle` and `createSafeBuilder` are exported
|
|
952
|
+
10. HTMLElementGenerator and HTMLControlGenerator (and the Hungarian input addon) are part of Athena UI; no more submodules for them
|
|
953
|
+
#### Changed:
|
|
954
|
+
1. jQuery is optional: init() does not need it, the layout, modal, forms and menus use plain DOM, the browser tests run without it
|
|
955
|
+
2. Only crypto-js can still be loaded as a classic script, and only with `enable_encrypt_password`
|
|
956
|
+
3. `el()` refuses code attributes and unsafe addresses
|
|
957
|
+
#### Deprecated:
|
|
958
|
+
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
|
|
959
|
+
|
|
960
|
+
### 1.2.0
|
|
961
|
+
#### Added:
|
|
962
|
+
1. Dialogs: `size` and `class` options, and the open dialog (`element`, `backdrop`, `close()`) on the returned promise
|
|
963
|
+
2. Tables: `cellClass`, `rowClass`, `focusableRows` / `rowLabel`, `density`, `wrap`, column `render` (text or Node), `align`, tooltip for cut text
|
|
964
|
+
3. Dropdown: `icon`, `ariaLabel`, `caret`, `toggleClass`; the label is optional
|
|
965
|
+
4. Every `parent` option takes an element, an id or a CSS selector; the components share the handle `{ element, update(), destroy() }`
|
|
966
|
+
5. `athena-ui-js/testing`: `installDom`, `until`, `tick`
|
|
967
|
+
#### Changed:
|
|
968
|
+
1. The dialog backdrop is shown by a CSS class, not by an inline style (works with a strict Content-Security-Policy)
|
|
969
|
+
2. Virtual tables: a list that starts empty draws a full window, the window is measured again when the scroll area changes size, and the cell padding no longer loses against the application's `td` padding
|
|
970
|
+
3. The combobox creates its events from the element's own window (no more jsdom errors)
|
|
971
|
+
4. The pager of a table with one page is hidden
|
|
972
|
+
|
|
973
|
+
### 1.1.0
|
|
974
|
+
#### Added:
|
|
975
|
+
1. `generateDropZone` / `createDropZone`: drag-and-drop area with file type, size and count checks
|
|
976
|
+
2. `generateWysiwyg` / `createWysiwyg` and the `wysiwyg` form field: rich text editor with a sanitized HTML source view
|
|
977
|
+
#### Changed:
|
|
978
|
+
1. `generateFileUpload` is built on the drop zone; dragging over child elements no longer flickers
|
|
979
|
+
|
|
980
|
+
### 1.0.0
|
|
981
|
+
#### Added:
|
|
982
|
+
1. Stable public API (semantic versioning from this release on)
|
|
983
|
+
2. README: status, known limits and quick links
|
|
984
|
+
#### Changed:
|
|
985
|
+
1. Version bumped to 1.0.0, no breaking changes since 0.7.0
|
|
986
|
+
|
|
987
|
+
### 0.7.0
|
|
988
|
+
#### Added:
|
|
989
|
+
1. Menus with submenus: `children` on a menu item, with keyboard support
|
|
990
|
+
2. Tables: resizable columns (mouse and keyboard) and virtual scrolling (`virtual`) for thousands of rows
|
|
991
|
+
3. `generateDateRange` and the `daterange` form field
|
|
992
|
+
4. `generateRichText` / `createRichText` and the `richtext` form field, with an allow-list sanitizer (`sanitizeHtml`, `isSafeUrl`)
|
|
993
|
+
5. Browser tests in headless Chrome (`npm run test:browser`), more unit tests
|
|
994
|
+
#### Changed:
|
|
995
|
+
1. English and Hungarian texts for the new components
|
|
996
|
+
|
|
997
|
+
### 0.6.0
|
|
998
|
+
#### Added:
|
|
999
|
+
1. Form builder (`generateForm`, `generateField`, `generateButton`) with validation, textarea, select, radio / checkbox groups, switch, autocomplete and multi select
|
|
1000
|
+
2. Feedback: `showToast`, `generateAlert`, `generateSpinner`, `generateProgress`; dialogs: `alertDialog`, `confirmDialog`, `promptDialog`, `showDialog`
|
|
1001
|
+
3. Navigation: tabs, accordion, dropdown, sidebar, breadcrumbs, pagination; `createRouter`
|
|
1002
|
+
4. Components: card, grid, section, badge, avatar, stat, tooltip, link
|
|
1003
|
+
5. `generateFileUpload` with progress, `generateStepper`
|
|
1004
|
+
6. Tables: row selection, inline editing, CSV export
|
|
1005
|
+
7. Session handling, change password form, "Remember me" in the login form
|
|
1006
|
+
8. Dark theme, `setTheme`, CSS variables, responsive styles
|
|
1007
|
+
9. Translations (English, Hungarian), `translate`, `setLocale`, `addMessages`
|
|
1008
|
+
10. Unit tests (`npm test`)
|
|
1009
|
+
#### Changed:
|
|
1010
|
+
1. Modals trap the focus, close with Esc and restore the focus
|
|
1011
|
+
2. The texts of the forms and of the table go through `translate`; the registration form checks its fields with the shared validator
|
|
1012
|
+
3. `init` accepts the `changePassword` callback
|
|
1013
|
+
|
|
1014
|
+
### 0.5.0
|
|
1015
|
+
#### Added:
|
|
1016
|
+
1. `generateChart`: bar, line, pie and donut charts as inline SVG
|
|
1017
|
+
2. `generateTable`: sortable, filterable, paginated tables
|
|
1018
|
+
3. `generateRegistrationForm` and `generateLostPasswordForm`, with the `register` / `lostPassword` callbacks and the `registration_enabled` / `lost_password_enabled` settings
|
|
1019
|
+
4. Example page shows all of them
|
|
1020
|
+
|
|
1021
|
+
### 0.4.1
|
|
1022
|
+
#### Changed:
|
|
1023
|
+
1. HTMLControlGenerator v0.4.0, HTMLElementGenerator v0.3.0, js-cookie updated to the latest master
|
|
1024
|
+
2. HTMLElementGenerator is imported as an ES module instead of being loaded as a classic script
|
|
1025
|
+
3. crypto-js follows the `master` branch, which holds the built release files
|
|
1026
|
+
#### Added:
|
|
1027
|
+
1. `HTMLElementGenerator` is exported from `athena-ui.js` (and stays available as a global)
|
|
1028
|
+
#### Bugfix:
|
|
1029
|
+
1. The label of a menu item without an `id` is not appended to the page body
|
|
1030
|
+
|
|
1031
|
+
### 0.4.0
|
|
1032
|
+
#### Changed:
|
|
1033
|
+
1. Rewritten as ES modules (no more chained `$.getScript` loading, no implicit globals)
|
|
1034
|
+
2. JQuery v4.0.0, js-cookie v3.0.8, crypto-js v4.2.0
|
|
1035
|
+
3. Libraries and theme load in parallel, the layout is generated when all of them are ready
|
|
1036
|
+
4. Theme CSS merged into a single file
|
|
1037
|
+
5. `init()` returns a Promise and accepts `config`, `nav`, `login`, `menuItems`
|
|
1038
|
+
#### Bugfix:
|
|
1039
|
+
1. Theme option (`theme` / `themes`) is respected, unknown theme falls back to the default
|
|
1040
|
+
2. Menu class does not start with "undefined"
|
|
1041
|
+
3. Modal script does not fail when the page has no modal
|
|
1042
|
+
4. Login data is not written to the console
|
|
1043
|
+
|
|
1044
|
+
### 0.3.6
|
|
1045
|
+
#### Added
|
|
1046
|
+
1. submodule update
|
|
1047
|
+
|
|
1048
|
+
### 0.3.4
|
|
1049
|
+
#### Added:
|
|
1050
|
+
1. support for custom JS loading
|
|
1051
|
+
#### Bugfix:
|
|
1052
|
+
1. Theme name fix
|
|
1053
|
+
|
|
1054
|
+
### 0.3.3
|
|
1055
|
+
#### Added:
|
|
1056
|
+
1. Modal support
|
|
1057
|
+
|
|
1058
|
+
### 0.3.2
|
|
1059
|
+
#### Added:
|
|
1060
|
+
1. title change
|
|
1061
|
+
2. copyright text change
|
|
1062
|
+
|
|
1063
|
+
### 0.3.1
|
|
1064
|
+
#### Added:
|
|
1065
|
+
1. Header element container added
|
|
1066
|
+
|
|
1067
|
+
### 0.3.0
|
|
1068
|
+
#### Added:
|
|
1069
|
+
1. Navigation Function call for menu
|
|
1070
|
+
|
|
1071
|
+
### 0.2.9
|
|
1072
|
+
#### Bugfix:
|
|
1073
|
+
1. Login form generation bugfix 2
|
|
1074
|
+
|
|
1075
|
+
### 0.2.8
|
|
1076
|
+
#### Bugfix:
|
|
1077
|
+
1. Login form generation bugfix
|
|
1078
|
+
|
|
1079
|
+
### 0.2.7
|
|
1080
|
+
#### Added:
|
|
1081
|
+
1. Basic layout div clear functions
|
|
1082
|
+
|
|
1083
|
+
### 0.2.6
|
|
1084
|
+
#### Added:
|
|
1085
|
+
1. Header Logo
|
|
1086
|
+
2. Updated Submodules
|
|
1087
|
+
|
|
1088
|
+
### 0.2.5
|
|
1089
|
+
#### Added
|
|
1090
|
+
1. JS-Cookie
|
|
1091
|
+
|
|
1092
|
+
### 0.2.4
|
|
1093
|
+
#### Added
|
|
1094
|
+
1. Crypto-JS
|
|
1095
|
+
2. Password encryption support
|
|
1096
|
+
|
|
1097
|
+
#### Bugfixes
|
|
1098
|
+
1. Login form generation
|
|
1099
|
+
|
|
1100
|
+
### 0.2.3
|
|
1101
|
+
#### Bugfixes
|
|
1102
|
+
1. Bugfixes on login form generation
|
|
1103
|
+
|
|
1104
|
+
### 0.2.2
|
|
1105
|
+
#### Added:
|
|
1106
|
+
1. Login Form generation
|
|
1107
|
+
|
|
1108
|
+
#### Bugfix:
|
|
1109
|
+
1. Config loading error fixed
|
|
1110
|
+
|
|
1111
|
+
### 0.2.1
|
|
1112
|
+
#### Bugfix:
|
|
1113
|
+
1. Some bugfixes on element generation
|
|
1114
|
+
|
|
1115
|
+
### 0.2.0
|
|
1116
|
+
#### Added:
|
|
1117
|
+
1. Element generation from external configuration
|
|
1118
|
+
|
|
1119
|
+
### 0.1.1
|
|
1120
|
+
#### Added:
|
|
1121
|
+
1. Fixes
|
|
1122
|
+
|
|
1123
|
+
### 0.1.0
|
|
1124
|
+
#### Added:
|
|
1125
|
+
1. basic html layout generation
|
|
1126
|
+
2. header generation
|
|
1127
|
+
3. footer generation
|
|
1128
|
+
|