TagSpaces is an offline, open source, document manager with tagging support
refactoring rect-dnd with hooks useDrag useDrop (#2055)
Stanimir0fa484bc8ef7
diff --git a/src/renderer/components/DirectoryTreeView.tsx b/src/renderer/components/DirectoryTreeView.tsxindex 9a36a55e8..5b3fc618e 100644--- a/src/renderer/components/DirectoryTreeView.tsx+++ b/src/renderer/components/DirectoryTreeView.tsx@@ -91,7 +91,6 @@ const DirectoryTreeView = forwardRef(<TargetTableMoveFileBoxaccepts={[DragItemTypes.FILE]}onDrop={handleFileMoveDrop}- location={location}{...props}/>);diff --git a/src/renderer/components/FileSourceDnd.tsx b/src/renderer/components/FileSourceDnd.tsxindex 38fd80bb1..f97ca75a7 100644--- a/src/renderer/components/FileSourceDnd.tsx+++ b/src/renderer/components/FileSourceDnd.tsx@@ -17,79 +17,48 @@*/import React from 'react';-import { DragSource, ConnectDragSource, ConnectDragPreview } from 'react-dnd';+import { useDrag } from 'react-dnd';import { getEmptyImage } from 'react-dnd-html5-backend';import DragItemTypes from './DragItemTypes';+import { TS } from '-/tagspaces.namespace';interface Props {- children: Array<any>;- connectDragSource: ConnectDragSource;- connectDragPreview: ConnectDragPreview;+ children: React.ReactNode;+}+interface ChildProps {+ entryPath: string;+ selectedEntries: TS.FileSystemEntry[];}-const boxSource = {- beginDrag(props) {- // console.log('beginDrag', props);- const entryPath = props.children.props.entryPath;- const selectedEntries = props.children.props.selectedEntries;- if (!selectedEntries.some((entry) => entry.path === entryPath)) {- return {- path: entryPath,- selectedEntries: [{ path: entryPath }],- };- } else {- return {- path: entryPath,- selectedEntries: selectedEntries,- };- }- },-- /* endDrag(props, monitor) {- const item = monitor.getItem();- const dropResult = monitor.getDropResult();+const FileSourceDnd: React.FC<Props> = ({ children }) => {+ const childProps = children as React.ReactElement<ChildProps>;+ const entryPath = childProps.props.entryPath;+ const selectedEntries = childProps.props.selectedEntries;+ let entries = !selectedEntries.some((entry) => entry.path === entryPath)+ ? [{ path: entryPath }]+ : selectedEntries;- // console.log('DropRESULT: ', dropResult);- // console.log('item: ', item);- if (dropResult && dropResult.tagGroupId && dropResult.tagGroupId !== item.sourceTagGroupId) {- // console.log(`Dropped ${item.tagId} from ${item.sourceTagGroupId} into ${dropResult.tagGroupId}!`);- props.moveTag(item.tagId, item.sourceTagGroupId, dropResult.tagGroupId);- } else if (dropResult && dropResult.entryPath) {- // console.log(`Dropped item: ${item.tag.title} onto file: ${dropResult.entryPath}!`);- props.addTags([dropResult.entryPath], [item.tag]);- }- } */-};+ const [collected, drag, preview] = useDrag({+ type: DragItemTypes.FILE,+ item: { path: entryPath, selectedEntries: entries },+ collect: (monitor) => ({+ isDragging: monitor.isDragging(),+ }),+ });-const FileSourceDnd = (props: Props) => {// Use empty image as a drag preview so browsers don't draw it// and we can draw whatever we want on the custom drag layer instead.- // if(props.children.props.selectedEntries && props.children.props.selectedEntries.length > 1) {- props.connectDragPreview(getEmptyImage(), {+ preview(getEmptyImage(), {// IE fallback: specify that we'd rather screenshot the node// when it already knows it's being dragged so we can hide it with CSS.captureDraggingState: true,});- // }- return props.connectDragSource(<span>{props.children}</span>);+ return (+ <span ref={drag} {...collected}>+ {children}+ </span>+ );};-/**- * Specifies which props to inject into your component.- */-const collect = (connect, monitor) => ({- // Call this function inside render()- // to let React DnD handle the drag events:- connectDragSource: connect.dragSource(),- // You can ask the monitor about the current drag preview- connectDragPreview: connect.dragPreview(),- // You can ask the monitor about the current drag state:- isDragging: monitor.isDragging(),-});--export default DragSource(- DragItemTypes.FILE,- boxSource,- collect,-)(FileSourceDnd);+export default FileSourceDnd;diff --git a/src/renderer/components/LocationView.tsx b/src/renderer/components/LocationView.tsxindex 279e6b11e..35b4a2650 100644--- a/src/renderer/components/LocationView.tsx+++ b/src/renderer/components/LocationView.tsx@@ -124,8 +124,8 @@ function LocationView(props: Props) {* @param monitor*/const handleFileMoveDrop = (item, monitor) => {- if (monitor) {- const { path, selectedEntries } = monitor.getItem();+ if (item) {+ const { path, selectedEntries } = item; //monitor.getItem();const arrPath = [];if (selectedEntries && selectedEntries.length > 0) {selectedEntries.map((entry) => {@@ -147,13 +147,13 @@ function LocationView(props: Props) {showNotification(t('Moving file not possible'), 'error', true);return;}- const targetLocation = item.location;+ const targetLocation = item.targetLocation;let targetPath = targetLocation ? targetLocation.path : undefined;if (targetPath === undefined) {- targetPath = item.path;+ targetPath = item.targetPath;}- if (monitor && targetPath !== undefined && targetLocation !== undefined) {+ if (targetPath !== undefined && targetLocation !== undefined) {// TODO handle monitor -> isOver and change folder iconconsole.log('Dropped files: ' + path);if (targetLocation.type === locationType.TYPE_CLOUD) {@@ -162,19 +162,11 @@ function LocationView(props: Props) {.then(() => {dispatch(AppActions.resetProgress());dispatch(AppActions.toggleUploadDialog());- uploadFiles(arrPath, targetPath, onUploadProgress)- .then((fsEntries: Array<TS.FileSystemEntry>) => {- /*if (targetPath === currentDirectoryPath) {- addDirectoryEntries(fsEntries);- dispatch(AppActions.reflectCreateEntries(fsEntries));- setSelectedEntries(fsEntries);- }*/- return true;- })- .catch((error) => {+ return uploadFiles(arrPath, targetPath, onUploadProgress).catch(+ (error) => {console.log('uploadFiles', error);- });- return true;+ },+ );}).catch((error) => {console.log('enableObjectStoreSupport', error);@@ -280,8 +272,8 @@ function LocationView(props: Props) {<TargetMoveFileBoxaccepts={[DragItemTypes.FILE]}onDrop={handleFileMoveDrop}- path={currentLocationPath} //PlatformIO.getLocationPath(location)}- location={location}+ targetPath={currentLocationPath} //PlatformIO.getLocationPath(location)}+ targetLocation={location}>{LocationTitle}</TargetMoveFileBox>diff --git a/src/renderer/components/TagContainerDnd.tsx b/src/renderer/components/TagContainerDnd.tsxindex e5156cc48..f01f16b73 100644--- a/src/renderer/components/TagContainerDnd.tsx+++ b/src/renderer/components/TagContainerDnd.tsx@@ -16,14 +16,8 @@**/-import React, { MutableRefObject } from 'react';-import {- DragSource,- DropTarget,- ConnectDragPreview,- ConnectDragSource,- ConnectDropTarget,-} from 'react-dnd';+import React, { useRef } from 'react';+import { useDrag, useDrop } from 'react-dnd';import { getEmptyImage } from 'react-dnd-html5-backend';import { extractTags } from '@tagspaces/tagspaces-common/paths';@@ -33,83 +27,116 @@ import TagContainer from './TagContainer';import { TS } from '-/tagspaces.namespace';import PlatformIO from '-/services/platform-facade';-const boxSource = {- // Expected the drag source specification to only have some of the following keys: canDrag, beginDrag, isDragging, endDrag- beginDrag(props) {- // console.log('beginDrag', props);- return {- index: props.index,- // tagTitle: props.tag.title,- tag: props.tag,- ...(props.tagGroup ? { sourceTagGroupId: props.tagGroup.uuid } : {}),- };- },+interface Props {+ tag: TS.Tag;+ index: number;+ tagGroup?: TS.TagGroup;+ handleTagMenu: (+ event: Object,+ tag: TS.Tag,+ param: any,+ haveSelectedEntries: boolean,+ ) => void;+ handleRemoveTag?: (event: Object, tag: TS.Tag) => void;+ tagMode?: 'default' | 'display' | 'remove';+ entryPath?: string;+ addTags?: (paths: Array<string>, tags: Array<TS.Tag>, updateIndex?) => void;+ addTag?: (tag: TS.Tag, parentTagGroupUuid: TS.Uuid) => void;+ moveTag?: (+ tagTitle: string,+ fromTagGroupId: TS.Uuid,+ toTagGroupId: TS.Uuid,+ ) => void;+ changeTagOrder?: (+ tagGroupUuid: TS.Uuid,+ fromIndex: number,+ toIndex: number,+ ) => void;+ editTagForEntry?: (path: string, tag: TS.Tag) => void;+ deleteIcon?: Object;+ selectedEntries: Array<TS.FileSystemEntry>;+ reorderTags?: boolean;+}- endDrag(props, monitor) {- const item = monitor.getItem();+const TagContainerDnd = (props: Props) => {+ const {+ index,+ tag,+ tagGroup,+ entryPath,+ handleTagMenu,+ deleteIcon,+ addTag,+ addTags,+ tagMode,+ reorderTags,+ changeTagOrder,+ editTagForEntry,+ moveTag,+ selectedEntries,+ } = props;++ const tagContainerRef = useRef<HTMLSpanElement>(null);++ const endDrag = (item, monitor) => {+ // const item = monitor.getItem();const dropResult = monitor.getDropResult();// console.log('DropRESULT: ', dropResult);- // console.log('item: ', item);if (dropResult &&dropResult.tagGroupId &&- dropResult.tagGroupId !== item.sourceTagGroupId+ tagGroup &&+ dropResult.tagGroupId !== tagGroup.uuid) {- if (props.moveTag) {- // console.log(`Dropped ${item.tagId} from ${item.sourceTagGroupId} into ${dropResult.tagGroupId}!`);- props.moveTag(- item.tag.title,- item.sourceTagGroupId,- dropResult.tagGroupId,- );- } else if (props.addTag) {+ if (moveTag) {+ // console.log(`Dropped ${item.tagId} from ${tagGroup.uuid} into ${dropResult.tagGroupId}!`);+ moveTag(item.tag.title, tagGroup.uuid, dropResult.tagGroupId);+ } else if (addTag) {// add from file DnD to tagGroup- props.addTag(props.tag, dropResult.tagGroupId);+ addTag(tag, dropResult.tagGroupId);}- } else if (dropResult && dropResult.entryPath && props.addTags) {+ } else if (dropResult && dropResult.entryPath && addTags) {// console.log(`Dropped item: ${item.tag.title} onto file: ${dropResult.entryPath}!`);if (- props.selectedEntries.some(- (entry) => entry.path === dropResult.entryPath,- )+ selectedEntries.some((entry) => entry.path === dropResult.entryPath)) {const selectedEntryPaths = [];- props.selectedEntries.map((entry) =>- selectedEntryPaths.push(entry.path),- );- props.addTags(selectedEntryPaths, [item.tag]);+ selectedEntries.map((entry) => selectedEntryPaths.push(entry.path));+ addTags(selectedEntryPaths, [item.tag]);} else {- props.addTags([dropResult.entryPath], [item.tag]);+ addTags([dropResult.entryPath], [item.tag]);}}- },-};+ };++ const [collected, drag, preview] = useDrag({+ type: DragItemTypes.TAG,+ item: { tag, tagGroup },+ end: endDrag,+ collect: (monitor) => ({+ isDragging: monitor.isDragging(),+ }),+ });-const boxTarget = {- // Expected the drop target specification to only have some of the following keys: canDrop, hover, drop- /* canDrop(props, monitor) {- const dragItem = monitor.getItem();- return dragItem.tag.type === props.tag.type;- }, */- hover(props, monitor) {- const dragItem = monitor.getItem();+ const boxTargetHover = (dragItem, monitor) => {+ // const dragItem = monitor.getItem();if (- props.reorderTags &&- props.tagGroup &&- dragItem.sourceTagGroupId === props.tagGroup.uuid+ reorderTags &&+ tagGroup+ //&& dragItem.sourceTagGroupId === tagGroup.uuid) {// sort tagGroups tagsconst dragIndex = dragItem.index;- const hoverIndex = props.index;+ const hoverIndex = index;// Don't replace items with themselvesif (dragIndex === hoverIndex) {return;}// Determine rectangle on screenconst hoverBoundingRect =- props.tagContainerRef && props.tagContainerRef.current- ? props.tagContainerRef.current.getBoundingClientRect()+ tagContainerRef && tagContainerRef.current+ ? tagContainerRef.current.getBoundingClientRect(): undefined; // findDOMNode(component).getBoundingClientRect(); // tagContainerRef.current.getBoundingClientRect();// Get vertical middle (bottom = right; top = left)@@ -136,22 +163,22 @@ const boxTarget = {return;}// Time to actually perform the action- props.changeTagOrder(props.tagGroup.uuid, dragIndex, hoverIndex);+ changeTagOrder(tagGroup.uuid, dragIndex, hoverIndex);// Note: we're mutating the monitor item here!// Generally it's better to avoid mutations,// but it's good here for the sake of performance// to avoid expensive index searches.dragItem.index = hoverIndex;- } else if (props.reorderTags && props.entryPath) {+ } else if (reorderTags && entryPath) {// sort fileSystemEntries tagsconst dragIndex = dragItem.index;- const hoverIndex = props.index;+ const hoverIndex = index;// Don't replace items with themselvesif (dragIndex === hoverIndex) {return;}// Cannot drop into different tag type- if (dragItem.tag.type !== props.tag.type) {+ if (dragItem.tag.type !== tag.type) {return;}// Skip smart tags drop into another tag@@ -159,13 +186,13 @@ const boxTarget = {return;}// Skip reorder from TagGroup source- if (dragItem.sourceTagGroupId !== undefined) {+ /*if (dragItem.sourceTagGroupId !== undefined) {return;- }+ }*/// Skip reorder on DnD Tag from an other fileif (dragItem.tag.type === 'plain') {const extractedTags = extractTags(- props.entryPath,+ entryPath,AppConfig.tagDelimiter,PlatformIO.getDirSeparator(),);@@ -180,125 +207,46 @@ const boxTarget = {}dragItem.tag.position = hoverIndex;- props.editTagForEntry(props.entryPath, dragItem.tag);+ editTagForEntry(entryPath, dragItem.tag);dragItem.index = hoverIndex;}- },-};--interface Props {- tag: TS.Tag;- index: number;- tagGroup?: TS.TagGroup;- handleTagMenu: (- event: Object,- tag: TS.Tag,- param: any,- haveSelectedEntries: boolean,- ) => void;- handleRemoveTag?: (event: Object, tag: TS.Tag) => void;- isDragging?: boolean;- tagMode?: 'default' | 'display' | 'remove';- entryPath?: string;- addTags?: (paths: Array<string>, tags: Array<TS.Tag>, updateIndex?) => void;- addTag?: (tag: TS.Tag, parentTagGroupUuid: TS.Uuid) => void;- moveTag?: (- tagTitle: string,- fromTagGroupId: TS.Uuid,- toTagGroupId: TS.Uuid,- ) => void;- changeTagOrder?: (- tagGroupUuid: TS.Uuid,- fromIndex: number,- toIndex: number,- ) => void;- editTagForEntry?: (path: string, tag: TS.Tag) => void;- connectDragSource?: ConnectDragSource;- connectDropTarget: ConnectDropTarget;- connectDragPreview?: ConnectDragPreview;- deleteIcon?: Object;- selectedEntries: Array<TS.FileSystemEntry>;- tagContainerRef?: MutableRefObject<HTMLSpanElement>;- reorderTags?: boolean;-}--const TagContainerDnd = (props: Props) => {- const {- tag,- tagGroup,- entryPath,- handleTagMenu,- deleteIcon,- isDragging,- connectDragSource,- connectDropTarget,- addTags,- tagMode,- tagContainerRef,- reorderTags,- connectDragPreview,- } = props;-- /* const [{ opacity }, dragRef] = useDrag(- () => ({- type: DragItemTypes.TAG,- item: { text },- collect: monitor => ({- opacity: monitor.isDragging() ? 0.5 : 1- })- }),- []- );*/-+ };++ const [, drop] = useDrop({+ accept: DragItemTypes.TAG,+ hover: boxTargetHover,+ /*hover: (item, monitor) => {+ // Implement hover logic here+ },*/+ });// Use empty image as a drag preview so browsers don't draw it// and we can draw whatever we want on the custom drag layer instead.- connectDragPreview(getEmptyImage(), {+ preview(getEmptyImage(), {// IE fallback: specify that we'd rather screenshot the node// when it already knows it's being dragged so we can hide it with CSS.captureDraggingState: true,});- return connectDropTarget(- connectDragSource(- <span ref={tagContainerRef}>- <TagContainer- tag={tag}- tagGroup={tagGroup}- handleTagMenu={handleTagMenu}- deleteIcon={deleteIcon}- addTags={addTags}- tagMode={tagMode}- entryPath={entryPath}- isDragging={isDragging}- reorderTags={reorderTags}- />- </span>,- ),+ const { isDragging } = collected;++ drag(drop(tagContainerRef));++ return (+ <span ref={tagContainerRef} {...collected}>+ <TagContainer+ tag={tag}+ tagGroup={tagGroup}+ handleTagMenu={handleTagMenu}+ deleteIcon={deleteIcon}+ addTags={addTags}+ tagMode={tagMode}+ entryPath={entryPath}+ isDragging={isDragging}+ reorderTags={reorderTags}+ />+ </span>);};-/**- * Specifies which props to inject into your component.- */-const collectSource = (connect, monitor) => ({- // Call this function inside render()- // to let React DnD handle the drag events:- connectDragSource: connect.dragSource(),- // You can ask the monitor about the current drag preview- connectDragPreview: connect.dragPreview(),- // You can ask the monitor about the current drag state:- isDragging: monitor.isDragging(),-});--const collectTarget = (connect, monitor) => ({- connectDropTarget: connect.dropTarget(),- isOver: monitor.isOver(),- canDrop: monitor.canDrop(),-});--export default DragSource(- DragItemTypes.TAG,- boxSource,- collectSource,-)(DropTarget(DragItemTypes.TAG, boxTarget, collectTarget)(TagContainerDnd));+export default TagContainerDnd;diff --git a/src/renderer/components/TagGroupTitleDnD.tsx b/src/renderer/components/TagGroupTitleDnD.tsxindex 4c659f2c1..32fa2eb58 100644--- a/src/renderer/components/TagGroupTitleDnD.tsx+++ b/src/renderer/components/TagGroupTitleDnD.tsx@@ -16,18 +16,13 @@**/-import React from 'react';+import React, { useRef } from 'react';import Typography from '@mui/material/Typography';import IconButton from '@mui/material/IconButton';import MoreVertIcon from '@mui/icons-material/MoreVert';import ArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';import ArrowRightIcon from '@mui/icons-material/KeyboardArrowRight';-import {- ConnectDragSource,- ConnectDropTarget,- DragSource,- DropTarget,-} from 'react-dnd';+import { useDrag, useDrop } from 'react-dnd';import Grid from '@mui/material/Grid';import { TS } from '-/tagspaces.namespace';import DragItemTypes from '-/components/DragItemTypes';@@ -45,18 +40,80 @@ interface Props {locations: Array<TS.Location>;tagGroupCollapsed: Array<string>;isReadOnly: boolean;- connectDragSource?: ConnectDragSource;- connectDropTarget: ConnectDropTarget;}function TagGroupTitleDnD(props: Props) {+ const {+ index,+ tagGroup,+ handleTagGroupMenu,+ moveTagGroup,+ toggleTagGroup,+ locations,+ isReadOnly,+ } = props;+ const tagGroupRef = useRef<HTMLSpanElement>(null);++ const [, drag] = useDrag({+ type: DragItemTypes.TAG_GROUP,+ item: { tagGroup: tagGroup, index: index },+ });+ const dropHover = (dragItem, monitor) => {+ // const dragItem = monitor.getItem();+ const dragIndex = dragItem.index;+ const hoverIndex = index;+ // Don't replace items with themselves+ if (dragIndex === hoverIndex) {+ return;+ }+ // Determine rectangle on screen+ const hoverBoundingRect =+ tagGroupRef && tagGroupRef.current+ ? tagGroupRef.current.getBoundingClientRect()+ : undefined; // findDOMNode(component).getBoundingClientRect(); // tagContainerRef.current.getBoundingClientRect();++ // Get vertical middle (bottom = right; top = left)+ const hoverMiddleY = (hoverBoundingRect.bottom - hoverBoundingRect.top) / 2;++ // Determine mouse position+ const clientOffset = monitor.getClientOffset();++ // Get pixels to the top+ const hoverClientY = clientOffset.y - hoverBoundingRect.top;++ // Only perform the move when the mouse has crossed half of the items height+ // When dragging downwards, only move when the cursor is below 50%+ // When dragging upwards, only move when the cursor is above 50%++ // Dragging downwards+ if (dragIndex < hoverIndex && hoverClientY < hoverMiddleY) {+ return;+ }++ // Dragging upwards+ if (dragIndex > hoverIndex && hoverClientY > hoverMiddleY) {+ return;+ }+ moveTagGroup(dragItem.tagGroup.uuid, hoverIndex);+ // Note: we're mutating the monitor item here!+ // Generally it's better to avoid mutations,+ // but it's good here for the sake of performance+ // to avoid expensive index searches.+ dragItem.index = hoverIndex;+ };++ const [, drop] = useDrop({+ accept: DragItemTypes.TAG_GROUP,+ hover: dropHover,+ });+const handleTagGroupTitleClick = (event: Object, tagGroup) => {- props.toggleTagGroup(tagGroup.uuid);+ toggleTagGroup(tagGroup.uuid);};function getLocationName(locationId: string) {if (locationId) {- const location: TS.Location = props.locations.find(+ const location: TS.Location = locations.find((l) => l.uuid === locationId,);if (location) {@@ -66,152 +123,85 @@ function TagGroupTitleDnD(props: Props) {return '';}- const { tagGroup, handleTagGroupMenu, connectDropTarget, connectDragSource } =- props;-const tagGroupTitle = (- <div>- <SidePanel- data-tid={'tagLibraryTagGroupTitle_' + tagGroup.title}- className={classes.listItem}- title={'Number of tags in this tag group: ' + tagGroup.children.length}+ <SidePanel+ data-tid={'tagLibraryTagGroupTitle_' + tagGroup.title}+ className={classes.listItem}+ title={'Number of tags in this tag group: ' + tagGroup.children.length}+ >+ <Grid+ container+ direction="row"+ alignItems="stretch"+ alignContent="center"+ style={{ flexWrap: 'nowrap' }}>- <Grid- container- direction="row"- alignItems="stretch"- alignContent="center"- style={{ flexWrap: 'nowrap' }}- >- <Grid item xs={2} style={{ maxWidth: 40 }}>+ <Grid item xs={2} style={{ maxWidth: 40 }}>+ <IconButton+ style={{ minWidth: 'auto', padding: 7 }}+ onClick={(event: any) => handleTagGroupTitleClick(event, tagGroup)}+ size="large"+ >+ {tagGroup.expanded ? <ArrowDownIcon /> : <ArrowRightIcon />}+ </IconButton>+ </Grid>+ <Grid item xs={8} style={{ alignSelf: 'center' }}>+ <Typography+ variant="inherit"+ className={classes.header}+ style={{ paddingLeft: 0 }}+ data-tid="locationTitleElement"+ noWrap+ onClick={(event: any) => handleTagGroupTitleClick(event, tagGroup)}+ >+ {tagGroup.title + getLocationName(tagGroup.locationId)}+ {!tagGroup.expanded && (+ <span+ style={{+ display: 'inline-block',+ minWidth: 10,+ padding: '3px 7px',+ fontSize: 10,+ fontWeight: 'normal',+ marginLeft: 4,+ color: '#ffffff',+ lineHeight: 1,+ verticalAlign: 'middle',+ whiteSpace: 'nowrap',+ textAlign: 'center',+ backgroundColor: '#bbbbbb',+ borderRadius: 10,+ }}+ >+ {tagGroup.children.length}+ </span>+ )}+ </Typography>+ </Grid>+ <Grid item xs={2} style={{ textAlign: 'end' }}>+ {!isReadOnly && (<IconButtonstyle={{ minWidth: 'auto', padding: 7 }}- onClick={(event: any) =>- handleTagGroupTitleClick(event, tagGroup)+ data-tid={+ 'tagLibraryMoreButton_' + tagGroup.title.replace(/ /g, '_')}+ onClick={(event: any) => handleTagGroupMenu(event, tagGroup)}size="large">- {tagGroup.expanded ? <ArrowDownIcon /> : <ArrowRightIcon />}+ <MoreVertIcon /></IconButton>- </Grid>- <Grid item xs={8} style={{ alignSelf: 'center' }}>- <Typography- variant="inherit"- className={classes.header}- style={{ paddingLeft: 0 }}- data-tid="locationTitleElement"- noWrap- onClick={(event: any) =>- handleTagGroupTitleClick(event, tagGroup)- }- >- {tagGroup.title + getLocationName(tagGroup.locationId)}- {!tagGroup.expanded && (- <span- style={{- display: 'inline-block',- minWidth: 10,- padding: '3px 7px',- fontSize: 10,- fontWeight: 'normal',- marginLeft: 4,- color: '#ffffff',- lineHeight: 1,- verticalAlign: 'middle',- whiteSpace: 'nowrap',- textAlign: 'center',- backgroundColor: '#bbbbbb',- borderRadius: 10,- }}- >- {tagGroup.children.length}- </span>- )}- </Typography>- </Grid>- <Grid item xs={2} style={{ textAlign: 'end' }}>- {!props.isReadOnly && (- <IconButton- style={{ minWidth: 'auto', padding: 7 }}- data-tid={- 'tagLibraryMoreButton_' + tagGroup.title.replace(/ /g, '_')- }- onClick={(event: any) => handleTagGroupMenu(event, tagGroup)}- size="large"- >- <MoreVertIcon />- </IconButton>- )}- </Grid>+ )}</Grid>- </SidePanel>- </div>+ </Grid>+ </SidePanel>);if (tagGroup.readOnly) {return tagGroupTitle;}- return connectDropTarget(connectDragSource(tagGroupTitle));-}-const boxSource = {- beginDrag(props) {- return { tagGroup: props.tagGroup, index: props.index };- } /* ,- endDrag(props, monitor) {- const item = monitor.getItem();- const dropResult = monitor.getDropResult();- } */,-};+ drag(drop(tagGroupRef));-/**- * Specifies which props to inject into your component.- */-const collectSource = (connect, monitor) => ({- // Call this function inside render()- // to let React DnD handle the drag events:- connectDragSource: connect.dragSource(),- // You can ask the monitor about the current drag preview- connectDragPreview: connect.dragPreview(),- // You can ask the monitor about the current drag state:- isDragging: monitor.isDragging(),-});--const boxTarget = {- // Expected the drop target specification to only have some of the following keys: canDrop, hover, drop- /* canDrop(props, monitor) {- const dragItem = monitor.getItem();- return dragItem.tag.type === props.tag.type;- }, */- hover(props, monitor) {- const dragItem = monitor.getItem();- const dragIndex = dragItem.index;- const hoverIndex = props.index;- // Don't replace items with themselves- if (dragIndex === hoverIndex) {- return;- }- props.moveTagGroup(dragItem.tagGroup.uuid, hoverIndex);- // Note: we're mutating the monitor item here!- // Generally it's better to avoid mutations,- // but it's good here for the sake of performance- // to avoid expensive index searches.- dragItem.index = hoverIndex;- },-};-const collectTarget = (connect, monitor) => ({- connectDropTarget: connect.dropTarget(),- isOver: monitor.isOver(),- canDrop: monitor.canDrop(),-});--export default DragSource(- DragItemTypes.TAG_GROUP,- boxSource,- collectSource,-)(- DropTarget(- DragItemTypes.TAG_GROUP,- boxTarget,- collectTarget,- )(TagGroupTitleDnD),-);+ return <span ref={tagGroupRef}>{tagGroupTitle}</span>;+}++export default TagGroupTitleDnD;diff --git a/src/renderer/components/TagLibrary.tsx b/src/renderer/components/TagLibrary.tsxindex e5bbad886..e5ea25372 100644--- a/src/renderer/components/TagLibrary.tsx+++ b/src/renderer/components/TagLibrary.tsx@@ -97,7 +97,7 @@ function TagLibrary(props: Props) {const [tagGroups, setTagGroups] =useState<Array<TS.TagGroup>>(getTagLibrary());// const tagLibrary: Array<TS.TagGroup> = getTagLibrary();- const tagContainerRef = useRef<HTMLSpanElement>(null);+ //const tagContainerRef = useRef<HTMLSpanElement>(null);const [tagGroupMenuAnchorEl, setTagGroupMenuAnchorEl] =useState<null | HTMLElement>(null);const [tagMenuAnchorEl, setTagMenuAnchorEl] = useState<null | HTMLElement>(@@ -297,7 +297,7 @@ function TagLibrary(props: Props) {return (<TagContainerDndkey={tagGroup.uuid + tag.title}- tagContainerRef={tagContainerRef}+ // tagContainerRef={tagContainerRef}index={idx}tag={tag}tagGroup={tagGroup}diff --git a/src/renderer/components/TargetMoveFileBox.tsx b/src/renderer/components/TargetMoveFileBox.tsxindex 73c6e4166..77d48b709 100644--- a/src/renderer/components/TargetMoveFileBox.tsx+++ b/src/renderer/components/TargetMoveFileBox.tsx@@ -17,11 +17,11 @@*/import React from 'react';-import { DropTarget } from 'react-dnd';+import { useDrop } from 'react-dnd';import { TS } from '-/tagspaces.namespace';import { classes, DnD } from '-/components/DnD.css';-const styles: any = () => ({+/*const styles: any = () => ({dropzone: {margin: 5,position: 'absolute',@@ -34,45 +34,46 @@ const styles: any = () => ({border: '3px dashed white',display: 'flex',},-});--const boxTarget = {- drop(props, monitor) {- return props.onDrop(props, monitor);- },-};+});*/interface Props {- accepts: Array<string>;+ accepts: string[];onDrop: (item: any, monitor: any) => void;- canDrop: boolean;- isOver: boolean;- connectDropTarget: any;children: any;- path?: string;- location?: TS.Location;+ targetPath?: string;+ targetLocation?: TS.Location;}const TargetMoveFileBox = (props: Props) => {- const { canDrop, isOver, connectDropTarget, children } = props;- const dragContent =+ const { accepts, onDrop, targetLocation, targetPath, children } = props;+ /*const dragContent =canDrop && isOver ? (- <DnD className={classes.dropzone} /> /* {t('core:releaseToMoveDrop')} */- ) : undefined;- return connectDropTarget(- <div>- {dragContent}+ <DnD className={classes.dropzone} /> /!* {t('core:releaseToMoveDrop')} *!/+ ) : undefined;*/++ const [{ isOver, canDrop }, drop] = useDrop({+ accept: accepts,+ drop: (item: any, monitor) => {+ onDrop(+ {+ ...item,+ ...(targetPath && { targetPath }),+ ...(targetLocation && { targetLocation }),+ },+ monitor,+ );+ },+ collect: (monitor) => ({+ isOver: monitor.isOver(),+ canDrop: monitor.canDrop(),+ }),+ });+ return (+ <div ref={drop}>+ {canDrop && isOver && <DnD className={classes.dropzone} />}{children}- </div>,+ </div>);};-export default DropTarget(- (props) => props.accepts,- boxTarget,- (connect, monitor) => ({- connectDropTarget: connect.dropTarget(),- isOver: monitor.isOver(),- canDrop: monitor.canDrop(),- }),-)(TargetMoveFileBox);+export default TargetMoveFileBox;diff --git a/src/renderer/components/TargetTableMoveFileBox.tsx b/src/renderer/components/TargetTableMoveFileBox.tsxindex c7cf5577e..fa4a7ce5c 100644--- a/src/renderer/components/TargetTableMoveFileBox.tsx+++ b/src/renderer/components/TargetTableMoveFileBox.tsx@@ -17,38 +17,40 @@*/import React from 'react';-import { DropTarget } from 'react-dnd';--const boxTarget = {- drop(props, monitor) {- return props.onDrop(props, monitor);- },-};+import { useDrop } from 'react-dnd';+import { TS } from '-/tagspaces.namespace';interface Props {- accepts: Array<string>;+ accepts: string[];onDrop: (item: any, monitor: any) => void;- canDrop: boolean;- isOver: boolean;- connectDropTarget: any;+ location: TS.Location;className: string;}const TargetTableMoveFileBox = (props: Props) => {- const { canDrop, isOver, connectDropTarget, ...restProps } = props;+ const { accepts, onDrop, ...restProps } = props;++ const [{ isOver, canDrop }, drop] = useDrop({+ accept: accepts,+ drop: (item: any, monitor) => {+ onDrop(+ {+ ...item,+ ...(restProps.location && { targetLocation: restProps.location }),+ },+ monitor,+ );+ },+ collect: (monitor) => ({+ isOver: monitor.isOver(),+ canDrop: monitor.canDrop(),+ }),+ });+if (canDrop && isOver) {restProps.className += ' dropzone'; // TODO set props.location type and add dropzonecopy based on this type}- // @ts-ignore- return connectDropTarget(<tr {...restProps} />);+ return <tr ref={drop} {...restProps} />;};-export default DropTarget(- (props) => props.accepts,- boxTarget,- (connect, monitor) => ({- connectDropTarget: connect.dropTarget(),- isOver: monitor.isOver(),- canDrop: monitor.canDrop(),- }),-)(TargetTableMoveFileBox);+export default TargetTableMoveFileBox;diff --git a/src/renderer/containers/MainPage.tsx b/src/renderer/containers/MainPage.tsxindex a50b87657..b8f8c17ee 100644--- a/src/renderer/containers/MainPage.tsx+++ b/src/renderer/containers/MainPage.tsx@@ -70,7 +70,6 @@ import {} from '../reducers/app';import TargetFileBox from '../components/TargetFileBox';import LoadingLazy from '../components/LoadingLazy';-import withDnDContext from '-/containers/withDnDContext';import CustomDragLayer from '-/components/CustomDragLayer';import FileUploadDialog from '-/components/dialogs/FileUploadDialog';import ProgressDialog from '-/components/dialogs/ProgressDialog';@@ -132,7 +131,7 @@ const Root = styled('div')(({ theme }) => ({}));interface Props {- isFirstRun: boolean;+ //isFirstRun: boolean;setFirstRun: (isFirstRun: boolean) => void;isDesktopMode: boolean;isSettingsDialogOpened: boolean;@@ -177,7 +176,7 @@ interface Props {// openSearchPanel: () => void;openHelpFeedbackPanel: () => void;// closeAllVerticalPanels: () => void;- leftSplitSize: number;+ //leftSplitSize: number;mainSplitSize: any;toggleShowUnixHiddenEntries: () => void;toggleTruncatedConfirmDialog: () => void;@@ -887,6 +886,7 @@ const areEqual = (prevProp, nextProp) =>nextProp.isImportKanBanDialogOpened === prevProp.isImportKanBanDialogOpened &&nextProp.mainSplitSize === prevProp.mainSplitSize;-export default withDnDContext(- connect(mapStateToProps, mapDispatchToProps)(React.memo(MainPage, areEqual)), //translate(['core'], { wait: true })(React.memo(MainPage, areEqual)))-);+export default connect(+ mapStateToProps,+ mapDispatchToProps,+)(React.memo(MainPage, areEqual));diff --git a/src/renderer/containers/Root.tsx b/src/renderer/containers/Root.tsxindex a13a59f02..a804909bf 100644--- a/src/renderer/containers/Root.tsx+++ b/src/renderer/containers/Root.tsx@@ -37,6 +37,8 @@ import { SelectedEntryContextProvider } from '-/hooks/SelectedEntryContextProvidimport { FSWatcherContextProvider } from '-/hooks/FSWatcherContextProvider';import { PlatformFacadeContextProvider } from '-/hooks/PlatformFacadeContextProvider';import { EditedEntryContextProvider } from '-/hooks/EditedEntryContextProvider';+import { HTML5Backend } from 'react-dnd-html5-backend';+import { DndProvider } from 'react-dnd';type RootType = {store: Store<{}>;@@ -69,7 +71,9 @@ export default function Root({ store, persistor }: RootType) {<OpenedEntryContextProvider><IOActionsContextProvider><TaggingActionsContextProvider>- <MainPage />+ <DndProvider backend={HTML5Backend}>+ <MainPage />+ </DndProvider></TaggingActionsContextProvider></IOActionsContextProvider></OpenedEntryContextProvider>diff --git a/src/renderer/containers/withDnDContext.tsx b/src/renderer/containers/withDnDContext.tsxindex 53ece4874..3c6c519df 100644--- a/src/renderer/containers/withDnDContext.tsx+++ b/src/renderer/containers/withDnDContext.tsx@@ -1,4 +1,4 @@-import * as React from 'react';+/*import * as React from 'react';import { DndProvider } from 'react-dnd';import { HTML5Backend } from 'react-dnd-html5-backend';@@ -9,4 +9,4 @@ export default (Component) =><Component {...props} /></DndProvider>);- };+ };*/diff --git a/src/renderer/perspectives/common/main-container.tsx b/src/renderer/perspectives/common/main-container.tsxindex d8e556273..c074ff8b2 100644--- a/src/renderer/perspectives/common/main-container.tsx+++ b/src/renderer/perspectives/common/main-container.tsx@@ -243,25 +243,25 @@ export const renderCell = (); //i18n.t('core:dndDisabledReadOnlyMode')return;}- if (monitor) {- const mItem = monitor.getItem();+ if (item) {+ // const mItem = monitor.getItem();let arrPath;- if (mItem.selectedEntries && mItem.selectedEntries.length > 0) {- const arrSelected = mItem.selectedEntries+ if (item.selectedEntries && item.selectedEntries.length > 0) {+ const arrSelected = item.selectedEntries.map((entry) => entry.path)// remove target folder selection- .filter((epath) => epath !== item.path);+ .filter((epath) => epath !== item.targetPath);if (arrSelected.length > 0) {arrPath = arrSelected;} else {- arrPath = [mItem.path];+ arrPath = [item.path];}} else {- arrPath = [mItem.path];+ arrPath = [item.path];}console.log('Dropped files: ' + item.path);- moveFiles(arrPath, item.path);- clearSelection();+ moveFiles(arrPath, item.targetPath);+ //clearSelection();}};@@ -292,7 +292,7 @@ export const renderCell = (><TargetMoveFileBoxaccepts={[DragItemTypes.FILE]}- path={fsEntry.path}+ targetPath={fsEntry.path}onDrop={handleFileMoveDrop}>{cellContent(