Files
homarr/packages/widgets/src/index.tsx
T
Meier Lukas 6b1879cbb1 feat: add notebook widget (#294)
* feat: add nestjs replacement, remove nestjs

* feat: add notebook widget

* fix: format issue

* fix: add missing tiptap packages

* refactor: improve structure of table options

* fix: downgrade to tiptap 2.2.5 as not yet supported by mantine/tiptap

* fix: format issue

* fix: deepsource issues

* fix: typecheck issues

* refactor: move default notebook content to seperate file

* fix: format issue
2024-04-13 12:32:55 +02:00

54 lines
1.6 KiB
TypeScript

import type { ComponentType } from "react";
import type { Loader } from "next/dynamic";
import dynamic from "next/dynamic";
import type { WidgetKind } from "@homarr/definitions";
import { Loader as UiLoader } from "@homarr/ui";
import * as app from "./app";
import * as clock from "./clock";
import type { WidgetComponentProps } from "./definition";
import * as iframe from "./iframe";
import type { WidgetImportRecord } from "./import";
import * as notebook from "./notebook";
import * as video from "./video";
import * as weather from "./weather";
export { reduceWidgetOptionsWithDefaultValues } from "./options";
export { WidgetEditModal } from "./modals/widget-edit-modal";
export { useServerDataFor } from "./server/provider";
export { GlobalItemServerDataRunner } from "./server/runner";
export const widgetImports = {
clock,
weather,
app,
notebook,
iframe,
video,
} satisfies WidgetImportRecord;
export type WidgetImports = typeof widgetImports;
export type WidgetImportKey = keyof WidgetImports;
const loadedComponents = new Map<
WidgetKind,
ComponentType<WidgetComponentProps<WidgetKind>>
>();
export const loadWidgetDynamic = <TKind extends WidgetKind>(kind: TKind) => {
const existingComponent = loadedComponents.get(kind);
if (existingComponent) return existingComponent;
const newlyLoadedComponent = dynamic<WidgetComponentProps<TKind>>(
widgetImports[kind].componentLoader as Loader<WidgetComponentProps<TKind>>,
{
loading: () => <UiLoader />,
},
);
loadedComponents.set(kind, newlyLoadedComponent as never);
return newlyLoadedComponent;
};