From fd8bfd4585259655f2e95c0157b57604b5d220c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81kos=20Fekete?= Date: Fri, 7 Jul 2023 08:46:16 +0200 Subject: [PATCH] Do not remove subgrid when updating widget content --- src/gridstack.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/gridstack.ts b/src/gridstack.ts index acdfe743d..442b98702 100644 --- a/src/gridstack.ts +++ b/src/gridstack.ts @@ -1192,10 +1192,16 @@ export class GridStack { // check for content changing if (w.content) { - let sub = el.querySelector('.grid-stack-item-content'); - if (sub && sub.innerHTML !== w.content) { - sub.innerHTML = w.content; + let toRemove = el.querySelectorAll('.grid-stack-item-content > :not(.grid-stack-nested, style)'); + const subGrid = el.querySelector('.grid-stack-item-content > .grid-stack-nested') + const itemContent = el.querySelector('.grid-stack-item-content'); + if (toRemove) { + toRemove.forEach(child => itemContent.removeChild(child)); } + const tempEl = document.createElement("div"); + tempEl.innerHTML = w.content; + tempEl.childNodes.forEach(childNode => itemContent.insertBefore(childNode, subGrid)); + delete w.content; }