@wordpress/build 0.9.0 → 0.10.1-next.v.202603102151.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,277 +15,263 @@ global ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_routes, ${{PREFIX}}_{{PAGE_
15
15
  ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_routes = array();
16
16
  ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_menu_items = array();
17
17
 
18
- if ( ! function_exists( '{{PREFIX}}_register_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_route' ) ) {
19
- /**
20
- * Register a route for the {{PAGE_SLUG}}-wp-admin page.
21
- *
22
- * @param string $path Route path (e.g., '/types/$type/edit/$id').
23
- * @param string|null $content_module Script module ID for content (stage/inspector).
24
- * @param string|null $route_module Script module ID for route lifecycle hooks.
25
- */
26
- function {{PREFIX}}_register_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_route( $path, $content_module = null, $route_module = null ) {
27
- global ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_routes;
28
-
29
- $route = array( 'path' => $path );
30
- if ( ! empty( $content_module ) ) {
31
- $route['content_module'] = $content_module;
32
- }
33
- if ( ! empty( $route_module ) ) {
34
- $route['route_module'] = $route_module;
35
- }
18
+ /**
19
+ * Register a route for the {{PAGE_SLUG}}-wp-admin page.
20
+ *
21
+ * @param string $path Route path (e.g., '/types/$type/edit/$id').
22
+ * @param string|null $content_module Script module ID for content (stage/inspector).
23
+ * @param string|null $route_module Script module ID for route lifecycle hooks.
24
+ */
25
+ function {{PREFIX}}_register_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_route( $path, $content_module = null, $route_module = null ) {
26
+ global ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_routes;
36
27
 
37
- ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_routes[] = $route;
28
+ $route = array( 'path' => $path );
29
+ if ( ! empty( $content_module ) ) {
30
+ $route['content_module'] = $content_module;
38
31
  }
32
+ if ( ! empty( $route_module ) ) {
33
+ $route['route_module'] = $route_module;
34
+ }
35
+
36
+ ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_routes[] = $route;
39
37
  }
40
38
 
41
- if ( ! function_exists( '{{PREFIX}}_register_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_menu_item' ) ) {
42
- /**
43
- * Register a menu item for the {{PAGE_SLUG}}-wp-admin page.
44
- * Note: Menu items are registered but not displayed in single-page mode.
45
- *
46
- * @param string $id Menu item ID.
47
- * @param string $label Display label.
48
- * @param string $to Route path to navigate to.
49
- * @param string $parent_id Optional. Parent menu item ID.
50
- */
51
- function {{PREFIX}}_register_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_menu_item( $id, $label, $to, $parent_id = '' ) {
52
- global ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_menu_items;
53
-
54
- $menu_item = array(
55
- 'id' => $id,
56
- 'label' => $label,
57
- 'to' => $to,
58
- );
39
+ /**
40
+ * Register a menu item for the {{PAGE_SLUG}}-wp-admin page.
41
+ * Note: Menu items are registered but not displayed in single-page mode.
42
+ *
43
+ * @param string $id Menu item ID.
44
+ * @param string $label Display label.
45
+ * @param string $to Route path to navigate to.
46
+ * @param string $parent_id Optional. Parent menu item ID.
47
+ */
48
+ function {{PREFIX}}_register_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_menu_item( $id, $label, $to, $parent_id = '' ) {
49
+ global ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_menu_items;
59
50
 
60
- if ( ! empty( $parent_id ) ) {
61
- $menu_item['parent'] = $parent_id;
62
- }
51
+ $menu_item = array(
52
+ 'id' => $id,
53
+ 'label' => $label,
54
+ 'to' => $to,
55
+ );
63
56
 
64
- ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_menu_items[] = $menu_item;
57
+ if ( ! empty( $parent_id ) ) {
58
+ $menu_item['parent'] = $parent_id;
65
59
  }
60
+
61
+ ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_menu_items[] = $menu_item;
66
62
  }
67
63
 
68
- if ( ! function_exists( '{{PREFIX}}_get_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_routes' ) ) {
69
- /**
70
- * Get all registered routes for the {{PAGE_SLUG}}-wp-admin page.
71
- *
72
- * @return array Array of route objects.
73
- */
74
- function {{PREFIX}}_get_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_routes() {
75
- global ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_routes;
76
- return ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_routes ?? array();
77
- }
64
+ /**
65
+ * Get all registered routes for the {{PAGE_SLUG}}-wp-admin page.
66
+ *
67
+ * @return array Array of route objects.
68
+ */
69
+ function {{PREFIX}}_get_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_routes() {
70
+ global ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_routes;
71
+ return ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_routes ?? array();
78
72
  }
79
73
 
80
- if ( ! function_exists( '{{PREFIX}}_get_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_menu_items' ) ) {
81
- /**
82
- * Get all registered menu items for the {{PAGE_SLUG}}-wp-admin page.
83
- *
84
- * @return array Array of menu item objects.
85
- */
86
- function {{PREFIX}}_get_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_menu_items() {
87
- global ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_menu_items;
88
- return ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_menu_items ?? array();
89
- }
74
+ /**
75
+ * Get all registered menu items for the {{PAGE_SLUG}}-wp-admin page.
76
+ *
77
+ * @return array Array of menu item objects.
78
+ */
79
+ function {{PREFIX}}_get_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_menu_items() {
80
+ global ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_menu_items;
81
+ return ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_menu_items ?? array();
90
82
  }
91
83
 
92
- if ( ! function_exists( '{{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_preload_data' ) ) {
93
- /**
94
- * Preload REST API data for the {{PAGE_SLUG}}-wp-admin page.
95
- * Automatically called during page rendering.
96
- */
97
- function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_preload_data() {
98
- // Define paths to preload - same for all pages
99
- // Please also change packages/core-data/src/entities.js when changing this.
100
- $preload_paths = array(
101
- '/?_fields=description,gmt_offset,home,image_sizes,image_size_threshold,image_output_formats,jpeg_interlaced,png_interlaced,gif_interlaced,name,site_icon,site_icon_url,site_logo,timezone_string,url,page_for_posts,page_on_front,show_on_front',
102
- array( '/wp/v2/settings', 'OPTIONS' ),
103
- );
84
+ /**
85
+ * Preload REST API data for the {{PAGE_SLUG}}-wp-admin page.
86
+ * Automatically called during page rendering.
87
+ */
88
+ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_preload_data() {
89
+ // Define paths to preload - same for all pages
90
+ // Please also change packages/core-data/src/entities.js when changing this.
91
+ $preload_paths = array(
92
+ '/?_fields=description,gmt_offset,home,image_sizes,image_size_threshold,image_output_formats,jpeg_interlaced,png_interlaced,gif_interlaced,name,site_icon,site_icon_url,site_logo,timezone_string,url,page_for_posts,page_on_front,show_on_front',
93
+ array( '/wp/v2/settings', 'OPTIONS' ),
94
+ );
95
+
96
+ // Use rest_preload_api_request to gather the preloaded data
97
+ $preload_data = array_reduce(
98
+ $preload_paths,
99
+ 'rest_preload_api_request',
100
+ array()
101
+ );
102
+
103
+ // Register the preloading middleware with wp-api-fetch
104
+ wp_add_inline_script(
105
+ 'wp-api-fetch',
106
+ sprintf(
107
+ 'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );',
108
+ wp_json_encode( $preload_data )
109
+ ),
110
+ 'after'
111
+ );
112
+ }
104
113
 
105
- // Use rest_preload_api_request to gather the preloaded data
106
- $preload_data = array_reduce(
107
- $preload_paths,
108
- 'rest_preload_api_request',
109
- array()
110
- );
114
+ /**
115
+ * Enqueue scripts and styles for the {{PAGE_SLUG}}-wp-admin page.
116
+ * Hooked to admin_enqueue_scripts.
117
+ *
118
+ * @param string $hook_suffix The current admin page.
119
+ */
120
+ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_enqueue_scripts( $hook_suffix ) {
121
+ // Check all possible ways this page can be accessed:
122
+ // 1. Menu page via admin.php?page={{PAGE_SLUG}}-wp-admin (plugin)
123
+ // 2. Direct file via {{PAGE_SLUG}}.php (Core) - screen ID will be '{{PAGE_SLUG}}'
124
+ $current_screen = get_current_screen();
125
+ $is_our_page = (
126
+ ( isset( $_GET['page'] ) && '{{PAGE_SLUG}}-wp-admin' === $_GET['page'] ) || // phpcs:ignore WordPress.Security.NonceVerification.Recommended
127
+ ( $current_screen && '{{PAGE_SLUG}}' === $current_screen->id )
128
+ );
129
+
130
+ if ( ! $is_our_page ) {
131
+ return;
132
+ }
133
+
134
+ // Load build constants
135
+ $build_constants = require __DIR__ . '/../../constants.php';
136
+
137
+ // Fire init action for extensions to register routes and menu items
138
+ do_action( '{{PAGE_SLUG}}-wp-admin_init' );
139
+
140
+ // Preload REST API data
141
+ {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_preload_data();
142
+
143
+ // Get all registered routes
144
+ $routes = {{PREFIX}}_get_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_routes();
145
+
146
+ // Get boot module asset file for dependencies
147
+ $asset_file = __DIR__ . '/../../modules/boot/index.min.asset.php';
148
+ if ( file_exists( $asset_file ) ) {
149
+ $asset = require $asset_file;
150
+
151
+ // This script serves two purposes:
152
+ // 1. It ensures all the globals that are made available to the modules are loaded.
153
+ // 2. It initializes the boot module as an inline script.
154
+ wp_register_script( '{{PAGE_SLUG}}-wp-admin-prerequisites', '', $asset['dependencies'], $asset['version'], true );
111
155
 
112
- // Register the preloading middleware with wp-api-fetch
156
+ // Add inline script to initialize the app using initSinglePage (no menuItems)
113
157
  wp_add_inline_script(
114
- 'wp-api-fetch',
158
+ '{{PAGE_SLUG}}-wp-admin-prerequisites',
115
159
  sprintf(
116
- 'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );',
117
- wp_json_encode( $preload_data )
118
- ),
119
- 'after'
160
+ 'import("@wordpress/boot").then(mod => mod.initSinglePage({mountId: "%s", routes: %s}));',
161
+ '{{PAGE_SLUG}}-wp-admin-app',
162
+ wp_json_encode( $routes, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
163
+ )
120
164
  );
121
- }
122
- }
123
165
 
124
- if ( ! function_exists( '{{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_enqueue_scripts' ) ) {
125
- /**
126
- * Enqueue scripts and styles for the {{PAGE_SLUG}}-wp-admin page.
127
- * Hooked to admin_enqueue_scripts.
128
- *
129
- * @param string $hook_suffix The current admin page.
130
- */
131
- function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_enqueue_scripts( $hook_suffix ) {
132
- // Check all possible ways this page can be accessed:
133
- // 1. Menu page via admin.php?page={{PAGE_SLUG}}-wp-admin (plugin)
134
- // 2. Direct file via {{PAGE_SLUG}}.php (Core) - screen ID will be '{{PAGE_SLUG}}'
135
- $current_screen = get_current_screen();
136
- $is_our_page = (
137
- ( isset( $_GET['page'] ) && '{{PAGE_SLUG}}-wp-admin' === $_GET['page'] ) || // phpcs:ignore WordPress.Security.NonceVerification.Recommended
138
- ( $current_screen && '{{PAGE_SLUG}}' === $current_screen->id )
166
+ // Register prerequisites style by filtering script dependencies to find registered styles
167
+ $style_dependencies = array_filter(
168
+ $asset['dependencies'],
169
+ function ( $handle ) {
170
+ return wp_style_is( $handle, 'registered' );
171
+ }
139
172
  );
173
+ wp_register_style( '{{PAGE_SLUG}}-wp-admin-prerequisites', false, $style_dependencies, $asset['version'] );
140
174
 
141
- if ( ! $is_our_page ) {
142
- return;
143
- }
175
+ // Build dependencies for {{PAGE_SLUG}}-wp-admin module
176
+ $boot_dependencies = array(
177
+ array(
178
+ 'import' => 'static',
179
+ 'id' => '@wordpress/boot',
180
+ ),
181
+ );
144
182
 
145
- // Load build constants
146
- $build_constants = require __DIR__ . '/../../constants.php';
147
-
148
- // Fire init action for extensions to register routes and menu items
149
- do_action( '{{PAGE_SLUG}}-wp-admin_init' );
150
-
151
- // Preload REST API data
152
- {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_preload_data();
153
-
154
- // Get all registered routes
155
- $routes = {{PREFIX}}_get_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_routes();
156
-
157
- // Get boot module asset file for dependencies
158
- $asset_file = __DIR__ . '/../../modules/boot/index.min.asset.php';
159
- if ( file_exists( $asset_file ) ) {
160
- $asset = require $asset_file;
161
-
162
- // This script serves two purposes:
163
- // 1. It ensures all the globals that are made available to the modules are loaded.
164
- // 2. It initializes the boot module as an inline script.
165
- wp_register_script( '{{PAGE_SLUG}}-wp-admin-prerequisites', '', $asset['dependencies'], $asset['version'], true );
166
-
167
- // Add inline script to initialize the app using initSinglePage (no menuItems)
168
- wp_add_inline_script(
169
- '{{PAGE_SLUG}}-wp-admin-prerequisites',
170
- sprintf(
171
- 'import("@wordpress/boot").then(mod => mod.initSinglePage({mountId: "%s", routes: %s}));',
172
- '{{PAGE_SLUG}}-wp-admin-app',
173
- wp_json_encode( $routes, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
174
- )
175
- );
176
-
177
- // Register prerequisites style by filtering script dependencies to find registered styles
178
- $style_dependencies = array_filter(
179
- $asset['dependencies'],
180
- function ( $handle ) {
181
- return wp_style_is( $handle, 'registered' );
182
- }
183
- );
184
- wp_register_style( '{{PAGE_SLUG}}-wp-admin-prerequisites', false, $style_dependencies, $asset['version'] );
185
-
186
- // Build dependencies for {{PAGE_SLUG}}-wp-admin module
187
- $boot_dependencies = array(
188
- array(
183
+ // Add all registered routes as dependencies
184
+ foreach ( $routes as $route ) {
185
+ if ( isset( $route['route_module'] ) ) {
186
+ $boot_dependencies[] = array(
189
187
  'import' => 'static',
190
- 'id' => '@wordpress/boot',
191
- ),
192
- );
193
-
194
- // Add all registered routes as dependencies
195
- foreach ( $routes as $route ) {
196
- if ( isset( $route['route_module'] ) ) {
197
- $boot_dependencies[] = array(
198
- 'import' => 'static',
199
- 'id' => $route['route_module'],
200
- );
201
- }
202
- if ( isset( $route['content_module'] ) ) {
203
- $boot_dependencies[] = array(
204
- 'import' => 'dynamic',
205
- 'id' => $route['content_module'],
206
- );
207
- }
188
+ 'id' => $route['route_module'],
189
+ );
190
+ }
191
+ if ( isset( $route['content_module'] ) ) {
192
+ $boot_dependencies[] = array(
193
+ 'import' => 'dynamic',
194
+ 'id' => $route['content_module'],
195
+ );
208
196
  }
209
-
210
- // Dummy script module to ensure dependencies are loaded
211
- wp_register_script_module(
212
- '{{PAGE_SLUG}}-wp-admin',
213
- $build_constants['build_url'] . 'pages/{{PAGE_SLUG}}/loader.js',
214
- $boot_dependencies
215
- );
216
-
217
- // Enqueue the boot scripts and styles
218
- wp_enqueue_script( '{{PAGE_SLUG}}-wp-admin-prerequisites' );
219
- wp_enqueue_script_module( '{{PAGE_SLUG}}-wp-admin' );
220
- wp_enqueue_style( '{{PAGE_SLUG}}-wp-admin-prerequisites' );
221
197
  }
198
+
199
+ // Dummy script module to ensure dependencies are loaded
200
+ wp_register_script_module(
201
+ '{{PAGE_SLUG}}-wp-admin',
202
+ $build_constants['build_url'] . 'pages/{{PAGE_SLUG}}/loader.js',
203
+ $boot_dependencies
204
+ );
205
+
206
+ // Enqueue the boot scripts and styles
207
+ wp_enqueue_script( '{{PAGE_SLUG}}-wp-admin-prerequisites' );
208
+ wp_enqueue_script_module( '{{PAGE_SLUG}}-wp-admin' );
209
+ wp_enqueue_style( '{{PAGE_SLUG}}-wp-admin-prerequisites' );
222
210
  }
223
211
  }
224
212
 
225
- if ( ! function_exists( '{{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_render_page' ) ) {
226
- /**
227
- * Render the {{PAGE_SLUG}}-wp-admin page.
228
- * Call this function from add_menu_page or add_submenu_page.
229
- * This renders within the normal WordPress admin interface.
230
- */
231
- function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_render_page() {
232
- ?>
233
- <style>
234
- /* Critical styles to prevent layout shifts - inlined for immediate application */
235
-
236
- /* Background colors */
237
- #wpwrap {
238
- background: var(--wpds-color-fg-content-neutral, #1e1e1e);
239
- overflow-y: auto;
240
- }
241
- body {
242
- background: #fff;
243
- }
213
+ /**
214
+ * Render the {{PAGE_SLUG}}-wp-admin page.
215
+ * Call this function from add_menu_page or add_submenu_page.
216
+ * This renders within the normal WordPress admin interface.
217
+ */
218
+ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_render_page() {
219
+ ?>
220
+ <style>
221
+ /* Critical styles to prevent layout shifts - inlined for immediate application */
222
+
223
+ /* Background colors */
224
+ #wpwrap {
225
+ background: var(--wpds-color-fg-content-neutral, #1e1e1e);
226
+ overflow-y: auto;
227
+ }
228
+ body {
229
+ background: #fff;
230
+ }
244
231
 
245
- /* Reset wp-admin padding */
246
- #wpcontent {
247
- padding-left: 0;
248
- }
249
- #wpbody-content {
250
- padding-bottom: 0;
251
- }
232
+ /* Reset wp-admin padding */
233
+ #wpcontent {
234
+ padding-left: 0;
235
+ }
236
+ #wpbody-content {
237
+ padding-bottom: 0;
238
+ }
252
239
 
253
- /* Hide legacy admin elements */
254
- #wpbody-content > div:not(.boot-layout-container):not(#screen-meta) {
255
- display: none;
256
- }
257
- #wpfooter {
258
- display: none;
259
- }
240
+ /* Hide legacy admin elements */
241
+ #wpbody-content > div:not(.boot-layout-container):not(#screen-meta) {
242
+ display: none;
243
+ }
244
+ #wpfooter {
245
+ display: none;
246
+ }
260
247
 
261
- /* Accessibility regions */
262
- .a11y-speak-region {
263
- left: -1px;
264
- top: -1px;
265
- }
248
+ /* Accessibility regions */
249
+ .a11y-speak-region {
250
+ left: -1px;
251
+ top: -1px;
252
+ }
266
253
 
267
- /* Admin menu indicators */
268
- ul#adminmenu a.wp-has-current-submenu::after,
269
- ul#adminmenu > li.current > a.current::after {
270
- border-right-color: #fff;
271
- }
254
+ /* Admin menu indicators */
255
+ ul#adminmenu a.wp-has-current-submenu::after,
256
+ ul#adminmenu > li.current > a.current::after {
257
+ border-right-color: #fff;
258
+ }
272
259
 
273
- /* Media frame fix */
274
- .media-frame select.attachment-filters:last-of-type {
275
- width: auto;
276
- max-width: 100%;
277
- }
260
+ /* Media frame fix */
261
+ .media-frame select.attachment-filters:last-of-type {
262
+ width: auto;
263
+ max-width: 100%;
264
+ }
278
265
 
279
- /* Responsive overflow fix for #wpwrap */
280
- @media (min-width: 782px) {
281
- #wpwrap {
282
- overflow-y: initial;
283
- }
266
+ /* Responsive overflow fix for #wpwrap */
267
+ @media (min-width: 782px) {
268
+ #wpwrap {
269
+ overflow-y: initial;
284
270
  }
285
- </style>
286
- <div id="{{PAGE_SLUG}}-wp-admin-app" class="boot-layout-container"></div>
287
- <?php
288
- }
271
+ }
272
+ </style>
273
+ <div id="{{PAGE_SLUG}}-wp-admin-app" class="boot-layout-container"></div>
274
+ <?php
289
275
  }
290
276
 
291
277
  // Hook the enqueue function to admin_enqueue_scripts