Skip to content

Commit

Permalink
chore: prettier all code
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed May 4, 2024
1 parent 9513334 commit 9bc5241
Show file tree
Hide file tree
Showing 25 changed files with 170 additions and 154 deletions.
2 changes: 1 addition & 1 deletion .fatherrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export default defineConfig({
output: 'es',
alias: { 'rc-util/lib': 'rc-util/es' },
},
});
});
19 changes: 3 additions & 16 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,8 @@ MIT LICENSE

Copyright (c) 2015-present Alipay.com, https://www.alipay.com/

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 changes: 4 additions & 5 deletions docs/examples/basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as React from 'react';
import '../../assets/index.less';
import { defaultIcons } from './common';


export default function Base() {
return (
<div>
Expand All @@ -21,7 +20,7 @@ export default function Base() {
onVisibleChange: visible => {
console.log('visible', visible);
},
zIndex: 9999
zIndex: 9999,
}}
/>

Expand All @@ -39,19 +38,19 @@ export default function Base() {
style={{
marginRight: 24,
}}
preview={{icons: defaultIcons}}
preview={{ icons: defaultIcons }}
/>
<Image
src="https://gw.alipayobjects.com/mdn/rms_08e378/afts/img/A*NZuwQp_vcIQAAAAAAAAAAABkARQnAQ"
width={200}
preview={{icons: defaultIcons}}
preview={{ icons: defaultIcons }}
/>

<Image
src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png"
width={200}
height={100}
preview={{icons: defaultIcons}}
preview={{ icons: defaultIcons }}
/>
</div>
);
Expand Down
45 changes: 22 additions & 23 deletions docs/examples/common.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@

import React from 'react';
import type { PreviewProps } from '@/Preview';
import {
CloseOutlined,
LeftOutlined,
RightOutlined,
RotateLeftOutlined,
RotateRightOutlined,
SwapOutlined,
ZoomInOutlined,
ZoomOutOutlined,
} from '@ant-design/icons';

export const defaultIcons: PreviewProps['icons'] = {
rotateLeft: <RotateLeftOutlined />,
rotateRight: <RotateRightOutlined />,
zoomIn: <ZoomInOutlined />,
zoomOut: <ZoomOutOutlined />,
close: <CloseOutlined />,
left: <LeftOutlined />,
right: <RightOutlined />,
flipX: <SwapOutlined />,
flipY: <SwapOutlined rotate={90} />,
};
CloseOutlined,
LeftOutlined,
RightOutlined,
RotateLeftOutlined,
RotateRightOutlined,
SwapOutlined,
ZoomInOutlined,
ZoomOutOutlined,
} from '@ant-design/icons';
import React from 'react';

export const defaultIcons: PreviewProps['icons'] = {
rotateLeft: <RotateLeftOutlined />,
rotateRight: <RotateRightOutlined />,
zoomIn: <ZoomInOutlined />,
zoomOut: <ZoomOutOutlined />,
close: <CloseOutlined />,
left: <LeftOutlined />,
right: <RightOutlined />,
flipX: <SwapOutlined />,
flipY: <SwapOutlined rotate={90} />,
};
2 changes: 1 addition & 1 deletion docs/examples/controlled.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import Image from 'rc-image';
import * as React from 'react';
import '../../assets/index.less';
import { defaultIcons } from './common';

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/controlledWithGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable global-require */
import * as React from 'react';
import Image from 'rc-image';
import * as React from 'react';
import '../../assets/index.less';
import { defaultIcons } from './common';

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/fallback.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import Image from 'rc-image';
import * as React from 'react';
import '../../assets/index.less';
import { defaultIcons } from './common';

Expand Down
6 changes: 3 additions & 3 deletions docs/examples/placeholder.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import Image from 'rc-image';
import * as React from 'react';
import '../../assets/index.less';
import { defaultIcons } from './common';

