@rhavenside/baseline 2.0.1 → 2.0.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.
- package/README.md +2 -2
- package/dist/js/base.js +157 -2
- package/dist/js/index.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Base-Line Design System
|
|
2
2
|
|
|
3
|
-
A strict, layer-based design system with semantic tokens.
|
|
3
|
+
A strict, layer-based design system with semantic tokens. Features a custom naming convention and token-based theming system.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@rhavenside/baseline)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
@@ -469,4 +469,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for the strict contribution rules.
|
|
|
469
469
|
|
|
470
470
|
---
|
|
471
471
|
|
|
472
|
-
Built with ❤️ using
|
|
472
|
+
Built with ❤️ using RFS for responsive typography.
|
package/dist/js/base.js
CHANGED
|
@@ -11,6 +11,8 @@ import { onDOMContentLoaded, getjQuery, executeAfterTransition, getDataAttribute
|
|
|
11
11
|
class DataAPI {
|
|
12
12
|
constructor() {
|
|
13
13
|
this.components = new Map()
|
|
14
|
+
this.observer = null
|
|
15
|
+
this.autoObserve = true
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
/**
|
|
@@ -23,10 +25,10 @@ class DataAPI {
|
|
|
23
25
|
/**
|
|
24
26
|
* Initialize components from data attributes
|
|
25
27
|
*/
|
|
26
|
-
init() {
|
|
28
|
+
init(rootElement = document) {
|
|
27
29
|
this.components.forEach((ComponentClass, name) => {
|
|
28
30
|
const selector = `[data-c-${name}]`
|
|
29
|
-
const elements =
|
|
31
|
+
const elements = rootElement.querySelectorAll(selector)
|
|
30
32
|
|
|
31
33
|
elements.forEach(element => {
|
|
32
34
|
if (!element._baseLineComponent) {
|
|
@@ -34,7 +36,158 @@ class DataAPI {
|
|
|
34
36
|
element._baseLineComponent = instance
|
|
35
37
|
}
|
|
36
38
|
})
|
|
39
|
+
|
|
40
|
+
// Special handling for collapse - also check data-c-toggle="collapse"
|
|
41
|
+
if (name === 'collapse') {
|
|
42
|
+
const toggleElements = rootElement.querySelectorAll('[data-c-toggle="collapse"]')
|
|
43
|
+
toggleElements.forEach(toggleElement => {
|
|
44
|
+
const target = toggleElement.getAttribute('data-c-target') || toggleElement.getAttribute('href')
|
|
45
|
+
if (target) {
|
|
46
|
+
const targetElement = rootElement.querySelector(target)
|
|
47
|
+
if (targetElement && !targetElement._baseLineComponent) {
|
|
48
|
+
const parentSelector = toggleElement.getAttribute('data-c-parent')
|
|
49
|
+
const config = parentSelector ? { parent: parentSelector } : {}
|
|
50
|
+
const instance = new ComponentClass(targetElement, config)
|
|
51
|
+
targetElement._baseLineComponent = instance
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Special handling for tooltip - also check data-c-toggle="tooltip"
|
|
58
|
+
if (name === 'tooltip') {
|
|
59
|
+
const tooltipElements = rootElement.querySelectorAll('[data-c-toggle="tooltip"], [data-bl-toggle="tooltip"]')
|
|
60
|
+
tooltipElements.forEach(element => {
|
|
61
|
+
if (!element._baseLineComponent) {
|
|
62
|
+
const title = element.getAttribute('title') ||
|
|
63
|
+
element.getAttribute('data-c-title') ||
|
|
64
|
+
element.getAttribute('data-bl-title')
|
|
65
|
+
const placement = element.getAttribute('data-c-placement') ||
|
|
66
|
+
element.getAttribute('data-bl-placement') ||
|
|
67
|
+
'top'
|
|
68
|
+
const html = element.getAttribute('data-c-html') === 'true' ||
|
|
69
|
+
element.getAttribute('data-bl-html') === 'true'
|
|
70
|
+
|
|
71
|
+
if (title) {
|
|
72
|
+
const instance = new ComponentClass(element, {
|
|
73
|
+
title: title,
|
|
74
|
+
placement: placement,
|
|
75
|
+
html: html
|
|
76
|
+
})
|
|
77
|
+
element._baseLineComponent = instance
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Special handling for tab - also check data-c-toggle="tab"
|
|
84
|
+
if (name === 'tab') {
|
|
85
|
+
const tabElements = rootElement.querySelectorAll('[data-c-toggle="tab"], [data-c-toggle="pill"], [data-bl-toggle="tab"], [data-bl-toggle="pill"]')
|
|
86
|
+
tabElements.forEach(element => {
|
|
87
|
+
if (!element._baseLineComponent) {
|
|
88
|
+
const instance = new ComponentClass(element)
|
|
89
|
+
element._baseLineComponent = instance
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Special handling for toast - check for .c-toast elements
|
|
95
|
+
if (name === 'toast') {
|
|
96
|
+
const toastElements = rootElement.querySelectorAll('.c-toast')
|
|
97
|
+
toastElements.forEach(element => {
|
|
98
|
+
if (!element._baseLineComponent) {
|
|
99
|
+
const instance = new ComponentClass(element)
|
|
100
|
+
element._baseLineComponent = instance
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Special handling for popover - also check data-c-toggle="popover"
|
|
106
|
+
if (name === 'popover') {
|
|
107
|
+
const popoverElements = rootElement.querySelectorAll('[data-c-toggle="popover"], [data-bl-toggle="popover"]')
|
|
108
|
+
popoverElements.forEach(element => {
|
|
109
|
+
if (!element._baseLineComponent) {
|
|
110
|
+
const title = element.getAttribute('data-c-title') || element.getAttribute('data-bl-title')
|
|
111
|
+
const content = element.getAttribute('data-c-content') || element.getAttribute('data-bl-content')
|
|
112
|
+
const placement = element.getAttribute('data-c-placement') ||
|
|
113
|
+
element.getAttribute('data-bl-placement') ||
|
|
114
|
+
'right'
|
|
115
|
+
|
|
116
|
+
if (title || content) {
|
|
117
|
+
const instance = new ComponentClass(element, {
|
|
118
|
+
title: title,
|
|
119
|
+
content: content,
|
|
120
|
+
placement: placement
|
|
121
|
+
})
|
|
122
|
+
element._baseLineComponent = instance
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Start observing DOM changes for automatic initialization
|
|
132
|
+
*/
|
|
133
|
+
startObserving() {
|
|
134
|
+
if (!this.autoObserve || this.observer) {
|
|
135
|
+
return
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Debounce function to avoid too many init calls
|
|
139
|
+
let initTimeout
|
|
140
|
+
const debouncedInit = () => {
|
|
141
|
+
clearTimeout(initTimeout)
|
|
142
|
+
initTimeout = setTimeout(() => {
|
|
143
|
+
this.init()
|
|
144
|
+
}, 100)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
this.observer = new MutationObserver((mutations) => {
|
|
148
|
+
let hasNewElements = false
|
|
149
|
+
|
|
150
|
+
mutations.forEach((mutation) => {
|
|
151
|
+
mutation.addedNodes.forEach((node) => {
|
|
152
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
153
|
+
// Check if this node or its children have data-c-* attributes
|
|
154
|
+
if (node.hasAttribute && Array.from(node.attributes).some(attr =>
|
|
155
|
+
attr.name.startsWith('data-c-')
|
|
156
|
+
)) {
|
|
157
|
+
hasNewElements = true
|
|
158
|
+
} else if (node.querySelectorAll) {
|
|
159
|
+
// Check children for data-c-* attributes or data-c-toggle
|
|
160
|
+
const hasDataAttributes = node.querySelectorAll('[data-c-toggle], [data-c-target], [data-c-parent]').length > 0
|
|
161
|
+
if (hasDataAttributes) {
|
|
162
|
+
hasNewElements = true
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
if (hasNewElements) {
|
|
170
|
+
debouncedInit()
|
|
171
|
+
}
|
|
37
172
|
})
|
|
173
|
+
|
|
174
|
+
// Only observe if document.body exists
|
|
175
|
+
if (document.body) {
|
|
176
|
+
this.observer.observe(document.body, {
|
|
177
|
+
childList: true,
|
|
178
|
+
subtree: true
|
|
179
|
+
})
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Stop observing DOM changes
|
|
185
|
+
*/
|
|
186
|
+
stopObserving() {
|
|
187
|
+
if (this.observer) {
|
|
188
|
+
this.observer.disconnect()
|
|
189
|
+
this.observer = null
|
|
190
|
+
}
|
|
38
191
|
}
|
|
39
192
|
|
|
40
193
|
/**
|
|
@@ -133,6 +286,8 @@ export class BaseComponent {
|
|
|
133
286
|
*/
|
|
134
287
|
onDOMContentLoaded(() => {
|
|
135
288
|
dataAPI.init()
|
|
289
|
+
// Start observing for dynamically added elements
|
|
290
|
+
dataAPI.startObserving()
|
|
136
291
|
})
|
|
137
292
|
|
|
138
293
|
// Export for global access
|
package/dist/js/index.js
CHANGED
|
@@ -47,6 +47,10 @@ Object.keys(components).forEach(name => {
|
|
|
47
47
|
// Initialize on DOM ready
|
|
48
48
|
onDOMContentLoaded(() => {
|
|
49
49
|
dataAPI.init()
|
|
50
|
+
// Start observing for dynamically added elements (already called in base.js, but ensure it's called here too)
|
|
51
|
+
if (document.body) {
|
|
52
|
+
dataAPI.startObserving()
|
|
53
|
+
}
|
|
50
54
|
|
|
51
55
|
// Trigger load event for components that need it (e.g., Tab)
|
|
52
56
|
const loadEvent = new Event('load.c.tab')
|