wp/wp-includes/js/dist/data-controls.js
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
    80 /******/ 	// __webpack_public_path__
    80 /******/ 	// __webpack_public_path__
    81 /******/ 	__webpack_require__.p = "";
    81 /******/ 	__webpack_require__.p = "";
    82 /******/
    82 /******/
    83 /******/
    83 /******/
    84 /******/ 	// Load entry module and return exports
    84 /******/ 	// Load entry module and return exports
    85 /******/ 	return __webpack_require__(__webpack_require__.s = 413);
    85 /******/ 	return __webpack_require__(__webpack_require__.s = "71Oy");
    86 /******/ })
    86 /******/ })
    87 /************************************************************************/
    87 /************************************************************************/
    88 /******/ ({
    88 /******/ ({
    89 
    89 
    90 /***/ 18:
    90 /***/ "1ZqX":
    91 /***/ (function(module, __webpack_exports__, __webpack_require__) {
    91 /***/ (function(module, exports) {
    92 
    92 
    93 "use strict";
    93 (function() { module.exports = window["wp"]["data"]; }());
    94 
       
    95 // EXPORTS
       
    96 __webpack_require__.d(__webpack_exports__, "a", function() { return /* binding */ _toConsumableArray; });
       
    97 
       
    98 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.js
       
    99 var arrayLikeToArray = __webpack_require__(26);
       
   100 
       
   101 // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.js
       
   102 
       
   103 function _arrayWithoutHoles(arr) {
       
   104   if (Array.isArray(arr)) return Object(arrayLikeToArray["a" /* default */])(arr);
       
   105 }
       
   106 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/iterableToArray.js
       
   107 var iterableToArray = __webpack_require__(35);
       
   108 
       
   109 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js
       
   110 var unsupportedIterableToArray = __webpack_require__(29);
       
   111 
       
   112 // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/nonIterableSpread.js
       
   113 function _nonIterableSpread() {
       
   114   throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
       
   115 }
       
   116 // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js
       
   117 
       
   118 
       
   119 
       
   120 
       
   121 function _toConsumableArray(arr) {
       
   122   return _arrayWithoutHoles(arr) || Object(iterableToArray["a" /* default */])(arr) || Object(unsupportedIterableToArray["a" /* default */])(arr) || _nonIterableSpread();
       
   123 }
       
   124 
    94 
   125 /***/ }),
    95 /***/ }),
   126 
    96 
   127 /***/ 26:
    97 /***/ "71Oy":
   128 /***/ (function(module, __webpack_exports__, __webpack_require__) {
       
   129 
       
   130 "use strict";
       
   131 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _arrayLikeToArray; });
       
   132 function _arrayLikeToArray(arr, len) {
       
   133   if (len == null || len > arr.length) len = arr.length;
       
   134 
       
   135   for (var i = 0, arr2 = new Array(len); i < len; i++) {
       
   136     arr2[i] = arr[i];
       
   137   }
       
   138 
       
   139   return arr2;
       
   140 }
       
   141 
       
   142 /***/ }),
       
   143 
       
   144 /***/ 29:
       
   145 /***/ (function(module, __webpack_exports__, __webpack_require__) {
       
   146 
       
   147 "use strict";
       
   148 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _unsupportedIterableToArray; });
       
   149 /* harmony import */ var _arrayLikeToArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(26);
       
   150 
       
   151 function _unsupportedIterableToArray(o, minLen) {
       
   152   if (!o) return;
       
   153   if (typeof o === "string") return Object(_arrayLikeToArray__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(o, minLen);
       
   154   var n = Object.prototype.toString.call(o).slice(8, -1);
       
   155   if (n === "Object" && o.constructor) n = o.constructor.name;
       
   156   if (n === "Map" || n === "Set") return Array.from(o);
       
   157   if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return Object(_arrayLikeToArray__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(o, minLen);
       
   158 }
       
   159 
       
   160 /***/ }),
       
   161 
       
   162 /***/ 35:
       
   163 /***/ (function(module, __webpack_exports__, __webpack_require__) {
       
   164 
       
   165 "use strict";
       
   166 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _iterableToArray; });
       
   167 function _iterableToArray(iter) {
       
   168   if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
       
   169 }
       
   170 
       
   171 /***/ }),
       
   172 
       
   173 /***/ 4:
       
   174 /***/ (function(module, exports) {
       
   175 
       
   176 (function() { module.exports = this["wp"]["data"]; }());
       
   177 
       
   178 /***/ }),
       
   179 
       
   180 /***/ 413:
       
   181 /***/ (function(module, __webpack_exports__, __webpack_require__) {
    98 /***/ (function(module, __webpack_exports__, __webpack_require__) {
   182 
    99 
   183 "use strict";
   100 "use strict";
   184 __webpack_require__.r(__webpack_exports__);
   101 __webpack_require__.r(__webpack_exports__);
   185 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "apiFetch", function() { return apiFetch; });
   102 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "apiFetch", function() { return apiFetch; });
   186 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "select", function() { return select; });
   103 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "select", function() { return select; });
   187 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__unstableSyncSelect", function() { return __unstableSyncSelect; });
   104 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "syncSelect", function() { return syncSelect; });
   188 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "dispatch", function() { return dispatch; });
   105 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "dispatch", function() { return dispatch; });
       
   106 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__unstableAwaitPromise", function() { return __unstableAwaitPromise; });
   189 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "controls", function() { return controls; });
   107 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "controls", function() { return controls; });
   190 /* harmony import */ var _babel_runtime_helpers_esm_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(18);
   108 /* harmony import */ var _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("ywyh");
   191 /* harmony import */ var _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(45);
   109 /* harmony import */ var _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_0__);
   192 /* harmony import */ var _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_1__);
   110 /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("1ZqX");
   193 /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(4);
   111 /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_1__);
   194 /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_2__);
   112 /* harmony import */ var _wordpress_deprecated__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("NMb1");
   195 
   113 /* harmony import */ var _wordpress_deprecated__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_deprecated__WEBPACK_IMPORTED_MODULE_2__);
   196 
       
   197 /**
   114 /**
   198  * WordPress dependencies
   115  * WordPress dependencies
   199  */
   116  */
       
   117 
   200 
   118 
   201 
   119 
   202 /**
   120 /**
   203  * Dispatches a control action for triggering an api fetch call.
   121  * Dispatches a control action for triggering an api fetch call.
   204  *
   122  *
   217  * ```
   135  * ```
   218  *
   136  *
   219  * @return {Object} The control descriptor.
   137  * @return {Object} The control descriptor.
   220  */
   138  */
   221 
   139 
   222 var apiFetch = function apiFetch(request) {
   140 function apiFetch(request) {
   223   return {
   141   return {
   224     type: 'API_FETCH',
   142     type: 'API_FETCH',
   225     request: request
   143     request
       
   144   };
       
   145 }
       
   146 /**
       
   147  * Control for resolving a selector in a registered data store.
       
   148  * Alias for the `resolveSelect` built-in control in the `@wordpress/data` package.
       
   149  *
       
   150  * @param {Array} args Arguments passed without change to the `@wordpress/data` control.
       
   151  */
       
   152 
       
   153 function select(...args) {
       
   154   _wordpress_deprecated__WEBPACK_IMPORTED_MODULE_2___default()('`select` control in `@wordpress/data-controls`', {
       
   155     since: '5.7',
       
   156     alternative: 'built-in `resolveSelect` control in `@wordpress/data`'
       
   157   });
       
   158   return _wordpress_data__WEBPACK_IMPORTED_MODULE_1__["controls"].resolveSelect(...args);
       
   159 }
       
   160 /**
       
   161  * Control for calling a selector in a registered data store.
       
   162  * Alias for the `select` built-in control in the `@wordpress/data` package.
       
   163  *
       
   164  * @param {Array} args Arguments passed without change to the `@wordpress/data` control.
       
   165  */
       
   166 
       
   167 function syncSelect(...args) {
       
   168   _wordpress_deprecated__WEBPACK_IMPORTED_MODULE_2___default()('`syncSelect` control in `@wordpress/data-controls`', {
       
   169     since: '5.7',
       
   170     alternative: 'built-in `select` control in `@wordpress/data`'
       
   171   });
       
   172   return _wordpress_data__WEBPACK_IMPORTED_MODULE_1__["controls"].select(...args);
       
   173 }
       
   174 /**
       
   175  * Control for dispatching an action in a registered data store.
       
   176  * Alias for the `dispatch` control in the `@wordpress/data` package.
       
   177  *
       
   178  * @param {Array} args Arguments passed without change to the `@wordpress/data` control.
       
   179  */
       
   180 
       
   181 function dispatch(...args) {
       
   182   _wordpress_deprecated__WEBPACK_IMPORTED_MODULE_2___default()('`dispatch` control in `@wordpress/data-controls`', {
       
   183     since: '5.7',
       
   184     alternative: 'built-in `dispatch` control in `@wordpress/data`'
       
   185   });
       
   186   return _wordpress_data__WEBPACK_IMPORTED_MODULE_1__["controls"].dispatch(...args);
       
   187 }
       
   188 /**
       
   189  * Dispatches a control action for awaiting on a promise to be resolved.
       
   190  *
       
   191  * @param {Object} promise Promise to wait for.
       
   192  *
       
   193  * @example
       
   194  * ```js
       
   195  * import { __unstableAwaitPromise } from '@wordpress/data-controls';
       
   196  *
       
   197  * // Action generator using apiFetch
       
   198  * export function* myAction() {
       
   199  * 	const promise = getItemsAsync();
       
   200  * 	const items = yield __unstableAwaitPromise( promise );
       
   201  * 	// do something with the items.
       
   202  * }
       
   203  * ```
       
   204  *
       
   205  * @return {Object} The control descriptor.
       
   206  */
       
   207 
       
   208 const __unstableAwaitPromise = function (promise) {
       
   209   return {
       
   210     type: 'AWAIT_PROMISE',
       
   211     promise
   226   };
   212   };
   227 };
   213 };
   228 /**
       
   229  * Dispatches a control action for triggering a registry select.
       
   230  *
       
   231  * Note: when this control action is handled, it automatically considers
       
   232  * selectors that may have a resolver. It will await and return the resolved
       
   233  * value when the selector has not been resolved yet.
       
   234  *
       
   235  * @param {string} storeKey      The key for the store the selector belongs to
       
   236  * @param {string} selectorName  The name of the selector
       
   237  * @param {Array}  args          Arguments for the select.
       
   238  *
       
   239  * @example
       
   240  * ```js
       
   241  * import { select } from '@wordpress/data-controls';
       
   242  *
       
   243  * // Action generator using select
       
   244  * export function* myAction() {
       
   245  * 	const isSidebarOpened = yield select( 'core/edit-post', 'isEditorSideBarOpened' );
       
   246  * 	// do stuff with the result from the select.
       
   247  * }
       
   248  * ```
       
   249  *
       
   250  * @return {Object} The control descriptor.
       
   251  */
       
   252 
       
   253 function select(storeKey, selectorName) {
       
   254   for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
       
   255     args[_key - 2] = arguments[_key];
       
   256   }
       
   257 
       
   258   return {
       
   259     type: 'SELECT',
       
   260     storeKey: storeKey,
       
   261     selectorName: selectorName,
       
   262     args: args
       
   263   };
       
   264 }
       
   265 /**
       
   266  * Dispatches a control action for triggering a registry select.
       
   267  *
       
   268  * Note: This functions like the `select` control, but does not wait
       
   269  * for resolvers.
       
   270  *
       
   271  * @param {string} storeKey     The key for the store the selector belongs to.
       
   272  * @param {string} selectorName The name of the selector.
       
   273  * @param {Array}  args         Arguments for the select.
       
   274  *
       
   275  * @example
       
   276  * ```js
       
   277  * import { __unstableSyncSelect } from '@wordpress/data-controls';
       
   278  *
       
   279  * // Action generator using `__unstableSyncSelect`.
       
   280  * export function* myAction() {
       
   281  * 	const isEditorSideBarOpened = yield __unstableSyncSelect( 'core/edit-post', 'isEditorSideBarOpened' );
       
   282  * 	// Do stuff with the result from the `__unstableSyncSelect`.
       
   283  * }
       
   284  * ```
       
   285  *
       
   286  * @return {Object} The control descriptor.
       
   287  */
       
   288 
       
   289 function __unstableSyncSelect(storeKey, selectorName) {
       
   290   for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
       
   291     args[_key2 - 2] = arguments[_key2];
       
   292   }
       
   293 
       
   294   return {
       
   295     type: 'SYNC_SELECT',
       
   296     storeKey: storeKey,
       
   297     selectorName: selectorName,
       
   298     args: args
       
   299   };
       
   300 }
       
   301 /**
       
   302  * Dispatches a control action for triggering a registry dispatch.
       
   303  *
       
   304  * @param {string} storeKey    The key for the store the action belongs to
       
   305  * @param {string} actionName  The name of the action to dispatch
       
   306  * @param {Array}  args        Arguments for the dispatch action.
       
   307  *
       
   308  * @example
       
   309  * ```js
       
   310  * import { dispatch } from '@wordpress/data-controls';
       
   311  *
       
   312  * // Action generator using dispatch
       
   313  * export function* myAction() {
       
   314  * 	yield dispatch( 'core/edit-post', 'togglePublishSidebar' );
       
   315  * 	// do some other things.
       
   316  * }
       
   317  * ```
       
   318  *
       
   319  * @return {Object}  The control descriptor.
       
   320  */
       
   321 
       
   322 function dispatch(storeKey, actionName) {
       
   323   for (var _len3 = arguments.length, args = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
       
   324     args[_key3 - 2] = arguments[_key3];
       
   325   }
       
   326 
       
   327   return {
       
   328     type: 'DISPATCH',
       
   329     storeKey: storeKey,
       
   330     actionName: actionName,
       
   331     args: args
       
   332   };
       
   333 }
       
   334 /**
   214 /**
   335  * The default export is what you use to register the controls with your custom
   215  * The default export is what you use to register the controls with your custom
   336  * store.
   216  * store.
   337  *
   217  *
   338  * @example
   218  * @example
   346  * import * as selectors from './selectors';
   226  * import * as selectors from './selectors';
   347  * import * as actions from './actions';
   227  * import * as actions from './actions';
   348  * import * as resolvers from './resolvers';
   228  * import * as resolvers from './resolvers';
   349  *
   229  *
   350  * registerStore( 'my-custom-store', {
   230  * registerStore( 'my-custom-store', {
   351  * 	reducer,
   231  * reducer,
   352  * 	controls,
   232  * controls,
   353  * 	actions,
   233  * actions,
   354  * 	selectors,
   234  * selectors,
   355  * 	resolvers,
   235  * resolvers,
   356  * } );
   236  * } );
   357  * ```
   237  * ```
   358  *
       
   359  * @return {Object} An object for registering the default controls with the
   238  * @return {Object} An object for registering the default controls with the
   360  *                  store.
   239  * store.
   361  */
   240  */
   362 
   241 
   363 var controls = {
   242 const controls = {
   364   API_FETCH: function API_FETCH(_ref) {
   243   AWAIT_PROMISE: ({
   365     var request = _ref.request;
   244     promise
   366     return _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_1___default()(request);
   245   }) => promise,
   367   },
   246 
   368   SELECT: Object(_wordpress_data__WEBPACK_IMPORTED_MODULE_2__["createRegistryControl"])(function (registry) {
   247   API_FETCH({
   369     return function (_ref2) {
   248     request
   370       var _registry;
   249   }) {
   371 
   250     return _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_0___default()(request);
   372       var storeKey = _ref2.storeKey,
   251   }
   373           selectorName = _ref2.selectorName,
   252 
   374           args = _ref2.args;
       
   375       return (_registry = registry[registry.select(storeKey)[selectorName].hasResolver ? '__experimentalResolveSelect' : 'select'](storeKey))[selectorName].apply(_registry, Object(_babel_runtime_helpers_esm_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(args));
       
   376     };
       
   377   }),
       
   378   SYNC_SELECT: Object(_wordpress_data__WEBPACK_IMPORTED_MODULE_2__["createRegistryControl"])(function (registry) {
       
   379     return function (_ref3) {
       
   380       var _registry$select;
       
   381 
       
   382       var storeKey = _ref3.storeKey,
       
   383           selectorName = _ref3.selectorName,
       
   384           args = _ref3.args;
       
   385       return (_registry$select = registry.select(storeKey))[selectorName].apply(_registry$select, Object(_babel_runtime_helpers_esm_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(args));
       
   386     };
       
   387   }),
       
   388   DISPATCH: Object(_wordpress_data__WEBPACK_IMPORTED_MODULE_2__["createRegistryControl"])(function (registry) {
       
   389     return function (_ref4) {
       
   390       var _registry$dispatch;
       
   391 
       
   392       var storeKey = _ref4.storeKey,
       
   393           actionName = _ref4.actionName,
       
   394           args = _ref4.args;
       
   395       return (_registry$dispatch = registry.dispatch(storeKey))[actionName].apply(_registry$dispatch, Object(_babel_runtime_helpers_esm_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(args));
       
   396     };
       
   397   })
       
   398 };
   253 };
   399 
   254 
   400 
   255 
   401 /***/ }),
   256 /***/ }),
   402 
   257 
   403 /***/ 45:
   258 /***/ "NMb1":
   404 /***/ (function(module, exports) {
   259 /***/ (function(module, exports) {
   405 
   260 
   406 (function() { module.exports = this["wp"]["apiFetch"]; }());
   261 (function() { module.exports = window["wp"]["deprecated"]; }());
       
   262 
       
   263 /***/ }),
       
   264 
       
   265 /***/ "ywyh":
       
   266 /***/ (function(module, exports) {
       
   267 
       
   268 (function() { module.exports = window["wp"]["apiFetch"]; }());
   407 
   269 
   408 /***/ })
   270 /***/ })
   409 
   271 
   410 /******/ });
   272 /******/ });