@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.
- package/LICENSE +122 -0
- package/README.md +304 -2
- package/dist/api/apiContext.d.ts +4 -0
- package/dist/api/apiContext.js +17 -0
- package/dist/api/types.d.ts +168 -0
- package/dist/api/types.js +3 -0
- package/dist/api/workflowsApi.d.ts +109 -0
- package/dist/api/workflowsApi.js +657 -0
- package/dist/components/Workflows.svelte +131 -0
- package/dist/components/Workflows.svelte.d.ts +4 -0
- package/dist/components/WorkflowsEmptyState.svelte +32 -0
- package/dist/components/WorkflowsEmptyState.svelte.d.ts +7 -0
- package/dist/components/WorkflowsHeader.svelte +14 -0
- package/dist/components/WorkflowsHeader.svelte.d.ts +18 -0
- package/dist/components/WorkflowsWorkspace.svelte +87 -0
- package/dist/components/WorkflowsWorkspace.svelte.d.ts +14 -0
- package/dist/components/canvas/AddBlockMenu.svelte +101 -0
- package/dist/components/canvas/AddBlockMenu.svelte.d.ts +5 -0
- package/dist/components/canvas/CanvasToolbar.svelte +95 -0
- package/dist/components/canvas/CanvasToolbar.svelte.d.ts +9 -0
- package/dist/components/canvas/CompositionNodeView.svelte +125 -0
- package/dist/components/canvas/CompositionNodeView.svelte.d.ts +5 -0
- package/dist/components/canvas/ConditionNodeView.svelte +95 -0
- package/dist/components/canvas/ConditionNodeView.svelte.d.ts +5 -0
- package/dist/components/canvas/HandlePoint.svelte +32 -0
- package/dist/components/canvas/HandlePoint.svelte.d.ts +14 -0
- package/dist/components/canvas/TriggerNodeView.svelte +75 -0
- package/dist/components/canvas/TriggerNodeView.svelte.d.ts +5 -0
- package/dist/components/canvas/WorkflowCanvas.svelte +380 -0
- package/dist/components/canvas/WorkflowCanvas.svelte.d.ts +25 -0
- package/dist/components/canvas/WorkflowEdgeView.svelte +58 -0
- package/dist/components/canvas/WorkflowEdgeView.svelte.d.ts +4 -0
- package/dist/components/editor/EditorBanners.svelte +143 -0
- package/dist/components/editor/EditorBanners.svelte.d.ts +7 -0
- package/dist/components/editor/EditorCanvasArea.svelte +85 -0
- package/dist/components/editor/EditorCanvasArea.svelte.d.ts +3 -0
- package/dist/components/editor/EditorTabs.svelte +81 -0
- package/dist/components/editor/EditorTabs.svelte.d.ts +7 -0
- package/dist/components/editor/EditorTopBar.svelte +132 -0
- package/dist/components/editor/EditorTopBar.svelte.d.ts +9 -0
- package/dist/components/editor/RunsTab.svelte +256 -0
- package/dist/components/editor/RunsTab.svelte.d.ts +3 -0
- package/dist/components/editor/SettingsTab.svelte +180 -0
- package/dist/components/editor/SettingsTab.svelte.d.ts +7 -0
- package/dist/components/editor/WorkflowEditor.svelte +185 -0
- package/dist/components/editor/WorkflowEditor.svelte.d.ts +15 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/list/CreateWorkflowDialog.svelte +89 -0
- package/dist/components/list/CreateWorkflowDialog.svelte.d.ts +9 -0
- package/dist/components/list/WorkflowList.svelte +204 -0
- package/dist/components/list/WorkflowList.svelte.d.ts +12 -0
- package/dist/components/list/WorkflowRow.svelte +191 -0
- package/dist/components/list/WorkflowRow.svelte.d.ts +10 -0
- package/dist/components/panel/BlockProblems.svelte +47 -0
- package/dist/components/panel/BlockProblems.svelte.d.ts +6 -0
- package/dist/components/panel/CompositionForm.svelte +127 -0
- package/dist/components/panel/CompositionForm.svelte.d.ts +7 -0
- package/dist/components/panel/CompositionPicker.svelte +179 -0
- package/dist/components/panel/CompositionPicker.svelte.d.ts +14 -0
- package/dist/components/panel/ConditionForm.svelte +105 -0
- package/dist/components/panel/ConditionForm.svelte.d.ts +7 -0
- package/dist/components/panel/EventValueRow.svelte +85 -0
- package/dist/components/panel/EventValueRow.svelte.d.ts +12 -0
- package/dist/components/panel/NextStepSelect.svelte +70 -0
- package/dist/components/panel/NextStepSelect.svelte.d.ts +12 -0
- package/dist/components/panel/ProblemsList.svelte +101 -0
- package/dist/components/panel/ProblemsList.svelte.d.ts +3 -0
- package/dist/components/panel/RuleCard.svelte +191 -0
- package/dist/components/panel/RuleCard.svelte.d.ts +13 -0
- package/dist/components/panel/SidePanel.svelte +82 -0
- package/dist/components/panel/SidePanel.svelte.d.ts +3 -0
- package/dist/components/panel/TestRow.svelte +150 -0
- package/dist/components/panel/TestRow.svelte.d.ts +15 -0
- package/dist/components/panel/TestRunPanel.svelte +85 -0
- package/dist/components/panel/TestRunPanel.svelte.d.ts +3 -0
- package/dist/components/panel/TestTriggerCard.svelte +121 -0
- package/dist/components/panel/TestTriggerCard.svelte.d.ts +7 -0
- package/dist/components/panel/TriggerForm.svelte +385 -0
- package/dist/components/panel/TriggerForm.svelte.d.ts +7 -0
- package/dist/components/panel/VersionHistory.svelte +123 -0
- package/dist/components/panel/VersionHistory.svelte.d.ts +3 -0
- package/dist/components/ui/ActionButton.svelte +85 -0
- package/dist/components/ui/ActionButton.svelte.d.ts +27 -0
- package/dist/components/ui/ConfirmDialog.svelte +52 -0
- package/dist/components/ui/ConfirmDialog.svelte.d.ts +16 -0
- package/dist/components/ui/Icon.svelte +32 -0
- package/dist/components/ui/Icon.svelte.d.ts +9 -0
- package/dist/components/ui/Menu.svelte +211 -0
- package/dist/components/ui/Menu.svelte.d.ts +21 -0
- package/dist/components/ui/Modal.svelte +129 -0
- package/dist/components/ui/Modal.svelte.d.ts +13 -0
- package/dist/components/ui/Notice.svelte +36 -0
- package/dist/components/ui/Notice.svelte.d.ts +11 -0
- package/dist/components/ui/SelectField.svelte +74 -0
- package/dist/components/ui/SelectField.svelte.d.ts +16 -0
- package/dist/components/ui/StatusBadge.svelte +41 -0
- package/dist/components/ui/StatusBadge.svelte.d.ts +9 -0
- package/dist/components/ui/TextField.svelte +97 -0
- package/dist/components/ui/TextField.svelte.d.ts +29 -0
- package/dist/components/ui/icons.d.ts +34 -0
- package/dist/components/ui/icons.js +54 -0
- package/dist/components/ui/types.d.ts +26 -0
- package/dist/components/ui/types.js +1 -0
- package/dist/editor/apiErrorText.d.ts +10 -0
- package/dist/editor/apiErrorText.js +53 -0
- package/dist/editor/autosave.d.ts +47 -0
- package/dist/editor/autosave.js +119 -0
- package/dist/editor/blockLabels.d.ts +91 -0
- package/dist/editor/blockLabels.js +196 -0
- package/dist/editor/canvasContext.d.ts +52 -0
- package/dist/editor/canvasContext.js +37 -0
- package/dist/editor/canvasWords.d.ts +24 -0
- package/dist/editor/canvasWords.js +40 -0
- package/dist/editor/capabilityModel.d.ts +46 -0
- package/dist/editor/capabilityModel.js +113 -0
- package/dist/editor/editorState.svelte.d.ts +220 -0
- package/dist/editor/editorState.svelte.js +713 -0
- package/dist/editor/flowAdapter.d.ts +59 -0
- package/dist/editor/flowAdapter.js +166 -0
- package/dist/editor/formatCount.d.ts +5 -0
- package/dist/editor/formatCount.js +15 -0
- package/dist/editor/graphDiff.d.ts +27 -0
- package/dist/editor/graphDiff.js +64 -0
- package/dist/editor/graphModel.d.ts +154 -0
- package/dist/editor/graphModel.js +457 -0
- package/dist/editor/issueText.d.ts +64 -0
- package/dist/editor/issueText.js +101 -0
- package/dist/editor/listState.svelte.d.ts +82 -0
- package/dist/editor/listState.svelte.js +250 -0
- package/dist/editor/statsRange.d.ts +26 -0
- package/dist/editor/statsRange.js +41 -0
- package/dist/editor/testRun.d.ts +36 -0
- package/dist/editor/testRun.js +74 -0
- package/dist/editor/zonedTime.d.ts +20 -0
- package/dist/editor/zonedTime.js +134 -0
- package/dist/i18n/index.d.ts +2 -0
- package/dist/i18n/index.js +2 -0
- package/dist/i18n/language.d.ts +22 -0
- package/dist/i18n/language.js +34 -0
- package/dist/i18n/messages.d.ts +423 -0
- package/dist/i18n/messages.js +446 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/types/index.d.ts +66 -0
- package/dist/types/index.js +1 -0
- package/dist/utils/logger.d.ts +4 -0
- package/dist/utils/logger.js +35 -0
- package/package.json +103 -5
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { ConditionCase, ConditionTest, FieldReference, FieldValue, TriggerConfig, WorkflowGraph } from '@widgetic/workflows-engine';
|
|
2
|
+
import type { WorkflowsMessageKey } from '../i18n/messages.js';
|
|
3
|
+
import type { CompositionOptionsById } from './capabilityModel.js';
|
|
4
|
+
/**
|
|
5
|
+
* What the blocks of a workflow are called and how a trigger is summed up in a line, in the person's language. The names a
|
|
6
|
+
* person wrote (a composition's name, a column, an event) go in as they are; the words around them are messages.
|
|
7
|
+
*/
|
|
8
|
+
/** The translator the screen's parts hold (`$t`), with the values a message may ask for. */
|
|
9
|
+
export type TranslateWorkflowsMessage = (key: WorkflowsMessageKey, values?: Readonly<Record<string, string | number>>) => string;
|
|
10
|
+
export declare const TRIGGER_KIND_MESSAGE_KEYS: {
|
|
11
|
+
readonly input: "workflows.trigger.kindInput";
|
|
12
|
+
readonly action: "workflows.trigger.kindAction";
|
|
13
|
+
readonly pageEvent: "workflows.trigger.kindPageEvent";
|
|
14
|
+
readonly scheduled: "workflows.trigger.kindScheduled";
|
|
15
|
+
};
|
|
16
|
+
export declare const OPERATOR_MESSAGE_KEYS: {
|
|
17
|
+
readonly is: "workflows.operator.is";
|
|
18
|
+
readonly isNot: "workflows.operator.isNot";
|
|
19
|
+
readonly contains: "workflows.operator.contains";
|
|
20
|
+
readonly doesNotContain: "workflows.operator.doesNotContain";
|
|
21
|
+
readonly startsWith: "workflows.operator.startsWith";
|
|
22
|
+
readonly endsWith: "workflows.operator.endsWith";
|
|
23
|
+
readonly greaterThan: "workflows.operator.greaterThan";
|
|
24
|
+
readonly atLeast: "workflows.operator.atLeast";
|
|
25
|
+
readonly lessThan: "workflows.operator.lessThan";
|
|
26
|
+
readonly atMost: "workflows.operator.atMost";
|
|
27
|
+
readonly isEmpty: "workflows.operator.isEmpty";
|
|
28
|
+
readonly isNotEmpty: "workflows.operator.isNotEmpty";
|
|
29
|
+
};
|
|
30
|
+
/** The unit of a wait as a plain noun, for the select that picks it. */
|
|
31
|
+
export declare const UNIT_MESSAGE_KEYS: {
|
|
32
|
+
readonly seconds: "workflows.schedule.unitSeconds";
|
|
33
|
+
readonly minutes: "workflows.schedule.unitMinutes";
|
|
34
|
+
readonly hours: "workflows.schedule.unitHours";
|
|
35
|
+
readonly days: "workflows.schedule.unitDays";
|
|
36
|
+
readonly weeks: "workflows.schedule.unitWeeks";
|
|
37
|
+
};
|
|
38
|
+
/** A wait as one phrase that agrees with the number (`Wait 1 minute`, `Wait 5 minutes`). */
|
|
39
|
+
export declare const WAIT_SUMMARY_MESSAGE_KEYS: {
|
|
40
|
+
readonly seconds: "workflows.schedule.waitSeconds";
|
|
41
|
+
readonly minutes: "workflows.schedule.waitMinutes";
|
|
42
|
+
readonly hours: "workflows.schedule.waitHours";
|
|
43
|
+
readonly days: "workflows.schedule.waitDays";
|
|
44
|
+
readonly weeks: "workflows.schedule.waitWeeks";
|
|
45
|
+
};
|
|
46
|
+
/** Why a trigger cannot be used on a composition, in words the editor shows next to the choice. */
|
|
47
|
+
export declare const CAPABILITY_REASON_MESSAGE_KEYS: {
|
|
48
|
+
readonly widget_keeps_no_data: "workflows.reason.widgetKeepsNoData";
|
|
49
|
+
readonly widget_reports_no_actions: "workflows.reason.widgetReportsNoActions";
|
|
50
|
+
readonly widget_not_published: "workflows.reason.widgetNotPublished";
|
|
51
|
+
};
|
|
52
|
+
export declare const FIELD_TYPE_MESSAGE_KEYS: {
|
|
53
|
+
readonly text: "workflows.fieldType.text";
|
|
54
|
+
readonly number: "workflows.fieldType.number";
|
|
55
|
+
readonly boolean: "workflows.fieldType.boolean";
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* What a block is called, for the places that name one (a problem found in it, a list of next steps): the composition's own
|
|
59
|
+
* name, or the kind of block for the others, with the kind of trigger. Never empty.
|
|
60
|
+
*/
|
|
61
|
+
export declare function makeBlockDescriber(graph: WorkflowGraph, options: CompositionOptionsById, t: TranslateWorkflowsMessage): (nodeId: string) => string;
|
|
62
|
+
/**
|
|
63
|
+
* What every block is called, with two blocks that would be called the same told apart by a number (`Condition`,
|
|
64
|
+
* `Condition (2)`): the lists that name blocks of one workflow (the next-step pickers, the problems) need names that tell
|
|
65
|
+
* one block from another.
|
|
66
|
+
*/
|
|
67
|
+
export declare function describeBlocksUniquely(graph: WorkflowGraph, options: CompositionOptionsById, t: TranslateWorkflowsMessage): ReadonlyMap<string, string>;
|
|
68
|
+
/** What a summary of a trigger needs besides the trigger. */
|
|
69
|
+
export interface TriggerSummaryContext {
|
|
70
|
+
t: TranslateWorkflowsMessage;
|
|
71
|
+
/** The language tag, for how a date is written. */
|
|
72
|
+
locale: string;
|
|
73
|
+
/** The workflow's time zone: a scheduled moment is told in it. */
|
|
74
|
+
timeZone: string;
|
|
75
|
+
/** What an action is called in the widget (its label), by the id the trigger stores; the id itself when it is not known. */
|
|
76
|
+
describeAction: (actionId: string) => string;
|
|
77
|
+
}
|
|
78
|
+
/** A date and time of a zone as `locale` writes them. Falls back to the plain text when the browser cannot format it. */
|
|
79
|
+
export declare function formatMomentInZone(iso: string, locale: string, timeZone: string): string;
|
|
80
|
+
/** A day as `locale` writes it (`Mar 10, 2026`), in the person's own time zone. The plain text when it is not a date. */
|
|
81
|
+
export declare function formatDay(iso: string, locale: string): string;
|
|
82
|
+
/** One line that says what a trigger waits for, or that it is not finished. */
|
|
83
|
+
export declare function summarizeTrigger(trigger: TriggerConfig, context: TriggerSummaryContext): string;
|
|
84
|
+
/** The value a test compares with, as the person reads it (yes and no for a switch, the text as it was typed). */
|
|
85
|
+
export declare function formatTestValue(value: FieldValue | undefined, t: TranslateWorkflowsMessage): string;
|
|
86
|
+
/** One test as a phrase (`Plan is Pro`, `Email is not empty`). The order of its parts is the message's, so a language can turn it around. */
|
|
87
|
+
export declare function summarizeTest(test: ConditionTest, labelField: (field: FieldReference) => string, t: TranslateWorkflowsMessage): string;
|
|
88
|
+
/** What a rule is called: the name the person gave it, or its place in the list. */
|
|
89
|
+
export declare function nameRule(rule: ConditionCase, index: number, t: TranslateWorkflowsMessage): string;
|
|
90
|
+
/** A rule in one line: its first test, and how many more there are. A rule with no test says so. */
|
|
91
|
+
export declare function summarizeRule(rule: ConditionCase, labelField: (field: FieldReference) => string, t: TranslateWorkflowsMessage): string;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { operatorNeedsValue } from '@widgetic/workflows-engine';
|
|
2
|
+
import { utcIsoToZonedLocal } from './zonedTime.js';
|
|
3
|
+
export const TRIGGER_KIND_MESSAGE_KEYS = {
|
|
4
|
+
input: 'workflows.trigger.kindInput',
|
|
5
|
+
action: 'workflows.trigger.kindAction',
|
|
6
|
+
pageEvent: 'workflows.trigger.kindPageEvent',
|
|
7
|
+
scheduled: 'workflows.trigger.kindScheduled'
|
|
8
|
+
};
|
|
9
|
+
export const OPERATOR_MESSAGE_KEYS = {
|
|
10
|
+
is: 'workflows.operator.is',
|
|
11
|
+
isNot: 'workflows.operator.isNot',
|
|
12
|
+
contains: 'workflows.operator.contains',
|
|
13
|
+
doesNotContain: 'workflows.operator.doesNotContain',
|
|
14
|
+
startsWith: 'workflows.operator.startsWith',
|
|
15
|
+
endsWith: 'workflows.operator.endsWith',
|
|
16
|
+
greaterThan: 'workflows.operator.greaterThan',
|
|
17
|
+
atLeast: 'workflows.operator.atLeast',
|
|
18
|
+
lessThan: 'workflows.operator.lessThan',
|
|
19
|
+
atMost: 'workflows.operator.atMost',
|
|
20
|
+
isEmpty: 'workflows.operator.isEmpty',
|
|
21
|
+
isNotEmpty: 'workflows.operator.isNotEmpty'
|
|
22
|
+
};
|
|
23
|
+
/** The unit of a wait as a plain noun, for the select that picks it. */
|
|
24
|
+
export const UNIT_MESSAGE_KEYS = {
|
|
25
|
+
seconds: 'workflows.schedule.unitSeconds',
|
|
26
|
+
minutes: 'workflows.schedule.unitMinutes',
|
|
27
|
+
hours: 'workflows.schedule.unitHours',
|
|
28
|
+
days: 'workflows.schedule.unitDays',
|
|
29
|
+
weeks: 'workflows.schedule.unitWeeks'
|
|
30
|
+
};
|
|
31
|
+
/** A wait as one phrase that agrees with the number (`Wait 1 minute`, `Wait 5 minutes`). */
|
|
32
|
+
export const WAIT_SUMMARY_MESSAGE_KEYS = {
|
|
33
|
+
seconds: 'workflows.schedule.waitSeconds',
|
|
34
|
+
minutes: 'workflows.schedule.waitMinutes',
|
|
35
|
+
hours: 'workflows.schedule.waitHours',
|
|
36
|
+
days: 'workflows.schedule.waitDays',
|
|
37
|
+
weeks: 'workflows.schedule.waitWeeks'
|
|
38
|
+
};
|
|
39
|
+
/** Why a trigger cannot be used on a composition, in words the editor shows next to the choice. */
|
|
40
|
+
export const CAPABILITY_REASON_MESSAGE_KEYS = {
|
|
41
|
+
widget_keeps_no_data: 'workflows.reason.widgetKeepsNoData',
|
|
42
|
+
widget_reports_no_actions: 'workflows.reason.widgetReportsNoActions',
|
|
43
|
+
widget_not_published: 'workflows.reason.widgetNotPublished'
|
|
44
|
+
};
|
|
45
|
+
export const FIELD_TYPE_MESSAGE_KEYS = {
|
|
46
|
+
text: 'workflows.fieldType.text',
|
|
47
|
+
number: 'workflows.fieldType.number',
|
|
48
|
+
boolean: 'workflows.fieldType.boolean'
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* What a block is called, for the places that name one (a problem found in it, a list of next steps): the composition's own
|
|
52
|
+
* name, or the kind of block for the others, with the kind of trigger. Never empty.
|
|
53
|
+
*/
|
|
54
|
+
export function makeBlockDescriber(graph, options, t) {
|
|
55
|
+
const nodesById = new Map(graph.nodes.map((node) => [node.id, node]));
|
|
56
|
+
return (nodeId) => {
|
|
57
|
+
const node = nodesById.get(nodeId);
|
|
58
|
+
if (!node)
|
|
59
|
+
return t('workflows.block.unknown');
|
|
60
|
+
if (node.type === 'composition') {
|
|
61
|
+
const name = node.compositionId ? options[node.compositionId]?.name : undefined;
|
|
62
|
+
return name && name.trim() !== '' ? name : t('workflows.block.compositionNotChosen');
|
|
63
|
+
}
|
|
64
|
+
if (node.type === 'trigger')
|
|
65
|
+
return t(TRIGGER_KIND_MESSAGE_KEYS[node.trigger.kind] ?? 'workflows.block.trigger');
|
|
66
|
+
return t('workflows.block.condition');
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* What every block is called, with two blocks that would be called the same told apart by a number (`Condition`,
|
|
71
|
+
* `Condition (2)`): the lists that name blocks of one workflow (the next-step pickers, the problems) need names that tell
|
|
72
|
+
* one block from another.
|
|
73
|
+
*/
|
|
74
|
+
export function describeBlocksUniquely(graph, options, t) {
|
|
75
|
+
const describe = makeBlockDescriber(graph, options, t);
|
|
76
|
+
const seen = new Map();
|
|
77
|
+
const taken = new Set();
|
|
78
|
+
const labels = new Map();
|
|
79
|
+
for (const node of graph.nodes) {
|
|
80
|
+
const name = describe(node.id);
|
|
81
|
+
let number = (seen.get(name) ?? 0) + 1;
|
|
82
|
+
let label = number === 1 ? name : t('workflows.block.numbered', { name, number });
|
|
83
|
+
// A label another block already has (a composition that is really called `Promo (2)`) takes the next number, so that no
|
|
84
|
+
// two blocks of the lists are called the same.
|
|
85
|
+
while (taken.has(label)) {
|
|
86
|
+
number += 1;
|
|
87
|
+
label = t('workflows.block.numbered', { name, number });
|
|
88
|
+
}
|
|
89
|
+
seen.set(name, number);
|
|
90
|
+
taken.add(label);
|
|
91
|
+
labels.set(node.id, label);
|
|
92
|
+
}
|
|
93
|
+
return labels;
|
|
94
|
+
}
|
|
95
|
+
/** A date and time of a zone as `locale` writes them. Falls back to the plain text when the browser cannot format it. */
|
|
96
|
+
export function formatMomentInZone(iso, locale, timeZone) {
|
|
97
|
+
const moment = new Date(iso);
|
|
98
|
+
if (Number.isNaN(moment.getTime()))
|
|
99
|
+
return iso;
|
|
100
|
+
try {
|
|
101
|
+
return new Intl.DateTimeFormat(locale, {
|
|
102
|
+
dateStyle: 'medium',
|
|
103
|
+
timeStyle: 'short',
|
|
104
|
+
timeZone
|
|
105
|
+
}).format(moment);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
// A zone or a locale the browser does not know: say the wall clock time we can compute, so the line is never empty.
|
|
109
|
+
return utcIsoToZonedLocal(iso, timeZone) ?? iso;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/** A day as `locale` writes it (`Mar 10, 2026`), in the person's own time zone. The plain text when it is not a date. */
|
|
113
|
+
export function formatDay(iso, locale) {
|
|
114
|
+
const moment = new Date(iso);
|
|
115
|
+
if (Number.isNaN(moment.getTime()))
|
|
116
|
+
return iso;
|
|
117
|
+
try {
|
|
118
|
+
return new Intl.DateTimeFormat(locale || undefined, { dateStyle: 'medium' }).format(moment);
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
// A language tag the browser does not know: say the day the plain way.
|
|
122
|
+
return moment.toISOString().slice(0, 10);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/** One line that says what a trigger waits for, or that it is not finished. */
|
|
126
|
+
export function summarizeTrigger(trigger, context) {
|
|
127
|
+
const { t } = context;
|
|
128
|
+
switch (trigger.kind) {
|
|
129
|
+
case 'input':
|
|
130
|
+
return trigger.table.trim() === ''
|
|
131
|
+
? t('workflows.trigger.summaryUnfinished')
|
|
132
|
+
: t('workflows.trigger.summaryInput', { table: trigger.table });
|
|
133
|
+
case 'action':
|
|
134
|
+
return trigger.actionId.trim() === ''
|
|
135
|
+
? t('workflows.trigger.summaryUnfinished')
|
|
136
|
+
: t('workflows.trigger.summaryAction', {
|
|
137
|
+
action: context.describeAction(trigger.actionId)
|
|
138
|
+
});
|
|
139
|
+
case 'pageEvent':
|
|
140
|
+
return trigger.name.trim() === ''
|
|
141
|
+
? t('workflows.trigger.summaryUnfinished')
|
|
142
|
+
: t('workflows.trigger.summaryPageEvent', { name: trigger.name });
|
|
143
|
+
case 'scheduled': {
|
|
144
|
+
const { schedule } = trigger;
|
|
145
|
+
if (schedule.mode === 'after') {
|
|
146
|
+
const key = WAIT_SUMMARY_MESSAGE_KEYS[schedule.unit];
|
|
147
|
+
return key ? t(key, { count: schedule.amount }) : t('workflows.trigger.summaryUnfinished');
|
|
148
|
+
}
|
|
149
|
+
return schedule.at.trim() === ''
|
|
150
|
+
? t('workflows.trigger.summaryUnfinished')
|
|
151
|
+
: t('workflows.trigger.summaryAt', {
|
|
152
|
+
moment: formatMomentInZone(schedule.at, context.locale, context.timeZone)
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
default:
|
|
156
|
+
return t('workflows.trigger.summaryUnfinished');
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
160
|
+
// Rules of a condition
|
|
161
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
162
|
+
/** The value a test compares with, as the person reads it (yes and no for a switch, the text as it was typed). */
|
|
163
|
+
export function formatTestValue(value, t) {
|
|
164
|
+
if (typeof value === 'boolean')
|
|
165
|
+
return value ? t('workflows.value.yes') : t('workflows.value.no');
|
|
166
|
+
if (value === undefined || value === null)
|
|
167
|
+
return '';
|
|
168
|
+
return String(value);
|
|
169
|
+
}
|
|
170
|
+
/** One test as a phrase (`Plan is Pro`, `Email is not empty`). The order of its parts is the message's, so a language can turn it around. */
|
|
171
|
+
export function summarizeTest(test, labelField, t) {
|
|
172
|
+
const field = labelField(test.field);
|
|
173
|
+
const operator = t(OPERATOR_MESSAGE_KEYS[test.operator] ?? 'workflows.operator.is');
|
|
174
|
+
if (!operatorNeedsValue(test.operator))
|
|
175
|
+
return t('workflows.rule.testWithoutValue', { field, operator });
|
|
176
|
+
return t('workflows.rule.testWithValue', {
|
|
177
|
+
field,
|
|
178
|
+
operator,
|
|
179
|
+
value: formatTestValue(test.value, t)
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
/** What a rule is called: the name the person gave it, or its place in the list. */
|
|
183
|
+
export function nameRule(rule, index, t) {
|
|
184
|
+
const given = rule.label?.trim();
|
|
185
|
+
return given ? given : t('workflows.rule.defaultName', { number: index + 1 });
|
|
186
|
+
}
|
|
187
|
+
/** A rule in one line: its first test, and how many more there are. A rule with no test says so. */
|
|
188
|
+
export function summarizeRule(rule, labelField, t) {
|
|
189
|
+
const [first, ...others] = rule.tests;
|
|
190
|
+
if (!first)
|
|
191
|
+
return t('workflows.rule.noTests');
|
|
192
|
+
const summary = summarizeTest(first, labelField, t);
|
|
193
|
+
return others.length === 0
|
|
194
|
+
? summary
|
|
195
|
+
: t('workflows.rule.testAndMore', { summary, count: others.length });
|
|
196
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { FieldReference, TriggerConfig, WorkflowEdge, WorkflowGraph } from '@widgetic/workflows-engine';
|
|
2
|
+
import type { CompositionOption } from '../api/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* What the blocks and lines of a canvas know about the workflow around them, beyond what the canvas hands them (the data of
|
|
5
|
+
* their own block): which composition starts it, which blocks have problems, where a test visitor is, how many visitors
|
|
6
|
+
* passed. The screen that owns the canvas (the editor, the Runs tab) makes one of these and the canvas shares it with the
|
|
7
|
+
* block and line drawings below it through the component context, so a block never asks the editor for anything by name.
|
|
8
|
+
*
|
|
9
|
+
* Everything here is read while drawing, so a change of any of it redraws only what shows it.
|
|
10
|
+
*/
|
|
11
|
+
export interface CanvasMarks {
|
|
12
|
+
/** The composition block visitors see first. */
|
|
13
|
+
startNodeId: string | null;
|
|
14
|
+
/** How many problems the draft has in a block (0 when it has none). */
|
|
15
|
+
problemCountOf(nodeId: string): number;
|
|
16
|
+
/** A problem in the line itself. */
|
|
17
|
+
hasEdgeProblem(edgeId: string): boolean;
|
|
18
|
+
/** Where a test visitor is: the line was followed on the way here. */
|
|
19
|
+
isEdgeTaken(edgeId: string): boolean;
|
|
20
|
+
/** Visitors who entered a block (the Runs tab); null where no counts are shown. */
|
|
21
|
+
entryCountOf(nodeId: string): number | null;
|
|
22
|
+
/** Visitors who followed a line (the Runs tab); null where no counts are shown. */
|
|
23
|
+
followCountOf(edgeId: string): number | null;
|
|
24
|
+
/** Times a composition could not be shown (the Runs tab); 0 when it always could. */
|
|
25
|
+
failureCountOf(nodeId: string): number;
|
|
26
|
+
}
|
|
27
|
+
/** What a block's drawing needs to say its content in words. */
|
|
28
|
+
export interface CanvasWords {
|
|
29
|
+
/** The composition as the API described it; `null` when it is not available to this person, `undefined` while unknown. */
|
|
30
|
+
findComposition(compositionId: string): CompositionOption | null | undefined;
|
|
31
|
+
/** One line that says what a trigger waits for. */
|
|
32
|
+
summarizeTrigger(trigger: TriggerConfig): string;
|
|
33
|
+
/** What a field of a test of this condition is called (the widget's label, or the column's name). */
|
|
34
|
+
labelField(conditionId: string, field: FieldReference): string;
|
|
35
|
+
/** The graph on the canvas, for what a block says about its neighbours (the next step of a rule). */
|
|
36
|
+
readonly graph: WorkflowGraph;
|
|
37
|
+
/** What a block is called, by its id. */
|
|
38
|
+
describeBlock(nodeId: string): string;
|
|
39
|
+
}
|
|
40
|
+
/** Everything a block and a line of the canvas can read. */
|
|
41
|
+
export interface CanvasContext {
|
|
42
|
+
marks: CanvasMarks;
|
|
43
|
+
words: CanvasWords;
|
|
44
|
+
/** The canvas cannot be changed (Runs, a version being looked at, a touch screen): blocks show no way to change anything. */
|
|
45
|
+
readOnly: boolean;
|
|
46
|
+
}
|
|
47
|
+
/** A getter function for each part: the owner passes functions that read its own state, so the drawings stay reactive. */
|
|
48
|
+
export declare function provideCanvasContext(read: () => CanvasContext): void;
|
|
49
|
+
/** Called by a block or a line while it is being created. Outside a canvas it is an empty workflow, so a block can still draw. */
|
|
50
|
+
export declare function useCanvasContext(): () => CanvasContext;
|
|
51
|
+
/** The line a block's rule leads along, if it has one: the next step of a rule or of a trigger. */
|
|
52
|
+
export declare function findEdgeFrom(graph: WorkflowGraph, nodeId: string, sourcePort: string): WorkflowEdge | undefined;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getContext, setContext } from 'svelte';
|
|
2
|
+
const CANVAS_CONTEXT_KEY = Symbol('workflows-canvas-context');
|
|
3
|
+
/** A getter function for each part: the owner passes functions that read its own state, so the drawings stay reactive. */
|
|
4
|
+
export function provideCanvasContext(read) {
|
|
5
|
+
setContext(CANVAS_CONTEXT_KEY, read);
|
|
6
|
+
}
|
|
7
|
+
/** Called by a block or a line while it is being created. Outside a canvas it is an empty workflow, so a block can still draw. */
|
|
8
|
+
export function useCanvasContext() {
|
|
9
|
+
const read = getContext(CANVAS_CONTEXT_KEY);
|
|
10
|
+
return read ?? readEmptyContext;
|
|
11
|
+
}
|
|
12
|
+
const EMPTY_GRAPH = { schemaVersion: 1, nodes: [], edges: [] };
|
|
13
|
+
function readEmptyContext() {
|
|
14
|
+
return {
|
|
15
|
+
marks: {
|
|
16
|
+
startNodeId: null,
|
|
17
|
+
problemCountOf: () => 0,
|
|
18
|
+
hasEdgeProblem: () => false,
|
|
19
|
+
isEdgeTaken: () => false,
|
|
20
|
+
entryCountOf: () => null,
|
|
21
|
+
followCountOf: () => null,
|
|
22
|
+
failureCountOf: () => 0
|
|
23
|
+
},
|
|
24
|
+
words: {
|
|
25
|
+
findComposition: () => undefined,
|
|
26
|
+
summarizeTrigger: () => '',
|
|
27
|
+
labelField: (_conditionId, field) => field.name,
|
|
28
|
+
graph: EMPTY_GRAPH,
|
|
29
|
+
describeBlock: () => ''
|
|
30
|
+
},
|
|
31
|
+
readOnly: true
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** The line a block's rule leads along, if it has one: the next step of a rule or of a trigger. */
|
|
35
|
+
export function findEdgeFrom(graph, nodeId, sourcePort) {
|
|
36
|
+
return graph.edges.find((edge) => edge.source === nodeId && edge.sourcePort === sourcePort);
|
|
37
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { WorkflowGraph } from '@widgetic/workflows-engine';
|
|
2
|
+
import type { TranslateWorkflowsMessage } from './blockLabels.js';
|
|
3
|
+
import type { CanvasWords } from './canvasContext.js';
|
|
4
|
+
import type { CompositionOptionsById } from './capabilityModel.js';
|
|
5
|
+
/**
|
|
6
|
+
* The words the blocks of a canvas need, made from one workflow and what is known about its compositions: what a block is
|
|
7
|
+
* called, what a trigger waits for in a line, what a column of a test is called. The editor makes it for the draft, the Runs
|
|
8
|
+
* tab for the version whose counts it shows; both draw the same blocks, so both ask the same questions.
|
|
9
|
+
*
|
|
10
|
+
* It is made again whenever the workflow, the compositions, the language or the time zone change, and works out each answer
|
|
11
|
+
* the first time a block asks, so a canvas of twenty-five blocks does the work for the blocks that are drawn.
|
|
12
|
+
*/
|
|
13
|
+
export interface CanvasWordsInput {
|
|
14
|
+
graph: WorkflowGraph;
|
|
15
|
+
options: CompositionOptionsById;
|
|
16
|
+
/** The workflow's time zone: a scheduled moment is told in it. */
|
|
17
|
+
timeZone: string;
|
|
18
|
+
/** The language tag, for how a date is written. */
|
|
19
|
+
locale: string;
|
|
20
|
+
t: TranslateWorkflowsMessage;
|
|
21
|
+
}
|
|
22
|
+
export declare function makeCanvasWords(input: CanvasWordsInput): CanvasWords;
|
|
23
|
+
/** The composition block a trigger follows, when its line comes from one that was chosen. */
|
|
24
|
+
export declare function findCompositionOfTrigger(graph: WorkflowGraph, triggerId: string): string | undefined;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { buildGraphIndex, findUpstreamTrigger } from '@widgetic/workflows-engine';
|
|
2
|
+
import { describeBlocksUniquely, summarizeTrigger } from './blockLabels.js';
|
|
3
|
+
import { labelOfField, listFieldChoices } from './capabilityModel.js';
|
|
4
|
+
export function makeCanvasWords(input) {
|
|
5
|
+
const { graph, options, timeZone, locale, t } = input;
|
|
6
|
+
let labels = null;
|
|
7
|
+
const readLabels = () => (labels ??= describeBlocksUniquely(graph, options, t));
|
|
8
|
+
// A condition reads what the trigger before it carries, so its columns are worked out once for all of its tests.
|
|
9
|
+
const choicesByCondition = new Map();
|
|
10
|
+
const readChoices = (conditionId) => {
|
|
11
|
+
let choices = choicesByCondition.get(conditionId);
|
|
12
|
+
if (choices === undefined) {
|
|
13
|
+
choices = listFieldChoices(graph, conditionId, options);
|
|
14
|
+
choicesByCondition.set(conditionId, choices);
|
|
15
|
+
}
|
|
16
|
+
return choices;
|
|
17
|
+
};
|
|
18
|
+
// What an action is called in the widget: the id of an action says which widget metric it is, and the label is the widget's own.
|
|
19
|
+
const describeAction = (actionId) => {
|
|
20
|
+
for (const option of Object.values(options)) {
|
|
21
|
+
const item = option?.actions.items.find((candidate) => candidate.id === actionId);
|
|
22
|
+
if (item)
|
|
23
|
+
return item.label;
|
|
24
|
+
}
|
|
25
|
+
return actionId;
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
findComposition: (compositionId) => options[compositionId],
|
|
29
|
+
summarizeTrigger: (trigger) => summarizeTrigger(trigger, { t, locale, timeZone, describeAction }),
|
|
30
|
+
labelField: (conditionId, field) => labelOfField(field, readChoices(conditionId)),
|
|
31
|
+
graph,
|
|
32
|
+
describeBlock: (nodeId) => readLabels().get(nodeId) ?? t('workflows.block.unknown')
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** The composition block a trigger follows, when its line comes from one that was chosen. */
|
|
36
|
+
export function findCompositionOfTrigger(graph, triggerId) {
|
|
37
|
+
const compositionId = findUpstreamTrigger(buildGraphIndex(graph), triggerId)?.compositionNode
|
|
38
|
+
?.compositionId;
|
|
39
|
+
return compositionId === '' ? undefined : compositionId;
|
|
40
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { FieldReference, ValidationContext, WorkflowGraph } from '@widgetic/workflows-engine';
|
|
2
|
+
import type { CapabilityReason, CompositionOption } from '../api/types.js';
|
|
3
|
+
import type { TriggerKind } from './graphModel.js';
|
|
4
|
+
/** Compositions by id; `null` for one the API does not know (gone, or not one this person may see). */
|
|
5
|
+
export type CompositionOptionsById = Readonly<Record<string, CompositionOption | null | undefined>>;
|
|
6
|
+
/**
|
|
7
|
+
* The engine's view of what these compositions can do. It is the same translation the gateway makes when it judges a
|
|
8
|
+
* publish: every table is listed (an "Input added" trigger waits for a new row, whether or not a rule may read a column
|
|
9
|
+
* of it), and a capability that is off lists nothing.
|
|
10
|
+
*/
|
|
11
|
+
export declare function toValidationContext(options: CompositionOptionsById): ValidationContext;
|
|
12
|
+
/** Whether a trigger kind can be used on a composition, and when not, why (so the editor says it next to the choice). */
|
|
13
|
+
export type TriggerAvailability = {
|
|
14
|
+
enabled: true;
|
|
15
|
+
} | {
|
|
16
|
+
enabled: false;
|
|
17
|
+
reason: CapabilityReason;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Whether this composition offers this trigger. "Event from your page" and "Scheduled" need nothing from the widget, so
|
|
21
|
+
* they are always on. A composition the API did not give (not chosen yet, or gone) is not judged: the kinds stay on, and the
|
|
22
|
+
* publish check reports what is wrong.
|
|
23
|
+
*/
|
|
24
|
+
export declare function readTriggerAvailability(option: CompositionOption | null | undefined, kind: TriggerKind): TriggerAvailability;
|
|
25
|
+
/** A value a condition can pick, with the words a person sees for it. */
|
|
26
|
+
export interface FieldChoice {
|
|
27
|
+
field: FieldReference;
|
|
28
|
+
/** `Plan` for a column the widget names, `plan` for a value of a page event. What the person sees first. */
|
|
29
|
+
label: string;
|
|
30
|
+
/** The table a column belongs to, to tell two columns of the same name apart; null for a value of a page event. */
|
|
31
|
+
table: string | null;
|
|
32
|
+
}
|
|
33
|
+
/** The key a choice goes by in a list: kind, name and type, which is what makes a reference the same reference. */
|
|
34
|
+
export declare function fieldChoiceKey(field: FieldReference): string;
|
|
35
|
+
/**
|
|
36
|
+
* The values a block after a trigger can read, with labels. A condition reads only what the trigger directly before it carries
|
|
37
|
+
* (the columns of the table an "Input added" trigger watches, the values a page event promises), and `undefined` for the list
|
|
38
|
+
* means "cannot tell yet" (the composition is not known), which the screen shows as an empty list that fills in once it is.
|
|
39
|
+
*/
|
|
40
|
+
export declare function listFieldChoices(graph: WorkflowGraph, nodeId: string, options: CompositionOptionsById): FieldChoice[];
|
|
41
|
+
/** The words for a field a rule already holds, found among the choices; the field's own name when it is not among them any more. */
|
|
42
|
+
export declare function labelOfField(field: FieldReference, choices: readonly FieldChoice[]): string;
|
|
43
|
+
/** The table names an "Input added" trigger can watch on a composition (all of them, even one with no column a rule may read). */
|
|
44
|
+
export declare function listInputTables(option: CompositionOption | null | undefined): string[];
|
|
45
|
+
/** The actions an "Action in the widget" trigger can wait for on a composition. */
|
|
46
|
+
export declare function listActionChoices(option: CompositionOption | null | undefined): CompositionOption['actions']['items'];
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a composition can do in a workflow, as the editor needs it: which triggers it offers, which values a condition after
|
|
3
|
+
* a trigger can read, and the engine's own view of all of it (so the editor can check a draft while it is being drawn, with
|
|
4
|
+
* the same rules the publish check applies).
|
|
5
|
+
*
|
|
6
|
+
* The compositions' capabilities come from the API (`composition-options`): a composition offers "Input added" only when
|
|
7
|
+
* its widget keeps a table a visitor can add to, and "Action in the widget" only when the published widget declares a goal.
|
|
8
|
+
* Nothing here decides that; this reads what the API said and turns it into the answers a screen asks for.
|
|
9
|
+
*/
|
|
10
|
+
import { buildGraphIndex, findUpstreamTrigger, listAvailableFields } from '@widgetic/workflows-engine';
|
|
11
|
+
/**
|
|
12
|
+
* The engine's view of what these compositions can do. It is the same translation the gateway makes when it judges a
|
|
13
|
+
* publish: every table is listed (an "Input added" trigger waits for a new row, whether or not a rule may read a column
|
|
14
|
+
* of it), and a capability that is off lists nothing.
|
|
15
|
+
*/
|
|
16
|
+
export function toValidationContext(options) {
|
|
17
|
+
const compositions = Object.create(null);
|
|
18
|
+
for (const [compositionId, option] of Object.entries(options)) {
|
|
19
|
+
if (option === undefined)
|
|
20
|
+
continue;
|
|
21
|
+
compositions[compositionId] = option === null ? null : capabilitiesOf(option);
|
|
22
|
+
}
|
|
23
|
+
return { compositions };
|
|
24
|
+
}
|
|
25
|
+
function capabilitiesOf(option) {
|
|
26
|
+
const columnsByTable = new Map(option.inputs.tables.map((name) => [name, []]));
|
|
27
|
+
for (const field of option.inputs.fields) {
|
|
28
|
+
const columns = columnsByTable.get(field.table);
|
|
29
|
+
if (columns)
|
|
30
|
+
columns.push({ name: field.column, type: field.type });
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
published: option.published,
|
|
34
|
+
inputs: {
|
|
35
|
+
enabled: option.inputs.enabled,
|
|
36
|
+
tables: option.inputs.enabled
|
|
37
|
+
? [...columnsByTable].map(([name, columns]) => ({ name, columns }))
|
|
38
|
+
: []
|
|
39
|
+
},
|
|
40
|
+
actions: {
|
|
41
|
+
enabled: option.actions.enabled,
|
|
42
|
+
items: option.actions.enabled ? option.actions.items.map((item) => ({ id: item.id })) : []
|
|
43
|
+
},
|
|
44
|
+
allowedWebsites: option.allowedWebsites
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Whether this composition offers this trigger. "Event from your page" and "Scheduled" need nothing from the widget, so
|
|
49
|
+
* they are always on. A composition the API did not give (not chosen yet, or gone) is not judged: the kinds stay on, and the
|
|
50
|
+
* publish check reports what is wrong.
|
|
51
|
+
*/
|
|
52
|
+
export function readTriggerAvailability(option, kind) {
|
|
53
|
+
if (option === null || option === undefined)
|
|
54
|
+
return { enabled: true };
|
|
55
|
+
switch (kind) {
|
|
56
|
+
case 'input':
|
|
57
|
+
return option.inputs.enabled
|
|
58
|
+
? { enabled: true }
|
|
59
|
+
: {
|
|
60
|
+
enabled: false,
|
|
61
|
+
reason: option.inputs.reason ??
|
|
62
|
+
(option.published ? 'widget_keeps_no_data' : 'widget_not_published')
|
|
63
|
+
};
|
|
64
|
+
case 'action':
|
|
65
|
+
return option.actions.enabled
|
|
66
|
+
? { enabled: true }
|
|
67
|
+
: {
|
|
68
|
+
enabled: false,
|
|
69
|
+
reason: option.actions.reason ??
|
|
70
|
+
(option.published ? 'widget_reports_no_actions' : 'widget_not_published')
|
|
71
|
+
};
|
|
72
|
+
case 'pageEvent':
|
|
73
|
+
case 'scheduled':
|
|
74
|
+
return { enabled: true };
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/** The key a choice goes by in a list: kind, name and type, which is what makes a reference the same reference. */
|
|
78
|
+
export function fieldChoiceKey(field) {
|
|
79
|
+
return `${field.kind}:${field.type}:${field.name}`;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The values a block after a trigger can read, with labels. A condition reads only what the trigger directly before it carries
|
|
83
|
+
* (the columns of the table an "Input added" trigger watches, the values a page event promises), and `undefined` for the list
|
|
84
|
+
* means "cannot tell yet" (the composition is not known), which the screen shows as an empty list that fills in once it is.
|
|
85
|
+
*/
|
|
86
|
+
export function listFieldChoices(graph, nodeId, options) {
|
|
87
|
+
const index = buildGraphIndex(graph);
|
|
88
|
+
const available = listAvailableFields(index, nodeId, toValidationContext(options)) ?? [];
|
|
89
|
+
const upstream = findUpstreamTrigger(index, nodeId);
|
|
90
|
+
const option = upstream?.compositionNode
|
|
91
|
+
? options[upstream.compositionNode.compositionId]
|
|
92
|
+
: undefined;
|
|
93
|
+
const watchedTable = upstream?.trigger.trigger.kind === 'input' ? upstream.trigger.trigger.table : null;
|
|
94
|
+
return available.map((field) => {
|
|
95
|
+
if (field.kind === 'event')
|
|
96
|
+
return { field, label: field.name, table: null };
|
|
97
|
+
const column = option?.inputs.fields.find((candidate) => candidate.table === watchedTable && candidate.column === field.name);
|
|
98
|
+
return { field, label: column?.label ?? field.name, table: watchedTable };
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/** The words for a field a rule already holds, found among the choices; the field's own name when it is not among them any more. */
|
|
102
|
+
export function labelOfField(field, choices) {
|
|
103
|
+
return (choices.find((choice) => fieldChoiceKey(choice.field) === fieldChoiceKey(field))?.label ??
|
|
104
|
+
field.name);
|
|
105
|
+
}
|
|
106
|
+
/** The table names an "Input added" trigger can watch on a composition (all of them, even one with no column a rule may read). */
|
|
107
|
+
export function listInputTables(option) {
|
|
108
|
+
return option?.inputs.enabled ? option.inputs.tables : [];
|
|
109
|
+
}
|
|
110
|
+
/** The actions an "Action in the widget" trigger can wait for on a composition. */
|
|
111
|
+
export function listActionChoices(option) {
|
|
112
|
+
return option?.actions.enabled ? option.actions.items : [];
|
|
113
|
+
}
|