@payloadcms/ui 3.32.0-canary.2 → 3.32.0-internal.9f46ea6
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/dist/elements/Autosave/index.d.ts.map +1 -1
- package/dist/elements/Autosave/index.js +20 -42
- package/dist/elements/Autosave/index.js.map +1 -1
- package/dist/exports/client/index.js +23 -23
- package/dist/exports/client/index.js.map +3 -3
- package/dist/fields/Array/index.d.ts.map +1 -1
- package/dist/fields/Array/index.js +46 -50
- package/dist/fields/Array/index.js.map +1 -1
- package/dist/fields/Blocks/index.d.ts.map +1 -1
- package/dist/fields/Blocks/index.js +46 -50
- package/dist/fields/Blocks/index.js.map +1 -1
- package/dist/forms/Form/index.d.ts.map +1 -1
- package/dist/forms/Form/index.js +56 -17
- package/dist/forms/Form/index.js.map +1 -1
- package/dist/forms/Form/initContextState.d.ts.map +1 -1
- package/dist/forms/Form/initContextState.js +1 -0
- package/dist/forms/Form/initContextState.js.map +1 -1
- package/dist/forms/Form/mergeServerFormState.d.ts.map +1 -1
- package/dist/forms/Form/mergeServerFormState.js.map +1 -1
- package/dist/forms/Form/types.d.ts +5 -0
- package/dist/forms/Form/types.d.ts.map +1 -1
- package/dist/forms/Form/types.js.map +1 -1
- package/dist/hooks/useQueues.d.ts +50 -1
- package/dist/hooks/useQueues.d.ts.map +1 -1
- package/dist/hooks/useQueues.js +53 -29
- package/dist/hooks/useQueues.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQueues.d.ts","sourceRoot":"","sources":["../../src/hooks/useQueues.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"useQueues.d.ts","sourceRoot":"","sources":["../../src/hooks/useQueues.ts"],"names":[],"mappings":"AAEA,KAAK,UAAU,GAAG;IAChB,OAAO,CAAC,EAAE,WAAW,CAAC,SAAS,CAAC,CAAA;IAChC,EAAE,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;IAC9B,QAAQ,CAAC,EAAE,WAAW,CAAC,UAAU,CAAC,CAAA;CACnC,CAAA;AAED,KAAK,WAAW,GAAG;IACjB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,IAAI,CAAA;IACzB;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,OAAO,CAAA;IAC7B;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,KAAK,SAAS,GAAG,CAAC,EAAE,EAAE,UAAU,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,IAAI,CAAA;AAEtE;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,SAAS,IAAI;IAC3B,SAAS,EAAE,SAAS,CAAA;CACrB,CA0DA"}
|
package/dist/hooks/useQueues.js
CHANGED
|
@@ -1,40 +1,64 @@
|
|
|
1
1
|
import { useCallback, useRef } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* A React hook that allows you to queue up functions to be executed in order.
|
|
4
|
+
* This is useful when you need to ensure long running networks requests are processed sequentially.
|
|
5
|
+
* Builds up a "queue" of functions to be executed in order, only ever processing the last function in the queue.
|
|
6
|
+
* This ensures that a long queue of tasks doesn't cause a backlog of tasks to be processed.
|
|
7
|
+
* E.g. if you queue a task and it begins running, then you queue 9 more tasks:
|
|
8
|
+
* 1. The currently task will finish
|
|
9
|
+
* 2. The next task in the queue will run
|
|
10
|
+
* 3. All remaining tasks will be discarded
|
|
11
|
+
* @returns {queueTask} A function used to queue a function.
|
|
12
|
+
* @example
|
|
13
|
+
* const { queueTask } = useQueues()
|
|
14
|
+
* queueTask(async () => {
|
|
15
|
+
* await fetch('https://api.example.com')
|
|
16
|
+
* })
|
|
17
|
+
*/
|
|
2
18
|
export function useQueues() {
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
19
|
+
const queue = useRef([]);
|
|
20
|
+
const isProcessing = useRef(false);
|
|
21
|
+
const queueTask = useCallback((fn, options) => {
|
|
22
|
+
queue.current.push({
|
|
23
|
+
discard: options?.discard,
|
|
24
|
+
fn,
|
|
25
|
+
priority: options?.priority
|
|
26
|
+
});
|
|
27
|
+
async function processQueue() {
|
|
28
|
+
if (isProcessing.current) {
|
|
29
|
+
return;
|
|
13
30
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
31
|
+
// Allow the consumer to prevent the queue from processing under certain conditions
|
|
32
|
+
if (typeof options?.beforeProcess === 'function') {
|
|
33
|
+
const shouldContinue = options.beforeProcess();
|
|
34
|
+
if (shouldContinue === false) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
while (queue.current.length > 0) {
|
|
39
|
+
// Only process the latest, prioritized task in the queue
|
|
40
|
+
const latestTask = queue.current.find(task => task.priority) || queue.current.pop();
|
|
41
|
+
// This task is about to run, so remove the discard option if it exists
|
|
42
|
+
if ('discard' in latestTask) {
|
|
43
|
+
latestTask.discard = undefined;
|
|
44
|
+
}
|
|
45
|
+
// Discard all other tasks that are not explicitly set to not be discarded
|
|
46
|
+
queue.current = queue.current.filter(task => task.discard === false);
|
|
47
|
+
isProcessing.current = true;
|
|
23
48
|
try {
|
|
24
|
-
|
|
25
|
-
await runningTaskRef.current // Wait for the task to complete
|
|
26
|
-
;
|
|
49
|
+
await latestTask.fn();
|
|
27
50
|
} catch (err) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
;
|
|
31
|
-
}
|
|
51
|
+
console.error('Error in queued function:', err) // eslint-disable-line no-console
|
|
52
|
+
;
|
|
32
53
|
} finally {
|
|
33
|
-
|
|
54
|
+
isProcessing.current = false;
|
|
55
|
+
if (typeof options?.afterProcess === 'function') {
|
|
56
|
+
options.afterProcess();
|
|
57
|
+
}
|
|
34
58
|
}
|
|
35
59
|
}
|
|
36
|
-
}
|
|
37
|
-
void
|
|
60
|
+
}
|
|
61
|
+
void processQueue();
|
|
38
62
|
}, []);
|
|
39
63
|
return {
|
|
40
64
|
queueTask
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQueues.js","names":["useCallback","useRef","useQueues","
|
|
1
|
+
{"version":3,"file":"useQueues.js","names":["useCallback","useRef","useQueues","queue","isProcessing","queueTask","fn","options","current","push","discard","priority","processQueue","beforeProcess","shouldContinue","length","latestTask","find","task","pop","undefined","filter","err","console","error","afterProcess"],"sources":["../../src/hooks/useQueues.ts"],"sourcesContent":["import { useCallback, useRef } from 'react'\n\ntype QueuedTask = {\n discard?: TaskOptions['discard']\n fn: () => Promise<void> | void\n priority?: TaskOptions['priority']\n}\n\ntype TaskOptions = {\n /**\n * A function that is called after the queue has processed a function\n * Used to perform side effects after processing the queue\n * @returns {void}\n */\n afterProcess?: () => void\n /**\n * A function that can be used to prevent the queue from processing under certain conditions\n * Can also be used to perform side effects before processing the queue\n * @returns {boolean} If `false`, the queue will not process\n */\n beforeProcess?: () => boolean\n /**\n * All tasks that except the last task in the queue will be discarded to prevent a backlog.\n * To ensure a task is not discarded, set the `discard` option to `false`\n * @default undefined\n */\n discard?: boolean\n /**\n * Priority tasks will be processed before non-priority tasks\n * This is helpful to ensure a task added later in the queue is processed first\n * @default false\n */\n priority?: boolean\n}\n\ntype QueueTask = (fn: QueuedTask['fn'], options?: TaskOptions) => void\n\n/**\n * A React hook that allows you to queue up functions to be executed in order.\n * This is useful when you need to ensure long running networks requests are processed sequentially.\n * Builds up a \"queue\" of functions to be executed in order, only ever processing the last function in the queue.\n * This ensures that a long queue of tasks doesn't cause a backlog of tasks to be processed.\n * E.g. if you queue a task and it begins running, then you queue 9 more tasks:\n * 1. The currently task will finish\n * 2. The next task in the queue will run\n * 3. All remaining tasks will be discarded\n * @returns {queueTask} A function used to queue a function.\n * @example\n * const { queueTask } = useQueues()\n * queueTask(async () => {\n * await fetch('https://api.example.com')\n * })\n */\nexport function useQueues(): {\n queueTask: QueueTask\n} {\n const queue = useRef<QueuedTask[]>([])\n\n const isProcessing = useRef(false)\n\n const queueTask = useCallback<QueueTask>((fn, options) => {\n queue.current.push({\n discard: options?.discard,\n fn,\n priority: options?.priority,\n })\n\n async function processQueue() {\n if (isProcessing.current) {\n return\n }\n\n // Allow the consumer to prevent the queue from processing under certain conditions\n if (typeof options?.beforeProcess === 'function') {\n const shouldContinue = options.beforeProcess()\n\n if (shouldContinue === false) {\n return\n }\n }\n\n while (queue.current.length > 0) {\n // Only process the latest, prioritized task in the queue\n const latestTask = queue.current.find((task) => task.priority) || queue.current.pop()\n\n // This task is about to run, so remove the discard option if it exists\n if ('discard' in latestTask) {\n latestTask.discard = undefined\n }\n\n // Discard all other tasks that are not explicitly set to not be discarded\n queue.current = queue.current.filter((task) => task.discard === false)\n\n isProcessing.current = true\n\n try {\n await latestTask.fn()\n } catch (err) {\n console.error('Error in queued function:', err) // eslint-disable-line no-console\n } finally {\n isProcessing.current = false\n\n if (typeof options?.afterProcess === 'function') {\n options.afterProcess()\n }\n }\n }\n }\n\n void processQueue()\n }, [])\n\n return { queueTask }\n}\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,MAAM,QAAQ;AAqCpC;;;;;;;;;;;;;;;;AAgBA,OAAO,SAASC,UAAA;EAGd,MAAMC,KAAA,GAAQF,MAAA,CAAqB,EAAE;EAErC,MAAMG,YAAA,GAAeH,MAAA,CAAO;EAE5B,MAAMI,SAAA,GAAYL,WAAA,CAAuB,CAACM,EAAA,EAAIC,OAAA;IAC5CJ,KAAA,CAAMK,OAAO,CAACC,IAAI,CAAC;MACjBC,OAAA,EAASH,OAAA,EAASG,OAAA;MAClBJ,EAAA;MACAK,QAAA,EAAUJ,OAAA,EAASI;IACrB;IAEA,eAAeC,aAAA;MACb,IAAIR,YAAA,CAAaI,OAAO,EAAE;QACxB;MACF;MAEA;MACA,IAAI,OAAOD,OAAA,EAASM,aAAA,KAAkB,YAAY;QAChD,MAAMC,cAAA,GAAiBP,OAAA,CAAQM,aAAa;QAE5C,IAAIC,cAAA,KAAmB,OAAO;UAC5B;QACF;MACF;MAEA,OAAOX,KAAA,CAAMK,OAAO,CAACO,MAAM,GAAG,GAAG;QAC/B;QACA,MAAMC,UAAA,GAAab,KAAA,CAAMK,OAAO,CAACS,IAAI,CAAEC,IAAA,IAASA,IAAA,CAAKP,QAAQ,KAAKR,KAAA,CAAMK,OAAO,CAACW,GAAG;QAEnF;QACA,IAAI,aAAaH,UAAA,EAAY;UAC3BA,UAAA,CAAWN,OAAO,GAAGU,SAAA;QACvB;QAEA;QACAjB,KAAA,CAAMK,OAAO,GAAGL,KAAA,CAAMK,OAAO,CAACa,MAAM,CAAEH,IAAA,IAASA,IAAA,CAAKR,OAAO,KAAK;QAEhEN,YAAA,CAAaI,OAAO,GAAG;QAEvB,IAAI;UACF,MAAMQ,UAAA,CAAWV,EAAE;QACrB,EAAE,OAAOgB,GAAA,EAAK;UACZC,OAAA,CAAQC,KAAK,CAAC,6BAA6BF,GAAA,EAAK;UAAA;QAClD,UAAU;UACRlB,YAAA,CAAaI,OAAO,GAAG;UAEvB,IAAI,OAAOD,OAAA,EAASkB,YAAA,KAAiB,YAAY;YAC/ClB,OAAA,CAAQkB,YAAY;UACtB;QACF;MACF;IACF;IAEA,KAAKb,YAAA;EACP,GAAG,EAAE;EAEL,OAAO;IAAEP;EAAU;AACrB","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/ui",
|
|
3
|
-
"version": "3.32.0-
|
|
3
|
+
"version": "3.32.0-internal.9f46ea6",
|
|
4
4
|
"homepage": "https://payloadcms.com",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -132,7 +132,7 @@
|
|
|
132
132
|
"ts-essentials": "10.0.3",
|
|
133
133
|
"use-context-selector": "2.0.0",
|
|
134
134
|
"uuid": "10.0.0",
|
|
135
|
-
"@payloadcms/translations": "3.32.0-
|
|
135
|
+
"@payloadcms/translations": "3.32.0-internal.9f46ea6"
|
|
136
136
|
},
|
|
137
137
|
"devDependencies": {
|
|
138
138
|
"@babel/cli": "7.26.4",
|
|
@@ -149,13 +149,13 @@
|
|
|
149
149
|
"esbuild-sass-plugin": "3.3.1",
|
|
150
150
|
"eslint-plugin-react-compiler": "19.0.0-beta-714736e-20250131",
|
|
151
151
|
"@payloadcms/eslint-config": "3.28.0",
|
|
152
|
-
"payload": "3.32.0-
|
|
152
|
+
"payload": "3.32.0-internal.9f46ea6"
|
|
153
153
|
},
|
|
154
154
|
"peerDependencies": {
|
|
155
155
|
"next": "^15.2.3",
|
|
156
156
|
"react": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",
|
|
157
157
|
"react-dom": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",
|
|
158
|
-
"payload": "3.32.0-
|
|
158
|
+
"payload": "3.32.0-internal.9f46ea6"
|
|
159
159
|
},
|
|
160
160
|
"engines": {
|
|
161
161
|
"node": "^18.20.2 || >=20.9.0"
|