athena-ui-js 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +621 -3
- package/package.json +84 -6
- package/src/athena-ui.js +145 -0
- package/src/libs/config/config.js +67 -0
- package/src/libs/config/hooks.js +46 -0
- package/src/libs/core/combobox.js +179 -0
- package/src/libs/core/csv.js +37 -0
- package/src/libs/core/dateRange.js +50 -0
- package/src/libs/core/dom.js +57 -0
- package/src/libs/core/focus.js +49 -0
- package/src/libs/core/format.js +31 -0
- package/src/libs/core/i18n.js +160 -0
- package/src/libs/core/pagination.js +24 -0
- package/src/libs/core/sanitize.js +65 -0
- package/src/libs/core/tableMath.js +31 -0
- package/src/libs/core/validation.js +79 -0
- package/src/libs/crypto-js/LICENSE +24 -0
- package/src/libs/crypto-js/crypto-js.js +6657 -0
- package/src/libs/hephaestus/HTMLControlGenerator/LICENSE +21 -0
- package/src/libs/hephaestus/HTMLControlGenerator/src/HTMLControlGenerator.min.js +5 -0
- package/src/libs/hephaestus/HTMLElementGenerator/LICENSE +21 -0
- package/src/libs/hephaestus/HTMLElementGenerator/src/HTMLElementGenerator.js +94 -0
- package/src/libs/hephaestus/HTMLElementGenerator/src/errors.js +46 -0
- package/src/libs/hephaestus/LayoutGenerator/basicLayoutGenerator.js +65 -0
- package/src/libs/hephaestus/LayoutGenerator/footerContentGenerator.js +38 -0
- package/src/libs/hephaestus/LayoutGenerator/headerContentGenerator.js +61 -0
- package/src/libs/hephaestus/LayoutGenerator/wrapperContentGenerator.js +10 -0
- package/src/libs/hephaestus/MenuGenerator/basicMenuGenerator.js +133 -0
- package/src/libs/hephaestus/auth/session.js +68 -0
- package/src/libs/hephaestus/chartGenerator/chartGenerator.js +187 -0
- package/src/libs/hephaestus/componentGenerator/componentGenerator.js +201 -0
- package/src/libs/hephaestus/dialogGenerator/dialogGenerator.js +126 -0
- package/src/libs/hephaestus/feedbackGenerator/feedbackGenerator.js +138 -0
- package/src/libs/hephaestus/formGenerator/changePasswordFormGenerator.js +50 -0
- package/src/libs/hephaestus/formGenerator/formBuilder.js +379 -0
- package/src/libs/hephaestus/formGenerator/formUtils.js +66 -0
- package/src/libs/hephaestus/formGenerator/loginFormGenerator.js +104 -0
- package/src/libs/hephaestus/formGenerator/lostPasswordFormGenerator.js +30 -0
- package/src/libs/hephaestus/formGenerator/registrationFormGenerator.js +54 -0
- package/src/libs/hephaestus/hephaestus.js +62 -0
- package/src/libs/hephaestus/inputGenerator/inputGenerator.js +299 -0
- package/src/libs/hephaestus/inputGenerator/richTextGenerator.js +222 -0
- package/src/libs/hephaestus/modalGenerator/modalGenerator.js +33 -0
- package/src/libs/hephaestus/navigationGenerator/navigationGenerator.js +388 -0
- package/src/libs/hephaestus/router/matchRoute.js +42 -0
- package/src/libs/hephaestus/router/router.js +102 -0
- package/src/libs/hephaestus/tableGenerator/tableGenerator.js +457 -0
- package/src/libs/js-cookie/LICENSE +21 -0
- package/src/libs/js-cookie/src/api.mjs +103 -0
- package/src/libs/js-cookie/src/assign.mjs +10 -0
- package/src/libs/js-cookie/src/converter.mjs +14 -0
- package/src/libs/libs.js +13 -0
- package/src/res/themes/dark/style.css +31 -0
- package/src/res/themes/default/style.css +1455 -0
- package/src/res/themes/themes.js +19 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Csaba Tóth
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,621 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# Athena UI
|
|
2
|
+
|
|
3
|
+
A small jQuery based 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: **1.0.0** (first stable release)
|
|
9
|
+
|
|
10
|
+
[Quick start](#usage) · [API](#api) · [Components](#charts) · [Themes](#themes) · [Tests](#tests) · [Release notes](#releases)
|
|
11
|
+
|
|
12
|
+
## Status
|
|
13
|
+
|
|
14
|
+
1.0.0 is the first stable release. From here on the exported API of `src/athena-ui.js` follows
|
|
15
|
+
[semantic versioning](https://semver.org/): breaking changes only come with a new major version.
|
|
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.
|
|
21
|
+
- Translations: English and Hungarian.
|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
|
|
25
|
+
- Generated page layout: container, header (logo, title, menu), wrapper, footer (menu, copyright text)
|
|
26
|
+
- Menus built from your own item lists, with a navigation callback
|
|
27
|
+
- Login, registration and lost password forms with optional SHA-256 password hashing
|
|
28
|
+
- SVG charts (bar, line, pie, donut) without extra dependencies
|
|
29
|
+
- Tables with sortable columns, filter box, pagination, row selection, inline editing, resizable columns, virtual scrolling for thousands of rows and CSV export
|
|
30
|
+
- Form builder: text, number, date, textarea, select, radio / checkbox groups, switch, autocomplete, multi select, with validation
|
|
31
|
+
- Buttons, toasts, alerts, spinner, progress bar, alert / confirm / prompt dialogs
|
|
32
|
+
- Tabs, accordion, dropdown, sidebar, breadcrumbs, pagination and a hash / history router
|
|
33
|
+
- Cards, grid, badges, avatars, KPI tiles, tooltips, links, sections
|
|
34
|
+
- File upload with progress, stepper (wizard), date range picker, rich text editor
|
|
35
|
+
- Menus with submenus
|
|
36
|
+
- Session handling (login state in a cookie), change password form
|
|
37
|
+
- Default and dark theme (switchable at runtime), responsive, translations (English, Hungarian), keyboard and ARIA support
|
|
38
|
+
- Modal open / close helpers
|
|
39
|
+
- Themes loaded at runtime, custom stylesheets supported
|
|
40
|
+
- Written as ES modules, no build step
|
|
41
|
+
|
|
42
|
+
## Requirements
|
|
43
|
+
|
|
44
|
+
- [jQuery](https://jquery.com/) v4.0.0, loaded before Athena UI
|
|
45
|
+
- A browser with ES module support
|
|
46
|
+
- The page has to be served over HTTP(S). Modules do not load from `file://`.
|
|
47
|
+
|
|
48
|
+
Bundled as git submodules:
|
|
49
|
+
|
|
50
|
+
| Library | Version | Used for |
|
|
51
|
+
| --- | --- | --- |
|
|
52
|
+
| [HTMLControlGenerator](https://github.com/csabatibortoth/HTMLControlGenerator) | 0.4.0 | inputs, lists |
|
|
53
|
+
| [HTMLElementGenerator](https://github.com/csabatibortoth/HTMLElementGenerator) | 0.3.0 | divs, headings, images |
|
|
54
|
+
| [crypto-js](https://github.com/brix/crypto-js) | 4.2.0 | password hashing |
|
|
55
|
+
| [js-cookie](https://github.com/js-cookie/js-cookie) | 3.0.8 | cookie handling |
|
|
56
|
+
|
|
57
|
+
## Installation
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
git clone --recurse-submodules https://github.com/csabatibortoth/athena-ui.git
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
In an existing clone, or after updating:
|
|
64
|
+
|
|
65
|
+
```sh
|
|
66
|
+
git submodule update --init
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Serve the `src` folder with any static web server and open `index.html` to see the example.
|
|
70
|
+
|
|
71
|
+
## Usage
|
|
72
|
+
|
|
73
|
+
```html
|
|
74
|
+
<script src="https://code.jquery.com/jquery-4.0.0.min.js"
|
|
75
|
+
integrity="sha256-OaVG6prZf4v69dPg6PhVattBXkcOWQB62pdZ3ORyrao=" crossorigin="anonymous"></script>
|
|
76
|
+
<script type="module">
|
|
77
|
+
import { init, clearWrapper, generateLoginForm } from "./athena-ui.js";
|
|
78
|
+
|
|
79
|
+
init({
|
|
80
|
+
theme: { id: 0 },
|
|
81
|
+
config: { header_title_text: "My App", login_enabled: true },
|
|
82
|
+
menuItems: {
|
|
83
|
+
headerMenu: [
|
|
84
|
+
{ id: "menu-home", class: "menu-item", text: "", inner_text: "Home" },
|
|
85
|
+
{ id: "menu-login", class: "menu-item", text: "", inner_text: "Login" }
|
|
86
|
+
],
|
|
87
|
+
footerMenu: []
|
|
88
|
+
},
|
|
89
|
+
nav: page => {
|
|
90
|
+
if (page === "Login") {
|
|
91
|
+
clearWrapper();
|
|
92
|
+
generateLoginForm();
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
login: ({ username, password }) => console.log(`${username} logged in`)
|
|
96
|
+
});
|
|
97
|
+
</script>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
`init()` returns a Promise that resolves with the effective configuration once the libraries and
|
|
101
|
+
the theme are loaded and the layout is generated.
|
|
102
|
+
|
|
103
|
+
### init options
|
|
104
|
+
|
|
105
|
+
| Option | Description |
|
|
106
|
+
| --- | --- |
|
|
107
|
+
| `theme` | `{ id }` of a theme registered in `res/themes/themes.js`, or `{ href }` of a custom stylesheet. Defaults to the default theme. |
|
|
108
|
+
| `config` | Settings overriding the defaults, see [Configuration](#configuration). |
|
|
109
|
+
| `menuItems` | `{ headerMenu, footerMenu }`, arrays of `{ id, class, text, inner_text }`. Placeholder items are generated without it. |
|
|
110
|
+
| `nav` | Called without arguments when the wrapper is generated, and with the `inner_text` of the item on menu clicks. |
|
|
111
|
+
| `login` | Called with `{ username, password }` when the login button is clicked and `login_enabled` is set. |
|
|
112
|
+
| `register` | Called with `{ username, email, password }` when a valid registration form is submitted and `registration_enabled` is set. |
|
|
113
|
+
| `lostPassword` | Called with `{ email }` when a valid lost password form is submitted and `lost_password_enabled` is set. |
|
|
114
|
+
| `changePassword` | Called with `{ currentPassword, newPassword }` when a valid change password form is submitted and `change_password_enabled` is set. |
|
|
115
|
+
|
|
116
|
+
### Configuration
|
|
117
|
+
|
|
118
|
+
| Setting | Default | Description |
|
|
119
|
+
| --- | --- | --- |
|
|
120
|
+
| `header_title_text` | `"Athena UI"` | Title in the header |
|
|
121
|
+
| `header_img_url` | | Header logo URL |
|
|
122
|
+
| `copyright` | placeholder text | Footer text, the version is appended |
|
|
123
|
+
| `version` | `"1.0.0"` | Version shown in the footer |
|
|
124
|
+
| `bordered` | `true` | Draw a border around the layout blocks |
|
|
125
|
+
| `generateHeader`, `generateFooter` | `true` | Generate the header / footer block |
|
|
126
|
+
| `generateHeadercontent`, `generateFooterContent`, `generateWrappercontent` | `true` | Generate the content of the block |
|
|
127
|
+
| `login_enabled` | `false` | Call the `login` callback from the login form |
|
|
128
|
+
| `registration_enabled` | `false` | Call the `register` callback from the registration form |
|
|
129
|
+
| `lost_password_enabled` | `false` | Call the `lostPassword` callback from the lost password form |
|
|
130
|
+
| `change_password_enabled` | `false` | Call the `changePassword` callback from the change password form |
|
|
131
|
+
| `login_remember_me` | `false` | Show a "Remember me" checkbox in the login form, passed to `login` as `remember` |
|
|
132
|
+
| `locale` | `"en"` | Language of the generated texts (`en`, `hu`, or your own, see [Translations](#translations)) |
|
|
133
|
+
| `session_cookie` | `"athena_session"` | Name of the session cookie |
|
|
134
|
+
| `session_days` | `7` | Lifetime of a remembered session in days |
|
|
135
|
+
| `enable_encrypt_password` | `false` | SHA-256 hash the password before it is passed to `login` / `register` |
|
|
136
|
+
| `customLoader` | | URL of an extra classic script, loaded before the layout is generated |
|
|
137
|
+
| `container_class`, `header_class`, `header_menu_class`, `wrapper_class`, `footer_class`, `footer_menu_class`, `loginForm_class`, `registrationForm_class`, `lostPasswordForm_class`, `changePasswordForm_class` | | CSS classes of the generated blocks |
|
|
138
|
+
|
|
139
|
+
### API
|
|
140
|
+
|
|
141
|
+
Everything is exported from `athena-ui.js`:
|
|
142
|
+
|
|
143
|
+
| Export | Description |
|
|
144
|
+
| --- | --- |
|
|
145
|
+
| `init(options)` | Loads everything and generates the layout |
|
|
146
|
+
| `config` | The live configuration object |
|
|
147
|
+
| `generateBasicLayout()`, `generateHeader()`, `generateWrapper()`, `generateFooter()` | Layout generation |
|
|
148
|
+
| `clearHeader()`, `clearWrapper()`, `clearFooter()`, `clearHeaderMenu()`, `clearFooterMenu()` | Empty a block |
|
|
149
|
+
| `generateBasicMenu(options)` | Generate a menu into any parent |
|
|
150
|
+
| `generateLoginForm()`, `getLoginFormData()` | Login form into the wrapper, and its current values |
|
|
151
|
+
| `generateRegistrationForm(parent)`, `getRegistrationFormData()`, `validateRegistrationForm()` | Registration form (username, email, password, confirmation) into `parent` (default `wrapper`). Validated before the callback is called. |
|
|
152
|
+
| `generateLostPasswordForm(parent)`, `getLostPasswordFormData()` | Lost password form (email) |
|
|
153
|
+
| `generateChart(options)` | Draw a chart, see [Charts](#charts) |
|
|
154
|
+
| `generateTable(options)` | Draw a table, see [Tables](#tables) |
|
|
155
|
+
| `generateChangePasswordForm(parent)`, `getChangePasswordFormData()`, `validateChangePasswordForm()` | Change password form |
|
|
156
|
+
| `generateForm`, `generateField`, `generateButton` | Form builder, see [Forms](#forms) |
|
|
157
|
+
| `showToast`, `generateAlert`, `generateSpinner`, `generateProgress` | See [Feedback](#feedback) |
|
|
158
|
+
| `showDialog`, `alertDialog`, `confirmDialog`, `promptDialog` | See [Dialogs](#dialogs) |
|
|
159
|
+
| `generateTabs`, `generateBreadcrumbs`, `generatePagination`, `generateAccordion`, `generateDropdown`, `generateSidebar` | See [Navigation](#navigation) |
|
|
160
|
+
| `createRouter(options)` | See [Router](#router) |
|
|
161
|
+
| `generateCard`, `generateSection`, `generateGrid`, `generateBadge`, `generateAvatar`, `generateStat`, `generateLink`, `generateTooltip` | See [Components](#components) |
|
|
162
|
+
| `generateAutocomplete`, `generateMultiSelect`, `generateFileUpload`, `generateStepper`, `generateDateRange`, `generateRichText` | See [Inputs](#inputs) |
|
|
163
|
+
| `sanitizeHtml(html)`, `htmlToText(html)`, `isSafeUrl(url)` | The allow-list sanitizer behind the rich text editor |
|
|
164
|
+
| `setSession`, `getSession`, `isLoggedIn`, `logout`, `onSessionChange` | See [Session](#session) |
|
|
165
|
+
| `translate`, `setLocale`, `getLocale`, `addMessages` | See [Translations](#translations) |
|
|
166
|
+
| `validateValue`, `validateAll` | The validator behind the form builder |
|
|
167
|
+
| `toCsv(columns, rows)`, `downloadFile(name, text)` | CSV helpers |
|
|
168
|
+
| `setTheme({ id })` | Switch the theme at runtime |
|
|
169
|
+
| `openModal(id)`, `closeModal(id)` | Show / hide a `.modal` element (default id: `myModal`). Elements with the `close` class close their modal. |
|
|
170
|
+
| `loadScript(src)` | Load a classic script once, returns a Promise |
|
|
171
|
+
| `Cookies` | The [js-cookie](https://github.com/js-cookie/js-cookie) API |
|
|
172
|
+
| `HTMLElementGenerator(options)` | The [HTMLElementGenerator](https://github.com/csabatibortoth/HTMLElementGenerator) function |
|
|
173
|
+
|
|
174
|
+
### Charts
|
|
175
|
+
|
|
176
|
+
```js
|
|
177
|
+
generateChart({
|
|
178
|
+
type: "bar", // "bar" | "line" | "pie" | "donut"
|
|
179
|
+
parent: "wrapper", // id of the parent element (default)
|
|
180
|
+
title: "Revenue",
|
|
181
|
+
labels: ["Q1", "Q2", "Q3"],
|
|
182
|
+
series: [
|
|
183
|
+
{ name: "2025", data: [12, 19, 8] },
|
|
184
|
+
{ name: "2026", data: [14, 17, 12], color: "#e15759" }
|
|
185
|
+
]
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Charts are inline SVG and support negative values. `pie` and `donut` use the first series, one slice per
|
|
190
|
+
label. Other options: `id`, `width` (600), `height` (360), `legend` (shown for several series and for
|
|
191
|
+
pie / donut). Returns the `<svg>` element, or `null` when the options are invalid.
|
|
192
|
+
|
|
193
|
+
### Tables
|
|
194
|
+
|
|
195
|
+
```js
|
|
196
|
+
const { setRows } = generateTable({
|
|
197
|
+
parent: "wrapper",
|
|
198
|
+
caption: "Users",
|
|
199
|
+
columns: [{ key: "name", label: "Name" }, { key: "age", label: "Age", format: v => `${v} y` }],
|
|
200
|
+
rows: [{ name: "Anna", age: 31 }, { name: "Béla", age: 27 }],
|
|
201
|
+
filter: true, // text filter box
|
|
202
|
+
pageSize: 10, // 0 = no pagination
|
|
203
|
+
onRowClick: row => console.log(row)
|
|
204
|
+
});
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Click a header to sort (disable with `sortable: false`, or per column). Other options: `id`, `class`,
|
|
208
|
+
`emptyText`. Returns `{ element, setRows(rows), getSelected(), clearSelection(), toCsv(), exportCsv(filename) }`.
|
|
209
|
+
|
|
210
|
+
- `selectable: true` adds a checkbox column (the header checkbox selects every filtered row), `onSelectionChange(rows)` reports changes.
|
|
211
|
+
- 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.
|
|
212
|
+
- `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.
|
|
213
|
+
- `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.
|
|
214
|
+
- `exportCsv()` downloads the filtered and sorted rows. Cells that start with `=`, `+`, `-` or `@` are prefixed with `'` so a spreadsheet does not run them as formulas.
|
|
215
|
+
|
|
216
|
+
### Forms
|
|
217
|
+
|
|
218
|
+
```js
|
|
219
|
+
const form = generateForm({
|
|
220
|
+
parent: "wrapper",
|
|
221
|
+
submitText: "Save",
|
|
222
|
+
fields: [
|
|
223
|
+
{ name: "name", label: "Name", required: true, minLength: 2, help: "At least 2 characters" },
|
|
224
|
+
{ name: "email", label: "Email", type: "email", required: true },
|
|
225
|
+
{ name: "password", label: "Password", type: "password", required: true },
|
|
226
|
+
{ name: "password2", label: "Repeat", type: "password", match: "password" },
|
|
227
|
+
{ name: "country", label: "Country", type: "select", placeholder: "Choose...", options: ["Hungary", "Italy"] },
|
|
228
|
+
{ name: "plan", type: "radio", label: "Plan", options: ["Free", "Pro"], value: "Free" },
|
|
229
|
+
{ name: "news", type: "switch", label: "Newsletter" }
|
|
230
|
+
],
|
|
231
|
+
onSubmit: async values => { await save(values); } // called when every field is valid
|
|
232
|
+
});
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Field types: `text`, `password`, `email`, `number`, `date`, `datetime-local`, `time`, `month`, `week`, `url`, `tel`,
|
|
236
|
+
`search`, `color`, `range`, `file`, `hidden`, `textarea`, `select` (`multiple`), `checkbox`, `switch`, `radio`,
|
|
237
|
+
`checkboxes`, `autocomplete`, `multiselect`, `daterange` (value `{ from, to }`), `richtext` (value: safe HTML).
|
|
238
|
+
The date, time and color types use the native pickers of the browser.
|
|
239
|
+
|
|
240
|
+
Rules (`required`, `email`, `minLength`, `maxLength`, `pattern`, `min`, `max`, `match`, `validate(value, values)`) can be
|
|
241
|
+
given on the field or in `rules`. A field is validated when it loses focus, then on every change. A rejected
|
|
242
|
+
`onSubmit` promise is shown as form message and the submit button shows a spinner while it runs.
|
|
243
|
+
|
|
244
|
+
The returned form has `getValues()`, `setValues()`, `setErrors({ name: "Taken" })` (server side errors),
|
|
245
|
+
`validate()`, `reset()`, `setMessage(text)`, `fields` and `submitButton`. `generateField(options)` builds a single field.
|
|
246
|
+
|
|
247
|
+
`generateButton({ text, variant, loading, disabled, onclick })` has the variants `primary`, `secondary`, `danger` and
|
|
248
|
+
`link`, and returns `{ element, setLoading, setDisabled, setText }`.
|
|
249
|
+
|
|
250
|
+
### Feedback
|
|
251
|
+
|
|
252
|
+
```js
|
|
253
|
+
showToast({ title: "Saved", message: "All good", type: "success", duration: 4000 }); // info | success | warning | error
|
|
254
|
+
generateAlert({ parent: "wrapper", type: "error", message: "Failed", dismissible: true });
|
|
255
|
+
generateSpinner({ parent: "wrapper", size: "large" });
|
|
256
|
+
const progress = generateProgress({ parent: "wrapper", label: "Upload", value: 20 }); // no value: indeterminate
|
|
257
|
+
progress.setValue(60);
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### Dialogs
|
|
261
|
+
|
|
262
|
+
```js
|
|
263
|
+
await alertDialog("Saved");
|
|
264
|
+
if (await confirmDialog("Delete the item?", { title: "Delete", confirmText: "Delete", danger: true })) { /* ... */ }
|
|
265
|
+
const name = await promptDialog("Your name", { validate: v => v ? "" : "Required" }); // null when cancelled
|
|
266
|
+
const choice = await showDialog({ title: "Custom", content: "Pick one", buttons: [{ text: "A", value: "a" }, { text: "B", value: "b" }] });
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
Dialogs trap the focus, close with Esc (resolving `null` / `false`) and restore the focus. Text content is
|
|
270
|
+
never parsed as HTML. `openModal` / `closeModal` got the same focus handling.
|
|
271
|
+
|
|
272
|
+
### Navigation
|
|
273
|
+
|
|
274
|
+
```js
|
|
275
|
+
generateTabs({ parent: "wrapper", tabs: [{ id: "a", label: "A", content: "First" }, { id: "b", label: "B", content: () => lazyNode() }] });
|
|
276
|
+
generateAccordion({ parent: "wrapper", items: [{ title: "Q", content: "A", open: true }], multiple: false });
|
|
277
|
+
generateDropdown({ parent: "wrapper", label: "Actions", items: [{ label: "Edit", onclick }, { divider: true }, { label: "Delete", onclick }] });
|
|
278
|
+
generatePagination({ parent: "wrapper", total: 200, pageSize: 10, onChange: page => load(page) });
|
|
279
|
+
generateBreadcrumbs({ parent: "wrapper", items: [{ label: "Home", href: "#/" }, { label: "Users" }] });
|
|
280
|
+
generateSidebar({ parent: "wrapper", active: "home", onSelect: item => go(item.id),
|
|
281
|
+
items: [{ id: "home", label: "Home" }, { id: "reports", label: "Reports", children: [{ id: "daily", label: "Daily" }] }] });
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
Tabs, dropdown and the combobox inputs follow the WAI-ARIA keyboard patterns (arrow keys, Home / End, Esc).
|
|
285
|
+
The sidebar collapses behind a toggle button on small screens.
|
|
286
|
+
|
|
287
|
+
### Menus with submenus
|
|
288
|
+
|
|
289
|
+
```js
|
|
290
|
+
init({
|
|
291
|
+
menuItems: {
|
|
292
|
+
headerMenu: [
|
|
293
|
+
{ id: "menu-home", class: "menu-item", text: "", inner_text: "Home" },
|
|
294
|
+
{ id: "menu-more", class: "menu-item", text: "", inner_text: "More", children: [{ inner_text: "Reports" }, { inner_text: "Archive", disabled: true }] }
|
|
295
|
+
],
|
|
296
|
+
footerMenu: []
|
|
297
|
+
},
|
|
298
|
+
nav: name => router.navigate(`/${name.toLowerCase()}`) // called with the entry's inner_text
|
|
299
|
+
});
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
A submenu opens with a click, Enter, Space or the Down arrow, closes with Esc, a click outside or by choosing an entry,
|
|
303
|
+
and supports the arrow keys, Home and End. The same works in the footer menu.
|
|
304
|
+
|
|
305
|
+
### Router
|
|
306
|
+
|
|
307
|
+
```js
|
|
308
|
+
const router = createRouter({
|
|
309
|
+
routes: {
|
|
310
|
+
"/": () => renderHome(),
|
|
311
|
+
"/users/:id": ({ params, query }) => renderUser(params.id),
|
|
312
|
+
"/admin": { handler: renderAdmin, title: "Admin" }
|
|
313
|
+
},
|
|
314
|
+
outlet: "wrapper", // emptied before every page
|
|
315
|
+
beforeEach: ({ path }) => path === "/admin" && !isLoggedIn() ? "/login" : undefined, // false cancels, a path redirects
|
|
316
|
+
notFound: () => renderNotFound()
|
|
317
|
+
});
|
|
318
|
+
router.start();
|
|
319
|
+
router.navigate("/users/5?tab=info");
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
`mode: "history"` uses real paths instead of the hash, the server then has to answer every path with the page.
|
|
323
|
+
Pass `router.navigate` from your `nav` callback to route the menu clicks.
|
|
324
|
+
|
|
325
|
+
### Components
|
|
326
|
+
|
|
327
|
+
```js
|
|
328
|
+
const grid = generateGrid({ parent: "wrapper", columns: 3 }); // one column on small screens
|
|
329
|
+
generateStat({ parent: grid, label: "Revenue", value: "$12k", delta: 8.2 });
|
|
330
|
+
generateCard({ parent: grid, title: "Title", content: "Text or a Node", footer: "Footer", image: "a.jpg" });
|
|
331
|
+
generateBadge({ parent: "wrapper", text: "new", variant: "success", pill: true });
|
|
332
|
+
generateAvatar({ parent: "wrapper", name: "Ada Lovelace", src: "ada.png" }); // initials without a working image
|
|
333
|
+
generateTooltip(buttonElement, "Saves the form");
|
|
334
|
+
generateLink({ parent: "wrapper", text: "Docs", href: "https://example.com", external: true });
|
|
335
|
+
generateSection({ parent: "wrapper", title: "Section", level: 2, content: "..." });
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
`parent` is the id of an element or the element itself. String content is always inserted as text.
|
|
339
|
+
|
|
340
|
+
### Inputs
|
|
341
|
+
|
|
342
|
+
```js
|
|
343
|
+
generateAutocomplete({ parent: "wrapper", label: "Country", options: ["Hungary", "Italy"] });
|
|
344
|
+
generateAutocomplete({ parent: "wrapper", options: async query => fetchSuggestions(query), minChars: 2 }); // remote data
|
|
345
|
+
generateMultiSelect({ parent: "wrapper", options: [{ value: "h", text: "Hungary" }], value: ["h"] }); // getValue(): array
|
|
346
|
+
generateFileUpload({ parent: "wrapper", accept: ".png,.pdf", maxSize: 2 * 1024 * 1024, url: "/upload",
|
|
347
|
+
onProgress: (file, percent) => {}, onComplete: (file, response) => {}, onError: (file, error) => {} });
|
|
348
|
+
generateStepper({ parent: "wrapper", onFinish: () => {}, steps: [
|
|
349
|
+
{ title: "Account", content: () => buildStep1(), validate: () => valid || "Fix the errors" },
|
|
350
|
+
{ title: "Done", content: "Finished" }
|
|
351
|
+
] });
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
```js
|
|
355
|
+
generateDateRange({ parent: "wrapper", label: "Stay", from: "2026-06-01", min: "2026-01-01", onChange: ({ from, to }) => {} });
|
|
356
|
+
const editor = generateRichText({ parent: "wrapper", label: "Description", placeholder: "Write...", value: "<p>Hello</p>",
|
|
357
|
+
toolbar: ["bold", "italic", "|", "ul", "ol", "link"], onChange: html => {} });
|
|
358
|
+
editor.getValue(); // safe HTML, "" when empty
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
The date range uses the native date pickers; the end picker starts at the chosen start date and a reversed range typed by
|
|
362
|
+
hand is reported. The rich text editor produces a restricted set of HTML (paragraphs, headings, bold / italic / underline /
|
|
363
|
+
strike, lists, quotes, code, links). Everything else (scripts, styles, iframes, images, event attributes, `javascript:` and
|
|
364
|
+
`data:` links) is removed when the content is set, pasted, dropped and read, so the value is safe to store and show with
|
|
365
|
+
`innerHTML`; links get `rel="noopener noreferrer"`. Toolbar buttons: `bold`, `italic`, `underline`, `strike`, `h2`, `h3`,
|
|
366
|
+
`quote`, `ul`, `ol`, `link`, `unlink`, `clear`, `undo`, `redo`. The editor is built on `contenteditable` and
|
|
367
|
+
`document.execCommand`, which every browser still supports; sanitize on the server as well, as with any HTML you accept.
|
|
368
|
+
|
|
369
|
+
Files are sent as a multipart POST (`fieldName`, `headers` are configurable). Without `url` the files are only collected,
|
|
370
|
+
read them with `getFiles()`.
|
|
371
|
+
|
|
372
|
+
### Session
|
|
373
|
+
|
|
374
|
+
```js
|
|
375
|
+
login: async ({ username, password, remember }) => {
|
|
376
|
+
const user = await api.login(username, password);
|
|
377
|
+
setSession({ user, token: user.token, remember }); // a session cookie, or `session_days` days when remembered
|
|
378
|
+
router.navigate("/");
|
|
379
|
+
}
|
|
380
|
+
isLoggedIn(); getSession(); logout();
|
|
381
|
+
onSessionChange(session => updateMenu(session));
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
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
|
|
385
|
+
and let the server enforce authorization; a server set `HttpOnly` cookie is the safer place for real credentials.
|
|
386
|
+
|
|
387
|
+
### Translations
|
|
388
|
+
|
|
389
|
+
```js
|
|
390
|
+
init({ config: { locale: "hu" } }); // English and Hungarian are included
|
|
391
|
+
setLocale("en"); // switch at runtime, texts of new components follow
|
|
392
|
+
addMessages("de", { login: "Anmelden", "validation.required": "Pflichtfeld" });
|
|
393
|
+
translate("login");
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
Missing texts fall back to English. See `src/libs/core/i18n.js` for all keys.
|
|
397
|
+
|
|
398
|
+
### Usage from classic scripts
|
|
399
|
+
|
|
400
|
+
The same API is available as globals (and as `AthenaUI`), so scripts written for earlier versions
|
|
401
|
+
keep working. Load `athena-ui.js` with `type="module"` and call the globals after the DOM is ready:
|
|
402
|
+
|
|
403
|
+
```html
|
|
404
|
+
<script>
|
|
405
|
+
var appConfig = { header_title_text: "My App", customLoader: "js/app.js" };
|
|
406
|
+
</script>
|
|
407
|
+
<script type="module" src="athena-ui/src/athena-ui.js"></script>
|
|
408
|
+
<script>
|
|
409
|
+
$(function () {
|
|
410
|
+
init({ theme: { id: 0 } });
|
|
411
|
+
});
|
|
412
|
+
</script>
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
The global `appConfig`, `menuItems`, `nav`, `login`, `register` and `lostPassword` are used when the matching `init` option is
|
|
416
|
+
not given. `appConfig.athenaUIFolder` is not needed anymore, paths are resolved relative to
|
|
417
|
+
`athena-ui.js`.
|
|
418
|
+
|
|
419
|
+
## Themes
|
|
420
|
+
|
|
421
|
+
A theme is a single stylesheet. Register it in `src/res/themes/themes.js` and select it with
|
|
422
|
+
`theme: { id }`, or pass any stylesheet directly with `theme: { href: "css/my-theme.css" }`.
|
|
423
|
+
The default theme is in `src/res/themes/default/style.css`; `{ id: 1 }` is a dark theme. All colors are CSS variables
|
|
424
|
+
(`--athena-bg`, `--athena-fg`, `--athena-accent`, ...), so a custom theme can import the default one and override them:
|
|
425
|
+
|
|
426
|
+
```css
|
|
427
|
+
@import url("athena-ui/src/res/themes/default/style.css");
|
|
428
|
+
:root { --athena-accent: #8e44ad; }
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
Switch themes at runtime with `setTheme({ id: 1 })`.
|
|
432
|
+
|
|
433
|
+
## Tests
|
|
434
|
+
|
|
435
|
+
```sh
|
|
436
|
+
npm test # unit tests of the pure modules, run in Node
|
|
437
|
+
npm run test:browser # the components in headless Chrome
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
The unit tests cover validation, translations, router matching, CSV, pagination, formatting, virtual scrolling math, date ranges and the URL check.
|
|
441
|
+
The browser tests start a small static server, open `tests/browser/index.html` in headless Chrome, Chromium or Edge and run every
|
|
442
|
+
component: forms, dialogs, navigation, submenus, inputs, rich text (sanitizing, toolbar, paste), tables (resizing, virtual scrolling), router,
|
|
443
|
+
session, themes. Set `CHROME_PATH` if the browser is not found, and `JQUERY_URL` to load jQuery from somewhere else than the CDN
|
|
444
|
+
(the machine needs internet access otherwise). `DEBUG=1` prints the browser log when the page does not report results.
|
|
445
|
+
|
|
446
|
+
## Project structure
|
|
447
|
+
|
|
448
|
+
```
|
|
449
|
+
src/
|
|
450
|
+
athena-ui.js entry point, exports the whole API
|
|
451
|
+
index.html, example.js example page
|
|
452
|
+
libs/
|
|
453
|
+
config/ default configuration, application hooks
|
|
454
|
+
core/ DOM / focus helpers, validation, translations, CSV, formatting, sanitizer, table math
|
|
455
|
+
hephaestus/ script and theme loader, generators (layout, menu, forms, charts, tables, feedback,
|
|
456
|
+
dialogs, navigation, components, inputs), router, session
|
|
457
|
+
crypto-js/, js-cookie/ submodules
|
|
458
|
+
libs.js classic scripts loaded at runtime
|
|
459
|
+
res/themes/ default and dark theme
|
|
460
|
+
tests/ unit tests (Node) and browser tests (headless Chrome)
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
## Authors
|
|
464
|
+
|
|
465
|
+
* **Csaba Tóth** - *Initial work* - [csabatibortoth](https://github.com/csabatibortoth)
|
|
466
|
+
|
|
467
|
+
## License
|
|
468
|
+
|
|
469
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
|
|
470
|
+
|
|
471
|
+
## Releases
|
|
472
|
+
|
|
473
|
+
### 1.0.0
|
|
474
|
+
#### Added:
|
|
475
|
+
1. Stable public API (semantic versioning from this release on)
|
|
476
|
+
2. README: status, known limits and quick links
|
|
477
|
+
#### Changed:
|
|
478
|
+
1. Version bumped to 1.0.0, no breaking changes since 0.7.0
|
|
479
|
+
|
|
480
|
+
### 0.7.0
|
|
481
|
+
#### Added:
|
|
482
|
+
1. Menus with submenus: `children` on a menu item, with keyboard support
|
|
483
|
+
2. Tables: resizable columns (mouse and keyboard) and virtual scrolling (`virtual`) for thousands of rows
|
|
484
|
+
3. `generateDateRange` and the `daterange` form field
|
|
485
|
+
4. `generateRichText` / `createRichText` and the `richtext` form field, with an allow-list sanitizer (`sanitizeHtml`, `isSafeUrl`)
|
|
486
|
+
5. Browser tests in headless Chrome (`npm run test:browser`), more unit tests
|
|
487
|
+
#### Changed:
|
|
488
|
+
1. English and Hungarian texts for the new components
|
|
489
|
+
|
|
490
|
+
### 0.6.0
|
|
491
|
+
#### Added:
|
|
492
|
+
1. Form builder (`generateForm`, `generateField`, `generateButton`) with validation, textarea, select, radio / checkbox groups, switch, autocomplete and multi select
|
|
493
|
+
2. Feedback: `showToast`, `generateAlert`, `generateSpinner`, `generateProgress`; dialogs: `alertDialog`, `confirmDialog`, `promptDialog`, `showDialog`
|
|
494
|
+
3. Navigation: tabs, accordion, dropdown, sidebar, breadcrumbs, pagination; `createRouter`
|
|
495
|
+
4. Components: card, grid, section, badge, avatar, stat, tooltip, link
|
|
496
|
+
5. `generateFileUpload` with progress, `generateStepper`
|
|
497
|
+
6. Tables: row selection, inline editing, CSV export
|
|
498
|
+
7. Session handling, change password form, "Remember me" in the login form
|
|
499
|
+
8. Dark theme, `setTheme`, CSS variables, responsive styles
|
|
500
|
+
9. Translations (English, Hungarian), `translate`, `setLocale`, `addMessages`
|
|
501
|
+
10. Unit tests (`npm test`)
|
|
502
|
+
#### Changed:
|
|
503
|
+
1. Modals trap the focus, close with Esc and restore the focus
|
|
504
|
+
2. The texts of the forms and of the table go through `translate`; the registration form checks its fields with the shared validator
|
|
505
|
+
3. `init` accepts the `changePassword` callback
|
|
506
|
+
|
|
507
|
+
### 0.5.0
|
|
508
|
+
#### Added:
|
|
509
|
+
1. `generateChart`: bar, line, pie and donut charts as inline SVG
|
|
510
|
+
2. `generateTable`: sortable, filterable, paginated tables
|
|
511
|
+
3. `generateRegistrationForm` and `generateLostPasswordForm`, with the `register` / `lostPassword` callbacks and the `registration_enabled` / `lost_password_enabled` settings
|
|
512
|
+
4. Example page shows all of them
|
|
513
|
+
|
|
514
|
+
### 0.4.1
|
|
515
|
+
#### Changed:
|
|
516
|
+
1. HTMLControlGenerator v0.4.0, HTMLElementGenerator v0.3.0, js-cookie updated to the latest master
|
|
517
|
+
2. HTMLElementGenerator is imported as an ES module instead of being loaded as a classic script
|
|
518
|
+
3. crypto-js follows the `master` branch, which holds the built release files
|
|
519
|
+
#### Added:
|
|
520
|
+
1. `HTMLElementGenerator` is exported from `athena-ui.js` (and stays available as a global)
|
|
521
|
+
#### Bugfix:
|
|
522
|
+
1. The label of a menu item without an `id` is not appended to the page body
|
|
523
|
+
|
|
524
|
+
### 0.4.0
|
|
525
|
+
#### Changed:
|
|
526
|
+
1. Rewritten as ES modules (no more chained `$.getScript` loading, no implicit globals)
|
|
527
|
+
2. JQuery v4.0.0, js-cookie v3.0.8, crypto-js v4.2.0
|
|
528
|
+
3. Libraries and theme load in parallel, the layout is generated when all of them are ready
|
|
529
|
+
4. Theme CSS merged into a single file
|
|
530
|
+
5. `init()` returns a Promise and accepts `config`, `nav`, `login`, `menuItems`
|
|
531
|
+
#### Bugfix:
|
|
532
|
+
1. Theme option (`theme` / `themes`) is respected, unknown theme falls back to the default
|
|
533
|
+
2. Menu class does not start with "undefined"
|
|
534
|
+
3. Modal script does not fail when the page has no modal
|
|
535
|
+
4. Login data is not written to the console
|
|
536
|
+
|
|
537
|
+
### 0.3.6
|
|
538
|
+
#### Added
|
|
539
|
+
1. submodule update
|
|
540
|
+
|
|
541
|
+
### 0.3.4
|
|
542
|
+
#### Added:
|
|
543
|
+
1. support for custom JS loading
|
|
544
|
+
#### Bugfix:
|
|
545
|
+
1. Theme name fix
|
|
546
|
+
|
|
547
|
+
### 0.3.3
|
|
548
|
+
#### Added:
|
|
549
|
+
1. Modal support
|
|
550
|
+
|
|
551
|
+
### 0.3.2
|
|
552
|
+
#### Added:
|
|
553
|
+
1. title change
|
|
554
|
+
2. copyright text change
|
|
555
|
+
|
|
556
|
+
### 0.3.1
|
|
557
|
+
#### Added:
|
|
558
|
+
1. Header element container added
|
|
559
|
+
|
|
560
|
+
### 0.3.0
|
|
561
|
+
#### Added:
|
|
562
|
+
1. Navigation Function call for menu
|
|
563
|
+
|
|
564
|
+
### 0.2.9
|
|
565
|
+
#### Bugfix:
|
|
566
|
+
1. Login form generation bugfix 2
|
|
567
|
+
|
|
568
|
+
### 0.2.8
|
|
569
|
+
#### Bugfix:
|
|
570
|
+
1. Login form generation bugfix
|
|
571
|
+
|
|
572
|
+
### 0.2.7
|
|
573
|
+
#### Added:
|
|
574
|
+
1. Basic layout div clear functions
|
|
575
|
+
|
|
576
|
+
### 0.2.6
|
|
577
|
+
#### Added:
|
|
578
|
+
1. Header Logo
|
|
579
|
+
2. Updated Submodules
|
|
580
|
+
|
|
581
|
+
### 0.2.5
|
|
582
|
+
#### Added
|
|
583
|
+
1. JS-Cookie
|
|
584
|
+
|
|
585
|
+
### 0.2.4
|
|
586
|
+
#### Added
|
|
587
|
+
1. Crypto-JS
|
|
588
|
+
2. Password encryption support
|
|
589
|
+
|
|
590
|
+
#### Bugfixes
|
|
591
|
+
1. Login form generation
|
|
592
|
+
|
|
593
|
+
### 0.2.3
|
|
594
|
+
#### Bugfixes
|
|
595
|
+
1. Bugfixes on login form generation
|
|
596
|
+
|
|
597
|
+
### 0.2.2
|
|
598
|
+
#### Added:
|
|
599
|
+
1. Login Form generation
|
|
600
|
+
|
|
601
|
+
#### Bugfix:
|
|
602
|
+
1. Config loading error fixed
|
|
603
|
+
|
|
604
|
+
### 0.2.1
|
|
605
|
+
#### Bugfix:
|
|
606
|
+
1. Some bugfixes on element generation
|
|
607
|
+
|
|
608
|
+
### 0.2.0
|
|
609
|
+
#### Added:
|
|
610
|
+
1. Element generation from external configuration
|
|
611
|
+
|
|
612
|
+
### 0.1.1
|
|
613
|
+
#### Added:
|
|
614
|
+
1. Fixes
|
|
615
|
+
|
|
616
|
+
### 0.1.0
|
|
617
|
+
#### Added:
|
|
618
|
+
1. basic html layout generation
|
|
619
|
+
2. header generation
|
|
620
|
+
3. footer generation
|
|
621
|
+
|