@@ -141,6 +141,70 @@ export class UmbBlockWorkspaceContext<LayoutDataType extends UmbBlockLayoutBaseM
141
141
'observeLayoutInitially' ,
142
142
) ;
143
143
144
+ this . #observeBlockData( unique ) ;
145
+
146
+ if ( this . #liveEditingMode) {
147
+ this . #establishLiveSync( ) ;
148
+ }
149
+ }
150
+
151
+ async create ( contentElementTypeId : string ) {
152
+ await this . #retrieveBlockEntries;
153
+ await this . #retrieveModalContext;
154
+ if ( ! this . #blockEntries) {
155
+ throw new Error ( 'Block Entries not found' ) ;
156
+ return ;
157
+ }
158
+ if ( ! this . #modalContext) {
159
+ throw new Error ( 'Modal Context not found' ) ;
160
+ return ;
161
+ }
162
+
163
+ // TODO: Missing some way to append more layout data... this could be part of modal data, (or context api?)
164
+
165
+ this . setIsNew ( true ) ;
166
+
167
+ const blockCreated = await this . #blockEntries. create (
168
+ contentElementTypeId ,
169
+ { } ,
170
+ this . #modalContext. data as UmbBlockWorkspaceData ,
171
+ ) ;
172
+ if ( ! blockCreated ) {
173
+ throw new Error ( 'Block Entries could not create block' ) ;
174
+ }
175
+
176
+ // TODO: We should investigate if it makes sense to gather
177
+
178
+ if ( ! this . #liveEditingMode) {
179
+ this . #layout. setValue ( blockCreated . layout as LayoutDataType ) ;
180
+ this . content . setData ( blockCreated . content ) ;
181
+ if ( blockCreated . settings ) {
182
+ this . settings . setData ( blockCreated . settings ) ;
183
+ }
184
+ } else {
185
+ // Insert already, cause we are in live editing mode:
186
+ const blockInserted = await this . #blockEntries. insert (
187
+ blockCreated . layout ,
188
+ blockCreated . content ,
189
+ blockCreated . settings ,
190
+ this . #modalContext. data as UmbBlockWorkspaceData ,
191
+ ) ;
192
+ if ( ! blockInserted ) {
193
+ throw new Error ( 'Block Entries could not insert block' ) ;
194
+ }
195
+
196
+ const unique = blockCreated . layout . contentUdi ;
197
+
198
+ this . #observeBlockData( unique ) ;
199
+ this . #establishLiveSync( ) ;
200
+ }
201
+ }
202
+
203
+ #observeBlockData( unique : string ) {
204
+ if ( ! this . #blockEntries) {
205
+ throw new Error ( 'Block Entries not found' ) ;
206
+ return ;
207
+ }
144
208
this . observe (
145
209
this . #blockEntries. layoutOf ( unique ) ,
146
210
( layoutData ) => {
@@ -194,56 +258,6 @@ export class UmbBlockWorkspaceContext<LayoutDataType extends UmbBlockLayoutBaseM
194
258
} ,
195
259
'observeLayout' ,
196
260
) ;
197
-
198
- if ( this . #liveEditingMode) {
199
- this . #establishLiveSync( ) ;
200
- }
201
- }
202
-
203
- async create ( contentElementTypeId : string ) {
204
- await this . #retrieveBlockEntries;
205
- await this . #retrieveModalContext;
206
- if ( ! this . #blockEntries) {
207
- throw new Error ( 'Block Entries not found' ) ;
208
- return ;
209
- }
210
- if ( ! this . #modalContext) {
211
- throw new Error ( 'Modal Context not found' ) ;
212
- return ;
213
- }
214
-
215
- // TODO: Missing some way to append more layout data... this could be part of modal data, (or context api?)
216
-
217
- this . setIsNew ( true ) ;
218
-
219
- const blockCreated = await this . #blockEntries. create (
220
- contentElementTypeId ,
221
- { } ,
222
- this . #modalContext. data as UmbBlockWorkspaceData ,
223
- ) ;
224
- if ( ! blockCreated ) {
225
- throw new Error ( 'Block Entries could not create block' ) ;
226
- }
227
-
228
- this . #layout. setValue ( blockCreated . layout as LayoutDataType ) ;
229
- this . content . setData ( blockCreated . content ) ;
230
- if ( blockCreated . settings ) {
231
- this . settings . setData ( blockCreated . settings ) ;
232
- }
233
-
234
- if ( this . #liveEditingMode) {
235
- // Insert already, cause we are in live editing mode:
236
- const blockInserted = await this . #blockEntries. insert (
237
- blockCreated . layout ,
238
- blockCreated . content ,
239
- blockCreated . settings ,
240
- this . #modalContext. data as UmbBlockWorkspaceData ,
241
- ) ;
242
- if ( ! blockInserted ) {
243
- throw new Error ( 'Block Entries could not insert block' ) ;
244
- }
245
- this . #establishLiveSync( ) ;
246
- }
247
261
}
248
262
249
263
#establishLiveSync( ) {
0 commit comments