@reactuses/core 1.0.1 → 1.0.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/LICENSE +24 -24
- package/README.md +81 -73
- package/index.cjs +152 -0
- package/index.d.ts +546 -445
- package/index.mjs +151 -1
- package/package.json +2 -2
package/index.mjs
CHANGED
|
@@ -2144,4 +2144,154 @@ function useActiveElement() {
|
|
|
2144
2144
|
return active;
|
|
2145
2145
|
}
|
|
2146
2146
|
|
|
2147
|
-
|
|
2147
|
+
function useDraggable(target, options = {}) {
|
|
2148
|
+
var _a, _b;
|
|
2149
|
+
const draggingElement = getTargetElement(options.draggingElement, window);
|
|
2150
|
+
const draggingHandle = getTargetElement((_a = options.handle) != null ? _a : target);
|
|
2151
|
+
const [position, setPositon] = useState(
|
|
2152
|
+
(_b = options.initialValue) != null ? _b : { x: 0, y: 0 }
|
|
2153
|
+
);
|
|
2154
|
+
const [pressedDelta, setPressedDelta] = useState();
|
|
2155
|
+
const filterEvent = (e) => {
|
|
2156
|
+
if (options.pointerTypes) {
|
|
2157
|
+
return options.pointerTypes.includes(e.pointerType);
|
|
2158
|
+
}
|
|
2159
|
+
return true;
|
|
2160
|
+
};
|
|
2161
|
+
const handleEvent = (e) => {
|
|
2162
|
+
if (options.preventDefault) {
|
|
2163
|
+
e.preventDefault();
|
|
2164
|
+
}
|
|
2165
|
+
if (options.stopPropagation) {
|
|
2166
|
+
e.stopPropagation();
|
|
2167
|
+
}
|
|
2168
|
+
};
|
|
2169
|
+
const start = (e) => {
|
|
2170
|
+
var _a2;
|
|
2171
|
+
const element = getTargetElement(target);
|
|
2172
|
+
if (!filterEvent(e) || !element) {
|
|
2173
|
+
return;
|
|
2174
|
+
}
|
|
2175
|
+
if (options.exact && e.target !== element) {
|
|
2176
|
+
return;
|
|
2177
|
+
}
|
|
2178
|
+
const rect = element.getBoundingClientRect();
|
|
2179
|
+
const pos = {
|
|
2180
|
+
x: e.pageX - rect.left,
|
|
2181
|
+
y: e.pageY - rect.top
|
|
2182
|
+
};
|
|
2183
|
+
if (((_a2 = options.onStart) == null ? void 0 : _a2.call(options, pos, e)) === false) {
|
|
2184
|
+
return;
|
|
2185
|
+
}
|
|
2186
|
+
setPressedDelta(pos);
|
|
2187
|
+
handleEvent(e);
|
|
2188
|
+
};
|
|
2189
|
+
const move = (e) => {
|
|
2190
|
+
var _a2;
|
|
2191
|
+
if (!filterEvent(e)) {
|
|
2192
|
+
return;
|
|
2193
|
+
}
|
|
2194
|
+
if (!pressedDelta) {
|
|
2195
|
+
return;
|
|
2196
|
+
}
|
|
2197
|
+
setPositon({
|
|
2198
|
+
x: e.pageX - pressedDelta.x,
|
|
2199
|
+
y: e.pageY - pressedDelta.y
|
|
2200
|
+
});
|
|
2201
|
+
(_a2 = options.onMove) == null ? void 0 : _a2.call(options, position, e);
|
|
2202
|
+
handleEvent(e);
|
|
2203
|
+
};
|
|
2204
|
+
const end = (e) => {
|
|
2205
|
+
var _a2;
|
|
2206
|
+
if (!filterEvent(e)) {
|
|
2207
|
+
return;
|
|
2208
|
+
}
|
|
2209
|
+
if (!pressedDelta) {
|
|
2210
|
+
return;
|
|
2211
|
+
}
|
|
2212
|
+
setPressedDelta(void 0);
|
|
2213
|
+
(_a2 = options.onEnd) == null ? void 0 : _a2.call(options, position, e);
|
|
2214
|
+
handleEvent(e);
|
|
2215
|
+
};
|
|
2216
|
+
useEventListener("pointerdown", start, draggingHandle, true);
|
|
2217
|
+
useEventListener("pointermove", move, draggingElement, true);
|
|
2218
|
+
useEventListener("pointerup", end, draggingElement, true);
|
|
2219
|
+
return [position.x, position.y, !!pressedDelta];
|
|
2220
|
+
}
|
|
2221
|
+
|
|
2222
|
+
function useElementBounding(target, options = {}) {
|
|
2223
|
+
const {
|
|
2224
|
+
reset = true,
|
|
2225
|
+
windowResize = true,
|
|
2226
|
+
windowScroll = true,
|
|
2227
|
+
immediate = true
|
|
2228
|
+
} = options;
|
|
2229
|
+
const [height, setHeight] = useState(0);
|
|
2230
|
+
const [bottom, setBottom] = useState(0);
|
|
2231
|
+
const [left, setLeft] = useState(0);
|
|
2232
|
+
const [right, setRight] = useState(0);
|
|
2233
|
+
const [top, setTop] = useState(0);
|
|
2234
|
+
const [width, setWidth] = useState(0);
|
|
2235
|
+
const [x, setX] = useState(0);
|
|
2236
|
+
const [y, setY] = useState(0);
|
|
2237
|
+
const update = useEvent(() => {
|
|
2238
|
+
const element = getTargetElement(target);
|
|
2239
|
+
if (!element) {
|
|
2240
|
+
if (reset) {
|
|
2241
|
+
setHeight(0);
|
|
2242
|
+
setBottom(0);
|
|
2243
|
+
setLeft(0);
|
|
2244
|
+
setRight(0);
|
|
2245
|
+
setTop(0);
|
|
2246
|
+
setWidth(0);
|
|
2247
|
+
setX(0);
|
|
2248
|
+
setY(0);
|
|
2249
|
+
}
|
|
2250
|
+
return;
|
|
2251
|
+
}
|
|
2252
|
+
const rect = element.getBoundingClientRect();
|
|
2253
|
+
setHeight(rect.height);
|
|
2254
|
+
setBottom(rect.bottom);
|
|
2255
|
+
setLeft(rect.left);
|
|
2256
|
+
setRight(rect.right);
|
|
2257
|
+
setTop(rect.top);
|
|
2258
|
+
setWidth(rect.width);
|
|
2259
|
+
setX(rect.x);
|
|
2260
|
+
setY(rect.y);
|
|
2261
|
+
});
|
|
2262
|
+
useResizeObserver(target, update);
|
|
2263
|
+
useEffect(() => {
|
|
2264
|
+
if (immediate) {
|
|
2265
|
+
update();
|
|
2266
|
+
}
|
|
2267
|
+
}, [immediate, update]);
|
|
2268
|
+
useEffect(() => {
|
|
2269
|
+
if (windowScroll) {
|
|
2270
|
+
window.addEventListener("scroll", update, { passive: true });
|
|
2271
|
+
}
|
|
2272
|
+
if (windowResize) {
|
|
2273
|
+
window.addEventListener("resize", update, { passive: true });
|
|
2274
|
+
}
|
|
2275
|
+
return () => {
|
|
2276
|
+
if (windowScroll) {
|
|
2277
|
+
window.removeEventListener("scroll", update);
|
|
2278
|
+
}
|
|
2279
|
+
if (windowResize) {
|
|
2280
|
+
window.removeEventListener("resize", update);
|
|
2281
|
+
}
|
|
2282
|
+
};
|
|
2283
|
+
}, [update, windowResize, windowScroll]);
|
|
2284
|
+
return {
|
|
2285
|
+
height,
|
|
2286
|
+
bottom,
|
|
2287
|
+
left,
|
|
2288
|
+
right,
|
|
2289
|
+
top,
|
|
2290
|
+
width,
|
|
2291
|
+
x,
|
|
2292
|
+
y,
|
|
2293
|
+
update
|
|
2294
|
+
};
|
|
2295
|
+
}
|
|
2296
|
+
|
|
2297
|
+
export { useActiveElement, useCounter, useCustomCompareEffect, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDocumentVisibility, useDraggable, useDropZone, useElementBounding, useElementSize, useEvent, useEventEmitter, useEventListener, useFavicon, useFileDialog, useFirstMountState, useFps$1 as useFps, useFullscreen, useGeolocation, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLongPress, useMarkdown, useMediaDevices$1 as useMediaDevices, useMediaQuery, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, useOnline, useOrientation, usePageLeave, usePermission, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePrevious, useRafFn, useRafState, useResizeObserver, useScriptTag, useScroll, useScrollLock, useSessionStorage, useTextDirection, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useTitle, useToggle, useUnmount, useUpdate, useUpdateEffect, useUpdateLayoutEffect, useVirtualList };
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactuses/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"main": "./index.cjs",
|
|
5
5
|
"module": "./index.mjs",
|
|
6
6
|
"types": "./index.d.ts",
|
|
7
7
|
"sideEffects": false,
|
|
8
8
|
"license": "Unlicense",
|
|
9
|
-
"homepage": "https://
|
|
9
|
+
"homepage": "https://www.reactuse.com/",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "https://github.com/childrentime/reactuse",
|