@kodaris/krubble-app-components 1.0.169 → 1.0.171

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.
@@ -19185,6 +19185,9 @@
19185
19185
  if (json.max !== undefined) {
19186
19186
  field.max = json.max;
19187
19187
  }
19188
+ if (json.format !== undefined) {
19189
+ field.format = json.format;
19190
+ }
19188
19191
  if (json.step !== undefined) {
19189
19192
  field.step = json.step;
19190
19193
  }
@@ -19243,6 +19246,13 @@
19243
19246
  * Maximum selectable date in YYYY-MM-DD format
19244
19247
  */
19245
19248
  this.max = '';
19249
+ /**
19250
+ * The format `value` is written in when a date is picked or typed: `YYYY`, `YY`, `MM`, `M`, `DD` and
19251
+ * `D` stand for the parts, anything else is kept as is. `YYYY-MM-DD` by default; `MM/DD/YY` for a
19252
+ * system that stores dates that way. Typed and set values are read in any format the picker knows
19253
+ * (ISO, M/D/YY, M/D/YYYY, "August 5, 2026"), whatever this is set to. `min` and `max` stay YYYY-MM-DD.
19254
+ */
19255
+ this.format = 'YYYY-MM-DD';
19246
19256
  /**
19247
19257
  * Step in days for valid date intervals
19248
19258
  */
@@ -19477,7 +19487,7 @@
19477
19487
  }
19478
19488
  const parsed = this._parseDate(raw);
19479
19489
  if (parsed) {
19480
- this.value = this._toISO(parsed);
19490
+ this.value = this._formatValue(parsed);
19481
19491
  this.valueAsDate = parsed;
19482
19492
  this.valueAsNumber = parsed.getTime();
19483
19493
  this._dirtyValue = this.value;
@@ -19515,7 +19525,7 @@
19515
19525
  else {
19516
19526
  const parsed = this._parseDate(raw);
19517
19527
  if (parsed) {
19518
- this.value = this._toISO(parsed);
19528
+ this.value = this._formatValue(parsed);
19519
19529
  this.valueAsDate = parsed;
19520
19530
  this.valueAsNumber = parsed.getTime();
19521
19531
  this._dirtyValue = this.value;
@@ -19548,7 +19558,7 @@
19548
19558
  else {
19549
19559
  const parsed = this._parseDate(raw);
19550
19560
  if (parsed) {
19551
- this.value = this._toISO(parsed);
19561
+ this.value = this._formatValue(parsed);
19552
19562
  this.valueAsDate = parsed;
19553
19563
  this.valueAsNumber = parsed.getTime();
19554
19564
  }
@@ -19620,7 +19630,7 @@
19620
19630
  if (this.readonly) {
19621
19631
  return;
19622
19632
  }
19623
- this.value = this._toISO(date);
19633
+ this.value = this._formatValue(date);
19624
19634
  this.valueAsDate = date;
19625
19635
  this.valueAsNumber = date.getTime();
19626
19636
  this.dirty = true;
@@ -19669,7 +19679,7 @@
19669
19679
  if (minDate) {
19670
19680
  const diffDays = Math.round((this.valueAsDate.getTime() - minDate.getTime()) / 86400000);
19671
19681
  if (diffDays % this.step !== 0) {
19672
- this._internals.setValidity({ stepMismatch: true }, `Please select a valid date. The nearest valid dates are ${this._toISO(new Date(minDate.getTime() + Math.floor(diffDays / this.step) * this.step * 86400000))} and ${this._toISO(new Date(minDate.getTime() + Math.ceil(diffDays / this.step) * this.step * 86400000))}`, this._triggerElement);
19682
+ this._internals.setValidity({ stepMismatch: true }, `Please select a valid date. The nearest valid dates are ${this._formatValue(new Date(minDate.getTime() + Math.floor(diffDays / this.step) * this.step * 86400000))} and ${this._formatValue(new Date(minDate.getTime() + Math.ceil(diffDays / this.step) * this.step * 86400000))}`, this._triggerElement);
19673
19683
  return;
19674
19684
  }
19675
19685
  }
@@ -19756,11 +19766,29 @@
19756
19766
  }
19757
19767
  return null;
19758
19768
  }
19759
- _toISO(date) {
19760
- const y = date.getFullYear();
19761
- const m = String(date.getMonth() + 1).padStart(2, '0');
19762
- const d = String(date.getDate()).padStart(2, '0');
19763
- return `${y}-${m}-${d}`;
19769
+ // The date as `value` carries it, in `format`. Longest tokens first, so YYYY isn't read as two YYs.
19770
+ _formatValue(date) {
19771
+ const year = String(date.getFullYear());
19772
+ const month = date.getMonth() + 1;
19773
+ const day = date.getDate();
19774
+ return this.format.replace(/YYYY|YY|MM|M|DD|D/g, (token) => {
19775
+ if (token === 'YYYY') {
19776
+ return year;
19777
+ }
19778
+ if (token === 'YY') {
19779
+ return year.slice(-2);
19780
+ }
19781
+ if (token === 'MM') {
19782
+ return String(month).padStart(2, '0');
19783
+ }
19784
+ if (token === 'M') {
19785
+ return String(month);
19786
+ }
19787
+ if (token === 'DD') {
19788
+ return String(day).padStart(2, '0');
19789
+ }
19790
+ return String(day);
19791
+ });
19764
19792
  }
19765
19793
  _renderCalendar() {
19766
19794
  const daysInMonth = new Date(this._viewYear, this._viewMonth + 1, 0).getDate();
@@ -19783,7 +19811,7 @@
19783
19811
  for (let day = 1; day <= daysInMonth; day++) {
19784
19812
  const date = new Date(this._viewYear, this._viewMonth, day);
19785
19813
  const isToday = date.getTime() === today.getTime();
19786
- const isSelected = this.value === this._toISO(date);
19814
+ const isSelected = this.value === this._formatValue(date);
19787
19815
  const isDisabled = this._isDateDisabled(date);
19788
19816
  cells.push(b `
19789
19817
  <button
@@ -20238,6 +20266,9 @@
20238
20266
  __decorate$3([
20239
20267
  n$1({ type: String })
20240
20268
  ], KRDatePicker.prototype, "max", void 0);
20269
+ __decorate$3([
20270
+ n$1({ type: String })
20271
+ ], KRDatePicker.prototype, "format", void 0);
20241
20272
  __decorate$3([
20242
20273
  n$1({ type: Number })
20243
20274
  ], KRDatePicker.prototype, "step", void 0);