@@ -72,8 +72,6 @@ export class UmbDataTypeWorkspaceContext
7272
7373 #settingsDefaultData?: Array < PropertyEditorSettingsDefaultData > ;
7474
75- #propertyEditorUISettingsSchemaAlias?: string ;
76-
7775 #propertyEditorUiIcon = new UmbStringState < string | null > ( null ) ;
7876 readonly propertyEditorUiIcon = this . #propertyEditorUiIcon. asObservable ( ) ;
7977
@@ -82,6 +80,8 @@ export class UmbDataTypeWorkspaceContext
8280
8381 constructor ( host : UmbControllerHost ) {
8482 super ( host , 'Umb.Workspace.DataType' ) ;
83+
84+ this . #observePropertyEditorSchemaAlias( ) ;
8585 this . #observePropertyEditorUIAlias( ) ;
8686
8787 this . routes . setRoutes ( [
@@ -121,7 +121,7 @@ export class UmbDataTypeWorkspaceContext
121121 this . #propertyEditorUISettingsDefaultData = [ ] ;
122122 this . #settingsDefaultData = undefined ;
123123
124- this . _mergeConfigProperties ( ) ;
124+ this . #mergeConfigProperties ( ) ;
125125 }
126126
127127 // Hold the last set property editor ui alias, so we know when it changes, so we can reset values. [NL]
@@ -131,30 +131,13 @@ export class UmbDataTypeWorkspaceContext
131131 this . observe (
132132 this . propertyEditorUiAlias ,
133133 async ( propertyEditorUiAlias ) => {
134- const previousPropertyEditorUIAlias = this . #lastPropertyEditorUIAlias;
135- this . #lastPropertyEditorUIAlias = propertyEditorUiAlias ;
134+ this . #propertyEditorUISettingsProperties = [ ] ;
135+ this . #propertyEditorUISettingsDefaultData = [ ] ;
136+
136137 // we only want to react on the change if the alias is set or null. When it is undefined something is still loading
137138 if ( propertyEditorUiAlias === undefined ) return ;
138139
139- // if the property editor ui alias is not set, we use the default alias from the schema
140- if ( propertyEditorUiAlias === null ) {
141- await this . #observePropertyEditorSchemaAlias( ) ;
142- if ( this . #propertyEditorSchemaConfigDefaultUIAlias !== null ) {
143- this . setPropertyEditorUiAlias ( this . #propertyEditorSchemaConfigDefaultUIAlias) ;
144- }
145- } else {
146- await this . #setPropertyEditorUIConfig( propertyEditorUiAlias ) ;
147- this . setPropertyEditorSchemaAlias ( this . #propertyEditorUISettingsSchemaAlias! ) ;
148- await this . #observePropertyEditorSchemaAlias( ) ;
149- }
150-
151- if (
152- this . getIsNew ( ) ||
153- ( previousPropertyEditorUIAlias && previousPropertyEditorUIAlias !== propertyEditorUiAlias )
154- ) {
155- this . #transferConfigDefaultData( ) ;
156- }
157- this . _mergeConfigProperties ( ) ;
140+ this . #observePropertyEditorUIConfig( propertyEditorUiAlias ) ;
158141 } ,
159142 'editorUiAlias' ,
160143 ) ;
@@ -164,13 +147,19 @@ export class UmbDataTypeWorkspaceContext
164147 return this . observe (
165148 this . propertyEditorSchemaAlias ,
166149 ( propertyEditorSchemaAlias ) => {
167- this . #setPropertyEditorSchemaConfig( propertyEditorSchemaAlias ) ;
150+ this . #propertyEditorSchemaSettingsProperties = [ ] ;
151+ this . #propertyEditorSchemaSettingsDefaultData = [ ] ;
152+ this . #observePropertyEditorSchemaConfig( propertyEditorSchemaAlias ) ;
168153 } ,
169154 'schemaAlias' ,
170- ) . asPromise ( ) ;
155+ ) ;
171156 }
172157
173- #setPropertyEditorSchemaConfig( propertyEditorSchemaAlias ?: string ) {
158+ #observePropertyEditorSchemaConfig( propertyEditorSchemaAlias ?: string ) {
159+ if ( ! propertyEditorSchemaAlias ) {
160+ this . removeUmbControllerByAlias ( 'schema' ) ;
161+ return ;
162+ }
174163 this . observe (
175164 propertyEditorSchemaAlias
176165 ? umbExtensionsRegistry . byTypeAndAlias ( 'propertyEditorSchema' , propertyEditorSchemaAlias )
@@ -183,36 +172,56 @@ export class UmbDataTypeWorkspaceContext
183172 } ) ) ;
184173 this . #propertyEditorSchemaSettingsDefaultData = manifest ?. meta . settings ?. defaultData || [ ] ;
185174 this . #propertyEditorSchemaConfigDefaultUIAlias = manifest ?. meta . defaultPropertyEditorUiAlias || null ;
175+ if ( this . #propertyEditorSchemaConfigDefaultUIAlias && this . getPropertyEditorUiAlias ( ) === null ) {
176+ // Fallback to the default property editor ui for this property editor schema.
177+ this . setPropertyEditorUiAlias ( this . #propertyEditorSchemaConfigDefaultUIAlias) ;
178+ }
179+ this . #mergeConfigProperties( ) ;
186180 } ,
187181 'schema' ,
188182 ) ;
189183 }
190184
191- #setPropertyEditorUIConfig( propertyEditorUIAlias : string ) {
192- return this . observe (
185+ #observePropertyEditorUIConfig( propertyEditorUIAlias : string | null ) {
186+ if ( ! propertyEditorUIAlias ) {
187+ this . removeUmbControllerByAlias ( 'editorUi' ) ;
188+ return ;
189+ }
190+ this . observe (
193191 umbExtensionsRegistry . byTypeAndAlias ( 'propertyEditorUi' , propertyEditorUIAlias ) ,
194192 ( manifest ) => {
195193 this . #propertyEditorUiIcon. setValue ( manifest ?. meta . icon || null ) ;
196194 this . #propertyEditorUiName. setValue ( manifest ?. name || null ) ;
197195
198- this . #propertyEditorUISettingsSchemaAlias = manifest ?. meta . propertyEditorSchemaAlias ;
199196 // Maps properties to have a weight, so they can be sorted, notice UI properties have a +1000 weight compared to schema properties.
200197 this . #propertyEditorUISettingsProperties = ( manifest ?. meta . settings ?. properties ?? [ ] ) . map ( ( x , i ) => ( {
201198 ...x ,
202199 weight : x . weight ?? 1000 + i ,
203200 } ) ) ;
204201 this . #propertyEditorUISettingsDefaultData = manifest ?. meta . settings ?. defaultData || [ ] ;
202+ this . setPropertyEditorSchemaAlias ( manifest ?. meta . propertyEditorSchemaAlias ) ;
203+ this . #mergeConfigProperties( ) ;
205204 } ,
206205 'editorUi' ,
207- ) . asPromise ( ) ;
206+ ) ;
208207 }
209208
210- private _mergeConfigProperties ( ) {
209+ #mergeConfigProperties ( ) {
211210 if ( this . #propertyEditorSchemaSettingsProperties && this . #propertyEditorUISettingsProperties) {
212211 // Reset the value to this array, and then afterwards append:
213212 this . #properties. setValue ( this . #propertyEditorSchemaSettingsProperties) ;
214213 // Append the UI settings properties to the schema properties, so they can override the schema properties:
215214 this . #properties. append ( this . #propertyEditorUISettingsProperties) ;
215+
216+ // If new or if the alias was changed then set default values.
217+ const previousPropertyEditorUIAlias = this . #lastPropertyEditorUIAlias;
218+ this . #lastPropertyEditorUIAlias = this . getPropertyEditorUiAlias ( ) ;
219+ if (
220+ this . getIsNew ( ) ||
221+ ( previousPropertyEditorUIAlias && previousPropertyEditorUIAlias !== this . #lastPropertyEditorUIAlias)
222+ ) {
223+ this . #transferConfigDefaultData( ) ;
224+ }
216225 }
217226 }
218227
@@ -301,9 +310,15 @@ export class UmbDataTypeWorkspaceContext
301310 this . #currentData. update ( { name } ) ;
302311 }
303312
313+ getPropertyEditorSchemaAlias ( ) {
314+ return this . #currentData. getValue ( ) ?. editorAlias ;
315+ }
304316 setPropertyEditorSchemaAlias ( alias ?: string ) {
305317 this . #currentData. update ( { editorAlias : alias } ) ;
306318 }
319+ getPropertyEditorUiAlias ( ) {
320+ return this . #currentData. getValue ( ) ?. editorUiAlias ;
321+ }
307322 setPropertyEditorUiAlias ( alias ?: string ) {
308323 this . #currentData. update ( { editorUiAlias : alias } ) ;
309324 }
0 commit comments