22 lines
602 B
TypeScript
22 lines
602 B
TypeScript
import type { Config, Widget } from "./schema";
|
|||
|
|
|
||
|
|
export interface WidgetInstance {
|
||
|
|
id: string;
|
||
|
|
groupName: string;
|
||
|
|
widget: Widget;
|
||
|
|
}
|
||
|
|
|
||
|
|
export function widgetId(groupIndex: number, widgetIndex: number): string {
|
||
|
|
return `${groupIndex}:${widgetIndex}`;
|
||
|
|
}
|
||
|
|
|
||
|
|
export function flattenWidgets(config: Config): WidgetInstance[] {
|
||
|
|
const instances: WidgetInstance[] = [];
|
||
|
|
config.groups.forEach((group, groupIndex) => {
|
||
|
|
group.widgets.forEach((widget, widgetIndex) => {
|
||
|
|
instances.push({ id: widgetId(groupIndex, widgetIndex), groupName: group.name, widget });
|
||
|
|
});
|
||
|
|
});
|
||
|
|
return instances;
|
||
|
|
}
|