@pega/cosmos-react-dnd 5.0.0-dev.4.9 → 5.0.0-dev.6.0

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.
Files changed (61) hide show
  1. package/lib/components/DragDropList/DragDropList.d.ts +6 -0
  2. package/lib/components/DragDropList/DragDropList.d.ts.map +1 -0
  3. package/lib/components/DragDropList/DragDropList.js +207 -0
  4. package/lib/components/DragDropList/DragDropList.js.map +1 -0
  5. package/lib/components/DragDropList/DragDropList.types.d.ts +39 -0
  6. package/lib/components/DragDropList/DragDropList.types.d.ts.map +1 -0
  7. package/lib/components/DragDropList/DragDropList.types.js +2 -0
  8. package/lib/components/DragDropList/DragDropList.types.js.map +1 -0
  9. package/lib/components/DragDropList/index.d.ts +3 -0
  10. package/lib/components/DragDropList/index.d.ts.map +1 -0
  11. package/lib/components/DragDropList/index.js +2 -0
  12. package/lib/components/DragDropList/index.js.map +1 -0
  13. package/lib/components/DragDropManager/DragDropManager.d.ts +8 -0
  14. package/lib/components/DragDropManager/DragDropManager.d.ts.map +1 -0
  15. package/lib/components/DragDropManager/DragDropManager.js +8 -0
  16. package/lib/components/DragDropManager/DragDropManager.js.map +1 -0
  17. package/lib/components/DragDropManager/index.d.ts +3 -0
  18. package/lib/components/DragDropManager/index.d.ts.map +1 -0
  19. package/lib/components/DragDropManager/index.js +2 -0
  20. package/lib/components/DragDropManager/index.js.map +1 -0
  21. package/lib/components/Draggable/Draggable.d.ts +28 -0
  22. package/lib/components/Draggable/Draggable.d.ts.map +1 -0
  23. package/lib/components/Draggable/Draggable.js +24 -0
  24. package/lib/components/Draggable/Draggable.js.map +1 -0
  25. package/lib/components/Draggable/index.d.ts +3 -0
  26. package/lib/components/Draggable/index.d.ts.map +1 -0
  27. package/lib/components/Draggable/index.js +2 -0
  28. package/lib/components/Draggable/index.js.map +1 -0
  29. package/lib/components/Droppable/Droppable.d.ts +23 -0
  30. package/lib/components/Droppable/Droppable.d.ts.map +1 -0
  31. package/lib/components/Droppable/Droppable.js +15 -0
  32. package/lib/components/Droppable/Droppable.js.map +1 -0
  33. package/lib/components/Droppable/index.d.ts +3 -0
  34. package/lib/components/Droppable/index.d.ts.map +1 -0
  35. package/lib/components/Droppable/index.js +2 -0
  36. package/lib/components/Droppable/index.js.map +1 -0
  37. package/lib/components/StandardDragDropList/StandardDragDropList.d.ts +8 -0
  38. package/lib/components/StandardDragDropList/StandardDragDropList.d.ts.map +1 -0
  39. package/lib/components/StandardDragDropList/StandardDragDropList.js +157 -0
  40. package/lib/components/StandardDragDropList/StandardDragDropList.js.map +1 -0
  41. package/lib/components/StandardDragDropList/StandardDragDropList.styles.d.ts +15 -0
  42. package/lib/components/StandardDragDropList/StandardDragDropList.styles.d.ts.map +1 -0
  43. package/lib/components/StandardDragDropList/StandardDragDropList.styles.js +142 -0
  44. package/lib/components/StandardDragDropList/StandardDragDropList.styles.js.map +1 -0
  45. package/lib/components/StandardDragDropList/StandardDragDropList.test-ids.d.ts +3 -0
  46. package/lib/components/StandardDragDropList/StandardDragDropList.test-ids.d.ts.map +1 -0
  47. package/lib/components/StandardDragDropList/StandardDragDropList.test-ids.js +11 -0
  48. package/lib/components/StandardDragDropList/StandardDragDropList.test-ids.js.map +1 -0
  49. package/lib/components/StandardDragDropList/StandardDragDropList.types.d.ts +68 -0
  50. package/lib/components/StandardDragDropList/StandardDragDropList.types.d.ts.map +1 -0
  51. package/lib/components/StandardDragDropList/StandardDragDropList.types.js +2 -0
  52. package/lib/components/StandardDragDropList/StandardDragDropList.types.js.map +1 -0
  53. package/lib/components/StandardDragDropList/index.d.ts +3 -0
  54. package/lib/components/StandardDragDropList/index.d.ts.map +1 -0
  55. package/lib/components/StandardDragDropList/index.js +2 -0
  56. package/lib/components/StandardDragDropList/index.js.map +1 -0
  57. package/lib/index.d.ts +11 -0
  58. package/lib/index.d.ts.map +1 -0
  59. package/lib/index.js +12 -0
  60. package/lib/index.js.map +1 -0
  61. package/package.json +2 -2
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import type { ForwardProps } from '@pega/cosmos-react-core';
3
+ import type { DragDropListProps } from './DragDropList.types';
4
+ declare const DragDropList: <T extends object = object>({ testId, id: idProp, accept, items, itemRenderer: ItemRenderer, emptyRenderer: EmptyRenderer, onChange, onEnter, pullMode, pushMode, dragToRemove, as: Component, ...restProps }: DragDropListProps<T> & ForwardProps) => JSX.Element;
5
+ export default DragDropList;
6
+ //# sourceMappingURL=DragDropList.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DragDropList.d.ts","sourceRoot":"","sources":["../../../src/components/DragDropList/DragDropList.tsx"],"names":[],"mappings":";AAUA,OAAO,KAAK,EAAE,YAAY,EAAc,MAAM,yBAAyB,CAAC;AAMxE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAgB9D,QAAA,MAAM,YAAY,oQAwRjB,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -0,0 +1,207 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useCallback, useState, useRef } from 'react';
3
+ import { useElement, useAfterInitialEffect, useTriggerableEffect, useUID } from '@pega/cosmos-react-core';
4
+ import Draggable from '../Draggable';
5
+ import Droppable from '../Droppable';
6
+ const middleYOfRect = ({ top, bottom }) => top + (bottom - top) / 2;
7
+ const DragDropList = ({ testId, id: idProp, accept, items, itemRenderer: ItemRenderer, emptyRenderer: EmptyRenderer, onChange, onEnter, pullMode = 'remove', pushMode = 'insert', dragToRemove = false, as: Component = 'ul', ...restProps }) => {
8
+ const [internalItems, setInternalItems] = useState(items);
9
+ const itemRectsRef = useRef(null);
10
+ const transformedItem = useRef(null);
11
+ const [listEl, setListEl] = useElement();
12
+ const uniqueId = useUID();
13
+ const listId = idProp ?? uniqueId;
14
+ const getItemRects = useCallback(() => {
15
+ if (!listEl || listEl.children.length === 0)
16
+ return null;
17
+ return [...listEl.children].map(itemEl => {
18
+ return itemEl.getBoundingClientRect();
19
+ });
20
+ }, [listEl]);
21
+ useAfterInitialEffect(() => {
22
+ setInternalItems(items);
23
+ }, [items]);
24
+ const internalItemsRef = useRef(internalItems);
25
+ internalItemsRef.current = internalItems;
26
+ const triggerOnChange = useTriggerableEffect(useCallback((newItems, insertIndex) => {
27
+ onChange(newItems, insertIndex);
28
+ }, [onChange]));
29
+ const getTransformedItem = useCallback((item) => {
30
+ if (!onEnter) {
31
+ transformedItem.current = null;
32
+ return item;
33
+ }
34
+ if (transformedItem.current)
35
+ return transformedItem.current;
36
+ const newItem = {
37
+ ...item,
38
+ ...onEnter(item),
39
+ id: item.id
40
+ };
41
+ transformedItem.current = newItem;
42
+ return newItem;
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]);
54
+ const getInsertIndex = useCallback((item, monitor) => {
55
+ itemRectsRef.current = getItemRects();
56
+ const { current: itemRects } = itemRectsRef;
57
+ let insertIndex = -1;
58
+ const prevIndex = internalItems.findIndex(({ id }) => id === item.id);
59
+ const clientXY = monitor.getClientOffset();
60
+ if (!itemRects || !clientXY)
61
+ return insertIndex;
62
+ const dragPreviewRectTop = clientXY.y;
63
+ const atHead = dragPreviewRectTop < middleYOfRect(itemRects[0]);
64
+ const atTail = dragPreviewRectTop >= middleYOfRect(itemRects[itemRects.length - 1]);
65
+ if (atHead) {
66
+ insertIndex = 0;
67
+ }
68
+ else if (atTail) {
69
+ insertIndex = prevIndex === itemRects.length - 1 ? prevIndex : itemRects.length;
70
+ }
71
+ else {
72
+ itemRects.some((rect, i, rects) => {
73
+ if (i === rects.length - 1) {
74
+ if (prevIndex === i)
75
+ insertIndex = i;
76
+ return true;
77
+ }
78
+ const belowCurrent = dragPreviewRectTop >= middleYOfRect(rect);
79
+ const aboveNext = dragPreviewRectTop < middleYOfRect(rects[i + 1]);
80
+ if (belowCurrent && aboveNext) {
81
+ if (prevIndex !== -1 && i >= prevIndex)
82
+ insertIndex = i;
83
+ else
84
+ insertIndex = i + 1;
85
+ return true;
86
+ }
87
+ return false;
88
+ });
89
+ }
90
+ return insertIndex;
91
+ }, [getItemRects, internalItems]);
92
+ const removeById = useCallback((itemId) => {
93
+ setInternalItems(currentItems => currentItems.filter(({ id }) => id !== itemId));
94
+ }, []);
95
+ const normalizeItems = useCallback(() => {
96
+ setInternalItems(currentItems => currentItems.map(({ id, data, type }) => ({
97
+ id,
98
+ data,
99
+ type
100
+ })));
101
+ }, []);
102
+ const positionItems = useCallback((item, monitor) => {
103
+ if (!monitor.canDrop() || !monitor.isOver({ shallow: true }))
104
+ return;
105
+ const prevIndex = internalItems.findIndex(({ id }) => id === item.id);
106
+ if (prevIndex === -1) {
107
+ item.removeFromCurrent?.();
108
+ item.removeFromCurrent = () => {
109
+ removeById(item.id);
110
+ };
111
+ }
112
+ item.normalizeDestination = normalizeItems;
113
+ item.changeDestination = triggerOnChange;
114
+ item.destinationItemsRef = internalItemsRef;
115
+ item.transformedItemCache?.add(transformedItem);
116
+ item.destinationId = listId;
117
+ let insertIndex = 0;
118
+ if (pushMode === 'insert')
119
+ insertIndex = getInsertIndex(item, monitor);
120
+ if (pushMode === 'append')
121
+ insertIndex = internalItems.length + 1;
122
+ let newItems;
123
+ // Is the current being dragged is within its own list
124
+ if (prevIndex !== -1) {
125
+ if (insertIndex === prevIndex || pushMode !== 'insert')
126
+ return;
127
+ newItems = internalItems.filter(({ id }) => id !== item.id);
128
+ newItems.splice(insertIndex, 0, transformedItem.current ?? item);
129
+ if (typeof pushMode === 'function')
130
+ setInternalItems(newItems.sort(pushMode));
131
+ else
132
+ setInternalItems(newItems);
133
+ }
134
+ else {
135
+ newItems = [...internalItems];
136
+ newItems.splice(insertIndex, 0, getTransformedItem(item));
137
+ if (typeof pushMode === 'function')
138
+ setInternalItems(newItems.sort(pushMode));
139
+ else
140
+ setInternalItems(newItems);
141
+ }
142
+ }, [internalItems, pushMode, getInsertIndex, normalizeItems, triggerOnChange, removeById, listId]);
143
+ const onHover = positionItems;
144
+ const onDrop = positionItems;
145
+ const onBegin = useCallback((itemId) => () => {
146
+ const initialIndex = internalItems.findIndex(({ id }) => id === itemId);
147
+ return {
148
+ returnToSource: (item) => {
149
+ setInternalItems(currentItems => {
150
+ const newItems = currentItems.filter(({ id }) => id !== itemId);
151
+ newItems.splice(initialIndex, 0, item);
152
+ return newItems;
153
+ });
154
+ normalizeItems();
155
+ },
156
+ normalizeDestination: normalizeItems,
157
+ changeSource,
158
+ changeDestination: triggerOnChange,
159
+ destinationItemsRef: internalItemsRef,
160
+ transformedItemCache: new Set([transformedItem]),
161
+ sourceId: listId,
162
+ destinationId: listId
163
+ };
164
+ }, [internalItems, normalizeItems, triggerOnChange, changeSource, removeById, listId]);
165
+ const onEnd = useCallback((item, monitor) => {
166
+ if (!item)
167
+ return;
168
+ if (monitor.didDrop()) {
169
+ const { id: itemId, sourceId, destinationId } = item;
170
+ let insertIndex;
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);
176
+ }
177
+ item.changeDestination?.(destinationItems, insertIndex);
178
+ }
179
+ else {
180
+ item.removeFromCurrent?.();
181
+ if (dragToRemove) {
182
+ triggerOnChange(internalItems.filter(({ id }) => id !== item.id));
183
+ }
184
+ else {
185
+ item.returnToSource?.(item);
186
+ }
187
+ }
188
+ item.transformedItemCache?.forEach(ref => {
189
+ ref.current = null;
190
+ });
191
+ }, [dragToRemove, internalItems, triggerOnChange]);
192
+ const emptyContent = EmptyRenderer ? _jsx(EmptyRenderer, {}) : null;
193
+ return (_jsx(Droppable, { accept: accept, onHover: onHover, onDrop: onDrop, children: ({ dropRef }) => {
194
+ return (_jsx(Component, { ref: (el) => {
195
+ dropRef(el);
196
+ setListEl(el);
197
+ }, ...restProps, children: internalItems.length === 0
198
+ ? emptyContent
199
+ : internalItems.map(item => {
200
+ return (_jsx(Draggable, { id: item.id, type: item.type, data: item.data, onBegin: onBegin(item.id), onEnd: onEnd, children: ({ dragRef, previewRef, collected }) => {
201
+ return (_jsx(ItemRenderer, { testId: testId, ...item, dragRef: dragRef, previewRef: previewRef, ...collected, isDragging: !!item.sourceId }));
202
+ } }, item.id));
203
+ }) }));
204
+ } }));
205
+ };
206
+ export default DragDropList;
207
+ //# sourceMappingURL=DragDropList.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DragDropList.js","sourceRoot":"","sources":["../../../src/components/DragDropList/DragDropList.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAItD,OAAO,EACL,UAAU,EACV,qBAAqB,EACrB,oBAAoB,EACpB,MAAM,EACP,MAAM,yBAAyB,CAAC;AAGjC,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,SAAS,MAAM,cAAc,CAAC;AAgBrC,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,EAAE,EAAE,MAAM,EACV,MAAM,EACN,KAAK,EACL,YAAY,EAAE,YAAY,EAC1B,aAAa,EAAE,aAAa,EAC5B,QAAQ,EACR,OAAO,EACP,QAAQ,GAAG,QAAQ,EACnB,QAAQ,GAAG,QAAQ,EACnB,YAAY,GAAG,KAAK,EACpB,EAAE,EAAE,SAAS,GAAG,IAAI,EACpB,GAAG,SAAS,EACwB,EAAE,EAAE;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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,IACX,MAAM,EAAE,MAAM,KACV,IAAI,EACR,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,UAAU,KAClB,SAAS,EACb,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,GAC3B,CACH,CAAC;4BACJ,CAAC,IAlBI,IAAI,CAAC,EAAE,CAmBF,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 } from 'react';\nimport type { RefObject, MutableRefObject } from 'react';\nimport type { DragSourceMonitor, DropTargetMonitor } from 'react-dnd';\n\nimport {\n useElement,\n useAfterInitialEffect,\n useTriggerableEffect,\n useUID\n} from '@pega/cosmos-react-core';\nimport type { ForwardProps, OmitStrict } from '@pega/cosmos-react-core';\n\nimport Draggable from '../Draggable';\nimport type { DraggableItem } from '../Draggable';\nimport Droppable from '../Droppable';\n\nimport type { 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 testId,\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 triggerOnChange(internalItems.filter(({ id }) => id !== item.id));\n } else {\n item.returnToSource?.(item);\n }\n }\n item.transformedItemCache?.forEach(ref => {\n ref.current = null;\n });\n },\n [dragToRemove, internalItems, triggerOnChange]\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 testId={testId}\n {...item}\n dragRef={dragRef}\n previewRef={previewRef}\n {...collected}\n isDragging={!!item.sourceId}\n />\n );\n }}\n </Draggable>\n );\n })}\n </Component>\n );\n }}\n </Droppable>\n );\n};\n\nexport default DragDropList;\n"]}
@@ -0,0 +1,39 @@
1
+ import type { RefCallback, ComponentType } from 'react';
2
+ import type { AsProp, BaseProps, NoChildrenProp, TestIdProp } from '@pega/cosmos-react-core';
3
+ import type { DraggableItem, DraggableCollectedProps } from '../Draggable';
4
+ import type { DroppableProps } from '../Droppable';
5
+ export interface ItemRendererProps<T extends object = object> extends DraggableItem<T>, DraggableCollectedProps, TestIdProp {
6
+ dragRef: RefCallback<HTMLElement>;
7
+ previewRef: RefCallback<HTMLElement>;
8
+ }
9
+ export interface DragDropListProps<T extends object = object> extends AsProp, BaseProps, NoChildrenProp, TestIdProp {
10
+ /** Unique identifier for the list */
11
+ id?: string;
12
+ /** Type of item allowed to be dropped on this list (useful when there is multiple lists that share data). */
13
+ accept: DroppableProps['accept'];
14
+ /** Array of data objects used for the list. */
15
+ items: DraggableItem<T>[];
16
+ /** @default 'remove' */
17
+ pullMode?: 'clone' | 'remove' | ((destinationId: string) => 'clone' | 'remove');
18
+ /** @default 'insert' */
19
+ pushMode?: 'insert' | 'prepend' | 'append' | ((a: DraggableItem<T>, b: DraggableItem<T>) => number);
20
+ /** User defined function that should return content for the draggable element. */
21
+ itemRenderer: ComponentType<ItemRendererProps<T>>;
22
+ /**
23
+ * Enable drag handle elements for each of the list items. By default the entire element is draggable.
24
+ * @default false
25
+ */
26
+ dragHandles?: boolean;
27
+ /**
28
+ * Enables "Drag to remove from list" behavior
29
+ * @default false
30
+ */
31
+ dragToRemove?: boolean;
32
+ /** User defined function(Component) that should return content for when the list is empty. */
33
+ emptyRenderer?: ComponentType;
34
+ /** Called when list data is updated. "insertIndex" is only defined when a new item has been added to the list. */
35
+ onChange: (items: DragDropListProps<T>['items'], insertIndex?: number) => void;
36
+ /** Called when an item enters a list. Allows for transformation of the item to fit the new list. */
37
+ onEnter?: (item: DraggableItem<T>) => DraggableItem<T>;
38
+ }
39
+ //# sourceMappingURL=DragDropList.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DragDropList.types.d.ts","sourceRoot":"","sources":["../../../src/components/DragDropList/DragDropList.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,OAAO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AAY,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"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=DragDropList.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DragDropList.types.js","sourceRoot":"","sources":["../../../src/components/DragDropList/DragDropList.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { RefCallback, ComponentType } from 'react';\n\nimport type { AsProp, BaseProps, NoChildrenProp, TestIdProp } from '@pega/cosmos-react-core';\n\nimport type { DraggableItem, DraggableCollectedProps } from '../Draggable';\nimport type { DroppableProps } from '../Droppable';\n\nexport interface ItemRendererProps<T extends object = object>\n extends DraggableItem<T>,\n DraggableCollectedProps,\n TestIdProp {\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 TestIdProp {\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 /** @default 'remove' */\n pullMode?: 'clone' | 'remove' | ((destinationId: string) => 'clone' | 'remove');\n /** @default 'insert' */\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"]}
@@ -0,0 +1,3 @@
1
+ export { default } from './DragDropList';
2
+ export type { DragDropListProps, ItemRendererProps } from './DragDropList.types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/DragDropList/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { default } from './DragDropList';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/DragDropList/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["export { default } from './DragDropList';\nexport type { DragDropListProps, ItemRendererProps } from './DragDropList.types';\n"]}
@@ -0,0 +1,8 @@
1
+ import type { FunctionComponent, ReactNode } from 'react';
2
+ export interface DragDropManagerProps {
3
+ children: ReactNode;
4
+ rootElement?: Node;
5
+ }
6
+ declare const DragDropManager: FunctionComponent<DragDropManagerProps>;
7
+ export default DragDropManager;
8
+ //# sourceMappingURL=DragDropManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DragDropManager.d.ts","sourceRoot":"","sources":["../../../src/components/DragDropManager/DragDropManager.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAI1D,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"}
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { DndProvider } from 'react-dnd';
3
+ import { HTML5Backend } from 'react-dnd-html5-backend';
4
+ const DragDropManager = ({ children, rootElement }) => {
5
+ return (_jsx(DndProvider, { backend: HTML5Backend, options: { rootElement }, children: children }));
6
+ };
7
+ export default DragDropManager;
8
+ //# sourceMappingURL=DragDropManager.js.map
@@ -0,0 +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;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 type { 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"]}
@@ -0,0 +1,3 @@
1
+ export { default } from './DragDropManager';
2
+ export type { DragDropManagerProps } from './DragDropManager';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/DragDropManager/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,YAAY,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { default } from './DragDropManager';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/DragDropManager/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC","sourcesContent":["export { default } from './DragDropManager';\nexport type { DragDropManagerProps } from './DragDropManager';\n"]}
@@ -0,0 +1,28 @@
1
+ import type { RefCallback, ReactElement } from 'react';
2
+ import type { DragSourceMonitor } from 'react-dnd';
3
+ import type { SourceType } from 'dnd-core';
4
+ export interface DraggableItem<T extends object | undefined = object | undefined> {
5
+ /** Draggable item id */
6
+ id: string;
7
+ /** Draggable item type */
8
+ type: SourceType;
9
+ /** Arbitrary data associated with this drag item */
10
+ data: T;
11
+ }
12
+ export interface DraggableCollectedProps {
13
+ isDragging: boolean;
14
+ dragEl: HTMLElement | null;
15
+ }
16
+ export interface DraggableProps<T extends object = object> extends DraggableItem<T> {
17
+ onBegin?: (monitor: DragSourceMonitor) => object;
18
+ /** Called when drag item is dropped on a valid drop target */
19
+ onEnd?: (item: DraggableItem<T> | undefined, monitor: DragSourceMonitor) => void;
20
+ children: (props: {
21
+ dragRef: RefCallback<HTMLElement>;
22
+ previewRef: RefCallback<HTMLElement>;
23
+ collected: DraggableCollectedProps;
24
+ }) => ReactElement;
25
+ }
26
+ declare const Draggable: <T extends object = object>({ id, type, data, onBegin, onEnd, children }: DraggableProps<T>) => ReactElement<any, string | import("react").JSXElementConstructor<any>>;
27
+ export default Draggable;
28
+ //# sourceMappingURL=Draggable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Draggable.d.ts","sourceRoot":"","sources":["../../../src/components/Draggable/Draggable.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAoB,WAAW,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAEzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS;IAC9E,wBAAwB;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,0BAA0B;IAC1B,IAAI,EAAE,UAAU,CAAC;IACjB,oDAAoD;IACpD,IAAI,EAAE,CAAC,CAAC;CACT;AAED,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;IACjF,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,MAAM,CAAC;IACjD,8DAA8D;IAC9D,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,SAAS,EAAE,OAAO,EAAE,iBAAiB,KAAK,IAAI,CAAC;IACjF,QAAQ,EAAE,CAAC,KAAK,EAAE;QAChB,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;QAClC,UAAU,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;QACrC,SAAS,EAAE,uBAAuB,CAAC;KACpC,KAAK,YAAY,CAAC;CACpB;AAED,QAAA,MAAM,SAAS,wKA+Bd,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { useRef } from 'react';
2
+ import { useDrag } from 'react-dnd';
3
+ const Draggable = ({ id, type, data, onBegin, onEnd, children }) => {
4
+ const dragElRef = useRef(null);
5
+ const [collected, dragRef, previewRef] = useDrag(() => ({
6
+ type,
7
+ item: monitor => ({ ...onBegin?.(monitor), id, type, data }),
8
+ end: onEnd,
9
+ collect: monitor => ({
10
+ isDragging: monitor.isDragging(),
11
+ dragEl: dragElRef.current
12
+ })
13
+ }), [id, type, data, onBegin, onEnd]);
14
+ return children({
15
+ dragRef: (el) => {
16
+ dragElRef.current = el;
17
+ dragRef(el);
18
+ },
19
+ previewRef,
20
+ collected
21
+ });
22
+ };
23
+ export default Draggable;
24
+ //# sourceMappingURL=Draggable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Draggable.js","sourceRoot":"","sources":["../../../src/components/Draggable/Draggable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA6BpC,MAAM,SAAS,GAAG,CAA4B,EAC5C,EAAE,EACF,IAAI,EACJ,IAAI,EACJ,OAAO,EACP,KAAK,EACL,QAAQ,EACU,EAAE,EAAE;IACtB,MAAM,SAAS,GAAyC,MAAM,CAAc,IAAI,CAAC,CAAC;IAElF,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,UAAU,CAAC,GAAG,OAAO,CAC9C,GAAG,EAAE,CAAC,CAAC;QACL,IAAI;QACJ,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QAC5D,GAAG,EAAE,KAAK;QACV,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;YACnB,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE;YAChC,MAAM,EAAE,SAAS,CAAC,OAAO;SAC1B,CAAC;KACH,CAAC,EACF,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CACjC,CAAC;IAEF,OAAO,QAAQ,CAAC;QACd,OAAO,EAAE,CAAC,EAAe,EAAE,EAAE;YAC3B,SAAS,CAAC,OAAO,GAAG,EAAE,CAAC;YACvB,OAAO,CAAC,EAAE,CAAC,CAAC;QACd,CAAC;QACD,UAAU;QACV,SAAS;KACV,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,eAAe,SAAS,CAAC","sourcesContent":["import { useRef } from 'react';\nimport type { MutableRefObject, RefCallback, ReactElement } from 'react';\nimport { useDrag } from 'react-dnd';\nimport type { DragSourceMonitor } from 'react-dnd';\nimport type { SourceType } from 'dnd-core';\n\nexport interface DraggableItem<T extends object | undefined = object | undefined> {\n /** Draggable item id */\n id: string;\n /** Draggable item type */\n type: SourceType;\n /** Arbitrary data associated with this drag item */\n data: T;\n}\n\nexport interface DraggableCollectedProps {\n isDragging: boolean;\n dragEl: HTMLElement | null;\n}\n\nexport interface DraggableProps<T extends object = object> extends DraggableItem<T> {\n onBegin?: (monitor: DragSourceMonitor) => object;\n /** Called when drag item is dropped on a valid drop target */\n onEnd?: (item: DraggableItem<T> | undefined, monitor: DragSourceMonitor) => void;\n children: (props: {\n dragRef: RefCallback<HTMLElement>;\n previewRef: RefCallback<HTMLElement>;\n collected: DraggableCollectedProps;\n }) => ReactElement;\n}\n\nconst Draggable = <T extends object = object>({\n id,\n type,\n data,\n onBegin,\n onEnd,\n children\n}: DraggableProps<T>) => {\n const dragElRef: MutableRefObject<HTMLElement | null> = useRef<HTMLElement>(null);\n\n const [collected, dragRef, previewRef] = useDrag(\n () => ({\n type,\n item: monitor => ({ ...onBegin?.(monitor), id, type, data }),\n end: onEnd,\n collect: monitor => ({\n isDragging: monitor.isDragging(),\n dragEl: dragElRef.current\n })\n }),\n [id, type, data, onBegin, onEnd]\n );\n\n return children({\n dragRef: (el: HTMLElement) => {\n dragElRef.current = el;\n dragRef(el);\n },\n previewRef,\n collected\n });\n};\n\nexport default Draggable;\n"]}
@@ -0,0 +1,3 @@
1
+ export { default } from './Draggable';
2
+ export type { DraggableProps, DraggableItem, DraggableCollectedProps } from './Draggable';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Draggable/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { default } from './Draggable';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/Draggable/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export { default } from './Draggable';\nexport type { DraggableProps, DraggableItem, DraggableCollectedProps } from './Draggable';\n"]}
@@ -0,0 +1,23 @@
1
+ import type { RefCallback, ReactElement } from 'react';
2
+ import type { DropTargetMonitor } from 'react-dnd';
3
+ import type { TargetType } from 'dnd-core';
4
+ import type { DraggableItem } from '../Draggable';
5
+ export interface DroppableProps<T extends object = object> {
6
+ /** Type of item allowed to be dropped on this drop target */
7
+ accept: TargetType;
8
+ /** Called when drop target is hovered with valid Droppable item */
9
+ onHover?: (item: DraggableItem<T>, monitor: DropTargetMonitor) => void;
10
+ /** Called when drag item is dropped on a valid drop target */
11
+ onDrop?: (item: DraggableItem<T>, monitor: DropTargetMonitor) => void;
12
+ /** Called when item is dropped on this drop target */
13
+ children: (refs: {
14
+ dropRef: RefCallback<HTMLElement>;
15
+ collected: {
16
+ canDrop: boolean;
17
+ isOver: boolean;
18
+ };
19
+ }) => ReactElement;
20
+ }
21
+ declare const Droppable: <T extends object = object>({ accept, onDrop, onHover, children }: DroppableProps<T>) => ReactElement<any, string | import("react").JSXElementConstructor<any>>;
22
+ export default Droppable;
23
+ //# sourceMappingURL=Droppable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Droppable.d.ts","sourceRoot":"","sources":["../../../src/components/Droppable/Droppable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAEvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IACvD,6DAA6D;IAC7D,MAAM,EAAE,UAAU,CAAC;IACnB,mEAAmE;IACnE,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,iBAAiB,KAAK,IAAI,CAAC;IACvE,8DAA8D;IAC9D,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,iBAAiB,KAAK,IAAI,CAAC;IACtE,sDAAsD;IACtD,QAAQ,EAAE,CAAC,IAAI,EAAE;QACf,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;QAClC,SAAS,EAAE;YAAE,OAAO,EAAE,OAAO,CAAC;YAAC,MAAM,EAAE,OAAO,CAAA;SAAE,CAAC;KAClD,KAAK,YAAY,CAAC;CACpB;AAED,QAAA,MAAM,SAAS,iKAoBd,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { useDrop } from 'react-dnd';
2
+ const Droppable = ({ accept, onDrop, onHover, children }) => {
3
+ const [collected, dropRef] = useDrop(() => ({
4
+ accept,
5
+ drop: onDrop,
6
+ hover: onHover,
7
+ collect: monitor => ({
8
+ canDrop: monitor.canDrop(),
9
+ isOver: monitor.isOver()
10
+ })
11
+ }), [accept, onDrop, onHover]);
12
+ return children({ dropRef, collected });
13
+ };
14
+ export default Droppable;
15
+ //# sourceMappingURL=Droppable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Droppable.js","sourceRoot":"","sources":["../../../src/components/Droppable/Droppable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAoBpC,MAAM,SAAS,GAAG,CAA4B,EAC5C,MAAM,EACN,MAAM,EACN,OAAO,EACP,QAAQ,EACU,EAAE,EAAE;IACtB,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,GAAG,OAAO,CAClC,GAAG,EAAE,CAAC,CAAC;QACL,MAAM;QACN,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,OAAO;QACd,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;YACnB,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE;YAC1B,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE;SACzB,CAAC;KACH,CAAC,EACF,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAC1B,CAAC;IAEF,OAAO,QAAQ,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;AAC1C,CAAC,CAAC;AAEF,eAAe,SAAS,CAAC","sourcesContent":["import type { RefCallback, ReactElement } from 'react';\nimport { useDrop } from 'react-dnd';\nimport type { DropTargetMonitor } from 'react-dnd';\nimport type { TargetType } from 'dnd-core';\n\nimport type { DraggableItem } from '../Draggable';\n\nexport interface DroppableProps<T extends object = object> {\n /** Type of item allowed to be dropped on this drop target */\n accept: TargetType;\n /** Called when drop target is hovered with valid Droppable item */\n onHover?: (item: DraggableItem<T>, monitor: DropTargetMonitor) => void;\n /** Called when drag item is dropped on a valid drop target */\n onDrop?: (item: DraggableItem<T>, monitor: DropTargetMonitor) => void;\n /** Called when item is dropped on this drop target */\n children: (refs: {\n dropRef: RefCallback<HTMLElement>;\n collected: { canDrop: boolean; isOver: boolean };\n }) => ReactElement;\n}\n\nconst Droppable = <T extends object = object>({\n accept,\n onDrop,\n onHover,\n children\n}: DroppableProps<T>) => {\n const [collected, dropRef] = useDrop(\n () => ({\n accept,\n drop: onDrop,\n hover: onHover,\n collect: monitor => ({\n canDrop: monitor.canDrop(),\n isOver: monitor.isOver()\n })\n }),\n [accept, onDrop, onHover]\n );\n\n return children({ dropRef, collected });\n};\n\nexport default Droppable;\n"]}
@@ -0,0 +1,3 @@
1
+ export { default } from './Droppable';
2
+ export type { DroppableProps } from './Droppable';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Droppable/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { default } from './Droppable';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/Droppable/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export { default } from './Droppable';\nexport type { DroppableProps } from './Droppable';\n"]}
@@ -0,0 +1,8 @@
1
+ import type { FunctionComponent } from 'react';
2
+ import type { ForwardProps } from '@pega/cosmos-react-core';
3
+ import type { StandardDragDropListProps } from './StandardDragDropList.types';
4
+ declare const _default: FunctionComponent<StandardDragDropListProps & ForwardProps> & {
5
+ getTestIds: (testIdProp?: string | undefined) => import("@pega/cosmos-react-core").TestIdsRecord<readonly ["header"]>;
6
+ };
7
+ export default _default;
8
+ //# sourceMappingURL=StandardDragDropList.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StandardDragDropList.d.ts","sourceRoot":"","sources":["../../../src/components/StandardDragDropList/StandardDragDropList.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAA+B,MAAM,OAAO,CAAC;AAiB5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAoB5D,OAAO,KAAK,EACV,yBAAyB,EAE1B,MAAM,8BAA8B,CAAC;;;;AA+YtC,wBAAiF"}
@@ -0,0 +1,157 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { forwardRef, useCallback, useMemo, useRef, useState } from 'react';
3
+ import { Flex, registerIcon, Icon, Text, Button, useI18n, EmptyState, ExpandCollapse, useUID, Tooltip, useElement, useTestIds, withTestIds } from '@pega/cosmos-react-core';
4
+ import * as DragIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/drag.icon';
5
+ import * as PlusIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/plus.icon';
6
+ import * as CaretDownIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/caret-down.icon';
7
+ import DragDropList from '../DragDropList';
8
+ import { StyledStandardDragDropList, StyledStandardDragDropListItem, StyledDragHandle, StyledExpandCollapseToggle, StyledItemActions, StyledItemContent, StyledItemStatus, StyledListItemInner, StyledSecondary } from './StandardDragDropList.styles';
9
+ import { getItemRendererTestIds, getStandardDragDropListTestIds } from './StandardDragDropList.test-ids';
10
+ registerIcon(DragIcon, PlusIcon, CaretDownIcon);
11
+ let StandardDragDropList;
12
+ const ItemStatus = ({ message, type }) => {
13
+ const [ttt, setTTT] = useElement(null);
14
+ return (_jsx(StyledItemStatus, { "aria-live": 'polite', role: 'status', children: message && (_jsx(Text, { variant: 'secondary', status: 'error', children: _jsxs(Flex, { container: { gap: 0.5 }, children: [_jsx(Icon, { ref: setTTT, name: 'warn-solid', role: 'status', tabIndex: 0, "aria-label": type }), _jsx(Tooltip, { target: ttt, "aria-hidden": true, showDelay: 'none', hideDelay: 'none', children: message })] }) })) }));
15
+ };
16
+ const getFlattenedIds = (items) => {
17
+ return items.flatMap(item => {
18
+ return item.items ? [item.id, ...item.items.map(({ id }) => id)] : [item.id];
19
+ });
20
+ };
21
+ const ItemRenderer = ({ testId, dragRef, previewRef, isDragging, data: { id,
22
+ // Remove type for DOM restProps
23
+ type, accept, primary, secondary, draggable = true, status, items, onConfigure, onRemove, onAddTo, onChange, ...restProps }, data }) => {
24
+ const t = useI18n();
25
+ const [collapsed, setCollapsed] = useState(false);
26
+ const expandCollpaseId = useUID();
27
+ const testIds = useTestIds(testId, getItemRendererTestIds);
28
+ const hasActions = !!(onConfigure ?? onRemove ?? onAddTo);
29
+ const primaryEl = useMemo(() => {
30
+ if (items) {
31
+ return (_jsx(StyledExpandCollapseToggle, { "data-testid": testIds.expandCollapseButton, variant: 'text', "aria-label": `${primary}. ${collapsed ? t('expand') : t('collapse')}.`, onClick: () => setCollapsed(cur => !cur), "aria-owns": expandCollpaseId, "aria-expanded": collapsed ? 'false' : 'true', children: _jsxs(Flex, { container: { inline: true, alignItems: 'center', gap: 0.5 }, children: [_jsx(Icon, { name: 'caret-down' }), _jsx("span", { children: primary })] }) }));
32
+ }
33
+ if (typeof primary === 'string') {
34
+ return _jsx("span", { children: primary });
35
+ }
36
+ return (_jsx(Button, { variant: 'link', onClick: primary.onClick, href: primary.href, children: _jsx("span", { children: primary.text }) }));
37
+ }, [t, items, primary, collapsed, expandCollpaseId]);
38
+ return (_jsxs(Flex, { "data-testid": testIds.root, ...restProps, container: { direction: 'column' }, as: StyledStandardDragDropListItem, ref: previewRef, isDragging: isDragging, children: [_jsxs(Flex, { container: { alignItems: 'center' }, as: StyledListItemInner, children: [draggable && (_jsx(StyledDragHandle, { ref: dragRef, children: _jsx(Icon, { name: 'drag' }) })), _jsx(Flex, { container: { alignItems: 'center', gap: 0.5 }, item: { grow: 1 }, children: _jsxs(Flex, { container: { alignItems: 'center', gap: status ? 0.5 : undefined, pad: 0.25 }, item: { grow: 1 }, as: StyledItemContent, children: [_jsx(ItemStatus, { type: status?.type, message: status?.message }), primaryEl] }) }), (secondary || hasActions) && (_jsxs(Flex, { container: { alignItems: 'center', gap: 0.5 }, children: [secondary && _jsx(StyledSecondary, { variant: 'secondary', children: secondary }), hasActions && (_jsxs(Flex, { container: { alignItems: 'center', gap: 0.5 }, as: StyledItemActions, children: [onAddTo && (_jsx("span", { children: _jsx(Button, { "data-testid": testIds.addButton, icon: true, variant: 'simple', label: t('add'), onClick: (e) => {
39
+ onAddTo?.(id, e);
40
+ }, children: _jsx(Icon, { name: 'plus' }) }) })), onConfigure && (_jsx("span", { children: _jsx(Button, { "data-testid": testIds.configureButton, icon: true, variant: 'simple', label: t('configure'), onClick: (e) => {
41
+ onConfigure?.(id, e);
42
+ }, children: _jsx(Icon, { name: 'gear' }) }) })), onRemove && (_jsx("span", { children: _jsx(Button, { "data-testid": testIds.removeButton, icon: true, variant: 'simple', label: t('remove'), onClick: (e) => {
43
+ onRemove?.(id, e);
44
+ }, children: _jsx(Icon, { name: 'trash' }) }) }))] }))] }))] }), data.items && data.items.length > 0 && (_jsx(ExpandCollapse, { collapsed: collapsed, id: expandCollpaseId, children: _jsx(StandardDragDropList, { accept: data.accept, items: data.items, onChange: data.onChange }) }))] }));
45
+ };
46
+ const ItemRendererWithTestIds = withTestIds(ItemRenderer, getItemRendererTestIds);
47
+ StandardDragDropList = forwardRef(function StandardDragDropListFunction({ testId, accept, items: itemsProp, heading: title, footer, onChange: onChangeProp, pushMode, pullMode, headingTag = 'h2', ...restProps }, ref) {
48
+ const flatIds = useMemo(() => getFlattenedIds(itemsProp), [itemsProp]);
49
+ const timerRef = useRef();
50
+ const newItemsRef = useRef();
51
+ const testIds = useTestIds(testId, getStandardDragDropListTestIds);
52
+ const mergeChangeHandler = useCallback((newItems) => {
53
+ if (typeof timerRef.current === 'number' && newItemsRef.current) {
54
+ clearTimeout(timerRef.current);
55
+ timerRef.current = undefined;
56
+ const refedItems = newItemsRef.current;
57
+ newItemsRef.current = undefined;
58
+ const reffedItemsCount = getFlattenedIds(refedItems).length;
59
+ const newItemsCount = getFlattenedIds(newItems).length;
60
+ // Item moved between the top level list and nested list.
61
+ if (Math.abs(reffedItemsCount - newItemsCount) === 2) {
62
+ const itemsWithDuplicate = reffedItemsCount > newItemsCount ? refedItems : newItems;
63
+ const flatItemsWithDuplicate = getFlattenedIds(itemsWithDuplicate);
64
+ const duplicateItemId = flatItemsWithDuplicate.find((id, idx) => flatItemsWithDuplicate.indexOf(id) !== idx);
65
+ // Should never happen.
66
+ if (!duplicateItemId)
67
+ return;
68
+ // The duplicate was top level before.
69
+ if (itemsProp.some(({ id }) => id === duplicateItemId)) {
70
+ onChangeProp(itemsWithDuplicate.filter(({ id }) => id !== duplicateItemId));
71
+ }
72
+ // The duplicate was nested before.
73
+ else {
74
+ onChangeProp(itemsWithDuplicate.map(innerItem => {
75
+ if (!innerItem.items)
76
+ return innerItem;
77
+ if (itemsProp
78
+ .find(({ id }) => id === innerItem.id)
79
+ ?.items?.some(({ id: subItemId }) => subItemId === duplicateItemId)) {
80
+ return {
81
+ ...innerItem,
82
+ items: innerItem.items.filter(({ id }) => id !== duplicateItemId)
83
+ };
84
+ }
85
+ return innerItem;
86
+ }));
87
+ }
88
+ }
89
+ else {
90
+ // Failsafe for two unrelated change events within 100ms.
91
+ onChangeProp(refedItems);
92
+ onChangeProp(newItems);
93
+ }
94
+ }
95
+ else {
96
+ newItemsRef.current = newItems;
97
+ timerRef.current = window.setTimeout(() => {
98
+ onChangeProp(newItems);
99
+ }, 100);
100
+ }
101
+ }, [onChangeProp, itemsProp]);
102
+ const itemsToRender = useMemo(() => itemsProp.map(item => {
103
+ const newItem = {
104
+ id: item.id,
105
+ type: item.type,
106
+ data: item
107
+ };
108
+ if (!item.items)
109
+ return newItem;
110
+ return {
111
+ ...newItem,
112
+ data: {
113
+ ...item,
114
+ accept: item.accept ?? accept,
115
+ onChange: (newItems) => {
116
+ const newContentItems = itemsProp.map(topLevelItem => topLevelItem.id === item.id && topLevelItem.items
117
+ ? { ...topLevelItem, items: newItems }
118
+ : topLevelItem);
119
+ const flatNewItems = getFlattenedIds(newContentItems);
120
+ if (itemsProp.some(propItem => !!propItem.items) &&
121
+ flatIds.length !== flatNewItems.length) {
122
+ // An item may be "removed" or "duplicated".
123
+ mergeChangeHandler(newContentItems);
124
+ }
125
+ else {
126
+ onChangeProp(newContentItems);
127
+ }
128
+ }
129
+ }
130
+ };
131
+ }), [accept, itemsProp, onChangeProp, flatIds, mergeChangeHandler]);
132
+ const onChange = useCallback((newItems) => {
133
+ const newContentItems = newItems.map(({ data: { onChange: _, ...data } }) => {
134
+ return data;
135
+ });
136
+ const flatNewItems = getFlattenedIds(newContentItems);
137
+ if (itemsProp.some(propItem => !!propItem.items) && flatIds.length !== flatNewItems.length) {
138
+ // An item may be "removed" or "duplicated".
139
+ mergeChangeHandler(newContentItems);
140
+ }
141
+ else {
142
+ onChangeProp(newContentItems);
143
+ }
144
+ }, [onChangeProp, flatIds, mergeChangeHandler]);
145
+ return (_jsxs(StyledStandardDragDropList, { ref: ref, ...restProps, children: [title && (_jsx(Flex, { "data-testid": testIds.header, container: {
146
+ justify: 'between',
147
+ alignItems: 'center',
148
+ gap: 1,
149
+ pad: 1
150
+ }, as: 'header', children: _jsx(Text, { variant: headingTag, children: title }) })), _jsx(DragDropList, { testId: testId, accept: accept, items: itemsToRender, pushMode: pushMode, pullMode: pullMode, itemRenderer: ItemRendererWithTestIds, emptyRenderer: EmptyState, onChange: onChange }), footer && (_jsx(Flex, { container: {
151
+ alignItems: 'center',
152
+ itemGap: 1,
153
+ pad: 1
154
+ }, as: 'footer', children: footer }))] }));
155
+ });
156
+ export default withTestIds(StandardDragDropList, getStandardDragDropListTestIds);
157
+ //# sourceMappingURL=StandardDragDropList.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StandardDragDropList.js","sourceRoot":"","sources":["../../../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EAAE,MAAM,EACd,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,uBAAuB,EACrC,aAAa,EAAE,UAAU,EACzB,QAAQ,EAAE,QAAQ,GAClB,EACD,MAAM,IAAI,CACT,KAAC,IAAI,IACH,SAAS,EAAE;oBACT,UAAU,EAAE,QAAQ;oBACpB,OAAO,EAAE,CAAC;oBACV,GAAG,EAAE,CAAC;iBACP,EACD,EAAE,EAAC,QAAQ,YAEV,MAAM,GACF,CACR,IAC0B,CAC9B,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,WAAW,CAAC,oBAAoB,EAAE,8BAA8B,CAAC,CAAC","sourcesContent":["import { forwardRef, useCallback, useMemo, useRef, useState } from 'react';\nimport type { FunctionComponent, MouseEvent, PropsWithoutRef } from 'react';\n\nimport {\n Flex,\n registerIcon,\n Icon,\n Text,\n Button,\n useI18n,\n EmptyState,\n ExpandCollapse,\n useUID,\n Tooltip,\n useElement,\n useTestIds,\n withTestIds\n} from '@pega/cosmos-react-core';\nimport type { ForwardProps } from '@pega/cosmos-react-core';\nimport * as DragIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/drag.icon';\nimport * as PlusIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/plus.icon';\nimport * as CaretDownIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/caret-down.icon';\n\nimport DragDropList from '../DragDropList';\nimport type { ItemRendererProps } from '../DragDropList';\nimport type { DraggableItem } from '../Draggable';\n\nimport {\n StyledStandardDragDropList,\n StyledStandardDragDropListItem,\n StyledDragHandle,\n StyledExpandCollapseToggle,\n StyledItemActions,\n StyledItemContent,\n StyledItemStatus,\n StyledListItemInner,\n StyledSecondary\n} from './StandardDragDropList.styles';\nimport type {\n StandardDragDropListProps,\n StandardDragDropListItemProps\n} from './StandardDragDropList.types';\nimport {\n getItemRendererTestIds,\n getStandardDragDropListTestIds\n} from './StandardDragDropList.test-ids';\n\nregisterIcon(DragIcon, PlusIcon, CaretDownIcon);\n\ntype InternalStandardDragDropListItemProps = StandardDragDropListItemProps &\n (\n | {\n items: StandardDragDropListItemProps[];\n accept: StandardDragDropListProps['accept'];\n onChange: StandardDragDropListProps['onChange'];\n }\n | {\n items?: undefined;\n accept?: never;\n onChange?: never;\n }\n );\n\nlet StandardDragDropList: FunctionComponent<StandardDragDropListProps & ForwardProps>;\n\nconst ItemStatus = ({\n message,\n type\n}: Partial<NonNullable<StandardDragDropListItemProps['status']>>) => {\n const [ttt, setTTT] = useElement(null);\n\n return (\n <StyledItemStatus aria-live='polite' role='status'>\n {message && (\n <Text variant='secondary' status='error'>\n <Flex container={{ gap: 0.5 }}>\n <Icon ref={setTTT} name='warn-solid' role='status' tabIndex={0} aria-label={type} />\n <Tooltip target={ttt} aria-hidden showDelay='none' hideDelay='none'>\n {message}\n </Tooltip>\n </Flex>\n </Text>\n )}\n </StyledItemStatus>\n );\n};\n\nconst getFlattenedIds = (\n items: StandardDragDropListItemProps[]\n): StandardDragDropListItemProps['id'][] => {\n return items.flatMap(item => {\n return item.items ? [item.id, ...item.items.map(({ id }) => id)] : [item.id];\n });\n};\n\nconst ItemRenderer = ({\n testId,\n dragRef,\n previewRef,\n isDragging,\n data: {\n id,\n // Remove type for DOM restProps\n type,\n accept,\n primary,\n secondary,\n draggable = true,\n status,\n items,\n onConfigure,\n onRemove,\n onAddTo,\n onChange,\n ...restProps\n },\n data\n}: ItemRendererProps<InternalStandardDragDropListItemProps>) => {\n const t = useI18n();\n const [collapsed, setCollapsed] = useState(false);\n const expandCollpaseId = useUID();\n const testIds = useTestIds(testId, getItemRendererTestIds);\n\n const hasActions = !!(onConfigure ?? onRemove ?? onAddTo);\n\n const primaryEl = useMemo(() => {\n if (items) {\n return (\n <StyledExpandCollapseToggle\n data-testid={testIds.expandCollapseButton}\n variant='text'\n aria-label={`${primary}. ${collapsed ? t('expand') : t('collapse')}.`}\n onClick={() => setCollapsed(cur => !cur)}\n aria-owns={expandCollpaseId}\n aria-expanded={collapsed ? 'false' : 'true'}\n >\n <Flex container={{ inline: true, alignItems: 'center', gap: 0.5 }}>\n <Icon name='caret-down' />\n <span>{primary}</span>\n </Flex>\n </StyledExpandCollapseToggle>\n );\n }\n\n if (typeof primary === 'string') {\n return <span>{primary}</span>;\n }\n\n return (\n <Button variant='link' onClick={primary.onClick} href={primary.href}>\n <span>{primary.text}</span>\n </Button>\n );\n }, [t, items, primary, collapsed, expandCollpaseId]);\n\n return (\n <Flex\n data-testid={testIds.root}\n {...restProps}\n container={{ direction: 'column' }}\n as={StyledStandardDragDropListItem}\n ref={previewRef}\n isDragging={isDragging}\n >\n <Flex container={{ alignItems: 'center' }} as={StyledListItemInner}>\n {draggable && (\n <StyledDragHandle ref={dragRef}>\n <Icon name='drag' />\n </StyledDragHandle>\n )}\n\n <Flex container={{ alignItems: 'center', gap: 0.5 }} item={{ grow: 1 }}>\n <Flex\n container={{ alignItems: 'center', gap: status ? 0.5 : undefined, pad: 0.25 }}\n item={{ grow: 1 }}\n as={StyledItemContent}\n >\n <ItemStatus type={status?.type} message={status?.message} />\n\n {primaryEl}\n </Flex>\n </Flex>\n\n {(secondary || hasActions) && (\n <Flex container={{ alignItems: 'center', gap: 0.5 }}>\n {secondary && <StyledSecondary variant='secondary'>{secondary}</StyledSecondary>}\n\n {hasActions && (\n <Flex container={{ alignItems: 'center', gap: 0.5 }} as={StyledItemActions}>\n {onAddTo && (\n <span>\n <Button\n data-testid={testIds.addButton}\n icon\n variant='simple'\n label={t('add')}\n onClick={(e: MouseEvent<HTMLButtonElement>) => {\n onAddTo?.(id, e);\n }}\n >\n <Icon name='plus' />\n </Button>\n </span>\n )}\n\n {onConfigure && (\n <span>\n <Button\n data-testid={testIds.configureButton}\n icon\n variant='simple'\n label={t('configure')}\n onClick={(e: MouseEvent<HTMLButtonElement>) => {\n onConfigure?.(id, e);\n }}\n >\n <Icon name='gear' />\n </Button>\n </span>\n )}\n\n {onRemove && (\n <span>\n <Button\n data-testid={testIds.removeButton}\n icon\n variant='simple'\n label={t('remove')}\n onClick={(e: MouseEvent<HTMLButtonElement>) => {\n onRemove?.(id, e);\n }}\n >\n <Icon name='trash' />\n </Button>\n </span>\n )}\n </Flex>\n )}\n </Flex>\n )}\n </Flex>\n\n {/* Using data here so TS can track conditional type. */}\n {data.items && data.items.length > 0 && (\n <ExpandCollapse collapsed={collapsed} id={expandCollpaseId}>\n <StandardDragDropList accept={data.accept} items={data.items} onChange={data.onChange} />\n </ExpandCollapse>\n )}\n </Flex>\n );\n};\n\nconst ItemRendererWithTestIds = withTestIds(ItemRenderer, getItemRendererTestIds);\n\nStandardDragDropList = forwardRef(function StandardDragDropListFunction(\n {\n testId,\n accept,\n items: itemsProp,\n heading: title,\n footer,\n onChange: onChangeProp,\n pushMode,\n pullMode,\n headingTag = 'h2',\n ...restProps\n }: PropsWithoutRef<StandardDragDropListProps>,\n ref: StandardDragDropListProps['ref']\n) {\n const flatIds = useMemo(() => getFlattenedIds(itemsProp), [itemsProp]);\n\n const timerRef = useRef<number>();\n const newItemsRef = useRef<StandardDragDropListItemProps[]>();\n\n const testIds = useTestIds(testId, getStandardDragDropListTestIds);\n\n const mergeChangeHandler = useCallback(\n (newItems: StandardDragDropListItemProps[]) => {\n if (typeof timerRef.current === 'number' && newItemsRef.current) {\n clearTimeout(timerRef.current);\n timerRef.current = undefined;\n const refedItems = newItemsRef.current;\n newItemsRef.current = undefined;\n\n const reffedItemsCount = getFlattenedIds(refedItems).length;\n const newItemsCount = getFlattenedIds(newItems).length;\n\n // Item moved between the top level list and nested list.\n if (Math.abs(reffedItemsCount - newItemsCount) === 2) {\n const itemsWithDuplicate = reffedItemsCount > newItemsCount ? refedItems : newItems;\n\n const flatItemsWithDuplicate = getFlattenedIds(itemsWithDuplicate);\n\n const duplicateItemId = flatItemsWithDuplicate.find(\n (id, idx) => flatItemsWithDuplicate.indexOf(id) !== idx\n );\n\n // Should never happen.\n if (!duplicateItemId) return;\n\n // The duplicate was top level before.\n if (itemsProp.some(({ id }) => id === duplicateItemId)) {\n onChangeProp(itemsWithDuplicate.filter(({ id }) => id !== duplicateItemId));\n }\n\n // The duplicate was nested before.\n else {\n onChangeProp(\n itemsWithDuplicate.map(innerItem => {\n if (!innerItem.items) return innerItem;\n\n if (\n itemsProp\n .find(({ id }) => id === innerItem.id)\n ?.items?.some(({ id: subItemId }) => subItemId === duplicateItemId)\n ) {\n return {\n ...innerItem,\n items: innerItem.items.filter(({ id }) => id !== duplicateItemId)\n };\n }\n\n return innerItem;\n })\n );\n }\n } else {\n // Failsafe for two unrelated change events within 100ms.\n onChangeProp(refedItems);\n onChangeProp(newItems);\n }\n } else {\n newItemsRef.current = newItems;\n timerRef.current = window.setTimeout(() => {\n onChangeProp(newItems);\n }, 100);\n }\n },\n [onChangeProp, itemsProp]\n );\n\n const itemsToRender: DraggableItem<InternalStandardDragDropListItemProps>[] = useMemo(\n () =>\n itemsProp.map(item => {\n const newItem = {\n id: item.id,\n type: item.type,\n data: item as InternalStandardDragDropListItemProps\n };\n if (!item.items) return newItem;\n\n return {\n ...newItem,\n data: {\n ...item,\n accept: item.accept ?? accept,\n onChange: (newItems: InternalStandardDragDropListItemProps[]) => {\n const newContentItems = itemsProp.map(topLevelItem =>\n topLevelItem.id === item.id && topLevelItem.items\n ? { ...topLevelItem, items: newItems }\n : topLevelItem\n );\n\n const flatNewItems = getFlattenedIds(newContentItems);\n\n if (\n itemsProp.some(propItem => !!propItem.items) &&\n flatIds.length !== flatNewItems.length\n ) {\n // An item may be \"removed\" or \"duplicated\".\n mergeChangeHandler(newContentItems);\n } else {\n onChangeProp(newContentItems);\n }\n }\n } as InternalStandardDragDropListItemProps\n };\n }),\n [accept, itemsProp, onChangeProp, flatIds, mergeChangeHandler]\n );\n\n const onChange = useCallback(\n (newItems: DraggableItem<InternalStandardDragDropListItemProps>[]) => {\n const newContentItems = newItems.map(({ data: { onChange: _, ...data } }) => {\n return data;\n });\n const flatNewItems = getFlattenedIds(newContentItems);\n\n if (itemsProp.some(propItem => !!propItem.items) && flatIds.length !== flatNewItems.length) {\n // An item may be \"removed\" or \"duplicated\".\n mergeChangeHandler(newContentItems);\n } else {\n onChangeProp(newContentItems);\n }\n },\n [onChangeProp, flatIds, mergeChangeHandler]\n );\n\n return (\n <StyledStandardDragDropList ref={ref} {...restProps}>\n {title && (\n <Flex\n data-testid={testIds.header}\n container={{\n justify: 'between',\n alignItems: 'center',\n gap: 1,\n pad: 1\n }}\n as='header'\n >\n <Text variant={headingTag}>{title}</Text>\n </Flex>\n )}\n <DragDropList\n testId={testId}\n accept={accept}\n items={itemsToRender}\n pushMode={pushMode}\n pullMode={pullMode}\n itemRenderer={ItemRendererWithTestIds}\n emptyRenderer={EmptyState}\n onChange={onChange}\n />\n {footer && (\n <Flex\n container={{\n alignItems: 'center',\n itemGap: 1,\n pad: 1\n }}\n as='footer'\n >\n {footer}\n </Flex>\n )}\n </StyledStandardDragDropList>\n );\n});\n\nexport default withTestIds(StandardDragDropList, getStandardDragDropListTestIds);\n"]}
@@ -0,0 +1,15 @@
1
+ /// <reference types="react" />
2
+ import { Button } from '@pega/cosmos-react-core';
3
+ export declare const StyledExpandCollapseToggle: typeof Button;
4
+ export declare const StyledItemStatus: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
5
+ export declare const StyledDragHandle: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
6
+ export declare const StyledItemContent: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
7
+ export declare const StyledItemActions: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
8
+ export declare const StyledSecondary: import("styled-components").StyledComponent<import("react").FunctionComponent<import("@pega/cosmos-react-core").TextProps & import("@pega/cosmos-react-core").ForwardProps>, import("styled-components").DefaultTheme, {}, never>;
9
+ export declare const StyledListItemInner: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
10
+ export declare const StyledStandardDragDropListItem: import("styled-components").StyledComponent<"li", import("styled-components").DefaultTheme, {
11
+ isDragging?: boolean | undefined;
12
+ empty?: boolean | undefined;
13
+ }, never>;
14
+ export declare const StyledStandardDragDropList: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
15
+ //# sourceMappingURL=StandardDragDropList.styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StandardDragDropList.styles.d.ts","sourceRoot":"","sources":["../../../src/components/StandardDragDropList/StandardDragDropList.styles.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,EAAoD,MAAM,yBAAyB,CAAC;AAEnG,eAAO,MAAM,0BAA0B,EAAE,OAAO,MAe9C,CAAC;AAEH,eAAO,MAAM,gBAAgB,yGAU3B,CAAC;AAIH,eAAO,MAAM,gBAAgB,yGAM5B,CAAC;AAIF,eAAO,MAAM,iBAAiB,yGAK7B,CAAC;AAIF,eAAO,MAAM,iBAAiB,yGAAe,CAAC;AAC9C,eAAO,MAAM,eAAe,mOAAiB,CAAC;AAE9C,eAAO,MAAM,mBAAmB,yGAK9B,CAAC;AAIH,eAAO,MAAM,8BAA8B;;;SAkE1C,CAAC;AAIF,eAAO,MAAM,0BAA0B,yGAqBrC,CAAC"}
@@ -0,0 +1,142 @@
1
+ import styled, { css } from 'styled-components';
2
+ import { Button, defaultThemeProp, StyledIcon, Text, useDirection } from '@pega/cosmos-react-core';
3
+ export const StyledExpandCollapseToggle = styled(Button)(({ theme }) => {
4
+ const { ltr } = useDirection();
5
+ return css `
6
+ & > div {
7
+ vertical-align: middle;
8
+ }
9
+
10
+ & ${StyledIcon} {
11
+ transition: transform ${theme.base.animation.speed} ${theme.base.animation.timing.ease};
12
+ }
13
+
14
+ &[aria-expanded='false'] ${StyledIcon} {
15
+ transform: rotateZ(${ltr ? '-' : ''}90deg);
16
+ }
17
+ `;
18
+ });
19
+ export const StyledItemStatus = styled.div(({ theme }) => {
20
+ return css `
21
+ ${StyledIcon} {
22
+ outline: none;
23
+
24
+ &:focus {
25
+ box-shadow: ${theme.base.shadow['focus-inset']};
26
+ }
27
+ }
28
+ `;
29
+ });
30
+ StyledItemStatus.defaultProps = defaultThemeProp;
31
+ export const StyledDragHandle = styled.div `
32
+ padding: 0 ${({ theme }) => theme.base.spacing} 0 0;
33
+ cursor: move;
34
+ > svg {
35
+ display: block;
36
+ }
37
+ `;
38
+ StyledDragHandle.defaultProps = defaultThemeProp;
39
+ export const StyledItemContent = styled.div `
40
+ & > :nth-child(2) {
41
+ overflow: hidden;
42
+ text-overflow: ellipsis;
43
+ }
44
+ `;
45
+ StyledItemContent.defaultProps = defaultThemeProp;
46
+ export const StyledItemActions = styled.div ``;
47
+ export const StyledSecondary = styled(Text) ``;
48
+ export const StyledListItemInner = styled.div(({ theme }) => {
49
+ return css `
50
+ padding-inline: calc(${theme.base.spacing} / 2);
51
+ white-space: nowrap;
52
+ `;
53
+ });
54
+ StyledListItemInner.defaultProps = defaultThemeProp;
55
+ export const StyledStandardDragDropListItem = styled.li(({ theme, isDragging, empty }) => {
56
+ const bdrColor = theme.base.palette['border-line'];
57
+ const bdr = `0.0625rem dashed ${isDragging || empty ? bdrColor : 'transparent'}`;
58
+ if (empty) {
59
+ return css `
60
+ text-align: center;
61
+ padding: ${theme.base.spacing};
62
+ border: ${bdr};
63
+ font-style: italic;
64
+ `;
65
+ }
66
+ return css `
67
+ position: relative;
68
+ background: ${theme.base.palette['primary-background']};
69
+
70
+ ${isDragging &&
71
+ css `
72
+ z-index: 1;
73
+
74
+ & > div,
75
+ span {
76
+ opacity: 0.5;
77
+ }
78
+ `}
79
+
80
+ &::before,
81
+ &::after {
82
+ content: '';
83
+ display: block;
84
+ position: absolute;
85
+ height: 0.0625rem;
86
+ left: 0;
87
+ right: 0;
88
+ background: ${isDragging ? theme.base.palette['primary-background'] : bdrColor};
89
+ }
90
+
91
+ &::before {
92
+ top: 0;
93
+ border-top: ${bdr};
94
+ ${isDragging &&
95
+ css `
96
+ box-shadow: 0 0.0625rem 0 ${theme.base.palette.interactive};
97
+ `}
98
+ }
99
+
100
+ &::after {
101
+ bottom: -0.0625rem;
102
+ border-bottom: ${bdr};
103
+ ${isDragging &&
104
+ css `
105
+ box-shadow: 0 -0.0625rem 0 ${theme.base.palette.interactive};
106
+ `}
107
+ }
108
+
109
+ & > ${StyledListItemInner} {
110
+ min-height: calc(${theme.base['hit-area'].mouse} + ${theme.base.spacing});
111
+
112
+ @media (pointer: coarse) {
113
+ min-height: calc(${theme.base['hit-area']['finger-min']} + ${theme.base.spacing});
114
+ }
115
+ }
116
+ `;
117
+ });
118
+ StyledStandardDragDropListItem.defaultProps = defaultThemeProp;
119
+ export const StyledStandardDragDropList = styled.div(({ theme }) => {
120
+ return css `
121
+ flex-grow: 1;
122
+ background-color: ${theme.base.palette['primary-background']};
123
+
124
+ ul {
125
+ list-style: none;
126
+ }
127
+
128
+ & & {
129
+ padding-inline: calc(3.5 * ${theme.base.spacing}) 0;
130
+
131
+ ${StyledStandardDragDropListItem} {
132
+ &:last-child {
133
+ &::after {
134
+ display: none;
135
+ }
136
+ }
137
+ }
138
+ }
139
+ `;
140
+ });
141
+ StyledStandardDragDropList.defaultProps = defaultThemeProp;
142
+ //# sourceMappingURL=StandardDragDropList.styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StandardDragDropList.styles.js","sourceRoot":"","sources":["../../../src/components/StandardDragDropList/StandardDragDropList.styles.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEnG,MAAM,CAAC,MAAM,0BAA0B,GAAkB,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IACpF,MAAM,EAAE,GAAG,EAAE,GAAG,YAAY,EAAE,CAAC;IAC/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C;AAE/D,MAAM,CAAC,MAAM,0BAA0B,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IACjE,OAAO,GAAG,CAAA;;wBAEY,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC;;;;;;;mCAO7B,KAAK,CAAC,IAAI,CAAC,OAAO;;QAE7C,8BAA8B;;;;;;;;GAQnC,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,0BAA0B,CAAC,YAAY,GAAG,gBAAgB,CAAC","sourcesContent":["import styled, { css } from 'styled-components';\n\nimport { Button, defaultThemeProp, StyledIcon, Text, useDirection } from '@pega/cosmos-react-core';\n\nexport const StyledExpandCollapseToggle: typeof Button = styled(Button)(({ theme }) => {\n const { ltr } = useDirection();\n return css`\n & > div {\n vertical-align: middle;\n }\n\n & ${StyledIcon} {\n transition: transform ${theme.base.animation.speed} ${theme.base.animation.timing.ease};\n }\n\n &[aria-expanded='false'] ${StyledIcon} {\n transform: rotateZ(${ltr ? '-' : ''}90deg);\n }\n `;\n});\n\nexport const StyledItemStatus = styled.div(({ theme }) => {\n return css`\n ${StyledIcon} {\n outline: none;\n\n &:focus {\n box-shadow: ${theme.base.shadow['focus-inset']};\n }\n }\n `;\n});\n\nStyledItemStatus.defaultProps = defaultThemeProp;\n\nexport const StyledDragHandle = styled.div`\n padding: 0 ${({ theme }) => theme.base.spacing} 0 0;\n cursor: move;\n > svg {\n display: block;\n }\n`;\n\nStyledDragHandle.defaultProps = defaultThemeProp;\n\nexport const StyledItemContent = styled.div`\n & > :nth-child(2) {\n overflow: hidden;\n text-overflow: ellipsis;\n }\n`;\n\nStyledItemContent.defaultProps = defaultThemeProp;\n\nexport const StyledItemActions = styled.div``;\nexport const StyledSecondary = styled(Text)``;\n\nexport const StyledListItemInner = styled.div(({ theme }) => {\n return css`\n padding-inline: calc(${theme.base.spacing} / 2);\n white-space: nowrap;\n `;\n});\n\nStyledListItemInner.defaultProps = defaultThemeProp;\n\nexport const StyledStandardDragDropListItem = styled.li<{ isDragging?: boolean; empty?: boolean }>(\n ({ theme, isDragging, empty }) => {\n const bdrColor = theme.base.palette['border-line'];\n const bdr = `0.0625rem dashed ${isDragging || empty ? bdrColor : 'transparent'}`;\n\n if (empty) {\n return css`\n text-align: center;\n padding: ${theme.base.spacing};\n border: ${bdr};\n font-style: italic;\n `;\n }\n\n return css`\n position: relative;\n background: ${theme.base.palette['primary-background']};\n\n ${isDragging &&\n css`\n z-index: 1;\n\n & > div,\n span {\n opacity: 0.5;\n }\n `}\n\n &::before,\n &::after {\n content: '';\n display: block;\n position: absolute;\n height: 0.0625rem;\n left: 0;\n right: 0;\n background: ${isDragging ? theme.base.palette['primary-background'] : bdrColor};\n }\n\n &::before {\n top: 0;\n border-top: ${bdr};\n ${isDragging &&\n css`\n box-shadow: 0 0.0625rem 0 ${theme.base.palette.interactive};\n `}\n }\n\n &::after {\n bottom: -0.0625rem;\n border-bottom: ${bdr};\n ${isDragging &&\n css`\n box-shadow: 0 -0.0625rem 0 ${theme.base.palette.interactive};\n `}\n }\n\n & > ${StyledListItemInner} {\n min-height: calc(${theme.base['hit-area'].mouse} + ${theme.base.spacing});\n\n @media (pointer: coarse) {\n min-height: calc(${theme.base['hit-area']['finger-min']} + ${theme.base.spacing});\n }\n }\n `;\n }\n);\n\nStyledStandardDragDropListItem.defaultProps = defaultThemeProp;\n\nexport const StyledStandardDragDropList = styled.div(({ theme }) => {\n return css`\n flex-grow: 1;\n background-color: ${theme.base.palette['primary-background']};\n\n ul {\n list-style: none;\n }\n\n & & {\n padding-inline: calc(3.5 * ${theme.base.spacing}) 0;\n\n ${StyledStandardDragDropListItem} {\n &:last-child {\n &::after {\n display: none;\n }\n }\n }\n }\n `;\n});\n\nStyledStandardDragDropList.defaultProps = defaultThemeProp;\n"]}
@@ -0,0 +1,3 @@
1
+ export declare const getItemRendererTestIds: (testIdProp?: string | undefined) => import("@pega/cosmos-react-core").TestIdsRecord<readonly ["expand-collapse-button", "add-button", "configure-button", "remove-button"]>;
2
+ export declare const getStandardDragDropListTestIds: (testIdProp?: string | undefined) => import("@pega/cosmos-react-core").TestIdsRecord<readonly ["header"]>;
3
+ //# sourceMappingURL=StandardDragDropList.test-ids.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StandardDragDropList.test-ids.d.ts","sourceRoot":"","sources":["../../../src/components/StandardDragDropList/StandardDragDropList.test-ids.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,sBAAsB,8KAKxB,CAAC;AAEZ,eAAO,MAAM,8BAA8B,2GAEhC,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { createTestIds } from '@pega/cosmos-react-core';
2
+ export const getItemRendererTestIds = createTestIds('standard-drag-drop-item', [
3
+ 'expand-collapse-button',
4
+ 'add-button',
5
+ 'configure-button',
6
+ 'remove-button'
7
+ ]);
8
+ export const getStandardDragDropListTestIds = createTestIds('standard-drag-drop-list', [
9
+ 'header'
10
+ ]);
11
+ //# sourceMappingURL=StandardDragDropList.test-ids.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StandardDragDropList.test-ids.js","sourceRoot":"","sources":["../../../src/components/StandardDragDropList/StandardDragDropList.test-ids.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,MAAM,CAAC,MAAM,sBAAsB,GAAG,aAAa,CAAC,yBAAyB,EAAE;IAC7E,wBAAwB;IACxB,YAAY;IACZ,kBAAkB;IAClB,eAAe;CACP,CAAC,CAAC;AAEZ,MAAM,CAAC,MAAM,8BAA8B,GAAG,aAAa,CAAC,yBAAyB,EAAE;IACrF,QAAQ;CACA,CAAC,CAAC","sourcesContent":["import { createTestIds } from '@pega/cosmos-react-core';\n\nexport const getItemRendererTestIds = createTestIds('standard-drag-drop-item', [\n 'expand-collapse-button',\n 'add-button',\n 'configure-button',\n 'remove-button'\n] as const);\n\nexport const getStandardDragDropListTestIds = createTestIds('standard-drag-drop-list', [\n 'header'\n] as const);\n"]}
@@ -0,0 +1,68 @@
1
+ import type { MouseEvent, MouseEventHandler, ReactNode, Ref } from 'react';
2
+ import type { TestIdProp, OmitStrict, BaseProps, NoChildrenProp, ForwardProps, HeadingTag } from '@pega/cosmos-react-core';
3
+ import type { DragDropListProps } from '../DragDropList';
4
+ export interface StandardDragDropListProps extends OmitStrict<DragDropListProps<StandardDragDropListItemProps>, 'dragHandles' | 'itemRenderer' | 'emptyRenderer' | 'items' | 'onChange'>, BaseProps, NoChildrenProp, TestIdProp {
5
+ /** The contents of the list. */
6
+ items: StandardDragDropListItemProps[];
7
+ /** A title for the list. */
8
+ heading?: string;
9
+ /**
10
+ * Select the heading tag for header
11
+ * @default h2
12
+ */
13
+ headingTag?: HeadingTag;
14
+ /** A region for various list level actions */
15
+ footer?: ReactNode;
16
+ /**
17
+ * Called when the list's content changes by way of drag for reorder, add or remove.
18
+ * The handler is provided an array of items representing the new state.
19
+ */
20
+ onChange: (items: StandardDragDropListProps['items']) => void;
21
+ /** A ref to the root HTMLElement for the component. */
22
+ ref?: Ref<HTMLDivElement>;
23
+ }
24
+ type ItemAction = (id: StandardDragDropListItemProps['id'], e: MouseEvent<HTMLButtonElement>) => void;
25
+ export type StandardDragDropListItemProps = ForwardProps & {
26
+ /** An identifier unique within the entire list hierarchy. */
27
+ id: string;
28
+ /** Indicates the type of item for determining drop acceptance by a target list. */
29
+ type: string;
30
+ /** The primary textual representation for the item or props for a linkable resource. */
31
+ primary: string | ({
32
+ text: string;
33
+ onClick: MouseEventHandler;
34
+ href?: string;
35
+ } & ForwardProps);
36
+ /** An additional textual representation for the item e.g. metadata. */
37
+ secondary?: string;
38
+ /** Presents the item as being in an invalidate state. */
39
+ status?: {
40
+ type: 'error';
41
+ message: string;
42
+ };
43
+ /** Whether or not the item can be reordered with drag. */
44
+ draggable?: boolean;
45
+ /**
46
+ * If the item is configurable pass a callback to render a button.
47
+ * The item's id and an event argument provides access to the underlying HTMLButtonElement.
48
+ */
49
+ onConfigure?: ItemAction;
50
+ /**
51
+ * If the item can be removed form the list pass a callback to render a button.
52
+ * The handler's event argument provides access to the underlying HTMLButtonElement.
53
+ */
54
+ onRemove?: ItemAction;
55
+ } & ({
56
+ /** If the item can possess a nested list of items. */
57
+ items: StandardDragDropListItemProps[];
58
+ /** Type of items allowed to be dropped on the list. If not passed it will inherit accept from the parent list. */
59
+ accept?: StandardDragDropListProps['accept'];
60
+ /** Optionally render an add button for parent item types. */
61
+ onAddTo?: ItemAction;
62
+ } | {
63
+ items?: undefined;
64
+ accept?: never;
65
+ onAddTo?: never;
66
+ });
67
+ export {};
68
+ //# sourceMappingURL=StandardDragDropList.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StandardDragDropList.types.d.ts","sourceRoot":"","sources":["../../../src/components/StandardDragDropList/StandardDragDropList.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE3E,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,SAAS,EACT,cAAc,EACd,YAAY,EACZ,UAAU,EACX,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,MAAM,WAAW,yBACf,SAAQ,UAAU,CACd,iBAAiB,CAAC,6BAA6B,CAAC,EAChD,aAAa,GAAG,cAAc,GAAG,eAAe,GAAG,OAAO,GAAG,UAAU,CACxE,EACD,SAAS,EACT,cAAc,EACd,UAAU;IACZ,gCAAgC;IAChC,KAAK,EAAE,6BAA6B,EAAE,CAAC;IACvC,4BAA4B;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,8CAA8C;IAC9C,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB;;;OAGG;IACH,QAAQ,EAAE,CAAC,KAAK,EA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 export {};
2
+ //# sourceMappingURL=StandardDragDropList.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StandardDragDropList.types.js","sourceRoot":"","sources":["../../../src/components/StandardDragDropList/StandardDragDropList.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { MouseEvent, MouseEventHandler, ReactNode, Ref } from 'react';\n\nimport type {\n TestIdProp,\n OmitStrict,\n BaseProps,\n NoChildrenProp,\n ForwardProps,\n HeadingTag\n} from '@pega/cosmos-react-core';\n\nimport type { DragDropListProps } from '../DragDropList';\n\nexport interface StandardDragDropListProps\n extends OmitStrict<\n DragDropListProps<StandardDragDropListItemProps>,\n 'dragHandles' | 'itemRenderer' | 'emptyRenderer' | 'items' | 'onChange'\n >,\n BaseProps,\n NoChildrenProp,\n TestIdProp {\n /** The contents of the list. */\n items: StandardDragDropListItemProps[];\n /** A title for the list. */\n heading?: string;\n /**\n * Select the heading tag for header\n * @default h2\n */\n headingTag?: HeadingTag;\n /** A region for various list level actions */\n footer?: ReactNode;\n /**\n * Called when the list's content changes by way of drag for reorder, add or remove.\n * The handler is provided an array of items representing the new state.\n */\n onChange: (items: StandardDragDropListProps['items']) => void;\n /** A ref to the root HTMLElement for the component. */\n ref?: Ref<HTMLDivElement>;\n}\n\ntype ItemAction = (\n id: StandardDragDropListItemProps['id'],\n e: MouseEvent<HTMLButtonElement>\n) => void;\n\nexport type StandardDragDropListItemProps = ForwardProps & {\n /** An identifier unique within the entire list hierarchy. */\n id: string;\n /** Indicates the type of item for determining drop acceptance by a target list. */\n type: string;\n /** The primary textual representation for the item or props for a linkable resource. */\n primary: string | ({ text: string; onClick: MouseEventHandler; href?: string } & ForwardProps);\n /** An additional textual representation for the item e.g. metadata. */\n secondary?: string;\n /** Presents the item as being in an invalidate state. */\n status?: {\n type: 'error';\n message: string;\n };\n /** Whether or not the item can be reordered with drag. */\n draggable?: boolean;\n /**\n * If the item is configurable pass a callback to render a button.\n * The item's id and an event argument provides access to the underlying HTMLButtonElement.\n */\n onConfigure?: ItemAction;\n /**\n * If the item can be removed form the list pass a callback to render a button.\n * The handler's event argument provides access to the underlying HTMLButtonElement.\n */\n onRemove?: ItemAction;\n} & (\n | {\n /** If the item can possess a nested list of items. */\n items: StandardDragDropListItemProps[];\n /** Type of items allowed to be dropped on the list. If not passed it will inherit accept from the parent list. */\n accept?: StandardDragDropListProps['accept'];\n /** Optionally render an add button for parent item types. */\n onAddTo?: ItemAction;\n }\n | {\n items?: undefined;\n accept?: never;\n onAddTo?: never;\n }\n );\n"]}
@@ -0,0 +1,3 @@
1
+ export { default } from './StandardDragDropList';
2
+ export type { StandardDragDropListProps, StandardDragDropListItemProps } from './StandardDragDropList.types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/StandardDragDropList/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,YAAY,EACV,yBAAyB,EACzB,6BAA6B,EAC9B,MAAM,8BAA8B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { default } from './StandardDragDropList';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/StandardDragDropList/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["export { default } from './StandardDragDropList';\nexport type {\n StandardDragDropListProps,\n StandardDragDropListItemProps\n} from './StandardDragDropList.types';\n"]}
package/lib/index.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ export { default as DragDropList } from './components/DragDropList';
2
+ export * from './components/DragDropList';
3
+ export { default as DragDropManager } from './components/DragDropManager';
4
+ export * from './components/DragDropManager';
5
+ export { default as Draggable } from './components/Draggable';
6
+ export * from './components/Draggable';
7
+ export { default as Droppable } from './components/Droppable';
8
+ export * from './components/Droppable';
9
+ export { default as StandardDragDropList } from './components/StandardDragDropList';
10
+ export * from './components/StandardDragDropList';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACpE,cAAc,2BAA2B,CAAC;AAC1C,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC1E,cAAc,8BAA8B,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAC9D,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAC9D,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACpF,cAAc,mCAAmC,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,12 @@
1
+ // This file is autogenerated. Any changes will be overwritten.
2
+ export { default as DragDropList } from './components/DragDropList';
3
+ export * from './components/DragDropList';
4
+ export { default as DragDropManager } from './components/DragDropManager';
5
+ export * from './components/DragDropManager';
6
+ export { default as Draggable } from './components/Draggable';
7
+ export * from './components/Draggable';
8
+ export { default as Droppable } from './components/Droppable';
9
+ export * from './components/Droppable';
10
+ export { default as StandardDragDropList } from './components/StandardDragDropList';
11
+ export * from './components/StandardDragDropList';
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACpE,cAAc,2BAA2B,CAAC;AAC1C,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC1E,cAAc,8BAA8B,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAC9D,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAC9D,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACpF,cAAc,mCAAmC,CAAC","sourcesContent":["// This file is autogenerated. Any changes will be overwritten.\nexport { default as DragDropList } from './components/DragDropList';\nexport * from './components/DragDropList';\nexport { default as DragDropManager } from './components/DragDropManager';\nexport * from './components/DragDropManager';\nexport { default as Draggable } from './components/Draggable';\nexport * from './components/Draggable';\nexport { default as Droppable } from './components/Droppable';\nexport * from './components/Droppable';\nexport { default as StandardDragDropList } from './components/StandardDragDropList';\nexport * from './components/StandardDragDropList';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pega/cosmos-react-dnd",
3
- "version": "5.0.0-dev.4.9",
3
+ "version": "5.0.0-dev.6.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/pegasystems/cosmos-react.git",
@@ -20,7 +20,7 @@
20
20
  "build": "tsc -b"
21
21
  },
22
22
  "dependencies": {
23
- "@pega/cosmos-react-core": "5.0.0-dev.4.9",
23
+ "@pega/cosmos-react-core": "5.0.0-dev.6.0",
24
24
  "@types/react": "^17.0.62",
25
25
  "@types/react-dom": "^17.0.20",
26
26
  "@types/styled-components": "^5.1.26",