cozy-ui 127.2.0 → 127.4.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 (27) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/package.json +1 -1
  3. package/react/GridList/Virtualized/Dnd/GridItem.jsx +86 -0
  4. package/react/GridList/Virtualized/Dnd/index.jsx +67 -0
  5. package/react/GridList/Virtualized/index.jsx +22 -0
  6. package/react/Table/Virtualized/Dnd/index.jsx +1 -1
  7. package/react/Table/Virtualized/Dnd/virtuosoComponents.jsx +1 -1
  8. package/react/utils/Dnd/CustomDrag/CustomDragLayer.jsx +45 -0
  9. package/react/utils/Dnd/CustomDrag/DragPreview.jsx +43 -0
  10. package/react/utils/Dnd/CustomDrag/DragPreviewWrapper.jsx +52 -0
  11. package/react/utils/Dnd/DnDConfigWrapper.jsx +48 -0
  12. package/transpiled/react/GridList/Virtualized/Dnd/GridItem.d.ts +7 -0
  13. package/transpiled/react/GridList/Virtualized/Dnd/GridItem.js +139 -0
  14. package/transpiled/react/GridList/Virtualized/Dnd/index.d.ts +13 -0
  15. package/transpiled/react/GridList/Virtualized/Dnd/index.js +81 -0
  16. package/transpiled/react/GridList/Virtualized/index.d.ts +3 -0
  17. package/transpiled/react/GridList/Virtualized/index.js +28 -0
  18. package/transpiled/react/Table/Virtualized/Dnd/index.js +1 -1
  19. package/transpiled/react/Table/Virtualized/Dnd/virtuosoComponents.js +1 -1
  20. package/transpiled/react/utils/Dnd/CustomDrag/CustomDragLayer.d.ts +4 -0
  21. package/transpiled/react/utils/Dnd/CustomDrag/CustomDragLayer.js +47 -0
  22. package/transpiled/react/utils/Dnd/CustomDrag/DragPreview.d.ts +6 -0
  23. package/transpiled/react/utils/Dnd/CustomDrag/DragPreview.js +34 -0
  24. package/transpiled/react/utils/Dnd/CustomDrag/DragPreviewWrapper.d.ts +8 -0
  25. package/transpiled/react/utils/Dnd/CustomDrag/DragPreviewWrapper.js +63 -0
  26. package/transpiled/react/utils/Dnd/DnDConfigWrapper.d.ts +2 -0
  27. package/transpiled/react/utils/Dnd/DnDConfigWrapper.js +55 -0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [127.4.0](https://github.com/cozy/cozy-ui/compare/v127.3.0...v127.4.0) (2025-07-21)
2
+
3
+
4
+ ### Features
5
+
6
+ * implement virtualized grid list drag and drop :sparkles: ([c4f93a1](https://github.com/cozy/cozy-ui/commit/c4f93a1))
7
+
8
+ # [127.3.0](https://github.com/cozy/cozy-ui/compare/v127.2.0...v127.3.0) (2025-07-21)
9
+
10
+
11
+ ### Features
12
+
13
+ * implement virtualized grid :sparkles: ([9a6a475](https://github.com/cozy/cozy-ui/commit/9a6a475))
14
+
1
15
  # [127.2.0](https://github.com/cozy/cozy-ui/compare/v127.1.0...v127.2.0) (2025-07-01)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "127.2.0",
3
+ "version": "127.4.0",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -0,0 +1,86 @@
1
+ import cx from 'classnames'
2
+ import React, { useEffect } from 'react'
3
+ import { useDrag, useDrop } from 'react-dnd'
4
+ import { getEmptyImage } from 'react-dnd-html5-backend'
5
+
6
+ const GridItem = ({ item, context, renderItem, className }) => {
7
+ const {
8
+ selectedItems = [],
9
+ itemsInDropProcess = [],
10
+ setItemsInDropProcess = () => {},
11
+ dragProps
12
+ } = context || {}
13
+
14
+ const {
15
+ onDrop,
16
+ canDrop: canDropProps,
17
+ canDrag: canDragProps,
18
+ dragId
19
+ } = dragProps
20
+
21
+ const isSelected = context?.isSelectedItem?.(item)
22
+ const isDisabled = itemsInDropProcess.includes(item._id)
23
+
24
+ const [{ isDragging }, dragRef, dragPreview] = useDrag(
25
+ () => ({
26
+ type: dragId,
27
+ isDragging: monitor => {
28
+ if (selectedItems.length > 0) {
29
+ return selectedItems.some(sel => sel._id === item._id)
30
+ }
31
+ return item._id === monitor.getItem().draggedItems?.[0]._id
32
+ },
33
+ item: {
34
+ draggedItems: selectedItems.length > 0 ? selectedItems : [item]
35
+ },
36
+ canDrag: () => {
37
+ const defaultCanDrag = canDragProps?.(item) ?? true
38
+ if (selectedItems.length > 0) {
39
+ return defaultCanDrag && isSelected
40
+ }
41
+ return defaultCanDrag
42
+ },
43
+ collect: monitor => ({
44
+ isDragging: monitor.isDragging()
45
+ })
46
+ }),
47
+ [item, selectedItems]
48
+ )
49
+
50
+ const [{ isOver }, dropRef] = useDrop(
51
+ () => ({
52
+ accept: dragId,
53
+ canDrop: () => (canDropProps ? canDropProps(item) : true),
54
+ drop: async draggedItem => {
55
+ setItemsInDropProcess(
56
+ draggedItem.draggedItems.map(dragged => dragged._id)
57
+ )
58
+ await onDrop(draggedItem.draggedItems, item, selectedItems)
59
+ setItemsInDropProcess([])
60
+ },
61
+ collect: monitor => ({
62
+ isOver: monitor.isOver()
63
+ })
64
+ }),
65
+ [item._id, selectedItems]
66
+ )
67
+
68
+ useEffect(() => {
69
+ dragPreview(getEmptyImage(), { captureDraggingState: true })
70
+ }, [dragPreview])
71
+
72
+ return (
73
+ <div
74
+ ref={node => dragRef(dropRef(node))}
75
+ className={cx(
76
+ className,
77
+ isDragging ? 'virtualized u-o-50' : 'virtualized'
78
+ )}
79
+ style={{ opacity: isDisabled ? 0.5 : 1 }}
80
+ >
81
+ {renderItem(item, { isDragging, isOver, isDisabled })}
82
+ </div>
83
+ )
84
+ }
85
+
86
+ export default GridItem
@@ -0,0 +1,67 @@
1
+ import React, { forwardRef, useState, useMemo } from 'react'
2
+
3
+ import GridItem from './GridItem'
4
+ import VirtualizedGridList from '../'
5
+ import CustomDragLayer from '../../../utils/Dnd/CustomDrag/CustomDragLayer'
6
+ import DnDConfigWrapper from '../../../utils/Dnd/DnDConfigWrapper'
7
+
8
+ const VirtualizedGridListDnd = ({
9
+ dragProps,
10
+ context,
11
+ itemRenderer,
12
+ children,
13
+ componentProps = {
14
+ List: {},
15
+ Item: {}
16
+ },
17
+ components,
18
+ ...props
19
+ }) => {
20
+ const [itemsInDropProcess, setItemsInDropProcess] = useState([])
21
+
22
+ const _context = useMemo(
23
+ () => ({
24
+ ...context,
25
+ dragProps,
26
+ itemRenderer,
27
+ itemsInDropProcess,
28
+ setItemsInDropProcess,
29
+ items: props.items
30
+ }),
31
+ [context, dragProps, itemRenderer, itemsInDropProcess, props.items]
32
+ )
33
+
34
+ return (
35
+ <>
36
+ <CustomDragLayer dragId={dragProps.dragId} />
37
+ <VirtualizedGridList
38
+ components={{
39
+ Scroller: forwardRef(({ ...scrollerProps }, ref) => (
40
+ <DnDConfigWrapper ref={ref}>
41
+ <div {...scrollerProps} ref={ref} />
42
+ </DnDConfigWrapper>
43
+ )),
44
+ Item: ({ context, children, ...props }) => {
45
+ const item = context?.items?.[props['data-index']]
46
+ return (
47
+ <GridItem
48
+ item={item}
49
+ context={context}
50
+ renderItem={() => <>{children}</>}
51
+ {...componentProps.Item}
52
+ />
53
+ )
54
+ },
55
+ ...components
56
+ }}
57
+ context={_context}
58
+ itemRenderer={itemRenderer}
59
+ {...props}
60
+ >
61
+ {children}
62
+ </VirtualizedGridList>
63
+ </>
64
+ )
65
+ }
66
+
67
+ export default VirtualizedGridListDnd
@@ -0,0 +1,22 @@
1
+ import React, { forwardRef } from 'react'
2
+ import { VirtuosoGrid } from 'react-virtuoso'
3
+
4
+ const VirtualizedGridList = forwardRef(
5
+ ({ items = [], itemRenderer, components, context, ...props }, ref) => {
6
+ return (
7
+ <VirtuosoGrid
8
+ ref={ref}
9
+ components={components}
10
+ context={context}
11
+ style={{ height: '100%' }}
12
+ totalCount={items.length}
13
+ itemContent={index => itemRenderer(items[index])}
14
+ {...props}
15
+ />
16
+ )
17
+ }
18
+ )
19
+
20
+ VirtualizedGridList.displayName = 'VirtualizedGridList'
21
+
22
+ export default VirtualizedGridList
@@ -1,7 +1,7 @@
1
1
  import React, { useState, useMemo } from 'react'
2
2
 
3
- import CustomDragLayer from './CustomDrag/CustomDragLayer'
4
3
  import virtuosoComponentsDnd from './virtuosoComponents'
4
+ import CustomDragLayer from '../../../utils/Dnd/CustomDrag/CustomDragLayer'
5
5
  import VirtualizedTable from '../index'
6
6
  import virtuosoComponents from '../virtuosoComponents'
7
7
 
@@ -1,8 +1,8 @@
1
1
  import React, { forwardRef } from 'react'
2
2
 
3
- import DnDConfigWrapper from './DnDConfigWrapper'
4
3
  import TableRowDnD from './TableRow'
5
4
  import TableContainer from '../../../TableContainer'
5
+ import DnDConfigWrapper from '../../../utils/Dnd/DnDConfigWrapper'
6
6
  import virtuosoComponents from '../virtuosoComponents'
7
7
 
8
8
  /**
@@ -0,0 +1,45 @@
1
+ import React from 'react'
2
+ import { useDragLayer } from 'react-dnd'
3
+
4
+ import DragPreviewWrapper from './DragPreviewWrapper'
5
+
6
+ const layerStyles = {
7
+ position: 'fixed',
8
+ pointerEvents: 'none',
9
+ zIndex: 100,
10
+ left: 0,
11
+ top: 0,
12
+ width: '100%',
13
+ height: '100%'
14
+ }
15
+
16
+ // Example find in the official documentation
17
+ // https://react-dnd.github.io/react-dnd/examples/drag-around/custom-drag-layer
18
+ export const CustomDragLayer = ({ dragId }) => {
19
+ const { itemType, isDragging, item, initialOffset, currentOffset } =
20
+ useDragLayer(monitor => ({
21
+ item: monitor.getItem(),
22
+ itemType: monitor.getItemType(),
23
+ initialOffset: monitor.getInitialSourceClientOffset(),
24
+ currentOffset: monitor.getSourceClientOffset(),
25
+ isDragging: monitor.isDragging()
26
+ }))
27
+
28
+ if (!isDragging) {
29
+ return null
30
+ }
31
+
32
+ return (
33
+ <div style={layerStyles}>
34
+ <DragPreviewWrapper
35
+ item={item}
36
+ itemType={itemType}
37
+ dragId={dragId}
38
+ initialOffset={initialOffset}
39
+ currentOffset={currentOffset}
40
+ />
41
+ </div>
42
+ )
43
+ }
44
+
45
+ export default CustomDragLayer
@@ -0,0 +1,43 @@
1
+ import React from 'react'
2
+
3
+ import Badge from '../../../Badge'
4
+ import Paper from '../../../Paper'
5
+ import Typography from '../../../Typography'
6
+ import { makeStyles } from '../../../styles'
7
+
8
+ const useStyles = makeStyles({
9
+ root: {
10
+ width: 'fit-content'
11
+ }
12
+ })
13
+
14
+ const DragPreview = ({ fileName, selectedCount }) => {
15
+ const classes = useStyles()
16
+
17
+ return (
18
+ <>
19
+ {selectedCount > 1 ? (
20
+ <Badge
21
+ badgeContent={selectedCount}
22
+ size="large"
23
+ color="primary"
24
+ anchorOrigin={{
25
+ vertical: 'top',
26
+ horizontal: 'right'
27
+ }}
28
+ overlap="rectangular"
29
+ >
30
+ <Paper classes={classes} className="u-p-half u-maw-5">
31
+ <Typography>{fileName}</Typography>
32
+ </Paper>
33
+ </Badge>
34
+ ) : (
35
+ <Paper classes={classes} className="u-p-half u-maw-5">
36
+ <Typography>{fileName}</Typography>
37
+ </Paper>
38
+ )}
39
+ </>
40
+ )
41
+ }
42
+
43
+ export default React.memo(DragPreview)
@@ -0,0 +1,52 @@
1
+ import React, { useEffect, useState } from 'react'
2
+
3
+ import DragPreview from './DragPreview'
4
+
5
+ const makeStyles = ({ x, y }) => {
6
+ if (!x || !y) {
7
+ return { display: 'none' }
8
+ }
9
+
10
+ const transform = `translate(${x}px, ${y}px)`
11
+
12
+ return {
13
+ transform,
14
+ WebkitTransform: transform
15
+ }
16
+ }
17
+
18
+ const DragPreviewWrapper = ({
19
+ item,
20
+ itemType,
21
+ dragId,
22
+ initialOffset,
23
+ currentOffset
24
+ }) => {
25
+ const [mousePosition, setMousePosition] = useState({ x: null, y: null })
26
+
27
+ useEffect(() => {
28
+ const handleMouseMove = e => {
29
+ setMousePosition({ x: e.clientX, y: e.clientY })
30
+ }
31
+
32
+ window.addEventListener('dragover', handleMouseMove)
33
+ return () => {
34
+ window.removeEventListener('dragover', handleMouseMove)
35
+ }
36
+ }, [])
37
+
38
+ if (!initialOffset || !currentOffset || itemType !== dragId) {
39
+ return null
40
+ }
41
+
42
+ return (
43
+ <div style={makeStyles(mousePosition)}>
44
+ <DragPreview
45
+ fileName={item.draggedItems[0].name}
46
+ selectedCount={item.draggedItems.length}
47
+ />
48
+ </div>
49
+ )
50
+ }
51
+
52
+ export default DragPreviewWrapper
@@ -0,0 +1,48 @@
1
+ import { forwardRef, useEffect, useState } from 'react'
2
+ import { useDragDropManager } from 'react-dnd'
3
+
4
+ const DnDConfigWrapper = forwardRef(({ children }, ref) => {
5
+ const dragDropManager = useDragDropManager()
6
+ const monitor = dragDropManager.getMonitor()
7
+ const [isDragging, setIsDragging] = useState(false)
8
+
9
+ useEffect(() => {
10
+ const unsubscribe = monitor.subscribeToStateChange(() => {
11
+ setIsDragging(monitor.isDragging())
12
+ })
13
+ return () => unsubscribe()
14
+ }, [monitor])
15
+
16
+ useEffect(() => {
17
+ if (!isDragging) return
18
+
19
+ const scrollThreshold = 100
20
+ const scrollMaxSpeed = 75
21
+
22
+ const intervalId = setInterval(() => {
23
+ const offset = monitor.getClientOffset()
24
+ const container = ref.current
25
+ if (!offset || !container) return
26
+
27
+ const { top, bottom } = container.getBoundingClientRect()
28
+ const distanceToTop = offset.y - top
29
+ const distanceToBottom = bottom - offset.y
30
+
31
+ if (distanceToTop < scrollThreshold) {
32
+ const speed = scrollMaxSpeed * (1 - distanceToTop / scrollThreshold)
33
+ container.scrollBy(0, -speed)
34
+ } else if (distanceToBottom < scrollThreshold) {
35
+ const speed = scrollMaxSpeed * (1 - distanceToBottom / scrollThreshold)
36
+ container.scrollBy(0, speed)
37
+ }
38
+ }, 16) // ~60fps
39
+
40
+ return () => clearInterval(intervalId)
41
+ }, [isDragging, monitor, ref])
42
+
43
+ return children
44
+ })
45
+
46
+ DnDConfigWrapper.displayName = 'DnDConfigWrapper'
47
+
48
+ export default DnDConfigWrapper
@@ -0,0 +1,7 @@
1
+ export default GridItem;
2
+ declare function GridItem({ item, context, renderItem, className }: {
3
+ item: any;
4
+ context: any;
5
+ renderItem: any;
6
+ className: any;
7
+ }): JSX.Element;
@@ -0,0 +1,139 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
4
+ import cx from 'classnames';
5
+ import React, { useEffect } from 'react';
6
+ import { useDrag, useDrop } from 'react-dnd';
7
+ import { getEmptyImage } from 'react-dnd-html5-backend';
8
+
9
+ var GridItem = function GridItem(_ref) {
10
+ var _context$isSelectedIt;
11
+
12
+ var item = _ref.item,
13
+ context = _ref.context,
14
+ renderItem = _ref.renderItem,
15
+ className = _ref.className;
16
+
17
+ var _ref2 = context || {},
18
+ _ref2$selectedItems = _ref2.selectedItems,
19
+ selectedItems = _ref2$selectedItems === void 0 ? [] : _ref2$selectedItems,
20
+ _ref2$itemsInDropProc = _ref2.itemsInDropProcess,
21
+ itemsInDropProcess = _ref2$itemsInDropProc === void 0 ? [] : _ref2$itemsInDropProc,
22
+ _ref2$setItemsInDropP = _ref2.setItemsInDropProcess,
23
+ setItemsInDropProcess = _ref2$setItemsInDropP === void 0 ? function () {} : _ref2$setItemsInDropP,
24
+ dragProps = _ref2.dragProps;
25
+
26
+ var onDrop = dragProps.onDrop,
27
+ canDropProps = dragProps.canDrop,
28
+ canDragProps = dragProps.canDrag,
29
+ dragId = dragProps.dragId;
30
+ var isSelected = context === null || context === void 0 ? void 0 : (_context$isSelectedIt = context.isSelectedItem) === null || _context$isSelectedIt === void 0 ? void 0 : _context$isSelectedIt.call(context, item);
31
+ var isDisabled = itemsInDropProcess.includes(item._id);
32
+
33
+ var _useDrag = useDrag(function () {
34
+ return {
35
+ type: dragId,
36
+ isDragging: function isDragging(monitor) {
37
+ var _monitor$getItem$drag;
38
+
39
+ if (selectedItems.length > 0) {
40
+ return selectedItems.some(function (sel) {
41
+ return sel._id === item._id;
42
+ });
43
+ }
44
+
45
+ return item._id === ((_monitor$getItem$drag = monitor.getItem().draggedItems) === null || _monitor$getItem$drag === void 0 ? void 0 : _monitor$getItem$drag[0]._id);
46
+ },
47
+ item: {
48
+ draggedItems: selectedItems.length > 0 ? selectedItems : [item]
49
+ },
50
+ canDrag: function canDrag() {
51
+ var _canDragProps;
52
+
53
+ var defaultCanDrag = (_canDragProps = canDragProps === null || canDragProps === void 0 ? void 0 : canDragProps(item)) !== null && _canDragProps !== void 0 ? _canDragProps : true;
54
+
55
+ if (selectedItems.length > 0) {
56
+ return defaultCanDrag && isSelected;
57
+ }
58
+
59
+ return defaultCanDrag;
60
+ },
61
+ collect: function collect(monitor) {
62
+ return {
63
+ isDragging: monitor.isDragging()
64
+ };
65
+ }
66
+ };
67
+ }, [item, selectedItems]),
68
+ _useDrag2 = _slicedToArray(_useDrag, 3),
69
+ isDragging = _useDrag2[0].isDragging,
70
+ dragRef = _useDrag2[1],
71
+ dragPreview = _useDrag2[2];
72
+
73
+ var _useDrop = useDrop(function () {
74
+ return {
75
+ accept: dragId,
76
+ canDrop: function canDrop() {
77
+ return canDropProps ? canDropProps(item) : true;
78
+ },
79
+ drop: function () {
80
+ var _drop = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(draggedItem) {
81
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
82
+ while (1) {
83
+ switch (_context.prev = _context.next) {
84
+ case 0:
85
+ setItemsInDropProcess(draggedItem.draggedItems.map(function (dragged) {
86
+ return dragged._id;
87
+ }));
88
+ _context.next = 3;
89
+ return onDrop(draggedItem.draggedItems, item, selectedItems);
90
+
91
+ case 3:
92
+ setItemsInDropProcess([]);
93
+
94
+ case 4:
95
+ case "end":
96
+ return _context.stop();
97
+ }
98
+ }
99
+ }, _callee);
100
+ }));
101
+
102
+ function drop(_x) {
103
+ return _drop.apply(this, arguments);
104
+ }
105
+
106
+ return drop;
107
+ }(),
108
+ collect: function collect(monitor) {
109
+ return {
110
+ isOver: monitor.isOver()
111
+ };
112
+ }
113
+ };
114
+ }, [item._id, selectedItems]),
115
+ _useDrop2 = _slicedToArray(_useDrop, 2),
116
+ isOver = _useDrop2[0].isOver,
117
+ dropRef = _useDrop2[1];
118
+
119
+ useEffect(function () {
120
+ dragPreview(getEmptyImage(), {
121
+ captureDraggingState: true
122
+ });
123
+ }, [dragPreview]);
124
+ return /*#__PURE__*/React.createElement("div", {
125
+ ref: function ref(node) {
126
+ return dragRef(dropRef(node));
127
+ },
128
+ className: cx(className, isDragging ? 'virtualized u-o-50' : 'virtualized'),
129
+ style: {
130
+ opacity: isDisabled ? 0.5 : 1
131
+ }
132
+ }, renderItem(item, {
133
+ isDragging: isDragging,
134
+ isOver: isOver,
135
+ isDisabled: isDisabled
136
+ }));
137
+ };
138
+
139
+ export default GridItem;
@@ -0,0 +1,13 @@
1
+ export default VirtualizedGridListDnd;
2
+ declare function VirtualizedGridListDnd({ dragProps, context, itemRenderer, children, componentProps, components, ...props }: {
3
+ [x: string]: any;
4
+ dragProps: any;
5
+ context: any;
6
+ itemRenderer: any;
7
+ children: any;
8
+ componentProps?: {
9
+ List: {};
10
+ Item: {};
11
+ } | undefined;
12
+ components: any;
13
+ }): JSX.Element;
@@ -0,0 +1,81 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
5
+ var _excluded = ["dragProps", "context", "itemRenderer", "children", "componentProps", "components"],
6
+ _excluded2 = ["context", "children"];
7
+
8
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
9
+
10
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
11
+
12
+ import React, { forwardRef, useState, useMemo } from 'react';
13
+ import GridItem from "cozy-ui/transpiled/react/GridList/Virtualized/Dnd/GridItem";
14
+ import VirtualizedGridList from "cozy-ui/transpiled/react/GridList/Virtualized";
15
+ import CustomDragLayer from "cozy-ui/transpiled/react/utils/Dnd/CustomDrag/CustomDragLayer";
16
+ import DnDConfigWrapper from "cozy-ui/transpiled/react/utils/Dnd/DnDConfigWrapper";
17
+
18
+ var VirtualizedGridListDnd = function VirtualizedGridListDnd(_ref) {
19
+ var dragProps = _ref.dragProps,
20
+ context = _ref.context,
21
+ itemRenderer = _ref.itemRenderer,
22
+ children = _ref.children,
23
+ _ref$componentProps = _ref.componentProps,
24
+ componentProps = _ref$componentProps === void 0 ? {
25
+ List: {},
26
+ Item: {}
27
+ } : _ref$componentProps,
28
+ components = _ref.components,
29
+ props = _objectWithoutProperties(_ref, _excluded);
30
+
31
+ var _useState = useState([]),
32
+ _useState2 = _slicedToArray(_useState, 2),
33
+ itemsInDropProcess = _useState2[0],
34
+ setItemsInDropProcess = _useState2[1];
35
+
36
+ var _context = useMemo(function () {
37
+ return _objectSpread(_objectSpread({}, context), {}, {
38
+ dragProps: dragProps,
39
+ itemRenderer: itemRenderer,
40
+ itemsInDropProcess: itemsInDropProcess,
41
+ setItemsInDropProcess: setItemsInDropProcess,
42
+ items: props.items
43
+ });
44
+ }, [context, dragProps, itemRenderer, itemsInDropProcess, props.items]);
45
+
46
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CustomDragLayer, {
47
+ dragId: dragProps.dragId
48
+ }), /*#__PURE__*/React.createElement(VirtualizedGridList, _extends({
49
+ components: _objectSpread({
50
+ Scroller: /*#__PURE__*/forwardRef(function (_ref2, ref) {
51
+ var scrollerProps = _extends({}, _ref2);
52
+
53
+ return /*#__PURE__*/React.createElement(DnDConfigWrapper, {
54
+ ref: ref
55
+ }, /*#__PURE__*/React.createElement("div", _extends({}, scrollerProps, {
56
+ ref: ref
57
+ })));
58
+ }),
59
+ Item: function Item(_ref3) {
60
+ var _context$items;
61
+
62
+ var context = _ref3.context,
63
+ children = _ref3.children,
64
+ props = _objectWithoutProperties(_ref3, _excluded2);
65
+
66
+ var item = context === null || context === void 0 ? void 0 : (_context$items = context.items) === null || _context$items === void 0 ? void 0 : _context$items[props['data-index']];
67
+ return /*#__PURE__*/React.createElement(GridItem, _extends({
68
+ item: item,
69
+ context: context,
70
+ renderItem: function renderItem() {
71
+ return /*#__PURE__*/React.createElement(React.Fragment, null, children);
72
+ }
73
+ }, componentProps.Item));
74
+ }
75
+ }, components),
76
+ context: _context,
77
+ itemRenderer: itemRenderer
78
+ }, props), children));
79
+ };
80
+
81
+ export default VirtualizedGridListDnd;
@@ -0,0 +1,3 @@
1
+ export default VirtualizedGridList;
2
+ declare const VirtualizedGridList: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
3
+ import React from "react";
@@ -0,0 +1,28 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ var _excluded = ["items", "itemRenderer", "components", "context"];
4
+ import React, { forwardRef } from 'react';
5
+ import { VirtuosoGrid } from 'react-virtuoso';
6
+ var VirtualizedGridList = /*#__PURE__*/forwardRef(function (_ref, ref) {
7
+ var _ref$items = _ref.items,
8
+ items = _ref$items === void 0 ? [] : _ref$items,
9
+ itemRenderer = _ref.itemRenderer,
10
+ components = _ref.components,
11
+ context = _ref.context,
12
+ props = _objectWithoutProperties(_ref, _excluded);
13
+
14
+ return /*#__PURE__*/React.createElement(VirtuosoGrid, _extends({
15
+ ref: ref,
16
+ components: components,
17
+ context: context,
18
+ style: {
19
+ height: '100%'
20
+ },
21
+ totalCount: items.length,
22
+ itemContent: function itemContent(index) {
23
+ return itemRenderer(items[index]);
24
+ }
25
+ }, props));
26
+ });
27
+ VirtualizedGridList.displayName = 'VirtualizedGridList';
28
+ export default VirtualizedGridList;
@@ -9,8 +9,8 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
9
9
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
10
10
 
11
11
  import React, { useState, useMemo } from 'react';
12
- import CustomDragLayer from "cozy-ui/transpiled/react/Table/Virtualized/Dnd/CustomDrag/CustomDragLayer";
13
12
  import virtuosoComponentsDnd from "cozy-ui/transpiled/react/Table/Virtualized/Dnd/virtuosoComponents";
13
+ import CustomDragLayer from "cozy-ui/transpiled/react/utils/Dnd/CustomDrag/CustomDragLayer";
14
14
  import VirtualizedTable from "cozy-ui/transpiled/react/Table/Virtualized/index";
15
15
  import virtuosoComponents from "cozy-ui/transpiled/react/Table/Virtualized/virtuosoComponents";
16
16
 
@@ -8,9 +8,9 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
8
8
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
9
9
 
10
10
  import React, { forwardRef } from 'react';
11
- import DnDConfigWrapper from "cozy-ui/transpiled/react/Table/Virtualized/Dnd/DnDConfigWrapper";
12
11
  import TableRowDnD from "cozy-ui/transpiled/react/Table/Virtualized/Dnd/TableRow";
13
12
  import TableContainer from "cozy-ui/transpiled/react/TableContainer";
13
+ import DnDConfigWrapper from "cozy-ui/transpiled/react/utils/Dnd/DnDConfigWrapper";
14
14
  import virtuosoComponents from "cozy-ui/transpiled/react/Table/Virtualized/virtuosoComponents";
15
15
  /**
16
16
  Be aware that context is spread to every components but should not be spread to Table components
@@ -0,0 +1,4 @@
1
+ export function CustomDragLayer({ dragId }: {
2
+ dragId: any;
3
+ }): JSX.Element | null;
4
+ export default CustomDragLayer;
@@ -0,0 +1,47 @@
1
+ import React from 'react';
2
+ import { useDragLayer } from 'react-dnd';
3
+ import DragPreviewWrapper from "cozy-ui/transpiled/react/utils/Dnd/CustomDrag/DragPreviewWrapper";
4
+ var layerStyles = {
5
+ position: 'fixed',
6
+ pointerEvents: 'none',
7
+ zIndex: 100,
8
+ left: 0,
9
+ top: 0,
10
+ width: '100%',
11
+ height: '100%'
12
+ }; // Example find in the official documentation
13
+ // https://react-dnd.github.io/react-dnd/examples/drag-around/custom-drag-layer
14
+
15
+ export var CustomDragLayer = function CustomDragLayer(_ref) {
16
+ var dragId = _ref.dragId;
17
+
18
+ var _useDragLayer = useDragLayer(function (monitor) {
19
+ return {
20
+ item: monitor.getItem(),
21
+ itemType: monitor.getItemType(),
22
+ initialOffset: monitor.getInitialSourceClientOffset(),
23
+ currentOffset: monitor.getSourceClientOffset(),
24
+ isDragging: monitor.isDragging()
25
+ };
26
+ }),
27
+ itemType = _useDragLayer.itemType,
28
+ isDragging = _useDragLayer.isDragging,
29
+ item = _useDragLayer.item,
30
+ initialOffset = _useDragLayer.initialOffset,
31
+ currentOffset = _useDragLayer.currentOffset;
32
+
33
+ if (!isDragging) {
34
+ return null;
35
+ }
36
+
37
+ return /*#__PURE__*/React.createElement("div", {
38
+ style: layerStyles
39
+ }, /*#__PURE__*/React.createElement(DragPreviewWrapper, {
40
+ item: item,
41
+ itemType: itemType,
42
+ dragId: dragId,
43
+ initialOffset: initialOffset,
44
+ currentOffset: currentOffset
45
+ }));
46
+ };
47
+ export default CustomDragLayer;
@@ -0,0 +1,6 @@
1
+ declare var _default: React.MemoExoticComponent<({ fileName, selectedCount }: {
2
+ fileName: any;
3
+ selectedCount: any;
4
+ }) => JSX.Element>;
5
+ export default _default;
6
+ import React from "react";
@@ -0,0 +1,34 @@
1
+ import React from 'react';
2
+ import Badge from "cozy-ui/transpiled/react/Badge";
3
+ import Paper from "cozy-ui/transpiled/react/Paper";
4
+ import Typography from "cozy-ui/transpiled/react/Typography";
5
+ import { makeStyles } from "cozy-ui/transpiled/react/styles";
6
+ var useStyles = makeStyles({
7
+ root: {
8
+ width: 'fit-content'
9
+ }
10
+ });
11
+
12
+ var DragPreview = function DragPreview(_ref) {
13
+ var fileName = _ref.fileName,
14
+ selectedCount = _ref.selectedCount;
15
+ var classes = useStyles();
16
+ return /*#__PURE__*/React.createElement(React.Fragment, null, selectedCount > 1 ? /*#__PURE__*/React.createElement(Badge, {
17
+ badgeContent: selectedCount,
18
+ size: "large",
19
+ color: "primary",
20
+ anchorOrigin: {
21
+ vertical: 'top',
22
+ horizontal: 'right'
23
+ },
24
+ overlap: "rectangular"
25
+ }, /*#__PURE__*/React.createElement(Paper, {
26
+ classes: classes,
27
+ className: "u-p-half u-maw-5"
28
+ }, /*#__PURE__*/React.createElement(Typography, null, fileName))) : /*#__PURE__*/React.createElement(Paper, {
29
+ classes: classes,
30
+ className: "u-p-half u-maw-5"
31
+ }, /*#__PURE__*/React.createElement(Typography, null, fileName)));
32
+ };
33
+
34
+ export default /*#__PURE__*/React.memo(DragPreview);
@@ -0,0 +1,8 @@
1
+ export default DragPreviewWrapper;
2
+ declare function DragPreviewWrapper({ item, itemType, dragId, initialOffset, currentOffset }: {
3
+ item: any;
4
+ itemType: any;
5
+ dragId: any;
6
+ initialOffset: any;
7
+ currentOffset: any;
8
+ }): JSX.Element | null;
@@ -0,0 +1,63 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import React, { useEffect, useState } from 'react';
3
+ import DragPreview from "cozy-ui/transpiled/react/utils/Dnd/CustomDrag/DragPreview";
4
+
5
+ var makeStyles = function makeStyles(_ref) {
6
+ var x = _ref.x,
7
+ y = _ref.y;
8
+
9
+ if (!x || !y) {
10
+ return {
11
+ display: 'none'
12
+ };
13
+ }
14
+
15
+ var transform = "translate(".concat(x, "px, ").concat(y, "px)");
16
+ return {
17
+ transform: transform,
18
+ WebkitTransform: transform
19
+ };
20
+ };
21
+
22
+ var DragPreviewWrapper = function DragPreviewWrapper(_ref2) {
23
+ var item = _ref2.item,
24
+ itemType = _ref2.itemType,
25
+ dragId = _ref2.dragId,
26
+ initialOffset = _ref2.initialOffset,
27
+ currentOffset = _ref2.currentOffset;
28
+
29
+ var _useState = useState({
30
+ x: null,
31
+ y: null
32
+ }),
33
+ _useState2 = _slicedToArray(_useState, 2),
34
+ mousePosition = _useState2[0],
35
+ setMousePosition = _useState2[1];
36
+
37
+ useEffect(function () {
38
+ var handleMouseMove = function handleMouseMove(e) {
39
+ setMousePosition({
40
+ x: e.clientX,
41
+ y: e.clientY
42
+ });
43
+ };
44
+
45
+ window.addEventListener('dragover', handleMouseMove);
46
+ return function () {
47
+ window.removeEventListener('dragover', handleMouseMove);
48
+ };
49
+ }, []);
50
+
51
+ if (!initialOffset || !currentOffset || itemType !== dragId) {
52
+ return null;
53
+ }
54
+
55
+ return /*#__PURE__*/React.createElement("div", {
56
+ style: makeStyles(mousePosition)
57
+ }, /*#__PURE__*/React.createElement(DragPreview, {
58
+ fileName: item.draggedItems[0].name,
59
+ selectedCount: item.draggedItems.length
60
+ }));
61
+ };
62
+
63
+ export default DragPreviewWrapper;
@@ -0,0 +1,2 @@
1
+ export default DnDConfigWrapper;
2
+ declare const DnDConfigWrapper: import("react").ForwardRefExoticComponent<import("react").RefAttributes<any>>;
@@ -0,0 +1,55 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import { forwardRef, useEffect, useState } from 'react';
3
+ import { useDragDropManager } from 'react-dnd';
4
+ var DnDConfigWrapper = /*#__PURE__*/forwardRef(function (_ref, ref) {
5
+ var children = _ref.children;
6
+ var dragDropManager = useDragDropManager();
7
+ var monitor = dragDropManager.getMonitor();
8
+
9
+ var _useState = useState(false),
10
+ _useState2 = _slicedToArray(_useState, 2),
11
+ isDragging = _useState2[0],
12
+ setIsDragging = _useState2[1];
13
+
14
+ useEffect(function () {
15
+ var unsubscribe = monitor.subscribeToStateChange(function () {
16
+ setIsDragging(monitor.isDragging());
17
+ });
18
+ return function () {
19
+ return unsubscribe();
20
+ };
21
+ }, [monitor]);
22
+ useEffect(function () {
23
+ if (!isDragging) return;
24
+ var scrollThreshold = 100;
25
+ var scrollMaxSpeed = 75;
26
+ var intervalId = setInterval(function () {
27
+ var offset = monitor.getClientOffset();
28
+ var container = ref.current;
29
+ if (!offset || !container) return;
30
+
31
+ var _container$getBoundin = container.getBoundingClientRect(),
32
+ top = _container$getBoundin.top,
33
+ bottom = _container$getBoundin.bottom;
34
+
35
+ var distanceToTop = offset.y - top;
36
+ var distanceToBottom = bottom - offset.y;
37
+
38
+ if (distanceToTop < scrollThreshold) {
39
+ var speed = scrollMaxSpeed * (1 - distanceToTop / scrollThreshold);
40
+ container.scrollBy(0, -speed);
41
+ } else if (distanceToBottom < scrollThreshold) {
42
+ var _speed = scrollMaxSpeed * (1 - distanceToBottom / scrollThreshold);
43
+
44
+ container.scrollBy(0, _speed);
45
+ }
46
+ }, 16); // ~60fps
47
+
48
+ return function () {
49
+ return clearInterval(intervalId);
50
+ };
51
+ }, [isDragging, monitor, ref]);
52
+ return children;
53
+ });
54
+ DnDConfigWrapper.displayName = 'DnDConfigWrapper';
55
+ export default DnDConfigWrapper;