support instance without props

This commit is contained in:
Oleg Isonen committed 2022-04-11 23:51:55 +01:00
1 parent 4ec7f07967
commit 4af3509271
1 file changed
+7 -4
+7 -4
View File
@@ -8,8 +8,8 @@ import { cloneInstance } from "~/shared/tree-utils";
import { cloneProps } from "~/shared/props-utils";
import { publish } from "./pubsub";
let currentInstance: Instance;
let currentProps: InstanceProps;
let currentInstance: Instance | undefined;
let currentProps: InstanceProps | undefined;
export const copy = () => {
if (selectedInstanceContainer.value === undefined) return;
@@ -20,11 +20,14 @@ export const copy = () => {
export const paste = () => {
if (currentInstance === undefined) return;
const instance = cloneInstance(currentInstance);
publish<"insertInstance", { instance: Instance; props: InstanceProps }>({
const props = currentProps
? cloneProps(currentProps, { instanceId: instance.id })
: undefined;
publish<"insertInstance", { instance: Instance; props?: InstanceProps }>({
type: "insertInstance",
payload: {
instance,
props: cloneProps(currentProps, { instanceId: instance.id }),
props,
},
});
};