@spark-ui/hooks 17.2.3-beta.0 → 17.2.3-beta.1
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/use-combined-state/index.d.ts +1 -0
- package/dist/use-combined-state/useCombinedState.d.ts +10 -0
- package/dist/use-merge-refs/index.d.ts +1 -0
- package/dist/use-merge-refs/useMergeRefs.d.ts +4 -0
- package/dist/use-mounted-state/index.d.ts +1 -0
- package/dist/use-mounted-state/useMountedState.d.ts +1 -0
- package/dist/use-scroll-overflow/index.d.ts +2 -0
- package/dist/use-scroll-overflow/useScrollOverflow.d.ts +19 -0
- package/dist/use-sortable-list/index.d.ts +2 -0
- package/dist/use-sortable-list/useSortableList.d.ts +95 -0
- package/package.json +3 -3
- package/vite.config.ts +20 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useCombinedState } from './useCombinedState';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This hook must be used when a component has both a controlled and uncontrolled mode.
|
|
3
|
+
* It will take care of updating the state value when a controlled mode (prop) is updated.
|
|
4
|
+
*/
|
|
5
|
+
export declare function useCombinedState<T>(controlledValue?: T, defaultValue?: T, onChange?: (nextValue: T) => void): [
|
|
6
|
+
T | undefined,
|
|
7
|
+
(newValue: T, forceFlag?: (prev: T, next: T) => boolean) => void,
|
|
8
|
+
boolean,
|
|
9
|
+
T | undefined
|
|
10
|
+
];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useMergeRefs, assignRef, mergeRefs } from './useMergeRefs';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Ref, RefCallback } from 'react';
|
|
2
|
+
export declare function assignRef<T>(ref: Ref<T> | null | undefined, value: T): void;
|
|
3
|
+
export declare function mergeRefs<T>(...refs: (Ref<T> | undefined)[]): RefCallback<T>;
|
|
4
|
+
export declare function useMergeRefs<T>(...refs: (Ref<T> | undefined)[]): RefCallback<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useMountedState } from './useMountedState';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useMountedState(): () => boolean;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
export interface ScrollOverflow {
|
|
3
|
+
top: number;
|
|
4
|
+
bottom: number;
|
|
5
|
+
left: number;
|
|
6
|
+
right: number;
|
|
7
|
+
}
|
|
8
|
+
export interface UseScrollOverflowReturn {
|
|
9
|
+
overflow: ScrollOverflow;
|
|
10
|
+
refresh: () => void;
|
|
11
|
+
}
|
|
12
|
+
export declare function useScrollOverflow(scrollRef: RefObject<HTMLElement | null>,
|
|
13
|
+
/**
|
|
14
|
+
* Tolerance threshold for floating-point precision issues.
|
|
15
|
+
* Values below this threshold are considered as "no overflow" to handle sub-pixel rendering artifacts.
|
|
16
|
+
*/
|
|
17
|
+
{ precisionTreshold }?: {
|
|
18
|
+
precisionTreshold?: number;
|
|
19
|
+
}): UseScrollOverflowReturn;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Ref } from 'react';
|
|
2
|
+
export interface UseSortableListOptions<T> {
|
|
3
|
+
/**
|
|
4
|
+
* The list of items to be sortable
|
|
5
|
+
*/
|
|
6
|
+
items: T[];
|
|
7
|
+
/**
|
|
8
|
+
* Callback called when items are reordered
|
|
9
|
+
* @param newItems - The reordered items array
|
|
10
|
+
*/
|
|
11
|
+
onReorder: (newItems: T[]) => void;
|
|
12
|
+
/**
|
|
13
|
+
* Function to generate a unique key for each item
|
|
14
|
+
* @param item - The item to generate a key for
|
|
15
|
+
* @returns A unique string key for the item
|
|
16
|
+
*/
|
|
17
|
+
getItemKey: (item: T) => string;
|
|
18
|
+
}
|
|
19
|
+
export interface SortableItemProps<TElement extends HTMLElement = HTMLElement> {
|
|
20
|
+
/**
|
|
21
|
+
* Whether the item is draggable
|
|
22
|
+
*/
|
|
23
|
+
draggable: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Handler for drag start event
|
|
26
|
+
*/
|
|
27
|
+
onDragStart: (e: React.DragEvent) => void;
|
|
28
|
+
/**
|
|
29
|
+
* Handler for drag enter event
|
|
30
|
+
*/
|
|
31
|
+
onDragEnter: (e: React.DragEvent) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Handler for drag over event
|
|
34
|
+
*/
|
|
35
|
+
onDragOver: (e: React.DragEvent) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Handler for drag leave event
|
|
38
|
+
*/
|
|
39
|
+
onDragLeave: (e: React.DragEvent) => void;
|
|
40
|
+
/**
|
|
41
|
+
* Handler for drag end event
|
|
42
|
+
*/
|
|
43
|
+
onDragEnd: (e: React.DragEvent) => void;
|
|
44
|
+
/**
|
|
45
|
+
* Handler for drop event
|
|
46
|
+
*/
|
|
47
|
+
onDrop: (e: React.DragEvent) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Handler for keyboard navigation
|
|
50
|
+
*/
|
|
51
|
+
onKeyDown: (e: React.KeyboardEvent) => void;
|
|
52
|
+
/**
|
|
53
|
+
* Tab index for keyboard navigation
|
|
54
|
+
*/
|
|
55
|
+
tabIndex: number;
|
|
56
|
+
/**
|
|
57
|
+
* Ref callback to attach to the item element
|
|
58
|
+
*/
|
|
59
|
+
ref: Ref<TElement>;
|
|
60
|
+
}
|
|
61
|
+
export interface UseSortableListReturn<T> {
|
|
62
|
+
/**
|
|
63
|
+
* Get props to spread on a sortable item element (includes ref)
|
|
64
|
+
* @param item - The item to get props for
|
|
65
|
+
* @param index - The current index of the item in the list
|
|
66
|
+
* @returns Props object to spread on the element
|
|
67
|
+
*/
|
|
68
|
+
getItemProps: <TElement extends HTMLElement = HTMLElement>(item: T, index: number) => SortableItemProps<TElement>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Hook to make a list of items sortable via drag and drop and keyboard navigation
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```tsx
|
|
75
|
+
* const { getItemProps } = useSortableList({
|
|
76
|
+
* items: myItems,
|
|
77
|
+
* onReorder: setMyItems,
|
|
78
|
+
* getItemKey: (item) => item.id
|
|
79
|
+
* })
|
|
80
|
+
*
|
|
81
|
+
* return (
|
|
82
|
+
* <ul>
|
|
83
|
+
* {myItems.map((item, index) => (
|
|
84
|
+
* <li
|
|
85
|
+
* key={getItemKey(item)}
|
|
86
|
+
* {...getItemProps(item, index)}
|
|
87
|
+
* >
|
|
88
|
+
* {item.name}
|
|
89
|
+
* </li>
|
|
90
|
+
* ))}
|
|
91
|
+
* </ul>
|
|
92
|
+
* )
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export declare function useSortableList<T>({ items, onReorder, getItemKey, }: UseSortableListOptions<T>): UseSortableListReturn<T>;
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spark-ui/hooks",
|
|
3
|
-
"version": "17.2.3-beta.
|
|
3
|
+
"version": "17.2.3-beta.1",
|
|
4
4
|
"description": "Common hooks for Spark UI",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./*": {
|
|
7
|
-
"types": "./dist
|
|
7
|
+
"types": "./dist/*/index.d.ts",
|
|
8
8
|
"import": "./dist/*/index.mjs",
|
|
9
9
|
"require": "./dist/*/index.js"
|
|
10
10
|
}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"typesVersions": {
|
|
13
13
|
"*": {
|
|
14
14
|
"*": [
|
|
15
|
-
"./dist
|
|
15
|
+
"./dist/*/index.d.ts"
|
|
16
16
|
]
|
|
17
17
|
}
|
|
18
18
|
},
|
package/vite.config.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readdirSync } from 'node:fs'
|
|
1
|
+
import { cpSync, existsSync, readdirSync, rmSync } from 'node:fs'
|
|
2
2
|
import { join } from 'node:path'
|
|
3
3
|
|
|
4
4
|
import { defineConfig } from 'vite'
|
|
@@ -39,6 +39,25 @@ export default defineConfig({
|
|
|
39
39
|
rollupTypes: false,
|
|
40
40
|
insertTypesEntry: false,
|
|
41
41
|
copyDtsFiles: false,
|
|
42
|
+
afterBuild: () => {
|
|
43
|
+
const distSrc = join(__dirname, 'dist/src')
|
|
44
|
+
if (!existsSync(distSrc)) return
|
|
45
|
+
|
|
46
|
+
for (const entry of readdirSync(distSrc, { withFileTypes: true })) {
|
|
47
|
+
if (!entry.isDirectory()) continue
|
|
48
|
+
|
|
49
|
+
const fromDir = join(distSrc, entry.name)
|
|
50
|
+
const toDir = join(__dirname, 'dist', entry.name)
|
|
51
|
+
|
|
52
|
+
for (const file of readdirSync(fromDir)) {
|
|
53
|
+
if (file.endsWith('.d.ts')) {
|
|
54
|
+
cpSync(join(fromDir, file), join(toDir, file), { force: true })
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
rmSync(distSrc, { recursive: true })
|
|
60
|
+
},
|
|
42
61
|
}),
|
|
43
62
|
],
|
|
44
63
|
})
|