@pega/cosmos-react-dnd 4.0.0-dev.5.1 → 4.0.0-dev.6.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/lib/components/DragDropList/DragDropList.d.ts +1 -1
- package/lib/components/DragDropList/DragDropList.d.ts.map +1 -1
- package/lib/components/DragDropList/DragDropList.js +42 -27
- package/lib/components/DragDropList/DragDropList.js.map +1 -1
- package/lib/components/DragDropList/DragDropList.types.d.ts +8 -1
- package/lib/components/DragDropList/DragDropList.types.d.ts.map +1 -1
- package/lib/components/DragDropList/DragDropList.types.js.map +1 -1
- package/lib/components/DragDropManager/DragDropManager.d.ts +1 -0
- package/lib/components/DragDropManager/DragDropManager.d.ts.map +1 -1
- package/lib/components/DragDropManager/DragDropManager.js +2 -2
- package/lib/components/DragDropManager/DragDropManager.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { ForwardProps } from '@pega/cosmos-react-core';
|
|
3
3
|
import { DragDropListProps } from './DragDropList.types';
|
|
4
|
-
declare const DragDropList: <T extends object = object>({ accept, items, itemRenderer: ItemRenderer, emptyRenderer: EmptyRenderer, onChange, onEnter, pullMode, pushMode, as: Component, ...restProps }: DragDropListProps<T> & ForwardProps) => JSX.Element;
|
|
4
|
+
declare const DragDropList: <T extends object = object>({ id: idProp, accept, items, itemRenderer: ItemRenderer, emptyRenderer: EmptyRenderer, onChange, onEnter, pullMode, pushMode, dragToRemove, as: Component, ...restProps }: DragDropListProps<T> & ForwardProps) => JSX.Element;
|
|
5
5
|
export default DragDropList;
|
|
6
6
|
//# sourceMappingURL=DragDropList.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DragDropList.d.ts","sourceRoot":"","sources":["../../../src/components/DragDropList/DragDropList.tsx"],"names":[],"mappings":";AAGA,OAAO,EAIL,YAAY,
|
|
1
|
+
{"version":3,"file":"DragDropList.d.ts","sourceRoot":"","sources":["../../../src/components/DragDropList/DragDropList.tsx"],"names":[],"mappings":";AAGA,OAAO,EAIL,YAAY,EAGb,MAAM,yBAAyB,CAAC;AAKjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAgBzD,QAAA,MAAM,YAAY,4PAwRjB,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useState, useRef } from 'react';
|
|
3
|
-
import { useElement, useAfterInitialEffect, useTriggerableEffect } from '@pega/cosmos-react-core';
|
|
3
|
+
import { useElement, useAfterInitialEffect, useTriggerableEffect, useUID } from '@pega/cosmos-react-core';
|
|
4
4
|
import Draggable from '../Draggable';
|
|
5
5
|
import Droppable from '../Droppable';
|
|
6
6
|
const middleYOfRect = ({ top, bottom }) => top + (bottom - top) / 2;
|
|
7
|
-
const DragDropList = ({ accept, items, itemRenderer: ItemRenderer, emptyRenderer: EmptyRenderer, onChange, onEnter, pullMode = 'remove', pushMode = 'insert', as: Component = 'ul', ...restProps }) => {
|
|
7
|
+
const DragDropList = ({ id: idProp, accept, items, itemRenderer: ItemRenderer, emptyRenderer: EmptyRenderer, onChange, onEnter, pullMode = 'remove', pushMode = 'insert', dragToRemove = false, as: Component = 'ul', ...restProps }) => {
|
|
8
8
|
const [internalItems, setInternalItems] = useState(items);
|
|
9
9
|
const itemRectsRef = useRef(null);
|
|
10
10
|
const transformedItem = useRef(null);
|
|
11
11
|
const [listEl, setListEl] = useElement();
|
|
12
|
+
const uniqueId = useUID();
|
|
13
|
+
const listId = idProp ?? uniqueId;
|
|
12
14
|
const getItemRects = useCallback(() => {
|
|
13
15
|
if (!listEl || listEl.children.length === 0)
|
|
14
16
|
return null;
|
|
@@ -32,12 +34,23 @@ const DragDropList = ({ accept, items, itemRenderer: ItemRenderer, emptyRenderer
|
|
|
32
34
|
if (transformedItem.current)
|
|
33
35
|
return transformedItem.current;
|
|
34
36
|
const newItem = {
|
|
37
|
+
...item,
|
|
35
38
|
...onEnter(item),
|
|
36
39
|
id: item.id
|
|
37
40
|
};
|
|
38
41
|
transformedItem.current = newItem;
|
|
39
42
|
return newItem;
|
|
40
43
|
}, [onEnter]);
|
|
44
|
+
const changeSource = useCallback((itemId, destinationId) => {
|
|
45
|
+
const sourcePullMode = typeof pullMode === 'function' ? pullMode(destinationId) : pullMode;
|
|
46
|
+
if (sourcePullMode === 'remove') {
|
|
47
|
+
const newList = internalItems.filter(({ id }) => id !== itemId);
|
|
48
|
+
triggerOnChange(newList);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
setInternalItems(items);
|
|
52
|
+
}
|
|
53
|
+
}, [pullMode, items, internalItems, triggerOnChange]);
|
|
41
54
|
const getInsertIndex = useCallback((item, monitor) => {
|
|
42
55
|
itemRectsRef.current = getItemRects();
|
|
43
56
|
const { current: itemRects } = itemRectsRef;
|
|
@@ -77,10 +90,8 @@ const DragDropList = ({ accept, items, itemRenderer: ItemRenderer, emptyRenderer
|
|
|
77
90
|
return insertIndex;
|
|
78
91
|
}, [getItemRects, internalItems]);
|
|
79
92
|
const removeById = useCallback((itemId) => {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
}, [pullMode]);
|
|
93
|
+
setInternalItems(currentItems => currentItems.filter(({ id }) => id !== itemId));
|
|
94
|
+
}, []);
|
|
84
95
|
const normalizeItems = useCallback(() => {
|
|
85
96
|
setInternalItems(currentItems => currentItems.map(({ id, data, type }) => ({
|
|
86
97
|
id,
|
|
@@ -97,11 +108,12 @@ const DragDropList = ({ accept, items, itemRenderer: ItemRenderer, emptyRenderer
|
|
|
97
108
|
item.removeFromCurrent = () => {
|
|
98
109
|
removeById(item.id);
|
|
99
110
|
};
|
|
100
|
-
item.normalizeDestination = normalizeItems;
|
|
101
|
-
item.changeDestination = triggerOnChange;
|
|
102
|
-
item.destinationItemsRef = internalItemsRef;
|
|
103
|
-
item.transformedItemCache?.add(transformedItem);
|
|
104
111
|
}
|
|
112
|
+
item.normalizeDestination = normalizeItems;
|
|
113
|
+
item.changeDestination = triggerOnChange;
|
|
114
|
+
item.destinationItemsRef = internalItemsRef;
|
|
115
|
+
item.transformedItemCache?.add(transformedItem);
|
|
116
|
+
item.destinationId = listId;
|
|
105
117
|
let insertIndex = 0;
|
|
106
118
|
if (pushMode === 'insert')
|
|
107
119
|
insertIndex = getInsertIndex(item, monitor);
|
|
@@ -127,15 +139,12 @@ const DragDropList = ({ accept, items, itemRenderer: ItemRenderer, emptyRenderer
|
|
|
127
139
|
else
|
|
128
140
|
setInternalItems(newItems);
|
|
129
141
|
}
|
|
130
|
-
}, [internalItems, pushMode, getInsertIndex, normalizeItems, triggerOnChange, removeById]);
|
|
142
|
+
}, [internalItems, pushMode, getInsertIndex, normalizeItems, triggerOnChange, removeById, listId]);
|
|
131
143
|
const onHover = positionItems;
|
|
132
144
|
const onDrop = positionItems;
|
|
133
145
|
const onBegin = useCallback((itemId) => () => {
|
|
134
146
|
const initialIndex = internalItems.findIndex(({ id }) => id === itemId);
|
|
135
147
|
return {
|
|
136
|
-
removeFromCurrent: () => {
|
|
137
|
-
removeById(itemId);
|
|
138
|
-
},
|
|
139
148
|
returnToSource: (item) => {
|
|
140
149
|
setInternalItems(currentItems => {
|
|
141
150
|
const newItems = currentItems.filter(({ id }) => id !== itemId);
|
|
@@ -145,35 +154,41 @@ const DragDropList = ({ accept, items, itemRenderer: ItemRenderer, emptyRenderer
|
|
|
145
154
|
normalizeItems();
|
|
146
155
|
},
|
|
147
156
|
normalizeDestination: normalizeItems,
|
|
148
|
-
changeSource
|
|
149
|
-
sourceItemsRef: internalItemsRef,
|
|
157
|
+
changeSource,
|
|
150
158
|
changeDestination: triggerOnChange,
|
|
151
159
|
destinationItemsRef: internalItemsRef,
|
|
152
|
-
transformedItemCache: new Set([transformedItem])
|
|
160
|
+
transformedItemCache: new Set([transformedItem]),
|
|
161
|
+
sourceId: listId,
|
|
162
|
+
destinationId: listId
|
|
153
163
|
};
|
|
154
|
-
}, [internalItems, normalizeItems, triggerOnChange, removeById]);
|
|
164
|
+
}, [internalItems, normalizeItems, triggerOnChange, changeSource, removeById, listId]);
|
|
155
165
|
const onEnd = useCallback((item, monitor) => {
|
|
156
166
|
if (!item)
|
|
157
167
|
return;
|
|
158
168
|
if (monitor.didDrop()) {
|
|
159
|
-
const
|
|
160
|
-
const destinationItems = item.destinationItemsRef.current;
|
|
161
|
-
item.normalizeDestination?.();
|
|
169
|
+
const { id: itemId, sourceId, destinationId } = item;
|
|
162
170
|
let insertIndex;
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
171
|
+
item.normalizeDestination?.();
|
|
172
|
+
const destinationItems = item.destinationItemsRef.current;
|
|
173
|
+
if (sourceId && destinationId && sourceId !== destinationId) {
|
|
174
|
+
item.changeSource?.(itemId, destinationId);
|
|
175
|
+
insertIndex = destinationItems.findIndex(({ id }) => id === itemId);
|
|
166
176
|
}
|
|
167
177
|
item.changeDestination?.(destinationItems, insertIndex);
|
|
168
178
|
}
|
|
169
179
|
else {
|
|
170
180
|
item.removeFromCurrent?.();
|
|
171
|
-
|
|
181
|
+
if (dragToRemove) {
|
|
182
|
+
removeById(item.id);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
item.returnToSource?.(item);
|
|
186
|
+
}
|
|
172
187
|
}
|
|
173
188
|
item.transformedItemCache?.forEach(ref => {
|
|
174
189
|
ref.current = null;
|
|
175
190
|
});
|
|
176
|
-
}, []);
|
|
191
|
+
}, [dragToRemove]);
|
|
177
192
|
const emptyContent = EmptyRenderer ? _jsx(EmptyRenderer, {}) : null;
|
|
178
193
|
return (_jsx(Droppable, { accept: accept, onHover: onHover, onDrop: onDrop, children: ({ dropRef }) => {
|
|
179
194
|
return (_jsx(Component, { ref: (el) => {
|
|
@@ -188,7 +203,7 @@ const DragDropList = ({ accept, items, itemRenderer: ItemRenderer, emptyRenderer
|
|
|
188
203
|
dragRef,
|
|
189
204
|
previewRef,
|
|
190
205
|
...collected,
|
|
191
|
-
isDragging:
|
|
206
|
+
isDragging: !!item.sourceId
|
|
192
207
|
} }));
|
|
193
208
|
} }, item.id));
|
|
194
209
|
}) }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DragDropList.js","sourceRoot":"","sources":["../../../src/components/DragDropList/DragDropList.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAA+B,MAAM,OAAO,CAAC;AAGnF,OAAO,EACL,UAAU,EACV,qBAAqB,EACrB,oBAAoB,EAGrB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,SAA4B,MAAM,cAAc,CAAC;AACxD,OAAO,SAAS,MAAM,cAAc,CAAC;AAerC,MAAM,aAAa,GAAG,CAAC,EAAE,GAAG,EAAE,MAAM,EAAW,EAAU,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;AAErF,MAAM,YAAY,GAAG,CAA4B,EAC/C,MAAM,EACN,KAAK,EACL,YAAY,EAAE,YAAY,EAC1B,aAAa,EAAE,aAAa,EAC5B,QAAQ,EACR,OAAO,EACP,QAAQ,GAAG,QAAQ,EACnB,QAAQ,GAAG,QAAQ,EACnB,EAAE,EAAE,SAAS,GAAG,IAAI,EACpB,GAAG,SAAS,EACwB,EAAE,EAAE;IACxC,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAAwB,KAAK,CAAC,CAAC;IACjF,MAAM,YAAY,GAAG,MAAM,CAAmB,IAAI,CAAC,CAAC;IACpD,MAAM,eAAe,GAAG,MAAM,CAA0B,IAAI,CAAC,CAAC;IAC9D,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,UAAU,EAAe,CAAC;IAEtD,MAAM,YAAY,GAAG,WAAW,CAAC,GAAqB,EAAE;QACtD,IAAI,CA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AAC,aAAa,KAAG,CAAC,CAAC,CAAC,IAAI,CAAC;IAE9D,OAAO,CACL,KAAC,SAAS,IAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,YACxD,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;YACf,OAAO,CACL,KAAC,SAAS,IACR,GAAG,EAAE,CAAC,EAAe,EAAE,EAAE;oBACvB,OAAO,CAAC,EAAE,CAAC,CAAC;oBACZ,SAAS,CAAC,EAAE,CAAC,CAAC;gBAChB,CAAC,KACG,SAAS,YAEZ,aAAa,CAAC,MAAM,KAAK,CAAC;oBACzB,CAAC,CAAC,YAAY;oBACd,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;wBACvB,OAAO,CACL,KAAC,SAAS,IAER,EAAE,EAAE,IAAI,CAAC,EAAE,EACX,IAAI,EAAE,IAAI,CAAC,IAAI,EACf,IAAI,EAAE,IAAI,CAAC,IAAI,EACf,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,EACzB,KAAK,EAAE,KAAK,YAEX,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,EAAE;gCACtC,OAAO,CACL,KAAC,YAAY,OACP;wCACF,GAAG,IAAI;wCACP,OAAO;wCACP,UAAU;wCACV,GAAG,SAAS;wCACZ,UAAU,EAAE,SAAS,CAAC,UAAU,IAAI,CAAC,CAAC,IAAI,CAAC,iBAAiB;qCAC7D,GACD,CACH,CAAC;4BACJ,CAAC,IAnBI,IAAI,CAAC,EAAE,CAoBF,CACb,CAAC;oBACJ,CAAC,CAAC,GACI,CACb,CAAC;QACJ,CAAC,GACS,CACb,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import { useCallback, useState, useRef, RefObject, MutableRefObject } from 'react';\nimport { DragSourceMonitor, DropTargetMonitor } from 'react-dnd';\n\nimport {\n useElement,\n useAfterInitialEffect,\n useTriggerableEffect,\n ForwardProps,\n OmitStrict\n} from '@pega/cosmos-react-core';\n\nimport Draggable, { DraggableItem } from '../Draggable';\nimport Droppable from '../Droppable';\n\nimport { DragDropListProps } from './DragDropList.types';\n\ninterface DragDropListItem<T extends object = object> extends DraggableItem<T> {\n removeFromCurrent?: () => void;\n returnToSource?: (item: DraggableItem<T>) => void;\n normalizeDestination?: () => void;\n changeSource?: (items: DragDropListItem<T>[]) => void;\n sourceItemsRef?: RefObject<DragDropListItem<T>[]>;\n changeDestination?: (items: DragDropListItem<T>[], insertIndex?: number) => void;\n destinationItemsRef?: RefObject<DragDropListItem<T>[]>;\n transformedItemCache?: Set<MutableRefObject<DraggableItem<T> | null>>;\n}\n\nconst middleYOfRect = ({ top, bottom }: DOMRect): number => top + (bottom - top) / 2;\n\nconst DragDropList = <T extends object = object>({\n accept,\n items,\n itemRenderer: ItemRenderer,\n emptyRenderer: EmptyRenderer,\n onChange,\n onEnter,\n pullMode = 'remove',\n pushMode = 'insert',\n as: Component = 'ul',\n ...restProps\n}: DragDropListProps<T> & ForwardProps) => {\n const [internalItems, setInternalItems] = useState<DragDropListItem<T>[]>(items);\n const itemRectsRef = useRef<DOMRect[] | null>(null);\n const transformedItem = useRef<DraggableItem<T> | null>(null);\n const [listEl, setListEl] = useElement<HTMLElement>();\n\n const getItemRects = useCallback((): DOMRect[] | null => {\n if (!listEl || listEl.children.length === 0) return null;\n return [...listEl.children].map(itemEl => {\n return itemEl.getBoundingClientRect();\n });\n }, [listEl]);\n\n useAfterInitialEffect(() => {\n setInternalItems(items);\n }, [items]);\n\n const internalItemsRef = useRef(internalItems);\n internalItemsRef.current = internalItems;\n\n const triggerOnChange = useTriggerableEffect(\n useCallback(\n (newItems: DragDropListItem<T>[], insertIndex?: number) => {\n onChange(newItems, insertIndex);\n },\n [onChange]\n )\n );\n\n const getTransformedItem = useCallback(\n (item: DragDropListItem<T>) => {\n if (!onEnter) {\n transformedItem.current = null;\n return item;\n }\n\n if (transformedItem.current) return transformedItem.current;\n\n const newItem = {\n ...onEnter(item),\n id: item.id\n };\n transformedItem.current = newItem;\n return newItem;\n },\n [onEnter]\n );\n\n const getInsertIndex = useCallback(\n (item: DraggableItem<T>, monitor: DropTargetMonitor | DragSourceMonitor): number => {\n itemRectsRef.current = getItemRects();\n const { current: itemRects } = itemRectsRef;\n let insertIndex = -1;\n const prevIndex = internalItems.findIndex(({ id }) => id === item.id);\n\n const clientXY = monitor.getClientOffset();\n if (!itemRects || !clientXY) return insertIndex;\n\n const dragPreviewRectTop = clientXY.y;\n const atHead = dragPreviewRectTop < middleYOfRect(itemRects[0]);\n const atTail = dragPreviewRectTop >= middleYOfRect(itemRects[itemRects.length - 1]);\n\n if (atHead) {\n insertIndex = 0;\n } else if (atTail) {\n insertIndex = prevIndex === itemRects.length - 1 ? prevIndex : itemRects.length;\n } else {\n itemRects.some((rect, i, rects) => {\n if (i === rects.length - 1) {\n if (prevIndex === i) insertIndex = i;\n return true;\n }\n const belowCurrent = dragPreviewRectTop >= middleYOfRect(rect);\n const aboveNext = dragPreviewRectTop < middleYOfRect(rects[i + 1]);\n if (belowCurrent && aboveNext) {\n if (prevIndex !== -1 && i >= prevIndex) insertIndex = i;\n else insertIndex = i + 1;\n return true;\n }\n return false;\n });\n }\n\n return insertIndex;\n },\n [getItemRects, internalItems]\n );\n\n const removeById = useCallback(\n (itemId: DraggableItem<T>['id']): void => {\n if (pullMode === 'remove') {\n setInternalItems(currentItems => currentItems.filter(({ id }) => id !== itemId));\n }\n },\n [pullMode]\n );\n\n const normalizeItems = useCallback(() => {\n setInternalItems(currentItems =>\n currentItems.map(({ id, data, type }) => ({\n id,\n data,\n type\n }))\n );\n }, []);\n\n const positionItems = useCallback(\n (item: DragDropListItem<T>, monitor: DropTargetMonitor): void => {\n if (!monitor.canDrop() || !monitor.isOver({ shallow: true })) return;\n\n const prevIndex = internalItems.findIndex(({ id }) => id === item.id);\n\n if (prevIndex === -1) {\n item.removeFromCurrent?.();\n item.removeFromCurrent = () => {\n removeById(item.id);\n };\n item.normalizeDestination = normalizeItems;\n item.changeDestination = triggerOnChange;\n item.destinationItemsRef = internalItemsRef;\n item.transformedItemCache?.add(transformedItem);\n }\n\n let insertIndex = 0;\n if (pushMode === 'insert') insertIndex = getInsertIndex(item, monitor);\n if (pushMode === 'append') insertIndex = internalItems.length + 1;\n\n let newItems: DraggableItem<T>[];\n\n // Is the current being dragged is within its own list\n if (prevIndex !== -1) {\n if (insertIndex === prevIndex || pushMode !== 'insert') return;\n\n newItems = internalItems.filter(({ id }) => id !== item.id);\n newItems.splice(insertIndex, 0, transformedItem.current ?? item);\n\n if (typeof pushMode === 'function') setInternalItems(newItems.sort(pushMode));\n else setInternalItems(newItems);\n } else {\n newItems = [...internalItems];\n newItems.splice(insertIndex, 0, getTransformedItem(item));\n\n if (typeof pushMode === 'function') setInternalItems(newItems.sort(pushMode));\n else setInternalItems(newItems);\n }\n },\n [internalItems, pushMode, getInsertIndex, normalizeItems, triggerOnChange, removeById]\n );\n\n const onHover = positionItems;\n const onDrop = positionItems;\n\n const onBegin = useCallback(\n (itemId: DraggableItem<T>['id']) =>\n (): OmitStrict<DragDropListItem<T>, keyof DraggableItem<T>> => {\n const initialIndex = internalItems.findIndex(({ id }) => id === itemId);\n\n return {\n removeFromCurrent: () => {\n removeById(itemId);\n },\n returnToSource: (item: DraggableItem<T>) => {\n setInternalItems(currentItems => {\n const newItems = currentItems.filter(({ id }) => id !== itemId);\n newItems.splice(initialIndex, 0, item);\n return newItems;\n });\n normalizeItems();\n },\n normalizeDestination: normalizeItems,\n changeSource: triggerOnChange,\n sourceItemsRef: internalItemsRef,\n changeDestination: triggerOnChange,\n destinationItemsRef: internalItemsRef,\n transformedItemCache: new Set([transformedItem])\n };\n },\n [internalItems, normalizeItems, triggerOnChange, removeById]\n );\n\n const onEnd = useCallback((item: DragDropListItem<T> | undefined, monitor: DragSourceMonitor) => {\n if (!item) return;\n\n if (monitor.didDrop()) {\n const sourceItems = item.sourceItemsRef!.current!;\n const destinationItems = item.destinationItemsRef!.current!;\n\n item.normalizeDestination?.();\n let insertIndex;\n if (item.changeSource !== item.changeDestination) {\n item.changeSource?.(sourceItems);\n insertIndex = destinationItems.findIndex(({ id }) => id === item.id);\n }\n item.changeDestination?.(destinationItems, insertIndex);\n } else {\n item.removeFromCurrent?.();\n item.returnToSource?.(item);\n }\n item.transformedItemCache?.forEach(ref => {\n ref.current = null;\n });\n }, []);\n\n const emptyContent = EmptyRenderer ? <EmptyRenderer /> : null;\n\n return (\n <Droppable accept={accept} onHover={onHover} onDrop={onDrop}>\n {({ dropRef }) => {\n return (\n <Component\n ref={(el: HTMLElement) => {\n dropRef(el);\n setListEl(el);\n }}\n {...restProps}\n >\n {internalItems.length === 0\n ? emptyContent\n : internalItems.map(item => {\n return (\n <Draggable\n key={item.id}\n id={item.id}\n type={item.type}\n data={item.data}\n onBegin={onBegin(item.id)}\n onEnd={onEnd}\n >\n {({ dragRef, previewRef, collected }) => {\n return (\n <ItemRenderer\n {...{\n ...item,\n dragRef,\n previewRef,\n ...collected,\n isDragging: collected.isDragging || !!item.removeFromCurrent\n }}\n />\n );\n }}\n </Draggable>\n );\n })}\n </Component>\n );\n }}\n </Droppable>\n );\n};\n\nexport default DragDropList;\n"]}
|
|
1
|
+
{"version":3,"file":"DragDropList.js","sourceRoot":"","sources":["../../../src/components/DragDropList/DragDropList.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAA+B,MAAM,OAAO,CAAC;AAGnF,OAAO,EACL,UAAU,EACV,qBAAqB,EACrB,oBAAoB,EAGpB,MAAM,EACP,MAAM,yBAAyB,CAAC;AAEjC,OAAO,SAA4B,MAAM,cAAc,CAAC;AACxD,OAAO,SAAS,MAAM,cAAc,CAAC;AAgBrC,MAAM,aAAa,GAAG,CAAC,EAAE,GAAG,EAAE,MAAM,EAAW,EAAU,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,GA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AC","sourcesContent":["import { useCallback, useState, useRef, RefObject, MutableRefObject } from 'react';\nimport { DragSourceMonitor, DropTargetMonitor } from 'react-dnd';\n\nimport {\n useElement,\n useAfterInitialEffect,\n useTriggerableEffect,\n ForwardProps,\n OmitStrict,\n useUID\n} from '@pega/cosmos-react-core';\n\nimport Draggable, { DraggableItem } from '../Draggable';\nimport Droppable from '../Droppable';\n\nimport { DragDropListProps } from './DragDropList.types';\n\ninterface DragDropListItem<T extends object = object> extends DraggableItem<T> {\n removeFromCurrent?: () => void;\n returnToSource?: (item: DraggableItem<T>) => void;\n normalizeDestination?: () => void;\n changeSource?: (itemId: DraggableItem<T>['id'], destinationId: string) => void;\n changeDestination?: (items: DragDropListItem<T>[], insertIndex?: number) => void;\n destinationItemsRef?: RefObject<DragDropListItem<T>[]>;\n transformedItemCache?: Set<MutableRefObject<DraggableItem<T> | null>>;\n sourceId?: string;\n destinationId?: string;\n}\n\nconst middleYOfRect = ({ top, bottom }: DOMRect): number => top + (bottom - top) / 2;\n\nconst DragDropList = <T extends object = object>({\n id: idProp,\n accept,\n items,\n itemRenderer: ItemRenderer,\n emptyRenderer: EmptyRenderer,\n onChange,\n onEnter,\n pullMode = 'remove',\n pushMode = 'insert',\n dragToRemove = false,\n as: Component = 'ul',\n ...restProps\n}: DragDropListProps<T> & ForwardProps) => {\n const [internalItems, setInternalItems] = useState<DragDropListItem<T>[]>(items);\n const itemRectsRef = useRef<DOMRect[] | null>(null);\n const transformedItem = useRef<DraggableItem<T> | null>(null);\n const [listEl, setListEl] = useElement<HTMLElement>();\n const uniqueId = useUID();\n const listId = idProp ?? uniqueId;\n\n const getItemRects = useCallback((): DOMRect[] | null => {\n if (!listEl || listEl.children.length === 0) return null;\n return [...listEl.children].map(itemEl => {\n return itemEl.getBoundingClientRect();\n });\n }, [listEl]);\n\n useAfterInitialEffect(() => {\n setInternalItems(items);\n }, [items]);\n\n const internalItemsRef = useRef(internalItems);\n internalItemsRef.current = internalItems;\n\n const triggerOnChange = useTriggerableEffect(\n useCallback(\n (newItems: DragDropListItem<T>[], insertIndex?: number) => {\n onChange(newItems, insertIndex);\n },\n [onChange]\n )\n );\n\n const getTransformedItem = useCallback(\n (item: DragDropListItem<T>) => {\n if (!onEnter) {\n transformedItem.current = null;\n return item;\n }\n\n if (transformedItem.current) return transformedItem.current;\n\n const newItem = {\n ...item,\n ...onEnter(item),\n id: item.id\n };\n transformedItem.current = newItem;\n return newItem;\n },\n [onEnter]\n );\n\n const changeSource = useCallback(\n (itemId: DraggableItem<T>['id'], destinationId: string) => {\n const sourcePullMode = typeof pullMode === 'function' ? pullMode(destinationId) : pullMode;\n if (sourcePullMode === 'remove') {\n const newList = internalItems.filter(({ id }) => id !== itemId);\n triggerOnChange(newList);\n } else {\n setInternalItems(items);\n }\n },\n [pullMode, items, internalItems, triggerOnChange]\n );\n\n const getInsertIndex = useCallback(\n (item: DraggableItem<T>, monitor: DropTargetMonitor | DragSourceMonitor): number => {\n itemRectsRef.current = getItemRects();\n const { current: itemRects } = itemRectsRef;\n let insertIndex = -1;\n const prevIndex = internalItems.findIndex(({ id }) => id === item.id);\n\n const clientXY = monitor.getClientOffset();\n if (!itemRects || !clientXY) return insertIndex;\n\n const dragPreviewRectTop = clientXY.y;\n const atHead = dragPreviewRectTop < middleYOfRect(itemRects[0]);\n const atTail = dragPreviewRectTop >= middleYOfRect(itemRects[itemRects.length - 1]);\n\n if (atHead) {\n insertIndex = 0;\n } else if (atTail) {\n insertIndex = prevIndex === itemRects.length - 1 ? prevIndex : itemRects.length;\n } else {\n itemRects.some((rect, i, rects) => {\n if (i === rects.length - 1) {\n if (prevIndex === i) insertIndex = i;\n return true;\n }\n const belowCurrent = dragPreviewRectTop >= middleYOfRect(rect);\n const aboveNext = dragPreviewRectTop < middleYOfRect(rects[i + 1]);\n if (belowCurrent && aboveNext) {\n if (prevIndex !== -1 && i >= prevIndex) insertIndex = i;\n else insertIndex = i + 1;\n return true;\n }\n return false;\n });\n }\n\n return insertIndex;\n },\n [getItemRects, internalItems]\n );\n\n const removeById = useCallback((itemId: DraggableItem<T>['id']): void => {\n setInternalItems(currentItems => currentItems.filter(({ id }) => id !== itemId));\n }, []);\n\n const normalizeItems = useCallback(() => {\n setInternalItems(currentItems =>\n currentItems.map(({ id, data, type }) => ({\n id,\n data,\n type\n }))\n );\n }, []);\n\n const positionItems = useCallback(\n (item: DragDropListItem<T>, monitor: DropTargetMonitor): void => {\n if (!monitor.canDrop() || !monitor.isOver({ shallow: true })) return;\n\n const prevIndex = internalItems.findIndex(({ id }) => id === item.id);\n\n if (prevIndex === -1) {\n item.removeFromCurrent?.();\n item.removeFromCurrent = () => {\n removeById(item.id);\n };\n }\n\n item.normalizeDestination = normalizeItems;\n item.changeDestination = triggerOnChange;\n item.destinationItemsRef = internalItemsRef;\n item.transformedItemCache?.add(transformedItem);\n item.destinationId = listId;\n\n let insertIndex = 0;\n if (pushMode === 'insert') insertIndex = getInsertIndex(item, monitor);\n if (pushMode === 'append') insertIndex = internalItems.length + 1;\n\n let newItems: DraggableItem<T>[];\n\n // Is the current being dragged is within its own list\n if (prevIndex !== -1) {\n if (insertIndex === prevIndex || pushMode !== 'insert') return;\n\n newItems = internalItems.filter(({ id }) => id !== item.id);\n newItems.splice(insertIndex, 0, transformedItem.current ?? item);\n\n if (typeof pushMode === 'function') setInternalItems(newItems.sort(pushMode));\n else setInternalItems(newItems);\n } else {\n newItems = [...internalItems];\n newItems.splice(insertIndex, 0, getTransformedItem(item));\n\n if (typeof pushMode === 'function') setInternalItems(newItems.sort(pushMode));\n else setInternalItems(newItems);\n }\n },\n [internalItems, pushMode, getInsertIndex, normalizeItems, triggerOnChange, removeById, listId]\n );\n\n const onHover = positionItems;\n const onDrop = positionItems;\n\n const onBegin = useCallback(\n (itemId: DraggableItem<T>['id']) =>\n (): OmitStrict<DragDropListItem<T>, keyof DraggableItem<T>> => {\n const initialIndex = internalItems.findIndex(({ id }) => id === itemId);\n\n return {\n returnToSource: (item: DraggableItem<T>) => {\n setInternalItems(currentItems => {\n const newItems = currentItems.filter(({ id }) => id !== itemId);\n newItems.splice(initialIndex, 0, item);\n return newItems;\n });\n normalizeItems();\n },\n normalizeDestination: normalizeItems,\n changeSource,\n changeDestination: triggerOnChange,\n destinationItemsRef: internalItemsRef,\n transformedItemCache: new Set([transformedItem]),\n sourceId: listId,\n destinationId: listId\n };\n },\n [internalItems, normalizeItems, triggerOnChange, changeSource, removeById, listId]\n );\n\n const onEnd = useCallback(\n (item: DragDropListItem<T> | undefined, monitor: DragSourceMonitor) => {\n if (!item) return;\n\n if (monitor.didDrop()) {\n const { id: itemId, sourceId, destinationId } = item;\n let insertIndex;\n item.normalizeDestination?.();\n const destinationItems = item.destinationItemsRef!.current!;\n if (sourceId && destinationId && sourceId !== destinationId) {\n item.changeSource?.(itemId, destinationId);\n insertIndex = destinationItems.findIndex(({ id }) => id === itemId);\n }\n item.changeDestination?.(destinationItems, insertIndex);\n } else {\n item.removeFromCurrent?.();\n if (dragToRemove) {\n removeById(item.id);\n } else {\n item.returnToSource?.(item);\n }\n }\n item.transformedItemCache?.forEach(ref => {\n ref.current = null;\n });\n },\n [dragToRemove]\n );\n\n const emptyContent = EmptyRenderer ? <EmptyRenderer /> : null;\n\n return (\n <Droppable accept={accept} onHover={onHover} onDrop={onDrop}>\n {({ dropRef }) => {\n return (\n <Component\n ref={(el: HTMLElement) => {\n dropRef(el);\n setListEl(el);\n }}\n {...restProps}\n >\n {internalItems.length === 0\n ? emptyContent\n : internalItems.map(item => {\n return (\n <Draggable\n key={item.id}\n id={item.id}\n type={item.type}\n data={item.data}\n onBegin={onBegin(item.id)}\n onEnd={onEnd}\n >\n {({ dragRef, previewRef, collected }) => {\n return (\n <ItemRenderer\n {...{\n ...item,\n dragRef,\n previewRef,\n ...collected,\n isDragging: !!item.sourceId\n }}\n />\n );\n }}\n </Draggable>\n );\n })}\n </Component>\n );\n }}\n </Droppable>\n );\n};\n\nexport default DragDropList;\n"]}
|
|
@@ -7,6 +7,8 @@ export interface ItemRendererProps<T extends object = object> extends DraggableI
|
|
|
7
7
|
previewRef: RefCallback<HTMLElement>;
|
|
8
8
|
}
|
|
9
9
|
export interface DragDropListProps<T extends object = object> extends AsProp, BaseProps, NoChildrenProp {
|
|
10
|
+
/** Unique identifier for the list */
|
|
11
|
+
id?: string;
|
|
10
12
|
/** Type of item allowed to be dropped on this list (useful when there is multiple lists that share data). */
|
|
11
13
|
accept: DroppableProps['accept'];
|
|
12
14
|
/** Array of data objects used for the list. */
|
|
@@ -14,7 +16,7 @@ export interface DragDropListProps<T extends object = object> extends AsProp, Ba
|
|
|
14
16
|
/**
|
|
15
17
|
* @default "remove"
|
|
16
18
|
*/
|
|
17
|
-
pullMode?: 'clone' | 'remove';
|
|
19
|
+
pullMode?: 'clone' | 'remove' | ((destinationId: string) => 'clone' | 'remove');
|
|
18
20
|
/**
|
|
19
21
|
* @default "insert"
|
|
20
22
|
*/
|
|
@@ -26,6 +28,11 @@ export interface DragDropListProps<T extends object = object> extends AsProp, Ba
|
|
|
26
28
|
* @default false
|
|
27
29
|
*/
|
|
28
30
|
dragHandles?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Enables "Drag to remove from list" behavior
|
|
33
|
+
* @default false
|
|
34
|
+
*/
|
|
35
|
+
dragToRemove?: boolean;
|
|
29
36
|
/** User defined function(Component) that should return content for when the list is empty. */
|
|
30
37
|
emptyRenderer?: ComponentType;
|
|
31
38
|
/** Called when list data is updated. "insertIndex" is only defined when a new item has been added to the list. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DragDropList.types.d.ts","sourceRoot":"","sources":["../../../src/components/DragDropList/DragDropList.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEnD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAE5E,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAA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,EACZ,SAAS,EACT,cAAc;IAChB,qCAAqC;IACrC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,6GAA6G;IAC7G,MAAM,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC;IACjC,+CAA+C;IAC/C,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1B;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,CAAC,CAAC,aAAa,EAAE,MAAM,KAAK,OAAO,GAAG,QAAQ,CAAC,CAAC;IAChF;;OAEG;IACH,QAAQ,CAAC,EACL,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC;IAC3D,kFAAkF;IAClF,YAAY,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;IAClD;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,8FAA8F;IAC9F,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,kHAAkH;IAClH,QAAQ,EAAE,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/E,oGAAoG;IACpG,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,aAAa,CAAC,CAAC,CAAC,CAAC;CACxD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DragDropList.types.js","sourceRoot":"","sources":["../../../src/components/DragDropList/DragDropList.types.ts"],"names":[],"mappings":"","sourcesContent":["import { RefCallback, ComponentType } from 'react';\n\nimport { AsProp, BaseProps, NoChildrenProp } from '@pega/cosmos-react-core';\n\nimport { DraggableItem, DraggableCollectedProps } from '../Draggable';\nimport { DroppableProps } from '../Droppable';\n\nexport interface ItemRendererProps<T extends object = object>\n extends DraggableItem<T>,\n DraggableCollectedProps {\n dragRef: RefCallback<HTMLElement>;\n previewRef: RefCallback<HTMLElement>;\n}\n\nexport interface DragDropListProps<T extends object = object>\n extends AsProp,\n BaseProps,\n NoChildrenProp {\n /** Type of item allowed to be dropped on this list (useful when there is multiple lists that share data). */\n accept: DroppableProps['accept'];\n /** Array of data objects used for the list. */\n items: DraggableItem<T>[];\n /**\n * @default \"remove\"\n */\n pullMode?: 'clone' | 'remove';\n /**\n * @default \"insert\"\n */\n pushMode?:\n | 'insert'\n | 'prepend'\n | 'append'\n | ((a: DraggableItem<T>, b: DraggableItem<T>) => number);\n /** User defined function that should return content for the draggable element. */\n itemRenderer: ComponentType<ItemRendererProps<T>>;\n /**\n * Enable drag handle elements for each of the list items. By default the entire element is draggable.\n * @default false\n */\n dragHandles?: boolean;\n /** User defined function(Component) that should return content for when the list is empty. */\n emptyRenderer?: ComponentType;\n /** Called when list data is updated. \"insertIndex\" is only defined when a new item has been added to the list. */\n onChange: (items: DragDropListProps<T>['items'], insertIndex?: number) => void;\n /** Called when an item enters a list. Allows for transformation of the item to fit the new list. */\n onEnter?: (item: DraggableItem<T>) => DraggableItem<T>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DragDropList.types.js","sourceRoot":"","sources":["../../../src/components/DragDropList/DragDropList.types.ts"],"names":[],"mappings":"","sourcesContent":["import { RefCallback, ComponentType } from 'react';\n\nimport { AsProp, BaseProps, NoChildrenProp } from '@pega/cosmos-react-core';\n\nimport { DraggableItem, DraggableCollectedProps } from '../Draggable';\nimport { DroppableProps } from '../Droppable';\n\nexport interface ItemRendererProps<T extends object = object>\n extends DraggableItem<T>,\n DraggableCollectedProps {\n dragRef: RefCallback<HTMLElement>;\n previewRef: RefCallback<HTMLElement>;\n}\n\nexport interface DragDropListProps<T extends object = object>\n extends AsProp,\n BaseProps,\n NoChildrenProp {\n /** Unique identifier for the list */\n id?: string;\n /** Type of item allowed to be dropped on this list (useful when there is multiple lists that share data). */\n accept: DroppableProps['accept'];\n /** Array of data objects used for the list. */\n items: DraggableItem<T>[];\n /**\n * @default \"remove\"\n */\n pullMode?: 'clone' | 'remove' | ((destinationId: string) => 'clone' | 'remove');\n /**\n * @default \"insert\"\n */\n pushMode?:\n | 'insert'\n | 'prepend'\n | 'append'\n | ((a: DraggableItem<T>, b: DraggableItem<T>) => number);\n /** User defined function that should return content for the draggable element. */\n itemRenderer: ComponentType<ItemRendererProps<T>>;\n /**\n * Enable drag handle elements for each of the list items. By default the entire element is draggable.\n * @default false\n */\n dragHandles?: boolean;\n /**\n * Enables \"Drag to remove from list\" behavior\n * @default false\n */\n dragToRemove?: boolean;\n /** User defined function(Component) that should return content for when the list is empty. */\n emptyRenderer?: ComponentType;\n /** Called when list data is updated. \"insertIndex\" is only defined when a new item has been added to the list. */\n onChange: (items: DragDropListProps<T>['items'], insertIndex?: number) => void;\n /** Called when an item enters a list. Allows for transformation of the item to fit the new list. */\n onEnter?: (item: DraggableItem<T>) => DraggableItem<T>;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DragDropManager.d.ts","sourceRoot":"","sources":["../../../src/components/DragDropManager/DragDropManager.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIrD,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"DragDropManager.d.ts","sourceRoot":"","sources":["../../../src/components/DragDropManager/DragDropManager.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIrD,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,SAAS,CAAC;IACpB,WAAW,CAAC,EAAE,IAAI,CAAC;CACpB;AAED,QAAA,MAAM,eAAe,EAAE,iBAAiB,CAAC,oBAAoB,CAS5D,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { DndProvider } from 'react-dnd';
|
|
3
3
|
import { HTML5Backend } from 'react-dnd-html5-backend';
|
|
4
|
-
const DragDropManager = ({ children }) => {
|
|
5
|
-
return _jsx(DndProvider, { backend: HTML5Backend, children: children });
|
|
4
|
+
const DragDropManager = ({ children, rootElement }) => {
|
|
5
|
+
return (_jsx(DndProvider, { backend: HTML5Backend, options: { rootElement }, children: children }));
|
|
6
6
|
};
|
|
7
7
|
export default DragDropManager;
|
|
8
8
|
//# sourceMappingURL=DragDropManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DragDropManager.js","sourceRoot":"","sources":["../../../src/components/DragDropManager/DragDropManager.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"DragDropManager.js","sourceRoot":"","sources":["../../../src/components/DragDropManager/DragDropManager.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAOvD,MAAM,eAAe,GAA4C,CAAC,EAChE,QAAQ,EACR,WAAW,EACU,EAAE,EAAE;IACzB,OAAO,CACL,KAAC,WAAW,IAAC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,EAAE,WAAW,EAAE,YACzD,QAAQ,GACG,CACf,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { FunctionComponent, ReactNode } from 'react';\nimport { DndProvider } from 'react-dnd';\nimport { HTML5Backend } from 'react-dnd-html5-backend';\n\nexport interface DragDropManagerProps {\n children: ReactNode;\n rootElement?: Node;\n}\n\nconst DragDropManager: FunctionComponent<DragDropManagerProps> = ({\n children,\n rootElement\n}: DragDropManagerProps) => {\n return (\n <DndProvider backend={HTML5Backend} options={{ rootElement }}>\n {children}\n </DndProvider>\n );\n};\n\nexport default DragDropManager;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pega/cosmos-react-dnd",
|
|
3
|
-
"version": "4.0.0-dev.
|
|
3
|
+
"version": "4.0.0-dev.6.1",
|
|
4
4
|
"author": "Pegasystems",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"repository": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"build": "tsc -b"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@pega/cosmos-react-core": "4.0.0-dev.
|
|
23
|
+
"@pega/cosmos-react-core": "4.0.0-dev.6.1",
|
|
24
24
|
"@types/react": "^16.14.24 || ^17.0.38",
|
|
25
25
|
"@types/react-dom": "^16.9.14 || ^17.0.11",
|
|
26
26
|
"@types/styled-components": "^5.1.26",
|