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
|
|
|
}
|
|
|
|
|
2021-05-26 01:21:33 +02:00
|
|
|
export const dynamicComponent =
|
|
|
|
<
|
|
|
|
Comp extends typeof SvelteComponentDev,
|
2021-10-19 01:06:00 +02:00
|
|
|
DefaultProps = NonNullable<ConstructorParameters<Comp>[0]["props"]>,
|
2021-05-26 01:21:33 +02:00
|
|
|
>(
|
2021-10-19 01:06:00 +02:00
|
|
|
component: Comp,
|
2021-05-26 01:21:33 +02:00
|
|
|
) =>
|
|
|
|
<Props = DefaultProps>(props: Props): DynamicSvelteComponent<Comp> & Props => {
|
|
|
|
return { component, ...props };
|
|
|
|
};
|