[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/js/dist/ -> media-utils.js (source)

   1  /******/ (() => { // webpackBootstrap
   2  /******/     "use strict";
   3  /******/     // The require scope
   4  /******/     var __webpack_require__ = {};
   5  /******/     
   6  /************************************************************************/
   7  /******/     /* webpack/runtime/compat get default export */
   8  /******/     (() => {
   9  /******/         // getDefaultExport function for compatibility with non-harmony modules
  10  /******/         __webpack_require__.n = (module) => {
  11  /******/             var getter = module && module.__esModule ?
  12  /******/                 () => (module['default']) :
  13  /******/                 () => (module);
  14  /******/             __webpack_require__.d(getter, { a: getter });
  15  /******/             return getter;
  16  /******/         };
  17  /******/     })();
  18  /******/     
  19  /******/     /* webpack/runtime/define property getters */
  20  /******/     (() => {
  21  /******/         // define getter functions for harmony exports
  22  /******/         __webpack_require__.d = (exports, definition) => {
  23  /******/             for(var key in definition) {
  24  /******/                 if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  25  /******/                     Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  26  /******/                 }
  27  /******/             }
  28  /******/         };
  29  /******/     })();
  30  /******/     
  31  /******/     /* webpack/runtime/hasOwnProperty shorthand */
  32  /******/     (() => {
  33  /******/         __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  34  /******/     })();
  35  /******/     
  36  /******/     /* webpack/runtime/make namespace object */
  37  /******/     (() => {
  38  /******/         // define __esModule on exports
  39  /******/         __webpack_require__.r = (exports) => {
  40  /******/             if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  41  /******/                 Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  42  /******/             }
  43  /******/             Object.defineProperty(exports, '__esModule', { value: true });
  44  /******/         };
  45  /******/     })();
  46  /******/     
  47  /************************************************************************/
  48  var __webpack_exports__ = {};
  49  // ESM COMPAT FLAG
  50  __webpack_require__.r(__webpack_exports__);
  51  
  52  // EXPORTS
  53  __webpack_require__.d(__webpack_exports__, {
  54    MediaUpload: () => (/* reexport */ media_upload),
  55    uploadMedia: () => (/* reexport */ uploadMedia)
  56  });
  57  
  58  ;// CONCATENATED MODULE: external ["wp","element"]
  59  const external_wp_element_namespaceObject = window["wp"]["element"];
  60  ;// CONCATENATED MODULE: external ["wp","i18n"]
  61  const external_wp_i18n_namespaceObject = window["wp"]["i18n"];
  62  ;// CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/components/media-upload/index.js
  63  /**
  64   * WordPress dependencies
  65   */
  66  
  67  
  68  const DEFAULT_EMPTY_GALLERY = [];
  69  
  70  /**
  71   * Prepares the Featured Image toolbars and frames.
  72   *
  73   * @return {window.wp.media.view.MediaFrame.Select} The default media workflow.
  74   */
  75  const getFeaturedImageMediaFrame = () => {
  76    const {
  77      wp
  78    } = window;
  79    return wp.media.view.MediaFrame.Select.extend({
  80      /**
  81       * Enables the Set Featured Image Button.
  82       *
  83       * @param {Object} toolbar toolbar for featured image state
  84       * @return {void}
  85       */
  86      featuredImageToolbar(toolbar) {
  87        this.createSelectToolbar(toolbar, {
  88          text: wp.media.view.l10n.setFeaturedImage,
  89          state: this.options.state
  90        });
  91      },
  92      /**
  93       * Handle the edit state requirements of selected media item.
  94       *
  95       * @return {void}
  96       */
  97      editState() {
  98        const selection = this.state('featured-image').get('selection');
  99        const view = new wp.media.view.EditImage({
 100          model: selection.single(),
 101          controller: this
 102        }).render();
 103  
 104        // Set the view to the EditImage frame using the selected image.
 105        this.content.set(view);
 106  
 107        // After bringing in the frame, load the actual editor via an ajax call.
 108        view.loadEditor();
 109      },
 110      /**
 111       * Create the default states.
 112       *
 113       * @return {void}
 114       */
 115      createStates: function createStates() {
 116        this.on('toolbar:create:featured-image', this.featuredImageToolbar, this);
 117        this.on('content:render:edit-image', this.editState, this);
 118        this.states.add([new wp.media.controller.FeaturedImage(), new wp.media.controller.EditImage({
 119          model: this.options.editImage
 120        })]);
 121      }
 122    });
 123  };
 124  
 125  /**
 126   * Prepares the Gallery toolbars and frames.
 127   *
 128   * @return {window.wp.media.view.MediaFrame.Post} The default media workflow.
 129   */
 130  const getGalleryDetailsMediaFrame = () => {
 131    const {
 132      wp
 133    } = window;
 134    /**
 135     * Custom gallery details frame.
 136     *
 137     * @see https://github.com/xwp/wp-core-media-widgets/blob/905edbccfc2a623b73a93dac803c5335519d7837/wp-admin/js/widgets/media-gallery-widget.js
 138     * @class GalleryDetailsMediaFrame
 139     * @class
 140     */
 141    return wp.media.view.MediaFrame.Post.extend({
 142      /**
 143       * Set up gallery toolbar.
 144       *
 145       * @return {void}
 146       */
 147      galleryToolbar() {
 148        const editing = this.state().get('editing');
 149        this.toolbar.set(new wp.media.view.Toolbar({
 150          controller: this,
 151          items: {
 152            insert: {
 153              style: 'primary',
 154              text: editing ? wp.media.view.l10n.updateGallery : wp.media.view.l10n.insertGallery,
 155              priority: 80,
 156              requires: {
 157                library: true
 158              },
 159              /**
 160               * @fires wp.media.controller.State#update
 161               */
 162              click() {
 163                const controller = this.controller,
 164                  state = controller.state();
 165                controller.close();
 166                state.trigger('update', state.get('library'));
 167  
 168                // Restore and reset the default state.
 169                controller.setState(controller.options.state);
 170                controller.reset();
 171              }
 172            }
 173          }
 174        }));
 175      },
 176      /**
 177       * Handle the edit state requirements of selected media item.
 178       *
 179       * @return {void}
 180       */
 181      editState() {
 182        const selection = this.state('gallery').get('selection');
 183        const view = new wp.media.view.EditImage({
 184          model: selection.single(),
 185          controller: this
 186        }).render();
 187  
 188        // Set the view to the EditImage frame using the selected image.
 189        this.content.set(view);
 190  
 191        // After bringing in the frame, load the actual editor via an ajax call.
 192        view.loadEditor();
 193      },
 194      /**
 195       * Create the default states.
 196       *
 197       * @return {void}
 198       */
 199      createStates: function createStates() {
 200        this.on('toolbar:create:main-gallery', this.galleryToolbar, this);
 201        this.on('content:render:edit-image', this.editState, this);
 202        this.states.add([new wp.media.controller.Library({
 203          id: 'gallery',
 204          title: wp.media.view.l10n.createGalleryTitle,
 205          priority: 40,
 206          toolbar: 'main-gallery',
 207          filterable: 'uploaded',
 208          multiple: 'add',
 209          editable: false,
 210          library: wp.media.query({
 211            type: 'image',
 212            ...this.options.library
 213          })
 214        }), new wp.media.controller.EditImage({
 215          model: this.options.editImage
 216        }), new wp.media.controller.GalleryEdit({
 217          library: this.options.selection,
 218          editing: this.options.editing,
 219          menu: 'gallery',
 220          displaySettings: false,
 221          multiple: true
 222        }), new wp.media.controller.GalleryAdd()]);
 223      }
 224    });
 225  };
 226  
 227  // The media library image object contains numerous attributes
 228  // we only need this set to display the image in the library.
 229  const slimImageObject = img => {
 230    const attrSet = ['sizes', 'mime', 'type', 'subtype', 'id', 'url', 'alt', 'link', 'caption'];
 231    return attrSet.reduce((result, key) => {
 232      if (img?.hasOwnProperty(key)) {
 233        result[key] = img[key];
 234      }
 235      return result;
 236    }, {});
 237  };
 238  const getAttachmentsCollection = ids => {
 239    const {
 240      wp
 241    } = window;
 242    return wp.media.query({
 243      order: 'ASC',
 244      orderby: 'post__in',
 245      post__in: ids,
 246      posts_per_page: -1,
 247      query: true,
 248      type: 'image'
 249    });
 250  };
 251  class MediaUpload extends external_wp_element_namespaceObject.Component {
 252    constructor() {
 253      super(...arguments);
 254      this.openModal = this.openModal.bind(this);
 255      this.onOpen = this.onOpen.bind(this);
 256      this.onSelect = this.onSelect.bind(this);
 257      this.onUpdate = this.onUpdate.bind(this);
 258      this.onClose = this.onClose.bind(this);
 259    }
 260    initializeListeners() {
 261      // When an image is selected in the media frame...
 262      this.frame.on('select', this.onSelect);
 263      this.frame.on('update', this.onUpdate);
 264      this.frame.on('open', this.onOpen);
 265      this.frame.on('close', this.onClose);
 266    }
 267  
 268    /**
 269     * Sets the Gallery frame and initializes listeners.
 270     *
 271     * @return {void}
 272     */
 273    buildAndSetGalleryFrame() {
 274      const {
 275        addToGallery = false,
 276        allowedTypes,
 277        multiple = false,
 278        value = DEFAULT_EMPTY_GALLERY
 279      } = this.props;
 280  
 281      // If the value did not changed there is no need to rebuild the frame,
 282      // we can continue to use the existing one.
 283      if (value === this.lastGalleryValue) {
 284        return;
 285      }
 286      const {
 287        wp
 288      } = window;
 289      this.lastGalleryValue = value;
 290  
 291      // If a frame already existed remove it.
 292      if (this.frame) {
 293        this.frame.remove();
 294      }
 295      let currentState;
 296      if (addToGallery) {
 297        currentState = 'gallery-library';
 298      } else {
 299        currentState = value && value.length ? 'gallery-edit' : 'gallery';
 300      }
 301      if (!this.GalleryDetailsMediaFrame) {
 302        this.GalleryDetailsMediaFrame = getGalleryDetailsMediaFrame();
 303      }
 304      const attachments = getAttachmentsCollection(value);
 305      const selection = new wp.media.model.Selection(attachments.models, {
 306        props: attachments.props.toJSON(),
 307        multiple
 308      });
 309      this.frame = new this.GalleryDetailsMediaFrame({
 310        mimeType: allowedTypes,
 311        state: currentState,
 312        multiple,
 313        selection,
 314        editing: value && value.length ? true : false
 315      });
 316      wp.media.frame = this.frame;
 317      this.initializeListeners();
 318    }
 319  
 320    /**
 321     * Initializes the Media Library requirements for the featured image flow.
 322     *
 323     * @return {void}
 324     */
 325    buildAndSetFeatureImageFrame() {
 326      const {
 327        wp
 328      } = window;
 329      const {
 330        value: featuredImageId,
 331        multiple,
 332        allowedTypes
 333      } = this.props;
 334      const featuredImageFrame = getFeaturedImageMediaFrame();
 335      const attachments = getAttachmentsCollection(featuredImageId);
 336      const selection = new wp.media.model.Selection(attachments.models, {
 337        props: attachments.props.toJSON()
 338      });
 339      this.frame = new featuredImageFrame({
 340        mimeType: allowedTypes,
 341        state: 'featured-image',
 342        multiple,
 343        selection,
 344        editing: featuredImageId
 345      });
 346      wp.media.frame = this.frame;
 347      // In order to select the current featured image when opening
 348      // the media library we have to set the appropriate settings.
 349      // Currently they are set in php for the post editor, but
 350      // not for site editor.
 351      wp.media.view.settings.post = {
 352        ...wp.media.view.settings.post,
 353        featuredImageId: featuredImageId || -1
 354      };
 355    }
 356    componentWillUnmount() {
 357      this.frame?.remove();
 358    }
 359    onUpdate(selections) {
 360      const {
 361        onSelect,
 362        multiple = false
 363      } = this.props;
 364      const state = this.frame.state();
 365      const selectedImages = selections || state.get('selection');
 366      if (!selectedImages || !selectedImages.models.length) {
 367        return;
 368      }
 369      if (multiple) {
 370        onSelect(selectedImages.models.map(model => slimImageObject(model.toJSON())));
 371      } else {
 372        onSelect(slimImageObject(selectedImages.models[0].toJSON()));
 373      }
 374    }
 375    onSelect() {
 376      const {
 377        onSelect,
 378        multiple = false
 379      } = this.props;
 380      // Get media attachment details from the frame state.
 381      const attachment = this.frame.state().get('selection').toJSON();
 382      onSelect(multiple ? attachment : attachment[0]);
 383    }
 384    onOpen() {
 385      const {
 386        wp
 387      } = window;
 388      const {
 389        value
 390      } = this.props;
 391      this.updateCollection();
 392  
 393      //Handle active tab in media model on model open.
 394      if (this.props.mode) {
 395        this.frame.content.mode(this.props.mode);
 396      }
 397  
 398      // Handle both this.props.value being either (number[]) multiple ids
 399      // (for galleries) or a (number) singular id (e.g. image block).
 400      const hasMedia = Array.isArray(value) ? !!value?.length : !!value;
 401      if (!hasMedia) {
 402        return;
 403      }
 404      const isGallery = this.props.gallery;
 405      const selection = this.frame.state().get('selection');
 406      const valueArray = Array.isArray(value) ? value : [value];
 407      if (!isGallery) {
 408        valueArray.forEach(id => {
 409          selection.add(wp.media.attachment(id));
 410        });
 411      }
 412  
 413      // Load the images so they are available in the media modal.
 414      const attachments = getAttachmentsCollection(valueArray);
 415  
 416      // Once attachments are loaded, set the current selection.
 417      attachments.more().done(function () {
 418        if (isGallery && attachments?.models?.length) {
 419          selection.add(attachments.models);
 420        }
 421      });
 422    }
 423    onClose() {
 424      const {
 425        onClose
 426      } = this.props;
 427      if (onClose) {
 428        onClose();
 429      }
 430    }
 431    updateCollection() {
 432      const frameContent = this.frame.content.get();
 433      if (frameContent && frameContent.collection) {
 434        const collection = frameContent.collection;
 435  
 436        // Clean all attachments we have in memory.
 437        collection.toArray().forEach(model => model.trigger('destroy', model));
 438  
 439        // Reset has more flag, if library had small amount of items all items may have been loaded before.
 440        collection.mirroring._hasMore = true;
 441  
 442        // Request items.
 443        collection.more();
 444      }
 445    }
 446    openModal() {
 447      const {
 448        allowedTypes,
 449        gallery = false,
 450        unstableFeaturedImageFlow = false,
 451        modalClass,
 452        multiple = false,
 453        title = (0,external_wp_i18n_namespaceObject.__)('Select or Upload Media')
 454      } = this.props;
 455      const {
 456        wp
 457      } = window;
 458      if (gallery) {
 459        this.buildAndSetGalleryFrame();
 460      } else {
 461        const frameConfig = {
 462          title,
 463          multiple
 464        };
 465        if (!!allowedTypes) {
 466          frameConfig.library = {
 467            type: allowedTypes
 468          };
 469        }
 470        this.frame = wp.media(frameConfig);
 471      }
 472      if (modalClass) {
 473        this.frame.$el.addClass(modalClass);
 474      }
 475      if (unstableFeaturedImageFlow) {
 476        this.buildAndSetFeatureImageFrame();
 477      }
 478      this.initializeListeners();
 479      this.frame.open();
 480    }
 481    render() {
 482      return this.props.render({
 483        open: this.openModal
 484      });
 485    }
 486  }
 487  /* harmony default export */ const media_upload = (MediaUpload);
 488  
 489  ;// CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/components/index.js
 490  
 491  
 492  ;// CONCATENATED MODULE: external ["wp","apiFetch"]
 493  const external_wp_apiFetch_namespaceObject = window["wp"]["apiFetch"];
 494  var external_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_wp_apiFetch_namespaceObject);
 495  ;// CONCATENATED MODULE: external ["wp","blob"]
 496  const external_wp_blob_namespaceObject = window["wp"]["blob"];
 497  ;// CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/utils/upload-media.js
 498  /**
 499   * WordPress dependencies
 500   */
 501  
 502  
 503  
 504  const noop = () => {};
 505  
 506  /**
 507   * Browsers may use unexpected mime types, and they differ from browser to browser.
 508   * This function computes a flexible array of mime types from the mime type structured provided by the server.
 509   * Converts { jpg|jpeg|jpe: "image/jpeg" } into [ "image/jpeg", "image/jpg", "image/jpeg", "image/jpe" ]
 510   * The computation of this array instead of directly using the object,
 511   * solves the problem in chrome where mp3 files have audio/mp3 as mime type instead of audio/mpeg.
 512   * https://bugs.chromium.org/p/chromium/issues/detail?id=227004
 513   *
 514   * @param {?Object} wpMimeTypesObject Mime type object received from the server.
 515   *                                    Extensions are keys separated by '|' and values are mime types associated with an extension.
 516   *
 517   * @return {?Array} An array of mime types or the parameter passed if it was "falsy".
 518   */
 519  function getMimeTypesArray(wpMimeTypesObject) {
 520    if (!wpMimeTypesObject) {
 521      return wpMimeTypesObject;
 522    }
 523    return Object.entries(wpMimeTypesObject).map(([extensionsString, mime]) => {
 524      const [type] = mime.split('/');
 525      const extensions = extensionsString.split('|');
 526      return [mime, ...extensions.map(extension => `$type}/$extension}`)];
 527    }).flat();
 528  }
 529  
 530  /**
 531   *    Media Upload is used by audio, image, gallery, video, and file blocks to
 532   *    handle uploading a media file when a file upload button is activated.
 533   *
 534   *    TODO: future enhancement to add an upload indicator.
 535   *
 536   * @param {Object}   $0                    Parameters object passed to the function.
 537   * @param {?Array}   $0.allowedTypes       Array with the types of media that can be uploaded, if unset all types are allowed.
 538   * @param {?Object}  $0.additionalData     Additional data to include in the request.
 539   * @param {Array}    $0.filesList          List of files.
 540   * @param {?number}  $0.maxUploadFileSize  Maximum upload size in bytes allowed for the site.
 541   * @param {Function} $0.onError            Function called when an error happens.
 542   * @param {Function} $0.onFileChange       Function called each time a file or a temporary representation of the file is available.
 543   * @param {?Object}  $0.wpAllowedMimeTypes List of allowed mime types and file extensions.
 544   */
 545  async function uploadMedia({
 546    allowedTypes,
 547    additionalData = {},
 548    filesList,
 549    maxUploadFileSize,
 550    onError = noop,
 551    onFileChange,
 552    wpAllowedMimeTypes = null
 553  }) {
 554    // Cast filesList to array.
 555    const files = [...filesList];
 556    const filesSet = [];
 557    const setAndUpdateFiles = (idx, value) => {
 558      (0,external_wp_blob_namespaceObject.revokeBlobURL)(filesSet[idx]?.url);
 559      filesSet[idx] = value;
 560      onFileChange(filesSet.filter(Boolean));
 561    };
 562  
 563    // Allowed type specified by consumer.
 564    const isAllowedType = fileType => {
 565      if (!allowedTypes) {
 566        return true;
 567      }
 568      return allowedTypes.some(allowedType => {
 569        // If a complete mimetype is specified verify if it matches exactly the mime type of the file.
 570        if (allowedType.includes('/')) {
 571          return allowedType === fileType;
 572        }
 573        // Otherwise a general mime type is used and we should verify if the file mimetype starts with it.
 574        return fileType.startsWith(`$allowedType}/`);
 575      });
 576    };
 577  
 578    // Allowed types for the current WP_User.
 579    const allowedMimeTypesForUser = getMimeTypesArray(wpAllowedMimeTypes);
 580    const isAllowedMimeTypeForUser = fileType => {
 581      return allowedMimeTypesForUser.includes(fileType);
 582    };
 583    const validFiles = [];
 584    for (const mediaFile of files) {
 585      // Verify if user is allowed to upload this mime type.
 586      // Defer to the server when type not detected.
 587      if (allowedMimeTypesForUser && mediaFile.type && !isAllowedMimeTypeForUser(mediaFile.type)) {
 588        onError({
 589          code: 'MIME_TYPE_NOT_ALLOWED_FOR_USER',
 590          message: (0,external_wp_i18n_namespaceObject.sprintf)(
 591          // translators: %s: file name.
 592          (0,external_wp_i18n_namespaceObject.__)('%s: Sorry, you are not allowed to upload this file type.'), mediaFile.name),
 593          file: mediaFile
 594        });
 595        continue;
 596      }
 597  
 598      // Check if the block supports this mime type.
 599      // Defer to the server when type not detected.
 600      if (mediaFile.type && !isAllowedType(mediaFile.type)) {
 601        onError({
 602          code: 'MIME_TYPE_NOT_SUPPORTED',
 603          message: (0,external_wp_i18n_namespaceObject.sprintf)(
 604          // translators: %s: file name.
 605          (0,external_wp_i18n_namespaceObject.__)('%s: Sorry, this file type is not supported here.'), mediaFile.name),
 606          file: mediaFile
 607        });
 608        continue;
 609      }
 610  
 611      // Verify if file is greater than the maximum file upload size allowed for the site.
 612      if (maxUploadFileSize && mediaFile.size > maxUploadFileSize) {
 613        onError({
 614          code: 'SIZE_ABOVE_LIMIT',
 615          message: (0,external_wp_i18n_namespaceObject.sprintf)(
 616          // translators: %s: file name.
 617          (0,external_wp_i18n_namespaceObject.__)('%s: This file exceeds the maximum upload size for this site.'), mediaFile.name),
 618          file: mediaFile
 619        });
 620        continue;
 621      }
 622  
 623      // Don't allow empty files to be uploaded.
 624      if (mediaFile.size <= 0) {
 625        onError({
 626          code: 'EMPTY_FILE',
 627          message: (0,external_wp_i18n_namespaceObject.sprintf)(
 628          // translators: %s: file name.
 629          (0,external_wp_i18n_namespaceObject.__)('%s: This file is empty.'), mediaFile.name),
 630          file: mediaFile
 631        });
 632        continue;
 633      }
 634      validFiles.push(mediaFile);
 635  
 636      // Set temporary URL to create placeholder media file, this is replaced
 637      // with final file from media gallery when upload is `done` below.
 638      filesSet.push({
 639        url: (0,external_wp_blob_namespaceObject.createBlobURL)(mediaFile)
 640      });
 641      onFileChange(filesSet);
 642    }
 643    for (let idx = 0; idx < validFiles.length; ++idx) {
 644      const mediaFile = validFiles[idx];
 645      try {
 646        var _savedMedia$caption$r;
 647        const savedMedia = await createMediaFromFile(mediaFile, additionalData);
 648        // eslint-disable-next-line camelcase
 649        const {
 650          alt_text,
 651          source_url,
 652          ...savedMediaProps
 653        } = savedMedia;
 654        const mediaObject = {
 655          ...savedMediaProps,
 656          alt: savedMedia.alt_text,
 657          caption: (_savedMedia$caption$r = savedMedia.caption?.raw) !== null && _savedMedia$caption$r !== void 0 ? _savedMedia$caption$r : '',
 658          title: savedMedia.title.raw,
 659          url: savedMedia.source_url
 660        };
 661        setAndUpdateFiles(idx, mediaObject);
 662      } catch (error) {
 663        // Reset to empty on failure.
 664        setAndUpdateFiles(idx, null);
 665        let message;
 666        if (error.message) {
 667          message = error.message;
 668        } else {
 669          message = (0,external_wp_i18n_namespaceObject.sprintf)(
 670          // translators: %s: file name
 671          (0,external_wp_i18n_namespaceObject.__)('Error while uploading file %s to the media library.'), mediaFile.name);
 672        }
 673        onError({
 674          code: 'GENERAL',
 675          message,
 676          file: mediaFile
 677        });
 678      }
 679    }
 680  }
 681  
 682  /**
 683   * @param {File}    file           Media File to Save.
 684   * @param {?Object} additionalData Additional data to include in the request.
 685   *
 686   * @return {Promise} Media Object Promise.
 687   */
 688  function createMediaFromFile(file, additionalData) {
 689    // Create upload payload.
 690    const data = new window.FormData();
 691    data.append('file', file, file.name || file.type.replace('/', '.'));
 692    if (additionalData) {
 693      Object.entries(additionalData).forEach(([key, value]) => data.append(key, value));
 694    }
 695    return external_wp_apiFetch_default()({
 696      path: '/wp/v2/media',
 697      body: data,
 698      method: 'POST'
 699    });
 700  }
 701  
 702  ;// CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/utils/index.js
 703  
 704  
 705  ;// CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/index.js
 706  
 707  
 708  
 709  (window.wp = window.wp || {}).mediaUtils = __webpack_exports__;
 710  /******/ })()
 711  ;


Generated : Fri Apr 26 08:20:02 2024 Cross-referenced by PHPXref