| 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\LiveCanvas; |
| 13 |
|
| 14 |
use WIND_PRESS; |
| 15 |
use WindPress\WindPress\Admin\AdminPage; |
| 16 |
use WindPress\WindPress\Utils\Vite; |
| 17 |
/** |
| 18 |
* @author Joshua Gugun Siagian <suabahasa@gmail.com> |
| 19 |
*/ |
| 20 |
class Editor |
| 21 |
{ |
| 22 |
public function __construct() |
| 23 |
{ |
| 24 |
add_action('lc_editor_before_body_closing', fn() => $this->register_livecanvas_autocomplete(), 1000001); |
| 25 |
} |
| 26 |
public function register_livecanvas_autocomplete() |
| 27 |
{ |
| 28 |
$handle = WIND_PRESS::WP_OPTION . ':integration-livecanvas-editor'; |
| 29 |
Vite::assets()->enqueue('resources/integration/livecanvas/main.js', ['handle' => $handle, 'in_footer' => \true, 'dependencies' => ['wp-hooks']]); |
| 30 |
wp_localize_script($handle, 'windpresslivecanvas', ['_version' => WIND_PRESS::VERSION, 'assets' => ['url' => Vite::base_url()], 'site_meta' => ['name' => get_bloginfo('name'), 'site_url' => get_site_url(), 'admin_url' => AdminPage::get_page_url()]]); |
| 31 |
$wp_scripts = wp_scripts(); |
| 32 |
$queue = $wp_scripts->queue; |
| 33 |
foreach ($queue as $handle) { |
| 34 |
if (strpos($handle, WIND_PRESS::WP_OPTION . ':') !== 0) { |
| 35 |
continue; |
| 36 |
} |
| 37 |
$wp_scripts->do_items($handle); |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
|