athena-ui-js 2.5.0 → 2.6.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 +1158 -1122
- package/docs/migration-2.0.md +99 -83
- package/docs/styling.md +124 -123
- package/package.json +176 -189
- package/src/app.js +85 -0
- package/src/athena-ui.js +60 -135
- package/src/libs/config/config.js +66 -66
- package/src/libs/core/i18n.js +354 -352
- package/src/libs/hephaestus/MenuGenerator/menuGenerator.js +278 -265
- package/src/libs/hephaestus/chartGenerator/chartGenerator.js +772 -722
- package/src/libs/hephaestus/feedbackGenerator/feedbackGenerator.js +171 -161
- package/src/libs/hephaestus/formGenerator/formBuilder.js +470 -460
- package/src/libs/hephaestus/tableGenerator/tableGenerator.js +837 -825
- package/src/res/themes/default/style.css +3128 -3037
- package/types/app.d.ts +58 -0
- package/types/athena-ui.d.ts +1 -55
- package/types/libs/config/config.d.ts +96 -96
- package/types/libs/hephaestus/MenuGenerator/menuGenerator.d.ts +5 -0
- package/types/libs/hephaestus/chartGenerator/chartGenerator.d.ts +123 -117
- package/types/libs/hephaestus/dialogGenerator/dialogGenerator.d.ts +122 -122
- package/types/libs/hephaestus/feedbackGenerator/feedbackGenerator.d.ts +3 -0
- package/types/libs/hephaestus/formGenerator/authForms.d.ts +130 -130
- package/types/libs/hephaestus/formGenerator/formBuilder.d.ts +128 -128
- package/types/libs/hephaestus/tableGenerator/tableGenerator.d.ts +133 -129
|
@@ -1,161 +1,171 @@
|
|
|
1
|
-
//feedbackGenerator 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
|
-
import { asHandle, cx, el, mount, setContent } from "../../core/dom.js";
|
|
7
|
-
import { removeAfterTransition } from "../../core/motion.js";
|
|
8
|
-
import { translate } from "../../core/i18n.js";
|
|
9
|
-
|
|
10
|
-
const TOAST_CONTAINER_ID = "athena-toasts";
|
|
11
|
-
const URGENT_TYPES = new Set(["error", "warning"]);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* @param {string} options
|
|
27
|
-
* @param {string}
|
|
28
|
-
* @param {
|
|
29
|
-
* @param {
|
|
30
|
-
* @
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
timer
|
|
52
|
-
|
|
53
|
-
toast
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
1
|
+
//feedbackGenerator 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
|
+
import { asHandle, cx, el, mount, setContent } from "../../core/dom.js";
|
|
7
|
+
import { removeAfterTransition } from "../../core/motion.js";
|
|
8
|
+
import { translate } from "../../core/i18n.js";
|
|
9
|
+
|
|
10
|
+
const TOAST_CONTAINER_ID = "athena-toasts";
|
|
11
|
+
const URGENT_TYPES = new Set(["error", "warning"]);
|
|
12
|
+
const TOAST_POSITIONS = ["top-right", "top-left", "top-center", "bottom-right", "bottom-left", "bottom-center"];
|
|
13
|
+
|
|
14
|
+
function closeButton(onclick) {
|
|
15
|
+
return el("button", {
|
|
16
|
+
class: "alert-close",
|
|
17
|
+
text: "×",
|
|
18
|
+
attrs: { type: "button", "aria-label": translate("close") },
|
|
19
|
+
on: { click: onclick }
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Shows a toast notification in the corner of the page.
|
|
25
|
+
*
|
|
26
|
+
* @param {object|string} options a message, or an options object
|
|
27
|
+
* @param {string} options.message
|
|
28
|
+
* @param {string} [options.title]
|
|
29
|
+
* @param {"info"|"success"|"warning"|"error"} [options.type="info"]
|
|
30
|
+
* @param {number} [options.duration=4000] ms before it disappears, 0 keeps it until it is closed
|
|
31
|
+
* @param {"top-right"|"top-left"|"top-center"|"bottom-right"|"bottom-left"|"bottom-center"} [options.position="top-right"] the corner (or the middle of an edge) of the window.
|
|
32
|
+
* Every position has its own stack. An application that keeps its main buttons in the top right corner shows its toasts at the bottom.
|
|
33
|
+
* @param {{x?: number, y?: number}} [options.offset] the distance from the edge in px (default 16); also the variables --athena-toast-x and --athena-toast-y
|
|
34
|
+
* @returns {{close: Function}}
|
|
35
|
+
*/
|
|
36
|
+
export function showToast(options) {
|
|
37
|
+
const { message, title, type = "info", duration = 4000, offset } = typeof options === "string" ? { message: options } : options;
|
|
38
|
+
const position = TOAST_POSITIONS.includes(options?.position) ? options.position : "top-right";
|
|
39
|
+
const containerId = position === "top-right" ? TOAST_CONTAINER_ID : `${TOAST_CONTAINER_ID}-${position}`;
|
|
40
|
+
let container = document.getElementById(containerId);
|
|
41
|
+
if (!container) {
|
|
42
|
+
container = el("div", { id: containerId, class: cx("toast-container", `toast-container-${position}`) });
|
|
43
|
+
document.body.append(container);
|
|
44
|
+
}
|
|
45
|
+
if (offset) {
|
|
46
|
+
if (Number.isFinite(offset.x)) container.style.setProperty("--athena-toast-x", `${offset.x}px`);
|
|
47
|
+
if (Number.isFinite(offset.y)) container.style.setProperty("--athena-toast-y", `${offset.y}px`);
|
|
48
|
+
}
|
|
49
|
+
let timer;
|
|
50
|
+
const close = () => {
|
|
51
|
+
clearTimeout(timer);
|
|
52
|
+
toast.classList.add("is-leaving");
|
|
53
|
+
removeAfterTransition(toast);
|
|
54
|
+
};
|
|
55
|
+
const toast = el("div", {
|
|
56
|
+
class: cx("toast", `alert-${type}`),
|
|
57
|
+
attrs: { role: URGENT_TYPES.has(type) ? "alert" : "status" }
|
|
58
|
+
}, el("div", { class: "alert-body" }, title ? el("strong", { text: title }) : "", el("div", { text: message })), closeButton(close));
|
|
59
|
+
container.append(toast);
|
|
60
|
+
if (duration > 0) {
|
|
61
|
+
timer = setTimeout(close, duration);
|
|
62
|
+
// Do not hide a toast the user is reading.
|
|
63
|
+
toast.addEventListener("mouseenter", () => clearTimeout(timer));
|
|
64
|
+
toast.addEventListener("mouseleave", () => { timer = setTimeout(close, duration); });
|
|
65
|
+
}
|
|
66
|
+
return { close };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Generates an inline alert box.
|
|
71
|
+
*
|
|
72
|
+
* @param {object} options
|
|
73
|
+
* @param {string|Element} [options.parent]
|
|
74
|
+
* @param {string} [options.id]
|
|
75
|
+
* @param {string|Node} options.message
|
|
76
|
+
* @param {string} [options.title]
|
|
77
|
+
* @param {"info"|"success"|"warning"|"error"} [options.type="info"]
|
|
78
|
+
* @param {boolean} [options.dismissible]
|
|
79
|
+
* @returns {HTMLElement}
|
|
80
|
+
*/
|
|
81
|
+
export function generateAlert(options = {}) {
|
|
82
|
+
const { type = "info", title, message, dismissible } = options;
|
|
83
|
+
const body = el("div", { class: "alert-body" });
|
|
84
|
+
if (title) body.append(el("strong", { text: title }));
|
|
85
|
+
body.append(setContent(el("div"), message));
|
|
86
|
+
const alert = el("div", {
|
|
87
|
+
id: options.id,
|
|
88
|
+
class: cx("alert", `alert-${type}`, options.class),
|
|
89
|
+
attrs: { role: URGENT_TYPES.has(type) ? "alert" : "status" }
|
|
90
|
+
}, body);
|
|
91
|
+
if (dismissible) alert.append(closeButton(() => alert.remove()));
|
|
92
|
+
return mount(options.parent, alert);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Copies text to the clipboard and says so in a toast. Resolves with true when it worked (it needs a secure page and a click or key
|
|
97
|
+
* press of the person), false otherwise (a toast with the error is shown).
|
|
98
|
+
*
|
|
99
|
+
* @param {string} text
|
|
100
|
+
* @param {object} [options]
|
|
101
|
+
* @param {string} [options.message] text of the toast (default: the translated "Copied")
|
|
102
|
+
* @param {boolean} [options.toast=true] false copies silently
|
|
103
|
+
* @returns {Promise<boolean>}
|
|
104
|
+
*/
|
|
105
|
+
export async function copyToClipboard(text, { message = translate("copied"), toast = true } = {}) {
|
|
106
|
+
try {
|
|
107
|
+
await navigator.clipboard.writeText(String(text));
|
|
108
|
+
if (toast) showToast({ message, type: "success" });
|
|
109
|
+
return true;
|
|
110
|
+
} catch {
|
|
111
|
+
if (toast) showToast({ message: translate("copyFailed"), type: "error" });
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Generates a loading spinner.
|
|
118
|
+
*
|
|
119
|
+
* @param {object} [options]
|
|
120
|
+
* @param {string|Element} [options.parent]
|
|
121
|
+
* @param {string} [options.id]
|
|
122
|
+
* @param {"small"|"large"} [options.size]
|
|
123
|
+
* @param {string} [options.label] accessible text, defaults to the translated "Loading..."
|
|
124
|
+
* @returns {HTMLElement}
|
|
125
|
+
*/
|
|
126
|
+
export function generateSpinner(options = {}) {
|
|
127
|
+
return mount(options.parent, el("span", {
|
|
128
|
+
id: options.id,
|
|
129
|
+
class: cx("spinner", options.size && `spinner-${options.size}`, options.class),
|
|
130
|
+
attrs: { role: "status", "aria-label": options.label ?? translate("loading") }
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Generates a progress bar. Without a value it is indeterminate.
|
|
136
|
+
*
|
|
137
|
+
* @param {object} [options]
|
|
138
|
+
* @param {string|Element} [options.parent]
|
|
139
|
+
* @param {string} [options.id]
|
|
140
|
+
* @param {number} [options.value] 0..max
|
|
141
|
+
* @param {number} [options.max=100]
|
|
142
|
+
* @param {string} [options.label] text shown above the bar
|
|
143
|
+
* @param {"info"|"success"|"warning"|"error"} [options.type]
|
|
144
|
+
* @returns {{element: HTMLElement, setValue: (value: number) => void}}
|
|
145
|
+
*/
|
|
146
|
+
export function generateProgress(options = {}) {
|
|
147
|
+
const max = options.max ?? 100;
|
|
148
|
+
const fill = el("div", { class: "progress-fill" });
|
|
149
|
+
const bar = el("div", {
|
|
150
|
+
class: "progress-bar",
|
|
151
|
+
attrs: { role: "progressbar", "aria-valuemin": 0, "aria-valuemax": max, "aria-label": options.label ?? null }
|
|
152
|
+
}, fill);
|
|
153
|
+
const element = el("div", { id: options.id, class: cx("progress", options.type && `progress-${options.type}`, options.class) },
|
|
154
|
+
options.label ? el("div", { class: "progress-label", text: options.label }) : "", bar);
|
|
155
|
+
|
|
156
|
+
const setValue = value => {
|
|
157
|
+
const indeterminate = value == null;
|
|
158
|
+
element.classList.toggle("progress-indeterminate", indeterminate);
|
|
159
|
+
if (indeterminate) {
|
|
160
|
+
bar.removeAttribute("aria-valuenow");
|
|
161
|
+
fill.style.width = "";
|
|
162
|
+
} else {
|
|
163
|
+
const clamped = Math.min(Math.max(value, 0), max);
|
|
164
|
+
bar.setAttribute("aria-valuenow", clamped);
|
|
165
|
+
fill.style.width = `${(clamped / max) * 100}%`;
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
setValue(options.value);
|
|
169
|
+
mount(options.parent, element);
|
|
170
|
+
return asHandle({ element, setValue, update: ({ value } = {}) => setValue(value) });
|
|
171
|
+
}
|