@sbb-esta/lyne-elements 1.15.1 → 1.16.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/tabs/tab-group.js CHANGED
@@ -1,8 +1,8 @@
1
- var I = (n) => {
2
- throw TypeError(n);
1
+ var S = (a) => {
2
+ throw TypeError(a);
3
3
  };
4
- var S = (n, r, l) => r.has(n) || I("Cannot " + l);
5
- var y = (n, r, l) => (S(n, r, "read from private field"), l ? l.call(n) : r.get(n)), z = (n, r, l) => r.has(n) ? I("Cannot add the same private member more than once") : r instanceof WeakSet ? r.add(n) : r.set(n, l), _ = (n, r, l, c) => (S(n, r, "write to private field"), c ? c.call(n, l) : r.set(n, l), l);
4
+ var I = (a, r, l) => r.has(a) || S("Cannot " + l);
5
+ var y = (a, r, l) => (I(a, r, "read from private field"), l ? l.call(a) : r.get(a)), z = (a, r, l) => r.has(a) ? S("Cannot add the same private member more than once") : r instanceof WeakSet ? r.add(a) : r.set(a, l), _ = (a, r, l, c) => (I(a, r, "write to private field"), c ? c.call(a, l) : r.set(a, l), l);
6
6
  import { __runInitializers as h, __esDecorate as m } from "tslib";
7
7
  import { MutationController as w } from "@lit-labs/observers/mutation-controller.js";
8
8
  import { ResizeController as E } from "@lit-labs/observers/resize-controller.js";
@@ -20,7 +20,7 @@ const F = k`*,:before,:after{box-sizing:border-box}:host{--sbb-tab-group-animati
20
20
  };
21
21
  let B = 0, ot = (() => {
22
22
  var b, d;
23
- let n = [$("sbb-tab-group")], r, l = [], c, p = U(R), v = [], g, A, x = [], T = [];
23
+ let a = [$("sbb-tab-group")], r, l = [], c, p = U(R), v = [], g, A, x = [], T = [];
24
24
  var f = (d = class extends p {
25
25
  constructor() {
26
26
  super(...arguments);
@@ -38,15 +38,16 @@ let B = 0, ot = (() => {
38
38
  skipInitial: !0,
39
39
  callback: (t) => this._onTabContentElementResize(t)
40
40
  }), this._size = "l", _(this, b, h(this, x, 0)), this._selectedTabChanged = (h(this, T), new j(this, f.events.didChange)), this._onContentSlotChange = () => {
41
+ var i, e;
41
42
  this._tabContentElement = this.shadowRoot.querySelector("div.tab-content");
42
- const t = this._getTabs().filter((e) => !this._tabs.includes(e));
43
- t.length && (t.forEach((e) => this._configure(e)), this._tabs = this._tabs.concat(t));
43
+ const t = this._getTabs().filter((s) => !this._tabs.includes(s));
44
+ t.length && (t.forEach((s) => this._configure(s)), this._tabs = this._tabs.concat(t), (e = (i = t.find((s) => s.active)) == null ? void 0 : i.tabGroupActions) == null || e.select());
44
45
  }, this._onTabsSlotChange = () => {
45
46
  const t = this._getTabs();
46
- t.length < this._tabs.length && (this._tabs.filter((i) => !t.includes(i)).forEach((i) => {
47
- var a;
48
- (a = i.tab) == null || a.remove();
49
- }), this._tabs = t), this._tabs.forEach((e) => e.setAttribute("data-size", this.size));
47
+ t.length < this._tabs.length && (this._tabs.filter((e) => !t.includes(e)).forEach((e) => {
48
+ var s;
49
+ (s = e.tab) == null || s.remove();
50
+ }), this._tabs = t), this._tabs.forEach((i) => i.setAttribute("data-size", this.size));
50
51
  };
51
52
  }
52
53
  /** Size variant, either s, l or xl. */
@@ -69,34 +70,34 @@ let B = 0, ot = (() => {
69
70
  connectedCallback() {
70
71
  super.connectedCallback();
71
72
  const t = this._abort.signal;
72
- this.addEventListener("keydown", (e) => this._handleKeyDown(e), { signal: t });
73
+ this.addEventListener("keydown", (i) => this._handleKeyDown(i), { signal: t });
73
74
  }
74
75
  firstUpdated(t) {
75
- super.firstUpdated(t), this._tabs = this._getTabs(), this._tabs.forEach((e) => this._configure(e)), this._initSelection(), this._tabGroupResizeObserver.observe(this._tabGroupElement);
76
+ super.firstUpdated(t), this._tabs = this._getTabs(), this._tabs.forEach((i) => this._configure(i)), this._initSelection(), this._tabGroupResizeObserver.observe(this._tabGroupElement);
76
77
  }
77
78
  /**
78
79
  * Disables a tab by index.
79
80
  * @param tabIndex The index of the tab you want to disable.
80
81
  */
81
82
  disableTab(t) {
82
- var e, i;
83
- (i = (e = this._tabs[t]) == null ? void 0 : e.tabGroupActions) == null || i.disable();
83
+ var i, e;
84
+ (e = (i = this._tabs[t]) == null ? void 0 : i.tabGroupActions) == null || e.disable();
84
85
  }
85
86
  /**
86
87
  * Enables a tab by index.
87
88
  * @param tabIndex The index of the tab you want to enable.
88
89
  */
89
90
  enableTab(t) {
90
- var e, i;
91
- (i = (e = this._tabs[t]) == null ? void 0 : e.tabGroupActions) == null || i.enable();
91
+ var i, e;
92
+ (e = (i = this._tabs[t]) == null ? void 0 : i.tabGroupActions) == null || e.enable();
92
93
  }
93
94
  /**
94
95
  * Activates a tab by index.
95
96
  * @param tabIndex The index of the tab you want to activate.
96
97
  */
97
98
  activateTab(t) {
98
- var e, i;
99
- (i = (e = this._tabs[t]) == null ? void 0 : e.tabGroupActions) == null || i.select();
99
+ var i, e;
100
+ (e = (i = this._tabs[t]) == null ? void 0 : i.tabGroupActions) == null || e.select();
100
101
  }
101
102
  _getTabs() {
102
103
  return Array.from(this.children ?? []).filter((t) => /^sbb-tab-label$/u.test(t.localName));
@@ -112,77 +113,78 @@ let B = 0, ot = (() => {
112
113
  return `sbb-tab-panel-${++B}`;
113
114
  }
114
115
  _initSelection() {
115
- var t, e, i;
116
- this.initialSelectedIndex >= 0 && this.initialSelectedIndex < this._tabs.length && !this._tabs[this.initialSelectedIndex].disabled ? (t = this._tabs[this.initialSelectedIndex].tabGroupActions) == null || t.select() : (i = (e = this._enabledTabs()[0]) == null ? void 0 : e.tabGroupActions) == null || i.select();
116
+ var t, i, e;
117
+ this.initialSelectedIndex >= 0 && this.initialSelectedIndex < this._tabs.length && !this._tabs[this.initialSelectedIndex].disabled ? (t = this._tabs[this.initialSelectedIndex].tabGroupActions) == null || t.select() : (e = (i = this._enabledTabs()[0]) == null ? void 0 : i.tabGroupActions) == null || e.select();
117
118
  }
118
119
  _onTabAttributesChange(t) {
119
- var e, i, a;
120
- for (const s of t) {
121
- if (s.type !== "attributes")
120
+ var i, e, s;
121
+ for (const n of t) {
122
+ if (n.type !== "attributes")
122
123
  return;
123
- const o = s.target;
124
- s.attributeName === "disabled" && (o.hasAttribute("disabled") && o !== this._selectedTab ? (e = o.tabGroupActions) == null || e.disable() : o.disabled && ((i = o.tabGroupActions) == null || i.enable())), s.attributeName === "active" && (o.hasAttribute("active") && !o.disabled ? (a = o.tabGroupActions) == null || a.select() : o === this._selectedTab && o.toggleAttribute("active", !0));
124
+ const o = n.target;
125
+ n.attributeName === "disabled" && (o.hasAttribute("disabled") && o !== this._selectedTab ? (i = o.tabGroupActions) == null || i.disable() : o.disabled && ((e = o.tabGroupActions) == null || e.enable())), n.attributeName === "active" && (o.hasAttribute("active") && !o.disabled ? (s = o.tabGroupActions) == null || s.select() : o === this._selectedTab && o.toggleAttribute("active", !0));
125
126
  }
126
127
  }
127
128
  _onTabGroupElementResize(t) {
128
- for (const e of t) {
129
- const i = e.target.firstElementChild.assignedElements();
130
- for (const a of i)
131
- a.toggleAttribute("data-has-divider", a === i[0] || a.offsetLeft === i[0].offsetLeft), this.style.setProperty("--sbb-tab-group-width", `${this._tabGroupElement.clientWidth}px`);
129
+ for (const i of t) {
130
+ const e = i.target.firstElementChild.assignedElements();
131
+ for (const s of e)
132
+ s.toggleAttribute("data-has-divider", s === e[0] || s.offsetLeft === e[0].offsetLeft), this.style.setProperty("--sbb-tab-group-width", `${this._tabGroupElement.clientWidth}px`);
132
133
  }
133
134
  }
134
135
  _onTabContentElementResize(t) {
135
- for (const e of t) {
136
- const i = Math.floor(e.contentRect.height);
137
- this._tabContentElement.style.height = `${i}px`;
138
- }
136
+ if (this._tabContentElement)
137
+ for (const i of t) {
138
+ const e = Math.floor(i.contentRect.height);
139
+ this._tabContentElement.style.height = `${e}px`;
140
+ }
139
141
  }
140
142
  _configure(t) {
141
- var e;
143
+ var i;
142
144
  t.tabGroupActions = {
143
145
  activate: () => {
144
- var i;
145
- t.toggleAttribute("active", !0), t.active = !0, t.tabIndex = 0, t.setAttribute("aria-selected", "true"), (i = t.tab) == null || i.toggleAttribute("active", !0);
146
+ var e;
147
+ t.toggleAttribute("active", !0), t.active = !0, t.tabIndex = 0, t.setAttribute("aria-selected", "true"), (e = t.tab) == null || e.toggleAttribute("active", !0);
146
148
  },
147
149
  deactivate: () => {
148
- var i;
149
- t.removeAttribute("active"), t.active = !1, t.tabIndex = -1, t.setAttribute("aria-selected", "false"), (i = t.tab) == null || i.removeAttribute("active");
150
+ var e;
151
+ t.removeAttribute("active"), t.active = !1, t.tabIndex = -1, t.setAttribute("aria-selected", "false"), (e = t.tab) == null || e.removeAttribute("active");
150
152
  },
151
153
  disable: () => {
152
- var i, a, s;
153
- t.disabled || (t.hasAttribute("disabled") || t.toggleAttribute("disabled", !0), t.disabled = !0, t.tabIndex = -1, t.setAttribute("aria-selected", "false"), (i = t.tab) == null || i.removeAttribute("active"), t.active && (t.removeAttribute("active"), t.active = !1, (s = (a = this._enabledTabs()[0]) == null ? void 0 : a.tabGroupActions) == null || s.select()));
154
+ var e, s, n;
155
+ t.disabled || (t.hasAttribute("disabled") || t.toggleAttribute("disabled", !0), t.disabled = !0, t.tabIndex = -1, t.setAttribute("aria-selected", "false"), (e = t.tab) == null || e.removeAttribute("active"), t.active && (t.removeAttribute("active"), t.active = !1, (n = (s = this._enabledTabs()[0]) == null ? void 0 : s.tabGroupActions) == null || n.select()));
154
156
  },
155
157
  enable: () => {
156
158
  t.disabled && (t.removeAttribute("disabled"), t.disabled = !1);
157
159
  },
158
160
  select: () => {
159
- var i, a;
161
+ var e, s;
160
162
  if (t !== this._selectedTab && !t.disabled) {
161
- const s = this._selectedTab;
162
- s && ((i = s.tabGroupActions) == null || i.deactivate(), this._tabContentResizeObserver.unobserve(s.tab)), (a = t.tabGroupActions) == null || a.activate(), this._selectedTab = t, this._tabContentResizeObserver.observe(t.tab);
163
+ const n = this._selectedTab;
164
+ n && ((e = n.tabGroupActions) == null || e.deactivate(), this._tabContentResizeObserver.unobserve(n.tab)), (s = t.tabGroupActions) == null || s.activate(), this._selectedTab = t, this._tabContentResizeObserver.observe(t.tab);
163
165
  const o = this._tabs;
164
166
  this._selectedTabChanged.emit({
165
167
  activeIndex: o.findIndex((u) => u === t),
166
168
  activeTabLabel: t,
167
169
  activeTab: t.tab,
168
- previousIndex: o.findIndex((u) => u === s),
169
- previousTabLabel: s,
170
- previousTab: s == null ? void 0 : s.tab
170
+ previousIndex: o.findIndex((u) => u === n),
171
+ previousTabLabel: n,
172
+ previousTab: n == null ? void 0 : n.tab
171
173
  });
172
174
  }
173
175
  }
174
- }, ((e = t.nextElementSibling) == null ? void 0 : e.localName) === "sbb-tab" && (t.tab = t.nextElementSibling, t.tab.id = this._assignId(), t.tab instanceof q && (t.tab.tabIndex = 0, t.tab.configure())), t.tabIndex = -1, t.disabled = t.hasAttribute("disabled"), t.active = t.hasAttribute("active") && !t.disabled, t.setAttribute("role", "tab"), t.setAttribute("aria-selected", "false"), t.addEventListener("click", () => {
175
- var i;
176
- (i = t.tabGroupActions) == null || i.select();
176
+ }, ((i = t.nextElementSibling) == null ? void 0 : i.localName) === "sbb-tab" && (t.tab = t.nextElementSibling, t.tab.id = this._assignId(), t.tab instanceof q && (t.tab.tabIndex = 0, t.tab.configure())), t.tabIndex = -1, t.disabled = t.hasAttribute("disabled"), t.active = t.hasAttribute("active") && !t.disabled, t.setAttribute("role", "tab"), t.setAttribute("aria-selected", String(t.active)), t.addEventListener("click", () => {
177
+ var e;
178
+ (e = t.tabGroupActions) == null || e.select();
177
179
  }), t.tab && (t.setAttribute("aria-controls", t.tab.id), t.tab.setAttribute("role", "tabpanel"), t.tab.toggleAttribute("active", t.active)), this._tabAttributeObserver.observe(t), t.slot = "tab-bar";
178
180
  }
179
181
  _handleKeyDown(t) {
180
- var i, a, s;
181
- const e = this._enabledTabs();
182
- if (!(!e || // don't trap nested handling
182
+ var e, s, n;
183
+ const i = this._enabledTabs();
184
+ if (!(!i || // don't trap nested handling
183
185
  t.target !== this && t.target.parentElement !== this) && N(t)) {
184
- const o = e.findIndex((G) => G.active), u = K(t, o, e.length);
185
- (a = (i = e[u]) == null ? void 0 : i.tabGroupActions) == null || a.select(), (s = e[u]) == null || s.focus(), t.preventDefault();
186
+ const o = i.findIndex((G) => G.active), u = K(t, o, i.length);
187
+ (s = (e = i[u]) == null ? void 0 : e.tabGroupActions) == null || s.select(), (n = i[u]) == null || n.focus(), t.preventDefault();
186
188
  }
187
189
  }
188
190
  render() {
@@ -202,11 +204,11 @@ let B = 0, ot = (() => {
202
204
  }
203
205
  }, b = new WeakMap(), c = d, (() => {
204
206
  const t = typeof Symbol == "function" && Symbol.metadata ? Object.create(p[Symbol.metadata] ?? null) : void 0;
205
- g = [C()], A = [P(), C({ attribute: "initial-selected-index", type: Number })], m(d, null, g, { kind: "setter", name: "size", static: !1, private: !1, access: { has: (e) => "size" in e, set: (e, i) => {
206
- e.size = i;
207
- } }, metadata: t }, null, v), m(d, null, A, { kind: "accessor", name: "initialSelectedIndex", static: !1, private: !1, access: { has: (e) => "initialSelectedIndex" in e, get: (e) => e.initialSelectedIndex, set: (e, i) => {
208
- e.initialSelectedIndex = i;
209
- } }, metadata: t }, x, T), m(null, r = { value: c }, n, { kind: "class", name: c.name, metadata: t }, null, l), f = c = r.value, t && Object.defineProperty(c, Symbol.metadata, { enumerable: !0, configurable: !0, writable: !0, value: t });
207
+ g = [C()], A = [P(), C({ attribute: "initial-selected-index", type: Number })], m(d, null, g, { kind: "setter", name: "size", static: !1, private: !1, access: { has: (i) => "size" in i, set: (i, e) => {
208
+ i.size = e;
209
+ } }, metadata: t }, null, v), m(d, null, A, { kind: "accessor", name: "initialSelectedIndex", static: !1, private: !1, access: { has: (i) => "initialSelectedIndex" in i, get: (i) => i.initialSelectedIndex, set: (i, e) => {
210
+ i.initialSelectedIndex = e;
211
+ } }, metadata: t }, x, T), m(null, r = { value: c }, a, { kind: "class", name: c.name, metadata: t }, null, l), f = c = r.value, t && Object.defineProperty(c, Symbol.metadata, { enumerable: !0, configurable: !0, writable: !0, value: t });
210
212
  })(), d.styles = F, d.events = {
211
213
  didChange: "didChange"
212
214
  }, h(c, l), d);