@powerhousedao/workflow 6.2.3-dev.82 → 6.2.3-dev.84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/README.md +3 -1
  2. package/dist/browser/{BlockSelector-DHVzUGjW.js → BlockSelector-CtoMNZ9A.js} +4 -3
  3. package/dist/browser/BlockSelector-CtoMNZ9A.js.map +1 -0
  4. package/dist/browser/{connection-form-D2qAEHsl.js → connection-form-_H-tP2Vk.js} +2 -2
  5. package/dist/browser/{connection-form-D2qAEHsl.js.map → connection-form-_H-tP2Vk.js.map} +1 -1
  6. package/dist/browser/{data-tree-BOuPR-2J.js → data-tree-CjWQllC7.js} +2 -2
  7. package/dist/browser/{data-tree-BOuPR-2J.js.map → data-tree-CjWQllC7.js.map} +1 -1
  8. package/dist/browser/{editor-BD-5ClkW.js → editor-B1AzXxaF.js} +207 -33
  9. package/dist/browser/editor-B1AzXxaF.js.map +1 -0
  10. package/dist/browser/{editor--59WtNaj.js → editor-B9069RYZ.js} +9 -2535
  11. package/dist/browser/editor-B9069RYZ.js.map +1 -0
  12. package/dist/browser/{editor-0XPrGeLT.js → editor-DgdTF2up.js} +3 -3
  13. package/dist/browser/{editor-0XPrGeLT.js.map → editor-DgdTF2up.js.map} +1 -1
  14. package/dist/browser/editors/connection-editor/module.js +1 -1
  15. package/dist/browser/editors/workflow-editor/module.js +1 -1
  16. package/dist/browser/editors/workflow-studio/module.js +1 -1
  17. package/dist/browser/trigger-text-BgpPIXEJ.js +3040 -0
  18. package/dist/browser/trigger-text-BgpPIXEJ.js.map +1 -0
  19. package/dist/node/{BlockSelector-D2UAnFpN.mjs → BlockSelector-CbdgYJfp.mjs} +5 -4
  20. package/dist/node/BlockSelector-CbdgYJfp.mjs.map +1 -0
  21. package/dist/node/{connection-form-Btmejfyn.mjs → connection-form-DPbyrUIm.mjs} +3 -3
  22. package/dist/node/{connection-form-Btmejfyn.mjs.map → connection-form-DPbyrUIm.mjs.map} +1 -1
  23. package/dist/node/{data-tree-rZiK2Ev-.mjs → data-tree-CXa2kEuD.mjs} +2 -2
  24. package/dist/node/{data-tree-rZiK2Ev-.mjs.map → data-tree-CXa2kEuD.mjs.map} +1 -1
  25. package/dist/node/{editor-U6trS0QO.mjs → editor-BGz1Ljdk.mjs} +9 -2534
  26. package/dist/node/editor-BGz1Ljdk.mjs.map +1 -0
  27. package/dist/node/{editor-C_eWGGi8.mjs → editor-D3MlbYBN.mjs} +207 -34
  28. package/dist/node/editor-D3MlbYBN.mjs.map +1 -0
  29. package/dist/node/{editor-ChJMxbeM.mjs → editor-DzxyNgYk.mjs} +4 -4
  30. package/dist/node/{editor-ChJMxbeM.mjs.map → editor-DzxyNgYk.mjs.map} +1 -1
  31. package/dist/node/editors/connection-editor/module.mjs +1 -1
  32. package/dist/node/editors/runtime/index.mjs +1 -1
  33. package/dist/node/editors/workflow-editor/module.mjs +1 -1
  34. package/dist/node/editors/workflow-studio/module.mjs +1 -1
  35. package/dist/node/index.mjs +1 -1
  36. package/dist/node/pieces/ai/descriptor.json +1 -1
  37. package/dist/node/pieces/ai/package.json +1 -1
  38. package/dist/node/pieces/reactor/descriptor.json +1 -1
  39. package/dist/node/pieces/reactor/package.json +1 -1
  40. package/dist/node/{runtime-queries-CmrHBPRw.mjs → runtime-queries-CatdoDey.mjs} +155 -4
  41. package/dist/node/runtime-queries-CatdoDey.mjs.map +1 -0
  42. package/dist/node/trigger-text-yNCaB6pd.mjs +3040 -0
  43. package/dist/node/trigger-text-yNCaB6pd.mjs.map +1 -0
  44. package/dist/powerhouse.manifest.json +2 -2
  45. package/dist/style.css +1 -1
  46. package/dist/types/editors/shared/controls.d.ts.map +1 -1
  47. package/dist/types/editors/workflow-editor/ui/manual-inputs.d.ts +7 -0
  48. package/dist/types/editors/workflow-editor/ui/manual-inputs.d.ts.map +1 -0
  49. package/dist/types/editors/workflow-editor/ui/manual-inputs.test.d.ts +2 -0
  50. package/dist/types/editors/workflow-editor/ui/manual-inputs.test.d.ts.map +1 -0
  51. package/dist/types/editors/workflow-studio/components/RunDialog.d.ts +7 -0
  52. package/dist/types/editors/workflow-studio/components/RunDialog.d.ts.map +1 -0
  53. package/dist/types/editors/workflow-studio/components/RunsView.d.ts +3 -1
  54. package/dist/types/editors/workflow-studio/components/RunsView.d.ts.map +1 -1
  55. package/dist/types/editors/workflow-studio/components/WorkflowStudio.d.ts.map +1 -1
  56. package/dist/types/editors/workflow-studio/components/run-dialog.test.d.ts +2 -0
  57. package/dist/types/editors/workflow-studio/components/run-dialog.test.d.ts.map +1 -0
  58. package/dist/types/test/graphql-server.d.ts +9 -0
  59. package/dist/types/test/graphql-server.d.ts.map +1 -0
  60. package/dist/types/test/ui/manual-inputs.spec.d.ts +2 -0
  61. package/dist/types/test/ui/manual-inputs.spec.d.ts.map +1 -0
  62. package/package.json +9 -9
  63. package/dist/browser/BlockSelector-DHVzUGjW.js.map +0 -1
  64. package/dist/browser/editor--59WtNaj.js.map +0 -1
  65. package/dist/browser/editor-BD-5ClkW.js.map +0 -1
  66. package/dist/browser/trigger-text-Co-dn9x-.js +0 -513
  67. package/dist/browser/trigger-text-Co-dn9x-.js.map +0 -1
  68. package/dist/node/BlockSelector-D2UAnFpN.mjs.map +0 -1
  69. package/dist/node/editor-C_eWGGi8.mjs.map +0 -1
  70. package/dist/node/editor-U6trS0QO.mjs.map +0 -1
  71. package/dist/node/runtime-queries-CmrHBPRw.mjs.map +0 -1
  72. package/dist/node/trigger-text-CAiRCG2X.mjs +0 -512
  73. package/dist/node/trigger-text-CAiRCG2X.mjs.map +0 -1
