@@ -10,11 +10,10 @@ import type {
1010import {
1111 UmbBlockRteEntriesContext ,
1212 UmbBlockRteManagerContext ,
13- type UmbBlockRteLayoutModel ,
1413 type UmbBlockRteTypeModel ,
1514} from '@umbraco-cms/backoffice/block-rte' ;
1615import { 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 ' ;
1817
1918// eslint-disable-next-line local-rules/enforce-element-suffix-on-element-class-name
2019export abstract class UmbPropertyEditorUiRteElementBase extends UmbLitElement implements UmbPropertyEditorUiElement {
@@ -39,7 +38,7 @@ export abstract class UmbPropertyEditorUiRteElementBase extends UmbLitElement im
3938 public set value ( value : UmbPropertyEditorUiValueType | undefined ) {
4039 if ( ! value ) {
4140 this . _value = undefined ;
42- this . _markup = '' ;
41+ this . _markup = this . _latestMarkup = '' ;
4342 this . #managerContext. setLayouts ( [ ] ) ;
4443 this . #managerContext. setContents ( [ ] ) ;
4544 this . #managerContext. setSettings ( [ ] ) ;
@@ -134,30 +133,38 @@ export abstract class UmbPropertyEditorUiRteElementBase extends UmbLitElement im
134133 this . #managerContext. setLayouts ( layouts ) ;
135134 } ) ;
136135
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+ }
151157
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+ }
156163
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+ ) ;
161168 } ) ;
162169
163170 this . consumeContext ( UMB_PROPERTY_DATASET_CONTEXT , ( context ) => {
@@ -181,19 +188,6 @@ export abstract class UmbPropertyEditorUiRteElementBase extends UmbLitElement im
181188 } ) ;
182189 }
183190
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-
197191 protected _fireChangeEvent ( ) {
198192 this . dispatchEvent ( new UmbPropertyValueChangeEvent ( ) ) ;
199193 }
0 commit comments