wp/wp-includes/js/media-models.js
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
     1 /******/ (() => { // webpackBootstrap
     1 /******/ (() => { // webpackBootstrap
     2 /******/ 	var __webpack_modules__ = ({
     2 /******/ 	var __webpack_modules__ = ({
       
     3 
       
     4 /***/ 1288:
       
     5 /***/ ((module) => {
       
     6 
       
     7 var Attachments = wp.media.model.Attachments,
       
     8 	Query;
       
     9 
       
    10 /**
       
    11  * wp.media.model.Query
       
    12  *
       
    13  * A collection of attachments that match the supplied query arguments.
       
    14  *
       
    15  * Note: Do NOT change this.args after the query has been initialized.
       
    16  *       Things will break.
       
    17  *
       
    18  * @memberOf wp.media.model
       
    19  *
       
    20  * @class
       
    21  * @augments wp.media.model.Attachments
       
    22  * @augments Backbone.Collection
       
    23  *
       
    24  * @param {array}  [models]                      Models to initialize with the collection.
       
    25  * @param {object} [options]                     Options hash.
       
    26  * @param {object} [options.args]                Attachments query arguments.
       
    27  * @param {object} [options.args.posts_per_page]
       
    28  */
       
    29 Query = Attachments.extend(/** @lends wp.media.model.Query.prototype */{
       
    30 	/**
       
    31 	 * @param {Array}  [models=[]]  Array of initial models to populate the collection.
       
    32 	 * @param {Object} [options={}]
       
    33 	 */
       
    34 	initialize: function( models, options ) {
       
    35 		var allowed;
       
    36 
       
    37 		options = options || {};
       
    38 		Attachments.prototype.initialize.apply( this, arguments );
       
    39 
       
    40 		this.args     = options.args;
       
    41 		this._hasMore = true;
       
    42 		this.created  = new Date();
       
    43 
       
    44 		this.filters.order = function( attachment ) {
       
    45 			var orderby = this.props.get('orderby'),
       
    46 				order = this.props.get('order');
       
    47 
       
    48 			if ( ! this.comparator ) {
       
    49 				return true;
       
    50 			}
       
    51 
       
    52 			/*
       
    53 			 * We want any items that can be placed before the last
       
    54 			 * item in the set. If we add any items after the last
       
    55 			 * item, then we can't guarantee the set is complete.
       
    56 			 */
       
    57 			if ( this.length ) {
       
    58 				return 1 !== this.comparator( attachment, this.last(), { ties: true });
       
    59 
       
    60 			/*
       
    61 			 * Handle the case where there are no items yet and
       
    62 			 * we're sorting for recent items. In that case, we want
       
    63 			 * changes that occurred after we created the query.
       
    64 			 */
       
    65 			} else if ( 'DESC' === order && ( 'date' === orderby || 'modified' === orderby ) ) {
       
    66 				return attachment.get( orderby ) >= this.created;
       
    67 
       
    68 			// If we're sorting by menu order and we have no items,
       
    69 			// accept any items that have the default menu order (0).
       
    70 			} else if ( 'ASC' === order && 'menuOrder' === orderby ) {
       
    71 				return attachment.get( orderby ) === 0;
       
    72 			}
       
    73 
       
    74 			// Otherwise, we don't want any items yet.
       
    75 			return false;
       
    76 		};
       
    77 
       
    78 		/*
       
    79 		 * Observe the central `wp.Uploader.queue` collection to watch for
       
    80 		 * new matches for the query.
       
    81 		 *
       
    82 		 * Only observe when a limited number of query args are set. There
       
    83 		 * are no filters for other properties, so observing will result in
       
    84 		 * false positives in those queries.
       
    85 		 */
       
    86 		allowed = [ 's', 'order', 'orderby', 'posts_per_page', 'post_mime_type', 'post_parent', 'author' ];
       
    87 		if ( wp.Uploader && _( this.args ).chain().keys().difference( allowed ).isEmpty().value() ) {
       
    88 			this.observe( wp.Uploader.queue );
       
    89 		}
       
    90 	},
       
    91 	/**
       
    92 	 * Whether there are more attachments that haven't been sync'd from the server
       
    93 	 * that match the collection's query.
       
    94 	 *
       
    95 	 * @return {boolean}
       
    96 	 */
       
    97 	hasMore: function() {
       
    98 		return this._hasMore;
       
    99 	},
       
   100 	/**
       
   101 	 * Fetch more attachments from the server for the collection.
       
   102 	 *
       
   103 	 * @param {Object} [options={}]
       
   104 	 * @return {Promise}
       
   105 	 */
       
   106 	more: function( options ) {
       
   107 		var query = this;
       
   108 
       
   109 		// If there is already a request pending, return early with the Deferred object.
       
   110 		if ( this._more && 'pending' === this._more.state() ) {
       
   111 			return this._more;
       
   112 		}
       
   113 
       
   114 		if ( ! this.hasMore() ) {
       
   115 			return jQuery.Deferred().resolveWith( this ).promise();
       
   116 		}
       
   117 
       
   118 		options = options || {};
       
   119 		options.remove = false;
       
   120 
       
   121 		return this._more = this.fetch( options ).done( function( response ) {
       
   122 			if ( _.isEmpty( response ) || -1 === query.args.posts_per_page || response.length < query.args.posts_per_page ) {
       
   123 				query._hasMore = false;
       
   124 			}
       
   125 		});
       
   126 	},
       
   127 	/**
       
   128 	 * Overrides Backbone.Collection.sync
       
   129 	 * Overrides wp.media.model.Attachments.sync
       
   130 	 *
       
   131 	 * @param {string} method
       
   132 	 * @param {Backbone.Model} model
       
   133 	 * @param {Object} [options={}]
       
   134 	 * @return {Promise}
       
   135 	 */
       
   136 	sync: function( method, model, options ) {
       
   137 		var args, fallback;
       
   138 
       
   139 		// Overload the read method so Attachment.fetch() functions correctly.
       
   140 		if ( 'read' === method ) {
       
   141 			options = options || {};
       
   142 			options.context = this;
       
   143 			options.data = _.extend( options.data || {}, {
       
   144 				action:  'query-attachments',
       
   145 				post_id: wp.media.model.settings.post.id
       
   146 			});
       
   147 
       
   148 			// Clone the args so manipulation is non-destructive.
       
   149 			args = _.clone( this.args );
       
   150 
       
   151 			// Determine which page to query.
       
   152 			if ( -1 !== args.posts_per_page ) {
       
   153 				args.paged = Math.round( this.length / args.posts_per_page ) + 1;
       
   154 			}
       
   155 
       
   156 			options.data.query = args;
       
   157 			return wp.media.ajax( options );
       
   158 
       
   159 		// Otherwise, fall back to `Backbone.sync()`.
       
   160 		} else {
       
   161 			/**
       
   162 			 * Call wp.media.model.Attachments.sync or Backbone.sync
       
   163 			 */
       
   164 			fallback = Attachments.prototype.sync ? Attachments.prototype : Backbone;
       
   165 			return fallback.sync.apply( this, arguments );
       
   166 		}
       
   167 	}
       
   168 }, /** @lends wp.media.model.Query */{
       
   169 	/**
       
   170 	 * @readonly
       
   171 	 */
       
   172 	defaultProps: {
       
   173 		orderby: 'date',
       
   174 		order:   'DESC'
       
   175 	},
       
   176 	/**
       
   177 	 * @readonly
       
   178 	 */
       
   179 	defaultArgs: {
       
   180 		posts_per_page: 80
       
   181 	},
       
   182 	/**
       
   183 	 * @readonly
       
   184 	 */
       
   185 	orderby: {
       
   186 		allowed:  [ 'name', 'author', 'date', 'title', 'modified', 'uploadedTo', 'id', 'post__in', 'menuOrder' ],
       
   187 		/**
       
   188 		 * A map of JavaScript orderby values to their WP_Query equivalents.
       
   189 		 * @type {Object}
       
   190 		 */
       
   191 		valuemap: {
       
   192 			'id':         'ID',
       
   193 			'uploadedTo': 'parent',
       
   194 			'menuOrder':  'menu_order ID'
       
   195 		}
       
   196 	},
       
   197 	/**
       
   198 	 * A map of JavaScript query properties to their WP_Query equivalents.
       
   199 	 *
       
   200 	 * @readonly
       
   201 	 */
       
   202 	propmap: {
       
   203 		'search':		's',
       
   204 		'type':			'post_mime_type',
       
   205 		'perPage':		'posts_per_page',
       
   206 		'menuOrder':	'menu_order',
       
   207 		'uploadedTo':	'post_parent',
       
   208 		'status':		'post_status',
       
   209 		'include':		'post__in',
       
   210 		'exclude':		'post__not_in',
       
   211 		'author':		'author'
       
   212 	},
       
   213 	/**
       
   214 	 * Creates and returns an Attachments Query collection given the properties.
       
   215 	 *
       
   216 	 * Caches query objects and reuses where possible.
       
   217 	 *
       
   218 	 * @static
       
   219 	 * @method
       
   220 	 *
       
   221 	 * @param {object} [props]
       
   222 	 * @param {Object} [props.order]
       
   223 	 * @param {Object} [props.orderby]
       
   224 	 * @param {Object} [props.include]
       
   225 	 * @param {Object} [props.exclude]
       
   226 	 * @param {Object} [props.s]
       
   227 	 * @param {Object} [props.post_mime_type]
       
   228 	 * @param {Object} [props.posts_per_page]
       
   229 	 * @param {Object} [props.menu_order]
       
   230 	 * @param {Object} [props.post_parent]
       
   231 	 * @param {Object} [props.post_status]
       
   232 	 * @param {Object} [props.author]
       
   233 	 * @param {Object} [options]
       
   234 	 *
       
   235 	 * @return {wp.media.model.Query} A new Attachments Query collection.
       
   236 	 */
       
   237 	get: (function(){
       
   238 		/**
       
   239 		 * @static
       
   240 		 * @type Array
       
   241 		 */
       
   242 		var queries = [];
       
   243 
       
   244 		/**
       
   245 		 * @return {Query}
       
   246 		 */
       
   247 		return function( props, options ) {
       
   248 			var args     = {},
       
   249 				orderby  = Query.orderby,
       
   250 				defaults = Query.defaultProps,
       
   251 				query;
       
   252 
       
   253 			// Remove the `query` property. This isn't linked to a query,
       
   254 			// this *is* the query.
       
   255 			delete props.query;
       
   256 
       
   257 			// Fill default args.
       
   258 			_.defaults( props, defaults );
       
   259 
       
   260 			// Normalize the order.
       
   261 			props.order = props.order.toUpperCase();
       
   262 			if ( 'DESC' !== props.order && 'ASC' !== props.order ) {
       
   263 				props.order = defaults.order.toUpperCase();
       
   264 			}
       
   265 
       
   266 			// Ensure we have a valid orderby value.
       
   267 			if ( ! _.contains( orderby.allowed, props.orderby ) ) {
       
   268 				props.orderby = defaults.orderby;
       
   269 			}
       
   270 
       
   271 			_.each( [ 'include', 'exclude' ], function( prop ) {
       
   272 				if ( props[ prop ] && ! _.isArray( props[ prop ] ) ) {
       
   273 					props[ prop ] = [ props[ prop ] ];
       
   274 				}
       
   275 			} );
       
   276 
       
   277 			// Generate the query `args` object.
       
   278 			// Correct any differing property names.
       
   279 			_.each( props, function( value, prop ) {
       
   280 				if ( _.isNull( value ) ) {
       
   281 					return;
       
   282 				}
       
   283 
       
   284 				args[ Query.propmap[ prop ] || prop ] = value;
       
   285 			});
       
   286 
       
   287 			// Fill any other default query args.
       
   288 			_.defaults( args, Query.defaultArgs );
       
   289 
       
   290 			// `props.orderby` does not always map directly to `args.orderby`.
       
   291 			// Substitute exceptions specified in orderby.keymap.
       
   292 			args.orderby = orderby.valuemap[ props.orderby ] || props.orderby;
       
   293 
       
   294 			queries = [];
       
   295 
       
   296 			// Otherwise, create a new query and add it to the cache.
       
   297 			if ( ! query ) {
       
   298 				query = new Query( [], _.extend( options || {}, {
       
   299 					props: props,
       
   300 					args:  args
       
   301 				} ) );
       
   302 				queries.push( query );
       
   303 			}
       
   304 
       
   305 			return query;
       
   306 		};
       
   307 	}())
       
   308 });
       
   309 
       
   310 module.exports = Query;
       
   311 
       
   312 
       
   313 /***/ }),
     3 
   314 
     4 /***/ 3343:
   315 /***/ 3343:
     5 /***/ ((module) => {
   316 /***/ ((module) => {
     6 
   317 
     7 var $ = Backbone.$,
   318 var $ = Backbone.$,
   171 		return Attachments.all.push( attachment || { id: id } );
   482 		return Attachments.all.push( attachment || { id: id } );
   172 	})
   483 	})
   173 });
   484 });
   174 
   485 
   175 module.exports = Attachment;
   486 module.exports = Attachment;
       
   487 
       
   488 
       
   489 /***/ }),
       
   490 
       
   491 /***/ 4134:
       
   492 /***/ ((module) => {
       
   493 
       
   494 var Attachments = wp.media.model.Attachments,
       
   495 	Selection;
       
   496 
       
   497 /**
       
   498  * wp.media.model.Selection
       
   499  *
       
   500  * A selection of attachments.
       
   501  *
       
   502  * @memberOf wp.media.model
       
   503  *
       
   504  * @class
       
   505  * @augments wp.media.model.Attachments
       
   506  * @augments Backbone.Collection
       
   507  */
       
   508 Selection = Attachments.extend(/** @lends wp.media.model.Selection.prototype */{
       
   509 	/**
       
   510 	 * Refresh the `single` model whenever the selection changes.
       
   511 	 * Binds `single` instead of using the context argument to ensure
       
   512 	 * it receives no parameters.
       
   513 	 *
       
   514 	 * @param {Array} [models=[]] Array of models used to populate the collection.
       
   515 	 * @param {Object} [options={}]
       
   516 	 */
       
   517 	initialize: function( models, options ) {
       
   518 		/**
       
   519 		 * call 'initialize' directly on the parent class
       
   520 		 */
       
   521 		Attachments.prototype.initialize.apply( this, arguments );
       
   522 		this.multiple = options && options.multiple;
       
   523 
       
   524 		this.on( 'add remove reset', _.bind( this.single, this, false ) );
       
   525 	},
       
   526 
       
   527 	/**
       
   528 	 * If the workflow does not support multi-select, clear out the selection
       
   529 	 * before adding a new attachment to it.
       
   530 	 *
       
   531 	 * @param {Array} models
       
   532 	 * @param {Object} options
       
   533 	 * @return {wp.media.model.Attachment[]}
       
   534 	 */
       
   535 	add: function( models, options ) {
       
   536 		if ( ! this.multiple ) {
       
   537 			this.remove( this.models );
       
   538 		}
       
   539 		/**
       
   540 		 * call 'add' directly on the parent class
       
   541 		 */
       
   542 		return Attachments.prototype.add.call( this, models, options );
       
   543 	},
       
   544 
       
   545 	/**
       
   546 	 * Fired when toggling (clicking on) an attachment in the modal.
       
   547 	 *
       
   548 	 * @param {undefined|boolean|wp.media.model.Attachment} model
       
   549 	 *
       
   550 	 * @fires wp.media.model.Selection#selection:single
       
   551 	 * @fires wp.media.model.Selection#selection:unsingle
       
   552 	 *
       
   553 	 * @return {Backbone.Model}
       
   554 	 */
       
   555 	single: function( model ) {
       
   556 		var previous = this._single;
       
   557 
       
   558 		// If a `model` is provided, use it as the single model.
       
   559 		if ( model ) {
       
   560 			this._single = model;
       
   561 		}
       
   562 		// If the single model isn't in the selection, remove it.
       
   563 		if ( this._single && ! this.get( this._single.cid ) ) {
       
   564 			delete this._single;
       
   565 		}
       
   566 
       
   567 		this._single = this._single || this.last();
       
   568 
       
   569 		// If single has changed, fire an event.
       
   570 		if ( this._single !== previous ) {
       
   571 			if ( previous ) {
       
   572 				previous.trigger( 'selection:unsingle', previous, this );
       
   573 
       
   574 				// If the model was already removed, trigger the collection
       
   575 				// event manually.
       
   576 				if ( ! this.get( previous.cid ) ) {
       
   577 					this.trigger( 'selection:unsingle', previous, this );
       
   578 				}
       
   579 			}
       
   580 			if ( this._single ) {
       
   581 				this._single.trigger( 'selection:single', this._single, this );
       
   582 			}
       
   583 		}
       
   584 
       
   585 		// Return the single model, or the last model as a fallback.
       
   586 		return this._single;
       
   587 	}
       
   588 });
       
   589 
       
   590 module.exports = Selection;
   176 
   591 
   177 
   592 
   178 /***/ }),
   593 /***/ }),
   179 
   594 
   180 /***/ 8266:
   595 /***/ 8266:
   940 		this.set( 'aspectRatio', this.get( 'customWidth' ) / this.get( 'customHeight' ) );
  1355 		this.set( 'aspectRatio', this.get( 'customWidth' ) / this.get( 'customHeight' ) );
   941 	}
  1356 	}
   942 });
  1357 });
   943 
  1358 
   944 module.exports = PostImage;
  1359 module.exports = PostImage;
   945 
       
   946 
       
   947 /***/ }),
       
   948 
       
   949 /***/ 1288:
       
   950 /***/ ((module) => {
       
   951 
       
   952 var Attachments = wp.media.model.Attachments,
       
   953 	Query;
       
   954 
       
   955 /**
       
   956  * wp.media.model.Query
       
   957  *
       
   958  * A collection of attachments that match the supplied query arguments.
       
   959  *
       
   960  * Note: Do NOT change this.args after the query has been initialized.
       
   961  *       Things will break.
       
   962  *
       
   963  * @memberOf wp.media.model
       
   964  *
       
   965  * @class
       
   966  * @augments wp.media.model.Attachments
       
   967  * @augments Backbone.Collection
       
   968  *
       
   969  * @param {array}  [models]                      Models to initialize with the collection.
       
   970  * @param {object} [options]                     Options hash.
       
   971  * @param {object} [options.args]                Attachments query arguments.
       
   972  * @param {object} [options.args.posts_per_page]
       
   973  */
       
   974 Query = Attachments.extend(/** @lends wp.media.model.Query.prototype */{
       
   975 	/**
       
   976 	 * @param {Array}  [models=[]]  Array of initial models to populate the collection.
       
   977 	 * @param {Object} [options={}]
       
   978 	 */
       
   979 	initialize: function( models, options ) {
       
   980 		var allowed;
       
   981 
       
   982 		options = options || {};
       
   983 		Attachments.prototype.initialize.apply( this, arguments );
       
   984 
       
   985 		this.args     = options.args;
       
   986 		this._hasMore = true;
       
   987 		this.created  = new Date();
       
   988 
       
   989 		this.filters.order = function( attachment ) {
       
   990 			var orderby = this.props.get('orderby'),
       
   991 				order = this.props.get('order');
       
   992 
       
   993 			if ( ! this.comparator ) {
       
   994 				return true;
       
   995 			}
       
   996 
       
   997 			/*
       
   998 			 * We want any items that can be placed before the last
       
   999 			 * item in the set. If we add any items after the last
       
  1000 			 * item, then we can't guarantee the set is complete.
       
  1001 			 */
       
  1002 			if ( this.length ) {
       
  1003 				return 1 !== this.comparator( attachment, this.last(), { ties: true });
       
  1004 
       
  1005 			/*
       
  1006 			 * Handle the case where there are no items yet and
       
  1007 			 * we're sorting for recent items. In that case, we want
       
  1008 			 * changes that occurred after we created the query.
       
  1009 			 */
       
  1010 			} else if ( 'DESC' === order && ( 'date' === orderby || 'modified' === orderby ) ) {
       
  1011 				return attachment.get( orderby ) >= this.created;
       
  1012 
       
  1013 			// If we're sorting by menu order and we have no items,
       
  1014 			// accept any items that have the default menu order (0).
       
  1015 			} else if ( 'ASC' === order && 'menuOrder' === orderby ) {
       
  1016 				return attachment.get( orderby ) === 0;
       
  1017 			}
       
  1018 
       
  1019 			// Otherwise, we don't want any items yet.
       
  1020 			return false;
       
  1021 		};
       
  1022 
       
  1023 		/*
       
  1024 		 * Observe the central `wp.Uploader.queue` collection to watch for
       
  1025 		 * new matches for the query.
       
  1026 		 *
       
  1027 		 * Only observe when a limited number of query args are set. There
       
  1028 		 * are no filters for other properties, so observing will result in
       
  1029 		 * false positives in those queries.
       
  1030 		 */
       
  1031 		allowed = [ 's', 'order', 'orderby', 'posts_per_page', 'post_mime_type', 'post_parent', 'author' ];
       
  1032 		if ( wp.Uploader && _( this.args ).chain().keys().difference( allowed ).isEmpty().value() ) {
       
  1033 			this.observe( wp.Uploader.queue );
       
  1034 		}
       
  1035 	},
       
  1036 	/**
       
  1037 	 * Whether there are more attachments that haven't been sync'd from the server
       
  1038 	 * that match the collection's query.
       
  1039 	 *
       
  1040 	 * @return {boolean}
       
  1041 	 */
       
  1042 	hasMore: function() {
       
  1043 		return this._hasMore;
       
  1044 	},
       
  1045 	/**
       
  1046 	 * Fetch more attachments from the server for the collection.
       
  1047 	 *
       
  1048 	 * @param {Object} [options={}]
       
  1049 	 * @return {Promise}
       
  1050 	 */
       
  1051 	more: function( options ) {
       
  1052 		var query = this;
       
  1053 
       
  1054 		// If there is already a request pending, return early with the Deferred object.
       
  1055 		if ( this._more && 'pending' === this._more.state() ) {
       
  1056 			return this._more;
       
  1057 		}
       
  1058 
       
  1059 		if ( ! this.hasMore() ) {
       
  1060 			return jQuery.Deferred().resolveWith( this ).promise();
       
  1061 		}
       
  1062 
       
  1063 		options = options || {};
       
  1064 		options.remove = false;
       
  1065 
       
  1066 		return this._more = this.fetch( options ).done( function( response ) {
       
  1067 			if ( _.isEmpty( response ) || -1 === query.args.posts_per_page || response.length < query.args.posts_per_page ) {
       
  1068 				query._hasMore = false;
       
  1069 			}
       
  1070 		});
       
  1071 	},
       
  1072 	/**
       
  1073 	 * Overrides Backbone.Collection.sync
       
  1074 	 * Overrides wp.media.model.Attachments.sync
       
  1075 	 *
       
  1076 	 * @param {string} method
       
  1077 	 * @param {Backbone.Model} model
       
  1078 	 * @param {Object} [options={}]
       
  1079 	 * @return {Promise}
       
  1080 	 */
       
  1081 	sync: function( method, model, options ) {
       
  1082 		var args, fallback;
       
  1083 
       
  1084 		// Overload the read method so Attachment.fetch() functions correctly.
       
  1085 		if ( 'read' === method ) {
       
  1086 			options = options || {};
       
  1087 			options.context = this;
       
  1088 			options.data = _.extend( options.data || {}, {
       
  1089 				action:  'query-attachments',
       
  1090 				post_id: wp.media.model.settings.post.id
       
  1091 			});
       
  1092 
       
  1093 			// Clone the args so manipulation is non-destructive.
       
  1094 			args = _.clone( this.args );
       
  1095 
       
  1096 			// Determine which page to query.
       
  1097 			if ( -1 !== args.posts_per_page ) {
       
  1098 				args.paged = Math.round( this.length / args.posts_per_page ) + 1;
       
  1099 			}
       
  1100 
       
  1101 			options.data.query = args;
       
  1102 			return wp.media.ajax( options );
       
  1103 
       
  1104 		// Otherwise, fall back to `Backbone.sync()`.
       
  1105 		} else {
       
  1106 			/**
       
  1107 			 * Call wp.media.model.Attachments.sync or Backbone.sync
       
  1108 			 */
       
  1109 			fallback = Attachments.prototype.sync ? Attachments.prototype : Backbone;
       
  1110 			return fallback.sync.apply( this, arguments );
       
  1111 		}
       
  1112 	}
       
  1113 }, /** @lends wp.media.model.Query */{
       
  1114 	/**
       
  1115 	 * @readonly
       
  1116 	 */
       
  1117 	defaultProps: {
       
  1118 		orderby: 'date',
       
  1119 		order:   'DESC'
       
  1120 	},
       
  1121 	/**
       
  1122 	 * @readonly
       
  1123 	 */
       
  1124 	defaultArgs: {
       
  1125 		posts_per_page: 80
       
  1126 	},
       
  1127 	/**
       
  1128 	 * @readonly
       
  1129 	 */
       
  1130 	orderby: {
       
  1131 		allowed:  [ 'name', 'author', 'date', 'title', 'modified', 'uploadedTo', 'id', 'post__in', 'menuOrder' ],
       
  1132 		/**
       
  1133 		 * A map of JavaScript orderby values to their WP_Query equivalents.
       
  1134 		 * @type {Object}
       
  1135 		 */
       
  1136 		valuemap: {
       
  1137 			'id':         'ID',
       
  1138 			'uploadedTo': 'parent',
       
  1139 			'menuOrder':  'menu_order ID'
       
  1140 		}
       
  1141 	},
       
  1142 	/**
       
  1143 	 * A map of JavaScript query properties to their WP_Query equivalents.
       
  1144 	 *
       
  1145 	 * @readonly
       
  1146 	 */
       
  1147 	propmap: {
       
  1148 		'search':		's',
       
  1149 		'type':			'post_mime_type',
       
  1150 		'perPage':		'posts_per_page',
       
  1151 		'menuOrder':	'menu_order',
       
  1152 		'uploadedTo':	'post_parent',
       
  1153 		'status':		'post_status',
       
  1154 		'include':		'post__in',
       
  1155 		'exclude':		'post__not_in',
       
  1156 		'author':		'author'
       
  1157 	},
       
  1158 	/**
       
  1159 	 * Creates and returns an Attachments Query collection given the properties.
       
  1160 	 *
       
  1161 	 * Caches query objects and reuses where possible.
       
  1162 	 *
       
  1163 	 * @static
       
  1164 	 * @method
       
  1165 	 *
       
  1166 	 * @param {object} [props]
       
  1167 	 * @param {Object} [props.order]
       
  1168 	 * @param {Object} [props.orderby]
       
  1169 	 * @param {Object} [props.include]
       
  1170 	 * @param {Object} [props.exclude]
       
  1171 	 * @param {Object} [props.s]
       
  1172 	 * @param {Object} [props.post_mime_type]
       
  1173 	 * @param {Object} [props.posts_per_page]
       
  1174 	 * @param {Object} [props.menu_order]
       
  1175 	 * @param {Object} [props.post_parent]
       
  1176 	 * @param {Object} [props.post_status]
       
  1177 	 * @param {Object} [props.author]
       
  1178 	 * @param {Object} [options]
       
  1179 	 *
       
  1180 	 * @return {wp.media.model.Query} A new Attachments Query collection.
       
  1181 	 */
       
  1182 	get: (function(){
       
  1183 		/**
       
  1184 		 * @static
       
  1185 		 * @type Array
       
  1186 		 */
       
  1187 		var queries = [];
       
  1188 
       
  1189 		/**
       
  1190 		 * @return {Query}
       
  1191 		 */
       
  1192 		return function( props, options ) {
       
  1193 			var args     = {},
       
  1194 				orderby  = Query.orderby,
       
  1195 				defaults = Query.defaultProps,
       
  1196 				query;
       
  1197 
       
  1198 			// Remove the `query` property. This isn't linked to a query,
       
  1199 			// this *is* the query.
       
  1200 			delete props.query;
       
  1201 
       
  1202 			// Fill default args.
       
  1203 			_.defaults( props, defaults );
       
  1204 
       
  1205 			// Normalize the order.
       
  1206 			props.order = props.order.toUpperCase();
       
  1207 			if ( 'DESC' !== props.order && 'ASC' !== props.order ) {
       
  1208 				props.order = defaults.order.toUpperCase();
       
  1209 			}
       
  1210 
       
  1211 			// Ensure we have a valid orderby value.
       
  1212 			if ( ! _.contains( orderby.allowed, props.orderby ) ) {
       
  1213 				props.orderby = defaults.orderby;
       
  1214 			}
       
  1215 
       
  1216 			_.each( [ 'include', 'exclude' ], function( prop ) {
       
  1217 				if ( props[ prop ] && ! _.isArray( props[ prop ] ) ) {
       
  1218 					props[ prop ] = [ props[ prop ] ];
       
  1219 				}
       
  1220 			} );
       
  1221 
       
  1222 			// Generate the query `args` object.
       
  1223 			// Correct any differing property names.
       
  1224 			_.each( props, function( value, prop ) {
       
  1225 				if ( _.isNull( value ) ) {
       
  1226 					return;
       
  1227 				}
       
  1228 
       
  1229 				args[ Query.propmap[ prop ] || prop ] = value;
       
  1230 			});
       
  1231 
       
  1232 			// Fill any other default query args.
       
  1233 			_.defaults( args, Query.defaultArgs );
       
  1234 
       
  1235 			// `props.orderby` does not always map directly to `args.orderby`.
       
  1236 			// Substitute exceptions specified in orderby.keymap.
       
  1237 			args.orderby = orderby.valuemap[ props.orderby ] || props.orderby;
       
  1238 
       
  1239 			queries = [];
       
  1240 
       
  1241 			// Otherwise, create a new query and add it to the cache.
       
  1242 			if ( ! query ) {
       
  1243 				query = new Query( [], _.extend( options || {}, {
       
  1244 					props: props,
       
  1245 					args:  args
       
  1246 				} ) );
       
  1247 				queries.push( query );
       
  1248 			}
       
  1249 
       
  1250 			return query;
       
  1251 		};
       
  1252 	}())
       
  1253 });
       
  1254 
       
  1255 module.exports = Query;
       
  1256 
       
  1257 
       
  1258 /***/ }),
       
  1259 
       
  1260 /***/ 4134:
       
  1261 /***/ ((module) => {
       
  1262 
       
  1263 var Attachments = wp.media.model.Attachments,
       
  1264 	Selection;
       
  1265 
       
  1266 /**
       
  1267  * wp.media.model.Selection
       
  1268  *
       
  1269  * A selection of attachments.
       
  1270  *
       
  1271  * @memberOf wp.media.model
       
  1272  *
       
  1273  * @class
       
  1274  * @augments wp.media.model.Attachments
       
  1275  * @augments Backbone.Collection
       
  1276  */
       
  1277 Selection = Attachments.extend(/** @lends wp.media.model.Selection.prototype */{
       
  1278 	/**
       
  1279 	 * Refresh the `single` model whenever the selection changes.
       
  1280 	 * Binds `single` instead of using the context argument to ensure
       
  1281 	 * it receives no parameters.
       
  1282 	 *
       
  1283 	 * @param {Array} [models=[]] Array of models used to populate the collection.
       
  1284 	 * @param {Object} [options={}]
       
  1285 	 */
       
  1286 	initialize: function( models, options ) {
       
  1287 		/**
       
  1288 		 * call 'initialize' directly on the parent class
       
  1289 		 */
       
  1290 		Attachments.prototype.initialize.apply( this, arguments );
       
  1291 		this.multiple = options && options.multiple;
       
  1292 
       
  1293 		this.on( 'add remove reset', _.bind( this.single, this, false ) );
       
  1294 	},
       
  1295 
       
  1296 	/**
       
  1297 	 * If the workflow does not support multi-select, clear out the selection
       
  1298 	 * before adding a new attachment to it.
       
  1299 	 *
       
  1300 	 * @param {Array} models
       
  1301 	 * @param {Object} options
       
  1302 	 * @return {wp.media.model.Attachment[]}
       
  1303 	 */
       
  1304 	add: function( models, options ) {
       
  1305 		if ( ! this.multiple ) {
       
  1306 			this.remove( this.models );
       
  1307 		}
       
  1308 		/**
       
  1309 		 * call 'add' directly on the parent class
       
  1310 		 */
       
  1311 		return Attachments.prototype.add.call( this, models, options );
       
  1312 	},
       
  1313 
       
  1314 	/**
       
  1315 	 * Fired when toggling (clicking on) an attachment in the modal.
       
  1316 	 *
       
  1317 	 * @param {undefined|boolean|wp.media.model.Attachment} model
       
  1318 	 *
       
  1319 	 * @fires wp.media.model.Selection#selection:single
       
  1320 	 * @fires wp.media.model.Selection#selection:unsingle
       
  1321 	 *
       
  1322 	 * @return {Backbone.Model}
       
  1323 	 */
       
  1324 	single: function( model ) {
       
  1325 		var previous = this._single;
       
  1326 
       
  1327 		// If a `model` is provided, use it as the single model.
       
  1328 		if ( model ) {
       
  1329 			this._single = model;
       
  1330 		}
       
  1331 		// If the single model isn't in the selection, remove it.
       
  1332 		if ( this._single && ! this.get( this._single.cid ) ) {
       
  1333 			delete this._single;
       
  1334 		}
       
  1335 
       
  1336 		this._single = this._single || this.last();
       
  1337 
       
  1338 		// If single has changed, fire an event.
       
  1339 		if ( this._single !== previous ) {
       
  1340 			if ( previous ) {
       
  1341 				previous.trigger( 'selection:unsingle', previous, this );
       
  1342 
       
  1343 				// If the model was already removed, trigger the collection
       
  1344 				// event manually.
       
  1345 				if ( ! this.get( previous.cid ) ) {
       
  1346 					this.trigger( 'selection:unsingle', previous, this );
       
  1347 				}
       
  1348 			}
       
  1349 			if ( this._single ) {
       
  1350 				this._single.trigger( 'selection:single', this._single, this );
       
  1351 			}
       
  1352 		}
       
  1353 
       
  1354 		// Return the single model, or the last model as a fallback.
       
  1355 		return this._single;
       
  1356 	}
       
  1357 });
       
  1358 
       
  1359 module.exports = Selection;
       
  1360 
  1360 
  1361 
  1361 
  1362 /***/ })
  1362 /***/ })
  1363 
  1363 
  1364 /******/ 	});
  1364 /******/ 	});
  1386 /******/ 		// Return the exports of the module
  1386 /******/ 		// Return the exports of the module
  1387 /******/ 		return module.exports;
  1387 /******/ 		return module.exports;
  1388 /******/ 	}
  1388 /******/ 	}
  1389 /******/ 	
  1389 /******/ 	
  1390 /************************************************************************/
  1390 /************************************************************************/
  1391 var __webpack_exports__ = {};
       
  1392 // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
       
  1393 (() => {
       
  1394 /**
  1391 /**
  1395  * @output wp-includes/js/media-models.js
  1392  * @output wp-includes/js/media-models.js
  1396  */
  1393  */
  1397 
  1394 
  1398 var Attachment, Attachments, l10n, media;
  1395 var Attachment, Attachments, l10n, media;
  1628 	return new Attachments( null, {
  1625 	return new Attachments( null, {
  1629 		props: _.extend( _.defaults( props || {}, { orderby: 'date' } ), { query: true } )
  1626 		props: _.extend( _.defaults( props || {}, { orderby: 'date' } ), { query: true } )
  1630 	});
  1627 	});
  1631 };
  1628 };
  1632 
  1629 
  1633 })();
       
  1634 
       
  1635 /******/ })()
  1630 /******/ })()
  1636 ;
  1631 ;