{
+ e.clipboardData.setData(
+ "text/plain",
+ JSON.stringify(elements.filter(element => element.isSelected))
+ );
+ deleteSelectedElements();
+ this.forceUpdate();
+ e.preventDefault();
+ }}
+ onCopy={e => {
+ e.clipboardData.setData(
+ "text/plain",
+ JSON.stringify(elements.filter(element => element.isSelected))
+ );
+ e.preventDefault();
+ }}
+ onPaste={e => {
+ const paste = e.clipboardData.getData("text");
+ let parsedElements;
+ try {
+ parsedElements = JSON.parse(paste);
+ } catch (e) {}
+ if (
+ Array.isArray(parsedElements) &&
+ parsedElements.length > 0 &&
+ parsedElements[0].type // need to implement a better check here...
+ ) {
+ clearSelection();
+ parsedElements.forEach(parsedElement => {
+ parsedElement.x += 10;
+ parsedElement.y += 10;
+ generateDraw(
+ parsedElement,
+ this.state.itemStrokeColor,
+ this.state.itemBackgroundColor
+ );
+ elements.push(parsedElement);
+ });
+ this.forceUpdate();
+ }
+ e.preventDefault();
+ }}
+ >
-
{
- e.clipboardData.setData(
- "text/plain",
- JSON.stringify(elements.filter(element => element.isSelected))
- );
- deleteSelectedElements();
- drawScene();
- e.preventDefault();
- }}
- onCopy={e => {
- e.clipboardData.setData(
- "text/plain",
- JSON.stringify(elements.filter(element => element.isSelected))
- );
- e.preventDefault();
- }}
- onPaste={e => {
- const paste = e.clipboardData.getData("text");
- let parsedElements;
- try {
- parsedElements = JSON.parse(paste);
- } catch (e) {}
- if (
- Array.isArray(parsedElements) &&
- parsedElements.length > 0 &&
- parsedElements[0].type // need to implement a better check here...
- ) {
- clearSelection();
- parsedElements.forEach(parsedElement => {
- parsedElement.x += 10;
- parsedElement.y += 10;
- generateDraw(
- parsedElement,
- this.state.itemStrokeColor,
- this.state.itemBackgroundColor
- );
- elements.push(parsedElement);
+
+
+ this.forceUpdate();
+ }}
+ />
- >
+
);
}
+
componentDidUpdate() {
const fillStyle = context.fillStyle;
context.fillStyle = this.state.viewBgColor;
@@ -794,8 +791,4 @@ const context = canvas.getContext("2d")!;
// https://stackoverflow.com/questions/13879322/drawing-a-1px-thick-line-in-canvas-creates-a-2px-thick-line/13879402#comment90766599_13879402
context.translate(0.5, 0.5);
-function drawScene() {
- ReactDOM.render(