@oslokommune/punkt-react 13.5.12 → 13.5.13

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,25 @@ og skriver commits ca etter [Conventional Commits](https://conventionalcommits.o
5
5
 
6
6
  ---
7
7
 
8
+ ## [13.5.13](https://github.com/oslokommune/punkt/compare/13.5.12...13.5.13) (2025-09-12)
9
+
10
+ ### ⚠ BREAKING CHANGES
11
+ Ingen
12
+
13
+ ### Features
14
+ Ingen
15
+
16
+ ### Bug Fixes
17
+ * Bedre synk mellom options som props og options som elementer (#3017). * fix(elements,react): Bedre synk mellom options som props og options som elementer
18
+ * Fiks klaging på `showPicker` i tester
19
+
20
+
21
+ ### Chores
22
+ Ingen
23
+
24
+ ---
25
+
26
+
8
27
  ## [13.5.12](https://github.com/oslokommune/punkt/compare/13.5.11...13.5.12) (2025-09-11)
9
28
 
10
29
  ### ⚠ BREAKING CHANGES
@@ -28743,69 +28743,85 @@ var N6 = Object.defineProperty, I6 = Object.getOwnPropertyDescriptor, GS = (e, t
28743
28743
  };
28744
28744
  let Iv = class extends cn {
28745
28745
  constructor() {
28746
- super(), this.inputRef = gn(), this.helptextSlot = gn(), this.options = [], this.value = "", this._options = [], this.selectedIndex = -1, this.selectedOptions = void 0, this.optionsController = new pU(this), this.slotController = new ni(this, this.helptextSlot), this.slotController.skipOptions = !0;
28746
+ super(), this.inputRef = gn(), this.helptextSlot = gn(), this._optionsProp = [], this.value = "", this._options = [], this.selectedIndex = -1, this.selectedOptions = void 0, this.optionsController = new pU(this), this.slotController = new ni(this, this.helptextSlot), this.slotController.skipOptions = !0;
28747
+ }
28748
+ // Getter and setter for options to expose the actual parsed options
28749
+ get options() {
28750
+ return this._options.map((t) => ({
28751
+ ...t,
28752
+ selected: t.value === this.value
28753
+ }));
28754
+ }
28755
+ set options(t) {
28756
+ this._optionsProp = t, this.requestUpdate("_optionsProp", this._options);
28747
28757
  }
28748
- // Used for initilization
28749
28758
  connectedCallback() {
28750
28759
  super.connectedCallback();
28751
- const e = this.options.length > 0, t = this.optionsController.nodes.length && this.optionsController.nodes.length > 0;
28752
- !e && t ? this.optionsController.nodes.forEach((a) => {
28753
- const o = {
28754
- value: a.hasAttribute("value") ? a.getAttribute("value") ?? "" : a.textContent ?? "",
28755
- label: a.textContent || a.getAttribute("value") || "",
28756
- disabled: a.hasAttribute("disabled"),
28757
- selected: a.hasAttribute("selected"),
28758
- hidden: a.hasAttribute("data-hidden")
28760
+ const t = this._optionsProp.length > 0, a = this.optionsController.nodes.length && this.optionsController.nodes.length > 0;
28761
+ !t && a ? this.optionsController.nodes.forEach((o) => {
28762
+ const u = {
28763
+ value: o.hasAttribute("value") ? o.getAttribute("value") ?? "" : o.textContent ?? "",
28764
+ label: o.textContent || o.getAttribute("value") || "",
28765
+ disabled: o.hasAttribute("disabled"),
28766
+ selected: o.hasAttribute("selected"),
28767
+ hidden: o.hasAttribute("data-hidden")
28759
28768
  };
28760
- a.getAttribute("selected") && !this.value && (this.value = o.value), this._options.push(o);
28761
- }) : (this._options = this.options, this._options.forEach((a) => {
28762
- a.selected && !this.value && (this.value = a.value);
28769
+ o.getAttribute("selected") && !this.value && (this.value = u.value), this._options.push(u);
28770
+ }) : (this._options = this._optionsProp, this._options.forEach((o) => {
28771
+ o.selected && !this.value && (this.value = o.value);
28763
28772
  }));
28764
28773
  }
28765
28774
  // Support native Select method `add`
28766
- add(e, t) {
28767
- var a, o, u;
28768
- (a = this.inputRef.value) == null || a.add(e, t), this._options.push({
28769
- value: e.value || e.text,
28770
- label: e.text || e.value,
28771
- selected: e.selected,
28772
- disabled: e.disabled
28773
- }), e.selected && (this.value = e.value || e.text, this.selectedIndex = this.returnNumberOrNull((o = this.inputRef.value) == null ? void 0 : o.selectedIndex), this.selectedOptions = (u = this.inputRef.value) == null ? void 0 : u.selectedOptions), this.requestUpdate();
28775
+ add(t, a) {
28776
+ const o = {
28777
+ value: t.value || t.text,
28778
+ label: t.text || t.value,
28779
+ selected: t.selected,
28780
+ disabled: t.disabled
28781
+ };
28782
+ if (a === void 0)
28783
+ this._options.push(o);
28784
+ else if (typeof a == "number")
28785
+ this._options.splice(a, 0, o);
28786
+ else {
28787
+ const u = a.value || a.text, d = this._options.findIndex((f) => f.value === u);
28788
+ d >= 0 ? this._options.splice(d, 0, o) : this._options.push(o);
28789
+ }
28790
+ t.selected && (this.value = t.value || t.text, this.selectedIndex = this._options.findIndex((u) => u.value === this.value)), this.requestUpdate();
28774
28791
  }
28775
28792
  // Support native Select method `remove`
28776
- remove(e) {
28777
- var t, a;
28778
- typeof e == "number" && (this.selectedIndex === e && (this.value = ((t = this._options[0]) == null ? void 0 : t.value) || ""), (a = this.inputRef.value) == null || a.remove(e));
28793
+ remove(t) {
28794
+ var a;
28795
+ typeof t == "number" && (this.selectedIndex === t && (this.value = ((a = this._options[0]) == null ? void 0 : a.value) || ""), this._options.splice(t, 1), this.requestUpdate());
28779
28796
  }
28780
28797
  // Support native Select method `item`
28781
- item(e) {
28782
- var t;
28783
- return (t = this.inputRef.value) == null ? void 0 : t.item(e);
28798
+ item(t) {
28799
+ var a;
28800
+ return (a = this.inputRef.value) == null ? void 0 : a.item(t);
28784
28801
  }
28785
28802
  // Support native Select method `namedItem`
28786
- namedItem(e) {
28787
- var t;
28788
- return (t = this.inputRef.value) == null ? void 0 : t.namedItem(e);
28803
+ namedItem(t) {
28804
+ var a;
28805
+ return (a = this.inputRef.value) == null ? void 0 : a.namedItem(t);
28789
28806
  }
28790
28807
  // Support native Select method `showPicker`
28791
28808
  showPicker() {
28792
- var e;
28793
- (e = this.inputRef.value) == null || e.showPicker();
28809
+ this.inputRef.value && "showPicker" in this.inputRef.value && this.inputRef.value.showPicker();
28794
28810
  }
28795
- attributeChangedCallback(e, t, a) {
28796
- var o, u;
28797
- e === "options" && (this._options = a ? JSON.parse(a) : []), e === "value" && this.value !== t && (this.selectedIndex = this.touched ? this.returnNumberOrNull((o = this.inputRef.value) == null ? void 0 : o.selectedIndex) : this.options.findIndex((d) => d.value === a), this.selectedOptions = (u = this.inputRef.value) == null ? void 0 : u.selectedOptions, this.valueChanged(a, t)), super.attributeChangedCallback(e, t, a);
28811
+ attributeChangedCallback(t, a, o) {
28812
+ var u, d;
28813
+ t === "options" && (this._options = o ? JSON.parse(o) : []), t === "value" && this.value !== a && (this.selectedIndex = this.touched ? this.returnNumberOrNull((u = this.inputRef.value) == null ? void 0 : u.selectedIndex) : this._options.findIndex((f) => f.value === o), this.selectedOptions = (d = this.inputRef.value) == null ? void 0 : d.selectedOptions, this.valueChanged(o, a)), super.attributeChangedCallback(t, a, o);
28798
28814
  }
28799
- update(e) {
28800
- var t, a;
28801
- super.update(e), e.has("options") && (this._options = this.options, this.requestUpdate("_options"), !this.value && this._options.length > 0 && (this.value = this._options[0].value, this.selectedIndex = 0)), e.has("value") && this.value !== e.get("value") && (this.selectedIndex = this.touched ? this.returnNumberOrNull((t = this.inputRef.value) == null ? void 0 : t.selectedIndex) : this.options.findIndex((o) => o.value === this.value), this.selectedOptions = (a = this.inputRef.value) == null ? void 0 : a.selectedOptions, this.valueChanged(this.value, e.get("value"))), e.has("id") && !this.name && this.id && (this.name = this.id);
28815
+ update(t) {
28816
+ var a, o;
28817
+ super.update(t), t.has("_optionsProp") && this._optionsProp.length > 0 && (this._options = this._optionsProp, this.requestUpdate("_options"), !this.value && this._options.length > 0 && (this.value = this._options[0].value, this.selectedIndex = 0)), t.has("value") && this.value !== t.get("value") && (this.selectedIndex = this.touched ? this.returnNumberOrNull((a = this.inputRef.value) == null ? void 0 : a.selectedIndex) : this._options.findIndex((u) => u.value === this.value), this.selectedOptions = (o = this.inputRef.value) == null ? void 0 : o.selectedOptions, this.valueChanged(this.value, t.get("value"))), t.has("id") && !this.name && this.id && (this.name = this.id);
28802
28818
  }
28803
- firstUpdated(e) {
28804
- var t;
28805
- super.firstUpdated(e), 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((a) => a.value === this.value), this.selectedOptions = (t = this.inputRef.value) == null ? void 0 : t.selectedOptions;
28819
+ firstUpdated(t) {
28820
+ var a;
28821
+ super.firstUpdated(t), this._optionsProp.length && (this._options = this._optionsProp), !this.value && this._options.length > 0 ? (this.value = this._options[0].value, this.selectedIndex = 0) : this.selectedIndex = this._options.findIndex((o) => o.value === this.value), this.selectedOptions = (a = this.inputRef.value) == null ? void 0 : a.selectedOptions;
28806
28822
  }
28807
28823
  render() {
28808
- const e = `pkt-input ${this.fullwidth ? "pkt-input--fullwidth" : ""}`;
28824
+ const t = `pkt-input ${this.fullwidth ? "pkt-input--fullwidth" : ""}`;
28809
28825
  return ke`
28810
28826
  <pkt-input-wrapper
28811
28827
  ?counter=${this.counter}
@@ -28829,7 +28845,7 @@ let Iv = class extends cn {
28829
28845
  tagText=${$t(this.tagText)}
28830
28846
  >
28831
28847
  <select
28832
- class=${e}
28848
+ class=${t}
28833
28849
  aria-invalid=${this.hasError}
28834
28850
  aria-errormessage=${`${this.id}-error`}
28835
28851
  aria-labelledby=${$t(this.ariaLabelledby)}
@@ -28837,28 +28853,28 @@ let Iv = class extends cn {
28837
28853
  id=${this.id + "-input"}
28838
28854
  name=${(this.name || this.id) + "-input"}
28839
28855
  value=${this.value}
28840
- @change=${(t) => {
28841
- this.touched = !0, this.value = t.target.value, t.stopImmediatePropagation();
28856
+ @change=${(a) => {
28857
+ this.touched = !0, this.value = a.target.value, a.stopImmediatePropagation();
28842
28858
  }}
28843
- @input=${(t) => {
28844
- this.onInput(), t.stopImmediatePropagation();
28859
+ @input=${(a) => {
28860
+ this.onInput(), a.stopImmediatePropagation();
28845
28861
  }}
28846
- @focus=${(t) => {
28847
- this.onFocus(), t.stopImmediatePropagation();
28862
+ @focus=${(a) => {
28863
+ this.onFocus(), a.stopImmediatePropagation();
28848
28864
  }}
28849
- @blur=${(t) => {
28850
- this.onBlur(), t.stopImmediatePropagation();
28865
+ @blur=${(a) => {
28866
+ this.onBlur(), a.stopImmediatePropagation();
28851
28867
  }}
28852
28868
  ${dn(this.inputRef)}
28853
28869
  >
28854
28870
  ${this._options.length > 0 ? this._options.map(
28855
- (t) => ke`<option
28856
- value=${t.value}
28857
- ?selected=${this.value == t.value || t.selected}
28858
- ?disabled=${t.disabled}
28859
- ?hidden=${t.hidden}
28871
+ (a) => ke`<option
28872
+ value=${a.value}
28873
+ ?selected=${this.value == a.value || a.selected}
28874
+ ?disabled=${a.disabled}
28875
+ ?hidden=${a.hidden}
28860
28876
  >
28861
- ${t.label}
28877
+ ${a.label}
28862
28878
  </option>`
28863
28879
  ) : ""}
28864
28880
  </select>
@@ -28866,13 +28882,13 @@ let Iv = class extends cn {
28866
28882
  </pkt-input-wrapper>
28867
28883
  `;
28868
28884
  }
28869
- returnNumberOrNull(e) {
28870
- return e == null || isNaN(e) ? null : e;
28885
+ returnNumberOrNull(t) {
28886
+ return t == null || isNaN(t) ? null : t;
28871
28887
  }
28872
28888
  };
28873
28889
  GS([
28874
- G({ type: Array })
28875
- ], Iv.prototype, "options", 2);
28890
+ G({ type: Array, attribute: "options" })
28891
+ ], Iv.prototype, "_optionsProp", 2);
28876
28892
  GS([
28877
28893
  G({ type: String })
28878
28894
  ], Iv.prototype, "value", 2);