Skip to content
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

ImageEditor now uses Cropper.Js / CamanJS libs (instead of tui-image-editor) #287

Merged
merged 17 commits into from
Nov 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ coverage
yarn-error.log
dist/
build/
packages/webiny-ui/.cache/
packages/demo-api/static/
.changelog
4 changes: 2 additions & 2 deletions packages/webiny-app-admin/src/views/Users/AvatarImage.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// @flow
import * as React from "react";
import { withFileUpload } from "webiny-app/components";
import { withImageUpload } from "webiny-app/components";
import { SingleImageUpload } from "webiny-ui/ImageUpload";

const AvatarImage = props => {
return <SingleImageUpload {...props} />;
};

export default withFileUpload()(AvatarImage);
export default withImageUpload()(AvatarImage);
1 change: 1 addition & 0 deletions packages/webiny-app/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
export * from "./withRouter";
export { withDataList } from "./withDataList";
export { withFileUpload } from "./withFileUpload";
export { withImageUpload } from "./withImageUpload";
export { withConfig } from "./withConfig";
export { withUi } from "./withUi";
export type { WithDataListProps, SearchParams, WithDataListParams } from "./withDataList";
Expand Down
57 changes: 57 additions & 0 deletions packages/webiny-app/src/components/withImageUpload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// @flow
import * as React from "react";
import { compose, withProps } from "recompose";
import { withConfig } from "webiny-app/components";
import { withFileUpload } from "./withFileUpload";

type WithImageUploadOptions = {
multiple?: boolean
};

const fetchImage = file => {
return new Promise(resolve => {
const image = new window.Image();
image.onload = async () => {
resolve();
};
image.src = file.src;
});
};

export const withImageUpload = (options: WithImageUploadOptions = {}): Function => {
return (BaseComponent: typeof React.Component) => {
return compose(
withConfig(),
withProps(props => {
return {
...props,
onChange: async file => {
const { onChange } = props;
if (!onChange) {
return;
}

// Multiple images.
if (options.multiple) {
if (Array.isArray(file)) {
for (let index = 0; index < file.length; index++) {
let current = file[index];
current.src.startsWith("http") && (await fetchImage(current));
}
await onChange(file);
}
return;
}

// Single image.
if (file && file.src.startsWith("http")) {
await fetchImage(file);
}
await onChange(file);
}
};
}),
withFileUpload(options)
)(BaseComponent);
};
};
6 changes: 3 additions & 3 deletions packages/webiny-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@
"@rmwc/typography": "^2.0.0",
"brace": "^0.11.1",
"bytes": "^3.0.0",
"caman": "^4.1.2",
"classnames": "^2.2.6",
"cropperjs": "^1.4.1",
"cropperjs": "^1.4.3",
"downshift": "^2.1.5",
"emotion": "^9.2.6",
"install": "^0.12.1",
"keycode": "^2.2.0",
"load-script": "^1.0.0",
"material-components-web": "^0.39.1",
"nprogress": "^0.2.0",
"nuka-carousel": "^4.3.9",
Expand All @@ -53,7 +54,6 @@
"react-emotion": "^9.2.6",
"react-image": "^1.5.1",
"react-loading-skeleton": "^0.5.0",
"tui-image-editor": "^3.2.0",
"webiny-form": "0.0.0-semantically-released",
"webiny-storybook-utils": "0.0.0-semantically-released"
},
Expand Down
Loading