2021-04-15 15:59:52 +02:00
|
|
|
// Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
2021-04-08 16:29:28 +02:00
|
|
|
import type { SvelteComponentDev } from "svelte/internal";
|
|
|
|
|
|
|
|
export interface DynamicSvelteComponent<
|
2021-10-19 01:06:00 +02:00
|
|
|
T extends typeof SvelteComponentDev = typeof SvelteComponentDev,
|
2021-04-08 16:29:28 +02:00
|
|
|
> {
|
|
|
|
component: T;
|
2021-04-15 02:32:58 +02:00
|
|
|
[k: string]: unknown;
|
2021-04-08 16:29:28 +02:00
|
|
|
}
|
|
|
|
|
2022-11-28 00:33:04 +01:00
|
|
|
export const dynamicComponent = <
|
|
|
|
Comp extends typeof SvelteComponentDev,
|
|
|
|
DefaultProps = NonNullable<ConstructorParameters<Comp>[0]["props"]>,
|
|
|
|
>(
|
|
|
|
component: Comp,
|
|
|
|
) =>
|
|
|
|
<Props = DefaultProps>(props: Props): DynamicSvelteComponent<Comp> & Props => {
|
|
|
|
return { component, ...props };
|
|
|
|
};
|