| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of the WindPress package. |
| 5 |
* |
| 6 |
* (c) Joshua Gugun Siagian <suabahasa@gmail.com> |
| 7 |
* |
| 8 |
* For the full copyright and license information, please view the LICENSE |
| 9 |
* file that was distributed with this source code. |
| 10 |
*/ |
| 11 |
declare (strict_types=1); |
| 12 |
namespace WindPress\WindPress\Integration\Gutenberg; |
| 13 |
|
| 14 |
use WIND_PRESS; |
| 15 |
use WindPress\WindPress\Core\Runtime; |
| 16 |
use WindPress\WindPress\Integration\IntegrationInterface; |
| 17 |
use WindPress\WindPress\Utils\AssetVite; |
| 18 |
use WindPress\WindPress\Utils\Config; |
| 19 |
/** |
| 20 |
* @author Joshua Gugun Siagian <suabahasa@gmail.com> |
| 21 |
*/ |
| 22 |
class Main implements IntegrationInterface |
| 23 |
{ |
| 24 |
public function __construct() |
| 25 |
{ |
| 26 |
// TODO: implement the integration |
| 27 |
return; |
| 28 |
\add_filter('f!windpress/core/cache:compile.providers', fn(array $providers): array => $this->register_provider($providers)); |
| 29 |
if ($this->is_enabled()) { |
| 30 |
\add_action('enqueue_block_editor_assets', fn() => $this->enqueue_block_editor_assets()); |
| 31 |
} |
| 32 |
} |
| 33 |
public function get_name() : string |
| 34 |
{ |
| 35 |
return 'gutenberg'; |
| 36 |
} |
| 37 |
public function is_enabled() : bool |
| 38 |
{ |
| 39 |
return (bool) \apply_filters('f!windpress/integration/gutenberg:enabled', Config::get(\sprintf('integration.%s.enabled', $this->get_name()), \true)); |
| 40 |
} |
| 41 |
public function register_provider(array $providers) : array |
| 42 |
{ |
| 43 |
$providers[] = ['id' => $this->get_name(), 'name' => 'Gutenberg', 'description' => 'Gutenberg integration', 'callback' => \WindPress\WindPress\Integration\Gutenberg\Compile::class, 'enabled' => $this->is_enabled()]; |
| 44 |
return $providers; |
| 45 |
} |
| 46 |
public function enqueue_block_editor_assets() |
| 47 |
{ |
| 48 |
$screen = \get_current_screen(); |
| 49 |
if (\is_admin() && $screen->is_block_editor()) { |
| 50 |
\add_action('admin_head', fn() => $this->admin_head(), 1000001); |
| 51 |
} |
| 52 |
} |
| 53 |
public function admin_head() |
| 54 |
{ |
| 55 |
// Runtime::get_instance()->enqueue_importmap(); |
| 56 |
Runtime::get_instance()->enqueue_play_cdn(); |
| 57 |
if (\strpos($_SERVER['REQUEST_URI'], 'site-editor.php') !== \false) { |
| 58 |
// wp_enqueue_script(WIND_PRESS::WP_OPTION . '-gutenberg-fse', plugin_dir_url(WIND_PRESS::FILE) . 'build/public/gutenberg/fse.js', [], WIND_PRESS::VERSION, true); |
| 59 |
} else { |
| 60 |
// wp_enqueue_script(WIND_PRESS::WP_OPTION . '-gutenberg-observer', plugin_dir_url(WIND_PRESS::FILE) . 'build/public/gutenberg/observer.js', [], WIND_PRESS::VERSION, true); |
| 61 |
// AssetVite::get_instance()->enqueue_asset('assets/integration/gutenberg/post-editor.js', [ |
| 62 |
// 'handle' => WIND_PRESS::WP_OPTION . ':integration-gutenberg-post-editor', |
| 63 |
// 'in-footer' => true, |
| 64 |
// ]); |
| 65 |
AssetVite::get_instance()->enqueue_asset('assets/integration/gutenberg/block-editor.jsx', ['handle' => WIND_PRESS::WP_OPTION . ':integration-gutenberg-block-editor', 'in-footer' => \true, 'dependencies' => ['wp-blocks', 'wp-element', 'wp-editor', 'wp-components', 'wp-i18n', 'react', 'react-dom']]); |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
|