@oslokommune/punkt-elements 13.6.5 → 13.6.7
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 +34 -0
- package/dist/{calendar-ChphTIhk.js → calendar-CodWwTHM.js} +503 -471
- package/dist/calendar-DH-fCGyW.cjs +115 -0
- package/dist/{combobox-COuxR036.cjs → combobox-CNH-j9Za.cjs} +7 -7
- package/dist/{combobox-D3aPvdrE.js → combobox-C_pTRtsQ.js} +181 -180
- package/dist/datepicker-BEMo4X9s.js +770 -0
- package/dist/datepicker-n49TAIAt.cjs +169 -0
- package/dist/index.d.ts +7 -1
- package/dist/pkt-calendar.cjs +1 -1
- package/dist/pkt-calendar.js +1 -1
- package/dist/pkt-combobox.cjs +1 -1
- package/dist/pkt-combobox.js +1 -1
- package/dist/pkt-datepicker.cjs +1 -1
- package/dist/pkt-datepicker.js +1 -1
- package/dist/pkt-index.cjs +1 -1
- package/dist/pkt-index.js +4 -4
- package/package.json +2 -2
- package/src/components/calendar/calendar.ts +26 -28
- package/src/components/combobox/combobox.test.ts +22 -0
- package/src/components/combobox/combobox.ts +19 -8
- package/src/components/datepicker/date-tags.ts +2 -1
- package/src/components/datepicker/datepicker-utils.ts +475 -0
- package/src/components/datepicker/datepicker.selection.test.ts +62 -1
- package/src/components/datepicker/datepicker.ts +157 -271
- package/dist/calendar-CL9O0tLP.cjs +0 -115
- package/dist/datepicker-CV73pLqD.cjs +0 -169
- package/dist/datepicker-Ca552mbJ.js +0 -531
|
@@ -1,82 +1,83 @@
|
|
|
1
|
-
import { E as
|
|
1
|
+
import { E as I, x as d, n as r, a as w } from "./element-DJZPsA_J.js";
|
|
2
2
|
import { o as f } from "./if-defined-D3lgJqT7.js";
|
|
3
3
|
import { r as c } from "./state-CPQXJ4Ct.js";
|
|
4
4
|
import { e as _, n as v } from "./ref-BCGCor-j.js";
|
|
5
|
-
import { e as
|
|
5
|
+
import { e as k } from "./class-map-Dw6Wrxwi.js";
|
|
6
6
|
import { c as R } from "./repeat-B6qPUgAq.js";
|
|
7
7
|
import { P as V } from "./input-element-DQOVrqUZ.js";
|
|
8
|
-
import { P as
|
|
9
|
-
import { P as
|
|
8
|
+
import { P as A } from "./pkt-options-controller-CZO1nxZ8.js";
|
|
9
|
+
import { P as C } from "./pkt-slot-controller-BPGj-LC5.js";
|
|
10
10
|
import "./input-wrapper-D_JdEqcO.js";
|
|
11
11
|
import "./icon-B1-mkmwB.js";
|
|
12
12
|
import "./tag-NZ5oeGfw.js";
|
|
13
13
|
import "./listbox-DJ7b3Wmc.js";
|
|
14
|
-
const
|
|
14
|
+
const S = {
|
|
15
15
|
displayValueAs: {
|
|
16
16
|
default: "label"
|
|
17
17
|
}
|
|
18
18
|
}, T = {
|
|
19
|
-
props:
|
|
19
|
+
props: S
|
|
20
20
|
};
|
|
21
|
-
var M = Object.defineProperty,
|
|
22
|
-
for (var
|
|
23
|
-
(a =
|
|
24
|
-
return s &&
|
|
21
|
+
var M = Object.defineProperty, U = Object.getOwnPropertyDescriptor, n = (t, e, i, s) => {
|
|
22
|
+
for (var h = s > 1 ? void 0 : s ? U(e, i) : e, l = t.length - 1, a; l >= 0; l--)
|
|
23
|
+
(a = t[l]) && (h = (s ? a(e, i, h) : a(h)) || h);
|
|
24
|
+
return s && h && M(e, i, h), h;
|
|
25
25
|
};
|
|
26
|
-
let
|
|
26
|
+
let o = class extends V {
|
|
27
27
|
constructor() {
|
|
28
|
-
super(), this.helptextSlot = _(), this.value = "", this.options = [], this.defaultOptions = [], this.allowUserInput = !1, this.typeahead = !1, this.includeSearch = !1, this.searchPlaceholder = "", this.multiple = !1, this.maxlength = null, this.displayValueAs = T.props.displayValueAs.default, this.tagPlacement = null, this._options = [], this._isOptionsOpen = !1, this._value = [], this._userInfoMessage = "", this._addValueText = null, this._maxIsReached = !1, this._search = "", this._inputFocus = !1, this._editingSingleValue = !1, this.inputRef = _(), this.arrowRef = _(), this.listboxRef = _(), this.focusRef = _(), this.optionTagRef = _(), this.optionsController = new
|
|
28
|
+
super(), this.helptextSlot = _(), this.value = "", this.options = [], this.defaultOptions = [], this.allowUserInput = !1, this.typeahead = !1, this.includeSearch = !1, this.searchPlaceholder = "", this.multiple = !1, this.maxlength = null, this.displayValueAs = T.props.displayValueAs.default, this.tagPlacement = null, this._options = [], this._isOptionsOpen = !1, this._value = [], this._userInfoMessage = "", this._addValueText = null, this._maxIsReached = !1, this._search = "", this._inputFocus = !1, this._editingSingleValue = !1, this.inputRef = _(), this.arrowRef = _(), this.listboxRef = _(), this.focusRef = _(), this.optionTagRef = _(), this.optionsController = new A(this), this.slotController = new C(this, this.helptextSlot), this.slotController.skipOptions = !0;
|
|
29
29
|
}
|
|
30
30
|
// Lifecycle methods
|
|
31
31
|
connectedCallback() {
|
|
32
|
-
var
|
|
33
|
-
if (super.connectedCallback(), document && document.body.addEventListener("click", (
|
|
34
|
-
this._isOptionsOpen && !this.contains(
|
|
32
|
+
var t;
|
|
33
|
+
if (super.connectedCallback(), document && document.body.addEventListener("click", (e) => {
|
|
34
|
+
this._isOptionsOpen && !this.contains(e.target) && this.handleFocusOut(e);
|
|
35
35
|
}), this._options = [], this.defaultOptions && this.defaultOptions.length) {
|
|
36
|
-
const
|
|
37
|
-
this.options = [...
|
|
36
|
+
const e = ((t = this.options) == null ? void 0 : t.filter((i) => i.userAdded)) || [];
|
|
37
|
+
this.options = [...e, ...JSON.parse(JSON.stringify(this.defaultOptions))], this._options = Array.isArray(this.options) ? [...this.options] : [];
|
|
38
38
|
}
|
|
39
39
|
if (this.optionsController.nodes.length) {
|
|
40
|
-
const
|
|
40
|
+
const e = [];
|
|
41
41
|
this.optionsController.nodes.forEach((i) => {
|
|
42
42
|
if (!i.textContent && !i.getAttribute("value")) return null;
|
|
43
43
|
const s = {
|
|
44
44
|
value: i.getAttribute("value") || i.textContent || "",
|
|
45
45
|
label: i.textContent || i.getAttribute("value") || ""
|
|
46
46
|
};
|
|
47
|
-
i.getAttribute("data-prefix") && (s.prefix = i.getAttribute("data-prefix") || void 0), i.getAttribute("tagskincolor") && (s.tagSkinColor = i.getAttribute("tagskincolor")), i.getAttribute("description") && (s.description = i.getAttribute("description") || void 0), s.fulltext = s.value + s.label + (s.prefix || ""),
|
|
48
|
-
}),
|
|
47
|
+
i.getAttribute("data-prefix") && (s.prefix = i.getAttribute("data-prefix") || void 0), i.getAttribute("tagskincolor") && (s.tagSkinColor = i.getAttribute("tagskincolor")), i.getAttribute("description") && (s.description = i.getAttribute("description") || void 0), s.fulltext = s.value + s.label + (s.prefix || ""), e.push(s);
|
|
48
|
+
}), e.length && (this.options = [...e], this._options = [...e]);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
updated(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
this.options = [...i, ...JSON.parse(JSON.stringify(this.defaultOptions))], this._options = [...this.options];
|
|
51
|
+
updated(t) {
|
|
52
|
+
if (t.has("_value") && this.valueChanged(this._value, t.get("_value")), t.has("value") && (Array.isArray(this.value) ? this._value = this.value : this.value && this.multiple ? this._value = this.value.split(",") : this.value ? this._value = [this.value] : this._value = [], !this.multiple && this._value.length > 1 && (this._value = [this._value[0]]), this.isMaxItemsReached()), t.has("defaultOptions") && this.defaultOptions.length) {
|
|
53
|
+
const e = (Array.isArray(this.options) ? this.options : []).filter((i) => i.userAdded) || [];
|
|
54
|
+
this.options = [...e, ...JSON.parse(JSON.stringify(this.defaultOptions))], this._options = Array.isArray(this.options) ? [...this.options] : [];
|
|
56
55
|
}
|
|
57
|
-
if (
|
|
58
|
-
const s = this._options.filter((l) => l.userAdded).filter(
|
|
59
|
-
(l) => !this.options
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
if (t.has("options")) {
|
|
57
|
+
const s = (t.get("options") || this._options || []).filter((l) => l && l.userAdded).filter(
|
|
58
|
+
(l) => !(Array.isArray(this.options) ? this.options : []).some(
|
|
59
|
+
(a) => a.value === l.value
|
|
60
|
+
)
|
|
61
|
+
), h = [...s, ...this.options];
|
|
62
|
+
this._options = h, s.length > 0 && (this.options = h), this._options.forEach((l) => {
|
|
62
63
|
if (l.value && !l.label && (l.label = l.value), l.selected && !this._value.includes(l.value)) {
|
|
63
|
-
const
|
|
64
|
-
this._value = [...this._value, l.value], this.valueChanged(this._value,
|
|
64
|
+
const a = [...this._value];
|
|
65
|
+
this._value = [...this._value, l.value], this.valueChanged(this._value, a);
|
|
65
66
|
}
|
|
66
67
|
l.fulltext = l.value + l.label + (l.prefix || ""), l.selected = l.selected || this._value.includes(l.value);
|
|
67
68
|
});
|
|
68
69
|
}
|
|
69
|
-
|
|
70
|
+
t.has("_search") && this.dispatchEvent(
|
|
70
71
|
new CustomEvent("search", {
|
|
71
72
|
detail: this._search,
|
|
72
73
|
bubbles: !1
|
|
73
74
|
})
|
|
74
|
-
), super.updated(
|
|
75
|
+
), super.updated(t);
|
|
75
76
|
}
|
|
76
|
-
attributeChangedCallback(
|
|
77
|
-
|
|
77
|
+
attributeChangedCallback(t, e, i) {
|
|
78
|
+
t === "value" && (Array.isArray(this.value) ? this._value = this.value : this.value && this.multiple ? this._value = this.value.split(",") : this.value ? this._value = [this.value] : this._value = [], !this.multiple && this._value.length > 1 && (this._value = [this._value[0]])), t === "options" && (this._options = Array.isArray(this.options) ? [...this.options] : [], this._options.forEach((s) => {
|
|
78
79
|
s.value && !s.label && (s.label = s.value), s.selected && !this._value.includes(s.value) && (this._value = [...this._value, s.value]), s.fulltext = s.value + s.label + (s.prefix || "");
|
|
79
|
-
}), this._search = ""), super.attributeChangedCallback(
|
|
80
|
+
}), this._search = ""), super.attributeChangedCallback(t, e, i);
|
|
80
81
|
}
|
|
81
82
|
// Render methods
|
|
82
83
|
render() {
|
|
@@ -104,7 +105,7 @@ let h = class extends V {
|
|
|
104
105
|
<div class="pkt-contents" ${v(this.helptextSlot)} name="helptext" slot="helptext"></div>
|
|
105
106
|
<div class="pkt-combobox" @focusout=${this.handleFocusOut}>
|
|
106
107
|
<div
|
|
107
|
-
class=${
|
|
108
|
+
class=${k({
|
|
108
109
|
"pkt-combobox__input": !0,
|
|
109
110
|
"pkt-combobox__input--fullwidth": this.fullwidth,
|
|
110
111
|
"pkt-combobox__input--open": this._isOptionsOpen,
|
|
@@ -116,7 +117,7 @@ let h = class extends V {
|
|
|
116
117
|
>
|
|
117
118
|
${this.placeholder && (!this._value.length || this.multiple && this.tagPlacement == "outside") && !this._inputFocus ? d`<span class="pkt-combobox__placeholder" @click=${this.handlePlaceholderClick}
|
|
118
119
|
>${this.placeholder}</span
|
|
119
|
-
>` : this.tagPlacement !== "outside" ? this.renderSingleOrMultipleValues() :
|
|
120
|
+
>` : this.tagPlacement !== "outside" ? this.renderSingleOrMultipleValues() : I}
|
|
120
121
|
${this.renderInputField()}
|
|
121
122
|
<div
|
|
122
123
|
class="pkt-btn pkt-btn--tertiary pkt-combobox__arrow"
|
|
@@ -134,7 +135,7 @@ let h = class extends V {
|
|
|
134
135
|
tabindex="${this.disabled ? "-1" : "0"}"
|
|
135
136
|
>
|
|
136
137
|
<pkt-icon
|
|
137
|
-
class=${
|
|
138
|
+
class=${k({
|
|
138
139
|
"pkt-combobox__arrow-icon": !0,
|
|
139
140
|
"pkt-combobox__arrow-icon--open": this._isOptionsOpen
|
|
140
141
|
})}
|
|
@@ -173,7 +174,7 @@ let h = class extends V {
|
|
|
173
174
|
|
|
174
175
|
${this.tagPlacement === "outside" && this.multiple ? d`<div class="pkt-combobox__tags-outside">
|
|
175
176
|
${this.renderSingleOrMultipleValues()}
|
|
176
|
-
</div>` :
|
|
177
|
+
</div>` : I}
|
|
177
178
|
</pkt-input-wrapper>
|
|
178
179
|
`;
|
|
179
180
|
}
|
|
@@ -211,68 +212,68 @@ let h = class extends V {
|
|
|
211
212
|
`;
|
|
212
213
|
}
|
|
213
214
|
renderSingleOrMultipleValues() {
|
|
214
|
-
const
|
|
215
|
+
const t = !this.multiple, e = this._editingSingleValue ? null : this.renderValueTag(this.findValueInOptions(this._value[0])), i = R(
|
|
215
216
|
this._value,
|
|
216
217
|
(s) => s,
|
|
217
218
|
(s) => {
|
|
218
219
|
var a;
|
|
219
|
-
const
|
|
220
|
+
const h = this.findValueInOptions(s), l = (a = this.options.find((u) => u.value === s)) == null ? void 0 : a.tagSkinColor;
|
|
220
221
|
return d`
|
|
221
222
|
<pkt-tag
|
|
222
|
-
skin=${
|
|
223
|
+
skin=${l || "blue-dark"}
|
|
223
224
|
?closeTag=${!this.disabled}
|
|
224
225
|
@close=${() => this.handleTagRemove(s)}
|
|
225
226
|
>
|
|
226
|
-
${this.renderValueTag(
|
|
227
|
+
${this.renderValueTag(h)}
|
|
227
228
|
</pkt-tag>
|
|
228
229
|
`;
|
|
229
230
|
}
|
|
230
231
|
);
|
|
231
|
-
return
|
|
232
|
+
return t ? e : i;
|
|
232
233
|
}
|
|
233
|
-
renderValueTag(
|
|
234
|
-
if (!
|
|
234
|
+
renderValueTag(t) {
|
|
235
|
+
if (!t) return "";
|
|
235
236
|
switch (this.displayValueAs) {
|
|
236
237
|
case "prefixAndValue":
|
|
237
238
|
return d`<span class="pkt-combobox__value" data-focusfix=${this.id}
|
|
238
|
-
>${
|
|
239
|
+
>${t.prefix || ""} ${t.value}</span
|
|
239
240
|
>`;
|
|
240
241
|
case "value":
|
|
241
242
|
return d`<span class="pkt-combobox__value" data-focusfix=${this.id}
|
|
242
|
-
>${
|
|
243
|
+
>${t.value}</span
|
|
243
244
|
>`;
|
|
244
245
|
case "label":
|
|
245
246
|
default:
|
|
246
247
|
return d`<span class="pkt-combobox__value" data-focusfix=${this.id}
|
|
247
|
-
>${
|
|
248
|
+
>${t.label || t.value}</span
|
|
248
249
|
>`;
|
|
249
250
|
}
|
|
250
251
|
}
|
|
251
252
|
// Event handlers
|
|
252
|
-
handleInput(
|
|
253
|
-
if (
|
|
253
|
+
handleInput(t) {
|
|
254
|
+
if (t.stopPropagation(), t.stopImmediatePropagation(), this.disabled) return;
|
|
254
255
|
this.touched = !0;
|
|
255
|
-
const
|
|
256
|
-
if (this._search =
|
|
256
|
+
const e = t.target;
|
|
257
|
+
if (this._search = e.value, this.checkForMatches(), this.typeahead)
|
|
257
258
|
if (this._search) {
|
|
258
259
|
if (this._options = this.options.filter(
|
|
259
260
|
(i) => {
|
|
260
261
|
var s;
|
|
261
262
|
return (s = i.fulltext) == null ? void 0 : s.toLowerCase().includes(this._search.toLowerCase());
|
|
262
263
|
}
|
|
263
|
-
),
|
|
264
|
+
), t.inputType !== "deleteContentBackward") {
|
|
264
265
|
const i = this._options.filter(
|
|
265
266
|
(s) => {
|
|
266
|
-
var
|
|
267
|
-
return !s.selected && ((
|
|
267
|
+
var h;
|
|
268
|
+
return !s.selected && ((h = s.label) == null ? void 0 : h.toLowerCase().startsWith(this._search.toLowerCase()));
|
|
268
269
|
}
|
|
269
270
|
);
|
|
270
271
|
if (i.length > 0 && this.inputRef.value && this.inputRef.value.type !== "hidden") {
|
|
271
272
|
const s = i[0];
|
|
272
|
-
s != null && s.label && (
|
|
273
|
-
() =>
|
|
273
|
+
s != null && s.label && (e.value = s.label, window.setTimeout(
|
|
274
|
+
() => e.setSelectionRange(this._search.length, e.value.length),
|
|
274
275
|
0
|
|
275
|
-
),
|
|
276
|
+
), e.selectionDirection = "backward");
|
|
276
277
|
}
|
|
277
278
|
}
|
|
278
279
|
} else
|
|
@@ -281,15 +282,15 @@ let h = class extends V {
|
|
|
281
282
|
handleFocus() {
|
|
282
283
|
if (!this.disabled) {
|
|
283
284
|
if (!this.multiple && this._value[0] && this.inputRef.value && this.inputRef.value.type !== "hidden") {
|
|
284
|
-
const
|
|
285
|
-
this._editingSingleValue = !0, this.inputRef.value.value = this.displayValueAs === "label" && (
|
|
285
|
+
const t = this.findValueInOptions(this._value[0]);
|
|
286
|
+
this._editingSingleValue = !0, this.inputRef.value.value = this.displayValueAs === "label" && (t != null && t.label) ? t.label : this._value[0];
|
|
286
287
|
}
|
|
287
288
|
this._inputFocus = !0, this._search = "", this._options = [...this.options], this._isOptionsOpen = !0, this.onFocus(), this.requestUpdate();
|
|
288
289
|
}
|
|
289
290
|
}
|
|
290
|
-
handleFocusOut(
|
|
291
|
-
var
|
|
292
|
-
if (!this.disabled && ((i = (
|
|
291
|
+
handleFocusOut(t) {
|
|
292
|
+
var e, i, s, h, l;
|
|
293
|
+
if (!this.disabled && ((i = (e = t.relatedTarget) == null ? void 0 : e.closest("pkt-combobox")) == null ? void 0 : i.id) !== this.id && ((h = (s = t.relatedTarget) == null ? void 0 : s.closest("pkt-combobox")) == null ? void 0 : h.id) !== this.id && ((l = t.target) == null ? void 0 : l.getAttribute("data-focusfix")) !== this.id && t.relatedTarget !== this.focusRef.value && t.relatedTarget !== this.inputRef.value && t.relatedTarget !== this.arrowRef.value && this._isOptionsOpen) {
|
|
293
294
|
if (this._inputFocus = !1, this._addValueText = null, this._userInfoMessage = "", this._search = "", this.inputRef.value && this.inputRef.value.type !== "hidden" && this.inputRef.value.value !== "") {
|
|
294
295
|
const a = this.inputRef.value.value, u = this.findValueInOptions(a);
|
|
295
296
|
!this._value.includes(a) && !u ? this.allowUserInput ? this.addNewUserValue(a) : this.multiple || this.removeValue(this._value[0]) : u && !this._value.includes(u.value) && this.setSelected(u.value), this.inputRef.value.value = "";
|
|
@@ -300,71 +301,71 @@ let h = class extends V {
|
|
|
300
301
|
handleBlur() {
|
|
301
302
|
this._inputFocus = !1, this._editingSingleValue = !1, this.onBlur();
|
|
302
303
|
}
|
|
303
|
-
handleInputClick(
|
|
304
|
-
var
|
|
305
|
-
this.disabled || (
|
|
304
|
+
handleInputClick(t) {
|
|
305
|
+
var e, i;
|
|
306
|
+
this.disabled || (t.currentTarget && t.currentTarget !== this.arrowRef.value && ((e = this.inputRef.value) == null ? void 0 : e.type) !== "hidden" ? ((i = this.inputRef.value) == null || i.focus(), this.requestUpdate()) : this.handleArrowClick(t));
|
|
306
307
|
}
|
|
307
|
-
handlePlaceholderClick(
|
|
308
|
-
this.disabled || (
|
|
308
|
+
handlePlaceholderClick(t) {
|
|
309
|
+
this.disabled || (t.stopPropagation(), this.inputRef.value && this.inputRef.value.type !== "hidden" && (this.inputRef.value.focus(), this._inputFocus = !0, this.requestUpdate()));
|
|
309
310
|
}
|
|
310
|
-
handleArrowClick(
|
|
311
|
-
var
|
|
312
|
-
this.disabled ||
|
|
311
|
+
handleArrowClick(t) {
|
|
312
|
+
var e, i;
|
|
313
|
+
this.disabled || t instanceof KeyboardEvent && t.key && t.key !== "Enter" && t.key !== " " && t.key !== "ArrowDown" || (t.stopImmediatePropagation(), t.preventDefault(), this._isOptionsOpen = !this._isOptionsOpen, this._isOptionsOpen ? (e = this.listboxRef.value) == null || e.focusFirstOrSelectedOption() : (i = this.arrowRef.value) == null || i.focus());
|
|
313
314
|
}
|
|
314
|
-
handleOptionToggled(
|
|
315
|
-
this.toggleValue(
|
|
315
|
+
handleOptionToggled(t) {
|
|
316
|
+
this.toggleValue(t.detail);
|
|
316
317
|
}
|
|
317
|
-
handleSearch(
|
|
318
|
-
|
|
318
|
+
handleSearch(t) {
|
|
319
|
+
t.stopPropagation(), this._search = t.detail.toLowerCase();
|
|
319
320
|
}
|
|
320
|
-
handleInputKeydown(
|
|
321
|
-
var
|
|
322
|
-
switch (
|
|
321
|
+
handleInputKeydown(t) {
|
|
322
|
+
var e, i, s;
|
|
323
|
+
switch (t.key) {
|
|
323
324
|
case ",":
|
|
324
|
-
this.multiple && (
|
|
325
|
+
this.multiple && (t.preventDefault(), this.addValue());
|
|
325
326
|
break;
|
|
326
327
|
case "Enter":
|
|
327
|
-
|
|
328
|
+
t.preventDefault(), this.addValue();
|
|
328
329
|
break;
|
|
329
330
|
case "Backspace":
|
|
330
|
-
!this._search && ((
|
|
331
|
+
!this._search && ((e = this.inputRef.value) == null ? void 0 : e.type) === "hidden" && this.removeLastValue(t);
|
|
331
332
|
break;
|
|
332
333
|
case "Tab":
|
|
333
334
|
case "ArrowDown":
|
|
334
|
-
|
|
335
|
+
t.shiftKey || ((i = this.listboxRef.value) == null || i.focusFirstOrSelectedOption(), t.preventDefault());
|
|
335
336
|
break;
|
|
336
337
|
case "Escape":
|
|
337
|
-
this._isOptionsOpen = !1, (s = this.arrowRef.value) == null || s.focus(),
|
|
338
|
+
this._isOptionsOpen = !1, (s = this.arrowRef.value) == null || s.focus(), t.preventDefault();
|
|
338
339
|
break;
|
|
339
340
|
}
|
|
340
341
|
}
|
|
341
|
-
handleTagRemove(
|
|
342
|
-
this.removeSelected(
|
|
342
|
+
handleTagRemove(t) {
|
|
343
|
+
this.removeSelected(t);
|
|
343
344
|
}
|
|
344
345
|
blurInput() {
|
|
345
346
|
this.inputRef.value && this.inputRef.value.matches(":focus") && this.inputRef.value.blur();
|
|
346
347
|
}
|
|
347
348
|
checkForMatches() {
|
|
348
|
-
var
|
|
349
|
-
const
|
|
350
|
-
if (!
|
|
349
|
+
var l;
|
|
350
|
+
const t = ((l = this.inputRef.value) == null ? void 0 : l.value) || this._search || "", e = t.trim().toLowerCase() || "";
|
|
351
|
+
if (!e) {
|
|
351
352
|
!this.multiple && this._value[0] && this.removeValue(this._value[0]), this.resetComboboxInput(!1);
|
|
352
353
|
return;
|
|
353
354
|
}
|
|
354
|
-
const i = this._value.find((a) => a.toLowerCase() ===
|
|
355
|
+
const i = this._value.find((a) => a.toLowerCase() === e), s = this._options.filter(
|
|
355
356
|
(a) => {
|
|
356
357
|
var u;
|
|
357
|
-
return ((u = a.label) == null ? void 0 : u.toLowerCase().includes(
|
|
358
|
+
return ((u = a.label) == null ? void 0 : u.toLowerCase().includes(e)) ?? !1;
|
|
358
359
|
}
|
|
359
|
-
),
|
|
360
|
+
), h = s.find(
|
|
360
361
|
(a) => {
|
|
361
362
|
var u;
|
|
362
|
-
return ((u = a.label) == null ? void 0 : u.toLowerCase()) ===
|
|
363
|
+
return ((u = a.label) == null ? void 0 : u.toLowerCase()) === e || a.value.toLowerCase() === e;
|
|
363
364
|
}
|
|
364
365
|
);
|
|
365
366
|
switch (!0) {
|
|
366
|
-
case ((s.length === 0 || !
|
|
367
|
-
this._addValueText =
|
|
367
|
+
case ((s.length === 0 || !h) && this.allowUserInput):
|
|
368
|
+
this._addValueText = t, this._userInfoMessage = "";
|
|
368
369
|
break;
|
|
369
370
|
case (s.length === 0 && !this.allowUserInput):
|
|
370
371
|
this._addValueText = null, this._userInfoMessage = "Ingen match i søket";
|
|
@@ -379,41 +380,41 @@ let h = class extends V {
|
|
|
379
380
|
this._addValueText = null, this._userInfoMessage = "";
|
|
380
381
|
}
|
|
381
382
|
}
|
|
382
|
-
findValueInOptions(
|
|
383
|
-
return this.options.find((
|
|
383
|
+
findValueInOptions(t) {
|
|
384
|
+
return this.options.find((e) => e.value === t || e.label === t) || null;
|
|
384
385
|
}
|
|
385
|
-
findIndexInOptions(
|
|
386
|
-
return this._options.findIndex((
|
|
386
|
+
findIndexInOptions(t) {
|
|
387
|
+
return this._options.findIndex((e) => e.value === t || e.label === t);
|
|
387
388
|
}
|
|
388
389
|
isMaxItemsReached() {
|
|
389
|
-
const
|
|
390
|
-
return
|
|
390
|
+
const t = this.maxlength !== null && this._value.length >= this.maxlength;
|
|
391
|
+
return t ? this._maxIsReached = !0 : this._maxIsReached = !1, t;
|
|
391
392
|
}
|
|
392
|
-
toggleValue(
|
|
393
|
-
var
|
|
393
|
+
toggleValue(t) {
|
|
394
|
+
var O, $;
|
|
394
395
|
if (this.disabled) return;
|
|
395
396
|
this.touched = !0, this._userInfoMessage = "", this._addValueText = null;
|
|
396
|
-
const
|
|
397
|
+
const e = ((O = this.findValueInOptions(t)) == null ? void 0 : O.value) || null, i = this._value.includes(t || e || ""), s = !!e, h = (($ = this._options.find((m) => m.value === t)) == null ? void 0 : $.disabled) || !1, l = !(t != null && t.trim()), a = !this.multiple, u = this.multiple, y = this.isMaxItemsReached();
|
|
397
398
|
let p = !1, b = !0, g = "", x = "";
|
|
398
|
-
|
|
399
|
+
h || (!s && this.allowUserInput && !l ? (this.addNewUserValue(t), g = "Ny verdi lagt til", p = !u) : !s && !this.allowUserInput ? (a && this._value[0] && this.removeValue(this._value[0]), b = !1, p = !0, g = "Ingen treff i søket") : i ? (this.removeValue(e), p = !0) : l && a ? (this.removeAllSelected(), p = !0) : a ? (this._value[0] && this.removeSelected(this._value[0]), this.setSelected(e), p = !1, this.inputRef.value && this.inputRef.value.type !== "hidden" && (this.inputRef.value.value = "", this.inputRef.value.blur())) : u && !y ? (this.setSelected(e), p = !0) : u && y ? (this._userInfoMessage = "Maks antall valg nådd", b = !1, x = t) : (a && this.removeAllSelected(), this._userInfoMessage = "Ingen gyldig verdi valgt", b = !1, p = !0, x = t), this._isOptionsOpen = p, p || window.setTimeout(() => {
|
|
399
400
|
var m;
|
|
400
401
|
(m = this.focusRef.value) == null || m.focus();
|
|
401
402
|
}, 0), this._userInfoMessage = g, this._search = x || "", this.resetComboboxInput(b), u && this.isMaxItemsReached());
|
|
402
403
|
}
|
|
403
|
-
setSelected(
|
|
404
|
-
if (!this._value.includes(
|
|
404
|
+
setSelected(t) {
|
|
405
|
+
if (!this._value.includes(t)) {
|
|
405
406
|
if (this.multiple && this.isMaxItemsReached()) {
|
|
406
407
|
this._userInfoMessage = "Maks antall valg nådd";
|
|
407
408
|
return;
|
|
408
409
|
}
|
|
409
|
-
!this.multiple && this.removeAllSelected(), this._value =
|
|
410
|
+
!this.multiple && this.removeAllSelected(), this._value = t ? [...this._value, t] : this._value, this._options = this._options.map((e) => (e.value === t && (e.selected = !0), e)), this.resetComboboxInput(!0);
|
|
410
411
|
}
|
|
411
412
|
}
|
|
412
|
-
removeSelected(
|
|
413
|
-
if (!
|
|
414
|
-
this._value = this._value.filter((i) => i !==
|
|
415
|
-
const
|
|
416
|
-
|
|
413
|
+
removeSelected(t) {
|
|
414
|
+
if (!t) return;
|
|
415
|
+
this._value = this._value.filter((i) => i !== t);
|
|
416
|
+
const e = this.findValueInOptions(t);
|
|
417
|
+
e ? (e.selected = !1, e.userAdded ? (this._options = [...this._options.filter((i) => i.value !== t)], this.options = [...this.options.filter((i) => i.value !== t)]) : this._options = [...this._options, e]) : !t && !this.multiple && (this._options = this._options.map((i) => (i.selected = !1, i)));
|
|
417
418
|
}
|
|
418
419
|
addAllOptions() {
|
|
419
420
|
if (this.multiple) {
|
|
@@ -421,113 +422,113 @@ let h = class extends V {
|
|
|
421
422
|
this._userInfoMessage = "For mange valgt";
|
|
422
423
|
return;
|
|
423
424
|
}
|
|
424
|
-
this._value = this._options.map((
|
|
425
|
+
this._value = this._options.map((t) => t.value), this._options = this._options.map((t) => (t.selected = !0, t)), this.requestUpdate();
|
|
425
426
|
}
|
|
426
427
|
}
|
|
427
428
|
removeAllSelected() {
|
|
428
|
-
this._value = [], this._options = this._options.map((
|
|
429
|
+
this._value = [], this._options = this._options.map((t) => (t.selected = !1, t)), this._options = this._options.filter((t) => !t.userAdded), this.requestUpdate();
|
|
429
430
|
}
|
|
430
431
|
addValue() {
|
|
431
|
-
var
|
|
432
|
-
const
|
|
433
|
-
this._search =
|
|
432
|
+
var e;
|
|
433
|
+
const t = ((e = this.inputRef.value) == null ? void 0 : e.value.trim()) || "";
|
|
434
|
+
this._search = t, this.toggleValue(t);
|
|
434
435
|
}
|
|
435
|
-
removeValue(
|
|
436
|
-
this._value = this.multiple ? this._value.filter((
|
|
436
|
+
removeValue(t) {
|
|
437
|
+
this._value = this.multiple ? this._value.filter((e) => e !== t) : [], this.removeSelected(t);
|
|
437
438
|
}
|
|
438
|
-
addNewUserValue(
|
|
439
|
-
if (!
|
|
439
|
+
addNewUserValue(t) {
|
|
440
|
+
if (!t || t.trim() === "") return;
|
|
440
441
|
if (!this.multiple)
|
|
441
|
-
this._value[0] && this.removeSelected(this._value[0]), this._value = [
|
|
442
|
-
else if (!this.findValueInOptions(
|
|
442
|
+
this._value[0] && this.removeSelected(this._value[0]), this._value = [t], this._isOptionsOpen = !1, this.blurInput();
|
|
443
|
+
else if (!this.findValueInOptions(t)) {
|
|
443
444
|
if (this.isMaxItemsReached()) return;
|
|
444
|
-
this._value = [...this._value,
|
|
445
|
+
this._value = [...this._value, t];
|
|
445
446
|
}
|
|
446
|
-
const
|
|
447
|
-
this.options = [
|
|
447
|
+
const e = { value: t, label: t, userAdded: !0 };
|
|
448
|
+
this.options = [e, ...this.options], this._options = [e, ...this._options], this.setSelected(t), this.requestUpdate();
|
|
448
449
|
}
|
|
449
|
-
resetComboboxInput(
|
|
450
|
-
if (this._addValueText = null, this.inputRef.value && this.inputRef.value.type !== "hidden" &&
|
|
450
|
+
resetComboboxInput(t = !0) {
|
|
451
|
+
if (this._addValueText = null, this.inputRef.value && this.inputRef.value.type !== "hidden" && t)
|
|
451
452
|
if (this._search = "", this.multiple)
|
|
452
453
|
this.inputRef.value.value = "";
|
|
453
454
|
else {
|
|
454
|
-
const
|
|
455
|
+
const e = this.findValueInOptions(this._value[0]);
|
|
455
456
|
window.setTimeout(() => {
|
|
456
|
-
!this.inputRef.value || this.inputRef.value.type === "hidden" || (this.inputRef.value.value = this.displayValueAs === "label" && (
|
|
457
|
+
!this.inputRef.value || this.inputRef.value.type === "hidden" || (this.inputRef.value.value = this.displayValueAs === "label" && (e != null && e.label) ? e.label : this._value[0] || "");
|
|
457
458
|
}, 0), this._userInfoMessage = "";
|
|
458
459
|
}
|
|
459
460
|
this._options = [...this.options];
|
|
460
461
|
}
|
|
461
|
-
removeLastValue(
|
|
462
|
+
removeLastValue(t) {
|
|
462
463
|
if (this._value.length === 0) return;
|
|
463
|
-
|
|
464
|
-
const
|
|
465
|
-
|
|
464
|
+
t.preventDefault();
|
|
465
|
+
const e = this._value[this._value.length - 1];
|
|
466
|
+
e && this.removeSelected(e), this.isMaxItemsReached();
|
|
466
467
|
}
|
|
467
468
|
};
|
|
468
|
-
|
|
469
|
+
n([
|
|
469
470
|
r({ type: String, reflect: !0 })
|
|
470
|
-
],
|
|
471
|
-
|
|
471
|
+
], o.prototype, "value", 2);
|
|
472
|
+
n([
|
|
472
473
|
r({ type: Array })
|
|
473
|
-
],
|
|
474
|
-
|
|
474
|
+
], o.prototype, "options", 2);
|
|
475
|
+
n([
|
|
475
476
|
r({ type: Array })
|
|
476
|
-
],
|
|
477
|
-
|
|
477
|
+
], o.prototype, "defaultOptions", 2);
|
|
478
|
+
n([
|
|
478
479
|
r({ type: Boolean })
|
|
479
|
-
],
|
|
480
|
-
|
|
480
|
+
], o.prototype, "allowUserInput", 2);
|
|
481
|
+
n([
|
|
481
482
|
r({ type: Boolean })
|
|
482
|
-
],
|
|
483
|
-
|
|
483
|
+
], o.prototype, "typeahead", 2);
|
|
484
|
+
n([
|
|
484
485
|
r({ type: Boolean })
|
|
485
|
-
],
|
|
486
|
-
|
|
486
|
+
], o.prototype, "includeSearch", 2);
|
|
487
|
+
n([
|
|
487
488
|
r({ type: String })
|
|
488
|
-
],
|
|
489
|
-
|
|
489
|
+
], o.prototype, "searchPlaceholder", 2);
|
|
490
|
+
n([
|
|
490
491
|
r({ type: Boolean })
|
|
491
|
-
],
|
|
492
|
-
|
|
492
|
+
], o.prototype, "multiple", 2);
|
|
493
|
+
n([
|
|
493
494
|
r({ type: Number })
|
|
494
|
-
],
|
|
495
|
-
|
|
495
|
+
], o.prototype, "maxlength", 2);
|
|
496
|
+
n([
|
|
496
497
|
r({ type: String })
|
|
497
|
-
],
|
|
498
|
-
|
|
498
|
+
], o.prototype, "displayValueAs", 2);
|
|
499
|
+
n([
|
|
499
500
|
r({ type: String })
|
|
500
|
-
],
|
|
501
|
-
|
|
501
|
+
], o.prototype, "tagPlacement", 2);
|
|
502
|
+
n([
|
|
502
503
|
c()
|
|
503
|
-
],
|
|
504
|
-
|
|
504
|
+
], o.prototype, "_options", 2);
|
|
505
|
+
n([
|
|
505
506
|
c()
|
|
506
|
-
],
|
|
507
|
-
|
|
507
|
+
], o.prototype, "_isOptionsOpen", 2);
|
|
508
|
+
n([
|
|
508
509
|
c()
|
|
509
|
-
],
|
|
510
|
-
|
|
510
|
+
], o.prototype, "_value", 2);
|
|
511
|
+
n([
|
|
511
512
|
c()
|
|
512
|
-
],
|
|
513
|
-
|
|
513
|
+
], o.prototype, "_userInfoMessage", 2);
|
|
514
|
+
n([
|
|
514
515
|
c()
|
|
515
|
-
],
|
|
516
|
-
|
|
516
|
+
], o.prototype, "_addValueText", 2);
|
|
517
|
+
n([
|
|
517
518
|
c()
|
|
518
|
-
],
|
|
519
|
-
|
|
519
|
+
], o.prototype, "_maxIsReached", 2);
|
|
520
|
+
n([
|
|
520
521
|
c()
|
|
521
|
-
],
|
|
522
|
-
|
|
522
|
+
], o.prototype, "_search", 2);
|
|
523
|
+
n([
|
|
523
524
|
c()
|
|
524
|
-
],
|
|
525
|
-
|
|
525
|
+
], o.prototype, "_inputFocus", 2);
|
|
526
|
+
n([
|
|
526
527
|
c()
|
|
527
|
-
],
|
|
528
|
-
|
|
528
|
+
], o.prototype, "_editingSingleValue", 2);
|
|
529
|
+
o = n([
|
|
529
530
|
w("pkt-combobox")
|
|
530
|
-
],
|
|
531
|
+
], o);
|
|
531
532
|
export {
|
|
532
|
-
|
|
533
|
+
o as P
|
|
533
534
|
};
|