11<template >
22 <Teleport
3- : disabled =" ! $el ?. ownerDocument . getElementById ( databoxId ) || ( ! databoxId && ! databoxType && databoxSource === ' default ' ) "
3+ v-if =" ! databoxId || targetReady "
44 :to =" ' #' + databoxId + ' -' + databoxType + ' -' + databoxSource "
5+ :disabled =" ! databoxId "
56 >
67 <div
78 :ref =" widgetId"
@@ -192,6 +193,7 @@ export default {
192193 isSubChart: false ,
193194 isSubLevel: false ,
194195 subTitle: null ,
196+ targetReady: false ,
195197 };
196198 },
197199 watch: {
@@ -207,23 +209,50 @@ export default {
207209 deep: true ,
208210 immediate: true ,
209211 },
212+ targetReady (val ) {
213+ if (val) {
214+ this .$nextTick (() => {
215+ this .resetData ();
216+ this .createChart ();
217+ });
218+ }
219+ },
210220 },
211221 created () {
212222 configureChartDefaults ();
213223 this .chartId = ` dsfr-chart-${ Math .floor (Math .random () * 1000 )} ` ;
214224 this .widgetId = ` dsfr-widget-${ Math .floor (Math .random () * 1000 )} ` ;
215225 },
216226 mounted () {
217- this .resetData ();
218- this .createChart ();
227+ if (! this .databoxId || ! this .databoxType ) {
228+ this .resetData ();
229+ this .createChart ();
230+ } else {
231+ const targetId = ` ${ this .databoxId } -${ this .databoxType } -${ this .databoxSource } ` ;
232+ if (document .getElementById (targetId)) {
233+ this .targetReady = true ;
234+ } else {
235+ this ._targetObserver = new MutationObserver (() => {
236+ if (document .getElementById (targetId)) {
237+ this ._targetObserver .disconnect ();
238+ this .targetReady = true ;
239+ }
240+ });
241+ this ._targetObserver .observe (document .body , { childList: true , subtree: true });
242+ }
243+ }
219244
220- const element = document .documentElement ;
221- element .addEventListener (' dsfr.theme' , (e ) => {
245+ document .documentElement .addEventListener (' dsfr.theme' , (e ) => {
222246 if (this .chartId !== ' ' ) {
223247 this .changeColors (e .detail .theme );
224248 }
225249 });
226250 },
251+ beforeUnmount () {
252+ if (this ._targetObserver ) {
253+ this ._targetObserver .disconnect ();
254+ }
255+ },
227256 methods: {
228257 resetData () {
229258 if (this .chart ) {
0 commit comments