athena-ui-js 2.0.0 → 2.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 +47 -5
- package/docs/migration-2.0.md +1 -1
- package/docs/styling.md +3 -1
- package/package.json +5 -2
- package/src/athena-ui.js +1 -1
- package/src/libs/config/config.js +1 -1
- package/src/libs/core/popover.js +96 -0
- package/src/libs/hephaestus/chartGenerator/chartGenerator.js +26 -2
- package/src/libs/hephaestus/componentGenerator/componentGenerator.js +26 -2
- package/src/libs/hephaestus/navigationGenerator/navigationGenerator.js +45 -9
- package/src/res/themes/default/style.css +32 -0
- package/types/athena-ui.d.ts +96 -96
- package/types/chart.d.ts +1 -1
- package/types/classic.d.ts +1 -1
- package/types/components.d.ts +1 -1
- package/types/controls.d.ts +3 -3
- package/types/csv.d.ts +1 -1
- package/types/dialog.d.ts +2 -2
- package/types/dom.d.ts +1 -1
- package/types/feedback.d.ts +1 -1
- package/types/format.d.ts +1 -1
- package/types/forms.d.ts +2 -2
- package/types/i18n.d.ts +1 -1
- package/types/inputs.d.ts +4 -4
- package/types/libs/config/config.d.ts +3 -3
- package/types/libs/config/hooks.d.ts +8 -8
- package/types/libs/core/combobox.d.ts +10 -10
- package/types/libs/core/controls.d.ts +28 -28
- package/types/libs/core/cookies.d.ts +27 -27
- package/types/libs/core/csv.d.ts +12 -12
- package/types/libs/core/dateRange.d.ts +72 -72
- package/types/libs/core/dom.d.ts +65 -65
- package/types/libs/core/elementGenerator.d.ts +30 -30
- package/types/libs/core/errors.d.ts +29 -29
- package/types/libs/core/focus.d.ts +6 -6
- package/types/libs/core/format.d.ts +21 -21
- package/types/libs/core/hungarianControls.d.ts +2 -2
- package/types/libs/core/i18n.d.ts +17 -17
- package/types/libs/core/pagination.d.ts +5 -5
- package/types/libs/core/popover.d.ts +36 -0
- package/types/libs/core/sanitize.d.ts +6 -6
- package/types/libs/core/tableMath.d.ts +26 -26
- package/types/libs/core/theme.d.ts +39 -39
- package/types/libs/core/validation.d.ts +56 -56
- package/types/libs/hephaestus/LayoutGenerator/basicLayoutGenerator.d.ts +10 -10
- package/types/libs/hephaestus/LayoutGenerator/footerContentGenerator.d.ts +4 -4
- package/types/libs/hephaestus/LayoutGenerator/headerContentGenerator.d.ts +20 -20
- package/types/libs/hephaestus/LayoutGenerator/wrapperContentGenerator.d.ts +1 -1
- package/types/libs/hephaestus/MenuGenerator/basicMenuGenerator.d.ts +14 -14
- package/types/libs/hephaestus/MenuGenerator/menuGenerator.d.ts +65 -65
- package/types/libs/hephaestus/auth/authState.d.ts +26 -26
- package/types/libs/hephaestus/auth/session.d.ts +26 -26
- package/types/libs/hephaestus/chartGenerator/chartGenerator.d.ts +93 -91
- package/types/libs/hephaestus/componentGenerator/componentGenerator.d.ts +3 -1
- package/types/libs/hephaestus/componentGenerator/themePicker.d.ts +24 -24
- package/types/libs/hephaestus/dialogGenerator/dialogGenerator.d.ts +120 -120
- package/types/libs/hephaestus/feedbackGenerator/feedbackGenerator.d.ts +86 -86
- package/types/libs/hephaestus/formGenerator/authForms.d.ts +122 -122
- package/types/libs/hephaestus/formGenerator/changePasswordFormGenerator.d.ts +6 -6
- package/types/libs/hephaestus/formGenerator/formBuilder.d.ts +113 -113
- package/types/libs/hephaestus/formGenerator/formUtils.d.ts +8 -8
- package/types/libs/hephaestus/formGenerator/loginFormGenerator.d.ts +11 -11
- package/types/libs/hephaestus/formGenerator/lostPasswordFormGenerator.d.ts +4 -4
- package/types/libs/hephaestus/formGenerator/registrationFormGenerator.d.ts +7 -7
- package/types/libs/hephaestus/hephaestus.d.ts +3 -3
- package/types/libs/hephaestus/inputGenerator/dropZoneGenerator.d.ts +48 -48
- package/types/libs/hephaestus/inputGenerator/inputGenerator.d.ts +185 -185
- package/types/libs/hephaestus/inputGenerator/richTextGenerator.d.ts +49 -49
- package/types/libs/hephaestus/modalGenerator/modalGenerator.d.ts +2 -2
- package/types/libs/hephaestus/navigationGenerator/navigationGenerator.d.ts +4 -1
- package/types/libs/hephaestus/router/matchRoute.d.ts +12 -12
- package/types/libs/hephaestus/router/router.d.ts +67 -67
- package/types/libs/hephaestus/tableGenerator/tableGenerator.d.ts +120 -120
- package/types/menu.d.ts +1 -1
- package/types/navigation.d.ts +1 -1
- package/types/res/themes/themes.d.ts +7 -7
- package/types/router.d.ts +1 -1
- package/types/sanitize.d.ts +1 -1
- package/types/session.d.ts +3 -3
- package/types/table.d.ts +1 -1
- package/types/testing.d.ts +27 -27
- package/types/theme.d.ts +2 -2
- package/types/validation.d.ts +1 -1
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: **2.
|
|
8
|
+
Current version: **2.1.0**
|
|
9
9
|
|
|
10
10
|
[Quick start](#usage) · [API](#api) · [Components](#charts) · [Themes](#themes) · [Tests](#tests) · [Release notes](#releases)
|
|
11
11
|
|
|
@@ -22,7 +22,7 @@ Known limits are listed below, so you can judge whether it fits your project:
|
|
|
22
22
|
- Athena UI has **no dependencies**: no jQuery, no bundled library, nothing is loaded at run time, and nothing is put on `window` unless you opt in with
|
|
23
23
|
`athena-ui-js/classic`. The older generators (`generateLoginForm`, the layout and the header / footer menu built from `menuItems`) are plain DOM too.
|
|
24
24
|
- The default theme follows the system's dark mode. Put `data-mode="light"` on `<html>` (or use `createThemeManager`) to choose.
|
|
25
|
-
- Dialogs
|
|
25
|
+
- Dialogs, the accordion, the dropdown menu and tooltips use the native `<dialog>`, `<details>` and popover elements, so they need a browser that supports cascade layers and `<dialog>` (2022 or later). The dropdown menu and the tooltips are native popovers (the `popover` attribute) in browsers that have them (Chrome / Edge 114, Safari 17, Firefox 125), and a plain fallback in older ones.
|
|
26
26
|
|
|
27
27
|
## Features
|
|
28
28
|
|
|
@@ -72,6 +72,20 @@ The package has `"sideEffects"` for `classic.js`, `theme-boot.js` and CSS only,
|
|
|
72
72
|
|
|
73
73
|
Without npm, serve the `src` folder with any static web server and open `index.html` to see the example.
|
|
74
74
|
|
|
75
|
+
### The demo application
|
|
76
|
+
|
|
77
|
+
**Try it live: https://athena-ui-js-demo-duc7dncrfhg5fxfs.northeurope-01.azurewebsites.net** (sign in with `demo` / `demo-pass`, or `admin` / `admin-pass`; the app sleeps when nobody visits, so the first request can take a few seconds).
|
|
78
|
+
|
|
79
|
+
`demo/` is a demo and test application: tables with 100,000 rows from a server, a streaming chart, every field type, native dialogs, a menu with groups inside groups, themes
|
|
80
|
+
and modes, and a real sign in, served by a small Node server (no dependencies) under a strict Content-Security-Policy.
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
npm run demo # http://localhost:3000
|
|
84
|
+
npm run test:demo # the server, the API and every page in a real browser
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
GitHub Actions tests it and deploys it to an Azure App Service: [demo/README.md](demo/README.md) has the one-time set up.
|
|
88
|
+
|
|
75
89
|
## Usage
|
|
76
90
|
|
|
77
91
|
```html
|
|
@@ -135,7 +149,7 @@ It takes the options of `init()`. The header and footer follow the settings `gen
|
|
|
135
149
|
| `header_title_text` | `"Athena UI"` | Title in the header |
|
|
136
150
|
| `header_img_url` | | Header logo URL |
|
|
137
151
|
| `copyright` | placeholder text | Footer text, the version is appended |
|
|
138
|
-
| `version` | `"2.
|
|
152
|
+
| `version` | `"2.1.0"` | Version shown in the footer |
|
|
139
153
|
| `bordered` | `true` | Draw a border around the layout blocks |
|
|
140
154
|
| `generateHeader`, `generateFooter` | `true` | Generate the header / footer block |
|
|
141
155
|
| `generateHeadercontent`, `generateFooterContent`, `generateWrappercontent` | `true` | Generate the content of the block |
|
|
@@ -343,6 +357,11 @@ never parsed as HTML. `openModal` / `closeModal` got the same focus handling.
|
|
|
343
357
|
|
|
344
358
|
### Navigation
|
|
345
359
|
|
|
360
|
+
The **dropdown** menu and the **tooltip** are native popovers: they are drawn in the top layer, so no parent with `overflow: hidden` can cut them off and no `z-index` fight is possible;
|
|
361
|
+
a click outside and Esc close the dropdown, and the focus goes back to its button. They are placed next to their button by a small helper (it sets two CSS variables, which a strict
|
|
362
|
+
Content-Security-Policy allows): below, or above when there is no room below, and always kept inside the window. A tooltip shows on hover and on focus and goes on Esc; a touch does not show it.
|
|
363
|
+
Without the popover API the dropdown is a plain menu that is shown and hidden with `hidden`, and the tooltip a CSS one.
|
|
364
|
+
|
|
346
365
|
```js
|
|
347
366
|
generateTabs({ parent: "wrapper", tabs: [{ id: "a", label: "A", content: "First" }, { id: "b", label: "B", content: () => lazyNode() }] });
|
|
348
367
|
generateAccordion({ parent: "wrapper", items: [{ title: "Q", content: "A", open: true }], multiple: false });
|
|
@@ -689,8 +708,8 @@ component: forms, dialogs, navigation, submenus, inputs, rich text (sanitizing,
|
|
|
689
708
|
session, themes. Set `CHROME_PATH` if the browser is not found. `DEBUG=1` prints the browser log when the page does not report results.
|
|
690
709
|
|
|
691
710
|
- **The page runs under a strict Content-Security-Policy** (`default-src 'none'; script-src 'self'; style-src 'self'`, set by `run.mjs`), and a `securitypolicyviolation` fails the test
|
|
692
|
-
that caused it. That is the guarantee that Athena UI needs no `'unsafe-inline'`. (Three tests that hand the sanitizer hostile markup are let through for the
|
|
693
|
-
makes while it parses an inline handler in an inert document.)
|
|
711
|
+
that caused it. That is the guarantee that Athena UI needs no `'unsafe-inline'`. (Three tests that hand the sanitizer hostile markup are let through for the reports Chrome
|
|
712
|
+
makes while it parses an inline handler, a style attribute or a `<style>` element in an inert document.)
|
|
694
713
|
- One test feeds markup to about 40 components and checks that text from data stays text.
|
|
695
714
|
- `WITH_JQUERY=1 npm run test:browser` loads jQuery from its CDN, to check that an application that still has it works too (`JQUERY_URL` for another address).
|
|
696
715
|
- The unit tests also check that `docs/styling.md` is up to date, and that a TypeScript file using the library compiles against `types/` (needs `npm install` for TypeScript).
|
|
@@ -714,6 +733,8 @@ src/
|
|
|
714
733
|
res/themes/ tokens.css, default and dark theme, appearance.css (themes and modes)
|
|
715
734
|
types/ TypeScript definitions (npm run types)
|
|
716
735
|
docs/ styling.md (generated), migration-2.0.md
|
|
736
|
+
demo/ the demo and test application (server, API, pages, end to end tests), deployed to Azure by GitHub Actions
|
|
737
|
+
.github/workflows/ ci.yml (tests) and demo-deploy.yml
|
|
717
738
|
tests/ unit tests (Node) and browser tests (headless Chrome, strict CSP)
|
|
718
739
|
```
|
|
719
740
|
|
|
@@ -727,6 +748,27 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
|
727
748
|
|
|
728
749
|
## Releases
|
|
729
750
|
|
|
751
|
+
### 2.1.0
|
|
752
|
+
#### Changed:
|
|
753
|
+
1. The dropdown menu is a native popover (`popover="auto"`, opened by its button through `popovertarget`): it is drawn in the top layer, so no parent with `overflow: hidden` cuts it off; a click outside and Esc close it and the focus goes back to the button; `aria-expanded` follows every way of opening and closing it. Markup: the menu has the attribute `popover` and no `hidden` any more (use `:popover-open`)
|
|
754
|
+
2. The tooltip is a native popover (`popover="manual"`): shown on hover and on keyboard focus, hidden on leave, blur and Esc, never shown by a touch, and never cut off by a parent
|
|
755
|
+
3. Both are placed next to their button by a small helper that sets two CSS variables (`--athena-popover-left`, `--athena-popover-top`; allowed by a strict Content-Security-Policy): below, or above when there is no room below, centred or aligned to an edge, and always kept inside the window; they follow the button when the page scrolls or resizes
|
|
756
|
+
4. Browsers without the popover API keep the previous behaviour (a plain menu shown with `hidden` and closed by a click outside, a CSS tooltip)
|
|
757
|
+
#### Added:
|
|
758
|
+
1. `src/libs/core/popover.js` (placement helpers) and the CSS class `.athena-popover`
|
|
759
|
+
2. The address of the live demo in the READMEs
|
|
760
|
+
3. Section 3 ("Make it lighter") of the to-do list is complete: the native elements are `<dialog>`, `<details>` and the popover
|
|
761
|
+
|
|
762
|
+
### 2.0.1
|
|
763
|
+
#### Added:
|
|
764
|
+
1. `demo/`: a demo and test application of Athena UI (tables with 100,000 rows from a server, streaming charts, forms, dialogs, menus, themes, sign in) with a dependency free Node server, and end to end tests that drive a real browser (DevTools protocol) under a strict Content-Security-Policy
|
|
765
|
+
2. GitHub Actions: `ci.yml` (unit, browser and demo tests on every push and pull request) and `demo-deploy.yml` (tests, builds `demo/dist`, deploys to an Azure App Service, checks the site)
|
|
766
|
+
#### Fixed (found by the end to end tests of the demo):
|
|
767
|
+
1. A chart that redraws (streaming `push`, zoom) no longer loses the keyboard focus: it moves to the same place in the new SVG
|
|
768
|
+
2. The series a person hid with the legend stay hidden when the chart redraws (`hiddenSeries` option)
|
|
769
|
+
#### Changed:
|
|
770
|
+
1. `package-lock.json` is part of the repository (CI uses `npm ci`)
|
|
771
|
+
|
|
730
772
|
### 2.0.0
|
|
731
773
|
#### Breaking (see [docs/migration-2.0.md](docs/migration-2.0.md)):
|
|
732
774
|
1. No default export, and nothing on `window` unless you import `athena-ui-js/classic`; `athena-ui.js` has no side effects
|
package/docs/migration-2.0.md
CHANGED
|
@@ -53,7 +53,7 @@ They are part of Athena UI (`athena-ui-js/controls`) and no longer git submodule
|
|
|
53
53
|
`athena-ui-js/testing`, which gives jsdom `showModal()`; a synthetic Esc key does not close a native dialog, send the `cancel` event instead.
|
|
54
54
|
- `generateAccordion` is `<details>` and `<summary>`: `.accordion-header` is a `<summary>`, there is no `aria-expanded` on a button, `.accordion-open` is the
|
|
55
55
|
`[open]` attribute and `.accordion-title` is gone. `accordion.toggle(index, open)` works as before.
|
|
56
|
-
- The dropdown
|
|
56
|
+
- The dropdown and the tooltip became native popovers in 2.1 (see the release notes): the menu is `<div class="dropdown-menu" popover>` (no `hidden` attribute any more: use `:popover-open`), and the tooltip text is a `popover="manual"` element.
|
|
57
57
|
|
|
58
58
|
## 6. CSS: a layer, tokens and dark mode
|
|
59
59
|
|
package/docs/styling.md
CHANGED
|
@@ -61,11 +61,13 @@ Dark colours: set `data-mode="dark"` on `<html>` (or let `createThemeManager` do
|
|
|
61
61
|
| Tabs | `.tab` `.tab-active` `.tab-list` `.tab-panel` | `--athena-accent` `--athena-border-width` `--athena-fg` `--athena-line` |
|
|
62
62
|
| Breadcrumbs, pagination | `.breadcrumb-item` `.breadcrumb-list` `.page-button` `.page-current` `.pagination` | `--athena-accent` `--athena-accent-fg` `--athena-bg` `--athena-border-width` `--athena-fg` `--athena-line` `--athena-muted` `--athena-space-1` |
|
|
63
63
|
| Accordion: <details> and <summary> | `.accordion-header` `.accordion-icon` `.accordion-item` `.accordion-panel` `.sidebar-parent` | `--athena-accent` `--athena-border-width` `--athena-fg` `--athena-focus` `--athena-focus-width` `--athena-line` `--athena-surface` |
|
|
64
|
-
| Dropdown | `.dropdown` `.dropdown-
|
|
64
|
+
| Dropdown | `.dropdown` `.dropdown-menu` `.dropdown-right` | `--athena-bg` `--athena-border-width` `--athena-line` `--athena-radius` `--athena-shadow` |
|
|
65
|
+
| A popover (the dropdown menu, the tooltip) is in the top layer, placed next to its anchor by script through two variables | `.athena-popover` `.athena-popover-above` `.athena-popover-center` `.athena-popover-end` `.dropdown-divider` `.dropdown-item` `.dropdown-menu` | `--athena-fg` `--athena-hover` `--athena-line` `--athena-popover-left` `--athena-popover-top` |
|
|
65
66
|
| Sidebar | `.accordion-icon` `.sidebar` `.sidebar-link` `.sidebar-list` `.sidebar-parent` `.sidebar-sublist` `.sidebar-toggle` | `--athena-accent` `--athena-accent-fg` `--athena-fg` `--athena-hover` `--athena-space-2` |
|
|
66
67
|
| Cards, sections, grid | `.athena-grid` `.card` `.card-body` `.card-footer` `.card-image` `.card-title` | `--athena-bg` `--athena-border-width` `--athena-line` `--athena-radius` `--athena-surface-alt` `--grid-columns` `--grid-gap` |
|
|
67
68
|
| Badge, avatar, stat | `.avatar` `.avatar-large` `.avatar-small` `.badge` `.badge-error` `.badge-info` `.badge-pill` `.badge-success` `.badge-warning` `.stat` `.stat-bad` `.stat-good` `.stat-label` `.stat-neutral` `.stat-value` | `--athena-accent` `--athena-accent-fg` `--athena-bg` `--athena-border-width` `--athena-danger` `--athena-fg` `--athena-info` `--athena-line` `--athena-muted` `--athena-radius` `--athena-success` `--athena-surface` `--athena-warning` |
|
|
68
69
|
| Tooltip | `.has-tooltip` `.tooltip-text` `.tooltip-wrap` | - |
|
|
70
|
+
| As a popover it is only drawn while it is open, so it is always visible; the position comes from placePopover() | `.tooltip-text` | - |
|
|
69
71
|
| Combobox (autocomplete, multi select) and chips | `.chip` `.chip-remove` `.combobox` `.combobox-active` `.combobox-chips` `.combobox-empty` `.combobox-input` `.combobox-list` `.combobox-multiple` `.combobox-option` `.combobox-selected` | `--athena-accent` `--athena-accent-fg` `--athena-bg` `--athena-border-width` `--athena-hover` `--athena-line` `--athena-muted` `--athena-radius` `--athena-shadow` `--athena-space-1` |
|
|
70
72
|
| File upload | `.dropzone` `.dropzone-disabled` `.dropzone-input` `.dropzone-over` `.file-item` `.file-list` `.file-status` | `--athena-accent` `--athena-hover` `--athena-line` `--athena-muted` `--athena-radius` |
|
|
71
73
|
| Stepper | `.form-actions` `.stepper` `.stepper-current` `.stepper-done` `.stepper-number` `.stepper-step` `.stepper-steps` | `--athena-accent` `--athena-accent-fg` `--athena-fg` `--athena-line` `--athena-muted` `--athena-space-2` `--athena-success` |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "athena-ui-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "A small, dependency-free UI framework: forms, tables, charts, menus, dialogs, themes and a router, written as ES modules.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/athena-ui.js",
|
|
@@ -8,7 +8,10 @@
|
|
|
8
8
|
"test": "node --test tests/*.test.js",
|
|
9
9
|
"test:browser": "node tests/browser/run.mjs",
|
|
10
10
|
"docs": "node scripts/styling-docs.mjs",
|
|
11
|
-
"types": "tsc -p tsconfig.types.json"
|
|
11
|
+
"types": "tsc -p tsconfig.types.json",
|
|
12
|
+
"test:demo": "node --test --test-timeout=600000 demo/tests/demo.test.mjs demo/tests/browser.test.mjs",
|
|
13
|
+
"demo": "node demo/server.mjs",
|
|
14
|
+
"demo:build": "node demo/scripts/build-package.mjs"
|
|
12
15
|
},
|
|
13
16
|
"exports": {
|
|
14
17
|
".": {
|
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: 2.
|
|
5
|
+
//Version: 2.1.0
|
|
6
6
|
|
|
7
7
|
// The whole API as ES module exports. There are no side effects: importing this file does not touch the page, does not load a script and does not
|
|
8
8
|
// put anything on globalThis. For pages that need globals use `athena-ui-js/classic`, and to download only what you use import from the entry points
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
//popover helpers for Athena UI
|
|
2
|
+
//Author: Csaba Tóth https://github.com/csabatibortoth/
|
|
3
|
+
//LICENCE: MIT
|
|
4
|
+
//Repository: https://github.com/csabatibortoth/athena-ui
|
|
5
|
+
|
|
6
|
+
// The native popover API (the `popover` attribute) gives a dropdown or a tooltip what it needs without a line of script: it is drawn in the top layer (above
|
|
7
|
+
// everything, never cut off by an overflow of a parent), a click outside or Esc closes it, and the focus goes back. What it does not do is place the popover
|
|
8
|
+
// next to its button: that is placePopover() below, which sets two CSS variables (allowed under a strict Content-Security-Policy: no inline style attribute)
|
|
9
|
+
// that the stylesheet reads. Browsers without the popover API (before 2023 to 2024) get the plain fallback: the element is shown and hidden with `hidden`.
|
|
10
|
+
|
|
11
|
+
/** True when the browser has the popover API. */
|
|
12
|
+
export const supportsPopover = () => typeof HTMLElement !== "undefined" && "popover" in HTMLElement.prototype && typeof HTMLElement.prototype.showPopover === "function";
|
|
13
|
+
|
|
14
|
+
/** Is the popover (or the fallback element) open? */
|
|
15
|
+
export const isOpen = element => (supportsPopover() && element.hasAttribute("popover") ? element.matches(":popover-open") : !element.hidden);
|
|
16
|
+
|
|
17
|
+
/** Opens it: showPopover(), or without the API: the element is no longer hidden. Does nothing when it is open already. */
|
|
18
|
+
export function openPopover(element) {
|
|
19
|
+
if (isOpen(element)) return;
|
|
20
|
+
if (supportsPopover() && element.hasAttribute("popover")) element.showPopover();
|
|
21
|
+
else element.hidden = false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Closes it. Does nothing when it is closed already. */
|
|
25
|
+
export function closePopover(element) {
|
|
26
|
+
if (!isOpen(element)) return;
|
|
27
|
+
if (supportsPopover() && element.hasAttribute("popover")) element.hidePopover();
|
|
28
|
+
else element.hidden = true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const EDGE = 4; // px kept free between the popover and the edge of the window
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Where a popover goes, next to the element it belongs to, before it is shown (so there is no frame at the wrong place). Only the side and the alignment
|
|
35
|
+
* are chosen here, from the position of the anchor in the window: the popover is moved with CSS (translate) by its own size. Once it is shown,
|
|
36
|
+
* `settlePopover` measures it and keeps it inside the window.
|
|
37
|
+
*
|
|
38
|
+
* @param {Element} anchor the button or the target of the tooltip
|
|
39
|
+
* @param {HTMLElement} popover
|
|
40
|
+
* @param {object} [options]
|
|
41
|
+
* @param {"bottom"|"top"|"auto"} [options.side="auto"] "bottom": below. "top": above, unless there is less than `room` px above. "auto": below,
|
|
42
|
+
* unless there is less than `room` px below and more room above
|
|
43
|
+
* @param {"start"|"end"|"center"} [options.align="start"] which edge of the anchor the popover lines up with
|
|
44
|
+
* @param {number} [options.gap=4] px between the anchor and the popover
|
|
45
|
+
* @param {number} [options.room=240] how much room a side needs, in px (a tooltip needs about 40)
|
|
46
|
+
*/
|
|
47
|
+
export function placePopover(anchor, popover, { side = "auto", align = "start", gap = 4, room = 240 } = {}) {
|
|
48
|
+
const box = anchor.getBoundingClientRect();
|
|
49
|
+
const height = document.documentElement.clientHeight;
|
|
50
|
+
const above = side === "top" ? box.top >= room : side === "auto" && height - box.bottom < room && box.top > height - box.bottom;
|
|
51
|
+
const x = align === "end" ? box.right : align === "center" ? box.left + box.width / 2 : box.left;
|
|
52
|
+
const y = above ? box.top - gap : box.bottom + gap;
|
|
53
|
+
popover.style.setProperty("--athena-popover-left", `${Math.round(x)}px`);
|
|
54
|
+
popover.style.setProperty("--athena-popover-top", `${Math.round(y)}px`);
|
|
55
|
+
popover.classList.toggle("athena-popover-above", above);
|
|
56
|
+
popover.classList.toggle("athena-popover-end", align === "end");
|
|
57
|
+
popover.classList.toggle("athena-popover-center", align === "center");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* After the popover is shown: measures it and moves it back inside the window when it sticks out to the left, the right or the bottom (a popover that
|
|
62
|
+
* is taller than the room is left where it is: it scrolls).
|
|
63
|
+
*/
|
|
64
|
+
export function settlePopover(popover) {
|
|
65
|
+
const box = popover.getBoundingClientRect();
|
|
66
|
+
const width = document.documentElement.clientWidth;
|
|
67
|
+
const height = document.documentElement.clientHeight;
|
|
68
|
+
const dx = box.left < EDGE ? EDGE - box.left : box.right > width - EDGE ? width - EDGE - box.right : 0;
|
|
69
|
+
const dy = box.bottom > height - EDGE && box.top - (box.bottom - (height - EDGE)) >= EDGE ? height - EDGE - box.bottom : 0;
|
|
70
|
+
if (dx) popover.style.setProperty("--athena-popover-left", `${Math.round(parseFloat(popover.style.getPropertyValue("--athena-popover-left")) + dx)}px`);
|
|
71
|
+
if (dy) popover.style.setProperty("--athena-popover-top", `${Math.round(parseFloat(popover.style.getPropertyValue("--athena-popover-top")) + dy)}px`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Keeps an open popover next to its anchor while the page scrolls or the window changes size. Returns a function that stops it.
|
|
76
|
+
* (A popover in the top layer does not move with its anchor by itself.)
|
|
77
|
+
*/
|
|
78
|
+
export function followAnchor(anchor, popover, options) {
|
|
79
|
+
let queued = false;
|
|
80
|
+
const update = () => {
|
|
81
|
+
if (queued) return;
|
|
82
|
+
queued = true;
|
|
83
|
+
requestAnimationFrame(() => {
|
|
84
|
+
queued = false;
|
|
85
|
+
if (!isOpen(popover)) return;
|
|
86
|
+
placePopover(anchor, popover, options);
|
|
87
|
+
settlePopover(popover);
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
window.addEventListener("scroll", update, { capture: true, passive: true });
|
|
91
|
+
window.addEventListener("resize", update, { passive: true });
|
|
92
|
+
return () => {
|
|
93
|
+
window.removeEventListener("scroll", update, { capture: true });
|
|
94
|
+
window.removeEventListener("resize", update);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
@@ -94,7 +94,7 @@ function addLegend(svg, entries, width, height, ctx) {
|
|
|
94
94
|
let x = MARGIN.left;
|
|
95
95
|
const y = height - 12;
|
|
96
96
|
entries.forEach(({ name, props, series }) => {
|
|
97
|
-
const group = svgEl("g", { class: "chart-legend-item", tabindex: 0, role: "button", "aria-pressed": "true", "aria-label": name });
|
|
97
|
+
const group = svgEl("g", { class: "chart-legend-item", tabindex: 0, role: "button", "aria-pressed": "true", "aria-label": name, "data-legend": series ?? "" });
|
|
98
98
|
group.append(svgEl("rect", { x, y: y - 9, width: 10, height: 10, class: `chart-swatch ${props.class ?? ""}`.trim(), ...(props.color ? { color: props.color } : {}) }));
|
|
99
99
|
group.append(svgEl("text", { x: x + 14, y, class: "chart-legend" }, name));
|
|
100
100
|
if (series != null) {
|
|
@@ -103,6 +103,7 @@ function addLegend(svg, entries, width, height, ctx) {
|
|
|
103
103
|
group.setAttribute("aria-pressed", hidden ? "false" : "true");
|
|
104
104
|
group.classList.toggle("is-off", hidden);
|
|
105
105
|
for (const node of svg.querySelectorAll(`[data-series="${series}"]`)) node.classList.toggle("chart-hidden", hidden);
|
|
106
|
+
ctx.hooks?.legend?.(series, hidden);
|
|
106
107
|
ctx.tooltip.hide();
|
|
107
108
|
};
|
|
108
109
|
group.addEventListener("click", toggle);
|
|
@@ -522,6 +523,7 @@ function buildDataTable({ labels, series, times, title, type }) {
|
|
|
522
523
|
* `times`, otherwise the index of the point (-0.5 is the left edge of the first point)
|
|
523
524
|
* @param {(range: ({from: number, to: number}|null)) => void} [options.onZoom] called when a person zooms or resets
|
|
524
525
|
* @param {number} [options.maxPoints] `push` keeps at most this many points per series (the oldest are dropped)
|
|
526
|
+
* @param {number[]} [options.hiddenSeries] the series (or slices) that are hidden at the start; a person hides and shows them with the legend, and a redraw keeps that
|
|
525
527
|
* @param {boolean} [options.interactive=true] line and area charts: false leaves out the pointer layer (tooltip that follows the pointer, zoom)
|
|
526
528
|
* @returns {(SVGElement & {element: SVGElement, update: (options?: object) => SVGElement, destroy: () => void,
|
|
527
529
|
* zoom: (from: number, to: number) => void, resetZoom: () => void, getZoom: () => ({from: number, to: number}|null),
|
|
@@ -536,7 +538,13 @@ export function generateChart(options = {}) {
|
|
|
536
538
|
const state = { used: { ...options, series: (options.series ?? []).map(s => ({ ...s, data: [...(s.data ?? [])] })) }, current: null, queued: false };
|
|
537
539
|
if (options.labels) state.used.labels = [...options.labels];
|
|
538
540
|
if (options.times) state.used.times = [...options.times];
|
|
541
|
+
const hidden = new Set(options.hiddenSeries ?? []);
|
|
539
542
|
const hooks = {
|
|
543
|
+
legend: (series, off) => {
|
|
544
|
+
if (off) hidden.add(series);
|
|
545
|
+
else hidden.delete(series);
|
|
546
|
+
state.used.hiddenSeries = [...hidden];
|
|
547
|
+
},
|
|
540
548
|
zoom: range => {
|
|
541
549
|
state.used = { ...state.used, zoomRange: range ?? null };
|
|
542
550
|
handle.redraw();
|
|
@@ -548,12 +556,22 @@ export function generateChart(options = {}) {
|
|
|
548
556
|
redraw() {
|
|
549
557
|
const next = buildChart(state.used, hooks);
|
|
550
558
|
if (!next) return state.current?.svg;
|
|
559
|
+
// A redraw replaces the whole SVG (every second while streaming, and when someone zooms). The keyboard focus would be lost
|
|
560
|
+
// with it, so it goes to the same place in the new one: the same legend entry, the same point, or the plot.
|
|
561
|
+
const old = state.current?.svg;
|
|
562
|
+
const active = old && old.contains(document.activeElement) ? document.activeElement : null;
|
|
563
|
+
const focusables = active ? [...old.querySelectorAll("[tabindex]")] : [];
|
|
564
|
+
const position = active ? focusables.indexOf(active) : -1;
|
|
551
565
|
if (state.current) {
|
|
552
|
-
|
|
566
|
+
old.replaceWith(next.svg);
|
|
553
567
|
state.current.table?.remove();
|
|
554
568
|
if (next.table) next.svg.after(next.table);
|
|
555
569
|
}
|
|
556
570
|
state.current = next;
|
|
571
|
+
if (active) {
|
|
572
|
+
const now = [...next.svg.querySelectorAll("[tabindex]")];
|
|
573
|
+
(active.classList.contains("chart-hit") || active.classList.contains("chart-reset") ? next.svg.querySelector(".chart-hit") : now[position] ?? next.svg.querySelector(".chart-hit"))?.focus({ preventScroll: true });
|
|
574
|
+
}
|
|
557
575
|
return attach(next.svg);
|
|
558
576
|
},
|
|
559
577
|
update(changes = {}) {
|
|
@@ -648,5 +666,11 @@ function buildChart(options = {}, hooks) {
|
|
|
648
666
|
addLegend(svg, pieLegend ?? series.map((s, i) => ({ name: s.name ?? `${translate("series")} ${i + 1}`, props: seriesProps(s, i), series: i })), width, height, ctx);
|
|
649
667
|
}
|
|
650
668
|
svg.append(tooltip.group);
|
|
669
|
+
for (const index of options.hiddenSeries ?? []) {
|
|
670
|
+
for (const node of svg.querySelectorAll(`[data-series="${index}"]`)) node.classList.add("chart-hidden");
|
|
671
|
+
const entry = svg.querySelector(`.chart-legend-item[data-legend="${index}"]`);
|
|
672
|
+
entry?.setAttribute("aria-pressed", "false");
|
|
673
|
+
entry?.classList.add("is-off");
|
|
674
|
+
}
|
|
651
675
|
return { svg, table: options.table ? buildDataTable({ labels, series, times, title, type }) : null };
|
|
652
676
|
}
|
|
@@ -7,6 +7,7 @@ import { asHandle, cx, el, mount, resolveElement, setContent, uid } from "../../
|
|
|
7
7
|
import { generateBreadcrumbs } from "../navigationGenerator/navigationGenerator.js";
|
|
8
8
|
import { generateSpinner } from "../feedbackGenerator/feedbackGenerator.js";
|
|
9
9
|
import { translate } from "../../core/i18n.js";
|
|
10
|
+
import { closePopover, followAnchor, openPopover, placePopover, settlePopover, supportsPopover } from "../../core/popover.js";
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Generates a link. External links open in a new tab and get `rel="noopener noreferrer"`.
|
|
@@ -199,7 +200,9 @@ export function generateGrid(options = {}) {
|
|
|
199
200
|
}
|
|
200
201
|
|
|
201
202
|
/**
|
|
202
|
-
* Adds a tooltip to an element. It shows on hover and on keyboard focus.
|
|
203
|
+
* Adds a tooltip to an element. It shows on hover and on keyboard focus, and Esc hides it.
|
|
204
|
+
* It is a native popover (`popover="manual"`), so it is drawn above everything and never cut off by a parent with `overflow: hidden`. A touch
|
|
205
|
+
* does not show it (a tap would hide the thing it describes). Browsers without the popover API show it with CSS, as before.
|
|
203
206
|
*
|
|
204
207
|
* @param {Element|string} target element or id
|
|
205
208
|
* @param {string} text
|
|
@@ -208,7 +211,8 @@ export function generateTooltip(target, text) {
|
|
|
208
211
|
const node = resolveElement(target);
|
|
209
212
|
if (!node) return null;
|
|
210
213
|
const id = uid("tooltip");
|
|
211
|
-
const
|
|
214
|
+
const native = supportsPopover();
|
|
215
|
+
const tip = el("span", { class: "tooltip-text athena-popover", id, text, attrs: { role: "tooltip", popover: native ? "manual" : null } });
|
|
212
216
|
// Inputs and images cannot hold the tooltip text, so they get a wrapper.
|
|
213
217
|
let host = node;
|
|
214
218
|
if (node.matches("input,img,select,textarea")) {
|
|
@@ -221,6 +225,26 @@ export function generateTooltip(target, text) {
|
|
|
221
225
|
host.classList.add("has-tooltip");
|
|
222
226
|
node.setAttribute("aria-describedby", id);
|
|
223
227
|
host.append(tip);
|
|
228
|
+
if (native) {
|
|
229
|
+
let stop = null;
|
|
230
|
+
const show = () => {
|
|
231
|
+
if (tip.matches(":popover-open")) return;
|
|
232
|
+
placePopover(node, tip, { side: "top", align: "center", gap: 6, room: 40 });
|
|
233
|
+
openPopover(tip);
|
|
234
|
+
settlePopover(tip);
|
|
235
|
+
stop = followAnchor(node, tip, { side: "top", align: "center", gap: 6, room: 40 });
|
|
236
|
+
};
|
|
237
|
+
const hide = () => {
|
|
238
|
+
stop?.();
|
|
239
|
+
stop = null;
|
|
240
|
+
closePopover(tip);
|
|
241
|
+
};
|
|
242
|
+
host.addEventListener("pointerenter", event => { if (event.pointerType !== "touch") show(); });
|
|
243
|
+
host.addEventListener("pointerleave", hide);
|
|
244
|
+
host.addEventListener("focusin", show);
|
|
245
|
+
host.addEventListener("focusout", hide);
|
|
246
|
+
host.addEventListener("keydown", event => { if (event.key === "Escape") hide(); });
|
|
247
|
+
}
|
|
224
248
|
return tip;
|
|
225
249
|
}
|
|
226
250
|
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { asHandle, cx, el, mount, setContent, uid } from "../../core/dom.js";
|
|
7
7
|
import { translate } from "../../core/i18n.js";
|
|
8
8
|
import { pageRange } from "../../core/pagination.js";
|
|
9
|
+
import { closePopover, followAnchor, isOpen, openPopover, placePopover, settlePopover, supportsPopover } from "../../core/popover.js";
|
|
9
10
|
|
|
10
11
|
/* ------------------TABS------------------- */
|
|
11
12
|
|
|
@@ -228,7 +229,10 @@ export function generateAccordion(options = {}) {
|
|
|
228
229
|
/* ------------------DROPDOWN------------------- */
|
|
229
230
|
|
|
230
231
|
/**
|
|
231
|
-
* Generates a button that opens a menu. Arrow keys move through the items, Esc closes it.
|
|
232
|
+
* Generates a button that opens a menu. Arrow keys move through the items, Esc closes it, and so does a click outside.
|
|
233
|
+
* The menu is a native popover (the `popover` attribute): it is drawn above everything, so no parent can cut it off, and the browser takes care of the
|
|
234
|
+
* light dismiss and of the focus. It is placed next to the button, below it, or above it when there is no room below. Browsers without the popover API
|
|
235
|
+
* get a plain menu that is shown and hidden with `hidden`.
|
|
232
236
|
*
|
|
233
237
|
* @param {object} options
|
|
234
238
|
* @param {string|Element} [options.parent]
|
|
@@ -243,12 +247,18 @@ export function generateAccordion(options = {}) {
|
|
|
243
247
|
*/
|
|
244
248
|
export function generateDropdown(options = {}) {
|
|
245
249
|
const menuId = uid("dropdown");
|
|
246
|
-
const
|
|
250
|
+
const native = supportsPopover();
|
|
251
|
+
const align = options.align === "right" ? "end" : "start";
|
|
252
|
+
const menu = el("div", {
|
|
253
|
+
class: cx("dropdown-menu athena-popover", options.align === "right" && "dropdown-right"), id: menuId,
|
|
254
|
+
attrs: { role: "menu", popover: native ? "auto" : null, hidden: native ? null : true }
|
|
255
|
+
});
|
|
247
256
|
const button = el("button", {
|
|
248
257
|
class: cx("athena-button button-secondary dropdown-toggle", options.icon && !options.label && "dropdown-icon-only", options.toggleClass),
|
|
249
258
|
attrs: {
|
|
250
259
|
type: "button", "aria-haspopup": "menu", "aria-expanded": "false", "aria-controls": menuId,
|
|
251
|
-
"aria-label": options.ariaLabel
|
|
260
|
+
"aria-label": options.ariaLabel,
|
|
261
|
+
popovertarget: native ? menuId : null // the browser opens and closes it, and a click on the button is not a click "outside"
|
|
252
262
|
}
|
|
253
263
|
});
|
|
254
264
|
if (options.icon) button.append(setContent(el("span", { class: "dropdown-icon", attrs: { "aria-hidden": "true" } }), options.icon));
|
|
@@ -257,18 +267,44 @@ export function generateDropdown(options = {}) {
|
|
|
257
267
|
const element = el("div", { id: options.id, class: cx("dropdown", options.class) }, button, menu);
|
|
258
268
|
|
|
259
269
|
const enabledItems = () => [...menu.querySelectorAll("[role=menuitem]:not([disabled])")];
|
|
270
|
+
// Without the popover API: the click outside is looked for here
|
|
260
271
|
const onOutside = event => { if (!element.contains(event.target)) close(); };
|
|
272
|
+
let stopFollowing = null;
|
|
261
273
|
function open() {
|
|
262
|
-
menu
|
|
274
|
+
if (isOpen(menu)) return;
|
|
275
|
+
if (native) {
|
|
276
|
+
openPopover(menu); // the handlers below place it and set aria-expanded
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
placePopover(button, menu, { align });
|
|
280
|
+
openPopover(menu);
|
|
281
|
+
settlePopover(menu);
|
|
263
282
|
button.setAttribute("aria-expanded", "true");
|
|
264
283
|
document.addEventListener("pointerdown", onOutside);
|
|
265
284
|
}
|
|
266
285
|
function close(restoreFocus = false) {
|
|
267
|
-
menu
|
|
268
|
-
|
|
269
|
-
|
|
286
|
+
closePopover(menu);
|
|
287
|
+
if (!native) {
|
|
288
|
+
button.setAttribute("aria-expanded", "false");
|
|
289
|
+
document.removeEventListener("pointerdown", onOutside);
|
|
290
|
+
}
|
|
270
291
|
if (restoreFocus === true) button.focus();
|
|
271
292
|
}
|
|
293
|
+
if (native) {
|
|
294
|
+
// beforetoggle comes before the menu is drawn: placed now, it never shows at the wrong place. It comes for a click, Esc, a click outside and open().
|
|
295
|
+
menu.addEventListener("beforetoggle", event => {
|
|
296
|
+
const opened = event.newState === "open";
|
|
297
|
+
button.setAttribute("aria-expanded", String(opened));
|
|
298
|
+
if (opened) placePopover(button, menu, { align });
|
|
299
|
+
});
|
|
300
|
+
menu.addEventListener("toggle", event => {
|
|
301
|
+
stopFollowing?.();
|
|
302
|
+
stopFollowing = null;
|
|
303
|
+
if (event.newState !== "open") return;
|
|
304
|
+
settlePopover(menu); // now it has a size: keep it inside the window
|
|
305
|
+
stopFollowing = followAnchor(button, menu, { align });
|
|
306
|
+
});
|
|
307
|
+
}
|
|
272
308
|
|
|
273
309
|
for (const item of options.items ?? []) {
|
|
274
310
|
if (item.divider) {
|
|
@@ -288,11 +324,11 @@ export function generateDropdown(options = {}) {
|
|
|
288
324
|
menu.append(node);
|
|
289
325
|
}
|
|
290
326
|
|
|
291
|
-
button.addEventListener("click", () => menu
|
|
327
|
+
if (!native) button.addEventListener("click", () => (isOpen(menu) ? close() : open()));
|
|
292
328
|
button.addEventListener("keydown", event => {
|
|
293
329
|
if (event.key === "ArrowDown") {
|
|
294
330
|
event.preventDefault();
|
|
295
|
-
|
|
331
|
+
open();
|
|
296
332
|
enabledItems()[0]?.focus();
|
|
297
333
|
}
|
|
298
334
|
});
|
|
@@ -632,6 +632,29 @@ dialog.dialog::backdrop {
|
|
|
632
632
|
right: 0;
|
|
633
633
|
}
|
|
634
634
|
|
|
635
|
+
/* A popover (the dropdown menu, the tooltip) is in the top layer, placed next to its anchor by script through two variables */
|
|
636
|
+
.athena-popover[popover] {
|
|
637
|
+
position: fixed;
|
|
638
|
+
inset: auto;
|
|
639
|
+
left: var(--athena-popover-left, 0);
|
|
640
|
+
top: var(--athena-popover-top, 0);
|
|
641
|
+
margin: 0;
|
|
642
|
+
width: max-content;
|
|
643
|
+
max-width: min(92vw, 36em);
|
|
644
|
+
overflow: visible;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
.athena-popover-center { translate: -50% 0; }
|
|
648
|
+
.athena-popover-end { translate: -100% 0; }
|
|
649
|
+
.athena-popover-above { translate: 0 -100%; }
|
|
650
|
+
.athena-popover-center.athena-popover-above { translate: -50% -100%; }
|
|
651
|
+
.athena-popover-end.athena-popover-above { translate: -100% -100%; }
|
|
652
|
+
|
|
653
|
+
.dropdown-menu[popover] {
|
|
654
|
+
max-height: min(70vh, 28em);
|
|
655
|
+
overflow-y: auto;
|
|
656
|
+
}
|
|
657
|
+
|
|
635
658
|
.dropdown-item {
|
|
636
659
|
display: block;
|
|
637
660
|
width: 100%;
|
|
@@ -884,6 +907,15 @@ dialog.dialog::backdrop {
|
|
|
884
907
|
opacity: 1;
|
|
885
908
|
}
|
|
886
909
|
|
|
910
|
+
/* As a popover it is only drawn while it is open, so it is always visible; the position comes from placePopover() */
|
|
911
|
+
.tooltip-text[popover] {
|
|
912
|
+
border: 0;
|
|
913
|
+
bottom: auto;
|
|
914
|
+
transform: none;
|
|
915
|
+
visibility: visible;
|
|
916
|
+
opacity: 1;
|
|
917
|
+
}
|
|
918
|
+
|
|
887
919
|
/* Combobox (autocomplete, multi select) and chips */
|
|
888
920
|
|
|
889
921
|
.combobox {
|