Files
pterodactyl-panel/resources/scripts/views/inspector/frames.ts
T
2026-10-12 14:24:49 -04:00

34 lines
820 B
TypeScript

const frames = new Set<HTMLIFrameElement>();
const listeners = new Set<() => void>();
let snapshot: readonly HTMLIFrameElement[] = [];
const publish = () => {
snapshot = [...frames];
for (const listener of listeners) {
listener();
}
};
/** A same-origin frame, such as a workbench preview, whose views the inspector reaches too. */
export function registerInspectableFrame(frame: HTMLIFrameElement): () => void {
frames.add(frame);
publish();
return () => {
frames.delete(frame);
publish();
};
}
export function getInspectableFrames(): readonly HTMLIFrameElement[] {
return snapshot;
}
export function subscribeInspectableFrames(listener: () => void): () => void {
listeners.add(listener);
return () => {
listeners.delete(listener);
};
}