@widgetic/workflows 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/LICENSE +122 -0
  2. package/README.md +304 -2
  3. package/dist/api/apiContext.d.ts +4 -0
  4. package/dist/api/apiContext.js +17 -0
  5. package/dist/api/types.d.ts +168 -0
  6. package/dist/api/types.js +3 -0
  7. package/dist/api/workflowsApi.d.ts +109 -0
  8. package/dist/api/workflowsApi.js +657 -0
  9. package/dist/components/Workflows.svelte +131 -0
  10. package/dist/components/Workflows.svelte.d.ts +4 -0
  11. package/dist/components/WorkflowsEmptyState.svelte +32 -0
  12. package/dist/components/WorkflowsEmptyState.svelte.d.ts +7 -0
  13. package/dist/components/WorkflowsHeader.svelte +14 -0
  14. package/dist/components/WorkflowsHeader.svelte.d.ts +18 -0
  15. package/dist/components/WorkflowsWorkspace.svelte +87 -0
  16. package/dist/components/WorkflowsWorkspace.svelte.d.ts +14 -0
  17. package/dist/components/canvas/AddBlockMenu.svelte +101 -0
  18. package/dist/components/canvas/AddBlockMenu.svelte.d.ts +5 -0
  19. package/dist/components/canvas/CanvasToolbar.svelte +95 -0
  20. package/dist/components/canvas/CanvasToolbar.svelte.d.ts +9 -0
  21. package/dist/components/canvas/CompositionNodeView.svelte +125 -0
  22. package/dist/components/canvas/CompositionNodeView.svelte.d.ts +5 -0
  23. package/dist/components/canvas/ConditionNodeView.svelte +95 -0
  24. package/dist/components/canvas/ConditionNodeView.svelte.d.ts +5 -0
  25. package/dist/components/canvas/HandlePoint.svelte +32 -0
  26. package/dist/components/canvas/HandlePoint.svelte.d.ts +14 -0
  27. package/dist/components/canvas/TriggerNodeView.svelte +75 -0
  28. package/dist/components/canvas/TriggerNodeView.svelte.d.ts +5 -0
  29. package/dist/components/canvas/WorkflowCanvas.svelte +380 -0
  30. package/dist/components/canvas/WorkflowCanvas.svelte.d.ts +25 -0
  31. package/dist/components/canvas/WorkflowEdgeView.svelte +58 -0
  32. package/dist/components/canvas/WorkflowEdgeView.svelte.d.ts +4 -0
  33. package/dist/components/editor/EditorBanners.svelte +143 -0
  34. package/dist/components/editor/EditorBanners.svelte.d.ts +7 -0
  35. package/dist/components/editor/EditorCanvasArea.svelte +85 -0
  36. package/dist/components/editor/EditorCanvasArea.svelte.d.ts +3 -0
  37. package/dist/components/editor/EditorTabs.svelte +81 -0
  38. package/dist/components/editor/EditorTabs.svelte.d.ts +7 -0
  39. package/dist/components/editor/EditorTopBar.svelte +132 -0
  40. package/dist/components/editor/EditorTopBar.svelte.d.ts +9 -0
  41. package/dist/components/editor/RunsTab.svelte +256 -0
  42. package/dist/components/editor/RunsTab.svelte.d.ts +3 -0
  43. package/dist/components/editor/SettingsTab.svelte +180 -0
  44. package/dist/components/editor/SettingsTab.svelte.d.ts +7 -0
  45. package/dist/components/editor/WorkflowEditor.svelte +185 -0
  46. package/dist/components/editor/WorkflowEditor.svelte.d.ts +15 -0
  47. package/dist/components/index.d.ts +1 -0
  48. package/dist/components/index.js +1 -0
  49. package/dist/components/list/CreateWorkflowDialog.svelte +89 -0
  50. package/dist/components/list/CreateWorkflowDialog.svelte.d.ts +9 -0
  51. package/dist/components/list/WorkflowList.svelte +204 -0
  52. package/dist/components/list/WorkflowList.svelte.d.ts +12 -0
  53. package/dist/components/list/WorkflowRow.svelte +191 -0
  54. package/dist/components/list/WorkflowRow.svelte.d.ts +10 -0
  55. package/dist/components/panel/BlockProblems.svelte +47 -0
  56. package/dist/components/panel/BlockProblems.svelte.d.ts +6 -0
  57. package/dist/components/panel/CompositionForm.svelte +127 -0
  58. package/dist/components/panel/CompositionForm.svelte.d.ts +7 -0
  59. package/dist/components/panel/CompositionPicker.svelte +179 -0
  60. package/dist/components/panel/CompositionPicker.svelte.d.ts +14 -0
  61. package/dist/components/panel/ConditionForm.svelte +105 -0
  62. package/dist/components/panel/ConditionForm.svelte.d.ts +7 -0
  63. package/dist/components/panel/EventValueRow.svelte +85 -0
  64. package/dist/components/panel/EventValueRow.svelte.d.ts +12 -0
  65. package/dist/components/panel/NextStepSelect.svelte +70 -0
  66. package/dist/components/panel/NextStepSelect.svelte.d.ts +12 -0
  67. package/dist/components/panel/ProblemsList.svelte +101 -0
  68. package/dist/components/panel/ProblemsList.svelte.d.ts +3 -0
  69. package/dist/components/panel/RuleCard.svelte +191 -0
  70. package/dist/components/panel/RuleCard.svelte.d.ts +13 -0
  71. package/dist/components/panel/SidePanel.svelte +82 -0
  72. package/dist/components/panel/SidePanel.svelte.d.ts +3 -0
  73. package/dist/components/panel/TestRow.svelte +150 -0
  74. package/dist/components/panel/TestRow.svelte.d.ts +15 -0
  75. package/dist/components/panel/TestRunPanel.svelte +85 -0
  76. package/dist/components/panel/TestRunPanel.svelte.d.ts +3 -0
  77. package/dist/components/panel/TestTriggerCard.svelte +121 -0
  78. package/dist/components/panel/TestTriggerCard.svelte.d.ts +7 -0
  79. package/dist/components/panel/TriggerForm.svelte +385 -0
  80. package/dist/components/panel/TriggerForm.svelte.d.ts +7 -0
  81. package/dist/components/panel/VersionHistory.svelte +123 -0
  82. package/dist/components/panel/VersionHistory.svelte.d.ts +3 -0
  83. package/dist/components/ui/ActionButton.svelte +85 -0
  84. package/dist/components/ui/ActionButton.svelte.d.ts +27 -0
  85. package/dist/components/ui/ConfirmDialog.svelte +52 -0
  86. package/dist/components/ui/ConfirmDialog.svelte.d.ts +16 -0
  87. package/dist/components/ui/Icon.svelte +32 -0
  88. package/dist/components/ui/Icon.svelte.d.ts +9 -0
  89. package/dist/components/ui/Menu.svelte +211 -0
  90. package/dist/components/ui/Menu.svelte.d.ts +21 -0
  91. package/dist/components/ui/Modal.svelte +129 -0
  92. package/dist/components/ui/Modal.svelte.d.ts +13 -0
  93. package/dist/components/ui/Notice.svelte +36 -0
  94. package/dist/components/ui/Notice.svelte.d.ts +11 -0
  95. package/dist/components/ui/SelectField.svelte +74 -0
  96. package/dist/components/ui/SelectField.svelte.d.ts +16 -0
  97. package/dist/components/ui/StatusBadge.svelte +41 -0
  98. package/dist/components/ui/StatusBadge.svelte.d.ts +9 -0
  99. package/dist/components/ui/TextField.svelte +97 -0
  100. package/dist/components/ui/TextField.svelte.d.ts +29 -0
  101. package/dist/components/ui/icons.d.ts +34 -0
  102. package/dist/components/ui/icons.js +54 -0
  103. package/dist/components/ui/types.d.ts +26 -0
  104. package/dist/components/ui/types.js +1 -0
  105. package/dist/editor/apiErrorText.d.ts +10 -0
  106. package/dist/editor/apiErrorText.js +53 -0
  107. package/dist/editor/autosave.d.ts +47 -0
  108. package/dist/editor/autosave.js +119 -0
  109. package/dist/editor/blockLabels.d.ts +91 -0
  110. package/dist/editor/blockLabels.js +196 -0
  111. package/dist/editor/canvasContext.d.ts +52 -0
  112. package/dist/editor/canvasContext.js +37 -0
  113. package/dist/editor/canvasWords.d.ts +24 -0
  114. package/dist/editor/canvasWords.js +40 -0
  115. package/dist/editor/capabilityModel.d.ts +46 -0
  116. package/dist/editor/capabilityModel.js +113 -0
  117. package/dist/editor/editorState.svelte.d.ts +220 -0
  118. package/dist/editor/editorState.svelte.js +713 -0
  119. package/dist/editor/flowAdapter.d.ts +59 -0
  120. package/dist/editor/flowAdapter.js +166 -0
  121. package/dist/editor/formatCount.d.ts +5 -0
  122. package/dist/editor/formatCount.js +15 -0
  123. package/dist/editor/graphDiff.d.ts +27 -0
  124. package/dist/editor/graphDiff.js +64 -0
  125. package/dist/editor/graphModel.d.ts +154 -0
  126. package/dist/editor/graphModel.js +457 -0
  127. package/dist/editor/issueText.d.ts +64 -0
  128. package/dist/editor/issueText.js +101 -0
  129. package/dist/editor/listState.svelte.d.ts +82 -0
  130. package/dist/editor/listState.svelte.js +250 -0
  131. package/dist/editor/statsRange.d.ts +26 -0
  132. package/dist/editor/statsRange.js +41 -0
  133. package/dist/editor/testRun.d.ts +36 -0
  134. package/dist/editor/testRun.js +74 -0
  135. package/dist/editor/zonedTime.d.ts +20 -0
  136. package/dist/editor/zonedTime.js +134 -0
  137. package/dist/i18n/index.d.ts +2 -0
  138. package/dist/i18n/index.js +2 -0
  139. package/dist/i18n/language.d.ts +22 -0
  140. package/dist/i18n/language.js +34 -0
  141. package/dist/i18n/messages.d.ts +423 -0
  142. package/dist/i18n/messages.js +446 -0
  143. package/dist/index.d.ts +4 -0
  144. package/dist/index.js +5 -0
  145. package/dist/types/index.d.ts +66 -0
  146. package/dist/types/index.js +1 -0
  147. package/dist/utils/logger.d.ts +4 -0
  148. package/dist/utils/logger.js +35 -0
  149. package/package.json +103 -5
