more structural changes

This commit is contained in:
Niels Lyngsø
2024-02-07 12:44:36 +01:00
parent 7ed6655cab
commit f3f2d9db72
11 changed files with 104 additions and 82 deletions

View File

@@ -1,29 +1,19 @@
import { UMB_BLOCK_CATALOGUE_MODAL } from '../../block/index.js';
import { UMB_BLOCK_CATALOGUE_MODAL, UmbBlockEntriesContext } from '../../block/index.js';
import { UMB_BLOCK_GRID_MANAGER_CONTEXT } from './block-grid-manager.context.js';
import type { UmbBlockGridLayoutModel } from '../types.js';
import { UMB_BLOCK_GRID_ENTRIES_CONTEXT } from './block-grid-entries.context-token.js';
import { UMB_BLOCK_GRID_ENTRY_CONTEXT } from './block-grid-entry.context-token.js';
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
import type { UmbBlockGridLayoutModel, UmbBlockGridTypeModel } from '../types.js';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { type UmbModalRouteBuilder, UmbModalRouteRegistrationController } from '@umbraco-cms/backoffice/modal';
import { UmbArrayState } from '@umbraco-cms/backoffice/observable-api';
export class UmbBlockGridEntriesContext extends UmbContextBase<UmbBlockGridEntriesContext> {
export class UmbBlockGridEntriesContext extends UmbBlockEntriesContext<
typeof UMB_BLOCK_GRID_MANAGER_CONTEXT,
typeof UMB_BLOCK_GRID_MANAGER_CONTEXT.TYPE,
UmbBlockGridTypeModel,
UmbBlockGridLayoutModel
> {
//
#blockManager?: typeof UMB_BLOCK_GRID_MANAGER_CONTEXT.TYPE;
#catalogueModal: UmbModalRouteRegistrationController<typeof UMB_BLOCK_CATALOGUE_MODAL.DATA, undefined>;
#catalogueRouteBuilder?: UmbModalRouteBuilder;
#layoutEntries = new UmbArrayState<UmbBlockGridLayoutModel>([], (x) => x.contentUdi);
layoutEntries = this.#layoutEntries.asObservable();
setLayoutEntries(layoutEntries: Array<UmbBlockGridLayoutModel>) {
this.#layoutEntries.setValue(layoutEntries);
}
getLayoutEntries() {
return this.#layoutEntries.value;
}
setParentKey(contentUdi: string) {
this.#catalogueModal.setUniquePathValue('parentUnique', contentUdi);
}
@@ -39,7 +29,7 @@ export class UmbBlockGridEntriesContext extends UmbContextBase<UmbBlockGridEntri
}
constructor(host: UmbControllerHost) {
super(host, UMB_BLOCK_GRID_ENTRIES_CONTEXT.toString());
super(host, UMB_BLOCK_GRID_MANAGER_CONTEXT);
this.#catalogueModal = new UmbModalRouteRegistrationController(this, UMB_BLOCK_CATALOGUE_MODAL)
.addUniquePaths(['propertyAlias', 'parentUnique', 'areaKey'])
@@ -58,20 +48,15 @@ export class UmbBlockGridEntriesContext extends UmbContextBase<UmbBlockGridEntri
})
.observeRouteBuilder((routeBuilder) => {
this.#catalogueRouteBuilder = routeBuilder;
// TODO: Trigger render update?
});
// TODO: Observe Blocks of the layout entries of this component.
this.consumeContext(UMB_BLOCK_GRID_MANAGER_CONTEXT, (blockGridManager) => {
this.#blockManager = blockGridManager;
this.#gotBlockManager();
});
}
#gotBlockManager() {
if (!this.#blockManager) return;
protected _gotBlockManager() {
if (!this._manager) return;
this.observe(
this.#blockManager.propertyAlias,
this._manager.propertyAlias,
(alias) => {
this.#catalogueModal.setUniquePathValue('propertyAlias', alias);
},

View File

@@ -1,13 +1,13 @@
import { UMB_BLOCK_GRID_MANAGER_CONTEXT } from './block-grid-manager.context.js';
import {
UmbBlockContext,
UmbBlockEntryContext,
type UmbBlockGridTypeModel,
type UmbBlockGridLayoutModel,
type UmbBlockGridLayoutAreaItemModel,
} from '@umbraco-cms/backoffice/block';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UmbArrayState } from '@umbraco-cms/backoffice/observable-api';
export class UmbBlockGridEntryContext extends UmbBlockContext<
export class UmbBlockGridEntryContext extends UmbBlockEntryContext<
typeof UMB_BLOCK_GRID_MANAGER_CONTEXT,
typeof UMB_BLOCK_GRID_MANAGER_CONTEXT.TYPE,
UmbBlockGridTypeModel,

View File

@@ -1,8 +1,8 @@
import { UMB_BLOCK_LIST_MANAGER_CONTEXT } from './block-list-manager.context.js';
import { UmbBlockContext } from '@umbraco-cms/backoffice/block';
import { UmbBlockEntryContext } from '@umbraco-cms/backoffice/block';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UmbBooleanState } from '@umbraco-cms/backoffice/observable-api';
export class UmbBlockListEntryContext extends UmbBlockContext<
export class UmbBlockListEntryContext extends UmbBlockEntryContext<
typeof UMB_BLOCK_LIST_MANAGER_CONTEXT,
typeof UMB_BLOCK_LIST_MANAGER_CONTEXT.TYPE
> {

View File

@@ -1,36 +0,0 @@
import type { UmbBlockTypeBaseModel } from '../../block-type/types.js';
import type { UmbBlockLayoutBaseModel } from '../types.js';
import type { UMB_BLOCK_MANAGER_CONTEXT } from './block-manager.context-token.js';
import type { UmbBlockManagerContext } from './block-manager.context.js';
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
export abstract class UmbBlockContext<
BlockManagerContextTokenType extends UmbContextToken<BlockManagerContextType, BlockManagerContextType>,
BlockManagerContextType extends UmbBlockManagerContext<BlockType, BlockLayoutType>,
BlockType extends UmbBlockTypeBaseModel = UmbBlockTypeBaseModel,
BlockLayoutType extends UmbBlockLayoutBaseModel = UmbBlockLayoutBaseModel,
> extends UmbContextBase<
UmbBlockContext<BlockManagerContextTokenType, BlockManagerContextType, BlockType, BlockLayoutType>
> {
//
_manager?: BlockManagerContextType;
constructor(host: UmbControllerHost, blockManagerContextToken: BlockManagerContextTokenType) {
super(host, UMB_BLOCK_ENTITY_CONTEXT.toString());
}
// Public methods:
//edit?
//editSettings
//requestDelete
//delete
// - should recursively delete all children of areas and their content/settings.
//copy
}
export const UMB_BLOCK_ENTITY_CONTEXT = new UmbContextToken<
UmbBlockContext<typeof UMB_BLOCK_MANAGER_CONTEXT, typeof UMB_BLOCK_MANAGER_CONTEXT.TYPE>
>('UmbBlockEntryContext');

View File

@@ -0,0 +1,14 @@
import type { UmbBlockTypeBaseModel } from '../../block-type/types.js';
import type { UmbBlockLayoutBaseModel } from '../types.js';
import type { UmbBlockEntriesContext } from './block-entries.context.js';
import type { UmbBlockManagerContext } from './block-manager.context.js';
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
export const UMB_BLOCK_ENTRIES_CONTEXT = new UmbContextToken<
typeof UmbBlockEntriesContext<
UmbContextToken<UmbBlockManagerContext, UmbBlockManagerContext>,
UmbBlockManagerContext<UmbBlockTypeBaseModel, UmbBlockLayoutBaseModel>,
UmbBlockTypeBaseModel,
UmbBlockLayoutBaseModel
>
>('UmbBlockEntriesContext');

View File

@@ -0,0 +1,54 @@
import type { UmbBlockTypeBaseModel } from '../../block-type/types.js';
import type { UmbBlockLayoutBaseModel } from '../types.js';
import type { UmbBlockManagerContext } from './block-manager.context.js';
import { UMB_BLOCK_ENTRIES_CONTEXT } from './block-entries.context-token.js';
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 { UmbArrayState } from '@umbraco-cms/backoffice/observable-api';
export abstract class UmbBlockEntriesContext<
BlockManagerContextTokenType extends UmbContextToken<BlockManagerContextType, BlockManagerContextType>,
BlockManagerContextType extends UmbBlockManagerContext<BlockType, BlockLayoutType>,
BlockType extends UmbBlockTypeBaseModel = UmbBlockTypeBaseModel,
BlockLayoutType extends UmbBlockLayoutBaseModel = UmbBlockLayoutBaseModel,
> extends UmbContextBase<
UmbBlockEntriesContext<BlockManagerContextTokenType, BlockManagerContextType, BlockType, BlockLayoutType>
> {
//
_manager?: BlockManagerContextType;
#layoutEntries = new UmbArrayState<BlockLayoutType>([], (x) => x.contentUdi);
layoutEntries = this.#layoutEntries.asObservable();
setLayoutEntries(layoutEntries: Array<BlockLayoutType>) {
this.#layoutEntries.setValue(layoutEntries);
}
getLayoutEntries() {
return this.#layoutEntries.value;
}
constructor(host: UmbControllerHost, blockManagerContextToken: BlockManagerContextTokenType) {
super(host, UMB_BLOCK_ENTRIES_CONTEXT.toString());
// TODO: Observe Blocks of the layout entries of this component.
this.consumeContext(blockManagerContextToken, (blockGridManager) => {
this._manager = blockGridManager;
this._gotBlockManager();
});
}
protected abstract _gotBlockManager(): void;
// Public methods:
public abstract getPathForCreateBlock(index: number): string | undefined;
public abstract getPathForClipboard(index: number): string | undefined;
//edit?
//editSettings
//requestDelete
//delete
// - should recursively delete all children of areas and their content/settings.
//copy
}

View File

@@ -0,0 +1,7 @@
import type { UmbBlockEntryContext } from './block-entry.context.js';
import type { UMB_BLOCK_MANAGER_CONTEXT } from './block-manager.context-token.js';
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
export const UMB_BLOCK_ENTRY_CONTEXT = new UmbContextToken<
UmbBlockEntryContext<typeof UMB_BLOCK_MANAGER_CONTEXT, typeof UMB_BLOCK_MANAGER_CONTEXT.TYPE>
>('UmbBlockEntryContext');

View File

@@ -1,20 +1,20 @@
import type { UmbBlockTypeBaseModel } from '../../block-type/types.js';
import type { UmbBlockLayoutBaseModel, UmbBlockDataType } from '../types.js';
import type { UMB_BLOCK_MANAGER_CONTEXT, UmbBlockManagerContext } from '../manager/index.js';
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
import { UMB_BLOCK_ENTRY_CONTEXT, type UmbBlockManagerContext } from '../index.js';
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 { UmbObjectState, UmbStringState } from '@umbraco-cms/backoffice/observable-api';
import { encodeFilePath } from '@umbraco-cms/backoffice/utils';
import { UMB_CONFIRM_MODAL, UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal';
export abstract class UmbBlockContext<
export abstract class UmbBlockEntryContext<
BlockManagerContextTokenType extends UmbContextToken<BlockManagerContextType, BlockManagerContextType>,
BlockManagerContextType extends UmbBlockManagerContext<BlockType, BlockLayoutType>,
BlockType extends UmbBlockTypeBaseModel = UmbBlockTypeBaseModel,
BlockLayoutType extends UmbBlockLayoutBaseModel = UmbBlockLayoutBaseModel,
> extends UmbContextBase<
UmbBlockContext<BlockManagerContextTokenType, BlockManagerContextType, BlockType, BlockLayoutType>
UmbBlockEntryContext<BlockManagerContextTokenType, BlockManagerContextType, BlockType, BlockLayoutType>
> {
//
_manager?: BlockManagerContextType;
@@ -72,7 +72,7 @@ export abstract class UmbBlockContext<
}
constructor(host: UmbControllerHost, blockManagerContextToken: BlockManagerContextTokenType) {
super(host, UMB_BLOCK_ENTITY_CONTEXT.toString());
super(host, UMB_BLOCK_ENTRY_CONTEXT.toString());
// Consume block manager:
this.consumeContext(blockManagerContextToken, (manager) => {
@@ -229,7 +229,3 @@ export abstract class UmbBlockContext<
//copy
}
export const UMB_BLOCK_ENTITY_CONTEXT = new UmbContextToken<
UmbBlockContext<typeof UMB_BLOCK_MANAGER_CONTEXT, typeof UMB_BLOCK_MANAGER_CONTEXT.TYPE>
>('UmbBlockEntryContext');

View File

@@ -1,3 +1,6 @@
export * from './block-entity.context.js';
export * from '../block-manager.context-token.js';
export type * from '../block-manager.context.js';
export * from './block-entry.context-token.js';
export * from './block-entry.context.js';
export * from './block-entries.context-token.js';
export * from './block-entries.context.js';
export * from './block-manager.context-token.js';
export type * from './block-manager.context.js';

View File

@@ -1,6 +1,5 @@
export * from './conditions/index.js';
export * from './context/index.js';
export * from './manager/index.js';
export * from './modals/index.js';
export * from './types.js';
export * from './workspace/index.js';

View File

@@ -6,7 +6,7 @@ import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import type { ManifestWorkspace } from '@umbraco-cms/backoffice/extension-registry';
import { UmbId } from '@umbraco-cms/backoffice/id';
import type { UmbBlockWorkspaceData } from '@umbraco-cms/backoffice/block';
import type { UMB_BLOCK_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/block';
import { UMB_BLOCK_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/block';
import { buildUdi } from '@umbraco-cms/backoffice/utils';
import { UMB_MODAL_CONTEXT } from '@umbraco-cms/backoffice/modal';