Skip to content

Commit

Permalink
wip construct block clipboard entry value
Browse files Browse the repository at this point in the history
  • Loading branch information
madsrasmussen committed Dec 17, 2024
1 parent de963eb commit 31c40d4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -387,37 +387,8 @@ export class UmbBlockListEntryElement extends UmbLitElement implements UmbProper
</uui-button>`;
}

async #copyToClipboard() {
// TODO: move to context
const propertyDatasetContext = await this.getContext(UMB_PROPERTY_DATASET_CONTEXT);
const propertyContext = await this.getContext(UMB_PROPERTY_CONTEXT);
const clipboardDetailRepository = new UmbClipboardEntryDetailRepository(this);

const workspaceName = propertyDatasetContext?.getName();
const propertyLabel = propertyContext?.getLabel();
const blockLabel = this._label;
const entryName = workspaceName
? `${workspaceName} - ${propertyLabel} - ${blockLabel}`
: `${propertyLabel} - ${blockLabel}`;

const blockValue = this._blockViewProps.content;
const blockIcon = this._icon;

const { data } = await clipboardDetailRepository.createScaffold({
type: 'block', // TODO: what is the correct type?
name: entryName,
icon: blockIcon,
meta: {}, // TODO: Add correct meta data
value: blockValue,
});

if (data) {
await clipboardDetailRepository.create(data);
}
}

#renderCopyToClipboardAction() {
return html`<uui-button label="Copy to clipboard" look="secondary" @click=${() => this.#copyToClipboard()}>
return html`<uui-button label="Copy to clipboard" look="secondary" @click=${() => this.#context.copyToClipboard()}>
<uui-icon name="icon-clipboard-copy"></uui-icon>
</uui-button>`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import type { Observable } from '@umbraco-cms/backoffice/external/rxjs';
import type { UmbBlockTypeBaseModel } from '@umbraco-cms/backoffice/block-type';
import { UmbVariantId } from '@umbraco-cms/backoffice/variant';
import { UmbUfmVirtualRenderController } from '@umbraco-cms/backoffice/ufm';
import { UMB_PROPERTY_CONTEXT, UMB_PROPERTY_DATASET_CONTEXT } from '@umbraco-cms/backoffice/property';
import { UmbClipboardEntryDetailRepository } from '@umbraco-cms/backoffice/clipboard';

export abstract class UmbBlockEntryContext<
BlockManagerContextTokenType extends UmbContextToken<BlockManagerContextType>,
Expand Down Expand Up @@ -712,5 +714,39 @@ export abstract class UmbBlockEntryContext<
this._manager?.setOneExpose(this.#contentKey, variantId);
}

//copy
public async copyToClipboard() {
// TODO: move to context
const propertyDatasetContext = await this.getContext(UMB_PROPERTY_DATASET_CONTEXT);
const propertyContext = await this.getContext(UMB_PROPERTY_CONTEXT);
const clipboardDetailRepository = new UmbClipboardEntryDetailRepository(this);

const workspaceName = propertyDatasetContext?.getName();
const propertyLabel = propertyContext?.getLabel();
const blockLabel = this.getName();
const entryName = workspaceName
? `${workspaceName} - ${propertyLabel} - ${blockLabel}`
: `${propertyLabel} - ${blockLabel}`;

const content = this.getContent();
const layout = this.getLayout();
const settings = this.getSettings();

const entryValue = {
contentData: content ? [structuredClone(content)] : [],
layout: layout ? [structuredClone(layout)] : [],
settingsData: settings ? [structuredClone(settings)] : [],
};

const { data } = await clipboardDetailRepository.createScaffold({
type: 'block',
name: entryName,
icon: this.getContentElementTypeIcon(),
meta: {}, // TODO: Add correct meta data
value: entryValue,
});

if (data) {
await clipboardDetailRepository.create(data);
}
}
}

0 comments on commit 31c40d4

Please sign in to comment.