Skip to content

Commit

Permalink
Merge branch 'master' into feature
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed Feb 2, 2024
2 parents 0e28360 + c21e948 commit 03b9175
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
12 changes: 7 additions & 5 deletions .dumi/theme/common/DirectionIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ const ltrD =
const rtlD =
'M256 64l512 0 0 128-128 0 0 768-128 0 0-768-128 0 0 768-128 0 0-448c-123.712 0-224-100.288-224-224s100.288-224 224-224zM960 896l-256-224 256-224z';

const DirectionSvg = ({ direction }: any) => (
<svg viewBox="0 0 1024 1024" fill="currentColor">
<path d={direction === 'ltr' ? ltrD : rtlD} />
</svg>
);

const DirectionIcon: React.FC<{ direction: DirectionType; className?: string }> = (props) => (
<Icon {...props}>
<svg viewBox="0 0 1024 1024" fill="currentColor">
<path d={props.direction === 'ltr' ? ltrD : rtlD} />
</svg>
</Icon>
<Icon {...props} component={() => <DirectionSvg direction={props.direction} />} />
);

export default DirectionIcon;
6 changes: 2 additions & 4 deletions components/upload/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,12 @@ const InternalUpload: React.ForwardRefRenderFunction<UploadRef, UploadProps> = (
[`${prefixCls}-disabled`]: mergedDisabled,
});

const renderUploadButton = (uploadButtonStyle?: React.CSSProperties) => (
<div className={uploadButtonCls} style={uploadButtonStyle}>
const uploadButton = (
<div className={uploadButtonCls} style={children ? undefined : { display: 'none' }}>
<RcUpload {...rcUploadProps} ref={upload} />
</div>
);

const uploadButton = renderUploadButton(children ? undefined : { display: 'none' });

if (listType === 'picture-card' || listType === 'picture-circle') {
return wrapCSSVar(
<span className={mergedCls}>{renderUploadList(uploadButton, !!children)}</span>,
Expand Down
15 changes: 9 additions & 6 deletions components/upload/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const isImageUrl = (file: UploadFile): boolean => {
if (file.type && !file.thumbUrl) {
return isImageFileType(file.type);
}
const url: string = (file.thumbUrl || file.url || '') as string;
const url = file.thumbUrl || file.url || '';
const extension = extname(url);
if (
/^data:image\//.test(url) ||
Expand All @@ -76,17 +76,16 @@ export const isImageUrl = (file: UploadFile): boolean => {
const MEASURE_SIZE = 200;

export function previewImage(file: File | Blob): Promise<string> {
return new Promise((resolve) => {
return new Promise<string>((resolve) => {
if (!file.type || !isImageFileType(file.type)) {
resolve('');
return;
}

const canvas = document.createElement('canvas');
canvas.width = MEASURE_SIZE;
canvas.height = MEASURE_SIZE;
canvas.style.cssText = `position: fixed; left: 0; top: 0; width: ${MEASURE_SIZE}px; height: ${MEASURE_SIZE}px; z-index: 9999; display: none;`;
document.body.appendChild(canvas);
document.body.appendChild<HTMLCanvasElement>(canvas);
const ctx = canvas.getContext('2d');
const img = new Image();
img.onload = () => {
Expand Down Expand Up @@ -115,13 +114,17 @@ export function previewImage(file: File | Blob): Promise<string> {
if (file.type.startsWith('image/svg+xml')) {
const reader = new FileReader();
reader.onload = () => {
if (reader.result) img.src = reader.result as string;
if (reader.result && typeof reader.result === 'string') {
img.src = reader.result;
}
};
reader.readAsDataURL(file);
} else if (file.type.startsWith('image/gif')) {
const reader = new FileReader();
reader.onload = () => {
if (reader.result) resolve(reader.result as string);
if (reader.result) {
resolve(reader.result as string);
}
};
reader.readAsDataURL(file);
} else {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
"glob": "^10.3.10",
"html2sketch": "^1.0.2",
"http-server": "^14.1.1",
"husky": "^9.0.7",
"husky": "^9.0.9",
"identity-obj-proxy": "^3.0.0",
"immer": "^10.0.3",
"inquirer": "^9.2.13",
Expand Down Expand Up @@ -317,7 +317,7 @@
"sharp": "^0.33.2",
"simple-git": "^3.22.0",
"size-limit": "^11.0.2",
"stylelint": "^16.2.0",
"stylelint": "^16.2.1",
"stylelint-config-rational-order": "^0.1.2",
"stylelint-config-standard": "^36.0.0",
"stylelint-prettier": "^5.0.0",
Expand Down

0 comments on commit 03b9175

Please sign in to comment.