@oslokommune/punkt-elements 18.8.0 → 18.9.0

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 (53) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/base-elements/form-attribute.test.d.ts +0 -0
  3. package/dist/base-elements/input-element.d.ts +3 -2
  4. package/dist/{checkbox-COw1Uwnm.js → checkbox-BhyUp6l6.js} +1 -1
  5. package/dist/{checkbox-CBZEGmqa.cjs → checkbox-DJfH-vTj.cjs} +1 -1
  6. package/dist/combobox-B9Qo7hbt.cjs +137 -0
  7. package/dist/{combobox-Cqqokx73.js → combobox-fzSaCPok.js} +8 -1
  8. package/dist/components/fileupload/fileupload-base.d.ts +2 -0
  9. package/dist/{datepicker-BzRhOIkG.cjs → datepicker-D6os8IVu.cjs} +2 -2
  10. package/dist/{datepicker-CtSYgxMs.js → datepicker-DMiZ3BBw.js} +8 -1
  11. package/dist/{fileupload-PJWEBD88.js → fileupload-C5lxuood.js} +21 -4
  12. package/dist/{fileupload-3OtW4Xlo.cjs → fileupload-Y4bDkaD9.cjs} +8 -2
  13. package/dist/{header-CxfDtS3Y.js → header-CCJeadiL.js} +1 -1
  14. package/dist/{header-D2SD2JLt.cjs → header-CP332MCg.cjs} +1 -1
  15. package/dist/{input-element-Qb0w3ChW.js → input-element-BWxgs8L-.js} +27 -15
  16. package/dist/{input-element-DhIEFeuP.cjs → input-element-PN5nWd1A.cjs} +1 -1
  17. package/dist/pkt-checkbox.cjs +1 -1
  18. package/dist/pkt-checkbox.js +1 -1
  19. package/dist/pkt-combobox.cjs +1 -1
  20. package/dist/pkt-combobox.js +1 -1
  21. package/dist/pkt-datepicker.cjs +1 -1
  22. package/dist/pkt-datepicker.js +1 -1
  23. package/dist/pkt-fileupload.cjs +1 -1
  24. package/dist/pkt-fileupload.js +1 -1
  25. package/dist/pkt-header.cjs +1 -1
  26. package/dist/pkt-header.js +1 -1
  27. package/dist/pkt-index.cjs +1 -1
  28. package/dist/pkt-index.js +10 -10
  29. package/dist/pkt-radiobutton.cjs +1 -1
  30. package/dist/pkt-radiobutton.js +1 -1
  31. package/dist/pkt-select.cjs +1 -1
  32. package/dist/pkt-select.js +1 -1
  33. package/dist/pkt-textarea.cjs +1 -1
  34. package/dist/pkt-textarea.js +1 -1
  35. package/dist/pkt-textinput.cjs +1 -1
  36. package/dist/pkt-textinput.js +1 -1
  37. package/dist/pkt-timepicker.cjs +1 -1
  38. package/dist/pkt-timepicker.js +1 -1
  39. package/dist/{radiobutton-BEzjKx1J.cjs → radiobutton-CnGhAnjp.cjs} +1 -1
  40. package/dist/{radiobutton-Cpwa5ezn.js → radiobutton-DWdn1O48.js} +1 -1
  41. package/dist/{select-c15YAQbr.js → select-CM-CcWab.js} +1 -1
  42. package/dist/{select-TAwBNhhf.cjs → select-D761TXmv.cjs} +1 -1
  43. package/dist/shared-types/fileupload.d.ts +2 -1
  44. package/dist/{textarea-BHGZhMN4.cjs → textarea-4s_SiG0_.cjs} +1 -1
  45. package/dist/{textarea-BPQVrOp9.js → textarea-D3SeDZ1r.js} +1 -1
  46. package/dist/{textinput-DHGUOsIA.js → textinput-Dje0Zcsa.js} +1 -1
  47. package/dist/{textinput-Cv4tal5W.cjs → textinput-uDRbleIa.cjs} +1 -1
  48. package/dist/{timepicker-C8DHbOpM.js → timepicker--CrfIU_7.js} +1 -1
  49. package/dist/{timepicker-BBUYnYzM.cjs → timepicker-auQ5Y6Et.cjs} +1 -1
  50. package/package.json +2 -2
  51. package/src/components/fileupload/fileupload-base.ts +13 -2
  52. package/src/components/fileupload/fileupload.ts +7 -1
  53. package/dist/combobox-N3NP77le.cjs +0 -137
@@ -37,6 +37,7 @@ export abstract class PktFileUploadBase
37
37
  @property({ type: String }) id: string = `pkt-fileupload-${uuidish()}`
38
38
  /** Field name used by native input (`form`) or hidden fileId inputs (`custom`). */
39
39
  @property({ type: String }) name: string = 'files'
40
+ @property({ type: String, reflect: true }) form?: string
40
41
  /** Optional label shown by `pkt-input-wrapper`. */
41
42
  @property({ type: String }) label: string = ''
42
43
  /** Optional help text shown under label. */
@@ -175,7 +176,8 @@ export abstract class PktFileUploadBase
175
176
  if (
176
177
  changedProperties.has('uploadStrategy') ||
177
178
  changedProperties.has('required') ||
178
- changedProperties.has('value')
179
+ changedProperties.has('value') ||
180
+ changedProperties.has('form')
179
181
  ) {
180
182
  this.syncFormSubmitListener()
181
183
  }
@@ -554,8 +556,17 @@ export abstract class PktFileUploadBase
554
556
  })
555
557
  }
556
558
 
