From 258727da39fe9d338220af34493e0b97acc808a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Fri, 2 Aug 2024 22:59:44 +0200 Subject: [PATCH] generator --- .../block-grid-entries.element.ts | 1 - ...itor-ui-block-grid-areas-config.element.ts | 2 +- .../property-editor-ui-block-list.element.ts | 6 +--- .../block-type-custom-view-guide.element.ts | 36 +++++++++++++++++-- .../manifest-viewer-modal.element.ts | 13 +++++-- 5 files changed, 46 insertions(+), 12 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/block/block-grid/components/block-grid-entries/block-grid-entries.element.ts b/src/Umbraco.Web.UI.Client/src/packages/block/block-grid/components/block-grid-entries/block-grid-entries.element.ts index 9ce184c1be..e4e62d56d9 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/block/block-grid/components/block-grid-entries/block-grid-entries.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/block/block-grid/components/block-grid-entries/block-grid-entries.element.ts @@ -291,7 +291,6 @@ export class UmbBlockGridEntriesElement extends UmbFormControlMixin(UmbLitElemen if (this._areaKey === null || this._layoutEntries.length === 0) { return html` `, )} - ` + ` : ''; } } diff --git a/src/Umbraco.Web.UI.Client/src/packages/block/block-list/property-editors/block-list-editor/property-editor-ui-block-list.element.ts b/src/Umbraco.Web.UI.Client/src/packages/block/block-list/property-editors/block-list-editor/property-editor-ui-block-list.element.ts index 584de1645c..2a96c2e0c0 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/block/block-list/property-editors/block-list-editor/property-editor-ui-block-list.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/block/block-list/property-editors/block-list-editor/property-editor-ui-block-list.element.ts @@ -175,11 +175,7 @@ export class UmbPropertyEditorUIBlockListElement extends UmbLitElement implement `, )} - + { + this.#contentTypeName = model?.name; this.#contentTypeAlias = model?.alias; this.#loadManifests(); }, @@ -54,7 +56,6 @@ export class UmbBlockTypeCustomViewGuideElement extends UmbLitElement { } #loadManifests() { - console.log('this.#blockEditorType', this.#blockEditorType, 'this.#contentTypeAlias', this.#contentTypeAlias); if (!this.#blockEditorType || !this.#contentTypeAlias) return; new UmbExtensionsManifestInitializer( this, @@ -87,6 +88,20 @@ export class UmbBlockTypeCustomViewGuideElement extends UmbLitElement { 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`
@@ -98,8 +113,23 @@ export class UmbBlockTypeCustomViewGuideElement extends UmbLitElement { `, )}
` - : html`No custom view matches the current block editor type and content type.`; + : html` this.#generateManifest()}>`; } + + static override styles = [ + css` + #add-button { + text-align: center; + width: 100%; + } + `, + ]; } export default UmbBlockTypeCustomViewGuideElement; diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/extension-registry/modals/manifest-viewer/manifest-viewer-modal.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/extension-registry/modals/manifest-viewer/manifest-viewer-modal.element.ts index 47100de84a..2e5e8e476e 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/extension-registry/modals/manifest-viewer/manifest-viewer-modal.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/extension-registry/modals/manifest-viewer/manifest-viewer-modal.element.ts @@ -2,18 +2,27 @@ import type { UmbManifestViewerModalData, UmbManifestViewerModalValue } from './ import { css, html, customElement, nothing } from '@umbraco-cms/backoffice/external/lit'; import { UmbModalBaseElement } from '@umbraco-cms/backoffice/modal'; +// JSON parser for the manifest viewer modal +// Enabling us to view JS code, but it is not optimal, but currently better than nothing [NL] +// Ideally we should have a JS code stringify that can print the manifest as JS. [NL] +function JsonParser(key: string, value: any) { + if (typeof value === 'function' && value !== null && value.toString) { + return Function.prototype.toString.call(value); + } + return value; +} + @customElement('umb-manifest-viewer-modal') export class UmbManifestViewerModalElement extends UmbModalBaseElement< UmbManifestViewerModalData, UmbManifestViewerModalValue > { override render() { - console.log('data', this.data); return html` ${this.data ? html`${JSON.stringify(this.data, null, 2)}${JSON.stringify(this.data, JsonParser, 2)}` : nothing}