mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-10 06:24:35 +09:00
26 lines
636 B
TypeScript
26 lines
636 B
TypeScript
import { type Instance } from "@webstudio-is/react-sdk";
|
|
import { findInstanceById } from "~/shared/tree-utils";
|
|
|
|
export const getInstanceElementById = (id: Instance["id"]) => {
|
|
return document.getElementById(id);
|
|
};
|
|
|
|
export const getInstanceIdFromElement = (
|
|
element: Element
|
|
): Instance["id"] | undefined => {
|
|
return element.id === "" ? undefined : element.id;
|
|
};
|
|
|
|
export const findInstanceByElement = (
|
|
rootInstance: Instance,
|
|
element: Element
|
|
): Instance | undefined => {
|
|
const id = getInstanceIdFromElement(element);
|
|
|
|
if (id === undefined) {
|
|
return undefined;
|
|
}
|
|
|
|
return findInstanceById(rootInstance, id);
|
|
};
|