@oslokommune/punkt-elements 12.31.2 → 12.32.7

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.
Files changed (181) hide show
  1. package/dist/alert-C2WKLFow.cjs +27 -0
  2. package/dist/alert-XGjypFHe.js +115 -0
  3. package/dist/alert.d.ts +32 -0
  4. package/dist/{backlink-CzpB-ih9.js → backlink-BX8HBhw5.js} +2 -2
  5. package/dist/{backlink-Dn4DfWVR.cjs → backlink-NJdC0FAO.cjs} +1 -1
  6. package/dist/backlink.d.ts +32 -0
  7. package/dist/{button-9NwGr-OS.js → button-Bn8jVB0f.js} +33 -33
  8. package/dist/{button-Beo3c7cx.cjs → button-Bpbh8A_a.cjs} +2 -2
  9. package/dist/button.d.ts +32 -0
  10. package/dist/{calendar-BbZNxsKY.js → calendar-BNHDEEwT.js} +20 -84
  11. package/dist/{calendar-CxBo98iI.cjs → calendar-Ds13AKr5.cjs} +4 -4
  12. package/dist/calendar.d.ts +32 -0
  13. package/dist/card-CEv3DL-o.js +94 -0
  14. package/dist/card-c5EEPaNh.cjs +28 -0
  15. package/dist/card.d.ts +32 -0
  16. package/dist/{checkbox-9Zjy_NU7.cjs → checkbox-DDBBDM85.cjs} +1 -1
  17. package/dist/{checkbox-CzDpR6_8.js → checkbox-DoMYxp83.js} +9 -9
  18. package/dist/checkbox.d.ts +32 -0
  19. package/dist/{class-map-DWtqmIRS.js → class-map-D4tSZX70.js} +2 -2
  20. package/dist/{class-map-Dj5mbCUg.cjs → class-map-DvBKxTiW.cjs} +1 -1
  21. package/dist/combobox-BflWORVa.cjs +115 -0
  22. package/dist/combobox-l7LmWQYu.js +491 -0
  23. package/dist/combobox.d.ts +47 -0
  24. package/dist/datepicker-Bkiyh5P5.cjs +153 -0
  25. package/dist/datepicker-nWd89NwP.js +449 -0
  26. package/dist/datepicker.d.ts +32 -0
  27. package/dist/directive-C7oCP5Bh.cjs +5 -0
  28. package/dist/directive-helpers-BmXIK-1b.js +45 -0
  29. package/dist/directive-helpers-donnvcEO.cjs +5 -0
  30. package/dist/{directive-B76A7YXI.js → directive-oAbCiebi.js} +4 -4
  31. package/dist/element-DJpGVXjq.cjs +238 -0
  32. package/dist/{element-C7XjZtLU.js → element-DiqKrDty.js} +8851 -8847
  33. package/dist/{helptext-CqnoPodd.js → helptext-DfRusn5R.js} +13 -13
  34. package/dist/{helptext-B9kxDc2b.cjs → helptext-aHD9icur.cjs} +2 -2
  35. package/dist/helptext.d.ts +32 -0
  36. package/dist/{icon-BEUgV9Wo.js → icon-BdY52BIt.js} +2 -2
  37. package/dist/{icon-BOKusjAA.cjs → icon-UtDKPH3R.cjs} +1 -1
  38. package/dist/icon.d.ts +32 -0
  39. package/dist/{if-defined-CpIkv1A4.cjs → if-defined-CoBDkDGb.cjs} +1 -1
  40. package/dist/{if-defined-eRX4e5zO.js → if-defined-DeANa4n5.js} +1 -1
  41. package/dist/index.d.ts +210 -15
  42. package/dist/{input-element-BK8UkQli.js → input-element-C4mmTk6h.js} +23 -20
  43. package/dist/input-element-VNai8bsq.cjs +1 -0
  44. package/dist/input-wrapper-8iKEzDRZ.js +40 -0
  45. package/dist/input-wrapper-DWOw7Yn-.cjs +52 -0
  46. package/dist/input-wrapper-EoSAbU-U.cjs +1 -0
  47. package/dist/input-wrapper-P_oEi6dk.js +185 -0
  48. package/dist/input-wrapper.d.ts +32 -0
  49. package/dist/link-D9dJ6F-R.js +73 -0
  50. package/dist/link-DBxXqsnP.cjs +8 -0
  51. package/dist/link.d.ts +32 -0
  52. package/dist/{linkcard-2WzDJPZz.cjs → linkcard-D5O1hR7N.cjs} +1 -1
  53. package/dist/{linkcard-CRpo3tiw.js → linkcard-DcEE9IVw.js} +4 -4
  54. package/dist/linkcard.d.ts +32 -0
  55. package/dist/listbox-CK1GmwCE.cjs +95 -0
  56. package/dist/listbox-CfJWJDrc.js +360 -0
  57. package/dist/listbox.d.ts +47 -0
  58. package/dist/{loader-B1edLWTg.js → loader-DZvOlXzI.js} +6 -6
  59. package/dist/{loader-DI74pe25.cjs → loader-SDXJp58K.cjs} +1 -1
  60. package/dist/loader.d.ts +32 -0
  61. package/dist/messagebox-Ce5e1gga.js +79 -0
  62. package/dist/messagebox-D2_-WZQG.cjs +12 -0
  63. package/dist/messagebox.d.ts +32 -0
  64. package/dist/modal-CCtUsYKk.cjs +33 -0
  65. package/dist/{modal-kPX8nO_L.js → modal-CdgIOp8Q.js} +51 -94
  66. package/dist/modal.d.ts +32 -0
  67. package/dist/pkt-alert.cjs +1 -1
  68. package/dist/pkt-alert.js +1 -1
  69. package/dist/pkt-backlink.cjs +1 -1
  70. package/dist/pkt-backlink.js +1 -1
  71. package/dist/pkt-button.cjs +1 -1
  72. package/dist/pkt-button.js +1 -1
  73. package/dist/pkt-calendar.cjs +1 -1
  74. package/dist/pkt-calendar.js +1 -1
  75. package/dist/pkt-card.cjs +1 -1
  76. package/dist/pkt-card.js +1 -1
  77. package/dist/pkt-checkbox.cjs +1 -1
  78. package/dist/pkt-checkbox.js +1 -1
  79. package/dist/pkt-combobox.cjs +1 -0
  80. package/dist/pkt-combobox.js +6 -0
  81. package/dist/pkt-datepicker.cjs +1 -1
  82. package/dist/pkt-datepicker.js +1 -1
  83. package/dist/pkt-helptext.cjs +1 -1
  84. package/dist/pkt-helptext.js +1 -1
  85. package/dist/pkt-icon.cjs +1 -1
  86. package/dist/pkt-icon.js +1 -1
  87. package/dist/pkt-index.cjs +3 -3
  88. package/dist/pkt-index.js +45 -43
  89. package/dist/pkt-input-wrapper.cjs +1 -1
  90. package/dist/pkt-input-wrapper.js +1 -1
  91. package/dist/pkt-link.cjs +1 -1
  92. package/dist/pkt-link.js +1 -1
  93. package/dist/pkt-linkcard.cjs +1 -1
  94. package/dist/pkt-linkcard.js +1 -1
  95. package/dist/pkt-listbox.cjs +1 -0
  96. package/dist/pkt-listbox.js +6 -0
  97. package/dist/pkt-loader.cjs +1 -1
  98. package/dist/pkt-loader.js +1 -1
  99. package/dist/pkt-messagebox.cjs +1 -1
  100. package/dist/pkt-messagebox.js +1 -1
  101. package/dist/pkt-modal.cjs +1 -1
  102. package/dist/pkt-modal.js +1 -1
  103. package/dist/pkt-options-controller-BkWE4pZe.js +38 -0
  104. package/dist/pkt-options-controller-TJ1apYGF.cjs +1 -0
  105. package/dist/pkt-progressbar.cjs +1 -1
  106. package/dist/pkt-progressbar.js +2 -2
  107. package/dist/pkt-radiobutton.cjs +1 -1
  108. package/dist/pkt-radiobutton.js +1 -1
  109. package/dist/pkt-select.cjs +1 -1
  110. package/dist/pkt-select.js +1 -1
  111. package/dist/pkt-slot-controller-BtVLTZb7.js +79 -0
  112. package/dist/pkt-slot-controller-plQxXRvV.cjs +1 -0
  113. package/dist/pkt-tag.cjs +1 -1
  114. package/dist/pkt-tag.js +1 -1
  115. package/dist/pkt-textarea.cjs +1 -1
  116. package/dist/pkt-textarea.js +1 -1
  117. package/dist/pkt-textinput.cjs +1 -1
  118. package/dist/pkt-textinput.js +1 -1
  119. package/dist/{progressbar-D0nxLqHu.js → progressbar-DvFz9KBo.js} +6 -6
  120. package/dist/{progressbar-B6A9UVXS.cjs → progressbar-jASTnhti.cjs} +1 -1
  121. package/dist/progressbar.d.ts +32 -0
  122. package/dist/{radiobutton-BWyQgR_x.cjs → radiobutton-C-Xd5sSq.cjs} +1 -1
  123. package/dist/{radiobutton-DLWjvLBO.js → radiobutton-D03aN4yn.js} +5 -5
  124. package/dist/radiobutton.d.ts +32 -0
  125. package/dist/ref-B70YZNXm.js +102 -0
  126. package/dist/ref-CLqTsViF.cjs +9 -0
  127. package/dist/repeat-CNLpCTun.js +61 -0
  128. package/dist/repeat-t2oms1o6.cjs +5 -0
  129. package/dist/select-BLDaK5Rd.js +118 -0
  130. package/dist/select-Dvds7MzS.cjs +49 -0
  131. package/dist/select.d.ts +32 -0
  132. package/dist/{state-HNj0_316.cjs → state-C4LdlTYO.cjs} +1 -1
  133. package/dist/{state-CDQk0DFQ.js → state-CDwPbiQj.js} +1 -1
  134. package/dist/tag-C52KeBmR.cjs +18 -0
  135. package/dist/{tag-CmFcSdOV.js → tag-DoS5S2Bq.js} +28 -77
  136. package/dist/tag.d.ts +32 -0
  137. package/dist/{textarea-BPqWCymU.js → textarea-C9EvdPGi.js} +18 -17
  138. package/dist/{textarea-VG-UTMLP.cjs → textarea-DJvNBmEL.cjs} +6 -6
  139. package/dist/textarea.d.ts +32 -0
  140. package/dist/{textinput-CEP7QA3E.cjs → textinput-Cg3ObBuw.cjs} +5 -4
  141. package/dist/{textinput-VD74aGzx.js → textinput-CxRSSYaN.js} +34 -33
  142. package/dist/textinput.d.ts +32 -0
  143. package/package.json +4 -4
  144. package/src/components/button/button.ts +3 -2
  145. package/src/components/combobox/combobox.ts +873 -0
  146. package/src/components/combobox/countrycodes.json +927 -0
  147. package/src/components/combobox/index.ts +6 -0
  148. package/src/components/datepicker/datepicker.ts +6 -4
  149. package/src/components/helptext/helptext.ts +1 -1
  150. package/src/components/index.ts +7 -0
  151. package/src/components/input-wrapper/input-wrapper.ts +42 -34
  152. package/src/components/listbox/index.ts +4 -0
  153. package/src/components/listbox/listbox.ts +474 -0
  154. package/src/components/select/select.ts +7 -0
  155. package/src/components/tag/tag.ts +1 -1
  156. package/src/components/textinput/textinput.ts +3 -2
  157. package/dist/alert-BDxxRqgi.cjs +0 -27
  158. package/dist/alert-D0S57u0r.js +0 -163
  159. package/dist/card-C63x_nll.cjs +0 -28
  160. package/dist/card-DQfNKnKl.js +0 -176
  161. package/dist/datepicker-CYUvRGhE.js +0 -663
  162. package/dist/datepicker-FuAL0uNU.cjs +0 -155
  163. package/dist/directive-C_VV3qwo.cjs +0 -5
  164. package/dist/element-CzFXQBoS.cjs +0 -238
  165. package/dist/input-element-Dtyuf6s8.cjs +0 -1
  166. package/dist/input-wrapper-Bo2_t6pA.cjs +0 -50
  167. package/dist/input-wrapper-Bw9tARAD.js +0 -125
  168. package/dist/input-wrapper-DaZZq8c0.js +0 -172
  169. package/dist/input-wrapper-jPnKsfEC.cjs +0 -1
  170. package/dist/link-1iq0Pmuf.cjs +0 -8
  171. package/dist/link-D3U0Jkz8.js +0 -109
  172. package/dist/messagebox-DQpEMkS2.cjs +0 -12
  173. package/dist/messagebox-KP-8-tA9.js +0 -114
  174. package/dist/modal-ytIJwfr3.cjs +0 -33
  175. package/dist/pkt-slot-controller-Clbye6cM.js +0 -85
  176. package/dist/pkt-slot-controller-Oc32unDk.cjs +0 -1
  177. package/dist/ref-2anvRHT4.cjs +0 -13
  178. package/dist/ref-DbOSDQbk.js +0 -143
  179. package/dist/select-CzuxXKll.js +0 -150
  180. package/dist/select-DZL6aa2s.cjs +0 -48
  181. package/dist/tag-BeLSOjNh.cjs +0 -18
