@mintplayer/web-components 1.0.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/README.md +11 -0
- package/a11y/index.mjs +58 -0
- package/a11y/src/index.d.ts +2 -0
- package/a11y/src/live-announcer.d.ts +38 -0
- package/calendar/index.mjs +365 -0
- package/calendar/src/index.d.ts +1 -0
- package/calendar/src/mp-calendar.element.d.ts +104 -0
- package/calendar/src/mp-calendar.element.template.d.ts +2 -0
- package/card/index.mjs +454 -0
- package/card/src/card-classes.d.ts +40 -0
- package/card/src/index.d.ts +13 -0
- package/card/src/mp-card-body.element.d.ts +12 -0
- package/card/src/mp-card-footer.element.d.ts +14 -0
- package/card/src/mp-card-group.element.d.ts +9 -0
- package/card/src/mp-card-header.element.d.ts +24 -0
- package/card/src/mp-card-img.element.d.ts +28 -0
- package/card/src/mp-card-link.element.d.ts +24 -0
- package/card/src/mp-card-subtitle.element.d.ts +9 -0
- package/card/src/mp-card-text.element.d.ts +9 -0
- package/card/src/mp-card-title.element.d.ts +13 -0
- package/card/src/mp-card.element.d.ts +33 -0
- package/card/src/mp-card.element.template.d.ts +2 -0
- package/card/src/types/card-header-nav-style.d.ts +1 -0
- package/card/src/types/card-image-position.d.ts +1 -0
- package/code-snippet/index.mjs +218 -0
- package/code-snippet/src/index.d.ts +1 -0
- package/code-snippet/src/mp-code-snippet.element.d.ts +47 -0
- package/custom-elements.json +1774 -0
- package/index.mjs +1 -0
- package/package.json +42 -0
- package/src/index.d.ts +16 -0
- package/src/test-setup.d.ts +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# mintplayer-web-components
|
|
2
|
+
|
|
3
|
+
This library was generated with [Nx](https://nx.dev).
|
|
4
|
+
|
|
5
|
+
## Building
|
|
6
|
+
|
|
7
|
+
Run `nx build mintplayer-web-components` to build the library.
|
|
8
|
+
|
|
9
|
+
## Running unit tests
|
|
10
|
+
|
|
11
|
+
Run `nx test mintplayer-web-components` to execute the unit tests via [Vitest](https://vitest.dev/).
|
package/a11y/index.mjs
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { html as r } from "lit";
|
|
2
|
+
import { createRef as s, ref as n } from "lit/directives/ref.js";
|
|
3
|
+
const l = "position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;";
|
|
4
|
+
class c {
|
|
5
|
+
constructor(e, t = {}) {
|
|
6
|
+
this.clearTimer = null, this.pendingMessage = null, this.regionRef = s(), this.host = e, this.politeness = t.politeness ?? "polite", this.clearAfterMs = t.clearAfterMs ?? 1500, e.addController(this);
|
|
7
|
+
}
|
|
8
|
+
hostUpdated() {
|
|
9
|
+
if (this.pendingMessage !== null && this.regionRef.value) {
|
|
10
|
+
const e = this.pendingMessage;
|
|
11
|
+
this.pendingMessage = null, this.writeMessage(e);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
hostDisconnected() {
|
|
15
|
+
this.clearTimer !== null && (clearTimeout(this.clearTimer), this.clearTimer = null);
|
|
16
|
+
}
|
|
17
|
+
announce(e) {
|
|
18
|
+
if (!e) return;
|
|
19
|
+
if (!this.regionRef.value) {
|
|
20
|
+
this.pendingMessage = e, this.host.requestUpdate();
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
this.writeMessage(e);
|
|
24
|
+
}
|
|
25
|
+
/** Returns the live-region template fragment. Call once inside the host's render(). */
|
|
26
|
+
template() {
|
|
27
|
+
const e = this.politeness === "assertive" ? "alert" : "status";
|
|
28
|
+
return r`<div
|
|
29
|
+
${n(this.regionRef)}
|
|
30
|
+
role=${e}
|
|
31
|
+
aria-live=${this.politeness}
|
|
32
|
+
aria-atomic="true"
|
|
33
|
+
style=${l}
|
|
34
|
+
></div>`;
|
|
35
|
+
}
|
|
36
|
+
writeMessage(e) {
|
|
37
|
+
const t = this.regionRef.value;
|
|
38
|
+
if (t) {
|
|
39
|
+
if (t.textContent === e) {
|
|
40
|
+
t.textContent = "", queueMicrotask(() => {
|
|
41
|
+
const i = this.regionRef.value;
|
|
42
|
+
i && (i.textContent = e), this.scheduleClear();
|
|
43
|
+
});
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
t.textContent = e, this.scheduleClear();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
scheduleClear() {
|
|
50
|
+
this.clearTimer !== null && clearTimeout(this.clearTimer), this.clearTimer = setTimeout(() => {
|
|
51
|
+
const e = this.regionRef.value;
|
|
52
|
+
e && (e.textContent = ""), this.clearTimer = null;
|
|
53
|
+
}, this.clearAfterMs);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
c as LiveAnnouncerController
|
|
58
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveControllerHost, TemplateResult } from 'lit';
|
|
2
|
+
export interface LiveAnnouncerOptions {
|
|
3
|
+
/** "polite" waits for an SR-idle moment; "assertive" interrupts. Default: "polite". */
|
|
4
|
+
politeness?: 'polite' | 'assertive';
|
|
5
|
+
/** ms after which the live region is blanked so the same message can re-announce later. Default: 1500. */
|
|
6
|
+
clearAfterMs?: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Lit reactive controller that owns a visually-hidden live region for a Lit
|
|
10
|
+
* web component. Call announce() to push a message; call template() once
|
|
11
|
+
* inside the host's render() to drop the live region into the shadow tree.
|
|
12
|
+
*
|
|
13
|
+
* Writes go directly to the rendered region's textContent (via a Lit `ref`).
|
|
14
|
+
* That keeps announce() safe to call from inside the host's `updated()`
|
|
15
|
+
* lifecycle hook — it never schedules a follow-up update, so it can't
|
|
16
|
+
* trigger Lit's "change-in-update" warning.
|
|
17
|
+
*
|
|
18
|
+
* Why a controller and not a free-floating div appended to the shadow root:
|
|
19
|
+
* Lit's render owns its render root; appending children outside the rendered
|
|
20
|
+
* subtree is fragile across re-renders. Going through the template keeps the
|
|
21
|
+
* region inside Lit's managed DOM and avoids "where did my element go" bugs.
|
|
22
|
+
*/
|
|
23
|
+
export declare class LiveAnnouncerController implements ReactiveController {
|
|
24
|
+
private host;
|
|
25
|
+
private clearTimer;
|
|
26
|
+
private pendingMessage;
|
|
27
|
+
private readonly politeness;
|
|
28
|
+
private readonly clearAfterMs;
|
|
29
|
+
private readonly regionRef;
|
|
30
|
+
constructor(host: ReactiveControllerHost, options?: LiveAnnouncerOptions);
|
|
31
|
+
hostUpdated(): void;
|
|
32
|
+
hostDisconnected(): void;
|
|
33
|
+
announce(message: string): void;
|
|
34
|
+
/** Returns the live-region template fragment. Call once inside the host's render(). */
|
|
35
|
+
template(): TemplateResult;
|
|
36
|
+
private writeMessage;
|
|
37
|
+
private scheduleClear;
|
|
38
|
+
}
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
import { html as u, unsafeCSS as b, LitElement as D, nothing as c } from "lit";
|
|
2
|
+
u`<!-- The calendar is rendered dynamically by render(). This file exists only so
|
|
3
|
+
the codegen-wc target emits a \`styles\` export from the sibling .scss; the
|
|
4
|
+
\`template\` export is intentionally unused. -->`;
|
|
5
|
+
const p = b(`:host {
|
|
6
|
+
display: inline-block;
|
|
7
|
+
box-sizing: border-box;
|
|
8
|
+
color: var(--bs-body-color);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.text-muted {
|
|
12
|
+
color: var(--bs-secondary-color) !important;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
table {
|
|
16
|
+
border-collapse: collapse;
|
|
17
|
+
border: 1px solid var(--bs-border-color);
|
|
18
|
+
background-color: var(--bs-body-bg);
|
|
19
|
+
color: var(--bs-body-color);
|
|
20
|
+
margin-bottom: 0;
|
|
21
|
+
width: auto;
|
|
22
|
+
}
|
|
23
|
+
table td, table th {
|
|
24
|
+
width: 40px;
|
|
25
|
+
height: 40px;
|
|
26
|
+
text-align: center;
|
|
27
|
+
cursor: default;
|
|
28
|
+
padding: 0;
|
|
29
|
+
}
|
|
30
|
+
table td span, table th span {
|
|
31
|
+
white-space: nowrap;
|
|
32
|
+
}
|
|
33
|
+
table td.selected {
|
|
34
|
+
background-color: var(--bs-primary);
|
|
35
|
+
color: #fff;
|
|
36
|
+
}
|
|
37
|
+
table td.cursor-pointer {
|
|
38
|
+
cursor: pointer;
|
|
39
|
+
}
|
|
40
|
+
table td:focus {
|
|
41
|
+
outline: none;
|
|
42
|
+
}
|
|
43
|
+
table td:focus-visible {
|
|
44
|
+
outline: 2px solid var(--bs-primary);
|
|
45
|
+
outline-offset: -2px;
|
|
46
|
+
}
|
|
47
|
+
table th {
|
|
48
|
+
background-color: var(--bs-tertiary-bg);
|
|
49
|
+
font-weight: bolder;
|
|
50
|
+
}
|
|
51
|
+
table tr {
|
|
52
|
+
border-top: none;
|
|
53
|
+
}
|
|
54
|
+
table tr:first-child > td {
|
|
55
|
+
border-bottom: 1px solid var(--bs-border-color);
|
|
56
|
+
}
|
|
57
|
+
table tr:nth-of-type(2) > th:not(:nth-of-type(1)) {
|
|
58
|
+
border-bottom: 1px solid var(--bs-border-color);
|
|
59
|
+
}
|
|
60
|
+
table tr:not(:nth-of-type(2)) > th:nth-of-type(1) {
|
|
61
|
+
border-right: 1px solid var(--bs-border-color);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.chevron-btn {
|
|
65
|
+
background: transparent;
|
|
66
|
+
border: 0;
|
|
67
|
+
padding: 0;
|
|
68
|
+
cursor: pointer;
|
|
69
|
+
color: inherit;
|
|
70
|
+
font: inherit;
|
|
71
|
+
width: 100%;
|
|
72
|
+
height: 100%;
|
|
73
|
+
display: inline-flex;
|
|
74
|
+
align-items: center;
|
|
75
|
+
justify-content: center;
|
|
76
|
+
}
|
|
77
|
+
.chevron-btn:focus {
|
|
78
|
+
outline: none;
|
|
79
|
+
}
|
|
80
|
+
.chevron-btn:focus-visible {
|
|
81
|
+
outline: 2px solid var(--bs-primary);
|
|
82
|
+
outline-offset: -2px;
|
|
83
|
+
}
|
|
84
|
+
.chevron-btn svg {
|
|
85
|
+
width: 16px;
|
|
86
|
+
height: 16px;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.month-label {
|
|
90
|
+
font-weight: bolder;
|
|
91
|
+
}`), m = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true"><path fill-rule="evenodd" d="M11.354 1.646a.5.5 0 0 1 0 .708L5.707 8l5.647 5.646a.5.5 0 0 1-.708.708l-6-6a.5.5 0 0 1 0-.708l6-6a.5.5 0 0 1 .708 0z"/></svg>', w = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true"><path fill-rule="evenodd" d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z"/></svg>';
|
|
92
|
+
let M = 0;
|
|
93
|
+
class y extends D {
|
|
94
|
+
constructor() {
|
|
95
|
+
super(...arguments), this.selectedDate = null, this.currentMonth = null, this.disableDateFn = null, this.min = null, this.max = null, this.firstDayOfWeek = 1, this.locale = void 0, this._focusedDate = null, this.pendingFocusMove = !1, this.instanceId = `mp-cal-${++M}`, this.monthLabelId = `${this.instanceId}-month`;
|
|
96
|
+
}
|
|
97
|
+
static {
|
|
98
|
+
this.styles = [p];
|
|
99
|
+
}
|
|
100
|
+
static {
|
|
101
|
+
this.properties = {
|
|
102
|
+
selectedDate: { attribute: !1 },
|
|
103
|
+
currentMonth: { attribute: !1 },
|
|
104
|
+
disableDateFn: { attribute: !1 },
|
|
105
|
+
min: { attribute: !1 },
|
|
106
|
+
max: { attribute: !1 },
|
|
107
|
+
firstDayOfWeek: { attribute: "first-day-of-week", type: Number, reflect: !0 },
|
|
108
|
+
locale: { attribute: "locale", type: String, reflect: !0 },
|
|
109
|
+
_focusedDate: { state: !0 }
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
connectedCallback() {
|
|
113
|
+
super.connectedCallback(), this.currentMonth === null && (this.currentMonth = /* @__PURE__ */ new Date());
|
|
114
|
+
}
|
|
115
|
+
updated(t) {
|
|
116
|
+
if (this.pendingFocusMove) {
|
|
117
|
+
this.pendingFocusMove = !1;
|
|
118
|
+
const e = this._focusedDate;
|
|
119
|
+
e && this.renderRoot.querySelector(
|
|
120
|
+
`[id="${this.cellId(e)}"]`
|
|
121
|
+
)?.focus();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
cellId(t) {
|
|
125
|
+
return `${this.instanceId}-cell-${t.getFullYear()}-${t.getMonth()}-${t.getDate()}`;
|
|
126
|
+
}
|
|
127
|
+
isSameDate(t, e) {
|
|
128
|
+
return t === null && e === null ? !0 : t === null || e === null ? !1 : t.getFullYear() === e.getFullYear() && t.getMonth() === e.getMonth() && t.getDate() === e.getDate();
|
|
129
|
+
}
|
|
130
|
+
isToday(t) {
|
|
131
|
+
return this.isSameDate(t, /* @__PURE__ */ new Date());
|
|
132
|
+
}
|
|
133
|
+
/** Disabled if out of [min, max] (date-only) or rejected by disableDateFn. */
|
|
134
|
+
isDisabled(t) {
|
|
135
|
+
return this.min && this.dateOnly(t) < this.dateOnly(this.min) || this.max && this.dateOnly(t) > this.dateOnly(this.max) ? !0 : !!this.disableDateFn && this.disableDateFn(t);
|
|
136
|
+
}
|
|
137
|
+
dateOnly(t) {
|
|
138
|
+
return new Date(t.getFullYear(), t.getMonth(), t.getDate()).getTime();
|
|
139
|
+
}
|
|
140
|
+
/** Compute the weeks rendered for the current month, honoring firstDayOfWeek. */
|
|
141
|
+
getWeeks(t) {
|
|
142
|
+
const e = new Date(t.getFullYear(), t.getMonth(), 1), n = new Date(t.getFullYear(), t.getMonth() + 1, 0), r = this.startOfWeek(e), i = this.endOfWeek(n), s = this.daysBetween(r, i) + 1, l = [];
|
|
143
|
+
for (let a = 0; a < s; a++) {
|
|
144
|
+
const h = new Date(r.getFullYear(), r.getMonth(), r.getDate() + a);
|
|
145
|
+
l.push({
|
|
146
|
+
date: h,
|
|
147
|
+
dayOfMonth: h.getDate(),
|
|
148
|
+
isInMonth: h.getFullYear() === t.getFullYear() && h.getMonth() === t.getMonth()
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
const o = [];
|
|
152
|
+
for (let a = 0; a < l.length; a += 7) {
|
|
153
|
+
const h = l.slice(a, a + 7), d = h.find((f) => f.isInMonth), g = d ? d.date : h[0].date;
|
|
154
|
+
o.push({
|
|
155
|
+
number: this.weekOfYear(g),
|
|
156
|
+
days: h
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
return o;
|
|
160
|
+
}
|
|
161
|
+
/** First day of the visible grid — Monday-on-top by default. */
|
|
162
|
+
startOfWeek(t) {
|
|
163
|
+
const n = (t.getDay() - this.firstDayOfWeek + 7) % 7;
|
|
164
|
+
return new Date(t.getFullYear(), t.getMonth(), t.getDate() - n);
|
|
165
|
+
}
|
|
166
|
+
endOfWeek(t) {
|
|
167
|
+
const e = t.getDay(), n = (this.firstDayOfWeek + 6 - e + 7) % 7;
|
|
168
|
+
return new Date(t.getFullYear(), t.getMonth(), t.getDate() + n);
|
|
169
|
+
}
|
|
170
|
+
daysBetween(t, e) {
|
|
171
|
+
return Math.floor((this.dateOnly(e) - this.dateOnly(t)) / 864e5);
|
|
172
|
+
}
|
|
173
|
+
/** ISO-8601 week-of-year. */
|
|
174
|
+
weekOfYear(t) {
|
|
175
|
+
const e = new Date(Date.UTC(t.getFullYear(), t.getMonth(), t.getDate()));
|
|
176
|
+
e.setUTCDate(e.getUTCDate() + 4 - (e.getUTCDay() || 7));
|
|
177
|
+
const n = new Date(Date.UTC(e.getUTCFullYear(), 0, 1));
|
|
178
|
+
return Math.ceil(((e.getTime() - n.getTime()) / 864e5 + 1) / 7);
|
|
179
|
+
}
|
|
180
|
+
/** Localized weekday short + long names, in the order driven by firstDayOfWeek. */
|
|
181
|
+
weekdayNames() {
|
|
182
|
+
const t = new Date(2024, 0, 7), e = [];
|
|
183
|
+
for (let n = 0; n < 7; n++) {
|
|
184
|
+
const r = new Date(t);
|
|
185
|
+
r.setDate(t.getDate() + (this.firstDayOfWeek + n) % 7), e.push({
|
|
186
|
+
short: r.toLocaleString(this.locale ?? "default", { weekday: "short" }),
|
|
187
|
+
long: r.toLocaleString(this.locale ?? "default", { weekday: "long" })
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
return e;
|
|
191
|
+
}
|
|
192
|
+
monthLabel(t) {
|
|
193
|
+
const e = t.toLocaleString(this.locale ?? "default", { month: "long" });
|
|
194
|
+
return `${e.charAt(0).toUpperCase()}${e.slice(1)} ${t.getFullYear()}`;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* The cell that should carry tabindex="0". One per month — focused, else
|
|
198
|
+
* selected, else today, else first enabled day. Mirrors APG convention.
|
|
199
|
+
*/
|
|
200
|
+
focusableDate() {
|
|
201
|
+
const t = this.currentMonth;
|
|
202
|
+
if (!t) return null;
|
|
203
|
+
const e = (o) => o.getFullYear() === t.getFullYear() && o.getMonth() === t.getMonth(), n = (o) => o && e(o) ? o : null, r = n(this._focusedDate);
|
|
204
|
+
if (r) return r;
|
|
205
|
+
const i = n(this.selectedDate);
|
|
206
|
+
if (i) return i;
|
|
207
|
+
const l = n(/* @__PURE__ */ new Date());
|
|
208
|
+
if (l) return l;
|
|
209
|
+
for (const o of this.getWeeks(t))
|
|
210
|
+
for (const a of o.days)
|
|
211
|
+
if (a && a.isInMonth && !this.isDisabled(a.date)) return a.date;
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
/* ---- Public API ---- */
|
|
215
|
+
previousMonth() {
|
|
216
|
+
this.currentMonth && this.setCurrentMonth(
|
|
217
|
+
new Date(this.currentMonth.getFullYear(), this.currentMonth.getMonth() - 1, 1)
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
nextMonth() {
|
|
221
|
+
this.currentMonth && this.setCurrentMonth(
|
|
222
|
+
new Date(this.currentMonth.getFullYear(), this.currentMonth.getMonth() + 1, 1)
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
goto(t) {
|
|
226
|
+
!t || !t.isInMonth || this.isDisabled(t.date) || (this.setSelectedDate(t.date), this._focusedDate = t.date, this.requestUpdate());
|
|
227
|
+
}
|
|
228
|
+
/* ---- Internal setters with event dispatch ---- */
|
|
229
|
+
setCurrentMonth(t) {
|
|
230
|
+
const e = this.currentMonth;
|
|
231
|
+
e && this.isSameYearMonth(e, t) || (this.currentMonth = t, this.requestUpdate(), this.dispatchEvent(
|
|
232
|
+
new CustomEvent("current-month-change", {
|
|
233
|
+
detail: new Date(t.getFullYear(), t.getMonth(), 1),
|
|
234
|
+
bubbles: !0,
|
|
235
|
+
composed: !0
|
|
236
|
+
})
|
|
237
|
+
));
|
|
238
|
+
}
|
|
239
|
+
setSelectedDate(t) {
|
|
240
|
+
this.selectedDate = t, this.requestUpdate(), this.dispatchEvent(
|
|
241
|
+
new CustomEvent("selected-date-change", {
|
|
242
|
+
detail: new Date(t.getFullYear(), t.getMonth(), t.getDate()),
|
|
243
|
+
bubbles: !0,
|
|
244
|
+
composed: !0
|
|
245
|
+
})
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
isSameYearMonth(t, e) {
|
|
249
|
+
return t.getFullYear() === e.getFullYear() && t.getMonth() === e.getMonth();
|
|
250
|
+
}
|
|
251
|
+
/* ---- Keyboard ---- */
|
|
252
|
+
onCellKeyDown(t, e) {
|
|
253
|
+
if (!e || !e.isInMonth) return;
|
|
254
|
+
const n = t.key, r = n === "ArrowLeft" || n === "ArrowRight" || n === "ArrowUp" || n === "ArrowDown" || n === "Home" || n === "End" || n === "PageUp" || n === "PageDown", i = n === "Enter" || n === " ";
|
|
255
|
+
if (!r && !i) return;
|
|
256
|
+
if (t.preventDefault(), i) {
|
|
257
|
+
this.goto(e);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const s = e.date;
|
|
261
|
+
let l = new Date(s);
|
|
262
|
+
const o = getComputedStyle(this).direction === "rtl";
|
|
263
|
+
switch (n) {
|
|
264
|
+
case "ArrowLeft":
|
|
265
|
+
l.setDate(s.getDate() + (o ? 1 : -1));
|
|
266
|
+
break;
|
|
267
|
+
case "ArrowRight":
|
|
268
|
+
l.setDate(s.getDate() + (o ? -1 : 1));
|
|
269
|
+
break;
|
|
270
|
+
case "ArrowUp":
|
|
271
|
+
l.setDate(s.getDate() - 7);
|
|
272
|
+
break;
|
|
273
|
+
case "ArrowDown":
|
|
274
|
+
l.setDate(s.getDate() + 7);
|
|
275
|
+
break;
|
|
276
|
+
case "Home": {
|
|
277
|
+
const a = (s.getDay() - this.firstDayOfWeek + 7) % 7;
|
|
278
|
+
l.setDate(s.getDate() - a);
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
case "End": {
|
|
282
|
+
const a = (this.firstDayOfWeek + 6 - s.getDay() + 7) % 7;
|
|
283
|
+
l.setDate(s.getDate() + a);
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
case "PageUp":
|
|
287
|
+
l = t.ctrlKey ? new Date(s.getFullYear() - 1, s.getMonth(), s.getDate()) : new Date(s.getFullYear(), s.getMonth() - 1, s.getDate());
|
|
288
|
+
break;
|
|
289
|
+
case "PageDown":
|
|
290
|
+
l = t.ctrlKey ? new Date(s.getFullYear() + 1, s.getMonth(), s.getDate()) : new Date(s.getFullYear(), s.getMonth() + 1, s.getDate());
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
this.moveFocusTo(l);
|
|
294
|
+
}
|
|
295
|
+
moveFocusTo(t) {
|
|
296
|
+
this.currentMonth && (this.isSameYearMonth(this.currentMonth, t) || this.setCurrentMonth(new Date(t.getFullYear(), t.getMonth(), 1)), this._focusedDate = t, this.pendingFocusMove = !0, this.requestUpdate());
|
|
297
|
+
}
|
|
298
|
+
/* ---- Render ---- */
|
|
299
|
+
render() {
|
|
300
|
+
const t = this.currentMonth ?? /* @__PURE__ */ new Date(), e = this.getWeeks(t), n = this.weekdayNames(), r = this.focusableDate();
|
|
301
|
+
return u`
|
|
302
|
+
<table role="grid" aria-labelledby="${this.monthLabelId}">
|
|
303
|
+
<tr>
|
|
304
|
+
<td>
|
|
305
|
+
<button
|
|
306
|
+
type="button"
|
|
307
|
+
class="chevron-btn"
|
|
308
|
+
aria-label="Previous month"
|
|
309
|
+
@click="${() => this.previousMonth()}"
|
|
310
|
+
.innerHTML="${m}"
|
|
311
|
+
></button>
|
|
312
|
+
</td>
|
|
313
|
+
<td colspan="6" id="${this.monthLabelId}" class="month-label" aria-live="polite">
|
|
314
|
+
${this.monthLabel(t)}
|
|
315
|
+
</td>
|
|
316
|
+
<td>
|
|
317
|
+
<button
|
|
318
|
+
type="button"
|
|
319
|
+
class="chevron-btn"
|
|
320
|
+
aria-label="Next month"
|
|
321
|
+
@click="${() => this.nextMonth()}"
|
|
322
|
+
.innerHTML="${w}"
|
|
323
|
+
></button>
|
|
324
|
+
</td>
|
|
325
|
+
</tr>
|
|
326
|
+
<tr role="row">
|
|
327
|
+
<th aria-hidden="true"></th>
|
|
328
|
+
${n.map(
|
|
329
|
+
(i) => u`<th scope="col" role="columnheader" title="${i.long}">${i.short}</th>`
|
|
330
|
+
)}
|
|
331
|
+
</tr>
|
|
332
|
+
${e.map(
|
|
333
|
+
(i) => u`
|
|
334
|
+
<tr role="row">
|
|
335
|
+
<th scope="row" role="rowheader">${i.number}</th>
|
|
336
|
+
${i.days.map((s) => this.renderCell(s, r))}
|
|
337
|
+
</tr>
|
|
338
|
+
`
|
|
339
|
+
)}
|
|
340
|
+
</table>
|
|
341
|
+
`;
|
|
342
|
+
}
|
|
343
|
+
renderCell(t, e) {
|
|
344
|
+
const n = !!t && t.isInMonth, r = !!t && this.isDisabled(t.date), i = !!t && t.isInMonth && this.isSameDate(this.selectedDate, t.date), s = !!t && t.isInMonth && this.isToday(t.date), l = !!t && t.isInMonth && this.isSameDate(e, t.date), o = [];
|
|
345
|
+
i && o.push("selected"), n && !r && o.push("cursor-pointer");
|
|
346
|
+
const a = o.length ? o.join(" ") : void 0, h = t && t.isInMonth ? this.cellId(t.date) : void 0;
|
|
347
|
+
return u`<td
|
|
348
|
+
role="gridcell"
|
|
349
|
+
id="${h ?? c}"
|
|
350
|
+
class="${a ?? c}"
|
|
351
|
+
tabindex="${n ? l ? 0 : -1 : c}"
|
|
352
|
+
aria-selected="${n ? i ? "true" : "false" : c}"
|
|
353
|
+
aria-current="${s ? "date" : c}"
|
|
354
|
+
aria-disabled="${r ? "true" : c}"
|
|
355
|
+
@click="${() => this.goto(t)}"
|
|
356
|
+
@keydown="${(d) => this.onCellKeyDown(d, t)}"
|
|
357
|
+
>
|
|
358
|
+
${n ? u`<span class="${r ? "text-muted" : ""}">${t.dayOfMonth}</span>` : c}
|
|
359
|
+
</td>`;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
typeof customElements < "u" && !customElements.get("mp-calendar") && customElements.define("mp-calendar", y);
|
|
363
|
+
export {
|
|
364
|
+
y as MpCalendarElement
|
|
365
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './mp-calendar.element';
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { LitElement, TemplateResult } from 'lit';
|
|
2
|
+
export type FirstDayOfWeek = 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
3
|
+
export interface CalendarDay {
|
|
4
|
+
date: Date;
|
|
5
|
+
dayOfMonth: number;
|
|
6
|
+
isInMonth: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface CalendarWeek {
|
|
9
|
+
number: number;
|
|
10
|
+
days: (CalendarDay | null)[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* mp-calendar — Bootstrap-styled month grid primitive.
|
|
14
|
+
*
|
|
15
|
+
* Standalone Lit element, framework-agnostic. The Angular wrapper
|
|
16
|
+
* (`bs-calendar`) is a thin shell that forwards inputs/outputs.
|
|
17
|
+
*
|
|
18
|
+
* APG Date Picker keyboard model: arrows ±1 day / ±1 week, Home/End to week
|
|
19
|
+
* edges, PageUp/Down ±1 month, Ctrl+PageUp/Down ±1 year, Enter/Space selects.
|
|
20
|
+
*
|
|
21
|
+
* Events:
|
|
22
|
+
* - `selected-date-change` fires on click + Enter/Space.
|
|
23
|
+
* - `current-month-change` fires on chevron clicks + month-crossing keys.
|
|
24
|
+
*
|
|
25
|
+
* Both bubble and compose so light-DOM Angular hosts pick them up.
|
|
26
|
+
*/
|
|
27
|
+
export declare class MpCalendarElement extends LitElement {
|
|
28
|
+
static styles: import('lit').CSSResult[];
|
|
29
|
+
static properties: {
|
|
30
|
+
selectedDate: {
|
|
31
|
+
attribute: boolean;
|
|
32
|
+
};
|
|
33
|
+
currentMonth: {
|
|
34
|
+
attribute: boolean;
|
|
35
|
+
};
|
|
36
|
+
disableDateFn: {
|
|
37
|
+
attribute: boolean;
|
|
38
|
+
};
|
|
39
|
+
min: {
|
|
40
|
+
attribute: boolean;
|
|
41
|
+
};
|
|
42
|
+
max: {
|
|
43
|
+
attribute: boolean;
|
|
44
|
+
};
|
|
45
|
+
firstDayOfWeek: {
|
|
46
|
+
attribute: string;
|
|
47
|
+
type: NumberConstructor;
|
|
48
|
+
reflect: boolean;
|
|
49
|
+
};
|
|
50
|
+
locale: {
|
|
51
|
+
attribute: string;
|
|
52
|
+
type: StringConstructor;
|
|
53
|
+
reflect: boolean;
|
|
54
|
+
};
|
|
55
|
+
_focusedDate: {
|
|
56
|
+
state: boolean;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
selectedDate: Date | null;
|
|
60
|
+
currentMonth: Date | null;
|
|
61
|
+
disableDateFn: ((date: Date) => boolean) | null;
|
|
62
|
+
min: Date | null;
|
|
63
|
+
max: Date | null;
|
|
64
|
+
firstDayOfWeek: FirstDayOfWeek;
|
|
65
|
+
locale: string | undefined;
|
|
66
|
+
private _focusedDate;
|
|
67
|
+
private pendingFocusMove;
|
|
68
|
+
private readonly instanceId;
|
|
69
|
+
private readonly monthLabelId;
|
|
70
|
+
connectedCallback(): void;
|
|
71
|
+
updated(changed: Map<string, unknown>): void;
|
|
72
|
+
cellId(date: Date): string;
|
|
73
|
+
isSameDate(a: Date | null, b: Date | null): boolean;
|
|
74
|
+
private isToday;
|
|
75
|
+
/** Disabled if out of [min, max] (date-only) or rejected by disableDateFn. */
|
|
76
|
+
private isDisabled;
|
|
77
|
+
private dateOnly;
|
|
78
|
+
/** Compute the weeks rendered for the current month, honoring firstDayOfWeek. */
|
|
79
|
+
private getWeeks;
|
|
80
|
+
/** First day of the visible grid — Monday-on-top by default. */
|
|
81
|
+
private startOfWeek;
|
|
82
|
+
private endOfWeek;
|
|
83
|
+
private daysBetween;
|
|
84
|
+
/** ISO-8601 week-of-year. */
|
|
85
|
+
private weekOfYear;
|
|
86
|
+
/** Localized weekday short + long names, in the order driven by firstDayOfWeek. */
|
|
87
|
+
private weekdayNames;
|
|
88
|
+
private monthLabel;
|
|
89
|
+
/**
|
|
90
|
+
* The cell that should carry tabindex="0". One per month — focused, else
|
|
91
|
+
* selected, else today, else first enabled day. Mirrors APG convention.
|
|
92
|
+
*/
|
|
93
|
+
private focusableDate;
|
|
94
|
+
previousMonth(): void;
|
|
95
|
+
nextMonth(): void;
|
|
96
|
+
goto(day: CalendarDay | null): void;
|
|
97
|
+
private setCurrentMonth;
|
|
98
|
+
private setSelectedDate;
|
|
99
|
+
private isSameYearMonth;
|
|
100
|
+
private onCellKeyDown;
|
|
101
|
+
private moveFocusTo;
|
|
102
|
+
protected render(): TemplateResult;
|
|
103
|
+
private renderCell;
|
|
104
|
+
}
|