@pie-element/drawing-response 3.9.8 → 3.9.10-beta.1443
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +381 -0
- package/configure/CHANGELOG.md +363 -0
- package/configure/lib/button.js.map +1 -1
- package/configure/lib/defaults.js +21 -2
- package/configure/lib/defaults.js.map +1 -1
- package/configure/lib/image-container.js +37 -21
- package/configure/lib/image-container.js.map +1 -1
- package/configure/lib/index.js +64 -11
- package/configure/lib/index.js.map +1 -1
- package/configure/lib/root.js +65 -30
- package/configure/lib/root.js.map +1 -1
- package/configure/package.json +4 -4
- package/configure/src/__tests__/__snapshots__/image-container.test.jsx.snap +3 -2
- package/configure/src/__tests__/__snapshots__/root.test.jsx.snap +34 -14
- package/configure/src/__tests__/image-container.test.jsx +42 -35
- package/configure/src/__tests__/index.test.js +7 -7
- package/configure/src/__tests__/root.test.jsx +18 -18
- package/configure/src/button.jsx +4 -4
- package/configure/src/defaults.js +24 -5
- package/configure/src/image-container.jsx +80 -59
- package/configure/src/index.js +46 -14
- package/configure/src/root.jsx +71 -63
- package/controller/CHANGELOG.md +20 -0
- package/controller/lib/defaults.js.map +1 -1
- package/controller/lib/index.js +13 -7
- package/controller/lib/index.js.map +1 -1
- package/controller/package.json +1 -1
- package/controller/src/__tests__/index.test.js +29 -19
- package/controller/src/defaults.js +2 -2
- package/controller/src/index.js +13 -14
- package/docs/config-schema.json +126 -0
- package/docs/config-schema.json.md +97 -1
- package/docs/demo/config.js +2 -2
- package/docs/demo/generate.js +4 -2
- package/docs/demo/session.js +4 -4
- package/docs/pie-schema.json +60 -0
- package/docs/pie-schema.json.md +44 -0
- package/lib/drawing-response/button.js.map +1 -1
- package/lib/drawing-response/constants.js.map +1 -1
- package/lib/drawing-response/container.js +73 -22
- package/lib/drawing-response/container.js.map +1 -1
- package/lib/drawing-response/drawable-image.js +1 -0
- package/lib/drawing-response/drawable-image.js.map +1 -1
- package/lib/drawing-response/drawable-main.js +45 -15
- package/lib/drawing-response/drawable-main.js.map +1 -1
- package/lib/drawing-response/drawable-palette.js +6 -1
- package/lib/drawing-response/drawable-palette.js.map +1 -1
- package/lib/drawing-response/drawable-text.js +15 -5
- package/lib/drawing-response/drawable-text.js.map +1 -1
- package/lib/drawing-response/drawable-transformer.js.map +1 -1
- package/lib/drawing-response/factory.js.map +1 -1
- package/lib/drawing-response/icon.js.map +1 -1
- package/lib/drawing-response/index.js +3 -0
- package/lib/drawing-response/index.js.map +1 -1
- package/lib/index.js +3 -0
- package/lib/index.js.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/drawing-index-test.jsx +4 -4
- package/src/drawing-response/__tests__/__snapshots__/container.test.jsx.snap +174 -290
- package/src/drawing-response/__tests__/__snapshots__/drawing-main.test.jsx.snap +26 -2
- package/src/drawing-response/__tests__/container.test.jsx +9 -2
- package/src/drawing-response/__tests__/drawable-helper.test.jsx +1 -1
- package/src/drawing-response/__tests__/drawing-main.test.jsx +74 -86
- package/src/drawing-response/button.jsx +5 -8
- package/src/drawing-response/constants.js +42 -34
- package/src/drawing-response/container.jsx +93 -70
- package/src/drawing-response/drawable-image.jsx +5 -4
- package/src/drawing-response/drawable-main.jsx +46 -17
- package/src/drawing-response/drawable-palette.jsx +18 -35
- package/src/drawing-response/drawable-text.jsx +34 -48
- package/src/drawing-response/drawable-transformer.jsx +3 -1
- package/src/drawing-response/factory.js +3 -11
- package/src/drawing-response/icon.jsx +19 -20
- package/src/drawing-response/index.jsx +9 -15
- package/src/index.js +8 -11
|
@@ -5,14 +5,14 @@ import { ImageContainer } from '../image-container';
|
|
|
5
5
|
|
|
6
6
|
jest.mock('@pie-lib/config-ui', () => ({
|
|
7
7
|
settings: {
|
|
8
|
-
Panel: props => <div {...props} />,
|
|
8
|
+
Panel: (props) => <div {...props} />,
|
|
9
9
|
toggle: jest.fn(),
|
|
10
10
|
radio: jest.fn(),
|
|
11
|
-
dropdown: jest.fn()
|
|
11
|
+
dropdown: jest.fn(),
|
|
12
12
|
},
|
|
13
13
|
layout: {
|
|
14
|
-
ConfigLayout: props => <div>{props.children}</div
|
|
15
|
-
}
|
|
14
|
+
ConfigLayout: (props) => <div>{props.children}</div>,
|
|
15
|
+
},
|
|
16
16
|
}));
|
|
17
17
|
|
|
18
18
|
describe('ImageContainer', () => {
|
|
@@ -25,7 +25,7 @@ describe('ImageContainer', () => {
|
|
|
25
25
|
classes: {},
|
|
26
26
|
imageUrl: 'url',
|
|
27
27
|
onUpdateImageDimension,
|
|
28
|
-
onImageUpload
|
|
28
|
+
onImageUpload,
|
|
29
29
|
};
|
|
30
30
|
wrapper = () => shallow(<ImageContainer {...props} />);
|
|
31
31
|
});
|
|
@@ -73,30 +73,32 @@ describe('ImageContainer', () => {
|
|
|
73
73
|
w.instance().handleOnDrop({
|
|
74
74
|
preventDefault: jest.fn(),
|
|
75
75
|
dataTransfer: {
|
|
76
|
-
items: [
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
items: [
|
|
77
|
+
{
|
|
78
|
+
kind: 'file',
|
|
79
|
+
getAsFile: jest.fn().mockReturnValue({ type: 'image', key: 'item' }),
|
|
80
|
+
},
|
|
80
81
|
],
|
|
81
|
-
files: []
|
|
82
|
-
}
|
|
82
|
+
files: [],
|
|
83
|
+
},
|
|
83
84
|
});
|
|
84
85
|
|
|
85
86
|
expect(onImageUpload).toBeCalledWith({ type: 'image', key: 'item' });
|
|
86
87
|
expect(onImageUpload).toHaveBeenCalledTimes(3);
|
|
87
88
|
});
|
|
88
89
|
|
|
89
|
-
it(
|
|
90
|
+
it("handleOnDrop calls handleFileRead which doesn't call onImageUpload if item is file but not image", () => {
|
|
90
91
|
w.instance().handleOnDrop({
|
|
91
92
|
preventDefault: jest.fn(),
|
|
92
93
|
dataTransfer: {
|
|
93
|
-
items: [
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
items: [
|
|
95
|
+
{
|
|
96
|
+
kind: 'file',
|
|
97
|
+
getAsFile: jest.fn().mockReturnValue({ type: 'jpg' }),
|
|
98
|
+
},
|
|
97
99
|
],
|
|
98
|
-
files: []
|
|
99
|
-
}
|
|
100
|
+
files: [],
|
|
101
|
+
},
|
|
100
102
|
});
|
|
101
103
|
|
|
102
104
|
// same times number as in previous test, meaning that is was not called again
|
|
@@ -107,30 +109,32 @@ describe('ImageContainer', () => {
|
|
|
107
109
|
w.instance().handleOnDrop({
|
|
108
110
|
preventDefault: jest.fn(),
|
|
109
111
|
dataTransfer: {
|
|
110
|
-
items: [
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
items: [
|
|
113
|
+
{
|
|
114
|
+
kind: 'something else',
|
|
115
|
+
getAsFile: jest.fn().mockReturnValue({ type: 'image' }),
|
|
116
|
+
},
|
|
114
117
|
],
|
|
115
|
-
files: [{ type: 'image', key: 'file' }]
|
|
116
|
-
}
|
|
118
|
+
files: [{ type: 'image', key: 'file' }],
|
|
119
|
+
},
|
|
117
120
|
});
|
|
118
121
|
|
|
119
122
|
expect(onImageUpload).toBeCalledWith({ type: 'image', key: 'file' });
|
|
120
123
|
expect(onImageUpload).toHaveBeenCalledTimes(4);
|
|
121
124
|
});
|
|
122
125
|
|
|
123
|
-
it(
|
|
126
|
+
it("handleOnDrop calls handleFileRead which doesn't call onImageUpload if item is not file and file is not image", () => {
|
|
124
127
|
w.instance().handleOnDrop({
|
|
125
128
|
preventDefault: jest.fn(),
|
|
126
129
|
dataTransfer: {
|
|
127
|
-
items: [
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
130
|
+
items: [
|
|
131
|
+
{
|
|
132
|
+
kind: 'something else',
|
|
133
|
+
getAsFile: jest.fn().mockReturnValue({ type: 'image' }),
|
|
134
|
+
},
|
|
131
135
|
],
|
|
132
|
-
files: [{ type: 'something else', key: 'file' }]
|
|
133
|
-
}
|
|
136
|
+
files: [{ type: 'something else', key: 'file' }],
|
|
137
|
+
},
|
|
134
138
|
});
|
|
135
139
|
|
|
136
140
|
// same times number as in previous test, meaning that is was not called again
|
|
@@ -138,16 +142,20 @@ describe('ImageContainer', () => {
|
|
|
138
142
|
});
|
|
139
143
|
|
|
140
144
|
it('handleOnImageLoad calls onUpdateImageDimension', () => {
|
|
141
|
-
w.instance().handleOnImageLoad({
|
|
145
|
+
w.instance().handleOnImageLoad({
|
|
146
|
+
target: { offsetHeight: 50, offsetWidth: 50, naturalWidth: 50, naturalHeight: 50 },
|
|
147
|
+
});
|
|
142
148
|
|
|
143
149
|
expect(onUpdateImageDimension).toHaveBeenCalledWith({
|
|
144
150
|
height: 50,
|
|
145
|
-
width: 50
|
|
151
|
+
width: 50,
|
|
146
152
|
});
|
|
147
153
|
});
|
|
148
154
|
|
|
149
155
|
it('stopResizing calls onUpdateImageDimension', () => {
|
|
150
|
-
w.instance().handleOnImageLoad({
|
|
156
|
+
w.instance().handleOnImageLoad({
|
|
157
|
+
target: { offsetHeight: 50, offsetWidth: 50, naturalWidth: 50, naturalHeight: 50 },
|
|
158
|
+
});
|
|
151
159
|
|
|
152
160
|
expect(onUpdateImageDimension).toHaveBeenCalledWith(w.instance().state.dimensions);
|
|
153
161
|
});
|
|
@@ -157,4 +165,3 @@ describe('ImageContainer', () => {
|
|
|
157
165
|
});
|
|
158
166
|
});
|
|
159
167
|
});
|
|
160
|
-
|
|
@@ -4,13 +4,13 @@ import { shallow } from 'enzyme';
|
|
|
4
4
|
|
|
5
5
|
jest.mock('@pie-lib/config-ui', () => ({
|
|
6
6
|
choiceUtils: {
|
|
7
|
-
firstAvailableIndex: jest.fn()
|
|
7
|
+
firstAvailableIndex: jest.fn(),
|
|
8
8
|
},
|
|
9
9
|
settings: {
|
|
10
|
-
Panel: props => <div {...props} />,
|
|
10
|
+
Panel: (props) => <div {...props} />,
|
|
11
11
|
toggle: jest.fn(),
|
|
12
|
-
radio: jest.fn()
|
|
13
|
-
}
|
|
12
|
+
radio: jest.fn(),
|
|
13
|
+
},
|
|
14
14
|
}));
|
|
15
15
|
|
|
16
16
|
const model = () => ({
|
|
@@ -19,12 +19,12 @@ const model = () => ({
|
|
|
19
19
|
imageUrl: '',
|
|
20
20
|
imageDimensions: {
|
|
21
21
|
height: 0,
|
|
22
|
-
width: 0
|
|
23
|
-
}
|
|
22
|
+
width: 0,
|
|
23
|
+
},
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
jest.mock('react-dom', () => ({
|
|
27
|
-
render: jest.fn()
|
|
27
|
+
render: jest.fn(),
|
|
28
28
|
}));
|
|
29
29
|
|
|
30
30
|
describe('index', () => {
|
|
@@ -6,14 +6,14 @@ import defaults from '../defaults';
|
|
|
6
6
|
|
|
7
7
|
jest.mock('@pie-lib/config-ui', () => ({
|
|
8
8
|
settings: {
|
|
9
|
-
Panel: props => <div {...props} />,
|
|
9
|
+
Panel: (props) => <div {...props} />,
|
|
10
10
|
toggle: jest.fn(),
|
|
11
11
|
radio: jest.fn(),
|
|
12
|
-
dropdown: jest.fn()
|
|
12
|
+
dropdown: jest.fn(),
|
|
13
13
|
},
|
|
14
14
|
layout: {
|
|
15
|
-
ConfigLayout: props => <div>{props.children}</div
|
|
16
|
-
}
|
|
15
|
+
ConfigLayout: (props) => <div>{props.children}</div>,
|
|
16
|
+
},
|
|
17
17
|
}));
|
|
18
18
|
|
|
19
19
|
const model = {
|
|
@@ -22,8 +22,8 @@ const model = {
|
|
|
22
22
|
imageUrl: '',
|
|
23
23
|
imageDimensions: {
|
|
24
24
|
height: 100,
|
|
25
|
-
width: 100
|
|
26
|
-
}
|
|
25
|
+
width: 100,
|
|
26
|
+
},
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
describe('Root', () => {
|
|
@@ -58,37 +58,37 @@ describe('Root', () => {
|
|
|
58
58
|
it('onPromptChanged calls onModelChanged', () => {
|
|
59
59
|
w.instance().onPromptChanged('New Prompt');
|
|
60
60
|
|
|
61
|
-
expect(onModelChanged).toHaveBeenCalledWith(
|
|
62
|
-
expect.objectContaining({ prompt: 'New Prompt' }))
|
|
61
|
+
expect(onModelChanged).toHaveBeenCalledWith(expect.objectContaining({ prompt: 'New Prompt' }));
|
|
63
62
|
});
|
|
64
63
|
|
|
65
64
|
it('onTeacherInstructionsChanged calls onModelChanged', () => {
|
|
66
65
|
w.instance().onTeacherInstructionsChanged('New Teacher Instructions');
|
|
67
66
|
|
|
68
67
|
expect(onModelChanged).toHaveBeenCalledWith(
|
|
69
|
-
|
|
68
|
+
expect.objectContaining({ teacherInstructions: 'New Teacher Instructions' }),
|
|
69
|
+
);
|
|
70
70
|
});
|
|
71
71
|
|
|
72
72
|
it('onUpdateImageDimension calls onModelChanged', () => {
|
|
73
73
|
w.instance().onUpdateImageDimension({
|
|
74
74
|
height: 200,
|
|
75
|
-
width: 200
|
|
75
|
+
width: 200,
|
|
76
76
|
});
|
|
77
77
|
|
|
78
78
|
expect(onModelChanged).toHaveBeenCalledWith(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
79
|
+
expect.objectContaining({
|
|
80
|
+
imageDimensions: {
|
|
81
|
+
height: 200,
|
|
82
|
+
width: 200,
|
|
83
|
+
},
|
|
84
|
+
}),
|
|
85
|
+
);
|
|
84
86
|
});
|
|
85
87
|
|
|
86
88
|
it('onImageUpload calls onModelChanged', () => {
|
|
87
89
|
w.instance().onImageUpload('url');
|
|
88
90
|
|
|
89
|
-
expect(onModelChanged).toHaveBeenCalledWith(
|
|
90
|
-
expect.objectContaining({ imageUrl: 'url' }))
|
|
91
|
+
expect(onModelChanged).toHaveBeenCalledWith(expect.objectContaining({ imageUrl: 'url' }));
|
|
91
92
|
});
|
|
92
93
|
});
|
|
93
94
|
});
|
|
94
|
-
|
package/configure/src/button.jsx
CHANGED
|
@@ -22,20 +22,20 @@ RawButton.propTypes = {
|
|
|
22
22
|
className: PropTypes.string,
|
|
23
23
|
disabled: PropTypes.bool,
|
|
24
24
|
label: PropTypes.string,
|
|
25
|
-
onClick: PropTypes.func
|
|
25
|
+
onClick: PropTypes.func,
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
RawButton.defaultProps = {
|
|
29
29
|
className: '',
|
|
30
30
|
disabled: false,
|
|
31
31
|
label: 'Add',
|
|
32
|
-
onClick: () => {}
|
|
32
|
+
onClick: () => {},
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
const styles = () => ({
|
|
36
36
|
addButton: {
|
|
37
|
-
marginLeft: 8
|
|
38
|
-
}
|
|
37
|
+
marginLeft: 8,
|
|
38
|
+
},
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
const ButtonStyled = withStyles(styles)(RawButton);
|
|
@@ -4,26 +4,45 @@ export default {
|
|
|
4
4
|
imageUrl: '',
|
|
5
5
|
imageDimensions: {
|
|
6
6
|
height: 0,
|
|
7
|
-
width: 0
|
|
7
|
+
width: 0,
|
|
8
8
|
},
|
|
9
9
|
promptEnabled: true,
|
|
10
10
|
teacherInstructionsEnabled: true,
|
|
11
11
|
studentInstructionsEnabled: true,
|
|
12
|
+
backgroundImageEnabled: true,
|
|
13
|
+
spellCheckEnabled: true,
|
|
12
14
|
toolbarEditorPosition: 'bottom',
|
|
13
15
|
},
|
|
14
16
|
configuration: {
|
|
17
|
+
spellCheck: {
|
|
18
|
+
label: 'Spellcheck',
|
|
19
|
+
settings: false,
|
|
20
|
+
enabled: true,
|
|
21
|
+
},
|
|
15
22
|
backgroundImage: {
|
|
16
23
|
settings: true,
|
|
17
24
|
label: 'Background Image',
|
|
18
|
-
enabled: true
|
|
19
25
|
},
|
|
20
26
|
prompt: {
|
|
21
27
|
settings: true,
|
|
22
|
-
label: 'Prompt'
|
|
28
|
+
label: 'Prompt',
|
|
23
29
|
},
|
|
30
|
+
settingsPanelDisabled: false,
|
|
24
31
|
teacherInstructions: {
|
|
25
32
|
settings: true,
|
|
26
33
|
label: 'Teacher Instructions',
|
|
27
|
-
}
|
|
28
|
-
|
|
34
|
+
},
|
|
35
|
+
maxImageWidth: {
|
|
36
|
+
teacherInstructions: 300,
|
|
37
|
+
prompt: 300,
|
|
38
|
+
},
|
|
39
|
+
maxImageHeight: {
|
|
40
|
+
teacherInstructions: 300,
|
|
41
|
+
prompt: 300,
|
|
42
|
+
},
|
|
43
|
+
withRubric: {
|
|
44
|
+
settings: false,
|
|
45
|
+
label: 'Add Rubric',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
29
48
|
};
|
|
@@ -13,11 +13,11 @@ export class ImageContainer extends Component {
|
|
|
13
13
|
constructor(props) {
|
|
14
14
|
super(props);
|
|
15
15
|
this.state = {
|
|
16
|
-
maxImageWidth:
|
|
17
|
-
maxImageHeight:
|
|
16
|
+
maxImageWidth: '100%',
|
|
17
|
+
maxImageHeight: 'auto',
|
|
18
18
|
dragEnabled: true,
|
|
19
19
|
dropzoneActive: false,
|
|
20
|
-
}
|
|
20
|
+
};
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
componentDidMount() {
|
|
@@ -26,7 +26,7 @@ export class ImageContainer extends Component {
|
|
|
26
26
|
const { height, width } = positionInfo;
|
|
27
27
|
this.setState({
|
|
28
28
|
maxImageWidth: width,
|
|
29
|
-
maxImageHeight: height
|
|
29
|
+
maxImageHeight: height,
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -46,7 +46,7 @@ export class ImageContainer extends Component {
|
|
|
46
46
|
this.handleFileRead(file);
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
makeDropzoneActive= () => this.setState({ dropzoneActive: true });
|
|
49
|
+
makeDropzoneActive = () => this.setState({ dropzoneActive: true });
|
|
50
50
|
|
|
51
51
|
makeDropzoneInactive = () => this.setState({ dropzoneActive: false });
|
|
52
52
|
|
|
@@ -84,15 +84,22 @@ export class ImageContainer extends Component {
|
|
|
84
84
|
handleDisableDrag = () => this.setState({ dragEnabled: false });
|
|
85
85
|
handleInputClick = () => this.input.click();
|
|
86
86
|
|
|
87
|
-
handleOnImageLoad = ({ target: { offsetHeight, offsetWidth } }) => {
|
|
88
|
-
const { onUpdateImageDimension } = this.props;
|
|
87
|
+
handleOnImageLoad = ({ target: { offsetHeight, offsetWidth, naturalHeight, naturalWidth } }) => {
|
|
88
|
+
const { onUpdateImageDimension, imageDimensions } = this.props;
|
|
89
89
|
const resizeHandle = this.resize;
|
|
90
90
|
|
|
91
91
|
const dimensions = {
|
|
92
|
-
height: offsetHeight,
|
|
93
|
-
width: offsetWidth
|
|
92
|
+
height: (imageDimensions && imageDimensions.height) || offsetHeight || naturalHeight,
|
|
93
|
+
width: (imageDimensions && imageDimensions.width) || offsetWidth || naturalWidth,
|
|
94
94
|
};
|
|
95
95
|
|
|
96
|
+
// check if aspect ratio is not respected on replacing image
|
|
97
|
+
const imageAspectRatio = naturalWidth / naturalHeight;
|
|
98
|
+
|
|
99
|
+
if (dimensions.width !== dimensions.height * imageAspectRatio) {
|
|
100
|
+
dimensions.width = dimensions.height * imageAspectRatio;
|
|
101
|
+
}
|
|
102
|
+
|
|
96
103
|
this.setState({ dimensions });
|
|
97
104
|
onUpdateImageDimension(dimensions);
|
|
98
105
|
|
|
@@ -117,20 +124,26 @@ export class ImageContainer extends Component {
|
|
|
117
124
|
|
|
118
125
|
startResizing = (e) => {
|
|
119
126
|
const box = this.image;
|
|
120
|
-
const { maxImageWidth } = this.state;
|
|
127
|
+
const { maxImageWidth, maxImageHeight, dimensions } = this.state;
|
|
121
128
|
|
|
122
129
|
const bounds = e.target.getBoundingClientRect();
|
|
123
130
|
const x = e.clientX - bounds.left;
|
|
124
131
|
const y = e.clientY - bounds.top;
|
|
125
132
|
|
|
126
|
-
const
|
|
133
|
+
const imageAspectRatio = dimensions.width / dimensions.height;
|
|
134
|
+
const fitsContainer = x <= maxImageWidth + 5 && x / imageAspectRatio <= maxImageHeight + 5;
|
|
127
135
|
const hasMinimumWidth = x > 150 && y > 150;
|
|
128
136
|
|
|
129
|
-
if (fitsContainer && hasMinimumWidth) {
|
|
137
|
+
if (fitsContainer && hasMinimumWidth && box) {
|
|
130
138
|
box.style.width = `${x}px`;
|
|
131
|
-
box.style.height = `${
|
|
139
|
+
box.style.height = `${x / imageAspectRatio}px`;
|
|
132
140
|
|
|
133
|
-
this.setState({
|
|
141
|
+
this.setState({
|
|
142
|
+
dimensions: {
|
|
143
|
+
width: x,
|
|
144
|
+
height: x / imageAspectRatio,
|
|
145
|
+
},
|
|
146
|
+
});
|
|
134
147
|
}
|
|
135
148
|
|
|
136
149
|
this.handleDisableDrag();
|
|
@@ -141,60 +154,68 @@ export class ImageContainer extends Component {
|
|
|
141
154
|
|
|
142
155
|
return (
|
|
143
156
|
<div>
|
|
144
|
-
<Button
|
|
145
|
-
label={label}
|
|
146
|
-
onClick={this.handleInputClick}
|
|
147
|
-
/>
|
|
157
|
+
<Button label={label} onClick={this.handleInputClick} />
|
|
148
158
|
<input
|
|
149
159
|
accept="image/*"
|
|
150
160
|
className={classes.input}
|
|
151
161
|
onChange={this.handleUploadImage}
|
|
152
|
-
ref={ref => {
|
|
162
|
+
ref={(ref) => {
|
|
163
|
+
this.input = ref;
|
|
164
|
+
}}
|
|
153
165
|
type="file"
|
|
154
166
|
/>
|
|
155
167
|
</div>
|
|
156
|
-
)
|
|
168
|
+
);
|
|
157
169
|
}
|
|
158
170
|
|
|
159
171
|
render() {
|
|
160
|
-
const {
|
|
161
|
-
|
|
162
|
-
imageUrl
|
|
163
|
-
} = this.props;
|
|
164
|
-
const {
|
|
165
|
-
dropzoneActive,
|
|
166
|
-
dragEnabled,
|
|
167
|
-
maxImageHeight,
|
|
168
|
-
maxImageWidth
|
|
169
|
-
} = this.state;
|
|
172
|
+
const { classes, imageUrl, imageDimensions } = this.props;
|
|
173
|
+
const { dropzoneActive, dragEnabled, maxImageHeight, maxImageWidth } = this.state;
|
|
170
174
|
|
|
171
175
|
return (
|
|
172
|
-
<div className={classes.base}
|
|
173
|
-
<div
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
176
|
+
<div className={classes.base}>
|
|
177
|
+
<div
|
|
178
|
+
className={`${classes.box} ${dropzoneActive ? classes.boxActive : ''}`}
|
|
179
|
+
{...(dragEnabled
|
|
180
|
+
? {
|
|
181
|
+
onDragExit: this.handleOnDragExit,
|
|
182
|
+
onDragLeave: this.handleOnDragExit,
|
|
183
|
+
onDragOver: this.handleOnDragOver,
|
|
184
|
+
onDrop: this.handleOnDrop,
|
|
185
|
+
}
|
|
186
|
+
: {})}
|
|
180
187
|
>
|
|
181
|
-
<div className={classes.toolbar}>
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
188
|
+
<div className={classes.toolbar}>{this.renderUploadControl(imageUrl ? 'Replace Image' : 'Upload Image')}</div>
|
|
189
|
+
|
|
190
|
+
<div
|
|
191
|
+
ref={(ref) => {
|
|
192
|
+
this.imageSection = ref;
|
|
193
|
+
}}
|
|
194
|
+
className={classes.drawableHeight}
|
|
195
|
+
>
|
|
186
196
|
{imageUrl ? (
|
|
187
197
|
<div className={classes.imageContainer}>
|
|
188
198
|
<img
|
|
189
199
|
className={classes.image}
|
|
190
200
|
height="auto"
|
|
191
201
|
onLoad={this.handleOnImageLoad}
|
|
192
|
-
ref={ref => {
|
|
202
|
+
ref={(ref) => {
|
|
203
|
+
this.image = ref;
|
|
204
|
+
}}
|
|
193
205
|
src={imageUrl}
|
|
194
|
-
style={{
|
|
195
|
-
|
|
206
|
+
style={{
|
|
207
|
+
width: imageDimensions && imageDimensions.width ? imageDimensions.width : undefined,
|
|
208
|
+
maxWidth: maxImageWidth,
|
|
209
|
+
maxHeight: maxImageHeight,
|
|
210
|
+
}}
|
|
211
|
+
alt=""
|
|
212
|
+
/>
|
|
213
|
+
<div
|
|
214
|
+
ref={(ref) => {
|
|
215
|
+
this.resize = ref;
|
|
216
|
+
}}
|
|
217
|
+
className={classes.resize}
|
|
196
218
|
/>
|
|
197
|
-
<div ref={ref => { this.resize = ref; }} className={classes.resize} />
|
|
198
219
|
</div>
|
|
199
220
|
) : (
|
|
200
221
|
<div className={`${classes.drawableHeight} ${classes.centered}`}>
|
|
@@ -210,25 +231,25 @@ export class ImageContainer extends Component {
|
|
|
210
231
|
}
|
|
211
232
|
}
|
|
212
233
|
|
|
213
|
-
const styles = theme => ({
|
|
234
|
+
const styles = (theme) => ({
|
|
214
235
|
base: {
|
|
215
|
-
marginTop: theme.spacing.unit * 2
|
|
236
|
+
marginTop: theme.spacing.unit * 2,
|
|
216
237
|
},
|
|
217
238
|
box: {
|
|
218
239
|
border: '1px solid #E0E1E6',
|
|
219
|
-
borderRadius: '5px'
|
|
240
|
+
borderRadius: '5px',
|
|
220
241
|
},
|
|
221
242
|
boxActive: {
|
|
222
|
-
border: '1px solid #0032C2'
|
|
243
|
+
border: '1px solid #0032C2',
|
|
223
244
|
},
|
|
224
245
|
centered: {
|
|
225
246
|
alignItems: 'center',
|
|
226
247
|
display: 'flex',
|
|
227
248
|
flexDirection: 'column',
|
|
228
|
-
justifyContent: 'center'
|
|
249
|
+
justifyContent: 'center',
|
|
229
250
|
},
|
|
230
251
|
drawableHeight: {
|
|
231
|
-
minHeight: 350
|
|
252
|
+
minHeight: 350,
|
|
232
253
|
},
|
|
233
254
|
image: {
|
|
234
255
|
alignItems: 'center',
|
|
@@ -237,7 +258,7 @@ const styles = theme => ({
|
|
|
237
258
|
},
|
|
238
259
|
imageContainer: {
|
|
239
260
|
position: 'relative',
|
|
240
|
-
width: 'fit-content'
|
|
261
|
+
width: 'fit-content',
|
|
241
262
|
},
|
|
242
263
|
resize: {
|
|
243
264
|
borderBottom: '1px solid #727272',
|
|
@@ -247,10 +268,10 @@ const styles = theme => ({
|
|
|
247
268
|
height: '10px',
|
|
248
269
|
position: 'absolute',
|
|
249
270
|
right: '-10px',
|
|
250
|
-
width: '10px'
|
|
271
|
+
width: '10px',
|
|
251
272
|
},
|
|
252
273
|
input: {
|
|
253
|
-
display: 'none'
|
|
274
|
+
display: 'none',
|
|
254
275
|
},
|
|
255
276
|
toolbar: {
|
|
256
277
|
backgroundColor: '#ECEDF1',
|
|
@@ -258,15 +279,15 @@ const styles = theme => ({
|
|
|
258
279
|
borderTopLeftRadius: '5px',
|
|
259
280
|
borderTopRightRadius: '5px',
|
|
260
281
|
display: 'flex',
|
|
261
|
-
padding: '12px 8px'
|
|
262
|
-
}
|
|
282
|
+
padding: '12px 8px',
|
|
283
|
+
},
|
|
263
284
|
});
|
|
264
285
|
|
|
265
286
|
ImageContainer.propTypes = {
|
|
266
287
|
classes: PropTypes.object.isRequired,
|
|
267
288
|
imageUrl: PropTypes.string.isRequired,
|
|
268
289
|
onImageUpload: PropTypes.func.isRequired,
|
|
269
|
-
onUpdateImageDimension: PropTypes.func.isRequired
|
|
290
|
+
onUpdateImageDimension: PropTypes.func.isRequired,
|
|
270
291
|
};
|
|
271
292
|
|
|
272
293
|
export default withStyles(styles)(ImageContainer);
|