@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.
@@ -1,82 +1,83 @@
1
- import { E as k, x as d, n as r, a as w } from "./element-DJZPsA_J.js";
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 y } from "./class-map-Dw6Wrxwi.js";
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 C } from "./pkt-options-controller-CZO1nxZ8.js";
9
- import { P as S } from "./pkt-slot-controller-BPGj-LC5.js";
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 A = {
14
+ const S = {
15
15
  displayValueAs: {
16
16
  default: "label"
17
17
  }
18
18
  }, T = {
19
- props: A
19
+ props: S
20
20
  };
21
- var M = Object.defineProperty, P = Object.getOwnPropertyDescriptor, o = (e, t, i, s) => {
22
- for (var l = s > 1 ? void 0 : s ? P(t, i) : t, n = e.length - 1, a; n >= 0; n--)
23
- (a = e[n]) && (l = (s ? a(t, i, l) : a(l)) || l);
24
- return s && l && M(t, i, l), l;
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 h = class extends V {
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 C(this), this.slotController = new S(this, this.helptextSlot), this.slotController.skipOptions = !0;
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 e;
33
- if (super.connectedCallback(), document && document.body.addEventListener("click", (t) => {
34
- this._isOptionsOpen && !this.contains(t.target) && this.handleFocusOut(t);
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 t = ((e = this.options) == null ? void 0 : e.filter((i) => i.userAdded)) || [];
37
- this.options = [...t, ...JSON.parse(JSON.stringify(this.defaultOptions))], this._options = [...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 t = [];
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 || ""), t.push(s);
48
- }), t.length && (this.options = [...t], this._options = [...t]);
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(e) {
52
- var t;
53
- if (e.has("_value") && this.valueChanged(this._value, e.get("_value")), e.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()), e.has("defaultOptions") && this.defaultOptions.length) {
54
- const i = ((t = this.options) == null ? void 0 : t.filter((s) => s.userAdded)) || [];
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 (e.has("options")) {
58
- const s = this._options.filter((l) => l.userAdded).filter(
59
- (l) => !this.options.some((n) => n.value === l.value)
60
- );
61
- this._options = [...s, ...this.options], this._options.forEach((l) => {
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 n = [...this._value];
64
- this._value = [...this._value, l.value], this.valueChanged(this._value, n);
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
- e.has("_search") && this.dispatchEvent(
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(e);
75
+ ), super.updated(t);
75
76
  }
76
- attributeChangedCallback(e, t, i) {
77
- e === "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]])), e === "options" && (this._options = this.options, this._options.forEach((s) => {
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(e, t, i);
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=${y({
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() : k}
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=${y({
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>` : k}
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 e = !this.multiple, t = this._editingSingleValue ? null : this.renderValueTag(this.findValueInOptions(this._value[0])), i = R(
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 l = this.findValueInOptions(s), n = (a = this.options.find((u) => u.value === s)) == null ? void 0 : a.tagSkinColor;
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=${n || "blue-dark"}
223
+ skin=${l || "blue-dark"}
223
224
  ?closeTag=${!this.disabled}
224
225
  @close=${() => this.handleTagRemove(s)}
225
226
  >
226
- ${this.renderValueTag(l)}
227
+ ${this.renderValueTag(h)}
227
228
  </pkt-tag>
228
229
  `;
229
230
  }
230
231
  );
231
- return e ? t : i;
232
+ return t ? e : i;
232
233
  }
233
- renderValueTag(e) {
234
- if (!e) return "";
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
- >${e.prefix || ""} ${e.value}</span
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
- >${e.value}</span
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
- >${e.label || e.value}</span
248
+ >${t.label || t.value}</span
248
249
  >`;
249
250
  }
250
251
  }
251
252
  // Event handlers
252
- handleInput(e) {
253
- if (e.stopPropagation(), e.stopImmediatePropagation(), this.disabled) return;
253
+ handleInput(t) {
254
+ if (t.stopPropagation(), t.stopImmediatePropagation(), this.disabled) return;
254
255
  this.touched = !0;
255
- const t = e.target;
256
- if (this._search = t.value, this.checkForMatches(), this.typeahead)
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
- ), e.inputType !== "deleteContentBackward") {
264
+ ), t.inputType !== "deleteContentBackward") {
264
265
  const i = this._options.filter(
265
266
  (s) => {
266
- var l;
267
- return !s.selected && ((l = s.label) == null ? void 0 : l.toLowerCase().startsWith(this._search.toLowerCase()));
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 && (t.value = s.label, window.setTimeout(
273
- () => t.setSelectionRange(this._search.length, t.value.length),
273
+ s != null && s.label && (e.value = s.label, window.setTimeout(
274
+ () => e.setSelectionRange(this._search.length, e.value.length),
274
275
  0
275
- ), t.selectionDirection = "backward");
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 e = this.findValueInOptions(this._value[0]);
285
- this._editingSingleValue = !0, this.inputRef.value.value = this.displayValueAs === "label" && (e != null && e.label) ? e.label : this._value[0];
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(e) {
291
- var t, i, s, l, n;
292
- if (!this.disabled && ((i = (t = e.relatedTarget) == null ? void 0 : t.closest("pkt-combobox")) == null ? void 0 : i.id) !== this.id && ((l = (s = e.relatedTarget) == null ? void 0 : s.closest("pkt-combobox")) == null ? void 0 : l.id) !== this.id && ((n = e.target) == null ? void 0 : n.getAttribute("data-focusfix")) !== this.id && e.relatedTarget !== this.focusRef.value && e.relatedTarget !== this.inputRef.value && e.relatedTarget !== this.arrowRef.value && this._isOptionsOpen) {
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(e) {
304
- var t, i;
305
- this.disabled || (e.currentTarget && e.currentTarget !== this.arrowRef.value && ((t = this.inputRef.value) == null ? void 0 : t.type) !== "hidden" ? ((i = this.inputRef.value) == null || i.focus(), this.requestUpdate()) : this.handleArrowClick(e));
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(e) {
308
- this.disabled || (e.stopPropagation(), this.inputRef.value && this.inputRef.value.type !== "hidden" && (this.inputRef.value.focus(), this._inputFocus = !0, this.requestUpdate()));
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(e) {
311
- var t, i;
312
- this.disabled || e instanceof KeyboardEvent && e.key && e.key !== "Enter" && e.key !== " " && e.key !== "ArrowDown" || (e.stopImmediatePropagation(), e.preventDefault(), this._isOptionsOpen = !this._isOptionsOpen, this._isOptionsOpen ? (t = this.listboxRef.value) == null || t.focusFirstOrSelectedOption() : (i = this.arrowRef.value) == null || i.focus());
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(e) {
315
- this.toggleValue(e.detail);
315
+ handleOptionToggled(t) {
316
+ this.toggleValue(t.detail);
316
317
  }
317
- handleSearch(e) {
318
- e.stopPropagation(), this._search = e.detail.toLowerCase();
318
+ handleSearch(t) {
319
+ t.stopPropagation(), this._search = t.detail.toLowerCase();
319
320
  }
320
- handleInputKeydown(e) {
321
- var t, i, s;
322
- switch (e.key) {
321
+ handleInputKeydown(t) {
322
+ var e, i, s;
323
+ switch (t.key) {
323
324
  case ",":
324
- this.multiple && (e.preventDefault(), this.addValue());
325
+ this.multiple && (t.preventDefault(), this.addValue());
325
326
  break;
326
327
  case "Enter":
327
- e.preventDefault(), this.addValue();
328
+ t.preventDefault(), this.addValue();
328
329
  break;
329
330
  case "Backspace":
330
- !this._search && ((t = this.inputRef.value) == null ? void 0 : t.type) === "hidden" && this.removeLastValue(e);
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
- e.shiftKey || ((i = this.listboxRef.value) == null || i.focusFirstOrSelectedOption(), e.preventDefault());
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(), e.preventDefault();
338
+ this._isOptionsOpen = !1, (s = this.arrowRef.value) == null || s.focus(), t.preventDefault();
338
339
  break;
339
340
  }
340
341
  }
341
- handleTagRemove(e) {
342
- this.removeSelected(e);
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 n;
349
- const e = ((n = this.inputRef.value) == null ? void 0 : n.value) || this._search || "", t = e.trim().toLowerCase() || "";
350
- if (!t) {
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() === t), s = this._options.filter(
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(t)) ?? !1;
358
+ return ((u = a.label) == null ? void 0 : u.toLowerCase().includes(e)) ?? !1;
358
359
  }
359
- ), l = s.find(
360
+ ), h = s.find(
360
361
  (a) => {
361
362
  var u;
362
- return ((u = a.label) == null ? void 0 : u.toLowerCase()) === t || a.value.toLowerCase() === t;
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 || !l) && this.allowUserInput):
367
- this._addValueText = e, this._userInfoMessage = "";
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(e) {
383
- return this.options.find((t) => t.value === e || t.label === e) || null;
383
+ findValueInOptions(t) {
384
+ return this.options.find((e) => e.value === t || e.label === t) || null;
384
385
  }
385
- findIndexInOptions(e) {
386
- return this._options.findIndex((t) => t.value === e || t.label === e);
386
+ findIndexInOptions(t) {
387
+ return this._options.findIndex((e) => e.value === t || e.label === t);
387
388
  }
388
389
  isMaxItemsReached() {
389
- const e = this.maxlength !== null && this._value.length >= this.maxlength;
390
- return e ? this._maxIsReached = !0 : this._maxIsReached = !1, e;
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(e) {
393
- var $, I;
393
+ toggleValue(t) {
394
+ var O, $;
394
395
  if (this.disabled) return;
395
396
  this.touched = !0, this._userInfoMessage = "", this._addValueText = null;
396
- const t = (($ = this.findValueInOptions(e)) == null ? void 0 : $.value) || null, i = this._value.includes(e || t || ""), s = !!t, l = ((I = this._options.find((m) => m.value === e)) == null ? void 0 : I.disabled) || !1, n = !(e != null && e.trim()), a = !this.multiple, u = this.multiple, O = this.isMaxItemsReached();
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
- l || (!s && this.allowUserInput && !n ? (this.addNewUserValue(e), 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(t), p = !0) : n && a ? (this.removeAllSelected(), p = !0) : a ? (this._value[0] && this.removeSelected(this._value[0]), this.setSelected(t), p = !1, this.inputRef.value && this.inputRef.value.type !== "hidden" && (this.inputRef.value.value = "", this.inputRef.value.blur())) : u && !O ? (this.setSelected(t), p = !0) : u && O ? (this._userInfoMessage = "Maks antall valg nådd", b = !1, x = e) : (a && this.removeAllSelected(), this._userInfoMessage = "Ingen gyldig verdi valgt", b = !1, p = !0, x = e), this._isOptionsOpen = p, p || window.setTimeout(() => {
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(e) {
404
- if (!this._value.includes(e)) {
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 = e ? [...this._value, e] : this._value, this._options = this._options.map((t) => (t.value === e && (t.selected = !0), t)), this.resetComboboxInput(!0);
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(e) {
413
- if (!e) return;
414
- this._value = this._value.filter((i) => i !== e);
415
- const t = this.findValueInOptions(e);
416
- t ? (t.selected = !1, t.userAdded ? (this._options = [...this._options.filter((i) => i.value !== e)], this.options = [...this.options.filter((i) => i.value !== e)]) : this._options = [...this._options, t]) : !e && !this.multiple && (this._options = this._options.map((i) => (i.selected = !1, i)));
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((e) => e.value), this._options = this._options.map((e) => (e.selected = !0, e)), this.requestUpdate();
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((e) => (e.selected = !1, e)), this._options = this._options.filter((e) => !e.userAdded), this.requestUpdate();
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 t;
432
- const e = ((t = this.inputRef.value) == null ? void 0 : t.value.trim()) || "";
433
- this._search = e, this.toggleValue(e);
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(e) {
436
- this._value = this.multiple ? this._value.filter((t) => t !== e) : [], this.removeSelected(e);
436
+ removeValue(t) {
437
+ this._value = this.multiple ? this._value.filter((e) => e !== t) : [], this.removeSelected(t);
437
438
  }
438
- addNewUserValue(e) {
439
- if (!e || e.trim() === "") return;
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 = [e], this._isOptionsOpen = !1, this.blurInput();
442
- else if (!this.findValueInOptions(e)) {
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, e];
445
+ this._value = [...this._value, t];
445
446
  }
446
- const t = { value: e, label: e, userAdded: !0 };
447
- this.options = [t, ...this.options], this._options = [t, ...this._options], this.setSelected(e), this.requestUpdate();
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(e = !0) {
450
- if (this._addValueText = null, this.inputRef.value && this.inputRef.value.type !== "hidden" && e)
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 t = this.findValueInOptions(this._value[0]);
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" && (t != null && t.label) ? t.label : this._value[0] || "");
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(e) {
462
+ removeLastValue(t) {
462
463
  if (this._value.length === 0) return;
463
- e.preventDefault();
464
- const t = this._value[this._value.length - 1];
465
- t && this.removeSelected(t), this.isMaxItemsReached();
464
+ t.preventDefault();
465
+ const e = this._value[this._value.length - 1];
466
+ e && this.removeSelected(e), this.isMaxItemsReached();
466
467
  }
467
468
  };
468
- o([
469
+ n([
469
470
  r({ type: String, reflect: !0 })
470
- ], h.prototype, "value", 2);
471
- o([
471
+ ], o.prototype, "value", 2);
472
+ n([
472
473
  r({ type: Array })
473
- ], h.prototype, "options", 2);
474
- o([
474
+ ], o.prototype, "options", 2);
475
+ n([
475
476
  r({ type: Array })
476
- ], h.prototype, "defaultOptions", 2);
477
- o([
477
+ ], o.prototype, "defaultOptions", 2);
478
+ n([
478
479
  r({ type: Boolean })
479
- ], h.prototype, "allowUserInput", 2);
480
- o([
480
+ ], o.prototype, "allowUserInput", 2);
481
+ n([
481
482
  r({ type: Boolean })
482
- ], h.prototype, "typeahead", 2);
483
- o([
483
+ ], o.prototype, "typeahead", 2);
484
+ n([
484
485
  r({ type: Boolean })
485
- ], h.prototype, "includeSearch", 2);
486
- o([
486
+ ], o.prototype, "includeSearch", 2);
487
+ n([
487
488
  r({ type: String })
488
- ], h.prototype, "searchPlaceholder", 2);
489
- o([
489
+ ], o.prototype, "searchPlaceholder", 2);
490
+ n([
490
491
  r({ type: Boolean })
491
- ], h.prototype, "multiple", 2);
492
- o([
492
+ ], o.prototype, "multiple", 2);
493
+ n([
493
494
  r({ type: Number })
494
- ], h.prototype, "maxlength", 2);
495
- o([
495
+ ], o.prototype, "maxlength", 2);
496
+ n([
496
497
  r({ type: String })
497
- ], h.prototype, "displayValueAs", 2);
498
- o([
498
+ ], o.prototype, "displayValueAs", 2);
499
+ n([
499
500
  r({ type: String })
500
- ], h.prototype, "tagPlacement", 2);
501
- o([
501
+ ], o.prototype, "tagPlacement", 2);
502
+ n([
502
503
  c()
503
- ], h.prototype, "_options", 2);
504
- o([
504
+ ], o.prototype, "_options", 2);
505
+ n([
505
506
  c()
506
- ], h.prototype, "_isOptionsOpen", 2);
507
- o([
507
+ ], o.prototype, "_isOptionsOpen", 2);
508
+ n([
508
509
  c()
509
- ], h.prototype, "_value", 2);
510
- o([
510
+ ], o.prototype, "_value", 2);
511
+ n([
511
512
  c()
512
- ], h.prototype, "_userInfoMessage", 2);
513
- o([
513
+ ], o.prototype, "_userInfoMessage", 2);
514
+ n([
514
515
  c()
515
- ], h.prototype, "_addValueText", 2);
516
- o([
516
+ ], o.prototype, "_addValueText", 2);
517
+ n([
517
518
  c()
518
- ], h.prototype, "_maxIsReached", 2);
519
- o([
519
+ ], o.prototype, "_maxIsReached", 2);
520
+ n([
520
521
  c()
521
- ], h.prototype, "_search", 2);
522
- o([
522
+ ], o.prototype, "_search", 2);
523
+ n([
523
524
  c()
524
- ], h.prototype, "_inputFocus", 2);
525
- o([
525
+ ], o.prototype, "_inputFocus", 2);
526
+ n([
526
527
  c()
527
- ], h.prototype, "_editingSingleValue", 2);
528
- h = o([
528
+ ], o.prototype, "_editingSingleValue", 2);
529
+ o = n([
529
530
  w("pkt-combobox")
530
- ], h);
531
+ ], o);
531
532
  export {
532
- h as P
533
+ o as P
533
534
  };