import { $editorKey } from "./types"; export function send(key: string, data: any) { if (import.meta.hot) { import.meta.hot.send(key, data); } } export function sendEditor(evt: string, data: any) { send("needle:editor", { type: evt, data }); } export function addEventListener(evt: string, cb: (data: any) => void) { if (import.meta.hot) { import.meta.hot.on(evt, cb); } } export function notifyPropertyChanged(obj: any, property: string, value: any) { const id = tryGetObjectId(obj); if (id === null || id === undefined) { console.warn("UNKNOWN object", obj); return; } sendEditor("needle:editor:propertyChanged", { id, property, value }); } function tryGetObjectId(obj: any): string | null { if (obj[$editorKey] !== undefined) { return obj[$editorKey]; } return null; }