559
+ protected get ownerForm(): HTMLFormElement | null {
560
+ if (this.form !== undefined) {
561
+ if (!this.form) return null
562
+ const owner = this.ownerDocument?.getElementById(this.form)
563
+ return owner instanceof HTMLFormElement ? owner : null
564
+ }
565
+ return this.closest('form')
566
+ }
567
+
557
568
  private syncFormSubmitListener() {
558
- const nextForm = this.closest('form')
569
+ const nextForm = this.ownerForm
559
570
  if (this.connectedForm === nextForm) return
560
571
 
561
572
  this.teardownFormSubmitListener()
@@ -157,6 +157,7 @@ export class PktFileUpload extends PktFileUploadBase implements IPktFileUpload {
157
157
  id=${`${this.id}-input`}
158
158
  type="file"
159
159
  name=${ifDefined(this.uploadStrategy === 'form' ? this.name : undefined)}
160
+ form=${ifDefined(this.form)}
160
161
  ?multiple=${this.multiple}
161
162
  ?disabled=${this.disabled}
162
163
  ?required=${this.required && this.uploadStrategy === 'form'}
@@ -172,7 +173,12 @@ export class PktFileUpload extends PktFileUploadBase implements IPktFileUpload {
172
173
  ${this.uploadStrategy === 'custom'
173
174
  ? filesAndTransfers.map(
174
175
  (fileItem) =>
175
- html`<input type="hidden" name=${this.name} value=${fileItem.fileId} />`,
176
+ html`<input
177
+ type="hidden"
178
+ name=${this.name}
179
+ value=${fileItem.fileId}
180
+ form=${ifDefined(this.form)}
181
+ />`,
176
182
  )
177
183
  : null}
178
184
  <div class="pkt-fileupload__drop-zone__placeholder">
@@ -1,137 +0,0 @@
1
- const e=require("./element-D_mCyFeX.cjs"),t=require("./class-map-DupQbnhE.cjs"),n=require("./if-defined-BbUZeoaQ.cjs"),r=require("./format-B8meU8Tm.cjs"),i=require("./element-with-slot-C66Jck5e.cjs");require("./icon-BzxBkRyE.cjs");const a=require("./ref-AuNEkS5a.cjs");require("./tag-CGlxtBOH.cjs");const o=require("./repeat-B3ksuY2F.cjs"),s=require("./listbox-kV4OO1Qa.cjs"),c=require("./input-element-DhIEFeuP.cjs"),l=require("./pkt-options-controller-DXAAVcBJ.cjs");require("./input-wrapper-D64Qn-QH.cjs");var u=(e,t,n)=>{switch(e){case`,`:return n?`addValue`:null;case`Enter`:return`addValue`;case`Tab`:case`ArrowDown`:return t?null:`focusListbox`;case`Escape`:return`closeOptions`;default:return null}},d=(e,t,n,r,i)=>{if(!e)return{action:`none`,value:null};let a=s.i(n,e);return!t.includes(e)&&!a?r?{action:`addUserValue`,value:e}:i?{action:`none`,value:null}:{action:`removeValue`,value:t[0]}:a&&!t.includes(a.value)?{action:`selectOption`,value:a.value}:{action:`none`,value:null}},f=(e,t,n,r,i)=>e.trim().toLowerCase()?{...s.c(e,t,n,r),shouldRemoveValue:!1,shouldResetInput:!1}:{addValueText:null,userInfoMessage:``,shouldRemoveValue:!i&&!!t[0],shouldResetInput:!0},p=(e,t,n)=>{let r=s.i(t,e);return n===`label`&&r?.label?r.label:e},m={markOptionSelected(e,t){if(t){for(let n of e)if(n.value===t){n.selected=!0;break}}},markOptionDeselected(e,t){if(t){for(let n of e)if(n.value===t){n.selected=!1;break}}},markAllSelected(e){for(let t of e)t.selected=!0},markAllDeselected(e){for(let t of e)t.selected=!1},removeUserAddedOptions(e){return e.filter(e=>!e.userAdded)}},h={parseOptionsFromSlot(e){let t=[];return e.forEach(e=>{if(!e.textContent&&!e.getAttribute(`value`))return;let n={value:e.getAttribute(`value`)||e.textContent||``,label:e.textContent||e.getAttribute(`value`)||``};e.getAttribute(`data-prefix`)&&(n.prefix=e.getAttribute(`data-prefix`)||void 0),e.getAttribute(`tagskincolor`)&&(n.tagSkinColor=e.getAttribute(`tagskincolor`)),e.getAttribute(`description`)&&(n.description=e.getAttribute(`description`)||void 0),n.fulltext=s.r(n),t.push(n)}),t}},g={cloneOptions(e){return Array.isArray(e)?e.map(e=>({...e})):[]},syncOptionsWithValues(e,t){let n=[...t];return e.forEach(e=>{e.value&&!e.label&&(e.label=e.value),e.selected&&!n.includes(e.value)&&n.push(e.value),e.fulltext=s.r(e),e.selected=e.selected||n.includes(e.value)}),{options:e,newValues:n}},mergeWithUserAdded(e,t,n){return[...t.filter(e=>e?.userAdded&&n.includes(e.value)).filter(t=>!(Array.isArray(e)?e:[]).some(e=>e.value===t.value)),...e]}},_={name:`pkt-combobox`,react:`PktCombobox`,"css-class":`pkt-combobox`,isElement:!0,isPureReact:!0,props:{name:{type:`string`,name:`Navn`,description:`Navn som brukes i skjema ved innsending`,category:`tech`},id:{type:`string`,name:`ID`,description:`Unik ID for feltet`,category:`tech`},label:{type:`string`,name:`Etikett/label`,description:`Tekst som vises over feltet`,category:`contents`},placeholder:{name:`Hint`,description:`Spesifiserer en kort hint som beskriver forventet verdi av feltet.`,type:`string`,category:`contents`,required:!1},multiple:{type:`boolean`,name:`Flervalg`,default:!1,description:`Mulighet for å velge flere valg`,category:`functionality`},tagPlacement:{attribute:`tag-placement`,type:[`inside`,`outside`],name:`Plassering av tags i flervalg`,description:`Plassering av valgte verdier i feltet ved flervalg`,category:`functionality`,showIf:{multiple:!0}},maxlength:{type:`number`,name:`Maks antall i flervalg`,description:`Maks antall valg dersom flervalg er aktivert`,category:`functionality`,showIf:{multiple:!0}},typeahead:{type:`boolean`,name:`Typeahead`,default:!1,description:`Mulighet for automatisk utfylling av feltet fra listen over valg`,category:`functionality`},includeSearch:{attribute:`include-search`,type:`boolean`,name:`Inkluder søk`,description:`Mulighet for å søke etter valg inni dropdown`,category:`functionality`},allowUserInput:{attribute:`allow-user-input`,type:`boolean`,name:`Brukervalgte verdier`,description:`Mulighet for å skrive inn egne verdier`,category:`functionality`},searchPlaceholder:{attribute:`search-placeholder`,type:`string`,name:`Søke-plassholder`,description:`Plassholdertekst for søkefeltet i dropdown`,category:`contents`,showIf:{includeSearch:!0}},displayValueAs:{attribute:`display-value-as`,type:[`label`,`value`,`prefixAndValue`],name:`Visning av valgt verdi`,description:`Hvordan valgt verdi vises i feltet`,default:`label`,category:`ui`},inputSize:{name:`Størrelse`,description:`Visuell størrelse via input-wrapper. small: kompakt wrapper og felt (42px). xsmall: samme wrapper som small, felt 36px.`,attribute:`input-size`,type:[`small`,`medium`,`xsmall`],default:`medium`,category:`ui`},value:{name:`Verdi`,type:`string`,description:`Valgt verdi. Streng ved enkelt valg, array av strenger ved flervalg.`,category:`tech`},helptext:{type:`string`,name:`Hjelpetekst`,description:`Hjelpetekst som vises over feltet`,category:`contents`},helptextDropdown:{attribute:`helptextdropdown`,type:`string`,name:`Utvidet hjelpetekst`,description:`Hjelpetekst som vises i en lukket boks man kan åpne`,category:`contents`},helptextDropdownButton:{attribute:`helptextdropdownbutton`,type:`string`,name:`Knappetekst for hjelpetekst`,description:`Tekst som vises på knappen for å åpne/lukke utvidet hjelpetekst`,category:`contents`,default:`Les mer`},disabled:{type:`boolean`,name:`Deaktivert`,description:`Feltet er deaktivert`,category:`tech`},hasError:{attribute:`haserror`,type:`boolean`,name:`Feil`,description:`Feltet har en feil`,category:`ui`},errorMessage:{attribute:`errormessage`,type:`string`,name:`Feilmelding`,description:`Tekst som vises under feltet ved feil`,category:`contents`},required:{type:`boolean`,name:`Påkrevd`,description:`Feltet må fylles ut`,category:`tech`},requiredTag:{attribute:`requiredtag`,type:`boolean`,name:`Påkrevd-merking`,description:`Viser en merking som indikerer at feltet er påkrevd`,category:`ui`},requiredText:{attribute:`requiredtext`,type:`string`,name:`Påkrevd-tekst`,description:`Tekst som vises i påkrevd-merkingen`,category:`contents`},optionalTag:{attribute:`optionaltag`,type:`boolean`,name:`Valgfritt-merking`,description:`Viser en merking som indikerer at feltet er valgfritt`,category:`ui`},optionalText:{attribute:`optionaltext`,type:`string`,name:`Valgfritt-tekst`,description:`Tekst som vises i valgfritt-merkingen`,category:`contents`},tagText:{attribute:`tagtext`,type:`string`,name:`Tag-tekst`,description:`Tekst som vises i en tag ved siden av label`,category:`ui`},fullwidth:{type:`boolean`,name:`Full bredde`,description:`Skal feltet ta opp hele bredden?`,category:`ui`},defaultOptions:{attribute:`default-options`,name:`Initielle valg (default options)`,description:`Liste over valg som kan velges, om options sendes inn som array med objekter (denne vil ikke modifiseres ved endring innad i komponenten)`,type:`array`,default:[],previewDefault:[{value:`bfr`,label:`Frogner`},{value:`bgo`,label:`Gamle Oslo`},{value:`bgr`,label:`Grorud`},{value:`bxx`,label:`Andre bydeler`}],items:{type:`object`,properties:{value:{type:`string`,description:`Verdi som sendes ved valg`},label:{type:`string`,description:`Tekst som vises for valget`},prefix:{type:`string`,description:`Tekst som vises før valget`},description:{type:`string`,description:`Beskrivelse av valget`},disabled:{type:`boolean`,description:`Valget er deaktivert`},selected:{type:`boolean`,description:`Valget er valgt`},tagSkinColor:{type:[`blue`,`blue-dark`,`blue-light`,`green`,`red`,`yellow`,`beige`,`gray`,`grey`],description:`Farge på tag`}},required:[`value`]},category:`contents`},options:{name:`Valg`,type:`array`,description:`Liste over valg som kan velges, om options sendes inn som array med objekter`,default:[],items:{type:`object`,properties:{value:{type:`string`,description:`Verdi som sendes ved valg`},label:{type:`string`,description:`Tekst som vises for valget`},prefix:{type:`string`,description:`Tekst som vises før valget`},description:{type:`string`,description:`Beskrivelse av valget`},disabled:{type:`boolean`,description:`Valget er deaktivert`},selected:{type:`boolean`,description:`Valget er valgt`},tagSkinColor:{type:[`blue`,`blue-dark`,`blue-light`,`green`,`red`,`yellow`,`beige`,`gray`,`grey`],description:`Farge på tag`}},required:[`value`]},category:`contents`},inline:{name:`Inline`,type:`boolean`,required:!1,default:!1,description:`Angir om feltet skal flyte med teksten`,category:`ui`},useWrapper:{attribute:`usewrapper`,name:`Bruk wrapper`,type:`boolean`,required:!1,displayAsFalse:!0,default:!0,description:`Indikerer om skjemaelementet skal bruke en wrapper`,category:`ui`},hasFieldset:{attribute:`hasfieldset`,name:`Bruk fieldset`,type:`boolean`,required:!1,default:null,description:`Bruk fieldset og legend i stedet for label. Utledes automatisk når feltet ikke har en input.`,category:`ui`},counter:{name:`Teller`,type:`boolean`,required:!1,default:null,description:`Viser teller under feltet. Slås på av seg selv når det finnes en grense å telle mot; sett til false for å skru den av.`,category:`ui`},defaultValue:{attribute:`defaultvalue`,type:`string | string[]`,name:`Standardverdi`,description:`Verdien feltet får ved oppstart og ved nullstilling av skjemaet`,category:`functionality`}},events:{change:{type:`Event`,description:`Returnerer valgt verdi som streng. Ved flervalg returneres kommaseparerte verdier.`},"value-change":{type:`CustomEvent`,description:`Returnerer valgt verdi. Ved enkeltvalg en streng, ved flervalg en <code>string[]</code>.`},search:{type:`CustomEvent`,description:`Returnerer søketeksten som streng i <code>event.detail</code> når brukeren skriver i søkefeltet`},toggleHelpText:{type:`CustomEvent`,description:`Returnerer <code>event.detail { isOpen: true }</code> eller <code>event.detail { isOpen: false }</code> når hjelpeteksten åpnes eller lukkes`}}},v=class extends c.t{constructor(){super(),this.value=``,this.options=[],this.defaultOptions=[],this.allowUserInput=!1,this.typeahead=!1,this.includeSearch=!1,this.searchPlaceholder=null,this.multiple=!1,this.maxlength=null,this.displayValueAs=_.props.displayValueAs.default,this.tagPlacement=null,this.isOpen=!1,this._options=[],this._value=[],this._isOptionsOpen=!1,this._userInfoMessage=``,this._messageValue=null,this._addValueText=null,this._maxIsReached=!1,this._search=``,this._inputFocus=!1,this._skipInputTab=!1,this._optionsFromSlot=!1,this._lastSlotGeneration=0,this._suppressNextOpen=!1,this.inputRef=a.t(),this.triggerRef=a.t(),this.listboxRef=a.t(),this._pendingDispatchFrom=null,this.optionsController=new l.t(this)}get _hasTextInput(){return this.typeahead||this.allowUserInput}get _selectionDescription(){if(!(!this.multiple||this._value.length===0))return`${this._value.length} valgt`}focusTrigger(){this._hasTextInput?this.inputRef.value?.focus():this.triggerRef.value?.focus()}focusAfterCommit(){this._skipInputTab=!0;let e=this.inputRef.value;e&&e.type!==`hidden`&&e.setAttribute(`tabindex`,`-1`),this.triggerRef.value?.focus()}restoreInputTab(){this._skipInputTab=!1}parseValue(){return this.parseToValues(this.value)}parseToValues(e){return Array.isArray(e)?this.multiple?e:e.length>0?[e[0]]:[]:e&&this.multiple?e.split(`,`):e?[e]:[]}updateMaxReached(){this._maxIsReached=s.l(this._value.length,this.maxlength)}syncPublicValue(){let e=this.multiple?this._value.join(`,`):this._value[0]||``;e!==(Array.isArray(this.value)?this.value.join(`,`):String(this.value||``))&&(this.value=e)}dispatchValueChange(e){let t=this._value;if(e?.join(`,`)!==t.join(`,`)){let e=this.multiple?[...t]:t[0]||``;this.onChange(e)}else t.length===0&&e&&e.length>0&&this.clearInputValue()}onChange(e){this.touched=!0,super.onChange(e)}valueChanged(){}};e.n([e.u({type:String,reflect:!0})],v.prototype,`value`,void 0),e.n([e.u({type:Array})],v.prototype,`options`,void 0),e.n([e.u({type:Array,attribute:`default-options`})],v.prototype,`defaultOptions`,void 0),e.n([e.u({type:Boolean,attribute:`allow-user-input`})],v.prototype,`allowUserInput`,void 0),e.n([e.u({type:Boolean})],v.prototype,`typeahead`,void 0),e.n([e.u({type:Boolean,attribute:`include-search`})],v.prototype,`includeSearch`,void 0),e.n([e.u({type:String,attribute:`search-placeholder`})],v.prototype,`searchPlaceholder`,void 0),e.n([e.u({type:Boolean})],v.prototype,`multiple`,void 0),e.n([e.u({type:Number})],v.prototype,`maxlength`,void 0),e.n([e.u({type:String,attribute:`display-value-as`})],v.prototype,`displayValueAs`,void 0),e.n([e.u({type:String,attribute:`tag-placement`})],v.prototype,`tagPlacement`,void 0),e.n([e.u({type:Boolean,attribute:`open`})],v.prototype,`isOpen`,void 0),e.n([e.l()],v.prototype,`_options`,void 0),e.n([e.l()],v.prototype,`_value`,void 0),e.n([e.l()],v.prototype,`_isOptionsOpen`,void 0),e.n([e.l()],v.prototype,`_userInfoMessage`,void 0),e.n([e.l()],v.prototype,`_messageValue`,void 0),e.n([e.l()],v.prototype,`_addValueText`,void 0),e.n([e.l()],v.prototype,`_maxIsReached`,void 0),e.n([e.l()],v.prototype,`_search`,void 0),e.n([e.l()],v.prototype,`_inputFocus`,void 0),e.n([e.l()],v.prototype,`_skipInputTab`,void 0);var y=class extends v{toggleValue(e){if(this.disabled)return;this.touched=!0,this._userInfoMessage=``,this._addValueText=null;let t=s.i(this.options,e)?.value||null,n=this._value.includes(e||t||``),r=!!t,i=this._options.find(t=>t.value===e)?.disabled||!1,a=!e?.trim(),o=!this.multiple,c=this.multiple,l=s.l(this._value.length,this.maxlength),u=!1,d=!0,f=``,m=null,h=``;i||(!r&&this.allowUserInput&&!a?(this.addNewUserValue(e),f=`valueAdded`,u=c):!r&&!this.allowUserInput?(o&&this._value[0]&&this.removeValue(this._value[0]),d=!1,u=!0,f=`noResults`):n?(this.removeValue(t),u=!0,o&&this._hasTextInput&&this.inputRef.value&&this.inputRef.value.type!==`hidden`&&(this.inputRef.value.value=``)):a&&o?(this.removeAllSelected(),u=!0):o?(this._value[0]&&this.removeSelected(this._value[0]),this.setSelected(t),u=!1,f=`valueSelected`,m=this._hasTextInput?p(t||``,this.options,this.displayValueAs):s.s(s.i(this.options,t),this.displayValueAs)):c&&!l?(this.setSelected(t),u=!0):c&&l?(f=`maxSelected`,d=!1,h=e):(o&&this.removeAllSelected(),f=`noValidValue`,d=!1,u=!0,h=e),this._isOptionsOpen=u,u||window.setTimeout(()=>{this.focusAfterCommit()},0),this._search=h||``,this.resetComboboxInput(d),this._userInfoMessage=f,this._messageValue=m,c&&this.updateMaxReached())}setSelected(e){if(!this._value.includes(e)){if(this.multiple&&s.l(this._value.length,this.maxlength)){this._userInfoMessage=`maxSelected`;return}!this.multiple&&this.removeAllSelected(),this._value=e?[...this._value,e]:this._value,m.markOptionSelected(this._options,e),this.resetComboboxInput(!0)}}removeSelected(e){if(!e)return;this._value=this._value.filter(t=>t!==e);let t=s.i(this.options,e);t&&(m.markOptionDeselected(this.options,e),t.userAdded?(this._options=[...this._options.filter(t=>t.value!==e)],this.options=[...this.options.filter(t=>t.value!==e)]):this._options.some(t=>t.value===e)||(this._options=[...this._options,t]))}addAllOptions(){if(this.multiple){if(this.maxlength&&this._options.length>this.maxlength){this._userInfoMessage=`tooManySelected`;return}this._value=this._options.map(e=>e.value),m.markAllSelected(this._options),this.requestUpdate()}}removeAllSelected(){this._value=[],m.markAllDeselected(this._options),this._options=m.removeUserAddedOptions(this._options),this.requestUpdate()}addValue(){let e=this.inputRef.value?.value.trim()||``;if(this._search=e,e&&this._value.includes(e)){this.resetComboboxInput(!0),this._userInfoMessage=`alreadySelected`;return}this.toggleValue(e)}removeValue(e){this._value=this.multiple?this._value.filter(t=>t!==e):[],this.removeSelected(e)}addNewUserValue(e){if(!e||e.trim()===``)return;if(!this.multiple)this._value[0]&&this.removeSelected(this._value[0]),this._value=[e];else if(!s.i(this.options,e)){if(s.l(this._value.length,this.maxlength))return;this._value=[...this._value,e]}let t={value:e,label:e,userAdded:!0,selected:!0};this.options=[t,...this.options],this._options=[t,...this._options],this.resetComboboxInput(!0),this.multiple||(this._isOptionsOpen=!1,window.setTimeout(()=>{this.focusAfterCommit()},0)),this.requestUpdate()}refreshOptionsFromValue(){let e=g.cloneOptions(this.options);e.forEach(e=>e.selected=this._value.includes(e.value)),this._options=g.syncOptionsWithValues(e,this._value).options}resetComboboxInput(e=!0){this._addValueText=null,this.inputRef.value&&this.inputRef.value.type!==`hidden`&&e&&(this._search=``,this.multiple?this.inputRef.value.value=``:(this.inputRef.value.value=this._value[0]?p(this._value[0],this.options,this.displayValueAs):``,this._userInfoMessage=``)),this.refreshOptionsFromValue()}removeLastValue(e){if(this._value.length===0)return;e.preventDefault();let t=this._value[this._value.length-1];t&&this.removeSelected(t),this.updateMaxReached()}},b=class extends y{handleInput(e){if(e.stopPropagation(),e.stopImmediatePropagation(),this.disabled)return;this.touched=!0;let t=e.target;if(this._search=t.value,this.checkForMatches(),this.typeahead){if(this._search){let{filtered:n,suggestion:r}=s.o(this.options,this._search);this._options=n,e.inputType!==`deleteContentBackward`&&r?.label&&this.inputRef.value&&this.inputRef.value.type!==`hidden`&&(t.value=r.label,window.setTimeout(()=>t.setSelectionRange(this._search.length,t.value.length),0),t.selectionDirection=`backward`)}else this.refreshOptionsFromValue()}}handleFocus(){if(!this.disabled){if(this._skipInputTab=!1,this._suppressNextOpen){this._suppressNextOpen=!1,this._inputFocus=!0,this.requestUpdate();return}!this.multiple&&this._value[0]&&this.inputRef.value&&this.inputRef.value.type!==`hidden`&&(this.inputRef.value.value=p(this._value[0],this.options,this.displayValueAs)),this._inputFocus=!0,this._search=``,this.refreshOptionsFromValue(),this._isOptionsOpen=!0,this.onFocus(),this.requestUpdate()}}handleCloseOptions(){this._isOptionsOpen=!1,this._hasTextInput&&(this._suppressNextOpen=!0),this.focusTrigger()}handleFocusOut(e){if(this.disabled||!this._isOptionsOpen)return;let t=e.relatedTarget;t?.closest(`pkt-combobox`)?.id===this.id||e.target?.classList?.contains(`pkt-combobox__value`)||t===this.inputRef.value||t===this.triggerRef.value||this.closeAndProcessInput()}closeAndProcessInput(){if(this._inputFocus=!1,this._addValueText=null,this._userInfoMessage=``,this._search=``,this.inputRef.value&&this.inputRef.value.type!==`hidden`){let e=this.inputRef.value.value;if(!this.multiple){if(!e)this._value[0]&&this.removeSelected(this._value[0]);else{let t=s.i(this.options,e);t&&t.value!==this._value[0]?(this._value[0]&&this.removeSelected(this._value[0]),this.setSelected(t.value)):!t&&this.allowUserInput&&(this._value[0]&&this.removeSelected(this._value[0]),this.addNewUserValue(e))}}else if(e!==``){let{action:t,value:n}=d(e,this._value,this.options,this.allowUserInput,this.multiple);switch(t){case`addUserValue`:this.addNewUserValue(n);break;case`selectOption`:this.setSelected(n);break;case`removeValue`:this.removeValue(n)}}!this.multiple&&this._value[0]?this.inputRef.value.value=p(this._value[0],this.options,this.displayValueAs):this.inputRef.value.value=``}this._isOptionsOpen=!1,this.onBlur()}handleBlur(){this._inputFocus=!1,this.onBlur()}handleInputClick(e){if(this.disabled){e.preventDefault(),e.stopImmediatePropagation();return}this._hasTextInput?(this.inputRef.value?.focus(),this.requestUpdate()):(e.stopImmediatePropagation(),e.preventDefault(),this._isOptionsOpen=!this._isOptionsOpen,this._isOptionsOpen&&this.listboxRef.value?.focusFirstOrSelectedOption())}handlePlaceholderClick(e){this.disabled||(e.stopPropagation(),this._hasTextInput&&this.inputRef.value?(this.inputRef.value.focus(),this._inputFocus=!0,this.requestUpdate()):(this._isOptionsOpen=!this._isOptionsOpen,this.requestUpdate()))}handleSelectOnlyKeydown(e){if(!this.disabled)switch(e.key){case`Enter`:case` `:case`ArrowDown`:case`ArrowUp`:e.preventDefault(),this._isOptionsOpen?this._isOptionsOpen=!1:(this._isOptionsOpen=!0,this.listboxRef.value?.focusFirstOrSelectedOption());break;case`Escape`:this._isOptionsOpen&&=(e.preventDefault(),!1);break;case`Home`:case`End`:e.preventDefault(),this._isOptionsOpen||=!0,this.listboxRef.value?.focusFirstOrSelectedOption();break;case`ArrowLeft`:this.multiple&&this._value.length>0&&(e.preventDefault(),this.focusTag(this._value.length-1));break;case`Backspace`:case`Delete`:this.multiple&&this._value.length>0&&(e.preventDefault(),this.removeSelected(this._value[this._value.length-1]))}}handleOptionToggled(e){this.toggleValue(e.detail)}handleSearch(e){e.stopPropagation(),this._search=e.detail.toLowerCase(),this.checkForMatches()}handleInputKeydown(e){if(e.key===`Backspace`){let t=!this.inputRef.value?.value;!this._search&&t&&this.multiple&&this._value.length>0&&this.removeLastValue(e);return}if(e.key===`ArrowLeft`&&this.multiple&&this._value.length>0){let t=this.inputRef.value;if(t&&t.selectionStart===0&&!t.value){e.preventDefault(),this.focusTag(this._value.length-1);return}}let t=u(e.key,e.shiftKey,this.multiple);if(t&&!(e.key===`Tab`&&!this._isOptionsOpen)){if(t===`focusListbox`&&e.key===`Tab`&&!this.listboxRef.value?.querySelector(`[role="option"]:not([data-disabled]), [data-type="new-option"]`)){this.closeAndProcessInput();return}switch(e.preventDefault(),t){case`addValue`:this.addValue();break;case`focusListbox`:this.listboxRef.value?.focusFirstOrSelectedOption();break;case`closeOptions`:this._isOptionsOpen=!1}}}handleTagRemove(e){this.removeSelected(e),this._hasTextInput&&this.inputRef.value&&(this._inputFocus=!0,this.inputRef.value.focus(),this.requestUpdate())}getInsideTags(){return Array.from(this.querySelectorAll(`.pkt-combobox__input .pkt-combobox__tag-list pkt-tag`))}focusTag(e){let t=this.getInsideTags();t.forEach((t,n)=>{t.buttonTabindex=n===e?0:-1}),(t[e]?.querySelector(`button`))?.focus()}resetTagTabindices(){this.getInsideTags().forEach(e=>{e.buttonTabindex=-1})}handleTagKeydown(e,t){e.stopPropagation();let n=()=>{this.resetTagTabindices(),this._hasTextInput&&this.inputRef.value?this.inputRef.value.focus():this.triggerRef.value?.focus()};switch(e.key){case`ArrowLeft`:e.preventDefault(),t>0&&this.focusTag(t-1);break;case`ArrowRight`:e.preventDefault(),t<this._value.length-1?this.focusTag(t+1):n();break;case`Backspace`:case`Delete`:e.preventDefault();{let e=this._value[t],r=t>=this._value.length-1?t-1:t;this.removeSelected(e),r>=0?(this.requestUpdate(),this.updateComplete.then(()=>this.focusTag(r))):n()}break;case`Tab`:this.resetTagTabindices();break;case`Escape`:e.preventDefault(),n()}}checkForMatches(){let e=f(this.inputRef.value?.value||this._search||``,this._value,this.options,this.allowUserInput,this.multiple);if(e.shouldRemoveValue&&this.removeValue(this._value[0]),e.shouldResetInput){this.resetComboboxInput(!1);return}this._addValueText=e.addValueText,this._userInfoMessage=e.userInfoMessage}},x=class extends b{constructor(...e){super(...e),this.handleBodyClick=e=>{this._isOptionsOpen&&!this.contains(e.target)&&this.closeAndProcessInput()}}connectedCallback(){if(super.connectedCallback(),document?.body.addEventListener(`click`,this.handleBodyClick),this._options=[],this.defaultOptions&&this.defaultOptions.length){let e=this.options?.filter(e=>e.userAdded)||[];this.options=[...e,...JSON.parse(JSON.stringify(this.defaultOptions))],this._options=g.cloneOptions(this.options)}if(this.optionsController?.nodes&&this.optionsController.nodes.length){let e=h.parseOptionsFromSlot(this.optionsController.nodes);e.length&&(this.options=[...e],this._options=[...e],this._optionsFromSlot=!0,this._lastSlotGeneration=this.optionsController.generation)}}disconnectedCallback(){super.disconnectedCallback(),document?.body.removeEventListener(`click`,this.handleBodyClick)}firstUpdated(e){this.defaultValue!==null&&!this.value&&(this.value=this.defaultValue),super.firstUpdated(e)}willUpdate(e){if(this._optionsFromSlot&&this.optionsController){let e=this.optionsController.generation;if(e!==this._lastSlotGeneration){this._lastSlotGeneration=e;let t=h.parseOptionsFromSlot(this.optionsController.nodes),n=this._options.filter(e=>e.userAdded);this.options=[...n,...t]}}if(super.willUpdate(e),e.has(`isOpen`)&&(this._isOptionsOpen=this.isOpen),e.has(`defaultOptions`)&&this.defaultOptions.length){let e=(Array.isArray(this.options)?this.options:[]).filter(e=>e.userAdded)||[];this.options=[...e,...JSON.parse(JSON.stringify(this.defaultOptions))],this._options=g.cloneOptions(this.options)}let t=e.has(`value`),n=e.has(`_value`);if(t){let e=[...this._value],t=this.parseValue();t.join(`,`)!==this._value.join(`,`)&&(this._value=t,this._options.forEach(e=>e.selected=t.includes(e.value)),this._options=[...this._options]),this._pendingDispatchFrom??=e}else n&&(this._pendingDispatchFrom??=e.get(`_value`)??[]);if(e.has(`defaultValue`)&&this.defaultValue!=null&&!this._value.length){let e=this.parseToValues(this.defaultValue);e.length&&(this._pendingDispatchFrom??=[...this._value],this._value=e,this._options.forEach(t=>t.selected=e.includes(t.value)),this._options=[...this._options])}if(e.has(`options`)){let t=e.get(`options`)||this._options||[],n=g.mergeWithUserAdded(g.cloneOptions(this.options),t,this._value);this._options=n,n.length>this.options.length&&(this.options=n);let r=g.syncOptionsWithValues(this._options,this._value);this._options=r.options,r.newValues.length>this._value.length&&(this._pendingDispatchFrom??=[...this._value],this._value=r.newValues)}(t||n||e.has(`options`)||e.has(`defaultValue`))&&this.updateMaxReached(),this._pendingDispatchFrom&&this.syncPublicValue()}updated(e){if(this._pendingDispatchFrom){let e=this._pendingDispatchFrom;this._pendingDispatchFrom=null,this.dispatchValueChange(e)}if(e.has(`_search`)&&this.dispatchEvent(new CustomEvent(`search`,{detail:this._search,bubbles:!1})),!this._isOptionsOpen&&this._hasTextInput&&this.inputRef.value&&this.inputRef.value.type!==`hidden`){let e=!this.multiple&&this._value[0]?p(this._value[0],this.options,this.displayValueAs):``;this.inputRef.value.value!==e&&(this.inputRef.value.value=e)}this.classList.add(`pkt-combobox-component`),this.classList.toggle(`pkt-combobox-component--fullwidth`,!!this.fullwidth),super.updated(e)}formResetCallback(){this.touched=!1;let e=this.defaultValue||(this.multiple,``);this.value=e,this._value=this.parseValue(),this._options=this._options.filter(e=>!e.userAdded).map(e=>({...e,selected:this._value.includes(e.value)})),this.options=this.options.filter(e=>!e.userAdded).map(e=>({...e,selected:this._value.includes(e.value)})),this._search=``,this._isOptionsOpen=!1,this._userInfoMessage=``,this._addValueText=null,this._inputFocus=!1,this.updateMaxReached(),this.inputRef.value&&this.inputRef.value.type!==`hidden`&&(this.inputRef.value.value=``),this.internals.setFormValue(``),this.internals.ariaInvalid=`false`,this.requestUpdate()}attributeChangedCallback(e,t,n){if(e===`options`){this._options=g.cloneOptions(this.options);let e=g.syncOptionsWithValues(this._options,this._value);this._options=e.options,e.newValues.length>this._value.length&&(this._value=e.newValues),this._search=``}super.attributeChangedCallback(e,t,n)}render(){return e._`
2
- <pkt-input-wrapper
3
- .strings=${this.strings}
4
- .size=${this.inputSize}
5
- .label=${this.label}
6
- .helptext=${this.helptext}
7
- .helptextDropdown=${n.t(this.helptextDropdown)}
8
- .helptextDropdownButton=${n.t(this.helptextDropdownButton)}
9
- ?fullwidth=${this.fullwidth}
10
- ?counter=${this.effectiveCounter(!!this.multiple&&this.maxlength!=null)}
11
- .counterCurrent=${this._value.length}
12
- .counterMaxLength=${this.maxlength??0}
13
- ?hasError=${this.hasError}
14
- ?inline=${this.inline}
15
- ?disabled=${this.disabled}
16
- .errorMessage=${this.errorMessage}
17
- ?optionalTag=${this.optionalTag}
18
- .optionalText=${this.optionalText}
19
- ?requiredTag=${this.requiredTag}
20
- .requiredText=${this.requiredText}
21
- .tagText=${this.tagText}
22
- useWrapper=${this.useWrapper}
23
- .forId=${this._hasTextInput?this.id+`-input`:this.id+`-combobox`}
24
- ?hasFieldset=${this.effectiveHasFieldset(!this._hasTextInput)}
25
- class="pkt-combobox__wrapper"
26
- @labelClick=${this.handleInputClick}
27
- >
28
- <div class="pkt-contents" slot="helptext">${i.r(this,`helptext`)}</div>
29
- <div class="pkt-combobox" @focusout=${this.handleFocusOut}>
30
- <div
31
- class=${t.t({"pkt-combobox__input":!0,[`pkt-combobox__input--${this.inputSize}`]:!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})}
32
- id=${n.t(this._hasTextInput?void 0:`${this.id}-combobox`)}
33
- role=${n.t(this._hasTextInput?void 0:`combobox`)}
34
- aria-expanded=${n.t(this._hasTextInput?void 0:this._isOptionsOpen?`true`:`false`)}
35
- aria-controls=${n.t(this._hasTextInput?void 0:`${this.id}-listbox`)}
36
- aria-haspopup=${n.t(this._hasTextInput?void 0:`listbox`)}
37
- aria-labelledby=${n.t(this._hasTextInput?void 0:`${this.id}-combobox-label`)}
38
- aria-activedescendant=${n.t(!this._hasTextInput&&this._isOptionsOpen&&this._value[0]&&s.i(this.options,this._value[0])?`${this.id}-listbox-${s.a(this._options,this._value[0])}`:void 0)}
39
- aria-description=${n.t(this._selectionDescription||void 0)}
40
- tabindex=${this._hasTextInput||this.disabled?`-1`:`0`}
41
- @click=${this.handleInputClick}
42
- @keydown=${this._hasTextInput?e.h:this.handleSelectOnlyKeydown}
43
- @blur=${this.restoreInputTab}
44
- ${a.n(this.triggerRef)}
45
- >
46
- ${!this._hasTextInput&&this.placeholder&&(!this._value.length||this.multiple&&this.tagPlacement==`outside`)&&!this._inputFocus?e._`<span class="pkt-combobox__placeholder" @click=${this.handlePlaceholderClick}
47
- >${this.placeholder}</span
48
- >`:this.tagPlacement===`outside`?e.h:this.renderSingleOrMultipleValues()}
49
- ${this.renderInputField()}
50
- <pkt-icon
51
- class=${t.t({"pkt-combobox__arrow-icon":!0,"pkt-combobox__arrow-icon--open":this._isOptionsOpen})}
52
- name="chevron-thin-down"
53
- aria-hidden="true"
54
- ></pkt-icon>
55
- </div>
56
-
57
- <pkt-listbox
58
- id="${this.id}-listbox"
59
- .options=${this._options}
60
- .isOpen=${this._isOptionsOpen}
61
- .searchPlaceholder=${this.searchPlaceholder}
62
- .label="Liste: ${this.label||``}"
63
- ?disabled=${this.disabled}
64
- ?include-search=${this.includeSearch}
65
- ?is-multi-select=${this.multiple}
66
- ?allow-user-input=${this.allowUserInput&&!this._maxIsReached}
67
- ?max-is-reached=${this._maxIsReached}
68
- .customUserInput=${n.t(this._addValueText)}
69
- .userMessage=${this._userInfoMessage?r.t(this.pktStrings.get(`combobox`)[this._userInfoMessage],{value:this._messageValue??``}):``}
70
- @search=${this.handleSearch}
71
- @option-toggle=${this.handleOptionToggled}
72
- @select-all=${this.addAllOptions}
73
- @close-options=${this.handleCloseOptions}
74
- @tab-close=${()=>this.closeAndProcessInput()}
75
- .searchValue=${this._search||null}
76
- .maxLength=${this.maxlength||0}
77
- ${a.n(this.listboxRef)}
78
- ></pkt-listbox>
79
- </div>
80
-
81
- ${this.tagPlacement===`outside`&&this.multiple?e._`<div class="pkt-combobox__tags-outside">
82
- ${this.renderSingleOrMultipleValues()}
83
- </div>`:e.h}
84
- </pkt-input-wrapper>
85
- `}renderInputField(){return this.typeahead||this.allowUserInput?e._`
86
- <div class="pkt-combobox__input-div combobox__input">
87
- <input
88
- type="text"
89
- id="${this.id}-input"
90
- name=${(this.name||this.id)+`-input`}
91
- placeholder=${n.t(!this._value.length||this.multiple&&this.tagPlacement===`outside`?this.placeholder:void 0)}
92
- @input=${this.handleInput}
93
- @change=${e=>{e.stopPropagation(),e.stopImmediatePropagation()}}
94
- tabindex=${n.t(this._skipInputTab?`-1`:void 0)}
95
- @keydown=${this.handleInputKeydown}
96
- @focus=${this.handleFocus}
97
- @blur=${this.handleBlur}
98
- autocomplete="off"
99
- role="combobox"
100
- aria-expanded=${this._isOptionsOpen?`true`:`false`}
101
- aria-label=${n.t(this.label)}
102
- aria-autocomplete=${this.typeahead?`both`:this.allowUserInput?`list`:`none`}
103
- aria-controls="${this.id}-listbox"
104
- aria-activedescendant=${n.t(this._isOptionsOpen&&this._value[0]&&s.i(this.options,this._value[0])?`${this.id}-listbox-${s.a(this._options,this._value[0])}`:void 0)}
105
- aria-description=${n.t(this._selectionDescription||void 0)}
106
- ${a.n(this.inputRef)}
107
- />
108
- </div>
109
- `:e._`
110
- <input
111
- type="hidden"
112
- id="${this.id}-input"
113
- name=${(this.name||this.id)+`-input`}
114
- .value=${this._value.join(`,`)}
115
- ${a.n(this.inputRef)}
116
- />
117
- `}renderSingleOrMultipleValues(){if(!this.multiple&&this._hasTextInput)return e.h;let t=!this.multiple,n=this.renderValueTag(s.i(this.options,this._value[0])),r=this.tagPlacement===`outside`,i=e._`
118
- <ul role="list" class="pkt-combobox__tag-list">
119
- ${o.t(this._value,e=>e,(t,n)=>{let i=s.i(this.options,t),a=i?.tagSkinColor;return e._`
120
- <li
121
- role="listitem"
122
- @click=${r?e.h:e=>e.stopPropagation()}
123
- @mousedown=${r?e.h:e=>e.preventDefault()}
124
- >
125
- <pkt-tag
126
- skin=${a||`blue-dark`}
127
- ?closeTag=${!this.disabled}
128
- .buttonTabindex=${r?void 0:-1}
129
- @close=${()=>this.handleTagRemove(t)}
130
- @keydown=${r?e.h:e=>this.handleTagKeydown(e,n)}
131
- >
132
- ${this.renderValueTag(i)}
133
- </pkt-tag>
134
- </li>
135
- `})}
136
- </ul>
137
- `;return!t&&this._value.length===0?e.h:t?n:i}renderValueTag(t){if(!t)return``;switch(this.displayValueAs){case`prefixAndValue`:return e._`<span class="pkt-combobox__value">${t.prefix||``} ${t.value}</span>`;case`value`:return e._`<span class="pkt-combobox__value">${t.value}</span>`;default:return e._`<span class="pkt-combobox__value">${t.label||t.value}</span>`}}};try{e.d(`pkt-combobox`)(x)}catch{console.warn(`Forsøker å definere <pkt-combobox>, men den er allerede definert`)}var S=x;Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return S}});