From 4361dfbcb7fb77187f7f95704de8ab8bb341b39b Mon Sep 17 00:00:00 2001 From: Aliaksandr Bazukevich Date: Wed, 6 Mar 2024 17:21:58 +0100 Subject: [PATCH 1/2] feat(preview): removed 'isolation' marker from preview plugin --- site/views/examples/example/form.njk | 2 +- src/core/preview/preview.tsx | 24 +++++++++--------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/site/views/examples/example/form.njk b/site/views/examples/example/form.njk index a53c5c90..3ecc1cd9 100644 --- a/site/views/examples/example/form.njk +++ b/site/views/examples/example/form.njk @@ -32,7 +32,7 @@ title: Example with form }; - + diff --git a/src/core/preview/preview.tsx b/src/core/preview/preview.tsx index dedefee1..cf4db66d 100644 --- a/src/core/preview/preview.tsx +++ b/src/core/preview/preview.tsx @@ -18,17 +18,13 @@ import type {ESLIntersectionEvent} from '@exadel/esl/modules/esl-event-listener/ */ export class UIPPreview extends UIPPlugin { static is = 'uip-preview'; - static observedAttributes: string[] = ['dir', 'resizable', 'isolation', 'isolation-template']; + static observedAttributes: string[] = ['dir', 'resizable']; /** Sync height with inner iframe content height */ @prop(true) public resizeLoop: boolean; - /** Marker to use iframe isolated rendering */ - @attr({parser: parseBoolean, serializer: toBooleanAttribute}) public isolation: boolean; - /** Marker to use iframe isolated rendering */ + /** Marker to force iframe rerendering */ @attr({parser: parseBoolean, serializer: toBooleanAttribute}) public forceUpdate: boolean; - /** Template to use for isolated rendering */ - @attr({defaultValue: 'default'}) public isolationTemplate: string; protected _iframeResizeRAF: number = 0; @@ -70,15 +66,13 @@ export class UIPPreview extends UIPPlugin { protected override attributeChangedCallback(attrName: string, oldVal: string, newVal: string): void { if (attrName === 'resizable' && newVal === null) this.clearInlineSize(); if (attrName === 'dir') this.updateDir(); - if (attrName === 'isolation' || attrName === 'isolation-template') { - this.$$on(this._onIframeLoad); - this._onRootStateChange(); - } } protected update(e?: UIPChangeEvent): void { - if (!this.isolation) return this.writeContent(); - if (!e || e.jsChanges.length || this.forceUpdate) this.writeContentIsolated(); + const isolated = this.model!.activeSnippet?.isolated || false; + + if (!isolated) return this.writeContent(); + if (!e || this.forceUpdate || e.force) this.writeContentIsolated(); this._onIframeLoad(); } @@ -134,8 +128,7 @@ export class UIPPreview extends UIPPlugin { @listen({ event: 'load', - target: ($this: UIPPreview) => $this.$iframe, - condition: ($this: UIPPreview) => $this.isolation + target: ($this: UIPPreview) => $this.$iframe }) protected _onIframeLoad(): void { if (!this.$iframe.contentWindow) return; @@ -143,7 +136,8 @@ export class UIPPreview extends UIPPlugin { const title = this.model!.activeSnippet?.label || 'UI Playground'; const script = UIPJSRenderingPreprocessors.preprocess(this.model!.js); const content = UIPHTMLRenderingPreprocessors.preprocess(this.model!.html); - const html = UIPRenderingTemplatesService.render(this.isolationTemplate, {title, content, script}); + const isolatedTemplate = this.model!.activeSnippet?.isolatedTemplate || 'default'; + const html = UIPRenderingTemplatesService.render(isolatedTemplate, {title, content, script}); this.$iframe.contentWindow?.document.close(); this.$iframe.contentWindow?.document.write(html); From 60991ebb1ddc079ab63b783df75071bb676bcc20 Mon Sep 17 00:00:00 2001 From: Aliaksandr Bazukevich Date: Wed, 6 Mar 2024 17:23:28 +0100 Subject: [PATCH 2/2] feat(snippet): added 'uip-isolated' marker on snippet to track if it should render in iframe; --- site/views/examples/example/form.njk | 2 +- site/views/examples/example/image.njk | 2 +- src/core/base/model.change.ts | 7 ++++++- src/core/base/model.ts | 9 +++++---- src/core/base/snippet.ts | 11 +++++++++++ 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/site/views/examples/example/form.njk b/site/views/examples/example/form.njk index 3ecc1cd9..1478ab33 100644 --- a/site/views/examples/example/form.njk +++ b/site/views/examples/example/form.njk @@ -5,7 +5,7 @@ title: Example with form -