Skip to content

Commit

Permalink
Add new private upload-media package
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy committed Oct 21, 2024
1 parent 119cacc commit ad143dc
Show file tree
Hide file tree
Showing 31 changed files with 3,330 additions and 0 deletions.
60 changes: 60 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"@wordpress/sync": "file:packages/sync",
"@wordpress/token-list": "file:packages/token-list",
"@wordpress/undo-manager": "file:packages/undo-manager",
"@wordpress/upload-media": "file:packages/upload-media",
"@wordpress/url": "file:packages/url",
"@wordpress/viewport": "file:packages/viewport",
"@wordpress/vips": "file:packages/vips",
Expand Down
1 change: 1 addition & 0 deletions packages/private-apis/src/implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const CORE_MODULES_USING_PRIVATE_APIS = [
'@wordpress/router',
'@wordpress/dataviews',
'@wordpress/fields',
'@wordpress/upload-media',
];

/**
Expand Down
1 change: 1 addition & 0 deletions packages/upload-media/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
5 changes: 5 additions & 0 deletions packages/upload-media/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- Learn how to maintain this file at https://github.com/WordPress/gutenberg/tree/HEAD/packages#maintaining-changelogs. -->

## Unreleased

Initial release.
43 changes: 43 additions & 0 deletions packages/upload-media/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "@wordpress/upload-media",
"version": "1.0.0-prerelease",
"private": true,
"description": "Core media upload logic.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
"keywords": [
"wordpress",
"media"
],
"homepage": "https://github.com/WordPress/gutenberg/tree/HEAD/packages/upload-media/README.md",
"repository": {
"type": "git",
"url": "https://github.com/WordPress/gutenberg.git",
"directory": "packages/upload-media"
},
"bugs": {
"url": "https://github.com/WordPress/gutenberg/issues"
},
"engines": {
"node": ">=18.12.0",
"npm": ">=8.19.2"
},
"main": "build/index.js",
"module": "build-module/index.js",
"types": "build-types",
"dependencies": {
"@shopify/web-worker": "^6.4.0",
"@wordpress/api-fetch": "file:../api-fetch",
"@wordpress/blob": "file:../blob",
"@wordpress/data": "file:../data",
"@wordpress/i18n": "file:../i18n",
"@wordpress/preferences": "file:../preferences",
"@wordpress/private-apis": "file:../private-apis",
"@wordpress/url": "file:../url",
"@wordpress/vips": "file:../vips",
"uuid": "^9.0.1"
},
"publishConfig": {
"access": "public"
}
}
1 change: 1 addition & 0 deletions packages/upload-media/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const PREFERENCES_NAME = 'core/media';
38 changes: 38 additions & 0 deletions packages/upload-media/src/image-file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* ImageFile class.
*
* Small wrapper around the `File` class to hold
* information about current dimensions and original
* dimensions, in case the image was resized.
*/
export class ImageFile extends File {
width = 0;
height = 0;
originalWidth? = 0;
originalHeight? = 0;

get wasResized() {
return (
( this.originalWidth || 0 ) > this.width ||
( this.originalHeight || 0 ) > this.height
);
}

constructor(
file: File,
width: number,
height: number,
originalWidth?: number,
originalHeight?: number
) {
super( [ file ], file.name, {
type: file.type,
lastModified: file.lastModified,
} );

this.width = width;
this.height = height;
this.originalWidth = originalWidth;
this.originalHeight = originalHeight;
}
}
17 changes: 17 additions & 0 deletions packages/upload-media/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Internal dependencies
*/
import { store as uploadStore } from './store';

export { uploadStore as store };

export { UploadError } from './upload-error';

export type {
ImageFormat,
ImageLibrary,
ImageSizeCrop,
ThumbnailGeneration,
VideoFormat,
AudioFormat,
} from './store/types';
10 changes: 10 additions & 0 deletions packages/upload-media/src/lock-unlock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* WordPress dependencies
*/
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';

export const { lock, unlock } =
__dangerousOptInToUnstableAPIsOnlyForCoreModules(
'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',
'@wordpress/upload-media'
);
Loading

0 comments on commit ad143dc

Please sign in to comment.