@@ -0,0 +1,3040 @@
1
+ import { A as MANUAL_TRIGGER, F as WEBHOOK_TRIGGER, M as SCHEDULE_TRIGGER, V as triggerBlock, z as stepBlock } from "./runtime-queries-LAcyniYz.js";
2
+ import { At as IconButton, Bt as Icon, Dt as FieldError, Et as Button, Ft as Toggle, It as Tooltip, K as useDynamicCache, Lt as invalidClass, Mt as Select, Nt as Switch, Pt as Tabs, Rt as textAreaClass, Vt as isIconName, X as useOptionSearch, Z as useResolvedProp, at as parsePropList, dt as withSetting, f as blockMeta, it as isPropVisible, jt as Segmented, kt as Hint, lt as stripOptions, ot as resolverInputFor, rt as isEmptyValue, st as settingFor, t as BlockLogo, zt as textInputClass } from "./BlockSelector-CtoMNZ9A.js";
3
+ import { useSetSelectedNode } from "@powerhousedao/reactor-browser";
4
+ import { blockKey } from "@powerhousedao/pieces-framework/block-type";
5
+ import { DOCUMENT_REF_KEY, NEXT_PORT, documentRefsIn, expandDocumentRefs, isDocumentRefMarker, parseScheduleConfig } from "@powerhousedao/pieces-framework/workflow";
6
+ import { Fragment, Suspense, createContext, lazy, useContext, useEffect, useId, useMemo, useRef, useState } from "react";
7
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
8
+ import { createPortal } from "react-dom";
9
+ //#region editors/workflow-editor/ui/prop-defaults.ts
10
+ function asRecord(value) {
11
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
12
+ }
13
+ function withPropDefaults(props, config) {
14
+ const next = { ...asRecord(config) };
15
+ for (const prop of props) {
16
+ if (prop.type === "MARKDOWN" || prop.defaultValue === void 0) continue;
17
+ if (next[prop.name] === void 0) next[prop.name] = prop.defaultValue;
18
+ }
19
+ return next;
20
+ }
21
+ function lacksDefaults(props, config) {
22
+ const record = asRecord(config);
23
+ return props.some((prop) => prop.type !== "MARKDOWN" && prop.defaultValue !== void 0 && record[prop.name] === void 0);
24
+ }
25
+ //#endregion
26
+ //#region editors/workflow-editor/ui/model.ts
27
+ const VARIABLES_VIEW = "__variables";
28
+ /** Query params of the editor's view: the open panel and its tab. */
29
+ const STEP_PARAM = "step";
30
+ function hasDraftChanges(model) {
31
+ return !model.published || model.published.version !== model.version;
32
+ }
33
+ function uniqueStepKey(taken, label) {
34
+ const base = label.toLowerCase().replaceAll(/[^a-z0-9]+/g, "_").replaceAll(/^_+|_+$/g, "") || "step";
35
+ const keys = new Set(taken);
36
+ let key = base;
37
+ let suffix = 2;
38
+ while (keys.has(key)) key = `${base}_${suffix++}`;
39
+ return key;
40
+ }
41
+ //#endregion
42
+ //#region editors/workflow-editor/ui/document-shape.ts
43
+ const MAX_DEPTH$1 = 6;
44
+ const normalize = (name) => name.toLowerCase().replace(/[^a-z0-9]/g, "");
45
+ function typeName(node, kind) {
46
+ if (node.kind === kind.NON_NULL_TYPE) {
47
+ const inner = typeName(node.type, kind);
48
+ return {
49
+ name: inner.name,
50
+ display: `${inner.display}!`
51
+ };
52
+ }
53
+ if (node.kind === kind.LIST_TYPE) {
54
+ const inner = typeName(node.type, kind);
55
+ return {
56
+ name: inner.name,
57
+ display: `[${inner.display}]`
58
+ };
59
+ }
60
+ return {
61
+ name: node.name.value,
62
+ display: node.name.value
63
+ };
64
+ }
65
+ async function stateFieldsFromSdl(model) {
66
+ if (!model.schema) return {};
67
+ const { Kind, parse } = await import("graphql");
68
+ let definitions;
69
+ try {
70
+ definitions = parse(model.schema).definitions;
71
+ } catch {
72
+ return {};
73
+ }
74
+ const types = /* @__PURE__ */ new Map();
75
+ for (const def of definitions) {
76
+ if (def.kind !== Kind.OBJECT_TYPE_DEFINITION && def.kind !== Kind.INPUT_OBJECT_TYPE_DEFINITION) continue;
77
+ types.set(normalize(def.name.value), (def.fields ?? []).map((field) => ({
78
+ name: field.name.value,
79
+ type: field.type
80
+ })));
81
+ }
82
+ const root = [`${normalize(model.name)}state`, `${normalize(model.name)}globalstate`].map((candidate) => types.get(candidate)).find((fields) => fields !== void 0);
83
+ const build = (fields, depth) => Object.fromEntries(fields.map((field) => {
84
+ const { name, display } = typeName(field.type, Kind);
85
+ const inner = types.get(normalize(name));
86
+ return [field.name, inner && inner.length > 0 && depth < MAX_DEPTH$1 ? build(inner, depth + 1) : display];
87
+ }));
88
+ return root ? build(root, 0) : {};
89
+ }
90
+ function documentShape(reference, globalState) {
91
+ return {
92
+ header: {
93
+ id: reference.documentId,
94
+ documentType: reference.documentType,
95
+ name: "String",
96
+ slug: "String",
97
+ branch: reference.branch,
98
+ revision: reference.revision,
99
+ createdAtUtcIso: "DateTime!",
100
+ lastModifiedAtUtcIso: "DateTime!"
101
+ },
102
+ state: { global: globalState }
103
+ };
104
+ }
105
+ //#endregion
106
+ //#region editors/workflow-editor/ui/variable-types.ts
107
+ const VARIABLE_TYPE_LABEL = {
108
+ TEXT: "Text",
109
+ NUMBER: "Number",
110
+ BOOLEAN: "True or false",
111
+ JSON: "JSON",
112
+ SECRET: "Secret"
113
+ };
114
+ const VARIABLE_TYPES = Object.keys(VARIABLE_TYPE_LABEL);
115
+ const DECIMAL$1 = /^-?(?:\d+(?:\.\d*)?|\.\d+)$/;
116
+ function parseTypedValue(type, raw) {
117
+ const trimmed = raw.trim();
118
+ switch (type) {
119
+ case "TEXT": return {
120
+ ok: true,
121
+ value: raw === "" ? null : raw
122
+ };
123
+ case "NUMBER":
124
+ if (trimmed === "") return {
125
+ ok: true,
126
+ value: null
127
+ };
128
+ return DECIMAL$1.test(trimmed) ? {
129
+ ok: true,
130
+ value: Number(trimmed)
131
+ } : {
132
+ ok: false,
133
+ error: "Not a number"
134
+ };
135
+ case "BOOLEAN":
136
+ if (trimmed === "true") return {
137
+ ok: true,
138
+ value: true
139
+ };
140
+ if (trimmed === "false") return {
141
+ ok: true,
142
+ value: false
143
+ };
144
+ return {
145
+ ok: false,
146
+ error: "Not true or false"
147
+ };
148
+ case "JSON":
149
+ if (trimmed === "") return {
150
+ ok: true,
151
+ value: null
152
+ };
153
+ try {
154
+ return {
155
+ ok: true,
156
+ value: JSON.parse(trimmed)
157
+ };
158
+ } catch (error) {
159
+ return {
160
+ ok: false,
161
+ error: `Not valid JSON: ${error instanceof Error ? error.message : String(error)}`
162
+ };
163
+ }
164
+ case "SECRET": return {
165
+ ok: false,
166
+ error: "Secrets are set through the secret field"
167
+ };
168
+ }
169
+ }
170
+ function valueMismatch(type, value) {
171
+ if (value === null || value === void 0) return null;
172
+ switch (type) {
173
+ case "TEXT": return typeof value === "string" ? null : "Not text";
174
+ case "NUMBER": return typeof value === "number" ? null : "Not a number";
175
+ case "BOOLEAN": return typeof value === "boolean" ? null : "Not true or false";
176
+ case "JSON": return null;
177
+ case "SECRET": return typeof value === "string" ? null : "Not a secret reference";
178
+ }
179
+ }
180
+ function convertVariableValue(value, from, to) {
181
+ if (from === to) return value;
182
+ if (from === "SECRET" || to === "SECRET") return null;
183
+ if (to === "JSON" || value === null || value === void 0) return value ?? null;
184
+ if (to === "TEXT") return typeof value === "string" ? value : JSON.stringify(value);
185
+ if (typeof value === "string") {
186
+ const parsed = parseTypedValue(to, value);
187
+ if (parsed.ok) return parsed.value;
188
+ }
189
+ return value;
190
+ }
191
+ //#endregion
192
+ //#region editors/workflow-editor/ui/expression-scope.ts
193
+ const EMPTY_SCOPE = {
194
+ value: {},
195
+ captions: {}
196
+ };
197
+ const MAX_DEPTH = 6;
198
+ const MAX_ARRAY_ITEMS = 25;
199
+ function capValue(value, depth = 0) {
200
+ if (value === null || typeof value !== "object") return value;
201
+ if (depth >= MAX_DEPTH) return Array.isArray(value) ? "[…]" : "{…}";
202
+ if (Array.isArray(value)) return value.slice(0, MAX_ARRAY_ITEMS).map((item) => capValue(item, depth + 1));
203
+ return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, capValue(entry, depth + 1)]));
204
+ }
205
+ function upstreamStepIds(model, stepId) {
206
+ const incoming = /* @__PURE__ */ new Map();
207
+ for (const edge of model.edges) incoming.set(edge.to, [...incoming.get(edge.to) ?? [], edge.from]);
208
+ const upstream = /* @__PURE__ */ new Set();
209
+ const queue = [stepId];
210
+ while (queue.length > 0) for (const from of incoming.get(queue.pop()) ?? []) if (!upstream.has(from)) {
211
+ upstream.add(from);
212
+ queue.push(from);
213
+ }
214
+ return upstream;
215
+ }
216
+ function formatRunTime(startedAt, now = /* @__PURE__ */ new Date()) {
217
+ const date = new Date(startedAt);
218
+ if (Number.isNaN(date.getTime())) return startedAt;
219
+ const sameDay = date.toDateString() === now.toDateString();
220
+ const time = date.toLocaleTimeString([], {
221
+ hour: "2-digit",
222
+ minute: "2-digit"
223
+ });
224
+ return sameDay ? time : `${date.toLocaleDateString([], {
225
+ month: "short",
226
+ day: "numeric"
227
+ })} ${time}`;
228
+ }
229
+ const hasOutput = (step) => (step.status === "SUCCEEDED" || step.status === "REPLAYED") && step.output !== void 0 && step.output !== null;
230
+ async function withDocuments(value, documentOutput) {
231
+ const references = documentRefsIn(value);
232
+ if (references.length === 0) return value;
233
+ const key = (reference) => `${reference.branch}:${reference.documentId}`;
234
+ const shapeOf = async (reference) => {
235
+ try {
236
+ if (documentOutput) return await documentOutput(reference);
237
+ } catch {}
238
+ return documentShape(reference, {});
239
+ };
240
+ const shapes = new Map(await Promise.all(references.map(async (reference) => [key(reference), await shapeOf(reference)])));
241
+ return expandDocumentRefs(value, (reference) => shapes.get(key(reference)));
242
+ }
243
+ async function buildExpressionScope(options) {
244
+ const { model, latestRun } = options;
245
+ const documents = (value) => withDocuments(value, options.documentOutput);
246
+ const runCaption = latestRun ? `from run ${formatRunTime(latestRun.startedAt, options.now)}` : void 0;
247
+ const runSteps = new Map((latestRun?.steps ?? []).filter(hasOutput).map((step) => [step.stepKey, step]));
248
+ const value = {};
249
+ const captions = {};
250
+ const testCaption = (sample) => `from test ${formatRunTime(sample.testedAt, options.now)}`;
251
+ const tested = async (block) => block.lastTest && options.testOutput ? options.testOutput(block.id).catch(() => void 0) : void 0;
252
+ if (model.trigger) {
253
+ const sample = await tested(model.trigger);
254
+ if (sample) {
255
+ value.trigger = { payload: capValue(await documents(sample.value)) };
256
+ captions["trigger.payload"] = testCaption(sample);
257
+ } else if (runCaption && latestRun?.triggerPayload !== void 0 && latestRun.triggerPayload !== null) {
258
+ value.trigger = { payload: capValue(await documents(latestRun.triggerPayload)) };
259
+ captions["trigger.payload"] = runCaption;
260
+ } else {
261
+ value.trigger = { payload: await options.authoredOutput(triggerBlock(model.trigger), model.trigger.config) };
262
+ captions["trigger.payload"] = "declared type";
263
+ }
264
+ }
265
+ const upstream = upstreamStepIds(model, options.stepId);
266
+ const steps = {};
267
+ await Promise.all(model.steps.filter((step) => upstream.has(step.id)).map(async (step) => {
268
+ const sample = await tested(step);
269
+ if (sample) {
270
+ steps[step.key] = { output: capValue(await documents(sample.value)) };
271
+ captions[`steps.${step.key}.output`] = testCaption(sample);
272
+ return;
273
+ }
274
+ const journaled = runSteps.get(step.key);
275
+ if (runCaption && journaled && journaled.pieceName === step.pieceName && journaled.blockName === step.actionName) {
276
+ steps[step.key] = { output: capValue(await documents(journaled.output)) };
277
+ captions[`steps.${step.key}.output`] = runCaption;
278
+ return;
279
+ }
280
+ steps[step.key] = { output: await options.authoredOutput(stepBlock(step), step.config) };
281
+ captions[`steps.${step.key}.output`] = "declared type";
282
+ }));
283
+ if (Object.keys(steps).length > 0) value.steps = steps;
284
+ if (model.variables.length > 0) {
285
+ value.variables = Object.fromEntries(model.variables.map((variable) => [variable.key, variable.type === "SECRET" ? "secret" : variable.value ?? null]));
286
+ captions.variables = "workflow variables";
287
+ for (const variable of model.variables) if (variable.type) captions[`variables.${variable.key}`] = VARIABLE_TYPE_LABEL[variable.type].toLowerCase();
288
+ }
289
+ return {
290
+ value,
291
+ captions
292
+ };
293
+ }
294
+ const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
295
+ function childPath(parent, key, parentIsArray) {
296
+ if (parentIsArray) return `${parent}[${key}]`;
297
+ if (!parent) return key;
298
+ return IDENTIFIER.test(key) ? `${parent}.${key}` : `${parent}[${JSON.stringify(key)}]`;
299
+ }
300
+ //#endregion
301
+ //#region editors/workflow-editor/ui/canvas-menu.ts
302
+ function hasNextPort(model, id, portsOf) {
303
+ if (model.trigger?.id === id) return true;
304
+ const step = model.steps.find((entry) => entry.id === id);
305
+ return step ? portsOf(stepBlock(step))?.includes(NEXT_PORT) ?? false : false;
306
+ }
307
+ function contextMenuItems(target, model, portsOf) {
308
+ switch (target.kind) {
309
+ case "step": {
310
+ const skipped = model.steps.find((entry) => entry.id === target.id)?.skip === true;
311
+ return [
312
+ {
313
+ id: "open",
314
+ label: "Open settings"
315
+ },
316
+ {
317
+ id: "addBelow",
318
+ label: "Add step below",
319
+ disabled: !hasNextPort(model, target.id, portsOf)
320
+ },
321
+ {
322
+ id: "duplicate",
323
+ label: "Duplicate step"
324
+ },
325
+ {
326
+ id: "toggleSkip",
327
+ label: skipped ? "Stop skipping this step" : "Skip this step"
328
+ },
329
+ {
330
+ id: "removeStep",
331
+ label: "Remove step"
332
+ }
333
+ ];
334
+ }
335
+ case "trigger": return [
336
+ {
337
+ id: "open",
338
+ label: "Open settings"
339
+ },
340
+ {
341
+ id: "addBelow",
342
+ label: "Add step below",
343
+ disabled: !model.trigger
344
+ },
345
+ {
346
+ id: "changeTrigger",
347
+ label: "Change trigger"
348
+ },
349
+ {
350
+ id: "removeTrigger",
351
+ label: "Remove trigger"
352
+ }
353
+ ];
354
+ case "edge": return [{
355
+ id: "insertStep",
356
+ label: "Insert step here"
357
+ }, {
358
+ id: "removeEdge",
359
+ label: "Remove edge"
360
+ }];
361
+ case "pane": return [
362
+ {
363
+ id: "addStep",
364
+ label: "Add step here"
365
+ },
366
+ {
367
+ id: "selectAll",
368
+ label: "Select all steps",
369
+ disabled: model.steps.length === 0
370
+ },
371
+ {
372
+ id: "fitView",
373
+ label: "Fit view"
374
+ }
375
+ ];
376
+ }
377
+ }
378
+ const MENU_ITEM_HEIGHT = 28;
379
+ const VIEWPORT_MARGIN = 8;
380
+ function menuHeight(items) {
381
+ return items * MENU_ITEM_HEIGHT + 8;
382
+ }
383
+ function clampToViewport(at, extent, available) {
384
+ return Math.max(VIEWPORT_MARGIN, Math.min(at, available - extent - VIEWPORT_MARGIN));
385
+ }
386
+ function menuPosition(point, size, viewport) {
387
+ const place = (at, extent, available) => clampToViewport(at + extent > available - VIEWPORT_MARGIN ? at - extent : at, extent, available);
388
+ return {
389
+ x: place(point.x, size.width, viewport.width),
390
+ y: place(point.y, size.height, viewport.height)
391
+ };
392
+ }
393
+ const ANCHOR_GAP = 8;
394
+ function anchorLeftPosition(anchor, size, viewport) {
395
+ const left = anchor.left - ANCHOR_GAP - size.width;
396
+ return {
397
+ x: clampToViewport(left >= VIEWPORT_MARGIN ? left : anchor.right + ANCHOR_GAP, size.width, viewport.width),
398
+ y: clampToViewport(anchor.top, size.height, viewport.height)
399
+ };
400
+ }
401
+ //#endregion
402
+ //#region editors/workflow-editor/ui/expression-tokens.ts
403
+ const EMBEDDED_EXPRESSION = /(?<!\\)\{\{\s*([^{}]+?)\s*\}\}/g;
404
+ function splitExpressionTokens(value) {
405
+ const tokens = [];
406
+ let last = 0;
407
+ for (const match of value.matchAll(EMBEDDED_EXPRESSION)) {
408
+ const index = match.index;
409
+ if (index > last) tokens.push({
410
+ kind: "text",
411
+ text: value.slice(last, index)
412
+ });
413
+ tokens.push({
414
+ kind: "expression",
415
+ text: match[0],
416
+ expression: match[1]
417
+ });
418
+ last = index + match[0].length;
419
+ }
420
+ if (last < value.length) tokens.push({
421
+ kind: "text",
422
+ text: value.slice(last)
423
+ });
424
+ return tokens;
425
+ }
426
+ function hasExpressions(value) {
427
+ return typeof value === "string" && new RegExp(EMBEDDED_EXPRESSION).test(value);
428
+ }
429
+ function describeExpression(expression) {
430
+ const terms = expression.split("||");
431
+ const path = terms[0].trim();
432
+ const hasFallback = terms.length > 1;
433
+ const segments = path.split(".");
434
+ switch (segments[0]) {
435
+ case "steps": return {
436
+ root: "steps",
437
+ stepKey: segments[1] ?? "",
438
+ rest: segments.slice(2).join("."),
439
+ hasFallback
440
+ };
441
+ case "trigger": return {
442
+ root: "trigger",
443
+ rest: segments.slice(1).join("."),
444
+ hasFallback
445
+ };
446
+ case "variables": return {
447
+ root: "variables",
448
+ rest: segments.slice(1).join("."),
449
+ hasFallback
450
+ };
451
+ default: return {
452
+ root: "other",
453
+ rest: path,
454
+ hasFallback
455
+ };
456
+ }
457
+ }
458
+ //#endregion
459
+ //#region editors/workflow-editor/ui/ExpressionPicker.tsx
460
+ const ScopeSourceContext = createContext(void 0);
461
+ const ExpressionScopeSourceProvider = ScopeSourceContext.Provider;
462
+ function useScopeSource() {
463
+ return useContext(ScopeSourceContext);
464
+ }
465
+ const TargetContext = createContext(null);
466
+ function ExpressionTargetProvider(props) {
467
+ const [target, setTarget] = useState(null);
468
+ const value = useMemo(() => ({
469
+ target,
470
+ setTarget,
471
+ stepBlocks: props.stepBlocks,
472
+ triggerBlock: props.triggerBlock
473
+ }), [
474
+ target,
475
+ props.stepBlocks,
476
+ props.triggerBlock
477
+ ]);
478
+ return /* @__PURE__ */ jsx(TargetContext.Provider, {
479
+ value,
480
+ children: props.children
481
+ });
482
+ }
483
+ function useExpressionTarget() {
484
+ return useContext(TargetContext);
485
+ }
486
+ function fieldAnchor(element) {
487
+ const rect = (element?.closest("label,div") ?? element)?.getBoundingClientRect();
488
+ if (!rect) return {
489
+ left: window.innerWidth,
490
+ right: window.innerWidth,
491
+ top: 0
492
+ };
493
+ return {
494
+ left: rect.left,
495
+ right: rect.right,
496
+ top: rect.top
497
+ };
498
+ }
499
+ function useExpressionField(options) {
500
+ const id = useId();
501
+ const context = useExpressionTarget();
502
+ const insertRef = useRef(options.insert);
503
+ useEffect(() => {
504
+ insertRef.current = options.insert;
505
+ });
506
+ const { stepId, label } = options;
507
+ return {
508
+ active: context?.target?.id === id,
509
+ focus: (event) => {
510
+ context?.setTarget({
511
+ id,
512
+ stepId,
513
+ label,
514
+ anchor: fieldAnchor(event?.currentTarget),
515
+ insert: (expression) => insertRef.current(expression)
516
+ });
517
+ }
518
+ };
519
+ }
520
+ function preview(value) {
521
+ if (value === null) return "null";
522
+ if (value === void 0) return "";
523
+ if (Array.isArray(value)) return `[${value.length}]`;
524
+ if (typeof value === "object") return "{…}";
525
+ const text = typeof value === "string" ? value : JSON.stringify(value) ?? "";
526
+ return text.length > 28 ? `${text.slice(0, 28)}…` : text;
527
+ }
528
+ function isExpandable(value) {
529
+ return value !== null && typeof value === "object" && Object.keys(value).length > 0;
530
+ }
531
+ function entriesOf(value) {
532
+ if (Array.isArray(value)) return value.map((item, i) => [String(i), item]);
533
+ if (value !== null && typeof value === "object") return Object.entries(value);
534
+ return [];
535
+ }
536
+ function Caption(props) {
537
+ if (!props.text) return null;
538
+ return /* @__PURE__ */ jsx("span", {
539
+ className: "ml-auto shrink-0 pl-2 text-[10px] italic text-muted-foreground/80",
540
+ children: props.text
541
+ });
542
+ }
543
+ function ValueNode(props) {
544
+ const context = useExpressionTarget();
545
+ const [open, setOpen] = useState(props.depth < 2);
546
+ const expandable = isExpandable(props.value);
547
+ const stepKey = /^steps\.([^.]+)$/.exec(props.path)?.[1];
548
+ const nodeBlock = stepKey ? context?.stepBlocks[stepKey] : props.path === "trigger" ? context?.triggerBlock : void 0;
549
+ return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs("div", {
550
+ className: "flex items-center gap-1 rounded px-1 py-0.5 hover:bg-muted/50",
551
+ style: { paddingLeft: props.depth * 14 + 4 },
552
+ children: [
553
+ expandable ? /* @__PURE__ */ jsx("button", {
554
+ type: "button",
555
+ className: "w-3 shrink-0 text-[10px] text-muted-foreground/80",
556
+ onClick: () => setOpen((value) => !value),
557
+ children: open ? "▾" : "▸"
558
+ }) : /* @__PURE__ */ jsx("span", { className: "w-3 shrink-0" }),
559
+ /* @__PURE__ */ jsxs("button", {
560
+ type: "button",
561
+ className: "flex min-w-0 flex-1 items-baseline gap-2 text-left",
562
+ title: `{{${props.path}}}`,
563
+ onClick: () => props.onPick(props.path),
564
+ children: [nodeBlock ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(BlockLogo, {
565
+ block: nodeBlock,
566
+ size: 16
567
+ }), /* @__PURE__ */ jsx("span", {
568
+ className: "shrink-0 text-xs font-medium text-foreground",
569
+ children: blockMeta(nodeBlock).displayName
570
+ })] }) : /* @__PURE__ */ jsx("span", {
571
+ className: "shrink-0 font-mono text-xs text-foreground",
572
+ children: props.name
573
+ }), /* @__PURE__ */ jsx("span", {
574
+ className: "truncate text-[11px] text-muted-foreground/80",
575
+ children: preview(props.value)
576
+ })]
577
+ }),
578
+ /* @__PURE__ */ jsx(Caption, { text: props.captions[props.path] })
579
+ ]
580
+ }), expandable && open ? entriesOf(props.value).map(([key, child]) => /* @__PURE__ */ jsx(ValueNode, {
581
+ name: key,
582
+ path: childPath(props.path, key, Array.isArray(props.value)),
583
+ value: child,
584
+ depth: props.depth + 1,
585
+ captions: props.captions,
586
+ onPick: props.onPick
587
+ }, key)) : null] });
588
+ }
589
+ const SEARCH_DEPTH = 6;
590
+ const SEARCH_LIMIT = 200;
591
+ function flatten(value, path, depth, out) {
592
+ for (const [key, child] of entriesOf(value)) {
593
+ const nested = childPath(path, key, Array.isArray(value));
594
+ out.push({
595
+ path: nested,
596
+ value: child
597
+ });
598
+ if (depth < SEARCH_DEPTH && isExpandable(child)) flatten(child, nested, depth + 1, out);
599
+ }
600
+ }
601
+ function SearchResults(props) {
602
+ const matches = useMemo(() => {
603
+ const all = [];
604
+ flatten(props.scope.value, "", 0, all);
605
+ const lowered = props.query.toLowerCase();
606
+ return all.filter((entry) => entry.path.toLowerCase().includes(lowered)).slice(0, SEARCH_LIMIT);
607
+ }, [props.scope, props.query]);
608
+ if (matches.length === 0) return /* @__PURE__ */ jsx("div", {
609
+ className: "px-2 py-1 text-xs text-muted-foreground/80",
610
+ children: "No matches"
611
+ });
612
+ return /* @__PURE__ */ jsx(Fragment$1, { children: matches.map((entry) => /* @__PURE__ */ jsxs("button", {
613
+ type: "button",
614
+ className: "flex w-full items-baseline gap-2 rounded px-2 py-0.5 text-left hover:bg-muted/50",
615
+ title: `{{${entry.path}}}`,
616
+ onClick: () => props.onPick(entry.path),
617
+ children: [/* @__PURE__ */ jsx("span", {
618
+ className: "min-w-0 truncate font-mono text-[11px] text-foreground",
619
+ children: entry.path
620
+ }), /* @__PURE__ */ jsx("span", {
621
+ className: "truncate text-[10px] text-muted-foreground/80",
622
+ children: preview(entry.value)
623
+ })]
624
+ }, entry.path)) });
625
+ }
626
+ const POPUP_SIZE = {
627
+ width: 420,
628
+ height: 520
629
+ };
630
+ function ExpressionPickerPopup() {
631
+ const context = useExpressionTarget();
632
+ const target = context?.target ?? null;
633
+ const [query, setQuery] = useState("");
634
+ const [state, setState] = useState({ kind: "idle" });
635
+ const scopeSource = useScopeSource();
636
+ const containerRef = useRef(null);
637
+ const stepId = target?.stepId;
638
+ const hasTarget = target !== null;
639
+ useEffect(() => {
640
+ if (!hasTarget || !scopeSource) return;
641
+ let alive = true;
642
+ setState((current) => current.kind === "ready" && current.stepId === stepId ? current : { kind: "loading" });
643
+ scopeSource.load({ stepId }).then((scope) => {
644
+ if (alive) setState({
645
+ kind: "ready",
646
+ scope,
647
+ stepId
648
+ });
649
+ }, (error) => {
650
+ if (alive) setState({
651
+ kind: "error",
652
+ message: error instanceof Error ? error.message : String(error)
653
+ });
654
+ });
655
+ return () => {
656
+ alive = false;
657
+ };
658
+ }, [
659
+ hasTarget,
660
+ stepId,
661
+ scopeSource
662
+ ]);
663
+ const targetId = target?.id;
664
+ useEffect(() => setQuery(""), [targetId]);
665
+ const close = context?.setTarget;
666
+ useEffect(() => {
667
+ if (!hasTarget || !close) return;
668
+ const dismiss = () => close(null);
669
+ const outside = (event) => !containerRef.current?.contains(event.target);
670
+ const onMouseDown = (event) => {
671
+ if (outside(event)) dismiss();
672
+ };
673
+ const onKeyDown = (event) => {
674
+ if (event.key === "Escape") dismiss();
675
+ };
676
+ const onScroll = (event) => {
677
+ if (outside(event)) dismiss();
678
+ };
679
+ window.addEventListener("mousedown", onMouseDown);
680
+ window.addEventListener("keydown", onKeyDown);
681
+ window.addEventListener("scroll", onScroll, true);
682
+ return () => {
683
+ window.removeEventListener("mousedown", onMouseDown);
684
+ window.removeEventListener("keydown", onKeyDown);
685
+ window.removeEventListener("scroll", onScroll, true);
686
+ };
687
+ }, [hasTarget, close]);
688
+ if (!context || !scopeSource || !target) return null;
689
+ const pick = (path) => {
690
+ target.insert(`{{${path}}}`);
691
+ context.setTarget(null);
692
+ };
693
+ const scope = state.kind === "ready" && state.stepId === stepId ? state.scope : EMPTY_SCOPE;
694
+ const empty = entriesOf(scope.value).length === 0;
695
+ const position = anchorLeftPosition(target.anchor, POPUP_SIZE, {
696
+ width: window.innerWidth,
697
+ height: window.innerHeight
698
+ });
699
+ return createPortal(/* @__PURE__ */ jsxs("div", {
700
+ ref: containerRef,
701
+ className: "workflow-expression-popup fixed flex flex-col rounded-md border border-solid border-foreground/10 bg-card shadow-lg",
702
+ onMouseDown: (event) => {
703
+ if (!(event.target instanceof HTMLInputElement)) event.preventDefault();
704
+ },
705
+ style: {
706
+ left: position.x,
707
+ top: position.y,
708
+ width: POPUP_SIZE.width,
709
+ maxHeight: POPUP_SIZE.height
710
+ },
711
+ children: [
712
+ /* @__PURE__ */ jsxs("div", {
713
+ className: "flex items-center gap-2 px-3 py-1.5",
714
+ children: [
715
+ /* @__PURE__ */ jsx("span", {
716
+ className: "font-mono text-[11px] text-muted-foreground",
717
+ children: "{}"
718
+ }),
719
+ /* @__PURE__ */ jsxs("span", {
720
+ className: "min-w-0 truncate text-xs text-muted-foreground",
721
+ children: [
722
+ "Insert into",
723
+ " ",
724
+ /* @__PURE__ */ jsx("span", {
725
+ className: "font-semibold text-foreground",
726
+ children: target.label
727
+ })
728
+ ]
729
+ }),
730
+ /* @__PURE__ */ jsx("button", {
731
+ type: "button",
732
+ className: "ml-auto text-[11px] text-muted-foreground/80 hover:text-muted-foreground",
733
+ title: "Close",
734
+ onClick: () => context.setTarget(null),
735
+ children: "✕"
736
+ })
737
+ ]
738
+ }),
739
+ /* @__PURE__ */ jsx("div", {
740
+ className: "px-3 pb-1.5",
741
+ children: /* @__PURE__ */ jsx("input", {
742
+ className: "w-full rounded border border-foreground/10 px-2 py-1.5 text-sm",
743
+ placeholder: "Search paths…",
744
+ value: query,
745
+ onChange: (event) => setQuery(event.target.value)
746
+ })
747
+ }),
748
+ /* @__PURE__ */ jsx("div", {
749
+ className: "min-h-0 flex-1 overflow-y-auto px-1 pb-1",
750
+ children: state.kind === "error" ? /* @__PURE__ */ jsx("div", {
751
+ className: "px-2 py-1 text-xs text-wf-fail",
752
+ children: state.message
753
+ }) : state.kind === "loading" ? /* @__PURE__ */ jsx("div", {
754
+ className: "px-2 py-1 text-xs text-muted-foreground/80",
755
+ children: "Loading…"
756
+ }) : empty ? /* @__PURE__ */ jsx("div", {
757
+ className: "px-2 py-1 text-xs text-muted-foreground/80",
758
+ children: "No values available for this field yet."
759
+ }) : query.trim() ? /* @__PURE__ */ jsx(SearchResults, {
760
+ scope,
761
+ query: query.trim(),
762
+ onPick: pick
763
+ }) : entriesOf(scope.value).map(([key, value]) => /* @__PURE__ */ jsx(ValueNode, {
764
+ name: key,
765
+ path: key,
766
+ value,
767
+ depth: 0,
768
+ captions: scope.captions,
769
+ onPick: pick
770
+ }, key))
771
+ })
772
+ ]
773
+ }), document.body);
774
+ }
775
+ function ExpressionPickerButton(props) {
776
+ if (!useScopeSource()) return null;
777
+ return /* @__PURE__ */ jsxs("button", {
778
+ type: "button",
779
+ title: "Insert data from the trigger or an earlier step",
780
+ className: `inline-flex h-6 shrink-0 items-center gap-1 rounded-md px-1.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40 ${props.active ? "bg-wf-run/10 text-wf-run" : "text-muted-foreground opacity-0 hover:bg-accent hover:text-foreground focus-visible:opacity-100 group-focus-within/field:opacity-100 group-hover/field:opacity-100 [@media(hover:none)]:opacity-100"}`,
781
+ onClick: props.onFocusField,
782
+ children: [/* @__PURE__ */ jsx(Icon, {
783
+ name: "braces",
784
+ className: "h-3.5 w-3.5"
785
+ }), "Insert data"]
786
+ });
787
+ }
788
+ function Chip(props) {
789
+ const ref = describeExpression(props.expression);
790
+ const block = ref.stepKey ? props.stepBlocks[ref.stepKey] : void 0;
791
+ const head = ref.root === "steps" ? ref.stepKey : ref.root === "trigger" ? "trigger" : ref.root === "variables" ? "var" : "";
792
+ return /* @__PURE__ */ jsxs("span", {
793
+ className: "inline-flex max-w-full items-center gap-1 rounded border border-solid border-wf-run/20 bg-wf-run/10 px-1 py-px font-mono text-[11px] text-wf-run",
794
+ title: `{{${props.expression}}}`,
795
+ children: [
796
+ block ? /* @__PURE__ */ jsx(BlockLogo, {
797
+ block,
798
+ size: 12
799
+ }) : null,
800
+ head ? /* @__PURE__ */ jsx("span", {
801
+ className: "font-semibold",
802
+ children: head
803
+ }) : null,
804
+ /* @__PURE__ */ jsx("span", {
805
+ className: "truncate",
806
+ children: ref.root === "other" ? ref.rest : ref.rest || "*"
807
+ }),
808
+ ref.hasFallback ? /* @__PURE__ */ jsx("span", {
809
+ className: "text-wf-run",
810
+ children: "||…"
811
+ }) : null
812
+ ]
813
+ });
814
+ }
815
+ function ExpressionTokenLine(props) {
816
+ const context = useExpressionTarget();
817
+ const tokens = splitExpressionTokens(props.value);
818
+ if (!tokens.some((token) => token.kind === "expression")) return null;
819
+ return /* @__PURE__ */ jsx("div", {
820
+ className: "mt-1.5 flex flex-wrap items-center gap-1 text-xs text-muted-foreground",
821
+ children: tokens.map((token, index) => token.kind === "text" ? /* @__PURE__ */ jsx("span", {
822
+ className: "max-w-40 truncate whitespace-pre",
823
+ children: token.text
824
+ }, index) : /* @__PURE__ */ jsx(Chip, {
825
+ expression: token.expression,
826
+ stepBlocks: context?.stepBlocks ?? {}
827
+ }, index))
828
+ });
829
+ }
830
+ //#endregion
831
+ //#region editors/workflow-editor/ui/PublishControls.tsx
832
+ function blockedReason(readiness) {
833
+ if (!readiness.hasTrigger) return "Add a trigger first";
834
+ if (readiness.firstIncomplete) return "You have incomplete steps";
835
+ return "Checking the steps…";
836
+ }
837
+ function usePublish(callbacks) {
838
+ const [publishing, setPublishing] = useState(false);
839
+ const [error, setError] = useState(null);
840
+ const publish = () => {
841
+ if (publishing) return;
842
+ setPublishing(true);
843
+ setError(null);
844
+ callbacks.publish().catch((cause) => setError(cause instanceof Error ? cause.message : String(cause))).finally(() => setPublishing(false));
845
+ };
846
+ return {
847
+ publishing,
848
+ error,
849
+ publish
850
+ };
851
+ }
852
+ function PublishButton(props) {
853
+ const { model, readiness } = props;
854
+ if (props.signIn?.required) return /* @__PURE__ */ jsx(Tooltip, {
855
+ content: "This Switchboard enforces document permissions, so a publish must be signed",
856
+ children: /* @__PURE__ */ jsx(Button, {
857
+ size: props.size ?? "sm",
858
+ variant: "primary",
859
+ disabled: props.signIn.pending,
860
+ onClick: props.signIn.login,
861
+ children: "Sign in to publish"
862
+ })
863
+ });
864
+ const incomplete = !readiness.ready;
865
+ const changes = hasDraftChanges(model);
866
+ const target = readiness.firstIncomplete;
867
+ const select = () => {
868
+ if (target) props.onSelect(target);
869
+ };
870
+ return /* @__PURE__ */ jsx(Tooltip, {
871
+ enabled: incomplete,
872
+ content: /* @__PURE__ */ jsx("button", {
873
+ type: "button",
874
+ className: "font-medium text-wf-warn hover:underline",
875
+ onClick: select,
876
+ children: blockedReason(readiness)
877
+ }),
878
+ children: /* @__PURE__ */ jsx("span", {
879
+ className: "inline-flex",
880
+ onClick: incomplete ? select : void 0,
881
+ children: /* @__PURE__ */ jsx(Button, {
882
+ size: props.size ?? "sm",
883
+ variant: "primary",
884
+ disabled: incomplete || !changes || props.publishing,
885
+ title: !changes && !incomplete ? "No unpublished changes" : void 0,
886
+ onClick: props.onPublish,
887
+ children: props.publishing ? "Publishing…" : "Publish"
888
+ })
889
+ })
890
+ });
891
+ }
892
+ function PublishState(props) {
893
+ const draft = hasDraftChanges(props.model);
894
+ return /* @__PURE__ */ jsxs("span", {
895
+ className: "flex shrink-0 items-center gap-1.5 whitespace-nowrap text-xs text-muted-foreground",
896
+ title: props.model.published ? `Published ${new Date(props.model.published.publishedAt).toLocaleString()}` : "Never published",
897
+ children: [
898
+ /* @__PURE__ */ jsx("span", {
899
+ "aria-hidden": true,
900
+ className: `h-2 w-2 rounded-full ${draft ? "bg-wf-warn" : "bg-wf-ok"}`
901
+ }),
902
+ /* @__PURE__ */ jsx("span", { children: !props.model.published ? "Draft" : draft ? "Unpublished changes" : "Published" }),
903
+ props.model.published && draft ? /* @__PURE__ */ jsxs("span", {
904
+ className: "text-muted-foreground/80",
905
+ children: [
906
+ "· v",
907
+ props.model.published.version,
908
+ " live"
909
+ ]
910
+ }) : null
911
+ ]
912
+ });
913
+ }
914
+ function StatusToggle(props) {
915
+ const allowed = props.published;
916
+ const on = props.status === "ENABLED";
917
+ return /* @__PURE__ */ jsx(Tooltip, {
918
+ enabled: !allowed,
919
+ content: "Publish the workflow first",
920
+ align: "end",
921
+ side: props.tooltipSide,
922
+ children: /* @__PURE__ */ jsxs("span", {
923
+ className: "flex items-center gap-2 text-xs text-muted-foreground",
924
+ children: [/* @__PURE__ */ jsx(Toggle, {
925
+ checked: on,
926
+ disabled: !allowed,
927
+ label: on ? "Turn the workflow off" : "Turn the workflow on",
928
+ onChange: (checked) => props.onChange(checked ? "ENABLED" : "DISABLED")
929
+ }), /* @__PURE__ */ jsx("span", {
930
+ className: "w-6",
931
+ children: on ? "On" : "Off"
932
+ })]
933
+ })
934
+ });
935
+ }
936
+ function PublishedMissingNote(props) {
937
+ if (props.missing.length === 0) return null;
938
+ return /* @__PURE__ */ jsx("span", {
939
+ role: "alert",
940
+ "aria-label": "Published version incomplete",
941
+ className: "shrink-0 whitespace-nowrap rounded-full bg-wf-warn/12 px-2 py-0.5 text-xs text-wf-warn",
942
+ title: `The published version is missing a reactor connection on: ${props.missing.join(", ")}`,
943
+ children: "Live version incomplete"
944
+ });
945
+ }
946
+ function ReactorDenialNote(props) {
947
+ if (!props.denial) return null;
948
+ return /* @__PURE__ */ jsxs("span", {
949
+ role: "alert",
950
+ "aria-label": "Reactor access denied",
951
+ className: "max-w-80 truncate rounded-full bg-wf-warn/12 px-2 py-0.5 text-xs text-wf-warn",
952
+ title: props.denial,
953
+ children: ["No reactor access: ", props.denial]
954
+ });
955
+ }
956
+ /** Instead of the draft banner on a managed workflow: who keeps it, and that edits here are not saved. */
957
+ function ManagedBanner(props) {
958
+ const manager = props.model.managedBy;
959
+ if (!manager) return null;
960
+ return /* @__PURE__ */ jsxs("div", {
961
+ role: "status",
962
+ className: "pointer-events-auto flex max-w-xl items-center gap-3 rounded-lg border border-solid border-foreground/10 bg-card px-3 py-1.5 text-[13px] shadow-sm",
963
+ children: [/* @__PURE__ */ jsx("span", {
964
+ className: "h-2 w-2 shrink-0 rounded-full bg-muted-foreground",
965
+ "aria-hidden": true
966
+ }), /* @__PURE__ */ jsxs("span", {
967
+ className: "text-foreground",
968
+ children: [
969
+ "Managed by ",
970
+ /* @__PURE__ */ jsx("strong", { children: manager.label || manager.documentType }),
971
+ ". Change it there: edits here are not saved."
972
+ ]
973
+ })]
974
+ });
975
+ }
976
+ function DraftBanner(props) {
977
+ if (!hasDraftChanges(props.model)) return null;
978
+ const { readiness } = props;
979
+ const target = readiness.firstIncomplete;
980
+ return /* @__PURE__ */ jsxs("div", {
981
+ role: "status",
982
+ className: "pointer-events-auto flex items-center gap-3 rounded-lg border border-solid border-foreground/10 bg-card py-1.5 pl-3 pr-1.5 text-[13px] shadow-sm",
983
+ children: [
984
+ /* @__PURE__ */ jsx("span", {
985
+ className: "h-2 w-2 shrink-0 rounded-full bg-wf-warn",
986
+ "aria-hidden": true
987
+ }),
988
+ /* @__PURE__ */ jsx("span", {
989
+ className: "text-foreground",
990
+ children: "You have unpublished changes"
991
+ }),
992
+ props.error ? /* @__PURE__ */ jsx("span", {
993
+ className: "text-xs text-wf-fail",
994
+ children: props.error
995
+ }) : null,
996
+ !readiness.hasTrigger || target ? /* @__PURE__ */ jsxs("span", {
997
+ className: "flex items-center gap-1.5 text-xs text-wf-warn",
998
+ children: [/* @__PURE__ */ jsx("span", { children: target ? "Incomplete steps" : "No trigger yet" }), target ? /* @__PURE__ */ jsx("button", {
999
+ type: "button",
1000
+ className: "font-medium underline underline-offset-2 hover:no-underline",
1001
+ onClick: () => props.onSelect(target),
1002
+ children: "Show"
1003
+ }) : null]
1004
+ }) : null,
1005
+ /* @__PURE__ */ jsxs("span", {
1006
+ className: "flex items-center gap-1",
1007
+ children: [props.model.published ? /* @__PURE__ */ jsx(Button, {
1008
+ size: "sm",
1009
+ variant: "ghost",
1010
+ onClick: props.onDiscard,
1011
+ children: "Discard changes"
1012
+ }) : null, /* @__PURE__ */ jsx(PublishButton, {
1013
+ model: props.model,
1014
+ readiness,
1015
+ publishing: props.publishing,
1016
+ onPublish: props.onPublish,
1017
+ onSelect: props.onSelect,
1018
+ signIn: props.signIn
1019
+ })]
1020
+ })
1021
+ ]
1022
+ });
1023
+ }
1024
+ //#endregion
1025
+ //#region editors/workflow-editor/ui/StepError.tsx
1026
+ function StepError(props) {
1027
+ return /* @__PURE__ */ jsx("pre", {
1028
+ className: "overflow-auto whitespace-pre-wrap rounded-md bg-wf-fail/10 p-2.5 text-xs text-wf-fail",
1029
+ children: props.error
1030
+ });
1031
+ }
1032
+ //#endregion
1033
+ //#region editors/shared/pending-echo.ts
1034
+ function keyOf(value) {
1035
+ return JSON.stringify(value, (_, entry) => entry && typeof entry === "object" && !Array.isArray(entry) ? Object.fromEntries(Object.entries(entry).sort(([a], [b]) => a.localeCompare(b))) : entry);
1036
+ }
1037
+ function usePendingEcho(saved, onChange) {
1038
+ const savedKey = keyOf(saved);
1039
+ const [sent, setSent] = useState([]);
1040
+ const [seen, setSeen] = useState(savedKey);
1041
+ let pending = sent;
1042
+ if (seen !== savedKey) {
1043
+ const echo = sent.findIndex((value) => keyOf(value) === savedKey);
1044
+ pending = echo === -1 ? [] : sent.slice(echo + 1);
1045
+ setSeen(savedKey);
1046
+ setSent(pending);
1047
+ }
1048
+ const value = pending.length > 0 ? pending[pending.length - 1] : saved;
1049
+ return {
1050
+ value,
1051
+ commit: (next) => {
1052
+ if (keyOf(next) === keyOf(value)) return;
1053
+ setSent([...pending, next]);
1054
+ onChange(next, value);
1055
+ },
1056
+ onBlur: (event) => {
1057
+ const inside = event.currentTarget.contains(event.relatedTarget);
1058
+ if (pending.length > 0 && !inside && keyOf(value) === savedKey) setSent([]);
1059
+ }
1060
+ };
1061
+ }
1062
+ //#endregion
1063
+ //#region editors/workflow-editor/ui/secret-ref.ts
1064
+ const SECRET_REF_PREFIX = "secret://v1:";
1065
+ function useSecretRef(options) {
1066
+ const { secrets } = options;
1067
+ const ref = typeof options.value === "string" ? options.value : "";
1068
+ const managed = ref.startsWith(SECRET_REF_PREFIX);
1069
+ const [draft, setDraft] = useState("");
1070
+ const [busy, setBusy] = useState(false);
1071
+ const [error, setError] = useState(null);
1072
+ const [stat, setStat] = useState(null);
1073
+ useEffect(() => {
1074
+ setStat(null);
1075
+ if (!managed || !secrets) return;
1076
+ let cancelled = false;
1077
+ secrets.stat(ref).then((result) => {
1078
+ if (!cancelled) setStat(result);
1079
+ }, () => void 0);
1080
+ return () => {
1081
+ cancelled = true;
1082
+ };
1083
+ }, [
1084
+ ref,
1085
+ managed,
1086
+ secrets
1087
+ ]);
1088
+ const commit = () => {
1089
+ if (draft === "" || busy || !secrets) return;
1090
+ setBusy(true);
1091
+ setError(null);
1092
+ secrets.save({
1093
+ ref: managed ? ref : void 0,
1094
+ value: draft,
1095
+ label: options.label
1096
+ }).then((result) => {
1097
+ setDraft("");
1098
+ if (result.ref !== ref) options.onCommit(result.ref);
1099
+ else setStat(result);
1100
+ }).catch((requestError) => {
1101
+ setError(requestError instanceof Error ? requestError.message : String(requestError));
1102
+ }).finally(() => setBusy(false));
1103
+ };
1104
+ return {
1105
+ ref,
1106
+ managed,
1107
+ draft,
1108
+ setDraft,
1109
+ busy,
1110
+ error,
1111
+ stat,
1112
+ commit
1113
+ };
1114
+ }
1115
+ //#endregion
1116
+ //#region editors/workflow-editor/ui/prop-controls.tsx
1117
+ const CALLOUT = {
1118
+ INFO: { box: "rounded bg-muted px-2 py-1.5" },
1119
+ WARNING: {
1120
+ box: "rounded border border-solid border-wf-warn/40 bg-wf-warn/10 px-2 py-1.5",
1121
+ icon: "alert"
1122
+ },
1123
+ TIP: {
1124
+ box: "rounded border border-solid border-wf-ok/30 bg-wf-ok/10 px-2 py-1.5",
1125
+ icon: "bolt"
1126
+ },
1127
+ BORDERLESS: { box: "" }
1128
+ };
1129
+ /** A MARKDOWN prop's text, styled by the piece's `variant` (INFO default). */
1130
+ function MarkdownCallout(props) {
1131
+ const callout = CALLOUT[props.variant ?? "INFO"] ?? CALLOUT.INFO;
1132
+ return /* @__PURE__ */ jsxs("div", {
1133
+ className: `flex gap-2 ${callout.box}`,
1134
+ "data-variant": props.variant ?? "INFO",
1135
+ children: [callout.icon ? /* @__PURE__ */ jsx(Icon, {
1136
+ name: callout.icon,
1137
+ className: `mt-0.5 h-3.5 w-3.5 shrink-0 ${callout.icon === "alert" ? "text-wf-warn" : "text-wf-ok"}`
1138
+ }) : null, /* @__PURE__ */ jsx("div", {
1139
+ className: "min-w-0 flex-1",
1140
+ children: props.children
1141
+ })]
1142
+ });
1143
+ }
1144
+ /** An option's icon, when the piece names one this editor draws. */
1145
+ function optionIcon(name) {
1146
+ return isIconName(name) ? /* @__PURE__ */ jsx(Icon, {
1147
+ name,
1148
+ className: "h-3.5 w-3.5 shrink-0 text-muted-foreground"
1149
+ }) : void 0;
1150
+ }
1151
+ /** STATIC_DROPDOWN with `display: 'cards'`: one selectable card per option. */
1152
+ function OptionCards(props) {
1153
+ const current = props.keyOf(props.value);
1154
+ return /* @__PURE__ */ jsx("div", {
1155
+ id: props.id,
1156
+ role: "radiogroup",
1157
+ className: `grid grid-cols-2 gap-2 ${props.invalid ? "rounded-md ring-1 ring-wf-warn/60" : ""}`,
1158
+ children: props.options.map((option) => {
1159
+ const key = props.keyOf(option.value);
1160
+ const selected = key === current;
1161
+ return /* @__PURE__ */ jsxs("button", {
1162
+ type: "button",
1163
+ role: "radio",
1164
+ "aria-checked": selected,
1165
+ className: `flex min-w-0 flex-col items-start gap-1 rounded-lg border border-solid p-3 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40 ${selected ? "border-foreground/40 bg-accent" : "border-foreground/10 hover:border-foreground/25"}`,
1166
+ onClick: () => props.onChange(selected && props.clearable ? void 0 : option.value),
1167
+ children: [/* @__PURE__ */ jsxs("span", {
1168
+ className: "flex items-center gap-1.5 text-[13px] font-medium text-foreground",
1169
+ children: [optionIcon(option.icon), option.label]
1170
+ }), option.description ? /* @__PURE__ */ jsx("span", {
1171
+ className: "text-xs leading-snug text-muted-foreground",
1172
+ children: option.description
1173
+ }) : null]
1174
+ }, key);
1175
+ })
1176
+ });
1177
+ }
1178
+ /** The declared bounds, for the hint and the check: "Between 0 and 5". */
1179
+ function numberRangeText(min, max) {
1180
+ if (min !== void 0 && max !== void 0) return `Between ${min} and ${max}`;
1181
+ if (min !== void 0) return `At least ${min}`;
1182
+ if (max !== void 0) return `At most ${max}`;
1183
+ return null;
1184
+ }
1185
+ function numberRangeError(value, min, max) {
1186
+ if (typeof value !== "number") return null;
1187
+ if (min !== void 0 && value < min || max !== void 0 && value > max) return `${numberRangeText(min, max)}.`;
1188
+ return null;
1189
+ }
1190
+ /** NUMBER with `display: 'stepper'`: − value +, still accepting expressions. */
1191
+ function NumberStepper(props) {
1192
+ const step = props.step ?? 1;
1193
+ const numeric = typeof props.value === "number" ? props.value : void 0;
1194
+ const clamp = (next) => Math.min(props.max ?? Infinity, Math.max(props.min ?? -Infinity, next));
1195
+ const bump = (direction) => props.onCommit(clamp((numeric ?? props.min ?? 0) + direction * step));
1196
+ const text = props.value === void 0 || props.value === null ? "" : String(props.value);
1197
+ return /* @__PURE__ */ jsxs("div", {
1198
+ className: "flex items-center gap-1",
1199
+ children: [
1200
+ /* @__PURE__ */ jsx(IconButton, {
1201
+ icon: "minus",
1202
+ label: "Decrease",
1203
+ disabled: numeric !== void 0 && props.min !== void 0 && numeric <= props.min,
1204
+ onClick: () => bump(-1)
1205
+ }),
1206
+ /* @__PURE__ */ jsx("input", {
1207
+ id: props.id,
1208
+ className: `${textInputClass} w-24 text-center tabular-nums ${props.invalid ? invalidClass : ""}`,
1209
+ defaultValue: text,
1210
+ inputMode: "decimal",
1211
+ spellCheck: false,
1212
+ onFocus: props.onFocus,
1213
+ onBlur: (event) => props.onCommitText(event.target.value)
1214
+ }, text),
1215
+ /* @__PURE__ */ jsx(IconButton, {
1216
+ icon: "plus",
1217
+ label: "Increase",
1218
+ disabled: numeric !== void 0 && props.max !== void 0 && numeric >= props.max,
1219
+ onClick: () => bump(1)
1220
+ })
1221
+ ]
1222
+ });
1223
+ }
1224
+ const DATE_PRESETS = Object.entries({
1225
+ any_time: "Any time",
1226
+ last_24_hours: "Last 24 hours",
1227
+ last_7_days: "Last 7 days",
1228
+ last_30_days: "Last 30 days",
1229
+ last_90_days: "Last 90 days",
1230
+ this_month: "This month",
1231
+ custom: "Custom"
1232
+ }).map(([value, label]) => ({
1233
+ value,
1234
+ label
1235
+ }));
1236
+ function toLocalInput(iso) {
1237
+ if (!iso) return "";
1238
+ const date = new Date(iso);
1239
+ if (Number.isNaN(date.getTime())) return "";
1240
+ const pad = (n) => String(n).padStart(2, "0");
1241
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
1242
+ }
1243
+ function fromLocalInput(local) {
1244
+ if (!local) return void 0;
1245
+ const date = new Date(local);
1246
+ return Number.isNaN(date.getTime()) ? void 0 : date.toISOString();
1247
+ }
1248
+ function asDateRange(value) {
1249
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
1250
+ }
1251
+ function DateRangeField(props) {
1252
+ const range = asDateRange(props.value);
1253
+ const setPreset = (preset) => props.onCommit(preset === "" ? void 0 : preset === "custom" ? {
1254
+ preset,
1255
+ after: range.after,
1256
+ before: range.before
1257
+ } : { preset });
1258
+ return /* @__PURE__ */ jsxs("div", {
1259
+ className: "flex flex-col gap-2",
1260
+ children: [props.dropdown ? /* @__PURE__ */ jsx(Select, {
1261
+ id: props.id,
1262
+ options: DATE_PRESETS,
1263
+ value: range.preset ?? "",
1264
+ onChange: setPreset,
1265
+ invalid: props.invalid,
1266
+ clearable: props.clearable,
1267
+ placeholder: "Choose a range"
1268
+ }) : /* @__PURE__ */ jsx("div", {
1269
+ id: props.id,
1270
+ role: "radiogroup",
1271
+ className: "flex flex-wrap gap-1.5",
1272
+ children: DATE_PRESETS.map((preset) => {
1273
+ const selected = range.preset === preset.value;
1274
+ return /* @__PURE__ */ jsx("button", {
1275
+ type: "button",
1276
+ role: "radio",
1277
+ "aria-checked": selected,
1278
+ className: `h-7 rounded-full border border-solid px-2.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40 ${selected ? "border-foreground bg-foreground text-background" : "border-foreground/15 text-muted-foreground hover:text-foreground"}`,
1279
+ onClick: () => setPreset(selected && props.clearable ? "" : preset.value),
1280
+ children: preset.label
1281
+ }, preset.value);
1282
+ })
1283
+ }), range.preset === "custom" ? /* @__PURE__ */ jsx("div", {
1284
+ className: "grid grid-cols-2 gap-2",
1285
+ children: ["after", "before"].map((edge) => /* @__PURE__ */ jsxs("label", {
1286
+ className: "flex flex-col gap-1 text-xs text-muted-foreground",
1287
+ children: [edge === "after" ? "From" : "To", /* @__PURE__ */ jsx("input", {
1288
+ type: "datetime-local",
1289
+ className: textInputClass,
1290
+ defaultValue: toLocalInput(range[edge]),
1291
+ onBlur: (event) => props.onCommit({
1292
+ ...range,
1293
+ [edge]: fromLocalInput(event.target.value)
1294
+ })
1295
+ })]
1296
+ }, edge))
1297
+ }) : null]
1298
+ });
1299
+ }
1300
+ const HEX = /^#[0-9a-f]{6}$/i;
1301
+ /** COLOR: a swatch picker beside a text field that also takes expressions. */
1302
+ function ColorField(props) {
1303
+ const text = typeof props.value === "string" ? props.value : "";
1304
+ const [draft, setDraft] = useState(null);
1305
+ const swatchRef = useRef(null);
1306
+ const onCommit = props.onCommit;
1307
+ useEffect(() => {
1308
+ const swatch = swatchRef.current;
1309
+ if (!swatch) return;
1310
+ const commit = () => {
1311
+ setDraft(null);
1312
+ onCommit(swatch.value);
1313
+ };
1314
+ swatch.addEventListener("change", commit);
1315
+ return () => swatch.removeEventListener("change", commit);
1316
+ }, [onCommit]);
1317
+ return /* @__PURE__ */ jsxs("div", {
1318
+ className: "flex items-center gap-2",
1319
+ children: [/* @__PURE__ */ jsx("input", {
1320
+ ref: swatchRef,
1321
+ type: "color",
1322
+ "aria-label": "Pick a colour",
1323
+ className: "h-9 w-10 shrink-0 cursor-pointer rounded-md border border-solid border-foreground/15 bg-card p-1",
1324
+ value: draft ?? (HEX.test(text) ? text : "#000000"),
1325
+ onChange: (event) => setDraft(event.target.value)
1326
+ }), /* @__PURE__ */ jsx("input", {
1327
+ id: props.id,
1328
+ className: `${textInputClass} font-mono text-xs ${props.invalid ? invalidClass : ""}`,
1329
+ defaultValue: text,
1330
+ placeholder: "#1d63d6 or {{steps.…}}",
1331
+ spellCheck: false,
1332
+ onFocus: props.onFocus,
1333
+ onBlur: (event) => {
1334
+ const raw = event.target.value.trim();
1335
+ props.onCommit(raw === "" ? void 0 : raw);
1336
+ }
1337
+ }, text)]
1338
+ });
1339
+ }
1340
+ function richTextMode(format) {
1341
+ if (format === "html") return "html";
1342
+ if (format === "markdown" || format === "md") return "markdown";
1343
+ return "plain";
1344
+ }
1345
+ //#endregion
1346
+ //#region editors/workflow-editor/ui/prop-layout.tsx
1347
+ const PLACED = /* @__PURE__ */ new Set([
1348
+ "section",
1349
+ "tabs",
1350
+ "builder",
1351
+ "footer"
1352
+ ]);
1353
+ function chipText(value) {
1354
+ if (typeof value === "string") return value;
1355
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
1356
+ if (Array.isArray(value)) return value.map(chipText).join(", ");
1357
+ return "set";
1358
+ }
1359
+ /** Consecutive `width: 'half'` fields share a row, two at a time. */
1360
+ function Rows(props) {
1361
+ const rows = [];
1362
+ let pending = null;
1363
+ const flush = () => {
1364
+ if (pending) rows.push(/* @__PURE__ */ jsx(Fragment, { children: pending.node }, pending.prop.name));
1365
+ pending = null;
1366
+ };
1367
+ for (const item of props.items) {
1368
+ if (item.prop.width !== "half") {
1369
+ flush();
1370
+ rows.push(/* @__PURE__ */ jsx(Fragment, { children: item.node }, item.prop.name));
1371
+ continue;
1372
+ }
1373
+ if (!pending) {
1374
+ pending = item;
1375
+ continue;
1376
+ }
1377
+ const first = pending;
1378
+ pending = null;
1379
+ rows.push(/* @__PURE__ */ jsxs("div", {
1380
+ className: "grid grid-cols-1 gap-4 min-[420px]:grid-cols-2",
1381
+ children: [/* @__PURE__ */ jsx("div", {
1382
+ className: "min-w-0",
1383
+ children: first.node
1384
+ }), /* @__PURE__ */ jsx("div", {
1385
+ className: "min-w-0",
1386
+ children: item.node
1387
+ })]
1388
+ }, `${first.prop.name}+${item.prop.name}`));
1389
+ }
1390
+ flush();
1391
+ return /* @__PURE__ */ jsx(Fragment$1, { children: rows });
1392
+ }
1393
+ function RevealCard(props) {
1394
+ const open = props.layout.values[props.checkbox.name] === true;
1395
+ return /* @__PURE__ */ jsxs("div", {
1396
+ className: "flex flex-col gap-4",
1397
+ children: [props.layout.renderField(props.checkbox), open && props.revealed.length > 0 ? /* @__PURE__ */ jsx("div", {
1398
+ className: "flex flex-col gap-4 border-l-2 border-solid border-foreground/10 pl-3",
1399
+ children: /* @__PURE__ */ jsx(Rows, { items: props.revealed.map((prop) => ({
1400
+ prop,
1401
+ node: props.layout.renderField(prop)
1402
+ })) })
1403
+ }) : null]
1404
+ });
1405
+ }
1406
+ function FieldList(props) {
1407
+ const byName = new Map(props.members.map((prop) => [prop.name, prop]));
1408
+ const revealedBy = /* @__PURE__ */ new Map();
1409
+ for (const prop of props.members) for (const name of prop.reveals ?? []) if (byName.has(name)) revealedBy.set(name, prop);
1410
+ const items = props.members.filter((prop) => !revealedBy.has(prop.name)).map((prop) => {
1411
+ const revealed = (prop.reveals ?? []).map((name) => byName.get(name)).filter((entry) => entry !== void 0);
1412
+ return {
1413
+ prop,
1414
+ node: revealed.length > 0 ? /* @__PURE__ */ jsx(RevealCard, {
1415
+ checkbox: prop,
1416
+ revealed,
1417
+ layout: props.layout
1418
+ }) : props.layout.renderField(prop)
1419
+ };
1420
+ });
1421
+ return /* @__PURE__ */ jsx(Rows, { items });
1422
+ }
1423
+ function GroupHeading(props) {
1424
+ const { group } = props;
1425
+ if (!group.label && !group.description) return null;
1426
+ return /* @__PURE__ */ jsxs("div", {
1427
+ className: "flex flex-col gap-0.5",
1428
+ children: [group.label ? /* @__PURE__ */ jsxs("span", {
1429
+ className: "flex items-center gap-1.5 text-[13px] font-semibold text-foreground",
1430
+ children: [isIconName(group.icon) ? /* @__PURE__ */ jsx(Icon, {
1431
+ name: group.icon,
1432
+ className: "h-3.5 w-3.5 text-muted-foreground"
1433
+ }) : null, group.label]
1434
+ }) : null, group.description ? /* @__PURE__ */ jsx("span", {
1435
+ className: "text-xs text-muted-foreground",
1436
+ children: group.description
1437
+ }) : null]
1438
+ });
1439
+ }
1440
+ function Section(props) {
1441
+ return /* @__PURE__ */ jsxs("section", {
1442
+ "aria-label": props.group.label,
1443
+ className: "flex flex-col gap-4 rounded-lg border border-solid border-foreground/10 p-4",
1444
+ children: [/* @__PURE__ */ jsx(GroupHeading, { group: props.group }), /* @__PURE__ */ jsx(FieldList, {
1445
+ members: props.members,
1446
+ layout: props.layout
1447
+ })]
1448
+ });
1449
+ }
1450
+ function TabbedGroup(props) {
1451
+ const [active, setActive] = useState(props.members[0]?.name ?? "");
1452
+ const current = props.members.find((prop) => prop.name === active) ?? props.members[0];
1453
+ if (!current) return null;
1454
+ return /* @__PURE__ */ jsxs("div", {
1455
+ className: "flex flex-col gap-3",
1456
+ children: [
1457
+ /* @__PURE__ */ jsx(GroupHeading, { group: props.group }),
1458
+ /* @__PURE__ */ jsx("div", {
1459
+ className: "border-b border-solid border-foreground/10",
1460
+ children: /* @__PURE__ */ jsx(Tabs, {
1461
+ value: current.name,
1462
+ onChange: setActive,
1463
+ tabs: props.members.map((prop) => ({
1464
+ value: prop.name,
1465
+ label: prop.displayName,
1466
+ badge: isEmptyValue(props.layout.values[prop.name]) ? void 0 : /* @__PURE__ */ jsx("span", {
1467
+ "aria-label": "has a value",
1468
+ className: "h-1.5 w-1.5 rounded-full bg-wf-run"
1469
+ })
1470
+ }))
1471
+ })
1472
+ }),
1473
+ props.layout.renderField(current)
1474
+ ]
1475
+ });
1476
+ }
1477
+ function BuilderGroups(props) {
1478
+ const members = props.groups.flatMap((group) => group.props.map((name) => props.byName.get(name)).filter((prop) => prop !== void 0));
1479
+ const [added, setAdded] = useState([]);
1480
+ const inUse = members.filter((prop) => prop.required || added.includes(prop.name) || !isEmptyValue(props.layout.values[prop.name]));
1481
+ const available = members.filter((prop) => !inUse.includes(prop));
1482
+ return /* @__PURE__ */ jsxs("div", {
1483
+ className: "flex flex-col gap-3",
1484
+ children: [
1485
+ props.groups.map((group) => /* @__PURE__ */ jsx(GroupHeading, { group }, group.key)),
1486
+ inUse.map((prop) => /* @__PURE__ */ jsxs("div", {
1487
+ className: "flex items-start gap-1",
1488
+ children: [/* @__PURE__ */ jsx("div", {
1489
+ className: "min-w-0 flex-1",
1490
+ children: props.layout.renderField(prop)
1491
+ }), prop.required ? null : /* @__PURE__ */ jsx(IconButton, {
1492
+ icon: "close",
1493
+ label: `Remove ${prop.displayName}`,
1494
+ className: "mt-7",
1495
+ onClick: () => {
1496
+ setAdded((names) => names.filter((name) => name !== prop.name));
1497
+ props.layout.onCommit(prop.name, void 0);
1498
+ }
1499
+ })]
1500
+ }, prop.name)),
1501
+ available.length > 0 ? /* @__PURE__ */ jsx("div", {
1502
+ className: "max-w-60",
1503
+ children: /* @__PURE__ */ jsx(Select, {
1504
+ options: available.map((prop) => ({
1505
+ value: prop.name,
1506
+ label: prop.displayName,
1507
+ description: prop.description
1508
+ })),
1509
+ value: "",
1510
+ placeholder: "Add filter",
1511
+ onChange: (name) => {
1512
+ if (name) setAdded((names) => [...names, name]);
1513
+ }
1514
+ })
1515
+ }) : null
1516
+ ]
1517
+ });
1518
+ }
1519
+ function Summary(props) {
1520
+ const set = props.members.filter((prop) => !isEmptyValue(props.layout.values[prop.name]));
1521
+ if (set.length === 0) return null;
1522
+ return /* @__PURE__ */ jsx("div", {
1523
+ className: "flex flex-wrap gap-1.5",
1524
+ "aria-label": "Filters in use",
1525
+ children: set.map((prop) => /* @__PURE__ */ jsxs("span", {
1526
+ className: "inline-flex h-6 max-w-full items-center gap-1 rounded-full bg-muted pl-2.5 pr-1 text-xs text-foreground",
1527
+ children: [/* @__PURE__ */ jsxs("span", {
1528
+ className: "truncate",
1529
+ children: [
1530
+ prop.displayName,
1531
+ ": ",
1532
+ chipText(props.layout.values[prop.name])
1533
+ ]
1534
+ }), /* @__PURE__ */ jsx("button", {
1535
+ type: "button",
1536
+ "aria-label": `Clear ${prop.displayName}`,
1537
+ className: "flex h-4 w-4 items-center justify-center rounded-full text-muted-foreground hover:bg-foreground/10 hover:text-foreground",
1538
+ onClick: () => props.layout.onCommit(prop.name, void 0),
1539
+ children: /* @__PURE__ */ jsx(Icon, {
1540
+ name: "close",
1541
+ className: "h-3 w-3"
1542
+ })
1543
+ })]
1544
+ }, prop.name))
1545
+ });
1546
+ }
1547
+ function PropLayout(props) {
1548
+ const groups = (props.groups ?? []).filter((group) => PLACED.has(group.display) || group.display === "summary");
1549
+ const byName = new Map(props.props.map((prop) => [prop.name, prop]));
1550
+ const groupOf = /* @__PURE__ */ new Map();
1551
+ for (const group of groups) {
1552
+ if (!PLACED.has(group.display)) continue;
1553
+ for (const name of group.props) if (byName.has(name) && !groupOf.has(name)) groupOf.set(name, group);
1554
+ }
1555
+ const membersOf = (group) => group.props.map((name) => byName.get(name)).filter((prop) => prop !== void 0);
1556
+ const builderGroups = groups.filter((group) => group.display === "builder");
1557
+ const summaries = groups.filter((group) => group.display === "summary");
1558
+ const sectionMembers = groups.filter((group) => group.display === "section").flatMap(membersOf);
1559
+ const blocks = [];
1560
+ let loose = [];
1561
+ const flushLoose = () => {
1562
+ if (loose.length === 0) return;
1563
+ blocks.push(/* @__PURE__ */ jsx(FieldList, {
1564
+ members: loose,
1565
+ layout: props
1566
+ }, `loose:${loose[0].name}`));
1567
+ loose = [];
1568
+ };
1569
+ const summarised = summaries.length > 0 && sectionMembers.length > 0;
1570
+ const placed = /* @__PURE__ */ new Set();
1571
+ for (const prop of props.props) {
1572
+ const group = groupOf.get(prop.name);
1573
+ if (!group) {
1574
+ loose.push(prop);
1575
+ continue;
1576
+ }
1577
+ const key = group.display === "builder" ? "builder" : group.key;
1578
+ if (placed.has(key)) continue;
1579
+ placed.add(key);
1580
+ flushLoose();
1581
+ if (group.display === "builder") blocks.push(/* @__PURE__ */ jsx(BuilderGroups, {
1582
+ groups: builderGroups,
1583
+ byName,
1584
+ layout: props
1585
+ }, "builder"));
1586
+ else if (group.display === "tabs") blocks.push(/* @__PURE__ */ jsx(TabbedGroup, {
1587
+ group,
1588
+ members: membersOf(group),
1589
+ layout: props
1590
+ }, group.key));
1591
+ else if (group.display === "footer") blocks.push(/* @__PURE__ */ jsxs("div", {
1592
+ className: "flex flex-col gap-4 border-t border-solid border-foreground/10 pt-4",
1593
+ children: [/* @__PURE__ */ jsx(GroupHeading, { group }), /* @__PURE__ */ jsx(FieldList, {
1594
+ members: membersOf(group),
1595
+ layout: props
1596
+ })]
1597
+ }, group.key));
1598
+ else {
1599
+ if (summarised && !placed.has("summary")) {
1600
+ placed.add("summary");
1601
+ blocks.push(/* @__PURE__ */ jsx(Summary, {
1602
+ members: sectionMembers,
1603
+ layout: props
1604
+ }, "summary"));
1605
+ }
1606
+ blocks.push(/* @__PURE__ */ jsx(Section, {
1607
+ group,
1608
+ members: membersOf(group),
1609
+ layout: props
1610
+ }, group.key));
1611
+ }
1612
+ }
1613
+ flushLoose();
1614
+ return /* @__PURE__ */ jsx(Fragment$1, { children: blocks });
1615
+ }
1616
+ //#endregion
1617
+ //#region editors/workflow-editor/ui/PropertyForm.tsx
1618
+ function insertAtCursor(element, text) {
1619
+ const start = element.selectionStart ?? element.value.length;
1620
+ const end = element.selectionEnd ?? start;
1621
+ element.value = element.value.slice(0, start) + text + element.value.slice(end);
1622
+ return element.value;
1623
+ }
1624
+ const WHOLE_EXPRESSION = /^\{\{\s*[^{}]+?\s*\}\}$/;
1625
+ const DECIMAL = /^-?(?:\d+(?:\.\d*)?|\.\d+)$/;
1626
+ function parseDecimal(raw) {
1627
+ const trimmed = raw.trim();
1628
+ return DECIMAL.test(trimmed) ? Number(trimmed) : void 0;
1629
+ }
1630
+ function stringifyValue(value) {
1631
+ if (value === void 0 || value === null) return "";
1632
+ if (typeof value === "string") return value;
1633
+ try {
1634
+ return JSON.stringify(value, null, 2);
1635
+ } catch {
1636
+ return String(value);
1637
+ }
1638
+ }
1639
+ function parseDropdownResult(result) {
1640
+ const record = result;
1641
+ if (!record || !Array.isArray(record.options)) throw new Error("Unexpected options result");
1642
+ return {
1643
+ options: record.options.map((option) => ({
1644
+ label: stringifyValue(option.label ?? option.value),
1645
+ value: option.value,
1646
+ ...typeof option.description === "string" && option.description ? { description: option.description } : {},
1647
+ ...typeof option.icon === "string" ? { icon: option.icon } : {}
1648
+ })),
1649
+ placeholder: record.placeholder,
1650
+ disabled: record.disabled
1651
+ };
1652
+ }
1653
+ const RELOAD_DEBOUNCE_MS = 400;
1654
+ const PieceMarkdown = lazy(() => import("./PieceMarkdown-U6OUTwRi.js"));
1655
+ const NO_ENDPOINT = "[no endpoint yet — see Endpoint URL above]";
1656
+ function fillPiecePlaceholders(text, values) {
1657
+ return text.replace(/\{\{\s*webhookUrl\s*\}\}/g, values.webhookUrl ?? NO_ENDPOINT).replace(/\{\{\s*webhookTimeoutSeconds\s*\}\}/g, values.webhookTimeoutSeconds === void 0 ? "{{webhookTimeoutSeconds}}" : String(values.webhookTimeoutSeconds));
1658
+ }
1659
+ function AvailableSoon(props) {
1660
+ return /* @__PURE__ */ jsxs("span", {
1661
+ className: "inline-flex items-center gap-1 rounded-full bg-wf-warn/10 px-2 py-0.5 text-[11px] font-medium normal-case tracking-normal text-wf-warn",
1662
+ title: "Not supported by the runtime yet",
1663
+ children: ["Available soon", props.children ? /* @__PURE__ */ jsxs("span", { children: [": ", props.children] }) : null]
1664
+ });
1665
+ }
1666
+ function FieldShell(props) {
1667
+ const { prop } = props;
1668
+ const LabelTag = props.htmlFor ? "label" : "span";
1669
+ return /* @__PURE__ */ jsxs("div", {
1670
+ className: "group/field",
1671
+ children: [
1672
+ /* @__PURE__ */ jsxs("div", {
1673
+ className: "mb-1.5 flex min-h-6 items-center justify-between gap-2",
1674
+ children: [/* @__PURE__ */ jsxs(LabelTag, {
1675
+ htmlFor: props.htmlFor,
1676
+ className: "flex min-w-0 items-baseline gap-1.5 text-[13px] font-medium text-foreground",
1677
+ children: [
1678
+ optionIcon(prop.icon),
1679
+ /* @__PURE__ */ jsx("span", {
1680
+ className: "truncate",
1681
+ children: prop.displayName
1682
+ }),
1683
+ !prop.required ? /* @__PURE__ */ jsx("span", {
1684
+ className: "shrink-0 text-xs font-normal text-muted-foreground",
1685
+ children: "Optional"
1686
+ }) : null,
1687
+ props.invalid ? /* @__PURE__ */ jsx("span", {
1688
+ className: "shrink-0 text-xs font-normal text-wf-warn",
1689
+ children: "Needs a value"
1690
+ }) : null
1691
+ ]
1692
+ }), props.picker ? /* @__PURE__ */ jsx("span", {
1693
+ className: "flex shrink-0 items-center gap-0.5",
1694
+ children: props.picker
1695
+ }) : null]
1696
+ }),
1697
+ props.children,
1698
+ /* @__PURE__ */ jsx(FieldError, { children: props.error }),
1699
+ /* @__PURE__ */ jsx(Hint, { text: prop.description })
1700
+ ]
1701
+ });
1702
+ }
1703
+ function OptionList(props) {
1704
+ const keyOf = (value) => stringifyValue(value);
1705
+ const byKey = new Map(props.options.map((option) => [keyOf(option.value), option]));
1706
+ return /* @__PURE__ */ jsx(Select, {
1707
+ id: props.id,
1708
+ multiple: true,
1709
+ options: props.options.map((option) => ({
1710
+ value: keyOf(option.value),
1711
+ label: option.label
1712
+ })),
1713
+ value: props.selected.map(keyOf),
1714
+ onChange: (keys) => props.onChange(keys.map((key) => byKey.get(key)?.value ?? key)),
1715
+ invalid: props.invalid,
1716
+ loading: props.loading,
1717
+ onRefresh: props.onRefresh,
1718
+ placeholder: props.placeholder ?? "Choose any"
1719
+ });
1720
+ }
1721
+ function OptionSelect(props) {
1722
+ const keyOf = (value) => stringifyValue(value);
1723
+ const byKey = new Map(props.options.map((option) => [keyOf(option.value), option]));
1724
+ return /* @__PURE__ */ jsx(Select, {
1725
+ id: props.id,
1726
+ options: props.options.map((option) => ({
1727
+ value: keyOf(option.value),
1728
+ label: option.label,
1729
+ description: option.description,
1730
+ icon: optionIcon(option.icon)
1731
+ })),
1732
+ value: keyOf(props.value),
1733
+ onChange: (key) => props.onChange(key === "" ? void 0 : byKey.get(key)?.value ?? key),
1734
+ invalid: props.invalid,
1735
+ placeholder: props.placeholder,
1736
+ loading: props.loading,
1737
+ disabled: props.disabled,
1738
+ onRefresh: props.onRefresh,
1739
+ clearable: props.clearable,
1740
+ emptyText: props.emptyText,
1741
+ searchable: props.searchable,
1742
+ actions: props.actions,
1743
+ onQueryChange: props.onQueryChange
1744
+ });
1745
+ }
1746
+ const SUMMARY_CHARS = 60;
1747
+ function itemSummary(fields, row) {
1748
+ const parts = [];
1749
+ for (const field of fields) {
1750
+ const value = row[field.name];
1751
+ if (value === true) {
1752
+ parts.push(field.displayName.toLowerCase());
1753
+ continue;
1754
+ }
1755
+ if (value === void 0 || value === null || value === false) continue;
1756
+ const option = field.staticOptions?.find((o) => o.value === value);
1757
+ const text = option ? option.label : stringifyValue(value).trim();
1758
+ if (!text) continue;
1759
+ parts.push(text.length > SUMMARY_CHARS ? `${text.slice(0, SUMMARY_CHARS)}…` : text);
1760
+ }
1761
+ return parts.join(" · ");
1762
+ }
1763
+ function ArrayRows(props) {
1764
+ const fields = props.prop.properties ?? [];
1765
+ const rows = Array.isArray(props.value) ? props.value.map((item) => item !== null && typeof item === "object" ? item : {}) : [];
1766
+ const [open, setOpen] = useState(() => /* @__PURE__ */ new Set());
1767
+ const toggle = (index) => setOpen((current) => {
1768
+ const next = new Set(current);
1769
+ if (!next.delete(index)) next.add(index);
1770
+ return next;
1771
+ });
1772
+ const update = (next) => props.onCommit(next.length > 0 ? next : void 0);
1773
+ const remove = (index) => {
1774
+ update(rows.filter((_, i) => i !== index));
1775
+ setOpen((current) => new Set([...current].filter((i) => i !== index).map((i) => i > index ? i - 1 : i)));
1776
+ };
1777
+ return /* @__PURE__ */ jsxs("div", {
1778
+ className: `flex flex-col gap-1.5 ${props.invalid ? "rounded-md ring-1 ring-wf-warn/50" : ""}`,
1779
+ children: [rows.map((row, index) => {
1780
+ const expanded = open.has(index);
1781
+ const summary = itemSummary(fields, row);
1782
+ return /* @__PURE__ */ jsxs("div", {
1783
+ className: "rounded-md border border-solid border-foreground/10 bg-muted/40",
1784
+ children: [/* @__PURE__ */ jsxs("div", {
1785
+ className: "flex items-center gap-1 py-1 pl-1 pr-1",
1786
+ children: [/* @__PURE__ */ jsxs("button", {
1787
+ type: "button",
1788
+ "aria-expanded": expanded,
1789
+ onClick: () => toggle(index),
1790
+ className: "flex min-w-0 flex-1 items-center gap-1.5 rounded px-1 py-0.5 text-left text-[13px] hover:bg-foreground/5",
1791
+ children: [/* @__PURE__ */ jsx(Icon, {
1792
+ name: expanded ? "chevronDown" : "chevron",
1793
+ className: "h-3.5 w-3.5 shrink-0 text-muted-foreground"
1794
+ }), /* @__PURE__ */ jsx("span", {
1795
+ className: `truncate ${summary ? "text-foreground" : "text-muted-foreground"}`,
1796
+ children: summary || `Item ${index + 1}`
1797
+ })]
1798
+ }), /* @__PURE__ */ jsx(IconButton, {
1799
+ icon: "trash",
1800
+ label: `Remove item ${index + 1}`,
1801
+ onClick: () => remove(index)
1802
+ })]
1803
+ }), expanded ? /* @__PURE__ */ jsx("div", {
1804
+ className: "border-t border-solid border-foreground/10 px-3 pb-3 pt-2",
1805
+ children: /* @__PURE__ */ jsx(PropertyForm, {
1806
+ props: fields,
1807
+ value: row,
1808
+ onChange: (next) => update(rows.map((entry, i) => i === index ? next : entry)),
1809
+ scopeStepId: props.scopeStepId,
1810
+ nested: true
1811
+ })
1812
+ }) : null]
1813
+ }, index);
1814
+ }), /* @__PURE__ */ jsxs(Button, {
1815
+ size: "sm",
1816
+ className: "self-start",
1817
+ onClick: () => {
1818
+ update([...rows, withPropDefaults(fields, {})]);
1819
+ setOpen((current) => new Set(current).add(rows.length));
1820
+ },
1821
+ children: [/* @__PURE__ */ jsx(Icon, {
1822
+ name: "plus",
1823
+ className: "h-3.5 w-3.5"
1824
+ }), "Add item"]
1825
+ })]
1826
+ });
1827
+ }
1828
+ function rowsOf(value) {
1829
+ return Object.entries(value).map(([key, entry]) => ({
1830
+ key,
1831
+ value: stringifyValue(entry)
1832
+ }));
1833
+ }
1834
+ function recordOf(rows) {
1835
+ const record = {};
1836
+ for (const row of rows) if (row.key.trim() !== "") record[row.key.trim()] = row.value;
1837
+ return record;
1838
+ }
1839
+ function ObjectRows(props) {
1840
+ const [rows, setRows] = useState(() => rowsOf(props.value));
1841
+ const valueKey = keyOf(props.value);
1842
+ const [seen, setSeen] = useState(valueKey);
1843
+ if (seen !== valueKey) {
1844
+ setSeen(valueKey);
1845
+ if (keyOf(recordOf(rows)) !== valueKey) setRows(rowsOf(props.value));
1846
+ }
1847
+ const commit = (next) => {
1848
+ setRows(next);
1849
+ const record = recordOf(next);
1850
+ props.onCommit(Object.keys(record).length > 0 ? record : void 0);
1851
+ };
1852
+ return /* @__PURE__ */ jsxs("div", {
1853
+ className: `flex flex-col gap-1.5 ${props.invalid ? "rounded-md ring-1 ring-wf-warn/50" : ""}`,
1854
+ children: [rows.map((row, index) => /* @__PURE__ */ jsxs("div", {
1855
+ className: "flex items-center gap-1",
1856
+ children: [
1857
+ /* @__PURE__ */ jsx("input", {
1858
+ className: `${textInputClass} font-mono text-xs`,
1859
+ placeholder: "Key",
1860
+ value: row.key,
1861
+ onChange: (event) => setRows(rows.map((entry, i) => i === index ? {
1862
+ ...entry,
1863
+ key: event.target.value
1864
+ } : entry)),
1865
+ onBlur: () => commit(rows)
1866
+ }),
1867
+ /* @__PURE__ */ jsx("input", {
1868
+ className: `${textInputClass} font-mono text-xs`,
1869
+ placeholder: "Value",
1870
+ value: row.value,
1871
+ onChange: (event) => setRows(rows.map((entry, i) => i === index ? {
1872
+ ...entry,
1873
+ value: event.target.value
1874
+ } : entry)),
1875
+ onBlur: () => commit(rows)
1876
+ }),
1877
+ /* @__PURE__ */ jsx(IconButton, {
1878
+ icon: "close",
1879
+ label: "Remove entry",
1880
+ onClick: () => commit(rows.filter((_, i) => i !== index))
1881
+ })
1882
+ ]
1883
+ }, index)), /* @__PURE__ */ jsxs(Button, {
1884
+ size: "sm",
1885
+ className: "self-start",
1886
+ onClick: () => setRows([...rows, {
1887
+ key: "",
1888
+ value: ""
1889
+ }]),
1890
+ children: [/* @__PURE__ */ jsx(Icon, {
1891
+ name: "plus",
1892
+ className: "h-3.5 w-3.5"
1893
+ }), "Add entry"]
1894
+ })]
1895
+ });
1896
+ }
1897
+ function isoToLocalInput(value) {
1898
+ if (typeof value !== "string" || value === "") return "";
1899
+ const date = new Date(value);
1900
+ if (Number.isNaN(date.getTime())) return "";
1901
+ const pad = (n) => String(n).padStart(2, "0");
1902
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
1903
+ }
1904
+ function localInputToIso(value) {
1905
+ if (value === "") return void 0;
1906
+ const date = new Date(value);
1907
+ return Number.isNaN(date.getTime()) ? value : date.toISOString();
1908
+ }
1909
+ function isDropdownType(type) {
1910
+ return type === "DROPDOWN" || type === "MULTI_SELECT_DROPDOWN";
1911
+ }
1912
+ const SEARCH_DEBOUNCE_MS = 300;
1913
+ const FLIPS_TO_TEXT = /* @__PURE__ */ new Set([
1914
+ "DATE_TIME",
1915
+ "OBJECT",
1916
+ "DROPDOWN",
1917
+ "CHECKBOX",
1918
+ "NUMBER"
1919
+ ]);
1920
+ const TEXT_MODE_TYPES = /* @__PURE__ */ new Set([
1921
+ "SHORT_TEXT",
1922
+ "LONG_TEXT",
1923
+ "NUMBER",
1924
+ "SECRET_TEXT",
1925
+ "FILE",
1926
+ "JSON",
1927
+ "DATE_TIME",
1928
+ "OBJECT",
1929
+ "DROPDOWN",
1930
+ "CHECKBOX"
1931
+ ]);
1932
+ function SecretRefField(props) {
1933
+ const { secrets } = props;
1934
+ const fieldId = useId();
1935
+ const { ref, managed, draft, setDraft, busy, error, stat, commit } = useSecretRef({
1936
+ value: props.value,
1937
+ secrets,
1938
+ label: props.prop.displayName,
1939
+ onCommit: props.onCommit
1940
+ });
1941
+ if (!secrets) return /* @__PURE__ */ jsx(FieldShell, {
1942
+ htmlFor: fieldId,
1943
+ prop: props.prop,
1944
+ invalid: props.invalid,
1945
+ children: /* @__PURE__ */ jsx("p", {
1946
+ className: "text-xs text-muted-foreground",
1947
+ children: "Managed secrets are unavailable in this session."
1948
+ })
1949
+ });
1950
+ return /* @__PURE__ */ jsxs(FieldShell, {
1951
+ htmlFor: fieldId,
1952
+ prop: props.prop,
1953
+ invalid: props.invalid,
1954
+ error,
1955
+ children: [managed ? /* @__PURE__ */ jsxs("p", {
1956
+ className: "mb-1.5 flex items-center gap-1.5 text-xs text-muted-foreground",
1957
+ children: [
1958
+ /* @__PURE__ */ jsx("span", {
1959
+ className: "font-medium text-foreground",
1960
+ children: stat?.label ?? ref
1961
+ }),
1962
+ stat ? /* @__PURE__ */ jsxs("span", { children: ["version ", stat.version] }) : null,
1963
+ stat?.status === "DELETED" ? /* @__PURE__ */ jsx("span", {
1964
+ className: "font-medium text-wf-fail",
1965
+ children: "deleted"
1966
+ }) : null
1967
+ ]
1968
+ }) : null, /* @__PURE__ */ jsxs("div", {
1969
+ className: "flex items-center gap-1",
1970
+ children: [/* @__PURE__ */ jsx("input", {
1971
+ id: fieldId,
1972
+ className: `${textInputClass} ${props.invalid ? invalidClass : ""}`,
1973
+ type: "password",
1974
+ value: draft,
1975
+ disabled: busy,
1976
+ placeholder: managed ? "Paste a new value to replace it" : "Paste the secret value",
1977
+ autoComplete: "off",
1978
+ spellCheck: false,
1979
+ onChange: (event) => setDraft(event.target.value),
1980
+ onKeyDown: (event) => {
1981
+ if (event.key === "Enter") commit();
1982
+ },
1983
+ onBlur: commit
1984
+ }), ref ? /* @__PURE__ */ jsx(IconButton, {
1985
+ icon: "close",
1986
+ label: "Remove secret",
1987
+ onClick: () => props.onCommit(void 0)
1988
+ }) : null]
1989
+ })]
1990
+ });
1991
+ }
1992
+ function ModeButton(props) {
1993
+ return /* @__PURE__ */ jsx("button", {
1994
+ type: "button",
1995
+ className: "inline-flex h-6 shrink-0 items-center rounded-md px-1.5 text-xs font-medium text-muted-foreground hover:bg-accent hover:text-foreground",
1996
+ onClick: props.onClick,
1997
+ children: props.label
1998
+ });
1999
+ }
2000
+ function PropField(props) {
2001
+ const { prop, value } = props;
2002
+ const fieldId = useId();
2003
+ const optionsUnavailable = Boolean(props.nested && prop.hasDynamicResolver && !props.loadOptions);
2004
+ const fieldRef = useRef(null);
2005
+ const invalid = prop.required && prop.type !== "MARKDOWN" && isEmptyValue(value);
2006
+ const [draft, setDraft] = useState(() => stringifyValue(value));
2007
+ const [prevValue, setPrevValue] = useState(value);
2008
+ if (value !== prevValue) {
2009
+ setPrevValue(value);
2010
+ setDraft(stringifyValue(value));
2011
+ }
2012
+ const [jsonError, setJsonError] = useState(null);
2013
+ const [textMode, setTextMode] = useState(props.mode === "EXPRESSION");
2014
+ const [prevMode, setPrevMode] = useState(props.mode);
2015
+ if (props.mode !== prevMode) {
2016
+ setPrevMode(props.mode);
2017
+ if (props.mode) setTextMode(props.mode === "EXPRESSION");
2018
+ }
2019
+ const onCommit = (next, mode) => props.onCommit(next, mode ?? (textMode ? "EXPRESSION" : "MANUAL"));
2020
+ const toMode = (expression) => {
2021
+ setTextMode(expression);
2022
+ props.onMode?.(expression ? "EXPRESSION" : "MANUAL");
2023
+ };
2024
+ const [numberError, setNumberError] = useState(null);
2025
+ const commitsOnInsert = prop.type !== "JSON";
2026
+ const field = useExpressionField({
2027
+ stepId: props.scopeStepId,
2028
+ label: prop.displayName,
2029
+ insert: (expression) => {
2030
+ if (FLIPS_TO_TEXT.has(prop.type) && !textMode) {
2031
+ setTextMode(true);
2032
+ setDraft(expression);
2033
+ setNumberError(null);
2034
+ onCommit(expression, "EXPRESSION");
2035
+ return;
2036
+ }
2037
+ if (!fieldRef.current) return;
2038
+ const next = insertAtCursor(fieldRef.current, expression);
2039
+ setDraft(next);
2040
+ if (commitsOnInsert) onCommit(next);
2041
+ }
2042
+ });
2043
+ const picker = TEXT_MODE_TYPES.has(prop.type) ? /* @__PURE__ */ jsx(ExpressionPickerButton, {
2044
+ active: field.active,
2045
+ onFocusField: field.focus
2046
+ }) : void 0;
2047
+ const dynamicLoad = props.loadOptions && prop.hasDynamicResolver && !props.optionsBlocked ? () => props.loadOptions(prop.name) : void 0;
2048
+ const isDropdown = prop.type === "DROPDOWN" || prop.type === "MULTI_SELECT_DROPDOWN";
2049
+ const dropdown = useResolvedProp({
2050
+ kind: "options",
2051
+ input: props.resolverInput,
2052
+ load: isDropdown ? dynamicLoad : void 0,
2053
+ parse: parseDropdownResult,
2054
+ debounceMs: RELOAD_DEBOUNCE_MS
2055
+ });
2056
+ const dynamic = useResolvedProp({
2057
+ kind: "dynamic",
2058
+ input: props.resolverInput,
2059
+ load: prop.type === "DYNAMIC" ? dynamicLoad : void 0,
2060
+ parse: parsePropList,
2061
+ debounceMs: RELOAD_DEBOUNCE_MS
2062
+ });
2063
+ const dynamicFields = dynamic.state.kind === "ready" ? dynamic.state.result : null;
2064
+ useEffect(() => {
2065
+ if (value !== void 0 || !dynamicFields) return;
2066
+ if (lacksDefaults(dynamicFields, {})) props.onCommit(withPropDefaults(dynamicFields, {}), "MANUAL");
2067
+ }, [dynamicFields]);
2068
+ const [searchQuery, setSearchQuery] = useState("");
2069
+ const [picked, setPicked] = useState(null);
2070
+ const loadOptions = props.loadOptions;
2071
+ const searchable = Boolean(prop.refreshOnSearch && loadOptions);
2072
+ const searchResult = useOptionSearch({
2073
+ input: props.resolverInput,
2074
+ query: searchQuery,
2075
+ load: searchable && loadOptions ? (searchValue) => loadOptions(prop.name, searchValue) : void 0,
2076
+ parse: parseDropdownResult,
2077
+ debounceMs: SEARCH_DEBOUNCE_MS
2078
+ });
2079
+ const onSearch = searchable ? setSearchQuery : void 0;
2080
+ const retryButton = (state, reload) => /* @__PURE__ */ jsx(IconButton, {
2081
+ icon: "retry",
2082
+ label: "Reload",
2083
+ disabled: state.kind === "loading",
2084
+ onClick: reload
2085
+ });
2086
+ const blocked = prop.hasDynamicResolver ? props.optionsBlocked : void 0;
2087
+ const loadError = (state) => blocked ?? (state.kind === "error" ? props.explainOptionsError?.(state.message) ?? state.message : null);
2088
+ const textInput = (extra) => /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("div", {
2089
+ className: "flex items-center gap-1",
2090
+ children: /* @__PURE__ */ jsx("input", {
2091
+ id: fieldId,
2092
+ ref: fieldRef,
2093
+ type: extra.type ?? "text",
2094
+ className: `${textInputClass} ${extra.mono ? "font-mono text-xs" : ""} ${invalid ? invalidClass : ""}`,
2095
+ defaultValue: stringifyValue(value),
2096
+ placeholder: extra.placeholder ?? prop.placeholder,
2097
+ spellCheck: false,
2098
+ onFocus: field.focus,
2099
+ onChange: (event) => setDraft(event.target.value),
2100
+ onBlur: (event) => extra.commit(event.target.value)
2101
+ })
2102
+ }), extra.type === "password" ? null : /* @__PURE__ */ jsx(ExpressionTokenLine, { value: draft })] });
2103
+ switch (prop.type) {
2104
+ case "PH_SECRET_REF": return /* @__PURE__ */ jsx(SecretRefField, {
2105
+ prop,
2106
+ value,
2107
+ onCommit,
2108
+ invalid,
2109
+ secrets: props.secrets
2110
+ });
2111
+ case "MARKDOWN": {
2112
+ const markdown = fillPiecePlaceholders(stringifyValue(prop.description ?? prop.defaultValue ?? prop.displayName), { webhookUrl: props.webhookUrl });
2113
+ return /* @__PURE__ */ jsx(MarkdownCallout, {
2114
+ variant: prop.variant,
2115
+ children: /* @__PURE__ */ jsx(Suspense, {
2116
+ fallback: /* @__PURE__ */ jsx("p", {
2117
+ className: "whitespace-pre-wrap text-xs text-muted-foreground",
2118
+ children: markdown
2119
+ }),
2120
+ children: /* @__PURE__ */ jsx(PieceMarkdown, { text: markdown })
2121
+ })
2122
+ });
2123
+ }
2124
+ case "CHECKBOX":
2125
+ if (textMode) return /* @__PURE__ */ jsx(FieldShell, {
2126
+ htmlFor: fieldId,
2127
+ prop,
2128
+ invalid,
2129
+ picker: /* @__PURE__ */ jsxs(Fragment$1, { children: [picker, /* @__PURE__ */ jsx(ModeButton, {
2130
+ label: "Use a switch",
2131
+ onClick: () => {
2132
+ setTextMode(false);
2133
+ onCommit(void 0, "MANUAL");
2134
+ }
2135
+ })] }),
2136
+ children: textInput({
2137
+ mono: true,
2138
+ placeholder: "{{steps.…}} yielding true or false",
2139
+ commit: (raw) => {
2140
+ const trimmed = raw.trim();
2141
+ if (trimmed === "") {
2142
+ setTextMode(false);
2143
+ return onCommit(void 0, "MANUAL");
2144
+ }
2145
+ onCommit(trimmed, "EXPRESSION");
2146
+ }
2147
+ })
2148
+ });
2149
+ return /* @__PURE__ */ jsxs("div", {
2150
+ className: "group/field flex items-start gap-1",
2151
+ children: [/* @__PURE__ */ jsx("div", {
2152
+ className: "min-w-0 flex-1",
2153
+ children: /* @__PURE__ */ jsx(Switch, {
2154
+ checked: value === true,
2155
+ onChange: (checked) => onCommit(checked, "MANUAL"),
2156
+ label: prop.displayName,
2157
+ description: prop.description
2158
+ })
2159
+ }), picker]
2160
+ });
2161
+ case "NUMBER": {
2162
+ const rangeError = numberRangeError(value, prop.min, prop.max);
2163
+ const commitNumber = (raw) => {
2164
+ const trimmed = raw.trim();
2165
+ if (trimmed === "") {
2166
+ setNumberError(null);
2167
+ if (!textMode) return onCommit(void 0);
2168
+ setTextMode(false);
2169
+ return onCommit(void 0, "MANUAL");
2170
+ }
2171
+ if (textMode || hasExpressions(trimmed)) {
2172
+ setNumberError(null);
2173
+ setTextMode(true);
2174
+ return onCommit(trimmed, "EXPRESSION");
2175
+ }
2176
+ const parsed = parseDecimal(trimmed);
2177
+ if (parsed === void 0) {
2178
+ setNumberError("Not a number");
2179
+ return;
2180
+ }
2181
+ setNumberError(null);
2182
+ onCommit(parsed);
2183
+ };
2184
+ if (prop.display === "stepper" && !textMode) return /* @__PURE__ */ jsx(FieldShell, {
2185
+ htmlFor: fieldId,
2186
+ prop,
2187
+ invalid,
2188
+ picker,
2189
+ error: numberError ?? rangeError,
2190
+ children: /* @__PURE__ */ jsx(NumberStepper, {
2191
+ id: fieldId,
2192
+ value,
2193
+ min: prop.min,
2194
+ max: prop.max,
2195
+ step: prop.step,
2196
+ invalid: invalid || rangeError !== null || numberError !== null,
2197
+ onCommit: (next) => {
2198
+ setNumberError(null);
2199
+ onCommit(next);
2200
+ },
2201
+ onCommitText: commitNumber,
2202
+ onFocus: field.focus
2203
+ })
2204
+ });
2205
+ return /* @__PURE__ */ jsx(FieldShell, {
2206
+ htmlFor: fieldId,
2207
+ prop,
2208
+ invalid,
2209
+ picker,
2210
+ error: numberError ?? (textMode ? null : rangeError),
2211
+ children: textInput({
2212
+ mono: textMode,
2213
+ placeholder: textMode ? "{{expression}} yielding a number" : prop.placeholder ?? numberRangeText(prop.min, prop.max) ?? void 0,
2214
+ commit: commitNumber
2215
+ })
2216
+ });
2217
+ }
2218
+ case "SECRET_TEXT": return /* @__PURE__ */ jsx(FieldShell, {
2219
+ htmlFor: fieldId,
2220
+ prop,
2221
+ invalid,
2222
+ picker,
2223
+ children: textInput({
2224
+ type: "password",
2225
+ commit: (raw) => onCommit(raw === "" ? void 0 : raw)
2226
+ })
2227
+ });
2228
+ case "FILE": return /* @__PURE__ */ jsx(FieldShell, {
2229
+ htmlFor: fieldId,
2230
+ prop,
2231
+ invalid,
2232
+ picker,
2233
+ children: textInput({
2234
+ mono: true,
2235
+ placeholder: prop.placeholder ?? "https://… or data:…;base64,…",
2236
+ commit: (raw) => onCommit(raw.trim() === "" ? void 0 : raw.trim())
2237
+ })
2238
+ });
2239
+ case "DATE_TIME":
2240
+ if (textMode) return /* @__PURE__ */ jsx(FieldShell, {
2241
+ htmlFor: fieldId,
2242
+ prop,
2243
+ invalid,
2244
+ picker,
2245
+ children: textInput({
2246
+ mono: true,
2247
+ placeholder: "ISO 8601 or {{expression}}",
2248
+ commit: (raw) => {
2249
+ const trimmed = raw.trim();
2250
+ if (trimmed === "") {
2251
+ setTextMode(false);
2252
+ return onCommit(void 0, "MANUAL");
2253
+ }
2254
+ onCommit(hasExpressions(trimmed) ? trimmed : localInputToIso(trimmed));
2255
+ }
2256
+ })
2257
+ });
2258
+ return /* @__PURE__ */ jsx(FieldShell, {
2259
+ htmlFor: fieldId,
2260
+ prop,
2261
+ invalid,
2262
+ picker,
2263
+ children: /* @__PURE__ */ jsx("input", {
2264
+ id: fieldId,
2265
+ type: "datetime-local",
2266
+ className: `${textInputClass} ${invalid ? invalidClass : ""}`,
2267
+ defaultValue: isoToLocalInput(value),
2268
+ onFocus: field.focus,
2269
+ onBlur: (event) => onCommit(localInputToIso(event.target.value))
2270
+ })
2271
+ });
2272
+ case "STATIC_DROPDOWN": {
2273
+ const options = prop.staticOptions ?? [];
2274
+ if (prop.display === "cards") return /* @__PURE__ */ jsx(FieldShell, {
2275
+ htmlFor: fieldId,
2276
+ prop,
2277
+ invalid,
2278
+ children: /* @__PURE__ */ jsx(OptionCards, {
2279
+ id: fieldId,
2280
+ options,
2281
+ value,
2282
+ keyOf: stringifyValue,
2283
+ onChange: onCommit,
2284
+ invalid,
2285
+ clearable: !prop.required
2286
+ })
2287
+ });
2288
+ if (!prop.staticDisabled && prop.required !== true && prop.defaultValue !== void 0 && options.length >= 2 && options.length <= 3 && options.every((option) => option.label.length <= 22)) return /* @__PURE__ */ jsx(FieldShell, {
2289
+ htmlFor: fieldId,
2290
+ prop,
2291
+ invalid: false,
2292
+ children: /* @__PURE__ */ jsx(Segmented, {
2293
+ value: stringifyValue(value),
2294
+ options: options.map((option) => ({
2295
+ value: stringifyValue(option.value),
2296
+ label: option.label
2297
+ })),
2298
+ onChange: (key) => onCommit(options.find((option) => stringifyValue(option.value) === key)?.value ?? key)
2299
+ })
2300
+ });
2301
+ return /* @__PURE__ */ jsx(FieldShell, {
2302
+ htmlFor: fieldId,
2303
+ prop,
2304
+ invalid,
2305
+ children: /* @__PURE__ */ jsx(OptionSelect, {
2306
+ id: fieldId,
2307
+ options: prop.staticOptions ?? [],
2308
+ value,
2309
+ onChange: onCommit,
2310
+ invalid,
2311
+ placeholder: prop.staticPlaceholder ?? prop.placeholder,
2312
+ disabled: prop.staticDisabled && isEmptyValue(value),
2313
+ clearable: !prop.required
2314
+ })
2315
+ });
2316
+ }
2317
+ case "STATIC_MULTI_SELECT_DROPDOWN": return /* @__PURE__ */ jsx(FieldShell, {
2318
+ htmlFor: fieldId,
2319
+ prop,
2320
+ invalid,
2321
+ children: /* @__PURE__ */ jsx(OptionList, {
2322
+ id: fieldId,
2323
+ options: prop.staticOptions ?? [],
2324
+ selected: Array.isArray(value) ? value : [],
2325
+ onChange: (next) => onCommit(next.length > 0 ? next : void 0),
2326
+ invalid
2327
+ })
2328
+ });
2329
+ case "DROPDOWN": {
2330
+ if (textMode) return /* @__PURE__ */ jsx(FieldShell, {
2331
+ htmlFor: fieldId,
2332
+ prop,
2333
+ invalid,
2334
+ picker: /* @__PURE__ */ jsxs(Fragment$1, { children: [picker, /* @__PURE__ */ jsx(ModeButton, {
2335
+ label: "Pick from list",
2336
+ onClick: () => {
2337
+ if (hasExpressions(value)) {
2338
+ setTextMode(false);
2339
+ onCommit(void 0, "MANUAL");
2340
+ } else toMode(false);
2341
+ }
2342
+ })] }),
2343
+ children: textInput({
2344
+ mono: true,
2345
+ placeholder: "{{steps.…}} or an id",
2346
+ commit: (raw) => onCommit(raw.trim() === "" ? void 0 : raw)
2347
+ })
2348
+ });
2349
+ const result = searchResult ?? (dropdown.state.kind === "ready" ? dropdown.state.result : null);
2350
+ const listed = result?.options ?? [];
2351
+ const options = picked !== null && stringifyValue(picked.value) === stringifyValue(value) && !listed.some((option) => stringifyValue(option.value) === stringifyValue(value)) ? [...listed, picked] : listed;
2352
+ return /* @__PURE__ */ jsx(FieldShell, {
2353
+ htmlFor: fieldId,
2354
+ prop,
2355
+ invalid,
2356
+ error: loadError(dropdown.state),
2357
+ picker: optionsUnavailable ? /* @__PURE__ */ jsx(AvailableSoon, {}) : picker,
2358
+ children: /* @__PURE__ */ jsx(OptionSelect, {
2359
+ id: fieldId,
2360
+ options,
2361
+ value,
2362
+ onChange: (next) => {
2363
+ setPicked(listed.find((option) => stringifyValue(option.value) === stringifyValue(next)) ?? null);
2364
+ onCommit(next);
2365
+ },
2366
+ invalid,
2367
+ loading: dropdown.state.kind === "loading",
2368
+ disabled: result?.disabled && !stringifyValue(value) || optionsUnavailable,
2369
+ onRefresh: dynamicLoad ? dropdown.reload : void 0,
2370
+ clearable: !prop.required,
2371
+ searchable: true,
2372
+ onQueryChange: onSearch,
2373
+ actions: [{
2374
+ label: "Use data from an earlier step",
2375
+ icon: "braces",
2376
+ onSelect: () => {
2377
+ toMode(true);
2378
+ field.focus();
2379
+ }
2380
+ }],
2381
+ emptyText: result?.placeholder ?? "Nothing to choose from yet. Some lists need a connection first.",
2382
+ placeholder: optionsUnavailable ? "Options for nested fields are available soon" : dropdown.syncing ? "Waiting for the Switchboard…" : result?.placeholder ?? prop.placeholder ?? "Choose…"
2383
+ })
2384
+ });
2385
+ }
2386
+ case "MULTI_SELECT_DROPDOWN": {
2387
+ const result = dropdown.state.kind === "ready" ? dropdown.state.result : null;
2388
+ const selected = Array.isArray(value) ? value : [];
2389
+ const listed = new Set((result?.options ?? []).map((o) => stringifyValue(o.value)));
2390
+ const extra = selected.filter((entry) => !listed.has(stringifyValue(entry))).map((entry) => ({
2391
+ label: stringifyValue(entry),
2392
+ value: entry
2393
+ }));
2394
+ return /* @__PURE__ */ jsx(FieldShell, {
2395
+ htmlFor: fieldId,
2396
+ prop,
2397
+ invalid,
2398
+ error: loadError(dropdown.state),
2399
+ picker: optionsUnavailable ? /* @__PURE__ */ jsx(AvailableSoon, {}) : void 0,
2400
+ children: optionsUnavailable ? /* @__PURE__ */ jsx("p", {
2401
+ className: "text-xs text-muted-foreground",
2402
+ children: "Options for nested fields are available soon."
2403
+ }) : /* @__PURE__ */ jsx(OptionList, {
2404
+ id: fieldId,
2405
+ options: [...extra, ...result?.options ?? []],
2406
+ selected,
2407
+ onChange: (next) => onCommit(next.length > 0 ? next : void 0),
2408
+ invalid,
2409
+ loading: dropdown.state.kind === "loading",
2410
+ onRefresh: dynamicLoad ? dropdown.reload : void 0,
2411
+ placeholder: result?.placeholder ?? prop.placeholder
2412
+ })
2413
+ });
2414
+ }
2415
+ case "DYNAMIC": {
2416
+ const fields = dynamic.state.kind === "ready" ? dynamic.state.result : null;
2417
+ const record = value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
2418
+ return /* @__PURE__ */ jsx(FieldShell, {
2419
+ htmlFor: fieldId,
2420
+ prop,
2421
+ invalid: invalid && fields !== null && fields.length > 0,
2422
+ error: loadError(dynamic.state),
2423
+ picker: optionsUnavailable ? /* @__PURE__ */ jsx(AvailableSoon, {}) : dynamicLoad ? retryButton(dynamic.state, dynamic.reload) : void 0,
2424
+ children: optionsUnavailable ? /* @__PURE__ */ jsx("p", {
2425
+ className: "text-xs text-muted-foreground",
2426
+ children: "Nested dynamic properties are available soon."
2427
+ }) : dynamic.state.kind === "loading" && !fields ? /* @__PURE__ */ jsx("p", {
2428
+ className: "text-xs text-muted-foreground",
2429
+ children: "Resolving properties…"
2430
+ }) : !dynamicLoad ? /* @__PURE__ */ jsx("p", {
2431
+ className: "text-xs text-muted-foreground",
2432
+ children: "Properties resolve once the runtime is reachable."
2433
+ }) : fields && fields.length > 0 ? /* @__PURE__ */ jsx("div", {
2434
+ className: "rounded-lg border border-solid border-foreground/10 bg-muted/40 p-3",
2435
+ children: /* @__PURE__ */ jsx(PropertyForm, {
2436
+ props: fields,
2437
+ value: record,
2438
+ onChange: (next) => onCommit(Object.keys(next).length > 0 ? next : void 0),
2439
+ scopeStepId: props.scopeStepId,
2440
+ nested: true
2441
+ })
2442
+ }) : fields ? /* @__PURE__ */ jsx("p", {
2443
+ className: "text-xs text-muted-foreground",
2444
+ children: props.waitingOn ? `Pick ${props.waitingOn} first; its fields show here.` : "No properties for the current selection."
2445
+ }) : null
2446
+ });
2447
+ }
2448
+ case "ARRAY": {
2449
+ if (prop.properties && prop.properties.length > 0) return /* @__PURE__ */ jsx(FieldShell, {
2450
+ htmlFor: fieldId,
2451
+ prop,
2452
+ invalid,
2453
+ children: /* @__PURE__ */ jsx(ArrayRows, {
2454
+ prop,
2455
+ value,
2456
+ onCommit,
2457
+ scopeStepId: props.scopeStepId,
2458
+ invalid
2459
+ })
2460
+ });
2461
+ if (textMode) return /* @__PURE__ */ jsx(FieldShell, {
2462
+ htmlFor: fieldId,
2463
+ prop,
2464
+ invalid,
2465
+ picker: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(ExpressionPickerButton, {
2466
+ active: field.active,
2467
+ onFocusField: field.focus
2468
+ }), /* @__PURE__ */ jsx(ModeButton, {
2469
+ label: "Enter items",
2470
+ onClick: () => {
2471
+ setTextMode(false);
2472
+ const bound = stringifyValue(value).trim();
2473
+ onCommit(bound ? [bound] : void 0, "MANUAL");
2474
+ }
2475
+ })] }),
2476
+ children: textInput({
2477
+ mono: true,
2478
+ placeholder: "{{steps.…}} yielding a list",
2479
+ commit: (raw) => onCommit(raw.trim() === "" ? void 0 : raw.trim(), "EXPRESSION")
2480
+ })
2481
+ });
2482
+ const lines = Array.isArray(value) ? value.map((item) => stringifyValue(item)).join("\n") : stringifyValue(value);
2483
+ return /* @__PURE__ */ jsxs(FieldShell, {
2484
+ htmlFor: fieldId,
2485
+ prop,
2486
+ invalid,
2487
+ picker: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(ExpressionPickerButton, {
2488
+ active: field.active,
2489
+ onFocusField: field.focus
2490
+ }), /* @__PURE__ */ jsx(ModeButton, {
2491
+ label: "Bind the whole list",
2492
+ onClick: () => {
2493
+ setTextMode(true);
2494
+ onCommit(void 0, "EXPRESSION");
2495
+ }
2496
+ })] }),
2497
+ children: [/* @__PURE__ */ jsx("textarea", {
2498
+ id: fieldId,
2499
+ ref: fieldRef,
2500
+ className: `${textAreaClass} font-mono text-xs ${invalid ? invalidClass : ""}`,
2501
+ defaultValue: lines,
2502
+ placeholder: prop.placeholder ?? "One item per line",
2503
+ spellCheck: false,
2504
+ onFocus: field.focus,
2505
+ onChange: (event) => setDraft(event.target.value),
2506
+ onBlur: (event) => {
2507
+ const items = event.target.value.split("\n").map((line) => line.trim()).filter((line) => line !== "");
2508
+ if (items.length === 0) return onCommit(void 0);
2509
+ onCommit(items);
2510
+ }
2511
+ }), /* @__PURE__ */ jsx(ExpressionTokenLine, { value: draft })]
2512
+ });
2513
+ }
2514
+ case "OBJECT":
2515
+ if (textMode) return /* @__PURE__ */ jsx(FieldShell, {
2516
+ htmlFor: fieldId,
2517
+ prop,
2518
+ invalid,
2519
+ picker,
2520
+ children: textInput({
2521
+ mono: true,
2522
+ placeholder: "{{expression}} yielding an object",
2523
+ commit: (raw) => {
2524
+ const trimmed = raw.trim();
2525
+ if (trimmed === "") {
2526
+ setTextMode(false);
2527
+ return onCommit(void 0, "MANUAL");
2528
+ }
2529
+ onCommit(trimmed);
2530
+ }
2531
+ })
2532
+ });
2533
+ return /* @__PURE__ */ jsx(FieldShell, {
2534
+ htmlFor: fieldId,
2535
+ prop,
2536
+ invalid,
2537
+ picker,
2538
+ children: /* @__PURE__ */ jsx(ObjectRows, {
2539
+ value: value !== null && typeof value === "object" && !Array.isArray(value) ? value : {},
2540
+ onCommit,
2541
+ invalid
2542
+ })
2543
+ });
2544
+ case "DATE_RANGE": return /* @__PURE__ */ jsx(FieldShell, {
2545
+ htmlFor: fieldId,
2546
+ prop,
2547
+ invalid,
2548
+ children: /* @__PURE__ */ jsx(DateRangeField, {
2549
+ id: fieldId,
2550
+ value,
2551
+ dropdown: prop.display === "dropdown",
2552
+ invalid,
2553
+ clearable: !prop.required,
2554
+ onCommit
2555
+ })
2556
+ });
2557
+ case "COLOR": return /* @__PURE__ */ jsx(FieldShell, {
2558
+ htmlFor: fieldId,
2559
+ prop,
2560
+ invalid,
2561
+ picker,
2562
+ children: /* @__PURE__ */ jsx(ColorField, {
2563
+ id: fieldId,
2564
+ value,
2565
+ invalid,
2566
+ onCommit,
2567
+ onFocus: field.focus
2568
+ })
2569
+ });
2570
+ case "RICH_TEXT":
2571
+ case "LONG_TEXT":
2572
+ case "CUSTOM":
2573
+ case "JSON": {
2574
+ const isJson = prop.type === "JSON" || prop.type === "CUSTOM";
2575
+ const mode = prop.type === "RICH_TEXT" ? richTextMode(prop.formatProperty ? props.config?.[prop.formatProperty] : "") : null;
2576
+ return /* @__PURE__ */ jsxs(FieldShell, {
2577
+ htmlFor: fieldId,
2578
+ prop,
2579
+ invalid,
2580
+ picker: mode ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
2581
+ className: "rounded bg-muted px-1.5 text-[11px] text-muted-foreground",
2582
+ children: mode === "html" ? "HTML" : mode === "markdown" ? "Markdown" : "Plain text"
2583
+ }), picker] }) : picker,
2584
+ error: jsonError,
2585
+ children: [/* @__PURE__ */ jsx("textarea", {
2586
+ id: fieldId,
2587
+ ref: fieldRef,
2588
+ className: `${textAreaClass} ${isJson || mode === "html" || prop.display === "code" ? "font-mono text-xs" : ""} ${mode ? "min-h-32" : ""} ${invalid ? invalidClass : ""}`,
2589
+ defaultValue: stringifyValue(value),
2590
+ placeholder: prop.placeholder,
2591
+ spellCheck: false,
2592
+ onFocus: field.focus,
2593
+ onChange: (event) => setDraft(event.target.value),
2594
+ onBlur: (event) => {
2595
+ const raw = event.target.value;
2596
+ if (!isJson) return onCommit(raw === "" ? void 0 : raw);
2597
+ const trimmed = raw.trim();
2598
+ if (trimmed === "") {
2599
+ setJsonError(null);
2600
+ return onCommit(void 0);
2601
+ }
2602
+ if (WHOLE_EXPRESSION.test(trimmed)) {
2603
+ setJsonError(null);
2604
+ return onCommit(trimmed);
2605
+ }
2606
+ try {
2607
+ onCommit(JSON.parse(trimmed));
2608
+ setJsonError(null);
2609
+ } catch {
2610
+ setJsonError("Not valid JSON, so it wasn't saved.");
2611
+ }
2612
+ }
2613
+ }), /* @__PURE__ */ jsx(ExpressionTokenLine, { value: draft })]
2614
+ });
2615
+ }
2616
+ default: return /* @__PURE__ */ jsxs(FieldShell, {
2617
+ htmlFor: fieldId,
2618
+ prop,
2619
+ invalid,
2620
+ picker,
2621
+ children: [prop.emptyChoice && value === "" ? null : textInput({ commit: (raw) => onCommit(raw === "" ? void 0 : raw) }), prop.emptyChoice ? /* @__PURE__ */ jsxs("label", {
2622
+ className: "mt-1.5 flex items-center gap-2 text-xs text-muted-foreground",
2623
+ children: [/* @__PURE__ */ jsx("input", {
2624
+ type: "checkbox",
2625
+ className: "h-3.5 w-3.5 accent-current",
2626
+ checked: value === "",
2627
+ onChange: (event) => onCommit(event.target.checked ? "" : void 0, "MANUAL")
2628
+ }), prop.emptyChoice]
2629
+ }) : null]
2630
+ });
2631
+ }
2632
+ }
2633
+ const NO_BLOCK = {
2634
+ pieceName: "",
2635
+ pieceVersion: "",
2636
+ kind: "action",
2637
+ name: ""
2638
+ };
2639
+ function PropertyForm(props) {
2640
+ const echo = usePendingEcho({
2641
+ value: props.value,
2642
+ settings: props.settings ?? null
2643
+ }, (next, shown) => {
2644
+ if (next.settings !== shown.settings) props.onChange(next.value, next.settings ?? []);
2645
+ else props.onChange(next.value);
2646
+ });
2647
+ const { value: current, settings } = echo.value;
2648
+ const tracksSettings = props.writesSettings === true;
2649
+ const readDynamic = useDynamicCache();
2650
+ const withResolvedSchemas = (list, config) => {
2651
+ let next = list;
2652
+ for (const prop of props.props) {
2653
+ if (prop.type !== "DYNAMIC") continue;
2654
+ if (settingFor(next, prop.name)?.mode === "EXPRESSION") continue;
2655
+ const fields = readDynamic(resolverInputFor(props.block ?? NO_BLOCK, prop, config, props.connectionId, props.reactorConnectionId));
2656
+ if (!fields) continue;
2657
+ const schema = stripOptions(fields);
2658
+ const stored = settingFor(next, prop.name)?.schema ?? null;
2659
+ if (JSON.stringify(stored) === JSON.stringify(schema)) continue;
2660
+ next = withSetting(next, prop.name, { schema });
2661
+ }
2662
+ return next;
2663
+ };
2664
+ const commitField = (name, value, mode) => {
2665
+ const next = { ...current };
2666
+ if (value === void 0) delete next[name];
2667
+ else next[name] = value;
2668
+ let nextSettings = settings;
2669
+ const nextMode = mode ?? settingFor(settings, name)?.mode ?? "MANUAL";
2670
+ if (tracksSettings && settingFor(settings, name)?.mode !== nextMode) nextSettings = withSetting(nextSettings, name, { mode: nextMode });
2671
+ if (value !== current[name]) for (const dependent of props.props) {
2672
+ if (!dependent.refreshers?.includes(name)) continue;
2673
+ if (isDropdownType(dependent.type)) delete next[dependent.name];
2674
+ if (tracksSettings && dependent.type === "DYNAMIC" && settingFor(nextSettings, dependent.name)?.schema != null) nextSettings = withSetting(nextSettings, dependent.name, { schema: null });
2675
+ }
2676
+ if (tracksSettings) nextSettings = withResolvedSchemas(nextSettings, next);
2677
+ echo.commit({
2678
+ value: next,
2679
+ settings: nextSettings
2680
+ });
2681
+ };
2682
+ const setMode = (name, mode) => {
2683
+ if (!tracksSettings || settingFor(settings, name)?.mode === mode) return;
2684
+ echo.commit({
2685
+ value: current,
2686
+ settings: withResolvedSchemas(withSetting(settings, name, { mode }), current)
2687
+ });
2688
+ };
2689
+ const visible = props.props.filter((prop) => isPropVisible(prop, current));
2690
+ const essential = visible.filter((prop) => !prop.advanced);
2691
+ const advanced = visible.filter((prop) => prop.advanced);
2692
+ const [showAdvanced, setShowAdvanced] = useState(false);
2693
+ const advancedSet = advanced.filter((prop) => current[prop.name] !== void 0).length;
2694
+ const field = (prop) => /* @__PURE__ */ jsx(PropField, {
2695
+ prop,
2696
+ value: current[prop.name],
2697
+ onCommit: (value, mode) => commitField(prop.name, value, mode),
2698
+ mode: settingFor(settings, prop.name)?.mode,
2699
+ onMode: (mode) => setMode(prop.name, mode),
2700
+ loadOptions: props.loadOptions ? (propName, searchValue) => props.loadOptions(propName, current, searchValue) : void 0,
2701
+ config: current,
2702
+ secrets: props.secrets,
2703
+ scopeStepId: props.scopeStepId,
2704
+ optionsBlocked: props.optionsBlocked,
2705
+ explainOptionsError: props.explainOptionsError,
2706
+ resolverInput: resolverInputFor(props.block ?? NO_BLOCK, prop, current, props.connectionId, props.reactorConnectionId),
2707
+ waitingOn: props.props.find((sibling) => prop.refreshers?.includes(sibling.name) && isEmptyValue(current[sibling.name]))?.displayName,
2708
+ nested: props.nested,
2709
+ webhookUrl: props.webhookUrl
2710
+ }, prop.name);
2711
+ return /* @__PURE__ */ jsxs("div", {
2712
+ className: `flex flex-col ${props.nested ? "gap-3" : "gap-5"}`,
2713
+ onBlur: echo.onBlur,
2714
+ children: [/* @__PURE__ */ jsx(PropLayout, {
2715
+ props: essential,
2716
+ groups: props.groups,
2717
+ values: current,
2718
+ renderField: field,
2719
+ onCommit: commitField
2720
+ }), advanced.length > 0 ? /* @__PURE__ */ jsxs("div", {
2721
+ className: "flex flex-col gap-5 border-t border-solid border-foreground/10 pt-4",
2722
+ children: [/* @__PURE__ */ jsxs("button", {
2723
+ type: "button",
2724
+ className: "-mx-1 flex items-center gap-1.5 self-start rounded px-1 text-[13px] font-medium text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40",
2725
+ "aria-expanded": showAdvanced,
2726
+ onClick: () => setShowAdvanced((open) => !open),
2727
+ children: [
2728
+ /* @__PURE__ */ jsx(Icon, {
2729
+ name: "chevron",
2730
+ className: `h-3.5 w-3.5 transition-transform ${showAdvanced ? "rotate-90" : ""}`
2731
+ }),
2732
+ "More options",
2733
+ /* @__PURE__ */ jsx("span", {
2734
+ className: "font-normal",
2735
+ children: advancedSet > 0 ? `${advanced.length} fields, ${advancedSet} set` : `${advanced.length} fields`
2736
+ })
2737
+ ]
2738
+ }), /* @__PURE__ */ jsx("div", {
2739
+ hidden: !showAdvanced,
2740
+ className: "flex flex-col gap-5",
2741
+ children: /* @__PURE__ */ jsx(PropLayout, {
2742
+ props: advanced,
2743
+ groups: props.groups,
2744
+ values: current,
2745
+ renderField: field,
2746
+ onCommit: commitField
2747
+ })
2748
+ })]
2749
+ }) : null]
2750
+ });
2751
+ }
2752
+ //#endregion
2753
+ //#region editors/shared/document-ref.tsx
2754
+ const SHOWN = 3;
2755
+ function shortId(id) {
2756
+ return id.length > 16 ? `${id.slice(0, 6)}…${id.slice(-6)}` : id;
2757
+ }
2758
+ function revisionText(reference) {
2759
+ const scopes = Object.entries(reference.revision).map(([scope, count]) => `${scope} ${count}`).join(" · ");
2760
+ return reference.branch === "main" ? scopes : `${reference.branch}: ${scopes}`;
2761
+ }
2762
+ function DocumentRefRow(props) {
2763
+ const { reference } = props;
2764
+ const setSelectedNode = useSetSelectedNode();
2765
+ return /* @__PURE__ */ jsxs("li", {
2766
+ "aria-label": `Document ${reference.documentId}`,
2767
+ className: "flex items-center gap-2",
2768
+ children: [/* @__PURE__ */ jsxs("div", {
2769
+ className: "min-w-0 flex-1 text-xs",
2770
+ children: [/* @__PURE__ */ jsxs("div", {
2771
+ className: "flex min-w-0 items-baseline gap-1.5",
2772
+ children: [/* @__PURE__ */ jsx("span", {
2773
+ className: "truncate font-medium text-foreground",
2774
+ children: reference.documentType
2775
+ }), /* @__PURE__ */ jsx("span", {
2776
+ className: "shrink-0 font-mono text-[11px] text-muted-foreground",
2777
+ title: reference.documentId,
2778
+ children: shortId(reference.documentId)
2779
+ })]
2780
+ }), /* @__PURE__ */ jsxs("div", {
2781
+ className: "truncate text-[11px] text-muted-foreground",
2782
+ children: ["Revision ", revisionText(reference)]
2783
+ })]
2784
+ }), /* @__PURE__ */ jsx(Button, {
2785
+ size: "sm",
2786
+ onClick: () => setSelectedNode(reference.documentId),
2787
+ "aria-label": `Open document ${reference.documentId}`,
2788
+ children: "Open document"
2789
+ })]
2790
+ });
2791
+ }
2792
+ function DocumentRefs(props) {
2793
+ const { references } = props;
2794
+ const hidden = references.length - SHOWN;
2795
+ return /* @__PURE__ */ jsxs("div", {
2796
+ role: "group",
2797
+ "aria-label": "Document references",
2798
+ className: "flex flex-col gap-1.5",
2799
+ children: [
2800
+ /* @__PURE__ */ jsx("ul", {
2801
+ className: "m-0 flex list-none flex-col gap-1.5 p-0",
2802
+ children: references.slice(0, SHOWN).map((reference, index) => /* @__PURE__ */ jsx(DocumentRefRow, { reference }, `${reference.documentId}-${index}`))
2803
+ }),
2804
+ hidden > 0 ? /* @__PURE__ */ jsxs("p", {
2805
+ className: "text-[11px] text-muted-foreground",
2806
+ children: [
2807
+ "and ",
2808
+ hidden,
2809
+ " more in the data below"
2810
+ ]
2811
+ }) : null,
2812
+ /* @__PURE__ */ jsx("p", {
2813
+ className: "text-[11px] text-muted-foreground",
2814
+ children: "The run kept a reference, not the state. Opening shows the document as it is now: past revisions can't be read yet (#3179)."
2815
+ })
2816
+ ]
2817
+ });
2818
+ }
2819
+ //#endregion
2820
+ //#region editors/shared/data-viewer.tsx
2821
+ const DataTree = lazy(() => import("./data-tree-CjWQllC7.js"));
2822
+ function stringify(value) {
2823
+ try {
2824
+ return JSON.stringify(value, null, 2) ?? "";
2825
+ } catch {
2826
+ return String(value);
2827
+ }
2828
+ }
2829
+ function isEmpty(value) {
2830
+ if (value === void 0 || value === null) return true;
2831
+ if (typeof value === "object") return Object.keys(value).length === 0;
2832
+ return false;
2833
+ }
2834
+ function RawJson(props) {
2835
+ return /* @__PURE__ */ jsx("pre", {
2836
+ className: "max-h-72 overflow-auto whitespace-pre-wrap break-words font-mono text-xs text-foreground",
2837
+ children: props.text
2838
+ });
2839
+ }
2840
+ function TreeSkeleton() {
2841
+ return /* @__PURE__ */ jsx("div", {
2842
+ role: "status",
2843
+ "aria-label": "Loading data",
2844
+ className: "flex animate-pulse flex-col gap-2 py-1",
2845
+ children: [
2846
+ "w-2/5",
2847
+ "w-3/5",
2848
+ "w-1/2",
2849
+ "w-1/3"
2850
+ ].map((width, index) => /* @__PURE__ */ jsx("span", {
2851
+ className: `h-2.5 rounded bg-muted ${width}`,
2852
+ style: { marginLeft: index === 0 ? 0 : 16 }
2853
+ }, width))
2854
+ });
2855
+ }
2856
+ function DataViewer(props) {
2857
+ const [raw, setRaw] = useState(false);
2858
+ const [copied, setCopied] = useState(false);
2859
+ const empty = isEmpty(props.value);
2860
+ const text = stringify(props.value);
2861
+ const tree = typeof props.value === "object" && props.value !== null;
2862
+ const references = tree ? documentRefsIn(props.value) : [];
2863
+ const treeValue = isDocumentRefMarker(props.value) ? Object.fromEntries(Object.entries(props.value).filter(([key]) => key !== DOCUMENT_REF_KEY)) : props.value;
2864
+ return /* @__PURE__ */ jsxs("section", {
2865
+ "aria-label": props.label,
2866
+ className: "min-w-0 rounded-md border border-solid border-border bg-card",
2867
+ children: [/* @__PURE__ */ jsxs("header", {
2868
+ className: "flex h-8 items-center gap-1 border-b border-solid border-border pl-3 pr-1",
2869
+ children: [
2870
+ /* @__PURE__ */ jsx("h4", {
2871
+ className: "mr-auto text-xs font-medium text-foreground",
2872
+ children: props.label
2873
+ }),
2874
+ !empty && tree ? /* @__PURE__ */ jsx("button", {
2875
+ type: "button",
2876
+ "aria-pressed": raw,
2877
+ className: "rounded px-1.5 py-0.5 text-[11px] text-muted-foreground hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40",
2878
+ onClick: () => setRaw((value) => !value),
2879
+ children: raw ? "Tree" : "JSON"
2880
+ }) : null,
2881
+ !empty ? /* @__PURE__ */ jsx(IconButton, {
2882
+ icon: copied ? "check" : "copy",
2883
+ label: `Copy ${props.label.toLowerCase()} as JSON`,
2884
+ onClick: () => {
2885
+ navigator.clipboard.writeText(text).then(() => {
2886
+ setCopied(true);
2887
+ setTimeout(() => setCopied(false), 1500);
2888
+ });
2889
+ }
2890
+ }) : null
2891
+ ]
2892
+ }), /* @__PURE__ */ jsx("div", {
2893
+ className: "px-3 py-2",
2894
+ children: empty ? /* @__PURE__ */ jsx("p", {
2895
+ className: "text-xs text-muted-foreground",
2896
+ children: props.emptyText ?? "Nothing"
2897
+ }) : !tree ? /* @__PURE__ */ jsx("p", {
2898
+ className: "break-words font-mono text-xs text-foreground",
2899
+ children: text
2900
+ }) : raw ? /* @__PURE__ */ jsx(RawJson, { text }) : /* @__PURE__ */ jsxs("div", {
2901
+ className: "flex flex-col gap-2",
2902
+ children: [references.length > 0 ? /* @__PURE__ */ jsx(DocumentRefs, { references }) : null, isEmpty(treeValue) ? null : /* @__PURE__ */ jsx("div", {
2903
+ className: "max-h-72 overflow-auto",
2904
+ children: /* @__PURE__ */ jsx(Suspense, {
2905
+ fallback: /* @__PURE__ */ jsx(TreeSkeleton, {}),
2906
+ children: /* @__PURE__ */ jsx(DataTree, {
2907
+ value: treeValue,
2908
+ root: props.root
2909
+ })
2910
+ })
2911
+ })]
2912
+ })
2913
+ })]
2914
+ });
2915
+ }
2916
+ //#endregion
2917
+ //#region editors/workflow-editor/ui/trigger-text.ts
2918
+ const WEEKDAYS = [
2919
+ "Sunday",
2920
+ "Monday",
2921
+ "Tuesday",
2922
+ "Wednesday",
2923
+ "Thursday",
2924
+ "Friday",
2925
+ "Saturday"
2926
+ ];
2927
+ const UNIT_LABEL = {
2928
+ minutes: ["minute", "minutes"],
2929
+ hours: ["hour", "hours"],
2930
+ days: ["day", "days"]
2931
+ };
2932
+ function isInt(field) {
2933
+ return /^\d+$/.test(field);
2934
+ }
2935
+ function clock(hour, minute) {
2936
+ return `${hour.padStart(2, "0")}:${minute.padStart(2, "0")}`;
2937
+ }
2938
+ function dayList(field) {
2939
+ if (field === "1-5") return "on weekdays";
2940
+ if (field === "0,6" || field === "6,0") return "at weekends";
2941
+ const days = field.split(",");
2942
+ if (!days.every((day) => isInt(day) && Number(day) <= 7)) return void 0;
2943
+ const names = days.map((day) => WEEKDAYS[Number(day) % 7]);
2944
+ if (names.length === 1) return `every ${names[0]}`;
2945
+ return `on ${names.slice(0, -1).join(", ")} and ${names[names.length - 1]}`;
2946
+ }
2947
+ /** Describes a five-field cron expression, or returns undefined. */
2948
+ function describeCron(cron) {
2949
+ const fields = cron.trim().split(/\s+/);
2950
+ if (fields.length !== 5) return void 0;
2951
+ const [minute, hour, dayOfMonth, month, dayOfWeek] = fields;
2952
+ if (month !== "*") return void 0;
2953
+ const everyMinutes = /^\*\/(\d+)$/.exec(minute);
2954
+ if (everyMinutes && hour === "*" && dayOfMonth === "*" && dayOfWeek === "*") {
2955
+ const n = Number(everyMinutes[1]);
2956
+ return n === 1 ? "Every minute" : `Every ${n} minutes`;
2957
+ }
2958
+ if (minute === "*" && hour === "*" && dayOfMonth === "*" && dayOfWeek === "*") return "Every minute";
2959
+ if (isInt(minute) && hour === "*" && dayOfMonth === "*" && dayOfWeek === "*") return minute === "0" ? "Every hour, on the hour" : `Every hour at ${minute.padStart(2, "0")} past`;
2960
+ const everyHours = /^\*\/(\d+)$/.exec(hour);
2961
+ if (isInt(minute) && everyHours && dayOfMonth === "*" && dayOfWeek === "*") return `Every ${everyHours[1]} hours`;
2962
+ if (!isInt(minute) || !isInt(hour)) return void 0;
2963
+ const at = clock(hour, minute);
2964
+ if (dayOfMonth === "*" && dayOfWeek === "*") return `Every day at ${at}`;
2965
+ if (dayOfMonth === "*") {
2966
+ const days = dayList(dayOfWeek);
2967
+ return days ? `${days.charAt(0).toUpperCase()}${days.slice(1)} at ${at}` : void 0;
2968
+ }
2969
+ if (isInt(dayOfMonth) && dayOfWeek === "*") return `Every month on day ${dayOfMonth} at ${at}`;
2970
+ }
2971
+ function describeSchedule(config) {
2972
+ let schedule;
2973
+ try {
2974
+ schedule = parseScheduleConfig(config);
2975
+ } catch {
2976
+ return "On a schedule that does not parse";
2977
+ }
2978
+ if (schedule.mode === "interval") {
2979
+ const unit = UNIT_LABEL[schedule.unit];
2980
+ return schedule.every === 1 ? `Every ${unit[0]}` : `Every ${schedule.every} ${unit[1]}`;
2981
+ }
2982
+ const described = describeCron(schedule.cron);
2983
+ return described ? `${described} ${schedule.timezone}` : `On schedule ${schedule.cron}`;
2984
+ }
2985
+ function literal(config, key) {
2986
+ if (!config || typeof config !== "object") return void 0;
2987
+ const value = config[key];
2988
+ if (typeof value !== "string") return void 0;
2989
+ const text = value.trim();
2990
+ return text && !text.includes("{{") ? text : void 0;
2991
+ }
2992
+ function documentTypeLabel(documentType) {
2993
+ return (documentType.split("/").pop() ?? documentType).split(/[-_\s]+/).filter(Boolean).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
2994
+ }
2995
+ function actionTypeLabel(actionType) {
2996
+ const text = actionType.toLowerCase().split(/[_\s]+/).filter(Boolean).join(" ");
2997
+ return text.charAt(0).toUpperCase() + text.slice(1);
2998
+ }
2999
+ /** Describes a reactor document trigger by what it filters on. */
3000
+ function describeDocumentTrigger(triggerName, config) {
3001
+ const documentType = literal(config, "documentType");
3002
+ const label = documentType ? documentTypeLabel(documentType) : "";
3003
+ const subject = label ? `${/^[AEIOU]/.test(label) ? "an" : "a"} ${label}` : literal(config, "documentId") ? "its document" : "a document";
3004
+ switch (triggerName) {
3005
+ case "document-event": {
3006
+ const actionType = literal(config, "actionType");
3007
+ return actionType ? `When ${actionTypeLabel(actionType)} runs on ${subject}` : `When ${subject} changes`;
3008
+ }
3009
+ case "document-created": return `When ${subject} is created`;
3010
+ case "document-deleted": return `When ${subject} is deleted`;
3011
+ default: return;
3012
+ }
3013
+ }
3014
+ /** When a workflow starts, from its trigger. */
3015
+ function describeTrigger(trigger) {
3016
+ if (!trigger) return "Never starts: no trigger";
3017
+ const block = {
3018
+ pieceName: trigger.pieceName,
3019
+ kind: "trigger",
3020
+ name: trigger.triggerName
3021
+ };
3022
+ switch (blockKey(block)) {
3023
+ case blockKey(MANUAL_TRIGGER): return "Manual";
3024
+ case blockKey(WEBHOOK_TRIGGER): return "When its webhook is called";
3025
+ case blockKey(SCHEDULE_TRIGGER): return describeSchedule(trigger.config);
3026
+ default: {
3027
+ if (trigger.pieceName === "@powerhousedao/piece-reactor") {
3028
+ const described = describeDocumentTrigger(trigger.triggerName, trigger.config);
3029
+ if (described) return described;
3030
+ }
3031
+ const meta = blockMeta(block);
3032
+ const piece = meta.subtitle.replace(/ · Trigger$/, "");
3033
+ return `${meta.displayName} in ${piece}`;
3034
+ }
3035
+ }
3036
+ }
3037
+ //#endregion
3038
+ export { VARIABLE_TYPE_LABEL as A, lacksDefaults as B, useExpressionField as C, EMPTY_SCOPE as D, menuPosition as E, stateFieldsFromSdl as F, STEP_PARAM as I, VARIABLES_VIEW as L, parseTypedValue as M, valueMismatch as N, buildExpressionScope as O, documentShape as P, hasDraftChanges as R, ExpressionTokenLine as S, menuHeight as T, withPropDefaults as V, usePublish as _, AvailableSoon as a, ExpressionScopeSourceProvider as b, usePendingEcho as c, ManagedBanner as d, PublishButton as f, StatusToggle as g, ReactorDenialNote as h, DataViewer as i, convertVariableValue as j, VARIABLE_TYPES as k, StepError as l, PublishedMissingNote as m, describeSchedule as n, PropertyForm as o, PublishState as p, describeTrigger as r, useSecretRef as s, describeCron as t, DraftBanner as u, ExpressionPickerButton as v, contextMenuItems as w, ExpressionTargetProvider as x, ExpressionPickerPopup as y, uniqueStepKey as z };
3039
+
3040
+ //# sourceMappingURL=trigger-text-BgpPIXEJ.js.map