@workflow/web 5.1.0 → 5.2.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.
Files changed (29) hide show
  1. package/build/client/assets/app-DSMA-d-h.css +1 -0
  2. package/build/client/assets/{arrow-up-right-KWrqnTig.js → arrow-up-right-Cpa3Pdwo.js} +1 -1
  3. package/build/client/assets/{highlighted-body-JLMTFACH-DcETTNIg.js → highlighted-body-JLMTFACH-B3GqULNn.js} +1 -1
  4. package/build/client/assets/{home-DXDIbwXs.js → home-D79hgIWW.js} +18 -1412
  5. package/build/client/assets/{loader-circle-CTGjdS9p.js → loader-circle-JR85kUd5.js} +1 -1
  6. package/build/client/assets/manifest-59ebdf79.js +1 -0
  7. package/build/client/assets/{mermaid-WFAXDIZX-C05IxJpM.js → mermaid-WFAXDIZX-CWiYj6ob.js} +21920 -21866
  8. package/build/client/assets/root-Cv68eh5c.css +1 -0
  9. package/build/client/assets/{root-BxCk7uqa.js → root-DgYJfBXO.js} +24 -9
  10. package/build/client/assets/{run-detail-CZBOEgvx.js → run-detail-Befe_Bls.js} +1868 -1952
  11. package/build/client/assets/{index-DsOfMZH2.js → url-state-DtiYSmtM.js} +1520 -95
  12. package/build/client/assets/{zstd-browser-decoder-DADxxRqK.js → zstd-browser-decoder-feFoAFP-.js} +1 -1
  13. package/build/server/assets/{app-DT6Gt-BX.js → app-BXJVj0oU.js} +22544 -25746
  14. package/build/server/assets/{highlighted-body-JLMTFACH-CHR6of_B.js → highlighted-body-JLMTFACH-DBscEG8Y.js} +2 -4
  15. package/build/server/assets/{index-puMiLsWF.js → index-DFAOTIzy.js} +276 -87
  16. package/build/server/assets/{mermaid-WFAXDIZX-D-xr2vKt.js → mermaid-WFAXDIZX-hv3921YS.js} +2 -4
  17. package/build/server/assets/{token-D41jJA1K.js → token-BPk8AzMN.js} +2 -2
  18. package/build/server/assets/{token-CwT5ChW-.js → token-CXneDSmI.js} +1 -1
  19. package/build/server/assets/{token-util-DqfRGa3d.js → token-util-C_CN233b.js} +1 -1
  20. package/build/server/assets/{token-util-BJpBdFnQ.js → token-util-lTSClVuJ.js} +2 -2
  21. package/build/server/assets/{wrapper-Cr0R902L.js → wrapper-CaZIHABu.js} +10 -12
  22. package/build/server/assets/{zstd-browser-decoder-B48pzCro.js → zstd-browser-decoder-XCzFkM-Z.js} +2 -4
  23. package/build/server/index.js +3 -5
  24. package/package.json +10 -10
  25. package/build/client/assets/app-C_84j2Id.css +0 -1
  26. package/build/client/assets/manifest-d238ca03.js +0 -1
  27. package/build/client/assets/root-DUrWgRk7.css +0 -1
  28. package/build/server/assets/dist-BQmT5wQz.js +0 -210
  29. /package/build/client/assets/{index-C9ccOmbh.css → url-state-C9ccOmbh.css} +0 -0
@@ -9,8 +9,8 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
9
9
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
10
10
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
11
11
  var _keys, _a;
