Skip to content

Commit

Permalink
fix: everything (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanVann authored Apr 6, 2020
1 parent 999c218 commit d5f69d8
Show file tree
Hide file tree
Showing 30 changed files with 18,596 additions and 7,474 deletions.
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v13.11.0
24,939 changes: 18,116 additions & 6,823 deletions .yarn/releases/yarn-1.13.0.js → .yarn/releases/yarn-1.22.4.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions .yarnrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# yarn lockfile v1


lastUpdateCheck 1549852927714
yarn-path ".yarn/releases/yarn-1.13.0.js"
lastUpdateCheck 1586147579290
yarn-path ".yarn/releases/yarn-1.22.4.js"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
],
"scripts": {
"build": "lerna run build --stream",
"//": "Using this until issue is resolved: https://github.com/facebook/create-react-app/issues/8685",
"start": "wsrun start",
"start_comment": "Using this until issue is resolved: https://github.com/facebook/create-react-app/issues/8685",
"test": "lerna run test --stream",
"test-ci": "lerna run test-ci --stream"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/ant-design-draggable-modal/src/DraggableModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { getModalState } from './draggableModalReducer'
import { ModalProps } from 'antd/lib/modal'

export interface DraggableModalProps extends ModalProps {
initialWidth: number
initialHeight: number
initialWidth?: number
initialHeight?: number
}

export const DraggableModal: FunctionComponent<DraggableModalProps> = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ export interface DraggableModalContextValue extends DraggableModalContextMethods
}

export const DraggableModalContext = React.createContext<DraggableModalContextValue | null>(null)

