From 40b13eaa54d336865ad52bb3f6bbbc921ead79a4 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Tue, 5 Mar 2024 18:35:25 +0100 Subject: [PATCH 1/5] External Media: support editor changes in WordPress 6.5 Fixes #36186 --- .../plugins/jetpack/changelog/update-external-media-store | 4 ++++ .../extensions/shared/external-media/media-service/index.ts | 1 + 2 files changed, 5 insertions(+) create mode 100644 projects/plugins/jetpack/changelog/update-external-media-store diff --git a/projects/plugins/jetpack/changelog/update-external-media-store b/projects/plugins/jetpack/changelog/update-external-media-store new file mode 100644 index 0000000000000..d34284e631488 --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-external-media-store @@ -0,0 +1,4 @@ +Significance: patch +Type: other + +External Media: support editor changes in WordPress 6.5. diff --git a/projects/plugins/jetpack/extensions/shared/external-media/media-service/index.ts b/projects/plugins/jetpack/extensions/shared/external-media/media-service/index.ts index c665bbfdaeb07..0ef6f39c3d5ed 100644 --- a/projects/plugins/jetpack/extensions/shared/external-media/media-service/index.ts +++ b/projects/plugins/jetpack/extensions/shared/external-media/media-service/index.ts @@ -197,6 +197,7 @@ const isMediaSourceConnected = async ( source: MediaSource ) => */ const isInserterOpened = (): boolean => select( 'core/edit-post' )?.isInserterOpened() || + select( 'core/editor' )?.isInserterOpened() || select( 'core/edit-site' )?.isInserterOpened() || select( 'core/edit-widgets' )?.isInserterOpened?.(); From 81ea640c046f9cc54574a7314b12fbbab6894683 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Wed, 6 Mar 2024 12:27:26 +0100 Subject: [PATCH 2/5] Avoid build errors --- .../extensions/shared/external-media/media-service/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/projects/plugins/jetpack/extensions/shared/external-media/media-service/index.ts b/projects/plugins/jetpack/extensions/shared/external-media/media-service/index.ts index 0ef6f39c3d5ed..d92ca64886ca1 100644 --- a/projects/plugins/jetpack/extensions/shared/external-media/media-service/index.ts +++ b/projects/plugins/jetpack/extensions/shared/external-media/media-service/index.ts @@ -196,8 +196,11 @@ const isMediaSourceConnected = async ( source: MediaSource ) => * @returns {boolean} True if the inserter is opened false otherwise. */ const isInserterOpened = (): boolean => + // @to-do: remove exception when Jetpack requires WordPress 6.5. + // eslint-disable-next-line + // @ts-ignore + select( 'core/editor' )?.isInserterOpened?.() || select( 'core/edit-post' )?.isInserterOpened() || - select( 'core/editor' )?.isInserterOpened() || select( 'core/edit-site' )?.isInserterOpened() || select( 'core/edit-widgets' )?.isInserterOpened?.(); From 82d869f83a398660393243614f48a5297adbdc43 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Fri, 8 Mar 2024 17:22:55 +0100 Subject: [PATCH 3/5] Try to be more explicit in checking for isInserterOpened --- .../external-media/media-service/index.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/projects/plugins/jetpack/extensions/shared/external-media/media-service/index.ts b/projects/plugins/jetpack/extensions/shared/external-media/media-service/index.ts index d92ca64886ca1..9de520a8cddf3 100644 --- a/projects/plugins/jetpack/extensions/shared/external-media/media-service/index.ts +++ b/projects/plugins/jetpack/extensions/shared/external-media/media-service/index.ts @@ -195,14 +195,22 @@ const isMediaSourceConnected = async ( source: MediaSource ) => * * @returns {boolean} True if the inserter is opened false otherwise. */ -const isInserterOpened = (): boolean => +const isInserterOpened = (): boolean => { + // Prior to WP 6.5, the isInserterOpened selector was available in core/edit-post. + // In WP 6.5, it was moved to core/editor. This check is to support both versions of WordPress. // @to-do: remove exception when Jetpack requires WordPress 6.5. // eslint-disable-next-line // @ts-ignore - select( 'core/editor' )?.isInserterOpened?.() || - select( 'core/edit-post' )?.isInserterOpened() || - select( 'core/edit-site' )?.isInserterOpened() || - select( 'core/edit-widgets' )?.isInserterOpened?.(); + const editorIsInserterOpened = select( 'core/editor' )?.isInserterOpened?.(); + const editPostIsInserterOpened = select( 'core/edit-post' )?.isInserterOpened(); + + return ( + editorIsInserterOpened || + editPostIsInserterOpened || + select( 'core/edit-site' )?.isInserterOpened() || + select( 'core/edit-widgets' )?.isInserterOpened() + ); +}; const registerInInserter = ( mediaCategoryProvider: () => object ) => // Remove as soon @types/wordpress__block-editor is up to date From 8c2a743a5a712bf12124b9ccd611f2f6e63b8f75 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Wed, 13 Mar 2024 16:07:11 +0100 Subject: [PATCH 4/5] Another try around TypeScript --- .../shared/external-media/media-service/index.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/projects/plugins/jetpack/extensions/shared/external-media/media-service/index.ts b/projects/plugins/jetpack/extensions/shared/external-media/media-service/index.ts index 9de520a8cddf3..d79a6eeb7334a 100644 --- a/projects/plugins/jetpack/extensions/shared/external-media/media-service/index.ts +++ b/projects/plugins/jetpack/extensions/shared/external-media/media-service/index.ts @@ -199,14 +199,14 @@ const isInserterOpened = (): boolean => { // Prior to WP 6.5, the isInserterOpened selector was available in core/edit-post. // In WP 6.5, it was moved to core/editor. This check is to support both versions of WordPress. // @to-do: remove exception when Jetpack requires WordPress 6.5. - // eslint-disable-next-line - // @ts-ignore - const editorIsInserterOpened = select( 'core/editor' )?.isInserterOpened?.(); - const editPostIsInserterOpened = select( 'core/edit-post' )?.isInserterOpened(); + /* eslint-disable @typescript-eslint/no-explicit-any */ + const editorIsInserterOpened = ( select( 'core/editor' ) as any )?.isInserterOpened?.() + ? ( select( 'core/editor' ) as any )?.isInserterOpened?.() + : select( 'core/edit-post' )?.isInserterOpened(); + /* eslint-enable @typescript-eslint/no-explicit-any */ return ( editorIsInserterOpened || - editPostIsInserterOpened || select( 'core/edit-site' )?.isInserterOpened() || select( 'core/edit-widgets' )?.isInserterOpened() ); From a36fd02987a61b5c4f65c1511dae8c8524474bc3 Mon Sep 17 00:00:00 2001 From: Renato Augusto Gama dos Santos Date: Thu, 2 May 2024 10:52:42 -0300 Subject: [PATCH 5/5] Media Store: Update call to is inserter opened --- .../shared/external-media/media-service/index.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/projects/plugins/jetpack/extensions/shared/external-media/media-service/index.ts b/projects/plugins/jetpack/extensions/shared/external-media/media-service/index.ts index d79a6eeb7334a..394396bc8a344 100644 --- a/projects/plugins/jetpack/extensions/shared/external-media/media-service/index.ts +++ b/projects/plugins/jetpack/extensions/shared/external-media/media-service/index.ts @@ -199,11 +199,12 @@ const isInserterOpened = (): boolean => { // Prior to WP 6.5, the isInserterOpened selector was available in core/edit-post. // In WP 6.5, it was moved to core/editor. This check is to support both versions of WordPress. // @to-do: remove exception when Jetpack requires WordPress 6.5. - /* eslint-disable @typescript-eslint/no-explicit-any */ - const editorIsInserterOpened = ( select( 'core/editor' ) as any )?.isInserterOpened?.() - ? ( select( 'core/editor' ) as any )?.isInserterOpened?.() - : select( 'core/edit-post' )?.isInserterOpened(); - /* eslint-enable @typescript-eslint/no-explicit-any */ + const selectIsInserterOpened = + /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ + ( select( 'core/editor' ) as any )?.isInserterOpened ?? + select( 'core/edit-post' )?.isInserterOpened; + + const editorIsInserterOpened = selectIsInserterOpened?.(); return ( editorIsInserterOpened ||