@oslokommune/punkt-elements 13.4.2 → 13.5.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.
@@ -1,154 +0,0 @@
1
- "use strict";const d=require("./class-map-BBG2gMX4.cjs"),o=require("./if-defined-Cni-RHLS.cjs"),s=require("./element-6DBpyGQm.cjs"),m=require("./state-DPobt-Yz.cjs"),h=require("./calendar-BZe2D4Sr.cjs"),v=require("./input-element-C4xJoM-X.cjs"),r=require("./ref-iJtiv3o2.cjs"),k=require("./repeat-CDsZqct8.cjs");require("./icon-B_ryAy4Q.cjs");require("./input-wrapper-CZ-a00V7.cjs");require("./tag-Bbs0U_Au.cjs");const $=require("./pkt-slot-controller-BzddBp7z.cjs"),y={dateformat:{default:"dd.MM.yyyy"},min:{default:null},max:{default:null},weeknumbers:{default:!1},withcontrols:{default:!1},multiple:{default:!1},range:{default:!1}},p={props:y};var b=Object.defineProperty,x=Object.getOwnPropertyDescriptor,n=(c,t,e,i)=>{for(var a=i>1?void 0:i?x(t,e):t,l=c.length-1,u;l>=0;l--)(u=c[l])&&(a=(i?u(t,e,a):u(a))||a);return i&&a&&b(t,e,a),a};const g=c=>new Promise(t=>setTimeout(t,c));exports.PktDatepicker=class extends v.PktInputElement{constructor(){super(),this.value="",this._value=this.value?Array.isArray(this.value)?this.value:this.value.split(","):[],this.label="Datovelger",this.dateformat=p.props.dateformat.default,this.multiple=p.props.multiple.default,this.maxlength=null,this.range=p.props.range.default,this.showRangeLabels=!1,this.min=null,this.max=null,this.weeknumbers=p.props.weeknumbers.default,this.withcontrols=p.props.withcontrols.default,this.excludedates=[],this.excludeweekdays=[],this.currentmonth=null,this.calendarOpen=!1,this.timezone="Europe/Oslo",this.inputClasses={},this.buttonClasses={},this.inputRef=r.e(),this.inputRefTo=r.e(),this.btnRef=r.e(),this.calRef=r.e(),this.popupRef=r.e(),this.helptextSlot=r.e(),this.addToSelected=t=>{const e=t.target;if(!e.value)return;const i=this.min?h.newDate(this.min):null,a=this.max?h.newDate(this.max):null,l=h.newDate(e.value.split(",")[0]);l&&!isNaN(l.getTime())&&(!i||l>=i)&&(!a||l<=a)&&this.calRef.value&&this.calRef.value.handleDateSelect(l),e.value=""},this.slotController=new $.PktSlotController(this,this.helptextSlot)}async connectedCallback(){super.connectedCallback();const t=navigator.userAgent,e=/iP(hone|od|ad)/.test(t);this.inputType=e?"text":"date",document&&document.body.addEventListener("click",i=>{var a,l;(a=this.inputRef)!=null&&a.value&&((l=this.btnRef)!=null&&l.value)&&!this.inputRef.value.contains(i.target)&&!(this.inputRefTo.value&&this.inputRefTo.value.contains(i.target))&&!this.btnRef.value.contains(i.target)&&!i.target.closest(".pkt-calendar-popup")&&this.calendarOpen&&(this.onBlur(),this.hideCalendar())}),this.value.length&&this._value.length===0&&(this._value=Array.isArray(this.value)?this.value:this.value.split(",")),this.min=this.min||p.props.min.default,this.max=this.max||p.props.max.default,typeof this.excludedates=="string"&&(this.excludedates=this.excludedates.split(",")),typeof this.excludeweekdays=="string"&&(this.excludeweekdays=this.excludeweekdays.split(",")),(this.multiple||this.range)&&this.name&&!this.name.endsWith("[]")&&(this.name=this.name+"[]"),this.calendarOpen&&(await g(20),this.handleCalendarPosition())}disconnectedCallback(){super.disconnectedCallback(),document&&document.body.removeEventListener("click",t=>{var e,i;(e=this.inputRef)!=null&&e.value&&((i=this.btnRef)!=null&&i.value)&&!this.inputRef.value.contains(t.target)&&!this.btnRef.value.contains(t.target)&&this.hideCalendar()})}attributeChangedCallback(t,e,i){if(t==="value"){if(this.range&&(i==null?void 0:i.split(",").length)===1)return;this.value!==e&&this.valueChanged(i,e)}t==="excludedates"&&typeof this.excludedates=="string"&&(this.excludedates=(i==null?void 0:i.split(","))??[]),t==="excludeweekdays"&&typeof this.excludeweekdays=="string"&&(this.excludeweekdays=(i==null?void 0:i.split(","))??[]),super.attributeChangedCallback(t,e,i)}updated(t){t.has("multiple")&&(this.multiple&&!Array.isArray(this._value)?this._value=typeof this.value=="string"?this.value?this.value.split(",").filter(Boolean):[]:[]:!this.multiple&&Array.isArray(this._value)&&(this._value=this._value.filter(Boolean)),!this.multiple&&Array.isArray(this._value)&&(this._value=[this._value[0]??""])),super.updated(t)}renderInput(){return s.x`
2
- <input
3
- class="${d.e(this.inputClasses)}"
4
- .type=${this.inputType}
5
- id="${this.id}-input"
6
- .value=${this._value[0]??""}
7
- min=${o.o(this.min)}
8
- max=${o.o(this.max)}
9
- @click=${t=>{t.preventDefault(),this.showCalendar()}}
10
- ?disabled=${this.disabled}
11
- @keydown=${t=>{var e,i;if(t.key===","&&((e=this.inputRef.value)==null||e.blur()),(t.key==="Space"||t.key===" ")&&(t.preventDefault(),this.toggleCalendar(t)),t.key==="Enter"){const a=this.internals.form;a?a.requestSubmit():(i=this.inputRef.value)==null||i.blur()}}}
12
- @input=${t=>{this.onInput(),t.stopImmediatePropagation()}}
13
- @focus=${()=>{this.onFocus(),this.isMobileSafari&&this.showCalendar()}}
14
- @blur=${t=>{var e;(e=this.calRef.value)!=null&&e.contains(t.relatedTarget)||this.onBlur(),this.manageValidity(t.target),this.value=t.target.value}}
15
- @change=${t=>{this.touched=!0,t.stopImmediatePropagation()}}
16
- ${r.n(this.inputRef)}
17
- />
18
- `}renderRangeInput(){const t={"pkt-input-prefix":this.showRangeLabels,"pkt-hide":!this.showRangeLabels};return s.x`
19
- ${this.showRangeLabels?s.x` <div class="pkt-input-prefix">${this.strings.generic.from}</div> `:s.E}
20
- <input
21
- class=${d.e(this.inputClasses)}
22
- .type=${this.inputType}
23
- id="${this.id}-input"
24
- .value=${this._value[0]??""}
25
- min=${o.o(this.min)}
26
- max=${o.o(this.max)}
27
- ?disabled=${this.disabled}
28
- @click=${e=>{e.preventDefault(),this.showCalendar()}}
29
- @keydown=${e=>{var i,a;if(e.key===","&&((i=this.inputRef.value)==null||i.blur()),(e.key==="Space"||e.key===" ")&&(e.preventDefault(),this.toggleCalendar(e)),e.key==="Enter"){const l=this.internals.form;l?l.requestSubmit():(a=this.inputRefTo.value)==null||a.focus()}}}
30
- @input=${e=>{this.onInput(),e.stopImmediatePropagation()}}
31
- @focus=${()=>{this.onFocus(),this.isMobileSafari&&this.showCalendar()}}
32
- @blur=${e=>{var i,a;if(e.target.value){this.manageValidity(e.target);const l=h.fromISOToDate(e.target.value);l&&this._value[0]!==e.target.value&&this._value[1]&&(this.clearInputValue(),(a=(i=this.calRef)==null?void 0:i.value)==null||a.handleDateSelect(l))}else this._value[0]&&this.clearInputValue()}}
33
- @change=${e=>{e.stopImmediatePropagation()}}
34
- ${r.n(this.inputRef)}
35
- />
36
- <div class="${d.e(t)}" id="${this.id}-to-label">
37
- ${this.strings.generic.to}
38
- </div>
39
- ${this.showRangeLabels?s.E:s.x` <div class="pkt-input-separator">–</div> `}
40
- <input
41
- class=${d.e(this.inputClasses)}
42
- .type=${this.inputType}
43
- id="${this.id}-to"
44
- aria-labelledby="${this.id}-to-label"
45
- .value=${this._value[1]??""}
46
- min=${o.o(this.min)}
47
- max=${o.o(this.max)}
48
- ?disabled=${this.disabled}
49
- @click=${e=>{e.preventDefault(),this.showCalendar()}}
50
- @keydown=${e=>{var i,a;if(e.key===","&&((i=this.inputRefTo.value)==null||i.blur()),(e.key==="Space"||e.key===" ")&&(e.preventDefault(),this.toggleCalendar(e)),e.key==="Enter"){const l=this.internals.form;l?l.requestSubmit():(a=this.inputRefTo.value)==null||a.blur()}}}
51
- @input=${e=>{this.onInput(),e.stopImmediatePropagation()}}
52
- @focus=${()=>{this.onFocus(),this.isMobileSafari&&this.showCalendar()}}
53
- @blur=${e=>{var i,a,l;if((i=this.calRef.value)!=null&&i.contains(e.relatedTarget)||this.onBlur(),e.target.value){this.manageValidity(e.target);const u=e.target.value;this.min&&this.min>u?this.internals.setValidity({rangeUnderflow:!0},this.strings.forms.messages.rangeUnderflow,e.target):this.max&&this.max<u&&this.internals.setValidity({rangeOverflow:!0},this.strings.forms.messages.rangeOverflow,e.target);const f=h.fromISOToDate(e.target.value);f&&this._value[1]!==h.formatISODate(f)&&((l=(a=this.calRef)==null?void 0:a.value)==null||l.handleDateSelect(f))}}}
54
- @change=${e=>{this.touched=!0,e.stopImmediatePropagation()}}
55
- ${r.n(this.inputRefTo)}
56
- />
57
- `}renderMultipleInput(){return console.log("range",this.range,"multiple",this.multiple),s.x`
58
- <input
59
- class=${d.e(this.inputClasses)}
60
- .type=${this.inputType}
61
- id="${this.id}-input"
62
- min=${o.o(this.min)}
63
- max=${o.o(this.max)}
64
- ?disabled=${this.disabled||this.maxlength&&this._value.length>=this.maxlength}
65
- @click=${t=>{t.preventDefault(),this.showCalendar()}}
66
- @blur=${t=>{var e;(e=this.calRef.value)!=null&&e.contains(t.relatedTarget)||this.onBlur(),this.addToSelected(t)}}
67
- @input=${t=>{this.onInput(),t.stopImmediatePropagation()}}
68
- @focus=${()=>{this.onFocus(),this.isMobileSafari&&this.showCalendar()}}
69
- @keydown=${t=>{var e;if(t.key===","&&(t.preventDefault(),this.addToSelected(t)),(t.key==="Space"||t.key===" ")&&(t.preventDefault(),this.toggleCalendar(t)),t.key==="Enter"){const i=this.internals.form;i?i.requestSubmit():(e=this.inputRef.value)==null||e.blur()}}}
70
- @change=${t=>{this.touched=!0,t.stopImmediatePropagation()}}
71
- ${r.n(this.inputRef)}
72
- />
73
- `}renderTags(){return s.x`
74
- <div class="pkt-datepicker__tags" aria-live="polite">
75
- ${this._value[0]?k.c((this._value??[]).filter(Boolean),t=>t,t=>s.x`
76
- <pkt-tag
77
- .id="${this.id+t+"-tag"}"
78
- closeTag
79
- ariaLabel="${this.strings.calendar.deleteDate} ${h.fromISOtoLocal(t,this.dateformat)}"
80
- @close=${()=>{var e;return(e=this.calRef.value)==null?void 0:e.handleDateSelect(h.fromISOToDate(t))}}
81
- ><time datetime="${t}">${h.fromISOtoLocal(t,this.dateformat)}</time></pkt-tag
82
- >
83
- `):s.E}
84
- </div>
85
- `}renderCalendar(){return s.x`<div
86
- class="pkt-calendar-popup pkt-${this.calendarOpen?"show":"hide"}"
87
- @focusout=${t=>{this.calendarOpen&&this.handleFocusOut(t)}}
88
- id="${this.id}-popup"
89
- ${r.n(this.popupRef)}
90
- >
91
- <pkt-calendar
92
- id="${this.id}-calendar"
93
- ?multiple=${this.multiple}
94
- ?range=${this.range}
95
- ?weeknumbers=${this.weeknumbers}
96
- ?withcontrols=${this.withcontrols}
97
- .maxMultiple=${this.maxlength}
98
- .selected=${this._value}
99
- .earliest=${this.min}
100
- .latest=${this.max}
101
- .excludedates=${Array.isArray(this.excludedates)?this.excludedates:this.excludedates.split(",")}
102
- .excludeweekdays=${this.excludeweekdays}
103
- .currentmonth=${this.currentmonth?h.newDate(this.currentmonth):null}
104
- @date-selected=${t=>{this.value=!this.multiple&&!this.range?t.detail[0]:t.detail,this._value=t.detail,this.inputRef.value&&(this.range&&this.inputRefTo.value?(this.inputRef.value.value=this._value[0]??"",this.inputRefTo.value.value=this._value[1]??""):this.multiple||(this.inputRef.value.value=this._value.length?this._value[0]:""))}}
105
- @close=${()=>{this.onBlur(),this.hideCalendar()}}
106
- ${r.n(this.calRef)}
107
- ></pkt-calendar>
108
- </div>`}render(){return console.log("multiple",this.multiple,"value",this.value,"_value",this._value),this.inputClasses={"pkt-input":!0,"pkt-datepicker__input":!0,"pkt-input--fullwidth":this.fullwidth,"pkt-datepicker--hasrangelabels":this.showRangeLabels,"pkt-datepicker--multiple":this.multiple,"pkt-datepicker--range":this.range},this.buttonClasses={"pkt-input-icon":!0,"pkt-btn":!0,"pkt-btn--icon-only":!0,"pkt-btn--tertiary":!0},s.x`
109
- <pkt-input-wrapper
110
- label="${this.label}"
111
- forId="${this.id}-input"
112
- ?counter=${this.multiple&&!!this.maxlength}
113
- .counterCurrent=${this.value?this._value.length:0}
114
- .counterMaxLength=${this.maxlength}
115
- ?disabled=${this.disabled}
116
- ?hasError=${this.hasError}
117
- ?hasFieldset=${this.hasFieldset}
118
- ?inline=${this.inline}
119
- ?required=${this.required}
120
- ?optionalTag=${this.optionalTag}
121
- ?requiredTag=${this.requiredTag}
122
- ?useWrapper=${this.useWrapper}
123
- .optionalText=${this.optionalText}
124
- .requiredText=${this.requiredText}
125
- .tagText=${this.tagText}
126
- .errorMessage=${this.errorMessage}
127
- .helptext=${this.helptext}
128
- .helptextDropdown=${this.helptextDropdown}
129
- .helptextDropdownButton=${this.helptextDropdownButton}
130
- .ariaDescribedBy=${this.ariaDescribedBy}
131
- class="pkt-datepicker"
132
- >
133
- <div class="pkt-contents" ${r.n(this.helptextSlot)} name="helptext" slot="helptext"></div>
134
- ${this.multiple?this.renderTags():s.E}
135
- <div
136
- class="pkt-datepicker__inputs ${this.range&&this.showRangeLabels?"pkt-input__range-inputs":""}"
137
- >
138
- <div class="pkt-input__container">
139
- ${this.range?this.renderRangeInput():this.multiple?this.renderMultipleInput():this.renderInput()}
140
- <button
141
- class="${d.e(this.buttonClasses)}"
142
- type="button"
143
- @click=${this.toggleCalendar}
144
- ?disabled=${this.disabled}
145
- ${r.n(this.btnRef)}
146
- >
147
- <pkt-icon name="calendar"></pkt-icon>
148
- <span class="pkt-btn__text">${this.strings.calendar.buttonAltText}</span>
149
- </button>
150
- </div>
151
- </div>
152
- </pkt-input-wrapper>
153
- ${this.renderCalendar()}
154
- `}handleCalendarPosition(){var t;if(this.popupRef.value&&this.inputRef.value){const e=this.multiple&&!!this.maxlength,i=((t=this.inputRef.value.parentElement)==null?void 0:t.getBoundingClientRect())||this.inputRef.value.getBoundingClientRect(),a=e?i.height+30:i.height,l=this.popupRef.value.getBoundingClientRect().height;let u=e?"calc(100% - 30px)":"100%";i&&i.top+l>window.innerHeight&&i.top-l>0&&(u=`calc(100% - ${a}px - ${l}px)`),this.popupRef.value.style.top=u}}handleFocusOut(t){this.contains(t.target)||(this.onBlur(),this.hideCalendar())}async showCalendar(){var t;this.calendarOpen=!0,await g(20),this.handleCalendarPosition(),this.isMobileSafari&&((t=this.calRef.value)==null||t.focusOnCurrentDate())}hideCalendar(){this.calendarOpen=!1}async toggleCalendar(t){t.preventDefault(),this.calendarOpen?this.hideCalendar():this.showCalendar()}};n([s.n({type:String,reflect:!0})],exports.PktDatepicker.prototype,"value",2);n([s.n({type:Array})],exports.PktDatepicker.prototype,"_value",2);n([s.n({type:String,reflect:!0})],exports.PktDatepicker.prototype,"label",2);n([s.n({type:String})],exports.PktDatepicker.prototype,"dateformat",2);n([s.n({type:Boolean,reflect:!0})],exports.PktDatepicker.prototype,"multiple",2);n([s.n({type:Number,reflect:!0})],exports.PktDatepicker.prototype,"maxlength",2);n([s.n({type:Boolean,reflect:!0})],exports.PktDatepicker.prototype,"range",2);n([s.n({type:Boolean})],exports.PktDatepicker.prototype,"showRangeLabels",2);n([s.n({type:String,reflect:!0})],exports.PktDatepicker.prototype,"min",2);n([s.n({type:String,reflect:!0})],exports.PktDatepicker.prototype,"max",2);n([s.n({type:Boolean})],exports.PktDatepicker.prototype,"weeknumbers",2);n([s.n({type:Boolean,reflect:!0})],exports.PktDatepicker.prototype,"withcontrols",2);n([s.n({converter:h.converters.csvToArray})],exports.PktDatepicker.prototype,"excludedates",2);n([s.n({converter:h.converters.csvToArray})],exports.PktDatepicker.prototype,"excludeweekdays",2);n([s.n({type:String})],exports.PktDatepicker.prototype,"currentmonth",2);n([s.n({type:Boolean,reflect:!0})],exports.PktDatepicker.prototype,"calendarOpen",2);n([s.n({type:String})],exports.PktDatepicker.prototype,"timezone",2);n([m.r()],exports.PktDatepicker.prototype,"inputClasses",2);n([m.r()],exports.PktDatepicker.prototype,"buttonClasses",2);exports.PktDatepicker=n([s.t("pkt-datepicker")],exports.PktDatepicker);