@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,500 @@
|
|
|
1
|
+
import { Component } from '../../core/component.js';
|
|
2
|
+
import { addDays, addMonths, formatDate, getWeekStart, isSameDay, parseDate } from '../../core/date.js';
|
|
3
|
+
import { h } from '../../core/dom.js';
|
|
4
|
+
import { icon } from '../../core/icons.js';
|
|
5
|
+
import { TimePicker } from './time-picker.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {Object} DatePickerOptions
|
|
9
|
+
* @property {Date|null} [value=null] Initially selected date.
|
|
10
|
+
* @property {Date|null} [min=null] Earliest selectable local calendar day.
|
|
11
|
+
* @property {Date|null} [max=null] Latest selectable local calendar day.
|
|
12
|
+
* @property {number} [weekStart=1] First weekday, from 0 (Sunday) through 6 (Saturday).
|
|
13
|
+
* @property {boolean} [showWeekNumbers=false] Show ISO week numbers.
|
|
14
|
+
* @property {boolean} [time=false] Append a time picker below the calendar.
|
|
15
|
+
* @property {(event: CustomEvent<{date: Date|null}>) => void} [onchange] Change listener.
|
|
16
|
+
* @property {(event: CustomEvent<{year: number, month: number}>) => void} [onmonthchange] Visible-month listener.
|
|
17
|
+
*/
|
|
18
|
+
/** @typedef {{silent?: boolean}} DatePickerSetOptions */
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Accessible inline calendar following the APG date-picker grid pattern.
|
|
22
|
+
* @fires DatePicker#change
|
|
23
|
+
* @fires DatePicker#monthchange
|
|
24
|
+
* @extends {Component<DatePickerOptions>}
|
|
25
|
+
*/
|
|
26
|
+
export class DatePicker extends Component {
|
|
27
|
+
static cssName = 'date-picker';
|
|
28
|
+
|
|
29
|
+
/** @type {DatePickerOptions} */
|
|
30
|
+
static defaults = {
|
|
31
|
+
value: null,
|
|
32
|
+
min: null,
|
|
33
|
+
max: null,
|
|
34
|
+
weekStart: 1,
|
|
35
|
+
showWeekNumbers: false,
|
|
36
|
+
time: false
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** @returns {HTMLElement} */
|
|
40
|
+
render() {
|
|
41
|
+
const root = /** @type {HTMLElement} */ (this.el ?? h('div'));
|
|
42
|
+
this._min = dayOnly(validDate(this.options.min));
|
|
43
|
+
this._max = dayOnly(validDate(this.options.max));
|
|
44
|
+
this._value = this._normalizeValue(validDate(this.options.value));
|
|
45
|
+
this._focused = dayOnly(this._value) ?? this._clampFocus(dayOnly(new Date()));
|
|
46
|
+
this._viewYear = this._focused.getFullYear();
|
|
47
|
+
this._viewMonth = this._focused.getMonth();
|
|
48
|
+
this._weekStart = normalizeWeekStart(this.options.weekStart);
|
|
49
|
+
this._quickOpen = false;
|
|
50
|
+
this._timePicker = null;
|
|
51
|
+
|
|
52
|
+
const surface = h('div', { class: 'zx-date-picker__surface' },
|
|
53
|
+
h('div', { class: 'zx-date-picker__header' },
|
|
54
|
+
h('button', {
|
|
55
|
+
ref: 'previous',
|
|
56
|
+
class: 'zx-date-picker__nav',
|
|
57
|
+
type: 'button',
|
|
58
|
+
ariaLabel: 'Previous month'
|
|
59
|
+
}, icon('chevron-left')),
|
|
60
|
+
h('button', {
|
|
61
|
+
ref: 'heading',
|
|
62
|
+
class: 'zx-date-picker__heading',
|
|
63
|
+
type: 'button',
|
|
64
|
+
ariaExpanded: 'false',
|
|
65
|
+
'aria-haspopup': 'grid'
|
|
66
|
+
}),
|
|
67
|
+
h('button', {
|
|
68
|
+
ref: 'next',
|
|
69
|
+
class: 'zx-date-picker__nav',
|
|
70
|
+
type: 'button',
|
|
71
|
+
ariaLabel: 'Next month'
|
|
72
|
+
}, icon('chevron-right'))
|
|
73
|
+
),
|
|
74
|
+
h('div', {
|
|
75
|
+
ref: 'quickPanel',
|
|
76
|
+
class: 'zx-date-picker__quick',
|
|
77
|
+
hidden: true
|
|
78
|
+
},
|
|
79
|
+
h('div', { class: 'zx-date-picker__quick-header' },
|
|
80
|
+
h('button', {
|
|
81
|
+
ref: 'quickPrevious',
|
|
82
|
+
class: 'zx-date-picker__nav',
|
|
83
|
+
type: 'button',
|
|
84
|
+
ariaLabel: 'Previous year'
|
|
85
|
+
}, icon('chevron-left')),
|
|
86
|
+
h('span', { ref: 'quickYear', class: 'zx-date-picker__quick-year', ariaLive: 'polite' }),
|
|
87
|
+
h('button', {
|
|
88
|
+
ref: 'quickNext',
|
|
89
|
+
class: 'zx-date-picker__nav',
|
|
90
|
+
type: 'button',
|
|
91
|
+
ariaLabel: 'Next year'
|
|
92
|
+
}, icon('chevron-right'))
|
|
93
|
+
),
|
|
94
|
+
h('div', { ref: 'quickGrid', class: 'zx-date-picker__quick-grid', role: 'grid' })),
|
|
95
|
+
h('table', {
|
|
96
|
+
ref: 'grid',
|
|
97
|
+
class: 'zx-date-picker__grid',
|
|
98
|
+
role: 'grid',
|
|
99
|
+
ariaLabel: 'Calendar'
|
|
100
|
+
},
|
|
101
|
+
h('thead', { ref: 'weekdays' }),
|
|
102
|
+
h('tbody', { ref: 'days' }))
|
|
103
|
+
);
|
|
104
|
+
this._content = surface;
|
|
105
|
+
root.append(surface);
|
|
106
|
+
|
|
107
|
+
this.listen(this.refs.previous, 'click', () => this._pageMonth(-1));
|
|
108
|
+
this.listen(this.refs.next, 'click', () => this._pageMonth(1));
|
|
109
|
+
this.listen(this.refs.heading, 'click', () => this._toggleQuickPick());
|
|
110
|
+
this.listen(this.refs.quickPrevious, 'click', () => this._stepQuickYear(-1));
|
|
111
|
+
this.listen(this.refs.quickNext, 'click', () => this._stepQuickYear(1));
|
|
112
|
+
this.listen(this.refs.quickGrid, 'click', (event) => this._onQuickClick(event));
|
|
113
|
+
this.listen(this.refs.quickGrid, 'keydown', (event) => this._onQuickKeydown(event));
|
|
114
|
+
this.listen(this.refs.days, 'click', (event) => this._onDayClick(event));
|
|
115
|
+
this.listen(this.refs.days, 'keydown', (event) => this._onDayKeydown(event));
|
|
116
|
+
|
|
117
|
+
this._renderWeekdays();
|
|
118
|
+
this._renderCalendar();
|
|
119
|
+
|
|
120
|
+
if (this.options.time) {
|
|
121
|
+
this._timePicker = new TimePicker(null, { value: this._value, seconds: false });
|
|
122
|
+
this._timePicker.on('change', (event) => {
|
|
123
|
+
const time = event.detail.time;
|
|
124
|
+
const base = this._value ?? this._focused;
|
|
125
|
+
const date = new Date(base.getTime());
|
|
126
|
+
date.setHours(time.h, time.m, time.s, 0);
|
|
127
|
+
this.set(date);
|
|
128
|
+
});
|
|
129
|
+
surface.append(this._timePicker.el);
|
|
130
|
+
}
|
|
131
|
+
return root;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Returns a copy of the selected date.
|
|
136
|
+
* @returns {Date|null}
|
|
137
|
+
*/
|
|
138
|
+
get() {
|
|
139
|
+
return cloneDate(this._value);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Selects a date, clamped to the configured day bounds.
|
|
144
|
+
* @param {Date|null} date Date to select, or null to clear.
|
|
145
|
+
* @param {DatePickerSetOptions} [options={}] Update behavior.
|
|
146
|
+
* @returns {this}
|
|
147
|
+
* @fires DatePicker#change
|
|
148
|
+
*/
|
|
149
|
+
set(date, { silent = false } = {}) {
|
|
150
|
+
const normalized = this._normalizeValue(validDate(date));
|
|
151
|
+
this._value = normalized;
|
|
152
|
+
if (normalized) {
|
|
153
|
+
this._focused = dayOnly(normalized);
|
|
154
|
+
this._viewYear = normalized.getFullYear();
|
|
155
|
+
this._viewMonth = normalized.getMonth();
|
|
156
|
+
}
|
|
157
|
+
this._timePicker?.set(normalized, { silent: true });
|
|
158
|
+
this._renderCalendar();
|
|
159
|
+
if (!silent) this.emit('change', { date: cloneDate(this._value) });
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Moves focus to the currently roving calendar day.
|
|
165
|
+
* @returns {this}
|
|
166
|
+
*/
|
|
167
|
+
focus() {
|
|
168
|
+
this._closeQuickPick();
|
|
169
|
+
const button = this._buttonForDate(this._focused);
|
|
170
|
+
button?.focus();
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Cleans up an appended time picker and generated host content. @returns {void} */
|
|
175
|
+
destroy() {
|
|
176
|
+
this._timePicker?.destroy();
|
|
177
|
+
this._timePicker = null;
|
|
178
|
+
this._content?.remove();
|
|
179
|
+
super.destroy();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** @param {Date|null} date @returns {Date|null} */
|
|
183
|
+
_normalizeValue(date) {
|
|
184
|
+
if (!date) return null;
|
|
185
|
+
const result = new Date(date.getTime());
|
|
186
|
+
const day = dayOnly(result);
|
|
187
|
+
if (this._min && day < this._min) copyCalendarDate(result, this._min);
|
|
188
|
+
if (this._max && day > this._max) copyCalendarDate(result, this._max);
|
|
189
|
+
return result;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** @param {Date} date @returns {Date} */
|
|
193
|
+
_clampFocus(date) {
|
|
194
|
+
if (this._min && date < this._min) return new Date(this._min.getTime());
|
|
195
|
+
if (this._max && date > this._max) return new Date(this._max.getTime());
|
|
196
|
+
return date;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** @returns {void} */
|
|
200
|
+
_renderWeekdays() {
|
|
201
|
+
const row = h('tr');
|
|
202
|
+
if (this.options.showWeekNumbers) {
|
|
203
|
+
row.append(h('th', {
|
|
204
|
+
class: 'zx-date-picker__week-heading',
|
|
205
|
+
scope: 'col',
|
|
206
|
+
ariaLabel: 'Week number'
|
|
207
|
+
}, '#'));
|
|
208
|
+
}
|
|
209
|
+
const sunday = new Date(2023, 0, 1);
|
|
210
|
+
for (let index = 0; index < 7; index += 1) {
|
|
211
|
+
const weekday = addDays(sunday, (this._weekStart + index) % 7);
|
|
212
|
+
row.append(h('th', {
|
|
213
|
+
scope: 'col',
|
|
214
|
+
ariaLabel: formatDate(weekday, '%A')
|
|
215
|
+
}, formatDate(weekday, '%a')));
|
|
216
|
+
}
|
|
217
|
+
this.refs.weekdays.replaceChildren(row);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** @returns {void} */
|
|
221
|
+
_renderCalendar() {
|
|
222
|
+
if (!this.refs?.days) return;
|
|
223
|
+
const first = new Date(this._viewYear, this._viewMonth, 1);
|
|
224
|
+
const offset = (first.getDay() - this._weekStart + 7) % 7;
|
|
225
|
+
const start = addDays(first, -offset);
|
|
226
|
+
this.refs.heading.textContent = formatDate(first, '%B %Y');
|
|
227
|
+
this.refs.heading.setAttribute('aria-label', `Choose month and year, ${formatDate(first, '%B %Y')}`);
|
|
228
|
+
const rows = [];
|
|
229
|
+
|
|
230
|
+
for (let week = 0; week < 6; week += 1) {
|
|
231
|
+
const rowStart = addDays(start, week * 7);
|
|
232
|
+
const row = h('tr');
|
|
233
|
+
if (this.options.showWeekNumbers) {
|
|
234
|
+
row.append(h('th', {
|
|
235
|
+
class: 'zx-date-picker__week',
|
|
236
|
+
scope: 'row',
|
|
237
|
+
ariaLabel: `Week ${isoWeekNumber(rowStart)}`
|
|
238
|
+
}, String(isoWeekNumber(rowStart))));
|
|
239
|
+
}
|
|
240
|
+
for (let column = 0; column < 7; column += 1) {
|
|
241
|
+
const date = addDays(rowStart, column);
|
|
242
|
+
const selected = Boolean(this._value && isSameDay(date, this._value));
|
|
243
|
+
const unavailable = !this._inRange(date);
|
|
244
|
+
const button = h('button', {
|
|
245
|
+
class: 'zx-date-picker__day',
|
|
246
|
+
type: 'button',
|
|
247
|
+
role: 'gridcell',
|
|
248
|
+
tabindex: isSameDay(date, this._focused) ? 0 : -1,
|
|
249
|
+
ariaSelected: String(selected),
|
|
250
|
+
ariaDisabled: String(unavailable),
|
|
251
|
+
ariaCurrent: isSameDay(date, new Date()) ? 'date' : null,
|
|
252
|
+
ariaLabel: `${formatDate(date, '%e')} ${formatDate(date, '%B %Y')}`,
|
|
253
|
+
dataset: {
|
|
254
|
+
date: formatDate(date, '%Y-%m-%d'),
|
|
255
|
+
otherMonth: date.getMonth() === this._viewMonth ? null : 'true'
|
|
256
|
+
}
|
|
257
|
+
}, formatDate(date, '%e'));
|
|
258
|
+
row.append(h('td', { role: 'presentation' }, button));
|
|
259
|
+
}
|
|
260
|
+
rows.push(row);
|
|
261
|
+
}
|
|
262
|
+
this.refs.days.replaceChildren(...rows);
|
|
263
|
+
if (this._quickOpen) this._renderQuickPick();
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** @param {Event} event @returns {void} */
|
|
267
|
+
_onDayClick(event) {
|
|
268
|
+
const button = event.target?.closest?.('[data-date]');
|
|
269
|
+
if (!button || !this.refs.days.contains(button)) return;
|
|
270
|
+
const date = parseDate(button.dataset.date, '%Y-%m-%d');
|
|
271
|
+
if (date && this._inRange(date)) this._selectDate(date);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/** @param {KeyboardEvent} event @returns {void} */
|
|
275
|
+
_onDayKeydown(event) {
|
|
276
|
+
const button = event.target?.closest?.('[data-date]');
|
|
277
|
+
if (!button || !this.refs.days.contains(button)) return;
|
|
278
|
+
const current = parseDate(button.dataset.date, '%Y-%m-%d');
|
|
279
|
+
if (!current) return;
|
|
280
|
+
let next = null;
|
|
281
|
+
if (event.key === 'ArrowLeft') next = addDays(current, -1);
|
|
282
|
+
else if (event.key === 'ArrowRight') next = addDays(current, 1);
|
|
283
|
+
else if (event.key === 'ArrowUp') next = addDays(current, -7);
|
|
284
|
+
else if (event.key === 'ArrowDown') next = addDays(current, 7);
|
|
285
|
+
else if (event.key === 'PageUp') next = addMonths(current, event.shiftKey ? -12 : -1);
|
|
286
|
+
else if (event.key === 'PageDown') next = addMonths(current, event.shiftKey ? 12 : 1);
|
|
287
|
+
else if (event.key === 'Home') next = addDays(current, -((current.getDay() - this._weekStart + 7) % 7));
|
|
288
|
+
else if (event.key === 'End') next = addDays(current, 6 - ((current.getDay() - this._weekStart + 7) % 7));
|
|
289
|
+
else if (event.key === 'Enter' || event.key === ' ') {
|
|
290
|
+
event.preventDefault();
|
|
291
|
+
if (this._inRange(current)) this._selectDate(current);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
if (!next) return;
|
|
295
|
+
event.preventDefault();
|
|
296
|
+
this._moveFocus(next);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** @param {Date} date @returns {void} */
|
|
300
|
+
_moveFocus(date) {
|
|
301
|
+
const monthChanged = date.getFullYear() !== this._viewYear || date.getMonth() !== this._viewMonth;
|
|
302
|
+
this._focused = dayOnly(date);
|
|
303
|
+
this._viewYear = date.getFullYear();
|
|
304
|
+
this._viewMonth = date.getMonth();
|
|
305
|
+
this._renderCalendar();
|
|
306
|
+
if (monthChanged) this._emitMonthChange();
|
|
307
|
+
this._buttonForDate(date)?.focus();
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** @param {Date} date @returns {void} */
|
|
311
|
+
_selectDate(date) {
|
|
312
|
+
const selected = new Date(date.getTime());
|
|
313
|
+
const time = this._timePicker?.get();
|
|
314
|
+
if (time) selected.setHours(time.h, time.m, time.s, 0);
|
|
315
|
+
else if (this._value) selected.setHours(
|
|
316
|
+
this._value.getHours(), this._value.getMinutes(), this._value.getSeconds(), this._value.getMilliseconds()
|
|
317
|
+
);
|
|
318
|
+
const monthChanged = selected.getFullYear() !== this._viewYear || selected.getMonth() !== this._viewMonth;
|
|
319
|
+
this._value = selected;
|
|
320
|
+
this._focused = dayOnly(selected);
|
|
321
|
+
this._viewYear = selected.getFullYear();
|
|
322
|
+
this._viewMonth = selected.getMonth();
|
|
323
|
+
this._timePicker?.set(selected, { silent: true });
|
|
324
|
+
this._renderCalendar();
|
|
325
|
+
if (monthChanged) this._emitMonthChange();
|
|
326
|
+
this.emit('change', { date: cloneDate(selected) });
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** @param {number} amount @returns {void} */
|
|
330
|
+
_pageMonth(amount) {
|
|
331
|
+
this._closeQuickPick();
|
|
332
|
+
const date = addMonths(this._focused, amount);
|
|
333
|
+
this._focused = dayOnly(date);
|
|
334
|
+
this._viewYear = date.getFullYear();
|
|
335
|
+
this._viewMonth = date.getMonth();
|
|
336
|
+
this._renderCalendar();
|
|
337
|
+
this._emitMonthChange();
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/** @returns {void} */
|
|
341
|
+
_emitMonthChange() {
|
|
342
|
+
this.emit('monthchange', { year: this._viewYear, month: this._viewMonth });
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/** @returns {void} */
|
|
346
|
+
_toggleQuickPick() {
|
|
347
|
+
if (this._quickOpen) {
|
|
348
|
+
this._closeQuickPick();
|
|
349
|
+
this.refs.heading.focus();
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
this._quickOpen = true;
|
|
353
|
+
this.refs.quickPanel.hidden = false;
|
|
354
|
+
this.refs.heading.setAttribute('aria-expanded', 'true');
|
|
355
|
+
this._renderQuickPick();
|
|
356
|
+
this.refs.quickGrid.querySelector('[tabindex="0"]')?.focus();
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/** @returns {void} */
|
|
360
|
+
_closeQuickPick() {
|
|
361
|
+
if (!this._quickOpen) return;
|
|
362
|
+
this._quickOpen = false;
|
|
363
|
+
this.refs.quickPanel.hidden = true;
|
|
364
|
+
this.refs.heading.setAttribute('aria-expanded', 'false');
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/** @returns {void} */
|
|
368
|
+
_renderQuickPick() {
|
|
369
|
+
this.refs.quickYear.textContent = String(this._viewYear);
|
|
370
|
+
const months = [];
|
|
371
|
+
for (let month = 0; month < 12; month += 1) {
|
|
372
|
+
const date = new Date(this._viewYear, month, 1);
|
|
373
|
+
months.push(h('button', {
|
|
374
|
+
class: 'zx-date-picker__quick-month',
|
|
375
|
+
type: 'button',
|
|
376
|
+
role: 'gridcell',
|
|
377
|
+
tabindex: month === this._viewMonth ? 0 : -1,
|
|
378
|
+
ariaSelected: String(month === this._viewMonth),
|
|
379
|
+
dataset: { month }
|
|
380
|
+
}, formatDate(date, '%b')));
|
|
381
|
+
}
|
|
382
|
+
this.refs.quickGrid.replaceChildren(...months);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/** @param {number} amount @returns {void} */
|
|
386
|
+
_stepQuickYear(amount) {
|
|
387
|
+
this._viewYear += amount;
|
|
388
|
+
this._renderQuickPick();
|
|
389
|
+
this._emitMonthChange();
|
|
390
|
+
this.refs.quickGrid.querySelector('[tabindex="0"]')?.focus();
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/** @param {Event} event @returns {void} */
|
|
394
|
+
_onQuickClick(event) {
|
|
395
|
+
const button = event.target?.closest?.('[data-month]');
|
|
396
|
+
if (!button || !this.refs.quickGrid.contains(button)) return;
|
|
397
|
+
this._chooseQuickMonth(Number(button.dataset.month));
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/** @param {KeyboardEvent} event @returns {void} */
|
|
401
|
+
_onQuickKeydown(event) {
|
|
402
|
+
const button = event.target?.closest?.('[data-month]');
|
|
403
|
+
if (!button || !this.refs.quickGrid.contains(button)) return;
|
|
404
|
+
const month = Number(button.dataset.month);
|
|
405
|
+
let next = null;
|
|
406
|
+
if (event.key === 'ArrowLeft') next = month - 1;
|
|
407
|
+
else if (event.key === 'ArrowRight') next = month + 1;
|
|
408
|
+
else if (event.key === 'ArrowUp') next = month - 3;
|
|
409
|
+
else if (event.key === 'ArrowDown') next = month + 3;
|
|
410
|
+
else if (event.key === 'Home') next = 0;
|
|
411
|
+
else if (event.key === 'End') next = 11;
|
|
412
|
+
else if (event.key === 'Enter' || event.key === ' ') {
|
|
413
|
+
event.preventDefault();
|
|
414
|
+
this._chooseQuickMonth(month);
|
|
415
|
+
return;
|
|
416
|
+
} else if (event.key === 'Escape') {
|
|
417
|
+
event.preventDefault();
|
|
418
|
+
this._closeQuickPick();
|
|
419
|
+
this.refs.heading.focus();
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
if (next === null) return;
|
|
423
|
+
event.preventDefault();
|
|
424
|
+
next = Math.max(0, Math.min(11, next));
|
|
425
|
+
const items = this.refs.quickGrid.querySelectorAll('[data-month]');
|
|
426
|
+
for (const item of items) item.tabIndex = Number(item.dataset.month) === next ? 0 : -1;
|
|
427
|
+
items[next]?.focus();
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/** @param {number} month @returns {void} */
|
|
431
|
+
_chooseQuickMonth(month) {
|
|
432
|
+
const date = new Date(this._viewYear, month, Math.min(
|
|
433
|
+
this._focused.getDate(), new Date(this._viewYear, month + 1, 0).getDate()
|
|
434
|
+
));
|
|
435
|
+
this._focused = dayOnly(date);
|
|
436
|
+
this._viewMonth = month;
|
|
437
|
+
this._closeQuickPick();
|
|
438
|
+
this._renderCalendar();
|
|
439
|
+
this._emitMonthChange();
|
|
440
|
+
this.focus();
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/** @param {Date} date @returns {boolean} */
|
|
444
|
+
_inRange(date) {
|
|
445
|
+
const day = dayOnly(date);
|
|
446
|
+
return !(this._min && day < this._min) && !(this._max && day > this._max);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/** @param {Date} date @returns {HTMLButtonElement|null} */
|
|
450
|
+
_buttonForDate(date) {
|
|
451
|
+
return this.refs.days.querySelector(`[data-date="${formatDate(date, '%Y-%m-%d')}"]`);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Fired when the selected date changes.
|
|
457
|
+
* @event DatePicker#change
|
|
458
|
+
* @type {CustomEvent<{date: Date|null}>}
|
|
459
|
+
*/
|
|
460
|
+
/**
|
|
461
|
+
* Fired when the visible month changes. Month is zero-based.
|
|
462
|
+
* @event DatePicker#monthchange
|
|
463
|
+
* @type {CustomEvent<{year: number, month: number}>}
|
|
464
|
+
*/
|
|
465
|
+
|
|
466
|
+
/** @param {unknown} value @returns {Date|null} */
|
|
467
|
+
function validDate(value) {
|
|
468
|
+
return value instanceof Date && !Number.isNaN(value.getTime()) ? new Date(value.getTime()) : null;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/** @param {Date|null} date @returns {Date|null} */
|
|
472
|
+
function dayOnly(date) {
|
|
473
|
+
if (!date) return null;
|
|
474
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/** @param {Date|null} date @returns {Date|null} */
|
|
478
|
+
function cloneDate(date) {
|
|
479
|
+
return date ? new Date(date.getTime()) : null;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/** @param {Date} target @param {Date} source @returns {void} */
|
|
483
|
+
function copyCalendarDate(target, source) {
|
|
484
|
+
target.setFullYear(source.getFullYear(), source.getMonth(), source.getDate());
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/** @param {unknown} value @returns {number} */
|
|
488
|
+
function normalizeWeekStart(value) {
|
|
489
|
+
const number = Number(value);
|
|
490
|
+
return Number.isInteger(number) && number >= 0 && number <= 6 ? number : getWeekStart();
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/** @param {Date} date @returns {number} */
|
|
494
|
+
function isoWeekNumber(date) {
|
|
495
|
+
const utc = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
|
|
496
|
+
const weekday = utc.getUTCDay() || 7;
|
|
497
|
+
utc.setUTCDate(utc.getUTCDate() + 4 - weekday);
|
|
498
|
+
const yearStart = new Date(Date.UTC(utc.getUTCFullYear(), 0, 1));
|
|
499
|
+
return Math.ceil((((utc.getTime() - yearStart.getTime()) / 86400000) + 1) / 7);
|
|
500
|
+
}
|