Skip to content

Commit 86bbd8c

Browse files
committed
fixes bug onLoad props
1 parent 9664d74 commit 86bbd8c

File tree

5 files changed

+40
-49
lines changed

5 files changed

+40
-49
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-design-editor",
3-
"version": "0.0.28",
3+
"version": "0.0.29",
44
"description": "Design Editor Tools with React.js + ant.design + fabric.js",
55
"main": "dist/react-design-editor.min.js",
66
"typings": "lib/index.d.ts",

src/components/canvas/Canvas.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ class Canvas extends Component<CanvasProps> {
9797
responsive,
9898
propertiesToInclude,
9999
gridOption,
100-
onLoad,
101100
...other
102101
} = this.props;
103102
const { id } = this.state;
@@ -124,7 +123,6 @@ class Canvas extends Component<CanvasProps> {
124123
defaultOption,
125124
propertiesToInclude: mergedPropertiesToInclude,
126125
gridOption: Object.assign({}, defaultGripOption, gridOption),
127-
onLoad,
128126
...other,
129127
});
130128
this.handler.gridHandler.init();
@@ -136,9 +134,6 @@ class Canvas extends Component<CanvasProps> {
136134
}
137135
}
138136
this.handler.eventHandler.attachEventListener();
139-
if (onLoad) {
140-
onLoad(this.handler, this.canvas);
141-
}
142137
}
143138

144139
componentDidUpdate(prevProps: CanvasProps) {

src/components/canvas/handlers/Handler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ class Handler implements HandlerOptions {
292292
this.init(options);
293293
this.initCallback(options);
294294
this.initHandler(options);
295+
if (this.onLoad) {
296+
this.onLoad(this, this.canvas);
297+
}
295298
}
296299

297300
/**

src/components/imagemap/ImageMapEditor.js

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class ImageMapEditor extends Component {
8989
dataSources: [],
9090
editing: false,
9191
descriptors: {},
92+
objects: undefined,
9293
};
9394

9495
componentDidMount() {
@@ -479,24 +480,16 @@ class ImageMapEditor extends Component {
479480

480481
handlers = {
481482
onChangePreview: checked => {
482-
this.setState(
483-
{
484-
preview: typeof checked === 'object' ? false : checked,
485-
},
486-
() => {
487-
if (this.state.preview) {
488-
const data = this.canvasRef.handler.exportJSON().objects.filter(obj => {
489-
if (!obj.id) {
490-
return false;
491-
}
492-
return true;
493-
});
494-
this.preview.canvasRef.handler.importJSON(data);
495-
return;
496-
}
497-
this.preview.canvasRef.handler.clear();
498-
},
499-
);
483+
const data = this.canvasRef.handler.exportJSON().objects.filter(obj => {
484+
if (!obj.id) {
485+
return false;
486+
}
487+
return true;
488+
});
489+
this.setState({
490+
preview: typeof checked === 'object' ? false : checked,
491+
objects: data,
492+
});
500493
},
501494
onProgress: progress => {
502495
this.setState({
@@ -529,7 +522,7 @@ class ImageMapEditor extends Component {
529522
}
530523
return true;
531524
});
532-
this.canvasRef.handler.importJSON(JSON.stringify(data));
525+
this.canvasRef.handler.importJSON(data);
533526
}
534527
};
535528
reader.onloadend = () => {
@@ -646,6 +639,7 @@ class ImageMapEditor extends Component {
646639
dataSources,
647640
editing,
648641
descriptors,
642+
objects,
649643
} = this.state;
650644
const {
651645
onAdd,
@@ -786,13 +780,11 @@ class ImageMapEditor extends Component {
786780
dataSources={dataSources}
787781
/>
788782
<ImageMapPreview
789-
ref={c => {
790-
this.preview = c;
791-
}}
792783
preview={preview}
793784
onChangePreview={onChangePreview}
794785
onTooltip={onTooltip}
795786
onClick={onClick}
787+
objects={objects}
796788
/>
797789
</div>
798790
);

src/components/imagemap/ImageMapPreview.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,36 @@ class ImageMapPreview extends Component {
1212
onChangePreview: PropTypes.func,
1313
onTooltip: PropTypes.func,
1414
onAction: PropTypes.func,
15+
objects: PropTypes.any,
1516
};
1617

1718
render() {
18-
const { onChangePreview, onTooltip, onClick, preview } = this.props;
19+
const { onChangePreview, onTooltip, onClick, preview, objects } = this.props;
1920
const previewClassName = classnames('rde-preview', { preview });
2021
return (
21-
<div className={previewClassName}>
22-
<div
23-
ref={c => {
24-
this.container = c;
25-
}}
26-
style={{ overvlow: 'hidden', display: 'flex', flex: '1', height: '100%' }}
27-
>
28-
<Canvas
22+
preview && (
23+
<div className={previewClassName}>
24+
<div
2925
ref={c => {
30-
this.canvasRef = c;
26+
this.container = c;
3127
}}
32-
editable={false}
33-
canvasOption={{
34-
backgroundColor: '#f3f3f3',
35-
}}
36-
onTooltip={onTooltip}
37-
onClick={onClick}
38-
/>
39-
<Button className="rde-action-btn rde-preview-close-btn" onClick={onChangePreview}>
40-
<Icon name="times" size={1.5} />
41-
</Button>
28+
style={{ overvlow: 'hidden', display: 'flex', flex: '1', height: '100%' }}
29+
>
30+
<Canvas
31+
editable={false}
32+
canvasOption={{
33+
backgroundColor: '#f3f3f3',
34+
}}
35+
onLoad={handler => handler.importJSON(objects)}
36+
onTooltip={onTooltip}
37+
onClick={onClick}
38+
/>
39+
<Button className="rde-action-btn rde-preview-close-btn" onClick={onChangePreview}>
40+
<Icon name="times" size={1.5} />
41+
</Button>
42+
</div>
4243
</div>
43-
</div>
44+
)
4445
);
4546
}
4647
}

0 commit comments

Comments
 (0)