Expand All @@ -22,7 +22,7 @@ export default function Base() {
src={`${require('./images/placeholder.png')}?random=${random}`}
width={400}
placeholder
preview={{icons: defaultIcons}}
preview={{ icons: defaultIcons }}
/>
</div>

Expand All @@ -32,7 +32,7 @@ export default function Base() {
// eslint-disable-next-line global-require
src={`${require('./images/placeholder.png')}?random=${random + 1}`}
width={400}
preview={{icons: defaultIcons}}
preview={{ icons: defaultIcons }}
placeholder={
<Image
width="100%"
Expand Down
7 changes: 3 additions & 4 deletions docs/examples/thumbnail.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import Image from 'rc-image';
import * as React from 'react';
import '../../assets/index.less';
import { defaultIcons } from './common';

Expand All @@ -17,7 +17,7 @@ export default function Thumbnail() {

<br />
<h1>PreviewGroup</h1>
<Image.PreviewGroup preview={{icons: defaultIcons}}>
<Image.PreviewGroup preview={{ icons: defaultIcons }}>
<Image
key={1}
src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png?x-oss-process=image/auto-orient,1/resize,p_10/quality,q_10"
Expand All @@ -30,8 +30,7 @@ export default function Thumbnail() {
key={2}
src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png?x-oss-process=image/auto-orient,1/resize,p_10/quality,q_10/contrast,-100"
preview={{
src:
'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png?x-oss-process=image/auto-orient,1/contrast,-100',
src: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png?x-oss-process=image/auto-orient,1/contrast,-100',
}}
width={200}
/>
Expand Down
4 changes: 1 addition & 3 deletions now.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@
"config": { "distDir": "dist" }
}
],
"routes": [
{ "src": "/(.*)", "dest": "/dist/$1" }
]
"routes": [{ "src": "/(.*)", "dest": "/dist/$1" }]
}
38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
"react-image",
"image"
],
"homepage": "http://github.com/react-component/image",
"bugs": {
"url": "http://github.com/react-component/image/issues"
},
"repository": {
"type": "git",
"url": "git@github.com:react-component/image.git"
},
"license": "MIT",
"main": "./lib/index",
"module": "./es/index",
"types": "./lib/index.d.ts",
Expand All @@ -16,30 +25,17 @@
"es",
"lib"
],
"homepage": "http://github.com/react-component/image",
"repository": {
"type": "git",
"url": "git@github.com:react-component/image.git"
},
"bugs": {
"url": "http://github.com/react-component/image/issues"
},
"license": "MIT",
"scripts": {
"start": "dumi dev",
"compile": "father build && lessc assets/index.less assets/index.css",
"coverage": "rc-test --coverage",
"docs:build": "dumi build",
"docs:deploy": "gh-pages -d docs-dist",
"compile": "father build && lessc assets/index.less assets/index.css",
"prepublishOnly": "npm run compile && np --yolo --no-publish --any-branch",
"lint": "eslint src/ --ext .ts,.tsx,.jsx,.js,.md",
"now-build": "npm run docs:build",
"prepublishOnly": "npm run compile && np --yolo --no-publish --any-branch",
"prettier": "prettier --write \"**/*.{ts,tsx,js,jsx,json,md}\"",
"test": "rc-test",
"coverage": "rc-test --coverage",
"now-build": "npm run docs:build"
},
"peerDependencies": {
"react": ">=16.9.0",
"react-dom": ">=16.9.0"
"start": "dumi dev",
"test": "rc-test"
},
"dependencies": {
"@babel/runtime": "^7.11.2",
Expand Down Expand Up @@ -69,5 +65,9 @@
"react": "^18.0.0",
"react-dom": "^18.0.0",
"typescript": "^5.3.3"
},
"peerDependencies": {
"react": ">=16.9.0",
"react-dom": ">=16.9.0"
}
}
8 changes: 4 additions & 4 deletions src/Image.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import cn from 'classnames';
import type { IDialogPropTypes } from 'rc-dialog/lib/IDialogPropTypes';
import { getOffset } from 'rc-util/lib/Dom/css';
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import type { GetContainer } from 'rc-util/lib/PortalWrapper';
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import * as React from 'react';
import { useContext, useMemo, useState } from 'react';
import type { PreviewProps, ToolbarRenderInfoType } from './Preview';
import Preview from './Preview';
import PreviewGroup from './PreviewGroup';
import { COMMON_PROPS } from './common';
import { PreviewGroupContext } from './context';
import type { TransformType } from './hooks/useImageTransform';
import useRegisterImage from './hooks/useRegisterImage';
import useStatus from './hooks/useStatus';
import type { ImageElementProps } from './interface';
import type { PreviewProps, ToolbarRenderInfoType } from './Preview';
import Preview from './Preview';
import PreviewGroup from './PreviewGroup';

