mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-08 21:15:18 +09:00
19 lines
476 B
TypeScript
19 lines
476 B
TypeScript
import { type Instance } from "@webstudio-is/sdk";
|
|
|
|
export const findInstanceById = (
|
|
instance: Instance,
|
|
id: Instance["id"]
|
|
): Instance | undefined => {
|
|
if (instance.id === id) {
|
|
return instance;
|
|
}
|
|
|
|
if (instance.children !== undefined) {
|
|
for (const child of instance.children) {
|
|
if (typeof child === "string") continue;
|
|
const foundInstance = findInstanceById(child, id);
|
|
if (foundInstance !== undefined) return foundInstance;
|
|
}
|
|
}
|
|
};
|