@@ -0,0 +1,115 @@
1
+ "use strict";const l=require("./element-DJpGVXjq.cjs"),c=require("./if-defined-CoBDkDGb.cjs"),d=require("./state-C4LdlTYO.cjs"),u=require("./ref-CLqTsViF.cjs"),$=require("./class-map-DvBKxTiW.cjs"),I=require("./repeat-t2oms1o6.cjs"),w=require("./input-element-VNai8bsq.cjs"),y=require("./pkt-options-controller-TJ1apYGF.cjs"),O=require("./pkt-slot-controller-plQxXRvV.cjs");require("./input-wrapper-DWOw7Yn-.cjs");require("./icon-UtDKPH3R.cjs");require("./tag-C52KeBmR.cjs");require("./listbox-CK1GmwCE.cjs");const C={displayValueAs:{default:"label"}},R={props:C};var V=Object.defineProperty,S=Object.getOwnPropertyDescriptor,o=(b,t,e,s)=>{for(var i=s>1?void 0:s?S(t,e):t,n=b.length-1,h;n>=0;n--)(h=b[n])&&(i=(s?h(t,e,i):h(i))||i);return s&&i&&V(t,e,i),i};exports.PktCombobox=class extends w.PktInputElement{constructor(){super(),this.helptextSlot=u.e(),this.value="",this.options=[],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=u.e(),this.arrowRef=u.e(),this.listboxRef=u.e(),this.focusRef=u.e(),this.optionTagRef=u.e(),this.optionsController=new y.PktOptionsSlotController(this),this.slotController=new O.PktSlotController(this,this.helptextSlot),this.slotController.skipOptions=!0}connectedCallback(){if(super.connectedCallback(),document&&document.body.addEventListener("click",t=>{this._isOptionsOpen&&!this.contains(t.target)&&this.handleFocusOut(t)}),this._options=[],this.optionsController.nodes.length){const t=[];this.optionsController.nodes.forEach(e=>{if(!e.textContent&&!e.getAttribute("value"))return null;const s={value:e.getAttribute("value")||e.textContent||"",label:e.textContent||e.getAttribute("value")||""};e.getAttribute("data-prefix")&&(s.prefix=e.getAttribute("data-prefix")||void 0),e.getAttribute("tagskincolor")&&(s.tagSkinColor=e.getAttribute("tagskincolor")),e.getAttribute("description")&&(s.description=e.getAttribute("description")||void 0),s.fulltext=s.value+s.label+(s.prefix||""),t.push(s)}),t.length&&(this.options=[...t],this._options=[...t])}}updated(t){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("options")&&this.options.length&&(this._options=this.options,this._options.forEach(e=>{e.fulltext=e.value+e.label+(e.prefix||""),e.selected=this._value.includes(e.value)})),t.has("_search")&&this.dispatchEvent(new CustomEvent("search",{detail:this._search,bubbles:!1})),super.updated(t)}attributeChangedCallback(t,e,s){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(i=>{i.fulltext=i.value+i.label+(i.prefix||"")}),this._search=""),super.attributeChangedCallback(t,e,s)}render(){return l.x`
2
+ <pkt-input-wrapper
3
+ .label=${this.label}
4
+ .helptext=${this.helptext}
5
+ .helptextDropdown=${c.o(this.helptextDropdown)}
6
+ .helptextDropdownButton=${c.o(this.helptextDropdownButton)}
7
+ ?fullwidth=${this.fullwidth}
8
+ ?hasError=${this.hasError}
9
+ ?inline=${this.inline}
10
+ ?disabled=${this.disabled}
11
+ .errorMessage=${this.errorMessage}
12
+ ?optionalTag=${this.optionalTag}
13
+ .optionalText=${this.optionalText}
14
+ ?requiredTag=${this.requiredTag}
15
+ .requiredText=${this.requiredText}
16
+ ?useWrapper=${this.useWrapper}
17
+ .forId=${this.allowUserInput||this.typeahead?this.id+"-input":this.id+"-arrow"}
18
+ class="pkt-combobox__wrapper"
19
+ @labelClick=${this.handleInputClick}
20
+ >
21
+ <div class="pkt-contents" ${u.n(this.helptextSlot)} name="helptext" slot="helptext"></div>
22
+ <div class="pkt-combobox" @focusout=${this.handleFocusOut}>
23
+ <div
24
+ class=${$.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
+ tabindex="-1"
26
+ @click=${this.handleInputClick}
27
+ >
28
+ ${this.placeholder&&(!this._value.length||this.multiple&&this.tagPlacement=="outside")&&!this._inputFocus?l.x`<span class="pkt-combobox__placeholder">${this.placeholder}</span>`:this.tagPlacement!=="outside"?this.renderSingleOrMultipleValues():l.E}
29
+ ${this.renderInputField()}
30
+ <div
31
+ class="pkt-btn pkt-btn--tertiary pkt-combobox__arrow"
32
+ @click=${this.handleArrowClick}
33
+ @keydown=${this.handleArrowClick}
34
+ id="${this.id}-arrow"
35
+ ${u.n(this.arrowRef)}
36
+ aria-expanded=${this._isOptionsOpen}
37
+ aria-controls="${this.id}-listbox"
38
+ aria-haspopup="listbox"
39
+ aria-label="Åpne liste"
40
+ ?disabled=${this.disabled}
41
+ ?data-disabled=${this.disabled}
42
+ role="button"
43
+ tabindex="${this.disabled?"-1":"0"}"
44
+ >
45
+ <pkt-icon
46
+ class=${$.e({"pkt-combobox__arrow-icon":!0,"pkt-combobox__arrow-icon--open":this._isOptionsOpen})}
47
+ name="chevron-thin-down"
48
+ ></pkt-icon>
49
+ </div>
50
+ <div ${u.n(this.focusRef)} tabindex="-1" @keydown=${this.handleArrowClick}></div>
51
+ </div>
52
+
53
+ <pkt-listbox
54
+ id="${this.id}-listbox"
55
+ .options=${this._options}
56
+ .isOpen=${this._isOptionsOpen}
57
+ .searchPlaceholder=${this.searchPlaceholder}
58
+ .label="Liste: ${this.label||""}"
59
+ ?includeSearch=${this.includeSearch}
60
+ ?isMultiSelect=${this.multiple}
61
+ ?allowUserInput=${this.allowUserInput&&!this._maxIsReached}
62
+ ?maxIsReached=${this._maxIsReached}
63
+ .customUserInput=${c.o(this._addValueText)}
64
+ .userMessage=${this._userInfoMessage}
65
+ @search=${this.handleSearch}
66
+ @option-toggle=${this.handleOptionToggled}
67
+ @select-all=${this.addAllOptions}
68
+ @close-options=${()=>this._isOptionsOpen=!1}
69
+ .searchValue=${this._search||null}
70
+ .maxLength=${this.maxlength||0}
71
+ ${u.n(this.listboxRef)}
72
+ ></pkt-listbox>
73
+ </div>
74
+
75
+ ${this.tagPlacement==="outside"&&this.multiple?l.x`<div class="pkt-combobox__tags-outside">
76
+ ${this.renderSingleOrMultipleValues()}
77
+ </div>`:l.E}
78
+ </pkt-input-wrapper>
79
+ `}renderInputField(){return this.typeahead||this.allowUserInput?l.x`
80
+ <div class="pkt-combobox__input-div combobox__input">
81
+ <input
82
+ type="text"
83
+ id="${this.id}-input"
84
+ name=${(this.name||this.id)+"-input"}
85
+ @input=${this.handleInput}
86
+ @keydown=${this.handleInputKeydown}
87
+ @focus=${this.handleFocus}
88
+ @blur=${this.handleBlur}
89
+ autocomplete="off"
90
+ role="combobox"
91
+ aria-label=${c.o(this.label)}
92
+ aria-autocomplete=${this.typeahead?"both":"list"}
93
+ aria-controls="${this.id}-listbox"
94
+ aria-multiselectable=${c.o(this.multiple?"true":void 0)}
95
+ aria-activedescendant=${c.o(this._value[0]&&this.findValueInOptions(this._value[0])?`${this.id}-listbox-${this.findIndexInOptions(this._value[0])}`:void 0)}
96
+ ${u.n(this.inputRef)}
97
+ />
98
+ </div>
99
+ `:l.x`
100
+ <input
101
+ type="hidden"
102
+ id="${this.id}-input"
103
+ name=${(this.name||this.id)+"-input"}
104
+ .value=${this._value.join(",")}
105
+ ${u.n(this.inputRef)}
106
+ />
107
+ `}renderSingleOrMultipleValues(){const t=!this.multiple,e=this._editingSingleValue?null:this.renderValueTag(this.findValueInOptions(this._value[0])),s=I.c(this._value,i=>i,i=>{var a;const n=this.findValueInOptions(i),h=(a=this.options.find(r=>r.value===i))==null?void 0:a.tagSkinColor;return l.x`
108
+ <pkt-tag
109
+ skin=${h||"blue-dark"}
110
+ ?closeTag=${!this.disabled}
111
+ @close=${()=>this.handleTagRemove(i)}
112
+ >
113
+ ${this.renderValueTag(n)}
114
+ </pkt-tag>
115
+ `});return t?e:s}renderValueTag(t){if(!t)return"";switch(this.displayValueAs){case"prefixAndValue":return l.x`<span data-focusfix=${this.id}>${t.prefix||""} ${t.value}</span>`;case"value":return l.x`<span data-focusfix=${this.id}>${t.value}</span>`;case"label":default:return l.x`<span data-focusfix=${this.id}>${t.label||t.value}</span>`}}handleInput(t){if(t.stopPropagation(),t.stopImmediatePropagation(),this.disabled)return;this.touched=!0;const e=t.target;if(this._search=e.value,this.checkForMatches(),this.typeahead)if(this._search){if(this._options=this.options.filter(s=>{var i;return(i=s.fulltext)==null?void 0:i.toLowerCase().includes(this._search.toLowerCase())}),t.inputType!=="deleteContentBackward"){const s=this._options.filter(i=>{var n;return!i.selected&&((n=i.label)==null?void 0:n.toLowerCase().startsWith(this._search.toLowerCase()))});if(s.length>0&&this.inputRef.value&&this.inputRef.value.type!=="hidden"){const i=s[0];i!=null&&i.label&&(e.value=i.label,window.setTimeout(()=>e.setSelectionRange(this._search.length,e.value.length),0),e.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 t=this.findValueInOptions(this._value[0]);this._editingSingleValue=!0,this.inputRef.value.value=this.displayValueAs==="label"&&(t!=null&&t.label)?t.label:this._value[0]}this._inputFocus=!0,this._search="",this._options=[...this.options],this._isOptionsOpen=!0,this.onFocus(),this.requestUpdate()}}handleFocusOut(t){var e,s,i,n,h;if(!this.disabled&&((s=(e=t.relatedTarget)==null?void 0:e.closest("pkt-combobox"))==null?void 0:s.id)!==this.id&&((n=(i=t.relatedTarget)==null?void 0:i.closest("pkt-combobox"))==null?void 0:n.id)!==this.id&&((h=t.target)==null?void 0:h.getAttribute("data-focusfix"))!==this.id&&t.relatedTarget!==this.focusRef.value&&t.relatedTarget!==this.inputRef.value&&t.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 a=this.inputRef.value.value;!this._value.includes(a)&&!this._options.find(r=>r.label===a)?this.allowUserInput?this.addNewUserValue(a):this.multiple||this.removeValue(this._value[0]):this._value.includes(a)||this.setSelected(a),this.inputRef.value.value=""}this._isOptionsOpen=!1,this.onBlur()}}handleBlur(){this._inputFocus=!1,this._editingSingleValue=!1,this.onBlur()}handleInputClick(t){var e,s;this.disabled||(t.currentTarget&&t.currentTarget!==this.arrowRef.value&&((e=this.inputRef.value)==null?void 0:e.type)!=="hidden"?(s=this.inputRef.value)==null||s.focus():this.handleArrowClick(t))}handleArrowClick(t){var e,s;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():(s=this.arrowRef.value)==null||s.focus())}handleOptionToggled(t){this.toggleValue(t.detail)}handleSearch(t){t.stopPropagation(),this._search=t.detail.toLowerCase()}handleInputKeydown(t){var e,s,i;switch(t.key){case",":case"Enter":t.preventDefault(),this.addValue();break;case"Backspace":!this._search&&((e=this.inputRef.value)==null?void 0:e.type)==="hidden"&&this.removeLastValue(t);break;case"Tab":case"ArrowDown":t.shiftKey||((s=this.listboxRef.value)==null||s.focusFirstOrSelectedOption(),t.preventDefault());break;case"Escape":this._isOptionsOpen=!1,(i=this.arrowRef.value)==null||i.focus(),t.preventDefault();break}}handleTagRemove(t){this.removeSelected(t)}blurInput(){this.inputRef.value&&this.inputRef.value.matches(":focus")&&this.inputRef.value.blur()}checkForMatches(){var h;const t=((h=this.inputRef.value)==null?void 0:h.value)||this._search||"",e=t.trim().toLowerCase()||"";if(!e){!this.multiple&&this._value[0]&&this.removeValue(this._value[0]),this.resetComboboxInput(!1);return}const s=this._value.find(a=>a.toLowerCase()===e),i=this._options.filter(a=>{var r;return((r=a.label)==null?void 0:r.toLowerCase().includes(e))??!1}),n=i.find(a=>{var r;return((r=a.label)==null?void 0:r.toLowerCase())===e||a.value.toLowerCase()===e});switch(!0){case((i.length===0||!n)&&this.allowUserInput):this._addValueText=t,this._userInfoMessage="";break;case(i.length===0&&!this.allowUserInput):this._addValueText=null,this._userInfoMessage="Ingen match i søket";break;case!!s:this._addValueText=null,this._userInfoMessage="Verdien er allerede valgt";break;case i.length>1:this._addValueText=null,this._userInfoMessage="";break;default:this._addValueText=null,this._userInfoMessage=""}}findValueInOptions(t){return this.options.find(e=>e.value===t||e.label===t)||null}findIndexInOptions(t){return this._options.findIndex(e=>e.value===t||e.label===t)}isMaxItemsReached(){const t=this.maxlength!==null&&this._value.length>=this.maxlength;return t?this._maxIsReached=!0:this._maxIsReached=!1,t}toggleValue(t){var g,k;if(this.disabled)return;this.touched=!0,this._userInfoMessage="",this._addValueText=null;const e=((g=this.findValueInOptions(t))==null?void 0:g.value)||null,s=this._value.includes(t||e||""),i=!!e,n=((k=this._options.find(_=>_.value===t))==null?void 0:k.disabled)||!1,h=!(t!=null&&t.trim()),a=!this.multiple,r=this.multiple,x=this.isMaxItemsReached();let p=!1,f=!0,v="",m="";n||(!i&&this.allowUserInput&&!h?(this.addNewUserValue(t),v="Ny verdi lagt til",p=!r):!i&&!this.allowUserInput?(a&&this._value[0]&&this.removeValue(this._value[0]),f=!1,p=!0,v="Ingen treff i søket"):s?(this.removeValue(e),p=!0):h&&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())):r&&!x?(this.setSelected(e),p=!0):r&&x?(this._userInfoMessage="Maks antall valg nådd",f=!1,m=t):(a&&this.removeAllSelected(),this._userInfoMessage="Ingen gyldig verdi valgt",f=!1,p=!0,m=t),this._isOptionsOpen=p,p||window.setTimeout(()=>{var _;(_=this.focusRef.value)==null||_.focus()},0),this._userInfoMessage=v,this._search=m||"",this.resetComboboxInput(f),r&&this.isMaxItemsReached())}setSelected(t){if(!this._value.includes(t)){if(this.multiple&&this.isMaxItemsReached()){this._userInfoMessage="Maks antall valg nådd";return}!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)}}removeSelected(t){if(!t)return;this._value=this._value.filter(s=>s!==t);const e=this.findValueInOptions(t);e?(e.selected=!1,e.userAdded?(this._options=[...this._options.filter(s=>s.value!==t)],this.options=[...this.options.filter(s=>s.value!==t)]):this._options=[...this._options,e]):!t&&!this.multiple&&(this._options=this._options.map(s=>(s.selected=!1,s)))}addAllOptions(){if(this.multiple){if(this.maxlength&&this._options.length>this.maxlength){this._userInfoMessage="For mange valgt";return}this._value=this._options.map(t=>t.value),this._options=this._options.map(t=>(t.selected=!0,t)),this.requestUpdate()}}removeAllSelected(){this._value=[],this._options=this._options.map(t=>(t.selected=!1,t)),this._options=this._options.filter(t=>!t.userAdded),this.requestUpdate()}addValue(){var e;const t=((e=this.inputRef.value)==null?void 0:e.value.trim())||"";this._search=t,this.toggleValue(t)}removeValue(t){this._value=this.multiple?this._value.filter(e=>e!==t):[],this.removeSelected(t)}addNewUserValue(t){if(!t||t.trim()==="")return;if(!this.multiple)this._value[0]&&this.removeSelected(this._value[0]),this._value=[t],this._isOptionsOpen=!1,this.blurInput();else if(!this.findValueInOptions(t)){if(this.isMaxItemsReached())return;this._value=[...this._value,t]}const e={value:t,label:t,userAdded:!0};this.options=[e,...this.options],this._options=[e,...this._options],this.setSelected(t),this.requestUpdate()}resetComboboxInput(t=!0){if(this._addValueText=null,this.inputRef.value&&this.inputRef.value.type!=="hidden"&&t)if(this._search="",this.multiple)this.inputRef.value.value="";else{const e=this.findValueInOptions(this._value[0]);window.setTimeout(()=>{!this.inputRef.value||this.inputRef.value.type==="hidden"||(this.inputRef.value.value=this.displayValueAs==="label"&&(e!=null&&e.label)?e.label:this._value[0]||"")},0),this._userInfoMessage=""}this._options=[...this.options]}removeLastValue(t){if(this._value.length===0)return;t.preventDefault();const e=this._value[this._value.length-1];e&&this.removeSelected(e),this.isMaxItemsReached()}};o([l.n({type:String,reflect:!0})],exports.PktCombobox.prototype,"value",2);o([l.n({type:Array})],exports.PktCombobox.prototype,"options",2);o([l.n({type:Boolean})],exports.PktCombobox.prototype,"allowUserInput",2);o([l.n({type:Boolean})],exports.PktCombobox.prototype,"typeahead",2);o([l.n({type:Boolean})],exports.PktCombobox.prototype,"includeSearch",2);o([l.n({type:String})],exports.PktCombobox.prototype,"searchPlaceholder",2);o([l.n({type:Boolean})],exports.PktCombobox.prototype,"multiple",2);o([l.n({type:Number})],exports.PktCombobox.prototype,"maxlength",2);o([l.n({type:String})],exports.PktCombobox.prototype,"displayValueAs",2);o([l.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([l.t("pkt-combobox")],exports.PktCombobox);
@@ -0,0 +1,491 @@
1
+ import { E as y, x as d, n as r, a as O } from "./element-DiqKrDty.js";
2
+ import { o as f } from "./if-defined-DeANa4n5.js";
3
+ import { r as c } from "./state-CDwPbiQj.js";
4
+ import { e as _, n as v } from "./ref-B70YZNXm.js";
5
+ import { e as k } from "./class-map-D4tSZX70.js";
6
+ import { c as R } from "./repeat-CNLpCTun.js";
7
+ import { P as V } from "./input-element-C4mmTk6h.js";
8
+ import { P as C } from "./pkt-options-controller-BkWE4pZe.js";
9
+ import { P as S } from "./pkt-slot-controller-BtVLTZb7.js";
10
+ import "./input-wrapper-P_oEi6dk.js";
11
+ import "./icon-BdY52BIt.js";
12
+ import "./tag-DoS5S2Bq.js";
13
+ import "./listbox-CfJWJDrc.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 = (t, e, s, i) => {
22
+ for (var o = i > 1 ? void 0 : i ? F(e, s) : e, n = t.length - 1, l; n >= 0; n--)
23
+ (l = t[n]) && (o = (i ? l(e, s, o) : l(o)) || o);
24
+ return i && o && M(e, s, o), o;
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", (t) => {
33
+ this._isOptionsOpen && !this.contains(t.target) && this.handleFocusOut(t);
34
+ }), this._options = [], this.optionsController.nodes.length) {
35
+ const t = [];
36
+ this.optionsController.nodes.forEach((e) => {
37
+ if (!e.textContent && !e.getAttribute("value")) return null;
38
+ const s = {
39
+ value: e.getAttribute("value") || e.textContent || "",
40
+ label: e.textContent || e.getAttribute("value") || ""
41
+ };
42
+ e.getAttribute("data-prefix") && (s.prefix = e.getAttribute("data-prefix") || void 0), e.getAttribute("tagskincolor") && (s.tagSkinColor = e.getAttribute("tagskincolor")), e.getAttribute("description") && (s.description = e.getAttribute("description") || void 0), s.fulltext = s.value + s.label + (s.prefix || ""), t.push(s);
43
+ }), t.length && (this.options = [...t], this._options = [...t]);
44
+ }
45
+ }
46
+ updated(t) {
47
+ 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("options") && this.options.length && (this._options = this.options, this._options.forEach((e) => {
48
+ e.fulltext = e.value + e.label + (e.prefix || ""), e.selected = this._value.includes(e.value);
49
+ })), t.has("_search") && this.dispatchEvent(
50
+ new CustomEvent("search", {
51
+ detail: this._search,
52
+ bubbles: !1
53
+ })
54
+ ), super.updated(t);
55
+ }
56
+ attributeChangedCallback(t, e, s) {
57
+ 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((i) => {
58
+ i.fulltext = i.value + i.label + (i.prefix || "");
59
+ }), this._search = ""), super.attributeChangedCallback(t, e, s);
60
+ }
61
+ // Render methods
62
+ render() {
63
+ return d`
64
+ <pkt-input-wrapper
65
+ .label=${this.label}
66
+ .helptext=${this.helptext}
67
+ .helptextDropdown=${f(this.helptextDropdown)}
68
+ .helptextDropdownButton=${f(this.helptextDropdownButton)}
69
+ ?fullwidth=${this.fullwidth}
70
+ ?hasError=${this.hasError}
71
+ ?inline=${this.inline}
72
+ ?disabled=${this.disabled}
73
+ .errorMessage=${this.errorMessage}
74
+ ?optionalTag=${this.optionalTag}
75
+ .optionalText=${this.optionalText}
76
+ ?requiredTag=${this.requiredTag}
77
+ .requiredText=${this.requiredText}
78
+ ?useWrapper=${this.useWrapper}
79
+ .forId=${this.allowUserInput || this.typeahead ? this.id + "-input" : this.id + "-arrow"}
80
+ class="pkt-combobox__wrapper"
81
+ @labelClick=${this.handleInputClick}
82
+ >
83
+ <div class="pkt-contents" ${v(this.helptextSlot)} name="helptext" slot="helptext"></div>
84
+ <div class="pkt-combobox" @focusout=${this.handleFocusOut}>
85
+ <div
86
+ class=${k({
87
+ "pkt-combobox__input": !0,
88
+ "pkt-combobox__input--fullwidth": this.fullwidth,
89
+ "pkt-combobox__input--open": this._isOptionsOpen,
90
+ "pkt-combobox__input--error": this.hasError,
91
+ "pkt-combobox__input--disabled": this.disabled
92
+ })}
93
+ tabindex="-1"
94
+ @click=${this.handleInputClick}
95
+ >
96
+ ${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}
97
+ ${this.renderInputField()}
98
+ <div
99
+ class="pkt-btn pkt-btn--tertiary pkt-combobox__arrow"
100
+ @click=${this.handleArrowClick}
101
+ @keydown=${this.handleArrowClick}
102
+ id="${this.id}-arrow"
103
+ ${v(this.arrowRef)}
104
+ aria-expanded=${this._isOptionsOpen}
105
+ aria-controls="${this.id}-listbox"
106
+ aria-haspopup="listbox"
107
+ aria-label="Åpne liste"
108
+ ?disabled=${this.disabled}
109
+ ?data-disabled=${this.disabled}
110
+ role="button"
111
+ tabindex="${this.disabled ? "-1" : "0"}"
112
+ >
113
+ <pkt-icon
114
+ class=${k({
115
+ "pkt-combobox__arrow-icon": !0,
116
+ "pkt-combobox__arrow-icon--open": this._isOptionsOpen
117
+ })}
118
+ name="chevron-thin-down"
119
+ ></pkt-icon>
120
+ </div>
121
+ <div ${v(this.focusRef)} tabindex="-1" @keydown=${this.handleArrowClick}></div>
122
+ </div>
123
+
124
+ <pkt-listbox
125
+ id="${this.id}-listbox"
126
+ .options=${this._options}
127
+ .isOpen=${this._isOptionsOpen}
128
+ .searchPlaceholder=${this.searchPlaceholder}
129
+ .label="Liste: ${this.label || ""}"
130
+ ?includeSearch=${this.includeSearch}
131
+ ?isMultiSelect=${this.multiple}
132
+ ?allowUserInput=${this.allowUserInput && !this._maxIsReached}
133
+ ?maxIsReached=${this._maxIsReached}
134
+ .customUserInput=${f(this._addValueText)}
135
+ .userMessage=${this._userInfoMessage}
136
+ @search=${this.handleSearch}
137
+ @option-toggle=${this.handleOptionToggled}
138
+ @select-all=${this.addAllOptions}
139
+ @close-options=${() => this._isOptionsOpen = !1}
140
+ .searchValue=${this._search || null}
141
+ .maxLength=${this.maxlength || 0}
142
+ ${v(this.listboxRef)}
143
+ ></pkt-listbox>
144
+ </div>
145
+
146
+ ${this.tagPlacement === "outside" && this.multiple ? d`<div class="pkt-combobox__tags-outside">
147
+ ${this.renderSingleOrMultipleValues()}
148
+ </div>` : y}
149
+ </pkt-input-wrapper>
150
+ `;
151
+ }
152
+ renderInputField() {
153
+ return this.typeahead || this.allowUserInput ? d`
154
+ <div class="pkt-combobox__input-div combobox__input">
155
+ <input
156
+ type="text"
157
+ id="${this.id}-input"
158
+ name=${(this.name || this.id) + "-input"}
159
+ @input=${this.handleInput}
160
+ @keydown=${this.handleInputKeydown}
161
+ @focus=${this.handleFocus}
162
+ @blur=${this.handleBlur}
163
+ autocomplete="off"
164
+ role="combobox"
165
+ aria-label=${f(this.label)}
166
+ aria-autocomplete=${this.typeahead ? "both" : "list"}
167
+ aria-controls="${this.id}-listbox"
168
+ aria-multiselectable=${f(this.multiple ? "true" : void 0)}
169
+ aria-activedescendant=${f(
170
+ this._value[0] && this.findValueInOptions(this._value[0]) ? `${this.id}-listbox-${this.findIndexInOptions(this._value[0])}` : void 0
171
+ )}
172
+ ${v(this.inputRef)}
173
+ />
174
+ </div>
175
+ ` : d`
176
+ <input
177
+ type="hidden"
178
+ id="${this.id}-input"
179
+ name=${(this.name || this.id) + "-input"}
180
+ .value=${this._value.join(",")}
181
+ ${v(this.inputRef)}
182
+ />
183
+ `;
184
+ }
185
+ renderSingleOrMultipleValues() {
186
+ const t = !this.multiple, e = this._editingSingleValue ? null : this.renderValueTag(this.findValueInOptions(this._value[0])), s = R(
187
+ this._value,
188
+ (i) => i,
189
+ (i) => {
190
+ var l;
191
+ const o = this.findValueInOptions(i), n = (l = this.options.find((u) => u.value === i)) == null ? void 0 : l.tagSkinColor;
192
+ return d`
193
+ <pkt-tag
194
+ skin=${n || "blue-dark"}
195
+ ?closeTag=${!this.disabled}
196
+ @close=${() => this.handleTagRemove(i)}
197
+ >
198
+ ${this.renderValueTag(o)}
199
+ </pkt-tag>
200
+ `;
201
+ }
202
+ );
203
+ return t ? e : s;
204
+ }
205
+ renderValueTag(t) {
206
+ if (!t) return "";
207
+ switch (this.displayValueAs) {
208
+ case "prefixAndValue":
209
+ return d`<span data-focusfix=${this.id}>${t.prefix || ""} ${t.value}</span>`;
210
+ case "value":
211
+ return d`<span data-focusfix=${this.id}>${t.value}</span>`;
212
+ case "label":
213
+ default:
214
+ return d`<span data-focusfix=${this.id}>${t.label || t.value}</span>`;
215
+ }
216
+ }
217
+ // Event handlers
218
+ handleInput(t) {
219
+ if (t.stopPropagation(), t.stopImmediatePropagation(), this.disabled) return;
220
+ this.touched = !0;
221
+ const e = t.target;
222
+ if (this._search = e.value, this.checkForMatches(), this.typeahead)
223
+ if (this._search) {
224
+ if (this._options = this.options.filter(
225
+ (s) => {
226
+ var i;
227
+ return (i = s.fulltext) == null ? void 0 : i.toLowerCase().includes(this._search.toLowerCase());
228
+ }
229
+ ), t.inputType !== "deleteContentBackward") {
230
+ const s = this._options.filter(
231
+ (i) => {
232
+ var o;
233
+ return !i.selected && ((o = i.label) == null ? void 0 : o.toLowerCase().startsWith(this._search.toLowerCase()));
234
+ }
235
+ );
236
+ if (s.length > 0 && this.inputRef.value && this.inputRef.value.type !== "hidden") {
237
+ const i = s[0];
238
+ i != null && i.label && (e.value = i.label, window.setTimeout(
239
+ () => e.setSelectionRange(this._search.length, e.value.length),
240
+ 0
241
+ ), e.selectionDirection = "backward");
242
+ }
243
+ }
244
+ } else
245
+ this._options = [...this.options];
246
+ }
247
+ handleFocus() {
248
+ if (!this.disabled) {
249
+ if (!this.multiple && this._value[0] && this.inputRef.value && this.inputRef.value.type !== "hidden") {
250
+ const t = this.findValueInOptions(this._value[0]);
251
+ this._editingSingleValue = !0, this.inputRef.value.value = this.displayValueAs === "label" && (t != null && t.label) ? t.label : this._value[0];
252
+ }
253
+ this._inputFocus = !0, this._search = "", this._options = [...this.options], this._isOptionsOpen = !0, this.onFocus(), this.requestUpdate();
254
+ }
255
+ }
256
+ handleFocusOut(t) {
257
+ var e, s, i, o, n;
258
+ if (!this.disabled && ((s = (e = t.relatedTarget) == null ? void 0 : e.closest("pkt-combobox")) == null ? void 0 : s.id) !== this.id && ((o = (i = t.relatedTarget) == null ? void 0 : i.closest("pkt-combobox")) == null ? void 0 : o.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) {
259
+ if (this._inputFocus = !1, this._addValueText = null, this._userInfoMessage = "", this._search = "", this.inputRef.value && this.inputRef.value.type !== "hidden" && this.inputRef.value.value !== "") {
260
+ const l = this.inputRef.value.value;
261
+ !this._value.includes(l) && !this._options.find((u) => u.label === l) ? this.allowUserInput ? this.addNewUserValue(l) : this.multiple || this.removeValue(this._value[0]) : this._value.includes(l) || this.setSelected(l), this.inputRef.value.value = "";
262
+ }
263
+ this._isOptionsOpen = !1, this.onBlur();
264
+ }
265
+ }
266
+ handleBlur() {
267
+ this._inputFocus = !1, this._editingSingleValue = !1, this.onBlur();
268
+ }
269
+ handleInputClick(t) {
270
+ var e, s;
271
+ this.disabled || (t.currentTarget && t.currentTarget !== this.arrowRef.value && ((e = this.inputRef.value) == null ? void 0 : e.type) !== "hidden" ? (s = this.inputRef.value) == null || s.focus() : this.handleArrowClick(t));
272
+ }
273
+ handleArrowClick(t) {
274
+ var e, s;
275
+ 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() : (s = this.arrowRef.value) == null || s.focus());
276
+ }
277
+ handleOptionToggled(t) {
278
+ this.toggleValue(t.detail);
279
+ }
280
+ handleSearch(t) {
281
+ t.stopPropagation(), this._search = t.detail.toLowerCase();
282
+ }
283
+ handleInputKeydown(t) {
284
+ var e, s, i;
285
+ switch (t.key) {
286
+ case ",":
287
+ case "Enter":
288
+ t.preventDefault(), this.addValue();
289
+ break;
290
+ case "Backspace":
291
+ !this._search && ((e = this.inputRef.value) == null ? void 0 : e.type) === "hidden" && this.removeLastValue(t);
292
+ break;
293
+ case "Tab":
294
+ case "ArrowDown":
295
+ t.shiftKey || ((s = this.listboxRef.value) == null || s.focusFirstOrSelectedOption(), t.preventDefault());
296
+ break;
297
+ case "Escape":
298
+ this._isOptionsOpen = !1, (i = this.arrowRef.value) == null || i.focus(), t.preventDefault();
299
+ break;
300
+ }
301
+ }
302
+ handleTagRemove(t) {
303
+ this.removeSelected(t);
304
+ }
305
+ blurInput() {
306
+ this.inputRef.value && this.inputRef.value.matches(":focus") && this.inputRef.value.blur();
307
+ }
308
+ checkForMatches() {
309
+ var n;
310
+ const t = ((n = this.inputRef.value) == null ? void 0 : n.value) || this._search || "", e = t.trim().toLowerCase() || "";
311
+ if (!e) {
312
+ !this.multiple && this._value[0] && this.removeValue(this._value[0]), this.resetComboboxInput(!1);
313
+ return;
314
+ }
315
+ const s = this._value.find((l) => l.toLowerCase() === e), i = this._options.filter(
316
+ (l) => {
317
+ var u;
318
+ return ((u = l.label) == null ? void 0 : u.toLowerCase().includes(e)) ?? !1;
319
+ }
320
+ ), o = i.find(
321
+ (l) => {
322
+ var u;
323
+ return ((u = l.label) == null ? void 0 : u.toLowerCase()) === e || l.value.toLowerCase() === e;
324
+ }
325
+ );
326
+ switch (!0) {
327
+ case ((i.length === 0 || !o) && this.allowUserInput):
328
+ this._addValueText = t, this._userInfoMessage = "";
329
+ break;
330
+ case (i.length === 0 && !this.allowUserInput):
331
+ this._addValueText = null, this._userInfoMessage = "Ingen match i søket";
332
+ break;
333
+ case !!s:
334
+ this._addValueText = null, this._userInfoMessage = "Verdien er allerede valgt";
335
+ break;
336
+ case i.length > 1:
337
+ this._addValueText = null, this._userInfoMessage = "";
338
+ break;
339
+ default:
340
+ this._addValueText = null, this._userInfoMessage = "";
341
+ }
342
+ }
343
+ findValueInOptions(t) {
344
+ return this.options.find((e) => e.value === t || e.label === t) || null;
345
+ }
346
+ findIndexInOptions(t) {
347
+ return this._options.findIndex((e) => e.value === t || e.label === t);
348
+ }
349
+ isMaxItemsReached() {
350
+ const t = this.maxlength !== null && this._value.length >= this.maxlength;
351
+ return t ? this._maxIsReached = !0 : this._maxIsReached = !1, t;
352
+ }
353
+ toggleValue(t) {
354
+ var I, w;
355
+ if (this.disabled) return;
356
+ this.touched = !0, this._userInfoMessage = "", this._addValueText = null;
357
+ const e = ((I = this.findValueInOptions(t)) == null ? void 0 : I.value) || null, s = this._value.includes(t || e || ""), i = !!e, o = ((w = this._options.find((m) => m.value === t)) == null ? void 0 : w.disabled) || !1, n = !(t != null && t.trim()), l = !this.multiple, u = this.multiple, $ = this.isMaxItemsReached();
358
+ let p = !1, b = !0, g = "", x = "";
359
+ o || (!i && this.allowUserInput && !n ? (this.addNewUserValue(t), g = "Ny verdi lagt til", p = !u) : !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(e), p = !0) : n && l ? (this.removeAllSelected(), p = !0) : l ? (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) : (l && this.removeAllSelected(), this._userInfoMessage = "Ingen gyldig verdi valgt", b = !1, p = !0, x = t), this._isOptionsOpen = p, p || window.setTimeout(() => {
360
+ var m;
361
+ (m = this.focusRef.value) == null || m.focus();
362
+ }, 0), this._userInfoMessage = g, this._search = x || "", this.resetComboboxInput(b), u && this.isMaxItemsReached());
363
+ }
364
+ setSelected(t) {
365
+ if (!this._value.includes(t)) {
366
+ if (this.multiple && this.isMaxItemsReached()) {
367
+ this._userInfoMessage = "Maks antall valg nådd";
368
+ return;
369
+ }
370
+ !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);
371
+ }
372
+ }
373
+ removeSelected(t) {
374
+ if (!t) return;
375
+ this._value = this._value.filter((s) => s !== t);
376
+ const e = this.findValueInOptions(t);
377
+ e ? (e.selected = !1, e.userAdded ? (this._options = [...this._options.filter((s) => s.value !== t)], this.options = [...this.options.filter((s) => s.value !== t)]) : this._options = [...this._options, e]) : !t && !this.multiple && (this._options = this._options.map((s) => (s.selected = !1, s)));
378
+ }
379
+ addAllOptions() {
380
+ if (this.multiple) {
381
+ if (this.maxlength && this._options.length > this.maxlength) {
382
+ this._userInfoMessage = "For mange valgt";
383
+ return;
384
+ }
385
+ this._value = this._options.map((t) => t.value), this._options = this._options.map((t) => (t.selected = !0, t)), this.requestUpdate();
386
+ }
387
+ }
388
+ removeAllSelected() {
389
+ this._value = [], this._options = this._options.map((t) => (t.selected = !1, t)), this._options = this._options.filter((t) => !t.userAdded), this.requestUpdate();
390
+ }
391
+ addValue() {
392
+ var e;
393
+ const t = ((e = this.inputRef.value) == null ? void 0 : e.value.trim()) || "";
394
+ this._search = t, this.toggleValue(t);
395
+ }
396
+ removeValue(t) {
397
+ this._value = this.multiple ? this._value.filter((e) => e !== t) : [], this.removeSelected(t);
398
+ }
399
+ addNewUserValue(t) {
400
+ if (!t || t.trim() === "") return;
401
+ if (!this.multiple)
402
+ this._value[0] && this.removeSelected(this._value[0]), this._value = [t], this._isOptionsOpen = !1, this.blurInput();
403
+ else if (!this.findValueInOptions(t)) {
404
+ if (this.isMaxItemsReached()) return;
405
+ this._value = [...this._value, t];
406
+ }
407
+ const e = { value: t, label: t, userAdded: !0 };
408
+ this.options = [e, ...this.options], this._options = [e, ...this._options], this.setSelected(t), this.requestUpdate();
409
+ }
410
+ resetComboboxInput(t = !0) {
411
+ if (this._addValueText = null, this.inputRef.value && this.inputRef.value.type !== "hidden" && t)
412
+ if (this._search = "", this.multiple)
413
+ this.inputRef.value.value = "";
414
+ else {
415
+ const e = this.findValueInOptions(this._value[0]);
416
+ window.setTimeout(() => {
417
+ !this.inputRef.value || this.inputRef.value.type === "hidden" || (this.inputRef.value.value = this.displayValueAs === "label" && (e != null && e.label) ? e.label : this._value[0] || "");
418
+ }, 0), this._userInfoMessage = "";
419
+ }
420
+ this._options = [...this.options];
421
+ }
422
+ removeLastValue(t) {
423
+ if (this._value.length === 0) return;
424
+ t.preventDefault();
425
+ const e = this._value[this._value.length - 1];
426
+ e && this.removeSelected(e), this.isMaxItemsReached();
427
+ }
428
+ };
429
+ h([
430
+ r({ type: String, reflect: !0 })
431
+ ], a.prototype, "value", 2);
432
+ h([
433
+ r({ type: Array })
434
+ ], a.prototype, "options", 2);
435
+ h([
436
+ r({ type: Boolean })
437
+ ], a.prototype, "allowUserInput", 2);
438
+ h([
439
+ r({ type: Boolean })
440
+ ], a.prototype, "typeahead", 2);
441
+ h([
442
+ r({ type: Boolean })
443
+ ], a.prototype, "includeSearch", 2);
444
+ h([
445
+ r({ type: String })
446
+ ], a.prototype, "searchPlaceholder", 2);
447
+ h([
448
+ r({ type: Boolean })
449
+ ], a.prototype, "multiple", 2);
450
+ h([
451
+ r({ type: Number })
452
+ ], a.prototype, "maxlength", 2);
453
+ h([
454
+ r({ type: String })
455
+ ], a.prototype, "displayValueAs", 2);
456
+ h([
457
+ r({ type: String })
458
+ ], a.prototype, "tagPlacement", 2);
459
+ h([
460
+ c()
461
+ ], a.prototype, "_options", 2);
462
+ h([
463
+ c()
464
+ ], a.prototype, "_isOptionsOpen", 2);
465
+ h([
466
+ c()
467
+ ], a.prototype, "_value", 2);
468
+ h([
469
+ c()
470
+ ], a.prototype, "_userInfoMessage", 2);
471
+ h([
472
+ c()
473
+ ], a.prototype, "_addValueText", 2);
474
+ h([
475
+ c()
476
+ ], a.prototype, "_maxIsReached", 2);
477
+ h([
478
+ c()
479
+ ], a.prototype, "_search", 2);
480
+ h([
481
+ c()
482
+ ], a.prototype, "_inputFocus", 2);
483
+ h([
484
+ c()
485
+ ], a.prototype, "_editingSingleValue", 2);
486
+ a = h([
487
+ O("pkt-combobox")
488
+ ], a);
489
+ export {
490
+ a as P
491
+ };