Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block type custom view guide #2167

Merged
merged 8 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
"eslint-plugin-wc": "^2.1.0",
"glob": "^11.0.0",
"globals": "^15.8.0",
"lucide-static": "^0.408.0",
"lucide-static": "^0.424.0",
"msw": "^1.3.2",
"playwright-msw": "^3.0.1",
"prettier": "3.3.3",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/lang/en-us.ts
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,7 @@ export default {
logout: 'Logout',
macro: 'Macro',
mandatory: 'Mandatory',
manifest: 'Manifest',
media: 'Media',
message: 'Message',
move: 'Move',
Expand Down Expand Up @@ -2403,6 +2404,7 @@ export default {
tabClipboard: 'Clipboard',
tabBlockSettings: 'Settings',
headlineAdvanced: 'Advanced',
headlineCustomView: 'Custom View',
forceHideContentEditor: 'Hide content editor',
forceHideContentEditorHelp: 'Hide the content edit button and the content editor from the Block Editor overlay',
gridInlineEditing: 'Inline editing',
Expand Down
2 changes: 2 additions & 0 deletions src/assets/lang/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@ export default {
logout: 'Logout',
macro: 'Macro',
mandatory: 'Mandatory',
manifest: 'Manifest',
message: 'Message',
move: 'Move',
name: 'Name',
Expand Down Expand Up @@ -2471,6 +2472,7 @@ export default {
tabClipboard: 'Clipboard',
tabBlockSettings: 'Settings',
headlineAdvanced: 'Advanced',
headlineCustomView: 'Custom View',
forceHideContentEditor: 'Hide content editor',
forceHideContentEditorHelp: 'Hide the content edit button and the content editor from the Block Editor overlay.',
gridInlineEditing: 'Inline editing',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ export class UmbBlockGridEntriesElement extends UmbFormControlMixin(UmbLitElemen
if (this._areaKey === null || this._layoutEntries.length === 0) {
return html`<uui-button-group>
<uui-button
id="add-button"
look="placeholder"
label=${this._singleBlockTypeName
? this.localize.term('blockEditor_addThis', [this._singleBlockTypeName])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ export class UmbPropertyEditorUIBlockGridAreasConfigElement
)}
</div>
<uui-button
id="add-button"
look="placeholder"
label=${'Add area'}
href=${this._workspacePath + 'create'}></uui-button>`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { UMB_BLOCK_GRID } from '../../types.js';
import { css, html, customElement } from '@umbraco-cms/backoffice/external/lit';
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
import type { UmbWorkspaceViewElement } from '@umbraco-cms/backoffice/extension-registry';
// Getting umb-block-type-custom-view-guide element
import '@umbraco-cms/backoffice/block-type';

@customElement('umb-block-grid-type-workspace-view-advanced')
export class UmbBlockGridTypeWorkspaceViewAdvancedElement extends UmbLitElement implements UmbWorkspaceViewElement {
Expand All @@ -21,6 +24,13 @@ export class UmbBlockGridTypeWorkspaceViewAdvancedElement extends UmbLitElement
alias="hideContentEditor"
property-editor-ui-alias="Umb.PropertyEditorUi.Toggle"></umb-property>
</uui-box>
<uui-box headline=${this.localize.term('blockEditor_headlineCustomView')}>
<umb-property-layout label=${this.localize.term('blockEditor_labelCustomView')}>
<umb-block-type-custom-view-guide
slot="editor"
block-editor-type=${UMB_BLOCK_GRID}></umb-block-type-custom-view-guide>
</umb-property-layout>
</uui-box>
<uui-box headline=${this.localize.term('blockEditor_headlineCatalogueAppearance')}>
<umb-property
label=${this.localize.term('blockEditor_labelBackgroundColor')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,7 @@ export class UmbPropertyEditorUIBlockListElement extends UmbLitElement implement
</umb-block-list-entry> `,
)}
<uui-button-group>
<uui-button
id="add-button"
look="placeholder"
label=${this._createButtonLabel}
href=${createPath ?? ''}></uui-button>
<uui-button look="placeholder" label=${this._createButtonLabel} href=${createPath ?? ''}></uui-button>
<uui-button
label=${this.localize.term('content_createFromClipboard')}
look="placeholder"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
import { html, customElement, state, property, css } from '@umbraco-cms/backoffice/external/lit';
import { UMB_PROPERTY_DATASET_CONTEXT } from '@umbraco-cms/backoffice/property';
import {
UMB_MANIFEST_VIEWER_MODAL,
umbExtensionsRegistry,
type ManifestBlockEditorCustomView,
} from '@umbraco-cms/backoffice/extension-registry';
import { stringOrStringArrayContains } from '@umbraco-cms/backoffice/utils';
import { UmbExtensionsManifestInitializer } from '@umbraco-cms/backoffice/extension-api';
import { UmbDocumentTypeDetailRepository } from '@umbraco-cms/backoffice/document-type';
import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal';

@customElement('umb-block-type-custom-view-guide')
export class UmbBlockTypeCustomViewGuideElement extends UmbLitElement {
#contentTypeName?: string;
#contentTypeAlias?: string;
#blockEditorType?: string;

@property({ type: String, attribute: 'block-editor-type' })
get blockEditorType() {
return this.#blockEditorType;
}
set blockEditorType(value) {
this.#blockEditorType = value;
this.#loadManifests();
}

@state()
private _manifests?: Array<ManifestBlockEditorCustomView>;

#repository = new UmbDocumentTypeDetailRepository(this);

constructor() {
super();

this.consumeContext(UMB_PROPERTY_DATASET_CONTEXT, async (context) => {
this.observe(
await context.propertyValueByAlias<string | undefined>('contentElementTypeKey'),
async (value) => {
if (!value) return;
const { asObservable } = await this.#repository.requestByUnique(value);
this.observe(
asObservable(),
(model) => {
this.#contentTypeName = model?.name;
this.#contentTypeAlias = model?.alias;
this.#loadManifests();
},
'observeContentType',
);
},
'observeContentElementTypeKey',
);
});
}

#loadManifests() {
if (!this.#blockEditorType || !this.#contentTypeAlias) return;
new UmbExtensionsManifestInitializer(
this,
umbExtensionsRegistry,
'blockEditorCustomView',
this.#extensionFilterMethod,
async (customViews) => {
this._manifests = customViews.map((x) => x.manifest);
},
'manifestInitializer',
);
}

#extensionFilterMethod = (manifest: ManifestBlockEditorCustomView) => {
if (!this.#blockEditorType || !this.#contentTypeAlias) return false;
if (
manifest.forContentTypeAlias &&
!stringOrStringArrayContains(manifest.forContentTypeAlias, this.#contentTypeAlias!)
) {
return false;
}
if (manifest.forBlockEditor && !stringOrStringArrayContains(manifest.forBlockEditor, this.#blockEditorType)) {
return false;
}
return true;
};

async #viewManifest(manifest: ManifestBlockEditorCustomView) {
const modalManager = await this.getContext(UMB_MODAL_MANAGER_CONTEXT);
modalManager.open(this, UMB_MANIFEST_VIEWER_MODAL, { data: manifest });
}

async #generateManifest() {
const modalManager = await this.getContext(UMB_MODAL_MANAGER_CONTEXT);

const manifest = {
type: 'blockEditorCustomView',
alias: 'Local.blockEditorCustomView.' + this.#contentTypeAlias,
name: 'Block Editor Custom View for ' + this.#contentTypeName,
element: '[replace with path to your web component js file...]',
forContentTypeAlias: this.#contentTypeAlias,
forBlockEditor: this.#blockEditorType,
};
modalManager.open(this, UMB_MANIFEST_VIEWER_MODAL, { data: manifest });
}

override render() {
return this._manifests && this._manifests.length > 0
? html` <div>
<umb-ref-manifest
standalone
@open=${() => this.#viewManifest(this._manifests![0])}
.manifest=${this._manifests[0]}></umb-ref-manifest>
</div>`
: html`<uui-button
id="add-button"
look="placeholder"
label="Generate manifest for this Block Type"
type="button"
color="default"
@click=${() => this.#generateManifest()}></uui-button>`;
}

static override styles = [
css`
#add-button {
text-align: center;
width: 100%;
}
`,
];
}

export default UmbBlockTypeCustomViewGuideElement;

declare global {
interface HTMLElementTagNameMap {
'umb-block-type-custom-view-guide': UmbBlockTypeCustomViewGuideElement;
}
}
1 change: 1 addition & 0 deletions src/packages/block/block-type/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './block-type-card/index.js';
export * from './input-block-type/index.js';
export * from './block-type-custom-view-guide/block-type-custom-view-guide.element.js';
1 change: 1 addition & 0 deletions src/packages/block/block-type/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './components/index.js';
export * from './types.js';
export * from './workspace/index.js';
3 changes: 1 addition & 2 deletions src/packages/block/block-type/manifests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { manifests as workspaceManifests } from './workspace/manifests.js';
import { manifests as propertyEditorManifests } from './property-editors/manifests.js';
import type { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';

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

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions src/packages/block/block-type/property-editors/manifests.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/packages/block/block-type/workspace/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './block-type-workspace.context-token.js';
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './composition-picker-modal.element.js';
export * from './composition-picker-modal.token.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { ManifestModal } from '@umbraco-cms/backoffice/extension-registry';

export const manifest: ManifestModal = {
type: 'modal',
alias: 'Umb.Modal.CompositionPicker',
name: 'ContentType Composition Picker Modal',
element: () => import('./composition-picker-modal.element.js'),
};
13 changes: 2 additions & 11 deletions src/packages/core/content-type/modals/manifests.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
import type { ManifestModal } from '@umbraco-cms/backoffice/extension-registry';
import { manifest } from './composition-picker/manifest.js';

const modals: Array<ManifestModal> = [
{
type: 'modal',
alias: 'Umb.Modal.CompositionPicker',
name: 'ContentType Composition Picker Modal',
element: () => import('./composition-picker/composition-picker-modal.element.js'),
},
];

export const manifests = modals;
export const manifests = [manifest];
Loading
Loading