@widgetic/workflows 0.1.1 → 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/README.md +107 -46
- 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 +41 -17
- package/dist/components/WorkflowsEmptyState.svelte +16 -5
- package/dist/components/WorkflowsEmptyState.svelte.d.ts +5 -16
- package/dist/components/WorkflowsHeader.svelte +2 -2
- 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 +0 -2
- package/dist/components/index.js +0 -2
- 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/language.d.ts +3 -3
- package/dist/i18n/messages.d.ts +396 -4
- package/dist/i18n/messages.js +421 -8
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/types/index.d.ts +31 -3
- package/package.json +5 -1
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
One trigger of the composition the test visitor is on, with a button that fires it. A trigger that carries values (a new
|
|
3
|
+
entry, a page's event) asks for them first, so the person can try each rule of the condition that follows; one that carries
|
|
4
|
+
none (an action, a wait) is only fired.
|
|
5
|
+
|
|
6
|
+
Nothing is sent anywhere and nothing is counted: this is the engine running the draft on the screen.
|
|
7
|
+
-->
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import type { FieldType, FieldValue, TriggerNode } from '@widgetic/workflows-engine';
|
|
10
|
+
import { FIELD_TYPE_MESSAGE_KEYS, summarizeTrigger } from '../../editor/blockLabels.js';
|
|
11
|
+
import { findCompositionOfTrigger } from '../../editor/canvasWords.js';
|
|
12
|
+
import { useEditorState } from '../../editor/editorState.svelte.js';
|
|
13
|
+
import { readTypedValue } from '../../editor/graphModel.js';
|
|
14
|
+
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
15
|
+
import ActionButton from '../ui/ActionButton.svelte';
|
|
16
|
+
import Icon from '../ui/Icon.svelte';
|
|
17
|
+
import SelectField from '../ui/SelectField.svelte';
|
|
18
|
+
import TextField from '../ui/TextField.svelte';
|
|
19
|
+
import type { SelectChoice } from '../ui/types.js';
|
|
20
|
+
|
|
21
|
+
interface Props {
|
|
22
|
+
trigger: TriggerNode;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let { trigger }: Props = $props();
|
|
26
|
+
|
|
27
|
+
const editor = useEditorState();
|
|
28
|
+
const { t, locale } = useWorkflowsLanguage();
|
|
29
|
+
|
|
30
|
+
interface TestValueField {
|
|
31
|
+
name: string;
|
|
32
|
+
label: string;
|
|
33
|
+
type: FieldType;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The composition of this trigger, for the names its widget gives to its columns and actions. */
|
|
37
|
+
const sourceOption = $derived.by(() => {
|
|
38
|
+
const compositionId = findCompositionOfTrigger(editor.graph, trigger.id);
|
|
39
|
+
return compositionId ? editor.options[compositionId] : undefined;
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const summary = $derived(
|
|
43
|
+
summarizeTrigger(trigger.trigger, {
|
|
44
|
+
t: $t,
|
|
45
|
+
locale: $locale,
|
|
46
|
+
timeZone: editor.timezone,
|
|
47
|
+
describeAction: (actionId) =>
|
|
48
|
+
sourceOption?.actions.items.find((item) => item.id === actionId)?.label ?? actionId
|
|
49
|
+
})
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
/** The values this trigger carries, which the person can set for the test. */
|
|
53
|
+
const fields = $derived.by<TestValueField[]>(() => {
|
|
54
|
+
const config = trigger.trigger;
|
|
55
|
+
if (config.kind === 'pageEvent')
|
|
56
|
+
return config.values.map((value) => ({
|
|
57
|
+
name: value.name,
|
|
58
|
+
label: value.name,
|
|
59
|
+
type: value.type
|
|
60
|
+
}));
|
|
61
|
+
if (config.kind === 'input' && sourceOption) {
|
|
62
|
+
return sourceOption.inputs.fields
|
|
63
|
+
.filter((field) => field.table === config.table)
|
|
64
|
+
.map((field) => ({ name: field.column, label: field.label, type: field.type }));
|
|
65
|
+
}
|
|
66
|
+
return [];
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const yesNoChoices = $derived<SelectChoice[]>([
|
|
70
|
+
{ value: 'true', label: $t('workflows.value.yes') },
|
|
71
|
+
{ value: 'false', label: $t('workflows.value.no') }
|
|
72
|
+
]);
|
|
73
|
+
|
|
74
|
+
/** What the person typed for each value, by its name. */
|
|
75
|
+
let typed = $state<Record<string, string>>({});
|
|
76
|
+
|
|
77
|
+
/** What is in the box of a value: what was typed, or the start of its kind (an empty box, "No" for a yes/no value). */
|
|
78
|
+
function readTyped(field: TestValueField): string {
|
|
79
|
+
return typed[field.name] ?? (field.type === 'boolean' ? 'false' : '');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Fires the trigger with the values typed; a text box left empty carries no value, as an empty value would not. */
|
|
83
|
+
function fire(): void {
|
|
84
|
+
const values: Record<string, FieldValue> = {};
|
|
85
|
+
for (const field of fields) {
|
|
86
|
+
const text = readTyped(field);
|
|
87
|
+
const value = readTypedValue(field.type, text);
|
|
88
|
+
if (value !== undefined && !(field.type === 'text' && text === ''))
|
|
89
|
+
values[field.name] = value;
|
|
90
|
+
}
|
|
91
|
+
editor.fireTrigger(trigger.id, values);
|
|
92
|
+
}
|
|
93
|
+
</script>
|
|
94
|
+
|
|
95
|
+
<div class="flex flex-col gap-2 rounded-large border border-grey2 p-3">
|
|
96
|
+
<p class="text-sm font-medium" dir="auto">{summary}</p>
|
|
97
|
+
{#each fields as field (field.name)}
|
|
98
|
+
{#if field.type === 'boolean'}
|
|
99
|
+
<SelectField
|
|
100
|
+
label={field.label}
|
|
101
|
+
value={readTyped(field)}
|
|
102
|
+
choices={yesNoChoices}
|
|
103
|
+
help={$t(FIELD_TYPE_MESSAGE_KEYS[field.type])}
|
|
104
|
+
onchange={(text) => (typed[field.name] = text)}
|
|
105
|
+
/>
|
|
106
|
+
{:else}
|
|
107
|
+
<TextField
|
|
108
|
+
label={field.label}
|
|
109
|
+
type={field.type === 'number' ? 'number' : 'text'}
|
|
110
|
+
inputmode={field.type === 'number' ? 'decimal' : 'text'}
|
|
111
|
+
maxlength={200}
|
|
112
|
+
help={$t(FIELD_TYPE_MESSAGE_KEYS[field.type])}
|
|
113
|
+
bind:value={() => readTyped(field), (text) => (typed[field.name] = text)}
|
|
114
|
+
/>
|
|
115
|
+
{/if}
|
|
116
|
+
{/each}
|
|
117
|
+
<ActionButton size="small" class="self-start" onclick={fire}>
|
|
118
|
+
<Icon name="play" />
|
|
119
|
+
{$t('workflows.test.fire')}
|
|
120
|
+
</ActionButton>
|
|
121
|
+
</div>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TriggerNode } from '@widgetic/workflows-engine';
|
|
2
|
+
interface Props {
|
|
3
|
+
trigger: TriggerNode;
|
|
4
|
+
}
|
|
5
|
+
declare const TestTriggerCard: import("svelte").Component<Props, {}, "">;
|
|
6
|
+
type TestTriggerCard = ReturnType<typeof TestTriggerCard>;
|
|
7
|
+
export default TestTriggerCard;
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The side panel for a trigger block: what the workflow waits for after a composition is shown, and which block comes next.
|
|
3
|
+
|
|
4
|
+
The kinds a composition cannot feed stay in the list, greyed out, with the reason written under the list (a widget that keeps
|
|
5
|
+
no visitor data has no "Input added"; one that reports no actions has no "Action in the widget"), so a person learns what
|
|
6
|
+
to change instead of wondering where a kind went. "Event from your page" and "Scheduled" need nothing from the widget.
|
|
7
|
+
|
|
8
|
+
Words typed here (the name of an event, of its values) are kept when the person leaves the field. A moment in time is
|
|
9
|
+
typed in the workflow's own time zone and stored as the same moment in UTC.
|
|
10
|
+
-->
|
|
11
|
+
<script lang="ts">
|
|
12
|
+
import {
|
|
13
|
+
EVENT_NAME_PATTERN,
|
|
14
|
+
MAX_EVENT_VALUES,
|
|
15
|
+
OUTPUT_PORT,
|
|
16
|
+
SCHEDULE_UNITS
|
|
17
|
+
} from '@widgetic/workflows-engine';
|
|
18
|
+
import type {
|
|
19
|
+
EventValueDeclaration,
|
|
20
|
+
ScheduleConfig,
|
|
21
|
+
ScheduleUnit,
|
|
22
|
+
TriggerNode
|
|
23
|
+
} from '@widgetic/workflows-engine';
|
|
24
|
+
import {
|
|
25
|
+
CAPABILITY_REASON_MESSAGE_KEYS,
|
|
26
|
+
TRIGGER_KIND_MESSAGE_KEYS,
|
|
27
|
+
UNIT_MESSAGE_KEYS
|
|
28
|
+
} from '../../editor/blockLabels.js';
|
|
29
|
+
import { findCompositionOfTrigger } from '../../editor/canvasWords.js';
|
|
30
|
+
import {
|
|
31
|
+
listActionChoices,
|
|
32
|
+
listInputTables,
|
|
33
|
+
readTriggerAvailability
|
|
34
|
+
} from '../../editor/capabilityModel.js';
|
|
35
|
+
import { useEditorState } from '../../editor/editorState.svelte.js';
|
|
36
|
+
import { TRIGGER_KINDS, changeScheduleMode, changeTriggerKind } from '../../editor/graphModel.js';
|
|
37
|
+
import type { TriggerKind } from '../../editor/graphModel.js';
|
|
38
|
+
import { utcIsoToZonedLocal, zonedLocalToUtcIso } from '../../editor/zonedTime.js';
|
|
39
|
+
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
40
|
+
import ActionButton from '../ui/ActionButton.svelte';
|
|
41
|
+
import Icon from '../ui/Icon.svelte';
|
|
42
|
+
import SelectField from '../ui/SelectField.svelte';
|
|
43
|
+
import TextField from '../ui/TextField.svelte';
|
|
44
|
+
import type { SelectChoice } from '../ui/types.js';
|
|
45
|
+
import BlockProblems from './BlockProblems.svelte';
|
|
46
|
+
import EventValueRow from './EventValueRow.svelte';
|
|
47
|
+
import NextStepSelect from './NextStepSelect.svelte';
|
|
48
|
+
|
|
49
|
+
interface Props {
|
|
50
|
+
node: TriggerNode;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let { node }: Props = $props();
|
|
54
|
+
|
|
55
|
+
const editor = useEditorState();
|
|
56
|
+
const { t } = useWorkflowsLanguage();
|
|
57
|
+
|
|
58
|
+
const trigger = $derived(node.trigger);
|
|
59
|
+
|
|
60
|
+
/** What the API says about the composition this trigger follows (`undefined` while it is not known). */
|
|
61
|
+
const sourceOption = $derived.by(() => {
|
|
62
|
+
const compositionId = findCompositionOfTrigger(editor.graph, node.id);
|
|
63
|
+
return compositionId ? editor.options[compositionId] : undefined;
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// --- the kind -------------------------------------------------------------------------------------------------
|
|
67
|
+
|
|
68
|
+
const kindChoices = $derived<SelectChoice[]>(
|
|
69
|
+
TRIGGER_KINDS.map((kind) => ({
|
|
70
|
+
value: kind,
|
|
71
|
+
label: $t(TRIGGER_KIND_MESSAGE_KEYS[kind]),
|
|
72
|
+
// The kind it has now stays selectable, so the list can still show it.
|
|
73
|
+
disabled: !readTriggerAvailability(sourceOption, kind).enabled && kind !== trigger.kind
|
|
74
|
+
}))
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
/** Why each kind that is off is off, one sentence a kind. */
|
|
78
|
+
const unavailableNotes = $derived(
|
|
79
|
+
TRIGGER_KINDS.flatMap((kind) => {
|
|
80
|
+
const availability = readTriggerAvailability(sourceOption, kind);
|
|
81
|
+
return availability.enabled
|
|
82
|
+
? []
|
|
83
|
+
: [
|
|
84
|
+
$t('workflows.trigger.unavailable', {
|
|
85
|
+
kind: $t(TRIGGER_KIND_MESSAGE_KEYS[kind]),
|
|
86
|
+
reason: $t(CAPABILITY_REASON_MESSAGE_KEYS[availability.reason])
|
|
87
|
+
})
|
|
88
|
+
];
|
|
89
|
+
})
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
function chooseKind(kind: string): void {
|
|
93
|
+
editor.replaceBlock(changeTriggerKind(node, kind as TriggerKind));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// --- Input added ----------------------------------------------------------------------------------------------
|
|
97
|
+
|
|
98
|
+
const tableChoices = $derived.by<SelectChoice[]>(() => {
|
|
99
|
+
if (trigger.kind !== 'input') return [];
|
|
100
|
+
const tables = listInputTables(sourceOption);
|
|
101
|
+
const choices: SelectChoice[] = [
|
|
102
|
+
{ value: '', label: $t('workflows.trigger.chooseOne') },
|
|
103
|
+
...tables.map((table) => ({ value: table, label: table }))
|
|
104
|
+
];
|
|
105
|
+
// A table the widget no longer has is still shown, marked, so the person sees what the draft holds.
|
|
106
|
+
if (trigger.table !== '' && !tables.includes(trigger.table)) {
|
|
107
|
+
choices.push({
|
|
108
|
+
value: trigger.table,
|
|
109
|
+
label: $t('workflows.trigger.notFound', { name: trigger.table })
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return choices;
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
/** The values of the chosen table a condition after this trigger can read, by the widget's names for them. */
|
|
116
|
+
const readableColumns = $derived(
|
|
117
|
+
trigger.kind === 'input' && sourceOption
|
|
118
|
+
? sourceOption.inputs.fields
|
|
119
|
+
.filter((field) => field.table === trigger.table)
|
|
120
|
+
.map((field) => field.label)
|
|
121
|
+
: []
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
// --- Action in the widget -------------------------------------------------------------------------------------
|
|
125
|
+
|
|
126
|
+
const actionChoices = $derived.by<SelectChoice[]>(() => {
|
|
127
|
+
if (trigger.kind !== 'action') return [];
|
|
128
|
+
const items = listActionChoices(sourceOption);
|
|
129
|
+
const choices: SelectChoice[] = [
|
|
130
|
+
{ value: '', label: $t('workflows.trigger.chooseOne') },
|
|
131
|
+
...items.map((item) => ({ value: item.id, label: item.label }))
|
|
132
|
+
];
|
|
133
|
+
if (trigger.actionId !== '' && !items.some((item) => item.id === trigger.actionId)) {
|
|
134
|
+
choices.push({
|
|
135
|
+
value: trigger.actionId,
|
|
136
|
+
label: $t('workflows.trigger.notFound', { name: trigger.actionId })
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
return choices;
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// --- Event from your page -------------------------------------------------------------------------------------
|
|
143
|
+
|
|
144
|
+
let eventNameDraft = $derived(trigger.kind === 'pageEvent' ? trigger.name : '');
|
|
145
|
+
|
|
146
|
+
const eventNameProblem = $derived(
|
|
147
|
+
eventNameDraft.trim() !== '' && !EVENT_NAME_PATTERN.test(eventNameDraft)
|
|
148
|
+
? $t('workflows.event.nameInvalid')
|
|
149
|
+
: undefined
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
function commitEventName(): void {
|
|
153
|
+
if (trigger.kind !== 'pageEvent') return;
|
|
154
|
+
const name = eventNameDraft.trim();
|
|
155
|
+
if (name !== trigger.name) editor.replaceBlock({ ...node, trigger: { ...trigger, name } });
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function changeEventValue(index: number, next: EventValueDeclaration): void {
|
|
159
|
+
if (trigger.kind !== 'pageEvent') return;
|
|
160
|
+
editor.replaceBlock({
|
|
161
|
+
...node,
|
|
162
|
+
trigger: {
|
|
163
|
+
...trigger,
|
|
164
|
+
values: trigger.values.map((value, position) => (position === index ? next : value))
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function removeEventValue(index: number): void {
|
|
170
|
+
if (trigger.kind !== 'pageEvent') return;
|
|
171
|
+
editor.replaceBlock({
|
|
172
|
+
...node,
|
|
173
|
+
trigger: { ...trigger, values: trigger.values.filter((_, position) => position !== index) }
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function addEventValue(): void {
|
|
178
|
+
if (trigger.kind !== 'pageEvent' || trigger.values.length >= MAX_EVENT_VALUES) return;
|
|
179
|
+
editor.replaceBlock({
|
|
180
|
+
...node,
|
|
181
|
+
trigger: { ...trigger, values: [...trigger.values, { name: '', type: 'text' }] }
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// --- Scheduled ------------------------------------------------------------------------------------------------
|
|
186
|
+
|
|
187
|
+
const schedule = $derived(trigger.kind === 'scheduled' ? trigger.schedule : null);
|
|
188
|
+
|
|
189
|
+
const scheduleModeChoices = $derived<SelectChoice[]>([
|
|
190
|
+
{ value: 'after', label: $t('workflows.schedule.modeAfter') },
|
|
191
|
+
{ value: 'at', label: $t('workflows.schedule.modeAt') }
|
|
192
|
+
]);
|
|
193
|
+
|
|
194
|
+
const unitChoices = $derived<SelectChoice[]>(
|
|
195
|
+
SCHEDULE_UNITS.map((unit) => ({ value: unit, label: $t(UNIT_MESSAGE_KEYS[unit]) }))
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
let waitAmountDraft = $derived(schedule?.mode === 'after' ? String(schedule.amount) : '1');
|
|
199
|
+
let momentDraft = $derived(
|
|
200
|
+
schedule?.mode === 'at' ? (utcIsoToZonedLocal(schedule.at, editor.timezone) ?? '') : ''
|
|
201
|
+
);
|
|
202
|
+
let momentProblem = $state<string | undefined>(undefined);
|
|
203
|
+
|
|
204
|
+
function replaceSchedule(next: ScheduleConfig): void {
|
|
205
|
+
editor.replaceBlock({ ...node, trigger: { kind: 'scheduled', schedule: next } });
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function chooseScheduleMode(mode: string): void {
|
|
209
|
+
if (!schedule) return;
|
|
210
|
+
momentProblem = undefined;
|
|
211
|
+
replaceSchedule(changeScheduleMode(schedule, mode as ScheduleConfig['mode']));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function commitWaitAmount(): void {
|
|
215
|
+
if (schedule?.mode !== 'after') return;
|
|
216
|
+
const amount = Number(waitAmountDraft);
|
|
217
|
+
// A wait is a whole number of units, at least one; anything else is kept as typed so the check can say what is wrong.
|
|
218
|
+
replaceSchedule({ ...schedule, amount: Number.isFinite(amount) ? amount : 0 });
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function chooseUnit(unit: string): void {
|
|
222
|
+
if (schedule?.mode !== 'after') return;
|
|
223
|
+
replaceSchedule({ ...schedule, unit: unit as ScheduleUnit });
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function commitMoment(): void {
|
|
227
|
+
if (schedule?.mode !== 'at') return;
|
|
228
|
+
const moment = zonedLocalToUtcIso(momentDraft, editor.timezone);
|
|
229
|
+
if (moment === null) {
|
|
230
|
+
momentProblem = $t('workflows.schedule.invalidMoment');
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
momentProblem = undefined;
|
|
234
|
+
if (moment !== schedule.at) replaceSchedule({ mode: 'at', at: moment });
|
|
235
|
+
}
|
|
236
|
+
</script>
|
|
237
|
+
|
|
238
|
+
<div class="flex flex-col gap-4">
|
|
239
|
+
<div>
|
|
240
|
+
<h3 class="text-sm font-semibold">{$t('workflows.trigger.heading')}</h3>
|
|
241
|
+
<p class="text-xs text-ink-muted">{$t('workflows.trigger.help')}</p>
|
|
242
|
+
</div>
|
|
243
|
+
|
|
244
|
+
<BlockProblems nodeId={node.id} />
|
|
245
|
+
|
|
246
|
+
<SelectField
|
|
247
|
+
label={$t('workflows.trigger.kindLabel')}
|
|
248
|
+
value={trigger.kind}
|
|
249
|
+
choices={kindChoices}
|
|
250
|
+
disabled={editor.isReadOnly}
|
|
251
|
+
onchange={chooseKind}
|
|
252
|
+
/>
|
|
253
|
+
{#if unavailableNotes.length > 0}
|
|
254
|
+
<ul class="flex flex-col gap-1 text-xs text-ink-muted">
|
|
255
|
+
{#each unavailableNotes as note (note)}
|
|
256
|
+
<li>{note}</li>
|
|
257
|
+
{/each}
|
|
258
|
+
</ul>
|
|
259
|
+
{/if}
|
|
260
|
+
|
|
261
|
+
{#if trigger.kind === 'input'}
|
|
262
|
+
<SelectField
|
|
263
|
+
label={$t('workflows.trigger.tableLabel')}
|
|
264
|
+
value={trigger.table}
|
|
265
|
+
choices={tableChoices}
|
|
266
|
+
disabled={editor.isReadOnly}
|
|
267
|
+
help={$t('workflows.trigger.tableHelp')}
|
|
268
|
+
onchange={(table) => editor.replaceBlock({ ...node, trigger: { kind: 'input', table } })}
|
|
269
|
+
/>
|
|
270
|
+
{#if trigger.table !== ''}
|
|
271
|
+
<p class="text-xs text-ink-muted">
|
|
272
|
+
{readableColumns.length > 0
|
|
273
|
+
? $t('workflows.trigger.readableValues', { values: readableColumns.join(', ') })
|
|
274
|
+
: $t('workflows.trigger.noReadableValues')}
|
|
275
|
+
</p>
|
|
276
|
+
{/if}
|
|
277
|
+
{:else if trigger.kind === 'action'}
|
|
278
|
+
<SelectField
|
|
279
|
+
label={$t('workflows.trigger.actionLabel')}
|
|
280
|
+
value={trigger.actionId}
|
|
281
|
+
choices={actionChoices}
|
|
282
|
+
disabled={editor.isReadOnly}
|
|
283
|
+
help={$t('workflows.trigger.actionHelp')}
|
|
284
|
+
onchange={(actionId) =>
|
|
285
|
+
editor.replaceBlock({ ...node, trigger: { kind: 'action', actionId } })}
|
|
286
|
+
/>
|
|
287
|
+
{:else if trigger.kind === 'pageEvent'}
|
|
288
|
+
<TextField
|
|
289
|
+
label={$t('workflows.event.nameLabel')}
|
|
290
|
+
placeholder={$t('workflows.event.namePlaceholder')}
|
|
291
|
+
help={$t('workflows.event.nameHelp')}
|
|
292
|
+
problem={eventNameProblem}
|
|
293
|
+
maxlength={64}
|
|
294
|
+
disabled={editor.isReadOnly}
|
|
295
|
+
bind:value={eventNameDraft}
|
|
296
|
+
onchange={commitEventName}
|
|
297
|
+
/>
|
|
298
|
+
<div class="flex flex-col gap-2">
|
|
299
|
+
<h4 class="text-xs font-medium">{$t('workflows.event.valuesHeading')}</h4>
|
|
300
|
+
<p class="text-xs text-ink-muted">{$t('workflows.event.valuesHelp')}</p>
|
|
301
|
+
{#each trigger.values as value, index (index)}
|
|
302
|
+
<EventValueRow
|
|
303
|
+
{value}
|
|
304
|
+
{index}
|
|
305
|
+
disabled={editor.isReadOnly}
|
|
306
|
+
onchange={(next) => changeEventValue(index, next)}
|
|
307
|
+
onremove={() => removeEventValue(index)}
|
|
308
|
+
/>
|
|
309
|
+
{/each}
|
|
310
|
+
{#if !editor.isReadOnly}
|
|
311
|
+
<ActionButton
|
|
312
|
+
size="small"
|
|
313
|
+
class="self-start"
|
|
314
|
+
disabled={trigger.values.length >= MAX_EVENT_VALUES}
|
|
315
|
+
onclick={addEventValue}
|
|
316
|
+
>
|
|
317
|
+
<Icon name="plus" />
|
|
318
|
+
{$t('workflows.event.addValue')}
|
|
319
|
+
</ActionButton>
|
|
320
|
+
{/if}
|
|
321
|
+
</div>
|
|
322
|
+
<p class="text-xs text-ink-muted">{$t('workflows.event.howToSend')}</p>
|
|
323
|
+
{:else if schedule}
|
|
324
|
+
<SelectField
|
|
325
|
+
label={$t('workflows.schedule.modeLabel')}
|
|
326
|
+
value={schedule.mode}
|
|
327
|
+
choices={scheduleModeChoices}
|
|
328
|
+
disabled={editor.isReadOnly}
|
|
329
|
+
onchange={chooseScheduleMode}
|
|
330
|
+
/>
|
|
331
|
+
{#if schedule.mode === 'after'}
|
|
332
|
+
<div class="flex items-start gap-2">
|
|
333
|
+
<TextField
|
|
334
|
+
class="w-24"
|
|
335
|
+
type="number"
|
|
336
|
+
min={1}
|
|
337
|
+
inputmode="numeric"
|
|
338
|
+
label={$t('workflows.schedule.amountLabel')}
|
|
339
|
+
disabled={editor.isReadOnly}
|
|
340
|
+
bind:value={waitAmountDraft}
|
|
341
|
+
onchange={commitWaitAmount}
|
|
342
|
+
/>
|
|
343
|
+
<SelectField
|
|
344
|
+
class="flex-1"
|
|
345
|
+
label={$t('workflows.schedule.unitLabel')}
|
|
346
|
+
value={schedule.unit}
|
|
347
|
+
choices={unitChoices}
|
|
348
|
+
disabled={editor.isReadOnly}
|
|
349
|
+
onchange={chooseUnit}
|
|
350
|
+
/>
|
|
351
|
+
</div>
|
|
352
|
+
<p class="text-xs text-ink-muted">{$t('workflows.schedule.afterHelp')}</p>
|
|
353
|
+
{:else}
|
|
354
|
+
<TextField
|
|
355
|
+
type="datetime-local"
|
|
356
|
+
label={$t('workflows.schedule.momentLabel')}
|
|
357
|
+
help={$t('workflows.schedule.momentHelp', { zone: editor.timezone })}
|
|
358
|
+
problem={momentProblem}
|
|
359
|
+
disabled={editor.isReadOnly}
|
|
360
|
+
bind:value={momentDraft}
|
|
361
|
+
onchange={commitMoment}
|
|
362
|
+
/>
|
|
363
|
+
{/if}
|
|
364
|
+
{/if}
|
|
365
|
+
|
|
366
|
+
<NextStepSelect
|
|
367
|
+
sourceId={node.id}
|
|
368
|
+
sourcePort={OUTPUT_PORT}
|
|
369
|
+
label={$t('workflows.trigger.nextLabel')}
|
|
370
|
+
emptyLabel={$t('workflows.trigger.nextNone')}
|
|
371
|
+
help={$t('workflows.trigger.nextHelp')}
|
|
372
|
+
/>
|
|
373
|
+
|
|
374
|
+
{#if !editor.isReadOnly}
|
|
375
|
+
<ActionButton
|
|
376
|
+
variant="danger"
|
|
377
|
+
size="small"
|
|
378
|
+
class="self-start"
|
|
379
|
+
onclick={() => editor.removeBlock(node.id)}
|
|
380
|
+
>
|
|
381
|
+
<Icon name="trash" />
|
|
382
|
+
{$t('workflows.panel.removeBlock')}
|
|
383
|
+
</ActionButton>
|
|
384
|
+
{/if}
|
|
385
|
+
</div>
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Version history: every publish made a version that never changes. The list shows which one is live; a version can be looked
|
|
3
|
+
at on the canvas (read-only), and restored, which copies it into the draft (publishing it is a separate step), so nothing
|
|
4
|
+
is ever lost by going back.
|
|
5
|
+
|
|
6
|
+
Visitors who were part-way through finish on the version they started on, so older versions are not gone from the embed
|
|
7
|
+
for a while after a newer one is published; the help line says so.
|
|
8
|
+
-->
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
import { formatMomentInZone } from '../../editor/blockLabels.js';
|
|
11
|
+
import { useEditorState } from '../../editor/editorState.svelte.js';
|
|
12
|
+
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
13
|
+
import ActionButton from '../ui/ActionButton.svelte';
|
|
14
|
+
import ConfirmDialog from '../ui/ConfirmDialog.svelte';
|
|
15
|
+
import Icon from '../ui/Icon.svelte';
|
|
16
|
+
|
|
17
|
+
const editor = useEditorState();
|
|
18
|
+
const { t, locale } = useWorkflowsLanguage();
|
|
19
|
+
|
|
20
|
+
let isAskingToRestore = $state(false);
|
|
21
|
+
|
|
22
|
+
const viewing = $derived(editor.viewing);
|
|
23
|
+
|
|
24
|
+
async function restore(): Promise<void> {
|
|
25
|
+
await editor.restoreViewedVersion();
|
|
26
|
+
isAskingToRestore = false;
|
|
27
|
+
}
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<div class="flex flex-col gap-4">
|
|
31
|
+
<div class="flex items-start justify-between gap-2">
|
|
32
|
+
<div>
|
|
33
|
+
<h3 class="text-sm font-semibold">{$t('workflows.history.heading')}</h3>
|
|
34
|
+
<p class="text-xs text-ink-muted">{$t('workflows.history.help')}</p>
|
|
35
|
+
</div>
|
|
36
|
+
<ActionButton
|
|
37
|
+
variant="ghost"
|
|
38
|
+
iconOnly
|
|
39
|
+
ariaLabel={$t('workflows.history.close')}
|
|
40
|
+
title={$t('workflows.history.close')}
|
|
41
|
+
onclick={() => editor.closeHistory()}
|
|
42
|
+
>
|
|
43
|
+
<Icon name="close" />
|
|
44
|
+
</ActionButton>
|
|
45
|
+
</div>
|
|
46
|
+
|
|
47
|
+
<!-- The banner above the canvas says which version is shown and has the way back to the draft; here is what can be done with it. -->
|
|
48
|
+
{#if viewing}
|
|
49
|
+
<div class="flex flex-wrap gap-2">
|
|
50
|
+
<ActionButton
|
|
51
|
+
variant="primary"
|
|
52
|
+
size="small"
|
|
53
|
+
disabled={editor.busy !== null || editor.status === 'archived'}
|
|
54
|
+
onclick={() => (isAskingToRestore = true)}
|
|
55
|
+
>
|
|
56
|
+
{$t('workflows.history.restore')}
|
|
57
|
+
</ActionButton>
|
|
58
|
+
</div>
|
|
59
|
+
{/if}
|
|
60
|
+
|
|
61
|
+
{#if editor.versionsState === 'loading' && editor.versions === null}
|
|
62
|
+
<p class="text-xs text-ink-muted" role="status">{$t('workflows.common.loading')}</p>
|
|
63
|
+
{:else if editor.versionsState === 'failed'}
|
|
64
|
+
<div class="flex flex-col items-start gap-2">
|
|
65
|
+
<p class="text-xs text-error" role="alert">{$t('workflows.history.failed')}</p>
|
|
66
|
+
<ActionButton size="small" onclick={() => void editor.loadVersions()}
|
|
67
|
+
>{$t('workflows.error.retry')}</ActionButton
|
|
68
|
+
>
|
|
69
|
+
</div>
|
|
70
|
+
{:else if editor.versions !== null && editor.versions.length === 0}
|
|
71
|
+
<p class="text-xs text-ink-muted">{$t('workflows.history.none')}</p>
|
|
72
|
+
{:else if editor.versions !== null}
|
|
73
|
+
<ul class="flex flex-col gap-2">
|
|
74
|
+
{#each editor.versions as version (version.id)}
|
|
75
|
+
{@const isShown = viewing?.id === version.id}
|
|
76
|
+
<li
|
|
77
|
+
class="flex items-start justify-between gap-2 rounded-medium border px-3 py-2 {isShown
|
|
78
|
+
? 'border-primary-green'
|
|
79
|
+
: 'border-grey2'}"
|
|
80
|
+
>
|
|
81
|
+
<div class="flex min-w-0 flex-col gap-0.5">
|
|
82
|
+
<span class="flex items-center gap-2 text-sm font-medium">
|
|
83
|
+
{$t('workflows.history.version', { number: version.versionNumber })}
|
|
84
|
+
{#if version.isLive}
|
|
85
|
+
<span
|
|
86
|
+
class="rounded-pill border border-primary-green px-2 text-xs font-normal text-primary-green"
|
|
87
|
+
>{$t('workflows.history.live')}</span
|
|
88
|
+
>
|
|
89
|
+
{/if}
|
|
90
|
+
</span>
|
|
91
|
+
<span class="text-xs text-ink-muted"
|
|
92
|
+
>{formatMomentInZone(version.publishedAt, $locale, editor.timezone)}</span
|
|
93
|
+
>
|
|
94
|
+
{#if version.publishedBy?.name}
|
|
95
|
+
<span class="truncate text-xs text-ink-muted" dir="auto"
|
|
96
|
+
>{$t('workflows.history.by', { name: version.publishedBy.name })}</span
|
|
97
|
+
>
|
|
98
|
+
{/if}
|
|
99
|
+
</div>
|
|
100
|
+
<ActionButton
|
|
101
|
+
size="small"
|
|
102
|
+
pressed={isShown}
|
|
103
|
+
disabled={editor.busy !== null}
|
|
104
|
+
onclick={() => void editor.viewVersion(version.id)}
|
|
105
|
+
>
|
|
106
|
+
{$t('workflows.history.view')}
|
|
107
|
+
</ActionButton>
|
|
108
|
+
</li>
|
|
109
|
+
{/each}
|
|
110
|
+
</ul>
|
|
111
|
+
{/if}
|
|
112
|
+
</div>
|
|
113
|
+
|
|
114
|
+
{#if isAskingToRestore && viewing}
|
|
115
|
+
<ConfirmDialog
|
|
116
|
+
title={$t('workflows.history.restoreTitle', { number: viewing.versionNumber })}
|
|
117
|
+
message={$t('workflows.history.restoreMessage', { number: viewing.versionNumber })}
|
|
118
|
+
confirmLabel={$t('workflows.history.restore')}
|
|
119
|
+
busy={editor.busy === 'restoring'}
|
|
120
|
+
onconfirm={() => void restore()}
|
|
121
|
+
oncancel={() => (isAskingToRestore = false)}
|
|
122
|
+
/>
|
|
123
|
+
{/if}
|