2020-01-12 02:22:03 +04:00
|
|
|
import { Action } from "./types";
|
2020-02-24 15:21:13 +01:00
|
|
|
import {
|
|
|
|
isTextElement,
|
|
|
|
isExcalidrawElement,
|
|
|
|
redrawTextBoundingBox,
|
|
|
|
} from "../element";
|
2020-01-19 13:21:33 -08:00
|
|
|
import { KEYS } from "../keys";
|
2020-01-12 02:22:03 +04:00
|
|
|
|
|
|
|
let copiedStyles: string = "{}";
|
|
|
|
|
|
|
|
export const actionCopyStyles: Action = {
|
|
|
|
name: "copyStyles",
|
|
|
|
perform: elements => {
|
|
|
|
const element = elements.find(el => el.isSelected);
|
|
|
|
if (element) {
|
|
|
|
copiedStyles = JSON.stringify(element);
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
},
|
2020-01-21 01:14:10 +02:00
|
|
|
contextItemLabel: "labels.copyStyles",
|
2020-02-01 17:37:22 +01:00
|
|
|
keyTest: event => event[KEYS.META] && event.shiftKey && event.key === "C",
|
2020-01-24 12:04:54 +02:00
|
|
|
contextMenuOrder: 0,
|
2020-01-12 02:22:03 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
export const actionPasteStyles: Action = {
|
|
|
|
name: "pasteStyles",
|
|
|
|
perform: elements => {
|
|
|
|
const pastedElement = JSON.parse(copiedStyles);
|
2020-02-24 15:21:13 +01:00
|
|
|
if (!isExcalidrawElement(pastedElement)) {
|
|
|
|
return { elements };
|
|
|
|
}
|
2020-01-12 02:22:03 +04:00
|
|
|
return {
|
|
|
|
elements: elements.map(element => {
|
|
|
|
if (element.isSelected) {
|
|
|
|
const newElement = {
|
|
|
|
...element,
|
2020-01-12 04:00:00 +04:00
|
|
|
shape: null,
|
2020-01-12 02:22:03 +04:00
|
|
|
backgroundColor: pastedElement?.backgroundColor,
|
|
|
|
strokeWidth: pastedElement?.strokeWidth,
|
|
|
|
strokeColor: pastedElement?.strokeColor,
|
|
|
|
fillStyle: pastedElement?.fillStyle,
|
|
|
|
opacity: pastedElement?.opacity,
|
2020-01-24 12:04:54 +02:00
|
|
|
roughness: pastedElement?.roughness,
|
2020-01-12 02:22:03 +04:00
|
|
|
};
|
|
|
|
if (isTextElement(newElement)) {
|
2020-02-24 15:35:56 +01:00
|
|
|
newElement.font = pastedElement?.font || "20px Virgil";
|
2020-01-12 02:22:03 +04:00
|
|
|
redrawTextBoundingBox(newElement);
|
|
|
|
}
|
|
|
|
return newElement;
|
|
|
|
}
|
|
|
|
return element;
|
2020-01-24 12:04:54 +02:00
|
|
|
}),
|
2020-01-12 02:22:03 +04:00
|
|
|
};
|
|
|
|
},
|
2020-02-05 22:47:10 +04:00
|
|
|
commitToHistory: () => true,
|
2020-01-21 01:14:10 +02:00
|
|
|
contextItemLabel: "labels.pasteStyles",
|
2020-02-01 17:37:22 +01:00
|
|
|
keyTest: event => event[KEYS.META] && event.shiftKey && event.key === "V",
|
2020-01-24 12:04:54 +02:00
|
|
|
contextMenuOrder: 1,
|
2020-01-12 02:22:03 +04:00
|
|
|
};
|