@zuzjs/ui 0.9.5 → 0.9.7
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/cjs/comps/Chart/index.d.ts +8 -0
- package/dist/cjs/comps/Chart/index.js +66 -0
- package/dist/cjs/comps/Chart/types.d.ts +10 -0
- package/dist/cjs/comps/Chart/types.js +4 -0
- package/dist/cjs/comps/Cover/index.d.ts +3 -1
- package/dist/cjs/comps/Cover/index.js +3 -3
- package/dist/cjs/comps/Form/index.js +7 -3
- package/dist/cjs/comps/Search/index.d.ts +4 -0
- package/dist/cjs/comps/Search/index.js +7 -3
- package/dist/cjs/comps/Search/types.d.ts +5 -0
- package/dist/cjs/comps/Select/index.d.ts +3 -0
- package/dist/cjs/comps/Select/index.js +13 -5
- package/dist/cjs/comps/Select/types.d.ts +7 -1
- package/dist/cjs/comps/Spinner/index.d.ts +3 -1
- package/dist/cjs/comps/Spinner/index.js +11 -4
- package/dist/cjs/comps/TextWheel/index.d.ts +2 -0
- package/dist/cjs/comps/TextWheel/index.js +24 -12
- package/dist/cjs/comps/TextWheel/types.d.ts +2 -0
- package/dist/cjs/comps/index.d.ts +2 -0
- package/dist/cjs/comps/index.js +2 -0
- package/dist/cjs/funs/stylesheet.js +3 -1
- package/dist/cjs/hooks/index.d.ts +2 -0
- package/dist/cjs/hooks/index.js +2 -0
- package/dist/cjs/hooks/useLineChart.d.ts +25 -0
- package/dist/cjs/hooks/useLineChart.js +86 -0
- package/dist/cjs/hooks/usePosition.d.ts +12 -0
- package/dist/cjs/hooks/usePosition.js +191 -0
- package/dist/cjs/hooks/useResizeObserver.d.ts +1 -1
- package/dist/cjs/hooks/useResizeObserver.js +5 -4
- package/dist/cjs/hooks/useScrollbar.js +115 -70
- package/dist/cjs/types/enums.d.ts +2 -0
- package/dist/cjs/types/enums.js +2 -0
- package/dist/cjs/types/index.d.ts +2 -1
- package/dist/css/styles.css +1 -1
- package/dist/esm/comps/Chart/index.d.ts +8 -0
- package/dist/esm/comps/Chart/index.js +66 -0
- package/dist/esm/comps/Chart/types.d.ts +10 -0
- package/dist/esm/comps/Chart/types.js +4 -0
- package/dist/esm/comps/Cover/index.d.ts +3 -1
- package/dist/esm/comps/Cover/index.js +3 -3
- package/dist/esm/comps/Form/index.js +7 -3
- package/dist/esm/comps/Search/index.d.ts +4 -0
- package/dist/esm/comps/Search/index.js +7 -3
- package/dist/esm/comps/Search/types.d.ts +5 -0
- package/dist/esm/comps/Select/index.d.ts +3 -0
- package/dist/esm/comps/Select/index.js +13 -5
- package/dist/esm/comps/Select/types.d.ts +7 -1
- package/dist/esm/comps/Spinner/index.d.ts +3 -1
- package/dist/esm/comps/Spinner/index.js +11 -4
- package/dist/esm/comps/TextWheel/index.d.ts +2 -0
- package/dist/esm/comps/TextWheel/index.js +24 -12
- package/dist/esm/comps/TextWheel/types.d.ts +2 -0
- package/dist/esm/comps/index.d.ts +2 -0
- package/dist/esm/comps/index.js +2 -0
- package/dist/esm/funs/stylesheet.js +3 -1
- package/dist/esm/hooks/index.d.ts +2 -0
- package/dist/esm/hooks/index.js +2 -0
- package/dist/esm/hooks/useLineChart.d.ts +25 -0
- package/dist/esm/hooks/useLineChart.js +86 -0
- package/dist/esm/hooks/usePosition.d.ts +12 -0
- package/dist/esm/hooks/usePosition.js +191 -0
- package/dist/esm/hooks/useResizeObserver.d.ts +1 -1
- package/dist/esm/hooks/useResizeObserver.js +5 -4
- package/dist/esm/hooks/useScrollbar.js +115 -70
- package/dist/esm/types/enums.d.ts +2 -0
- package/dist/esm/types/enums.js +2 -0
- package/dist/esm/types/index.d.ts +2 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -3,6 +3,7 @@ import { useEffect, useState } from 'react';
|
|
|
3
3
|
const useResizeObserver = (ref) => {
|
|
4
4
|
const [size, setSize] = useState({ width: 0, height: 0, top: 0, left: 0 });
|
|
5
5
|
useEffect(() => {
|
|
6
|
+
const _ref = ref instanceof HTMLElement ? ref : ref.current;
|
|
6
7
|
const handleResize = (entries) => {
|
|
7
8
|
for (let entry of entries) {
|
|
8
9
|
const { width, height, top, left } = entry.contentRect;
|
|
@@ -10,12 +11,12 @@ const useResizeObserver = (ref) => {
|
|
|
10
11
|
}
|
|
11
12
|
};
|
|
12
13
|
const resizeObserver = new ResizeObserver(handleResize);
|
|
13
|
-
if (
|
|
14
|
-
resizeObserver.observe(
|
|
14
|
+
if (_ref) {
|
|
15
|
+
resizeObserver.observe(_ref);
|
|
15
16
|
}
|
|
16
17
|
return () => {
|
|
17
|
-
if (
|
|
18
|
-
resizeObserver.unobserve(
|
|
18
|
+
if (_ref) {
|
|
19
|
+
resizeObserver.unobserve(_ref);
|
|
19
20
|
}
|
|
20
21
|
};
|
|
21
22
|
}, [ref]);
|
|
@@ -13,60 +13,78 @@ const useScrollbar = (speed, breakpoints = {}) => {
|
|
|
13
13
|
const dragStartY = useRef(0);
|
|
14
14
|
const scrollStartY = useRef(0);
|
|
15
15
|
const scrollStartX = useRef(0);
|
|
16
|
-
|
|
17
|
-
const
|
|
16
|
+
// No need for thumbHeight/Width refs if calculating them dynamically
|
|
17
|
+
// const thumbHeight = useRef(30);
|
|
18
|
+
// const thumbWidth = useRef(30);
|
|
19
|
+
// Animation frame ID for batching visual updates
|
|
20
|
+
const animationFrameId = useRef(null);
|
|
18
21
|
const updateThumb = useCallback(() => {
|
|
19
22
|
if (!containerRef.current || !thumbY.current || !thumbX.current)
|
|
20
23
|
return;
|
|
21
24
|
const { clientHeight, scrollHeight, scrollTop, clientWidth, scrollWidth, scrollLeft } = containerRef.current;
|
|
22
|
-
//Y thumb
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
const
|
|
25
|
+
// Y thumb calculations and update
|
|
26
|
+
const actualThumbMinHeight = 30; // Min thumb size: 30px
|
|
27
|
+
const thumbSizeY = Math.max((clientHeight / scrollHeight) * clientHeight, actualThumbMinHeight);
|
|
28
|
+
const maxThumbPosY = clientHeight - thumbSizeY;
|
|
29
|
+
const thumbPosY = (scrollTop / (scrollHeight - clientHeight)) * maxThumbPosY;
|
|
26
30
|
thumbY.current.style.height = `${thumbSizeY}px`;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
31
|
+
// *** KEY CHANGE: Use transform for positioning ***
|
|
32
|
+
thumbY.current.style.transform = `translateY(${thumbPosY}px)`;
|
|
33
|
+
thumbY.current.style.willChange = 'transform, height'; // Hint for browser
|
|
34
|
+
// X thumb calculations and update
|
|
35
|
+
const actualThumbMinWidth = 30; // Min thumb size: 30px
|
|
36
|
+
const thumbSizeX = Math.max((clientWidth / scrollWidth) * clientWidth, actualThumbMinWidth);
|
|
37
|
+
const maxThumbPosX = clientWidth - thumbSizeX;
|
|
38
|
+
const thumbPosX = (scrollLeft / (scrollWidth - clientWidth)) * maxThumbPosX;
|
|
32
39
|
thumbX.current.style.width = `${thumbSizeX}px`;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
// *** KEY CHANGE: Use transform for positioning ***
|
|
41
|
+
thumbX.current.style.transform = `translateX(${thumbPosX}px)`;
|
|
42
|
+
thumbX.current.style.willChange = 'transform, width'; // Hint for browser
|
|
43
|
+
// Handle --no-y and --no-x classes (consider if these are strictly needed on every frame)
|
|
44
|
+
// These might still cause reflows, but less frequently than 'top'/'left'
|
|
45
|
+
if (scrollHeight <= clientHeight && rootRef.current) { // Use scrollHeight <= clientHeight for accurate check
|
|
46
|
+
rootRef.current.classList.add(`--no-y`);
|
|
36
47
|
}
|
|
37
|
-
else
|
|
38
|
-
rootRef.current
|
|
39
|
-
if (thumbX.current.clientWidth == clientWidth && rootRef) {
|
|
40
|
-
rootRef.current?.classList.add(`--no-x`);
|
|
48
|
+
else if (rootRef.current) {
|
|
49
|
+
rootRef.current.classList.remove(`--no-y`);
|
|
41
50
|
}
|
|
42
|
-
|
|
43
|
-
rootRef.current
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
if (scrollWidth <= clientWidth && rootRef.current) { // Use scrollWidth <= clientWidth for accurate check
|
|
52
|
+
rootRef.current.classList.add(`--no-x`);
|
|
53
|
+
}
|
|
54
|
+
else if (rootRef.current) {
|
|
55
|
+
rootRef.current.classList.remove(`--no-x`);
|
|
56
|
+
}
|
|
57
|
+
}, []); // Dependencies can be added here if needed, but often not for core calculations
|
|
58
|
+
// *** NEW: Central function to request a visual update via requestAnimationFrame ***
|
|
59
|
+
const requestVisualUpdate = useCallback(() => {
|
|
60
|
+
if (animationFrameId.current) {
|
|
61
|
+
cancelAnimationFrame(animationFrameId.current);
|
|
62
|
+
}
|
|
63
|
+
animationFrameId.current = requestAnimationFrame(() => {
|
|
64
|
+
updateThumb();
|
|
65
|
+
// Trigger breakpoints after the visual update for this frame
|
|
66
|
+
if (containerRef.current) {
|
|
67
|
+
const { scrollTop, scrollHeight, clientHeight, scrollLeft, scrollWidth, clientWidth } = containerRef.current;
|
|
68
|
+
const scrollPercentY = (scrollTop / (scrollHeight - clientHeight)) * 100;
|
|
69
|
+
const scrollPercentX = (scrollLeft / (scrollWidth - clientWidth)) * 100;
|
|
70
|
+
Object.keys(breakpoints).forEach((key) => {
|
|
71
|
+
const breakpoint = parseFloat(key);
|
|
72
|
+
if (Math.abs(scrollPercentY - breakpoint) < 1) {
|
|
73
|
+
breakpoints[breakpoint]?.();
|
|
74
|
+
}
|
|
75
|
+
if (Math.abs(scrollPercentX - breakpoint) < 1) { // Assuming breakpoints can be for X too
|
|
76
|
+
breakpoints[breakpoint]?.();
|
|
77
|
+
}
|
|
78
|
+
});
|
|
52
79
|
}
|
|
53
80
|
});
|
|
54
|
-
};
|
|
81
|
+
}, [updateThumb, breakpoints]);
|
|
55
82
|
const handleScroll = useCallback(() => {
|
|
56
|
-
if (!containerRef.current
|
|
57
|
-
// ||
|
|
58
|
-
// (
|
|
59
|
-
// typeof window !== `undefined` &&
|
|
60
|
-
// window.document.body.classList.contains(`--no-scroll`)
|
|
61
|
-
// )
|
|
62
|
-
)
|
|
83
|
+
if (!containerRef.current)
|
|
63
84
|
return;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
postScroll(scrollPercentY);
|
|
68
|
-
postScroll(scrollPercentX);
|
|
69
|
-
}, [breakpoints, updateThumb]);
|
|
85
|
+
// *** Call requestVisualUpdate instead of postScroll ***
|
|
86
|
+
requestVisualUpdate();
|
|
87
|
+
}, [requestVisualUpdate]);
|
|
70
88
|
// Dragging logic
|
|
71
89
|
const onScrollY = (e) => {
|
|
72
90
|
isDraggingY.current = true;
|
|
@@ -85,30 +103,37 @@ const useScrollbar = (speed, breakpoints = {}) => {
|
|
|
85
103
|
rootRef.current?.classList.add(`--scrolling`);
|
|
86
104
|
};
|
|
87
105
|
const handleDragMove = useCallback((e) => {
|
|
88
|
-
if (!containerRef.current || !
|
|
106
|
+
if (!containerRef.current || (!isDraggingY.current && !isDraggingX.current))
|
|
89
107
|
return;
|
|
90
108
|
const { clientHeight, scrollHeight, clientWidth, scrollWidth } = containerRef.current;
|
|
91
109
|
if (isDraggingY.current) {
|
|
92
110
|
const maxScroll = scrollHeight - clientHeight;
|
|
93
|
-
const
|
|
111
|
+
const thumbCurrentHeight = thumbY.current?.clientHeight || 30; // Use actual thumb height
|
|
112
|
+
const maxThumbMove = clientHeight - thumbCurrentHeight;
|
|
94
113
|
const deltaY = e.clientY - dragStartY.current;
|
|
95
114
|
const newScrollTop = Math.min(Math.max(scrollStartY.current + (deltaY / maxThumbMove) * maxScroll, 0), maxScroll);
|
|
96
115
|
containerRef.current.scrollTop = newScrollTop;
|
|
116
|
+
// *** No direct updateThumb here, the scroll event listener will trigger requestVisualUpdate ***
|
|
97
117
|
}
|
|
98
118
|
if (isDraggingX.current) {
|
|
99
119
|
const maxScrollX = scrollWidth - clientWidth;
|
|
100
|
-
const
|
|
120
|
+
const thumbCurrentWidth = thumbX.current?.clientWidth || 30; // Use actual thumb width
|
|
121
|
+
const maxThumbMoveX = clientWidth - thumbCurrentWidth;
|
|
101
122
|
const deltaX = e.clientX - dragStartX.current;
|
|
102
123
|
const newScrollLeft = Math.min(Math.max(scrollStartX.current + (deltaX / maxThumbMoveX) * maxScrollX, 0), maxScrollX);
|
|
103
124
|
containerRef.current.scrollLeft = newScrollLeft;
|
|
125
|
+
// *** No direct updateThumb here, the scroll event listener will trigger requestVisualUpdate ***
|
|
104
126
|
}
|
|
105
|
-
}, []);
|
|
127
|
+
}, []); // No dependencies needed if current values are always fresh
|
|
106
128
|
const handleDragEnd = () => {
|
|
107
129
|
isDraggingY.current = false;
|
|
108
130
|
isDraggingX.current = false;
|
|
109
131
|
document.body.style.userSelect = "";
|
|
110
132
|
if (rootRef.current)
|
|
111
133
|
rootRef.current?.classList.remove(`--scrolling`);
|
|
134
|
+
if (animationFrameId.current) {
|
|
135
|
+
cancelAnimationFrame(animationFrameId.current); // Clear any pending rAF
|
|
136
|
+
}
|
|
112
137
|
};
|
|
113
138
|
const scrollToTop = () => containerRef.current?.scrollTo({ top: 0, behavior: "smooth" });
|
|
114
139
|
const scrollToBottom = () => containerRef.current?.scrollTo({ top: containerRef.current.scrollHeight, behavior: "smooth" });
|
|
@@ -119,49 +144,69 @@ const useScrollbar = (speed, breakpoints = {}) => {
|
|
|
119
144
|
if (!container)
|
|
120
145
|
return;
|
|
121
146
|
const handleWheel = (e) => {
|
|
122
|
-
|
|
123
|
-
e.
|
|
147
|
+
// *** Passive listener means preventDefault is often not needed/effective here ***
|
|
148
|
+
// e.preventDefault();
|
|
149
|
+
// e.stopPropagation();
|
|
124
150
|
if (!containerRef.current)
|
|
125
151
|
return;
|
|
126
|
-
// Adjust scrollTop manually based on deltaY
|
|
127
152
|
const { scrollTop, scrollHeight, clientHeight, scrollLeft, scrollWidth, clientWidth } = containerRef.current;
|
|
153
|
+
let newScrollTop = scrollTop;
|
|
154
|
+
let newScrollLeft = scrollLeft;
|
|
155
|
+
let changed = false;
|
|
128
156
|
if (Math.abs(e.deltaY) > Math.abs(e.deltaX)) {
|
|
129
157
|
const maxScrollY = scrollHeight - clientHeight;
|
|
130
|
-
|
|
158
|
+
newScrollTop = scrollTop + e.deltaY * SCROLL_SPEED;
|
|
131
159
|
newScrollTop = Math.max(0, Math.min(newScrollTop, maxScrollY));
|
|
132
|
-
|
|
160
|
+
if (newScrollTop !== scrollTop) {
|
|
161
|
+
containerRef.current.scrollTop = newScrollTop;
|
|
162
|
+
changed = true;
|
|
163
|
+
}
|
|
133
164
|
}
|
|
134
|
-
|
|
165
|
+
else { // Prefer deltaX if it's larger or if deltaY is 0
|
|
135
166
|
const maxScrollX = scrollWidth - clientWidth;
|
|
136
|
-
|
|
167
|
+
newScrollLeft = scrollLeft + e.deltaX * SCROLL_SPEED;
|
|
137
168
|
newScrollLeft = Math.max(0, Math.min(newScrollLeft, maxScrollX));
|
|
138
|
-
|
|
169
|
+
if (newScrollLeft !== scrollLeft) {
|
|
170
|
+
containerRef.current.scrollLeft = newScrollLeft;
|
|
171
|
+
changed = true;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
// *** Only request update if scroll position actually changed ***
|
|
175
|
+
if (changed) {
|
|
176
|
+
requestVisualUpdate();
|
|
139
177
|
}
|
|
140
|
-
const scrollPercentY = (containerRef.current.scrollTop / (containerRef.current.scrollHeight - clientHeight)) * 100;
|
|
141
|
-
const scrollPercentX = (containerRef.current.scrollLeft / (containerRef.current.scrollWidth - clientWidth)) * 100;
|
|
142
|
-
postScroll(scrollPercentY);
|
|
143
|
-
postScroll(scrollPercentX);
|
|
144
178
|
};
|
|
145
|
-
window.addEventListener("resize",
|
|
146
|
-
container.addEventListener("scroll", handleScroll);
|
|
147
|
-
|
|
148
|
-
container.addEventListener("wheel", handleWheel, { passive: false });
|
|
179
|
+
window.addEventListener("resize", requestVisualUpdate); // Use requestVisualUpdate for resize
|
|
180
|
+
container.addEventListener("scroll", handleScroll, { passive: true }); // Make scroll passive if you don't preventDefault
|
|
181
|
+
container.addEventListener("wheel", handleWheel, { passive: true }); // Keep passive for wheel
|
|
149
182
|
document.addEventListener("mousemove", handleDragMove);
|
|
150
183
|
document.addEventListener("mouseup", handleDragEnd);
|
|
151
|
-
|
|
184
|
+
// Initial update
|
|
185
|
+
requestVisualUpdate(); // Use requestVisualUpdate for initial render
|
|
152
186
|
return () => {
|
|
153
|
-
window.removeEventListener("resize",
|
|
154
|
-
window.removeEventListener("wheel", handleWheel);
|
|
187
|
+
window.removeEventListener("resize", requestVisualUpdate);
|
|
155
188
|
container.removeEventListener("scroll", handleScroll);
|
|
189
|
+
container.removeEventListener("wheel", handleWheel); // Corrected: remove from container
|
|
156
190
|
document.removeEventListener("mousemove", handleDragMove);
|
|
157
191
|
document.removeEventListener("mouseup", handleDragEnd);
|
|
192
|
+
if (animationFrameId.current) {
|
|
193
|
+
cancelAnimationFrame(animationFrameId.current); // Clean up any pending rAF
|
|
194
|
+
}
|
|
158
195
|
};
|
|
159
|
-
}, [handleScroll, handleDragMove,
|
|
160
|
-
useMutationObserver
|
|
196
|
+
}, [handleScroll, handleDragMove, requestVisualUpdate, SCROLL_SPEED]); // Added SCROLL_SPEED to deps
|
|
197
|
+
// *** NEW: Hook useMutationObserver to call requestVisualUpdate ***
|
|
198
|
+
useMutationObserver(containerRef.current, requestVisualUpdate);
|
|
161
199
|
return {
|
|
162
|
-
rootRef,
|
|
163
|
-
|
|
164
|
-
|
|
200
|
+
rootRef,
|
|
201
|
+
containerRef,
|
|
202
|
+
thumbY,
|
|
203
|
+
thumbX,
|
|
204
|
+
scrollToTop,
|
|
205
|
+
scrollToBottom,
|
|
206
|
+
scrollToLeft,
|
|
207
|
+
scrollToRight,
|
|
208
|
+
onScrollY,
|
|
209
|
+
onScrollX,
|
|
165
210
|
};
|
|
166
211
|
};
|
|
167
212
|
export default useScrollbar;
|
package/dist/esm/types/enums.js
CHANGED
|
@@ -19,6 +19,8 @@ export var FORMVALIDATION_STYLE;
|
|
|
19
19
|
})(FORMVALIDATION_STYLE || (FORMVALIDATION_STYLE = {}));
|
|
20
20
|
export var FORMVALIDATION;
|
|
21
21
|
(function (FORMVALIDATION) {
|
|
22
|
+
FORMVALIDATION["IPV4"] = "IPV4";
|
|
23
|
+
FORMVALIDATION["IPV6"] = "IPV6";
|
|
22
24
|
FORMVALIDATION["Email"] = "EMAIL";
|
|
23
25
|
FORMVALIDATION["Uri"] = "URI";
|
|
24
26
|
FORMVALIDATION["Password"] = "PASSWORD";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ComponentPropsWithoutRef, ElementType } from "react";
|
|
2
2
|
import { DragOptions } from "../hooks";
|
|
3
|
-
import { SHIMMER, SORT, TRANSITIONS } from "./enums";
|
|
3
|
+
import { Position, SHIMMER, SORT, TRANSITIONS } from "./enums";
|
|
4
4
|
import { animationProps, Skeleton } from "./interfaces";
|
|
5
5
|
export type Deprecated<T, M extends string> = T & {
|
|
6
6
|
__deprecatedMessage?: M;
|
|
@@ -85,3 +85,4 @@ export type cssShortKeys = {
|
|
|
85
85
|
sy: string | number;
|
|
86
86
|
sz: string | number;
|
|
87
87
|
};
|
|
88
|
+
export type Direction = Position;
|