@oslokommune/punkt-elements 16.15.1 → 16.17.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.
- package/CHANGELOG.md +18 -0
- package/dist/{accordion-nNH87Y60.js → accordion-CU2tJ5vn.js} +23 -9
- package/dist/{accordion-BB1JrONI.cjs → accordion-DDZkjXFb.cjs} +20 -7
- package/dist/{checkbox-Bjp43NxA.js → checkbox-BxNrOGUf.js} +1 -1
- package/dist/{checkbox-nTbihMxW.cjs → checkbox-rmSCYDgR.cjs} +1 -1
- package/dist/{combobox-C4Q6kQEs.cjs → combobox-C8Iwfalo.cjs} +1 -1
- package/dist/{combobox-CL9BLuxt.js → combobox-haqD3OH4.js} +3 -3
- package/dist/components/header-menu/header-menu.d.ts +41 -0
- package/dist/components/header-menu/header-menu.test.d.ts +0 -0
- package/dist/components/header-menu/index.d.ts +5 -0
- package/dist/components/header-menu/types.d.ts +6 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/{datepicker-BUK1Qanw.js → datepicker-DbkWEh8e.js} +2 -2
- package/dist/{datepicker-DYd3JCs_.cjs → datepicker-xZFsUaXB.cjs} +1 -1
- package/dist/docs/components/header-full.d.ts +13 -0
- package/dist/docs/components/header-menu.d.ts +8 -0
- package/dist/{fileupload-DbmqRkz3.js → fileupload-CTnjLOnj.js} +3 -3
- package/dist/{fileupload-DjUAvBcP.cjs → fileupload-D2z1Ngrt.cjs} +1 -1
- package/dist/{header-Dps8o-ZY.cjs → header-BHU7qpA_.cjs} +2 -2
- package/dist/{header-T5O6sfCN.js → header-Zqs7F1pI.js} +4 -3
- package/dist/header-menu-CPI1_5oZ.cjs +126 -0
- package/dist/header-menu-zhGYdnvz.js +319 -0
- package/dist/header-menu.d.ts +1 -0
- package/dist/{helptext-C5rG4VkA.js → helptext-BdqoW19r.js} +1 -1
- package/dist/{helptext-DQgStO4D.cjs → helptext-KWXjKljV.cjs} +1 -1
- package/dist/{input-element-CjebcQd1.js → input-element-B1ciW1N2.js} +1 -1
- package/dist/{input-element-FGcr5hGd.cjs → input-element-D0egtEnr.cjs} +1 -1
- package/dist/{input-wrapper-B_XFi211.cjs → input-wrapper-BJfspAt7.cjs} +1 -1
- package/dist/{input-wrapper-DBpMVSxt.js → input-wrapper-CGSrvrlb.js} +2 -2
- package/dist/{modal-DyIC3uhs.js → modal-DYc5M-Pn.js} +1 -1
- package/dist/{modal-B6591sWa.cjs → modal-J5uWdD1M.cjs} +1 -1
- package/dist/pkt-accordion.cjs +1 -1
- package/dist/pkt-accordion.js +1 -1
- package/dist/pkt-checkbox.cjs +1 -1
- package/dist/pkt-checkbox.js +1 -1
- package/dist/pkt-combobox.cjs +1 -1
- package/dist/pkt-combobox.js +1 -1
- package/dist/pkt-consent.cjs +1 -1
- package/dist/pkt-consent.js +1 -1
- package/dist/pkt-datepicker.cjs +1 -1
- package/dist/pkt-datepicker.js +1 -1
- package/dist/pkt-fileupload.cjs +1 -1
- package/dist/pkt-fileupload.js +1 -1
- package/dist/pkt-header-menu.cjs +1 -0
- package/dist/pkt-header-menu.js +2 -0
- package/dist/pkt-header.cjs +1 -1
- package/dist/pkt-header.js +1 -1
- package/dist/pkt-helptext.cjs +1 -1
- package/dist/pkt-helptext.js +1 -1
- package/dist/pkt-index.cjs +1 -1
- package/dist/pkt-index.js +23 -22
- package/dist/pkt-input-wrapper.cjs +1 -1
- package/dist/pkt-input-wrapper.js +1 -1
- package/dist/pkt-link.cjs +1 -1
- package/dist/pkt-link.js +1 -1
- package/dist/pkt-linkcard.cjs +1 -1
- package/dist/pkt-linkcard.js +1 -1
- package/dist/pkt-loader.cjs +1 -1
- package/dist/pkt-loader.js +1 -1
- package/dist/pkt-messagebox.cjs +1 -1
- package/dist/pkt-messagebox.js +1 -1
- package/dist/pkt-modal.cjs +1 -1
- package/dist/pkt-modal.js +1 -1
- package/dist/pkt-progressbar.cjs +1 -1
- package/dist/pkt-progressbar.js +1 -1
- package/dist/pkt-radiobutton.cjs +1 -1
- package/dist/pkt-radiobutton.js +1 -1
- package/dist/pkt-select.cjs +1 -1
- package/dist/pkt-select.js +1 -1
- package/dist/pkt-tabs.cjs +1 -1
- package/dist/pkt-tabs.js +1 -1
- package/dist/pkt-textarea.cjs +1 -1
- package/dist/pkt-textarea.js +1 -1
- package/dist/pkt-textinput.cjs +1 -1
- package/dist/pkt-textinput.js +1 -1
- package/dist/pkt-timepicker.cjs +1 -1
- package/dist/pkt-timepicker.js +1 -1
- package/dist/{radiobutton-DvXr7tDk.cjs → radiobutton-Crl2w27S.cjs} +1 -1
- package/dist/{radiobutton-B-8-wWFf.js → radiobutton-CzNQ4OLz.js} +1 -1
- package/dist/{select-B75wzvyz.cjs → select-BvlbaxYf.cjs} +1 -1
- package/dist/{select-D9B8Ighz.js → select-DpxXnNje.js} +3 -3
- package/dist/shared-types/header-menu.d.ts +108 -0
- package/dist/shared-types/index.d.ts +2 -0
- package/dist/shared-types/skin.d.ts +1 -1
- package/dist/shared-utils/header-menu/example-data.d.ts +11 -0
- package/dist/shared-utils/header-menu/fetch-header-footer-data.d.ts +12 -0
- package/dist/shared-utils/header-menu/icon-map.d.ts +34 -0
- package/dist/shared-utils/header-menu/index.d.ts +11 -0
- package/dist/shared-utils/header-menu/select-megamenu.d.ts +16 -0
- package/dist/{textarea-CIWXMaAD.js → textarea-BgsX_PHm.js} +2 -2
- package/dist/{textarea-CjqprL6Y.cjs → textarea-BjQ_37ji.cjs} +1 -1
- package/dist/{textinput-CxzAxM8E.js → textinput-BmuQREJY.js} +2 -2
- package/dist/{textinput-B0VWmVIF.cjs → textinput-mjmYIwxr.cjs} +1 -1
- package/dist/{timepicker-DXrpg5C7.js → timepicker-Bj_esO1U.js} +2 -2
- package/dist/{timepicker-Cv9juQeB.cjs → timepicker-C7vU_hTg.cjs} +1 -1
- package/package.json +3 -3
- package/src/components/accordion/accordionitem.ts +22 -5
- package/src/components/header/header-service.ts +1 -0
- package/src/components/header-menu/header-menu.test.ts +314 -0
- package/src/components/header-menu/header-menu.ts +401 -0
- package/src/components/header-menu/index.ts +6 -0
- package/src/components/header-menu/types.ts +31 -0
- package/src/components/index.ts +3 -0
- /package/dist/{consent-f_IGyHss.js → consent-CsX3DABo.js} +0 -0
- /package/dist/{consent-zh2npq2K.cjs → consent-DjXqLn2K.cjs} +0 -0
- /package/dist/{dialog-polyfill.esm-CXDsb3l-.cjs → dialog-polyfill.esm-C6RtqFbz.cjs} +0 -0
- /package/dist/{dialog-polyfill.esm-BmVHGRTX.js → dialog-polyfill.esm-DrODM08x.js} +0 -0
- /package/dist/{input-wrapper-CYCCx8MP.cjs → input-wrapper-CQGoyLdZ.cjs} +0 -0
- /package/dist/{input-wrapper-kw2y6Jp_.js → input-wrapper-DwSsP39J.js} +0 -0
- /package/dist/{link-B8zYc5WK.cjs → link-H7BhqdWV.cjs} +0 -0
- /package/dist/{link-CjJcwcxR.js → link-X9H6zi7W.js} +0 -0
- /package/dist/{linkcard-Ddh5R_L-.js → linkcard-CSWzphQK.js} +0 -0
- /package/dist/{linkcard-C4x-NJMi.cjs → linkcard-zS3WuhAY.cjs} +0 -0
- /package/dist/{loader-DeizpX45.js → loader-B4EGLEoa.js} +0 -0
- /package/dist/{loader-CGQXAuyM.cjs → loader-BWcSsK7i.cjs} +0 -0
- /package/dist/{messagebox-Ccu29rDv.cjs → messagebox-BSvU998N.cjs} +0 -0
- /package/dist/{messagebox-DqoPqo4K.js → messagebox-DsrTKauA.js} +0 -0
- /package/dist/{pkt-options-controller-DbLrdRwH.js → pkt-options-controller-CCB15L_G.js} +0 -0
- /package/dist/{pkt-options-controller-BPBb_O2K.cjs → pkt-options-controller-CeAQ-D-i.cjs} +0 -0
- /package/dist/{progressbar-CrwpnIkv.cjs → progressbar-8RYeaOQe.cjs} +0 -0
- /package/dist/{progressbar-uC-0W6o4.js → progressbar-hQSIzdof.js} +0 -0
- /package/dist/{tabs-RnDtIFv3.cjs → tabs-CDLdEDGH.cjs} +0 -0
- /package/dist/{tabs-4eWA7CsK.js → tabs-DDBYA5c8.js} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,24 @@ og skriver commits ca etter [Conventional Commits](https://conventionalcommits.o
|
|
|
5
5
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
+
## [16.17.0](https://github.com/oslokommune/punkt/compare/16.16.2...16.17.0) (2026-05-15)
|
|
9
|
+
|
|
10
|
+
### ⚠ BREAKING CHANGES
|
|
11
|
+
Ingen
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
* Global headermeny (#3446).
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
Ingen
|
|
19
|
+
|
|
20
|
+
### Chores
|
|
21
|
+
Ingen
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
|
|
8
26
|
## [16.15.1](https://github.com/oslokommune/punkt/compare/16.15.0...16.15.1) (2026-05-11)
|
|
9
27
|
|
|
10
28
|
### ⚠ BREAKING CHANGES
|
|
@@ -74,13 +74,14 @@ var f = class extends s {
|
|
|
74
74
|
this.defaultOpen && (this.isOpen = !0);
|
|
75
75
|
}
|
|
76
76
|
render() {
|
|
77
|
-
|
|
78
|
-
<details
|
|
79
|
-
class=${a({
|
|
77
|
+
let e = {
|
|
80
78
|
"pkt-accordion-item": !0,
|
|
81
79
|
"pkt-accordion-item--compact": this.compact,
|
|
82
80
|
[`pkt-accordion-item--${this.skin}`]: !!this.skin
|
|
83
|
-
}
|
|
81
|
+
}, t = this.skin === "plus-minus";
|
|
82
|
+
return n`
|
|
83
|
+
<details
|
|
84
|
+
class=${a(e)}
|
|
84
85
|
id=${this.id}
|
|
85
86
|
?open=${this.isOpen}
|
|
86
87
|
${l(this.accordionItemRef)}
|
|
@@ -88,11 +89,24 @@ var f = class extends s {
|
|
|
88
89
|
>
|
|
89
90
|
<summary class="pkt-accordion-item__title" id=${`pkt-accordion-item-summary-${this.id}`}>
|
|
90
91
|
${this.title}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
92
|
+
${t ? n`
|
|
93
|
+
<pkt-icon
|
|
94
|
+
name="plus-sign"
|
|
95
|
+
class="pkt-accordion-item__icon pkt-accordion-item__icon--plus"
|
|
96
|
+
aria-hidden="true"
|
|
97
|
+
></pkt-icon>
|
|
98
|
+
<pkt-icon
|
|
99
|
+
name="minus-sign"
|
|
100
|
+
class="pkt-accordion-item__icon pkt-accordion-item__icon--minus"
|
|
101
|
+
aria-hidden="true"
|
|
102
|
+
></pkt-icon>
|
|
103
|
+
` : n`
|
|
104
|
+
<pkt-icon
|
|
105
|
+
name="chevron-thin-down"
|
|
106
|
+
class="pkt-accordion-item__icon"
|
|
107
|
+
aria-hidden="true"
|
|
108
|
+
></pkt-icon>
|
|
109
|
+
`}
|
|
96
110
|
</summary>
|
|
97
111
|
<div
|
|
98
112
|
class="pkt-accordion-item__content"
|
|
@@ -7,9 +7,9 @@ const e=require(`./element-DjtxO-1r.cjs`),t=require(`./class-map-CJ-msbHs.cjs`),
|
|
|
7
7
|
>
|
|
8
8
|
<slot></slot>
|
|
9
9
|
</div>
|
|
10
|
-
`}};e.r([e.s({type:String,reflect:!0,attribute:`aria-labelledby`})],a.prototype,`ariaLabelledBy`,void 0),e.r([e.s({type:Boolean,reflect:!0,attribute:`compact`})],a.prototype,`compact`,void 0),e.r([e.s({type:String,reflect:!0,attribute:`skin`})],a.prototype,`skin`,void 0),e.r([e.s({type:String,reflect:!0,attribute:`name`})],a.prototype,`name`,void 0);try{e.c(`pkt-accordion`)(a)}catch{console.warn(`Forsøker å definere <pkt-accordion>, men den er allerede definert`)}var o=class extends n.t{constructor(){super(),this.defaultOpen=!1,this.title=``,this.skin=void 0,this.compact=!1,this.isOpen=!1,this.name=void 0,this.accordionItemRef=i.t()}firstUpdated(e){this.defaultOpen&&(this.isOpen=!0)}render(){return e.d`
|
|
10
|
+
`}};e.r([e.s({type:String,reflect:!0,attribute:`aria-labelledby`})],a.prototype,`ariaLabelledBy`,void 0),e.r([e.s({type:Boolean,reflect:!0,attribute:`compact`})],a.prototype,`compact`,void 0),e.r([e.s({type:String,reflect:!0,attribute:`skin`})],a.prototype,`skin`,void 0),e.r([e.s({type:String,reflect:!0,attribute:`name`})],a.prototype,`name`,void 0);try{e.c(`pkt-accordion`)(a)}catch{console.warn(`Forsøker å definere <pkt-accordion>, men den er allerede definert`)}var o=class extends n.t{constructor(){super(),this.defaultOpen=!1,this.title=``,this.skin=void 0,this.compact=!1,this.isOpen=!1,this.name=void 0,this.accordionItemRef=i.t()}firstUpdated(e){this.defaultOpen&&(this.isOpen=!0)}render(){let a={"pkt-accordion-item":!0,"pkt-accordion-item--compact":this.compact,[`pkt-accordion-item--${this.skin}`]:!!this.skin},o=this.skin===`plus-minus`;return e.d`
|
|
11
11
|
<details
|
|
12
|
-
class=${t.t(
|
|
12
|
+
class=${t.t(a)}
|
|
13
13
|
id=${this.id}
|
|
14
14
|
?open=${this.isOpen}
|
|
15
15
|
${i.n(this.accordionItemRef)}
|
|
@@ -17,11 +17,24 @@ const e=require(`./element-DjtxO-1r.cjs`),t=require(`./class-map-CJ-msbHs.cjs`),
|
|
|
17
17
|
>
|
|
18
18
|
<summary class="pkt-accordion-item__title" id=${`pkt-accordion-item-summary-${this.id}`}>
|
|
19
19
|
${this.title}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
${o?e.d`
|
|
21
|
+
<pkt-icon
|
|
22
|
+
name="plus-sign"
|
|
23
|
+
class="pkt-accordion-item__icon pkt-accordion-item__icon--plus"
|
|
24
|
+
aria-hidden="true"
|
|
25
|
+
></pkt-icon>
|
|
26
|
+
<pkt-icon
|
|
27
|
+
name="minus-sign"
|
|
28
|
+
class="pkt-accordion-item__icon pkt-accordion-item__icon--minus"
|
|
29
|
+
aria-hidden="true"
|
|
30
|
+
></pkt-icon>
|
|
31
|
+
`:e.d`
|
|
32
|
+
<pkt-icon
|
|
33
|
+
name="chevron-thin-down"
|
|
34
|
+
class="pkt-accordion-item__icon"
|
|
35
|
+
aria-hidden="true"
|
|
36
|
+
></pkt-icon>
|
|
37
|
+
`}
|
|
25
38
|
</summary>
|
|
26
39
|
<div
|
|
27
40
|
class="pkt-accordion-item__content"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { c as e, d as t, l as n, r, s as i } from "./element-cZ85T_aa.js";
|
|
2
2
|
import { t as a } from "./class-map-C8HuhNzZ.js";
|
|
3
3
|
import { n as o, t as s } from "./ref-RS8Uv6uC.js";
|
|
4
|
-
import { t as c } from "./input-element-
|
|
4
|
+
import { t as c } from "./input-element-B1ciW1N2.js";
|
|
5
5
|
//#region src/components/checkbox/checkbox.ts
|
|
6
6
|
var l = class extends c {
|
|
7
7
|
constructor(...e) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const e=require(`./element-DjtxO-1r.cjs`),t=require(`./class-map-CJ-msbHs.cjs`),n=require(`./ref-BaJ0mBT_.cjs`),r=require(`./input-element-
|
|
1
|
+
const e=require(`./element-DjtxO-1r.cjs`),t=require(`./class-map-CJ-msbHs.cjs`),n=require(`./ref-BaJ0mBT_.cjs`),r=require(`./input-element-D0egtEnr.cjs`);var i=class extends r.t{constructor(...e){super(...e),this.inputRef=n.t(),this.value=``,this.checkHelptext=null,this.defaultChecked=!1,this.hasTile=!1,this.isSwitch=!1,this.labelPosition=`right`,this.hideLabel=!1,this.checked=null,this.indeterminate=!1,this.type=`checkbox`,this.tagText=null,this.optionalTag=!1,this.optionalText=`Valgfritt`,this.requiredTag=!1,this.requiredText=`Må fylles ut`}connectedCallback(){super.connectedCallback()}attributeChangedCallback(e,t,n){e===`defaultChecked`&&!this.checked&&(this.checked=this.defaultChecked),e===`checked`&&(this.checked=this.checked===``||this.checked===`true`||this.checked===!0,this.inputRef.value&&(this.inputRef.value.checked=this.checked)),e===`indeterminate`&&(this.indeterminate=this.indeterminate===``||this.indeterminate===`true`||this.indeterminate===!0,this.inputRef.value&&(this.inputRef.value.indeterminate=this.indeterminate)),super.attributeChangedCallback(e,t,n)}firstUpdated(e){e.has(`defaultChecked`)&&!this.checked&&(this.checked=this.defaultChecked),this.inputRef.value&&(this.inputRef.value.indeterminate=this.indeterminate===``||this.indeterminate===`true`||this.indeterminate===!0),super.firstUpdated(e)}updated(e){e.has(`defaultChecked`)&&!this.checked&&(this.checked=this.defaultChecked),e.has(`checked`)&&this.inputRef.value&&(this.inputRef.value.checked=this.checked===``||this.checked===`true`||this.checked===!0),e.has(`indeterminate`)&&this.inputRef.value&&(this.inputRef.value.indeterminate=this.indeterminate===``||this.indeterminate===`true`||this.indeterminate===!0),super.updated(e)}render(){let r=t.t({"pkt-input-check__input":!0,"pkt-input-check__input--tile":this.hasTile,"pkt-input-check__input--tile-disabled":this.disabled&&this.hasTile}),i=t.t({"pkt-input-check__input-checkbox":!0,"pkt-input-check__input-checkbox--error":this.hasError}),a=t.t({"pkt-input-check__input-label":!0,"pkt-input-check__input-label--disabled":this.disabled,"pkt-input-check__input-label--left":this.labelPosition===`left`,"pkt-input-check__input-label--right":this.labelPosition===`right`,"pkt-sr-only":this.hideLabel}),o=`pkt-tag pkt-tag--small pkt-tag--thin-text`,s=()=>e.d`
|
|
2
2
|
${this.tagText?e.d`<span class=${o+` pkt-tag--gray`}>${this.tagText}</span>`:e.l}
|
|
3
3
|
${this.optionalTag?e.d`<span class=${o+` pkt-tag--blue-light`}>${this.optionalText}</span>`:e.l}
|
|
4
4
|
${this.requiredTag?e.d`<span class=${o+` pkt-tag--beige`}>${this.requiredText}</span>`:e.l}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const e=require(`./element-DjtxO-1r.cjs`),t=require(`./class-map-CJ-msbHs.cjs`),n=require(`./element-with-slot-CWoTGA1B.cjs`);require(`./icon-Dr8sfT2X.cjs`);const r=require(`./if-defined-XKOD_t_V.cjs`),i=require(`./ref-BaJ0mBT_.cjs`);require(`./tag-DWtajZk6.cjs`);const a=require(`./repeat-DaDFvx86.cjs`),o=require(`./listbox-CcThiNBY.cjs`),s=require(`./input-element-FGcr5hGd.cjs`),c=require(`./pkt-options-controller-BPBb_O2K.cjs`);require(`./input-wrapper-B_XFi211.cjs`);var l=(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}},u=(e,t,n,r,i)=>{if(!e)return{action:`none`,value:null};let a=o.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}},d=(e,t,n,r,i)=>e.trim().toLowerCase()?{...o.s(e,t,n,r),shouldRemoveValue:!1,shouldResetInput:!1}:{addValueText:null,userInfoMessage:``,shouldRemoveValue:!i&&!!t[0],shouldResetInput:!0},f=(e,t,n)=>{let r=o.i(t,e);return n===`label`&&r?.label?r.label:e},p={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)}},m={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=o.r(n),t.push(n)}),t}},h={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=o.r(e),e.selected=e.selected||n.includes(e.value)}),{options:e,newValues:n}},mergeWithUserAdded(e,t){return[...t.filter(e=>e?.userAdded&&e.selected).filter(t=>!(Array.isArray(e)?e:[]).some(e=>e.value===t.value)),...e]}},g={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`},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:{type:`string`,name:`Utvidet hjelpetekst`,description:`Hjelpetekst som vises i en lukket boks man kan åpne`,category:`contents`},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:{type:`boolean`,name:`Feil`,description:`Feltet har en feil`,category:`ui`},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:{type:`boolean`,name:`Påkrevd-merking`,description:`Viser en merking som indikerer at feltet er påkrevd`,category:`ui`},requiredText:{type:`string`,name:`Påkrevd-tekst`,description:`Tekst som vises i påkrevd-merkingen`,category:`contents`},optionalTag:{type:`boolean`,name:`Valgfritt-merking`,description:`Viser en merking som indikerer at feltet er valgfritt`,category:`ui`},optionalText:{type:`string`,name:`Valgfritt-tekst`,description:`Tekst som vises i valgfritt-merkingen`,category:`contents`},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`}},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`}}},_=class extends s.t{constructor(){super(),this.value=``,this.options=[],this.defaultOptions=[],this.allowUserInput=!1,this.typeahead=!1,this.includeSearch=!1,this.searchPlaceholder=``,this.multiple=!1,this.maxlength=null,this.displayValueAs=g.props.displayValueAs.default,this.tagPlacement=null,this.isOpen=!1,this._options=[],this._value=[],this._isOptionsOpen=!1,this._userInfoMessage=``,this._addValueText=null,this._maxIsReached=!1,this._search=``,this._inputFocus=!1,this._internalValueSync=!1,this._optionsFromSlot=!1,this._lastSlotGeneration=0,this._suppressNextOpen=!1,this.inputRef=i.t(),this.triggerRef=i.t(),this.listboxRef=i.t(),this.optionsController=new c.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()}parseValue(){return Array.isArray(this.value)?this.multiple?this.value:this.value.length>0?[this.value[0]]:[]:this.value&&this.multiple?this.value.split(`,`):this.value?[this.value]:[]}updateMaxReached(){this._maxIsReached=o.c(this._value.length,this.maxlength)}syncValueAndDispatch(e){let t=this._value,n=this.multiple?t.join(`,`):t[0]||``;if(n!==(Array.isArray(this.value)?this.value.join(`,`):String(this.value||``))&&(this._internalValueSync=!0,this.value=n),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.r([e.s({type:String,reflect:!0})],_.prototype,`value`,void 0),e.r([e.s({type:Array})],_.prototype,`options`,void 0),e.r([e.s({type:Array,attribute:`default-options`})],_.prototype,`defaultOptions`,void 0),e.r([e.s({type:Boolean,attribute:`allow-user-input`})],_.prototype,`allowUserInput`,void 0),e.r([e.s({type:Boolean})],_.prototype,`typeahead`,void 0),e.r([e.s({type:Boolean,attribute:`include-search`})],_.prototype,`includeSearch`,void 0),e.r([e.s({type:String,attribute:`search-placeholder`})],_.prototype,`searchPlaceholder`,void 0),e.r([e.s({type:Boolean})],_.prototype,`multiple`,void 0),e.r([e.s({type:Number})],_.prototype,`maxlength`,void 0),e.r([e.s({type:String,attribute:`display-value-as`})],_.prototype,`displayValueAs`,void 0),e.r([e.s({type:String,attribute:`tag-placement`})],_.prototype,`tagPlacement`,void 0),e.r([e.s({type:Boolean,attribute:`open`})],_.prototype,`isOpen`,void 0),e.r([e.o()],_.prototype,`_options`,void 0),e.r([e.o()],_.prototype,`_value`,void 0),e.r([e.o()],_.prototype,`_isOptionsOpen`,void 0),e.r([e.o()],_.prototype,`_userInfoMessage`,void 0),e.r([e.o()],_.prototype,`_addValueText`,void 0),e.r([e.o()],_.prototype,`_maxIsReached`,void 0),e.r([e.o()],_.prototype,`_search`,void 0),e.r([e.o()],_.prototype,`_inputFocus`,void 0);var v=class extends _{toggleValue(e){if(this.disabled)return;this.touched=!0,this._userInfoMessage=``,this._addValueText=null;let t=o.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(),s=!this.multiple,c=this.multiple,l=o.c(this._value.length,this.maxlength),u=!1,d=!0,f=``,p=``;i||(!r&&this.allowUserInput&&!a?(this.addNewUserValue(e),f=`Ny verdi lagt til`,u=c):!r&&!this.allowUserInput?(s&&this._value[0]&&this.removeValue(this._value[0]),d=!1,u=!0,f=`Ingen treff i søket`):n?(this.removeValue(t),u=!0,s&&this._hasTextInput&&this.inputRef.value&&this.inputRef.value.type!==`hidden`&&(this.inputRef.value.value=``)):a&&s?(this.removeAllSelected(),u=!0):s?(this._value[0]&&this.removeSelected(this._value[0]),this.setSelected(t),u=!1):c&&!l?(this.setSelected(t),u=!0):c&&l?(f=`Maks antall valg nådd`,d=!1,p=e):(s&&this.removeAllSelected(),f=`Ingen gyldig verdi valgt`,d=!1,u=!0,p=e),this._isOptionsOpen=u,u||(s&&this._hasTextInput&&(this._suppressNextOpen=!0),window.setTimeout(()=>{this.focusTrigger()},0)),this._userInfoMessage=f,this._search=p||``,this.resetComboboxInput(d),c&&this.updateMaxReached())}setSelected(e){if(!this._value.includes(e)){if(this.multiple&&o.c(this._value.length,this.maxlength)){this._userInfoMessage=`Maks antall valg nådd`;return}!this.multiple&&this.removeAllSelected(),this._value=e?[...this._value,e]:this._value,p.markOptionSelected(this._options,e),this.resetComboboxInput(!0)}}removeSelected(e){if(!e)return;this._value=this._value.filter(t=>t!==e);let t=o.i(this.options,e);t&&(p.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=`For mange valgt`;return}this._value=this._options.map(e=>e.value),p.markAllSelected(this._options),this.requestUpdate()}}removeAllSelected(){this._value=[],p.markAllDeselected(this._options),this._options=p.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=`Verdien er allerede valgt`;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(!o.i(this.options,e)){if(o.c(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,this._hasTextInput&&(this._suppressNextOpen=!0),window.setTimeout(()=>{this.focusTrigger()},0)),this.requestUpdate()}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]?f(this._value[0],this.options,this.displayValueAs):``,this._userInfoMessage=``)),this._options=[...this.options]}removeLastValue(e){if(this._value.length===0)return;e.preventDefault();let t=this._value[this._value.length-1];t&&this.removeSelected(t),this.updateMaxReached()}},y=class extends v{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}=o.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._options=[...this.options]}handleFocus(){if(!this.disabled){if(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=f(this._value[0],this.options,this.displayValueAs)),this._inputFocus=!0,this._search=``,this._options=[...this.options],this._isOptionsOpen=!0,this.onFocus(),this.requestUpdate()}}handleFocusOut(e){if(this.disabled||!this._isOptionsOpen)return;let t=e.relatedTarget;t?.closest(`pkt-combobox`)?.id===this.id||e.target?.getAttribute(`data-focusfix`)===this.id||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=o.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}=u(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);break}}!this.multiple&&this._value[0]?this.inputRef.value.value=f(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]));break}}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=l(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;break}}}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();break}}checkForMatches(){let e=d(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}},b=class extends y{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&&(this.options=[...this.options?.filter(e=>e.userAdded)||[],...JSON.parse(JSON.stringify(this.defaultOptions))],this._options=Array.isArray(this.options)?[...this.options]:[]),this.optionsController?.nodes&&this.optionsController.nodes.length){let e=m.parseOptionsFromSlot(this.optionsController.nodes);e.length&&(this.options=[...e],this._options=[...e],this._optionsFromSlot=!0,this._lastSlotGeneration=this.optionsController.generation)}}willUpdate(e){if(this._optionsFromSlot&&this.optionsController){let e=this.optionsController.generation;if(e!==this._lastSlotGeneration){this._lastSlotGeneration=e;let t=m.parseOptionsFromSlot(this.optionsController.nodes);this.options=[...this._options.filter(e=>e.userAdded),...t]}}super.willUpdate(e)}disconnectedCallback(){super.disconnectedCallback(),document?.body.removeEventListener(`click`,this.handleBodyClick)}firstUpdated(e){this.defaultValue!==null&&!this.value&&(this.value=this.defaultValue),super.firstUpdated(e)}updated(e){e.has(`isOpen`)&&(this._isOptionsOpen=this.isOpen);let t=e.has(`value`),n=e.has(`_value`);if(t&&this._internalValueSync)this._internalValueSync=!1,n&&this.syncValueAndDispatch(e.get(`_value`));else if(t){let e=[...this._value],t=this.parseValue();t.join(`,`)!==this._value.join(`,`)&&(this._value=t),this.updateMaxReached(),this.syncValueAndDispatch(e)}else n&&this.syncValueAndDispatch(e.get(`_value`));if(e.has(`defaultOptions`)&&this.defaultOptions.length&&(this.options=[...(Array.isArray(this.options)?this.options:[]).filter(e=>e.userAdded)||[],...JSON.parse(JSON.stringify(this.defaultOptions))],this._options=Array.isArray(this.options)?[...this.options]:[]),e.has(`options`)){let t=e.get(`options`)||this._options||[],n=h.mergeWithUserAdded(this.options,t);this._options=n,n.length>this.options.length&&(this.options=n);let r=h.syncOptionsWithValues(this._options,this._value);if(this._options=r.options,r.newValues.length>this._value.length){let e=[...this._value];this._value=r.newValues,this.syncValueAndDispatch(e)}}if(e.has(`_search`)&&this.dispatchEvent(new CustomEvent(`search`,{detail:this._search,bubbles:!1})),!this._isOptionsOpen&&!this.multiple&&this._hasTextInput&&this.inputRef.value&&this.inputRef.value.type!==`hidden`){let e=this._value[0]?f(this._value[0],this.options,this.displayValueAs):``;this.inputRef.value.value!==e&&(this.inputRef.value.value=e)}super.updated(e)}formResetCallback(){this.touched=!1,this.value=this.defaultValue||(this.multiple,``),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=Array.isArray(this.options)?[...this.options]:[];let e=h.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.d`
|
|
1
|
+
const e=require(`./element-DjtxO-1r.cjs`),t=require(`./class-map-CJ-msbHs.cjs`),n=require(`./element-with-slot-CWoTGA1B.cjs`);require(`./icon-Dr8sfT2X.cjs`);const r=require(`./if-defined-XKOD_t_V.cjs`),i=require(`./ref-BaJ0mBT_.cjs`);require(`./tag-DWtajZk6.cjs`);const a=require(`./repeat-DaDFvx86.cjs`),o=require(`./listbox-CcThiNBY.cjs`),s=require(`./input-element-D0egtEnr.cjs`),c=require(`./pkt-options-controller-CeAQ-D-i.cjs`);require(`./input-wrapper-BJfspAt7.cjs`);var l=(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}},u=(e,t,n,r,i)=>{if(!e)return{action:`none`,value:null};let a=o.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}},d=(e,t,n,r,i)=>e.trim().toLowerCase()?{...o.s(e,t,n,r),shouldRemoveValue:!1,shouldResetInput:!1}:{addValueText:null,userInfoMessage:``,shouldRemoveValue:!i&&!!t[0],shouldResetInput:!0},f=(e,t,n)=>{let r=o.i(t,e);return n===`label`&&r?.label?r.label:e},p={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)}},m={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=o.r(n),t.push(n)}),t}},h={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=o.r(e),e.selected=e.selected||n.includes(e.value)}),{options:e,newValues:n}},mergeWithUserAdded(e,t){return[...t.filter(e=>e?.userAdded&&e.selected).filter(t=>!(Array.isArray(e)?e:[]).some(e=>e.value===t.value)),...e]}},g={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`},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:{type:`string`,name:`Utvidet hjelpetekst`,description:`Hjelpetekst som vises i en lukket boks man kan åpne`,category:`contents`},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:{type:`boolean`,name:`Feil`,description:`Feltet har en feil`,category:`ui`},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:{type:`boolean`,name:`Påkrevd-merking`,description:`Viser en merking som indikerer at feltet er påkrevd`,category:`ui`},requiredText:{type:`string`,name:`Påkrevd-tekst`,description:`Tekst som vises i påkrevd-merkingen`,category:`contents`},optionalTag:{type:`boolean`,name:`Valgfritt-merking`,description:`Viser en merking som indikerer at feltet er valgfritt`,category:`ui`},optionalText:{type:`string`,name:`Valgfritt-tekst`,description:`Tekst som vises i valgfritt-merkingen`,category:`contents`},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`}},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`}}},_=class extends s.t{constructor(){super(),this.value=``,this.options=[],this.defaultOptions=[],this.allowUserInput=!1,this.typeahead=!1,this.includeSearch=!1,this.searchPlaceholder=``,this.multiple=!1,this.maxlength=null,this.displayValueAs=g.props.displayValueAs.default,this.tagPlacement=null,this.isOpen=!1,this._options=[],this._value=[],this._isOptionsOpen=!1,this._userInfoMessage=``,this._addValueText=null,this._maxIsReached=!1,this._search=``,this._inputFocus=!1,this._internalValueSync=!1,this._optionsFromSlot=!1,this._lastSlotGeneration=0,this._suppressNextOpen=!1,this.inputRef=i.t(),this.triggerRef=i.t(),this.listboxRef=i.t(),this.optionsController=new c.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()}parseValue(){return Array.isArray(this.value)?this.multiple?this.value:this.value.length>0?[this.value[0]]:[]:this.value&&this.multiple?this.value.split(`,`):this.value?[this.value]:[]}updateMaxReached(){this._maxIsReached=o.c(this._value.length,this.maxlength)}syncValueAndDispatch(e){let t=this._value,n=this.multiple?t.join(`,`):t[0]||``;if(n!==(Array.isArray(this.value)?this.value.join(`,`):String(this.value||``))&&(this._internalValueSync=!0,this.value=n),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.r([e.s({type:String,reflect:!0})],_.prototype,`value`,void 0),e.r([e.s({type:Array})],_.prototype,`options`,void 0),e.r([e.s({type:Array,attribute:`default-options`})],_.prototype,`defaultOptions`,void 0),e.r([e.s({type:Boolean,attribute:`allow-user-input`})],_.prototype,`allowUserInput`,void 0),e.r([e.s({type:Boolean})],_.prototype,`typeahead`,void 0),e.r([e.s({type:Boolean,attribute:`include-search`})],_.prototype,`includeSearch`,void 0),e.r([e.s({type:String,attribute:`search-placeholder`})],_.prototype,`searchPlaceholder`,void 0),e.r([e.s({type:Boolean})],_.prototype,`multiple`,void 0),e.r([e.s({type:Number})],_.prototype,`maxlength`,void 0),e.r([e.s({type:String,attribute:`display-value-as`})],_.prototype,`displayValueAs`,void 0),e.r([e.s({type:String,attribute:`tag-placement`})],_.prototype,`tagPlacement`,void 0),e.r([e.s({type:Boolean,attribute:`open`})],_.prototype,`isOpen`,void 0),e.r([e.o()],_.prototype,`_options`,void 0),e.r([e.o()],_.prototype,`_value`,void 0),e.r([e.o()],_.prototype,`_isOptionsOpen`,void 0),e.r([e.o()],_.prototype,`_userInfoMessage`,void 0),e.r([e.o()],_.prototype,`_addValueText`,void 0),e.r([e.o()],_.prototype,`_maxIsReached`,void 0),e.r([e.o()],_.prototype,`_search`,void 0),e.r([e.o()],_.prototype,`_inputFocus`,void 0);var v=class extends _{toggleValue(e){if(this.disabled)return;this.touched=!0,this._userInfoMessage=``,this._addValueText=null;let t=o.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(),s=!this.multiple,c=this.multiple,l=o.c(this._value.length,this.maxlength),u=!1,d=!0,f=``,p=``;i||(!r&&this.allowUserInput&&!a?(this.addNewUserValue(e),f=`Ny verdi lagt til`,u=c):!r&&!this.allowUserInput?(s&&this._value[0]&&this.removeValue(this._value[0]),d=!1,u=!0,f=`Ingen treff i søket`):n?(this.removeValue(t),u=!0,s&&this._hasTextInput&&this.inputRef.value&&this.inputRef.value.type!==`hidden`&&(this.inputRef.value.value=``)):a&&s?(this.removeAllSelected(),u=!0):s?(this._value[0]&&this.removeSelected(this._value[0]),this.setSelected(t),u=!1):c&&!l?(this.setSelected(t),u=!0):c&&l?(f=`Maks antall valg nådd`,d=!1,p=e):(s&&this.removeAllSelected(),f=`Ingen gyldig verdi valgt`,d=!1,u=!0,p=e),this._isOptionsOpen=u,u||(s&&this._hasTextInput&&(this._suppressNextOpen=!0),window.setTimeout(()=>{this.focusTrigger()},0)),this._userInfoMessage=f,this._search=p||``,this.resetComboboxInput(d),c&&this.updateMaxReached())}setSelected(e){if(!this._value.includes(e)){if(this.multiple&&o.c(this._value.length,this.maxlength)){this._userInfoMessage=`Maks antall valg nådd`;return}!this.multiple&&this.removeAllSelected(),this._value=e?[...this._value,e]:this._value,p.markOptionSelected(this._options,e),this.resetComboboxInput(!0)}}removeSelected(e){if(!e)return;this._value=this._value.filter(t=>t!==e);let t=o.i(this.options,e);t&&(p.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=`For mange valgt`;return}this._value=this._options.map(e=>e.value),p.markAllSelected(this._options),this.requestUpdate()}}removeAllSelected(){this._value=[],p.markAllDeselected(this._options),this._options=p.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=`Verdien er allerede valgt`;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(!o.i(this.options,e)){if(o.c(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,this._hasTextInput&&(this._suppressNextOpen=!0),window.setTimeout(()=>{this.focusTrigger()},0)),this.requestUpdate()}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]?f(this._value[0],this.options,this.displayValueAs):``,this._userInfoMessage=``)),this._options=[...this.options]}removeLastValue(e){if(this._value.length===0)return;e.preventDefault();let t=this._value[this._value.length-1];t&&this.removeSelected(t),this.updateMaxReached()}},y=class extends v{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}=o.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._options=[...this.options]}handleFocus(){if(!this.disabled){if(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=f(this._value[0],this.options,this.displayValueAs)),this._inputFocus=!0,this._search=``,this._options=[...this.options],this._isOptionsOpen=!0,this.onFocus(),this.requestUpdate()}}handleFocusOut(e){if(this.disabled||!this._isOptionsOpen)return;let t=e.relatedTarget;t?.closest(`pkt-combobox`)?.id===this.id||e.target?.getAttribute(`data-focusfix`)===this.id||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=o.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}=u(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);break}}!this.multiple&&this._value[0]?this.inputRef.value.value=f(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]));break}}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=l(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;break}}}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();break}}checkForMatches(){let e=d(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}},b=class extends y{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&&(this.options=[...this.options?.filter(e=>e.userAdded)||[],...JSON.parse(JSON.stringify(this.defaultOptions))],this._options=Array.isArray(this.options)?[...this.options]:[]),this.optionsController?.nodes&&this.optionsController.nodes.length){let e=m.parseOptionsFromSlot(this.optionsController.nodes);e.length&&(this.options=[...e],this._options=[...e],this._optionsFromSlot=!0,this._lastSlotGeneration=this.optionsController.generation)}}willUpdate(e){if(this._optionsFromSlot&&this.optionsController){let e=this.optionsController.generation;if(e!==this._lastSlotGeneration){this._lastSlotGeneration=e;let t=m.parseOptionsFromSlot(this.optionsController.nodes);this.options=[...this._options.filter(e=>e.userAdded),...t]}}super.willUpdate(e)}disconnectedCallback(){super.disconnectedCallback(),document?.body.removeEventListener(`click`,this.handleBodyClick)}firstUpdated(e){this.defaultValue!==null&&!this.value&&(this.value=this.defaultValue),super.firstUpdated(e)}updated(e){e.has(`isOpen`)&&(this._isOptionsOpen=this.isOpen);let t=e.has(`value`),n=e.has(`_value`);if(t&&this._internalValueSync)this._internalValueSync=!1,n&&this.syncValueAndDispatch(e.get(`_value`));else if(t){let e=[...this._value],t=this.parseValue();t.join(`,`)!==this._value.join(`,`)&&(this._value=t),this.updateMaxReached(),this.syncValueAndDispatch(e)}else n&&this.syncValueAndDispatch(e.get(`_value`));if(e.has(`defaultOptions`)&&this.defaultOptions.length&&(this.options=[...(Array.isArray(this.options)?this.options:[]).filter(e=>e.userAdded)||[],...JSON.parse(JSON.stringify(this.defaultOptions))],this._options=Array.isArray(this.options)?[...this.options]:[]),e.has(`options`)){let t=e.get(`options`)||this._options||[],n=h.mergeWithUserAdded(this.options,t);this._options=n,n.length>this.options.length&&(this.options=n);let r=h.syncOptionsWithValues(this._options,this._value);if(this._options=r.options,r.newValues.length>this._value.length){let e=[...this._value];this._value=r.newValues,this.syncValueAndDispatch(e)}}if(e.has(`_search`)&&this.dispatchEvent(new CustomEvent(`search`,{detail:this._search,bubbles:!1})),!this._isOptionsOpen&&!this.multiple&&this._hasTextInput&&this.inputRef.value&&this.inputRef.value.type!==`hidden`){let e=this._value[0]?f(this._value[0],this.options,this.displayValueAs):``;this.inputRef.value.value!==e&&(this.inputRef.value.value=e)}super.updated(e)}formResetCallback(){this.touched=!1,this.value=this.defaultValue||(this.multiple,``),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=Array.isArray(this.options)?[...this.options]:[];let e=h.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.d`
|
|
2
2
|
<pkt-input-wrapper
|
|
3
3
|
.label=${this.label}
|
|
4
4
|
.helptext=${this.helptext}
|
|
@@ -7,9 +7,9 @@ import { n as l, t as u } from "./ref-RS8Uv6uC.js";
|
|
|
7
7
|
import "./tag-hl59gziI.js";
|
|
8
8
|
import { t as d } from "./repeat-DV1O43YU.js";
|
|
9
9
|
import { a as f, c as p, i as m, o as h, r as g, s as _ } from "./listbox-0NHJvNjz.js";
|
|
10
|
-
import { t as v } from "./input-element-
|
|
11
|
-
import { t as y } from "./pkt-options-controller-
|
|
12
|
-
import "./input-wrapper-
|
|
10
|
+
import { t as v } from "./input-element-B1ciW1N2.js";
|
|
11
|
+
import { t as y } from "./pkt-options-controller-CCB15L_G.js";
|
|
12
|
+
import "./input-wrapper-CGSrvrlb.js";
|
|
13
13
|
//#region ../../shared-utils/combobox/input-utils.ts
|
|
14
14
|
var b = (e, t, n) => {
|
|
15
15
|
switch (e) {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { PktElement } from '../../base-elements/element';
|
|
2
|
+
import { PropertyValues, TemplateResult } from 'lit';
|
|
3
|
+
import { Booleanish } from '../../shared-types';
|
|
4
|
+
import { IPktHeaderMenu, THeaderFooterApi, THeaderMenuLocale } from './types';
|
|
5
|
+
export declare class PktHeaderMenu extends PktElement<IPktHeaderMenu> implements IPktHeaderMenu {
|
|
6
|
+
dataUrl: string;
|
|
7
|
+
data?: THeaderFooterApi;
|
|
8
|
+
locale: THeaderMenuLocale;
|
|
9
|
+
open: Booleanish;
|
|
10
|
+
ariaLabelledBy: string;
|
|
11
|
+
mobileBreakpoint: number;
|
|
12
|
+
private loadState;
|
|
13
|
+
private fetchedData?;
|
|
14
|
+
private isMobile;
|
|
15
|
+
private abortController?;
|
|
16
|
+
private mediaQuery?;
|
|
17
|
+
connectedCallback(): void;
|
|
18
|
+
private updateOpenClass;
|
|
19
|
+
disconnectedCallback(): void;
|
|
20
|
+
updated(changedProperties: PropertyValues): void;
|
|
21
|
+
private setupMediaQuery;
|
|
22
|
+
private teardownMediaQuery;
|
|
23
|
+
private handleMediaChange;
|
|
24
|
+
private loadData;
|
|
25
|
+
private get effectiveData();
|
|
26
|
+
private get localeData();
|
|
27
|
+
render(): TemplateResult<1>;
|
|
28
|
+
private renderMobileAccordion;
|
|
29
|
+
private renderServicesList;
|
|
30
|
+
private renderServices;
|
|
31
|
+
private renderButtons;
|
|
32
|
+
private renderSections;
|
|
33
|
+
private renderSectionList;
|
|
34
|
+
private renderFooter;
|
|
35
|
+
private renderSocialLink;
|
|
36
|
+
}
|
|
37
|
+
declare global {
|
|
38
|
+
interface HTMLElementTagNameMap {
|
|
39
|
+
'pkt-header-menu': PktHeaderMenu;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { IHeaderMenuLink, IHeaderMenuIconLink, IHeaderMenuButton, IHeaderMenuServices, IHeaderMenuSection, IMegaMenu, IHeaderFooter, IHeaderFooterLocaleData, IPktHeaderMenu as ISharedPktHeaderMenu, THeaderFooterApi, THeaderMenuLocale } from '../../shared-types/header-menu';
|
|
2
|
+
import { Booleanish } from '../../shared-types';
|
|
3
|
+
export type { IHeaderMenuLink, IHeaderMenuIconLink, IHeaderMenuButton, IHeaderMenuServices, IHeaderMenuSection, IMegaMenu, IHeaderFooter, IHeaderFooterLocaleData, THeaderFooterApi, THeaderMenuLocale, };
|
|
4
|
+
export interface IPktHeaderMenu extends Omit<ISharedPktHeaderMenu, 'open'> {
|
|
5
|
+
open?: Booleanish;
|
|
6
|
+
}
|
|
@@ -12,6 +12,7 @@ export { PktFileUpload } from './fileupload';
|
|
|
12
12
|
export { PktDateTags } from './datepicker/date-tags.js';
|
|
13
13
|
export { PktDatepicker } from './datepicker/datepicker.js';
|
|
14
14
|
export { PktHeader, PktHeaderService, PktHeaderUserMenu } from './header';
|
|
15
|
+
export { PktHeaderMenu } from './header-menu';
|
|
15
16
|
export { PktHelptext } from './helptext';
|
|
16
17
|
export { PktHeading } from './heading';
|
|
17
18
|
export { PktIcon } from './icon';
|
|
@@ -33,6 +34,7 @@ export { PktTimepicker } from './timepicker';
|
|
|
33
34
|
export type { IPktAccordion, IPktAccordionItem, TPktAccordionSkin } from './accordion';
|
|
34
35
|
export type { IPktButton, TPktButtonMode, TPktButtonSize, TPktButtonColor, TPktButtonSkin, TPktButtonVariant, TPktButtonState, TPktButtonType, } from './button';
|
|
35
36
|
export type { User as IPktHeaderUser, Representing as IPktHeaderRepresenting, UserMenuItem as IPktHeaderUserMenuItem, THeaderMenu, TLogOutButtonPlacement as TPktHeaderLogOutButtonPlacement, THeaderPosition, THeaderScrollBehavior, TSlotMenuVariant, IPktHeader, } from './header';
|
|
37
|
+
export type { IPktHeaderMenu } from './header-menu';
|
|
36
38
|
export type { IPktProgressbar, TProgressbarRole, TProgressbarSkin, TProgressbarStatusPlacement, TProgressbarStatusType, TProgressbarTitlePosition, } from './progressbar';
|
|
37
39
|
export type { IPktCombobox, IPktComboboxOption, TPktComboboxTagPlacement, } from './combobox';
|
|
38
40
|
export type { IPktHeading, TPktHeadingSize, TPktHeadingLevel } from './heading';
|
|
@@ -9,8 +9,8 @@ import "./calendar-Ch1dgnBo.js";
|
|
|
9
9
|
import "./tag-hl59gziI.js";
|
|
10
10
|
import { t as C } from "./repeat-DV1O43YU.js";
|
|
11
11
|
import { n as w, t as T } from "./utils-BOOZ0ppt.js";
|
|
12
|
-
import { t as E } from "./input-element-
|
|
13
|
-
import "./input-wrapper-
|
|
12
|
+
import { t as E } from "./input-element-B1ciW1N2.js";
|
|
13
|
+
import "./input-wrapper-CGSrvrlb.js";
|
|
14
14
|
//#region ../../shared-types/datepicker.ts
|
|
15
15
|
var D = { calendar: { buttonAltText: "Åpne kalender" } }, O = {
|
|
16
16
|
calendar: { buttonAltText: "Åpne kalender" },
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const e=require(`./element-DjtxO-1r.cjs`),t=require(`./class-map-CJ-msbHs.cjs`),n=require(`./element-with-slot-CWoTGA1B.cjs`);require(`./icon-Dr8sfT2X.cjs`);const r=require(`./if-defined-XKOD_t_V.cjs`),i=require(`./ref-BaJ0mBT_.cjs`),a=require(`./converters-Bffq_YDm.cjs`);require(`./calendar-DkjXla0I.cjs`),require(`./tag-DWtajZk6.cjs`);const o=require(`./repeat-DaDFvx86.cjs`),s=require(`./utils-CM67Oudc.cjs`),c=require(`./input-element-
|
|
1
|
+
const e=require(`./element-DjtxO-1r.cjs`),t=require(`./class-map-CJ-msbHs.cjs`),n=require(`./element-with-slot-CWoTGA1B.cjs`);require(`./icon-Dr8sfT2X.cjs`);const r=require(`./if-defined-XKOD_t_V.cjs`),i=require(`./ref-BaJ0mBT_.cjs`),a=require(`./converters-Bffq_YDm.cjs`);require(`./calendar-DkjXla0I.cjs`),require(`./tag-DWtajZk6.cjs`);const o=require(`./repeat-DaDFvx86.cjs`),s=require(`./utils-CM67Oudc.cjs`),c=require(`./input-element-D0egtEnr.cjs`);require(`./input-wrapper-BJfspAt7.cjs`);var l={calendar:{buttonAltText:`Åpne kalender`}},u={calendar:{buttonAltText:`Åpne kalender`},generic:{from:`Fra`,to:`Til`}},d=class extends e.t{constructor(...e){super(...e),this.dates=[],this.dateformat=`dd.MM.yyyy`,this.className=`pkt-datepicker__tags`,this.idBase=s.n()}render(){return this.classes={"pkt-date-tags":!0,[this.className]:!0},e.d`
|
|
2
2
|
<div class=${t.t(this.classes)} aria-live="polite">
|
|
3
3
|
${Array.isArray(this.dates)&&this.dates[0]?o.t(a.h((this.dates??[]).filter(Boolean)),e=>e,t=>e.d` <pkt-tag
|
|
4
4
|
id=${this.idBase+t+`-tag`}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import { PropertyValues } from 'lit';
|
|
1
2
|
import { PktElement } from '../../base-elements/element';
|
|
2
3
|
export declare class HeaderFull extends PktElement {
|
|
3
4
|
private isDarkMode;
|
|
4
5
|
private searchValue;
|
|
5
6
|
private openedMenu;
|
|
7
|
+
private isMegamenuOpen;
|
|
8
|
+
private previousActiveElement;
|
|
9
|
+
private headerResizeObserver?;
|
|
10
|
+
private observedHeaderEl?;
|
|
6
11
|
private user;
|
|
7
12
|
private representing;
|
|
8
13
|
private userMenu;
|
|
@@ -14,6 +19,14 @@ export declare class HeaderFull extends PktElement {
|
|
|
14
19
|
private handleLogoClick;
|
|
15
20
|
private toggleDarkMode;
|
|
16
21
|
private openModal;
|
|
22
|
+
connectedCallback(): void;
|
|
23
|
+
disconnectedCallback(): void;
|
|
24
|
+
updated(changedProperties: PropertyValues): void;
|
|
25
|
+
private setupHeaderResizeObserver;
|
|
26
|
+
private teardownHeaderResizeObserver;
|
|
27
|
+
private handleDocumentKeydown;
|
|
28
|
+
private toggleMegamenu;
|
|
29
|
+
private handleOverlayClick;
|
|
17
30
|
render(): import('lit-html').TemplateResult<1>;
|
|
18
31
|
}
|
|
19
32
|
declare global {
|
|
@@ -5,9 +5,9 @@ import "./icon-Co72KtgF.js";
|
|
|
5
5
|
import { t as s } from "./if-defined-Cjj8qN-Z.js";
|
|
6
6
|
import { t as c } from "./converters-jauYkvNh.js";
|
|
7
7
|
import { n as l } from "./utils-BOOZ0ppt.js";
|
|
8
|
-
import "./input-wrapper-
|
|
9
|
-
import "./modal-
|
|
10
|
-
import "./progressbar-
|
|
8
|
+
import "./input-wrapper-CGSrvrlb.js";
|
|
9
|
+
import "./modal-DYc5M-Pn.js";
|
|
10
|
+
import "./progressbar-hQSIzdof.js";
|
|
11
11
|
//#region ../../shared-types/fileupload.ts
|
|
12
12
|
var u = {
|
|
13
13
|
dropZoneDragMultiple: "Dra filer hit for å laste dem opp eller",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const e=require(`./element-DjtxO-1r.cjs`),t=require(`./class-map-CJ-msbHs.cjs`);require(`./alert-BEEnTiCb.cjs`),require(`./icon-Dr8sfT2X.cjs`);const n=require(`./if-defined-XKOD_t_V.cjs`),r=require(`./converters-Bffq_YDm.cjs`),i=require(`./utils-CM67Oudc.cjs`);require(`./input-wrapper-B_XFi211.cjs`),require(`./modal-B6591sWa.cjs`),require(`./progressbar-CrwpnIkv.cjs`);var a={dropZoneDragMultiple:`Dra filer hit for å laste dem opp eller`,dropZoneDragSingle:`Dra en fil hit for å laste den opp eller`,dropZoneDragMultipleThumbnail:`Dra bilder hit for å laste dem opp eller`,dropZoneDragSingleThumbnail:`Dra et bilde hit for å laste det opp eller`,dropZoneDragActiveMultiple:`Slipp filene her`,dropZoneDragActiveSingle:`Slipp filen her`,dropZoneDragActiveMultipleThumbnail:`Slipp bildene her`,dropZoneDragActiveSingleThumbnail:`Slipp bildet her`,dropZoneOpenFileDialogMultiple:`velg filer`,dropZoneOpenFileDialogSingle:`velg en fil`,dropZoneOpenFileDialogMultipleThumbnail:`velg fra kamerarull`,dropZoneOpenFileDialogSingleThumbnail:`velg fra kamerarull`,supportedFormatsPrefix:`Format:`,invalidFormatDefault:e=>`Ugyldig filtype. Tillatte formater: ${e}`,sizeTooLargeDefault:e=>`Filen er for stor. Maks størrelse er ${e}.`,requiredMissing:`Du må laste opp minst én fil.`,genericValidationRejection:`Filen ble avvist av validering.`,unknownFilename:`Ukjent fil`,fileLabel:e=>e===1?`fil`:`filer`,srFileAdded:e=>`Filen «${e}» er lagt til`,srFilesAdded:e=>`${e} filer er lagt til`,srFilesUploadedOfTotal:(e,t,n)=>`${e} av ${t} ${n} lastet opp`,srFilesFailedOfTotal:(e,t,n)=>`Feil ved opplasting: ${e} av ${t} ${n} feilet`};function o(e){if(e==null||e===``)return;if(typeof e==`number`)return Number.isFinite(e)&&e>0?e:void 0;let t=String(e).trim(),n=Number(t);if(!Number.isNaN(n)&&n>0)return n;let r=t.match(/^(\d+(?:\.\d+)?)\s*(B|KB|MB|GB)$/i);if(!r){console.warn(`PktFileUpload: Invalid maxFileSize format "${t}". Use format like "5MB", "500KB", "1GB", or bytes.`);return}let i=parseFloat(r[1]);switch(r[2].toUpperCase()){case`B`:return i;case`KB`:return i*1024;case`MB`:return i*1024*1024;case`GB`:return i*1024*1024*1024;default:return}}function s(e){return e<1024?`${Math.round(e)} B`:e<1024*1024?`${Math.round(e/1024)} KB`:e<1024*1024*1024?`${Math.round(e/(1024*1024))} MB`:`${Math.round(e/(1024*1024*1024))} GB`}function c(e){return Array.isArray(e)?e.map(e=>String(e).trim().toLowerCase()).filter(Boolean):[]}function l(e){return e?e.split(`,`).map(e=>e.trim().toLowerCase()).filter(Boolean):[]}function u(e,t,n){let r=e.toLowerCase().replace(/^\./,``);if(r.includes(`/`)){if(r.endsWith(`/*`)){let e=r.replace(`/*`,``);return n.startsWith(`${e}/`)}return n===r}return t===r}function d(e,t){let n=c(t);if(n.length===0)return!0;let r=e.name.split(`.`).pop()?.toLowerCase()??``,i=e.type.toLowerCase();return n.some(e=>u(e,r,i))}function f(e,t){let n=(e??``).trim();if(n)return n;let r=c(t);return r.length===0?``:r.map(e=>e.includes(`/`)||e.startsWith(`.`)?e:`.${e}`).join(`, `)}function p(e){return e.includes(`/`)?e:e.replace(/^\./,``).toUpperCase()}function m(e,t){let n=c(e);if(n.length>0)return n.map(p).join(`, `);let r=l(t);return r.length>0?r.map(p).join(`, `):``}function h(e,t,n){return((e??``).trim()||t).replace(/\{(\w+)\}/g,(e,t)=>n[t]??`{${t}}`)}function g(e,t){let n=c(t.allowedFormats);if(n.length>0&&!d(e,n)){let e=n.join(`, `),r=`Ugyldig filtype. Tillatte formater: ${e}`;return h(t.formatErrorMessage,r,{formats:e})}let r=o(t.maxFileSize);if(r!==void 0&&e.size>r){let e=s(r),n=`Filen er for stor. Maks størrelse er ${e}.`;return h(t.sizeErrorMessage,n,{maxSize:e})}if(t.onFileValidation){let n=t.onFileValidation(e);if(n)return n}return null}function _(e){let t=e.file;if(t?.type?.startsWith(`image/`))return!0;let n=e.attributes?.targetFilename||t?.name||``;return/\.(jpe?g|png|gif|webp|heic|heif|bmp|svg)$/i.test(n)}function v(e){return typeof e==`number`?`in-progress`:e===`error`?`error`:`idle`}function y(e,t,n){let r={"in-progress":0,error:1,idle:2};return e.map(e=>{let r=t?.find(t=>t.fileId===e.fileId);return{...e,progress:r?.progress??(n===`form`?`done`:`queued`),errorMessage:r?.errorMessage,showProgress:r?.showProgress,lastProgress:r?.lastProgress}}).sort((e,t)=>r[v(e.progress)]-r[v(t.progress)])}function b(e){if(!e)return[];let t=[`a[href]:not([tabindex="-1"])`,`button:not([disabled]):not([tabindex="-1"])`,`input:not([disabled]):not([type="hidden"]):not([tabindex="-1"])`,`select:not([disabled]):not([tabindex="-1"])`,`textarea:not([disabled]):not([tabindex="-1"])`,`[tabindex]:not([tabindex="-1"])`].join(`, `);return Array.from(e.querySelectorAll(t)).filter(e=>!e.hasAttribute(`inert`))}function x(e,t){if(e.key!==`Tab`)return!1;let n=b(t);if(n.length===0)return e.preventDefault(),!0;let r=n[0],i=n[n.length-1],a=(t?.ownerDocument??document).activeElement,o=!!a&&n.includes(a);return e.shiftKey?!o||a===r?(e.preventDefault(),i.focus(),!0):!1:!o||a===i?(e.preventDefault(),r.focus(),!0):!1}function S(e,t){return!t||t<=0||e.length<=t+3?null:{head:e.slice(0,e.length-t),tail:e.slice(-t)}}function C(e,t,n){return n<=0?0:t===`prev`?e<=0?n-1:e-1:e>=n-1?0:e+1}function w(e,t){let n=e.length;if(n===0||!t||t.length===0)return{totalCount:n,uploadedCount:0,failedCount:0};let r=0,i=0;for(let n of e){let e=t.find(e=>e.fileId===n.fileId);e?.progress===`done`?r++:e?.progress===`error`&&i++}return{totalCount:n,uploadedCount:r,failedCount:i}}function T(e,t=a.unknownFilename){return e.attributes?.targetFilename||e.file?.name||t}var E=class extends e.t{constructor(...e){super(...e),this.id=`pkt-fileupload-${i.n()}`,this.name=`files`,this.label=``,this.helptext=``,this.required=!1,this.multiple=!1,this.disabled=!1,this.fullwidth=!1,this.uploadStrategy=`form`,this.itemRenderer=`filename`,this.accept=``,this.allowedFormats=[],this.formatErrorMessage=``,this.sizeErrorMessage=``,this.transfers=[],this.addCommentsEnabled=!1,this.renameFilesEnabled=!1,this.extraOperations=[],this.enableImagePreview=!1,this.hasError=!1,this.errorMessage=``,this.optionalTag=!1,this.requiredTag=!1,this.truncateTail=4,this.files=[],this.isDragActive=!1,this.validationErrorMessage=null,this.addedAnnouncement=``,this.thumbnailUrls={},this.hasInitializedValue=!1,this.hasWarnedInvalidValueCombo=!1,this.thumbnailFileById=new Map,this.connectedForm=null,this.addedAnnouncementTimer=null,this.requiredSelectionMessage=a.requiredMissing,this.onNativeFileChange=e=>{let t=e.target;this.addFiles(t.files?Array.from(t.files):[]),this.uploadStrategy===`custom`&&(t.value=``)},this.openFileDialog=e=>{e.preventDefault(),e.stopPropagation(),!this.disabled&&this.querySelector(`#${this.id}-input`)?.click()},this.onDropZoneClick=e=>{this.disabled||e.target.closest(`.pkt-fileupload__drop-zone__placeholder__title__open-file-dialog`)||this.querySelector(`#${this.id}-input`)?.click()},this.onDragOver=e=>{e.preventDefault(),!this.disabled&&(this.isDragActive=!0)},this.onDragLeave=()=>{this.isDragActive=!1},this.onDrop=e=>{if(e.preventDefault(),this.isDragActive=!1,this.disabled)return;let t=e.dataTransfer?.files?Array.from(e.dataTransfer.files):[];this.addFiles(t)},this.onHostFormSubmit=e=>{!this.required||this.uploadStrategy!==`custom`||this.getCurrentFiles().length>0||(this.validationErrorMessage=this.requiredSelectionMessage,e.preventDefault())}}get isControlled(){return this.value!==void 0}get hasEffectiveError(){return!!this.validationErrorMessage||this.hasError||!!this.errorMessage.trim()}get effectiveErrorMessage(){return this.validationErrorMessage??this.errorMessage??``}get hasValidationError(){return!!this.validationErrorMessage}firstUpdated(e){super.firstUpdated?.(e),this.hasInitializedValue||=(this.files=this.value??this.defaultValue??[],this.syncThumbnailUrls(this.files),!0),this.value!==void 0&&this.defaultValue!==void 0&&this.warnInvalidValueCombo()}willUpdate(e){super.willUpdate(e),this.hasInitializedValue&&this.isControlled&&(e.has(`value`)||e.has(`itemRenderer`)||e.has(`enableImagePreview`))&&(this.files=this.value??[],this.syncThumbnailUrls(this.files))}updated(e){super.updated(e),(e.has(`uploadStrategy`)||e.has(`required`)||e.has(`value`))&&this.syncFormSubmitListener(),this.uploadStrategy===`form`&&(e.has(`value`)||e.has(`files`)||e.has(`uploadStrategy`))&&this.syncNativeInputFiles()}syncNativeInputFiles(){let e=this.querySelector(`#${this.id}-input`);if(!(!e||typeof DataTransfer>`u`))try{let t=new DataTransfer;for(let e of this.getCurrentFiles())e.file&&t.items.add(e.file);e.files=t.files}catch{}}warnInvalidValueCombo(){this.hasWarnedInvalidValueCombo||=(console.warn(`PktFileUpload: Både value og defaultValue er angitt. Komponenten kan være enten kontrollert eller ukontrollert, ikke begge. value vil bli prioritert.`),!0)}disconnectedCallback(){this.teardownFormSubmitListener(),this.addedAnnouncementTimer&&=(clearTimeout(this.addedAnnouncementTimer),null),super.disconnectedCallback(),this.revokeAllThumbnailUrls()}setAddedAnnouncement(e){this.addedAnnouncement=e,this.addedAnnouncementTimer&&clearTimeout(this.addedAnnouncementTimer),this.addedAnnouncementTimer=setTimeout(()=>{this.addedAnnouncement=``,this.addedAnnouncementTimer=null},1500)}connectedCallback(){super.connectedCallback(),this.syncFormSubmitListener()}addFiles(e){if(e.length===0)return;let t=this.multiple?e:[e[0]];for(let e of t){let t=this.validateFile(e);if(t){this.validationErrorMessage=t;return}}this.validationErrorMessage=null;let n=t.map(e=>({fileId:i.n(),file:e,attributes:{targetFilename:e.name}}));this.setAddedAnnouncement(n.length===1?a.srFileAdded(n[0].attributes.targetFilename):a.srFilesAdded(n.length));let r=this.getCurrentFiles(),o=this.multiple?[...r,...n]:[n[0]];this.commitFiles(o,`add`,n.map(e=>e.fileId)),this.uploadStrategy===`custom`&&n.forEach(e=>{this.dispatchEvent(new CustomEvent(`file-upload-requested`,{detail:{fileId:e.fileId,file:e.file,attributes:e.attributes},bubbles:!0,composed:!0}))})}getCurrentFiles(){return this.isControlled?this.value??[]:this.files}cancelTransfer(e){if(this.disabled)return;let t=this.getCurrentFiles().find(t=>t.fileId===e);t&&(this.removeFileItem(e),this.dispatchEvent(new CustomEvent(`transfer-cancelled`,{detail:{fileId:t.fileId,file:t.file,attributes:t.attributes},bubbles:!0,composed:!0})))}removeFileItem(e){if(this.disabled)return;let t=this.getCurrentFiles(),n=t.filter(t=>t.fileId!==e);n.length!==t.length&&this.commitFiles(n,`remove`,[e])}updateFileItem(e,t){let n=this.getCurrentFiles().map(n=>n.fileId===e?{...n,...t}:n);this.commitFiles(n,`update`,[e])}commitFiles(e,t,n){this.isControlled||(this.files=e,this.syncThumbnailUrls(e)),this.validationErrorMessage===this.requiredSelectionMessage&&e.length>0&&(this.validationErrorMessage=null),this.dispatchEvent(new CustomEvent(`files-changed`,{detail:{files:e,reason:t,changedFileIds:n},bubbles:!0,composed:!0}))}getThumbnailUrl(e){return this.thumbnailUrls[e.fileId]}getTransferProgress(e){let t=this.transfers.find(t=>t.fileId===e);return t?t.progress:this.uploadStrategy===`form`?`done`:`queued`}getTransferForFile(e){return this.transfers.find(t=>t.fileId===e)}isImageFile(e){return _(e)}formatFileSize(e){return s(e)}getResolvedAcceptValue(){return f(this.accept,this.allowedFormats)}getSupportedFormatsText(){return m(this.allowedFormats,this.accept)}getSortedFilesAndTransfers(){return y(this.getCurrentFiles(),this.transfers,this.uploadStrategy)}validateFile(e){let t=g(e,{allowedFormats:this.allowedFormats,maxFileSize:this.maxFileSize,formatErrorMessage:this.formatErrorMessage,sizeErrorMessage:this.sizeErrorMessage,onFileValidation:this.onFileValidation});if(t)return t;let n={file:e,errorMessage:null},r=new CustomEvent(`file-validate`,{detail:n,bubbles:!0,composed:!0,cancelable:!0});return this.dispatchEvent(r),n.errorMessage?n.errorMessage:r.defaultPrevented?a.genericValidationRejection:null}syncThumbnailUrls(e){if(!(typeof URL<`u`&&typeof URL.createObjectURL==`function`&&typeof URL.revokeObjectURL==`function`)){this.thumbnailUrls={},this.thumbnailFileById.clear();return}let t=new Set(e.map(e=>e.fileId)),n={};for(let[e,n]of Object.entries(this.thumbnailUrls))t.has(e)||(URL.revokeObjectURL(n),this.thumbnailFileById.delete(e));for(let t of e){let e=this.thumbnailUrls[t.fileId],r=this.thumbnailFileById.get(t.fileId);if(!t.file||!this.isImageFile(t)){e&&(URL.revokeObjectURL(e),this.thumbnailFileById.delete(t.fileId));continue}if(e&&r===t.file){n[t.fileId]=e;continue}e&&r!==t.file&&URL.revokeObjectURL(e);let i=URL.createObjectURL(t.file);this.thumbnailFileById.set(t.fileId,t.file),n[t.fileId]=i}this.thumbnailUrls=n}revokeAllThumbnailUrls(){if(typeof URL>`u`||typeof URL.revokeObjectURL!=`function`){this.thumbnailUrls={},this.thumbnailFileById.clear();return}Object.values(this.thumbnailUrls).forEach(e=>URL.revokeObjectURL(e)),this.thumbnailUrls={},this.thumbnailFileById.clear()}getSrUploadedMessage(){if(this.addedAnnouncement)return this.addedAnnouncement;let{totalCount:e,uploadedCount:t}=w(this.getCurrentFiles(),this.transfers);return e===0||t===0?``:a.srFilesUploadedOfTotal(t,e,a.fileLabel(e))}getSrErrorsMessage(){let{totalCount:e,failedCount:t}=w(this.getCurrentFiles(),this.transfers);return e===0||t===0?``:a.srFilesFailedOfTotal(t,e,a.fileLabel(e))}syncFormSubmitListener(){let e=this.closest(`form`);this.connectedForm!==e&&(this.teardownFormSubmitListener(),this.connectedForm=e,this.connectedForm&&this.connectedForm.addEventListener(`submit`,this.onHostFormSubmit))}teardownFormSubmitListener(){this.connectedForm&&=(this.connectedForm.removeEventListener(`submit`,this.onHostFormSubmit),null)}};e.r([e.s({type:String})],E.prototype,`id`,void 0),e.r([e.s({type:String})],E.prototype,`name`,void 0),e.r([e.s({type:String})],E.prototype,`label`,void 0),e.r([e.s({type:String})],E.prototype,`helptext`,void 0),e.r([e.s({type:Boolean,reflect:!0})],E.prototype,`required`,void 0),e.r([e.s({type:Boolean,reflect:!0})],E.prototype,`multiple`,void 0),e.r([e.s({type:Boolean,reflect:!0})],E.prototype,`disabled`,void 0),e.r([e.s({type:Boolean,reflect:!0,attribute:`fullwidth`})],E.prototype,`fullwidth`,void 0),e.r([e.s({type:String,reflect:!0,attribute:`upload-strategy`})],E.prototype,`uploadStrategy`,void 0),e.r([e.s({type:String,reflect:!0,attribute:`item-renderer`})],E.prototype,`itemRenderer`,void 0),e.r([e.s({type:String})],E.prototype,`accept`,void 0),e.r([e.s({converter:r.t.csvToArray,attribute:`allowed-formats`})],E.prototype,`allowedFormats`,void 0),e.r([e.s({type:String,attribute:`format-error-message`})],E.prototype,`formatErrorMessage`,void 0),e.r([e.s({attribute:`max-file-size`})],E.prototype,`maxFileSize`,void 0),e.r([e.s({type:String,attribute:`size-error-message`})],E.prototype,`sizeErrorMessage`,void 0),e.r([e.s({attribute:!1})],E.prototype,`onFileValidation`,void 0),e.r([e.s({attribute:!1})],E.prototype,`transfers`,void 0),e.r([e.s({type:Boolean,attribute:`add-comments-enabled`})],E.prototype,`addCommentsEnabled`,void 0),e.r([e.s({type:Boolean,attribute:`rename-files-enabled`})],E.prototype,`renameFilesEnabled`,void 0),e.r([e.s({attribute:!1})],E.prototype,`extraOperations`,void 0),e.r([e.s({type:Boolean,reflect:!0,attribute:`enable-image-preview`})],E.prototype,`enableImagePreview`,void 0),e.r([e.s({type:Boolean,attribute:`has-error`})],E.prototype,`hasError`,void 0),e.r([e.s({type:String,attribute:`error-message`})],E.prototype,`errorMessage`,void 0),e.r([e.s({type:Boolean,attribute:`optional-tag`})],E.prototype,`optionalTag`,void 0),e.r([e.s({type:Boolean,attribute:`required-tag`})],E.prototype,`requiredTag`,void 0),e.r([e.s({type:Number,attribute:`truncate-tail`})],E.prototype,`truncateTail`,void 0),e.r([e.s({attribute:!1})],E.prototype,`value`,void 0),e.r([e.s({attribute:!1})],E.prototype,`defaultValue`,void 0),e.r([e.o()],E.prototype,`files`,void 0),e.r([e.o()],E.prototype,`isDragActive`,void 0),e.r([e.o()],E.prototype,`validationErrorMessage`,void 0),e.r([e.o()],E.prototype,`addedAnnouncement`,void 0),e.r([e.o()],E.prototype,`thumbnailUrls`,void 0);var D=`comments`,O=e=>{let t=new Date(e);return Number.isNaN(t.getTime())?e:`${String(t.getDate()).padStart(2,`0`)}.${String(t.getMonth()+1).padStart(2,`0`)}.${t.getFullYear()} kl. ${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`},k=(e,t,n)=>{e.key===`Enter`&&(e.preventDefault(),e.stopPropagation(),t()),e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),n())},A=(e,t,n)=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),n()),(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),e.stopPropagation(),t())},j=e=>({id:`remove`,title:`Slett`,ariaLabel:`Slett fil`,onClick:({file:t})=>e(t.fileId)}),M=()=>({id:`rename`,title:`Rediger`,ariaLabel:`Rediger filnavn`,renderInlineUI:t=>{let n=t.getAttribute(`targetFilename`)||t.file.attributes?.targetFilename||t.file.file?.name||``,r=`pkt-fileupload-rename-${t.file.fileId}`,i=()=>{let e=document.getElementById(r)?.value?.trim();e&&t.setAttribute(`targetFilename`,e),t.close()};return e.d`
|
|
1
|
+
const e=require(`./element-DjtxO-1r.cjs`),t=require(`./class-map-CJ-msbHs.cjs`);require(`./alert-BEEnTiCb.cjs`),require(`./icon-Dr8sfT2X.cjs`);const n=require(`./if-defined-XKOD_t_V.cjs`),r=require(`./converters-Bffq_YDm.cjs`),i=require(`./utils-CM67Oudc.cjs`);require(`./input-wrapper-BJfspAt7.cjs`),require(`./modal-J5uWdD1M.cjs`),require(`./progressbar-8RYeaOQe.cjs`);var a={dropZoneDragMultiple:`Dra filer hit for å laste dem opp eller`,dropZoneDragSingle:`Dra en fil hit for å laste den opp eller`,dropZoneDragMultipleThumbnail:`Dra bilder hit for å laste dem opp eller`,dropZoneDragSingleThumbnail:`Dra et bilde hit for å laste det opp eller`,dropZoneDragActiveMultiple:`Slipp filene her`,dropZoneDragActiveSingle:`Slipp filen her`,dropZoneDragActiveMultipleThumbnail:`Slipp bildene her`,dropZoneDragActiveSingleThumbnail:`Slipp bildet her`,dropZoneOpenFileDialogMultiple:`velg filer`,dropZoneOpenFileDialogSingle:`velg en fil`,dropZoneOpenFileDialogMultipleThumbnail:`velg fra kamerarull`,dropZoneOpenFileDialogSingleThumbnail:`velg fra kamerarull`,supportedFormatsPrefix:`Format:`,invalidFormatDefault:e=>`Ugyldig filtype. Tillatte formater: ${e}`,sizeTooLargeDefault:e=>`Filen er for stor. Maks størrelse er ${e}.`,requiredMissing:`Du må laste opp minst én fil.`,genericValidationRejection:`Filen ble avvist av validering.`,unknownFilename:`Ukjent fil`,fileLabel:e=>e===1?`fil`:`filer`,srFileAdded:e=>`Filen «${e}» er lagt til`,srFilesAdded:e=>`${e} filer er lagt til`,srFilesUploadedOfTotal:(e,t,n)=>`${e} av ${t} ${n} lastet opp`,srFilesFailedOfTotal:(e,t,n)=>`Feil ved opplasting: ${e} av ${t} ${n} feilet`};function o(e){if(e==null||e===``)return;if(typeof e==`number`)return Number.isFinite(e)&&e>0?e:void 0;let t=String(e).trim(),n=Number(t);if(!Number.isNaN(n)&&n>0)return n;let r=t.match(/^(\d+(?:\.\d+)?)\s*(B|KB|MB|GB)$/i);if(!r){console.warn(`PktFileUpload: Invalid maxFileSize format "${t}". Use format like "5MB", "500KB", "1GB", or bytes.`);return}let i=parseFloat(r[1]);switch(r[2].toUpperCase()){case`B`:return i;case`KB`:return i*1024;case`MB`:return i*1024*1024;case`GB`:return i*1024*1024*1024;default:return}}function s(e){return e<1024?`${Math.round(e)} B`:e<1024*1024?`${Math.round(e/1024)} KB`:e<1024*1024*1024?`${Math.round(e/(1024*1024))} MB`:`${Math.round(e/(1024*1024*1024))} GB`}function c(e){return Array.isArray(e)?e.map(e=>String(e).trim().toLowerCase()).filter(Boolean):[]}function l(e){return e?e.split(`,`).map(e=>e.trim().toLowerCase()).filter(Boolean):[]}function u(e,t,n){let r=e.toLowerCase().replace(/^\./,``);if(r.includes(`/`)){if(r.endsWith(`/*`)){let e=r.replace(`/*`,``);return n.startsWith(`${e}/`)}return n===r}return t===r}function d(e,t){let n=c(t);if(n.length===0)return!0;let r=e.name.split(`.`).pop()?.toLowerCase()??``,i=e.type.toLowerCase();return n.some(e=>u(e,r,i))}function f(e,t){let n=(e??``).trim();if(n)return n;let r=c(t);return r.length===0?``:r.map(e=>e.includes(`/`)||e.startsWith(`.`)?e:`.${e}`).join(`, `)}function p(e){return e.includes(`/`)?e:e.replace(/^\./,``).toUpperCase()}function m(e,t){let n=c(e);if(n.length>0)return n.map(p).join(`, `);let r=l(t);return r.length>0?r.map(p).join(`, `):``}function h(e,t,n){return((e??``).trim()||t).replace(/\{(\w+)\}/g,(e,t)=>n[t]??`{${t}}`)}function g(e,t){let n=c(t.allowedFormats);if(n.length>0&&!d(e,n)){let e=n.join(`, `),r=`Ugyldig filtype. Tillatte formater: ${e}`;return h(t.formatErrorMessage,r,{formats:e})}let r=o(t.maxFileSize);if(r!==void 0&&e.size>r){let e=s(r),n=`Filen er for stor. Maks størrelse er ${e}.`;return h(t.sizeErrorMessage,n,{maxSize:e})}if(t.onFileValidation){let n=t.onFileValidation(e);if(n)return n}return null}function _(e){let t=e.file;if(t?.type?.startsWith(`image/`))return!0;let n=e.attributes?.targetFilename||t?.name||``;return/\.(jpe?g|png|gif|webp|heic|heif|bmp|svg)$/i.test(n)}function v(e){return typeof e==`number`?`in-progress`:e===`error`?`error`:`idle`}function y(e,t,n){let r={"in-progress":0,error:1,idle:2};return e.map(e=>{let r=t?.find(t=>t.fileId===e.fileId);return{...e,progress:r?.progress??(n===`form`?`done`:`queued`),errorMessage:r?.errorMessage,showProgress:r?.showProgress,lastProgress:r?.lastProgress}}).sort((e,t)=>r[v(e.progress)]-r[v(t.progress)])}function b(e){if(!e)return[];let t=[`a[href]:not([tabindex="-1"])`,`button:not([disabled]):not([tabindex="-1"])`,`input:not([disabled]):not([type="hidden"]):not([tabindex="-1"])`,`select:not([disabled]):not([tabindex="-1"])`,`textarea:not([disabled]):not([tabindex="-1"])`,`[tabindex]:not([tabindex="-1"])`].join(`, `);return Array.from(e.querySelectorAll(t)).filter(e=>!e.hasAttribute(`inert`))}function x(e,t){if(e.key!==`Tab`)return!1;let n=b(t);if(n.length===0)return e.preventDefault(),!0;let r=n[0],i=n[n.length-1],a=(t?.ownerDocument??document).activeElement,o=!!a&&n.includes(a);return e.shiftKey?!o||a===r?(e.preventDefault(),i.focus(),!0):!1:!o||a===i?(e.preventDefault(),r.focus(),!0):!1}function S(e,t){return!t||t<=0||e.length<=t+3?null:{head:e.slice(0,e.length-t),tail:e.slice(-t)}}function C(e,t,n){return n<=0?0:t===`prev`?e<=0?n-1:e-1:e>=n-1?0:e+1}function w(e,t){let n=e.length;if(n===0||!t||t.length===0)return{totalCount:n,uploadedCount:0,failedCount:0};let r=0,i=0;for(let n of e){let e=t.find(e=>e.fileId===n.fileId);e?.progress===`done`?r++:e?.progress===`error`&&i++}return{totalCount:n,uploadedCount:r,failedCount:i}}function T(e,t=a.unknownFilename){return e.attributes?.targetFilename||e.file?.name||t}var E=class extends e.t{constructor(...e){super(...e),this.id=`pkt-fileupload-${i.n()}`,this.name=`files`,this.label=``,this.helptext=``,this.required=!1,this.multiple=!1,this.disabled=!1,this.fullwidth=!1,this.uploadStrategy=`form`,this.itemRenderer=`filename`,this.accept=``,this.allowedFormats=[],this.formatErrorMessage=``,this.sizeErrorMessage=``,this.transfers=[],this.addCommentsEnabled=!1,this.renameFilesEnabled=!1,this.extraOperations=[],this.enableImagePreview=!1,this.hasError=!1,this.errorMessage=``,this.optionalTag=!1,this.requiredTag=!1,this.truncateTail=4,this.files=[],this.isDragActive=!1,this.validationErrorMessage=null,this.addedAnnouncement=``,this.thumbnailUrls={},this.hasInitializedValue=!1,this.hasWarnedInvalidValueCombo=!1,this.thumbnailFileById=new Map,this.connectedForm=null,this.addedAnnouncementTimer=null,this.requiredSelectionMessage=a.requiredMissing,this.onNativeFileChange=e=>{let t=e.target;this.addFiles(t.files?Array.from(t.files):[]),this.uploadStrategy===`custom`&&(t.value=``)},this.openFileDialog=e=>{e.preventDefault(),e.stopPropagation(),!this.disabled&&this.querySelector(`#${this.id}-input`)?.click()},this.onDropZoneClick=e=>{this.disabled||e.target.closest(`.pkt-fileupload__drop-zone__placeholder__title__open-file-dialog`)||this.querySelector(`#${this.id}-input`)?.click()},this.onDragOver=e=>{e.preventDefault(),!this.disabled&&(this.isDragActive=!0)},this.onDragLeave=()=>{this.isDragActive=!1},this.onDrop=e=>{if(e.preventDefault(),this.isDragActive=!1,this.disabled)return;let t=e.dataTransfer?.files?Array.from(e.dataTransfer.files):[];this.addFiles(t)},this.onHostFormSubmit=e=>{!this.required||this.uploadStrategy!==`custom`||this.getCurrentFiles().length>0||(this.validationErrorMessage=this.requiredSelectionMessage,e.preventDefault())}}get isControlled(){return this.value!==void 0}get hasEffectiveError(){return!!this.validationErrorMessage||this.hasError||!!this.errorMessage.trim()}get effectiveErrorMessage(){return this.validationErrorMessage??this.errorMessage??``}get hasValidationError(){return!!this.validationErrorMessage}firstUpdated(e){super.firstUpdated?.(e),this.hasInitializedValue||=(this.files=this.value??this.defaultValue??[],this.syncThumbnailUrls(this.files),!0),this.value!==void 0&&this.defaultValue!==void 0&&this.warnInvalidValueCombo()}willUpdate(e){super.willUpdate(e),this.hasInitializedValue&&this.isControlled&&(e.has(`value`)||e.has(`itemRenderer`)||e.has(`enableImagePreview`))&&(this.files=this.value??[],this.syncThumbnailUrls(this.files))}updated(e){super.updated(e),(e.has(`uploadStrategy`)||e.has(`required`)||e.has(`value`))&&this.syncFormSubmitListener(),this.uploadStrategy===`form`&&(e.has(`value`)||e.has(`files`)||e.has(`uploadStrategy`))&&this.syncNativeInputFiles()}syncNativeInputFiles(){let e=this.querySelector(`#${this.id}-input`);if(!(!e||typeof DataTransfer>`u`))try{let t=new DataTransfer;for(let e of this.getCurrentFiles())e.file&&t.items.add(e.file);e.files=t.files}catch{}}warnInvalidValueCombo(){this.hasWarnedInvalidValueCombo||=(console.warn(`PktFileUpload: Både value og defaultValue er angitt. Komponenten kan være enten kontrollert eller ukontrollert, ikke begge. value vil bli prioritert.`),!0)}disconnectedCallback(){this.teardownFormSubmitListener(),this.addedAnnouncementTimer&&=(clearTimeout(this.addedAnnouncementTimer),null),super.disconnectedCallback(),this.revokeAllThumbnailUrls()}setAddedAnnouncement(e){this.addedAnnouncement=e,this.addedAnnouncementTimer&&clearTimeout(this.addedAnnouncementTimer),this.addedAnnouncementTimer=setTimeout(()=>{this.addedAnnouncement=``,this.addedAnnouncementTimer=null},1500)}connectedCallback(){super.connectedCallback(),this.syncFormSubmitListener()}addFiles(e){if(e.length===0)return;let t=this.multiple?e:[e[0]];for(let e of t){let t=this.validateFile(e);if(t){this.validationErrorMessage=t;return}}this.validationErrorMessage=null;let n=t.map(e=>({fileId:i.n(),file:e,attributes:{targetFilename:e.name}}));this.setAddedAnnouncement(n.length===1?a.srFileAdded(n[0].attributes.targetFilename):a.srFilesAdded(n.length));let r=this.getCurrentFiles(),o=this.multiple?[...r,...n]:[n[0]];this.commitFiles(o,`add`,n.map(e=>e.fileId)),this.uploadStrategy===`custom`&&n.forEach(e=>{this.dispatchEvent(new CustomEvent(`file-upload-requested`,{detail:{fileId:e.fileId,file:e.file,attributes:e.attributes},bubbles:!0,composed:!0}))})}getCurrentFiles(){return this.isControlled?this.value??[]:this.files}cancelTransfer(e){if(this.disabled)return;let t=this.getCurrentFiles().find(t=>t.fileId===e);t&&(this.removeFileItem(e),this.dispatchEvent(new CustomEvent(`transfer-cancelled`,{detail:{fileId:t.fileId,file:t.file,attributes:t.attributes},bubbles:!0,composed:!0})))}removeFileItem(e){if(this.disabled)return;let t=this.getCurrentFiles(),n=t.filter(t=>t.fileId!==e);n.length!==t.length&&this.commitFiles(n,`remove`,[e])}updateFileItem(e,t){let n=this.getCurrentFiles().map(n=>n.fileId===e?{...n,...t}:n);this.commitFiles(n,`update`,[e])}commitFiles(e,t,n){this.isControlled||(this.files=e,this.syncThumbnailUrls(e)),this.validationErrorMessage===this.requiredSelectionMessage&&e.length>0&&(this.validationErrorMessage=null),this.dispatchEvent(new CustomEvent(`files-changed`,{detail:{files:e,reason:t,changedFileIds:n},bubbles:!0,composed:!0}))}getThumbnailUrl(e){return this.thumbnailUrls[e.fileId]}getTransferProgress(e){let t=this.transfers.find(t=>t.fileId===e);return t?t.progress:this.uploadStrategy===`form`?`done`:`queued`}getTransferForFile(e){return this.transfers.find(t=>t.fileId===e)}isImageFile(e){return _(e)}formatFileSize(e){return s(e)}getResolvedAcceptValue(){return f(this.accept,this.allowedFormats)}getSupportedFormatsText(){return m(this.allowedFormats,this.accept)}getSortedFilesAndTransfers(){return y(this.getCurrentFiles(),this.transfers,this.uploadStrategy)}validateFile(e){let t=g(e,{allowedFormats:this.allowedFormats,maxFileSize:this.maxFileSize,formatErrorMessage:this.formatErrorMessage,sizeErrorMessage:this.sizeErrorMessage,onFileValidation:this.onFileValidation});if(t)return t;let n={file:e,errorMessage:null},r=new CustomEvent(`file-validate`,{detail:n,bubbles:!0,composed:!0,cancelable:!0});return this.dispatchEvent(r),n.errorMessage?n.errorMessage:r.defaultPrevented?a.genericValidationRejection:null}syncThumbnailUrls(e){if(!(typeof URL<`u`&&typeof URL.createObjectURL==`function`&&typeof URL.revokeObjectURL==`function`)){this.thumbnailUrls={},this.thumbnailFileById.clear();return}let t=new Set(e.map(e=>e.fileId)),n={};for(let[e,n]of Object.entries(this.thumbnailUrls))t.has(e)||(URL.revokeObjectURL(n),this.thumbnailFileById.delete(e));for(let t of e){let e=this.thumbnailUrls[t.fileId],r=this.thumbnailFileById.get(t.fileId);if(!t.file||!this.isImageFile(t)){e&&(URL.revokeObjectURL(e),this.thumbnailFileById.delete(t.fileId));continue}if(e&&r===t.file){n[t.fileId]=e;continue}e&&r!==t.file&&URL.revokeObjectURL(e);let i=URL.createObjectURL(t.file);this.thumbnailFileById.set(t.fileId,t.file),n[t.fileId]=i}this.thumbnailUrls=n}revokeAllThumbnailUrls(){if(typeof URL>`u`||typeof URL.revokeObjectURL!=`function`){this.thumbnailUrls={},this.thumbnailFileById.clear();return}Object.values(this.thumbnailUrls).forEach(e=>URL.revokeObjectURL(e)),this.thumbnailUrls={},this.thumbnailFileById.clear()}getSrUploadedMessage(){if(this.addedAnnouncement)return this.addedAnnouncement;let{totalCount:e,uploadedCount:t}=w(this.getCurrentFiles(),this.transfers);return e===0||t===0?``:a.srFilesUploadedOfTotal(t,e,a.fileLabel(e))}getSrErrorsMessage(){let{totalCount:e,failedCount:t}=w(this.getCurrentFiles(),this.transfers);return e===0||t===0?``:a.srFilesFailedOfTotal(t,e,a.fileLabel(e))}syncFormSubmitListener(){let e=this.closest(`form`);this.connectedForm!==e&&(this.teardownFormSubmitListener(),this.connectedForm=e,this.connectedForm&&this.connectedForm.addEventListener(`submit`,this.onHostFormSubmit))}teardownFormSubmitListener(){this.connectedForm&&=(this.connectedForm.removeEventListener(`submit`,this.onHostFormSubmit),null)}};e.r([e.s({type:String})],E.prototype,`id`,void 0),e.r([e.s({type:String})],E.prototype,`name`,void 0),e.r([e.s({type:String})],E.prototype,`label`,void 0),e.r([e.s({type:String})],E.prototype,`helptext`,void 0),e.r([e.s({type:Boolean,reflect:!0})],E.prototype,`required`,void 0),e.r([e.s({type:Boolean,reflect:!0})],E.prototype,`multiple`,void 0),e.r([e.s({type:Boolean,reflect:!0})],E.prototype,`disabled`,void 0),e.r([e.s({type:Boolean,reflect:!0,attribute:`fullwidth`})],E.prototype,`fullwidth`,void 0),e.r([e.s({type:String,reflect:!0,attribute:`upload-strategy`})],E.prototype,`uploadStrategy`,void 0),e.r([e.s({type:String,reflect:!0,attribute:`item-renderer`})],E.prototype,`itemRenderer`,void 0),e.r([e.s({type:String})],E.prototype,`accept`,void 0),e.r([e.s({converter:r.t.csvToArray,attribute:`allowed-formats`})],E.prototype,`allowedFormats`,void 0),e.r([e.s({type:String,attribute:`format-error-message`})],E.prototype,`formatErrorMessage`,void 0),e.r([e.s({attribute:`max-file-size`})],E.prototype,`maxFileSize`,void 0),e.r([e.s({type:String,attribute:`size-error-message`})],E.prototype,`sizeErrorMessage`,void 0),e.r([e.s({attribute:!1})],E.prototype,`onFileValidation`,void 0),e.r([e.s({attribute:!1})],E.prototype,`transfers`,void 0),e.r([e.s({type:Boolean,attribute:`add-comments-enabled`})],E.prototype,`addCommentsEnabled`,void 0),e.r([e.s({type:Boolean,attribute:`rename-files-enabled`})],E.prototype,`renameFilesEnabled`,void 0),e.r([e.s({attribute:!1})],E.prototype,`extraOperations`,void 0),e.r([e.s({type:Boolean,reflect:!0,attribute:`enable-image-preview`})],E.prototype,`enableImagePreview`,void 0),e.r([e.s({type:Boolean,attribute:`has-error`})],E.prototype,`hasError`,void 0),e.r([e.s({type:String,attribute:`error-message`})],E.prototype,`errorMessage`,void 0),e.r([e.s({type:Boolean,attribute:`optional-tag`})],E.prototype,`optionalTag`,void 0),e.r([e.s({type:Boolean,attribute:`required-tag`})],E.prototype,`requiredTag`,void 0),e.r([e.s({type:Number,attribute:`truncate-tail`})],E.prototype,`truncateTail`,void 0),e.r([e.s({attribute:!1})],E.prototype,`value`,void 0),e.r([e.s({attribute:!1})],E.prototype,`defaultValue`,void 0),e.r([e.o()],E.prototype,`files`,void 0),e.r([e.o()],E.prototype,`isDragActive`,void 0),e.r([e.o()],E.prototype,`validationErrorMessage`,void 0),e.r([e.o()],E.prototype,`addedAnnouncement`,void 0),e.r([e.o()],E.prototype,`thumbnailUrls`,void 0);var D=`comments`,O=e=>{let t=new Date(e);return Number.isNaN(t.getTime())?e:`${String(t.getDate()).padStart(2,`0`)}.${String(t.getMonth()+1).padStart(2,`0`)}.${t.getFullYear()} kl. ${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`},k=(e,t,n)=>{e.key===`Enter`&&(e.preventDefault(),e.stopPropagation(),t()),e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),n())},A=(e,t,n)=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),n()),(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),e.stopPropagation(),t())},j=e=>({id:`remove`,title:`Slett`,ariaLabel:`Slett fil`,onClick:({file:t})=>e(t.fileId)}),M=()=>({id:`rename`,title:`Rediger`,ariaLabel:`Rediger filnavn`,renderInlineUI:t=>{let n=t.getAttribute(`targetFilename`)||t.file.attributes?.targetFilename||t.file.file?.name||``,r=`pkt-fileupload-rename-${t.file.fileId}`,i=()=>{let e=document.getElementById(r)?.value?.trim();e&&t.setAttribute(`targetFilename`,e),t.close()};return e.d`
|
|
2
2
|
<label for=${r} class="pkt-sr-only">Endre filnavn</label>
|
|
3
3
|
<input
|
|
4
4
|
id=${r}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const e=require(`./element-DjtxO-1r.cjs`),t=require(`./class-map-CJ-msbHs.cjs`),n=require(`./element-with-slot-CWoTGA1B.cjs`);require(`./icon-Dr8sfT2X.cjs`);const r=require(`./if-defined-XKOD_t_V.cjs`);require(`./button-D-TOBaJB.cjs`);const i=require(`./ref-BaJ0mBT_.cjs`),a=require(`./booleanish-B5EFqFpJ.cjs`);require(`./link-
|
|
1
|
+
const e=require(`./element-DjtxO-1r.cjs`),t=require(`./class-map-CJ-msbHs.cjs`),n=require(`./element-with-slot-CWoTGA1B.cjs`);require(`./icon-Dr8sfT2X.cjs`);const r=require(`./if-defined-XKOD_t_V.cjs`);require(`./button-D-TOBaJB.cjs`);const i=require(`./ref-BaJ0mBT_.cjs`),a=require(`./booleanish-B5EFqFpJ.cjs`);require(`./link-H7BhqdWV.cjs`),require(`./textinput-mjmYIwxr.cjs`);var o=e=>typeof e.target==`string`?{title:e.title,iconName:e.iconName,href:e.target}:{title:e.title,iconName:e.iconName,onClick:e.target},s=e=>o(e),c=e=>{if(!e)return;let t=typeof e==`string`?new Date(e):e;if(!isNaN(t.getTime()))return t.toLocaleDateString(`nb-NO`,{day:`numeric`,month:`long`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})},l=class extends e.t{constructor(...e){super(...e),this.canChangeRepresentation=!1,this.logoutOnClick=!1}handleChangeRepresentation(){this.dispatchEvent(new CustomEvent(`change-representation`,{bubbles:!0,composed:!0}))}handleLogout(){this.dispatchEvent(new CustomEvent(`log-out`,{bubbles:!0,composed:!0}))}handleMenuItemClick(e){`onClick`in e&&typeof e.onClick==`function`&&e.onClick()}renderLinkOrButton(n,r){let i=`href`in n,a=t.t({"pkt-user-menu__link":!0,"pkt-link-button":!i,"pkt-link":!i,"pkt-link--icon-left":!i,[r||``]:!!r});return i?e.d`
|
|
2
2
|
<pkt-link
|
|
3
3
|
icon-name=${n.iconName||e.l}
|
|
4
4
|
href=${n.href}
|
|
@@ -273,7 +273,7 @@ const e=require(`./element-DjtxO-1r.cjs`),t=require(`./class-map-CJ-msbHs.cjs`),
|
|
|
273
273
|
`}render(){let n=this.renderHeader();return this.isFixed?e.d`
|
|
274
274
|
<div class="pkt-header-service-wrapper">
|
|
275
275
|
${n}
|
|
276
|
-
<div class=${t.t({"pkt-header-service-spacer":!0,"pkt-header-service-spacer--compact":this.compact,"pkt-header-service-spacer--has-user":!!this.user,"pkt-header-service-spacer--mobile":this.isMobile})}></div>
|
|
276
|
+
<div class=${t.t({"pkt-header-service-spacer":!0,"pkt-header-service-spacer--compact":this.compact,"pkt-header-service-spacer--has-user":!!this.user,"pkt-header-service-spacer--mobile":this.isMobile,"pkt-header-service-spacer--tablet":this.isTablet})}></div>
|
|
277
277
|
</div>
|
|
278
278
|
`:n}};e.r([e.s({type:String,attribute:`service-name`})],d.prototype,`serviceName`,void 0),e.r([e.s({type:String,attribute:`service-link`})],d.prototype,`serviceLink`,void 0),e.r([e.s({type:String,attribute:`logo-link`})],d.prototype,`logoLink`,void 0),e.r([e.s({type:String,attribute:`search-placeholder`})],d.prototype,`searchPlaceholder`,void 0),e.r([e.s({type:String,attribute:`search-value`})],d.prototype,`searchValue`,void 0),e.r([e.s({type:Number,attribute:`mobile-breakpoint`})],d.prototype,`mobileBreakpoint`,void 0),e.r([e.s({type:Number,attribute:`tablet-breakpoint`})],d.prototype,`tabletBreakpoint`,void 0),e.r([e.s({type:String,attribute:`opened-menu`})],d.prototype,`openedMenu`,void 0),e.r([e.s({type:String,attribute:`log-out-button-placement`})],d.prototype,`logOutButtonPlacement`,void 0),e.r([e.s({type:String})],d.prototype,`position`,void 0),e.r([e.s({type:String,attribute:`scroll-behavior`})],d.prototype,`scrollBehavior`,void 0),e.r([e.s({type:String,attribute:`slot-menu-variant`})],d.prototype,`slotMenuVariant`,void 0),e.r([e.s({type:String,attribute:`slot-menu-text`})],d.prototype,`slotMenuText`,void 0),e.r([e.s({type:Boolean,attribute:`hide-logo`,converter:a.t})],d.prototype,`hideLogo`,void 0),e.r([e.s({type:Boolean,converter:a.t})],d.prototype,`compact`,void 0),e.r([e.s({type:Boolean,attribute:`show-search`,converter:a.t})],d.prototype,`showSearch`,void 0),e.r([e.s({type:Boolean,attribute:`can-change-representation`,converter:a.t})],d.prototype,`canChangeRepresentation`,void 0),e.r([e.s({type:Boolean,attribute:`has-log-out`,converter:a.t})],d.prototype,`hasLogOut`,void 0),e.r([e.s({type:Object})],d.prototype,`user`,void 0),e.r([e.s({type:Array,attribute:`user-menu`})],d.prototype,`userMenu`,void 0),e.r([e.s({type:Object})],d.prototype,`representing`,void 0),e.r([e.o()],d.prototype,`isMobile`,void 0),e.r([e.o()],d.prototype,`isTablet`,void 0),e.r([e.o()],d.prototype,`openMenu`,void 0),e.r([e.o()],d.prototype,`isHidden`,void 0),e.r([e.o()],d.prototype,`componentWidth`,void 0),e.r([e.o()],d.prototype,`alignSlotRight`,void 0),e.r([e.o()],d.prototype,`alignSearchRight`,void 0);try{e.c(`pkt-header-service`)(d)}catch{console.warn(`Forsøker å definere <pkt-header-service>, men den er allerede definert`)}var f=class extends n.t{constructor(...e){super(...e),this.searchPlaceholder=`Søk`,this.searchValue=``,this.mobileBreakpoint=768,this.tabletBreakpoint=1280,this.openedMenu=`none`,this.logOutButtonPlacement=`none`,this.position=`fixed`,this.scrollBehavior=`hide`,this.slotMenuVariant=`icon-only`,this.slotMenuText=`Meny`,this.hideLogo=!1,this.compact=!1,this.showSearch=!1,this.canChangeRepresentation=!1,this.hasLogOut=!1}firstUpdated(e){super.firstUpdated(e),this.emitDeprecationWarnings()}emitDeprecationWarnings(){this.userMenuFooter!==void 0&&console.warn(`[PktHeader] userMenuFooter is deprecated. Use userMenu instead.`),this.userOptions!==void 0&&console.warn(`[PktHeader] userOptions is deprecated. Use userMenu instead.`)}get effectiveUserMenu(){let e=this.userMenu||[],t=this.userMenuFooter||[],n=this.userOptions||[];return t.length||n.length?[...e,...n,...t]:this.userMenu}render(){return e.d`
|
|
279
279
|
<pkt-header-service
|
|
@@ -6,8 +6,8 @@ import { t as u } from "./if-defined-Cjj8qN-Z.js";
|
|
|
6
6
|
import "./button-BIpd1xJh.js";
|
|
7
7
|
import { n as d, t as f } from "./ref-RS8Uv6uC.js";
|
|
8
8
|
import { t as p } from "./booleanish-CRaKZ75t.js";
|
|
9
|
-
import "./link-
|
|
10
|
-
import "./textinput-
|
|
9
|
+
import "./link-X9H6zi7W.js";
|
|
10
|
+
import "./textinput-BmuQREJY.js";
|
|
11
11
|
//#region ../../shared-types/header.ts
|
|
12
12
|
var m = (e) => typeof e.target == "string" ? {
|
|
13
13
|
title: e.title,
|
|
@@ -588,7 +588,8 @@ var v = "https://punkt-cdn.oslo.kommune.no/latest/logos/", y = class extends l {
|
|
|
588
588
|
"pkt-header-service-spacer": !0,
|
|
589
589
|
"pkt-header-service-spacer--compact": this.compact,
|
|
590
590
|
"pkt-header-service-spacer--has-user": !!this.user,
|
|
591
|
-
"pkt-header-service-spacer--mobile": this.isMobile
|
|
591
|
+
"pkt-header-service-spacer--mobile": this.isMobile,
|
|
592
|
+
"pkt-header-service-spacer--tablet": this.isTablet
|
|
592
593
|
})}></div>
|
|
593
594
|
</div>
|
|
594
595
|
` : e;
|