-
Notifications
You must be signed in to change notification settings - Fork 0
Touch and hold to drag #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,16 +9,17 @@ | |
"yarn": ">=1.16.0" | ||
}, | ||
"scripts": { | ||
"start": "react-app-rewired start", | ||
"build-frontend": "react-app-rewired build", | ||
"build": "yarn build-frontend && yarn build-mock-backend", | ||
"build-mock-backend": "tsc mock-api/functions/*/**.ts", | ||
"start-frontend": "react-app-rewired start", | ||
"test": "react-app-rewired test", | ||
"eject": "react-scripts eject", | ||
"heroku-postbuild": "yarn run build", | ||
"lint": "eslint --ext .ts --ext .tsx src/", | ||
"typecheck": "tsc -p tsconfig.json --noEmit", | ||
"serve": "ts-node mock-api/server", | ||
"start-mock-backend": "ts-node mock-api/server", | ||
"start": "concurrently \"yarn start-frontend\" \"yarn start-mock-backend\"", | ||
"storybook": "start-storybook -p 9009 -s public", | ||
"build-storybook": "build-storybook -s public" | ||
}, | ||
|
@@ -44,13 +45,10 @@ | |
"ramda": "^0.27.0", | ||
"react": "^16.13.1", | ||
"react-animated-dots": "^1.0.0", | ||
"react-dnd": "^9.4.0", | ||
"react-dnd-cjs": "^9.4.0", | ||
"react-dnd-html5-backend": "^9.4.0", | ||
"react-dnd-html5-backend-cjs": "^9.4.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
"react-dnd-multi-backend": "^4.0.0-0", | ||
"react-dnd-touch-backend": "^9.4.0", | ||
"react-dnd-touch-backend-cjs": "^9.4.0", | ||
"react-dnd": "^11.1.3", | ||
"react-dnd-html5-backend": "^11.1.3", | ||
"react-dnd-multi-backend": "^6.0.2", | ||
"react-dnd-touch-backend": "^11.1.3", | ||
"react-dom": "^16.13.1", | ||
"react-highlight-words": "^0.16.0", | ||
"react-hot-keys": "^2.0.0-beta.2", | ||
|
@@ -75,11 +73,6 @@ | |
"serverless-http": "^2.5.0" | ||
}, | ||
"devDependencies": { | ||
"@storybook/addon-actions": "^5.3.19", | ||
"@storybook/addon-links": "^5.3.19", | ||
"@storybook/addons": "^5.3.19", | ||
"@storybook/preset-create-react-app": "^3.1.4", | ||
"@storybook/react": "^5.3.19", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These were in twice. Oopsy. |
||
"@babel/core": "^7.10.5", | ||
"@storybook/addon-actions": "^5.3.19", | ||
"@storybook/addon-links": "^5.3.19", | ||
|
@@ -91,7 +84,6 @@ | |
"@types/body-parser": "^1.19.0", | ||
"@types/classnames": "^2.2.10", | ||
"@types/cors": "^2.8.6", | ||
"@types/eslint-plugin-prettier": "^3.1.0", | ||
"@types/express": "^4.17.3", | ||
"@types/history": "^4.7.6", | ||
"@types/jest": "^25.1.4", | ||
|
@@ -103,7 +95,6 @@ | |
"@types/prettier": "^2.0.2", | ||
"@types/ramda": "^0.27.11", | ||
"@types/react": "^16.9.25", | ||
"@types/react-dnd-multi-backend": "^4.0.1", | ||
"@types/react-dom": "^16.9.5", | ||
"@types/react-highlight-words": "^0.16.1", | ||
"@types/react-list": "^0.8.5", | ||
|
@@ -122,6 +113,7 @@ | |
"@types/redux-thunk": "^2.1.0", | ||
"babel-loader": "^8.1.0", | ||
"body-parser": "^1.18.2", | ||
"concurrently": "^5.2.0", | ||
"cors": "^2.8.5", | ||
"cross-env": "^5.1.3", | ||
"css-loader": "^3.4.2", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
import React from "react"; | ||
import { connect } from "react-redux"; | ||
import styled from "@emotion/styled"; | ||
// Also, set up the drag and drop context | ||
import { DndProvider } from "react-dnd"; | ||
import HTML5Backend from "react-dnd-html5-backend"; | ||
import TouchBackend from "react-dnd-touch-backend"; | ||
import { HTML5Backend } from "react-dnd-html5-backend"; | ||
import { TouchBackend } from "react-dnd-touch-backend"; | ||
import MultiBackend, { | ||
TouchTransition, | ||
Preview, | ||
TouchTransition | ||
usePreview | ||
} from "react-dnd-multi-backend"; | ||
// import HTML5toTouch from "react-dnd-multi-backend/lib/HTML5toTouch"; | ||
import { withRouter } from "react-router"; | ||
|
||
import Tooltip from "../tooltip/Tooltip"; | ||
|
@@ -19,9 +18,16 @@ import type { TabT } from "../pane/types"; | |
import LeftPane from "./LeftPane"; | ||
import RightPane from "./RightPane"; | ||
import { ContentLayout } from "../ContentLayout"; | ||
import { BackendFactory } from "dnd-core"; | ||
|
||
interface PreviewItemProps { | ||
theme?: any; | ||
width: string; | ||
height: string; | ||
} | ||
|
||
const PreviewItem = styled("div")` | ||
background-color: ${({ theme }) => theme.col.grayVeryLight}; | ||
background-color: ${({ theme }: PreviewItemProps) => theme.col.grayVeryLight}; | ||
opacity: 0.9; | ||
box-shadow: 0 0 15px 0 rgba(0, 0, 0, 0.2); | ||
border-radius: ${({ theme }) => theme.borderRadius}; | ||
|
@@ -36,12 +42,16 @@ const PreviewItem = styled("div")` | |
// Consider upgrading react-dnd BUT somehow try to keep IE11 compatibility | ||
//@ts-ignore | ||
|
||
const generatePreview = (type, item, style) => { | ||
// eslint-disable-next-line no-console | ||
console.log("PREVIEW RENDERED", item.width, item.height, style); | ||
//@ts-ignore | ||
|
||
return <PreviewItem width={item.width} height={item.height} style={style} />; | ||
const DragPreview = () => { | ||
const { item, style, display } = usePreview(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the hook api now after updating |
||
if (!display) { | ||
return null; | ||
} | ||
return ( | ||
<PreviewItem width={item.width} height={item.height} style={style}> | ||
{item.label} | ||
</PreviewItem> | ||
); | ||
}; | ||
|
||
type PropsType = { | ||
|
@@ -57,23 +67,30 @@ export const CustomHTML5toTouch = { | |
{ | ||
backend: TouchBackend, | ||
transition: TouchTransition, | ||
options: { enableMouseEvents: true }, // Note that you can call your backends with options | ||
preview: true, | ||
skipDispatchOnTransition: true | ||
options: { | ||
delayTouchStart: 100, //This enables touch to scroll and touch and hold to drag. | ||
ignoreContextMenu: true | ||
}, | ||
preview: true | ||
} | ||
] | ||
}; | ||
|
||
const Content = ({ displayTooltip, rightTabs }: PropsType) => { | ||
return ( | ||
<DndProvider backend={MultiBackend} options={CustomHTML5toTouch}> | ||
<DndProvider | ||
backend={(MultiBackend as unknown) as BackendFactory} | ||
options={CustomHTML5toTouch} | ||
> | ||
<ContentLayout | ||
info={displayTooltip ? <Tooltip /> : <ActivateTooltip />} | ||
editor={<RightPane tabs={rightTabs} />} | ||
tools={<LeftPane />} | ||
/> | ||
|
||
<Preview generator={generatePreview} /> | ||
<Preview> | ||
<DragPreview /> | ||
</Preview> | ||
</DndProvider> | ||
); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module "react-dnd-multi-backend"; // Currently the DT types for this package are broken (the new API is missing). Until then we any this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was too strict. The "react-app" config is strict enough.