diff --git a/src/Roots/Acorn/Assets/Concerns/Enqueuable.php b/src/Roots/Acorn/Assets/Concerns/Enqueuable.php index 43652d81..e4f47f7a 100644 --- a/src/Roots/Acorn/Assets/Concerns/Enqueuable.php +++ b/src/Roots/Acorn/Assets/Concerns/Enqueuable.php @@ -78,6 +78,18 @@ public function enqueue() return $this->enqueueCss()->enqueueJs(); } + /** + * Add CSS files as editor styles in WordPress. + * + * @return $this + */ + public function editorStyles() + { + $this->css(fn ($handle, $src) => add_editor_style($src)); + + return $this; + } + /** * Dequeue CSS files in WordPress. * diff --git a/tests/Assets/BundleTest.php b/tests/Assets/BundleTest.php index 242e98ee..f360c472 100644 --- a/tests/Assets/BundleTest.php +++ b/tests/Assets/BundleTest.php @@ -42,6 +42,15 @@ $app->enqueueCss(); }); +it('can add editor styles', function () { + $manifest = json_decode(file_get_contents($this->fixture('bud_single_runtime/public/entrypoints.json')), JSON_OBJECT_AS_ARRAY); + $app = new Bundle('app', $manifest['app'], $this->fixture('bud_single_runtime'), 'https://k.jo'); + + $this->stub('add_editor_style', fn (...$args) => assertMatchesSnapshot($args)); + + $app->editorStyles(); +}); + it('can dequeue css', function () { $manifest = json_decode(file_get_contents($this->fixture('bud_single_runtime/public/entrypoints.json')), JSON_OBJECT_AS_ARRAY); $app = new Bundle('app', $manifest['app'], $this->fixture('bud_single_runtime'), 'https://k.jo'); diff --git a/tests/__snapshots__/BundleTest__it_can_add_editor_styles__1.yml b/tests/__snapshots__/BundleTest__it_can_add_editor_styles__1.yml new file mode 100644 index 00000000..19a9ad9d --- /dev/null +++ b/tests/__snapshots__/BundleTest__it_can_add_editor_styles__1.yml @@ -0,0 +1 @@ +- 'https://k.jo/public/app.2.4476c5f869ee7584ba3c.css'