@limetech/lime-elements 37.53.0 → 37.53.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/lime-elements.cjs.js +1 -1
  3. package/dist/cjs/limel-date-picker.cjs.entry.js +5 -20
  4. package/dist/cjs/limel-date-picker.cjs.entry.js.map +1 -1
  5. package/dist/cjs/limel-flatpickr-adapter.cjs.entry.js +24 -20
  6. package/dist/cjs/limel-flatpickr-adapter.cjs.entry.js.map +1 -1
  7. package/dist/cjs/loader.cjs.js +1 -1
  8. package/dist/collection/components/date-picker/date-picker.js +5 -24
  9. package/dist/collection/components/date-picker/date-picker.js.map +1 -1
  10. package/dist/collection/components/date-picker/flatpickr-adapter/flatpickr-adapter.js +4 -1
  11. package/dist/collection/components/date-picker/flatpickr-adapter/flatpickr-adapter.js.map +1 -1
  12. package/dist/collection/components/date-picker/pickers/Picker.js +20 -19
  13. package/dist/collection/components/date-picker/pickers/Picker.js.map +1 -1
  14. package/dist/esm/lime-elements.js +1 -1
  15. package/dist/esm/limel-date-picker.entry.js +5 -20
  16. package/dist/esm/limel-date-picker.entry.js.map +1 -1
  17. package/dist/esm/limel-flatpickr-adapter.entry.js +24 -20
  18. package/dist/esm/limel-flatpickr-adapter.entry.js.map +1 -1
  19. package/dist/esm/loader.js +1 -1
  20. package/dist/lime-elements/lime-elements.esm.js +1 -1
  21. package/dist/lime-elements/lime-elements.esm.js.map +1 -1
  22. package/dist/lime-elements/p-5224d7bb.entry.js +2 -0
  23. package/dist/lime-elements/p-5224d7bb.entry.js.map +1 -0
  24. package/dist/lime-elements/{p-42b6ba6d.entry.js → p-5a035a41.entry.js} +3 -3
  25. package/dist/lime-elements/p-5a035a41.entry.js.map +1 -0
  26. package/dist/types/components/date-picker/date-picker.d.ts +0 -2
  27. package/dist/types/components/date-picker/pickers/Picker.d.ts +3 -2
  28. package/package.json +1 -1
  29. package/dist/lime-elements/p-42b6ba6d.entry.js.map +0 -1
  30. package/dist/lime-elements/p-b76d8f4f.entry.js +0 -2
  31. package/dist/lime-elements/p-b76d8f4f.entry.js.map +0 -1
