@powerhousedao/workflow 6.2.3-dev.83 → 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
@@ -4,15 +4,14 @@ import { i as connectorIdForPiece, l as planFromAuth, s as packageFromConnectorI
4
4
  import { B as stepFields, H as triggerFields, I as isCoreBlock, N as STEP_PRESETS, P as TRIGGER_PRESETS, R as sameBlock, V as triggerBlock, f as stepOutputTreeQuery, h as blockRefKey, i as outputTreeQuery, n as catalogQuery, u as runsQuery, v as TEST_TRIGGER_KIND, y as realRuns, z as stepBlock } from "./runtime-queries-LAcyniYz.js";
5
5
  import { y as actions$1 } from "./module-eOpxJVIl.js";
6
6
  import { t as useSelectedWorkflowDocument } from "./workflow-Cn1UP-eJ.js";
7
- import { $ as useTestStepRunner, At as IconButton, B as useBlockForms, Bt as Icon, Dt as FieldError, E as formatDuration, Et as Button, F as toneOf, G as useDesignTime, H as useBlockResolutions, Ht as DocumentErrorBoundary, J as useDynamicPrefetch, K as useDynamicCache, L as DesignTimeProvider, Lt as invalidClass, Mt as Select, Nt as Switch, Ot as FieldLabel, Pt as Tabs, Q as useRunById, R as useBlockForm, Rt as textAreaClass, S as TONE_TEXT, T as formatAbsolute, U as useCachedBlockForm, V as useBlockPorts, Vt as isIconName, W as useConnectionList, X as useOptionSearch, Y as useLatestRun, Z as useResolvedProp, a as BlockResolutionsProvider, at as parsePropList, bt as useRuntime, c as runsDifferentVersion, ct as storedSchema, d as versionBadge, dt as withSetting, et as useTestTrigger, f as blockMeta, ft as workflowReadiness, g as usePieceLogos, h as useBlockMeta, i as PickerPopover, it as isPropVisible, jt as Segmented, k as formatWhen, kt as Hint, l as updateVersion, lt as stripOptions, m as pieceLogo, n as BlockSelector, nt as blockMissing, o as VersionSummary, ot as resolverInputFor, p as pieceDisplayName, pt as WorkflowRuntimeProvider, q as useDynamicLookup, r as PICKER_SIZE, rt as isEmptyValue, s as resolutionText, st as settingFor, t as BlockLogo, tt as useWebhookEndpoint, u as useResolution, ut as undeclaredPortIssues, wt as useSearchParam, x as TONE_DOT, xt as useRuntimeActions, y as RUN_TONE, yt as useRunsQuery, z as useBlockFormLoader, zt as textInputClass } from "./BlockSelector-DHVzUGjW.js";
8
- import { a as useSignInGate, f as connectionCallbacks, g as newUndoGroup, h as groupedAction, i as useReactorAccessDenial, l as reactorConnections, m as UndoRedo, n as SignInPrompt, o as missingInPublished, p as BackButton, r as usePublisher, s as runsAsText, t as ConnectionForm } from "./connection-form-D2qAEHsl.js";
9
- import { _ as uniqueStepKey, a as StepError, c as PublishButton, d as ReactorDenialNote, f as StatusToggle, g as hasDraftChanges, h as VARIABLES_VIEW, i as DataViewer, l as PublishState, m as STEP_PARAM, n as describeSchedule, o as DraftBanner, p as usePublish, r as describeTrigger, s as ManagedBanner, t as describeCron, u as PublishedMissingNote } from "./trigger-text-Co-dn9x-.js";
7
+ import { $ as useTestStepRunner, At as IconButton, B as useBlockForms, Bt as Icon, Dt as FieldError, E as formatDuration, Et as Button, F as toneOf, G as useDesignTime, H as useBlockResolutions, Ht as DocumentErrorBoundary, J as useDynamicPrefetch, L as DesignTimeProvider, Mt as Select, Nt as Switch, Ot as FieldLabel, Pt as Tabs, Q as useRunById, R as useBlockForm, Rt as textAreaClass, S as TONE_TEXT, T as formatAbsolute, U as useCachedBlockForm, V as useBlockPorts, W as useConnectionList, Y as useLatestRun, a as BlockResolutionsProvider, bt as useRuntime, c as runsDifferentVersion, ct as storedSchema, d as versionBadge, et as useTestTrigger, ft as workflowReadiness, g as usePieceLogos, h as useBlockMeta, i as PickerPopover, it as isPropVisible, jt as Segmented, k as formatWhen, kt as Hint, l as updateVersion, m as pieceLogo, n as BlockSelector, nt as blockMissing, o as VersionSummary, ot as resolverInputFor, p as pieceDisplayName, pt as WorkflowRuntimeProvider, q as useDynamicLookup, r as PICKER_SIZE, s as resolutionText, st as settingFor, t as BlockLogo, tt as useWebhookEndpoint, u as useResolution, ut as undeclaredPortIssues, wt as useSearchParam, x as TONE_DOT, xt as useRuntimeActions, y as RUN_TONE, yt as useRunsQuery, z as useBlockFormLoader, zt as textInputClass } from "./BlockSelector-CtoMNZ9A.js";
8
+ import { a as useSignInGate, f as connectionCallbacks, g as newUndoGroup, h as groupedAction, i as useReactorAccessDenial, l as reactorConnections, m as UndoRedo, n as SignInPrompt, o as missingInPublished, p as BackButton, r as usePublisher, s as runsAsText, t as ConnectionForm } from "./connection-form-_H-tP2Vk.js";
9
+ import { A as VARIABLE_TYPE_LABEL, B as lacksDefaults, C as useExpressionField, D as EMPTY_SCOPE, E as menuPosition, F as stateFieldsFromSdl, I as STEP_PARAM, L as VARIABLES_VIEW, M as parseTypedValue, N as valueMismatch, O as buildExpressionScope, P as documentShape, R as hasDraftChanges, S as ExpressionTokenLine, T as menuHeight, V as withPropDefaults, _ as usePublish, a as AvailableSoon, b as ExpressionScopeSourceProvider, c as usePendingEcho, d as ManagedBanner, f as PublishButton, g as StatusToggle, h as ReactorDenialNote, i as DataViewer, j as convertVariableValue, k as VARIABLE_TYPES, l as StepError, m as PublishedMissingNote, n as describeSchedule, o as PropertyForm, p as PublishState, r as describeTrigger, s as useSecretRef, t as describeCron, u as DraftBanner, v as ExpressionPickerButton, w as contextMenuItems, x as ExpressionTargetProvider, y as ExpressionPickerPopup, z as uniqueStepKey } from "./trigger-text-BgpPIXEJ.js";
10
10
  import { addDocument, dispatchActions, useDocumentModelModules, useDocumentSafe, useFileNodesInSelectedDrive, useSelectedDriveId } from "@powerhousedao/reactor-browser";
11
11
  import { generateId } from "document-model";
12
- import { DEFAULT_TIMEZONE, NEXT_PORT, documentRefsIn, expandDocumentRefs, flowPorts, knownPorts, parseScheduleConfig, scheduleConfigIssue } from "@powerhousedao/pieces-framework/workflow";
13
- import { Fragment, Suspense, createContext, lazy, useCallback, useContext, useEffect, useId, useMemo, useRef, useState, useSyncExternalStore } from "react";
12
+ import { DEFAULT_TIMEZONE, flowPorts, knownPorts, parseScheduleConfig, scheduleConfigIssue } from "@powerhousedao/pieces-framework/workflow";
13
+ import { createContext, useCallback, useContext, useEffect, useId, useMemo, useRef, useState, useSyncExternalStore } from "react";
14
14
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
15
- import { createPortal } from "react-dom";
16
15
  import { Modal } from "@powerhousedao/design-system/connect";
17
16
  import { Background, BaseEdge, Controls, EdgeLabelRenderer, Handle, MiniMap, Position, ReactFlow, getSmoothStepPath } from "@xyflow/react";
18
17
  //#region editors/workflow-editor/undo-policy.ts
@@ -31,23 +30,6 @@ const WORKFLOW_UNDO = {
31
30
  }
32
31
  };
33
32
  //#endregion
34
- //#region editors/workflow-editor/ui/prop-defaults.ts
35
- function asRecord(value) {
36
- return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
37
- }
38
- function withPropDefaults(props, config) {
39
- const next = { ...asRecord(config) };
40
- for (const prop of props) {
41
- if (prop.type === "MARKDOWN" || prop.defaultValue === void 0) continue;
42
- if (next[prop.name] === void 0) next[prop.name] = prop.defaultValue;
43
- }
44
- return next;
45
- }
46
- function lacksDefaults(props, config) {
47
- const record = asRecord(config);
48
- return props.some((prop) => prop.type !== "MARKDOWN" && prop.defaultValue !== void 0 && record[prop.name] === void 0);
49
- }
50
- //#endregion
51
33
  //#region editors/workflow-editor/ui/add-follow-up.ts
52
34
  function followUpConfig(form, config) {
53
35
  return lacksDefaults(form.props, config) ? withPropDefaults(form.props, config) : null;
@@ -397,795 +379,6 @@ function findBlock(state, added) {
397
379
  config: step.config
398
380
  } : void 0;
399
381
  }
