From 93e9ec9624e17d81826777f7560a17db6b51f469 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 2 Dec 2024 20:50:57 +0100 Subject: [PATCH] Fixes --- .../src/components/provider/index.js | 37 ++++----- packages/editor/README.md | 1 + packages/media-utils/README.md | 1 + .../media-utils/src/utils/upload-media.ts | 1 + packages/upload-media/README.md | 76 +------------------ packages/upload-media/src/store/reducer.ts | 2 - 6 files changed, 19 insertions(+), 99 deletions(-) diff --git a/packages/block-editor/src/components/provider/index.js b/packages/block-editor/src/components/provider/index.js index 7a75368afe0e4..056b6aeac3cd9 100644 --- a/packages/block-editor/src/components/provider/index.js +++ b/packages/block-editor/src/components/provider/index.js @@ -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 ] ); } diff --git a/packages/editor/README.md b/packages/editor/README.md index dd7b53f421a1d..c1c0c810be908 100644 --- a/packages/editor/README.md +++ b/packages/editor/README.md @@ -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 diff --git a/packages/media-utils/README.md b/packages/media-utils/README.md index ddf18efb28833..51f6284e042a0 100644 --- a/packages/media-utils/README.md +++ b/packages/media-utils/README.md @@ -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. diff --git a/packages/media-utils/src/utils/upload-media.ts b/packages/media-utils/src/utils/upload-media.ts index e10823bac06d1..ae3c417022cb9 100644 --- a/packages/media-utils/src/utils/upload-media.ts +++ b/packages/media-utils/src/utils/upload-media.ts @@ -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. */ diff --git a/packages/upload-media/README.md b/packages/upload-media/README.md index 86f7d41091818..28a97512cf695 100644 --- a/packages/upload-media/README.md +++ b/packages/upload-media/README.md @@ -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. - ### Selectors @@ -76,24 +42,9 @@ The following selectors are available on the object returned by `wp.data.select( -#### 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_ @@ -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. diff --git a/packages/upload-media/src/store/reducer.ts b/packages/upload-media/src/store/reducer.ts index dd5dabca143bc..290a319fcbc1d 100644 --- a/packages/upload-media/src/store/reducer.ts +++ b/packages/upload-media/src/store/reducer.ts @@ -6,7 +6,6 @@ import { type AddOperationsAction, type CacheBlobUrlAction, type CancelAction, - ItemStatus, type OperationFinishAction, type OperationStartAction, type PauseQueueAction, @@ -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 {