@@ -10,11 +10,10 @@ import type {
10
10
import {
11
11
UmbBlockRteEntriesContext ,
12
12
UmbBlockRteManagerContext ,
13
- type UmbBlockRteLayoutModel ,
14
13
type UmbBlockRteTypeModel ,
15
14
} from '@umbraco-cms/backoffice/block-rte' ;
16
15
import { UMB_PROPERTY_CONTEXT , UMB_PROPERTY_DATASET_CONTEXT } from '@umbraco-cms/backoffice/property' ;
17
- import type { UmbBlockValueType } from '@umbraco-cms/backoffice/block ' ;
16
+ import { observeMultiple } from '@umbraco-cms/backoffice/observable-api ' ;
18
17
19
18
// eslint-disable-next-line local-rules/enforce-element-suffix-on-element-class-name
20
19
export abstract class UmbPropertyEditorUiRteElementBase extends UmbLitElement implements UmbPropertyEditorUiElement {
@@ -39,7 +38,7 @@ export abstract class UmbPropertyEditorUiRteElementBase extends UmbLitElement im
39
38
public set value ( value : UmbPropertyEditorUiValueType | undefined ) {
40
39
if ( ! value ) {
41
40
this . _value = undefined ;
42
- this . _markup = '' ;
41
+ this . _markup = this . _latestMarkup = '' ;
43
42
this . #managerContext. setLayouts ( [ ] ) ;
44
43
this . #managerContext. setContents ( [ ] ) ;
45
44
this . #managerContext. setSettings ( [ ] ) ;
@@ -134,30 +133,38 @@ export abstract class UmbPropertyEditorUiRteElementBase extends UmbLitElement im
134
133
this . #managerContext. setLayouts ( layouts ) ;
135
134
} ) ;
136
135
137
- // Observe the value of the property and update the editor value.
138
- this . observe ( this . #managerContext. layouts , ( layouts ) => {
139
- const blocksValue =
140
- this . _value && layouts ?. length > 0
141
- ? { ...this . _value . blocks , layout : { [ UMB_BLOCK_RTE_PROPERTY_EDITOR_SCHEMA_ALIAS ] : layouts } }
142
- : undefined ;
143
-
144
- this . #setBlocksValue( blocksValue ) ;
145
- } ) ;
146
-
147
- this . observe ( this . #managerContext. contents , ( contents ) => {
148
- const blocksValue = this . _value ? { ...this . _value . blocks , contentData : contents } : undefined ;
149
- this . #setBlocksValue( blocksValue ) ;
150
- } ) ;
136
+ this . observe (
137
+ observeMultiple ( [
138
+ this . #managerContext. layouts ,
139
+ this . #managerContext. contents ,
140
+ this . #managerContext. settings ,
141
+ this . #managerContext. exposes ,
142
+ ] ) ,
143
+ ( [ layouts , contents , settings , exposes ] ) => {
144
+ if ( layouts . length === 0 ) {
145
+ this . _value = undefined ;
146
+ } else {
147
+ this . _value = {
148
+ markup : this . _latestMarkup ,
149
+ blocks : {
150
+ layout : { [ UMB_BLOCK_RTE_PROPERTY_EDITOR_SCHEMA_ALIAS ] : layouts } ,
151
+ contentData : contents ,
152
+ settingsData : settings ,
153
+ expose : exposes ,
154
+ } ,
155
+ } ;
156
+ }
151
157
152
- this . observe ( this . #managerContext. settings , ( settings ) => {
153
- const blocksValue = this . _value ? { ...this . _value . blocks , settingsData : settings } : undefined ;
154
- this . #setBlocksValue( blocksValue ) ;
155
- } ) ;
158
+ // If we don't have a value set from the outside or an internal value, we don't want to set the value.
159
+ // This is added to prevent the block list from setting an empty value on startup.
160
+ if ( ! this . _latestMarkup && ! this . _value ?. markup ) {
161
+ return ;
162
+ }
156
163
157
- this . observe ( this . #managerContext . exposes , ( exposes ) => {
158
- const blocksValue = this . _value ? { ... this . _value . blocks , expose : exposes } : undefined ;
159
- this . #setBlocksValue ( blocksValue ) ;
160
- } ) ;
164
+ context . setValue ( this . _value ) ;
165
+ } ,
166
+ 'motherObserver' ,
167
+ ) ;
161
168
} ) ;
162
169
163
170
this . consumeContext ( UMB_PROPERTY_DATASET_CONTEXT , ( context ) => {
@@ -181,19 +188,6 @@ export abstract class UmbPropertyEditorUiRteElementBase extends UmbLitElement im
181
188
} ) ;
182
189
}
183
190
184
- #setBlocksValue( blocksValue ?: UmbBlockValueType < UmbBlockRteLayoutModel > ) {
185
- if ( ! blocksValue || ! this . _value ) {
186
- return ;
187
- }
188
-
189
- this . _value = {
190
- ...this . _value ,
191
- blocks : blocksValue ,
192
- } ;
193
-
194
- this . _fireChangeEvent ( ) ;
195
- }
196
-
197
191
protected _fireChangeEvent ( ) {
198
192
this . dispatchEvent ( new UmbPropertyValueChangeEvent ( ) ) ;
199
193
}
0 commit comments