@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,36 @@
|
|
|
1
|
+
import { Field } from '../field/field.js';
|
|
2
|
+
import { MonthPicker } from './month-picker.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Registers the MonthPicker-backed `month` field type. Date and datetime fields are registered
|
|
6
|
+
* by the Datebox adapter so those types retain formatted text-input behavior.
|
|
7
|
+
* @returns {void}
|
|
8
|
+
*/
|
|
9
|
+
export function registerDatePickerFieldAdapters() {
|
|
10
|
+
Field.register('month', (field, options) => {
|
|
11
|
+
const picker = field.own(new MonthPicker(null, {
|
|
12
|
+
...(options.props ?? {}),
|
|
13
|
+
value: options.value
|
|
14
|
+
}));
|
|
15
|
+
let disabled = false;
|
|
16
|
+
const syncDisabled = () => {
|
|
17
|
+
picker.el.setAttribute('aria-disabled', String(disabled));
|
|
18
|
+
for (const button of picker.el.querySelectorAll('button')) button.disabled = disabled;
|
|
19
|
+
};
|
|
20
|
+
field.listen(picker.el, 'change', (event) => event.stopImmediatePropagation());
|
|
21
|
+
picker.on('change', (event) => field.emit('change', { value: event.detail.date }));
|
|
22
|
+
return {
|
|
23
|
+
el: picker.el,
|
|
24
|
+
get: () => picker.get(),
|
|
25
|
+
set: (value) => {
|
|
26
|
+
picker.set(value instanceof Date ? value : null, { silent: true });
|
|
27
|
+
syncDisabled();
|
|
28
|
+
},
|
|
29
|
+
focus: () => picker.focus(),
|
|
30
|
+
setDisabled: (value) => {
|
|
31
|
+
disabled = Boolean(value);
|
|
32
|
+
syncDisabled();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { formatDate } from '../../core/date.js';
|
|
2
|
+
import { h } from '../../core/dom.js';
|
|
3
|
+
import { icon } from '../../core/icons.js';
|
|
4
|
+
import { DatePicker } from './date-picker.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {Object} MonthPickerOptions
|
|
8
|
+
* @property {Date|null} [value=null] Initially selected month.
|
|
9
|
+
* @property {Date|null} [min=null] Earliest selectable month.
|
|
10
|
+
* @property {Date|null} [max=null] Latest selectable month.
|
|
11
|
+
* @property {(event: CustomEvent<{date: Date|null}>) => void} [onchange] Change listener.
|
|
12
|
+
*/
|
|
13
|
+
/** @typedef {{silent?: boolean}} MonthPickerSetOptions */
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Twelve-month grid with a year stepper.
|
|
17
|
+
* @fires MonthPicker#change
|
|
18
|
+
*/
|
|
19
|
+
export class MonthPicker extends DatePicker {
|
|
20
|
+
static cssName = 'month-picker';
|
|
21
|
+
|
|
22
|
+
/** @type {MonthPickerOptions} */
|
|
23
|
+
static defaults = { value: null, min: null, max: null };
|
|
24
|
+
|
|
25
|
+
/** @returns {HTMLElement} */
|
|
26
|
+
render() {
|
|
27
|
+
const root = /** @type {HTMLElement} */ (this.el ?? h('div'));
|
|
28
|
+
this._min = firstOfMonth(validDate(this.options.min));
|
|
29
|
+
this._max = firstOfMonth(validDate(this.options.max));
|
|
30
|
+
this._value = this._normalizeMonth(validDate(this.options.value));
|
|
31
|
+
const initial = this._value ?? firstOfMonth(new Date());
|
|
32
|
+
this._year = initial.getFullYear();
|
|
33
|
+
this._focusedMonth = initial.getMonth();
|
|
34
|
+
|
|
35
|
+
const content = h('div', { class: 'zx-month-picker__surface' },
|
|
36
|
+
h('div', { class: 'zx-month-picker__header' },
|
|
37
|
+
h('button', {
|
|
38
|
+
ref: 'previousYear',
|
|
39
|
+
class: 'zx-month-picker__nav',
|
|
40
|
+
type: 'button',
|
|
41
|
+
ariaLabel: 'Previous year'
|
|
42
|
+
}, icon('chevron-left')),
|
|
43
|
+
h('span', { ref: 'year', class: 'zx-month-picker__year', ariaLive: 'polite' }),
|
|
44
|
+
h('button', {
|
|
45
|
+
ref: 'nextYear',
|
|
46
|
+
class: 'zx-month-picker__nav',
|
|
47
|
+
type: 'button',
|
|
48
|
+
ariaLabel: 'Next year'
|
|
49
|
+
}, icon('chevron-right'))
|
|
50
|
+
),
|
|
51
|
+
h('div', {
|
|
52
|
+
ref: 'grid',
|
|
53
|
+
class: 'zx-month-picker__grid',
|
|
54
|
+
role: 'grid',
|
|
55
|
+
ariaLabel: 'Choose month'
|
|
56
|
+
})
|
|
57
|
+
);
|
|
58
|
+
this._content = content;
|
|
59
|
+
root.append(content);
|
|
60
|
+
this.listen(this.refs.previousYear, 'click', () => this._stepYear(-1));
|
|
61
|
+
this.listen(this.refs.nextYear, 'click', () => this._stepYear(1));
|
|
62
|
+
this.listen(this.refs.grid, 'click', (event) => this._onMonthClick(event));
|
|
63
|
+
this.listen(this.refs.grid, 'keydown', (event) => this._onMonthKeydown(event));
|
|
64
|
+
this._renderMonths();
|
|
65
|
+
return root;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** @returns {Date|null} */
|
|
69
|
+
get() {
|
|
70
|
+
return this._value ? new Date(this._value.getTime()) : null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Selects the first day of a month.
|
|
75
|
+
* @param {Date|null} date Month to select, or null to clear.
|
|
76
|
+
* @param {MonthPickerSetOptions} [options={}] Update behavior.
|
|
77
|
+
* @returns {this}
|
|
78
|
+
* @fires MonthPicker#change
|
|
79
|
+
*/
|
|
80
|
+
set(date, { silent = false } = {}) {
|
|
81
|
+
this._value = this._normalizeMonth(validDate(date));
|
|
82
|
+
if (this._value) {
|
|
83
|
+
this._year = this._value.getFullYear();
|
|
84
|
+
this._focusedMonth = this._value.getMonth();
|
|
85
|
+
}
|
|
86
|
+
this._renderMonths();
|
|
87
|
+
if (!silent) this.emit('change', { date: this.get() });
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** @returns {this} */
|
|
92
|
+
focus() {
|
|
93
|
+
this._button(this._focusedMonth)?.focus();
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Removes generated content from an enhanced target. @returns {void} */
|
|
98
|
+
destroy() {
|
|
99
|
+
this._content?.remove();
|
|
100
|
+
super.destroy();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** @param {Date|null} date @returns {Date|null} */
|
|
104
|
+
_normalizeMonth(date) {
|
|
105
|
+
if (!date) return null;
|
|
106
|
+
let result = firstOfMonth(date);
|
|
107
|
+
if (this._min && result < this._min) result = new Date(this._min.getTime());
|
|
108
|
+
if (this._max && result > this._max) result = new Date(this._max.getTime());
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** @returns {void} */
|
|
113
|
+
_renderMonths() {
|
|
114
|
+
if (!this.refs?.grid) return;
|
|
115
|
+
this.refs.year.textContent = String(this._year);
|
|
116
|
+
const months = [];
|
|
117
|
+
for (let month = 0; month < 12; month += 1) {
|
|
118
|
+
const date = new Date(this._year, month, 1);
|
|
119
|
+
const selected = Boolean(this._value && sameMonth(date, this._value));
|
|
120
|
+
months.push(h('button', {
|
|
121
|
+
class: 'zx-month-picker__month',
|
|
122
|
+
type: 'button',
|
|
123
|
+
role: 'gridcell',
|
|
124
|
+
tabindex: month === this._focusedMonth ? 0 : -1,
|
|
125
|
+
ariaSelected: String(selected),
|
|
126
|
+
ariaDisabled: String(!this._inRange(date)),
|
|
127
|
+
ariaLabel: formatDate(date, '%B %Y'),
|
|
128
|
+
dataset: { month }
|
|
129
|
+
}, formatDate(date, '%b')));
|
|
130
|
+
}
|
|
131
|
+
this.refs.grid.replaceChildren(...months);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** @param {number} amount @returns {void} */
|
|
135
|
+
_stepYear(amount) {
|
|
136
|
+
this._year += amount;
|
|
137
|
+
this._renderMonths();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** @param {Event} event @returns {void} */
|
|
141
|
+
_onMonthClick(event) {
|
|
142
|
+
const button = event.target?.closest?.('[data-month]');
|
|
143
|
+
if (!button || !this.refs.grid.contains(button)) return;
|
|
144
|
+
this._selectMonth(Number(button.dataset.month));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** @param {KeyboardEvent} event @returns {void} */
|
|
148
|
+
_onMonthKeydown(event) {
|
|
149
|
+
const button = event.target?.closest?.('[data-month]');
|
|
150
|
+
if (!button || !this.refs.grid.contains(button)) return;
|
|
151
|
+
const current = Number(button.dataset.month);
|
|
152
|
+
let delta = null;
|
|
153
|
+
if (event.key === 'ArrowLeft') delta = -1;
|
|
154
|
+
else if (event.key === 'ArrowRight') delta = 1;
|
|
155
|
+
else if (event.key === 'ArrowUp') delta = -3;
|
|
156
|
+
else if (event.key === 'ArrowDown') delta = 3;
|
|
157
|
+
else if (event.key === 'Home') delta = -(current % 3);
|
|
158
|
+
else if (event.key === 'End') delta = 2 - (current % 3);
|
|
159
|
+
else if (event.key === 'PageUp') {
|
|
160
|
+
event.preventDefault();
|
|
161
|
+
this._stepYear(-1);
|
|
162
|
+
this.focus();
|
|
163
|
+
return;
|
|
164
|
+
} else if (event.key === 'PageDown') {
|
|
165
|
+
event.preventDefault();
|
|
166
|
+
this._stepYear(1);
|
|
167
|
+
this.focus();
|
|
168
|
+
return;
|
|
169
|
+
} else if (event.key === 'Enter' || event.key === ' ') {
|
|
170
|
+
event.preventDefault();
|
|
171
|
+
this._selectMonth(current);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (delta === null) return;
|
|
175
|
+
event.preventDefault();
|
|
176
|
+
const absolute = this._year * 12 + current + delta;
|
|
177
|
+
this._year = Math.floor(absolute / 12);
|
|
178
|
+
this._focusedMonth = ((absolute % 12) + 12) % 12;
|
|
179
|
+
this._renderMonths();
|
|
180
|
+
this.focus();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** @param {number} month @returns {void} */
|
|
184
|
+
_selectMonth(month) {
|
|
185
|
+
const date = new Date(this._year, month, 1);
|
|
186
|
+
if (!this._inRange(date)) return;
|
|
187
|
+
this._focusedMonth = month;
|
|
188
|
+
this._value = date;
|
|
189
|
+
this._renderMonths();
|
|
190
|
+
this.emit('change', { date: this.get() });
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** @param {Date} date @returns {boolean} */
|
|
194
|
+
_inRange(date) {
|
|
195
|
+
return !(this._min && date < this._min) && !(this._max && date > this._max);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** @param {number} month @returns {HTMLButtonElement|null} */
|
|
199
|
+
_button(month) {
|
|
200
|
+
return this.refs.grid.querySelector(`[data-month="${month}"]`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Fired when the selected month changes.
|
|
206
|
+
* @event MonthPicker#change
|
|
207
|
+
* @type {CustomEvent<{date: Date|null}>}
|
|
208
|
+
*/
|
|
209
|
+
|
|
210
|
+
/** @param {unknown} value @returns {Date|null} */
|
|
211
|
+
function validDate(value) {
|
|
212
|
+
return value instanceof Date && !Number.isNaN(value.getTime()) ? new Date(value.getTime()) : null;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** @param {Date|null} date @returns {Date|null} */
|
|
216
|
+
function firstOfMonth(date) {
|
|
217
|
+
return date ? new Date(date.getFullYear(), date.getMonth(), 1) : null;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** @param {Date} a @param {Date} b @returns {boolean} */
|
|
221
|
+
function sameMonth(a, b) {
|
|
222
|
+
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth();
|
|
223
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { DateRangeBox } from '../datebox/date-range-box.js';
|
|
2
|
+
import { Field } from '../field/field.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Registers the DateRangeBox-backed `daterange` field type, so a Form field declared as
|
|
6
|
+
* `{ type: 'daterange', label, props: {…} }` renders a formatted range input with an anchored
|
|
7
|
+
* two-month calendar. Field values are `{start, end}` objects of `Date|null`.
|
|
8
|
+
* @returns {void}
|
|
9
|
+
*/
|
|
10
|
+
export function registerDateRangeFieldAdapter() {
|
|
11
|
+
Field.register('daterange', (field, options) => {
|
|
12
|
+
const box = field.own(new DateRangeBox(null, {
|
|
13
|
+
...(options.props ?? {}),
|
|
14
|
+
disabled: Boolean(options.disabled),
|
|
15
|
+
start: options.value?.start ?? null,
|
|
16
|
+
end: options.value?.end ?? null
|
|
17
|
+
}));
|
|
18
|
+
// The box already emits its own `change`; stop the DOM copy so Field does not report twice.
|
|
19
|
+
field.listen(box.el, 'change', (event) => event.stopImmediatePropagation());
|
|
20
|
+
box.on('change', (event) => field.emit('change', {
|
|
21
|
+
value: { start: event.detail.start, end: event.detail.end }
|
|
22
|
+
}));
|
|
23
|
+
return {
|
|
24
|
+
el: box.el,
|
|
25
|
+
get: () => box.get(),
|
|
26
|
+
set: (value) => box.set(value, { silent: true }),
|
|
27
|
+
focus: () => box.focus(),
|
|
28
|
+
setDisabled: (disabled) => disabled ? box.disable() : box.enable()
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
.zx-time-picker {
|
|
2
|
+
display: inline-block;
|
|
3
|
+
color: var(--zx-color-text);
|
|
4
|
+
font-size: var(--zx-control-font-size);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.zx-time-picker__segments {
|
|
8
|
+
display: inline-flex;
|
|
9
|
+
align-items: center;
|
|
10
|
+
gap: var(--zx-space-1);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.zx-time-picker__spin {
|
|
14
|
+
inline-size: calc(var(--zx-control-height) + var(--zx-space-2));
|
|
15
|
+
padding-inline: var(--zx-space-1);
|
|
16
|
+
text-align: center;
|
|
17
|
+
font-variant-numeric: tabular-nums;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.zx-time-picker__spin:focus-visible {
|
|
21
|
+
box-shadow: var(--zx-focus-ring);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.zx-time-picker__separator {
|
|
25
|
+
color: var(--zx-color-text-muted);
|
|
26
|
+
font-weight: 700;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.zx-time-picker__clock-toggle {
|
|
30
|
+
margin-inline-start: var(--zx-space-1);
|
|
31
|
+
color: var(--zx-color-text-muted);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.zx-time-picker__clock-toggle[aria-expanded="true"] {
|
|
35
|
+
color: var(--zx-color-accent);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/* -------------------------------------------------------------------- clock -- */
|
|
39
|
+
|
|
40
|
+
/*
|
|
41
|
+
* Dial geometry. Every mark is centred on the dial and then pushed out along its own angle,
|
|
42
|
+
* which keeps the numbers upright: rotate the coordinate system, translate outwards, rotate back.
|
|
43
|
+
*/
|
|
44
|
+
.zx-time-picker__clock {
|
|
45
|
+
--zx-clock-size: 232px;
|
|
46
|
+
--zx-clock-mark: 32px;
|
|
47
|
+
--zx-clock-outer: calc(var(--zx-clock-size) / 2 - var(--zx-clock-mark) / 2 - 4px);
|
|
48
|
+
--zx-clock-inner: calc(var(--zx-clock-outer) - var(--zx-clock-mark) - 2px);
|
|
49
|
+
display: grid;
|
|
50
|
+
justify-items: center;
|
|
51
|
+
gap: var(--zx-space-2);
|
|
52
|
+
margin-block-start: var(--zx-space-3);
|
|
53
|
+
border-block-start: 1px solid var(--zx-color-border);
|
|
54
|
+
padding-block-start: var(--zx-space-3);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.zx-time-picker__clock[hidden] {
|
|
58
|
+
display: none;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.zx-time-picker__clock-head {
|
|
62
|
+
display: flex;
|
|
63
|
+
align-items: baseline;
|
|
64
|
+
gap: var(--zx-space-1);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.zx-time-picker__clock-unit {
|
|
68
|
+
min-block-size: 0;
|
|
69
|
+
border: 0;
|
|
70
|
+
border-radius: var(--zx-radius-sm);
|
|
71
|
+
background: none;
|
|
72
|
+
padding: 0 var(--zx-space-1);
|
|
73
|
+
color: var(--zx-color-text-muted);
|
|
74
|
+
font: inherit;
|
|
75
|
+
font-size: var(--zx-text-2xl);
|
|
76
|
+
font-weight: 600;
|
|
77
|
+
font-variant-numeric: tabular-nums;
|
|
78
|
+
line-height: 1.2;
|
|
79
|
+
cursor: pointer;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.zx-time-picker__clock-unit[aria-pressed="true"] {
|
|
83
|
+
color: var(--zx-color-accent);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.zx-time-picker__clock-unit:focus-visible {
|
|
87
|
+
outline: 0;
|
|
88
|
+
box-shadow: var(--zx-focus-ring);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.zx-time-picker__clock-colon {
|
|
92
|
+
color: var(--zx-color-text-muted);
|
|
93
|
+
font-size: var(--zx-text-2xl);
|
|
94
|
+
font-weight: 600;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.zx-time-picker__dial {
|
|
98
|
+
position: relative;
|
|
99
|
+
inline-size: var(--zx-clock-size);
|
|
100
|
+
block-size: var(--zx-clock-size);
|
|
101
|
+
border-radius: var(--zx-radius-full);
|
|
102
|
+
background: var(--zx-color-bg-muted);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.zx-time-picker__mark {
|
|
106
|
+
position: absolute;
|
|
107
|
+
inset-block-start: 50%;
|
|
108
|
+
inset-inline-start: 50%;
|
|
109
|
+
display: grid;
|
|
110
|
+
place-items: center;
|
|
111
|
+
inline-size: var(--zx-clock-mark);
|
|
112
|
+
block-size: var(--zx-clock-mark);
|
|
113
|
+
min-block-size: 0;
|
|
114
|
+
border: 0;
|
|
115
|
+
border-radius: var(--zx-radius-full);
|
|
116
|
+
background: none;
|
|
117
|
+
padding: 0;
|
|
118
|
+
color: var(--zx-color-text);
|
|
119
|
+
font: inherit;
|
|
120
|
+
font-size: var(--zx-text-sm);
|
|
121
|
+
font-variant-numeric: tabular-nums;
|
|
122
|
+
cursor: pointer;
|
|
123
|
+
transform: translate(-50%, -50%)
|
|
124
|
+
rotate(var(--zx-clock-angle))
|
|
125
|
+
translateY(calc(-1 * var(--zx-clock-outer)))
|
|
126
|
+
rotate(calc(-1 * var(--zx-clock-angle)));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.zx-time-picker__mark[data-ring="inner"] {
|
|
130
|
+
color: var(--zx-color-text-muted);
|
|
131
|
+
font-size: var(--zx-text-xs);
|
|
132
|
+
transform: translate(-50%, -50%)
|
|
133
|
+
rotate(var(--zx-clock-angle))
|
|
134
|
+
translateY(calc(-1 * var(--zx-clock-inner)))
|
|
135
|
+
rotate(calc(-1 * var(--zx-clock-angle)));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.zx-time-picker__mark:hover {
|
|
139
|
+
background: var(--zx-color-bg-hover);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.zx-time-picker__mark[aria-checked="true"] {
|
|
143
|
+
background: var(--zx-color-accent);
|
|
144
|
+
color: var(--zx-color-on-accent);
|
|
145
|
+
font-weight: 600;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.zx-time-picker__mark:focus-visible {
|
|
149
|
+
outline: 0;
|
|
150
|
+
box-shadow: var(--zx-focus-ring);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/* The hand's box hangs from the dial centre, so a plain rotation sweeps it around the face. */
|
|
154
|
+
.zx-time-picker__hand {
|
|
155
|
+
position: absolute;
|
|
156
|
+
inset-block-start: calc(50% - var(--zx-clock-outer));
|
|
157
|
+
inset-inline-start: 50%;
|
|
158
|
+
inline-size: 2px;
|
|
159
|
+
block-size: var(--zx-clock-outer);
|
|
160
|
+
margin-inline-start: -1px;
|
|
161
|
+
background: var(--zx-color-accent);
|
|
162
|
+
transform-origin: 50% 100%;
|
|
163
|
+
transform: rotate(var(--zx-clock-angle, 0deg));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.zx-time-picker__hand[data-ring="inner"] {
|
|
167
|
+
inset-block-start: calc(50% - var(--zx-clock-inner));
|
|
168
|
+
block-size: var(--zx-clock-inner);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.zx-time-picker__pivot {
|
|
172
|
+
position: absolute;
|
|
173
|
+
inset-block-start: 50%;
|
|
174
|
+
inset-inline-start: 50%;
|
|
175
|
+
inline-size: 8px;
|
|
176
|
+
block-size: 8px;
|
|
177
|
+
border-radius: var(--zx-radius-full);
|
|
178
|
+
background: var(--zx-color-accent);
|
|
179
|
+
transform: translate(-50%, -50%);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
183
|
+
.zx-time-picker__hand {
|
|
184
|
+
transition: transform var(--zx-dur-base) var(--zx-ease);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.zx-time-picker__mark {
|
|
188
|
+
transition: background-color var(--zx-dur-fast) var(--zx-ease),
|
|
189
|
+
color var(--zx-dur-fast) var(--zx-ease);
|
|
190
|
+
}
|
|
191
|
+
}
|