export interface ImgInfo {
url: string;
Expand Down
4 changes: 2 additions & 2 deletions src/Operations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import CSSMotion from 'rc-motion';
import KeyCode from 'rc-util/lib/KeyCode';
import * as React from 'react';
import { useContext } from 'react';
import type { ImgInfo } from './Image';
import type { PreviewProps, ToolbarRenderInfoType } from './Preview';
import { PreviewGroupContext } from './context';
import type { TransformType } from './hooks/useImageTransform';
import type { PreviewProps, ToolbarRenderInfoType } from './Preview';
import type { ImgInfo } from './Image';

interface OperationsProps
extends Pick<
Expand Down
6 changes: 3 additions & 3 deletions src/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import Dialog from 'rc-dialog';
import addEventListener from 'rc-util/lib/Dom/addEventListener';
import KeyCode from 'rc-util/lib/KeyCode';
import React, { useContext, useEffect, useRef, useState } from 'react';
import type { ImgInfo } from './Image';
import Operations from './Operations';
import { PreviewGroupContext } from './context';
import type { TransformAction, TransformType } from './hooks/useImageTransform';
import useImageTransform from './hooks/useImageTransform';
import useMouseEvent from './hooks/useMouseEvent';
import useTouchEvent from './hooks/useTouchEvent';
import useStatus from './hooks/useStatus';
import Operations from './Operations';
import useTouchEvent from './hooks/useTouchEvent';
import { BASE_SCALE_RATIO } from './previewConfig';
import type { ImgInfo } from './Image';

export type ToolbarRenderInfoType = {
icons: {
Expand Down
8 changes: 4 additions & 4 deletions src/PreviewGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import * as React from 'react';
import { useState } from 'react';
import { type ImagePreviewType } from './Image';
import type { PreviewProps, ToolbarRenderInfoType } from './Preview';
import Preview from './Preview';
import { PreviewGroupContext } from './context';
import type { TransformType } from './hooks/useImageTransform';
import usePreviewItems from './hooks/usePreviewItems';
import { type ImagePreviewType } from './Image';
import type { ImageElementProps, OnGroupPreview } from './interface';
import type { PreviewProps, ToolbarRenderInfoType } from './Preview';
import Preview from './Preview';

export interface PreviewGroupPreview
extends Omit<
ImagePreviewType,
| 'mask' | 'maskClassName' | 'onVisibleChange' | 'toolbarRender' | 'imageRender'
'mask' | 'maskClassName' | 'onVisibleChange' | 'toolbarRender' | 'imageRender'
> {
/**
* If Preview the show img index
Expand Down
8 changes: 7 additions & 1 deletion src/hooks/useImageTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ export default function useImageTransform(
};

/** Scale according to the position of centerX and centerY */
const dispatchZoomChange: DispatchZoomChangeFunc = (ratio, action, centerX?, centerY?, isTouch?) => {
const dispatchZoomChange: DispatchZoomChangeFunc = (
ratio,
action,
centerX?,
centerY?,
isTouch?,
) => {
const { width, height, offsetWidth, offsetHeight, offsetLeft, offsetTop } = imgRef.current;

let newRatio = ratio;
Expand Down
Loading

0 comments on commit 9bc5241

Please sign in to comment.