Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy committed Dec 2, 2024
1 parent bae3e67 commit 93e9ec9
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 99 deletions.
37 changes: 15 additions & 22 deletions packages/block-editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,28 +105,21 @@ export const ExperimentalBlockEditorProvider = withRegistryProvider(

const mediaUploadSettings = useMediaUploadSettings( _settings );

// Create a new variable so that the original props.settings.mediaUpload is not modified.
const settings = useMemo(
() => ( {
..._settings,
mediaUpload: _settings.mediaUpload
? mediaUpload.bind(
null,
registry,
_settings.experimentalValidateMimeType || noop,
_settings.validateFileSize || noop
)
: undefined,
} ),
[ _settings, registry ]
);

if ( window.__experimentalMediaProcessing && settings.mediaUpload ) {
settings.mediaUpload = mediaUpload.bind(
null,
registry,
settings.experimentalValidateMimeType || noop,
settings.validateFileSize || noop
let settings = _settings;

if ( window.__experimentalMediaProcessing && _settings.mediaUpload ) {
// Create a new variable so that the original props.settings.mediaUpload is not modified.
settings = useMemo(
() => ( {
..._settings,
mediaUpload: mediaUpload.bind(
null,
registry,
_settings.experimentalValidateMimeType || noop,
_settings.validateFileSize || noop
),
} ),
[ _settings, registry ]
);
}

Expand Down
1 change: 1 addition & 0 deletions packages/editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ _Parameters_
- _$0.maxUploadFileSize_ `?number`: Maximum upload size in bytes allowed for the site.
- _$0.onError_ `Function`: Function called when an error happens.
- _$0.onFileChange_ `Function`: Function called each time a file or a temporary representation of the file is available.
- _$0.onSuccess_ `Function`: Function called after the final representation of the file is available.

### MediaUploadCheck

Expand Down
1 change: 1 addition & 0 deletions packages/media-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ _Parameters_
- _$0.maxUploadFileSize_ `UploadMediaArgs[ 'maxUploadFileSize' ]`: Maximum upload size in bytes allowed for the site.
- _$0.onError_ `UploadMediaArgs[ 'onError' ]`: Function called when an error happens.
- _$0.onFileChange_ `UploadMediaArgs[ 'onFileChange' ]`: Function called each time a file or a temporary representation of the file is available.
- _$0.onSuccess_ `UploadMediaArgs[ 'onSuccess' ]`: Function called after the final representation of the file is available.
- _$0.wpAllowedMimeTypes_ `UploadMediaArgs[ 'wpAllowedMimeTypes' ]`: List of allowed mime types and file extensions.
- _$0.signal_ `UploadMediaArgs[ 'signal' ]`: Abort signal.

Expand Down
1 change: 1 addition & 0 deletions packages/media-utils/src/utils/upload-media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ interface UploadMediaArgs {
* @param $0.maxUploadFileSize Maximum upload size in bytes allowed for the site.
* @param $0.onError Function called when an error happens.
* @param $0.onFileChange Function called each time a file or a temporary representation of the file is available.
* @param $0.onSuccess Function called after the final representation of the file is available.
* @param $0.wpAllowedMimeTypes List of allowed mime types and file extensions.
* @param $0.signal Abort signal.
*/
Expand Down
76 changes: 1 addition & 75 deletions packages/upload-media/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,40 +34,6 @@ _Parameters_
- _error_ `Error`: Error instance.
- _silent_ Whether to cancel the item silently, without invoking its `onError` callback.

#### grantApproval

Approves a proposed optimized/converted version of a file so it can continue being processed and uploaded.

_Parameters_

- _id_ `number`: Item ID.

#### optimizeExistingItem

Adds a new item to the upload queue for optimizing (compressing) an existing item.

_Parameters_

- _$0_ `OptimizeExistingItemArgs`:
- _$0.id_ `OptimizeExistingItemArgs[ 'id' ]`: Attachment ID.
- _$0.url_ `OptimizeExistingItemArgs[ 'url' ]`: URL.
- _$0.fileName_ `[OptimizeExistingItemArgs[ 'fileName' ]]`: File name.
- _$0.poster_ `[OptimizeExistingItemArgs[ 'poster' ]]`: Poster URL.
- _$0.batchId_ `[OptimizeExistingItemArgs[ 'batchId' ]]`: Batch ID.
- _$0.onChange_ `[OptimizeExistingItemArgs[ 'onChange' ]]`: Function called each time a file or a temporary representation of the file is available.
- _$0.onSuccess_ `[OptimizeExistingItemArgs[ 'onSuccess' ]]`: Function called after the file is uploaded.
- _$0.onBatchSuccess_ `[OptimizeExistingItemArgs[ 'onBatchSuccess' ]]`: Function called after a batch of files is uploaded.
- _$0.onError_ `[OptimizeExistingItemArgs[ 'onError' ]]`: Function called when an error happens.
- _$0.additionalData_ `[OptimizeExistingItemArgs[ 'additionalData' ]]`: Additional data to include in the request.

#### rejectApproval

Rejects a proposed optimized/converted version of a file by essentially cancelling its further processing.

_Parameters_

- _id_ `number`: Item ID.

<!-- END TOKEN(Autogenerated actions|src/store/actions.ts) -->

### Selectors
Expand All @@ -76,24 +42,9 @@ The following selectors are available on the object returned by `wp.data.select(

<!-- START TOKEN(Autogenerated selectors|src/store/selectors.ts) -->

#### getComparisonDataForApproval

Returns data to compare the old file vs. the optimized file, given the attachment ID.

Includes both the URLs and the respective file sizes and the size difference in percentage.

_Parameters_

- _state_ `State`: Upload state.
- _attachmentId_ `number`: Attachment ID.

_Returns_

- `{ oldUrl: string | undefined; oldSize: number; newSize: number; newUrl: string | undefined; sizeDiff: number; } | null`: Comparison data.

#### getItems

Returns all items currently being uploaded, without sub-sizes (children).
Returns all items currently being uploaded.

_Parameters_

Expand All @@ -115,31 +66,6 @@ _Returns_

- `Settings`: Settings

#### isPendingApproval

Determines whether there is an item pending approval.

_Parameters_

- _state_ `State`: Upload state.

_Returns_

- `boolean`: Whether there is an item pending approval.

#### isPendingApprovalByAttachmentId

Determines whether an item is the first one pending approval given its associated attachment ID.

_Parameters_

- _state_ `State`: Upload state.
- _attachmentId_ `number`: Attachment ID.

_Returns_

- `boolean`: Whether the item is first in the list of items pending approval.

#### isUploading

Determines whether any upload is currently in progress.
Expand Down
2 changes: 0 additions & 2 deletions packages/upload-media/src/store/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
type AddOperationsAction,
type CacheBlobUrlAction,
type CancelAction,
ItemStatus,
type OperationFinishAction,
type OperationStartAction,
type PauseQueueAction,
Expand Down Expand Up @@ -49,7 +48,6 @@ function reducer(
state = DEFAULT_STATE,
action: Action = { type: Type.Unknown }
) {
console.log( 'reducer', state, action );
switch ( action.type ) {
case Type.PauseQueue: {
return {
Expand Down

0 comments on commit 93e9ec9

Please sign in to comment.