@oslokommune/punkt-elements 12.40.10 → 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.
@@ -1,121 +0,0 @@
1
- import { n as a, P as c, E as p, x as l, a as b } from "./element-gAd63VwC.js";
2
- import { P as f } from "./pkt-slot-controller-DtDaD9q_.js";
3
- import { e as u, n as k } from "./ref-DnSbnXsj.js";
4
- var m = Object.defineProperty, y = Object.getOwnPropertyDescriptor, e = (t, s, n, r) => {
5
- for (var o = r > 1 ? void 0 : r ? y(s, n) : s, d = t.length - 1, h; d >= 0; d--)
6
- (h = t[d]) && (o = (r ? h(s, n, o) : h(o)) || o);
7
- return r && o && m(s, n, o), o;
8
- };
9
- window.pktAnimationPath = window.pktAnimationPath || "https://punkt-cdn.oslo.kommune.no/latest/animations/";
10
- let i = class extends c {
11
- constructor() {
12
- super(), this.internals = this.attachInternals(), this.defaultSlot = u(), this.iconName = "user", this.secondIconName = "user", this.mode = "light", this.size = "medium", this.skin = "primary", this.variant = "label-only", this.state = "normal", this.type = "button", this.isLoading = !1, this.disabled = !1, this.loadingAnimationPath = window.pktAnimationPath, this.slotController = new f(this, this.defaultSlot);
13
- }
14
- // Lifecycle
15
- connectedCallback() {
16
- super.connectedCallback(), this.addEventListener("click", this.handleClick), this.addEventListener("keydown", this.handleKeydown);
17
- }
18
- disconnectedCallback() {
19
- super.disconnectedCallback(), this.removeEventListener("click", this.handleClick), this.removeEventListener("keydown", this.handleKeydown);
20
- }
21
- attributeChangedCallback(t, s, n) {
22
- super.attributeChangedCallback(t, s, n), t === "disabled" && n === "false" && (this.disabled = !1), (t === "isloading" || t === "isLoading") && n === "false" && (this.isLoading = !1);
23
- }
24
- firstUpdated(t) {
25
- super.firstUpdated(t), this.disabled === "false" && (this.disabled = !1), this.isLoading === "false" && (this.isLoading = !1);
26
- }
27
- updated(t) {
28
- super.updated(t), this.setAttribute("role", "button"), this.internals.role = "button", this.disabled === "false" && (this.disabled = !1), this.isLoading === "false" && (this.isLoading = !1), this.disabled ? (this.getAttribute("tabindex") !== "-1" && this.setAttribute("tabindex", "-1"), this.getAttribute("aria-disabled") !== "true" && this.setAttribute("aria-disabled", "true")) : (this.getAttribute("tabindex") !== "0" && this.setAttribute("tabindex", "0"), this.getAttribute("aria-disabled") !== "false" && this.removeAttribute("aria-disabled")), this.isLoading ? this.getAttribute("aria-busy") !== "true" && this.setAttribute("aria-busy", "true") : this.hasAttribute("aria-busy") && this.removeAttribute("aria-busy"), this.updateElementClasses();
29
- }
30
- // Render
31
- render() {
32
- return l`
33
- <div class="pkt-contents">
34
- ${this.isLoading ? l`<pkt-icon
35
- class="pkt-btn__icon pkt-btn__spinner"
36
- name="spinner-blue"
37
- path=${this.loadingAnimationPath}
38
- ></pkt-icon>` : p}
39
- ${this.variant !== "label-only" ? l`<pkt-icon class="pkt-btn__icon pkt-icon" name=${this.iconName}></pkt-icon>` : p}
40
- <span class="pkt-btn__text" ${k(this.defaultSlot)}></span>
41
- ${this.variant === "icons-right-and-left" ? l`<pkt-icon class="pkt-btn__icon" name=${this.secondIconName}></pkt-icon>` : p}
42
- </div>
43
- `;
44
- }
45
- // Methods
46
- updateElementClasses() {
47
- const t = /* @__PURE__ */ new Set(), s = this.getAttribute("class");
48
- t.add("pkt-btn"), s && s.split(" ").forEach((n) => t.add(n)), this.size && t.add(`pkt-btn--${this.size}`), this.skin && t.add(`pkt-btn--${this.skin}`), this.variant && t.add(`pkt-btn--${this.variant}`), this.color && t.add(`pkt-btn--${this.color}`), this.isLoading && t.add("pkt-btn--active"), this.state && t.add(`pkt-btn--${this.state}`), this.disabled && t.add("pkt-btn--disabled"), this.className = [...t].join(" ");
49
- }
50
- handleClick(t) {
51
- if (this.disabled || this.isLoading) {
52
- t.preventDefault(), t.stopImmediatePropagation();
53
- return;
54
- }
55
- if (this.type === "submit" && this.internals.form) {
56
- this.internals.form.requestSubmit();
57
- return;
58
- }
59
- if (this.type === "reset" && this.internals.form) {
60
- this.internals.form.reset();
61
- return;
62
- }
63
- this.onClick && typeof this.onClick == "function" && this.onClick !== this.handleClick && this.onClick(t), this.dispatchEvent(
64
- new CustomEvent("button-click", {
65
- bubbles: !0,
66
- composed: !0,
67
- detail: { originalEvent: t }
68
- })
69
- );
70
- }
71
- handleKeydown(t) {
72
- if (!(this.disabled || this.isLoading) && (t.key === "Enter" || t.key === " ")) {
73
- t.preventDefault();
74
- const s = t.target;
75
- s && s.click();
76
- }
77
- }
78
- };
79
- i.formAssociated = !0;
80
- e([
81
- a({ type: String })
82
- ], i.prototype, "iconName", 2);
83
- e([
84
- a({ type: String })
85
- ], i.prototype, "secondIconName", 2);
86
- e([
87
- a({ type: String })
88
- ], i.prototype, "mode", 2);
89
- e([
90
- a({ type: String })
91
- ], i.prototype, "size", 2);
92
- e([
93
- a({ type: String })
94
- ], i.prototype, "color", 2);
95
- e([
96
- a({ type: String })
97
- ], i.prototype, "skin", 2);
98
- e([
99
- a({ type: String })
100
- ], i.prototype, "variant", 2);
101
- e([
102
- a({ type: String, reflect: !0 })
103
- ], i.prototype, "state", 2);
104
- e([
105
- a({ type: String, reflect: !0 })
106
- ], i.prototype, "type", 2);
107
- e([
108
- a({ type: Boolean, reflect: !0 })
109
- ], i.prototype, "isLoading", 2);
110
- e([
111
- a({ type: Boolean, reflect: !0 })
112
- ], i.prototype, "disabled", 2);
113
- e([
114
- a({ type: String })
115
- ], i.prototype, "loadingAnimationPath", 2);
116
- i = e([
117
- b("pkt-button")
118
- ], i);
119
- export {
120
- i as P
121
- };
@@ -1,12 +0,0 @@
1
- "use strict";const i=require("./element-90YeMNbV.cjs"),h=require("./pkt-slot-controller-Da-RgXfS.cjs"),d=require("./ref-B-w1vCo8.cjs");var p=Object.defineProperty,u=Object.getOwnPropertyDescriptor,e=(o,t,s,n)=>{for(var a=n>1?void 0:n?u(t,s):t,r=o.length-1,l;r>=0;r--)(l=o[r])&&(a=(n?l(t,s,a):l(a))||a);return n&&a&&p(t,s,a),a};window.pktAnimationPath=window.pktAnimationPath||"https://punkt-cdn.oslo.kommune.no/latest/animations/";exports.PktButton=class extends i.PktElement{constructor(){super(),this.internals=this.attachInternals(),this.defaultSlot=d.e(),this.iconName="user",this.secondIconName="user",this.mode="light",this.size="medium",this.skin="primary",this.variant="label-only",this.state="normal",this.type="button",this.isLoading=!1,this.disabled=!1,this.loadingAnimationPath=window.pktAnimationPath,this.slotController=new h.PktSlotController(this,this.defaultSlot)}connectedCallback(){super.connectedCallback(),this.addEventListener("click",this.handleClick),this.addEventListener("keydown",this.handleKeydown)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("click",this.handleClick),this.removeEventListener("keydown",this.handleKeydown)}attributeChangedCallback(t,s,n){super.attributeChangedCallback(t,s,n),t==="disabled"&&n==="false"&&(this.disabled=!1),(t==="isloading"||t==="isLoading")&&n==="false"&&(this.isLoading=!1)}firstUpdated(t){super.firstUpdated(t),this.disabled==="false"&&(this.disabled=!1),this.isLoading==="false"&&(this.isLoading=!1)}updated(t){super.updated(t),this.setAttribute("role","button"),this.internals.role="button",this.disabled==="false"&&(this.disabled=!1),this.isLoading==="false"&&(this.isLoading=!1),this.disabled?(this.getAttribute("tabindex")!=="-1"&&this.setAttribute("tabindex","-1"),this.getAttribute("aria-disabled")!=="true"&&this.setAttribute("aria-disabled","true")):(this.getAttribute("tabindex")!=="0"&&this.setAttribute("tabindex","0"),this.getAttribute("aria-disabled")!=="false"&&this.removeAttribute("aria-disabled")),this.isLoading?this.getAttribute("aria-busy")!=="true"&&this.setAttribute("aria-busy","true"):this.hasAttribute("aria-busy")&&this.removeAttribute("aria-busy"),this.updateElementClasses()}render(){return i.x`
2
- <div class="pkt-contents">
3
- ${this.isLoading?i.x`<pkt-icon
4
- class="pkt-btn__icon pkt-btn__spinner"
5
- name="spinner-blue"
6
- path=${this.loadingAnimationPath}
7
- ></pkt-icon>`:i.E}
8
- ${this.variant!=="label-only"?i.x`<pkt-icon class="pkt-btn__icon pkt-icon" name=${this.iconName}></pkt-icon>`:i.E}
9
- <span class="pkt-btn__text" ${d.n(this.defaultSlot)}></span>
10
- ${this.variant==="icons-right-and-left"?i.x`<pkt-icon class="pkt-btn__icon" name=${this.secondIconName}></pkt-icon>`:i.E}
11
- </div>
12
- `}updateElementClasses(){const t=new Set,s=this.getAttribute("class");t.add("pkt-btn"),s&&s.split(" ").forEach(n=>t.add(n)),this.size&&t.add(`pkt-btn--${this.size}`),this.skin&&t.add(`pkt-btn--${this.skin}`),this.variant&&t.add(`pkt-btn--${this.variant}`),this.color&&t.add(`pkt-btn--${this.color}`),this.isLoading&&t.add("pkt-btn--active"),this.state&&t.add(`pkt-btn--${this.state}`),this.disabled&&t.add("pkt-btn--disabled"),this.className=[...t].join(" ")}handleClick(t){if(this.disabled||this.isLoading){t.preventDefault(),t.stopImmediatePropagation();return}if(this.type==="submit"&&this.internals.form){this.internals.form.requestSubmit();return}if(this.type==="reset"&&this.internals.form){this.internals.form.reset();return}this.onClick&&typeof this.onClick=="function"&&this.onClick!==this.handleClick&&this.onClick(t),this.dispatchEvent(new CustomEvent("button-click",{bubbles:!0,composed:!0,detail:{originalEvent:t}}))}handleKeydown(t){if(!(this.disabled||this.isLoading)&&(t.key==="Enter"||t.key===" ")){t.preventDefault();const s=t.target;s&&s.click()}}};exports.PktButton.formAssociated=!0;e([i.n({type:String})],exports.PktButton.prototype,"iconName",2);e([i.n({type:String})],exports.PktButton.prototype,"secondIconName",2);e([i.n({type:String})],exports.PktButton.prototype,"mode",2);e([i.n({type:String})],exports.PktButton.prototype,"size",2);e([i.n({type:String})],exports.PktButton.prototype,"color",2);e([i.n({type:String})],exports.PktButton.prototype,"skin",2);e([i.n({type:String})],exports.PktButton.prototype,"variant",2);e([i.n({type:String,reflect:!0})],exports.PktButton.prototype,"state",2);e([i.n({type:String,reflect:!0})],exports.PktButton.prototype,"type",2);e([i.n({type:Boolean,reflect:!0})],exports.PktButton.prototype,"isLoading",2);e([i.n({type:Boolean,reflect:!0})],exports.PktButton.prototype,"disabled",2);e([i.n({type:String})],exports.PktButton.prototype,"loadingAnimationPath",2);exports.PktButton=e([i.t("pkt-button")],exports.PktButton);
@@ -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
- };