@pega/cosmos-react-dnd 5.0.0-dev.1.0 → 5.0.0-dev.2.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 +2 -1
- package/lib/components/DragDropList/DragDropList.js.map +1 -1
- package/lib/components/DragDropList/DragDropList.types.d.ts +3 -3
- package/lib/components/DragDropList/DragDropList.types.d.ts.map +1 -1
- package/lib/components/DragDropList/DragDropList.types.js.map +1 -1
- package/lib/components/StandardDragDropList/StandardDragDropList.d.ts +4 -2
- package/lib/components/StandardDragDropList/StandardDragDropList.d.ts.map +1 -1
- package/lib/components/StandardDragDropList/StandardDragDropList.js +14 -11
- package/lib/components/StandardDragDropList/StandardDragDropList.js.map +1 -1
- package/lib/components/StandardDragDropList/StandardDragDropList.test-ids.d.ts +3 -0
- package/lib/components/StandardDragDropList/StandardDragDropList.test-ids.d.ts.map +1 -0
- package/lib/components/StandardDragDropList/StandardDragDropList.test-ids.js +11 -0
- package/lib/components/StandardDragDropList/StandardDragDropList.test-ids.js.map +1 -0
- package/lib/components/StandardDragDropList/StandardDragDropList.types.d.ts +2 -2
- package/lib/components/StandardDragDropList/StandardDragDropList.types.d.ts.map +1 -1
- package/lib/components/StandardDragDropList/StandardDragDropList.types.js.map +1 -1
- package/package.json +8 -8
|
@@ -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>({ id: idProp, accept, items, itemRenderer: ItemRenderer, emptyRenderer: EmptyRenderer, onChange, onEnter, pullMode, pushMode, dragToRemove, as: Component, ...restProps }: DragDropListProps<T> & ForwardProps) => JSX.Element;
|
|
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
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,EAGb,MAAM,yBAAyB,CAAC;AAKjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAgBzD,QAAA,MAAM,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,oQA0RjB,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -4,7 +4,7 @@ import { useElement, useAfterInitialEffect, useTriggerableEffect, useUID } from
|
|
|
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 = ({ id: idProp, accept, items, itemRenderer: ItemRenderer, emptyRenderer: EmptyRenderer, onChange, onEnter, pullMode = 'remove', pushMode = 'insert', dragToRemove = false, as: Component = 'ul', ...restProps }) => {
|
|
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
8
|
const [internalItems, setInternalItems] = useState(items);
|
|
9
9
|
const itemRectsRef = useRef(null);
|
|
10
10
|
const transformedItem = useRef(null);
|
|
@@ -199,6 +199,7 @@ const DragDropList = ({ id: idProp, accept, items, itemRenderer: ItemRenderer, e
|
|
|
199
199
|
: internalItems.map(item => {
|
|
200
200
|
return (_jsx(Draggable, { id: item.id, type: item.type, data: item.data, onBegin: onBegin(item.id), onEnd: onEnd, children: ({ dragRef, previewRef, collected }) => {
|
|
201
201
|
return (_jsx(ItemRenderer, { ...{
|
|
202
|
+
testId,
|
|
202
203
|
...item,
|
|
203
204
|
dragRef,
|
|
204
205
|
previewRef,
|
|
@@ -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,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,GAAG,CAAC,GAAG,CAAC,CAAC;AAErF,MAAM,YAAY,GAAG,CAA4B,EAC/C,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;IACxC,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAAwB,KA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AAE,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,CAAC,CAAC,IAAI,CAAC,QAAQ;qCAC5B,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 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 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 {...{\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"]}
|
|
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,OAA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,OACP;wCACF,MAAM;wCACN,GAAG,IAAI;wCACP,OAAO;wCACP,UAAU;wCACV,GAAG,SAAS;wCACZ,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ;qCAC5B,GACD,CACH,CAAC;4BACJ,CAAC,IApBI,IAAI,CAAC,EAAE,CAqBF,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 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 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 {...{\n testId,\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"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { RefCallback, ComponentType } from 'react';
|
|
2
|
-
import { AsProp, BaseProps, NoChildrenProp } from '@pega/cosmos-react-core';
|
|
2
|
+
import { AsProp, BaseProps, NoChildrenProp, TestIdProp } from '@pega/cosmos-react-core';
|
|
3
3
|
import { DraggableItem, DraggableCollectedProps } from '../Draggable';
|
|
4
4
|
import { DroppableProps } from '../Droppable';
|
|
5
|
-
export interface ItemRendererProps<T extends object = object> extends DraggableItem<T>, DraggableCollectedProps {
|
|
5
|
+
export interface ItemRendererProps<T extends object = object> extends DraggableItem<T>, DraggableCollectedProps, TestIdProp {
|
|
6
6
|
dragRef: RefCallback<HTMLElement>;
|
|
7
7
|
previewRef: RefCallback<HTMLElement>;
|
|
8
8
|
}
|
|
9
|
-
export interface DragDropListProps<T extends object = object> extends AsProp, BaseProps, NoChildrenProp {
|
|
9
|
+
export interface DragDropListProps<T extends object = object> extends AsProp, BaseProps, NoChildrenProp, TestIdProp {
|
|
10
10
|
/** Unique identifier for the list */
|
|
11
11
|
id?: string;
|
|
12
12
|
/** Type of item allowed to be dropped on this list (useful when there is multiple lists that share data). */
|
|
@@ -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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E,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 /** 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"]}
|
|
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, TestIdProp } 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 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"]}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { FunctionComponent } from 'react';
|
|
2
2
|
import { type ForwardProps } from '@pega/cosmos-react-core';
|
|
3
3
|
import { StandardDragDropListProps } from './StandardDragDropList.types';
|
|
4
|
-
declare
|
|
5
|
-
|
|
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;
|
|
6
8
|
//# sourceMappingURL=StandardDragDropList.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StandardDragDropList.d.ts","sourceRoot":"","sources":["../../../src/components/StandardDragDropList/StandardDragDropList.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAOlB,MAAM,OAAO,CAAC;AAEf,OAAO,EACL,KAAK,YAAY,
|
|
1
|
+
{"version":3,"file":"StandardDragDropList.d.ts","sourceRoot":"","sources":["../../../src/components/StandardDragDropList/StandardDragDropList.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAOlB,MAAM,OAAO,CAAC;AAEf,OAAO,EACL,KAAK,YAAY,EAclB,MAAM,yBAAyB,CAAC;AAmBjC,OAAO,EACL,yBAAyB,EAE1B,MAAM,8BAA8B,CAAC;;;;AA+YtC,wBAAiF"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef, useCallback, useMemo, useRef, useState } from 'react';
|
|
3
|
-
import { Flex, registerIcon, Icon, Text, Button, useI18n, EmptyState, ExpandCollapse, useUID, Tooltip, useElement } from '@pega/cosmos-react-core';
|
|
3
|
+
import { Flex, registerIcon, Icon, Text, Button, useI18n, EmptyState, ExpandCollapse, useUID, Tooltip, useElement, useTestIds, withTestIds } from '@pega/cosmos-react-core';
|
|
4
4
|
import * as DragIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/drag.icon';
|
|
5
5
|
import * as PlusIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/plus.icon';
|
|
6
6
|
import * as CaretDownIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/caret-down.icon';
|
|
7
7
|
import DragDropList from '../DragDropList';
|
|
8
8
|
import { StyledStandardDragDropList, StyledStandardDragDropListItem, StyledDragHandle, StyledExpandCollapseToggle, StyledItemActions, StyledItemContent, StyledItemStatus, StyledListItemInner, StyledSecondary } from './StandardDragDropList.styles';
|
|
9
|
+
import { getItemRendererTestIds, getStandardDragDropListTestIds } from './StandardDragDropList.test-ids';
|
|
9
10
|
registerIcon(DragIcon, PlusIcon, CaretDownIcon);
|
|
10
|
-
// eslint-disable-next-line import/no-mutable-exports
|
|
11
11
|
let StandardDragDropList;
|
|
12
12
|
const ItemStatus = ({ message, type }) => {
|
|
13
13
|
const [ttt, setTTT] = useElement(null);
|
|
@@ -18,34 +18,37 @@ const getFlattenedIds = (items) => {
|
|
|
18
18
|
return item.items ? [item.id, ...item.items.map(({ id }) => id)] : [item.id];
|
|
19
19
|
});
|
|
20
20
|
};
|
|
21
|
-
const ItemRenderer = ({ dragRef, previewRef, isDragging, data: { id,
|
|
21
|
+
const ItemRenderer = ({ testId, dragRef, previewRef, isDragging, data: { id,
|
|
22
22
|
// Remove type for DOM restProps
|
|
23
23
|
type, accept, primary, secondary, draggable = true, status, items, onConfigure, onRemove, onAddTo, onChange, ...restProps }, data }) => {
|
|
24
24
|
const t = useI18n();
|
|
25
25
|
const [collapsed, setCollapsed] = useState(false);
|
|
26
26
|
const expandCollpaseId = useUID();
|
|
27
|
+
const testIds = useTestIds(testId, getItemRendererTestIds);
|
|
27
28
|
const hasActions = !!(onConfigure ?? onRemove ?? onAddTo);
|
|
28
29
|
const primaryEl = useMemo(() => {
|
|
29
30
|
if (items) {
|
|
30
|
-
return (_jsx(StyledExpandCollapseToggle, { 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 })] }) }));
|
|
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 })] }) }));
|
|
31
32
|
}
|
|
32
33
|
if (typeof primary === 'string') {
|
|
33
34
|
return _jsx("span", { children: primary });
|
|
34
35
|
}
|
|
35
36
|
return (_jsx(Button, { variant: 'link', onClick: primary.onClick, href: primary.href, children: _jsx("span", { children: primary.text }) }));
|
|
36
37
|
}, [t, items, primary, collapsed, expandCollpaseId]);
|
|
37
|
-
return (_jsxs(Flex, { ...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, { icon: true, variant: 'simple', label: t('add'), onClick: (e) => {
|
|
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) => {
|
|
38
39
|
onAddTo?.(id, e);
|
|
39
|
-
}, children: _jsx(Icon, { name: 'plus' }) }) })), onConfigure && (_jsx("span", { children: _jsx(Button, { icon: true, variant: 'simple', label: t('configure'), onClick: (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) => {
|
|
40
41
|
onConfigure?.(id, e);
|
|
41
|
-
}, children: _jsx(Icon, { name: 'gear' }) }) })), onRemove && (_jsx("span", { children: _jsx(Button, { icon: true, variant: 'simple', label: t('remove'), onClick: (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) => {
|
|
42
43
|
onRemove?.(id, e);
|
|
43
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 }) }))] }));
|
|
44
45
|
};
|
|
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) {
|
|
46
48
|
const flatIds = useMemo(() => getFlattenedIds(itemsProp), [itemsProp]);
|
|
47
49
|
const timerRef = useRef();
|
|
48
50
|
const newItemsRef = useRef();
|
|
51
|
+
const testIds = useTestIds(testId, getStandardDragDropListTestIds);
|
|
49
52
|
const mergeChangeHandler = useCallback((newItems) => {
|
|
50
53
|
if (typeof timerRef.current === 'number' && newItemsRef.current) {
|
|
51
54
|
clearTimeout(timerRef.current);
|
|
@@ -139,16 +142,16 @@ StandardDragDropList = forwardRef(function StandardDragDropListFunction({ accept
|
|
|
139
142
|
onChangeProp(newContentItems);
|
|
140
143
|
}
|
|
141
144
|
}, [onChangeProp, flatIds, mergeChangeHandler]);
|
|
142
|
-
return (_jsxs(StyledStandardDragDropList, { ref: ref, ...restProps, children: [title && (_jsx(Flex, { container: {
|
|
145
|
+
return (_jsxs(StyledStandardDragDropList, { ref: ref, ...restProps, children: [title && (_jsx(Flex, { "data-testid": testIds.header, container: {
|
|
143
146
|
justify: 'between',
|
|
144
147
|
alignItems: 'center',
|
|
145
148
|
gap: 1,
|
|
146
149
|
pad: 1
|
|
147
|
-
}, as: 'header', children: _jsx(Text, { variant: headingTag, children: title }) })), _jsx(DragDropList, { accept: accept, items: itemsToRender, pushMode: pushMode, pullMode: pullMode, itemRenderer:
|
|
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: {
|
|
148
151
|
alignItems: 'center',
|
|
149
152
|
itemGap: 1,
|
|
150
153
|
pad: 1
|
|
151
154
|
}, as: 'footer', children: footer }))] }));
|
|
152
155
|
});
|
|
153
|
-
export default StandardDragDropList;
|
|
156
|
+
export default withTestIds(StandardDragDropList, getStandardDragDropListTestIds);
|
|
154
157
|
//# sourceMappingURL=StandardDragDropList.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StandardDragDropList.js","sourceRoot":"","sources":["../../../src/components/StandardDragDropList/StandardDragDropList.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EAIV,WAAW,EACX,OAAO,EACP,MAAM,EACN,QAAQ,EACT,MAAM,OAAO,CAAC;AAEf,OAAO,EAEL,IAAI,EACJ,YAAY,EACZ,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,OAAO,EACP,UAAU,EACV,cAAc,EACd,MAAM,EACN,OAAO,EACP,UAAU,EACX,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,QAAQ,M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,CAAC,YAAY,EAAE,OAAO,EAAE,kBAAkB,CAAC,CAC5C,CAAC;IAEF,OAAO,CACL,MAAC,0BAA0B,IAAC,GAAG,EAAE,GAAG,KAAM,SAAS,aAChD,KAAK,IAAI,CACR,KAAC,IAAI,IACH,SAAS,EAAE;oBACT,OAAO,EAAE,SAAS;oBAClB,UAAU,EAAE,QAAQ;oBACpB,GAAG,EAAE,CAAC;oBACN,GAAG,EAAE,CAAC;iBACP,EACD,EAAE,EAAC,QAAQ,YAEX,KAAC,IAAI,IAAC,OAAO,EAAE,UAAU,YAAG,KAAK,GAAQ,GACpC,CACR,EACD,KAAC,YAAY,IACX,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,YAAY,EAC1B,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,oBAAoB,CAAC","sourcesContent":["import {\n forwardRef,\n FunctionComponent,\n MouseEvent,\n PropsWithoutRef,\n useCallback,\n useMemo,\n useRef,\n useState\n} from 'react';\n\nimport {\n type ForwardProps,\n Flex,\n registerIcon,\n Icon,\n Text,\n Button,\n useI18n,\n EmptyState,\n ExpandCollapse,\n useUID,\n Tooltip,\n useElement\n} 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, { ItemRendererProps } from '../DragDropList';\nimport { 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 {\n StandardDragDropListProps,\n StandardDragDropListItemProps\n} from './StandardDragDropList.types';\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\n// eslint-disable-next-line import/no-mutable-exports\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 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\n const hasActions = !!(onConfigure ?? onRemove ?? onAddTo);\n\n const primaryEl = useMemo(() => {\n if (items) {\n return (\n <StyledExpandCollapseToggle\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 {...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 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 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 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\nStandardDragDropList = forwardRef(function StandardDragDropListFunction(\n {\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 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 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 accept={accept}\n items={itemsToRender}\n pushMode={pushMode}\n pullMode={pullMode}\n itemRenderer={ItemRenderer}\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 StandardDragDropList;\n"]}
|
|
1
|
+
{"version":3,"file":"StandardDragDropList.js","sourceRoot":"","sources":["../../../src/components/StandardDragDropList/StandardDragDropList.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EAIV,WAAW,EACX,OAAO,EACP,MAAM,EACN,QAAQ,EACT,MAAM,OAAO,CAAC;AAEf,OAAO,EAEL,IAAI,EACJ,YAAY,EACZ,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,OAAO,EACP,UAAU,EACV,cAAc,EACd,MAAM,EACN,OAAO,EACP,UAAU,EACV,UAAU,EACV,WAAW,EACZ,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,QAAQ,MAAM,6DAA6D,CAAC;AACxF,OAAO,KAAK,QAAQ,MAAM,6DAA6D,CAAC;AACxF,OAAO,KAAK,aAAa,MAAM,mEAAmE,CAAC;AAEnG,OAAO,YAAmC,MAAM,iBAAiB,CAAC;AAGlE,OAAO,EACL,0BAA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n useRef,\n useState\n} from 'react';\n\nimport {\n type ForwardProps,\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 * 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, { ItemRendererProps } from '../DragDropList';\nimport { 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 {\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,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"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MouseEvent, MouseEventHandler, ReactNode, Ref } from 'react';
|
|
2
|
-
import { OmitStrict, BaseProps, NoChildrenProp, ForwardProps, HeadingTag } from '@pega/cosmos-react-core';
|
|
2
|
+
import { TestIdProp, OmitStrict, BaseProps, NoChildrenProp, ForwardProps, HeadingTag } from '@pega/cosmos-react-core';
|
|
3
3
|
import { DragDropListProps } from '../DragDropList';
|
|
4
|
-
export interface StandardDragDropListProps extends OmitStrict<DragDropListProps<StandardDragDropListItemProps>, 'dragHandles' | 'itemRenderer' | 'emptyRenderer' | 'items' | 'onChange'>, BaseProps, NoChildrenProp {
|
|
4
|
+
export interface StandardDragDropListProps extends OmitStrict<DragDropListProps<StandardDragDropListItemProps>, 'dragHandles' | 'itemRenderer' | 'emptyRenderer' | 'items' | 'onChange'>, BaseProps, NoChildrenProp, TestIdProp {
|
|
5
5
|
/** The contents of the list. */
|
|
6
6
|
items: StandardDragDropListItemProps[];
|
|
7
7
|
/** A title for the list. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StandardDragDropList.types.d.ts","sourceRoot":"","sources":["../../../src/components/StandardDragDropList/StandardDragDropList.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAEtE,OAAO,EACL,UAAU,EACV,SAAS,EACT,cAAc,EACd,YAAY,EACZ,UAAU,EACX,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD,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;
|
|
1
|
+
{"version":3,"file":"StandardDragDropList.types.d.ts","sourceRoot":"","sources":["../../../src/components/StandardDragDropList/StandardDragDropList.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAEtE,OAAO,EACL,UAAU,EACV,UAAU,EACV,SAAS,EACT,cAAc,EACd,YAAY,EACZ,UAAU,EACX,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD,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,EAAE,yBAAyB,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;IAC9D,uDAAuD;IACvD,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CAC3B;AAED,KAAK,UAAU,GAAG,CAChB,EAAE,EAAE,6BAA6B,CAAC,IAAI,CAAC,EACvC,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,KAC7B,IAAI,CAAC;AAEV,MAAM,MAAM,6BAA6B,GAAG,YAAY,GAAG;IACzD,6DAA6D;IAC7D,EAAE,EAAE,MAAM,CAAC;IACX,mFAAmF;IACnF,IAAI,EAAE,MAAM,CAAC;IACb,wFAAwF;IACxF,OAAO,EAAE,MAAM,GAAG,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,iBAAiB,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,YAAY,CAAC,CAAC;IAC/F,uEAAuE;IACvE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yDAAyD;IACzD,MAAM,CAAC,EAAE;QACP,IAAI,EAAE,OAAO,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,0DAA0D;IAC1D,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,WAAW,CAAC,EAAE,UAAU,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,UAAU,CAAC;CACvB,GAAG,CACE;IACE,sDAAsD;IACtD,KAAK,EAAE,6BAA6B,EAAE,CAAC;IACvC,kHAAkH;IAClH,MAAM,CAAC,EAAE,yBAAyB,CAAC,QAAQ,CAAC,CAAC;IAC7C,6DAA6D;IAC7D,OAAO,CAAC,EAAE,UAAU,CAAC;CACtB,GACD;IACE,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,MAAM,CAAC,EAAE,KAAK,CAAC;IACf,OAAO,CAAC,EAAE,KAAK,CAAC;CACjB,CACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StandardDragDropList.types.js","sourceRoot":"","sources":["../../../src/components/StandardDragDropList/StandardDragDropList.types.ts"],"names":[],"mappings":"","sourcesContent":["import { MouseEvent, MouseEventHandler, ReactNode, Ref } from 'react';\n\nimport {\n OmitStrict,\n BaseProps,\n NoChildrenProp,\n ForwardProps,\n HeadingTag\n} from '@pega/cosmos-react-core';\n\nimport { 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 /** 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"]}
|
|
1
|
+
{"version":3,"file":"StandardDragDropList.types.js","sourceRoot":"","sources":["../../../src/components/StandardDragDropList/StandardDragDropList.types.ts"],"names":[],"mappings":"","sourcesContent":["import { MouseEvent, MouseEventHandler, ReactNode, Ref } from 'react';\n\nimport {\n TestIdProp,\n OmitStrict,\n BaseProps,\n NoChildrenProp,\n ForwardProps,\n HeadingTag\n} from '@pega/cosmos-react-core';\n\nimport { 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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pega/cosmos-react-dnd",
|
|
3
|
-
"version": "5.0.0-dev.1
|
|
3
|
+
"version": "5.0.0-dev.2.1",
|
|
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.1
|
|
23
|
+
"@pega/cosmos-react-core": "5.0.0-dev.2.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",
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
"styled-components": "^5.2.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@storybook/addon-a11y": "
|
|
37
|
-
"@storybook/addon-actions": "
|
|
38
|
-
"@storybook/addon-storysource": "
|
|
39
|
-
"@storybook/addon-toolbars": "
|
|
40
|
-
"@storybook/react": "
|
|
41
|
-
"@storybook/theming": "
|
|
36
|
+
"@storybook/addon-a11y": "~7.0.24",
|
|
37
|
+
"@storybook/addon-actions": "~7.0.24",
|
|
38
|
+
"@storybook/addon-storysource": "~7.0.24",
|
|
39
|
+
"@storybook/addon-toolbars": "~7.0.24",
|
|
40
|
+
"@storybook/react": "~7.0.24",
|
|
41
|
+
"@storybook/theming": "~7.0.24",
|
|
42
42
|
"typescript": "~5.0.2"
|
|
43
43
|
}
|
|
44
44
|
}
|