@@ -0,0 +1,82 @@
1
+ import { type WorkflowsApi } from '../api/workflowsApi.js';
2
+ import type { CompositionOption, SortDirection, WorkflowDetail, WorkflowListItem, WorkflowSortField, WorkflowStateAction, WorkflowStatus } from '../api/types.js';
3
+ import type { WorkflowsMessageKey } from '../i18n/messages.js';
4
+ import type { WorkflowsError } from '../types/index.js';
5
+ /** What the list is filtered by. Empty is "not archived" (drafts, live and paused), which is what the API lists by default. */
6
+ export type ListStatusFilter = '' | WorkflowStatus | 'all';
7
+ /** One page of the list is this many workflows; "Show more" reads the next. */
8
+ export declare const LIST_PAGE_SIZE = 25;
9
+ /** How long the list waits after the last letter typed in the search before it asks. */
10
+ export declare const SEARCH_DELAY_MILLISECONDS = 300;
11
+ export interface WorkflowListOptions {
12
+ api: WorkflowsApi;
13
+ reportError: (error: WorkflowsError) => void;
14
+ /** For tests. */
15
+ searchDelayMilliseconds?: number;
16
+ /** For tests. */
17
+ pageSize?: number;
18
+ }
19
+ /** What the person is told after something they did in the list. */
20
+ export interface ListNotice {
21
+ tone: 'info' | 'problem';
22
+ messageKey: WorkflowsMessageKey;
23
+ values?: Record<string, string | number>;
24
+ }
25
+ /**
26
+ * The list of workflows: what is shown, how it is searched, filtered and ordered, and the things done to a workflow from
27
+ * its row (create, duplicate, pause, archive, delete). It asks the API for every change of the search or the order (the list
28
+ * can be longer than a page), and keeps the answer of the newest question only.
29
+ */
30
+ export declare class WorkflowListState {
31
+ items: readonly WorkflowListItem[];
32
+ total: number;
33
+ loadState: "loading" | "ready" | "failed";
34
+ loadingMore: boolean;
35
+ failure: "workflows.region.label" | "workflows.header.title" | "workflows.header.subtitle" | "workflows.common.cancel" | "workflows.common.close" | "workflows.common.dismiss" | "workflows.common.loading" | "workflows.empty.title" | "workflows.empty.hint" | "workflows.error.title" | "workflows.error.hint" | "workflows.error.retry" | "workflows.error.generic" | "workflows.error.network" | "workflows.error.timeout" | "workflows.error.server" | "workflows.error.sessionEnded" | "workflows.error.planRestricted" | "workflows.error.notFound" | "workflows.error.revisionChanged" | "workflows.error.archived" | "workflows.error.nothingToPublish" | "workflows.error.nothingToDiscard" | "workflows.error.everPublished" | "workflows.error.wrongState" | "workflows.error.tooManyWorkflows" | "workflows.error.publishBlocked" | "workflows.error.invalidGraph" | "workflows.error.tooManyRequests" | "workflows.list.label" | "workflows.list.newWorkflow" | "workflows.list.searchLabel" | "workflows.list.searchPlaceholder" | "workflows.list.filterLabel" | "workflows.list.filterActive" | "workflows.list.filterAll" | "workflows.list.sortLabel" | "workflows.list.sortCreated" | "workflows.list.sortPublished" | "workflows.list.sortRuns" | "workflows.list.sortName" | "workflows.list.sortAscending" | "workflows.list.sortDescending" | "workflows.list.columnName" | "workflows.list.columnStatus" | "workflows.list.columnRuns" | "workflows.list.columnPublished" | "workflows.list.columnCreated" | "workflows.list.compositionsCount" | "workflows.list.runsCount" | "workflows.list.publishedOn" | "workflows.list.neverPublished" | "workflows.list.never" | "workflows.list.open" | "workflows.list.rowMenu" | "workflows.list.showMore" | "workflows.list.noMatches" | "workflows.list.duplicated" | "workflows.list.deleted" | "workflows.create.title" | "workflows.create.nameLabel" | "workflows.create.namePlaceholder" | "workflows.create.compositionLabel" | "workflows.create.compositionHelp" | "workflows.create.create" | "workflows.create.creating" | "workflows.status.draft" | "workflows.status.live" | "workflows.status.paused" | "workflows.status.archived" | "workflows.status.unpublishedChanges" | "workflows.top.back" | "workflows.top.nameLabel" | "workflows.top.testRun" | "workflows.top.history" | "workflows.top.embedCode" | "workflows.top.publish" | "workflows.top.publishChanges" | "workflows.top.publishing" | "workflows.save.saved" | "workflows.save.saving" | "workflows.save.pending" | "workflows.save.failed" | "workflows.save.conflict" | "workflows.tabs.label" | "workflows.tabs.editor" | "workflows.tabs.runs" | "workflows.tabs.settings" | "workflows.banner.unpublishedChanges" | "workflows.banner.publishChanges" | "workflows.banner.discard" | "workflows.banner.discardTitle" | "workflows.banner.discardMessage" | "workflows.banner.neverPublished" | "workflows.banner.paused" | "workflows.banner.archived" | "workflows.banner.conflict" | "workflows.banner.reload" | "workflows.banner.touchOnly" | "workflows.editor.published" | "workflows.editor.discarded" | "workflows.editor.restored" | "workflows.editor.reloaded" | "workflows.editor.paused" | "workflows.editor.resumed" | "workflows.editor.archived" | "workflows.editor.unarchived" | "workflows.editor.saveFirst" | "workflows.editor.fixProblems" | "workflows.editor.blockLimit" | "workflows.publish.firstTitle" | "workflows.publish.firstMessage" | "workflows.publish.changesTitle" | "workflows.publish.changesMessage" | "workflows.leave.title" | "workflows.leave.message" | "workflows.leave.confirm" | "workflows.canvas.label" | "workflows.canvas.pointIn" | "workflows.canvas.pointOut" | "workflows.toolbar.label" | "workflows.toolbar.addBlock" | "workflows.toolbar.undo" | "workflows.toolbar.redo" | "workflows.toolbar.zoomIn" | "workflows.toolbar.zoomOut" | "workflows.toolbar.fit" | "workflows.addBlock.composition" | "workflows.addBlock.helpComposition" | "workflows.addBlock.condition" | "workflows.addBlock.helpCondition" | "workflows.addBlock.triggerHeading" | "workflows.addBlock.helpInput" | "workflows.addBlock.helpAction" | "workflows.addBlock.helpPageEvent" | "workflows.addBlock.helpScheduled" | "workflows.block.startsHere" | "workflows.block.trigger" | "workflows.block.condition" | "workflows.block.unknown" | "workflows.block.compositionNotChosen" | "workflows.block.compositionLoading" | "workflows.block.compositionUnavailable" | "workflows.block.notPublished" | "workflows.block.numbered" | "workflows.block.problems" | "workflows.panel.label" | "workflows.panel.overviewHeading" | "workflows.panel.overviewHelp" | "workflows.panel.problemsHeading" | "workflows.panel.problemsLabel" | "workflows.panel.noProblems" | "workflows.panel.manyBlocksSelected" | "workflows.panel.connectionSelected" | "workflows.panel.removeBlock" | "workflows.panel.removeBlocks" | "workflows.panel.removeConnection" | "workflows.composition.heading" | "workflows.composition.help" | "workflows.composition.searchLabel" | "workflows.composition.searchPlaceholder" | "workflows.composition.none" | "workflows.composition.alreadyUsed" | "workflows.composition.isStart" | "workflows.composition.makeStart" | "workflows.composition.capabilitiesHeading" | "workflows.composition.capabilityInput" | "workflows.composition.capabilityAction" | "workflows.composition.capabilityWebsites" | "workflows.composition.inputTables" | "workflows.composition.actionCount" | "workflows.trigger.heading" | "workflows.trigger.help" | "workflows.trigger.kindLabel" | "workflows.trigger.kindInput" | "workflows.trigger.kindAction" | "workflows.trigger.kindPageEvent" | "workflows.trigger.kindScheduled" | "workflows.trigger.unavailable" | "workflows.trigger.tableLabel" | "workflows.trigger.tableHelp" | "workflows.trigger.actionLabel" | "workflows.trigger.actionHelp" | "workflows.trigger.chooseOne" | "workflows.trigger.notFound" | "workflows.trigger.readableValues" | "workflows.trigger.noReadableValues" | "workflows.trigger.nextLabel" | "workflows.trigger.nextHelp" | "workflows.trigger.nextNone" | "workflows.trigger.summaryInput" | "workflows.trigger.summaryAction" | "workflows.trigger.summaryPageEvent" | "workflows.trigger.summaryAt" | "workflows.trigger.summaryUnfinished" | "workflows.reason.widgetKeepsNoData" | "workflows.reason.widgetReportsNoActions" | "workflows.reason.widgetNotPublished" | "workflows.schedule.modeLabel" | "workflows.schedule.modeAfter" | "workflows.schedule.modeAt" | "workflows.schedule.afterHelp" | "workflows.schedule.amountLabel" | "workflows.schedule.unitLabel" | "workflows.schedule.unitSeconds" | "workflows.schedule.unitMinutes" | "workflows.schedule.unitHours" | "workflows.schedule.unitDays" | "workflows.schedule.unitWeeks" | "workflows.schedule.waitSeconds" | "workflows.schedule.waitMinutes" | "workflows.schedule.waitHours" | "workflows.schedule.waitDays" | "workflows.schedule.waitWeeks" | "workflows.schedule.momentLabel" | "workflows.schedule.momentHelp" | "workflows.schedule.invalidMoment" | "workflows.event.nameLabel" | "workflows.event.namePlaceholder" | "workflows.event.nameHelp" | "workflows.event.nameInvalid" | "workflows.event.howToSend" | "workflows.event.valuesHeading" | "workflows.event.valuesHelp" | "workflows.event.addValue" | "workflows.event.valueName" | "workflows.event.valueNamePlaceholder" | "workflows.event.valueNameInvalid" | "workflows.event.valueType" | "workflows.event.removeValue" | "workflows.fieldType.text" | "workflows.fieldType.number" | "workflows.fieldType.boolean" | "workflows.value.yes" | "workflows.value.no" | "workflows.condition.heading" | "workflows.condition.help" | "workflows.condition.noTrigger" | "workflows.condition.noValues" | "workflows.condition.addRule" | "workflows.condition.ruleLimit" | "workflows.condition.defaultName" | "workflows.condition.defaultLabel" | "workflows.condition.defaultStay" | "workflows.condition.defaultHelp" | "workflows.condition.defaultHint" | "workflows.condition.defaultStays" | "workflows.rule.defaultName" | "workflows.rule.nameLabel" | "workflows.rule.moveUp" | "workflows.rule.moveDown" | "workflows.rule.remove" | "workflows.rule.matchLabel" | "workflows.rule.matchAll" | "workflows.rule.matchAny" | "workflows.rule.noTests" | "workflows.rule.addTest" | "workflows.rule.testLimit" | "workflows.rule.thenGoTo" | "workflows.rule.testWithValue" | "workflows.rule.testWithoutValue" | "workflows.rule.testAndMore" | "workflows.test.field" | "workflows.test.operator" | "workflows.test.value" | "workflows.test.valuePlaceholder" | "workflows.test.remove" | "workflows.operator.is" | "workflows.operator.isNot" | "workflows.operator.contains" | "workflows.operator.doesNotContain" | "workflows.operator.startsWith" | "workflows.operator.endsWith" | "workflows.operator.greaterThan" | "workflows.operator.atLeast" | "workflows.operator.lessThan" | "workflows.operator.atMost" | "workflows.operator.isEmpty" | "workflows.operator.isNotEmpty" | "workflows.test.heading" | "workflows.test.help" | "workflows.test.close" | "workflows.test.start" | "workflows.test.restart" | "workflows.test.ended" | "workflows.test.noStart" | "workflows.test.noTriggers" | "workflows.test.visitorIsOn" | "workflows.test.fire" | "workflows.test.resultMoved" | "workflows.test.resultStayed" | "workflows.test.resultIgnored" | "workflows.history.heading" | "workflows.history.help" | "workflows.history.close" | "workflows.history.none" | "workflows.history.failed" | "workflows.history.version" | "workflows.history.live" | "workflows.history.by" | "workflows.history.view" | "workflows.history.viewing" | "workflows.history.backToDraft" | "workflows.history.restore" | "workflows.history.restoreTitle" | "workflows.history.restoreMessage" | "workflows.runs.help" | "workflows.runs.rangeLabel" | "workflows.runs.lastDays" | "workflows.runs.versionLabel" | "workflows.runs.allVersions" | "workflows.runs.versionLive" | "workflows.runs.started" | "workflows.runs.entered" | "workflows.runs.fired" | "workflows.runs.failed" | "workflows.runs.none" | "workflows.runs.neverPublished" | "workflows.settings.zoneHeading" | "workflows.settings.zoneLabel" | "workflows.settings.zoneHelp" | "workflows.settings.embedHeading" | "workflows.settings.embedHelp" | "workflows.settings.stateHeading" | "workflows.settings.pause" | "workflows.settings.pauseHelp" | "workflows.settings.resume" | "workflows.settings.resumeHelp" | "workflows.settings.archive" | "workflows.settings.archiveHelp" | "workflows.settings.archiveTitle" | "workflows.settings.archiveMessage" | "workflows.settings.unarchive" | "workflows.settings.unarchiveHelp" | "workflows.settings.duplicate" | "workflows.settings.duplicateHelp" | "workflows.settings.delete" | "workflows.settings.deleteHelp" | "workflows.settings.deleteBlocked" | "workflows.settings.deleteTitle" | "workflows.settings.deleteMessage" | "workflows.issue.unknown" | "workflows.issue.malformed" | "workflows.issue.schemaVersion" | "workflows.issue.graphTooLarge" | "workflows.issue.unknownNodeType" | "workflows.issue.unknownTriggerKind" | "workflows.issue.badId" | "workflows.issue.duplicateId" | "workflows.issue.tooManyBlocks" | "workflows.issue.tooManyEdges" | "workflows.issue.noComposition" | "workflows.issue.noStart" | "workflows.issue.manyStarts" | "workflows.issue.compositionMissingId" | "workflows.issue.duplicateComposition" | "workflows.issue.compositionNotAvailable" | "workflows.issue.compositionWebsiteMismatch" | "workflows.issue.unreachableBlock" | "workflows.issue.edgeUnknownNode" | "workflows.issue.edgeBadPort" | "workflows.issue.edgeInvalidConnection" | "workflows.issue.portManyTargets" | "workflows.issue.cycle" | "workflows.issue.triggerNoSource" | "workflows.issue.triggerManySources" | "workflows.issue.triggerNoTarget" | "workflows.issue.triggerConfigIncomplete" | "workflows.issue.triggerNeedsTable" | "workflows.issue.triggerNeedsAction" | "workflows.issue.triggerNeedsName" | "workflows.issue.scheduleInvalid" | "workflows.issue.eventValueInvalid" | "workflows.issue.eventTooManyValues" | "workflows.issue.triggerCapabilityMissing" | "workflows.issue.triggerInputMissing" | "workflows.issue.triggerActionMissing" | "workflows.issue.conditionNoSource" | "workflows.issue.conditionManySources" | "workflows.issue.conditionNoCases" | "workflows.issue.conditionTooManyCases" | "workflows.issue.caseBadId" | "workflows.issue.caseDuplicateId" | "workflows.issue.caseNoTests" | "workflows.issue.caseTooManyTests" | "workflows.issue.caseNoTarget" | "workflows.issue.testBadField" | "workflows.issue.testBadOperator" | "workflows.issue.testMissingValue" | "workflows.issue.fieldUnknown" | null;
36
+ search: string;
37
+ statusFilter: ListStatusFilter;
38
+ sortField: WorkflowSortField;
39
+ sortDirection: SortDirection;
40
+ /** Workflows something is being done to (a duplicate on its way, a state change). */
41
+ busyIds: ReadonlySet<string>;
42
+ notice: ListNotice | null;
43
+ /** Whether there is more of the list than is shown. */
44
+ hasMore: boolean;
45
+ /** Whether the person asked for anything that narrows the list (so "nothing" means "nothing matches", not "nothing yet"). */
46
+ isNarrowed: boolean;
47
+ private readonly api;
48
+ private readonly reportError;
49
+ private readonly searchDelay;
50
+ private readonly pageSize;
51
+ private controller;
52
+ private searchTimer;
53
+ private disposed;
54
+ constructor(options: WorkflowListOptions);
55
+ dispose(): void;
56
+ private buildQuery;
57
+ /** Reads the first page again with the search, the filter and the order as they are now. */
58
+ load(): Promise<void>;
59
+ /** Reads the next page and adds it to the end. */
60
+ loadMore(): Promise<void>;
61
+ /** The person typed in the search: ask again once they stop. */
62
+ setSearch(text: string): void;
63
+ setStatusFilter(filter: ListStatusFilter): void;
64
+ setSort(field: WorkflowSortField): void;
65
+ toggleSortDirection(): void;
66
+ private setBusy;
67
+ private runFor;
68
+ /** Makes a workflow (the dialog asked). Resolves to it, or to `undefined` with the reason in `createFailure`. */
69
+ createFailure: "workflows.region.label" | "workflows.header.title" | "workflows.header.subtitle" | "workflows.common.cancel" | "workflows.common.close" | "workflows.common.dismiss" | "workflows.common.loading" | "workflows.empty.title" | "workflows.empty.hint" | "workflows.error.title" | "workflows.error.hint" | "workflows.error.retry" | "workflows.error.generic" | "workflows.error.network" | "workflows.error.timeout" | "workflows.error.server" | "workflows.error.sessionEnded" | "workflows.error.planRestricted" | "workflows.error.notFound" | "workflows.error.revisionChanged" | "workflows.error.archived" | "workflows.error.nothingToPublish" | "workflows.error.nothingToDiscard" | "workflows.error.everPublished" | "workflows.error.wrongState" | "workflows.error.tooManyWorkflows" | "workflows.error.publishBlocked" | "workflows.error.invalidGraph" | "workflows.error.tooManyRequests" | "workflows.list.label" | "workflows.list.newWorkflow" | "workflows.list.searchLabel" | "workflows.list.searchPlaceholder" | "workflows.list.filterLabel" | "workflows.list.filterActive" | "workflows.list.filterAll" | "workflows.list.sortLabel" | "workflows.list.sortCreated" | "workflows.list.sortPublished" | "workflows.list.sortRuns" | "workflows.list.sortName" | "workflows.list.sortAscending" | "workflows.list.sortDescending" | "workflows.list.columnName" | "workflows.list.columnStatus" | "workflows.list.columnRuns" | "workflows.list.columnPublished" | "workflows.list.columnCreated" | "workflows.list.compositionsCount" | "workflows.list.runsCount" | "workflows.list.publishedOn" | "workflows.list.neverPublished" | "workflows.list.never" | "workflows.list.open" | "workflows.list.rowMenu" | "workflows.list.showMore" | "workflows.list.noMatches" | "workflows.list.duplicated" | "workflows.list.deleted" | "workflows.create.title" | "workflows.create.nameLabel" | "workflows.create.namePlaceholder" | "workflows.create.compositionLabel" | "workflows.create.compositionHelp" | "workflows.create.create" | "workflows.create.creating" | "workflows.status.draft" | "workflows.status.live" | "workflows.status.paused" | "workflows.status.archived" | "workflows.status.unpublishedChanges" | "workflows.top.back" | "workflows.top.nameLabel" | "workflows.top.testRun" | "workflows.top.history" | "workflows.top.embedCode" | "workflows.top.publish" | "workflows.top.publishChanges" | "workflows.top.publishing" | "workflows.save.saved" | "workflows.save.saving" | "workflows.save.pending" | "workflows.save.failed" | "workflows.save.conflict" | "workflows.tabs.label" | "workflows.tabs.editor" | "workflows.tabs.runs" | "workflows.tabs.settings" | "workflows.banner.unpublishedChanges" | "workflows.banner.publishChanges" | "workflows.banner.discard" | "workflows.banner.discardTitle" | "workflows.banner.discardMessage" | "workflows.banner.neverPublished" | "workflows.banner.paused" | "workflows.banner.archived" | "workflows.banner.conflict" | "workflows.banner.reload" | "workflows.banner.touchOnly" | "workflows.editor.published" | "workflows.editor.discarded" | "workflows.editor.restored" | "workflows.editor.reloaded" | "workflows.editor.paused" | "workflows.editor.resumed" | "workflows.editor.archived" | "workflows.editor.unarchived" | "workflows.editor.saveFirst" | "workflows.editor.fixProblems" | "workflows.editor.blockLimit" | "workflows.publish.firstTitle" | "workflows.publish.firstMessage" | "workflows.publish.changesTitle" | "workflows.publish.changesMessage" | "workflows.leave.title" | "workflows.leave.message" | "workflows.leave.confirm" | "workflows.canvas.label" | "workflows.canvas.pointIn" | "workflows.canvas.pointOut" | "workflows.toolbar.label" | "workflows.toolbar.addBlock" | "workflows.toolbar.undo" | "workflows.toolbar.redo" | "workflows.toolbar.zoomIn" | "workflows.toolbar.zoomOut" | "workflows.toolbar.fit" | "workflows.addBlock.composition" | "workflows.addBlock.helpComposition" | "workflows.addBlock.condition" | "workflows.addBlock.helpCondition" | "workflows.addBlock.triggerHeading" | "workflows.addBlock.helpInput" | "workflows.addBlock.helpAction" | "workflows.addBlock.helpPageEvent" | "workflows.addBlock.helpScheduled" | "workflows.block.startsHere" | "workflows.block.trigger" | "workflows.block.condition" | "workflows.block.unknown" | "workflows.block.compositionNotChosen" | "workflows.block.compositionLoading" | "workflows.block.compositionUnavailable" | "workflows.block.notPublished" | "workflows.block.numbered" | "workflows.block.problems" | "workflows.panel.label" | "workflows.panel.overviewHeading" | "workflows.panel.overviewHelp" | "workflows.panel.problemsHeading" | "workflows.panel.problemsLabel" | "workflows.panel.noProblems" | "workflows.panel.manyBlocksSelected" | "workflows.panel.connectionSelected" | "workflows.panel.removeBlock" | "workflows.panel.removeBlocks" | "workflows.panel.removeConnection" | "workflows.composition.heading" | "workflows.composition.help" | "workflows.composition.searchLabel" | "workflows.composition.searchPlaceholder" | "workflows.composition.none" | "workflows.composition.alreadyUsed" | "workflows.composition.isStart" | "workflows.composition.makeStart" | "workflows.composition.capabilitiesHeading" | "workflows.composition.capabilityInput" | "workflows.composition.capabilityAction" | "workflows.composition.capabilityWebsites" | "workflows.composition.inputTables" | "workflows.composition.actionCount" | "workflows.trigger.heading" | "workflows.trigger.help" | "workflows.trigger.kindLabel" | "workflows.trigger.kindInput" | "workflows.trigger.kindAction" | "workflows.trigger.kindPageEvent" | "workflows.trigger.kindScheduled" | "workflows.trigger.unavailable" | "workflows.trigger.tableLabel" | "workflows.trigger.tableHelp" | "workflows.trigger.actionLabel" | "workflows.trigger.actionHelp" | "workflows.trigger.chooseOne" | "workflows.trigger.notFound" | "workflows.trigger.readableValues" | "workflows.trigger.noReadableValues" | "workflows.trigger.nextLabel" | "workflows.trigger.nextHelp" | "workflows.trigger.nextNone" | "workflows.trigger.summaryInput" | "workflows.trigger.summaryAction" | "workflows.trigger.summaryPageEvent" | "workflows.trigger.summaryAt" | "workflows.trigger.summaryUnfinished" | "workflows.reason.widgetKeepsNoData" | "workflows.reason.widgetReportsNoActions" | "workflows.reason.widgetNotPublished" | "workflows.schedule.modeLabel" | "workflows.schedule.modeAfter" | "workflows.schedule.modeAt" | "workflows.schedule.afterHelp" | "workflows.schedule.amountLabel" | "workflows.schedule.unitLabel" | "workflows.schedule.unitSeconds" | "workflows.schedule.unitMinutes" | "workflows.schedule.unitHours" | "workflows.schedule.unitDays" | "workflows.schedule.unitWeeks" | "workflows.schedule.waitSeconds" | "workflows.schedule.waitMinutes" | "workflows.schedule.waitHours" | "workflows.schedule.waitDays" | "workflows.schedule.waitWeeks" | "workflows.schedule.momentLabel" | "workflows.schedule.momentHelp" | "workflows.schedule.invalidMoment" | "workflows.event.nameLabel" | "workflows.event.namePlaceholder" | "workflows.event.nameHelp" | "workflows.event.nameInvalid" | "workflows.event.howToSend" | "workflows.event.valuesHeading" | "workflows.event.valuesHelp" | "workflows.event.addValue" | "workflows.event.valueName" | "workflows.event.valueNamePlaceholder" | "workflows.event.valueNameInvalid" | "workflows.event.valueType" | "workflows.event.removeValue" | "workflows.fieldType.text" | "workflows.fieldType.number" | "workflows.fieldType.boolean" | "workflows.value.yes" | "workflows.value.no" | "workflows.condition.heading" | "workflows.condition.help" | "workflows.condition.noTrigger" | "workflows.condition.noValues" | "workflows.condition.addRule" | "workflows.condition.ruleLimit" | "workflows.condition.defaultName" | "workflows.condition.defaultLabel" | "workflows.condition.defaultStay" | "workflows.condition.defaultHelp" | "workflows.condition.defaultHint" | "workflows.condition.defaultStays" | "workflows.rule.defaultName" | "workflows.rule.nameLabel" | "workflows.rule.moveUp" | "workflows.rule.moveDown" | "workflows.rule.remove" | "workflows.rule.matchLabel" | "workflows.rule.matchAll" | "workflows.rule.matchAny" | "workflows.rule.noTests" | "workflows.rule.addTest" | "workflows.rule.testLimit" | "workflows.rule.thenGoTo" | "workflows.rule.testWithValue" | "workflows.rule.testWithoutValue" | "workflows.rule.testAndMore" | "workflows.test.field" | "workflows.test.operator" | "workflows.test.value" | "workflows.test.valuePlaceholder" | "workflows.test.remove" | "workflows.operator.is" | "workflows.operator.isNot" | "workflows.operator.contains" | "workflows.operator.doesNotContain" | "workflows.operator.startsWith" | "workflows.operator.endsWith" | "workflows.operator.greaterThan" | "workflows.operator.atLeast" | "workflows.operator.lessThan" | "workflows.operator.atMost" | "workflows.operator.isEmpty" | "workflows.operator.isNotEmpty" | "workflows.test.heading" | "workflows.test.help" | "workflows.test.close" | "workflows.test.start" | "workflows.test.restart" | "workflows.test.ended" | "workflows.test.noStart" | "workflows.test.noTriggers" | "workflows.test.visitorIsOn" | "workflows.test.fire" | "workflows.test.resultMoved" | "workflows.test.resultStayed" | "workflows.test.resultIgnored" | "workflows.history.heading" | "workflows.history.help" | "workflows.history.close" | "workflows.history.none" | "workflows.history.failed" | "workflows.history.version" | "workflows.history.live" | "workflows.history.by" | "workflows.history.view" | "workflows.history.viewing" | "workflows.history.backToDraft" | "workflows.history.restore" | "workflows.history.restoreTitle" | "workflows.history.restoreMessage" | "workflows.runs.help" | "workflows.runs.rangeLabel" | "workflows.runs.lastDays" | "workflows.runs.versionLabel" | "workflows.runs.allVersions" | "workflows.runs.versionLive" | "workflows.runs.started" | "workflows.runs.entered" | "workflows.runs.fired" | "workflows.runs.failed" | "workflows.runs.none" | "workflows.runs.neverPublished" | "workflows.settings.zoneHeading" | "workflows.settings.zoneLabel" | "workflows.settings.zoneHelp" | "workflows.settings.embedHeading" | "workflows.settings.embedHelp" | "workflows.settings.stateHeading" | "workflows.settings.pause" | "workflows.settings.pauseHelp" | "workflows.settings.resume" | "workflows.settings.resumeHelp" | "workflows.settings.archive" | "workflows.settings.archiveHelp" | "workflows.settings.archiveTitle" | "workflows.settings.archiveMessage" | "workflows.settings.unarchive" | "workflows.settings.unarchiveHelp" | "workflows.settings.duplicate" | "workflows.settings.duplicateHelp" | "workflows.settings.delete" | "workflows.settings.deleteHelp" | "workflows.settings.deleteBlocked" | "workflows.settings.deleteTitle" | "workflows.settings.deleteMessage" | "workflows.issue.unknown" | "workflows.issue.malformed" | "workflows.issue.schemaVersion" | "workflows.issue.graphTooLarge" | "workflows.issue.unknownNodeType" | "workflows.issue.unknownTriggerKind" | "workflows.issue.badId" | "workflows.issue.duplicateId" | "workflows.issue.tooManyBlocks" | "workflows.issue.tooManyEdges" | "workflows.issue.noComposition" | "workflows.issue.noStart" | "workflows.issue.manyStarts" | "workflows.issue.compositionMissingId" | "workflows.issue.duplicateComposition" | "workflows.issue.compositionNotAvailable" | "workflows.issue.compositionWebsiteMismatch" | "workflows.issue.unreachableBlock" | "workflows.issue.edgeUnknownNode" | "workflows.issue.edgeBadPort" | "workflows.issue.edgeInvalidConnection" | "workflows.issue.portManyTargets" | "workflows.issue.cycle" | "workflows.issue.triggerNoSource" | "workflows.issue.triggerManySources" | "workflows.issue.triggerNoTarget" | "workflows.issue.triggerConfigIncomplete" | "workflows.issue.triggerNeedsTable" | "workflows.issue.triggerNeedsAction" | "workflows.issue.triggerNeedsName" | "workflows.issue.scheduleInvalid" | "workflows.issue.eventValueInvalid" | "workflows.issue.eventTooManyValues" | "workflows.issue.triggerCapabilityMissing" | "workflows.issue.triggerInputMissing" | "workflows.issue.triggerActionMissing" | "workflows.issue.conditionNoSource" | "workflows.issue.conditionManySources" | "workflows.issue.conditionNoCases" | "workflows.issue.conditionTooManyCases" | "workflows.issue.caseBadId" | "workflows.issue.caseDuplicateId" | "workflows.issue.caseNoTests" | "workflows.issue.caseTooManyTests" | "workflows.issue.caseNoTarget" | "workflows.issue.testBadField" | "workflows.issue.testBadOperator" | "workflows.issue.testMissingValue" | "workflows.issue.fieldUnknown" | null;
70
+ create(input: {
71
+ name: string;
72
+ composition: CompositionOption | null;
73
+ }): Promise<WorkflowDetail | undefined>;
74
+ duplicate(workflowId: string): Promise<WorkflowDetail | undefined>;
75
+ changeState(workflowId: string, action: WorkflowStateAction): Promise<void>;
76
+ remove(workflowId: string): Promise<boolean>;
77
+ showNotice(tone: ListNotice['tone'], messageKey: WorkflowsMessageKey, values?: Record<string, string | number>): void;
78
+ dismissNotice(): void;
79
+ private noteFailure;
80
+ }
81
+ export declare function provideListState(state: WorkflowListState): WorkflowListState;
82
+ export declare function useListState(): WorkflowListState;
@@ -0,0 +1,250 @@
1
+ import { getContext, setContext } from 'svelte';
2
+ import { WorkflowsApiError, isCancelled } from '../api/workflowsApi.js';
3
+ import { workflowsError, workflowsWarn } from '../utils/logger.js';
4
+ import { pickApiErrorMessage } from './apiErrorText.js';
5
+ import { detectBrowserTimeZone } from './zonedTime.js';
6
+ /** One page of the list is this many workflows; "Show more" reads the next. */
7
+ export const LIST_PAGE_SIZE = 25;
8
+ /** How long the list waits after the last letter typed in the search before it asks. */
9
+ export const SEARCH_DELAY_MILLISECONDS = 300;
10
+ /**
11
+ * The list of workflows: what is shown, how it is searched, filtered and ordered, and the things done to a workflow from
12
+ * its row (create, duplicate, pause, archive, delete). It asks the API for every change of the search or the order (the list
13
+ * can be longer than a page), and keeps the answer of the newest question only.
14
+ */
15
+ export class WorkflowListState {
16
+ items = $state.raw([]);
17
+ total = $state(0);
18
+ loadState = $state('loading');
19
+ loadingMore = $state(false);
20
+ failure = $state.raw(null);
21
+ search = $state('');
22
+ statusFilter = $state('');
23
+ sortField = $state('createdAt');
24
+ sortDirection = $state('desc');
25
+ /** Workflows something is being done to (a duplicate on its way, a state change). */
26
+ // Replaced as a whole (see setBusy), never changed in place, which is what `$state.raw` watches
27
+ // eslint-disable-next-line svelte/prefer-svelte-reactivity
28
+ busyIds = $state.raw(new Set());
29
+ notice = $state.raw(null);
30
+ /** Whether there is more of the list than is shown. */
31
+ hasMore = $derived(this.items.length < this.total);
32
+ /** Whether the person asked for anything that narrows the list (so "nothing" means "nothing matches", not "nothing yet"). */
33
+ isNarrowed = $derived(this.search.trim() !== '' || this.statusFilter !== '');
34
+ api;
35
+ reportError;
36
+ searchDelay;
37
+ pageSize;
38
+ controller = null;
39
+ searchTimer = null;
40
+ disposed = false;
41
+ constructor(options) {
42
+ this.api = options.api;
43
+ this.reportError = options.reportError;
44
+ this.searchDelay = options.searchDelayMilliseconds ?? SEARCH_DELAY_MILLISECONDS;
45
+ this.pageSize = options.pageSize ?? LIST_PAGE_SIZE;
46
+ }
47
+ dispose() {
48
+ this.disposed = true;
49
+ this.controller?.abort();
50
+ if (this.searchTimer !== null)
51
+ clearTimeout(this.searchTimer);
52
+ this.searchTimer = null;
53
+ }
54
+ buildQuery(offset) {
55
+ const search = this.search.trim();
56
+ return {
57
+ ...(search === '' ? {} : { search }),
58
+ ...(this.statusFilter === '' ? {} : { status: this.statusFilter }),
59
+ sort: { field: this.sortField, direction: this.sortDirection },
60
+ limit: this.pageSize,
61
+ offset
62
+ };
63
+ }
64
+ /** Reads the first page again with the search, the filter and the order as they are now. */
65
+ async load() {
66
+ this.controller?.abort();
67
+ const controller = new AbortController();
68
+ this.controller = controller;
69
+ this.loadState = this.items.length === 0 ? 'loading' : this.loadState;
70
+ this.failure = null;
71
+ try {
72
+ const page = await this.api.listWorkflows(this.buildQuery(0), { signal: controller.signal });
73
+ if (controller.signal.aborted || this.disposed)
74
+ return;
75
+ this.items = page.items;
76
+ this.total = page.total;
77
+ this.loadState = 'ready';
78
+ }
79
+ catch (error) {
80
+ if (isCancelled(error) || this.disposed)
81
+ return;
82
+ this.loadState = 'failed';
83
+ this.failure = pickApiErrorMessage(error) ?? 'workflows.error.generic';
84
+ this.noteFailure('Reading the list of workflows failed', error);
85
+ }
86
+ }
87
+ /** Reads the next page and adds it to the end. */
88
+ async loadMore() {
89
+ if (this.loadingMore || !this.hasMore || this.loadState !== 'ready')
90
+ return;
91
+ this.loadingMore = true;
92
+ const controller = new AbortController();
93
+ this.controller?.abort();
94
+ this.controller = controller;
95
+ try {
96
+ const page = await this.api.listWorkflows(this.buildQuery(this.items.length), {
97
+ signal: controller.signal
98
+ });
99
+ if (controller.signal.aborted || this.disposed)
100
+ return;
101
+ // A local lookup for leaving out what the list already has, not state
102
+ // eslint-disable-next-line svelte/prefer-svelte-reactivity
103
+ const known = new Set(this.items.map((item) => item.id));
104
+ this.items = [...this.items, ...page.items.filter((item) => !known.has(item.id))];
105
+ this.total = page.total;
106
+ }
107
+ catch (error) {
108
+ if (isCancelled(error) || this.disposed)
109
+ return;
110
+ this.showNotice('problem', pickApiErrorMessage(error) ?? 'workflows.error.generic');
111
+ this.noteFailure('Reading more workflows failed', error);
112
+ }
113
+ finally {
114
+ this.loadingMore = false;
115
+ }
116
+ }
117
+ /** The person typed in the search: ask again once they stop. */
118
+ setSearch(text) {
119
+ this.search = text;
120
+ if (this.searchTimer !== null)
121
+ clearTimeout(this.searchTimer);
122
+ this.searchTimer = setTimeout(() => {
123
+ this.searchTimer = null;
124
+ void this.load();
125
+ }, this.searchDelay);
126
+ }
127
+ setStatusFilter(filter) {
128
+ if (filter === this.statusFilter)
129
+ return;
130
+ this.statusFilter = filter;
131
+ void this.load();
132
+ }
133
+ setSort(field) {
134
+ this.sortField = field;
135
+ void this.load();
136
+ }
137
+ toggleSortDirection() {
138
+ this.sortDirection = this.sortDirection === 'asc' ? 'desc' : 'asc';
139
+ void this.load();
140
+ }
141
+ // ---- things done to a workflow -------------------------------------------------------------------------------
142
+ setBusy(workflowId, isBusy) {
143
+ // A copy that is changed and then handed over whole: the old set is never touched
144
+ // eslint-disable-next-line svelte/prefer-svelte-reactivity
145
+ const next = new Set(this.busyIds);
146
+ if (isBusy)
147
+ next.add(workflowId);
148
+ else
149
+ next.delete(workflowId);
150
+ this.busyIds = next;
151
+ }
152
+ async runFor(workflowId, action, whatFailed) {
153
+ if (this.busyIds.has(workflowId))
154
+ return undefined;
155
+ this.setBusy(workflowId, true);
156
+ try {
157
+ return await action();
158
+ }
159
+ catch (error) {
160
+ if (isCancelled(error))
161
+ return undefined;
162
+ this.showNotice('problem', pickApiErrorMessage(error) ?? 'workflows.error.generic');
163
+ this.noteFailure(whatFailed, error);
164
+ return undefined;
165
+ }
166
+ finally {
167
+ this.setBusy(workflowId, false);
168
+ }
169
+ }
170
+ /** Makes a workflow (the dialog asked). Resolves to it, or to `undefined` with the reason in `createFailure`. */
171
+ createFailure = $state.raw(null);
172
+ async create(input) {
173
+ this.createFailure = null;
174
+ try {
175
+ const created = await this.api.createWorkflow({
176
+ name: input.name,
177
+ compositionId: input.composition?.id ?? null,
178
+ timezone: detectBrowserTimeZone()
179
+ });
180
+ return created;
181
+ }
182
+ catch (error) {
183
+ if (isCancelled(error))
184
+ return undefined;
185
+ this.createFailure = pickApiErrorMessage(error) ?? 'workflows.error.generic';
186
+ this.noteFailure('Creating the workflow failed', error);
187
+ return undefined;
188
+ }
189
+ }
190
+ async duplicate(workflowId) {
191
+ const copy = await this.runFor(workflowId, () => this.api.duplicateWorkflow(workflowId), 'Duplicating failed');
192
+ if (copy) {
193
+ this.showNotice('info', 'workflows.list.duplicated');
194
+ await this.load();
195
+ }
196
+ return copy;
197
+ }
198
+ async changeState(workflowId, action) {
199
+ const updated = await this.runFor(workflowId, () => this.api.changeState(workflowId, action), 'Changing the state failed');
200
+ if (!updated)
201
+ return;
202
+ // Archived workflows leave the default list, and a restored one joins it, so read the list again.
203
+ await this.load();
204
+ }
205
+ async remove(workflowId) {
206
+ const done = await this.runFor(workflowId, async () => {
207
+ await this.api.deleteWorkflow(workflowId);
208
+ return true;
209
+ }, 'Deleting failed');
210
+ if (!done)
211
+ return false;
212
+ this.items = this.items.filter((item) => item.id !== workflowId);
213
+ this.total = Math.max(0, this.total - 1);
214
+ this.showNotice('info', 'workflows.list.deleted');
215
+ return true;
216
+ }
217
+ showNotice(tone, messageKey, values) {
218
+ this.notice = { tone, messageKey, values };
219
+ }
220
+ dismissNotice() {
221
+ this.notice = null;
222
+ }
223
+ noteFailure(what, error) {
224
+ if (isCancelled(error))
225
+ return;
226
+ const detail = error instanceof Error ? error.message : String(error);
227
+ workflowsError(`${what}: ${detail}`, error);
228
+ const sessionEnded = error instanceof WorkflowsApiError && error.sessionEnded;
229
+ try {
230
+ this.reportError({
231
+ message: `${what}: ${detail}`,
232
+ code: sessionEnded ? 'SESSION_ENDED' : 'REQUEST_FAILED',
233
+ fatal: false
234
+ });
235
+ }
236
+ catch (handlerError) {
237
+ workflowsWarn('The onError handler of the page threw.', handlerError);
238
+ }
239
+ }
240
+ }
241
+ const LIST_STATE_KEY = Symbol('workflows-list-state');
242
+ export function provideListState(state) {
243
+ return setContext(LIST_STATE_KEY, state);
244
+ }
245
+ export function useListState() {
246
+ const state = getContext(LIST_STATE_KEY);
247
+ if (!state)
248
+ throw new Error('[Workflows] A part of the list was drawn outside the list.');
249
+ return state;
250
+ }
@@ -0,0 +1,26 @@
1
+ import type { WorkflowStats } from '../api/types.js';
2
+ /** The longest range the API answers for: a year and a day (a leap year's days). */
3
+ export declare const MAX_RANGE_DAYS = 366;
4
+ /** The ranges the Runs tab offers, in days. */
5
+ export declare const RANGE_CHOICES_IN_DAYS: readonly number[];
6
+ /**
7
+ * The days a stats request covers: the last `days` days with today included, written `YYYY-MM-DD` as the API wants them.
8
+ * The API counts in UTC days, so the range is in UTC days too: what the person sees as "today" can be a day behind or ahead
9
+ * of it for a few hours, which the counts' own wording ("days (UTC)") tells.
10
+ */
11
+ export declare function makeStatsRange(days: number, now?: Date): {
12
+ from: string;
13
+ to: string;
14
+ };
15
+ /** What the Runs canvas shows: a number for every block and line by its id. A block nobody entered is 0, not missing. */
16
+ export interface RunCounts {
17
+ /** Visitors who started the workflow in the range, or `null` when the counts cover every version. */
18
+ started: number | null;
19
+ entered: ReadonlyMap<string, number>;
20
+ followed: ReadonlyMap<string, number>;
21
+ failed: ReadonlyMap<string, number>;
22
+ /** The most visitors that reached any one block: the busiest block sets the scale of the story. */
23
+ busiest: number;
24
+ }
25
+ /** Turns the API's lists (ids are values, never keys) into lookups the blocks and lines ask by id. */
26
+ export declare function readRunCounts(stats: WorkflowStats): RunCounts;
@@ -0,0 +1,41 @@
1
+ const ONE_DAY_MILLISECONDS = 24 * 60 * 60 * 1000;
2
+ /** The longest range the API answers for: a year and a day (a leap year's days). */
3
+ export const MAX_RANGE_DAYS = 366;
4
+ /** The ranges the Runs tab offers, in days. */
5
+ export const RANGE_CHOICES_IN_DAYS = [7, 30, 90, 365];
6
+ /**
7
+ * The days a stats request covers: the last `days` days with today included, written `YYYY-MM-DD` as the API wants them.
8
+ * The API counts in UTC days, so the range is in UTC days too: what the person sees as "today" can be a day behind or ahead
9
+ * of it for a few hours, which the counts' own wording ("days (UTC)") tells.
10
+ */
11
+ export function makeStatsRange(days, now = new Date()) {
12
+ const wholeDays = Number.isFinite(days)
13
+ ? Math.min(MAX_RANGE_DAYS, Math.max(1, Math.floor(days)))
14
+ : 30;
15
+ const today = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate());
16
+ const first = today - (wholeDays - 1) * ONE_DAY_MILLISECONDS;
17
+ return {
18
+ from: new Date(first).toISOString().slice(0, 10),
19
+ to: new Date(today).toISOString().slice(0, 10)
20
+ };
21
+ }
22
+ function toLookup(items) {
23
+ const lookup = new Map();
24
+ for (const item of items)
25
+ lookup.set(item.id, (lookup.get(item.id) ?? 0) + item.total);
26
+ return lookup;
27
+ }
28
+ /** Turns the API's lists (ids are values, never keys) into lookups the blocks and lines ask by id. */
29
+ export function readRunCounts(stats) {
30
+ const entered = toLookup(stats.nodes);
31
+ let busiest = 0;
32
+ for (const total of entered.values())
33
+ busiest = Math.max(busiest, total);
34
+ return {
35
+ started: stats.started,
36
+ entered,
37
+ followed: toLookup(stats.edges),
38
+ failed: toLookup(stats.failed),
39
+ busiest
40
+ };
41
+ }
@@ -0,0 +1,36 @@
1
+ import type { CompositionNode, FieldValue, Signal, TriggerNode, WorkflowGraph } from '@widgetic/workflows-engine';
2
+ /** Where the test visitor is, and the trail they left. */
3
+ export interface TestRunState {
4
+ /** The composition block the visitor is on; `null` when the workflow has no start to begin from. */
5
+ currentNodeId: string | null;
6
+ /** Every composition the visitor was on, in order, the start included. */
7
+ visitedNodeIds: string[];
8
+ /** Every block and connection the visitor passed, for the highlight on the canvas. */
9
+ passedNodeIds: string[];
10
+ takenEdgeIds: string[];
11
+ /** What the last trigger did, for the line under the list of triggers; `null` before any. */
12
+ lastResult: TestRunResult | null;
13
+ }
14
+ /** What firing a trigger did, in terms a screen can say. */
15
+ export type TestRunResult = {
16
+ outcome: 'moved';
17
+ fromNodeId: string;
18
+ toNodeId: string;
19
+ } | {
20
+ outcome: 'stayed';
21
+ } | {
22
+ outcome: 'ignored';
23
+ };
24
+ /** Begins a test at the start composition. */
25
+ export declare function startTestRun(graph: WorkflowGraph): TestRunState;
26
+ /** The triggers hanging off the composition the test visitor is on. */
27
+ export declare function listTriggersOfCurrent(graph: WorkflowGraph, state: TestRunState): TriggerNode[];
28
+ /**
29
+ * What the visitor's browser would tell the workflow when this trigger fires: a new row for an Input added trigger (with the
30
+ * values the person typed for the test), a goal for an Action, the page's event, the clock for a Scheduled one.
31
+ */
32
+ export declare function makeSignalFor(trigger: TriggerNode, values: Record<string, FieldValue>): Signal;
33
+ /** Fires one trigger for the test visitor and returns where they are after it. The state that came in is not changed. */
34
+ export declare function fireTestTrigger(graph: WorkflowGraph, state: TestRunState, trigger: TriggerNode, values?: Record<string, FieldValue>): TestRunState;
35
+ /** The composition blocks of the graph by id, for the screen that names where the visitor is. */
36
+ export declare function findCompositionBlock(graph: WorkflowGraph, nodeId: string | null): CompositionNode | undefined;
@@ -0,0 +1,74 @@
1
+ /**
2
+ * The editor's Test run: a person plays a visitor on the draft, fires a trigger, and sees where the visitor goes. Nothing is
3
+ * recorded and nothing leaves the screen. It is the engine's own `advance` (the very function the embed runs), so what the
4
+ * test shows is what a visitor gets.
5
+ */
6
+ import { advance, buildGraphIndex, findStartNode, listTriggersOf } from '@widgetic/workflows-engine';
7
+ /** Begins a test at the start composition. */
8
+ export function startTestRun(graph) {
9
+ const start = findStartNode(graph);
10
+ return {
11
+ currentNodeId: start?.id ?? null,
12
+ visitedNodeIds: start ? [start.id] : [],
13
+ passedNodeIds: [],
14
+ takenEdgeIds: [],
15
+ lastResult: null
16
+ };
17
+ }
18
+ /** The triggers hanging off the composition the test visitor is on. */
19
+ export function listTriggersOfCurrent(graph, state) {
20
+ if (state.currentNodeId === null)
21
+ return [];
22
+ return listTriggersOf(buildGraphIndex(graph), state.currentNodeId);
23
+ }
24
+ /**
25
+ * What the visitor's browser would tell the workflow when this trigger fires: a new row for an Input added trigger (with the
26
+ * values the person typed for the test), a goal for an Action, the page's event, the clock for a Scheduled one.
27
+ */
28
+ export function makeSignalFor(trigger, values) {
29
+ const config = trigger.trigger;
30
+ switch (config.kind) {
31
+ case 'input':
32
+ return { type: 'input', table: config.table, values };
33
+ case 'action':
34
+ return { type: 'action', actionId: config.actionId };
35
+ case 'pageEvent':
36
+ return { type: 'pageEvent', name: config.name, values };
37
+ case 'scheduled':
38
+ return { type: 'scheduled', triggerId: trigger.id };
39
+ }
40
+ }
41
+ function describe(result, fromNodeId) {
42
+ if (result.outcome === 'moved')
43
+ return { outcome: 'moved', fromNodeId, toNodeId: result.position.nodeId };
44
+ return result.outcome === 'stayed' ? { outcome: 'stayed' } : { outcome: 'ignored' };
45
+ }
46
+ /** Fires one trigger for the test visitor and returns where they are after it. The state that came in is not changed. */
47
+ export function fireTestTrigger(graph, state, trigger, values = {}) {
48
+ if (state.currentNodeId === null)
49
+ return state;
50
+ const result = advance(graph, { nodeId: state.currentNodeId }, makeSignalFor(trigger, values));
51
+ const lastResult = describe(result, state.currentNodeId);
52
+ if (result.outcome !== 'moved')
53
+ return { ...state, lastResult };
54
+ // The engine reports the connections from the trigger on; the one that led from the composition to the trigger comes first.
55
+ const edgeIntoTrigger = graph.edges.find((edge) => edge.source === state.currentNodeId && edge.target === result.firedTriggerId);
56
+ return {
57
+ currentNodeId: result.position.nodeId,
58
+ visitedNodeIds: [...state.visitedNodeIds, result.position.nodeId],
59
+ passedNodeIds: [...state.passedNodeIds, ...result.passedNodeIds],
60
+ takenEdgeIds: [
61
+ ...state.takenEdgeIds,
62
+ ...(edgeIntoTrigger ? [edgeIntoTrigger.id] : []),
63
+ ...result.takenEdgeIds
64
+ ],
65
+ lastResult
66
+ };
67
+ }
68
+ /** The composition blocks of the graph by id, for the screen that names where the visitor is. */
69
+ export function findCompositionBlock(graph, nodeId) {
70
+ if (nodeId === null)
71
+ return undefined;
72
+ const node = graph.nodes.find((candidate) => candidate.id === nodeId);
73
+ return node?.type === 'composition' ? node : undefined;
74
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Time in the workflow's own time zone. A Scheduled trigger that waits for "3 November, 9:00" means 9:00 where the team
3
+ * works, not where each visitor is; the workflow has a time zone for that (its Settings), and the graph stores the moment
4
+ * in UTC. These two functions are the conversion between what a person types (a wall clock time in the zone) and what is
5
+ * stored (an ISO time in UTC), written with the browser's own `Intl` so that no date library is shipped for it.
6
+ */
7
+ /** Whether the browser knows this zone (`Europe/Bucharest`, `UTC`). */
8
+ export declare function isValidTimeZone(timeZone: string): boolean;
9
+ /**
10
+ * The UTC time of a wall clock time in a zone, as an ISO text, or `null` when the text is not a time or the zone is not
11
+ * known. A wall clock time that does not exist (the hour a spring clock change skips) is read as the same time after the
12
+ * change, and one that happens twice (the hour an autumn change repeats) as its first time.
13
+ */
14
+ export declare function zonedLocalToUtcIso(local: string, timeZone: string): string | null;
15
+ /** The wall clock time, as a date input reads it (`2026-11-03T09:00`), of an ISO time in a zone, or `null` when it cannot be read. */
16
+ export declare function utcIsoToZonedLocal(iso: string, timeZone: string): string | null;
17
+ /** The zones to choose from: every zone the browser lists, `UTC` first; a short list when the browser cannot list them. */
18
+ export declare function listTimeZones(): string[];
19
+ /** The zone the person's browser is in, or `UTC` when it cannot say. */
20
+ export declare function detectBrowserTimeZone(): string;