@deepfuture/dui-components 0.0.12 → 0.0.14
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/_deprecated/center/center.js +2 -2
- package/_deprecated/hstack/hstack.js +79 -33
- package/_deprecated/page-inset/page-inset.js +104 -56
- package/_deprecated/vstack/vstack.js +61 -19
- package/accordion/accordion-item.js +217 -147
- package/accordion/accordion.js +214 -149
- package/alert-dialog/alert-dialog-close.js +2 -2
- package/alert-dialog/alert-dialog-popup.js +230 -166
- package/alert-dialog/alert-dialog-trigger.js +2 -2
- package/alert-dialog/alert-dialog.js +128 -73
- package/avatar/avatar.js +175 -115
- package/badge/badge.js +2 -2
- package/breadcrumb/breadcrumb-ellipsis.js +2 -2
- package/breadcrumb/breadcrumb-item.js +2 -2
- package/breadcrumb/breadcrumb-link.js +2 -2
- package/breadcrumb/breadcrumb-page.js +2 -2
- package/breadcrumb/breadcrumb-separator.js +2 -2
- package/breadcrumb/breadcrumb.js +2 -2
- package/button/button.js +109 -65
- package/calendar/calendar.js +368 -290
- package/checkbox/checkbox-group.js +146 -87
- package/checkbox/checkbox.js +232 -167
- package/collapsible/collapsible.js +210 -132
- package/combobox/combobox.js +318 -252
- package/command/command-empty.js +67 -25
- package/command/command-group.js +87 -47
- package/command/command-input.js +84 -44
- package/command/command-item.js +168 -124
- package/command/command-list.js +60 -18
- package/command/command-separator.js +2 -2
- package/command/command-shortcut.js +2 -2
- package/command/command.js +297 -232
- package/data-table/data-table.js +225 -153
- package/dialog/dialog-close.js +2 -2
- package/dialog/dialog-popup.js +247 -181
- package/dialog/dialog-trigger.js +2 -2
- package/dialog/dialog.js +128 -73
- package/dropzone/dropzone.js +310 -249
- package/icon/icon.js +2 -2
- package/input/input.js +204 -143
- package/link/link.js +62 -24
- package/menu/menu-item.js +66 -24
- package/menu/menu.js +189 -136
- package/menubar/menubar.js +142 -91
- package/number-field/number-field.js +277 -204
- package/package.json +2 -3
- package/popover/popover-close.js +2 -2
- package/popover/popover-popup.js +126 -76
- package/popover/popover-trigger.js +2 -2
- package/popover/popover.js +181 -120
- package/portal/portal.js +128 -86
- package/preview-card/preview-card-popup.js +114 -66
- package/preview-card/preview-card-trigger.js +2 -2
- package/preview-card/preview-card.js +211 -142
- package/progress/progress.js +91 -45
- package/radio/radio-group.js +153 -90
- package/radio/radio.js +137 -94
- package/scroll-area/scroll-area.js +382 -283
- package/select/select.js +260 -203
- package/separator/separator.js +60 -18
- package/sidebar/sidebar-content.js +2 -2
- package/sidebar/sidebar-footer.js +2 -2
- package/sidebar/sidebar-group-label.js +2 -2
- package/sidebar/sidebar-group.js +2 -2
- package/sidebar/sidebar-header.js +2 -2
- package/sidebar/sidebar-inset.js +2 -2
- package/sidebar/sidebar-menu-button.js +118 -74
- package/sidebar/sidebar-menu-item.js +2 -2
- package/sidebar/sidebar-menu.js +2 -2
- package/sidebar/sidebar-provider.js +202 -129
- package/sidebar/sidebar-separator.js +2 -2
- package/sidebar/sidebar-trigger.js +2 -2
- package/sidebar/sidebar.js +150 -85
- package/slider/slider.js +217 -159
- package/spinner/spinner.js +70 -28
- package/switch/switch.js +174 -111
- package/tabs/tab.js +89 -47
- package/tabs/tabs-indicator.js +2 -2
- package/tabs/tabs-list.js +92 -54
- package/tabs/tabs-panel.js +90 -44
- package/tabs/tabs.js +130 -71
- package/textarea/textarea.js +153 -95
- package/toggle/toggle-group.js +184 -125
- package/toggle/toggle.js +131 -76
- package/toolbar/toolbar.js +79 -33
- package/tooltip/tooltip-popup.js +108 -60
- package/tooltip/tooltip-trigger.js +93 -55
- package/tooltip/tooltip.js +225 -154
- package/trunc/trunc.js +78 -34
package/calendar/calendar.js
CHANGED
|
@@ -1,11 +1,43 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
2
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
3
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
4
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
5
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
6
|
+
var _, done = false;
|
|
7
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
8
|
+
var context = {};
|
|
9
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
10
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
11
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
12
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
13
|
+
if (kind === "accessor") {
|
|
14
|
+
if (result === void 0) continue;
|
|
15
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
16
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
17
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
18
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
19
|
+
}
|
|
20
|
+
else if (_ = accept(result)) {
|
|
21
|
+
if (kind === "field") initializers.unshift(_);
|
|
22
|
+
else descriptor[key] = _;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
26
|
+
done = true;
|
|
27
|
+
};
|
|
28
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
29
|
+
var useValue = arguments.length > 2;
|
|
30
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
31
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
32
|
+
}
|
|
33
|
+
return useValue ? value : void 0;
|
|
34
|
+
};
|
|
35
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
36
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
37
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
6
38
|
};
|
|
7
39
|
import { css, html, LitElement } from "lit";
|
|
8
|
-
import { property } from "lit/decorators.js";
|
|
40
|
+
import { property, state } from "lit/decorators.js";
|
|
9
41
|
import { base } from "@deepfuture/dui-core/base";
|
|
10
42
|
import { customEvent } from "@deepfuture/dui-core/event";
|
|
11
43
|
export const valueChangeEvent = customEvent("value-change", { bubbles: true, composed: true });
|
|
@@ -84,284 +116,349 @@ const styles = css `
|
|
|
84
116
|
* @csspart day - Individual day button.
|
|
85
117
|
* @fires value-change - Fired when a date is selected. Detail: { value: string }
|
|
86
118
|
*/
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
119
|
+
let DuiCalendar = (() => {
|
|
120
|
+
let _classSuper = LitElement;
|
|
121
|
+
let _value_decorators;
|
|
122
|
+
let _value_initializers = [];
|
|
123
|
+
let _value_extraInitializers = [];
|
|
124
|
+
let _defaultValue_decorators;
|
|
125
|
+
let _defaultValue_initializers = [];
|
|
126
|
+
let _defaultValue_extraInitializers = [];
|
|
127
|
+
let _min_decorators;
|
|
128
|
+
let _min_initializers = [];
|
|
129
|
+
let _min_extraInitializers = [];
|
|
130
|
+
let _max_decorators;
|
|
131
|
+
let _max_initializers = [];
|
|
132
|
+
let _max_extraInitializers = [];
|
|
133
|
+
let _locale_decorators;
|
|
134
|
+
let _locale_initializers = [];
|
|
135
|
+
let _locale_extraInitializers = [];
|
|
136
|
+
let _disabled_decorators;
|
|
137
|
+
let _disabled_initializers = [];
|
|
138
|
+
let _disabled_extraInitializers = [];
|
|
139
|
+
let _readOnly_decorators;
|
|
140
|
+
let _readOnly_initializers = [];
|
|
141
|
+
let _readOnly_extraInitializers = [];
|
|
142
|
+
let _private_internalValue_decorators;
|
|
143
|
+
let _private_internalValue_initializers = [];
|
|
144
|
+
let _private_internalValue_extraInitializers = [];
|
|
145
|
+
let _private_internalValue_descriptor;
|
|
146
|
+
let _private_focusedDate_decorators;
|
|
147
|
+
let _private_focusedDate_initializers = [];
|
|
148
|
+
let _private_focusedDate_extraInitializers = [];
|
|
149
|
+
let _private_focusedDate_descriptor;
|
|
150
|
+
let _private_viewMonth_decorators;
|
|
151
|
+
let _private_viewMonth_initializers = [];
|
|
152
|
+
let _private_viewMonth_extraInitializers = [];
|
|
153
|
+
let _private_viewMonth_descriptor;
|
|
154
|
+
let _private_viewYear_decorators;
|
|
155
|
+
let _private_viewYear_initializers = [];
|
|
156
|
+
let _private_viewYear_extraInitializers = [];
|
|
157
|
+
let _private_viewYear_descriptor;
|
|
158
|
+
return class DuiCalendar extends _classSuper {
|
|
159
|
+
static {
|
|
160
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
161
|
+
_value_decorators = [property()];
|
|
162
|
+
_defaultValue_decorators = [property({ attribute: "default-value" })];
|
|
163
|
+
_min_decorators = [property()];
|
|
164
|
+
_max_decorators = [property()];
|
|
165
|
+
_locale_decorators = [property()];
|
|
166
|
+
_disabled_decorators = [property({ type: Boolean, reflect: true })];
|
|
167
|
+
_readOnly_decorators = [property({ type: Boolean, reflect: true, attribute: "read-only" })];
|
|
168
|
+
_private_internalValue_decorators = [state()];
|
|
169
|
+
_private_focusedDate_decorators = [state()];
|
|
170
|
+
_private_viewMonth_decorators = [state()];
|
|
171
|
+
_private_viewYear_decorators = [state()];
|
|
172
|
+
__esDecorate(this, null, _value_decorators, { kind: "accessor", name: "value", static: false, private: false, access: { has: obj => "value" in obj, get: obj => obj.value, set: (obj, value) => { obj.value = value; } }, metadata: _metadata }, _value_initializers, _value_extraInitializers);
|
|
173
|
+
__esDecorate(this, null, _defaultValue_decorators, { kind: "accessor", name: "defaultValue", static: false, private: false, access: { has: obj => "defaultValue" in obj, get: obj => obj.defaultValue, set: (obj, value) => { obj.defaultValue = value; } }, metadata: _metadata }, _defaultValue_initializers, _defaultValue_extraInitializers);
|
|
174
|
+
__esDecorate(this, null, _min_decorators, { kind: "accessor", name: "min", static: false, private: false, access: { has: obj => "min" in obj, get: obj => obj.min, set: (obj, value) => { obj.min = value; } }, metadata: _metadata }, _min_initializers, _min_extraInitializers);
|
|
175
|
+
__esDecorate(this, null, _max_decorators, { kind: "accessor", name: "max", static: false, private: false, access: { has: obj => "max" in obj, get: obj => obj.max, set: (obj, value) => { obj.max = value; } }, metadata: _metadata }, _max_initializers, _max_extraInitializers);
|
|
176
|
+
__esDecorate(this, null, _locale_decorators, { kind: "accessor", name: "locale", static: false, private: false, access: { has: obj => "locale" in obj, get: obj => obj.locale, set: (obj, value) => { obj.locale = value; } }, metadata: _metadata }, _locale_initializers, _locale_extraInitializers);
|
|
177
|
+
__esDecorate(this, null, _disabled_decorators, { kind: "accessor", name: "disabled", static: false, private: false, access: { has: obj => "disabled" in obj, get: obj => obj.disabled, set: (obj, value) => { obj.disabled = value; } }, metadata: _metadata }, _disabled_initializers, _disabled_extraInitializers);
|
|
178
|
+
__esDecorate(this, null, _readOnly_decorators, { kind: "accessor", name: "readOnly", static: false, private: false, access: { has: obj => "readOnly" in obj, get: obj => obj.readOnly, set: (obj, value) => { obj.readOnly = value; } }, metadata: _metadata }, _readOnly_initializers, _readOnly_extraInitializers);
|
|
179
|
+
__esDecorate(this, _private_internalValue_descriptor = { get: __setFunctionName(function () { return this.#internalValue_accessor_storage; }, "#internalValue", "get"), set: __setFunctionName(function (value) { this.#internalValue_accessor_storage = value; }, "#internalValue", "set") }, _private_internalValue_decorators, { kind: "accessor", name: "#internalValue", static: false, private: true, access: { has: obj => #internalValue in obj, get: obj => obj.#internalValue, set: (obj, value) => { obj.#internalValue = value; } }, metadata: _metadata }, _private_internalValue_initializers, _private_internalValue_extraInitializers);
|
|
180
|
+
__esDecorate(this, _private_focusedDate_descriptor = { get: __setFunctionName(function () { return this.#focusedDate_accessor_storage; }, "#focusedDate", "get"), set: __setFunctionName(function (value) { this.#focusedDate_accessor_storage = value; }, "#focusedDate", "set") }, _private_focusedDate_decorators, { kind: "accessor", name: "#focusedDate", static: false, private: true, access: { has: obj => #focusedDate in obj, get: obj => obj.#focusedDate, set: (obj, value) => { obj.#focusedDate = value; } }, metadata: _metadata }, _private_focusedDate_initializers, _private_focusedDate_extraInitializers);
|
|
181
|
+
__esDecorate(this, _private_viewMonth_descriptor = { get: __setFunctionName(function () { return this.#viewMonth_accessor_storage; }, "#viewMonth", "get"), set: __setFunctionName(function (value) { this.#viewMonth_accessor_storage = value; }, "#viewMonth", "set") }, _private_viewMonth_decorators, { kind: "accessor", name: "#viewMonth", static: false, private: true, access: { has: obj => #viewMonth in obj, get: obj => obj.#viewMonth, set: (obj, value) => { obj.#viewMonth = value; } }, metadata: _metadata }, _private_viewMonth_initializers, _private_viewMonth_extraInitializers);
|
|
182
|
+
__esDecorate(this, _private_viewYear_descriptor = { get: __setFunctionName(function () { return this.#viewYear_accessor_storage; }, "#viewYear", "get"), set: __setFunctionName(function (value) { this.#viewYear_accessor_storage = value; }, "#viewYear", "set") }, _private_viewYear_decorators, { kind: "accessor", name: "#viewYear", static: false, private: true, access: { has: obj => #viewYear in obj, get: obj => obj.#viewYear, set: (obj, value) => { obj.#viewYear = value; } }, metadata: _metadata }, _private_viewYear_initializers, _private_viewYear_extraInitializers);
|
|
183
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
130
184
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
185
|
+
static tagName = "dui-calendar";
|
|
186
|
+
static styles = [base, styles];
|
|
187
|
+
#value_accessor_storage = __runInitializers(this, _value_initializers, undefined);
|
|
188
|
+
get value() { return this.#value_accessor_storage; }
|
|
189
|
+
set value(value) { this.#value_accessor_storage = value; }
|
|
190
|
+
#defaultValue_accessor_storage = (__runInitializers(this, _value_extraInitializers), __runInitializers(this, _defaultValue_initializers, undefined));
|
|
191
|
+
get defaultValue() { return this.#defaultValue_accessor_storage; }
|
|
192
|
+
set defaultValue(value) { this.#defaultValue_accessor_storage = value; }
|
|
193
|
+
#min_accessor_storage = (__runInitializers(this, _defaultValue_extraInitializers), __runInitializers(this, _min_initializers, undefined));
|
|
194
|
+
get min() { return this.#min_accessor_storage; }
|
|
195
|
+
set min(value) { this.#min_accessor_storage = value; }
|
|
196
|
+
#max_accessor_storage = (__runInitializers(this, _min_extraInitializers), __runInitializers(this, _max_initializers, undefined));
|
|
197
|
+
get max() { return this.#max_accessor_storage; }
|
|
198
|
+
set max(value) { this.#max_accessor_storage = value; }
|
|
199
|
+
#locale_accessor_storage = (__runInitializers(this, _max_extraInitializers), __runInitializers(this, _locale_initializers, "en-US"));
|
|
200
|
+
get locale() { return this.#locale_accessor_storage; }
|
|
201
|
+
set locale(value) { this.#locale_accessor_storage = value; }
|
|
202
|
+
#disabled_accessor_storage = (__runInitializers(this, _locale_extraInitializers), __runInitializers(this, _disabled_initializers, false));
|
|
203
|
+
get disabled() { return this.#disabled_accessor_storage; }
|
|
204
|
+
set disabled(value) { this.#disabled_accessor_storage = value; }
|
|
205
|
+
#readOnly_accessor_storage = (__runInitializers(this, _disabled_extraInitializers), __runInitializers(this, _readOnly_initializers, false));
|
|
206
|
+
get readOnly() { return this.#readOnly_accessor_storage; }
|
|
207
|
+
set readOnly(value) { this.#readOnly_accessor_storage = value; }
|
|
208
|
+
#internalValue_accessor_storage = (__runInitializers(this, _readOnly_extraInitializers), __runInitializers(this, _private_internalValue_initializers, undefined));
|
|
209
|
+
get #internalValue() { return _private_internalValue_descriptor.get.call(this); }
|
|
210
|
+
set #internalValue(value) { return _private_internalValue_descriptor.set.call(this, value); }
|
|
211
|
+
#focusedDate_accessor_storage = (__runInitializers(this, _private_internalValue_extraInitializers), __runInitializers(this, _private_focusedDate_initializers, new Date()));
|
|
212
|
+
get #focusedDate() { return _private_focusedDate_descriptor.get.call(this); }
|
|
213
|
+
set #focusedDate(value) { return _private_focusedDate_descriptor.set.call(this, value); }
|
|
214
|
+
#viewMonth_accessor_storage = (__runInitializers(this, _private_focusedDate_extraInitializers), __runInitializers(this, _private_viewMonth_initializers, new Date().getMonth()));
|
|
215
|
+
get #viewMonth() { return _private_viewMonth_descriptor.get.call(this); }
|
|
216
|
+
set #viewMonth(value) { return _private_viewMonth_descriptor.set.call(this, value); }
|
|
217
|
+
#viewYear_accessor_storage = (__runInitializers(this, _private_viewMonth_extraInitializers), __runInitializers(this, _private_viewYear_initializers, new Date().getFullYear()));
|
|
218
|
+
get #viewYear() { return _private_viewYear_descriptor.get.call(this); }
|
|
219
|
+
set #viewYear(value) { return _private_viewYear_descriptor.set.call(this, value); }
|
|
220
|
+
get #selectedValue() {
|
|
221
|
+
return this.value ?? this.#internalValue;
|
|
137
222
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
#isDateDisabled(date) {
|
|
151
|
-
if (this.disabled)
|
|
152
|
-
return true;
|
|
153
|
-
const iso = this.#formatISO(date);
|
|
154
|
-
if (this.min && iso < this.min)
|
|
155
|
-
return true;
|
|
156
|
-
if (this.max && iso > this.max)
|
|
157
|
-
return true;
|
|
158
|
-
return false;
|
|
159
|
-
}
|
|
160
|
-
#getDaysInMonth(year, month) {
|
|
161
|
-
return new Date(year, month + 1, 0).getDate();
|
|
162
|
-
}
|
|
163
|
-
#getFirstDayOfWeek() {
|
|
164
|
-
// Use Intl to determine first day of week for locale
|
|
165
|
-
// Fallback to Sunday (0) for most locales
|
|
166
|
-
try {
|
|
167
|
-
const locale = new Intl.Locale(this.locale);
|
|
168
|
-
// @ts-ignore — weekInfo is a newer API
|
|
169
|
-
const weekInfo = locale.weekInfo ?? locale.getWeekInfo?.();
|
|
170
|
-
return weekInfo?.firstDay === 7 ? 0 : (weekInfo?.firstDay ?? 0);
|
|
223
|
+
connectedCallback() {
|
|
224
|
+
super.connectedCallback();
|
|
225
|
+
if (this.value === undefined && this.defaultValue !== undefined) {
|
|
226
|
+
this.#internalValue = this.defaultValue;
|
|
227
|
+
}
|
|
228
|
+
const selected = this.#selectedValue;
|
|
229
|
+
if (selected) {
|
|
230
|
+
const d = new Date(selected + "T00:00:00");
|
|
231
|
+
this.#viewMonth = d.getMonth();
|
|
232
|
+
this.#viewYear = d.getFullYear();
|
|
233
|
+
this.#focusedDate = d;
|
|
234
|
+
}
|
|
171
235
|
}
|
|
172
|
-
|
|
173
|
-
|
|
236
|
+
#formatISO(date) {
|
|
237
|
+
const y = date.getFullYear();
|
|
238
|
+
const m = String(date.getMonth() + 1).padStart(2, "0");
|
|
239
|
+
const d = String(date.getDate()).padStart(2, "0");
|
|
240
|
+
return `${y}-${m}-${d}`;
|
|
174
241
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
const daysInMonth = this.#getDaysInMonth(year, month);
|
|
180
|
-
const firstDay = new Date(year, month, 1).getDay();
|
|
181
|
-
const firstDayOfWeek = this.#getFirstDayOfWeek();
|
|
182
|
-
const today = new Date();
|
|
183
|
-
const selectedIso = this.#selectedValue;
|
|
184
|
-
let startOffset = firstDay - firstDayOfWeek;
|
|
185
|
-
if (startOffset < 0)
|
|
186
|
-
startOffset += 7;
|
|
187
|
-
const cells = [];
|
|
188
|
-
// Days from previous month
|
|
189
|
-
const prevMonth = month === 0 ? 11 : month - 1;
|
|
190
|
-
const prevYear = month === 0 ? year - 1 : year;
|
|
191
|
-
const daysInPrevMonth = this.#getDaysInMonth(prevYear, prevMonth);
|
|
192
|
-
for (let i = startOffset - 1; i >= 0; i--) {
|
|
193
|
-
const day = daysInPrevMonth - i;
|
|
194
|
-
const date = new Date(prevYear, prevMonth, day);
|
|
195
|
-
cells.push({
|
|
196
|
-
date,
|
|
197
|
-
day,
|
|
198
|
-
iso: this.#formatISO(date),
|
|
199
|
-
isToday: this.#isSameDay(date, today),
|
|
200
|
-
isSelected: this.#formatISO(date) === selectedIso,
|
|
201
|
-
isOutsideMonth: true,
|
|
202
|
-
isDisabled: this.#isDateDisabled(date),
|
|
203
|
-
});
|
|
242
|
+
#isSameDay(a, b) {
|
|
243
|
+
return (a.getFullYear() === b.getFullYear() &&
|
|
244
|
+
a.getMonth() === b.getMonth() &&
|
|
245
|
+
a.getDate() === b.getDate());
|
|
204
246
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
isOutsideMonth: false,
|
|
215
|
-
isDisabled: this.#isDateDisabled(date),
|
|
216
|
-
});
|
|
247
|
+
#isDateDisabled(date) {
|
|
248
|
+
if (this.disabled)
|
|
249
|
+
return true;
|
|
250
|
+
const iso = this.#formatISO(date);
|
|
251
|
+
if (this.min && iso < this.min)
|
|
252
|
+
return true;
|
|
253
|
+
if (this.max && iso > this.max)
|
|
254
|
+
return true;
|
|
255
|
+
return false;
|
|
217
256
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
const nextMonth = month === 11 ? 0 : month + 1;
|
|
221
|
-
const nextYear = month === 11 ? year + 1 : year;
|
|
222
|
-
for (let day = 1; day <= remaining; day++) {
|
|
223
|
-
const date = new Date(nextYear, nextMonth, day);
|
|
224
|
-
cells.push({
|
|
225
|
-
date,
|
|
226
|
-
day,
|
|
227
|
-
iso: this.#formatISO(date),
|
|
228
|
-
isToday: this.#isSameDay(date, today),
|
|
229
|
-
isSelected: this.#formatISO(date) === selectedIso,
|
|
230
|
-
isOutsideMonth: true,
|
|
231
|
-
isDisabled: this.#isDateDisabled(date),
|
|
232
|
-
});
|
|
257
|
+
#getDaysInMonth(year, month) {
|
|
258
|
+
return new Date(year, month + 1, 0).getDate();
|
|
233
259
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
260
|
+
#getFirstDayOfWeek() {
|
|
261
|
+
// Use Intl to determine first day of week for locale
|
|
262
|
+
// Fallback to Sunday (0) for most locales
|
|
263
|
+
try {
|
|
264
|
+
const locale = new Intl.Locale(this.locale);
|
|
265
|
+
// @ts-ignore — weekInfo is a newer API
|
|
266
|
+
const weekInfo = locale.weekInfo ?? locale.getWeekInfo?.();
|
|
267
|
+
return weekInfo?.firstDay === 7 ? 0 : (weekInfo?.firstDay ?? 0);
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
return 0;
|
|
271
|
+
}
|
|
238
272
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
273
|
+
#buildGrid() {
|
|
274
|
+
const year = this.#viewYear;
|
|
275
|
+
const month = this.#viewMonth;
|
|
276
|
+
const daysInMonth = this.#getDaysInMonth(year, month);
|
|
277
|
+
const firstDay = new Date(year, month, 1).getDay();
|
|
278
|
+
const firstDayOfWeek = this.#getFirstDayOfWeek();
|
|
279
|
+
const today = new Date();
|
|
280
|
+
const selectedIso = this.#selectedValue;
|
|
281
|
+
let startOffset = firstDay - firstDayOfWeek;
|
|
282
|
+
if (startOffset < 0)
|
|
283
|
+
startOffset += 7;
|
|
284
|
+
const cells = [];
|
|
285
|
+
// Days from previous month
|
|
286
|
+
const prevMonth = month === 0 ? 11 : month - 1;
|
|
287
|
+
const prevYear = month === 0 ? year - 1 : year;
|
|
288
|
+
const daysInPrevMonth = this.#getDaysInMonth(prevYear, prevMonth);
|
|
289
|
+
for (let i = startOffset - 1; i >= 0; i--) {
|
|
290
|
+
const day = daysInPrevMonth - i;
|
|
291
|
+
const date = new Date(prevYear, prevMonth, day);
|
|
292
|
+
cells.push({
|
|
293
|
+
date,
|
|
294
|
+
day,
|
|
295
|
+
iso: this.#formatISO(date),
|
|
296
|
+
isToday: this.#isSameDay(date, today),
|
|
297
|
+
isSelected: this.#formatISO(date) === selectedIso,
|
|
298
|
+
isOutsideMonth: true,
|
|
299
|
+
isDisabled: this.#isDateDisabled(date),
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
// Days in current month
|
|
303
|
+
for (let day = 1; day <= daysInMonth; day++) {
|
|
304
|
+
const date = new Date(year, month, day);
|
|
305
|
+
cells.push({
|
|
306
|
+
date,
|
|
307
|
+
day,
|
|
308
|
+
iso: this.#formatISO(date),
|
|
309
|
+
isToday: this.#isSameDay(date, today),
|
|
310
|
+
isSelected: this.#formatISO(date) === selectedIso,
|
|
311
|
+
isOutsideMonth: false,
|
|
312
|
+
isDisabled: this.#isDateDisabled(date),
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
// Fill remaining cells to make 6 rows
|
|
316
|
+
const remaining = 42 - cells.length;
|
|
317
|
+
const nextMonth = month === 11 ? 0 : month + 1;
|
|
318
|
+
const nextYear = month === 11 ? year + 1 : year;
|
|
319
|
+
for (let day = 1; day <= remaining; day++) {
|
|
320
|
+
const date = new Date(nextYear, nextMonth, day);
|
|
321
|
+
cells.push({
|
|
322
|
+
date,
|
|
323
|
+
day,
|
|
324
|
+
iso: this.#formatISO(date),
|
|
325
|
+
isToday: this.#isSameDay(date, today),
|
|
326
|
+
isSelected: this.#formatISO(date) === selectedIso,
|
|
327
|
+
isOutsideMonth: true,
|
|
328
|
+
isDisabled: this.#isDateDisabled(date),
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
// Split into rows of 7
|
|
332
|
+
const rows = [];
|
|
333
|
+
for (let i = 0; i < cells.length; i += 7) {
|
|
334
|
+
rows.push(cells.slice(i, i + 7));
|
|
335
|
+
}
|
|
336
|
+
return rows;
|
|
249
337
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
if (this.disabled || this.readOnly)
|
|
261
|
-
return;
|
|
262
|
-
if (this.value === undefined) {
|
|
263
|
-
this.#internalValue = iso;
|
|
338
|
+
#getWeekdayNames() {
|
|
339
|
+
const formatter = new Intl.DateTimeFormat(this.locale, { weekday: "short" });
|
|
340
|
+
const firstDayOfWeek = this.#getFirstDayOfWeek();
|
|
341
|
+
const names = [];
|
|
342
|
+
for (let i = 0; i < 7; i++) {
|
|
343
|
+
// Jan 4 2015 is a Sunday
|
|
344
|
+
const date = new Date(2015, 0, 4 + firstDayOfWeek + i);
|
|
345
|
+
names.push(formatter.format(date));
|
|
346
|
+
}
|
|
347
|
+
return names;
|
|
264
348
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
newMonth = 11;
|
|
272
|
-
newYear--;
|
|
349
|
+
#getMonthYearHeading() {
|
|
350
|
+
const date = new Date(this.#viewYear, this.#viewMonth, 1);
|
|
351
|
+
return new Intl.DateTimeFormat(this.locale, {
|
|
352
|
+
month: "long",
|
|
353
|
+
year: "numeric",
|
|
354
|
+
}).format(date);
|
|
273
355
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
356
|
+
#selectDate(iso) {
|
|
357
|
+
if (this.disabled || this.readOnly)
|
|
358
|
+
return;
|
|
359
|
+
if (this.value === undefined) {
|
|
360
|
+
this.#internalValue = iso;
|
|
361
|
+
}
|
|
362
|
+
this.dispatchEvent(valueChangeEvent({ value: iso }));
|
|
277
363
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
364
|
+
#navigateMonth(delta) {
|
|
365
|
+
let newMonth = this.#viewMonth + delta;
|
|
366
|
+
let newYear = this.#viewYear;
|
|
367
|
+
if (newMonth < 0) {
|
|
368
|
+
newMonth = 11;
|
|
369
|
+
newYear--;
|
|
370
|
+
}
|
|
371
|
+
else if (newMonth > 11) {
|
|
372
|
+
newMonth = 0;
|
|
373
|
+
newYear++;
|
|
374
|
+
}
|
|
375
|
+
this.#viewMonth = newMonth;
|
|
376
|
+
this.#viewYear = newYear;
|
|
377
|
+
this.#focusedDate = new Date(newYear, newMonth, 1);
|
|
287
378
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
379
|
+
#onDayClick = (__runInitializers(this, _private_viewYear_extraInitializers), (e) => {
|
|
380
|
+
const button = e.currentTarget;
|
|
381
|
+
const iso = button.dataset.date;
|
|
382
|
+
if (iso && !button.disabled) {
|
|
383
|
+
this.#selectDate(iso);
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
#onKeyDown = (e) => {
|
|
387
|
+
const focused = new Date(this.#focusedDate);
|
|
388
|
+
let handled = true;
|
|
389
|
+
switch (e.key) {
|
|
390
|
+
case "ArrowLeft":
|
|
391
|
+
focused.setDate(focused.getDate() - 1);
|
|
392
|
+
break;
|
|
393
|
+
case "ArrowRight":
|
|
394
|
+
focused.setDate(focused.getDate() + 1);
|
|
395
|
+
break;
|
|
396
|
+
case "ArrowUp":
|
|
397
|
+
focused.setDate(focused.getDate() - 7);
|
|
398
|
+
break;
|
|
399
|
+
case "ArrowDown":
|
|
400
|
+
focused.setDate(focused.getDate() + 7);
|
|
401
|
+
break;
|
|
402
|
+
case "PageUp":
|
|
403
|
+
if (e.shiftKey) {
|
|
404
|
+
focused.setFullYear(focused.getFullYear() - 1);
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
focused.setMonth(focused.getMonth() - 1);
|
|
408
|
+
}
|
|
409
|
+
break;
|
|
410
|
+
case "PageDown":
|
|
411
|
+
if (e.shiftKey) {
|
|
412
|
+
focused.setFullYear(focused.getFullYear() + 1);
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
focused.setMonth(focused.getMonth() + 1);
|
|
416
|
+
}
|
|
417
|
+
break;
|
|
418
|
+
case "Home": {
|
|
419
|
+
focused.setDate(1);
|
|
420
|
+
break;
|
|
316
421
|
}
|
|
317
|
-
|
|
318
|
-
focused.
|
|
422
|
+
case "End": {
|
|
423
|
+
const daysInMonth = this.#getDaysInMonth(focused.getFullYear(), focused.getMonth());
|
|
424
|
+
focused.setDate(daysInMonth);
|
|
425
|
+
break;
|
|
319
426
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
427
|
+
case "Enter":
|
|
428
|
+
case " ":
|
|
429
|
+
e.preventDefault();
|
|
430
|
+
if (!this.#isDateDisabled(focused)) {
|
|
431
|
+
this.#selectDate(this.#formatISO(focused));
|
|
432
|
+
}
|
|
433
|
+
return;
|
|
434
|
+
default:
|
|
435
|
+
handled = false;
|
|
329
436
|
}
|
|
330
|
-
|
|
331
|
-
case " ":
|
|
437
|
+
if (handled) {
|
|
332
438
|
e.preventDefault();
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
#onNextClick = () => {
|
|
357
|
-
this.#navigateMonth(1);
|
|
358
|
-
};
|
|
359
|
-
render() {
|
|
360
|
-
const grid = this.#buildGrid();
|
|
361
|
-
const weekdays = this.#getWeekdayNames();
|
|
362
|
-
const heading = this.#getMonthYearHeading();
|
|
363
|
-
const focusedIso = this.#formatISO(this.#focusedDate);
|
|
364
|
-
return html `
|
|
439
|
+
this.#focusedDate = focused;
|
|
440
|
+
this.#viewMonth = focused.getMonth();
|
|
441
|
+
this.#viewYear = focused.getFullYear();
|
|
442
|
+
// Focus the correct day button after render
|
|
443
|
+
this.updateComplete.then(() => {
|
|
444
|
+
const iso = this.#formatISO(focused);
|
|
445
|
+
const btn = this.shadowRoot?.querySelector(`[data-date="${iso}"]`);
|
|
446
|
+
btn?.focus();
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
#onPrevClick = () => {
|
|
451
|
+
this.#navigateMonth(-1);
|
|
452
|
+
};
|
|
453
|
+
#onNextClick = () => {
|
|
454
|
+
this.#navigateMonth(1);
|
|
455
|
+
};
|
|
456
|
+
render() {
|
|
457
|
+
const grid = this.#buildGrid();
|
|
458
|
+
const weekdays = this.#getWeekdayNames();
|
|
459
|
+
const heading = this.#getMonthYearHeading();
|
|
460
|
+
const focusedIso = this.#formatISO(this.#focusedDate);
|
|
461
|
+
return html `
|
|
365
462
|
<div part="root" role="grid" @keydown="${this.#onKeyDown}">
|
|
366
463
|
<div part="header">
|
|
367
464
|
<button
|
|
@@ -403,26 +500,7 @@ export class DuiCalendar extends LitElement {
|
|
|
403
500
|
</div>
|
|
404
501
|
</div>
|
|
405
502
|
`;
|
|
406
|
-
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
], DuiCalendar.prototype, "value", null);
|
|
411
|
-
__decorate([
|
|
412
|
-
property({ attribute: "default-value" })
|
|
413
|
-
], DuiCalendar.prototype, "defaultValue", null);
|
|
414
|
-
__decorate([
|
|
415
|
-
property()
|
|
416
|
-
], DuiCalendar.prototype, "min", null);
|
|
417
|
-
__decorate([
|
|
418
|
-
property()
|
|
419
|
-
], DuiCalendar.prototype, "max", null);
|
|
420
|
-
__decorate([
|
|
421
|
-
property()
|
|
422
|
-
], DuiCalendar.prototype, "locale", null);
|
|
423
|
-
__decorate([
|
|
424
|
-
property({ type: Boolean, reflect: true })
|
|
425
|
-
], DuiCalendar.prototype, "disabled", null);
|
|
426
|
-
__decorate([
|
|
427
|
-
property({ type: Boolean, reflect: true, attribute: "read-only" })
|
|
428
|
-
], DuiCalendar.prototype, "readOnly", null);
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
})();
|
|
506
|
+
export { DuiCalendar };
|