@oslokommune/punkt-elements 12.41.0 → 12.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/dist/alert-BY97zZYx.cjs +32 -0
- package/dist/{alert-CoGYPbs-.js → alert-oh7nc3ip.js} +23 -20
- package/dist/combobox-CavDENt-.js +514 -0
- package/dist/{combobox-lds6Lryq.cjs → combobox-DMkMUJfx.cjs} +12 -12
- package/dist/index.d.ts +4 -0
- package/dist/pkt-alert.cjs +1 -1
- package/dist/pkt-alert.js +1 -1
- package/dist/pkt-combobox.cjs +1 -1
- package/dist/pkt-combobox.js +1 -1
- package/dist/pkt-index.cjs +1 -1
- package/dist/pkt-index.js +2 -2
- package/package.json +2 -2
- package/src/components/alert/alert.ts +3 -1
- package/src/components/combobox/combobox.ts +27 -1
- package/dist/alert-D2PhTV94.cjs +0 -32
- package/dist/combobox-Ct7-a2Vy.js +0 -495
|
@@ -1,495 +0,0 @@
|
|
|
1
|
-
import { E as y, x as d, n as r, a as k } from "./element-gAd63VwC.js";
|
|
2
|
-
import { o as f } from "./if-defined-Cj-3Kdsr.js";
|
|
3
|
-
import { r as c } from "./state-BxrO4zNJ.js";
|
|
4
|
-
import { e as _, n as v } from "./ref-DnSbnXsj.js";
|
|
5
|
-
import { e as O } from "./class-map-m7ZCZ49w.js";
|
|
6
|
-
import { c as R } from "./repeat-lUFq9w5d.js";
|
|
7
|
-
import { P as V } from "./input-element-BEvaQK4g.js";
|
|
8
|
-
import { P as C } from "./pkt-options-controller-DepYQBqb.js";
|
|
9
|
-
import { P as S } from "./pkt-slot-controller-DtDaD9q_.js";
|
|
10
|
-
import "./input-wrapper-CDgnd3WJ.js";
|
|
11
|
-
import "./icon-CO1TLSs5.js";
|
|
12
|
-
import "./tag-CX-zbR-7.js";
|
|
13
|
-
import "./listbox-DCWdrjFp.js";
|
|
14
|
-
const T = {
|
|
15
|
-
displayValueAs: {
|
|
16
|
-
default: "label"
|
|
17
|
-
}
|
|
18
|
-
}, A = {
|
|
19
|
-
props: T
|
|
20
|
-
};
|
|
21
|
-
var M = Object.defineProperty, F = Object.getOwnPropertyDescriptor, h = (e, t, s, i) => {
|
|
22
|
-
for (var n = i > 1 ? void 0 : i ? F(t, s) : t, u = e.length - 1, l; u >= 0; u--)
|
|
23
|
-
(l = e[u]) && (n = (i ? l(t, s, n) : l(n)) || n);
|
|
24
|
-
return i && n && M(t, s, n), n;
|
|
25
|
-
};
|
|
26
|
-
let a = class extends V {
|
|
27
|
-
constructor() {
|
|
28
|
-
super(), this.helptextSlot = _(), this.value = "", this.options = [], this.allowUserInput = !1, this.typeahead = !1, this.includeSearch = !1, this.searchPlaceholder = "", this.multiple = !1, this.maxlength = null, this.displayValueAs = A.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;
|
|
29
|
-
}
|
|
30
|
-
// Lifecycle methods
|
|
31
|
-
connectedCallback() {
|
|
32
|
-
if (super.connectedCallback(), document && document.body.addEventListener("click", (e) => {
|
|
33
|
-
this._isOptionsOpen && !this.contains(e.target) && this.handleFocusOut(e);
|
|
34
|
-
}), this._options = [], this.optionsController.nodes.length) {
|
|
35
|
-
const e = [];
|
|
36
|
-
this.optionsController.nodes.forEach((t) => {
|
|
37
|
-
if (!t.textContent && !t.getAttribute("value")) return null;
|
|
38
|
-
const s = {
|
|
39
|
-
value: t.getAttribute("value") || t.textContent || "",
|
|
40
|
-
label: t.textContent || t.getAttribute("value") || ""
|
|
41
|
-
};
|
|
42
|
-
t.getAttribute("data-prefix") && (s.prefix = t.getAttribute("data-prefix") || void 0), t.getAttribute("tagskincolor") && (s.tagSkinColor = t.getAttribute("tagskincolor")), t.getAttribute("description") && (s.description = t.getAttribute("description") || void 0), s.fulltext = s.value + s.label + (s.prefix || ""), e.push(s);
|
|
43
|
-
}), e.length && (this.options = [...e], this._options = [...e]);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
updated(e) {
|
|
47
|
-
e.has("_value") && this.valueChanged(this._value, e.get("_value")), e.has("value") && (this._value = Array.isArray(this.value) ? this.value : this.value ? this.value.split(",") : [], !this.multiple && this._value.length > 1 && (this._value = [this._value[0]]), this.isMaxItemsReached()), e.has("options") && this.options.length && (this._options = this.options, this._options.forEach((t) => {
|
|
48
|
-
if (t.value && !t.label && (t.label = t.value), t.selected && !this._value.includes(t.value)) {
|
|
49
|
-
const s = [...this._value];
|
|
50
|
-
this._value = [...this._value, t.value], this.valueChanged(this._value, s);
|
|
51
|
-
}
|
|
52
|
-
t.fulltext = t.value + t.label + (t.prefix || ""), t.selected = t.selected || this._value.includes(t.value);
|
|
53
|
-
})), e.has("_search") && this.dispatchEvent(
|
|
54
|
-
new CustomEvent("search", {
|
|
55
|
-
detail: this._search,
|
|
56
|
-
bubbles: !1
|
|
57
|
-
})
|
|
58
|
-
), super.updated(e);
|
|
59
|
-
}
|
|
60
|
-
attributeChangedCallback(e, t, s) {
|
|
61
|
-
e === "value" && (this._value = Array.isArray(this.value) ? this.value : this.value ? this.value.split(",") : [], !this.multiple && this._value.length > 1 && (this._value = [this._value[0]])), e === "options" && (this._options = this.options, this._options.forEach((i) => {
|
|
62
|
-
i.value && !i.label && (i.label = i.value), i.selected && !this._value.includes(i.value) && (this._value = [...this._value, i.value]), i.fulltext = i.value + i.label + (i.prefix || "");
|
|
63
|
-
}), this._search = ""), super.attributeChangedCallback(e, t, s);
|
|
64
|
-
}
|
|
65
|
-
// Render methods
|
|
66
|
-
render() {
|
|
67
|
-
return d`
|
|
68
|
-
<pkt-input-wrapper
|
|
69
|
-
.label=${this.label}
|
|
70
|
-
.helptext=${this.helptext}
|
|
71
|
-
.helptextDropdown=${f(this.helptextDropdown)}
|
|
72
|
-
.helptextDropdownButton=${f(this.helptextDropdownButton)}
|
|
73
|
-
?fullwidth=${this.fullwidth}
|
|
74
|
-
?hasError=${this.hasError}
|
|
75
|
-
?inline=${this.inline}
|
|
76
|
-
?disabled=${this.disabled}
|
|
77
|
-
.errorMessage=${this.errorMessage}
|
|
78
|
-
?optionalTag=${this.optionalTag}
|
|
79
|
-
.optionalText=${this.optionalText}
|
|
80
|
-
?requiredTag=${this.requiredTag}
|
|
81
|
-
.requiredText=${this.requiredText}
|
|
82
|
-
?useWrapper=${this.useWrapper}
|
|
83
|
-
.forId=${this.allowUserInput || this.typeahead ? this.id + "-input" : this.id + "-arrow"}
|
|
84
|
-
class="pkt-combobox__wrapper"
|
|
85
|
-
@labelClick=${this.handleInputClick}
|
|
86
|
-
>
|
|
87
|
-
<div class="pkt-contents" ${v(this.helptextSlot)} name="helptext" slot="helptext"></div>
|
|
88
|
-
<div class="pkt-combobox" @focusout=${this.handleFocusOut}>
|
|
89
|
-
<div
|
|
90
|
-
class=${O({
|
|
91
|
-
"pkt-combobox__input": !0,
|
|
92
|
-
"pkt-combobox__input--fullwidth": this.fullwidth,
|
|
93
|
-
"pkt-combobox__input--open": this._isOptionsOpen,
|
|
94
|
-
"pkt-combobox__input--error": this.hasError,
|
|
95
|
-
"pkt-combobox__input--disabled": this.disabled
|
|
96
|
-
})}
|
|
97
|
-
tabindex="-1"
|
|
98
|
-
@click=${this.handleInputClick}
|
|
99
|
-
>
|
|
100
|
-
${this.placeholder && (!this._value.length || this.multiple && this.tagPlacement == "outside") && !this._inputFocus ? d`<span class="pkt-combobox__placeholder">${this.placeholder}</span>` : this.tagPlacement !== "outside" ? this.renderSingleOrMultipleValues() : y}
|
|
101
|
-
${this.renderInputField()}
|
|
102
|
-
<div
|
|
103
|
-
class="pkt-btn pkt-btn--tertiary pkt-combobox__arrow"
|
|
104
|
-
@click=${this.handleArrowClick}
|
|
105
|
-
@keydown=${this.handleArrowClick}
|
|
106
|
-
id="${this.id}-arrow"
|
|
107
|
-
${v(this.arrowRef)}
|
|
108
|
-
aria-expanded=${this._isOptionsOpen}
|
|
109
|
-
aria-controls="${this.id}-listbox"
|
|
110
|
-
aria-haspopup="listbox"
|
|
111
|
-
aria-label="Åpne liste"
|
|
112
|
-
?disabled=${this.disabled}
|
|
113
|
-
?data-disabled=${this.disabled}
|
|
114
|
-
role="button"
|
|
115
|
-
tabindex="${this.disabled ? "-1" : "0"}"
|
|
116
|
-
>
|
|
117
|
-
<pkt-icon
|
|
118
|
-
class=${O({
|
|
119
|
-
"pkt-combobox__arrow-icon": !0,
|
|
120
|
-
"pkt-combobox__arrow-icon--open": this._isOptionsOpen
|
|
121
|
-
})}
|
|
122
|
-
name="chevron-thin-down"
|
|
123
|
-
></pkt-icon>
|
|
124
|
-
</div>
|
|
125
|
-
<div ${v(this.focusRef)} tabindex="-1" @keydown=${this.handleArrowClick}></div>
|
|
126
|
-
</div>
|
|
127
|
-
|
|
128
|
-
<pkt-listbox
|
|
129
|
-
id="${this.id}-listbox"
|
|
130
|
-
.options=${this._options}
|
|
131
|
-
.isOpen=${this._isOptionsOpen}
|
|
132
|
-
.searchPlaceholder=${this.searchPlaceholder}
|
|
133
|
-
.label="Liste: ${this.label || ""}"
|
|
134
|
-
?includeSearch=${this.includeSearch}
|
|
135
|
-
?isMultiSelect=${this.multiple}
|
|
136
|
-
?allowUserInput=${this.allowUserInput && !this._maxIsReached}
|
|
137
|
-
?maxIsReached=${this._maxIsReached}
|
|
138
|
-
.customUserInput=${f(this._addValueText)}
|
|
139
|
-
.userMessage=${this._userInfoMessage}
|
|
140
|
-
@search=${this.handleSearch}
|
|
141
|
-
@option-toggle=${this.handleOptionToggled}
|
|
142
|
-
@select-all=${this.addAllOptions}
|
|
143
|
-
@close-options=${() => this._isOptionsOpen = !1}
|
|
144
|
-
.searchValue=${this._search || null}
|
|
145
|
-
.maxLength=${this.maxlength || 0}
|
|
146
|
-
${v(this.listboxRef)}
|
|
147
|
-
></pkt-listbox>
|
|
148
|
-
</div>
|
|
149
|
-
|
|
150
|
-
${this.tagPlacement === "outside" && this.multiple ? d`<div class="pkt-combobox__tags-outside">
|
|
151
|
-
${this.renderSingleOrMultipleValues()}
|
|
152
|
-
</div>` : y}
|
|
153
|
-
</pkt-input-wrapper>
|
|
154
|
-
`;
|
|
155
|
-
}
|
|
156
|
-
renderInputField() {
|
|
157
|
-
return this.typeahead || this.allowUserInput ? d`
|
|
158
|
-
<div class="pkt-combobox__input-div combobox__input">
|
|
159
|
-
<input
|
|
160
|
-
type="text"
|
|
161
|
-
id="${this.id}-input"
|
|
162
|
-
name=${(this.name || this.id) + "-input"}
|
|
163
|
-
@input=${this.handleInput}
|
|
164
|
-
@keydown=${this.handleInputKeydown}
|
|
165
|
-
@focus=${this.handleFocus}
|
|
166
|
-
@blur=${this.handleBlur}
|
|
167
|
-
autocomplete="off"
|
|
168
|
-
role="combobox"
|
|
169
|
-
aria-label=${f(this.label)}
|
|
170
|
-
aria-autocomplete=${this.typeahead ? "both" : "list"}
|
|
171
|
-
aria-controls="${this.id}-listbox"
|
|
172
|
-
aria-multiselectable=${f(this.multiple ? "true" : void 0)}
|
|
173
|
-
aria-activedescendant=${f(
|
|
174
|
-
this._value[0] && this.findValueInOptions(this._value[0]) ? `${this.id}-listbox-${this.findIndexInOptions(this._value[0])}` : void 0
|
|
175
|
-
)}
|
|
176
|
-
${v(this.inputRef)}
|
|
177
|
-
/>
|
|
178
|
-
</div>
|
|
179
|
-
` : d`
|
|
180
|
-
<input
|
|
181
|
-
type="hidden"
|
|
182
|
-
id="${this.id}-input"
|
|
183
|
-
name=${(this.name || this.id) + "-input"}
|
|
184
|
-
.value=${this._value.join(",")}
|
|
185
|
-
${v(this.inputRef)}
|
|
186
|
-
/>
|
|
187
|
-
`;
|
|
188
|
-
}
|
|
189
|
-
renderSingleOrMultipleValues() {
|
|
190
|
-
const e = !this.multiple, t = this._editingSingleValue ? null : this.renderValueTag(this.findValueInOptions(this._value[0])), s = R(
|
|
191
|
-
this._value,
|
|
192
|
-
(i) => i,
|
|
193
|
-
(i) => {
|
|
194
|
-
var l;
|
|
195
|
-
const n = this.findValueInOptions(i), u = (l = this.options.find((o) => o.value === i)) == null ? void 0 : l.tagSkinColor;
|
|
196
|
-
return d`
|
|
197
|
-
<pkt-tag
|
|
198
|
-
skin=${u || "blue-dark"}
|
|
199
|
-
?closeTag=${!this.disabled}
|
|
200
|
-
@close=${() => this.handleTagRemove(i)}
|
|
201
|
-
>
|
|
202
|
-
${this.renderValueTag(n)}
|
|
203
|
-
</pkt-tag>
|
|
204
|
-
`;
|
|
205
|
-
}
|
|
206
|
-
);
|
|
207
|
-
return e ? t : s;
|
|
208
|
-
}
|
|
209
|
-
renderValueTag(e) {
|
|
210
|
-
if (!e) return "";
|
|
211
|
-
switch (this.displayValueAs) {
|
|
212
|
-
case "prefixAndValue":
|
|
213
|
-
return d`<span data-focusfix=${this.id}>${e.prefix || ""} ${e.value}</span>`;
|
|
214
|
-
case "value":
|
|
215
|
-
return d`<span data-focusfix=${this.id}>${e.value}</span>`;
|
|
216
|
-
case "label":
|
|
217
|
-
default:
|
|
218
|
-
return d`<span data-focusfix=${this.id}>${e.label || e.value}</span>`;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
// Event handlers
|
|
222
|
-
handleInput(e) {
|
|
223
|
-
if (e.stopPropagation(), e.stopImmediatePropagation(), this.disabled) return;
|
|
224
|
-
this.touched = !0;
|
|
225
|
-
const t = e.target;
|
|
226
|
-
if (this._search = t.value, this.checkForMatches(), this.typeahead)
|
|
227
|
-
if (this._search) {
|
|
228
|
-
if (this._options = this.options.filter(
|
|
229
|
-
(s) => {
|
|
230
|
-
var i;
|
|
231
|
-
return (i = s.fulltext) == null ? void 0 : i.toLowerCase().includes(this._search.toLowerCase());
|
|
232
|
-
}
|
|
233
|
-
), e.inputType !== "deleteContentBackward") {
|
|
234
|
-
const s = this._options.filter(
|
|
235
|
-
(i) => {
|
|
236
|
-
var n;
|
|
237
|
-
return !i.selected && ((n = i.label) == null ? void 0 : n.toLowerCase().startsWith(this._search.toLowerCase()));
|
|
238
|
-
}
|
|
239
|
-
);
|
|
240
|
-
if (s.length > 0 && this.inputRef.value && this.inputRef.value.type !== "hidden") {
|
|
241
|
-
const i = s[0];
|
|
242
|
-
i != null && i.label && (t.value = i.label, window.setTimeout(
|
|
243
|
-
() => t.setSelectionRange(this._search.length, t.value.length),
|
|
244
|
-
0
|
|
245
|
-
), t.selectionDirection = "backward");
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
} else
|
|
249
|
-
this._options = [...this.options];
|
|
250
|
-
}
|
|
251
|
-
handleFocus() {
|
|
252
|
-
if (!this.disabled) {
|
|
253
|
-
if (!this.multiple && this._value[0] && this.inputRef.value && this.inputRef.value.type !== "hidden") {
|
|
254
|
-
const e = this.findValueInOptions(this._value[0]);
|
|
255
|
-
this._editingSingleValue = !0, this.inputRef.value.value = this.displayValueAs === "label" && (e != null && e.label) ? e.label : this._value[0];
|
|
256
|
-
}
|
|
257
|
-
this._inputFocus = !0, this._search = "", this._options = [...this.options], this._isOptionsOpen = !0, this.onFocus(), this.requestUpdate();
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
handleFocusOut(e) {
|
|
261
|
-
var t, s, i, n, u;
|
|
262
|
-
if (!this.disabled && ((s = (t = e.relatedTarget) == null ? void 0 : t.closest("pkt-combobox")) == null ? void 0 : s.id) !== this.id && ((n = (i = e.relatedTarget) == null ? void 0 : i.closest("pkt-combobox")) == null ? void 0 : n.id) !== this.id && ((u = e.target) == null ? void 0 : u.getAttribute("data-focusfix")) !== this.id && e.relatedTarget !== this.focusRef.value && e.relatedTarget !== this.inputRef.value && e.relatedTarget !== this.arrowRef.value && this._isOptionsOpen) {
|
|
263
|
-
if (this._inputFocus = !1, this._addValueText = null, this._userInfoMessage = "", this._search = "", this.inputRef.value && this.inputRef.value.type !== "hidden" && this.inputRef.value.value !== "") {
|
|
264
|
-
const l = this.inputRef.value.value, o = this.findValueInOptions(l);
|
|
265
|
-
!this._value.includes(l) && !o ? this.allowUserInput ? this.addNewUserValue(l) : this.multiple || this.removeValue(this._value[0]) : o && !this._value.includes(o.value) && this.setSelected(o.value), this.inputRef.value.value = "";
|
|
266
|
-
}
|
|
267
|
-
this._isOptionsOpen = !1, this.onBlur();
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
handleBlur() {
|
|
271
|
-
this._inputFocus = !1, this._editingSingleValue = !1, this.onBlur();
|
|
272
|
-
}
|
|
273
|
-
handleInputClick(e) {
|
|
274
|
-
var t, s;
|
|
275
|
-
this.disabled || (e.currentTarget && e.currentTarget !== this.arrowRef.value && ((t = this.inputRef.value) == null ? void 0 : t.type) !== "hidden" ? (s = this.inputRef.value) == null || s.focus() : this.handleArrowClick(e));
|
|
276
|
-
}
|
|
277
|
-
handleArrowClick(e) {
|
|
278
|
-
var t, s;
|
|
279
|
-
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() : (s = this.arrowRef.value) == null || s.focus());
|
|
280
|
-
}
|
|
281
|
-
handleOptionToggled(e) {
|
|
282
|
-
this.toggleValue(e.detail);
|
|
283
|
-
}
|
|
284
|
-
handleSearch(e) {
|
|
285
|
-
e.stopPropagation(), this._search = e.detail.toLowerCase();
|
|
286
|
-
}
|
|
287
|
-
handleInputKeydown(e) {
|
|
288
|
-
var t, s, i;
|
|
289
|
-
switch (e.key) {
|
|
290
|
-
case ",":
|
|
291
|
-
case "Enter":
|
|
292
|
-
e.preventDefault(), this.addValue();
|
|
293
|
-
break;
|
|
294
|
-
case "Backspace":
|
|
295
|
-
!this._search && ((t = this.inputRef.value) == null ? void 0 : t.type) === "hidden" && this.removeLastValue(e);
|
|
296
|
-
break;
|
|
297
|
-
case "Tab":
|
|
298
|
-
case "ArrowDown":
|
|
299
|
-
e.shiftKey || ((s = this.listboxRef.value) == null || s.focusFirstOrSelectedOption(), e.preventDefault());
|
|
300
|
-
break;
|
|
301
|
-
case "Escape":
|
|
302
|
-
this._isOptionsOpen = !1, (i = this.arrowRef.value) == null || i.focus(), e.preventDefault();
|
|
303
|
-
break;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
handleTagRemove(e) {
|
|
307
|
-
this.removeSelected(e);
|
|
308
|
-
}
|
|
309
|
-
blurInput() {
|
|
310
|
-
this.inputRef.value && this.inputRef.value.matches(":focus") && this.inputRef.value.blur();
|
|
311
|
-
}
|
|
312
|
-
checkForMatches() {
|
|
313
|
-
var u;
|
|
314
|
-
const e = ((u = this.inputRef.value) == null ? void 0 : u.value) || this._search || "", t = e.trim().toLowerCase() || "";
|
|
315
|
-
if (!t) {
|
|
316
|
-
!this.multiple && this._value[0] && this.removeValue(this._value[0]), this.resetComboboxInput(!1);
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
const s = this._value.find((l) => l.toLowerCase() === t), i = this._options.filter(
|
|
320
|
-
(l) => {
|
|
321
|
-
var o;
|
|
322
|
-
return ((o = l.label) == null ? void 0 : o.toLowerCase().includes(t)) ?? !1;
|
|
323
|
-
}
|
|
324
|
-
), n = i.find(
|
|
325
|
-
(l) => {
|
|
326
|
-
var o;
|
|
327
|
-
return ((o = l.label) == null ? void 0 : o.toLowerCase()) === t || l.value.toLowerCase() === t;
|
|
328
|
-
}
|
|
329
|
-
);
|
|
330
|
-
switch (!0) {
|
|
331
|
-
case ((i.length === 0 || !n) && this.allowUserInput):
|
|
332
|
-
this._addValueText = e, this._userInfoMessage = "";
|
|
333
|
-
break;
|
|
334
|
-
case (i.length === 0 && !this.allowUserInput):
|
|
335
|
-
this._addValueText = null, this._userInfoMessage = "Ingen match i søket";
|
|
336
|
-
break;
|
|
337
|
-
case !!s:
|
|
338
|
-
this._addValueText = null, this._userInfoMessage = "Verdien er allerede valgt";
|
|
339
|
-
break;
|
|
340
|
-
case i.length > 1:
|
|
341
|
-
this._addValueText = null, this._userInfoMessage = "";
|
|
342
|
-
break;
|
|
343
|
-
default:
|
|
344
|
-
this._addValueText = null, this._userInfoMessage = "";
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
findValueInOptions(e) {
|
|
348
|
-
return this.options.find((t) => t.value === e || t.label === e) || null;
|
|
349
|
-
}
|
|
350
|
-
findIndexInOptions(e) {
|
|
351
|
-
return this._options.findIndex((t) => t.value === e || t.label === e);
|
|
352
|
-
}
|
|
353
|
-
isMaxItemsReached() {
|
|
354
|
-
const e = this.maxlength !== null && this._value.length >= this.maxlength;
|
|
355
|
-
return e ? this._maxIsReached = !0 : this._maxIsReached = !1, e;
|
|
356
|
-
}
|
|
357
|
-
toggleValue(e) {
|
|
358
|
-
var I, w;
|
|
359
|
-
if (this.disabled) return;
|
|
360
|
-
this.touched = !0, this._userInfoMessage = "", this._addValueText = null;
|
|
361
|
-
const t = ((I = this.findValueInOptions(e)) == null ? void 0 : I.value) || null, s = this._value.includes(e || t || ""), i = !!t, n = ((w = this._options.find((m) => m.value === e)) == null ? void 0 : w.disabled) || !1, u = !(e != null && e.trim()), l = !this.multiple, o = this.multiple, $ = this.isMaxItemsReached();
|
|
362
|
-
let p = !1, b = !0, g = "", x = "";
|
|
363
|
-
n || (!i && this.allowUserInput && !u ? (this.addNewUserValue(e), g = "Ny verdi lagt til", p = !o) : !i && !this.allowUserInput ? (l && this._value[0] && this.removeValue(this._value[0]), b = !1, p = !0, g = "Ingen treff i søket") : s ? (this.removeValue(t), p = !0) : u && l ? (this.removeAllSelected(), p = !0) : l ? (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())) : o && !$ ? (this.setSelected(t), p = !0) : o && $ ? (this._userInfoMessage = "Maks antall valg nådd", b = !1, x = e) : (l && this.removeAllSelected(), this._userInfoMessage = "Ingen gyldig verdi valgt", b = !1, p = !0, x = e), this._isOptionsOpen = p, p || window.setTimeout(() => {
|
|
364
|
-
var m;
|
|
365
|
-
(m = this.focusRef.value) == null || m.focus();
|
|
366
|
-
}, 0), this._userInfoMessage = g, this._search = x || "", this.resetComboboxInput(b), o && this.isMaxItemsReached());
|
|
367
|
-
}
|
|
368
|
-
setSelected(e) {
|
|
369
|
-
if (!this._value.includes(e)) {
|
|
370
|
-
if (this.multiple && this.isMaxItemsReached()) {
|
|
371
|
-
this._userInfoMessage = "Maks antall valg nådd";
|
|
372
|
-
return;
|
|
373
|
-
}
|
|
374
|
-
!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);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
removeSelected(e) {
|
|
378
|
-
if (!e) return;
|
|
379
|
-
this._value = this._value.filter((s) => s !== e);
|
|
380
|
-
const t = this.findValueInOptions(e);
|
|
381
|
-
t ? (t.selected = !1, t.userAdded ? (this._options = [...this._options.filter((s) => s.value !== e)], this.options = [...this.options.filter((s) => s.value !== e)]) : this._options = [...this._options, t]) : !e && !this.multiple && (this._options = this._options.map((s) => (s.selected = !1, s)));
|
|
382
|
-
}
|
|
383
|
-
addAllOptions() {
|
|
384
|
-
if (this.multiple) {
|
|
385
|
-
if (this.maxlength && this._options.length > this.maxlength) {
|
|
386
|
-
this._userInfoMessage = "For mange valgt";
|
|
387
|
-
return;
|
|
388
|
-
}
|
|
389
|
-
this._value = this._options.map((e) => e.value), this._options = this._options.map((e) => (e.selected = !0, e)), this.requestUpdate();
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
removeAllSelected() {
|
|
393
|
-
this._value = [], this._options = this._options.map((e) => (e.selected = !1, e)), this._options = this._options.filter((e) => !e.userAdded), this.requestUpdate();
|
|
394
|
-
}
|
|
395
|
-
addValue() {
|
|
396
|
-
var t;
|
|
397
|
-
const e = ((t = this.inputRef.value) == null ? void 0 : t.value.trim()) || "";
|
|
398
|
-
this._search = e, this.toggleValue(e);
|
|
399
|
-
}
|
|
400
|
-
removeValue(e) {
|
|
401
|
-
this._value = this.multiple ? this._value.filter((t) => t !== e) : [], this.removeSelected(e);
|
|
402
|
-
}
|
|
403
|
-
addNewUserValue(e) {
|
|
404
|
-
if (!e || e.trim() === "") return;
|
|
405
|
-
if (!this.multiple)
|
|
406
|
-
this._value[0] && this.removeSelected(this._value[0]), this._value = [e], this._isOptionsOpen = !1, this.blurInput();
|
|
407
|
-
else if (!this.findValueInOptions(e)) {
|
|
408
|
-
if (this.isMaxItemsReached()) return;
|
|
409
|
-
this._value = [...this._value, e];
|
|
410
|
-
}
|
|
411
|
-
const t = { value: e, label: e, userAdded: !0 };
|
|
412
|
-
this.options = [t, ...this.options], this._options = [t, ...this._options], this.setSelected(e), this.requestUpdate();
|
|
413
|
-
}
|
|
414
|
-
resetComboboxInput(e = !0) {
|
|
415
|
-
if (this._addValueText = null, this.inputRef.value && this.inputRef.value.type !== "hidden" && e)
|
|
416
|
-
if (this._search = "", this.multiple)
|
|
417
|
-
this.inputRef.value.value = "";
|
|
418
|
-
else {
|
|
419
|
-
const t = this.findValueInOptions(this._value[0]);
|
|
420
|
-
window.setTimeout(() => {
|
|
421
|
-
!this.inputRef.value || this.inputRef.value.type === "hidden" || (this.inputRef.value.value = this.displayValueAs === "label" && (t != null && t.label) ? t.label : this._value[0] || "");
|
|
422
|
-
}, 0), this._userInfoMessage = "";
|
|
423
|
-
}
|
|
424
|
-
this._options = [...this.options];
|
|
425
|
-
}
|
|
426
|
-
removeLastValue(e) {
|
|
427
|
-
if (this._value.length === 0) return;
|
|
428
|
-
e.preventDefault();
|
|
429
|
-
const t = this._value[this._value.length - 1];
|
|
430
|
-
t && this.removeSelected(t), this.isMaxItemsReached();
|
|
431
|
-
}
|
|
432
|
-
};
|
|
433
|
-
h([
|
|
434
|
-
r({ type: String, reflect: !0 })
|
|
435
|
-
], a.prototype, "value", 2);
|
|
436
|
-
h([
|
|
437
|
-
r({ type: Array })
|
|
438
|
-
], a.prototype, "options", 2);
|
|
439
|
-
h([
|
|
440
|
-
r({ type: Boolean })
|
|
441
|
-
], a.prototype, "allowUserInput", 2);
|
|
442
|
-
h([
|
|
443
|
-
r({ type: Boolean })
|
|
444
|
-
], a.prototype, "typeahead", 2);
|
|
445
|
-
h([
|
|
446
|
-
r({ type: Boolean })
|
|
447
|
-
], a.prototype, "includeSearch", 2);
|
|
448
|
-
h([
|
|
449
|
-
r({ type: String })
|
|
450
|
-
], a.prototype, "searchPlaceholder", 2);
|
|
451
|
-
h([
|
|
452
|
-
r({ type: Boolean })
|
|
453
|
-
], a.prototype, "multiple", 2);
|
|
454
|
-
h([
|
|
455
|
-
r({ type: Number })
|
|
456
|
-
], a.prototype, "maxlength", 2);
|
|
457
|
-
h([
|
|
458
|
-
r({ type: String })
|
|
459
|
-
], a.prototype, "displayValueAs", 2);
|
|
460
|
-
h([
|
|
461
|
-
r({ type: String })
|
|
462
|
-
], a.prototype, "tagPlacement", 2);
|
|
463
|
-
h([
|
|
464
|
-
c()
|
|
465
|
-
], a.prototype, "_options", 2);
|
|
466
|
-
h([
|
|
467
|
-
c()
|
|
468
|
-
], a.prototype, "_isOptionsOpen", 2);
|
|
469
|
-
h([
|
|
470
|
-
c()
|
|
471
|
-
], a.prototype, "_value", 2);
|
|
472
|
-
h([
|
|
473
|
-
c()
|
|
474
|
-
], a.prototype, "_userInfoMessage", 2);
|
|
475
|
-
h([
|
|
476
|
-
c()
|
|
477
|
-
], a.prototype, "_addValueText", 2);
|
|
478
|
-
h([
|
|
479
|
-
c()
|
|
480
|
-
], a.prototype, "_maxIsReached", 2);
|
|
481
|
-
h([
|
|
482
|
-
c()
|
|
483
|
-
], a.prototype, "_search", 2);
|
|
484
|
-
h([
|
|
485
|
-
c()
|
|
486
|
-
], a.prototype, "_inputFocus", 2);
|
|
487
|
-
h([
|
|
488
|
-
c()
|
|
489
|
-
], a.prototype, "_editingSingleValue", 2);
|
|
490
|
-
a = h([
|
|
491
|
-
k("pkt-combobox")
|
|
492
|
-
], a);
|
|
493
|
-
export {
|
|
494
|
-
a as P
|
|
495
|
-
};
|