@haiilo/catalyst 10.19.1 → 10.19.3

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.
@@ -13329,6 +13329,7 @@ const CatTime = class {
13329
13329
  this.hasSlottedHint = false;
13330
13330
  this.selectionTime = null;
13331
13331
  this.isAm = true;
13332
+ this.valueChangedBySelection = false;
13332
13333
  this.requiredMarker = 'optional';
13333
13334
  this.horizontal = false;
13334
13335
  this.autoComplete = undefined;
@@ -13365,7 +13366,17 @@ const CatTime = class {
13365
13366
  this.reclamp('max', max);
13366
13367
  }
13367
13368
  }
13369
+ onValueChanged(value, oldValue) {
13370
+ if (this.valueChangedBySelection) {
13371
+ this.valueChangedBySelection = false;
13372
+ }
13373
+ else if (value !== oldValue) {
13374
+ this.set12hFormat();
13375
+ this.syncValue(value);
13376
+ }
13377
+ }
13368
13378
  componentWillLoad() {
13379
+ this.set12hFormat();
13369
13380
  this.syncValue(this.value ?? '');
13370
13381
  }
13371
13382
  componentWillRender() {
@@ -13397,6 +13408,7 @@ const CatTime = class {
13397
13408
  */
13398
13409
  async select(date) {
13399
13410
  const oldValue = this.value;
13411
+ let newValue = this.value;
13400
13412
  if (!date) {
13401
13413
  this.selectionTime = null;
13402
13414
  this.value = undefined;
@@ -13405,16 +13417,21 @@ const CatTime = class {
13405
13417
  const time = clampTime(this.min ?? null, date, this.max ?? null);
13406
13418
  this.isAm = this.format(time).toLowerCase().includes('am');
13407
13419
  this.selectionTime = time;
13408
- this.value = formatIso(time);
13420
+ newValue = formatIso(time);
13409
13421
  }
13410
13422
  // we need to set the input explicitly to sync the input even without a
13411
13423
  // rerender (if the value is not changed)
13412
13424
  if (this.input) {
13413
13425
  this.input.value = this.format(this.selectionTime, false);
13414
13426
  }
13415
- if (oldValue !== this.value) {
13427
+ if (oldValue !== newValue) {
13428
+ this.valueChangedBySelection = true;
13429
+ this.value = newValue;
13416
13430
  this.catChange.emit(this.value);
13417
13431
  }
13432
+ else {
13433
+ this.valueChangedBySelection = false;
13434
+ }
13418
13435
  }
13419
13436
  /**
13420
13437
  * Programmatically move focus to the input. Use this method instead of
@@ -13440,14 +13457,14 @@ const CatTime = class {
13440
13457
  this.input?.clear();
13441
13458
  }
13442
13459
  render() {
13443
- return (index.h(index.Host, { key: 'e9bfaeee8aa39aa58ac287afeaed1a2fc39d7b83' }, index.h("cat-input", { key: '1e200e6041b06a0859e392cfc6b6b03668b3eb35', class: "cat-time-input", ref: el => (this.input = el), requiredMarker: this.requiredMarker, horizontal: this.horizontal, autoComplete: this.autoComplete, clearable: this.clearable, disabled: this.disabled, hint: this.hint, icon: this.icon, iconRight: this.iconRight, identifier: this.identifier, label: this.label, labelHidden: this.labelHidden, name: this.name, placeholder: this.placeholder, textPrefix: this.textPrefix, textSuffix: this.textSuffix, readonly: this.readonly, required: this.required, value: this.format(this.selectionTime, false), errors: this.errors, errorUpdate: this.errorUpdate, nativeAttributes: this.nativeAttributes, onCatFocus: e => this.catFocus.emit(e.detail), onCatBlur: e => this.onInputBlur(e.detail) }, index.h("span", { key: 'e91e3e12272c24858a71b485e00e54cf00d7386f', slot: "label" }, this.hasSlottedLabel && index.h("slot", { key: '2449ea042497293868bcc767b1626070b3a1dcec', name: "label" }), !this.hasSlottedLabel && this.label, index.h("span", { key: '3bab583a7629d01350fbd9e54d3fe1f113e0b372', class: "label-aria" }, " (HH:mm)")), index.h("div", { key: '8340d31e70e30ebe1d020f456b3a7bc5bed6b998', slot: "addon", class: "cat-time-addon" }, this.locale.timeFormat === '12' && (index.h("cat-button", { key: 'e6bb50abe2c3296cee7c3d5c02a6cef7c69f8678', class: "cat-time-format", disabled: this.disabled || this.readonly, onCatClick: () => this.toggleAm() }, this.isAm ? 'AM' : 'PM')), index.h("cat-dropdown", { key: 'e79b7f58ffdc4d356e94f3e96afb6727d3e9be26', slot: "addon", placement: this.placement }, index.h("cat-button", { key: 'd6bd905d7760e0ae7e9ab8c23e87f7c926769aa9', slot: "trigger", class: "cat-time-toggle", disabled: this.disabled || this.readonly, icon: "$cat:timepicker-clock", iconOnly: true, a11yLabel: this.selectionTime ? `${this.locale.change}, ${this.format(this.selectionTime)}` : this.locale.choose }), index.h("nav", { key: 'c2ae49020a1e8cafedd27b8a7e061e63dbb4c6d2', slot: "content", class: "cat-nav" }, index.h("ul", { key: 'b918672be1b65ca3a1c2daa239a196d4117b52f7' }, this.timeArray().map(time => {
13460
+ return (index.h(index.Host, { key: '257e8034002a6c0cfd53d2d8b99d32953ecd229a' }, index.h("cat-input", { key: 'b0572967e133b2b099e9010f6e9ce67168f9592c', class: "cat-time-input", ref: el => (this.input = el), requiredMarker: this.requiredMarker, horizontal: this.horizontal, autoComplete: this.autoComplete, clearable: this.clearable, disabled: this.disabled, hint: this.hint, icon: this.icon, iconRight: this.iconRight, identifier: this.identifier, label: this.label, labelHidden: this.labelHidden, name: this.name, placeholder: this.placeholder, textPrefix: this.textPrefix, textSuffix: this.textSuffix, readonly: this.readonly, required: this.required, value: this.format(this.selectionTime, false), errors: this.errors, errorUpdate: this.errorUpdate, nativeAttributes: this.nativeAttributes, onCatFocus: e => this.catFocus.emit(e.detail), onCatBlur: e => this.onInputBlur(e.detail) }, index.h("span", { key: '5b21ff245c6f582803756c7b5177d735a1e360fb', slot: "label" }, this.hasSlottedLabel && index.h("slot", { key: 'e5dfa72756d8698f1e0bfc55e45fb0791c272157', name: "label" }), !this.hasSlottedLabel && this.label, index.h("span", { key: 'ea2ac13fb8bddf7168448d7f3f50bd2703391393', class: "label-aria" }, " (HH:mm)")), index.h("div", { key: '50cedc1bf604b00ba062dff0881cad36f3eb62d3', slot: "addon", class: "cat-time-addon" }, this.locale.timeFormat === '12' && (index.h("cat-button", { key: '238e1a4005a877ab8dd0fa2d23d2cafdf48dab38', class: "cat-time-format", disabled: this.disabled || this.readonly, onCatClick: () => this.toggleAm() }, this.isAm ? 'AM' : 'PM')), index.h("cat-dropdown", { key: '42367ea0ef47e851555ca3aae23d51169069158b', slot: "addon", placement: this.placement }, index.h("cat-button", { key: '8cd18784f5f4077b66dd0f5e134ff6fae83ce79b', slot: "trigger", class: "cat-time-toggle", disabled: this.disabled || this.readonly, icon: "$cat:timepicker-clock", iconOnly: true, a11yLabel: this.selectionTime ? `${this.locale.change}, ${this.format(this.selectionTime)}` : this.locale.choose }), index.h("nav", { key: 'e89d88df8d6612eb48bb211954ef4b924f9e2d15', slot: "content", class: "cat-nav" }, index.h("ul", { key: '631bcc9f06b20e71fd175951671c66abaafaf5c0' }, this.timeArray().map(time => {
13444
13461
  const isoTime = formatIso(time);
13445
13462
  const disabled = isBefore(time, this.min ?? null) || isAfter(time, this.max ?? null);
13446
13463
  return (index.h("li", null, index.h("cat-button", { class: {
13447
13464
  'cat-nav-item': true,
13448
13465
  'time-disabled': disabled
13449
13466
  }, disabled: disabled, active: isoTime === this.value, color: isoTime === this.value ? 'primary' : 'secondary', variant: isoTime === this.value ? 'filled' : 'outlined', onCatClick: () => this.select(time), "data-time": isoTime }, this.format(time))));
13450
- }))))), this.hasSlottedHint && (index.h("span", { key: '817f2b58417911affc39ce6977160998c39ebf71', slot: "hint" }, index.h("slot", { key: 'a1ffdd541103064abf49311801088fe15d5ed88d', name: "hint" }))))));
13467
+ }))))), this.hasSlottedHint && (index.h("span", { key: 'f2d0bf13097fac363af4a309ac69b77114b01168', slot: "hint" }, index.h("slot", { key: 'e44ce224148d9bf82803a4eff9bbed89fbb04dc2', name: "hint" }))))));
13451
13468
  }
13452
13469
  timeArray() {
13453
13470
  const result = [];
@@ -13469,6 +13486,12 @@ const CatTime = class {
13469
13486
  ? new Date(2000, 5, 1, hh, mm, 0)
13470
13487
  : new Date(2000, 5, 1, (hh % 12) + (this.isAm ? 0 : 12), mm, 0));
13471
13488
  }
13489
+ set12hFormat() {
13490
+ const [, hh] = this.value?.match(/(\d{2}):(\d{2})/)?.map(Number) ?? [];
13491
+ if (this.locale.timeFormat === '12') {
13492
+ this.isAm = hh === 0 || hh < 12;
13493
+ }
13494
+ }
13472
13495
  toggleAm() {
13473
13496
  if (this.selectionTime) {
13474
13497
  this.select(new Date(this.selectionTime.getTime() + (this.isAm ? 12 : -12) * 3600000));
@@ -13505,7 +13528,8 @@ const CatTime = class {
13505
13528
  get hostElement() { return index.getElement(this); }
13506
13529
  static get watchers() { return {
13507
13530
  "min": ["onMinChanged"],
13508
- "max": ["onMaxChanged"]
13531
+ "max": ["onMaxChanged"],
13532
+ "value": ["onValueChanged"]
13509
13533
  }; }
13510
13534
  };
13511
13535
  CatTime.style = CatTimeStyle0;