@@ -95,7 +95,6 @@ const DatePicker = class {
95
95
  this.format = undefined;
96
96
  this.language = 'en';
97
97
  this.formatter = undefined;
98
- this.formattedValue = undefined;
99
98
  this.internalFormat = undefined;
100
99
  this.showPortal = false;
101
100
  this.handleCalendarChange = this.handleCalendarChange.bind(this);
@@ -113,7 +112,6 @@ const DatePicker = class {
113
112
  componentWillLoad() {
114
113
  this.useNative = !this.readonly && (isIOSDevice() || isAndroidDevice());
115
114
  this.updateInternalFormatAndType();
116
- this.formattedValue = this.formatValue(this.value);
117
115
  }
118
116
  componentWillUpdate() {
119
117
  this.updateInternalFormatAndType();
@@ -126,29 +124,22 @@ const DatePicker = class {
126
124
  inputProps.trailingIcon = 'clear_symbol';
127
125
  }
128
126
  if (this.useNative) {
129
- return (h("limel-input-field", { disabled: this.disabled, readonly: this.readonly, invalid: this.invalid, label: this.label, helperText: this.helperText, required: this.required, value: this.formattedValue, type: this.nativeType, onChange: this.nativeChangeHandler }));
127
+ return (h("limel-input-field", { disabled: this.disabled, readonly: this.readonly, invalid: this.invalid, label: this.label, helperText: this.helperText, required: this.required, value: this.formatValue(this.value), type: this.nativeType, onChange: this.nativeChangeHandler }));
130
128
  }
131
129
  const dropdownZIndex = getComputedStyle(this.host).getPropertyValue('--dropdown-z-index');
130
+ const formatter = this.formatter || this.formatValue;
132
131
  return [
133
- h("limel-input-field", Object.assign({ disabled: this.disabled, readonly: this.readonly, invalid: this.invalid, label: this.label, placeholder: this.placeholder, helperText: this.helperText, required: this.required, value: this.formattedValue, onFocus: this.showCalendar, onBlur: this.hideCalendar, onClick: this.onInputClick, onChange: this.handleInputElementChange, ref: (el) => (this.textField = el) }, inputProps)),
134
- h("limel-portal", { containerId: this.portalId, visible: this.showPortal, containerStyle: { 'z-index': dropdownZIndex } }, h("limel-flatpickr-adapter", { format: this.internalFormat, language: this.language, type: this.type, value: this.value, ref: (el) => (this.datePickerCalendar = el), isOpen: this.showPortal, formatter: this.formatValue, onChange: this.handleCalendarChange })),
132
+ h("limel-input-field", Object.assign({ disabled: this.disabled, readonly: this.readonly, invalid: this.invalid, label: this.label, placeholder: this.placeholder, helperText: this.helperText, required: this.required, value: this.value ? formatter(this.value) : '', onFocus: this.showCalendar, onBlur: this.hideCalendar, onClick: this.onInputClick, onChange: this.handleInputElementChange, ref: (el) => (this.textField = el) }, inputProps)),
133
+ h("limel-portal", { containerId: this.portalId, visible: this.showPortal, containerStyle: { 'z-index': dropdownZIndex } }, h("limel-flatpickr-adapter", { format: this.internalFormat, language: this.language, type: this.type, value: this.value, ref: (el) => (this.datePickerCalendar = el), isOpen: this.showPortal, formatter: formatter, onChange: this.handleCalendarChange })),
135
134
  ];
136
135
  }
137
- onValueChange(newValue, oldValue) {
138
- if (newValue !== oldValue && newValue !== this.formattedValue) {
139
- this.formattedValue = this.formatValue(this.value);
140
- }
141
- }
142
136
  updateInternalFormatAndType() {
143
137
  this.nativeType = nativeTypeForConsumerType[this.type || 'default'];
144
138
  this.nativeFormat = nativeFormatForType[this.nativeType];
145
139
  if (this.useNative) {
146
140
  this.internalFormat = this.nativeFormat;
147
141
  }
148
- else if (this.formatter) {
149
- this.formatValue = this.formatter;
150
- }
151
- else if (this.format) {
142
+ else if (this.formatter || this.format) {
152
143
  this.internalFormat = this.format;
153
144
  }
154
145
  else {
@@ -158,7 +149,6 @@ const DatePicker = class {
158
149
  nativeChangeHandler(event) {
159
150
  event.stopPropagation();
160
151
  const date = this.dateFormatter.parseDate(event.detail, this.internalFormat);
161
- this.formattedValue = event.detail;
162
152
  this.change.emit(date);
163
153
  }
164
154
  showCalendar(event) {
@@ -203,7 +193,6 @@ const DatePicker = class {
203
193
  }
204
194
  handleCalendarChange(event) {
205
195
  const date = event.detail;
206
- this.formattedValue = this.formatValue(date);
207
196
  event.stopPropagation();
208
197
  if (this.pickerIsAutoClosing()) {
209
198
  this.hideCalendar();
@@ -229,13 +218,9 @@ const DatePicker = class {
229
218
  return this.type !== 'datetime' && this.type !== 'time';
230
219
  }
231
220
  clearValue() {
232
- this.formattedValue = '';
233
221
  this.change.emit(null);
234
222
  }
235
223
  get host() { return getElement(this); }
236
- static get watchers() { return {
237
- "value": ["onValueChange"]
238
- }; }
239
224
  };
240
225
  DatePicker.style = datePickerCss;
241
226
 
@@ -1 +1 @@
1
- {"file":"limel-date-picker.entry.js","mappings":";;;;;;;;;;;;MAUa,aAAa;EAGtB,YAAmB,WAAmB,IAAI;IACtC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;GAC5B;EAEM,UAAU,CAAC,IAAU,EAAE,UAAkB;IAC5C,IAAI,IAAI,EAAE;MACN,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;KACrE;IAED,OAAO,EAAE,CAAC;GACb;EAEM,SAAS,CAAC,IAAY,EAAE,UAAkB;IAC7C,IAAI,IAAI,EAAE;MACN,OAAO,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,MAAM,EAAE,CAAC;KAC5C;IAED,OAAO,IAAI,CAAC;GACf;EAEM,WAAW;IACd,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,EAAE;MACxB,OAAO,IAAI,CAAC;KACf;IAED,OAAO,IAAI,CAAC,QAAQ,CAAC;GACxB;EAEM,aAAa,CAAC,IAAc;IAC/B,QACI;MACI,IAAI,EAAE,GAAG;MACT,IAAI,EAAE,IAAI;MACV,IAAI,EAAE,YAAY;MAClB,KAAK,EAAE,SAAS;MAChB,OAAO,EAAE,WAAW;MACpB,IAAI,EAAE,MAAM;MACZ,QAAQ,EAAE,QAAQ;KACrB,CAAC,IAAI,CAAC,IAAI,QAAQ,EACrB;GACL;;;ACrDL,MAAM,aAAa,GAAG,yHAAyH;;AC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,CAAC,iBAAiB,CAAC,CAC7D,CAAC;IACF,YAAY,CAAC,oBAAoB,EAAE,CAAC,eAAe,EAAE,CAAC;GACzD;EAaO,oBAAoB,CAAC,KAAK;IAC9B,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC;IAC1B,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC7C,KAAK,CAAC,eAAe,EAAE,CAAC;IACxB,IAAI,IAAI,CAAC,mBAAmB,EAAE,EAAE;MAC5B,IAAI,CAAC,YAAY,EAAE,CAAC;KACvB;IAED,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;GAC1B;EAEO,YAAY,CAAC,KAAK;IACtB,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,EAAE;MAChC,OAAO;KACV;IAED,IAAI,IAAI,CAAC,UAAU,EAAE;MACjB,OAAO;KACV;IAED,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;GAC5B;EAEO,wBAAwB,CAAC,KAAK;IAClC,IAAI,KAAK,CAAC,MAAM,KAAK,EAAE,EAAE;MACrB,IAAI,CAAC,UAAU,EAAE,CAAC;KACrB;IAED,KAAK,CAAC,eAAe,EAAE,CAAC;GAC3B;EAEO,mBAAmB;IACvB,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC;GAC3D;EAEO,UAAU;IACd,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;IACzB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;GAC1B;;;;;;;;;;","names":[],"sources":["./src/components/date-picker/dateFormatter.ts","./src/components/date-picker/date-picker.scss?tag=limel-date-picker&encapsulation=shadow","./src/components/date-picker/date-picker.tsx"],"sourcesContent":["import 'moment/locale/da';\nimport 'moment/locale/de';\nimport 'moment/locale/fi';\nimport 'moment/locale/fr';\nimport 'moment/locale/nb';\nimport 'moment/locale/nl';\nimport 'moment/locale/sv';\nimport moment from 'moment/moment';\nimport { DateType } from './date.types';\n\nexport class DateFormatter {\n private language: string;\n\n public constructor(language: string = 'en') {\n this.language = language;\n }\n\n public formatDate(date: Date, dateFormat: string) {\n if (date) {\n return moment(date).locale(this.getLanguage()).format(dateFormat);\n }\n\n return '';\n }\n\n public parseDate(date: string, dateFormat: string) {\n if (date) {\n return moment(date, dateFormat).toDate();\n }\n\n return null;\n }\n\n public getLanguage() {\n if (this.language === 'no') {\n return 'nb';\n }\n\n return this.language;\n }\n\n public getDateFormat(type: DateType) {\n return (\n {\n date: 'L',\n time: 'LT',\n week: '[w] W GGGG',\n month: 'MM/YYYY',\n quarter: '[Q]Q YYYY',\n year: 'YYYY',\n datetime: 'L - LT',\n }[type] || 'L - LT'\n );\n }\n}\n","// Note! The `--dropdown-z-index` property is used from `date-picker.tsx`.\n/**\n * @prop --dropdown-z-index: z-index of the dropdown menu.\n */\n\n:host(limel-date-picker) {\n position: relative;\n}\n\nlimel-input-field[disabled],\nlimel-input-field[readonly] {\n pointer-events: none;\n}\n","import {\n Component,\n h,\n Prop,\n State,\n Element,\n EventEmitter,\n Event,\n Watch,\n} from '@stencil/core';\nimport { createRandomString } from '../../util/random-string';\nimport { isAndroidDevice, isIOSDevice } from '../../util/device';\nimport { DateType, Languages } from '../date-picker/date.types';\nimport { InputType } from '../input-field/input-field.types';\nimport { DateFormatter } from './dateFormatter';\nimport { MDCTextField } from '@material/textfield';\n\n// tslint:disable:no-duplicate-string\nconst nativeTypeForConsumerType: { [key: string]: InputType } = {\n date: 'date',\n time: 'time',\n // Mobile Safari feature detects as capable of input type `week`,\n // but it just displays a non-interactive input\n // TODO(ads): remove this when support is decent on iOS!\n week: isIOSDevice() ? 'date' : 'week',\n month: 'month',\n quarter: 'date',\n year: 'date',\n datetime: 'datetime-local',\n default: 'datetime-local',\n};\nconst nativeFormatForType = {\n date: 'Y-MM-DD',\n time: 'HH:mm',\n week: 'GGGG-[W]WW',\n month: 'Y-MM',\n 'datetime-local': 'Y-MM-DD[T]HH:mm',\n};\n// tslint:enable:no-duplicate-string\n\n/**\n * @exampleComponent limel-example-date-picker-datetime\n * @exampleComponent limel-example-date-picker-date\n * @exampleComponent limel-example-date-picker-time\n * @exampleComponent limel-example-date-picker-week\n * @exampleComponent limel-example-date-picker-month\n * @exampleComponent limel-example-date-picker-quarter\n * @exampleComponent limel-example-date-picker-year\n * @exampleComponent limel-example-date-picker-formatted\n * @exampleComponent limel-example-date-picker-programmatic-change\n * @exampleComponent limel-example-date-picker-composite\n * @exampleComponent limel-example-date-picker-custom-formatter\n */\n@Component({\n tag: 'limel-date-picker',\n shadow: true,\n styleUrl: 'date-picker.scss',\n})\nexport class DatePicker {\n /**\n * Set to `true` to disable the field.\n * Use `disabled` to indicate that the field can normally be interacted\n * with, but is currently disabled. This tells the user that if certain\n * requirements are met, the field may become enabled again.\n */\n @Prop({ reflect: true })\n public disabled = false;\n\n /**\n * Set to `true` to make the field read-only.\n * Use `readonly` when the field is only there to present the data it holds,\n * and will not become possible for the current user to edit.\n */\n @Prop({ reflect: true })\n public readonly = false;\n\n /**\n * Set to `true` to indicate that the current value of the date picker is\n * invalid.\n */\n @Prop({ reflect: true })\n public invalid = false;\n\n /**\n * Text to display next to the date picker\n */\n @Prop({ reflect: true })\n public label: string;\n\n /**\n * The placeholder text shown inside the input field, when the field is focused and empty\n */\n @Prop({ reflect: true })\n public placeholder: string;\n\n /**\n * Optional helper text to display below the input field when it has focus\n */\n @Prop({ reflect: true })\n public helperText: string;\n\n /**\n * Set to `true` to indicate that the field is required.\n */\n @Prop({ reflect: true })\n public required = false;\n\n /**\n * The value of the field.\n */\n @Prop()\n public value: Date;\n\n /**\n * Type of date picker.\n */\n @Prop({ reflect: true })\n public type: DateType = 'datetime';\n\n /**\n * Format to display the selected date in.\n */\n @Prop({ reflect: true })\n public format: string;\n\n /**\n * Defines the localisation for translations and date formatting.\n * Property `format` customizes the localized date format.\n */\n @Prop({ reflect: true })\n public language: Languages = 'en';\n\n /**\n * Custom formatting function. Will be used for date formatting.\n *\n * :::note\n * overrides `format` and `language`\n * :::\n */\n @Prop()\n public formatter?: (date: Date) => string;\n\n /**\n * Emitted when the date picker value is changed.\n */\n @Event()\n private change: EventEmitter<Date>;\n\n @Element()\n private host: HTMLLimelDatePickerElement;\n\n @State()\n private formattedValue: string;\n\n @State()\n private internalFormat: string;\n @State()\n private showPortal = false;\n\n private useNative: boolean;\n private nativeType: InputType;\n private nativeFormat: string;\n private textField: HTMLElement;\n private datePickerCalendar: HTMLLimelFlatpickrAdapterElement;\n private portalId = `date-picker-calendar-${createRandomString()}`;\n private dateFormatter: DateFormatter;\n\n constructor() {\n this.handleCalendarChange = this.handleCalendarChange.bind(this);\n this.handleInputElementChange =\n this.handleInputElementChange.bind(this);\n this.showCalendar = this.showCalendar.bind(this);\n this.dateFormatter = new DateFormatter(this.language);\n this.clearValue = this.clearValue.bind(this);\n this.hideCalendar = this.hideCalendar.bind(this);\n this.onInputClick = this.onInputClick.bind(this);\n this.nativeChangeHandler = this.nativeChangeHandler.bind(this);\n this.preventBlurFromCalendarContainer =\n this.preventBlurFromCalendarContainer.bind(this);\n }\n\n public componentWillLoad() {\n this.useNative = !this.readonly && (isIOSDevice() || isAndroidDevice());\n\n this.updateInternalFormatAndType();\n\n this.formattedValue = this.formatValue(this.value);\n }\n\n public componentWillUpdate() {\n this.updateInternalFormatAndType();\n }\n\n public render() {\n const inputProps: any = {\n onAction: this.clearValue,\n };\n\n if (this.value && !this.readonly) {\n inputProps.trailingIcon = 'clear_symbol';\n }\n\n if (this.useNative) {\n return (\n <limel-input-field\n disabled={this.disabled}\n readonly={this.readonly}\n invalid={this.invalid}\n label={this.label}\n helperText={this.helperText}\n required={this.required}\n value={this.formattedValue}\n type={this.nativeType}\n onChange={this.nativeChangeHandler}\n />\n );\n }\n\n const dropdownZIndex = getComputedStyle(this.host).getPropertyValue(\n '--dropdown-z-index',\n );\n\n return [\n <limel-input-field\n disabled={this.disabled}\n readonly={this.readonly}\n invalid={this.invalid}\n label={this.label}\n placeholder={this.placeholder}\n helperText={this.helperText}\n required={this.required}\n value={this.formattedValue}\n onFocus={this.showCalendar}\n onBlur={this.hideCalendar}\n onClick={this.onInputClick}\n onChange={this.handleInputElementChange}\n ref={(el) => (this.textField = el)}\n {...inputProps}\n />,\n <limel-portal\n containerId={this.portalId}\n visible={this.showPortal}\n containerStyle={{ 'z-index': dropdownZIndex }}\n >\n <limel-flatpickr-adapter\n format={this.internalFormat}\n language={this.language}\n type={this.type}\n value={this.value}\n ref={(el) => (this.datePickerCalendar = el)}\n isOpen={this.showPortal}\n formatter={this.formatValue}\n onChange={this.handleCalendarChange}\n />\n </limel-portal>,\n ];\n }\n\n @Watch('value')\n protected onValueChange(newValue: string, oldValue: string) {\n if (newValue !== oldValue && newValue !== this.formattedValue) {\n this.formattedValue = this.formatValue(this.value);\n }\n }\n\n private updateInternalFormatAndType() {\n this.nativeType = nativeTypeForConsumerType[this.type || 'default'];\n this.nativeFormat = nativeFormatForType[this.nativeType];\n\n if (this.useNative) {\n this.internalFormat = this.nativeFormat;\n } else if (this.formatter) {\n this.formatValue = this.formatter;\n } else if (this.format) {\n this.internalFormat = this.format;\n } else {\n this.internalFormat = this.dateFormatter.getDateFormat(this.type);\n }\n }\n\n private nativeChangeHandler(event: CustomEvent<string>) {\n event.stopPropagation();\n const date = this.dateFormatter.parseDate(\n event.detail,\n this.internalFormat,\n );\n this.formattedValue = event.detail;\n this.change.emit(date);\n }\n\n private showCalendar(event) {\n this.showPortal = true;\n const inputElement = this.textField.shadowRoot.querySelector('input');\n setTimeout(() => {\n this.datePickerCalendar.inputElement = inputElement;\n });\n event.stopPropagation();\n\n document.addEventListener('mousedown', this.documentClickListener, {\n passive: true,\n });\n\n document.addEventListener(\n 'blur',\n this.preventBlurFromCalendarContainer,\n {\n capture: true,\n },\n );\n }\n\n private preventBlurFromCalendarContainer(event) {\n // We don't want the input element to lose focus when we pick\n // a date in the calendar container.\n // This is also required in order to not close the non\n // automatically closing pickers (type datetime and time)\n // when you pick a value.\n if (event.relatedTarget === this.datePickerCalendar) {\n event.stopPropagation();\n }\n }\n\n private hideCalendar() {\n setTimeout(() => {\n this.showPortal = false;\n });\n document.removeEventListener('mousedown', this.documentClickListener);\n document.removeEventListener(\n 'blur',\n this.preventBlurFromCalendarContainer,\n );\n\n if (!this.pickerIsAutoClosing()) {\n this.fixFlatpickrFocusBug();\n }\n }\n\n private fixFlatpickrFocusBug() {\n // Flatpickr removes the focus from the input field\n // but the 'visual focus' is still there\n const mdcTextField = new MDCTextField(\n this.textField.shadowRoot.querySelector('.mdc-text-field'),\n );\n mdcTextField.getDefaultFoundation().deactivateFocus();\n }\n\n private documentClickListener = (event: MouseEvent) => {\n if (event.composedPath().includes(this.textField)) {\n return;\n }\n\n const element = document.querySelector(`#${this.portalId}`);\n if (!element.contains(event.target as Node)) {\n this.hideCalendar();\n }\n };\n\n private handleCalendarChange(event) {\n const date = event.detail;\n this.formattedValue = this.formatValue(date);\n event.stopPropagation();\n if (this.pickerIsAutoClosing()) {\n this.hideCalendar();\n }\n\n this.change.emit(date);\n }\n\n private onInputClick(event) {\n if (this.disabled || this.readonly) {\n return;\n }\n\n if (this.showPortal) {\n return;\n }\n\n this.showCalendar(event);\n }\n\n private handleInputElementChange(event) {\n if (event.detail === '') {\n this.clearValue();\n }\n\n event.stopPropagation();\n }\n\n private pickerIsAutoClosing() {\n return this.type !== 'datetime' && this.type !== 'time';\n }\n\n private clearValue() {\n this.formattedValue = '';\n this.change.emit(null);\n }\n\n private formatValue = (value: Date): string =>\n this.dateFormatter.formatDate(value, this.internalFormat);\n}\n"],"version":3}
1
+ {"file":"limel-date-picker.entry.js","mappings":";;;;;;;;;;;;MAUa,aAAa;EAGtB,YAAmB,WAAmB,IAAI;IACtC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;GAC5B;EAEM,UAAU,CAAC,IAAU,EAAE,UAAk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B;IACvB,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC;GAC3D;EAEO,UAAU;IACd,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;GAC1B;;;;;;;","names":[],"sources":["./src/components/date-picker/dateFormatter.ts","./src/components/date-picker/date-picker.scss?tag=limel-date-picker&encapsulation=shadow","./src/components/date-picker/date-picker.tsx"],"sourcesContent":["import 'moment/locale/da';\nimport 'moment/locale/de';\nimport 'moment/locale/fi';\nimport 'moment/locale/fr';\nimport 'moment/locale/nb';\nimport 'moment/locale/nl';\nimport 'moment/locale/sv';\nimport moment from 'moment/moment';\nimport { DateType } from './date.types';\n\nexport class DateFormatter {\n private language: string;\n\n public constructor(language: string = 'en') {\n this.language = language;\n }\n\n public formatDate(date: Date, dateFormat: string) {\n if (date) {\n return moment(date).locale(this.getLanguage()).format(dateFormat);\n }\n\n return '';\n }\n\n public parseDate(date: string, dateFormat: string) {\n if (date) {\n return moment(date, dateFormat).toDate();\n }\n\n return null;\n }\n\n public getLanguage() {\n if (this.language === 'no') {\n return 'nb';\n }\n\n return this.language;\n }\n\n public getDateFormat(type: DateType) {\n return (\n {\n date: 'L',\n time: 'LT',\n week: '[w] W GGGG',\n month: 'MM/YYYY',\n quarter: '[Q]Q YYYY',\n year: 'YYYY',\n datetime: 'L - LT',\n }[type] || 'L - LT'\n );\n }\n}\n","// Note! The `--dropdown-z-index` property is used from `date-picker.tsx`.\n/**\n * @prop --dropdown-z-index: z-index of the dropdown menu.\n */\n\n:host(limel-date-picker) {\n position: relative;\n}\n\nlimel-input-field[disabled],\nlimel-input-field[readonly] {\n pointer-events: none;\n}\n","import {\n Component,\n h,\n Prop,\n State,\n Element,\n EventEmitter,\n Event,\n} from '@stencil/core';\nimport { createRandomString } from '../../util/random-string';\nimport { isAndroidDevice, isIOSDevice } from '../../util/device';\nimport { DateType, Languages } from '../date-picker/date.types';\nimport { InputType } from '../input-field/input-field.types';\nimport { DateFormatter } from './dateFormatter';\nimport { MDCTextField } from '@material/textfield';\n\n// tslint:disable:no-duplicate-string\nconst nativeTypeForConsumerType: { [key: string]: InputType } = {\n date: 'date',\n time: 'time',\n // Mobile Safari feature detects as capable of input type `week`,\n // but it just displays a non-interactive input\n // TODO(ads): remove this when support is decent on iOS!\n week: isIOSDevice() ? 'date' : 'week',\n month: 'month',\n quarter: 'date',\n year: 'date',\n datetime: 'datetime-local',\n default: 'datetime-local',\n};\nconst nativeFormatForType = {\n date: 'Y-MM-DD',\n time: 'HH:mm',\n week: 'GGGG-[W]WW',\n month: 'Y-MM',\n 'datetime-local': 'Y-MM-DD[T]HH:mm',\n};\n// tslint:enable:no-duplicate-string\n\n/**\n * @exampleComponent limel-example-date-picker-datetime\n * @exampleComponent limel-example-date-picker-date\n * @exampleComponent limel-example-date-picker-time\n * @exampleComponent limel-example-date-picker-week\n * @exampleComponent limel-example-date-picker-month\n * @exampleComponent limel-example-date-picker-quarter\n * @exampleComponent limel-example-date-picker-year\n * @exampleComponent limel-example-date-picker-formatted\n * @exampleComponent limel-example-date-picker-programmatic-change\n * @exampleComponent limel-example-date-picker-composite\n * @exampleComponent limel-example-date-picker-custom-formatter\n */\n@Component({\n tag: 'limel-date-picker',\n shadow: true,\n styleUrl: 'date-picker.scss',\n})\nexport class DatePicker {\n /**\n * Set to `true` to disable the field.\n * Use `disabled` to indicate that the field can normally be interacted\n * with, but is currently disabled. This tells the user that if certain\n * requirements are met, the field may become enabled again.\n */\n @Prop({ reflect: true })\n public disabled = false;\n\n /**\n * Set to `true` to make the field read-only.\n * Use `readonly` when the field is only there to present the data it holds,\n * and will not become possible for the current user to edit.\n */\n @Prop({ reflect: true })\n public readonly = false;\n\n /**\n * Set to `true` to indicate that the current value of the date picker is\n * invalid.\n */\n @Prop({ reflect: true })\n public invalid = false;\n\n /**\n * Text to display next to the date picker\n */\n @Prop({ reflect: true })\n public label: string;\n\n /**\n * The placeholder text shown inside the input field, when the field is focused and empty\n */\n @Prop({ reflect: true })\n public placeholder: string;\n\n /**\n * Optional helper text to display below the input field when it has focus\n */\n @Prop({ reflect: true })\n public helperText: string;\n\n /**\n * Set to `true` to indicate that the field is required.\n */\n @Prop({ reflect: true })\n public required = false;\n\n /**\n * The value of the field.\n */\n @Prop()\n public value: Date;\n\n /**\n * Type of date picker.\n */\n @Prop({ reflect: true })\n public type: DateType = 'datetime';\n\n /**\n * Format to display the selected date in.\n */\n @Prop({ reflect: true })\n public format: string;\n\n /**\n * Defines the localisation for translations and date formatting.\n * Property `format` customizes the localized date format.\n */\n @Prop({ reflect: true })\n public language: Languages = 'en';\n\n /**\n * Custom formatting function. Will be used for date formatting.\n *\n * :::note\n * overrides `format` and `language`\n * :::\n */\n @Prop()\n public formatter?: (date: Date) => string;\n\n /**\n * Emitted when the date picker value is changed.\n */\n @Event()\n private change: EventEmitter<Date>;\n\n @Element()\n private host: HTMLLimelDatePickerElement;\n\n @State()\n private internalFormat: string;\n @State()\n private showPortal = false;\n\n private useNative: boolean;\n private nativeType: InputType;\n private nativeFormat: string;\n private textField: HTMLElement;\n private datePickerCalendar: HTMLLimelFlatpickrAdapterElement;\n private portalId = `date-picker-calendar-${createRandomString()}`;\n private dateFormatter: DateFormatter;\n\n constructor() {\n this.handleCalendarChange = this.handleCalendarChange.bind(this);\n this.handleInputElementChange =\n this.handleInputElementChange.bind(this);\n this.showCalendar = this.showCalendar.bind(this);\n this.dateFormatter = new DateFormatter(this.language);\n this.clearValue = this.clearValue.bind(this);\n this.hideCalendar = this.hideCalendar.bind(this);\n this.onInputClick = this.onInputClick.bind(this);\n this.nativeChangeHandler = this.nativeChangeHandler.bind(this);\n this.preventBlurFromCalendarContainer =\n this.preventBlurFromCalendarContainer.bind(this);\n }\n\n public componentWillLoad() {\n this.useNative = !this.readonly && (isIOSDevice() || isAndroidDevice());\n\n this.updateInternalFormatAndType();\n }\n\n public componentWillUpdate() {\n this.updateInternalFormatAndType();\n }\n\n public render() {\n const inputProps: any = {\n onAction: this.clearValue,\n };\n\n if (this.value && !this.readonly) {\n inputProps.trailingIcon = 'clear_symbol';\n }\n\n if (this.useNative) {\n return (\n <limel-input-field\n disabled={this.disabled}\n readonly={this.readonly}\n invalid={this.invalid}\n label={this.label}\n helperText={this.helperText}\n required={this.required}\n value={this.formatValue(this.value)}\n type={this.nativeType}\n onChange={this.nativeChangeHandler}\n />\n );\n }\n\n const dropdownZIndex = getComputedStyle(this.host).getPropertyValue(\n '--dropdown-z-index',\n );\n\n const formatter = this.formatter || this.formatValue;\n\n return [\n <limel-input-field\n disabled={this.disabled}\n readonly={this.readonly}\n invalid={this.invalid}\n label={this.label}\n placeholder={this.placeholder}\n helperText={this.helperText}\n required={this.required}\n value={this.value ? formatter(this.value) : ''}\n onFocus={this.showCalendar}\n onBlur={this.hideCalendar}\n onClick={this.onInputClick}\n onChange={this.handleInputElementChange}\n ref={(el) => (this.textField = el)}\n {...inputProps}\n />,\n <limel-portal\n containerId={this.portalId}\n visible={this.showPortal}\n containerStyle={{ 'z-index': dropdownZIndex }}\n >\n <limel-flatpickr-adapter\n format={this.internalFormat}\n language={this.language}\n type={this.type}\n value={this.value}\n ref={(el) => (this.datePickerCalendar = el)}\n isOpen={this.showPortal}\n formatter={formatter}\n onChange={this.handleCalendarChange}\n />\n </limel-portal>,\n ];\n }\n\n private updateInternalFormatAndType() {\n this.nativeType = nativeTypeForConsumerType[this.type || 'default'];\n this.nativeFormat = nativeFormatForType[this.nativeType];\n\n if (this.useNative) {\n this.internalFormat = this.nativeFormat;\n } else if (this.formatter || this.format) {\n this.internalFormat = this.format;\n } else {\n this.internalFormat = this.dateFormatter.getDateFormat(this.type);\n }\n }\n\n private nativeChangeHandler(event: CustomEvent<string>) {\n event.stopPropagation();\n const date = this.dateFormatter.parseDate(\n event.detail,\n this.internalFormat,\n );\n this.change.emit(date);\n }\n\n private showCalendar(event) {\n this.showPortal = true;\n const inputElement = this.textField.shadowRoot.querySelector('input');\n setTimeout(() => {\n this.datePickerCalendar.inputElement = inputElement;\n });\n event.stopPropagation();\n\n document.addEventListener('mousedown', this.documentClickListener, {\n passive: true,\n });\n\n document.addEventListener(\n 'blur',\n this.preventBlurFromCalendarContainer,\n {\n capture: true,\n },\n );\n }\n\n private preventBlurFromCalendarContainer(event) {\n // We don't want the input element to lose focus when we pick\n // a date in the calendar container.\n // This is also required in order to not close the non\n // automatically closing pickers (type datetime and time)\n // when you pick a value.\n if (event.relatedTarget === this.datePickerCalendar) {\n event.stopPropagation();\n }\n }\n\n private hideCalendar() {\n setTimeout(() => {\n this.showPortal = false;\n });\n document.removeEventListener('mousedown', this.documentClickListener);\n document.removeEventListener(\n 'blur',\n this.preventBlurFromCalendarContainer,\n );\n\n if (!this.pickerIsAutoClosing()) {\n this.fixFlatpickrFocusBug();\n }\n }\n\n private fixFlatpickrFocusBug() {\n // Flatpickr removes the focus from the input field\n // but the 'visual focus' is still there\n const mdcTextField = new MDCTextField(\n this.textField.shadowRoot.querySelector('.mdc-text-field'),\n );\n mdcTextField.getDefaultFoundation().deactivateFocus();\n }\n\n private documentClickListener = (event: MouseEvent) => {\n if (event.composedPath().includes(this.textField)) {\n return;\n }\n\n const element = document.querySelector(`#${this.portalId}`);\n if (!element.contains(event.target as Node)) {\n this.hideCalendar();\n }\n };\n\n private handleCalendarChange(event) {\n const date = event.detail;\n event.stopPropagation();\n if (this.pickerIsAutoClosing()) {\n this.hideCalendar();\n }\n\n this.change.emit(date);\n }\n\n private onInputClick(event) {\n if (this.disabled || this.readonly) {\n return;\n }\n\n if (this.showPortal) {\n return;\n }\n\n this.showCalendar(event);\n }\n\n private handleInputElementChange(event) {\n if (event.detail === '') {\n this.clearValue();\n }\n\n event.stopPropagation();\n }\n\n private pickerIsAutoClosing() {\n return this.type !== 'datetime' && this.type !== 'time';\n }\n\n private clearValue() {\n this.change.emit(null);\n }\n\n private formatValue = (value: Date): string =>\n this.dateFormatter.formatDate(value, this.internalFormat);\n}\n"],"version":3}
@@ -6461,6 +6461,7 @@ var l10n = createCommonjsModule(function (module, exports) {
6461
6461
 
6462
6462
  const FlatpickrLanguages = /*@__PURE__*/getDefaultExportFromCjs(l10n);
6463
6463
 
6464
+ const ARIA_DATE_FORMAT = 'F j, Y';
6464
6465
  class Picker {
6465
6466
  constructor(dateFormat, language, change) {
6466
6467
  this.change = change;
@@ -6474,31 +6475,20 @@ class Picker {
6474
6475
  this.getWeek = this.getWeek.bind(this);
6475
6476
  this.handleClose = this.handleClose.bind(this);
6476
6477
  this.handleOnClose = this.handleOnClose.bind(this);
6477
- this.parseDate = this.parseDate.bind(this);
6478
6478
  this.getFlatpickrLang = this.getFlatpickrLang.bind(this);
6479
6479
  }
6480
6480
  init(element, container, value) {
6481
- let config = {
6482
- clickOpens: this.nativePicker,
6483
- disableMobile: !this.nativePicker,
6484
- formatDate: this.nativePicker ? undefined : this.formatDate,
6485
- parseDate: this.nativePicker ? undefined : this.parseDate,
6486
- appendTo: container,
6487
- onClose: this.handleOnClose,
6488
- defaultDate: value,
6489
- onValueUpdate: this.handleClose,
6490
- inline: !this.nativePicker,
6491
- locale: FlatpickrLanguages[this.getFlatpickrLang()] ||
6492
- FlatpickrLanguages.en,
6493
- getWeek: this.getWeek,
6494
- };
6495
- config = Object.assign(Object.assign({}, config), this.getConfig(this.nativePicker));
6481
+ const config = Object.assign({ clickOpens: this.nativePicker, disableMobile: !this.nativePicker, formatDate: this.nativePicker ? undefined : this.formatDate, appendTo: container, onClose: this.handleOnClose, defaultDate: value, onValueUpdate: this.handleClose, inline: !this.nativePicker, locale: FlatpickrLanguages[this.getFlatpickrLang()] ||
6482
+ FlatpickrLanguages.en, getWeek: this.getWeek }, this.getConfig(this.nativePicker));
6496
6483
  // Week numbers designate weeks as starting with Monday and
6497
6484
  // ending with Sunday. To make the week numbers make sense,
6498
6485
  // the calendar has to show weeks in the same way.
6499
6486
  config.locale.firstDayOfWeek = 1;
6500
6487
  this.flatpickr = flatpickr(element, config);
6501
6488
  }
6489
+ setValue(value) {
6490
+ this.flatpickr.setDate(value, false);
6491
+ }
6502
6492
  redraw() {
6503
6493
  this.flatpickr.redraw();
6504
6494
  }
@@ -6532,12 +6522,23 @@ class Picker {
6532
6522
  getPickerDate(selectedDates) {
6533
6523
  return selectedDates[0] ? new Date(selectedDates[0].toJSON()) : null;
6534
6524
  }
6525
+ get formatDate() {
6526
+ const longDateFormat = new Intl.DateTimeFormat(this.language, {
6527
+ dateStyle: 'long',
6528
+ });
6529
+ return (date, format) => {
6530
+ if (!date) {
6531
+ return '';
6532
+ }
6533
+ if (format === ARIA_DATE_FORMAT) {
6534
+ return longDateFormat.format(date);
6535
+ }
6536
+ return this.formatter(date);
6537
+ };
6538
+ }
6535
6539
  getWeek(date) {
6536
6540
  return moment(date).isoWeek();
6537
6541
  }
6538
- parseDate(date) {
6539
- return moment(date, this.dateFormat, this.getMomentLang()).toDate();
6540
- }
6541
6542
  handleOnClose() {
6542
6543
  this.flatpickr.element.focus();
6543
6544
  }
@@ -7611,12 +7612,15 @@ const DatePickerCalendar = class {
7611
7612
  this.picker = new DatetimePicker(this.format, this.language, this.change);
7612
7613
  break;
7613
7614
  }
7614
- this.picker.formatDate = this.formatter;
7615
+ this.picker.formatter = this.formatter;
7615
7616
  }
7616
7617
  componentDidUpdate() {
7617
7618
  if (!this.flatPickrCreated) {
7618
7619
  this.createFlatpickr();
7619
7620
  }
7621
+ else if (!this.isOpen) {
7622
+ this.picker.setValue(this.value);
7623
+ }
7620
7624
  this.tryFixConfusingWidthBug();
7621
7625
  }
7622
7626
  tryFixConfusingWidthBug() {