From 8f7bd86415ab4dc1a1f564a2001e53470b4f0222 Mon Sep 17 00:00:00 2001 From: flootr Date: Mon, 16 Jan 2023 08:51:21 +0100 Subject: [PATCH] `MediaUtils`: move `window` access to function body (#46970) --- packages/blob/src/index.js | 9 ++------- .../src/components/media-upload/index.js | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/blob/src/index.js b/packages/blob/src/index.js index 3af66755c011e8..67a48e0003150a 100644 --- a/packages/blob/src/index.js +++ b/packages/blob/src/index.js @@ -1,8 +1,3 @@ -/** - * Browser dependencies - */ -const { createObjectURL, revokeObjectURL } = window.URL; - /** * @type {Record} */ @@ -16,7 +11,7 @@ const cache = {}; * @return {string} The blob URL. */ export function createBlobURL( file ) { - const url = createObjectURL( file ); + const url = window.URL.createObjectURL( file ); cache[ url ] = file; @@ -56,7 +51,7 @@ export function getBlobTypeByURL( url ) { */ export function revokeBlobURL( url ) { if ( cache[ url ] ) { - revokeObjectURL( url ); + window.URL.revokeObjectURL( url ); } delete cache[ url ]; diff --git a/packages/media-utils/src/components/media-upload/index.js b/packages/media-utils/src/components/media-upload/index.js index 03343e8b1cbe9a..bf2da5c470a5ef 100644 --- a/packages/media-utils/src/components/media-upload/index.js +++ b/packages/media-utils/src/components/media-upload/index.js @@ -4,16 +4,16 @@ import { Component } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; -const { wp } = window; - const DEFAULT_EMPTY_GALLERY = []; /** * Prepares the Featured Image toolbars and frames. * - * @return {wp.media.view.MediaFrame.Select} The default media workflow. + * @return {window.wp.media.view.MediaFrame.Select} The default media workflow. */ const getFeaturedImageMediaFrame = () => { + const { wp } = window; + return wp.media.view.MediaFrame.Select.extend( { /** * Enables the Set Featured Image Button. @@ -73,9 +73,10 @@ const getFeaturedImageMediaFrame = () => { /** * Prepares the Gallery toolbars and frames. * - * @return {wp.media.view.MediaFrame.Post} The default media workflow. + * @return {window.wp.media.view.MediaFrame.Post} The default media workflow. */ const getGalleryDetailsMediaFrame = () => { + const { wp } = window; /** * Custom gallery details frame. * @@ -210,6 +211,8 @@ const slimImageObject = ( img ) => { }; const getAttachmentsCollection = ( ids ) => { + const { wp } = window; + return wp.media.query( { order: 'ASC', orderby: 'post__in', @@ -236,6 +239,8 @@ class MediaUpload extends Component { this.onUpdate = this.onUpdate.bind( this ); this.onClose = this.onClose.bind( this ); + const { wp } = window; + if ( gallery ) { this.buildAndSetGalleryFrame(); } else { @@ -287,6 +292,8 @@ class MediaUpload extends Component { return; } + const { wp } = window; + this.lastGalleryValue = value; // If a frame already existed remove it. @@ -324,6 +331,7 @@ class MediaUpload extends Component { * @return {void} */ buildAndSetFeatureImageFrame() { + const { wp } = window; const featuredImageFrame = getFeaturedImageMediaFrame(); const attachments = getAttachmentsCollection( this.props.value ); const selection = new wp.media.model.Selection( attachments.models, { @@ -371,6 +379,7 @@ class MediaUpload extends Component { } onOpen() { + const { wp } = window; const { value } = this.props; this.updateCollection();