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

Feature: Clipboard #17820

Merged
merged 246 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
246 commits
Select commit Hold shift + click to select a range
d8ca9bb
wip clipboard context + tests
madsrasmussen Nov 18, 2024
d8ffe86
clean up property action module + register copy action
madsrasmussen Nov 18, 2024
a077490
split manifests
madsrasmussen Nov 18, 2024
e7f2723
add clipboard module
madsrasmussen Nov 18, 2024
9feccde
import type
madsrasmussen Nov 18, 2024
82cb470
export type
madsrasmussen Nov 18, 2024
4f8762b
mark all methods async
madsrasmussen Nov 18, 2024
e98b155
Merge branch 'v15/dev' into v15/feature/clipboard
madsrasmussen Nov 19, 2024
c201fd1
scaffold copy + paste property actions
madsrasmussen Nov 19, 2024
f4d30c5
scaffold workspace, collection, repo + data sources
madsrasmussen Nov 19, 2024
8ac1832
remove references to language
madsrasmussen Nov 19, 2024
3a4e138
register detail manifests
madsrasmussen Nov 19, 2024
dc7ec8f
call repo when creating
madsrasmussen Nov 19, 2024
e02abc7
load clipboard collection data
madsrasmussen Nov 19, 2024
c26019a
remove debugger
madsrasmussen Nov 19, 2024
e1826f1
register clipboard item picker modal
madsrasmussen Nov 20, 2024
7ddd2c8
return value from picker
madsrasmussen Nov 20, 2024
385850f
accept native error
madsrasmussen Nov 20, 2024
de96683
clean up data source
madsrasmussen Nov 20, 2024
6197bf6
add tests for error states
madsrasmussen Nov 20, 2024
b0ef687
make clipboard local storage manager
madsrasmussen Nov 20, 2024
82a1d42
add clip entry entity type
madsrasmussen Nov 20, 2024
f2413f2
create unique in scaffold
madsrasmussen Nov 20, 2024
a924830
add clipboard entry item data
madsrasmussen Nov 20, 2024
d813a46
align naming
madsrasmussen Nov 20, 2024
b6eb6b6
move around
madsrasmussen Nov 20, 2024
0973181
name alignment
madsrasmussen Nov 20, 2024
b8b7065
fix imports
madsrasmussen Nov 20, 2024
6c65b8a
fix missing entityType
madsrasmussen Nov 20, 2024
a43ca3f
Merge branch 'v15/dev' into v15/feature/clipboard
madsrasmussen Nov 21, 2024
e7e2222
Merge branch 'v15/dev' into v15/feature/clipboard
madsrasmussen Nov 21, 2024
5e5b192
clean up
madsrasmussen Nov 21, 2024
f5138fa
use picker input context
madsrasmussen Nov 21, 2024
94abfb5
remove unused context
madsrasmussen Nov 21, 2024
e0d79b8
Update clipboard.context.ts
madsrasmussen Nov 21, 2024
6844b23
map to item model
madsrasmussen Nov 21, 2024
d7ed963
poc paste property action
madsrasmussen Nov 21, 2024
5ed42e1
Merge branch 'v15/dev' into v15/feature/clipboard
madsrasmussen Nov 21, 2024
77d94dd
register copy/paste as kinds
madsrasmussen Nov 21, 2024
83f1d85
Merge branch 'v15/dev' into v15/feature/clipboard
madsrasmussen Nov 25, 2024
933a357
lint fix
madsrasmussen Nov 25, 2024
7887c6e
add tests
madsrasmussen Nov 25, 2024
8969642
Merge branch 'v15/dev' into v15/feature/clipboard
madsrasmussen Nov 26, 2024
f6aa998
rename test
madsrasmussen Nov 26, 2024
79462cc
add repository tests
madsrasmussen Nov 26, 2024
669ed5b
register delete clipboard action + enable action dropdown outside of …
madsrasmussen Nov 26, 2024
cb22982
remove notifcation
madsrasmussen Nov 26, 2024
3b49b63
export entity type
madsrasmussen Nov 26, 2024
32f00a3
temp use repo instead of context
madsrasmussen Nov 26, 2024
71ae92f
delete unused copy property action
madsrasmussen Nov 26, 2024
9ff4b28
Merge branch 'v15/dev' into v15/feature/clipboard
madsrasmussen Dec 16, 2024
459c6ee
make data source non breaking
madsrasmussen Dec 16, 2024
eb857d0
Update vite.config.ts
madsrasmussen Dec 16, 2024
69a7b25
add icons for clipboard copy, paste + entry
madsrasmussen Dec 16, 2024
5298688
remove unused
madsrasmussen Dec 16, 2024
b84cf9e
return if there is no property value
madsrasmussen Dec 16, 2024
61149dd
add kind interfaces
madsrasmussen Dec 16, 2024
501472d
pass entry type for copy and paste
madsrasmussen Dec 16, 2024
6365c2f
register clipboard for block list
madsrasmussen Dec 16, 2024
892f44c
implement filter on entry type
madsrasmussen Dec 16, 2024
ec31ae5
delete unused context
madsrasmussen Dec 16, 2024
4531f15
remove references
madsrasmussen Dec 16, 2024
88d0da9
rename data to value and don't force an array
madsrasmussen Dec 16, 2024
78b2d8b
make icons and single value
madsrasmussen Dec 16, 2024
0e106d4
allow to add create and update dates for clipboard entries
madsrasmussen Dec 16, 2024
3e25446
use clipboard icon
madsrasmussen Dec 16, 2024
ba52d2d
add create and update dates
madsrasmussen Dec 16, 2024
688729d
export constants
madsrasmussen Dec 16, 2024
a845ce1
don't set as an array
madsrasmussen Dec 16, 2024
e040b00
reload picker content
madsrasmussen Dec 16, 2024
36d2bdd
add copy to clipboard button to block list entry
madsrasmussen Dec 17, 2024
cb6a5fb
make picker element
madsrasmussen Dec 17, 2024
a5a6d8f
allow to pick multiple
madsrasmussen Dec 17, 2024
6ea65a0
remove generic block list clipboard actions
madsrasmussen Dec 17, 2024
a1df745
Revert "remove generic block list clipboard actions"
madsrasmussen Dec 17, 2024
de963eb
add get methods
madsrasmussen Dec 17, 2024
31c40d4
wip construct block clipboard entry value
madsrasmussen Dec 17, 2024
ec0dd78
add method to get exposes + add jsdocs
madsrasmussen Dec 17, 2024
8fba489
add expose
madsrasmussen Dec 17, 2024
a55f885
remove todo + add jsdocs
madsrasmussen Dec 17, 2024
e663a81
move clipboard out of core package
madsrasmussen Dec 17, 2024
f539805
add package files
madsrasmussen Dec 17, 2024
6ee49d8
load package again
madsrasmussen Dec 17, 2024
7e593f3
render entry icon
madsrasmussen Dec 17, 2024
0ad0b26
render correct icon
madsrasmussen Dec 17, 2024
c74d8e7
Merge branch 'v15/dev' into v15/feature/clipboard
madsrasmussen Dec 18, 2024
0f172ac
remove clipboard from core vite.config
madsrasmussen Dec 18, 2024
8315377
Update package-lock.json
madsrasmussen Dec 18, 2024
de4ed4e
Merge branch 'v15/dev' into v15/feature/clipboard
madsrasmussen Dec 18, 2024
1c9a2cf
wip copy/paste resolvers
madsrasmussen Dec 18, 2024
fa80f49
allow multiple accepted entry types
madsrasmussen Dec 18, 2024
effb420
move logic to resolvers
madsrasmussen Dec 18, 2024
888321f
transforming clipboard block value to fit block list
madsrasmussen Dec 18, 2024
4139aab
wip copy/paste resolvers
madsrasmussen Dec 19, 2024
e2ffc1b
clean up
madsrasmussen Dec 19, 2024
30b4f06
remove unused
madsrasmussen Dec 19, 2024
0f8cb79
fix missing exports
madsrasmussen Dec 19, 2024
419e42f
fix tests
madsrasmussen Dec 19, 2024
1283c09
return clipboard entry unique from modal
madsrasmussen Dec 19, 2024
a8b7b81
Update block-list-entries.context.ts
madsrasmussen Dec 19, 2024
1bf7cf9
clipboard feature: clipboard property value cloner (#17824)
nielslyngsoe Dec 19, 2024
167c48c
try out cloner
madsrasmussen Dec 19, 2024
fca37fb
wip translators
madsrasmussen Dec 20, 2024
42f5aec
Revert "delete unused context"
madsrasmussen Dec 20, 2024
ede0bb9
move translator + cloner logic to context
madsrasmussen Dec 20, 2024
6853915
clean up
madsrasmussen Dec 20, 2024
3118ed1
implement read from clipboard in block list property editor
madsrasmussen Dec 20, 2024
db509dc
remove debugger
madsrasmussen Dec 20, 2024
a464814
values array
madsrasmussen Dec 20, 2024
cb930ea
handle paste
madsrasmussen Dec 20, 2024
bb32505
Update types.ts
madsrasmussen Dec 20, 2024
5337114
move files
madsrasmussen Dec 20, 2024
953b874
Update clipboard-local-storage.manager.ts
madsrasmussen Dec 20, 2024
0ba3513
set both create and update date when creating a clipboard entry
madsrasmussen Dec 20, 2024
2b683c5
align naming
madsrasmussen Dec 20, 2024
87ab399
handle paste
madsrasmussen Dec 20, 2024
5f751b3
clean up + wip block grid translators
madsrasmussen Dec 20, 2024
6df1efa
updates types
madsrasmussen Dec 20, 2024
d1bf907
Merge branch 'v15/dev' into v15/feature/clipboard
madsrasmussen Jan 6, 2025
3e0f0f6
Merge branch 'v15/feature/clipboard' into v15/feature/clipboard-trans…
madsrasmussen Jan 6, 2025
2be6226
add grid block copy translator
madsrasmussen Jan 6, 2025
32d7518
only allow paste translator to handle a single value
madsrasmussen Jan 6, 2025
279eac2
align copy and paste translators
madsrasmussen Jan 6, 2025
92e0359
remove debugger
madsrasmussen Jan 6, 2025
6f25e13
move to folders
madsrasmussen Jan 6, 2025
23e79cb
add block const
madsrasmussen Jan 6, 2025
d0b0760
rename
madsrasmussen Jan 6, 2025
2ef7f27
add tests
madsrasmussen Jan 6, 2025
fbf9d71
Update index.ts
madsrasmussen Jan 7, 2025
0872850
use correct type
madsrasmussen Jan 7, 2025
59f6a5f
add tests for UmbBlockListToBlockClipboardCopyTranslator
madsrasmussen Jan 7, 2025
eddc82b
fix tests
madsrasmussen Jan 7, 2025
c235eb8
Merge branch 'v15/dev' into v15/feature/clipboard
madsrasmussen Jan 8, 2025
d4634d8
Merge branch 'v15/feature/clipboard' into v15/feature/clipboard-trans…
madsrasmussen Jan 8, 2025
482f09c
add translator tests
madsrasmussen Jan 8, 2025
cd91d23
add tests
madsrasmussen Jan 8, 2025
31f2967
organize
madsrasmussen Jan 8, 2025
abef437
organize
madsrasmussen Jan 8, 2025
458927c
clean up translator tests
madsrasmussen Jan 8, 2025
0c01e21
align naming
madsrasmussen Jan 8, 2025
657e502
remove unused button
madsrasmussen Jan 8, 2025
034d672
only render copy property action if property has a value
madsrasmussen Jan 8, 2025
042c7b4
use constants
madsrasmussen Jan 8, 2025
56ad1c4
copy single grid block
madsrasmussen Jan 8, 2025
ed0633c
get block grid property value from clipboard entry
madsrasmussen Jan 8, 2025
63e154c
add clear method to extension registry + add js docs
madsrasmussen Jan 8, 2025
641cca4
Update index.ts
madsrasmussen Jan 8, 2025
edb8f1e
add tests for copy value resolver
madsrasmussen Jan 8, 2025
5d01a32
add icon for clipboard
madsrasmussen Jan 8, 2025
7db648e
use clipboard icon in modal
madsrasmussen Jan 8, 2025
97becbf
add tests
madsrasmussen Jan 9, 2025
b767e16
remove unused setting
madsrasmussen Jan 9, 2025
f7d8c30
fix log
madsrasmussen Jan 9, 2025
927b3d1
only create array once
madsrasmussen Jan 9, 2025
ae51169
filter for supported paste translators
madsrasmussen Jan 9, 2025
78cd576
use write method instead of duplicating the code
madsrasmussen Jan 9, 2025
d253360
add condition config type
madsrasmussen Jan 9, 2025
95685c2
use config type
madsrasmussen Jan 9, 2025
ad51c35
Update manifests.ts
madsrasmussen Jan 9, 2025
2d78116
add support for multi picker
madsrasmussen Jan 9, 2025
581000d
move multiple look up logic to context
madsrasmussen Jan 9, 2025
a07d717
add js docs
madsrasmussen Jan 9, 2025
086a571
add js docs
madsrasmussen Jan 9, 2025
9bead97
remove unused
madsrasmussen Jan 9, 2025
2ed6251
remove unused
madsrasmussen Jan 9, 2025
db87259
Merge branch 'v15/dev' into v15/feature/clipboard
madsrasmussen Jan 9, 2025
5df9c13
remove unused
madsrasmussen Jan 9, 2025
5579746
implement paste translator filtering for block catalogue modal
madsrasmussen Jan 9, 2025
e8d7aaa
temp color translator
madsrasmussen Jan 10, 2025
4a36d31
adding a UmbPropertyValueDataPotentiallyWithEditorAlias
nielslyngsoe Jan 10, 2025
ca91dbc
simplify observer
nielslyngsoe Jan 10, 2025
da7ca7e
append user unique to local storage key
madsrasmussen Jan 10, 2025
11a0c11
Merge branch 'v15/feature/clipboard' of https://github.com/umbraco/Um…
madsrasmussen Jan 10, 2025
cd962fa
remove temp color picker clipboard implementations
madsrasmussen Jan 10, 2025
af8334c
more explicit extension type name
madsrasmussen Jan 10, 2025
e9baea0
more renaming
madsrasmussen Jan 10, 2025
ea23226
type specifications
nielslyngsoe Jan 10, 2025
7b3e9c4
Merge branch 'v15/feature/clipboard-block-insert' into v15/feature/cl…
nielslyngsoe Jan 10, 2025
5ace8be
Merge branch 'v15/feature/clipboard' of https://github.com/umbraco/Um…
madsrasmussen Jan 10, 2025
b805166
fix test and missing type
nielslyngsoe Jan 10, 2025
9a243ba
more types for test
nielslyngsoe Jan 10, 2025
a89c8cd
renaming of paste translators
madsrasmussen Jan 10, 2025
3c02037
Merge branch 'v15/feature/clipboard' of https://github.com/umbraco/Um…
madsrasmussen Jan 10, 2025
50da142
rename folder
madsrasmussen Jan 10, 2025
98e5e05
rename value resolvers
madsrasmussen Jan 10, 2025
0877bce
Merge branch 'v15/dev' into v15/feature/clipboard
nielslyngsoe Jan 10, 2025
508e5e7
correct variable name
madsrasmussen Jan 10, 2025
c7d8923
wip tests for clipboard context
madsrasmussen Jan 10, 2025
1642a5b
clean up tests correctly
madsrasmussen Jan 10, 2025
e466f4b
add more tests for clipboard context
madsrasmussen Jan 10, 2025
6482e96
Update clipboard.context.test.ts
madsrasmussen Jan 10, 2025
e38a501
use after each for clean up
madsrasmussen Jan 10, 2025
15d7c28
fix test that times out
madsrasmussen Jan 10, 2025
4976bb1
correct name
madsrasmussen Jan 10, 2025
9b4aac7
optimize
madsrasmussen Jan 10, 2025
d87508f
remove webkit
madsrasmussen Jan 10, 2025
32e4970
newest first when picking
madsrasmussen Jan 10, 2025
7413460
use fingerprint local storage key to obfuscate user id
madsrasmussen Jan 10, 2025
16ac60e
rename method
madsrasmussen Jan 10, 2025
d30ba54
use const
madsrasmussen Jan 10, 2025
325679e
set content max length
madsrasmussen Jan 11, 2025
07c3fc0
return object including the selection uniques
madsrasmussen Jan 11, 2025
c2fa4a3
show confirm dialog before pasting value
madsrasmussen Jan 11, 2025
97de7a2
only show confirm dialog if there is a value
madsrasmussen Jan 11, 2025
1c4061d
Feature: clipboard block insert (#17935)
nielslyngsoe Jan 12, 2025
3a738d5
remove expose from block clipboard entry model
madsrasmussen Jan 12, 2025
41febcf
remove expose from grid block clipboard entry
madsrasmussen Jan 12, 2025
df6fb1d
remove todo
madsrasmussen Jan 12, 2025
377aa33
wip move value expand responsibility
madsrasmussen Jan 12, 2025
cefa27f
Merge branch 'v15/dev' into v15/feature/clipboard
madsrasmussen Jan 13, 2025
4592e70
Merge branch 'v15/feature/clipboard' into v15/feature/clipboard-local…
madsrasmussen Jan 13, 2025
7882c66
wip split clipboard context
madsrasmussen Jan 13, 2025
fad0d5f
experiment with an extendable property context
madsrasmussen Jan 13, 2025
7d3714d
create propertyContexts + proxy events
madsrasmussen Jan 13, 2025
55637ce
rename methods
madsrasmussen Jan 13, 2025
fe8a564
move proxy to context + update grid copy logic
madsrasmussen Jan 13, 2025
213dc0c
split tests
madsrasmussen Jan 13, 2025
e7a11df
remove unused
madsrasmussen Jan 13, 2025
0f86bcf
add property context extension type
madsrasmussen Jan 13, 2025
ff33367
fix tests
madsrasmussen Jan 13, 2025
268b5e4
fix tests
madsrasmussen Jan 13, 2025
5c5054b
reorganize
madsrasmussen Jan 13, 2025
5f3ae42
Update clipboard.property-context.ts
madsrasmussen Jan 13, 2025
85981ef
use context
madsrasmussen Jan 13, 2025
01cfc62
register property context clipboard kind
madsrasmussen Jan 13, 2025
d739adc
register for block grid
madsrasmussen Jan 13, 2025
905b3c6
remove redundant code
madsrasmussen Jan 13, 2025
b1336e7
Merge branch 'v15/dev' into v15/feature/clipboard
madsrasmussen Jan 13, 2025
eb0535e
rename to replace
madsrasmussen Jan 13, 2025
65ca043
Revert "rename to replace"
madsrasmussen Jan 14, 2025
d6bed32
rename prop
madsrasmussen Jan 14, 2025
a075f5f
rename label
madsrasmussen Jan 14, 2025
a42333d
improve block clean-up abilities
nielslyngsoe Jan 14, 2025
d9e140e
Update rte-base.element.ts
madsrasmussen Jan 14, 2025
561be3b
make local get of clipboard context
madsrasmussen Jan 14, 2025
f516ce9
add asyncFilter option to the type
madsrasmussen Jan 14, 2025
a2ae5a8
add is compatible method to the interface
madsrasmussen Jan 14, 2025
63c09e2
support asyncFilter in picker
madsrasmussen Jan 14, 2025
c6e0c39
add compatability check for block list
madsrasmussen Jan 14, 2025
35f40bd
more explicit name
madsrasmussen Jan 14, 2025
9eb8b4d
wip implementation of filter
madsrasmussen Jan 14, 2025
b401c37
add compatability checks
madsrasmussen Jan 14, 2025
6bddce8
add temp types
madsrasmussen Jan 15, 2025
cdcdffb
add clipboard filtering for grid and list
madsrasmussen Jan 15, 2025
a7df315
lint corrections
nielslyngsoe Jan 15, 2025
a226c50
Merge branch 'v15/dev' into v15/feature/clipboard
nielslyngsoe Jan 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Umbraco.Web.UI.Client/package-lock.json

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

1 change: 1 addition & 0 deletions src/Umbraco.Web.UI.Client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"./block-rte": "./dist-cms/packages/block/block-rte/index.js",
"./block-type": "./dist-cms/packages/block/block-type/index.js",
"./block": "./dist-cms/packages/block/block/index.js",
"./clipboard": "./dist-cms/packages/clipboard/index.js",
"./code-editor": "./dist-cms/packages/code-editor/index.js",
"./collection": "./dist-cms/packages/core/collection/index.js",
"./components": "./dist-cms/packages/core/components/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import './components/index.js';

const CORE_PACKAGES = [
import('../../packages/block/umbraco-package.js'),
import('../../packages/clipboard/umbraco-package.js'),
import('../../packages/code-editor/umbraco-package.js'),
import('../../packages/data-type/umbraco-package.js'),
import('../../packages/dictionary/umbraco-package.js'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ export class UmbExtensionRegistry<
return !this.#exclusions.includes(ext.alias);
};

/**
* Register an extension.
* @param {(ManifestTypes | ManifestKind<ManifestTypes>)} manifest - The extension to register.
* @memberof UmbExtensionRegistry
*/
register(manifest: ManifestTypes | ManifestKind<ManifestTypes>): void {
const isValid = this.#validateExtension(manifest);
if (!isValid) {
Expand All @@ -185,19 +190,39 @@ export class UmbExtensionRegistry<
]);
}

/**
* Get all registered extensions.
* @returns {Array<ManifestTypes>} - All registered extensions.
* @memberof UmbExtensionRegistry
*/
getAllExtensions(): Array<ManifestTypes> {
return this._extensions.getValue();
}

/**
* Register many extensions.
* @param {(Array<ManifestTypes | ManifestKind<ManifestTypes>>)} manifests - The extensions to register.
* @memberof UmbExtensionRegistry
*/
registerMany(manifests: Array<ManifestTypes | ManifestKind<ManifestTypes>>): void {
// we have to register extensions individually, so we ensure a manifest is valid before continuing to the next one
manifests.forEach((manifest) => this.register(manifest));
}

/**
* Unregister many extensions with the given aliases.
* @param {Array<string>} aliases - The aliases of the extensions to unregister.
* @memberof UmbExtensionRegistry
*/
unregisterMany(aliases: Array<string>): void {
aliases.forEach((alias) => this.unregister(alias));
}

/**
* Unregister an extension with the given alias.
* @param {string} alias - The alias of the extension to unregister.
* @memberof UmbExtensionRegistry
*/
unregister(alias: string): void {
const newKindsValues = this._kinds.getValue().filter((kind) => kind.alias !== alias);
const newExtensionsValues = this._extensions.getValue().filter((extension) => extension.alias !== alias);
Expand All @@ -206,6 +231,12 @@ export class UmbExtensionRegistry<
this._extensions.setValue(newExtensionsValues);
}

/**
* Check if an extension with the given alias is registered.
* @param {string} alias - The alias of the extension to check.
* @returns {boolean} - true if an extension with the given alias is registered.
* @memberof UmbExtensionRegistry
*/
isRegistered(alias: string): boolean {
if (this._extensions.getValue().find((ext) => ext.alias === alias)) {
return true;
Expand All @@ -218,6 +249,15 @@ export class UmbExtensionRegistry<
return false;
}

/**
* Clears all extensions and kinds from the registry.
* @memberof UmbExtensionRegistry
*/
clear(): void {
this._extensions.setValue([]);
this._kinds.setValue([]);
}

#validateExtension(manifest: ManifestTypes | ManifestKind<ManifestTypes>): boolean {
if (!manifest.type) {
console.error(`Extension is missing type`, manifest);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { expect } from '@open-wc/testing';
import { customElement } from 'lit/decorators.js';
import { UmbControllerHostElementMixin } from '@umbraco-cms/backoffice/controller-api';
import { UMB_BLOCK_GRID_PROPERTY_EDITOR_SCHEMA_ALIAS } from '../../../property-editors/constants.js';
import { UmbBlockGridToBlockClipboardCopyPropertyValueTranslator } from './block-grid-to-block-copy-translator.js';
import type { UmbBlockGridValueModel } from '../../../types.js';
import type { UmbBlockClipboardEntryValueModel } from '@umbraco-cms/backoffice/block';

@customElement('test-controller-host')
class UmbTestControllerHostElement extends UmbControllerHostElementMixin(HTMLElement) {}

describe('UmbBlockListToBlockClipboardCopyPropertyValueTranslator', () => {
let hostElement: UmbTestControllerHostElement;
let copyTranslator: UmbBlockGridToBlockClipboardCopyPropertyValueTranslator;

const blockGridPropertyValue: UmbBlockGridValueModel = {
contentData: [
{
key: 'contentKey',
contentTypeKey: 'contentTypeKey',
values: [
{
culture: null,
segment: null,
alias: 'headline',
editorAlias: 'Umbraco.TextBox',
value: 'Headline value',
},
],
},
],
layout: {
[UMB_BLOCK_GRID_PROPERTY_EDITOR_SCHEMA_ALIAS]: [
{
columnSpan: 12,
rowSpan: 1,
areas: [],
contentKey: 'contentKey',
settingsKey: null,
},
],
},
settingsData: [],
expose: [
{
contentKey: 'contentKey',
culture: null,
segment: null,
},
],
};

const blockClipboardEntryValue: UmbBlockClipboardEntryValueModel = {
contentData: blockGridPropertyValue.contentData,
layout: [
{
contentKey: 'contentKey',
settingsKey: null,
},
],
settingsData: blockGridPropertyValue.settingsData,
};

beforeEach(async () => {
hostElement = new UmbTestControllerHostElement();
copyTranslator = new UmbBlockGridToBlockClipboardCopyPropertyValueTranslator(hostElement);
document.body.innerHTML = '';
document.body.appendChild(hostElement);
});

describe('Public API', () => {
describe('methods', () => {
it('has a translate method', () => {
expect(copyTranslator).to.have.property('translate').that.is.a('function');
});
});
});

describe('translate', () => {
it('returns the block clipboard entry value', async () => {
const result = await copyTranslator.translate(blockGridPropertyValue);
expect(result).to.deep.equal(blockClipboardEntryValue);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import type { UmbBlockGridValueModel } from '../../../types.js';
import { UMB_BLOCK_GRID_PROPERTY_EDITOR_SCHEMA_ALIAS } from '../../../property-editors/constants.js';
import type { UmbGridBlockClipboardEntryValueModel } from '../../types.js';
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
import type { UmbClipboardCopyPropertyValueTranslator } from '@umbraco-cms/backoffice/clipboard';
import type { UmbBlockClipboardEntryValueModel } from '@umbraco-cms/backoffice/block';

export class UmbBlockGridToBlockClipboardCopyPropertyValueTranslator
extends UmbControllerBase
implements UmbClipboardCopyPropertyValueTranslator<UmbBlockGridValueModel, UmbBlockClipboardEntryValueModel>
{
/**
* Translates a Block Grid property value to a Block clipboard entry value.
* @param {UmbBlockGridValueModel} propertyValue - The Block Grid property value.
* @returns {Promise<UmbBlockClipboardEntryValueModel>} - The Block clipboard entry value.
* @memberof UmbBlockGridToBlockClipboardCopyPropertyValueTranslator
*/
async translate(propertyValue: UmbBlockGridValueModel): Promise<UmbBlockClipboardEntryValueModel> {
if (!propertyValue) {
throw new Error('Property value is missing.');
}

return this.#constructBlockValue(propertyValue);
}

#constructGridBlockValue(propertyValue: UmbBlockGridValueModel): UmbGridBlockClipboardEntryValueModel {
const valueClone = structuredClone(propertyValue);

const gridBlockValue: UmbGridBlockClipboardEntryValueModel = {
contentData: valueClone.contentData,
layout: valueClone.layout?.[UMB_BLOCK_GRID_PROPERTY_EDITOR_SCHEMA_ALIAS] ?? undefined,
settingsData: valueClone.settingsData,
};

return gridBlockValue;
}

#constructBlockValue(propertyValue: UmbBlockGridValueModel): UmbBlockClipboardEntryValueModel {
const gridBlockValue = this.#constructGridBlockValue(propertyValue);

const layout: UmbBlockClipboardEntryValueModel['layout'] = gridBlockValue.layout?.map((gridLayout) => {
return {
contentKey: gridLayout.contentKey,
settingsKey: gridLayout.settingsKey,
};
});

return {
contentData: gridBlockValue.contentData,
layout: layout,
settingsData: gridBlockValue.settingsData,
};
}
}

export { UmbBlockGridToBlockClipboardCopyPropertyValueTranslator as api };
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { UMB_BLOCK_GRID_PROPERTY_EDITOR_UI_ALIAS } from '../../property-editors/constants.js';
import { UMB_BLOCK_CLIPBOARD_ENTRY_VALUE_TYPE } from '@umbraco-cms/backoffice/block';

export const manifests: Array<UmbExtensionManifest> = [
{
type: 'clipboardCopyPropertyValueTranslator',
alias: 'Umb.ClipboardCopyPropertyValueTranslator.BlockGridToBlock',
name: 'Block Grid to Block Clipboard Copy Property Value Translator',
api: () => import('./copy/block-grid-to-block-copy-translator.js'),
fromPropertyEditorUi: UMB_BLOCK_GRID_PROPERTY_EDITOR_UI_ALIAS,
toClipboardEntryValueType: UMB_BLOCK_CLIPBOARD_ENTRY_VALUE_TYPE,
},
{
type: 'clipboardPastePropertyValueTranslator',
alias: 'Umb.ClipboardPastePropertyValueTranslator.BlockToBlockGrid',
name: 'Block To Block Grid Clipboard Paste Property Value Translator',
weight: 900,
api: () => import('./paste/block-to-block-grid-paste-translator.js'),
fromClipboardEntryValueType: UMB_BLOCK_CLIPBOARD_ENTRY_VALUE_TYPE,
toPropertyEditorUi: UMB_BLOCK_GRID_PROPERTY_EDITOR_UI_ALIAS,
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { expect } from '@open-wc/testing';
import { customElement } from 'lit/decorators.js';
import { UmbControllerHostElementMixin } from '@umbraco-cms/backoffice/controller-api';
import { UMB_BLOCK_GRID_PROPERTY_EDITOR_SCHEMA_ALIAS } from '../../../property-editors/constants.js';
import type { UmbBlockGridValueModel } from '../../../types.js';
import { UmbBlockToBlockGridClipboardPastePropertyValueTranslator } from './block-to-block-grid-paste-translator.js';
import type { UmbBlockClipboardEntryValueModel } from '@umbraco-cms/backoffice/block';

@customElement('test-controller-host')
class UmbTestControllerHostElement extends UmbControllerHostElementMixin(HTMLElement) {}

describe('UmbBlockToBlockGridClipboardPastePropertyValueTranslator', () => {
let hostElement: UmbTestControllerHostElement;
let copyTranslator: UmbBlockToBlockGridClipboardPastePropertyValueTranslator;

const blockGridPropertyValue: UmbBlockGridValueModel = {
contentData: [
{
key: 'contentKey',
contentTypeKey: 'contentTypeKey',
values: [
{
culture: null,
segment: null,
alias: 'headline',
editorAlias: 'Umbraco.TextBox',
value: 'Headline value',
},
],
},
],
layout: {
[UMB_BLOCK_GRID_PROPERTY_EDITOR_SCHEMA_ALIAS]: [
{
columnSpan: 12,
rowSpan: 1,
areas: [],
contentKey: 'contentKey',
settingsKey: null,
},
],
},
settingsData: [],
expose: [],
};

const blockClipboardEntryValue: UmbBlockClipboardEntryValueModel = {
contentData: blockGridPropertyValue.contentData,
layout: [
{
contentKey: 'contentKey',
settingsKey: null,
},
],
settingsData: blockGridPropertyValue.settingsData,
};

const config1: Array<{ alias: string; value: [{ contentElementTypeKey: string }] }> = [
{
alias: 'blocks',
value: [
{
contentElementTypeKey: 'contentTypeKey',
},
],
},
];

const config2: Array<{ alias: string; value: [{ contentElementTypeKey: string }] }> = [
{
alias: 'blocks',
value: [
{
contentElementTypeKey: 'contentTypeKey2',
},
],
},
];

beforeEach(async () => {
hostElement = new UmbTestControllerHostElement();
copyTranslator = new UmbBlockToBlockGridClipboardPastePropertyValueTranslator(hostElement);
document.body.innerHTML = '';
document.body.appendChild(hostElement);
});

describe('Public API', () => {
describe('methods', () => {
it('has a translate method', () => {
expect(copyTranslator).to.have.property('translate').that.is.a('function');
});
});
});

describe('translate', () => {
it('returns the block grid property value', async () => {
const result = await copyTranslator.translate(blockClipboardEntryValue);
expect(result).to.deep.equal(blockGridPropertyValue);
});
});

describe('isCompatibleValue', () => {
it('returns true if the value is compatible', async () => {
const result = await copyTranslator.isCompatibleValue(blockClipboardEntryValue, config1);
expect(result).to.be.true;
});

it('returns false if the value is not compatible', async () => {
const result = await copyTranslator.isCompatibleValue(blockClipboardEntryValue, config2);
expect(result).to.be.false;
});
});
});
Loading
Loading