@cedx/ui 0.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/License.md +20 -0
- package/ReadMe.md +17 -0
- package/lib/Alignment.d.ts +22 -0
- package/lib/Alignment.d.ts.map +1 -0
- package/lib/Alignment.js +17 -0
- package/lib/AppTheme.d.ts +34 -0
- package/lib/AppTheme.d.ts.map +1 -0
- package/lib/AppTheme.js +41 -0
- package/lib/Components/BackButton.d.ts +27 -0
- package/lib/Components/BackButton.d.ts.map +1 -0
- package/lib/Components/BackButton.js +29 -0
- package/lib/Components/DialogBox.d.ts +151 -0
- package/lib/Components/DialogBox.d.ts.map +1 -0
- package/lib/Components/DialogBox.js +268 -0
- package/lib/Components/FullScreenToggler.d.ts +42 -0
- package/lib/Components/FullScreenToggler.d.ts.map +1 -0
- package/lib/Components/FullScreenToggler.js +103 -0
- package/lib/Components/KeyboardAccelerator.d.ts +36 -0
- package/lib/Components/KeyboardAccelerator.d.ts.map +1 -0
- package/lib/Components/KeyboardAccelerator.js +78 -0
- package/lib/Components/LoadingIndicator.d.ts +58 -0
- package/lib/Components/LoadingIndicator.d.ts.map +1 -0
- package/lib/Components/LoadingIndicator.js +93 -0
- package/lib/Components/MenuActivator.d.ts +26 -0
- package/lib/Components/MenuActivator.d.ts.map +1 -0
- package/lib/Components/MenuActivator.js +42 -0
- package/lib/Components/OfflineIndicator.d.ts +59 -0
- package/lib/Components/OfflineIndicator.d.ts.map +1 -0
- package/lib/Components/OfflineIndicator.js +106 -0
- package/lib/Components/TabActivator.d.ts +49 -0
- package/lib/Components/TabActivator.d.ts.map +1 -0
- package/lib/Components/TabActivator.js +70 -0
- package/lib/Components/ThemeDropdown.d.ts +86 -0
- package/lib/Components/ThemeDropdown.d.ts.map +1 -0
- package/lib/Components/ThemeDropdown.js +207 -0
- package/lib/Components/Toast.d.ts +94 -0
- package/lib/Components/Toast.d.ts.map +1 -0
- package/lib/Components/Toast.js +284 -0
- package/lib/Components/Toaster.d.ts +119 -0
- package/lib/Components/Toaster.d.ts.map +1 -0
- package/lib/Components/Toaster.js +153 -0
- package/lib/Components/TypeAhead.d.ts +53 -0
- package/lib/Components/TypeAhead.d.ts.map +1 -0
- package/lib/Components/TypeAhead.js +138 -0
- package/lib/Context.d.ts +38 -0
- package/lib/Context.d.ts.map +1 -0
- package/lib/Context.js +42 -0
- package/lib/DialogResult.d.ts +30 -0
- package/lib/DialogResult.d.ts.map +1 -0
- package/lib/DialogResult.js +29 -0
- package/lib/File.d.ts +25 -0
- package/lib/File.d.ts.map +1 -0
- package/lib/File.js +66 -0
- package/lib/Form.d.ts +33 -0
- package/lib/Form.d.ts.map +1 -0
- package/lib/Form.js +50 -0
- package/lib/Htmx.d.ts +12 -0
- package/lib/Htmx.d.ts.map +1 -0
- package/lib/Htmx.js +2 -0
- package/lib/KeyboardModifiers.d.ts +26 -0
- package/lib/KeyboardModifiers.d.ts.map +1 -0
- package/lib/KeyboardModifiers.js +25 -0
- package/lib/Position.d.ts +52 -0
- package/lib/Position.d.ts.map +1 -0
- package/lib/Position.js +59 -0
- package/lib/Size.d.ts +40 -0
- package/lib/Size.d.ts.map +1 -0
- package/lib/Size.js +44 -0
- package/lib/StorageArea.d.ts +18 -0
- package/lib/StorageArea.d.ts.map +1 -0
- package/lib/StorageArea.js +13 -0
- package/lib/Tags.d.ts +15 -0
- package/lib/Tags.d.ts.map +1 -0
- package/lib/Tags.js +48 -0
- package/lib/Variant.d.ts +36 -0
- package/lib/Variant.d.ts.map +1 -0
- package/lib/Variant.js +31 -0
- package/lib/ViewportScroller.d.ts +49 -0
- package/lib/ViewportScroller.d.ts.map +1 -0
- package/lib/ViewportScroller.js +69 -0
- package/package.json +58 -0
- package/src/Client/Alignment.ts +25 -0
- package/src/Client/AppTheme.ts +51 -0
- package/src/Client/Components/BackButton.ts +45 -0
- package/src/Client/Components/DialogBox.ts +344 -0
- package/src/Client/Components/FullScreenToggler.ts +122 -0
- package/src/Client/Components/KeyboardAccelerator.ts +97 -0
- package/src/Client/Components/LoadingIndicator.ts +113 -0
- package/src/Client/Components/MenuActivator.ts +58 -0
- package/src/Client/Components/OfflineIndicator.ts +125 -0
- package/src/Client/Components/TabActivator.ts +93 -0
- package/src/Client/Components/ThemeDropdown.ts +235 -0
- package/src/Client/Components/Toast.ts +319 -0
- package/src/Client/Components/Toaster.ts +224 -0
- package/src/Client/Components/TypeAhead.ts +153 -0
- package/src/Client/Context.ts +53 -0
- package/src/Client/DialogResult.ts +35 -0
- package/src/Client/File.ts +73 -0
- package/src/Client/Form.ts +55 -0
- package/src/Client/Htmx.ts +13 -0
- package/src/Client/KeyboardModifiers.ts +30 -0
- package/src/Client/Position.ts +74 -0
- package/src/Client/Size.ts +56 -0
- package/src/Client/StorageArea.ts +20 -0
- package/src/Client/Tags.ts +58 -0
- package/src/Client/Variant.ts +42 -0
- package/src/Client/ViewportScroller.ts +89 -0
- package/src/Client/tsconfig.json +19 -0
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { Toast as BootstrapToast } from "bootstrap";
|
|
2
|
+
import { Context, cssClass, icon } from "../Context.js";
|
|
3
|
+
/**
|
|
4
|
+
* Represents a notification.
|
|
5
|
+
*/
|
|
6
|
+
export class Toast extends HTMLElement {
|
|
7
|
+
/**
|
|
8
|
+
* The list of observed attributes.
|
|
9
|
+
*/
|
|
10
|
+
static observedAttributes = ["autohide", "caption", "context", "culture", "delay", "fade", "icon"];
|
|
11
|
+
/**
|
|
12
|
+
* The time units.
|
|
13
|
+
*/
|
|
14
|
+
static #timeUnits = ["second", "minute", "hour"];
|
|
15
|
+
/**
|
|
16
|
+
* The abort controller used to remove the event listeners.
|
|
17
|
+
*/
|
|
18
|
+
#abortController = null;
|
|
19
|
+
/**
|
|
20
|
+
* The formatter used to format the relative time.
|
|
21
|
+
*/
|
|
22
|
+
#formatter;
|
|
23
|
+
/**
|
|
24
|
+
* The time at which this component was initially shown.
|
|
25
|
+
*/
|
|
26
|
+
#initialTime = Date.now();
|
|
27
|
+
/**
|
|
28
|
+
* The timer identifier.
|
|
29
|
+
*/
|
|
30
|
+
#timer = 0;
|
|
31
|
+
/**
|
|
32
|
+
* The underlying Bootstrap toast.
|
|
33
|
+
*/
|
|
34
|
+
#toast;
|
|
35
|
+
/**
|
|
36
|
+
* Registers the component.
|
|
37
|
+
*/
|
|
38
|
+
static {
|
|
39
|
+
customElements.define("toaster-item", this);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Value indicating whether to automatically hide this toast.
|
|
43
|
+
*/
|
|
44
|
+
get autoHide() {
|
|
45
|
+
return this.hasAttribute("autohide");
|
|
46
|
+
}
|
|
47
|
+
set autoHide(value) {
|
|
48
|
+
this.toggleAttribute("autohide", value);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The child content displayed in the body.
|
|
52
|
+
*/
|
|
53
|
+
set body(value) {
|
|
54
|
+
this.querySelector(".toast-body").replaceChildren(...value.childNodes);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The title displayed in the header.
|
|
58
|
+
*/
|
|
59
|
+
get caption() {
|
|
60
|
+
return (this.getAttribute("caption") ?? "").trim();
|
|
61
|
+
}
|
|
62
|
+
set caption(value) {
|
|
63
|
+
this.setAttribute("caption", value);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A contextual modifier.
|
|
67
|
+
*/
|
|
68
|
+
get context() {
|
|
69
|
+
const value = this.getAttribute("context");
|
|
70
|
+
return Object.values(Context).includes(value) ? value : Context.Info;
|
|
71
|
+
}
|
|
72
|
+
set context(value) {
|
|
73
|
+
this.setAttribute("context", value);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The culture used to format the relative time.
|
|
77
|
+
*/
|
|
78
|
+
get culture() {
|
|
79
|
+
const value = this.getAttribute("culture") ?? "";
|
|
80
|
+
return new Intl.Locale(value.trim() || navigator.language);
|
|
81
|
+
}
|
|
82
|
+
set culture(value) {
|
|
83
|
+
this.setAttribute("culture", value.toString());
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The delay, in milliseconds, to hide this toast.
|
|
87
|
+
*/
|
|
88
|
+
get delay() {
|
|
89
|
+
const value = Number(this.getAttribute("delay"));
|
|
90
|
+
return Math.max(0, Number.isNaN(value) ? 5_000 : value);
|
|
91
|
+
}
|
|
92
|
+
set delay(value) {
|
|
93
|
+
this.setAttribute("delay", value.toString());
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The time elapsed since this component was initially shown, in milliseconds.
|
|
97
|
+
*/
|
|
98
|
+
get elapsedTime() {
|
|
99
|
+
return Date.now() - this.#initialTime;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Value indicating whether to apply a transition.
|
|
103
|
+
*/
|
|
104
|
+
get fade() {
|
|
105
|
+
return this.hasAttribute("fade");
|
|
106
|
+
}
|
|
107
|
+
set fade(value) {
|
|
108
|
+
this.toggleAttribute("fade", value);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The icon displayed next to the caption.
|
|
112
|
+
*/
|
|
113
|
+
get icon() {
|
|
114
|
+
const value = this.getAttribute("icon") ?? "";
|
|
115
|
+
return value.trim() || null;
|
|
116
|
+
}
|
|
117
|
+
set icon(value) {
|
|
118
|
+
if (value)
|
|
119
|
+
this.setAttribute("icon", value);
|
|
120
|
+
else
|
|
121
|
+
this.removeAttribute("icon");
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Value indicating whether to initially show this component.
|
|
125
|
+
*/
|
|
126
|
+
get open() {
|
|
127
|
+
return this.hasAttribute("open");
|
|
128
|
+
}
|
|
129
|
+
set open(value) {
|
|
130
|
+
this.toggleAttribute("open", value);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Method invoked when an attribute has been changed.
|
|
134
|
+
* @param attribute The attribute name.
|
|
135
|
+
* @param oldValue The previous attribute value.
|
|
136
|
+
* @param newValue The new attribute value.
|
|
137
|
+
*/
|
|
138
|
+
attributeChangedCallback(attribute, oldValue, newValue) {
|
|
139
|
+
if (newValue != oldValue)
|
|
140
|
+
switch (attribute) {
|
|
141
|
+
case "autohide":
|
|
142
|
+
this.#updateAutoHide(newValue != null);
|
|
143
|
+
break;
|
|
144
|
+
case "caption":
|
|
145
|
+
this.#updateCaption(newValue ?? "");
|
|
146
|
+
break;
|
|
147
|
+
case "context":
|
|
148
|
+
this.#updateContext(Object.values(Context).includes(newValue) ? newValue : Context.Info);
|
|
149
|
+
break;
|
|
150
|
+
case "culture":
|
|
151
|
+
this.#formatter = new Intl.RelativeTimeFormat((newValue ?? "").trim() || navigator.language, { style: "long" });
|
|
152
|
+
break;
|
|
153
|
+
case "delay":
|
|
154
|
+
this.#updateDelay(Number(newValue));
|
|
155
|
+
break;
|
|
156
|
+
case "fade":
|
|
157
|
+
this.#updateFade(newValue != null);
|
|
158
|
+
break;
|
|
159
|
+
case "icon":
|
|
160
|
+
this.#updateIcon(newValue);
|
|
161
|
+
break;
|
|
162
|
+
// No default
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Closes this toast.
|
|
167
|
+
*/
|
|
168
|
+
close() {
|
|
169
|
+
this.#toast.hide();
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Method invoked when this component is connected.
|
|
173
|
+
*/
|
|
174
|
+
connectedCallback() {
|
|
175
|
+
this.#abortController = new AbortController;
|
|
176
|
+
const root = this.firstElementChild;
|
|
177
|
+
root.addEventListener("hide.bs.toast", () => this.#stopTimer(), { signal: this.#abortController.signal });
|
|
178
|
+
root.addEventListener("show.bs.toast", () => this.#startTimer(), { signal: this.#abortController.signal });
|
|
179
|
+
this.#toast = new BootstrapToast(root);
|
|
180
|
+
if (this.open)
|
|
181
|
+
this.show();
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Method invoked when this component is disconnected.
|
|
185
|
+
*/
|
|
186
|
+
disconnectedCallback() {
|
|
187
|
+
this.#stopTimer();
|
|
188
|
+
this.#abortController?.abort();
|
|
189
|
+
this.#toast.dispose();
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Shows this toast.
|
|
193
|
+
*/
|
|
194
|
+
show() {
|
|
195
|
+
if (!this.#toast.isShown()) {
|
|
196
|
+
this.#initialTime = Date.now();
|
|
197
|
+
this.#updateElapsedTime();
|
|
198
|
+
}
|
|
199
|
+
this.#toast.show();
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Formats the specified elapsed time.
|
|
203
|
+
* @param elapsed The elapsed time, in seconds.
|
|
204
|
+
* @returns The formated time.
|
|
205
|
+
*/
|
|
206
|
+
#formatTime(elapsed) {
|
|
207
|
+
let index = 0;
|
|
208
|
+
while (elapsed > 60 && index < Toast.#timeUnits.length) {
|
|
209
|
+
elapsed /= 60;
|
|
210
|
+
index++;
|
|
211
|
+
}
|
|
212
|
+
return this.#formatter.format(Math.ceil(-elapsed), Toast.#timeUnits[index]);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Starts the timer.
|
|
216
|
+
*/
|
|
217
|
+
#startTimer() {
|
|
218
|
+
this.#timer = window.setInterval(() => this.#updateElapsedTime(), 1_000);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Stops the timer.
|
|
222
|
+
*/
|
|
223
|
+
#stopTimer() {
|
|
224
|
+
clearInterval(this.#timer);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Updates the value indicating whether to automatically hide this toast.
|
|
228
|
+
* @param value The new value.
|
|
229
|
+
*/
|
|
230
|
+
#updateAutoHide(value) {
|
|
231
|
+
this.firstElementChild.dataset.bsAutohide = value ? "true" : "false";
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Updates the title displayed in the header.
|
|
235
|
+
* @param value The new value.
|
|
236
|
+
*/
|
|
237
|
+
#updateCaption(value) {
|
|
238
|
+
this.querySelector(".toast-header b").textContent = value.trim();
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Updates the contextual modifier.
|
|
242
|
+
* @param value The new value.
|
|
243
|
+
*/
|
|
244
|
+
#updateContext(value) {
|
|
245
|
+
const contexts = Object.values(Context);
|
|
246
|
+
let { classList } = this.querySelector(".toast-header");
|
|
247
|
+
classList.remove(...contexts.map(context => `toast-header-${cssClass(context)}`));
|
|
248
|
+
classList.add(`toast-header-${cssClass(value)}`);
|
|
249
|
+
({ classList } = this.querySelector(".toast-header .icon"));
|
|
250
|
+
classList.remove(...contexts.map(context => `text-${cssClass(context)}`));
|
|
251
|
+
classList.add(`text-${cssClass(value)}`);
|
|
252
|
+
if (!this.icon)
|
|
253
|
+
this.#updateIcon(icon(value));
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Updates the delay to hide the toast.
|
|
257
|
+
* @param value The new value.
|
|
258
|
+
*/
|
|
259
|
+
#updateDelay(value) {
|
|
260
|
+
const delay = Math.max(0, Number.isNaN(value) ? 5_000 : value);
|
|
261
|
+
this.firstElementChild.dataset.bsDelay = delay.toString();
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Updates the label corresponding to the elapsed time.
|
|
265
|
+
*/
|
|
266
|
+
#updateElapsedTime() {
|
|
267
|
+
const { elapsedTime } = this;
|
|
268
|
+
this.querySelector(".toast-header small").textContent = elapsedTime > 0 ? this.#formatTime(elapsedTime / 1_000) : "";
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Updates the value indicating whether to apply a transition.
|
|
272
|
+
* @param value The new value.
|
|
273
|
+
*/
|
|
274
|
+
#updateFade(value) {
|
|
275
|
+
this.firstElementChild.dataset.bsAnimation = value ? "true" : "false";
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Updates the icon displayed next to the caption.
|
|
279
|
+
* @param value The new value.
|
|
280
|
+
*/
|
|
281
|
+
#updateIcon(value) {
|
|
282
|
+
this.querySelector(".toast-header .icon").textContent = (value ?? "").trim() || icon(this.context);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Context } from "../Context.js";
|
|
2
|
+
import { Position } from "../Position.js";
|
|
3
|
+
/**
|
|
4
|
+
* Represents a notification.
|
|
5
|
+
*/
|
|
6
|
+
export interface IToast {
|
|
7
|
+
/**
|
|
8
|
+
* Value indicating whether to automatically hide the toast.
|
|
9
|
+
*/
|
|
10
|
+
autoHide?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* The child content displayed in the body.
|
|
13
|
+
*/
|
|
14
|
+
body: DocumentFragment;
|
|
15
|
+
/**
|
|
16
|
+
* The title displayed in the header.
|
|
17
|
+
*/
|
|
18
|
+
caption: string;
|
|
19
|
+
/**
|
|
20
|
+
* The default contextual modifier.
|
|
21
|
+
*/
|
|
22
|
+
context?: Context;
|
|
23
|
+
/**
|
|
24
|
+
* The culture used to format the relative time.
|
|
25
|
+
*/
|
|
26
|
+
culture?: Intl.Locale;
|
|
27
|
+
/**
|
|
28
|
+
* The delay, in milliseconds, to hide the toast.
|
|
29
|
+
*/
|
|
30
|
+
delay?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Value indicating whether to apply a transition.
|
|
33
|
+
*/
|
|
34
|
+
fade?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* The icon displayed next to the caption.
|
|
37
|
+
*/
|
|
38
|
+
icon?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Manages the notifications.
|
|
42
|
+
*/
|
|
43
|
+
export declare class Toaster extends HTMLElement {
|
|
44
|
+
#private;
|
|
45
|
+
/**
|
|
46
|
+
* The list of observed attributes.
|
|
47
|
+
*/
|
|
48
|
+
static readonly observedAttributes: string[];
|
|
49
|
+
/**
|
|
50
|
+
* Creates a new toaster.
|
|
51
|
+
*/
|
|
52
|
+
constructor();
|
|
53
|
+
/**
|
|
54
|
+
* Value indicating whether to automatically hide the toasts.
|
|
55
|
+
*/
|
|
56
|
+
get autoHide(): boolean;
|
|
57
|
+
set autoHide(value: boolean);
|
|
58
|
+
/**
|
|
59
|
+
* The default contextual modifier.
|
|
60
|
+
*/
|
|
61
|
+
get context(): Context;
|
|
62
|
+
set context(value: Context);
|
|
63
|
+
/**
|
|
64
|
+
* The default culture used to format the relative times.
|
|
65
|
+
*/
|
|
66
|
+
get culture(): Intl.Locale;
|
|
67
|
+
set culture(value: Intl.Locale);
|
|
68
|
+
/**
|
|
69
|
+
* The default delay, in milliseconds, to hide the toasts.
|
|
70
|
+
*/
|
|
71
|
+
get delay(): number;
|
|
72
|
+
set delay(value: number);
|
|
73
|
+
/**
|
|
74
|
+
* Value indicating whether to apply a transition.
|
|
75
|
+
*/
|
|
76
|
+
get fade(): boolean;
|
|
77
|
+
set fade(value: boolean);
|
|
78
|
+
/**
|
|
79
|
+
* The default icon displayed next to the captions.
|
|
80
|
+
*/
|
|
81
|
+
get icon(): string | null;
|
|
82
|
+
set icon(value: string | null);
|
|
83
|
+
/**
|
|
84
|
+
* The toaster placement.
|
|
85
|
+
*/
|
|
86
|
+
get position(): Position;
|
|
87
|
+
set position(value: Position);
|
|
88
|
+
/**
|
|
89
|
+
* Method invoked when an attribute has been changed.
|
|
90
|
+
* @param attribute The attribute name.
|
|
91
|
+
* @param oldValue The previous attribute value.
|
|
92
|
+
* @param newValue The new attribute value.
|
|
93
|
+
*/
|
|
94
|
+
attributeChangedCallback(attribute: string, oldValue: string | null, newValue: string | null): void;
|
|
95
|
+
/**
|
|
96
|
+
* Shows a toast.
|
|
97
|
+
* @param context The contextual modifier.
|
|
98
|
+
* @param caption The title displayed in the toast header.
|
|
99
|
+
* @param message The child content displayed in the toast body.
|
|
100
|
+
*/
|
|
101
|
+
notify(context: Context, caption: string, message: DocumentFragment): void;
|
|
102
|
+
/**
|
|
103
|
+
* Shows a toast.
|
|
104
|
+
* @param toast The toast to show.
|
|
105
|
+
*/
|
|
106
|
+
show(toast: IToast): void;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Declaration merging.
|
|
110
|
+
*/
|
|
111
|
+
declare global {
|
|
112
|
+
/**
|
|
113
|
+
* The map of HTML tag names.
|
|
114
|
+
*/
|
|
115
|
+
interface HTMLElementTagNameMap {
|
|
116
|
+
"toaster-container": Toaster;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=Toaster.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Toaster.d.ts","sourceRoot":"","sources":["../../src/Client/Components/Toaster.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AACtC,OAAO,EAAC,QAAQ,EAAW,MAAM,gBAAgB,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,MAAM;IAEtB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,IAAI,EAAE,gBAAgB,CAAC;IAEvB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,OAAO,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IAEtB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,qBAAa,OAAQ,SAAQ,WAAW;;IAEvC;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,kBAAkB,WAAgB;IAOlD;;OAEG;;IAaH;;OAEG;IACH,IAAI,QAAQ,IAAI,OAAO,CAEtB;IACD,IAAI,QAAQ,CAAC,KAAK,EAAE,OAAO,EAE1B;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,OAAO,CAGrB;IACD,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,EAEzB;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,IAAI,CAAC,MAAM,CAGzB;IACD,IAAI,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAE7B;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAGlB;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,EAEtB;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,OAAO,CAElB;IACD,IAAI,IAAI,CAAC,KAAK,EAAE,OAAO,EAEtB;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,GAAC,IAAI,CAGtB;IACD,IAAI,IAAI,CAAC,KAAK,EAAE,MAAM,GAAC,IAAI,EAG1B;IAED;;OAEG;IACH,IAAI,QAAQ,IAAI,QAAQ,CAGvB;IACD,IAAI,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAE3B;IAED;;;;;OAKG;IACH,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,GAAG,IAAI;IAO/F;;;;;OAKG;IACH,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,IAAI;IAI1E;;;OAGG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;CA4BzB;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,mBAAmB,EAAE,OAAO,CAAC;KAC7B;CACD"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { Context } from "../Context.js";
|
|
2
|
+
import { Position, cssClass } from "../Position.js";
|
|
3
|
+
/**
|
|
4
|
+
* Manages the notifications.
|
|
5
|
+
*/
|
|
6
|
+
export class Toaster extends HTMLElement {
|
|
7
|
+
/**
|
|
8
|
+
* The list of observed attributes.
|
|
9
|
+
*/
|
|
10
|
+
static observedAttributes = ["position"];
|
|
11
|
+
/**
|
|
12
|
+
* The template for a toast.
|
|
13
|
+
*/
|
|
14
|
+
#toastTemplate = this.querySelector("template").content;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new toaster.
|
|
17
|
+
*/
|
|
18
|
+
constructor() {
|
|
19
|
+
super();
|
|
20
|
+
for (const toast of this.querySelectorAll("toaster-item"))
|
|
21
|
+
toast.addEventListener("hidden.bs.toast", () => toast.remove());
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Registers the component.
|
|
25
|
+
*/
|
|
26
|
+
static {
|
|
27
|
+
customElements.define("toaster-container", this);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Value indicating whether to automatically hide the toasts.
|
|
31
|
+
*/
|
|
32
|
+
get autoHide() {
|
|
33
|
+
return this.hasAttribute("autohide");
|
|
34
|
+
}
|
|
35
|
+
set autoHide(value) {
|
|
36
|
+
this.toggleAttribute("autohide", value);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The default contextual modifier.
|
|
40
|
+
*/
|
|
41
|
+
get context() {
|
|
42
|
+
const value = this.getAttribute("context");
|
|
43
|
+
return Object.values(Context).includes(value) ? value : Context.Info;
|
|
44
|
+
}
|
|
45
|
+
set context(value) {
|
|
46
|
+
this.setAttribute("context", value);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The default culture used to format the relative times.
|
|
50
|
+
*/
|
|
51
|
+
get culture() {
|
|
52
|
+
const value = this.getAttribute("culture") ?? "";
|
|
53
|
+
return new Intl.Locale(value.trim() || navigator.language);
|
|
54
|
+
}
|
|
55
|
+
set culture(value) {
|
|
56
|
+
this.setAttribute("culture", value.toString());
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The default delay, in milliseconds, to hide the toasts.
|
|
60
|
+
*/
|
|
61
|
+
get delay() {
|
|
62
|
+
const value = Number(this.getAttribute("delay"));
|
|
63
|
+
return Math.max(0, Number.isNaN(value) ? 5_000 : value);
|
|
64
|
+
}
|
|
65
|
+
set delay(value) {
|
|
66
|
+
this.setAttribute("delay", value.toString());
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Value indicating whether to apply a transition.
|
|
70
|
+
*/
|
|
71
|
+
get fade() {
|
|
72
|
+
return this.hasAttribute("fade");
|
|
73
|
+
}
|
|
74
|
+
set fade(value) {
|
|
75
|
+
this.toggleAttribute("fade", value);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The default icon displayed next to the captions.
|
|
79
|
+
*/
|
|
80
|
+
get icon() {
|
|
81
|
+
const value = this.getAttribute("icon") ?? "";
|
|
82
|
+
return value.trim() || null;
|
|
83
|
+
}
|
|
84
|
+
set icon(value) {
|
|
85
|
+
if (value)
|
|
86
|
+
this.setAttribute("icon", value);
|
|
87
|
+
else
|
|
88
|
+
this.removeAttribute("icon");
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The toaster placement.
|
|
92
|
+
*/
|
|
93
|
+
get position() {
|
|
94
|
+
const value = this.getAttribute("position");
|
|
95
|
+
return Object.values(Position).includes(value) ? value : Position.BottomEnd;
|
|
96
|
+
}
|
|
97
|
+
set position(value) {
|
|
98
|
+
this.setAttribute("position", value);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Method invoked when an attribute has been changed.
|
|
102
|
+
* @param attribute The attribute name.
|
|
103
|
+
* @param oldValue The previous attribute value.
|
|
104
|
+
* @param newValue The new attribute value.
|
|
105
|
+
*/
|
|
106
|
+
attributeChangedCallback(attribute, oldValue, newValue) {
|
|
107
|
+
if (newValue != oldValue)
|
|
108
|
+
switch (attribute) {
|
|
109
|
+
case "position":
|
|
110
|
+
this.#updatePosition(Object.values(Position).includes(newValue) ? newValue : Position.BottomEnd);
|
|
111
|
+
break;
|
|
112
|
+
// No default
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Shows a toast.
|
|
117
|
+
* @param context The contextual modifier.
|
|
118
|
+
* @param caption The title displayed in the toast header.
|
|
119
|
+
* @param message The child content displayed in the toast body.
|
|
120
|
+
*/
|
|
121
|
+
notify(context, caption, message) {
|
|
122
|
+
return this.show({ body: message, caption, context });
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Shows a toast.
|
|
126
|
+
* @param toast The toast to show.
|
|
127
|
+
*/
|
|
128
|
+
show(toast) {
|
|
129
|
+
const item = document.createElement("toaster-item");
|
|
130
|
+
const childContent = this.#toastTemplate.cloneNode(true).querySelector(".toast");
|
|
131
|
+
childContent.addEventListener("hidden.bs.toast", () => item.remove());
|
|
132
|
+
item.appendChild(childContent);
|
|
133
|
+
item.autoHide = toast.autoHide ?? this.autoHide;
|
|
134
|
+
item.body = toast.body;
|
|
135
|
+
item.caption = toast.caption;
|
|
136
|
+
item.context = toast.context ?? this.context;
|
|
137
|
+
item.culture = toast.culture ?? this.culture;
|
|
138
|
+
item.delay = toast.delay ?? this.delay;
|
|
139
|
+
item.fade = toast.fade ?? this.fade;
|
|
140
|
+
item.icon = toast.icon ?? this.icon;
|
|
141
|
+
this.firstElementChild.appendChild(item);
|
|
142
|
+
item.show();
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Updates the toaster placement.
|
|
146
|
+
* @param value The new value.
|
|
147
|
+
*/
|
|
148
|
+
#updatePosition(value) {
|
|
149
|
+
const { classList } = this.firstElementChild;
|
|
150
|
+
classList.remove(...Object.values(Position).flatMap(position => cssClass(position).split(" ")));
|
|
151
|
+
classList.add(...cssClass(value).split(" "));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A dynamic list of suggested values for an associated control.
|
|
3
|
+
*/
|
|
4
|
+
export declare class TypeAhead extends HTMLElement {
|
|
5
|
+
#private;
|
|
6
|
+
/**
|
|
7
|
+
* The list of observed attributes.
|
|
8
|
+
*/
|
|
9
|
+
static readonly observedAttributes: string[];
|
|
10
|
+
/**
|
|
11
|
+
* The delay in milliseconds to wait before triggering autocomplete suggestions.
|
|
12
|
+
*/
|
|
13
|
+
get delay(): number;
|
|
14
|
+
set delay(value: number);
|
|
15
|
+
/**
|
|
16
|
+
* The function invoked when the query has been changed.
|
|
17
|
+
*/
|
|
18
|
+
set handler(callback: (query: string) => Promise<string[]>);
|
|
19
|
+
/**
|
|
20
|
+
* The data list identifier.
|
|
21
|
+
*/
|
|
22
|
+
get list(): string;
|
|
23
|
+
set list(value: string);
|
|
24
|
+
/**
|
|
25
|
+
* The minimum character length needed before triggering autocomplete suggestions.
|
|
26
|
+
*/
|
|
27
|
+
get minLength(): number;
|
|
28
|
+
set minLength(value: number);
|
|
29
|
+
/**
|
|
30
|
+
* The query to look up.
|
|
31
|
+
*/
|
|
32
|
+
get query(): string;
|
|
33
|
+
set query(value: string);
|
|
34
|
+
/**
|
|
35
|
+
* Method invoked when an attribute has been changed.
|
|
36
|
+
* @param attribute The attribute name.
|
|
37
|
+
* @param oldValue The previous attribute value.
|
|
38
|
+
* @param newValue The new attribute value.
|
|
39
|
+
*/
|
|
40
|
+
attributeChangedCallback(attribute: string, oldValue: string | null, newValue: string | null): void;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Declaration merging.
|
|
44
|
+
*/
|
|
45
|
+
declare global {
|
|
46
|
+
/**
|
|
47
|
+
* The map of HTML tag names.
|
|
48
|
+
*/
|
|
49
|
+
interface HTMLElementTagNameMap {
|
|
50
|
+
"type-ahead": TypeAhead;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=TypeAhead.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypeAhead.d.ts","sourceRoot":"","sources":["../../src/Client/Components/TypeAhead.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,SAAU,SAAQ,WAAW;;IAEzC;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,kBAAkB,WAAqB;IAmBvD;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAGlB;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,EAEtB;IAED;;OAEG;IACH,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,EAKzD;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IACD,IAAI,IAAI,CAAC,KAAK,EAAE,MAAM,EAErB;IAED;;OAEG;IACH,IAAI,SAAS,IAAI,MAAM,CAGtB;IACD,IAAI,SAAS,CAAC,KAAK,EAAE,MAAM,EAE1B;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,EAEtB;IAED;;;;;OAKG;IACH,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,GAAG,IAAI;CAsD/F;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,YAAY,EAAE,SAAS,CAAC;KACxB;CACD"}
|