Fixes #11
CI / build-and-test (pull_request) Successful in 1m15s

- Fix dashboard draggin: introduced sophistaced drag handle
- Fix disappearing of charts when dragged inside a dashboard widget
This commit is contained in:
Pit Friedrich
2026-07-26 14:05:11 +02:00
parent 6bd81ff561
commit 9311d494bd
9 changed files with 108 additions and 5 deletions
+20 -1
View File
@@ -59,6 +59,8 @@ function applyThemeOverlay(options: any): any {
export class ApexChart extends LitElement {
private chart?: ApexCharts;
private lastOptions?: any;
private lastOptionsJson?: string;
private destroyTimer?: ReturnType<typeof setTimeout>;
private readonly onThemeChange = () => {
if (!this.chart || !this.lastOptions) return;
@@ -71,7 +73,14 @@ export class ApexChart extends LitElement {
connectedCallback() {
super.connectedCallback();
clearTimeout(this.destroyTimer);
this.destroyTimer = undefined;
window.addEventListener('dialect-theme-change', this.onThemeChange);
// Back after a real teardown (Flow detach, cached view): rebuild, since
// the server only pushes options on setData(), not on re-attach.
if (!this.chart && this.lastOptionsJson) {
void this.renderChart(this.lastOptionsJson);
}
}
render() {
@@ -80,6 +89,7 @@ export class ApexChart extends LitElement {
async renderChart(optionsJson: string) {
await this.updateComplete;
this.lastOptionsJson = optionsJson;
const options = JSON.parse(optionsJson);
options.chart = {
@@ -106,6 +116,15 @@ export class ApexChart extends LitElement {
disconnectedCallback() {
super.disconnectedCallback();
window.removeEventListener('dialect-theme-change', this.onThemeChange);
this.chart?.destroy();
// gridstack's _sortDom() re-appends item elements after every
// move/resize, which disconnects and immediately reconnects this
// element within the same task — destroying the chart synchronously
// would blank it with nothing to trigger a re-render. Defer past the
// current task and bail out if we came back.
this.destroyTimer = setTimeout(() => {
if (this.isConnected) return;
this.chart?.destroy();
this.chart = undefined;
}, 0);
}
}