400
- //#endregion
401
- //#region editors/workflow-editor/ui/document-shape.ts
402
- const MAX_DEPTH$1 = 6;
403
- const normalize = (name) => name.toLowerCase().replace(/[^a-z0-9]/g, "");
404
- function typeName(node, kind) {
405
- if (node.kind === kind.NON_NULL_TYPE) {
406
- const inner = typeName(node.type, kind);
407
- return {
408
- name: inner.name,
409
- display: `${inner.display}!`
410
- };
411
- }
412
- if (node.kind === kind.LIST_TYPE) {
413
- const inner = typeName(node.type, kind);
414
- return {
415
- name: inner.name,
416
- display: `[${inner.display}]`
417
- };
418
- }
419
- return {
420
- name: node.name.value,
421
- display: node.name.value
422
- };
423
- }
424
- async function stateFieldsFromSdl(model) {
425
- if (!model.schema) return {};
426
- const { Kind, parse } = await import("graphql");
427
- let definitions;
428
- try {
429
- definitions = parse(model.schema).definitions;
430
- } catch {
431
- return {};
432
- }
433
- const types = /* @__PURE__ */ new Map();
434
- for (const def of definitions) {
435
- if (def.kind !== Kind.OBJECT_TYPE_DEFINITION && def.kind !== Kind.INPUT_OBJECT_TYPE_DEFINITION) continue;
436
- types.set(normalize(def.name.value), (def.fields ?? []).map((field) => ({
437
- name: field.name.value,
438
- type: field.type
439
- })));
440
- }
441
- const root = [`${normalize(model.name)}state`, `${normalize(model.name)}globalstate`].map((candidate) => types.get(candidate)).find((fields) => fields !== void 0);
442
- const build = (fields, depth) => Object.fromEntries(fields.map((field) => {
443
- const { name, display } = typeName(field.type, Kind);
444
- const inner = types.get(normalize(name));
445
- return [field.name, inner && inner.length > 0 && depth < MAX_DEPTH$1 ? build(inner, depth + 1) : display];
446
- }));
447
- return root ? build(root, 0) : {};
448
- }
449
- function documentShape(reference, globalState) {
450
- return {
451
- header: {
452
- id: reference.documentId,
453
- documentType: reference.documentType,
454
- name: "String",
455
- slug: "String",
456
- branch: reference.branch,
457
- revision: reference.revision,
458
- createdAtUtcIso: "DateTime!",
459
- lastModifiedAtUtcIso: "DateTime!"
460
- },
461
- state: { global: globalState }
462
- };
463
- }
464
- //#endregion
465
- //#region editors/workflow-editor/ui/variable-types.ts
466
- const VARIABLE_TYPE_LABEL = {
467
- TEXT: "Text",
468
- NUMBER: "Number",
469
- BOOLEAN: "True or false",
470
- JSON: "JSON",
471
- SECRET: "Secret"
472
- };
473
- const VARIABLE_TYPES = Object.keys(VARIABLE_TYPE_LABEL);
474
- const DECIMAL$1 = /^-?(?:\d+(?:\.\d*)?|\.\d+)$/;
475
- function parseTypedValue(type, raw) {
476
- const trimmed = raw.trim();
477
- switch (type) {
478
- case "TEXT": return {
479
- ok: true,
480
- value: raw === "" ? null : raw
481
- };
482
- case "NUMBER":
483
- if (trimmed === "") return {
484
- ok: true,
485
- value: null
486
- };
487
- return DECIMAL$1.test(trimmed) ? {
488
- ok: true,
489
- value: Number(trimmed)
490
- } : {
491
- ok: false,
492
- error: "Not a number"
493
- };
494
- case "BOOLEAN":
495
- if (trimmed === "true") return {
496
- ok: true,
497
- value: true
498
- };
499
- if (trimmed === "false") return {
500
- ok: true,
501
- value: false
502
- };
503
- return {
504
- ok: false,
505
- error: "Not true or false"
506
- };
507
- case "JSON":
508
- if (trimmed === "") return {
509
- ok: true,
510
- value: null
511
- };
512
- try {
513
- return {
514
- ok: true,
515
- value: JSON.parse(trimmed)
516
- };
517
- } catch (error) {
518
- return {
519
- ok: false,
520
- error: `Not valid JSON: ${error instanceof Error ? error.message : String(error)}`
521
- };
522
- }
523
- case "SECRET": return {
524
- ok: false,
525
- error: "Secrets are set through the secret field"
526
- };
527
- }
528
- }
529
- function valueMismatch(type, value) {
530
- if (value === null || value === void 0) return null;
531
- switch (type) {
532
- case "TEXT": return typeof value === "string" ? null : "Not text";
533
- case "NUMBER": return typeof value === "number" ? null : "Not a number";
534
- case "BOOLEAN": return typeof value === "boolean" ? null : "Not true or false";
535
- case "JSON": return null;
536
- case "SECRET": return typeof value === "string" ? null : "Not a secret reference";
537
- }
538
- }
539
- function convertVariableValue(value, from, to) {
540
- if (from === to) return value;
541
- if (from === "SECRET" || to === "SECRET") return null;
542
- if (to === "JSON" || value === null || value === void 0) return value ?? null;
543
- if (to === "TEXT") return typeof value === "string" ? value : JSON.stringify(value);
544
- if (typeof value === "string") {
545
- const parsed = parseTypedValue(to, value);
546
- if (parsed.ok) return parsed.value;
547
- }
548
- return value;
549
- }
550
- //#endregion
551
- //#region editors/workflow-editor/ui/expression-scope.ts
552
- const EMPTY_SCOPE = {
553
- value: {},
554
- captions: {}
555
- };
556
- const MAX_DEPTH = 6;
557
- const MAX_ARRAY_ITEMS = 25;
558
- function capValue(value, depth = 0) {
559
- if (value === null || typeof value !== "object") return value;
560
- if (depth >= MAX_DEPTH) return Array.isArray(value) ? "[…]" : "{…}";
561
- if (Array.isArray(value)) return value.slice(0, MAX_ARRAY_ITEMS).map((item) => capValue(item, depth + 1));
562
- return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, capValue(entry, depth + 1)]));
563
- }
564
- function upstreamStepIds(model, stepId) {
565
- const incoming = /* @__PURE__ */ new Map();
566
- for (const edge of model.edges) incoming.set(edge.to, [...incoming.get(edge.to) ?? [], edge.from]);
567
- const upstream = /* @__PURE__ */ new Set();
568
- const queue = [stepId];
569
- while (queue.length > 0) for (const from of incoming.get(queue.pop()) ?? []) if (!upstream.has(from)) {
570
- upstream.add(from);
571
- queue.push(from);
572
- }
573
- return upstream;
574
- }
575
- function formatRunTime(startedAt, now = /* @__PURE__ */ new Date()) {
576
- const date = new Date(startedAt);
577
- if (Number.isNaN(date.getTime())) return startedAt;
578
- const sameDay = date.toDateString() === now.toDateString();
579
- const time = date.toLocaleTimeString([], {
580
- hour: "2-digit",
581
- minute: "2-digit"
582
- });
583
- return sameDay ? time : `${date.toLocaleDateString([], {
584
- month: "short",
585
- day: "numeric"
586
- })} ${time}`;
587
- }
588
- const hasOutput = (step) => (step.status === "SUCCEEDED" || step.status === "REPLAYED") && step.output !== void 0 && step.output !== null;
589
- async function withDocuments(value, documentOutput) {
590
- const references = documentRefsIn(value);
591
- if (references.length === 0) return value;
592
- const key = (reference) => `${reference.branch}:${reference.documentId}`;
593
- const shapeOf = async (reference) => {
594
- try {
595
- if (documentOutput) return await documentOutput(reference);
596
- } catch {}
597
- return documentShape(reference, {});
598
- };
599
- const shapes = new Map(await Promise.all(references.map(async (reference) => [key(reference), await shapeOf(reference)])));
600
- return expandDocumentRefs(value, (reference) => shapes.get(key(reference)));
601
- }
602
- async function buildExpressionScope(options) {
603
- const { model, latestRun } = options;
604
- const documents = (value) => withDocuments(value, options.documentOutput);
605
- const runCaption = latestRun ? `from run ${formatRunTime(latestRun.startedAt, options.now)}` : void 0;
606
- const runSteps = new Map((latestRun?.steps ?? []).filter(hasOutput).map((step) => [step.stepKey, step]));
607
- const value = {};
608
- const captions = {};
609
- const testCaption = (sample) => `from test ${formatRunTime(sample.testedAt, options.now)}`;
610
- const tested = async (block) => block.lastTest && options.testOutput ? options.testOutput(block.id).catch(() => void 0) : void 0;
611
- if (model.trigger) {
612
- const sample = await tested(model.trigger);
613
- if (sample) {
614
- value.trigger = { payload: capValue(await documents(sample.value)) };
615
- captions["trigger.payload"] = testCaption(sample);
616
- } else if (runCaption && latestRun?.triggerPayload !== void 0 && latestRun.triggerPayload !== null) {
617
- value.trigger = { payload: capValue(await documents(latestRun.triggerPayload)) };
618
- captions["trigger.payload"] = runCaption;
619
- } else {
620
- value.trigger = { payload: await options.authoredOutput(triggerBlock(model.trigger), model.trigger.config) };
621
- captions["trigger.payload"] = "declared type";
622
- }
623
- }
624
- const upstream = upstreamStepIds(model, options.stepId);
625
- const steps = {};
626
- await Promise.all(model.steps.filter((step) => upstream.has(step.id)).map(async (step) => {
627
- const sample = await tested(step);
628
- if (sample) {
629
- steps[step.key] = { output: capValue(await documents(sample.value)) };
630
- captions[`steps.${step.key}.output`] = testCaption(sample);
631
- return;
632
- }
633
- const journaled = runSteps.get(step.key);
634
- if (runCaption && journaled && journaled.pieceName === step.pieceName && journaled.blockName === step.actionName) {
635
- steps[step.key] = { output: capValue(await documents(journaled.output)) };
636
- captions[`steps.${step.key}.output`] = runCaption;
637
- return;
638
- }
639
- steps[step.key] = { output: await options.authoredOutput(stepBlock(step), step.config) };
640
- captions[`steps.${step.key}.output`] = "declared type";
641
- }));
642
- if (Object.keys(steps).length > 0) value.steps = steps;
643
- if (model.variables.length > 0) {
644
- value.variables = Object.fromEntries(model.variables.map((variable) => [variable.key, variable.type === "SECRET" ? "secret" : variable.value ?? null]));
645
- captions.variables = "workflow variables";
646
- for (const variable of model.variables) if (variable.type) captions[`variables.${variable.key}`] = VARIABLE_TYPE_LABEL[variable.type].toLowerCase();
647
- }
648
- return {
649
- value,
650
- captions
651
- };
652
- }
653
- const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
654
- function childPath(parent, key, parentIsArray) {
655
- if (parentIsArray) return `${parent}[${key}]`;
656
- if (!parent) return key;
657
- return IDENTIFIER.test(key) ? `${parent}.${key}` : `${parent}[${JSON.stringify(key)}]`;
658
- }
659
- //#endregion
660
- //#region editors/workflow-editor/ui/canvas-menu.ts
661
- function hasNextPort(model, id, portsOf) {
662
- if (model.trigger?.id === id) return true;
663
- const step = model.steps.find((entry) => entry.id === id);
664
- return step ? portsOf(stepBlock(step))?.includes(NEXT_PORT) ?? false : false;
665
- }
666
- function contextMenuItems(target, model, portsOf) {
667
- switch (target.kind) {
668
- case "step": {
669
- const skipped = model.steps.find((entry) => entry.id === target.id)?.skip === true;
670
- return [
671
- {
672
- id: "open",
673
- label: "Open settings"
674
- },
675
- {
676
- id: "addBelow",
677
- label: "Add step below",
678
- disabled: !hasNextPort(model, target.id, portsOf)
679
- },
680
- {
681
- id: "duplicate",
682
- label: "Duplicate step"
683
- },
684
- {
685
- id: "toggleSkip",
686
- label: skipped ? "Stop skipping this step" : "Skip this step"
687
- },
688
- {
689
- id: "removeStep",
690
- label: "Remove step"
691
- }
692
- ];
693
- }
694
- case "trigger": return [
695
- {
696
- id: "open",
697
- label: "Open settings"
698
- },
699
- {
700
- id: "addBelow",
701
- label: "Add step below",
702
- disabled: !model.trigger
703
- },
704
- {
705
- id: "changeTrigger",
706
- label: "Change trigger"
707
- },
708
- {
709
- id: "removeTrigger",
710
- label: "Remove trigger"
711
- }
712
- ];
713
- case "edge": return [{
714
- id: "insertStep",
715
- label: "Insert step here"
716
- }, {
717
- id: "removeEdge",
718
- label: "Remove edge"
719
- }];
720
- case "pane": return [
721
- {
722
- id: "addStep",
723
- label: "Add step here"
724
- },
725
- {
726
- id: "selectAll",
727
- label: "Select all steps",
728
- disabled: model.steps.length === 0
729
- },
730
- {
731
- id: "fitView",
732
- label: "Fit view"
733
- }
734
- ];
735
- }
736
- }
737
- const MENU_ITEM_HEIGHT = 28;
738
- const VIEWPORT_MARGIN = 8;
739
- function menuHeight(items) {
740
- return items * MENU_ITEM_HEIGHT + 8;
741
- }
742
- function clampToViewport(at, extent, available) {
743
- return Math.max(VIEWPORT_MARGIN, Math.min(at, available - extent - VIEWPORT_MARGIN));
744
- }
745
- function menuPosition(point, size, viewport) {
746
- const place = (at, extent, available) => clampToViewport(at + extent > available - VIEWPORT_MARGIN ? at - extent : at, extent, available);
747
- return {
748
- x: place(point.x, size.width, viewport.width),
749
- y: place(point.y, size.height, viewport.height)
750
- };
751
- }
752
- const ANCHOR_GAP = 8;
753
- function anchorLeftPosition(anchor, size, viewport) {
754
- const left = anchor.left - ANCHOR_GAP - size.width;
755
- return {
756
- x: clampToViewport(left >= VIEWPORT_MARGIN ? left : anchor.right + ANCHOR_GAP, size.width, viewport.width),
757
- y: clampToViewport(anchor.top, size.height, viewport.height)
758
- };
759
- }
760
- //#endregion
761
- //#region editors/workflow-editor/ui/expression-tokens.ts
762
- const EMBEDDED_EXPRESSION = /(?<!\\)\{\{\s*([^{}]+?)\s*\}\}/g;
763
- function splitExpressionTokens(value) {
764
- const tokens = [];
765
- let last = 0;
766
- for (const match of value.matchAll(EMBEDDED_EXPRESSION)) {
767
- const index = match.index;
768
- if (index > last) tokens.push({
769
- kind: "text",
770
- text: value.slice(last, index)
771
- });
772
- tokens.push({
773
- kind: "expression",
774
- text: match[0],
775
- expression: match[1]
776
- });
777
- last = index + match[0].length;
778
- }
779
- if (last < value.length) tokens.push({
780
- kind: "text",
781
- text: value.slice(last)
782
- });
783
- return tokens;
784
- }
785
- function hasExpressions(value) {
786
- return typeof value === "string" && new RegExp(EMBEDDED_EXPRESSION).test(value);
787
- }
788
- function describeExpression(expression) {
789
- const terms = expression.split("||");
790
- const path = terms[0].trim();
791
- const hasFallback = terms.length > 1;
792
- const segments = path.split(".");
793
- switch (segments[0]) {
794
- case "steps": return {
795
- root: "steps",
796
- stepKey: segments[1] ?? "",
797
- rest: segments.slice(2).join("."),
798
- hasFallback
799
- };
800
- case "trigger": return {
801
- root: "trigger",
802
- rest: segments.slice(1).join("."),
803
- hasFallback
804
- };
805
- case "variables": return {
806
- root: "variables",
807
- rest: segments.slice(1).join("."),
808
- hasFallback
809
- };
810
- default: return {
811
- root: "other",
812
- rest: path,
813
- hasFallback
814
- };
815
- }
816
- }
817
- //#endregion
818
- //#region editors/workflow-editor/ui/ExpressionPicker.tsx
819
- const ScopeSourceContext = createContext(void 0);
820
- const ExpressionScopeSourceProvider = ScopeSourceContext.Provider;
821
- function useScopeSource() {
822
- return useContext(ScopeSourceContext);
823
- }
824
- const TargetContext = createContext(null);
825
- function ExpressionTargetProvider(props) {
826
- const [target, setTarget] = useState(null);
827
- const value = useMemo(() => ({
828
- target,
829
- setTarget,
830
- stepBlocks: props.stepBlocks,
831
- triggerBlock: props.triggerBlock
832
- }), [
833
- target,
834
- props.stepBlocks,
835
- props.triggerBlock
836
- ]);
837
- return /* @__PURE__ */ jsx(TargetContext.Provider, {
838
- value,
839
- children: props.children
840
- });
841
- }
842
- function useExpressionTarget() {
843
- return useContext(TargetContext);
844
- }
845
- function fieldAnchor(element) {
846
- const rect = (element?.closest("label,div") ?? element)?.getBoundingClientRect();
847
- if (!rect) return {
848
- left: window.innerWidth,
849
- right: window.innerWidth,
850
- top: 0
851
- };
852
- return {
853
- left: rect.left,
854
- right: rect.right,
855
- top: rect.top
856
- };
857
- }
858
- function useExpressionField(options) {
859
- const id = useId();
860
- const context = useExpressionTarget();
861
- const insertRef = useRef(options.insert);
862
- useEffect(() => {
863
- insertRef.current = options.insert;
864
- });
865
- const { stepId, label } = options;
866
- return {
867
- active: context?.target?.id === id,
868
- focus: (event) => {
869
- context?.setTarget({
870
- id,
871
- stepId,
872
- label,
873
- anchor: fieldAnchor(event?.currentTarget),
874
- insert: (expression) => insertRef.current(expression)
875
- });
876
- }
877
- };
878
- }
879
- function preview(value) {
880
- if (value === null) return "null";
881
- if (value === void 0) return "";
882
- if (Array.isArray(value)) return `[${value.length}]`;
883
- if (typeof value === "object") return "{…}";
884
- const text = typeof value === "string" ? value : JSON.stringify(value) ?? "";
885
- return text.length > 28 ? `${text.slice(0, 28)}…` : text;
886
- }
887
- function isExpandable(value) {
888
- return value !== null && typeof value === "object" && Object.keys(value).length > 0;
889
- }
890
- function entriesOf(value) {
891
- if (Array.isArray(value)) return value.map((item, i) => [String(i), item]);
892
- if (value !== null && typeof value === "object") return Object.entries(value);
893
- return [];
894
- }
895
- function Caption(props) {
896
- if (!props.text) return null;
897
- return /* @__PURE__ */ jsx("span", {
898
- className: "ml-auto shrink-0 pl-2 text-[10px] italic text-muted-foreground/80",
899
- children: props.text
900
- });
901
- }
902
- function ValueNode(props) {
903
- const context = useExpressionTarget();
904
- const [open, setOpen] = useState(props.depth < 2);
905
- const expandable = isExpandable(props.value);
906
- const stepKey = /^steps\.([^.]+)$/.exec(props.path)?.[1];
907
- const nodeBlock = stepKey ? context?.stepBlocks[stepKey] : props.path === "trigger" ? context?.triggerBlock : void 0;
908
- return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs("div", {
909
- className: "flex items-center gap-1 rounded px-1 py-0.5 hover:bg-muted/50",
910
- style: { paddingLeft: props.depth * 14 + 4 },
911
- children: [
912
- expandable ? /* @__PURE__ */ jsx("button", {
913
- type: "button",
914
- className: "w-3 shrink-0 text-[10px] text-muted-foreground/80",
915
- onClick: () => setOpen((value) => !value),
916
- children: open ? "▾" : "▸"
917
- }) : /* @__PURE__ */ jsx("span", { className: "w-3 shrink-0" }),
918
- /* @__PURE__ */ jsxs("button", {
919
- type: "button",
920
- className: "flex min-w-0 flex-1 items-baseline gap-2 text-left",
921
- title: `{{${props.path}}}`,
922
- onClick: () => props.onPick(props.path),
923
- children: [nodeBlock ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(BlockLogo, {
924
- block: nodeBlock,
925
- size: 16
926
- }), /* @__PURE__ */ jsx("span", {
927
- className: "shrink-0 text-xs font-medium text-foreground",
928
- children: blockMeta(nodeBlock).displayName
929
- })] }) : /* @__PURE__ */ jsx("span", {
930
- className: "shrink-0 font-mono text-xs text-foreground",
931
- children: props.name
932
- }), /* @__PURE__ */ jsx("span", {
933
- className: "truncate text-[11px] text-muted-foreground/80",
934
- children: preview(props.value)
935
- })]
936
- }),
937
- /* @__PURE__ */ jsx(Caption, { text: props.captions[props.path] })
938
- ]
939
- }), expandable && open ? entriesOf(props.value).map(([key, child]) => /* @__PURE__ */ jsx(ValueNode, {
940
- name: key,
941
- path: childPath(props.path, key, Array.isArray(props.value)),
942
- value: child,
943
- depth: props.depth + 1,
944
- captions: props.captions,
945
- onPick: props.onPick
946
- }, key)) : null] });
947
- }
948
- const SEARCH_DEPTH = 6;
949
- const SEARCH_LIMIT = 200;
950
- function flatten(value, path, depth, out) {
951
- for (const [key, child] of entriesOf(value)) {
952
- const nested = childPath(path, key, Array.isArray(value));
953
- out.push({
954
- path: nested,
955
- value: child
956
- });
957
- if (depth < SEARCH_DEPTH && isExpandable(child)) flatten(child, nested, depth + 1, out);
958
- }
959
- }
960
- function SearchResults(props) {
961
- const matches = useMemo(() => {
962
- const all = [];
963
- flatten(props.scope.value, "", 0, all);
964
- const lowered = props.query.toLowerCase();
965
- return all.filter((entry) => entry.path.toLowerCase().includes(lowered)).slice(0, SEARCH_LIMIT);
966
- }, [props.scope, props.query]);
967
- if (matches.length === 0) return /* @__PURE__ */ jsx("div", {
968
- className: "px-2 py-1 text-xs text-muted-foreground/80",
969
- children: "No matches"
970
- });
971
- return /* @__PURE__ */ jsx(Fragment$1, { children: matches.map((entry) => /* @__PURE__ */ jsxs("button", {
972
- type: "button",
973
- className: "flex w-full items-baseline gap-2 rounded px-2 py-0.5 text-left hover:bg-muted/50",
974
- title: `{{${entry.path}}}`,
975
- onClick: () => props.onPick(entry.path),
976
- children: [/* @__PURE__ */ jsx("span", {
977
- className: "min-w-0 truncate font-mono text-[11px] text-foreground",
978
- children: entry.path
979
- }), /* @__PURE__ */ jsx("span", {
980
- className: "truncate text-[10px] text-muted-foreground/80",
981
- children: preview(entry.value)
982
- })]
983
- }, entry.path)) });
984
- }
985
- const POPUP_SIZE = {
986
- width: 420,
987
- height: 520
988
- };
989
- function ExpressionPickerPopup() {
990
- const context = useExpressionTarget();
991
- const target = context?.target ?? null;
992
- const [query, setQuery] = useState("");
993
- const [state, setState] = useState({ kind: "idle" });
994
- const scopeSource = useScopeSource();
995
- const containerRef = useRef(null);
996
- const stepId = target?.stepId;
997
- const hasTarget = target !== null;
998
- useEffect(() => {
999
- if (!hasTarget || !scopeSource) return;
1000
- let alive = true;
1001
- setState((current) => current.kind === "ready" && current.stepId === stepId ? current : { kind: "loading" });
1002
- scopeSource.load({ stepId }).then((scope) => {
1003
- if (alive) setState({
1004
- kind: "ready",
1005
- scope,
1006
- stepId
1007
- });
1008
- }, (error) => {
1009
- if (alive) setState({
1010
- kind: "error",
1011
- message: error instanceof Error ? error.message : String(error)
1012
- });
1013
- });
1014
- return () => {
1015
- alive = false;
1016
- };
1017
- }, [
1018
- hasTarget,
1019
- stepId,
1020
- scopeSource
1021
- ]);
1022
- const targetId = target?.id;
1023
- useEffect(() => setQuery(""), [targetId]);
1024
- const close = context?.setTarget;
1025
- useEffect(() => {
1026
- if (!hasTarget || !close) return;
1027
- const dismiss = () => close(null);
1028
- const outside = (event) => !containerRef.current?.contains(event.target);
1029
- const onMouseDown = (event) => {
1030
- if (outside(event)) dismiss();
1031
- };
1032
- const onKeyDown = (event) => {
1033
- if (event.key === "Escape") dismiss();
1034
- };
1035
- const onScroll = (event) => {
1036
- if (outside(event)) dismiss();
1037
- };
1038
- window.addEventListener("mousedown", onMouseDown);
1039
- window.addEventListener("keydown", onKeyDown);
1040
- window.addEventListener("scroll", onScroll, true);
1041
- return () => {
1042
- window.removeEventListener("mousedown", onMouseDown);
1043
- window.removeEventListener("keydown", onKeyDown);
1044
- window.removeEventListener("scroll", onScroll, true);
1045
- };
1046
- }, [hasTarget, close]);
1047
- if (!context || !scopeSource || !target) return null;
1048
- const pick = (path) => {
1049
- target.insert(`{{${path}}}`);
1050
- context.setTarget(null);
1051
- };
1052
- const scope = state.kind === "ready" && state.stepId === stepId ? state.scope : EMPTY_SCOPE;
1053
- const empty = entriesOf(scope.value).length === 0;
1054
- const position = anchorLeftPosition(target.anchor, POPUP_SIZE, {
1055
- width: window.innerWidth,
1056
- height: window.innerHeight
1057
- });
1058
- return createPortal(/* @__PURE__ */ jsxs("div", {
1059
- ref: containerRef,
1060
- className: "workflow-expression-popup fixed flex flex-col rounded-md border border-solid border-foreground/10 bg-card shadow-lg",
1061
- onMouseDown: (event) => {
1062
- if (!(event.target instanceof HTMLInputElement)) event.preventDefault();
1063
- },
1064
- style: {
1065
- left: position.x,
1066
- top: position.y,
1067
- width: POPUP_SIZE.width,
1068
- maxHeight: POPUP_SIZE.height
1069
- },
1070
- children: [
1071
- /* @__PURE__ */ jsxs("div", {
1072
- className: "flex items-center gap-2 px-3 py-1.5",
1073
- children: [
1074
- /* @__PURE__ */ jsx("span", {
1075
- className: "font-mono text-[11px] text-muted-foreground",
1076
- children: "{}"
1077
- }),
1078
- /* @__PURE__ */ jsxs("span", {
1079
- className: "min-w-0 truncate text-xs text-muted-foreground",
1080
- children: [
1081
- "Insert into",
1082
- " ",
1083
- /* @__PURE__ */ jsx("span", {
1084
- className: "font-semibold text-foreground",
1085
- children: target.label
1086
- })
1087
- ]
1088
- }),
1089
- /* @__PURE__ */ jsx("button", {
1090
- type: "button",
1091
- className: "ml-auto text-[11px] text-muted-foreground/80 hover:text-muted-foreground",
1092
- title: "Close",
1093
- onClick: () => context.setTarget(null),
1094
- children: "✕"
1095
- })
1096
- ]
1097
- }),
1098
- /* @__PURE__ */ jsx("div", {
1099
- className: "px-3 pb-1.5",
1100
- children: /* @__PURE__ */ jsx("input", {
1101
- className: "w-full rounded border border-foreground/10 px-2 py-1.5 text-sm",
1102
- placeholder: "Search paths…",
1103
- value: query,
1104
- onChange: (event) => setQuery(event.target.value)
1105
- })
1106
- }),
1107
- /* @__PURE__ */ jsx("div", {
1108
- className: "min-h-0 flex-1 overflow-y-auto px-1 pb-1",
1109
- children: state.kind === "error" ? /* @__PURE__ */ jsx("div", {
1110
- className: "px-2 py-1 text-xs text-wf-fail",
1111
- children: state.message
1112
- }) : state.kind === "loading" ? /* @__PURE__ */ jsx("div", {
1113
- className: "px-2 py-1 text-xs text-muted-foreground/80",
1114
- children: "Loading…"
1115
- }) : empty ? /* @__PURE__ */ jsx("div", {
1116
- className: "px-2 py-1 text-xs text-muted-foreground/80",
1117
- children: "No values available for this field yet."
1118
- }) : query.trim() ? /* @__PURE__ */ jsx(SearchResults, {
1119
- scope,
1120
- query: query.trim(),
1121
- onPick: pick
1122
- }) : entriesOf(scope.value).map(([key, value]) => /* @__PURE__ */ jsx(ValueNode, {
1123
- name: key,
1124
- path: key,
1125
- value,
1126
- depth: 0,
1127
- captions: scope.captions,
1128
- onPick: pick
1129
- }, key))
1130
- })
1131
- ]
1132
- }), document.body);
1133
- }
1134
- function ExpressionPickerButton(props) {
1135
- if (!useScopeSource()) return null;
1136
- return /* @__PURE__ */ jsxs("button", {
1137
- type: "button",
1138
- title: "Insert data from the trigger or an earlier step",
1139
- 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"}`,
1140
- onClick: props.onFocusField,
1141
- children: [/* @__PURE__ */ jsx(Icon, {
1142
- name: "braces",
1143
- className: "h-3.5 w-3.5"
1144
- }), "Insert data"]
1145
- });
1146
- }
1147
- function Chip(props) {
1148
- const ref = describeExpression(props.expression);
1149
- const block = ref.stepKey ? props.stepBlocks[ref.stepKey] : void 0;
1150
- const head = ref.root === "steps" ? ref.stepKey : ref.root === "trigger" ? "trigger" : ref.root === "variables" ? "var" : "";
1151
- return /* @__PURE__ */ jsxs("span", {
1152
- 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",
1153
- title: `{{${props.expression}}}`,
1154
- children: [
1155
- block ? /* @__PURE__ */ jsx(BlockLogo, {
1156
- block,
1157
- size: 12
1158
- }) : null,
1159
- head ? /* @__PURE__ */ jsx("span", {
1160
- className: "font-semibold",
1161
- children: head
1162
- }) : null,
1163
- /* @__PURE__ */ jsx("span", {
1164
- className: "truncate",
1165
- children: ref.root === "other" ? ref.rest : ref.rest || "*"
1166
- }),
1167
- ref.hasFallback ? /* @__PURE__ */ jsx("span", {
1168
- className: "text-wf-run",
1169
- children: "||…"
1170
- }) : null
1171
- ]
1172
- });
1173
- }
1174
- function ExpressionTokenLine(props) {
1175
- const context = useExpressionTarget();
1176
- const tokens = splitExpressionTokens(props.value);
1177
- if (!tokens.some((token) => token.kind === "expression")) return null;
1178
- return /* @__PURE__ */ jsx("div", {
1179
- className: "mt-1.5 flex flex-wrap items-center gap-1 text-xs text-muted-foreground",
1180
- children: tokens.map((token, index) => token.kind === "text" ? /* @__PURE__ */ jsx("span", {
1181
- className: "max-w-40 truncate whitespace-pre",
1182
- children: token.text
1183
- }, index) : /* @__PURE__ */ jsx(Chip, {
1184
- expression: token.expression,
1185
- stepBlocks: context?.stepBlocks ?? {}
1186
- }, index))
1187
- });
1188
- }
1189
382
  const PANEL_DEFAULT_WIDTH = 416;
