athena-ui-js 1.0.0 → 1.2.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 +68 -6
- package/package.json +3 -1
- package/src/athena-ui.js +4 -1
- package/src/libs/config/config.js +1 -1
- package/src/libs/core/combobox.js +1 -1
- package/src/libs/core/dom.js +30 -3
- package/src/libs/core/i18n.js +6 -2
- package/src/libs/hephaestus/chartGenerator/chartGenerator.js +36 -3
- package/src/libs/hephaestus/componentGenerator/componentGenerator.js +5 -4
- package/src/libs/hephaestus/dialogGenerator/dialogGenerator.js +12 -5
- package/src/libs/hephaestus/feedbackGenerator/feedbackGenerator.js +2 -2
- package/src/libs/hephaestus/formGenerator/formBuilder.js +9 -9
- package/src/libs/hephaestus/inputGenerator/dropZoneGenerator.js +118 -0
- package/src/libs/hephaestus/inputGenerator/inputGenerator.js +14 -29
- package/src/libs/hephaestus/inputGenerator/richTextGenerator.js +41 -6
- package/src/libs/hephaestus/navigationGenerator/navigationGenerator.js +20 -11
- package/src/libs/hephaestus/router/router.js +2 -1
- package/src/libs/hephaestus/tableGenerator/tableGenerator.js +80 -15
- package/src/res/themes/default/style.css +68 -2
- package/src/testing.js +71 -0
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ layout (header, menu, content wrapper, footer) from a single `init()` call, load
|
|
|
5
5
|
and theme, and ships the building blocks of a multipurpose application: forms, tables, charts,
|
|
6
6
|
feedback, navigation, a router and more.
|
|
7
7
|
|
|
8
|
-
Current version: **1.
|
|
8
|
+
Current version: **1.2.0**
|
|
9
9
|
|
|
10
10
|
[Quick start](#usage) · [API](#api) · [Components](#charts) · [Themes](#themes) · [Tests](#tests) · [Release notes](#releases)
|
|
11
11
|
|
|
@@ -17,7 +17,7 @@ Known limits are listed below, so you can judge whether it fits your project:
|
|
|
17
17
|
|
|
18
18
|
- Rich text uses the deprecated `document.execCommand`. Content is sanitized in the browser, but sanitize it on the server too.
|
|
19
19
|
- The session cookie is readable from JavaScript. It is a UI state, not a security boundary: authenticate on the server.
|
|
20
|
-
- Virtual table rows have to be a fixed height, one line per cell.
|
|
20
|
+
- Virtual table rows have to be a fixed height, one line per cell (set it with `virtual.rowHeight`; the CSS variable `--row-height` follows).
|
|
21
21
|
- Translations: English and Hungarian.
|
|
22
22
|
|
|
23
23
|
## Features
|
|
@@ -31,7 +31,7 @@ Known limits are listed below, so you can judge whether it fits your project:
|
|
|
31
31
|
- Buttons, toasts, alerts, spinner, progress bar, alert / confirm / prompt dialogs
|
|
32
32
|
- Tabs, accordion, dropdown, sidebar, breadcrumbs, pagination and a hash / history router
|
|
33
33
|
- Cards, grid, badges, avatars, KPI tiles, tooltips, links, sections
|
|
34
|
-
- File upload with progress, stepper (wizard), date range picker, rich text editor
|
|
34
|
+
- File upload with progress, drag-and-drop area, stepper (wizard), date range picker, rich text and WYSIWYG editor
|
|
35
35
|
- Menus with submenus
|
|
36
36
|
- Session handling (login state in a cookie), change password form
|
|
37
37
|
- Default and dark theme (switchable at runtime), responsive, translations (English, Hungarian), keyboard and ARIA support
|
|
@@ -120,7 +120,7 @@ the theme are loaded and the layout is generated.
|
|
|
120
120
|
| `header_title_text` | `"Athena UI"` | Title in the header |
|
|
121
121
|
| `header_img_url` | | Header logo URL |
|
|
122
122
|
| `copyright` | placeholder text | Footer text, the version is appended |
|
|
123
|
-
| `version` | `"1.
|
|
123
|
+
| `version` | `"1.2.0"` | Version shown in the footer |
|
|
124
124
|
| `bordered` | `true` | Draw a border around the layout blocks |
|
|
125
125
|
| `generateHeader`, `generateFooter` | `true` | Generate the header / footer block |
|
|
126
126
|
| `generateHeadercontent`, `generateFooterContent`, `generateWrappercontent` | `true` | Generate the content of the block |
|
|
@@ -159,7 +159,7 @@ Everything is exported from `athena-ui.js`:
|
|
|
159
159
|
| `generateTabs`, `generateBreadcrumbs`, `generatePagination`, `generateAccordion`, `generateDropdown`, `generateSidebar` | See [Navigation](#navigation) |
|
|
160
160
|
| `createRouter(options)` | See [Router](#router) |
|
|
161
161
|
| `generateCard`, `generateSection`, `generateGrid`, `generateBadge`, `generateAvatar`, `generateStat`, `generateLink`, `generateTooltip` | See [Components](#components) |
|
|
162
|
-
| `generateAutocomplete`, `generateMultiSelect`, `generateFileUpload`, `generateStepper`, `generateDateRange`, `generateRichText` | See [Inputs](#inputs) |
|
|
162
|
+
| `generateAutocomplete`, `generateMultiSelect`, `generateFileUpload`, `generateDropZone`, `generateStepper`, `generateDateRange`, `generateRichText`, `generateWysiwyg` | See [Inputs](#inputs) |
|
|
163
163
|
| `sanitizeHtml(html)`, `htmlToText(html)`, `isSafeUrl(url)` | The allow-list sanitizer behind the rich text editor |
|
|
164
164
|
| `setSession`, `getSession`, `isLoggedIn`, `logout`, `onSessionChange` | See [Session](#session) |
|
|
165
165
|
| `translate`, `setLocale`, `getLocale`, `addMessages` | See [Translations](#translations) |
|
|
@@ -211,6 +211,9 @@ Click a header to sort (disable with `sortable: false`, or per column). Other op
|
|
|
211
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
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
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
|
+
- Hooks and looks: `cellClass(row, column)` and `rowClass(row)` return a class name (or a list) for a cell or a row. `focusableRows: true` makes rows reachable with Tab (`rowLabel(row)` is their aria-label); together with `onRowClick` they open with Enter and Space. `density: "compact"`, and `wrap: true | false` (long text wraps, or stays on one line with an ellipsis). The pager is hidden when there is only one page.
|
|
215
|
+
- Column extras: `render(row, value)` returns text or a Node (built by you, so it is safe by construction), `align: "left" | "center" | "right"`. Text longer than 24 characters gets its full text as a tooltip (`title: false` switches it off).
|
|
216
|
+
- 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.
|
|
214
217
|
- `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
218
|
|
|
216
219
|
### Forms
|
|
@@ -234,7 +237,7 @@ const form = generateForm({
|
|
|
234
237
|
|
|
235
238
|
Field types: `text`, `password`, `email`, `number`, `date`, `datetime-local`, `time`, `month`, `week`, `url`, `tel`,
|
|
236
239
|
`search`, `color`, `range`, `file`, `hidden`, `textarea`, `select` (`multiple`), `checkbox`, `switch`, `radio`,
|
|
237
|
-
`checkboxes`, `autocomplete`, `multiselect`, `daterange` (value `{ from, to }`), `richtext` (value: safe HTML).
|
|
240
|
+
`checkboxes`, `autocomplete`, `multiselect`, `daterange` (value `{ from, to }`), `richtext` and `wysiwyg` (value: safe HTML).
|
|
238
241
|
The date, time and color types use the native pickers of the browser.
|
|
239
242
|
|
|
240
243
|
Rules (`required`, `email`, `minLength`, `maxLength`, `pattern`, `min`, `max`, `match`, `validate(value, values)`) can be
|
|
@@ -266,6 +269,10 @@ const name = await promptDialog("Your name", { validate: v => v ? "" : "Required
|
|
|
266
269
|
const choice = await showDialog({ title: "Custom", content: "Pick one", buttons: [{ text: "A", value: "a" }, { text: "B", value: "b" }] });
|
|
267
270
|
```
|
|
268
271
|
|
|
272
|
+
Options: `size` ("small" 360 px, "medium" 480 px, "large" 720 px, "full") and `class` (extra class on the dialog).
|
|
273
|
+
`showDialog` returns a promise that also carries the open dialog: `const dialog = showDialog({ size: "large", ... }); dialog.element; dialog.close(value);`.
|
|
274
|
+
The dialog is shown by a CSS class, not by an inline style, so a strict Content-Security-Policy works.
|
|
275
|
+
|
|
269
276
|
Dialogs trap the focus, close with Esc (resolving `null` / `false`) and restore the focus. Text content is
|
|
270
277
|
never parsed as HTML. `openModal` / `closeModal` got the same focus handling.
|
|
271
278
|
|
|
@@ -275,6 +282,7 @@ never parsed as HTML. `openModal` / `closeModal` got the same focus handling.
|
|
|
275
282
|
generateTabs({ parent: "wrapper", tabs: [{ id: "a", label: "A", content: "First" }, { id: "b", label: "B", content: () => lazyNode() }] });
|
|
276
283
|
generateAccordion({ parent: "wrapper", items: [{ title: "Q", content: "A", open: true }], multiple: false });
|
|
277
284
|
generateDropdown({ parent: "wrapper", label: "Actions", items: [{ label: "Edit", onclick }, { divider: true }, { label: "Delete", onclick }] });
|
|
285
|
+
generateDropdown({ parent: "wrapper", icon: "⋮", ariaLabel: "More actions", items: [{ label: "Edit", onclick }] }); // icon only; also caret: true, toggleClass
|
|
278
286
|
generatePagination({ parent: "wrapper", total: 200, pageSize: 10, onChange: page => load(page) });
|
|
279
287
|
generateBreadcrumbs({ parent: "wrapper", items: [{ label: "Home", href: "#/" }, { label: "Users" }] });
|
|
280
288
|
generateSidebar({ parent: "wrapper", active: "home", onSelect: item => go(item.id),
|
|
@@ -366,6 +374,17 @@ strike, lists, quotes, code, links). Everything else (scripts, styles, iframes,
|
|
|
366
374
|
`quote`, `ul`, `ol`, `link`, `unlink`, `clear`, `undo`, `redo`. The editor is built on `contenteditable` and
|
|
367
375
|
`document.execCommand`, which every browser still supports; sanitize on the server as well, as with any HTML you accept.
|
|
368
376
|
|
|
377
|
+
```js
|
|
378
|
+
generateDropZone({ parent: "wrapper", accept: "image/*", maxSize: 2 * 1024 * 1024, maxFiles: 3,
|
|
379
|
+
onDrop: files => {}, onReject: rejected => rejected.forEach(({ file, reason }) => {}) });
|
|
380
|
+
const wysiwyg = generateWysiwyg({ parent: "wrapper", label: "Body", value: "<p>Hello</p>" }); // rich text + HTML source view
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
`generateDropZone` is a bare drag-and-drop area (also reachable with Enter / Space and the file dialog). Dropped files are
|
|
384
|
+
checked against `accept`, `maxSize` and `maxFiles`; valid ones go to `onDrop`, the others to `onReject` with a reason. It
|
|
385
|
+
reads and sends nothing, and `setDisabled(true)` turns it off. `generateWysiwyg` is the rich text editor plus a `source`
|
|
386
|
+
toolbar button that shows the sanitized HTML; what is typed there is sanitized again when you switch back.
|
|
387
|
+
|
|
369
388
|
Files are sent as a multipart POST (`fieldName`, `headers` are configurable). Without `url` the files are only collected,
|
|
370
389
|
read them with `getFiles()`.
|
|
371
390
|
|
|
@@ -430,6 +449,29 @@ The default theme is in `src/res/themes/default/style.css`; `{ id: 1 }` is a dar
|
|
|
430
449
|
|
|
431
450
|
Switch themes at runtime with `setTheme({ id: 1 })`.
|
|
432
451
|
|
|
452
|
+
### Parents and handles
|
|
453
|
+
|
|
454
|
+
Every `parent` option takes an element, an id or a CSS selector (`"wrapper"`, `"#list"`, `".panel > ul"`; an id wins over a selector).
|
|
455
|
+
The components return the same kind of handle: `{ element, update(), destroy() }`, plus their own methods. `destroy()` removes the
|
|
456
|
+
component. `update()` redraws it where that makes sense (`table.update({ rows })`, `chart.update({ series })`, `stat.update({ value })`,
|
|
457
|
+
`progress.update({ value })`) and otherwise just returns the handle. `generateChart` still returns the SVG element, which also carries
|
|
458
|
+
`element`, `update(options)` and `destroy()`.
|
|
459
|
+
|
|
460
|
+
### Testing your application
|
|
461
|
+
|
|
462
|
+
```js
|
|
463
|
+
import { JSDOM } from "jsdom";
|
|
464
|
+
import { installDom, until, tick } from "athena-ui-js/testing";
|
|
465
|
+
|
|
466
|
+
const dom = installDom(JSDOM); // window, document, Node, Event, ... become global
|
|
467
|
+
generateDropdown({ parent: "#wrapper", icon: "x", ariaLabel: "More", items: [] });
|
|
468
|
+
await until(() => document.querySelector(".dropdown"), { message: "the dropdown" });
|
|
469
|
+
dom.uninstall();
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
`installDom` takes your own `JSDOM` class, so Athena UI has no dependency on jsdom. Athena creates its events from the element's own
|
|
473
|
+
window, so they work in jsdom without a global `Event`.
|
|
474
|
+
|
|
433
475
|
## Tests
|
|
434
476
|
|
|
435
477
|
```sh
|
|
@@ -470,6 +512,26 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
|
470
512
|
|
|
471
513
|
## Releases
|
|
472
514
|
|
|
515
|
+
### 1.2.0
|
|
516
|
+
#### Added:
|
|
517
|
+
1. Dialogs: `size` and `class` options, and the open dialog (`element`, `backdrop`, `close()`) on the returned promise
|
|
518
|
+
2. Tables: `cellClass`, `rowClass`, `focusableRows` / `rowLabel`, `density`, `wrap`, column `render` (text or Node), `align`, tooltip for cut text
|
|
519
|
+
3. Dropdown: `icon`, `ariaLabel`, `caret`, `toggleClass`; the label is optional
|
|
520
|
+
4. Every `parent` option takes an element, an id or a CSS selector; the components share the handle `{ element, update(), destroy() }`
|
|
521
|
+
5. `athena-ui-js/testing`: `installDom`, `until`, `tick`
|
|
522
|
+
#### Changed:
|
|
523
|
+
1. The dialog backdrop is shown by a CSS class, not by an inline style (works with a strict Content-Security-Policy)
|
|
524
|
+
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
|
|
525
|
+
3. The combobox creates its events from the element's own window (no more jsdom errors)
|
|
526
|
+
4. The pager of a table with one page is hidden
|
|
527
|
+
|
|
528
|
+
### 1.1.0
|
|
529
|
+
#### Added:
|
|
530
|
+
1. `generateDropZone` / `createDropZone`: drag-and-drop area with file type, size and count checks
|
|
531
|
+
2. `generateWysiwyg` / `createWysiwyg` and the `wysiwyg` form field: rich text editor with a sanitized HTML source view
|
|
532
|
+
#### Changed:
|
|
533
|
+
1. `generateFileUpload` is built on the drop zone; dragging over child elements no longer flickers
|
|
534
|
+
|
|
473
535
|
### 1.0.0
|
|
474
536
|
#### Added:
|
|
475
537
|
1. Stable public API (semantic versioning from this release on)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "athena-ui-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
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
5
|
"type": "module",
|
|
6
6
|
"main": "./src/athena-ui.js",
|
|
@@ -10,11 +10,13 @@
|
|
|
10
10
|
},
|
|
11
11
|
"exports": {
|
|
12
12
|
".": "./src/athena-ui.js",
|
|
13
|
+
"./testing": "./src/testing.js",
|
|
13
14
|
"./themes/*": "./src/res/themes/*",
|
|
14
15
|
"./package.json": "./package.json"
|
|
15
16
|
},
|
|
16
17
|
"files": [
|
|
17
18
|
"src/athena-ui.js",
|
|
19
|
+
"src/testing.js",
|
|
18
20
|
"src/libs/libs.js",
|
|
19
21
|
"src/libs/config",
|
|
20
22
|
"src/libs/hephaestus/hephaestus.js",
|
package/src/athena-ui.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
//Author: Csaba Tóth https://github.com/csabatibortoth/
|
|
3
3
|
//LICENCE: MIT
|
|
4
4
|
//Repository: https://github.com/csabatibortoth/athena-ui
|
|
5
|
-
//Version: 1.
|
|
5
|
+
//Version: 1.2.0
|
|
6
6
|
|
|
7
7
|
/* global $ */
|
|
8
8
|
|
|
@@ -26,6 +26,7 @@ import * as dialog from "./libs/hephaestus/dialogGenerator/dialogGenerator.js";
|
|
|
26
26
|
import * as navigation from "./libs/hephaestus/navigationGenerator/navigationGenerator.js";
|
|
27
27
|
import * as components from "./libs/hephaestus/componentGenerator/componentGenerator.js";
|
|
28
28
|
import * as inputs from "./libs/hephaestus/inputGenerator/inputGenerator.js";
|
|
29
|
+
import * as dropZone from "./libs/hephaestus/inputGenerator/dropZoneGenerator.js";
|
|
29
30
|
import * as richText from "./libs/hephaestus/inputGenerator/richTextGenerator.js";
|
|
30
31
|
import * as sanitize from "./libs/core/sanitize.js";
|
|
31
32
|
import * as router from "./libs/hephaestus/router/router.js";
|
|
@@ -99,6 +100,7 @@ const AthenaUI = {
|
|
|
99
100
|
...navigation,
|
|
100
101
|
...components,
|
|
101
102
|
...inputs,
|
|
103
|
+
...dropZone,
|
|
102
104
|
...richText,
|
|
103
105
|
...sanitize,
|
|
104
106
|
...router,
|
|
@@ -134,6 +136,7 @@ export * from "./libs/hephaestus/dialogGenerator/dialogGenerator.js";
|
|
|
134
136
|
export * from "./libs/hephaestus/navigationGenerator/navigationGenerator.js";
|
|
135
137
|
export * from "./libs/hephaestus/componentGenerator/componentGenerator.js";
|
|
136
138
|
export * from "./libs/hephaestus/inputGenerator/inputGenerator.js";
|
|
139
|
+
export * from "./libs/hephaestus/inputGenerator/dropZoneGenerator.js";
|
|
137
140
|
export * from "./libs/hephaestus/inputGenerator/richTextGenerator.js";
|
|
138
141
|
export * from "./libs/core/sanitize.js";
|
|
139
142
|
export * from "./libs/hephaestus/router/router.js";
|
|
@@ -36,7 +36,7 @@ export function createCombobox(options = {}) {
|
|
|
36
36
|
const element = el("div", { class: cx("combobox", multiple && "combobox-multiple", options.class) }, chips, input, list);
|
|
37
37
|
|
|
38
38
|
const notify = () => {
|
|
39
|
-
input.dispatchEvent(new Event("change", { bubbles: true }));
|
|
39
|
+
input.dispatchEvent(new (input.ownerDocument.defaultView.Event)("change", { bubbles: true }));
|
|
40
40
|
onChange?.(getValue());
|
|
41
41
|
};
|
|
42
42
|
const isOpen = () => !list.hidden;
|
package/src/libs/core/dom.js
CHANGED
|
@@ -47,11 +47,38 @@ export function setContent(node, content) {
|
|
|
47
47
|
return node;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Finds an element from an element, an id or a CSS selector ("#list", ".panel > ul").
|
|
52
|
+
* An id wins over a selector with the same text. Returns null when nothing matches.
|
|
53
|
+
*/
|
|
54
|
+
export function resolveElement(target) {
|
|
55
|
+
if (target instanceof Element) return target;
|
|
56
|
+
if (typeof target !== "string" || !target) return null;
|
|
57
|
+
const byId = document.getElementById(target);
|
|
58
|
+
if (byId) return byId;
|
|
59
|
+
try {
|
|
60
|
+
return document.querySelector(target);
|
|
61
|
+
} catch {
|
|
62
|
+
return null; // not a valid selector
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Appends a node to a parent given as element, id or selector. Falls back to the body.
|
|
51
67
|
export function mount(parent, node) {
|
|
52
|
-
|
|
53
|
-
(host ?? document.body).append(node);
|
|
68
|
+
(resolveElement(parent) ?? document.body).append(node);
|
|
54
69
|
return node;
|
|
55
70
|
}
|
|
56
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Gives a component the same handle as every other one: { element, update(), destroy() }.
|
|
74
|
+
* What the component already has is kept. `update` does nothing unless the component supports it
|
|
75
|
+
* (it returns the handle), `destroy` removes the element (and `also`, e.g. a wrapper around it).
|
|
76
|
+
*/
|
|
77
|
+
export function asHandle(handle, { element = handle.element, also } = {}) {
|
|
78
|
+
handle.element ??= element;
|
|
79
|
+
handle.update ??= () => handle;
|
|
80
|
+
handle.destroy ??= () => (also ?? element)?.remove();
|
|
81
|
+
return handle;
|
|
82
|
+
}
|
|
83
|
+
|
|
57
84
|
export const cx = (...classes) => classes.filter(Boolean).join(" ");
|
package/src/libs/core/i18n.js
CHANGED
|
@@ -44,6 +44,7 @@ const messages = {
|
|
|
44
44
|
"validation.match": "The values do not match.",
|
|
45
45
|
"validation.invalid": "The value is invalid.",
|
|
46
46
|
"validation.fileSize": "{name} is larger than {max}.",
|
|
47
|
+
"validation.maxFiles": "At most {max} files are accepted.",
|
|
47
48
|
"validation.url": "Enter a valid address (https://, mailto: or tel:).",
|
|
48
49
|
"validation.dateRange": "The end date must not be before the start date.",
|
|
49
50
|
"validation.dateMin": "The date must be {min} or later.",
|
|
@@ -68,7 +69,8 @@ const messages = {
|
|
|
68
69
|
"rt.clear": "Clear formatting",
|
|
69
70
|
"rt.undo": "Undo",
|
|
70
71
|
"rt.redo": "Redo",
|
|
71
|
-
"rt.linkPrompt": "Link address"
|
|
72
|
+
"rt.linkPrompt": "Link address",
|
|
73
|
+
"rt.source": "HTML source"
|
|
72
74
|
},
|
|
73
75
|
hu: {
|
|
74
76
|
username: "Felhasználónév",
|
|
@@ -107,6 +109,7 @@ const messages = {
|
|
|
107
109
|
"validation.match": "Az értékek nem egyeznek.",
|
|
108
110
|
"validation.invalid": "Érvénytelen érték.",
|
|
109
111
|
"validation.fileSize": "{name} mérete meghaladja a {max} értéket.",
|
|
112
|
+
"validation.maxFiles": "Legfeljebb {max} fájl fogadható el.",
|
|
110
113
|
"validation.url": "Adjon meg érvényes címet (https://, mailto: vagy tel:).",
|
|
111
114
|
"validation.dateRange": "A záró dátum nem lehet korábbi a kezdő dátumnál.",
|
|
112
115
|
"validation.dateMin": "A dátum legkorábban {min} lehet.",
|
|
@@ -131,7 +134,8 @@ const messages = {
|
|
|
131
134
|
"rt.clear": "Formázás törlése",
|
|
132
135
|
"rt.undo": "Visszavonás",
|
|
133
136
|
"rt.redo": "Újra",
|
|
134
|
-
"rt.linkPrompt": "Hivatkozás címe"
|
|
137
|
+
"rt.linkPrompt": "Hivatkozás címe",
|
|
138
|
+
"rt.source": "HTML forrás"
|
|
135
139
|
}
|
|
136
140
|
};
|
|
137
141
|
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
// Dependency free SVG charts: bar, line, pie and donut.
|
|
7
7
|
|
|
8
|
+
import { resolveElement } from "../../core/dom.js";
|
|
9
|
+
|
|
8
10
|
const NS = "http://www.w3.org/2000/svg";
|
|
9
11
|
const PALETTE = ["#4e79a7", "#f28e2b", "#e15759", "#76b7b2", "#59a14f", "#edc948", "#b07aa1", "#ff9da7", "#9c755f", "#bab0ac"];
|
|
10
12
|
const MARGIN = { top: 40, right: 20, bottom: 50, left: 55 };
|
|
@@ -157,10 +159,42 @@ const DRAWERS = {
|
|
|
157
159
|
* @param {number} [options.width=600]
|
|
158
160
|
* @param {number} [options.height=360]
|
|
159
161
|
* @param {boolean} [options.legend] default: shown for several series, and for pie / donut
|
|
160
|
-
* @returns {SVGElement
|
|
162
|
+
* @returns {(SVGElement & {element: SVGElement, update: (options?: object) => void, destroy: () => void})|null}
|
|
163
|
+
* the SVG element, which also carries the handle ({ element, update(options), destroy() }) of the other
|
|
164
|
+
* components; null when the options are invalid. `parent` is an element, an id or a selector.
|
|
161
165
|
*/
|
|
162
166
|
export function generateChart(options = {}) {
|
|
163
|
-
const
|
|
167
|
+
const svg = buildChart(options);
|
|
168
|
+
if (!svg) return null;
|
|
169
|
+
(resolveElement(options.parent ?? "wrapper") ?? document.body).append(svg);
|
|
170
|
+
return withHandle(svg, options);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// update(changes) draws the chart again with the old options plus the changes, in the same place.
|
|
174
|
+
function withHandle(svg, options) {
|
|
175
|
+
let current = svg;
|
|
176
|
+
let used = options;
|
|
177
|
+
const handle = {
|
|
178
|
+
get element() { return current; },
|
|
179
|
+
update(changes = {}) {
|
|
180
|
+
const next = buildChart({ ...used, ...changes });
|
|
181
|
+
if (!next) return current;
|
|
182
|
+
used = { ...used, ...changes };
|
|
183
|
+
current.replaceWith(next);
|
|
184
|
+
current = withHandle(next, used);
|
|
185
|
+
return current;
|
|
186
|
+
},
|
|
187
|
+
destroy() { current.remove(); }
|
|
188
|
+
};
|
|
189
|
+
return Object.defineProperties(svg, {
|
|
190
|
+
element: { get: () => handle.element, configurable: true },
|
|
191
|
+
update: { value: handle.update, configurable: true },
|
|
192
|
+
destroy: { value: handle.destroy, configurable: true }
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function buildChart(options = {}) {
|
|
197
|
+
const { type = "bar", id, title, width = 600, height = 360 } = options;
|
|
164
198
|
const draw = DRAWERS[type];
|
|
165
199
|
const series = (options.series ?? []).filter(s => Array.isArray(s?.data) && s.data.length);
|
|
166
200
|
if (!draw || !series.length) {
|
|
@@ -182,6 +216,5 @@ export function generateChart(options = {}) {
|
|
|
182
216
|
if (options.legend ?? (Boolean(pieLegend) || series.length > 1)) {
|
|
183
217
|
addLegend(svg, pieLegend ?? series.map((s, i) => ({ name: s.name ?? `Series ${i + 1}`, color: colorOf(s, i) })), width, height);
|
|
184
218
|
}
|
|
185
|
-
(document.getElementById(parent) ?? document.body).append(svg);
|
|
186
219
|
return svg;
|
|
187
220
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//LICENCE: MIT
|
|
4
4
|
//Repository: https://github.com/csabatibortoth/athena-ui
|
|
5
5
|
|
|
6
|
-
import { cx, el, mount, setContent, uid } from "../../core/dom.js";
|
|
6
|
+
import { asHandle, cx, el, mount, resolveElement, setContent, uid } from "../../core/dom.js";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Generates a link. External links open in a new tab and get `rel="noopener noreferrer"`.
|
|
@@ -81,7 +81,7 @@ export function generateCard(options = {}) {
|
|
|
81
81
|
card.append(body);
|
|
82
82
|
if (options.footer) card.append(setContent(el("div", { class: "card-footer" }), options.footer));
|
|
83
83
|
mount(options.parent, card);
|
|
84
|
-
return { element: card, body };
|
|
84
|
+
return asHandle({ element: card, body });
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
/**
|
|
@@ -155,7 +155,8 @@ export function generateStat(options = {}) {
|
|
|
155
155
|
element.append(el("div", { class: cx("stat-delta", `stat-${kind}`), text: `${arrow} ${Math.abs(options.delta)}%` }));
|
|
156
156
|
}
|
|
157
157
|
mount(options.parent, element);
|
|
158
|
-
|
|
158
|
+
const setValue = text => { value.textContent = String(text); };
|
|
159
|
+
return asHandle({ element, setValue, update: ({ value: text } = {}) => { if (text != null) setValue(text); } });
|
|
159
160
|
}
|
|
160
161
|
|
|
161
162
|
/**
|
|
@@ -181,7 +182,7 @@ export function generateGrid(options = {}) {
|
|
|
181
182
|
* @param {string} text
|
|
182
183
|
*/
|
|
183
184
|
export function generateTooltip(target, text) {
|
|
184
|
-
const node =
|
|
185
|
+
const node = resolveElement(target);
|
|
185
186
|
if (!node) return null;
|
|
186
187
|
const id = uid("tooltip");
|
|
187
188
|
const tip = el("span", { class: "tooltip-text", id, text, attrs: { role: "tooltip" } });
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//LICENCE: MIT
|
|
4
4
|
//Repository: https://github.com/csabatibortoth/athena-ui
|
|
5
5
|
|
|
6
|
-
import { el, setContent, uid } from "../../core/dom.js";
|
|
6
|
+
import { cx, el, setContent, uid } from "../../core/dom.js";
|
|
7
7
|
import { trapFocus } from "../../core/focus.js";
|
|
8
8
|
import { translate } from "../../core/i18n.js";
|
|
9
9
|
import { generateButton } from "../formGenerator/formBuilder.js";
|
|
@@ -18,21 +18,25 @@ import { generateButton } from "../formGenerator/formBuilder.js";
|
|
|
18
18
|
* @param {{text: string, value?: *, variant?: string, autofocus?: boolean}[]} [options.buttons]
|
|
19
19
|
* @param {boolean} [options.dismissible=true]
|
|
20
20
|
* @param {(value) => (boolean|Promise<boolean>)} [options.beforeClose] return false to keep the dialog open
|
|
21
|
-
* @
|
|
21
|
+
* @param {"small"|"medium"|"large"|"full"} [options.size="medium"] width of the dialog (360 / 480 / 720 px / the whole window)
|
|
22
|
+
* @param {string} [options.class] extra CSS class(es) of the dialog element
|
|
23
|
+
* @returns {Promise<*> & {element: HTMLElement, backdrop: HTMLElement, close: (value?) => Promise<void>}}
|
|
24
|
+
* resolves with the pressed button's value; the promise also carries the handle of the open dialog
|
|
22
25
|
*/
|
|
23
26
|
export function showDialog(options = {}) {
|
|
24
27
|
const { title, content, buttons = [{ text: translate("ok"), value: true }], dismissible = true } = options;
|
|
25
|
-
|
|
28
|
+
let handle;
|
|
29
|
+
const promise = new Promise(resolve => {
|
|
26
30
|
const titleId = uid("dialog-title");
|
|
27
31
|
const body = setContent(el("div", { class: "dialog-body" }), content);
|
|
28
32
|
const footer = el("div", { class: "dialog-footer" });
|
|
29
33
|
const dialog = el("div", {
|
|
30
|
-
class: "modal-content dialog",
|
|
34
|
+
class: cx("modal-content dialog", options.size && `dialog-${options.size}`, options.class),
|
|
31
35
|
attrs: { role: "dialog", "aria-modal": "true", "aria-labelledby": title ? titleId : null }
|
|
32
36
|
});
|
|
33
37
|
if (title) dialog.append(el("h2", { class: "dialog-title", id: titleId, text: title }));
|
|
34
38
|
dialog.append(body, footer);
|
|
35
|
-
const backdrop = el("div", { class: "modal dialog-backdrop"
|
|
39
|
+
const backdrop = el("div", { class: "modal dialog-backdrop" }, dialog);
|
|
36
40
|
|
|
37
41
|
let release = () => {};
|
|
38
42
|
let closing = false;
|
|
@@ -70,7 +74,10 @@ export function showDialog(options = {}) {
|
|
|
70
74
|
document.body.append(backdrop);
|
|
71
75
|
release = trapFocus(dialog, { onEscape: dismissible ? () => close(null) : undefined });
|
|
72
76
|
dialog.querySelector("[data-autofocus]")?.focus();
|
|
77
|
+
handle = { element: dialog, backdrop, close: value => close(value ?? null) };
|
|
73
78
|
});
|
|
79
|
+
// The executor above runs synchronously, so the handle exists here.
|
|
80
|
+
return Object.assign(promise, handle);
|
|
74
81
|
}
|
|
75
82
|
|
|
76
83
|
/** Message with an OK button. Resolves when it is closed. */
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//LICENCE: MIT
|
|
4
4
|
//Repository: https://github.com/csabatibortoth/athena-ui
|
|
5
5
|
|
|
6
|
-
import { cx, el, mount, setContent } from "../../core/dom.js";
|
|
6
|
+
import { asHandle, cx, el, mount, setContent } from "../../core/dom.js";
|
|
7
7
|
import { translate } from "../../core/i18n.js";
|
|
8
8
|
|
|
9
9
|
const TOAST_CONTAINER_ID = "athena-toasts";
|
|
@@ -134,5 +134,5 @@ export function generateProgress(options = {}) {
|
|
|
134
134
|
};
|
|
135
135
|
setValue(options.value);
|
|
136
136
|
mount(options.parent, element);
|
|
137
|
-
return { element, setValue };
|
|
137
|
+
return asHandle({ element, setValue, update: ({ value } = {}) => setValue(value) });
|
|
138
138
|
}
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
|
|
6
6
|
import { createCombobox } from "../../core/combobox.js";
|
|
7
7
|
import { createDateRange } from "../../core/dateRange.js";
|
|
8
|
-
import { cx, el, mount, uid } from "../../core/dom.js";
|
|
8
|
+
import { asHandle, cx, el, mount, uid } from "../../core/dom.js";
|
|
9
9
|
import { translate } from "../../core/i18n.js";
|
|
10
10
|
import { validateDateRange, validateValue } from "../../core/validation.js";
|
|
11
|
-
import { createRichText } from "../inputGenerator/richTextGenerator.js";
|
|
11
|
+
import { createRichText, createWysiwyg } from "../inputGenerator/richTextGenerator.js";
|
|
12
12
|
|
|
13
13
|
const INPUT_TYPES = new Set([
|
|
14
14
|
"text", "password", "email", "number", "date", "datetime-local", "time", "month", "week",
|
|
@@ -58,7 +58,7 @@ export function generateButton(options = {}) {
|
|
|
58
58
|
sync();
|
|
59
59
|
}
|
|
60
60
|
mount(options.parent, element);
|
|
61
|
-
return {
|
|
61
|
+
return asHandle({
|
|
62
62
|
element,
|
|
63
63
|
setLoading(value) {
|
|
64
64
|
loading = Boolean(value);
|
|
@@ -71,7 +71,7 @@ export function generateButton(options = {}) {
|
|
|
71
71
|
setText(text) {
|
|
72
72
|
label.textContent = text;
|
|
73
73
|
}
|
|
74
|
-
};
|
|
74
|
+
});
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/* ------------------FIELD------------------- */
|
|
@@ -94,7 +94,7 @@ function choiceList(wrapper, kind, name, choices, value) {
|
|
|
94
94
|
*
|
|
95
95
|
* @param {object} options
|
|
96
96
|
* @param {string} options.name key of the field in the form values
|
|
97
|
-
* @param {"text"|"password"|"email"|"number"|"date"|"datetime-local"|"time"|"url"|"tel"|"search"|"color"|"range"|"file"|"hidden"|"textarea"|"select"|"checkbox"|"switch"|"radio"|"checkboxes"|"autocomplete"|"multiselect"|"daterange"|"richtext"} [options.type="text"]
|
|
97
|
+
* @param {"text"|"password"|"email"|"number"|"date"|"datetime-local"|"time"|"url"|"tel"|"search"|"color"|"range"|"file"|"hidden"|"textarea"|"select"|"checkbox"|"switch"|"radio"|"checkboxes"|"autocomplete"|"multiselect"|"daterange"|"richtext"|"wysiwyg"} [options.type="text"]
|
|
98
98
|
* @param {string} [options.label]
|
|
99
99
|
* @param {string} [options.help] help text under the control
|
|
100
100
|
* @param {*} [options.value] initial value (boolean for checkbox / switch, array for checkboxes / multiple select)
|
|
@@ -186,8 +186,8 @@ export function generateField(options = {}) {
|
|
|
186
186
|
controlNodes = [range.element];
|
|
187
187
|
getValue = range.getValue;
|
|
188
188
|
setValue = range.setValue;
|
|
189
|
-
} else if (type === "richtext") {
|
|
190
|
-
const rich = createRichText({
|
|
189
|
+
} else if (type === "richtext" || type === "wysiwyg") {
|
|
190
|
+
const rich = (type === "wysiwyg" ? createWysiwyg : createRichText)({
|
|
191
191
|
id, value: options.value, placeholder, minHeight: options.minHeight, toolbar: options.toolbar, disabled: options.disabled
|
|
192
192
|
});
|
|
193
193
|
rich.editor.setAttribute("aria-labelledby", `${id}-label`);
|
|
@@ -277,7 +277,7 @@ export function generateField(options = {}) {
|
|
|
277
277
|
if (event === "change" || event === "input") onChange?.(getValue(), field);
|
|
278
278
|
}));
|
|
279
279
|
});
|
|
280
|
-
return field;
|
|
280
|
+
return asHandle(field);
|
|
281
281
|
}
|
|
282
282
|
|
|
283
283
|
/* ------------------FORM------------------- */
|
|
@@ -375,5 +375,5 @@ export function generateForm(options = {}) {
|
|
|
375
375
|
});
|
|
376
376
|
|
|
377
377
|
mount(options.parent, element);
|
|
378
|
-
return form;
|
|
378
|
+
return asHandle(form);
|
|
379
379
|
}
|