@oslokommune/punkt-elements 12.40.0 → 12.40.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 CHANGED
@@ -5,6 +5,23 @@ og skriver commits ca etter [Conventional Commits](https://conventionalcommits.o
5
5
 
6
6
  ---
7
7
 
8
+ ## [12.40.1](https://github.com/oslokommune/punkt/compare/12.40.0...12.40.1) (2025-05-20)
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.39.8](https://github.com/oslokommune/punkt/compare/12.39.7...12.39.8) (2025-05-19)
9
26
 
10
27
  ### ⚠ BREAKING CHANGES
package/dist/index.d.ts CHANGED
@@ -295,6 +295,7 @@ export declare interface IPktProgressbar {
295
295
 
296
296
  declare interface IPktSelect {
297
297
  options: TSelectOption[];
298
+ value: string;
298
299
  }
299
300
 
300
301
  declare interface IPktTag {
@@ -1029,12 +1030,20 @@ export declare class PktSelect extends PktInputElement implements IPktSelect {
1029
1030
  options: TSelectOption[];
1030
1031
  value: string;
1031
1032
  private _options;
1033
+ selectedIndex: number | null;
1034
+ selectedOptions: HTMLCollectionOf<HTMLOptionElement> | undefined;
1032
1035
  constructor();
1033
1036
  connectedCallback(): void;
1037
+ add(item: HTMLOptionElement, before?: HTMLOptionElement | number): void;
1038
+ remove(item?: number): void;
1039
+ item(index: number): HTMLOptionElement | null | undefined;
1040
+ namedItem(name: string): HTMLOptionElement | null | undefined;
1041
+ showPicker(): void;
1034
1042
  attributeChangedCallback(name: string, _old: string, value: string): void;
1035
- updated(changedProperties: PropertyValues): void;
1043
+ update(changedProperties: PropertyValues): void;
1036
1044
  protected firstUpdated(_changedProperties: PropertyValues): void;
1037
1045
  render(): TemplateResult<1>;
1046
+ private returnNumberOrNull;
1038
1047
  }
1039
1048
 
1040
1049
  /**
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("./alert-C2EPmB0W.cjs"),l=require("./accordionitem-RFwXQC_0.cjs"),d=require("./backlink-HHM21crL.cjs"),b=require("./button-C60j8BsA.cjs"),k=require("./calendar-CYY42kN4.cjs"),m=require("./card-C8wbJJyj.cjs"),g=require("./combobox-dwkB9Yv_.cjs"),h=require("./consent-1ZSUrWK9.cjs"),f=require("./checkbox-7ct89AUo.cjs"),t=require("./element-BSypUpzA.cjs"),y=require("./pkt-slot-controller-Da-RgXfS.cjs"),s=require("./ref-BvbyvXRH.cjs"),O=require("./class-map-DCyaICmy.cjs"),j=require("./datepicker-BDnncwne.cjs"),q=require("./helptext-bMgnhZ1R.cjs"),x=require("./heading-BnJhJDMD.cjs"),C=require("./icon-BnKGwYjj.cjs"),v=require("./input-wrapper-B-f_SotM.cjs"),S=require("./link-nesPZCIx.cjs"),$=require("./linkcard-s9yoOq90.cjs"),L=require("./loader-ndMy12Pb.cjs"),_=require("./messagebox-B0kgftoP.cjs"),A=require("./modal-C8GbUY8p.cjs"),B=require("./progressbar-DiRfScnB.cjs"),p=require("./radiobutton-DGWTMdAZ.cjs"),T=require("./tag-B9kFYxHg.cjs"),I=require("./textarea-yUzqcBYY.cjs"),M=require("./textinput-8mT0npMY.cjs"),R=require("./select-Brv7vglu.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`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("./alert-C2EPmB0W.cjs"),l=require("./accordionitem-RFwXQC_0.cjs"),d=require("./backlink-HHM21crL.cjs"),b=require("./button-C60j8BsA.cjs"),k=require("./calendar-CYY42kN4.cjs"),m=require("./card-C8wbJJyj.cjs"),g=require("./combobox-dwkB9Yv_.cjs"),h=require("./consent-1ZSUrWK9.cjs"),f=require("./checkbox-7ct89AUo.cjs"),t=require("./element-BSypUpzA.cjs"),y=require("./pkt-slot-controller-Da-RgXfS.cjs"),s=require("./ref-BvbyvXRH.cjs"),O=require("./class-map-DCyaICmy.cjs"),j=require("./datepicker-BDnncwne.cjs"),q=require("./helptext-bMgnhZ1R.cjs"),x=require("./heading-BnJhJDMD.cjs"),C=require("./icon-BnKGwYjj.cjs"),v=require("./input-wrapper-B-f_SotM.cjs"),S=require("./link-nesPZCIx.cjs"),$=require("./linkcard-s9yoOq90.cjs"),L=require("./loader-ndMy12Pb.cjs"),_=require("./messagebox-B0kgftoP.cjs"),A=require("./modal-C8GbUY8p.cjs"),B=require("./progressbar-DiRfScnB.cjs"),p=require("./radiobutton-DGWTMdAZ.cjs"),T=require("./tag-B9kFYxHg.cjs"),I=require("./textarea-yUzqcBYY.cjs"),M=require("./textinput-8mT0npMY.cjs"),R=require("./select-ChpPtH7u.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
@@ -27,7 +27,7 @@ import { P as ht, P as ct } from "./radiobutton-CET0zjgD.js";
27
27
  import { P as ut } from "./tag-Cu8afZy8.js";
28
28
  import { P as vt } from "./textarea-l10XGym1.js";
29
29
  import { P as bt } from "./textinput-B1n0gFaS.js";
30
- import { P as $t } from "./select-C36Z4gui.js";
30
+ import { P as $t } from "./select-C2Lr2fdU.js";
31
31
  var g = Object.defineProperty, v = Object.getOwnPropertyDescriptor, s = (t, e, i, a) => {
32
32
  for (var r = a > 1 ? void 0 : a ? v(e, i) : e, p = t.length - 1, l; p >= 0; p--)
33
33
  (l = t[p]) && (r = (a ? l(e, i, r) : l(r)) || r);
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./select-Brv7vglu.cjs"),t=e.PktSelect;Object.defineProperty(exports,"PktSelect",{enumerable:!0,get:()=>e.PktSelect});exports.default=t;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./select-ChpPtH7u.cjs"),t=e.PktSelect;Object.defineProperty(exports,"PktSelect",{enumerable:!0,get:()=>e.PktSelect});exports.default=t;
@@ -1,4 +1,4 @@
1
- import { P as t } from "./select-C36Z4gui.js";
1
+ import { P as t } from "./select-C2Lr2fdU.js";
2
2
  const a = t;
3
3
  export {
4
4
  t as PktSelect,
@@ -0,0 +1,153 @@
1
+ import { x as p, n as c, a as v } from "./element-DjjF_tEh.js";
2
+ import { r as f } from "./state-BtbpSrdV.js";
3
+ import { e as u, n as d } from "./ref-iIffqQAI.js";
4
+ import { o } from "./if-defined-BErSJCeJ.js";
5
+ import { P as b } from "./input-element-B2GjFOXX.js";
6
+ import { P as $ } from "./pkt-options-controller-DepYQBqb.js";
7
+ import { P as x } from "./pkt-slot-controller-DtDaD9q_.js";
8
+ import "./input-wrapper-BdeoMGnk.js";
9
+ var m = Object.defineProperty, g = Object.getOwnPropertyDescriptor, r = (t, e, s, i) => {
10
+ for (var l = i > 1 ? void 0 : i ? g(e, s) : e, n = t.length - 1, h; n >= 0; n--)
11
+ (h = t[n]) && (l = (i ? h(e, s, l) : h(l)) || l);
12
+ return i && l && m(e, s, l), l;
13
+ };
14
+ let a = class extends b {
15
+ constructor() {
16
+ super(), this.inputRef = u(), this.helptextSlot = u(), this.options = [], this.value = "", this._options = [], this.selectedIndex = -1, this.selectedOptions = void 0, this.optionsController = new $(this), this.slotController = new x(this, this.helptextSlot), this.slotController.skipOptions = !0;
17
+ }
18
+ // Used for initilization
19
+ connectedCallback() {
20
+ super.connectedCallback();
21
+ const t = this.options.length > 0, e = this.optionsController.nodes.length && this.optionsController.nodes.length > 0;
22
+ !t && e ? this.optionsController.nodes.forEach((s) => {
23
+ const i = {
24
+ value: s.getAttribute("value") || s.textContent || "",
25
+ label: s.textContent || s.getAttribute("value") || "",
26
+ disabled: !!s.getAttribute("disabled")
27
+ };
28
+ s.getAttribute("selected") && !this.value && (this.value = i.value), this._options.push(i);
29
+ }) : (this._options = this.options, this._options.forEach((s) => {
30
+ s.selected && !this.value && (this.value = s.value);
31
+ }));
32
+ }
33
+ // Support native Select method `add`
34
+ add(t, e) {
35
+ var s, i, l;
36
+ (s = this.inputRef.value) == null || s.add(t, e), this._options.push({
37
+ value: t.value || t.text,
38
+ label: t.text || t.value,
39
+ selected: t.selected,
40
+ disabled: t.disabled
41
+ }), t.selected && (this.value = t.value || t.text, this.selectedIndex = this.returnNumberOrNull((i = this.inputRef.value) == null ? void 0 : i.selectedIndex), this.selectedOptions = (l = this.inputRef.value) == null ? void 0 : l.selectedOptions), this.requestUpdate();
42
+ }
43
+ // Support native Select method `remove`
44
+ remove(t) {
45
+ var e, s;
46
+ typeof t == "number" && ((e = this.inputRef.value) == null || e.remove(t), this._options.splice(t, 1), this.selectedIndex === t && (this.value = ((s = this._options[0]) == null ? void 0 : s.value) || ""));
47
+ }
48
+ // Support native Select method `item`
49
+ item(t) {
50
+ var e;
51
+ return (e = this.inputRef.value) == null ? void 0 : e.item(t);
52
+ }
53
+ // Support native Select method `namedItem`
54
+ namedItem(t) {
55
+ var e;
56
+ return (e = this.inputRef.value) == null ? void 0 : e.namedItem(t);
57
+ }
58
+ // Support native Select method `showPicker`
59
+ showPicker() {
60
+ var t;
61
+ (t = this.inputRef.value) == null || t.showPicker();
62
+ }
63
+ attributeChangedCallback(t, e, s) {
64
+ var i, l;
65
+ t === "options" && (this._options = s ? JSON.parse(s) : []), t === "value" && this.value !== e && (this.selectedIndex = this.touched ? this.returnNumberOrNull((i = this.inputRef.value) == null ? void 0 : i.selectedIndex) : this.options.findIndex((n) => n.value === s), this.selectedOptions = (l = this.inputRef.value) == null ? void 0 : l.selectedOptions, this.valueChanged(s, e)), super.attributeChangedCallback(t, e, s);
66
+ }
67
+ update(t) {
68
+ var e, s;
69
+ super.update(t), t.has("value") && this.value !== t.get("value") && (this.selectedIndex = this.touched ? this.returnNumberOrNull((e = this.inputRef.value) == null ? void 0 : e.selectedIndex) : this.options.findIndex((i) => i.value === this.value), this.selectedOptions = (s = this.inputRef.value) == null ? void 0 : s.selectedOptions, this.valueChanged(this.value, t.get("value"))), t.has("id") && !this.name && this.id && (this.name = this.id);
70
+ }
71
+ firstUpdated(t) {
72
+ var e;
73
+ super.firstUpdated(t), this.options.length && (this._options = this.options), !this.value && this._options.length > 0 ? (this.value = this._options[0].value, this.selectedIndex = 0) : this.selectedIndex = this._options.findIndex((s) => s.value === this.value), this.selectedOptions = (e = this.inputRef.value) == null ? void 0 : e.selectedOptions;
74
+ }
75
+ render() {
76
+ const t = `pkt-input ${this.fullwidth ? "pkt-input--fullwidth" : ""}`;
77
+ return p`
78
+ <pkt-input-wrapper
79
+ ?counter=${this.counter}
80
+ ?disabled=${this.disabled}
81
+ ?hasError=${this.hasError}
82
+ ?hasFieldset=${this.hasFieldset}
83
+ ?inline=${this.inline}
84
+ ?optionalTag=${this.optionalTag}
85
+ ?requiredTag=${this.requiredTag}
86
+ ?useWrapper=${this.useWrapper}
87
+ ariaDescribedBy=${o(this.ariaDescribedBy)}
88
+ class="pkt-select"
89
+ errorMessage=${o(this.errorMessage)}
90
+ forId=${this.id + "-input"}
91
+ helptext=${o(this.helptext)}
92
+ helptextDropdown=${o(this.helptextDropdown)}
93
+ helptextDropdownButton=${o(this.helptextDropdownButton)}
94
+ label=${o(this.label)}
95
+ optionalText=${o(this.optionalText)}
96
+ requiredText=${o(this.requiredText)}
97
+ >
98
+ <select
99
+ class=${t}
100
+ aria-invalid=${this.hasError}
101
+ aria-errormessage=${`${this.id}-error`}
102
+ aria-labelledby=${o(this.ariaLabelledby)}
103
+ ?disabled=${this.disabled}
104
+ id=${this.id + "-input"}
105
+ name=${(this.name || this.id) + "-input"}
106
+ value=${this.value}
107
+ @change=${(e) => {
108
+ this.value = e.target.value, e.stopImmediatePropagation();
109
+ }}
110
+ @input=${(e) => {
111
+ this.onInput(), e.stopImmediatePropagation();
112
+ }}
113
+ @focus=${(e) => {
114
+ this.onFocus(), e.stopImmediatePropagation();
115
+ }}
116
+ @blur=${(e) => {
117
+ this.onBlur(), e.stopImmediatePropagation();
118
+ }}
119
+ ${d(this.inputRef)}
120
+ >
121
+ ${this._options.length > 0 && this._options.map(
122
+ (e) => p`<option
123
+ value=${e.value}
124
+ ?selected=${this.value == e.value || e.selected}
125
+ ?disabled=${e.disabled}
126
+ >
127
+ ${e.label}
128
+ </option>`
129
+ )}
130
+ </select>
131
+ <div class="pkt-contents" ${d(this.helptextSlot)} name="helptext" slot="helptext"></div>
132
+ </pkt-input-wrapper>
133
+ `;
134
+ }
135
+ returnNumberOrNull(t) {
136
+ return t == null || isNaN(t) ? null : t;
137
+ }
138
+ };
139
+ r([
140
+ c({ type: Array })
141
+ ], a.prototype, "options", 2);
142
+ r([
143
+ c({ type: String })
144
+ ], a.prototype, "value", 2);
145
+ r([
146
+ f()
147
+ ], a.prototype, "_options", 2);
148
+ a = r([
149
+ v("pkt-select")
150
+ ], a);
151
+ export {
152
+ a as P
153
+ };
@@ -0,0 +1,47 @@
1
+ "use strict";const r=require("./element-BSypUpzA.cjs"),p=require("./state-B5KCNjEd.cjs"),h=require("./ref-BvbyvXRH.cjs"),o=require("./if-defined-a3sotaUr.cjs"),d=require("./input-element-DK0UmdGZ.cjs"),c=require("./pkt-options-controller-Ay9ELZTV.cjs"),v=require("./pkt-slot-controller-Da-RgXfS.cjs");require("./input-wrapper-B-f_SotM.cjs");var f=Object.defineProperty,b=Object.getOwnPropertyDescriptor,a=(u,t,e,s)=>{for(var i=s>1?void 0:s?b(t,e):t,l=u.length-1,n;l>=0;l--)(n=u[l])&&(i=(s?n(t,e,i):n(i))||i);return s&&i&&f(t,e,i),i};exports.PktSelect=class extends d.PktInputElement{constructor(){super(),this.inputRef=h.e(),this.helptextSlot=h.e(),this.options=[],this.value="",this._options=[],this.selectedIndex=-1,this.selectedOptions=void 0,this.optionsController=new c.PktOptionsSlotController(this),this.slotController=new v.PktSlotController(this,this.helptextSlot),this.slotController.skipOptions=!0}connectedCallback(){super.connectedCallback();const t=this.options.length>0,e=this.optionsController.nodes.length&&this.optionsController.nodes.length>0;!t&&e?this.optionsController.nodes.forEach(s=>{const i={value:s.getAttribute("value")||s.textContent||"",label:s.textContent||s.getAttribute("value")||"",disabled:!!s.getAttribute("disabled")};s.getAttribute("selected")&&!this.value&&(this.value=i.value),this._options.push(i)}):(this._options=this.options,this._options.forEach(s=>{s.selected&&!this.value&&(this.value=s.value)}))}add(t,e){var s,i,l;(s=this.inputRef.value)==null||s.add(t,e),this._options.push({value:t.value||t.text,label:t.text||t.value,selected:t.selected,disabled:t.disabled}),t.selected&&(this.value=t.value||t.text,this.selectedIndex=this.returnNumberOrNull((i=this.inputRef.value)==null?void 0:i.selectedIndex),this.selectedOptions=(l=this.inputRef.value)==null?void 0:l.selectedOptions),this.requestUpdate()}remove(t){var e,s;typeof t=="number"&&((e=this.inputRef.value)==null||e.remove(t),this._options.splice(t,1),this.selectedIndex===t&&(this.value=((s=this._options[0])==null?void 0:s.value)||""))}item(t){var e;return(e=this.inputRef.value)==null?void 0:e.item(t)}namedItem(t){var e;return(e=this.inputRef.value)==null?void 0:e.namedItem(t)}showPicker(){var t;(t=this.inputRef.value)==null||t.showPicker()}attributeChangedCallback(t,e,s){var i,l;t==="options"&&(this._options=s?JSON.parse(s):[]),t==="value"&&this.value!==e&&(this.selectedIndex=this.touched?this.returnNumberOrNull((i=this.inputRef.value)==null?void 0:i.selectedIndex):this.options.findIndex(n=>n.value===s),this.selectedOptions=(l=this.inputRef.value)==null?void 0:l.selectedOptions,this.valueChanged(s,e)),super.attributeChangedCallback(t,e,s)}update(t){var e,s;super.update(t),t.has("value")&&this.value!==t.get("value")&&(this.selectedIndex=this.touched?this.returnNumberOrNull((e=this.inputRef.value)==null?void 0:e.selectedIndex):this.options.findIndex(i=>i.value===this.value),this.selectedOptions=(s=this.inputRef.value)==null?void 0:s.selectedOptions,this.valueChanged(this.value,t.get("value"))),t.has("id")&&!this.name&&this.id&&(this.name=this.id)}firstUpdated(t){var e;super.firstUpdated(t),this.options.length&&(this._options=this.options),!this.value&&this._options.length>0?(this.value=this._options[0].value,this.selectedIndex=0):this.selectedIndex=this._options.findIndex(s=>s.value===this.value),this.selectedOptions=(e=this.inputRef.value)==null?void 0:e.selectedOptions}render(){const t=`pkt-input ${this.fullwidth?"pkt-input--fullwidth":""}`;return r.x`
2
+ <pkt-input-wrapper
3
+ ?counter=${this.counter}
4
+ ?disabled=${this.disabled}
5
+ ?hasError=${this.hasError}
6
+ ?hasFieldset=${this.hasFieldset}
7
+ ?inline=${this.inline}
8
+ ?optionalTag=${this.optionalTag}
9
+ ?requiredTag=${this.requiredTag}
10
+ ?useWrapper=${this.useWrapper}
11
+ ariaDescribedBy=${o.o(this.ariaDescribedBy)}
12
+ class="pkt-select"
13
+ errorMessage=${o.o(this.errorMessage)}
14
+ forId=${this.id+"-input"}
15
+ helptext=${o.o(this.helptext)}
16
+ helptextDropdown=${o.o(this.helptextDropdown)}
17
+ helptextDropdownButton=${o.o(this.helptextDropdownButton)}
18
+ label=${o.o(this.label)}
19
+ optionalText=${o.o(this.optionalText)}
20
+ requiredText=${o.o(this.requiredText)}
21
+ >
22
+ <select
23
+ class=${t}
24
+ aria-invalid=${this.hasError}
25
+ aria-errormessage=${`${this.id}-error`}
26
+ aria-labelledby=${o.o(this.ariaLabelledby)}
27
+ ?disabled=${this.disabled}
28
+ id=${this.id+"-input"}
29
+ name=${(this.name||this.id)+"-input"}
30
+ value=${this.value}
31
+ @change=${e=>{this.value=e.target.value,e.stopImmediatePropagation()}}
32
+ @input=${e=>{this.onInput(),e.stopImmediatePropagation()}}
33
+ @focus=${e=>{this.onFocus(),e.stopImmediatePropagation()}}
34
+ @blur=${e=>{this.onBlur(),e.stopImmediatePropagation()}}
35
+ ${h.n(this.inputRef)}
36
+ >
37
+ ${this._options.length>0&&this._options.map(e=>r.x`<option
38
+ value=${e.value}
39
+ ?selected=${this.value==e.value||e.selected}
40
+ ?disabled=${e.disabled}
41
+ >
42
+ ${e.label}
43
+ </option>`)}
44
+ </select>
45
+ <div class="pkt-contents" ${h.n(this.helptextSlot)} name="helptext" slot="helptext"></div>
46
+ </pkt-input-wrapper>
47
+ `}returnNumberOrNull(t){return t==null||isNaN(t)?null:t}};a([r.n({type:Array})],exports.PktSelect.prototype,"options",2);a([r.n({type:String})],exports.PktSelect.prototype,"value",2);a([p.r()],exports.PktSelect.prototype,"_options",2);exports.PktSelect=a([r.t("pkt-select")],exports.PktSelect);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oslokommune/punkt-elements",
3
- "version": "12.40.0",
3
+ "version": "12.40.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": "01a4a75820f2c854bd51a4fa590bedf37e2ce8ce"
62
+ "gitHead": "6bd6f3b4b95dc4beadf43392788dfd17d1f37efc"
63
63
  }
@@ -16,6 +16,7 @@ export type TSelectOption = {
16
16
 
17
17
  export interface IPktSelect {
18
18
  options: TSelectOption[]
19
+ value: string
19
20
  }
20
21
 
21
22
  /**
@@ -42,10 +43,13 @@ export class PktSelect extends PktInputElement implements IPktSelect {
42
43
  private helptextSlot: Ref<HTMLElement> = createRef()
43
44
 
44
45
  @property({ type: Array }) options: TSelectOption[] = []
45
- @property({ type: String, reflect: true }) value: string = ''
46
+ @property({ type: String }) value: string = ''
46
47
 
47
48
  @state() private _options: TSelectOption[] = []
48
49
 
50
+ public selectedIndex: number | null = -1
51
+ public selectedOptions: HTMLCollectionOf<HTMLOptionElement> | undefined = undefined
52
+
49
53
  constructor() {
50
54
  super()
51
55
  this.optionsController = new PktOptionsSlotController(this)
@@ -75,23 +79,78 @@ export class PktSelect extends PktInputElement implements IPktSelect {
75
79
  })
76
80
  } else {
77
81
  this._options = this.options
82
+ this._options.forEach((option) => {
83
+ if (option.selected && !this.value) {
84
+ this.value = option.value
85
+ }
86
+ })
87
+ }
88
+ }
89
+
90
+ // Support native Select method `add`
91
+ public add(item: HTMLOptionElement, before?: HTMLOptionElement | number) {
92
+ this.inputRef.value?.add(item, before)
93
+ this._options.push({
94
+ value: item.value || item.text,
95
+ label: item.text || item.value,
96
+ selected: item.selected,
97
+ disabled: item.disabled,
98
+ })
99
+ if (item.selected) {
100
+ this.value = item.value || item.text
101
+ this.selectedIndex = this.returnNumberOrNull(this.inputRef.value?.selectedIndex)
102
+ this.selectedOptions = this.inputRef.value?.selectedOptions
103
+ }
104
+ this.requestUpdate()
105
+ }
106
+
107
+ // Support native Select method `remove`
108
+ public remove(item?: number) {
109
+ if (typeof item === 'number') {
110
+ this.inputRef.value?.remove(item)
111
+ this._options.splice(item, 1)
112
+ if (this.selectedIndex === item) {
113
+ this.value = this._options[0]?.value || ''
114
+ }
78
115
  }
79
116
  }
80
117
 
118
+ // Support native Select method `item`
119
+ public item(index: number) {
120
+ return this.inputRef.value?.item(index)
121
+ }
122
+
123
+ // Support native Select method `namedItem`
124
+ public namedItem(name: string) {
125
+ return this.inputRef.value?.namedItem(name)
126
+ }
127
+
128
+ // Support native Select method `showPicker`
129
+ public showPicker() {
130
+ this.inputRef.value?.showPicker()
131
+ }
132
+
81
133
  public attributeChangedCallback(name: string, _old: string, value: string): void {
82
134
  if (name === 'options') {
83
135
  this._options = value ? JSON.parse(value) : []
84
136
  }
85
137
  if (name === 'value' && this.value !== _old) {
138
+ this.selectedIndex = this.touched
139
+ ? this.returnNumberOrNull(this.inputRef.value?.selectedIndex)
140
+ : this.options.findIndex((option) => option.value === value)
141
+ this.selectedOptions = this.inputRef.value?.selectedOptions
86
142
  this.valueChanged(value, _old)
87
143
  }
88
144
  super.attributeChangedCallback(name, _old, value)
89
145
  }
90
146
 
91
- updated(changedProperties: PropertyValues) {
92
- super.updated(changedProperties)
93
- if (changedProperties.has('value')) {
94
- this.counterCurrent = this.value?.length || 0
147
+ update(changedProperties: PropertyValues) {
148
+ super.update(changedProperties)
149
+ if (changedProperties.has('value') && this.value !== changedProperties.get('value')) {
150
+ this.selectedIndex = this.touched
151
+ ? this.returnNumberOrNull(this.inputRef.value?.selectedIndex)
152
+ : this.options.findIndex((option) => option.value === this.value)
153
+ this.selectedOptions = this.inputRef.value?.selectedOptions
95
154
  this.valueChanged(this.value, changedProperties.get('value'))
96
155
  }
97
156
  if (changedProperties.has('id')) {
@@ -104,6 +163,14 @@ export class PktSelect extends PktInputElement implements IPktSelect {
104
163
  if (this.options.length) {
105
164
  this._options = this.options
106
165
  }
166
+ // If no options are selected, set value and selectedIndex to the first option
167
+ if (!this.value && this._options.length > 0) {
168
+ this.value = this._options[0].value
169
+ this.selectedIndex = 0
170
+ } else {
171
+ this.selectedIndex = this._options.findIndex((option) => option.value === this.value)
172
+ }
173
+ this.selectedOptions = this.inputRef.value?.selectedOptions
107
174
  }
108
175
 
109
176
  render() {
@@ -120,8 +187,6 @@ export class PktSelect extends PktInputElement implements IPktSelect {
120
187
  ?requiredTag=${this.requiredTag}
121
188
  ?useWrapper=${this.useWrapper}
122
189
  ariaDescribedBy=${ifDefined(this.ariaDescribedBy)}
123
- .counterCurrent=${this.counterCurrent}
124
- .counterMaxLength=${this.counterMaxLength}
125
190
  class="pkt-select"
126
191
  errorMessage=${ifDefined(this.errorMessage)}
127
192
  forId=${this.id + '-input'}
@@ -164,7 +229,7 @@ export class PktSelect extends PktInputElement implements IPktSelect {
164
229
  (option) =>
165
230
  html`<option
166
231
  value=${option.value}
167
- ?selected=${this.value == option.value}
232
+ ?selected=${this.value == option.value || option.selected}
168
233
  ?disabled=${option.disabled}
169
234
  >
170
235
  ${option.label}
@@ -175,4 +240,11 @@ export class PktSelect extends PktInputElement implements IPktSelect {
175
240
  </pkt-input-wrapper>
176
241
  `
177
242
  }
243
+
244
+ private returnNumberOrNull(value: number | null | undefined): number | null {
245
+ if (value === undefined || value === null || isNaN(value)) {
246
+ return null
247
+ }
248
+ return value
249
+ }
178
250
  }
@@ -1,49 +0,0 @@
1
- "use strict";const r=require("./element-BSypUpzA.cjs"),u=require("./state-B5KCNjEd.cjs"),l=require("./ref-BvbyvXRH.cjs"),o=require("./if-defined-a3sotaUr.cjs"),d=require("./input-element-DK0UmdGZ.cjs"),c=require("./pkt-options-controller-Ay9ELZTV.cjs"),$=require("./pkt-slot-controller-Da-RgXfS.cjs");require("./input-wrapper-B-f_SotM.cjs");var b=Object.defineProperty,v=Object.getOwnPropertyDescriptor,n=(a,e,t,i)=>{for(var s=i>1?void 0:i?v(e,t):e,p=a.length-1,h;p>=0;p--)(h=a[p])&&(s=(i?h(e,t,s):h(s))||s);return i&&s&&b(e,t,s),s};exports.PktSelect=class extends d.PktInputElement{constructor(){super(),this.inputRef=l.e(),this.helptextSlot=l.e(),this.options=[],this.value="",this._options=[],this.optionsController=new c.PktOptionsSlotController(this),this.slotController=new $.PktSlotController(this,this.helptextSlot),this.slotController.skipOptions=!0}connectedCallback(){super.connectedCallback();const e=this.options.length>0,t=this.optionsController.nodes.length&&this.optionsController.nodes.length>0;!e&&t?this.optionsController.nodes.forEach(i=>{const s={value:i.getAttribute("value")||i.textContent||"",label:i.textContent||i.getAttribute("value")||"",disabled:!!i.getAttribute("disabled")};i.getAttribute("selected")&&!this.value&&(this.value=s.value),this._options.push(s)}):this._options=this.options}attributeChangedCallback(e,t,i){e==="options"&&(this._options=i?JSON.parse(i):[]),e==="value"&&this.value!==t&&this.valueChanged(i,t),super.attributeChangedCallback(e,t,i)}updated(e){var t;super.updated(e),e.has("value")&&(this.counterCurrent=((t=this.value)==null?void 0:t.length)||0,this.valueChanged(this.value,e.get("value"))),e.has("id")&&!this.name&&this.id&&(this.name=this.id)}firstUpdated(e){super.firstUpdated(e),this.options.length&&(this._options=this.options)}render(){const e=`pkt-input ${this.fullwidth?"pkt-input--fullwidth":""}`;return r.x`
2
- <pkt-input-wrapper
3
- ?counter=${this.counter}
4
- ?disabled=${this.disabled}
5
- ?hasError=${this.hasError}
6
- ?hasFieldset=${this.hasFieldset}
7
- ?inline=${this.inline}
8
- ?optionalTag=${this.optionalTag}
9
- ?requiredTag=${this.requiredTag}
10
- ?useWrapper=${this.useWrapper}
11
- ariaDescribedBy=${o.o(this.ariaDescribedBy)}
12
- .counterCurrent=${this.counterCurrent}
13
- .counterMaxLength=${this.counterMaxLength}
14
- class="pkt-select"
15
- errorMessage=${o.o(this.errorMessage)}
16
- forId=${this.id+"-input"}
17
- helptext=${o.o(this.helptext)}
18
- helptextDropdown=${o.o(this.helptextDropdown)}
19
- helptextDropdownButton=${o.o(this.helptextDropdownButton)}
20
- label=${o.o(this.label)}
21
- optionalText=${o.o(this.optionalText)}
22
- requiredText=${o.o(this.requiredText)}
23
- >
24
- <select
25
- class=${e}
26
- aria-invalid=${this.hasError}
27
- aria-errormessage=${`${this.id}-error`}
28
- aria-labelledby=${o.o(this.ariaLabelledby)}
29
- ?disabled=${this.disabled}
30
- id=${this.id+"-input"}
31
- name=${(this.name||this.id)+"-input"}
32
- value=${this.value}
33
- @change=${t=>{this.value=t.target.value,t.stopImmediatePropagation()}}
34
- @input=${t=>{this.onInput(),t.stopImmediatePropagation()}}
35
- @focus=${t=>{this.onFocus(),t.stopImmediatePropagation()}}
36
- @blur=${t=>{this.onBlur(),t.stopImmediatePropagation()}}
37
- ${l.n(this.inputRef)}
38
- >
39
- ${this._options.length>0&&this._options.map(t=>r.x`<option
40
- value=${t.value}
41
- ?selected=${this.value==t.value}
42
- ?disabled=${t.disabled}
43
- >
44
- ${t.label}
45
- </option>`)}
46
- </select>
47
- <div class="pkt-contents" ${l.n(this.helptextSlot)} name="helptext" slot="helptext"></div>
48
- </pkt-input-wrapper>
49
- `}};n([r.n({type:Array})],exports.PktSelect.prototype,"options",2);n([r.n({type:String,reflect:!0})],exports.PktSelect.prototype,"value",2);n([u.r()],exports.PktSelect.prototype,"_options",2);exports.PktSelect=n([r.t("pkt-select")],exports.PktSelect);
@@ -1,118 +0,0 @@
1
- import { x as h, n as c, a as $ } from "./element-DjjF_tEh.js";
2
- import { r as b } from "./state-BtbpSrdV.js";
3
- import { e as u, n as d } from "./ref-iIffqQAI.js";
4
- import { o as s } from "./if-defined-BErSJCeJ.js";
5
- import { P as v } from "./input-element-B2GjFOXX.js";
6
- import { P as f } from "./pkt-options-controller-DepYQBqb.js";
7
- import { P as m } from "./pkt-slot-controller-DtDaD9q_.js";
8
- import "./input-wrapper-BdeoMGnk.js";
9
- var g = Object.defineProperty, C = Object.getOwnPropertyDescriptor, a = (e, t, i, o) => {
10
- for (var r = o > 1 ? void 0 : o ? C(t, i) : t, n = e.length - 1, p; n >= 0; n--)
11
- (p = e[n]) && (r = (o ? p(t, i, r) : p(r)) || r);
12
- return o && r && g(t, i, r), r;
13
- };
14
- let l = class extends v {
15
- constructor() {
16
- super(), this.inputRef = u(), this.helptextSlot = u(), this.options = [], this.value = "", this._options = [], this.optionsController = new f(this), this.slotController = new m(this, this.helptextSlot), this.slotController.skipOptions = !0;
17
- }
18
- // Used for initilization
19
- connectedCallback() {
20
- super.connectedCallback();
21
- const e = this.options.length > 0, t = this.optionsController.nodes.length && this.optionsController.nodes.length > 0;
22
- !e && t ? this.optionsController.nodes.forEach((i) => {
23
- const o = {
24
- value: i.getAttribute("value") || i.textContent || "",
25
- label: i.textContent || i.getAttribute("value") || "",
26
- disabled: !!i.getAttribute("disabled")
27
- };
28
- i.getAttribute("selected") && !this.value && (this.value = o.value), this._options.push(o);
29
- }) : this._options = this.options;
30
- }
31
- attributeChangedCallback(e, t, i) {
32
- e === "options" && (this._options = i ? JSON.parse(i) : []), e === "value" && this.value !== t && this.valueChanged(i, t), super.attributeChangedCallback(e, t, i);
33
- }
34
- updated(e) {
35
- var t;
36
- super.updated(e), e.has("value") && (this.counterCurrent = ((t = this.value) == null ? void 0 : t.length) || 0, this.valueChanged(this.value, e.get("value"))), e.has("id") && !this.name && this.id && (this.name = this.id);
37
- }
38
- firstUpdated(e) {
39
- super.firstUpdated(e), this.options.length && (this._options = this.options);
40
- }
41
- render() {
42
- const e = `pkt-input ${this.fullwidth ? "pkt-input--fullwidth" : ""}`;
43
- return h`
44
- <pkt-input-wrapper
45
- ?counter=${this.counter}
46
- ?disabled=${this.disabled}
47
- ?hasError=${this.hasError}
48
- ?hasFieldset=${this.hasFieldset}
49
- ?inline=${this.inline}
50
- ?optionalTag=${this.optionalTag}
51
- ?requiredTag=${this.requiredTag}
52
- ?useWrapper=${this.useWrapper}
53
- ariaDescribedBy=${s(this.ariaDescribedBy)}
54
- .counterCurrent=${this.counterCurrent}
55
- .counterMaxLength=${this.counterMaxLength}
56
- class="pkt-select"
57
- errorMessage=${s(this.errorMessage)}
58
- forId=${this.id + "-input"}
59
- helptext=${s(this.helptext)}
60
- helptextDropdown=${s(this.helptextDropdown)}
61
- helptextDropdownButton=${s(this.helptextDropdownButton)}
62
- label=${s(this.label)}
63
- optionalText=${s(this.optionalText)}
64
- requiredText=${s(this.requiredText)}
65
- >
66
- <select
67
- class=${e}
68
- aria-invalid=${this.hasError}
69
- aria-errormessage=${`${this.id}-error`}
70
- aria-labelledby=${s(this.ariaLabelledby)}
71
- ?disabled=${this.disabled}
72
- id=${this.id + "-input"}
73
- name=${(this.name || this.id) + "-input"}
74
- value=${this.value}
75
- @change=${(t) => {
76
- this.value = t.target.value, t.stopImmediatePropagation();
77
- }}
78
- @input=${(t) => {
79
- this.onInput(), t.stopImmediatePropagation();
80
- }}
81
- @focus=${(t) => {
82
- this.onFocus(), t.stopImmediatePropagation();
83
- }}
84
- @blur=${(t) => {
85
- this.onBlur(), t.stopImmediatePropagation();
86
- }}
87
- ${d(this.inputRef)}
88
- >
89
- ${this._options.length > 0 && this._options.map(
90
- (t) => h`<option
91
- value=${t.value}
92
- ?selected=${this.value == t.value}
93
- ?disabled=${t.disabled}
94
- >
95
- ${t.label}
96
- </option>`
97
- )}
98
- </select>
99
- <div class="pkt-contents" ${d(this.helptextSlot)} name="helptext" slot="helptext"></div>
100
- </pkt-input-wrapper>
101
- `;
102
- }
103
- };
104
- a([
105
- c({ type: Array })
106
- ], l.prototype, "options", 2);
107
- a([
108
- c({ type: String, reflect: !0 })
109
- ], l.prototype, "value", 2);
110
- a([
111
- b()
112
- ], l.prototype, "_options", 2);
113
- l = a([
114
- $("pkt-select")
115
- ], l);
116
- export {
117
- l as P
118
- };