diff --git a/studio/src/editors/merch-card-editor.js b/studio/src/editors/merch-card-editor.js index bdc8231d..65a656e8 100644 --- a/studio/src/editors/merch-card-editor.js +++ b/studio/src/editors/merch-card-editor.js @@ -12,12 +12,15 @@ import { Fragment } from '../aem/fragment.js'; const MODEL_PATH = '/conf/mas/settings/dam/cfm/models/card'; +const merchCardCustomElementPromise = customElements.whenDefined('merch-card'); + class MerchCardEditor extends LitElement { static properties = { refreshing: { state: true, attribute: true }, disabled: { state: true, attribute: true }, hasChanges: { state: true, attribute: true }, loading: { state: true, attribute: true }, + superWide: { type: Boolean, state: true }, }; createRenderRoot() { @@ -30,6 +33,7 @@ class MerchCardEditor extends LitElement { this.refreshing = false; this.hasChanges = false; this.loading = false; + this.superWide = false; this.handleKeyDown = this.handleKeyDown.bind(this); this.close = this.close.bind(this); this.discardChanges = this.discardChanges.bind(this); @@ -167,6 +171,28 @@ class MerchCardEditor extends LitElement { ); } + updated() { + this.toggleFields(); + } + + async toggleFields() { + if (!this.fragment) return; + const merchCardCustomElement = await merchCardCustomElementPromise; + if (!merchCardCustomElement) return; + this.querySelectorAll('sp-field-group.toggle').forEach((field) => { + field.style.display = 'none'; + }); + const variant = merchCardCustomElement.getFragmentMapping( + this.fragment.variant, + ); + if (!variant) return; + Object.keys(variant).forEach((key) => { + const field = this.querySelector(`sp-field-group.toggle#${key}`); + if (field) field.style.display = 'block'; + }); + this.superWide = variant.size?.includes('super-wide'); + } + render() { if (this.loading) return html`
${this.fragment.path}
-