@sebgroup/green-core 1.1.1 → 1.2.0

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.
package/index.js CHANGED
@@ -9,9 +9,9 @@ var __decorateClass = (decorators, target, key, kind) => {
9
9
  __defProp(target, key, result);
10
10
  return result;
11
11
  };
12
- var __accessCheck = (obj, member, msg3) => {
12
+ var __accessCheck = (obj, member, msg4) => {
13
13
  if (!member.has(obj))
14
- throw TypeError("Cannot " + msg3);
14
+ throw TypeError("Cannot " + msg4);
15
15
  };
16
16
  var __privateGet = (obj, member, getter) => {
17
17
  __accessCheck(obj, member, "read from private field");
@@ -33,11 +33,10 @@ var __privateMethod = (obj, member, method) => {
33
33
  };
34
34
 
35
35
  // libs/core/src/components/dropdown/dropdown.ts
36
- import { property as property5 } from "lit/decorators.js";
36
+ import { property as property5, query, queryAsync } from "lit/decorators.js";
37
37
  import { unsafeHTML } from "lit/directives/unsafe-html.js";
38
38
  import { when as when2 } from "lit/directives/when.js";
39
39
  import { ifDefined } from "lit/directives/if-defined.js";
40
- import { createRef as createRef3, ref as ref3 } from "lit/directives/ref.js";
41
40
  import { msg as msg2, str, updateWhenLocaleChanges } from "@lit/localize";
42
41
  import "reflect-metadata";
43
42
 
@@ -67,9 +66,6 @@ function constrainSlots(self) {
67
66
  });
68
67
  }
69
68
 
70
- // libs/core/src/utils/helpers/id.ts
71
- var randomId = () => "gds-" + Math.random().toString(36).substring(2, 9);
72
-
73
69
  // libs/core/src/utils/decorators/watch.ts
