@oslokommune/punkt-elements 18.9.3 → 18.9.5
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 +17 -0
- package/dist/combobox-CFgPKb3j.cjs +139 -0
- package/dist/{combobox-fzSaCPok.js → combobox-Cei828v1.js} +56 -47
- package/dist/components/combobox/combobox.d.ts +1 -0
- package/dist/components/helptext/helptext-association.test.d.ts +0 -0
- package/dist/components/timepicker/timepicker.d.ts +1 -0
- package/dist/{fileupload-Y4bDkaD9.cjs → fileupload-2nliUg_z.cjs} +2 -2
- package/dist/{fileupload-C5lxuood.js → fileupload-BpkvNlxN.js} +3 -3
- package/dist/pkt-combobox.cjs +1 -1
- package/dist/pkt-combobox.js +1 -1
- package/dist/pkt-fileupload.cjs +1 -1
- package/dist/pkt-fileupload.js +1 -1
- package/dist/pkt-index.cjs +1 -1
- package/dist/pkt-index.js +3 -3
- package/dist/pkt-timepicker.cjs +1 -1
- package/dist/pkt-timepicker.js +1 -1
- package/dist/timepicker-CAD2AYFr.cjs +198 -0
- package/dist/{timepicker--CrfIU_7.js → timepicker-D9liFW1z.js} +29 -20
- package/package.json +2 -2
- package/src/components/combobox/combobox.ts +12 -0
- package/src/components/fileupload/fileupload.ts +1 -3
- package/src/components/helptext/helptext-association.test.ts +108 -0
- package/src/components/timepicker/timepicker.ts +11 -0
- package/dist/combobox-B9Qo7hbt.cjs +0 -137
- package/dist/timepicker-auQ5Y6Et.cjs +0 -196
|
@@ -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-PN5nWd1A.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`},form:{name:`Skjema`,description:`ID-en til skjemaet feltet hører til, når feltet ligger utenfor skjemaet`,type:`string`,required:!1,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}});
|
|
@@ -1,196 +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"),o=require("./input-element-PN5nWd1A.cjs");require("./input-wrapper-D64Qn-QH.cjs");var s=e=>/^\d{2}:\d{2}$/.test(e)&&parseInt(e.slice(0,2),10)<=23&&parseInt(e.slice(3),10)<=59,c=e=>{let[t,n]=e.split(`:`).map(Number);return t*60+n},l=e=>e?Math.max(1,Math.round(e/60)):1,u=(e,t)=>{let n=e?parseInt(String(e).split(`:`)[0],10):0,r=t?parseInt(String(t).split(`:`)[0],10):23;return Array.from({length:r-n+1},(e,t)=>t+n)},d=e=>{let t=l(e);return Array.from({length:Math.floor(60/t)},(e,n)=>n*t)},f=(e,t,n,r)=>{let i=e===``?n===1?0:23:parseInt(e,10),a=t===``?n===1?0:Math.floor(59/r)*r:parseInt(t,10);return a+=n*r,a>59?(a=0,i=(i+1)%24):a<0&&(a=Math.floor(59/r)*r,i=(i-1+24)%24),{hours:String(i).padStart(2,`0`),minutes:String(a).padStart(2,`0`)}},p=class extends o.t{constructor(...e){super(...e),this.hiddenInputRef=a.t(),this.hoursInputRef=a.t(),this.minutesInputRef=a.t(),this.buttonRef=a.t(),this.value=``,this.hidePicker=!1,this.stepArrows=!1,this._hours=``,this._minutes=``,this._isOpen=!1,this._hoursDigitCount=0,this._hoursFirstDigit=-1,this._minutesDigitCount=0,this._minutesFirstDigit=-1,this._hasFocus=!1,this._outsideClickHandler=e=>{this.contains(e.target)||this._closePopup()},this._handleComponentFocusIn=()=>{this._hasFocus||(this._hasFocus=!0,this.onFocus())},this._handleComponentFocusOut=e=>{this.contains(e.relatedTarget)||(this._hasFocus=!1,this.onBlur())},this._handleHoursKeydown=e=>{let t=e.target;switch(e.key){case`ArrowUp`:{e.preventDefault();let t=this._hours===``?0:parseInt(this._hours,10);this._hours=String((t+1)%24).padStart(2,`0`),this._syncValueFromDisplay(),this.onInput();break}case`ArrowDown`:{e.preventDefault();let t=this._hours===``?0:parseInt(this._hours,10);this._hours=String((t-1+24)%24).padStart(2,`0`),this._syncValueFromDisplay(),this.onInput();break}case`ArrowRight`:e.preventDefault(),this.minutesInputRef.value?.focus();break;case`Backspace`:case`Delete`:this._hoursDigitCount=0,this._hoursFirstDigit=-1;break;case`Tab`:break;case`Enter`:{e.preventDefault();let n=this.internals.form;n?n.requestSubmit():t.blur();break}default:if(/^\d$/.test(e.key)){e.preventDefault();let t=parseInt(e.key,10);if(this._hoursDigitCount===0)this._hoursFirstDigit=t,this._hours=String(t).padStart(2,`0`),this._hoursDigitCount=1,this.onInput(),t>=3&&(this._hoursFirstDigit=-1,this._hoursDigitCount=0,this._syncValueFromDisplay(),this.minutesInputRef.value?.focus());else{let e=this._hoursFirstDigit*10+t;this._hours=e<=23?String(e).padStart(2,`0`):String(t).padStart(2,`0`),this._hoursFirstDigit=-1,this._hoursDigitCount=0,this._syncValueFromDisplay(),this.onInput(),this.minutesInputRef.value?.focus()}}else e.preventDefault()}},this._handleHoursBlur=()=>{this._hours!==``&&(this._hours=String(parseInt(this._hours,10)).padStart(2,`0`)),this._hoursDigitCount=0,this._hoursFirstDigit=-1,this._syncValueFromDisplay()},this._handleMinutesKeydown=e=>{let t=e.target;switch(e.key){case`ArrowUp`:{e.preventDefault();let t=this._minutes===``?0:parseInt(this._minutes,10);this._minutes=String((t+this._minuteStep)%60).padStart(2,`0`),this._syncValueFromDisplay(),this.onInput();break}case`ArrowDown`:{e.preventDefault();let t=this._minutes===``?0:parseInt(this._minutes,10);this._minutes=String((t-this._minuteStep+60)%60).padStart(2,`0`),this._syncValueFromDisplay(),this.onInput();break}case`ArrowLeft`:e.preventDefault(),this.hoursInputRef.value?.focus();break;case`Backspace`:case`Delete`:this._minutesDigitCount=0,this._minutesFirstDigit=-1;break;case`Tab`:break;case`Enter`:{e.preventDefault();let n=this.internals.form;n?n.requestSubmit():t.blur();break}default:if(/^\d$/.test(e.key)){e.preventDefault();let t=parseInt(e.key,10);if(this._minutesDigitCount===0)this._minutesFirstDigit=t,this._minutes=String(t).padStart(2,`0`),this._minutesDigitCount=1,this.onInput(),t>=6&&(this._minutesFirstDigit=-1,this._minutesDigitCount=0,this._syncValueFromDisplay());else{let e=this._minutesFirstDigit*10+t;this._minutes=e<=59?String(e).padStart(2,`0`):String(t).padStart(2,`0`),this._minutesFirstDigit=-1,this._minutesDigitCount=0,this._syncValueFromDisplay(),this.onInput()}}else e.preventDefault()}},this._handleMinutesBlur=()=>{this._minutes!==``&&(this._minutes=String(parseInt(this._minutes,10)).padStart(2,`0`)),this._minutesDigitCount=0,this._minutesFirstDigit=-1,this._syncValueFromDisplay()},this._handlePopupKeydown=e=>{let t=document.activeElement,n=t.closest(`.pkt-timepicker-popup__col`);if(!n)return;let r=Array.from(n.querySelectorAll(`.pkt-timepicker-popup__option`)),i=r.indexOf(t),a=t.dataset.type??``;switch(e.key){case`ArrowDown`:e.preventDefault(),this._focusOptionAndSync(r[Math.min(i+1,r.length-1)],a);break;case`ArrowUp`:e.preventDefault(),this._focusOptionAndSync(r[Math.max(i-1,0)],a);break;case`Home`:e.preventDefault(),this._focusOptionAndSync(r[0],a);break;case`End`:e.preventDefault(),this._focusOptionAndSync(r[r.length-1],a);break;case`ArrowRight`:e.preventDefault(),a===`hour`&&(this._focusOptionAndSync(t,a),this.updateComplete.then(()=>{this._scrollToSelected(),this._focusSelectedOrFirst(`minute`)}));break;case`ArrowLeft`:e.preventDefault(),a===`minute`&&(this._focusOptionAndSync(t,a),this.updateComplete.then(()=>{this._scrollToSelected(),this._focusSelectedOrFirst(`hour`)}));break;case`Enter`:case` `:e.preventDefault(),t.click();break;case`Escape`:e.preventDefault(),this._closePopup(),this.buttonRef.value?.focus()}}}get inputRef(){return this.hiddenInputRef}manageValidity(e){let t=this.hoursInputRef.value;if(!t)return;let n=this.pktStrings.get(`validation`);if(this.required&&!this.value){this.internals.setValidity({valueMissing:!0},n.valueMissing,t),this._setAriaInvalid(!0);return}if(!this.value){this.internals.setValidity({}),this._setAriaInvalid(!1);return}let i=c(this.value),a=l(this.step);if(this.min&&i<c(String(this.min))){this.internals.setValidity({rangeUnderflow:!0},r.t(n.rangeUnderflowMin,{min:String(this.min)}),t),this._setAriaInvalid(!0);return}if(this.max&&i>c(String(this.max))){this.internals.setValidity({rangeOverflow:!0},r.t(n.rangeOverflowMax,{max:String(this.max)}),t),this._setAriaInvalid(!0);return}if(this.step&&i%a!==0){let e=a===60?n.timeStepMismatchHour:a===30?n.timeStepMismatchHalfHour:r.t(n.timeStepMismatch,{step:`${a}, ${a*2}, ${a*3}`});this.internals.setValidity({stepMismatch:!0},e,t),this._setAriaInvalid(!0);return}this.internals.setValidity({}),this._setAriaInvalid(!1)}_setAriaInvalid(e){if(!this.touched&&e)return;let t=this.hoursInputRef.value,n=this.minutesInputRef.value;if(e)t?.setAttribute(`aria-invalid`,`true`),n?.setAttribute(`aria-invalid`,`true`);else{if(this.hasError)return;t?.removeAttribute(`aria-invalid`),n?.removeAttribute(`aria-invalid`)}}connectedCallback(){super.connectedCallback(),this.addEventListener(`focusin`,this._handleComponentFocusIn),this.addEventListener(`focusout`,this._handleComponentFocusOut),document.addEventListener(`click`,this._outsideClickHandler)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener(`focusin`,this._handleComponentFocusIn),this.removeEventListener(`focusout`,this._handleComponentFocusOut),document.removeEventListener(`click`,this._outsideClickHandler)}willUpdate(e){super.willUpdate(e),e.has(`value`)&&this._syncDisplayFromValue()}updated(e){super.updated(e),this.classList.add(`pkt-timepicker`),this.classList.toggle(`pkt-timepicker--stepper`,this.stepArrows),this.classList.toggle(`pkt-timepicker--fullwidth`,this.fullwidth),this.classList.toggle(`pkt-timepicker--medium`,this.inputSize===`medium`),this.classList.toggle(`pkt-timepicker--small`,this.inputSize===`small`),this.classList.toggle(`pkt-timepicker--xsmall`,this.inputSize===`xsmall`),e.has(`step`)&&this.step!==null&&!this._isValidStep(this.step)&&console.warn(`pkt-timepicker: step="${this.step}" er ikke en gyldig verdi. Step må være et multiplum av 60 (hele minutter) eller nøyaktig 3600 (hel time).`)}formResetCallback(){super.formResetCallback(),this._hours=``,this._minutes=``,this._isOpen=!1}_isValidStep(e){return e===3600||e<3600&&3600%e==0&&e%60==0}_syncDisplayFromValue(){let e=s(this.value)?this.value.split(`:`):null;e?(this._hours=e[0],this._minutes=e[1]):(this._hours=``,this._minutes=``)}_syncValueFromDisplay(){if(this._hours!==``&&this._minutes!==``){let e=`${this._hours}:${this._minutes}`;e!==this.value&&(this.value=e,this.onChange(e))}else this.value!==``&&(this.value=``,this.onChange(``))}get _minuteStep(){return l(this.step)}get _hourOptions(){return u(this.min,this.max)}get _minuteOptions(){return d(this.step)}_openPopup(){this._isOpen=!0,this.updateComplete.then(()=>{this._scrollToSelected(),this._focusSelectedOrFirst(`hour`)})}_closePopup(){this._isOpen=!1,this._syncValueFromDisplay()}_togglePopup(){this._isOpen?this._closePopup():this._openPopup()}_scrollToSelected(){let e=this.querySelector(`.pkt-timepicker-popup`);e&&e.querySelectorAll(`.pkt-timepicker-popup__col`).forEach(e=>{let t=e.querySelector(`.pkt-timepicker-popup__option--selected`);t&&t.scrollIntoView({block:`center`})})}_focusSelectedOrFirst(e){let t=this.querySelector(`.pkt-timepicker-popup`);if(!t)return;let n=t.querySelectorAll(`.pkt-timepicker-popup__col`),r=e===`hour`?n[0]:n[1];if(!r)return;let i=r.querySelector(`.pkt-timepicker-popup__option--selected`),a=r.querySelector(`.pkt-timepicker-popup__option`);(i||a)?.focus()}_handleOptionClick(e,t){let n=String(e).padStart(2,`0`);t===`hour`?(this._hours=n,this.updateComplete.then(()=>this._focusSelectedOrFirst(`minute`))):(this._minutes=n,this._closePopup(),this.buttonRef.value?.focus())}_focusOptionAndSync(e,t){if(!e)return;let n=parseInt(e.dataset.value??`0`,10);t===`hour`?this._hours=String(n).padStart(2,`0`):this._minutes=String(n).padStart(2,`0`),e.focus()}_stepTime(e){let t=f(this._hours,this._minutes,e,this._minuteStep);this._hours=t.hours,this._minutes=t.minutes,this._syncValueFromDisplay()}_renderOption(n,r){let i=String(n).padStart(2,`0`),a=n===(r===`hour`?this._hours===``?NaN:parseInt(this._hours,10):this._minutes===``?NaN:parseInt(this._minutes,10));return e._`
|
|
2
|
-
<button
|
|
3
|
-
class=${t.t({"pkt-btn":!0,"pkt-btn--tertiary":!0,"pkt-btn--small":!0,"pkt-btn--label-only":!0,"pkt-timepicker-popup__option":!0,"pkt-timepicker-popup__option--selected":a})}
|
|
4
|
-
type="button"
|
|
5
|
-
role="option"
|
|
6
|
-
aria-selected=${a?`true`:`false`}
|
|
7
|
-
tabindex=${a?`0`:`-1`}
|
|
8
|
-
data-type=${r}
|
|
9
|
-
data-value=${n}
|
|
10
|
-
@click=${e=>{e.stopImmediatePropagation(),this._handleOptionClick(n,r)}}
|
|
11
|
-
>
|
|
12
|
-
<span class="pkt-btn__text pkt-txt-14-light">${i}</span>
|
|
13
|
-
</button>
|
|
14
|
-
`}_renderPopup(){return e._`
|
|
15
|
-
<div
|
|
16
|
-
class="pkt-timepicker-popup"
|
|
17
|
-
id=${this.id+`-popup`}
|
|
18
|
-
?hidden=${!this._isOpen}
|
|
19
|
-
role="group"
|
|
20
|
-
aria-label=${this.pktStrings.get(`timepicker`).selectTime}
|
|
21
|
-
@keydown=${this._handlePopupKeydown}
|
|
22
|
-
@focusout=${e=>{this.querySelector(`.pkt-timepicker-popup`)?.contains(e.relatedTarget)||this._closePopup()}}
|
|
23
|
-
>
|
|
24
|
-
<div
|
|
25
|
-
class="pkt-timepicker-popup__col"
|
|
26
|
-
role="listbox"
|
|
27
|
-
aria-label=${this.pktStrings.get(`timepicker`).hours}
|
|
28
|
-
aria-orientation="vertical"
|
|
29
|
-
>
|
|
30
|
-
${this._hourOptions.map(e=>this._renderOption(e,`hour`))}
|
|
31
|
-
</div>
|
|
32
|
-
<div
|
|
33
|
-
class="pkt-timepicker-popup__col"
|
|
34
|
-
role="listbox"
|
|
35
|
-
aria-label=${this.pktStrings.get(`timepicker`).minutes}
|
|
36
|
-
aria-orientation="vertical"
|
|
37
|
-
>
|
|
38
|
-
${this._minuteOptions.map(e=>this._renderOption(e,`minute`))}
|
|
39
|
-
</div>
|
|
40
|
-
</div>
|
|
41
|
-
`}_renderContainer(){let t=this.pktStrings.get(`timepicker`).hours,r=this.pktStrings.get(`timepicker`).minutes,i=this.label?`${t}, ${this.label}`:t,o=this.label?`${r}, ${this.label}`:r;return e._`
|
|
42
|
-
<div
|
|
43
|
-
class="pkt-input__container pkt-input__container--${this.inputSize}"
|
|
44
|
-
@click=${e=>{e.target.closest(`button, input`)||this.hoursInputRef.value?.focus()}}
|
|
45
|
-
>
|
|
46
|
-
${this.stepArrows?e._`
|
|
47
|
-
<button
|
|
48
|
-
class="pkt-input-icon pkt-btn pkt-btn--icon-only pkt-btn--tertiary pkt-btn--${this.inputSize} pkt-timepicker__button pkt-timepicker__button--prev"
|
|
49
|
-
type="button"
|
|
50
|
-
aria-label=${this.pktStrings.get(`timepicker`).prevTime}
|
|
51
|
-
?disabled=${this.disabled}
|
|
52
|
-
@click=${()=>this._stepTime(-1)}
|
|
53
|
-
>
|
|
54
|
-
<pkt-icon name="chevron-thin-left"></pkt-icon>
|
|
55
|
-
<span class="pkt-btn__text"
|
|
56
|
-
>${this.pktStrings.get(`timepicker`).prevTime}</span
|
|
57
|
-
>
|
|
58
|
-
</button>
|
|
59
|
-
`:e.h}
|
|
60
|
-
<input
|
|
61
|
-
${a.n(this.hoursInputRef)}
|
|
62
|
-
type="text"
|
|
63
|
-
inputmode="numeric"
|
|
64
|
-
maxlength="2"
|
|
65
|
-
size="2"
|
|
66
|
-
class="pkt-input pkt-input--${this.inputSize} pkt-timepicker__input"
|
|
67
|
-
id=${this.id+`-hours`}
|
|
68
|
-
data-min="0"
|
|
69
|
-
data-max="23"
|
|
70
|
-
.value=${this._hours}
|
|
71
|
-
placeholder="––"
|
|
72
|
-
aria-label=${i}
|
|
73
|
-
role="spinbutton"
|
|
74
|
-
aria-invalid=${this.hasError?`true`:e.h}
|
|
75
|
-
aria-errormessage=${this.hasError?`${this.id}-hours-error`:e.h}
|
|
76
|
-
aria-valuemin="0"
|
|
77
|
-
aria-valuemax="23"
|
|
78
|
-
aria-valuenow=${this._hours===``?e.h:this._hours}
|
|
79
|
-
aria-valuetext=${this._hours===``?e.h:`${this._hours} ${t.toLowerCase()}`}
|
|
80
|
-
autocomplete="off"
|
|
81
|
-
?disabled=${this.disabled}
|
|
82
|
-
@keydown=${this._handleHoursKeydown}
|
|
83
|
-
@blur=${this._handleHoursBlur}
|
|
84
|
-
@focus=${e=>{e.target.select(),e.stopImmediatePropagation()}}
|
|
85
|
-
/>
|
|
86
|
-
<span class="pkt-timepicker__separator">:</span>
|
|
87
|
-
<input
|
|
88
|
-
${a.n(this.minutesInputRef)}
|
|
89
|
-
type="text"
|
|
90
|
-
inputmode="numeric"
|
|
91
|
-
maxlength="2"
|
|
92
|
-
size="2"
|
|
93
|
-
class="pkt-input pkt-input--${this.inputSize} pkt-timepicker__input"
|
|
94
|
-
id=${this.id+`-minutes`}
|
|
95
|
-
data-min="0"
|
|
96
|
-
data-max="59"
|
|
97
|
-
.value=${this._minutes}
|
|
98
|
-
placeholder="––"
|
|
99
|
-
aria-label=${o}
|
|
100
|
-
role="spinbutton"
|
|
101
|
-
aria-invalid=${this.hasError?`true`:e.h}
|
|
102
|
-
aria-errormessage=${this.hasError?`${this.id}-hours-error`:e.h}
|
|
103
|
-
aria-valuemin="0"
|
|
104
|
-
aria-valuemax="59"
|
|
105
|
-
aria-valuenow=${this._minutes===``?e.h:this._minutes}
|
|
106
|
-
aria-valuetext=${this._minutes===``?e.h:`${this._minutes} ${r.toLowerCase()}`}
|
|
107
|
-
autocomplete="off"
|
|
108
|
-
?disabled=${this.disabled}
|
|
109
|
-
@keydown=${this._handleMinutesKeydown}
|
|
110
|
-
@blur=${this._handleMinutesBlur}
|
|
111
|
-
@focus=${e=>{e.target.select(),e.stopImmediatePropagation()}}
|
|
112
|
-
/>
|
|
113
|
-
${this.hidePicker&&!this.stepArrows?e._`<pkt-icon
|
|
114
|
-
class="pkt-input-icon pkt-timepicker__icon"
|
|
115
|
-
name="clock"
|
|
116
|
-
aria-hidden="true"
|
|
117
|
-
></pkt-icon>`:e.h}
|
|
118
|
-
${!this.hidePicker&&!this.stepArrows?e._`
|
|
119
|
-
<button
|
|
120
|
-
${a.n(this.buttonRef)}
|
|
121
|
-
class="pkt-input-icon pkt-btn pkt-btn--icon-only pkt-btn--tertiary pkt-btn--${this.inputSize} pkt-timepicker__button"
|
|
122
|
-
type="button"
|
|
123
|
-
aria-label=${this.pktStrings.get(`timepicker`).openPicker}
|
|
124
|
-
aria-haspopup="listbox"
|
|
125
|
-
aria-expanded=${this._isOpen?`true`:`false`}
|
|
126
|
-
aria-controls=${this.id+`-popup`}
|
|
127
|
-
?disabled=${this.disabled}
|
|
128
|
-
@click=${this._togglePopup}
|
|
129
|
-
>
|
|
130
|
-
<pkt-icon name="clock"></pkt-icon>
|
|
131
|
-
<span class="pkt-btn__text"
|
|
132
|
-
>${this.pktStrings.get(`timepicker`).openPicker}</span
|
|
133
|
-
>
|
|
134
|
-
</button>
|
|
135
|
-
`:e.h}
|
|
136
|
-
${this.stepArrows?e._`
|
|
137
|
-
<button
|
|
138
|
-
class="pkt-input-icon pkt-btn pkt-btn--icon-only pkt-btn--tertiary pkt-btn--${this.inputSize} pkt-timepicker__button pkt-timepicker__button--next"
|
|
139
|
-
type="button"
|
|
140
|
-
aria-label=${this.pktStrings.get(`timepicker`).nextTime}
|
|
141
|
-
?disabled=${this.disabled}
|
|
142
|
-
@click=${()=>this._stepTime(1)}
|
|
143
|
-
>
|
|
144
|
-
<pkt-icon name="chevron-thin-right"></pkt-icon>
|
|
145
|
-
<span class="pkt-btn__text"
|
|
146
|
-
>${this.pktStrings.get(`timepicker`).nextTime}</span
|
|
147
|
-
>
|
|
148
|
-
</button>
|
|
149
|
-
`:e.h}
|
|
150
|
-
<input
|
|
151
|
-
${a.n(this.hiddenInputRef)}
|
|
152
|
-
type="time"
|
|
153
|
-
hidden
|
|
154
|
-
name=${this.name||this.id}
|
|
155
|
-
id=${this.id+`-input`}
|
|
156
|
-
.value=${this.value}
|
|
157
|
-
min=${n.t(this.min??void 0)}
|
|
158
|
-
max=${n.t(this.max??void 0)}
|
|
159
|
-
step=${n.t(this.step??void 0)}
|
|
160
|
-
?required=${this.required}
|
|
161
|
-
?disabled=${this.disabled}
|
|
162
|
-
tabindex="-1"
|
|
163
|
-
/>
|
|
164
|
-
</div>
|
|
165
|
-
`}render(){return e._`
|
|
166
|
-
<pkt-input-wrapper
|
|
167
|
-
.strings=${this.strings}
|
|
168
|
-
label="${this.label}"
|
|
169
|
-
?disabled=${this.disabled}
|
|
170
|
-
?fullwidth=${this.fullwidth}
|
|
171
|
-
?hasError=${this.hasError}
|
|
172
|
-
?hasFieldset=${this.effectiveHasFieldset(!1)}
|
|
173
|
-
?inline=${this.inline}
|
|
174
|
-
?optionalTag=${this.optionalTag}
|
|
175
|
-
?required=${this.required}
|
|
176
|
-
?requiredTag=${this.requiredTag}
|
|
177
|
-
useWrapper=${this.useWrapper}
|
|
178
|
-
.ariaDescribedby=${this.ariaDescribedby}
|
|
179
|
-
.errorMessage=${this.errorMessage}
|
|
180
|
-
.forId="${this.id+`-hours`}"
|
|
181
|
-
.helptext=${this.helptext}
|
|
182
|
-
.helptextDropdown=${this.helptextDropdown}
|
|
183
|
-
.helptextDropdownButton=${this.helptextDropdownButton}
|
|
184
|
-
.optionalText=${this.optionalText}
|
|
185
|
-
.requiredText=${this.requiredText}
|
|
186
|
-
.tagText=${this.tagText}
|
|
187
|
-
.size=${this.inputSize}
|
|
188
|
-
>
|
|
189
|
-
<div class="pkt-contents" slot="helptext">${i.r(this,`helptext`)}</div>
|
|
190
|
-
${!this.hidePicker&&!this.stepArrows?e._`
|
|
191
|
-
<div class="pkt-timepicker__anchor">
|
|
192
|
-
${this._renderContainer()} ${this._renderPopup()}
|
|
193
|
-
</div>
|
|
194
|
-
`:this._renderContainer()}
|
|
195
|
-
</pkt-input-wrapper>
|
|
196
|
-
`}};e.n([e.u({type:String,reflect:!0})],p.prototype,`value`,void 0),e.n([e.u({type:Boolean,reflect:!0,attribute:`hide-picker`})],p.prototype,`hidePicker`,void 0),e.n([e.u({type:Boolean,reflect:!0,attribute:`step-arrows`})],p.prototype,`stepArrows`,void 0),e.n([e.l()],p.prototype,`_hours`,void 0),e.n([e.l()],p.prototype,`_minutes`,void 0),e.n([e.l()],p.prototype,`_isOpen`,void 0);try{e.d(`pkt-timepicker`)(p)}catch{console.warn(`Forsøker å definere <pkt-timepicker>, men den er allerede definert`)}Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return p}});
|