make exposed methods
This commit is contained in:
@@ -5,6 +5,7 @@ import type { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
|
||||
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import {
|
||||
UmbBooleanState,
|
||||
UmbClassState,
|
||||
UmbNumberState,
|
||||
UmbObjectState,
|
||||
@@ -46,6 +47,9 @@ export abstract class UmbBlockEntryContext<
|
||||
#variantId = new UmbClassState<UmbVariantId | undefined>(undefined);
|
||||
protected _variantId = this.#variantId.asObservable();
|
||||
|
||||
#hasExpose = new UmbBooleanState(undefined);
|
||||
hasExpose = this.#hasExpose.asObservable();
|
||||
|
||||
// Workspace alike methods, to enables editing of data without the need of a workspace (Custom views and block grid inline editing mode for example).
|
||||
getEntityType() {
|
||||
return 'block';
|
||||
@@ -232,26 +236,6 @@ export abstract class UmbBlockEntryContext<
|
||||
|
||||
abstract readonly showContentEdit: Observable<boolean>;
|
||||
|
||||
/**
|
||||
* Set the contentKey of this entry.
|
||||
* @function setContentKey
|
||||
* @param {string} contentKey the entry content key.
|
||||
* @returns {void}
|
||||
*/
|
||||
setContentKey(contentKey: string) {
|
||||
this.#contentKey = contentKey;
|
||||
this.#observeLayout();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current value of this Blocks label.
|
||||
* @function getLabel
|
||||
* @returns {string} - the value of the label.
|
||||
*/
|
||||
getLabel() {
|
||||
return this.#label.value;
|
||||
}
|
||||
|
||||
constructor(
|
||||
host: UmbControllerHost,
|
||||
blockManagerContextToken: BlockManagerContextTokenType,
|
||||
@@ -359,6 +343,26 @@ export abstract class UmbBlockEntryContext<
|
||||
return this._layout.value?.contentKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the contentKey of this entry.
|
||||
* @function setContentKey
|
||||
* @param {string} contentKey the entry content key.
|
||||
* @returns {void}
|
||||
*/
|
||||
setContentKey(contentKey: string) {
|
||||
this.#contentKey = contentKey;
|
||||
this.#observeLayout();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current value of this Blocks label.
|
||||
* @function getLabel
|
||||
* @returns {string} - the value of the label.
|
||||
*/
|
||||
getLabel() {
|
||||
return this.#label.value;
|
||||
}
|
||||
|
||||
#updateCreatePaths() {
|
||||
if (this._entries) {
|
||||
this.observe(
|
||||
@@ -540,8 +544,16 @@ export abstract class UmbBlockEntryContext<
|
||||
}
|
||||
|
||||
#gotVariantId() {
|
||||
if (!this.#variantId) return;
|
||||
const variantId = this.#variantId.getValue();
|
||||
if (!variantId || !this.#contentKey) return;
|
||||
// TODO: Handle variantId changes
|
||||
this.observe(
|
||||
this._manager?.hasExposeOf(this.#contentKey, variantId),
|
||||
(hasExpose) => {
|
||||
this.#hasExpose.setValue(hasExpose);
|
||||
},
|
||||
'observeExpose',
|
||||
);
|
||||
}
|
||||
|
||||
// Public methods:
|
||||
@@ -573,5 +585,11 @@ export abstract class UmbBlockEntryContext<
|
||||
this._entries.delete(contentKey);
|
||||
}
|
||||
|
||||
public expose() {
|
||||
const variantId = this.#variantId.getValue();
|
||||
if (!this.#contentKey || !variantId) return;
|
||||
this._manager?.setOneExpose(this.#contentKey, variantId);
|
||||
}
|
||||
|
||||
//copy
|
||||
}
|
||||
|
||||
@@ -167,6 +167,11 @@ export abstract class UmbBlockManagerContext<
|
||||
source.filter((x) => x.contentKey === contentKey && variantId.compare(x)),
|
||||
);
|
||||
}
|
||||
hasExposeOf(contentKey: string, variantId: UmbVariantId) {
|
||||
return this.#exposes.asObservablePart((source) =>
|
||||
source.some((x) => x.contentKey === contentKey && variantId.compare(x)),
|
||||
);
|
||||
}
|
||||
|
||||
getBlockTypeOf(contentTypeKey: string) {
|
||||
return this.#blockTypes.value.find((x) => x.contentElementTypeKey === contentTypeKey);
|
||||
|
||||
Reference in New Issue
Block a user