mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-08 04:55:06 +09:00
27 lines
730 B
TypeScript
27 lines
730 B
TypeScript
import produce from "immer";
|
|
import { type Instance } from "@webstudio-is/sdk";
|
|
|
|
export const deleteInstanceMutable = (
|
|
instance: Instance,
|
|
instanceId: Instance["id"]
|
|
): boolean => {
|
|
if (instance.id === instanceId) return true;
|
|
|
|
for (const child of instance.children) {
|
|
if (typeof child === "string") continue;
|
|
const shouldDelete = deleteInstanceMutable(child, instanceId);
|
|
if (shouldDelete === true) {
|
|
const index = instance.children.indexOf(child);
|
|
instance.children.splice(index, 1);
|
|
return false;
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
|
|
export const deleteInstance = produce(
|
|
(draftInstance: Instance, instanceId: Instance["id"]) => {
|
|
deleteInstanceMutable(draftInstance, instanceId);
|
|
}
|
|
);
|