Skip to content

Commit 5c8d460

Browse files
authored
Feature: Block workspace modal size from block type (#17501)
* correct ctrl alias * move types * undefined as an overlay size option * make modal size an observable * change set size order * remove log
1 parent 29bab94 commit 5c8d460

File tree

7 files changed

+81
-30
lines changed

7 files changed

+81
-30
lines changed

src/Umbraco.Web.UI.Client/src/packages/block/block/workspace/block-workspace.context.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
UMB_BLOCK_ENTRY_CONTEXT,
2626
} from '@umbraco-cms/backoffice/block';
2727
import { UmbVariantId } from '@umbraco-cms/backoffice/variant';
28+
import type { UUIModalSidebarSize } from '@umbraco-cms/backoffice/external/uui';
2829

2930
export type UmbBlockWorkspaceElementManagerNames = 'content' | 'settings';
3031
export class UmbBlockWorkspaceContext<LayoutDataType extends UmbBlockLayoutBaseModel = UmbBlockLayoutBaseModel>
@@ -44,6 +45,7 @@ export class UmbBlockWorkspaceContext<LayoutDataType extends UmbBlockLayoutBaseM
4445
setOriginData(data: UmbBlockWorkspaceOriginData) {
4546
this.#originData = data;
4647
}
48+
#modalContext?: typeof UMB_MODAL_CONTEXT.TYPE;
4749
#retrieveModalContext;
4850

4951
#entityType: string;
@@ -83,6 +85,7 @@ export class UmbBlockWorkspaceContext<LayoutDataType extends UmbBlockLayoutBaseM
8385
this.addValidationContext(this.settings.validation);
8486

8587
this.#retrieveModalContext = this.consumeContext(UMB_MODAL_CONTEXT, (context) => {
88+
this.#modalContext = context;
8689
this.#originData = context?.data.originData;
8790
context.onSubmit().catch(this.#modalRejected);
8891
}).asPromise();
@@ -116,7 +119,7 @@ export class UmbBlockWorkspaceContext<LayoutDataType extends UmbBlockLayoutBaseM
116119

117120
this.#variantId.setValue(variantId);
118121
},
119-
'observeBlockType',
122+
'observeVariantIds',
120123
);
121124

122125
this.removeUmbControllerByAlias('observeHasExpose');
@@ -156,6 +159,22 @@ export class UmbBlockWorkspaceContext<LayoutDataType extends UmbBlockLayoutBaseM
156159
},
157160
'observeIsReadOnly',
158161
);
162+
163+
this.observe(
164+
this.content.contentTypeId,
165+
(contentTypeId) => {
166+
this.observe(
167+
contentTypeId ? manager.blockTypeOf(contentTypeId) : undefined,
168+
(blockType) => {
169+
if (blockType?.editorSize) {
170+
this.setEditorSize(blockType.editorSize);
171+
}
172+
},
173+
'observeBlockType',
174+
);
175+
},
176+
'observeContentTypeId',
177+
);
159178
});
160179

161180
this.#retrieveBlockEntries = this.consumeContext(UMB_BLOCK_ENTRIES_CONTEXT, (context) => {
@@ -197,6 +216,10 @@ export class UmbBlockWorkspaceContext<LayoutDataType extends UmbBlockLayoutBaseM
197216
]);
198217
}
199218

219+
setEditorSize(editorSize: UUIModalSidebarSize) {
220+
this.#modalContext?.setModalSize(editorSize);
221+
}
222+
200223
protected override resetState() {
201224
super.resetState();
202225
this.#name.setValue(undefined);

src/Umbraco.Web.UI.Client/src/packages/core/modal/component/modal.element.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
type UUIDialogElement,
1414
type UUIModalDialogElement,
1515
type UUIModalSidebarElement,
16+
type UUIModalSidebarSize,
1617
} from '@umbraco-cms/backoffice/external/uui';
1718
import { UMB_ROUTE_CONTEXT, type UmbRouterSlotElement } from '@umbraco-cms/backoffice/router';
1819
import { createExtensionElement, loadManifestElement } from '@umbraco-cms/backoffice/extension-api';
@@ -117,7 +118,13 @@ export class UmbModalElement extends UmbLitElement {
117118

118119
#createSidebarElement() {
119120
const sidebarElement = document.createElement('uui-modal-sidebar');
120-
sidebarElement.size = this.#modalContext!.size;
121+
this.observe(
122+
this.#modalContext!.size,
123+
(size) => {
124+
sidebarElement.size = size as UUIModalSidebarSize;
125+
},
126+
'observeSize',
127+
);
121128
return sidebarElement;
122129
}
123130

