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
|
2023-07-01 08:21:53 +02:00
|
|
|
|
|
|
|
/* eslint
|
|
|
|
@typescript-eslint/no-explicit-any: "off",
|
|
|
|
*/
|
|
|
|
|
|
|
|
import type { SvelteComponent } from "svelte";
|
2021-04-08 16:29:28 +02:00
|
|
|
|
|
|
|
export interface DynamicSvelteComponent<
|
2023-07-01 08:21:53 +02:00
|
|
|
T extends typeof SvelteComponent<any> = typeof SvelteComponent<any>,
|
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 = <
|
2023-07-01 08:21:53 +02:00
|
|
|
Comp extends typeof SvelteComponent<any>,
|
2022-11-28 00:33:04 +01:00
|
|
|
DefaultProps = NonNullable<ConstructorParameters<Comp>[0]["props"]>,
|
|
|
|
>(
|
|
|
|
component: Comp,
|
|
|
|
) =>
|
|
|
|
<Props = DefaultProps>(props: Props): DynamicSvelteComponent<Comp> & Props => {
|
|
|
|
return { component, ...props };
|
|
|
|
};
|