mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-08 04:55:06 +09:00
20 lines
545 B
TypeScript
20 lines
545 B
TypeScript
import { type Instance } from "@webstudio-is/react-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;
|
|
};
|