1190
383
  const PANEL_MAX_SHARE = .7;
1191
384
  const KEY_STEP = 16;
@@ -2010,1726 +1203,6 @@ function ReactorConnectionField(props) {
2010
1203
  }) : null]
2011
1204
  });
2012
1205
  }
2013
- //#endregion
2014
- //#region editors/shared/pending-echo.ts
2015
- function keyOf(value) {
2016
- return JSON.stringify(value, (_, entry) => entry && typeof entry === "object" && !Array.isArray(entry) ? Object.fromEntries(Object.entries(entry).sort(([a], [b]) => a.localeCompare(b))) : entry);
2017
- }
2018
- function usePendingEcho(saved, onChange) {
2019
- const savedKey = keyOf(saved);
2020
- const [sent, setSent] = useState([]);
2021
- const [seen, setSeen] = useState(savedKey);
2022
- let pending = sent;
2023
- if (seen !== savedKey) {
2024
- const echo = sent.findIndex((value) => keyOf(value) === savedKey);
2025
- pending = echo === -1 ? [] : sent.slice(echo + 1);
2026
- setSeen(savedKey);
2027
- setSent(pending);
2028
- }
2029
- const value = pending.length > 0 ? pending[pending.length - 1] : saved;
2030
- return {
2031
- value,
2032
- commit: (next) => {
2033
- if (keyOf(next) === keyOf(value)) return;
2034
- setSent([...pending, next]);
2035
- onChange(next, value);
2036
- },
2037
- onBlur: (event) => {
2038
- const inside = event.currentTarget.contains(event.relatedTarget);
2039
- if (pending.length > 0 && !inside && keyOf(value) === savedKey) setSent([]);
2040
- }
2041
- };
2042
- }
2043
- //#endregion
2044
- //#region editors/workflow-editor/ui/secret-ref.ts
2045
- const SECRET_REF_PREFIX = "secret://v1:";
2046
- function useSecretRef(options) {
2047
- const { secrets } = options;
2048
- const ref = typeof options.value === "string" ? options.value : "";
2049
- const managed = ref.startsWith(SECRET_REF_PREFIX);
2050
- const [draft, setDraft] = useState("");
2051
- const [busy, setBusy] = useState(false);
2052
- const [error, setError] = useState(null);
2053
- const [stat, setStat] = useState(null);
2054
- useEffect(() => {
2055
- setStat(null);
2056
- if (!managed || !secrets) return;
2057
- let cancelled = false;
2058
- secrets.stat(ref).then((result) => {
2059
- if (!cancelled) setStat(result);
2060
- }, () => void 0);
2061
- return () => {
2062
- cancelled = true;
2063
- };
2064
- }, [
2065
- ref,
2066
- managed,
2067
- secrets
2068
- ]);
2069
- const commit = () => {
2070
- if (draft === "" || busy || !secrets) return;
2071
- setBusy(true);
2072
- setError(null);
2073
- secrets.save({
2074
- ref: managed ? ref : void 0,
2075
- value: draft,
2076
- label: options.label
2077
- }).then((result) => {
2078
- setDraft("");
2079
- if (result.ref !== ref) options.onCommit(result.ref);
2080
- else setStat(result);
2081
- }).catch((requestError) => {
2082
- setError(requestError instanceof Error ? requestError.message : String(requestError));
2083
- }).finally(() => setBusy(false));
2084
- };
2085
- return {
2086
- ref,
2087
- managed,
2088
- draft,
2089
- setDraft,
2090
- busy,
2091
- error,
2092
- stat,
2093
- commit
2094
- };
2095
- }
2096
- //#endregion
2097
- //#region editors/workflow-editor/ui/prop-controls.tsx
2098
- const CALLOUT = {
2099
- INFO: { box: "rounded bg-muted px-2 py-1.5" },
2100
- WARNING: {
2101
- box: "rounded border border-solid border-wf-warn/40 bg-wf-warn/10 px-2 py-1.5",
2102
- icon: "alert"
2103
- },
2104
- TIP: {
2105
- box: "rounded border border-solid border-wf-ok/30 bg-wf-ok/10 px-2 py-1.5",
2106
- icon: "bolt"
2107
- },
2108
- BORDERLESS: { box: "" }
2109
- };
2110
- /** A MARKDOWN prop's text, styled by the piece's `variant` (INFO default). */
2111
- function MarkdownCallout(props) {
2112
- const callout = CALLOUT[props.variant ?? "INFO"] ?? CALLOUT.INFO;
2113
- return /* @__PURE__ */ jsxs("div", {
2114
- className: `flex gap-2 ${callout.box}`,
2115
- "data-variant": props.variant ?? "INFO",
2116
- children: [callout.icon ? /* @__PURE__ */ jsx(Icon, {
2117
- name: callout.icon,
2118
- className: `mt-0.5 h-3.5 w-3.5 shrink-0 ${callout.icon === "alert" ? "text-wf-warn" : "text-wf-ok"}`
2119
- }) : null, /* @__PURE__ */ jsx("div", {
2120
- className: "min-w-0 flex-1",
2121
- children: props.children
2122
- })]
2123
- });
2124
- }
2125
- /** An option's icon, when the piece names one this editor draws. */
2126
- function optionIcon(name) {
2127
- return isIconName(name) ? /* @__PURE__ */ jsx(Icon, {
2128
- name,
2129
- className: "h-3.5 w-3.5 shrink-0 text-muted-foreground"
2130
- }) : void 0;
2131
- }
2132
- /** STATIC_DROPDOWN with `display: 'cards'`: one selectable card per option. */
2133
- function OptionCards(props) {
2134
- const current = props.keyOf(props.value);
2135
- return /* @__PURE__ */ jsx("div", {
2136
- id: props.id,
2137
- role: "radiogroup",
2138
- className: `grid grid-cols-2 gap-2 ${props.invalid ? "rounded-md ring-1 ring-wf-warn/60" : ""}`,
2139
- children: props.options.map((option) => {
2140
- const key = props.keyOf(option.value);
2141
- const selected = key === current;
2142
- return /* @__PURE__ */ jsxs("button", {
2143
- type: "button",
2144
- role: "radio",
2145
- "aria-checked": selected,
2146
- 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"}`,
2147
- onClick: () => props.onChange(selected && props.clearable ? void 0 : option.value),
2148
- children: [/* @__PURE__ */ jsxs("span", {
2149
- className: "flex items-center gap-1.5 text-[13px] font-medium text-foreground",
2150
- children: [optionIcon(option.icon), option.label]
2151
- }), option.description ? /* @__PURE__ */ jsx("span", {
2152
- className: "text-xs leading-snug text-muted-foreground",
2153
- children: option.description
2154
- }) : null]
2155
- }, key);
2156
- })
2157
- });
2158
- }
2159
- /** The declared bounds, for the hint and the check: "Between 0 and 5". */
2160
- function numberRangeText(min, max) {
2161
- if (min !== void 0 && max !== void 0) return `Between ${min} and ${max}`;
2162
- if (min !== void 0) return `At least ${min}`;
2163
- if (max !== void 0) return `At most ${max}`;
2164
- return null;
2165
- }
2166
- function numberRangeError(value, min, max) {
2167
- if (typeof value !== "number") return null;
2168
- if (min !== void 0 && value < min || max !== void 0 && value > max) return `${numberRangeText(min, max)}.`;
2169
- return null;
2170
- }
2171
- /** NUMBER with `display: 'stepper'`: − value +, still accepting expressions. */
2172
- function NumberStepper(props) {
2173
- const step = props.step ?? 1;
2174
- const numeric = typeof props.value === "number" ? props.value : void 0;
2175
- const clamp = (next) => Math.min(props.max ?? Infinity, Math.max(props.min ?? -Infinity, next));
2176
- const bump = (direction) => props.onCommit(clamp((numeric ?? props.min ?? 0) + direction * step));
2177
- const text = props.value === void 0 || props.value === null ? "" : String(props.value);
2178
- return /* @__PURE__ */ jsxs("div", {
2179
- className: "flex items-center gap-1",
2180
- children: [
2181
- /* @__PURE__ */ jsx(IconButton, {
2182
- icon: "minus",
2183
- label: "Decrease",
2184
- disabled: numeric !== void 0 && props.min !== void 0 && numeric <= props.min,
2185
- onClick: () => bump(-1)
2186
- }),
2187
- /* @__PURE__ */ jsx("input", {
2188
- id: props.id,
2189
- className: `${textInputClass} w-24 text-center tabular-nums ${props.invalid ? invalidClass : ""}`,
2190
- defaultValue: text,
2191
- inputMode: "decimal",
2192
- spellCheck: false,
2193
- onFocus: props.onFocus,
2194
- onBlur: (event) => props.onCommitText(event.target.value)
2195
- }, text),
2196
- /* @__PURE__ */ jsx(IconButton, {
2197
- icon: "plus",
2198
- label: "Increase",
2199
- disabled: numeric !== void 0 && props.max !== void 0 && numeric >= props.max,
2200
- onClick: () => bump(1)
2201
- })
2202
- ]
2203
- });
2204
- }
2205
- const DATE_PRESETS = Object.entries({
2206
- any_time: "Any time",
2207
- last_24_hours: "Last 24 hours",
2208
- last_7_days: "Last 7 days",
2209
- last_30_days: "Last 30 days",
2210
- last_90_days: "Last 90 days",
2211
- this_month: "This month",
2212
- custom: "Custom"
2213
- }).map(([value, label]) => ({
2214
- value,
2215
- label
2216
- }));
2217
- function toLocalInput(iso) {
2218
- if (!iso) return "";
2219
- const date = new Date(iso);
2220
- if (Number.isNaN(date.getTime())) return "";
2221
- const pad = (n) => String(n).padStart(2, "0");
2222
- return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
2223
- }
2224
- function fromLocalInput(local) {
2225
- if (!local) return void 0;
2226
- const date = new Date(local);
2227
- return Number.isNaN(date.getTime()) ? void 0 : date.toISOString();
2228
- }
2229
- function asDateRange(value) {
2230
- return typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
2231
- }
2232
- function DateRangeField(props) {
2233
- const range = asDateRange(props.value);
2234
- const setPreset = (preset) => props.onCommit(preset === "" ? void 0 : preset === "custom" ? {
2235
- preset,
2236
- after: range.after,
2237
- before: range.before
2238
- } : { preset });
2239
- return /* @__PURE__ */ jsxs("div", {
2240
- className: "flex flex-col gap-2",
2241
- children: [props.dropdown ? /* @__PURE__ */ jsx(Select, {
2242
- id: props.id,
2243
- options: DATE_PRESETS,
2244
- value: range.preset ?? "",
2245
- onChange: setPreset,
2246
- invalid: props.invalid,
2247
- clearable: props.clearable,
2248
- placeholder: "Choose a range"
2249
- }) : /* @__PURE__ */ jsx("div", {
2250
- id: props.id,
2251
- role: "radiogroup",
2252
- className: "flex flex-wrap gap-1.5",
2253
- children: DATE_PRESETS.map((preset) => {
2254
- const selected = range.preset === preset.value;
2255
- return /* @__PURE__ */ jsx("button", {
2256
- type: "button",
2257
- role: "radio",
2258
- "aria-checked": selected,
2259
- 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"}`,
2260
- onClick: () => setPreset(selected && props.clearable ? "" : preset.value),
2261
- children: preset.label
2262
- }, preset.value);
2263
- })
2264
- }), range.preset === "custom" ? /* @__PURE__ */ jsx("div", {
2265
- className: "grid grid-cols-2 gap-2",
2266
- children: ["after", "before"].map((edge) => /* @__PURE__ */ jsxs("label", {
2267
- className: "flex flex-col gap-1 text-xs text-muted-foreground",
2268
- children: [edge === "after" ? "From" : "To", /* @__PURE__ */ jsx("input", {
2269
- type: "datetime-local",
2270
- className: textInputClass,
2271
- defaultValue: toLocalInput(range[edge]),
2272
- onBlur: (event) => props.onCommit({
2273
- ...range,
2274
- [edge]: fromLocalInput(event.target.value)
2275
- })
2276
- })]
2277
- }, edge))
2278
- }) : null]
2279
- });
2280
- }
2281
- const HEX = /^#[0-9a-f]{6}$/i;
2282
- /** COLOR: a swatch picker beside a text field that also takes expressions. */
2283
- function ColorField(props) {
2284
- const text = typeof props.value === "string" ? props.value : "";
2285
- const [draft, setDraft] = useState(null);
2286
- const swatchRef = useRef(null);
2287
- const onCommit = props.onCommit;
2288
- useEffect(() => {
2289
- const swatch = swatchRef.current;
2290
- if (!swatch) return;
2291
- const commit = () => {
2292
- setDraft(null);
2293
- onCommit(swatch.value);
2294
- };
2295
- swatch.addEventListener("change", commit);
2296
- return () => swatch.removeEventListener("change", commit);
2297
- }, [onCommit]);
2298
- return /* @__PURE__ */ jsxs("div", {
2299
- className: "flex items-center gap-2",
2300
- children: [/* @__PURE__ */ jsx("input", {
2301
- ref: swatchRef,
2302
- type: "color",
2303
- "aria-label": "Pick a colour",
2304
- className: "h-9 w-10 shrink-0 cursor-pointer rounded-md border border-solid border-foreground/15 bg-card p-1",
2305
- value: draft ?? (HEX.test(text) ? text : "#000000"),
2306
- onChange: (event) => setDraft(event.target.value)
2307
- }), /* @__PURE__ */ jsx("input", {
2308
- id: props.id,
2309
- className: `${textInputClass} font-mono text-xs ${props.invalid ? invalidClass : ""}`,
2310
- defaultValue: text,
2311
- placeholder: "#1d63d6 or {{steps.…}}",
2312
- spellCheck: false,
2313
- onFocus: props.onFocus,
2314
- onBlur: (event) => {
2315
- const raw = event.target.value.trim();
2316
- props.onCommit(raw === "" ? void 0 : raw);
2317
- }
2318
- }, text)]
2319
- });
2320
- }
2321
- function richTextMode(format) {
2322
- if (format === "html") return "html";
2323
- if (format === "markdown" || format === "md") return "markdown";
2324
- return "plain";
2325
- }
2326
- //#endregion
2327
- //#region editors/workflow-editor/ui/prop-layout.tsx
2328
- const PLACED = /* @__PURE__ */ new Set([
2329
- "section",
2330
- "tabs",
2331
- "builder",
2332
- "footer"
2333
- ]);
2334
- function chipText(value) {
2335
- if (typeof value === "string") return value;
2336
- if (typeof value === "number" || typeof value === "boolean") return String(value);
2337
- if (Array.isArray(value)) return value.map(chipText).join(", ");
2338
- return "set";
2339
- }
2340
- /** Consecutive `width: 'half'` fields share a row, two at a time. */
2341
- function Rows(props) {
2342
- const rows = [];
2343
- let pending = null;
2344
- const flush = () => {
2345
- if (pending) rows.push(/* @__PURE__ */ jsx(Fragment, { children: pending.node }, pending.prop.name));
2346
- pending = null;
2347
- };
2348
- for (const item of props.items) {
2349
- if (item.prop.width !== "half") {
2350
- flush();
2351
- rows.push(/* @__PURE__ */ jsx(Fragment, { children: item.node }, item.prop.name));
2352
- continue;
2353
- }
2354
- if (!pending) {
2355
- pending = item;
2356
- continue;
2357
- }
2358
- const first = pending;
2359
- pending = null;
2360
- rows.push(/* @__PURE__ */ jsxs("div", {
2361
- className: "grid grid-cols-1 gap-4 min-[420px]:grid-cols-2",
2362
- children: [/* @__PURE__ */ jsx("div", {
2363
- className: "min-w-0",
2364
- children: first.node
2365
- }), /* @__PURE__ */ jsx("div", {
2366
- className: "min-w-0",
2367
- children: item.node
2368
- })]
2369
- }, `${first.prop.name}+${item.prop.name}`));
2370
- }
2371
- flush();
2372
- return /* @__PURE__ */ jsx(Fragment$1, { children: rows });
2373
- }
2374
- function RevealCard(props) {
2375
- const open = props.layout.values[props.checkbox.name] === true;
2376
- return /* @__PURE__ */ jsxs("div", {
2377
- className: "flex flex-col gap-4",
2378
- children: [props.layout.renderField(props.checkbox), open && props.revealed.length > 0 ? /* @__PURE__ */ jsx("div", {
2379
- className: "flex flex-col gap-4 border-l-2 border-solid border-foreground/10 pl-3",
2380
- children: /* @__PURE__ */ jsx(Rows, { items: props.revealed.map((prop) => ({
2381
- prop,
2382
- node: props.layout.renderField(prop)
2383
- })) })
2384
- }) : null]
2385
- });
2386
- }
2387
- function FieldList(props) {
2388
- const byName = new Map(props.members.map((prop) => [prop.name, prop]));
2389
- const revealedBy = /* @__PURE__ */ new Map();
2390
- for (const prop of props.members) for (const name of prop.reveals ?? []) if (byName.has(name)) revealedBy.set(name, prop);
2391
- const items = props.members.filter((prop) => !revealedBy.has(prop.name)).map((prop) => {
2392
- const revealed = (prop.reveals ?? []).map((name) => byName.get(name)).filter((entry) => entry !== void 0);
2393
- return {
2394
- prop,
2395
- node: revealed.length > 0 ? /* @__PURE__ */ jsx(RevealCard, {
2396
- checkbox: prop,
2397
- revealed,
2398
- layout: props.layout
2399
- }) : props.layout.renderField(prop)
2400
- };
2401
- });
2402
- return /* @__PURE__ */ jsx(Rows, { items });
2403
- }
2404
- function GroupHeading(props) {
2405
- const { group } = props;
2406
- if (!group.label && !group.description) return null;
2407
- return /* @__PURE__ */ jsxs("div", {
2408
- className: "flex flex-col gap-0.5",
2409
- children: [group.label ? /* @__PURE__ */ jsxs("span", {
2410
- className: "flex items-center gap-1.5 text-[13px] font-semibold text-foreground",
2411
- children: [isIconName(group.icon) ? /* @__PURE__ */ jsx(Icon, {
2412
- name: group.icon,
2413
- className: "h-3.5 w-3.5 text-muted-foreground"
2414
- }) : null, group.label]
2415
- }) : null, group.description ? /* @__PURE__ */ jsx("span", {
2416
- className: "text-xs text-muted-foreground",
2417
- children: group.description
2418
- }) : null]
2419
- });
2420
- }
2421
- function Section$1(props) {
2422
- return /* @__PURE__ */ jsxs("section", {
2423
- "aria-label": props.group.label,
2424
- className: "flex flex-col gap-4 rounded-lg border border-solid border-foreground/10 p-4",
2425
- children: [/* @__PURE__ */ jsx(GroupHeading, { group: props.group }), /* @__PURE__ */ jsx(FieldList, {
2426
- members: props.members,
2427
- layout: props.layout
2428
- })]
2429
- });
2430
- }
2431
- function TabbedGroup(props) {
2432
- const [active, setActive] = useState(props.members[0]?.name ?? "");
2433
- const current = props.members.find((prop) => prop.name === active) ?? props.members[0];
2434
- if (!current) return null;
2435
- return /* @__PURE__ */ jsxs("div", {
2436
- className: "flex flex-col gap-3",
2437
- children: [
2438
- /* @__PURE__ */ jsx(GroupHeading, { group: props.group }),
2439
- /* @__PURE__ */ jsx("div", {
2440
- className: "border-b border-solid border-foreground/10",
2441
- children: /* @__PURE__ */ jsx(Tabs, {
2442
- value: current.name,
2443
- onChange: setActive,
2444
- tabs: props.members.map((prop) => ({
2445
- value: prop.name,
2446
- label: prop.displayName,
2447
- badge: isEmptyValue(props.layout.values[prop.name]) ? void 0 : /* @__PURE__ */ jsx("span", {
2448
- "aria-label": "has a value",
2449
- className: "h-1.5 w-1.5 rounded-full bg-wf-run"
2450
- })
2451
- }))
2452
- })
2453
- }),
2454
- props.layout.renderField(current)
2455
- ]
2456
- });
2457
- }
2458
- function BuilderGroups(props) {
2459
- const members = props.groups.flatMap((group) => group.props.map((name) => props.byName.get(name)).filter((prop) => prop !== void 0));
2460
- const [added, setAdded] = useState([]);
2461
- const inUse = members.filter((prop) => prop.required || added.includes(prop.name) || !isEmptyValue(props.layout.values[prop.name]));
2462
- const available = members.filter((prop) => !inUse.includes(prop));
2463
- return /* @__PURE__ */ jsxs("div", {
2464
- className: "flex flex-col gap-3",
2465
- children: [
2466
- props.groups.map((group) => /* @__PURE__ */ jsx(GroupHeading, { group }, group.key)),
2467
- inUse.map((prop) => /* @__PURE__ */ jsxs("div", {
2468
- className: "flex items-start gap-1",
2469
- children: [/* @__PURE__ */ jsx("div", {
2470
- className: "min-w-0 flex-1",
2471
- children: props.layout.renderField(prop)
2472
- }), prop.required ? null : /* @__PURE__ */ jsx(IconButton, {
2473
- icon: "close",
2474
- label: `Remove ${prop.displayName}`,
2475
- className: "mt-7",
2476
- onClick: () => {
2477
- setAdded((names) => names.filter((name) => name !== prop.name));
2478
- props.layout.onCommit(prop.name, void 0);
2479
- }
2480
- })]
2481
- }, prop.name)),
2482
- available.length > 0 ? /* @__PURE__ */ jsx("div", {
2483
- className: "max-w-60",
2484
- children: /* @__PURE__ */ jsx(Select, {
2485
- options: available.map((prop) => ({
2486
- value: prop.name,
2487
- label: prop.displayName,
2488
- description: prop.description
2489
- })),
2490
- value: "",
2491
- placeholder: "Add filter",
2492
- onChange: (name) => {
2493
- if (name) setAdded((names) => [...names, name]);
2494
- }
2495
- })
2496
- }) : null
2497
- ]
2498
- });
2499
- }
2500
- function Summary(props) {
2501
- const set = props.members.filter((prop) => !isEmptyValue(props.layout.values[prop.name]));
2502
- if (set.length === 0) return null;
2503
- return /* @__PURE__ */ jsx("div", {
2504
- className: "flex flex-wrap gap-1.5",
2505
- "aria-label": "Filters in use",
2506
- children: set.map((prop) => /* @__PURE__ */ jsxs("span", {
2507
- 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",
2508
- children: [/* @__PURE__ */ jsxs("span", {
2509
- className: "truncate",
2510
- children: [
2511
- prop.displayName,
2512
- ": ",
2513
- chipText(props.layout.values[prop.name])
2514
- ]
2515
- }), /* @__PURE__ */ jsx("button", {
2516
- type: "button",
2517
- "aria-label": `Clear ${prop.displayName}`,
2518
- className: "flex h-4 w-4 items-center justify-center rounded-full text-muted-foreground hover:bg-foreground/10 hover:text-foreground",
2519
- onClick: () => props.layout.onCommit(prop.name, void 0),
2520
- children: /* @__PURE__ */ jsx(Icon, {
2521
- name: "close",
2522
- className: "h-3 w-3"
2523
- })
2524
- })]
2525
- }, prop.name))
2526
- });
2527
- }
2528
- function PropLayout(props) {
2529
- const groups = (props.groups ?? []).filter((group) => PLACED.has(group.display) || group.display === "summary");
2530
- const byName = new Map(props.props.map((prop) => [prop.name, prop]));
2531
- const groupOf = /* @__PURE__ */ new Map();
2532
- for (const group of groups) {
2533
- if (!PLACED.has(group.display)) continue;
2534
- for (const name of group.props) if (byName.has(name) && !groupOf.has(name)) groupOf.set(name, group);
2535
- }
2536
- const membersOf = (group) => group.props.map((name) => byName.get(name)).filter((prop) => prop !== void 0);
2537
- const builderGroups = groups.filter((group) => group.display === "builder");
2538
- const summaries = groups.filter((group) => group.display === "summary");
2539
- const sectionMembers = groups.filter((group) => group.display === "section").flatMap(membersOf);
2540
- const blocks = [];
2541
- let loose = [];
2542
- const flushLoose = () => {
2543
- if (loose.length === 0) return;
2544
- blocks.push(/* @__PURE__ */ jsx(FieldList, {
2545
- members: loose,
2546
- layout: props
2547
- }, `loose:${loose[0].name}`));
2548
- loose = [];
2549
- };
2550
- const summarised = summaries.length > 0 && sectionMembers.length > 0;
2551
- const placed = /* @__PURE__ */ new Set();
2552
- for (const prop of props.props) {
2553
- const group = groupOf.get(prop.name);
2554
- if (!group) {
2555
- loose.push(prop);
2556
- continue;
2557
- }
2558
- const key = group.display === "builder" ? "builder" : group.key;
2559
- if (placed.has(key)) continue;
2560
- placed.add(key);
2561
- flushLoose();
2562
- if (group.display === "builder") blocks.push(/* @__PURE__ */ jsx(BuilderGroups, {
2563
- groups: builderGroups,
2564
- byName,
2565
- layout: props
2566
- }, "builder"));
2567
- else if (group.display === "tabs") blocks.push(/* @__PURE__ */ jsx(TabbedGroup, {
2568
- group,
2569
- members: membersOf(group),
2570
- layout: props
2571
- }, group.key));
2572
- else if (group.display === "footer") blocks.push(/* @__PURE__ */ jsxs("div", {
2573
- className: "flex flex-col gap-4 border-t border-solid border-foreground/10 pt-4",
2574
- children: [/* @__PURE__ */ jsx(GroupHeading, { group }), /* @__PURE__ */ jsx(FieldList, {
2575
- members: membersOf(group),
2576
- layout: props
2577
- })]
2578
- }, group.key));
2579
- else {
2580
- if (summarised && !placed.has("summary")) {
2581
- placed.add("summary");
2582
- blocks.push(/* @__PURE__ */ jsx(Summary, {
2583
- members: sectionMembers,
2584
- layout: props
2585
- }, "summary"));
2586
- }
2587
- blocks.push(/* @__PURE__ */ jsx(Section$1, {
2588
- group,
2589
- members: membersOf(group),
2590
- layout: props
2591
- }, group.key));
2592
- }
2593
- }
2594
- flushLoose();
2595
- return /* @__PURE__ */ jsx(Fragment$1, { children: blocks });
2596
- }
2597
- //#endregion
2598
- //#region editors/workflow-editor/ui/PropertyForm.tsx
2599
- function insertAtCursor$1(element, text) {
2600
- const start = element.selectionStart ?? element.value.length;
2601
- const end = element.selectionEnd ?? start;
2602
- element.value = element.value.slice(0, start) + text + element.value.slice(end);
2603
- return element.value;
2604
- }
2605
- const WHOLE_EXPRESSION = /^\{\{\s*[^{}]+?\s*\}\}$/;
2606
- const DECIMAL = /^-?(?:\d+(?:\.\d*)?|\.\d+)$/;
2607
- function parseDecimal(raw) {
2608
- const trimmed = raw.trim();
2609
- return DECIMAL.test(trimmed) ? Number(trimmed) : void 0;
2610
- }
2611
- function stringifyValue$1(value) {
2612
- if (value === void 0 || value === null) return "";
2613
- if (typeof value === "string") return value;
2614
- try {
2615
- return JSON.stringify(value, null, 2);
2616
- } catch {
2617
- return String(value);
2618
- }
2619
- }
2620
- function parseDropdownResult(result) {
2621
- const record = result;
2622
- if (!record || !Array.isArray(record.options)) throw new Error("Unexpected options result");
2623
- return {
2624
- options: record.options.map((option) => ({
2625
- label: stringifyValue$1(option.label ?? option.value),
2626
- value: option.value,
2627
- ...typeof option.description === "string" && option.description ? { description: option.description } : {},
2628
- ...typeof option.icon === "string" ? { icon: option.icon } : {}
2629
- })),
2630
- placeholder: record.placeholder,
2631
- disabled: record.disabled
2632
- };
2633
- }
2634
- const RELOAD_DEBOUNCE_MS = 400;
2635
- const PieceMarkdown = lazy(() => import("./PieceMarkdown-U6OUTwRi.js"));
2636
- const NO_ENDPOINT = "[no endpoint yet — see Endpoint URL above]";
2637
- function fillPiecePlaceholders(text, values) {
2638
- return text.replace(/\{\{\s*webhookUrl\s*\}\}/g, values.webhookUrl ?? NO_ENDPOINT).replace(/\{\{\s*webhookTimeoutSeconds\s*\}\}/g, values.webhookTimeoutSeconds === void 0 ? "{{webhookTimeoutSeconds}}" : String(values.webhookTimeoutSeconds));
2639
- }
2640
- function AvailableSoon(props) {
2641
- return /* @__PURE__ */ jsxs("span", {
2642
- 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",
2643
- title: "Not supported by the runtime yet",
2644
- children: ["Available soon", props.children ? /* @__PURE__ */ jsxs("span", { children: [": ", props.children] }) : null]
2645
- });
2646
- }
2647
- function FieldShell(props) {
2648
- const { prop } = props;
2649
- const LabelTag = props.htmlFor ? "label" : "span";
2650
- return /* @__PURE__ */ jsxs("div", {
2651
- className: "group/field",
2652
- children: [
2653
- /* @__PURE__ */ jsxs("div", {
2654
- className: "mb-1.5 flex min-h-6 items-center justify-between gap-2",
2655
- children: [/* @__PURE__ */ jsxs(LabelTag, {
2656
- htmlFor: props.htmlFor,
2657
- className: "flex min-w-0 items-baseline gap-1.5 text-[13px] font-medium text-foreground",
2658
- children: [
2659
- optionIcon(prop.icon),
2660
- /* @__PURE__ */ jsx("span", {
2661
- className: "truncate",
2662
- children: prop.displayName
2663
- }),
2664
- !prop.required ? /* @__PURE__ */ jsx("span", {
2665
- className: "shrink-0 text-xs font-normal text-muted-foreground",
2666
- children: "Optional"
2667
- }) : null,
2668
- props.invalid ? /* @__PURE__ */ jsx("span", {
2669
- className: "shrink-0 text-xs font-normal text-wf-warn",
2670
- children: "Needs a value"
2671
- }) : null
2672
- ]
2673
- }), props.picker ? /* @__PURE__ */ jsx("span", {
2674
- className: "flex shrink-0 items-center gap-0.5",
2675
- children: props.picker
2676
- }) : null]
2677
- }),
2678
- props.children,
2679
- /* @__PURE__ */ jsx(FieldError, { children: props.error }),
2680
- /* @__PURE__ */ jsx(Hint, { text: prop.description })
2681
- ]
2682
- });
2683
- }
2684
- function OptionList(props) {
2685
- const keyOf = (value) => stringifyValue$1(value);
2686
- const byKey = new Map(props.options.map((option) => [keyOf(option.value), option]));
2687
- return /* @__PURE__ */ jsx(Select, {
2688
- id: props.id,
2689
- multiple: true,
2690
- options: props.options.map((option) => ({
2691
- value: keyOf(option.value),
2692
- label: option.label
2693
- })),
2694
- value: props.selected.map(keyOf),
2695
- onChange: (keys) => props.onChange(keys.map((key) => byKey.get(key)?.value ?? key)),
2696
- invalid: props.invalid,
2697
- loading: props.loading,
2698
- onRefresh: props.onRefresh,
2699
- placeholder: props.placeholder ?? "Choose any"
2700
- });
2701
- }
2702
- function OptionSelect(props) {
2703
- const keyOf = (value) => stringifyValue$1(value);
2704
- const byKey = new Map(props.options.map((option) => [keyOf(option.value), option]));
2705
- return /* @__PURE__ */ jsx(Select, {
2706
- id: props.id,
2707
- options: props.options.map((option) => ({
2708
- value: keyOf(option.value),
2709
- label: option.label,
2710
- description: option.description,
2711
- icon: optionIcon(option.icon)
2712
- })),
2713
- value: keyOf(props.value),
2714
- onChange: (key) => props.onChange(key === "" ? void 0 : byKey.get(key)?.value ?? key),
2715
- invalid: props.invalid,
2716
- placeholder: props.placeholder,
2717
- loading: props.loading,
2718
- disabled: props.disabled,
2719
- onRefresh: props.onRefresh,
2720
- clearable: props.clearable,
2721
- emptyText: props.emptyText,
2722
- searchable: props.searchable,
2723
- actions: props.actions,
2724
- onQueryChange: props.onQueryChange
2725
- });
2726
- }
2727
- const SUMMARY_CHARS = 60;
2728
- function itemSummary(fields, row) {
2729
- const parts = [];
2730
- for (const field of fields) {
2731
- const value = row[field.name];
2732
- if (value === true) {
2733
- parts.push(field.displayName.toLowerCase());
2734
- continue;
2735
- }
2736
- if (value === void 0 || value === null || value === false) continue;
2737
- const option = field.staticOptions?.find((o) => o.value === value);
2738
- const text = option ? option.label : stringifyValue$1(value).trim();
2739
- if (!text) continue;
2740
- parts.push(text.length > SUMMARY_CHARS ? `${text.slice(0, SUMMARY_CHARS)}…` : text);
2741
- }
2742
- return parts.join(" · ");
2743
- }
2744
- function ArrayRows(props) {
2745
- const fields = props.prop.properties ?? [];
2746
- const rows = Array.isArray(props.value) ? props.value.map((item) => item !== null && typeof item === "object" ? item : {}) : [];
2747
- const [open, setOpen] = useState(() => /* @__PURE__ */ new Set());
2748
- const toggle = (index) => setOpen((current) => {
2749
- const next = new Set(current);
2750
- if (!next.delete(index)) next.add(index);
2751
- return next;
2752
- });
2753
- const update = (next) => props.onCommit(next.length > 0 ? next : void 0);
2754
- const remove = (index) => {
2755
- update(rows.filter((_, i) => i !== index));
2756
- setOpen((current) => new Set([...current].filter((i) => i !== index).map((i) => i > index ? i - 1 : i)));
2757
- };
2758
- return /* @__PURE__ */ jsxs("div", {
2759
- className: `flex flex-col gap-1.5 ${props.invalid ? "rounded-md ring-1 ring-wf-warn/50" : ""}`,
2760
- children: [rows.map((row, index) => {
2761
- const expanded = open.has(index);
2762
- const summary = itemSummary(fields, row);
2763
- return /* @__PURE__ */ jsxs("div", {
2764
- className: "rounded-md border border-solid border-foreground/10 bg-muted/40",
2765
- children: [/* @__PURE__ */ jsxs("div", {
2766
- className: "flex items-center gap-1 py-1 pl-1 pr-1",
2767
- children: [/* @__PURE__ */ jsxs("button", {
2768
- type: "button",
2769
- "aria-expanded": expanded,
2770
- onClick: () => toggle(index),
2771
- 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",
2772
- children: [/* @__PURE__ */ jsx(Icon, {
2773
- name: expanded ? "chevronDown" : "chevron",
2774
- className: "h-3.5 w-3.5 shrink-0 text-muted-foreground"
2775
- }), /* @__PURE__ */ jsx("span", {
2776
- className: `truncate ${summary ? "text-foreground" : "text-muted-foreground"}`,
2777
- children: summary || `Item ${index + 1}`
2778
- })]
2779
- }), /* @__PURE__ */ jsx(IconButton, {
2780
- icon: "trash",
2781
- label: `Remove item ${index + 1}`,
2782
- onClick: () => remove(index)
2783
- })]
2784
- }), expanded ? /* @__PURE__ */ jsx("div", {
2785
- className: "border-t border-solid border-foreground/10 px-3 pb-3 pt-2",
2786
- children: /* @__PURE__ */ jsx(PropertyForm, {
2787
- props: fields,
2788
- value: row,
2789
- onChange: (next) => update(rows.map((entry, i) => i === index ? next : entry)),
2790
- scopeStepId: props.scopeStepId,
2791
- nested: true
2792
- })
2793
- }) : null]
2794
- }, index);
2795
- }), /* @__PURE__ */ jsxs(Button, {
2796
- size: "sm",
2797
- className: "self-start",
2798
- onClick: () => {
2799
- update([...rows, withPropDefaults(fields, {})]);
2800
- setOpen((current) => new Set(current).add(rows.length));
2801
- },
2802
- children: [/* @__PURE__ */ jsx(Icon, {
2803
- name: "plus",
2804
- className: "h-3.5 w-3.5"
2805
- }), "Add item"]
2806
- })]
2807
- });
2808
- }
2809
- function rowsOf(value) {
2810
- return Object.entries(value).map(([key, entry]) => ({
2811
- key,
2812
- value: stringifyValue$1(entry)
2813
- }));
2814
- }
2815
- function recordOf(rows) {
2816
- const record = {};
2817
- for (const row of rows) if (row.key.trim() !== "") record[row.key.trim()] = row.value;
2818
- return record;
2819
- }
2820
- function ObjectRows(props) {
2821
- const [rows, setRows] = useState(() => rowsOf(props.value));
2822
- const valueKey = keyOf(props.value);
2823
- const [seen, setSeen] = useState(valueKey);
2824
- if (seen !== valueKey) {
2825
- setSeen(valueKey);
2826
- if (keyOf(recordOf(rows)) !== valueKey) setRows(rowsOf(props.value));
2827
- }
2828
- const commit = (next) => {
2829
- setRows(next);
2830
- const record = recordOf(next);
2831
- props.onCommit(Object.keys(record).length > 0 ? record : void 0);
2832
- };
2833
- return /* @__PURE__ */ jsxs("div", {
2834
- className: `flex flex-col gap-1.5 ${props.invalid ? "rounded-md ring-1 ring-wf-warn/50" : ""}`,
2835
- children: [rows.map((row, index) => /* @__PURE__ */ jsxs("div", {
2836
- className: "flex items-center gap-1",
2837
- children: [
2838
- /* @__PURE__ */ jsx("input", {
2839
- className: `${textInputClass} font-mono text-xs`,
2840
- placeholder: "Key",
2841
- value: row.key,
2842
- onChange: (event) => setRows(rows.map((entry, i) => i === index ? {
2843
- ...entry,
2844
- key: event.target.value
2845
- } : entry)),
2846
- onBlur: () => commit(rows)
2847
- }),
2848
- /* @__PURE__ */ jsx("input", {
2849
- className: `${textInputClass} font-mono text-xs`,
2850
- placeholder: "Value",
2851
- value: row.value,
2852
- onChange: (event) => setRows(rows.map((entry, i) => i === index ? {
2853
- ...entry,
2854
- value: event.target.value
2855
- } : entry)),
2856
- onBlur: () => commit(rows)
2857
- }),
2858
- /* @__PURE__ */ jsx(IconButton, {
2859
- icon: "close",
2860
- label: "Remove entry",
2861
- onClick: () => commit(rows.filter((_, i) => i !== index))
2862
- })
2863
- ]
2864
- }, index)), /* @__PURE__ */ jsxs(Button, {
2865
- size: "sm",
2866
- className: "self-start",
2867
- onClick: () => setRows([...rows, {
2868
- key: "",
2869
- value: ""
2870
- }]),
2871
- children: [/* @__PURE__ */ jsx(Icon, {
2872
- name: "plus",
2873
- className: "h-3.5 w-3.5"
2874
- }), "Add entry"]
2875
- })]
2876
- });
2877
- }
2878
- function isoToLocalInput(value) {
2879
- if (typeof value !== "string" || value === "") return "";
2880
- const date = new Date(value);
2881
- if (Number.isNaN(date.getTime())) return "";
2882
- const pad = (n) => String(n).padStart(2, "0");
2883
- return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
2884
- }
2885
- function localInputToIso(value) {
2886
- if (value === "") return void 0;
2887
- const date = new Date(value);
2888
- return Number.isNaN(date.getTime()) ? value : date.toISOString();
2889
- }
2890
- function isDropdownType(type) {
2891
- return type === "DROPDOWN" || type === "MULTI_SELECT_DROPDOWN";
2892
- }
2893
- const SEARCH_DEBOUNCE_MS = 300;
2894
- const FLIPS_TO_TEXT = /* @__PURE__ */ new Set([
2895
- "DATE_TIME",
2896
- "OBJECT",
2897
- "DROPDOWN",
2898
- "CHECKBOX",
2899
- "NUMBER"
2900
- ]);
2901
- const TEXT_MODE_TYPES = /* @__PURE__ */ new Set([
2902
- "SHORT_TEXT",
2903
- "LONG_TEXT",
2904
- "NUMBER",
2905
- "SECRET_TEXT",
2906
- "FILE",
2907
- "JSON",
2908
- "DATE_TIME",
2909
- "OBJECT",
2910
- "DROPDOWN",
2911
- "CHECKBOX"
2912
- ]);
2913
- function SecretRefField(props) {
2914
- const { secrets } = props;
2915
- const fieldId = useId();
2916
- const { ref, managed, draft, setDraft, busy, error, stat, commit } = useSecretRef({
2917
- value: props.value,
2918
- secrets,
2919
- label: props.prop.displayName,
2920
- onCommit: props.onCommit
2921
- });
2922
- if (!secrets) return /* @__PURE__ */ jsx(FieldShell, {
2923
- htmlFor: fieldId,
2924
- prop: props.prop,
2925
- invalid: props.invalid,
2926
- children: /* @__PURE__ */ jsx("p", {
2927
- className: "text-xs text-muted-foreground",
2928
- children: "Managed secrets are unavailable in this session."
2929
- })
2930
- });
2931
- return /* @__PURE__ */ jsxs(FieldShell, {
2932
- htmlFor: fieldId,
2933
- prop: props.prop,
2934
- invalid: props.invalid,
2935
- error,
2936
- children: [managed ? /* @__PURE__ */ jsxs("p", {
2937
- className: "mb-1.5 flex items-center gap-1.5 text-xs text-muted-foreground",
2938
- children: [
2939
- /* @__PURE__ */ jsx("span", {
2940
- className: "font-medium text-foreground",
2941
- children: stat?.label ?? ref
2942
- }),
2943
- stat ? /* @__PURE__ */ jsxs("span", { children: ["version ", stat.version] }) : null,
2944
- stat?.status === "DELETED" ? /* @__PURE__ */ jsx("span", {
2945
- className: "font-medium text-wf-fail",
2946
- children: "deleted"
2947
- }) : null
2948
- ]
2949
- }) : null, /* @__PURE__ */ jsxs("div", {
2950
- className: "flex items-center gap-1",
2951
- children: [/* @__PURE__ */ jsx("input", {
2952
- id: fieldId,
2953
- className: `${textInputClass} ${props.invalid ? invalidClass : ""}`,
2954
- type: "password",
2955
- value: draft,
2956
- disabled: busy,
2957
- placeholder: managed ? "Paste a new value to replace it" : "Paste the secret value",
2958
- autoComplete: "off",
2959
- spellCheck: false,
2960
- onChange: (event) => setDraft(event.target.value),
2961
- onKeyDown: (event) => {
2962
- if (event.key === "Enter") commit();
2963
- },
2964
- onBlur: commit
2965
- }), ref ? /* @__PURE__ */ jsx(IconButton, {
2966
- icon: "close",
2967
- label: "Remove secret",
2968
- onClick: () => props.onCommit(void 0)
2969
- }) : null]
2970
- })]
2971
- });
2972
- }
2973
- function ModeButton(props) {
2974
- return /* @__PURE__ */ jsx("button", {
2975
- type: "button",
2976
- 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",
2977
- onClick: props.onClick,
2978
- children: props.label
2979
- });
2980
- }
2981
- function PropField(props) {
2982
- const { prop, value } = props;
2983
- const fieldId = useId();
2984
- const optionsUnavailable = Boolean(props.nested && prop.hasDynamicResolver && !props.loadOptions);
2985
- const fieldRef = useRef(null);
2986
- const invalid = prop.required && prop.type !== "MARKDOWN" && isEmptyValue(value);
2987
- const [draft, setDraft] = useState(() => stringifyValue$1(value));
2988
- const [prevValue, setPrevValue] = useState(value);
2989
- if (value !== prevValue) {
2990
- setPrevValue(value);
2991
- setDraft(stringifyValue$1(value));
2992
- }
2993
- const [jsonError, setJsonError] = useState(null);
2994
- const [textMode, setTextMode] = useState(props.mode === "EXPRESSION");
2995
- const [prevMode, setPrevMode] = useState(props.mode);
2996
- if (props.mode !== prevMode) {
2997
- setPrevMode(props.mode);
2998
- if (props.mode) setTextMode(props.mode === "EXPRESSION");
2999
- }
3000
- const onCommit = (next, mode) => props.onCommit(next, mode ?? (textMode ? "EXPRESSION" : "MANUAL"));
3001
- const toMode = (expression) => {
3002
- setTextMode(expression);
3003
- props.onMode?.(expression ? "EXPRESSION" : "MANUAL");
3004
- };
3005
- const [numberError, setNumberError] = useState(null);
3006
- const commitsOnInsert = prop.type !== "JSON";
3007
- const field = useExpressionField({
3008
- stepId: props.scopeStepId,
3009
- label: prop.displayName,
3010
- insert: (expression) => {
3011
- if (FLIPS_TO_TEXT.has(prop.type) && !textMode) {
3012
- setTextMode(true);
3013
- setDraft(expression);
3014
- setNumberError(null);
3015
- onCommit(expression, "EXPRESSION");
3016
- return;
3017
- }
3018
- if (!fieldRef.current) return;
3019
- const next = insertAtCursor$1(fieldRef.current, expression);
3020
- setDraft(next);
3021
- if (commitsOnInsert) onCommit(next);
3022
- }
3023
- });
3024
- const picker = TEXT_MODE_TYPES.has(prop.type) ? /* @__PURE__ */ jsx(ExpressionPickerButton, {
3025
- active: field.active,
3026
- onFocusField: field.focus
3027
- }) : void 0;
3028
- const dynamicLoad = props.loadOptions && prop.hasDynamicResolver && !props.optionsBlocked ? () => props.loadOptions(prop.name) : void 0;
3029
- const isDropdown = prop.type === "DROPDOWN" || prop.type === "MULTI_SELECT_DROPDOWN";
3030
- const dropdown = useResolvedProp({
3031
- kind: "options",
3032
- input: props.resolverInput,
3033
- load: isDropdown ? dynamicLoad : void 0,
3034
- parse: parseDropdownResult,
3035
- debounceMs: RELOAD_DEBOUNCE_MS
3036
- });
3037
- const dynamic = useResolvedProp({
3038
- kind: "dynamic",
3039
- input: props.resolverInput,
3040
- load: prop.type === "DYNAMIC" ? dynamicLoad : void 0,
3041
- parse: parsePropList,
3042
- debounceMs: RELOAD_DEBOUNCE_MS
3043
- });
3044
- const dynamicFields = dynamic.state.kind === "ready" ? dynamic.state.result : null;
3045
- useEffect(() => {
3046
- if (value !== void 0 || !dynamicFields) return;
3047
- if (lacksDefaults(dynamicFields, {})) props.onCommit(withPropDefaults(dynamicFields, {}), "MANUAL");
3048
- }, [dynamicFields]);
3049
- const [searchQuery, setSearchQuery] = useState("");
3050
- const [picked, setPicked] = useState(null);
3051
- const loadOptions = props.loadOptions;
3052
- const searchable = Boolean(prop.refreshOnSearch && loadOptions);
3053
- const searchResult = useOptionSearch({
3054
- input: props.resolverInput,
3055
- query: searchQuery,
3056
- load: searchable && loadOptions ? (searchValue) => loadOptions(prop.name, searchValue) : void 0,
3057
- parse: parseDropdownResult,
3058
- debounceMs: SEARCH_DEBOUNCE_MS
3059
- });
3060
- const onSearch = searchable ? setSearchQuery : void 0;
3061
- const retryButton = (state, reload) => /* @__PURE__ */ jsx(IconButton, {
3062
- icon: "retry",
3063
- label: "Reload",
3064
- disabled: state.kind === "loading",
3065
- onClick: reload
3066
- });
3067
- const blocked = prop.hasDynamicResolver ? props.optionsBlocked : void 0;
3068
- const loadError = (state) => blocked ?? (state.kind === "error" ? props.explainOptionsError?.(state.message) ?? state.message : null);
3069
- const textInput = (extra) => /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("div", {
3070
- className: "flex items-center gap-1",
3071
- children: /* @__PURE__ */ jsx("input", {
3072
- id: fieldId,
3073
- ref: fieldRef,
3074
- type: extra.type ?? "text",
3075
- className: `${textInputClass} ${extra.mono ? "font-mono text-xs" : ""} ${invalid ? invalidClass : ""}`,
3076
- defaultValue: stringifyValue$1(value),
3077
- placeholder: extra.placeholder ?? prop.placeholder,
3078
- spellCheck: false,
3079
- onFocus: field.focus,
3080
- onChange: (event) => setDraft(event.target.value),
3081
- onBlur: (event) => extra.commit(event.target.value)
3082
- })
3083
- }), extra.type === "password" ? null : /* @__PURE__ */ jsx(ExpressionTokenLine, { value: draft })] });
3084
- switch (prop.type) {
3085
- case "PH_SECRET_REF": return /* @__PURE__ */ jsx(SecretRefField, {
3086
- prop,
3087
- value,
3088
- onCommit,
3089
- invalid,
3090
- secrets: props.secrets
3091
- });
3092
- case "MARKDOWN": {
3093
- const markdown = fillPiecePlaceholders(stringifyValue$1(prop.description ?? prop.defaultValue ?? prop.displayName), { webhookUrl: props.webhookUrl });
3094
- return /* @__PURE__ */ jsx(MarkdownCallout, {
3095
- variant: prop.variant,
3096
- children: /* @__PURE__ */ jsx(Suspense, {
3097
- fallback: /* @__PURE__ */ jsx("p", {
3098
- className: "whitespace-pre-wrap text-xs text-muted-foreground",
3099
- children: markdown
3100
- }),
3101
- children: /* @__PURE__ */ jsx(PieceMarkdown, { text: markdown })
3102
- })
3103
- });
3104
- }
3105
- case "CHECKBOX":
3106
- if (textMode) return /* @__PURE__ */ jsx(FieldShell, {
3107
- htmlFor: fieldId,
3108
- prop,
3109
- invalid,
3110
- picker: /* @__PURE__ */ jsxs(Fragment$1, { children: [picker, /* @__PURE__ */ jsx(ModeButton, {
3111
- label: "Use a switch",
3112
- onClick: () => {
3113
- setTextMode(false);
3114
- onCommit(void 0, "MANUAL");
3115
- }
3116
- })] }),
3117
- children: textInput({
3118
- mono: true,
3119
- placeholder: "{{steps.…}} yielding true or false",
3120
- commit: (raw) => {
3121
- const trimmed = raw.trim();
3122
- if (trimmed === "") {
3123
- setTextMode(false);
3124
- return onCommit(void 0, "MANUAL");
3125
- }
3126
- onCommit(trimmed, "EXPRESSION");
3127
- }
3128
- })
3129
- });
3130
- return /* @__PURE__ */ jsxs("div", {
3131
- className: "group/field flex items-start gap-1",
3132
- children: [/* @__PURE__ */ jsx("div", {
3133
- className: "min-w-0 flex-1",
3134
- children: /* @__PURE__ */ jsx(Switch, {
3135
- checked: value === true,
3136
- onChange: (checked) => onCommit(checked, "MANUAL"),
3137
- label: prop.displayName,
3138
- description: prop.description
3139
- })
3140
- }), picker]
3141
- });
3142
- case "NUMBER": {
3143
- const rangeError = numberRangeError(value, prop.min, prop.max);
3144
- const commitNumber = (raw) => {
3145
- const trimmed = raw.trim();
3146
- if (trimmed === "") {
3147
- setNumberError(null);
3148
- if (!textMode) return onCommit(void 0);
3149
- setTextMode(false);
3150
- return onCommit(void 0, "MANUAL");
3151
- }
3152
- if (textMode || hasExpressions(trimmed)) {
3153
- setNumberError(null);
3154
- setTextMode(true);
3155
- return onCommit(trimmed, "EXPRESSION");
3156
- }
3157
- const parsed = parseDecimal(trimmed);
3158
- if (parsed === void 0) {
3159
- setNumberError("Not a number");
3160
- return;
3161
- }
3162
- setNumberError(null);
3163
- onCommit(parsed);
3164
- };
3165
- if (prop.display === "stepper" && !textMode) return /* @__PURE__ */ jsx(FieldShell, {
3166
- htmlFor: fieldId,
3167
- prop,
3168
- invalid,
3169
- picker,
3170
- error: numberError ?? rangeError,
3171
- children: /* @__PURE__ */ jsx(NumberStepper, {
3172
- id: fieldId,
3173
- value,
3174
- min: prop.min,
3175
- max: prop.max,
3176
- step: prop.step,
3177
- invalid: invalid || rangeError !== null || numberError !== null,
3178
- onCommit: (next) => {
3179
- setNumberError(null);
3180
- onCommit(next);
3181
- },
3182
- onCommitText: commitNumber,
3183
- onFocus: field.focus
3184
- })
3185
- });
3186
- return /* @__PURE__ */ jsx(FieldShell, {
3187
- htmlFor: fieldId,
3188
- prop,
3189
- invalid,
3190
- picker,
3191
- error: numberError ?? (textMode ? null : rangeError),
3192
- children: textInput({
3193
- mono: textMode,
3194
- placeholder: textMode ? "{{expression}} yielding a number" : prop.placeholder ?? numberRangeText(prop.min, prop.max) ?? void 0,
3195
- commit: commitNumber
3196
- })
3197
- });
3198
- }
3199
- case "SECRET_TEXT": return /* @__PURE__ */ jsx(FieldShell, {
3200
- htmlFor: fieldId,
3201
- prop,
3202
- invalid,
3203
- picker,
3204
- children: textInput({
3205
- type: "password",
3206
- commit: (raw) => onCommit(raw === "" ? void 0 : raw)
3207
- })
3208
- });
3209
- case "FILE": return /* @__PURE__ */ jsx(FieldShell, {
3210
- htmlFor: fieldId,
3211
- prop,
3212
- invalid,
3213
- picker,
3214
- children: textInput({
3215
- mono: true,
3216
- placeholder: prop.placeholder ?? "https://… or data:…;base64,…",
3217
- commit: (raw) => onCommit(raw.trim() === "" ? void 0 : raw.trim())
3218
- })
3219
- });
3220
- case "DATE_TIME":
3221
- if (textMode) return /* @__PURE__ */ jsx(FieldShell, {
3222
- htmlFor: fieldId,
3223
- prop,
3224
- invalid,
3225
- picker,
3226
- children: textInput({
3227
- mono: true,
3228
- placeholder: "ISO 8601 or {{expression}}",
3229
- commit: (raw) => {
3230
- const trimmed = raw.trim();
3231
- if (trimmed === "") {
3232
- setTextMode(false);
3233
- return onCommit(void 0, "MANUAL");
3234
- }
3235
- onCommit(hasExpressions(trimmed) ? trimmed : localInputToIso(trimmed));
3236
- }
3237
- })
3238
- });
3239
- return /* @__PURE__ */ jsx(FieldShell, {
3240
- htmlFor: fieldId,
3241
- prop,
3242
- invalid,
3243
- picker,
3244
- children: /* @__PURE__ */ jsx("input", {
3245
- id: fieldId,
3246
- type: "datetime-local",
3247
- className: `${textInputClass} ${invalid ? invalidClass : ""}`,
3248
- defaultValue: isoToLocalInput(value),
3249
- onFocus: field.focus,
3250
- onBlur: (event) => onCommit(localInputToIso(event.target.value))
3251
- })
3252
- });
3253
- case "STATIC_DROPDOWN": {
3254
- const options = prop.staticOptions ?? [];
3255
- if (prop.display === "cards") return /* @__PURE__ */ jsx(FieldShell, {
3256
- htmlFor: fieldId,
3257
- prop,
3258
- invalid,
3259
- children: /* @__PURE__ */ jsx(OptionCards, {
3260
- id: fieldId,
3261
- options,
3262
- value,
3263
- keyOf: stringifyValue$1,
3264
- onChange: onCommit,
3265
- invalid,
3266
- clearable: !prop.required
3267
- })
3268
- });
3269
- 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, {
3270
- htmlFor: fieldId,
3271
- prop,
3272
- invalid: false,
3273
- children: /* @__PURE__ */ jsx(Segmented, {
3274
- value: stringifyValue$1(value),
3275
- options: options.map((option) => ({
3276
- value: stringifyValue$1(option.value),
3277
- label: option.label
3278
- })),
3279
- onChange: (key) => onCommit(options.find((option) => stringifyValue$1(option.value) === key)?.value ?? key)
3280
- })
3281
- });
3282
- return /* @__PURE__ */ jsx(FieldShell, {
3283
- htmlFor: fieldId,
3284
- prop,
3285
- invalid,
3286
- children: /* @__PURE__ */ jsx(OptionSelect, {
3287
- id: fieldId,
3288
- options: prop.staticOptions ?? [],
3289
- value,
3290
- onChange: onCommit,
3291
- invalid,
3292
- placeholder: prop.staticPlaceholder ?? prop.placeholder,
3293
- disabled: prop.staticDisabled && isEmptyValue(value),
3294
- clearable: !prop.required
3295
- })
3296
- });
3297
- }
3298
- case "STATIC_MULTI_SELECT_DROPDOWN": return /* @__PURE__ */ jsx(FieldShell, {
3299
- htmlFor: fieldId,
3300
- prop,
3301
- invalid,
3302
- children: /* @__PURE__ */ jsx(OptionList, {
3303
- id: fieldId,
3304
- options: prop.staticOptions ?? [],
3305
- selected: Array.isArray(value) ? value : [],
3306
- onChange: (next) => onCommit(next.length > 0 ? next : void 0),
3307
- invalid
3308
- })
3309
- });
3310
- case "DROPDOWN": {
3311
- if (textMode) return /* @__PURE__ */ jsx(FieldShell, {
3312
- htmlFor: fieldId,
3313
- prop,
3314
- invalid,
3315
- picker: /* @__PURE__ */ jsxs(Fragment$1, { children: [picker, /* @__PURE__ */ jsx(ModeButton, {
3316
- label: "Pick from list",
3317
- onClick: () => {
3318
- if (hasExpressions(value)) {
3319
- setTextMode(false);
3320
- onCommit(void 0, "MANUAL");
3321
- } else toMode(false);
3322
- }
3323
- })] }),
3324
- children: textInput({
3325
- mono: true,
3326
- placeholder: "{{steps.…}} or an id",
3327
- commit: (raw) => onCommit(raw.trim() === "" ? void 0 : raw)
3328
- })
3329
- });
3330
- const result = searchResult ?? (dropdown.state.kind === "ready" ? dropdown.state.result : null);
3331
- const listed = result?.options ?? [];
3332
- const options = picked !== null && stringifyValue$1(picked.value) === stringifyValue$1(value) && !listed.some((option) => stringifyValue$1(option.value) === stringifyValue$1(value)) ? [...listed, picked] : listed;
3333
- return /* @__PURE__ */ jsx(FieldShell, {
3334
- htmlFor: fieldId,
3335
- prop,
3336
- invalid,
3337
- error: loadError(dropdown.state),
3338
- picker: optionsUnavailable ? /* @__PURE__ */ jsx(AvailableSoon, {}) : picker,
3339
- children: /* @__PURE__ */ jsx(OptionSelect, {
3340
- id: fieldId,
3341
- options,
3342
- value,
3343
- onChange: (next) => {
3344
- setPicked(listed.find((option) => stringifyValue$1(option.value) === stringifyValue$1(next)) ?? null);
3345
- onCommit(next);
3346
- },
3347
- invalid,
3348
- loading: dropdown.state.kind === "loading",
3349
- disabled: result?.disabled && !stringifyValue$1(value) || optionsUnavailable,
3350
- onRefresh: dynamicLoad ? dropdown.reload : void 0,
3351
- clearable: !prop.required,
3352
- searchable: true,
3353
- onQueryChange: onSearch,
3354
- actions: [{
3355
- label: "Use data from an earlier step",
3356
- icon: "braces",
3357
- onSelect: () => {
3358
- toMode(true);
3359
- field.focus();
3360
- }
3361
- }],
3362
- emptyText: result?.placeholder ?? "Nothing to choose from yet. Some lists need a connection first.",
3363
- placeholder: optionsUnavailable ? "Options for nested fields are available soon" : dropdown.syncing ? "Waiting for the Switchboard…" : result?.placeholder ?? prop.placeholder ?? "Choose…"
3364
- })
3365
- });
3366
- }
3367
- case "MULTI_SELECT_DROPDOWN": {
3368
- const result = dropdown.state.kind === "ready" ? dropdown.state.result : null;
3369
- const selected = Array.isArray(value) ? value : [];
3370
- const listed = new Set((result?.options ?? []).map((o) => stringifyValue$1(o.value)));
3371
- const extra = selected.filter((entry) => !listed.has(stringifyValue$1(entry))).map((entry) => ({
3372
- label: stringifyValue$1(entry),
3373
- value: entry
3374
- }));
3375
- return /* @__PURE__ */ jsx(FieldShell, {
3376
- htmlFor: fieldId,
3377
- prop,
3378
- invalid,
3379
- error: loadError(dropdown.state),
3380
- picker: optionsUnavailable ? /* @__PURE__ */ jsx(AvailableSoon, {}) : void 0,
3381
- children: optionsUnavailable ? /* @__PURE__ */ jsx("p", {
3382
- className: "text-xs text-muted-foreground",
3383
- children: "Options for nested fields are available soon."
3384
- }) : /* @__PURE__ */ jsx(OptionList, {
3385
- id: fieldId,
3386
- options: [...extra, ...result?.options ?? []],
3387
- selected,
3388
- onChange: (next) => onCommit(next.length > 0 ? next : void 0),
3389
- invalid,
3390
- loading: dropdown.state.kind === "loading",
3391
- onRefresh: dynamicLoad ? dropdown.reload : void 0,
3392
- placeholder: result?.placeholder ?? prop.placeholder
3393
- })
3394
- });
3395
- }
3396
- case "DYNAMIC": {
3397
- const fields = dynamic.state.kind === "ready" ? dynamic.state.result : null;
3398
- const record = value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
3399
- return /* @__PURE__ */ jsx(FieldShell, {
3400
- htmlFor: fieldId,
3401
- prop,
3402
- invalid: invalid && fields !== null && fields.length > 0,
3403
- error: loadError(dynamic.state),
3404
- picker: optionsUnavailable ? /* @__PURE__ */ jsx(AvailableSoon, {}) : dynamicLoad ? retryButton(dynamic.state, dynamic.reload) : void 0,
3405
- children: optionsUnavailable ? /* @__PURE__ */ jsx("p", {
3406
- className: "text-xs text-muted-foreground",
3407
- children: "Nested dynamic properties are available soon."
3408
- }) : dynamic.state.kind === "loading" && !fields ? /* @__PURE__ */ jsx("p", {
3409
- className: "text-xs text-muted-foreground",
3410
- children: "Resolving properties…"
3411
- }) : !dynamicLoad ? /* @__PURE__ */ jsx("p", {
3412
- className: "text-xs text-muted-foreground",
3413
- children: "Properties resolve once the runtime is reachable."
3414
- }) : fields && fields.length > 0 ? /* @__PURE__ */ jsx("div", {
3415
- className: "rounded-lg border border-solid border-foreground/10 bg-muted/40 p-3",
3416
- children: /* @__PURE__ */ jsx(PropertyForm, {
3417
- props: fields,
3418
- value: record,
3419
- onChange: (next) => onCommit(Object.keys(next).length > 0 ? next : void 0),
3420
- scopeStepId: props.scopeStepId,
3421
- nested: true
3422
- })
3423
- }) : fields ? /* @__PURE__ */ jsx("p", {
3424
- className: "text-xs text-muted-foreground",
3425
- children: props.waitingOn ? `Pick ${props.waitingOn} first; its fields show here.` : "No properties for the current selection."
3426
- }) : null
3427
- });
3428
- }
3429
- case "ARRAY": {
3430
- if (prop.properties && prop.properties.length > 0) return /* @__PURE__ */ jsx(FieldShell, {
3431
- htmlFor: fieldId,
3432
- prop,
3433
- invalid,
3434
- children: /* @__PURE__ */ jsx(ArrayRows, {
3435
- prop,
3436
- value,
3437
- onCommit,
3438
- scopeStepId: props.scopeStepId,
3439
- invalid
3440
- })
3441
- });
3442
- if (textMode) return /* @__PURE__ */ jsx(FieldShell, {
3443
- htmlFor: fieldId,
3444
- prop,
3445
- invalid,
3446
- picker: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(ExpressionPickerButton, {
3447
- active: field.active,
3448
- onFocusField: field.focus
3449
- }), /* @__PURE__ */ jsx(ModeButton, {
3450
- label: "Enter items",
3451
- onClick: () => {
3452
- setTextMode(false);
3453
- const bound = stringifyValue$1(value).trim();
3454
- onCommit(bound ? [bound] : void 0, "MANUAL");
3455
- }
3456
- })] }),
3457
- children: textInput({
3458
- mono: true,
3459
- placeholder: "{{steps.…}} yielding a list",
3460
- commit: (raw) => onCommit(raw.trim() === "" ? void 0 : raw.trim(), "EXPRESSION")
3461
- })
3462
- });
3463
- const lines = Array.isArray(value) ? value.map((item) => stringifyValue$1(item)).join("\n") : stringifyValue$1(value);
3464
- return /* @__PURE__ */ jsxs(FieldShell, {
3465
- htmlFor: fieldId,
3466
- prop,
3467
- invalid,
3468
- picker: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(ExpressionPickerButton, {
3469
- active: field.active,
3470
- onFocusField: field.focus
3471
- }), /* @__PURE__ */ jsx(ModeButton, {
3472
- label: "Bind the whole list",
3473
- onClick: () => {
3474
- setTextMode(true);
3475
- onCommit(void 0, "EXPRESSION");
3476
- }
3477
- })] }),
3478
- children: [/* @__PURE__ */ jsx("textarea", {
3479
- id: fieldId,
3480
- ref: fieldRef,
3481
- className: `${textAreaClass} font-mono text-xs ${invalid ? invalidClass : ""}`,
3482
- defaultValue: lines,
3483
- placeholder: prop.placeholder ?? "One item per line",
3484
- spellCheck: false,
3485
- onFocus: field.focus,
3486
- onChange: (event) => setDraft(event.target.value),
3487
- onBlur: (event) => {
3488
- const items = event.target.value.split("\n").map((line) => line.trim()).filter((line) => line !== "");
3489
- if (items.length === 0) return onCommit(void 0);
3490
- onCommit(items);
3491
- }
3492
- }), /* @__PURE__ */ jsx(ExpressionTokenLine, { value: draft })]
3493
- });
3494
- }
3495
- case "OBJECT":
3496
- if (textMode) return /* @__PURE__ */ jsx(FieldShell, {
3497
- htmlFor: fieldId,
3498
- prop,
3499
- invalid,
3500
- picker,
3501
- children: textInput({
3502
- mono: true,
3503
- placeholder: "{{expression}} yielding an object",
3504
- commit: (raw) => {
3505
- const trimmed = raw.trim();
3506
- if (trimmed === "") {
3507
- setTextMode(false);
3508
- return onCommit(void 0, "MANUAL");
3509
- }
3510
- onCommit(trimmed);
3511
- }
3512
- })
3513
- });
3514
- return /* @__PURE__ */ jsx(FieldShell, {
3515
- htmlFor: fieldId,
3516
- prop,
3517
- invalid,
3518
- picker,
3519
- children: /* @__PURE__ */ jsx(ObjectRows, {
3520
- value: value !== null && typeof value === "object" && !Array.isArray(value) ? value : {},
3521
- onCommit,
3522
- invalid
3523
- })
3524
- });
3525
- case "DATE_RANGE": return /* @__PURE__ */ jsx(FieldShell, {
3526
- htmlFor: fieldId,
3527
- prop,
3528
- invalid,
3529
- children: /* @__PURE__ */ jsx(DateRangeField, {
3530
- id: fieldId,
3531
- value,
3532
- dropdown: prop.display === "dropdown",
3533
- invalid,
3534
- clearable: !prop.required,
3535
- onCommit
3536
- })
3537
- });
3538
- case "COLOR": return /* @__PURE__ */ jsx(FieldShell, {
3539
- htmlFor: fieldId,
3540
- prop,
3541
- invalid,
3542
- picker,
3543
- children: /* @__PURE__ */ jsx(ColorField, {
3544
- id: fieldId,
3545
- value,
3546
- invalid,
3547
- onCommit,
3548
- onFocus: field.focus
3549
- })
3550
- });
3551
- case "RICH_TEXT":
3552
- case "LONG_TEXT":
3553
- case "CUSTOM":
3554
- case "JSON": {
3555
- const isJson = prop.type === "JSON" || prop.type === "CUSTOM";
3556
- const mode = prop.type === "RICH_TEXT" ? richTextMode(prop.formatProperty ? props.config?.[prop.formatProperty] : "") : null;
3557
- return /* @__PURE__ */ jsxs(FieldShell, {
3558
- htmlFor: fieldId,
3559
- prop,
3560
- invalid,
3561
- picker: mode ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
3562
- className: "rounded bg-muted px-1.5 text-[11px] text-muted-foreground",
3563
- children: mode === "html" ? "HTML" : mode === "markdown" ? "Markdown" : "Plain text"
3564
- }), picker] }) : picker,
3565
- error: jsonError,
3566
- children: [/* @__PURE__ */ jsx("textarea", {
3567
- id: fieldId,
3568
- ref: fieldRef,
3569
- className: `${textAreaClass} ${isJson || mode === "html" || prop.display === "code" ? "font-mono text-xs" : ""} ${mode ? "min-h-32" : ""} ${invalid ? invalidClass : ""}`,
3570
- defaultValue: stringifyValue$1(value),
3571
- placeholder: prop.placeholder,
3572
- spellCheck: false,
3573
- onFocus: field.focus,
3574
- onChange: (event) => setDraft(event.target.value),
3575
- onBlur: (event) => {
3576
- const raw = event.target.value;
3577
- if (!isJson) return onCommit(raw === "" ? void 0 : raw);
3578
- const trimmed = raw.trim();
3579
- if (trimmed === "") {
3580
- setJsonError(null);
3581
- return onCommit(void 0);
3582
- }
3583
- if (WHOLE_EXPRESSION.test(trimmed)) {
3584
- setJsonError(null);
3585
- return onCommit(trimmed);
3586
- }
3587
- try {
3588
- onCommit(JSON.parse(trimmed));
3589
- setJsonError(null);
3590
- } catch {
3591
- setJsonError("Not valid JSON, so it wasn't saved.");
3592
- }
3593
- }
3594
- }), /* @__PURE__ */ jsx(ExpressionTokenLine, { value: draft })]
3595
- });
3596
- }
3597
- default: return /* @__PURE__ */ jsxs(FieldShell, {
3598
- htmlFor: fieldId,
3599
- prop,
3600
- invalid,
3601
- picker,
3602
- children: [prop.emptyChoice && value === "" ? null : textInput({ commit: (raw) => onCommit(raw === "" ? void 0 : raw) }), prop.emptyChoice ? /* @__PURE__ */ jsxs("label", {
3603
- className: "mt-1.5 flex items-center gap-2 text-xs text-muted-foreground",
3604
- children: [/* @__PURE__ */ jsx("input", {
3605
- type: "checkbox",
3606
- className: "h-3.5 w-3.5 accent-current",
3607
- checked: value === "",
3608
- onChange: (event) => onCommit(event.target.checked ? "" : void 0, "MANUAL")
3609
- }), prop.emptyChoice]
3610
- }) : null]
3611
- });
3612
- }
3613
- }
3614
- const NO_BLOCK = {
3615
- pieceName: "",
3616
- pieceVersion: "",
3617
- kind: "action",
3618
- name: ""
3619
- };
3620
- function PropertyForm(props) {
3621
- const echo = usePendingEcho({
3622
- value: props.value,
3623
- settings: props.settings ?? null
3624
- }, (next, shown) => {
3625
- if (next.settings !== shown.settings) props.onChange(next.value, next.settings ?? []);
3626
- else props.onChange(next.value);
3627
- });
3628
- const { value: current, settings } = echo.value;
3629
- const tracksSettings = props.writesSettings === true;
3630
- const readDynamic = useDynamicCache();
3631
- const withResolvedSchemas = (list, config) => {
3632
- let next = list;
3633
- for (const prop of props.props) {
3634
- if (prop.type !== "DYNAMIC") continue;
3635
- if (settingFor(next, prop.name)?.mode === "EXPRESSION") continue;
3636
- const fields = readDynamic(resolverInputFor(props.block ?? NO_BLOCK, prop, config, props.connectionId, props.reactorConnectionId));
3637
- if (!fields) continue;
3638
- const schema = stripOptions(fields);
3639
- const stored = settingFor(next, prop.name)?.schema ?? null;
3640
- if (JSON.stringify(stored) === JSON.stringify(schema)) continue;
3641
- next = withSetting(next, prop.name, { schema });
3642
- }
3643
- return next;
3644
- };
3645
- const commitField = (name, value, mode) => {
3646
- const next = { ...current };
3647
- if (value === void 0) delete next[name];
3648
- else next[name] = value;
3649
- let nextSettings = settings;
3650
- const nextMode = mode ?? settingFor(settings, name)?.mode ?? "MANUAL";
3651
- if (tracksSettings && settingFor(settings, name)?.mode !== nextMode) nextSettings = withSetting(nextSettings, name, { mode: nextMode });
3652
- if (value !== current[name]) for (const dependent of props.props) {
3653
- if (!dependent.refreshers?.includes(name)) continue;
3654
- if (isDropdownType(dependent.type)) delete next[dependent.name];
3655
- if (tracksSettings && dependent.type === "DYNAMIC" && settingFor(nextSettings, dependent.name)?.schema != null) nextSettings = withSetting(nextSettings, dependent.name, { schema: null });
3656
- }
3657
- if (tracksSettings) nextSettings = withResolvedSchemas(nextSettings, next);
3658
- echo.commit({
3659
- value: next,
3660
- settings: nextSettings
3661
- });
3662
- };
3663
- const setMode = (name, mode) => {
3664
- if (!tracksSettings || settingFor(settings, name)?.mode === mode) return;
3665
- echo.commit({
3666
- value: current,
3667
- settings: withResolvedSchemas(withSetting(settings, name, { mode }), current)
3668
- });
3669
- };
3670
- const visible = props.props.filter((prop) => isPropVisible(prop, current));
3671
- const essential = visible.filter((prop) => !prop.advanced);
3672
- const advanced = visible.filter((prop) => prop.advanced);
3673
- const [showAdvanced, setShowAdvanced] = useState(false);
3674
- const advancedSet = advanced.filter((prop) => current[prop.name] !== void 0).length;
3675
- const field = (prop) => /* @__PURE__ */ jsx(PropField, {
3676
- prop,
3677
- value: current[prop.name],
3678
- onCommit: (value, mode) => commitField(prop.name, value, mode),
3679
- mode: settingFor(settings, prop.name)?.mode,
3680
- onMode: (mode) => setMode(prop.name, mode),
3681
- loadOptions: props.loadOptions ? (propName, searchValue) => props.loadOptions(propName, current, searchValue) : void 0,
3682
- config: current,
3683
- secrets: props.secrets,
3684
- scopeStepId: props.scopeStepId,
3685
- optionsBlocked: props.optionsBlocked,
3686
- explainOptionsError: props.explainOptionsError,
3687
- resolverInput: resolverInputFor(props.block ?? NO_BLOCK, prop, current, props.connectionId, props.reactorConnectionId),
3688
- waitingOn: props.props.find((sibling) => prop.refreshers?.includes(sibling.name) && isEmptyValue(current[sibling.name]))?.displayName,
3689
- nested: props.nested,
3690
- webhookUrl: props.webhookUrl
3691
- }, prop.name);
3692
- return /* @__PURE__ */ jsxs("div", {
3693
- className: `flex flex-col ${props.nested ? "gap-3" : "gap-5"}`,
3694
- onBlur: echo.onBlur,
3695
- children: [/* @__PURE__ */ jsx(PropLayout, {
3696
- props: essential,
3697
- groups: props.groups,
3698
- values: current,
3699
- renderField: field,
3700
- onCommit: commitField
3701
- }), advanced.length > 0 ? /* @__PURE__ */ jsxs("div", {
3702
- className: "flex flex-col gap-5 border-t border-solid border-foreground/10 pt-4",
3703
- children: [/* @__PURE__ */ jsxs("button", {
3704
- type: "button",
3705
- 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",
3706
- "aria-expanded": showAdvanced,
3707
- onClick: () => setShowAdvanced((open) => !open),
3708
- children: [
3709
- /* @__PURE__ */ jsx(Icon, {
3710
- name: "chevron",
3711
- className: `h-3.5 w-3.5 transition-transform ${showAdvanced ? "rotate-90" : ""}`
3712
- }),
3713
- "More options",
3714
- /* @__PURE__ */ jsx("span", {
3715
- className: "font-normal",
3716
- children: advancedSet > 0 ? `${advanced.length} fields, ${advancedSet} set` : `${advanced.length} fields`
3717
- })
3718
- ]
3719
- }), /* @__PURE__ */ jsx("div", {
3720
- hidden: !showAdvanced,
3721
- className: "flex flex-col gap-5",
3722
- children: /* @__PURE__ */ jsx(PropLayout, {
3723
- props: advanced,
3724
- groups: props.groups,
3725
- values: current,
3726
- renderField: field,
3727
- onCommit: commitField
3728
- })
3729
- })]
3730
- }) : null]
3731
- });
3732
- }
3733
1206
  const DEFAULT_RETRY = {
3734
1207
  maxAttempts: 3,
3735
1208
  backoff: "EXPONENTIAL",
@@ -6977,10 +4450,11 @@ function WorkflowEditor() {
6977
4450
  }, block, config),
6978
4451
  documentOutput: async (reference) => {
6979
4452
  const referenced = modules?.filter((module) => module.documentModel.global.id === reference.documentType).sort((a, b) => (b.version ?? 1) - (a.version ?? 1)).at(0)?.documentModel.global;
6980
- return documentShape(reference, referenced ? await stateFieldsFromSdl({
4453
+ const global = referenced ? await stateFieldsFromSdl({
6981
4454
  name: referenced.name,
6982
4455
  schema: referenced.specifications.at(-1)?.state.global.schema ?? null
6983
- }) : {});
4456
+ }) : {};
4457
+ return documentShape(reference, global);
6984
4458
  },
6985
4459
  testOutput: async (blockId) => {
6986
4460
  const block = model.trigger?.id === blockId ? model.trigger : model.steps.find((step) => step.id === blockId);
@@ -7028,4 +4502,4 @@ function Editor({ document }) {
7028
4502
  //#endregion
7029
4503
  export { Editor as default };
7030
4504
 
7031
- //# sourceMappingURL=editor--59WtNaj.js.map
4505
+ //# sourceMappingURL=editor-B9069RYZ.js.map