@oslokommune/punkt-elements 13.5.12 → 13.6.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.
@@ -43,7 +43,7 @@ export class PktSelect extends PktInputElement implements IPktSelect {
43
43
  private inputRef: Ref<HTMLSelectElement> = createRef()
44
44
  private helptextSlot: Ref<HTMLElement> = createRef()
45
45
 
46
- @property({ type: Array }) options: TSelectOption[] = []
46
+ @property({ type: Array, attribute: 'options' }) private _optionsProp: TSelectOption[] = []
47
47
  @property({ type: String }) value: string = ''
48
48
 
49
49
  @state() private _options: TSelectOption[] = []
@@ -51,6 +51,19 @@ export class PktSelect extends PktInputElement implements IPktSelect {
51
51
  public selectedIndex: number | null = -1
52
52
  public selectedOptions: HTMLCollectionOf<HTMLOptionElement> | undefined = undefined
53
53
 
54
+ // Getter and setter for options to expose the actual parsed options
55
+ public get options(): TSelectOption[] {
56
+ return this._options.map((option) => ({
57
+ ...option,
58
+ selected: option.value === this.value,
59
+ }))
60
+ }
61
+
62
+ public set options(value: TSelectOption[]) {
63
+ this._optionsProp = value
64
+ this.requestUpdate('_optionsProp', this._options)
65
+ }
66
+
54
67
  constructor() {
55
68
  super()
56
69
  this.optionsController = new PktOptionsSlotController(this)
@@ -58,11 +71,10 @@ export class PktSelect extends PktInputElement implements IPktSelect {
58
71
  this.slotController.skipOptions = true
59
72
  }
60
73
 
61
- // Used for initilization
62
74
  connectedCallback(): void {
63
75
  super.connectedCallback()
64
76
 
65
- const optionsReceivedFromProps = this.options.length > 0
77
+ const optionsReceivedFromProps = this._optionsProp.length > 0
66
78
  const checkIfOptionNodesInSlot =
67
79
  this.optionsController.nodes.length && this.optionsController.nodes.length > 0
68
80
 
@@ -83,7 +95,7 @@ export class PktSelect extends PktInputElement implements IPktSelect {
83
95
  this._options.push(option)
84
96
  })
85
97
  } else {
86
- this._options = this.options
98
+ this._options = this._optionsProp
87
99
  this._options.forEach((option) => {
88
100
  if (option.selected && !this.value) {
89
101
  this.value = option.value
@@ -94,17 +106,32 @@ export class PktSelect extends PktInputElement implements IPktSelect {
94
106
 
95
107
  // Support native Select method `add`
96
108
  public add(item: HTMLOptionElement, before?: HTMLOptionElement | number) {
97
- this.inputRef.value?.add(item, before)
98
- this._options.push({
109
+ const newOption = {
99
110
  value: item.value || item.text,
100
111
  label: item.text || item.value,
101
112
  selected: item.selected,
102
113
  disabled: item.disabled,
103
- })
114
+ }
115
+
116
+ // Add to our internal options array at the correct position
117
+ if (before === undefined) {
118
+ this._options.push(newOption)
119
+ } else if (typeof before === 'number') {
120
+ this._options.splice(before, 0, newOption)
121
+ } else {
122
+ // If before is an HTMLOptionElement, find its index in our options
123
+ const beforeValue = before.value || before.text
124
+ const beforeIndex = this._options.findIndex((opt) => opt.value === beforeValue)
125
+ if (beforeIndex >= 0) {
126
+ this._options.splice(beforeIndex, 0, newOption)
127
+ } else {
128
+ this._options.push(newOption)
129
+ }
130
+ }
131
+
104
132
  if (item.selected) {
105
133
  this.value = item.value || item.text
106
- this.selectedIndex = this.returnNumberOrNull(this.inputRef.value?.selectedIndex)
107
- this.selectedOptions = this.inputRef.value?.selectedOptions
134
+ this.selectedIndex = this._options.findIndex((opt) => opt.value === this.value)
108
135
  }
109
136
  this.requestUpdate()
110
137
  }
@@ -115,7 +142,8 @@ export class PktSelect extends PktInputElement implements IPktSelect {
115
142
  if (this.selectedIndex === item) {
116
143
  this.value = this._options[0]?.value || ''
117
144
  }
118
- this.inputRef.value?.remove(item)
145
+ this._options.splice(item, 1)
146
+ this.requestUpdate()
119
147
  }
120
148
  }
121
149
 
@@ -131,7 +159,9 @@ export class PktSelect extends PktInputElement implements IPktSelect {
131
159
 
132
160
  // Support native Select method `showPicker`
133
161
  public showPicker() {
134
- this.inputRef.value?.showPicker()
162
+ if (this.inputRef.value && 'showPicker' in this.inputRef.value) {
163
+ ;(this.inputRef.value as any).showPicker()
164
+ }
135
165
  }
136
166
 
137
167
  public attributeChangedCallback(name: string, _old: string, value: string): void {
@@ -141,7 +171,7 @@ export class PktSelect extends PktInputElement implements IPktSelect {
141
171
  if (name === 'value' && this.value !== _old) {
142
172
  this.selectedIndex = this.touched
143
173
  ? this.returnNumberOrNull(this.inputRef.value?.selectedIndex)
144
- : this.options.findIndex((option) => option.value === value)
174
+ : this._options.findIndex((option) => option.value === value)
145
175
  this.selectedOptions = this.inputRef.value?.selectedOptions
146
176
  this.valueChanged(value, _old)
147
177
  }
@@ -150,8 +180,8 @@ export class PktSelect extends PktInputElement implements IPktSelect {
150
180
 
151
181
  update(changedProperties: PropertyValues) {
152
182
  super.update(changedProperties)
153
- if (changedProperties.has('options')) {
154
- this._options = this.options
183
+ if (changedProperties.has('_optionsProp') && this._optionsProp.length > 0) {
184
+ this._options = this._optionsProp
155
185
  this.requestUpdate('_options')
156
186
 
157
187
  // If no value is set and we have options, set to first option
@@ -163,7 +193,7 @@ export class PktSelect extends PktInputElement implements IPktSelect {
163
193
  if (changedProperties.has('value') && this.value !== changedProperties.get('value')) {
164
194
  this.selectedIndex = this.touched
165
195
  ? this.returnNumberOrNull(this.inputRef.value?.selectedIndex)
166
- : this.options.findIndex((option) => option.value === this.value)
196
+ : this._options.findIndex((option) => option.value === this.value)
167
197
  this.selectedOptions = this.inputRef.value?.selectedOptions
168
198
  this.valueChanged(this.value, changedProperties.get('value'))
169
199
  }
@@ -174,8 +204,8 @@ export class PktSelect extends PktInputElement implements IPktSelect {
174
204
 
175
205
  protected firstUpdated(_changedProperties: PropertyValues): void {
176
206
  super.firstUpdated(_changedProperties)
177
- if (this.options.length) {
178
- this._options = this.options
207
+ if (this._optionsProp.length) {
208
+ this._options = this._optionsProp
179
209
  }
180
210
  // If no options are selected, set value and selectedIndex to the first option
181
211
  if (!this.value && this._options.length > 0) {
@@ -1,164 +0,0 @@
1
- "use strict";const d=require("./class-map-BBG2gMX4.cjs"),h=require("./if-defined-Cni-RHLS.cjs"),s=require("./element-6DBpyGQm.cjs"),v=require("./state-DPobt-Yz.cjs"),o=require("./calendar-32W9p9uc.cjs"),m=require("./input-element-C4xJoM-X.cjs"),r=require("./ref-iJtiv3o2.cjs"),y=require("./repeat-CDsZqct8.cjs");require("./icon-B_ryAy4Q.cjs");require("./input-wrapper-CZ-a00V7.cjs");require("./tag-Bbs0U_Au.cjs");const k=require("./pkt-slot-controller-BzddBp7z.cjs"),$={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:$};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 m.PktInputElement{constructor(){super(),this._valueProperty="",this._value=[],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?o.newDate(this.min):null,a=this.max?o.newDate(this.max):null,l=o.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 k.PktSlotController(this,this.helptextSlot)}get value(){return this._valueProperty}set value(t){const e=this._valueProperty;this._valueProperty=Array.isArray(t)?t.join(","):t||"",this.valueChanged(this._valueProperty,e),this.requestUpdate("value",e)}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())}),document&&document.body.addEventListener("keydown",i=>{i.key==="Escape"&&this.calendarOpen&&this.hideCalendar()}),this.value&&(this._value=Array.isArray(this.value)?this.value.filter(Boolean):this.value.split(",").filter(Boolean)),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()})}onInput(){this.dispatchEvent(new Event("input",{bubbles:!0}))}valueChanged(t,e){if(t===e)return;let i=[];t&&(typeof t=="string"?i=t.split(",").filter(Boolean):i=String(t).split(",").filter(Boolean)),this._value=i;const a=i.join(",");this._valueProperty!==a&&(this._valueProperty=a),super.valueChanged(a,e)}attributeChangedCallback(t,e,i){t==="value"&&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){if(t.has("value")){const e=Array.isArray(this.value)?this.value.join(","):this.value,i=t.get("value"),a=Array.isArray(i)?i.join(","):i;this.valueChanged(e,a)}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&&!this.range&&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=${h.o(this.min)}
8
- max=${h.o(this.max)}
9
- placeholder=${h.o(this.placeholder)}
10
- ?readonly=${this.readonly}
11
- aria-describedby="${this.id}-helptext"
12
- @click=${t=>{t.preventDefault(),this.showCalendar()}}
13
- ?disabled=${this.disabled}
14
- @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()}}}
15
- @input=${t=>{this.onInput(),t.stopImmediatePropagation()}}
16
- @focus=${()=>{this.onFocus(),this.isMobileSafari&&this.showCalendar()}}
17
- @blur=${t=>{var e;(e=this.calRef.value)!=null&&e.contains(t.relatedTarget)||this.onBlur(),this.manageValidity(t.target),this.value=t.target.value}}
18
- @change=${t=>{this.touched=!0,t.stopImmediatePropagation()}}
19
- ${r.n(this.inputRef)}
20
- />
21
- `}renderRangeInput(){const t={"pkt-input-prefix":this.showRangeLabels,"pkt-hide":!this.showRangeLabels};return s.x`
22
- ${this.showRangeLabels?s.x` <div class="pkt-input-prefix">${this.strings.generic.from}</div> `:s.E}
23
- <input
24
- class=${d.e(this.inputClasses)}
25
- .type=${this.inputType}
26
- id="${this.id}-input"
27
- .value=${this._value[0]??""}
28
- min=${h.o(this.min)}
29
- max=${h.o(this.max)}
30
- placeholder=${h.o(this.placeholder)}
31
- ?readonly=${this.readonly}
32
- ?disabled=${this.disabled}
33
- @click=${e=>{e.preventDefault(),this.showCalendar()}}
34
- @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()}}}
35
- @input=${e=>{this.onInput(),e.stopImmediatePropagation()}}
36
- @focus=${()=>{this.onFocus(),this.isMobileSafari&&this.showCalendar()}}
37
- @blur=${e=>{var i,a;if(e.target.value){this.manageValidity(e.target);const l=o.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()}}
38
- @change=${e=>{e.stopImmediatePropagation()}}
39
- ${r.n(this.inputRef)}
40
- />
41
- <div class="${d.e(t)}" id="${this.id}-to-label">
42
- ${this.strings.generic.to}
43
- </div>
44
- ${this.showRangeLabels?s.E:s.x` <div class="pkt-input-separator">–</div> `}
45
- <input
46
- class=${d.e(this.inputClasses)}
47
- .type=${this.inputType}
48
- id="${this.id}-to"
49
- aria-labelledby="${this.id}-to-label"
50
- .value=${this._value[1]??""}
51
- min=${h.o(this.min)}
52
- max=${h.o(this.max)}
53
- placeholder=${h.o(this.placeholder)}
54
- ?readonly=${this.readonly}
55
- ?disabled=${this.disabled}
56
- @click=${e=>{e.preventDefault(),this.showCalendar()}}
57
- @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()}}}
58
- @input=${e=>{this.onInput(),e.stopImmediatePropagation()}}
59
- @focus=${()=>{this.onFocus(),this.isMobileSafari&&this.showCalendar()}}
60
- @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=o.fromISOToDate(e.target.value);f&&this._value[1]!==o.formatISODate(f)&&((l=(a=this.calRef)==null?void 0:a.value)==null||l.handleDateSelect(f))}}}
61
- @change=${e=>{this.touched=!0,e.stopImmediatePropagation()}}
62
- ${r.n(this.inputRefTo)}
63
- />
64
- `}renderMultipleInput(){return s.x`
65
- <input
66
- class=${d.e(this.inputClasses)}
67
- .type=${this.inputType}
68
- id="${this.id}-input"
69
- min=${h.o(this.min)}
70
- max=${h.o(this.max)}
71
- placeholder=${h.o(this.placeholder)}
72
- ?readonly=${this.readonly}
73
- ?disabled=${this.disabled||this.maxlength&&this._value.length>=this.maxlength}
74
- @click=${t=>{t.preventDefault(),this.showCalendar()}}
75
- @blur=${t=>{var e;(e=this.calRef.value)!=null&&e.contains(t.relatedTarget)||this.onBlur(),this.addToSelected(t)}}
76
- @input=${t=>{this.onInput(),t.stopImmediatePropagation()}}
77
- @focus=${()=>{this.onFocus(),this.isMobileSafari&&this.showCalendar()}}
78
- @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()}}}
79
- @change=${t=>{this.touched=!0,t.stopImmediatePropagation()}}
80
- ${r.n(this.inputRef)}
81
- />
82
- `}renderTags(){return s.x`
83
- <div class="pkt-datepicker__tags" aria-live="polite">
84
- ${this._value[0]?y.c((this._value??[]).filter(Boolean).sort(),t=>t,t=>s.x`
85
- <pkt-tag
86
- .id="${this.id+t+"-tag"}"
87
- closeTag
88
- ariaLabel="${this.strings.calendar.deleteDate} ${o.fromISOtoLocal(t,this.dateformat)}"
89
- @close=${()=>{var e;return(e=this.calRef.value)==null?void 0:e.handleDateSelect(o.fromISOToDate(t))}}
90
- ><time datetime="${t}">${o.fromISOtoLocal(t,this.dateformat)}</time></pkt-tag
91
- >
92
- `):s.E}
93
- </div>
94
- `}renderCalendar(){return s.x`<div
95
- class="pkt-calendar-popup pkt-${this.calendarOpen?"show":"hide"}"
96
- @focusout=${t=>{this.calendarOpen&&this.handleFocusOut(t)}}
97
- id="${this.id}-popup"
98
- ${r.n(this.popupRef)}
99
- >
100
- <pkt-calendar
101
- id="${this.id}-calendar"
102
- ?multiple=${this.multiple}
103
- ?range=${this.range}
104
- ?weeknumbers=${this.weeknumbers}
105
- ?withcontrols=${this.withcontrols}
106
- .maxMultiple=${this.maxlength}
107
- .selected=${this._value}
108
- .earliest=${this.min}
109
- .latest=${this.max}
110
- .excludedates=${Array.isArray(this.excludedates)?this.excludedates:this.excludedates.split(",")}
111
- .excludeweekdays=${this.excludeweekdays}
112
- .currentmonth=${this.currentmonth?o.parseISODateString(this.currentmonth):null}
113
- @date-selected=${t=>{this.value=!this.multiple&&!this.range?t.detail[0]:Array.isArray(t.detail)?t.detail.join(","):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.manageValidity(this.inputRef.value),this.manageValidity(this.inputRefTo.value)):this.multiple||(this.inputRef.value.value=this._value.length?this._value[0]:"",this.manageValidity(this.inputRef.value)))}}
114
- @close=${()=>{this.onBlur(),this.hideCalendar()}}
115
- ${r.n(this.calRef)}
116
- ></pkt-calendar>
117
- </div>`}render(){return 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,"pkt-datepicker__calendar-button":!0},s.x`
118
- <pkt-input-wrapper
119
- label="${this.label}"
120
- forId="${this.id}-input"
121
- ?counter=${this.multiple&&!!this.maxlength}
122
- .counterCurrent=${this.value?this._value.length:0}
123
- .counterMaxLength=${this.maxlength}
124
- ?disabled=${this.disabled}
125
- ?hasError=${this.hasError}
126
- ?hasFieldset=${this.hasFieldset}
127
- ?inline=${this.inline}
128
- ?required=${this.required}
129
- ?optionalTag=${this.optionalTag}
130
- ?requiredTag=${this.requiredTag}
131
- ?useWrapper=${this.useWrapper}
132
- .optionalText=${this.optionalText}
133
- .requiredText=${this.requiredText}
134
- .tagText=${this.tagText}
135
- .errorMessage=${this.errorMessage}
136
- .helptext=${this.helptext}
137
- .helptextDropdown=${this.helptextDropdown}
138
- .helptextDropdownButton=${this.helptextDropdownButton}
139
- .ariaDescribedBy=${this.ariaDescribedBy}
140
- class="pkt-datepicker"
141
- >
142
- <div class="pkt-contents" ${r.n(this.helptextSlot)} name="helptext" slot="helptext"></div>
143
- ${this.multiple?this.renderTags():s.E}
144
- <div
145
- class="pkt-datepicker__inputs ${this.range&&this.showRangeLabels?"pkt-input__range-inputs":""}"
146
- >
147
- <div class="pkt-input__container">
148
- ${this.range?this.renderRangeInput():this.multiple?this.renderMultipleInput():this.renderInput()}
149
- <button
150
- class="${d.e(this.buttonClasses)}"
151
- type="button"
152
- @click=${this.toggleCalendar}
153
- @keydown=${t=>{(t.key==="Enter"||t.key===" "||t.key==="Space")&&(t.preventDefault(),this.toggleCalendar(t))}}
154
- ?disabled=${this.disabled}
155
- ${r.n(this.btnRef)}
156
- >
157
- <pkt-icon name="calendar"></pkt-icon>
158
- <span class="pkt-btn__text">${this.strings.calendar.buttonAltText}</span>
159
- </button>
160
- </div>
161
- </div>
162
- </pkt-input-wrapper>
163
- ${this.renderCalendar()}
164
- `}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()}clearInputValue(){this._value=[],this.value=""}};n([s.n({type:String,reflect:!0})],exports.PktDatepicker.prototype,"value",1);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:o.converters.csvToArray})],exports.PktDatepicker.prototype,"excludedates",2);n([s.n({converter:o.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([v.r()],exports.PktDatepicker.prototype,"inputClasses",2);n([v.r()],exports.PktDatepicker.prototype,"buttonClasses",2);exports.PktDatepicker=n([s.t("pkt-datepicker")],exports.PktDatepicker);
@@ -1,49 +0,0 @@
1
- "use strict";const h=require("./element-6DBpyGQm.cjs"),p=require("./state-DPobt-Yz.cjs"),r=require("./ref-iJtiv3o2.cjs"),l=require("./if-defined-Cni-RHLS.cjs"),d=require("./input-element-C4xJoM-X.cjs"),c=require("./pkt-options-controller-CiuBG6Lt.cjs"),v=require("./pkt-slot-controller-BzddBp7z.cjs");require("./input-wrapper-CZ-a00V7.cjs");var f=Object.defineProperty,b=Object.getOwnPropertyDescriptor,a=(u,t,e,s)=>{for(var i=s>1?void 0:s?b(t,e):t,o=u.length-1,n;o>=0;o--)(n=u[o])&&(i=(s?n(t,e,i):n(i))||i);return s&&i&&f(t,e,i),i};exports.PktSelect=class extends d.PktInputElement{constructor(){super(),this.inputRef=r.e(),this.helptextSlot=r.e(),this.options=[],this.value="",this._options=[],this.selectedIndex=-1,this.selectedOptions=void 0,this.optionsController=new c.PktOptionsSlotController(this),this.slotController=new v.PktSlotController(this,this.helptextSlot),this.slotController.skipOptions=!0}connectedCallback(){super.connectedCallback();const t=this.options.length>0,e=this.optionsController.nodes.length&&this.optionsController.nodes.length>0;!t&&e?this.optionsController.nodes.forEach(s=>{const i={value:s.hasAttribute("value")?s.getAttribute("value")??"":s.textContent??"",label:s.textContent||s.getAttribute("value")||"",disabled:s.hasAttribute("disabled"),selected:s.hasAttribute("selected"),hidden:s.hasAttribute("data-hidden")};s.getAttribute("selected")&&!this.value&&(this.value=i.value),this._options.push(i)}):(this._options=this.options,this._options.forEach(s=>{s.selected&&!this.value&&(this.value=s.value)}))}add(t,e){var s,i,o;(s=this.inputRef.value)==null||s.add(t,e),this._options.push({value:t.value||t.text,label:t.text||t.value,selected:t.selected,disabled:t.disabled}),t.selected&&(this.value=t.value||t.text,this.selectedIndex=this.returnNumberOrNull((i=this.inputRef.value)==null?void 0:i.selectedIndex),this.selectedOptions=(o=this.inputRef.value)==null?void 0:o.selectedOptions),this.requestUpdate()}remove(t){var e,s;typeof t=="number"&&(this.selectedIndex===t&&(this.value=((e=this._options[0])==null?void 0:e.value)||""),(s=this.inputRef.value)==null||s.remove(t))}item(t){var e;return(e=this.inputRef.value)==null?void 0:e.item(t)}namedItem(t){var e;return(e=this.inputRef.value)==null?void 0:e.namedItem(t)}showPicker(){var t;(t=this.inputRef.value)==null||t.showPicker()}attributeChangedCallback(t,e,s){var i,o;t==="options"&&(this._options=s?JSON.parse(s):[]),t==="value"&&this.value!==e&&(this.selectedIndex=this.touched?this.returnNumberOrNull((i=this.inputRef.value)==null?void 0:i.selectedIndex):this.options.findIndex(n=>n.value===s),this.selectedOptions=(o=this.inputRef.value)==null?void 0:o.selectedOptions,this.valueChanged(s,e)),super.attributeChangedCallback(t,e,s)}update(t){var e,s;super.update(t),t.has("options")&&(this._options=this.options,this.requestUpdate("_options"),!this.value&&this._options.length>0&&(this.value=this._options[0].value,this.selectedIndex=0)),t.has("value")&&this.value!==t.get("value")&&(this.selectedIndex=this.touched?this.returnNumberOrNull((e=this.inputRef.value)==null?void 0:e.selectedIndex):this.options.findIndex(i=>i.value===this.value),this.selectedOptions=(s=this.inputRef.value)==null?void 0:s.selectedOptions,this.valueChanged(this.value,t.get("value"))),t.has("id")&&!this.name&&this.id&&(this.name=this.id)}firstUpdated(t){var e;super.firstUpdated(t),this.options.length&&(this._options=this.options),!this.value&&this._options.length>0?(this.value=this._options[0].value,this.selectedIndex=0):this.selectedIndex=this._options.findIndex(s=>s.value===this.value),this.selectedOptions=(e=this.inputRef.value)==null?void 0:e.selectedOptions}render(){const t=`pkt-input ${this.fullwidth?"pkt-input--fullwidth":""}`;return h.x`
2
- <pkt-input-wrapper
3
- ?counter=${this.counter}
4
- ?disabled=${this.disabled}
5
- ?hasError=${this.hasError}
6
- ?hasFieldset=${this.hasFieldset}
7
- ?inline=${this.inline}
8
- ?optionalTag=${this.optionalTag}
9
- ?requiredTag=${this.requiredTag}
10
- ?useWrapper=${this.useWrapper}
11
- ariaDescribedBy=${l.o(this.ariaDescribedBy)}
12
- class="pkt-select"
13
- errorMessage=${l.o(this.errorMessage)}
14
- forId=${this.id+"-input"}
15
- helptext=${l.o(this.helptext)}
16
- helptextDropdown=${l.o(this.helptextDropdown)}
17
- helptextDropdownButton=${l.o(this.helptextDropdownButton)}
18
- label=${l.o(this.label)}
19
- optionalText=${l.o(this.optionalText)}
20
- requiredText=${l.o(this.requiredText)}
21
- tagText=${l.o(this.tagText)}
22
- >
23
- <select
24
- class=${t}
25
- aria-invalid=${this.hasError}
26
- aria-errormessage=${`${this.id}-error`}
27
- aria-labelledby=${l.o(this.ariaLabelledby)}
28
- ?disabled=${this.disabled}
29
- id=${this.id+"-input"}
30
- name=${(this.name||this.id)+"-input"}
31
- value=${this.value}
32
- @change=${e=>{this.touched=!0,this.value=e.target.value,e.stopImmediatePropagation()}}
33
- @input=${e=>{this.onInput(),e.stopImmediatePropagation()}}
34
- @focus=${e=>{this.onFocus(),e.stopImmediatePropagation()}}
35
- @blur=${e=>{this.onBlur(),e.stopImmediatePropagation()}}
36
- ${r.n(this.inputRef)}
37
- >
38
- ${this._options.length>0?this._options.map(e=>h.x`<option
39
- value=${e.value}
40
- ?selected=${this.value==e.value||e.selected}
41
- ?disabled=${e.disabled}
42
- ?hidden=${e.hidden}
43
- >
44
- ${e.label}
45
- </option>`):""}
46
- </select>
47
- <div class="pkt-contents" ${r.n(this.helptextSlot)} name="helptext" slot="helptext"></div>
48
- </pkt-input-wrapper>
49
- `}returnNumberOrNull(t){return t==null||isNaN(t)?null:t}};a([h.n({type:Array})],exports.PktSelect.prototype,"options",2);a([h.n({type:String})],exports.PktSelect.prototype,"value",2);a([p.r()],exports.PktSelect.prototype,"_options",2);exports.PktSelect=a([h.t("pkt-select")],exports.PktSelect);
@@ -1,157 +0,0 @@
1
- import { x as p, n as c, a as v } from "./element-CgEWt74-.js";
2
- import { r as f } from "./state-Bo2bck5_.js";
3
- import { e as u, n as d } from "./ref-BBYSqgeW.js";
4
- import { o } from "./if-defined-CmuO4Vz9.js";
5
- import { P as b } from "./input-element-NnrDmp4r.js";
6
- import { P as $ } from "./pkt-options-controller-CZO1nxZ8.js";
7
- import { P as x } from "./pkt-slot-controller-BPGj-LC5.js";
8
- import "./input-wrapper-Dr__Sxql.js";
9
- var m = Object.defineProperty, g = Object.getOwnPropertyDescriptor, n = (t, e, s, i) => {
10
- for (var l = i > 1 ? void 0 : i ? g(e, s) : e, h = t.length - 1, r; h >= 0; h--)
11
- (r = t[h]) && (l = (i ? r(e, s, l) : r(l)) || l);
12
- return i && l && m(e, s, l), l;
13
- };
14
- let a = class extends b {
15
- constructor() {
16
- super(), this.inputRef = u(), this.helptextSlot = u(), this.options = [], this.value = "", this._options = [], this.selectedIndex = -1, this.selectedOptions = void 0, this.optionsController = new $(this), this.slotController = new x(this, this.helptextSlot), this.slotController.skipOptions = !0;
17
- }
18
- // Used for initilization
19
- connectedCallback() {
20
- super.connectedCallback();
21
- const t = this.options.length > 0, e = this.optionsController.nodes.length && this.optionsController.nodes.length > 0;
22
- !t && e ? this.optionsController.nodes.forEach((s) => {
23
- const i = {
24
- value: s.hasAttribute("value") ? s.getAttribute("value") ?? "" : s.textContent ?? "",
25
- label: s.textContent || s.getAttribute("value") || "",
26
- disabled: s.hasAttribute("disabled"),
27
- selected: s.hasAttribute("selected"),
28
- hidden: s.hasAttribute("data-hidden")
29
- };
30
- s.getAttribute("selected") && !this.value && (this.value = i.value), this._options.push(i);
31
- }) : (this._options = this.options, this._options.forEach((s) => {
32
- s.selected && !this.value && (this.value = s.value);
33
- }));
34
- }
35
- // Support native Select method `add`
36
- add(t, e) {
37
- var s, i, l;
38
- (s = this.inputRef.value) == null || s.add(t, e), this._options.push({
39
- value: t.value || t.text,
40
- label: t.text || t.value,
41
- selected: t.selected,
42
- disabled: t.disabled
43
- }), t.selected && (this.value = t.value || t.text, this.selectedIndex = this.returnNumberOrNull((i = this.inputRef.value) == null ? void 0 : i.selectedIndex), this.selectedOptions = (l = this.inputRef.value) == null ? void 0 : l.selectedOptions), this.requestUpdate();
44
- }
45
- // Support native Select method `remove`
46
- remove(t) {
47
- var e, s;
48
- typeof t == "number" && (this.selectedIndex === t && (this.value = ((e = this._options[0]) == null ? void 0 : e.value) || ""), (s = this.inputRef.value) == null || s.remove(t));
49
- }
50
- // Support native Select method `item`
51
- item(t) {
52
- var e;
53
- return (e = this.inputRef.value) == null ? void 0 : e.item(t);
54
- }
55
- // Support native Select method `namedItem`
56
- namedItem(t) {
57
- var e;
58
- return (e = this.inputRef.value) == null ? void 0 : e.namedItem(t);
59
- }
60
- // Support native Select method `showPicker`
61
- showPicker() {
62
- var t;
63
- (t = this.inputRef.value) == null || t.showPicker();
64
- }
65
- attributeChangedCallback(t, e, s) {
66
- var i, l;
67
- t === "options" && (this._options = s ? JSON.parse(s) : []), t === "value" && this.value !== e && (this.selectedIndex = this.touched ? this.returnNumberOrNull((i = this.inputRef.value) == null ? void 0 : i.selectedIndex) : this.options.findIndex((h) => h.value === s), this.selectedOptions = (l = this.inputRef.value) == null ? void 0 : l.selectedOptions, this.valueChanged(s, e)), super.attributeChangedCallback(t, e, s);
68
- }
69
- update(t) {
70
- var e, s;
71
- super.update(t), t.has("options") && (this._options = this.options, this.requestUpdate("_options"), !this.value && this._options.length > 0 && (this.value = this._options[0].value, this.selectedIndex = 0)), t.has("value") && this.value !== t.get("value") && (this.selectedIndex = this.touched ? this.returnNumberOrNull((e = this.inputRef.value) == null ? void 0 : e.selectedIndex) : this.options.findIndex((i) => i.value === this.value), this.selectedOptions = (s = this.inputRef.value) == null ? void 0 : s.selectedOptions, this.valueChanged(this.value, t.get("value"))), t.has("id") && !this.name && this.id && (this.name = this.id);
72
- }
73
- firstUpdated(t) {
74
- var e;
75
- super.firstUpdated(t), this.options.length && (this._options = this.options), !this.value && this._options.length > 0 ? (this.value = this._options[0].value, this.selectedIndex = 0) : this.selectedIndex = this._options.findIndex((s) => s.value === this.value), this.selectedOptions = (e = this.inputRef.value) == null ? void 0 : e.selectedOptions;
76
- }
77
- render() {
78
- const t = `pkt-input ${this.fullwidth ? "pkt-input--fullwidth" : ""}`;
79
- return p`
80
- <pkt-input-wrapper
81
- ?counter=${this.counter}
82
- ?disabled=${this.disabled}
83
- ?hasError=${this.hasError}
84
- ?hasFieldset=${this.hasFieldset}
85
- ?inline=${this.inline}
86
- ?optionalTag=${this.optionalTag}
87
- ?requiredTag=${this.requiredTag}
88
- ?useWrapper=${this.useWrapper}
89
- ariaDescribedBy=${o(this.ariaDescribedBy)}
90
- class="pkt-select"
91
- errorMessage=${o(this.errorMessage)}
92
- forId=${this.id + "-input"}
93
- helptext=${o(this.helptext)}
94
- helptextDropdown=${o(this.helptextDropdown)}
95
- helptextDropdownButton=${o(this.helptextDropdownButton)}
96
- label=${o(this.label)}
97
- optionalText=${o(this.optionalText)}
98
- requiredText=${o(this.requiredText)}
99
- tagText=${o(this.tagText)}
100
- >
101
- <select
102
- class=${t}
103
- aria-invalid=${this.hasError}
104
- aria-errormessage=${`${this.id}-error`}
105
- aria-labelledby=${o(this.ariaLabelledby)}
106
- ?disabled=${this.disabled}
107
- id=${this.id + "-input"}
108
- name=${(this.name || this.id) + "-input"}
109
- value=${this.value}
110
- @change=${(e) => {
111
- this.touched = !0, this.value = e.target.value, e.stopImmediatePropagation();
112
- }}
113
- @input=${(e) => {
114
- this.onInput(), e.stopImmediatePropagation();
115
- }}
116
- @focus=${(e) => {
117
- this.onFocus(), e.stopImmediatePropagation();
118
- }}
119
- @blur=${(e) => {
120
- this.onBlur(), e.stopImmediatePropagation();
121
- }}
122
- ${d(this.inputRef)}
123
- >
124
- ${this._options.length > 0 ? this._options.map(
125
- (e) => p`<option
126
- value=${e.value}
127
- ?selected=${this.value == e.value || e.selected}
128
- ?disabled=${e.disabled}
129
- ?hidden=${e.hidden}
130
- >
131
- ${e.label}
132
- </option>`
133
- ) : ""}
134
- </select>
135
- <div class="pkt-contents" ${d(this.helptextSlot)} name="helptext" slot="helptext"></div>
136
- </pkt-input-wrapper>
137
- `;
138
- }
139
- returnNumberOrNull(t) {
140
- return t == null || isNaN(t) ? null : t;
141
- }
142
- };
143
- n([
144
- c({ type: Array })
145
- ], a.prototype, "options", 2);
146
- n([
147
- c({ type: String })
148
- ], a.prototype, "value", 2);
149
- n([
150
- f()
151
- ], a.prototype, "_options", 2);
152
- a = n([
153
- v("pkt-select")
154
- ], a);
155
- export {
156
- a as P
157
- };