Skip to content

Commit a1d1c54

Browse files
authored
Tiptap RTE: Custom CSS Variables for min/max height/width (#19841)
* Adds CSS variables to `umb-input-tiptap` to set the min/max height/width of the RTE. * Moves "dimensions" config to the base RTE element so can be reused with other RTE-based property-editors. * Sets the CSS variables in the Tiptap property-editor element * Code tidyup for RTE base element imports * Corrects localization text of RTE dimensions description As it's a fixed height/width as opposed to a maximum height/width. * The CSS variable fallback value 'unset' should not be quoted. CSS keywords like 'unset' should be unquoted, while string values should be quoted.
1 parent 7199ed0 commit a1d1c54

File tree

6 files changed

+37
-24
lines changed

6 files changed

+37
-24
lines changed

src/Umbraco.Web.UI.Client/src/assets/lang/da.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,7 +2705,7 @@ export default {
27052705
trainingDescription:
27062706
'\n <p>Want to master Umbraco? Spend a couple of minutes learning some best practices by watching one of these videos about using Umbraco. And visit <a href="https://umbraco.tv" target="_blank" rel="noopener">umbraco.tv</a> for even more Umbraco videos</p>\n ',
27072707
learningBaseDescription:
2708-
' <p>Vil du mestre Umbraco? Brug et par minutter på at lære nogle best practices ved at besøge <a class="btn-link -underline" href="https://www.youtube.com/c/UmbracoLearningBase" target="_blank" rel="noopener">Umbraco Learning Base YouTube-kanalen</a>. Her finder du en masse videoer, der dækker mange aspekter af Umbraco.</p> ',
2708+
' <p>Vil du mestre Umbraco? Brug et par minutter på at lære nogle best practices ved at besøge <a class="btn-link -underline" href="https://www.youtube.com/c/UmbracoLearningBase" target="_blank" rel="noopener">Umbraco Learning Base YouTube-kanalen</a>. Her finder du en masse videoer, der dækker mange aspekter af Umbraco.</p> ',
27092709
getStarted: 'To get you started',
27102710
},
27112711
settingsDashboard: {
@@ -2790,9 +2790,8 @@ export default {
27902790
tiptap: {
27912791
anchor: 'Anker',
27922792
anchor_input: 'Indtast anker-ID',
2793-
config_dimensions_description: 'Sæt den maksimale bredde og højde på editoren. Dette ekskluderer værktøjslinjens højde.',
2794-
maxDimensions: 'Maksimale dimensioner',
2795-
minDimensions: 'Minimale dimensioner',
2793+
config_dimensions_description:
2794+
'Angiver en fast bredde og højde for editoren. Dette ekskluderer værktøjslinjens og statuslinjens højder.',
27962795
config_extensions: 'Funktioner',
27972796
config_statusbar: 'Statuslinje',
27982797
config_toolbar: 'Værktøjslinje',

src/Umbraco.Web.UI.Client/src/assets/lang/en.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2781,7 +2781,8 @@ export default {
27812781
tiptap: {
27822782
anchor: 'Anchor',
27832783
anchor_input: 'Enter an anchor ID',
2784-
config_dimensions_description: 'Set the maximum width and height of the editor. This excludes the toolbar height.',
2784+
config_dimensions_description:
2785+
'Sets the fixed width and height of the editor. This excludes the toolbar and statusbar heights.',
27852786
config_extensions: 'Capabilities',
27862787
config_statusbar: 'Statusbar',
27872788
config_toolbar: 'Toolbar',

src/Umbraco.Web.UI.Client/src/assets/lang/pt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2789,7 +2789,7 @@ export default {
27892789
anchor: 'Âncora',
27902790
anchor_input: 'Introduza um ID de âncora',
27912791
config_dimensions_description:
2792-
'Defina a largura e altura máximas do editor. Isto exclui a altura da barra de ferramentas.',
2792+
'Definir uma largura e altura fixas para o editor. Isso exclui as alturas da barra de ferramentas e da barra de estado.',
27932793
config_extensions: 'Capacidades',
27942794
config_statusbar: 'Barra de estado',
27952795
config_toolbar: 'Barra de ferramentas',

src/Umbraco.Web.UI.Client/src/packages/rte/components/rte-base.element.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
import type { UmbPropertyEditorRteValueType } from '../types.js';
22
import { UMB_BLOCK_RTE_PROPERTY_EDITOR_SCHEMA_ALIAS } from '../constants.js';
3-
import { property, state } from '@umbraco-cms/backoffice/external/lit';
43
import { observeMultiple } from '@umbraco-cms/backoffice/observable-api';
4+
import { property, state } from '@umbraco-cms/backoffice/external/lit';
55
import { UmbBlockRteEntriesContext, UmbBlockRteManagerContext } from '@umbraco-cms/backoffice/block-rte';
6+
import { UmbChangeEvent } from '@umbraco-cms/backoffice/event';
7+
import {
8+
UmbFormControlMixin,
9+
UmbValidationContext,
10+
UMB_VALIDATION_EMPTY_LOCALIZATION_KEY,
11+
} from '@umbraco-cms/backoffice/validation';
612
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
13+
import { UMB_CONTENT_WORKSPACE_CONTEXT } from '@umbraco-cms/backoffice/content';
714
import { UMB_PROPERTY_CONTEXT, UMB_PROPERTY_DATASET_CONTEXT } from '@umbraco-cms/backoffice/property';
815
import type { UmbBlockRteTypeModel } from '@umbraco-cms/backoffice/block-rte';
916
import type {
1017
UmbPropertyEditorUiElement,
1118
UmbPropertyEditorConfigCollection,
1219
} from '@umbraco-cms/backoffice/property-editor';
13-
import {
14-
UMB_VALIDATION_EMPTY_LOCALIZATION_KEY,
15-
UmbFormControlMixin,
16-
UmbValidationContext,
17-
} from '@umbraco-cms/backoffice/validation';
18-
import { UmbChangeEvent } from '@umbraco-cms/backoffice/event';
19-
import { UMB_CONTENT_WORKSPACE_CONTEXT } from '@umbraco-cms/backoffice/content';
20+
import type { StyleInfo } from '@umbraco-cms/backoffice/external/lit';
2021

2122
export abstract class UmbPropertyEditorUiRteElementBase
2223
extends UmbFormControlMixin<UmbPropertyEditorRteValueType | undefined, typeof UmbLitElement, undefined>(UmbLitElement)
@@ -31,6 +32,12 @@ export abstract class UmbPropertyEditorUiRteElementBase
3132
this.#managerContext.setBlockTypes(blocks);
3233

3334
this.#managerContext.setEditorConfiguration(config);
35+
36+
const dimensions = config.getValueByAlias<{ width?: number; height?: number }>('dimensions');
37+
this._css = {
38+
'--umb-rte-max-width': dimensions?.width ? `${dimensions.width}px` : '100%',
39+
'--umb-rte-height': dimensions?.height ? `${dimensions.height}px` : 'unset',
40+
};
3441
}
3542

3643
@property({
@@ -94,8 +101,12 @@ export abstract class UmbPropertyEditorUiRteElementBase
94101
@state()
95102
protected _config?: UmbPropertyEditorConfigCollection;
96103

104+
@state()
105+
protected _css: StyleInfo = {};
106+
97107
/**
98108
* @deprecated _value is depreacated, use `super.value` instead.
109+
* @returns {UmbPropertyEditorRteValueType | undefined} The value of the property editor.
99110
*/
100111
@state()
101112
protected get _value(): UmbPropertyEditorRteValueType | undefined {

src/Umbraco.Web.UI.Client/src/packages/tiptap/components/input-tiptap/input-tiptap.element.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,6 @@ export class UmbInputTiptapElement extends UmbFormControlMixin<string, typeof Um
134134
const element = this.shadowRoot?.querySelector('#editor');
135135
if (!element) return;
136136

137-
const dimensions = this.configuration?.getValueByAlias<{ width?: number; height?: number }>('dimensions');
138-
if (dimensions?.width) {
139-
this.setAttribute('style', `max-width: ${dimensions.width}px;`);
140-
}
141-
if (dimensions?.height) {
142-
element.setAttribute('style', `height: ${dimensions.height}px;`);
143-
}
144-
145137
const stylesheets = this.configuration?.getValueByAlias<Array<string>>('stylesheets');
146138
if (stylesheets?.length) {
147139
stylesheets.forEach((stylesheet) => {
@@ -247,6 +239,10 @@ export class UmbInputTiptapElement extends UmbFormControlMixin<string, typeof Um
247239
display: block;
248240
position: relative;
249241
z-index: 0;
242+
243+
width: var(--umb-rte-width, unset);
244+
min-width: var(--umb-rte-min-width, unset);
245+
max-width: var(--umb-rte-max-width, 100%);
250246
}
251247
252248
:host([readonly]) {
@@ -279,7 +275,11 @@ export class UmbInputTiptapElement extends UmbFormControlMixin<string, typeof Um
279275
border: 1px solid var(--umb-tiptap-edge-border-color, var(--uui-color-border));
280276
padding: 1rem;
281277
box-sizing: border-box;
282-
height: 100%;
278+
279+
height: var(--umb-rte-height, 100%);
280+
min-height: var(--umb-rte-min-height, 100%);
281+
max-height: var(--umb-rte-max-height, 100%);
282+
283283
width: 100%;
284284
max-width: 100%;
285285

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { UmbInputTiptapElement } from '../../components/input-tiptap/input-tiptap.element.js';
2+
import { css, customElement, html, styleMap } from '@umbraco-cms/backoffice/external/lit';
23
import { UmbPropertyEditorUiRteElementBase } from '@umbraco-cms/backoffice/rte';
3-
import { css, customElement, html, type PropertyValueMap } from '@umbraco-cms/backoffice/external/lit';
4+
import type { PropertyValueMap } from '@umbraco-cms/backoffice/external/lit';
45

56
import '../../components/input-tiptap/input-tiptap.element.js';
67

@@ -66,6 +67,7 @@ export class UmbPropertyEditorUiTiptapElement extends UmbPropertyEditorUiRteElem
6667
override render() {
6768
return html`
6869
<umb-input-tiptap
70+
style=${styleMap(this._css)}
6971
.configuration=${this._config}
7072
.requiredMessage=${this.mandatoryMessage}
7173
.value=${this._markup}

0 commit comments

Comments
 (0)