WordPress/wp-includes/js/dist/media-utils.min.js
gziolo b8871304cf Editor: Update WordPress packages from Gutenberg 10.5
Applies changes between the Gutenberg plugin v10.4 and v10.5. It contains the latest version of WordPress packages and PHP changes applied to non-experimental features.

Props youknowriad.
See #52991.


Built from https://develop.svn.wordpress.org/trunk@50824


git-svn-id: http://core.svn.wordpress.org/trunk@50433 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-05-07 11:48:27 +00:00

2 lines
16 KiB
JavaScript

/*! This file is auto-generated */
this.wp=this.wp||{},this.wp.mediaUtils=function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=476)}({0:function(e,t){e.exports=window.wp.element},1:function(e,t){e.exports=window.wp.i18n},12:function(e,t,r){"use strict";r.d(t,"a",(function(){return a}));var n=r(38);var o=r(28),i=r(39);function a(e,t){return Object(n.a)(e)||function(e,t){var r=e&&("undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"]);if(null!=r){var n,o,i=[],a=!0,l=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){l=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(l)throw o}}return i}}(e,t)||Object(o.a)(e,t)||Object(i.a)()}},15:function(e,t,r){"use strict";r.d(t,"a",(function(){return a}));var n=r(24);var o=r(42),i=r(28);function a(e){return function(e){if(Array.isArray(e))return Object(n.a)(e)}(e)||Object(o.a)(e)||Object(i.a)(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}},16:function(e,t){e.exports=window.regeneratorRuntime},18:function(e,t,r){"use strict";function n(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}r.d(t,"a",(function(){return n}))},2:function(e,t){e.exports=window.lodash},22:function(e,t,r){"use strict";function n(e){return(n=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}r.d(t,"a",(function(){return n}))},24:function(e,t,r){"use strict";function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}r.d(t,"a",(function(){return n}))},25:function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}r.d(t,"a",(function(){return n}))},26:function(e,t,r){"use strict";function n(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function o(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e}r.d(t,"a",(function(){return o}))},28:function(e,t,r){"use strict";r.d(t,"a",(function(){return o}));var n=r(24);function o(e,t){if(e){if("string"==typeof e)return Object(n.a)(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?Object(n.a)(e,t):void 0}}},33:function(e,t,r){"use strict";r.d(t,"a",(function(){return o}));var n=r(55);function o(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&Object(n.a)(e,t)}},34:function(e,t,r){"use strict";r.d(t,"a",(function(){return a}));var n=r(59),o=r.n(n),i=r(18);function a(e,t){return!t||"object"!==o()(t)&&"function"!=typeof t?Object(i.a)(e):t}},38:function(e,t,r){"use strict";function n(e){if(Array.isArray(e))return e}r.d(t,"a",(function(){return n}))},39:function(e,t,r){"use strict";function n(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}r.d(t,"a",(function(){return n}))},42:function(e,t,r){"use strict";function n(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}r.d(t,"a",(function(){return n}))},43:function(e,t){e.exports=window.wp.blob},476:function(e,t,r){"use strict";r.r(t),r.d(t,"MediaUpload",(function(){return h})),r.d(t,"uploadMedia",(function(){return I}));var n=r(25),o=r(26),i=r(18),a=r(33),l=r(34),u=r(22),c=r(2),s=r(0),f=r(1);function p(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=Object(u.a)(e);if(t){var o=Object(u.a)(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return Object(l.a)(this,r)}}var d=window.wp,m=[],y=function(e){return Object(c.pick)(e,["sizes","mime","type","subtype","id","url","alt","link","caption"])},b=function(e){return d.media.query({order:"ASC",orderby:"post__in",post__in:e,posts_per_page:-1,query:!0,type:"image"})},h=function(e){Object(a.a)(r,e);var t=p(r);function r(e){var o,a=e.allowedTypes,l=e.gallery,u=void 0!==l&&l,c=e.unstableFeaturedImageFlow,s=void 0!==c&&c,p=e.modalClass,m=e.multiple,y=void 0!==m&&m,b=e.title,h=void 0===b?Object(f.__)("Select or Upload Media"):b;if(Object(n.a)(this,r),(o=t.apply(this,arguments)).openModal=o.openModal.bind(Object(i.a)(o)),o.onOpen=o.onOpen.bind(Object(i.a)(o)),o.onSelect=o.onSelect.bind(Object(i.a)(o)),o.onUpdate=o.onUpdate.bind(Object(i.a)(o)),o.onClose=o.onClose.bind(Object(i.a)(o)),u)o.buildAndSetGalleryFrame();else{var v={title:h,multiple:y};a&&(v.library={type:a}),o.frame=d.media(v)}return p&&o.frame.$el.addClass(p),s&&o.buildAndSetFeatureImageFrame(),o.initializeListeners(),o}return Object(o.a)(r,[{key:"initializeListeners",value:function(){this.frame.on("select",this.onSelect),this.frame.on("update",this.onUpdate),this.frame.on("open",this.onOpen),this.frame.on("close",this.onClose)}},{key:"buildAndSetGalleryFrame",value:function(){var e=this.props,t=e.addToGallery,r=void 0!==t&&t,n=e.allowedTypes,o=e.multiple,i=void 0!==o&&o,a=e.value,l=void 0===a?m:a;if(l!==this.lastGalleryValue){var u;this.lastGalleryValue=l,this.frame&&this.frame.remove(),u=r?"gallery-library":l&&l.length?"gallery-edit":"gallery",this.GalleryDetailsMediaFrame||(this.GalleryDetailsMediaFrame=d.media.view.MediaFrame.Post.extend({galleryToolbar:function(){var e=this.state().get("editing");this.toolbar.set(new d.media.view.Toolbar({controller:this,items:{insert:{style:"primary",text:e?d.media.view.l10n.updateGallery:d.media.view.l10n.insertGallery,priority:80,requires:{library:!0},click:function(){var e=this.controller,t=e.state();e.close(),t.trigger("update",t.get("library")),e.setState(e.options.state),e.reset()}}}}))},editState:function(){var e=this.state("gallery").get("selection"),t=new d.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 d.media.controller.Library({id:"gallery",title:d.media.view.l10n.createGalleryTitle,priority:40,toolbar:"main-gallery",filterable:"uploaded",multiple:"add",editable:!1,library:d.media.query(Object(c.defaults)({type:"image"},this.options.library))}),new d.media.controller.EditImage({model:this.options.editImage}),new d.media.controller.GalleryEdit({library:this.options.selection,editing:this.options.editing,menu:"gallery",displaySettings:!1,multiple:!0}),new d.media.controller.GalleryAdd])}}));var s=b(l),f=new d.media.model.Selection(s.models,{props:s.props.toJSON(),multiple:i});this.frame=new this.GalleryDetailsMediaFrame({mimeType:n,state:u,multiple:i,selection:f,editing:!(!l||!l.length)}),d.media.frame=this.frame,this.initializeListeners()}}},{key:"buildAndSetFeatureImageFrame",value:function(){var e=d.media.view.MediaFrame.Select.extend({featuredImageToolbar:function(e){this.createSelectToolbar(e,{text:d.media.view.l10n.setFeaturedImage,state:this.options.state})},editState:function(){var e=this.state("featured-image").get("selection"),t=new d.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 d.media.controller.FeaturedImage,new d.media.controller.EditImage({model:this.options.editImage})])}}),t=b(this.props.value),r=new d.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:r,editing:!!this.props.value}),d.media.frame=this.frame}},{key:"componentWillUnmount",value:function(){this.frame.remove()}},{key:"onUpdate",value:function(e){var t=this.props,r=t.onSelect,n=t.multiple,o=void 0!==n&&n,i=this.frame.state(),a=e||i.get("selection");a&&a.models.length&&r(o?a.models.map((function(e){return y(e.toJSON())})):y(a.models[0].toJSON()))}},{key:"onSelect",value:function(){var e=this.props,t=e.onSelect,r=e.multiple,n=void 0!==r&&r,o=this.frame.state().get("selection").toJSON();t(n?o:o[0])}},{key:"onOpen",value:function(){var e;if(this.updateCollection(),Array.isArray(this.props.value)?!(null===(e=this.props.value)||void 0===e||!e.length):!!this.props.value){if(!this.props.gallery){var t=this.frame.state().get("selection");Object(c.castArray)(this.props.value).forEach((function(e){t.add(d.media.attachment(e))}))}b(Object(c.castArray)(this.props.value)).more()}}},{key:"onClose",value:function(){var e=this.props.onClose;e&&e()}},{key:"updateCollection",value:function(){var e=this.frame.content.get();if(e&&e.collection){var t=e.collection;t.toArray().forEach((function(e){return e.trigger("destroy",e)})),t.mirroring._hasMore=!0,t.more()}}},{key:"openModal",value:function(){this.props.gallery&&this.buildAndSetGalleryFrame(),this.frame.open()}},{key:"render",value:function(){return this.props.render({open:this.openModal})}}]),r}(s.Component),v=r(5),O=r(48),g=r(15),w=r(12),j=r(16),S=r.n(j),_=r(50),x=r.n(_),E=r(43);function T(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function A(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?T(Object(r),!0).forEach((function(t){Object(v.a)(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):T(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function M(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(!e)return;if("string"==typeof e)return k(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return k(e,t)}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,l=!1;return{s:function(){r=e[Symbol.iterator]()},n:function(){var e=r.next();return a=e.done,e},e:function(e){l=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(l)throw i}}}}function k(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function P(e){return e?Object(c.flatMap)(e,(function(e,t){var r=e.split("/"),n=Object(w.a)(r,1)[0],o=t.split("|");return[e].concat(Object(g.a)(Object(c.map)(o,(function(e){return"".concat(n,"/").concat(e)}))))})):e}function I(e){return F.apply(this,arguments)}function F(){return(F=Object(O.a)(S.a.mark((function e(t){var r,n,o,i,a,l,u,p,d,m,y,b,h,v,O,w,j,_,x,T,k,I,F,G,U,R;return S.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r=t.allowedTypes,n=t.additionalData,o=void 0===n?{}:n,i=t.filesList,a=t.maxUploadFileSize,l=t.onError,u=void 0===l?c.noop:l,p=t.onFileChange,d=t.wpAllowedMimeTypes,m=void 0===d?null:d,y=Object(g.a)(i),b=[],h=function(e,t){Object(E.revokeBlobURL)(Object(c.get)(b,[e,"url"])),b[e]=t,p(Object(c.compact)(b))},v=function(e){return!r||Object(c.some)(r,(function(t){return Object(c.includes)(t,"/")?t===e:Object(c.startsWith)(e,"".concat(t,"/"))}))},O=P(m),w=function(e){return Object(c.includes)(O,e)},j=function(e){e.message=[Object(s.createElement)("strong",{key:"filename"},e.file.name),": ",e.message],u(e)},_=[],x=M(y),e.prev=10,x.s();case 12:if((T=x.n()).done){e.next=31;break}if(k=T.value,!O||!k.type||w(k.type)){e.next=17;break}return j({code:"MIME_TYPE_NOT_ALLOWED_FOR_USER",message:Object(f.__)("Sorry, this file type is not permitted for security reasons."),file:k}),e.abrupt("continue",29);case 17:if(!k.type||v(k.type)){e.next=20;break}return j({code:"MIME_TYPE_NOT_SUPPORTED",message:Object(f.__)("Sorry, this file type is not supported here."),file:k}),e.abrupt("continue",29);case 20:if(!(a&&k.size>a)){e.next=23;break}return j({code:"SIZE_ABOVE_LIMIT",message:Object(f.__)("This file exceeds the maximum upload size for this site."),file:k}),e.abrupt("continue",29);case 23:if(!(k.size<=0)){e.next=26;break}return j({code:"EMPTY_FILE",message:Object(f.__)("This file is empty."),file:k}),e.abrupt("continue",29);case 26:_.push(k),b.push({url:Object(E.createBlobURL)(k)}),p(b);case 29:e.next=12;break;case 31:e.next=36;break;case 33:e.prev=33,e.t0=e.catch(10),x.e(e.t0);case 36:return e.prev=36,x.f(),e.finish(36);case 39:I=0;case 40:if(!(I<_.length)){e.next=59;break}return F=_[I],e.prev=42,e.next=45,C(F,o);case 45:G=e.sent,U=A(A({},Object(c.omit)(G,["alt_text","source_url"])),{},{alt:G.alt_text,caption:Object(c.get)(G,["caption","raw"],""),title:G.title.raw,url:G.source_url}),h(I,U),e.next=56;break;case 50:e.prev=50,e.t1=e.catch(42),h(I,null),R=void 0,R=Object(c.has)(e.t1,["message"])?Object(c.get)(e.t1,["message"]):Object(f.sprintf)(Object(f.__)("Error while uploading file %s to the media library."),F.name),u({code:"GENERAL",message:R,file:F});case 56:++I,e.next=40;break;case 59:case"end":return e.stop()}}),e,null,[[10,33,36,39],[42,50]])})))).apply(this,arguments)}function C(e,t){var r=new window.FormData;return r.append("file",e,e.name||e.type.replace("/",".")),Object(c.forEach)(t,(function(e,t){return r.append(t,e)})),x()({path:"/wp/v2/media",body:r,method:"POST"})}},48:function(e,t,r){"use strict";function n(e,t,r,n,o,i,a){try{var l=e[i](a),u=l.value}catch(e){return void r(e)}l.done?t(u):Promise.resolve(u).then(n,o)}function o(e){return function(){var t=this,r=arguments;return new Promise((function(o,i){var a=e.apply(t,r);function l(e){n(a,o,i,l,u,"next",e)}function u(e){n(a,o,i,l,u,"throw",e)}l(void 0)}))}}r.d(t,"a",(function(){return o}))},5:function(e,t,r){"use strict";function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}r.d(t,"a",(function(){return n}))},50:function(e,t){e.exports=window.wp.apiFetch},55:function(e,t,r){"use strict";function n(e,t){return(n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}r.d(t,"a",(function(){return n}))},59:function(e,t){function r(t){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?(e.exports=r=function(e){return typeof e},e.exports.default=e.exports,e.exports.__esModule=!0):(e.exports=r=function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e.exports.default=e.exports,e.exports.__esModule=!0),r(t)}e.exports=r,e.exports.default=e.exports,e.exports.__esModule=!0}});