src/Umbraco.Web.UI.Client/src/packages/core/modal/context/modal-manager.context.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,9 @@
11
import type { UmbModalToken } from '../token/modal-token.js';
22
import { UmbModalContext, type UmbModalContextClassArgs } from './modal.context.js';
3-
import type { UUIModalElement, UUIModalSidebarSize } from '@umbraco-cms/backoffice/external/uui';
43
import { UmbBasicState, appendToFrozenArray } from '@umbraco-cms/backoffice/observable-api';
54
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
65
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
76
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
8-
import type { ElementLoaderProperty } from '@umbraco-cms/backoffice/extension-api';
9-
10-
export type UmbModalType = 'dialog' | 'sidebar' | 'custom';
11-
12-
export interface UmbModalConfig {
13-
key?: string;
14-
type?: UmbModalType;
15-
size?: UUIModalSidebarSize;
16-
17-
/**
18-
* Used to provide a custom modal element to replace the default uui-modal-dialog or uui-modal-sidebar
19-
*/
20-
element?: ElementLoaderProperty<UUIModalElement>;
21-
22-
/**
23-
* Set the background property of the modal backdrop
24-
*/
25-
backdropBackground?: string;
26-
}
277

288
export class UmbModalManagerContext extends UmbContextBase<UmbModalManagerContext> {
299
// TODO: Investigate if we can get rid of HTML elements in our store, so we can use one of our states.

src/Umbraco.Web.UI.Client/src/packages/core/modal/context/modal.context.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { UmbModalToken } from '../token/modal-token.js';
2-
import type { UmbModalConfig, UmbModalType } from './modal-manager.context.js';
2+
import type { UmbModalConfig, UmbModalType } from '../types.js';
33
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
44
import type { IRouterSlot } from '@umbraco-cms/backoffice/external/router-slot';
55
import type { UUIModalElement, UUIModalSidebarSize } from '@umbraco-cms/backoffice/external/uui';
66
import { UmbId } from '@umbraco-cms/backoffice/id';
7-
import { UmbObjectState } from '@umbraco-cms/backoffice/observable-api';
7+
import { UmbObjectState, UmbStringState } from '@umbraco-cms/backoffice/observable-api';
88
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
99
import { type UmbDeepPartialObject, umbDeepMerge } from '@umbraco-cms/backoffice/utils';
1010
import type { ElementLoaderProperty } from '@umbraco-cms/backoffice/extension-api';
@@ -38,15 +38,17 @@ export class UmbModalContext<
3838
public readonly key: string;
3939
public readonly data: ModalData;
4040
public readonly type: UmbModalType = 'dialog';
41-
public readonly size: UUIModalSidebarSize = 'small';
42-
public element?: ElementLoaderProperty<UUIModalElement>;
41+
public readonly element?: ElementLoaderProperty<UUIModalElement>;
4342
public readonly backdropBackground?: string;
4443
public readonly router: IRouterSlot | null = null;
4544
public readonly alias: string | UmbModalToken<ModalData, ModalValue>;
4645

4746
#value;
4847
public readonly value;
4948

49+
#size = new UmbStringState<UUIModalSidebarSize>('small');
50+
public readonly size = this.#size.asObservable();
51+
5052
constructor(
5153
host: UmbControllerHost,
5254
modalAlias: string | UmbModalToken<ModalData, ModalValue>,
@@ -57,18 +59,24 @@ export class UmbModalContext<
5759
this.router = args.router ?? null;
5860
this.alias = modalAlias;
5961

62+
let size = 'small';
63+
6064
if (this.alias instanceof UmbModalToken) {
6165
this.type = this.alias.getDefaultModal()?.type || this.type;
62-
this.size = this.alias.getDefaultModal()?.size || this.size;
66+
size = this.alias.getDefaultModal()?.size ?? size;
6367
this.element = this.alias.getDefaultModal()?.element || this.element;
6468
this.backdropBackground = this.alias.getDefaultModal()?.backdropBackground || this.backdropBackground;
6569
}
6670

6771
this.type = args.modal?.type || this.type;
68-
this.size = args.modal?.size || this.size;
72+
size = args.modal?.size ?? size;
6973
this.element = args.modal?.element || this.element;
7074
this.backdropBackground = args.modal?.backdropBackground || this.backdropBackground;
7175

76+
console.log('size', size);
77+
78+
this.#size.setValue(size);
79+
7280
const defaultData = this.alias instanceof UmbModalToken ? this.alias.getDefaultData() : undefined;
7381
this.data = Object.freeze(
7482
// If we have both data and defaultData perform a deep merge
@@ -153,6 +161,16 @@ export class UmbModalContext<
153161
this.#value.update(partialValue);
154162
}
155163

164+
/**
165+
* Updates the size this modal.
166+
* @param size
167+
* @public
168+
* @memberof UmbModalContext
169+
*/
170+
setModalSize(size: UUIModalSidebarSize) {
171+
this.#size.setValue(size);
172+
}
173+
156174
public override destroy(): void {
157175
this.dispatchEvent(new CustomEvent('umb:destroy'));
158176
this.#value.destroy();

src/Umbraco.Web.UI.Client/src/packages/core/modal/token/modal-token.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { UmbModalConfig } from '../context/modal-manager.context.js';
1+
import type { UmbModalConfig } from '../types.js';
22

33
export interface UmbModalTokenDefaults<
44
ModalDataType extends { [key: string]: any } = { [key: string]: any },

src/Umbraco.Web.UI.Client/src/packages/core/modal/types.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import type { UUIModalElement, UUIModalSidebarSize } from '@umbraco-cms/backoffice/external/uui';
2+
import type { ElementLoaderProperty } from '@umbraco-cms/backoffice/extension-api';
3+
14
export type * from './extensions/index.js';
25

36
export interface UmbPickerModalData<ItemType> {
@@ -15,3 +18,21 @@ export interface UmbPickerModalSearchConfig {
1518
export interface UmbPickerModalValue {
1619
selection: Array<string | null>;
1720
}
21+
22+
export type UmbModalType = 'dialog' | 'sidebar' | 'custom';
23+
24+
export interface UmbModalConfig {
25+
key?: string;
26+
type?: UmbModalType;
27+
size?: UUIModalSidebarSize;
28+
29+
/**
30+
* Used to provide a custom modal element to replace the default uui-modal-dialog or uui-modal-sidebar
31+
*/
32+
element?: ElementLoaderProperty<UUIModalElement>;
33+
34+
/**
35+
* Set the background property of the modal backdrop
36+
*/
37+
backdropBackground?: string;
38+
}

src/Umbraco.Web.UI.Client/src/packages/property-editors/overlay-size/property-editor-ui-overlay-size.element.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ export class UmbPropertyEditorUIOverlaySizeElement extends UmbLitElement impleme
1515
@property()
1616
value: UUIModalSidebarSize | string = '';
1717

18+
// TODO: Stop having global type of the UUI-SELECT element. And make it possible to have undefined as an option.
1819
@state()
1920
private _list: Array<Option> = [
20-
{ value: 'small', name: 'Small', selected: true },
21+
{ value: undefined as any, name: 'Default', selected: true },
22+
{ value: 'small', name: 'Small' },
2123
{ value: 'medium', name: 'Medium' },
2224
{ value: 'large', name: 'Large' },
2325
{ value: 'full', name: 'Full' },

0 commit comments

Comments
 (0)