blue-web 1.36.2 → 1.37.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,92 +1,126 @@
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
- const DRAG_THRESHOLD = 5;
5
-
1
+ // src/js/read-view.ts
2
+ var DRAG_THRESHOLD = 5;
6
3
  /**
7
- * A Web Component that displays a read view of its content and allows the user to switch to an edit view.
8
- * Fires event "EditRequested" when the user clicks the read view.
9
- * @element read-view
10
- * @fires EditRequested
11
- * @attr {boolean} disabled - Disables the component, preventing interactions and removing hover effects.
12
- * @cssprop --bs-primary-rgb - The primary color as an RGB value.
13
- * @cssprop --bs-secondary-bg-subtle - The subtle background color for the read view.
14
- * @cssprop --bs-border-radius-sm - The border radius for the read view.
15
- * @slot - The content to display in the read view.
16
- * @example
17
- * <bl-read-view id="my-read-view" onEditRequested="setEditing(true)">
18
- * <a href="#">bla</a> {value}
19
- * </bl-read-view>
20
- * @example
21
- * document.getElementById("my-read-view").addEventListener("EditRequested", () => {
22
- * setEditing(true)
23
- * })
24
- */
25
- export class ReadView extends HTMLElement {
26
- constructor() {
27
- super();
28
- _defineProperty(this, "startX", 0);
29
- _defineProperty(this, "startY", 0);
30
- this.attachShadow({
31
- mode: "open"
32
- });
33
- }
34
- static get observedAttributes() {
35
- return ["disabled"];
36
- }
37
- connectedCallback() {
38
- this.render();
39
- }
40
- attributeChangedCallback(name, oldValue, newValue) {
41
- if (name === "disabled") {
42
- this.updateDisabledState();
43
- }
44
- }
45
- render() {
46
- if (!this.shadowRoot) return;
47
- this.shadowRoot.innerHTML = /* HTML */"\n <style>\n button {\n display: block;\n margin: 0;\n padding: 0;\n appearance: none;\n background-color: transparent;\n border: none;\n line-height: 1;\n outline: 0;\n }\n\n button:focus-visible + div {\n outline: 0;\n box-shadow:\n 0 0 0 0.25rem rgba(var(--bs-primary-rgb), 25%),\n inset 0 0 0 1px rgba(var(--bs-primary-rgb), 50%);\n }\n\n div {\n display: var(--display, flex);\n box-sizing: border-box;\n width: auto;\n max-width: 100%;\n border-color: transparent;\n border-radius: calc(var(--bs-border-radius-sm, 3px) + var(--blue-read-view-padding-y));\n background: var(--bg, transparent);\n transition: var(--transition, background 0.2s);\n\n padding: var(--blue-read-view-padding-y) var(--blue-read-view-padding-x);\n }\n\n div:hover {\n background: var(--hover-bg, var(--bs-secondary-bg));\n }\n\n :host([disabled]) div {\n background-color: transparent;\n }\n </style>\n <button aria-label=\"Edit\"></button>\n <div role=\"presentation\" part=\"presentation\">\n <slot></slot>\n </div>\n ";
48
- this.button = this.shadowRoot.querySelector("button");
49
- this.container = this.shadowRoot.querySelector("div");
50
- this.button.addEventListener("click", this.onEditRequested.bind(this));
51
- this.container.addEventListener("click", this.onReadViewClick.bind(this));
52
- this.container.addEventListener("mousedown", this.onMouseDown.bind(this));
53
- this.updateDisabledState();
54
- }
55
- updateDisabledState() {
56
- var _this$button, _this$container;
57
- const isDisabled = this.hasAttribute("disabled");
58
- (_this$button = this.button) === null || _this$button === void 0 || _this$button.setAttribute("aria-disabled", String(isDisabled));
59
- if (isDisabled) {
60
- var _this$button2;
61
- (_this$button2 = this.button) === null || _this$button2 === void 0 || _this$button2.setAttribute("tabindex", "-1");
62
- } else {
63
- var _this$button3;
64
- (_this$button3 = this.button) === null || _this$button3 === void 0 || _this$button3.removeAttribute("tabindex");
65
- }
66
- (_this$container = this.container) === null || _this$container === void 0 || _this$container.setAttribute("aria-disabled", String(isDisabled));
67
- }
68
- onEditRequested() {
69
- if (this.hasAttribute("disabled")) return;
70
- this.dispatchEvent(new CustomEvent("EditRequested", {
71
- bubbles: true,
72
- composed: true
73
- }));
74
- }
75
- onMouseDown(event) {
76
- if (this.hasAttribute("disabled")) return;
77
- this.startX = event.clientX;
78
- this.startY = event.clientY;
79
- }
80
- mouseHasMovedAfterMouseDown(event) {
81
- return Math.abs(this.startX - event.clientX) >= DRAG_THRESHOLD || Math.abs(this.startY - event.clientY) >= DRAG_THRESHOLD;
82
- }
83
- onReadViewClick(event) {
84
- if (this.hasAttribute("disabled")) return;
85
- const target = event.target;
86
- if (target.tagName.toLowerCase() !== "a" && !this.mouseHasMovedAfterMouseDown(event)) {
87
- event.preventDefault();
88
- this.onEditRequested();
89
- }
90
- }
91
- }
92
- customElements.define("bl-read-view", ReadView);
4
+ * A Web Component that displays a read view of its content and allows the user to switch to an edit view.
5
+ * Fires event "EditRequested" when the user clicks the read view.
6
+ * @element read-view
7
+ * @fires EditRequested
8
+ * @attr {boolean} disabled - Disables the component, preventing interactions and removing hover effects.
9
+ * @cssprop --bs-primary-rgb - The primary color as an RGB value.
10
+ * @cssprop --bs-secondary-bg-subtle - The subtle background color for the read view.
11
+ * @cssprop --bs-border-radius-sm - The border radius for the read view.
12
+ * @slot - The content to display in the read view.
13
+ * @example
14
+ * <bl-read-view id="my-read-view" onEditRequested="setEditing(true)">
15
+ * <a href="#">bla</a> {value}
16
+ * </bl-read-view>
17
+ * @example
18
+ * document.getElementById("my-read-view").addEventListener("EditRequested", () => {
19
+ * setEditing(true)
20
+ * })
21
+ */
22
+ var ReadView = class extends HTMLElement {
23
+ button;
24
+ container;
25
+ startX = 0;
26
+ startY = 0;
27
+ constructor() {
28
+ super();
29
+ this.attachShadow({ mode: "open" });
30
+ }
31
+ static get observedAttributes() {
32
+ return ["disabled"];
33
+ }
34
+ connectedCallback() {
35
+ this.render();
36
+ }
37
+ attributeChangedCallback(name, oldValue, newValue) {
38
+ if (name === "disabled") this.updateDisabledState();
39
+ }
40
+ render() {
41
+ if (!this.shadowRoot) return;
42
+ this.shadowRoot.innerHTML = `
43
+ <style>
44
+ button {
45
+ display: block;
46
+ margin: 0;
47
+ padding: 0;
48
+ appearance: none;
49
+ background-color: transparent;
50
+ border: none;
51
+ line-height: 1;
52
+ outline: 0;
53
+ }
54
+
55
+ button:focus-visible + div {
56
+ outline: 0;
57
+ box-shadow:
58
+ 0 0 0 0.25rem rgba(var(--bs-primary-rgb), 25%),
59
+ inset 0 0 0 1px rgba(var(--bs-primary-rgb), 50%);
60
+ }
61
+
62
+ div {
63
+ display: var(--display, flex);
64
+ box-sizing: border-box;
65
+ width: auto;
66
+ max-width: 100%;
67
+ border-color: transparent;
68
+ border-radius: calc(var(--bs-border-radius-sm, 3px) + var(--blue-read-view-padding-y));
69
+ background: var(--bg, transparent);
70
+ transition: var(--transition, background 0.2s);
71
+
72
+ padding: var(--blue-read-view-padding-y) var(--blue-read-view-padding-x);
73
+ }
74
+
75
+ div:hover {
76
+ background: var(--hover-bg, var(--bs-secondary-bg));
77
+ }
78
+
79
+ :host([disabled]) div {
80
+ background-color: transparent;
81
+ }
82
+ </style>
83
+ <button aria-label="Edit"></button>
84
+ <div role="presentation" part="presentation">
85
+ <slot></slot>
86
+ </div>
87
+ `;
88
+ this.button = this.shadowRoot.querySelector("button");
89
+ this.container = this.shadowRoot.querySelector("div");
90
+ this.button.addEventListener("click", this.onEditRequested.bind(this));
91
+ this.container.addEventListener("click", this.onReadViewClick.bind(this));
92
+ this.container.addEventListener("mousedown", this.onMouseDown.bind(this));
93
+ this.updateDisabledState();
94
+ }
95
+ updateDisabledState() {
96
+ const isDisabled = this.hasAttribute("disabled");
97
+ this.button?.setAttribute("aria-disabled", String(isDisabled));
98
+ if (isDisabled) this.button?.setAttribute("tabindex", "-1");
99
+ else this.button?.removeAttribute("tabindex");
100
+ this.container?.setAttribute("aria-disabled", String(isDisabled));
101
+ }
102
+ onEditRequested() {
103
+ if (this.hasAttribute("disabled")) return;
104
+ this.dispatchEvent(new CustomEvent("EditRequested", {
105
+ bubbles: true,
106
+ composed: true
107
+ }));
108
+ }
109
+ onMouseDown(event) {
110
+ if (this.hasAttribute("disabled")) return;
111
+ this.startX = event.clientX;
112
+ this.startY = event.clientY;
113
+ }
114
+ mouseHasMovedAfterMouseDown(event) {
115
+ return Math.abs(this.startX - event.clientX) >= DRAG_THRESHOLD || Math.abs(this.startY - event.clientY) >= DRAG_THRESHOLD;
116
+ }
117
+ onReadViewClick(event) {
118
+ if (this.hasAttribute("disabled")) return;
119
+ if (event.target.tagName.toLowerCase() !== "a" && !this.mouseHasMovedAfterMouseDown(event)) {
120
+ event.preventDefault();
121
+ this.onEditRequested();
122
+ }
123
+ }
124
+ };
125
+ customElements.define("bl-read-view", ReadView);
126
+ export { ReadView };
@@ -1,178 +1,169 @@
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
+ // src/js/select-list.ts
2
+ var BlSelectEvent = class BlSelectEvent extends Event {
3
+ static eventName = "bl-select";
4
+ index;
5
+ item;
6
+ constructor(index, item) {
7
+ super(BlSelectEvent.eventName, {
8
+ bubbles: true,
9
+ composed: true
10
+ });
11
+ this.index = index;
12
+ this.item = item;
13
+ }
14
+ };
15
15
  /**
16
- * A Web Component that provides a keyboard-accessible selectable list, typically used for dropdowns or autocomplete lists.
17
- * Together with `popover` and CSS Anchoring, it's also useful to create a dropdown list.
18
- * Supports keyboard navigation and selection, and integrates with an input element for combobox behavior.
19
- *
20
- * The Web Component will automatically set attributes for accessibility.
21
- *
22
- * @element bl-select-list
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").
25
- * @slot - The list options.
26
- * @example
27
- * <input id="my-input" />
28
- * <bl-select-list for="my-input">
29
- * <div>Option 1</div>
30
- * <div>Option 2</div>
31
- * </bl-select-list>
32
- */
33
- _defineProperty(BlSelectEvent, "eventName", "bl-select");
34
- class SelectList extends HTMLElement {
35
- constructor() {
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
- });
49
- this.attachShadow({
50
- mode: "open"
51
- });
52
- this.shadowRoot.innerHTML = "<slot style=\"border-radius: inherit\"></slot>";
53
- this.activeIndex = -1;
54
- this.items = [];
55
- this.inputElement = null;
56
- this.slotElement = null;
57
- this.observer = null;
58
- }
59
- get activeClass() {
60
- return this.getAttribute("active-class") || "active";
61
- }
62
- connectedCallback() {
63
- var _this$shadowRoot, _this$slotElement;
64
- this.setAttribute("role", "listbox");
65
- this.tabIndex = -1;
66
- this.updateItems();
67
- this.syncActiveIndexFromDataSelected();
68
- this.updateActiveItem();
69
- const inputId = this.getAttribute("for");
70
- this.inputElement = inputId ? document.getElementById(inputId) : null;
71
- if (this.inputElement) {
72
- this.inputElement.setAttribute("role", "combobox");
73
- this.inputElement.setAttribute("aria-controls", this.id);
74
- this.inputElement.setAttribute("aria-expanded", "true");
75
- this.inputElement.addEventListener("keydown", this.onKeyDown.bind(this));
76
- }
77
- this.addEventListener("keydown", this.onKeyDown.bind(this));
78
- this.addEventListener("click", e => {
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"));
82
- this.select(index);
83
- }
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
- }
114
- }
115
- updateItems() {
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));
118
- this.items.forEach((el, i) => {
119
- if (!el.hasAttribute("id")) {
120
- el.setAttribute("id", "".concat(this.id, "-option-").concat(i));
121
- }
122
- el.setAttribute("data-select-list-index", i.toString());
123
- el.setAttribute("aria-selected", "false");
124
- el.setAttribute("role", "option");
125
- el.tabIndex = -1;
126
- });
127
- }
128
- onKeyDown(e) {
129
- if (!this.items.length) return;
130
- if (e.key === "ArrowDown") {
131
- e.preventDefault();
132
- this.activeIndex = (this.activeIndex + 1) % this.items.length;
133
- this.updateActiveItem();
134
- } else if (e.key === "ArrowUp") {
135
- e.preventDefault();
136
- this.activeIndex = (this.activeIndex - 1 + this.items.length) % this.items.length;
137
- this.updateActiveItem();
138
- } else if (e.key === "Enter" && this.activeIndex >= 0) {
139
- e.preventDefault();
140
- const item = this.items[this.activeIndex];
141
- item === null || item === void 0 || item.click();
142
- }
143
- }
144
- updateActiveItem() {
145
- const activeClassNames = this.activeClass.split(" ");
146
- this.items.forEach((el, i) => {
147
- const active = i === this.activeIndex;
148
- activeClassNames.forEach(activeClassName => {
149
- el.classList.toggle(activeClassName, active);
150
- });
151
- el.setAttribute("aria-selected", active.toString());
152
- });
153
- const activeItem = this.items[this.activeIndex];
154
- if (activeItem && this.inputElement) {
155
- this.inputElement.setAttribute("aria-activedescendant", activeItem.id);
156
- activeItem.scrollIntoView({
157
- block: "nearest"
158
- });
159
- } else if (this.inputElement) {
160
- this.inputElement.removeAttribute("aria-activedescendant");
161
- }
162
- }
163
- select(index) {
164
- this.activeIndex = index;
165
- this.items.forEach(el => el.removeAttribute("data-selected"));
166
- const selectedItem = this.items[index];
167
- if (selectedItem) {
168
- selectedItem.setAttribute("data-selected", "");
169
- this.dispatchEvent(new BlSelectEvent(index, selectedItem));
170
- this.updateActiveItem();
171
- }
172
- }
173
- }
174
- if (!customElements.get("bl-select-list")) {
175
- customElements.define("bl-select-list", SelectList);
176
- }
177
- export { SelectList, BlSelectEvent };
178
- export default SelectList;
16
+ * A Web Component that provides a keyboard-accessible selectable list, typically used for dropdowns or autocomplete lists.
17
+ * Together with `popover` and CSS Anchoring, it's also useful to create a dropdown list.
18
+ * Supports keyboard navigation and selection, and integrates with an input element for combobox behavior.
19
+ *
20
+ * The Web Component will automatically set attributes for accessibility.
21
+ *
22
+ * @element bl-select-list
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").
25
+ * @slot - The list options.
26
+ * @example
27
+ * <input id="my-input" />
28
+ * <bl-select-list for="my-input">
29
+ * <div>Option 1</div>
30
+ * <div>Option 2</div>
31
+ * </bl-select-list>
32
+ */
33
+ var SelectList = class extends HTMLElement {
34
+ activeIndex;
35
+ items;
36
+ inputElement;
37
+ slotElement;
38
+ observer;
39
+ constructor() {
40
+ super();
41
+ this.attachShadow({ mode: "open" });
42
+ this.shadowRoot.innerHTML = `<slot style="border-radius: inherit"></slot>`;
43
+ this.activeIndex = -1;
44
+ this.items = [];
45
+ this.inputElement = null;
46
+ this.slotElement = null;
47
+ this.observer = null;
48
+ }
49
+ get activeClass() {
50
+ return this.getAttribute("active-class") || "active";
51
+ }
52
+ connectedCallback() {
53
+ this.setAttribute("role", "listbox");
54
+ this.tabIndex = -1;
55
+ this.updateItems();
56
+ this.syncActiveIndexFromDataSelected();
57
+ this.updateActiveItem();
58
+ const inputId = this.getAttribute("for");
59
+ this.inputElement = inputId ? document.getElementById(inputId) : null;
60
+ if (this.inputElement) {
61
+ this.inputElement.setAttribute("role", "combobox");
62
+ this.inputElement.setAttribute("aria-controls", this.id);
63
+ this.inputElement.setAttribute("aria-expanded", "true");
64
+ this.inputElement.addEventListener("keydown", this.onKeyDown.bind(this));
65
+ }
66
+ this.addEventListener("keydown", this.onKeyDown.bind(this));
67
+ this.addEventListener("click", (e) => {
68
+ const target = e.target instanceof Element ? e.target.closest("[data-select-list-index]") : null;
69
+ if (target && target.hasAttribute("data-select-list-index")) {
70
+ const index = Number(target.getAttribute("data-select-list-index"));
71
+ this.select(index);
72
+ }
73
+ });
74
+ this.observer = new MutationObserver((mutations) => {
75
+ if (mutations.some((m) => m.type === "childList")) this.handleChildrenChanged();
76
+ if (mutations.some((m) => m.type === "attributes" && m.attributeName === "data-selected")) {
77
+ this.syncActiveIndexFromDataSelected();
78
+ this.updateActiveItem();
79
+ }
80
+ });
81
+ this.observer.observe(this, {
82
+ childList: true,
83
+ subtree: true,
84
+ attributes: true,
85
+ attributeFilter: ["data-selected"]
86
+ });
87
+ this.slotElement = this.shadowRoot?.querySelector("slot");
88
+ this.slotElement?.addEventListener("slotchange", this.handleChildrenChanged);
89
+ }
90
+ disconnectedCallback() {
91
+ this.observer?.disconnect();
92
+ this.observer = null;
93
+ this.slotElement?.removeEventListener("slotchange", this.handleChildrenChanged);
94
+ }
95
+ handleChildrenChanged = () => {
96
+ const previousActiveId = this.items[this.activeIndex]?.id;
97
+ this.updateItems();
98
+ if (previousActiveId) {
99
+ const newIndex = this.items.findIndex((el) => el.id === previousActiveId);
100
+ this.activeIndex = newIndex >= 0 ? newIndex : -1;
101
+ } else this.activeIndex = -1;
102
+ this.updateActiveItem();
103
+ };
104
+ syncActiveIndexFromDataSelected() {
105
+ const selectedIndex = this.items.findIndex((el) => el.hasAttribute("data-selected"));
106
+ if (selectedIndex >= 0) this.activeIndex = selectedIndex;
107
+ }
108
+ updateItems() {
109
+ const selectableSelectors = [
110
+ "button:not([disabled])",
111
+ "a[href]",
112
+ "input:not([disabled])",
113
+ "select:not([disabled])",
114
+ "textarea:not([disabled])",
115
+ "[tabindex]:not([tabindex=\"-1\"])",
116
+ "[role=\"option\"]"
117
+ ].join(", ");
118
+ this.items = Array.from(this.querySelectorAll(selectableSelectors));
119
+ this.items.forEach((el, i) => {
120
+ if (!el.hasAttribute("id")) el.setAttribute("id", `${this.id}-option-${i}`);
121
+ el.setAttribute("data-select-list-index", i.toString());
122
+ el.setAttribute("aria-selected", "false");
123
+ el.setAttribute("role", "option");
124
+ el.tabIndex = -1;
125
+ });
126
+ }
127
+ onKeyDown(e) {
128
+ if (!this.items.length) return;
129
+ if (e.key === "ArrowDown") {
130
+ e.preventDefault();
131
+ this.activeIndex = (this.activeIndex + 1) % this.items.length;
132
+ this.updateActiveItem();
133
+ } else if (e.key === "ArrowUp") {
134
+ e.preventDefault();
135
+ this.activeIndex = (this.activeIndex - 1 + this.items.length) % this.items.length;
136
+ this.updateActiveItem();
137
+ } else if (e.key === "Enter" && this.activeIndex >= 0) {
138
+ e.preventDefault();
139
+ this.items[this.activeIndex]?.click();
140
+ }
141
+ }
142
+ updateActiveItem() {
143
+ const activeClassNames = this.activeClass.split(" ");
144
+ this.items.forEach((el, i) => {
145
+ const active = i === this.activeIndex;
146
+ activeClassNames.forEach((activeClassName) => {
147
+ el.classList.toggle(activeClassName, active);
148
+ });
149
+ el.setAttribute("aria-selected", active.toString());
150
+ });
151
+ const activeItem = this.items[this.activeIndex];
152
+ if (activeItem && this.inputElement) {
153
+ this.inputElement.setAttribute("aria-activedescendant", activeItem.id);
154
+ activeItem.scrollIntoView({ block: "nearest" });
155
+ } else if (this.inputElement) this.inputElement.removeAttribute("aria-activedescendant");
156
+ }
157
+ select(index) {
158
+ this.activeIndex = index;
159
+ this.items.forEach((el) => el.removeAttribute("data-selected"));
160
+ const selectedItem = this.items[index];
161
+ if (selectedItem) {
162
+ selectedItem.setAttribute("data-selected", "");
163
+ this.dispatchEvent(new BlSelectEvent(index, selectedItem));
164
+ this.updateActiveItem();
165
+ }
166
+ }
167
+ };
168
+ if (!customElements.get("bl-select-list")) customElements.define("bl-select-list", SelectList);
169
+ export { BlSelectEvent, SelectList, SelectList as default };
package/dist/js/shared.js CHANGED
@@ -1,27 +1,22 @@
1
- const phrases = {
2
- Cancel: ["Cancel", "Abbrechen"],
3
- Message: ["Message", "Nachricht"],
4
- Question: ["Question", "Frage"],
5
- Confirm: ["Confirm", "Bestätigen"],
6
- "Toggle menu": ["Toggle menu", "Menü umschalten"],
7
- "Close all": ["Close all", "Alle schließen"],
8
- Error: ["Error", "Fehler"],
9
- Information: ["Information", "Information"],
10
- Loading: ["Loading", "Laden"],
11
- Successful: ["Successful", "Erfolgreich"]
1
+ // src/js/shared.ts
2
+ var phrases = {
3
+ Cancel: ["Cancel", "Abbrechen"],
4
+ Message: ["Message", "Nachricht"],
5
+ Question: ["Question", "Frage"],
6
+ Confirm: ["Confirm", "Bestätigen"],
7
+ "Toggle menu": ["Toggle menu", "Menü umschalten"],
8
+ "Close all": ["Close all", "Alle schließen"],
9
+ Error: ["Error", "Fehler"],
10
+ Information: ["Information", "Information"],
11
+ Loading: ["Loading", "Laden"],
12
+ Successful: ["Successful", "Erfolgreich"]
12
13
  };
13
- export function getPhrase(keyword) {
14
- let countryCode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
15
- let _phrases = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
16
- countryCode = countryCode || navigator.language.toLowerCase().indexOf("de") > -1 ? "de-DE" : "en-US";
17
- _phrases = _phrases || phrases;
18
- if (_phrases[keyword]) {
19
- if (countryCode.indexOf("de-") > -1) {
20
- return _phrases[keyword][1];
21
- } else {
22
- return _phrases[keyword][0];
23
- }
24
- } else {
25
- return keyword;
26
- }
27
- }
14
+ function getPhrase(keyword, countryCode = void 0, _phrases = void 0) {
15
+ countryCode = countryCode || navigator.language.toLowerCase().indexOf("de") > -1 ? "de-DE" : "en-US";
16
+ _phrases = _phrases || phrases;
17
+ if (_phrases[keyword]) {
18
+ if (countryCode.indexOf("de-") > -1) return _phrases[keyword][1];
19
+ else return _phrases[keyword][0];
20
+ } else return keyword;
21
+ }
22
+ export { getPhrase };
@@ -1,4 +1,4 @@
1
- import { StatusType } from "./shared.js";
1
+ import type { StatusType } from "./shared.js";
2
2
  export declare function startLoading(): void;
3
3
  export declare function finishLoading(): void;
4
4
  export declare function showSuccess(): void;