deepsea-components 5.16.2 → 5.16.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.
|
@@ -83,10 +83,10 @@ function getOrderToKey(keyToOrder) {
|
|
|
83
83
|
key
|
|
84
84
|
]));
|
|
85
85
|
}
|
|
86
|
-
|
|
86
|
+
function DraggableGridItem({ item, itemKey, handle, onDragMoveStart, onDragMove, onDragMoveEnd, ...rest }) {
|
|
87
87
|
const element = (0, external_react_namespaceObject.useRef)(null);
|
|
88
88
|
(0, external_soda_hooks_namespaceObject.useDragMove)({
|
|
89
|
-
element,
|
|
89
|
+
element: (0, external_deepsea_tools_namespaceObject.isNullable)(handle) ? element : ()=>element.current && ("string" == typeof handle ? element.current.querySelector(handle) : "function" == typeof handle ? handle(item, itemKey, element.current) : handle),
|
|
90
90
|
onDragMoveStart,
|
|
91
91
|
onDragMove,
|
|
92
92
|
onDragMoveEnd
|
|
@@ -95,8 +95,8 @@ const DraggableGridItem = ({ onDragMoveStart, onDragMove, onDragMoveEnd, ...rest
|
|
|
95
95
|
ref: element,
|
|
96
96
|
...rest
|
|
97
97
|
});
|
|
98
|
-
}
|
|
99
|
-
function DraggableGrid({ className, classNames, style, items = [], disabled, columns, rows, gap = 0, gapX = gap, gapY = gap, itemWidth, itemHeight, orderMap, onOrderMapChange, render, keyExtractor, isItemDisabled: _isItemDisabled, isOrderDisabled, orderPriority, ...rest }) {
|
|
98
|
+
}
|
|
99
|
+
function DraggableGrid({ className, classNames, style, items = [], disabled, columns, rows, gap = 0, gapX = gap, gapY = gap, itemWidth, itemHeight, orderMap, onOrderMapChange, render, keyExtractor, isItemDisabled: _isItemDisabled, isOrderDisabled, orderPriority, handle, onDragMoveStart: _onDragMoveStart, onDragMove: _onDragMove, onDragMoveEnd: _onDragMoveEnd, ...rest }) {
|
|
100
100
|
const keyToItem = (0, external_react_namespaceObject.useMemo)(()=>{
|
|
101
101
|
const keyToItem = new Map();
|
|
102
102
|
items.forEach((item)=>{
|
|
@@ -190,6 +190,7 @@ function DraggableGrid({ className, classNames, style, items = [], disabled, col
|
|
|
190
190
|
onOrderMapChange
|
|
191
191
|
]);
|
|
192
192
|
function onDragMoveStart(key, event) {
|
|
193
|
+
_onDragMoveStart?.(event);
|
|
193
194
|
const position = getPosition({
|
|
194
195
|
order: keyToOrder.get(key),
|
|
195
196
|
columns,
|
|
@@ -216,6 +217,7 @@ function DraggableGrid({ className, classNames, style, items = [], disabled, col
|
|
|
216
217
|
});
|
|
217
218
|
}
|
|
218
219
|
function onDragMove(event) {
|
|
220
|
+
_onDragMove?.(event);
|
|
219
221
|
if (!dragging) return;
|
|
220
222
|
const { deltaX, deltaY } = event;
|
|
221
223
|
const { key, orders, keyToOrder, startX, startY, columns, gapX, gapY, itemWidth, itemHeight } = dragging;
|
|
@@ -281,7 +283,8 @@ function DraggableGrid({ className, classNames, style, items = [], disabled, col
|
|
|
281
283
|
setKeyToOrder(newKeyToOrder);
|
|
282
284
|
onOrderMapChange?.(newKeyToOrder);
|
|
283
285
|
}
|
|
284
|
-
function onDragMoveEnd() {
|
|
286
|
+
function onDragMoveEnd(event) {
|
|
287
|
+
_onDragMoveEnd?.(event);
|
|
285
288
|
if (!dragging) return;
|
|
286
289
|
setDragging(void 0);
|
|
287
290
|
}
|
|
@@ -336,6 +339,9 @@ function DraggableGrid({ className, classNames, style, items = [], disabled, col
|
|
|
336
339
|
isDragging: isDragging
|
|
337
340
|
}) : item;
|
|
338
341
|
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(DraggableGridItem, {
|
|
342
|
+
item: item,
|
|
343
|
+
itemKey: key,
|
|
344
|
+
handle: handle,
|
|
339
345
|
className: (0, external_deepsea_tools_namespaceObject.clsx)(external_DraggableGrid_module_cjs_default().draggableGridItem, "function" == typeof classNames?.item ? classNames.item({
|
|
340
346
|
order,
|
|
341
347
|
isDragging: isDragging
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CSSProperties, ComponentProps, Key, ReactNode } from "react";
|
|
2
|
+
import { DragMoveEvents } from "soda-hooks";
|
|
2
3
|
export type DraggableGridClassName = string | ((status: ContainerStatus) => string);
|
|
3
4
|
export type DraggableGridItemClassName = string | ((status: DraggableGridItemStatus) => string);
|
|
4
5
|
export type DraggableGridStyle = CSSProperties | ((status: ContainerStatus) => CSSProperties);
|
|
@@ -22,7 +23,7 @@ export interface DraggableGridItemStatus {
|
|
|
22
23
|
export type DraggableGridKeyToOrder = Map<Key, number>;
|
|
23
24
|
/** 次序到元素的 key 的映射 */
|
|
24
25
|
export type DraggableGridOrderToKey = Map<number, Key>;
|
|
25
|
-
export type DraggableGridProps<T> = Omit<ComponentProps<"div">, "className" | "children"> & {
|
|
26
|
+
export type DraggableGridProps<T> = Omit<ComponentProps<"div">, "className" | "children"> & DragMoveEvents<HTMLDivElement> & {
|
|
26
27
|
/** 类名 */
|
|
27
28
|
className?: DraggableGridClassName;
|
|
28
29
|
/** 类名 */
|
|
@@ -66,6 +67,8 @@ export type DraggableGridProps<T> = Omit<ComponentProps<"div">, "className" | "c
|
|
|
66
67
|
isOrderDisabled?: number[] | ((order: number) => boolean);
|
|
67
68
|
/** 次序的优先级,可以通过此函数调整元素的优先放置的方向,左上,右上,左下,右下,中心,顺时针,逆时针等等 */
|
|
68
69
|
orderPriority?: (a: number, b: number) => number;
|
|
70
|
+
/** 触发移动的元素 */
|
|
71
|
+
handle?: string | HTMLElement | ((item: T, key: Key, element: HTMLDivElement) => HTMLElement | undefined | null) | undefined | null;
|
|
69
72
|
} & (T extends ReactNode ? {
|
|
70
73
|
/** 渲染函数,当 T 为 ReactNode 时,render 为可选 */
|
|
71
74
|
render?: (item: T, status: DraggableGridItemStatus) => ReactNode;
|
|
@@ -79,4 +82,4 @@ export type DraggableGridProps<T> = Omit<ComponentProps<"div">, "className" | "c
|
|
|
79
82
|
/** 获取 key 的函数,当 T 为 Key 时,keyExtractor 为可选 */
|
|
80
83
|
keyExtractor: (item: T) => Key;
|
|
81
84
|
});
|
|
82
|
-
export declare function DraggableGrid<T>({ className, classNames, style, items, disabled, columns, rows, gap, gapX, gapY, itemWidth, itemHeight, orderMap, onOrderMapChange, render, keyExtractor, isItemDisabled: _isItemDisabled, isOrderDisabled, orderPriority, ...rest }: DraggableGridProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
85
|
+
export declare function DraggableGrid<T>({ className, classNames, style, items, disabled, columns, rows, gap, gapX, gapY, itemWidth, itemHeight, orderMap, onOrderMapChange, render, keyExtractor, isItemDisabled: _isItemDisabled, isOrderDisabled, orderPriority, handle, onDragMoveStart: _onDragMoveStart, onDragMove: _onDragMove, onDragMoveEnd: _onDragMoveEnd, ...rest }: DraggableGridProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
-
import { clsx, getArray } from "deepsea-tools";
|
|
3
|
+
import { clsx, getArray, isNullable } from "deepsea-tools";
|
|
4
4
|
import { useDragMove } from "soda-hooks";
|
|
5
5
|
import DraggableGrid_module from "./DraggableGrid.module.js";
|
|
6
6
|
function isTheSameArray(a, b) {
|
|
@@ -45,10 +45,10 @@ function getOrderToKey(keyToOrder) {
|
|
|
45
45
|
key
|
|
46
46
|
]));
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
function DraggableGridItem({ item, itemKey, handle, onDragMoveStart, onDragMove, onDragMoveEnd, ...rest }) {
|
|
49
49
|
const element = useRef(null);
|
|
50
50
|
useDragMove({
|
|
51
|
-
element,
|
|
51
|
+
element: isNullable(handle) ? element : ()=>element.current && ("string" == typeof handle ? element.current.querySelector(handle) : "function" == typeof handle ? handle(item, itemKey, element.current) : handle),
|
|
52
52
|
onDragMoveStart,
|
|
53
53
|
onDragMove,
|
|
54
54
|
onDragMoveEnd
|
|
@@ -57,8 +57,8 @@ const DraggableGridItem = ({ onDragMoveStart, onDragMove, onDragMoveEnd, ...rest
|
|
|
57
57
|
ref: element,
|
|
58
58
|
...rest
|
|
59
59
|
});
|
|
60
|
-
}
|
|
61
|
-
function DraggableGrid({ className, classNames, style, items = [], disabled, columns, rows, gap = 0, gapX = gap, gapY = gap, itemWidth, itemHeight, orderMap, onOrderMapChange, render, keyExtractor, isItemDisabled: _isItemDisabled, isOrderDisabled, orderPriority, ...rest }) {
|
|
60
|
+
}
|
|
61
|
+
function DraggableGrid({ className, classNames, style, items = [], disabled, columns, rows, gap = 0, gapX = gap, gapY = gap, itemWidth, itemHeight, orderMap, onOrderMapChange, render, keyExtractor, isItemDisabled: _isItemDisabled, isOrderDisabled, orderPriority, handle, onDragMoveStart: _onDragMoveStart, onDragMove: _onDragMove, onDragMoveEnd: _onDragMoveEnd, ...rest }) {
|
|
62
62
|
const keyToItem = useMemo(()=>{
|
|
63
63
|
const keyToItem = new Map();
|
|
64
64
|
items.forEach((item)=>{
|
|
@@ -152,6 +152,7 @@ function DraggableGrid({ className, classNames, style, items = [], disabled, col
|
|
|
152
152
|
onOrderMapChange
|
|
153
153
|
]);
|
|
154
154
|
function onDragMoveStart(key, event) {
|
|
155
|
+
_onDragMoveStart?.(event);
|
|
155
156
|
const position = getPosition({
|
|
156
157
|
order: keyToOrder.get(key),
|
|
157
158
|
columns,
|
|
@@ -178,6 +179,7 @@ function DraggableGrid({ className, classNames, style, items = [], disabled, col
|
|
|
178
179
|
});
|
|
179
180
|
}
|
|
180
181
|
function onDragMove(event) {
|
|
182
|
+
_onDragMove?.(event);
|
|
181
183
|
if (!dragging) return;
|
|
182
184
|
const { deltaX, deltaY } = event;
|
|
183
185
|
const { key, orders, keyToOrder, startX, startY, columns, gapX, gapY, itemWidth, itemHeight } = dragging;
|
|
@@ -243,7 +245,8 @@ function DraggableGrid({ className, classNames, style, items = [], disabled, col
|
|
|
243
245
|
setKeyToOrder(newKeyToOrder);
|
|
244
246
|
onOrderMapChange?.(newKeyToOrder);
|
|
245
247
|
}
|
|
246
|
-
function onDragMoveEnd() {
|
|
248
|
+
function onDragMoveEnd(event) {
|
|
249
|
+
_onDragMoveEnd?.(event);
|
|
247
250
|
if (!dragging) return;
|
|
248
251
|
setDragging(void 0);
|
|
249
252
|
}
|
|
@@ -298,6 +301,9 @@ function DraggableGrid({ className, classNames, style, items = [], disabled, col
|
|
|
298
301
|
isDragging: isDragging
|
|
299
302
|
}) : item;
|
|
300
303
|
return /*#__PURE__*/ jsx(DraggableGridItem, {
|
|
304
|
+
item: item,
|
|
305
|
+
itemKey: key,
|
|
306
|
+
handle: handle,
|
|
301
307
|
className: clsx(DraggableGrid_module.draggableGridItem, "function" == typeof classNames?.item ? classNames.item({
|
|
302
308
|
order,
|
|
303
309
|
isDragging: isDragging
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deepsea-components",
|
|
3
|
-
"version": "5.16.
|
|
3
|
+
"version": "5.16.3",
|
|
4
4
|
"description": "格数科技自用组件库",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"echarts": "^5.6.0",
|
|
41
41
|
"hls.js": "^1.6.9",
|
|
42
42
|
"smooth-scrollbar": "^8.8.4",
|
|
43
|
-
"
|
|
44
|
-
"
|
|
43
|
+
"deepsea-tools": "5.41.0",
|
|
44
|
+
"soda-hooks": "6.13.4"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"typescript": "^5.9.2"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CSSProperties, ComponentProps,
|
|
2
|
-
import { clsx, getArray } from "deepsea-tools"
|
|
3
|
-
import { DragMoveEvent,
|
|
1
|
+
import { CSSProperties, ComponentProps, Key, ReactNode, useEffect, useMemo, useRef, useState } from "react"
|
|
2
|
+
import { clsx, getArray, isNullable } from "deepsea-tools"
|
|
3
|
+
import { DragMoveEvent, DragMoveEvents, useDragMove } from "soda-hooks"
|
|
4
4
|
|
|
5
5
|
import styles from "./DraggableGrid.module.css"
|
|
6
6
|
|
|
@@ -101,51 +101,54 @@ function getOrderToKey(keyToOrder: DraggableGridKeyToOrder) {
|
|
|
101
101
|
return new Map(Array.from(keyToOrder.entries()).map(([key, order]) => [order, key]))
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
export type DraggableGridProps<T> = Omit<ComponentProps<"div">, "className" | "children"> &
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
104
|
+
export type DraggableGridProps<T> = Omit<ComponentProps<"div">, "className" | "children"> &
|
|
105
|
+
DragMoveEvents<HTMLDivElement> & {
|
|
106
|
+
/** 类名 */
|
|
107
|
+
className?: DraggableGridClassName
|
|
108
|
+
/** 类名 */
|
|
109
|
+
classNames?: DraggableGridClassNames
|
|
110
|
+
/** 样式 */
|
|
111
|
+
style?: DraggableGridStyle
|
|
112
|
+
/** 数据源 */
|
|
113
|
+
items?: T[]
|
|
114
|
+
/** 是否禁用拖拽 */
|
|
115
|
+
disabled?: boolean
|
|
116
|
+
/** 列数 */
|
|
117
|
+
columns: number
|
|
118
|
+
/** 行数 */
|
|
119
|
+
rows: number
|
|
120
|
+
/**
|
|
121
|
+
* 间距
|
|
122
|
+
* @default 0
|
|
123
|
+
*/
|
|
124
|
+
gap?: number
|
|
125
|
+
/**
|
|
126
|
+
* 水平间距
|
|
127
|
+
* @default 0
|
|
128
|
+
*/
|
|
129
|
+
gapX?: number
|
|
130
|
+
/**
|
|
131
|
+
* 垂直间距
|
|
132
|
+
* @default 0
|
|
133
|
+
*/
|
|
134
|
+
gapY?: number
|
|
135
|
+
/** 元素宽度 */
|
|
136
|
+
itemWidth: number
|
|
137
|
+
/** 元素高度 */
|
|
138
|
+
itemHeight: number
|
|
139
|
+
/** 元素的 key 到次序的映射 */
|
|
140
|
+
orderMap?: DraggableGridKeyToOrder
|
|
141
|
+
/** 次序变化时回调 */
|
|
142
|
+
onOrderMapChange?: (orderMap: DraggableGridKeyToOrder) => void
|
|
143
|
+
/** 禁用的元素 */
|
|
144
|
+
isItemDisabled?: Key[] | ((item: T, key: Key) => boolean)
|
|
145
|
+
/** 禁用的次序 */
|
|
146
|
+
isOrderDisabled?: number[] | ((order: number) => boolean)
|
|
147
|
+
/** 次序的优先级,可以通过此函数调整元素的优先放置的方向,左上,右上,左下,右下,中心,顺时针,逆时针等等 */
|
|
148
|
+
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
|
|
149
152
|
? {
|
|
150
153
|
/** 渲染函数,当 T 为 ReactNode 时,render 为可选 */
|
|
151
154
|
render?: (item: T, status: DraggableGridItemStatus) => ReactNode
|
|
@@ -164,13 +167,26 @@ export type DraggableGridProps<T> = Omit<ComponentProps<"div">, "className" | "c
|
|
|
164
167
|
keyExtractor: (item: T) => Key
|
|
165
168
|
})
|
|
166
169
|
|
|
167
|
-
interface DraggableGridItemProps extends ComponentProps<"div">,
|
|
170
|
+
interface DraggableGridItemProps<T> extends ComponentProps<"div">, DragMoveEvents<HTMLDivElement> {
|
|
171
|
+
item: T
|
|
172
|
+
itemKey: Key
|
|
173
|
+
/** 触发移动的元素 */
|
|
174
|
+
handle?: string | HTMLElement | ((item: T, key: Key, element: HTMLDivElement) => HTMLElement | undefined | null) | undefined | null
|
|
175
|
+
}
|
|
168
176
|
|
|
169
|
-
|
|
177
|
+
function DraggableGridItem<T>({ item, itemKey, handle, onDragMoveStart, onDragMove, onDragMoveEnd, ...rest }: DraggableGridItemProps<T>) {
|
|
170
178
|
const element = useRef<HTMLDivElement>(null)
|
|
171
179
|
|
|
172
180
|
useDragMove({
|
|
173
|
-
element
|
|
181
|
+
element: isNullable(handle)
|
|
182
|
+
? element
|
|
183
|
+
: () =>
|
|
184
|
+
element.current &&
|
|
185
|
+
(typeof handle === "string"
|
|
186
|
+
? (element.current.querySelector(handle) as HTMLElement)
|
|
187
|
+
: typeof handle === "function"
|
|
188
|
+
? handle(item, itemKey, element.current)
|
|
189
|
+
: handle),
|
|
174
190
|
onDragMoveStart,
|
|
175
191
|
onDragMove,
|
|
176
192
|
onDragMoveEnd,
|
|
@@ -215,6 +231,10 @@ export function DraggableGrid<T>({
|
|
|
215
231
|
isItemDisabled: _isItemDisabled,
|
|
216
232
|
isOrderDisabled,
|
|
217
233
|
orderPriority,
|
|
234
|
+
handle,
|
|
235
|
+
onDragMoveStart: _onDragMoveStart,
|
|
236
|
+
onDragMove: _onDragMove,
|
|
237
|
+
onDragMoveEnd: _onDragMoveEnd,
|
|
218
238
|
...rest
|
|
219
239
|
}: DraggableGridProps<T>) {
|
|
220
240
|
const keyToItem = useMemo(() => {
|
|
@@ -302,6 +322,7 @@ export function DraggableGrid<T>({
|
|
|
302
322
|
}, [orderMap, keyToOrder, onOrderMapChange])
|
|
303
323
|
|
|
304
324
|
function onDragMoveStart(key: Key, event: DragMoveEvent<HTMLDivElement>) {
|
|
325
|
+
_onDragMoveStart?.(event)
|
|
305
326
|
const position = getPosition({ order: keyToOrder.get(key)!, columns, gapX, gapY, itemWidth, itemHeight })
|
|
306
327
|
recent.current = key
|
|
307
328
|
setDragging({
|
|
@@ -322,6 +343,7 @@ export function DraggableGrid<T>({
|
|
|
322
343
|
}
|
|
323
344
|
|
|
324
345
|
function onDragMove(event: DragMoveEvent<HTMLDivElement>) {
|
|
346
|
+
_onDragMove?.(event)
|
|
325
347
|
if (!dragging) return
|
|
326
348
|
|
|
327
349
|
const { deltaX, deltaY } = event
|
|
@@ -395,7 +417,8 @@ export function DraggableGrid<T>({
|
|
|
395
417
|
onOrderMapChange?.(newKeyToOrder)
|
|
396
418
|
}
|
|
397
419
|
|
|
398
|
-
function onDragMoveEnd() {
|
|
420
|
+
function onDragMoveEnd(event: DragMoveEvent<HTMLDivElement>) {
|
|
421
|
+
_onDragMoveEnd?.(event)
|
|
399
422
|
if (!dragging) return
|
|
400
423
|
setDragging(undefined)
|
|
401
424
|
}
|
|
@@ -451,6 +474,9 @@ export function DraggableGrid<T>({
|
|
|
451
474
|
return (
|
|
452
475
|
<DraggableGridItem
|
|
453
476
|
key={key}
|
|
477
|
+
item={item}
|
|
478
|
+
itemKey={key}
|
|
479
|
+
handle={handle}
|
|
454
480
|
className={clsx(
|
|
455
481
|
styles.draggableGridItem,
|
|
456
482
|
typeof classNames?.item === "function" ? classNames.item({ order, isDragging: isDragging }) : classNames?.item,
|