@studiometa/playground-preview 0.3.5 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/element.js CHANGED
@@ -862,6 +862,7 @@ var PlaygroundPreview = class extends HTMLElement {
862
862
  #scale = DEFAULT_ZOOM;
863
863
  #iframe = null;
864
864
  #observer = null;
865
+ #childObserver = null;
865
866
  #mediaQuery = null;
866
867
  #mediaQueryHandler = null;
867
868
  #isVisible = false;
@@ -885,12 +886,15 @@ var PlaygroundPreview = class extends HTMLElement {
885
886
  this.#readChildContent();
886
887
  this.#render();
887
888
  this.#setupIntersectionObserver();
889
+ this.#setupChildObserver();
888
890
  this.#setupMediaQuery();
889
891
  }
890
892
  disconnectedCallback() {
891
893
  this.#isConnected = false;
892
894
  this.#observer?.disconnect();
893
895
  this.#observer = null;
896
+ this.#childObserver?.disconnect();
897
+ this.#childObserver = null;
894
898
  if (this.#mediaQuery && this.#mediaQueryHandler) {
895
899
  this.#mediaQuery.removeEventListener("change", this.#mediaQueryHandler);
896
900
  this.#mediaQuery = null;
@@ -1097,11 +1101,7 @@ var PlaygroundPreview = class extends HTMLElement {
1097
1101
  }
1098
1102
  #updateIframeSrc() {
1099
1103
  if (!this.#iframe) return;
1100
- const src = this.#buildSrc();
1101
- this.#iframe.classList.add("loading");
1102
- this.#loader?.classList.remove("hidden");
1103
- this.#iframe.src = src;
1104
- this.#updateOpenLink();
1104
+ this.#reloadIframe();
1105
1105
  }
1106
1106
  #updateIframeScale() {
1107
1107
  if (!this.#iframe) return;
@@ -1157,6 +1157,23 @@ var PlaygroundPreview = class extends HTMLElement {
1157
1157
  this.#observer.observe(this);
1158
1158
  }
1159
1159
  // -------------------------------------------------------
1160
+ // Child mutation observer
1161
+ // -------------------------------------------------------
1162
+ #setupChildObserver() {
1163
+ this.#childObserver = new MutationObserver((mutations) => {
1164
+ for (const mutation of mutations) {
1165
+ if (mutation.type === "childList") {
1166
+ this.#readChildContent();
1167
+ if (this.#isVisible) {
1168
+ this.#updateIframeSrc();
1169
+ }
1170
+ break;
1171
+ }
1172
+ }
1173
+ });
1174
+ this.#childObserver.observe(this, { childList: true });
1175
+ }
1176
+ // -------------------------------------------------------
1160
1177
  // Media query (auto theme)
1161
1178
  // -------------------------------------------------------
1162
1179
  #setupMediaQuery() {