expose button for no content editor block

This commit is contained in:
Niels Lyngsø
2024-10-16 11:40:04 +02:00
parent d192f9ea55
commit f99b542ece
3 changed files with 32 additions and 15 deletions

View File

@@ -48,9 +48,6 @@ export class UmbBlockGridBlockInlineElement extends UmbLitElement {
@property({ attribute: false })
content?: UmbBlockDataType;
@state()
private _exposed?: boolean;
@state()
_inlineProperty?: UmbPropertyTypeModel;
@@ -95,14 +92,6 @@ export class UmbBlockGridBlockInlineElement extends UmbLitElement {
'observeProperties',
);
this.observe(
this.#workspaceContext.exposed,
(exposed) => {
this._exposed = exposed;
},
'observeExposed',
);
this.observe(
context.content.structure.ownerContentTypeName,
(name) => {
@@ -174,7 +163,7 @@ export class UmbBlockGridBlockInlineElement extends UmbLitElement {
}
#renderInside() {
if (this._exposed === false) {
if (this.unpublished === true) {
return html`<uui-button id="exposeButton" @click=${this.#expose}
><uui-icon name="icon-add"></uui-icon>
<umb-localize

View File

@@ -1,5 +1,6 @@
import { UMB_BLOCK_GRID_ENTRY_CONTEXT } from '../../context/block-grid-entry.context-token.js';
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
import { css, customElement, html, property } from '@umbraco-cms/backoffice/external/lit';
import { css, customElement, html, nothing, property, state } from '@umbraco-cms/backoffice/external/lit';
import type { UmbBlockDataType } from '@umbraco-cms/backoffice/block';
import type { UmbBlockEditorCustomViewConfiguration } from '@umbraco-cms/backoffice/block-custom-view';
@@ -13,6 +14,8 @@ import '../ref-grid-block/index.js';
@customElement('umb-block-grid-block')
export class UmbBlockGridBlockElement extends UmbLitElement {
//
#context?: typeof UMB_BLOCK_GRID_ENTRY_CONTEXT.TYPE;
@property({ attribute: false })
label?: string;
@@ -28,10 +31,35 @@ export class UmbBlockGridBlockElement extends UmbLitElement {
@property({ attribute: false })
content?: UmbBlockDataType;
@state()
_ownerContentTypeName?: string;
constructor() {
super();
this.consumeContext(UMB_BLOCK_GRID_ENTRY_CONTEXT, (context) => {
this.#context = context;
this.observe(context.contentElementTypeName, (name) => {
this._ownerContentTypeName = name;
});
});
}
#expose = () => {
this.#context?.expose();
};
override render() {
return html`<umb-ref-grid-block
standalone
href=${(this.config?.showContentEdit ? this.config?.editContentPath : undefined) ?? ''}>
${this.config?.showContentEdit === false && this.unpublished
? html`
<uui-button slot="action" @click=${this.#expose}
><uui-icon name="icon-add"></uui-icon>
<umb-localize key="blockEditor_createThisFor" .args=${[this._ownerContentTypeName]}></umb-localize
></uui-button>
`
: nothing}
<umb-icon slot="icon" .name=${this.icon}></umb-icon>
<umb-ufm-render slot="name" inline .markdown=${this.label} .value=${this.content}></umb-ufm-render>
<umb-block-grid-areas-container slot="areas"></umb-block-grid-areas-container>

View File

@@ -46,10 +46,10 @@ export abstract class UmbBlockEntryContext<
#contentKey?: string;
#variantId = new UmbClassState<UmbVariantId | undefined>(undefined);
protected _variantId = this.#variantId.asObservable();
protected readonly _variantId = this.#variantId.asObservable();
#hasExpose = new UmbBooleanState(undefined);
hasExpose = this.#hasExpose.asObservable();
readonly hasExpose = this.#hasExpose.asObservable();
public readonly readOnlyState = new UmbReadOnlyVariantStateManager(this);