123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- /******/ (function() { // webpackBootstrap
- /******/ "use strict";
- /******/ // The require scope
- /******/ var __webpack_require__ = {};
- /******/
- /************************************************************************/
- /******/ /* webpack/runtime/define property getters */
- /******/ !function() {
- /******/ // define getter functions for harmony exports
- /******/ __webpack_require__.d = function(exports, definition) {
- /******/ for(var key in definition) {
- /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
- /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
- /******/ }
- /******/ }
- /******/ };
- /******/ }();
- /******/
- /******/ /* webpack/runtime/hasOwnProperty shorthand */
- /******/ !function() {
- /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
- /******/ }();
- /******/
- /******/ /* webpack/runtime/make namespace object */
- /******/ !function() {
- /******/ // define __esModule on exports
- /******/ __webpack_require__.r = function(exports) {
- /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
- /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
- /******/ }
- /******/ Object.defineProperty(exports, '__esModule', { value: true });
- /******/ };
- /******/ }();
- /******/
- /************************************************************************/
- var __webpack_exports__ = {};
- // ESM COMPAT FLAG
- __webpack_require__.r(__webpack_exports__);
- // EXPORTS
- __webpack_require__.d(__webpack_exports__, {
- "createQueue": function() { return /* binding */ createQueue; }
- });
- ;// CONCATENATED MODULE: ./node_modules/@wordpress/priority-queue/build-module/request-idle-callback.js
- /**
- * @typedef {( timeOrDeadline: IdleDeadline | number ) => void} Callback
- */
- /**
- * @return {(callback: Callback) => void} RequestIdleCallback
- */
- function createRequestIdleCallback() {
- if (typeof window === 'undefined') {
- return callback => {
- setTimeout(() => callback(Date.now()), 0);
- };
- }
- return window.requestIdleCallback || window.requestAnimationFrame;
- }
- /* harmony default export */ var request_idle_callback = (createRequestIdleCallback());
- ;// CONCATENATED MODULE: ./node_modules/@wordpress/priority-queue/build-module/index.js
- /**
- * Internal dependencies
- */
- /**
- * Enqueued callback to invoke once idle time permits.
- *
- * @typedef {()=>void} WPPriorityQueueCallback
- */
- /**
- * An object used to associate callbacks in a particular context grouping.
- *
- * @typedef {{}} WPPriorityQueueContext
- */
- /**
- * Function to add callback to priority queue.
- *
- * @typedef {(element:WPPriorityQueueContext,item:WPPriorityQueueCallback)=>void} WPPriorityQueueAdd
- */
- /**
- * Function to flush callbacks from priority queue.
- *
- * @typedef {(element:WPPriorityQueueContext)=>boolean} WPPriorityQueueFlush
- */
- /**
- * Reset the queue.
- *
- * @typedef {()=>void} WPPriorityQueueReset
- */
- /**
- * Priority queue instance.
- *
- * @typedef {Object} WPPriorityQueue
- *
- * @property {WPPriorityQueueAdd} add Add callback to queue for context.
- * @property {WPPriorityQueueFlush} flush Flush queue for context.
- * @property {WPPriorityQueueReset} reset Reset queue.
- */
- /**
- * Creates a context-aware queue that only executes
- * the last task of a given context.
- *
- * @example
- *```js
- * import { createQueue } from '@wordpress/priority-queue';
- *
- * const queue = createQueue();
- *
- * // Context objects.
- * const ctx1 = {};
- * const ctx2 = {};
- *
- * // For a given context in the queue, only the last callback is executed.
- * queue.add( ctx1, () => console.log( 'This will be printed first' ) );
- * queue.add( ctx2, () => console.log( 'This won\'t be printed' ) );
- * queue.add( ctx2, () => console.log( 'This will be printed second' ) );
- *```
- *
- * @return {WPPriorityQueue} Queue object with `add`, `flush` and `reset` methods.
- */
- const createQueue = () => {
- /** @type {WPPriorityQueueContext[]} */
- let waitingList = [];
- /** @type {WeakMap<WPPriorityQueueContext,WPPriorityQueueCallback>} */
- let elementsMap = new WeakMap();
- let isRunning = false;
- /**
- * Callback to process as much queue as time permits.
- *
- * @param {IdleDeadline|number} deadline Idle callback deadline object, or
- * animation frame timestamp.
- */
- const runWaitingList = deadline => {
- const hasTimeRemaining = typeof deadline === 'number' ? () => false : () => deadline.timeRemaining() > 0;
- do {
- if (waitingList.length === 0) {
- isRunning = false;
- return;
- }
- const nextElement =
- /** @type {WPPriorityQueueContext} */
- waitingList.shift();
- const callback =
- /** @type {WPPriorityQueueCallback} */
- elementsMap.get(nextElement); // If errors with undefined callbacks are encountered double check that all of your useSelect calls
- // have all dependecies set correctly in second parameter. Missing dependencies can cause unexpected
- // loops and race conditions in the queue.
- callback();
- elementsMap.delete(nextElement);
- } while (hasTimeRemaining());
- request_idle_callback(runWaitingList);
- };
- /**
- * Add a callback to the queue for a given context.
- *
- * @type {WPPriorityQueueAdd}
- *
- * @param {WPPriorityQueueContext} element Context object.
- * @param {WPPriorityQueueCallback} item Callback function.
- */
- const add = (element, item) => {
- if (!elementsMap.has(element)) {
- waitingList.push(element);
- }
- elementsMap.set(element, item);
- if (!isRunning) {
- isRunning = true;
- request_idle_callback(runWaitingList);
- }
- };
- /**
- * Flushes queue for a given context, returning true if the flush was
- * performed, or false if there is no queue for the given context.
- *
- * @type {WPPriorityQueueFlush}
- *
- * @param {WPPriorityQueueContext} element Context object.
- *
- * @return {boolean} Whether flush was performed.
- */
- const flush = element => {
- if (!elementsMap.has(element)) {
- return false;
- }
- const index = waitingList.indexOf(element);
- waitingList.splice(index, 1);
- const callback =
- /** @type {WPPriorityQueueCallback} */
- elementsMap.get(element);
- elementsMap.delete(element);
- callback();
- return true;
- };
- /**
- * Reset the queue without running the pending callbacks.
- *
- * @type {WPPriorityQueueReset}
- */
- const reset = () => {
- waitingList = [];
- elementsMap = new WeakMap();
- isRunning = false;
- };
- return {
- add,
- flush,
- reset
- };
- };
- (window.wp = window.wp || {}).priorityQueue = __webpack_exports__;
- /******/ })()
- ;
|