| @@ -10,12 +10,10 @@ | ||
| 10 | 10 | */ |
| 11 | 11 | declare (strict_types=1); |
| 12 | 12 | namespace WindPress\WindPress\Integration\Gutenberg; |
| 13 | 13 | |
| 14 | -use WIND_PRESS; | |
| 15 | -use WindPress\WindPress\Core\Runtime; | |
| 16 | 14 | use WindPress\WindPress\Integration\IntegrationInterface; |
| 17 | -use WindPress\WindPress\Utils\AssetVite; | |
| 15 | +use WindPress\WindPress\Utils\Common; | |
| 18 | 16 | use WindPress\WindPress\Utils\Config; |
| 19 | 17 | /** |
| 20 | 18 | * @author Joshua Gugun Siagian <suabahasa@gmail.com> |
| 21 | 19 | */ |
| @@ -22,13 +20,14 @@ | ||
| 22 | 20 | class Main implements IntegrationInterface |
| 23 | 21 | { |
| 24 | 22 | public function __construct() |
| 25 | 23 | { |
| 26 | - // TODO: implement the integration | |
| 27 | - return; | |
| 28 | 24 | add_filter('f!windpress/core/cache:compile.providers', fn(array $providers): array => $this->register_provider($providers)); |
| 29 | 25 | if ($this->is_enabled()) { |
| 30 | - add_action('enqueue_block_editor_assets', fn() => $this->enqueue_block_editor_assets()); | |
| 26 | + if (Config::get(sprintf('integration.%s.editor.enabled', $this->get_name()), \true)) { | |
| 27 | + new \WindPress\WindPress\Integration\Gutenberg\Editor(); | |
| 28 | + } | |
| 29 | + \WindPress\WindPress\Integration\Gutenberg\CommonBlock::get_instance(); | |
| 31 | 30 | } |
| 32 | 31 | } |
| 33 | 32 | public function get_name(): string |
| 34 | 33 | { |
| @@ -39,30 +38,13 @@ | ||
| 39 | 38 | return (bool) apply_filters('f!windpress/integration/gutenberg:enabled', Config::get(sprintf('integration.%s.enabled', $this->get_name()), \true)); |
| 40 | 39 | } |
| 41 | 40 | public function register_provider(array $providers): array |
| 42 | 41 | { |
| 43 | - $providers[] = ['id' => $this->get_name(), 'name' => 'Gutenberg', 'description' => 'Gutenberg integration', 'callback' => \WindPress\WindPress\Integration\Gutenberg\Compile::class, 'enabled' => $this->is_enabled()]; | |
| 42 | + $providers[] = ['id' => $this->get_name(), 'name' => __('Gutenberg', 'windpress'), 'description' => __('Gutenberg/Block Editor integration', 'windpress'), 'source_index' => 1, 'callback' => Config::get(sprintf('integration.%s.compile.enabled', $this->get_name()), \true) ? \WindPress\WindPress\Integration\Gutenberg\Compile::class : static fn() => [], 'enabled' => $this->is_enabled(), 'type' => 'custom', 'homepage' => 'https://wordpress.org/gutenberg/?ref=jooosi', 'is_installed_active' => static function () { | |
| 43 | + $is = -1; | |
| 44 | + $is += function_exists('register_block_type') ? 1 : 0; | |
| 45 | + $is += function_exists('register_block_type') ? 1 : 0; | |
| 46 | + return $is; | |
| 47 | + }]; | |
| 44 | 48 | 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 | 49 | } |
| 68 | 50 | } |