@etsoo/react 1.5.59 → 1.5.60
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/lib/mu/DnDList.d.ts +31 -0
- package/lib/mu/DnDList.js +20 -2
- package/package.json +1 -1
- package/src/mu/DnDList.tsx +81 -2
package/lib/mu/DnDList.d.ts
CHANGED
|
@@ -1,4 +1,35 @@
|
|
|
1
|
+
import { UniqueIdentifier } from '@dnd-kit/core';
|
|
1
2
|
import React, { CSSProperties } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* DnD list item props
|
|
5
|
+
*/
|
|
6
|
+
export interface DnDItemProps<D extends {}> {
|
|
7
|
+
/**
|
|
8
|
+
* Unique id
|
|
9
|
+
*/
|
|
10
|
+
id: UniqueIdentifier;
|
|
11
|
+
/**
|
|
12
|
+
* Children
|
|
13
|
+
*/
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
/**
|
|
16
|
+
* Item data
|
|
17
|
+
*/
|
|
18
|
+
data?: D;
|
|
19
|
+
/**
|
|
20
|
+
* Disabled or not
|
|
21
|
+
*/
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Inline style
|
|
25
|
+
*/
|
|
26
|
+
style?: CSSProperties;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* DnD list item
|
|
30
|
+
* @param props Props
|
|
31
|
+
*/
|
|
32
|
+
export declare function DnDItem<D extends {}>(props: DnDItemProps<D>): JSX.Element;
|
|
2
33
|
/**
|
|
3
34
|
* DnD list props
|
|
4
35
|
*/
|
package/lib/mu/DnDList.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
import { DndContext } from '@dnd-kit/core';
|
|
1
|
+
import { DndContext, DragOverlay, useDraggable } from '@dnd-kit/core';
|
|
2
2
|
import { DataTypes } from '@etsoo/shared';
|
|
3
3
|
import React from 'react';
|
|
4
|
+
/**
|
|
5
|
+
* DnD list item
|
|
6
|
+
* @param props Props
|
|
7
|
+
*/
|
|
8
|
+
export function DnDItem(props) {
|
|
9
|
+
const { children, style, ...rest } = props;
|
|
10
|
+
const { attributes, listeners, setNodeRef } = useDraggable(rest);
|
|
11
|
+
return (React.createElement("div", { style: style, ref: setNodeRef, ...listeners, ...attributes }, children));
|
|
12
|
+
}
|
|
4
13
|
/**
|
|
5
14
|
* Drag and drop list
|
|
6
15
|
* https://github.com/atlassian/react-beautiful-dnd
|
|
@@ -23,6 +32,7 @@ export function DnDList(props) {
|
|
|
23
32
|
const onDragEndLocal = (result) => {
|
|
24
33
|
// Clone
|
|
25
34
|
const newItems = [...items];
|
|
35
|
+
console.log(result);
|
|
26
36
|
// Removed item
|
|
27
37
|
// const [removed] = newItems.splice(result.source.index, 1);
|
|
28
38
|
// Insert to the destination index
|
|
@@ -104,7 +114,15 @@ export function DnDList(props) {
|
|
|
104
114
|
if (id == null)
|
|
105
115
|
return;
|
|
106
116
|
return (React.createElement("div", { key: id, style: getItemStyle(false, index) }, children(item, index, deleteItem, editItem)));
|
|
107
|
-
}))) : (React.createElement(DndContext, { onDragEnd: onDragEndLocal }
|
|
117
|
+
}))) : (React.createElement(DndContext, { onDragEnd: onDragEndLocal },
|
|
118
|
+
items.map((item, index) => {
|
|
119
|
+
// Id
|
|
120
|
+
const id = DataTypes.convert(item[labelField], 'string');
|
|
121
|
+
if (id == null)
|
|
122
|
+
return;
|
|
123
|
+
return (React.createElement(DnDItem, { id: id, key: id, data: item, "data-index": index, style: getItemStyle(false, index) }, children(item, index, deleteItem, editItem)));
|
|
124
|
+
}),
|
|
125
|
+
React.createElement(DragOverlay, null)))),
|
|
108
126
|
sideRenderer &&
|
|
109
127
|
sideRenderer(false, addItem, addItems, reloadItems)));
|
|
110
128
|
}
|
package/package.json
CHANGED
package/src/mu/DnDList.tsx
CHANGED
|
@@ -1,7 +1,57 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
DndContext,
|
|
3
|
+
DragEndEvent,
|
|
4
|
+
DragOverlay,
|
|
5
|
+
UniqueIdentifier,
|
|
6
|
+
useDraggable
|
|
7
|
+
} from '@dnd-kit/core';
|
|
2
8
|
import { DataTypes } from '@etsoo/shared';
|
|
3
9
|
import React, { CSSProperties } from 'react';
|
|
4
10
|
|
|
11
|
+
/**
|
|
12
|
+
* DnD list item props
|
|
13
|
+
*/
|
|
14
|
+
export interface DnDItemProps<D extends {}> {
|
|
15
|
+
/**
|
|
16
|
+
* Unique id
|
|
17
|
+
*/
|
|
18
|
+
id: UniqueIdentifier;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Children
|
|
22
|
+
*/
|
|
23
|
+
children: React.ReactNode;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Item data
|
|
27
|
+
*/
|
|
28
|
+
data?: D;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Disabled or not
|
|
32
|
+
*/
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Inline style
|
|
37
|
+
*/
|
|
38
|
+
style?: CSSProperties;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* DnD list item
|
|
43
|
+
* @param props Props
|
|
44
|
+
*/
|
|
45
|
+
export function DnDItem<D extends {}>(props: DnDItemProps<D>) {
|
|
46
|
+
const { children, style, ...rest } = props;
|
|
47
|
+
const { attributes, listeners, setNodeRef } = useDraggable(rest);
|
|
48
|
+
return (
|
|
49
|
+
<div style={style} ref={setNodeRef} {...listeners} {...attributes}>
|
|
50
|
+
{children}
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
5
55
|
/**
|
|
6
56
|
* DnD list props
|
|
7
57
|
*/
|
|
@@ -120,6 +170,8 @@ export function DnDList<
|
|
|
120
170
|
// Clone
|
|
121
171
|
const newItems = [...items];
|
|
122
172
|
|
|
173
|
+
console.log(result);
|
|
174
|
+
|
|
123
175
|
// Removed item
|
|
124
176
|
// const [removed] = newItems.splice(result.source.index, 1);
|
|
125
177
|
|
|
@@ -249,7 +301,34 @@ export function DnDList<
|
|
|
249
301
|
})}
|
|
250
302
|
</div>
|
|
251
303
|
) : (
|
|
252
|
-
<DndContext onDragEnd={onDragEndLocal}
|
|
304
|
+
<DndContext onDragEnd={onDragEndLocal}>
|
|
305
|
+
{items.map((item, index) => {
|
|
306
|
+
// Id
|
|
307
|
+
const id = DataTypes.convert(
|
|
308
|
+
item[labelField],
|
|
309
|
+
'string'
|
|
310
|
+
);
|
|
311
|
+
if (id == null) return;
|
|
312
|
+
|
|
313
|
+
return (
|
|
314
|
+
<DnDItem<D>
|
|
315
|
+
id={id}
|
|
316
|
+
key={id}
|
|
317
|
+
data={item}
|
|
318
|
+
data-index={index}
|
|
319
|
+
style={getItemStyle(false, index)}
|
|
320
|
+
>
|
|
321
|
+
{children(
|
|
322
|
+
item,
|
|
323
|
+
index,
|
|
324
|
+
deleteItem,
|
|
325
|
+
editItem
|
|
326
|
+
)}
|
|
327
|
+
</DnDItem>
|
|
328
|
+
);
|
|
329
|
+
})}
|
|
330
|
+
<DragOverlay></DragOverlay>
|
|
331
|
+
</DndContext>
|
|
253
332
|
)}
|
|
254
333
|
</Component>
|
|
255
334
|
{sideRenderer &&
|