|
4 | 4 | import { createCustomComponentFn } from '$lib/utils/create-custom-component-fn.js';
|
5 | 5 | import Portal from '$lib/utils/Portal.svelte';
|
6 | 6 |
|
7 |
| - import type { CustomComponentMeta, CustomComponents } from '$lib/types/custom-components.js'; |
| 7 | + import type { CustomComponentMeta } from '$lib/types/custom-components.js'; |
8 | 8 | import type { CalendarApp } from '@schedule-x/calendar';
|
9 | 9 |
|
10 | 10 | export let calendarApp: CalendarApp;
|
11 | 11 |
|
12 |
| - export let timeGridEvent: CustomComponents['timeGridEvent'] | undefined = undefined; |
13 |
| - export let dateGridEvent: CustomComponents['dateGridEvent'] | undefined = undefined; |
14 |
| - export let monthGridEvent: CustomComponents['monthGridEvent'] | undefined = undefined; |
15 |
| - export let monthAgendaEvent: CustomComponents['monthAgendaEvent'] | undefined = undefined; |
16 |
| - export let eventModal: CustomComponents['eventModal'] | undefined = undefined; |
17 |
| - export let headerContentLeftPrepend: CustomComponents['headerContentLeftPrepend'] | undefined = |
18 |
| - undefined; |
19 |
| - export let headerContentLeftAppend: CustomComponents['headerContentLeftAppend'] | undefined = |
20 |
| - undefined; |
21 |
| - export let headerContentRightPrepend: CustomComponents['headerContentRightPrepend'] | undefined = |
22 |
| - undefined; |
23 |
| - export let headerContentRightAppend: CustomComponents['headerContentRightAppend'] | undefined = |
24 |
| - undefined; |
25 |
| - export let headerContent: CustomComponents['headerContent'] | undefined = undefined; |
26 |
| -
|
27 | 12 | let customComponentsMeta: CustomComponentMeta[] = [];
|
28 |
| -
|
29 | 13 | $: wrapperId = randomStringId();
|
30 |
| - $: customComponentsMeta = []; |
31 | 14 |
|
32 | 15 | const setComponent = (component: CustomComponentMeta) => {
|
33 | 16 | const newComponents = [...customComponentsMeta];
|
34 | 17 | const ccid = component.wrapperElement.dataset.ccid;
|
35 |
| - const existingComponent = newComponents.find((c) => c.wrapperElement.dataset.ccid === ccid); |
| 18 | + const existing = newComponents.find((c) => c.wrapperElement.dataset.ccid === ccid); |
36 | 19 |
|
37 |
| - if (existingComponent) { |
38 |
| - newComponents.splice(newComponents.indexOf(existingComponent), 1); |
| 20 | + if (existing) { |
| 21 | + newComponents.splice(newComponents.indexOf(existing), 1); |
39 | 22 | }
|
40 | 23 |
|
41 | 24 | customComponentsMeta = [...newComponents, component];
|
42 | 25 | };
|
43 | 26 |
|
44 | 27 | const setCustomComponentFns = () => {
|
45 |
| - const customComponentsAvailable: { |
46 |
| - name: keyof CustomComponents; |
47 |
| - component: CustomComponents[keyof CustomComponents]; |
48 |
| - }[] = [ |
49 |
| - { name: 'timeGridEvent', component: timeGridEvent }, |
50 |
| - { name: 'dateGridEvent', component: dateGridEvent }, |
51 |
| - { name: 'monthGridEvent', component: monthGridEvent }, |
52 |
| - { name: 'monthAgendaEvent', component: monthAgendaEvent }, |
53 |
| - { name: 'eventModal', component: eventModal }, |
54 |
| - { name: 'headerContentLeftPrepend', component: headerContentLeftPrepend }, |
55 |
| - { name: 'headerContentLeftAppend', component: headerContentLeftAppend }, |
56 |
| - { name: 'headerContentRightPrepend', component: headerContentRightPrepend }, |
57 |
| - { name: 'headerContentRightAppend', component: headerContentRightAppend }, |
58 |
| - { name: 'headerContent', component: headerContent } |
59 |
| - ]; |
60 |
| -
|
61 |
| - customComponentsAvailable.forEach(({ name, component }) => { |
| 28 | + Object.entries($$restProps).forEach(([name, component]) => { |
62 | 29 | if (component) {
|
63 |
| - // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
64 |
| - // @ts-ignore |
65 | 30 | calendarApp._setCustomComponentFn(name, createCustomComponentFn(setComponent, component));
|
66 | 31 | }
|
67 | 32 | });
|
68 | 33 | };
|
69 | 34 |
|
70 | 35 | onMount(() => {
|
71 |
| - setCustomComponentFns(); |
72 |
| -
|
73 | 36 | const wrapper = document.getElementById(wrapperId);
|
74 | 37 | if (!(wrapper instanceof HTMLElement)) {
|
75 | 38 | console.warn('Could not find wrapper element to mount calendar on');
|
76 | 39 | return;
|
77 | 40 | }
|
78 | 41 |
|
| 42 | + setCustomComponentFns(); |
| 43 | +
|
79 | 44 | calendarApp.render(wrapper);
|
80 | 45 | });
|
81 | 46 | </script>
|
|
0 commit comments