@oslokommune/punkt-elements 12.2.0 → 12.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -0
- package/dist/alert.d.ts +1 -0
- package/dist/calendar.d.ts +1 -0
- package/dist/card.d.ts +1 -0
- package/dist/class-map-CA8wadiN.cjs +5 -0
- package/dist/class-map-DiT0qP3E.js +34 -0
- package/dist/component-template.d.ts +1 -0
- package/dist/converters-DNCwIFwr.js +17 -0
- package/dist/converters-DhM11VlY.cjs +1 -0
- package/dist/datepicker.d.ts +1 -0
- package/dist/directive-19_ixLKS.cjs +9 -0
- package/dist/directive-DA0-wdk7.js +38 -0
- package/dist/element.d.ts +1 -0
- package/dist/icon.d.ts +1 -0
- package/dist/index-BHzxfdBK.js +807 -0
- package/dist/index-BJ_4AGO3.cjs +23 -0
- package/dist/index-BlHnvy7v.js +82 -0
- package/dist/index-CPvZ03uX.js +577 -0
- package/dist/index-DSplpVWQ.cjs +9 -0
- package/dist/index-DkGcZra2.cjs +90 -0
- package/dist/index.d.ts +393 -3
- package/dist/input-wrapper.d.ts +1 -0
- package/dist/link.d.ts +1 -0
- package/dist/messagebox.d.ts +1 -0
- package/dist/pkt-alert.cjs +27 -0
- package/dist/pkt-alert.js +86 -0
- package/dist/pkt-calendar.cjs +1 -0
- package/dist/pkt-calendar.js +10 -0
- package/dist/pkt-card.cjs +23 -0
- package/dist/pkt-card.js +177 -0
- package/dist/pkt-component-template.cjs +29 -0
- package/dist/{pkt-el-component-template.js → pkt-component-template.js} +25 -26
- package/dist/pkt-datepicker.cjs +140 -0
- package/dist/pkt-datepicker.js +1769 -0
- package/dist/pkt-element.cjs +1 -0
- package/dist/pkt-element.js +5 -0
- package/dist/pkt-icon.cjs +1 -0
- package/dist/pkt-icon.js +6 -0
- package/dist/pkt-index.cjs +1 -0
- package/dist/pkt-index.js +20 -0
- package/dist/pkt-input-wrapper.cjs +59 -0
- package/dist/pkt-input-wrapper.js +293 -0
- package/dist/pkt-link.cjs +3 -0
- package/dist/pkt-link.js +90 -0
- package/dist/pkt-messagebox.cjs +12 -0
- package/dist/pkt-messagebox.js +62 -0
- package/dist/pkt-tag.cjs +17 -0
- package/dist/pkt-tag.js +151 -0
- package/dist/ref-Bk590hog.cjs +13 -0
- package/dist/ref-Co_S0Cgj.js +173 -0
- package/dist/state-BRgFbJX9.js +12 -0
- package/dist/state-D2tUtTi6.cjs +5 -0
- package/dist/tag.d.ts +1 -0
- package/package.json +10 -7
- package/src/components/alert/index.ts +86 -0
- package/src/components/calendar/index.ts +391 -143
- package/src/components/card/index.ts +78 -0
- package/src/components/component-template/index.ts +25 -9
- package/src/components/datepicker/index.ts +546 -0
- package/src/components/element/index.ts +181 -8
- package/src/components/icon/index.ts +44 -49
- package/src/components/index.ts +7 -1
- package/src/components/input-wrapper/index.ts +260 -0
- package/src/components/link/index.ts +51 -0
- package/src/components/messagebox/index.ts +63 -0
- package/src/components/tag/index.ts +110 -0
- package/dist/components/calendar/index.d.ts +0 -59
- package/dist/components/component-template/index.d.ts +0 -34
- package/dist/components/element/index.d.ts +0 -24
- package/dist/components/icon/index.d.ts +0 -29
- package/dist/components/index.d.ts +0 -3
- package/dist/controllers/pkt-slot-controller.d.ts +0 -11
- package/dist/converters-Bi8tmNvQ.cjs +0 -5
- package/dist/converters-DMveycvc.js +0 -100
- package/dist/directive-C7mkmyiy.js +0 -573
- package/dist/directive-DfhMJ1ie.cjs +0 -23
- package/dist/helpers/converters.d.ts +0 -3
- package/dist/index-0PZgk9Oc.js +0 -159
- package/dist/index-xoVy6sfy.cjs +0 -13
- package/dist/pkt-el-calendar.cjs +0 -60
- package/dist/pkt-el-calendar.js +0 -1496
- package/dist/pkt-el-component-template.cjs +0 -29
- package/dist/pkt-el-element.cjs +0 -1
- package/dist/pkt-el-element.js +0 -5
- package/dist/pkt-el-icon.cjs +0 -9
- package/dist/pkt-el-icon.js +0 -98
- package/dist/pkt-el-index.cjs +0 -1
- package/dist/pkt-el-index.js +0 -8
- package/dist/property-BBVRv-DT.js +0 -47
- package/dist/property-CK6SFc5B.cjs +0 -9
- package/dist/src/translations/no.json.d.ts +0 -43
|
@@ -0,0 +1,577 @@
|
|
|
1
|
+
import { P as _, k as f, D, n as h } from "./index-BHzxfdBK.js";
|
|
2
|
+
import { a as b } from "./converters-DNCwIFwr.js";
|
|
3
|
+
import { t as A } from "./directive-DA0-wdk7.js";
|
|
4
|
+
import { r as M } from "./state-BRgFbJX9.js";
|
|
5
|
+
import { R as I } from "./class-map-DiT0qP3E.js";
|
|
6
|
+
import "./index-BlHnvy7v.js";
|
|
7
|
+
function k(e) {
|
|
8
|
+
const t = Object.prototype.toString.call(e);
|
|
9
|
+
return e instanceof Date || typeof e == "object" && t === "[object Date]" ? new e.constructor(+e) : typeof e == "number" || t === "[object Number]" || typeof e == "string" || t === "[object String]" ? new Date(e) : /* @__PURE__ */ new Date(NaN);
|
|
10
|
+
}
|
|
11
|
+
function x(e, t) {
|
|
12
|
+
return e instanceof Date ? new e.constructor(t) : new Date(t);
|
|
13
|
+
}
|
|
14
|
+
const T = 6048e5, V = 864e5;
|
|
15
|
+
let E = {};
|
|
16
|
+
function O() {
|
|
17
|
+
return E;
|
|
18
|
+
}
|
|
19
|
+
function v(e, t) {
|
|
20
|
+
var p, c, u, d;
|
|
21
|
+
const s = O(), n = (t == null ? void 0 : t.weekStartsOn) ?? ((c = (p = t == null ? void 0 : t.locale) == null ? void 0 : p.options) == null ? void 0 : c.weekStartsOn) ?? s.weekStartsOn ?? ((d = (u = s.locale) == null ? void 0 : u.options) == null ? void 0 : d.weekStartsOn) ?? 0, a = k(e), o = a.getDay(), r = (o < n ? 7 : 0) + o - n;
|
|
22
|
+
return a.setDate(a.getDate() - r), a.setHours(0, 0, 0, 0), a;
|
|
23
|
+
}
|
|
24
|
+
function S(e, t) {
|
|
25
|
+
const s = k(e.start), n = k(e.end);
|
|
26
|
+
let a = +s > +n;
|
|
27
|
+
const o = a ? +s : +n, r = a ? n : s;
|
|
28
|
+
r.setHours(0, 0, 0, 0);
|
|
29
|
+
let p = 1;
|
|
30
|
+
const c = [];
|
|
31
|
+
for (; +r <= o; )
|
|
32
|
+
c.push(k(r)), r.setDate(r.getDate() + p), r.setHours(0, 0, 0, 0);
|
|
33
|
+
return a ? c.reverse() : c;
|
|
34
|
+
}
|
|
35
|
+
function R(e, t) {
|
|
36
|
+
var d, y, m, w;
|
|
37
|
+
const s = k(e), n = s.getFullYear(), a = O(), o = (t == null ? void 0 : t.firstWeekContainsDate) ?? ((y = (d = t == null ? void 0 : t.locale) == null ? void 0 : d.options) == null ? void 0 : y.firstWeekContainsDate) ?? a.firstWeekContainsDate ?? ((w = (m = a.locale) == null ? void 0 : m.options) == null ? void 0 : w.firstWeekContainsDate) ?? 1, r = x(e, 0);
|
|
38
|
+
r.setFullYear(n + 1, 0, o), r.setHours(0, 0, 0, 0);
|
|
39
|
+
const p = v(r, t), c = x(e, 0);
|
|
40
|
+
c.setFullYear(n, 0, o), c.setHours(0, 0, 0, 0);
|
|
41
|
+
const u = v(c, t);
|
|
42
|
+
return s.getTime() >= p.getTime() ? n + 1 : s.getTime() >= u.getTime() ? n : n - 1;
|
|
43
|
+
}
|
|
44
|
+
function C(e, t) {
|
|
45
|
+
var p, c, u, d;
|
|
46
|
+
const s = O(), n = (t == null ? void 0 : t.firstWeekContainsDate) ?? ((c = (p = t == null ? void 0 : t.locale) == null ? void 0 : p.options) == null ? void 0 : c.firstWeekContainsDate) ?? s.firstWeekContainsDate ?? ((d = (u = s.locale) == null ? void 0 : u.options) == null ? void 0 : d.firstWeekContainsDate) ?? 1, a = R(e, t), o = x(e, 0);
|
|
47
|
+
return o.setFullYear(a, 0, n), o.setHours(0, 0, 0, 0), v(o, t);
|
|
48
|
+
}
|
|
49
|
+
function $(e, t) {
|
|
50
|
+
const s = k(e), n = +v(s, t) - +C(s, t);
|
|
51
|
+
return Math.round(n / T) + 1;
|
|
52
|
+
}
|
|
53
|
+
function H(e) {
|
|
54
|
+
let s = k(e).getDay();
|
|
55
|
+
return s === 0 && (s = 7), s;
|
|
56
|
+
}
|
|
57
|
+
const N = "pkt-calendar", P = {
|
|
58
|
+
id: {
|
|
59
|
+
type: "string",
|
|
60
|
+
name: "ID",
|
|
61
|
+
description: "Unique identifier for the calendar"
|
|
62
|
+
},
|
|
63
|
+
currentmonth: {
|
|
64
|
+
type: "date",
|
|
65
|
+
converter: "stringToDate",
|
|
66
|
+
description: "The current month to display"
|
|
67
|
+
},
|
|
68
|
+
selected: {
|
|
69
|
+
type: "array",
|
|
70
|
+
converter: "csvToArray",
|
|
71
|
+
reflect: !0,
|
|
72
|
+
items: {
|
|
73
|
+
type: "date"
|
|
74
|
+
},
|
|
75
|
+
description: "Array of selected dates"
|
|
76
|
+
},
|
|
77
|
+
excludeweekdays: {
|
|
78
|
+
type: "array",
|
|
79
|
+
converter: "csvToArray",
|
|
80
|
+
items: {
|
|
81
|
+
type: "string"
|
|
82
|
+
},
|
|
83
|
+
description: "Array of weekdays (1-7) to exclude"
|
|
84
|
+
},
|
|
85
|
+
excludedates: {
|
|
86
|
+
type: "array",
|
|
87
|
+
converter: "stringsToDate",
|
|
88
|
+
items: {
|
|
89
|
+
type: "date"
|
|
90
|
+
},
|
|
91
|
+
description: "Array of specific dates to exclude"
|
|
92
|
+
},
|
|
93
|
+
earliest: {
|
|
94
|
+
type: "date",
|
|
95
|
+
converter: "stringToDate",
|
|
96
|
+
default: null,
|
|
97
|
+
description: "Earliest selectable date"
|
|
98
|
+
},
|
|
99
|
+
latest: {
|
|
100
|
+
type: "date",
|
|
101
|
+
converter: "stringToDate",
|
|
102
|
+
default: null,
|
|
103
|
+
description: "Latest selectable date"
|
|
104
|
+
},
|
|
105
|
+
weeknumbers: {
|
|
106
|
+
type: "boolean",
|
|
107
|
+
reflect: !0,
|
|
108
|
+
default: !1,
|
|
109
|
+
description: "Show week numbers in calendar"
|
|
110
|
+
},
|
|
111
|
+
withcontrols: {
|
|
112
|
+
type: "boolean",
|
|
113
|
+
reflect: !0,
|
|
114
|
+
default: !1,
|
|
115
|
+
description: "Show month and year navigation controls"
|
|
116
|
+
},
|
|
117
|
+
multiple: {
|
|
118
|
+
type: "boolean",
|
|
119
|
+
reflect: !0,
|
|
120
|
+
default: !1,
|
|
121
|
+
description: "Allow multiple date selection"
|
|
122
|
+
},
|
|
123
|
+
maxMultiple: {
|
|
124
|
+
type: "number",
|
|
125
|
+
default: 4,
|
|
126
|
+
description: "Maximum number of dates that can be selected"
|
|
127
|
+
},
|
|
128
|
+
range: {
|
|
129
|
+
type: "boolean",
|
|
130
|
+
reflect: !0,
|
|
131
|
+
default: !1,
|
|
132
|
+
description: "Allow date range selection"
|
|
133
|
+
}
|
|
134
|
+
}, W = {
|
|
135
|
+
"date-selected": {
|
|
136
|
+
description: "Returns ISO formatted date string"
|
|
137
|
+
}
|
|
138
|
+
}, g = {
|
|
139
|
+
name: N,
|
|
140
|
+
"css-class": "pkt-calendar",
|
|
141
|
+
props: P,
|
|
142
|
+
events: W
|
|
143
|
+
};
|
|
144
|
+
var Y = Object.defineProperty, F = Object.getOwnPropertyDescriptor, l = (e, t, s, n) => {
|
|
145
|
+
for (var a = n > 1 ? void 0 : n ? F(t, s) : t, o = e.length - 1, r; o >= 0; o--)
|
|
146
|
+
(r = e[o]) && (a = (n ? r(t, s, a) : r(a)) || a);
|
|
147
|
+
return n && a && Y(t, s, a), a;
|
|
148
|
+
};
|
|
149
|
+
let i = class extends _ {
|
|
150
|
+
/**
|
|
151
|
+
* If we are initializing props, slots and events from specs, we should do it in the constructor
|
|
152
|
+
*/
|
|
153
|
+
constructor() {
|
|
154
|
+
super(), this.multiple = g.props.multiple.default, this.maxMultiple = g.props.maxMultiple.default, this.range = g.props.range.default, this.weeknumbers = g.props.weeknumbers.default, this.withcontrols = g.props.withcontrols.default, this.focused = !1, this.selected = [], this.earliest = g.props.earliest.default, this.latest = g.props.latest.default, this.excludedates = [], this.excludeweekdays = [], this.currentmonth = /* @__PURE__ */ new Date(), this.dayStrings = this.strings.dates.daysShort, this.monthStrings = this.strings.dates.months, this.weekString = this.strings.dates.week, this.prevMonthString = this.strings.dates.prevMonth, this.nextMonthString = this.strings.dates.nextMonth, this._selected = [], this.year = 0, this.month = 0, this.week = 0, this.rangeHovered = null, this.inRange = {}, this.focusedDate = null, this.selectableDates = [];
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Runs on mount, used to set up various values and whatever you need to run
|
|
158
|
+
*/
|
|
159
|
+
connectedCallback() {
|
|
160
|
+
const e = this.currentmonth;
|
|
161
|
+
this.year = e.getFullYear(), this.month = e.getMonth(), this.week = $(new Date(this.year, this.month, 1, 12)), this.selected && this.selected.length && this.selected.forEach((t) => {
|
|
162
|
+
this._selected.push(new Date(t));
|
|
163
|
+
}), super.connectedCallback();
|
|
164
|
+
}
|
|
165
|
+
disconnectedCallback() {
|
|
166
|
+
this.removeEventListener("keydown", this.handleKeydown), super.disconnectedCallback();
|
|
167
|
+
}
|
|
168
|
+
updated(e) {
|
|
169
|
+
if (e.has("selected") && this.selected.length === 2) {
|
|
170
|
+
const t = S({
|
|
171
|
+
start: new Date(this.selected[0]),
|
|
172
|
+
end: new Date(this.selected[1])
|
|
173
|
+
});
|
|
174
|
+
if (this.inRange = {}, Array.isArray(t) && t.length) {
|
|
175
|
+
const s = {};
|
|
176
|
+
for (let n = 0; n < t.length; n++)
|
|
177
|
+
s[this.formatISODate(t[n])] = this.isInRange(t[n]);
|
|
178
|
+
this.inRange = s;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
super.updated(e);
|
|
182
|
+
}
|
|
183
|
+
firstUpdated(e) {
|
|
184
|
+
this.addEventListener("keydown", this.handleKeydown);
|
|
185
|
+
}
|
|
186
|
+
handleKeydown(e) {
|
|
187
|
+
switch (e.key) {
|
|
188
|
+
case "ArrowLeft":
|
|
189
|
+
this.handleArrowKey(e, -1);
|
|
190
|
+
break;
|
|
191
|
+
case "ArrowRight":
|
|
192
|
+
this.handleArrowKey(e, 1);
|
|
193
|
+
break;
|
|
194
|
+
case "ArrowUp":
|
|
195
|
+
this.handleArrowKey(e, -7);
|
|
196
|
+
break;
|
|
197
|
+
case "ArrowDown":
|
|
198
|
+
this.handleArrowKey(e, 7);
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
handleArrowKey(e, t) {
|
|
203
|
+
if (e.preventDefault(), !this.focusedDate) return;
|
|
204
|
+
const s = new Date(this.focusedDate);
|
|
205
|
+
let n = new Date(s.setDate(s.getDate() + t));
|
|
206
|
+
if (n) {
|
|
207
|
+
let a = this.querySelector(`div[data-date="${this.formatISODate(n)}"]`);
|
|
208
|
+
if (a instanceof HTMLDivElement) {
|
|
209
|
+
if (a.dataset.disabled) {
|
|
210
|
+
let o = new Date(s.setDate(s.getDate() + t)), r = this.querySelector(`div[data-date="${this.formatISODate(o)}"]`);
|
|
211
|
+
for (; r && r instanceof HTMLDivElement && r.dataset.disabled; )
|
|
212
|
+
o = new Date(o.setDate(o.getDate() + t)), r = this.querySelector(`div[data-date="${this.formatISODate(o)}"]`);
|
|
213
|
+
a = r;
|
|
214
|
+
}
|
|
215
|
+
a instanceof HTMLDivElement && !a.dataset.disabled && a.focus();
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Component functionality and render
|
|
221
|
+
*/
|
|
222
|
+
render() {
|
|
223
|
+
return f`
|
|
224
|
+
<div
|
|
225
|
+
class="pkt-calendar ${this.weeknumbers ? "pkt-cal-weeknumbers" : D}"
|
|
226
|
+
@focusout=${this.closeEvent}
|
|
227
|
+
@keydown=${(e) => {
|
|
228
|
+
e.key === "Escape" && (e.preventDefault(), this.close());
|
|
229
|
+
}}
|
|
230
|
+
>
|
|
231
|
+
<nav class="pkt-cal-month-nav">
|
|
232
|
+
<div
|
|
233
|
+
@click=${this.isPrevMonthAllowed() && this.prevMonth}
|
|
234
|
+
@keydown=${(e) => {
|
|
235
|
+
(e.key === "Enter" || e.key === " ") && (e.preventDefault(), this.isNextMonthAllowed() && this.prevMonth());
|
|
236
|
+
}}
|
|
237
|
+
class="pkt-btn pkt-btn--tertiary pkt-btn--small pkt-btn--icon-only"
|
|
238
|
+
.data-disabled=${this.isPrevMonthAllowed() ? D : "disabled"}
|
|
239
|
+
?aria-disabled=${!this.isPrevMonthAllowed()}
|
|
240
|
+
tabindex="0"
|
|
241
|
+
>
|
|
242
|
+
<pkt-icon class="pkt-btn__icon" name="chevron-thin-left"></pkt-icon>
|
|
243
|
+
<span class="pkt-btn__text">${this.prevMonthString}</span>
|
|
244
|
+
</div>
|
|
245
|
+
${this.renderMonthNav()}
|
|
246
|
+
<div
|
|
247
|
+
@click=${this.isNextMonthAllowed() && this.nextMonth}
|
|
248
|
+
@keydown=${(e) => {
|
|
249
|
+
(e.key === "Enter" || e.key === " ") && (e.preventDefault(), this.isNextMonthAllowed() && this.nextMonth());
|
|
250
|
+
}}
|
|
251
|
+
class="pkt-btn pkt-btn--tertiary pkt-btn--small pkt-btn--icon-only"
|
|
252
|
+
.data-disabled=${this.isNextMonthAllowed() ? D : "disabled"}
|
|
253
|
+
?aria-disabled=${!this.isNextMonthAllowed()}
|
|
254
|
+
tabindex="0"
|
|
255
|
+
>
|
|
256
|
+
<pkt-icon class="pkt-btn__icon" name="chevron-thin-right"></pkt-icon>
|
|
257
|
+
<span class="pkt-btn__text">${this.nextMonthString}</span>
|
|
258
|
+
</div>
|
|
259
|
+
</nav>
|
|
260
|
+
<table
|
|
261
|
+
class="pkt-cal-days pkt-txt-12-medium"
|
|
262
|
+
role="grid"
|
|
263
|
+
?aria-multiselectable=${this.range || this.multiple}
|
|
264
|
+
>
|
|
265
|
+
${this.renderDayNames()} ${this.renderCalendarBody()}
|
|
266
|
+
</table>
|
|
267
|
+
</div>
|
|
268
|
+
`;
|
|
269
|
+
}
|
|
270
|
+
renderDayNames() {
|
|
271
|
+
const e = [];
|
|
272
|
+
this.weeknumbers && e.push(f`<td><div>${this.weekString}<div></td>`);
|
|
273
|
+
for (let t = 0; t < this.dayStrings.length; t++)
|
|
274
|
+
e.push(f`<td><div>${this.dayStrings[t]}</div></td>`);
|
|
275
|
+
return f`<tr class="pkt-cal-week-row" role="presentation">
|
|
276
|
+
${e}
|
|
277
|
+
</tr>`;
|
|
278
|
+
}
|
|
279
|
+
renderMonthNav() {
|
|
280
|
+
let e = [];
|
|
281
|
+
return this.withcontrols ? e.push(
|
|
282
|
+
f`<div class="pkt-cal-month-picker">
|
|
283
|
+
<select
|
|
284
|
+
class="pkt-input pkt-input-compact"
|
|
285
|
+
@change=${(t) => {
|
|
286
|
+
this.changeMonth(this.year, t.target.value);
|
|
287
|
+
}}
|
|
288
|
+
>
|
|
289
|
+
${this.monthStrings.map(
|
|
290
|
+
(t, s) => f`<option value=${s} ?selected=${this.month === s}>${t}</option>`
|
|
291
|
+
)}
|
|
292
|
+
</select>
|
|
293
|
+
<input
|
|
294
|
+
class="pkt-input pkt-cal-input-year pkt-input-compact"
|
|
295
|
+
type="number"
|
|
296
|
+
size="4"
|
|
297
|
+
placeholder="0000"
|
|
298
|
+
@change=${(t) => {
|
|
299
|
+
this.changeMonth(t.target.value, this.month);
|
|
300
|
+
}}
|
|
301
|
+
value="${this.year}"
|
|
302
|
+
/>
|
|
303
|
+
</div> `
|
|
304
|
+
) : e.push(
|
|
305
|
+
f`<div class="pkt-txt-16-medium" aria-live="polite">
|
|
306
|
+
${this.monthStrings[this.month]} ${this.year}
|
|
307
|
+
</div>`
|
|
308
|
+
), e;
|
|
309
|
+
}
|
|
310
|
+
renderDayView(e, t, s) {
|
|
311
|
+
const n = new Date(this.year, this.month, e, 12), a = this.formatISODate(n), o = a === this.formatISODate(t), r = this.selected.includes(a), p = this.isExcluded(s, n) || !r && this.multiple && this.maxMultiple > 0 && this.selected.length >= this.maxMultiple, c = this.focusedDate ? this.focusedDate === a ? "0" : "-1" : e === 1 ? "0" : "-1";
|
|
312
|
+
this.selectableDates.push({ currentDateISO: a, isDisabled: p });
|
|
313
|
+
const u = {
|
|
314
|
+
"pkt-cal-today": o,
|
|
315
|
+
"pkt-cal-selected": r,
|
|
316
|
+
"pkt-cal-in-range": this.inRange[a],
|
|
317
|
+
"pkt-cal-excluded": this.isExcluded(s, n),
|
|
318
|
+
"pkt-cal-in-range-first": this.range && (this.selected.length === 2 || this.rangeHovered !== null) && a === this.selected[0],
|
|
319
|
+
"pkt-cal-in-range-last": this.range && this.selected.length === 2 && a === this.selected[1],
|
|
320
|
+
"pkt-cal-range-hover": this.rangeHovered !== null && a === this.formatISODate(this.rangeHovered)
|
|
321
|
+
};
|
|
322
|
+
return f`<td class=${I(u)}>
|
|
323
|
+
<div
|
|
324
|
+
?aria-selected=${r}
|
|
325
|
+
role="gridcell"
|
|
326
|
+
class="pkt-btn pkt-btn--tertiary pkt-btn--small pkt-btn--label-only"
|
|
327
|
+
@mouseover=${() => this.range && !this.isExcluded(s, n) && this.handleRangeHover(n)}
|
|
328
|
+
@focus=${() => {
|
|
329
|
+
this.range && !this.isExcluded(s, n) && this.handleRangeHover(n), this.focusedDate = a;
|
|
330
|
+
}}
|
|
331
|
+
tabindex=${c}
|
|
332
|
+
data-disabled=${p ? "disabled" : D}
|
|
333
|
+
data-date=${a}
|
|
334
|
+
@keydown=${(d) => {
|
|
335
|
+
(d.key === "Enter" || d.key === " ") && (d.preventDefault(), this.handleDateSelect(n));
|
|
336
|
+
}}
|
|
337
|
+
@click=${(d) => {
|
|
338
|
+
p || (d.preventDefault(), this.handleDateSelect(n));
|
|
339
|
+
}}
|
|
340
|
+
>
|
|
341
|
+
<span class="pkt-btn__text pkt-txt-14-light">${e}</span>
|
|
342
|
+
</div>
|
|
343
|
+
</td>`;
|
|
344
|
+
}
|
|
345
|
+
renderCalendarBody() {
|
|
346
|
+
const e = /* @__PURE__ */ new Date(), t = new Date(this.year, this.month, 1, 12), s = new Date(this.year, this.month + 1, 0, 12), n = (t.getDay() + 6) % 7, a = s.getDate(), o = Math.ceil((a + n) / 7), p = new Date(this.year, this.month, 0, 12).getDate();
|
|
347
|
+
let c = 1;
|
|
348
|
+
this.week = $(new Date(this.year, this.month, 1, 12));
|
|
349
|
+
const u = [];
|
|
350
|
+
for (let d = 0; d < o; d++) {
|
|
351
|
+
const y = [];
|
|
352
|
+
this.weeknumbers && y.push(f`<td class="pkt-cal-week">${this.week}</td>`), this.week++;
|
|
353
|
+
for (let m = 1; m < 8; m++)
|
|
354
|
+
if (d === 0 && m < n + 1) {
|
|
355
|
+
const w = p - (n - m - 1);
|
|
356
|
+
y.push(
|
|
357
|
+
f`<td class="pkt-cal-other">
|
|
358
|
+
<div
|
|
359
|
+
class="pkt-btn pkt-btn--tertiary pkt-btn--small pkt-btn--label-only"
|
|
360
|
+
data-disabled="disabled"
|
|
361
|
+
>
|
|
362
|
+
<span class="pkt-btn__text pkt-txt-14-light">${w}</span>
|
|
363
|
+
</div>
|
|
364
|
+
</td>`
|
|
365
|
+
);
|
|
366
|
+
} else c > a ? (y.push(
|
|
367
|
+
f`<td class="pkt-cal-other">
|
|
368
|
+
<div
|
|
369
|
+
class="pkt-btn pkt-btn--tertiary pkt-btn--small pkt-btn--label-only"
|
|
370
|
+
data-disabled="disabled"
|
|
371
|
+
>
|
|
372
|
+
<span class="pkt-btn__text pkt-txt-14-light">${c - a}</span>
|
|
373
|
+
</div>
|
|
374
|
+
</td>`
|
|
375
|
+
), c++) : (y.push(this.renderDayView(c, e, m)), c++);
|
|
376
|
+
u.push(
|
|
377
|
+
f`<tr class="pkt-cal-week-row" role="row">
|
|
378
|
+
${y}
|
|
379
|
+
</tr>`
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
return u;
|
|
383
|
+
}
|
|
384
|
+
isExcluded(e, t) {
|
|
385
|
+
return this.excludeweekdays.includes(e.toString()) || this.earliest && t < new Date(this.earliest) || this.latest && t > new Date(this.latest) ? !0 : this.excludedates.some((s) => typeof s == "string" ? s === this.formatISODate(t) : s.toDateString() === t.toDateString());
|
|
386
|
+
}
|
|
387
|
+
formatISODate(e) {
|
|
388
|
+
return e.toISOString().split("T")[0];
|
|
389
|
+
}
|
|
390
|
+
isPrevMonthAllowed() {
|
|
391
|
+
const e = new Date(this.year, this.month, 0, 12);
|
|
392
|
+
return !(this.earliest && new Date(this.earliest) > e);
|
|
393
|
+
}
|
|
394
|
+
prevMonth() {
|
|
395
|
+
const e = this.month === 0 ? 11 : this.month - 1, t = this.month === 0 ? this.year - 1 : this.year;
|
|
396
|
+
this.changeMonth(t, e);
|
|
397
|
+
}
|
|
398
|
+
isNextMonthAllowed() {
|
|
399
|
+
const e = new Date(this.year, this.month === 11 ? 0 : this.month + 1, 1, 12);
|
|
400
|
+
return !(this.latest && new Date(this.latest) < e);
|
|
401
|
+
}
|
|
402
|
+
nextMonth() {
|
|
403
|
+
const e = this.month === 11 ? 0 : this.month + 1, t = this.month === 11 ? this.year + 1 : this.year;
|
|
404
|
+
this.changeMonth(t, e);
|
|
405
|
+
}
|
|
406
|
+
changeMonth(e, t) {
|
|
407
|
+
this.year = e, this.month = t, this.selectableDates = [], this.requestUpdate("currentmonth");
|
|
408
|
+
}
|
|
409
|
+
isInRange(e) {
|
|
410
|
+
if (this.range && this.selected.length === 2) {
|
|
411
|
+
if (e > new Date(this.selected[0]) && e < new Date(this.selected[1])) return !0;
|
|
412
|
+
} else if (this.range && this.selected.length === 1 && this.rangeHovered && e > new Date(this.selected[0]) && e < this.rangeHovered)
|
|
413
|
+
return !0;
|
|
414
|
+
return !1;
|
|
415
|
+
}
|
|
416
|
+
isRangeAllowed(e) {
|
|
417
|
+
let t = !0;
|
|
418
|
+
if (this._selected.length === 1) {
|
|
419
|
+
const s = S({
|
|
420
|
+
start: this._selected[0],
|
|
421
|
+
end: e
|
|
422
|
+
});
|
|
423
|
+
if (Array.isArray(s) && s.length)
|
|
424
|
+
for (let n = 0; n < s.length; n++)
|
|
425
|
+
this.excludedates.forEach((a) => {
|
|
426
|
+
a > this._selected[0] && a < e && (t = !1);
|
|
427
|
+
}), this.excludeweekdays.includes(H(s[n]).toString()) && (t = !1);
|
|
428
|
+
}
|
|
429
|
+
return t;
|
|
430
|
+
}
|
|
431
|
+
emptySelected() {
|
|
432
|
+
this.selected = [], this._selected = [], this.inRange = {};
|
|
433
|
+
}
|
|
434
|
+
addToSelected(e) {
|
|
435
|
+
this.selected.includes(this.formatISODate(e)) || (this.selected = [...this.selected, this.formatISODate(e)], this._selected = [...this._selected, e]);
|
|
436
|
+
}
|
|
437
|
+
removeFromSelected(e) {
|
|
438
|
+
if (this.selected.length === 1)
|
|
439
|
+
this.emptySelected();
|
|
440
|
+
else {
|
|
441
|
+
const t = this.selected.indexOf(this.formatISODate(e)), s = [...this.selected], n = [...this._selected];
|
|
442
|
+
s.splice(t, 1), n.splice(t, 1), this.selected = s, this._selected = n;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
toggleSelected(e) {
|
|
446
|
+
const t = this.formatISODate(e);
|
|
447
|
+
this.selected.includes(t) ? this.removeFromSelected(e) : this.maxMultiple && this.selected.length >= this.maxMultiple || this.addToSelected(e);
|
|
448
|
+
}
|
|
449
|
+
handleRangeSelect(e) {
|
|
450
|
+
const t = this.formatISODate(e);
|
|
451
|
+
return this.selected.includes(t) ? this.selected.indexOf(t) === 0 ? this.emptySelected() : this.removeFromSelected(e) : this.selected.length > 1 ? (this.emptySelected(), this.addToSelected(e)) : (this.selected.length === 1 && !this.isRangeAllowed(e) && this.emptySelected(), this.selected.length === 1 && this._selected[0] > e && this.emptySelected(), this.addToSelected(e)), Promise.resolve();
|
|
452
|
+
}
|
|
453
|
+
handleRangeHover(e) {
|
|
454
|
+
if (this.range && this._selected.length === 1 && this.isRangeAllowed(e) && this._selected[0] < e) {
|
|
455
|
+
this.rangeHovered = e, this.inRange = {};
|
|
456
|
+
const t = S({
|
|
457
|
+
start: this._selected[0],
|
|
458
|
+
end: e
|
|
459
|
+
});
|
|
460
|
+
if (Array.isArray(t) && t.length)
|
|
461
|
+
for (let s = 0; s < t.length; s++)
|
|
462
|
+
this.inRange[this.formatISODate(t[s])] = this.isInRange(t[s]);
|
|
463
|
+
} else
|
|
464
|
+
this.rangeHovered = null;
|
|
465
|
+
}
|
|
466
|
+
handleDateSelect(e) {
|
|
467
|
+
if (e)
|
|
468
|
+
return this.range ? this.handleRangeSelect(e) : this.multiple ? this.toggleSelected(e) : (this.selected.includes(this.formatISODate(e)) ? this.emptySelected() : (this.emptySelected(), this.addToSelected(e)), this.close()), this.dispatchEvent(
|
|
469
|
+
new CustomEvent("date-selected", {
|
|
470
|
+
detail: this.selected,
|
|
471
|
+
bubbles: !0,
|
|
472
|
+
composed: !0
|
|
473
|
+
})
|
|
474
|
+
), Promise.resolve();
|
|
475
|
+
}
|
|
476
|
+
closeEvent(e) {
|
|
477
|
+
this.contains(e.relatedTarget) || this.close();
|
|
478
|
+
}
|
|
479
|
+
close() {
|
|
480
|
+
this.dispatchEvent(
|
|
481
|
+
new CustomEvent("close", {
|
|
482
|
+
detail: !0,
|
|
483
|
+
bubbles: !0,
|
|
484
|
+
composed: !0
|
|
485
|
+
})
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
l([
|
|
490
|
+
h({ type: Boolean, reflect: !0 })
|
|
491
|
+
], i.prototype, "multiple", 2);
|
|
492
|
+
l([
|
|
493
|
+
h({ type: Number })
|
|
494
|
+
], i.prototype, "maxMultiple", 2);
|
|
495
|
+
l([
|
|
496
|
+
h({ type: Boolean, reflect: !0 })
|
|
497
|
+
], i.prototype, "range", 2);
|
|
498
|
+
l([
|
|
499
|
+
h({ type: Boolean, reflect: !0 })
|
|
500
|
+
], i.prototype, "weeknumbers", 2);
|
|
501
|
+
l([
|
|
502
|
+
h({ type: Boolean, reflect: !0 })
|
|
503
|
+
], i.prototype, "withcontrols", 2);
|
|
504
|
+
l([
|
|
505
|
+
h({ type: Boolean, reflect: !0 })
|
|
506
|
+
], i.prototype, "focused", 2);
|
|
507
|
+
l([
|
|
508
|
+
h({ converter: b.csvToArray })
|
|
509
|
+
], i.prototype, "selected", 2);
|
|
510
|
+
l([
|
|
511
|
+
h({ type: String, reflect: !0 })
|
|
512
|
+
], i.prototype, "earliest", 2);
|
|
513
|
+
l([
|
|
514
|
+
h({ type: String, reflect: !0 })
|
|
515
|
+
], i.prototype, "latest", 2);
|
|
516
|
+
l([
|
|
517
|
+
h({ converter: b.stringsToDate })
|
|
518
|
+
], i.prototype, "excludedates", 2);
|
|
519
|
+
l([
|
|
520
|
+
h({ converter: b.csvToArray })
|
|
521
|
+
], i.prototype, "excludeweekdays", 2);
|
|
522
|
+
l([
|
|
523
|
+
h({ converter: b.stringToDate })
|
|
524
|
+
], i.prototype, "currentmonth", 2);
|
|
525
|
+
l([
|
|
526
|
+
h({ type: Array })
|
|
527
|
+
], i.prototype, "dayStrings", 2);
|
|
528
|
+
l([
|
|
529
|
+
h({ type: Array })
|
|
530
|
+
], i.prototype, "monthStrings", 2);
|
|
531
|
+
l([
|
|
532
|
+
h({ type: String })
|
|
533
|
+
], i.prototype, "weekString", 2);
|
|
534
|
+
l([
|
|
535
|
+
h({ type: String })
|
|
536
|
+
], i.prototype, "prevMonthString", 2);
|
|
537
|
+
l([
|
|
538
|
+
h({ type: String })
|
|
539
|
+
], i.prototype, "nextMonthString", 2);
|
|
540
|
+
l([
|
|
541
|
+
h({ type: Array })
|
|
542
|
+
], i.prototype, "_selected", 2);
|
|
543
|
+
l([
|
|
544
|
+
h({ type: Number })
|
|
545
|
+
], i.prototype, "year", 2);
|
|
546
|
+
l([
|
|
547
|
+
h({ type: Number })
|
|
548
|
+
], i.prototype, "month", 2);
|
|
549
|
+
l([
|
|
550
|
+
h({ type: Number })
|
|
551
|
+
], i.prototype, "week", 2);
|
|
552
|
+
l([
|
|
553
|
+
h({ type: Date })
|
|
554
|
+
], i.prototype, "rangeHovered", 2);
|
|
555
|
+
l([
|
|
556
|
+
M()
|
|
557
|
+
], i.prototype, "inRange", 2);
|
|
558
|
+
l([
|
|
559
|
+
M()
|
|
560
|
+
], i.prototype, "focusedDate", 2);
|
|
561
|
+
l([
|
|
562
|
+
M()
|
|
563
|
+
], i.prototype, "selectableDates", 2);
|
|
564
|
+
i = l([
|
|
565
|
+
A("pkt-calendar")
|
|
566
|
+
], i);
|
|
567
|
+
export {
|
|
568
|
+
i as P,
|
|
569
|
+
T as a,
|
|
570
|
+
$ as b,
|
|
571
|
+
x as c,
|
|
572
|
+
O as d,
|
|
573
|
+
R as g,
|
|
574
|
+
V as m,
|
|
575
|
+
v as s,
|
|
576
|
+
k as t
|
|
577
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";const o=require("./index-BJ_4AGO3.cjs"),n=require("./directive-19_ixLKS.cjs");/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2017 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
*/class a extends n.i{constructor(t){if(super(t),this.it=o.D,t.type!==n.t$1.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(t){if(t===o.D||t==null)return this._t=void 0,this.it=t;if(t===o.R)return t;if(typeof t!="string")throw Error(this.constructor.directiveName+"() called with a non-string value");if(t===this.it)return this._t;this.it=t;const r=[t];return r.raw=r,this._t={_$litType$:this.constructor.resultType,strings:r,values:[]}}}a.directiveName="unsafeHTML",a.resultType=1;const f=n.e(a);/**
|
|
6
|
+
* @license
|
|
7
|
+
* Copyright 2017 Google LLC
|
|
8
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
9
|
+
*/class d extends a{}d.directiveName="unsafeSVG",d.resultType=2;const w=n.e(d);var v=Object.defineProperty,g=Object.getOwnPropertyDescriptor,c=(e,t,r,s)=>{for(var i=s>1?void 0:s?g(t,r):t,p=e.length-1,u;p>=0;p--)(u=e[p])&&(i=(s?u(t,r,i):u(i))||i);return s&&i&&v(t,r,i),i};window.pktFetch=window.pktFetch===void 0?fetch:window.pktFetch;window.pktIconPath=window.pktIconPath||"https://punkt-cdn.oslo.kommune.no/latest/icons/";const P=e=>new Promise(t=>setTimeout(t,e)),l='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"></svg>',h={},k=async(e,t)=>{let r=0;for(;h[t+e+".svg"]==="fetching"&&(r++,!(r>50));)await P(50);return localStorage.getItem(t+e+".svg")?Promise.resolve(localStorage.getItem(t+e+".svg")):typeof window.pktFetch=="function"?(h[t+e+".svg"]="fetching",Promise.resolve(window.pktFetch(t+e+".svg").then(s=>s.ok?s.text():(console.error("Missing icon: "+t+e+".svg"),l)).then(s=>(s!==l&&localStorage.setItem(t+e+".svg",s),h[t+e+".svg"]="fetched",s)))):Promise.resolve(l)};exports.PktIcon=class extends o.PktElement{constructor(){super(),this.path=window.pktIconPath,this.name="",this.icon=w(l),this._updatedProps=[],this.classList.add("pkt-icon")}willUpdate(t){super.willUpdate(t),t.has("class")&&this.classList.add("my-element")}async attributeChangedCallback(t,r,s){super.attributeChangedCallback(t,r,s),this._updatedProps.length>0?(this.icon=w(await k(this.name||"",this.path).then(i=>i)),this._updatedProps=[]):this._updatedProps.includes(t)||this._updatedProps.push(t)}render(){return o.ke`${this.name&&this.icon}`}};c([o.n({type:String,reflect:!1})],exports.PktIcon.prototype,"path",2);c([o.n({type:String,reflect:!0})],exports.PktIcon.prototype,"name",2);c([o.n({type:SVGElement})],exports.PktIcon.prototype,"icon",2);c([o.n({type:Array,noAccessor:!0})],exports.PktIcon.prototype,"_updatedProps",2);exports.PktIcon=c([n.t("pkt-icon")],exports.PktIcon);exports.ae=f;
|