| 1 |
<template> |
| 2 |
<div> |
| 3 |
<component |
| 4 |
:is="BannerComponent" |
| 5 |
v-for="(BannerComponent, index) in bannerComponents" |
| 6 |
:key="index" |
| 7 |
/> |
| 8 |
<RouterView /> |
| 9 |
<IvyChangelogModal /> |
| 10 |
<ProUpgradeDialog /> |
| 11 |
</div> |
| 12 |
</template> |
| 13 |
|
| 14 |
<script setup lang="ts"> |
| 15 |
import { shallowRef, onMounted, markRaw, isReactive } from 'vue' |
| 16 |
import type { Component } from 'vue' |
| 17 |
import IvyChangelogModal from '@/views/_components/changelog/IvyChangelogModal.vue' |
| 18 |
import ProUpgradeDialog from '@/views/_components/dialog/ProUpgradeDialog.vue' |
| 19 |
|
| 20 |
// Allow Pro to inject banner components via hook |
| 21 |
// Use shallowRef to prevent components from being made deeply reactive |
| 22 |
const bannerComponents = shallowRef<Component[]>([]) |
| 23 |
|
| 24 |
onMounted(() => { |
| 25 |
// Apply filter initially |
| 26 |
if (window.IvyForms?.hooks?.applyFilters) { |
| 27 |
const components = window.IvyForms.hooks.applyFilters('ivyforms/app/banner_components', []) |
| 28 |
// Wrap each component with markRaw to prevent reactivity (only if not already raw) |
| 29 |
bannerComponents.value = components.map((comp: Component) => |
| 30 |
isReactive(comp) ? markRaw(comp) : comp, |
| 31 |
) |
| 32 |
} |
| 33 |
|
| 34 |
// Listen for banner refresh events (e.g., when Pro plugin registers banners after mount) |
| 35 |
const refreshBanners = () => { |
| 36 |
if (window.IvyForms?.hooks?.applyFilters) { |
| 37 |
const components = window.IvyForms.hooks.applyFilters('ivyforms/app/banner_components', []) |
| 38 |
// Wrap each component with markRaw to prevent reactivity (only if not already raw) |
| 39 |
bannerComponents.value = components.map((comp: Component) => |
| 40 |
isReactive(comp) ? markRaw(comp) : comp, |
| 41 |
) |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
window.addEventListener('ivyforms:refresh_banners', refreshBanners) |
| 46 |
}) |
| 47 |
</script> |
| 48 |
|