74
70
  function watch(propertyName, options) {
75
71
  const resolvedOptions = {
@@ -80,8 +76,8 @@ function watch(propertyName, options) {
80
76
  const { update } = proto;
81
77
  const watchedProperties = Array.isArray(propertyName) ? propertyName : [propertyName];
82
78
  proto.update = function(changedProps) {
83
- watchedProperties.forEach((property6) => {
84
- const key = property6;
79
+ watchedProperties.forEach((property7) => {
80
+ const key = property7;
85
81
  if (changedProps.has(key)) {
86
82
  const oldValue = changedProps.get(key);
87
83
  const newValue = this[key];
@@ -143,7 +139,7 @@ function watchMediaQuery(q) {
143
139
  // libs/core/src/utils/helpers/custom-element-scoping.ts
144
140
  import { html as litHtml } from "lit";
145
141
  import { customElement } from "lit/decorators.js";
146
- var VER_SUFFIX = "-2ca105";
142
+ var VER_SUFFIX = "-91f802";
147
143
  var elementLookupTable = /* @__PURE__ */ new Map();
148
144
  var gdsCustomElement = (tagName) => {
149
145
  if (globalThis.GDS_DISABLE_VERSIONED_ELEMENTS) {
@@ -167,7 +163,7 @@ function applyElementScoping(strings, ...values) {
167
163
  }
168
164
  var replaceTags = (inStr) => inStr.map((s) => {
169
165
  for (const [key, value] of elementLookupTable.entries()) {
170
- s = s.split(key).join(value);
166
+ s = s.replace(new RegExp(`${key}(?![-a-z])`, "mg"), value);
171
167
  }
172
168
  return s;
173
169
  });
@@ -191,8 +187,8 @@ function getUnscopedTagName(tagName) {
191
187
  }
192
188
 
193
189
  // libs/core/src/primitives/listbox/listbox.ts
194
- import { LitElement as LitElement2 } from "lit";
195
- import { property as property2 } from "lit/decorators.js";
190
+ import { LitElement } from "lit";
191
+ import { property } from "lit/decorators.js";
196
192
  import { createRef, ref } from "lit/directives/ref.js";
197
193
 
198
194
  // libs/core/src/utils/helpers/transitional-styles.ts
@@ -229,224 +225,42 @@ var TransitionalStyles = class _TransitionalStyles {
229
225
  }
230
226
  };
231
227
 
232
- // libs/core/src/primitives/listbox/option.ts
233
- import { LitElement, html as html2 } from "lit";
234
- import { property } from "lit/decorators.js";
235
- import { when } from "lit/directives/when.js";
236
- import { classMap } from "lit/directives/class-map.js";
237
-
238
- // libs/core/src/primitives/listbox/option.styles.ts
239
- import { css } from "lit";
240
- var style = css`
241
- :host {
242
- padding: 0.5 1rem;
243
- cursor: pointer;
244
- }
245
-
246
- :host(:hover) {
247
- background-color: grey;
248
- }
249
- `;
250
- var option_styles_default = style;
251
-
252
- // libs/core/src/primitives/listbox/option.ts
253
- import "reflect-metadata";
254
- var _hidden, _emitSelect, emitSelect_fn;
255
- var GdsOption = class extends LitElement {
256
- constructor() {
257
- super();
258
- __privateAdd(this, _emitSelect);
259
- __privateAdd(this, _hidden, false);
260
- this.selected = false;
261
- this.isPlaceholder = false;
262
- this.onblur = (e) => {
263
- this.setAttribute("tabindex", "-1");
264
- this.dispatchEvent(
265
- new FocusEvent("gds-blur", {
266
- bubbles: true,
267
- composed: true,
268
- relatedTarget: e.relatedTarget
269
- })
270
- );
271
- };
272
- this.onfocus = (e) => {
273
- this.dispatchEvent(
274
- new FocusEvent("gds-focus", {
275
- bubbles: true,
276
- composed: true,
277
- relatedTarget: e.relatedTarget
278
- })
279
- );
280
- };
281
- this.addEventListener("click", __privateMethod(this, _emitSelect, emitSelect_fn));
282
- this.addEventListener("keydown", (e) => {
283
- if (e.key !== "Enter" && e.key !== " ")
284
- return;
285
- e.preventDefault();
286
- __privateMethod(this, _emitSelect, emitSelect_fn).call(this);
287
- });
288
- }
289
- get hidden() {
290
- return __privateGet(this, _hidden);
291
- }
292
- set hidden(value) {
293
- if (this.isPlaceholder)
294
- return;
295
- __privateSet(this, _hidden, value === "true" || value === true);
296
- this.setAttribute("aria-hidden", value.toString());
297
- }
298
- connectedCallback() {
299
- super.connectedCallback();
300
- this.setAttribute("role", "option");
301
- if (this.isPlaceholder) {
302
- __privateSet(this, _hidden, true);
303
- this.setAttribute("aria-hidden", "true");
304
- }
305
- this.updateComplete.then(
306
- () => TransitionalStyles.instance.apply(this, "gds-option")
307
- );
308
- }
309
- get parentElement() {
310
- return super.parentElement;
311
- }
312
- handlePlaceholderStatusChange() {
313
- if (this.isPlaceholder) {
314
- __privateSet(this, _hidden, true);
315
- this.setAttribute("aria-hidden", "true");
316
- } else {
317
- __privateSet(this, _hidden, false);
318
- this.setAttribute("aria-hidden", "false");
319
- }
320
- }
321
- /**
322
- * Focuses the option.
323
- *
324
- * @param options - Focus options
325
- */
326
- focus(options) {
327
- this.setAttribute("tabindex", "0");
328
- super.focus(options);
329
- if (document.activeElement !== this) {
330
- const iv = setInterval(() => {
331
- if (document.activeElement === this)
332
- clearInterval(iv);
333
- super.focus(options);
334
- }, 10);
335
- }
336
- }
337
- render() {
338
- const isMultiple = this.parentElement.multiple;
339
- const checkbox = html2`<span
340
- class="checkbox ${classMap({ checked: this.selected })}"
341
- ></span>`;
342
- if (!isMultiple) {
343
- if (this.selected)
344
- this.setAttribute("highlighted", "");
345
- else
346
- this.removeAttribute("highlighted");
347
- }
348
- return html2`${when(isMultiple, () => checkbox)}<slot></slot>`;
349
- }
350
- };
351
- _hidden = new WeakMap();
352
- _emitSelect = new WeakSet();
353
- emitSelect_fn = function() {
354
- this.dispatchEvent(
355
- new CustomEvent("gds-select", {
356
- bubbles: true,
357
- composed: true,
358
- detail: {
359
- value: this.value
360
- }
361
- })
362
- );
363
- };
364
- GdsOption.styles = option_styles_default;
365
- __decorateClass([
366
- property()
367
- ], GdsOption.prototype, "value", 2);
368
- __decorateClass([
369
- property({
370
- attribute: "aria-hidden",
371
- reflect: true
372
- })
373
- ], GdsOption.prototype, "hidden", 1);
374
- __decorateClass([
375
- property({
376
- attribute: "aria-selected",
377
- reflect: true
378
- })
379
- ], GdsOption.prototype, "selected", 2);
380
- __decorateClass([
381
- property({ type: Boolean, reflect: true })
382
- ], GdsOption.prototype, "isPlaceholder", 2);
383
- __decorateClass([
384
- watch("isplaceholder")
385
- ], GdsOption.prototype, "handlePlaceholderStatusChange", 1);
386
- GdsOption = __decorateClass([
387
- gdsCustomElement("gds-option")
388
- ], GdsOption);
389
-
390
228
  // libs/core/src/primitives/listbox/listbox.ts
391
229
  import "reflect-metadata";
392
230
 
393
231
  // libs/core/src/primitives/listbox/listbox.styles.ts
394
- import { css as css2 } from "lit";
395
- var style2 = css2`
232
+ import { css } from "lit";
233
+ var style = css`
396
234
  :host {
397
235
  display: flex;
398
236
  flex-direction: column;
399
237
  }
400
238
  `;
401
- var listbox_styles_default = style2;
239
+ var listbox_styles_default = style;
402
240
 
403
- // libs/core/src/primitives/listbox/listbox.ts
404
- var _slotRef, _handleSelect, _keyboardNavigationHandler;
405
- var GdsListbox = class extends LitElement2 {
406
- constructor() {
407
- super();
408
- this.multiple = false;
409
- this.compareWith = (a, b) => a === b;
410
- __privateAdd(this, _slotRef, createRef());
411
- __privateAdd(this, _handleSelect, (e) => {
412
- const option = e.target;
413
- if (this.multiple)
414
- option.selected = !option.selected;
415
- else {
416
- option.selected = true;
417
- Array.from(this.options).forEach((el) => {
418
- if (el !== option)
419
- el.selected = false;
420
- });
421
- }
422
- ;
423
- this.ariaActiveDescendantElement = option;
424
- this.dispatchEvent(
425
- new CustomEvent("change", {
426
- bubbles: false,
427
- composed: false
428
- })
429
- );
430
- });
431
- __privateAdd(this, _keyboardNavigationHandler, (e) => {
432
- if (!(e.target instanceof GdsOption))
241
+ // libs/core/src/controllers/listbox-kb-nav-controller.ts
242
+ var ListboxKbNavController = class {
243
+ constructor(host) {
244
+ this.#keyboardNavigationHandler = (e) => {
245
+ const targetItem = e.target;
246
+ if (!this.host.navigableItems.includes(targetItem))
433
247
  return;
434
248
  let handled = false;
435
249
  if (e.key === "ArrowDown") {
436
- const nextOptionIndex = this.visibleOptionElements.indexOf(e.target) + 1;
437
- const nextItem = this.visibleOptionElements[nextOptionIndex];
250
+ const nextItemIndex = this.host.navigableItems.indexOf(targetItem) + 1;
251
+ const nextItem = this.host.navigableItems[nextItemIndex];
438
252
  nextItem?.focus();
439
253
  handled = true;
440
254
  } else if (e.key === "ArrowUp") {
441
- const prevOptionIndex = this.visibleOptionElements.indexOf(e.target) - 1;
442
- const prevItem = this.visibleOptionElements[prevOptionIndex];
255
+ const prevOptionIndex = this.host.navigableItems.indexOf(targetItem) - 1;
256
+ const prevItem = this.host.navigableItems[prevOptionIndex];
443
257
  prevItem?.focus();
444
258
  handled = true;
445
259
  } else if (e.key === "Home") {
446
- this.visibleOptionElements[0]?.focus();
260
+ this.host.navigableItems[0]?.focus();
447
261
  handled = true;
448
262
  } else if (e.key === "End") {
449
- this.visibleOptionElements[this.visibleOptionElements.length - 1]?.focus();
263
+ this.host.navigableItems[this.host.navigableItems.length - 1]?.focus();
450
264
  handled = true;
451
265
  } else {
452
266
  const key = e.key.toLowerCase();
@@ -456,7 +270,7 @@ var GdsListbox = class extends LitElement2 {
456
270
  const isLetter = key >= "a" && key <= "z";
457
271
  const isNumber = key >= "0" && key <= "9";
458
272
  if (isLetter || isNumber) {
459
- const firstMatch = this.visibleOptionElements.find((el) => {
273
+ const firstMatch = this.host.navigableItems.find((el) => {
460
274
  const text = el.textContent?.trim().toLowerCase();
461
275
  return text?.startsWith(key);
462
276
  });
@@ -468,19 +282,68 @@ var GdsListbox = class extends LitElement2 {
468
282
  e.preventDefault();
469
283
  e.stopPropagation();
470
284
  }
285
+ };
286
+ ;
287
+ (this.host = host).addController(this);
288
+ }
289
+ hostConnected() {
290
+ this.host.addEventListener("keydown", this.#keyboardNavigationHandler);
291
+ }
292
+ hostDisconnected() {
293
+ this.host.removeEventListener("keydown", this.#keyboardNavigationHandler);
294
+ }
295
+ #keyboardNavigationHandler;
296
+ };
297
+
298
+ // libs/core/src/utils/helpers/unwrap-slots.ts
299
+ function unwrap(slotRef) {
300
+ let slot = slotRef;
301
+ while (slot.assignedElements().length > 0 && slot.assignedElements()[0].nodeName === "SLOT") {
302
+ slot = slot.assignedElements()[0];
303
+ }
304
+ return slot;
305
+ }
306
+
307
+ // libs/core/src/primitives/listbox/listbox.ts
308
+ var _slotRef, _handleSelect;
309
+ var GdsListbox = class extends LitElement {
310
+ constructor() {
311
+ super();
312
+ this.multiple = false;
313
+ this.compareWith = (a, b) => a === b;
314
+ __privateAdd(this, _slotRef, createRef());
315
+ __privateAdd(this, _handleSelect, (e) => {
316
+ const option = e.target;
317
+ if (this.multiple)
318
+ option.selected = !option.selected;
319
+ else {
320
+ option.selected = true;
321
+ Array.from(this.options).forEach((el) => {
322
+ if (el !== option)
323
+ el.selected = false;
324
+ });
325
+ }
326
+ ;
327
+ this.ariaActiveDescendantElement = option;
328
+ this.dispatchEvent(
329
+ new CustomEvent("change", {
330
+ bubbles: false,
331
+ composed: false
332
+ })
333
+ );
471
334
  });
335
+ new ListboxKbNavController(this);
336
+ }
337
+ get navigableItems() {
338
+ return this.visibleOptionElements;
472
339
  }
473
340
  /**
474
341
  * Returns a list of all `gds-option` elements in the listbox.
475
342
  */
476
343
  get options() {
477
- let slot = __privateGet(this, _slotRef).value;
478
- if (!slot)
344
+ if (!__privateGet(this, _slotRef).value)
479
345
  return [];
480
- while (slot.assignedElements().length > 0 && slot.assignedElements()[0].nodeName === "SLOT") {
481
- slot = slot.assignedElements()[0];
482
- }
483
- return slot.assignedElements().filter(
346
+ return unwrap(__privateGet(this, _slotRef).value).assignedElements().filter(
484
347
  (o) => !o.hasAttribute("isplaceholder")
485
348
  ) || [];
486
349
  }
@@ -511,7 +374,6 @@ var GdsListbox = class extends LitElement2 {
511
374
  super.connectedCallback();
512
375
  this.setAttribute("role", "listbox");
513
376
  TransitionalStyles.instance.apply(this, "gds-listbox");
514
- this.addEventListener("keydown", __privateGet(this, _keyboardNavigationHandler));
515
377
  this.addEventListener("gds-select", __privateGet(this, _handleSelect));
516
378
  }
517
379
  /**
@@ -533,10 +395,9 @@ var GdsListbox = class extends LitElement2 {
533
395
  };
534
396
  _slotRef = new WeakMap();
535
397
  _handleSelect = new WeakMap();
536
- _keyboardNavigationHandler = new WeakMap();
537
398
  GdsListbox.styles = listbox_styles_default;
538
399
  __decorateClass([
539
- property2({
400
+ property({
540
401
  type: Boolean,
541
402
  reflect: true,
542
403
  attribute: "aria-multiselectable",
@@ -547,7 +408,7 @@ __decorateClass([
547
408
  })
548
409
  ], GdsListbox.prototype, "multiple", 2);
549
410
  __decorateClass([
550
- property2()
411
+ property()
551
412
  ], GdsListbox.prototype, "compareWith", 2);
552
413
  __decorateClass([
553
414
  watch("multiple")
@@ -556,12 +417,182 @@ GdsListbox = __decorateClass([
556
417
  gdsCustomElement("gds-listbox")
557
418
  ], GdsListbox);
558
419
 
420
+ // libs/core/src/primitives/listbox/option.ts
421
+ import { LitElement as LitElement2, html as html2 } from "lit";
422
+ import { property as property2 } from "lit/decorators.js";
423
+ import { when } from "lit/directives/when.js";
424
+ import { classMap } from "lit/directives/class-map.js";
425
+
426
+ // libs/core/src/primitives/listbox/option.styles.ts
427
+ import { css as css2 } from "lit";
428
+ var style2 = css2`
429
+ :host {
430
+ padding: 0.5 1rem;
431
+ cursor: pointer;
432
+ }
433
+
434
+ :host(:hover) {
435
+ background-color: grey;
436
+ }
437
+ `;
438
+ var option_styles_default = style2;
439
+
440
+ // libs/core/src/primitives/listbox/option.ts
441
+ import "reflect-metadata";
442
+
443
+ // libs/core/src/mixins/focusable.ts
444
+ var Focusable = (superClass) => {
445
+ class HighlightableElement extends superClass {
446
+ constructor() {
447
+ super(...arguments);
448
+ this.onblur = (e) => {
449
+ this.setAttribute("tabindex", "-1");
450
+ this.dispatchEvent(
451
+ new FocusEvent("gds-blur", {
452
+ bubbles: true,
453
+ composed: true,
454
+ relatedTarget: e.relatedTarget
455
+ })
456
+ );
457
+ };
458
+ this.onfocus = (e) => {
459
+ this.dispatchEvent(
460
+ new FocusEvent("gds-focus", {
461
+ bubbles: true,
462
+ composed: true,
463
+ relatedTarget: e.relatedTarget
464
+ })
465
+ );
466
+ };
467
+ }
468
+ focus(options) {
469
+ this.setAttribute("tabindex", "0");
470
+ super.focus(options);
471
+ if (document.activeElement !== this) {
472
+ const iv = setInterval(() => {
473
+ if (document.activeElement === this)
474
+ clearInterval(iv);
475
+ super.focus(options);
476
+ }, 10);
477
+ }
478
+ }
479
+ }
480
+ return HighlightableElement;
481
+ };
482
+
483
+ // libs/core/src/primitives/listbox/option.ts
484
+ var _hidden, _emitSelect, emitSelect_fn;
485
+ var GdsOption = class extends Focusable(LitElement2) {
486
+ constructor() {
487
+ super();
488
+ __privateAdd(this, _emitSelect);
489
+ __privateAdd(this, _hidden, false);
490
+ this.selected = false;
491
+ this.isPlaceholder = false;
492
+ this.addEventListener("click", __privateMethod(this, _emitSelect, emitSelect_fn));
493
+ this.addEventListener("keydown", (e) => {
494
+ if (e.key !== "Enter" && e.key !== " ")
495
+ return;
496
+ e.preventDefault();
497
+ __privateMethod(this, _emitSelect, emitSelect_fn).call(this);
498
+ });
499
+ }
500
+ get hidden() {
501
+ return __privateGet(this, _hidden);
502
+ }
503
+ set hidden(value) {
504
+ if (this.isPlaceholder)
505
+ return;
506
+ __privateSet(this, _hidden, value === "true" || value === true);
507
+ this.setAttribute("aria-hidden", value.toString());
508
+ }
509
+ connectedCallback() {
510
+ super.connectedCallback();
511
+ this.setAttribute("role", "option");
512
+ if (this.isPlaceholder) {
513
+ __privateSet(this, _hidden, true);
514
+ this.setAttribute("aria-hidden", "true");
515
+ }
516
+ this.updateComplete.then(
517
+ () => TransitionalStyles.instance.apply(this, "gds-option")
518
+ );
519
+ }
520
+ get parentElement() {
521
+ return super.parentElement;
522
+ }
523
+ handlePlaceholderStatusChange() {
524
+ if (this.isPlaceholder) {
525
+ __privateSet(this, _hidden, true);
526
+ this.setAttribute("aria-hidden", "true");
527
+ } else {
528
+ __privateSet(this, _hidden, false);
529
+ this.setAttribute("aria-hidden", "false");
530
+ }
531
+ }
532
+ render() {
533
+ const isMultiple = this.parentElement.multiple;
534
+ const checkbox = html2`<span
535
+ class="checkbox ${classMap({ checked: this.selected })}"
536
+ ></span>`;
537
+ if (!isMultiple) {
538
+ if (this.selected)
539
+ this.setAttribute("highlighted", "");
540
+ else
541
+ this.removeAttribute("highlighted");
542
+ }
543
+ return html2`${when(isMultiple, () => checkbox)}<slot></slot>`;
544
+ }
545
+ };
546
+ _hidden = new WeakMap();
547
+ _emitSelect = new WeakSet();
548
+ emitSelect_fn = function() {
549
+ this.dispatchEvent(
550
+ new CustomEvent("gds-select", {
551
+ bubbles: true,
552
+ composed: true,
553
+ detail: {
554
+ value: this.value
555
+ }
556
+ })
557
+ );
558
+ };
559
+ GdsOption.styles = option_styles_default;
560
+ __decorateClass([
561
+ property2()
562
+ ], GdsOption.prototype, "value", 2);
563
+ __decorateClass([
564
+ property2({
565
+ attribute: "aria-hidden",
566
+ reflect: true
567
+ })
568
+ ], GdsOption.prototype, "hidden", 1);
569
+ __decorateClass([
570
+ property2({
571
+ attribute: "aria-selected",
572
+ reflect: true
573
+ })
574
+ ], GdsOption.prototype, "selected", 2);
575
+ __decorateClass([
576
+ property2({ type: Boolean, reflect: true })
577
+ ], GdsOption.prototype, "isPlaceholder", 2);
578
+ __decorateClass([
579
+ watch("isplaceholder")
580
+ ], GdsOption.prototype, "handlePlaceholderStatusChange", 1);
581
+ GdsOption = __decorateClass([
582
+ gdsCustomElement("gds-option")
583
+ ], GdsOption);
584
+
559
585
  // libs/core/src/primitives/popover/popover.ts
560
586
  import { LitElement as LitElement3, html as html3, unsafeCSS as unsafeCSS3 } from "lit";
561
- import { property as property3 } from "lit/decorators.js";
587
+ import { property as property3, state } from "lit/decorators.js";
562
588
  import { msg } from "@lit/localize";
563
589
  import { createRef as createRef2, ref as ref2 } from "lit/directives/ref.js";
564
- import { computePosition, autoUpdate, offset, flip } from "@floating-ui/dom";
590
+ import {
591
+ computePosition,
592
+ autoUpdate,
593
+ offset,
594
+ flip
595
+ } from "@floating-ui/dom";
565
596
 
566
597
  // libs/core/src/primitives/popover/topLayerOverTransforms.middleware.ts
567
598
  var topLayerOverTransforms = () => ({
@@ -740,14 +771,16 @@ var GdsPopover = class extends LitElement3 {
740
771
  __privateAdd(this, _unregisterTriggerEvents);
741
772
  __privateAdd(this, _registerAutoPositioning);
742
773
  this.open = false;
743
- this.trigger = void 0;
774
+ this.triggerRef = Promise.resolve(void 0);
744
775
  this.label = void 0;
776
+ this.placement = "bottom-start";
777
+ this._trigger = void 0;
745
778
  __privateAdd(this, _dialogElementRef, createRef2());
746
779
  __privateAdd(this, _handleCloseButton, (e) => {
747
780
  e.stopPropagation();
748
781
  e.preventDefault();
749
782
  this.open = false;
750
- setTimeout(() => this.trigger?.focus(), 250);
783
+ setTimeout(() => this._trigger?.focus(), 250);
751
784
  });
752
785
  __privateAdd(this, _autoPositionCleanup, void 0);
753
786
  /**
@@ -782,8 +815,15 @@ var GdsPopover = class extends LitElement3 {
782
815
  }
783
816
  });
784
817
  }
818
+ _handleTriggerRefChanged() {
819
+ this.triggerRef.then((el) => {
820
+ if (el)
821
+ this._trigger = el;
822
+ });
823
+ }
785
824
  _handleTriggerChanged() {
786
825
  __privateMethod(this, _registerTriggerEvents, registerTriggerEvents_fn).call(this);
826
+ __privateMethod(this, _registerAutoPositioning, registerAutoPositioning_fn).call(this);
787
827
  }
788
828
  connectedCallback() {
789
829
  super.connectedCallback();
@@ -867,24 +907,24 @@ _dialogElementRef = new WeakMap();
867
907
  _handleCloseButton = new WeakMap();
868
908
  _registerTriggerEvents = new WeakSet();
869
909
  registerTriggerEvents_fn = function() {
870
- this.trigger?.addEventListener("keydown", __privateGet(this, _triggerKeyDownListener));
910
+ this._trigger?.addEventListener("keydown", __privateGet(this, _triggerKeyDownListener));
871
911
  };
872
912
  _unregisterTriggerEvents = new WeakSet();
873
913
  unregisterTriggerEvents_fn = function() {
874
914
  var _a;
875
- this.trigger?.removeEventListener("keydown", __privateGet(this, _triggerKeyDownListener));
915
+ this._trigger?.removeEventListener("keydown", __privateGet(this, _triggerKeyDownListener));
876
916
  (_a = __privateGet(this, _autoPositionCleanup)) == null ? void 0 : _a.call(this);
877
917
  };
878
918
  _autoPositionCleanup = new WeakMap();
879
919
  _registerAutoPositioning = new WeakSet();
880
920
  registerAutoPositioning_fn = function() {
881
- const referenceEl = this.trigger;
921
+ const referenceEl = this._trigger;
882
922
  const floatingEl = __privateGet(this, _dialogElementRef).value;
883
923
  if (!referenceEl || !floatingEl)
884
924
  return;
885
925
  __privateSet(this, _autoPositionCleanup, autoUpdate(referenceEl, floatingEl, () => {
886
926
  computePosition(referenceEl, floatingEl, {
887
- placement: "bottom-start",
927
+ placement: this.placement,
888
928
  middleware: [offset(8), flip(), topLayerOverTransforms()],
889
929
  strategy: "fixed"
890
930
  }).then(
@@ -905,12 +945,21 @@ __decorateClass([
905
945
  ], GdsPopover.prototype, "open", 2);
906
946
  __decorateClass([
907
947
  property3()
908
- ], GdsPopover.prototype, "trigger", 2);
948
+ ], GdsPopover.prototype, "triggerRef", 2);
909
949
  __decorateClass([
910
950
  property3()
911
951
  ], GdsPopover.prototype, "label", 2);
912
952
  __decorateClass([
913
- watch("trigger")
953
+ property3()
954
+ ], GdsPopover.prototype, "placement", 2);
955
+ __decorateClass([
956
+ state()
957
+ ], GdsPopover.prototype, "_trigger", 2);
958
+ __decorateClass([
959
+ watch("triggerRef")
960
+ ], GdsPopover.prototype, "_handleTriggerRefChanged", 1);
961
+ __decorateClass([
962
+ watch("_trigger")
914
963
  ], GdsPopover.prototype, "_handleTriggerChanged", 1);
915
964
  __decorateClass([
916
965
  watch("open")
@@ -1034,16 +1083,10 @@ var style4 = css4`
1034
1083
  var dropdown_styles_default = style4;
1035
1084
 
1036
1085
  // libs/core/src/components/dropdown/dropdown.ts
1037
- var _listboxRef, _triggerRef, _searchInputRef, _optionElements, _listboxId, _triggerId, _handleSearchFieldKeyUp, _handleSearchFieldKeyDown, _handleListboxKeyDown, _handleOptionFocusChange, _registerPopoverTrigger, registerPopoverTrigger_fn, _handleSelectionChange, handleSelectionChange_fn, _registerAutoCloseListener, registerAutoCloseListener_fn, _unregisterAutoCloseListener, unregisterAutoCloseListener_fn, _blurCloseListener, _tabCloseListener;
1086
+ var _optionElements, _handleSearchFieldKeyUp, _handleSearchFieldKeyDown, _handleListboxKeyDown, _handleOptionFocusChange, _handleSelectionChange, handleSelectionChange_fn, _registerAutoCloseListener, registerAutoCloseListener_fn, _unregisterAutoCloseListener, unregisterAutoCloseListener_fn, _blurCloseListener, _tabCloseListener;
1038
1087
  var GdsDropdown = class extends GdsFormControlElement {
1039
1088
  constructor() {
1040
1089
  super();
1041
- /**
1042
- * Registers the trigger button of the dropdown to the popover.
1043
- *
1044
- * @param el The popover element.
1045
- */
1046
- __privateAdd(this, _registerPopoverTrigger);
1047
1090
  /**
1048
1091
  * Selects an option in the dropdown.
1049
1092
  *
@@ -1059,19 +1102,14 @@ var GdsDropdown = class extends GdsFormControlElement {
1059
1102
  this.compareWith = (a, b) => a === b;
1060
1103
  this.searchFilter = (q, o) => o.innerHTML.toLowerCase().includes(q.toLowerCase());
1061
1104
  // Private members
1062
- __privateAdd(this, _listboxRef, createRef3());
1063
- __privateAdd(this, _triggerRef, createRef3());
1064
- __privateAdd(this, _searchInputRef, createRef3());
1065
1105
  __privateAdd(this, _optionElements, void 0);
1066
- __privateAdd(this, _listboxId, randomId());
1067
- __privateAdd(this, _triggerId, randomId());
1068
1106
  /**
1069
1107
  * Event handler for filtering the options in the dropdown.
1070
1108
  *
1071
1109
  * @param e The keyboard event.
1072
1110
  */
1073
1111
  __privateAdd(this, _handleSearchFieldKeyUp, (e) => {
1074
- const input = __privateGet(this, _searchInputRef).value;
1112
+ const input = this.elSearchInput;
1075
1113
  const options = Array.from(__privateGet(this, _optionElements));
1076
1114
  options.forEach((o) => o.hidden = false);
1077
1115
  if (!input.value)
@@ -1088,7 +1126,7 @@ var GdsDropdown = class extends GdsFormControlElement {
1088
1126
  __privateAdd(this, _handleSearchFieldKeyDown, (e) => {
1089
1127
  if (e.key === "ArrowDown" || e.key === "Tab") {
1090
1128
  e.preventDefault();
1091
- __privateGet(this, _listboxRef).value?.focus();
1129
+ this.elListbox?.focus();
1092
1130
  return;
1093
1131
  }
1094
1132
  });
@@ -1099,12 +1137,12 @@ var GdsDropdown = class extends GdsFormControlElement {
1099
1137
  __privateAdd(this, _handleListboxKeyDown, (e) => {
1100
1138
  if (e.key === "Tab" && this.searchable) {
1101
1139
  e.preventDefault();
1102
- __privateGet(this, _searchInputRef).value?.focus();
1140
+ this.elSearchInput?.focus();
1103
1141
  return;
1104
1142
  }
1105
1143
  });
1106
1144
  __privateAdd(this, _handleOptionFocusChange, (e) => {
1107
- const triggerButton = __privateGet(this, _triggerRef).value;
1145
+ const triggerButton = this.elTriggerBtn;
1108
1146
  if (triggerButton)
1109
1147
  triggerButton.ariaActiveDescendantElement = e.target;
1110
1148
  });
@@ -1120,7 +1158,7 @@ var GdsDropdown = class extends GdsFormControlElement {
1120
1158
  if (e.key === "Tab" && !this.searchable) {
1121
1159
  e.preventDefault();
1122
1160
  this.open = false;
1123
- __privateGet(this, _triggerRef).value?.focus();
1161
+ this.elTriggerBtn?.focus();
1124
1162
  }
1125
1163
  });
1126
1164
  constrainSlots(this);
@@ -1174,20 +1212,19 @@ var GdsDropdown = class extends GdsFormControlElement {
1174
1212
  return html`
1175
1213
  ${when2(
1176
1214
  this.label,
1177
- () => html`<label for="${__privateGet(this, _triggerId)}">${this.label}</label>`
1215
+ () => html`<label for="trigger">${this.label}</label>`
1178
1216
  )}
1179
1217
 
1180
1218
  <span class="form-info"><slot name="sub-label"></slot></span>
1181
1219
 
1182
1220
  <button
1183
- id="${__privateGet(this, _triggerId)}"
1221
+ id="trigger"
1184
1222
  @click="${() => this.open = !this.open}"
1185
1223
  aria-haspopup="listbox"
1186
1224
  role="combobox"
1187
- aria-owns="${__privateGet(this, _listboxId)}"
1188
- aria-controls="${__privateGet(this, _listboxId)}"
1225
+ aria-owns="listbox"
1226
+ aria-controls="listbox"
1189
1227
  aria-expanded="${this.open}"
1190
- ${ref3(__privateGet(this, _triggerRef))}
1191
1228
  >
1192
1229
  <slot name="trigger">
1193
1230
  <span>${unsafeHTML(this.displayValue)}</span>
@@ -1199,26 +1236,25 @@ var GdsDropdown = class extends GdsFormControlElement {
1199
1236
  <gds-popover
1200
1237
  .label=${this.label}
1201
1238
  .open=${this.open}
1239
+ .triggerRef=${this.elTriggerBtnAsync}
1202
1240
  @gds-ui-state=${(e) => this.open = e.detail.open}
1203
- ${ref3(__privateMethod(this, _registerPopoverTrigger, registerPopoverTrigger_fn))}
1204
1241
  >
1205
1242
  ${when2(
1206
1243
  this.searchable,
1207
1244
  () => html`<input
1245
+ id="searchinput"
1208
1246
  type="text"
1209
1247
  aria-label="${msg2("Filter available options")}"
1210
1248
  placeholder="${msg2("Search")}"
1211
- ${ref3(__privateGet(this, _searchInputRef))}
1212
1249
  @keydown=${__privateGet(this, _handleSearchFieldKeyDown)}
1213
1250
  @keyup=${__privateGet(this, _handleSearchFieldKeyUp)}
1214
1251
  />`
1215
1252
  )}
1216
1253
 
1217
1254
  <gds-listbox
1218
- id="${__privateGet(this, _listboxId)}"
1255
+ id="listbox"
1219
1256
  .multiple="${ifDefined(this.multiple)}"
1220
1257
  .compareWith="${this.compareWith}"
1221
- ${ref3(__privateGet(this, _listboxRef))}
1222
1258
  @change="${__privateMethod(this, _handleSelectionChange, handleSelectionChange_fn)}"
1223
1259
  @gds-focus="${__privateGet(this, _handleOptionFocusChange)}"
1224
1260
  @keydown=${__privateGet(this, _handleListboxKeyDown)}
@@ -1244,7 +1280,7 @@ var GdsDropdown = class extends GdsFormControlElement {
1244
1280
  }
1245
1281
  }
1246
1282
  _handleValueChange() {
1247
- const listbox = __privateGet(this, _listboxRef).value;
1283
+ const listbox = this.elListbox;
1248
1284
  if (listbox) {
1249
1285
  if (Array.isArray(this.value))
1250
1286
  listbox.selection = this.value;
@@ -1259,7 +1295,7 @@ var GdsDropdown = class extends GdsFormControlElement {
1259
1295
  __privateMethod(this, _registerAutoCloseListener, registerAutoCloseListener_fn).call(this);
1260
1296
  else {
1261
1297
  __privateMethod(this, _unregisterAutoCloseListener, unregisterAutoCloseListener_fn).call(this);
1262
- __privateGet(this, _searchInputRef).value && (__privateGet(this, _searchInputRef).value.value = "");
1298
+ this.elSearchInput && (this.elSearchInput.value = "");
1263
1299
  }
1264
1300
  this.dispatchEvent(
1265
1301
  new CustomEvent("gds-ui-state", {
@@ -1270,26 +1306,14 @@ var GdsDropdown = class extends GdsFormControlElement {
1270
1306
  );
1271
1307
  }
1272
1308
  };
1273
- _listboxRef = new WeakMap();
1274
- _triggerRef = new WeakMap();
1275
- _searchInputRef = new WeakMap();
1276
1309
  _optionElements = new WeakMap();
1277
- _listboxId = new WeakMap();
1278
- _triggerId = new WeakMap();
1279
1310
  _handleSearchFieldKeyUp = new WeakMap();
1280
1311
  _handleSearchFieldKeyDown = new WeakMap();
1281
1312
  _handleListboxKeyDown = new WeakMap();
1282
1313
  _handleOptionFocusChange = new WeakMap();
1283
- _registerPopoverTrigger = new WeakSet();
1284
- registerPopoverTrigger_fn = function(el) {
1285
- if (el) {
1286
- const popover = el;
1287
- popover.trigger = __privateGet(this, _triggerRef).value;
1288
- }
1289
- };
1290
1314
  _handleSelectionChange = new WeakSet();
1291
1315
  handleSelectionChange_fn = function() {
1292
- const listbox = __privateGet(this, _listboxRef).value;
1316
+ const listbox = this.elListbox;
1293
1317
  if (!listbox)
1294
1318
  return;
1295
1319
  if (this.multiple)
@@ -1297,7 +1321,7 @@ handleSelectionChange_fn = function() {
1297
1321
  else {
1298
1322
  this.value = listbox.selection[0]?.value;
1299
1323
  this.open = false;
1300
- setTimeout(() => __privateGet(this, _triggerRef).value?.focus(), 0);
1324
+ setTimeout(() => this.elTriggerBtn?.focus(), 0);
1301
1325
  }
1302
1326
  this.dispatchEvent(
1303
1327
  new CustomEvent("change", {
@@ -1344,6 +1368,18 @@ __decorateClass([
1344
1368
  __decorateClass([
1345
1369
  property5()
1346
1370
  ], GdsDropdown.prototype, "searchFilter", 2);
1371
+ __decorateClass([
1372
+ query("#trigger")
1373
+ ], GdsDropdown.prototype, "elTriggerBtn", 2);
1374
+ __decorateClass([
1375
+ queryAsync("#trigger")
1376
+ ], GdsDropdown.prototype, "elTriggerBtnAsync", 2);
1377
+ __decorateClass([
1378
+ query("#listbox")
1379
+ ], GdsDropdown.prototype, "elListbox", 2);
1380
+ __decorateClass([
1381
+ query("#searchinput")
1382
+ ], GdsDropdown.prototype, "elSearchInput", 2);
1347
1383
  __decorateClass([
1348
1384
  observeLightDOM()
1349
1385
  ], GdsDropdown.prototype, "_handleLightDOMChange", 1);
@@ -1356,8 +1392,170 @@ __decorateClass([
1356
1392
  GdsDropdown = __decorateClass([
1357
1393
  gdsCustomElement("gds-dropdown")
1358
1394
  ], GdsDropdown);
1395
+
1396
+ // libs/core/src/components/context-menu/context-menu.ts
1397
+ import { LitElement as LitElement6 } from "lit-element";
1398
+ import { msg as msg3 } from "@lit/localize";
1399
+ import { classMap as classMap2 } from "lit-html/directives/class-map.js";
1400
+ import { property as property6, queryAsync as queryAsync2 } from "lit/decorators.js";
1401
+
1402
+ // libs/core/src/primitives/menu/menu.ts
1403
+ import { LitElement as LitElement5 } from "lit";
1404
+ import { createRef as createRef3, ref as ref3 } from "lit/directives/ref.js";
1405
+ var _slotRef2;
1406
+ var GdsMenu = class extends LitElement5 {
1407
+ constructor() {
1408
+ super();
1409
+ __privateAdd(this, _slotRef2, createRef3());
1410
+ new ListboxKbNavController(this);
1411
+ }
1412
+ connectedCallback() {
1413
+ super.connectedCallback();
1414
+ this.setAttribute("role", "menu");
1415
+ TransitionalStyles.instance.apply(this, "gds-listbox");
1416
+ }
1417
+ get navigableItems() {
1418
+ if (!__privateGet(this, _slotRef2).value)
1419
+ return [];
1420
+ return unwrap(__privateGet(this, _slotRef2).value).assignedElements().filter(
1421
+ (o) => !o.hasAttribute("isplaceholder")
1422
+ ) || [];
1423
+ }
1424
+ /**
1425
+ * Focuses the first item in the menu.
1426
+ */
1427
+ focus() {
1428
+ this.navigableItems[0]?.focus();
1429
+ }
1430
+ render() {
1431
+ return html`<slot ${ref3(__privateGet(this, _slotRef2))}></slot>`;
1432
+ }
1433
+ };
1434
+ _slotRef2 = new WeakMap();
1435
+ GdsMenu = __decorateClass([
1436
+ gdsCustomElement("gds-menu")
1437
+ ], GdsMenu);
1438
+
1439
+ // libs/core/src/components/context-menu/context-menu.ts
1440
+ var _handleItemClick, handleItemClick_fn;
1441
+ var GdsContextMenu = class extends LitElement6 {
1442
+ constructor() {
1443
+ super();
1444
+ __privateAdd(this, _handleItemClick);
1445
+ this.open = false;
1446
+ this.buttonLabel = msg3("Open context menu");
1447
+ this.label = "";
1448
+ this.placement = "bottom-start";
1449
+ constrainSlots(this);
1450
+ }
1451
+ connectedCallback() {
1452
+ super.connectedCallback();
1453
+ TransitionalStyles.instance.apply(this, "gds-context-menu");
1454
+ this.addEventListener("keydown", (e) => {
1455
+ if (this.open && e.key == "Tab") {
1456
+ e.preventDefault();
1457
+ this.open = false;
1458
+ this.elTriggerBtn.then((el) => el.focus());
1459
+ }
1460
+ });
1461
+ }
1462
+ render() {
1463
+ return html`<button
1464
+ id="trigger"
1465
+ class="ghost border-0 small ${classMap2({ highlighted: this.open })}"
1466
+ aria-label="${this.buttonLabel}"
1467
+ aria-haspopup="menu"
1468
+ aria-controls="menu"
1469
+ aria-expanded=${this.open}
1470
+ @click=${() => this.open = !this.open}
1471
+ >
1472
+ <slot name="trigger">
1473
+ <i class="sg-icon sg-icon-ellipsis"></i>
1474
+ </slot>
1475
+ </button>
1476
+ <gds-popover
1477
+ id="menu"
1478
+ .open=${this.open}
1479
+ .triggerRef=${this.elTriggerBtn}
1480
+ .label=${this.label}
1481
+ .placement=${this.placement}
1482
+ @gds-ui-state=${(e) => this.open = e.detail.open}
1483
+ >
1484
+ <gds-menu
1485
+ aria-label=${this.label}
1486
+ @gds-menu-item-click=${__privateMethod(this, _handleItemClick, handleItemClick_fn)}
1487
+ >
1488
+ <slot allow="gds-menu-item"></slot>
1489
+ </gds-menu>
1490
+ </gds-popover>`;
1491
+ }
1492
+ };
1493
+ _handleItemClick = new WeakSet();
1494
+ handleItemClick_fn = function() {
1495
+ this.open = false;
1496
+ };
1497
+ GdsContextMenu.shadowRootOptions = {
1498
+ mode: "open",
1499
+ delegatesFocus: true
1500
+ };
1501
+ __decorateClass([
1502
+ property6({ type: Boolean, reflect: true })
1503
+ ], GdsContextMenu.prototype, "open", 2);
1504
+ __decorateClass([
1505
+ property6()
1506
+ ], GdsContextMenu.prototype, "buttonLabel", 2);
1507
+ __decorateClass([
1508
+ property6()
1509
+ ], GdsContextMenu.prototype, "label", 2);
1510
+ __decorateClass([
1511
+ property6()
1512
+ ], GdsContextMenu.prototype, "placement", 2);
1513
+ __decorateClass([
1514
+ queryAsync2("#trigger")
1515
+ ], GdsContextMenu.prototype, "elTriggerBtn", 2);
1516
+ GdsContextMenu = __decorateClass([
1517
+ gdsCustomElement("gds-context-menu")
1518
+ ], GdsContextMenu);
1519
+
1520
+ // libs/core/src/primitives/menu/menu-item.ts
1521
+ import { LitElement as LitElement7 } from "lit";
1522
+ var _handleOnClick;
1523
+ var GdsMenuItem = class extends Focusable(LitElement7) {
1524
+ constructor() {
1525
+ super(...arguments);
1526
+ __privateAdd(this, _handleOnClick, () => {
1527
+ this.dispatchEvent(
1528
+ new CustomEvent("gds-menu-item-click", {
1529
+ bubbles: true,
1530
+ composed: true
1531
+ })
1532
+ );
1533
+ });
1534
+ }
1535
+ connectedCallback() {
1536
+ super.connectedCallback();
1537
+ this.setAttribute("role", "menuitem");
1538
+ this.addEventListener("keydown", (e) => {
1539
+ if (e.key !== "Enter" && e.key !== " ")
1540
+ return;
1541
+ e.preventDefault();
1542
+ this.click();
1543
+ });
1544
+ this.addEventListener("click", __privateGet(this, _handleOnClick));
1545
+ TransitionalStyles.instance.apply(this, "gds-option");
1546
+ }
1547
+ render() {
1548
+ return html`<slot></slot>`;
1549
+ }
1550
+ };
1551
+ _handleOnClick = new WeakMap();
1552
+ GdsMenuItem = __decorateClass([
1553
+ gdsCustomElement("gds-menu-item")
1554
+ ], GdsMenuItem);
1359
1555
  export {
1556
+ GdsContextMenu,
1360
1557
  GdsDropdown,
1558
+ GdsMenuItem,
1361
1559
  GdsOption,
1362
1560
  VER_SUFFIX,
1363
1561
  gdsCustomElement,