12
- import { c as createLucideIcon, L as ChevronDown, a0 as cn, al as isRunCreationEvent, bj as startHookId, aj as isHookLifecycleEventType, e as cn$1, Q as cva, o as useComposedRefs, x as createContextScope, K as createSlot, p as useLayoutEffect2, s as useId, P as Primitive, z as composeEventHandlers, q as useControllableState, J as useCallbackRef$1, w as createPopperScope, v as Popper, y as PopperAnchor, E as Presence, A as Portal, bk as dispatchDiscreteCustomEvent, bl as useFocusScopeBranch, bm as useFocusScopeBranchRegistry, bn as FocusScopeBranchProvider, F as FocusScope, G as DismissableLayer, H as PopperContent, m as ChevronRight, C as Check, bo as VERCEL_403_ERROR_MESSAGE, bp as bulkCancelRuns$1, bq as reenqueueRun$1, br as wakeUpRun$1, bs as resumeHook$1, bt as fetchHookToken$1, bu as cancelRun$1, bv as recreateRun$1, T as Tooltip, a as TooltipTrigger, l as Copy, b as TooltipContent, ag as formatDuration, B as Button, t as toast, bw as useDismissableLayerSurface } from "./mermaid-WFAXDIZX-C05IxJpM.js";
13
- import { r as reactExports, j as jsxRuntimeExports, E as React2, a as requireReact, G as getDefaultExportFromCjs, R as ReactExports, f as reactDomExports } from "./index-BS6T0Zjc.js";
12
+ import { c as createLucideIcon, K as ChevronDown, a6 as cn, a5 as isRunCreationEvent, bj as startHookId, a2 as isHookLifecycleEventType, e as cn$1, O as cva, n as useComposedRefs, w as createContextScope, J as createSlot, o as useLayoutEffect2, q as useId, P as Primitive, y as composeEventHandlers, p as useControllableState, H as useCallbackRef$1, v as createPopperScope, s as Popper, x as PopperAnchor, A as Presence, z as Portal, bk as dispatchDiscreteCustomEvent, bl as useFocusScopeBranch, bm as useFocusScopeBranchRegistry, bn as FocusScopeBranchProvider, F as FocusScope, E as DismissableLayer, G as PopperContent, l as ChevronRight, C as Check, bo as VERCEL_403_ERROR_MESSAGE, bp as fetchRuns, bq as bulkCancelRuns$1, br as reenqueueRun$1, bs as wakeUpRun$1, bt as resumeHook$1, bu as fetchHookToken$1, bv as cancelRun$1, bw as recreateRun$1, T as Tooltip, a as TooltipTrigger, k as Copy, b as TooltipContent, bx as formatDuration, B as Button, t as toast, by as useDismissableLayerSurface } from "./mermaid-WFAXDIZX-CWiYj6ob.js";
13
+ import { r as reactExports, j as jsxRuntimeExports, E as React2, a as requireReact, R as ReactExports, G as getDefaultExportFromCjs, f as reactDomExports, B as useSearchParams, A as useNavigate } from "./index-BS6T0Zjc.js";
14
14
  function parseName(tag, name) {
15
15
  if (typeof name !== "string") {
16
16
  return null;
@@ -218,7 +218,7 @@ const __iconNode = [
218
218
  const Zap = createLucideIcon("zap", __iconNode);
219
219
  function ErrorCard({ title, className, details = "Unknown error" }) {
220
220
  const [isExpanded, setIsExpanded] = reactExports.useState(false);
221
- return jsxRuntimeExports.jsx("div", { className: "flex justify-center w-full", children: jsxRuntimeExports.jsxs("div", { className: cn("rounded-lg border border-red-400 w-full max-w-[800px]", className), style: { background: "var(--ds-red-100)" }, children: [jsxRuntimeExports.jsxs("button", { type: "button", onClick: () => setIsExpanded(!isExpanded), className: "w-full px-4 py-3 flex items-center justify-between gap-2 text-left transition-colors", style: { color: "var(--ds-red-900)" }, children: [jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2", children: [jsxRuntimeExports.jsx(CircleAlert, { className: "h-4 w-4 shrink-0" }), jsxRuntimeExports.jsx("span", { className: "font-medium text-label-14", children: title })] }), jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-1.5 opacity-70", children: [jsxRuntimeExports.jsx("span", { className: "text-label-12", children: "Click to show details" }), jsxRuntimeExports.jsx(ChevronDown, { className: cn("h-4 w-4 transition-transform duration-200", isExpanded && "rotate-180") })] })] }), isExpanded && details && jsxRuntimeExports.jsx("div", { className: "px-4 pb-3", style: { borderTop: "1px solid var(--ds-red-400)" }, children: jsxRuntimeExports.jsx("pre", { className: "mt-3 p-3 rounded-md text-label-12-mono whitespace-pre-wrap break-words overflow-auto", style: {
221
+ return jsxRuntimeExports.jsx("div", { className: "flex justify-center w-full", children: jsxRuntimeExports.jsxs("div", { className: cn("rounded-lg border border-red-400 w-full max-w-[800px]", className), style: { background: "var(--ds-red-100)" }, children: [jsxRuntimeExports.jsxs("button", { type: "button", onClick: () => setIsExpanded(!isExpanded), className: "w-full px-4 py-3 flex items-center justify-between gap-2 text-left transition-colors", style: { color: "var(--ds-red-900)" }, children: [jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2", children: [jsxRuntimeExports.jsx(CircleAlert, { className: "h-4 w-4 shrink-0" }), jsxRuntimeExports.jsx("span", { className: "font-medium text-label-14", children: title })] }), jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-1.5 text-red-800", children: [jsxRuntimeExports.jsx("span", { className: "text-label-12", children: "Click to show details" }), jsxRuntimeExports.jsx(ChevronDown, { className: cn("h-4 w-4 transition-transform duration-200", isExpanded && "rotate-180") })] })] }), isExpanded && details && jsxRuntimeExports.jsx("div", { className: "px-4 pb-3", style: { borderTop: "1px solid var(--ds-red-400)" }, children: jsxRuntimeExports.jsx("pre", { className: "mt-3 p-3 rounded-md text-label-12-mono whitespace-pre-wrap break-words overflow-auto", style: {
222
222
  background: "var(--ds-red-200)",
223
223
  color: "var(--ds-red-900)"
224
224
  }, children: details }) })] }) });
@@ -252,6 +252,39 @@ ${err.stack}` : (err == null ? void 0 : err.message) ?? "Unknown error";
252
252
  return this.props.children;
253
253
  }
254
254
  }
255
+ function eventTimestamp(event) {
256
+ const value = (event == null ? void 0 : event.occurredAt) ?? (event == null ? void 0 : event.createdAt);
257
+ if (!value)
258
+ return void 0;
259
+ const date2 = value instanceof Date ? value : new Date(value);
260
+ return Number.isNaN(date2.getTime()) ? void 0 : date2;
261
+ }
262
+ function tokenOf(startHook) {
263
+ if (!startHook || typeof startHook !== "object")
264
+ return void 0;
265
+ const { token } = startHook;
266
+ return typeof token === "string" && token.length > 0 ? token : void 0;
267
+ }
268
+ function findStartHookCreation(events, run) {
269
+ var _a2, _b;
270
+ const creationEvent = events.find(isRunCreationEvent);
271
+ const runId = (run == null ? void 0 : run.runId) ?? (creationEvent == null ? void 0 : creationEvent.runId) ?? ((_a2 = events[0]) == null ? void 0 : _a2.runId);
272
+ if (!(runId == null ? void 0 : runId.startsWith("wrun_")) || runId.length <= "wrun_".length) {
273
+ return void 0;
274
+ }
275
+ const hookId = startHookId(runId);
276
+ const token = tokenOf(creationEvent && "eventData" in creationEvent ? (_b = creationEvent.eventData) == null ? void 0 : _b.startHook : void 0) ?? tokenOf(run == null ? void 0 : run.startHook);
277
+ const hookEvents = events.filter((event) => event.correlationId === hookId && isHookLifecycleEventType(event.eventType));
278
+ if (token === void 0 && hookEvents.length === 0)
279
+ return void 0;
280
+ if (hookEvents.some((event) => event.eventType === "hook_created")) {
281
+ return void 0;
282
+ }
283
+ const createdAt = eventTimestamp(creationEvent) ?? ((run == null ? void 0 : run.createdAt) ? new Date(run.createdAt) : void 0) ?? eventTimestamp(hookEvents[0]);
284
+ if (!createdAt)
285
+ return void 0;
286
+ return { hookId, runId, token, createdAt };
287
+ }
255
288
  function ResolveHookModal({ isOpen, onClose, onSubmit, isSubmitting = false }) {
256
289
  var _a2;
257
290
  const [jsonInput, setJsonInput] = reactExports.useState("");
@@ -311,39 +344,6 @@ function ResolveHookModal({ isOpen, onClose, onSubmit, isSubmitting = false }) {
311
344
  setParseError(null);
312
345
  }, onKeyDown: handleKeyDown, disabled: isSubmitting, placeholder: '{"key": "value"}', className: cn("box-border h-40 w-full resize-none rounded-lg border bg-background-100 px-3 py-2 font-mono text-[13px] text-gray-1000 leading-[1.5] outline-none disabled:cursor-not-allowed disabled:opacity-50", parseError ? "border-red-700" : "border-gray-alpha-400") }), parseError && jsxRuntimeExports.jsx("p", { className: "mt-2 mb-0 text-[13px] text-red-900", children: parseError }), jsxRuntimeExports.jsxs("p", { className: "mt-2 mb-0 text-gray-800 text-xs", children: ["Press", " ", jsxRuntimeExports.jsxs("kbd", { className: "rounded border border-gray-alpha-400 bg-gray-alpha-200 px-[5px] py-0.5 font-mono text-[11px]", children: [isMacPlatform ? "⌘" : "Ctrl", "+Enter"] }), " ", "to submit"] })] }), jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-end gap-2 border-gray-alpha-400 border-t px-6 py-3", children: [jsxRuntimeExports.jsx("button", { type: "button", onClick: onClose, disabled: isSubmitting, className: "cursor-pointer rounded-lg border border-gray-alpha-400 bg-background-100 px-4 py-2 font-medium text-gray-1000 text-sm transition-colors hover:bg-gray-alpha-100 disabled:cursor-not-allowed disabled:opacity-50", children: "Cancel" }), jsxRuntimeExports.jsxs("button", { type: "button", onClick: () => void submitPayload(), disabled: isSubmitting, className: "flex cursor-pointer items-center gap-1.5 rounded-lg !border-none bg-gray-1000 px-4 py-2 font-medium text-background-100 text-sm transition-opacity hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:opacity-50", children: [jsxRuntimeExports.jsx(Send, { className: "size-3.5" }), isSubmitting ? "Sending..." : "Send Payload"] })] })] })] })] });
313
346
  }
314
- function eventTimestamp(event) {
315
- const value = (event == null ? void 0 : event.occurredAt) ?? (event == null ? void 0 : event.createdAt);
316
- if (!value)
317
- return void 0;
318
- const date2 = value instanceof Date ? value : new Date(value);
319
- return Number.isNaN(date2.getTime()) ? void 0 : date2;
320
- }
321
- function tokenOf(startHook) {
322
- if (!startHook || typeof startHook !== "object")
323
- return void 0;
324
- const { token } = startHook;
325
- return typeof token === "string" && token.length > 0 ? token : void 0;
326
- }
327
- function findStartHookCreation(events, run) {
328
- var _a2, _b;
329
- const creationEvent = events.find(isRunCreationEvent);
330
- const runId = (run == null ? void 0 : run.runId) ?? (creationEvent == null ? void 0 : creationEvent.runId) ?? ((_a2 = events[0]) == null ? void 0 : _a2.runId);
331
- if (!(runId == null ? void 0 : runId.startsWith("wrun_")) || runId.length <= "wrun_".length) {
332
- return void 0;
333
- }
334
- const hookId = startHookId(runId);
335
- const token = tokenOf(creationEvent && "eventData" in creationEvent ? (_b = creationEvent.eventData) == null ? void 0 : _b.startHook : void 0) ?? tokenOf(run == null ? void 0 : run.startHook);
336
- const hookEvents = events.filter((event) => event.correlationId === hookId && isHookLifecycleEventType(event.eventType));
337
- if (token === void 0 && hookEvents.length === 0)
338
- return void 0;
339
- if (hookEvents.some((event) => event.eventType === "hook_created")) {
340
- return void 0;
341
- }
342
- const createdAt = eventTimestamp(creationEvent) ?? ((run == null ? void 0 : run.createdAt) ? new Date(run.createdAt) : void 0) ?? eventTimestamp(hookEvents[0]);
343
- if (!createdAt)
344
- return void 0;
345
- return { hookId, runId, token, createdAt };
346
- }
347
347
  const millisecondsInWeek = 6048e5;
348
348
  const millisecondsInDay = 864e5;
349
349
  const millisecondsInMinute = 6e4;
@@ -415,11 +415,11 @@ function getTimezoneOffsetInMilliseconds(date2) {
415
415
  return +date2 - +utcDate;
416
416
  }
417
417
  function normalizeDates(context, ...dates) {
418
- const normalize = constructFrom.bind(
418
+ const normalize2 = constructFrom.bind(
419
419
  null,
420
420
  context || dates.find((date2) => typeof date2 === "object")
421
421
  );
422
- return dates.map(normalize);
422
+ return dates.map(normalize2);
423
423
  }
424
424
  function startOfDay(date2, options) {
425
425
  const _date = toDate(date2, options == null ? void 0 : options.in);
@@ -2162,11 +2162,11 @@ var OrderedDict = (_a = class extends Map {
2162
2162
  * - Out-of-range indices are clamped
2163
2163
  */
2164
2164
  insert(index2, key, value) {
2165
- const has = this.has(key);
2166
- const finalSize = has ? this.size : this.size + 1;
2165
+ const has2 = this.has(key);
2166
+ const finalSize = has2 ? this.size : this.size + 1;
2167
2167
  const relativeIndex = toSafeInteger(index2);
2168
2168
  const targetIndex = relativeIndex >= 0 ? Math.min(relativeIndex, finalSize - 1) : Math.max(finalSize + relativeIndex, 0);
2169
- if (has ? __privateGet(this, _keys).indexOf(key) === targetIndex : targetIndex === this.size) {
2169
+ if (has2 ? __privateGet(this, _keys).indexOf(key) === targetIndex : targetIndex === this.size) {
2170
2170
  this.set(key, value);
2171
2171
  return this;
2172
2172
  }
@@ -3201,7 +3201,7 @@ function useCallbackRef(initialValue, callback) {
3201
3201
  ref.callback = callback;
3202
3202
  return ref.facade;
3203
3203
  }
3204
- var useIsomorphicLayoutEffect$1 = typeof window !== "undefined" ? reactExports.useLayoutEffect : reactExports.useEffect;
3204
+ var useIsomorphicLayoutEffect$2 = typeof window !== "undefined" ? reactExports.useLayoutEffect : reactExports.useEffect;
3205
3205
  var currentValues = /* @__PURE__ */ new WeakMap();
3206
3206
  function useMergeRefs(refs, defaultValue) {
3207
3207
  var callbackRef = useCallbackRef(null, function(newValue) {
@@ -3209,7 +3209,7 @@ function useMergeRefs(refs, defaultValue) {
3209
3209
  return assignRef(ref, newValue);
3210
3210
  });
3211
3211
  });
3212
- useIsomorphicLayoutEffect$1(function() {
3212
+ useIsomorphicLayoutEffect$2(function() {
3213
3213
  var oldValue = currentValues.get(callbackRef);
3214
3214
  if (oldValue) {
3215
3215
  var prevRefs_1 = new Set(oldValue);
@@ -3233,9 +3233,9 @@ function useMergeRefs(refs, defaultValue) {
3233
3233
  function ItoI(a) {
3234
3234
  return a;
3235
3235
  }
3236
- function innerCreateMedium(defaults, middleware) {
3237
- if (middleware === void 0) {
3238
- middleware = ItoI;
3236
+ function innerCreateMedium(defaults, middleware2) {
3237
+ if (middleware2 === void 0) {
3238
+ middleware2 = ItoI;
3239
3239
  }
3240
3240
  var buffer = [];
3241
3241
  var assigned = false;
@@ -3250,7 +3250,7 @@ function innerCreateMedium(defaults, middleware) {
3250
3250
  return defaults;
3251
3251
  },
3252
3252
  useMedium: function(data) {
3253
- var item = middleware(data, assigned);
3253
+ var item = middleware2(data, assigned);
3254
3254
  buffer.push(item);
3255
3255
  return function() {
3256
3256
  buffer = buffer.filter(function(x) {
@@ -3390,21 +3390,21 @@ function insertStyleTag(tag) {
3390
3390
  head.appendChild(tag);
3391
3391
  }
3392
3392
  var stylesheetSingleton = function() {
3393
- var counter = 0;
3393
+ var counter2 = 0;
3394
3394
  var stylesheet = null;
3395
3395
  return {
3396
3396
  add: function(style2) {
3397
- if (counter == 0) {
3397
+ if (counter2 == 0) {
3398
3398
  if (stylesheet = makeStyleTag()) {
3399
3399
  injectStyles(stylesheet, style2);
3400
3400
  insertStyleTag(stylesheet);
3401
3401
  }
3402
3402
  }
3403
- counter++;
3403
+ counter2++;
3404
3404
  },
3405
3405
  remove: function() {
3406
- counter--;
3407
- if (!counter && stylesheet) {
3406
+ counter2--;
3407
+ if (!counter2 && stylesheet) {
3408
3408
  stylesheet.parentNode && stylesheet.parentNode.removeChild(stylesheet);
3409
3409
  stylesheet = null;
3410
3410
  }
@@ -3478,8 +3478,8 @@ var getStyles = function(_a2, allowRelative, gapMode, important) {
3478
3478
  ].filter(Boolean).join(""), "\n }\n \n .").concat(zeroRightClassName, " {\n right: ").concat(gap, "px ").concat(important, ";\n }\n \n .").concat(fullWidthClassName, " {\n margin-right: ").concat(gap, "px ").concat(important, ";\n }\n \n .").concat(zeroRightClassName, " .").concat(zeroRightClassName, " {\n right: 0 ").concat(important, ";\n }\n \n .").concat(fullWidthClassName, " .").concat(fullWidthClassName, " {\n margin-right: 0 ").concat(important, ";\n }\n \n body[").concat(lockAttribute, "] {\n ").concat(removedBarSizeVariable, ": ").concat(gap, "px;\n }\n");
3479
3479
  };
3480
3480
  var getCurrentUseCounter = function() {
3481
- var counter = parseInt(document.body.getAttribute(lockAttribute) || "0", 10);
3482
- return isFinite(counter) ? counter : 0;
3481
+ var counter2 = parseInt(document.body.getAttribute(lockAttribute) || "0", 10);
3482
+ return isFinite(counter2) ? counter2 : 0;
3483
3483
  };
3484
3484
  var useLockAttribute = function() {
3485
3485
  reactExports.useEffect(function() {
@@ -4953,6 +4953,1306 @@ function requireShim() {
4953
4953
  }
4954
4954
  return shim.exports;
4955
4955
  }
4956
+ var shimExports = requireShim();
4957
+ var has = Object.prototype.hasOwnProperty;
4958
+ function dequal(foo, bar) {
4959
+ var ctor, len;
4960
+ if (foo === bar) return true;
4961
+ if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
4962
+ if (ctor === Date) return foo.getTime() === bar.getTime();
4963
+ if (ctor === RegExp) return foo.toString() === bar.toString();
4964
+ if (ctor === Array) {
4965
+ if ((len = foo.length) === bar.length) {
4966
+ while (len-- && dequal(foo[len], bar[len])) ;
4967
+ }
4968
+ return len === -1;
4969
+ }
4970
+ if (!ctor || typeof foo === "object") {
4971
+ len = 0;
4972
+ for (ctor in foo) {
4973
+ if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
4974
+ if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false;
4975
+ }
4976
+ return Object.keys(bar).length === len;
4977
+ }
4978
+ }
4979
+ return foo !== foo && bar !== bar;
4980
+ }
4981
+ const FOCUS_EVENT = 0;
4982
+ const RECONNECT_EVENT = 1;
4983
+ const MUTATE_EVENT = 2;
4984
+ const ERROR_REVALIDATE_EVENT = 3;
4985
+ const UNLOAD_EVENT = 4;
4986
+ const SWRGlobalState = /* @__PURE__ */ new WeakMap();
4987
+ const noop$1 = () => {
4988
+ };
4989
+ const UNDEFINED = (
4990
+ /*#__NOINLINE__*/
4991
+ noop$1()
4992
+ );
4993
+ const OBJECT = Object;
4994
+ const isUndefined = (v) => v === UNDEFINED;
4995
+ const isFunction = (v) => typeof v == "function";
4996
+ const mergeObjects$1 = (a, b) => ({
4997
+ ...a,
4998
+ ...b
4999
+ });
5000
+ const isPromiseLike = (x) => isFunction(x.then);
5001
+ const EMPTY_CACHE = {};
5002
+ const INITIAL_CACHE = {};
5003
+ const STR_UNDEFINED = "undefined";
5004
+ const isWindowDefined = typeof window != STR_UNDEFINED;
5005
+ const isDocumentDefined = typeof document != STR_UNDEFINED;
5006
+ const isLegacyDeno = isWindowDefined && "Deno" in window;
5007
+ const hasRequestAnimationFrame = () => isWindowDefined && typeof window["requestAnimationFrame"] != STR_UNDEFINED;
5008
+ const createCacheHelper = (cache2, key) => {
5009
+ const state = SWRGlobalState.get(cache2);
5010
+ return [
5011
+ // Getter
5012
+ () => !isUndefined(key) && cache2.get(key) || EMPTY_CACHE,
5013
+ // Setter
5014
+ (info) => {
5015
+ if (!isUndefined(key)) {
5016
+ const prev = cache2.get(key);
5017
+ if (!(key in INITIAL_CACHE)) {
5018
+ INITIAL_CACHE[key] = prev;
5019
+ }
5020
+ state[5](key, mergeObjects$1(prev, info), prev || EMPTY_CACHE);
5021
+ }
5022
+ },
5023
+ // Subscriber
5024
+ state[6],
5025
+ // Get server cache snapshot
5026
+ () => {
5027
+ if (!isUndefined(key)) {
5028
+ if (key in INITIAL_CACHE) return INITIAL_CACHE[key];
5029
+ }
5030
+ return !isUndefined(key) && cache2.get(key) || EMPTY_CACHE;
5031
+ }
5032
+ ];
5033
+ };
5034
+ let online = true;
5035
+ const isOnline = () => online;
5036
+ const [onWindowEvent, offWindowEvent] = isWindowDefined && window.addEventListener ? [
5037
+ window.addEventListener.bind(window),
5038
+ window.removeEventListener.bind(window)
5039
+ ] : [
5040
+ noop$1,
5041
+ noop$1
5042
+ ];
5043
+ const isVisible = () => {
5044
+ const visibilityState = isDocumentDefined && document.visibilityState;
5045
+ return isUndefined(visibilityState) || visibilityState !== "hidden";
5046
+ };
5047
+ const initFocus = (callback) => {
5048
+ if (isDocumentDefined) {
5049
+ document.addEventListener("visibilitychange", callback);
5050
+ }
5051
+ onWindowEvent("focus", callback);
5052
+ return () => {
5053
+ if (isDocumentDefined) {
5054
+ document.removeEventListener("visibilitychange", callback);
5055
+ }
5056
+ offWindowEvent("focus", callback);
5057
+ };
5058
+ };
5059
+ const initReconnect = (callback) => {
5060
+ const onOnline = () => {
5061
+ online = true;
5062
+ callback();
5063
+ };
5064
+ const onOffline = () => {
5065
+ online = false;
5066
+ };
5067
+ onWindowEvent("online", onOnline);
5068
+ onWindowEvent("offline", onOffline);
5069
+ return () => {
5070
+ offWindowEvent("online", onOnline);
5071
+ offWindowEvent("offline", onOffline);
5072
+ };
5073
+ };
5074
+ const preset = {
5075
+ isOnline,
5076
+ isVisible
5077
+ };
5078
+ const defaultConfigOptions = {
5079
+ initFocus,
5080
+ initReconnect
5081
+ };
5082
+ const IS_REACT_LEGACY = !ReactExports.useId;
5083
+ const IS_SERVER = !isWindowDefined || isLegacyDeno;
5084
+ const rAF = (f) => hasRequestAnimationFrame() ? window["requestAnimationFrame"](f) : setTimeout(f, 1);
5085
+ const useIsomorphicLayoutEffect$1 = IS_SERVER ? reactExports.useEffect : reactExports.useLayoutEffect;
5086
+ const navigatorConnection = typeof navigator !== "undefined" && navigator.connection;
5087
+ const slowConnection = !IS_SERVER && navigatorConnection && ([
5088
+ "slow-2g",
5089
+ "2g"
5090
+ ].includes(navigatorConnection.effectiveType) || navigatorConnection.saveData);
5091
+ const table = /* @__PURE__ */ new WeakMap();
5092
+ const getTypeName = (value) => OBJECT.prototype.toString.call(value);
5093
+ const isObjectTypeName = (typeName, type) => typeName === `[object ${type}]`;
5094
+ let counter = 0;
5095
+ const stableHash = (arg) => {
5096
+ const type = typeof arg;
5097
+ const typeName = getTypeName(arg);
5098
+ const isDate2 = isObjectTypeName(typeName, "Date");
5099
+ const isRegex = isObjectTypeName(typeName, "RegExp");
5100
+ const isPlainObject = isObjectTypeName(typeName, "Object");
5101
+ let result;
5102
+ let index2;
5103
+ if (OBJECT(arg) === arg && !isDate2 && !isRegex) {
5104
+ result = table.get(arg);
5105
+ if (result) return result;
5106
+ result = ++counter + "~";
5107
+ table.set(arg, result);
5108
+ if (Array.isArray(arg)) {
5109
+ result = "@";
5110
+ for (index2 = 0; index2 < arg.length; index2++) {
5111
+ result += stableHash(arg[index2]) + ",";
5112
+ }
5113
+ table.set(arg, result);
5114
+ }
5115
+ if (isPlainObject) {
5116
+ result = "#";
5117
+ const keys = OBJECT.keys(arg).sort();
5118
+ while (!isUndefined(index2 = keys.pop())) {
5119
+ if (!isUndefined(arg[index2])) {
5120
+ result += index2 + ":" + stableHash(arg[index2]) + ",";
5121
+ }
5122
+ }
5123
+ table.set(arg, result);
5124
+ }
5125
+ } else {
5126
+ result = isDate2 ? arg.toJSON() : type == "symbol" ? arg.toString() : type == "string" ? JSON.stringify(arg) : "" + arg;
5127
+ }
5128
+ return result;
5129
+ };
5130
+ const serialize = (key) => {
5131
+ if (isFunction(key)) {
5132
+ try {
5133
+ key = key();
5134
+ } catch (err) {
5135
+ key = "";
5136
+ }
5137
+ }
5138
+ const args = key;
5139
+ key = typeof key == "string" ? key : (Array.isArray(key) ? key.length : key) ? stableHash(key) : "";
5140
+ return [
5141
+ key,
5142
+ args
5143
+ ];
5144
+ };
5145
+ let __timestamp = 0;
5146
+ const getTimestamp = () => ++__timestamp;
5147
+ async function internalMutate(...args) {
5148
+ const [cache2, _key, _data, _opts] = args;
5149
+ const options = mergeObjects$1({
5150
+ populateCache: true,
5151
+ throwOnError: true
5152
+ }, typeof _opts === "boolean" ? {
5153
+ revalidate: _opts
5154
+ } : _opts || {});
5155
+ let populateCache = options.populateCache;
5156
+ const rollbackOnErrorOption = options.rollbackOnError;
5157
+ let optimisticData = options.optimisticData;
5158
+ const rollbackOnError = (error) => {
5159
+ return typeof rollbackOnErrorOption === "function" ? rollbackOnErrorOption(error) : rollbackOnErrorOption !== false;
5160
+ };
5161
+ const throwOnError = options.throwOnError;
5162
+ if (isFunction(_key)) {
5163
+ const keyFilter = _key;
5164
+ const matchedKeys = [];
5165
+ const it = cache2.keys();
5166
+ for (const key of it) {
5167
+ if (
5168
+ // Skip the special useSWRInfinite and useSWRSubscription keys.
5169
+ !/^\$(inf|sub)\$/.test(key) && keyFilter(cache2.get(key)._k)
5170
+ ) {
5171
+ matchedKeys.push(key);
5172
+ }
5173
+ }
5174
+ return Promise.all(matchedKeys.map(mutateByKey));
5175
+ }
5176
+ return mutateByKey(_key);
5177
+ async function mutateByKey(_k) {
5178
+ const [key] = serialize(_k);
5179
+ if (!key) return;
5180
+ const [get2, set2] = createCacheHelper(cache2, key);
5181
+ const [EVENT_REVALIDATORS, MUTATION, FETCH, PRELOAD] = SWRGlobalState.get(cache2);
5182
+ const startRevalidate = () => {
5183
+ const revalidators = EVENT_REVALIDATORS[key];
5184
+ const revalidate = isFunction(options.revalidate) ? options.revalidate(get2().data, _k) : options.revalidate !== false;
5185
+ if (revalidate) {
5186
+ delete FETCH[key];
5187
+ delete PRELOAD[key];
5188
+ if (revalidators && revalidators[0]) {
5189
+ return revalidators[0](MUTATE_EVENT).then(() => get2().data);
5190
+ }
5191
+ }
5192
+ return get2().data;
5193
+ };
5194
+ if (args.length < 3) {
5195
+ return startRevalidate();
5196
+ }
5197
+ let data = _data;
5198
+ let error;
5199
+ let isError = false;
5200
+ const beforeMutationTs = getTimestamp();
5201
+ MUTATION[key] = [
5202
+ beforeMutationTs,
5203
+ 0
5204
+ ];
5205
+ const hasOptimisticData = !isUndefined(optimisticData);
5206
+ const state = get2();
5207
+ const displayedData = state.data;
5208
+ const currentData = state._c;
5209
+ const committedData = isUndefined(currentData) ? displayedData : currentData;
5210
+ if (hasOptimisticData) {
5211
+ optimisticData = isFunction(optimisticData) ? optimisticData(committedData, displayedData) : optimisticData;
5212
+ set2({
5213
+ data: optimisticData,
5214
+ _c: committedData
5215
+ });
5216
+ }
5217
+ if (isFunction(data)) {
5218
+ try {
5219
+ data = data(committedData);
5220
+ } catch (err) {
5221
+ error = err;
5222
+ isError = true;
5223
+ }
5224
+ }
5225
+ if (data && isPromiseLike(data)) {
5226
+ data = await data.catch((err) => {
5227
+ error = err;
5228
+ isError = true;
5229
+ });
5230
+ if (beforeMutationTs !== MUTATION[key][0]) {
5231
+ if (isError) throw error;
5232
+ return data;
5233
+ } else if (isError && hasOptimisticData && rollbackOnError(error)) {
5234
+ populateCache = true;
5235
+ set2({
5236
+ data: committedData,
5237
+ _c: UNDEFINED
5238
+ });
5239
+ }
5240
+ }
5241
+ if (populateCache) {
5242
+ if (!isError) {
5243
+ if (isFunction(populateCache)) {
5244
+ const populateCachedData = populateCache(data, committedData);
5245
+ set2({
5246
+ data: populateCachedData,
5247
+ error: UNDEFINED,
5248
+ _c: UNDEFINED
5249
+ });
5250
+ } else {
5251
+ set2({
5252
+ data,
5253
+ error: UNDEFINED,
5254
+ _c: UNDEFINED
5255
+ });
5256
+ }
5257
+ }
5258
+ }
5259
+ MUTATION[key][1] = getTimestamp();
5260
+ Promise.resolve(startRevalidate()).then(() => {
5261
+ set2({
5262
+ _c: UNDEFINED
5263
+ });
5264
+ });
5265
+ if (isError) {
5266
+ if (throwOnError) throw error;
5267
+ return;
5268
+ }
5269
+ return data;
5270
+ }
5271
+ }
5272
+ const revalidateAllKeys = (revalidators, type) => {
5273
+ for (const key in revalidators) {
5274
+ if (revalidators[key][0]) revalidators[key][0](type);
5275
+ }
5276
+ };
5277
+ const initCache = (provider, options) => {
5278
+ if (!SWRGlobalState.has(provider)) {
5279
+ const opts = mergeObjects$1(defaultConfigOptions, options);
5280
+ const EVENT_REVALIDATORS = /* @__PURE__ */ Object.create(null);
5281
+ const mutate2 = internalMutate.bind(UNDEFINED, provider);
5282
+ let unmount = noop$1;
5283
+ const subscriptions = /* @__PURE__ */ Object.create(null);
5284
+ const subscribe2 = (key, callback) => {
5285
+ const subs = subscriptions[key] || [];
5286
+ subscriptions[key] = subs;
5287
+ subs.push(callback);
5288
+ return () => {
5289
+ const index2 = subs.indexOf(callback);
5290
+ if (index2 >= 0) {
5291
+ subs[index2] = subs[subs.length - 1];
5292
+ subs.pop();
5293
+ }
5294
+ };
5295
+ };
5296
+ const setter = (key, value, prev) => {
5297
+ provider.set(key, value);
5298
+ const subs = subscriptions[key];
5299
+ if (subs) {
5300
+ for (const fn of subs) {
5301
+ fn(value, prev);
5302
+ }
5303
+ }
5304
+ };
5305
+ const unload2 = (unloadOptions) => {
5306
+ const state2 = SWRGlobalState.get(provider);
5307
+ const [, MUTATION, FETCH, PRELOAD] = state2;
5308
+ const ts = getTimestamp();
5309
+ state2[8]++;
5310
+ for (const key in FETCH) delete FETCH[key];
5311
+ for (const key in PRELOAD) delete PRELOAD[key];
5312
+ for (const key in MUTATION) MUTATION[key] = [
5313
+ ts,
5314
+ ts
5315
+ ];
5316
+ const emptyState = {};
5317
+ for (const key of [
5318
+ ...provider.keys()
5319
+ ]) {
5320
+ const prev = provider.get(key);
5321
+ provider.delete(key);
5322
+ const subs = subscriptions[key];
5323
+ if (subs) {
5324
+ for (const fn of subs) {
5325
+ fn(emptyState, prev);
5326
+ }
5327
+ }
5328
+ }
5329
+ const revalidate = !unloadOptions || unloadOptions.revalidate !== false;
5330
+ for (const key in EVENT_REVALIDATORS) {
5331
+ const revalidators = EVENT_REVALIDATORS[key];
5332
+ for (let i = 0; i < revalidators.length; i++) {
5333
+ revalidators[i](UNLOAD_EVENT, {
5334
+ revalidate: revalidate && !i
5335
+ });
5336
+ }
5337
+ }
5338
+ };
5339
+ const initProvider = () => {
5340
+ if (!SWRGlobalState.has(provider)) {
5341
+ SWRGlobalState.set(provider, [
5342
+ EVENT_REVALIDATORS,
5343
+ /* @__PURE__ */ Object.create(null),
5344
+ /* @__PURE__ */ Object.create(null),
5345
+ /* @__PURE__ */ Object.create(null),
5346
+ mutate2,
5347
+ setter,
5348
+ subscribe2,
5349
+ unload2,
5350
+ 0
5351
+ ]);
5352
+ if (!IS_SERVER) {
5353
+ const releaseFocus = opts.initFocus(setTimeout.bind(UNDEFINED, revalidateAllKeys.bind(UNDEFINED, EVENT_REVALIDATORS, FOCUS_EVENT)));
5354
+ const releaseReconnect = opts.initReconnect(setTimeout.bind(UNDEFINED, revalidateAllKeys.bind(UNDEFINED, EVENT_REVALIDATORS, RECONNECT_EVENT)));
5355
+ unmount = () => {
5356
+ releaseFocus && releaseFocus();
5357
+ releaseReconnect && releaseReconnect();
5358
+ SWRGlobalState.delete(provider);
5359
+ };
5360
+ }
5361
+ }
5362
+ };
5363
+ initProvider();
5364
+ return [
5365
+ provider,
5366
+ mutate2,
5367
+ initProvider,
5368
+ unmount,
5369
+ unload2
5370
+ ];
5371
+ }
5372
+ const state = SWRGlobalState.get(provider);
5373
+ return [
5374
+ provider,
5375
+ state[4],
5376
+ UNDEFINED,
5377
+ UNDEFINED,
5378
+ state[7]
5379
+ ];
5380
+ };
5381
+ const onErrorRetry = (_, __, config, revalidate, opts) => {
5382
+ const maxRetryCount = config.errorRetryCount;
5383
+ const currentRetryCount = opts.retryCount;
5384
+ const timeout2 = ~~((Math.random() + 0.5) * (1 << (currentRetryCount < 8 ? currentRetryCount : 8))) * config.errorRetryInterval;
5385
+ if (!isUndefined(maxRetryCount) && currentRetryCount > maxRetryCount) {
5386
+ return;
5387
+ }
5388
+ setTimeout(revalidate, timeout2, opts);
5389
+ };
5390
+ const compare = dequal;
5391
+ const [cache, mutate, , , unload] = initCache(/* @__PURE__ */ new Map());
5392
+ const defaultConfig = mergeObjects$1(
5393
+ {
5394
+ // events
5395
+ onLoadingSlow: noop$1,
5396
+ onSuccess: noop$1,
5397
+ onError: noop$1,
5398
+ onErrorRetry,
5399
+ onDiscarded: noop$1,
5400
+ // switches
5401
+ revalidateOnFocus: true,
5402
+ revalidateOnReconnect: true,
5403
+ revalidateIfStale: true,
5404
+ shouldRetryOnError: true,
5405
+ // timeouts
5406
+ errorRetryInterval: slowConnection ? 1e4 : 5e3,
5407
+ focusThrottleInterval: 5 * 1e3,
5408
+ dedupingInterval: 2 * 1e3,
5409
+ loadingTimeout: slowConnection ? 5e3 : 3e3,
5410
+ // providers
5411
+ compare,
5412
+ isPaused: () => false,
5413
+ cache,
5414
+ mutate,
5415
+ unload,
5416
+ fallback: {}
5417
+ },
5418
+ // use web preset by default
5419
+ preset
5420
+ );
5421
+ const mergeConfigs = (a, b) => {
5422
+ const v = mergeObjects$1(a, b);
5423
+ if (b) {
5424
+ const { use: u1, fallback: f1, cacheData: c1 } = a;
5425
+ const { use: u2, fallback: f2, cacheData: c2 } = b;
5426
+ if (u1 && u2) {
5427
+ v.use = u1.concat(u2);
5428
+ }
5429
+ if (f1 && f2) {
5430
+ v.fallback = mergeObjects$1(f1, f2);
5431
+ }
5432
+ if (c1 && c2) {
5433
+ v.cacheData = mergeObjects$1(c1, c2);
5434
+ }
5435
+ }
5436
+ return v;
5437
+ };
5438
+ const SWRConfigContext = reactExports.createContext({});
5439
+ const INFINITE_PREFIX = "$inf$";
5440
+ const enableDevtools = isWindowDefined && window.__SWR_DEVTOOLS_USE__;
5441
+ const use$1 = enableDevtools ? window.__SWR_DEVTOOLS_USE__ : [];
5442
+ const setupDevTools = () => {
5443
+ if (enableDevtools) {
5444
+ window.__SWR_DEVTOOLS_REACT__ = ReactExports;
5445
+ }
5446
+ };
5447
+ const normalize = (args) => {
5448
+ return isFunction(args[1]) ? [
5449
+ args[0],
5450
+ args[1],
5451
+ args[2] || {}
5452
+ ] : [
5453
+ args[0],
5454
+ null,
5455
+ (args[1] === null ? args[2] : args[1]) || {}
5456
+ ];
5457
+ };
5458
+ const useSWRConfig = () => {
5459
+ const parentConfig = reactExports.useContext(SWRConfigContext);
5460
+ const mergedConfig = reactExports.useMemo(() => mergeObjects$1(defaultConfig, parentConfig), [
5461
+ parentConfig
5462
+ ]);
5463
+ return mergedConfig;
5464
+ };
5465
+ const middleware = (useSWRNext) => (key_, fetcher_, config) => {
5466
+ const fetcher = fetcher_ && ((...args) => {
5467
+ const [key] = serialize(key_);
5468
+ const [, , , PRELOAD] = SWRGlobalState.get(cache);
5469
+ if (key.startsWith(INFINITE_PREFIX)) {
5470
+ return fetcher_(...args);
5471
+ }
5472
+ const req = PRELOAD[key];
5473
+ if (isUndefined(req)) return fetcher_(...args);
5474
+ delete PRELOAD[key];
5475
+ return req;
5476
+ });
5477
+ return useSWRNext(key_, fetcher, config);
5478
+ };
5479
+ const BUILT_IN_MIDDLEWARE = use$1.concat(middleware);
5480
+ const withArgs = (hook) => {
5481
+ return function useSWRArgs(...args) {
5482
+ const fallbackConfig = useSWRConfig();
5483
+ const [key, fn, _config] = normalize(args);
5484
+ const config = mergeConfigs(fallbackConfig, _config);
5485
+ let next = hook;
5486
+ const { use: use2 } = config;
5487
+ const middleware2 = (use2 || []).concat(BUILT_IN_MIDDLEWARE);
5488
+ for (let i = middleware2.length; i--; ) {
5489
+ next = middleware2[i](next);
5490
+ }
5491
+ return next(key, fn || config.fetcher || null, config);
5492
+ };
5493
+ };
5494
+ const subscribeCallback = (key, callbacks, callback) => {
5495
+ const keyedRevalidators = callbacks[key] || (callbacks[key] = []);
5496
+ keyedRevalidators.push(callback);
5497
+ return () => {
5498
+ const index2 = keyedRevalidators.indexOf(callback);
5499
+ if (index2 >= 0) {
5500
+ keyedRevalidators[index2] = keyedRevalidators[keyedRevalidators.length - 1];
5501
+ keyedRevalidators.pop();
5502
+ }
5503
+ };
5504
+ };
5505
+ const withMiddleware = (useSWR2, middleware2) => {
5506
+ return (...args) => {
5507
+ const [key, fn, config] = normalize(args);
5508
+ const uses = (config.use || []).concat(middleware2);
5509
+ return useSWR2(key, fn, {
5510
+ ...config,
5511
+ use: uses
5512
+ });
5513
+ };
5514
+ };
5515
+ setupDevTools();
5516
+ const use = ReactExports.use || // This extra generic is to avoid TypeScript mixing up the generic and JSX sytax
5517
+ // and emitting an error.
5518
+ // We assume that this is only for the `use(thenable)` case, not `use(context)`.
5519
+ // https://github.com/facebook/react/blob/aed00dacfb79d17c53218404c52b1c7aa59c4a89/packages/react-server/src/ReactFizzThenable.js#L45
5520
+ ((thenable) => {
5521
+ switch (thenable.status) {
5522
+ case "pending":
5523
+ throw thenable;
5524
+ case "fulfilled":
5525
+ return thenable.value;
5526
+ case "rejected":
5527
+ throw thenable.reason;
5528
+ default:
5529
+ thenable.status = "pending";
5530
+ thenable.then((v) => {
5531
+ thenable.status = "fulfilled";
5532
+ thenable.value = v;
5533
+ }, (e) => {
5534
+ thenable.status = "rejected";
5535
+ thenable.reason = e;
5536
+ });
5537
+ throw thenable;
5538
+ }
5539
+ });
5540
+ const WITH_DEDUPE = {
5541
+ dedupe: true
5542
+ };
5543
+ const isCacheDataConsumed = (consumedCacheData, cacheData, key) => {
5544
+ var _consumedCacheData_get;
5545
+ return cacheData ? ((_consumedCacheData_get = consumedCacheData.get(cacheData)) == null ? void 0 : _consumedCacheData_get.has(key)) === true : false;
5546
+ };
5547
+ const markCacheDataConsumed = (consumedCacheData, cacheData, key) => {
5548
+ if (!cacheData) return;
5549
+ let consumedKeys = consumedCacheData.get(cacheData);
5550
+ if (!consumedKeys) {
5551
+ consumedKeys = /* @__PURE__ */ new Set();
5552
+ consumedCacheData.set(cacheData, consumedKeys);
5553
+ }
5554
+ consumedKeys.add(key);
5555
+ };
5556
+ const commitCacheData = ({ value, getCacheData, canCommit, setCache }) => {
5557
+ const commit = (state) => {
5558
+ if (canCommit() && isUndefined(getCacheData())) {
5559
+ setCache(state);
5560
+ }
5561
+ };
5562
+ Promise.resolve(value).then((data) => {
5563
+ commit({
5564
+ data,
5565
+ error: UNDEFINED
5566
+ });
5567
+ }, (error) => {
5568
+ commit({
5569
+ error
5570
+ });
5571
+ });
5572
+ };
5573
+ const resolvedUndef = Promise.resolve(UNDEFINED);
5574
+ resolvedUndef.status = "fulfilled";
5575
+ resolvedUndef.value = UNDEFINED;
5576
+ const sub = () => noop$1;
5577
+ const useSWRHandler = (_key, fetcher, config) => {
5578
+ const { cache: cache2, compare: compare2, suspense, fallbackData, revalidateOnMount, revalidateIfStale, refreshInterval, refreshWhenHidden, refreshWhenOffline, keepPreviousData, strictServerPrefetchWarning } = config;
5579
+ const [EVENT_REVALIDATORS, MUTATION, FETCH, PRELOAD] = SWRGlobalState.get(cache2);
5580
+ const [key, fnArg] = serialize(_key);
5581
+ const initialMountedRef = reactExports.useRef(false);
5582
+ const unmountedRef = reactExports.useRef(false);
5583
+ const keyRef = reactExports.useRef(key);
5584
+ const fetcherRef = reactExports.useRef(fetcher);
5585
+ const configRef = reactExports.useRef(config);
5586
+ const getConfig = () => configRef.current;
5587
+ const isActive = () => getConfig().isVisible() && getConfig().isOnline();
5588
+ const [getCache, setCache, subscribeCache, getInitialCache] = createCacheHelper(cache2, key);
5589
+ const stateDependencies = reactExports.useRef({}).current;
5590
+ const fallback = isUndefined(fallbackData) ? isUndefined(config.fallback) ? UNDEFINED : config.fallback[key] : fallbackData;
5591
+ const serverCacheData = config.cacheData;
5592
+ const configCacheData = !key ? UNDEFINED : serverCacheData == null ? void 0 : serverCacheData[key];
5593
+ const req = key ? PRELOAD[key] : UNDEFINED;
5594
+ const hasCacheData = isUndefined(req) && !isUndefined(configCacheData);
5595
+ const preloadedData = hasCacheData ? configCacheData : req;
5596
+ const isEqual = (prev, current) => {
5597
+ for (const _ in stateDependencies) {
5598
+ const t = _;
5599
+ if (t === "data") {
5600
+ if (!compare2(prev[t], current[t])) {
5601
+ if (!isUndefined(prev[t])) {
5602
+ return false;
5603
+ }
5604
+ if (!compare2(returnedData, current[t])) {
5605
+ return false;
5606
+ }
5607
+ }
5608
+ } else {
5609
+ if (current[t] !== prev[t]) {
5610
+ return false;
5611
+ }
5612
+ }
5613
+ }
5614
+ return true;
5615
+ };
5616
+ const isInitialMount = !initialMountedRef.current;
5617
+ const getSnapshot = reactExports.useMemo(() => {
5618
+ const cachedData2 = getCache();
5619
+ const initialData = getInitialCache();
5620
+ const getSelectedCache = (state) => {
5621
+ const snapshot = mergeObjects$1(state);
5622
+ delete snapshot._k;
5623
+ const shouldStartRequest = (() => {
5624
+ if (!key) return false;
5625
+ if (!fetcher) return false;
5626
+ if (getConfig().isPaused()) return false;
5627
+ if (isInitialMount && !isUndefined(revalidateOnMount)) return revalidateOnMount;
5628
+ const data2 = !isUndefined(fallback) ? fallback : snapshot.data;
5629
+ if (suspense && hasCacheData && isUndefined(data2)) return false;
5630
+ if (suspense) return isUndefined(data2) || revalidateIfStale;
5631
+ return isUndefined(data2) || revalidateIfStale;
5632
+ })();
5633
+ if (!shouldStartRequest) {
5634
+ return snapshot;
5635
+ }
5636
+ return {
5637
+ isValidating: true,
5638
+ isLoading: true,
5639
+ ...snapshot
5640
+ };
5641
+ };
5642
+ const clientSnapshot = getSelectedCache(cachedData2);
5643
+ const serverSnapshot = cachedData2 === initialData ? clientSnapshot : getSelectedCache(initialData);
5644
+ let memorizedSnapshot = clientSnapshot;
5645
+ return [
5646
+ () => {
5647
+ const newSnapshot = getSelectedCache(getCache());
5648
+ const compareResult = isEqual(newSnapshot, memorizedSnapshot);
5649
+ if (compareResult) {
5650
+ memorizedSnapshot.data = newSnapshot.data;
5651
+ memorizedSnapshot.isLoading = newSnapshot.isLoading;
5652
+ memorizedSnapshot.isValidating = newSnapshot.isValidating;
5653
+ memorizedSnapshot.error = newSnapshot.error;
5654
+ return memorizedSnapshot;
5655
+ } else {
5656
+ memorizedSnapshot = newSnapshot;
5657
+ return newSnapshot;
5658
+ }
5659
+ },
5660
+ () => serverSnapshot
5661
+ ];
5662
+ }, [
5663
+ cache2,
5664
+ key
5665
+ ]);
5666
+ const cached = shimExports.useSyncExternalStore(reactExports.useCallback(
5667
+ (callback) => subscribeCache(key, (current, prev) => {
5668
+ if (!isEqual(prev, current)) callback();
5669
+ }),
5670
+ // eslint-disable-next-line react-hooks/exhaustive-deps
5671
+ [
5672
+ cache2,
5673
+ key
5674
+ ]
5675
+ ), getSnapshot[0], getSnapshot[1]);
5676
+ const hasRevalidator = EVENT_REVALIDATORS[key] && EVENT_REVALIDATORS[key].length > 0;
5677
+ const cachedData = cached.data;
5678
+ let data = isUndefined(cachedData) ? fallback && isPromiseLike(fallback) ? use(fallback) : fallback : cachedData;
5679
+ const error = cached.error;
5680
+ const laggyDataRef = reactExports.useRef(data);
5681
+ const consumedCacheDataRef = reactExports.useRef(UNDEFINED);
5682
+ let consumedCacheData = consumedCacheDataRef.current;
5683
+ if (!consumedCacheData) {
5684
+ consumedCacheData = /* @__PURE__ */ new WeakMap();
5685
+ consumedCacheDataRef.current = consumedCacheData;
5686
+ }
5687
+ const preloadCacheRef = reactExports.useRef(null);
5688
+ let returnedData = keepPreviousData ? isUndefined(cachedData) ? isUndefined(laggyDataRef.current) ? data : laggyDataRef.current : cachedData : data;
5689
+ const hasKeyButNoData = key && isUndefined(data);
5690
+ const hydrationRef = reactExports.useRef(null);
5691
+ !IS_SERVER && // getServerSnapshot is only called during hydration
5692
+ // eslint-disable-next-line react-hooks/rules-of-hooks
5693
+ shimExports.useSyncExternalStore(sub, () => {
5694
+ hydrationRef.current = false;
5695
+ return hydrationRef;
5696
+ }, () => {
5697
+ hydrationRef.current = true;
5698
+ return hydrationRef;
5699
+ });
5700
+ const isHydration = hydrationRef.current;
5701
+ if (strictServerPrefetchWarning && isHydration && !suspense && hasKeyButNoData) {
5702
+ console.warn(`Missing pre-initiated data for serialized key "${key}" during server-side rendering. Data fetching should be initiated on the server and provided to SWR via fallback data. You can set "strictServerPrefetchWarning: false" to disable this warning.`);
5703
+ }
5704
+ const shouldDoInitialRevalidation = (() => {
5705
+ if (!key || !fetcher) return false;
5706
+ if (getConfig().isPaused()) return false;
5707
+ if (hasRevalidator && !isUndefined(error)) return false;
5708
+ if (isInitialMount && !isUndefined(revalidateOnMount)) return revalidateOnMount;
5709
+ if (suspense && hasCacheData && hasKeyButNoData) return false;
5710
+ if (suspense) return isUndefined(data) ? false : revalidateIfStale;
5711
+ return isUndefined(data) || revalidateIfStale;
5712
+ })();
5713
+ const defaultValidatingState = isInitialMount && shouldDoInitialRevalidation;
5714
+ const isValidating = isUndefined(cached.isValidating) ? defaultValidatingState : cached.isValidating;
5715
+ const isLoading = isUndefined(cached.isLoading) ? defaultValidatingState : cached.isLoading;
5716
+ const revalidate = reactExports.useCallback(
5717
+ async (revalidateOpts) => {
5718
+ const currentFetcher = fetcherRef.current;
5719
+ if (!key || !currentFetcher || unmountedRef.current || getConfig().isPaused()) {
5720
+ return false;
5721
+ }
5722
+ let newData;
5723
+ let startAt;
5724
+ let loading = true;
5725
+ const opts = revalidateOpts || {};
5726
+ const shouldStartNewRequest = !FETCH[key] || !opts.dedupe;
5727
+ const shouldUseRSCPreload = hasCacheData && !isCacheDataConsumed(consumedCacheData, serverCacheData, key) && !isUndefined(preloadedData) && isUndefined(getCache().data);
5728
+ const callbackSafeguard = () => {
5729
+ if (IS_REACT_LEGACY) {
5730
+ return !unmountedRef.current && key === keyRef.current && initialMountedRef.current;
5731
+ }
5732
+ return key === keyRef.current;
5733
+ };
5734
+ const finalState = {
5735
+ isValidating: false,
5736
+ isLoading: false
5737
+ };
5738
+ const finishRequestAndUpdateState = () => {
5739
+ setCache(finalState);
5740
+ };
5741
+ const cleanupState = () => {
5742
+ const requestInfo = FETCH[key];
5743
+ if (requestInfo && requestInfo[1] === startAt) {
5744
+ delete FETCH[key];
5745
+ }
5746
+ };
5747
+ const initialState = {
5748
+ isValidating: true
5749
+ };
5750
+ if (isUndefined(getCache().data)) {
5751
+ initialState.isLoading = true;
5752
+ }
5753
+ try {
5754
+ if (shouldStartNewRequest) {
5755
+ setCache(initialState);
5756
+ if (config.loadingTimeout && isUndefined(getCache().data)) {
5757
+ setTimeout(() => {
5758
+ if (loading && callbackSafeguard()) {
5759
+ getConfig().onLoadingSlow(key, config);
5760
+ }
5761
+ }, config.loadingTimeout);
5762
+ }
5763
+ if (shouldUseRSCPreload) {
5764
+ markCacheDataConsumed(consumedCacheData, serverCacheData, key);
5765
+ }
5766
+ FETCH[key] = [
5767
+ shouldUseRSCPreload ? preloadedData : currentFetcher(fnArg),
5768
+ getTimestamp()
5769
+ ];
5770
+ if (shouldUseRSCPreload && PRELOAD[key]) {
5771
+ delete PRELOAD[key];
5772
+ }
5773
+ }
5774
+ ;
5775
+ [newData, startAt] = FETCH[key];
5776
+ newData = await newData;
5777
+ if (shouldStartNewRequest) {
5778
+ setTimeout(cleanupState, config.dedupingInterval);
5779
+ }
5780
+ if (!FETCH[key] || FETCH[key][1] !== startAt) {
5781
+ if (shouldStartNewRequest) {
5782
+ if (callbackSafeguard()) {
5783
+ getConfig().onDiscarded(key);
5784
+ }
5785
+ }
5786
+ return false;
5787
+ }
5788
+ finalState.error = UNDEFINED;
5789
+ const mutationInfo = MUTATION[key];
5790
+ if (!isUndefined(mutationInfo) && // case 1
5791
+ (startAt <= mutationInfo[0] || // case 2
5792
+ startAt <= mutationInfo[1] || // case 3
5793
+ mutationInfo[1] === 0)) {
5794
+ finishRequestAndUpdateState();
5795
+ if (shouldStartNewRequest) {
5796
+ if (callbackSafeguard()) {
5797
+ getConfig().onDiscarded(key);
5798
+ }
5799
+ }
5800
+ return false;
5801
+ }
5802
+ const cacheData = getCache().data;
5803
+ finalState.data = compare2(cacheData, newData) ? cacheData : newData;
5804
+ if (shouldStartNewRequest) {
5805
+ if (callbackSafeguard()) {
5806
+ getConfig().onSuccess(newData, key, config);
5807
+ }
5808
+ }
5809
+ } catch (err) {
5810
+ cleanupState();
5811
+ const currentConfig = getConfig();
5812
+ const { shouldRetryOnError } = currentConfig;
5813
+ if (!currentConfig.isPaused()) {
5814
+ finalState.error = err;
5815
+ if (shouldStartNewRequest && callbackSafeguard()) {
5816
+ currentConfig.onError(err, key, currentConfig);
5817
+ if (shouldRetryOnError === true || isFunction(shouldRetryOnError) && shouldRetryOnError(err)) {
5818
+ if (!getConfig().revalidateOnFocus || !getConfig().revalidateOnReconnect || isActive()) {
5819
+ currentConfig.onErrorRetry(err, key, currentConfig, (_opts) => {
5820
+ const revalidators = EVENT_REVALIDATORS[key];
5821
+ if (revalidators && revalidators[0]) {
5822
+ revalidators[0](ERROR_REVALIDATE_EVENT, _opts);
5823
+ }
5824
+ }, {
5825
+ retryCount: (opts.retryCount || 0) + 1,
5826
+ dedupe: true
5827
+ });
5828
+ }
5829
+ }
5830
+ }
5831
+ }
5832
+ }
5833
+ loading = false;
5834
+ finishRequestAndUpdateState();
5835
+ return true;
5836
+ },
5837
+ // `setState` is immutable, and `eventsCallback`, `fnArg`, and
5838
+ // `keyValidating` are depending on `key`, so we can exclude them from
5839
+ // the deps array.
5840
+ //
5841
+ // FIXME:
5842
+ // `fn` and `config` might be changed during the lifecycle,
5843
+ // but they might be changed every render like this.
5844
+ // `useSWR('key', () => fetch('/api/'), { suspense: true })`
5845
+ // So we omit the values from the deps array
5846
+ // even though it might cause unexpected behaviors.
5847
+ // eslint-disable-next-line react-hooks/exhaustive-deps
5848
+ [
5849
+ key,
5850
+ cache2
5851
+ ]
5852
+ );
5853
+ const boundMutate = reactExports.useCallback(
5854
+ // Use callback to make sure `keyRef.current` returns latest result every time
5855
+ (...args) => {
5856
+ return internalMutate(cache2, keyRef.current, ...args);
5857
+ },
5858
+ // eslint-disable-next-line react-hooks/exhaustive-deps
5859
+ []
5860
+ );
5861
+ useIsomorphicLayoutEffect$1(() => {
5862
+ const preloaded = preloadCacheRef.current;
5863
+ if (!preloaded) return;
5864
+ preloadCacheRef.current = null;
5865
+ markCacheDataConsumed(consumedCacheData, preloaded.cacheData, preloaded.key);
5866
+ if (isUndefined(getCache().data)) {
5867
+ setCache({
5868
+ data: preloaded.data,
5869
+ error: UNDEFINED,
5870
+ _k: preloaded._k
5871
+ });
5872
+ }
5873
+ if (PRELOAD[preloaded.key]) {
5874
+ delete PRELOAD[preloaded.key];
5875
+ }
5876
+ });
5877
+ useIsomorphicLayoutEffect$1(() => {
5878
+ fetcherRef.current = fetcher;
5879
+ configRef.current = config;
5880
+ if (!isUndefined(cachedData)) {
5881
+ laggyDataRef.current = cachedData;
5882
+ }
5883
+ });
5884
+ useIsomorphicLayoutEffect$1(() => {
5885
+ if (fetcher || !hasCacheData || isUndefined(preloadedData) || isCacheDataConsumed(consumedCacheData, serverCacheData, key) || !isUndefined(getCache().data)) {
5886
+ return;
5887
+ }
5888
+ markCacheDataConsumed(consumedCacheData, serverCacheData, key);
5889
+ const mutation = MUTATION[key];
5890
+ commitCacheData({
5891
+ value: preloadedData,
5892
+ getCacheData: () => getCache().data,
5893
+ canCommit: () => !unmountedRef.current && key === keyRef.current && MUTATION[key] === mutation,
5894
+ setCache: (state) => setCache({
5895
+ ...state,
5896
+ _k: fnArg
5897
+ })
5898
+ });
5899
+ });
5900
+ useIsomorphicLayoutEffect$1(() => {
5901
+ if (!key) return;
5902
+ const softRevalidate = revalidate.bind(UNDEFINED, WITH_DEDUPE);
5903
+ let nextFocusRevalidatedAt = 0;
5904
+ if (getConfig().revalidateOnFocus) {
5905
+ const initNow = Date.now();
5906
+ nextFocusRevalidatedAt = initNow + getConfig().focusThrottleInterval;
5907
+ }
5908
+ const onRevalidate = (type, opts = {}) => {
5909
+ if (type == FOCUS_EVENT) {
5910
+ const now2 = Date.now();
5911
+ if (getConfig().revalidateOnFocus && now2 > nextFocusRevalidatedAt && isActive()) {
5912
+ nextFocusRevalidatedAt = now2 + getConfig().focusThrottleInterval;
5913
+ softRevalidate();
5914
+ }
5915
+ } else if (type == RECONNECT_EVENT) {
5916
+ if (getConfig().revalidateOnReconnect && isActive()) {
5917
+ softRevalidate();
5918
+ }
5919
+ } else if (type == MUTATE_EVENT) {
5920
+ return revalidate();
5921
+ } else if (type == ERROR_REVALIDATE_EVENT) {
5922
+ return revalidate(opts);
5923
+ } else if (type == UNLOAD_EVENT) {
5924
+ laggyDataRef.current = UNDEFINED;
5925
+ if (opts.revalidate) {
5926
+ return revalidate();
5927
+ }
5928
+ }
5929
+ return;
5930
+ };
5931
+ const unsubEvents = subscribeCallback(key, EVENT_REVALIDATORS, onRevalidate);
5932
+ unmountedRef.current = false;
5933
+ keyRef.current = key;
5934
+ initialMountedRef.current = true;
5935
+ setCache({
5936
+ _k: fnArg
5937
+ });
5938
+ if (shouldDoInitialRevalidation) {
5939
+ if (!FETCH[key]) {
5940
+ if (isUndefined(data) || IS_SERVER) {
5941
+ softRevalidate();
5942
+ } else {
5943
+ rAF(softRevalidate);
5944
+ }
5945
+ }
5946
+ }
5947
+ return () => {
5948
+ unmountedRef.current = true;
5949
+ unsubEvents();
5950
+ };
5951
+ }, [
5952
+ key
5953
+ ]);
5954
+ useIsomorphicLayoutEffect$1(() => {
5955
+ let timer2;
5956
+ function next() {
5957
+ const interval2 = isFunction(refreshInterval) ? refreshInterval(getCache().data) : refreshInterval;
5958
+ if (interval2 && timer2 !== -1) {
5959
+ timer2 = setTimeout(execute, interval2);
5960
+ }
5961
+ }
5962
+ function execute() {
5963
+ if (!getCache().error && (refreshWhenHidden || getConfig().isVisible()) && (refreshWhenOffline || getConfig().isOnline())) {
5964
+ revalidate(WITH_DEDUPE).then(next);
5965
+ } else {
5966
+ next();
5967
+ }
5968
+ }
5969
+ next();
5970
+ return () => {
5971
+ if (timer2) {
5972
+ clearTimeout(timer2);
5973
+ timer2 = -1;
5974
+ }
5975
+ };
5976
+ }, [
5977
+ refreshInterval,
5978
+ refreshWhenHidden,
5979
+ refreshWhenOffline,
5980
+ key
5981
+ ]);
5982
+ reactExports.useDebugValue(returnedData);
5983
+ if (suspense) {
5984
+ if (!IS_REACT_LEGACY && IS_SERVER && hasKeyButNoData && isUndefined(preloadedData)) {
5985
+ throw new Error("Fallback data is required when using Suspense in SSR.");
5986
+ }
5987
+ if (hasKeyButNoData) {
5988
+ fetcherRef.current = fetcher;
5989
+ configRef.current = config;
5990
+ unmountedRef.current = false;
5991
+ }
5992
+ const shouldConsumePreload = !isUndefined(preloadedData) && hasKeyButNoData;
5993
+ let preloadData = UNDEFINED;
5994
+ if (shouldConsumePreload && hasCacheData) {
5995
+ preloadData = preloadedData && isPromiseLike(preloadedData) ? use(preloadedData) : preloadedData;
5996
+ data = preloadData;
5997
+ returnedData = preloadData;
5998
+ if (!IS_SERVER) {
5999
+ preloadCacheRef.current = {
6000
+ data: preloadData,
6001
+ _k: fnArg,
6002
+ key,
6003
+ cacheData: serverCacheData
6004
+ };
6005
+ }
6006
+ } else {
6007
+ const mutateReq = shouldConsumePreload ? boundMutate(preloadedData) : resolvedUndef;
6008
+ use(mutateReq);
6009
+ }
6010
+ if (!isUndefined(error) && hasKeyButNoData) {
6011
+ throw error;
6012
+ }
6013
+ const revalidation = hasKeyButNoData && isUndefined(preloadData) ? revalidate(WITH_DEDUPE) : resolvedUndef;
6014
+ if (!isUndefined(returnedData) && hasKeyButNoData) {
6015
+ revalidation.status = "fulfilled";
6016
+ revalidation.value = true;
6017
+ }
6018
+ use(revalidation);
6019
+ }
6020
+ const swrResponse = {
6021
+ mutate: boundMutate,
6022
+ get data() {
6023
+ stateDependencies.data = true;
6024
+ return returnedData;
6025
+ },
6026
+ get error() {
6027
+ stateDependencies.error = true;
6028
+ return error;
6029
+ },
6030
+ get isValidating() {
6031
+ stateDependencies.isValidating = true;
6032
+ return isValidating;
6033
+ },
6034
+ get isLoading() {
6035
+ stateDependencies.isLoading = true;
6036
+ return isLoading;
6037
+ }
6038
+ };
6039
+ return swrResponse;
6040
+ };
6041
+ const useSWR = withArgs(useSWRHandler);
6042
+ const getFirstPageKey = (getKey) => {
6043
+ return serialize(getKey ? getKey(0, null) : null)[0];
6044
+ };
6045
+ const EMPTY_PROMISE = Promise.resolve();
6046
+ const infinite = (useSWRNext) => (getKey, fn, config) => {
6047
+ const didMountRef = reactExports.useRef(false);
6048
+ const { cache: cache$1, initialSize = 1, revalidateAll = false, persistSize = false, revalidateFirstPage = true, revalidateOnMount = false, parallel = false } = config;
6049
+ const [, , , PRELOAD] = SWRGlobalState.get(cache);
6050
+ let infiniteKey;
6051
+ try {
6052
+ infiniteKey = getFirstPageKey(getKey);
6053
+ if (infiniteKey) infiniteKey = INFINITE_PREFIX + infiniteKey;
6054
+ } catch (err) {
6055
+ }
6056
+ const [get2, set2, subscribeCache] = createCacheHelper(cache$1, infiniteKey);
6057
+ const getSnapshot = reactExports.useCallback(() => {
6058
+ const size = isUndefined(get2()._l) ? initialSize : get2()._l;
6059
+ return size;
6060
+ }, [
6061
+ cache$1,
6062
+ infiniteKey,
6063
+ initialSize
6064
+ ]);
6065
+ shimExports.useSyncExternalStore(reactExports.useCallback(
6066
+ (callback) => {
6067
+ if (infiniteKey) return subscribeCache(infiniteKey, () => {
6068
+ callback();
6069
+ });
6070
+ return () => {
6071
+ };
6072
+ },
6073
+ // eslint-disable-next-line react-hooks/exhaustive-deps
6074
+ [
6075
+ cache$1,
6076
+ infiniteKey
6077
+ ]
6078
+ ), getSnapshot, getSnapshot);
6079
+ const resolvePageSize = reactExports.useCallback(() => {
6080
+ const cachedPageSize = get2()._l;
6081
+ return isUndefined(cachedPageSize) ? initialSize : cachedPageSize;
6082
+ }, [
6083
+ infiniteKey,
6084
+ initialSize
6085
+ ]);
6086
+ const lastPageSizeRef = reactExports.useRef(resolvePageSize());
6087
+ useIsomorphicLayoutEffect$1(() => {
6088
+ if (!didMountRef.current) {
6089
+ didMountRef.current = true;
6090
+ return;
6091
+ }
6092
+ if (infiniteKey) {
6093
+ set2({
6094
+ _l: persistSize ? lastPageSizeRef.current : resolvePageSize()
6095
+ });
6096
+ }
6097
+ }, [
6098
+ infiniteKey,
6099
+ cache$1
6100
+ ]);
6101
+ const shouldRevalidateOnMount = revalidateOnMount && !didMountRef.current;
6102
+ const swr = useSWRNext(infiniteKey, async (key) => {
6103
+ const forceRevalidateAll = get2()._i;
6104
+ const shouldRevalidatePage = get2()._r;
6105
+ const state = SWRGlobalState.get(cache$1);
6106
+ const unloadGeneration = state[8];
6107
+ const unloadedDuringRequest = () => state[8] !== unloadGeneration;
6108
+ set2({
6109
+ _r: UNDEFINED
6110
+ });
6111
+ const data = [];
6112
+ const pageSize = resolvePageSize();
6113
+ const [getCache] = createCacheHelper(cache$1, key);
6114
+ const cacheData = getCache().data;
6115
+ const revalidators = [];
6116
+ let previousPageData = null;
6117
+ for (let i = 0; i < pageSize; ++i) {
6118
+ const [pageKey, pageArg] = serialize(getKey(i, parallel ? null : previousPageData));
6119
+ if (!pageKey) {
6120
+ break;
6121
+ }
6122
+ const [getSWRCache, setSWRCache] = createCacheHelper(cache$1, pageKey);
6123
+ let pageData = getSWRCache().data;
6124
+ const shouldFetchPage = revalidateAll || forceRevalidateAll || isUndefined(pageData) || revalidateFirstPage && !i && !isUndefined(cacheData) || shouldRevalidateOnMount || cacheData && !isUndefined(cacheData[i]) && !config.compare(cacheData[i], pageData);
6125
+ if (fn && (typeof shouldRevalidatePage === "function" ? shouldRevalidatePage(pageData, pageArg) : shouldFetchPage)) {
6126
+ const revalidate = async () => {
6127
+ const hasPreloadedRequest = pageKey in PRELOAD;
6128
+ if (!hasPreloadedRequest) {
6129
+ pageData = await fn(pageArg);
6130
+ } else {
6131
+ const req = PRELOAD[pageKey];
6132
+ delete PRELOAD[pageKey];
6133
+ pageData = await req;
6134
+ }
6135
+ if (!unloadedDuringRequest()) {
6136
+ setSWRCache({
6137
+ data: pageData,
6138
+ _k: pageArg
6139
+ });
6140
+ }
6141
+ data[i] = pageData;
6142
+ };
6143
+ if (parallel) {
6144
+ revalidators.push(revalidate);
6145
+ } else {
6146
+ await revalidate();
6147
+ }
6148
+ } else {
6149
+ data[i] = pageData;
6150
+ }
6151
+ if (!parallel) {
6152
+ previousPageData = pageData;
6153
+ }
6154
+ }
6155
+ if (parallel) {
6156
+ await Promise.all(revalidators.map((r) => r()));
6157
+ }
6158
+ if (!unloadedDuringRequest()) {
6159
+ set2({
6160
+ _i: UNDEFINED
6161
+ });
6162
+ }
6163
+ return data;
6164
+ }, config);
6165
+ const mutate2 = reactExports.useCallback(
6166
+ // eslint-disable-next-line func-names
6167
+ function(data, opts) {
6168
+ const options = typeof opts === "boolean" ? {
6169
+ revalidate: opts
6170
+ } : opts || {};
6171
+ const shouldRevalidate = options.revalidate !== false;
6172
+ if (!infiniteKey) return EMPTY_PROMISE;
6173
+ if (shouldRevalidate) {
6174
+ if (!isUndefined(data)) {
6175
+ set2({
6176
+ _i: false,
6177
+ _r: options.revalidate
6178
+ });
6179
+ } else {
6180
+ set2({
6181
+ _i: true,
6182
+ _r: options.revalidate
6183
+ });
6184
+ }
6185
+ }
6186
+ return arguments.length ? swr.mutate(data, {
6187
+ ...options,
6188
+ revalidate: shouldRevalidate
6189
+ }) : swr.mutate();
6190
+ },
6191
+ // swr.mutate is always the same reference
6192
+ // eslint-disable-next-line react-hooks/exhaustive-deps
6193
+ [
6194
+ infiniteKey,
6195
+ cache$1
6196
+ ]
6197
+ );
6198
+ const setSize = reactExports.useCallback(
6199
+ (arg) => {
6200
+ if (!infiniteKey) return EMPTY_PROMISE;
6201
+ const [, changeSize] = createCacheHelper(cache$1, infiniteKey);
6202
+ let size;
6203
+ if (isFunction(arg)) {
6204
+ size = arg(resolvePageSize());
6205
+ } else if (typeof arg == "number") {
6206
+ size = arg;
6207
+ }
6208
+ if (typeof size != "number") return EMPTY_PROMISE;
6209
+ changeSize({
6210
+ _l: size
6211
+ });
6212
+ lastPageSizeRef.current = size;
6213
+ const data = [];
6214
+ const [getInfiniteCache] = createCacheHelper(cache$1, infiniteKey);
6215
+ let previousPageData = null;
6216
+ for (let i = 0; i < size; ++i) {
6217
+ const [pageKey] = serialize(getKey(i, previousPageData));
6218
+ const [getCache] = createCacheHelper(cache$1, pageKey);
6219
+ const pageData = pageKey ? getCache().data : UNDEFINED;
6220
+ if (isUndefined(pageData)) {
6221
+ return mutate2(getInfiniteCache().data);
6222
+ }
6223
+ data.push(pageData);
6224
+ previousPageData = pageData;
6225
+ }
6226
+ return mutate2(data);
6227
+ },
6228
+ // exclude getKey from the dependencies, which isn't allowed to change during the lifecycle
6229
+ // eslint-disable-next-line react-hooks/exhaustive-deps
6230
+ [
6231
+ infiniteKey,
6232
+ cache$1,
6233
+ mutate2,
6234
+ resolvePageSize
6235
+ ]
6236
+ );
6237
+ return {
6238
+ size: resolvePageSize(),
6239
+ setSize,
6240
+ mutate: mutate2,
6241
+ get data() {
6242
+ return swr.data;
6243
+ },
6244
+ get error() {
6245
+ return swr.error;
6246
+ },
6247
+ get isValidating() {
6248
+ return swr.isValidating;
6249
+ },
6250
+ get isLoading() {
6251
+ return swr.isLoading;
6252
+ }
6253
+ };
6254
+ };
6255
+ const useSWRInfinite = withMiddleware(useSWR, infinite);
4956
6256
  const OBSERVABILITY_UPGRADE_REQUIRED_CODE = "observability-upgrade-required";
4957
6257
  const OBSERVABILITY_UPGRADE_REQUIRED_MESSAGE = "This workflow observability data is outside your current plan window. Upgrade Observability Plus to view up to 30 days of workflow data.";
4958
6258
  const OBSERVABILITY_UPGRADE_REQUIRED_TITLE = "Upgrade Observability Plus";
@@ -5033,6 +6333,101 @@ async function unwrapOrThrow(promise) {
5033
6333
  if (error) throw error;
5034
6334
  return result;
5035
6335
  }
6336
+ function useInfiniteList(cacheKey, fetchFn, getItemKey, options = {}) {
6337
+ var _a2;
6338
+ const { keepPreviousData = true, revalidateCached = false } = options;
6339
+ const getKey = reactExports.useCallback(
6340
+ (_index, prev) => {
6341
+ if (prev && (!prev.hasMore || !prev.cursor)) return null;
6342
+ return [cacheKey, (prev == null ? void 0 : prev.cursor) ?? null];
6343
+ },
6344
+ [cacheKey]
6345
+ );
6346
+ const {
6347
+ data: pages,
6348
+ error,
6349
+ isLoading,
6350
+ isValidating,
6351
+ size,
6352
+ setSize,
6353
+ mutate: mutate2
6354
+ } = useSWRInfinite(
6355
+ getKey,
6356
+ ([, cursor]) => fetchFn(cursor ?? void 0),
6357
+ {
6358
+ revalidateFirstPage: false,
6359
+ revalidateIfStale: false,
6360
+ revalidateOnFocus: false,
6361
+ keepPreviousData
6362
+ }
6363
+ );
6364
+ const items = reactExports.useMemo(() => {
6365
+ if (!pages) return [];
6366
+ const seen = /* @__PURE__ */ new Set();
6367
+ const result = [];
6368
+ for (const page of pages) {
6369
+ for (const item of page.data) {
6370
+ const key = getItemKey(item);
6371
+ if (seen.has(key)) continue;
6372
+ seen.add(key);
6373
+ result.push(item);
6374
+ }
6375
+ }
6376
+ return result;
6377
+ }, [pages, getItemKey]);
6378
+ const lastPage = pages == null ? void 0 : pages[pages.length - 1];
6379
+ const hasMore = Boolean((lastPage == null ? void 0 : lastPage.hasMore) && (lastPage == null ? void 0 : lastPage.cursor));
6380
+ const isLoadingMore = size > 0 && Boolean(pages) && pages.length < size;
6381
+ const loadMore = reactExports.useCallback(() => {
6382
+ if (isValidating || !hasMore) return;
6383
+ void setSize((s) => s + 1);
6384
+ }, [isValidating, hasMore, setSize]);
6385
+ const reload = reactExports.useCallback(() => {
6386
+ void setSize(1);
6387
+ void mutate2();
6388
+ }, [setSize, mutate2]);
6389
+ reactExports.useEffect(() => {
6390
+ if (revalidateCached && pages && !isLoading) void mutate2();
6391
+ }, [cacheKey]);
6392
+ const normalizedError = error ? error instanceof Error ? error : new WorkflowWebAPIError(String(error), { layer: "client" }) : null;
6393
+ return {
6394
+ items,
6395
+ error: normalizedError,
6396
+ isLoading,
6397
+ isLoadingMore,
6398
+ hasMore,
6399
+ loadMore,
6400
+ reload,
6401
+ pageInfo: (_a2 = pages == null ? void 0 : pages[0]) == null ? void 0 : _a2.pageInfo
6402
+ };
6403
+ }
6404
+ function useWorkflowRunsInfinite(env, params) {
6405
+ const {
6406
+ workflowName,
6407
+ status,
6408
+ limit = 25,
6409
+ sortOrder = "desc",
6410
+ startTime,
6411
+ endTime
6412
+ } = params;
6413
+ const cacheKey = `workflow-runs:${workflowName ?? ""}:${status ?? ""}:${sortOrder}:${limit}:${startTime ?? ""}:${endTime ?? ""}`;
6414
+ const fetchFn = reactExports.useCallback(
6415
+ (cursor) => unwrapOrThrow(
6416
+ fetchRuns(env, {
6417
+ cursor,
6418
+ sortOrder,
6419
+ limit,
6420
+ workflowName,
6421
+ status,
6422
+ startTime,
6423
+ endTime
6424
+ })
6425
+ ),
6426
+ [env, workflowName, limit, sortOrder, status, startTime, endTime]
6427
+ );
6428
+ const getItemKey = reactExports.useCallback((run) => run.runId, []);
6429
+ return useInfiniteList(cacheKey, fetchFn, getItemKey);
6430
+ }
5036
6431
  async function cancelRun(env, runId) {
5037
6432
  await unwrapOrThrow(cancelRun$1(env, runId));
5038
6433
  }
@@ -5189,7 +6584,7 @@ function StatusBadge({
5189
6584
  ),
5190
6585
  /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-muted-foreground text-xs font-medium capitalize", children: status })
5191
6586
  ] }),
5192
- durationMs !== void 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-muted-foreground/70 text-xs", children: [
6587
+ durationMs !== void 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-gray-700 text-xs", children: [
5193
6588
  "(",
5194
6589
  formatDuration(durationMs),
5195
6590
  ")"
@@ -5732,8 +7127,8 @@ var TabsContent$1 = /* @__PURE__ */ reactExports.forwardRef(
5732
7127
  const isSelected = value === context.value;
5733
7128
  const isMountAnimationPreventedRef = reactExports.useRef(isSelected);
5734
7129
  reactExports.useEffect(() => {
5735
- const rAF = requestAnimationFrame(() => isMountAnimationPreventedRef.current = false);
5736
- return () => cancelAnimationFrame(rAF);
7130
+ const rAF2 = requestAnimationFrame(() => isMountAnimationPreventedRef.current = false);
7131
+ return () => cancelAnimationFrame(rAF2);
5737
7132
  }, []);
5738
7133
  return /* @__PURE__ */ jsxRuntimeExports.jsx(Presence, { present: forceMount || isSelected, children: ({ present }) => /* @__PURE__ */ jsxRuntimeExports.jsx(
5739
7134
  Primitive.div,
@@ -6173,10 +7568,10 @@ function selection_order() {
6173
7568
  }
6174
7569
  return this;
6175
7570
  }
6176
- function selection_sort(compare) {
6177
- if (!compare) compare = ascending;
7571
+ function selection_sort(compare2) {
7572
+ if (!compare2) compare2 = ascending;
6178
7573
  function compareNode(a, b) {
6179
- return a && b ? compare(a.__data__, b.__data__) : !a - !b;
7574
+ return a && b ? compare2(a.__data__, b.__data__) : !a - !b;
6180
7575
  }
6181
7576
  for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
6182
7577
  for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
@@ -8690,8 +10085,8 @@ const getNodesInside = (nodes, rect, [tx, ty, tScale] = [0, 0, 1], partially = f
8690
10085
  const area = width * height;
8691
10086
  const partiallyVisible = partially && overlappingArea > 0;
8692
10087
  const forceInitialRender = !node.internals.handleBounds;
8693
- const isVisible = forceInitialRender || partiallyVisible || overlappingArea >= area;
8694
- if (isVisible || node.dragging) {
10088
+ const isVisible2 = forceInitialRender || partiallyVisible || overlappingArea >= area;
10089
+ if (isVisible2 || node.dragging) {
8695
10090
  visibleNodes.push(node);
8696
10091
  }
8697
10092
  }
@@ -8708,14 +10103,14 @@ function getFitViewNodes(nodeLookup, options) {
8708
10103
  const fitViewNodes = /* @__PURE__ */ new Map();
8709
10104
  const optionNodeIds = (options == null ? void 0 : options.nodes) ? new Set(options.nodes.map((node) => node.id)) : null;
8710
10105
  nodeLookup.forEach((n) => {
8711
- let isVisible;
10106
+ let isVisible2;
8712
10107
  if (options == null ? void 0 : options.includeHiddenNodes) {
8713
10108
  const { width, height } = getNodeDimensions(n);
8714
- isVisible = width > 0 && height > 0;
10109
+ isVisible2 = width > 0 && height > 0;
8715
10110
  } else {
8716
- isVisible = Boolean(n.measured.width && n.measured.height && !n.hidden);
10111
+ isVisible2 = Boolean(n.measured.width && n.measured.height && !n.hidden);
8717
10112
  }
8718
- if (isVisible && (!optionNodeIds || optionNodeIds.has(n.id))) {
10113
+ if (isVisible2 && (!optionNodeIds || optionNodeIds.has(n.id))) {
8719
10114
  fitViewNodes.set(n.id, n);
8720
10115
  }
8721
10116
  });
@@ -11966,8 +13361,8 @@ function BatchProvider({ children: children2 }) {
11966
13361
  items: next,
11967
13362
  lookup: nodeLookup
11968
13363
  });
11969
- for (const middleware of onNodesChangeMiddlewareMap.values()) {
11970
- changes = middleware(changes);
13364
+ for (const middleware2 of onNodesChangeMiddlewareMap.values()) {
13365
+ changes = middleware2(changes);
11971
13366
  }
11972
13367
  if (hasDefaultNodes) {
11973
13368
  setNodes(next);
@@ -14040,8 +15435,8 @@ const createStore = ({ nodes, edges, defaultNodes, defaultEdges, width, height,
14040
15435
  const parentExpandChanges = handleExpandParent(parentExpandChildren, nodeLookup, parentLookup, nodeOrigin2);
14041
15436
  changes.push(...parentExpandChanges);
14042
15437
  }
14043
- for (const middleware of onNodesChangeMiddlewareMap.values()) {
14044
- changes = middleware(changes);
15438
+ for (const middleware2 of onNodesChangeMiddlewareMap.values()) {
15439
+ changes = middleware2(changes);
14045
15440
  }
14046
15441
  triggerNodeChanges(changes);
14047
15442
  },
@@ -14775,7 +16170,7 @@ function ParallelGroupComponent({ data }) {
14775
16170
  left: 12,
14776
16171
  fontSize: 11,
14777
16172
  fontWeight: 600,
14778
- color: "rgba(59, 130, 246, 0.8)",
16173
+ color: "var(--ds-blue-800)",
14779
16174
  textTransform: "uppercase",
14780
16175
  letterSpacing: "0.5px",
14781
16176
  pointerEvents: "none"
@@ -15782,8 +17177,36 @@ function getState(open) {
15782
17177
  return open ? "open" : "closed";
15783
17178
  }
15784
17179
  __name(getState, "getState");
17180
+ function useOptimisticSearchParams() {
17181
+ const [searchParams] = useSearchParams();
17182
+ const navigate = useNavigate();
17183
+ const [optimisticParams, setOptimisticParams] = reactExports.useOptimistic(searchParams);
17184
+ const [, startTransition] = reactExports.useTransition();
17185
+ const updateSearchParams = reactExports.useCallback(
17186
+ (updates, options) => {
17187
+ const next = new URLSearchParams(optimisticParams);
17188
+ for (const [key, value] of Object.entries(updates)) {
17189
+ if (value === null) {
17190
+ next.delete(key);
17191
+ } else {
17192
+ next.set(key, value);
17193
+ }
17194
+ }
17195
+ const search = next.toString();
17196
+ startTransition(async () => {
17197
+ setOptimisticParams(next);
17198
+ await navigate(
17199
+ { search: search ? `?${search}` : "" },
17200
+ { preventScrollReset: true, ...options }
17201
+ );
17202
+ });
17203
+ },
17204
+ [navigate, optimisticParams, setOptimisticParams]
17205
+ );
17206
+ return [optimisticParams, updateSearchParams];
17207
+ }
15785
17208
  export {
15786
- Circle as $,
17209
+ ErrorCard as $,
15787
17210
  Alert as A,
15788
17211
  Dialog as B,
15789
17212
  CircleAlert as C,
@@ -15797,28 +17220,30 @@ export {
15797
17220
  DialogOverlay as K,
15798
17221
  unwrapServerActionResult as L,
15799
17222
  WorkflowGraphViewer as M,
15800
- TabsList as N,
15801
- TabsTrigger as O,
15802
- TabsContent as P,
15803
- ErrorBoundary as Q,
17223
+ useOptimisticSearchParams as N,
17224
+ TabsList as O,
17225
+ TabsTrigger as P,
17226
+ TabsContent as Q,
15804
17227
  ResolveHookModal as R,
15805
17228
  Send as S,
15806
17229
  Tabs as T,
15807
- parseStepName as U,
15808
- findStartHookCreation as V,
17230
+ ErrorBoundary as U,
17231
+ parseStepName as V,
15809
17232
  WorkflowWebAPIError as W,
15810
17233
  X,
15811
- ErrorCard as Y,
17234
+ findStartHookCreation as Y,
15812
17235
  Zap as Z,
15813
- format as _,
17236
+ Circle as _,
15814
17237
  Skeleton as a,
15815
- createDialogScope as a0,
15816
- DialogTrigger as a1,
15817
- LAYOUT as a2,
15818
- wakeUpRun as a3,
15819
- RunActionsButtons as a4,
15820
- cancelRun as a5,
15821
- recreateRun as a6,
17238
+ format as a0,
17239
+ useInfiniteList as a1,
17240
+ createDialogScope as a2,
17241
+ DialogTrigger as a3,
17242
+ LAYOUT as a4,
17243
+ wakeUpRun as a5,
17244
+ RunActionsButtons as a6,
17245
+ cancelRun as a7,
17246
+ recreateRun as a8,
15822
17247
  RelativeTime as b,
15823
17248
  AlertTitle as c,
15824
17249
  AlertDescription as d,
@@ -15829,14 +17254,14 @@ export {
15829
17254
  DropdownMenuTrigger as i,
15830
17255
  DropdownMenuContent as j,
15831
17256
  DropdownMenuItem as k,
15832
- resumeHook as l,
15833
- useDirection as m,
15834
- createCollection as n,
15835
- hideOthers as o,
15836
- useFocusGuards as p,
15837
- ReactRemoveScroll as q,
15838
- requireShim as r,
15839
- ChevronUp as s,
17257
+ useDirection as l,
17258
+ createCollection as m,
17259
+ hideOthers as n,
17260
+ useFocusGuards as o,
17261
+ ReactRemoveScroll as p,
17262
+ ChevronUp as q,
17263
+ resumeHook as r,
17264
+ useWorkflowRunsInfinite as s,
15840
17265
  bulkCancelRuns as t,
15841
17266
  unwrapOrThrow as u,
15842
17267
  reenqueueRun as v,