athena-ui-js 0.4.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +370 -11
- package/package.json +84 -60
- package/src/athena-ui.js +71 -1
- package/src/libs/config/config.js +15 -1
- package/src/libs/config/hooks.js +15 -3
- 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 +164 -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/hephaestus/MenuGenerator/basicMenuGenerator.js +81 -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 +20 -6
- package/src/libs/hephaestus/formGenerator/lostPasswordFormGenerator.js +30 -0
- package/src/libs/hephaestus/formGenerator/registrationFormGenerator.js +54 -0
- package/src/libs/hephaestus/hephaestus.js +8 -1
- package/src/libs/hephaestus/inputGenerator/dropZoneGenerator.js +118 -0
- package/src/libs/hephaestus/inputGenerator/inputGenerator.js +284 -0
- package/src/libs/hephaestus/inputGenerator/richTextGenerator.js +257 -0
- package/src/libs/hephaestus/modalGenerator/modalGenerator.js +13 -2
- 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/res/themes/dark/style.css +31 -0
- package/src/res/themes/default/style.css +1416 -7
- package/src/res/themes/themes.js +6 -0
package/README.md
CHANGED
|
@@ -1,16 +1,40 @@
|
|
|
1
1
|
# Athena UI
|
|
2
2
|
|
|
3
3
|
A small jQuery based UI framework for development and education purposes. It generates a page
|
|
4
|
-
layout (header, menu, content wrapper, footer)
|
|
5
|
-
|
|
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.
|
|
6
7
|
|
|
7
|
-
Current version: **
|
|
8
|
+
Current version: **1.1.0**
|
|
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.
|
|
8
22
|
|
|
9
23
|
## Features
|
|
10
24
|
|
|
11
25
|
- Generated page layout: container, header (logo, title, menu), wrapper, footer (menu, copyright text)
|
|
12
26
|
- Menus built from your own item lists, with a navigation callback
|
|
13
|
-
- Login
|
|
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, drag-and-drop area, stepper (wizard), date range picker, rich text and WYSIWYG 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
|
|
14
38
|
- Modal open / close helpers
|
|
15
39
|
- Themes loaded at runtime, custom stylesheets supported
|
|
16
40
|
- Written as ES modules, no build step
|
|
@@ -85,6 +109,9 @@ the theme are loaded and the layout is generated.
|
|
|
85
109
|
| `menuItems` | `{ headerMenu, footerMenu }`, arrays of `{ id, class, text, inner_text }`. Placeholder items are generated without it. |
|
|
86
110
|
| `nav` | Called without arguments when the wrapper is generated, and with the `inner_text` of the item on menu clicks. |
|
|
87
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. |
|
|
88
115
|
|
|
89
116
|
### Configuration
|
|
90
117
|
|
|
@@ -93,14 +120,21 @@ the theme are loaded and the layout is generated.
|
|
|
93
120
|
| `header_title_text` | `"Athena UI"` | Title in the header |
|
|
94
121
|
| `header_img_url` | | Header logo URL |
|
|
95
122
|
| `copyright` | placeholder text | Footer text, the version is appended |
|
|
96
|
-
| `version` | `"
|
|
123
|
+
| `version` | `"1.1.0"` | Version shown in the footer |
|
|
97
124
|
| `bordered` | `true` | Draw a border around the layout blocks |
|
|
98
125
|
| `generateHeader`, `generateFooter` | `true` | Generate the header / footer block |
|
|
99
126
|
| `generateHeadercontent`, `generateFooterContent`, `generateWrappercontent` | `true` | Generate the content of the block |
|
|
100
127
|
| `login_enabled` | `false` | Call the `login` callback from the login form |
|
|
101
|
-
| `
|
|
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` |
|
|
102
136
|
| `customLoader` | | URL of an extra classic script, loaded before the layout is generated |
|
|
103
|
-
| `container_class`, `header_class`, `header_menu_class`, `wrapper_class`, `footer_class`, `footer_menu_class`, `loginForm_class` | | CSS classes of the generated blocks |
|
|
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 |
|
|
104
138
|
|
|
105
139
|
### API
|
|
106
140
|
|
|
@@ -114,11 +148,264 @@ Everything is exported from `athena-ui.js`:
|
|
|
114
148
|
| `clearHeader()`, `clearWrapper()`, `clearFooter()`, `clearHeaderMenu()`, `clearFooterMenu()` | Empty a block |
|
|
115
149
|
| `generateBasicMenu(options)` | Generate a menu into any parent |
|
|
116
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`, `generateDropZone`, `generateStepper`, `generateDateRange`, `generateRichText`, `generateWysiwyg` | 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 |
|
|
117
169
|
| `openModal(id)`, `closeModal(id)` | Show / hide a `.modal` element (default id: `myModal`). Elements with the `close` class close their modal. |
|
|
118
170
|
| `loadScript(src)` | Load a classic script once, returns a Promise |
|
|
119
171
|
| `Cookies` | The [js-cookie](https://github.com/js-cookie/js-cookie) API |
|
|
120
172
|
| `HTMLElementGenerator(options)` | The [HTMLElementGenerator](https://github.com/csabatibortoth/HTMLElementGenerator) function |
|
|
121
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` and `wysiwyg` (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
|
+
```js
|
|
370
|
+
generateDropZone({ parent: "wrapper", accept: "image/*", maxSize: 2 * 1024 * 1024, maxFiles: 3,
|
|
371
|
+
onDrop: files => {}, onReject: rejected => rejected.forEach(({ file, reason }) => {}) });
|
|
372
|
+
const wysiwyg = generateWysiwyg({ parent: "wrapper", label: "Body", value: "<p>Hello</p>" }); // rich text + HTML source view
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
`generateDropZone` is a bare drag-and-drop area (also reachable with Enter / Space and the file dialog). Dropped files are
|
|
376
|
+
checked against `accept`, `maxSize` and `maxFiles`; valid ones go to `onDrop`, the others to `onReject` with a reason. It
|
|
377
|
+
reads and sends nothing, and `setDisabled(true)` turns it off. `generateWysiwyg` is the rich text editor plus a `source`
|
|
378
|
+
toolbar button that shows the sanitized HTML; what is typed there is sanitized again when you switch back.
|
|
379
|
+
|
|
380
|
+
Files are sent as a multipart POST (`fieldName`, `headers` are configurable). Without `url` the files are only collected,
|
|
381
|
+
read them with `getFiles()`.
|
|
382
|
+
|
|
383
|
+
### Session
|
|
384
|
+
|
|
385
|
+
```js
|
|
386
|
+
login: async ({ username, password, remember }) => {
|
|
387
|
+
const user = await api.login(username, password);
|
|
388
|
+
setSession({ user, token: user.token, remember }); // a session cookie, or `session_days` days when remembered
|
|
389
|
+
router.navigate("/");
|
|
390
|
+
}
|
|
391
|
+
isLoggedIn(); getSession(); logout();
|
|
392
|
+
onSessionChange(session => updateMenu(session));
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
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
|
|
396
|
+
and let the server enforce authorization; a server set `HttpOnly` cookie is the safer place for real credentials.
|
|
397
|
+
|
|
398
|
+
### Translations
|
|
399
|
+
|
|
400
|
+
```js
|
|
401
|
+
init({ config: { locale: "hu" } }); // English and Hungarian are included
|
|
402
|
+
setLocale("en"); // switch at runtime, texts of new components follow
|
|
403
|
+
addMessages("de", { login: "Anmelden", "validation.required": "Pflichtfeld" });
|
|
404
|
+
translate("login");
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
Missing texts fall back to English. See `src/libs/core/i18n.js` for all keys.
|
|
408
|
+
|
|
122
409
|
### Usage from classic scripts
|
|
123
410
|
|
|
124
411
|
The same API is available as globals (and as `AthenaUI`), so scripts written for earlier versions
|
|
@@ -136,7 +423,7 @@ keep working. Load `athena-ui.js` with `type="module"` and call the globals afte
|
|
|
136
423
|
</script>
|
|
137
424
|
```
|
|
138
425
|
|
|
139
|
-
The global `appConfig`, `menuItems`, `nav` and `
|
|
426
|
+
The global `appConfig`, `menuItems`, `nav`, `login`, `register` and `lostPassword` are used when the matching `init` option is
|
|
140
427
|
not given. `appConfig.athenaUIFolder` is not needed anymore, paths are resolved relative to
|
|
141
428
|
`athena-ui.js`.
|
|
142
429
|
|
|
@@ -144,7 +431,28 @@ not given. `appConfig.athenaUIFolder` is not needed anymore, paths are resolved
|
|
|
144
431
|
|
|
145
432
|
A theme is a single stylesheet. Register it in `src/res/themes/themes.js` and select it with
|
|
146
433
|
`theme: { id }`, or pass any stylesheet directly with `theme: { href: "css/my-theme.css" }`.
|
|
147
|
-
The default theme is in `src/res/themes/default/style.css
|
|
434
|
+
The default theme is in `src/res/themes/default/style.css`; `{ id: 1 }` is a dark theme. All colors are CSS variables
|
|
435
|
+
(`--athena-bg`, `--athena-fg`, `--athena-accent`, ...), so a custom theme can import the default one and override them:
|
|
436
|
+
|
|
437
|
+
```css
|
|
438
|
+
@import url("athena-ui/src/res/themes/default/style.css");
|
|
439
|
+
:root { --athena-accent: #8e44ad; }
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
Switch themes at runtime with `setTheme({ id: 1 })`.
|
|
443
|
+
|
|
444
|
+
## Tests
|
|
445
|
+
|
|
446
|
+
```sh
|
|
447
|
+
npm test # unit tests of the pure modules, run in Node
|
|
448
|
+
npm run test:browser # the components in headless Chrome
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
The unit tests cover validation, translations, router matching, CSV, pagination, formatting, virtual scrolling math, date ranges and the URL check.
|
|
452
|
+
The browser tests start a small static server, open `tests/browser/index.html` in headless Chrome, Chromium or Edge and run every
|
|
453
|
+
component: forms, dialogs, navigation, submenus, inputs, rich text (sanitizing, toolbar, paste), tables (resizing, virtual scrolling), router,
|
|
454
|
+
session, themes. Set `CHROME_PATH` if the browser is not found, and `JQUERY_URL` to load jQuery from somewhere else than the CDN
|
|
455
|
+
(the machine needs internet access otherwise). `DEBUG=1` prints the browser log when the page does not report results.
|
|
148
456
|
|
|
149
457
|
## Project structure
|
|
150
458
|
|
|
@@ -154,10 +462,13 @@ src/
|
|
|
154
462
|
index.html, example.js example page
|
|
155
463
|
libs/
|
|
156
464
|
config/ default configuration, application hooks
|
|
157
|
-
|
|
465
|
+
core/ DOM / focus helpers, validation, translations, CSV, formatting, sanitizer, table math
|
|
466
|
+
hephaestus/ script and theme loader, generators (layout, menu, forms, charts, tables, feedback,
|
|
467
|
+
dialogs, navigation, components, inputs), router, session
|
|
158
468
|
crypto-js/, js-cookie/ submodules
|
|
159
469
|
libs.js classic scripts loaded at runtime
|
|
160
|
-
res/themes/
|
|
470
|
+
res/themes/ default and dark theme
|
|
471
|
+
tests/ unit tests (Node) and browser tests (headless Chrome)
|
|
161
472
|
```
|
|
162
473
|
|
|
163
474
|
## Authors
|
|
@@ -170,6 +481,54 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
|
170
481
|
|
|
171
482
|
## Releases
|
|
172
483
|
|
|
484
|
+
### 1.1.0
|
|
485
|
+
#### Added:
|
|
486
|
+
1. `generateDropZone` / `createDropZone`: drag-and-drop area with file type, size and count checks
|
|
487
|
+
2. `generateWysiwyg` / `createWysiwyg` and the `wysiwyg` form field: rich text editor with a sanitized HTML source view
|
|
488
|
+
#### Changed:
|
|
489
|
+
1. `generateFileUpload` is built on the drop zone; dragging over child elements no longer flickers
|
|
490
|
+
|
|
491
|
+
### 1.0.0
|
|
492
|
+
#### Added:
|
|
493
|
+
1. Stable public API (semantic versioning from this release on)
|
|
494
|
+
2. README: status, known limits and quick links
|
|
495
|
+
#### Changed:
|
|
496
|
+
1. Version bumped to 1.0.0, no breaking changes since 0.7.0
|
|
497
|
+
|
|
498
|
+
### 0.7.0
|
|
499
|
+
#### Added:
|
|
500
|
+
1. Menus with submenus: `children` on a menu item, with keyboard support
|
|
501
|
+
2. Tables: resizable columns (mouse and keyboard) and virtual scrolling (`virtual`) for thousands of rows
|
|
502
|
+
3. `generateDateRange` and the `daterange` form field
|
|
503
|
+
4. `generateRichText` / `createRichText` and the `richtext` form field, with an allow-list sanitizer (`sanitizeHtml`, `isSafeUrl`)
|
|
504
|
+
5. Browser tests in headless Chrome (`npm run test:browser`), more unit tests
|
|
505
|
+
#### Changed:
|
|
506
|
+
1. English and Hungarian texts for the new components
|
|
507
|
+
|
|
508
|
+
### 0.6.0
|
|
509
|
+
#### Added:
|
|
510
|
+
1. Form builder (`generateForm`, `generateField`, `generateButton`) with validation, textarea, select, radio / checkbox groups, switch, autocomplete and multi select
|
|
511
|
+
2. Feedback: `showToast`, `generateAlert`, `generateSpinner`, `generateProgress`; dialogs: `alertDialog`, `confirmDialog`, `promptDialog`, `showDialog`
|
|
512
|
+
3. Navigation: tabs, accordion, dropdown, sidebar, breadcrumbs, pagination; `createRouter`
|
|
513
|
+
4. Components: card, grid, section, badge, avatar, stat, tooltip, link
|
|
514
|
+
5. `generateFileUpload` with progress, `generateStepper`
|
|
515
|
+
6. Tables: row selection, inline editing, CSV export
|
|
516
|
+
7. Session handling, change password form, "Remember me" in the login form
|
|
517
|
+
8. Dark theme, `setTheme`, CSS variables, responsive styles
|
|
518
|
+
9. Translations (English, Hungarian), `translate`, `setLocale`, `addMessages`
|
|
519
|
+
10. Unit tests (`npm test`)
|
|
520
|
+
#### Changed:
|
|
521
|
+
1. Modals trap the focus, close with Esc and restore the focus
|
|
522
|
+
2. The texts of the forms and of the table go through `translate`; the registration form checks its fields with the shared validator
|
|
523
|
+
3. `init` accepts the `changePassword` callback
|
|
524
|
+
|
|
525
|
+
### 0.5.0
|
|
526
|
+
#### Added:
|
|
527
|
+
1. `generateChart`: bar, line, pie and donut charts as inline SVG
|
|
528
|
+
2. `generateTable`: sortable, filterable, paginated tables
|
|
529
|
+
3. `generateRegistrationForm` and `generateLostPasswordForm`, with the `register` / `lostPassword` callbacks and the `registration_enabled` / `lost_password_enabled` settings
|
|
530
|
+
4. Example page shows all of them
|
|
531
|
+
|
|
173
532
|
### 0.4.1
|
|
174
533
|
#### Changed:
|
|
175
534
|
1. HTMLControlGenerator v0.4.0, HTMLElementGenerator v0.3.0, js-cookie updated to the latest master
|
package/package.json
CHANGED
|
@@ -1,60 +1,84 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "athena-ui-js",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "A small jQuery based UI framework: generated page layout, menus, login
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "./src/athena-ui.js",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"src/
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"src/
|
|
18
|
-
"src/libs/
|
|
19
|
-
"src/libs/
|
|
20
|
-
"src/libs/hephaestus/
|
|
21
|
-
"src/libs/hephaestus/
|
|
22
|
-
"src/libs/hephaestus/
|
|
23
|
-
"src/libs/hephaestus/
|
|
24
|
-
"src/libs/
|
|
25
|
-
"src/libs/hephaestus/
|
|
26
|
-
"src/libs/
|
|
27
|
-
"src/libs/
|
|
28
|
-
"src/libs/
|
|
29
|
-
"src/libs/
|
|
30
|
-
"src/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "athena-ui-js",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "A small jQuery based UI framework: generated page layout, menus, login / registration / lost password forms, charts, tables, modals and themes, written as ES modules.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/athena-ui.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "node --test tests/*.test.js",
|
|
9
|
+
"test:browser": "node tests/browser/run.mjs"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./src/athena-ui.js",
|
|
13
|
+
"./themes/*": "./src/res/themes/*",
|
|
14
|
+
"./package.json": "./package.json"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"src/athena-ui.js",
|
|
18
|
+
"src/libs/libs.js",
|
|
19
|
+
"src/libs/config",
|
|
20
|
+
"src/libs/hephaestus/hephaestus.js",
|
|
21
|
+
"src/libs/hephaestus/LayoutGenerator",
|
|
22
|
+
"src/libs/hephaestus/MenuGenerator",
|
|
23
|
+
"src/libs/hephaestus/formGenerator",
|
|
24
|
+
"src/libs/core",
|
|
25
|
+
"src/libs/hephaestus/auth",
|
|
26
|
+
"src/libs/hephaestus/router",
|
|
27
|
+
"src/libs/hephaestus/feedbackGenerator",
|
|
28
|
+
"src/libs/hephaestus/dialogGenerator",
|
|
29
|
+
"src/libs/hephaestus/navigationGenerator",
|
|
30
|
+
"src/libs/hephaestus/componentGenerator",
|
|
31
|
+
"src/libs/hephaestus/inputGenerator",
|
|
32
|
+
"src/libs/hephaestus/chartGenerator",
|
|
33
|
+
"src/libs/hephaestus/tableGenerator",
|
|
34
|
+
"src/libs/hephaestus/modalGenerator",
|
|
35
|
+
"src/libs/hephaestus/HTMLControlGenerator/LICENSE",
|
|
36
|
+
"src/libs/hephaestus/HTMLControlGenerator/src/HTMLControlGenerator.min.js",
|
|
37
|
+
"src/libs/hephaestus/HTMLElementGenerator/LICENSE",
|
|
38
|
+
"src/libs/hephaestus/HTMLElementGenerator/src/HTMLElementGenerator.js",
|
|
39
|
+
"src/libs/hephaestus/HTMLElementGenerator/src/errors.js",
|
|
40
|
+
"src/libs/crypto-js/LICENSE",
|
|
41
|
+
"src/libs/crypto-js/crypto-js.js",
|
|
42
|
+
"src/libs/js-cookie/LICENSE",
|
|
43
|
+
"src/libs/js-cookie/src",
|
|
44
|
+
"src/res"
|
|
45
|
+
],
|
|
46
|
+
"sideEffects": true,
|
|
47
|
+
"keywords": [
|
|
48
|
+
"ui",
|
|
49
|
+
"framework",
|
|
50
|
+
"jquery",
|
|
51
|
+
"layout",
|
|
52
|
+
"menu",
|
|
53
|
+
"login-form",
|
|
54
|
+
"registration-form",
|
|
55
|
+
"chart",
|
|
56
|
+
"table",
|
|
57
|
+
"form-builder",
|
|
58
|
+
"dialog",
|
|
59
|
+
"router",
|
|
60
|
+
"dark-theme",
|
|
61
|
+
"i18n",
|
|
62
|
+
"rich-text",
|
|
63
|
+
"virtual-scroll",
|
|
64
|
+
"modal",
|
|
65
|
+
"themes",
|
|
66
|
+
"es-modules"
|
|
67
|
+
],
|
|
68
|
+
"peerDependencies": {
|
|
69
|
+
"jquery": "^4.0.0"
|
|
70
|
+
},
|
|
71
|
+
"publishConfig": {
|
|
72
|
+
"access": "public"
|
|
73
|
+
},
|
|
74
|
+
"repository": {
|
|
75
|
+
"type": "git",
|
|
76
|
+
"url": "git+https://github.com/csabatibortoth/athena-ui.git"
|
|
77
|
+
},
|
|
78
|
+
"homepage": "https://github.com/csabatibortoth/athena-ui#readme",
|
|
79
|
+
"bugs": {
|
|
80
|
+
"url": "https://github.com/csabatibortoth/athena-ui/issues"
|
|
81
|
+
},
|
|
82
|
+
"author": "Csaba Tóth (https://github.com/csabatibortoth)",
|
|
83
|
+
"license": "MIT"
|
|
84
|
+
}
|