Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const restrictedSyntax = [
// here. That's why we use \\u002F in the regexes below.
{
selector:
'ImportDeclaration[source.value=/^@wordpress\\u002F.+\\u002F/]',
'ImportDeclaration[source.value=/^@wordpress\\u002F.+\\u002F/]:not([source.value=/^@wordpress\\u002F.+\\u002Fbuild-types\\u002F/])',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why make this change? Isn't any other way of importing types from a package?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now no, third-party devs have been doing this forever. The other way is to export all types from the "index" of components which is being explored in its own PR. #72831

message: 'Path access on WordPress dependencies is not allowed.',
},
{
Expand Down
6 changes: 6 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,12 @@
"markdown_source": "../packages/blocks/README.md",
"parent": "packages"
},
{
"title": "@wordpress/boot",
"slug": "packages-boot",
"markdown_source": "../packages/boot/README.md",
"parent": "packages"
},
{
"title": "@wordpress/browserslist-config",
"slug": "packages-browserslist-config",
Expand Down
49 changes: 49 additions & 0 deletions lib/experimental/boot/boot-menu-items.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Boot package menu item registration API.
*
* @package gutenberg
*/

/**
* Registered menu items storage.
*
* @var array
*/
global $gutenberg_boot_menu_items;
$gutenberg_boot_menu_items = array();

/**
* Register a boot menu item.
*
* @param string $id Unique menu item ID.
* @param string $label Menu item label.
* @param string $to Route path the menu item links to.
* @param string $parent_id Optional parent menu item ID.
*/
function gutenberg_register_boot_menu_item( $id, $label, $to, $parent_id = '' ) {
global $gutenberg_boot_menu_items;

$menu_item = array(
'id' => $id,
'label' => $label,
'to' => $to,
);

// Only include parent if it's not empty (matches next-admin approach).
if ( ! empty( $parent_id ) ) {
$menu_item['parent'] = $parent_id;
}

$gutenberg_boot_menu_items[] = $menu_item;
}

/**
* Get all registered boot menu items.
*
* @return array Array of registered menu items.
*/
function gutenberg_get_boot_menu_items() {
global $gutenberg_boot_menu_items;
return $gutenberg_boot_menu_items;
}
193 changes: 193 additions & 0 deletions lib/experimental/boot/boot.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
<?php
/**
* Boot package - Minimal admin page with router and sidebar.
*
* @package gutenberg
*/

// Include route and menu APIs.
require_once __DIR__ . '/boot-menu-items.php';
require_once __DIR__ . '/preload.php';

/**
* Initialize boot admin page.
*/
function gutenberg_boot_admin_page() {
// Set current screen.
set_current_screen();

// Remove unwanted deprecated handler.
remove_action( 'admin_head', 'wp_admin_bar_header' );

// Remove unwanted scripts and styles that were enqueued during `admin_init`.
foreach ( wp_scripts()->queue as $script ) {
wp_dequeue_script( $script );
}
foreach ( wp_styles()->queue as $style ) {
wp_dequeue_style( $style );
}

// Fire init action for extensions to register routes and menu items.
do_action( 'gutenberg_boot_init' );

// Register some default menu items for demonstration.
gutenberg_register_boot_menu_item( 'home', __( 'Home', 'gutenberg' ), '/', '' );
gutenberg_register_boot_menu_item( 'about', __( 'About', 'gutenberg' ), '/', '' );
gutenberg_register_boot_menu_item( 'settings', __( 'Settings', 'gutenberg' ), '/', '' );

// Get routes and menu items.
$menu_items = gutenberg_get_boot_menu_items();

// Get boot module asset file for dependencies.
$asset_file = gutenberg_dir_path() . 'build/modules/boot/index.min.asset.php';
if ( file_exists( $asset_file ) ) {
$asset = require $asset_file;

// This script serves two purposes:
// 1. It ensures all the globals that are made available to the modules are loaded.
// 2. It initializes the boot module as an inline script.
wp_register_script( 'gutenberg-boot-prerequisites', '', $asset['dependencies'], $asset['version'], true );

// Add inline script to initialize the app.
wp_add_inline_script(
'gutenberg-boot-prerequisites',
sprintf(
'import("@wordpress/boot").then(mod => mod.init(%s));',
wp_json_encode( $menu_items, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
)
);

// Register prerequisites style by filtering script dependencies to find registered styles.
$style_dependencies = array_filter(
$asset['dependencies'],
function ( $handle ) {
return wp_style_is( $handle, 'registered' );
}
);
wp_register_style( 'gutenberg-boot-prerequisites', false, $style_dependencies, $asset['version'] );

// Dummy script module to ensure dependencies are loaded.
wp_register_script_module(
'gutenberg-boot',
gutenberg_url( 'lib/experimental/boot/loader.js' ),
array(
'import' => 'static',
'id' => '@wordpress/boot',
)
);

// Enqueue the boot scripts a,d styles.
wp_enqueue_script( 'gutenberg-boot-prerequisites' );
wp_enqueue_script_module( 'gutenberg-boot' );
wp_enqueue_style( 'gutenberg-boot-prerequisites' );
}

// Output the HTML.
?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php esc_html_e( 'Boot Demo', 'gutenberg' ); ?></title>
<style>
html {
background: #f1f1f1;
color: #444;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
font-size: 13px;
line-height: 1.4em;
}
body {
margin: 0;
}
#wpadminbar { display: none; }
</style>
<?php
global $hook_suffix;
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$hook_suffix = 'gutenberg-boot';

// BEGIN see wp-admin/admin-header.php.
print_admin_styles();
print_head_scripts();

/**
* Fires in head section for a specific admin page.
*
* @since 2.1.0
*/
do_action( "admin_head-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores

/**
* Fires in head section for all admin pages.
*
* @since 2.1.0
*/
do_action( 'admin_head' );
// END see wp-admin/admin-header.php.
?>
</head>
<body class="gutenberg-boot">
<div id="gutenberg-boot-app" style="height: 100vh; box-sizing: border-box;"></div>
<?php
// BEGIN see wp-admin/admin-footer.php.

/**
* Prints scripts or data before the default footer scripts.
*
* @since 1.2.0
*/
do_action( 'admin_footer', '' );

// Print import map first so it's available for inline scripts.
wp_script_modules()->print_import_map();
print_footer_scripts();
wp_script_modules()->print_enqueued_script_modules();
wp_script_modules()->print_script_module_preloads();
wp_script_modules()->print_script_module_data();

/**
* Prints scripts or data after the default footer scripts.
*
* @since 2.8.0
*/
do_action( "admin_footer-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
// END see wp-admin/admin-footer.php.
?>
</body>
</html>
<?php
exit;
}

/**
* Register boot admin page in WordPress admin menu.
*/
function gutenberg_register_boot_admin_page() {
add_submenu_page(
'nothing',
__( 'Boot Demo', 'gutenberg' ),
__( 'Boot Demo', 'gutenberg' ),
'manage_options',
'gutenberg-boot',
''
);
}

/**
* Render the boot admin page.
*
* This function checks if the current request is for the boot admin page
* and renders it, bypassing the default WordPress admin template.
*/
function gutenberg_boot_render_page() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( isset( $_GET['page'] ) && 'gutenberg-boot' === $_GET['page'] ) {
gutenberg_boot_admin_page();
exit;
}
}

add_action( 'admin_menu', 'gutenberg_register_boot_admin_page' );
add_action( 'admin_init', 'gutenberg_boot_render_page' );
Empty file.
37 changes: 37 additions & 0 deletions lib/experimental/boot/preload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Boot package REST API preloading.
*
* @package gutenberg
*/

/**
* Preload REST API data for boot admin page.
*
* Manually implements preloading without block editor dependencies.
*/
function gutenberg_boot_preload_site_data() {
// Define paths to preload - must match exact fields from entities.js
$preload_paths = array(
'/?_fields=description,gmt_offset,home,name,site_icon,site_icon_url,site_logo,timezone_string,url,page_for_posts,page_on_front,show_on_front',
array( '/wp/v2/settings', 'OPTIONS' ),
);

// Use rest_preload_api_request to gather the preloaded data
$preload_data = array_reduce(
$preload_paths,
'rest_preload_api_request',
array()
);

// Register the preloading middleware with wp-api-fetch
wp_add_inline_script(
'wp-api-fetch',
sprintf(
'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );',
wp_json_encode( $preload_data )
),
'after'
);
}
add_action( 'gutenberg_boot_init', 'gutenberg_boot_preload_site_data', 5 );
1 change: 1 addition & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/experimental/kses.php';
require __DIR__ . '/experimental/synchronization.php';
require __DIR__ . '/experimental/script-modules.php';
require __DIR__ . '/experimental/boot/boot.php';
require __DIR__ . '/experimental/posts/load.php';

if ( gutenberg_is_experiment_enabled( 'gutenberg-no-tinymce' ) ) {
Expand Down
Loading
Loading