Fix: rename and implement fallbackRenderMethod (#20005)

* rename and implement fallbackRender

* re introducing method as part of the name

* rename impls

---------

Co-authored-by: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com>
Co-authored-by: Andrej Davidovič <andrejd@cdata.com>
This commit is contained in:
Niels Lyngsø
2025-08-27 13:11:58 +02:00
committed by GitHub
parent 279409d6ee
commit a2b2ecb221
5 changed files with 36 additions and 14 deletions

View File

@@ -467,7 +467,7 @@ export class UmbBlockGridEntryElement extends UmbLitElement implements UmbProper
<umb-extension-slot <umb-extension-slot
.filter=${this.#extensionSlotFilterMethod} .filter=${this.#extensionSlotFilterMethod}
.renderMethod=${this.#extensionSlotRenderMethod} .renderMethod=${this.#extensionSlotRenderMethod}
.defaultRenderMethod=${this.#renderBuiltinBlockView} .fallbackRenderMethod=${this.#renderBuiltinBlockView}
.props=${this._blockViewProps} .props=${this._blockViewProps}
default-element=${this._inlineEditingMode ? 'umb-block-grid-block-inline' : 'umb-block-grid-block'} default-element=${this._inlineEditingMode ? 'umb-block-grid-block-inline' : 'umb-block-grid-block'}
type="blockEditorCustomView" type="blockEditorCustomView"

View File

@@ -399,7 +399,7 @@ export class UmbBlockListEntryElement extends UmbLitElement implements UmbProper
${umbDestroyOnDisconnect()}></umb-unsupported-list-block>`; ${umbDestroyOnDisconnect()}></umb-unsupported-list-block>`;
} }
#renderBuiltinBlockView() { #renderBuiltinBlockView = () => {
if (this._unsupported) { if (this._unsupported) {
return this.#renderUnsupportedBlock(); return this.#renderUnsupportedBlock();
} }
@@ -407,7 +407,7 @@ export class UmbBlockListEntryElement extends UmbLitElement implements UmbProper
return this.#renderInlineBlock(); return this.#renderInlineBlock();
} }
return this.#renderRefBlock(); return this.#renderRefBlock();
} };
#renderBlock() { #renderBlock() {
return this.contentKey && (this._contentTypeAlias || this._unsupported) return this.contentKey && (this._contentTypeAlias || this._unsupported)
@@ -417,11 +417,10 @@ export class UmbBlockListEntryElement extends UmbLitElement implements UmbProper
type="blockEditorCustomView" type="blockEditorCustomView"
default-element=${this._inlineEditingMode ? 'umb-inline-list-block' : 'umb-ref-list-block'} default-element=${this._inlineEditingMode ? 'umb-inline-list-block' : 'umb-ref-list-block'}
.renderMethod=${this.#extensionSlotRenderMethod} .renderMethod=${this.#extensionSlotRenderMethod}
.fallbackRenderMethod=${this.#renderBuiltinBlockView}
.props=${this._blockViewProps} .props=${this._blockViewProps}
.filter=${this.#extensionSlotFilterMethod} .filter=${this.#extensionSlotFilterMethod}
single single></umb-extension-slot>
>${this.#renderBuiltinBlockView()}</umb-extension-slot
>
${this.#renderActionBar()} ${this.#renderActionBar()}
${!this._showContentEdit && this._contentInvalid ${!this._showContentEdit && this._contentInvalid
? html`<uui-badge attention color="invalid" label="Invalid content">!</uui-badge>` ? html`<uui-badge attention color="invalid" label="Invalid content">!</uui-badge>`

View File

@@ -277,11 +277,10 @@ export class UmbBlockRteEntryElement extends UmbLitElement implements UmbPropert
type="blockEditorCustomView" type="blockEditorCustomView"
default-element="umb-ref-rte-block" default-element="umb-ref-rte-block"
.renderMethod=${this.#extensionSlotRenderMethod} .renderMethod=${this.#extensionSlotRenderMethod}
.fallbackRenderMethod=${this.#renderBuiltinBlockView}
.props=${this._blockViewProps} .props=${this._blockViewProps}
.filter=${this.#filterBlockCustomViews} .filter=${this.#filterBlockCustomViews}
single> single></umb-extension-slot>
${this.#renderRefBlock()}
</umb-extension-slot>
${this.#renderActionBar()} ${this.#renderActionBar()}
${!this._showContentEdit && this._contentInvalid ${!this._showContentEdit && this._contentInvalid
? html`<uui-badge attention color="invalid" label="Invalid content">!</uui-badge>` ? html`<uui-badge attention color="invalid" label="Invalid content">!</uui-badge>`
@@ -297,6 +296,14 @@ export class UmbBlockRteEntryElement extends UmbLitElement implements UmbPropert
: nothing; : nothing;
} }
#renderBuiltinBlockView = () => {
// TODO: Missing unsupported rendering [NL]
/*if (this._unsupported) {
return this.#renderUnsupportedBlock();
}*/
return this.#renderRefBlock();
};
#renderRefBlock() { #renderRefBlock() {
return html`<umb-ref-rte-block return html`<umb-ref-rte-block
.label=${this._label} .label=${this._label}

View File

@@ -98,7 +98,7 @@ export class UmbExtensionSlotElement extends UmbLitElement {
) => TemplateResult | TemplateResult<1> | HTMLElement | null | undefined | typeof nothing; ) => TemplateResult | TemplateResult<1> | HTMLElement | null | undefined | typeof nothing;
@property({ attribute: false }) @property({ attribute: false })
public defaultRenderMethod?: () => public fallbackRenderMethod?: () =>
| TemplateResult | TemplateResult
| TemplateResult<1> | TemplateResult<1>
| HTMLElement | HTMLElement
@@ -142,15 +142,18 @@ export class UmbExtensionSlotElement extends UmbLitElement {
} }
override render() { override render() {
// First renders something once _permitted is set, this is to avoid flickering. [NL]
return this._permitted return this._permitted
? this._permitted.length > 0 ? this._permitted.length > 0
? repeat(this._permitted, (ext) => ext.alias, this.#renderExtension) ? repeat(this._permitted, (ext) => ext.alias, this.#renderExtension)
: this.defaultRenderMethod : this.#renderNoting()
? this.defaultRenderMethod()
: html`<slot></slot>`
: nothing; : nothing;
} }
#renderNoting() {
return this.fallbackRenderMethod ? this.fallbackRenderMethod() : html`<slot></slot>`;
}
#renderExtension = (ext: UmbExtensionElementInitializer, i: number) => { #renderExtension = (ext: UmbExtensionElementInitializer, i: number) => {
return this.renderMethod ? this.renderMethod(ext, i) : ext.component; return this.renderMethod ? this.renderMethod(ext, i) : ext.component;
}; };

View File

@@ -143,6 +143,15 @@ export class UmbExtensionWithApiSlotElement extends UmbLitElement {
index: number, index: number,
) => TemplateResult | TemplateResult<1> | HTMLElement | null | undefined | typeof nothing; ) => TemplateResult | TemplateResult<1> | HTMLElement | null | undefined | typeof nothing;
@property({ attribute: false })
public fallbackRenderMethod?: () =>
| TemplateResult
| TemplateResult<1>
| HTMLElement
| null
| undefined
| typeof nothing;
override connectedCallback(): void { override connectedCallback(): void {
super.connectedCallback(); super.connectedCallback();
this.#attached = true; this.#attached = true;
@@ -185,10 +194,14 @@ export class UmbExtensionWithApiSlotElement extends UmbLitElement {
return this._permitted return this._permitted
? this._permitted.length > 0 ? this._permitted.length > 0
? repeat(this._permitted, (ext) => ext.alias, this.#renderExtension) ? repeat(this._permitted, (ext) => ext.alias, this.#renderExtension)
: html`<slot></slot>` : this.#renderNoting()
: nothing; : nothing;
} }
#renderNoting() {
return this.fallbackRenderMethod ? this.fallbackRenderMethod() : html`<slot></slot>`;
}
#renderExtension = (ext: UmbExtensionElementAndApiInitializer, i: number) => { #renderExtension = (ext: UmbExtensionElementAndApiInitializer, i: number) => {
return this.renderMethod ? this.renderMethod(ext, i) : ext.component; return this.renderMethod ? this.renderMethod(ext, i) : ext.component;
}; };