@svar-ui/svelte-toolbar 2.5.1 → 2.5.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/package.json +3 -3
- package/src/components/Toolbar.svelte +36 -23
- package/types/index.d.ts +1 -0
- package/whatsnew.md +7 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@svar-ui/svelte-toolbar",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.3",
|
|
4
4
|
"description": "Svelte toolbar component. Lightweight, customizable, easy-to-use.",
|
|
5
5
|
"productTag": "toolbar",
|
|
6
6
|
"productTrial": false,
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
},
|
|
34
34
|
"homepage": "https://svar.dev/svelte/core/",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@svar-ui/svelte-core": "2.5.
|
|
37
|
-
"@svar-ui/lib-dom": "0.12.
|
|
36
|
+
"@svar-ui/svelte-core": "2.5.3",
|
|
37
|
+
"@svar-ui/lib-dom": "0.12.2"
|
|
38
38
|
},
|
|
39
39
|
"files": [
|
|
40
40
|
"src",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
css = "",
|
|
13
13
|
values = $bindable(null),
|
|
14
14
|
overflow = "menu",
|
|
15
|
+
layout = "row",
|
|
15
16
|
onclick,
|
|
16
17
|
onchange,
|
|
17
18
|
} = $props();
|
|
@@ -25,57 +26,60 @@
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
let div = null;
|
|
28
|
-
let lastToolbarState = -1;
|
|
29
29
|
let menuItems = $state([]);
|
|
30
30
|
|
|
31
31
|
function processOverflow() {
|
|
32
32
|
if (overflow === "wrap") return;
|
|
33
33
|
|
|
34
|
+
const nodes = div.children;
|
|
35
|
+
// restore all items so widths can be measured
|
|
36
|
+
for (let i = 0; i < items.length; i++) {
|
|
37
|
+
if (nodes[i]) nodes[i].style.display = "";
|
|
38
|
+
}
|
|
39
|
+
|
|
34
40
|
const visibleWidth = div.clientWidth;
|
|
35
41
|
const fullWidth = div.scrollWidth;
|
|
36
42
|
const needMenu = fullWidth > visibleWidth;
|
|
37
43
|
|
|
38
44
|
if (needMenu) {
|
|
39
45
|
if (overflow === "collapse") return collapseGroups(visibleWidth);
|
|
40
|
-
// we need to decide how many nodes need to be
|
|
41
|
-
const nodes = div.children;
|
|
42
|
-
let sum = 0;
|
|
43
46
|
|
|
47
|
+
// pinned items always stay visible
|
|
48
|
+
let pinnedWidth = 0;
|
|
44
49
|
for (let i = 0; i < items.length; i++) {
|
|
50
|
+
if (items[i].pinned) pinnedWidth += nodes[i].clientWidth;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let sum = 0;
|
|
54
|
+
for (let i = 0; i < items.length; i++) {
|
|
55
|
+
if (items[i].pinned) continue;
|
|
45
56
|
sum += nodes[i].clientWidth;
|
|
46
57
|
if (items[i].comp == "separator") sum += 8;
|
|
47
|
-
if (sum > visibleWidth - 40) {
|
|
48
|
-
//
|
|
49
|
-
if (lastToolbarState === i) return;
|
|
50
|
-
lastToolbarState = i;
|
|
51
|
-
|
|
52
|
-
// we need to hide nodes[i] and all next nodes
|
|
58
|
+
if (sum > visibleWidth - 40 - pinnedWidth) {
|
|
59
|
+
// we need to hide nodes[i] and all next non-pinned nodes
|
|
53
60
|
menuItems = [];
|
|
54
61
|
for (let j = i; j < items.length; j++) {
|
|
62
|
+
if (items[j].pinned) continue;
|
|
55
63
|
menuItems.push(items[j]);
|
|
56
|
-
nodes[j].style.
|
|
64
|
+
nodes[j].style.display = "none";
|
|
57
65
|
}
|
|
58
66
|
// hide the ending separator
|
|
59
|
-
if (
|
|
60
|
-
|
|
67
|
+
if (
|
|
68
|
+
i > 0 &&
|
|
69
|
+
items[i - 1].comp == "separator" &&
|
|
70
|
+
!items[i - 1].pinned
|
|
71
|
+
) {
|
|
72
|
+
nodes[i - 1].style.display = "none";
|
|
61
73
|
}
|
|
62
74
|
break;
|
|
63
75
|
}
|
|
64
|
-
nodes[i].style.visibility = "";
|
|
65
76
|
}
|
|
66
77
|
} else {
|
|
67
78
|
const freeWidth = visibleWidth - getTotalWidth();
|
|
68
79
|
if (freeWidth <= 0) return;
|
|
69
80
|
if (overflow === "collapse") return expandGroups(freeWidth);
|
|
70
81
|
|
|
71
|
-
if (menuItems.length)
|
|
72
|
-
lastToolbarState = null;
|
|
73
|
-
const nodes = div.children;
|
|
74
|
-
for (let i = 0; i < items.length; i++) {
|
|
75
|
-
nodes[i].style.visibility = "";
|
|
76
|
-
}
|
|
77
|
-
menuItems = [];
|
|
78
|
-
}
|
|
82
|
+
if (menuItems.length) menuItems = [];
|
|
79
83
|
}
|
|
80
84
|
}
|
|
81
85
|
|
|
@@ -84,7 +88,7 @@
|
|
|
84
88
|
let sum = 0;
|
|
85
89
|
for (let i = 0; i < items.length; i++) {
|
|
86
90
|
if (items[i].comp != "spacer") {
|
|
87
|
-
sum += nodes[i]
|
|
91
|
+
sum += nodes[i]?.clientWidth || 0;
|
|
88
92
|
if (items[i].comp == "separator") sum += 8;
|
|
89
93
|
}
|
|
90
94
|
}
|
|
@@ -150,6 +154,8 @@
|
|
|
150
154
|
<div
|
|
151
155
|
class="wx-toolbar {css}"
|
|
152
156
|
class:wx-wrap={overflow === "wrap"}
|
|
157
|
+
class:wx-column={layout == "column"}
|
|
158
|
+
class:wx-has-menu={menuItems.length}
|
|
153
159
|
bind:this={div}
|
|
154
160
|
>
|
|
155
161
|
{#each visibleItems as item}
|
|
@@ -178,8 +184,15 @@
|
|
|
178
184
|
align-items: stretch;
|
|
179
185
|
padding: 4px;
|
|
180
186
|
position: relative;
|
|
187
|
+
min-height: 48px;
|
|
188
|
+
}
|
|
189
|
+
.wx-toolbar.wx-has-menu {
|
|
190
|
+
padding-right: 48px;
|
|
181
191
|
}
|
|
182
192
|
.wx-toolbar.wx-wrap {
|
|
183
193
|
flex-wrap: wrap;
|
|
184
194
|
}
|
|
195
|
+
.wx-column {
|
|
196
|
+
flex-flow: column;
|
|
197
|
+
}
|
|
185
198
|
</style>
|
package/types/index.d.ts
CHANGED