if (process.env.NODE_ENV !== 'production') {
DraggableModalContext.displayName = 'DraggableModalContext'
}
153 changes: 80 additions & 73 deletions packages/ant-design-draggable-modal/src/DraggableModalInner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,91 +14,98 @@ const modalStyle: React.CSSProperties = { margin: 0, paddingBottom: 0, pointerEv
interface ContextProps extends DraggableModalContextMethods {
id: ModalID
modalState: ModalState
initialWidth?: number
initialHeight?: number
}

export type DraggableModalInnerProps = ModalProps & { children?: React.ReactNode } & ContextProps

export const DraggableModalInner = memo(
({
id,
modalState,
dispatch,
visible,
children,
title,
...otherProps
}: DraggableModalInnerProps) => {
// Call on mount and unmount.
useEffect(() => {
dispatch({ type: 'mount', id })
return () => dispatch({ type: 'unmount', id })
}, [dispatch, id])
function DraggableModalInnerNonMemo({
id,
modalState,
dispatch,
visible,
children,
title,
initialWidth,
initialHeight,
...otherProps
}: DraggableModalInnerProps) {
// Call on mount and unmount.
useEffect(() => {
dispatch({ type: 'mount', id, intialState: { initialWidth, initialHeight } })
return () => dispatch({ type: 'unmount', id })
}, [dispatch, id])

// Bring this to the front if it's been opened with props.
const visiblePrevious = usePrevious(visible)
useEffect(() => {
if (visible !== visiblePrevious) {
if (visible) {
dispatch({ type: 'show', id })
} else {
dispatch({ type: 'hide', id })
}
// Bring this to the front if it's been opened with props.
const visiblePrevious = usePrevious(visible)
useEffect(() => {
if (visible !== visiblePrevious) {
if (visible) {
dispatch({ type: 'show', id })
} else {
dispatch({ type: 'hide', id })
}
}, [visible, visiblePrevious, id, dispatch])

const { zIndex, x, y, width, height } = modalState
}
}, [visible, visiblePrevious, id, dispatch])

const style: React.CSSProperties = useMemo(
() => ({ ...modalStyle, top: y, left: x, height }),
[y, x, height],
)
const { zIndex, x, y, width, height } = modalState

const onFocus = useCallback(() => dispatch({ type: 'focus', id }), [id, dispatch])
const style: React.CSSProperties = useMemo(() => ({ ...modalStyle, top: y, left: x, height }), [
y,
x,
height,
])

const onDragWithID = useCallback(args => dispatch({ type: 'drag', id, ...args }), [
dispatch,
id,
])
const onFocus = useCallback(() => dispatch({ type: 'focus', id }), [id, dispatch])

const onResizeWithID = useCallback(args => dispatch({ type: 'resize', id, ...args }), [
dispatch,
id,
])
const onDragWithID = useCallback(args => dispatch({ type: 'drag', id, ...args }), [
dispatch,
id,
])

const onMouseDrag = useDrag(x, y, onDragWithID)
const onMouseResize = useResize(x, y, width, height, onResizeWithID)
const onResizeWithID = useCallback(args => dispatch({ type: 'resize', id, ...args }), [
dispatch,
id,
])

const titleElement = useMemo(
() => (
<div
className="ant-design-draggable-modal-title"
onMouseDown={onMouseDrag}
onClick={onFocus}
>
{title}
</div>
),
[onMouseDrag, onFocus, title],
)
const onMouseDrag = useDrag(x, y, onDragWithID)
const onMouseResize = useResize(x, y, width, height, onResizeWithID)

return (
<Modal
wrapClassName="ant-design-draggable-modal"
style={style}
width={width}
destroyOnClose={true}
mask={false}
maskClosable={false}
zIndex={zIndex}
title={titleElement}
visible={visible}
{...otherProps}
const titleElement = useMemo(
() => (
<div
className="ant-design-draggable-modal-title"
onMouseDown={onMouseDrag}
onClick={onFocus}
>
{children}
<ResizeHandle onMouseDown={onMouseResize} />
</Modal>
)
},
)
{title}
</div>
),
[onMouseDrag, onFocus, title],
)

return (
<Modal
wrapClassName="ant-design-draggable-modal"
style={style}
width={width}
destroyOnClose={true}
mask={false}
maskClosable={false}
zIndex={zIndex}
title={titleElement}
visible={visible}
{...otherProps}
>
{children}
<ResizeHandle onMouseDown={onMouseResize} />
</Modal>
)
}

DraggableModalInner.displayName = 'DraggableModalInner'
export const DraggableModalInner = memo(DraggableModalInnerNonMemo)

if (process.env.NODE_ENV !== 'production') {
DraggableModalInner.displayName = 'DraggableModalInner'
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export type Action =
| { type: 'hide'; id: ModalID }
| { type: 'focus'; id: ModalID }
| { type: 'unmount'; id: ModalID }
| { type: 'mount'; id: ModalID }
| { type: 'mount'; id: ModalID; intialState: { initialWidth?: number; initialHeight?: number } }
| { type: 'windowResize'; size: { width: number; height: number } }
| { type: 'drag'; id: ModalID; x: number; y: number }
| {
Expand Down Expand Up @@ -225,15 +225,16 @@ export const draggableModalReducer = (state: ModalsState, action: Action): Modal
}
}
case 'mount':
const initialState = getInitialModalState(action.intialState)
return {
...state,
maxZIndex: state.maxZIndex + 1,
modals: {
...state.modals,
[action.id]: {
...initialModalState,
x: state.windowSize.width / 2 - initialModalState.width / 2,
y: state.windowSize.height / 2 - initialModalState.height / 2,
...initialState,
x: state.windowSize.width / 2 - initialState.width / 2,
y: state.windowSize.height / 2 - initialState.height / 2,
zIndex: state.maxZIndex + 1,
},
},
Expand Down
Empty file modified packages/example/.gitignore
100755 → 100644
Empty file.
44 changes: 10 additions & 34 deletions packages/example/README.md
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,36 @@ This project was bootstrapped with [Create React App](https://github.com/faceboo

In the project directory, you can run:

### `npm start`
### `yarn start`

Runs the app in the development mode.<br>
Runs the app in the development mode.<br />
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.<br>
The page will reload if you make edits.<br />
You will also see any lint errors in the console.

### `npm test`
### `yarn test`

Launches the test runner in the interactive watch mode.<br>
Launches the test runner in the interactive watch mode.<br />
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`
### `yarn build`

Builds the app for production to the `build` folder.<br>
Builds the app for production to the `build` folder.<br />
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.<br>
The build is minified and the filenames include the hashes.<br />
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`
### `yarn eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

Expand All @@ -42,27 +42,3 @@ You don’t have to ever use `eject`. The curated feature set is suitable for sm
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting

### Analyzing the Bundle Size

This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size

### Making a Progressive Web App

This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app

### Advanced Configuration

This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration

### Deployment

This section has moved here: https://facebook.github.io/create-react-app/docs/deployment

### `npm run build` fails to minify

This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
43 changes: 26 additions & 17 deletions packages/example/package.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
{
"name": "example",
"version": "0.0.13",
"version": "0.1.0",
"private": true,
"scripts": {
"build": "react-scripts build",
"eject": "react-scripts eject",
"serve": "serve build",
"start": "react-scripts start",
"test": "react-scripts test",
"test-ci": "yarn build && yarn test"
"test": "react-scripts test"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"eslintConfig": {
"extends": "react-app"
},
"dependencies": {
"ant-design-draggable-modal": "file:../ant-design-draggable-modal",
"react": "^16.8.4",
"react-dom": "^16.8.4",
"react-scripts": "^3.4.1"
},
"devDependencies": {
"serve": "^11.3.0"
"@testing-library/jest-dom": "^5.3.0",
"@testing-library/react": "^10.0.2",
"@testing-library/user-event": "^10.0.1",
"@types/jest": "^25.2.1",
"@types/node": "^13.11.0",
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",
"ant-design-draggable-modal": "0.0.15",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1",
"typescript": "~3.8.3"
}
}
Binary file modified packages/example/public/favicon.ico
100755 → 100644
Binary file not shown.
Loading

0 comments on commit d5f69d8

Please sign in to comment.