Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ideas for 64845 #65250

Draft
wants to merge 8 commits into
base: trunk
Choose a base branch
from
Draft
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
6 changes: 5 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ module.exports = ( api ) => {

return {
presets: [ '@wordpress/babel-preset-default' ],
plugins: [ '@emotion/babel-plugin', 'babel-plugin-inline-json-import' ],
plugins: [
'@emotion/babel-plugin',
'babel-plugin-inline-json-import',
require.resolve( '@shopify/web-worker/babel' ),
],
overrides: [
{
test: 'packages/block-library/src/index.js',
Expand Down
19 changes: 19 additions & 0 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,25 @@ function gutenberg_register_vendor_scripts( $scripts ) {
array( 'react' ),
'18'
);

wp_register_script_module(
'@wordpress/vips/vips',
gutenberg_url( 'build/vendors/vips.wasm' ),
array(),
'vips-version-not-this-string'
);
wp_register_script_module(
'@wordpress/vips/vips-heif',
gutenberg_url( 'build/vendors/vips-heif.wasm' ),
array(),
'vips-version-not-this-string'
);
wp_register_script_module(
'@wordpress/vips/vips-jxl',
gutenberg_url( 'build/vendors/vips-jxl.wasm' ),
array(),
'vips-version-not-this-string'
);
}
add_action( 'wp_default_scripts', 'gutenberg_register_vendor_scripts' );

Expand Down
29 changes: 21 additions & 8 deletions lib/experimental/media/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,24 @@
return null;
}

/**
* Filters the list of rewrite rules formatted for output to an .htaccess file.
*
* Adds support for serving wasm-vips locally.
*
* @param string $rules mod_rewrite Rewrite rules formatted for .htaccess.
* @return string Filtered rewrite rules.
*/
function gutenberg_filter_mod_rewrite_rules( string $rules ): string {
$rules .= "\n# BEGIN Gutenberg client-side media processing experiment\n" .
"AddType application/wasm wasm\n" .

Check warning on line 199 in lib/experimental/media/load.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Found precision alignment of 2 spaces.

Check failure on line 199 in lib/experimental/media/load.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Tabs must be used to indent lines; spaces are not allowed
"# END Gutenberg client-side media processing experiment\n";

Check warning on line 200 in lib/experimental/media/load.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Found precision alignment of 2 spaces.

Check failure on line 200 in lib/experimental/media/load.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Tabs must be used to indent lines; spaces are not allowed

return $rules;
}

add_filter( 'mod_rewrite_rules', 'gutenberg_filter_mod_rewrite_rules' );

/**
* Enables cross-origin isolation in the block editor.
*
Expand Down Expand Up @@ -236,16 +254,11 @@
$coep = $is_safari ? 'require-corp' : 'credentialless';

ob_start(
function ( string $output, ?int $phase ) use ( $coep ): string {

Check warning on line 257 in lib/experimental/media/load.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Unused function parameter $phase.
// Only send the header when the buffer is not being cleaned.
if ( ( $phase & PHP_OUTPUT_HANDLER_CLEAN ) === 0 ) {
header( 'Cross-Origin-Opener-Policy: same-origin' );
header( "Cross-Origin-Embedder-Policy: $coep" );

$output = gutenberg_add_crossorigin_attributes( $output );
}
header( 'Cross-Origin-Opener-Policy: same-origin' );
header( "Cross-Origin-Embedder-Policy: $coep" );

return $output;
return gutenberg_add_crossorigin_attributes( $output );
}
);
}
Expand Down
93 changes: 91 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"@wordpress/undo-manager": "file:packages/undo-manager",
"@wordpress/url": "file:packages/url",
"@wordpress/viewport": "file:packages/viewport",
"@wordpress/vips": "file:packages/vips",
"@wordpress/warning": "file:packages/warning",
"@wordpress/widgets": "file:packages/widgets",
"@wordpress/wordcount": "file:packages/wordcount",
Expand Down Expand Up @@ -116,6 +117,7 @@
"@react-native/babel-preset": "0.73.10",
"@react-native/metro-babel-transformer": "0.73.10",
"@react-native/metro-config": "0.73.4",
"@shopify/web-worker": "6.3.0",
"@storybook/addon-a11y": "7.6.15",
"@storybook/addon-actions": "7.6.15",
"@storybook/addon-controls": "7.6.15",
Expand Down
4 changes: 3 additions & 1 deletion packages/media-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
"types": "build-types",
"dependencies": {
"@babel/runtime": "^7.16.0",
"@shopify/web-worker": "^6.3.0",
"@wordpress/api-fetch": "file:../api-fetch",
"@wordpress/blob": "file:../blob",
"@wordpress/element": "file:../element",
"@wordpress/i18n": "file:../i18n"
"@wordpress/i18n": "file:../i18n",
"@wordpress/vips": "file:../vips"
},
"publishConfig": {
"access": "public"
Expand Down
27 changes: 27 additions & 0 deletions packages/media-utils/src/utils/upload-to-server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import { createWorkerFactory } from '@shopify/web-worker';

/**
* WordPress dependencies
*/
Expand All @@ -10,11 +15,33 @@
import { transformAttachment } from './transform-attachment';
import type { CreateRestAttachment, RestAttachment } from './types';

/*
! FOR TESTING PURPOSES ONLY !

__webpack_public_path__ will be something like
https://example/wp-content/plugins/gutenberg/build/media-utils/../../
*/
const createVipsWorker = createWorkerFactory(
() => import( /* webpackChunkName: 'vips' */ '@wordpress/vips' )
);
const vipsWorker = createVipsWorker();

//void vipsWorker.setLocation( __webpack_public_path__ );

Check failure on line 29 in packages/media-utils/src/utils/upload-to-server.ts

View workflow job for this annotation

GitHub Actions / Check

Cannot find name '__webpack_public_path__'.

export async function uploadToServer(
file: File,
additionalData: CreateRestAttachment = {},
signal?: AbortSignal
) {
// FOR TESTING PURPOSES ONLY!
const outBuffer = await vipsWorker.compressImage(
'foo',
await file.arrayBuffer(),
file.type
);
const blob = new Blob( [ outBuffer ], { type: file.type } );
file = new File( [ blob ], file.name, { type: file.type } );

// Create upload payload.
const data = new FormData();
data.append( 'file', file, file.name || file.type.replace( '/', '.' ) );
Expand Down
3 changes: 2 additions & 1 deletion packages/media-utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
{ "path": "../api-fetch" },
{ "path": "../blob" },
{ "path": "../element" },
{ "path": "../i18n" }
{ "path": "../i18n" },
{ "path": "../vips" }
]
}
1 change: 1 addition & 0 deletions packages/vips/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
7 changes: 7 additions & 0 deletions packages/vips/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- Learn how to maintain this file at https://github.com/WordPress/gutenberg/tree/HEAD/packages#maintaining-changelogs. -->

## Unreleased

### New Features

- Initial public release.
Loading
Loading