@zeyos/zx 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -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 +362 -33
- package/dist/zx-compat.esm.min.js +1 -1
- package/dist/zx-compat.global.js +359 -67
- package/dist/zx-compat.global.min.js +3 -3
- package/dist/zx-zeyos.esm.js +342 -43
- package/dist/zx-zeyos.esm.min.js +1 -1
- package/dist/zx.css +68 -6
- package/dist/zx.esm.js +346 -67
- package/dist/zx.esm.min.js +3 -3
- package/dist/zx.global.js +346 -67
- 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 +28 -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 +1693 -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,288 @@
|
|
|
1
|
+
import { Component } from '../../core/component.js';
|
|
2
|
+
import { h, resolveElement } from '../../core/dom.js';
|
|
3
|
+
import { position } from '../../core/position.js';
|
|
4
|
+
import { uid } from '../../core/util.js';
|
|
5
|
+
|
|
6
|
+
const HANDLE_POINTER_DISMISS = Symbol('zxDropdownPointerDismiss');
|
|
7
|
+
const HANDLE_ESCAPE_DISMISS = Symbol('zxDropdownEscapeDismiss');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {Object} DropdownOptions
|
|
11
|
+
* @property {Node|string|number|{toElement: () => Node|null}|null} [content=null] Panel content.
|
|
12
|
+
* @property {'bottom-start'|'bottom-end'|'top-start'|'top-end'|'bottom'|'top'} [placement='bottom-start'] Panel placement.
|
|
13
|
+
* @property {number} [offset=4] Gap between anchor and panel in pixels.
|
|
14
|
+
* @property {boolean} [matchWidth=false] Whether the panel matches the anchor width.
|
|
15
|
+
* @property {'click'|'manual'} [openOn='click'] Trigger behavior.
|
|
16
|
+
* @property {boolean} [closeOnSelect=false] Whether a click within the panel closes it.
|
|
17
|
+
* @property {(event: CustomEvent<Record<string, never>>) => void} [onopen] Open event listener.
|
|
18
|
+
* @property {(event: CustomEvent<Record<string, never>>) => void} [onclose] Close event listener.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Generic anchored floating panel using the browser popover top layer.
|
|
23
|
+
* @fires Dropdown#open
|
|
24
|
+
* @fires Dropdown#close
|
|
25
|
+
* @extends {Component<DropdownOptions>}
|
|
26
|
+
*/
|
|
27
|
+
export class Dropdown extends Component {
|
|
28
|
+
static cssName = 'dropdown';
|
|
29
|
+
|
|
30
|
+
/** @type {Readonly<DropdownOptions>} */
|
|
31
|
+
static defaults = {
|
|
32
|
+
content: null,
|
|
33
|
+
placement: 'bottom-start',
|
|
34
|
+
offset: 4,
|
|
35
|
+
matchWidth: false,
|
|
36
|
+
openOn: 'click',
|
|
37
|
+
closeOnSelect: false
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/** @type {Element} */
|
|
41
|
+
#anchor;
|
|
42
|
+
/** @type {ReturnType<typeof position>|null} */
|
|
43
|
+
#position = null;
|
|
44
|
+
/** @type {Map<string, string|null>} */
|
|
45
|
+
#anchorAttributes = new Map();
|
|
46
|
+
#destroyed = false;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Creates a floating panel anchored to an existing element.
|
|
50
|
+
* @param {Element|string} anchor Anchor element or selector.
|
|
51
|
+
* @param {DropdownOptions} [options={}] Dropdown options.
|
|
52
|
+
*/
|
|
53
|
+
constructor(anchor, options = {}) {
|
|
54
|
+
const resolved = resolveElement(anchor);
|
|
55
|
+
if (!resolved) throw new TypeError('Dropdown anchor could not be resolved');
|
|
56
|
+
super(null, options);
|
|
57
|
+
this.#anchor = resolved;
|
|
58
|
+
this.#rememberAnchorAttribute('aria-expanded');
|
|
59
|
+
this.#rememberAnchorAttribute('aria-controls');
|
|
60
|
+
this.#anchor.setAttribute('aria-expanded', 'false');
|
|
61
|
+
this.#anchor.setAttribute('aria-controls', this.el.id);
|
|
62
|
+
this.setContent(this.options.content);
|
|
63
|
+
|
|
64
|
+
if (this.options.openOn === 'click') {
|
|
65
|
+
this.listen(this.#anchor, 'click', () => this.toggle());
|
|
66
|
+
}
|
|
67
|
+
this.listen(this.el, 'click', () => {
|
|
68
|
+
if (this.options.closeOnSelect) this.close();
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Creates the owned popover panel.
|
|
74
|
+
* @returns {HTMLElement}
|
|
75
|
+
*/
|
|
76
|
+
render() {
|
|
77
|
+
const panel = h('div', {
|
|
78
|
+
id: uid('zx-dropdown'),
|
|
79
|
+
popover: 'manual'
|
|
80
|
+
});
|
|
81
|
+
panel.dataset.state = 'closed';
|
|
82
|
+
document.body.append(panel);
|
|
83
|
+
return panel;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Opens and positions the panel.
|
|
88
|
+
* @returns {this}
|
|
89
|
+
* @fires Dropdown#open
|
|
90
|
+
*/
|
|
91
|
+
open() {
|
|
92
|
+
if (this.isOpen() || this.#destroyed) return this;
|
|
93
|
+
this.#position = position(this.#anchor, this.el, {
|
|
94
|
+
placement: this.options.placement,
|
|
95
|
+
offset: Number(this.options.offset),
|
|
96
|
+
matchWidth: Boolean(this.options.matchWidth)
|
|
97
|
+
});
|
|
98
|
+
this.el.dataset.state = 'open';
|
|
99
|
+
this.el.dataset.zxOverlayOrder = String(nextOverlayOrder());
|
|
100
|
+
this.#anchor.setAttribute('aria-expanded', 'true');
|
|
101
|
+
ensureDismissManager();
|
|
102
|
+
this.emit('open');
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Closes the panel and releases its positioning resources.
|
|
108
|
+
* @returns {this}
|
|
109
|
+
* @fires Dropdown#close
|
|
110
|
+
*/
|
|
111
|
+
close() {
|
|
112
|
+
if (!this.isOpen()) return this;
|
|
113
|
+
this.#position?.destroy();
|
|
114
|
+
this.#position = null;
|
|
115
|
+
this.el.dataset.state = 'closed';
|
|
116
|
+
delete this.el.dataset.zxOverlayOrder;
|
|
117
|
+
this.#anchor.setAttribute('aria-expanded', 'false');
|
|
118
|
+
this.emit('close');
|
|
119
|
+
destroyUnusedDismissManager();
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Toggles the panel.
|
|
125
|
+
* @returns {this}
|
|
126
|
+
*/
|
|
127
|
+
toggle() {
|
|
128
|
+
return this.isOpen() ? this.close() : this.open();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Reports whether the panel is open.
|
|
133
|
+
* @returns {boolean}
|
|
134
|
+
*/
|
|
135
|
+
isOpen() {
|
|
136
|
+
return this.#position !== null;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Replaces panel content without interpreting strings as HTML.
|
|
141
|
+
* @param {Node|string|number|{toElement: () => Node|null}|null} content Panel content.
|
|
142
|
+
* @returns {this}
|
|
143
|
+
*/
|
|
144
|
+
setContent(content) {
|
|
145
|
+
replaceContent(this.el, content);
|
|
146
|
+
this.#position?.update();
|
|
147
|
+
return this;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Returns the owned popover panel.
|
|
152
|
+
* @returns {HTMLElement}
|
|
153
|
+
*/
|
|
154
|
+
getPanel() {
|
|
155
|
+
return this.el;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Closes and removes the panel, restoring anchor ARIA attributes.
|
|
160
|
+
* @returns {void}
|
|
161
|
+
*/
|
|
162
|
+
destroy() {
|
|
163
|
+
if (this.#destroyed) return;
|
|
164
|
+
this.#destroyed = true;
|
|
165
|
+
this.close();
|
|
166
|
+
for (const [name, value] of this.#anchorAttributes) restoreAttribute(this.#anchor, name, value);
|
|
167
|
+
super.destroy();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** @param {PointerEvent} event @returns {void} */
|
|
171
|
+
[HANDLE_POINTER_DISMISS](event) {
|
|
172
|
+
if (!this.isOpen()) return;
|
|
173
|
+
const path = event.composedPath();
|
|
174
|
+
if (path.includes(this.el) || path.includes(this.#anchor)) return;
|
|
175
|
+
this.close();
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** @param {KeyboardEvent} event @returns {void} */
|
|
179
|
+
[HANDLE_ESCAPE_DISMISS](event) {
|
|
180
|
+
if (event.key !== 'Escape' || !this.isOpen()) return;
|
|
181
|
+
event.preventDefault();
|
|
182
|
+
const restoreFocus = this.el.contains(document.activeElement);
|
|
183
|
+
this.close();
|
|
184
|
+
if (restoreFocus && this.#anchor instanceof HTMLElement) this.#anchor.focus();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** @param {string} name @returns {void} */
|
|
188
|
+
#rememberAnchorAttribute(name) {
|
|
189
|
+
this.#anchorAttributes.set(name, this.#anchor.getAttribute(name));
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** Shared document-level light-dismiss listener owned only while a dropdown is open. */
|
|
194
|
+
class DropdownDismissManager extends Component {
|
|
195
|
+
/** Creates the transient listener owner. */
|
|
196
|
+
constructor() {
|
|
197
|
+
super(null);
|
|
198
|
+
this.listen(document, 'pointerdown', (event) => {
|
|
199
|
+
const component = topmostOverlayComponent();
|
|
200
|
+
if (component instanceof Dropdown) component[HANDLE_POINTER_DISMISS](event);
|
|
201
|
+
});
|
|
202
|
+
this.listen(document, 'keydown', (event) => {
|
|
203
|
+
if (event.key !== 'Escape') return;
|
|
204
|
+
const component = topmostOverlayComponent();
|
|
205
|
+
if (component instanceof Dropdown) component[HANDLE_ESCAPE_DISMISS](event);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** @returns {HTMLElement} */
|
|
210
|
+
render() {
|
|
211
|
+
const marker = h('span', { hidden: true, 'data-zx-dropdown-dismiss-manager': '' });
|
|
212
|
+
document.body.append(marker);
|
|
213
|
+
return marker;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Fired when the dropdown panel opens.
|
|
219
|
+
* @event Dropdown#open
|
|
220
|
+
* @type {CustomEvent<Record<string, never>>}
|
|
221
|
+
*/
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Fired when the dropdown panel closes.
|
|
225
|
+
* @event Dropdown#close
|
|
226
|
+
* @type {CustomEvent<Record<string, never>>}
|
|
227
|
+
*/
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* @param {Element} target
|
|
231
|
+
* @param {Node|string|number|{toElement: () => Node|null}|null|undefined} content
|
|
232
|
+
* @returns {void}
|
|
233
|
+
*/
|
|
234
|
+
function replaceContent(target, content) {
|
|
235
|
+
target.replaceChildren();
|
|
236
|
+
if (content == null) return;
|
|
237
|
+
if (typeof content === 'string' || typeof content === 'number') {
|
|
238
|
+
target.append(document.createTextNode(String(content)));
|
|
239
|
+
} else if (typeof content.toElement === 'function') {
|
|
240
|
+
const element = content.toElement();
|
|
241
|
+
if (element) target.append(element);
|
|
242
|
+
} else if (typeof content.nodeType === 'number') {
|
|
243
|
+
target.append(content);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** @returns {Component|null} */
|
|
248
|
+
function topmostOverlayComponent() {
|
|
249
|
+
let topmost = null;
|
|
250
|
+
let highest = -1;
|
|
251
|
+
for (const candidate of document.querySelectorAll('[data-zx-overlay-order]')) {
|
|
252
|
+
const order = Number(candidate.getAttribute('data-zx-overlay-order')) || 0;
|
|
253
|
+
if (order > highest) {
|
|
254
|
+
highest = order;
|
|
255
|
+
topmost = candidate;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return topmost ? Component.from(topmost) : null;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** @returns {number} */
|
|
262
|
+
function nextOverlayOrder() {
|
|
263
|
+
const orders = Array.from(document.querySelectorAll('[data-zx-overlay-order]'), (element) =>
|
|
264
|
+
Number(element.getAttribute('data-zx-overlay-order')) || 0
|
|
265
|
+
);
|
|
266
|
+
return Math.max(0, ...orders) + 1;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** @returns {DropdownDismissManager} */
|
|
270
|
+
function ensureDismissManager() {
|
|
271
|
+
const marker = document.querySelector('[data-zx-dropdown-dismiss-manager]');
|
|
272
|
+
const existing = marker ? Component.from(marker) : null;
|
|
273
|
+
return existing instanceof DropdownDismissManager ? existing : new DropdownDismissManager();
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** @returns {void} */
|
|
277
|
+
function destroyUnusedDismissManager() {
|
|
278
|
+
if (document.querySelector('.zx-dropdown[data-state="open"]')) return;
|
|
279
|
+
const marker = document.querySelector('[data-zx-dropdown-dismiss-manager]');
|
|
280
|
+
const manager = marker ? Component.from(marker) : null;
|
|
281
|
+
if (manager instanceof DropdownDismissManager) manager.destroy();
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** @param {Element} element @param {string} name @param {string|null} value @returns {void} */
|
|
285
|
+
function restoreAttribute(element, name, value) {
|
|
286
|
+
if (value === null) element.removeAttribute(name);
|
|
287
|
+
else element.setAttribute(name, value);
|
|
288
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
.zx-empty-state {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
align-items: center;
|
|
5
|
+
gap: var(--zx-space-2);
|
|
6
|
+
padding-block: var(--zx-space-7);
|
|
7
|
+
padding-inline: var(--zx-space-5);
|
|
8
|
+
color: var(--zx-color-text-muted);
|
|
9
|
+
text-align: center;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.zx-empty-state__icon {
|
|
13
|
+
display: flex;
|
|
14
|
+
color: var(--zx-color-text-placeholder);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.zx-empty-state__title {
|
|
18
|
+
margin: 0;
|
|
19
|
+
color: var(--zx-color-text);
|
|
20
|
+
font-size: var(--zx-text-lg);
|
|
21
|
+
font-weight: 600;
|
|
22
|
+
line-height: 1.4;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.zx-empty-state__description {
|
|
26
|
+
margin: 0;
|
|
27
|
+
max-inline-size: 52ch;
|
|
28
|
+
font-size: var(--zx-control-font-size);
|
|
29
|
+
line-height: 1.6;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.zx-empty-state__actions {
|
|
33
|
+
display: flex;
|
|
34
|
+
flex-wrap: wrap;
|
|
35
|
+
align-items: center;
|
|
36
|
+
justify-content: center;
|
|
37
|
+
gap: var(--zx-space-2);
|
|
38
|
+
margin-block-start: var(--zx-space-2);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.zx-empty-state[data-align="start"] {
|
|
42
|
+
align-items: flex-start;
|
|
43
|
+
text-align: start;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.zx-empty-state[data-align="start"] .zx-empty-state__actions {
|
|
47
|
+
justify-content: flex-start;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.zx-empty-state[data-size="sm"] {
|
|
51
|
+
gap: var(--zx-space-1);
|
|
52
|
+
padding-block: var(--zx-space-5);
|
|
53
|
+
padding-inline: var(--zx-space-4);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.zx-empty-state[data-size="sm"] .zx-empty-state__title {
|
|
57
|
+
font-size: var(--zx-control-font-size);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.zx-empty-state[data-size="sm"] .zx-empty-state__description {
|
|
61
|
+
font-size: var(--zx-text-sm);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
65
|
+
.zx-empty-state {
|
|
66
|
+
animation: zx-empty-state-in var(--zx-dur-base) var(--zx-ease) both;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@keyframes zx-empty-state-in {
|
|
71
|
+
from {
|
|
72
|
+
opacity: 0;
|
|
73
|
+
transform: translateY(4px);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
to {
|
|
77
|
+
opacity: 1;
|
|
78
|
+
transform: none;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { h } from '../../core/dom.js';
|
|
2
|
+
import { icon as createIcon } from '../../core/icons.js';
|
|
3
|
+
import { isElement } from '../../core/util.js';
|
|
4
|
+
import { button } from '../button/button.js';
|
|
5
|
+
|
|
6
|
+
/** @typedef {import('../button/button.js').ButtonOptions} ButtonOptions */
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {Object} EmptyStateOptions
|
|
10
|
+
* @property {string|null} [icon='folder-open'] Decorative icon name; null renders no icon.
|
|
11
|
+
* @property {string} [title=''] Headline text, rendered as a paragraph so page outlines stay intact.
|
|
12
|
+
* @property {string} [description=''] Supporting sentence below the headline.
|
|
13
|
+
* @property {Array<Element|ButtonOptions>} [actions=[]] Buttons or button descriptors below the text.
|
|
14
|
+
* @property {'md'|'sm'} [size='md'] Overall scale.
|
|
15
|
+
* @property {'center'|'start'} [align='center'] Content alignment.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** Icon sizes per `size` option. */
|
|
19
|
+
const ICON_SIZE = Object.freeze({ md: 40, sm: 28 });
|
|
20
|
+
|
|
21
|
+
/** @type {Readonly<EmptyStateOptions>} */
|
|
22
|
+
const defaults = Object.freeze({
|
|
23
|
+
icon: 'folder-open',
|
|
24
|
+
title: '',
|
|
25
|
+
description: '',
|
|
26
|
+
actions: [],
|
|
27
|
+
size: 'md',
|
|
28
|
+
align: 'center'
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Creates the placeholder shown where a list, table, or panel has no content yet.
|
|
33
|
+
*
|
|
34
|
+
* Purely presentational: the icon is decorative, the headline is a paragraph rather than a heading
|
|
35
|
+
* so dropping the element into a Table's empty slot or a Panel body never disturbs the page's
|
|
36
|
+
* heading outline.
|
|
37
|
+
*
|
|
38
|
+
* @param {EmptyStateOptions} [opts={}] Empty-state options.
|
|
39
|
+
* @returns {HTMLDivElement}
|
|
40
|
+
*/
|
|
41
|
+
export function emptyState(opts = {}) {
|
|
42
|
+
const options = { ...defaults, ...opts };
|
|
43
|
+
const size = normalizeSize(options.size);
|
|
44
|
+
const element = /** @type {HTMLDivElement} */ (h('div', {
|
|
45
|
+
class: 'zx-empty-state',
|
|
46
|
+
dataset: { size, align: normalizeAlign(options.align) }
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
if (options.icon) {
|
|
50
|
+
element.append(h('div', { class: 'zx-empty-state__icon', ariaHidden: 'true' },
|
|
51
|
+
createIcon(options.icon, { size: ICON_SIZE[size] })
|
|
52
|
+
));
|
|
53
|
+
}
|
|
54
|
+
if (options.title) {
|
|
55
|
+
element.append(h('p', { class: 'zx-empty-state__title' }, String(options.title)));
|
|
56
|
+
}
|
|
57
|
+
if (options.description) {
|
|
58
|
+
element.append(h('p', { class: 'zx-empty-state__description' }, String(options.description)));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const actions = buildActions(options.actions);
|
|
62
|
+
if (actions.length > 0) {
|
|
63
|
+
element.append(h('div', { class: 'zx-empty-state__actions' }, actions));
|
|
64
|
+
}
|
|
65
|
+
return element;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Turns action descriptors into buttons, passing through any Element unchanged.
|
|
70
|
+
* @param {Array<Element|ButtonOptions>} list Buttons or button descriptors.
|
|
71
|
+
* @returns {Element[]}
|
|
72
|
+
*/
|
|
73
|
+
function buildActions(list) {
|
|
74
|
+
if (!Array.isArray(list)) throw new TypeError('emptyState actions must be an array');
|
|
75
|
+
return list.map((item) => {
|
|
76
|
+
if (isElement(item)) return item;
|
|
77
|
+
if (!item || typeof item !== 'object' || Array.isArray(item)) {
|
|
78
|
+
throw new TypeError('emptyState actions must be Elements or button descriptors');
|
|
79
|
+
}
|
|
80
|
+
return button(item);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** @param {unknown} value @returns {'md'|'sm'} */
|
|
85
|
+
function normalizeSize(value) {
|
|
86
|
+
return value === 'sm' ? 'sm' : 'md';
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** @param {unknown} value @returns {'center'|'start'} */
|
|
90
|
+
function normalizeAlign(value) {
|
|
91
|
+
return value === 'start' ? 'start' : 'center';
|
|
92
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
.zx-field {
|
|
2
|
+
display: grid;
|
|
3
|
+
gap: var(--zx-space-1);
|
|
4
|
+
min-inline-size: 0;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.zx-field[data-layout="inline"] {
|
|
8
|
+
grid-template-columns: minmax(8rem, 1fr) minmax(0, 2fr);
|
|
9
|
+
column-gap: var(--zx-space-4);
|
|
10
|
+
align-items: start;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.zx-field[data-field-type="hidden"] {
|
|
14
|
+
display: none;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.zx-field__label {
|
|
18
|
+
min-inline-size: 0;
|
|
19
|
+
color: var(--zx-color-text);
|
|
20
|
+
font-size: var(--zx-text-sm);
|
|
21
|
+
font-weight: 600;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.zx-field__required,
|
|
25
|
+
.zx-field[data-state="danger"] .zx-field__label {
|
|
26
|
+
color: var(--zx-color-danger);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.zx-field[data-state="warning"] .zx-field__label {
|
|
30
|
+
color: var(--zx-color-warning);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.zx-field[data-state="success"] .zx-field__label {
|
|
34
|
+
color: var(--zx-color-success);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.zx-field__body,
|
|
38
|
+
.zx-field__control {
|
|
39
|
+
min-inline-size: 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.zx-field__control > input:not([type="checkbox"]):not([type="radio"]),
|
|
43
|
+
.zx-field__control > select,
|
|
44
|
+
.zx-field__control > textarea {
|
|
45
|
+
inline-size: 100%;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.zx-field__control > textarea {
|
|
49
|
+
min-block-size: calc(var(--zx-control-height) * 2.5);
|
|
50
|
+
padding-block: var(--zx-space-2);
|
|
51
|
+
resize: vertical;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.zx-field__option-list {
|
|
55
|
+
display: flex;
|
|
56
|
+
flex-wrap: wrap;
|
|
57
|
+
gap: var(--zx-space-2) var(--zx-space-4);
|
|
58
|
+
min-block-size: var(--zx-control-height);
|
|
59
|
+
align-items: center;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.zx-field__option {
|
|
63
|
+
display: inline-flex;
|
|
64
|
+
gap: var(--zx-space-2);
|
|
65
|
+
align-items: center;
|
|
66
|
+
cursor: pointer;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.zx-field__option input {
|
|
70
|
+
margin: 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.zx-field__description,
|
|
74
|
+
.zx-field__highlight {
|
|
75
|
+
margin-block-start: var(--zx-space-1);
|
|
76
|
+
color: var(--zx-color-text-muted);
|
|
77
|
+
font-size: var(--zx-text-sm);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.zx-field__highlight[hidden],
|
|
81
|
+
.zx-field__description:empty {
|
|
82
|
+
display: none;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.zx-field[data-state="danger"] .zx-field__highlight {
|
|
86
|
+
color: var(--zx-color-danger);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.zx-field[data-state="warning"] .zx-field__highlight {
|
|
90
|
+
color: var(--zx-color-warning);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.zx-field[data-state="success"] .zx-field__highlight {
|
|
94
|
+
color: var(--zx-color-success);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.zx-field[data-state="danger"] .zx-field__control > input,
|
|
98
|
+
.zx-field[data-state="danger"] .zx-field__control > select,
|
|
99
|
+
.zx-field[data-state="danger"] .zx-field__control > textarea,
|
|
100
|
+
.zx-field[data-state="danger"] .zx-field__option-list {
|
|
101
|
+
border-color: var(--zx-color-danger);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.zx-field__static,
|
|
105
|
+
.zx-field__error-control {
|
|
106
|
+
min-block-size: var(--zx-control-height);
|
|
107
|
+
padding: var(--zx-space-2) var(--zx-control-pad-x);
|
|
108
|
+
border: 1px solid var(--zx-color-border);
|
|
109
|
+
border-radius: var(--zx-control-radius);
|
|
110
|
+
background: var(--zx-color-bg-surface);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.zx-field__error-control {
|
|
114
|
+
border-color: var(--zx-color-danger);
|
|
115
|
+
background: var(--zx-color-danger-bg);
|
|
116
|
+
color: var(--zx-color-danger);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.zx-field[data-disabled="true"] {
|
|
120
|
+
opacity: 0.65;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
@container (max-width: 30rem) {
|
|
124
|
+
.zx-field[data-layout="inline"] {
|
|
125
|
+
grid-template-columns: 1fr;
|
|
126
|
+
}
|
|
127
|
+
}
|