Skip to content
This repository was archived by the owner on Nov 6, 2025. It is now read-only.

Commit 6d9611f

Browse files
committed
poc custom view guide
1 parent 5814fba commit 6d9611f

File tree

13 files changed

+119
-95
lines changed

13 files changed

+119
-95
lines changed

src/assets/lang/en-us.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2403,6 +2403,7 @@ export default {
24032403
tabClipboard: 'Clipboard',
24042404
tabBlockSettings: 'Settings',
24052405
headlineAdvanced: 'Advanced',
2406+
headlineCustomView: 'Custom View',
24062407
forceHideContentEditor: 'Hide content editor',
24072408
forceHideContentEditorHelp: 'Hide the content edit button and the content editor from the Block Editor overlay',
24082409
gridInlineEditing: 'Inline editing',

src/assets/lang/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,6 +2470,7 @@ export default {
24702470
tabClipboard: 'Clipboard',
24712471
tabBlockSettings: 'Settings',
24722472
headlineAdvanced: 'Advanced',
2473+
headlineCustomView: 'Custom View',
24732474
forceHideContentEditor: 'Hide content editor',
24742475
forceHideContentEditorHelp: 'Hide the content edit button and the content editor from the Block Editor overlay.',
24752476
gridInlineEditing: 'Inline editing',

src/packages/block/block-grid/workspace/views/block-grid-type-workspace-view-advanced.element.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import { UMB_BLOCK_GRID } from '../../types.js';
12
import { css, html, customElement } from '@umbraco-cms/backoffice/external/lit';
23
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
34
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
45
import type { UmbWorkspaceViewElement } from '@umbraco-cms/backoffice/extension-registry';
6+
// Getting umb-block-type-custom-view-guide element
7+
import '@umbraco-cms/backoffice/block-type';
58

69
@customElement('umb-block-grid-type-workspace-view-advanced')
710
export class UmbBlockGridTypeWorkspaceViewAdvancedElement extends UmbLitElement implements UmbWorkspaceViewElement {
@@ -21,6 +24,13 @@ export class UmbBlockGridTypeWorkspaceViewAdvancedElement extends UmbLitElement
2124
alias="hideContentEditor"
2225
property-editor-ui-alias="Umb.PropertyEditorUi.Toggle"></umb-property>
2326
</uui-box>
27+
<uui-box headline=${this.localize.term('blockEditor_headlineCustomView')}>
28+
<umb-property-layout label=${this.localize.term('blockEditor_labelCustomView')}>
29+
<umb-block-type-custom-view-guide
30+
slot="editor"
31+
block-editor-type=${UMB_BLOCK_GRID}></umb-block-type-custom-view-guide>
32+
</umb-property-layout>
33+
</uui-box>
2434
<uui-box headline=${this.localize.term('blockEditor_headlineCatalogueAppearance')}>
2535
<umb-property
2636
label=${this.localize.term('blockEditor_labelBackgroundColor')}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
2+
import { html, customElement, state, property, repeat } from '@umbraco-cms/backoffice/external/lit';
3+
import { UMB_PROPERTY_DATASET_CONTEXT } from '@umbraco-cms/backoffice/property';
4+
import { umbExtensionsRegistry, type ManifestBlockEditorCustomView } from '@umbraco-cms/backoffice/extension-registry';
5+
import { stringOrStringArrayContains } from '@umbraco-cms/backoffice/utils';
6+
import { UmbExtensionsManifestInitializer } from '@umbraco-cms/backoffice/extension-api';
7+
import { UmbDocumentTypeDetailRepository } from '@umbraco-cms/backoffice/document-type';
8+
9+
@customElement('umb-block-type-custom-view-guide')
10+
export class UmbBlockTypeCustomViewGuideElement extends UmbLitElement {
11+
#contentTypeAlias?: string;
12+
#blockEditorType?: string;
13+
14+
@property({ type: String, attribute: 'block-editor-type' })
15+
get blockEditorType() {
16+
return this.#blockEditorType;
17+
}
18+
set blockEditorType(value) {
19+
this.#blockEditorType = value;
20+
this.#loadManifests();
21+
}
22+
23+
@state()
24+
private _manifests?: Array<ManifestBlockEditorCustomView>;
25+
26+
#repository = new UmbDocumentTypeDetailRepository(this);
27+
28+
constructor() {
29+
super();
30+
31+
this.consumeContext(UMB_PROPERTY_DATASET_CONTEXT, async (context) => {
32+
this.observe(
33+
await context.propertyValueByAlias<string | undefined>('contentElementTypeKey'),
34+
async (value) => {
35+
if (!value) return;
36+
const { asObservable } = await this.#repository.requestByUnique(value);
37+
this.observe(
38+
asObservable(),
39+
(model) => {
40+
this.#contentTypeAlias = model?.alias;
41+
this.#loadManifests();
42+
},
43+
'observeContentType',
44+
);
45+
},
46+
'observeContentElementTypeKey',
47+
);
48+
});
49+
}
50+
51+
#loadManifests() {
52+
console.log('this.#blockEditorType', this.#blockEditorType, 'this.#contentTypeAlias', this.#contentTypeAlias);
53+
if (!this.#blockEditorType || !this.#contentTypeAlias) return;
54+
new UmbExtensionsManifestInitializer(
55+
this,
56+
umbExtensionsRegistry,
57+
'blockEditorCustomView',
58+
this.#extensionFilterMethod,
59+
async (customViews) => {
60+
this._manifests = customViews.map((x) => x.manifest);
61+
},
62+
'manifestInitializer',
63+
);
64+
}
65+
66+
#extensionFilterMethod = (manifest: ManifestBlockEditorCustomView) => {
67+
if (!this.#blockEditorType || !this.#contentTypeAlias) return false;
68+
if (
69+
manifest.forContentTypeAlias &&
70+
!stringOrStringArrayContains(manifest.forContentTypeAlias, this.#contentTypeAlias!)
71+
) {
72+
return false;
73+
}
74+
if (manifest.forBlockEditor && !stringOrStringArrayContains(manifest.forBlockEditor, this.#blockEditorType)) {
75+
return false;
76+
}
77+
return true;
78+
};
79+
80+
override render() {
81+
return this._manifests && this._manifests.length > 0
82+
? html` <div>
83+
${repeat(
84+
this._manifests,
85+
(x) => x.alias,
86+
(x) => html`
87+
<uui-ref-node standalone name=${x.name} detail=${x.alias}>
88+
<umb-icon slot="icon" name=${'icon-flowerpot'}></umb-icon
89+
></uui-ref-node>
90+
`,
91+
)}
92+
</div>`
93+
: html`No custom view matches the current block editor type and content type.`;
94+
}
95+
}
96+
97+
export default UmbBlockTypeCustomViewGuideElement;
98+
99+
declare global {
100+
interface HTMLElementTagNameMap {
101+
'umb-block-type-custom-view-guide': UmbBlockTypeCustomViewGuideElement;
102+
}
103+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './block-type-card/index.js';
22
export * from './input-block-type/index.js';
3+
export * from './block-type-custom-view-guide/block-type-custom-view-guide.element.js';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './components/index.js';
22
export * from './types.js';
3+
export * from './workspace/index.js';
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { manifests as workspaceManifests } from './workspace/manifests.js';
2-
import { manifests as propertyEditorManifests } from './property-editors/manifests.js';
32
import type { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';
43

5-
export const manifests: Array<ManifestTypes> = [...workspaceManifests, ...propertyEditorManifests];
4+
export const manifests: Array<ManifestTypes> = [...workspaceManifests];

src/packages/block/block-type/property-editors/block-type-group-configuration/manifests.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/packages/block/block-type/property-editors/block-type-group-configuration/property-editor-ui-block-type-group-configuration.element.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/packages/block/block-type/property-editors/block-type-group-configuration/property-editor-ui-block-type-group-configuration.stories.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)