@sebgroup/green-core 1.4.2 → 1.4.4

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.
@@ -78,4 +78,5 @@ export declare class GdsDatepicker extends GdsFormControlElement<Date> {
78
78
  connectedCallback(): void;
79
79
  render(): any;
80
80
  private _handleValueChange;
81
+ private _handleOpenChange;
81
82
  }
package/index.js CHANGED
@@ -139,7 +139,7 @@ function watchMediaQuery(q) {
139
139
  // libs/core/src/utils/helpers/custom-element-scoping.ts
140
140
  import { html as litHtml } from "lit";
141
141
  import { customElement } from "lit/decorators.js";
142
- var VER_SUFFIX = "-3bff35";
142
+ var VER_SUFFIX = "-6cf221";
143
143
  var elementLookupTable = /* @__PURE__ */ new Map();
144
144
  var gdsCustomElement = (tagName) => {
145
145
  if (globalThis.GDS_DISABLE_VERSIONED_ELEMENTS) {
@@ -193,12 +193,20 @@ import { createRef, ref } from "lit/directives/ref.js";
193
193
  // libs/core/src/utils/helpers/transitional-styles.ts
194
194
  import { html as html2 } from "lit";
195
195
  import { unsafeHTML } from "lit/directives/unsafe-html.js";
196
+ function supportsConstructedStylesheets() {
197
+ try {
198
+ new CSSStyleSheet();
199
+ return true;
200
+ } catch {
201
+ return false;
202
+ }
203
+ }
196
204
  var TransitionalStyles = class {
197
205
  constructor() {
198
206
  this.sheets = /* @__PURE__ */ new Map();
199
207
  this.elements = /* @__PURE__ */ new Map();
200
208
  this.sheetsLegacy = /* @__PURE__ */ new Map();
201
- this.useLegacyStylesheets = true;
209
+ this.useLegacyStylesheets = !supportsConstructedStylesheets();
202
210
  }
203
211
  static get instance() {
204
212
  if (!globalThis.__gdsTransitionalStyles?.[VER_SUFFIX])
@@ -208,7 +216,6 @@ var TransitionalStyles = class {
208
216
  };
209
217
  return globalThis.__gdsTransitionalStyles[VER_SUFFIX];
210
218
  }
211
- //!supportsConstructedStylesheets()
212
219
  apply(element, styleKey) {
213
220
  if (!element.shadowRoot)
214
221
  return;
@@ -1746,7 +1753,6 @@ import { map } from "lit/directives/map.js";
1746
1753
  import { repeat } from "lit/directives/repeat.js";
1747
1754
  import { nothing } from "lit";
1748
1755
  import { msg as msg5 } from "@lit/localize";
1749
- import { eachYearOfInterval } from "date-fns";
1750
1756
 
1751
1757
  // libs/core/src/primitives/calendar/calendar.ts
1752
1758
  import { html as html6 } from "lit";
@@ -1901,6 +1907,9 @@ var GdsCalendar = class extends GdsElement {
1901
1907
  </tbody>
1902
1908
  </table>`;
1903
1909
  }
1910
+ _valueChanged() {
1911
+ this.focusedDate = this.value;
1912
+ }
1904
1913
  };
1905
1914
  _setSelectedDate = new WeakSet();
1906
1915
  setSelectedDate_fn = function(date) {
@@ -1997,6 +2006,9 @@ __decorateClass([
1997
2006
  __decorateClass([
1998
2007
  state8()
1999
2008
  ], GdsCalendar.prototype, "_tStyles", 2);
2009
+ __decorateClass([
2010
+ watch("value")
2011
+ ], GdsCalendar.prototype, "_valueChanged", 1);
2000
2012
  GdsCalendar = __decorateClass([
2001
2013
  gdsCustomElement("gds-calendar")
2002
2014
  ], GdsCalendar);
@@ -2069,9 +2081,13 @@ var GdsDatePartSpinner = class extends LitElement6 {
2069
2081
  } else {
2070
2082
  const key = parseInt(e.key);
2071
2083
  if (!isNaN(key)) {
2072
- __privateSet(this, _inputBuffer, __privateGet(this, _inputBuffer) + key.toString());
2073
- this.value = parseInt(__privateGet(this, _inputBuffer));
2074
- if (__privateGet(this, _inputBuffer).length == this.length) {
2084
+ if (__privateGet(this, _inputBuffer).length < this.length) {
2085
+ __privateSet(this, _inputBuffer, __privateGet(this, _inputBuffer) + key.toString());
2086
+ this.value = parseInt(__privateGet(this, _inputBuffer));
2087
+ }
2088
+ if (__privateGet(this, _inputBuffer).length === this.length) {
2089
+ this.value = __privateMethod(this, _clamp, clamp_fn).call(this, this.value);
2090
+ __privateMethod(this, _clearInputBuffer, clearInputBuffer_fn).call(this);
2075
2091
  __privateMethod(this, _focusNextSpinner, focusNextSpinner_fn).call(this);
2076
2092
  __privateMethod(this, _dispatchChangeEvent, dispatchChangeEvent_fn).call(this);
2077
2093
  }
@@ -2193,7 +2209,7 @@ var dateConverter = {
2193
2209
  return value.toISOString();
2194
2210
  }
2195
2211
  };
2196
- var _renderBackToValidRangeButton, renderBackToValidRangeButton_fn, _focusDate, focusDate_fn, _getSpinnerLabel, getSpinnerLabel_fn, _getMinSpinnerValue, getMinSpinnerValue_fn, _getMaxSpinnerValue, getMaxSpinnerValue_fn, _dispatchChangeEvent2, dispatchChangeEvent_fn2, _handleCalendarChange, _handleMonthChange, _handleYearChange, _handleIncrementFocusedMonth, _handleDecrementFocusedMonth, _handleFocusChange, _handlePopoverStateChange, _handleSpinnerKeydown, _parseDateFormat, parseDateFormat_fn, _handleSpinnerChange, _spinnerState, _years, years_get;
2212
+ var _renderBackToValidRangeButton, renderBackToValidRangeButton_fn, _focusDate, focusDate_fn, _getSpinnerLabel, getSpinnerLabel_fn, _getMinSpinnerValue, getMinSpinnerValue_fn, _getMaxSpinnerValue, getMaxSpinnerValue_fn, _dispatchChangeEvent2, dispatchChangeEvent_fn2, _handleFieldClick, _handleCalendarChange, _handleMonthChange, _handleYearChange, _handleIncrementFocusedMonth, _handleDecrementFocusedMonth, _handleFocusChange, _handlePopoverStateChange, _handleSpinnerKeydown, _parseDateFormat, parseDateFormat_fn, _handleSpinnerChange, _spinnerState, _years, years_get, _isValueOutsideRange, isValueOutsideRange_get;
2197
2213
  var GdsDatepicker = class extends GdsFormControlElement {
2198
2214
  constructor() {
2199
2215
  super(...arguments);
@@ -2208,10 +2224,10 @@ var GdsDatepicker = class extends GdsFormControlElement {
2208
2224
  */
2209
2225
  __privateAdd(this, _parseDateFormat);
2210
2226
  /**
2211
- * Returns an array of years between the min and max dates for use in the year dropdown.
2212
- * If the value is set to a year outside the range, it will be added to the array until the value is changed.
2227
+ * Returns a year iterator between the min and max dates for use in the year dropdown.
2213
2228
  */
2214
2229
  __privateAdd(this, _years);
2230
+ __privateAdd(this, _isValueOutsideRange);
2215
2231
  this.min = new Date((/* @__PURE__ */ new Date()).getFullYear() - 10, 0, 1);
2216
2232
  this.max = new Date((/* @__PURE__ */ new Date()).getFullYear() + 10, 0, 1);
2217
2233
  this.open = false;
@@ -2220,6 +2236,9 @@ var GdsDatepicker = class extends GdsFormControlElement {
2220
2236
  this._focusedMonth = (/* @__PURE__ */ new Date()).getMonth();
2221
2237
  this._focusedYear = (/* @__PURE__ */ new Date()).getFullYear();
2222
2238
  this._dateFormatLayout = __privateMethod(this, _parseDateFormat, parseDateFormat_fn).call(this, "y-m-d");
2239
+ __privateAdd(this, _handleFieldClick, (e) => {
2240
+ this._elSpinners[0].focus();
2241
+ });
2223
2242
  __privateAdd(this, _handleCalendarChange, (e) => {
2224
2243
  e.stopPropagation();
2225
2244
  this.value = e.detail;
@@ -2326,7 +2345,7 @@ var GdsDatepicker = class extends GdsFormControlElement {
2326
2345
 
2327
2346
  <div class="form-info"><slot name="sub-label"></slot></div>
2328
2347
 
2329
- <div class="field" id="trigger">
2348
+ <div class="field" id="trigger" @click=${__privateGet(this, _handleFieldClick)}>
2330
2349
  <div class="input">
2331
2350
  ${join(
2332
2351
  map(
@@ -2473,6 +2492,10 @@ var GdsDatepicker = class extends GdsFormControlElement {
2473
2492
  const day = date.getDate().toString().padStart(2, "0");
2474
2493
  __privateSet(this, _spinnerState, { year, month, day });
2475
2494
  }
2495
+ _handleOpenChange() {
2496
+ if (this.open)
2497
+ this._elCalendar.then((el) => el.focus());
2498
+ }
2476
2499
  };
2477
2500
  _renderBackToValidRangeButton = new WeakSet();
2478
2501
  renderBackToValidRangeButton_fn = async function() {
@@ -2511,7 +2534,7 @@ getSpinnerLabel_fn = function(name) {
2511
2534
  _getMinSpinnerValue = new WeakSet();
2512
2535
  getMinSpinnerValue_fn = function(name) {
2513
2536
  const min = {
2514
- year: this.min.getFullYear(),
2537
+ year: 1900,
2515
2538
  month: 1,
2516
2539
  day: 1
2517
2540
  };
@@ -2520,7 +2543,7 @@ getMinSpinnerValue_fn = function(name) {
2520
2543
  _getMaxSpinnerValue = new WeakSet();
2521
2544
  getMaxSpinnerValue_fn = function(name) {
2522
2545
  const max = {
2523
- year: this.max.getFullYear(),
2546
+ year: 9999,
2524
2547
  month: 12,
2525
2548
  day: 31
2526
2549
  };
@@ -2534,6 +2557,7 @@ dispatchChangeEvent_fn2 = function() {
2534
2557
  })
2535
2558
  );
2536
2559
  };
2560
+ _handleFieldClick = new WeakMap();
2537
2561
  _handleCalendarChange = new WeakMap();
2538
2562
  _handleMonthChange = new WeakMap();
2539
2563
  _handleYearChange = new WeakMap();
@@ -2562,19 +2586,24 @@ _handleSpinnerChange = new WeakMap();
2562
2586
  _spinnerState = new WeakMap();
2563
2587
  _years = new WeakSet();
2564
2588
  years_get = function() {
2565
- const years = eachYearOfInterval({
2566
- start: this.min,
2567
- end: this.max
2568
- }).map((date) => date.getFullYear());
2589
+ const minYear = this.min.getFullYear();
2590
+ const maxYear = this.max.getFullYear();
2591
+ const isOutsideRange = __privateGet(this, _isValueOutsideRange, isValueOutsideRange_get);
2592
+ const valueYear = this.value?.getFullYear();
2593
+ return {
2594
+ *[Symbol.iterator]() {
2595
+ if (isOutsideRange)
2596
+ yield valueYear;
2597
+ for (let i = minYear; i <= maxYear; i++)
2598
+ yield i;
2599
+ }
2600
+ };
2601
+ };
2602
+ _isValueOutsideRange = new WeakSet();
2603
+ isValueOutsideRange_get = function() {
2569
2604
  if (!this.value)
2570
- return years;
2571
- const selectedYear = this.value.getFullYear();
2572
- const valueIsInrage = years[0] <= selectedYear && years[years.length - 1] >= selectedYear;
2573
- if (!valueIsInrage) {
2574
- years.push(selectedYear);
2575
- years.sort((a, b) => a - b);
2576
- }
2577
- return years;
2605
+ return false;
2606
+ return this.value.getFullYear() < this.min.getFullYear() || this.value.getFullYear() > this.max.getFullYear();
2578
2607
  };
2579
2608
  GdsDatepicker.styles = [styles];
2580
2609
  GdsDatepicker.shadowRootOptions = {
@@ -2629,6 +2658,9 @@ __decorateClass([
2629
2658
  __decorateClass([
2630
2659
  watch("value")
2631
2660
  ], GdsDatepicker.prototype, "_handleValueChange", 1);
2661
+ __decorateClass([
2662
+ watch("open")
2663
+ ], GdsDatepicker.prototype, "_handleOpenChange", 1);
2632
2664
  GdsDatepicker = __decorateClass([
2633
2665
  gdsCustomElement("gds-datepicker")
2634
2666
  ], GdsDatepicker);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sebgroup/green-core",
3
3
  "description": "A carefully crafted set of Web Components, laying the foundation of the Green Design System.",
4
- "version": "1.4.2",
4
+ "version": "1.4.4",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
7
7
  "type": "module",
@@ -51,4 +51,5 @@ export declare class GdsCalendar extends GdsElement {
51
51
  connectedCallback(): void;
52
52
  focus(): void;
53
53
  render(): import("lit").TemplateResult<1>;
54
+ private _valueChanged;
54
55
  }
@@ -2871,8 +2871,8 @@ var calendar_trans_styles_default = `/* stylelint-disable max-nesting-depth */
2871
2871
  :host table tbody tr td.today {
2872
2872
  background: transparent;
2873
2873
  border-radius: 4px;
2874
- box-shadow: inset 0 0 0 2px hsl(var(--sg-hsl-blue-2));
2875
2874
  color: hsl(var(--sg-hsl-blue-2));
2875
+ text-decoration: underline;
2876
2876
  }
2877
2877
  :host table tbody tr td:hover:not(.disabled) {
2878
2878
  background: hsl(var(--sg-hsl-blue-0));
@@ -2882,10 +2882,8 @@ var calendar_trans_styles_default = `/* stylelint-disable max-nesting-depth */
2882
2882
  cursor: pointer;
2883
2883
  }
2884
2884
  :host table tbody tr td:focus-visible:not(.disabled) {
2885
- background: hsl(var(--sg-hsl-blue-0));
2886
2885
  border: solid 1px var(--sg-bg-level-2);
2887
2886
  border-radius: 4px;
2888
- color: hsl(var(--sg-hsl-white));
2889
2887
  cursor: pointer;
2890
2888
  position: relative;
2891
2889
  z-index: 0;
@@ -2907,10 +2905,8 @@ var calendar_trans_styles_default = `/* stylelint-disable max-nesting-depth */
2907
2905
  color: hsl(var(--sg-hsl-white));
2908
2906
  }
2909
2907
  :host table tbody tr td[tabindex="0"] {
2910
- background: hsl(var(--sg-hsl-blue-2));
2911
- border: solid 1px var(--sg-bg-level-2);
2912
2908
  border-radius: 4px;
2913
- color: hsl(var(--sg-hsl-white));
2909
+ box-shadow: inset 0 0 0 2px hsl(var(--sg-hsl-blue-2));
2914
2910
  }
2915
2911
  :host table tbody tr td:hover:active:not(.disabled) {
2916
2912
  background: hsl(var(--sg-hsl-blue-2));
@@ -3216,7 +3212,7 @@ function register6() {
3216
3212
  // libs/core/src/utils/helpers/custom-element-scoping.ts
3217
3213
  import { html as litHtml } from "lit";
3218
3214
  import { customElement } from "lit/decorators.js";
3219
- var VER_SUFFIX = "-3bff35";
3215
+ var VER_SUFFIX = "-6cf221";
3220
3216
  var elementLookupTable = /* @__PURE__ */ new Map();
3221
3217
  var templateCache = /* @__PURE__ */ new WeakMap();
3222
3218
  function applyElementScoping(strings, ...values) {
@@ -3254,12 +3250,20 @@ var registerTransitionalStyles = () => {
3254
3250
  register5();
3255
3251
  register6();
3256
3252
  };
3253
+ function supportsConstructedStylesheets() {
3254
+ try {
3255
+ new CSSStyleSheet();
3256
+ return true;
3257
+ } catch {
3258
+ return false;
3259
+ }
3260
+ }
3257
3261
  var TransitionalStyles = class {
3258
3262
  constructor() {
3259
3263
  this.sheets = /* @__PURE__ */ new Map();
3260
3264
  this.elements = /* @__PURE__ */ new Map();
3261
3265
  this.sheetsLegacy = /* @__PURE__ */ new Map();
3262
- this.useLegacyStylesheets = true;
3266
+ this.useLegacyStylesheets = !supportsConstructedStylesheets();
3263
3267
  }
3264
3268
  static get instance() {
3265
3269
  if (!globalThis.__gdsTransitionalStyles?.[VER_SUFFIX])
@@ -3269,7 +3273,6 @@ var TransitionalStyles = class {
3269
3273
  };
3270
3274
  return globalThis.__gdsTransitionalStyles[VER_SUFFIX];
3271
3275
  }
3272
- //!supportsConstructedStylesheets()
3273
3276
  apply(element, styleKey) {
3274
3277
  if (!element.shadowRoot)
3275
3278
  return;