@@ -76,22 +76,63 @@ export default class MetaMomentumPropertyEditorUIElement extends UmbLitElement i
7676
7777 constructor ( ) {
7878 super ( ) ;
79-
80-
79+
80+
8181 this . consumeContext ( UMB_DOCUMENT_WORKSPACE_CONTEXT , ( _instance ) => {
8282
8383 this . workspaceContext = _instance ;
84-
84+
85+ //this.value has been loaded, so we can do any migration or initialisation required here
86+
87+ if ( ! this . value ) {
88+ this . value = {
89+ title : "" ,
90+ description : "" ,
91+ noIndex : false ,
92+ shareTitle : "" ,
93+ shareDescription : "" ,
94+ shareImage : undefined ,
95+ default : {
96+ title : "" ,
97+ description : "" ,
98+ } ,
99+ share : {
100+ title : "" ,
101+ description : "" ,
102+ image : undefined ,
103+ } ,
104+ } ;
105+
106+ }
107+
108+
109+ // Migrate old image format if needed
110+
111+ if ( this . value . share ?. image ) {
112+ let testOldImgFormat : any = this . value . share . image as any ;
113+ if ( testOldImgFormat ?. key ) {
114+ var share = {
115+
116+ ...this . value . share ,
117+ ...{ image : testOldImgFormat . key }
118+ } ;
119+ this . value = { ...this . value , ...{ share : share } } ;
120+
121+ }
122+ }
123+
124+
125+
85126 this . initValue ( ) ;
86-
127+
87128 this . initNodeUrl ( ) ;
88129
89130
90- //;
91- // this.workspaceContext.urls?.subscribe((data) => {
92- // debugger;
93- // var previousNodeUrl = data;
94- // });
131+ //;
132+ // this.workspaceContext.urls?.subscribe((data) => {
133+ // debugger;
134+ // var previousNodeUrl = data;
135+ // });
95136
96137
97138
@@ -106,6 +147,7 @@ export default class MetaMomentumPropertyEditorUIElement extends UmbLitElement i
106147
107148 const imageFields = [ ...( this . #config?. fallbackImageFields ?? [ ] ) ] ;
108149
150+ if ( ! context ) return ; //for some reason the context is undefined sometimes
109151 // Keep track of the name field separately
110152 this . observe ( context . name , ( name ) => {
111153 console . log ( "Setting fallbackValue: name to " + name ) ;
@@ -169,7 +211,7 @@ export default class MetaMomentumPropertyEditorUIElement extends UmbLitElement i
169211
170212 } ) ;
171213
172-
214+
173215
174216 } ) ;
175217
@@ -180,7 +222,7 @@ export default class MetaMomentumPropertyEditorUIElement extends UmbLitElement i
180222 } ) ;
181223
182224
183-
225+
184226
185227
186228 }
@@ -191,30 +233,27 @@ export default class MetaMomentumPropertyEditorUIElement extends UmbLitElement i
191233 initValue ( ) {
192234
193235
194- if ( ! this . value ) {
195- this . value = {
196- title : "" ,
197- description : "" ,
198- noIndex : false ,
199- shareTitle : "" ,
200- shareDescription : "" ,
201- shareImage : undefined ,
202- default : {
203- title : "" ,
204- description : "" ,
205- } ,
206- share : {
207- title : "" ,
208- description : "" ,
209- image : undefined ,
210- } ,
211- } ;
236+ // if (!this.value) {
237+ // this.value = {
238+ // title: "",
239+ // description: "",
240+ // noIndex: false,
241+ // shareTitle: "",
242+ // shareDescription: "",
243+ // shareImage: undefined,
244+ // default: {
245+ // title: "",
246+ // description: "",
247+ // },
248+ // share: {
249+ // title: "",
250+ // description: "",
251+ // image: undefined,
252+ // },
253+ // };
212254
213- }
255+ // }
214256
215- // This is for backwards compatibility. Previous versions stored the media as a UDI string, and we now just use the guid
216- //TODO: come back and check backwards compatibility
217- //this.value = { ...this.value, ...{shareImage: this.value.shareImage?.convertUdiToGuid() } };
218257
219258
220259 //this.#updateShareImageUrls();
@@ -226,12 +265,12 @@ export default class MetaMomentumPropertyEditorUIElement extends UmbLitElement i
226265 // Updates the preview values based on the current value and fallback values
227266 #updatePreviewValues( ) {
228267 this . initValue ( ) ;
229- let title = this . #getFallbackStringValue( this . #config?. fallbackTitleFields , this . value . default ?. title ) ;
230- let description = this . #getFallbackStringValue( this . #config?. fallbackDescriptionFields , this . value . default . description ) ;
268+ let title = this . #getFallbackStringValue( this . #config?. fallbackTitleFields , this . value ? .default ?. title ) ;
269+ let description = this . #getFallbackStringValue( this . #config?. fallbackDescriptionFields , this . value ? .default ? .description ) ;
231270
232271
233- let shareTitle = this . #getFallbackStringValue( this . #config?. fallbackTitleFields , this . value . share . title , this . value . default . title ) ;
234- let shareDescription = this . #getFallbackStringValue( this . #config?. fallbackDescriptionFields , this . value . share . description , this . value . default . description ) ;
272+ let shareTitle = this . #getFallbackStringValue( this . #config?. fallbackTitleFields , this . value ? .share ? .title , this . value ? .default ? .title ) ;
273+ let shareDescription = this . #getFallbackStringValue( this . #config?. fallbackDescriptionFields , this . value ? .share ? .description , this . value ? .default ? .description ) ;
235274
236275 this . value = { ...this . value , ...{ title : title , description : description , shareTitle : shareTitle , shareDescription : shareDescription } } ;
237276 }
@@ -241,11 +280,12 @@ export default class MetaMomentumPropertyEditorUIElement extends UmbLitElement i
241280 let result : string = "" ;
242281 this . initValue ( ) ;
243282
244- if ( customValue !== undefined && customValue !== "" ) {
283+ if ( customValue ) {
245284 return customValue ;
246- } else if ( customFallbackValue !== null && customFallbackValue !== "" ) {
285+ } else if ( customFallbackValue ) {
247286 return customFallbackValue ;
248287 } else {
288+ //fallback to external fields
249289 for ( let i = 0 ; i < ( fieldAliases ?. length ?? 0 ) ; i ++ ) {
250290
251291 let field = fieldAliases ! [ i ] ;
@@ -359,8 +399,8 @@ export default class MetaMomentumPropertyEditorUIElement extends UmbLitElement i
359399
360400 var share = { ...this . value . share , ...{ image : newShareImageValue } } ;
361401 this . value = { ...this . value , ...{ share : share } } ;
362-
363-
402+
403+
364404
365405 await this . #updateShareImage( ) ;
366406 //Notify Umbraco that the value has changed to do IsDirty Check
@@ -383,7 +423,7 @@ export default class MetaMomentumPropertyEditorUIElement extends UmbLitElement i
383423 // [this.value.share!.image!], 0, 0
384424 //);
385425
386-
426+
387427
388428 //if (value?.share?.image !== undefined && value.share.image !== null) {
389429 // this.value = {
@@ -414,12 +454,14 @@ export default class MetaMomentumPropertyEditorUIElement extends UmbLitElement i
414454
415455 const unique = this . value ?. shareImage !== undefined ? this . value ?. shareImage : undefined ;
416456
417-
418457 console . log ( unique )
419458 if ( unique == undefined || unique == "" ) {
420459 return ;
421460 }
422461
462+
463+
464+
423465 let imageData = (
424466 await this . imagingRepository . requestThumbnailUrls (
425467 [ unique ] ,
0 commit comments