blue-web 1.20.0 → 1.21.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.
@@ -1 +1 @@
1
- (()=>{"use strict";class t extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}),this.shadowRoot.innerHTML='<slot style="border-radius: inherit"></slot>',this.activeIndex=-1,this.items=[],this.inputElement=null}connectedCallback(){this.setAttribute("role","listbox"),this.tabIndex=-1,this.updateItems();const t=this.getAttribute("for");this.inputElement=t?document.getElementById(t):null,this.inputElement&&(this.inputElement.setAttribute("role","combobox"),this.inputElement.setAttribute("aria-controls",this.id),this.inputElement.setAttribute("aria-expanded","true"),this.inputElement.addEventListener("keydown",this.onKeyDown.bind(this))),this.addEventListener("keydown",this.onKeyDown.bind(this)),this.addEventListener("click",t=>{const e=t.target instanceof Element?t.target.closest("[data-blue-select-list-index]"):null;if(e&&e.hasAttribute("data-blue-select-list-index")){const t=Number(e.getAttribute("data-blue-select-list-index"));this.select(t)}})}updateItems(){this.items=Array.from(this.children),this.items.forEach((t,e)=>{t.hasAttribute("id")||t.setAttribute("id","".concat(this.id,"-option-").concat(e)),t.setAttribute("data-blue-select-list-index",e.toString()),t.setAttribute("aria-selected","false"),t.setAttribute("role","option"),t.tabIndex=-1})}onKeyDown(t){if(this.items.length)if("ArrowDown"===t.key)t.preventDefault(),this.activeIndex=(this.activeIndex+1)%this.items.length,this.updateActiveItem();else if("ArrowUp"===t.key)t.preventDefault(),this.activeIndex=(this.activeIndex-1+this.items.length)%this.items.length,this.updateActiveItem();else if("Enter"===t.key&&this.activeIndex>=0){const t=this.items[this.activeIndex];null==t||t.click()}}updateActiveItem(){this.items.forEach((t,e)=>{const i=e===this.activeIndex;t.classList.toggle("active",i),t.setAttribute("aria-selected",i.toString())});const t=this.items[this.activeIndex];t&&this.inputElement&&(this.inputElement.setAttribute("aria-activedescendant",t.id),t.scrollIntoView({block:"nearest"}))}select(t){this.activeIndex=t,this.updateActiveItem();const e=this.items[t];e&&(this.dispatchEvent(new CustomEvent("bl-select",{detail:{index:t,item:e},bubbles:!0,composed:!0})),e.click())}}customElements.define("bl-select-list",t)})();
1
+ (()=>{"use strict";var t={};function e(t,e,i){return(e=function(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}t.d=(e,i)=>{for(var s in i)t.o(i,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:i[s]})},t.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);class i extends Event{constructor(t,e){super(i.eventName,{bubbles:!0,composed:!0}),this.index=t,this.item=e}}e(i,"eventName","bl-select");class s extends HTMLElement{constructor(){super(),e(this,"handleChildrenChanged",()=>{var t;const e=null===(t=this.items[this.activeIndex])||void 0===t?void 0:t.id;if(this.updateItems(),e){const t=this.items.findIndex(t=>t.id===e);this.activeIndex=t>=0?t:-1}else this.activeIndex=-1;this.updateActiveItem()}),this.attachShadow({mode:"open"}),this.shadowRoot.innerHTML='<slot style="border-radius: inherit"></slot>',this.activeIndex=-1,this.items=[],this.inputElement=null,this.slotElement=null,this.observer=null}get activeClass(){return this.getAttribute("active-class")||"active"}connectedCallback(){var t,e;this.setAttribute("role","listbox"),this.tabIndex=-1,this.updateItems(),this.syncActiveIndexFromDataSelected(),this.updateActiveItem();const i=this.getAttribute("for");this.inputElement=i?document.getElementById(i):null,this.inputElement&&(this.inputElement.setAttribute("role","combobox"),this.inputElement.setAttribute("aria-controls",this.id),this.inputElement.setAttribute("aria-expanded","true"),this.inputElement.addEventListener("keydown",this.onKeyDown.bind(this))),this.addEventListener("keydown",this.onKeyDown.bind(this)),this.addEventListener("click",t=>{const e=t.target instanceof Element?t.target.closest("[data-select-list-index]"):null;if(e&&e.hasAttribute("data-select-list-index")){const t=Number(e.getAttribute("data-select-list-index"));this.select(t)}}),this.observer=new MutationObserver(t=>{t.some(t=>"childList"===t.type)&&this.handleChildrenChanged(),t.some(t=>"attributes"===t.type&&"data-selected"===t.attributeName)&&(this.syncActiveIndexFromDataSelected(),this.updateActiveItem())}),this.observer.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-selected"]}),this.slotElement=null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector("slot"),null===(e=this.slotElement)||void 0===e||e.addEventListener("slotchange",this.handleChildrenChanged)}disconnectedCallback(){var t,e;null===(t=this.observer)||void 0===t||t.disconnect(),this.observer=null,null===(e=this.slotElement)||void 0===e||e.removeEventListener("slotchange",this.handleChildrenChanged)}syncActiveIndexFromDataSelected(){const t=this.items.findIndex(t=>t.hasAttribute("data-selected"));t>=0&&(this.activeIndex=t)}updateItems(){const t=["button:not([disabled])","a[href]","input:not([disabled])","select:not([disabled])","textarea:not([disabled])",'[tabindex]:not([tabindex="-1"])','[role="option"]'].join(", ");this.items=Array.from(this.querySelectorAll(t)),this.items.forEach((t,e)=>{t.hasAttribute("id")||t.setAttribute("id","".concat(this.id,"-option-").concat(e)),t.setAttribute("data-select-list-index",e.toString()),t.setAttribute("aria-selected","false"),t.setAttribute("role","option"),t.tabIndex=-1})}onKeyDown(t){if(this.items.length)if("ArrowDown"===t.key)t.preventDefault(),this.activeIndex=(this.activeIndex+1)%this.items.length,this.updateActiveItem();else if("ArrowUp"===t.key)t.preventDefault(),this.activeIndex=(this.activeIndex-1+this.items.length)%this.items.length,this.updateActiveItem();else if("Enter"===t.key&&this.activeIndex>=0){t.preventDefault();const e=this.items[this.activeIndex];null==e||e.click()}}updateActiveItem(){const t=this.activeClass.split(" ");this.items.forEach((e,i)=>{const s=i===this.activeIndex;t.forEach(t=>{e.classList.toggle(t,s)}),e.setAttribute("aria-selected",s.toString())});const e=this.items[this.activeIndex];e&&this.inputElement?(this.inputElement.setAttribute("aria-activedescendant",e.id),e.scrollIntoView({block:"nearest"})):this.inputElement&&this.inputElement.removeAttribute("aria-activedescendant")}select(t){this.activeIndex=t,this.items.forEach(t=>t.removeAttribute("data-selected"));const e=this.items[t];e&&(e.setAttribute("data-selected",""),this.dispatchEvent(new i(t,e)),this.updateActiveItem())}}customElements.get("bl-select-list")||customElements.define("bl-select-list",s)})();
@@ -1,3 +1,9 @@
1
+ declare class BlSelectEvent extends Event {
2
+ static readonly eventName = "bl-select";
3
+ readonly index: number;
4
+ readonly item: HTMLElement;
5
+ constructor(index: number, item: HTMLElement);
6
+ }
1
7
  /**
2
8
  * A Web Component that provides a keyboard-accessible selectable list, typically used for dropdowns or autocomplete lists.
3
9
  * Together with `popover` and CSS Anchoring, it's also useful to create a dropdown list.
@@ -5,22 +11,29 @@
5
11
  *
6
12
  * The Web Component will automatically set attributes for accessibility.
7
13
  *
8
- * @element blue-select-list
14
+ * @element bl-select-list
9
15
  * @attr {string} for - The id of the input element to associate as the combobox controller.
16
+ * @attr {string} active-class - The CSS class name to apply to the active item (default: "active").
10
17
  * @slot - The list options.
11
18
  * @example
12
19
  * <input id="my-input" />
13
- * <blue-select-list for="my-input">
20
+ * <bl-select-list for="my-input">
14
21
  * <div>Option 1</div>
15
22
  * <div>Option 2</div>
16
- * </blue-select-list>
23
+ * </bl-select-list>
17
24
  */
18
- export declare class SelectList extends HTMLElement {
25
+ declare class SelectList extends HTMLElement {
19
26
  activeIndex: number;
20
27
  items: HTMLElement[];
21
28
  inputElement: HTMLElement | null;
29
+ slotElement: HTMLSlotElement | null;
30
+ observer: MutationObserver | null;
22
31
  constructor();
32
+ get activeClass(): string;
23
33
  connectedCallback(): void;
34
+ disconnectedCallback(): void;
35
+ handleChildrenChanged: () => void;
36
+ syncActiveIndexFromDataSelected(): void;
24
37
  updateItems(): void;
25
38
  onKeyDown(e: {
26
39
  key: string;
@@ -29,3 +42,5 @@ export declare class SelectList extends HTMLElement {
29
42
  updateActiveItem(): void;
30
43
  select(index: number): void;
31
44
  }
45
+ export { SelectList, BlSelectEvent };
46
+ export default SelectList;
@@ -1,3 +1,17 @@
1
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
2
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
+ class BlSelectEvent extends Event {
5
+ constructor(index, item) {
6
+ super(BlSelectEvent.eventName, {
7
+ bubbles: true,
8
+ composed: true
9
+ });
10
+ this.index = index;
11
+ this.item = item;
12
+ }
13
+ }
14
+
1
15
  /**
2
16
  * A Web Component that provides a keyboard-accessible selectable list, typically used for dropdowns or autocomplete lists.
3
17
  * Together with `popover` and CSS Anchoring, it's also useful to create a dropdown list.
@@ -5,19 +19,33 @@
5
19
  *
6
20
  * The Web Component will automatically set attributes for accessibility.
7
21
  *
8
- * @element blue-select-list
22
+ * @element bl-select-list
9
23
  * @attr {string} for - The id of the input element to associate as the combobox controller.
24
+ * @attr {string} active-class - The CSS class name to apply to the active item (default: "active").
10
25
  * @slot - The list options.
11
26
  * @example
12
27
  * <input id="my-input" />
13
- * <blue-select-list for="my-input">
28
+ * <bl-select-list for="my-input">
14
29
  * <div>Option 1</div>
15
30
  * <div>Option 2</div>
16
- * </blue-select-list>
31
+ * </bl-select-list>
17
32
  */
18
- export class SelectList extends HTMLElement {
33
+ _defineProperty(BlSelectEvent, "eventName", "bl-select");
34
+ class SelectList extends HTMLElement {
19
35
  constructor() {
20
36
  super();
37
+ _defineProperty(this, "handleChildrenChanged", () => {
38
+ var _this$items$this$acti;
39
+ const previousActiveId = (_this$items$this$acti = this.items[this.activeIndex]) === null || _this$items$this$acti === void 0 ? void 0 : _this$items$this$acti.id;
40
+ this.updateItems();
41
+ if (previousActiveId) {
42
+ const newIndex = this.items.findIndex(el => el.id === previousActiveId);
43
+ this.activeIndex = newIndex >= 0 ? newIndex : -1;
44
+ } else {
45
+ this.activeIndex = -1;
46
+ }
47
+ this.updateActiveItem();
48
+ });
21
49
  this.attachShadow({
22
50
  mode: "open"
23
51
  });
@@ -25,13 +53,19 @@ export class SelectList extends HTMLElement {
25
53
  this.activeIndex = -1;
26
54
  this.items = [];
27
55
  this.inputElement = null;
56
+ this.slotElement = null;
57
+ this.observer = null;
58
+ }
59
+ get activeClass() {
60
+ return this.getAttribute("active-class") || "active";
28
61
  }
29
62
  connectedCallback() {
63
+ var _this$shadowRoot, _this$slotElement;
30
64
  this.setAttribute("role", "listbox");
31
65
  this.tabIndex = -1;
32
66
  this.updateItems();
33
-
34
- // Input zuweisen über Attribut oder fallback
67
+ this.syncActiveIndexFromDataSelected();
68
+ this.updateActiveItem();
35
69
  const inputId = this.getAttribute("for");
36
70
  this.inputElement = inputId ? document.getElementById(inputId) : null;
37
71
  if (this.inputElement) {
@@ -42,20 +76,50 @@ export class SelectList extends HTMLElement {
42
76
  }
43
77
  this.addEventListener("keydown", this.onKeyDown.bind(this));
44
78
  this.addEventListener("click", e => {
45
- const target = e.target instanceof Element ? e.target.closest("[data-blue-select-list-index]") : null;
46
- if (target && target.hasAttribute("data-blue-select-list-index")) {
47
- const index = Number(target.getAttribute("data-blue-select-list-index"));
79
+ const target = e.target instanceof Element ? e.target.closest("[data-select-list-index]") : null;
80
+ if (target && target.hasAttribute("data-select-list-index")) {
81
+ const index = Number(target.getAttribute("data-select-list-index"));
48
82
  this.select(index);
49
83
  }
50
84
  });
85
+ this.observer = new MutationObserver(mutations => {
86
+ if (mutations.some(m => m.type === "childList")) {
87
+ this.handleChildrenChanged();
88
+ }
89
+ if (mutations.some(m => m.type === "attributes" && m.attributeName === "data-selected")) {
90
+ this.syncActiveIndexFromDataSelected();
91
+ this.updateActiveItem();
92
+ }
93
+ });
94
+ this.observer.observe(this, {
95
+ childList: true,
96
+ subtree: true,
97
+ attributes: true,
98
+ attributeFilter: ["data-selected"]
99
+ });
100
+ this.slotElement = (_this$shadowRoot = this.shadowRoot) === null || _this$shadowRoot === void 0 ? void 0 : _this$shadowRoot.querySelector("slot");
101
+ (_this$slotElement = this.slotElement) === null || _this$slotElement === void 0 || _this$slotElement.addEventListener("slotchange", this.handleChildrenChanged);
102
+ }
103
+ disconnectedCallback() {
104
+ var _this$observer, _this$slotElement2;
105
+ (_this$observer = this.observer) === null || _this$observer === void 0 || _this$observer.disconnect();
106
+ this.observer = null;
107
+ (_this$slotElement2 = this.slotElement) === null || _this$slotElement2 === void 0 || _this$slotElement2.removeEventListener("slotchange", this.handleChildrenChanged);
108
+ }
109
+ syncActiveIndexFromDataSelected() {
110
+ const selectedIndex = this.items.findIndex(el => el.hasAttribute("data-selected"));
111
+ if (selectedIndex >= 0) {
112
+ this.activeIndex = selectedIndex;
113
+ }
51
114
  }
52
115
  updateItems() {
53
- this.items = Array.from(this.children);
116
+ const selectableSelectors = ["button:not([disabled])", "a[href]", "input:not([disabled])", "select:not([disabled])", "textarea:not([disabled])", '[tabindex]:not([tabindex="-1"])', '[role="option"]'].join(", ");
117
+ this.items = Array.from(this.querySelectorAll(selectableSelectors));
54
118
  this.items.forEach((el, i) => {
55
119
  if (!el.hasAttribute("id")) {
56
120
  el.setAttribute("id", "".concat(this.id, "-option-").concat(i));
57
121
  }
58
- el.setAttribute("data-blue-select-list-index", i.toString());
122
+ el.setAttribute("data-select-list-index", i.toString());
59
123
  el.setAttribute("aria-selected", "false");
60
124
  el.setAttribute("role", "option");
61
125
  el.tabIndex = -1;
@@ -72,14 +136,18 @@ export class SelectList extends HTMLElement {
72
136
  this.activeIndex = (this.activeIndex - 1 + this.items.length) % this.items.length;
73
137
  this.updateActiveItem();
74
138
  } else if (e.key === "Enter" && this.activeIndex >= 0) {
139
+ e.preventDefault();
75
140
  const item = this.items[this.activeIndex];
76
141
  item === null || item === void 0 || item.click();
77
142
  }
78
143
  }
79
144
  updateActiveItem() {
145
+ const activeClassNames = this.activeClass.split(" ");
80
146
  this.items.forEach((el, i) => {
81
147
  const active = i === this.activeIndex;
82
- el.classList.toggle("active", active);
148
+ activeClassNames.forEach(activeClassName => {
149
+ el.classList.toggle(activeClassName, active);
150
+ });
83
151
  el.setAttribute("aria-selected", active.toString());
84
152
  });
85
153
  const activeItem = this.items[this.activeIndex];
@@ -88,24 +156,23 @@ export class SelectList extends HTMLElement {
88
156
  activeItem.scrollIntoView({
89
157
  block: "nearest"
90
158
  });
159
+ } else if (this.inputElement) {
160
+ this.inputElement.removeAttribute("aria-activedescendant");
91
161
  }
92
162
  }
93
163
  select(index) {
94
164
  this.activeIndex = index;
95
- this.updateActiveItem();
165
+ this.items.forEach(el => el.removeAttribute("data-selected"));
96
166
  const selectedItem = this.items[index];
97
167
  if (selectedItem) {
98
- // Fire a custom event with the selected item and index
99
- this.dispatchEvent(new CustomEvent("bl-select", {
100
- detail: {
101
- index,
102
- item: selectedItem
103
- },
104
- bubbles: true,
105
- composed: true
106
- }));
107
- selectedItem.click();
168
+ selectedItem.setAttribute("data-selected", "");
169
+ this.dispatchEvent(new BlSelectEvent(index, selectedItem));
170
+ this.updateActiveItem();
108
171
  }
109
172
  }
110
173
  }
111
- customElements.define("bl-select-list", SelectList);
174
+ if (!customElements.get("bl-select-list")) {
175
+ customElements.define("bl-select-list", SelectList);
176
+ }
177
+ export { SelectList, BlSelectEvent };
178
+ export default SelectList;
package/dist/merged.scss CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Blue Web v1.20.0 (https://bruegmann.github.io/blue-web)
2
+ * Blue Web v1.21.0 (https://bruegmann.github.io/blue-web)
3
3
  * Licensed under GNU General Public License v3.0 (https://github.com/bruegmann/blue-web/blob/master/LICENSE).
4
4
  */
5
5
 
@@ -48,6 +48,7 @@ $focus-ring-color: #{rgba(var(--bs-primary-rgb), 25%)} !default;
48
48
  $input-focus-border-color: #{rgba(var(--bs-primary-rgb), 50%)} !default;
49
49
 
50
50
  $enable-button-pointers: false !default;
51
+ $focus-ring-width: 0.125rem !default;
51
52
 
52
53
 
53
54
  // Bootstrap functions
@@ -10906,6 +10907,20 @@ body {
10906
10907
  margin: 0 !important;
10907
10908
  }
10908
10909
 
10910
+ // Shows empty message if the element has no children.
10911
+ // Can be used for lists and such.
10912
+ // For localization you should override CSS variable `--message` dynamically.
10913
+ .blue-empty-message {
10914
+ --message: "No items found.";
10915
+ &:empty::before {
10916
+ content: var(--message);
10917
+ color: var(--bs-secondary-color);
10918
+ display: flex;
10919
+ padding: 1rem;
10920
+ justify-content: center;
10921
+ }
10922
+ }
10923
+
10909
10924
  .blue-loading {
10910
10925
  background-color: $primary;
10911
10926
  }
@@ -12097,6 +12112,12 @@ dialog.blue-modal:has(.offcanvas-start) {
12097
12112
  grid-area: side;
12098
12113
  overflow: auto;
12099
12114
  background: inherit;
12115
+ scrollbar-color: transparent transparent;
12116
+
12117
+ &:hover,
12118
+ &:focus-within {
12119
+ scrollbar-color: color-mix(in srgb, currentColor 50%, transparent) transparent;
12120
+ }
12100
12121
  }
12101
12122
 
12102
12123
  @media (width < 64rem) {
@@ -12132,6 +12153,7 @@ dialog.blue-modal:has(.offcanvas-start) {
12132
12153
  margin-left: auto;
12133
12154
  margin-right: auto;
12134
12155
  overflow: auto;
12156
+ scrollbar-color: color-mix(in srgb, currentColor 50%, transparent) transparent;
12135
12157
  background-color: rgba(var(--bs-body-bg-rgb), var(--bs-bg-opacity, 1));
12136
12158
  color: rgba(var(--bs-body-color-rgb), var(--bs-text-opacity, 1));
12137
12159
  box-shadow: var(--bs-box-shadow-sm);
@@ -12307,6 +12329,12 @@ dialog.blue-modal:has(.offcanvas-start) {
12307
12329
  }
12308
12330
  }
12309
12331
 
12332
+ .btn:has(+ :popover-open):not(:focus-visible):not(.blue-menu-item) {
12333
+ --bs-focus-ring-color: rgba(var(--bs-secondary-rgb), 0.25);
12334
+ box-shadow: var(--bs-focus-ring-x, 0) var(--bs-focus-ring-y, 0) var(--bs-focus-ring-blur, 0)
12335
+ var(--bs-focus-ring-width) var(--bs-focus-ring-color);
12336
+ }
12337
+
12310
12338
  .blue-scrollspy {
12311
12339
  --#{$prefix}nav-link-padding-x: #{$nav-link-padding-x * 0.5};
12312
12340
  --#{$prefix}nav-link-padding-y: #{$nav-link-padding-y * 0.5};
@@ -12341,9 +12369,11 @@ dialog.blue-modal:has(.offcanvas-start) {
12341
12369
  (var(--#{$prefix}nav-link-font-size) * var(--#{$prefix}body-line-height))
12342
12370
  );
12343
12371
  margin-bottom: 0.25rem;
12372
+ padding-inline: var(--blue-scrollspy-marker-group-padding-inline);
12373
+ gap: var(--blue-scrollspy-marker-group-gap);
12344
12374
  }
12345
12375
 
12346
- & > section {
12376
+ & > :is(section, .blue-scrollspy-group) {
12347
12377
  &::scroll-marker {
12348
12378
  content: attr(aria-label);
12349
12379