@@ -44,7 +44,7 @@ public function index($themeCode)
4444 'config ' => [
4545 'baseUrl ' => parse_url (route ('visual.admin.editor ' , ['theme ' => $ themeCode ]), PHP_URL_PATH ),
4646 'imagesBaseUrl ' => Storage::disk (config ('bagisto_visual.images_storage ' ))->url ('' ),
47- 'storefrontUrl ' => url ('/ ' ). '? ' . http_build_query (['_designMode ' => $ themeCode ]),
47+ 'storefrontUrl ' => url ('/ ' ) . '? ' . http_build_query (['_designMode ' => $ themeCode ]),
4848 'channels ' => $ this ->getChannels (),
4949 'defaultChannel ' => core ()->getDefaultChannelCode (),
5050 'blockSchemas ' => $ this ->loadBlocks (),
@@ -87,13 +87,14 @@ public function persistUpdates(Request $request)
8787 'updates.regions ' => ['present ' , 'array ' ],
8888 ]);
8989
90- $ this ->persistEditorUpdates ->handle ($ validated );
90+ $ result = $ this ->persistEditorUpdates ->handle ($ validated );
91+ $ loadedBlocks = $ result ['loadedBlocks ' ] ?? [];
9192
92- $ changedBlockIds = $ this ->extractChangedBlockIds ($ validated ['updates ' ]);
93+ $ allBlockIds = $ this ->buildRenderSet ($ validated ['updates ' ], $ loadedBlocks );
9394
9495 $ url = $ request ->input ('template.url ' );
9596
96- return $ this ->renderPreview ->execute ($ url , $ changedBlockIds );
97+ return $ this ->renderPreview ->execute ($ url , $ allBlockIds );
9798 }
9899
99100 public function persistThemeSettings (Request $ request )
@@ -136,7 +137,7 @@ public function uploadImages(Request $request)
136137 return $ images ->map (function ($ image ) {
137138 $ originalName = pathinfo ($ image ->getClientOriginalName (), PATHINFO_FILENAME );
138139 $ extension = $ image ->guessExtension ();
139- $ storedName = bin2hex ($ originalName ). '_ ' . uniqid (). '. ' . $ extension ;
140+ $ storedName = bin2hex ($ originalName ) . '_ ' . uniqid () . '. ' . $ extension ;
140141
141142 $ path = $ image ->storeAs (
142143 config ('bagisto_visual.images_directory ' ),
@@ -211,15 +212,15 @@ public function icons(Request $request, Factory $factory, IconsManifest $iconsMa
211212
212213 $ icons ->push ([
213214 'name ' => $ name ,
214- 'id ' => $ set ['prefix ' ]. '- ' . $ name ,
215+ 'id ' => $ set ['prefix ' ] . '- ' . $ name ,
215216 'svg ' => File::get ($ file ->getRealPath ()),
216217 ]);
217218 }
218219 }
219220
220221 return [
221222 'currentSet ' => $ selectedSet ,
222- 'sets ' => collect ($ sets )->map (fn ($ set , $ key ) => ['id ' => $ key , 'prefix ' => $ set ['prefix ' ], 'name ' => Str::headline ($ key )])->values (),
223+ 'sets ' => collect ($ sets )->map (fn ($ set , $ key ) => ['id ' => $ key , 'prefix ' => $ set ['prefix ' ], 'name ' => Str::headline ($ key )])->values (),
223224 'icons ' => $ icons ->values (),
224225 ];
225226 }
@@ -262,7 +263,7 @@ protected function loadBlocks()
262263 'category ' => $ blockSchema ->category ,
263264 'description ' => $ blockSchema ->description ,
264265 'previewImageUrl ' => asset ($ blockSchema ->previewImageUrl ),
265- 'isSection ' => collect ([SimpleSection::class, BladeSection::class, LivewireSection::class])->some (fn ($ class ) => is_subclass_of ($ blockSchema ->class , $ class )),
266+ 'isSection ' => collect ([SimpleSection::class, BladeSection::class, LivewireSection::class])->some (fn ($ class ) => is_subclass_of ($ blockSchema ->class , $ class )),
266267 'enabledOn ' => $ blockSchema ->enabledOn ?? [],
267268 'disabledOn ' => $ blockSchema ->disabledOn ?? [],
268269 ],
@@ -294,7 +295,7 @@ protected function loadTheme($themeCode)
294295 protected function loadTemplates ()
295296 {
296297 return collect (app (\BagistoPlus \Visual \ThemeEditor::class)->getTemplates ())
297- ->map (fn ($ template ) => [
298+ ->map (fn ($ template ) => [
298299 'template ' => $ template ->template ,
299300 'label ' => $ template ->label ,
300301 'icon ' => $ template ->icon ,
@@ -331,7 +332,7 @@ protected function translateSettingsSchema(array $settingsSchema): array
331332
332333 protected function getChannels ()
333334 {
334- return core ()->getAllChannels ()->map (fn ($ channel ) => [
335+ return core ()->getAllChannels ()->map (fn ($ channel ) => [
335336 'code ' => $ channel ->code ,
336337 'name ' => $ channel ->name ,
337338 'locales ' => $ channel ->locales ,
@@ -342,7 +343,7 @@ protected function getChannels()
342343 protected function getChannelCodes (): array
343344 {
344345 return $ this ->getChannels ()
345- ->map (fn ($ channel ) => $ channel ['code ' ])
346+ ->map (fn ($ channel ) => $ channel ['code ' ])
346347 ->toArray ();
347348 }
348349
@@ -354,28 +355,66 @@ protected function getLocaleCodes(string $channel): array
354355 return [];
355356 }
356357
357- return $ channel ['locales ' ]->map (fn ($ locale ) => $ locale ['code ' ])->toArray ();
358+ return $ channel ['locales ' ]->map (fn ($ locale ) => $ locale ['code ' ])->toArray ();
358359 }
359360
360361 protected function getVisualThemes (): array
361362 {
362363 return collect (config ('themes.shop ' , []))
363- ->filter (fn ($ config ) => $ config ['visual_theme ' ] ?? false )
364- ->map (fn ($ config ) => $ config ['code ' ])
364+ ->filter (fn ($ config ) => $ config ['visual_theme ' ] ?? false )
365+ ->map (fn ($ config ) => $ config ['code ' ])
365366 ->toArray ();
366367 }
367368
368369 /**
369- * Extract changed block IDs from updates.
370- * Tree expansion (parents + children) happens during render via BlockRenderFilter.
370+ * Build complete render set: changed blocks + all their parents + all their children.
371371 */
372- protected function extractChangedBlockIds (array $ updates ): array
372+ protected function buildRenderSet (array $ updates, array $ loadedBlocks ): array
373373 {
374374 $ changes = $ updates ['changes ' ] ?? [];
375-
376- return array_merge (
375+ $ changedIds = array_merge (
377376 $ changes ['added ' ] ?? [],
378377 $ changes ['updated ' ] ?? []
379378 );
379+
380+ $ renderSet = [];
381+
382+ foreach ($ changedIds as $ id ) {
383+ $ renderSet [] = $ id ;
384+
385+ // Walk up parent chain
386+ $ currentId = $ id ;
387+ while (isset ($ loadedBlocks [$ currentId ]['parentId ' ]) && $ loadedBlocks [$ currentId ]['parentId ' ]) {
388+ $ parentId = $ loadedBlocks [$ currentId ]['parentId ' ];
389+ $ renderSet [] = $ parentId ;
390+
391+ // If parent is a repeated block, include its entire children structure
392+ if (isset ($ loadedBlocks [$ parentId ]['repeated ' ]) && $ loadedBlocks [$ parentId ]['repeated ' ]) {
393+ $ this ->addChildren ($ parentId , $ loadedBlocks , $ renderSet );
394+ }
395+
396+ $ currentId = $ parentId ;
397+ }
398+
399+ // Walk down children
400+ $ this ->addChildren ($ id , $ loadedBlocks , $ renderSet );
401+ }
402+
403+ return array_unique ($ renderSet );
404+ }
405+
406+ /**
407+ * Recursively add all children to the render set.
408+ */
409+ protected function addChildren (string $ blockId , array $ loadedBlocks , array &$ renderSet ): void
410+ {
411+ if (! isset ($ loadedBlocks [$ blockId ]['children ' ])) {
412+ return ;
413+ }
414+
415+ foreach ($ loadedBlocks [$ blockId ]['children ' ] as $ childId ) {
416+ $ renderSet [] = $ childId ;
417+ $ this ->addChildren ($ childId , $ loadedBlocks , $ renderSet );
418+ }
380419 }
381420}
0 commit comments