Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Proxy modules
  • Loading branch information
sirreal committed Mar 13, 2024
commit bd3377b3e80aa49eddedbc062fb22ef1378da883
6 changes: 6 additions & 0 deletions src/wp-includes/js/esm-proxy/a11y.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if ( ! Object.hasOwn( globalThis, 'wp' ) || ! Object.hasOwn( globalThis.wp, 'a11y' ) ) {
throw new Error( `Script dependency not found, missing: \`wp.a11y\`` );
}

export const setup = globalThis['wp']['a11y']['setup'];
export const speak = globalThis['wp']['a11y']['speak'];
5 changes: 5 additions & 0 deletions src/wp-includes/js/esm-proxy/api-fetch.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if ( ! Object.hasOwn( globalThis, 'wp' ) || ! Object.hasOwn( globalThis.wp, 'apiFetch' ) ) {
throw new Error( `Script dependency not found, missing: \`wp.apiFetch\`` );
}

export default globalThis['wp']['apiFetch'];
10 changes: 10 additions & 0 deletions src/wp-includes/js/esm-proxy/blob.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if ( ! Object.hasOwn( globalThis, 'wp' ) || ! Object.hasOwn( globalThis.wp, 'blob' ) ) {
throw new Error( `Script dependency not found, missing: \`wp.blob\`` );
}

export const createBlobURL = globalThis['wp']['blob'].createBlobURL;
export const downloadBlob = globalThis['wp']['blob'].downloadBlob;
export const getBlobByURL = globalThis['wp']['blob'].getBlobByURL;
export const getBlobTypeByURL = globalThis['wp']['blob'].getBlobTypeByURL;
export const isBlobURL = globalThis['wp']['blob'].isBlobURL;
export const revokeBlobURL = globalThis['wp']['blob'].revokeBlobURL;
19 changes: 19 additions & 0 deletions src/wp-includes/script-modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,22 @@ function wp_dequeue_script_module( string $id ) {
function wp_deregister_script_module( string $id ) {
wp_script_modules()->deregister( $id );
}

add_action( 'init', function () {
$base = includes_url( 'js/esm-proxy/' );
$suffix = '.esm.js';

$script_script_modules = array(
'api-fetch',
'a11y',
'blob',
);

foreach ( $script_script_modules as $handle ) {
wp_register_script_module(
'@wordpress/' . $handle,
$base . $handle . $suffix,
array( array( 'id' => 'wp-' . $handle, 'import' => 'wp-script' ) ),
);
}
} );