cozy-ui 127.3.0 → 127.5.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 (34) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cozy-ui.min.css +1 -1
  3. package/package.json +1 -1
  4. package/react/GridList/Virtualized/Dnd/GridItem.jsx +86 -0
  5. package/react/GridList/Virtualized/Dnd/index.jsx +67 -0
  6. package/react/GridList/Virtualized/index.jsx +2 -1
  7. package/react/Layout/Layout.jsx +9 -19
  8. package/react/Layout/Layout.md +73 -23
  9. package/react/Table/Virtualized/Dnd/index.jsx +1 -1
  10. package/react/Table/Virtualized/Dnd/virtuosoComponents.jsx +1 -1
  11. package/react/utils/Dnd/CustomDrag/CustomDragLayer.jsx +45 -0
  12. package/react/utils/Dnd/CustomDrag/DragPreview.jsx +43 -0
  13. package/react/utils/Dnd/CustomDrag/DragPreviewWrapper.jsx +52 -0
  14. package/react/utils/Dnd/DnDConfigWrapper.jsx +48 -0
  15. package/scripts/screenshots/screenshotComponent.js +4 -8
  16. package/stylus/elements/defaults.styl +1 -11
  17. package/stylus/objects/layouts.styl +13 -47
  18. package/transpiled/react/GridList/Virtualized/Dnd/GridItem.d.ts +7 -0
  19. package/transpiled/react/GridList/Virtualized/Dnd/GridItem.js +139 -0
  20. package/transpiled/react/GridList/Virtualized/Dnd/index.d.ts +13 -0
  21. package/transpiled/react/GridList/Virtualized/Dnd/index.js +81 -0
  22. package/transpiled/react/GridList/Virtualized/index.js +3 -1
  23. package/transpiled/react/Layout/Layout.js +9 -9
  24. package/transpiled/react/Table/Virtualized/Dnd/index.js +1 -1
  25. package/transpiled/react/Table/Virtualized/Dnd/virtuosoComponents.js +1 -1
  26. package/transpiled/react/stylesheet.css +1 -1
  27. package/transpiled/react/utils/Dnd/CustomDrag/CustomDragLayer.d.ts +4 -0
  28. package/transpiled/react/utils/Dnd/CustomDrag/CustomDragLayer.js +47 -0
  29. package/transpiled/react/utils/Dnd/CustomDrag/DragPreview.d.ts +6 -0
  30. package/transpiled/react/utils/Dnd/CustomDrag/DragPreview.js +34 -0
  31. package/transpiled/react/utils/Dnd/CustomDrag/DragPreviewWrapper.d.ts +8 -0
  32. package/transpiled/react/utils/Dnd/CustomDrag/DragPreviewWrapper.js +63 -0
  33. package/transpiled/react/utils/Dnd/DnDConfigWrapper.d.ts +2 -0
  34. package/transpiled/react/utils/Dnd/DnDConfigWrapper.js +55 -0
@@ -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;