@svar-ui/svelte-toolbar 2.5.2 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@svar-ui/svelte-toolbar",
3
- "version": "2.5.2",
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.1",
37
- "@svar-ui/lib-dom": "0.12.1"
36
+ "@svar-ui/svelte-core": "2.5.3",
37
+ "@svar-ui/lib-dom": "0.12.2"
38
38
  },
39
39
  "files": [
40
40
  "src",
@@ -26,57 +26,60 @@
26
26
  }
27
27
 
28
28
  let div = null;
29
- let lastToolbarState = -1;
30
29
  let menuItems = $state([]);
31
30
 
32
31
  function processOverflow() {
33
32
  if (overflow === "wrap") return;
34
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
+
35
40
  const visibleWidth = div.clientWidth;
36
41
  const fullWidth = div.scrollWidth;
37
42
  const needMenu = fullWidth > visibleWidth;
38
43
 
39
44
  if (needMenu) {
40
45
  if (overflow === "collapse") return collapseGroups(visibleWidth);
41
- // we need to decide how many nodes need to be
42
- const nodes = div.children;
43
- let sum = 0;
44
46
 
47
+ // pinned items always stay visible
48
+ let pinnedWidth = 0;
45
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;
46
56
  sum += nodes[i].clientWidth;
47
57
  if (items[i].comp == "separator") sum += 8;
48
- if (sum > visibleWidth - 40) {
49
- // skip updates, as visibility state was not changed
50
- if (lastToolbarState === i) return;
51
- lastToolbarState = i;
52
-
53
- // 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
54
60
  menuItems = [];
55
61
  for (let j = i; j < items.length; j++) {
62
+ if (items[j].pinned) continue;
56
63
  menuItems.push(items[j]);
57
- nodes[j].style.visibility = "hidden";
64
+ nodes[j].style.display = "none";
58
65
  }
59
66
  // hide the ending separator
60
- if (i > 0 && items[i - 1].comp == "separator") {
61
- nodes[i - 1].style.visibility = "hidden";
67
+ if (
68
+ i > 0 &&
69
+ items[i - 1].comp == "separator" &&
70
+ !items[i - 1].pinned
71
+ ) {
72
+ nodes[i - 1].style.display = "none";
62
73
  }
63
74
  break;
64
75
  }
65
- nodes[i].style.visibility = "";
66
76
  }
67
77
  } else {
68
78
  const freeWidth = visibleWidth - getTotalWidth();
69
79
  if (freeWidth <= 0) return;
70
80
  if (overflow === "collapse") return expandGroups(freeWidth);
71
81
 
72
- if (menuItems.length) {
73
- lastToolbarState = null;
74
- const nodes = div.children;
75
- for (let i = 0; i < items.length; i++) {
76
- nodes[i].style.visibility = "";
77
- }
78
- menuItems = [];
79
- }
82
+ if (menuItems.length) menuItems = [];
80
83
  }
81
84
  }
82
85
 
@@ -152,6 +155,7 @@
152
155
  class="wx-toolbar {css}"
153
156
  class:wx-wrap={overflow === "wrap"}
154
157
  class:wx-column={layout == "column"}
158
+ class:wx-has-menu={menuItems.length}
155
159
  bind:this={div}
156
160
  >
157
161
  {#each visibleItems as item}
@@ -180,6 +184,10 @@
180
184
  align-items: stretch;
181
185
  padding: 4px;
182
186
  position: relative;
187
+ min-height: 48px;
188
+ }
189
+ .wx-toolbar.wx-has-menu {
190
+ padding-right: 48px;
183
191
  }
184
192
  .wx-toolbar.wx-wrap {
185
193
  flex-wrap: wrap;
package/types/index.d.ts CHANGED
@@ -13,6 +13,7 @@ export interface IToolbarItem {
13
13
  handler?: (item: IToolbarItem, value?: any) => void;
14
14
  layout?: "column";
15
15
  items?: IToolbarItem[];
16
+ pinned?: boolean;
16
17
  [key: string]: any;
17
18
  }
18
19
 
package/whatsnew.md CHANGED
@@ -1,8 +1,9 @@
1
- ## 2.5.2
1
+ ## 2.5.3
2
2
 
3
3
  ### Fixes
4
4
 
5
5
  - Impossible to arrange first level items as a column
6
+ - Impossible to fix certain items as always visible
6
7
 
7
8
  ## 2.5.1
8
9