Skip to content

Commit 98e0615

Browse files
V15: Revert "Fix: RTE markup props not up to date issue" (#18879)
* Revert "simplifying the use of props (#18430)" This reverts commit 347e898. * do not set value if identical check cherry-picked from c03a8af Co-authored-by: Niels Lyngsø <[email protected]> --------- Co-authored-by: Niels Lyngsø <[email protected]>
1 parent 26907f2 commit 98e0615

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ export class UmbInputTinyMceElement extends UUIFormControlMixin(UmbLitElement, '
6161
}
6262

6363
override set value(newValue: FormDataEntryValue | FormData) {
64-
if (newValue === this.value) return;
65-
super.value = newValue;
6664
const newContent = typeof newValue === 'string' ? newValue : '';
65+
super.value = newContent;
6766

6867
if (this.#editorRef && this.#editorRef.getContent() != newContent) {
6968
this.#editorRef.setContent(newContent);

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

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { UmbInputTinyMceElement } from '../../components/input-tiny-mce/input-tiny-mce.element.js';
22
import { customElement, html } from '@umbraco-cms/backoffice/external/lit';
3-
import { UmbPropertyEditorUiRteElementBase, UMB_BLOCK_RTE_DATA_CONTENT_KEY } from '@umbraco-cms/backoffice/rte';
3+
import { UmbPropertyEditorUiRteElementBase } from '@umbraco-cms/backoffice/rte';
44

55
import '../../components/input-tiny-mce/input-tiny-mce.element.js';
66

@@ -10,37 +10,32 @@ import '../../components/input-tiny-mce/input-tiny-mce.element.js';
1010
@customElement('umb-property-editor-ui-tiny-mce')
1111
export class UmbPropertyEditorUITinyMceElement extends UmbPropertyEditorUiRteElementBase {
1212
#onChange(event: CustomEvent & { target: UmbInputTinyMceElement }) {
13-
const value = typeof event.target.value === 'string' ? event.target.value : '';
13+
const markup = typeof event.target.value === 'string' ? event.target.value : '';
1414

1515
// If we don't get any markup clear the property editor value.
16-
if (value === '') {
16+
if (markup === '') {
1717
this.value = undefined;
1818
this._fireChangeEvent();
1919
return;
2020
}
2121

22-
// Clone the DOM, to remove the classes and attributes on the original:
23-
const div = document.createElement('div');
24-
div.innerHTML = value;
25-
26-
// Loop through used, to remove the classes on these.
27-
const blockEls = div.querySelectorAll(`umb-rte-block, umb-rte-block-inline`);
28-
blockEls.forEach((blockEl) => {
29-
blockEl.removeAttribute('contenteditable');
30-
blockEl.removeAttribute('class');
31-
});
32-
33-
const markup = div.innerHTML;
34-
3522
// Remove unused Blocks of Blocks Layout. Leaving only the Blocks that are present in Markup.
36-
//const blockElements = editor.dom.select(`umb-rte-block, umb-rte-block-inline`);
37-
const usedContentKeys = Array.from(blockEls).map((blockElement) =>
38-
blockElement.getAttribute(UMB_BLOCK_RTE_DATA_CONTENT_KEY),
23+
const usedContentKeys: string[] = [];
24+
25+
// Regex matching all block elements in the markup, and extracting the content key. It's the same as the one used on the backend.
26+
const regex = new RegExp(
27+
/<umb-rte-block(?:-inline)?(?: class="(?:.[^"]*)")? data-content-key="(?<key>.[^"]*)">(?:<!--Umbraco-Block-->)?<\/umb-rte-block(?:-inline)?>/gi,
3928
);
29+
let blockElement: RegExpExecArray | null;
30+
while ((blockElement = regex.exec(markup)) !== null) {
31+
if (blockElement.groups?.key) {
32+
usedContentKeys.push(blockElement.groups.key);
33+
}
34+
}
4035

41-
if (super.value) {
42-
super.value = {
43-
...super.value,
36+
if (this.value) {
37+
this.value = {
38+
...this.value,
4439
markup: markup,
4540
};
4641
} else {

0 commit comments

Comments
 (0)