@neovici/cosmoz-bottom-bar 9.1.2 → 9.3.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/dist/cosmoz-bottom-bar.js +16 -7
- package/dist/overflow.d.ts +1 -0
- package/dist/overflow.js +27 -2
- package/package.json +1 -1
|
@@ -84,7 +84,13 @@ const style = css `
|
|
|
84
84
|
line-height: 40px;
|
|
85
85
|
overflow: hidden;
|
|
86
86
|
flex: 0 0 auto;
|
|
87
|
+
}
|
|
88
|
+
#bottomBarToolbar::slotted(
|
|
89
|
+
:not(slot):not([unstyled])[data-visibility='hidden']
|
|
90
|
+
) {
|
|
87
91
|
visibility: hidden;
|
|
92
|
+
width: 100%;
|
|
93
|
+
order: 9999;
|
|
88
94
|
}
|
|
89
95
|
|
|
90
96
|
#bottomBarToolbar::slotted(:not(slot)[disabled]) {
|
|
@@ -127,6 +133,9 @@ const useMenuButtons = (host) => {
|
|
|
127
133
|
visible: new Set(),
|
|
128
134
|
overflowing: new Set(),
|
|
129
135
|
});
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
host.dispatchEvent(new CustomEvent('reflow', { detail: buttonStates }));
|
|
138
|
+
}, [buttonStates]);
|
|
130
139
|
const allButtons = useMemo(() => [...buttonStates.visible, ...buttonStates.overflowing], [buttonStates]);
|
|
131
140
|
const processedButtons = useMemo(() => allButtons
|
|
132
141
|
.map((btn) => ({
|
|
@@ -140,7 +149,7 @@ const useMenuButtons = (host) => {
|
|
|
140
149
|
useEffect(() => {
|
|
141
150
|
processedButtons.forEach(({ element, priority }, i) => {
|
|
142
151
|
const isVisible = i < toolbarLimit;
|
|
143
|
-
element.
|
|
152
|
+
element.dataset.visibility = isVisible ? 'visible' : 'hidden';
|
|
144
153
|
element.style.order = String(-priority);
|
|
145
154
|
});
|
|
146
155
|
}, [processedButtons, toolbarLimit]);
|
|
@@ -166,13 +175,13 @@ const CosmozBottomBar = (host) => {
|
|
|
166
175
|
useLayoutEffect(() => {
|
|
167
176
|
toggle(host, active);
|
|
168
177
|
}, [active]);
|
|
169
|
-
return html
|
|
178
|
+
return html ` <div id="bar" part="bar">
|
|
170
179
|
<div id="info" part="info"><slot name="info"></slot></div>
|
|
171
|
-
<div id="buttonContainer">
|
|
180
|
+
<div id="buttonContainer" part="buttons">
|
|
172
181
|
<slot id="bottomBarToolbar" ${overflow(setButtonStates)}></slot>
|
|
173
182
|
</div>
|
|
174
183
|
|
|
175
|
-
<cosmoz-dropdown-menu id="dropdown">
|
|
184
|
+
<cosmoz-dropdown-menu id="dropdown" part="dropdown">
|
|
176
185
|
<svg
|
|
177
186
|
slot="button"
|
|
178
187
|
width="4"
|
|
@@ -185,19 +194,19 @@ const CosmozBottomBar = (host) => {
|
|
|
185
194
|
fill-rule="evenodd"
|
|
186
195
|
clip-rule="evenodd"
|
|
187
196
|
d="M1.50996e-07 2C1.02714e-07 3.10457 0.89543 4 2 4C3.10457 4 4 3.10457 4 2C4 0.89543 3.10457 -3.91405e-08 2 -8.74228e-08C0.895431 -1.35705e-07 1.99278e-07 0.89543 1.50996e-07 2Z"
|
|
188
|
-
fill="
|
|
197
|
+
fill="currentColor"
|
|
189
198
|
/>
|
|
190
199
|
<path
|
|
191
200
|
fill-rule="evenodd"
|
|
192
201
|
clip-rule="evenodd"
|
|
193
202
|
d="M1.50996e-07 8C1.02714e-07 9.10457 0.89543 10 2 10C3.10457 10 4 9.10457 4 8C4 6.89543 3.10457 6 2 6C0.895431 6 1.99278e-07 6.89543 1.50996e-07 8Z"
|
|
194
|
-
fill="
|
|
203
|
+
fill="currentColor"
|
|
195
204
|
/>
|
|
196
205
|
<path
|
|
197
206
|
fill-rule="evenodd"
|
|
198
207
|
clip-rule="evenodd"
|
|
199
208
|
d="M1.50996e-07 14C1.02714e-07 15.1046 0.89543 16 2 16C3.10457 16 4 15.1046 4 14C4 12.8954 3.10457 12 2 12C0.895431 12 1.99278e-07 12.8954 1.50996e-07 14Z"
|
|
200
|
-
fill="
|
|
209
|
+
fill="currentColor"
|
|
201
210
|
/>
|
|
202
211
|
</svg>
|
|
203
212
|
${map(menuButtons, (menuButton) => html `
|
package/dist/overflow.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { DirectiveResult } from 'lit-html/directive.js';
|
|
|
4
4
|
type OnOverflow = (opts: {
|
|
5
5
|
visible: Set<HTMLElement>;
|
|
6
6
|
overflowing: Set<HTMLElement>;
|
|
7
|
+
hidden: Set<HTMLElement>;
|
|
7
8
|
}) => void;
|
|
8
9
|
declare class OverflowDirective extends AsyncDirective {
|
|
9
10
|
observer?: IntersectionObserver;
|
package/dist/overflow.js
CHANGED
|
@@ -4,14 +4,30 @@ import { directive } from 'lit-html/directive.js';
|
|
|
4
4
|
function isEntryHidden(el) {
|
|
5
5
|
return el.boundingClientRect.height === 0;
|
|
6
6
|
}
|
|
7
|
+
function isElementHidden(el) {
|
|
8
|
+
return el.getBoundingClientRect().height === 0;
|
|
9
|
+
}
|
|
7
10
|
const check = (part) => {
|
|
8
11
|
if (part.element.tagName !== 'SLOT') {
|
|
9
12
|
throw new Error('Overflow directive must be used on a slot element');
|
|
10
13
|
}
|
|
11
14
|
};
|
|
15
|
+
function reconcileHiddenElements(hidden, overflowing) {
|
|
16
|
+
// If a parent element was hidden, all its children were marked as hidden.
|
|
17
|
+
// When the parent becomes visible, the observer only reports entries for
|
|
18
|
+
// children that intersect the parent’s content box. Others remain stuck in
|
|
19
|
+
// `hidden` even if they should be `overflowing`. This pass corrects that.
|
|
20
|
+
hidden.forEach((el) => {
|
|
21
|
+
if (isElementHidden(el))
|
|
22
|
+
return;
|
|
23
|
+
overflowing.add(el);
|
|
24
|
+
hidden.delete(el);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
12
27
|
const setupObserver = (slot, onOverflow) => {
|
|
13
28
|
let visible = new Set();
|
|
14
29
|
let overflowing = new Set();
|
|
30
|
+
let hidden = new Set();
|
|
15
31
|
const observer = new IntersectionObserver((entries) => {
|
|
16
32
|
entries.forEach((entry) => {
|
|
17
33
|
const el = entry.target;
|
|
@@ -19,22 +35,27 @@ const setupObserver = (slot, onOverflow) => {
|
|
|
19
35
|
entry.intersectionRect.height !== 0) {
|
|
20
36
|
visible.add(el);
|
|
21
37
|
overflowing.delete(el);
|
|
38
|
+
hidden.delete(el);
|
|
22
39
|
}
|
|
23
40
|
else if (isEntryHidden(entry)) {
|
|
24
41
|
visible.delete(el);
|
|
25
42
|
overflowing.delete(el);
|
|
43
|
+
hidden.add(el);
|
|
26
44
|
}
|
|
27
45
|
else {
|
|
28
46
|
visible.delete(el);
|
|
29
47
|
overflowing.add(el);
|
|
48
|
+
hidden.delete(el);
|
|
30
49
|
}
|
|
31
50
|
});
|
|
32
|
-
|
|
51
|
+
reconcileHiddenElements(hidden, overflowing);
|
|
52
|
+
onOverflow({ visible, overflowing, hidden });
|
|
33
53
|
}, { root: slot.parentElement, threshold: [0, 0.5, 1] });
|
|
34
54
|
const observe = () => {
|
|
35
55
|
const elements = Array.from(slot.assignedElements({ flatten: true }));
|
|
36
56
|
const newVisible = new Set();
|
|
37
57
|
const newOverflowing = new Set();
|
|
58
|
+
const newHidden = new Set();
|
|
38
59
|
for (const c of elements) {
|
|
39
60
|
if (visible.has(c)) {
|
|
40
61
|
newVisible.add(c);
|
|
@@ -42,13 +63,17 @@ const setupObserver = (slot, onOverflow) => {
|
|
|
42
63
|
else if (overflowing.has(c)) {
|
|
43
64
|
newOverflowing.add(c);
|
|
44
65
|
}
|
|
66
|
+
else if (hidden.has(c)) {
|
|
67
|
+
newHidden.add(c);
|
|
68
|
+
}
|
|
45
69
|
else {
|
|
46
70
|
observer.observe(c);
|
|
47
71
|
}
|
|
48
72
|
}
|
|
49
73
|
visible = newVisible;
|
|
50
74
|
overflowing = newOverflowing;
|
|
51
|
-
|
|
75
|
+
hidden = newHidden;
|
|
76
|
+
onOverflow({ visible, overflowing, hidden });
|
|
52
77
|
};
|
|
53
78
|
observe();
|
|
54
79
|
slot.addEventListener('slotchange', observe);
|
package/package.json
CHANGED