@powerhousedao/workflow 6.2.3-dev.69 → 6.2.3-dev.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/BlockSelector-DFX-DZHl.js +3243 -0
- package/dist/browser/BlockSelector-DFX-DZHl.js.map +1 -0
- package/dist/browser/PieceMarkdown-U6OUTwRi.js +66 -0
- package/dist/browser/PieceMarkdown-U6OUTwRi.js.map +1 -0
- package/dist/browser/{connection-5ri_Ex8F.js → connection-Ci_pI3kD.js} +2 -2
- package/dist/browser/{connection-5ri_Ex8F.js.map → connection-Ci_pI3kD.js.map} +1 -1
- package/dist/browser/{connection-form-FoGRZSTT.js → connection-form-BuW6qOAF.js} +6 -5
- package/dist/browser/{connection-form-FoGRZSTT.js.map → connection-form-BuW6qOAF.js.map} +1 -1
- package/dist/browser/data-tree-BLn565V5.js +63 -0
- package/dist/browser/data-tree-BLn565V5.js.map +1 -0
- package/dist/browser/document-models/connection/index.js +2 -2
- package/dist/browser/document-models/index.js +3 -3
- package/dist/browser/document-models/workflow/index.js +2 -2
- package/dist/browser/{document-models-DAAo3Bln.js → document-models-B2IDRvBZ.js} +3 -3
- package/dist/browser/{document-models-DAAo3Bln.js.map → document-models-B2IDRvBZ.js.map} +1 -1
- package/dist/browser/{editor-ioEkaHLb.js → editor-B1-_KRbr.js} +10 -11
- package/dist/browser/{editor-ioEkaHLb.js.map → editor-B1-_KRbr.js.map} +1 -1
- package/dist/browser/editor-DBcq58Fr.js +6847 -0
- package/dist/browser/editor-DBcq58Fr.js.map +1 -0
- package/dist/browser/{editor-CX_SY6s_.js → editor-DPGuck1V.js} +8 -8
- package/dist/browser/editor-DPGuck1V.js.map +1 -0
- package/dist/browser/editors/connection-editor/module.js +1 -1
- package/dist/browser/editors/connection-editor/module.js.map +1 -1
- package/dist/browser/editors/runtime/index.js +1 -1
- package/dist/browser/editors/workflow-editor/module.js +1 -1
- package/dist/browser/editors/workflow-editor/module.js.map +1 -1
- package/dist/browser/editors/workflow-studio/module.js +1 -1
- package/dist/browser/index.js +5 -4
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/{module-DxQBeqBh.js → module-DFCANOuI.js} +3 -3
- package/dist/browser/{module-DxQBeqBh.js.map → module-DFCANOuI.js.map} +1 -1
- package/dist/browser/{module-DIQ3tQ2M.js → module-FuSfFXPT.js} +2 -2
- package/dist/browser/{module-DIQ3tQ2M.js.map → module-FuSfFXPT.js.map} +1 -1
- package/dist/browser/reactor/index.js +2 -2
- package/dist/browser/rolldown-runtime-D7D4PA-g.js +13 -0
- package/dist/browser/runtime-queries-C9SoXGm2.js +791 -0
- package/dist/browser/runtime-queries-C9SoXGm2.js.map +1 -0
- package/dist/browser/trigger-text-B2mo1fiB.js +493 -0
- package/dist/browser/trigger-text-B2mo1fiB.js.map +1 -0
- package/dist/browser/upgrade-manifests-B62uqKVp.js +8 -0
- package/dist/browser/{upgrade-manifests-CAE3ivDp.js.map → upgrade-manifests-B62uqKVp.js.map} +1 -1
- package/dist/browser/{workflow-CP_X_Njm.js → workflow-DjTleFFO.js} +2 -2
- package/dist/browser/{workflow-CP_X_Njm.js.map → workflow-DjTleFFO.js.map} +1 -1
- package/dist/node/{BlockSelector-DfCL1GAk.mjs → BlockSelector-CF4xOFNG.mjs} +2 -2
- package/dist/node/{BlockSelector-DfCL1GAk.mjs.map → BlockSelector-CF4xOFNG.mjs.map} +1 -1
- package/dist/node/{PieceMarkdown-BMhBGa4t.mjs → PieceMarkdown-DwpCBISY.mjs} +2 -2
- package/dist/node/{PieceMarkdown-BMhBGa4t.mjs.map → PieceMarkdown-DwpCBISY.mjs.map} +1 -1
- package/dist/node/{connection-form-BbWKMBHt.mjs → connection-form-CYlSCGTK.mjs} +3 -3
- package/dist/node/{connection-form-BbWKMBHt.mjs.map → connection-form-CYlSCGTK.mjs.map} +1 -1
- package/dist/node/{connection-DJFsS9rQ.mjs → connection-i6ISRY0F.mjs} +2 -2
- package/dist/node/{connection-DJFsS9rQ.mjs.map → connection-i6ISRY0F.mjs.map} +1 -1
- package/dist/node/{data-tree-DAlZbha-.mjs → data-tree-DmhiI_Jk.mjs} +3 -3
- package/dist/node/{data-tree-DAlZbha-.mjs.map → data-tree-DmhiI_Jk.mjs.map} +1 -1
- package/dist/node/document-models/connection/index.mjs +2 -2
- package/dist/node/document-models/index.mjs +3 -3
- package/dist/node/document-models/workflow/index.mjs +2 -2
- package/dist/node/{editor-tHhPmmR_.mjs → editor-B653s9Xv.mjs} +15 -15
- package/dist/node/editor-B653s9Xv.mjs.map +1 -0
- package/dist/node/{editor-CAfTlm6l.mjs → editor-C6B1IKNB.mjs} +9 -10
- package/dist/node/{editor-CAfTlm6l.mjs.map → editor-C6B1IKNB.mjs.map} +1 -1
- package/dist/node/{editor-mRrsuvh4.mjs → editor-k8zOuO2n.mjs} +6 -6
- package/dist/node/editor-k8zOuO2n.mjs.map +1 -0
- package/dist/node/editors/connection-editor/module.mjs +1 -1
- package/dist/node/editors/connection-editor/module.mjs.map +1 -1
- package/dist/node/editors/workflow-editor/module.mjs +1 -1
- package/dist/node/editors/workflow-editor/module.mjs.map +1 -1
- package/dist/node/editors/workflow-studio/module.mjs +1 -1
- package/dist/node/{graphql-BGVLRhC1.mjs → graphql-D76E1YiQ.mjs} +2 -2
- package/dist/node/{graphql-BGVLRhC1.mjs.map → graphql-D76E1YiQ.mjs.map} +1 -1
- package/dist/node/index.mjs +3 -3
- package/dist/node/{module-DPg8IYIn.mjs → module-DV3LLvxo.mjs} +2 -2
- package/dist/node/{module-DPg8IYIn.mjs.map → module-DV3LLvxo.mjs.map} +1 -1
- package/dist/node/{module-Bl_4mnxR.mjs → module-weVJEMpP.mjs} +2 -2
- package/dist/node/{module-Bl_4mnxR.mjs.map → module-weVJEMpP.mjs.map} +1 -1
- package/dist/node/pieces/reactor/descriptor.json +1 -1
- package/dist/node/pieces/reactor/package.json +1 -1
- package/dist/{browser/rolldown-runtime-DC62tzP2.js → node/rolldown-runtime-B4iAMlE-.mjs} +3 -1
- package/dist/node/trigger-text-D98Ip9qF.mjs +492 -0
- package/dist/node/trigger-text-D98Ip9qF.mjs.map +1 -0
- package/dist/node/upgrade-manifests-CO9zzPnE.mjs +8 -0
- package/dist/node/{upgrade-manifests-7SFwDrhd.mjs.map → upgrade-manifests-CO9zzPnE.mjs.map} +1 -1
- package/dist/node/{workflow-CPlqsc5D.mjs → workflow-BS5m4jtr.mjs} +2 -2
- package/dist/node/{workflow-CPlqsc5D.mjs.map → workflow-BS5m4jtr.mjs.map} +1 -1
- package/dist/powerhouse.manifest.json +1 -1
- package/dist/style.css +3 -2903
- package/dist/types/editors/connection-editor/editor.d.ts +3 -1
- package/dist/types/editors/connection-editor/editor.d.ts.map +1 -1
- package/dist/types/editors/connection-editor/module.d.ts +2 -1
- package/dist/types/editors/connection-editor/module.d.ts.map +1 -1
- package/dist/types/editors/workflow-editor/editor.d.ts +3 -1
- package/dist/types/editors/workflow-editor/editor.d.ts.map +1 -1
- package/dist/types/editors/workflow-editor/module.d.ts +2 -1
- package/dist/types/editors/workflow-editor/module.d.ts.map +1 -1
- package/package.json +8 -8
- package/dist/browser/BlockSelector-BMI6RtS_.js +0 -8596
- package/dist/browser/BlockSelector-BMI6RtS_.js.map +0 -1
- package/dist/browser/PieceMarkdown-B8EEaQgT.js +0 -21435
- package/dist/browser/PieceMarkdown-B8EEaQgT.js.map +0 -1
- package/dist/browser/assets/entry-oIniX8Dq.js +0 -418
- package/dist/browser/assets/projection-entry-CdlLTrjU.js +0 -482
- package/dist/browser/block-type-kX-27vVt.js +0 -44
- package/dist/browser/block-type-kX-27vVt.js.map +0 -1
- package/dist/browser/data-tree-Bae8a2NP.js +0 -1896
- package/dist/browser/data-tree-Bae8a2NP.js.map +0 -1
- package/dist/browser/editor-CX_SY6s_.js.map +0 -1
- package/dist/browser/editor-DUtYefNU.js +0 -17626
- package/dist/browser/editor-DUtYefNU.js.map +0 -1
- package/dist/browser/graphql-Cr1ia6fo.js +0 -2474
- package/dist/browser/graphql-Cr1ia6fo.js.map +0 -1
- package/dist/browser/icon-components-CJ4I3Y6Y-DQj9fo1T.js +0 -3188
- package/dist/browser/icon-components-CJ4I3Y6Y-DQj9fo1T.js.map +0 -1
- package/dist/browser/runtime-queries-DehIdatq.js +0 -2615
- package/dist/browser/runtime-queries-DehIdatq.js.map +0 -1
- package/dist/browser/trigger-text-Cepiqt6x.js +0 -6131
- package/dist/browser/trigger-text-Cepiqt6x.js.map +0 -1
- package/dist/browser/upgrade-manifests-CAE3ivDp.js +0 -8
- package/dist/node/editor-mRrsuvh4.mjs.map +0 -1
- package/dist/node/editor-tHhPmmR_.mjs.map +0 -1
- package/dist/node/icon-components-CJ4I3Y6Y-DyXkyBjD.mjs +0 -3188
- package/dist/node/icon-components-CJ4I3Y6Y-DyXkyBjD.mjs.map +0 -1
- package/dist/node/rolldown-runtime-BMI-E3GI.mjs +0 -44
- package/dist/node/trigger-text-nrUcI93G.mjs +0 -7327
- package/dist/node/trigger-text-nrUcI93G.mjs.map +0 -1
- package/dist/node/upgrade-manifests-7SFwDrhd.mjs +0 -8
|
@@ -0,0 +1,3243 @@
|
|
|
1
|
+
import { A as MANUAL_TRIGGER, D as ASSERT_BLOCK, E as isSyncingError, F as WEBHOOK_TRIGGER, I as isCoreBlock, L as pinBlock, M as SCHEDULE_TRIGGER, O as BRANCH_BLOCK, S as createRuntimeClient, _ as runtimeKeys, a as pieceActionsQuery, c as runQuery, d as secretStatQuery, g as queryKind, h as blockRefKey, m as SHARED_STALE_MS, n as catalogQuery, o as pieceTriggersQuery, p as RESOLVER_STALE_MS, r as createRuntimeQueryClient, s as runPagesQuery, u as runsQuery, z as stepBlock } from "./runtime-queries-C9SoXGm2.js";
|
|
2
|
+
import { DEFAULT_SWITCHBOARD_URL, parseDriveUrl, subgraphUrlFromGraphqlUrl, useDefaultDrivesUrl, useSearchParams, useSelectedDriveSafe, useSetSearchParams, useSyncList } from "@powerhousedao/reactor-browser";
|
|
3
|
+
import { blockKey, compareVersions } from "@powerhousedao/pieces-framework/block-type";
|
|
4
|
+
import { CORE_PIECE_NAME, checkTriggerStrategy, scheduleConfigIssue } from "@powerhousedao/pieces-framework/workflow";
|
|
5
|
+
import { QueryClient, keepPreviousData, useInfiniteQuery, useQueries, useQuery } from "@tanstack/react-query";
|
|
6
|
+
import { Component, Fragment, createContext, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
7
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { createPortal } from "react-dom";
|
|
9
|
+
import { DriveCollectionId } from "@powerhousedao/reactor";
|
|
10
|
+
//#region editors/shared/DocumentErrorBoundary.tsx
|
|
11
|
+
/** Best-effort message for anything thrown, without stringifying an object. */
|
|
12
|
+
function errorMessage(error) {
|
|
13
|
+
if (error instanceof Error) return error.message;
|
|
14
|
+
if (typeof error === "string") return error;
|
|
15
|
+
return "Unknown error";
|
|
16
|
+
}
|
|
17
|
+
/** Inline "could not load" panel, also used for hook-level (non-thrown) failures. */
|
|
18
|
+
function DocumentLoadError(props) {
|
|
19
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
20
|
+
className: "m-3 rounded border border-solid border-wf-fail/40 bg-wf-fail/10 p-3",
|
|
21
|
+
children: [
|
|
22
|
+
/* @__PURE__ */ jsx("p", {
|
|
23
|
+
className: "text-sm font-medium text-wf-fail",
|
|
24
|
+
children: props.title ?? "This document could not be loaded"
|
|
25
|
+
}),
|
|
26
|
+
props.label ? /* @__PURE__ */ jsx("p", {
|
|
27
|
+
className: "mt-0.5 text-xs text-wf-fail",
|
|
28
|
+
children: props.label
|
|
29
|
+
}) : null,
|
|
30
|
+
props.documentId ? /* @__PURE__ */ jsx("p", {
|
|
31
|
+
className: "mt-0.5 font-mono text-[11px] text-wf-fail",
|
|
32
|
+
children: props.documentId
|
|
33
|
+
}) : null,
|
|
34
|
+
/* @__PURE__ */ jsx("p", {
|
|
35
|
+
className: "mt-1 text-xs text-muted-foreground",
|
|
36
|
+
children: errorMessage(props.error)
|
|
37
|
+
}),
|
|
38
|
+
/* @__PURE__ */ jsxs("div", {
|
|
39
|
+
className: "mt-2 flex gap-2",
|
|
40
|
+
children: [props.onRetry ? /* @__PURE__ */ jsx("button", {
|
|
41
|
+
type: "button",
|
|
42
|
+
className: "rounded border border-solid border-wf-fail/40 px-2 py-0.5 text-xs font-medium text-wf-fail",
|
|
43
|
+
onClick: props.onRetry,
|
|
44
|
+
children: "Retry"
|
|
45
|
+
}) : null, props.onDismiss ? /* @__PURE__ */ jsx("button", {
|
|
46
|
+
type: "button",
|
|
47
|
+
className: "rounded border border-solid border-foreground/15 px-2 py-0.5 text-xs text-muted-foreground",
|
|
48
|
+
onClick: props.onDismiss,
|
|
49
|
+
children: "Dismiss"
|
|
50
|
+
}) : null]
|
|
51
|
+
})
|
|
52
|
+
]
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
var DocumentErrorBoundary = class extends Component {
|
|
56
|
+
state = {
|
|
57
|
+
error: void 0,
|
|
58
|
+
attempt: 0
|
|
59
|
+
};
|
|
60
|
+
static getDerivedStateFromError(error) {
|
|
61
|
+
return { error };
|
|
62
|
+
}
|
|
63
|
+
componentDidCatch(error, info) {
|
|
64
|
+
console.error(`Failed to render document ${this.props.documentId ?? "(unknown id)"}:`, error, info.componentStack);
|
|
65
|
+
}
|
|
66
|
+
retry = () => {
|
|
67
|
+
this.setState((state) => ({
|
|
68
|
+
error: void 0,
|
|
69
|
+
attempt: state.attempt + 1
|
|
70
|
+
}));
|
|
71
|
+
};
|
|
72
|
+
dismiss = () => {
|
|
73
|
+
this.setState({ error: void 0 });
|
|
74
|
+
this.props.onDismiss?.();
|
|
75
|
+
};
|
|
76
|
+
render() {
|
|
77
|
+
if (this.state.error !== void 0) return /* @__PURE__ */ jsx(DocumentLoadError, {
|
|
78
|
+
label: this.props.label,
|
|
79
|
+
documentId: this.props.documentId,
|
|
80
|
+
error: this.state.error,
|
|
81
|
+
onRetry: this.retry,
|
|
82
|
+
onDismiss: this.props.onDismiss ? this.dismiss : void 0
|
|
83
|
+
});
|
|
84
|
+
return /* @__PURE__ */ jsx(Fragment, { children: this.props.children }, this.state.attempt);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region editors/shared/icons.tsx
|
|
89
|
+
const ICON_PATHS = {
|
|
90
|
+
pencil: "M4 20h4L19 9l-4-4L4 16v4zM14 6l4 4",
|
|
91
|
+
trash: "M5 7h14M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3",
|
|
92
|
+
plus: "M12 5v14M5 12h14",
|
|
93
|
+
minus: "M5 12h14",
|
|
94
|
+
list: "M8 6h12M8 12h12M8 18h12M4 6h.01M4 12h.01M4 18h.01",
|
|
95
|
+
play: "M7 5v14l12-7z",
|
|
96
|
+
chevron: "M9 6l6 6-6 6",
|
|
97
|
+
chevronDown: "M6 9l6 6 6-6",
|
|
98
|
+
retry: "M4 12a8 8 0 1 0 2.3-5.7M4 4v4h4",
|
|
99
|
+
back: "M15 6l-6 6 6 6",
|
|
100
|
+
close: "M6 6l12 12M18 6L6 18",
|
|
101
|
+
check: "M5 12l5 5 9-10",
|
|
102
|
+
search: "M11 18a7 7 0 1 0 0-14 7 7 0 0 0 0 14zM20 20l-4-4",
|
|
103
|
+
braces: "M8 4c-2 0-3 1-3 3v2c0 1.5-1 3-2 3 1 0 2 1.5 2 3v2c0 2 1 3 3 3M16 4c2 0 3 1 3 3v2c0 1.5 1 3 2 3-1 0-2 1.5-2 3v2c0 2-1 3-3 3",
|
|
104
|
+
link: "M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1",
|
|
105
|
+
arrowRight: "M5 12h14M13 6l6 6-6 6",
|
|
106
|
+
alert: "M12 8v5M12 16.5v.01M10.3 4l-7.6 13.2A2 2 0 0 0 4.4 20h15.2a2 2 0 0 0 1.7-2.8L13.7 4a2 2 0 0 0-3.4 0z",
|
|
107
|
+
copy: "M9 9h10v10H9zM5 15V5h10",
|
|
108
|
+
sliders: "M4 7h10M18 7h2M4 17h4M12 17h8M14 5v4M8 15v4",
|
|
109
|
+
eye: "M2.5 12s3.5-6.5 9.5-6.5 9.5 6.5 9.5 6.5-3.5 6.5-9.5 6.5S2.5 12 2.5 12zM12 14.5a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5z",
|
|
110
|
+
eyeOff: "M3 3l18 18M10.6 5.6A10 10 0 0 1 12 5.5c6 0 9.5 6.5 9.5 6.5a17 17 0 0 1-3 3.7M6.6 6.6C4 8.3 2.5 12 2.5 12s3.5 6.5 9.5 6.5a9.6 9.6 0 0 0 4.4-1M9.9 9.9a3 3 0 0 0 4.2 4.2",
|
|
111
|
+
undo: "M9 14L4 9l5-5M4 9h10a6 6 0 0 1 0 12h-3",
|
|
112
|
+
redo: "M15 14l5-5-5-5M20 9H10a6 6 0 0 0 0 12h3",
|
|
113
|
+
clock: "M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18zM12 7v5l3 2",
|
|
114
|
+
bolt: "M13 3L5 13h6l-1 8 8-10h-6l1-8z",
|
|
115
|
+
branch: "M6 4v10M6 14a3 3 0 1 0 0 6 3 3 0 0 0 0-6zM18 4a3 3 0 1 0 0 6 3 3 0 0 0 0-6zM18 10c0 4-6 3-11 6",
|
|
116
|
+
lock: "M6 11h12v9H6zM8.5 11V8a3.5 3.5 0 0 1 7 0v3M12 15v2",
|
|
117
|
+
more: "M5 11a1 1 0 1 0 0 2 1 1 0 0 0 0-2zM12 11a1 1 0 1 0 0 2 1 1 0 0 0 0-2zM19 11a1 1 0 1 0 0 2 1 1 0 0 0 0-2z",
|
|
118
|
+
archive: "M4 5h16v4H4zM6 9v10h12V9M10 13h4"
|
|
119
|
+
};
|
|
120
|
+
function isIconName(name) {
|
|
121
|
+
return typeof name === "string" && name in ICON_PATHS;
|
|
122
|
+
}
|
|
123
|
+
function Icon(props) {
|
|
124
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
125
|
+
"aria-hidden": true,
|
|
126
|
+
viewBox: "0 0 24 24",
|
|
127
|
+
fill: "none",
|
|
128
|
+
stroke: "currentColor",
|
|
129
|
+
strokeWidth: 1.75,
|
|
130
|
+
strokeLinecap: "round",
|
|
131
|
+
strokeLinejoin: "round",
|
|
132
|
+
width: props.size,
|
|
133
|
+
height: props.size,
|
|
134
|
+
className: `shrink-0 ${props.size ? "" : "h-4 w-4"} ${props.className ?? ""}`,
|
|
135
|
+
children: /* @__PURE__ */ jsx("path", { d: ICON_PATHS[props.name] })
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region editors/shared/controls.tsx
|
|
140
|
+
const FOCUS_RING = "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40";
|
|
141
|
+
const BUTTON_SIZE = {
|
|
142
|
+
sm: "h-7 gap-1 rounded-md px-2 text-xs",
|
|
143
|
+
md: "h-8 gap-1.5 rounded-md px-3 text-[13px]"
|
|
144
|
+
};
|
|
145
|
+
const BUTTON_VARIANT = {
|
|
146
|
+
primary: "bg-primary text-primary-foreground hover:opacity-90",
|
|
147
|
+
secondary: "border border-solid border-foreground/15 bg-card text-foreground hover:bg-accent",
|
|
148
|
+
ghost: "text-muted-foreground hover:bg-accent hover:text-foreground",
|
|
149
|
+
danger: "text-wf-fail hover:bg-wf-fail/10",
|
|
150
|
+
destructive: "bg-wf-fail text-white hover:opacity-90"
|
|
151
|
+
};
|
|
152
|
+
function Button(props) {
|
|
153
|
+
const { variant = "secondary", size = "md", className = "", ...rest } = props;
|
|
154
|
+
return /* @__PURE__ */ jsx("button", {
|
|
155
|
+
type: "button",
|
|
156
|
+
className: `inline-flex shrink-0 items-center font-medium transition-colors disabled:pointer-events-none disabled:opacity-50 ${FOCUS_RING} ${BUTTON_SIZE[size]} ${BUTTON_VARIANT[variant]} ${className}`,
|
|
157
|
+
...rest
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
function IconButton(props) {
|
|
161
|
+
const { icon, label, active, className = "", ...rest } = props;
|
|
162
|
+
return /* @__PURE__ */ jsx("button", {
|
|
163
|
+
type: "button",
|
|
164
|
+
title: label,
|
|
165
|
+
"aria-label": label,
|
|
166
|
+
className: `inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md transition-colors disabled:pointer-events-none disabled:opacity-50 ${FOCUS_RING} ${active ? "bg-wf-run/10 text-wf-run" : "text-muted-foreground hover:bg-accent hover:text-foreground"} ${className}`,
|
|
167
|
+
...rest,
|
|
168
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
169
|
+
name: icon,
|
|
170
|
+
className: "h-3.5 w-3.5"
|
|
171
|
+
})
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
const inputClass = "w-full rounded-md border border-solid border-foreground/15 bg-card px-2.5 text-[13px] text-foreground placeholder:text-muted-foreground/70 transition-colors hover:border-foreground/25 focus:border-ring focus:outline-none focus:ring-2 focus:ring-ring/25 disabled:cursor-not-allowed disabled:opacity-60";
|
|
175
|
+
const textInputClass = `${inputClass} h-9`;
|
|
176
|
+
const textAreaClass = `${inputClass} min-h-20 py-2 leading-relaxed`;
|
|
177
|
+
const invalidClass = "border-wf-warn/70 hover:border-wf-warn";
|
|
178
|
+
/** Label row above a control: name, optional marker, and a trailing action. */
|
|
179
|
+
function FieldLabel(props) {
|
|
180
|
+
const LabelTag = props.htmlFor ? "label" : "span";
|
|
181
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
182
|
+
className: "mb-1.5 flex min-h-6 items-center justify-between gap-2",
|
|
183
|
+
children: [/* @__PURE__ */ jsxs(LabelTag, {
|
|
184
|
+
htmlFor: props.htmlFor,
|
|
185
|
+
className: "flex min-w-0 items-baseline gap-1.5 text-[13px] font-medium text-foreground",
|
|
186
|
+
children: [
|
|
187
|
+
/* @__PURE__ */ jsx("span", {
|
|
188
|
+
className: "truncate",
|
|
189
|
+
children: props.label
|
|
190
|
+
}),
|
|
191
|
+
props.optional ? /* @__PURE__ */ jsx("span", {
|
|
192
|
+
className: "shrink-0 text-xs font-normal text-muted-foreground",
|
|
193
|
+
children: "Optional"
|
|
194
|
+
}) : null,
|
|
195
|
+
props.needsValue ? /* @__PURE__ */ jsx("span", {
|
|
196
|
+
className: "shrink-0 text-xs font-normal text-wf-warn",
|
|
197
|
+
children: "Needs a value"
|
|
198
|
+
}) : null
|
|
199
|
+
]
|
|
200
|
+
}), props.action ? /* @__PURE__ */ jsx("span", {
|
|
201
|
+
className: "flex shrink-0 items-center gap-0.5",
|
|
202
|
+
children: props.action
|
|
203
|
+
}) : null]
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
const LONG_HINT = 140;
|
|
207
|
+
/** Help text under a control; long piece descriptions fold to two lines. */
|
|
208
|
+
function Hint(props) {
|
|
209
|
+
const [open, setOpen] = useState(false);
|
|
210
|
+
const text = props.text;
|
|
211
|
+
if (text !== void 0) {
|
|
212
|
+
if (!text.trim()) return null;
|
|
213
|
+
const long = text.length > LONG_HINT;
|
|
214
|
+
return /* @__PURE__ */ jsxs("p", {
|
|
215
|
+
className: "mt-1.5 text-xs leading-relaxed text-muted-foreground",
|
|
216
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
217
|
+
className: long && !open ? "line-clamp-2" : void 0,
|
|
218
|
+
children: text
|
|
219
|
+
}), long ? /* @__PURE__ */ jsx("button", {
|
|
220
|
+
type: "button",
|
|
221
|
+
className: "mt-0.5 block font-medium text-foreground/70 hover:text-foreground",
|
|
222
|
+
onClick: () => setOpen((value) => !value),
|
|
223
|
+
children: open ? "Show less" : "Show more"
|
|
224
|
+
}) : null]
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
return /* @__PURE__ */ jsx("p", {
|
|
228
|
+
className: "mt-1.5 text-xs leading-relaxed text-muted-foreground",
|
|
229
|
+
children: props.children
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
function FieldError(props) {
|
|
233
|
+
if (!props.children) return null;
|
|
234
|
+
return /* @__PURE__ */ jsx("p", {
|
|
235
|
+
className: "mt-1.5 text-xs text-wf-fail",
|
|
236
|
+
children: props.children
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
function Switch(props) {
|
|
240
|
+
const id = useId();
|
|
241
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
242
|
+
className: "flex items-start justify-between gap-4",
|
|
243
|
+
children: [/* @__PURE__ */ jsxs("label", {
|
|
244
|
+
htmlFor: id,
|
|
245
|
+
className: "min-w-0",
|
|
246
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
247
|
+
className: "block text-[13px] font-medium text-foreground",
|
|
248
|
+
children: props.label
|
|
249
|
+
}), props.description ? /* @__PURE__ */ jsx(Hint, { text: props.description }) : null]
|
|
250
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
251
|
+
id,
|
|
252
|
+
type: "button",
|
|
253
|
+
role: "switch",
|
|
254
|
+
"aria-checked": props.checked,
|
|
255
|
+
disabled: props.disabled,
|
|
256
|
+
className: `relative mt-0.5 inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors disabled:opacity-50 ${FOCUS_RING} ${props.checked ? "bg-primary" : "bg-foreground/20"}`,
|
|
257
|
+
onClick: () => props.onChange(!props.checked),
|
|
258
|
+
children: /* @__PURE__ */ jsx("span", { className: `inline-block h-4 w-4 rounded-full bg-card shadow-sm transition-transform ${props.checked ? "translate-x-[18px]" : "translate-x-0.5"}` })
|
|
259
|
+
})]
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
function Toggle(props) {
|
|
263
|
+
return /* @__PURE__ */ jsx("button", {
|
|
264
|
+
type: "button",
|
|
265
|
+
role: "switch",
|
|
266
|
+
"aria-checked": props.checked,
|
|
267
|
+
"aria-label": props.label,
|
|
268
|
+
disabled: props.disabled,
|
|
269
|
+
className: `relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${FOCUS_RING} ${props.checked ? "bg-wf-ok" : "bg-foreground/20"}`,
|
|
270
|
+
onClick: (event) => {
|
|
271
|
+
event.stopPropagation();
|
|
272
|
+
props.onChange(!props.checked);
|
|
273
|
+
},
|
|
274
|
+
children: /* @__PURE__ */ jsx("span", { className: `inline-block h-4 w-4 rounded-full bg-card shadow-sm transition-transform ${props.checked ? "translate-x-[18px]" : "translate-x-0.5"}` })
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
function Tooltip(props) {
|
|
278
|
+
if (props.enabled === false) return /* @__PURE__ */ jsx(Fragment$1, { children: props.children });
|
|
279
|
+
const place = props.side === "left" ? "right-full top-1/2 -translate-y-1/2 pr-1.5" : `top-full pt-1.5 ${props.align === "start" ? "left-0" : "right-0"}`;
|
|
280
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
281
|
+
className: "group/tip relative inline-flex",
|
|
282
|
+
children: [props.children, /* @__PURE__ */ jsx("span", {
|
|
283
|
+
className: `invisible absolute z-50 opacity-0 transition-opacity group-focus-within/tip:visible group-focus-within/tip:opacity-100 group-hover/tip:visible group-hover/tip:opacity-100 ${place}`,
|
|
284
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
285
|
+
role: "tooltip",
|
|
286
|
+
className: "block w-max max-w-64 rounded-md border border-solid border-foreground/10 bg-card px-2.5 py-1.5 text-xs text-foreground shadow-lg",
|
|
287
|
+
children: props.content
|
|
288
|
+
})
|
|
289
|
+
})]
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
function Tabs$1(props) {
|
|
293
|
+
return /* @__PURE__ */ jsx("div", {
|
|
294
|
+
role: "tablist",
|
|
295
|
+
className: "flex gap-4",
|
|
296
|
+
children: props.tabs.map((tab) => {
|
|
297
|
+
const selected = tab.value === props.value;
|
|
298
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
299
|
+
type: "button",
|
|
300
|
+
role: "tab",
|
|
301
|
+
"aria-selected": selected,
|
|
302
|
+
className: `-mb-px flex items-center gap-1.5 border-b-2 border-solid pb-2 text-[13px] font-medium transition-colors ${FOCUS_RING} ${selected ? "border-foreground text-foreground" : "border-transparent text-muted-foreground hover:text-foreground"}`,
|
|
303
|
+
onClick: () => props.onChange(tab.value),
|
|
304
|
+
children: [tab.label, tab.badge]
|
|
305
|
+
}, tab.value);
|
|
306
|
+
})
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
/** Two or three short, mutually exclusive choices shown side by side. */
|
|
310
|
+
function Segmented(props) {
|
|
311
|
+
return /* @__PURE__ */ jsx("div", {
|
|
312
|
+
role: "radiogroup",
|
|
313
|
+
className: `flex h-9 w-full items-center gap-0.5 rounded-md bg-muted p-0.5 ${props.invalid ? "ring-1 ring-wf-warn/60" : ""}`,
|
|
314
|
+
children: props.options.map((option) => {
|
|
315
|
+
const selected = option.value === props.value;
|
|
316
|
+
return /* @__PURE__ */ jsx("button", {
|
|
317
|
+
type: "button",
|
|
318
|
+
role: "radio",
|
|
319
|
+
"aria-checked": selected,
|
|
320
|
+
className: `h-8 min-w-0 flex-1 truncate rounded px-2 text-[13px] transition-colors ${FOCUS_RING} ${selected ? "bg-card font-medium text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"}`,
|
|
321
|
+
onClick: () => props.onChange(option.value),
|
|
322
|
+
children: option.label
|
|
323
|
+
}, option.value);
|
|
324
|
+
})
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
const SEARCH_THRESHOLD = 7;
|
|
328
|
+
function Select(props) {
|
|
329
|
+
const [open, setOpen] = useState(false);
|
|
330
|
+
const [query, setQuery] = useState("");
|
|
331
|
+
const [active, setActive] = useState(0);
|
|
332
|
+
const triggerRef = useRef(null);
|
|
333
|
+
const popoverRef = useRef(null);
|
|
334
|
+
const searchRef = useRef(null);
|
|
335
|
+
const listId = useId();
|
|
336
|
+
const [position, setPosition] = useState(null);
|
|
337
|
+
const selected = props.multiple ? props.value : props.value ? [props.value] : [];
|
|
338
|
+
const selectedSet = new Set(selected);
|
|
339
|
+
const searchable = props.searchable || Boolean(props.onQueryChange) || props.options.length > SEARCH_THRESHOLD;
|
|
340
|
+
const needle = query.trim().toLowerCase();
|
|
341
|
+
const serverSide = Boolean(props.onQueryChange);
|
|
342
|
+
const visible = useMemo(() => needle && !serverSide ? props.options.filter((option) => `${option.label} ${option.description ?? ""}`.toLowerCase().includes(needle)) : props.options, [
|
|
343
|
+
needle,
|
|
344
|
+
props.options,
|
|
345
|
+
serverSide
|
|
346
|
+
]);
|
|
347
|
+
const onQueryChange = props.onQueryChange;
|
|
348
|
+
const dismiss = () => {
|
|
349
|
+
setOpen(false);
|
|
350
|
+
setQuery("");
|
|
351
|
+
onQueryChange?.("");
|
|
352
|
+
};
|
|
353
|
+
const close = () => {
|
|
354
|
+
dismiss();
|
|
355
|
+
triggerRef.current?.focus();
|
|
356
|
+
};
|
|
357
|
+
const place = () => {
|
|
358
|
+
const rect = triggerRef.current?.getBoundingClientRect();
|
|
359
|
+
if (!rect) return;
|
|
360
|
+
const below = window.innerHeight - rect.bottom - 8;
|
|
361
|
+
const above = rect.top - 8;
|
|
362
|
+
const flip = below < 240 && above > below;
|
|
363
|
+
setPosition({
|
|
364
|
+
left: rect.left,
|
|
365
|
+
width: rect.width,
|
|
366
|
+
top: flip ? void 0 : rect.bottom + 4,
|
|
367
|
+
bottom: flip ? window.innerHeight - rect.top + 4 : void 0,
|
|
368
|
+
maxHeight: Math.min(320, flip ? above : below)
|
|
369
|
+
});
|
|
370
|
+
};
|
|
371
|
+
const openList = () => {
|
|
372
|
+
const index = props.options.findIndex((option) => selectedSet.has(option.value));
|
|
373
|
+
setActive(Math.max(0, index));
|
|
374
|
+
setOpen(true);
|
|
375
|
+
};
|
|
376
|
+
useLayoutEffect(() => {
|
|
377
|
+
if (!open) return;
|
|
378
|
+
place();
|
|
379
|
+
}, [open]);
|
|
380
|
+
const placed = position !== null;
|
|
381
|
+
useEffect(() => {
|
|
382
|
+
if (open && placed && searchable) searchRef.current?.focus();
|
|
383
|
+
}, [
|
|
384
|
+
open,
|
|
385
|
+
placed,
|
|
386
|
+
searchable
|
|
387
|
+
]);
|
|
388
|
+
useEffect(() => {
|
|
389
|
+
if (!open) return;
|
|
390
|
+
const onPointer = (event) => {
|
|
391
|
+
const target = event.target;
|
|
392
|
+
if (!popoverRef.current?.contains(target) && !triggerRef.current?.contains(target)) {
|
|
393
|
+
setOpen(false);
|
|
394
|
+
setQuery("");
|
|
395
|
+
onQueryChange?.("");
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
window.addEventListener("mousedown", onPointer);
|
|
399
|
+
window.addEventListener("resize", place);
|
|
400
|
+
window.addEventListener("scroll", place, true);
|
|
401
|
+
return () => {
|
|
402
|
+
window.removeEventListener("mousedown", onPointer);
|
|
403
|
+
window.removeEventListener("resize", place);
|
|
404
|
+
window.removeEventListener("scroll", place, true);
|
|
405
|
+
};
|
|
406
|
+
}, [
|
|
407
|
+
open,
|
|
408
|
+
searchable,
|
|
409
|
+
onQueryChange
|
|
410
|
+
]);
|
|
411
|
+
useEffect(() => {
|
|
412
|
+
popoverRef.current?.querySelector(`[data-index="${active}"]`)?.scrollIntoView({ block: "nearest" });
|
|
413
|
+
}, [active]);
|
|
414
|
+
const choose = (option) => {
|
|
415
|
+
if (option.disabled) return;
|
|
416
|
+
if (props.multiple) {
|
|
417
|
+
props.onChange(selectedSet.has(option.value) ? props.value.filter((value) => value !== option.value) : [...props.value, option.value]);
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
props.onChange(option.value);
|
|
421
|
+
close();
|
|
422
|
+
};
|
|
423
|
+
const onListKey = (event) => {
|
|
424
|
+
if (event.key === "ArrowDown") {
|
|
425
|
+
event.preventDefault();
|
|
426
|
+
setActive((index) => Math.min(visible.length - 1, index + 1));
|
|
427
|
+
} else if (event.key === "ArrowUp") {
|
|
428
|
+
event.preventDefault();
|
|
429
|
+
setActive((index) => Math.max(0, index - 1));
|
|
430
|
+
} else if (event.key === "Enter") {
|
|
431
|
+
event.preventDefault();
|
|
432
|
+
const option = visible[active];
|
|
433
|
+
if (option) choose(option);
|
|
434
|
+
} else if (event.key === "Escape") {
|
|
435
|
+
event.preventDefault();
|
|
436
|
+
close();
|
|
437
|
+
} else if (event.key === "Tab") dismiss();
|
|
438
|
+
};
|
|
439
|
+
const labels = props.options.filter((option) => selectedSet.has(option.value)).map((option) => option.label);
|
|
440
|
+
const unknown = selected.filter((value) => !props.options.some((option) => option.value === value));
|
|
441
|
+
const shown = [...labels, ...unknown];
|
|
442
|
+
const selectedIcon = props.multiple ? void 0 : props.options.find((option) => option.value === props.value)?.icon;
|
|
443
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("button", {
|
|
444
|
+
ref: triggerRef,
|
|
445
|
+
id: props.id,
|
|
446
|
+
"aria-label": props.ariaLabel,
|
|
447
|
+
type: "button",
|
|
448
|
+
role: "combobox",
|
|
449
|
+
"aria-expanded": open,
|
|
450
|
+
"aria-controls": open ? listId : void 0,
|
|
451
|
+
"aria-activedescendant": open && visible.length > 0 ? `${listId}-${active}` : void 0,
|
|
452
|
+
"aria-haspopup": "listbox",
|
|
453
|
+
disabled: props.disabled,
|
|
454
|
+
className: `${textInputClass} flex items-center gap-2 text-left ${props.invalid ? invalidClass : ""} ${open ? "border-ring ring-2 ring-ring/25" : ""}`,
|
|
455
|
+
onClick: () => open ? close() : openList(),
|
|
456
|
+
onKeyDown: (event) => {
|
|
457
|
+
if (open) {
|
|
458
|
+
onListKey(event);
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
if (event.key === "ArrowDown" || event.key === "Enter" || event.key === " ") {
|
|
462
|
+
event.preventDefault();
|
|
463
|
+
openList();
|
|
464
|
+
}
|
|
465
|
+
},
|
|
466
|
+
children: [
|
|
467
|
+
selectedIcon,
|
|
468
|
+
/* @__PURE__ */ jsx("span", {
|
|
469
|
+
className: `min-w-0 flex-1 truncate ${shown.length ? "" : "text-muted-foreground/70"}`,
|
|
470
|
+
children: labels.length === 0 && unknown.length > 0 && props.valueLabel !== void 0 ? props.valueLabel : shown.length > 0 ? shown.join(", ") : props.loading ? "Loading…" : props.placeholder ?? "Choose…"
|
|
471
|
+
}),
|
|
472
|
+
props.multiple && shown.length > 1 ? /* @__PURE__ */ jsx("span", {
|
|
473
|
+
className: "shrink-0 rounded bg-muted px-1.5 text-[11px] tabular-nums text-muted-foreground",
|
|
474
|
+
children: shown.length
|
|
475
|
+
}) : null,
|
|
476
|
+
/* @__PURE__ */ jsx(Icon, {
|
|
477
|
+
name: "chevronDown",
|
|
478
|
+
className: `h-3.5 w-3.5 text-muted-foreground transition-transform ${open ? "rotate-180" : ""}`
|
|
479
|
+
})
|
|
480
|
+
]
|
|
481
|
+
}), open && position ? createPortal(/* @__PURE__ */ jsxs("div", {
|
|
482
|
+
ref: popoverRef,
|
|
483
|
+
tabIndex: -1,
|
|
484
|
+
className: "workflow-select-popover fixed flex flex-col overflow-hidden rounded-lg border border-solid border-foreground/10 bg-popover text-popover-foreground shadow-lg outline-none",
|
|
485
|
+
style: {
|
|
486
|
+
left: position.left,
|
|
487
|
+
width: Math.max(position.width, 220),
|
|
488
|
+
top: position.top,
|
|
489
|
+
bottom: position.bottom,
|
|
490
|
+
maxHeight: position.maxHeight
|
|
491
|
+
},
|
|
492
|
+
onKeyDown: onListKey,
|
|
493
|
+
children: [
|
|
494
|
+
searchable || props.onRefresh ? /* @__PURE__ */ jsxs("div", {
|
|
495
|
+
className: "flex items-center gap-1 border-b border-solid border-foreground/10 px-2",
|
|
496
|
+
children: [searchable ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(Icon, {
|
|
497
|
+
name: "search",
|
|
498
|
+
className: "h-3.5 w-3.5 text-muted-foreground"
|
|
499
|
+
}), /* @__PURE__ */ jsx("input", {
|
|
500
|
+
ref: searchRef,
|
|
501
|
+
className: "h-9 min-w-0 flex-1 bg-transparent text-[13px] text-foreground placeholder:text-muted-foreground/70 focus:outline-none",
|
|
502
|
+
placeholder: "Search",
|
|
503
|
+
value: query,
|
|
504
|
+
onChange: (event) => {
|
|
505
|
+
setQuery(event.target.value);
|
|
506
|
+
setActive(0);
|
|
507
|
+
props.onQueryChange?.(event.target.value);
|
|
508
|
+
}
|
|
509
|
+
})] }) : /* @__PURE__ */ jsx("span", { className: "h-9 flex-1" }), props.onRefresh ? /* @__PURE__ */ jsx(IconButton, {
|
|
510
|
+
icon: "retry",
|
|
511
|
+
label: "Reload options",
|
|
512
|
+
disabled: props.loading,
|
|
513
|
+
onClick: props.onRefresh
|
|
514
|
+
}) : null]
|
|
515
|
+
}) : null,
|
|
516
|
+
/* @__PURE__ */ jsx("div", {
|
|
517
|
+
id: listId,
|
|
518
|
+
role: "listbox",
|
|
519
|
+
"aria-multiselectable": props.multiple || void 0,
|
|
520
|
+
className: "min-h-0 flex-1 overflow-y-auto p-1",
|
|
521
|
+
children: props.loading && props.options.length === 0 ? /* @__PURE__ */ jsx("p", {
|
|
522
|
+
className: "px-2 py-2 text-[13px] text-muted-foreground",
|
|
523
|
+
children: "Loading options…"
|
|
524
|
+
}) : visible.length === 0 ? /* @__PURE__ */ jsx("p", {
|
|
525
|
+
className: "px-2 py-2 text-[13px] text-muted-foreground",
|
|
526
|
+
children: needle ? "Nothing matches." : props.emptyText ?? "No options."
|
|
527
|
+
}) : visible.map((option, index) => {
|
|
528
|
+
const isSelected = selectedSet.has(option.value);
|
|
529
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
530
|
+
id: `${listId}-${index}`,
|
|
531
|
+
role: "option",
|
|
532
|
+
"aria-selected": isSelected,
|
|
533
|
+
"aria-disabled": option.disabled || void 0,
|
|
534
|
+
"data-index": index,
|
|
535
|
+
className: `flex cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 text-[13px] ${index === active ? "bg-accent" : ""} ${option.disabled ? "cursor-not-allowed opacity-50" : ""}`,
|
|
536
|
+
onMouseEnter: () => setActive(index),
|
|
537
|
+
onMouseDown: (event) => {
|
|
538
|
+
event.preventDefault();
|
|
539
|
+
choose(option);
|
|
540
|
+
},
|
|
541
|
+
children: [
|
|
542
|
+
props.multiple ? /* @__PURE__ */ jsx("span", {
|
|
543
|
+
className: `flex h-4 w-4 shrink-0 items-center justify-center rounded border border-solid ${isSelected ? "border-primary bg-primary text-primary-foreground" : "border-foreground/25"}`,
|
|
544
|
+
children: isSelected ? /* @__PURE__ */ jsx(Icon, {
|
|
545
|
+
name: "check",
|
|
546
|
+
className: "h-3 w-3"
|
|
547
|
+
}) : null
|
|
548
|
+
}) : null,
|
|
549
|
+
option.icon,
|
|
550
|
+
/* @__PURE__ */ jsxs("span", {
|
|
551
|
+
className: "min-w-0 flex-1",
|
|
552
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
553
|
+
className: "block truncate",
|
|
554
|
+
children: option.label
|
|
555
|
+
}), option.description ? /* @__PURE__ */ jsx("span", {
|
|
556
|
+
className: "block truncate text-xs text-muted-foreground",
|
|
557
|
+
children: option.description
|
|
558
|
+
}) : null]
|
|
559
|
+
}),
|
|
560
|
+
!props.multiple && isSelected ? /* @__PURE__ */ jsx(Icon, {
|
|
561
|
+
name: "check",
|
|
562
|
+
className: "h-3.5 w-3.5 text-foreground"
|
|
563
|
+
}) : null
|
|
564
|
+
]
|
|
565
|
+
}, option.value);
|
|
566
|
+
})
|
|
567
|
+
}),
|
|
568
|
+
props.actions?.length ? /* @__PURE__ */ jsx("div", {
|
|
569
|
+
className: "border-t border-solid border-foreground/10 p-1",
|
|
570
|
+
children: props.actions.map((action) => /* @__PURE__ */ jsxs("button", {
|
|
571
|
+
type: "button",
|
|
572
|
+
className: "flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-[13px] text-muted-foreground hover:bg-accent hover:text-foreground",
|
|
573
|
+
onMouseDown: (event) => {
|
|
574
|
+
event.preventDefault();
|
|
575
|
+
dismiss();
|
|
576
|
+
action.onSelect();
|
|
577
|
+
},
|
|
578
|
+
children: [action.icon ? /* @__PURE__ */ jsx(Icon, {
|
|
579
|
+
name: action.icon,
|
|
580
|
+
className: "h-3.5 w-3.5"
|
|
581
|
+
}) : null, action.label]
|
|
582
|
+
}, action.label))
|
|
583
|
+
}) : null,
|
|
584
|
+
!props.multiple && props.clearable && props.value ? /* @__PURE__ */ jsx("div", {
|
|
585
|
+
className: "border-t border-solid border-foreground/10 p-1",
|
|
586
|
+
children: /* @__PURE__ */ jsxs("button", {
|
|
587
|
+
type: "button",
|
|
588
|
+
className: "flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-[13px] text-muted-foreground hover:bg-accent hover:text-foreground",
|
|
589
|
+
onMouseDown: (event) => {
|
|
590
|
+
event.preventDefault();
|
|
591
|
+
props.onChange("");
|
|
592
|
+
close();
|
|
593
|
+
},
|
|
594
|
+
children: [/* @__PURE__ */ jsx(Icon, {
|
|
595
|
+
name: "close",
|
|
596
|
+
className: "h-3.5 w-3.5"
|
|
597
|
+
}), "Clear selection"]
|
|
598
|
+
})
|
|
599
|
+
}) : null
|
|
600
|
+
]
|
|
601
|
+
}), document.body) : null] });
|
|
602
|
+
}
|
|
603
|
+
//#endregion
|
|
604
|
+
//#region editors/shared/url-param.ts
|
|
605
|
+
/** The studio's sidebar selection. */
|
|
606
|
+
const ITEM_PARAM = "item";
|
|
607
|
+
/** A query param read as one of `allowed`, else `fallback`; the fallback is
|
|
608
|
+
* kept out of the URL. `also` updates other params in the same entry. */
|
|
609
|
+
function useSearchParam(key, fallback, allowed) {
|
|
610
|
+
const params = useSearchParams();
|
|
611
|
+
const setParams = useSetSearchParams();
|
|
612
|
+
const raw = params[key];
|
|
613
|
+
const value = raw !== void 0 && (!allowed || allowed.includes(raw)) ? raw : fallback;
|
|
614
|
+
return [value, useCallback((next, options) => {
|
|
615
|
+
if (next === value && !options?.also) return;
|
|
616
|
+
setParams({
|
|
617
|
+
...options?.also,
|
|
618
|
+
[key]: next === fallback ? void 0 : next
|
|
619
|
+
}, { replace: options?.replace });
|
|
620
|
+
}, [
|
|
621
|
+
key,
|
|
622
|
+
fallback,
|
|
623
|
+
value,
|
|
624
|
+
setParams
|
|
625
|
+
])];
|
|
626
|
+
}
|
|
627
|
+
/** A text param with a local draft, so typing never waits on a navigation;
|
|
628
|
+
* the draft follows other URL changes, e.g. back and forward. */
|
|
629
|
+
function useSearchParamDraft(key) {
|
|
630
|
+
const [param, setParam] = useSearchParam(key, "");
|
|
631
|
+
const [draft, setDraft] = useState(param);
|
|
632
|
+
const written = useRef([]);
|
|
633
|
+
useEffect(() => {
|
|
634
|
+
const index = written.current.indexOf(param);
|
|
635
|
+
written.current = index === -1 ? [] : written.current.slice(index + 1);
|
|
636
|
+
if (index === -1) setDraft(param);
|
|
637
|
+
}, [param]);
|
|
638
|
+
return [draft, useCallback((value) => {
|
|
639
|
+
setDraft(value);
|
|
640
|
+
if (value === param) return;
|
|
641
|
+
written.current.push(value);
|
|
642
|
+
setParam(value, { replace: true });
|
|
643
|
+
}, [param, setParam])];
|
|
644
|
+
}
|
|
645
|
+
function shouldPersistQuery(queryKey) {
|
|
646
|
+
if (typeof queryKey[0] !== "string") return false;
|
|
647
|
+
const kind = queryKind(queryKey);
|
|
648
|
+
if (kind === "catalog") return queryKey.length === 2;
|
|
649
|
+
if (kind === "form") {
|
|
650
|
+
const block = queryKey[2];
|
|
651
|
+
return Array.isArray(block) && block[0] !== CORE_PIECE_NAME;
|
|
652
|
+
}
|
|
653
|
+
return false;
|
|
654
|
+
}
|
|
655
|
+
function persistRuntimeQueries(queryClient, url, store, now = Date.now) {
|
|
656
|
+
if (!store) return {
|
|
657
|
+
ready: Promise.resolve(),
|
|
658
|
+
dispose: () => void 0
|
|
659
|
+
};
|
|
660
|
+
return {
|
|
661
|
+
ready: hydrate(queryClient, url, store, now()),
|
|
662
|
+
dispose: queryClient.getQueryCache().subscribe((event) => {
|
|
663
|
+
if (event.type !== "updated" || event.action.type !== "success") return;
|
|
664
|
+
if (event.action.manual) return;
|
|
665
|
+
const { queryKey, state } = event.query;
|
|
666
|
+
if (!shouldPersistQuery(queryKey) || state.data === void 0) return;
|
|
667
|
+
store.save({
|
|
668
|
+
id: JSON.stringify(queryKey),
|
|
669
|
+
url: queryKey[0],
|
|
670
|
+
queryKey,
|
|
671
|
+
data: state.data,
|
|
672
|
+
updatedAt: state.dataUpdatedAt,
|
|
673
|
+
version: 2
|
|
674
|
+
}).catch(() => void 0);
|
|
675
|
+
})
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
async function hydrate(queryClient, url, store, at) {
|
|
679
|
+
let entries;
|
|
680
|
+
try {
|
|
681
|
+
entries = await store.load(url);
|
|
682
|
+
} catch {
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
for (const entry of entries) {
|
|
686
|
+
if (entry.version !== 2 || at - entry.updatedAt > 6048e5 || !shouldPersistQuery(entry.queryKey)) {
|
|
687
|
+
store.remove(entry.id).catch(() => void 0);
|
|
688
|
+
continue;
|
|
689
|
+
}
|
|
690
|
+
const current = queryClient.getQueryState(entry.queryKey);
|
|
691
|
+
if (current && current.dataUpdatedAt >= entry.updatedAt) continue;
|
|
692
|
+
queryClient.setQueryData(entry.queryKey, entry.data, { updatedAt: entry.updatedAt });
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
const DB_NAME = "ph-workflow-runtime-cache";
|
|
696
|
+
const STORE = "queries";
|
|
697
|
+
function request(req) {
|
|
698
|
+
return new Promise((resolve, reject) => {
|
|
699
|
+
req.onsuccess = () => resolve(req.result);
|
|
700
|
+
req.onerror = () => reject(req.error ?? /* @__PURE__ */ new Error("IndexedDB request failed"));
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
function openIdbCacheStore() {
|
|
704
|
+
const idb = globalThis.indexedDB;
|
|
705
|
+
if (!idb) return null;
|
|
706
|
+
let db;
|
|
707
|
+
const open = () => {
|
|
708
|
+
db ??= new Promise((resolve, reject) => {
|
|
709
|
+
const req = idb.open(DB_NAME, 1);
|
|
710
|
+
req.onupgradeneeded = () => {
|
|
711
|
+
req.result.createObjectStore(STORE, { keyPath: "id" }).createIndex("url", "url");
|
|
712
|
+
};
|
|
713
|
+
req.onsuccess = () => resolve(req.result);
|
|
714
|
+
req.onerror = () => reject(req.error ?? /* @__PURE__ */ new Error("IndexedDB unavailable"));
|
|
715
|
+
req.onblocked = () => reject(/* @__PURE__ */ new Error("IndexedDB blocked"));
|
|
716
|
+
});
|
|
717
|
+
db.catch(() => db = void 0);
|
|
718
|
+
return db;
|
|
719
|
+
};
|
|
720
|
+
const withStore = async (mode, run) => {
|
|
721
|
+
return request(run((await open()).transaction(STORE, mode).objectStore(STORE)));
|
|
722
|
+
};
|
|
723
|
+
return {
|
|
724
|
+
load: (url) => withStore("readonly", (store) => store.index("url").getAll(url)),
|
|
725
|
+
save: (entry) => withStore("readwrite", (store) => store.put(entry)).then(() => void 0),
|
|
726
|
+
remove: (id) => withStore("readwrite", (store) => store.delete(id)).then(() => void 0)
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
//#endregion
|
|
730
|
+
//#region editors/workflow-editor/ui/piece-source.ts
|
|
731
|
+
function blockUnavailable(entry) {
|
|
732
|
+
if (entry.unsupported) return entry.unsupported;
|
|
733
|
+
if (entry.kind !== "trigger") return void 0;
|
|
734
|
+
const strategy = checkTriggerStrategy(entry.strategy);
|
|
735
|
+
return "issue" in strategy ? strategy.issue : void 0;
|
|
736
|
+
}
|
|
737
|
+
const PieceSourceContext = createContext(void 0);
|
|
738
|
+
const PieceSourceProvider = PieceSourceContext.Provider;
|
|
739
|
+
function usePieceSource() {
|
|
740
|
+
return useContext(PieceSourceContext);
|
|
741
|
+
}
|
|
742
|
+
//#endregion
|
|
743
|
+
//#region editors/workflow-editor/use-runtime-url.ts
|
|
744
|
+
const SUBGRAPH_NAME = "workflow-runtime";
|
|
745
|
+
function baseFromChannelUrl(channelUrl) {
|
|
746
|
+
try {
|
|
747
|
+
const url = new URL(channelUrl);
|
|
748
|
+
url.search = "";
|
|
749
|
+
url.hash = "";
|
|
750
|
+
url.pathname = url.pathname.replace(/\/r\/?$/, "");
|
|
751
|
+
return url.toString();
|
|
752
|
+
} catch {
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
function useWorkflowRuntimeUrl() {
|
|
757
|
+
const [drive] = useSelectedDriveSafe();
|
|
758
|
+
const remotes = useSyncList();
|
|
759
|
+
const defaultDrivesUrl = useDefaultDrivesUrl();
|
|
760
|
+
const driveId = drive?.header.id;
|
|
761
|
+
return useMemo(() => {
|
|
762
|
+
let base;
|
|
763
|
+
if (driveId) {
|
|
764
|
+
const channelUrl = (remotes.find((entry) => entry.meta.collectionId.equals(DriveCollectionId.forDrive(driveId)))?.channel)?.config.url;
|
|
765
|
+
if (typeof channelUrl === "string") base = baseFromChannelUrl(channelUrl);
|
|
766
|
+
}
|
|
767
|
+
if (!base && defaultDrivesUrl) try {
|
|
768
|
+
base = parseDriveUrl(defaultDrivesUrl).graphqlEndpoint.replace(/\/r$/, "");
|
|
769
|
+
} catch {}
|
|
770
|
+
return subgraphUrlFromGraphqlUrl(base ?? DEFAULT_SWITCHBOARD_URL, SUBGRAPH_NAME);
|
|
771
|
+
}, [
|
|
772
|
+
driveId,
|
|
773
|
+
remotes,
|
|
774
|
+
defaultDrivesUrl
|
|
775
|
+
]);
|
|
776
|
+
}
|
|
777
|
+
//#endregion
|
|
778
|
+
//#region editors/workflow-editor/runtime-context.tsx
|
|
779
|
+
const RuntimeContext = createContext(null);
|
|
780
|
+
const SEARCH_STALE_MS = 3e5;
|
|
781
|
+
function runtimePieceSource(client, queryClient) {
|
|
782
|
+
return {
|
|
783
|
+
loadCatalog: () => queryClient.fetchQuery(catalogQuery(client)),
|
|
784
|
+
reloadCatalog: () => queryClient.fetchQuery({
|
|
785
|
+
...catalogQuery(client),
|
|
786
|
+
staleTime: 0
|
|
787
|
+
}),
|
|
788
|
+
loadActions: (packageName) => queryClient.fetchQuery(pieceActionsQuery(client, packageName)),
|
|
789
|
+
loadTriggers: (packageName) => queryClient.fetchQuery(pieceTriggersQuery(client, packageName)),
|
|
790
|
+
searchPieces: async (query, filter) => {
|
|
791
|
+
const key = runtimeKeys.searchPieces(client.url, query, filter);
|
|
792
|
+
const result = await queryClient.fetchQuery({
|
|
793
|
+
queryKey: key,
|
|
794
|
+
queryFn: () => client.searchPieces(query, filter),
|
|
795
|
+
staleTime: SEARCH_STALE_MS
|
|
796
|
+
});
|
|
797
|
+
if (result.status !== "ready") queryClient.removeQueries({ queryKey: key });
|
|
798
|
+
return result;
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
function RuntimeProvider(props) {
|
|
803
|
+
const { url } = props;
|
|
804
|
+
const [queryClient] = useState(createRuntimeQueryClient);
|
|
805
|
+
const [store] = useState(() => props.store === void 0 ? openIdbCacheStore() : props.store);
|
|
806
|
+
const client = useMemo(() => createRuntimeClient(url), [url]);
|
|
807
|
+
useEffect(() => persistRuntimeQueries(queryClient, url, store).dispose, [
|
|
808
|
+
queryClient,
|
|
809
|
+
url,
|
|
810
|
+
store
|
|
811
|
+
]);
|
|
812
|
+
const value = useMemo(() => ({
|
|
813
|
+
client,
|
|
814
|
+
queryClient
|
|
815
|
+
}), [client, queryClient]);
|
|
816
|
+
const pieceSource = useMemo(() => runtimePieceSource(client, queryClient), [client, queryClient]);
|
|
817
|
+
return /* @__PURE__ */ jsx(RuntimeContext.Provider, {
|
|
818
|
+
value,
|
|
819
|
+
children: /* @__PURE__ */ jsx(PieceSourceProvider, {
|
|
820
|
+
value: pieceSource,
|
|
821
|
+
children: props.children
|
|
822
|
+
})
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
function WorkflowRuntimeProvider(props) {
|
|
826
|
+
const url = useWorkflowRuntimeUrl();
|
|
827
|
+
return /* @__PURE__ */ jsx(RuntimeProvider, {
|
|
828
|
+
url,
|
|
829
|
+
children: props.children
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
function useRuntime() {
|
|
833
|
+
const context = useContext(RuntimeContext);
|
|
834
|
+
if (!context) throw new Error("useRuntime needs a RuntimeProvider");
|
|
835
|
+
return context;
|
|
836
|
+
}
|
|
837
|
+
function usePieceCatalog() {
|
|
838
|
+
const { client, queryClient } = useRuntime();
|
|
839
|
+
return useQuery(catalogQuery(client), queryClient);
|
|
840
|
+
}
|
|
841
|
+
function useRunsQuery(scope, options = {}) {
|
|
842
|
+
const { client, queryClient } = useRuntime();
|
|
843
|
+
return useQuery({
|
|
844
|
+
...runsQuery(client, scope),
|
|
845
|
+
enabled: options.active ?? true,
|
|
846
|
+
refetchInterval: options.pollMs ?? false
|
|
847
|
+
}, queryClient);
|
|
848
|
+
}
|
|
849
|
+
function useRunPagesQuery(scope, options = {}) {
|
|
850
|
+
const { client, queryClient } = useRuntime();
|
|
851
|
+
return useInfiniteQuery({
|
|
852
|
+
...runPagesQuery(client, scope),
|
|
853
|
+
enabled: options.active ?? true,
|
|
854
|
+
refetchInterval: options.pollMs ?? false
|
|
855
|
+
}, queryClient);
|
|
856
|
+
}
|
|
857
|
+
function useRunQuery(runId, options = {}) {
|
|
858
|
+
const { client, queryClient } = useRuntime();
|
|
859
|
+
return useQuery({
|
|
860
|
+
...runQuery(client, runId),
|
|
861
|
+
refetchInterval: (query) => options.pollMs && query.state.data?.endedAt == null ? options.pollMs : false
|
|
862
|
+
}, queryClient);
|
|
863
|
+
}
|
|
864
|
+
function useSecretStat(ref, enabled) {
|
|
865
|
+
const { client, queryClient } = useRuntime();
|
|
866
|
+
const query = useQuery({
|
|
867
|
+
...secretStatQuery(client, ref),
|
|
868
|
+
enabled,
|
|
869
|
+
gcTime: 0
|
|
870
|
+
}, queryClient);
|
|
871
|
+
if (!enabled) return null;
|
|
872
|
+
if (query.status === "pending") return void 0;
|
|
873
|
+
return query.status === "error" ? null : query.data;
|
|
874
|
+
}
|
|
875
|
+
function useOAuthRedirectUri() {
|
|
876
|
+
const { client, queryClient } = useRuntime();
|
|
877
|
+
return useQuery({
|
|
878
|
+
queryKey: [client.url, "oauthRedirectUri"],
|
|
879
|
+
queryFn: () => client.fetchOAuthRedirectUri(),
|
|
880
|
+
staleTime: Infinity
|
|
881
|
+
}, queryClient);
|
|
882
|
+
}
|
|
883
|
+
function useOAuthAttempt(state) {
|
|
884
|
+
const { client, queryClient } = useRuntime();
|
|
885
|
+
const query = useQuery({
|
|
886
|
+
queryKey: [
|
|
887
|
+
client.url,
|
|
888
|
+
"oauthAttempt",
|
|
889
|
+
state
|
|
890
|
+
],
|
|
891
|
+
queryFn: () => client.fetchOAuthAttempt(state),
|
|
892
|
+
enabled: state !== null,
|
|
893
|
+
gcTime: 0,
|
|
894
|
+
refetchInterval: (current) => {
|
|
895
|
+
if (current.state.status === "error") return false;
|
|
896
|
+
const data = current.state.data;
|
|
897
|
+
if (data === null) return false;
|
|
898
|
+
return data?.status === "OK" || data?.status === "ERROR" ? false : 1e3;
|
|
899
|
+
}
|
|
900
|
+
}, queryClient);
|
|
901
|
+
if (state === null || query.isError) return null;
|
|
902
|
+
return query.data;
|
|
903
|
+
}
|
|
904
|
+
function useRuntimeActions() {
|
|
905
|
+
const { client, queryClient } = useRuntime();
|
|
906
|
+
return useMemo(() => {
|
|
907
|
+
const invalidate = (queryKey) => void queryClient.invalidateQueries({ queryKey });
|
|
908
|
+
const runsChanged = () => {
|
|
909
|
+
invalidate(runtimeKeys.allRuns(client.url));
|
|
910
|
+
invalidate([client.url, "latestRun"]);
|
|
911
|
+
};
|
|
912
|
+
const secretSaved = (stat) => {
|
|
913
|
+
queryClient.setQueryData(runtimeKeys.secret(client.url, stat.ref), stat);
|
|
914
|
+
return stat;
|
|
915
|
+
};
|
|
916
|
+
return {
|
|
917
|
+
fireWorkflow: (workflowId, payload) => client.fireWorkflow(workflowId, payload).finally(runsChanged),
|
|
918
|
+
rerunRun: (runId) => client.rerunRun(runId).finally(runsChanged),
|
|
919
|
+
createSecret: (value, label) => client.createSecret(value, label).then(secretSaved),
|
|
920
|
+
rotateSecret: (ref, value) => client.rotateSecret(ref, value).then(secretSaved),
|
|
921
|
+
checkConnection: (connectionId) => client.checkConnection(connectionId).finally(() => invalidate(runtimeKeys.connections(client.url))),
|
|
922
|
+
connectionsChanged: () => invalidate(runtimeKeys.connections(client.url)),
|
|
923
|
+
startOAuth: (connectionId, options) => client.startOAuth(connectionId, options)
|
|
924
|
+
};
|
|
925
|
+
}, [client, queryClient]);
|
|
926
|
+
}
|
|
927
|
+
//#endregion
|
|
928
|
+
//#region editors/workflow-editor/ui/validation.ts
|
|
929
|
+
function isEmptyValue(value) {
|
|
930
|
+
if (value === void 0 || value === null) return true;
|
|
931
|
+
if (typeof value === "string") return value.trim() === "";
|
|
932
|
+
if (Array.isArray(value)) return value.length === 0;
|
|
933
|
+
return false;
|
|
934
|
+
}
|
|
935
|
+
function isPropVisible(prop, config) {
|
|
936
|
+
const rule = prop.showWhen;
|
|
937
|
+
if (!rule) return true;
|
|
938
|
+
return rule.oneOf.includes(config[rule.prop] ?? void 0);
|
|
939
|
+
}
|
|
940
|
+
function asRecord(config) {
|
|
941
|
+
return config !== null && typeof config === "object" && !Array.isArray(config) ? config : {};
|
|
942
|
+
}
|
|
943
|
+
function missingRequired(props, config) {
|
|
944
|
+
const record = asRecord(config);
|
|
945
|
+
return props.filter((prop) => prop.required && prop.type !== "MARKDOWN" && isPropVisible(prop, record) && isEmptyValue(record[prop.name])).map((prop) => prop.displayName);
|
|
946
|
+
}
|
|
947
|
+
function resolverInputFor(block, prop, config, connectionId, reactorConnectionId) {
|
|
948
|
+
const refreshers = (prop.refreshers ?? []).filter((name) => name !== "auth");
|
|
949
|
+
return {
|
|
950
|
+
block,
|
|
951
|
+
propName: prop.name,
|
|
952
|
+
refreshers: refreshers.map((name) => config[name] ?? null),
|
|
953
|
+
connectionId: connectionId ?? null,
|
|
954
|
+
...reactorConnectionId ? { reactorConnectionId } : {}
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
function settingFor(settings, prop) {
|
|
958
|
+
return settings?.find((setting) => setting.prop === prop);
|
|
959
|
+
}
|
|
960
|
+
function parsePropList(result) {
|
|
961
|
+
if (!Array.isArray(result)) throw new Error("Unexpected properties result");
|
|
962
|
+
return result.filter((entry) => entry !== null && typeof entry === "object" && typeof entry.name === "string");
|
|
963
|
+
}
|
|
964
|
+
function storedSchema(settings, prop) {
|
|
965
|
+
const schema = settingFor(settings, prop)?.schema;
|
|
966
|
+
if (!Array.isArray(schema)) return void 0;
|
|
967
|
+
return schema.filter((entry) => entry !== null && typeof entry === "object" && typeof entry.name === "string");
|
|
968
|
+
}
|
|
969
|
+
function stripOptions(props) {
|
|
970
|
+
return props.map((prop) => {
|
|
971
|
+
const { staticOptions: _options, properties, ...rest } = prop;
|
|
972
|
+
return properties ? {
|
|
973
|
+
...rest,
|
|
974
|
+
properties: stripOptions(properties)
|
|
975
|
+
} : rest;
|
|
976
|
+
});
|
|
977
|
+
}
|
|
978
|
+
function withSetting(settings, prop, patch) {
|
|
979
|
+
const list = [...settings ?? []];
|
|
980
|
+
const index = list.findIndex((setting) => setting.prop === prop);
|
|
981
|
+
const current = index >= 0 ? list[index] : {
|
|
982
|
+
prop,
|
|
983
|
+
mode: "MANUAL"
|
|
984
|
+
};
|
|
985
|
+
const next = {
|
|
986
|
+
prop,
|
|
987
|
+
mode: patch.mode ?? current.mode,
|
|
988
|
+
schema: "schema" in patch ? patch.schema ?? null : current.schema ?? null
|
|
989
|
+
};
|
|
990
|
+
if (index >= 0) list[index] = next;
|
|
991
|
+
else list.push(next);
|
|
992
|
+
return list;
|
|
993
|
+
}
|
|
994
|
+
const REACTOR_CONNECTION_LABEL = "Reactor connection";
|
|
995
|
+
function blockMissing(input) {
|
|
996
|
+
if (input.skip) return [];
|
|
997
|
+
const { form } = input;
|
|
998
|
+
if (!form || form === "loading") return null;
|
|
999
|
+
const record = asRecord(input.config);
|
|
1000
|
+
const missing = [];
|
|
1001
|
+
let unknown = false;
|
|
1002
|
+
if (form.auth === "required" && !input.connectionId) missing.push("Connection");
|
|
1003
|
+
if (form.requireReactor && !input.reactorConnectionId) missing.push(REACTOR_CONNECTION_LABEL);
|
|
1004
|
+
for (const prop of form.props) {
|
|
1005
|
+
if (prop.type === "MARKDOWN" || !isPropVisible(prop, record)) continue;
|
|
1006
|
+
const value = record[prop.name];
|
|
1007
|
+
const bound = settingFor(input.propertySettings, prop.name)?.mode === "EXPRESSION";
|
|
1008
|
+
if (prop.type !== "DYNAMIC" || bound) {
|
|
1009
|
+
if (prop.required && isEmptyValue(value)) missing.push(prop.displayName);
|
|
1010
|
+
continue;
|
|
1011
|
+
}
|
|
1012
|
+
const children = input.resolveDynamic?.(resolverInputFor(input.block, prop, record, input.connectionId, input.reactorConnectionId)) ?? storedSchema(input.propertySettings, prop.name);
|
|
1013
|
+
if (children === void 0) {
|
|
1014
|
+
unknown = true;
|
|
1015
|
+
continue;
|
|
1016
|
+
}
|
|
1017
|
+
missing.push(...missingRequired(children, value));
|
|
1018
|
+
}
|
|
1019
|
+
if (missing.length > 0) return missing;
|
|
1020
|
+
if (form.display === "schedule") {
|
|
1021
|
+
const issue = scheduleConfigIssue(input.config);
|
|
1022
|
+
if (issue) return [issue.replace(/^Schedule: /, "")];
|
|
1023
|
+
}
|
|
1024
|
+
return unknown ? null : [];
|
|
1025
|
+
}
|
|
1026
|
+
function undeclaredPortIssues(form, outgoingPorts) {
|
|
1027
|
+
const ports = form && form !== "loading" ? form.ports : void 0;
|
|
1028
|
+
if (!ports || !outgoingPorts) return [];
|
|
1029
|
+
return [...new Set(outgoingPorts)].filter((port) => !ports.includes(port)).map((port) => `An edge leaves on "${port}", which this block never takes`);
|
|
1030
|
+
}
|
|
1031
|
+
function workflowReadiness(blocks, hasTrigger) {
|
|
1032
|
+
const firstIncomplete = blocks.find((block) => block.missing && block.missing.length > 0)?.id ?? null;
|
|
1033
|
+
const checking = blocks.some((block) => block.missing === null);
|
|
1034
|
+
return {
|
|
1035
|
+
ready: hasTrigger && !checking && firstIncomplete === null,
|
|
1036
|
+
hasTrigger,
|
|
1037
|
+
firstIncomplete,
|
|
1038
|
+
checking
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
//#endregion
|
|
1042
|
+
//#region editors/workflow-editor/ui/design-time.tsx
|
|
1043
|
+
const DesignTimeContext = createContext(null);
|
|
1044
|
+
function DesignTimeProvider(props) {
|
|
1045
|
+
const { service, queryClient, scope } = props;
|
|
1046
|
+
const value = useMemo(() => ({
|
|
1047
|
+
service,
|
|
1048
|
+
queryClient,
|
|
1049
|
+
scope
|
|
1050
|
+
}), [
|
|
1051
|
+
service,
|
|
1052
|
+
queryClient,
|
|
1053
|
+
scope
|
|
1054
|
+
]);
|
|
1055
|
+
return /* @__PURE__ */ jsx(DesignTimeContext.Provider, {
|
|
1056
|
+
value,
|
|
1057
|
+
children: props.children
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1060
|
+
function useDesignTime() {
|
|
1061
|
+
return useContext(DesignTimeContext)?.service;
|
|
1062
|
+
}
|
|
1063
|
+
function useDesignTimeScope() {
|
|
1064
|
+
const context = useContext(DesignTimeContext);
|
|
1065
|
+
const [detached] = useState(() => context ? null : {
|
|
1066
|
+
queryClient: new QueryClient(),
|
|
1067
|
+
scope: ""
|
|
1068
|
+
});
|
|
1069
|
+
return context ?? detached;
|
|
1070
|
+
}
|
|
1071
|
+
function messageOf(error) {
|
|
1072
|
+
return error instanceof Error ? error.message : String(error);
|
|
1073
|
+
}
|
|
1074
|
+
function useBlockForm(block) {
|
|
1075
|
+
const { service, queryClient, scope } = useDesignTimeScope();
|
|
1076
|
+
const query = useQuery({
|
|
1077
|
+
queryKey: runtimeKeys.form(scope, block),
|
|
1078
|
+
queryFn: () => service.getBlockForm(block),
|
|
1079
|
+
enabled: Boolean(service),
|
|
1080
|
+
staleTime: SHARED_STALE_MS
|
|
1081
|
+
}, queryClient);
|
|
1082
|
+
if (!service) return { form: null };
|
|
1083
|
+
if (query.data !== void 0) return { form: query.data };
|
|
1084
|
+
if (query.status === "error") return {
|
|
1085
|
+
form: null,
|
|
1086
|
+
error: messageOf(query.error)
|
|
1087
|
+
};
|
|
1088
|
+
return { form: "loading" };
|
|
1089
|
+
}
|
|
1090
|
+
function formQuery(service, scope, block) {
|
|
1091
|
+
return {
|
|
1092
|
+
queryKey: runtimeKeys.form(scope, block),
|
|
1093
|
+
queryFn: () => service.getBlockForm(block),
|
|
1094
|
+
staleTime: SHARED_STALE_MS
|
|
1095
|
+
};
|
|
1096
|
+
}
|
|
1097
|
+
function useBlockFormLoader() {
|
|
1098
|
+
const { service, queryClient, scope } = useDesignTimeScope();
|
|
1099
|
+
return useMemo(() => async (block) => {
|
|
1100
|
+
if (!service) return null;
|
|
1101
|
+
try {
|
|
1102
|
+
return await queryClient.fetchQuery(formQuery(service, scope, block));
|
|
1103
|
+
} catch {
|
|
1104
|
+
return null;
|
|
1105
|
+
}
|
|
1106
|
+
}, [
|
|
1107
|
+
service,
|
|
1108
|
+
queryClient,
|
|
1109
|
+
scope
|
|
1110
|
+
]);
|
|
1111
|
+
}
|
|
1112
|
+
function useCachedBlockForm() {
|
|
1113
|
+
const { queryClient, scope } = useDesignTimeScope();
|
|
1114
|
+
return useMemo(() => (block) => queryClient.getQueryData(runtimeKeys.form(scope, block)), [queryClient, scope]);
|
|
1115
|
+
}
|
|
1116
|
+
function useBlockFormPrefetch() {
|
|
1117
|
+
const { service, queryClient, scope } = useDesignTimeScope();
|
|
1118
|
+
return useMemo(() => (block) => {
|
|
1119
|
+
if (!service) return;
|
|
1120
|
+
queryClient.prefetchQuery(formQuery(service, scope, block));
|
|
1121
|
+
}, [
|
|
1122
|
+
service,
|
|
1123
|
+
queryClient,
|
|
1124
|
+
scope
|
|
1125
|
+
]);
|
|
1126
|
+
}
|
|
1127
|
+
function useBlockForms(blocks) {
|
|
1128
|
+
const { service, queryClient, scope } = useDesignTimeScope();
|
|
1129
|
+
const unique = [...new Map(blocks.map((block) => [blockRefKey(block), block])).values()];
|
|
1130
|
+
const results = useQueries({ queries: unique.map((block) => ({
|
|
1131
|
+
queryKey: runtimeKeys.form(scope, block),
|
|
1132
|
+
queryFn: () => service.getBlockForm(block),
|
|
1133
|
+
enabled: Boolean(service),
|
|
1134
|
+
staleTime: SHARED_STALE_MS
|
|
1135
|
+
})) }, queryClient);
|
|
1136
|
+
const forms = /* @__PURE__ */ new Map();
|
|
1137
|
+
unique.forEach((block, index) => {
|
|
1138
|
+
const query = results[index];
|
|
1139
|
+
forms.set(blockRefKey(block), !service ? null : query.data !== void 0 ? query.data : query.status === "error" ? null : "loading");
|
|
1140
|
+
});
|
|
1141
|
+
return forms;
|
|
1142
|
+
}
|
|
1143
|
+
function useBlockPorts(blocks) {
|
|
1144
|
+
const forms = useBlockForms(blocks);
|
|
1145
|
+
return (block) => {
|
|
1146
|
+
const form = forms.get(blockRefKey(block));
|
|
1147
|
+
return form && form !== "loading" ? form.ports : void 0;
|
|
1148
|
+
};
|
|
1149
|
+
}
|
|
1150
|
+
function keyHash(value) {
|
|
1151
|
+
try {
|
|
1152
|
+
return JSON.stringify(value);
|
|
1153
|
+
} catch {
|
|
1154
|
+
return String(value);
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
const SYNC_REFUSAL = /forbidden|document\b.*not found|was not found/i;
|
|
1158
|
+
const SYNC_RETRIES_MAX = 4;
|
|
1159
|
+
function retryWhileSyncing(input) {
|
|
1160
|
+
if (!input.reactorConnectionId) return {};
|
|
1161
|
+
return {
|
|
1162
|
+
retry: (failures, error) => failures < SYNC_RETRIES_MAX && SYNC_REFUSAL.test(messageOf(error)),
|
|
1163
|
+
retryDelay: 1e3
|
|
1164
|
+
};
|
|
1165
|
+
}
|
|
1166
|
+
function useSettled(value, ms) {
|
|
1167
|
+
const hash = keyHash(value);
|
|
1168
|
+
const latest = useRef(value);
|
|
1169
|
+
useEffect(() => {
|
|
1170
|
+
latest.current = value;
|
|
1171
|
+
});
|
|
1172
|
+
const [settled, setSettled] = useState({
|
|
1173
|
+
hash,
|
|
1174
|
+
value
|
|
1175
|
+
});
|
|
1176
|
+
useEffect(() => {
|
|
1177
|
+
if (hash === settled.hash) return;
|
|
1178
|
+
const timer = setTimeout(() => setSettled({
|
|
1179
|
+
hash,
|
|
1180
|
+
value: latest.current
|
|
1181
|
+
}), ms);
|
|
1182
|
+
return () => clearTimeout(timer);
|
|
1183
|
+
}, [
|
|
1184
|
+
hash,
|
|
1185
|
+
settled.hash,
|
|
1186
|
+
ms
|
|
1187
|
+
]);
|
|
1188
|
+
return settled.value;
|
|
1189
|
+
}
|
|
1190
|
+
function useResolvedProp(options) {
|
|
1191
|
+
const { queryClient, scope } = useDesignTimeScope();
|
|
1192
|
+
const input = useSettled(options.input, options.debounceMs);
|
|
1193
|
+
const loadRef = useRef(options);
|
|
1194
|
+
useEffect(() => {
|
|
1195
|
+
loadRef.current = options;
|
|
1196
|
+
});
|
|
1197
|
+
const enabled = Boolean(options.load);
|
|
1198
|
+
const query = useQuery({
|
|
1199
|
+
queryKey: runtimeKeys[options.kind](scope, input),
|
|
1200
|
+
queryFn: async () => {
|
|
1201
|
+
const current = loadRef.current;
|
|
1202
|
+
if (!current.load) throw new Error("No resolver");
|
|
1203
|
+
return current.parse(await current.load());
|
|
1204
|
+
},
|
|
1205
|
+
enabled,
|
|
1206
|
+
staleTime: RESOLVER_STALE_MS,
|
|
1207
|
+
...retryWhileSyncing(input)
|
|
1208
|
+
}, queryClient);
|
|
1209
|
+
const reload = () => void query.refetch();
|
|
1210
|
+
const syncing = query.isFetching && query.failureCount > 0;
|
|
1211
|
+
if (!enabled) return {
|
|
1212
|
+
state: { kind: "idle" },
|
|
1213
|
+
reload,
|
|
1214
|
+
syncing: false
|
|
1215
|
+
};
|
|
1216
|
+
if (query.isFetching) return {
|
|
1217
|
+
state: { kind: "loading" },
|
|
1218
|
+
reload,
|
|
1219
|
+
syncing
|
|
1220
|
+
};
|
|
1221
|
+
if (query.status === "error") return {
|
|
1222
|
+
state: {
|
|
1223
|
+
kind: "error",
|
|
1224
|
+
message: messageOf(query.error)
|
|
1225
|
+
},
|
|
1226
|
+
reload,
|
|
1227
|
+
syncing
|
|
1228
|
+
};
|
|
1229
|
+
if (query.status === "success") return {
|
|
1230
|
+
state: {
|
|
1231
|
+
kind: "ready",
|
|
1232
|
+
result: query.data
|
|
1233
|
+
},
|
|
1234
|
+
reload,
|
|
1235
|
+
syncing
|
|
1236
|
+
};
|
|
1237
|
+
return {
|
|
1238
|
+
state: { kind: "loading" },
|
|
1239
|
+
reload,
|
|
1240
|
+
syncing
|
|
1241
|
+
};
|
|
1242
|
+
}
|
|
1243
|
+
function useOptionSearch(options) {
|
|
1244
|
+
const { queryClient, scope } = useDesignTimeScope();
|
|
1245
|
+
const typed = options.query.trim() === "" ? "" : options.query;
|
|
1246
|
+
const settled = useSettled(typed, options.debounceMs);
|
|
1247
|
+
const loadRef = useRef(options);
|
|
1248
|
+
useEffect(() => {
|
|
1249
|
+
loadRef.current = options;
|
|
1250
|
+
});
|
|
1251
|
+
const query = useQuery({
|
|
1252
|
+
queryKey: runtimeKeys.options(scope, {
|
|
1253
|
+
...options.input,
|
|
1254
|
+
searchValue: settled
|
|
1255
|
+
}),
|
|
1256
|
+
queryFn: async () => {
|
|
1257
|
+
const current = loadRef.current;
|
|
1258
|
+
if (!current.load) throw new Error("No resolver");
|
|
1259
|
+
return current.parse(await current.load(settled));
|
|
1260
|
+
},
|
|
1261
|
+
enabled: Boolean(options.load) && settled !== "" && typed !== "",
|
|
1262
|
+
staleTime: RESOLVER_STALE_MS,
|
|
1263
|
+
...retryWhileSyncing(options.input),
|
|
1264
|
+
placeholderData: keepPreviousData
|
|
1265
|
+
}, queryClient);
|
|
1266
|
+
return typed === "" ? null : query.data ?? null;
|
|
1267
|
+
}
|
|
1268
|
+
function getResolvedDynamicProps(queryClient, scope, input) {
|
|
1269
|
+
return queryClient.getQueryData(runtimeKeys.dynamic(scope, input));
|
|
1270
|
+
}
|
|
1271
|
+
function useDynamicPrefetch() {
|
|
1272
|
+
const { service, queryClient, scope } = useDesignTimeScope();
|
|
1273
|
+
return useMemo(() => (input, config) => {
|
|
1274
|
+
if (!service) return;
|
|
1275
|
+
queryClient.prefetchQuery({
|
|
1276
|
+
queryKey: runtimeKeys.dynamic(scope, input),
|
|
1277
|
+
queryFn: () => service.loadOptions(input.block, input.propName, config, input.connectionId ?? void 0, void 0, input.reactorConnectionId ?? void 0).then(parsePropList),
|
|
1278
|
+
staleTime: RESOLVER_STALE_MS,
|
|
1279
|
+
...retryWhileSyncing(input)
|
|
1280
|
+
});
|
|
1281
|
+
}, [
|
|
1282
|
+
service,
|
|
1283
|
+
queryClient,
|
|
1284
|
+
scope
|
|
1285
|
+
]);
|
|
1286
|
+
}
|
|
1287
|
+
function useDynamicCache() {
|
|
1288
|
+
const { queryClient, scope } = useDesignTimeScope();
|
|
1289
|
+
return useMemo(() => (input) => getResolvedDynamicProps(queryClient, scope, input), [queryClient, scope]);
|
|
1290
|
+
}
|
|
1291
|
+
function useDynamicLookup() {
|
|
1292
|
+
const { queryClient, scope } = useDesignTimeScope();
|
|
1293
|
+
const [version, setVersion] = useState(0);
|
|
1294
|
+
useEffect(() => queryClient.getQueryCache().subscribe((event) => {
|
|
1295
|
+
if (event.type !== "updated") return;
|
|
1296
|
+
const key = event.query.queryKey;
|
|
1297
|
+
if (key[0] === scope && key[1] === "dynamic") setVersion((v) => v + 1);
|
|
1298
|
+
}), [queryClient, scope]);
|
|
1299
|
+
return useMemo(() => (input) => version >= 0 ? getResolvedDynamicProps(queryClient, scope, input) : void 0, [
|
|
1300
|
+
queryClient,
|
|
1301
|
+
scope,
|
|
1302
|
+
version
|
|
1303
|
+
]);
|
|
1304
|
+
}
|
|
1305
|
+
function useRunById(runId) {
|
|
1306
|
+
const { service, queryClient, scope } = useDesignTimeScope();
|
|
1307
|
+
const fetchRun = service?.fetchRun;
|
|
1308
|
+
const query = useQuery({
|
|
1309
|
+
queryKey: runtimeKeys.run(scope, runId ?? ""),
|
|
1310
|
+
queryFn: () => fetchRun(runId),
|
|
1311
|
+
enabled: Boolean(fetchRun && runId),
|
|
1312
|
+
staleTime: Infinity
|
|
1313
|
+
}, queryClient);
|
|
1314
|
+
if (!runId) return null;
|
|
1315
|
+
return query.data;
|
|
1316
|
+
}
|
|
1317
|
+
function useLatestRun(enabled = true) {
|
|
1318
|
+
const { service, queryClient, scope } = useDesignTimeScope();
|
|
1319
|
+
const active = enabled && Boolean(service?.latestRun);
|
|
1320
|
+
const query = useQuery({
|
|
1321
|
+
queryKey: runtimeKeys.latestRun(scope, service?.workflowId ?? ""),
|
|
1322
|
+
queryFn: () => service.latestRun(),
|
|
1323
|
+
enabled: active,
|
|
1324
|
+
staleTime: 0
|
|
1325
|
+
}, queryClient);
|
|
1326
|
+
if (!active) return null;
|
|
1327
|
+
if (query.status === "pending") return { kind: "loading" };
|
|
1328
|
+
return {
|
|
1329
|
+
kind: "ready",
|
|
1330
|
+
run: query.data ?? null
|
|
1331
|
+
};
|
|
1332
|
+
}
|
|
1333
|
+
const SYNC_RETRIES = 5;
|
|
1334
|
+
const SYNC_RETRY_MS = 2e3;
|
|
1335
|
+
function useWebhookEndpoint(enabled) {
|
|
1336
|
+
const { service, queryClient, scope } = useDesignTimeScope();
|
|
1337
|
+
const active = enabled && Boolean(service?.webhookEndpoint);
|
|
1338
|
+
const query = useQuery({
|
|
1339
|
+
queryKey: runtimeKeys.webhook(scope, service?.workflowId ?? ""),
|
|
1340
|
+
queryFn: () => service.webhookEndpoint(),
|
|
1341
|
+
enabled: active,
|
|
1342
|
+
staleTime: 0,
|
|
1343
|
+
gcTime: 0,
|
|
1344
|
+
retry: (failures, error) => isSyncingError(error) && failures < SYNC_RETRIES,
|
|
1345
|
+
retryDelay: SYNC_RETRY_MS
|
|
1346
|
+
}, queryClient);
|
|
1347
|
+
if (query.status === "pending" && isSyncingError(query.failureReason)) return { kind: "syncing" };
|
|
1348
|
+
if (query.status === "error") return {
|
|
1349
|
+
kind: "error",
|
|
1350
|
+
message: messageOf(query.error)
|
|
1351
|
+
};
|
|
1352
|
+
if (query.status === "pending") return { kind: "loading" };
|
|
1353
|
+
return query.data ? {
|
|
1354
|
+
kind: "ready",
|
|
1355
|
+
endpoint: query.data
|
|
1356
|
+
} : { kind: "empty" };
|
|
1357
|
+
}
|
|
1358
|
+
function useConnectionList() {
|
|
1359
|
+
const { service, queryClient, scope } = useDesignTimeScope();
|
|
1360
|
+
const list = service?.listConnections;
|
|
1361
|
+
const options = {
|
|
1362
|
+
queryKey: runtimeKeys.connections(scope, service?.connectionScope ?? null),
|
|
1363
|
+
queryFn: () => list(),
|
|
1364
|
+
staleTime: 0,
|
|
1365
|
+
gcTime: 0
|
|
1366
|
+
};
|
|
1367
|
+
const query = useQuery({
|
|
1368
|
+
...options,
|
|
1369
|
+
enabled: Boolean(list)
|
|
1370
|
+
}, queryClient);
|
|
1371
|
+
return {
|
|
1372
|
+
connections: query.data ?? [],
|
|
1373
|
+
refetch: () => {
|
|
1374
|
+
if (list) query.refetch();
|
|
1375
|
+
},
|
|
1376
|
+
invalidate: () => void queryClient.invalidateQueries({ queryKey: runtimeKeys.connections(scope) }),
|
|
1377
|
+
fetchNow: () => list ? queryClient.fetchQuery({
|
|
1378
|
+
...options,
|
|
1379
|
+
staleTime: 0
|
|
1380
|
+
}) : Promise.resolve([])
|
|
1381
|
+
};
|
|
1382
|
+
}
|
|
1383
|
+
function useTestStepRunner() {
|
|
1384
|
+
const { service, queryClient, scope } = useDesignTimeScope();
|
|
1385
|
+
const test = service?.testStep;
|
|
1386
|
+
if (!test) return void 0;
|
|
1387
|
+
return (stepId) => test(stepId).finally(() => {
|
|
1388
|
+
for (const queryKey of [
|
|
1389
|
+
runtimeKeys.allRuns(scope),
|
|
1390
|
+
[scope, "latestRun"],
|
|
1391
|
+
runtimeKeys.outputTrees(scope)
|
|
1392
|
+
]) queryClient.invalidateQueries({ queryKey });
|
|
1393
|
+
});
|
|
1394
|
+
}
|
|
1395
|
+
function useTestTrigger() {
|
|
1396
|
+
const { service, queryClient, scope } = useDesignTimeScope();
|
|
1397
|
+
const test = service?.testTrigger;
|
|
1398
|
+
if (!test) return void 0;
|
|
1399
|
+
return () => test().finally(() => void queryClient.invalidateQueries({ queryKey: runtimeKeys.outputTrees(scope) }));
|
|
1400
|
+
}
|
|
1401
|
+
var DraftNotSynced = class extends Error {};
|
|
1402
|
+
const DRAFT_SYNC_RETRIES = 10;
|
|
1403
|
+
/**
|
|
1404
|
+
* The piece version each draft block runs, trigger first; `blocks` is the
|
|
1405
|
+
* draft in that order. Empty outside a runtime, or until the runtime answers.
|
|
1406
|
+
*/
|
|
1407
|
+
function useBlockResolutions(workflowId, blocks) {
|
|
1408
|
+
const { service, queryClient, scope } = useDesignTimeScope();
|
|
1409
|
+
const fetchResolutions = service?.blockResolutions;
|
|
1410
|
+
const expected = blocks.map((entry) => `${entry.id}=${blockRefKey(entry.block)}`);
|
|
1411
|
+
return useQuery({
|
|
1412
|
+
queryKey: runtimeKeys.blockResolutions(scope, workflowId, blocks.map((entry) => entry.block)),
|
|
1413
|
+
queryFn: async () => {
|
|
1414
|
+
const resolutions = await fetchResolutions();
|
|
1415
|
+
if (keyHash(resolutions.map((resolution) => `${resolution.stepId}=${blockRefKey(resolution)}`)) !== keyHash(expected)) throw new DraftNotSynced();
|
|
1416
|
+
return resolutions;
|
|
1417
|
+
},
|
|
1418
|
+
enabled: Boolean(fetchResolutions && workflowId),
|
|
1419
|
+
retry: (count, error) => error instanceof DraftNotSynced && count < DRAFT_SYNC_RETRIES,
|
|
1420
|
+
retryDelay: 300,
|
|
1421
|
+
placeholderData: keepPreviousData,
|
|
1422
|
+
staleTime: 0
|
|
1423
|
+
}, queryClient).data ?? EMPTY_RESOLUTIONS;
|
|
1424
|
+
}
|
|
1425
|
+
const EMPTY_RESOLUTIONS = [];
|
|
1426
|
+
//#endregion
|
|
1427
|
+
//#region editors/workflow-studio/components/run-format.ts
|
|
1428
|
+
const RUN_STATUSES = [
|
|
1429
|
+
"RUNNING",
|
|
1430
|
+
"SUCCEEDED",
|
|
1431
|
+
"FAILED"
|
|
1432
|
+
];
|
|
1433
|
+
const TONE_TEXT = {
|
|
1434
|
+
ok: "text-wf-ok",
|
|
1435
|
+
fail: "text-wf-fail",
|
|
1436
|
+
warn: "text-wf-warn",
|
|
1437
|
+
run: "text-wf-run",
|
|
1438
|
+
idle: "text-muted-foreground"
|
|
1439
|
+
};
|
|
1440
|
+
const TONE_DOT = {
|
|
1441
|
+
ok: "bg-wf-ok",
|
|
1442
|
+
fail: "bg-wf-fail",
|
|
1443
|
+
warn: "bg-wf-warn",
|
|
1444
|
+
run: "bg-wf-run",
|
|
1445
|
+
idle: "bg-muted-foreground/40"
|
|
1446
|
+
};
|
|
1447
|
+
const RUN_TONE = {
|
|
1448
|
+
SUCCEEDED: "ok",
|
|
1449
|
+
FAILED: "fail",
|
|
1450
|
+
RUNNING: "run",
|
|
1451
|
+
WAITING: "run",
|
|
1452
|
+
PENDING: "idle",
|
|
1453
|
+
PARKED: "warn",
|
|
1454
|
+
CANCELLED: "idle"
|
|
1455
|
+
};
|
|
1456
|
+
const STEP_TONE = {
|
|
1457
|
+
...RUN_TONE,
|
|
1458
|
+
SKIPPED: "idle",
|
|
1459
|
+
REPLAYED: "run",
|
|
1460
|
+
INDETERMINATE: "warn"
|
|
1461
|
+
};
|
|
1462
|
+
function runTone(run) {
|
|
1463
|
+
if (run.status === "SUCCEEDED" && (run.warningNotes?.length ?? 0) > 0) return "warn";
|
|
1464
|
+
return toneOf(RUN_TONE, run.status);
|
|
1465
|
+
}
|
|
1466
|
+
function runStatusLabel(run) {
|
|
1467
|
+
const count = run.warningNotes?.length ?? 0;
|
|
1468
|
+
const label = statusLabel(run.status);
|
|
1469
|
+
if (run.status !== "SUCCEEDED" || count === 0) return label;
|
|
1470
|
+
return `${label}, ${count} ${count === 1 ? "warning" : "warnings"}`;
|
|
1471
|
+
}
|
|
1472
|
+
function workflowHealth(status, lastRunStatus, published) {
|
|
1473
|
+
if (!published) return {
|
|
1474
|
+
tone: "idle",
|
|
1475
|
+
hollow: true,
|
|
1476
|
+
label: "Not published yet"
|
|
1477
|
+
};
|
|
1478
|
+
const label = (status === "ENABLED" ? "" : `${statusLabel(status ?? "DISABLED")}, `) + (lastRunStatus ? `last run ${statusLabel(lastRunStatus).toLowerCase()}` : "not run yet");
|
|
1479
|
+
return {
|
|
1480
|
+
tone: toneOf(RUN_TONE, lastRunStatus),
|
|
1481
|
+
hollow: false,
|
|
1482
|
+
label: label.charAt(0).toUpperCase() + label.slice(1)
|
|
1483
|
+
};
|
|
1484
|
+
}
|
|
1485
|
+
const CONNECTION_TONE = {
|
|
1486
|
+
OK: "ok",
|
|
1487
|
+
ERROR: "fail",
|
|
1488
|
+
REVOKED: "fail",
|
|
1489
|
+
UNCONFIGURED: "warn"
|
|
1490
|
+
};
|
|
1491
|
+
function toneOf(map, status) {
|
|
1492
|
+
return (status ? map[status] : void 0) ?? "idle";
|
|
1493
|
+
}
|
|
1494
|
+
function statusLabel(status) {
|
|
1495
|
+
return status.charAt(0) + status.slice(1).toLowerCase();
|
|
1496
|
+
}
|
|
1497
|
+
function formatDuration(startedAt, endedAt) {
|
|
1498
|
+
if (!endedAt) return "…";
|
|
1499
|
+
return formatMs(new Date(endedAt).getTime() - new Date(startedAt).getTime());
|
|
1500
|
+
}
|
|
1501
|
+
function runTimeline(run) {
|
|
1502
|
+
const start = new Date(run.startedAt).getTime();
|
|
1503
|
+
const ends = run.steps.map((step) => step.endedAt ? new Date(step.endedAt).getTime() : 0).concat(run.endedAt ? new Date(run.endedAt).getTime() : 0);
|
|
1504
|
+
const total = Math.max(...ends) - start;
|
|
1505
|
+
const spans = /* @__PURE__ */ new Map();
|
|
1506
|
+
if (total <= 0) return spans;
|
|
1507
|
+
for (const step of run.steps) {
|
|
1508
|
+
if (!step.startedAt || !step.endedAt) continue;
|
|
1509
|
+
const from = new Date(step.startedAt).getTime() - start;
|
|
1510
|
+
const ms = new Date(step.endedAt).getTime() - new Date(step.startedAt).getTime();
|
|
1511
|
+
spans.set(step.stepId, {
|
|
1512
|
+
offset: Math.min(Math.max(from / total, 0), 1),
|
|
1513
|
+
width: Math.min(Math.max(ms / total, 0), 1),
|
|
1514
|
+
ms
|
|
1515
|
+
});
|
|
1516
|
+
}
|
|
1517
|
+
return spans;
|
|
1518
|
+
}
|
|
1519
|
+
function formatMs(ms) {
|
|
1520
|
+
if (ms < 1e3) return `${ms}ms`;
|
|
1521
|
+
const tenths = Math.round(ms / 100);
|
|
1522
|
+
if (tenths < 600) return `${(tenths / 10).toFixed(1)}s`;
|
|
1523
|
+
const seconds = Math.round(ms / 1e3);
|
|
1524
|
+
return `${Math.floor(seconds / 60)}m ${seconds % 60}s`;
|
|
1525
|
+
}
|
|
1526
|
+
function durationMs(startedAt, endedAt) {
|
|
1527
|
+
if (!endedAt) return null;
|
|
1528
|
+
return new Date(endedAt).getTime() - new Date(startedAt).getTime();
|
|
1529
|
+
}
|
|
1530
|
+
function formatWhen(startedAt) {
|
|
1531
|
+
const diff = Date.now() - new Date(startedAt).getTime();
|
|
1532
|
+
if (diff < 6e4) return "just now";
|
|
1533
|
+
if (diff < 36e5) return `${Math.floor(diff / 6e4)}m ago`;
|
|
1534
|
+
if (diff < 864e5) return `${Math.floor(diff / 36e5)}h ago`;
|
|
1535
|
+
return new Date(startedAt).toLocaleDateString();
|
|
1536
|
+
}
|
|
1537
|
+
function formatAbsolute(iso) {
|
|
1538
|
+
return new Date(iso).toLocaleString();
|
|
1539
|
+
}
|
|
1540
|
+
function formatTrigger(kind) {
|
|
1541
|
+
return kind.replace(/[-_]/g, " ").toLowerCase();
|
|
1542
|
+
}
|
|
1543
|
+
function runStats(runs) {
|
|
1544
|
+
const succeeded = runs.filter((run) => run.status === "SUCCEEDED").length;
|
|
1545
|
+
const failed = runs.filter((run) => run.status === "FAILED").length;
|
|
1546
|
+
const finished = succeeded + failed;
|
|
1547
|
+
return {
|
|
1548
|
+
total: runs.length,
|
|
1549
|
+
succeeded,
|
|
1550
|
+
failed,
|
|
1551
|
+
running: runs.filter((run) => run.status === "RUNNING").length,
|
|
1552
|
+
lastRun: runs[0],
|
|
1553
|
+
successRate: finished === 0 ? null : Math.round(succeeded / finished * 100)
|
|
1554
|
+
};
|
|
1555
|
+
}
|
|
1556
|
+
const RUN_DEADLINE_ERROR_NAME = "RunDeadlineExceeded";
|
|
1557
|
+
function canRerun(run) {
|
|
1558
|
+
return run.status === "FAILED" || run.status === "CANCELLED" && run.errorName === RUN_DEADLINE_ERROR_NAME;
|
|
1559
|
+
}
|
|
1560
|
+
//#endregion
|
|
1561
|
+
//#region editors/workflow-editor/ui/block-meta.ts
|
|
1562
|
+
const CORE_META = {
|
|
1563
|
+
[blockKey(MANUAL_TRIGGER)]: {
|
|
1564
|
+
displayName: "Manual",
|
|
1565
|
+
subtitle: "Trigger",
|
|
1566
|
+
glyph: "▶"
|
|
1567
|
+
},
|
|
1568
|
+
[blockKey(SCHEDULE_TRIGGER)]: {
|
|
1569
|
+
displayName: "Schedule",
|
|
1570
|
+
subtitle: "Trigger",
|
|
1571
|
+
glyph: "◷"
|
|
1572
|
+
},
|
|
1573
|
+
[blockKey(WEBHOOK_TRIGGER)]: {
|
|
1574
|
+
displayName: "Webhook",
|
|
1575
|
+
subtitle: "Trigger",
|
|
1576
|
+
glyph: "⇲"
|
|
1577
|
+
},
|
|
1578
|
+
[blockKey(BRANCH_BLOCK)]: {
|
|
1579
|
+
displayName: "Branch",
|
|
1580
|
+
subtitle: "Core",
|
|
1581
|
+
glyph: "⑂"
|
|
1582
|
+
},
|
|
1583
|
+
[blockKey(ASSERT_BLOCK)]: {
|
|
1584
|
+
displayName: "Assert",
|
|
1585
|
+
subtitle: "Core",
|
|
1586
|
+
glyph: "!"
|
|
1587
|
+
}
|
|
1588
|
+
};
|
|
1589
|
+
function shortPieceName(packageName) {
|
|
1590
|
+
return packageName.split("/").pop()?.replace(/^piece-/, "") ?? "";
|
|
1591
|
+
}
|
|
1592
|
+
const pieceLogos = /* @__PURE__ */ new Map();
|
|
1593
|
+
const pieceNames = /* @__PURE__ */ new Map();
|
|
1594
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
1595
|
+
let logoRevision = 0;
|
|
1596
|
+
function registerPieceLogos(entries) {
|
|
1597
|
+
let changed = false;
|
|
1598
|
+
for (const entry of entries) {
|
|
1599
|
+
if (!entry.name) continue;
|
|
1600
|
+
if (entry.displayName && pieceNames.get(entry.name) !== entry.displayName) {
|
|
1601
|
+
pieceNames.set(entry.name, entry.displayName);
|
|
1602
|
+
changed = true;
|
|
1603
|
+
}
|
|
1604
|
+
if (!entry.logoUrl || pieceLogos.get(entry.name) === entry.logoUrl) continue;
|
|
1605
|
+
pieceLogos.set(entry.name, entry.logoUrl);
|
|
1606
|
+
changed = true;
|
|
1607
|
+
}
|
|
1608
|
+
if (!changed) return;
|
|
1609
|
+
logoRevision += 1;
|
|
1610
|
+
for (const listener of listeners) listener();
|
|
1611
|
+
}
|
|
1612
|
+
function pieceLogo(packageName) {
|
|
1613
|
+
return pieceLogos.get(packageName);
|
|
1614
|
+
}
|
|
1615
|
+
function pieceDisplayName(packageName) {
|
|
1616
|
+
return pieceNames.get(packageName);
|
|
1617
|
+
}
|
|
1618
|
+
const blockNames = /* @__PURE__ */ new Map();
|
|
1619
|
+
const namesRequested = /* @__PURE__ */ new Set();
|
|
1620
|
+
const namesPending = /* @__PURE__ */ new Set();
|
|
1621
|
+
function registerBlockNames(entries) {
|
|
1622
|
+
let changed = false;
|
|
1623
|
+
for (const entry of entries) {
|
|
1624
|
+
const key = blockKey(entry);
|
|
1625
|
+
if (!entry.displayName || blockNames.get(key) === entry.displayName) continue;
|
|
1626
|
+
blockNames.set(key, entry.displayName);
|
|
1627
|
+
changed = true;
|
|
1628
|
+
}
|
|
1629
|
+
if (!changed) return;
|
|
1630
|
+
logoRevision += 1;
|
|
1631
|
+
for (const listener of listeners) listener();
|
|
1632
|
+
}
|
|
1633
|
+
function requestBlockNames(packageName) {
|
|
1634
|
+
if (!namesRequested.has(packageName)) namesPending.add(packageName);
|
|
1635
|
+
}
|
|
1636
|
+
function loadPendingBlockNames(source) {
|
|
1637
|
+
for (const packageName of namesPending) loadBlockNames(source, packageName);
|
|
1638
|
+
namesPending.clear();
|
|
1639
|
+
}
|
|
1640
|
+
function loadBlockNames(source, packageName) {
|
|
1641
|
+
if (namesRequested.has(packageName)) return;
|
|
1642
|
+
namesRequested.add(packageName);
|
|
1643
|
+
Promise.all([source.loadActions(packageName), source.loadTriggers(packageName)]).then(([actions, triggers]) => registerBlockNames([...actions.map((entry) => ({
|
|
1644
|
+
...entry,
|
|
1645
|
+
kind: "action"
|
|
1646
|
+
})), ...triggers.map((entry) => ({
|
|
1647
|
+
...entry,
|
|
1648
|
+
kind: "trigger"
|
|
1649
|
+
}))])).catch(() => namesRequested.delete(packageName));
|
|
1650
|
+
}
|
|
1651
|
+
function subscribePieceLogos(listener) {
|
|
1652
|
+
listeners.add(listener);
|
|
1653
|
+
return () => listeners.delete(listener);
|
|
1654
|
+
}
|
|
1655
|
+
function pieceLogoRevision() {
|
|
1656
|
+
return logoRevision;
|
|
1657
|
+
}
|
|
1658
|
+
const logoMisses = /* @__PURE__ */ new Set();
|
|
1659
|
+
let catalogLoads = /* @__PURE__ */ new WeakMap();
|
|
1660
|
+
const retryTimers = /* @__PURE__ */ new Set();
|
|
1661
|
+
const CATALOG_RETRY_MS = 2e3;
|
|
1662
|
+
function notify() {
|
|
1663
|
+
logoRevision += 1;
|
|
1664
|
+
for (const listener of listeners) listener();
|
|
1665
|
+
}
|
|
1666
|
+
function scheduleRetry(state) {
|
|
1667
|
+
if (state.attempts >= 5) return;
|
|
1668
|
+
const timer = setTimeout(() => {
|
|
1669
|
+
retryTimers.delete(timer);
|
|
1670
|
+
state.load = void 0;
|
|
1671
|
+
notify();
|
|
1672
|
+
}, CATALOG_RETRY_MS * 2 ** (state.attempts - 1));
|
|
1673
|
+
retryTimers.add(timer);
|
|
1674
|
+
}
|
|
1675
|
+
function ensurePieceLogos(source) {
|
|
1676
|
+
if (!source) return Promise.resolve();
|
|
1677
|
+
let state = catalogLoads.get(source);
|
|
1678
|
+
if (!state) {
|
|
1679
|
+
state = { attempts: 0 };
|
|
1680
|
+
catalogLoads.set(source, state);
|
|
1681
|
+
}
|
|
1682
|
+
if (state.load) return state.load;
|
|
1683
|
+
const current = state;
|
|
1684
|
+
const request = current.attempts > 0 && source.reloadCatalog ? source.reloadCatalog() : source.loadCatalog();
|
|
1685
|
+
current.attempts += 1;
|
|
1686
|
+
current.load = request.then((pieces) => {
|
|
1687
|
+
registerPieceLogos(pieces);
|
|
1688
|
+
const listed = new Set(pieces.map((piece) => piece.name));
|
|
1689
|
+
if ([...logoMisses].some((name) => !listed.has(name) && !pieceLogos.has(name))) scheduleRetry(current);
|
|
1690
|
+
}, () => scheduleRetry(current));
|
|
1691
|
+
return current.load;
|
|
1692
|
+
}
|
|
1693
|
+
function blockMeta(block) {
|
|
1694
|
+
const key = blockKey(block);
|
|
1695
|
+
const core = CORE_META[key];
|
|
1696
|
+
if (core) return core;
|
|
1697
|
+
if (isCoreBlock(block)) return {
|
|
1698
|
+
displayName: titleCase(block.name),
|
|
1699
|
+
subtitle: "Core",
|
|
1700
|
+
glyph: "?"
|
|
1701
|
+
};
|
|
1702
|
+
const packageName = block.pieceName;
|
|
1703
|
+
const short = shortPieceName(packageName);
|
|
1704
|
+
const pieceLabel = pieceNames.get(packageName) ?? titleCase(short);
|
|
1705
|
+
const known = blockNames.get(key);
|
|
1706
|
+
if (!known) requestBlockNames(packageName);
|
|
1707
|
+
const logoUrl = pieceLogo(packageName);
|
|
1708
|
+
if (!logoUrl) logoMisses.add(packageName);
|
|
1709
|
+
return {
|
|
1710
|
+
displayName: known ?? titleCase(block.name),
|
|
1711
|
+
subtitle: block.kind === "trigger" ? `${pieceLabel} · Trigger` : pieceLabel,
|
|
1712
|
+
logoUrl,
|
|
1713
|
+
glyph: short.slice(0, 1).toUpperCase() || "?"
|
|
1714
|
+
};
|
|
1715
|
+
}
|
|
1716
|
+
function titleCase(value) {
|
|
1717
|
+
return value.replaceAll(/[-_]/g, " ").replace(/^\w/, (char) => char.toUpperCase());
|
|
1718
|
+
}
|
|
1719
|
+
function usePieceLogos() {
|
|
1720
|
+
const source = usePieceSource();
|
|
1721
|
+
const revision = useSyncExternalStore(subscribePieceLogos, pieceLogoRevision, pieceLogoRevision);
|
|
1722
|
+
useEffect(() => {
|
|
1723
|
+
ensurePieceLogos(source);
|
|
1724
|
+
if (source && namesPending.size > 0) loadPendingBlockNames(source);
|
|
1725
|
+
});
|
|
1726
|
+
return revision;
|
|
1727
|
+
}
|
|
1728
|
+
function useBlockMeta(block) {
|
|
1729
|
+
usePieceLogos();
|
|
1730
|
+
return blockMeta(block);
|
|
1731
|
+
}
|
|
1732
|
+
//#endregion
|
|
1733
|
+
//#region editors/workflow-editor/ui/version-badge.tsx
|
|
1734
|
+
function resolutionText(resolution) {
|
|
1735
|
+
if (resolution.note) return resolution.note;
|
|
1736
|
+
if (!resolution.resolvedVersion) return `Nothing resolves ${resolution.pieceName} ${resolution.kind} "${resolution.name}"`;
|
|
1737
|
+
const from = resolution.source ? ` from ${resolution.source}` : "";
|
|
1738
|
+
return `Configured with v${resolution.pieceVersion}, runs v${resolution.resolvedVersion}${from}`;
|
|
1739
|
+
}
|
|
1740
|
+
function runsDifferentVersion(resolution) {
|
|
1741
|
+
switch (resolution.match) {
|
|
1742
|
+
case "exact": return false;
|
|
1743
|
+
case "installed": return resolution.resolvedVersion !== resolution.pieceVersion;
|
|
1744
|
+
default: return true;
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
function versionBadge(resolution) {
|
|
1748
|
+
if (!resolution || !runsDifferentVersion(resolution)) return null;
|
|
1749
|
+
const title = resolutionText(resolution);
|
|
1750
|
+
if (resolution.match === "missing") return {
|
|
1751
|
+
tone: "fail",
|
|
1752
|
+
label: "Missing",
|
|
1753
|
+
title
|
|
1754
|
+
};
|
|
1755
|
+
return {
|
|
1756
|
+
tone: resolution.match === "fallback" ? "warn" : "neutral",
|
|
1757
|
+
label: `v${resolution.resolvedVersion}`,
|
|
1758
|
+
title
|
|
1759
|
+
};
|
|
1760
|
+
}
|
|
1761
|
+
/** The newer version to offer, when a source has one above the pin. */
|
|
1762
|
+
function updateVersion(resolution) {
|
|
1763
|
+
const { pieceVersion, latestVersion } = resolution ?? {};
|
|
1764
|
+
if (!pieceVersion || !latestVersion) return null;
|
|
1765
|
+
try {
|
|
1766
|
+
return compareVersions(latestVersion, pieceVersion) > 0 ? latestVersion : null;
|
|
1767
|
+
} catch {
|
|
1768
|
+
return null;
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
const ResolutionsContext = createContext([]);
|
|
1772
|
+
const DraftBlocksContext = createContext([]);
|
|
1773
|
+
function BlockResolutionsProvider(props) {
|
|
1774
|
+
return /* @__PURE__ */ jsx(DraftBlocksContext.Provider, {
|
|
1775
|
+
value: props.blocks,
|
|
1776
|
+
children: /* @__PURE__ */ jsx(ResolutionsContext.Provider, {
|
|
1777
|
+
value: props.resolutions,
|
|
1778
|
+
children: props.children
|
|
1779
|
+
})
|
|
1780
|
+
});
|
|
1781
|
+
}
|
|
1782
|
+
function useDraftBlocks() {
|
|
1783
|
+
return useContext(DraftBlocksContext);
|
|
1784
|
+
}
|
|
1785
|
+
function useResolution(id, block) {
|
|
1786
|
+
return useContext(ResolutionsContext).find((entry) => entry.stepId === id && entry.pieceName === block.pieceName && entry.pieceVersion === block.pieceVersion && entry.kind === block.kind && entry.name === block.name);
|
|
1787
|
+
}
|
|
1788
|
+
const SUMMARY_TONE = {
|
|
1789
|
+
neutral: "text-muted-foreground hover:text-foreground",
|
|
1790
|
+
warn: "text-wf-warn"
|
|
1791
|
+
};
|
|
1792
|
+
function versionSummary(resolutions) {
|
|
1793
|
+
const differing = resolutions.filter(runsDifferentVersion);
|
|
1794
|
+
if (differing.length === 0) return null;
|
|
1795
|
+
const missing = differing.filter((entry) => entry.match === "missing");
|
|
1796
|
+
const count = missing.length > 0 ? missing.length : differing.length;
|
|
1797
|
+
const noun = count === 1 ? "step" : "steps";
|
|
1798
|
+
return {
|
|
1799
|
+
text: missing.length > 0 ? `${count} ${noun} can't find ${count === 1 ? "its" : "their"} piece` : `${count} ${noun} ${count === 1 ? "runs" : "run"} a different piece version`,
|
|
1800
|
+
tone: differing.some((entry) => entry.match === "fallback" || entry.match === "missing") ? "warn" : "neutral",
|
|
1801
|
+
title: differing.map(resolutionText).join("\n"),
|
|
1802
|
+
firstStepId: (missing.length > 0 ? missing : differing)[0].stepId
|
|
1803
|
+
};
|
|
1804
|
+
}
|
|
1805
|
+
function VersionSummary(props) {
|
|
1806
|
+
const summary = versionSummary(props.resolutions);
|
|
1807
|
+
if (!summary) return null;
|
|
1808
|
+
return /* @__PURE__ */ jsx("button", {
|
|
1809
|
+
type: "button",
|
|
1810
|
+
"data-tone": summary.tone,
|
|
1811
|
+
className: `truncate text-xs underline-offset-2 hover:underline ${SUMMARY_TONE[summary.tone]}`,
|
|
1812
|
+
title: summary.title,
|
|
1813
|
+
onClick: () => props.onSelect(summary.firstStepId),
|
|
1814
|
+
children: summary.text
|
|
1815
|
+
});
|
|
1816
|
+
}
|
|
1817
|
+
//#endregion
|
|
1818
|
+
//#region editors/workflow-editor/ui/picker-placement.ts
|
|
1819
|
+
const MARGIN = 8;
|
|
1820
|
+
const GAP = 6;
|
|
1821
|
+
const MIN_HEIGHT = 240;
|
|
1822
|
+
function pickerPlacement(anchor, size, viewport) {
|
|
1823
|
+
const width = Math.min(size.width, viewport.width - 16);
|
|
1824
|
+
const below = viewport.height - anchor.bottom - GAP - MARGIN;
|
|
1825
|
+
const above = anchor.top - GAP - MARGIN;
|
|
1826
|
+
const downward = below >= Math.min(size.height, MIN_HEIGHT) || below >= above;
|
|
1827
|
+
const height = Math.max(Math.min(size.height, downward ? below : above), Math.min(size.height, MIN_HEIGHT));
|
|
1828
|
+
const centre = (anchor.left + anchor.right) / 2;
|
|
1829
|
+
const left = Math.min(Math.max(centre - width / 2, MARGIN), viewport.width - width - MARGIN);
|
|
1830
|
+
const top = downward ? Math.min(anchor.bottom + GAP, viewport.height - height - MARGIN) : Math.max(anchor.top - GAP - height, MARGIN);
|
|
1831
|
+
return {
|
|
1832
|
+
left,
|
|
1833
|
+
top: Math.max(top, MARGIN),
|
|
1834
|
+
width,
|
|
1835
|
+
height,
|
|
1836
|
+
above: !downward
|
|
1837
|
+
};
|
|
1838
|
+
}
|
|
1839
|
+
//#endregion
|
|
1840
|
+
//#region editors/workflow-editor/ui/PickerPopover.tsx
|
|
1841
|
+
const PICKER_SIZE = {
|
|
1842
|
+
width: 640,
|
|
1843
|
+
height: 480
|
|
1844
|
+
};
|
|
1845
|
+
function PickerPopover(props) {
|
|
1846
|
+
const [placement, setPlacement] = useState(null);
|
|
1847
|
+
const { anchor, onClose } = props;
|
|
1848
|
+
useLayoutEffect(() => {
|
|
1849
|
+
const place = () => {
|
|
1850
|
+
const rect = anchor.current?.getBoundingClientRect();
|
|
1851
|
+
if (!rect) return;
|
|
1852
|
+
setPlacement(pickerPlacement(rect, PICKER_SIZE, {
|
|
1853
|
+
width: window.innerWidth,
|
|
1854
|
+
height: window.innerHeight
|
|
1855
|
+
}));
|
|
1856
|
+
};
|
|
1857
|
+
place();
|
|
1858
|
+
const onWheel = (event) => {
|
|
1859
|
+
const target = event.target;
|
|
1860
|
+
if (!(target instanceof Element && target.closest("[data-selector-open]"))) onClose();
|
|
1861
|
+
};
|
|
1862
|
+
window.addEventListener("resize", onClose);
|
|
1863
|
+
window.addEventListener("wheel", onWheel, {
|
|
1864
|
+
capture: true,
|
|
1865
|
+
passive: true
|
|
1866
|
+
});
|
|
1867
|
+
return () => {
|
|
1868
|
+
window.removeEventListener("resize", onClose);
|
|
1869
|
+
window.removeEventListener("wheel", onWheel, { capture: true });
|
|
1870
|
+
};
|
|
1871
|
+
}, [anchor, onClose]);
|
|
1872
|
+
const host = anchor.current?.closest(".react-flow")?.parentElement ?? document.body;
|
|
1873
|
+
if (!placement) return null;
|
|
1874
|
+
return createPortal(/* @__PURE__ */ jsx("div", {
|
|
1875
|
+
"data-selector-open": "true",
|
|
1876
|
+
className: "nodrag nopan nowheel fixed z-50 motion-safe:animate-[wf-picker-in_120ms_ease-out]",
|
|
1877
|
+
style: placement.above ? {
|
|
1878
|
+
left: placement.left,
|
|
1879
|
+
bottom: window.innerHeight - placement.top - placement.height,
|
|
1880
|
+
transformOrigin: "bottom center"
|
|
1881
|
+
} : {
|
|
1882
|
+
left: placement.left,
|
|
1883
|
+
top: placement.top,
|
|
1884
|
+
transformOrigin: "top center"
|
|
1885
|
+
},
|
|
1886
|
+
children: props.children(placement)
|
|
1887
|
+
}), host);
|
|
1888
|
+
}
|
|
1889
|
+
//#endregion
|
|
1890
|
+
//#region editors/workflow-editor/ui/picker-recent.ts
|
|
1891
|
+
const STORAGE_KEY = "ph-workflow-picker-recent:v1";
|
|
1892
|
+
const MAX_RECENT = 6;
|
|
1893
|
+
function isStoredPick(value) {
|
|
1894
|
+
const entry = value;
|
|
1895
|
+
const block = entry?.block;
|
|
1896
|
+
return typeof entry?.label === "string" && typeof block?.pieceName === "string" && typeof block.name === "string" && (block.kind === "action" || block.kind === "trigger");
|
|
1897
|
+
}
|
|
1898
|
+
function readAll() {
|
|
1899
|
+
try {
|
|
1900
|
+
const raw = window.localStorage.getItem(STORAGE_KEY);
|
|
1901
|
+
const parsed = raw ? JSON.parse(raw) : [];
|
|
1902
|
+
return Array.isArray(parsed) ? parsed.filter(isStoredPick) : [];
|
|
1903
|
+
} catch {
|
|
1904
|
+
return [];
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
function recentPicks(kind) {
|
|
1908
|
+
return readAll().filter((entry) => entry.block.kind === kind).map((entry) => ({
|
|
1909
|
+
label: entry.label,
|
|
1910
|
+
description: entry.description ?? "",
|
|
1911
|
+
block: entry.block,
|
|
1912
|
+
defaultConfig: {}
|
|
1913
|
+
}));
|
|
1914
|
+
}
|
|
1915
|
+
function rememberPick(preset) {
|
|
1916
|
+
const { pieceName, kind, name } = preset.block;
|
|
1917
|
+
const entry = {
|
|
1918
|
+
label: preset.label,
|
|
1919
|
+
description: preset.description,
|
|
1920
|
+
block: {
|
|
1921
|
+
pieceName,
|
|
1922
|
+
kind,
|
|
1923
|
+
name
|
|
1924
|
+
}
|
|
1925
|
+
};
|
|
1926
|
+
const same = (other) => other.block.pieceName === pieceName && other.block.kind === kind && other.block.name === name;
|
|
1927
|
+
const all = readAll();
|
|
1928
|
+
const ofKind = all.filter((other) => other.block.kind === kind);
|
|
1929
|
+
const others = all.filter((other) => other.block.kind !== kind);
|
|
1930
|
+
const next = [entry, ...ofKind.filter((other) => !same(other))].slice(0, MAX_RECENT);
|
|
1931
|
+
try {
|
|
1932
|
+
window.localStorage.setItem(STORAGE_KEY, JSON.stringify([...next, ...others]));
|
|
1933
|
+
} catch {}
|
|
1934
|
+
}
|
|
1935
|
+
//#endregion
|
|
1936
|
+
//#region editors/workflow-editor/ui/VirtualList.tsx
|
|
1937
|
+
const OVERSCAN = 6;
|
|
1938
|
+
function rowOffsets(heights) {
|
|
1939
|
+
const offsets = [0];
|
|
1940
|
+
for (const height of heights) offsets.push(offsets.at(-1) + height);
|
|
1941
|
+
return offsets;
|
|
1942
|
+
}
|
|
1943
|
+
function visibleRange(offsets, scrollTop, height, overscan = OVERSCAN) {
|
|
1944
|
+
const count = offsets.length - 1;
|
|
1945
|
+
let start = 0;
|
|
1946
|
+
while (start < count && offsets[start + 1] <= scrollTop) start++;
|
|
1947
|
+
let end = start;
|
|
1948
|
+
while (end < count && offsets[end] < scrollTop + height) end++;
|
|
1949
|
+
return [Math.max(0, start - overscan), Math.min(count, end + overscan)];
|
|
1950
|
+
}
|
|
1951
|
+
function VirtualList(props) {
|
|
1952
|
+
const ref = useRef(null);
|
|
1953
|
+
const [scrollTop, setScrollTop] = useState(0);
|
|
1954
|
+
const [height, setHeight] = useState(400);
|
|
1955
|
+
const offsets = useMemo(() => rowOffsets(props.items.map(props.heightOf)), [props.items, props.heightOf]);
|
|
1956
|
+
useLayoutEffect(() => {
|
|
1957
|
+
const element = ref.current;
|
|
1958
|
+
if (!element) return;
|
|
1959
|
+
const observer = new ResizeObserver(() => setHeight(element.clientHeight));
|
|
1960
|
+
observer.observe(element);
|
|
1961
|
+
setHeight(element.clientHeight);
|
|
1962
|
+
return () => observer.disconnect();
|
|
1963
|
+
}, []);
|
|
1964
|
+
useEffect(() => {
|
|
1965
|
+
if (ref.current) ref.current.scrollTop = 0;
|
|
1966
|
+
}, [props.resetKey]);
|
|
1967
|
+
useEffect(() => {
|
|
1968
|
+
const element = ref.current;
|
|
1969
|
+
const index = props.activeIndex;
|
|
1970
|
+
if (!element || index === void 0 || index < 0) return;
|
|
1971
|
+
const top = offsets.at(index);
|
|
1972
|
+
const bottom = offsets.at(index + 1);
|
|
1973
|
+
if (top === void 0 || bottom === void 0) return;
|
|
1974
|
+
if (top < element.scrollTop) element.scrollTop = top;
|
|
1975
|
+
else if (bottom > element.scrollTop + element.clientHeight) element.scrollTop = bottom - element.clientHeight;
|
|
1976
|
+
}, [props.activeIndex, offsets]);
|
|
1977
|
+
const [start, end] = visibleRange(offsets, scrollTop, height);
|
|
1978
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1979
|
+
ref,
|
|
1980
|
+
id: props.id,
|
|
1981
|
+
role: "listbox",
|
|
1982
|
+
"aria-label": props.label,
|
|
1983
|
+
className: `min-h-0 overflow-y-auto ${props.className ?? ""}`,
|
|
1984
|
+
onScroll: (event) => setScrollTop(event.currentTarget.scrollTop),
|
|
1985
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
1986
|
+
role: "presentation",
|
|
1987
|
+
style: {
|
|
1988
|
+
height: offsets.at(-1),
|
|
1989
|
+
position: "relative"
|
|
1990
|
+
},
|
|
1991
|
+
children: props.items.slice(start, end).map((item, i) => {
|
|
1992
|
+
const index = start + i;
|
|
1993
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1994
|
+
role: "presentation",
|
|
1995
|
+
style: {
|
|
1996
|
+
position: "absolute",
|
|
1997
|
+
top: offsets[index],
|
|
1998
|
+
left: 0,
|
|
1999
|
+
right: 0,
|
|
2000
|
+
height: offsets[index + 1] - offsets[index]
|
|
2001
|
+
},
|
|
2002
|
+
children: props.render(item, index)
|
|
2003
|
+
}, props.keyOf(item, index));
|
|
2004
|
+
})
|
|
2005
|
+
})
|
|
2006
|
+
});
|
|
2007
|
+
}
|
|
2008
|
+
//#endregion
|
|
2009
|
+
//#region editors/workflow-editor/ui/BlockSelector.tsx
|
|
2010
|
+
const ROW_LOGO = 24;
|
|
2011
|
+
const CORE_TILE = {
|
|
2012
|
+
[blockKey(MANUAL_TRIGGER)]: {
|
|
2013
|
+
icon: "play",
|
|
2014
|
+
color: "#2563eb"
|
|
2015
|
+
},
|
|
2016
|
+
[blockKey(SCHEDULE_TRIGGER)]: {
|
|
2017
|
+
icon: "clock",
|
|
2018
|
+
color: "#7c3aed"
|
|
2019
|
+
},
|
|
2020
|
+
[blockKey(WEBHOOK_TRIGGER)]: {
|
|
2021
|
+
icon: "bolt",
|
|
2022
|
+
color: "#0891b2"
|
|
2023
|
+
},
|
|
2024
|
+
[blockKey(BRANCH_BLOCK)]: {
|
|
2025
|
+
icon: "branch",
|
|
2026
|
+
color: "#d97706"
|
|
2027
|
+
},
|
|
2028
|
+
[blockKey(ASSERT_BLOCK)]: {
|
|
2029
|
+
icon: "alert",
|
|
2030
|
+
color: "#dc2626"
|
|
2031
|
+
}
|
|
2032
|
+
};
|
|
2033
|
+
function CoreTile(props) {
|
|
2034
|
+
const tile = props.tile;
|
|
2035
|
+
const glyph = Math.round(props.size * (props.bare ? .9 : .55));
|
|
2036
|
+
if (props.bare) return /* @__PURE__ */ jsx("span", {
|
|
2037
|
+
className: "flex shrink-0 items-center justify-center",
|
|
2038
|
+
style: {
|
|
2039
|
+
width: props.size,
|
|
2040
|
+
height: props.size,
|
|
2041
|
+
color: tile.color
|
|
2042
|
+
},
|
|
2043
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
2044
|
+
name: tile.icon,
|
|
2045
|
+
size: glyph
|
|
2046
|
+
})
|
|
2047
|
+
});
|
|
2048
|
+
return /* @__PURE__ */ jsx("span", {
|
|
2049
|
+
className: "flex shrink-0 items-center justify-center rounded-[22%] text-white",
|
|
2050
|
+
style: {
|
|
2051
|
+
width: props.size,
|
|
2052
|
+
height: props.size,
|
|
2053
|
+
backgroundColor: tile.color
|
|
2054
|
+
},
|
|
2055
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
2056
|
+
name: tile.icon,
|
|
2057
|
+
size: glyph
|
|
2058
|
+
})
|
|
2059
|
+
});
|
|
2060
|
+
}
|
|
2061
|
+
function BlockLogo(props) {
|
|
2062
|
+
const meta = useBlockMeta(props.block);
|
|
2063
|
+
const tile = CORE_TILE[blockKey(props.block)];
|
|
2064
|
+
if (tile) return /* @__PURE__ */ jsx(CoreTile, {
|
|
2065
|
+
tile,
|
|
2066
|
+
size: props.size ?? 36,
|
|
2067
|
+
bare: props.bare
|
|
2068
|
+
});
|
|
2069
|
+
return /* @__PURE__ */ jsx(LogoFrame, {
|
|
2070
|
+
src: meta.logoUrl,
|
|
2071
|
+
alt: meta.displayName,
|
|
2072
|
+
size: props.size ?? 36,
|
|
2073
|
+
glyph: meta.glyph,
|
|
2074
|
+
bare: props.bare
|
|
2075
|
+
});
|
|
2076
|
+
}
|
|
2077
|
+
function GlyphBadge(props) {
|
|
2078
|
+
return /* @__PURE__ */ jsx("div", {
|
|
2079
|
+
className: "flex shrink-0 items-center justify-center rounded-sm border border-solid border-foreground/10 bg-muted/50 text-muted-foreground",
|
|
2080
|
+
style: {
|
|
2081
|
+
width: props.size,
|
|
2082
|
+
height: props.size,
|
|
2083
|
+
fontSize: props.size / 2
|
|
2084
|
+
},
|
|
2085
|
+
children: props.glyph ?? "?"
|
|
2086
|
+
});
|
|
2087
|
+
}
|
|
2088
|
+
function LogoFrame(props) {
|
|
2089
|
+
const [broken, setBroken] = useState(false);
|
|
2090
|
+
useEffect(() => {
|
|
2091
|
+
setBroken(false);
|
|
2092
|
+
}, [props.src]);
|
|
2093
|
+
if (!props.src || broken) return /* @__PURE__ */ jsx(GlyphBadge, {
|
|
2094
|
+
glyph: props.glyph,
|
|
2095
|
+
size: props.size
|
|
2096
|
+
});
|
|
2097
|
+
return /* @__PURE__ */ jsx("div", {
|
|
2098
|
+
className: `flex shrink-0 items-center justify-center ${props.bare ? "" : "dark:rounded-[22%] dark:bg-white dark:p-[var(--logo-pad)]"}`,
|
|
2099
|
+
style: {
|
|
2100
|
+
width: props.size,
|
|
2101
|
+
height: props.size,
|
|
2102
|
+
"--logo-pad": `${Math.round(props.size * .12)}px`
|
|
2103
|
+
},
|
|
2104
|
+
children: /* @__PURE__ */ jsx("img", {
|
|
2105
|
+
src: props.src,
|
|
2106
|
+
alt: props.alt,
|
|
2107
|
+
className: "h-full w-full object-contain drop-shadow-sm",
|
|
2108
|
+
onError: () => setBroken(true)
|
|
2109
|
+
})
|
|
2110
|
+
});
|
|
2111
|
+
}
|
|
2112
|
+
function Row(props) {
|
|
2113
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2114
|
+
...optionAttributes(props.option),
|
|
2115
|
+
role: "option",
|
|
2116
|
+
"aria-selected": (props.active ?? false) || (props.selected ?? false),
|
|
2117
|
+
"aria-disabled": props.disabled,
|
|
2118
|
+
className: `group mx-1.5 my-px flex h-[calc(100%-2px)] cursor-pointer items-center gap-2.5 rounded-md px-2 text-left ${rowTone(props.active, props.selected)} ${props.disabled ? "cursor-not-allowed opacity-50" : ""}`,
|
|
2119
|
+
title: props.title,
|
|
2120
|
+
onClick: props.disabled ? void 0 : props.onClick,
|
|
2121
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
2122
|
+
onMouseEnter: props.onHover,
|
|
2123
|
+
children: [
|
|
2124
|
+
/* @__PURE__ */ jsx("span", {
|
|
2125
|
+
"aria-hidden": "true",
|
|
2126
|
+
className: "contents",
|
|
2127
|
+
children: props.logo
|
|
2128
|
+
}),
|
|
2129
|
+
/* @__PURE__ */ jsxs("span", {
|
|
2130
|
+
className: "min-w-0",
|
|
2131
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
2132
|
+
className: "block truncate text-[13px] font-medium leading-[18px] text-foreground",
|
|
2133
|
+
children: props.label
|
|
2134
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
2135
|
+
className: `text-xs leading-4 text-muted-foreground ${props.tall ? "line-clamp-2" : "block truncate"}`,
|
|
2136
|
+
children: props.description
|
|
2137
|
+
})]
|
|
2138
|
+
}),
|
|
2139
|
+
props.version ? /* @__PURE__ */ jsxs("span", {
|
|
2140
|
+
className: `ml-auto shrink-0 pl-2 text-[11px] tabular-nums text-muted-foreground ${props.versionNote ? "" : props.active ? "" : "hidden group-hover:inline"}`,
|
|
2141
|
+
title: props.versionNote ?? `Pinned to version ${props.version}`,
|
|
2142
|
+
children: ["v", props.version]
|
|
2143
|
+
}) : null
|
|
2144
|
+
]
|
|
2145
|
+
});
|
|
2146
|
+
}
|
|
2147
|
+
function rowTone(active, selected) {
|
|
2148
|
+
if (active) return "bg-wf-run/10 ring-1 ring-inset ring-wf-run/25";
|
|
2149
|
+
if (selected) return "bg-card shadow-sm ring-1 ring-foreground/10";
|
|
2150
|
+
return "hover:bg-foreground/[0.05]";
|
|
2151
|
+
}
|
|
2152
|
+
function optionId(list, index) {
|
|
2153
|
+
return `${list}-${index}`;
|
|
2154
|
+
}
|
|
2155
|
+
function optionAttributes(place) {
|
|
2156
|
+
return place ? {
|
|
2157
|
+
id: optionId(place.list, place.index),
|
|
2158
|
+
"aria-posinset": place.index + 1,
|
|
2159
|
+
"aria-setsize": place.size
|
|
2160
|
+
} : {};
|
|
2161
|
+
}
|
|
2162
|
+
function shownVersion(pieceName, version) {
|
|
2163
|
+
return isCoreBlock({ pieceName }) ? void 0 : version;
|
|
2164
|
+
}
|
|
2165
|
+
function useVersionNote(catalog) {
|
|
2166
|
+
const draft = useDraftBlocks();
|
|
2167
|
+
return (piece, version) => {
|
|
2168
|
+
if (!piece || !version) return void 0;
|
|
2169
|
+
const others = [...new Set(draft.filter((block) => block.pieceName === piece && block.pieceVersion !== version).map((block) => `v${block.pieceVersion}`))];
|
|
2170
|
+
if (others.length > 0) return `Other steps of this workflow use ${others.join(", ")}`;
|
|
2171
|
+
if (piece === "@powerhousedao/piece-reactor") return void 0;
|
|
2172
|
+
const published = catalog?.find((entry) => entry.name === piece)?.publishedVersion;
|
|
2173
|
+
return published && published !== version ? `A local build; v${published} is published` : void 0;
|
|
2174
|
+
};
|
|
2175
|
+
}
|
|
2176
|
+
const CATEGORY_LABELS = {
|
|
2177
|
+
ARTIFICIAL_INTELLIGENCE: "AI",
|
|
2178
|
+
UNIVERSAL_AI: "AI",
|
|
2179
|
+
PRODUCTIVITY: "Productivity",
|
|
2180
|
+
MARKETING: "Marketing",
|
|
2181
|
+
COMMUNICATION: "Communication",
|
|
2182
|
+
SALES_AND_CRM: "Sales & CRM",
|
|
2183
|
+
DEVELOPER_TOOLS: "Developer tools",
|
|
2184
|
+
CONTENT_AND_FILES: "Content & files",
|
|
2185
|
+
BUSINESS_INTELLIGENCE: "Business intelligence",
|
|
2186
|
+
CORE: "Utilities",
|
|
2187
|
+
FLOW_CONTROL: "Utilities",
|
|
2188
|
+
COMMERCE: "Commerce",
|
|
2189
|
+
FORMS_AND_SURVEYS: "Forms & surveys",
|
|
2190
|
+
ACCOUNTING: "Accounting",
|
|
2191
|
+
CUSTOMER_SUPPORT: "Customer support",
|
|
2192
|
+
PAYMENT_PROCESSING: "Payments",
|
|
2193
|
+
HUMAN_RESOURCES: "HR"
|
|
2194
|
+
};
|
|
2195
|
+
const AI_CHIP = "AI";
|
|
2196
|
+
function categoryLabel(id) {
|
|
2197
|
+
return CATEGORY_LABELS[id] ?? id.toLowerCase().replaceAll("_", " ").replace(/^\w/, (char) => char.toUpperCase());
|
|
2198
|
+
}
|
|
2199
|
+
function chipsOf(piece) {
|
|
2200
|
+
return new Set(piece.categories.map(categoryLabel));
|
|
2201
|
+
}
|
|
2202
|
+
function categoriesOfChip(chip, pieces) {
|
|
2203
|
+
return [...new Set(pieces.flatMap((piece) => piece.categories))].filter((id) => categoryLabel(id) === chip);
|
|
2204
|
+
}
|
|
2205
|
+
function orderChips(pieces) {
|
|
2206
|
+
const counts = /* @__PURE__ */ new Map();
|
|
2207
|
+
for (const piece of pieces) for (const chip of chipsOf(piece)) counts.set(chip, (counts.get(chip) ?? 0) + 1);
|
|
2208
|
+
const rest = [...counts.entries()].filter(([chip]) => chip !== AI_CHIP).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([chip]) => chip);
|
|
2209
|
+
return [...counts.has(AI_CHIP) ? [AI_CHIP] : [], ...rest];
|
|
2210
|
+
}
|
|
2211
|
+
const TAB_LABELS = {
|
|
2212
|
+
all: "All",
|
|
2213
|
+
core: "Core",
|
|
2214
|
+
powerhouse: "Powerhouse",
|
|
2215
|
+
activepieces: "Integrations"
|
|
2216
|
+
};
|
|
2217
|
+
const TAB_SOURCES = {
|
|
2218
|
+
all: void 0,
|
|
2219
|
+
core: [],
|
|
2220
|
+
powerhouse: ["local", "registry"],
|
|
2221
|
+
activepieces: ["activepieces"]
|
|
2222
|
+
};
|
|
2223
|
+
function inTab(tab, piece) {
|
|
2224
|
+
const sources = TAB_SOURCES[tab];
|
|
2225
|
+
return sources === void 0 || sources.includes(piece.source ?? "activepieces");
|
|
2226
|
+
}
|
|
2227
|
+
function folded(text) {
|
|
2228
|
+
return text.normalize("NFKD").replace(/\p{M}/gu, "").toLowerCase();
|
|
2229
|
+
}
|
|
2230
|
+
function queryTokens(query) {
|
|
2231
|
+
return folded(query).split(/[^\p{L}\p{N}]+/u).filter(Boolean);
|
|
2232
|
+
}
|
|
2233
|
+
function matchesQuery(text, tokens) {
|
|
2234
|
+
const lowered = folded(text);
|
|
2235
|
+
return tokens.every((token) => lowered.includes(token));
|
|
2236
|
+
}
|
|
2237
|
+
function escapeRegExp(text) {
|
|
2238
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2239
|
+
}
|
|
2240
|
+
function Highlight(props) {
|
|
2241
|
+
if (props.tokens.length === 0) return /* @__PURE__ */ jsx(Fragment$1, { children: props.text });
|
|
2242
|
+
const pattern = new RegExp(`(?<![\\p{L}\\p{N}])(${props.tokens.map(escapeRegExp).join("|")})`, "giu");
|
|
2243
|
+
const parts = props.text.split(pattern);
|
|
2244
|
+
return /* @__PURE__ */ jsx(Fragment$1, { children: parts.map((part, i) => i % 2 === 1 ? /* @__PURE__ */ jsx("mark", {
|
|
2245
|
+
className: "bg-transparent font-semibold text-inherit",
|
|
2246
|
+
children: part
|
|
2247
|
+
}, i) : part) });
|
|
2248
|
+
}
|
|
2249
|
+
const SEARCH_MIN_CHARS = 2;
|
|
2250
|
+
const SEARCH_DEBOUNCE_MS = 250;
|
|
2251
|
+
const INDEXING_RETRY_MS = 2e3;
|
|
2252
|
+
function usePieceSearch(query, filter) {
|
|
2253
|
+
const [state, setState] = useState({ kind: "idle" });
|
|
2254
|
+
const [attempt, setAttempt] = useState(0);
|
|
2255
|
+
const trimmed = query.trim();
|
|
2256
|
+
const search = usePieceSource()?.searchPieces;
|
|
2257
|
+
const active = filter !== null && search !== void 0 && trimmed.length >= SEARCH_MIN_CHARS;
|
|
2258
|
+
const filterKey = JSON.stringify(filter);
|
|
2259
|
+
const key = `${trimmed}\n${filterKey}`;
|
|
2260
|
+
useEffect(() => {
|
|
2261
|
+
if (!active) {
|
|
2262
|
+
setState({ kind: "idle" });
|
|
2263
|
+
return;
|
|
2264
|
+
}
|
|
2265
|
+
let alive = true;
|
|
2266
|
+
let retry;
|
|
2267
|
+
const timer = setTimeout(() => {
|
|
2268
|
+
search(trimmed, JSON.parse(filterKey)).then((result) => {
|
|
2269
|
+
if (!alive) return;
|
|
2270
|
+
setState({
|
|
2271
|
+
kind: "done",
|
|
2272
|
+
key,
|
|
2273
|
+
result
|
|
2274
|
+
});
|
|
2275
|
+
if (result.status === "indexing") retry = setTimeout(() => setAttempt((value) => value + 1), INDEXING_RETRY_MS);
|
|
2276
|
+
}, (error) => {
|
|
2277
|
+
if (alive) setState({
|
|
2278
|
+
kind: "error",
|
|
2279
|
+
key,
|
|
2280
|
+
message: error instanceof Error ? error.message : String(error)
|
|
2281
|
+
});
|
|
2282
|
+
});
|
|
2283
|
+
}, SEARCH_DEBOUNCE_MS);
|
|
2284
|
+
return () => {
|
|
2285
|
+
alive = false;
|
|
2286
|
+
clearTimeout(timer);
|
|
2287
|
+
if (retry) clearTimeout(retry);
|
|
2288
|
+
};
|
|
2289
|
+
}, [
|
|
2290
|
+
active,
|
|
2291
|
+
trimmed,
|
|
2292
|
+
filterKey,
|
|
2293
|
+
key,
|
|
2294
|
+
attempt,
|
|
2295
|
+
search
|
|
2296
|
+
]);
|
|
2297
|
+
if (!active) return { kind: "idle" };
|
|
2298
|
+
if (state.kind === "idle") return { kind: "loading" };
|
|
2299
|
+
if (state.kind === "error") return state.key === key ? {
|
|
2300
|
+
kind: "error",
|
|
2301
|
+
message: state.message
|
|
2302
|
+
} : { kind: "loading" };
|
|
2303
|
+
return {
|
|
2304
|
+
kind: "done",
|
|
2305
|
+
result: state.result,
|
|
2306
|
+
stale: state.key !== key
|
|
2307
|
+
};
|
|
2308
|
+
}
|
|
2309
|
+
function rovingFocus(event) {
|
|
2310
|
+
const delta = event.key === "ArrowRight" ? 1 : event.key === "ArrowLeft" ? -1 : 0;
|
|
2311
|
+
if (delta === 0) return;
|
|
2312
|
+
event.preventDefault();
|
|
2313
|
+
const buttons = [...event.currentTarget.querySelectorAll("button")];
|
|
2314
|
+
const at = buttons.indexOf(document.activeElement);
|
|
2315
|
+
buttons.at((at + delta) % buttons.length)?.focus();
|
|
2316
|
+
}
|
|
2317
|
+
function Chip(props) {
|
|
2318
|
+
return /* @__PURE__ */ jsx("button", {
|
|
2319
|
+
type: "button",
|
|
2320
|
+
"aria-pressed": props.active,
|
|
2321
|
+
tabIndex: props.tabStop ? 0 : -1,
|
|
2322
|
+
className: `shrink-0 rounded-full border px-2.5 py-0.5 text-[11px] font-medium focus-visible:outline-2 focus-visible:outline-wf-run ${props.active ? "border-wf-run/40 bg-wf-run/10 text-wf-run" : "border-foreground/10 text-muted-foreground hover:border-foreground/25 hover:text-foreground"}`,
|
|
2323
|
+
onClick: (event) => props.onClick(event.detail === 0),
|
|
2324
|
+
children: props.label
|
|
2325
|
+
});
|
|
2326
|
+
}
|
|
2327
|
+
function ChipBar(props) {
|
|
2328
|
+
const ref = useRef(null);
|
|
2329
|
+
const [more, setMore] = useState({
|
|
2330
|
+
left: false,
|
|
2331
|
+
right: false
|
|
2332
|
+
});
|
|
2333
|
+
const measure = () => {
|
|
2334
|
+
const element = ref.current;
|
|
2335
|
+
if (!element) return;
|
|
2336
|
+
const left = element.scrollLeft > 1;
|
|
2337
|
+
const right = element.scrollLeft + element.clientWidth < element.scrollWidth - 1;
|
|
2338
|
+
setMore((previous) => previous.left === left && previous.right === right ? previous : {
|
|
2339
|
+
left,
|
|
2340
|
+
right
|
|
2341
|
+
});
|
|
2342
|
+
};
|
|
2343
|
+
useLayoutEffect(() => {
|
|
2344
|
+
const element = ref.current;
|
|
2345
|
+
if (!element) return;
|
|
2346
|
+
const observer = new ResizeObserver(measure);
|
|
2347
|
+
observer.observe(element);
|
|
2348
|
+
return () => observer.disconnect();
|
|
2349
|
+
}, []);
|
|
2350
|
+
const fade = (side) => /* @__PURE__ */ jsx("span", {
|
|
2351
|
+
"aria-hidden": "true",
|
|
2352
|
+
className: "pointer-events-none absolute inset-y-0 w-14",
|
|
2353
|
+
style: {
|
|
2354
|
+
[side]: 0,
|
|
2355
|
+
background: `linear-gradient(to ${side === "left" ? "right" : "left"}, var(--card), transparent)`
|
|
2356
|
+
}
|
|
2357
|
+
});
|
|
2358
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2359
|
+
className: "relative shrink-0 border-b border-foreground/10",
|
|
2360
|
+
children: [
|
|
2361
|
+
/* @__PURE__ */ jsx("div", {
|
|
2362
|
+
ref,
|
|
2363
|
+
role: "toolbar",
|
|
2364
|
+
"aria-label": "Categories",
|
|
2365
|
+
className: "flex gap-1.5 overflow-x-auto whitespace-nowrap px-3 py-2 [scrollbar-width:none]",
|
|
2366
|
+
onKeyDown: rovingFocus,
|
|
2367
|
+
onScroll: measure,
|
|
2368
|
+
children: props.children
|
|
2369
|
+
}),
|
|
2370
|
+
more.left ? fade("left") : null,
|
|
2371
|
+
more.right ? fade("right") : null
|
|
2372
|
+
]
|
|
2373
|
+
});
|
|
2374
|
+
}
|
|
2375
|
+
function Tabs(props) {
|
|
2376
|
+
return /* @__PURE__ */ jsx("div", {
|
|
2377
|
+
role: "tablist",
|
|
2378
|
+
"aria-label": "Piece sources",
|
|
2379
|
+
className: "inline-flex gap-0.5 rounded-md bg-foreground/[0.05] p-0.5",
|
|
2380
|
+
onKeyDown: (event) => {
|
|
2381
|
+
rovingFocus(event);
|
|
2382
|
+
const tab = document.activeElement?.dataset.tab;
|
|
2383
|
+
if (tab && tab !== props.active) props.onSelect(tab, true);
|
|
2384
|
+
},
|
|
2385
|
+
children: props.tabs.map((tab) => /* @__PURE__ */ jsx("button", {
|
|
2386
|
+
type: "button",
|
|
2387
|
+
role: "tab",
|
|
2388
|
+
"data-tab": tab,
|
|
2389
|
+
"aria-selected": props.active === tab,
|
|
2390
|
+
tabIndex: props.active === tab ? 0 : -1,
|
|
2391
|
+
className: `rounded px-2.5 py-1 text-xs font-medium focus-visible:outline-2 focus-visible:outline-wf-run ${props.active === tab ? "bg-card text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"}`,
|
|
2392
|
+
onClick: (event) => props.onSelect(tab, event.detail === 0),
|
|
2393
|
+
children: TAB_LABELS[tab]
|
|
2394
|
+
}, tab))
|
|
2395
|
+
});
|
|
2396
|
+
}
|
|
2397
|
+
function Status(props) {
|
|
2398
|
+
return /* @__PURE__ */ jsx("div", {
|
|
2399
|
+
role: "status",
|
|
2400
|
+
className: `px-4 py-2.5 text-xs ${props.error ? "text-wf-fail" : "text-muted-foreground"}`,
|
|
2401
|
+
children: props.children
|
|
2402
|
+
});
|
|
2403
|
+
}
|
|
2404
|
+
const ROW_HEIGHT = 46;
|
|
2405
|
+
const BLOCK_HEIGHT = 60;
|
|
2406
|
+
const HEADER_LOGO = 36;
|
|
2407
|
+
const HEADER_HEIGHT = 38;
|
|
2408
|
+
const MORE_HEIGHT = 28;
|
|
2409
|
+
const GROUP_BLOCKS = 4;
|
|
2410
|
+
const HOVER_PREVIEW_MS = 120;
|
|
2411
|
+
const searchRowHeight = (row) => row.type === "entry" ? BLOCK_HEIGHT : row.type === "more" ? MORE_HEIGHT : HEADER_HEIGHT;
|
|
2412
|
+
const sourceHeight = () => ROW_HEIGHT;
|
|
2413
|
+
const entryHeight = () => BLOCK_HEIGHT;
|
|
2414
|
+
function listTile(icon, color) {
|
|
2415
|
+
return (size) => /* @__PURE__ */ jsx(CoreTile, {
|
|
2416
|
+
tile: {
|
|
2417
|
+
icon,
|
|
2418
|
+
color
|
|
2419
|
+
},
|
|
2420
|
+
size
|
|
2421
|
+
});
|
|
2422
|
+
}
|
|
2423
|
+
function EntryRow(props) {
|
|
2424
|
+
const { entry } = props;
|
|
2425
|
+
return /* @__PURE__ */ jsx(Row, {
|
|
2426
|
+
logo: props.indent ? /* @__PURE__ */ jsx("span", {
|
|
2427
|
+
className: "shrink-0",
|
|
2428
|
+
style: { width: ROW_LOGO }
|
|
2429
|
+
}) : entry.logo,
|
|
2430
|
+
label: /* @__PURE__ */ jsx(Highlight, {
|
|
2431
|
+
text: entry.label,
|
|
2432
|
+
tokens: props.tokens
|
|
2433
|
+
}),
|
|
2434
|
+
title: entry.description || entry.label,
|
|
2435
|
+
description: entry.unavailable ?? /* @__PURE__ */ jsx(Highlight, {
|
|
2436
|
+
text: entry.description,
|
|
2437
|
+
tokens: props.tokens
|
|
2438
|
+
}),
|
|
2439
|
+
disabled: entry.unavailable !== void 0,
|
|
2440
|
+
active: props.active,
|
|
2441
|
+
tall: true,
|
|
2442
|
+
option: props.option,
|
|
2443
|
+
version: entry.version,
|
|
2444
|
+
versionNote: entry.versionNote,
|
|
2445
|
+
onHover: () => {
|
|
2446
|
+
props.onActivate();
|
|
2447
|
+
if (entry.unavailable === void 0) entry.warm?.();
|
|
2448
|
+
},
|
|
2449
|
+
onClick: entry.pick
|
|
2450
|
+
});
|
|
2451
|
+
}
|
|
2452
|
+
function SourceRow(props) {
|
|
2453
|
+
const { source } = props;
|
|
2454
|
+
if (source.kind === "list") return /* @__PURE__ */ jsx(Row, {
|
|
2455
|
+
logo: source.logo(ROW_LOGO),
|
|
2456
|
+
label: source.title,
|
|
2457
|
+
description: source.subtitle,
|
|
2458
|
+
active: props.active,
|
|
2459
|
+
selected: props.selected,
|
|
2460
|
+
option: props.option,
|
|
2461
|
+
onHover: props.onActivate,
|
|
2462
|
+
onClick: props.onOpen
|
|
2463
|
+
});
|
|
2464
|
+
const { piece } = source;
|
|
2465
|
+
const count = props.mode === "triggers" ? piece.triggerCount : piece.actionCount;
|
|
2466
|
+
const noun = props.mode === "triggers" ? "trigger" : "action";
|
|
2467
|
+
return /* @__PURE__ */ jsx(Row, {
|
|
2468
|
+
logo: /* @__PURE__ */ jsx(LogoFrame, {
|
|
2469
|
+
src: piece.logoUrl,
|
|
2470
|
+
alt: piece.displayName,
|
|
2471
|
+
size: ROW_LOGO
|
|
2472
|
+
}),
|
|
2473
|
+
label: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(Highlight, {
|
|
2474
|
+
text: piece.displayName,
|
|
2475
|
+
tokens: props.tokens
|
|
2476
|
+
}), piece.deprecated ? " (deprecated)" : ""] }),
|
|
2477
|
+
title: piece.description || piece.displayName,
|
|
2478
|
+
description: piece.unsupported ?? `${count} ${noun}${count === 1 ? "" : "s"}`,
|
|
2479
|
+
active: props.active,
|
|
2480
|
+
selected: props.selected,
|
|
2481
|
+
option: props.option,
|
|
2482
|
+
onHover: props.onActivate,
|
|
2483
|
+
onClick: props.onOpen
|
|
2484
|
+
});
|
|
2485
|
+
}
|
|
2486
|
+
function usePieceEntries(piece, mode) {
|
|
2487
|
+
const pieceSource = usePieceSource();
|
|
2488
|
+
const [state, setState] = useState(null);
|
|
2489
|
+
const name = piece?.name;
|
|
2490
|
+
useEffect(() => {
|
|
2491
|
+
if (!name || !pieceSource) return;
|
|
2492
|
+
let cancelled = false;
|
|
2493
|
+
(mode === "triggers" ? pieceSource.loadTriggers(name) : pieceSource.loadActions(name)).then((entries) => {
|
|
2494
|
+
if (!cancelled) setState({
|
|
2495
|
+
name,
|
|
2496
|
+
entries,
|
|
2497
|
+
error: null
|
|
2498
|
+
});
|
|
2499
|
+
}, (error) => {
|
|
2500
|
+
if (!cancelled) setState({
|
|
2501
|
+
name,
|
|
2502
|
+
entries: null,
|
|
2503
|
+
error: error instanceof Error ? error.message : String(error)
|
|
2504
|
+
});
|
|
2505
|
+
});
|
|
2506
|
+
return () => {
|
|
2507
|
+
cancelled = true;
|
|
2508
|
+
};
|
|
2509
|
+
}, [
|
|
2510
|
+
name,
|
|
2511
|
+
mode,
|
|
2512
|
+
pieceSource
|
|
2513
|
+
]);
|
|
2514
|
+
return state && state.name === name ? {
|
|
2515
|
+
entries: state.entries,
|
|
2516
|
+
error: state.error
|
|
2517
|
+
} : {
|
|
2518
|
+
entries: null,
|
|
2519
|
+
error: null
|
|
2520
|
+
};
|
|
2521
|
+
}
|
|
2522
|
+
function EntriesPane(props) {
|
|
2523
|
+
const { source } = props;
|
|
2524
|
+
const entries = source?.kind === "list" ? source.entries : props.pieceEntries;
|
|
2525
|
+
const kind = props.mode === "triggers" ? "trigger" : "action";
|
|
2526
|
+
const title = source?.kind === "list" ? source.title : source?.piece.displayName;
|
|
2527
|
+
const about = source?.kind === "list" ? source.subtitle : source?.piece.description;
|
|
2528
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2529
|
+
className: "flex min-h-0 min-w-0 flex-1 flex-col",
|
|
2530
|
+
children: [source && props.showHeader ? /* @__PURE__ */ jsxs("div", {
|
|
2531
|
+
className: "flex shrink-0 items-start gap-3 border-b border-foreground/10 px-4 py-3",
|
|
2532
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
2533
|
+
"aria-hidden": "true",
|
|
2534
|
+
className: "contents",
|
|
2535
|
+
children: source.kind === "list" ? source.logo(HEADER_LOGO) : /* @__PURE__ */ jsx(LogoFrame, {
|
|
2536
|
+
src: source.piece.logoUrl,
|
|
2537
|
+
alt: "",
|
|
2538
|
+
size: HEADER_LOGO
|
|
2539
|
+
})
|
|
2540
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
2541
|
+
className: "min-w-0",
|
|
2542
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
2543
|
+
className: "truncate text-sm font-semibold leading-5 text-foreground",
|
|
2544
|
+
children: title
|
|
2545
|
+
}), about ? /* @__PURE__ */ jsx("div", {
|
|
2546
|
+
className: "line-clamp-2 text-xs leading-4 text-muted-foreground",
|
|
2547
|
+
title: about,
|
|
2548
|
+
children: about
|
|
2549
|
+
}) : null]
|
|
2550
|
+
})]
|
|
2551
|
+
}) : null, !source ? /* @__PURE__ */ jsxs(Status, { children: [
|
|
2552
|
+
"Pick a piece to see its ",
|
|
2553
|
+
kind,
|
|
2554
|
+
"s"
|
|
2555
|
+
] }) : props.pieceError ? /* @__PURE__ */ jsx(Status, {
|
|
2556
|
+
error: true,
|
|
2557
|
+
children: props.pieceError
|
|
2558
|
+
}) : entries === null ? /* @__PURE__ */ jsx(Status, { children: "Loading…" }) : entries.length === 0 ? /* @__PURE__ */ jsxs(Status, { children: [
|
|
2559
|
+
"No ",
|
|
2560
|
+
kind,
|
|
2561
|
+
"s"
|
|
2562
|
+
] }) : /* @__PURE__ */ jsx(VirtualList, {
|
|
2563
|
+
id: props.listId,
|
|
2564
|
+
resetKey: source.id,
|
|
2565
|
+
label: `${title ?? ""} ${kind}s`,
|
|
2566
|
+
className: "flex-1 py-1",
|
|
2567
|
+
items: entries,
|
|
2568
|
+
heightOf: entryHeight,
|
|
2569
|
+
keyOf: (entry) => entry.key,
|
|
2570
|
+
activeIndex: props.activeIndex,
|
|
2571
|
+
render: (entry, index) => /* @__PURE__ */ jsx(EntryRow, {
|
|
2572
|
+
entry,
|
|
2573
|
+
tokens: props.tokens,
|
|
2574
|
+
active: index === props.activeIndex,
|
|
2575
|
+
option: {
|
|
2576
|
+
list: props.listId,
|
|
2577
|
+
index,
|
|
2578
|
+
size: entries.length
|
|
2579
|
+
},
|
|
2580
|
+
onActivate: () => props.onActivate(index)
|
|
2581
|
+
})
|
|
2582
|
+
})]
|
|
2583
|
+
});
|
|
2584
|
+
}
|
|
2585
|
+
function SearchList(props) {
|
|
2586
|
+
const size = props.rows.length;
|
|
2587
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2588
|
+
className: "flex min-h-0 flex-1 flex-col",
|
|
2589
|
+
children: [props.status, /* @__PURE__ */ jsx(VirtualList, {
|
|
2590
|
+
id: props.listId,
|
|
2591
|
+
label: "Search results",
|
|
2592
|
+
resetKey: props.resetKey,
|
|
2593
|
+
className: `flex-1 py-1 ${props.stale ? "opacity-60" : ""}`,
|
|
2594
|
+
items: props.rows,
|
|
2595
|
+
heightOf: searchRowHeight,
|
|
2596
|
+
keyOf: (row, index) => row.type === "entry" ? `e:${row.entry.key}` : row.type === "piece" ? `p:${row.match.pieceName}` : row.type === "list" ? `l:${row.source.id}` : `m:${row.pieceName}:${index}`,
|
|
2597
|
+
activeIndex: props.activeIndex,
|
|
2598
|
+
render: (row, index) => {
|
|
2599
|
+
const active = index === props.activeIndex;
|
|
2600
|
+
const activate = () => props.onActivate(index);
|
|
2601
|
+
const option = {
|
|
2602
|
+
list: props.listId,
|
|
2603
|
+
index,
|
|
2604
|
+
size
|
|
2605
|
+
};
|
|
2606
|
+
if (row.type === "entry") return /* @__PURE__ */ jsx(EntryRow, {
|
|
2607
|
+
entry: row.entry,
|
|
2608
|
+
tokens: props.tokens,
|
|
2609
|
+
active,
|
|
2610
|
+
option,
|
|
2611
|
+
indent: true,
|
|
2612
|
+
onActivate: activate
|
|
2613
|
+
});
|
|
2614
|
+
if (row.type === "more") return /* @__PURE__ */ jsxs("div", {
|
|
2615
|
+
...optionAttributes(option),
|
|
2616
|
+
role: "option",
|
|
2617
|
+
"aria-selected": active,
|
|
2618
|
+
className: `mx-1.5 my-px flex h-[calc(100%-2px)] cursor-pointer items-center rounded-md pl-[42px] text-xs text-muted-foreground hover:text-foreground ${rowTone(active)}`,
|
|
2619
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
2620
|
+
onMouseEnter: activate,
|
|
2621
|
+
onClick: () => props.onExpand(row.pieceName),
|
|
2622
|
+
children: [row.hidden, " more…"]
|
|
2623
|
+
});
|
|
2624
|
+
const header = row.type === "piece" ? {
|
|
2625
|
+
logo: /* @__PURE__ */ jsx(LogoFrame, {
|
|
2626
|
+
src: row.match.logoUrl,
|
|
2627
|
+
alt: row.match.displayName,
|
|
2628
|
+
size: 20
|
|
2629
|
+
}),
|
|
2630
|
+
label: row.match.displayName,
|
|
2631
|
+
note: row.match.deprecated ? "Deprecated" : row.match.unsupported ?? void 0,
|
|
2632
|
+
kind: props.kind,
|
|
2633
|
+
open: () => props.onOpenPiece(row.match.pieceName)
|
|
2634
|
+
} : {
|
|
2635
|
+
logo: row.source.logo(20),
|
|
2636
|
+
label: row.source.title,
|
|
2637
|
+
note: void 0,
|
|
2638
|
+
kind: props.kind,
|
|
2639
|
+
open: () => props.onOpenList(row.source.id)
|
|
2640
|
+
};
|
|
2641
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2642
|
+
...optionAttributes(option),
|
|
2643
|
+
role: "option",
|
|
2644
|
+
"aria-selected": active,
|
|
2645
|
+
title: `Open ${header.label}`,
|
|
2646
|
+
className: `group mx-1.5 mt-1 flex h-[calc(100%-4px)] cursor-pointer items-center gap-2.5 rounded-md px-2 text-left ${rowTone(active)}`,
|
|
2647
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
2648
|
+
onMouseEnter: activate,
|
|
2649
|
+
onClick: header.open,
|
|
2650
|
+
children: [
|
|
2651
|
+
/* @__PURE__ */ jsx("span", {
|
|
2652
|
+
"aria-hidden": "true",
|
|
2653
|
+
className: "contents",
|
|
2654
|
+
children: header.logo
|
|
2655
|
+
}),
|
|
2656
|
+
/* @__PURE__ */ jsx("span", {
|
|
2657
|
+
className: "truncate text-[13px] font-semibold text-foreground",
|
|
2658
|
+
children: /* @__PURE__ */ jsx(Highlight, {
|
|
2659
|
+
text: header.label,
|
|
2660
|
+
tokens: props.tokens
|
|
2661
|
+
})
|
|
2662
|
+
}),
|
|
2663
|
+
header.note ? /* @__PURE__ */ jsx("span", {
|
|
2664
|
+
className: "truncate text-[11px] text-muted-foreground",
|
|
2665
|
+
children: header.note
|
|
2666
|
+
}) : null,
|
|
2667
|
+
/* @__PURE__ */ jsxs("span", {
|
|
2668
|
+
className: `ml-auto flex shrink-0 items-center gap-0.5 text-[11px] text-muted-foreground ${active ? "" : "opacity-0 group-hover:opacity-100"}`,
|
|
2669
|
+
children: [
|
|
2670
|
+
"All ",
|
|
2671
|
+
header.kind,
|
|
2672
|
+
"s",
|
|
2673
|
+
/* @__PURE__ */ jsx(Icon, {
|
|
2674
|
+
name: "chevron",
|
|
2675
|
+
size: 12
|
|
2676
|
+
})
|
|
2677
|
+
]
|
|
2678
|
+
})
|
|
2679
|
+
]
|
|
2680
|
+
});
|
|
2681
|
+
}
|
|
2682
|
+
})]
|
|
2683
|
+
});
|
|
2684
|
+
}
|
|
2685
|
+
function BlockSelector(props) {
|
|
2686
|
+
const [query, setQuery] = useState("");
|
|
2687
|
+
const [tab, setTab] = useState("all");
|
|
2688
|
+
const [chip, setChip] = useState(null);
|
|
2689
|
+
const [catalog, setCatalog] = useState(null);
|
|
2690
|
+
const [selectedId, setSelectedId] = useState(null);
|
|
2691
|
+
const [paneState, setPane] = useState("sources");
|
|
2692
|
+
const [entryIndex, setEntryIndex] = useState(-1);
|
|
2693
|
+
const [rowIndex, setRowIndex] = useState(-1);
|
|
2694
|
+
const [expanded, setExpanded] = useState(/* @__PURE__ */ new Set());
|
|
2695
|
+
const containerRef = useRef(null);
|
|
2696
|
+
const inputRef = useRef(null);
|
|
2697
|
+
const baseId = useId();
|
|
2698
|
+
const listIds = {
|
|
2699
|
+
sources: `${baseId}-sources`,
|
|
2700
|
+
entries: `${baseId}-entries`,
|
|
2701
|
+
results: `${baseId}-results`
|
|
2702
|
+
};
|
|
2703
|
+
const pointerMoved = useRef(false);
|
|
2704
|
+
const hoverTimer = useRef(void 0);
|
|
2705
|
+
const { anchor, onClose } = props;
|
|
2706
|
+
useEffect(() => {
|
|
2707
|
+
const handler = (event) => {
|
|
2708
|
+
const target = event.target;
|
|
2709
|
+
if (containerRef.current?.contains(target)) return;
|
|
2710
|
+
if (anchor?.current?.contains(target)) return;
|
|
2711
|
+
onClose();
|
|
2712
|
+
};
|
|
2713
|
+
window.addEventListener("pointerdown", handler, true);
|
|
2714
|
+
return () => window.removeEventListener("pointerdown", handler, true);
|
|
2715
|
+
}, [anchor, onClose]);
|
|
2716
|
+
useEffect(() => () => clearTimeout(hoverTimer.current), []);
|
|
2717
|
+
const anySource = usePieceSource();
|
|
2718
|
+
const pieceSource = props.showPieces ? anySource : void 0;
|
|
2719
|
+
const [catalogRound, setCatalogRound] = useState(0);
|
|
2720
|
+
useEffect(() => {
|
|
2721
|
+
if (!anySource) return;
|
|
2722
|
+
let cancelled = false;
|
|
2723
|
+
let timer;
|
|
2724
|
+
const load = (attempt) => {
|
|
2725
|
+
(attempt > 0 && anySource.reloadCatalog ? anySource.reloadCatalog() : anySource.loadCatalog()).then((pieces) => {
|
|
2726
|
+
registerPieceLogos(pieces);
|
|
2727
|
+
if (!cancelled) setCatalog({ pieces });
|
|
2728
|
+
}).catch((error) => {
|
|
2729
|
+
if (cancelled) return;
|
|
2730
|
+
if (attempt + 1 < 5) {
|
|
2731
|
+
timer = setTimeout(() => load(attempt + 1), CATALOG_RETRY_MS * 2 ** attempt);
|
|
2732
|
+
return;
|
|
2733
|
+
}
|
|
2734
|
+
setCatalog({
|
|
2735
|
+
pieces: [],
|
|
2736
|
+
error: error instanceof Error ? error.message : String(error)
|
|
2737
|
+
});
|
|
2738
|
+
});
|
|
2739
|
+
};
|
|
2740
|
+
load(catalogRound > 0 ? 1 : 0);
|
|
2741
|
+
return () => {
|
|
2742
|
+
cancelled = true;
|
|
2743
|
+
clearTimeout(timer);
|
|
2744
|
+
};
|
|
2745
|
+
}, [anySource, catalogRound]);
|
|
2746
|
+
const installed = (name) => catalog?.pieces.find((entry) => entry.name === name)?.version;
|
|
2747
|
+
const versionNote = useVersionNote(catalog?.pieces);
|
|
2748
|
+
const pinned = (preset) => pinBlock(preset.block, installed);
|
|
2749
|
+
const pick = (preset) => {
|
|
2750
|
+
const block = pinned(preset);
|
|
2751
|
+
if (!block) return;
|
|
2752
|
+
rememberPick(preset);
|
|
2753
|
+
props.onPick({
|
|
2754
|
+
...preset,
|
|
2755
|
+
block
|
|
2756
|
+
});
|
|
2757
|
+
};
|
|
2758
|
+
const prefetch = useBlockFormPrefetch();
|
|
2759
|
+
const mode = props.pieceMode ?? "actions";
|
|
2760
|
+
const kind = mode === "triggers" ? "trigger" : "action";
|
|
2761
|
+
const tokens = queryTokens(query);
|
|
2762
|
+
const searching = query.trim().length >= SEARCH_MIN_CHARS;
|
|
2763
|
+
const showCatalog = pieceSource !== void 0 && tab !== "core";
|
|
2764
|
+
const tabs = pieceSource ? [
|
|
2765
|
+
"all",
|
|
2766
|
+
"core",
|
|
2767
|
+
"powerhouse",
|
|
2768
|
+
"activepieces"
|
|
2769
|
+
] : [
|
|
2770
|
+
"all",
|
|
2771
|
+
"core",
|
|
2772
|
+
"powerhouse"
|
|
2773
|
+
];
|
|
2774
|
+
const modePieces = useMemo(() => {
|
|
2775
|
+
const presetCounts = /* @__PURE__ */ new Map();
|
|
2776
|
+
for (const preset of props.presets) {
|
|
2777
|
+
const name = preset.block.pieceName;
|
|
2778
|
+
presetCounts.set(name, (presetCounts.get(name) ?? 0) + 1);
|
|
2779
|
+
}
|
|
2780
|
+
return (catalog?.pieces ?? []).filter((entry) => {
|
|
2781
|
+
return (mode === "triggers" ? entry.triggerCount : entry.actionCount) > (presetCounts.get(entry.name) ?? 0);
|
|
2782
|
+
});
|
|
2783
|
+
}, [
|
|
2784
|
+
catalog,
|
|
2785
|
+
mode,
|
|
2786
|
+
props.presets
|
|
2787
|
+
]);
|
|
2788
|
+
const tabPieces = useMemo(() => modePieces.filter((entry) => inTab(tab, entry)), [modePieces, tab]);
|
|
2789
|
+
const chips = useMemo(() => orderChips(tabPieces), [tabPieces]);
|
|
2790
|
+
const showChips = showCatalog && (tab === "activepieces" || tab === "powerhouse") && chips.length > 1;
|
|
2791
|
+
const activeChip = showChips && chip !== null && chips.includes(chip) ? chip : null;
|
|
2792
|
+
const searchFilter = useMemo(() => showCatalog ? {
|
|
2793
|
+
kind,
|
|
2794
|
+
...TAB_SOURCES[tab] ? { sources: TAB_SOURCES[tab] } : {},
|
|
2795
|
+
...activeChip ? { categories: categoriesOfChip(activeChip, tabPieces) } : {}
|
|
2796
|
+
} : null, [
|
|
2797
|
+
showCatalog,
|
|
2798
|
+
kind,
|
|
2799
|
+
tab,
|
|
2800
|
+
activeChip,
|
|
2801
|
+
tabPieces
|
|
2802
|
+
]);
|
|
2803
|
+
const search = usePieceSearch(query, searchFilter);
|
|
2804
|
+
const presetEntry = (preset) => {
|
|
2805
|
+
const block = pinned(preset);
|
|
2806
|
+
return {
|
|
2807
|
+
key: `${blockKey(preset.block)} ${preset.label}`,
|
|
2808
|
+
logo: /* @__PURE__ */ jsx(BlockLogo, {
|
|
2809
|
+
block: preset.block,
|
|
2810
|
+
size: ROW_LOGO
|
|
2811
|
+
}),
|
|
2812
|
+
label: preset.label,
|
|
2813
|
+
description: preset.description,
|
|
2814
|
+
unavailable: block ? void 0 : catalog === null ? "Loading…" : "Not installed on this runtime",
|
|
2815
|
+
version: shownVersion(preset.block.pieceName, block?.pieceVersion),
|
|
2816
|
+
versionNote: versionNote(preset.block.pieceName, block?.pieceVersion),
|
|
2817
|
+
pick: () => pick(preset),
|
|
2818
|
+
warm: block ? () => prefetch(block) : void 0
|
|
2819
|
+
};
|
|
2820
|
+
};
|
|
2821
|
+
const blockEntry = (entry, logo) => {
|
|
2822
|
+
const block = {
|
|
2823
|
+
pieceName: entry.pieceName,
|
|
2824
|
+
pieceVersion: entry.pieceVersion,
|
|
2825
|
+
kind,
|
|
2826
|
+
name: entry.name
|
|
2827
|
+
};
|
|
2828
|
+
return {
|
|
2829
|
+
key: blockKey(block),
|
|
2830
|
+
logo,
|
|
2831
|
+
label: entry.displayName,
|
|
2832
|
+
description: entry.description,
|
|
2833
|
+
unavailable: blockUnavailable({
|
|
2834
|
+
...entry,
|
|
2835
|
+
kind
|
|
2836
|
+
}),
|
|
2837
|
+
version: shownVersion(entry.pieceName, entry.pieceVersion),
|
|
2838
|
+
versionNote: versionNote(entry.pieceName, entry.pieceVersion),
|
|
2839
|
+
pick: () => pick({
|
|
2840
|
+
label: entry.displayName,
|
|
2841
|
+
block,
|
|
2842
|
+
description: entry.description,
|
|
2843
|
+
defaultConfig: {}
|
|
2844
|
+
}),
|
|
2845
|
+
warm: () => prefetch(block)
|
|
2846
|
+
};
|
|
2847
|
+
};
|
|
2848
|
+
const lists = (() => {
|
|
2849
|
+
if (activeChip !== null) return [];
|
|
2850
|
+
const result = [];
|
|
2851
|
+
const add = (id, title, subtitle, logo, entries) => {
|
|
2852
|
+
if (entries.length > 0) result.push({
|
|
2853
|
+
kind: "list",
|
|
2854
|
+
id,
|
|
2855
|
+
title,
|
|
2856
|
+
subtitle,
|
|
2857
|
+
logo,
|
|
2858
|
+
entries
|
|
2859
|
+
});
|
|
2860
|
+
};
|
|
2861
|
+
if (tab === "all") {
|
|
2862
|
+
if (props.onAttach) add("attach", "Detached steps", "Re-attach a step at this point", listTile("branch", "#64748b"), (props.attachSteps ?? []).map((step) => ({
|
|
2863
|
+
key: `attach ${step.id}`,
|
|
2864
|
+
logo: /* @__PURE__ */ jsx(BlockLogo, {
|
|
2865
|
+
block: stepBlock(step),
|
|
2866
|
+
size: ROW_LOGO
|
|
2867
|
+
}),
|
|
2868
|
+
label: step.name,
|
|
2869
|
+
description: `{{steps.${step.key}}} · detached`,
|
|
2870
|
+
pick: () => props.onAttach?.(step.id)
|
|
2871
|
+
})));
|
|
2872
|
+
}
|
|
2873
|
+
if (tab === "all" || tab === "core") add("core", "Core", "Built into the workflow engine", listTile("bolt", "#2563eb"), props.presets.filter((preset) => preset.group !== "powerhouse").map(presetEntry));
|
|
2874
|
+
if (tab === "all" || tab === "powerhouse") {
|
|
2875
|
+
const reactorPreset = props.presets.find((preset) => preset.group === "powerhouse");
|
|
2876
|
+
add("powerhouse", "Documents", "Read and change documents on this reactor", (size) => reactorPreset ? /* @__PURE__ */ jsx(BlockLogo, {
|
|
2877
|
+
block: reactorPreset.block,
|
|
2878
|
+
size
|
|
2879
|
+
}) : null, props.presets.filter((preset) => preset.group === "powerhouse").map(presetEntry));
|
|
2880
|
+
}
|
|
2881
|
+
if (tab === "all") {
|
|
2882
|
+
const recent = recentPicks(kind).filter((preset) => isCoreBlock(preset.block) || installed(preset.block.pieceName));
|
|
2883
|
+
add("recent", "Recently used", `Your last ${kind}s`, listTile("clock", "#64748b"), recent.map((preset) => {
|
|
2884
|
+
const entry = presetEntry(preset);
|
|
2885
|
+
const reason = catalog?.pieces.find((piece) => piece.name === preset.block.pieceName)?.unsupported;
|
|
2886
|
+
return reason ? {
|
|
2887
|
+
...entry,
|
|
2888
|
+
unavailable: reason
|
|
2889
|
+
} : entry;
|
|
2890
|
+
}));
|
|
2891
|
+
}
|
|
2892
|
+
return result;
|
|
2893
|
+
})();
|
|
2894
|
+
const sources = (() => {
|
|
2895
|
+
const listSources = lists.map((list) => ({
|
|
2896
|
+
...list,
|
|
2897
|
+
entries: list.entries.filter((entry) => matchesQuery(`${entry.label} ${entry.description}`, tokens))
|
|
2898
|
+
})).filter((list) => list.entries.length > 0);
|
|
2899
|
+
const pieceSources = showCatalog ? tabPieces.filter((entry) => (activeChip === null || chipsOf(entry).has(activeChip)) && matchesQuery(`${entry.displayName} ${entry.name} ${entry.description}`, tokens)).map((piece) => ({
|
|
2900
|
+
kind: "piece",
|
|
2901
|
+
id: piece.name,
|
|
2902
|
+
piece
|
|
2903
|
+
})) : [];
|
|
2904
|
+
return [...listSources, ...pieceSources];
|
|
2905
|
+
})();
|
|
2906
|
+
const selected = sources.find((source) => source.id === selectedId) ?? sources.at(0);
|
|
2907
|
+
const sourceIndex = selected ? sources.indexOf(selected) : -1;
|
|
2908
|
+
const selectedPiece = selected?.kind === "piece" ? selected.piece : void 0;
|
|
2909
|
+
const loaded = usePieceEntries(selectedPiece, mode);
|
|
2910
|
+
const pieceEntries = selectedPiece && loaded.entries ? loaded.entries.map((entry) => blockEntry(entry, /* @__PURE__ */ jsx(LogoFrame, {
|
|
2911
|
+
src: selectedPiece.logoUrl,
|
|
2912
|
+
alt: selectedPiece.displayName,
|
|
2913
|
+
size: ROW_LOGO
|
|
2914
|
+
}))) : null;
|
|
2915
|
+
const entries = selected?.kind === "list" ? selected.entries : pieceEntries ?? [];
|
|
2916
|
+
const entryAt = entries.length === 0 ? -1 : Math.min(entryIndex, entries.length - 1);
|
|
2917
|
+
const presetKeys = new Set(props.presets.map((preset) => `${preset.block.pieceName} ${preset.block.name}`));
|
|
2918
|
+
const rows = [];
|
|
2919
|
+
if (searching) {
|
|
2920
|
+
for (const source of sources) {
|
|
2921
|
+
if (source.kind !== "list" || source.id === "recent") continue;
|
|
2922
|
+
rows.push({
|
|
2923
|
+
type: "list",
|
|
2924
|
+
source
|
|
2925
|
+
});
|
|
2926
|
+
for (const entry of source.entries) rows.push({
|
|
2927
|
+
type: "entry",
|
|
2928
|
+
entry
|
|
2929
|
+
});
|
|
2930
|
+
}
|
|
2931
|
+
const groups = search.kind === "done" ? search.result.pieces.map((match) => ({
|
|
2932
|
+
...match,
|
|
2933
|
+
blocks: match.blocks.filter((hit) => !presetKeys.has(`${hit.pieceName} ${hit.name}`))
|
|
2934
|
+
})).filter((match) => match.blocks.length > 0) : [];
|
|
2935
|
+
for (const match of groups) {
|
|
2936
|
+
rows.push({
|
|
2937
|
+
type: "piece",
|
|
2938
|
+
match
|
|
2939
|
+
});
|
|
2940
|
+
const shown = groups.length <= 2 || expanded.has(match.pieceName) ? match.blocks : match.blocks.slice(0, GROUP_BLOCKS);
|
|
2941
|
+
const logo = /* @__PURE__ */ jsx(LogoFrame, {
|
|
2942
|
+
src: match.logoUrl,
|
|
2943
|
+
alt: match.displayName,
|
|
2944
|
+
size: ROW_LOGO
|
|
2945
|
+
});
|
|
2946
|
+
for (const hit of shown) rows.push({
|
|
2947
|
+
type: "entry",
|
|
2948
|
+
entry: blockEntry(hit, logo)
|
|
2949
|
+
});
|
|
2950
|
+
if (shown.length < match.blocks.length) rows.push({
|
|
2951
|
+
type: "more",
|
|
2952
|
+
pieceName: match.pieceName,
|
|
2953
|
+
hidden: match.blocks.length - shown.length
|
|
2954
|
+
});
|
|
2955
|
+
}
|
|
2956
|
+
const partial = !pieceSource?.searchPieces || search.kind === "done" && search.result.status !== "ready";
|
|
2957
|
+
if (showCatalog && partial) {
|
|
2958
|
+
const grouped = new Set(groups.map((match) => match.pieceName));
|
|
2959
|
+
const named = (source) => source.kind === "piece" && matchesQuery(source.piece.displayName, tokens) ? 0 : 1;
|
|
2960
|
+
for (const source of [...sources].sort((a, b) => named(a) - named(b))) {
|
|
2961
|
+
if (source.kind !== "piece" || grouped.has(source.id)) continue;
|
|
2962
|
+
rows.push({
|
|
2963
|
+
type: "piece",
|
|
2964
|
+
match: {
|
|
2965
|
+
pieceName: source.piece.name,
|
|
2966
|
+
pieceVersion: source.piece.version ?? "",
|
|
2967
|
+
displayName: source.piece.displayName,
|
|
2968
|
+
description: source.piece.description,
|
|
2969
|
+
logoUrl: source.piece.logoUrl,
|
|
2970
|
+
categories: source.piece.categories,
|
|
2971
|
+
source: source.piece.source ?? "activepieces",
|
|
2972
|
+
namedPiece: true,
|
|
2973
|
+
blocks: []
|
|
2974
|
+
}
|
|
2975
|
+
});
|
|
2976
|
+
}
|
|
2977
|
+
}
|
|
2978
|
+
}
|
|
2979
|
+
const activeRow = rowIndex < 0 ? rows.findIndex((row) => row.type === "entry") : Math.min(rowIndex, rows.length - 1);
|
|
2980
|
+
const twoPane = showCatalog || sources.length > 1;
|
|
2981
|
+
const pane = twoPane ? paneState : "entries";
|
|
2982
|
+
const selectSource = (id) => {
|
|
2983
|
+
setSelectedId(id);
|
|
2984
|
+
setPane("sources");
|
|
2985
|
+
setEntryIndex(-1);
|
|
2986
|
+
};
|
|
2987
|
+
const openSource = (id) => {
|
|
2988
|
+
setSelectedId(id);
|
|
2989
|
+
setPane("entries");
|
|
2990
|
+
setEntryIndex(0);
|
|
2991
|
+
};
|
|
2992
|
+
const openPiece = (pieceName) => {
|
|
2993
|
+
if (!modePieces.some((piece) => piece.name === pieceName)) {
|
|
2994
|
+
setExpanded(/* @__PURE__ */ new Set([...expanded, pieceName]));
|
|
2995
|
+
return;
|
|
2996
|
+
}
|
|
2997
|
+
setQuery("");
|
|
2998
|
+
setChip(null);
|
|
2999
|
+
if (tab !== "all") setTab("all");
|
|
3000
|
+
openSource(pieceName);
|
|
3001
|
+
inputRef.current?.focus();
|
|
3002
|
+
};
|
|
3003
|
+
const hoverSource = (id) => {
|
|
3004
|
+
if (!pointerMoved.current) return;
|
|
3005
|
+
clearTimeout(hoverTimer.current);
|
|
3006
|
+
hoverTimer.current = setTimeout(() => selectSource(id), HOVER_PREVIEW_MS);
|
|
3007
|
+
};
|
|
3008
|
+
const step = (index, delta, count) => count === 0 ? index : Math.min(Math.max(index + delta, 0), count - 1);
|
|
3009
|
+
const onKeyDown = (event) => {
|
|
3010
|
+
const key = event.key;
|
|
3011
|
+
if (key !== "Escape" && event.target !== inputRef.current) return;
|
|
3012
|
+
if (key === "Escape") {
|
|
3013
|
+
event.stopPropagation();
|
|
3014
|
+
if (query !== "") setQuery("");
|
|
3015
|
+
else if (twoPane && pane === "entries" && !searching) setPane("sources");
|
|
3016
|
+
else onClose();
|
|
3017
|
+
return;
|
|
3018
|
+
}
|
|
3019
|
+
const delta = key === "ArrowDown" ? 1 : key === "ArrowUp" ? -1 : 0;
|
|
3020
|
+
if (searching) {
|
|
3021
|
+
if (delta !== 0) {
|
|
3022
|
+
event.preventDefault();
|
|
3023
|
+
setRowIndex(Math.max(step(activeRow, delta, rows.length), 0));
|
|
3024
|
+
return;
|
|
3025
|
+
}
|
|
3026
|
+
if (key === "Enter") {
|
|
3027
|
+
event.preventDefault();
|
|
3028
|
+
if (search.kind === "done" && search.stale) return;
|
|
3029
|
+
const row = rows.at(activeRow);
|
|
3030
|
+
if (!row) return;
|
|
3031
|
+
if (row.type === "entry") {
|
|
3032
|
+
if (row.entry.unavailable === void 0) row.entry.pick();
|
|
3033
|
+
} else if (row.type === "piece") openPiece(row.match.pieceName);
|
|
3034
|
+
else if (row.type === "list") openSource(row.source.id);
|
|
3035
|
+
else setExpanded(/* @__PURE__ */ new Set([...expanded, row.pieceName]));
|
|
3036
|
+
}
|
|
3037
|
+
return;
|
|
3038
|
+
}
|
|
3039
|
+
const sideways = query === "";
|
|
3040
|
+
if (pane === "sources") {
|
|
3041
|
+
if (delta !== 0) {
|
|
3042
|
+
event.preventDefault();
|
|
3043
|
+
const next = sources.at(step(sourceIndex, delta, sources.length));
|
|
3044
|
+
if (next) selectSource(next.id);
|
|
3045
|
+
} else if (key === "Enter" || sideways && key === "ArrowRight") {
|
|
3046
|
+
event.preventDefault();
|
|
3047
|
+
if (selected) openSource(selected.id);
|
|
3048
|
+
}
|
|
3049
|
+
return;
|
|
3050
|
+
}
|
|
3051
|
+
if (delta !== 0) {
|
|
3052
|
+
event.preventDefault();
|
|
3053
|
+
setEntryIndex(step(entryIndex, delta, entries.length));
|
|
3054
|
+
} else if (sideways && key === "ArrowLeft") {
|
|
3055
|
+
event.preventDefault();
|
|
3056
|
+
setPane("sources");
|
|
3057
|
+
} else if (key === "Enter") {
|
|
3058
|
+
event.preventDefault();
|
|
3059
|
+
const entry = entryAt < 0 ? void 0 : entries.at(entryAt);
|
|
3060
|
+
if (entry && entry.unavailable === void 0) entry.pick();
|
|
3061
|
+
}
|
|
3062
|
+
};
|
|
3063
|
+
const width = props.width ?? (pieceSource ? PICKER_SIZE.width : 360);
|
|
3064
|
+
const activeList = searching ? listIds.results : pane === "entries" ? listIds.entries : listIds.sources;
|
|
3065
|
+
const activeIndex = searching ? activeRow : pane === "entries" ? entryAt : sourceIndex;
|
|
3066
|
+
const activeOption = activeIndex >= 0 ? optionId(activeList, activeIndex) : void 0;
|
|
3067
|
+
const searchStatus = search.kind === "loading" || search.kind === "done" && search.stale ? /* @__PURE__ */ jsx(Status, { children: "Searching…" }) : search.kind === "error" ? /* @__PURE__ */ jsx(Status, {
|
|
3068
|
+
error: true,
|
|
3069
|
+
children: search.message
|
|
3070
|
+
}) : search.kind === "done" && search.result.status === "indexing" ? /* @__PURE__ */ jsx(Status, { children: "Still indexing the catalog: pieces are matched by name until it is ready." }) : search.kind === "done" && search.result.status === "error" ? /* @__PURE__ */ jsxs(Status, {
|
|
3071
|
+
error: true,
|
|
3072
|
+
children: [search.result.error ?? "Search failed", "; pieces are matched by name."]
|
|
3073
|
+
}) : rows.length === 0 ? /* @__PURE__ */ jsxs(Status, { children: [
|
|
3074
|
+
"No matching ",
|
|
3075
|
+
kind,
|
|
3076
|
+
"s"
|
|
3077
|
+
] }) : null;
|
|
3078
|
+
const compact = !twoPane && !searching;
|
|
3079
|
+
const height = props.height ?? PICKER_SIZE.height;
|
|
3080
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
3081
|
+
ref: containerRef,
|
|
3082
|
+
className: "nodrag nopan nowheel flex flex-col overflow-hidden rounded-lg border border-solid border-foreground/10 bg-card shadow-xl",
|
|
3083
|
+
style: compact ? {
|
|
3084
|
+
width,
|
|
3085
|
+
maxHeight: height
|
|
3086
|
+
} : {
|
|
3087
|
+
width,
|
|
3088
|
+
height
|
|
3089
|
+
},
|
|
3090
|
+
onClick: (event) => event.stopPropagation(),
|
|
3091
|
+
onKeyDown,
|
|
3092
|
+
onMouseMove: () => {
|
|
3093
|
+
pointerMoved.current = true;
|
|
3094
|
+
},
|
|
3095
|
+
children: [
|
|
3096
|
+
/* @__PURE__ */ jsxs("div", {
|
|
3097
|
+
className: "shrink-0 border-b border-foreground/10",
|
|
3098
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
3099
|
+
className: "flex items-center gap-2 px-3.5 pt-3 text-muted-foreground",
|
|
3100
|
+
children: [
|
|
3101
|
+
/* @__PURE__ */ jsx(Icon, {
|
|
3102
|
+
name: "search",
|
|
3103
|
+
size: 15
|
|
3104
|
+
}),
|
|
3105
|
+
/* @__PURE__ */ jsx("input", {
|
|
3106
|
+
ref: inputRef,
|
|
3107
|
+
autoFocus: true,
|
|
3108
|
+
role: "combobox",
|
|
3109
|
+
"aria-expanded": true,
|
|
3110
|
+
"aria-autocomplete": "list",
|
|
3111
|
+
"aria-label": `Search ${props.title.toLowerCase()}`,
|
|
3112
|
+
"aria-controls": activeList,
|
|
3113
|
+
"aria-activedescendant": activeOption,
|
|
3114
|
+
className: "min-w-0 flex-1 bg-transparent py-1 text-sm text-foreground outline-none placeholder:text-muted-foreground",
|
|
3115
|
+
placeholder: pieceSource ? `Search pieces and ${kind}s…` : "Search…",
|
|
3116
|
+
value: query,
|
|
3117
|
+
onChange: (event) => {
|
|
3118
|
+
setQuery(event.target.value);
|
|
3119
|
+
setRowIndex(-1);
|
|
3120
|
+
setExpanded(/* @__PURE__ */ new Set());
|
|
3121
|
+
}
|
|
3122
|
+
}),
|
|
3123
|
+
/* @__PURE__ */ jsx("span", {
|
|
3124
|
+
className: "shrink-0 truncate text-xs",
|
|
3125
|
+
children: props.title
|
|
3126
|
+
})
|
|
3127
|
+
]
|
|
3128
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
3129
|
+
className: "px-3 pb-2.5 pt-2",
|
|
3130
|
+
children: /* @__PURE__ */ jsx(Tabs, {
|
|
3131
|
+
tabs,
|
|
3132
|
+
active: tab,
|
|
3133
|
+
onSelect: (next, fromKeyboard) => {
|
|
3134
|
+
setTab(next);
|
|
3135
|
+
setChip(null);
|
|
3136
|
+
setSelectedId(null);
|
|
3137
|
+
setPane("sources");
|
|
3138
|
+
if (!fromKeyboard) inputRef.current?.focus();
|
|
3139
|
+
}
|
|
3140
|
+
})
|
|
3141
|
+
})]
|
|
3142
|
+
}),
|
|
3143
|
+
showChips && catalog && !catalog.error ? /* @__PURE__ */ jsx(ChipBar, { children: chips.map((label, index) => /* @__PURE__ */ jsx(Chip, {
|
|
3144
|
+
label,
|
|
3145
|
+
active: activeChip === label,
|
|
3146
|
+
tabStop: activeChip === null ? index === 0 : activeChip === label,
|
|
3147
|
+
onClick: (fromKeyboard) => {
|
|
3148
|
+
setChip(activeChip === label ? null : label);
|
|
3149
|
+
setSelectedId(null);
|
|
3150
|
+
if (!fromKeyboard) inputRef.current?.focus();
|
|
3151
|
+
}
|
|
3152
|
+
}, label)) }) : null,
|
|
3153
|
+
searching ? /* @__PURE__ */ jsx(SearchList, {
|
|
3154
|
+
rows,
|
|
3155
|
+
tokens,
|
|
3156
|
+
activeIndex: activeRow,
|
|
3157
|
+
onActivate: (index) => {
|
|
3158
|
+
if (pointerMoved.current) setRowIndex(index);
|
|
3159
|
+
},
|
|
3160
|
+
onOpenPiece: openPiece,
|
|
3161
|
+
onOpenList: (id) => {
|
|
3162
|
+
setQuery("");
|
|
3163
|
+
openSource(id);
|
|
3164
|
+
},
|
|
3165
|
+
onExpand: (name) => setExpanded(/* @__PURE__ */ new Set([...expanded, name])),
|
|
3166
|
+
status: searchStatus,
|
|
3167
|
+
kind,
|
|
3168
|
+
listId: listIds.results,
|
|
3169
|
+
resetKey: `${query} ${JSON.stringify(searchFilter)}`,
|
|
3170
|
+
stale: search.kind === "done" && search.stale
|
|
3171
|
+
}) : /* @__PURE__ */ jsxs("div", {
|
|
3172
|
+
className: "flex min-h-0 flex-1",
|
|
3173
|
+
children: [twoPane ? /* @__PURE__ */ jsxs("div", {
|
|
3174
|
+
className: "flex w-56 shrink-0 flex-col border-r border-foreground/10 bg-foreground/[0.025]",
|
|
3175
|
+
children: [
|
|
3176
|
+
catalog?.error ? /* @__PURE__ */ jsxs("div", {
|
|
3177
|
+
className: "flex items-center gap-2 px-3 py-2 text-xs text-wf-fail",
|
|
3178
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
3179
|
+
className: "min-w-0 flex-1",
|
|
3180
|
+
children: catalog.error
|
|
3181
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
3182
|
+
type: "button",
|
|
3183
|
+
className: "shrink-0 cursor-pointer rounded border border-solid border-foreground/15 bg-card px-1.5 py-0.5 text-foreground hover:border-foreground/25",
|
|
3184
|
+
onClick: () => {
|
|
3185
|
+
setCatalog(null);
|
|
3186
|
+
setCatalogRound((round) => round + 1);
|
|
3187
|
+
},
|
|
3188
|
+
children: "Retry"
|
|
3189
|
+
})]
|
|
3190
|
+
}) : null,
|
|
3191
|
+
/* @__PURE__ */ jsx(VirtualList, {
|
|
3192
|
+
id: listIds.sources,
|
|
3193
|
+
label: "Pieces",
|
|
3194
|
+
resetKey: `${tab} ${activeChip ?? ""} ${query}`,
|
|
3195
|
+
className: "flex-1 py-1",
|
|
3196
|
+
items: sources,
|
|
3197
|
+
heightOf: sourceHeight,
|
|
3198
|
+
keyOf: (source) => `${source.kind}:${source.id}`,
|
|
3199
|
+
activeIndex: sourceIndex,
|
|
3200
|
+
render: (source, index) => /* @__PURE__ */ jsx(SourceRow, {
|
|
3201
|
+
source,
|
|
3202
|
+
tokens,
|
|
3203
|
+
mode,
|
|
3204
|
+
active: pane === "sources" && index === sourceIndex,
|
|
3205
|
+
selected: index === sourceIndex,
|
|
3206
|
+
option: {
|
|
3207
|
+
list: listIds.sources,
|
|
3208
|
+
index,
|
|
3209
|
+
size: sources.length
|
|
3210
|
+
},
|
|
3211
|
+
onActivate: () => hoverSource(source.id),
|
|
3212
|
+
onOpen: () => {
|
|
3213
|
+
clearTimeout(hoverTimer.current);
|
|
3214
|
+
openSource(source.id);
|
|
3215
|
+
inputRef.current?.focus();
|
|
3216
|
+
}
|
|
3217
|
+
})
|
|
3218
|
+
}),
|
|
3219
|
+
showCatalog && catalog === null ? /* @__PURE__ */ jsx(Status, { children: "Loading catalog…" }) : sources.length === 0 ? /* @__PURE__ */ jsx(Status, { children: tab === "powerhouse" && tokens.length === 0 ? "No registry pieces on this runtime" : "No matching pieces" }) : null
|
|
3220
|
+
]
|
|
3221
|
+
}) : null, /* @__PURE__ */ jsx(EntriesPane, {
|
|
3222
|
+
source: selected,
|
|
3223
|
+
mode,
|
|
3224
|
+
pieceEntries,
|
|
3225
|
+
pieceError: selected?.kind === "piece" ? loaded.error : null,
|
|
3226
|
+
tokens,
|
|
3227
|
+
activeIndex: pane === "entries" ? entryAt : -1,
|
|
3228
|
+
listId: listIds.entries,
|
|
3229
|
+
showHeader: twoPane,
|
|
3230
|
+
onActivate: (index) => {
|
|
3231
|
+
if (!pointerMoved.current) return;
|
|
3232
|
+
setPane("entries");
|
|
3233
|
+
setEntryIndex(index);
|
|
3234
|
+
}
|
|
3235
|
+
})]
|
|
3236
|
+
})
|
|
3237
|
+
]
|
|
3238
|
+
});
|
|
3239
|
+
}
|
|
3240
|
+
//#endregion
|
|
3241
|
+
export { useTestStepRunner as $, runStats as A, IconButton as At, useBlockForms as B, Icon as Bt, canRerun as C, ITEM_PARAM as Ct, formatMs as D, FieldError as Dt, formatDuration as E, Button as Et, toneOf as F, Toggle as Ft, useDesignTime as G, useBlockResolutions as H, DocumentErrorBoundary as Ht, workflowHealth as I, Tooltip as It, useDynamicPrefetch as J, useDynamicCache as K, DesignTimeProvider as L, invalidClass as Lt, runTimeline as M, Select as Mt, runTone as N, Switch as Nt, formatTrigger as O, FieldLabel as Ot, statusLabel as P, Tabs$1 as Pt, useRunById as Q, useBlockForm as R, textAreaClass as Rt, TONE_TEXT as S, useSecretStat as St, formatAbsolute as T, useSearchParamDraft as Tt, useCachedBlockForm as U, DocumentLoadError as Ut, useBlockPorts as V, isIconName as Vt, useConnectionList as W, errorMessage as Wt, useOptionSearch as X, useLatestRun as Y, useResolvedProp as Z, CONNECTION_TONE as _, useRunPagesQuery as _t, BlockResolutionsProvider as a, parsePropList as at, STEP_TONE as b, useRuntime as bt, runsDifferentVersion as c, storedSchema as ct, versionBadge as d, withSetting as dt, useTestTrigger as et, blockMeta as f, workflowReadiness as ft, usePieceLogos as g, usePieceCatalog as gt, useBlockMeta as h, useOAuthRedirectUri as ht, PickerPopover as i, isPropVisible as it, runStatusLabel as j, Segmented as jt, formatWhen as k, Hint as kt, updateVersion as l, stripOptions as lt, pieceLogo as m, useOAuthAttempt as mt, BlockSelector as n, blockMissing as nt, VersionSummary as o, resolverInputFor as ot, pieceDisplayName as p, WorkflowRuntimeProvider as pt, useDynamicLookup as q, PICKER_SIZE as r, isEmptyValue as rt, resolutionText as s, settingFor as st, BlockLogo as t, useWebhookEndpoint as tt, useResolution as u, undeclaredPortIssues as ut, RUN_STATUSES as v, useRunQuery as vt, durationMs as w, useSearchParam as wt, TONE_DOT as x, useRuntimeActions as xt, RUN_TONE as y, useRunsQuery as yt, useBlockFormLoader as z, textInputClass as zt };
|
|
3242
|
+
|
|
3243
|
+
//# sourceMappingURL=BlockSelector-DFX-DZHl.js.map
|