Skip to content

Commit e18ea78

Browse files
committed
Fix compatibility with future VueJS versions #65
1 parent 954dc8d commit e18ea78

14 files changed

Lines changed: 421 additions & 128 deletions

package-lock.json

Lines changed: 57 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,6 @@
9292
"standard": "^17.1.2",
9393
"storybook": "^10.3.5",
9494
"vite": "^8.0.8",
95-
"vue": "3.5.29"
95+
"vue": "^3.5.32"
9696
}
9797
}

src/components/BarChart.vue

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
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) {

src/components/BarLineChart.vue

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
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"
@@ -235,6 +236,7 @@ export default {
235236
colorBarParse: [],
236237
colorHover: [],
237238
colorBarHover: [],
239+
targetReady: false,
238240
};
239241
},
240242
watch: {
@@ -250,23 +252,50 @@ export default {
250252
deep: true,
251253
immediate: true,
252254
},
255+
targetReady(val) {
256+
if (val) {
257+
this.$nextTick(() => {
258+
this.resetData();
259+
this.createChart();
260+
});
261+
}
262+
},
253263
},
254264
created() {
255265
configureChartDefaults();
256266
this.chartId = `dsfr-chart-${Math.floor(Math.random() * 1000)}`;
257267
this.widgetId = `dsfr-widget-${Math.floor(Math.random() * 1000)}`;
258268
},
259269
mounted() {
260-
this.resetData();
261-
this.createChart();
270+
if (!this.databoxId || !this.databoxType) {
271+
this.resetData();
272+
this.createChart();
273+
} else {
274+
const targetId = `${this.databoxId}-${this.databoxType}-${this.databoxSource}`;
275+
if (document.getElementById(targetId)) {
276+
this.targetReady = true;
277+
} else {
278+
this._targetObserver = new MutationObserver(() => {
279+
if (document.getElementById(targetId)) {
280+
this._targetObserver.disconnect();
281+
this.targetReady = true;
282+
}
283+
});
284+
this._targetObserver.observe(document.body, { childList: true, subtree: true });
285+
}
286+
}
262287
263-
const element = document.documentElement;
264-
element.addEventListener('dsfr.theme', (e) => {
288+
document.documentElement.addEventListener('dsfr.theme', (e) => {
265289
if (this.chartId !== '') {
266290
this.changeColors(e.detail.theme);
267291
}
268292
});
269293
},
294+
beforeUnmount() {
295+
if (this._targetObserver) {
296+
this._targetObserver.disconnect();
297+
}
298+
},
270299
methods: {
271300
resetData() {
272301
if (this.chart) {

0 commit comments

Comments
 (0)