Skip to content

Commit

Permalink
inject editor css
Browse files Browse the repository at this point in the history
  • Loading branch information
retlehs committed Jan 20, 2025
1 parent df5a4a8 commit e4c1c50
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions app/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,28 @@
});

/**
* Inject assets into the block editor.
* Inject CSS into the block editor iframe.
*
* @return void
* @return array
*/
add_filter('block_editor_settings_all', function ($settings) {
$manifest = File::json(public_path('build/manifest.json')) ?? [];

if (isset($manifest['resources/css/editor.css'])) {
$css_path = public_path("build/{$manifest['resources/css/editor.css']['file']}");

if (file_exists($css_path)) {
$settings['styles'][] = [
'css' => file_get_contents($css_path),
];
}
}

return $settings;
});

/**
* Inject JS into the block editor.
*/
add_filter('admin_head', function () {
$screen = get_current_screen();
Expand All @@ -43,7 +62,6 @@
}

echo Str::wrap(app('assets.vite')([
'resources/css/editor.css',
'resources/js/editor.js',
]), "\n");
});
Expand Down

0 comments on commit e4c1c50

Please sign in to comment.