@umbraco-cms/backoffice 14.1.0 → 14.1.2

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.
@@ -28,6 +28,7 @@ export declare class UmbPropertyEditorUIDatePickerElement extends UmbLitElement
28
28
  private _max?;
29
29
  private _step?;
30
30
  value?: string;
31
+ private _inputValue?;
31
32
  set config(config: UmbPropertyEditorConfigCollection | undefined);
32
33
  render(): import("lit-html").TemplateResult<1>;
33
34
  }
@@ -5,7 +5,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
7
  import { UmbPropertyValueChangeEvent } from '../../core/property-editor/index.js';
8
- import { html, customElement, property, state, ifDefined } from '../../../external/lit/index.js';
8
+ import { html, customElement, property, state } from '../../../external/lit/index.js';
9
9
  import { UmbLitElement } from '../../core/lit-element/index.js';
10
10
  /**
11
11
  * This property editor allows the user to pick a date, datetime-local, or time.
@@ -37,8 +37,8 @@ let UmbPropertyEditorUIDatePickerElement = class UmbPropertyEditorUIDatePickerEl
37
37
  return;
38
38
  // Format string prevalue/config
39
39
  const format = config.getValueByAlias('format');
40
- const hasTime = format?.includes('H') || format?.includes('m');
41
- const hasSeconds = format?.includes('s');
40
+ const hasTime = (format?.includes('H') || format?.includes('m')) ?? false;
41
+ const hasSeconds = format?.includes('s') ?? false;
42
42
  this._inputType = hasTime ? 'datetime-local' : 'date';
43
43
  // Based on the type of format string change the UUI-input type
44
44
  // Note: The format string is not validated, so it's possible to have an invalid format string,
@@ -56,28 +56,47 @@ let UmbPropertyEditorUIDatePickerElement = class UmbPropertyEditorUIDatePickerEl
56
56
  }
57
57
  }
58
58
  #onChange(event) {
59
- this.#formatValue(event.target.value.toString());
59
+ let value = event.target.value.toString();
60
+ switch (this._inputType) {
61
+ case 'time':
62
+ value = `0001-01-01 ${value}`;
63
+ break;
64
+ case 'date':
65
+ value = `${value} 00:00:00`;
66
+ break;
67
+ case 'datetime-local':
68
+ value = value.replace('T', ' ');
69
+ break;
70
+ }
71
+ this.#syncValue(value);
60
72
  }
61
73
  /**
62
74
  * Formats the value depending on the input type.
63
75
  */
64
76
  #formatValue(value) {
65
- // Check that the value is a valid date
66
- const valueToDate = new Date(value);
67
- if (isNaN(valueToDate.getTime())) {
68
- console.warn('[Umbraco.DatePicker] The value is not a valid date.', value);
77
+ this._inputValue = undefined;
78
+ if (isNaN(new Date(value).getTime())) {
79
+ console.warn(`[UmbDatePicker] Invalid date: ${value}`);
69
80
  return;
70
81
  }
71
- // Replace the potential time demoninator 'T' with a whitespace for backwards compatibility
72
- value = value.replace('T', ' ');
73
- // If the inputType is 'date', we need to make sure the value doesn't have a time
74
- if (this._inputType === 'date' && value.includes(' ')) {
75
- value = value.split(' ')[0];
82
+ const dateSplit = value.split(' ');
83
+ if (dateSplit.length !== 2) {
84
+ console.warn(`[UmbDatePicker] Invalid date: ${value}`);
85
+ return;
76
86
  }
77
- // If the inputType is 'time', we need to remove the date part of the value
78
- if (this._inputType === 'time' && value.includes(' ')) {
79
- value = value.split(' ')[1];
87
+ switch (this._inputType) {
88
+ case 'time':
89
+ this._inputValue = dateSplit[1];
90
+ break;
91
+ case 'date':
92
+ this._inputValue = dateSplit[0];
93
+ break;
94
+ default:
95
+ this._inputValue = dateSplit.join('T');
96
+ break;
80
97
  }
98
+ }
99
+ #syncValue(value) {
81
100
  const valueHasChanged = this.value !== value;
82
101
  if (valueHasChanged) {
83
102
  this.value = value;
@@ -87,7 +106,7 @@ let UmbPropertyEditorUIDatePickerElement = class UmbPropertyEditorUIDatePickerEl
87
106
  render() {
88
107
  return html `
89
108
  <umb-input-date
90
- value="${ifDefined(this.value)}"
109
+ .value=${this._inputValue}
91
110
  .min=${this._min}
92
111
  .max=${this._max}
93
112
  .step=${this._step}
@@ -112,6 +131,9 @@ __decorate([
112
131
  __decorate([
113
132
  property()
114
133
  ], UmbPropertyEditorUIDatePickerElement.prototype, "value", void 0);
134
+ __decorate([
135
+ state()
136
+ ], UmbPropertyEditorUIDatePickerElement.prototype, "_inputValue", void 0);
115
137
  UmbPropertyEditorUIDatePickerElement = __decorate([
116
138
  customElement('umb-property-editor-ui-date-picker')
117
139
  ], UmbPropertyEditorUIDatePickerElement);