@brickkit/cli 0.11.0 → 0.13.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/dashboard-dist/CollapsiblePanel-CbUysOp5.js +2 -0
- package/dashboard-dist/CompositeRoot-D4sRkYq3.js +1 -0
- package/dashboard-dist/Geist-Variable.woff2 +0 -0
- package/dashboard-dist/GeistMono-Variable.woff2 +0 -0
- package/dashboard-dist/PopoverPopup-CiI2avT_.js +1 -0
- package/dashboard-dist/api-reference-mT9VNcPb.js +265 -0
- package/dashboard-dist/app.css +2 -2
- package/dashboard-dist/app.js +12 -13
- package/dashboard-dist/ccount-CcG1m-Yh.js +1 -0
- package/dashboard-dist/client-CwATkLJa.js +1 -0
- package/dashboard-dist/core-BEUWp6B5.js +1 -0
- package/dashboard-dist/docs-BRrtyxDB.js +4 -0
- package/dashboard-dist/docs.css +1 -1
- package/dashboard-dist/kit.js +1 -1
- package/dashboard-dist/popover-Bj9x-88h.js +1 -0
- package/dist/bin.d.ts +0 -2
- package/dist/bin.js +309 -211
- package/dist/bin.js.map +1 -1
- package/dist/build.js +463 -0
- package/dist/build.js.map +1 -0
- package/dist/client-contract-file.js +356 -1
- package/dist/client-contract-file.js.map +1 -0
- package/dist/compiler.d.ts +12 -3
- package/dist/compiler.js +1 -1
- package/dist/compiler2.js +13 -7
- package/dist/compiler2.js.map +1 -1
- package/dist/config.d.ts +3 -0
- package/dist/config.js +1 -252
- package/dist/config2.d.ts +122 -0
- package/dist/config2.js +207 -0
- package/dist/config2.js.map +1 -0
- package/dist/dashboard-extension.d.ts +3 -2
- package/dist/{dev-telemetry-store.js → dashboard-host.js} +1381 -1432
- package/dist/dashboard-host.js.map +1 -0
- package/dist/dashboard-protocol.js +189 -0
- package/dist/dashboard-protocol.js.map +1 -0
- package/dist/dashboard.d.ts +8 -135
- package/dist/definitions.js +33 -0
- package/dist/definitions.js.map +1 -0
- package/dist/dev-application.js +34 -0
- package/dist/dev-application.js.map +1 -0
- package/dist/dev-protocol.js +21 -0
- package/dist/dev-protocol.js.map +1 -0
- package/dist/dev-reporter.d.ts +0 -2
- package/dist/dev-reporter.js +3 -3
- package/dist/dev-reporter.js.map +1 -1
- package/dist/dev-telemetry.js +8 -24
- package/dist/dev-telemetry.js.map +1 -1
- package/dist/dev-worker.js +80 -21
- package/dist/dev-worker.js.map +1 -1
- package/dist/index.d.ts +18 -87
- package/dist/index.js +12 -6
- package/dist/index.js.map +1 -0
- package/dist/lint/oxlint.d.ts +0 -2
- package/dist/lint/oxlint.js +6 -5
- package/dist/lint/oxlint.js.map +1 -1
- package/dist/own-module.js +7 -0
- package/dist/own-module.js.map +1 -0
- package/dist/plugin.d.ts +6 -11
- package/dist/plugin.js +6 -42
- package/dist/plugin.js.map +1 -1
- package/dist/production-dashboard.d.ts +2 -0
- package/dist/production-dashboard.js +51 -0
- package/dist/production-dashboard.js.map +1 -0
- package/dist/production-dashboard2.d.ts +34 -0
- package/dist/{presets.js → project.js} +107 -113
- package/dist/project.js.map +1 -0
- package/dist/serve.d.ts +24 -0
- package/dist/serve.js +1 -0
- package/dist/serve2.js +49 -0
- package/dist/serve2.js.map +1 -0
- package/dist/vite.d.ts +0 -2
- package/dist/vite.js +28 -51
- package/dist/vite.js.map +1 -1
- package/dist/workflows.d.ts +2 -4
- package/dist/workflows2.js +60 -39
- package/dist/workflows2.js.map +1 -1
- package/inspector-dist/client/assets/api.rpc-BvRk9kiK.js +0 -0
- package/inspector-dist/client/assets/api.stream._streamId-BvRk9kiK.js +0 -0
- package/inspector-dist/client/assets/app-CeSwVsRm.css +2 -0
- package/inspector-dist/client/assets/dist-BK8w6xOr.js +3930 -0
- package/inspector-dist/client/assets/dist-CG2aVufI.js +197 -0
- package/inspector-dist/client/assets/entry.client-D9jbgmTR.js +9391 -0
- package/inspector-dist/client/assets/highlighted-body-B3W2YXNL-CfRnuITN.js +34 -0
- package/inspector-dist/client/assets/home-hwPlkNhv.js +4034 -0
- package/inspector-dist/client/assets/jsx-runtime-CPEah4WQ.js +7084 -0
- package/inspector-dist/client/assets/manifest-0e76e9ac.js +1 -0
- package/inspector-dist/client/assets/mermaid-3ZIDBTTL-ZDR2PNY_.js +1 -0
- package/inspector-dist/client/assets/root-ChBNTZd2.css +2 -0
- package/inspector-dist/client/assets/root-SLeEf-sT.js +320 -0
- package/inspector-dist/client/assets/run-detail-DYbVkIFH.js +1871 -0
- package/inspector-dist/client/assets/tabs-CaJisoyb.js +73751 -0
- package/inspector-dist/client/assets/tabs-L5XKzOpP.css +1 -0
- package/inspector-dist/client/assets/zstd-browser-decoder-D94wmfAU.js +41 -0
- package/inspector-dist/server/assets/app-DGlfWVUI.js +99330 -0
- package/inspector-dist/server/assets/chunk-RLXIAIE6-F0SJZlei.js +42975 -0
- package/inspector-dist/server/assets/dist-BCbwm6jl.js +10325 -0
- package/inspector-dist/server/assets/dist-CG2aVufI.js +197 -0
- package/inspector-dist/server/assets/dist-Ce0I2PUv.js +1137 -0
- package/inspector-dist/server/assets/dist-DY0UlahA.js +1642 -0
- package/inspector-dist/server/assets/encryption-DdQgC8Rk.js +886 -0
- package/inspector-dist/server/assets/event-metadata-n7E4zEmT.js +145 -0
- package/inspector-dist/server/assets/functions-CNVQtbgg.js +1170 -0
- package/inspector-dist/server/assets/global-singleton-D8sIN5du.js +80 -0
- package/inspector-dist/server/assets/highlighted-body-B3W2YXNL-CWRzMxYD.js +34 -0
- package/inspector-dist/server/assets/mermaid-3ZIDBTTL-D0v0ngVr.js +1 -0
- package/inspector-dist/server/assets/parse-Begau9cA.js +469 -0
- package/inspector-dist/server/assets/rolldown-runtime-C1I3wEg2.js +43 -0
- package/inspector-dist/server/assets/serialization-format-BbuGfHog.js +476 -0
- package/inspector-dist/server/assets/token-BgMmJNP5.js +60 -0
- package/inspector-dist/server/assets/token-BrUX0bxz.js +55 -0
- package/inspector-dist/server/assets/token-util-DZN32qmT.js +455 -0
- package/inspector-dist/server/assets/wrapper-CIC3w0oC.js +3624 -0
- package/inspector-dist/server/assets/ws-transport-CxTYB11n.js +29476 -0
- package/inspector-dist/server/assets/zstd-browser-decoder-D7bCXbGg.js +38 -0
- package/inspector-dist/server/index.js +1 -58
- package/package.json +39 -28
- package/vite-client.d.ts +1 -1
- package/dashboard-dist/CollapsiblePanel-BX79_W-b.js +0 -2
- package/dashboard-dist/CompositeRoot-xzybXjnx.js +0 -1
- package/dashboard-dist/PopoverPopup-CvlmC7EL.js +0 -1
- package/dashboard-dist/api-reference-BcAYVYwJ.js +0 -260
- package/dashboard-dist/core-BGO9JZ1r.js +0 -1
- package/dashboard-dist/docs-DHikPD2v.js +0 -4
- package/dashboard-dist/popover-DG498XHH.js +0 -1
- package/dist/app-entry.js +0 -1
- package/dist/app-entry2.js +0 -19
- package/dist/app-entry2.js.map +0 -1
- package/dist/bin.d.ts.map +0 -1
- package/dist/client-contract-file2.js +0 -34
- package/dist/client-contract-file2.js.map +0 -1
- package/dist/client-contract.js +0 -1
- package/dist/client-contract2.js +0 -294
- package/dist/client-contract2.js.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/dashboard-extension.d.ts.map +0 -1
- package/dist/dev-reporter.d.ts.map +0 -1
- package/dist/dev-telemetry-store.js.map +0 -1
- package/dist/emit.d.ts +0 -7
- package/dist/emit.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/lint/oxlint.d.ts.map +0 -1
- package/dist/plugin.d.ts.map +0 -1
- package/dist/presets.js.map +0 -1
- package/dist/runner.js +0 -523
- package/dist/runner.js.map +0 -1
- package/dist/vite.d.ts.map +0 -1
- package/dist/workflows.d.ts.map +0 -1
- package/inspector-dist/client/assets/api.rpc-l0sNRNKZ.js +0 -1
- package/inspector-dist/client/assets/api.stream._streamId-l0sNRNKZ.js +0 -1
- package/inspector-dist/client/assets/app-CvoGgWcV.css +0 -1
- package/inspector-dist/client/assets/entry.client-BJ6G3n5t.js +0 -11697
- package/inspector-dist/client/assets/highlighted-body-B3W2YXNL-C-3wZnxf.js +0 -19
- package/inspector-dist/client/assets/home-CSKAS4P2.js +0 -4979
- package/inspector-dist/client/assets/index-DECCyMR0.js +0 -4482
- package/inspector-dist/client/assets/index-Dot7CgrA.js +0 -9837
- package/inspector-dist/client/assets/index-HqNj_XIX.js +0 -200
- package/inspector-dist/client/assets/manifest-139c9319.js +0 -1
- package/inspector-dist/client/assets/mermaid-3ZIDBTTL-DC0K8uTy.js +0 -58626
- package/inspector-dist/client/assets/mermaid-3ZIDBTTL-F88p7PFX.css +0 -1
- package/inspector-dist/client/assets/root-BMHd_XHz.css +0 -1
- package/inspector-dist/client/assets/root-cbi6iYwg.js +0 -305
- package/inspector-dist/client/assets/run-detail-CWoGxu_0.css +0 -1
- package/inspector-dist/client/assets/run-detail-Cc7tSGNq.js +0 -6237
- package/inspector-dist/client/assets/world-config-context-BAD1QCrR.js +0 -26
- package/inspector-dist/client/assets/zstd-browser-decoder-BQoRpP7L.js +0 -28
- package/inspector-dist/server/assets/app-DUP5RybL.js +0 -174880
- package/inspector-dist/server/assets/highlighted-body-B3W2YXNL-D2g4hL2-.js +0 -71
- package/inspector-dist/server/assets/index-BfLBLRRi.js +0 -204
- package/inspector-dist/server/assets/index-BzrGWk7J.js +0 -1164
- package/inspector-dist/server/assets/index-D71yP6AL.js +0 -191
- package/inspector-dist/server/assets/index-wGSWRns3.js +0 -1296
- package/inspector-dist/server/assets/mermaid-3ZIDBTTL-DsvuKoEV.js +0 -58
- package/inspector-dist/server/assets/token-ClUZZwXl.js +0 -95
- package/inspector-dist/server/assets/token-util-DSxMZ6nI.js +0 -33
- package/inspector-dist/server/assets/wrapper-B3vstpCO.js +0 -67
- package/inspector-dist/server/assets/zstd-browser-decoder-Dn82m2BU.js +0 -77
|
@@ -0,0 +1,4034 @@
|
|
|
1
|
+
import { D as useLocation, F as require_react, I as __commonJSMin, M as withComponentProps, O as useNavigate, P as require_react_dom, R as __toESM, j as useSearchParams, r as Link, t as require_jsx_runtime } from "./jsx-runtime-CPEah4WQ.js";
|
|
2
|
+
import { A as PopperContent, B as useCallbackRef, Bt as ChevronRight, C as DropdownMenuTrigger, D as Portal, E as Presence, Ft as Ellipsis, G as useControllableState, H as createCollection, Ht as Check, It as Copy, J as useComposedRefs, K as useLayoutEffect2, L as useFocusGuards, Lt as CircleX, M as useSize, Mt as Zap, N as useId, Nt as X, O as Popper, P as FocusScope, Q as AlertTitle, R as DismissableLayer, Rt as CircleAlert, S as DropdownMenuItem, T as hideOthers, U as Primitive, Ut as createLucideIcon, V as useDirection, Vt as ChevronDown, W as createSlot, Wt as parseWorkflowName, X as Alert, Y as composeEventHandlers, Z as AlertDescription, _ as unwrapOrThrow, b as DropdownMenu, c as STATUS_COLORS, d as rpc, dt as ResolveHookDropdownItem, et as cn, ft as useHookActions, g as getErrorMessage, gt as TooltipTrigger, h as WorkflowWebAPIError, ht as TooltipContent, i as TabsTrigger, j as createPopperScope, jt as ErrorBoundary, k as PopperAnchor, l as Skeleton, mt as Tooltip, n as TabsContent, o as RunActionsDropdownItems, q as createContextScope, r as TabsList, s as StatusBadge, t as Tabs, tt as getPaginationDisplay, u as RelativeTime, ut as HookResolveModalWrapper, vt as Button, w as ReactRemoveScroll, x as DropdownMenuContent, y as CopyableText, zt as ChevronUp } from "./tabs-CaJisoyb.js";
|
|
3
|
+
import { n as toast } from "./dist-BK8w6xOr.js";
|
|
4
|
+
/**
|
|
5
|
+
* @license lucide-react v0.575.0 - ISC
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the ISC license.
|
|
8
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
var ArrowDownAZ = createLucideIcon("arrow-down-a-z", [
|
|
11
|
+
["path", {
|
|
12
|
+
d: "m3 16 4 4 4-4",
|
|
13
|
+
key: "1co6wj"
|
|
14
|
+
}],
|
|
15
|
+
["path", {
|
|
16
|
+
d: "M7 20V4",
|
|
17
|
+
key: "1yoxec"
|
|
18
|
+
}],
|
|
19
|
+
["path", {
|
|
20
|
+
d: "M20 8h-5",
|
|
21
|
+
key: "1vsyxs"
|
|
22
|
+
}],
|
|
23
|
+
["path", {
|
|
24
|
+
d: "M15 10V6.5a2.5 2.5 0 0 1 5 0V10",
|
|
25
|
+
key: "ag13bf"
|
|
26
|
+
}],
|
|
27
|
+
["path", {
|
|
28
|
+
d: "M15 14h5l-5 6h5",
|
|
29
|
+
key: "ur5jdg"
|
|
30
|
+
}]
|
|
31
|
+
]);
|
|
32
|
+
/**
|
|
33
|
+
* @license lucide-react v0.575.0 - ISC
|
|
34
|
+
*
|
|
35
|
+
* This source code is licensed under the ISC license.
|
|
36
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
37
|
+
*/
|
|
38
|
+
var ArrowUpAZ = createLucideIcon("arrow-up-a-z", [
|
|
39
|
+
["path", {
|
|
40
|
+
d: "m3 8 4-4 4 4",
|
|
41
|
+
key: "11wl7u"
|
|
42
|
+
}],
|
|
43
|
+
["path", {
|
|
44
|
+
d: "M7 4v16",
|
|
45
|
+
key: "1glfcx"
|
|
46
|
+
}],
|
|
47
|
+
["path", {
|
|
48
|
+
d: "M20 8h-5",
|
|
49
|
+
key: "1vsyxs"
|
|
50
|
+
}],
|
|
51
|
+
["path", {
|
|
52
|
+
d: "M15 10V6.5a2.5 2.5 0 0 1 5 0V10",
|
|
53
|
+
key: "ag13bf"
|
|
54
|
+
}],
|
|
55
|
+
["path", {
|
|
56
|
+
d: "M15 14h5l-5 6h5",
|
|
57
|
+
key: "ur5jdg"
|
|
58
|
+
}]
|
|
59
|
+
]);
|
|
60
|
+
/**
|
|
61
|
+
* @license lucide-react v0.575.0 - ISC
|
|
62
|
+
*
|
|
63
|
+
* This source code is licensed under the ISC license.
|
|
64
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
65
|
+
*/
|
|
66
|
+
var ChevronLeft = createLucideIcon("chevron-left", [["path", {
|
|
67
|
+
d: "m15 18-6-6 6-6",
|
|
68
|
+
key: "1wnfg3"
|
|
69
|
+
}]]);
|
|
70
|
+
/**
|
|
71
|
+
* @license lucide-react v0.575.0 - ISC
|
|
72
|
+
*
|
|
73
|
+
* This source code is licensed under the ISC license.
|
|
74
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
75
|
+
*/
|
|
76
|
+
var LoaderCircle = createLucideIcon("loader-circle", [["path", {
|
|
77
|
+
d: "M21 12a9 9 0 1 1-6.219-8.56",
|
|
78
|
+
key: "13zald"
|
|
79
|
+
}]]);
|
|
80
|
+
/**
|
|
81
|
+
* @license lucide-react v0.575.0 - ISC
|
|
82
|
+
*
|
|
83
|
+
* This source code is licensed under the ISC license.
|
|
84
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
85
|
+
*/
|
|
86
|
+
var Minus = createLucideIcon("minus", [["path", {
|
|
87
|
+
d: "M5 12h14",
|
|
88
|
+
key: "1ays0h"
|
|
89
|
+
}]]);
|
|
90
|
+
/**
|
|
91
|
+
* @license lucide-react v0.575.0 - ISC
|
|
92
|
+
*
|
|
93
|
+
* This source code is licensed under the ISC license.
|
|
94
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
95
|
+
*/
|
|
96
|
+
var RefreshCw = createLucideIcon("refresh-cw", [
|
|
97
|
+
["path", {
|
|
98
|
+
d: "M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",
|
|
99
|
+
key: "v9h5vc"
|
|
100
|
+
}],
|
|
101
|
+
["path", {
|
|
102
|
+
d: "M21 3v5h-5",
|
|
103
|
+
key: "1q7to0"
|
|
104
|
+
}],
|
|
105
|
+
["path", {
|
|
106
|
+
d: "M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",
|
|
107
|
+
key: "3uifl3"
|
|
108
|
+
}],
|
|
109
|
+
["path", {
|
|
110
|
+
d: "M8 16H3v5",
|
|
111
|
+
key: "1cv678"
|
|
112
|
+
}]
|
|
113
|
+
]);
|
|
114
|
+
// app/components/ui/card.tsx
|
|
115
|
+
var import_react = /* @__PURE__ */ __toESM(require_react(), 1);
|
|
116
|
+
var import_jsx_runtime = require_jsx_runtime();
|
|
117
|
+
var Card = import_react.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
118
|
+
ref,
|
|
119
|
+
className: cn("rounded-lg border bg-card text-card-foreground shadow-sm", className),
|
|
120
|
+
...props
|
|
121
|
+
}));
|
|
122
|
+
Card.displayName = "Card";
|
|
123
|
+
var CardHeader = import_react.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
124
|
+
ref,
|
|
125
|
+
className: cn("flex flex-col space-y-1.5 p-6", className),
|
|
126
|
+
...props
|
|
127
|
+
}));
|
|
128
|
+
CardHeader.displayName = "CardHeader";
|
|
129
|
+
var CardTitle = import_react.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
130
|
+
ref,
|
|
131
|
+
className: cn("text-2xl font-semibold leading-none tracking-tight", className),
|
|
132
|
+
...props
|
|
133
|
+
}));
|
|
134
|
+
CardTitle.displayName = "CardTitle";
|
|
135
|
+
var CardDescription = import_react.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
136
|
+
ref,
|
|
137
|
+
className: cn("text-sm text-muted-foreground", className),
|
|
138
|
+
...props
|
|
139
|
+
}));
|
|
140
|
+
CardDescription.displayName = "CardDescription";
|
|
141
|
+
var CardContent = import_react.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
142
|
+
ref,
|
|
143
|
+
className: cn("p-6 pt-0", className),
|
|
144
|
+
...props
|
|
145
|
+
}));
|
|
146
|
+
CardContent.displayName = "CardContent";
|
|
147
|
+
var CardFooter = import_react.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
148
|
+
ref,
|
|
149
|
+
className: cn("flex items-center p-6 pt-0", className),
|
|
150
|
+
...props
|
|
151
|
+
}));
|
|
152
|
+
CardFooter.displayName = "CardFooter";
|
|
153
|
+
// app/components/ui/docs-link.tsx
|
|
154
|
+
/**
|
|
155
|
+
* A styled link component for documentation links.
|
|
156
|
+
* Automatically prepends the docs base URL if a relative path is provided.
|
|
157
|
+
*/
|
|
158
|
+
var DocsLink = import_react.forwardRef(({ className, href, children, ...props }, ref) => {
|
|
159
|
+
const fullHref = href.startsWith("http") ? href : `https://workflow-sdk.dev/docs/${href.replace(/^\//, "")}`;
|
|
160
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Link, {
|
|
161
|
+
to: fullHref,
|
|
162
|
+
className: cn("font-medium underline underline-offset-4 transition-colors", className),
|
|
163
|
+
style: { color: "var(--ds-blue-600)" },
|
|
164
|
+
target: "_blank",
|
|
165
|
+
rel: "noopener noreferrer",
|
|
166
|
+
ref,
|
|
167
|
+
...props,
|
|
168
|
+
children
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
DocsLink.displayName = "DocsLink";
|
|
172
|
+
// app/components/ui/table.tsx
|
|
173
|
+
var Table = import_react.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
174
|
+
className: "relative w-full overflow-auto",
|
|
175
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("table", {
|
|
176
|
+
ref,
|
|
177
|
+
className: cn("w-full caption-bottom text-sm", className),
|
|
178
|
+
...props
|
|
179
|
+
})
|
|
180
|
+
}));
|
|
181
|
+
Table.displayName = "Table";
|
|
182
|
+
var TableHeader = import_react.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("thead", {
|
|
183
|
+
ref,
|
|
184
|
+
className: cn("[&_tr]:border-b", className),
|
|
185
|
+
...props
|
|
186
|
+
}));
|
|
187
|
+
TableHeader.displayName = "TableHeader";
|
|
188
|
+
var TableBody = import_react.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tbody", {
|
|
189
|
+
ref,
|
|
190
|
+
className: cn("[&_tr:last-child]:border-0", className),
|
|
191
|
+
...props
|
|
192
|
+
}));
|
|
193
|
+
TableBody.displayName = "TableBody";
|
|
194
|
+
var TableFooter = import_react.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tfoot", {
|
|
195
|
+
ref,
|
|
196
|
+
className: cn("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0", className),
|
|
197
|
+
...props
|
|
198
|
+
}));
|
|
199
|
+
TableFooter.displayName = "TableFooter";
|
|
200
|
+
var TableRow = import_react.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", {
|
|
201
|
+
ref,
|
|
202
|
+
className: cn("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted", className),
|
|
203
|
+
...props
|
|
204
|
+
}));
|
|
205
|
+
TableRow.displayName = "TableRow";
|
|
206
|
+
var TableHead = import_react.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", {
|
|
207
|
+
ref,
|
|
208
|
+
className: cn("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0", className),
|
|
209
|
+
...props
|
|
210
|
+
}));
|
|
211
|
+
TableHead.displayName = "TableHead";
|
|
212
|
+
var TableCell = import_react.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
213
|
+
ref,
|
|
214
|
+
className: cn("p-4 align-middle [&:has([role=checkbox])]:pr-0", className),
|
|
215
|
+
...props
|
|
216
|
+
}));
|
|
217
|
+
TableCell.displayName = "TableCell";
|
|
218
|
+
var TableCaption = import_react.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("caption", {
|
|
219
|
+
ref,
|
|
220
|
+
className: cn("mt-4 text-sm text-muted-foreground", className),
|
|
221
|
+
...props
|
|
222
|
+
}));
|
|
223
|
+
TableCaption.displayName = "TableCaption";
|
|
224
|
+
// app/components/display-utils/hook-token-cell.tsx
|
|
225
|
+
/**
|
|
226
|
+
* Renders a hook's secret token as a masked, copy-on-demand cell.
|
|
227
|
+
*
|
|
228
|
+
* The token is not present in hook list rows — it is fetched one hook at a
|
|
229
|
+
* time (via `fetchHookToken`) only when the user clicks to copy it. This keeps
|
|
230
|
+
* the secret out of bulk list responses while preserving the copy affordance.
|
|
231
|
+
*/
|
|
232
|
+
function HookTokenCell({ runId, hookId }) {
|
|
233
|
+
const [status, setStatus] = (0, import_react.useState)("idle");
|
|
234
|
+
const [error, setError] = (0, import_react.useState)(null);
|
|
235
|
+
const handleCopy = async (e) => {
|
|
236
|
+
e.stopPropagation();
|
|
237
|
+
if (status === "loading") return;
|
|
238
|
+
setStatus("loading");
|
|
239
|
+
setError(null);
|
|
240
|
+
try {
|
|
241
|
+
const { token } = await unwrapOrThrow(rpc("fetchHookToken", {
|
|
242
|
+
runId,
|
|
243
|
+
hookId
|
|
244
|
+
}));
|
|
245
|
+
await navigator.clipboard.writeText(token);
|
|
246
|
+
setStatus("copied");
|
|
247
|
+
setTimeout(() => setStatus("idle"), 2e3);
|
|
248
|
+
} catch (err) {
|
|
249
|
+
console.error("Failed to copy hook token:", err);
|
|
250
|
+
setError("Failed to copy token");
|
|
251
|
+
setStatus("idle");
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
255
|
+
className: "relative group/copy inline-block",
|
|
256
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
257
|
+
className: "text-muted-foreground",
|
|
258
|
+
children: "••••••••••••"
|
|
259
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Tooltip, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipTrigger, {
|
|
260
|
+
asChild: true,
|
|
261
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
262
|
+
type: "button",
|
|
263
|
+
onClick: handleCopy,
|
|
264
|
+
disabled: status === "loading",
|
|
265
|
+
className: "absolute right-0 top-1/2 -translate-y-1/2 opacity-0 group-hover/copy:opacity-100 transition-opacity bg-background/80 backdrop-blur-sm p-1 rounded",
|
|
266
|
+
"aria-label": "Copy token",
|
|
267
|
+
children: status === "loading" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoaderCircle, { className: "h-3 w-3 text-muted-foreground animate-spin" }) : status === "copied" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Check, { className: "h-3 w-3 text-muted-foreground" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Copy, { className: "h-3 w-3 text-muted-foreground hover:text-foreground" })
|
|
268
|
+
})
|
|
269
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContent, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: error ? error : status === "copied" ? "Copied!" : status === "loading" ? "Fetching token…" : "Copy token" }) })] })]
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
// app/components/display-utils/table-skeleton.tsx
|
|
273
|
+
/** The hooks table while its first page loads: Hook ID, Run ID, Token, Created, Invocations, Actions. */
|
|
274
|
+
function TableSkeleton({ rows = 10 }) {
|
|
275
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Card, {
|
|
276
|
+
className: "overflow-hidden mt-4 bg-background",
|
|
277
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(CardContent, {
|
|
278
|
+
className: "p-0",
|
|
279
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
280
|
+
className: "grid grid-cols-[1.2fr_1.2fr_0.8fr_1fr_0.5fr_40px] items-center gap-4 py-3 px-4 border-b",
|
|
281
|
+
children: [
|
|
282
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Skeleton, { className: "h-4 w-16" }),
|
|
283
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Skeleton, { className: "h-4 w-14" }),
|
|
284
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Skeleton, { className: "h-4 w-12" }),
|
|
285
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Skeleton, { className: "h-4 w-14" }),
|
|
286
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Skeleton, { className: "h-4 w-20" }),
|
|
287
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "w-6" })
|
|
288
|
+
]
|
|
289
|
+
}), Array.from({ length: rows }, (_, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
290
|
+
className: "grid grid-cols-[1.2fr_1.2fr_0.8fr_1fr_0.5fr_40px] items-center gap-4 py-3 px-4",
|
|
291
|
+
children: [
|
|
292
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Skeleton, { className: "h-4 w-4/5" }),
|
|
293
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Skeleton, { className: "h-4 w-4/5" }),
|
|
294
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Skeleton, { className: "h-4 w-3/4" }),
|
|
295
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Skeleton, { className: "h-3 w-3/4" }),
|
|
296
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Skeleton, { className: "h-4 w-8" }),
|
|
297
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Skeleton, { className: "h-6 w-6 rounded" })
|
|
298
|
+
]
|
|
299
|
+
}, `skeleton-row-${i}`))]
|
|
300
|
+
})
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
// app/lib/client/hooks/use-paginated-list.ts
|
|
304
|
+
/**
|
|
305
|
+
* Generic hook for cursor-based paginated lists with caching and navigation.
|
|
306
|
+
* Callers should memoize `fetchFn` with useCallback to control when data is refetched.
|
|
307
|
+
*/
|
|
308
|
+
function usePaginatedList(fetchFn) {
|
|
309
|
+
const [cursor, setCursor] = (0, import_react.useState)(void 0);
|
|
310
|
+
const [hasMore, setHasMore] = (0, import_react.useState)(false);
|
|
311
|
+
const [currentPage, setCurrentPage] = (0, import_react.useState)(0);
|
|
312
|
+
const [pageHistory, setPageHistory] = (0, import_react.useState)([void 0]);
|
|
313
|
+
const [maxPagesVisited, setMaxPagesVisited] = (0, import_react.useState)(1);
|
|
314
|
+
const [allPageResults, setAllPageResults] = (0, import_react.useState)(/* @__PURE__ */ new Map([[0, {
|
|
315
|
+
data: null,
|
|
316
|
+
isLoading: false,
|
|
317
|
+
error: null
|
|
318
|
+
}]]));
|
|
319
|
+
const pageCache = (0, import_react.useRef)(/* @__PURE__ */ new Map());
|
|
320
|
+
const fetchPage = (0, import_react.useCallback)(async (pageIndex, pageCursor, force = false) => {
|
|
321
|
+
const cacheKey = pageCursor ?? "initial";
|
|
322
|
+
setAllPageResults((prev) => {
|
|
323
|
+
const newMap = new Map(prev);
|
|
324
|
+
newMap.set(pageIndex, {
|
|
325
|
+
data: prev.get(pageIndex)?.data ?? null,
|
|
326
|
+
isLoading: true,
|
|
327
|
+
error: null
|
|
328
|
+
});
|
|
329
|
+
return newMap;
|
|
330
|
+
});
|
|
331
|
+
if (!force && pageCache.current.has(cacheKey)) {
|
|
332
|
+
const cached = pageCache.current.get(cacheKey);
|
|
333
|
+
if (cached) {
|
|
334
|
+
setAllPageResults((prev) => {
|
|
335
|
+
const newMap = new Map(prev);
|
|
336
|
+
newMap.set(pageIndex, {
|
|
337
|
+
data: cached.data,
|
|
338
|
+
isLoading: false,
|
|
339
|
+
error: null
|
|
340
|
+
});
|
|
341
|
+
return newMap;
|
|
342
|
+
});
|
|
343
|
+
setCursor(cached.cursor);
|
|
344
|
+
setHasMore(cached.hasMore);
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
try {
|
|
349
|
+
const result = await fetchFn(pageCursor);
|
|
350
|
+
pageCache.current.set(cacheKey, {
|
|
351
|
+
data: result.data,
|
|
352
|
+
cursor: result.cursor,
|
|
353
|
+
hasMore: result.hasMore
|
|
354
|
+
});
|
|
355
|
+
setAllPageResults((prev) => {
|
|
356
|
+
const newMap = new Map(prev);
|
|
357
|
+
newMap.set(pageIndex, {
|
|
358
|
+
data: result.data,
|
|
359
|
+
isLoading: false,
|
|
360
|
+
error: null
|
|
361
|
+
});
|
|
362
|
+
return newMap;
|
|
363
|
+
});
|
|
364
|
+
setCursor(result.cursor);
|
|
365
|
+
setHasMore(result.hasMore);
|
|
366
|
+
} catch (err) {
|
|
367
|
+
const error = err instanceof Error ? err : new WorkflowWebAPIError(String(err), { layer: "client" });
|
|
368
|
+
setAllPageResults((prev) => {
|
|
369
|
+
const newMap = new Map(prev);
|
|
370
|
+
newMap.set(pageIndex, {
|
|
371
|
+
data: prev.get(pageIndex)?.data ?? null,
|
|
372
|
+
isLoading: false,
|
|
373
|
+
error
|
|
374
|
+
});
|
|
375
|
+
return newMap;
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
}, [fetchFn]);
|
|
379
|
+
(0, import_react.useEffect)(() => {
|
|
380
|
+
fetchPage(0, void 0, true);
|
|
381
|
+
}, [fetchPage]);
|
|
382
|
+
const nextPage = (0, import_react.useCallback)(() => {
|
|
383
|
+
if (hasMore && cursor) {
|
|
384
|
+
const newPage = currentPage + 1;
|
|
385
|
+
setPageHistory((prev) => [...prev, cursor]);
|
|
386
|
+
setCurrentPage(newPage);
|
|
387
|
+
setMaxPagesVisited((prev) => Math.max(prev, newPage + 1));
|
|
388
|
+
if (!allPageResults.has(newPage)) setAllPageResults((prev) => {
|
|
389
|
+
const newMap = new Map(prev);
|
|
390
|
+
newMap.set(newPage, {
|
|
391
|
+
data: null,
|
|
392
|
+
isLoading: true,
|
|
393
|
+
error: null
|
|
394
|
+
});
|
|
395
|
+
return newMap;
|
|
396
|
+
});
|
|
397
|
+
fetchPage(newPage, cursor);
|
|
398
|
+
}
|
|
399
|
+
}, [
|
|
400
|
+
hasMore,
|
|
401
|
+
cursor,
|
|
402
|
+
fetchPage,
|
|
403
|
+
currentPage,
|
|
404
|
+
allPageResults
|
|
405
|
+
]);
|
|
406
|
+
const previousPage = (0, import_react.useCallback)(() => {
|
|
407
|
+
if (currentPage > 0) {
|
|
408
|
+
const newPage = currentPage - 1;
|
|
409
|
+
const prevCursor = pageHistory[newPage];
|
|
410
|
+
setCurrentPage(newPage);
|
|
411
|
+
fetchPage(newPage, prevCursor);
|
|
412
|
+
}
|
|
413
|
+
}, [
|
|
414
|
+
currentPage,
|
|
415
|
+
pageHistory,
|
|
416
|
+
fetchPage
|
|
417
|
+
]);
|
|
418
|
+
const reload = (0, import_react.useCallback)(() => {
|
|
419
|
+
pageCache.current.clear();
|
|
420
|
+
setAllPageResults(/* @__PURE__ */ new Map([[0, {
|
|
421
|
+
data: null,
|
|
422
|
+
isLoading: true,
|
|
423
|
+
error: null
|
|
424
|
+
}]]));
|
|
425
|
+
setCurrentPage(0);
|
|
426
|
+
setPageHistory([void 0]);
|
|
427
|
+
setMaxPagesVisited(1);
|
|
428
|
+
fetchPage(0, void 0, true);
|
|
429
|
+
}, [fetchPage]);
|
|
430
|
+
const refresh = (0, import_react.useCallback)(() => {
|
|
431
|
+
const currentCursor = pageHistory[currentPage];
|
|
432
|
+
const cacheKey = currentCursor ?? "initial";
|
|
433
|
+
pageCache.current.delete(cacheKey);
|
|
434
|
+
fetchPage(currentPage, currentCursor, true);
|
|
435
|
+
}, [
|
|
436
|
+
fetchPage,
|
|
437
|
+
currentPage,
|
|
438
|
+
pageHistory
|
|
439
|
+
]);
|
|
440
|
+
const currentPageResult = allPageResults.get(currentPage) ?? {
|
|
441
|
+
data: null,
|
|
442
|
+
isLoading: true,
|
|
443
|
+
error: null
|
|
444
|
+
};
|
|
445
|
+
const globalError = Array.from(allPageResults.values()).find((p) => p.error)?.error ?? null;
|
|
446
|
+
const globalLoading = Array.from(allPageResults.values()).some((p) => p.isLoading);
|
|
447
|
+
const totalPages = hasMore ? currentPage + 2 : currentPage + 1;
|
|
448
|
+
const currentPageNumber = currentPage + 1;
|
|
449
|
+
const pageInfo = getPaginationDisplay(currentPageNumber, maxPagesVisited, currentPageNumber === maxPagesVisited && hasMore);
|
|
450
|
+
return {
|
|
451
|
+
data: currentPageResult,
|
|
452
|
+
allData: Array.from(allPageResults.values()),
|
|
453
|
+
error: globalError,
|
|
454
|
+
isLoading: globalLoading,
|
|
455
|
+
currentPage,
|
|
456
|
+
totalPages,
|
|
457
|
+
nextPage,
|
|
458
|
+
previousPage,
|
|
459
|
+
hasNextPage: hasMore,
|
|
460
|
+
hasPreviousPage: currentPage > 0,
|
|
461
|
+
reload,
|
|
462
|
+
refresh,
|
|
463
|
+
pageInfo
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Returns a list of hooks with pagination control
|
|
468
|
+
*/
|
|
469
|
+
function useWorkflowHooks(params) {
|
|
470
|
+
const { runId, limit = 10, sortOrder = "desc" } = params;
|
|
471
|
+
return usePaginatedList((0, import_react.useCallback)((cursor) => unwrapOrThrow(rpc("fetchHooks", {
|
|
472
|
+
runId,
|
|
473
|
+
cursor,
|
|
474
|
+
sortOrder,
|
|
475
|
+
limit
|
|
476
|
+
})), [
|
|
477
|
+
runId,
|
|
478
|
+
limit,
|
|
479
|
+
sortOrder
|
|
480
|
+
]));
|
|
481
|
+
}
|
|
482
|
+
// app/components/hooks-table.tsx
|
|
483
|
+
var INVOCATION_EVENTS_LIMIT = 100;
|
|
484
|
+
/**
|
|
485
|
+
* Hooks with server-side pagination. Fetches invocation counts in the
|
|
486
|
+
* background for each hook.
|
|
487
|
+
*/
|
|
488
|
+
function HooksTable({ onHookClick, selectedHookId }) {
|
|
489
|
+
const [lastRefreshTime, setLastRefreshTime] = (0, import_react.useState)(() => /* @__PURE__ */ new Date());
|
|
490
|
+
const { data, error, nextPage, previousPage, hasNextPage, hasPreviousPage, refresh, pageInfo } = useWorkflowHooks({ sortOrder: "desc" });
|
|
491
|
+
const hookActions = useHookActions({
|
|
492
|
+
onResolve: async (hook, payload) => {
|
|
493
|
+
const { token } = await unwrapOrThrow(rpc("fetchHookToken", {
|
|
494
|
+
runId: hook.runId,
|
|
495
|
+
hookId: hook.hookId
|
|
496
|
+
}));
|
|
497
|
+
await unwrapOrThrow(rpc("resumeHook", {
|
|
498
|
+
token,
|
|
499
|
+
payload
|
|
500
|
+
}));
|
|
501
|
+
},
|
|
502
|
+
callbacks: { onSuccess: refresh }
|
|
503
|
+
});
|
|
504
|
+
const loading = data.isLoading;
|
|
505
|
+
const hooks = data.data ?? [];
|
|
506
|
+
const onRefresh = () => {
|
|
507
|
+
setLastRefreshTime(() => /* @__PURE__ */ new Date());
|
|
508
|
+
refresh();
|
|
509
|
+
};
|
|
510
|
+
const [invocationData, setInvocationData] = (0, import_react.useState)(/* @__PURE__ */ new Map());
|
|
511
|
+
(0, import_react.useEffect)(() => {
|
|
512
|
+
if (!hooks.length) return;
|
|
513
|
+
let ignore = false;
|
|
514
|
+
setInvocationData(new Map(hooks.map((hook) => [hook.hookId, {
|
|
515
|
+
count: 0,
|
|
516
|
+
hasMore: false,
|
|
517
|
+
loading: true
|
|
518
|
+
}])));
|
|
519
|
+
const settle = (hookId, data) => {
|
|
520
|
+
if (ignore) return;
|
|
521
|
+
setInvocationData((prev) => new Map(prev).set(hookId, data));
|
|
522
|
+
};
|
|
523
|
+
for (const hook of hooks) unwrapOrThrow(rpc("fetchEventsByCorrelationId", {
|
|
524
|
+
correlationId: hook.hookId,
|
|
525
|
+
runId: hook.runId,
|
|
526
|
+
limit: INVOCATION_EVENTS_LIMIT
|
|
527
|
+
})).then(({ data: events, hasMore }) => settle(hook.hookId, {
|
|
528
|
+
count: events.filter((event) => event.eventType === "hook_received").length,
|
|
529
|
+
hasMore,
|
|
530
|
+
loading: false
|
|
531
|
+
}), (error) => settle(hook.hookId, {
|
|
532
|
+
count: error,
|
|
533
|
+
hasMore: false,
|
|
534
|
+
loading: false
|
|
535
|
+
}));
|
|
536
|
+
return () => {
|
|
537
|
+
ignore = true;
|
|
538
|
+
};
|
|
539
|
+
}, [hooks]);
|
|
540
|
+
const renderInvocationCount = (hook) => {
|
|
541
|
+
const data = invocationData.get(hook.hookId);
|
|
542
|
+
if (!data || data.loading) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
543
|
+
className: "text-muted-foreground text-xs",
|
|
544
|
+
children: "..."
|
|
545
|
+
});
|
|
546
|
+
if (data.count instanceof Error) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
547
|
+
className: "text-muted-foreground",
|
|
548
|
+
children: "Error"
|
|
549
|
+
});
|
|
550
|
+
if (data.count === 0) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
551
|
+
className: "text-muted-foreground",
|
|
552
|
+
children: "0"
|
|
553
|
+
});
|
|
554
|
+
const displayText = data.hasMore ? `${data.count}+` : `${data.count}`;
|
|
555
|
+
if (data.hasMore) return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Tooltip, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipTrigger, {
|
|
556
|
+
asChild: true,
|
|
557
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
558
|
+
className: "font-semibold cursor-help",
|
|
559
|
+
children: displayText
|
|
560
|
+
})
|
|
561
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContent, {
|
|
562
|
+
className: "max-w-xs",
|
|
563
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
564
|
+
className: "text-xs",
|
|
565
|
+
children: [
|
|
566
|
+
"Counted from the first ",
|
|
567
|
+
INVOCATION_EVENTS_LIMIT,
|
|
568
|
+
" events. There may be more."
|
|
569
|
+
]
|
|
570
|
+
})
|
|
571
|
+
})] });
|
|
572
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
573
|
+
className: "font-semibold",
|
|
574
|
+
children: displayText
|
|
575
|
+
});
|
|
576
|
+
};
|
|
577
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
|
|
578
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(HookResolveModalWrapper, { hookActions }),
|
|
579
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
580
|
+
className: "flex items-center justify-between",
|
|
581
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
582
|
+
className: "flex items-end gap-2",
|
|
583
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
|
|
584
|
+
className: "text-sm text-muted-foreground",
|
|
585
|
+
children: "Last refreshed"
|
|
586
|
+
}), lastRefreshTime && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RelativeTime, {
|
|
587
|
+
date: lastRefreshTime,
|
|
588
|
+
className: "text-sm text-muted-foreground",
|
|
589
|
+
type: "distance"
|
|
590
|
+
})]
|
|
591
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
592
|
+
className: "flex items-center gap-4",
|
|
593
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Tooltip, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipTrigger, {
|
|
594
|
+
asChild: true,
|
|
595
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button, {
|
|
596
|
+
variant: "secondary",
|
|
597
|
+
size: "small",
|
|
598
|
+
onClick: onRefresh,
|
|
599
|
+
disabled: loading,
|
|
600
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(RefreshCw, { className: loading ? "animate-spin" : "" }), "Refresh"]
|
|
601
|
+
})
|
|
602
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContent, { children: "Note that this resets pages" })] })
|
|
603
|
+
})]
|
|
604
|
+
}),
|
|
605
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Alert, {
|
|
606
|
+
variant: "destructive",
|
|
607
|
+
children: [
|
|
608
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(CircleAlert, { className: "h-4 w-4" }),
|
|
609
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertTitle, { children: "Error loading hooks" }),
|
|
610
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertDescription, { children: getErrorMessage(error) })
|
|
611
|
+
]
|
|
612
|
+
}) : !loading && (!hooks || hooks.length === 0) ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
613
|
+
className: "text-center py-8 text-muted-foreground",
|
|
614
|
+
children: [
|
|
615
|
+
"No active hooks found. ",
|
|
616
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("br", {}),
|
|
617
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(DocsLink, {
|
|
618
|
+
href: "https://workflow-sdk.dev/docs/api-reference/workflow/create-hook",
|
|
619
|
+
children: "Learn how to create a hook"
|
|
620
|
+
})
|
|
621
|
+
]
|
|
622
|
+
}) : loading && !data?.data ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableSkeleton, {}) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Card, {
|
|
623
|
+
className: "overflow-hidden mt-4 bg-background",
|
|
624
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CardContent, {
|
|
625
|
+
className: "p-0 max-h-[calc(100vh-280px)] overflow-auto",
|
|
626
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Table, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHeader, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableRow, { children: [
|
|
627
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHead, {
|
|
628
|
+
className: "sticky top-0 bg-background z-10 border-b shadow-sm h-10",
|
|
629
|
+
children: "Hook ID"
|
|
630
|
+
}),
|
|
631
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHead, {
|
|
632
|
+
className: "sticky top-0 bg-background z-10 border-b shadow-sm h-10",
|
|
633
|
+
children: "Run ID"
|
|
634
|
+
}),
|
|
635
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHead, {
|
|
636
|
+
className: "sticky top-0 bg-background z-10 border-b shadow-sm h-10",
|
|
637
|
+
children: "Token"
|
|
638
|
+
}),
|
|
639
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHead, {
|
|
640
|
+
className: "sticky top-0 bg-background z-10 border-b shadow-sm h-10",
|
|
641
|
+
children: "Created"
|
|
642
|
+
}),
|
|
643
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHead, {
|
|
644
|
+
className: "sticky top-0 bg-background z-10 border-b shadow-sm h-10",
|
|
645
|
+
children: "Invocations"
|
|
646
|
+
}),
|
|
647
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHead, { className: "sticky top-0 bg-background z-10 border-b shadow-sm h-10 w-10" })
|
|
648
|
+
] }) }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableBody, { children: hooks.map((hook) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableRow, {
|
|
649
|
+
className: "cursor-pointer group relative",
|
|
650
|
+
onClick: () => onHookClick(hook.hookId, hook.runId),
|
|
651
|
+
"data-selected": hook.hookId === selectedHookId,
|
|
652
|
+
children: [
|
|
653
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
|
|
654
|
+
className: "font-mono text-xs py-2",
|
|
655
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CopyableText, {
|
|
656
|
+
text: hook.hookId,
|
|
657
|
+
overlay: true,
|
|
658
|
+
children: hook.hookId
|
|
659
|
+
})
|
|
660
|
+
}),
|
|
661
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
|
|
662
|
+
className: "font-mono text-xs py-2",
|
|
663
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CopyableText, {
|
|
664
|
+
text: hook.runId,
|
|
665
|
+
overlay: true,
|
|
666
|
+
children: hook.runId
|
|
667
|
+
})
|
|
668
|
+
}),
|
|
669
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
|
|
670
|
+
className: "font-mono text-xs py-2",
|
|
671
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(HookTokenCell, {
|
|
672
|
+
runId: hook.runId,
|
|
673
|
+
hookId: hook.hookId
|
|
674
|
+
})
|
|
675
|
+
}),
|
|
676
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
|
|
677
|
+
className: "py-2 text-muted-foreground text-xs",
|
|
678
|
+
children: hook.createdAt ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RelativeTime, { date: hook.createdAt }) : "-"
|
|
679
|
+
}),
|
|
680
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
|
|
681
|
+
className: "py-2",
|
|
682
|
+
children: renderInvocationCount(hook)
|
|
683
|
+
}),
|
|
684
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
|
|
685
|
+
className: "py-2",
|
|
686
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenu, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuTrigger, {
|
|
687
|
+
asChild: true,
|
|
688
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
|
|
689
|
+
variant: "tertiary",
|
|
690
|
+
size: "small",
|
|
691
|
+
shape: "square",
|
|
692
|
+
"aria-label": "Hook actions",
|
|
693
|
+
onClick: (e) => e.stopPropagation(),
|
|
694
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Ellipsis, { className: "h-4 w-4" })
|
|
695
|
+
})
|
|
696
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuContent, {
|
|
697
|
+
align: "end",
|
|
698
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ResolveHookDropdownItem, {
|
|
699
|
+
hook,
|
|
700
|
+
stopPropagation: true,
|
|
701
|
+
onResolveClick: hookActions.openResolveModal,
|
|
702
|
+
DropdownMenuItem
|
|
703
|
+
})
|
|
704
|
+
})] })
|
|
705
|
+
})
|
|
706
|
+
]
|
|
707
|
+
}, hook.hookId)) })] })
|
|
708
|
+
})
|
|
709
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
710
|
+
className: "flex items-center justify-between mt-4",
|
|
711
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
712
|
+
className: "text-sm text-muted-foreground",
|
|
713
|
+
children: pageInfo
|
|
714
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
715
|
+
className: "flex gap-2 items-center",
|
|
716
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button, {
|
|
717
|
+
variant: "secondary",
|
|
718
|
+
size: "small",
|
|
719
|
+
onClick: previousPage,
|
|
720
|
+
disabled: !hasPreviousPage,
|
|
721
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChevronLeft, {}), "Previous"]
|
|
722
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button, {
|
|
723
|
+
variant: "secondary",
|
|
724
|
+
size: "small",
|
|
725
|
+
onClick: nextPage,
|
|
726
|
+
disabled: !hasNextPage,
|
|
727
|
+
children: ["Next", /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChevronRight, {})]
|
|
728
|
+
})]
|
|
729
|
+
})]
|
|
730
|
+
})] })
|
|
731
|
+
] });
|
|
732
|
+
}
|
|
733
|
+
// ../../node_modules/.bun/@radix-ui+number@1.1.3/node_modules/@radix-ui/number/dist/index.mjs
|
|
734
|
+
var import_react_dom = /* @__PURE__ */ __toESM(require_react_dom(), 1);
|
|
735
|
+
var __defProp$2 = Object.defineProperty;
|
|
736
|
+
var __name$2 = (target, value) => __defProp$2(target, "name", {
|
|
737
|
+
value,
|
|
738
|
+
configurable: true
|
|
739
|
+
});
|
|
740
|
+
function clamp(value, [min, max]) {
|
|
741
|
+
return Math.min(max, Math.max(min, value));
|
|
742
|
+
}
|
|
743
|
+
__name$2(clamp, "clamp");
|
|
744
|
+
// ../../node_modules/.bun/@radix-ui+react-visually-hidden@1.2.13+a68cb332b68cb125/node_modules/@radix-ui/react-visually-hidden/dist/index.mjs
|
|
745
|
+
var VISUALLY_HIDDEN_STYLES = Object.freeze({
|
|
746
|
+
position: "absolute",
|
|
747
|
+
border: 0,
|
|
748
|
+
width: 1,
|
|
749
|
+
height: 1,
|
|
750
|
+
padding: 0,
|
|
751
|
+
margin: -1,
|
|
752
|
+
overflow: "hidden",
|
|
753
|
+
clip: "rect(0, 0, 0, 0)",
|
|
754
|
+
whiteSpace: "nowrap",
|
|
755
|
+
wordWrap: "normal"
|
|
756
|
+
});
|
|
757
|
+
// ../../node_modules/.bun/@radix-ui+react-select@2.4.1+a68cb332b68cb125/node_modules/@radix-ui/react-select/dist/index.mjs
|
|
758
|
+
var __defProp$1 = Object.defineProperty;
|
|
759
|
+
var __name$1 = (target, value) => __defProp$1(target, "name", {
|
|
760
|
+
value,
|
|
761
|
+
configurable: true
|
|
762
|
+
});
|
|
763
|
+
var Position = {
|
|
764
|
+
ItemAligned: "item-aligned",
|
|
765
|
+
Popper: "popper"
|
|
766
|
+
};
|
|
767
|
+
var Direction = {
|
|
768
|
+
LTR: "ltr",
|
|
769
|
+
RTL: "rtl"
|
|
770
|
+
};
|
|
771
|
+
var OPEN_KEYS = [
|
|
772
|
+
" ",
|
|
773
|
+
"Enter",
|
|
774
|
+
"ArrowUp",
|
|
775
|
+
"ArrowDown"
|
|
776
|
+
];
|
|
777
|
+
var SELECTION_KEYS = [" ", "Enter"];
|
|
778
|
+
var SELECT_NAME = "Select";
|
|
779
|
+
var [Collection, useCollection, createCollectionScope] = createCollection(SELECT_NAME);
|
|
780
|
+
var [createSelectContext, createSelectScope] = createContextScope(SELECT_NAME, [createCollectionScope, createPopperScope]);
|
|
781
|
+
var usePopperScope = createPopperScope();
|
|
782
|
+
var [SelectProviderImpl, useSelectContext] = createSelectContext(SELECT_NAME);
|
|
783
|
+
var [SelectNativeOptionsProvider, useSelectNativeOptionsContext] = createSelectContext(SELECT_NAME);
|
|
784
|
+
function SelectProvider(props) {
|
|
785
|
+
const { __scopeSelect, children, open: openProp, defaultOpen, onOpenChange, value: valueProp, defaultValue, onValueChange, dir, name, autoComplete, disabled, required, form, internal_do_not_use_render } = props;
|
|
786
|
+
const popperScope = usePopperScope(__scopeSelect);
|
|
787
|
+
const [trigger, setTrigger] = import_react.useState(null);
|
|
788
|
+
const [valueNode, setValueNode] = import_react.useState(null);
|
|
789
|
+
const [valueNodeHasChildren, setValueNodeHasChildren] = import_react.useState(false);
|
|
790
|
+
const direction = useDirection(dir);
|
|
791
|
+
const [open, setOpen] = useControllableState({
|
|
792
|
+
prop: openProp,
|
|
793
|
+
defaultProp: defaultOpen ?? false,
|
|
794
|
+
onChange: onOpenChange,
|
|
795
|
+
caller: SELECT_NAME
|
|
796
|
+
});
|
|
797
|
+
const [value, setValue] = useControllableState({
|
|
798
|
+
prop: valueProp,
|
|
799
|
+
defaultProp: defaultValue,
|
|
800
|
+
onChange: onValueChange,
|
|
801
|
+
caller: SELECT_NAME
|
|
802
|
+
});
|
|
803
|
+
const triggerPointerDownPosRef = import_react.useRef(null);
|
|
804
|
+
const hasConsumerStoppedPropagationRef = import_react.useRef(false);
|
|
805
|
+
const [userSelection, setUserSelection] = import_react.useState(null);
|
|
806
|
+
const handleUserSelect = /* @__PURE__ */ __name$1((nextValue) => {
|
|
807
|
+
setUserSelection({
|
|
808
|
+
value: nextValue,
|
|
809
|
+
hasConsumerStoppedPropagation: hasConsumerStoppedPropagationRef.current
|
|
810
|
+
});
|
|
811
|
+
setValue(nextValue);
|
|
812
|
+
}, "handleUserSelect");
|
|
813
|
+
const initialValueRef = import_react.useRef(value);
|
|
814
|
+
import_react.useEffect(() => {
|
|
815
|
+
const associatedForm = form ? trigger?.ownerDocument.getElementById(form) : trigger?.form;
|
|
816
|
+
if (associatedForm instanceof HTMLFormElement) {
|
|
817
|
+
const reset = /* @__PURE__ */ __name$1(() => setValue(initialValueRef.current), "reset");
|
|
818
|
+
associatedForm.addEventListener("reset", reset);
|
|
819
|
+
return () => associatedForm.removeEventListener("reset", reset);
|
|
820
|
+
}
|
|
821
|
+
}, [
|
|
822
|
+
form,
|
|
823
|
+
trigger,
|
|
824
|
+
setValue
|
|
825
|
+
]);
|
|
826
|
+
const isFormControl = trigger ? !!form || !!trigger.closest("form") : true;
|
|
827
|
+
const [nativeOptionsSet, setNativeOptionsSet] = import_react.useState(/* @__PURE__ */ new Set());
|
|
828
|
+
const contentId = useId();
|
|
829
|
+
const nativeSelectKey = Array.from(nativeOptionsSet).map((option) => option.props.value).join(";");
|
|
830
|
+
const handleNativeOptionAdd = import_react.useCallback((option) => {
|
|
831
|
+
setNativeOptionsSet((prev) => new Set(prev).add(option));
|
|
832
|
+
}, []);
|
|
833
|
+
const handleNativeOptionRemove = import_react.useCallback((option) => {
|
|
834
|
+
setNativeOptionsSet((prev) => {
|
|
835
|
+
const optionsSet = new Set(prev);
|
|
836
|
+
optionsSet.delete(option);
|
|
837
|
+
return optionsSet;
|
|
838
|
+
});
|
|
839
|
+
}, []);
|
|
840
|
+
const context = {
|
|
841
|
+
required,
|
|
842
|
+
trigger,
|
|
843
|
+
onTriggerChange: setTrigger,
|
|
844
|
+
valueNode,
|
|
845
|
+
onValueNodeChange: setValueNode,
|
|
846
|
+
valueNodeHasChildren,
|
|
847
|
+
onValueNodeHasChildrenChange: setValueNodeHasChildren,
|
|
848
|
+
contentId,
|
|
849
|
+
value,
|
|
850
|
+
onValueChange: setValue,
|
|
851
|
+
hasConsumerStoppedPropagationRef,
|
|
852
|
+
userSelection,
|
|
853
|
+
onUserSelect: handleUserSelect,
|
|
854
|
+
open,
|
|
855
|
+
onOpenChange: setOpen,
|
|
856
|
+
dir: direction,
|
|
857
|
+
triggerPointerDownPosRef,
|
|
858
|
+
disabled,
|
|
859
|
+
name,
|
|
860
|
+
autoComplete,
|
|
861
|
+
form,
|
|
862
|
+
nativeOptions: nativeOptionsSet,
|
|
863
|
+
nativeSelectKey,
|
|
864
|
+
isFormControl
|
|
865
|
+
};
|
|
866
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Popper, {
|
|
867
|
+
...popperScope,
|
|
868
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectProviderImpl, {
|
|
869
|
+
scope: __scopeSelect,
|
|
870
|
+
...context,
|
|
871
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Collection.Provider, {
|
|
872
|
+
scope: __scopeSelect,
|
|
873
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectNativeOptionsProvider, {
|
|
874
|
+
scope: __scopeSelect,
|
|
875
|
+
onNativeOptionAdd: handleNativeOptionAdd,
|
|
876
|
+
onNativeOptionRemove: handleNativeOptionRemove,
|
|
877
|
+
children: isFunction$2(internal_do_not_use_render) ? internal_do_not_use_render(context) : children
|
|
878
|
+
})
|
|
879
|
+
})
|
|
880
|
+
})
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
__name$1(SelectProvider, "SelectProvider");
|
|
884
|
+
var Select$1 = /* @__PURE__ */ __name$1((props) => {
|
|
885
|
+
const { __scopeSelect, children, ...providerProps } = props;
|
|
886
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectProvider, {
|
|
887
|
+
__scopeSelect,
|
|
888
|
+
...providerProps,
|
|
889
|
+
internal_do_not_use_render: ({ isFormControl }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [children, isFormControl ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectBubbleInput, { __scopeSelect }) : null] })
|
|
890
|
+
});
|
|
891
|
+
}, "Select");
|
|
892
|
+
var TRIGGER_NAME$1 = "SelectTrigger";
|
|
893
|
+
var SelectTrigger$1 = /* @__PURE__ */ import_react.forwardRef(/* @__PURE__ */ __name$1(function SelectTrigger2(props, forwardedRef) {
|
|
894
|
+
const { __scopeSelect, disabled = false, ...triggerProps } = props;
|
|
895
|
+
const popperScope = usePopperScope(__scopeSelect);
|
|
896
|
+
const context = useSelectContext(TRIGGER_NAME$1, __scopeSelect);
|
|
897
|
+
const isDisabled = context.disabled || disabled;
|
|
898
|
+
const composedRefs = useComposedRefs(forwardedRef, context.onTriggerChange);
|
|
899
|
+
const getItems = useCollection(__scopeSelect);
|
|
900
|
+
const pointerTypeRef = import_react.useRef("touch");
|
|
901
|
+
const [searchRef, handleTypeaheadSearch, resetTypeahead] = useTypeaheadSearch((search) => {
|
|
902
|
+
const enabledItems = getItems().filter((item) => !item.disabled);
|
|
903
|
+
const nextItem = findNextItem(enabledItems, search, enabledItems.find((item) => item.value === context.value));
|
|
904
|
+
if (nextItem !== void 0) context.onUserSelect(nextItem.value);
|
|
905
|
+
});
|
|
906
|
+
const handleOpen = /* @__PURE__ */ __name$1((pointerEvent) => {
|
|
907
|
+
if (!isDisabled) {
|
|
908
|
+
context.onOpenChange(true);
|
|
909
|
+
resetTypeahead();
|
|
910
|
+
}
|
|
911
|
+
if (pointerEvent) context.triggerPointerDownPosRef.current = {
|
|
912
|
+
x: Math.round(pointerEvent.pageX),
|
|
913
|
+
y: Math.round(pointerEvent.pageY)
|
|
914
|
+
};
|
|
915
|
+
}, "handleOpen");
|
|
916
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopperAnchor, {
|
|
917
|
+
asChild: true,
|
|
918
|
+
...popperScope,
|
|
919
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Primitive.button, {
|
|
920
|
+
type: "button",
|
|
921
|
+
role: "combobox",
|
|
922
|
+
"aria-controls": context.open ? context.contentId : void 0,
|
|
923
|
+
"aria-expanded": context.open,
|
|
924
|
+
"aria-required": context.required,
|
|
925
|
+
"aria-autocomplete": "none",
|
|
926
|
+
dir: context.dir,
|
|
927
|
+
"data-state": context.open ? "open" : "closed",
|
|
928
|
+
disabled: isDisabled,
|
|
929
|
+
"data-disabled": isDisabled ? "" : void 0,
|
|
930
|
+
"data-placeholder": shouldShowPlaceholder(context.value) ? "" : void 0,
|
|
931
|
+
...triggerProps,
|
|
932
|
+
ref: composedRefs,
|
|
933
|
+
onClick: composeEventHandlers(triggerProps.onClick, (event) => {
|
|
934
|
+
event.currentTarget.focus();
|
|
935
|
+
if (pointerTypeRef.current !== "mouse") handleOpen(event);
|
|
936
|
+
}),
|
|
937
|
+
onPointerDown: composeEventHandlers(triggerProps.onPointerDown, (event) => {
|
|
938
|
+
pointerTypeRef.current = event.pointerType;
|
|
939
|
+
const target = event.target;
|
|
940
|
+
if (target.hasPointerCapture(event.pointerId)) target.releasePointerCapture(event.pointerId);
|
|
941
|
+
if (event.button === 0 && event.ctrlKey === false && event.pointerType === "mouse") {
|
|
942
|
+
handleOpen(event);
|
|
943
|
+
event.preventDefault();
|
|
944
|
+
}
|
|
945
|
+
}),
|
|
946
|
+
onKeyDown: composeEventHandlers(triggerProps.onKeyDown, (event) => {
|
|
947
|
+
const isTypingAhead = searchRef.current !== "";
|
|
948
|
+
if (!(event.ctrlKey || event.altKey || event.metaKey) && event.key.length === 1) {
|
|
949
|
+
context.hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
950
|
+
handleTypeaheadSearch(event.key);
|
|
951
|
+
}
|
|
952
|
+
if (isTypingAhead && event.key === " ") return;
|
|
953
|
+
if (OPEN_KEYS.includes(event.key)) {
|
|
954
|
+
handleOpen();
|
|
955
|
+
event.preventDefault();
|
|
956
|
+
}
|
|
957
|
+
})
|
|
958
|
+
})
|
|
959
|
+
});
|
|
960
|
+
}, "SelectTrigger"));
|
|
961
|
+
var VALUE_NAME = "SelectValue";
|
|
962
|
+
var SelectValue$1 = /* @__PURE__ */ import_react.forwardRef(/* @__PURE__ */ __name$1(function SelectValue2(props, forwardedRef) {
|
|
963
|
+
const { __scopeSelect, className, style, children, placeholder = "", ...valueProps } = props;
|
|
964
|
+
const context = useSelectContext(VALUE_NAME, __scopeSelect);
|
|
965
|
+
const { onValueNodeHasChildrenChange } = context;
|
|
966
|
+
const hasChildren = children !== void 0;
|
|
967
|
+
const composedRefs = useComposedRefs(forwardedRef, context.onValueNodeChange);
|
|
968
|
+
useLayoutEffect2(() => {
|
|
969
|
+
onValueNodeHasChildrenChange(hasChildren);
|
|
970
|
+
}, [onValueNodeHasChildrenChange, hasChildren]);
|
|
971
|
+
const showPlaceholder = shouldShowPlaceholder(context.value);
|
|
972
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Primitive.span, {
|
|
973
|
+
...valueProps,
|
|
974
|
+
asChild: showPlaceholder ? false : valueProps.asChild,
|
|
975
|
+
ref: composedRefs,
|
|
976
|
+
style: { pointerEvents: "none" },
|
|
977
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Fragment, { children: showPlaceholder ? placeholder : children }, showPlaceholder ? "placeholder" : "value")
|
|
978
|
+
});
|
|
979
|
+
}, "SelectValue"));
|
|
980
|
+
var SelectIcon = /* @__PURE__ */ import_react.forwardRef(/* @__PURE__ */ __name$1(function SelectIcon2(props, forwardedRef) {
|
|
981
|
+
const { __scopeSelect, children, ...iconProps } = props;
|
|
982
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Primitive.span, {
|
|
983
|
+
"aria-hidden": true,
|
|
984
|
+
...iconProps,
|
|
985
|
+
ref: forwardedRef,
|
|
986
|
+
children: children || "▼"
|
|
987
|
+
});
|
|
988
|
+
}, "SelectIcon"));
|
|
989
|
+
var [PortalProvider, usePortalContext] = createSelectContext("SelectPortal", { forceMount: void 0 });
|
|
990
|
+
var SelectPortal = /* @__PURE__ */ __name$1((props) => {
|
|
991
|
+
const { __scopeSelect, forceMount, ...portalProps } = props;
|
|
992
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PortalProvider, {
|
|
993
|
+
scope: props.__scopeSelect,
|
|
994
|
+
forceMount,
|
|
995
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Portal, {
|
|
996
|
+
asChild: true,
|
|
997
|
+
...portalProps
|
|
998
|
+
})
|
|
999
|
+
});
|
|
1000
|
+
}, "SelectPortal");
|
|
1001
|
+
var CONTENT_NAME = "SelectContent";
|
|
1002
|
+
var SelectContent$1 = /* @__PURE__ */ import_react.forwardRef(/* @__PURE__ */ __name$1(function SelectContent2(props, forwardedRef) {
|
|
1003
|
+
const portalContext = usePortalContext(CONTENT_NAME, props.__scopeSelect);
|
|
1004
|
+
const { forceMount = portalContext.forceMount, ...contentProps } = props;
|
|
1005
|
+
const context = useSelectContext(CONTENT_NAME, props.__scopeSelect);
|
|
1006
|
+
const [fragment, setFragment] = import_react.useState();
|
|
1007
|
+
useLayoutEffect2(() => {
|
|
1008
|
+
setFragment(new DocumentFragment());
|
|
1009
|
+
}, []);
|
|
1010
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Presence, {
|
|
1011
|
+
present: forceMount || context.open,
|
|
1012
|
+
children: ({ present }) => present ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectContentImpl, {
|
|
1013
|
+
...contentProps,
|
|
1014
|
+
ref: forwardedRef
|
|
1015
|
+
}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectContentFragment, {
|
|
1016
|
+
...contentProps,
|
|
1017
|
+
fragment
|
|
1018
|
+
})
|
|
1019
|
+
});
|
|
1020
|
+
}, "SelectContent"));
|
|
1021
|
+
var SelectContentFragment = /* @__PURE__ */ import_react.forwardRef(/* @__PURE__ */ __name$1(function SelectContentFragment2(props, forwardedRef) {
|
|
1022
|
+
const { __scopeSelect, children, fragment } = props;
|
|
1023
|
+
if (!fragment) return null;
|
|
1024
|
+
return import_react_dom.createPortal(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectContentProvider, {
|
|
1025
|
+
scope: __scopeSelect,
|
|
1026
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Collection.Slot, {
|
|
1027
|
+
scope: __scopeSelect,
|
|
1028
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
1029
|
+
ref: forwardedRef,
|
|
1030
|
+
children
|
|
1031
|
+
})
|
|
1032
|
+
})
|
|
1033
|
+
}), fragment);
|
|
1034
|
+
}, "SelectContentFragment"));
|
|
1035
|
+
var CONTENT_MARGIN = 10;
|
|
1036
|
+
var [SelectContentProvider, useSelectContentContext] = createSelectContext(CONTENT_NAME);
|
|
1037
|
+
var Slot = createSlot("SelectContent.RemoveScroll");
|
|
1038
|
+
var SelectContentImpl = /* @__PURE__ */ import_react.forwardRef(/* @__PURE__ */ __name$1(function SelectContentImpl2(props, forwardedRef) {
|
|
1039
|
+
const { __scopeSelect } = props;
|
|
1040
|
+
const { position = Position.ItemAligned, onCloseAutoFocus, onEscapeKeyDown, onPointerDownOutside, side, sideOffset, align, alignOffset, arrowPadding, collisionBoundary, collisionPadding, sticky, hideWhenDetached, avoidCollisions, ...contentProps } = props;
|
|
1041
|
+
const context = useSelectContext(CONTENT_NAME, __scopeSelect);
|
|
1042
|
+
const [content, setContent] = import_react.useState(null);
|
|
1043
|
+
const [viewport, setViewport] = import_react.useState(null);
|
|
1044
|
+
const composedRefs = useComposedRefs(forwardedRef, setContent);
|
|
1045
|
+
const [selectedItem, setSelectedItem] = import_react.useState(null);
|
|
1046
|
+
const [selectedItemText, setSelectedItemText] = import_react.useState(null);
|
|
1047
|
+
const getItems = useCollection(__scopeSelect);
|
|
1048
|
+
const [isPositioned, setIsPositioned] = import_react.useState(false);
|
|
1049
|
+
const firstValidItemFoundRef = import_react.useRef(false);
|
|
1050
|
+
const firstItemFoundRef = import_react.useRef(false);
|
|
1051
|
+
const firstItemTextFoundRef = import_react.useRef(false);
|
|
1052
|
+
import_react.useEffect(() => {
|
|
1053
|
+
if (content) return hideOthers(content);
|
|
1054
|
+
}, [content]);
|
|
1055
|
+
useFocusGuards();
|
|
1056
|
+
const focusFirst = import_react.useCallback((candidates) => {
|
|
1057
|
+
const [firstItem, ...restItems] = getItems().map((item) => item.ref.current);
|
|
1058
|
+
const [lastItem] = restItems.slice(-1);
|
|
1059
|
+
const PREVIOUSLY_FOCUSED_ELEMENT = document.activeElement;
|
|
1060
|
+
for (const candidate of candidates) {
|
|
1061
|
+
if (candidate === PREVIOUSLY_FOCUSED_ELEMENT) return;
|
|
1062
|
+
candidate?.scrollIntoView({ block: "nearest" });
|
|
1063
|
+
if (candidate === firstItem && viewport) viewport.scrollTop = 0;
|
|
1064
|
+
if (candidate === lastItem && viewport) viewport.scrollTop = viewport.scrollHeight;
|
|
1065
|
+
candidate?.focus();
|
|
1066
|
+
if (document.activeElement !== PREVIOUSLY_FOCUSED_ELEMENT) return;
|
|
1067
|
+
}
|
|
1068
|
+
}, [getItems, viewport]);
|
|
1069
|
+
const focusSelectedItem = import_react.useCallback(() => focusFirst([selectedItem, content]), [
|
|
1070
|
+
focusFirst,
|
|
1071
|
+
selectedItem,
|
|
1072
|
+
content
|
|
1073
|
+
]);
|
|
1074
|
+
import_react.useEffect(() => {
|
|
1075
|
+
if (isPositioned) focusSelectedItem();
|
|
1076
|
+
}, [isPositioned, focusSelectedItem]);
|
|
1077
|
+
const { onOpenChange, triggerPointerDownPosRef } = context;
|
|
1078
|
+
import_react.useEffect(() => {
|
|
1079
|
+
if (content) {
|
|
1080
|
+
let pointerMoveDelta = {
|
|
1081
|
+
x: 0,
|
|
1082
|
+
y: 0
|
|
1083
|
+
};
|
|
1084
|
+
const handlePointerMove = /* @__PURE__ */ __name$1((event) => {
|
|
1085
|
+
pointerMoveDelta = {
|
|
1086
|
+
x: Math.abs(Math.round(event.pageX) - (triggerPointerDownPosRef.current?.x ?? 0)),
|
|
1087
|
+
y: Math.abs(Math.round(event.pageY) - (triggerPointerDownPosRef.current?.y ?? 0))
|
|
1088
|
+
};
|
|
1089
|
+
}, "handlePointerMove");
|
|
1090
|
+
const handlePointerUp = /* @__PURE__ */ __name$1((event) => {
|
|
1091
|
+
if (pointerMoveDelta.x <= 10 && pointerMoveDelta.y <= 10) event.preventDefault();
|
|
1092
|
+
else if (!event.composedPath().includes(content)) onOpenChange(false);
|
|
1093
|
+
document.removeEventListener("pointermove", handlePointerMove);
|
|
1094
|
+
triggerPointerDownPosRef.current = null;
|
|
1095
|
+
}, "handlePointerUp");
|
|
1096
|
+
if (triggerPointerDownPosRef.current !== null) {
|
|
1097
|
+
document.addEventListener("pointermove", handlePointerMove);
|
|
1098
|
+
document.addEventListener("pointerup", handlePointerUp, {
|
|
1099
|
+
capture: true,
|
|
1100
|
+
once: true
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
return () => {
|
|
1104
|
+
document.removeEventListener("pointermove", handlePointerMove);
|
|
1105
|
+
document.removeEventListener("pointerup", handlePointerUp, { capture: true });
|
|
1106
|
+
};
|
|
1107
|
+
}
|
|
1108
|
+
}, [
|
|
1109
|
+
content,
|
|
1110
|
+
onOpenChange,
|
|
1111
|
+
triggerPointerDownPosRef
|
|
1112
|
+
]);
|
|
1113
|
+
import_react.useEffect(() => {
|
|
1114
|
+
const close = /* @__PURE__ */ __name$1(() => onOpenChange(false), "close");
|
|
1115
|
+
window.addEventListener("blur", close);
|
|
1116
|
+
window.addEventListener("resize", close);
|
|
1117
|
+
return () => {
|
|
1118
|
+
window.removeEventListener("blur", close);
|
|
1119
|
+
window.removeEventListener("resize", close);
|
|
1120
|
+
};
|
|
1121
|
+
}, [onOpenChange]);
|
|
1122
|
+
const [searchRef, handleTypeaheadSearch] = useTypeaheadSearch((search) => {
|
|
1123
|
+
const enabledItems = getItems().filter((item) => !item.disabled);
|
|
1124
|
+
const nextItem = findNextItem(enabledItems, search, enabledItems.find((item) => item.ref.current === document.activeElement));
|
|
1125
|
+
if (nextItem) setTimeout(() => nextItem.ref.current?.focus());
|
|
1126
|
+
});
|
|
1127
|
+
const itemRefCallback = import_react.useCallback((node, value, disabled) => {
|
|
1128
|
+
const isFirstItem = !firstItemFoundRef.current;
|
|
1129
|
+
if (isFirstItem) firstItemFoundRef.current = true;
|
|
1130
|
+
const isFirstValidItem = !firstValidItemFoundRef.current && !disabled;
|
|
1131
|
+
if (context.value !== void 0 && context.value === value || isFirstValidItem) {
|
|
1132
|
+
setSelectedItem(node);
|
|
1133
|
+
if (isFirstValidItem) firstValidItemFoundRef.current = true;
|
|
1134
|
+
} else if (isFirstItem) setSelectedItem(node);
|
|
1135
|
+
}, [context.value]);
|
|
1136
|
+
const handleItemLeave = import_react.useCallback(() => content?.focus(), [content]);
|
|
1137
|
+
const itemTextRefCallback = import_react.useCallback((node, value, disabled) => {
|
|
1138
|
+
if (!node) return;
|
|
1139
|
+
const isFirstItem = !firstItemTextFoundRef.current;
|
|
1140
|
+
if (isFirstItem) firstItemTextFoundRef.current = true;
|
|
1141
|
+
const isFirstValidItem = !firstValidItemFoundRef.current && !disabled;
|
|
1142
|
+
if (context.value !== void 0 && context.value === value || isFirstValidItem) setSelectedItemText(node);
|
|
1143
|
+
else if (isFirstItem) setSelectedItemText(node);
|
|
1144
|
+
}, [context.value]);
|
|
1145
|
+
const SelectPosition = position === Position.Popper ? SelectPopperPosition : SelectItemAlignedPosition;
|
|
1146
|
+
const popperContentProps = SelectPosition === SelectPopperPosition ? {
|
|
1147
|
+
side,
|
|
1148
|
+
sideOffset,
|
|
1149
|
+
align,
|
|
1150
|
+
alignOffset,
|
|
1151
|
+
arrowPadding,
|
|
1152
|
+
collisionBoundary,
|
|
1153
|
+
collisionPadding,
|
|
1154
|
+
sticky,
|
|
1155
|
+
hideWhenDetached,
|
|
1156
|
+
avoidCollisions
|
|
1157
|
+
} : {};
|
|
1158
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectContentProvider, {
|
|
1159
|
+
scope: __scopeSelect,
|
|
1160
|
+
content,
|
|
1161
|
+
viewport,
|
|
1162
|
+
onViewportChange: setViewport,
|
|
1163
|
+
itemRefCallback,
|
|
1164
|
+
selectedItem,
|
|
1165
|
+
onItemLeave: handleItemLeave,
|
|
1166
|
+
itemTextRefCallback,
|
|
1167
|
+
focusSelectedItem,
|
|
1168
|
+
selectedItemText,
|
|
1169
|
+
position,
|
|
1170
|
+
isPositioned,
|
|
1171
|
+
searchRef,
|
|
1172
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReactRemoveScroll, {
|
|
1173
|
+
as: Slot,
|
|
1174
|
+
allowPinchZoom: true,
|
|
1175
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FocusScope, {
|
|
1176
|
+
asChild: true,
|
|
1177
|
+
trapped: context.open,
|
|
1178
|
+
onMountAutoFocus: (event) => {
|
|
1179
|
+
event.preventDefault();
|
|
1180
|
+
},
|
|
1181
|
+
onUnmountAutoFocus: composeEventHandlers(onCloseAutoFocus, (event) => {
|
|
1182
|
+
context.trigger?.focus({ preventScroll: true });
|
|
1183
|
+
event.preventDefault();
|
|
1184
|
+
}),
|
|
1185
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DismissableLayer, {
|
|
1186
|
+
asChild: true,
|
|
1187
|
+
disableOutsidePointerEvents: true,
|
|
1188
|
+
onEscapeKeyDown,
|
|
1189
|
+
onPointerDownOutside,
|
|
1190
|
+
onFocusOutside: (event) => event.preventDefault(),
|
|
1191
|
+
onDismiss: () => context.onOpenChange(false),
|
|
1192
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectPosition, {
|
|
1193
|
+
role: "listbox",
|
|
1194
|
+
id: context.contentId,
|
|
1195
|
+
"data-state": context.open ? "open" : "closed",
|
|
1196
|
+
dir: context.dir,
|
|
1197
|
+
onContextMenu: (event) => event.preventDefault(),
|
|
1198
|
+
...contentProps,
|
|
1199
|
+
...popperContentProps,
|
|
1200
|
+
onPlaced: () => setIsPositioned(true),
|
|
1201
|
+
ref: composedRefs,
|
|
1202
|
+
style: {
|
|
1203
|
+
display: "flex",
|
|
1204
|
+
flexDirection: "column",
|
|
1205
|
+
outline: "none",
|
|
1206
|
+
...contentProps.style
|
|
1207
|
+
},
|
|
1208
|
+
onKeyDown: composeEventHandlers(contentProps.onKeyDown, (event) => {
|
|
1209
|
+
const isModifierKey = event.ctrlKey || event.altKey || event.metaKey;
|
|
1210
|
+
if (event.key === "Tab") event.preventDefault();
|
|
1211
|
+
if (!isModifierKey && event.key.length === 1) handleTypeaheadSearch(event.key);
|
|
1212
|
+
if ([
|
|
1213
|
+
"ArrowUp",
|
|
1214
|
+
"ArrowDown",
|
|
1215
|
+
"Home",
|
|
1216
|
+
"End"
|
|
1217
|
+
].includes(event.key)) {
|
|
1218
|
+
let candidateNodes = getItems().filter((item) => !item.disabled).map((item) => item.ref.current);
|
|
1219
|
+
if (["ArrowUp", "End"].includes(event.key)) candidateNodes = candidateNodes.slice().reverse();
|
|
1220
|
+
if (["ArrowUp", "ArrowDown"].includes(event.key)) {
|
|
1221
|
+
const currentElement = event.target;
|
|
1222
|
+
const currentIndex = candidateNodes.indexOf(currentElement);
|
|
1223
|
+
candidateNodes = candidateNodes.slice(currentIndex + 1);
|
|
1224
|
+
}
|
|
1225
|
+
setTimeout(() => focusFirst(candidateNodes));
|
|
1226
|
+
event.preventDefault();
|
|
1227
|
+
}
|
|
1228
|
+
})
|
|
1229
|
+
})
|
|
1230
|
+
})
|
|
1231
|
+
})
|
|
1232
|
+
})
|
|
1233
|
+
});
|
|
1234
|
+
}, "SelectContentImpl"));
|
|
1235
|
+
var SelectItemAlignedPosition = /* @__PURE__ */ import_react.forwardRef(/* @__PURE__ */ __name$1(function SelectItemAlignedPosition2(props, forwardedRef) {
|
|
1236
|
+
const { __scopeSelect, onPlaced, ...popperProps } = props;
|
|
1237
|
+
const context = useSelectContext(CONTENT_NAME, __scopeSelect);
|
|
1238
|
+
const contentContext = useSelectContentContext(CONTENT_NAME, __scopeSelect);
|
|
1239
|
+
const [contentWrapper, setContentWrapper] = import_react.useState(null);
|
|
1240
|
+
const [content, setContent] = import_react.useState(null);
|
|
1241
|
+
const composedRefs = useComposedRefs(forwardedRef, setContent);
|
|
1242
|
+
const getItems = useCollection(__scopeSelect);
|
|
1243
|
+
const shouldExpandOnScrollRef = import_react.useRef(false);
|
|
1244
|
+
const shouldRepositionRef = import_react.useRef(true);
|
|
1245
|
+
const { viewport, selectedItem, selectedItemText, focusSelectedItem } = contentContext;
|
|
1246
|
+
const position = import_react.useCallback(() => {
|
|
1247
|
+
if (context.trigger && context.valueNode && contentWrapper && content && viewport && selectedItem && selectedItemText) {
|
|
1248
|
+
const triggerRect = context.trigger.getBoundingClientRect();
|
|
1249
|
+
const contentRect = content.getBoundingClientRect();
|
|
1250
|
+
const valueNodeRect = context.valueNode.getBoundingClientRect();
|
|
1251
|
+
const itemTextRect = selectedItemText.getBoundingClientRect();
|
|
1252
|
+
if (context.dir !== Direction.RTL) {
|
|
1253
|
+
const itemTextOffset = itemTextRect.left - contentRect.left;
|
|
1254
|
+
const left = valueNodeRect.left - itemTextOffset;
|
|
1255
|
+
const leftDelta = triggerRect.left - left;
|
|
1256
|
+
const minContentWidth = triggerRect.width + leftDelta;
|
|
1257
|
+
const contentWidth = Math.max(minContentWidth, contentRect.width);
|
|
1258
|
+
const rightEdge = window.innerWidth - CONTENT_MARGIN;
|
|
1259
|
+
const clampedLeft = clamp(left, [CONTENT_MARGIN, Math.max(CONTENT_MARGIN, rightEdge - contentWidth)]);
|
|
1260
|
+
contentWrapper.style.minWidth = minContentWidth + "px";
|
|
1261
|
+
contentWrapper.style.left = clampedLeft + "px";
|
|
1262
|
+
} else {
|
|
1263
|
+
const itemTextOffset = contentRect.right - itemTextRect.right;
|
|
1264
|
+
const right = window.innerWidth - valueNodeRect.right - itemTextOffset;
|
|
1265
|
+
const rightDelta = window.innerWidth - triggerRect.right - right;
|
|
1266
|
+
const minContentWidth = triggerRect.width + rightDelta;
|
|
1267
|
+
const contentWidth = Math.max(minContentWidth, contentRect.width);
|
|
1268
|
+
const leftEdge = window.innerWidth - CONTENT_MARGIN;
|
|
1269
|
+
const clampedRight = clamp(right, [CONTENT_MARGIN, Math.max(CONTENT_MARGIN, leftEdge - contentWidth)]);
|
|
1270
|
+
contentWrapper.style.minWidth = minContentWidth + "px";
|
|
1271
|
+
contentWrapper.style.right = clampedRight + "px";
|
|
1272
|
+
}
|
|
1273
|
+
const items = getItems();
|
|
1274
|
+
const availableHeight = window.innerHeight - CONTENT_MARGIN * 2;
|
|
1275
|
+
const itemsHeight = viewport.scrollHeight;
|
|
1276
|
+
const contentStyles = window.getComputedStyle(content);
|
|
1277
|
+
const contentBorderTopWidth = parseInt(contentStyles.borderTopWidth, 10);
|
|
1278
|
+
const contentPaddingTop = parseInt(contentStyles.paddingTop, 10);
|
|
1279
|
+
const contentBorderBottomWidth = parseInt(contentStyles.borderBottomWidth, 10);
|
|
1280
|
+
const contentPaddingBottom = parseInt(contentStyles.paddingBottom, 10);
|
|
1281
|
+
const fullContentHeight = contentBorderTopWidth + contentPaddingTop + itemsHeight + contentPaddingBottom + contentBorderBottomWidth;
|
|
1282
|
+
const minContentHeight = Math.min(selectedItem.offsetHeight * 5, fullContentHeight);
|
|
1283
|
+
const viewportStyles = window.getComputedStyle(viewport);
|
|
1284
|
+
const viewportPaddingTop = parseInt(viewportStyles.paddingTop, 10);
|
|
1285
|
+
const viewportPaddingBottom = parseInt(viewportStyles.paddingBottom, 10);
|
|
1286
|
+
const topEdgeToTriggerMiddle = triggerRect.top + triggerRect.height / 2 - CONTENT_MARGIN;
|
|
1287
|
+
const triggerMiddleToBottomEdge = availableHeight - topEdgeToTriggerMiddle;
|
|
1288
|
+
const selectedItemHalfHeight = selectedItem.offsetHeight / 2;
|
|
1289
|
+
const itemOffsetMiddle = selectedItem.offsetTop + selectedItemHalfHeight;
|
|
1290
|
+
const contentTopToItemMiddle = contentBorderTopWidth + contentPaddingTop + itemOffsetMiddle;
|
|
1291
|
+
const itemMiddleToContentBottom = fullContentHeight - contentTopToItemMiddle;
|
|
1292
|
+
if (contentTopToItemMiddle <= topEdgeToTriggerMiddle) {
|
|
1293
|
+
const isLastItem = items.length > 0 && selectedItem === items[items.length - 1].ref.current;
|
|
1294
|
+
contentWrapper.style.bottom = "0px";
|
|
1295
|
+
const viewportOffsetBottom = content.clientHeight - viewport.offsetTop - viewport.offsetHeight;
|
|
1296
|
+
const height = contentTopToItemMiddle + Math.max(triggerMiddleToBottomEdge, selectedItemHalfHeight + (isLastItem ? viewportPaddingBottom : 0) + viewportOffsetBottom + contentBorderBottomWidth);
|
|
1297
|
+
contentWrapper.style.height = height + "px";
|
|
1298
|
+
} else {
|
|
1299
|
+
const isFirstItem = items.length > 0 && selectedItem === items[0].ref.current;
|
|
1300
|
+
contentWrapper.style.top = "0px";
|
|
1301
|
+
const height = Math.max(topEdgeToTriggerMiddle, contentBorderTopWidth + viewport.offsetTop + (isFirstItem ? viewportPaddingTop : 0) + selectedItemHalfHeight) + itemMiddleToContentBottom;
|
|
1302
|
+
contentWrapper.style.height = height + "px";
|
|
1303
|
+
viewport.scrollTop = contentTopToItemMiddle - topEdgeToTriggerMiddle + viewport.offsetTop;
|
|
1304
|
+
}
|
|
1305
|
+
contentWrapper.style.margin = `${CONTENT_MARGIN}px 0`;
|
|
1306
|
+
contentWrapper.style.minHeight = minContentHeight + "px";
|
|
1307
|
+
contentWrapper.style.maxHeight = availableHeight + "px";
|
|
1308
|
+
onPlaced?.();
|
|
1309
|
+
requestAnimationFrame(() => shouldExpandOnScrollRef.current = true);
|
|
1310
|
+
}
|
|
1311
|
+
}, [
|
|
1312
|
+
getItems,
|
|
1313
|
+
context.trigger,
|
|
1314
|
+
context.valueNode,
|
|
1315
|
+
contentWrapper,
|
|
1316
|
+
content,
|
|
1317
|
+
viewport,
|
|
1318
|
+
selectedItem,
|
|
1319
|
+
selectedItemText,
|
|
1320
|
+
context.dir,
|
|
1321
|
+
onPlaced
|
|
1322
|
+
]);
|
|
1323
|
+
useLayoutEffect2(() => position(), [position]);
|
|
1324
|
+
const [contentZIndex, setContentZIndex] = import_react.useState();
|
|
1325
|
+
useLayoutEffect2(() => {
|
|
1326
|
+
if (content) setContentZIndex(window.getComputedStyle(content).zIndex);
|
|
1327
|
+
}, [content]);
|
|
1328
|
+
const handleScrollButtonChange = import_react.useCallback((node) => {
|
|
1329
|
+
if (node && shouldRepositionRef.current === true) {
|
|
1330
|
+
position();
|
|
1331
|
+
focusSelectedItem?.();
|
|
1332
|
+
shouldRepositionRef.current = false;
|
|
1333
|
+
}
|
|
1334
|
+
}, [position, focusSelectedItem]);
|
|
1335
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectViewportProvider, {
|
|
1336
|
+
scope: __scopeSelect,
|
|
1337
|
+
contentWrapper,
|
|
1338
|
+
shouldExpandOnScrollRef,
|
|
1339
|
+
onScrollButtonChange: handleScrollButtonChange,
|
|
1340
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
1341
|
+
ref: setContentWrapper,
|
|
1342
|
+
style: {
|
|
1343
|
+
display: "flex",
|
|
1344
|
+
flexDirection: "column",
|
|
1345
|
+
position: "fixed",
|
|
1346
|
+
zIndex: contentZIndex
|
|
1347
|
+
},
|
|
1348
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Primitive.div, {
|
|
1349
|
+
...popperProps,
|
|
1350
|
+
ref: composedRefs,
|
|
1351
|
+
style: {
|
|
1352
|
+
boxSizing: "border-box",
|
|
1353
|
+
maxHeight: "100%",
|
|
1354
|
+
...popperProps.style
|
|
1355
|
+
}
|
|
1356
|
+
})
|
|
1357
|
+
})
|
|
1358
|
+
});
|
|
1359
|
+
}, "SelectItemAlignedPosition"));
|
|
1360
|
+
var SelectPopperPosition = /* @__PURE__ */ import_react.forwardRef(/* @__PURE__ */ __name$1(function SelectPopperPosition2(props, forwardedRef) {
|
|
1361
|
+
const { __scopeSelect, align = "start", collisionPadding = CONTENT_MARGIN, ...popperProps } = props;
|
|
1362
|
+
const popperScope = usePopperScope(__scopeSelect);
|
|
1363
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopperContent, {
|
|
1364
|
+
...popperScope,
|
|
1365
|
+
...popperProps,
|
|
1366
|
+
ref: forwardedRef,
|
|
1367
|
+
align,
|
|
1368
|
+
collisionPadding,
|
|
1369
|
+
style: {
|
|
1370
|
+
boxSizing: "border-box",
|
|
1371
|
+
...popperProps.style,
|
|
1372
|
+
"--radix-select-content-transform-origin": "var(--radix-popper-transform-origin)",
|
|
1373
|
+
"--radix-select-content-available-width": "var(--radix-popper-available-width)",
|
|
1374
|
+
"--radix-select-content-available-height": "var(--radix-popper-available-height)",
|
|
1375
|
+
"--radix-select-trigger-width": "var(--radix-popper-anchor-width)",
|
|
1376
|
+
"--radix-select-trigger-height": "var(--radix-popper-anchor-height)"
|
|
1377
|
+
}
|
|
1378
|
+
});
|
|
1379
|
+
}, "SelectPopperPosition"));
|
|
1380
|
+
var [SelectViewportProvider, useSelectViewportContext] = createSelectContext(CONTENT_NAME, {});
|
|
1381
|
+
var VIEWPORT_NAME = "SelectViewport";
|
|
1382
|
+
var SelectViewport = /* @__PURE__ */ import_react.forwardRef(/* @__PURE__ */ __name$1(function SelectViewport2(props, forwardedRef) {
|
|
1383
|
+
const { __scopeSelect, nonce, ...viewportProps } = props;
|
|
1384
|
+
const contentContext = useSelectContentContext(VIEWPORT_NAME, __scopeSelect);
|
|
1385
|
+
const viewportContext = useSelectViewportContext(VIEWPORT_NAME, __scopeSelect);
|
|
1386
|
+
const composedRefs = useComposedRefs(forwardedRef, contentContext.onViewportChange);
|
|
1387
|
+
const prevScrollTopRef = import_react.useRef(0);
|
|
1388
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", {
|
|
1389
|
+
dangerouslySetInnerHTML: { __html: `[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}` },
|
|
1390
|
+
nonce
|
|
1391
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Collection.Slot, {
|
|
1392
|
+
scope: __scopeSelect,
|
|
1393
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Primitive.div, {
|
|
1394
|
+
"data-radix-select-viewport": "",
|
|
1395
|
+
role: "presentation",
|
|
1396
|
+
...viewportProps,
|
|
1397
|
+
ref: composedRefs,
|
|
1398
|
+
style: {
|
|
1399
|
+
position: "relative",
|
|
1400
|
+
flex: 1,
|
|
1401
|
+
overflow: "hidden auto",
|
|
1402
|
+
...viewportProps.style
|
|
1403
|
+
},
|
|
1404
|
+
onScroll: composeEventHandlers(viewportProps.onScroll, (event) => {
|
|
1405
|
+
const viewport = event.currentTarget;
|
|
1406
|
+
const { contentWrapper, shouldExpandOnScrollRef } = viewportContext;
|
|
1407
|
+
if (shouldExpandOnScrollRef?.current && contentWrapper) {
|
|
1408
|
+
const scrolledBy = Math.abs(prevScrollTopRef.current - viewport.scrollTop);
|
|
1409
|
+
if (scrolledBy > 0) {
|
|
1410
|
+
const availableHeight = window.innerHeight - CONTENT_MARGIN * 2;
|
|
1411
|
+
const cssMinHeight = parseFloat(contentWrapper.style.minHeight);
|
|
1412
|
+
const cssHeight = parseFloat(contentWrapper.style.height);
|
|
1413
|
+
const prevHeight = Math.max(cssMinHeight, cssHeight);
|
|
1414
|
+
if (prevHeight < availableHeight) {
|
|
1415
|
+
const nextHeight = prevHeight + scrolledBy;
|
|
1416
|
+
const clampedNextHeight = Math.min(availableHeight, nextHeight);
|
|
1417
|
+
const heightDiff = nextHeight - clampedNextHeight;
|
|
1418
|
+
contentWrapper.style.height = clampedNextHeight + "px";
|
|
1419
|
+
if (contentWrapper.style.bottom === "0px") {
|
|
1420
|
+
viewport.scrollTop = heightDiff > 0 ? heightDiff : 0;
|
|
1421
|
+
contentWrapper.style.justifyContent = "flex-end";
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
prevScrollTopRef.current = viewport.scrollTop;
|
|
1427
|
+
})
|
|
1428
|
+
})
|
|
1429
|
+
})] });
|
|
1430
|
+
}, "SelectViewport"));
|
|
1431
|
+
var [SelectGroupContextProvider, useSelectGroupContext] = createSelectContext("SelectGroup");
|
|
1432
|
+
var LABEL_NAME = "SelectLabel";
|
|
1433
|
+
var SelectLabel$1 = /* @__PURE__ */ import_react.forwardRef(/* @__PURE__ */ __name$1(function SelectLabel2(props, forwardedRef) {
|
|
1434
|
+
const { __scopeSelect, ...labelProps } = props;
|
|
1435
|
+
const groupContext = useSelectGroupContext(LABEL_NAME, __scopeSelect);
|
|
1436
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Primitive.div, {
|
|
1437
|
+
id: groupContext.id,
|
|
1438
|
+
...labelProps,
|
|
1439
|
+
ref: forwardedRef
|
|
1440
|
+
});
|
|
1441
|
+
}, "SelectLabel"));
|
|
1442
|
+
var ITEM_NAME = "SelectItem";
|
|
1443
|
+
var [SelectItemContextProvider, useSelectItemContext] = createSelectContext(ITEM_NAME);
|
|
1444
|
+
var SelectItem$1 = /* @__PURE__ */ import_react.forwardRef(/* @__PURE__ */ __name$1(function SelectItem2(props, forwardedRef) {
|
|
1445
|
+
const { __scopeSelect, value, disabled = false, textValue: textValueProp, ...itemProps } = props;
|
|
1446
|
+
const context = useSelectContext(ITEM_NAME, __scopeSelect);
|
|
1447
|
+
const contentContext = useSelectContentContext(ITEM_NAME, __scopeSelect);
|
|
1448
|
+
const isSelected = context.value === value;
|
|
1449
|
+
const [textValue, setTextValue] = import_react.useState(textValueProp ?? "");
|
|
1450
|
+
const [isFocused, setIsFocused] = import_react.useState(false);
|
|
1451
|
+
const handleItemRefCallback = useCallbackRef((node) => contentContext.itemRefCallback?.(node, value, disabled));
|
|
1452
|
+
const composedRefs = useComposedRefs(forwardedRef, handleItemRefCallback);
|
|
1453
|
+
const textId = useId();
|
|
1454
|
+
const pointerTypeRef = import_react.useRef("touch");
|
|
1455
|
+
function handleSelect(event) {
|
|
1456
|
+
context.hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
1457
|
+
context.onUserSelect(value);
|
|
1458
|
+
context.onOpenChange(false);
|
|
1459
|
+
}
|
|
1460
|
+
__name$1(handleSelect, "handleSelect");
|
|
1461
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectItemContextProvider, {
|
|
1462
|
+
scope: __scopeSelect,
|
|
1463
|
+
value,
|
|
1464
|
+
disabled,
|
|
1465
|
+
textId,
|
|
1466
|
+
isSelected,
|
|
1467
|
+
onItemTextChange: import_react.useCallback((node) => {
|
|
1468
|
+
setTextValue((prevTextValue) => prevTextValue || (node?.textContent ?? "").trim());
|
|
1469
|
+
}, []),
|
|
1470
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Collection.ItemSlot, {
|
|
1471
|
+
scope: __scopeSelect,
|
|
1472
|
+
value,
|
|
1473
|
+
disabled,
|
|
1474
|
+
textValue,
|
|
1475
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Primitive.div, {
|
|
1476
|
+
role: "option",
|
|
1477
|
+
"aria-labelledby": textId,
|
|
1478
|
+
"data-highlighted": isFocused ? "" : void 0,
|
|
1479
|
+
"aria-selected": isSelected && isFocused,
|
|
1480
|
+
"data-state": isSelected ? "checked" : "unchecked",
|
|
1481
|
+
"aria-disabled": disabled || void 0,
|
|
1482
|
+
"data-disabled": disabled ? "" : void 0,
|
|
1483
|
+
tabIndex: disabled ? void 0 : -1,
|
|
1484
|
+
...itemProps,
|
|
1485
|
+
ref: composedRefs,
|
|
1486
|
+
onFocus: composeEventHandlers(itemProps.onFocus, () => setIsFocused(true)),
|
|
1487
|
+
onBlur: composeEventHandlers(itemProps.onBlur, () => setIsFocused(false)),
|
|
1488
|
+
onClick: composeEventHandlers(itemProps.onClick, (event) => {
|
|
1489
|
+
if (disabled) return;
|
|
1490
|
+
if (pointerTypeRef.current !== "mouse") handleSelect(event);
|
|
1491
|
+
}),
|
|
1492
|
+
onPointerUp: composeEventHandlers(itemProps.onPointerUp, (event) => {
|
|
1493
|
+
if (disabled) return;
|
|
1494
|
+
if (pointerTypeRef.current === "mouse") handleSelect(event);
|
|
1495
|
+
}),
|
|
1496
|
+
onPointerDown: composeEventHandlers(itemProps.onPointerDown, (event) => {
|
|
1497
|
+
pointerTypeRef.current = event.pointerType;
|
|
1498
|
+
}),
|
|
1499
|
+
onPointerMove: composeEventHandlers(itemProps.onPointerMove, (event) => {
|
|
1500
|
+
pointerTypeRef.current = event.pointerType;
|
|
1501
|
+
if (disabled) contentContext.onItemLeave?.();
|
|
1502
|
+
else if (pointerTypeRef.current === "mouse") event.currentTarget.focus({ preventScroll: true });
|
|
1503
|
+
}),
|
|
1504
|
+
onPointerLeave: composeEventHandlers(itemProps.onPointerLeave, (event) => {
|
|
1505
|
+
if (event.currentTarget === document.activeElement) contentContext.onItemLeave?.();
|
|
1506
|
+
}),
|
|
1507
|
+
onKeyDown: composeEventHandlers(itemProps.onKeyDown, (event) => {
|
|
1508
|
+
if (disabled || event.target !== event.currentTarget) return;
|
|
1509
|
+
if (contentContext.searchRef?.current !== "" && event.key === " ") return;
|
|
1510
|
+
if (SELECTION_KEYS.includes(event.key)) handleSelect(event);
|
|
1511
|
+
if (event.key === " ") event.preventDefault();
|
|
1512
|
+
})
|
|
1513
|
+
})
|
|
1514
|
+
})
|
|
1515
|
+
});
|
|
1516
|
+
}, "SelectItem"));
|
|
1517
|
+
var ITEM_TEXT_NAME = "SelectItemText";
|
|
1518
|
+
var SelectItemText = /* @__PURE__ */ import_react.forwardRef(/* @__PURE__ */ __name$1(function SelectItemText2(props, forwardedRef) {
|
|
1519
|
+
const { __scopeSelect, className, style, ...itemTextProps } = props;
|
|
1520
|
+
const context = useSelectContext(ITEM_TEXT_NAME, __scopeSelect);
|
|
1521
|
+
const contentContext = useSelectContentContext(ITEM_TEXT_NAME, __scopeSelect);
|
|
1522
|
+
const itemContext = useSelectItemContext(ITEM_TEXT_NAME, __scopeSelect);
|
|
1523
|
+
const nativeOptionsContext = useSelectNativeOptionsContext(ITEM_TEXT_NAME, __scopeSelect);
|
|
1524
|
+
const [itemTextNode, setItemTextNode] = import_react.useState(null);
|
|
1525
|
+
const handleItemTextRefCallback = useCallbackRef((node) => contentContext.itemTextRefCallback?.(node, itemContext.value, itemContext.disabled));
|
|
1526
|
+
const composedRefs = useComposedRefs(forwardedRef, setItemTextNode, itemContext.onItemTextChange, handleItemTextRefCallback);
|
|
1527
|
+
const textContent = itemTextNode?.textContent;
|
|
1528
|
+
const nativeOption = import_react.useMemo(() => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", {
|
|
1529
|
+
value: itemContext.value,
|
|
1530
|
+
disabled: itemContext.disabled,
|
|
1531
|
+
children: textContent
|
|
1532
|
+
}, itemContext.value), [
|
|
1533
|
+
itemContext.disabled,
|
|
1534
|
+
itemContext.value,
|
|
1535
|
+
textContent
|
|
1536
|
+
]);
|
|
1537
|
+
const { onNativeOptionAdd, onNativeOptionRemove } = nativeOptionsContext;
|
|
1538
|
+
useLayoutEffect2(() => {
|
|
1539
|
+
onNativeOptionAdd(nativeOption);
|
|
1540
|
+
return () => onNativeOptionRemove(nativeOption);
|
|
1541
|
+
}, [
|
|
1542
|
+
onNativeOptionAdd,
|
|
1543
|
+
onNativeOptionRemove,
|
|
1544
|
+
nativeOption
|
|
1545
|
+
]);
|
|
1546
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Primitive.span, {
|
|
1547
|
+
id: itemContext.textId,
|
|
1548
|
+
...itemTextProps,
|
|
1549
|
+
ref: composedRefs
|
|
1550
|
+
}), itemContext.isSelected && context.valueNode && !context.valueNodeHasChildren && !shouldShowPlaceholder(context.value) ? import_react_dom.createPortal(itemTextProps.children, context.valueNode) : null] });
|
|
1551
|
+
}, "SelectItemText"));
|
|
1552
|
+
var ITEM_INDICATOR_NAME = "SelectItemIndicator";
|
|
1553
|
+
var SelectItemIndicator = /* @__PURE__ */ import_react.forwardRef(/* @__PURE__ */ __name$1(function SelectItemIndicator2(props, forwardedRef) {
|
|
1554
|
+
const { __scopeSelect, ...itemIndicatorProps } = props;
|
|
1555
|
+
return useSelectItemContext(ITEM_INDICATOR_NAME, __scopeSelect).isSelected ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Primitive.span, {
|
|
1556
|
+
"aria-hidden": true,
|
|
1557
|
+
...itemIndicatorProps,
|
|
1558
|
+
ref: forwardedRef
|
|
1559
|
+
}) : null;
|
|
1560
|
+
}, "SelectItemIndicator"));
|
|
1561
|
+
var SCROLL_UP_BUTTON_NAME = "SelectScrollUpButton";
|
|
1562
|
+
var SelectScrollUpButton$1 = /* @__PURE__ */ import_react.forwardRef(/* @__PURE__ */ __name$1(function SelectScrollUpButton2(props, forwardedRef) {
|
|
1563
|
+
const contentContext = useSelectContentContext(SCROLL_UP_BUTTON_NAME, props.__scopeSelect);
|
|
1564
|
+
const viewportContext = useSelectViewportContext(SCROLL_UP_BUTTON_NAME, props.__scopeSelect);
|
|
1565
|
+
const [canScrollUp, setCanScrollUp] = import_react.useState(false);
|
|
1566
|
+
const composedRefs = useComposedRefs(forwardedRef, viewportContext.onScrollButtonChange);
|
|
1567
|
+
useLayoutEffect2(() => {
|
|
1568
|
+
if (contentContext.viewport && contentContext.isPositioned) {
|
|
1569
|
+
let handleScroll2 = function() {
|
|
1570
|
+
const canScrollUp2 = viewport.scrollTop > 0;
|
|
1571
|
+
setCanScrollUp(canScrollUp2);
|
|
1572
|
+
};
|
|
1573
|
+
__name$1(handleScroll2, "handleScroll");
|
|
1574
|
+
const viewport = contentContext.viewport;
|
|
1575
|
+
handleScroll2();
|
|
1576
|
+
viewport.addEventListener("scroll", handleScroll2);
|
|
1577
|
+
return () => viewport.removeEventListener("scroll", handleScroll2);
|
|
1578
|
+
}
|
|
1579
|
+
}, [contentContext.viewport, contentContext.isPositioned]);
|
|
1580
|
+
return canScrollUp ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectScrollButtonImpl, {
|
|
1581
|
+
...props,
|
|
1582
|
+
ref: composedRefs,
|
|
1583
|
+
onAutoScroll: () => {
|
|
1584
|
+
const { viewport, selectedItem } = contentContext;
|
|
1585
|
+
if (viewport && selectedItem) viewport.scrollTop = viewport.scrollTop - selectedItem.offsetHeight;
|
|
1586
|
+
}
|
|
1587
|
+
}) : null;
|
|
1588
|
+
}, "SelectScrollUpButton"));
|
|
1589
|
+
var SCROLL_DOWN_BUTTON_NAME = "SelectScrollDownButton";
|
|
1590
|
+
var SelectScrollDownButton$1 = /* @__PURE__ */ import_react.forwardRef(/* @__PURE__ */ __name$1(function SelectScrollDownButton2(props, forwardedRef) {
|
|
1591
|
+
const contentContext = useSelectContentContext(SCROLL_DOWN_BUTTON_NAME, props.__scopeSelect);
|
|
1592
|
+
const viewportContext = useSelectViewportContext(SCROLL_DOWN_BUTTON_NAME, props.__scopeSelect);
|
|
1593
|
+
const [canScrollDown, setCanScrollDown] = import_react.useState(false);
|
|
1594
|
+
const composedRefs = useComposedRefs(forwardedRef, viewportContext.onScrollButtonChange);
|
|
1595
|
+
useLayoutEffect2(() => {
|
|
1596
|
+
if (contentContext.viewport && contentContext.isPositioned) {
|
|
1597
|
+
let handleScroll2 = function() {
|
|
1598
|
+
const maxScroll = viewport.scrollHeight - viewport.clientHeight;
|
|
1599
|
+
const canScrollDown2 = Math.ceil(viewport.scrollTop) < maxScroll;
|
|
1600
|
+
setCanScrollDown(canScrollDown2);
|
|
1601
|
+
};
|
|
1602
|
+
__name$1(handleScroll2, "handleScroll");
|
|
1603
|
+
const viewport = contentContext.viewport;
|
|
1604
|
+
handleScroll2();
|
|
1605
|
+
viewport.addEventListener("scroll", handleScroll2);
|
|
1606
|
+
return () => viewport.removeEventListener("scroll", handleScroll2);
|
|
1607
|
+
}
|
|
1608
|
+
}, [contentContext.viewport, contentContext.isPositioned]);
|
|
1609
|
+
return canScrollDown ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectScrollButtonImpl, {
|
|
1610
|
+
...props,
|
|
1611
|
+
ref: composedRefs,
|
|
1612
|
+
onAutoScroll: () => {
|
|
1613
|
+
const { viewport, selectedItem } = contentContext;
|
|
1614
|
+
if (viewport && selectedItem) viewport.scrollTop = viewport.scrollTop + selectedItem.offsetHeight;
|
|
1615
|
+
}
|
|
1616
|
+
}) : null;
|
|
1617
|
+
}, "SelectScrollDownButton"));
|
|
1618
|
+
var SelectScrollButtonImpl = /* @__PURE__ */ import_react.forwardRef(/* @__PURE__ */ __name$1(function SelectScrollButtonImpl2(props, forwardedRef) {
|
|
1619
|
+
const { __scopeSelect, onAutoScroll, ...scrollIndicatorProps } = props;
|
|
1620
|
+
const contentContext = useSelectContentContext("SelectScrollButton", __scopeSelect);
|
|
1621
|
+
const autoScrollTimerRef = import_react.useRef(null);
|
|
1622
|
+
const getItems = useCollection(__scopeSelect);
|
|
1623
|
+
const clearAutoScrollTimer = import_react.useCallback(() => {
|
|
1624
|
+
if (autoScrollTimerRef.current !== null) {
|
|
1625
|
+
window.clearInterval(autoScrollTimerRef.current);
|
|
1626
|
+
autoScrollTimerRef.current = null;
|
|
1627
|
+
}
|
|
1628
|
+
}, []);
|
|
1629
|
+
import_react.useEffect(() => {
|
|
1630
|
+
return () => clearAutoScrollTimer();
|
|
1631
|
+
}, [clearAutoScrollTimer]);
|
|
1632
|
+
useLayoutEffect2(() => {
|
|
1633
|
+
getItems().find((item) => item.ref.current === document.activeElement)?.ref.current?.scrollIntoView({ block: "nearest" });
|
|
1634
|
+
}, [getItems]);
|
|
1635
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Primitive.div, {
|
|
1636
|
+
"aria-hidden": true,
|
|
1637
|
+
...scrollIndicatorProps,
|
|
1638
|
+
ref: forwardedRef,
|
|
1639
|
+
style: {
|
|
1640
|
+
flexShrink: 0,
|
|
1641
|
+
...scrollIndicatorProps.style
|
|
1642
|
+
},
|
|
1643
|
+
onPointerDown: composeEventHandlers(scrollIndicatorProps.onPointerDown, () => {
|
|
1644
|
+
if (autoScrollTimerRef.current === null) autoScrollTimerRef.current = window.setInterval(onAutoScroll, 50);
|
|
1645
|
+
}),
|
|
1646
|
+
onPointerMove: composeEventHandlers(scrollIndicatorProps.onPointerMove, () => {
|
|
1647
|
+
contentContext.onItemLeave?.();
|
|
1648
|
+
if (autoScrollTimerRef.current === null) autoScrollTimerRef.current = window.setInterval(onAutoScroll, 50);
|
|
1649
|
+
}),
|
|
1650
|
+
onPointerLeave: composeEventHandlers(scrollIndicatorProps.onPointerLeave, () => {
|
|
1651
|
+
clearAutoScrollTimer();
|
|
1652
|
+
})
|
|
1653
|
+
});
|
|
1654
|
+
}, "SelectScrollButtonImpl"));
|
|
1655
|
+
var SelectSeparator$1 = /* @__PURE__ */ import_react.forwardRef(/* @__PURE__ */ __name$1(function SelectSeparator2(props, forwardedRef) {
|
|
1656
|
+
const { __scopeSelect, ...separatorProps } = props;
|
|
1657
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Primitive.div, {
|
|
1658
|
+
"aria-hidden": true,
|
|
1659
|
+
...separatorProps,
|
|
1660
|
+
ref: forwardedRef
|
|
1661
|
+
});
|
|
1662
|
+
}, "SelectSeparator"));
|
|
1663
|
+
var BUBBLE_INPUT_NAME$1 = "SelectBubbleInput";
|
|
1664
|
+
var SelectBubbleInput = /* @__PURE__ */ import_react.forwardRef(/* @__PURE__ */ __name$1(function SelectBubbleInput2({ __scopeSelect, ...props }, forwardedRef) {
|
|
1665
|
+
const context = useSelectContext(BUBBLE_INPUT_NAME$1, __scopeSelect);
|
|
1666
|
+
const { value, onValueChange, required, disabled, name, autoComplete, form, userSelection } = context;
|
|
1667
|
+
const { nativeOptions, nativeSelectKey } = context;
|
|
1668
|
+
const ref = import_react.useRef(null);
|
|
1669
|
+
const composedRefs = useComposedRefs(forwardedRef, ref);
|
|
1670
|
+
const selectValue = value ?? "";
|
|
1671
|
+
const prevValueRef = import_react.useRef(selectValue);
|
|
1672
|
+
const handledUserSelectionRef = import_react.useRef(userSelection);
|
|
1673
|
+
const isDispatchingUserSelectionRef = import_react.useRef(false);
|
|
1674
|
+
const hasEmptyValueOption = Array.from(nativeOptions).some((option) => (option.props.value ?? "") === "");
|
|
1675
|
+
import_react.useEffect(() => {
|
|
1676
|
+
const select = ref.current;
|
|
1677
|
+
if (!select) return;
|
|
1678
|
+
const selectProto = window.HTMLSelectElement.prototype;
|
|
1679
|
+
const setValue = Object.getOwnPropertyDescriptor(selectProto, "value").set;
|
|
1680
|
+
const isNewUserSelection = userSelection !== null && userSelection !== handledUserSelectionRef.current;
|
|
1681
|
+
handledUserSelectionRef.current = userSelection;
|
|
1682
|
+
const valueChanged = prevValueRef.current !== selectValue;
|
|
1683
|
+
prevValueRef.current = selectValue;
|
|
1684
|
+
const isUserInteraction = isNewUserSelection && valueChanged;
|
|
1685
|
+
if (isNewUserSelection && !valueChanged && userSelection.value !== selectValue && !userSelection.hasConsumerStoppedPropagation && setValue) {
|
|
1686
|
+
isDispatchingUserSelectionRef.current = true;
|
|
1687
|
+
try {
|
|
1688
|
+
setValue.call(select, userSelection.value);
|
|
1689
|
+
select.dispatchEvent(new Event("change", { bubbles: true }));
|
|
1690
|
+
} finally {
|
|
1691
|
+
isDispatchingUserSelectionRef.current = false;
|
|
1692
|
+
setValue.call(select, selectValue);
|
|
1693
|
+
}
|
|
1694
|
+
return;
|
|
1695
|
+
}
|
|
1696
|
+
const bubbles = isUserInteraction && !userSelection.hasConsumerStoppedPropagation;
|
|
1697
|
+
if (valueChanged && setValue) {
|
|
1698
|
+
const event = new Event("change", { bubbles });
|
|
1699
|
+
setValue.call(select, selectValue);
|
|
1700
|
+
select.dispatchEvent(event);
|
|
1701
|
+
}
|
|
1702
|
+
}, [selectValue, userSelection]);
|
|
1703
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Primitive.select, {
|
|
1704
|
+
"aria-hidden": true,
|
|
1705
|
+
required,
|
|
1706
|
+
tabIndex: -1,
|
|
1707
|
+
name,
|
|
1708
|
+
autoComplete,
|
|
1709
|
+
disabled,
|
|
1710
|
+
form,
|
|
1711
|
+
onChange: (event) => {
|
|
1712
|
+
if (!isDispatchingUserSelectionRef.current) onValueChange(event.target.value);
|
|
1713
|
+
},
|
|
1714
|
+
...props,
|
|
1715
|
+
style: {
|
|
1716
|
+
...VISUALLY_HIDDEN_STYLES,
|
|
1717
|
+
...props.style
|
|
1718
|
+
},
|
|
1719
|
+
ref: composedRefs,
|
|
1720
|
+
defaultValue: selectValue,
|
|
1721
|
+
children: [shouldShowPlaceholder(value) && !hasEmptyValueOption ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "" }) : null, Array.from(nativeOptions)]
|
|
1722
|
+
}, nativeSelectKey);
|
|
1723
|
+
}, "SelectBubbleInput"));
|
|
1724
|
+
function isFunction$2(value) {
|
|
1725
|
+
return typeof value === "function";
|
|
1726
|
+
}
|
|
1727
|
+
__name$1(isFunction$2, "isFunction");
|
|
1728
|
+
function shouldShowPlaceholder(value) {
|
|
1729
|
+
return value === "" || value === void 0;
|
|
1730
|
+
}
|
|
1731
|
+
__name$1(shouldShowPlaceholder, "shouldShowPlaceholder");
|
|
1732
|
+
function useTypeaheadSearch(onSearchChange) {
|
|
1733
|
+
const handleSearchChange = useCallbackRef(onSearchChange);
|
|
1734
|
+
const searchRef = import_react.useRef("");
|
|
1735
|
+
const timerRef = import_react.useRef(0);
|
|
1736
|
+
const handleTypeaheadSearch = import_react.useCallback((key) => {
|
|
1737
|
+
const search = searchRef.current + key;
|
|
1738
|
+
handleSearchChange(search);
|
|
1739
|
+
function updateSearch(value) {
|
|
1740
|
+
searchRef.current = value;
|
|
1741
|
+
window.clearTimeout(timerRef.current);
|
|
1742
|
+
if (value !== "") timerRef.current = window.setTimeout(() => updateSearch(""), 1e3);
|
|
1743
|
+
}
|
|
1744
|
+
__name$1(updateSearch, "updateSearch");
|
|
1745
|
+
updateSearch(search);
|
|
1746
|
+
}, [handleSearchChange]);
|
|
1747
|
+
const resetTypeahead = import_react.useCallback(() => {
|
|
1748
|
+
searchRef.current = "";
|
|
1749
|
+
window.clearTimeout(timerRef.current);
|
|
1750
|
+
}, []);
|
|
1751
|
+
import_react.useEffect(() => {
|
|
1752
|
+
return () => window.clearTimeout(timerRef.current);
|
|
1753
|
+
}, []);
|
|
1754
|
+
return [
|
|
1755
|
+
searchRef,
|
|
1756
|
+
handleTypeaheadSearch,
|
|
1757
|
+
resetTypeahead
|
|
1758
|
+
];
|
|
1759
|
+
}
|
|
1760
|
+
__name$1(useTypeaheadSearch, "useTypeaheadSearch");
|
|
1761
|
+
function findNextItem(items, search, currentItem) {
|
|
1762
|
+
const normalizedSearch = search.length > 1 && Array.from(search).every((char) => char === search[0]) ? search[0] : search;
|
|
1763
|
+
const currentItemIndex = currentItem ? items.indexOf(currentItem) : -1;
|
|
1764
|
+
let wrappedItems = wrapArray(items, Math.max(currentItemIndex, 0));
|
|
1765
|
+
if (normalizedSearch.length === 1) wrappedItems = wrappedItems.filter((v) => v !== currentItem);
|
|
1766
|
+
const nextItem = wrappedItems.find((item) => item.textValue.toLowerCase().startsWith(normalizedSearch.toLowerCase()));
|
|
1767
|
+
return nextItem !== currentItem ? nextItem : void 0;
|
|
1768
|
+
}
|
|
1769
|
+
__name$1(findNextItem, "findNextItem");
|
|
1770
|
+
function wrapArray(array, startIndex) {
|
|
1771
|
+
return array.map((_, index) => array[(startIndex + index) % array.length]);
|
|
1772
|
+
}
|
|
1773
|
+
__name$1(wrapArray, "wrapArray");
|
|
1774
|
+
// app/components/ui/select.tsx
|
|
1775
|
+
var Select = Select$1;
|
|
1776
|
+
var SelectValue = SelectValue$1;
|
|
1777
|
+
var SelectTrigger = import_react.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(SelectTrigger$1, {
|
|
1778
|
+
ref,
|
|
1779
|
+
className: cn("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1", className),
|
|
1780
|
+
...props,
|
|
1781
|
+
children: [children, /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectIcon, {
|
|
1782
|
+
asChild: true,
|
|
1783
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChevronDown, { className: "h-4 w-4 opacity-50" })
|
|
1784
|
+
})]
|
|
1785
|
+
}));
|
|
1786
|
+
SelectTrigger.displayName = SelectTrigger$1.displayName;
|
|
1787
|
+
var SelectScrollUpButton = import_react.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectScrollUpButton$1, {
|
|
1788
|
+
ref,
|
|
1789
|
+
className: cn("flex cursor-default items-center justify-center py-1", className),
|
|
1790
|
+
...props,
|
|
1791
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChevronUp, { className: "h-4 w-4" })
|
|
1792
|
+
}));
|
|
1793
|
+
SelectScrollUpButton.displayName = SelectScrollUpButton$1.displayName;
|
|
1794
|
+
var SelectScrollDownButton = import_react.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectScrollDownButton$1, {
|
|
1795
|
+
ref,
|
|
1796
|
+
className: cn("flex cursor-default items-center justify-center py-1", className),
|
|
1797
|
+
...props,
|
|
1798
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChevronDown, { className: "h-4 w-4" })
|
|
1799
|
+
}));
|
|
1800
|
+
SelectScrollDownButton.displayName = SelectScrollDownButton$1.displayName;
|
|
1801
|
+
var SelectContent = import_react.forwardRef(({ className, children, position = "popper", ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectPortal, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(SelectContent$1, {
|
|
1802
|
+
ref,
|
|
1803
|
+
className: cn("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", position === "popper" && "data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1", className),
|
|
1804
|
+
position,
|
|
1805
|
+
...props,
|
|
1806
|
+
children: [
|
|
1807
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectScrollUpButton, {}),
|
|
1808
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectViewport, {
|
|
1809
|
+
className: cn("p-1", position === "popper" && "h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),
|
|
1810
|
+
children
|
|
1811
|
+
}),
|
|
1812
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectScrollDownButton, {})
|
|
1813
|
+
]
|
|
1814
|
+
}) }));
|
|
1815
|
+
SelectContent.displayName = SelectContent$1.displayName;
|
|
1816
|
+
var SelectLabel = import_react.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectLabel$1, {
|
|
1817
|
+
ref,
|
|
1818
|
+
className: cn("py-1.5 pl-8 pr-2 text-sm font-semibold", className),
|
|
1819
|
+
...props
|
|
1820
|
+
}));
|
|
1821
|
+
SelectLabel.displayName = SelectLabel$1.displayName;
|
|
1822
|
+
var SelectItem = import_react.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(SelectItem$1, {
|
|
1823
|
+
ref,
|
|
1824
|
+
className: cn("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50", className),
|
|
1825
|
+
...props,
|
|
1826
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1827
|
+
className: "absolute left-2 flex h-3.5 w-3.5 items-center justify-center",
|
|
1828
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectItemIndicator, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Check, { className: "h-4 w-4" }) })
|
|
1829
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectItemText, { children })]
|
|
1830
|
+
}));
|
|
1831
|
+
SelectItem.displayName = SelectItem$1.displayName;
|
|
1832
|
+
var SelectSeparator = import_react.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectSeparator$1, {
|
|
1833
|
+
ref,
|
|
1834
|
+
className: cn("-mx-1 my-1 h-px bg-muted", className),
|
|
1835
|
+
...props
|
|
1836
|
+
}));
|
|
1837
|
+
SelectSeparator.displayName = SelectSeparator$1.displayName;
|
|
1838
|
+
// app/lib/bulk-cancel-ui.ts
|
|
1839
|
+
/**
|
|
1840
|
+
* Choose the toast severity for a completed bulk-cancel request.
|
|
1841
|
+
*
|
|
1842
|
+
* `already_cancelled` is an idempotent success, so it counts toward the
|
|
1843
|
+
* success total — a batch that another caller had already cancelled is not an
|
|
1844
|
+
* error. The error toast is reserved for the case where nothing succeeded;
|
|
1845
|
+
* a genuine problem (failed / not-found / not-cancellable) alongside some
|
|
1846
|
+
* success is a warning.
|
|
1847
|
+
*/
|
|
1848
|
+
function bulkCancelToastSeverity(summary) {
|
|
1849
|
+
const succeeded = summary.cancelled + summary.alreadyCancelled;
|
|
1850
|
+
const hadProblem = summary.failed + summary.notCancellable + summary.notFound > 0;
|
|
1851
|
+
if (succeeded === 0) return "error";
|
|
1852
|
+
if (hadProblem) return "warning";
|
|
1853
|
+
return "success";
|
|
1854
|
+
}
|
|
1855
|
+
/**
|
|
1856
|
+
* Whether a run should stay selected after a bulk-cancel batch. Retryable
|
|
1857
|
+
* failures are kept selected so the user can retry them without reselecting;
|
|
1858
|
+
* every terminal outcome (cancelled, already-cancelled, not-cancellable,
|
|
1859
|
+
* not-found, and non-retryable failures) is cleared.
|
|
1860
|
+
*/
|
|
1861
|
+
function shouldRetainSelectionAfterBulkCancel(result) {
|
|
1862
|
+
return result.outcome === "failed" && result.retryable;
|
|
1863
|
+
}
|
|
1864
|
+
// app/lib/hooks/use-table-selection.ts
|
|
1865
|
+
/**
|
|
1866
|
+
* Hook for managing table row selection state.
|
|
1867
|
+
* Provides a consistent interface for multi-select functionality across different tables.
|
|
1868
|
+
*/
|
|
1869
|
+
function useTableSelection({ getItemId }) {
|
|
1870
|
+
const [selectedIds, setSelectedIds] = (0, import_react.useState)(/* @__PURE__ */ new Set());
|
|
1871
|
+
const isSelected = (0, import_react.useCallback)((item) => selectedIds.has(getItemId(item)), [selectedIds, getItemId]);
|
|
1872
|
+
const toggleSelection = (0, import_react.useCallback)((item) => {
|
|
1873
|
+
const id = getItemId(item);
|
|
1874
|
+
setSelectedIds((prev) => {
|
|
1875
|
+
const next = new Set(prev);
|
|
1876
|
+
if (next.has(id)) next.delete(id);
|
|
1877
|
+
else next.add(id);
|
|
1878
|
+
return next;
|
|
1879
|
+
});
|
|
1880
|
+
}, [getItemId]);
|
|
1881
|
+
const selectAll = (0, import_react.useCallback)((items) => {
|
|
1882
|
+
setSelectedIds(new Set(items.map(getItemId)));
|
|
1883
|
+
}, [getItemId]);
|
|
1884
|
+
const clearSelection = (0, import_react.useCallback)(() => {
|
|
1885
|
+
setSelectedIds(/* @__PURE__ */ new Set());
|
|
1886
|
+
}, []);
|
|
1887
|
+
const isAllSelected = (0, import_react.useCallback)((items) => {
|
|
1888
|
+
if (items.length === 0) return false;
|
|
1889
|
+
return items.every((item) => selectedIds.has(getItemId(item)));
|
|
1890
|
+
}, [selectedIds, getItemId]);
|
|
1891
|
+
const isSomeSelected = (0, import_react.useCallback)((items) => {
|
|
1892
|
+
if (items.length === 0) return false;
|
|
1893
|
+
const someSelected = items.some((item) => selectedIds.has(getItemId(item)));
|
|
1894
|
+
const allSelected = items.every((item) => selectedIds.has(getItemId(item)));
|
|
1895
|
+
return someSelected && !allSelected;
|
|
1896
|
+
}, [selectedIds, getItemId]);
|
|
1897
|
+
const toggleSelectAll = (0, import_react.useCallback)((items) => {
|
|
1898
|
+
if (isAllSelected(items)) clearSelection();
|
|
1899
|
+
else selectAll(items);
|
|
1900
|
+
}, [
|
|
1901
|
+
isAllSelected,
|
|
1902
|
+
clearSelection,
|
|
1903
|
+
selectAll
|
|
1904
|
+
]);
|
|
1905
|
+
const deselectById = (0, import_react.useCallback)((id) => {
|
|
1906
|
+
setSelectedIds((prev) => {
|
|
1907
|
+
const next = new Set(prev);
|
|
1908
|
+
next.delete(id);
|
|
1909
|
+
return next;
|
|
1910
|
+
});
|
|
1911
|
+
}, []);
|
|
1912
|
+
const selectionCount = selectedIds.size;
|
|
1913
|
+
return (0, import_react.useMemo)(() => ({
|
|
1914
|
+
selectedIds,
|
|
1915
|
+
isSelected,
|
|
1916
|
+
toggleSelection,
|
|
1917
|
+
clearSelection,
|
|
1918
|
+
toggleSelectAll,
|
|
1919
|
+
selectionCount,
|
|
1920
|
+
isAllSelected,
|
|
1921
|
+
isSomeSelected,
|
|
1922
|
+
deselectById
|
|
1923
|
+
}), [
|
|
1924
|
+
selectedIds,
|
|
1925
|
+
isSelected,
|
|
1926
|
+
toggleSelection,
|
|
1927
|
+
clearSelection,
|
|
1928
|
+
toggleSelectAll,
|
|
1929
|
+
selectionCount,
|
|
1930
|
+
isAllSelected,
|
|
1931
|
+
isSomeSelected,
|
|
1932
|
+
deselectById
|
|
1933
|
+
]);
|
|
1934
|
+
}
|
|
1935
|
+
// app/lib/run-replay.ts
|
|
1936
|
+
function getRunReplayDisabledReason(run, runIdentityLoading) {
|
|
1937
|
+
if (runIdentityLoading) return "Loading run identity...";
|
|
1938
|
+
if (!run) return "Unable to verify whether this run can be replayed.";
|
|
1939
|
+
if (run.executionContext?.dynamicWorkflow) return "Dynamic runs cannot be replayed as a new run.";
|
|
1940
|
+
}
|
|
1941
|
+
// app/components/display-utils/selection-bar.tsx
|
|
1942
|
+
/**
|
|
1943
|
+
* A floating bar that appears when items are selected in a table.
|
|
1944
|
+
* Shows selection count and provides actions for bulk operations.
|
|
1945
|
+
*/
|
|
1946
|
+
function SelectionBar({ selectionCount, onClearSelection, actions, itemLabel = "items", className }) {
|
|
1947
|
+
if (selectionCount === 0) return null;
|
|
1948
|
+
const label = selectionCount === 1 ? itemLabel.replace(/s$/, "") : itemLabel;
|
|
1949
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
1950
|
+
className: cn("fixed bottom-6 left-1/2 -translate-x-1/2 z-50", "flex items-center gap-3 px-4 py-2.5 rounded-lg", "bg-primary text-primary-foreground shadow-lg", "animate-in fade-in slide-in-from-bottom-4 duration-200", className),
|
|
1951
|
+
children: [
|
|
1952
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
1953
|
+
className: "text-sm font-medium",
|
|
1954
|
+
children: [
|
|
1955
|
+
selectionCount,
|
|
1956
|
+
" ",
|
|
1957
|
+
label,
|
|
1958
|
+
" selected"
|
|
1959
|
+
]
|
|
1960
|
+
}),
|
|
1961
|
+
actions && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
1962
|
+
className: "flex items-center gap-2 border-l border-primary-foreground/20 pl-3",
|
|
1963
|
+
children: actions
|
|
1964
|
+
}),
|
|
1965
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button, {
|
|
1966
|
+
variant: "tertiary",
|
|
1967
|
+
size: "small",
|
|
1968
|
+
className: "h-7 px-2 text-primary-foreground hover:bg-primary-foreground/10 hover:text-primary-foreground",
|
|
1969
|
+
onClick: onClearSelection,
|
|
1970
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(X, { className: "h-4 w-4" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1971
|
+
className: "sr-only",
|
|
1972
|
+
children: "Clear selection"
|
|
1973
|
+
})]
|
|
1974
|
+
})
|
|
1975
|
+
]
|
|
1976
|
+
});
|
|
1977
|
+
}
|
|
1978
|
+
// ../../node_modules/.bun/@radix-ui+react-checkbox@1.4.1+a68cb332b68cb125/node_modules/@radix-ui/react-checkbox/dist/index.mjs
|
|
1979
|
+
var __defProp = Object.defineProperty;
|
|
1980
|
+
var __name = (target, value) => __defProp(target, "name", {
|
|
1981
|
+
value,
|
|
1982
|
+
configurable: true
|
|
1983
|
+
});
|
|
1984
|
+
var CHECKBOX_NAME = "Checkbox";
|
|
1985
|
+
var [createCheckboxContext, createCheckboxScope] = createContextScope(CHECKBOX_NAME);
|
|
1986
|
+
var [CheckboxProviderImpl, useCheckboxContext] = createCheckboxContext(CHECKBOX_NAME);
|
|
1987
|
+
function CheckboxProvider(props) {
|
|
1988
|
+
const { __scopeCheckbox, checked: checkedProp, children, defaultChecked, disabled, form, name, onCheckedChange, required, value = "on", internal_do_not_use_render } = props;
|
|
1989
|
+
const [checked, setChecked] = useControllableState({
|
|
1990
|
+
prop: checkedProp,
|
|
1991
|
+
defaultProp: defaultChecked ?? false,
|
|
1992
|
+
onChange: onCheckedChange,
|
|
1993
|
+
caller: CHECKBOX_NAME
|
|
1994
|
+
});
|
|
1995
|
+
const [control, setControl] = import_react.useState(null);
|
|
1996
|
+
const [bubbleInput, setBubbleInput] = import_react.useState(null);
|
|
1997
|
+
const [userClick, setUserClick] = import_react.useState(null);
|
|
1998
|
+
const isFormControl = control ? !!form || !!control.closest("form") : true;
|
|
1999
|
+
const context = {
|
|
2000
|
+
checked,
|
|
2001
|
+
disabled,
|
|
2002
|
+
setChecked,
|
|
2003
|
+
control,
|
|
2004
|
+
setControl,
|
|
2005
|
+
name,
|
|
2006
|
+
form,
|
|
2007
|
+
value,
|
|
2008
|
+
userClick,
|
|
2009
|
+
onUserClick: setUserClick,
|
|
2010
|
+
required,
|
|
2011
|
+
defaultChecked: isIndeterminate(defaultChecked) ? false : defaultChecked,
|
|
2012
|
+
isFormControl,
|
|
2013
|
+
bubbleInput,
|
|
2014
|
+
setBubbleInput
|
|
2015
|
+
};
|
|
2016
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CheckboxProviderImpl, {
|
|
2017
|
+
scope: __scopeCheckbox,
|
|
2018
|
+
...context,
|
|
2019
|
+
children: isFunction$1(internal_do_not_use_render) ? internal_do_not_use_render(context) : children
|
|
2020
|
+
});
|
|
2021
|
+
}
|
|
2022
|
+
__name(CheckboxProvider, "CheckboxProvider");
|
|
2023
|
+
var TRIGGER_NAME = "CheckboxTrigger";
|
|
2024
|
+
var CheckboxTrigger = /* @__PURE__ */ import_react.forwardRef(/* @__PURE__ */ __name(function CheckboxTrigger2({ __scopeCheckbox, onKeyDown, onClick, ...checkboxProps }, forwardedRef) {
|
|
2025
|
+
const { control, value, disabled, checked, required, setControl, setChecked, onUserClick, isFormControl, bubbleInput } = useCheckboxContext(TRIGGER_NAME, __scopeCheckbox);
|
|
2026
|
+
const composedRefs = useComposedRefs(forwardedRef, setControl);
|
|
2027
|
+
const initialCheckedStateRef = import_react.useRef(checked);
|
|
2028
|
+
import_react.useEffect(() => {
|
|
2029
|
+
const form = control?.form;
|
|
2030
|
+
if (form) {
|
|
2031
|
+
const reset = /* @__PURE__ */ __name(() => setChecked(initialCheckedStateRef.current), "reset");
|
|
2032
|
+
form.addEventListener("reset", reset);
|
|
2033
|
+
return () => form.removeEventListener("reset", reset);
|
|
2034
|
+
}
|
|
2035
|
+
}, [control, setChecked]);
|
|
2036
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Primitive.button, {
|
|
2037
|
+
type: "button",
|
|
2038
|
+
role: "checkbox",
|
|
2039
|
+
"aria-checked": isIndeterminate(checked) ? "mixed" : checked,
|
|
2040
|
+
"aria-required": required,
|
|
2041
|
+
"data-state": getState(checked),
|
|
2042
|
+
"data-disabled": disabled ? "" : void 0,
|
|
2043
|
+
disabled,
|
|
2044
|
+
value,
|
|
2045
|
+
...checkboxProps,
|
|
2046
|
+
ref: composedRefs,
|
|
2047
|
+
onKeyDown: composeEventHandlers(onKeyDown, (event) => {
|
|
2048
|
+
if (event.key === "Enter") event.preventDefault();
|
|
2049
|
+
}),
|
|
2050
|
+
onClick: composeEventHandlers(onClick, (event) => {
|
|
2051
|
+
const hasConsumerStoppedPropagation = event.isPropagationStopped();
|
|
2052
|
+
onUserClick({
|
|
2053
|
+
requestedChecked: isIndeterminate(checked) ? true : !checked,
|
|
2054
|
+
hasConsumerStoppedPropagation
|
|
2055
|
+
});
|
|
2056
|
+
setChecked((prevChecked) => isIndeterminate(prevChecked) ? true : !prevChecked);
|
|
2057
|
+
if (bubbleInput && isFormControl) {
|
|
2058
|
+
if (!hasConsumerStoppedPropagation) event.stopPropagation();
|
|
2059
|
+
}
|
|
2060
|
+
})
|
|
2061
|
+
});
|
|
2062
|
+
}, "CheckboxTrigger"));
|
|
2063
|
+
var Checkbox$1 = /* @__PURE__ */ import_react.forwardRef(/* @__PURE__ */ __name(function Checkbox2(props, forwardedRef) {
|
|
2064
|
+
const { __scopeCheckbox, name, checked, defaultChecked, required, disabled, value, onCheckedChange, form, ...checkboxProps } = props;
|
|
2065
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CheckboxProvider, {
|
|
2066
|
+
__scopeCheckbox,
|
|
2067
|
+
checked,
|
|
2068
|
+
defaultChecked,
|
|
2069
|
+
disabled,
|
|
2070
|
+
required,
|
|
2071
|
+
onCheckedChange,
|
|
2072
|
+
name,
|
|
2073
|
+
form,
|
|
2074
|
+
value,
|
|
2075
|
+
internal_do_not_use_render: ({ isFormControl }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(CheckboxTrigger, {
|
|
2076
|
+
...checkboxProps,
|
|
2077
|
+
ref: forwardedRef,
|
|
2078
|
+
__scopeCheckbox
|
|
2079
|
+
}), isFormControl && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CheckboxBubbleInput, { __scopeCheckbox })] })
|
|
2080
|
+
});
|
|
2081
|
+
}, "Checkbox"));
|
|
2082
|
+
var INDICATOR_NAME = "CheckboxIndicator";
|
|
2083
|
+
var CheckboxIndicator = /* @__PURE__ */ import_react.forwardRef(/* @__PURE__ */ __name(function CheckboxIndicator2(props, forwardedRef) {
|
|
2084
|
+
const { __scopeCheckbox, forceMount, ...indicatorProps } = props;
|
|
2085
|
+
const context = useCheckboxContext(INDICATOR_NAME, __scopeCheckbox);
|
|
2086
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Presence, {
|
|
2087
|
+
present: forceMount || isIndeterminate(context.checked) || context.checked === true,
|
|
2088
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Primitive.span, {
|
|
2089
|
+
"data-state": getState(context.checked),
|
|
2090
|
+
"data-disabled": context.disabled ? "" : void 0,
|
|
2091
|
+
...indicatorProps,
|
|
2092
|
+
ref: forwardedRef,
|
|
2093
|
+
style: {
|
|
2094
|
+
pointerEvents: "none",
|
|
2095
|
+
...props.style
|
|
2096
|
+
}
|
|
2097
|
+
})
|
|
2098
|
+
});
|
|
2099
|
+
}, "CheckboxIndicator"));
|
|
2100
|
+
var BUBBLE_INPUT_NAME = "CheckboxBubbleInput";
|
|
2101
|
+
var CheckboxBubbleInput = /* @__PURE__ */ import_react.forwardRef(/* @__PURE__ */ __name(function CheckboxBubbleInput2({ __scopeCheckbox, onClick, ...props }, forwardedRef) {
|
|
2102
|
+
const { control, userClick, checked, defaultChecked, required, disabled, name, value, form, bubbleInput, setBubbleInput } = useCheckboxContext(BUBBLE_INPUT_NAME, __scopeCheckbox);
|
|
2103
|
+
const composedRefs = useComposedRefs(forwardedRef, setBubbleInput);
|
|
2104
|
+
const controlSize = useSize(control);
|
|
2105
|
+
const shouldStopClickPropagationRef = import_react.useRef(false);
|
|
2106
|
+
const prevCheckedRef = import_react.useRef(checked);
|
|
2107
|
+
const handledUserClickRef = import_react.useRef(userClick);
|
|
2108
|
+
const pendingUserClickRef = import_react.useRef(null);
|
|
2109
|
+
import_react.useEffect(() => {
|
|
2110
|
+
const input = bubbleInput;
|
|
2111
|
+
if (!input) return;
|
|
2112
|
+
const inputProto = window.HTMLInputElement.prototype;
|
|
2113
|
+
const setChecked = Object.getOwnPropertyDescriptor(inputProto, "checked").set;
|
|
2114
|
+
if (!setChecked) return;
|
|
2115
|
+
const checkedChanged = prevCheckedRef.current !== checked;
|
|
2116
|
+
prevCheckedRef.current = checked;
|
|
2117
|
+
const isNewUserClick = userClick !== null && userClick !== handledUserClickRef.current;
|
|
2118
|
+
handledUserClickRef.current = userClick;
|
|
2119
|
+
if (isNewUserClick) {
|
|
2120
|
+
pendingUserClickRef.current = checkedChanged ? null : userClick;
|
|
2121
|
+
if (checkedChanged) {
|
|
2122
|
+
input.indeterminate = isIndeterminate(checked);
|
|
2123
|
+
setChecked.call(input, isIndeterminate(checked) ? false : checked);
|
|
2124
|
+
}
|
|
2125
|
+
input.dispatchEvent(new Event("click", { bubbles: !userClick.hasConsumerStoppedPropagation }));
|
|
2126
|
+
} else if (checkedChanged) {
|
|
2127
|
+
const pendingUserClick = pendingUserClickRef.current;
|
|
2128
|
+
pendingUserClickRef.current = null;
|
|
2129
|
+
const isPendingUserChange = pendingUserClick?.requestedChecked === checked;
|
|
2130
|
+
shouldStopClickPropagationRef.current = true;
|
|
2131
|
+
input.indeterminate = isIndeterminate(checked);
|
|
2132
|
+
setChecked.call(input, isIndeterminate(checked) ? false : checked);
|
|
2133
|
+
input.dispatchEvent(new Event("click", { bubbles: !(isPendingUserChange && pendingUserClick.hasConsumerStoppedPropagation) }));
|
|
2134
|
+
shouldStopClickPropagationRef.current = false;
|
|
2135
|
+
}
|
|
2136
|
+
}, [
|
|
2137
|
+
bubbleInput,
|
|
2138
|
+
checked,
|
|
2139
|
+
userClick
|
|
2140
|
+
]);
|
|
2141
|
+
const defaultCheckedRef = import_react.useRef(isIndeterminate(checked) ? false : checked);
|
|
2142
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Primitive.input, {
|
|
2143
|
+
type: "checkbox",
|
|
2144
|
+
"aria-hidden": true,
|
|
2145
|
+
defaultChecked: defaultChecked ?? defaultCheckedRef.current,
|
|
2146
|
+
required,
|
|
2147
|
+
disabled,
|
|
2148
|
+
name,
|
|
2149
|
+
value,
|
|
2150
|
+
form,
|
|
2151
|
+
...props,
|
|
2152
|
+
tabIndex: -1,
|
|
2153
|
+
ref: composedRefs,
|
|
2154
|
+
onClick: composeEventHandlers(onClick, (event) => {
|
|
2155
|
+
if (shouldStopClickPropagationRef.current) event.stopPropagation();
|
|
2156
|
+
}),
|
|
2157
|
+
style: {
|
|
2158
|
+
...props.style,
|
|
2159
|
+
...controlSize,
|
|
2160
|
+
position: "absolute",
|
|
2161
|
+
pointerEvents: "none",
|
|
2162
|
+
opacity: 0,
|
|
2163
|
+
margin: 0,
|
|
2164
|
+
transform: "translateX(-100%)"
|
|
2165
|
+
}
|
|
2166
|
+
});
|
|
2167
|
+
}, "CheckboxBubbleInput"));
|
|
2168
|
+
function isFunction$1(value) {
|
|
2169
|
+
return typeof value === "function";
|
|
2170
|
+
}
|
|
2171
|
+
__name(isFunction$1, "isFunction");
|
|
2172
|
+
function isIndeterminate(checked) {
|
|
2173
|
+
return checked === "indeterminate";
|
|
2174
|
+
}
|
|
2175
|
+
__name(isIndeterminate, "isIndeterminate");
|
|
2176
|
+
function getState(checked) {
|
|
2177
|
+
return isIndeterminate(checked) ? "indeterminate" : checked ? "checked" : "unchecked";
|
|
2178
|
+
}
|
|
2179
|
+
__name(getState, "getState");
|
|
2180
|
+
// app/components/ui/checkbox.tsx
|
|
2181
|
+
var Checkbox = import_react.forwardRef(({ className, checked, indeterminate, onCheckedChange, ...props }, ref) => {
|
|
2182
|
+
const id = import_react.useId();
|
|
2183
|
+
const checkboxId = props.id ?? id;
|
|
2184
|
+
const checkedState = indeterminate ? "indeterminate" : checked ?? false;
|
|
2185
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", {
|
|
2186
|
+
htmlFor: checkboxId,
|
|
2187
|
+
className: "p-2 -m-2 inline-flex items-center justify-center cursor-pointer",
|
|
2188
|
+
onClick: (e) => e.stopPropagation(),
|
|
2189
|
+
onKeyDown: (e) => e.stopPropagation(),
|
|
2190
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Checkbox$1, {
|
|
2191
|
+
ref,
|
|
2192
|
+
id: checkboxId,
|
|
2193
|
+
checked: checkedState,
|
|
2194
|
+
onCheckedChange: (state) => {
|
|
2195
|
+
onCheckedChange?.(state === true);
|
|
2196
|
+
},
|
|
2197
|
+
className: cn("peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background", "disabled:cursor-not-allowed disabled:opacity-50", "data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground", "data-[state=indeterminate]:bg-primary data-[state=indeterminate]:text-primary-foreground", className),
|
|
2198
|
+
...props,
|
|
2199
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CheckboxIndicator, {
|
|
2200
|
+
className: "flex items-center justify-center text-current",
|
|
2201
|
+
children: indeterminate ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Minus, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Check, { className: "h-3.5 w-3.5" })
|
|
2202
|
+
})
|
|
2203
|
+
})
|
|
2204
|
+
});
|
|
2205
|
+
});
|
|
2206
|
+
Checkbox.displayName = "Checkbox";
|
|
2207
|
+
// ../../node_modules/.bun/use-sync-external-store@1.7.0+4bcfe187168658ad/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js
|
|
2208
|
+
/**
|
|
2209
|
+
* @license React
|
|
2210
|
+
* use-sync-external-store-shim.production.js
|
|
2211
|
+
*
|
|
2212
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2213
|
+
*
|
|
2214
|
+
* This source code is licensed under the MIT license found in the
|
|
2215
|
+
* LICENSE file in the root directory of this source tree.
|
|
2216
|
+
*/
|
|
2217
|
+
var require_use_sync_external_store_shim_production = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
2218
|
+
var React = require_react();
|
|
2219
|
+
function is(x, y) {
|
|
2220
|
+
return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
|
|
2221
|
+
}
|
|
2222
|
+
var objectIs = "function" === typeof Object.is ? Object.is : is;
|
|
2223
|
+
var useState = React.useState;
|
|
2224
|
+
var useEffect = React.useEffect;
|
|
2225
|
+
var useLayoutEffect = React.useLayoutEffect;
|
|
2226
|
+
var useDebugValue = React.useDebugValue;
|
|
2227
|
+
function useSyncExternalStore$2(subscribe, getSnapshot) {
|
|
2228
|
+
var value = getSnapshot(), _useState = useState({ inst: {
|
|
2229
|
+
value,
|
|
2230
|
+
getSnapshot
|
|
2231
|
+
} }), inst = _useState[0].inst, forceUpdate = _useState[1];
|
|
2232
|
+
useLayoutEffect(function() {
|
|
2233
|
+
inst.value = value;
|
|
2234
|
+
inst.getSnapshot = getSnapshot;
|
|
2235
|
+
checkIfSnapshotChanged(inst) && forceUpdate({ inst });
|
|
2236
|
+
}, [
|
|
2237
|
+
subscribe,
|
|
2238
|
+
value,
|
|
2239
|
+
getSnapshot
|
|
2240
|
+
]);
|
|
2241
|
+
useEffect(function() {
|
|
2242
|
+
checkIfSnapshotChanged(inst) && forceUpdate({ inst });
|
|
2243
|
+
return subscribe(function() {
|
|
2244
|
+
checkIfSnapshotChanged(inst) && forceUpdate({ inst });
|
|
2245
|
+
});
|
|
2246
|
+
}, [subscribe]);
|
|
2247
|
+
useDebugValue(value);
|
|
2248
|
+
return value;
|
|
2249
|
+
}
|
|
2250
|
+
function checkIfSnapshotChanged(inst) {
|
|
2251
|
+
var latestGetSnapshot = inst.getSnapshot;
|
|
2252
|
+
inst = inst.value;
|
|
2253
|
+
try {
|
|
2254
|
+
var nextValue = latestGetSnapshot();
|
|
2255
|
+
return !objectIs(inst, nextValue);
|
|
2256
|
+
} catch (error) {
|
|
2257
|
+
return !0;
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
function useSyncExternalStore$1(subscribe, getSnapshot) {
|
|
2261
|
+
return getSnapshot();
|
|
2262
|
+
}
|
|
2263
|
+
var shim = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? useSyncExternalStore$1 : useSyncExternalStore$2;
|
|
2264
|
+
exports.useSyncExternalStore = void 0 !== React.useSyncExternalStore ? React.useSyncExternalStore : shim;
|
|
2265
|
+
}));
|
|
2266
|
+
// ../../node_modules/.bun/dequal@2.0.3/node_modules/dequal/lite/index.mjs
|
|
2267
|
+
var import_shim = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2268
|
+
module.exports = require_use_sync_external_store_shim_production();
|
|
2269
|
+
})))();
|
|
2270
|
+
var has = Object.prototype.hasOwnProperty;
|
|
2271
|
+
function dequal(foo, bar) {
|
|
2272
|
+
var ctor, len;
|
|
2273
|
+
if (foo === bar) return true;
|
|
2274
|
+
if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
|
|
2275
|
+
if (ctor === Date) return foo.getTime() === bar.getTime();
|
|
2276
|
+
if (ctor === RegExp) return foo.toString() === bar.toString();
|
|
2277
|
+
if (ctor === Array) {
|
|
2278
|
+
if ((len = foo.length) === bar.length) while (len-- && dequal(foo[len], bar[len]));
|
|
2279
|
+
return len === -1;
|
|
2280
|
+
}
|
|
2281
|
+
if (!ctor || typeof foo === "object") {
|
|
2282
|
+
len = 0;
|
|
2283
|
+
for (ctor in foo) {
|
|
2284
|
+
if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
|
|
2285
|
+
if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false;
|
|
2286
|
+
}
|
|
2287
|
+
return Object.keys(bar).length === len;
|
|
2288
|
+
}
|
|
2289
|
+
}
|
|
2290
|
+
return foo !== foo && bar !== bar;
|
|
2291
|
+
}
|
|
2292
|
+
var SWRGlobalState = /* @__PURE__ */ new WeakMap();
|
|
2293
|
+
var noop = () => {};
|
|
2294
|
+
var OBJECT = Object;
|
|
2295
|
+
var isUndefined = (v) => v === void 0;
|
|
2296
|
+
var isFunction = (v) => typeof v == "function";
|
|
2297
|
+
var mergeObjects = (a, b) => ({
|
|
2298
|
+
...a,
|
|
2299
|
+
...b
|
|
2300
|
+
});
|
|
2301
|
+
var isPromiseLike = (x) => isFunction(x.then);
|
|
2302
|
+
var EMPTY_CACHE = {};
|
|
2303
|
+
var INITIAL_CACHE = {};
|
|
2304
|
+
var STR_UNDEFINED = "undefined";
|
|
2305
|
+
var isWindowDefined = typeof window != STR_UNDEFINED;
|
|
2306
|
+
var isDocumentDefined = typeof document != STR_UNDEFINED;
|
|
2307
|
+
var isLegacyDeno = isWindowDefined && "Deno" in window;
|
|
2308
|
+
var hasRequestAnimationFrame = () => isWindowDefined && typeof window["requestAnimationFrame"] != STR_UNDEFINED;
|
|
2309
|
+
var createCacheHelper = (cache, key) => {
|
|
2310
|
+
const state = SWRGlobalState.get(cache);
|
|
2311
|
+
return [
|
|
2312
|
+
() => !isUndefined(key) && cache.get(key) || EMPTY_CACHE,
|
|
2313
|
+
(info) => {
|
|
2314
|
+
if (!isUndefined(key)) {
|
|
2315
|
+
const prev = cache.get(key);
|
|
2316
|
+
if (!(key in INITIAL_CACHE)) INITIAL_CACHE[key] = prev;
|
|
2317
|
+
state[5](key, mergeObjects(prev, info), prev || EMPTY_CACHE);
|
|
2318
|
+
}
|
|
2319
|
+
},
|
|
2320
|
+
state[6],
|
|
2321
|
+
() => {
|
|
2322
|
+
if (!isUndefined(key)) {
|
|
2323
|
+
if (key in INITIAL_CACHE) return INITIAL_CACHE[key];
|
|
2324
|
+
}
|
|
2325
|
+
return !isUndefined(key) && cache.get(key) || EMPTY_CACHE;
|
|
2326
|
+
}
|
|
2327
|
+
];
|
|
2328
|
+
};
|
|
2329
|
+
/**
|
|
2330
|
+
* Due to the bug https://bugs.chromium.org/p/chromium/issues/detail?id=678075,
|
|
2331
|
+
* it's not reliable to detect if the browser is currently online or offline
|
|
2332
|
+
* based on `navigator.onLine`.
|
|
2333
|
+
* As a workaround, we always assume it's online on the first load, and change
|
|
2334
|
+
* the status upon `online` or `offline` events.
|
|
2335
|
+
*/ var online = true;
|
|
2336
|
+
var isOnline = () => online;
|
|
2337
|
+
var [onWindowEvent, offWindowEvent] = isWindowDefined && window.addEventListener ? [window.addEventListener.bind(window), window.removeEventListener.bind(window)] : [noop, noop];
|
|
2338
|
+
var isVisible = () => {
|
|
2339
|
+
const visibilityState = isDocumentDefined && document.visibilityState;
|
|
2340
|
+
return isUndefined(visibilityState) || visibilityState !== "hidden";
|
|
2341
|
+
};
|
|
2342
|
+
var initFocus = (callback) => {
|
|
2343
|
+
if (isDocumentDefined) document.addEventListener("visibilitychange", callback);
|
|
2344
|
+
onWindowEvent("focus", callback);
|
|
2345
|
+
return () => {
|
|
2346
|
+
if (isDocumentDefined) document.removeEventListener("visibilitychange", callback);
|
|
2347
|
+
offWindowEvent("focus", callback);
|
|
2348
|
+
};
|
|
2349
|
+
};
|
|
2350
|
+
var initReconnect = (callback) => {
|
|
2351
|
+
const onOnline = () => {
|
|
2352
|
+
online = true;
|
|
2353
|
+
callback();
|
|
2354
|
+
};
|
|
2355
|
+
const onOffline = () => {
|
|
2356
|
+
online = false;
|
|
2357
|
+
};
|
|
2358
|
+
onWindowEvent("online", onOnline);
|
|
2359
|
+
onWindowEvent("offline", onOffline);
|
|
2360
|
+
return () => {
|
|
2361
|
+
offWindowEvent("online", onOnline);
|
|
2362
|
+
offWindowEvent("offline", onOffline);
|
|
2363
|
+
};
|
|
2364
|
+
};
|
|
2365
|
+
var preset = {
|
|
2366
|
+
isOnline,
|
|
2367
|
+
isVisible
|
|
2368
|
+
};
|
|
2369
|
+
var defaultConfigOptions = {
|
|
2370
|
+
initFocus,
|
|
2371
|
+
initReconnect
|
|
2372
|
+
};
|
|
2373
|
+
var IS_REACT_LEGACY = !import_react.useId;
|
|
2374
|
+
var IS_SERVER = !isWindowDefined || isLegacyDeno;
|
|
2375
|
+
var rAF = (f) => hasRequestAnimationFrame() ? window["requestAnimationFrame"](f) : setTimeout(f, 1);
|
|
2376
|
+
var useIsomorphicLayoutEffect = IS_SERVER ? import_react.useEffect : import_react.useLayoutEffect;
|
|
2377
|
+
var navigatorConnection = typeof navigator !== "undefined" && navigator.connection;
|
|
2378
|
+
var slowConnection = !IS_SERVER && navigatorConnection && (["slow-2g", "2g"].includes(navigatorConnection.effectiveType) || navigatorConnection.saveData);
|
|
2379
|
+
var table = /* @__PURE__ */ new WeakMap();
|
|
2380
|
+
var getTypeName = (value) => OBJECT.prototype.toString.call(value);
|
|
2381
|
+
var isObjectTypeName = (typeName, type) => typeName === `[object ${type}]`;
|
|
2382
|
+
var counter = 0;
|
|
2383
|
+
var stableHash = (arg) => {
|
|
2384
|
+
const type = typeof arg;
|
|
2385
|
+
const typeName = getTypeName(arg);
|
|
2386
|
+
const isDate = isObjectTypeName(typeName, "Date");
|
|
2387
|
+
const isRegex = isObjectTypeName(typeName, "RegExp");
|
|
2388
|
+
const isPlainObject = isObjectTypeName(typeName, "Object");
|
|
2389
|
+
let result;
|
|
2390
|
+
let index;
|
|
2391
|
+
if (OBJECT(arg) === arg && !isDate && !isRegex) {
|
|
2392
|
+
result = table.get(arg);
|
|
2393
|
+
if (result) return result;
|
|
2394
|
+
result = ++counter + "~";
|
|
2395
|
+
table.set(arg, result);
|
|
2396
|
+
if (Array.isArray(arg)) {
|
|
2397
|
+
result = "@";
|
|
2398
|
+
for (index = 0; index < arg.length; index++) result += stableHash(arg[index]) + ",";
|
|
2399
|
+
table.set(arg, result);
|
|
2400
|
+
}
|
|
2401
|
+
if (isPlainObject) {
|
|
2402
|
+
result = "#";
|
|
2403
|
+
const keys = OBJECT.keys(arg).sort();
|
|
2404
|
+
while (!isUndefined(index = keys.pop())) if (!isUndefined(arg[index])) result += index + ":" + stableHash(arg[index]) + ",";
|
|
2405
|
+
table.set(arg, result);
|
|
2406
|
+
}
|
|
2407
|
+
} else result = isDate ? arg.toJSON() : type == "symbol" ? arg.toString() : type == "string" ? JSON.stringify(arg) : "" + arg;
|
|
2408
|
+
return result;
|
|
2409
|
+
};
|
|
2410
|
+
var serialize = (key) => {
|
|
2411
|
+
if (isFunction(key)) try {
|
|
2412
|
+
key = key();
|
|
2413
|
+
} catch (err) {
|
|
2414
|
+
key = "";
|
|
2415
|
+
}
|
|
2416
|
+
const args = key;
|
|
2417
|
+
key = typeof key == "string" ? key : (Array.isArray(key) ? key.length : key) ? stableHash(key) : "";
|
|
2418
|
+
return [key, args];
|
|
2419
|
+
};
|
|
2420
|
+
var __timestamp = 0;
|
|
2421
|
+
var getTimestamp = () => ++__timestamp;
|
|
2422
|
+
async function internalMutate(...args) {
|
|
2423
|
+
const [cache, _key, _data, _opts] = args;
|
|
2424
|
+
const options = mergeObjects({
|
|
2425
|
+
populateCache: true,
|
|
2426
|
+
throwOnError: true
|
|
2427
|
+
}, typeof _opts === "boolean" ? { revalidate: _opts } : _opts || {});
|
|
2428
|
+
let populateCache = options.populateCache;
|
|
2429
|
+
const rollbackOnErrorOption = options.rollbackOnError;
|
|
2430
|
+
let optimisticData = options.optimisticData;
|
|
2431
|
+
const rollbackOnError = (error) => {
|
|
2432
|
+
return typeof rollbackOnErrorOption === "function" ? rollbackOnErrorOption(error) : rollbackOnErrorOption !== false;
|
|
2433
|
+
};
|
|
2434
|
+
const throwOnError = options.throwOnError;
|
|
2435
|
+
if (isFunction(_key)) {
|
|
2436
|
+
const keyFilter = _key;
|
|
2437
|
+
const matchedKeys = [];
|
|
2438
|
+
const it = cache.keys();
|
|
2439
|
+
for (const key of it) if (!/^\$(inf|sub)\$/.test(key) && keyFilter(cache.get(key)._k)) matchedKeys.push(key);
|
|
2440
|
+
return Promise.all(matchedKeys.map(mutateByKey));
|
|
2441
|
+
}
|
|
2442
|
+
return mutateByKey(_key);
|
|
2443
|
+
async function mutateByKey(_k) {
|
|
2444
|
+
const [key] = serialize(_k);
|
|
2445
|
+
if (!key) return;
|
|
2446
|
+
const [get, set] = createCacheHelper(cache, key);
|
|
2447
|
+
const [EVENT_REVALIDATORS, MUTATION, FETCH, PRELOAD] = SWRGlobalState.get(cache);
|
|
2448
|
+
const startRevalidate = () => {
|
|
2449
|
+
const revalidators = EVENT_REVALIDATORS[key];
|
|
2450
|
+
if (isFunction(options.revalidate) ? options.revalidate(get().data, _k) : options.revalidate !== false) {
|
|
2451
|
+
delete FETCH[key];
|
|
2452
|
+
delete PRELOAD[key];
|
|
2453
|
+
if (revalidators && revalidators[0]) return revalidators[0](2).then(() => get().data);
|
|
2454
|
+
}
|
|
2455
|
+
return get().data;
|
|
2456
|
+
};
|
|
2457
|
+
if (args.length < 3) return startRevalidate();
|
|
2458
|
+
let data = _data;
|
|
2459
|
+
let error;
|
|
2460
|
+
let isError = false;
|
|
2461
|
+
const beforeMutationTs = getTimestamp();
|
|
2462
|
+
MUTATION[key] = [beforeMutationTs, 0];
|
|
2463
|
+
const hasOptimisticData = !isUndefined(optimisticData);
|
|
2464
|
+
const state = get();
|
|
2465
|
+
const displayedData = state.data;
|
|
2466
|
+
const currentData = state._c;
|
|
2467
|
+
const committedData = isUndefined(currentData) ? displayedData : currentData;
|
|
2468
|
+
if (hasOptimisticData) {
|
|
2469
|
+
optimisticData = isFunction(optimisticData) ? optimisticData(committedData, displayedData) : optimisticData;
|
|
2470
|
+
set({
|
|
2471
|
+
data: optimisticData,
|
|
2472
|
+
_c: committedData
|
|
2473
|
+
});
|
|
2474
|
+
}
|
|
2475
|
+
if (isFunction(data)) try {
|
|
2476
|
+
data = data(committedData);
|
|
2477
|
+
} catch (err) {
|
|
2478
|
+
error = err;
|
|
2479
|
+
isError = true;
|
|
2480
|
+
}
|
|
2481
|
+
if (data && isPromiseLike(data)) {
|
|
2482
|
+
data = await data.catch((err) => {
|
|
2483
|
+
error = err;
|
|
2484
|
+
isError = true;
|
|
2485
|
+
});
|
|
2486
|
+
if (beforeMutationTs !== MUTATION[key][0]) {
|
|
2487
|
+
if (isError) throw error;
|
|
2488
|
+
return data;
|
|
2489
|
+
} else if (isError && hasOptimisticData && rollbackOnError(error)) {
|
|
2490
|
+
populateCache = true;
|
|
2491
|
+
set({
|
|
2492
|
+
data: committedData,
|
|
2493
|
+
_c: void 0
|
|
2494
|
+
});
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
if (populateCache) {
|
|
2498
|
+
if (!isError) {
|
|
2499
|
+
if (isFunction(populateCache)) set({
|
|
2500
|
+
data: populateCache(data, committedData),
|
|
2501
|
+
error: void 0,
|
|
2502
|
+
_c: void 0
|
|
2503
|
+
});
|
|
2504
|
+
else set({
|
|
2505
|
+
data,
|
|
2506
|
+
error: void 0,
|
|
2507
|
+
_c: void 0
|
|
2508
|
+
});
|
|
2509
|
+
}
|
|
2510
|
+
}
|
|
2511
|
+
MUTATION[key][1] = getTimestamp();
|
|
2512
|
+
Promise.resolve(startRevalidate()).then(() => {
|
|
2513
|
+
set({ _c: void 0 });
|
|
2514
|
+
});
|
|
2515
|
+
if (isError) {
|
|
2516
|
+
if (throwOnError) throw error;
|
|
2517
|
+
return;
|
|
2518
|
+
}
|
|
2519
|
+
return data;
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
var revalidateAllKeys = (revalidators, type) => {
|
|
2523
|
+
for (const key in revalidators) if (revalidators[key][0]) revalidators[key][0](type);
|
|
2524
|
+
};
|
|
2525
|
+
var initCache = (provider, options) => {
|
|
2526
|
+
if (!SWRGlobalState.has(provider)) {
|
|
2527
|
+
const opts = mergeObjects(defaultConfigOptions, options);
|
|
2528
|
+
const EVENT_REVALIDATORS = Object.create(null);
|
|
2529
|
+
const mutate = internalMutate.bind(void 0, provider);
|
|
2530
|
+
let unmount = noop;
|
|
2531
|
+
const subscriptions = Object.create(null);
|
|
2532
|
+
const subscribe = (key, callback) => {
|
|
2533
|
+
const subs = subscriptions[key] || [];
|
|
2534
|
+
subscriptions[key] = subs;
|
|
2535
|
+
subs.push(callback);
|
|
2536
|
+
return () => {
|
|
2537
|
+
const index = subs.indexOf(callback);
|
|
2538
|
+
if (index >= 0) {
|
|
2539
|
+
subs[index] = subs[subs.length - 1];
|
|
2540
|
+
subs.pop();
|
|
2541
|
+
}
|
|
2542
|
+
};
|
|
2543
|
+
};
|
|
2544
|
+
const setter = (key, value, prev) => {
|
|
2545
|
+
provider.set(key, value);
|
|
2546
|
+
const subs = subscriptions[key];
|
|
2547
|
+
if (subs) for (const fn of subs) fn(value, prev);
|
|
2548
|
+
};
|
|
2549
|
+
const unload = (unloadOptions) => {
|
|
2550
|
+
const state = SWRGlobalState.get(provider);
|
|
2551
|
+
const [, MUTATION, FETCH, PRELOAD] = state;
|
|
2552
|
+
const ts = getTimestamp();
|
|
2553
|
+
state[8]++;
|
|
2554
|
+
for (const key in FETCH) delete FETCH[key];
|
|
2555
|
+
for (const key in PRELOAD) delete PRELOAD[key];
|
|
2556
|
+
for (const key in MUTATION) MUTATION[key] = [ts, ts];
|
|
2557
|
+
const emptyState = {};
|
|
2558
|
+
for (const key of [...provider.keys()]) {
|
|
2559
|
+
const prev = provider.get(key);
|
|
2560
|
+
provider.delete(key);
|
|
2561
|
+
const subs = subscriptions[key];
|
|
2562
|
+
if (subs) for (const fn of subs) fn(emptyState, prev);
|
|
2563
|
+
}
|
|
2564
|
+
const revalidate = !unloadOptions || unloadOptions.revalidate !== false;
|
|
2565
|
+
for (const key in EVENT_REVALIDATORS) {
|
|
2566
|
+
const revalidators = EVENT_REVALIDATORS[key];
|
|
2567
|
+
for (let i = 0; i < revalidators.length; i++) revalidators[i](4, { revalidate: revalidate && !i });
|
|
2568
|
+
}
|
|
2569
|
+
};
|
|
2570
|
+
const initProvider = () => {
|
|
2571
|
+
if (!SWRGlobalState.has(provider)) {
|
|
2572
|
+
SWRGlobalState.set(provider, [
|
|
2573
|
+
EVENT_REVALIDATORS,
|
|
2574
|
+
Object.create(null),
|
|
2575
|
+
Object.create(null),
|
|
2576
|
+
Object.create(null),
|
|
2577
|
+
mutate,
|
|
2578
|
+
setter,
|
|
2579
|
+
subscribe,
|
|
2580
|
+
unload,
|
|
2581
|
+
0
|
|
2582
|
+
]);
|
|
2583
|
+
if (!IS_SERVER) {
|
|
2584
|
+
const releaseFocus = opts.initFocus(setTimeout.bind(void 0, revalidateAllKeys.bind(void 0, EVENT_REVALIDATORS, 0)));
|
|
2585
|
+
const releaseReconnect = opts.initReconnect(setTimeout.bind(void 0, revalidateAllKeys.bind(void 0, EVENT_REVALIDATORS, 1)));
|
|
2586
|
+
unmount = () => {
|
|
2587
|
+
releaseFocus && releaseFocus();
|
|
2588
|
+
releaseReconnect && releaseReconnect();
|
|
2589
|
+
SWRGlobalState.delete(provider);
|
|
2590
|
+
};
|
|
2591
|
+
}
|
|
2592
|
+
}
|
|
2593
|
+
};
|
|
2594
|
+
initProvider();
|
|
2595
|
+
return [
|
|
2596
|
+
provider,
|
|
2597
|
+
mutate,
|
|
2598
|
+
initProvider,
|
|
2599
|
+
unmount,
|
|
2600
|
+
unload
|
|
2601
|
+
];
|
|
2602
|
+
}
|
|
2603
|
+
const state = SWRGlobalState.get(provider);
|
|
2604
|
+
return [
|
|
2605
|
+
provider,
|
|
2606
|
+
state[4],
|
|
2607
|
+
void 0,
|
|
2608
|
+
void 0,
|
|
2609
|
+
state[7]
|
|
2610
|
+
];
|
|
2611
|
+
};
|
|
2612
|
+
var onErrorRetry = (_, __, config, revalidate, opts) => {
|
|
2613
|
+
const maxRetryCount = config.errorRetryCount;
|
|
2614
|
+
const currentRetryCount = opts.retryCount;
|
|
2615
|
+
const timeout = ~~((Math.random() + .5) * (1 << (currentRetryCount < 8 ? currentRetryCount : 8))) * config.errorRetryInterval;
|
|
2616
|
+
if (!isUndefined(maxRetryCount) && currentRetryCount > maxRetryCount) return;
|
|
2617
|
+
setTimeout(revalidate, timeout, opts);
|
|
2618
|
+
};
|
|
2619
|
+
var compare = dequal;
|
|
2620
|
+
var [cache, mutate, , , unload] = initCache(/* @__PURE__ */ new Map());
|
|
2621
|
+
var defaultConfig = mergeObjects({
|
|
2622
|
+
onLoadingSlow: noop,
|
|
2623
|
+
onSuccess: noop,
|
|
2624
|
+
onError: noop,
|
|
2625
|
+
onErrorRetry,
|
|
2626
|
+
onDiscarded: noop,
|
|
2627
|
+
revalidateOnFocus: true,
|
|
2628
|
+
revalidateOnReconnect: true,
|
|
2629
|
+
revalidateIfStale: true,
|
|
2630
|
+
shouldRetryOnError: true,
|
|
2631
|
+
errorRetryInterval: slowConnection ? 1e4 : 5e3,
|
|
2632
|
+
focusThrottleInterval: 5e3,
|
|
2633
|
+
dedupingInterval: 2e3,
|
|
2634
|
+
loadingTimeout: slowConnection ? 5e3 : 3e3,
|
|
2635
|
+
compare,
|
|
2636
|
+
isPaused: () => false,
|
|
2637
|
+
cache,
|
|
2638
|
+
mutate,
|
|
2639
|
+
unload,
|
|
2640
|
+
fallback: {}
|
|
2641
|
+
}, preset);
|
|
2642
|
+
var mergeConfigs = (a, b) => {
|
|
2643
|
+
const v = mergeObjects(a, b);
|
|
2644
|
+
if (b) {
|
|
2645
|
+
const { use: u1, fallback: f1, cacheData: c1 } = a;
|
|
2646
|
+
const { use: u2, fallback: f2, cacheData: c2 } = b;
|
|
2647
|
+
if (u1 && u2) v.use = u1.concat(u2);
|
|
2648
|
+
if (f1 && f2) v.fallback = mergeObjects(f1, f2);
|
|
2649
|
+
if (c1 && c2) v.cacheData = mergeObjects(c1, c2);
|
|
2650
|
+
}
|
|
2651
|
+
return v;
|
|
2652
|
+
};
|
|
2653
|
+
var SWRConfigContext = (0, import_react.createContext)({});
|
|
2654
|
+
var SWRConfig$1 = (props) => {
|
|
2655
|
+
const { value } = props;
|
|
2656
|
+
const parentConfig = (0, import_react.useContext)(SWRConfigContext);
|
|
2657
|
+
const isFunctionalConfig = isFunction(value);
|
|
2658
|
+
const config = (0, import_react.useMemo)(() => isFunctionalConfig ? value(parentConfig) : value, [
|
|
2659
|
+
isFunctionalConfig,
|
|
2660
|
+
parentConfig,
|
|
2661
|
+
value
|
|
2662
|
+
]);
|
|
2663
|
+
const extendedConfig = (0, import_react.useMemo)(() => isFunctionalConfig ? config : mergeConfigs(parentConfig, config), [
|
|
2664
|
+
isFunctionalConfig,
|
|
2665
|
+
parentConfig,
|
|
2666
|
+
config
|
|
2667
|
+
]);
|
|
2668
|
+
const provider = config && config.provider;
|
|
2669
|
+
const cacheContextRef = (0, import_react.useRef)(void 0);
|
|
2670
|
+
if (provider && !cacheContextRef.current) cacheContextRef.current = initCache(provider(extendedConfig.cache || cache), config);
|
|
2671
|
+
const cacheContext = cacheContextRef.current;
|
|
2672
|
+
if (cacheContext) {
|
|
2673
|
+
extendedConfig.cache = cacheContext[0];
|
|
2674
|
+
extendedConfig.mutate = cacheContext[1];
|
|
2675
|
+
extendedConfig.unload = cacheContext[4];
|
|
2676
|
+
}
|
|
2677
|
+
useIsomorphicLayoutEffect(() => {
|
|
2678
|
+
if (cacheContext) {
|
|
2679
|
+
cacheContext[2] && cacheContext[2]();
|
|
2680
|
+
return cacheContext[3];
|
|
2681
|
+
}
|
|
2682
|
+
}, []);
|
|
2683
|
+
return (0, import_react.createElement)(SWRConfigContext.Provider, mergeObjects(props, { value: extendedConfig }));
|
|
2684
|
+
};
|
|
2685
|
+
// ../../node_modules/.bun/swr@2.5.1+4bcfe187168658ad/node_modules/swr/dist/_internal/constants.mjs
|
|
2686
|
+
var INFINITE_PREFIX = "$inf$";
|
|
2687
|
+
// ../../node_modules/.bun/swr@2.5.1+4bcfe187168658ad/node_modules/swr/dist/_internal/index.mjs
|
|
2688
|
+
var enableDevtools = isWindowDefined && window.__SWR_DEVTOOLS_USE__;
|
|
2689
|
+
var use$1 = enableDevtools ? window.__SWR_DEVTOOLS_USE__ : [];
|
|
2690
|
+
var setupDevTools = () => {
|
|
2691
|
+
if (enableDevtools) window.__SWR_DEVTOOLS_REACT__ = import_react.default;
|
|
2692
|
+
};
|
|
2693
|
+
var normalize = (args) => {
|
|
2694
|
+
return isFunction(args[1]) ? [
|
|
2695
|
+
args[0],
|
|
2696
|
+
args[1],
|
|
2697
|
+
args[2] || {}
|
|
2698
|
+
] : [
|
|
2699
|
+
args[0],
|
|
2700
|
+
null,
|
|
2701
|
+
(args[1] === null ? args[2] : args[1]) || {}
|
|
2702
|
+
];
|
|
2703
|
+
};
|
|
2704
|
+
var useSWRConfig = () => {
|
|
2705
|
+
const parentConfig = (0, import_react.useContext)(SWRConfigContext);
|
|
2706
|
+
return (0, import_react.useMemo)(() => mergeObjects(defaultConfig, parentConfig), [parentConfig]);
|
|
2707
|
+
};
|
|
2708
|
+
var middleware = (useSWRNext) => (key_, fetcher_, config) => {
|
|
2709
|
+
return useSWRNext(key_, fetcher_ && ((...args) => {
|
|
2710
|
+
const [key] = serialize(key_);
|
|
2711
|
+
const [, , , PRELOAD] = SWRGlobalState.get(cache);
|
|
2712
|
+
if (key.startsWith("$inf$")) return fetcher_(...args);
|
|
2713
|
+
const req = PRELOAD[key];
|
|
2714
|
+
if (isUndefined(req)) return fetcher_(...args);
|
|
2715
|
+
delete PRELOAD[key];
|
|
2716
|
+
return req;
|
|
2717
|
+
}), config);
|
|
2718
|
+
};
|
|
2719
|
+
var BUILT_IN_MIDDLEWARE = use$1.concat(middleware);
|
|
2720
|
+
var withArgs = (hook) => {
|
|
2721
|
+
return function useSWRArgs(...args) {
|
|
2722
|
+
const fallbackConfig = useSWRConfig();
|
|
2723
|
+
const [key, fn, _config] = normalize(args);
|
|
2724
|
+
const config = mergeConfigs(fallbackConfig, _config);
|
|
2725
|
+
let next = hook;
|
|
2726
|
+
const { use } = config;
|
|
2727
|
+
const middleware = (use || []).concat(BUILT_IN_MIDDLEWARE);
|
|
2728
|
+
for (let i = middleware.length; i--;) next = middleware[i](next);
|
|
2729
|
+
return next(key, fn || config.fetcher || null, config);
|
|
2730
|
+
};
|
|
2731
|
+
};
|
|
2732
|
+
var subscribeCallback = (key, callbacks, callback) => {
|
|
2733
|
+
const keyedRevalidators = callbacks[key] || (callbacks[key] = []);
|
|
2734
|
+
keyedRevalidators.push(callback);
|
|
2735
|
+
return () => {
|
|
2736
|
+
const index = keyedRevalidators.indexOf(callback);
|
|
2737
|
+
if (index >= 0) {
|
|
2738
|
+
keyedRevalidators[index] = keyedRevalidators[keyedRevalidators.length - 1];
|
|
2739
|
+
keyedRevalidators.pop();
|
|
2740
|
+
}
|
|
2741
|
+
};
|
|
2742
|
+
};
|
|
2743
|
+
var withMiddleware = (useSWR, middleware) => {
|
|
2744
|
+
return (...args) => {
|
|
2745
|
+
const [key, fn, config] = normalize(args);
|
|
2746
|
+
const uses = (config.use || []).concat(middleware);
|
|
2747
|
+
return useSWR(key, fn, {
|
|
2748
|
+
...config,
|
|
2749
|
+
use: uses
|
|
2750
|
+
});
|
|
2751
|
+
};
|
|
2752
|
+
};
|
|
2753
|
+
setupDevTools();
|
|
2754
|
+
// ../../node_modules/.bun/swr@2.5.1+4bcfe187168658ad/node_modules/swr/dist/use-swr-emll9s78.mjs
|
|
2755
|
+
var use = import_react.use || ((thenable) => {
|
|
2756
|
+
switch (thenable.status) {
|
|
2757
|
+
case "pending": throw thenable;
|
|
2758
|
+
case "fulfilled": return thenable.value;
|
|
2759
|
+
case "rejected": throw thenable.reason;
|
|
2760
|
+
default:
|
|
2761
|
+
thenable.status = "pending";
|
|
2762
|
+
thenable.then((v) => {
|
|
2763
|
+
thenable.status = "fulfilled";
|
|
2764
|
+
thenable.value = v;
|
|
2765
|
+
}, (e) => {
|
|
2766
|
+
thenable.status = "rejected";
|
|
2767
|
+
thenable.reason = e;
|
|
2768
|
+
});
|
|
2769
|
+
throw thenable;
|
|
2770
|
+
}
|
|
2771
|
+
});
|
|
2772
|
+
var WITH_DEDUPE = { dedupe: true };
|
|
2773
|
+
var isCacheDataConsumed = (consumedCacheData, cacheData, key) => {
|
|
2774
|
+
var _consumedCacheData_get;
|
|
2775
|
+
return cacheData ? ((_consumedCacheData_get = consumedCacheData.get(cacheData)) == null ? void 0 : _consumedCacheData_get.has(key)) === true : false;
|
|
2776
|
+
};
|
|
2777
|
+
var markCacheDataConsumed = (consumedCacheData, cacheData, key) => {
|
|
2778
|
+
if (!cacheData) return;
|
|
2779
|
+
let consumedKeys = consumedCacheData.get(cacheData);
|
|
2780
|
+
if (!consumedKeys) {
|
|
2781
|
+
consumedKeys = /* @__PURE__ */ new Set();
|
|
2782
|
+
consumedCacheData.set(cacheData, consumedKeys);
|
|
2783
|
+
}
|
|
2784
|
+
consumedKeys.add(key);
|
|
2785
|
+
};
|
|
2786
|
+
var commitCacheData = ({ value, getCacheData, canCommit, setCache }) => {
|
|
2787
|
+
const commit = (state) => {
|
|
2788
|
+
if (canCommit() && isUndefined(getCacheData())) setCache(state);
|
|
2789
|
+
};
|
|
2790
|
+
Promise.resolve(value).then((data) => {
|
|
2791
|
+
commit({
|
|
2792
|
+
data,
|
|
2793
|
+
error: void 0
|
|
2794
|
+
});
|
|
2795
|
+
}, (error) => {
|
|
2796
|
+
commit({ error });
|
|
2797
|
+
});
|
|
2798
|
+
};
|
|
2799
|
+
var resolvedUndef = Promise.resolve(void 0);
|
|
2800
|
+
resolvedUndef.status = "fulfilled";
|
|
2801
|
+
resolvedUndef.value = void 0;
|
|
2802
|
+
var sub = () => noop;
|
|
2803
|
+
/**
|
|
2804
|
+
* The core implementation of the useSWR hook.
|
|
2805
|
+
*
|
|
2806
|
+
* This is the main handler function that implements all SWR functionality including
|
|
2807
|
+
* data fetching, caching, revalidation, error handling, and state management.
|
|
2808
|
+
* It manages the complete lifecycle of SWR requests from initialization through
|
|
2809
|
+
* cleanup.
|
|
2810
|
+
*
|
|
2811
|
+
* Key responsibilities:
|
|
2812
|
+
* - Key serialization and normalization
|
|
2813
|
+
* - Cache state management and synchronization
|
|
2814
|
+
* - Automatic and manual revalidation
|
|
2815
|
+
* - Error handling and retry logic
|
|
2816
|
+
* - Suspense integration
|
|
2817
|
+
* - Loading state management
|
|
2818
|
+
* - Effect cleanup and memory management
|
|
2819
|
+
*
|
|
2820
|
+
* @template Data - The type of data returned by the fetcher
|
|
2821
|
+
* @template Error - The type of error that can be thrown
|
|
2822
|
+
*
|
|
2823
|
+
* @param _key - The SWR key (string, array, object, function, or falsy)
|
|
2824
|
+
* @param fetcher - The fetcher function to retrieve data, or null to disable fetching
|
|
2825
|
+
* @param config - Complete SWR configuration object with both public and internal options
|
|
2826
|
+
*
|
|
2827
|
+
* @returns SWRResponse object containing data, error, mutate function, and loading states
|
|
2828
|
+
*
|
|
2829
|
+
* @internal This is the internal implementation. Use `useSWR` instead.
|
|
2830
|
+
*/ var useSWRHandler = (_key, fetcher, config) => {
|
|
2831
|
+
const { cache, compare, suspense, fallbackData, revalidateOnMount, revalidateIfStale, refreshInterval, refreshWhenHidden, refreshWhenOffline, keepPreviousData, strictServerPrefetchWarning } = config;
|
|
2832
|
+
const [EVENT_REVALIDATORS, MUTATION, FETCH, PRELOAD] = SWRGlobalState.get(cache);
|
|
2833
|
+
const [key, fnArg] = serialize(_key);
|
|
2834
|
+
const initialMountedRef = (0, import_react.useRef)(false);
|
|
2835
|
+
const unmountedRef = (0, import_react.useRef)(false);
|
|
2836
|
+
const keyRef = (0, import_react.useRef)(key);
|
|
2837
|
+
const fetcherRef = (0, import_react.useRef)(fetcher);
|
|
2838
|
+
const configRef = (0, import_react.useRef)(config);
|
|
2839
|
+
const getConfig = () => configRef.current;
|
|
2840
|
+
const isActive = () => getConfig().isVisible() && getConfig().isOnline();
|
|
2841
|
+
const [getCache, setCache, subscribeCache, getInitialCache] = createCacheHelper(cache, key);
|
|
2842
|
+
const stateDependencies = (0, import_react.useRef)({}).current;
|
|
2843
|
+
const fallback = isUndefined(fallbackData) ? isUndefined(config.fallback) ? void 0 : config.fallback[key] : fallbackData;
|
|
2844
|
+
const serverCacheData = config.cacheData;
|
|
2845
|
+
const configCacheData = !key ? void 0 : serverCacheData == null ? void 0 : serverCacheData[key];
|
|
2846
|
+
const req = key ? PRELOAD[key] : void 0;
|
|
2847
|
+
const hasCacheData = isUndefined(req) && !isUndefined(configCacheData);
|
|
2848
|
+
const preloadedData = hasCacheData ? configCacheData : req;
|
|
2849
|
+
const isEqual = (prev, current) => {
|
|
2850
|
+
for (const _ in stateDependencies) {
|
|
2851
|
+
const t = _;
|
|
2852
|
+
if (t === "data") {
|
|
2853
|
+
if (!compare(prev[t], current[t])) {
|
|
2854
|
+
if (!isUndefined(prev[t])) return false;
|
|
2855
|
+
if (!compare(returnedData, current[t])) return false;
|
|
2856
|
+
}
|
|
2857
|
+
} else if (current[t] !== prev[t]) return false;
|
|
2858
|
+
}
|
|
2859
|
+
return true;
|
|
2860
|
+
};
|
|
2861
|
+
const isInitialMount = !initialMountedRef.current;
|
|
2862
|
+
const getSnapshot = (0, import_react.useMemo)(() => {
|
|
2863
|
+
const cachedData = getCache();
|
|
2864
|
+
const initialData = getInitialCache();
|
|
2865
|
+
const getSelectedCache = (state) => {
|
|
2866
|
+
const snapshot = mergeObjects(state);
|
|
2867
|
+
delete snapshot._k;
|
|
2868
|
+
if (!(() => {
|
|
2869
|
+
if (!key) return false;
|
|
2870
|
+
if (!fetcher) return false;
|
|
2871
|
+
if (getConfig().isPaused()) return false;
|
|
2872
|
+
if (isInitialMount && !isUndefined(revalidateOnMount)) return revalidateOnMount;
|
|
2873
|
+
const data = !isUndefined(fallback) ? fallback : snapshot.data;
|
|
2874
|
+
if (suspense && hasCacheData && isUndefined(data)) return false;
|
|
2875
|
+
if (suspense) return isUndefined(data) || revalidateIfStale;
|
|
2876
|
+
return isUndefined(data) || revalidateIfStale;
|
|
2877
|
+
})()) return snapshot;
|
|
2878
|
+
return {
|
|
2879
|
+
isValidating: true,
|
|
2880
|
+
isLoading: true,
|
|
2881
|
+
...snapshot
|
|
2882
|
+
};
|
|
2883
|
+
};
|
|
2884
|
+
const clientSnapshot = getSelectedCache(cachedData);
|
|
2885
|
+
const serverSnapshot = cachedData === initialData ? clientSnapshot : getSelectedCache(initialData);
|
|
2886
|
+
let memorizedSnapshot = clientSnapshot;
|
|
2887
|
+
return [() => {
|
|
2888
|
+
const newSnapshot = getSelectedCache(getCache());
|
|
2889
|
+
if (isEqual(newSnapshot, memorizedSnapshot)) {
|
|
2890
|
+
memorizedSnapshot.data = newSnapshot.data;
|
|
2891
|
+
memorizedSnapshot.isLoading = newSnapshot.isLoading;
|
|
2892
|
+
memorizedSnapshot.isValidating = newSnapshot.isValidating;
|
|
2893
|
+
memorizedSnapshot.error = newSnapshot.error;
|
|
2894
|
+
return memorizedSnapshot;
|
|
2895
|
+
} else {
|
|
2896
|
+
memorizedSnapshot = newSnapshot;
|
|
2897
|
+
return newSnapshot;
|
|
2898
|
+
}
|
|
2899
|
+
}, () => serverSnapshot];
|
|
2900
|
+
}, [cache, key]);
|
|
2901
|
+
const cached = (0, import_shim.useSyncExternalStore)((0, import_react.useCallback)((callback) => subscribeCache(key, (current, prev) => {
|
|
2902
|
+
if (!isEqual(prev, current)) callback();
|
|
2903
|
+
}), [cache, key]), getSnapshot[0], getSnapshot[1]);
|
|
2904
|
+
const hasRevalidator = EVENT_REVALIDATORS[key] && EVENT_REVALIDATORS[key].length > 0;
|
|
2905
|
+
const cachedData = cached.data;
|
|
2906
|
+
let data = isUndefined(cachedData) ? fallback && isPromiseLike(fallback) ? use(fallback) : fallback : cachedData;
|
|
2907
|
+
const error = cached.error;
|
|
2908
|
+
const laggyDataRef = (0, import_react.useRef)(data);
|
|
2909
|
+
const consumedCacheDataRef = (0, import_react.useRef)(void 0);
|
|
2910
|
+
let consumedCacheData = consumedCacheDataRef.current;
|
|
2911
|
+
if (!consumedCacheData) {
|
|
2912
|
+
consumedCacheData = /* @__PURE__ */ new WeakMap();
|
|
2913
|
+
consumedCacheDataRef.current = consumedCacheData;
|
|
2914
|
+
}
|
|
2915
|
+
const preloadCacheRef = (0, import_react.useRef)(null);
|
|
2916
|
+
let returnedData = keepPreviousData ? isUndefined(cachedData) ? isUndefined(laggyDataRef.current) ? data : laggyDataRef.current : cachedData : data;
|
|
2917
|
+
const hasKeyButNoData = key && isUndefined(data);
|
|
2918
|
+
const hydrationRef = (0, import_react.useRef)(null);
|
|
2919
|
+
!IS_SERVER && (0, import_shim.useSyncExternalStore)(sub, () => {
|
|
2920
|
+
hydrationRef.current = false;
|
|
2921
|
+
return hydrationRef;
|
|
2922
|
+
}, () => {
|
|
2923
|
+
hydrationRef.current = true;
|
|
2924
|
+
return hydrationRef;
|
|
2925
|
+
});
|
|
2926
|
+
const isHydration = hydrationRef.current;
|
|
2927
|
+
if (strictServerPrefetchWarning && isHydration && !suspense && hasKeyButNoData) 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.`);
|
|
2928
|
+
const shouldDoInitialRevalidation = (() => {
|
|
2929
|
+
if (!key || !fetcher) return false;
|
|
2930
|
+
if (getConfig().isPaused()) return false;
|
|
2931
|
+
if (hasRevalidator && !isUndefined(error)) return false;
|
|
2932
|
+
if (isInitialMount && !isUndefined(revalidateOnMount)) return revalidateOnMount;
|
|
2933
|
+
if (suspense && hasCacheData && hasKeyButNoData) return false;
|
|
2934
|
+
if (suspense) return isUndefined(data) ? false : revalidateIfStale;
|
|
2935
|
+
return isUndefined(data) || revalidateIfStale;
|
|
2936
|
+
})();
|
|
2937
|
+
const defaultValidatingState = isInitialMount && shouldDoInitialRevalidation;
|
|
2938
|
+
const isValidating = isUndefined(cached.isValidating) ? defaultValidatingState : cached.isValidating;
|
|
2939
|
+
const isLoading = isUndefined(cached.isLoading) ? defaultValidatingState : cached.isLoading;
|
|
2940
|
+
const revalidate = (0, import_react.useCallback)(async (revalidateOpts) => {
|
|
2941
|
+
const currentFetcher = fetcherRef.current;
|
|
2942
|
+
if (!key || !currentFetcher || unmountedRef.current || getConfig().isPaused()) return false;
|
|
2943
|
+
let newData;
|
|
2944
|
+
let startAt;
|
|
2945
|
+
let loading = true;
|
|
2946
|
+
const opts = revalidateOpts || {};
|
|
2947
|
+
const shouldStartNewRequest = !FETCH[key] || !opts.dedupe;
|
|
2948
|
+
const shouldUseRSCPreload = hasCacheData && !isCacheDataConsumed(consumedCacheData, serverCacheData, key) && !isUndefined(preloadedData) && isUndefined(getCache().data);
|
|
2949
|
+
const callbackSafeguard = () => {
|
|
2950
|
+
if (IS_REACT_LEGACY) return !unmountedRef.current && key === keyRef.current && initialMountedRef.current;
|
|
2951
|
+
return key === keyRef.current;
|
|
2952
|
+
};
|
|
2953
|
+
const finalState = {
|
|
2954
|
+
isValidating: false,
|
|
2955
|
+
isLoading: false
|
|
2956
|
+
};
|
|
2957
|
+
const finishRequestAndUpdateState = () => {
|
|
2958
|
+
setCache(finalState);
|
|
2959
|
+
};
|
|
2960
|
+
const cleanupState = () => {
|
|
2961
|
+
const requestInfo = FETCH[key];
|
|
2962
|
+
if (requestInfo && requestInfo[1] === startAt) delete FETCH[key];
|
|
2963
|
+
};
|
|
2964
|
+
const initialState = { isValidating: true };
|
|
2965
|
+
if (isUndefined(getCache().data)) initialState.isLoading = true;
|
|
2966
|
+
try {
|
|
2967
|
+
if (shouldStartNewRequest) {
|
|
2968
|
+
setCache(initialState);
|
|
2969
|
+
if (config.loadingTimeout && isUndefined(getCache().data)) setTimeout(() => {
|
|
2970
|
+
if (loading && callbackSafeguard()) getConfig().onLoadingSlow(key, config);
|
|
2971
|
+
}, config.loadingTimeout);
|
|
2972
|
+
if (shouldUseRSCPreload) markCacheDataConsumed(consumedCacheData, serverCacheData, key);
|
|
2973
|
+
FETCH[key] = [shouldUseRSCPreload ? preloadedData : currentFetcher(fnArg), getTimestamp()];
|
|
2974
|
+
if (shouldUseRSCPreload && PRELOAD[key]) delete PRELOAD[key];
|
|
2975
|
+
}
|
|
2976
|
+
[newData, startAt] = FETCH[key];
|
|
2977
|
+
newData = await newData;
|
|
2978
|
+
if (shouldStartNewRequest) setTimeout(cleanupState, config.dedupingInterval);
|
|
2979
|
+
if (!FETCH[key] || FETCH[key][1] !== startAt) {
|
|
2980
|
+
if (shouldStartNewRequest) {
|
|
2981
|
+
if (callbackSafeguard()) getConfig().onDiscarded(key);
|
|
2982
|
+
}
|
|
2983
|
+
return false;
|
|
2984
|
+
}
|
|
2985
|
+
finalState.error = void 0;
|
|
2986
|
+
const mutationInfo = MUTATION[key];
|
|
2987
|
+
if (!isUndefined(mutationInfo) && (startAt <= mutationInfo[0] || startAt <= mutationInfo[1] || mutationInfo[1] === 0)) {
|
|
2988
|
+
finishRequestAndUpdateState();
|
|
2989
|
+
if (shouldStartNewRequest) {
|
|
2990
|
+
if (callbackSafeguard()) getConfig().onDiscarded(key);
|
|
2991
|
+
}
|
|
2992
|
+
return false;
|
|
2993
|
+
}
|
|
2994
|
+
const cacheData = getCache().data;
|
|
2995
|
+
finalState.data = compare(cacheData, newData) ? cacheData : newData;
|
|
2996
|
+
if (shouldStartNewRequest) {
|
|
2997
|
+
if (callbackSafeguard()) getConfig().onSuccess(newData, key, config);
|
|
2998
|
+
}
|
|
2999
|
+
} catch (err) {
|
|
3000
|
+
cleanupState();
|
|
3001
|
+
const currentConfig = getConfig();
|
|
3002
|
+
const { shouldRetryOnError } = currentConfig;
|
|
3003
|
+
if (!currentConfig.isPaused()) {
|
|
3004
|
+
finalState.error = err;
|
|
3005
|
+
if (shouldStartNewRequest && callbackSafeguard()) {
|
|
3006
|
+
currentConfig.onError(err, key, currentConfig);
|
|
3007
|
+
if (shouldRetryOnError === true || isFunction(shouldRetryOnError) && shouldRetryOnError(err)) {
|
|
3008
|
+
if (!getConfig().revalidateOnFocus || !getConfig().revalidateOnReconnect || isActive()) currentConfig.onErrorRetry(err, key, currentConfig, (_opts) => {
|
|
3009
|
+
const revalidators = EVENT_REVALIDATORS[key];
|
|
3010
|
+
if (revalidators && revalidators[0]) revalidators[0](3, _opts);
|
|
3011
|
+
}, {
|
|
3012
|
+
retryCount: (opts.retryCount || 0) + 1,
|
|
3013
|
+
dedupe: true
|
|
3014
|
+
});
|
|
3015
|
+
}
|
|
3016
|
+
}
|
|
3017
|
+
}
|
|
3018
|
+
}
|
|
3019
|
+
loading = false;
|
|
3020
|
+
finishRequestAndUpdateState();
|
|
3021
|
+
return true;
|
|
3022
|
+
}, [key, cache]);
|
|
3023
|
+
const boundMutate = (0, import_react.useCallback)((...args) => {
|
|
3024
|
+
return internalMutate(cache, keyRef.current, ...args);
|
|
3025
|
+
}, []);
|
|
3026
|
+
useIsomorphicLayoutEffect(() => {
|
|
3027
|
+
const preloaded = preloadCacheRef.current;
|
|
3028
|
+
if (!preloaded) return;
|
|
3029
|
+
preloadCacheRef.current = null;
|
|
3030
|
+
markCacheDataConsumed(consumedCacheData, preloaded.cacheData, preloaded.key);
|
|
3031
|
+
if (isUndefined(getCache().data)) setCache({
|
|
3032
|
+
data: preloaded.data,
|
|
3033
|
+
error: void 0,
|
|
3034
|
+
_k: preloaded._k
|
|
3035
|
+
});
|
|
3036
|
+
if (PRELOAD[preloaded.key]) delete PRELOAD[preloaded.key];
|
|
3037
|
+
});
|
|
3038
|
+
useIsomorphicLayoutEffect(() => {
|
|
3039
|
+
fetcherRef.current = fetcher;
|
|
3040
|
+
configRef.current = config;
|
|
3041
|
+
if (!isUndefined(cachedData)) laggyDataRef.current = cachedData;
|
|
3042
|
+
});
|
|
3043
|
+
useIsomorphicLayoutEffect(() => {
|
|
3044
|
+
if (fetcher || !hasCacheData || isUndefined(preloadedData) || isCacheDataConsumed(consumedCacheData, serverCacheData, key) || !isUndefined(getCache().data)) return;
|
|
3045
|
+
markCacheDataConsumed(consumedCacheData, serverCacheData, key);
|
|
3046
|
+
const mutation = MUTATION[key];
|
|
3047
|
+
commitCacheData({
|
|
3048
|
+
value: preloadedData,
|
|
3049
|
+
getCacheData: () => getCache().data,
|
|
3050
|
+
canCommit: () => !unmountedRef.current && key === keyRef.current && MUTATION[key] === mutation,
|
|
3051
|
+
setCache: (state) => setCache({
|
|
3052
|
+
...state,
|
|
3053
|
+
_k: fnArg
|
|
3054
|
+
})
|
|
3055
|
+
});
|
|
3056
|
+
});
|
|
3057
|
+
useIsomorphicLayoutEffect(() => {
|
|
3058
|
+
if (!key) return;
|
|
3059
|
+
const softRevalidate = revalidate.bind(void 0, WITH_DEDUPE);
|
|
3060
|
+
let nextFocusRevalidatedAt = 0;
|
|
3061
|
+
if (getConfig().revalidateOnFocus) nextFocusRevalidatedAt = Date.now() + getConfig().focusThrottleInterval;
|
|
3062
|
+
const onRevalidate = (type, opts = {}) => {
|
|
3063
|
+
if (type == 0) {
|
|
3064
|
+
const now = Date.now();
|
|
3065
|
+
if (getConfig().revalidateOnFocus && now > nextFocusRevalidatedAt && isActive()) {
|
|
3066
|
+
nextFocusRevalidatedAt = now + getConfig().focusThrottleInterval;
|
|
3067
|
+
softRevalidate();
|
|
3068
|
+
}
|
|
3069
|
+
} else if (type == 1) {
|
|
3070
|
+
if (getConfig().revalidateOnReconnect && isActive()) softRevalidate();
|
|
3071
|
+
} else if (type == 2) return revalidate();
|
|
3072
|
+
else if (type == 3) return revalidate(opts);
|
|
3073
|
+
else if (type == 4) {
|
|
3074
|
+
laggyDataRef.current = void 0;
|
|
3075
|
+
if (opts.revalidate) return revalidate();
|
|
3076
|
+
}
|
|
3077
|
+
};
|
|
3078
|
+
const unsubEvents = subscribeCallback(key, EVENT_REVALIDATORS, onRevalidate);
|
|
3079
|
+
unmountedRef.current = false;
|
|
3080
|
+
keyRef.current = key;
|
|
3081
|
+
initialMountedRef.current = true;
|
|
3082
|
+
setCache({ _k: fnArg });
|
|
3083
|
+
if (shouldDoInitialRevalidation) {
|
|
3084
|
+
if (!FETCH[key]) {
|
|
3085
|
+
if (isUndefined(data) || IS_SERVER) softRevalidate();
|
|
3086
|
+
else rAF(softRevalidate);
|
|
3087
|
+
}
|
|
3088
|
+
}
|
|
3089
|
+
return () => {
|
|
3090
|
+
unmountedRef.current = true;
|
|
3091
|
+
unsubEvents();
|
|
3092
|
+
};
|
|
3093
|
+
}, [key]);
|
|
3094
|
+
useIsomorphicLayoutEffect(() => {
|
|
3095
|
+
let timer;
|
|
3096
|
+
function next() {
|
|
3097
|
+
const interval = isFunction(refreshInterval) ? refreshInterval(getCache().data) : refreshInterval;
|
|
3098
|
+
if (interval && timer !== -1) timer = setTimeout(execute, interval);
|
|
3099
|
+
}
|
|
3100
|
+
function execute() {
|
|
3101
|
+
if (!getCache().error && (refreshWhenHidden || getConfig().isVisible()) && (refreshWhenOffline || getConfig().isOnline())) revalidate(WITH_DEDUPE).then(next);
|
|
3102
|
+
else next();
|
|
3103
|
+
}
|
|
3104
|
+
next();
|
|
3105
|
+
return () => {
|
|
3106
|
+
if (timer) {
|
|
3107
|
+
clearTimeout(timer);
|
|
3108
|
+
timer = -1;
|
|
3109
|
+
}
|
|
3110
|
+
};
|
|
3111
|
+
}, [
|
|
3112
|
+
refreshInterval,
|
|
3113
|
+
refreshWhenHidden,
|
|
3114
|
+
refreshWhenOffline,
|
|
3115
|
+
key
|
|
3116
|
+
]);
|
|
3117
|
+
(0, import_react.useDebugValue)(returnedData);
|
|
3118
|
+
if (suspense) {
|
|
3119
|
+
if (!IS_REACT_LEGACY && IS_SERVER && hasKeyButNoData && isUndefined(preloadedData)) throw new Error("Fallback data is required when using Suspense in SSR.");
|
|
3120
|
+
if (hasKeyButNoData) {
|
|
3121
|
+
fetcherRef.current = fetcher;
|
|
3122
|
+
configRef.current = config;
|
|
3123
|
+
unmountedRef.current = false;
|
|
3124
|
+
}
|
|
3125
|
+
const shouldConsumePreload = !isUndefined(preloadedData) && hasKeyButNoData;
|
|
3126
|
+
let preloadData = void 0;
|
|
3127
|
+
if (shouldConsumePreload && hasCacheData) {
|
|
3128
|
+
preloadData = preloadedData && isPromiseLike(preloadedData) ? use(preloadedData) : preloadedData;
|
|
3129
|
+
data = preloadData;
|
|
3130
|
+
returnedData = preloadData;
|
|
3131
|
+
if (!IS_SERVER) preloadCacheRef.current = {
|
|
3132
|
+
data: preloadData,
|
|
3133
|
+
_k: fnArg,
|
|
3134
|
+
key,
|
|
3135
|
+
cacheData: serverCacheData
|
|
3136
|
+
};
|
|
3137
|
+
} else use(shouldConsumePreload ? boundMutate(preloadedData) : resolvedUndef);
|
|
3138
|
+
if (!isUndefined(error) && hasKeyButNoData) throw error;
|
|
3139
|
+
const revalidation = hasKeyButNoData && isUndefined(preloadData) ? revalidate(WITH_DEDUPE) : resolvedUndef;
|
|
3140
|
+
if (!isUndefined(returnedData) && hasKeyButNoData) {
|
|
3141
|
+
revalidation.status = "fulfilled";
|
|
3142
|
+
revalidation.value = true;
|
|
3143
|
+
}
|
|
3144
|
+
use(revalidation);
|
|
3145
|
+
}
|
|
3146
|
+
return {
|
|
3147
|
+
mutate: boundMutate,
|
|
3148
|
+
get data() {
|
|
3149
|
+
stateDependencies.data = true;
|
|
3150
|
+
return returnedData;
|
|
3151
|
+
},
|
|
3152
|
+
get error() {
|
|
3153
|
+
stateDependencies.error = true;
|
|
3154
|
+
return error;
|
|
3155
|
+
},
|
|
3156
|
+
get isValidating() {
|
|
3157
|
+
stateDependencies.isValidating = true;
|
|
3158
|
+
return isValidating;
|
|
3159
|
+
},
|
|
3160
|
+
get isLoading() {
|
|
3161
|
+
stateDependencies.isLoading = true;
|
|
3162
|
+
return isLoading;
|
|
3163
|
+
}
|
|
3164
|
+
};
|
|
3165
|
+
};
|
|
3166
|
+
OBJECT.defineProperty(SWRConfig$1, "defaultValue", { value: defaultConfig });
|
|
3167
|
+
/**
|
|
3168
|
+
* A hook to fetch data.
|
|
3169
|
+
*
|
|
3170
|
+
* @see {@link https://swr.vercel.app}
|
|
3171
|
+
*
|
|
3172
|
+
* @example
|
|
3173
|
+
* ```jsx
|
|
3174
|
+
* import useSWR from 'swr'
|
|
3175
|
+
* function Profile() {
|
|
3176
|
+
* const { data, error, isLoading } = useSWR('/api/user', fetcher)
|
|
3177
|
+
* if (error) return <div>failed to load</div>
|
|
3178
|
+
* if (isLoading) return <div>loading...</div>
|
|
3179
|
+
* return <div>hello {data.name}!</div>
|
|
3180
|
+
* }
|
|
3181
|
+
* ```
|
|
3182
|
+
*/ var useSWR = withArgs(useSWRHandler);
|
|
3183
|
+
// ../../node_modules/.bun/swr@2.5.1+4bcfe187168658ad/node_modules/swr/dist/infinite/index.mjs
|
|
3184
|
+
var getFirstPageKey = (getKey) => {
|
|
3185
|
+
return serialize(getKey ? getKey(0, null) : null)[0];
|
|
3186
|
+
};
|
|
3187
|
+
var EMPTY_PROMISE = Promise.resolve();
|
|
3188
|
+
var infinite = (useSWRNext) => (getKey, fn, config) => {
|
|
3189
|
+
const didMountRef = (0, import_react.useRef)(false);
|
|
3190
|
+
const { cache: cache$1, initialSize = 1, revalidateAll = false, persistSize = false, revalidateFirstPage = true, revalidateOnMount = false, parallel = false } = config;
|
|
3191
|
+
const [, , , PRELOAD] = SWRGlobalState.get(cache);
|
|
3192
|
+
let infiniteKey;
|
|
3193
|
+
try {
|
|
3194
|
+
infiniteKey = getFirstPageKey(getKey);
|
|
3195
|
+
if (infiniteKey) infiniteKey = INFINITE_PREFIX + infiniteKey;
|
|
3196
|
+
} catch (err) {}
|
|
3197
|
+
const [get, set, subscribeCache] = createCacheHelper(cache$1, infiniteKey);
|
|
3198
|
+
const getSnapshot = (0, import_react.useCallback)(() => {
|
|
3199
|
+
return isUndefined(get()._l) ? initialSize : get()._l;
|
|
3200
|
+
}, [
|
|
3201
|
+
cache$1,
|
|
3202
|
+
infiniteKey,
|
|
3203
|
+
initialSize
|
|
3204
|
+
]);
|
|
3205
|
+
(0, import_shim.useSyncExternalStore)((0, import_react.useCallback)((callback) => {
|
|
3206
|
+
if (infiniteKey) return subscribeCache(infiniteKey, () => {
|
|
3207
|
+
callback();
|
|
3208
|
+
});
|
|
3209
|
+
return () => {};
|
|
3210
|
+
}, [cache$1, infiniteKey]), getSnapshot, getSnapshot);
|
|
3211
|
+
const resolvePageSize = (0, import_react.useCallback)(() => {
|
|
3212
|
+
const cachedPageSize = get()._l;
|
|
3213
|
+
return isUndefined(cachedPageSize) ? initialSize : cachedPageSize;
|
|
3214
|
+
}, [infiniteKey, initialSize]);
|
|
3215
|
+
const lastPageSizeRef = (0, import_react.useRef)(resolvePageSize());
|
|
3216
|
+
useIsomorphicLayoutEffect(() => {
|
|
3217
|
+
if (!didMountRef.current) {
|
|
3218
|
+
didMountRef.current = true;
|
|
3219
|
+
return;
|
|
3220
|
+
}
|
|
3221
|
+
if (infiniteKey) set({ _l: persistSize ? lastPageSizeRef.current : resolvePageSize() });
|
|
3222
|
+
}, [infiniteKey, cache$1]);
|
|
3223
|
+
const shouldRevalidateOnMount = revalidateOnMount && !didMountRef.current;
|
|
3224
|
+
const swr = useSWRNext(infiniteKey, async (key) => {
|
|
3225
|
+
const forceRevalidateAll = get()._i;
|
|
3226
|
+
const shouldRevalidatePage = get()._r;
|
|
3227
|
+
const state = SWRGlobalState.get(cache$1);
|
|
3228
|
+
const unloadGeneration = state[8];
|
|
3229
|
+
const unloadedDuringRequest = () => state[8] !== unloadGeneration;
|
|
3230
|
+
set({ _r: void 0 });
|
|
3231
|
+
const data = [];
|
|
3232
|
+
const pageSize = resolvePageSize();
|
|
3233
|
+
const [getCache] = createCacheHelper(cache$1, key);
|
|
3234
|
+
const cacheData = getCache().data;
|
|
3235
|
+
const revalidators = [];
|
|
3236
|
+
let previousPageData = null;
|
|
3237
|
+
for (let i = 0; i < pageSize; ++i) {
|
|
3238
|
+
const [pageKey, pageArg] = serialize(getKey(i, parallel ? null : previousPageData));
|
|
3239
|
+
if (!pageKey) break;
|
|
3240
|
+
const [getSWRCache, setSWRCache] = createCacheHelper(cache$1, pageKey);
|
|
3241
|
+
let pageData = getSWRCache().data;
|
|
3242
|
+
const shouldFetchPage = revalidateAll || forceRevalidateAll || isUndefined(pageData) || revalidateFirstPage && !i && !isUndefined(cacheData) || shouldRevalidateOnMount || cacheData && !isUndefined(cacheData[i]) && !config.compare(cacheData[i], pageData);
|
|
3243
|
+
if (fn && (typeof shouldRevalidatePage === "function" ? shouldRevalidatePage(pageData, pageArg) : shouldFetchPage)) {
|
|
3244
|
+
const revalidate = async () => {
|
|
3245
|
+
if (!(pageKey in PRELOAD)) pageData = await fn(pageArg);
|
|
3246
|
+
else {
|
|
3247
|
+
const req = PRELOAD[pageKey];
|
|
3248
|
+
delete PRELOAD[pageKey];
|
|
3249
|
+
pageData = await req;
|
|
3250
|
+
}
|
|
3251
|
+
if (!unloadedDuringRequest()) setSWRCache({
|
|
3252
|
+
data: pageData,
|
|
3253
|
+
_k: pageArg
|
|
3254
|
+
});
|
|
3255
|
+
data[i] = pageData;
|
|
3256
|
+
};
|
|
3257
|
+
if (parallel) revalidators.push(revalidate);
|
|
3258
|
+
else await revalidate();
|
|
3259
|
+
} else data[i] = pageData;
|
|
3260
|
+
if (!parallel) previousPageData = pageData;
|
|
3261
|
+
}
|
|
3262
|
+
if (parallel) await Promise.all(revalidators.map((r) => r()));
|
|
3263
|
+
if (!unloadedDuringRequest()) set({ _i: void 0 });
|
|
3264
|
+
return data;
|
|
3265
|
+
}, config);
|
|
3266
|
+
const mutate = (0, import_react.useCallback)(function(data, opts) {
|
|
3267
|
+
const options = typeof opts === "boolean" ? { revalidate: opts } : opts || {};
|
|
3268
|
+
const shouldRevalidate = options.revalidate !== false;
|
|
3269
|
+
if (!infiniteKey) return EMPTY_PROMISE;
|
|
3270
|
+
if (shouldRevalidate) {
|
|
3271
|
+
if (!isUndefined(data)) set({
|
|
3272
|
+
_i: false,
|
|
3273
|
+
_r: options.revalidate
|
|
3274
|
+
});
|
|
3275
|
+
else set({
|
|
3276
|
+
_i: true,
|
|
3277
|
+
_r: options.revalidate
|
|
3278
|
+
});
|
|
3279
|
+
}
|
|
3280
|
+
return arguments.length ? swr.mutate(data, {
|
|
3281
|
+
...options,
|
|
3282
|
+
revalidate: shouldRevalidate
|
|
3283
|
+
}) : swr.mutate();
|
|
3284
|
+
}, [infiniteKey, cache$1]);
|
|
3285
|
+
const setSize = (0, import_react.useCallback)((arg) => {
|
|
3286
|
+
if (!infiniteKey) return EMPTY_PROMISE;
|
|
3287
|
+
const [, changeSize] = createCacheHelper(cache$1, infiniteKey);
|
|
3288
|
+
let size;
|
|
3289
|
+
if (isFunction(arg)) size = arg(resolvePageSize());
|
|
3290
|
+
else if (typeof arg == "number") size = arg;
|
|
3291
|
+
if (typeof size != "number") return EMPTY_PROMISE;
|
|
3292
|
+
changeSize({ _l: size });
|
|
3293
|
+
lastPageSizeRef.current = size;
|
|
3294
|
+
const data = [];
|
|
3295
|
+
const [getInfiniteCache] = createCacheHelper(cache$1, infiniteKey);
|
|
3296
|
+
let previousPageData = null;
|
|
3297
|
+
for (let i = 0; i < size; ++i) {
|
|
3298
|
+
const [pageKey] = serialize(getKey(i, previousPageData));
|
|
3299
|
+
const [getCache] = createCacheHelper(cache$1, pageKey);
|
|
3300
|
+
const pageData = pageKey ? getCache().data : void 0;
|
|
3301
|
+
if (isUndefined(pageData)) return mutate(getInfiniteCache().data);
|
|
3302
|
+
data.push(pageData);
|
|
3303
|
+
previousPageData = pageData;
|
|
3304
|
+
}
|
|
3305
|
+
return mutate(data);
|
|
3306
|
+
}, [
|
|
3307
|
+
infiniteKey,
|
|
3308
|
+
cache$1,
|
|
3309
|
+
mutate,
|
|
3310
|
+
resolvePageSize
|
|
3311
|
+
]);
|
|
3312
|
+
return {
|
|
3313
|
+
size: resolvePageSize(),
|
|
3314
|
+
setSize,
|
|
3315
|
+
mutate,
|
|
3316
|
+
get data() {
|
|
3317
|
+
return swr.data;
|
|
3318
|
+
},
|
|
3319
|
+
get error() {
|
|
3320
|
+
return swr.error;
|
|
3321
|
+
},
|
|
3322
|
+
get isValidating() {
|
|
3323
|
+
return swr.isValidating;
|
|
3324
|
+
},
|
|
3325
|
+
get isLoading() {
|
|
3326
|
+
return swr.isLoading;
|
|
3327
|
+
}
|
|
3328
|
+
};
|
|
3329
|
+
};
|
|
3330
|
+
var useSWRInfinite = withMiddleware(useSWR, infinite);
|
|
3331
|
+
// app/lib/client/hooks/use-infinite-list.ts
|
|
3332
|
+
/**
|
|
3333
|
+
* Cursor-based infinite list backed by SWR's global cache.
|
|
3334
|
+
*
|
|
3335
|
+
* Pages are keyed by `[cacheKey, cursor]`, so switching tabs (unmount +
|
|
3336
|
+
* remount) restores previously fetched pages instantly instead of refetching.
|
|
3337
|
+
* Revalidation is deliberately conservative: cached pages are NOT refetched on remount or
|
|
3338
|
+
* when loading further pages (`revalidateFirstPage: false`,
|
|
3339
|
+
* `revalidateIfStale: false`). Freshness comes from explicit `reload()`/
|
|
3340
|
+
* `refresh()` calls (the Refresh button and the tab-visibility auto-reload).
|
|
3341
|
+
*
|
|
3342
|
+
* Rows are deduped by `getItemKey` when pages are flattened, so cursor drift
|
|
3343
|
+
* on live data cannot produce duplicate rows.
|
|
3344
|
+
*/
|
|
3345
|
+
function useInfiniteList(cacheKey, fetchFn, getItemKey) {
|
|
3346
|
+
const { data: pages, error, isLoading, isValidating, size, setSize, mutate } = useSWRInfinite((0, import_react.useCallback)((_index, prev) => {
|
|
3347
|
+
if (prev && (!prev.hasMore || !prev.cursor)) return null;
|
|
3348
|
+
return [cacheKey, prev?.cursor ?? null];
|
|
3349
|
+
}, [cacheKey]), ([, cursor]) => fetchFn(cursor ?? void 0), {
|
|
3350
|
+
revalidateFirstPage: false,
|
|
3351
|
+
revalidateIfStale: false,
|
|
3352
|
+
revalidateOnFocus: false,
|
|
3353
|
+
keepPreviousData: true
|
|
3354
|
+
});
|
|
3355
|
+
const items = (0, import_react.useMemo)(() => {
|
|
3356
|
+
if (!pages) return [];
|
|
3357
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3358
|
+
const result = [];
|
|
3359
|
+
for (const page of pages) for (const item of page.data) {
|
|
3360
|
+
const key = getItemKey(item);
|
|
3361
|
+
if (seen.has(key)) continue;
|
|
3362
|
+
seen.add(key);
|
|
3363
|
+
result.push(item);
|
|
3364
|
+
}
|
|
3365
|
+
return result;
|
|
3366
|
+
}, [pages, getItemKey]);
|
|
3367
|
+
const lastPage = pages?.[pages.length - 1];
|
|
3368
|
+
const hasMore = Boolean(lastPage?.hasMore && lastPage?.cursor);
|
|
3369
|
+
const isLoadingMore = size > 0 && Boolean(pages) && pages.length < size;
|
|
3370
|
+
const loadMore = (0, import_react.useCallback)(() => {
|
|
3371
|
+
if (isValidating || !hasMore) return;
|
|
3372
|
+
setSize((s) => s + 1);
|
|
3373
|
+
}, [
|
|
3374
|
+
isValidating,
|
|
3375
|
+
hasMore,
|
|
3376
|
+
setSize
|
|
3377
|
+
]);
|
|
3378
|
+
const reload = (0, import_react.useCallback)(() => {
|
|
3379
|
+
setSize(1);
|
|
3380
|
+
mutate();
|
|
3381
|
+
}, [setSize, mutate]);
|
|
3382
|
+
return {
|
|
3383
|
+
items,
|
|
3384
|
+
error: error ? error instanceof Error ? error : new WorkflowWebAPIError(String(error), { layer: "client" }) : null,
|
|
3385
|
+
isLoading,
|
|
3386
|
+
isLoadingMore,
|
|
3387
|
+
hasMore,
|
|
3388
|
+
loadMore,
|
|
3389
|
+
reload
|
|
3390
|
+
};
|
|
3391
|
+
}
|
|
3392
|
+
/**
|
|
3393
|
+
* Infinite-scrolling list of workflow runs.
|
|
3394
|
+
*
|
|
3395
|
+
* Pages are large since rows accumulate, which keeps the number of
|
|
3396
|
+
* round-trips low while scrolling.
|
|
3397
|
+
*/
|
|
3398
|
+
function useWorkflowRunsInfinite(params) {
|
|
3399
|
+
const { workflowName, status, limit = 25, sortOrder = "desc" } = params;
|
|
3400
|
+
return useInfiniteList(`workflow-runs:${workflowName ?? ""}:${status ?? ""}:${sortOrder}:${limit}`, (0, import_react.useCallback)((cursor) => unwrapOrThrow(rpc("fetchRuns", {
|
|
3401
|
+
cursor,
|
|
3402
|
+
sortOrder,
|
|
3403
|
+
limit,
|
|
3404
|
+
workflowName,
|
|
3405
|
+
status
|
|
3406
|
+
})), [
|
|
3407
|
+
workflowName,
|
|
3408
|
+
limit,
|
|
3409
|
+
sortOrder,
|
|
3410
|
+
status
|
|
3411
|
+
]), (0, import_react.useCallback)((run) => run.runId, []));
|
|
3412
|
+
}
|
|
3413
|
+
// app/lib/client/hooks/use-load-more-on-scroll.ts
|
|
3414
|
+
/**
|
|
3415
|
+
* Fires `loadMore` when a sentinel element scrolls into view.
|
|
3416
|
+
*
|
|
3417
|
+
* Attach the returned ref to an empty element placed after the list. The
|
|
3418
|
+
* observer only fires while `hasMore && !isLoadingMore`, and `loadMore` is
|
|
3419
|
+
* held in a ref so its identity changing does not re-create the observer.
|
|
3420
|
+
*
|
|
3421
|
+
* Pass the scrollable container as `root` when the list scrolls inside a
|
|
3422
|
+
* fixed-height element (rather than the viewport) so `rootMargin` prefetching
|
|
3423
|
+
* is measured against the container edge.
|
|
3424
|
+
*/
|
|
3425
|
+
function useLoadMoreOnScroll(loadMore, { hasMore, isLoadingMore, root = null, rootMargin = "400px" }) {
|
|
3426
|
+
const sentinelRef = (0, import_react.useRef)(null);
|
|
3427
|
+
const loadMoreRef = (0, import_react.useRef)(loadMore);
|
|
3428
|
+
(0, import_react.useEffect)(() => {
|
|
3429
|
+
loadMoreRef.current = loadMore;
|
|
3430
|
+
}, [loadMore]);
|
|
3431
|
+
(0, import_react.useEffect)(() => {
|
|
3432
|
+
const sentinel = sentinelRef.current;
|
|
3433
|
+
if (!sentinel || !hasMore || isLoadingMore) return;
|
|
3434
|
+
const observer = new IntersectionObserver((entries) => {
|
|
3435
|
+
for (const entry of entries) if (entry.isIntersecting) {
|
|
3436
|
+
loadMoreRef.current();
|
|
3437
|
+
break;
|
|
3438
|
+
}
|
|
3439
|
+
}, {
|
|
3440
|
+
root,
|
|
3441
|
+
rootMargin,
|
|
3442
|
+
threshold: 0
|
|
3443
|
+
});
|
|
3444
|
+
observer.observe(sentinel);
|
|
3445
|
+
return () => observer.disconnect();
|
|
3446
|
+
}, [
|
|
3447
|
+
hasMore,
|
|
3448
|
+
isLoadingMore,
|
|
3449
|
+
root,
|
|
3450
|
+
rootMargin
|
|
3451
|
+
]);
|
|
3452
|
+
return sentinelRef;
|
|
3453
|
+
}
|
|
3454
|
+
// app/components/runs-table.tsx
|
|
3455
|
+
function RunActionsDropdownContentInner({ runId, runStatus, onSuccess }) {
|
|
3456
|
+
const [events, setEvents] = (0, import_react.useState)(void 0);
|
|
3457
|
+
const [eventsLoading, setEventsLoading] = (0, import_react.useState)(true);
|
|
3458
|
+
const [run, setRun] = (0, import_react.useState)(void 0);
|
|
3459
|
+
const [runIdentityLoading, setRunIdentityLoading] = (0, import_react.useState)(true);
|
|
3460
|
+
const status = run?.status || runStatus;
|
|
3461
|
+
(0, import_react.useEffect)(() => {
|
|
3462
|
+
setRun(void 0);
|
|
3463
|
+
setRunIdentityLoading(true);
|
|
3464
|
+
rpc("fetchRun", {
|
|
3465
|
+
runId,
|
|
3466
|
+
resolveData: "none"
|
|
3467
|
+
}).then((runResult) => {
|
|
3468
|
+
if (runResult.success) setRun(runResult.data);
|
|
3469
|
+
}).catch((err) => {
|
|
3470
|
+
console.error("Failed to fetch run:", err);
|
|
3471
|
+
}).finally(() => {
|
|
3472
|
+
setRunIdentityLoading(false);
|
|
3473
|
+
});
|
|
3474
|
+
setEvents(void 0);
|
|
3475
|
+
setEventsLoading(true);
|
|
3476
|
+
rpc("fetchEvents", {
|
|
3477
|
+
runId,
|
|
3478
|
+
limit: 1e3,
|
|
3479
|
+
sortOrder: "desc"
|
|
3480
|
+
}).then((eventsResult) => {
|
|
3481
|
+
if (eventsResult.success) setEvents(eventsResult.data.data);
|
|
3482
|
+
}).catch((err) => {
|
|
3483
|
+
console.error("Failed to fetch events:", err);
|
|
3484
|
+
}).finally(() => {
|
|
3485
|
+
setEventsLoading(false);
|
|
3486
|
+
});
|
|
3487
|
+
}, [runId]);
|
|
3488
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RunActionsDropdownItems, {
|
|
3489
|
+
runId,
|
|
3490
|
+
runStatus: status,
|
|
3491
|
+
events,
|
|
3492
|
+
eventsLoading,
|
|
3493
|
+
replayDisabledReason: getRunReplayDisabledReason(run, runIdentityLoading),
|
|
3494
|
+
stopPropagation: true,
|
|
3495
|
+
callbacks: { onSuccess }
|
|
3496
|
+
});
|
|
3497
|
+
}
|
|
3498
|
+
function LazyDropdownMenu({ runId, runStatus, onSuccess }) {
|
|
3499
|
+
const [isOpen, setIsOpen] = (0, import_react.useState)(false);
|
|
3500
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenu, {
|
|
3501
|
+
open: isOpen,
|
|
3502
|
+
onOpenChange: setIsOpen,
|
|
3503
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuTrigger, {
|
|
3504
|
+
asChild: true,
|
|
3505
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
|
|
3506
|
+
variant: "tertiary",
|
|
3507
|
+
size: "small",
|
|
3508
|
+
shape: "square",
|
|
3509
|
+
"aria-label": "Run actions",
|
|
3510
|
+
onClick: (e) => e.stopPropagation(),
|
|
3511
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Ellipsis, { className: "h-4 w-4" })
|
|
3512
|
+
})
|
|
3513
|
+
}), isOpen && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuContent, {
|
|
3514
|
+
align: "end",
|
|
3515
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RunActionsDropdownContentInner, {
|
|
3516
|
+
runId,
|
|
3517
|
+
runStatus,
|
|
3518
|
+
onSuccess
|
|
3519
|
+
})
|
|
3520
|
+
})]
|
|
3521
|
+
});
|
|
3522
|
+
}
|
|
3523
|
+
var statusMap = {
|
|
3524
|
+
pending: {
|
|
3525
|
+
label: "Pending",
|
|
3526
|
+
color: STATUS_COLORS.pending
|
|
3527
|
+
},
|
|
3528
|
+
running: {
|
|
3529
|
+
label: "Running",
|
|
3530
|
+
color: STATUS_COLORS.running
|
|
3531
|
+
},
|
|
3532
|
+
completed: {
|
|
3533
|
+
label: "Completed",
|
|
3534
|
+
color: STATUS_COLORS.completed
|
|
3535
|
+
},
|
|
3536
|
+
failed: {
|
|
3537
|
+
label: "Failed",
|
|
3538
|
+
color: STATUS_COLORS.failed
|
|
3539
|
+
},
|
|
3540
|
+
cancelled: {
|
|
3541
|
+
label: "Cancelled",
|
|
3542
|
+
color: STATUS_COLORS.cancelled
|
|
3543
|
+
}
|
|
3544
|
+
};
|
|
3545
|
+
function useWorkflowFilter() {
|
|
3546
|
+
const navigate = useNavigate();
|
|
3547
|
+
const { pathname } = useLocation();
|
|
3548
|
+
const [searchParams] = useSearchParams();
|
|
3549
|
+
return (0, import_react.useCallback)((value) => {
|
|
3550
|
+
const params = new URLSearchParams(searchParams.toString());
|
|
3551
|
+
if (value === "all") {
|
|
3552
|
+
params.delete("workflow");
|
|
3553
|
+
params.delete("status");
|
|
3554
|
+
} else params.set("workflow", value);
|
|
3555
|
+
navigate(`${pathname}?${params.toString()}`);
|
|
3556
|
+
}, [
|
|
3557
|
+
navigate,
|
|
3558
|
+
pathname,
|
|
3559
|
+
searchParams
|
|
3560
|
+
]);
|
|
3561
|
+
}
|
|
3562
|
+
function useStatusFilter() {
|
|
3563
|
+
const navigate = useNavigate();
|
|
3564
|
+
const { pathname } = useLocation();
|
|
3565
|
+
const [searchParams] = useSearchParams();
|
|
3566
|
+
return (0, import_react.useCallback)((value) => {
|
|
3567
|
+
const params = new URLSearchParams(searchParams.toString());
|
|
3568
|
+
if (value === "all") params.delete("status");
|
|
3569
|
+
else params.set("status", value);
|
|
3570
|
+
navigate(`${pathname}?${params.toString()}`);
|
|
3571
|
+
}, [
|
|
3572
|
+
navigate,
|
|
3573
|
+
pathname,
|
|
3574
|
+
searchParams
|
|
3575
|
+
]);
|
|
3576
|
+
}
|
|
3577
|
+
function FilterControls({ workflowNameFilter, status, seenWorkflowNames, sortOrder, loading, onWorkflowChange, onStatusChange, onSortToggle, onRefresh, lastRefreshTime }) {
|
|
3578
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
3579
|
+
className: "flex items-center justify-between",
|
|
3580
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
3581
|
+
className: "flex items-end gap-2",
|
|
3582
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
|
|
3583
|
+
className: "text-sm text-muted-foreground",
|
|
3584
|
+
children: "Last refreshed"
|
|
3585
|
+
}), lastRefreshTime && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RelativeTime, {
|
|
3586
|
+
date: lastRefreshTime,
|
|
3587
|
+
className: "text-sm text-muted-foreground",
|
|
3588
|
+
type: "distance"
|
|
3589
|
+
})]
|
|
3590
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
3591
|
+
className: "flex items-center gap-4",
|
|
3592
|
+
children: [
|
|
3593
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Select, {
|
|
3594
|
+
value: workflowNameFilter ?? "all",
|
|
3595
|
+
onValueChange: onWorkflowChange,
|
|
3596
|
+
disabled: loading,
|
|
3597
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectTrigger, {
|
|
3598
|
+
className: "w-[180px] h-9",
|
|
3599
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectValue, { placeholder: "Filter by workflow" })
|
|
3600
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(SelectContent, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectItem, {
|
|
3601
|
+
value: "all",
|
|
3602
|
+
children: "All Workflows"
|
|
3603
|
+
}), Array.from(seenWorkflowNames).sort().map((name) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectItem, {
|
|
3604
|
+
value: name,
|
|
3605
|
+
children: parseWorkflowName(name)?.shortName || name
|
|
3606
|
+
}, name))] })]
|
|
3607
|
+
}),
|
|
3608
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Tooltip, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipTrigger, {
|
|
3609
|
+
asChild: true,
|
|
3610
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Select, {
|
|
3611
|
+
value: status || "all",
|
|
3612
|
+
onValueChange: onStatusChange,
|
|
3613
|
+
disabled: loading,
|
|
3614
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectTrigger, {
|
|
3615
|
+
className: "w-[140px] h-9",
|
|
3616
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectValue, { placeholder: "Filter by status" })
|
|
3617
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(SelectContent, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectItem, {
|
|
3618
|
+
value: "all",
|
|
3619
|
+
children: "Any status"
|
|
3620
|
+
}), Object.entries(statusMap).map(([status, { label, color }]) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectItem, {
|
|
3621
|
+
value: status,
|
|
3622
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
3623
|
+
className: "flex items-center",
|
|
3624
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: `${color} size-1.5 rounded-full mr-2` }), label]
|
|
3625
|
+
})
|
|
3626
|
+
}, status))] })]
|
|
3627
|
+
}) })
|
|
3628
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContent, { children: "Filter runs by status" })] }),
|
|
3629
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Tooltip, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipTrigger, {
|
|
3630
|
+
asChild: true,
|
|
3631
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button, {
|
|
3632
|
+
variant: "secondary",
|
|
3633
|
+
size: "small",
|
|
3634
|
+
onClick: onSortToggle,
|
|
3635
|
+
disabled: loading,
|
|
3636
|
+
children: [sortOrder === "desc" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ArrowDownAZ, { className: "h-4 w-4" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ArrowUpAZ, { className: "h-4 w-4" }), sortOrder === "desc" ? "Newest" : "Oldest"]
|
|
3637
|
+
})
|
|
3638
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContent, { children: sortOrder === "desc" ? "Showing newest first" : "Showing oldest first" })] }),
|
|
3639
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Tooltip, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipTrigger, {
|
|
3640
|
+
asChild: true,
|
|
3641
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button, {
|
|
3642
|
+
variant: "secondary",
|
|
3643
|
+
size: "small",
|
|
3644
|
+
onClick: onRefresh,
|
|
3645
|
+
disabled: loading,
|
|
3646
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(RefreshCw, { className: loading ? "animate-spin" : "" }), "Refresh"]
|
|
3647
|
+
})
|
|
3648
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContent, { children: "Note that this resets pages" })] })
|
|
3649
|
+
]
|
|
3650
|
+
})]
|
|
3651
|
+
});
|
|
3652
|
+
}
|
|
3653
|
+
/** Workflow runs, loading further pages from the server as the list scrolls. */
|
|
3654
|
+
function RunsTable({ onRunClick }) {
|
|
3655
|
+
const [searchParams] = useSearchParams();
|
|
3656
|
+
const handleWorkflowFilter = useWorkflowFilter();
|
|
3657
|
+
const handleStatusFilter = useStatusFilter();
|
|
3658
|
+
const rawStatus = searchParams.get("status");
|
|
3659
|
+
const validStatuses = Object.keys(statusMap);
|
|
3660
|
+
const status = rawStatus === "all" || rawStatus && validStatuses.includes(rawStatus) ? rawStatus : void 0;
|
|
3661
|
+
const workflowNameFilter = searchParams.get("workflow");
|
|
3662
|
+
const [sortOrder, setSortOrder] = (0, import_react.useState)("desc");
|
|
3663
|
+
const [lastRefreshTime, setLastRefreshTime] = (0, import_react.useState)(() => /* @__PURE__ */ new Date());
|
|
3664
|
+
const [hasLoadedOnce, setHasLoadedOnce] = (0, import_react.useState)(false);
|
|
3665
|
+
const [seenWorkflowNames, setSeenWorkflowNames] = (0, import_react.useState)(/* @__PURE__ */ new Set());
|
|
3666
|
+
const { items: runs, error, isLoading, isLoadingMore, hasMore, loadMore, reload } = useWorkflowRunsInfinite({
|
|
3667
|
+
sortOrder,
|
|
3668
|
+
workflowName: workflowNameFilter === "all" ? void 0 : workflowNameFilter,
|
|
3669
|
+
status: status === "all" ? void 0 : status
|
|
3670
|
+
});
|
|
3671
|
+
const [scrollRoot, setScrollRoot] = (0, import_react.useState)(null);
|
|
3672
|
+
const sentinelRef = useLoadMoreOnScroll(loadMore, {
|
|
3673
|
+
hasMore,
|
|
3674
|
+
isLoadingMore,
|
|
3675
|
+
root: scrollRoot
|
|
3676
|
+
});
|
|
3677
|
+
const selection = useTableSelection({ getItemId: (run) => run.runId });
|
|
3678
|
+
const [isBulkCancelling, setIsBulkCancelling] = (0, import_react.useState)(false);
|
|
3679
|
+
const [isBulkReenqueuing, setIsBulkReenqueuing] = (0, import_react.useState)(false);
|
|
3680
|
+
(0, import_react.useEffect)(() => {
|
|
3681
|
+
if (runs.length > 0) {
|
|
3682
|
+
const newNames = new Set(runs.map((run) => run.workflowName));
|
|
3683
|
+
setSeenWorkflowNames((prev) => {
|
|
3684
|
+
const updated = new Set(prev);
|
|
3685
|
+
for (const name of newNames) updated.add(name);
|
|
3686
|
+
return updated;
|
|
3687
|
+
});
|
|
3688
|
+
}
|
|
3689
|
+
}, [runs]);
|
|
3690
|
+
const loading = isLoading;
|
|
3691
|
+
(0, import_react.useEffect)(() => {
|
|
3692
|
+
if (!loading && !hasLoadedOnce) setHasLoadedOnce(true);
|
|
3693
|
+
}, [loading, hasLoadedOnce]);
|
|
3694
|
+
(0, import_react.useEffect)(() => {
|
|
3695
|
+
setHasLoadedOnce(false);
|
|
3696
|
+
}, [
|
|
3697
|
+
workflowNameFilter,
|
|
3698
|
+
status,
|
|
3699
|
+
sortOrder
|
|
3700
|
+
]);
|
|
3701
|
+
const onReload = (0, import_react.useCallback)(() => {
|
|
3702
|
+
setLastRefreshTime(() => /* @__PURE__ */ new Date());
|
|
3703
|
+
setHasLoadedOnce(false);
|
|
3704
|
+
reload();
|
|
3705
|
+
}, [reload]);
|
|
3706
|
+
const selectedRuns = (0, import_react.useMemo)(() => {
|
|
3707
|
+
return runs.filter((run) => selection.selectedIds.has(run.runId));
|
|
3708
|
+
}, [runs, selection.selectedIds]);
|
|
3709
|
+
const cancellableSelectedRuns = (0, import_react.useMemo)(() => {
|
|
3710
|
+
return selectedRuns.filter((run) => run.status === "pending" || run.status === "running");
|
|
3711
|
+
}, [selectedRuns]);
|
|
3712
|
+
const hasCancellableSelection = cancellableSelectedRuns.length > 0;
|
|
3713
|
+
const exceedsBulkCancelLimit = cancellableSelectedRuns.length > 500;
|
|
3714
|
+
const handleBulkCancel = (0, import_react.useCallback)(async () => {
|
|
3715
|
+
if (isBulkCancelling || cancellableSelectedRuns.length === 0 || cancellableSelectedRuns.length > 500) return;
|
|
3716
|
+
setIsBulkCancelling(true);
|
|
3717
|
+
try {
|
|
3718
|
+
const { summary, results } = await unwrapOrThrow(rpc("bulkCancelRuns", { runIds: cancellableSelectedRuns.map((run) => run.runId) }));
|
|
3719
|
+
const parts = [];
|
|
3720
|
+
if (summary.cancelled > 0) parts.push(`${summary.cancelled} cancelled`);
|
|
3721
|
+
if (summary.alreadyCancelled > 0) parts.push(`${summary.alreadyCancelled} already cancelled`);
|
|
3722
|
+
if (summary.notCancellable > 0) parts.push(`${summary.notCancellable} not cancellable`);
|
|
3723
|
+
if (summary.notFound > 0) parts.push(`${summary.notFound} not found`);
|
|
3724
|
+
if (summary.failed > 0) parts.push(`${summary.failed} failed`);
|
|
3725
|
+
const message = parts.join(", ") || "No runs cancelled";
|
|
3726
|
+
const severity = bulkCancelToastSeverity(summary);
|
|
3727
|
+
if (severity === "error") toast.error(message);
|
|
3728
|
+
else if (severity === "warning") toast.warning(message);
|
|
3729
|
+
else toast.success(message);
|
|
3730
|
+
for (const result of results) if (!shouldRetainSelectionAfterBulkCancel(result)) selection.deselectById(result.runId);
|
|
3731
|
+
onReload();
|
|
3732
|
+
} catch (err) {
|
|
3733
|
+
toast.error("Failed to cancel runs", { description: err instanceof Error ? err.message : "Unknown error" });
|
|
3734
|
+
} finally {
|
|
3735
|
+
setIsBulkCancelling(false);
|
|
3736
|
+
}
|
|
3737
|
+
}, [
|
|
3738
|
+
cancellableSelectedRuns,
|
|
3739
|
+
isBulkCancelling,
|
|
3740
|
+
selection,
|
|
3741
|
+
onReload
|
|
3742
|
+
]);
|
|
3743
|
+
const handleBulkReenqueue = (0, import_react.useCallback)(async () => {
|
|
3744
|
+
if (isBulkReenqueuing || selectedRuns.length === 0) return;
|
|
3745
|
+
setIsBulkReenqueuing(true);
|
|
3746
|
+
try {
|
|
3747
|
+
const results = await Promise.allSettled(selectedRuns.map((run) => unwrapOrThrow(rpc("reenqueueRun", { runId: run.runId }))));
|
|
3748
|
+
const succeeded = results.filter((r) => r.status === "fulfilled").length;
|
|
3749
|
+
const failed = results.filter((r) => r.status === "rejected").length;
|
|
3750
|
+
if (failed === 0) toast.success(`Re-enqueued ${succeeded} run${succeeded !== 1 ? "s" : ""}`);
|
|
3751
|
+
else if (succeeded === 0) toast.error(`Failed to re-enqueue ${failed} run${failed !== 1 ? "s" : ""}`);
|
|
3752
|
+
else toast.warning(`Re-enqueued ${succeeded} run${succeeded !== 1 ? "s" : ""}, ${failed} failed`);
|
|
3753
|
+
selection.clearSelection();
|
|
3754
|
+
onReload();
|
|
3755
|
+
} catch (err) {
|
|
3756
|
+
toast.error("Failed to re-enqueue runs", { description: err instanceof Error ? err.message : "Unknown error" });
|
|
3757
|
+
} finally {
|
|
3758
|
+
setIsBulkReenqueuing(false);
|
|
3759
|
+
}
|
|
3760
|
+
}, [
|
|
3761
|
+
selectedRuns,
|
|
3762
|
+
isBulkReenqueuing,
|
|
3763
|
+
selection,
|
|
3764
|
+
onReload
|
|
3765
|
+
]);
|
|
3766
|
+
const toggleSortOrder = () => {
|
|
3767
|
+
setSortOrder((prev) => prev === "desc" ? "asc" : "desc");
|
|
3768
|
+
};
|
|
3769
|
+
(0, import_react.useEffect)(() => {
|
|
3770
|
+
const handleVisibilityChange = () => {
|
|
3771
|
+
if (document.visibilityState === "visible" && lastRefreshTime) {
|
|
3772
|
+
if (Date.now() - lastRefreshTime.getTime() >= 1e4) onReload();
|
|
3773
|
+
}
|
|
3774
|
+
};
|
|
3775
|
+
document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
3776
|
+
return () => {
|
|
3777
|
+
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
|
3778
|
+
};
|
|
3779
|
+
}, [lastRefreshTime, onReload]);
|
|
3780
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
|
|
3781
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(FilterControls, {
|
|
3782
|
+
workflowNameFilter,
|
|
3783
|
+
status,
|
|
3784
|
+
seenWorkflowNames,
|
|
3785
|
+
sortOrder,
|
|
3786
|
+
loading,
|
|
3787
|
+
onWorkflowChange: handleWorkflowFilter,
|
|
3788
|
+
onStatusChange: handleStatusFilter,
|
|
3789
|
+
onSortToggle: toggleSortOrder,
|
|
3790
|
+
onRefresh: onReload,
|
|
3791
|
+
lastRefreshTime
|
|
3792
|
+
}),
|
|
3793
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Card, {
|
|
3794
|
+
className: "overflow-hidden mt-4 bg-background",
|
|
3795
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(CardContent, {
|
|
3796
|
+
ref: setScrollRoot,
|
|
3797
|
+
className: "p-0 max-h-[calc(100vh-280px)] overflow-auto",
|
|
3798
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Table, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHeader, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableRow, { children: [
|
|
3799
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHead, {
|
|
3800
|
+
className: "sticky top-0 bg-background z-10 border-b shadow-sm h-10 w-10",
|
|
3801
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Checkbox, {
|
|
3802
|
+
checked: selection.isAllSelected(runs),
|
|
3803
|
+
indeterminate: selection.isSomeSelected(runs),
|
|
3804
|
+
onCheckedChange: () => selection.toggleSelectAll(runs),
|
|
3805
|
+
"aria-label": "Select all runs",
|
|
3806
|
+
disabled: !runs.length
|
|
3807
|
+
})
|
|
3808
|
+
}),
|
|
3809
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHead, {
|
|
3810
|
+
className: "sticky top-0 bg-background z-10 border-b shadow-sm h-10",
|
|
3811
|
+
children: "Workflow"
|
|
3812
|
+
}),
|
|
3813
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHead, {
|
|
3814
|
+
className: "sticky top-0 bg-background z-10 border-b shadow-sm h-10",
|
|
3815
|
+
children: "Run ID"
|
|
3816
|
+
}),
|
|
3817
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHead, {
|
|
3818
|
+
className: "sticky top-0 bg-background z-10 border-b shadow-sm h-10",
|
|
3819
|
+
children: "Status"
|
|
3820
|
+
}),
|
|
3821
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHead, {
|
|
3822
|
+
className: "sticky top-0 bg-background z-10 border-b shadow-sm h-10",
|
|
3823
|
+
children: "Started"
|
|
3824
|
+
}),
|
|
3825
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHead, {
|
|
3826
|
+
className: "sticky top-0 bg-background z-10 border-b shadow-sm h-10",
|
|
3827
|
+
children: "Completed"
|
|
3828
|
+
}),
|
|
3829
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHead, { className: "sticky top-0 bg-background z-10 border-b shadow-sm h-10 w-10" })
|
|
3830
|
+
] }) }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableBody, { children: [error ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableRow, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
|
|
3831
|
+
colSpan: 7,
|
|
3832
|
+
className: "h-[400px]",
|
|
3833
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
3834
|
+
className: "flex items-center justify-center h-full",
|
|
3835
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Alert, {
|
|
3836
|
+
variant: "destructive",
|
|
3837
|
+
className: "max-w-md",
|
|
3838
|
+
children: [
|
|
3839
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(CircleAlert, { className: "h-4 w-4" }),
|
|
3840
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertTitle, { children: "Error loading runs" }),
|
|
3841
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertDescription, { children: getErrorMessage(error) })
|
|
3842
|
+
]
|
|
3843
|
+
})
|
|
3844
|
+
})
|
|
3845
|
+
}) }) : loading && !hasLoadedOnce ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableRow, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
|
|
3846
|
+
colSpan: 7,
|
|
3847
|
+
className: "h-[400px]",
|
|
3848
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
3849
|
+
className: "flex items-center justify-center h-full",
|
|
3850
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoaderCircle, { className: "h-8 w-8 animate-spin text-muted-foreground" })
|
|
3851
|
+
})
|
|
3852
|
+
}) }) : runs.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableRow, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
|
|
3853
|
+
colSpan: 7,
|
|
3854
|
+
className: "h-[400px]",
|
|
3855
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
3856
|
+
className: "text-sm text-center text-muted-foreground flex flex-col items-center justify-center gap-3 h-full",
|
|
3857
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
3858
|
+
className: "text-sm",
|
|
3859
|
+
children: "No workflow runs found."
|
|
3860
|
+
})
|
|
3861
|
+
})
|
|
3862
|
+
}) }) : runs.map((run) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableRow, {
|
|
3863
|
+
className: "cursor-pointer group relative",
|
|
3864
|
+
onClick: () => onRunClick(run.runId),
|
|
3865
|
+
"data-selected": selection.isSelected(run),
|
|
3866
|
+
children: [
|
|
3867
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
|
|
3868
|
+
className: "py-2",
|
|
3869
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Checkbox, {
|
|
3870
|
+
checked: selection.isSelected(run),
|
|
3871
|
+
onCheckedChange: () => selection.toggleSelection(run),
|
|
3872
|
+
"aria-label": `Select run ${run.runId}`
|
|
3873
|
+
})
|
|
3874
|
+
}),
|
|
3875
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
|
|
3876
|
+
className: "py-2",
|
|
3877
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CopyableText, {
|
|
3878
|
+
text: run.workflowName,
|
|
3879
|
+
overlay: true,
|
|
3880
|
+
children: parseWorkflowName(run.workflowName)?.shortName || "?"
|
|
3881
|
+
})
|
|
3882
|
+
}),
|
|
3883
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
|
|
3884
|
+
className: "font-mono text-xs py-2",
|
|
3885
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CopyableText, {
|
|
3886
|
+
text: run.runId,
|
|
3887
|
+
overlay: true,
|
|
3888
|
+
children: run.runId
|
|
3889
|
+
})
|
|
3890
|
+
}),
|
|
3891
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
|
|
3892
|
+
className: "py-2",
|
|
3893
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusBadge, {
|
|
3894
|
+
status: run.status,
|
|
3895
|
+
context: run,
|
|
3896
|
+
durationMs: run.startedAt ? (run.completedAt ? new Date(run.completedAt).getTime() : Date.now()) - new Date(run.startedAt).getTime() : void 0
|
|
3897
|
+
})
|
|
3898
|
+
}),
|
|
3899
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
|
|
3900
|
+
className: "py-2 text-muted-foreground text-xs",
|
|
3901
|
+
children: run.startedAt ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RelativeTime, { date: run.startedAt }) : "-"
|
|
3902
|
+
}),
|
|
3903
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
|
|
3904
|
+
className: "py-2 text-muted-foreground text-xs",
|
|
3905
|
+
children: run.completedAt ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RelativeTime, { date: run.completedAt }) : "-"
|
|
3906
|
+
}),
|
|
3907
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
|
|
3908
|
+
className: "py-2",
|
|
3909
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LazyDropdownMenu, {
|
|
3910
|
+
runId: run.runId,
|
|
3911
|
+
runStatus: run.status,
|
|
3912
|
+
onSuccess: onReload
|
|
3913
|
+
})
|
|
3914
|
+
})
|
|
3915
|
+
]
|
|
3916
|
+
}, run.runId)), isLoadingMore && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableRow, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
|
|
3917
|
+
colSpan: 7,
|
|
3918
|
+
className: "py-3",
|
|
3919
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
3920
|
+
className: "flex items-center justify-center gap-2 text-sm text-muted-foreground",
|
|
3921
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoaderCircle, { className: "h-4 w-4 animate-spin" }), "Loading more runs…"]
|
|
3922
|
+
})
|
|
3923
|
+
}) })] })] }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
3924
|
+
ref: sentinelRef,
|
|
3925
|
+
"aria-hidden": true,
|
|
3926
|
+
className: "h-px"
|
|
3927
|
+
})]
|
|
3928
|
+
})
|
|
3929
|
+
}),
|
|
3930
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
3931
|
+
className: "flex items-center justify-between mt-4 text-sm text-muted-foreground",
|
|
3932
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: runs.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
3933
|
+
"Showing ",
|
|
3934
|
+
runs.length,
|
|
3935
|
+
" run",
|
|
3936
|
+
runs.length === 1 ? "" : "s",
|
|
3937
|
+
!hasMore && !loading ? " · end of list" : ""
|
|
3938
|
+
] }) })
|
|
3939
|
+
}),
|
|
3940
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectionBar, {
|
|
3941
|
+
selectionCount: selection.selectionCount,
|
|
3942
|
+
onClearSelection: selection.clearSelection,
|
|
3943
|
+
itemLabel: "runs",
|
|
3944
|
+
actions: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Tooltip, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipTrigger, {
|
|
3945
|
+
asChild: true,
|
|
3946
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button, {
|
|
3947
|
+
variant: "tertiary",
|
|
3948
|
+
size: "small",
|
|
3949
|
+
className: "h-7 text-primary-foreground hover:bg-primary-foreground/10 hover:text-primary-foreground",
|
|
3950
|
+
onClick: handleBulkReenqueue,
|
|
3951
|
+
disabled: isBulkReenqueuing || selectedRuns.length === 0,
|
|
3952
|
+
children: [isBulkReenqueuing ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoaderCircle, { className: "h-4 w-4 mr-1 animate-spin" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Zap, { className: "h-4 w-4 mr-1" }), isBulkReenqueuing ? "Re-enqueuing..." : "Re-enqueue"]
|
|
3953
|
+
})
|
|
3954
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContent, { children: "Re-enqueue the workflow orchestration layer for selected runs. Useful if workflows appear stuck." })] }), hasCancellableSelection && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Tooltip, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipTrigger, {
|
|
3955
|
+
asChild: true,
|
|
3956
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
3957
|
+
className: "inline-flex",
|
|
3958
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button, {
|
|
3959
|
+
variant: "tertiary",
|
|
3960
|
+
size: "small",
|
|
3961
|
+
className: "h-7 text-primary-foreground hover:bg-primary-foreground/10 hover:text-primary-foreground",
|
|
3962
|
+
onClick: handleBulkCancel,
|
|
3963
|
+
disabled: isBulkCancelling || exceedsBulkCancelLimit,
|
|
3964
|
+
children: [
|
|
3965
|
+
isBulkCancelling ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoaderCircle, { className: "h-4 w-4 mr-1 animate-spin" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CircleX, { className: "h-4 w-4 mr-1" }),
|
|
3966
|
+
"Cancel",
|
|
3967
|
+
" ",
|
|
3968
|
+
cancellableSelectedRuns.length !== selection.selectionCount ? `${cancellableSelectedRuns.length} ` : "",
|
|
3969
|
+
isBulkCancelling ? "cancelling..." : ""
|
|
3970
|
+
]
|
|
3971
|
+
})
|
|
3972
|
+
})
|
|
3973
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContent, { children: exceedsBulkCancelLimit ? `Select up to 500 runs at a time.` : "Cancel the selected pending and running runs." })] })] })
|
|
3974
|
+
})
|
|
3975
|
+
] });
|
|
3976
|
+
}
|
|
3977
|
+
// app/routes/home.tsx
|
|
3978
|
+
var home_default = withComponentProps(function Home() {
|
|
3979
|
+
const navigate = useNavigate();
|
|
3980
|
+
const [searchParams, setSearchParams] = useSearchParams();
|
|
3981
|
+
const sidebar = searchParams.get("sidebar");
|
|
3982
|
+
const hookId = searchParams.get("hookId");
|
|
3983
|
+
const tab = searchParams.get("tab") || "runs";
|
|
3984
|
+
const setTab = (value) => {
|
|
3985
|
+
setSearchParams((prev) => {
|
|
3986
|
+
prev.set("tab", value);
|
|
3987
|
+
return prev;
|
|
3988
|
+
}, { replace: true });
|
|
3989
|
+
};
|
|
3990
|
+
const selectedHookId = sidebar === "hook" && hookId ? hookId : void 0;
|
|
3991
|
+
const handleRunClick = (runId) => navigate(`/run/${runId}`);
|
|
3992
|
+
const handleHookSelect = (hookId, runId) => {
|
|
3993
|
+
if (hookId) navigate(`/run/${runId}?sidebar=hook&hookId=${hookId}`);
|
|
3994
|
+
else navigate(`/run/${runId}`);
|
|
3995
|
+
};
|
|
3996
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
3997
|
+
className: "max-w-7xl mx-auto px-4",
|
|
3998
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Tabs, {
|
|
3999
|
+
value: tab,
|
|
4000
|
+
onValueChange: setTab,
|
|
4001
|
+
className: "w-full",
|
|
4002
|
+
children: [
|
|
4003
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TabsList, {
|
|
4004
|
+
className: "mb-4",
|
|
4005
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TabsTrigger, {
|
|
4006
|
+
value: "runs",
|
|
4007
|
+
children: "Runs"
|
|
4008
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TabsTrigger, {
|
|
4009
|
+
value: "hooks",
|
|
4010
|
+
children: "Hooks"
|
|
4011
|
+
})]
|
|
4012
|
+
}),
|
|
4013
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TabsContent, {
|
|
4014
|
+
value: "runs",
|
|
4015
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorBoundary, {
|
|
4016
|
+
title: "Failed to load workflow runs",
|
|
4017
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RunsTable, { onRunClick: handleRunClick })
|
|
4018
|
+
})
|
|
4019
|
+
}),
|
|
4020
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TabsContent, {
|
|
4021
|
+
value: "hooks",
|
|
4022
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorBoundary, {
|
|
4023
|
+
title: "Failed to load hooks",
|
|
4024
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(HooksTable, {
|
|
4025
|
+
onHookClick: handleHookSelect,
|
|
4026
|
+
selectedHookId
|
|
4027
|
+
})
|
|
4028
|
+
})
|
|
4029
|
+
})
|
|
4030
|
+
]
|
|
4031
|
+
})
|
|
4032
|
+
});
|
|
4033
|
+
});
|
|
4034
|
+
export { home_default as default };
|