|
@@ -1,5 +1,5 @@
|
|
import { useInstanceCreator } from '/@/core'
|
|
import { useInstanceCreator } from '/@/core'
|
|
-import { App, ref, Component, Ref } from 'vue'
|
|
|
|
|
|
+import { App, ref, Component, Ref, provide } from 'vue'
|
|
import * as THREE from 'three'
|
|
import * as THREE from 'three'
|
|
import { TresCatalogue } from '/@/types'
|
|
import { TresCatalogue } from '/@/types'
|
|
|
|
|
|
@@ -8,20 +8,26 @@ const catalogue: Ref<TresCatalogue> = ref({ ...THREE })
|
|
delete catalogue.value.Scene
|
|
delete catalogue.value.Scene
|
|
|
|
|
|
let localApp: App
|
|
let localApp: App
|
|
-
|
|
|
|
export function useCatalogue(app?: App, prefix = 'Tres') {
|
|
export function useCatalogue(app?: App, prefix = 'Tres') {
|
|
if (!localApp && app) {
|
|
if (!localApp && app) {
|
|
localApp = app
|
|
localApp = app
|
|
}
|
|
}
|
|
const { createComponentInstances } = useInstanceCreator(prefix)
|
|
const { createComponentInstances } = useInstanceCreator(prefix)
|
|
|
|
|
|
|
|
+ provide('catalogue', catalogue)
|
|
|
|
+
|
|
const extend = (objects: any) => {
|
|
const extend = (objects: any) => {
|
|
catalogue.value = Object.assign(catalogue.value, objects)
|
|
catalogue.value = Object.assign(catalogue.value, objects)
|
|
const components = createComponentInstances(ref(objects))
|
|
const components = createComponentInstances(ref(objects))
|
|
|
|
|
|
- components.forEach(([key, cmp]) => {
|
|
|
|
- localApp.component(key as string, cmp as Component)
|
|
|
|
- })
|
|
|
|
|
|
+ if (localApp) {
|
|
|
|
+ components.forEach(([key, cmp]) => {
|
|
|
|
+ // If the component is not already registered, register it
|
|
|
|
+ if (!localApp._context.components[key as string]) {
|
|
|
|
+ localApp.component(key as string, cmp as Component)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
return {
|
|
return {
|