@reltio/components 1.4.1992 → 1.4.1993

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.
@@ -1,10 +1,10 @@
1
1
  import { makeStyles } from '@mui/styles';
2
- export var useStyles = makeStyles(function () { return ({
2
+ export var useStyles = makeStyles(function (theme) { return ({
3
3
  switcherButtonWrapper: {
4
- paddingTop: '9px',
5
- paddingLeft: '6px',
6
- width: '16px',
7
- height: '16px',
4
+ paddingTop: '11px',
5
+ paddingLeft: '4px',
6
+ width: '12px',
7
+ height: '12px',
8
8
  cursor: 'pointer'
9
9
  },
10
10
  switcherButton: {
@@ -24,6 +24,39 @@ export var useStyles = makeStyles(function () { return ({
24
24
  treeWrapper: {
25
25
  border: 'none'
26
26
  },
27
+ dropIndicator: {
28
+ '&:before': {
29
+ content: '""',
30
+ backgroundColor: '#e0eef9',
31
+ border: '1px dashed #2184D4',
32
+ position: 'absolute',
33
+ top: 0,
34
+ right: '23px',
35
+ bottom: 0,
36
+ left: '-22px',
37
+ zIndex: 1
38
+ },
39
+ '&>div': {
40
+ opacity: 0
41
+ }
42
+ },
43
+ dropNotAllowed: {
44
+ '&:before': {
45
+ backgroundColor: '#ffedee',
46
+ borderColor: '#FF6673'
47
+ }
48
+ },
49
+ draggedChildrenNode: {
50
+ opacity: 0.5
51
+ },
52
+ dragHandle: {
53
+ cursor: 'move',
54
+ color: theme.palette.text.secondary,
55
+ width: '16px'
56
+ },
57
+ dragHandleDragging: {
58
+ visibility: 'hidden'
59
+ },
27
60
  /* rc-tree/assets/index.css */
28
61
  '@global': {
29
62
  '.rc-tree': {
@@ -49,12 +82,6 @@ export var useStyles = makeStyles(function () { return ({
49
82
  boxShadow: 'inset 0 0 0 2px red',
50
83
  content: "''"
51
84
  },
52
- '.rc-tree .rc-tree-treenode.drop-container ~ .rc-tree-treenode': {
53
- borderLeft: '2px solid chocolate'
54
- },
55
- '.rc-tree .rc-tree-treenode.drop-target': {
56
- backgroundColor: 'yellowgreen'
57
- },
58
85
  '.rc-tree .rc-tree-treenode.drop-target ~ .rc-tree-treenode': {
59
86
  borderLeft: 'none'
60
87
  },
@@ -152,11 +179,6 @@ export var useStyles = makeStyles(function () { return ({
152
179
  '.rc-tree-treenode-active': {
153
180
  background: 'rgba(0, 0, 0, 0.1)'
154
181
  },
155
- '.rc-tree-node-selected': {
156
- backgroundColor: '#ffe6b0',
157
- boxShadow: '0 0 0 1px #ffb951',
158
- opacity: 0.8
159
- },
160
182
  '.rc-tree-icon__open': {
161
183
  marginRight: '2px',
162
184
  verticalAlign: 'top',
@@ -185,11 +207,6 @@ export var useStyles = makeStyles(function () { return ({
185
207
  display: 'inline-block',
186
208
  width: '16px'
187
209
  },
188
- '.rc-tree-draggable-icon': {
189
- display: 'inline-flex',
190
- justifyContent: 'center',
191
- width: '16px'
192
- },
193
210
  //Custom styles
194
211
  '.rc-tree .rc-tree-treenode .rc-tree-node-content-wrapper': {
195
212
  position: 'relative',
@@ -200,8 +217,8 @@ export var useStyles = makeStyles(function () { return ({
200
217
  verticalAlign: 'top',
201
218
  cursor: 'pointer',
202
219
  height: 'auto',
203
- width: '100%',
204
- paddingRight: '11px'
220
+ paddingRight: '11px',
221
+ flexGrow: 1
205
222
  },
206
223
  '.rc-tree .rc-tree-treenode': {
207
224
  margin: 0,
@@ -222,6 +239,18 @@ export var useStyles = makeStyles(function () { return ({
222
239
  '.rc-tree-title': {
223
240
  display: 'inline-block',
224
241
  width: '100%'
242
+ },
243
+ '.rc-tree-draggable-icon': {
244
+ display: 'inline-flex',
245
+ justifyContent: 'center',
246
+ width: '16px',
247
+ visibility: 'hidden'
248
+ },
249
+ '.rc-tree-treenode-draggable:hover .rc-tree-draggable-icon': {
250
+ visibility: 'visible'
251
+ },
252
+ '.rc-tree-switcher-noop': {
253
+ width: '16px'
225
254
  }
226
255
  }
227
256
  }); });
@@ -7,7 +7,18 @@ export type RCTreeNode = {
7
7
  };
8
8
  export type InternalRCNode = {
9
9
  value: RCTreeNode;
10
+ pos?: string;
10
11
  } & FieldDataNode<{
11
12
  key: string;
12
13
  title?: string;
13
14
  }>;
15
+ export type DropPositionInfo = {
16
+ pos: string;
17
+ dropPosition: number;
18
+ addToEnd?: boolean;
19
+ };
20
+ export declare enum AddNodePosition {
21
+ Bottom = 1,
22
+ Top = -1,
23
+ AsChild = 0
24
+ }
@@ -1 +1,6 @@
1
- export {};
1
+ export var AddNodePosition;
2
+ (function (AddNodePosition) {
3
+ AddNodePosition[AddNodePosition["Bottom"] = 1] = "Bottom";
4
+ AddNodePosition[AddNodePosition["Top"] = -1] = "Top";
5
+ AddNodePosition[AddNodePosition["AsChild"] = 0] = "AsChild";
6
+ })(AddNodePosition || (AddNodePosition = {}));
@@ -0,0 +1,6 @@
1
+ import { DragEvent } from 'react';
2
+ import { InternalRCNode } from './types';
3
+ export declare const useDelayedDragEventCall: (callback: (params: {
4
+ event: DragEvent<HTMLDivElement>;
5
+ node: InternalRCNode;
6
+ }) => void, delay?: number) => ({ event, node }: any) => void;
@@ -0,0 +1,22 @@
1
+ import { useCallback, useRef } from 'react';
2
+ import { equals } from 'ramda';
3
+ var DELAY_TIMEOUT = 50;
4
+ export var useDelayedDragEventCall = function (callback, delay) {
5
+ if (delay === void 0) { delay = DELAY_TIMEOUT; }
6
+ var prevMousePosition = useRef(null);
7
+ var lastTimeChanged = useRef(0);
8
+ return useCallback(function (_a) {
9
+ var event = _a.event, node = _a.node;
10
+ var now = Date.now();
11
+ var newMousePosition = { x: event.clientX, y: event.clientY };
12
+ if (!equals(prevMousePosition === null || prevMousePosition === void 0 ? void 0 : prevMousePosition.current, newMousePosition)) {
13
+ lastTimeChanged.current = now;
14
+ }
15
+ var waitedTime = now - (lastTimeChanged === null || lastTimeChanged === void 0 ? void 0 : lastTimeChanged.current);
16
+ if (waitedTime > delay) {
17
+ lastTimeChanged.current = now;
18
+ callback({ event: event, node: node });
19
+ }
20
+ prevMousePosition.current = newMousePosition;
21
+ }, [callback, delay]);
22
+ };
@@ -0,0 +1,47 @@
1
+ import { DragEvent } from 'react';
2
+ import { InternalRCNode, RCTreeNode } from './types';
3
+ type Props = {
4
+ treeData: RCTreeNode[];
5
+ containerRef: React.RefObject<HTMLDivElement>;
6
+ expandNode: (pos: string, expanded: boolean) => void;
7
+ onLoadChildren?: (treeNode: RCTreeNode) => Promise<void>;
8
+ onChange?: (node: RCTreeNode[]) => void;
9
+ onDrop?: (treeData: RCTreeNode[], dragNode: RCTreeNode, parentNode: RCTreeNode) => void;
10
+ canDrop?: (params: {
11
+ nextParent: RCTreeNode;
12
+ node: RCTreeNode;
13
+ }) => boolean;
14
+ canDrag?: (params: {
15
+ node: RCTreeNode;
16
+ }) => boolean;
17
+ };
18
+ export declare const useDnd: ({ treeData, containerRef, expandNode, onLoadChildren, onChange, onDrop: onDropProp, canDrop, canDrag }: Props) => {
19
+ treeProps: {
20
+ onDragStart: ({ node }: {
21
+ node: InternalRCNode;
22
+ }) => void;
23
+ onDragOver: ({ event, node }: {
24
+ event: DragEvent<HTMLDivElement>;
25
+ node: InternalRCNode;
26
+ }) => void;
27
+ onDragLeave: ({ event, node }: {
28
+ event: any;
29
+ node: any;
30
+ }) => void;
31
+ onDrop: () => void;
32
+ dropIndicatorRender: () => any;
33
+ allowDrop: ({ dragNode, dropNode }: {
34
+ dragNode: InternalRCNode;
35
+ dropNode: InternalRCNode;
36
+ }) => boolean;
37
+ };
38
+ nodeDraggable: (node: InternalRCNode) => boolean;
39
+ dropNode: InternalRCNode;
40
+ dragNode: InternalRCNode;
41
+ dropPositionInfo: {
42
+ pos: string;
43
+ dropPosition: number;
44
+ addToEnd?: boolean;
45
+ };
46
+ };
47
+ export {};
@@ -0,0 +1,108 @@
1
+ import { useCallback, useMemo, useState } from 'react';
2
+ import { equals } from 'ramda';
3
+ import { AddNodePosition } from './types';
4
+ import { useScrollOnDrag } from './useScrollOnDrag';
5
+ import { useDelayedDragEventCall } from './useDelayedDragEventCall';
6
+ import { getDropNodePosition, getExpandedKeys, getNodeAtPosition, getParentPos, isDropIndicatorNode, moveNode, slideNodePos } from './helper';
7
+ export var useDnd = function (_a) {
8
+ var treeData = _a.treeData, containerRef = _a.containerRef, expandNode = _a.expandNode, onLoadChildren = _a.onLoadChildren, onChange = _a.onChange, onDropProp = _a.onDrop, canDrop = _a.canDrop, canDrag = _a.canDrag;
9
+ var _b = useState(null), dragNode = _b[0], setDragNode = _b[1];
10
+ var _c = useState(null), dropNode = _c[0], setDropNode = _c[1];
11
+ var _d = useState(null), dropPositionInfo = _d[0], setDropPositionInfo = _d[1];
12
+ var _e = useScrollOnDrag(containerRef), onStartDragging = _e.onStartDragging, onEndDragging = _e.onEndDragging, getIsScrolling = _e.getIsScrolling;
13
+ var handleDropOutsideTree = function () {
14
+ setDragNode(null);
15
+ setDropNode(null);
16
+ onEndDragging();
17
+ window.removeEventListener('mousemove', handleDropOutsideTree);
18
+ };
19
+ var onDragStart = function (_a) {
20
+ var node = _a.node;
21
+ setDragNode(node);
22
+ onStartDragging();
23
+ window.addEventListener('mousemove', handleDropOutsideTree);
24
+ };
25
+ var expandedKeys = useMemo(function () {
26
+ return getExpandedKeys(treeData);
27
+ }, [treeData]);
28
+ var expandDropNodeAtPosition = useCallback(function (pos, expanded) {
29
+ var node = getNodeAtPosition(treeData, pos);
30
+ if (node && !expandedKeys.includes(node.nodeId)) {
31
+ expandNode(pos, expanded);
32
+ if (node.pending && onLoadChildren) {
33
+ onLoadChildren(node);
34
+ }
35
+ }
36
+ }, [expandNode, expandedKeys, onLoadChildren, treeData]);
37
+ var expandDropNode = useCallback(function (newDropPositionInfo) {
38
+ if (onChange && newDropPositionInfo.dropPosition === AddNodePosition.AsChild) {
39
+ var currentParentNodePos = slideNodePos(newDropPositionInfo.pos, dragNode.pos);
40
+ if (currentParentNodePos.split('-').length > 1) {
41
+ expandDropNodeAtPosition(currentParentNodePos, true);
42
+ }
43
+ }
44
+ }, [dragNode, expandDropNodeAtPosition, onChange]);
45
+ var handleSetDropNode = useCallback(function (_a) {
46
+ var event = _a.event, node = _a.node;
47
+ var newDropPositionInfo = getDropNodePosition(event, node, dropPositionInfo) || dropPositionInfo;
48
+ if (!equals(newDropPositionInfo, dropPositionInfo) && (!isDropIndicatorNode(node) || !dropNode)) {
49
+ setDropPositionInfo(newDropPositionInfo);
50
+ expandDropNode(newDropPositionInfo);
51
+ }
52
+ if (node.key !== (dropNode === null || dropNode === void 0 ? void 0 : dropNode.key)) {
53
+ setDropNode(node);
54
+ }
55
+ }, [dropNode, dropPositionInfo, expandDropNode]);
56
+ var delayedHandleDragOver = useDelayedDragEventCall(handleSetDropNode);
57
+ var onDragOver = function (_a) {
58
+ var event = _a.event, node = _a.node;
59
+ var isScrolling = getIsScrolling();
60
+ if (!isScrolling)
61
+ delayedHandleDragOver({ event: event, node: node });
62
+ };
63
+ var dropIndicatorRender = function () {
64
+ return null;
65
+ };
66
+ var onDragLeave = function (_a) {
67
+ var _b, _c;
68
+ var event = _a.event, node = _a.node;
69
+ var draggedChildrenNodes = ((_b = dragNode === null || dragNode === void 0 ? void 0 : dragNode.value) === null || _b === void 0 ? void 0 : _b.expanded) ? getExpandedKeys((_c = dragNode.value) === null || _c === void 0 ? void 0 : _c.children) : [];
70
+ if (draggedChildrenNodes.includes(node.key)) {
71
+ handleSetDropNode({ event: event, node: node });
72
+ }
73
+ };
74
+ var onDrop = function () {
75
+ if (dragNode && isDropIndicatorNode(dropNode)) {
76
+ var parentNodePosition = dropPositionInfo.dropPosition === AddNodePosition.AsChild
77
+ ? dropPositionInfo.pos
78
+ : getParentPos(dropPositionInfo.pos);
79
+ var parentNode = getNodeAtPosition(treeData, parentNodePosition);
80
+ var newTreeData = moveNode(treeData, dragNode.value, dragNode.pos, dropPositionInfo);
81
+ onDropProp(newTreeData, dragNode.value, parentNode);
82
+ }
83
+ setDragNode(null);
84
+ setDropNode(null);
85
+ onEndDragging();
86
+ };
87
+ var allowDrop = useCallback(function (_a) {
88
+ var dragNode = _a.dragNode, dropNode = _a.dropNode;
89
+ return canDrop({ nextParent: dropNode.value, node: dragNode.value });
90
+ }, [canDrop]);
91
+ var nodeDraggable = useCallback(function (node) {
92
+ return canDrag({ node: node.value });
93
+ }, [canDrag]);
94
+ return {
95
+ treeProps: {
96
+ onDragStart: onDragStart,
97
+ onDragOver: onDragOver,
98
+ onDragLeave: onDragLeave,
99
+ onDrop: onDrop,
100
+ dropIndicatorRender: dropIndicatorRender,
101
+ allowDrop: allowDrop
102
+ },
103
+ nodeDraggable: nodeDraggable,
104
+ dropNode: dropNode,
105
+ dragNode: dragNode,
106
+ dropPositionInfo: dropPositionInfo
107
+ };
108
+ };
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ export declare const useScrollOnDrag: (scrollContainer: React.MutableRefObject<HTMLDivElement>) => {
3
+ onStartDragging: () => void;
4
+ onEndDragging: () => void;
5
+ getIsScrolling: () => boolean;
6
+ };
@@ -0,0 +1,83 @@
1
+ import { useCallback, useEffect, useRef } from 'react';
2
+ import { throttle } from '@reltio/mdm-sdk';
3
+ var SCROLL_MARGIN = 50;
4
+ var SPEED_MULTIPLIER = 25;
5
+ var UPDATE_DATA_INTERVAL = 100;
6
+ export var useScrollOnDrag = function (scrollContainer) {
7
+ var scrolling = useRef(false);
8
+ var running = useRef(false);
9
+ var scrollData = useRef(null);
10
+ var getIsScrolling = function () {
11
+ return scrolling === null || scrolling === void 0 ? void 0 : scrolling.current;
12
+ };
13
+ var onStartDragging = function () {
14
+ var container = scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.current;
15
+ if (container && typeof container.addEventListener === 'function') {
16
+ container.addEventListener('dragover', updateScrollData);
17
+ window.addEventListener('dragover', updateScrollData);
18
+ running.current = true;
19
+ }
20
+ };
21
+ var updateScrollData = useCallback(throttle(function (event) {
22
+ var container = scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.current;
23
+ if (!container || !running.current)
24
+ return;
25
+ var holder = container.getElementsByClassName('rc-tree-list-holder')[0];
26
+ var calcSpeed = function () {
27
+ var clientY = event.clientY, clientX = event.clientX;
28
+ var _a = container.getBoundingClientRect(), top = _a.top, bottom = _a.bottom, left = _a.left, right = _a.right;
29
+ var maxScroll = holder.scrollHeight - holder.clientHeight;
30
+ var insideContainer = clientY > top && clientY < bottom && clientX >= left && clientX <= right;
31
+ if (insideContainer) {
32
+ if (clientY - top < SCROLL_MARGIN && holder.scrollTop > 0) {
33
+ return (clientY - top - SCROLL_MARGIN) / SCROLL_MARGIN;
34
+ }
35
+ else if (bottom - clientY < SCROLL_MARGIN && holder.scrollTop < maxScroll) {
36
+ return -(bottom - clientY - SCROLL_MARGIN) / SCROLL_MARGIN;
37
+ }
38
+ }
39
+ return 0;
40
+ };
41
+ if (holder) {
42
+ scrollData.current = calcSpeed();
43
+ if (scrollData.current) {
44
+ runScrolling(holder);
45
+ }
46
+ }
47
+ }, UPDATE_DATA_INTERVAL), []);
48
+ var removeListeners = useCallback(function () {
49
+ var container = scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.current;
50
+ if (container && typeof container.removeEventListener === 'function') {
51
+ container.removeEventListener('dragover', updateScrollData);
52
+ }
53
+ window.removeEventListener('dragover', updateScrollData);
54
+ }, [scrollContainer, updateScrollData]);
55
+ var onEndDragging = useCallback(function () {
56
+ scrolling.current = false;
57
+ scrollData.current = null;
58
+ running.current = false;
59
+ removeListeners();
60
+ }, [removeListeners]);
61
+ var runScrolling = function (holder) {
62
+ if (scrolling === null || scrolling === void 0 ? void 0 : scrolling.current) {
63
+ return;
64
+ }
65
+ scrolling.current = true;
66
+ var scroll = function () {
67
+ if (scrolling.current && scrollData.current) {
68
+ holder.scrollTop += scrollData.current * SPEED_MULTIPLIER;
69
+ requestAnimationFrame(scroll);
70
+ }
71
+ else {
72
+ scrolling.current = false;
73
+ }
74
+ };
75
+ scroll();
76
+ };
77
+ useEffect(function () {
78
+ return function () {
79
+ removeListeners();
80
+ };
81
+ }, [removeListeners]);
82
+ return { onStartDragging: onStartDragging, onEndDragging: onEndDragging, getIsScrolling: getIsScrolling };
83
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reltio/components",
3
- "version": "1.4.1992",
3
+ "version": "1.4.1993",
4
4
  "license": "SEE LICENSE IN LICENSE FILE",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -8,7 +8,7 @@
8
8
  "@fluentui/react-context-selector": "^9.1.26",
9
9
  "@react-google-maps/api": "2.7.0",
10
10
  "@react-sigma/core": "3.4.0",
11
- "@reltio/mdm-sdk": "^1.4.1888",
11
+ "@reltio/mdm-sdk": "^1.4.1889",
12
12
  "d3-cloud": "^1.2.5",
13
13
  "d3-geo": "^2.0.1",
14
14
  "d3-hierarchy": "^2.0.0",