mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-02 16:59:35 +01:00
6e4458c935
Props peterwilsoncc, desrosj. Fixes #53192. Built from https://develop.svn.wordpress.org/trunk@50940 git-svn-id: http://core.svn.wordpress.org/trunk@50549 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2 lines
8.1 KiB
JavaScript
2 lines
8.1 KiB
JavaScript
/*! This file is auto-generated */
|
|
this.wp=this.wp||{},this.wp.mediaUtils=function(e){var t={};function i(o){if(t[o])return t[o].exports;var s=t[o]={i:o,l:!1,exports:{}};return e[o].call(s.exports,s,s.exports,i),s.l=!0,s.exports}return i.m=e,i.c=t,i.d=function(e,t,o){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(i.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)i.d(o,s,function(t){return e[t]}.bind(null,s));return o},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s="./node_modules/@wordpress/media-utils/build-module/index.js")}({"./node_modules/@wordpress/media-utils/build-module/index.js":function(e,t,i){"use strict";i.r(t),i.d(t,"MediaUpload",(function(){return u})),i.d(t,"uploadMedia",(function(){return b}));var o=i("lodash"),s=i("@wordpress/element"),r=i("@wordpress/i18n");const{wp:l}=window,a=[],n=()=>l.media.view.MediaFrame.Select.extend({featuredImageToolbar(e){this.createSelectToolbar(e,{text:l.media.view.l10n.setFeaturedImage,state:this.options.state})},editState(){const e=this.state("featured-image").get("selection"),t=new l.media.view.EditImage({model:e.single(),controller:this}).render();this.content.set(t),t.loadEditor()},createStates:function(){this.on("toolbar:create:featured-image",this.featuredImageToolbar,this),this.on("content:render:edit-image",this.editState,this),this.states.add([new l.media.controller.FeaturedImage,new l.media.controller.EditImage({model:this.options.editImage})])}}),d=()=>l.media.view.MediaFrame.Post.extend({galleryToolbar(){const e=this.state().get("editing");this.toolbar.set(new l.media.view.Toolbar({controller:this,items:{insert:{style:"primary",text:e?l.media.view.l10n.updateGallery:l.media.view.l10n.insertGallery,priority:80,requires:{library:!0},click(){const e=this.controller,t=e.state();e.close(),t.trigger("update",t.get("library")),e.setState(e.options.state),e.reset()}}}}))},editState(){const e=this.state("gallery").get("selection"),t=new l.media.view.EditImage({model:e.single(),controller:this}).render();this.content.set(t),t.loadEditor()},createStates:function(){this.on("toolbar:create:main-gallery",this.galleryToolbar,this),this.on("content:render:edit-image",this.editState,this),this.states.add([new l.media.controller.Library({id:"gallery",title:l.media.view.l10n.createGalleryTitle,priority:40,toolbar:"main-gallery",filterable:"uploaded",multiple:"add",editable:!1,library:l.media.query(Object(o.defaults)({type:"image"},this.options.library))}),new l.media.controller.EditImage({model:this.options.editImage}),new l.media.controller.GalleryEdit({library:this.options.selection,editing:this.options.editing,menu:"gallery",displaySettings:!1,multiple:!0}),new l.media.controller.GalleryAdd])}}),p=e=>Object(o.pick)(e,["sizes","mime","type","subtype","id","url","alt","link","caption"]),c=e=>l.media.query({order:"ASC",orderby:"post__in",post__in:e,posts_per_page:-1,query:!0,type:"image"});class m extends s.Component{constructor({allowedTypes:e,gallery:t=!1,unstableFeaturedImageFlow:i=!1,modalClass:o,multiple:s=!1,title:a=Object(r.__)("Select or Upload Media")}){if(super(...arguments),this.openModal=this.openModal.bind(this),this.onOpen=this.onOpen.bind(this),this.onSelect=this.onSelect.bind(this),this.onUpdate=this.onUpdate.bind(this),this.onClose=this.onClose.bind(this),t)this.buildAndSetGalleryFrame();else{const t={title:a,multiple:s};e&&(t.library={type:e}),this.frame=l.media(t)}o&&this.frame.$el.addClass(o),i&&this.buildAndSetFeatureImageFrame(),this.initializeListeners()}initializeListeners(){this.frame.on("select",this.onSelect),this.frame.on("update",this.onUpdate),this.frame.on("open",this.onOpen),this.frame.on("close",this.onClose)}buildAndSetGalleryFrame(){const{addToGallery:e=!1,allowedTypes:t,multiple:i=!1,value:o=a}=this.props;if(o===this.lastGalleryValue)return;let s;this.lastGalleryValue=o,this.frame&&this.frame.remove(),s=e?"gallery-library":o&&o.length?"gallery-edit":"gallery",this.GalleryDetailsMediaFrame||(this.GalleryDetailsMediaFrame=d());const r=c(o),n=new l.media.model.Selection(r.models,{props:r.props.toJSON(),multiple:i});this.frame=new this.GalleryDetailsMediaFrame({mimeType:t,state:s,multiple:i,selection:n,editing:!(!o||!o.length)}),l.media.frame=this.frame,this.initializeListeners()}buildAndSetFeatureImageFrame(){const e=n(),t=c(this.props.value),i=new l.media.model.Selection(t.models,{props:t.props.toJSON()});this.frame=new e({mimeType:this.props.allowedTypes,state:"featured-image",multiple:this.props.multiple,selection:i,editing:!!this.props.value}),l.media.frame=this.frame}componentWillUnmount(){this.frame.remove()}onUpdate(e){const{onSelect:t,multiple:i=!1}=this.props,o=this.frame.state(),s=e||o.get("selection");s&&s.models.length&&t(i?s.models.map(e=>p(e.toJSON())):p(s.models[0].toJSON()))}onSelect(){const{onSelect:e,multiple:t=!1}=this.props,i=this.frame.state().get("selection").toJSON();e(t?i:i[0])}onOpen(){var e;this.updateCollection();if(Array.isArray(this.props.value)?!(null===(e=this.props.value)||void 0===e||!e.length):!!this.props.value){if(!this.props.gallery){const e=this.frame.state().get("selection");Object(o.castArray)(this.props.value).forEach(t=>{e.add(l.media.attachment(t))})}c(Object(o.castArray)(this.props.value)).more()}}onClose(){const{onClose:e}=this.props;e&&e()}updateCollection(){const e=this.frame.content.get();if(e&&e.collection){const t=e.collection;t.toArray().forEach(e=>e.trigger("destroy",e)),t.mirroring._hasMore=!0,t.more()}}openModal(){this.props.gallery&&this.buildAndSetGalleryFrame(),this.frame.open()}render(){return this.props.render({open:this.openModal})}}var u=m,h=i("@wordpress/api-fetch"),f=i.n(h),y=i("@wordpress/blob");async function b({allowedTypes:e,additionalData:t={},filesList:i,maxUploadFileSize:l,onError:a=o.noop,onFileChange:n,wpAllowedMimeTypes:d=null}){const p=[...i],c=[],m=(e,t)=>{Object(y.revokeBlobURL)(Object(o.get)(c,[e,"url"])),c[e]=t,n(Object(o.compact)(c))},u=t=>!e||Object(o.some)(e,e=>Object(o.includes)(e,"/")?e===t:Object(o.startsWith)(t,e+"/")),h=(f=d)?Object(o.flatMap)(f,(e,t)=>{const[i]=e.split("/"),s=t.split("|");return[e,...Object(o.map)(s,e=>`${i}/${e}`)]}):f;var f;const b=e=>{e.message=[Object(s.createElement)("strong",{key:"filename"},e.file.name),": ",e.message],a(e)},w=[];for(const e of p)h&&e.type&&(O=e.type,!Object(o.includes)(h,O))?b({code:"MIME_TYPE_NOT_ALLOWED_FOR_USER",message:Object(r.__)("Sorry, this file type is not permitted for security reasons."),file:e}):!e.type||u(e.type)?l&&e.size>l?b({code:"SIZE_ABOVE_LIMIT",message:Object(r.__)("This file exceeds the maximum upload size for this site."),file:e}):e.size<=0?b({code:"EMPTY_FILE",message:Object(r.__)("This file is empty."),file:e}):(w.push(e),c.push({url:Object(y.createBlobURL)(e)}),n(c)):b({code:"MIME_TYPE_NOT_SUPPORTED",message:Object(r.__)("Sorry, this file type is not supported here."),file:e});var O;for(let e=0;e<w.length;++e){const i=w[e];try{const s=await g(i,t);m(e,{...Object(o.omit)(s,["alt_text","source_url"]),alt:s.alt_text,caption:Object(o.get)(s,["caption","raw"],""),title:s.title.raw,url:s.source_url})}catch(t){let s;m(e,null),s=Object(o.has)(t,["message"])?Object(o.get)(t,["message"]):Object(r.sprintf)(Object(r.__)("Error while uploading file %s to the media library."),i.name),a({code:"GENERAL",message:s,file:i})}}}function g(e,t){const i=new window.FormData;return i.append("file",e,e.name||e.type.replace("/",".")),Object(o.forEach)(t,(e,t)=>i.append(t,e)),f()({path:"/wp/v2/media",body:i,method:"POST"})}},"@wordpress/api-fetch":function(e,t){e.exports=window.wp.apiFetch},"@wordpress/blob":function(e,t){e.exports=window.wp.blob},"@wordpress/element":function(e,t){e.exports=window.wp.element},"@wordpress/i18n":function(e,t){e.exports=window.wp.i18n},lodash:function(e,t){e.exports=window.lodash}}); |