deepsea-components 5.16.3 → 5.16.5
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/components/AutoFit.cjs +20 -15
- package/dist/components/AutoFit.js +20 -15
- package/dist/components/AutoScroll.cjs +12 -9
- package/dist/components/AutoScroll.js +12 -9
- package/dist/components/AutoSizeTextarea.cjs +81 -23
- package/dist/components/AutoSizeTextarea.js +81 -23
- package/dist/components/CircleText.cjs +120 -24
- package/dist/components/CircleText.js +120 -24
- package/dist/components/CopyButton.cjs +8 -2
- package/dist/components/CopyButton.js +8 -2
- package/dist/components/DraggableGrid.cjs +155 -104
- package/dist/components/DraggableGrid.d.ts +31 -27
- package/dist/components/DraggableGrid.js +155 -104
- package/dist/components/Echart.cjs +95 -21
- package/dist/components/Echart.js +95 -21
- package/dist/components/Flow.cjs +10 -10
- package/dist/components/Flow.js +10 -10
- package/dist/components/FormLabel.cjs +92 -27
- package/dist/components/FormLabel.js +92 -27
- package/dist/components/HlsPlayer.cjs +65 -24
- package/dist/components/HlsPlayer.js +65 -24
- package/dist/components/IconFileType.cjs +14 -4
- package/dist/components/IconFileType.js +14 -4
- package/dist/components/InfiniteScroll.cjs +17 -10
- package/dist/components/InfiniteScroll.js +17 -10
- package/dist/components/InputFile.cjs +5 -5
- package/dist/components/InputFile.js +5 -5
- package/dist/components/InputFileButton.cjs +14 -13
- package/dist/components/InputFileButton.js +14 -13
- package/dist/components/ReadSheet.cjs +32 -7
- package/dist/components/ReadSheet.js +32 -7
- package/dist/components/Ring.cjs +48 -10
- package/dist/components/Ring.js +48 -10
- package/dist/components/Scroll.cjs +10 -3
- package/dist/components/Scroll.js +10 -3
- package/dist/components/ScrollMask.cjs +97 -11
- package/dist/components/ScrollMask.js +97 -11
- package/dist/components/SectionRing.cjs +60 -15
- package/dist/components/SectionRing.js +60 -15
- package/dist/components/TransitionBox.cjs +120 -30
- package/dist/components/TransitionBox.js +120 -30
- package/dist/components/TransitionNum.cjs +8 -8
- package/dist/components/TransitionNum.js +8 -8
- package/dist/components/Trapezium.cjs +68 -9
- package/dist/components/Trapezium.js +68 -9
- package/dist/components/Unify.cjs +79 -19
- package/dist/components/Unify.js +79 -19
- package/dist/components/WriteSheet.cjs +1 -1
- package/dist/components/WriteSheet.js +1 -1
- package/package.json +1 -1
- package/src/components/DraggableGrid.tsx +67 -51
|
@@ -4,6 +4,10 @@ import { DragMoveEvent, DragMoveEvents, useDragMove } from "soda-hooks"
|
|
|
4
4
|
|
|
5
5
|
import styles from "./DraggableGrid.module.css"
|
|
6
6
|
|
|
7
|
+
export type MustBeReactNode<T> = false extends (T extends ReactNode ? true : false) ? false : true
|
|
8
|
+
|
|
9
|
+
export type MustBeReactKey<T> = false extends (T extends Key ? true : false) ? false : true
|
|
10
|
+
|
|
7
11
|
export type DraggableGridClassName = string | ((status: ContainerStatus) => string)
|
|
8
12
|
|
|
9
13
|
export type DraggableGridItemClassName = string | ((status: DraggableGridItemStatus) => string)
|
|
@@ -30,10 +34,10 @@ export interface DraggableGridItemStatus {
|
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
/** 元素的 key 到次序的映射 */
|
|
33
|
-
export type DraggableGridKeyToOrder = Map<
|
|
37
|
+
export type DraggableGridKeyToOrder<K extends Key> = Map<K, number>
|
|
34
38
|
|
|
35
39
|
/** 次序到元素的 key 的映射 */
|
|
36
|
-
export type DraggableGridOrderToKey = Map<number,
|
|
40
|
+
export type DraggableGridOrderToKey<K extends Key> = Map<number, K>
|
|
37
41
|
|
|
38
42
|
function isTheSameArray<T>(a: T[], b: T[]) {
|
|
39
43
|
if (a.length !== b.length) return false
|
|
@@ -50,15 +54,15 @@ function isTheSameIterable<T>(a: Iterable<T>, b: Iterable<T>) {
|
|
|
50
54
|
return aSet.difference(bSet).size === 0
|
|
51
55
|
}
|
|
52
56
|
|
|
53
|
-
interface GetOrderMapParams {
|
|
54
|
-
prev?: DraggableGridKeyToOrder
|
|
57
|
+
interface GetOrderMapParams<K extends Key> {
|
|
58
|
+
prev?: DraggableGridKeyToOrder<K>
|
|
55
59
|
orders: number[]
|
|
56
|
-
keys:
|
|
60
|
+
keys: K[]
|
|
57
61
|
}
|
|
58
62
|
|
|
59
|
-
function getOrderMap({ prev, orders, keys }: GetOrderMapParams) {
|
|
63
|
+
function getOrderMap<K extends Key>({ prev, orders, keys }: GetOrderMapParams<K>) {
|
|
60
64
|
const orderSet = new Set(orders)
|
|
61
|
-
const orderMap = new Map<
|
|
65
|
+
const orderMap = new Map<K, number>()
|
|
62
66
|
const newKeys = keys.filter(key => {
|
|
63
67
|
if (!prev) return true
|
|
64
68
|
if (prev.has(key)) {
|
|
@@ -97,11 +101,41 @@ function getPosition({ order, columns, gapX, gapY, itemWidth, itemHeight }: GetP
|
|
|
97
101
|
}
|
|
98
102
|
}
|
|
99
103
|
|
|
100
|
-
function getOrderToKey(keyToOrder: DraggableGridKeyToOrder) {
|
|
104
|
+
function getOrderToKey<K extends Key>(keyToOrder: DraggableGridKeyToOrder<K>) {
|
|
101
105
|
return new Map(Array.from(keyToOrder.entries()).map(([key, order]) => [order, key]))
|
|
102
106
|
}
|
|
103
107
|
|
|
104
|
-
export type
|
|
108
|
+
export type DraggableGridPropsCore<T, K extends Key = T extends Key ? T : never> = {
|
|
109
|
+
/** 数据源 */
|
|
110
|
+
items?: T[]
|
|
111
|
+
/** 元素的 key 到次序的映射 */
|
|
112
|
+
orderMap?: DraggableGridKeyToOrder<K>
|
|
113
|
+
/** 次序变化时回调 */
|
|
114
|
+
onOrderMapChange?: (orderMap: DraggableGridKeyToOrder<K>) => void
|
|
115
|
+
/** 禁用的元素 */
|
|
116
|
+
isItemDisabled?: K[] | ((item: T, key: K) => boolean)
|
|
117
|
+
/** 触发移动的元素 */
|
|
118
|
+
handle?: string | HTMLElement | ((item: T, key: K, element: HTMLDivElement) => HTMLElement | undefined | null) | undefined | null
|
|
119
|
+
} & (MustBeReactNode<T> extends true
|
|
120
|
+
? {
|
|
121
|
+
/** 渲染函数,当 T 为 ReactNode 时,render 为可选 */
|
|
122
|
+
render?: (item: T, status: DraggableGridItemStatus) => ReactNode
|
|
123
|
+
}
|
|
124
|
+
: {
|
|
125
|
+
/** 渲染函数,当 T 为 ReactNode 时,render 为可选 */
|
|
126
|
+
render: (item: T, status: DraggableGridItemStatus) => ReactNode
|
|
127
|
+
}) &
|
|
128
|
+
(MustBeReactKey<T> extends true
|
|
129
|
+
? {
|
|
130
|
+
/** 获取 key 的函数,当 T 为 Key 时,keyExtractor 为可选 */
|
|
131
|
+
keyExtractor?: (item: T) => K
|
|
132
|
+
}
|
|
133
|
+
: {
|
|
134
|
+
/** 获取 key 的函数,当 T 为 Key 时,keyExtractor 为可选 */
|
|
135
|
+
keyExtractor: (item: T) => K
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
export type DraggableGridProps<T, K extends Key = T extends Key ? T : never> = Omit<ComponentProps<"div">, "className" | "children"> &
|
|
105
139
|
DragMoveEvents<HTMLDivElement> & {
|
|
106
140
|
/** 类名 */
|
|
107
141
|
className?: DraggableGridClassName
|
|
@@ -109,8 +143,7 @@ export type DraggableGridProps<T> = Omit<ComponentProps<"div">, "className" | "c
|
|
|
109
143
|
classNames?: DraggableGridClassNames
|
|
110
144
|
/** 样式 */
|
|
111
145
|
style?: DraggableGridStyle
|
|
112
|
-
|
|
113
|
-
items?: T[]
|
|
146
|
+
|
|
114
147
|
/** 是否禁用拖拽 */
|
|
115
148
|
disabled?: boolean
|
|
116
149
|
/** 列数 */
|
|
@@ -136,45 +169,28 @@ export type DraggableGridProps<T> = Omit<ComponentProps<"div">, "className" | "c
|
|
|
136
169
|
itemWidth: number
|
|
137
170
|
/** 元素高度 */
|
|
138
171
|
itemHeight: number
|
|
139
|
-
/** 元素的 key 到次序的映射 */
|
|
140
|
-
orderMap?: DraggableGridKeyToOrder
|
|
141
|
-
/** 次序变化时回调 */
|
|
142
|
-
onOrderMapChange?: (orderMap: DraggableGridKeyToOrder) => void
|
|
143
|
-
/** 禁用的元素 */
|
|
144
|
-
isItemDisabled?: Key[] | ((item: T, key: Key) => boolean)
|
|
145
172
|
/** 禁用的次序 */
|
|
146
173
|
isOrderDisabled?: number[] | ((order: number) => boolean)
|
|
147
174
|
/** 次序的优先级,可以通过此函数调整元素的优先放置的方向,左上,右上,左下,右下,中心,顺时针,逆时针等等 */
|
|
148
175
|
orderPriority?: (a: number, b: number) => number
|
|
149
|
-
|
|
150
|
-
handle?: string | HTMLElement | ((item: T, key: Key, element: HTMLDivElement) => HTMLElement | undefined | null) | undefined | null
|
|
151
|
-
} & (T extends ReactNode
|
|
152
|
-
? {
|
|
153
|
-
/** 渲染函数,当 T 为 ReactNode 时,render 为可选 */
|
|
154
|
-
render?: (item: T, status: DraggableGridItemStatus) => ReactNode
|
|
155
|
-
}
|
|
156
|
-
: {
|
|
157
|
-
/** 渲染函数,当 T 为 ReactNode 时,render 为可选 */
|
|
158
|
-
render: (item: T, status: DraggableGridItemStatus) => ReactNode
|
|
159
|
-
}) &
|
|
160
|
-
(T extends Key
|
|
161
|
-
? {
|
|
162
|
-
/** 获取 key 的函数,当 T 为 Key 时,keyExtractor 为可选 */
|
|
163
|
-
keyExtractor?: (item: T) => Key
|
|
164
|
-
}
|
|
165
|
-
: {
|
|
166
|
-
/** 获取 key 的函数,当 T 为 Key 时,keyExtractor 为可选 */
|
|
167
|
-
keyExtractor: (item: T) => Key
|
|
168
|
-
})
|
|
176
|
+
} & DraggableGridPropsCore<T, K>
|
|
169
177
|
|
|
170
|
-
interface DraggableGridItemProps<T> extends ComponentProps<"div">, DragMoveEvents<HTMLDivElement> {
|
|
178
|
+
interface DraggableGridItemProps<T, K extends Key = T extends Key ? T : never> extends ComponentProps<"div">, DragMoveEvents<HTMLDivElement> {
|
|
171
179
|
item: T
|
|
172
|
-
itemKey:
|
|
180
|
+
itemKey: K
|
|
173
181
|
/** 触发移动的元素 */
|
|
174
|
-
handle?: string | HTMLElement | ((item: T, key:
|
|
182
|
+
handle?: string | HTMLElement | ((item: T, key: K, element: HTMLDivElement) => HTMLElement | undefined | null) | undefined | null
|
|
175
183
|
}
|
|
176
184
|
|
|
177
|
-
function DraggableGridItem<T
|
|
185
|
+
function DraggableGridItem<T, K extends Key = T extends Key ? T : never>({
|
|
186
|
+
item,
|
|
187
|
+
itemKey,
|
|
188
|
+
handle,
|
|
189
|
+
onDragMoveStart,
|
|
190
|
+
onDragMove,
|
|
191
|
+
onDragMoveEnd,
|
|
192
|
+
...rest
|
|
193
|
+
}: DraggableGridItemProps<T, K>) {
|
|
178
194
|
const element = useRef<HTMLDivElement>(null)
|
|
179
195
|
|
|
180
196
|
useDragMove({
|
|
@@ -195,8 +211,8 @@ function DraggableGridItem<T>({ item, itemKey, handle, onDragMoveStart, onDragMo
|
|
|
195
211
|
return <div ref={element} {...rest} />
|
|
196
212
|
}
|
|
197
213
|
|
|
198
|
-
interface DraggingItem {
|
|
199
|
-
key:
|
|
214
|
+
interface DraggingItem<K extends Key> {
|
|
215
|
+
key: K
|
|
200
216
|
startX: number
|
|
201
217
|
startY: number
|
|
202
218
|
deltaX: number
|
|
@@ -208,10 +224,10 @@ interface DraggingItem {
|
|
|
208
224
|
gapY: number
|
|
209
225
|
itemWidth: number
|
|
210
226
|
itemHeight: number
|
|
211
|
-
keyToOrder: DraggableGridKeyToOrder
|
|
227
|
+
keyToOrder: DraggableGridKeyToOrder<K>
|
|
212
228
|
}
|
|
213
229
|
|
|
214
|
-
export function DraggableGrid<T>({
|
|
230
|
+
export function DraggableGrid<T, K extends Key = T extends Key ? T : never>({
|
|
215
231
|
className,
|
|
216
232
|
classNames,
|
|
217
233
|
style,
|
|
@@ -236,11 +252,11 @@ export function DraggableGrid<T>({
|
|
|
236
252
|
onDragMove: _onDragMove,
|
|
237
253
|
onDragMoveEnd: _onDragMoveEnd,
|
|
238
254
|
...rest
|
|
239
|
-
}: DraggableGridProps<T>) {
|
|
255
|
+
}: DraggableGridProps<T, K>) {
|
|
240
256
|
const keyToItem = useMemo(() => {
|
|
241
|
-
const keyToItem = new Map<
|
|
257
|
+
const keyToItem = new Map<K, T>()
|
|
242
258
|
items.forEach(item => {
|
|
243
|
-
const key = keyExtractor ? keyExtractor(item) : (item as
|
|
259
|
+
const key = keyExtractor ? keyExtractor(item) : (item as unknown as K)
|
|
244
260
|
keyToItem.set(key, item)
|
|
245
261
|
})
|
|
246
262
|
return keyToItem
|
|
@@ -269,7 +285,7 @@ export function DraggableGrid<T>({
|
|
|
269
285
|
})
|
|
270
286
|
|
|
271
287
|
/** 拖拽中的元素 */
|
|
272
|
-
const [dragging, setDragging] = useState<DraggingItem | undefined>(undefined)
|
|
288
|
+
const [dragging, setDragging] = useState<DraggingItem<K> | undefined>(undefined)
|
|
273
289
|
|
|
274
290
|
const { current: cache } = useRef({
|
|
275
291
|
orders,
|
|
@@ -321,7 +337,7 @@ export function DraggableGrid<T>({
|
|
|
321
337
|
else onOrderMapChange?.(keyToOrder)
|
|
322
338
|
}, [orderMap, keyToOrder, onOrderMapChange])
|
|
323
339
|
|
|
324
|
-
function onDragMoveStart(key:
|
|
340
|
+
function onDragMoveStart(key: K, event: DragMoveEvent<HTMLDivElement>) {
|
|
325
341
|
_onDragMoveStart?.(event)
|
|
326
342
|
const position = getPosition({ order: keyToOrder.get(key)!, columns, gapX, gapY, itemWidth, itemHeight })
|
|
327
343
|
recent.current = key
|
|
@@ -423,7 +439,7 @@ export function DraggableGrid<T>({
|
|
|
423
439
|
setDragging(undefined)
|
|
424
440
|
}
|
|
425
441
|
|
|
426
|
-
function isItemDisabled(key:
|
|
442
|
+
function isItemDisabled(key: K) {
|
|
427
443
|
if (!_isItemDisabled) return false
|
|
428
444
|
if (Array.isArray(_isItemDisabled)) return _isItemDisabled.includes(key)
|
|
429
445
|
return _isItemDisabled(keyToItem.get(key)!, key)
|