@rhavenside/baseline 2.1.1 → 2.1.3

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.
@@ -111,6 +111,13 @@ class Carousel extends BaseComponent {
111
111
  }
112
112
 
113
113
  nextWhenVisible() {
114
+ // For auto-play carousels (with data-c-ride), always proceed if document is visible
115
+ // The visibility check can prevent auto-play when element is scrolled out of viewport
116
+ if (this._config.ride && !document.hidden) {
117
+ this.next()
118
+ return
119
+ }
120
+ // For manual carousels, check both document visibility and element visibility
114
121
  if (!document.hidden && isVisible(this._element)) {
115
122
  this.next()
116
123
  }
@@ -219,9 +219,29 @@ class Collapse extends BaseComponent {
219
219
  on(document, 'click', SELECTOR_DATA_TOGGLE, function (event) {
220
220
  event.preventDefault()
221
221
  const selector = this.getAttribute('data-c-target') || this.getAttribute('href')
222
- const target = getElement(selector)
222
+
223
+ // Try to get single element first (for ID selectors)
224
+ let target = getElement(selector)
225
+
226
+ // If no single element found or selector is a class selector, try multiple
227
+ if (!target || selector.startsWith('.')) {
228
+ const targets = getElements(selector)
229
+ if (targets.length > 0) {
230
+ // Get parent from trigger button if available
231
+ const parentSelector = this.getAttribute('data-c-parent')
232
+ const config = parentSelector ? { parent: parentSelector } : {}
233
+
234
+ // Toggle all found elements
235
+ targets.forEach(element => {
236
+ const collapse = Collapse.getOrCreateInstance(element, config)
237
+ collapse.toggle()
238
+ })
239
+ return
240
+ }
241
+ }
242
+
243
+ // Single element handling (existing logic)
223
244
  if (target) {
224
- // Get parent from trigger button if available
225
245
  const parentSelector = this.getAttribute('data-c-parent')
226
246
  const config = parentSelector ? { parent: parentSelector } : {}
227
247
  const collapse = Collapse.getOrCreateInstance(target, config)
@@ -0,0 +1,80 @@
1
+ // src/js/util/state-handler.js
2
+ import { on, off, executeAfterTransition, reflow } from './util.js';
3
+
4
+ const EVENT_SHOW = 'show';
5
+ const EVENT_SHOWN = 'shown';
6
+ const EVENT_HIDE = 'hide';
7
+ const EVENT_HIDDEN = 'hidden';
8
+
9
+ export class StateHandler {
10
+ constructor(element, config = {}) {
11
+ this._element = element;
12
+ this._isShown = false;
13
+ this._transitioning = false;
14
+ this._config = {
15
+ backdrop: config.backdrop ?? false,
16
+ keyboard: config.keyboard ?? true,
17
+ focus: config.focus ?? true,
18
+ ...config
19
+ };
20
+ }
21
+
22
+ toggle() {
23
+ return this._isShown ? this.hide() : this.show();
24
+ }
25
+
26
+ show() {
27
+ if (this._isShown || this._transitioning) return;
28
+
29
+ const showEvent = this._triggerEvent(EVENT_SHOW);
30
+ if (showEvent.defaultPrevented) return;
31
+
32
+ this._transitioning = true;
33
+ this._showElement();
34
+
35
+ if (this._config.backdrop) {
36
+ // Backdrop-Logik hier oder via separaten Backdrop-Instanz
37
+ }
38
+
39
+ executeAfterTransition(() => {
40
+ this._isShown = true;
41
+ this._transitioning = false;
42
+ this._triggerEvent(EVENT_SHOWN);
43
+ if (this._config.focus) this._element.focus();
44
+ }, this._element);
45
+ }
46
+
47
+ hide() {
48
+ if (!this._isShown || this._transitioning) return;
49
+
50
+ const hideEvent = this._triggerEvent(EVENT_HIDE);
51
+ if (hideEvent.defaultPrevented) return;
52
+
53
+ this._transitioning = true;
54
+ this._hideElement();
55
+
56
+ executeAfterTransition(() => {
57
+ this._isShown = false;
58
+ this._transitioning = false;
59
+ this._triggerEvent(EVENT_HIDDEN);
60
+ }, this._element);
61
+ }
62
+
63
+ // Interne Helfer
64
+ _triggerEvent(eventName) {
65
+ const event = new CustomEvent(eventName + this.constructor.EVENT_KEY, {
66
+ bubbles: true,
67
+ cancelable: true
68
+ });
69
+ this._element.dispatchEvent(event);
70
+ return event;
71
+ }
72
+
73
+ _showElement() { throw new Error('_showElement muss implementiert werden'); }
74
+ _hideElement() { throw new Error('_hideElement muss implementiert werden'); }
75
+ }
76
+
77
+ StateHandler.EVENT_KEY = '.c.state';
78
+ StateHandler.VERSION = '2.0.0-base-line';
79
+
80
+ export default StateHandler;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhavenside/baseline",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "description": "A strict, layer-based design system with semantic tokens",
5
5
  "main": "dist/base-line.css",
6
6
  "module": "dist/js/index.js",
@@ -44,7 +44,7 @@
44
44
  "license": "MIT",
45
45
  "dependencies": {
46
46
  "@rhavenside/cadence": "^1.0.1",
47
- "@rhavenside/scaffold": "^1.1.8",
47
+ "@rhavenside/scaffold": "^1.1.9",
48
48
  "@popperjs/core": "^2.11.8"
49
49
  },
50
50
  "devDependencies": {