mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-14 13:27:13 +00:00
* feat(studio): add design-panel input usage tracking primitive * feat(studio): track input usage in classic inspector panel * feat(studio): track input usage in flat inspector panel * fix(studio): attribute animation meta by field, track classic chrome, widen coverage guard
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import { createContext, useCallback, useContext, useMemo, type ReactNode } from "react";
|
|
import { trackDesignInput, type DesignInputUi } from "../utils/designInputTracking";
|
|
|
|
// Carries which inspector UI and which section the currently-rendered design-panel
|
|
// inputs belong to, so commit sites only pass { control, name } and never thread
|
|
// section/ui through every call. Providers nest: PropertyPanel sets `ui` once at the
|
|
// top; each Section sets `section` and inherits `ui` from the parent.
|
|
|
|
interface DesignPanelInputContextValue {
|
|
ui: DesignInputUi;
|
|
section: string;
|
|
}
|
|
|
|
const DesignPanelInputContext = createContext<DesignPanelInputContextValue>({
|
|
ui: "classic",
|
|
section: "unknown",
|
|
});
|
|
|
|
export function DesignPanelInputProvider({
|
|
ui,
|
|
section,
|
|
children,
|
|
}: {
|
|
ui?: DesignInputUi;
|
|
section?: string;
|
|
children: ReactNode;
|
|
}) {
|
|
const parent = useContext(DesignPanelInputContext);
|
|
const value = useMemo(
|
|
() => ({ ui: ui ?? parent.ui, section: section ?? parent.section }),
|
|
[ui, section, parent.ui, parent.section],
|
|
);
|
|
return (
|
|
<DesignPanelInputContext.Provider value={value}>{children}</DesignPanelInputContext.Provider>
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Returns a stable `track(control, name)` fn bound to the current UI + section.
|
|
* Call it from any input's commit handler.
|
|
*/
|
|
export function useTrackDesignInput(): (control: string, name: string) => void {
|
|
const { ui, section } = useContext(DesignPanelInputContext);
|
|
return useCallback(
|
|
(control: string, name: string) => trackDesignInput({ ui, section, control, name }),
|
|
[ui, section],
|
|
);
|
|
}
|