@oslokommune/punkt-elements 12.41.0 → 12.41.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/combobox-CavDENt-.js +514 -0
- package/dist/{combobox-lds6Lryq.cjs → combobox-DMkMUJfx.cjs} +12 -12
- package/dist/index.d.ts +2 -0
- 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 +1 -1
- package/package.json +2 -2
- package/src/components/combobox/combobox.ts +27 -1
- package/dist/combobox-Ct7-a2Vy.js +0 -495
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,23 @@ og skriver commits ca etter [Conventional Commits](https://conventionalcommits.o
|
|
|
5
5
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
+
## [12.41.1](https://github.com/oslokommune/punkt/compare/12.41.0...12.41.1) (2025-06-11)
|
|
9
|
+
|
|
10
|
+
### ⚠ BREAKING CHANGES
|
|
11
|
+
Ingen
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
Ingen
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
Ingen
|
|
18
|
+
|
|
19
|
+
### Chores
|
|
20
|
+
Ingen
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
|
|
8
25
|
## [12.41.0](https://github.com/oslokommune/punkt/compare/12.40.10...12.41.0) (2025-06-10)
|
|
9
26
|
|
|
10
27
|
### ⚠ BREAKING CHANGES
|
|
@@ -0,0 +1,514 @@
|
|
|
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 w } 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 A } 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 S = {
|
|
15
|
+
displayValueAs: {
|
|
16
|
+
default: "label"
|
|
17
|
+
}
|
|
18
|
+
}, T = {
|
|
19
|
+
props: S
|
|
20
|
+
};
|
|
21
|
+
var M = Object.defineProperty, F = Object.getOwnPropertyDescriptor, o = (t, e, i, s) => {
|
|
22
|
+
for (var l = s > 1 ? void 0 : s ? F(e, i) : e, n = t.length - 1, a; n >= 0; n--)
|
|
23
|
+
(a = t[n]) && (l = (s ? a(e, i, l) : a(l)) || l);
|
|
24
|
+
return s && l && M(e, i, l), l;
|
|
25
|
+
};
|
|
26
|
+
let h = class extends V {
|
|
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 A(this, this.helptextSlot), this.slotController.skipOptions = !0;
|
|
29
|
+
}
|
|
30
|
+
// Lifecycle methods
|
|
31
|
+
connectedCallback() {
|
|
32
|
+
var t;
|
|
33
|
+
if (super.connectedCallback(), document && document.body.addEventListener("click", (e) => {
|
|
34
|
+
this._isOptionsOpen && !this.contains(e.target) && this.handleFocusOut(e);
|
|
35
|
+
}), this._options = [], this.defaultOptions && this.defaultOptions.length) {
|
|
36
|
+
const e = ((t = this.options) == null ? void 0 : t.filter((i) => i.userAdded)) || [];
|
|
37
|
+
this.options = [...e, ...structuredClone(this.defaultOptions)], this._options = [...this.options];
|
|
38
|
+
}
|
|
39
|
+
if (this.optionsController.nodes.length) {
|
|
40
|
+
const e = [];
|
|
41
|
+
this.optionsController.nodes.forEach((i) => {
|
|
42
|
+
if (!i.textContent && !i.getAttribute("value")) return null;
|
|
43
|
+
const s = {
|
|
44
|
+
value: i.getAttribute("value") || i.textContent || "",
|
|
45
|
+
label: i.textContent || i.getAttribute("value") || ""
|
|
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 || ""), e.push(s);
|
|
48
|
+
}), e.length && (this.options = [...e], this._options = [...e]);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
updated(t) {
|
|
52
|
+
var e;
|
|
53
|
+
if (t.has("_value") && this.valueChanged(this._value, t.get("_value")), t.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()), t.has("defaultOptions") && this.defaultOptions.length) {
|
|
54
|
+
const i = ((e = this.options) == null ? void 0 : e.filter((s) => s.userAdded)) || [];
|
|
55
|
+
this.options = [...i, ...structuredClone(this.defaultOptions)], this._options = [...this.options];
|
|
56
|
+
}
|
|
57
|
+
if (t.has("options") && this.options.length) {
|
|
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) => {
|
|
62
|
+
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);
|
|
65
|
+
}
|
|
66
|
+
l.fulltext = l.value + l.label + (l.prefix || ""), l.selected = l.selected || this._value.includes(l.value);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
t.has("_search") && this.dispatchEvent(
|
|
70
|
+
new CustomEvent("search", {
|
|
71
|
+
detail: this._search,
|
|
72
|
+
bubbles: !1
|
|
73
|
+
})
|
|
74
|
+
), super.updated(t);
|
|
75
|
+
}
|
|
76
|
+
attributeChangedCallback(t, e, i) {
|
|
77
|
+
t === "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]])), t === "options" && (this._options = this.options, this._options.forEach((s) => {
|
|
78
|
+
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(t, e, i);
|
|
80
|
+
}
|
|
81
|
+
// Render methods
|
|
82
|
+
render() {
|
|
83
|
+
return d`
|
|
84
|
+
<pkt-input-wrapper
|
|
85
|
+
.label=${this.label}
|
|
86
|
+
.helptext=${this.helptext}
|
|
87
|
+
.helptextDropdown=${f(this.helptextDropdown)}
|
|
88
|
+
.helptextDropdownButton=${f(this.helptextDropdownButton)}
|
|
89
|
+
?fullwidth=${this.fullwidth}
|
|
90
|
+
?hasError=${this.hasError}
|
|
91
|
+
?inline=${this.inline}
|
|
92
|
+
?disabled=${this.disabled}
|
|
93
|
+
.errorMessage=${this.errorMessage}
|
|
94
|
+
?optionalTag=${this.optionalTag}
|
|
95
|
+
.optionalText=${this.optionalText}
|
|
96
|
+
?requiredTag=${this.requiredTag}
|
|
97
|
+
.requiredText=${this.requiredText}
|
|
98
|
+
?useWrapper=${this.useWrapper}
|
|
99
|
+
.forId=${this.allowUserInput || this.typeahead ? this.id + "-input" : this.id + "-arrow"}
|
|
100
|
+
class="pkt-combobox__wrapper"
|
|
101
|
+
@labelClick=${this.handleInputClick}
|
|
102
|
+
>
|
|
103
|
+
<div class="pkt-contents" ${v(this.helptextSlot)} name="helptext" slot="helptext"></div>
|
|
104
|
+
<div class="pkt-combobox" @focusout=${this.handleFocusOut}>
|
|
105
|
+
<div
|
|
106
|
+
class=${w({
|
|
107
|
+
"pkt-combobox__input": !0,
|
|
108
|
+
"pkt-combobox__input--fullwidth": this.fullwidth,
|
|
109
|
+
"pkt-combobox__input--open": this._isOptionsOpen,
|
|
110
|
+
"pkt-combobox__input--error": this.hasError,
|
|
111
|
+
"pkt-combobox__input--disabled": this.disabled
|
|
112
|
+
})}
|
|
113
|
+
tabindex="-1"
|
|
114
|
+
@click=${this.handleInputClick}
|
|
115
|
+
>
|
|
116
|
+
${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}
|
|
117
|
+
${this.renderInputField()}
|
|
118
|
+
<div
|
|
119
|
+
class="pkt-btn pkt-btn--tertiary pkt-combobox__arrow"
|
|
120
|
+
@click=${this.handleArrowClick}
|
|
121
|
+
@keydown=${this.handleArrowClick}
|
|
122
|
+
id="${this.id}-arrow"
|
|
123
|
+
${v(this.arrowRef)}
|
|
124
|
+
aria-expanded=${this._isOptionsOpen}
|
|
125
|
+
aria-controls="${this.id}-listbox"
|
|
126
|
+
aria-haspopup="listbox"
|
|
127
|
+
aria-label="Åpne liste"
|
|
128
|
+
?disabled=${this.disabled}
|
|
129
|
+
?data-disabled=${this.disabled}
|
|
130
|
+
role="button"
|
|
131
|
+
tabindex="${this.disabled ? "-1" : "0"}"
|
|
132
|
+
>
|
|
133
|
+
<pkt-icon
|
|
134
|
+
class=${w({
|
|
135
|
+
"pkt-combobox__arrow-icon": !0,
|
|
136
|
+
"pkt-combobox__arrow-icon--open": this._isOptionsOpen
|
|
137
|
+
})}
|
|
138
|
+
name="chevron-thin-down"
|
|
139
|
+
></pkt-icon>
|
|
140
|
+
</div>
|
|
141
|
+
<div ${v(this.focusRef)} tabindex="-1" @keydown=${this.handleArrowClick}></div>
|
|
142
|
+
</div>
|
|
143
|
+
|
|
144
|
+
<pkt-listbox
|
|
145
|
+
id="${this.id}-listbox"
|
|
146
|
+
.options=${this._options}
|
|
147
|
+
.isOpen=${this._isOptionsOpen}
|
|
148
|
+
.searchPlaceholder=${this.searchPlaceholder}
|
|
149
|
+
.label="Liste: ${this.label || ""}"
|
|
150
|
+
?includeSearch=${this.includeSearch}
|
|
151
|
+
?isMultiSelect=${this.multiple}
|
|
152
|
+
?allowUserInput=${this.allowUserInput && !this._maxIsReached}
|
|
153
|
+
?maxIsReached=${this._maxIsReached}
|
|
154
|
+
.customUserInput=${f(this._addValueText)}
|
|
155
|
+
.userMessage=${this._userInfoMessage}
|
|
156
|
+
@search=${this.handleSearch}
|
|
157
|
+
@option-toggle=${this.handleOptionToggled}
|
|
158
|
+
@select-all=${this.addAllOptions}
|
|
159
|
+
@close-options=${() => this._isOptionsOpen = !1}
|
|
160
|
+
.searchValue=${this._search || null}
|
|
161
|
+
.maxLength=${this.maxlength || 0}
|
|
162
|
+
${v(this.listboxRef)}
|
|
163
|
+
></pkt-listbox>
|
|
164
|
+
</div>
|
|
165
|
+
|
|
166
|
+
${this.tagPlacement === "outside" && this.multiple ? d`<div class="pkt-combobox__tags-outside">
|
|
167
|
+
${this.renderSingleOrMultipleValues()}
|
|
168
|
+
</div>` : y}
|
|
169
|
+
</pkt-input-wrapper>
|
|
170
|
+
`;
|
|
171
|
+
}
|
|
172
|
+
renderInputField() {
|
|
173
|
+
return this.typeahead || this.allowUserInput ? d`
|
|
174
|
+
<div class="pkt-combobox__input-div combobox__input">
|
|
175
|
+
<input
|
|
176
|
+
type="text"
|
|
177
|
+
id="${this.id}-input"
|
|
178
|
+
name=${(this.name || this.id) + "-input"}
|
|
179
|
+
@input=${this.handleInput}
|
|
180
|
+
@keydown=${this.handleInputKeydown}
|
|
181
|
+
@focus=${this.handleFocus}
|
|
182
|
+
@blur=${this.handleBlur}
|
|
183
|
+
autocomplete="off"
|
|
184
|
+
role="combobox"
|
|
185
|
+
aria-label=${f(this.label)}
|
|
186
|
+
aria-autocomplete=${this.typeahead ? "both" : "list"}
|
|
187
|
+
aria-controls="${this.id}-listbox"
|
|
188
|
+
aria-multiselectable=${f(this.multiple ? "true" : void 0)}
|
|
189
|
+
aria-activedescendant=${f(
|
|
190
|
+
this._value[0] && this.findValueInOptions(this._value[0]) ? `${this.id}-listbox-${this.findIndexInOptions(this._value[0])}` : void 0
|
|
191
|
+
)}
|
|
192
|
+
${v(this.inputRef)}
|
|
193
|
+
/>
|
|
194
|
+
</div>
|
|
195
|
+
` : d`
|
|
196
|
+
<input
|
|
197
|
+
type="hidden"
|
|
198
|
+
id="${this.id}-input"
|
|
199
|
+
name=${(this.name || this.id) + "-input"}
|
|
200
|
+
.value=${this._value.join(",")}
|
|
201
|
+
${v(this.inputRef)}
|
|
202
|
+
/>
|
|
203
|
+
`;
|
|
204
|
+
}
|
|
205
|
+
renderSingleOrMultipleValues() {
|
|
206
|
+
const t = !this.multiple, e = this._editingSingleValue ? null : this.renderValueTag(this.findValueInOptions(this._value[0])), i = R(
|
|
207
|
+
this._value,
|
|
208
|
+
(s) => s,
|
|
209
|
+
(s) => {
|
|
210
|
+
var a;
|
|
211
|
+
const l = this.findValueInOptions(s), n = (a = this.options.find((u) => u.value === s)) == null ? void 0 : a.tagSkinColor;
|
|
212
|
+
return d`
|
|
213
|
+
<pkt-tag
|
|
214
|
+
skin=${n || "blue-dark"}
|
|
215
|
+
?closeTag=${!this.disabled}
|
|
216
|
+
@close=${() => this.handleTagRemove(s)}
|
|
217
|
+
>
|
|
218
|
+
${this.renderValueTag(l)}
|
|
219
|
+
</pkt-tag>
|
|
220
|
+
`;
|
|
221
|
+
}
|
|
222
|
+
);
|
|
223
|
+
return t ? e : i;
|
|
224
|
+
}
|
|
225
|
+
renderValueTag(t) {
|
|
226
|
+
if (!t) return "";
|
|
227
|
+
switch (this.displayValueAs) {
|
|
228
|
+
case "prefixAndValue":
|
|
229
|
+
return d`<span data-focusfix=${this.id}>${t.prefix || ""} ${t.value}</span>`;
|
|
230
|
+
case "value":
|
|
231
|
+
return d`<span data-focusfix=${this.id}>${t.value}</span>`;
|
|
232
|
+
case "label":
|
|
233
|
+
default:
|
|
234
|
+
return d`<span data-focusfix=${this.id}>${t.label || t.value}</span>`;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
// Event handlers
|
|
238
|
+
handleInput(t) {
|
|
239
|
+
if (t.stopPropagation(), t.stopImmediatePropagation(), this.disabled) return;
|
|
240
|
+
this.touched = !0;
|
|
241
|
+
const e = t.target;
|
|
242
|
+
if (this._search = e.value, this.checkForMatches(), this.typeahead)
|
|
243
|
+
if (this._search) {
|
|
244
|
+
if (this._options = this.options.filter(
|
|
245
|
+
(i) => {
|
|
246
|
+
var s;
|
|
247
|
+
return (s = i.fulltext) == null ? void 0 : s.toLowerCase().includes(this._search.toLowerCase());
|
|
248
|
+
}
|
|
249
|
+
), t.inputType !== "deleteContentBackward") {
|
|
250
|
+
const i = this._options.filter(
|
|
251
|
+
(s) => {
|
|
252
|
+
var l;
|
|
253
|
+
return !s.selected && ((l = s.label) == null ? void 0 : l.toLowerCase().startsWith(this._search.toLowerCase()));
|
|
254
|
+
}
|
|
255
|
+
);
|
|
256
|
+
if (i.length > 0 && this.inputRef.value && this.inputRef.value.type !== "hidden") {
|
|
257
|
+
const s = i[0];
|
|
258
|
+
s != null && s.label && (e.value = s.label, window.setTimeout(
|
|
259
|
+
() => e.setSelectionRange(this._search.length, e.value.length),
|
|
260
|
+
0
|
|
261
|
+
), e.selectionDirection = "backward");
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
} else
|
|
265
|
+
this._options = [...this.options];
|
|
266
|
+
}
|
|
267
|
+
handleFocus() {
|
|
268
|
+
if (!this.disabled) {
|
|
269
|
+
if (!this.multiple && this._value[0] && this.inputRef.value && this.inputRef.value.type !== "hidden") {
|
|
270
|
+
const t = this.findValueInOptions(this._value[0]);
|
|
271
|
+
this._editingSingleValue = !0, this.inputRef.value.value = this.displayValueAs === "label" && (t != null && t.label) ? t.label : this._value[0];
|
|
272
|
+
}
|
|
273
|
+
this._inputFocus = !0, this._search = "", this._options = [...this.options], this._isOptionsOpen = !0, this.onFocus(), this.requestUpdate();
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
handleFocusOut(t) {
|
|
277
|
+
var e, i, s, l, n;
|
|
278
|
+
if (!this.disabled && ((i = (e = t.relatedTarget) == null ? void 0 : e.closest("pkt-combobox")) == null ? void 0 : i.id) !== this.id && ((l = (s = t.relatedTarget) == null ? void 0 : s.closest("pkt-combobox")) == null ? void 0 : l.id) !== this.id && ((n = t.target) == null ? void 0 : n.getAttribute("data-focusfix")) !== this.id && t.relatedTarget !== this.focusRef.value && t.relatedTarget !== this.inputRef.value && t.relatedTarget !== this.arrowRef.value && this._isOptionsOpen) {
|
|
279
|
+
if (this._inputFocus = !1, this._addValueText = null, this._userInfoMessage = "", this._search = "", this.inputRef.value && this.inputRef.value.type !== "hidden" && this.inputRef.value.value !== "") {
|
|
280
|
+
const a = this.inputRef.value.value, u = this.findValueInOptions(a);
|
|
281
|
+
!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 = "";
|
|
282
|
+
}
|
|
283
|
+
this._isOptionsOpen = !1, this.onBlur();
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
handleBlur() {
|
|
287
|
+
this._inputFocus = !1, this._editingSingleValue = !1, this.onBlur();
|
|
288
|
+
}
|
|
289
|
+
handleInputClick(t) {
|
|
290
|
+
var e, i;
|
|
291
|
+
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.handleArrowClick(t));
|
|
292
|
+
}
|
|
293
|
+
handleArrowClick(t) {
|
|
294
|
+
var e, i;
|
|
295
|
+
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());
|
|
296
|
+
}
|
|
297
|
+
handleOptionToggled(t) {
|
|
298
|
+
this.toggleValue(t.detail);
|
|
299
|
+
}
|
|
300
|
+
handleSearch(t) {
|
|
301
|
+
t.stopPropagation(), this._search = t.detail.toLowerCase();
|
|
302
|
+
}
|
|
303
|
+
handleInputKeydown(t) {
|
|
304
|
+
var e, i, s;
|
|
305
|
+
switch (t.key) {
|
|
306
|
+
case ",":
|
|
307
|
+
case "Enter":
|
|
308
|
+
t.preventDefault(), this.addValue();
|
|
309
|
+
break;
|
|
310
|
+
case "Backspace":
|
|
311
|
+
!this._search && ((e = this.inputRef.value) == null ? void 0 : e.type) === "hidden" && this.removeLastValue(t);
|
|
312
|
+
break;
|
|
313
|
+
case "Tab":
|
|
314
|
+
case "ArrowDown":
|
|
315
|
+
t.shiftKey || ((i = this.listboxRef.value) == null || i.focusFirstOrSelectedOption(), t.preventDefault());
|
|
316
|
+
break;
|
|
317
|
+
case "Escape":
|
|
318
|
+
this._isOptionsOpen = !1, (s = this.arrowRef.value) == null || s.focus(), t.preventDefault();
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
handleTagRemove(t) {
|
|
323
|
+
this.removeSelected(t);
|
|
324
|
+
}
|
|
325
|
+
blurInput() {
|
|
326
|
+
this.inputRef.value && this.inputRef.value.matches(":focus") && this.inputRef.value.blur();
|
|
327
|
+
}
|
|
328
|
+
checkForMatches() {
|
|
329
|
+
var n;
|
|
330
|
+
const t = ((n = this.inputRef.value) == null ? void 0 : n.value) || this._search || "", e = t.trim().toLowerCase() || "";
|
|
331
|
+
if (!e) {
|
|
332
|
+
!this.multiple && this._value[0] && this.removeValue(this._value[0]), this.resetComboboxInput(!1);
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
const i = this._value.find((a) => a.toLowerCase() === e), s = this._options.filter(
|
|
336
|
+
(a) => {
|
|
337
|
+
var u;
|
|
338
|
+
return ((u = a.label) == null ? void 0 : u.toLowerCase().includes(e)) ?? !1;
|
|
339
|
+
}
|
|
340
|
+
), l = s.find(
|
|
341
|
+
(a) => {
|
|
342
|
+
var u;
|
|
343
|
+
return ((u = a.label) == null ? void 0 : u.toLowerCase()) === e || a.value.toLowerCase() === e;
|
|
344
|
+
}
|
|
345
|
+
);
|
|
346
|
+
switch (!0) {
|
|
347
|
+
case ((s.length === 0 || !l) && this.allowUserInput):
|
|
348
|
+
this._addValueText = t, this._userInfoMessage = "";
|
|
349
|
+
break;
|
|
350
|
+
case (s.length === 0 && !this.allowUserInput):
|
|
351
|
+
this._addValueText = null, this._userInfoMessage = "Ingen match i søket";
|
|
352
|
+
break;
|
|
353
|
+
case !!i:
|
|
354
|
+
this._addValueText = null, this._userInfoMessage = "Verdien er allerede valgt";
|
|
355
|
+
break;
|
|
356
|
+
case s.length > 1:
|
|
357
|
+
this._addValueText = null, this._userInfoMessage = "";
|
|
358
|
+
break;
|
|
359
|
+
default:
|
|
360
|
+
this._addValueText = null, this._userInfoMessage = "";
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
findValueInOptions(t) {
|
|
364
|
+
return this.options.find((e) => e.value === t || e.label === t) || null;
|
|
365
|
+
}
|
|
366
|
+
findIndexInOptions(t) {
|
|
367
|
+
return this._options.findIndex((e) => e.value === t || e.label === t);
|
|
368
|
+
}
|
|
369
|
+
isMaxItemsReached() {
|
|
370
|
+
const t = this.maxlength !== null && this._value.length >= this.maxlength;
|
|
371
|
+
return t ? this._maxIsReached = !0 : this._maxIsReached = !1, t;
|
|
372
|
+
}
|
|
373
|
+
toggleValue(t) {
|
|
374
|
+
var I, O;
|
|
375
|
+
if (this.disabled) return;
|
|
376
|
+
this.touched = !0, this._userInfoMessage = "", this._addValueText = null;
|
|
377
|
+
const e = ((I = this.findValueInOptions(t)) == null ? void 0 : I.value) || null, i = this._value.includes(t || e || ""), s = !!e, l = ((O = this._options.find((m) => m.value === t)) == null ? void 0 : O.disabled) || !1, n = !(t != null && t.trim()), a = !this.multiple, u = this.multiple, $ = this.isMaxItemsReached();
|
|
378
|
+
let p = !1, b = !0, g = "", x = "";
|
|
379
|
+
l || (!s && this.allowUserInput && !n ? (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) : n && 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 && !$ ? (this.setSelected(e), p = !0) : u && $ ? (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(() => {
|
|
380
|
+
var m;
|
|
381
|
+
(m = this.focusRef.value) == null || m.focus();
|
|
382
|
+
}, 0), this._userInfoMessage = g, this._search = x || "", this.resetComboboxInput(b), u && this.isMaxItemsReached());
|
|
383
|
+
}
|
|
384
|
+
setSelected(t) {
|
|
385
|
+
if (!this._value.includes(t)) {
|
|
386
|
+
if (this.multiple && this.isMaxItemsReached()) {
|
|
387
|
+
this._userInfoMessage = "Maks antall valg nådd";
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
!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);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
removeSelected(t) {
|
|
394
|
+
if (!t) return;
|
|
395
|
+
this._value = this._value.filter((i) => i !== t);
|
|
396
|
+
const e = this.findValueInOptions(t);
|
|
397
|
+
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)));
|
|
398
|
+
}
|
|
399
|
+
addAllOptions() {
|
|
400
|
+
if (this.multiple) {
|
|
401
|
+
if (this.maxlength && this._options.length > this.maxlength) {
|
|
402
|
+
this._userInfoMessage = "For mange valgt";
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
this._value = this._options.map((t) => t.value), this._options = this._options.map((t) => (t.selected = !0, t)), this.requestUpdate();
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
removeAllSelected() {
|
|
409
|
+
this._value = [], this._options = this._options.map((t) => (t.selected = !1, t)), this._options = this._options.filter((t) => !t.userAdded), this.requestUpdate();
|
|
410
|
+
}
|
|
411
|
+
addValue() {
|
|
412
|
+
var e;
|
|
413
|
+
const t = ((e = this.inputRef.value) == null ? void 0 : e.value.trim()) || "";
|
|
414
|
+
this._search = t, this.toggleValue(t);
|
|
415
|
+
}
|
|
416
|
+
removeValue(t) {
|
|
417
|
+
this._value = this.multiple ? this._value.filter((e) => e !== t) : [], this.removeSelected(t);
|
|
418
|
+
}
|
|
419
|
+
addNewUserValue(t) {
|
|
420
|
+
if (!t || t.trim() === "") return;
|
|
421
|
+
if (!this.multiple)
|
|
422
|
+
this._value[0] && this.removeSelected(this._value[0]), this._value = [t], this._isOptionsOpen = !1, this.blurInput();
|
|
423
|
+
else if (!this.findValueInOptions(t)) {
|
|
424
|
+
if (this.isMaxItemsReached()) return;
|
|
425
|
+
this._value = [...this._value, t];
|
|
426
|
+
}
|
|
427
|
+
const e = { value: t, label: t, userAdded: !0 };
|
|
428
|
+
this.options = [e, ...this.options], this._options = [e, ...this._options], this.setSelected(t), this.requestUpdate();
|
|
429
|
+
}
|
|
430
|
+
resetComboboxInput(t = !0) {
|
|
431
|
+
if (this._addValueText = null, this.inputRef.value && this.inputRef.value.type !== "hidden" && t)
|
|
432
|
+
if (this._search = "", this.multiple)
|
|
433
|
+
this.inputRef.value.value = "";
|
|
434
|
+
else {
|
|
435
|
+
const e = this.findValueInOptions(this._value[0]);
|
|
436
|
+
window.setTimeout(() => {
|
|
437
|
+
!this.inputRef.value || this.inputRef.value.type === "hidden" || (this.inputRef.value.value = this.displayValueAs === "label" && (e != null && e.label) ? e.label : this._value[0] || "");
|
|
438
|
+
}, 0), this._userInfoMessage = "";
|
|
439
|
+
}
|
|
440
|
+
this._options = [...this.options];
|
|
441
|
+
}
|
|
442
|
+
removeLastValue(t) {
|
|
443
|
+
if (this._value.length === 0) return;
|
|
444
|
+
t.preventDefault();
|
|
445
|
+
const e = this._value[this._value.length - 1];
|
|
446
|
+
e && this.removeSelected(e), this.isMaxItemsReached();
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
o([
|
|
450
|
+
r({ type: String, reflect: !0 })
|
|
451
|
+
], h.prototype, "value", 2);
|
|
452
|
+
o([
|
|
453
|
+
r({ type: Array })
|
|
454
|
+
], h.prototype, "options", 2);
|
|
455
|
+
o([
|
|
456
|
+
r({ type: Array })
|
|
457
|
+
], h.prototype, "defaultOptions", 2);
|
|
458
|
+
o([
|
|
459
|
+
r({ type: Boolean })
|
|
460
|
+
], h.prototype, "allowUserInput", 2);
|
|
461
|
+
o([
|
|
462
|
+
r({ type: Boolean })
|
|
463
|
+
], h.prototype, "typeahead", 2);
|
|
464
|
+
o([
|
|
465
|
+
r({ type: Boolean })
|
|
466
|
+
], h.prototype, "includeSearch", 2);
|
|
467
|
+
o([
|
|
468
|
+
r({ type: String })
|
|
469
|
+
], h.prototype, "searchPlaceholder", 2);
|
|
470
|
+
o([
|
|
471
|
+
r({ type: Boolean })
|
|
472
|
+
], h.prototype, "multiple", 2);
|
|
473
|
+
o([
|
|
474
|
+
r({ type: Number })
|
|
475
|
+
], h.prototype, "maxlength", 2);
|
|
476
|
+
o([
|
|
477
|
+
r({ type: String })
|
|
478
|
+
], h.prototype, "displayValueAs", 2);
|
|
479
|
+
o([
|
|
480
|
+
r({ type: String })
|
|
481
|
+
], h.prototype, "tagPlacement", 2);
|
|
482
|
+
o([
|
|
483
|
+
c()
|
|
484
|
+
], h.prototype, "_options", 2);
|
|
485
|
+
o([
|
|
486
|
+
c()
|
|
487
|
+
], h.prototype, "_isOptionsOpen", 2);
|
|
488
|
+
o([
|
|
489
|
+
c()
|
|
490
|
+
], h.prototype, "_value", 2);
|
|
491
|
+
o([
|
|
492
|
+
c()
|
|
493
|
+
], h.prototype, "_userInfoMessage", 2);
|
|
494
|
+
o([
|
|
495
|
+
c()
|
|
496
|
+
], h.prototype, "_addValueText", 2);
|
|
497
|
+
o([
|
|
498
|
+
c()
|
|
499
|
+
], h.prototype, "_maxIsReached", 2);
|
|
500
|
+
o([
|
|
501
|
+
c()
|
|
502
|
+
], h.prototype, "_search", 2);
|
|
503
|
+
o([
|
|
504
|
+
c()
|
|
505
|
+
], h.prototype, "_inputFocus", 2);
|
|
506
|
+
o([
|
|
507
|
+
c()
|
|
508
|
+
], h.prototype, "_editingSingleValue", 2);
|
|
509
|
+
h = o([
|
|
510
|
+
k("pkt-combobox")
|
|
511
|
+
], h);
|
|
512
|
+
export {
|
|
513
|
+
h as P
|
|
514
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const a=require("./element-90YeMNbV.cjs"),c=require("./if-defined-C8eotHpL.cjs"),d=require("./state-D-Recv7U.cjs"),r=require("./ref-B-w1vCo8.cjs"),O=require("./class-map-DWDPOqjO.cjs"),I=require("./repeat-CxQA3AeF.cjs"),$=require("./input-element-CInrWeac.cjs"),y=require("./pkt-options-controller-Ay9ELZTV.cjs"),w=require("./pkt-slot-controller-Da-RgXfS.cjs");require("./input-wrapper-B_TtkGqo.cjs");require("./icon-B1_BRNqf.cjs");require("./tag-lU4vz70a.cjs");require("./listbox-AjDNhDsQ.cjs");const C={displayValueAs:{default:"label"}},R={props:C};var V=Object.defineProperty,S=Object.getOwnPropertyDescriptor,o=(b,e,t,i)=>{for(var s=i>1?void 0:i?S(e,t):e,l=b.length-1,n;l>=0;l--)(n=b[l])&&(s=(i?n(e,t,s):n(s))||s);return i&&s&&V(e,t,s),s};exports.PktCombobox=class extends $.PktInputElement{constructor(){super(),this.helptextSlot=r.e(),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=R.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=r.e(),this.arrowRef=r.e(),this.listboxRef=r.e(),this.focusRef=r.e(),this.optionTagRef=r.e(),this.optionsController=new y.PktOptionsSlotController(this),this.slotController=new w.PktSlotController(this,this.helptextSlot),this.slotController.skipOptions=!0}connectedCallback(){var e;if(super.connectedCallback(),document&&document.body.addEventListener("click",t=>{this._isOptionsOpen&&!this.contains(t.target)&&this.handleFocusOut(t)}),this._options=[],this.defaultOptions&&this.defaultOptions.length){const t=((e=this.options)==null?void 0:e.filter(i=>i.userAdded))||[];this.options=[...t,...structuredClone(this.defaultOptions)],this._options=[...this.options]}if(this.optionsController.nodes.length){const t=[];this.optionsController.nodes.forEach(i=>{if(!i.textContent&&!i.getAttribute("value"))return null;const s={value:i.getAttribute("value")||i.textContent||"",label:i.textContent||i.getAttribute("value")||""};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)}),t.length&&(this.options=[...t],this._options=[...t])}}updated(e){var t;if(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("defaultOptions")&&this.defaultOptions.length){const i=((t=this.options)==null?void 0:t.filter(s=>s.userAdded))||[];this.options=[...i,...structuredClone(this.defaultOptions)],this._options=[...this.options]}if(e.has("options")&&this.options.length){const s=this._options.filter(l=>l.userAdded).filter(l=>!this.options.some(n=>n.value===l.value));this._options=[...s,...this.options],this._options.forEach(l=>{if(l.value&&!l.label&&(l.label=l.value),l.selected&&!this._value.includes(l.value)){const n=[...this._value];this._value=[...this._value,l.value],this.valueChanged(this._value,n)}l.fulltext=l.value+l.label+(l.prefix||""),l.selected=l.selected||this._value.includes(l.value)})}e.has("_search")&&this.dispatchEvent(new CustomEvent("search",{detail:this._search,bubbles:!1})),super.updated(e)}attributeChangedCallback(e,t,i){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(s=>{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||"")}),this._search=""),super.attributeChangedCallback(e,t,i)}render(){return a.x`
|
|
2
2
|
<pkt-input-wrapper
|
|
3
3
|
.label=${this.label}
|
|
4
4
|
.helptext=${this.helptext}
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
<div class="pkt-contents" ${r.n(this.helptextSlot)} name="helptext" slot="helptext"></div>
|
|
22
22
|
<div class="pkt-combobox" @focusout=${this.handleFocusOut}>
|
|
23
23
|
<div
|
|
24
|
-
class=${
|
|
24
|
+
class=${O.e({"pkt-combobox__input":!0,"pkt-combobox__input--fullwidth":this.fullwidth,"pkt-combobox__input--open":this._isOptionsOpen,"pkt-combobox__input--error":this.hasError,"pkt-combobox__input--disabled":this.disabled})}
|
|
25
25
|
tabindex="-1"
|
|
26
26
|
@click=${this.handleInputClick}
|
|
27
27
|
>
|
|
28
|
-
${this.placeholder&&(!this._value.length||this.multiple&&this.tagPlacement=="outside")&&!this._inputFocus?
|
|
28
|
+
${this.placeholder&&(!this._value.length||this.multiple&&this.tagPlacement=="outside")&&!this._inputFocus?a.x`<span class="pkt-combobox__placeholder">${this.placeholder}</span>`:this.tagPlacement!=="outside"?this.renderSingleOrMultipleValues():a.E}
|
|
29
29
|
${this.renderInputField()}
|
|
30
30
|
<div
|
|
31
31
|
class="pkt-btn pkt-btn--tertiary pkt-combobox__arrow"
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
tabindex="${this.disabled?"-1":"0"}"
|
|
44
44
|
>
|
|
45
45
|
<pkt-icon
|
|
46
|
-
class=${
|
|
46
|
+
class=${O.e({"pkt-combobox__arrow-icon":!0,"pkt-combobox__arrow-icon--open":this._isOptionsOpen})}
|
|
47
47
|
name="chevron-thin-down"
|
|
48
48
|
></pkt-icon>
|
|
49
49
|
</div>
|
|
@@ -72,11 +72,11 @@
|
|
|
72
72
|
></pkt-listbox>
|
|
73
73
|
</div>
|
|
74
74
|
|
|
75
|
-
${this.tagPlacement==="outside"&&this.multiple?
|
|
75
|
+
${this.tagPlacement==="outside"&&this.multiple?a.x`<div class="pkt-combobox__tags-outside">
|
|
76
76
|
${this.renderSingleOrMultipleValues()}
|
|
77
|
-
</div>`:
|
|
77
|
+
</div>`:a.E}
|
|
78
78
|
</pkt-input-wrapper>
|
|
79
|
-
`}renderInputField(){return this.typeahead||this.allowUserInput?
|
|
79
|
+
`}renderInputField(){return this.typeahead||this.allowUserInput?a.x`
|
|
80
80
|
<div class="pkt-combobox__input-div combobox__input">
|
|
81
81
|
<input
|
|
82
82
|
type="text"
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
${r.n(this.inputRef)}
|
|
97
97
|
/>
|
|
98
98
|
</div>
|
|
99
|
-
`:
|
|
99
|
+
`:a.x`
|
|
100
100
|
<input
|
|
101
101
|
type="hidden"
|
|
102
102
|
id="${this.id}-input"
|
|
@@ -104,12 +104,12 @@
|
|
|
104
104
|
.value=${this._value.join(",")}
|
|
105
105
|
${r.n(this.inputRef)}
|
|
106
106
|
/>
|
|
107
|
-
`}renderSingleOrMultipleValues(){const e=!this.multiple,t=this._editingSingleValue?null:this.renderValueTag(this.findValueInOptions(this._value[0])),i
|
|
107
|
+
`}renderSingleOrMultipleValues(){const e=!this.multiple,t=this._editingSingleValue?null:this.renderValueTag(this.findValueInOptions(this._value[0])),i=I.c(this._value,s=>s,s=>{var h;const l=this.findValueInOptions(s),n=(h=this.options.find(u=>u.value===s))==null?void 0:h.tagSkinColor;return a.x`
|
|
108
108
|
<pkt-tag
|
|
109
|
-
skin=${
|
|
109
|
+
skin=${n||"blue-dark"}
|
|
110
110
|
?closeTag=${!this.disabled}
|
|
111
111
|
@close=${()=>this.handleTagRemove(s)}
|
|
112
112
|
>
|
|
113
|
-
${this.renderValueTag(
|
|
113
|
+
${this.renderValueTag(l)}
|
|
114
114
|
</pkt-tag>
|
|
115
|
-
`});return e?t:i}renderValueTag(e){if(!e)return"";switch(this.displayValueAs){case"prefixAndValue":return l.x`<span data-focusfix=${this.id}>${e.prefix||""} ${e.value}</span>`;case"value":return l.x`<span data-focusfix=${this.id}>${e.value}</span>`;case"label":default:return l.x`<span data-focusfix=${this.id}>${e.label||e.value}</span>`}}handleInput(e){if(e.stopPropagation(),e.stopImmediatePropagation(),this.disabled)return;this.touched=!0;const t=e.target;if(this._search=t.value,this.checkForMatches(),this.typeahead)if(this._search){if(this._options=this.options.filter(i=>{var s;return(s=i.fulltext)==null?void 0:s.toLowerCase().includes(this._search.toLowerCase())}),e.inputType!=="deleteContentBackward"){const i=this._options.filter(s=>{var n;return!s.selected&&((n=s.label)==null?void 0:n.toLowerCase().startsWith(this._search.toLowerCase()))});if(i.length>0&&this.inputRef.value&&this.inputRef.value.type!=="hidden"){const s=i[0];s!=null&&s.label&&(t.value=s.label,window.setTimeout(()=>t.setSelectionRange(this._search.length,t.value.length),0),t.selectionDirection="backward")}}}else this._options=[...this.options]}handleFocus(){if(!this.disabled){if(!this.multiple&&this._value[0]&&this.inputRef.value&&this.inputRef.value.type!=="hidden"){const e=this.findValueInOptions(this._value[0]);this._editingSingleValue=!0,this.inputRef.value.value=this.displayValueAs==="label"&&(e!=null&&e.label)?e.label:this._value[0]}this._inputFocus=!0,this._search="",this._options=[...this.options],this._isOptionsOpen=!0,this.onFocus(),this.requestUpdate()}}handleFocusOut(e){var t,i,s,n,u;if(!this.disabled&&((i=(t=e.relatedTarget)==null?void 0:t.closest("pkt-combobox"))==null?void 0:i.id)!==this.id&&((n=(s=e.relatedTarget)==null?void 0:s.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){if(this._inputFocus=!1,this._addValueText=null,this._userInfoMessage="",this._search="",this.inputRef.value&&this.inputRef.value.type!=="hidden"&&this.inputRef.value.value!==""){const o=this.inputRef.value.value,h=this.findValueInOptions(o);!this._value.includes(o)&&!h?this.allowUserInput?this.addNewUserValue(o):this.multiple||this.removeValue(this._value[0]):h&&!this._value.includes(h.value)&&this.setSelected(h.value),this.inputRef.value.value=""}this._isOptionsOpen=!1,this.onBlur()}}handleBlur(){this._inputFocus=!1,this._editingSingleValue=!1,this.onBlur()}handleInputClick(e){var t,i;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.handleArrowClick(e))}handleArrowClick(e){var t,i;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())}handleOptionToggled(e){this.toggleValue(e.detail)}handleSearch(e){e.stopPropagation(),this._search=e.detail.toLowerCase()}handleInputKeydown(e){var t,i,s;switch(e.key){case",":case"Enter":e.preventDefault(),this.addValue();break;case"Backspace":!this._search&&((t=this.inputRef.value)==null?void 0:t.type)==="hidden"&&this.removeLastValue(e);break;case"Tab":case"ArrowDown":e.shiftKey||((i=this.listboxRef.value)==null||i.focusFirstOrSelectedOption(),e.preventDefault());break;case"Escape":this._isOptionsOpen=!1,(s=this.arrowRef.value)==null||s.focus(),e.preventDefault();break}}handleTagRemove(e){this.removeSelected(e)}blurInput(){this.inputRef.value&&this.inputRef.value.matches(":focus")&&this.inputRef.value.blur()}checkForMatches(){var u;const e=((u=this.inputRef.value)==null?void 0:u.value)||this._search||"",t=e.trim().toLowerCase()||"";if(!t){!this.multiple&&this._value[0]&&this.removeValue(this._value[0]),this.resetComboboxInput(!1);return}const i=this._value.find(o=>o.toLowerCase()===t),s=this._options.filter(o=>{var h;return((h=o.label)==null?void 0:h.toLowerCase().includes(t))??!1}),n=s.find(o=>{var h;return((h=o.label)==null?void 0:h.toLowerCase())===t||o.value.toLowerCase()===t});switch(!0){case((s.length===0||!n)&&this.allowUserInput):this._addValueText=e,this._userInfoMessage="";break;case(s.length===0&&!this.allowUserInput):this._addValueText=null,this._userInfoMessage="Ingen match i søket";break;case!!i:this._addValueText=null,this._userInfoMessage="Verdien er allerede valgt";break;case s.length>1:this._addValueText=null,this._userInfoMessage="";break;default:this._addValueText=null,this._userInfoMessage=""}}findValueInOptions(e){return this.options.find(t=>t.value===e||t.label===e)||null}findIndexInOptions(e){return this._options.findIndex(t=>t.value===e||t.label===e)}isMaxItemsReached(){const e=this.maxlength!==null&&this._value.length>=this.maxlength;return e?this._maxIsReached=!0:this._maxIsReached=!1,e}toggleValue(e){var g,k;if(this.disabled)return;this.touched=!0,this._userInfoMessage="",this._addValueText=null;const t=((g=this.findValueInOptions(e))==null?void 0:g.value)||null,i=this._value.includes(e||t||""),s=!!t,n=((k=this._options.find(_=>_.value===e))==null?void 0:k.disabled)||!1,u=!(e!=null&&e.trim()),o=!this.multiple,h=this.multiple,x=this.isMaxItemsReached();let p=!1,f=!0,v="",m="";n||(!s&&this.allowUserInput&&!u?(this.addNewUserValue(e),v="Ny verdi lagt til",p=!h):!s&&!this.allowUserInput?(o&&this._value[0]&&this.removeValue(this._value[0]),f=!1,p=!0,v="Ingen treff i søket"):i?(this.removeValue(t),p=!0):u&&o?(this.removeAllSelected(),p=!0):o?(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())):h&&!x?(this.setSelected(t),p=!0):h&&x?(this._userInfoMessage="Maks antall valg nådd",f=!1,m=e):(o&&this.removeAllSelected(),this._userInfoMessage="Ingen gyldig verdi valgt",f=!1,p=!0,m=e),this._isOptionsOpen=p,p||window.setTimeout(()=>{var _;(_=this.focusRef.value)==null||_.focus()},0),this._userInfoMessage=v,this._search=m||"",this.resetComboboxInput(f),h&&this.isMaxItemsReached())}setSelected(e){if(!this._value.includes(e)){if(this.multiple&&this.isMaxItemsReached()){this._userInfoMessage="Maks antall valg nådd";return}!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)}}removeSelected(e){if(!e)return;this._value=this._value.filter(i=>i!==e);const t=this.findValueInOptions(e);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)))}addAllOptions(){if(this.multiple){if(this.maxlength&&this._options.length>this.maxlength){this._userInfoMessage="For mange valgt";return}this._value=this._options.map(e=>e.value),this._options=this._options.map(e=>(e.selected=!0,e)),this.requestUpdate()}}removeAllSelected(){this._value=[],this._options=this._options.map(e=>(e.selected=!1,e)),this._options=this._options.filter(e=>!e.userAdded),this.requestUpdate()}addValue(){var t;const e=((t=this.inputRef.value)==null?void 0:t.value.trim())||"";this._search=e,this.toggleValue(e)}removeValue(e){this._value=this.multiple?this._value.filter(t=>t!==e):[],this.removeSelected(e)}addNewUserValue(e){if(!e||e.trim()==="")return;if(!this.multiple)this._value[0]&&this.removeSelected(this._value[0]),this._value=[e],this._isOptionsOpen=!1,this.blurInput();else if(!this.findValueInOptions(e)){if(this.isMaxItemsReached())return;this._value=[...this._value,e]}const t={value:e,label:e,userAdded:!0};this.options=[t,...this.options],this._options=[t,...this._options],this.setSelected(e),this.requestUpdate()}resetComboboxInput(e=!0){if(this._addValueText=null,this.inputRef.value&&this.inputRef.value.type!=="hidden"&&e)if(this._search="",this.multiple)this.inputRef.value.value="";else{const t=this.findValueInOptions(this._value[0]);window.setTimeout(()=>{!this.inputRef.value||this.inputRef.value.type==="hidden"||(this.inputRef.value.value=this.displayValueAs==="label"&&(t!=null&&t.label)?t.label:this._value[0]||"")},0),this._userInfoMessage=""}this._options=[...this.options]}removeLastValue(e){if(this._value.length===0)return;e.preventDefault();const t=this._value[this._value.length-1];t&&this.removeSelected(t),this.isMaxItemsReached()}};a([l.n({type:String,reflect:!0})],exports.PktCombobox.prototype,"value",2);a([l.n({type:Array})],exports.PktCombobox.prototype,"options",2);a([l.n({type:Boolean})],exports.PktCombobox.prototype,"allowUserInput",2);a([l.n({type:Boolean})],exports.PktCombobox.prototype,"typeahead",2);a([l.n({type:Boolean})],exports.PktCombobox.prototype,"includeSearch",2);a([l.n({type:String})],exports.PktCombobox.prototype,"searchPlaceholder",2);a([l.n({type:Boolean})],exports.PktCombobox.prototype,"multiple",2);a([l.n({type:Number})],exports.PktCombobox.prototype,"maxlength",2);a([l.n({type:String})],exports.PktCombobox.prototype,"displayValueAs",2);a([l.n({type:String})],exports.PktCombobox.prototype,"tagPlacement",2);a([d.r()],exports.PktCombobox.prototype,"_options",2);a([d.r()],exports.PktCombobox.prototype,"_isOptionsOpen",2);a([d.r()],exports.PktCombobox.prototype,"_value",2);a([d.r()],exports.PktCombobox.prototype,"_userInfoMessage",2);a([d.r()],exports.PktCombobox.prototype,"_addValueText",2);a([d.r()],exports.PktCombobox.prototype,"_maxIsReached",2);a([d.r()],exports.PktCombobox.prototype,"_search",2);a([d.r()],exports.PktCombobox.prototype,"_inputFocus",2);a([d.r()],exports.PktCombobox.prototype,"_editingSingleValue",2);exports.PktCombobox=a([l.t("pkt-combobox")],exports.PktCombobox);
|
|
115
|
+
`});return e?t:i}renderValueTag(e){if(!e)return"";switch(this.displayValueAs){case"prefixAndValue":return a.x`<span data-focusfix=${this.id}>${e.prefix||""} ${e.value}</span>`;case"value":return a.x`<span data-focusfix=${this.id}>${e.value}</span>`;case"label":default:return a.x`<span data-focusfix=${this.id}>${e.label||e.value}</span>`}}handleInput(e){if(e.stopPropagation(),e.stopImmediatePropagation(),this.disabled)return;this.touched=!0;const t=e.target;if(this._search=t.value,this.checkForMatches(),this.typeahead)if(this._search){if(this._options=this.options.filter(i=>{var s;return(s=i.fulltext)==null?void 0:s.toLowerCase().includes(this._search.toLowerCase())}),e.inputType!=="deleteContentBackward"){const i=this._options.filter(s=>{var l;return!s.selected&&((l=s.label)==null?void 0:l.toLowerCase().startsWith(this._search.toLowerCase()))});if(i.length>0&&this.inputRef.value&&this.inputRef.value.type!=="hidden"){const s=i[0];s!=null&&s.label&&(t.value=s.label,window.setTimeout(()=>t.setSelectionRange(this._search.length,t.value.length),0),t.selectionDirection="backward")}}}else this._options=[...this.options]}handleFocus(){if(!this.disabled){if(!this.multiple&&this._value[0]&&this.inputRef.value&&this.inputRef.value.type!=="hidden"){const e=this.findValueInOptions(this._value[0]);this._editingSingleValue=!0,this.inputRef.value.value=this.displayValueAs==="label"&&(e!=null&&e.label)?e.label:this._value[0]}this._inputFocus=!0,this._search="",this._options=[...this.options],this._isOptionsOpen=!0,this.onFocus(),this.requestUpdate()}}handleFocusOut(e){var t,i,s,l,n;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){if(this._inputFocus=!1,this._addValueText=null,this._userInfoMessage="",this._search="",this.inputRef.value&&this.inputRef.value.type!=="hidden"&&this.inputRef.value.value!==""){const h=this.inputRef.value.value,u=this.findValueInOptions(h);!this._value.includes(h)&&!u?this.allowUserInput?this.addNewUserValue(h):this.multiple||this.removeValue(this._value[0]):u&&!this._value.includes(u.value)&&this.setSelected(u.value),this.inputRef.value.value=""}this._isOptionsOpen=!1,this.onBlur()}}handleBlur(){this._inputFocus=!1,this._editingSingleValue=!1,this.onBlur()}handleInputClick(e){var t,i;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.handleArrowClick(e))}handleArrowClick(e){var t,i;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())}handleOptionToggled(e){this.toggleValue(e.detail)}handleSearch(e){e.stopPropagation(),this._search=e.detail.toLowerCase()}handleInputKeydown(e){var t,i,s;switch(e.key){case",":case"Enter":e.preventDefault(),this.addValue();break;case"Backspace":!this._search&&((t=this.inputRef.value)==null?void 0:t.type)==="hidden"&&this.removeLastValue(e);break;case"Tab":case"ArrowDown":e.shiftKey||((i=this.listboxRef.value)==null||i.focusFirstOrSelectedOption(),e.preventDefault());break;case"Escape":this._isOptionsOpen=!1,(s=this.arrowRef.value)==null||s.focus(),e.preventDefault();break}}handleTagRemove(e){this.removeSelected(e)}blurInput(){this.inputRef.value&&this.inputRef.value.matches(":focus")&&this.inputRef.value.blur()}checkForMatches(){var n;const e=((n=this.inputRef.value)==null?void 0:n.value)||this._search||"",t=e.trim().toLowerCase()||"";if(!t){!this.multiple&&this._value[0]&&this.removeValue(this._value[0]),this.resetComboboxInput(!1);return}const i=this._value.find(h=>h.toLowerCase()===t),s=this._options.filter(h=>{var u;return((u=h.label)==null?void 0:u.toLowerCase().includes(t))??!1}),l=s.find(h=>{var u;return((u=h.label)==null?void 0:u.toLowerCase())===t||h.value.toLowerCase()===t});switch(!0){case((s.length===0||!l)&&this.allowUserInput):this._addValueText=e,this._userInfoMessage="";break;case(s.length===0&&!this.allowUserInput):this._addValueText=null,this._userInfoMessage="Ingen match i søket";break;case!!i:this._addValueText=null,this._userInfoMessage="Verdien er allerede valgt";break;case s.length>1:this._addValueText=null,this._userInfoMessage="";break;default:this._addValueText=null,this._userInfoMessage=""}}findValueInOptions(e){return this.options.find(t=>t.value===e||t.label===e)||null}findIndexInOptions(e){return this._options.findIndex(t=>t.value===e||t.label===e)}isMaxItemsReached(){const e=this.maxlength!==null&&this._value.length>=this.maxlength;return e?this._maxIsReached=!0:this._maxIsReached=!1,e}toggleValue(e){var g,k;if(this.disabled)return;this.touched=!0,this._userInfoMessage="",this._addValueText=null;const t=((g=this.findValueInOptions(e))==null?void 0:g.value)||null,i=this._value.includes(e||t||""),s=!!t,l=((k=this._options.find(_=>_.value===e))==null?void 0:k.disabled)||!1,n=!(e!=null&&e.trim()),h=!this.multiple,u=this.multiple,x=this.isMaxItemsReached();let p=!1,f=!0,v="",m="";l||(!s&&this.allowUserInput&&!n?(this.addNewUserValue(e),v="Ny verdi lagt til",p=!u):!s&&!this.allowUserInput?(h&&this._value[0]&&this.removeValue(this._value[0]),f=!1,p=!0,v="Ingen treff i søket"):i?(this.removeValue(t),p=!0):n&&h?(this.removeAllSelected(),p=!0):h?(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&&!x?(this.setSelected(t),p=!0):u&&x?(this._userInfoMessage="Maks antall valg nådd",f=!1,m=e):(h&&this.removeAllSelected(),this._userInfoMessage="Ingen gyldig verdi valgt",f=!1,p=!0,m=e),this._isOptionsOpen=p,p||window.setTimeout(()=>{var _;(_=this.focusRef.value)==null||_.focus()},0),this._userInfoMessage=v,this._search=m||"",this.resetComboboxInput(f),u&&this.isMaxItemsReached())}setSelected(e){if(!this._value.includes(e)){if(this.multiple&&this.isMaxItemsReached()){this._userInfoMessage="Maks antall valg nådd";return}!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)}}removeSelected(e){if(!e)return;this._value=this._value.filter(i=>i!==e);const t=this.findValueInOptions(e);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)))}addAllOptions(){if(this.multiple){if(this.maxlength&&this._options.length>this.maxlength){this._userInfoMessage="For mange valgt";return}this._value=this._options.map(e=>e.value),this._options=this._options.map(e=>(e.selected=!0,e)),this.requestUpdate()}}removeAllSelected(){this._value=[],this._options=this._options.map(e=>(e.selected=!1,e)),this._options=this._options.filter(e=>!e.userAdded),this.requestUpdate()}addValue(){var t;const e=((t=this.inputRef.value)==null?void 0:t.value.trim())||"";this._search=e,this.toggleValue(e)}removeValue(e){this._value=this.multiple?this._value.filter(t=>t!==e):[],this.removeSelected(e)}addNewUserValue(e){if(!e||e.trim()==="")return;if(!this.multiple)this._value[0]&&this.removeSelected(this._value[0]),this._value=[e],this._isOptionsOpen=!1,this.blurInput();else if(!this.findValueInOptions(e)){if(this.isMaxItemsReached())return;this._value=[...this._value,e]}const t={value:e,label:e,userAdded:!0};this.options=[t,...this.options],this._options=[t,...this._options],this.setSelected(e),this.requestUpdate()}resetComboboxInput(e=!0){if(this._addValueText=null,this.inputRef.value&&this.inputRef.value.type!=="hidden"&&e)if(this._search="",this.multiple)this.inputRef.value.value="";else{const t=this.findValueInOptions(this._value[0]);window.setTimeout(()=>{!this.inputRef.value||this.inputRef.value.type==="hidden"||(this.inputRef.value.value=this.displayValueAs==="label"&&(t!=null&&t.label)?t.label:this._value[0]||"")},0),this._userInfoMessage=""}this._options=[...this.options]}removeLastValue(e){if(this._value.length===0)return;e.preventDefault();const t=this._value[this._value.length-1];t&&this.removeSelected(t),this.isMaxItemsReached()}};o([a.n({type:String,reflect:!0})],exports.PktCombobox.prototype,"value",2);o([a.n({type:Array})],exports.PktCombobox.prototype,"options",2);o([a.n({type:Array})],exports.PktCombobox.prototype,"defaultOptions",2);o([a.n({type:Boolean})],exports.PktCombobox.prototype,"allowUserInput",2);o([a.n({type:Boolean})],exports.PktCombobox.prototype,"typeahead",2);o([a.n({type:Boolean})],exports.PktCombobox.prototype,"includeSearch",2);o([a.n({type:String})],exports.PktCombobox.prototype,"searchPlaceholder",2);o([a.n({type:Boolean})],exports.PktCombobox.prototype,"multiple",2);o([a.n({type:Number})],exports.PktCombobox.prototype,"maxlength",2);o([a.n({type:String})],exports.PktCombobox.prototype,"displayValueAs",2);o([a.n({type:String})],exports.PktCombobox.prototype,"tagPlacement",2);o([d.r()],exports.PktCombobox.prototype,"_options",2);o([d.r()],exports.PktCombobox.prototype,"_isOptionsOpen",2);o([d.r()],exports.PktCombobox.prototype,"_value",2);o([d.r()],exports.PktCombobox.prototype,"_userInfoMessage",2);o([d.r()],exports.PktCombobox.prototype,"_addValueText",2);o([d.r()],exports.PktCombobox.prototype,"_maxIsReached",2);o([d.r()],exports.PktCombobox.prototype,"_search",2);o([d.r()],exports.PktCombobox.prototype,"_inputFocus",2);o([d.r()],exports.PktCombobox.prototype,"_editingSingleValue",2);exports.PktCombobox=o([a.t("pkt-combobox")],exports.PktCombobox);
|
package/dist/index.d.ts
CHANGED
|
@@ -163,6 +163,7 @@ export declare interface IPktCombobox {
|
|
|
163
163
|
optionalTag?: boolean;
|
|
164
164
|
optionalText?: string;
|
|
165
165
|
options?: IPktComboboxOption[];
|
|
166
|
+
defaultOptions?: IPktComboboxOption[];
|
|
166
167
|
placeholder?: string | null;
|
|
167
168
|
requiredTag?: boolean;
|
|
168
169
|
requiredText?: string;
|
|
@@ -512,6 +513,7 @@ export declare class PktCombobox extends PktInputElement implements IPktCombobox
|
|
|
512
513
|
constructor();
|
|
513
514
|
value: string | string[];
|
|
514
515
|
options: IPktComboboxOption[];
|
|
516
|
+
defaultOptions: IPktComboboxOption[];
|
|
515
517
|
allowUserInput: boolean;
|
|
516
518
|
typeahead: boolean;
|
|
517
519
|
includeSearch: boolean;
|
package/dist/pkt-combobox.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./combobox-
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./combobox-DMkMUJfx.cjs"),o=e.PktCombobox;Object.defineProperty(exports,"PktCombobox",{enumerable:!0,get:()=>e.PktCombobox});exports.default=o;
|
package/dist/pkt-combobox.js
CHANGED
package/dist/pkt-index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("./alert-D2PhTV94.cjs"),l=require("./accordionitem-Dz6jwPpb.cjs"),d=require("./backlink-CcAZfB1d.cjs"),b=require("./button-KzBZ-Bff.cjs"),k=require("./calendar-BDeaGBaH.cjs"),m=require("./card-CmdIb2X9.cjs"),g=require("./combobox-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("./alert-D2PhTV94.cjs"),l=require("./accordionitem-Dz6jwPpb.cjs"),d=require("./backlink-CcAZfB1d.cjs"),b=require("./button-KzBZ-Bff.cjs"),k=require("./calendar-BDeaGBaH.cjs"),m=require("./card-CmdIb2X9.cjs"),g=require("./combobox-DMkMUJfx.cjs"),h=require("./consent-D1r9LYda.cjs"),f=require("./checkbox-CiXWukkL.cjs"),t=require("./element-90YeMNbV.cjs"),y=require("./pkt-slot-controller-Da-RgXfS.cjs"),s=require("./ref-B-w1vCo8.cjs"),O=require("./class-map-DWDPOqjO.cjs"),j=require("./datepicker-DpQV8G6g.cjs"),q=require("./helptext-AqNI_oFG.cjs"),x=require("./heading-CxJ0IqpU.cjs"),C=require("./icon-B1_BRNqf.cjs"),v=require("./input-wrapper-B_TtkGqo.cjs"),S=require("./link-BWJrqWi7.cjs"),$=require("./linkcard-0KLDuaGM.cjs"),L=require("./loader--5h6NKGl.cjs"),_=require("./messagebox-IJOkv427.cjs"),A=require("./modal-CBURcXBd.cjs"),B=require("./progressbar-BrXtjUvh.cjs"),p=require("./radiobutton-x10h-JEh.cjs"),T=require("./tag-lU4vz70a.cjs"),I=require("./textarea-j8kBS-hf.cjs"),M=require("./textinput-kmcj-FlC.cjs"),R=require("./select-BUvu5SFp.cjs");var H=Object.defineProperty,w=Object.getOwnPropertyDescriptor,o=(a,e,r,i)=>{for(var n=i>1?void 0:i?w(e,r):e,u=a.length-1,c;u>=0;u--)(c=a[u])&&(n=(i?c(e,r,n):c(n))||n);return i&&n&&H(e,r,n),n};exports.PktComponent=class extends t.PktElement{constructor(){super(),this.string="",this.strings=[],this.darkmode=!1,this._list=[],this.defaultSlot=s.e(),this.namedSlot=s.e(),this.slotController=new y.PktSlotController(this,this.defaultSlot,this.namedSlot)}connectedCallback(){this.strings.length&&this.strings.forEach(e=>{this._list.push(e.toUpperCase())}),super.connectedCallback()}render(){const e={"pkt-component":!0,"pkt-component--has-list":this.strings.length>0,"pkt-darkmode":this.darkmode};return t.x`
|
|
2
2
|
<div class="${O.e(e)}">
|
|
3
3
|
<h1 class="pkt-txt-28">${this.string}</h1>
|
|
4
4
|
|
package/dist/pkt-index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { P as T } from "./button-OLSvT2Im.js";
|
|
|
5
5
|
import { c as f } from "./calendar-Beno8yU7.js";
|
|
6
6
|
import { P as D } from "./calendar-Beno8yU7.js";
|
|
7
7
|
import { P as G } from "./card-BxHlJq4J.js";
|
|
8
|
-
import { P as K } from "./combobox-
|
|
8
|
+
import { P as K } from "./combobox-CavDENt-.js";
|
|
9
9
|
import { P as U } from "./consent-a09DlJZT.js";
|
|
10
10
|
import { P as q } from "./checkbox-B67_cfqW.js";
|
|
11
11
|
import { P as k, t as h, x as P, n, a as c } from "./element-gAd63VwC.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-elements",
|
|
3
|
-
"version": "12.41.
|
|
3
|
+
"version": "12.41.1",
|
|
4
4
|
"description": "Komponentbiblioteket til Punkt, et designsystem laget av Oslo Origo",
|
|
5
5
|
"homepage": "https://punkt.oslo.kommune.no",
|
|
6
6
|
"author": "Team Designsystem, Oslo Origo",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
60
60
|
},
|
|
61
61
|
"license": "MIT",
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "6af0ba1d43d2ba724a15b4d37c80ab62a68c8cae"
|
|
63
63
|
}
|
|
@@ -49,6 +49,7 @@ export interface IPktCombobox {
|
|
|
49
49
|
optionalTag?: boolean
|
|
50
50
|
optionalText?: string
|
|
51
51
|
options?: IPktComboboxOption[]
|
|
52
|
+
defaultOptions?: IPktComboboxOption[]
|
|
52
53
|
placeholder?: string | null
|
|
53
54
|
requiredTag?: boolean
|
|
54
55
|
requiredText?: string
|
|
@@ -79,6 +80,7 @@ export class PktCombobox extends PktInputElement implements IPktCombobox {
|
|
|
79
80
|
// Props / Attributes
|
|
80
81
|
@property({ type: String, reflect: true }) value: string | string[] = ''
|
|
81
82
|
@property({ type: Array }) options: IPktComboboxOption[] = []
|
|
83
|
+
@property({ type: Array }) defaultOptions: IPktComboboxOption[] = []
|
|
82
84
|
@property({ type: Boolean }) allowUserInput: boolean = false
|
|
83
85
|
@property({ type: Boolean }) typeahead: boolean = false
|
|
84
86
|
@property({ type: Boolean }) includeSearch: boolean = false
|
|
@@ -118,6 +120,15 @@ export class PktCombobox extends PktInputElement implements IPktCombobox {
|
|
|
118
120
|
})
|
|
119
121
|
|
|
120
122
|
this._options = []
|
|
123
|
+
|
|
124
|
+
// Deep clone defaultOptions into options, preserving userAdded options
|
|
125
|
+
if (this.defaultOptions && this.defaultOptions.length) {
|
|
126
|
+
const userAdded = this.options?.filter((opt) => opt.userAdded) || []
|
|
127
|
+
this.options = [...userAdded, ...structuredClone(this.defaultOptions)]
|
|
128
|
+
this._options = [...this.options]
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// If options are provided via the options slot, we need to extract them
|
|
121
132
|
if (this.optionsController.nodes.length) {
|
|
122
133
|
const options: IPktComboboxOption[] = []
|
|
123
134
|
this.optionsController.nodes.forEach((node: Element) => {
|
|
@@ -156,8 +167,23 @@ export class PktCombobox extends PktInputElement implements IPktCombobox {
|
|
|
156
167
|
}
|
|
157
168
|
this.isMaxItemsReached()
|
|
158
169
|
}
|
|
170
|
+
|
|
171
|
+
// If defaultOptions changed, update options (preserving userAdded)
|
|
172
|
+
if (changedProperties.has('defaultOptions') && this.defaultOptions.length) {
|
|
173
|
+
const userAdded = this.options?.filter((opt) => opt.userAdded) || []
|
|
174
|
+
this.options = [...userAdded, ...structuredClone(this.defaultOptions)]
|
|
175
|
+
this._options = [...this.options]
|
|
176
|
+
}
|
|
177
|
+
|
|
159
178
|
if (changedProperties.has('options') && this.options.length) {
|
|
160
|
-
|
|
179
|
+
// If options change, we need to update _options, but we need to preserve userAdded values
|
|
180
|
+
const userAddedValues = this._options.filter((option) => option.userAdded)
|
|
181
|
+
// Filter out userAddedValues that are overridden by this.options
|
|
182
|
+
const filteredUserAdded = userAddedValues.filter(
|
|
183
|
+
(userOpt) => !this.options.some((opt) => opt.value === userOpt.value),
|
|
184
|
+
)
|
|
185
|
+
// Merge, giving precedence to this.options
|
|
186
|
+
this._options = [...filteredUserAdded, ...this.options]
|
|
161
187
|
this._options.forEach((option) => {
|
|
162
188
|
if (option.value && !option.label) {
|
|
163
189
|
option.label = option.value
|
|
@@ -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
|
-
};
|