@iyulab/components 1.52.0 → 1.54.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 +73 -0
- package/README.md +54 -1
- package/dist/_virtual/{_@oxc-project_runtime@0.151.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/decorate.js +1 -1
- package/dist/_virtual/{_@oxc-project_runtime@0.151.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/decorateMetadata.js +1 -1
- package/dist/_virtual/_glob-assets_raw/player-pause-fill.svg.a756c400.js +4 -0
- package/dist/_virtual/_glob-assets_raw/player-play-fill.svg.768b6efc.js +4 -0
- package/dist/assets/locales/ar.json.js +27 -1
- package/dist/assets/locales/de.json.js +27 -1
- package/dist/assets/locales/en.json.js +27 -1
- package/dist/assets/locales/es.json.js +27 -1
- package/dist/assets/locales/fr.json.js +27 -1
- package/dist/assets/locales/id.json.js +27 -1
- package/dist/assets/locales/ja.json.js +27 -1
- package/dist/assets/locales/ko.json.js +27 -1
- package/dist/assets/locales/pt-BR.json.js +27 -1
- package/dist/assets/locales/ru.json.js +27 -1
- package/dist/assets/locales/th.json.js +27 -1
- package/dist/assets/locales/vi.json.js +27 -1
- package/dist/assets/locales/zh-CN.json.js +27 -1
- package/dist/assets/locales/zh-TW.json.js +27 -1
- package/dist/components/UFloatingElement.js +2 -2
- package/dist/components/UFormControlElement.js +2 -2
- package/dist/components/UOverlayElement.js +2 -2
- package/dist/components/alert/UAlert.js +2 -2
- package/dist/components/avatar/UAvatar.js +2 -2
- package/dist/components/badge/UBadge.js +2 -2
- package/dist/components/breadcrumb/UBreadcrumb.js +1 -1
- package/dist/components/breadcrumb-item/UBreadcrumbItem.js +2 -2
- package/dist/components/button/UButton.js +2 -2
- package/dist/components/button-group/UButtonGroup.js +2 -2
- package/dist/components/calendar/UCalendar.d.ts +101 -0
- package/dist/components/calendar/UCalendar.js +223 -0
- package/dist/components/calendar/UCalendar.styles.d.ts +1 -0
- package/dist/components/calendar/UCalendar.styles.js +137 -0
- package/dist/components/calendar/dates.d.ts +13 -0
- package/dist/components/calendar/dates.js +37 -0
- package/dist/components/calendar/picker.styles.d.ts +5 -0
- package/dist/components/calendar/picker.styles.js +78 -0
- package/dist/components/card/UCard.js +2 -2
- package/dist/components/carousel/UCarousel.d.ts +17 -0
- package/dist/components/carousel/UCarousel.js +53 -12
- package/dist/components/carousel/UCarousel.styles.js +20 -0
- package/dist/components/checkbox/UCheckbox.js +2 -2
- package/dist/components/chip/UChip.js +2 -2
- package/dist/components/copy-button/UCopyButton.js +2 -2
- package/dist/components/date-picker/UDatePicker.d.ts +8 -13
- package/dist/components/date-picker/UDatePicker.js +36 -165
- package/dist/components/date-picker/UDatePicker.styles.js +0 -135
- package/dist/components/date-range-picker/UDateRangePicker.d.ts +113 -0
- package/dist/components/date-range-picker/UDateRangePicker.js +276 -0
- package/dist/components/date-range-picker/UDateRangePicker.styles.d.ts +1 -0
- package/dist/components/date-range-picker/UDateRangePicker.styles.js +83 -0
- package/dist/components/date-range-picker/presets.d.ts +32 -0
- package/dist/components/date-range-picker/presets.js +78 -0
- package/dist/components/dialog/UDialog.js +2 -2
- package/dist/components/divider/UDivider.js +2 -2
- package/dist/components/drawer/UDrawer.js +2 -2
- package/dist/components/expander/UExpander.js +2 -2
- package/dist/components/field/UField.js +2 -2
- package/dist/components/file-input/UFileInput.js +2 -2
- package/dist/components/form/UForm.js +2 -2
- package/dist/components/icon/UIcon.js +2 -2
- package/dist/components/icon-button/UIconButton.js +2 -2
- package/dist/components/input/UInput.d.ts +31 -3
- package/dist/components/input/UInput.js +131 -24
- package/dist/components/menu/UMenu.js +2 -2
- package/dist/components/menu-item/UMenuItem.js +2 -2
- package/dist/components/option/UOption.js +2 -2
- package/dist/components/panel/UPanel.js +2 -2
- package/dist/components/popover/UPopover.js +2 -2
- package/dist/components/progress-bar/UProgressBar.js +2 -2
- package/dist/components/progress-ring/UProgressRing.js +2 -2
- package/dist/components/radio/URadio.js +2 -2
- package/dist/components/rating/URating.js +2 -2
- package/dist/components/select/USelect.js +2 -2
- package/dist/components/skeleton/USkeleton.js +2 -2
- package/dist/components/slider/USlider.js +2 -2
- package/dist/components/spinner/USpinner.js +2 -2
- package/dist/components/split-panel/USplitPanel.js +2 -2
- package/dist/components/switch/USwitch.js +2 -2
- package/dist/components/tab/UTab.js +2 -2
- package/dist/components/tab-panel/UTabPanel.js +2 -2
- package/dist/components/tag/UTag.js +2 -2
- package/dist/components/text/UText.js +2 -2
- package/dist/components/textarea/UTextarea.js +2 -2
- package/dist/components/tooltip/UTooltip.js +2 -2
- package/dist/components/tree/UTree.js +2 -2
- package/dist/components/tree-item/UTreeItem.js +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -2
- package/dist/plugins/vite-plugin-react-wrapper.d.ts +7 -0
- package/dist/plugins/vite-plugin-react-wrapper.js +11 -1
- package/dist/react/UDateRangePicker.d.ts +13 -0
- package/dist/react/UDateRangePicker.js +12 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +1 -0
- package/dist/utilities/Locale.d.ts +1 -1
- package/dist/utilities/format.d.ts +27 -0
- package/dist/utilities/format.js +71 -1
- package/dist/utilities/icons.js +4 -0
- package/package.json +3 -3
- package/skills/iyulab-components/SKILL.md +1 -0
- package/skills/iyulab-components/references/components/carousel.md +6 -0
- package/skills/iyulab-components/references/components/date-picker.md +2 -0
- package/skills/iyulab-components/references/components/date-range-picker.md +147 -0
- package/skills/iyulab-components/references/components/input.md +14 -4
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { UElement } from "../UElement.js";
|
|
2
|
-
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.
|
|
3
|
-
import __decorate from "../../_virtual/_@oxc-project_runtime@0.
|
|
2
|
+
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorateMetadata.js";
|
|
3
|
+
import __decorate from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorate.js";
|
|
4
4
|
import "../button/UButton.js";
|
|
5
5
|
import "../icon/UIcon.js";
|
|
6
6
|
import { Locale } from "../../utilities/Locale.js";
|
|
7
7
|
import { styles } from "./UCarousel.styles.js";
|
|
8
|
-
import { html } from "lit";
|
|
8
|
+
import { html, nothing } from "lit";
|
|
9
9
|
import { customElement, property, state } from "lit/decorators.js";
|
|
10
|
+
import { ifDefined } from "lit/directives/if-defined.js";
|
|
10
11
|
//#region src/components/carousel/UCarousel.ts
|
|
11
12
|
var UCarousel = class UCarousel extends UElement {
|
|
12
13
|
constructor(..._args) {
|
|
@@ -24,6 +25,8 @@ var UCarousel = class UCarousel extends UElement {
|
|
|
24
25
|
this.slideCount = 0;
|
|
25
26
|
this.isDragging = false;
|
|
26
27
|
this.dragOffset = 0;
|
|
28
|
+
this.rotationStopped = false;
|
|
29
|
+
this.hovered = false;
|
|
27
30
|
this.dragStartX = 0;
|
|
28
31
|
this.dragStartTime = 0;
|
|
29
32
|
this.pointerDown = false;
|
|
@@ -40,7 +43,7 @@ var UCarousel = class UCarousel extends UElement {
|
|
|
40
43
|
this.goTo = (index) => {
|
|
41
44
|
if (index < 0 || index > this.maxIndex || index === this.index) return;
|
|
42
45
|
this.index = index;
|
|
43
|
-
if (this.
|
|
46
|
+
if (this.rotating) this.startAutoplay();
|
|
44
47
|
};
|
|
45
48
|
this.handleDragStart = (e) => {
|
|
46
49
|
e.preventDefault();
|
|
@@ -51,7 +54,7 @@ var UCarousel = class UCarousel extends UElement {
|
|
|
51
54
|
this.dragStartX = e.clientX;
|
|
52
55
|
this.dragOffset = 0;
|
|
53
56
|
this.dragStartTime = Date.now();
|
|
54
|
-
|
|
57
|
+
this.stopAutoplay();
|
|
55
58
|
};
|
|
56
59
|
this.handlePointerMove = (e) => {
|
|
57
60
|
if (!this.pointerDown) return;
|
|
@@ -79,7 +82,21 @@ var UCarousel = class UCarousel extends UElement {
|
|
|
79
82
|
this.pointerDown = false;
|
|
80
83
|
this.isDragging = false;
|
|
81
84
|
this.dragOffset = 0;
|
|
82
|
-
if (this.
|
|
85
|
+
if (this.rotating) this.startAutoplay();
|
|
86
|
+
};
|
|
87
|
+
this.toggleRotation = () => {
|
|
88
|
+
this.rotationStopped = !this.rotationStopped;
|
|
89
|
+
};
|
|
90
|
+
this.handleFocusIn = (e) => {
|
|
91
|
+
if (!this.autoplay) return;
|
|
92
|
+
const origin = e.composedPath()[0];
|
|
93
|
+
if (origin instanceof Element && origin.matches(":focus-visible")) this.rotationStopped = true;
|
|
94
|
+
};
|
|
95
|
+
this.handlePointerEnter = (e) => {
|
|
96
|
+
if (e.pointerType === "mouse") this.hovered = true;
|
|
97
|
+
};
|
|
98
|
+
this.handlePointerLeave = () => {
|
|
99
|
+
this.hovered = false;
|
|
83
100
|
};
|
|
84
101
|
this.handleClickCancel = (e) => {
|
|
85
102
|
e.preventDefault();
|
|
@@ -89,6 +106,13 @@ var UCarousel = class UCarousel extends UElement {
|
|
|
89
106
|
static {
|
|
90
107
|
this.styles = [super.styles, styles];
|
|
91
108
|
}
|
|
109
|
+
/** 지금 자동으로 넘기고 있는가. */
|
|
110
|
+
get rotating() {
|
|
111
|
+
return this.autoplay && !this.rotationStopped && !this.hovered;
|
|
112
|
+
}
|
|
113
|
+
get showDots() {
|
|
114
|
+
return this.pagination && this.pageCount > 1;
|
|
115
|
+
}
|
|
92
116
|
get perView() {
|
|
93
117
|
return Math.max(1, this.slidesPerView);
|
|
94
118
|
}
|
|
@@ -106,21 +130,28 @@ var UCarousel = class UCarousel extends UElement {
|
|
|
106
130
|
}
|
|
107
131
|
connectedCallback() {
|
|
108
132
|
super.connectedCallback();
|
|
109
|
-
|
|
133
|
+
this.addEventListener("focusin", this.handleFocusIn);
|
|
134
|
+
this.addEventListener("pointerenter", this.handlePointerEnter);
|
|
135
|
+
this.addEventListener("pointerleave", this.handlePointerLeave);
|
|
136
|
+
if (this.rotating) this.startAutoplay();
|
|
110
137
|
}
|
|
111
138
|
disconnectedCallback() {
|
|
112
139
|
this.stopAutoplay();
|
|
140
|
+
this.removeEventListener("focusin", this.handleFocusIn);
|
|
141
|
+
this.removeEventListener("pointerenter", this.handlePointerEnter);
|
|
142
|
+
this.removeEventListener("pointerleave", this.handlePointerLeave);
|
|
113
143
|
super.disconnectedCallback();
|
|
114
144
|
}
|
|
115
145
|
willUpdate(changedProperties) {
|
|
116
146
|
super.willUpdate(changedProperties);
|
|
147
|
+
if (changedProperties.has("autoplay") && this.autoplay) this.rotationStopped = false;
|
|
117
148
|
if (changedProperties.has("slidesPerView")) this.style.setProperty("--slides-per-view", String(this.perView));
|
|
118
149
|
if (changedProperties.has("gap")) this.style.setProperty("--slide-gap", `${this.gap}px`);
|
|
119
150
|
}
|
|
120
151
|
updated(changedProperties) {
|
|
121
152
|
super.updated(changedProperties);
|
|
122
|
-
if (changedProperties.has("autoplay") || changedProperties.has("autoplayInterval")) {
|
|
123
|
-
if (this.
|
|
153
|
+
if (changedProperties.has("autoplay") || changedProperties.has("autoplayInterval") || changedProperties.has("rotationStopped") || changedProperties.has("hovered")) {
|
|
154
|
+
if (this.rotating) this.startAutoplay();
|
|
124
155
|
else this.stopAutoplay();
|
|
125
156
|
}
|
|
126
157
|
}
|
|
@@ -135,7 +166,8 @@ var UCarousel = class UCarousel extends UElement {
|
|
|
135
166
|
@pointermove=${this.draggable ? this.handlePointerMove : null}
|
|
136
167
|
@pointerup=${this.draggable ? this.handlePointerUp : null}
|
|
137
168
|
@pointerleave=${this.draggable ? this.handlePointerUp : null}>
|
|
138
|
-
<div part="slides" class="slides" style="${style}"
|
|
169
|
+
<div part="slides" class="slides" style="${style}"
|
|
170
|
+
aria-live=${ifDefined(this.autoplay ? this.rotating ? "off" : "polite" : void 0)}>
|
|
139
171
|
<slot @slotchange=${this.handleSlotChange}></slot>
|
|
140
172
|
</div>
|
|
141
173
|
</div>
|
|
@@ -158,8 +190,15 @@ var UCarousel = class UCarousel extends UElement {
|
|
|
158
190
|
</u-button>
|
|
159
191
|
|
|
160
192
|
<div part="indicator" class="indicator"
|
|
161
|
-
?hidden=${!this.
|
|
162
|
-
${
|
|
193
|
+
?hidden=${!this.autoplay && !this.showDots}>
|
|
194
|
+
${this.autoplay ? html`
|
|
195
|
+
<button part="rotation-button" class="rotation-button"
|
|
196
|
+
aria-label=${Locale.getValue(this.rotationStopped ? "startSlideRotation" : "stopSlideRotation")}
|
|
197
|
+
@click=${this.toggleRotation}>
|
|
198
|
+
<u-icon lib="internal" name=${this.rotationStopped ? "player-play-fill" : "player-pause-fill"}></u-icon>
|
|
199
|
+
</button>
|
|
200
|
+
` : nothing}
|
|
201
|
+
${!this.showDots ? nothing : Array.from({ length: this.pageCount }, (_, i) => html`
|
|
163
202
|
<button part="dot" class="dot"
|
|
164
203
|
aria-label=${Locale.getValue("goToSlide", { n: i + 1 })}
|
|
165
204
|
aria-current=${i === this.currentPage ? "true" : "false"}
|
|
@@ -225,6 +264,8 @@ __decorate([property({ type: Number }), __decorateMetadata("design:type", Object
|
|
|
225
264
|
__decorate([state(), __decorateMetadata("design:type", Object)], UCarousel.prototype, "slideCount", void 0);
|
|
226
265
|
__decorate([state(), __decorateMetadata("design:type", Object)], UCarousel.prototype, "isDragging", void 0);
|
|
227
266
|
__decorate([state(), __decorateMetadata("design:type", Object)], UCarousel.prototype, "dragOffset", void 0);
|
|
267
|
+
__decorate([state(), __decorateMetadata("design:type", Object)], UCarousel.prototype, "rotationStopped", void 0);
|
|
268
|
+
__decorate([state(), __decorateMetadata("design:type", Object)], UCarousel.prototype, "hovered", void 0);
|
|
228
269
|
UCarousel = __decorate([customElement("u-carousel")], UCarousel);
|
|
229
270
|
//#endregion
|
|
230
271
|
export { UCarousel };
|
|
@@ -72,6 +72,26 @@ var styles = css`
|
|
|
72
72
|
transform: translateY(-50%) scale(0.95);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
/* ── Rotation control (autoplay) ── */
|
|
76
|
+
.rotation-button {
|
|
77
|
+
display: inline-flex;
|
|
78
|
+
align-items: center;
|
|
79
|
+
justify-content: center;
|
|
80
|
+
width: 24px;
|
|
81
|
+
height: 24px;
|
|
82
|
+
padding: 0;
|
|
83
|
+
border: none;
|
|
84
|
+
border-radius: var(--u-radius-circle, 50%);
|
|
85
|
+
font-size: 12px;
|
|
86
|
+
color: var(--u-neutral-900, #212121);
|
|
87
|
+
background-color: var(--u-neutral-100, #F5F5F5);
|
|
88
|
+
box-shadow: var(--u-shadow-md, 0 2px 8px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.05));
|
|
89
|
+
cursor: pointer;
|
|
90
|
+
}
|
|
91
|
+
.rotation-button:hover {
|
|
92
|
+
background-color: var(--u-neutral-200, #EEEEEE);
|
|
93
|
+
}
|
|
94
|
+
|
|
75
95
|
.nav-button.prev { left: 12px; }
|
|
76
96
|
.nav-button.next { right: 12px; }
|
|
77
97
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.
|
|
2
|
-
import __decorate from "../../_virtual/_@oxc-project_runtime@0.
|
|
1
|
+
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorateMetadata.js";
|
|
2
|
+
import __decorate from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorate.js";
|
|
3
3
|
import { UFormControlElement } from "../UFormControlElement.js";
|
|
4
4
|
import "../icon/UIcon.js";
|
|
5
5
|
import { Locale } from "../../utilities/Locale.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UElement } from "../UElement.js";
|
|
2
|
-
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.
|
|
3
|
-
import __decorate from "../../_virtual/_@oxc-project_runtime@0.
|
|
2
|
+
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorateMetadata.js";
|
|
3
|
+
import __decorate from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorate.js";
|
|
4
4
|
import "../button/UButton.js";
|
|
5
5
|
import "../icon/UIcon.js";
|
|
6
6
|
import { Locale } from "../../utilities/Locale.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UElement } from "../UElement.js";
|
|
2
|
-
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.
|
|
3
|
-
import __decorate from "../../_virtual/_@oxc-project_runtime@0.
|
|
2
|
+
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorateMetadata.js";
|
|
3
|
+
import __decorate from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorate.js";
|
|
4
4
|
import "../button/UButton.js";
|
|
5
5
|
import "../icon/UIcon.js";
|
|
6
6
|
import { Locale } from "../../utilities/Locale.js";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PropertyValues } from 'lit';
|
|
2
2
|
import { UFormControlElement } from '../UFormControlElement.js';
|
|
3
|
+
import { UCalendar } from '../calendar/UCalendar.js';
|
|
3
4
|
import { UPopover } from '../popover/UPopover.js';
|
|
4
5
|
export type DatePickerMode = 'date' | 'datetime';
|
|
5
6
|
/**
|
|
@@ -62,23 +63,18 @@ export declare class UDatePicker extends UFormControlElement<string> {
|
|
|
62
63
|
placeholder?: string;
|
|
63
64
|
containerEl?: HTMLElement;
|
|
64
65
|
popoverEl?: UPopover;
|
|
66
|
+
calendarEl?: UCalendar;
|
|
65
67
|
/** Unique id wiring the combobox's `aria-controls` to the calendar dialog — mirrors USelect's `listboxId`. */
|
|
66
68
|
private readonly calendarId;
|
|
67
69
|
private open;
|
|
68
|
-
private viewDate;
|
|
69
|
-
private focusedDate;
|
|
70
70
|
/** Time-of-day for the next selection while no `value` exists yet (`mode="datetime"` only) —
|
|
71
71
|
* once `value` is set, the time input reads/writes its time portion directly instead. */
|
|
72
72
|
private pendingTime;
|
|
73
|
-
private grabFocusOnUpdate;
|
|
74
73
|
protected updated(changed: PropertyValues): void;
|
|
75
74
|
render(): import('lit-html').TemplateResult<1>;
|
|
76
75
|
private renderCalendar;
|
|
77
76
|
private renderTimeRow;
|
|
78
77
|
private renderFooter;
|
|
79
|
-
private renderDay;
|
|
80
|
-
private isOutOfRange;
|
|
81
|
-
private focusDayButton;
|
|
82
78
|
/** `timeOverride` lets a caller force the time-of-day (the "today" quick action wants
|
|
83
79
|
* "right now", overriding whatever time was previously set) — a plain day-cell click omits
|
|
84
80
|
* it, which preserves the existing time-of-day (or `pendingTime`) so switching the date
|
|
@@ -89,16 +85,15 @@ export declare class UDatePicker extends UFormControlElement<string> {
|
|
|
89
85
|
* `pendingTime` for whenever a day gets picked. Doesn't close the popover or refocus the
|
|
90
86
|
* trigger — unlike selecting a day, adjusting the time doesn't conclude the interaction. */
|
|
91
87
|
private handleTimeChange;
|
|
92
|
-
private
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
private
|
|
96
|
-
private moveFocus;
|
|
88
|
+
private handleDaySelect;
|
|
89
|
+
/** Escape inside the grid closes the calendar and returns focus to the trigger — the grid
|
|
90
|
+
* itself does not know it lives in a popover, so the picker owns this. */
|
|
91
|
+
private handleCalendarKeydown;
|
|
97
92
|
private handlePopoverShow;
|
|
98
93
|
private handlePopoverHide;
|
|
99
94
|
private handleClearClick;
|
|
100
|
-
/** "오늘" 퀵액션 — `today`
|
|
101
|
-
* `
|
|
95
|
+
/** "오늘" 퀵액션 — 달력이 이미 `data-today` 로 표시 중인 날을 실제로 선택하는 것뿐이라
|
|
96
|
+
* `selectDay`를 그대로 탄다
|
|
102
97
|
* (범위 밖이면 `selectDay`가 조용히 no-op — 클릭 불가 상태인 day 셀과 동일 규약).
|
|
103
98
|
* datetime 모드에서는 "지금"을 통째로 채우는 것이 소비자 요청의 본질
|
|
104
99
|
* 이라 시간까지 `now`로 덮어쓴다 — 평범한 day 셀 클릭과 달리 기존 시각을 보존하지 않는다. */
|
|
@@ -1,40 +1,20 @@
|
|
|
1
|
-
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.
|
|
2
|
-
import __decorate from "../../_virtual/_@oxc-project_runtime@0.
|
|
1
|
+
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorateMetadata.js";
|
|
2
|
+
import __decorate from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorate.js";
|
|
3
3
|
import { UFormControlElement } from "../UFormControlElement.js";
|
|
4
4
|
import "../button/UButton.js";
|
|
5
5
|
import "../icon/UIcon.js";
|
|
6
6
|
import { Locale } from "../../utilities/Locale.js";
|
|
7
|
-
import "
|
|
7
|
+
import { formatDate } from "../../utilities/format.js";
|
|
8
|
+
import { isOutOfRange, parseISODate, toISODate } from "../calendar/dates.js";
|
|
9
|
+
import { UCalendar } from "../calendar/UCalendar.js";
|
|
8
10
|
import "../field/UField.js";
|
|
9
11
|
import { UPopover } from "../popover/UPopover.js";
|
|
10
|
-
import {
|
|
11
|
-
import { styles } from "./UDatePicker.styles.js";
|
|
12
|
+
import { styles } from "../calendar/picker.styles.js";
|
|
13
|
+
import { styles as styles$1 } from "./UDatePicker.styles.js";
|
|
12
14
|
import { html } from "lit";
|
|
13
15
|
import { customElement, property, query, state } from "lit/decorators.js";
|
|
14
16
|
import { ifDefined } from "lit/directives/if-defined.js";
|
|
15
17
|
//#region src/components/date-picker/UDatePicker.ts
|
|
16
|
-
function parseISODate(iso) {
|
|
17
|
-
const [y, m, d] = iso.split("-").map(Number);
|
|
18
|
-
return new Date(y, m - 1, d);
|
|
19
|
-
}
|
|
20
|
-
function toISODate(date) {
|
|
21
|
-
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
|
|
22
|
-
}
|
|
23
|
-
function isSameDay(a, b) {
|
|
24
|
-
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
|
|
25
|
-
}
|
|
26
|
-
function startOfMonth(date) {
|
|
27
|
-
return new Date(date.getFullYear(), date.getMonth(), 1);
|
|
28
|
-
}
|
|
29
|
-
function addMonths(date, delta) {
|
|
30
|
-
return new Date(date.getFullYear(), date.getMonth() + delta, 1);
|
|
31
|
-
}
|
|
32
|
-
function addDays(date, delta) {
|
|
33
|
-
return new Date(date.getFullYear(), date.getMonth(), date.getDate() + delta);
|
|
34
|
-
}
|
|
35
|
-
function daysInMonth(date) {
|
|
36
|
-
return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
|
|
37
|
-
}
|
|
38
18
|
/** `±HH:mm` for the browser's local timezone at `date` (DST-aware — recomputed per date,
|
|
39
19
|
* not cached — `getTimezoneOffset()`'s sign is the inverse of the ISO-8601 offset sign). */
|
|
40
20
|
function getLocalOffset(date) {
|
|
@@ -60,27 +40,6 @@ function splitValue(value) {
|
|
|
60
40
|
time: match ? match[1] : "00:00"
|
|
61
41
|
};
|
|
62
42
|
}
|
|
63
|
-
/** Cells to render for the calendar grid — leading `null`s pad the previous month's weekday offset. */
|
|
64
|
-
function buildMonthGrid(viewDate) {
|
|
65
|
-
const startOffset = startOfMonth(viewDate).getDay();
|
|
66
|
-
const total = daysInMonth(viewDate);
|
|
67
|
-
const cells = [];
|
|
68
|
-
for (let i = 0; i < startOffset; i++) cells.push(null);
|
|
69
|
-
for (let d = 1; d <= total; d++) cells.push(new Date(viewDate.getFullYear(), viewDate.getMonth(), d));
|
|
70
|
-
return cells;
|
|
71
|
-
}
|
|
72
|
-
/** Splits the flat cell list into 7-day weeks — the `role="row"` grouping the APG grid pattern expects. */
|
|
73
|
-
function chunkWeeks(cells) {
|
|
74
|
-
const weeks = [];
|
|
75
|
-
for (let i = 0; i < cells.length; i += 7) weeks.push(cells.slice(i, i + 7));
|
|
76
|
-
return weeks;
|
|
77
|
-
}
|
|
78
|
-
/** 2023-01-01 was a Sunday — a fixed reference date that always yields Sun..Sat order regardless of today. */
|
|
79
|
-
function getWeekdayLabels(locale) {
|
|
80
|
-
const formatter = new Intl.DateTimeFormat(locale ?? Locale.get(), { weekday: "narrow" });
|
|
81
|
-
const sunday = new Date(2023, 0, 1);
|
|
82
|
-
return Array.from({ length: 7 }, (_, i) => formatter.format(addDays(sunday, i)));
|
|
83
|
-
}
|
|
84
43
|
var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
85
44
|
constructor(..._args) {
|
|
86
45
|
super(..._args);
|
|
@@ -88,10 +47,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
88
47
|
this.clearable = false;
|
|
89
48
|
this.calendarId = `u-date-picker-calendar-${Math.random().toString(36).slice(2, 8)}`;
|
|
90
49
|
this.open = false;
|
|
91
|
-
this.viewDate = startOfMonth(/* @__PURE__ */ new Date());
|
|
92
|
-
this.focusedDate = /* @__PURE__ */ new Date();
|
|
93
50
|
this.pendingTime = "00:00";
|
|
94
|
-
this.grabFocusOnUpdate = false;
|
|
95
51
|
this.handleTimeChange = (e) => {
|
|
96
52
|
const time = e.target.value || "00:00";
|
|
97
53
|
this.pendingTime = time;
|
|
@@ -101,51 +57,17 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
101
57
|
this.value = iso;
|
|
102
58
|
if (changed) this.emitChange();
|
|
103
59
|
};
|
|
104
|
-
this.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
case "ArrowLeft":
|
|
113
|
-
e.preventDefault();
|
|
114
|
-
this.moveFocus(date, -1);
|
|
115
|
-
break;
|
|
116
|
-
case "ArrowDown":
|
|
117
|
-
e.preventDefault();
|
|
118
|
-
this.moveFocus(date, 7);
|
|
119
|
-
break;
|
|
120
|
-
case "ArrowUp":
|
|
121
|
-
e.preventDefault();
|
|
122
|
-
this.moveFocus(date, -7);
|
|
123
|
-
break;
|
|
124
|
-
case "Home":
|
|
125
|
-
e.preventDefault();
|
|
126
|
-
this.moveFocus(date, -date.getDay());
|
|
127
|
-
break;
|
|
128
|
-
case "End":
|
|
129
|
-
e.preventDefault();
|
|
130
|
-
this.moveFocus(date, 6 - date.getDay());
|
|
131
|
-
break;
|
|
132
|
-
case "Enter":
|
|
133
|
-
case " ":
|
|
134
|
-
e.preventDefault();
|
|
135
|
-
this.selectDay(date);
|
|
136
|
-
break;
|
|
137
|
-
case "Escape":
|
|
138
|
-
e.preventDefault();
|
|
139
|
-
this.popoverEl?.hide();
|
|
140
|
-
this.containerEl?.focus();
|
|
141
|
-
}
|
|
60
|
+
this.handleDaySelect = (e) => {
|
|
61
|
+
this.selectDay(parseISODate(e.detail.date));
|
|
62
|
+
};
|
|
63
|
+
this.handleCalendarKeydown = (e) => {
|
|
64
|
+
if (e.key !== "Escape") return;
|
|
65
|
+
e.preventDefault();
|
|
66
|
+
this.popoverEl?.hide();
|
|
67
|
+
this.containerEl?.focus();
|
|
142
68
|
};
|
|
143
69
|
this.handlePopoverShow = () => {
|
|
144
70
|
this.open = true;
|
|
145
|
-
this.grabFocusOnUpdate = true;
|
|
146
|
-
const base = this.value ? splitValue(this.value).date : /* @__PURE__ */ new Date();
|
|
147
|
-
this.viewDate = startOfMonth(base);
|
|
148
|
-
this.focusedDate = base;
|
|
149
71
|
};
|
|
150
72
|
this.handlePopoverHide = () => {
|
|
151
73
|
this.open = false;
|
|
@@ -173,15 +95,21 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
173
95
|
};
|
|
174
96
|
}
|
|
175
97
|
static {
|
|
176
|
-
this.styles = [
|
|
98
|
+
this.styles = [
|
|
99
|
+
super.styles,
|
|
100
|
+
styles,
|
|
101
|
+
styles$1
|
|
102
|
+
];
|
|
177
103
|
}
|
|
178
104
|
updated(changed) {
|
|
179
105
|
super.updated(changed);
|
|
180
106
|
if (changed.has("value")) this.internals?.setFormValue(this.value ?? "");
|
|
181
107
|
if (changed.has("open")) this.internals?.states[this.open ? "add" : "delete"]("open");
|
|
182
|
-
if (changed.has("open") && this.open
|
|
183
|
-
|
|
184
|
-
this.
|
|
108
|
+
if (changed.has("open") && this.open) {
|
|
109
|
+
const calendar = this.calendarEl;
|
|
110
|
+
const base = this.value ? toISODate(splitValue(this.value).date) : toISODate(/* @__PURE__ */ new Date());
|
|
111
|
+
calendar?.showDate(base);
|
|
112
|
+
this.popoverEl?.updateComplete.then(() => calendar?.focusDay());
|
|
185
113
|
}
|
|
186
114
|
}
|
|
187
115
|
render() {
|
|
@@ -243,29 +171,16 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
243
171
|
`;
|
|
244
172
|
}
|
|
245
173
|
renderCalendar() {
|
|
246
|
-
const cells = buildMonthGrid(this.viewDate);
|
|
247
|
-
const monthLabel = formatDate(this.viewDate, {
|
|
248
|
-
year: "numeric",
|
|
249
|
-
month: "long"
|
|
250
|
-
});
|
|
251
|
-
const weekdayLabels = getWeekdayLabels();
|
|
252
174
|
return html`
|
|
253
175
|
<div class="calendar" part="calendar">
|
|
254
|
-
<
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
<div class="calendar-grid" part="calendar-grid" role="grid">
|
|
263
|
-
${chunkWeeks(cells).map((week) => html`
|
|
264
|
-
<div class="calendar-week" part="calendar-week" role="row">
|
|
265
|
-
${week.map((date) => date ? this.renderDay(date) : html`<span class="day-empty" role="gridcell" aria-hidden="true"></span>`)}
|
|
266
|
-
</div>
|
|
267
|
-
`)}
|
|
268
|
-
</div>
|
|
176
|
+
<u-calendar
|
|
177
|
+
exportparts="calendar-header, calendar-title, calendar-weekdays, calendar-grid, calendar-week, day"
|
|
178
|
+
.value=${this.value ? toISODate(splitValue(this.value).date) : void 0}
|
|
179
|
+
.min=${this.min}
|
|
180
|
+
.max=${this.max}
|
|
181
|
+
@day-select=${this.handleDaySelect}
|
|
182
|
+
@keydown=${this.handleCalendarKeydown}
|
|
183
|
+
></u-calendar>
|
|
269
184
|
${this.renderTimeRow()}
|
|
270
185
|
${this.renderFooter()}
|
|
271
186
|
</div>
|
|
@@ -285,7 +200,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
285
200
|
`;
|
|
286
201
|
}
|
|
287
202
|
renderFooter() {
|
|
288
|
-
const todayDisabled =
|
|
203
|
+
const todayDisabled = isOutOfRange(/* @__PURE__ */ new Date(), this.min, this.max);
|
|
289
204
|
return html`
|
|
290
205
|
<div class="calendar-footer" part="calendar-footer">
|
|
291
206
|
<u-button variant="ghost" size="sm" ?disabled=${todayDisabled} @click=${this.handleTodayClick}>${Locale.getValue("today")}</u-button>
|
|
@@ -295,42 +210,12 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
295
210
|
</div>
|
|
296
211
|
`;
|
|
297
212
|
}
|
|
298
|
-
renderDay(date) {
|
|
299
|
-
const selected = this.value ? isSameDay(date, splitValue(this.value).date) : false;
|
|
300
|
-
const focused = isSameDay(date, this.focusedDate);
|
|
301
|
-
const today = isSameDay(date, /* @__PURE__ */ new Date());
|
|
302
|
-
const outOfRange = this.isOutOfRange(date);
|
|
303
|
-
return html`
|
|
304
|
-
<button type="button" class="day" part="day"
|
|
305
|
-
role="gridcell"
|
|
306
|
-
data-iso=${toISODate(date)}
|
|
307
|
-
tabindex=${focused ? 0 : -1}
|
|
308
|
-
aria-selected=${selected}
|
|
309
|
-
aria-disabled=${outOfRange}
|
|
310
|
-
?data-today=${today}
|
|
311
|
-
@click=${() => this.selectDay(date)}
|
|
312
|
-
@keydown=${(e) => this.handleDayKeydown(e, date)}
|
|
313
|
-
@focus=${() => {
|
|
314
|
-
this.focusedDate = date;
|
|
315
|
-
}}
|
|
316
|
-
>${date.getDate()}</button>
|
|
317
|
-
`;
|
|
318
|
-
}
|
|
319
|
-
isOutOfRange(date) {
|
|
320
|
-
if (this.min && date.getTime() < parseISODate(this.min).getTime()) return true;
|
|
321
|
-
if (this.max && date.getTime() > parseISODate(this.max).getTime()) return true;
|
|
322
|
-
return false;
|
|
323
|
-
}
|
|
324
|
-
focusDayButton(date) {
|
|
325
|
-
const iso = toISODate(date);
|
|
326
|
-
this.renderRoot.querySelector(`button.day[data-iso="${iso}"]`)?.focus();
|
|
327
|
-
}
|
|
328
213
|
/** `timeOverride` lets a caller force the time-of-day (the "today" quick action wants
|
|
329
214
|
* "right now", overriding whatever time was previously set) — a plain day-cell click omits
|
|
330
215
|
* it, which preserves the existing time-of-day (or `pendingTime`) so switching the date
|
|
331
216
|
* alone doesn't clobber a time the user already picked. */
|
|
332
217
|
selectDay(date, timeOverride) {
|
|
333
|
-
if (
|
|
218
|
+
if (isOutOfRange(date, this.min, this.max)) return;
|
|
334
219
|
const time = timeOverride ?? (this.value ? splitValue(this.value).time : this.pendingTime);
|
|
335
220
|
const iso = buildValue(date, this.mode, time);
|
|
336
221
|
const changed = iso !== this.value;
|
|
@@ -340,19 +225,6 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
340
225
|
this.popoverEl?.hide();
|
|
341
226
|
this.containerEl?.focus();
|
|
342
227
|
}
|
|
343
|
-
navigateMonth(delta) {
|
|
344
|
-
this.grabFocusOnUpdate = false;
|
|
345
|
-
const next = addMonths(this.viewDate, delta);
|
|
346
|
-
this.viewDate = next;
|
|
347
|
-
const clampedDay = Math.min(this.focusedDate.getDate(), daysInMonth(next));
|
|
348
|
-
this.focusedDate = new Date(next.getFullYear(), next.getMonth(), clampedDay);
|
|
349
|
-
}
|
|
350
|
-
moveFocus(from, deltaDays) {
|
|
351
|
-
this.grabFocusOnUpdate = true;
|
|
352
|
-
const next = addDays(from, deltaDays);
|
|
353
|
-
if (next.getMonth() !== this.viewDate.getMonth() || next.getFullYear() !== this.viewDate.getFullYear()) this.viewDate = startOfMonth(next);
|
|
354
|
-
this.focusedDate = next;
|
|
355
|
-
}
|
|
356
228
|
resetValue() {
|
|
357
229
|
const hadValue = !!this.value;
|
|
358
230
|
this.value = void 0;
|
|
@@ -408,9 +280,8 @@ __decorate([property({
|
|
|
408
280
|
__decorate([property({ type: String }), __decorateMetadata("design:type", String)], UDatePicker.prototype, "placeholder", void 0);
|
|
409
281
|
__decorate([query(".container", true), __decorateMetadata("design:type", typeof HTMLElement === "undefined" ? Object : HTMLElement)], UDatePicker.prototype, "containerEl", void 0);
|
|
410
282
|
__decorate([query("u-popover", true), __decorateMetadata("design:type", typeof UPopover === "undefined" ? Object : UPopover)], UDatePicker.prototype, "popoverEl", void 0);
|
|
283
|
+
__decorate([query("u-calendar"), __decorateMetadata("design:type", typeof UCalendar === "undefined" ? Object : UCalendar)], UDatePicker.prototype, "calendarEl", void 0);
|
|
411
284
|
__decorate([state(), __decorateMetadata("design:type", Boolean)], UDatePicker.prototype, "open", void 0);
|
|
412
|
-
__decorate([state(), __decorateMetadata("design:type", typeof Date === "undefined" ? Object : Date)], UDatePicker.prototype, "viewDate", void 0);
|
|
413
|
-
__decorate([state(), __decorateMetadata("design:type", typeof Date === "undefined" ? Object : Date)], UDatePicker.prototype, "focusedDate", void 0);
|
|
414
285
|
__decorate([state(), __decorateMetadata("design:type", String)], UDatePicker.prototype, "pendingTime", void 0);
|
|
415
286
|
UDatePicker = __decorate([customElement("u-date-picker")], UDatePicker);
|
|
416
287
|
//#endregion
|