@zeyos/zx 2.1.0 → 2.2.1
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/CHANGELOG.md +51 -0
- package/README.md +15 -0
- package/dist/types/compat/base.d.ts +156 -0
- package/dist/types/compat/globals.d.ts +20 -0
- package/dist/types/compat/index.d.ts +128 -0
- package/dist/types/compat/map/basic.d.ts +175 -0
- package/dist/types/compat/map/data.d.ts +102 -0
- package/dist/types/compat/map/date-time.d.ts +80 -0
- package/dist/types/compat/map/factory.d.ts +9 -0
- package/dist/types/compat/map/form.d.ts +98 -0
- package/dist/types/compat/map/helpers.d.ts +12 -0
- package/dist/types/compat/map/http.d.ts +36 -0
- package/dist/types/compat/map/layout.d.ts +106 -0
- package/dist/types/compat/map/options.d.ts +80 -0
- package/dist/types/compat/map/select.d.ts +95 -0
- package/dist/types/compat/map/stubs.d.ts +32 -0
- package/dist/types/compat/map/utilities.d.ts +37 -0
- package/dist/types/compat-entry.d.ts +5 -0
- package/dist/types/components/badge/badge.d.ts +46 -0
- package/dist/types/components/breadcrumb/breadcrumb.d.ts +200 -0
- package/dist/types/components/button/button.d.ts +42 -0
- package/dist/types/components/check-button/check-button.d.ts +98 -0
- package/dist/types/components/checklist/checklist.d.ts +143 -0
- package/dist/types/components/checklist/field-adapter.d.ts +5 -0
- package/dist/types/components/context-menu/context-menu.d.ts +130 -0
- package/dist/types/components/copy/copy-button.d.ts +48 -0
- package/dist/types/components/copy/copy-input.d.ts +91 -0
- package/dist/types/components/data-filter/data-filter.d.ts +250 -0
- package/dist/types/components/data-filter/filter-core.d.ts +52 -0
- package/dist/types/components/date-picker/date-picker.d.ts +137 -0
- package/dist/types/components/date-picker/date-range-picker.d.ts +350 -0
- package/dist/types/components/date-picker/field-adapter.d.ts +6 -0
- package/dist/types/components/date-picker/month-picker.d.ts +75 -0
- package/dist/types/components/date-picker/range-field-adapter.d.ts +7 -0
- package/dist/types/components/date-picker/time-picker.d.ts +127 -0
- package/dist/types/components/datebox/date-range-box.d.ts +218 -0
- package/dist/types/components/datebox/datebox.d.ts +160 -0
- package/dist/types/components/datebox/field-adapter.d.ts +5 -0
- package/dist/types/components/dialog/dialog.d.ts +284 -0
- package/dist/types/components/dropdown/dropdown.d.ts +118 -0
- package/dist/types/components/empty-state/empty-state.d.ts +38 -0
- package/dist/types/components/field/field.d.ts +231 -0
- package/dist/types/components/field-upload/field-adapter.d.ts +5 -0
- package/dist/types/components/field-upload/field-upload.d.ts +213 -0
- package/dist/types/components/fieldset/fieldset.d.ts +125 -0
- package/dist/types/components/finder/finder.d.ts +252 -0
- package/dist/types/components/form/form.d.ts +194 -0
- package/dist/types/components/groupbox/groupbox.d.ts +89 -0
- package/dist/types/components/layout/layout.d.ts +132 -0
- package/dist/types/components/loading/inline-loading.d.ts +86 -0
- package/dist/types/components/loading/progress-bar.d.ts +168 -0
- package/dist/types/components/loading/spinner.d.ts +34 -0
- package/dist/types/components/master-panel/master-panel.d.ts +112 -0
- package/dist/types/components/menu-button/menu-button.d.ts +142 -0
- package/dist/types/components/message/message.d.ts +212 -0
- package/dist/types/components/modal/modal.d.ts +105 -0
- package/dist/types/components/multi-value-editor/field-adapter.d.ts +5 -0
- package/dist/types/components/multi-value-editor/multi-value-editor.d.ts +66 -0
- package/dist/types/components/navigation-bar/navigation-bar.d.ts +229 -0
- package/dist/types/components/number-field/field-adapter.d.ts +5 -0
- package/dist/types/components/number-field/number-field.d.ts +292 -0
- package/dist/types/components/pagination/pagination.d.ts +267 -0
- package/dist/types/components/panel/panel.d.ts +194 -0
- package/dist/types/components/permission/permission.d.ts +93 -0
- package/dist/types/components/rating/field-adapter.d.ts +5 -0
- package/dist/types/components/rating/rating.d.ts +213 -0
- package/dist/types/components/search/search.d.ts +98 -0
- package/dist/types/components/select/field-adapter.d.ts +5 -0
- package/dist/types/components/select/filter.d.ts +11 -0
- package/dist/types/components/select/select.d.ts +235 -0
- package/dist/types/components/skeleton/skeleton.d.ts +97 -0
- package/dist/types/components/slider/field-adapter.d.ts +5 -0
- package/dist/types/components/slider/slider.d.ts +216 -0
- package/dist/types/components/split-view/split-view.d.ts +335 -0
- package/dist/types/components/stepper/stepper.d.ts +314 -0
- package/dist/types/components/stepper/steps.d.ts +131 -0
- package/dist/types/components/tabbox/tabbox.d.ts +230 -0
- package/dist/types/components/table/sort.d.ts +49 -0
- package/dist/types/components/table/table.d.ts +872 -0
- package/dist/types/components/tag-picker/field-adapter.d.ts +5 -0
- package/dist/types/components/tag-picker/tag-picker.d.ts +375 -0
- package/dist/types/components/timebox/field-adapter.d.ts +5 -0
- package/dist/types/components/timebox/timebox.d.ts +121 -0
- package/dist/types/components/toggle/field-adapter.d.ts +5 -0
- package/dist/types/components/toggle/toggle.d.ts +94 -0
- package/dist/types/components/toolbar/toolbar.d.ts +230 -0
- package/dist/types/components/tooltip/tooltip.d.ts +183 -0
- package/dist/types/components/tree/hierarchy.d.ts +113 -0
- package/dist/types/components/tree/tree.d.ts +383 -0
- package/dist/types/components/truncate/truncate.d.ts +61 -0
- package/dist/types/components/value-list/field-adapter.d.ts +5 -0
- package/dist/types/components/value-list/value-list.d.ts +143 -0
- package/dist/types/core/breakpoint.d.ts +68 -0
- package/dist/types/core/component.d.ts +115 -0
- package/dist/types/core/date.d.ts +50 -0
- package/dist/types/core/dom.d.ts +86 -0
- package/dist/types/core/export.d.ts +70 -0
- package/dist/types/core/fontawesome.d.ts +107 -0
- package/dist/types/core/format.d.ts +107 -0
- package/dist/types/core/http.d.ts +122 -0
- package/dist/types/core/i18n.d.ts +35 -0
- package/dist/types/core/icons.d.ts +137 -0
- package/dist/types/core/keyboard.d.ts +72 -0
- package/dist/types/core/position.d.ts +45 -0
- package/dist/types/core/storage.d.ts +46 -0
- package/dist/types/core/util.d.ts +117 -0
- package/dist/types/elements/define.d.ts +73 -0
- package/dist/types/elements/reflect.d.ts +27 -0
- package/dist/types/index.d.ts +79 -0
- package/dist/types/zeyos/connect.d.ts +65 -0
- package/dist/types/zeyos/form.d.ts +140 -0
- package/dist/types/zeyos/icons.d.ts +104 -0
- package/dist/types/zeyos/index.d.ts +12 -0
- package/dist/types/zeyos/modules.d.ts +110 -0
- package/dist/types/zeyos/query.d.ts +157 -0
- package/dist/types/zeyos/schema.d.ts +79 -0
- package/dist/types/zeyos/select.d.ts +167 -0
- package/dist/types/zeyos/table.d.ts +205 -0
- package/dist/zx-compat.esm.js +375 -39
- package/dist/zx-compat.esm.min.js +1 -1
- package/dist/zx-compat.global.js +372 -73
- package/dist/zx-compat.global.min.js +3 -3
- package/dist/zx-zeyos.esm.js +355 -49
- package/dist/zx-zeyos.esm.min.js +1 -1
- package/dist/zx.css +68 -6
- package/dist/zx.esm.js +359 -73
- package/dist/zx.esm.min.js +3 -3
- package/dist/zx.global.js +359 -73
- package/dist/zx.global.min.js +3 -3
- package/dist/zx.min.css +1 -1
- package/docs/api.json +48 -2
- package/docs/llms.md +31 -0
- package/package.json +37 -9
- package/src/compat/base.js +291 -0
- package/src/compat/globals.js +165 -0
- package/src/compat/index.js +84 -0
- package/src/compat/map/basic.js +464 -0
- package/src/compat/map/data.js +232 -0
- package/src/compat/map/date-time.js +177 -0
- package/src/compat/map/factory.js +45 -0
- package/src/compat/map/form.js +330 -0
- package/src/compat/map/helpers.js +46 -0
- package/src/compat/map/http.js +117 -0
- package/src/compat/map/layout.js +256 -0
- package/src/compat/map/options.js +267 -0
- package/src/compat/map/select.js +198 -0
- package/src/compat/map/stubs.js +26 -0
- package/src/compat/map/utilities.js +113 -0
- package/src/compat-entry.js +11 -0
- package/src/components/badge/badge.css +147 -0
- package/src/components/badge/badge.js +92 -0
- package/src/components/breadcrumb/breadcrumb.css +105 -0
- package/src/components/breadcrumb/breadcrumb.js +331 -0
- package/src/components/button/button.css +104 -0
- package/src/components/button/button.js +76 -0
- package/src/components/check-button/check-button.css +66 -0
- package/src/components/check-button/check-button.js +167 -0
- package/src/components/checklist/checklist.css +65 -0
- package/src/components/checklist/checklist.js +282 -0
- package/src/components/checklist/field-adapter.js +46 -0
- package/src/components/context-menu/context-menu.css +54 -0
- package/src/components/context-menu/context-menu.js +334 -0
- package/src/components/copy/copy-button.css +27 -0
- package/src/components/copy/copy-button.js +78 -0
- package/src/components/copy/copy-input.css +59 -0
- package/src/components/copy/copy-input.js +123 -0
- package/src/components/data-filter/data-filter.css +53 -0
- package/src/components/data-filter/data-filter.js +400 -0
- package/src/components/data-filter/filter-core.js +128 -0
- package/src/components/date-picker/date-picker.css +181 -0
- package/src/components/date-picker/date-picker.js +500 -0
- package/src/components/date-picker/date-range-picker.css +264 -0
- package/src/components/date-picker/date-range-picker.js +990 -0
- package/src/components/date-picker/field-adapter.js +36 -0
- package/src/components/date-picker/month-picker.js +223 -0
- package/src/components/date-picker/range-field-adapter.js +31 -0
- package/src/components/date-picker/time-picker.css +191 -0
- package/src/components/date-picker/time-picker.js +406 -0
- package/src/components/datebox/date-range-box.css +128 -0
- package/src/components/datebox/date-range-box.js +492 -0
- package/src/components/datebox/datebox.css +108 -0
- package/src/components/datebox/datebox.js +358 -0
- package/src/components/datebox/field-adapter.js +34 -0
- package/src/components/dialog/dialog.css +74 -0
- package/src/components/dialog/dialog.js +450 -0
- package/src/components/dropdown/dropdown.css +24 -0
- package/src/components/dropdown/dropdown.js +288 -0
- package/src/components/empty-state/empty-state.css +80 -0
- package/src/components/empty-state/empty-state.js +92 -0
- package/src/components/field/field.css +127 -0
- package/src/components/field/field.js +605 -0
- package/src/components/field-upload/field-adapter.js +21 -0
- package/src/components/field-upload/field-upload.css +108 -0
- package/src/components/field-upload/field-upload.js +475 -0
- package/src/components/fieldset/fieldset.css +37 -0
- package/src/components/fieldset/fieldset.js +307 -0
- package/src/components/finder/finder.css +98 -0
- package/src/components/finder/finder.js +509 -0
- package/src/components/form/form.css +32 -0
- package/src/components/form/form.js +302 -0
- package/src/components/groupbox/groupbox.css +51 -0
- package/src/components/groupbox/groupbox.js +199 -0
- package/src/components/layout/layout.css +117 -0
- package/src/components/layout/layout.js +136 -0
- package/src/components/loading/inline-loading.css +34 -0
- package/src/components/loading/inline-loading.js +140 -0
- package/src/components/loading/progress-bar.css +115 -0
- package/src/components/loading/progress-bar.js +259 -0
- package/src/components/loading/spinner.css +58 -0
- package/src/components/loading/spinner.js +57 -0
- package/src/components/master-panel/master-panel.css +51 -0
- package/src/components/master-panel/master-panel.js +203 -0
- package/src/components/menu-button/menu-button.css +49 -0
- package/src/components/menu-button/menu-button.js +294 -0
- package/src/components/message/message.css +122 -0
- package/src/components/message/message.js +499 -0
- package/src/components/modal/modal.css +47 -0
- package/src/components/modal/modal.js +203 -0
- package/src/components/multi-value-editor/field-adapter.js +44 -0
- package/src/components/multi-value-editor/multi-value-editor.css +56 -0
- package/src/components/multi-value-editor/multi-value-editor.js +170 -0
- package/src/components/navigation-bar/navigation-bar.css +130 -0
- package/src/components/navigation-bar/navigation-bar.js +450 -0
- package/src/components/number-field/field-adapter.js +40 -0
- package/src/components/number-field/number-field.css +77 -0
- package/src/components/number-field/number-field.js +545 -0
- package/src/components/pagination/pagination.css +95 -0
- package/src/components/pagination/pagination.js +481 -0
- package/src/components/panel/panel.css +123 -0
- package/src/components/panel/panel.js +336 -0
- package/src/components/permission/permission.css +47 -0
- package/src/components/permission/permission.js +198 -0
- package/src/components/rating/field-adapter.js +34 -0
- package/src/components/rating/rating.css +97 -0
- package/src/components/rating/rating.js +395 -0
- package/src/components/search/search.css +70 -0
- package/src/components/search/search.js +193 -0
- package/src/components/select/field-adapter.js +24 -0
- package/src/components/select/filter.js +39 -0
- package/src/components/select/select.css +180 -0
- package/src/components/select/select.js +663 -0
- package/src/components/skeleton/skeleton.css +76 -0
- package/src/components/skeleton/skeleton.js +139 -0
- package/src/components/slider/field-adapter.js +36 -0
- package/src/components/slider/slider.css +181 -0
- package/src/components/slider/slider.js +399 -0
- package/src/components/split-view/split-view.css +139 -0
- package/src/components/split-view/split-view.js +806 -0
- package/src/components/stepper/stepper.css +234 -0
- package/src/components/stepper/stepper.js +459 -0
- package/src/components/stepper/steps.js +131 -0
- package/src/components/tabbox/tabbox.css +281 -0
- package/src/components/tabbox/tabbox.js +484 -0
- package/src/components/table/sort.js +85 -0
- package/src/components/table/table.css +364 -0
- package/src/components/table/table.js +1711 -0
- package/src/components/tag-picker/field-adapter.js +35 -0
- package/src/components/tag-picker/tag-picker.css +169 -0
- package/src/components/tag-picker/tag-picker.js +837 -0
- package/src/components/timebox/field-adapter.js +24 -0
- package/src/components/timebox/timebox.css +51 -0
- package/src/components/timebox/timebox.js +276 -0
- package/src/components/toggle/field-adapter.js +24 -0
- package/src/components/toggle/toggle.css +66 -0
- package/src/components/toggle/toggle.js +150 -0
- package/src/components/toolbar/toolbar.css +81 -0
- package/src/components/toolbar/toolbar.js +511 -0
- package/src/components/tooltip/tooltip.css +36 -0
- package/src/components/tooltip/tooltip.js +420 -0
- package/src/components/tree/hierarchy.js +151 -0
- package/src/components/tree/tree.css +99 -0
- package/src/components/tree/tree.js +784 -0
- package/src/components/truncate/truncate.css +20 -0
- package/src/components/truncate/truncate.js +92 -0
- package/src/components/value-list/field-adapter.js +24 -0
- package/src/components/value-list/value-list.css +108 -0
- package/src/components/value-list/value-list.js +336 -0
- package/src/core/breakpoint.js +150 -0
- package/src/core/component.js +292 -0
- package/src/core/date.js +216 -0
- package/src/core/dom.js +260 -0
- package/src/core/export.js +204 -0
- package/src/core/fontawesome.js +177 -0
- package/src/core/format.js +283 -0
- package/src/core/http.js +246 -0
- package/src/core/i18n.js +83 -0
- package/src/core/icons.js +283 -0
- package/src/core/keyboard.js +240 -0
- package/src/core/position.js +177 -0
- package/src/core/storage.js +175 -0
- package/src/core/util.js +336 -0
- package/src/elements/define.js +715 -0
- package/src/elements/reflect.js +79 -0
- package/src/index.js +131 -0
- package/src/zeyos/connect.js +142 -0
- package/src/zeyos/form.js +254 -0
- package/src/zeyos/icons.js +92 -0
- package/src/zeyos/index.js +21 -0
- package/src/zeyos/modules.js +269 -0
- package/src/zeyos/query.js +199 -0
- package/src/zeyos/schema.js +474 -0
- package/src/zeyos/select.js +175 -0
- package/src/zeyos/table.js +272 -0
- package/styles/base.css +124 -0
- package/styles/icons.css +34 -0
- package/styles/tokens/dark.css +84 -0
- package/styles/tokens/density.css +9 -0
- package/styles/tokens/global.css +80 -0
- package/styles/tokens/modules.css +109 -0
- package/styles/tokens/semantic.css +49 -0
- package/styles/zx.css +61 -0
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
import { Component } from '../../core/component.js';
|
|
2
|
+
import { h } from '../../core/dom.js';
|
|
3
|
+
import { icon } from '../../core/icons.js';
|
|
4
|
+
|
|
5
|
+
/** @typedef {'info'|'success'|'warning'|'error'} MessageKind */
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {Object} MessageShowOptions
|
|
9
|
+
* @property {MessageKind|'danger'} [kind='info'] Message intent (`danger` aliases `error`).
|
|
10
|
+
* @property {number} [timeout=4000] Auto-dismiss delay in milliseconds; zero persists.
|
|
11
|
+
* @property {boolean} [closable=true] Whether to render a close button.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {Object} MessageOptions
|
|
16
|
+
* @property {MessageKind|'danger'} [kind='info'] Default message intent.
|
|
17
|
+
* @property {number} [timeout=4000] Default auto-dismiss delay.
|
|
18
|
+
* @property {boolean} [closable=true] Default close-button visibility.
|
|
19
|
+
* @property {number} [maxVisible=5] Maximum number of visible messages.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/** @typedef {{close: () => void}} MessageHandle */
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @typedef {Object} ProgressHandle
|
|
26
|
+
* @property {(pct: number, text?: string) => void} update Updates progress and optional text.
|
|
27
|
+
* @property {() => void} done Completes and dismisses the progress message.
|
|
28
|
+
* @property {(text?: string) => void} fail Marks progress as failed and dismisses it later.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Small FIFO admission queue used by message regions.
|
|
33
|
+
* @template T
|
|
34
|
+
*/
|
|
35
|
+
export class MessageQueue {
|
|
36
|
+
#limit;
|
|
37
|
+
#active = [];
|
|
38
|
+
#pending = [];
|
|
39
|
+
#onActivate;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {number} [limit=5] Maximum active item count.
|
|
43
|
+
* @param {(item: T) => void} [onActivate=()=>{}] Called when an item becomes active.
|
|
44
|
+
*/
|
|
45
|
+
constructor(limit = 5, onActivate = () => {}) {
|
|
46
|
+
if (!Number.isInteger(limit) || limit < 1) throw new RangeError('Queue limit must be positive');
|
|
47
|
+
if (typeof onActivate !== 'function') throw new TypeError('Activation callback must be a function');
|
|
48
|
+
this.#limit = limit;
|
|
49
|
+
this.#onActivate = onActivate;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Adds an item, activating it immediately when capacity allows.
|
|
54
|
+
* @param {T} item Item to add.
|
|
55
|
+
* @returns {'active'|'pending'} Initial queue location.
|
|
56
|
+
*/
|
|
57
|
+
enqueue(item) {
|
|
58
|
+
if (this.#active.length < this.#limit) {
|
|
59
|
+
this.#active.push(item);
|
|
60
|
+
this.#onActivate(item);
|
|
61
|
+
return 'active';
|
|
62
|
+
}
|
|
63
|
+
this.#pending.push(item);
|
|
64
|
+
return 'pending';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Removes an item and promotes the oldest pending item when needed.
|
|
69
|
+
* @param {T} item Item to remove.
|
|
70
|
+
* @returns {'active'|'pending'|null} Previous location, or null when absent.
|
|
71
|
+
*/
|
|
72
|
+
remove(item) {
|
|
73
|
+
const pendingIndex = this.#pending.indexOf(item);
|
|
74
|
+
if (pendingIndex !== -1) {
|
|
75
|
+
this.#pending.splice(pendingIndex, 1);
|
|
76
|
+
return 'pending';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const activeIndex = this.#active.indexOf(item);
|
|
80
|
+
if (activeIndex === -1) return null;
|
|
81
|
+
this.#active.splice(activeIndex, 1);
|
|
82
|
+
if (this.#pending.length > 0) {
|
|
83
|
+
const next = /** @type {T} */ (this.#pending.shift());
|
|
84
|
+
this.#active.push(next);
|
|
85
|
+
this.#onActivate(next);
|
|
86
|
+
}
|
|
87
|
+
return 'active';
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Reports whether an item is active.
|
|
92
|
+
* @param {T} item Item to inspect.
|
|
93
|
+
* @returns {boolean}
|
|
94
|
+
*/
|
|
95
|
+
isActive(item) {
|
|
96
|
+
return this.#active.includes(item);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Removes every item without activation callbacks.
|
|
101
|
+
* @returns {{active: T[], pending: T[]}} Removed items.
|
|
102
|
+
*/
|
|
103
|
+
clear() {
|
|
104
|
+
const removed = { active: this.#active.slice(), pending: this.#pending.slice() };
|
|
105
|
+
this.#active.length = 0;
|
|
106
|
+
this.#pending.length = 0;
|
|
107
|
+
return removed;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** @returns {number} */
|
|
111
|
+
get activeCount() {
|
|
112
|
+
return this.#active.length;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** @returns {number} */
|
|
116
|
+
get pendingCount() {
|
|
117
|
+
return this.#pending.length;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Inline message area and static toast service.
|
|
123
|
+
* @extends {Component<MessageOptions>}
|
|
124
|
+
*/
|
|
125
|
+
export class Message extends Component {
|
|
126
|
+
static cssName = 'message';
|
|
127
|
+
|
|
128
|
+
/** @type {Readonly<MessageOptions>} */
|
|
129
|
+
static defaults = {
|
|
130
|
+
kind: 'info',
|
|
131
|
+
timeout: 4000,
|
|
132
|
+
closable: true,
|
|
133
|
+
maxVisible: 5
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/** @type {Message|null} */
|
|
137
|
+
static #floating = null;
|
|
138
|
+
|
|
139
|
+
/** @returns {HTMLElement} */
|
|
140
|
+
render() {
|
|
141
|
+
const created = !this.el;
|
|
142
|
+
const root = /** @type {HTMLElement} */ (this.el ?? h('div'));
|
|
143
|
+
this._createdRoot = created;
|
|
144
|
+
this._original = created ? null : snapshot(root);
|
|
145
|
+
this._entries = new Set();
|
|
146
|
+
this._queue = new MessageQueue(normalizeLimit(this.options.maxVisible), (entry) => {
|
|
147
|
+
this._activate(entry);
|
|
148
|
+
});
|
|
149
|
+
root.replaceChildren();
|
|
150
|
+
root.setAttribute('role', 'status');
|
|
151
|
+
root.setAttribute('aria-live', 'polite');
|
|
152
|
+
return root;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Shows a message in this inline region.
|
|
157
|
+
* @param {string|Node} msg Text or DOM content.
|
|
158
|
+
* @param {MessageShowOptions} [options={}] Display options.
|
|
159
|
+
* @returns {MessageHandle}
|
|
160
|
+
*/
|
|
161
|
+
show(msg, options = {}) {
|
|
162
|
+
const settings = {
|
|
163
|
+
kind: normalizeKind(options.kind ?? this.options.kind),
|
|
164
|
+
timeout: normalizeTimeout(options.timeout ?? this.options.timeout),
|
|
165
|
+
closable: options.closable ?? Boolean(this.options.closable)
|
|
166
|
+
};
|
|
167
|
+
const entry = this._createEntry(msg, settings);
|
|
168
|
+
this._entries.add(entry);
|
|
169
|
+
this._queue.enqueue(entry);
|
|
170
|
+
return { close: () => this._close(entry) };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Shows a floating informational toast.
|
|
175
|
+
* @param {string|Node} msg Text or DOM content.
|
|
176
|
+
* @param {MessageShowOptions} [options={}] Display options.
|
|
177
|
+
* @returns {MessageHandle}
|
|
178
|
+
*/
|
|
179
|
+
static info(msg, options = {}) {
|
|
180
|
+
return this.show(msg, { ...options, kind: 'info' });
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Shows a floating success toast.
|
|
185
|
+
* @param {string|Node} msg Text or DOM content.
|
|
186
|
+
* @param {MessageShowOptions} [options={}] Display options.
|
|
187
|
+
* @returns {MessageHandle}
|
|
188
|
+
*/
|
|
189
|
+
static success(msg, options = {}) {
|
|
190
|
+
return this.show(msg, { ...options, kind: 'success' });
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Shows a floating warning toast.
|
|
195
|
+
* @param {string|Node} msg Text or DOM content.
|
|
196
|
+
* @param {MessageShowOptions} [options={}] Display options.
|
|
197
|
+
* @returns {MessageHandle}
|
|
198
|
+
*/
|
|
199
|
+
static warning(msg, options = {}) {
|
|
200
|
+
return this.show(msg, { ...options, kind: 'warning' });
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Shows a floating error toast.
|
|
205
|
+
* @param {string|Node} msg Text or DOM content.
|
|
206
|
+
* @param {MessageShowOptions} [options={}] Display options.
|
|
207
|
+
* @returns {MessageHandle}
|
|
208
|
+
*/
|
|
209
|
+
static error(msg, options = {}) {
|
|
210
|
+
return this.show(msg, { ...options, kind: 'error' });
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Shows a floating toast.
|
|
215
|
+
* @param {string|Node} msg Text or DOM content.
|
|
216
|
+
* @param {MessageShowOptions} [options={}] Display options.
|
|
217
|
+
* @returns {MessageHandle}
|
|
218
|
+
*/
|
|
219
|
+
static show(msg, options = {}) {
|
|
220
|
+
return this.#floatingRegion().show(msg, options);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Shows a floating progress status.
|
|
225
|
+
* @param {string} text Initial status text.
|
|
226
|
+
* @returns {ProgressHandle}
|
|
227
|
+
*/
|
|
228
|
+
static progress(text) {
|
|
229
|
+
return this.#floatingRegion()._progress(text);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** @returns {void} */
|
|
233
|
+
destroy() {
|
|
234
|
+
if (this._cleaned) return;
|
|
235
|
+
this._cleaned = true;
|
|
236
|
+
for (const entry of this._entries) {
|
|
237
|
+
clearEntryTimers(entry);
|
|
238
|
+
entry.node.remove();
|
|
239
|
+
}
|
|
240
|
+
this._queue.clear();
|
|
241
|
+
this._entries.clear();
|
|
242
|
+
super.destroy();
|
|
243
|
+
if (!this._createdRoot && this._original) restore(this.el, this._original);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** @param {string} text @returns {ProgressHandle} */
|
|
247
|
+
_progress(text) {
|
|
248
|
+
const state = { pct: 0, text: String(text) };
|
|
249
|
+
const entry = this._createEntry(state.text, {
|
|
250
|
+
kind: 'info', timeout: 0, closable: false
|
|
251
|
+
}, state);
|
|
252
|
+
this._entries.add(entry);
|
|
253
|
+
this._queue.enqueue(entry);
|
|
254
|
+
let settled = false;
|
|
255
|
+
|
|
256
|
+
return {
|
|
257
|
+
update: (pct, nextText) => {
|
|
258
|
+
if (settled || entry.closed) return;
|
|
259
|
+
state.pct = clampPercent(pct);
|
|
260
|
+
if (nextText !== undefined) state.text = String(nextText);
|
|
261
|
+
syncProgress(entry, state);
|
|
262
|
+
},
|
|
263
|
+
done: () => {
|
|
264
|
+
if (settled || entry.closed) return;
|
|
265
|
+
settled = true;
|
|
266
|
+
state.pct = 100;
|
|
267
|
+
syncProgress(entry, state);
|
|
268
|
+
entry.remaining = 600;
|
|
269
|
+
if (this._queue.isActive(entry)) this._schedule(entry);
|
|
270
|
+
},
|
|
271
|
+
fail: (nextText) => {
|
|
272
|
+
if (settled || entry.closed) return;
|
|
273
|
+
settled = true;
|
|
274
|
+
if (nextText !== undefined) state.text = String(nextText);
|
|
275
|
+
entry.kind = 'error';
|
|
276
|
+
entry.node.dataset.kind = 'error';
|
|
277
|
+
entry.node.setAttribute('role', 'alert');
|
|
278
|
+
entry.iconHost.replaceChildren(icon('error', { size: 18 }));
|
|
279
|
+
syncProgress(entry, state);
|
|
280
|
+
entry.remaining = 4000;
|
|
281
|
+
if (this._queue.isActive(entry)) this._schedule(entry);
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* @param {string|Node} msg
|
|
288
|
+
* @param {{kind: MessageKind, timeout: number, closable: boolean}} settings
|
|
289
|
+
* @param {{pct: number, text: string}|null} [progress=null]
|
|
290
|
+
* @returns {any}
|
|
291
|
+
*/
|
|
292
|
+
_createEntry(msg, settings, progress = null) {
|
|
293
|
+
const iconHost = h('span', { class: 'zx-message__icon', ariaHidden: 'true' },
|
|
294
|
+
icon(settings.kind, { size: 18 })
|
|
295
|
+
);
|
|
296
|
+
const content = h('div', { class: 'zx-message__content' });
|
|
297
|
+
if (isNode(msg)) content.append(msg);
|
|
298
|
+
else content.append(document.createTextNode(String(msg)));
|
|
299
|
+
const node = h('div', {
|
|
300
|
+
class: 'zx-message__toast',
|
|
301
|
+
role: settings.kind === 'error' ? 'alert' : 'status',
|
|
302
|
+
dataset: { kind: settings.kind, state: 'queued' }
|
|
303
|
+
}, iconHost, content);
|
|
304
|
+
const entry = {
|
|
305
|
+
node,
|
|
306
|
+
content,
|
|
307
|
+
iconHost,
|
|
308
|
+
kind: settings.kind,
|
|
309
|
+
timeout: settings.timeout,
|
|
310
|
+
remaining: settings.timeout,
|
|
311
|
+
startedAt: 0,
|
|
312
|
+
timer: null,
|
|
313
|
+
exitTimer: null,
|
|
314
|
+
closed: false,
|
|
315
|
+
progressBar: null,
|
|
316
|
+
progressFill: null
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
if (progress) {
|
|
320
|
+
node.dataset.progress = '';
|
|
321
|
+
const fill = h('span', { class: 'zx-message__progress-fill' });
|
|
322
|
+
const bar = h('div', {
|
|
323
|
+
class: 'zx-message__progress',
|
|
324
|
+
role: 'progressbar',
|
|
325
|
+
ariaValueMin: '0',
|
|
326
|
+
ariaValueMax: '100',
|
|
327
|
+
ariaValueNow: '0',
|
|
328
|
+
ariaLabel: progress.text
|
|
329
|
+
}, fill);
|
|
330
|
+
content.append(bar);
|
|
331
|
+
entry.progressBar = bar;
|
|
332
|
+
entry.progressFill = fill;
|
|
333
|
+
syncProgress(entry, progress);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (settings.closable) {
|
|
337
|
+
const close = h('button', {
|
|
338
|
+
class: 'zx-icon-btn zx-message__close',
|
|
339
|
+
type: 'button',
|
|
340
|
+
ariaLabel: 'Close message',
|
|
341
|
+
title: 'Close'
|
|
342
|
+
}, icon('x', { size: 14 }));
|
|
343
|
+
node.append(close);
|
|
344
|
+
this.listen(close, 'click', () => this._close(entry));
|
|
345
|
+
}
|
|
346
|
+
this.listen(node, 'mouseenter', () => this._pause(entry));
|
|
347
|
+
this.listen(node, 'mouseleave', () => this._resume(entry));
|
|
348
|
+
return entry;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** @param {any} entry @returns {void} */
|
|
352
|
+
_activate(entry) {
|
|
353
|
+
if (entry.closed) return;
|
|
354
|
+
entry.node.dataset.state = 'open';
|
|
355
|
+
this.el.append(entry.node);
|
|
356
|
+
this._schedule(entry);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/** @param {any} entry @returns {void} */
|
|
360
|
+
_schedule(entry) {
|
|
361
|
+
if (entry.closed || entry.remaining <= 0) return;
|
|
362
|
+
entry.startedAt = Date.now();
|
|
363
|
+
entry.timer = setTimeout(() => this._close(entry), entry.remaining);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/** @param {any} entry @returns {void} */
|
|
367
|
+
_pause(entry) {
|
|
368
|
+
if (entry.closed || entry.timer === null) return;
|
|
369
|
+
clearTimeout(entry.timer);
|
|
370
|
+
entry.timer = null;
|
|
371
|
+
entry.remaining = Math.max(0, entry.remaining - (Date.now() - entry.startedAt));
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/** @param {any} entry @returns {void} */
|
|
375
|
+
_resume(entry) {
|
|
376
|
+
if (entry.closed || entry.timer !== null) return;
|
|
377
|
+
if (entry.remaining <= 0) {
|
|
378
|
+
this._close(entry);
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
this._schedule(entry);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/** @param {any} entry @returns {void} */
|
|
385
|
+
_close(entry) {
|
|
386
|
+
if (entry.closed) return;
|
|
387
|
+
entry.closed = true;
|
|
388
|
+
clearEntryTimers(entry);
|
|
389
|
+
if (!this._queue.isActive(entry)) {
|
|
390
|
+
this._queue.remove(entry);
|
|
391
|
+
entry.node.remove();
|
|
392
|
+
this._entries.delete(entry);
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
entry.node.dataset.state = 'closing';
|
|
397
|
+
if (!shouldAnimate()) {
|
|
398
|
+
this._finish(entry);
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
const finish = (event) => {
|
|
402
|
+
if (event.target === entry.node) this._finish(entry);
|
|
403
|
+
};
|
|
404
|
+
this.listen(entry.node, 'animationend', finish, { once: true });
|
|
405
|
+
entry.exitTimer = setTimeout(() => this._finish(entry), 260);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/** @param {any} entry @returns {void} */
|
|
409
|
+
_finish(entry) {
|
|
410
|
+
if (!this._entries.has(entry)) return;
|
|
411
|
+
clearEntryTimers(entry);
|
|
412
|
+
entry.node.remove();
|
|
413
|
+
this._entries.delete(entry);
|
|
414
|
+
this._queue.remove(entry);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/** @returns {Message} */
|
|
418
|
+
static #floatingRegion() {
|
|
419
|
+
if (this.#floating) return this.#floating;
|
|
420
|
+
const region = h('div', {
|
|
421
|
+
class: 'zx-message-region',
|
|
422
|
+
popover: 'manual',
|
|
423
|
+
role: 'status',
|
|
424
|
+
ariaLive: 'polite'
|
|
425
|
+
});
|
|
426
|
+
document.body.append(region);
|
|
427
|
+
this.#floating = new Message(region);
|
|
428
|
+
if (typeof region.showPopover === 'function') region.showPopover();
|
|
429
|
+
return this.#floating;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/** @param {unknown} value @returns {MessageKind} */
|
|
434
|
+
function normalizeKind(value) {
|
|
435
|
+
if (value === 'danger') return 'error';
|
|
436
|
+
return ['success', 'warning', 'error'].includes(String(value)) ?
|
|
437
|
+
/** @type {MessageKind} */ (value) : 'info';
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/** @param {unknown} value @returns {number} */
|
|
441
|
+
function normalizeTimeout(value) {
|
|
442
|
+
const timeout = Number(value);
|
|
443
|
+
return Number.isFinite(timeout) ? Math.max(0, timeout) : 4000;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/** @param {unknown} value @returns {number} */
|
|
447
|
+
function normalizeLimit(value) {
|
|
448
|
+
const limit = Number(value);
|
|
449
|
+
return Number.isInteger(limit) && limit > 0 ? limit : 5;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/** @param {unknown} value @returns {boolean} */
|
|
453
|
+
function isNode(value) {
|
|
454
|
+
return Boolean(value && typeof value === 'object' && typeof value.nodeType === 'number');
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/** @param {unknown} value @returns {number} */
|
|
458
|
+
function clampPercent(value) {
|
|
459
|
+
const number = Number(value);
|
|
460
|
+
if (!Number.isFinite(number)) return 0;
|
|
461
|
+
return Math.min(100, Math.max(0, number));
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/** @param {any} entry @param {{pct: number, text: string}} state @returns {void} */
|
|
465
|
+
function syncProgress(entry, state) {
|
|
466
|
+
entry.content.firstChild.textContent = state.text;
|
|
467
|
+
entry.progressBar?.setAttribute('aria-valuenow', String(state.pct));
|
|
468
|
+
entry.progressBar?.setAttribute('aria-label', state.text);
|
|
469
|
+
if (entry.progressFill) entry.progressFill.style.inlineSize = `${state.pct}%`;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/** @param {any} entry @returns {void} */
|
|
473
|
+
function clearEntryTimers(entry) {
|
|
474
|
+
if (entry.timer !== null) clearTimeout(entry.timer);
|
|
475
|
+
if (entry.exitTimer !== null) clearTimeout(entry.exitTimer);
|
|
476
|
+
entry.timer = null;
|
|
477
|
+
entry.exitTimer = null;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/** @returns {boolean} */
|
|
481
|
+
function shouldAnimate() {
|
|
482
|
+
return typeof matchMedia !== 'function' ||
|
|
483
|
+
matchMedia('(prefers-reduced-motion: no-preference)').matches;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/** @param {Element} element @returns {{attributes: [string, string][], children: Node[]}} */
|
|
487
|
+
function snapshot(element) {
|
|
488
|
+
return {
|
|
489
|
+
attributes: Array.from(element.attributes, (attribute) => [attribute.name, attribute.value]),
|
|
490
|
+
children: Array.from(element.childNodes)
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/** @param {Element} element @param {{attributes: [string, string][], children: Node[]}} state */
|
|
495
|
+
function restore(element, state) {
|
|
496
|
+
for (const attribute of Array.from(element.attributes)) element.removeAttribute(attribute.name);
|
|
497
|
+
for (const [name, value] of state.attributes) element.setAttribute(name, value);
|
|
498
|
+
element.replaceChildren(...state.children);
|
|
499
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
.zx-modal {
|
|
2
|
+
max-inline-size: calc(100vw - (2 * var(--zx-space-4)));
|
|
3
|
+
max-block-size: calc(100vh - (2 * var(--zx-space-4)));
|
|
4
|
+
overflow: auto;
|
|
5
|
+
border: 1px solid var(--zx-color-border);
|
|
6
|
+
border-radius: var(--zx-radius-lg);
|
|
7
|
+
background: var(--zx-color-bg-raised);
|
|
8
|
+
box-shadow: var(--zx-overlay-shadow);
|
|
9
|
+
color: var(--zx-color-text);
|
|
10
|
+
padding: 0;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.zx-modal::backdrop {
|
|
14
|
+
background: var(--zx-color-bg-backdrop);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.zx-modal__content {
|
|
18
|
+
padding: var(--zx-space-5);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
body:has(> .zx-modal[open]) {
|
|
22
|
+
overflow: hidden;
|
|
23
|
+
overscroll-behavior: none;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
27
|
+
.zx-modal[data-state="open"] {
|
|
28
|
+
animation: zx-modal-enter var(--zx-dur-base) var(--zx-ease);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.zx-modal[data-state="open"]::backdrop {
|
|
32
|
+
animation: zx-modal-backdrop-enter var(--zx-dur-base) var(--zx-ease);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@keyframes zx-modal-enter {
|
|
37
|
+
from {
|
|
38
|
+
opacity: 0;
|
|
39
|
+
transform: translateY(var(--zx-space-2)) scale(.98);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@keyframes zx-modal-backdrop-enter {
|
|
44
|
+
from {
|
|
45
|
+
opacity: 0;
|
|
46
|
+
}
|
|
47
|
+
}
|