@wordpress/priority-queue 3.32.0 → 3.32.1-next.ff1cebbba.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.js +45 -106
- package/build/index.js.map +7 -1
- package/build/request-idle-callback.js +31 -21
- package/build/request-idle-callback.js.map +7 -1
- package/build/types.js +16 -5
- package/build/types.js.map +7 -1
- package/build-module/index.js +12 -99
- package/build-module/index.js.map +7 -1
- package/build-module/request-idle-callback.js +10 -17
- package/build-module/request-idle-callback.js.map +7 -1
- package/build-module/types.js +1 -2
- package/build-module/types.js.map +7 -1
- package/package.json +10 -3
package/build/index.js
CHANGED
|
@@ -1,74 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var index_exports = {};
|
|
30
|
+
__export(index_exports, {
|
|
31
|
+
createQueue: () => createQueue
|
|
6
32
|
});
|
|
7
|
-
exports
|
|
8
|
-
var
|
|
9
|
-
/**
|
|
10
|
-
* Internal dependencies
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Enqueued callback to invoke once idle time permits.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* An object used to associate callbacks in a particular context grouping.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Interface for the priority queue instance.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Creates a context-aware queue that only executes
|
|
27
|
-
* the last task of a given context.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
*```js
|
|
31
|
-
* import { createQueue } from '@wordpress/priority-queue';
|
|
32
|
-
*
|
|
33
|
-
* const queue = createQueue();
|
|
34
|
-
*
|
|
35
|
-
* // Context objects.
|
|
36
|
-
* const ctx1 = {};
|
|
37
|
-
* const ctx2 = {};
|
|
38
|
-
*
|
|
39
|
-
* // For a given context in the queue, only the last callback is executed.
|
|
40
|
-
* queue.add( ctx1, () => console.log( 'This will be printed first' ) );
|
|
41
|
-
* queue.add( ctx2, () => console.log( 'This won\'t be printed' ) );
|
|
42
|
-
* queue.add( ctx2, () => console.log( 'This will be printed second' ) );
|
|
43
|
-
*```
|
|
44
|
-
*
|
|
45
|
-
* @return {WPPriorityQueue} Queue object with `add`, `flush` and `reset` methods.
|
|
46
|
-
*/
|
|
33
|
+
module.exports = __toCommonJS(index_exports);
|
|
34
|
+
var import_request_idle_callback = __toESM(require("./request-idle-callback"));
|
|
47
35
|
const createQueue = () => {
|
|
48
|
-
const waitingList = new Map();
|
|
36
|
+
const waitingList = /* @__PURE__ */ new Map();
|
|
49
37
|
let isRunning = false;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Callback to process as much queue as time permits.
|
|
53
|
-
*
|
|
54
|
-
* Map Iteration follows the original insertion order. This means that here
|
|
55
|
-
* we can iterate the queue and know that the first contexts which were
|
|
56
|
-
* added will be run first. On the other hand, if anyone adds a new callback
|
|
57
|
-
* for an existing context it will supplant the previously-set callback for
|
|
58
|
-
* that context because we reassigned that map key's value.
|
|
59
|
-
*
|
|
60
|
-
* In the case that a callback adds a new callback to its own context then
|
|
61
|
-
* the callback it adds will appear at the end of the iteration and will be
|
|
62
|
-
* run only after all other existing contexts have finished executing.
|
|
63
|
-
*
|
|
64
|
-
* @param {IdleDeadline|number} deadline Idle callback deadline object, or
|
|
65
|
-
* animation frame timestamp.
|
|
66
|
-
*/
|
|
67
|
-
const runWaitingList = deadline => {
|
|
38
|
+
const runWaitingList = (deadline) => {
|
|
68
39
|
for (const [nextElement, callback] of waitingList) {
|
|
69
40
|
waitingList.delete(nextElement);
|
|
70
41
|
callback();
|
|
71
|
-
if (
|
|
42
|
+
if ("number" === typeof deadline || deadline.timeRemaining() <= 0) {
|
|
72
43
|
break;
|
|
73
44
|
}
|
|
74
45
|
}
|
|
@@ -76,62 +47,27 @@ const createQueue = () => {
|
|
|
76
47
|
isRunning = false;
|
|
77
48
|
return;
|
|
78
49
|
}
|
|
79
|
-
(0,
|
|
50
|
+
(0, import_request_idle_callback.default)(runWaitingList);
|
|
80
51
|
};
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Add a callback to the queue for a given context.
|
|
84
|
-
*
|
|
85
|
-
* If errors with undefined callbacks are encountered double check that
|
|
86
|
-
* all of your useSelect calls have the right dependencies set correctly
|
|
87
|
-
* in their second parameter. Missing dependencies can cause unexpected
|
|
88
|
-
* loops and race conditions in the queue.
|
|
89
|
-
*
|
|
90
|
-
* @param {WPPriorityQueueContext} element Context object.
|
|
91
|
-
* @param {WPPriorityQueueCallback} item Callback function.
|
|
92
|
-
*/
|
|
93
52
|
const add = (element, item) => {
|
|
94
53
|
waitingList.set(element, item);
|
|
95
54
|
if (!isRunning) {
|
|
96
55
|
isRunning = true;
|
|
97
|
-
(0,
|
|
56
|
+
(0, import_request_idle_callback.default)(runWaitingList);
|
|
98
57
|
}
|
|
99
58
|
};
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Flushes queue for a given context, returning true if the flush was
|
|
103
|
-
* performed, or false if there is no queue for the given context.
|
|
104
|
-
*
|
|
105
|
-
* @param {WPPriorityQueueContext} element Context object.
|
|
106
|
-
*
|
|
107
|
-
* @return {boolean} Whether flush was performed.
|
|
108
|
-
*/
|
|
109
|
-
const flush = element => {
|
|
59
|
+
const flush = (element) => {
|
|
110
60
|
const callback = waitingList.get(element);
|
|
111
|
-
if (
|
|
61
|
+
if (void 0 === callback) {
|
|
112
62
|
return false;
|
|
113
63
|
}
|
|
114
64
|
waitingList.delete(element);
|
|
115
65
|
callback();
|
|
116
66
|
return true;
|
|
117
67
|
};
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Clears the queue for a given context, cancelling the callbacks without
|
|
121
|
-
* executing them. Returns `true` if there were scheduled callbacks to cancel,
|
|
122
|
-
* or `false` if there was is no queue for the given context.
|
|
123
|
-
*
|
|
124
|
-
* @param {WPPriorityQueueContext} element Context object.
|
|
125
|
-
*
|
|
126
|
-
* @return {boolean} Whether any callbacks got cancelled.
|
|
127
|
-
*/
|
|
128
|
-
const cancel = element => {
|
|
68
|
+
const cancel = (element) => {
|
|
129
69
|
return waitingList.delete(element);
|
|
130
70
|
};
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Reset the queue without running the pending callbacks.
|
|
134
|
-
*/
|
|
135
71
|
const reset = () => {
|
|
136
72
|
waitingList.clear();
|
|
137
73
|
isRunning = false;
|
|
@@ -143,5 +79,8 @@ const createQueue = () => {
|
|
|
143
79
|
reset
|
|
144
80
|
};
|
|
145
81
|
};
|
|
146
|
-
|
|
147
|
-
|
|
82
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
83
|
+
0 && (module.exports = {
|
|
84
|
+
createQueue
|
|
85
|
+
});
|
|
86
|
+
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport requestIdleCallback from './request-idle-callback';\n\n/**\n * Enqueued callback to invoke once idle time permits.\n */\nexport type WPPriorityQueueCallback = VoidFunction;\n\n/**\n * An object used to associate callbacks in a particular context grouping.\n */\nexport type WPPriorityQueueContext = object;\n\n/**\n * Interface for the priority queue instance.\n */\nexport interface WPPriorityQueue {\n\t/**\n\t * Add a callback to the queue for a given context.\n\t */\n\tadd: (\n\t\telement: WPPriorityQueueContext,\n\t\titem: WPPriorityQueueCallback\n\t) => void;\n\n\t/**\n\t * Flush and run the callback for a given context immediately.\n\t * @return true if a callback was run, false otherwise.\n\t */\n\tflush: ( element: WPPriorityQueueContext ) => boolean;\n\n\t/**\n\t * Cancel (remove) the callback for a given context without running it.\n\t * @return true if a callback was cancelled, false otherwise.\n\t */\n\tcancel: ( element: WPPriorityQueueContext ) => boolean;\n\n\t/**\n\t * Reset the entire queue, clearing pending callbacks.\n\t */\n\treset: VoidFunction;\n}\n\n/**\n * Creates a context-aware queue that only executes\n * the last task of a given context.\n *\n * @example\n *```js\n * import { createQueue } from '@wordpress/priority-queue';\n *\n * const queue = createQueue();\n *\n * // Context objects.\n * const ctx1 = {};\n * const ctx2 = {};\n *\n * // For a given context in the queue, only the last callback is executed.\n * queue.add( ctx1, () => console.log( 'This will be printed first' ) );\n * queue.add( ctx2, () => console.log( 'This won\\'t be printed' ) );\n * queue.add( ctx2, () => console.log( 'This will be printed second' ) );\n *```\n *\n * @return {WPPriorityQueue} Queue object with `add`, `flush` and `reset` methods.\n */\nexport const createQueue = (): WPPriorityQueue => {\n\tconst waitingList = new Map<\n\t\tWPPriorityQueueContext,\n\t\tWPPriorityQueueCallback\n\t>();\n\tlet isRunning = false;\n\n\t/**\n\t * Callback to process as much queue as time permits.\n\t *\n\t * Map Iteration follows the original insertion order. This means that here\n\t * we can iterate the queue and know that the first contexts which were\n\t * added will be run first. On the other hand, if anyone adds a new callback\n\t * for an existing context it will supplant the previously-set callback for\n\t * that context because we reassigned that map key's value.\n\t *\n\t * In the case that a callback adds a new callback to its own context then\n\t * the callback it adds will appear at the end of the iteration and will be\n\t * run only after all other existing contexts have finished executing.\n\t *\n\t * @param {IdleDeadline|number} deadline Idle callback deadline object, or\n\t * animation frame timestamp.\n\t */\n\tconst runWaitingList = ( deadline: IdleDeadline | number ): void => {\n\t\tfor ( const [ nextElement, callback ] of waitingList ) {\n\t\t\twaitingList.delete( nextElement );\n\t\t\tcallback();\n\n\t\t\tif (\n\t\t\t\t'number' === typeof deadline ||\n\t\t\t\tdeadline.timeRemaining() <= 0\n\t\t\t) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tif ( waitingList.size === 0 ) {\n\t\t\tisRunning = false;\n\t\t\treturn;\n\t\t}\n\n\t\trequestIdleCallback( runWaitingList );\n\t};\n\n\t/**\n\t * Add a callback to the queue for a given context.\n\t *\n\t * If errors with undefined callbacks are encountered double check that\n\t * all of your useSelect calls have the right dependencies set correctly\n\t * in their second parameter. Missing dependencies can cause unexpected\n\t * loops and race conditions in the queue.\n\t *\n\t * @param {WPPriorityQueueContext} element Context object.\n\t * @param {WPPriorityQueueCallback} item Callback function.\n\t */\n\tconst add: WPPriorityQueue[ 'add' ] = (\n\t\telement: WPPriorityQueueContext,\n\t\titem: WPPriorityQueueCallback\n\t) => {\n\t\twaitingList.set( element, item );\n\t\tif ( ! isRunning ) {\n\t\t\tisRunning = true;\n\t\t\trequestIdleCallback( runWaitingList );\n\t\t}\n\t};\n\n\t/**\n\t * Flushes queue for a given context, returning true if the flush was\n\t * performed, or false if there is no queue for the given context.\n\t *\n\t * @param {WPPriorityQueueContext} element Context object.\n\t *\n\t * @return {boolean} Whether flush was performed.\n\t */\n\tconst flush: WPPriorityQueue[ 'flush' ] = (\n\t\telement: WPPriorityQueueContext\n\t) => {\n\t\tconst callback = waitingList.get( element );\n\t\tif ( undefined === callback ) {\n\t\t\treturn false;\n\t\t}\n\n\t\twaitingList.delete( element );\n\t\tcallback();\n\n\t\treturn true;\n\t};\n\n\t/**\n\t * Clears the queue for a given context, cancelling the callbacks without\n\t * executing them. Returns `true` if there were scheduled callbacks to cancel,\n\t * or `false` if there was is no queue for the given context.\n\t *\n\t * @param {WPPriorityQueueContext} element Context object.\n\t *\n\t * @return {boolean} Whether any callbacks got cancelled.\n\t */\n\tconst cancel: WPPriorityQueue[ 'cancel' ] = (\n\t\telement: WPPriorityQueueContext\n\t) => {\n\t\treturn waitingList.delete( element );\n\t};\n\n\t/**\n\t * Reset the queue without running the pending callbacks.\n\t */\n\tconst reset: WPPriorityQueue[ 'reset' ] = () => {\n\t\twaitingList.clear();\n\t\tisRunning = false;\n\t};\n\n\treturn {\n\t\tadd,\n\t\tflush,\n\t\tcancel,\n\t\treset,\n\t};\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mCAAgC;AAgEzB,MAAM,cAAc,MAAuB;AACjD,QAAM,cAAc,oBAAI,IAGtB;AACF,MAAI,YAAY;AAkBhB,QAAM,iBAAiB,CAAE,aAA2C;AACnE,eAAY,CAAE,aAAa,QAAS,KAAK,aAAc;AACtD,kBAAY,OAAQ,WAAY;AAChC,eAAS;AAET,UACC,aAAa,OAAO,YACpB,SAAS,cAAc,KAAK,GAC3B;AACD;AAAA,MACD;AAAA,IACD;AAEA,QAAK,YAAY,SAAS,GAAI;AAC7B,kBAAY;AACZ;AAAA,IACD;AAEA,qCAAAA,SAAqB,cAAe;AAAA,EACrC;AAaA,QAAM,MAAgC,CACrC,SACA,SACI;AACJ,gBAAY,IAAK,SAAS,IAAK;AAC/B,QAAK,CAAE,WAAY;AAClB,kBAAY;AACZ,uCAAAA,SAAqB,cAAe;AAAA,IACrC;AAAA,EACD;AAUA,QAAM,QAAoC,CACzC,YACI;AACJ,UAAM,WAAW,YAAY,IAAK,OAAQ;AAC1C,QAAK,WAAc,UAAW;AAC7B,aAAO;AAAA,IACR;AAEA,gBAAY,OAAQ,OAAQ;AAC5B,aAAS;AAET,WAAO;AAAA,EACR;AAWA,QAAM,SAAsC,CAC3C,YACI;AACJ,WAAO,YAAY,OAAQ,OAAQ;AAAA,EACpC;AAKA,QAAM,QAAoC,MAAM;AAC/C,gBAAY,MAAM;AAClB,gBAAY;AAAA,EACb;AAEA,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
|
+
"names": ["requestIdleCallback"]
|
|
7
|
+
}
|
|
@@ -1,29 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var request_idle_callback_exports = {};
|
|
20
|
+
__export(request_idle_callback_exports, {
|
|
21
|
+
createRequestIdleCallback: () => createRequestIdleCallback,
|
|
22
|
+
default: () => request_idle_callback_default
|
|
5
23
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
require("requestidlecallback");
|
|
9
|
-
/**
|
|
10
|
-
* External dependencies
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Internal dependencies
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @return A function that schedules a callback when the browser is idle or via setTimeout on the server.
|
|
19
|
-
*/
|
|
24
|
+
module.exports = __toCommonJS(request_idle_callback_exports);
|
|
25
|
+
var import_requestidlecallback = require("requestidlecallback");
|
|
20
26
|
function createRequestIdleCallback() {
|
|
21
|
-
if (typeof window ===
|
|
22
|
-
return callback => {
|
|
27
|
+
if (typeof window === "undefined") {
|
|
28
|
+
return (callback) => {
|
|
23
29
|
setTimeout(() => callback(Date.now()), 0);
|
|
24
30
|
};
|
|
25
31
|
}
|
|
26
32
|
return window.requestIdleCallback;
|
|
27
33
|
}
|
|
28
|
-
var
|
|
29
|
-
|
|
34
|
+
var request_idle_callback_default = createRequestIdleCallback();
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
createRequestIdleCallback
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=request-idle-callback.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/request-idle-callback.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport 'requestidlecallback';\n\n/**\n * Internal dependencies\n */\nimport type { RequestIdleCallbackCallback } from './types';\n\n/**\n * @return A function that schedules a callback when the browser is idle or via setTimeout on the server.\n */\nexport function createRequestIdleCallback() {\n\tif ( typeof window === 'undefined' ) {\n\t\treturn ( callback: RequestIdleCallbackCallback ) => {\n\t\t\tsetTimeout( () => callback( Date.now() ), 0 );\n\t\t};\n\t}\n\n\treturn window.requestIdleCallback;\n}\n\nexport default createRequestIdleCallback();\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iCAAO;AAUA,SAAS,4BAA4B;AAC3C,MAAK,OAAO,WAAW,aAAc;AACpC,WAAO,CAAE,aAA2C;AACnD,iBAAY,MAAM,SAAU,KAAK,IAAI,CAAE,GAAG,CAAE;AAAA,IAC7C;AAAA,EACD;AAEA,SAAO,OAAO;AACf;AAEA,IAAO,gCAAQ,0BAA0B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build/types.js
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
17
|
+
//# sourceMappingURL=types.js.map
|
package/build/types.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/types.ts"],
|
|
4
|
+
"sourcesContent": ["export type RequestIdleCallbackCallback = (\n\t/**\n\t * @param timeOrDeadline - IdleDeadline object or a timestamp number.\n\t */\n\ttimeOrDeadline: IdleDeadline | number\n) => void;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build-module/index.js
CHANGED
|
@@ -1,67 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
import requestIdleCallback from './request-idle-callback';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Enqueued callback to invoke once idle time permits.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* An object used to associate callbacks in a particular context grouping.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Interface for the priority queue instance.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Creates a context-aware queue that only executes
|
|
20
|
-
* the last task of a given context.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
*```js
|
|
24
|
-
* import { createQueue } from '@wordpress/priority-queue';
|
|
25
|
-
*
|
|
26
|
-
* const queue = createQueue();
|
|
27
|
-
*
|
|
28
|
-
* // Context objects.
|
|
29
|
-
* const ctx1 = {};
|
|
30
|
-
* const ctx2 = {};
|
|
31
|
-
*
|
|
32
|
-
* // For a given context in the queue, only the last callback is executed.
|
|
33
|
-
* queue.add( ctx1, () => console.log( 'This will be printed first' ) );
|
|
34
|
-
* queue.add( ctx2, () => console.log( 'This won\'t be printed' ) );
|
|
35
|
-
* queue.add( ctx2, () => console.log( 'This will be printed second' ) );
|
|
36
|
-
*```
|
|
37
|
-
*
|
|
38
|
-
* @return {WPPriorityQueue} Queue object with `add`, `flush` and `reset` methods.
|
|
39
|
-
*/
|
|
40
|
-
export const createQueue = () => {
|
|
41
|
-
const waitingList = new Map();
|
|
1
|
+
import requestIdleCallback from "./request-idle-callback";
|
|
2
|
+
const createQueue = () => {
|
|
3
|
+
const waitingList = /* @__PURE__ */ new Map();
|
|
42
4
|
let isRunning = false;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Callback to process as much queue as time permits.
|
|
46
|
-
*
|
|
47
|
-
* Map Iteration follows the original insertion order. This means that here
|
|
48
|
-
* we can iterate the queue and know that the first contexts which were
|
|
49
|
-
* added will be run first. On the other hand, if anyone adds a new callback
|
|
50
|
-
* for an existing context it will supplant the previously-set callback for
|
|
51
|
-
* that context because we reassigned that map key's value.
|
|
52
|
-
*
|
|
53
|
-
* In the case that a callback adds a new callback to its own context then
|
|
54
|
-
* the callback it adds will appear at the end of the iteration and will be
|
|
55
|
-
* run only after all other existing contexts have finished executing.
|
|
56
|
-
*
|
|
57
|
-
* @param {IdleDeadline|number} deadline Idle callback deadline object, or
|
|
58
|
-
* animation frame timestamp.
|
|
59
|
-
*/
|
|
60
|
-
const runWaitingList = deadline => {
|
|
5
|
+
const runWaitingList = (deadline) => {
|
|
61
6
|
for (const [nextElement, callback] of waitingList) {
|
|
62
7
|
waitingList.delete(nextElement);
|
|
63
8
|
callback();
|
|
64
|
-
if (
|
|
9
|
+
if ("number" === typeof deadline || deadline.timeRemaining() <= 0) {
|
|
65
10
|
break;
|
|
66
11
|
}
|
|
67
12
|
}
|
|
@@ -71,18 +16,6 @@ export const createQueue = () => {
|
|
|
71
16
|
}
|
|
72
17
|
requestIdleCallback(runWaitingList);
|
|
73
18
|
};
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Add a callback to the queue for a given context.
|
|
77
|
-
*
|
|
78
|
-
* If errors with undefined callbacks are encountered double check that
|
|
79
|
-
* all of your useSelect calls have the right dependencies set correctly
|
|
80
|
-
* in their second parameter. Missing dependencies can cause unexpected
|
|
81
|
-
* loops and race conditions in the queue.
|
|
82
|
-
*
|
|
83
|
-
* @param {WPPriorityQueueContext} element Context object.
|
|
84
|
-
* @param {WPPriorityQueueCallback} item Callback function.
|
|
85
|
-
*/
|
|
86
19
|
const add = (element, item) => {
|
|
87
20
|
waitingList.set(element, item);
|
|
88
21
|
if (!isRunning) {
|
|
@@ -90,41 +23,18 @@ export const createQueue = () => {
|
|
|
90
23
|
requestIdleCallback(runWaitingList);
|
|
91
24
|
}
|
|
92
25
|
};
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Flushes queue for a given context, returning true if the flush was
|
|
96
|
-
* performed, or false if there is no queue for the given context.
|
|
97
|
-
*
|
|
98
|
-
* @param {WPPriorityQueueContext} element Context object.
|
|
99
|
-
*
|
|
100
|
-
* @return {boolean} Whether flush was performed.
|
|
101
|
-
*/
|
|
102
|
-
const flush = element => {
|
|
26
|
+
const flush = (element) => {
|
|
103
27
|
const callback = waitingList.get(element);
|
|
104
|
-
if (
|
|
28
|
+
if (void 0 === callback) {
|
|
105
29
|
return false;
|
|
106
30
|
}
|
|
107
31
|
waitingList.delete(element);
|
|
108
32
|
callback();
|
|
109
33
|
return true;
|
|
110
34
|
};
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Clears the queue for a given context, cancelling the callbacks without
|
|
114
|
-
* executing them. Returns `true` if there were scheduled callbacks to cancel,
|
|
115
|
-
* or `false` if there was is no queue for the given context.
|
|
116
|
-
*
|
|
117
|
-
* @param {WPPriorityQueueContext} element Context object.
|
|
118
|
-
*
|
|
119
|
-
* @return {boolean} Whether any callbacks got cancelled.
|
|
120
|
-
*/
|
|
121
|
-
const cancel = element => {
|
|
35
|
+
const cancel = (element) => {
|
|
122
36
|
return waitingList.delete(element);
|
|
123
37
|
};
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Reset the queue without running the pending callbacks.
|
|
127
|
-
*/
|
|
128
38
|
const reset = () => {
|
|
129
39
|
waitingList.clear();
|
|
130
40
|
isRunning = false;
|
|
@@ -136,4 +46,7 @@ export const createQueue = () => {
|
|
|
136
46
|
reset
|
|
137
47
|
};
|
|
138
48
|
};
|
|
139
|
-
|
|
49
|
+
export {
|
|
50
|
+
createQueue
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport requestIdleCallback from './request-idle-callback';\n\n/**\n * Enqueued callback to invoke once idle time permits.\n */\nexport type WPPriorityQueueCallback = VoidFunction;\n\n/**\n * An object used to associate callbacks in a particular context grouping.\n */\nexport type WPPriorityQueueContext = object;\n\n/**\n * Interface for the priority queue instance.\n */\nexport interface WPPriorityQueue {\n\t/**\n\t * Add a callback to the queue for a given context.\n\t */\n\tadd: (\n\t\telement: WPPriorityQueueContext,\n\t\titem: WPPriorityQueueCallback\n\t) => void;\n\n\t/**\n\t * Flush and run the callback for a given context immediately.\n\t * @return true if a callback was run, false otherwise.\n\t */\n\tflush: ( element: WPPriorityQueueContext ) => boolean;\n\n\t/**\n\t * Cancel (remove) the callback for a given context without running it.\n\t * @return true if a callback was cancelled, false otherwise.\n\t */\n\tcancel: ( element: WPPriorityQueueContext ) => boolean;\n\n\t/**\n\t * Reset the entire queue, clearing pending callbacks.\n\t */\n\treset: VoidFunction;\n}\n\n/**\n * Creates a context-aware queue that only executes\n * the last task of a given context.\n *\n * @example\n *```js\n * import { createQueue } from '@wordpress/priority-queue';\n *\n * const queue = createQueue();\n *\n * // Context objects.\n * const ctx1 = {};\n * const ctx2 = {};\n *\n * // For a given context in the queue, only the last callback is executed.\n * queue.add( ctx1, () => console.log( 'This will be printed first' ) );\n * queue.add( ctx2, () => console.log( 'This won\\'t be printed' ) );\n * queue.add( ctx2, () => console.log( 'This will be printed second' ) );\n *```\n *\n * @return {WPPriorityQueue} Queue object with `add`, `flush` and `reset` methods.\n */\nexport const createQueue = (): WPPriorityQueue => {\n\tconst waitingList = new Map<\n\t\tWPPriorityQueueContext,\n\t\tWPPriorityQueueCallback\n\t>();\n\tlet isRunning = false;\n\n\t/**\n\t * Callback to process as much queue as time permits.\n\t *\n\t * Map Iteration follows the original insertion order. This means that here\n\t * we can iterate the queue and know that the first contexts which were\n\t * added will be run first. On the other hand, if anyone adds a new callback\n\t * for an existing context it will supplant the previously-set callback for\n\t * that context because we reassigned that map key's value.\n\t *\n\t * In the case that a callback adds a new callback to its own context then\n\t * the callback it adds will appear at the end of the iteration and will be\n\t * run only after all other existing contexts have finished executing.\n\t *\n\t * @param {IdleDeadline|number} deadline Idle callback deadline object, or\n\t * animation frame timestamp.\n\t */\n\tconst runWaitingList = ( deadline: IdleDeadline | number ): void => {\n\t\tfor ( const [ nextElement, callback ] of waitingList ) {\n\t\t\twaitingList.delete( nextElement );\n\t\t\tcallback();\n\n\t\t\tif (\n\t\t\t\t'number' === typeof deadline ||\n\t\t\t\tdeadline.timeRemaining() <= 0\n\t\t\t) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tif ( waitingList.size === 0 ) {\n\t\t\tisRunning = false;\n\t\t\treturn;\n\t\t}\n\n\t\trequestIdleCallback( runWaitingList );\n\t};\n\n\t/**\n\t * Add a callback to the queue for a given context.\n\t *\n\t * If errors with undefined callbacks are encountered double check that\n\t * all of your useSelect calls have the right dependencies set correctly\n\t * in their second parameter. Missing dependencies can cause unexpected\n\t * loops and race conditions in the queue.\n\t *\n\t * @param {WPPriorityQueueContext} element Context object.\n\t * @param {WPPriorityQueueCallback} item Callback function.\n\t */\n\tconst add: WPPriorityQueue[ 'add' ] = (\n\t\telement: WPPriorityQueueContext,\n\t\titem: WPPriorityQueueCallback\n\t) => {\n\t\twaitingList.set( element, item );\n\t\tif ( ! isRunning ) {\n\t\t\tisRunning = true;\n\t\t\trequestIdleCallback( runWaitingList );\n\t\t}\n\t};\n\n\t/**\n\t * Flushes queue for a given context, returning true if the flush was\n\t * performed, or false if there is no queue for the given context.\n\t *\n\t * @param {WPPriorityQueueContext} element Context object.\n\t *\n\t * @return {boolean} Whether flush was performed.\n\t */\n\tconst flush: WPPriorityQueue[ 'flush' ] = (\n\t\telement: WPPriorityQueueContext\n\t) => {\n\t\tconst callback = waitingList.get( element );\n\t\tif ( undefined === callback ) {\n\t\t\treturn false;\n\t\t}\n\n\t\twaitingList.delete( element );\n\t\tcallback();\n\n\t\treturn true;\n\t};\n\n\t/**\n\t * Clears the queue for a given context, cancelling the callbacks without\n\t * executing them. Returns `true` if there were scheduled callbacks to cancel,\n\t * or `false` if there was is no queue for the given context.\n\t *\n\t * @param {WPPriorityQueueContext} element Context object.\n\t *\n\t * @return {boolean} Whether any callbacks got cancelled.\n\t */\n\tconst cancel: WPPriorityQueue[ 'cancel' ] = (\n\t\telement: WPPriorityQueueContext\n\t) => {\n\t\treturn waitingList.delete( element );\n\t};\n\n\t/**\n\t * Reset the queue without running the pending callbacks.\n\t */\n\tconst reset: WPPriorityQueue[ 'reset' ] = () => {\n\t\twaitingList.clear();\n\t\tisRunning = false;\n\t};\n\n\treturn {\n\t\tadd,\n\t\tflush,\n\t\tcancel,\n\t\treset,\n\t};\n};\n"],
|
|
5
|
+
"mappings": "AAGA,OAAO,yBAAyB;AAgEzB,MAAM,cAAc,MAAuB;AACjD,QAAM,cAAc,oBAAI,IAGtB;AACF,MAAI,YAAY;AAkBhB,QAAM,iBAAiB,CAAE,aAA2C;AACnE,eAAY,CAAE,aAAa,QAAS,KAAK,aAAc;AACtD,kBAAY,OAAQ,WAAY;AAChC,eAAS;AAET,UACC,aAAa,OAAO,YACpB,SAAS,cAAc,KAAK,GAC3B;AACD;AAAA,MACD;AAAA,IACD;AAEA,QAAK,YAAY,SAAS,GAAI;AAC7B,kBAAY;AACZ;AAAA,IACD;AAEA,wBAAqB,cAAe;AAAA,EACrC;AAaA,QAAM,MAAgC,CACrC,SACA,SACI;AACJ,gBAAY,IAAK,SAAS,IAAK;AAC/B,QAAK,CAAE,WAAY;AAClB,kBAAY;AACZ,0BAAqB,cAAe;AAAA,IACrC;AAAA,EACD;AAUA,QAAM,QAAoC,CACzC,YACI;AACJ,UAAM,WAAW,YAAY,IAAK,OAAQ;AAC1C,QAAK,WAAc,UAAW;AAC7B,aAAO;AAAA,IACR;AAEA,gBAAY,OAAQ,OAAQ;AAC5B,aAAS;AAET,WAAO;AAAA,EACR;AAWA,QAAM,SAAsC,CAC3C,YACI;AACJ,WAAO,YAAY,OAAQ,OAAQ;AAAA,EACpC;AAKA,QAAM,QAAoC,MAAM;AAC/C,gBAAY,MAAM;AAClB,gBAAY;AAAA,EACb;AAEA,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @return A function that schedules a callback when the browser is idle or via setTimeout on the server.
|
|
12
|
-
*/
|
|
13
|
-
export function createRequestIdleCallback() {
|
|
14
|
-
if (typeof window === 'undefined') {
|
|
15
|
-
return callback => {
|
|
1
|
+
import "requestidlecallback";
|
|
2
|
+
function createRequestIdleCallback() {
|
|
3
|
+
if (typeof window === "undefined") {
|
|
4
|
+
return (callback) => {
|
|
16
5
|
setTimeout(() => callback(Date.now()), 0);
|
|
17
6
|
};
|
|
18
7
|
}
|
|
19
8
|
return window.requestIdleCallback;
|
|
20
9
|
}
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
var request_idle_callback_default = createRequestIdleCallback();
|
|
11
|
+
export {
|
|
12
|
+
createRequestIdleCallback,
|
|
13
|
+
request_idle_callback_default as default
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=request-idle-callback.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/request-idle-callback.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport 'requestidlecallback';\n\n/**\n * Internal dependencies\n */\nimport type { RequestIdleCallbackCallback } from './types';\n\n/**\n * @return A function that schedules a callback when the browser is idle or via setTimeout on the server.\n */\nexport function createRequestIdleCallback() {\n\tif ( typeof window === 'undefined' ) {\n\t\treturn ( callback: RequestIdleCallbackCallback ) => {\n\t\t\tsetTimeout( () => callback( Date.now() ), 0 );\n\t\t};\n\t}\n\n\treturn window.requestIdleCallback;\n}\n\nexport default createRequestIdleCallback();\n"],
|
|
5
|
+
"mappings": "AAGA,OAAO;AAUA,SAAS,4BAA4B;AAC3C,MAAK,OAAO,WAAW,aAAc;AACpC,WAAO,CAAE,aAA2C;AACnD,iBAAY,MAAM,SAAU,KAAK,IAAI,CAAE,GAAG,CAAE;AAAA,IAC7C;AAAA,EACD;AAEA,SAAO,OAAO;AACf;AAEA,IAAO,gCAAQ,0BAA0B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build-module/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=types.js.map
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": [],
|
|
4
|
+
"sourcesContent": [],
|
|
5
|
+
"mappings": "",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/priority-queue",
|
|
3
|
-
"version": "3.32.0",
|
|
3
|
+
"version": "3.32.1-next.ff1cebbba.0",
|
|
4
4
|
"description": "Generic browser priority queue.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -25,16 +25,23 @@
|
|
|
25
25
|
},
|
|
26
26
|
"main": "build/index.js",
|
|
27
27
|
"module": "build-module/index.js",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./build-types/index.d.ts",
|
|
31
|
+
"import": "./build-module/index.js",
|
|
32
|
+
"require": "./build/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
28
36
|
"react-native": "src/index",
|
|
29
37
|
"wpScript": true,
|
|
30
38
|
"types": "build-types",
|
|
31
39
|
"sideEffects": false,
|
|
32
40
|
"dependencies": {
|
|
33
|
-
"@babel/runtime": "7.25.7",
|
|
34
41
|
"requestidlecallback": "^0.3.0"
|
|
35
42
|
},
|
|
36
43
|
"publishConfig": {
|
|
37
44
|
"access": "public"
|
|
38
45
|
},
|
|
39
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "c5b659710aff01d40d2eb97b211eb2cec9c07d3b"
|
|
40
47
|
}
|