@kws3/ui 1.7.2 → 1.7.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/CHANGELOG.mdx CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.7.3
2
+ - Fix docs for `Popover`
3
+ - Increase performance for `SlidingPane` by using ResizeObserver when available
4
+
1
5
  ## 1.7.2
2
6
  - `DatePicker` component: fix initialisation bug on mobile
3
7
  - `Pagination` component: rename property `breakThreshold` -> `maxVisiblePages` plus bugfix and documentation update
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kws3/ui",
3
- "version": "1.7.2",
3
+ "version": "1.7.3",
4
4
  "description": "UI components for use with Svelte v3 applications.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -29,5 +29,5 @@
29
29
  "text-mask-core": "^5.1.2",
30
30
  "tippy.js": "^6.3.1"
31
31
  },
32
- "gitHead": "227e2a0e081adad79a4a46096d1f846bd307d6e3"
32
+ "gitHead": "f76e8d0f5bb9859092c7e4e6b38f8fbd3252dc5d"
33
33
  }
@@ -18,24 +18,40 @@ This will work only when `track_height` is set to `true`
18
18
  - `<slot name="default" />` - Used to display content
19
19
 
20
20
  -->
21
- <div
22
- bind:clientHeight={_height}
23
- class="sliding-pane {v_center ? 'v-centered' : ''} {h_center
24
- ? 'h-centered'
25
- : ''} {active ? 'is-active' : ''} {klass}"
26
- {style}>
21
+ {#if hasResizeObserver}
27
22
  <div
28
- bind:this={slideInner}
29
- class="sliding-pane-inner {v_center ? 'v-centered' : ''} {h_center
30
- ? 'h-centered'
31
- : ''}">
32
- <!--Used to display content--><slot />
23
+ class="sliding-pane with-resize-observer {v_center
24
+ ? 'v-centered'
25
+ : ''} {h_center ? 'h-centered' : ''} {active ? 'is-active' : ''} {klass}"
26
+ {style}>
27
+ <div
28
+ bind:this={slideInner}
29
+ class="sliding-pane-inner {v_center ? 'v-centered' : ''} {h_center
30
+ ? 'h-centered'
31
+ : ''}">
32
+ <!--Used to display content--><slot />
33
+ </div>
33
34
  </div>
34
- </div>
35
+ {:else}
36
+ <div
37
+ bind:clientHeight={_height}
38
+ class="sliding-pane with-legacy-observer {v_center
39
+ ? 'v-centered'
40
+ : ''} {h_center ? 'h-centered' : ''} {active ? 'is-active' : ''} {klass}"
41
+ {style}>
42
+ <div
43
+ bind:this={slideInner}
44
+ class="sliding-pane-inner {v_center ? 'v-centered' : ''} {h_center
45
+ ? 'h-centered'
46
+ : ''}">
47
+ <!--Used to display content--><slot />
48
+ </div>
49
+ </div>
50
+ {/if}
35
51
 
36
52
  <script>
37
53
  import { onMount, createEventDispatcher } from "svelte";
38
- import { rAF } from "../utils";
54
+ import { debounce } from "@kws3/ui/utils";
39
55
 
40
56
  const fire = createEventDispatcher();
41
57
 
@@ -60,7 +76,8 @@ This will work only when `track_height` is set to `true`
60
76
  */
61
77
  track_height = true;
62
78
 
63
- let _height, slideInner;
79
+ const hasResizeObserver = typeof window.ResizeObserver != "undefined";
80
+ let _height, slideInner, Observer;
64
81
 
65
82
  /**
66
83
  * CSS classes for the panel
@@ -68,15 +85,9 @@ This will work only when `track_height` is set to `true`
68
85
  let klass = "";
69
86
  export { klass as class };
70
87
 
71
- onMount(() => {
72
- pollForRender();
73
- });
74
-
75
88
  $: {
76
89
  if (active && track_height && (active || _height)) {
77
- rAF(() => {
78
- fireSizeChange();
79
- });
90
+ fireSizeChange();
80
91
  }
81
92
  }
82
93
 
@@ -86,11 +97,12 @@ This will work only when `track_height` is set to `true`
86
97
  } else {
87
98
  setTimeout(() => {
88
99
  pollForRender();
89
- }, 200);
100
+ }, 50);
90
101
  }
91
102
  }
92
103
 
93
104
  function init() {
105
+ setupResizeObserver();
94
106
  fireSizeChange();
95
107
  }
96
108
 
@@ -99,21 +111,41 @@ This will work only when `track_height` is set to `true`
99
111
  if (!slideInner || typeof slideInner == "undefined") {
100
112
  pollForRender();
101
113
  } else {
102
- rAF(() => {
103
- if (!slideInner || typeof slideInner == "undefined") {
104
- return;
105
- }
106
- var h1 = slideInner.scrollHeight,
107
- h2 = slideInner.clientHeight;
108
- var new_height = Math.max(h1, h2);
109
- /**
110
- * Event fired when the height of the pane changes
111
- *
112
- * This will work only when `track_height` is set to `true`
113
- */
114
- fire("heightChange", { height: new_height });
115
- });
114
+ if (!slideInner || typeof slideInner == "undefined") {
115
+ return;
116
+ }
117
+ var h1 = slideInner.scrollHeight,
118
+ h2 = slideInner.clientHeight;
119
+ var new_height = Math.max(h1, h2);
120
+ /**
121
+ * Event fired when the height of the pane changes
122
+ *
123
+ * This will work only when `track_height` is set to `true`
124
+ */
125
+ fire("heightChange", { height: new_height });
116
126
  }
117
127
  }
118
128
  }
129
+
130
+ const debouncedFireSizeChange = debounce(fireSizeChange, 150, false);
131
+
132
+ const setupResizeObserver = () => {
133
+ if (hasResizeObserver) {
134
+ if (!slideInner || typeof slideInner == "undefined") {
135
+ pollForRender();
136
+ } else {
137
+ Observer = new ResizeObserver(() => {
138
+ debouncedFireSizeChange();
139
+ });
140
+ Observer.observe(slideInner);
141
+ }
142
+ }
143
+ };
144
+
145
+ onMount(() => {
146
+ pollForRender();
147
+ return () => {
148
+ Observer && Observer.disconnect();
149
+ };
150
+ });
119
151
  </script>