@wordpress/build 0.26.0 → 0.28.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.
- package/CHANGELOG.md +40 -0
- package/README.md +58 -31
- package/eslint-overrides.cjs +1 -1
- package/lib/build-concurrency.mjs +87 -0
- package/lib/build.mjs +686 -555
- package/lib/compile-inline-style.mjs +48 -12
- package/lib/copy-files.mjs +165 -0
- package/lib/package-utils.mjs +16 -2
- package/lib/php-generator.mjs +5 -0
- package/lib/route-utils.mjs +1 -1
- package/lib/sass-compiler.mjs +41 -0
- package/lib/widget-utils.mjs +7 -1
- package/lib/wordpress-externals-plugin.mjs +332 -313
- package/lib/worker-build.mjs +85 -75
- package/package.json +11 -11
- package/templates/build.php.template +4 -0
- package/templates/constants.php.template +4 -0
- package/templates/module-registration.php.template +4 -0
- package/templates/module-registry.php.template +4 -0
- package/templates/page-wp-admin.php.template +67 -54
- package/templates/page.php.template +27 -21
- package/templates/pages.php.template +4 -0
- package/templates/route-registry.php.template +4 -0
- package/templates/routes-registration.php.template +4 -0
- package/templates/script-registration.php.template +4 -0
- package/templates/script-registry.php.template +4 -0
- package/templates/style-registration.php.template +4 -0
- package/templates/style-registry.php.template +4 -0
- package/templates/widget-registration.php.template +4 -0
- package/templates/widget-registry.php.template +4 -0
package/lib/worker-build.mjs
CHANGED
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { readFile, writeFile, access } from 'fs/promises';
|
|
10
10
|
import path from 'path';
|
|
11
|
-
import
|
|
11
|
+
import { buildWithConcurrency } from './build-concurrency.mjs';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* Creates
|
|
14
|
+
* Creates a Rolldown plugin that redirects module loads based on filename patterns.
|
|
15
15
|
*
|
|
16
16
|
* This is useful when bundling workers for Blob URL contexts where certain
|
|
17
17
|
* ES module entry points use `import.meta.url` (which resolves to an invalid
|
|
@@ -30,11 +30,11 @@ import esbuild from 'esbuild';
|
|
|
30
30
|
* }
|
|
31
31
|
*
|
|
32
32
|
* @param {Object} resolveMap An object mapping source filenames to target
|
|
33
|
-
* filenames. When
|
|
33
|
+
* filenames. When Rolldown loads a file whose path
|
|
34
34
|
* ends with a source key, the plugin rewrites it
|
|
35
35
|
* to re-export from the corresponding target file
|
|
36
36
|
* in the same directory.
|
|
37
|
-
* @return {
|
|
37
|
+
* @return {import('rolldown').Plugin} A Rolldown plugin.
|
|
38
38
|
*/
|
|
39
39
|
function createModuleRedirectPlugin( resolveMap ) {
|
|
40
40
|
// Build a single regex that matches any of the source filenames.
|
|
@@ -45,32 +45,31 @@ function createModuleRedirectPlugin( resolveMap ) {
|
|
|
45
45
|
|
|
46
46
|
return {
|
|
47
47
|
name: 'module-redirect',
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
load: {
|
|
49
|
+
filter: { id: pattern },
|
|
50
|
+
handler( id ) {
|
|
50
51
|
// Find which key matched.
|
|
51
52
|
const matchedKey = Object.keys( resolveMap ).find( ( key ) =>
|
|
52
|
-
|
|
53
|
+
id.endsWith( key )
|
|
53
54
|
);
|
|
54
|
-
const targetPath =
|
|
55
|
+
const targetPath = id.replace(
|
|
55
56
|
matchedKey,
|
|
56
57
|
resolveMap[ matchedKey ]
|
|
57
58
|
);
|
|
58
|
-
const resolveDir = path.dirname( args.path );
|
|
59
59
|
// A relative specifier keeps the checkout path out of the source map.
|
|
60
60
|
const specifier =
|
|
61
61
|
'./' +
|
|
62
62
|
path
|
|
63
|
-
.relative(
|
|
63
|
+
.relative( path.dirname( id ), targetPath )
|
|
64
64
|
.split( path.sep )
|
|
65
65
|
.join( '/' );
|
|
66
66
|
return {
|
|
67
|
-
|
|
67
|
+
code: `export { default } from ${ JSON.stringify(
|
|
68
68
|
specifier
|
|
69
69
|
) };`,
|
|
70
|
-
|
|
71
|
-
resolveDir,
|
|
70
|
+
moduleType: 'js',
|
|
72
71
|
};
|
|
73
|
-
}
|
|
72
|
+
},
|
|
74
73
|
},
|
|
75
74
|
};
|
|
76
75
|
}
|
|
@@ -151,7 +150,7 @@ export const workerCode = '/* Placeholder - run npm run build to generate actual
|
|
|
151
150
|
* @param {string} options.buildDir Path to the CJS build directory.
|
|
152
151
|
* @param {string} options.buildModuleDir Path to the ESM build-module directory.
|
|
153
152
|
* @param {string[]} options.target esbuild target configuration.
|
|
154
|
-
* @param {Object} options.wasmInlinePlugin The WASM inline plugin for
|
|
153
|
+
* @param {Object} options.wasmInlinePlugin The WASM inline plugin for Rolldown.
|
|
155
154
|
*/
|
|
156
155
|
export async function buildWorkers(
|
|
157
156
|
packageDir,
|
|
@@ -178,32 +177,39 @@ export async function buildWorkers(
|
|
|
178
177
|
// Build ESM worker for build-module (primary for browser use).
|
|
179
178
|
if ( packageJson.module ) {
|
|
180
179
|
workerBuilds.push(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
`${ workerOutputName }.mjs`
|
|
186
|
-
),
|
|
187
|
-
bundle: true,
|
|
188
|
-
// Emit UTF-8 so binary-encoded inlined WASM stays compact
|
|
189
|
-
// (ASCII output would escape high bytes as \uXXXX).
|
|
190
|
-
charset: 'utf8',
|
|
191
|
-
format: 'esm',
|
|
180
|
+
buildWithConcurrency( {
|
|
181
|
+
input: workerEntryPoint,
|
|
182
|
+
// wasm-vips uses eval, don't warn about it
|
|
183
|
+
checks: { eval: false },
|
|
192
184
|
platform: 'browser',
|
|
193
|
-
|
|
194
|
-
|
|
185
|
+
// Rolldown's default conditions lack esbuild's module condition.
|
|
186
|
+
resolve: {
|
|
187
|
+
conditionNames: [ 'module', 'browser', 'default' ],
|
|
188
|
+
},
|
|
195
189
|
// Bundle everything - workers need to be self-contained.
|
|
196
|
-
external: [],
|
|
197
190
|
plugins: [
|
|
198
191
|
wasmInlinePlugin,
|
|
199
192
|
...( resolveMap
|
|
200
193
|
? [ createModuleRedirectPlugin( resolveMap ) ]
|
|
201
194
|
: [] ),
|
|
202
195
|
],
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
196
|
+
transform: {
|
|
197
|
+
target,
|
|
198
|
+
define: {
|
|
199
|
+
'process.env.NODE_ENV': JSON.stringify(
|
|
200
|
+
process.env.NODE_ENV || 'production'
|
|
201
|
+
),
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
output: {
|
|
205
|
+
file: path.join(
|
|
206
|
+
buildModuleDir,
|
|
207
|
+
`${ workerOutputName }.mjs`
|
|
206
208
|
),
|
|
209
|
+
format: 'esm',
|
|
210
|
+
minify: false,
|
|
211
|
+
sourcemap: true,
|
|
212
|
+
codeSplitting: false,
|
|
207
213
|
},
|
|
208
214
|
} )
|
|
209
215
|
);
|
|
@@ -220,23 +226,32 @@ export async function buildWorkers(
|
|
|
220
226
|
// unused or misleading CJS artifacts.
|
|
221
227
|
if ( packageJson.main ) {
|
|
222
228
|
workerBuilds.push(
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
// Emit UTF-8 so binary-encoded inlined WASM stays compact
|
|
228
|
-
// (ASCII output would escape high bytes as \uXXXX).
|
|
229
|
-
charset: 'utf8',
|
|
230
|
-
format: 'cjs',
|
|
229
|
+
buildWithConcurrency( {
|
|
230
|
+
input: workerEntryPoint,
|
|
231
|
+
// wasm-vips uses eval, don't warn about it
|
|
232
|
+
checks: { eval: false },
|
|
231
233
|
platform: 'node',
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
234
|
+
resolve: {
|
|
235
|
+
conditionNames: [ 'module', 'node', 'default' ],
|
|
236
|
+
},
|
|
235
237
|
plugins: [ wasmInlinePlugin ],
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
238
|
+
transform: {
|
|
239
|
+
target,
|
|
240
|
+
define: {
|
|
241
|
+
'process.env.NODE_ENV': JSON.stringify(
|
|
242
|
+
process.env.NODE_ENV || 'production'
|
|
243
|
+
),
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
output: {
|
|
247
|
+
file: path.join(
|
|
248
|
+
buildDir,
|
|
249
|
+
`${ workerOutputName }.cjs`
|
|
239
250
|
),
|
|
251
|
+
format: 'cjs',
|
|
252
|
+
minify: false,
|
|
253
|
+
sourcemap: true,
|
|
254
|
+
codeSplitting: false,
|
|
240
255
|
},
|
|
241
256
|
} )
|
|
242
257
|
);
|
|
@@ -260,7 +275,7 @@ export async function buildWorkers(
|
|
|
260
275
|
* @param {string} options.buildDir Path to the CJS build directory.
|
|
261
276
|
* @param {string} options.buildModuleDir Path to the ESM build-module directory.
|
|
262
277
|
* @param {string[]} options.target esbuild target configuration.
|
|
263
|
-
* @param {Array} options.plugins
|
|
278
|
+
* @param {Array} options.plugins Rolldown plugins for transpilation.
|
|
264
279
|
*/
|
|
265
280
|
export async function generateWorkerCode(
|
|
266
281
|
packageDir,
|
|
@@ -323,48 +338,43 @@ export const workerCode = ${ JSON.stringify( workerContent ) };
|
|
|
323
338
|
// build-module/worker-code.mjs (and build/worker-code.cjs if applicable)
|
|
324
339
|
// reflect the actual worker code in a single build run.
|
|
325
340
|
const workerCodeSrcFile = path.join( packageDir, 'src', 'worker-code.ts' );
|
|
341
|
+
// Name the entry after its path in `src`, so the output mirrors it.
|
|
342
|
+
const workerCodeEntryName = path
|
|
343
|
+
.relative( srcDir, workerCodeSrcFile )
|
|
344
|
+
.replace( /\.ts$/, '' );
|
|
326
345
|
const retranspileBuilds = [];
|
|
327
346
|
|
|
328
347
|
if ( packageJson.module ) {
|
|
329
348
|
retranspileBuilds.push(
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
outdir: buildModuleDir,
|
|
333
|
-
outbase: srcDir,
|
|
334
|
-
outExtension: { '.js': '.mjs' },
|
|
335
|
-
bundle: true,
|
|
336
|
-
// Emit UTF-8 so binary-encoded inlined WASM stays compact
|
|
337
|
-
// (ASCII output would escape high bytes as \uXXXX).
|
|
338
|
-
charset: 'utf8',
|
|
349
|
+
buildWithConcurrency( {
|
|
350
|
+
input: { [ workerCodeEntryName ]: workerCodeSrcFile },
|
|
339
351
|
platform: 'neutral',
|
|
340
|
-
|
|
341
|
-
sourcemap: true,
|
|
342
|
-
target,
|
|
343
|
-
jsx: 'automatic',
|
|
344
|
-
jsxImportSource: 'react',
|
|
352
|
+
transform: { target },
|
|
345
353
|
plugins,
|
|
354
|
+
output: {
|
|
355
|
+
dir: buildModuleDir,
|
|
356
|
+
entryFileNames: '[name].mjs',
|
|
357
|
+
format: 'esm',
|
|
358
|
+
sourcemap: true,
|
|
359
|
+
},
|
|
346
360
|
} )
|
|
347
361
|
);
|
|
348
362
|
}
|
|
349
363
|
|
|
350
364
|
if ( packageJson.main ) {
|
|
351
365
|
retranspileBuilds.push(
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
outdir: buildDir,
|
|
355
|
-
outbase: srcDir,
|
|
356
|
-
outExtension: { '.js': '.cjs' },
|
|
357
|
-
bundle: true,
|
|
358
|
-
// Emit UTF-8 so binary-encoded inlined WASM stays compact
|
|
359
|
-
// (ASCII output would escape high bytes as \uXXXX).
|
|
360
|
-
charset: 'utf8',
|
|
366
|
+
buildWithConcurrency( {
|
|
367
|
+
input: { [ workerCodeEntryName ]: workerCodeSrcFile },
|
|
361
368
|
platform: 'node',
|
|
362
|
-
|
|
363
|
-
sourcemap: true,
|
|
364
|
-
target,
|
|
365
|
-
jsx: 'automatic',
|
|
366
|
-
jsxImportSource: 'react',
|
|
369
|
+
transform: { target },
|
|
367
370
|
plugins,
|
|
371
|
+
output: {
|
|
372
|
+
dir: buildDir,
|
|
373
|
+
entryFileNames: '[name].cjs',
|
|
374
|
+
format: 'cjs',
|
|
375
|
+
exports: 'named',
|
|
376
|
+
sourcemap: true,
|
|
377
|
+
},
|
|
368
378
|
} )
|
|
369
379
|
);
|
|
370
380
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/build",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"description": "Build tool for WordPress plugins.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"wordpress",
|
|
9
9
|
"build",
|
|
10
|
-
"
|
|
10
|
+
"rolldown",
|
|
11
11
|
"bundler"
|
|
12
12
|
],
|
|
13
13
|
"homepage": "https://github.com/WordPress/gutenberg/tree/HEAD/packages/wp-build/README.md",
|
|
@@ -41,30 +41,30 @@
|
|
|
41
41
|
"wp-build": "./lib/build.mjs"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@wordpress/browserslist-config": "^7.
|
|
45
|
-
"@wordpress/style-runtime": "^0.
|
|
44
|
+
"@wordpress/browserslist-config": "^7.2.0",
|
|
45
|
+
"@wordpress/style-runtime": "^0.16.0",
|
|
46
|
+
"@wordpress/theme-build-tools": "^1.1.0",
|
|
46
47
|
"autoprefixer": "^10.4.21",
|
|
47
48
|
"browserslist": "^4.28.7",
|
|
48
49
|
"browserslist-to-esbuild": "^2.1.1",
|
|
49
50
|
"change-case": "^4.1.2",
|
|
50
51
|
"chokidar": "^4.0.0",
|
|
51
52
|
"cssnano": "^6.0.1",
|
|
52
|
-
"esbuild": "^0.27.2",
|
|
53
|
-
"esbuild-sass-plugin": "^3.3.1",
|
|
54
53
|
"fast-glob": "^3.2.7",
|
|
55
54
|
"moment-timezone": "^0.5.40",
|
|
56
|
-
"postcss": "^8.
|
|
55
|
+
"postcss": "^8.5.33",
|
|
57
56
|
"postcss-modules": "^6.0.1",
|
|
57
|
+
"rolldown": "^1.2.15",
|
|
58
58
|
"rtlcss": "^4.3.0",
|
|
59
59
|
"sass-embedded": "^1.97.2"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@types/node": "^24.13.3",
|
|
63
|
-
"@wordpress/theme": "^
|
|
64
|
-
"vitest": "^5.0
|
|
63
|
+
"@wordpress/theme": "^5.0.0",
|
|
64
|
+
"vitest": "^5.1.0"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"@wordpress/theme": "
|
|
67
|
+
"@wordpress/theme": "^3.0.0 || ^4.0.0 || ^5.0.0"
|
|
68
68
|
},
|
|
69
69
|
"peerDependenciesMeta": {
|
|
70
70
|
"@wordpress/theme": {
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"publishConfig": {
|
|
75
75
|
"access": "public"
|
|
76
76
|
},
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "1000cdf1dffd5b5e69f75cc4360aa76db8252264"
|
|
78
78
|
}
|
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
* @package {{PREFIX}}
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
if ( ! defined( 'ABSPATH' ) ) {
|
|
14
|
+
exit;
|
|
15
|
+
}
|
|
16
|
+
|
|
13
17
|
// Global storage for {{PAGE_SLUG}} routes and menu items
|
|
14
18
|
global ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_routes, ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_menu_items;
|
|
15
19
|
${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_routes = array();
|
|
@@ -87,7 +91,7 @@ function {{PREFIX}}_get_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_menu_items() {
|
|
|
87
91
|
*/
|
|
88
92
|
function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_preload_data() {
|
|
89
93
|
// Define paths to preload - same for all pages
|
|
90
|
-
// This must exactly match the _fields list in packages/core-data/src/entities.
|
|
94
|
+
// This must exactly match the _fields list in packages/core-data/src/entities.ts,
|
|
91
95
|
// same fields in the same order, or the preload is never consumed.
|
|
92
96
|
$preload_paths = array(
|
|
93
97
|
'/?_fields=description,generate_animated_image_subsizes,gmt_offset,home,image_max_bit_depth,image_sizes,image_size_threshold,image_strip_meta,name,site_icon,site_icon_url,site_logo,timezone_string,url,page_for_posts,page_on_front,show_on_front',
|
|
@@ -134,10 +138,17 @@ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_enqueue_scripts( $hook_suf
|
|
|
134
138
|
// Check all possible ways this page can be accessed:
|
|
135
139
|
// 1. Menu page via admin.php?page={{PAGE_SLUG}}-wp-admin (plugin)
|
|
136
140
|
// 2. Direct file via {{PAGE_SLUG}}.php (Core) - screen ID will be '{{PAGE_SLUG}}'
|
|
141
|
+
// The screen ID alone is not enough: a Core screen can share it with the page
|
|
142
|
+
// slug (for example, index.php has the screen ID 'dashboard').
|
|
137
143
|
$current_screen = get_current_screen();
|
|
138
144
|
$is_our_page = (
|
|
139
145
|
( isset( $_GET['page'] ) && '{{PAGE_SLUG}}-wp-admin' === $_GET['page'] ) || // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
|
140
|
-
(
|
|
146
|
+
(
|
|
147
|
+
$current_screen &&
|
|
148
|
+
'{{PAGE_SLUG}}' === $current_screen->id &&
|
|
149
|
+
isset( $GLOBALS['pagenow'] ) &&
|
|
150
|
+
'{{PAGE_SLUG}}.php' === $GLOBALS['pagenow']
|
|
151
|
+
)
|
|
141
152
|
);
|
|
142
153
|
|
|
143
154
|
if ( ! $is_our_page ) {
|
|
@@ -170,7 +181,7 @@ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_enqueue_scripts( $hook_suf
|
|
|
170
181
|
// This script serves two purposes:
|
|
171
182
|
// 1. It ensures all the globals that are made available to the modules are loaded.
|
|
172
183
|
// 2. It initializes the boot module as an inline script.
|
|
173
|
-
wp_register_script( '{{PAGE_SLUG}}-wp-admin-prerequisites',
|
|
184
|
+
wp_register_script( '{{PAGE_SLUG}}-wp-admin-prerequisites', false, $asset['dependencies'], $asset['version'], true );
|
|
174
185
|
|
|
175
186
|
$init_modules = {{INIT_MODULES_JSON}};
|
|
176
187
|
|
|
@@ -217,6 +228,58 @@ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_enqueue_scripts( $hook_suf
|
|
|
217
228
|
);
|
|
218
229
|
wp_register_style( '{{PAGE_SLUG}}-wp-admin-prerequisites', false, $style_dependencies, $asset['version'] );
|
|
219
230
|
|
|
231
|
+
// Critical styles to prevent layout shifts.
|
|
232
|
+
$page_styles = <<<'CSS'
|
|
233
|
+
#wpwrap {
|
|
234
|
+
overflow-y: auto;
|
|
235
|
+
}
|
|
236
|
+
body.js {
|
|
237
|
+
background: #fff;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/* Reset wp-admin padding */
|
|
241
|
+
body.js #wpcontent {
|
|
242
|
+
padding-inline-start: 0;
|
|
243
|
+
}
|
|
244
|
+
body.js #wpbody-content {
|
|
245
|
+
padding-bottom: 0;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/* Hide legacy admin elements */
|
|
249
|
+
body.js #wpbody-content > div:not(#{{PAGE_SLUG}}-wp-admin-app):not(#screen-meta) {
|
|
250
|
+
display: none;
|
|
251
|
+
}
|
|
252
|
+
body.js #wpfooter {
|
|
253
|
+
display: none;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/* Accessibility regions */
|
|
257
|
+
.a11y-speak-region {
|
|
258
|
+
inset-inline-start: -1px;
|
|
259
|
+
top: -1px;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/* Admin menu indicators */
|
|
263
|
+
ul#adminmenu a.wp-has-current-submenu::after,
|
|
264
|
+
ul#adminmenu > li.current > a.current::after {
|
|
265
|
+
border-inline-end-color: #fff;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/* Media frame fix */
|
|
269
|
+
.media-frame select.attachment-filters:last-of-type {
|
|
270
|
+
width: auto;
|
|
271
|
+
max-width: 100%;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/* Responsive overflow fix for #wpwrap */
|
|
275
|
+
@media (min-width: 782px) {
|
|
276
|
+
#wpwrap {
|
|
277
|
+
overflow-y: initial;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
CSS;
|
|
281
|
+
wp_add_inline_style( '{{PAGE_SLUG}}-wp-admin-prerequisites', $page_styles );
|
|
282
|
+
|
|
220
283
|
// Build dependencies for {{PAGE_SLUG}}-wp-admin module
|
|
221
284
|
$boot_dependencies = array(
|
|
222
285
|
array(
|
|
@@ -280,61 +343,11 @@ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_enqueue_scripts( $hook_suf
|
|
|
280
343
|
*/
|
|
281
344
|
function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_render_page() {
|
|
282
345
|
?>
|
|
283
|
-
<style>
|
|
284
|
-
/* Critical styles to prevent layout shifts - inlined for immediate application */
|
|
285
|
-
|
|
286
|
-
#wpwrap {
|
|
287
|
-
overflow-y: auto;
|
|
288
|
-
}
|
|
289
|
-
body.js {
|
|
290
|
-
background: #fff;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/* Reset wp-admin padding */
|
|
294
|
-
body.js #wpcontent {
|
|
295
|
-
padding-inline-start: 0;
|
|
296
|
-
}
|
|
297
|
-
body.js #wpbody-content {
|
|
298
|
-
padding-bottom: 0;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
/* Hide legacy admin elements */
|
|
302
|
-
body.js #wpbody-content > div:not(#{{PAGE_SLUG}}-wp-admin-app):not(#screen-meta) {
|
|
303
|
-
display: none;
|
|
304
|
-
}
|
|
305
|
-
body.js #wpfooter {
|
|
306
|
-
display: none;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/* Accessibility regions */
|
|
310
|
-
.a11y-speak-region {
|
|
311
|
-
inset-inline-start: -1px;
|
|
312
|
-
top: -1px;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/* Admin menu indicators */
|
|
316
|
-
ul#adminmenu a.wp-has-current-submenu::after,
|
|
317
|
-
ul#adminmenu > li.current > a.current::after {
|
|
318
|
-
border-inline-end-color: #fff;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/* Media frame fix */
|
|
322
|
-
.media-frame select.attachment-filters:last-of-type {
|
|
323
|
-
width: auto;
|
|
324
|
-
max-width: 100%;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/* Responsive overflow fix for #wpwrap */
|
|
328
|
-
@media (min-width: 782px) {
|
|
329
|
-
#wpwrap {
|
|
330
|
-
overflow-y: initial;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
</style>
|
|
334
346
|
<div class="wrap hide-if-js">
|
|
335
347
|
<h1 class="wp-heading-inline"><?php echo esc_html( get_admin_page_title() ); ?></h1>
|
|
336
348
|
<?php
|
|
337
349
|
wp_admin_notice(
|
|
350
|
+
// phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- Core string, translated in the default text domain.
|
|
338
351
|
__( 'This screen requires JavaScript. Enable JavaScript in your browser settings and reload the page.' ),
|
|
339
352
|
array( 'type' => 'error' )
|
|
340
353
|
);
|
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
* @package {{PREFIX}}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
if ( ! defined( 'ABSPATH' ) ) {
|
|
11
|
+
exit;
|
|
12
|
+
}
|
|
13
|
+
|
|
10
14
|
// Global storage for {{PAGE_SLUG}} routes and menu items
|
|
11
15
|
global ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_routes, ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_menu_items;
|
|
12
16
|
${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_routes = array();
|
|
@@ -88,7 +92,7 @@ function {{PREFIX}}_get_{{PAGE_SLUG_UNDERSCORE}}_menu_items() {
|
|
|
88
92
|
*/
|
|
89
93
|
function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_preload_data() {
|
|
90
94
|
// Define paths to preload - same for all pages
|
|
91
|
-
// This must exactly match the _fields list in packages/core-data/src/entities.
|
|
95
|
+
// This must exactly match the _fields list in packages/core-data/src/entities.ts,
|
|
92
96
|
// same fields in the same order, or the preload is never consumed.
|
|
93
97
|
$preload_paths = array(
|
|
94
98
|
'/?_fields=description,generate_animated_image_subsizes,gmt_offset,home,image_max_bit_depth,image_sizes,image_size_threshold,image_strip_meta,name,site_icon,site_icon_url,site_logo,timezone_string,url,page_for_posts,page_on_front,show_on_front',
|
|
@@ -164,7 +168,7 @@ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_render_page() {
|
|
|
164
168
|
// This script serves two purposes:
|
|
165
169
|
// 1. It ensures all the globals that are made available to the modules are loaded.
|
|
166
170
|
// 2. It initializes the boot module as an inline script.
|
|
167
|
-
wp_register_script( '{{PAGE_SLUG}}-prerequisites',
|
|
171
|
+
wp_register_script( '{{PAGE_SLUG}}-prerequisites', false, $asset['dependencies'], $asset['version'], true );
|
|
168
172
|
|
|
169
173
|
// Add inline script to initialize the app
|
|
170
174
|
$init_modules = {{INIT_MODULES_JSON}};
|
|
@@ -189,6 +193,23 @@ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_render_page() {
|
|
|
189
193
|
);
|
|
190
194
|
wp_register_style( '{{PAGE_SLUG}}-prerequisites', false, $style_dependencies, $asset['version'] );
|
|
191
195
|
|
|
196
|
+
// Base styles for the full-page screen, which renders without the wp-admin stylesheets.
|
|
197
|
+
// `:where()` lets a page that shows the admin bar override the rule hiding it.
|
|
198
|
+
$page_styles = <<<'CSS'
|
|
199
|
+
html {
|
|
200
|
+
background: #f1f1f1;
|
|
201
|
+
color: #444;
|
|
202
|
+
font-family: -apple-system, system-ui, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
|
203
|
+
font-size: 13px;
|
|
204
|
+
line-height: 1.4em;
|
|
205
|
+
}
|
|
206
|
+
body {
|
|
207
|
+
margin: 0;
|
|
208
|
+
}
|
|
209
|
+
:where(#wpadminbar) { display: none; }
|
|
210
|
+
CSS;
|
|
211
|
+
wp_add_inline_style( '{{PAGE_SLUG}}-prerequisites', $page_styles );
|
|
212
|
+
|
|
192
213
|
// Build dependencies for {{PAGE_SLUG}} module
|
|
193
214
|
$boot_dependencies = array(
|
|
194
215
|
array(
|
|
@@ -252,19 +273,6 @@ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_render_page() {
|
|
|
252
273
|
<meta charset="<?php bloginfo( 'charset' ); ?>">
|
|
253
274
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
254
275
|
<title><?php echo esc_html( get_admin_page_title() ); ?></title>
|
|
255
|
-
<style>
|
|
256
|
-
html {
|
|
257
|
-
background: #f1f1f1;
|
|
258
|
-
color: #444;
|
|
259
|
-
font-family: -apple-system, system-ui, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
|
260
|
-
font-size: 13px;
|
|
261
|
-
line-height: 1.4em;
|
|
262
|
-
}
|
|
263
|
-
body {
|
|
264
|
-
margin: 0;
|
|
265
|
-
}
|
|
266
|
-
#wpadminbar { display: none; }
|
|
267
|
-
</style>
|
|
268
276
|
<?php
|
|
269
277
|
global $hook_suffix;
|
|
270
278
|
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
|
@@ -285,17 +293,14 @@ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_render_page() {
|
|
|
285
293
|
<body class="{{PAGE_SLUG}} no-js">
|
|
286
294
|
<?php
|
|
287
295
|
// BEGIN see wp-admin/admin-header.php
|
|
288
|
-
|
|
289
|
-
<script type="text/javascript">
|
|
290
|
-
document.body.className = document.body.className.replace( 'no-js', 'js' );
|
|
291
|
-
</script>
|
|
292
|
-
<?php
|
|
296
|
+
wp_print_inline_script_tag( "document.body.className = document.body.className.replace( 'no-js', 'js' );" );
|
|
293
297
|
// END see wp-admin/admin-header.php
|
|
294
298
|
?>
|
|
295
299
|
<div class="wrap hide-if-js" style="margin: 20px;">
|
|
296
300
|
<h1 class="wp-heading-inline"><?php echo esc_html( get_admin_page_title() ); ?></h1>
|
|
297
301
|
<?php
|
|
298
302
|
wp_admin_notice(
|
|
303
|
+
// phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- Core string, translated in the default text domain.
|
|
299
304
|
__( 'This screen requires JavaScript. Enable JavaScript in your browser settings and reload the page.' ),
|
|
300
305
|
array( 'type' => 'error' )
|
|
301
306
|
);
|
|
@@ -343,7 +348,8 @@ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_intercept_render() {
|
|
|
343
348
|
|
|
344
349
|
if ( ! current_user_can( '{{CAPABILITY}}' ) ) {
|
|
345
350
|
wp_die(
|
|
346
|
-
|
|
351
|
+
// phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- Core string, translated in the default text domain.
|
|
352
|
+
esc_html__( 'Sorry, you are not allowed to access this page.' ),
|
|
347
353
|
403
|
|
348
354
|
);
|
|
349
355
|
}
|