19
|
1 |
/******/ (function() { // webpackBootstrap |
|
2 |
/******/ "use strict"; |
|
3 |
/******/ // The require scope |
|
4 |
/******/ var __webpack_require__ = {}; |
|
5 |
/******/ |
|
6 |
/************************************************************************/ |
|
7 |
/******/ /* webpack/runtime/define property getters */ |
|
8 |
/******/ !function() { |
|
9 |
/******/ // define getter functions for harmony exports |
|
10 |
/******/ __webpack_require__.d = function(exports, definition) { |
|
11 |
/******/ for(var key in definition) { |
|
12 |
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
|
13 |
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
|
14 |
/******/ } |
|
15 |
/******/ } |
9
|
16 |
/******/ }; |
19
|
17 |
/******/ }(); |
|
18 |
/******/ |
|
19 |
/******/ /* webpack/runtime/hasOwnProperty shorthand */ |
|
20 |
/******/ !function() { |
|
21 |
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } |
|
22 |
/******/ }(); |
|
23 |
/******/ |
|
24 |
/******/ /* webpack/runtime/make namespace object */ |
|
25 |
/******/ !function() { |
|
26 |
/******/ // define __esModule on exports |
|
27 |
/******/ __webpack_require__.r = function(exports) { |
|
28 |
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
|
29 |
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
|
30 |
/******/ } |
|
31 |
/******/ Object.defineProperty(exports, '__esModule', { value: true }); |
|
32 |
/******/ }; |
|
33 |
/******/ }(); |
|
34 |
/******/ |
9
|
35 |
/************************************************************************/ |
19
|
36 |
var __webpack_exports__ = {}; |
16
|
37 |
// ESM COMPAT FLAG |
9
|
38 |
__webpack_require__.r(__webpack_exports__); |
16
|
39 |
|
|
40 |
// EXPORTS |
19
|
41 |
__webpack_require__.d(__webpack_exports__, { |
|
42 |
"createQueue": function() { return /* binding */ createQueue; } |
|
43 |
}); |
16
|
44 |
|
19
|
45 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/priority-queue/build-module/request-idle-callback.js |
16
|
46 |
/** |
|
47 |
* @typedef {( timeOrDeadline: IdleDeadline | number ) => void} Callback |
|
48 |
*/ |
|
49 |
|
|
50 |
/** |
|
51 |
* @return {(callback: Callback) => void} RequestIdleCallback |
|
52 |
*/ |
|
53 |
function createRequestIdleCallback() { |
|
54 |
if (typeof window === 'undefined') { |
18
|
55 |
return callback => { |
|
56 |
setTimeout(() => callback(Date.now()), 0); |
16
|
57 |
}; |
|
58 |
} |
|
59 |
|
|
60 |
return window.requestIdleCallback || window.requestAnimationFrame; |
|
61 |
} |
|
62 |
/* harmony default export */ var request_idle_callback = (createRequestIdleCallback()); |
|
63 |
|
19
|
64 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/priority-queue/build-module/index.js |
16
|
65 |
/** |
|
66 |
* Internal dependencies |
|
67 |
*/ |
|
68 |
|
|
69 |
/** |
|
70 |
* Enqueued callback to invoke once idle time permits. |
|
71 |
* |
|
72 |
* @typedef {()=>void} WPPriorityQueueCallback |
|
73 |
*/ |
|
74 |
|
|
75 |
/** |
|
76 |
* An object used to associate callbacks in a particular context grouping. |
|
77 |
* |
|
78 |
* @typedef {{}} WPPriorityQueueContext |
|
79 |
*/ |
|
80 |
|
|
81 |
/** |
|
82 |
* Function to add callback to priority queue. |
|
83 |
* |
|
84 |
* @typedef {(element:WPPriorityQueueContext,item:WPPriorityQueueCallback)=>void} WPPriorityQueueAdd |
|
85 |
*/ |
|
86 |
|
|
87 |
/** |
|
88 |
* Function to flush callbacks from priority queue. |
|
89 |
* |
|
90 |
* @typedef {(element:WPPriorityQueueContext)=>boolean} WPPriorityQueueFlush |
|
91 |
*/ |
|
92 |
|
|
93 |
/** |
|
94 |
* Reset the queue. |
|
95 |
* |
|
96 |
* @typedef {()=>void} WPPriorityQueueReset |
|
97 |
*/ |
|
98 |
|
|
99 |
/** |
|
100 |
* Priority queue instance. |
|
101 |
* |
|
102 |
* @typedef {Object} WPPriorityQueue |
|
103 |
* |
|
104 |
* @property {WPPriorityQueueAdd} add Add callback to queue for context. |
|
105 |
* @property {WPPriorityQueueFlush} flush Flush queue for context. |
|
106 |
* @property {WPPriorityQueueReset} reset Reset queue. |
|
107 |
*/ |
|
108 |
|
9
|
109 |
/** |
|
110 |
* Creates a context-aware queue that only executes |
|
111 |
* the last task of a given context. |
|
112 |
* |
|
113 |
* @example |
|
114 |
*```js |
|
115 |
* import { createQueue } from '@wordpress/priority-queue'; |
|
116 |
* |
|
117 |
* const queue = createQueue(); |
|
118 |
* |
|
119 |
* // Context objects. |
|
120 |
* const ctx1 = {}; |
|
121 |
* const ctx2 = {}; |
|
122 |
* |
|
123 |
* // For a given context in the queue, only the last callback is executed. |
|
124 |
* queue.add( ctx1, () => console.log( 'This will be printed first' ) ); |
|
125 |
* queue.add( ctx2, () => console.log( 'This won\'t be printed' ) ); |
|
126 |
* queue.add( ctx2, () => console.log( 'This will be printed second' ) ); |
|
127 |
*``` |
|
128 |
* |
16
|
129 |
* @return {WPPriorityQueue} Queue object with `add`, `flush` and `reset` methods. |
9
|
130 |
*/ |
|
131 |
|
18
|
132 |
const createQueue = () => { |
16
|
133 |
/** @type {WPPriorityQueueContext[]} */ |
18
|
134 |
let waitingList = []; |
16
|
135 |
/** @type {WeakMap<WPPriorityQueueContext,WPPriorityQueueCallback>} */ |
|
136 |
|
18
|
137 |
let elementsMap = new WeakMap(); |
|
138 |
let isRunning = false; |
16
|
139 |
/** |
|
140 |
* Callback to process as much queue as time permits. |
|
141 |
* |
|
142 |
* @param {IdleDeadline|number} deadline Idle callback deadline object, or |
|
143 |
* animation frame timestamp. |
|
144 |
*/ |
|
145 |
|
18
|
146 |
const runWaitingList = deadline => { |
|
147 |
const hasTimeRemaining = typeof deadline === 'number' ? () => false : () => deadline.timeRemaining() > 0; |
16
|
148 |
|
9
|
149 |
do { |
|
150 |
if (waitingList.length === 0) { |
|
151 |
isRunning = false; |
|
152 |
return; |
|
153 |
} |
|
154 |
|
18
|
155 |
const nextElement = |
16
|
156 |
/** @type {WPPriorityQueueContext} */ |
|
157 |
waitingList.shift(); |
18
|
158 |
const callback = |
16
|
159 |
/** @type {WPPriorityQueueCallback} */ |
18
|
160 |
elementsMap.get(nextElement); // If errors with undefined callbacks are encountered double check that all of your useSelect calls |
|
161 |
// have all dependecies set correctly in second parameter. Missing dependencies can cause unexpected |
|
162 |
// loops and race conditions in the queue. |
|
163 |
|
16
|
164 |
callback(); |
9
|
165 |
elementsMap.delete(nextElement); |
16
|
166 |
} while (hasTimeRemaining()); |
9
|
167 |
|
16
|
168 |
request_idle_callback(runWaitingList); |
9
|
169 |
}; |
16
|
170 |
/** |
|
171 |
* Add a callback to the queue for a given context. |
|
172 |
* |
|
173 |
* @type {WPPriorityQueueAdd} |
|
174 |
* |
|
175 |
* @param {WPPriorityQueueContext} element Context object. |
|
176 |
* @param {WPPriorityQueueCallback} item Callback function. |
|
177 |
*/ |
|
178 |
|
9
|
179 |
|
18
|
180 |
const add = (element, item) => { |
9
|
181 |
if (!elementsMap.has(element)) { |
|
182 |
waitingList.push(element); |
|
183 |
} |
|
184 |
|
|
185 |
elementsMap.set(element, item); |
|
186 |
|
|
187 |
if (!isRunning) { |
|
188 |
isRunning = true; |
16
|
189 |
request_idle_callback(runWaitingList); |
9
|
190 |
} |
|
191 |
}; |
16
|
192 |
/** |
|
193 |
* Flushes queue for a given context, returning true if the flush was |
|
194 |
* performed, or false if there is no queue for the given context. |
|
195 |
* |
|
196 |
* @type {WPPriorityQueueFlush} |
|
197 |
* |
|
198 |
* @param {WPPriorityQueueContext} element Context object. |
|
199 |
* |
|
200 |
* @return {boolean} Whether flush was performed. |
|
201 |
*/ |
|
202 |
|
9
|
203 |
|
18
|
204 |
const flush = element => { |
9
|
205 |
if (!elementsMap.has(element)) { |
|
206 |
return false; |
|
207 |
} |
|
208 |
|
18
|
209 |
const index = waitingList.indexOf(element); |
9
|
210 |
waitingList.splice(index, 1); |
18
|
211 |
const callback = |
16
|
212 |
/** @type {WPPriorityQueueCallback} */ |
|
213 |
elementsMap.get(element); |
|
214 |
elementsMap.delete(element); |
|
215 |
callback(); |
9
|
216 |
return true; |
|
217 |
}; |
16
|
218 |
/** |
|
219 |
* Reset the queue without running the pending callbacks. |
|
220 |
* |
|
221 |
* @type {WPPriorityQueueReset} |
|
222 |
*/ |
|
223 |
|
|
224 |
|
18
|
225 |
const reset = () => { |
16
|
226 |
waitingList = []; |
|
227 |
elementsMap = new WeakMap(); |
|
228 |
isRunning = false; |
|
229 |
}; |
9
|
230 |
|
|
231 |
return { |
18
|
232 |
add, |
|
233 |
flush, |
|
234 |
reset |
9
|
235 |
}; |
|
236 |
}; |
|
237 |
|
19
|
238 |
(window.wp = window.wp || {}).priorityQueue = __webpack_exports__; |
|
239 |
/******/ })() |
|
240 |
; |