@widgetic/workflows 0.1.1 → 0.2.1
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 +118 -46
- package/dist/api/apiContext.d.ts +4 -0
- package/dist/api/apiContext.js +17 -0
- package/dist/api/types.d.ts +201 -0
- package/dist/api/types.js +3 -0
- package/dist/api/workflowsApi.d.ts +133 -0
- package/dist/api/workflowsApi.js +763 -0
- package/dist/components/Workflows.svelte +43 -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 +90 -0
- package/dist/components/WorkflowsWorkspace.svelte.d.ts +15 -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/ConflictBanner.svelte +78 -0
- package/dist/components/editor/ConflictBanner.svelte.d.ts +3 -0
- package/dist/components/editor/EditorBanners.svelte +141 -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/PresenceBanner.svelte +126 -0
- package/dist/components/editor/PresenceBanner.svelte.d.ts +3 -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 +198 -0
- package/dist/components/editor/WorkflowEditor.svelte.d.ts +17 -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/editLeaseController.d.ts +162 -0
- package/dist/editor/editLeaseController.js +459 -0
- package/dist/editor/editorState.svelte.d.ts +277 -0
- package/dist/editor/editorState.svelte.js +862 -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/keepCopy.d.ts +41 -0
- package/dist/editor/keepCopy.js +52 -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 +429 -4
- package/dist/i18n/messages.js +456 -8
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/types/index.d.ts +41 -3
- package/package.json +5 -1
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The side panel for a condition block: its rules, in the order they are tried, and what happens when none of them matches
|
|
3
|
+
(the Default). A condition compares only what the trigger right before it carries (the columns of the table an "Input
|
|
4
|
+
added" trigger watches, the values a page event promises), so it says so when there is nothing to compare.
|
|
5
|
+
|
|
6
|
+
"Stay on this composition" for the Default means no line leaves from it: the visitor keeps seeing the composition and the
|
|
7
|
+
workflow ends for them there.
|
|
8
|
+
-->
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
import {
|
|
11
|
+
MAX_CASES_PER_CONDITION,
|
|
12
|
+
DEFAULT_PORT,
|
|
13
|
+
buildGraphIndex,
|
|
14
|
+
findUpstreamTrigger
|
|
15
|
+
} from '@widgetic/workflows-engine';
|
|
16
|
+
import type { ConditionNode } from '@widgetic/workflows-engine';
|
|
17
|
+
import { listFieldChoices } from '../../editor/capabilityModel.js';
|
|
18
|
+
import { useEditorState } from '../../editor/editorState.svelte.js';
|
|
19
|
+
import { addRule, canAddRule, collectTakenIds, makeRule } from '../../editor/graphModel.js';
|
|
20
|
+
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
21
|
+
import ActionButton from '../ui/ActionButton.svelte';
|
|
22
|
+
import Icon from '../ui/Icon.svelte';
|
|
23
|
+
import BlockProblems from './BlockProblems.svelte';
|
|
24
|
+
import NextStepSelect from './NextStepSelect.svelte';
|
|
25
|
+
import RuleCard from './RuleCard.svelte';
|
|
26
|
+
|
|
27
|
+
interface Props {
|
|
28
|
+
node: ConditionNode;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let { node }: Props = $props();
|
|
32
|
+
|
|
33
|
+
const editor = useEditorState();
|
|
34
|
+
const { t } = useWorkflowsLanguage();
|
|
35
|
+
|
|
36
|
+
/** What the trigger before this condition carries, which is all its tests may read. */
|
|
37
|
+
const choices = $derived(listFieldChoices(editor.graph, node.id, editor.options));
|
|
38
|
+
const hasTrigger = $derived(
|
|
39
|
+
findUpstreamTrigger(buildGraphIndex(editor.graph), node.id) !== undefined
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
function addNewRule(): void {
|
|
43
|
+
if (!canAddRule(node)) return;
|
|
44
|
+
// A new rule starts with the first value there is to compare, so it is never an empty shell.
|
|
45
|
+
editor.replaceBlock(addRule(node, makeRule(collectTakenIds(editor.graph), choices[0]?.field)));
|
|
46
|
+
}
|
|
47
|
+
</script>
|
|
48
|
+
|
|
49
|
+
<div class="flex flex-col gap-4">
|
|
50
|
+
<div>
|
|
51
|
+
<h3 class="text-sm font-semibold">{$t('workflows.condition.heading')}</h3>
|
|
52
|
+
<p class="text-xs text-ink-muted">{$t('workflows.condition.help')}</p>
|
|
53
|
+
</div>
|
|
54
|
+
|
|
55
|
+
<BlockProblems nodeId={node.id} />
|
|
56
|
+
|
|
57
|
+
{#if !hasTrigger}
|
|
58
|
+
<p class="text-xs text-ink-muted">{$t('workflows.condition.noTrigger')}</p>
|
|
59
|
+
{:else if choices.length === 0}
|
|
60
|
+
<p class="text-xs text-ink-muted">{$t('workflows.condition.noValues')}</p>
|
|
61
|
+
{/if}
|
|
62
|
+
|
|
63
|
+
<div class="flex flex-col gap-3">
|
|
64
|
+
{#each node.cases as rule, index (rule.id)}
|
|
65
|
+
<RuleCard {node} {rule} {index} {choices} />
|
|
66
|
+
{/each}
|
|
67
|
+
</div>
|
|
68
|
+
|
|
69
|
+
{#if !editor.isReadOnly}
|
|
70
|
+
<ActionButton
|
|
71
|
+
size="small"
|
|
72
|
+
class="self-start"
|
|
73
|
+
disabled={!canAddRule(node)}
|
|
74
|
+
title={canAddRule(node)
|
|
75
|
+
? undefined
|
|
76
|
+
: $t('workflows.condition.ruleLimit', { max: MAX_CASES_PER_CONDITION })}
|
|
77
|
+
onclick={addNewRule}
|
|
78
|
+
>
|
|
79
|
+
<Icon name="plus" />
|
|
80
|
+
{$t('workflows.condition.addRule')}
|
|
81
|
+
</ActionButton>
|
|
82
|
+
{/if}
|
|
83
|
+
|
|
84
|
+
<div class="flex flex-col gap-1 border-t border-grey2 pt-3">
|
|
85
|
+
<NextStepSelect
|
|
86
|
+
sourceId={node.id}
|
|
87
|
+
sourcePort={DEFAULT_PORT}
|
|
88
|
+
label={$t('workflows.condition.defaultLabel')}
|
|
89
|
+
emptyLabel={$t('workflows.condition.defaultStay')}
|
|
90
|
+
help={$t('workflows.condition.defaultHelp')}
|
|
91
|
+
/>
|
|
92
|
+
</div>
|
|
93
|
+
|
|
94
|
+
{#if !editor.isReadOnly}
|
|
95
|
+
<ActionButton
|
|
96
|
+
variant="danger"
|
|
97
|
+
size="small"
|
|
98
|
+
class="self-start"
|
|
99
|
+
onclick={() => editor.removeBlock(node.id)}
|
|
100
|
+
>
|
|
101
|
+
<Icon name="trash" />
|
|
102
|
+
{$t('workflows.panel.removeBlock')}
|
|
103
|
+
</ActionButton>
|
|
104
|
+
{/if}
|
|
105
|
+
</div>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ConditionNode } from '@widgetic/workflows-engine';
|
|
2
|
+
interface Props {
|
|
3
|
+
node: ConditionNode;
|
|
4
|
+
}
|
|
5
|
+
declare const ConditionForm: import("svelte").Component<Props, {}, "">;
|
|
6
|
+
type ConditionForm = ReturnType<typeof ConditionForm>;
|
|
7
|
+
export default ConditionForm;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
One value that the page's event carries: its name and what kind of value it is (text, number, yes/no). A condition after the
|
|
3
|
+
trigger can compare only the values listed here, and the visitor's browser sends no other value of the event.
|
|
4
|
+
|
|
5
|
+
The name is kept when the person leaves the field (Enter, or moving on), so a name typed letter by letter is one change to
|
|
6
|
+
undo and one save. The kind is kept at once.
|
|
7
|
+
-->
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import { EVENT_NAME_PATTERN } from '@widgetic/workflows-engine';
|
|
10
|
+
import type { EventValueDeclaration, FieldType } from '@widgetic/workflows-engine';
|
|
11
|
+
import { FIELD_TYPE_MESSAGE_KEYS } from '../../editor/blockLabels.js';
|
|
12
|
+
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
13
|
+
import ActionButton from '../ui/ActionButton.svelte';
|
|
14
|
+
import Icon from '../ui/Icon.svelte';
|
|
15
|
+
import SelectField from '../ui/SelectField.svelte';
|
|
16
|
+
import TextField from '../ui/TextField.svelte';
|
|
17
|
+
import type { SelectChoice } from '../ui/types.js';
|
|
18
|
+
|
|
19
|
+
interface Props {
|
|
20
|
+
value: EventValueDeclaration;
|
|
21
|
+
/** Its place in the list, from 0: the person hears "Value 2", not an id. */
|
|
22
|
+
index: number;
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
onchange: (next: EventValueDeclaration) => void;
|
|
25
|
+
onremove: () => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let { value, index, disabled = false, onchange, onremove }: Props = $props();
|
|
29
|
+
|
|
30
|
+
const { t } = useWorkflowsLanguage();
|
|
31
|
+
|
|
32
|
+
/** What is in the box while it is being typed; it follows the value again whenever the value changes. */
|
|
33
|
+
let nameDraft = $derived(value.name);
|
|
34
|
+
|
|
35
|
+
const typeChoices = $derived<SelectChoice[]>(
|
|
36
|
+
(Object.keys(FIELD_TYPE_MESSAGE_KEYS) as FieldType[]).map((type) => ({
|
|
37
|
+
value: type,
|
|
38
|
+
label: $t(FIELD_TYPE_MESSAGE_KEYS[type])
|
|
39
|
+
}))
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const nameProblem = $derived(
|
|
43
|
+
nameDraft.trim() !== '' && !EVENT_NAME_PATTERN.test(nameDraft)
|
|
44
|
+
? $t('workflows.event.valueNameInvalid')
|
|
45
|
+
: undefined
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
function commitName(): void {
|
|
49
|
+
const name = nameDraft.trim();
|
|
50
|
+
if (name !== value.name) onchange({ ...value, name });
|
|
51
|
+
}
|
|
52
|
+
</script>
|
|
53
|
+
|
|
54
|
+
<div class="flex items-start gap-2">
|
|
55
|
+
<TextField
|
|
56
|
+
class="flex-1"
|
|
57
|
+
label={$t('workflows.event.valueName', { number: index + 1 })}
|
|
58
|
+
hideLabel
|
|
59
|
+
placeholder={$t('workflows.event.valueNamePlaceholder')}
|
|
60
|
+
maxlength={64}
|
|
61
|
+
{disabled}
|
|
62
|
+
problem={nameProblem}
|
|
63
|
+
bind:value={nameDraft}
|
|
64
|
+
onchange={commitName}
|
|
65
|
+
/>
|
|
66
|
+
<SelectField
|
|
67
|
+
class="w-28"
|
|
68
|
+
label={$t('workflows.event.valueType', { number: index + 1 })}
|
|
69
|
+
hideLabel
|
|
70
|
+
{disabled}
|
|
71
|
+
value={value.type}
|
|
72
|
+
choices={typeChoices}
|
|
73
|
+
onchange={(type) => onchange({ ...value, type: type as FieldType })}
|
|
74
|
+
/>
|
|
75
|
+
<ActionButton
|
|
76
|
+
variant="ghost"
|
|
77
|
+
iconOnly
|
|
78
|
+
{disabled}
|
|
79
|
+
ariaLabel={$t('workflows.event.removeValue', { number: index + 1 })}
|
|
80
|
+
title={$t('workflows.event.removeValue', { number: index + 1 })}
|
|
81
|
+
onclick={onremove}
|
|
82
|
+
>
|
|
83
|
+
<Icon name="trash" />
|
|
84
|
+
</ActionButton>
|
|
85
|
+
</div>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EventValueDeclaration } from '@widgetic/workflows-engine';
|
|
2
|
+
interface Props {
|
|
3
|
+
value: EventValueDeclaration;
|
|
4
|
+
/** Its place in the list, from 0: the person hears "Value 2", not an id. */
|
|
5
|
+
index: number;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
onchange: (next: EventValueDeclaration) => void;
|
|
8
|
+
onremove: () => void;
|
|
9
|
+
}
|
|
10
|
+
declare const EventValueRow: import("svelte").Component<Props, {}, "">;
|
|
11
|
+
type EventValueRow = ReturnType<typeof EventValueRow>;
|
|
12
|
+
export default EventValueRow;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
"Then go to": where one exit of a block leads (the single exit of a trigger, a rule of a condition, a condition's Default),
|
|
3
|
+
chosen from a list instead of by dragging a line, which is the way to do it with the keyboard and on a touch screen. It
|
|
4
|
+
draws and removes the same line the canvas does, through the editor.
|
|
5
|
+
|
|
6
|
+
Only blocks the engine would accept that line to are offered (no loop, nothing that already has a way in from elsewhere),
|
|
7
|
+
plus the block the exit leads to now, so the list never shows a choice that would be refused. A block's name is its
|
|
8
|
+
composition's name, or the kind of block; two blocks with the same name are told apart by a number.
|
|
9
|
+
-->
|
|
10
|
+
<script lang="ts">
|
|
11
|
+
import { checkConnection } from '@widgetic/workflows-engine';
|
|
12
|
+
import { describeBlocksUniquely } from '../../editor/blockLabels.js';
|
|
13
|
+
import { useEditorState } from '../../editor/editorState.svelte.js';
|
|
14
|
+
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
15
|
+
import SelectField from '../ui/SelectField.svelte';
|
|
16
|
+
import type { SelectChoice } from '../ui/types.js';
|
|
17
|
+
|
|
18
|
+
interface Props {
|
|
19
|
+
/** The block the exit belongs to, and which of its exits. */
|
|
20
|
+
sourceId: string;
|
|
21
|
+
sourcePort: string;
|
|
22
|
+
label: string;
|
|
23
|
+
/** What "no line" is called: "Choose the next step" for a rule, "Stay on this composition" for a Default. */
|
|
24
|
+
emptyLabel: string;
|
|
25
|
+
help?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let { sourceId, sourcePort, label, emptyLabel, help }: Props = $props();
|
|
29
|
+
|
|
30
|
+
const editor = useEditorState();
|
|
31
|
+
const { t } = useWorkflowsLanguage();
|
|
32
|
+
|
|
33
|
+
/** The block the exit leads to now; empty when it leads nowhere. */
|
|
34
|
+
const currentTargetId = $derived(
|
|
35
|
+
editor.graph.edges.find((edge) => edge.source === sourceId && edge.sourcePort === sourcePort)
|
|
36
|
+
?.target ?? ''
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const choices = $derived.by<SelectChoice[]>(() => {
|
|
40
|
+
const labels = describeBlocksUniquely(editor.graph, editor.options, $t);
|
|
41
|
+
// The engine judges the line as if the exit had none yet (it allows one next step per exit).
|
|
42
|
+
const withoutThisExit = {
|
|
43
|
+
...editor.graph,
|
|
44
|
+
edges: editor.graph.edges.filter(
|
|
45
|
+
(edge) => !(edge.source === sourceId && edge.sourcePort === sourcePort)
|
|
46
|
+
)
|
|
47
|
+
};
|
|
48
|
+
const list: SelectChoice[] = [{ value: '', label: emptyLabel }];
|
|
49
|
+
for (const node of editor.graph.nodes) {
|
|
50
|
+
if (node.id === sourceId) continue;
|
|
51
|
+
const isCurrent = node.id === currentTargetId;
|
|
52
|
+
if (
|
|
53
|
+
isCurrent ||
|
|
54
|
+
checkConnection(withoutThisExit, { source: sourceId, sourcePort, target: node.id }).ok
|
|
55
|
+
) {
|
|
56
|
+
list.push({ value: node.id, label: labels.get(node.id) ?? node.id });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return list;
|
|
60
|
+
});
|
|
61
|
+
</script>
|
|
62
|
+
|
|
63
|
+
<SelectField
|
|
64
|
+
{label}
|
|
65
|
+
{help}
|
|
66
|
+
value={currentTargetId}
|
|
67
|
+
{choices}
|
|
68
|
+
disabled={editor.isReadOnly}
|
|
69
|
+
onchange={(targetId) => editor.connect(sourceId, sourcePort, targetId === '' ? null : targetId)}
|
|
70
|
+
/>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
/** The block the exit belongs to, and which of its exits. */
|
|
3
|
+
sourceId: string;
|
|
4
|
+
sourcePort: string;
|
|
5
|
+
label: string;
|
|
6
|
+
/** What "no line" is called: "Choose the next step" for a rule, "Stay on this composition" for a Default. */
|
|
7
|
+
emptyLabel: string;
|
|
8
|
+
help?: string;
|
|
9
|
+
}
|
|
10
|
+
declare const NextStepSelect: import("svelte").Component<Props, {}, "">;
|
|
11
|
+
type NextStepSelect = ReturnType<typeof NextStepSelect>;
|
|
12
|
+
export default NextStepSelect;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Everything the check finds wrong with the draft, in sentences. It is what stops a publish, so it is the first thing the
|
|
3
|
+
panel shows when no block is selected. A problem that belongs to a block is a button that selects the block, so the person
|
|
4
|
+
lands on the form that fixes it. Warnings are advice and do not stop a publish.
|
|
5
|
+
|
|
6
|
+
It also lists what a refused publish said (the server checks again with what it knows), in the same place, so there is one
|
|
7
|
+
list to work through.
|
|
8
|
+
-->
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
import type { ValidationIssue } from '@widgetic/workflows-engine';
|
|
11
|
+
import { describeBlocksUniquely } from '../../editor/blockLabels.js';
|
|
12
|
+
import { useEditorState } from '../../editor/editorState.svelte.js';
|
|
13
|
+
import { describeIssue } from '../../editor/issueText.js';
|
|
14
|
+
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
15
|
+
import Icon from '../ui/Icon.svelte';
|
|
16
|
+
|
|
17
|
+
const editor = useEditorState();
|
|
18
|
+
const { t } = useWorkflowsLanguage();
|
|
19
|
+
|
|
20
|
+
/** What makes two findings the same finding, so one the server repeats is listed once. */
|
|
21
|
+
function identify(issue: ValidationIssue): string {
|
|
22
|
+
return [
|
|
23
|
+
issue.code,
|
|
24
|
+
issue.nodeId ?? '',
|
|
25
|
+
issue.edgeId ?? '',
|
|
26
|
+
issue.caseId ?? '',
|
|
27
|
+
issue.detail ?? ''
|
|
28
|
+
].join('|');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const sentences = $derived.by(() => {
|
|
32
|
+
const labels = describeBlocksUniquely(editor.graph, editor.options, $t);
|
|
33
|
+
const context = { t: $t, describeBlock: (blockId: string) => labels.get(blockId) ?? '' };
|
|
34
|
+
// A plain Set: it lives for one pass over the findings and is never state, so there is nothing for it to notify
|
|
35
|
+
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
|
36
|
+
const seen = new Set<string>();
|
|
37
|
+
const list: Array<{
|
|
38
|
+
key: string;
|
|
39
|
+
severity: ValidationIssue['severity'];
|
|
40
|
+
nodeId: string | undefined;
|
|
41
|
+
text: string;
|
|
42
|
+
}> = [];
|
|
43
|
+
for (const issue of [...editor.issues, ...editor.refusedIssues]) {
|
|
44
|
+
const key = identify(issue);
|
|
45
|
+
if (seen.has(key)) continue;
|
|
46
|
+
seen.add(key);
|
|
47
|
+
list.push({
|
|
48
|
+
key,
|
|
49
|
+
severity: issue.severity,
|
|
50
|
+
nodeId: issue.nodeId,
|
|
51
|
+
text: describeIssue(issue, context)
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
// Errors first: they are what stops a publish.
|
|
55
|
+
return list.sort(
|
|
56
|
+
(left, right) => Number(right.severity === 'error') - Number(left.severity === 'error')
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
function goToBlock(nodeId: string): void {
|
|
61
|
+
editor.canvas?.selectNodes([nodeId]);
|
|
62
|
+
editor.panel = 'selection';
|
|
63
|
+
}
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
{#if sentences.length > 0}
|
|
67
|
+
<ul class="flex flex-col gap-1" aria-label={$t('workflows.panel.problemsLabel')}>
|
|
68
|
+
{#each sentences as sentence (sentence.key)}
|
|
69
|
+
<li>
|
|
70
|
+
{#if sentence.nodeId}
|
|
71
|
+
{@const nodeId = sentence.nodeId}
|
|
72
|
+
<button
|
|
73
|
+
type="button"
|
|
74
|
+
class="flex w-full items-start gap-2 rounded-medium px-2 py-1.5 text-start text-xs hover:text-ink-primary focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary-green {sentence.severity ===
|
|
75
|
+
'error'
|
|
76
|
+
? 'text-error'
|
|
77
|
+
: 'text-ink-muted'}"
|
|
78
|
+
onclick={() => goToBlock(nodeId)}
|
|
79
|
+
>
|
|
80
|
+
<Icon name="warning" class="mt-0.5 size-3.5" />
|
|
81
|
+
<span>{sentence.text}</span>
|
|
82
|
+
</button>
|
|
83
|
+
{:else}
|
|
84
|
+
<p
|
|
85
|
+
class="flex items-start gap-2 px-2 py-1.5 text-xs {sentence.severity === 'error'
|
|
86
|
+
? 'text-error'
|
|
87
|
+
: 'text-ink-muted'}"
|
|
88
|
+
>
|
|
89
|
+
<Icon name="warning" class="mt-0.5 size-3.5" />
|
|
90
|
+
<span>{sentence.text}</span>
|
|
91
|
+
</p>
|
|
92
|
+
{/if}
|
|
93
|
+
</li>
|
|
94
|
+
{/each}
|
|
95
|
+
</ul>
|
|
96
|
+
{:else}
|
|
97
|
+
<p class="flex items-center gap-2 text-xs text-ink-muted">
|
|
98
|
+
<Icon name="check" class="size-3.5 text-primary-green" />
|
|
99
|
+
{$t('workflows.panel.noProblems')}
|
|
100
|
+
</p>
|
|
101
|
+
{/if}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
One rule of a condition: a name, whether all or any of its tests must hold, the tests, and where a visitor goes when the
|
|
3
|
+
rule matches. Rules are tried in the order they are listed and the first that matches wins, so each card can be moved up
|
|
4
|
+
or down.
|
|
5
|
+
|
|
6
|
+
A name is optional (without one the rule is "Rule 1", "Rule 2"…); it is kept when the person leaves the field.
|
|
7
|
+
-->
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import { MAX_TESTS_PER_CASE } from '@widgetic/workflows-engine';
|
|
10
|
+
import type { ConditionCase, ConditionNode, ConditionTest } from '@widgetic/workflows-engine';
|
|
11
|
+
import { nameRule } from '../../editor/blockLabels.js';
|
|
12
|
+
import type { FieldChoice } from '../../editor/capabilityModel.js';
|
|
13
|
+
import { useEditorState } from '../../editor/editorState.svelte.js';
|
|
14
|
+
import {
|
|
15
|
+
canAddTest,
|
|
16
|
+
changeRule,
|
|
17
|
+
makeTest,
|
|
18
|
+
moveRule,
|
|
19
|
+
removeRule
|
|
20
|
+
} from '../../editor/graphModel.js';
|
|
21
|
+
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
22
|
+
import ActionButton from '../ui/ActionButton.svelte';
|
|
23
|
+
import Icon from '../ui/Icon.svelte';
|
|
24
|
+
import SelectField from '../ui/SelectField.svelte';
|
|
25
|
+
import TextField from '../ui/TextField.svelte';
|
|
26
|
+
import type { SelectChoice } from '../ui/types.js';
|
|
27
|
+
import NextStepSelect from './NextStepSelect.svelte';
|
|
28
|
+
import TestRow from './TestRow.svelte';
|
|
29
|
+
|
|
30
|
+
interface Props {
|
|
31
|
+
node: ConditionNode;
|
|
32
|
+
rule: ConditionCase;
|
|
33
|
+
/** Its place among the rules, from 0. */
|
|
34
|
+
index: number;
|
|
35
|
+
/** The values the trigger before the condition carries. */
|
|
36
|
+
choices: readonly FieldChoice[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let { node, rule, index, choices }: Props = $props();
|
|
40
|
+
|
|
41
|
+
const editor = useEditorState();
|
|
42
|
+
const { t } = useWorkflowsLanguage();
|
|
43
|
+
const headingId = $props.id();
|
|
44
|
+
|
|
45
|
+
const ruleName = $derived(nameRule(rule, index, $t));
|
|
46
|
+
const isFirst = $derived(index === 0);
|
|
47
|
+
const isLast = $derived(index === node.cases.length - 1);
|
|
48
|
+
|
|
49
|
+
/** What is in the name box while it is being typed; it follows the rule again whenever the rule changes. */
|
|
50
|
+
let nameDraft = $derived(rule.label ?? '');
|
|
51
|
+
|
|
52
|
+
const matchChoices = $derived<SelectChoice[]>([
|
|
53
|
+
{ value: 'all', label: $t('workflows.rule.matchAll') },
|
|
54
|
+
{ value: 'any', label: $t('workflows.rule.matchAny') }
|
|
55
|
+
]);
|
|
56
|
+
|
|
57
|
+
function replaceRule(change: (current: ConditionCase) => ConditionCase): void {
|
|
58
|
+
editor.replaceBlock(changeRule(node, rule.id, change));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function commitName(): void {
|
|
62
|
+
const label = nameDraft.trim();
|
|
63
|
+
if (label === (rule.label ?? '')) return;
|
|
64
|
+
replaceRule((current) => {
|
|
65
|
+
const { label: _previous, ...rest } = current;
|
|
66
|
+
return label === '' ? rest : { ...rest, label };
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function addTest(): void {
|
|
71
|
+
const firstChoice = choices[0];
|
|
72
|
+
if (!firstChoice || !canAddTest(rule)) return;
|
|
73
|
+
replaceRule((current) => ({
|
|
74
|
+
...current,
|
|
75
|
+
tests: [...current.tests, makeTest(firstChoice.field)]
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function changeTest(position: number, next: ConditionTest): void {
|
|
80
|
+
replaceRule((current) => ({
|
|
81
|
+
...current,
|
|
82
|
+
tests: current.tests.map((test, at) => (at === position ? next : test))
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function removeTest(position: number): void {
|
|
87
|
+
replaceRule((current) => ({
|
|
88
|
+
...current,
|
|
89
|
+
tests: current.tests.filter((_, at) => at !== position)
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
</script>
|
|
93
|
+
|
|
94
|
+
<section
|
|
95
|
+
class="flex flex-col gap-3 rounded-large border border-grey2 p-3"
|
|
96
|
+
aria-labelledby={headingId}
|
|
97
|
+
>
|
|
98
|
+
<div class="flex items-start gap-2">
|
|
99
|
+
<TextField
|
|
100
|
+
class="flex-1"
|
|
101
|
+
label={$t('workflows.rule.nameLabel', { name: ruleName })}
|
|
102
|
+
hideLabel
|
|
103
|
+
placeholder={ruleName}
|
|
104
|
+
maxlength={80}
|
|
105
|
+
disabled={editor.isReadOnly}
|
|
106
|
+
bind:value={nameDraft}
|
|
107
|
+
onchange={commitName}
|
|
108
|
+
/>
|
|
109
|
+
<h4 id={headingId} class="sr-only">{ruleName}</h4>
|
|
110
|
+
{#if !editor.isReadOnly}
|
|
111
|
+
<ActionButton
|
|
112
|
+
variant="ghost"
|
|
113
|
+
iconOnly
|
|
114
|
+
disabled={isFirst}
|
|
115
|
+
ariaLabel={$t('workflows.rule.moveUp', { name: ruleName })}
|
|
116
|
+
title={$t('workflows.rule.moveUp', { name: ruleName })}
|
|
117
|
+
onclick={() => editor.replaceBlock(moveRule(node, rule.id, index - 1))}
|
|
118
|
+
>
|
|
119
|
+
<Icon name="up" />
|
|
120
|
+
</ActionButton>
|
|
121
|
+
<ActionButton
|
|
122
|
+
variant="ghost"
|
|
123
|
+
iconOnly
|
|
124
|
+
disabled={isLast}
|
|
125
|
+
ariaLabel={$t('workflows.rule.moveDown', { name: ruleName })}
|
|
126
|
+
title={$t('workflows.rule.moveDown', { name: ruleName })}
|
|
127
|
+
onclick={() => editor.replaceBlock(moveRule(node, rule.id, index + 1))}
|
|
128
|
+
>
|
|
129
|
+
<Icon name="down" />
|
|
130
|
+
</ActionButton>
|
|
131
|
+
<ActionButton
|
|
132
|
+
variant="ghost"
|
|
133
|
+
iconOnly
|
|
134
|
+
ariaLabel={$t('workflows.rule.remove', { name: ruleName })}
|
|
135
|
+
title={$t('workflows.rule.remove', { name: ruleName })}
|
|
136
|
+
onclick={() => editor.replaceBlock(removeRule(node, rule.id))}
|
|
137
|
+
>
|
|
138
|
+
<Icon name="trash" />
|
|
139
|
+
</ActionButton>
|
|
140
|
+
{/if}
|
|
141
|
+
</div>
|
|
142
|
+
|
|
143
|
+
{#if rule.tests.length === 0}
|
|
144
|
+
<p class="text-xs text-ink-muted">{$t('workflows.rule.noTests')}</p>
|
|
145
|
+
{:else}
|
|
146
|
+
{#if rule.tests.length > 1}
|
|
147
|
+
<SelectField
|
|
148
|
+
label={$t('workflows.rule.matchLabel')}
|
|
149
|
+
value={rule.match}
|
|
150
|
+
choices={matchChoices}
|
|
151
|
+
disabled={editor.isReadOnly}
|
|
152
|
+
onchange={(match) =>
|
|
153
|
+
replaceRule((current) => ({ ...current, match: match === 'any' ? 'any' : 'all' }))}
|
|
154
|
+
/>
|
|
155
|
+
{/if}
|
|
156
|
+
<div class="flex flex-col gap-2">
|
|
157
|
+
{#each rule.tests as test, position (position)}
|
|
158
|
+
<TestRow
|
|
159
|
+
{test}
|
|
160
|
+
index={position}
|
|
161
|
+
{choices}
|
|
162
|
+
disabled={editor.isReadOnly}
|
|
163
|
+
onchange={(next) => changeTest(position, next)}
|
|
164
|
+
onremove={() => removeTest(position)}
|
|
165
|
+
/>
|
|
166
|
+
{/each}
|
|
167
|
+
</div>
|
|
168
|
+
{/if}
|
|
169
|
+
|
|
170
|
+
{#if !editor.isReadOnly}
|
|
171
|
+
<ActionButton
|
|
172
|
+
size="small"
|
|
173
|
+
class="self-start"
|
|
174
|
+
disabled={choices.length === 0 || !canAddTest(rule)}
|
|
175
|
+
title={canAddTest(rule)
|
|
176
|
+
? undefined
|
|
177
|
+
: $t('workflows.rule.testLimit', { max: MAX_TESTS_PER_CASE })}
|
|
178
|
+
onclick={addTest}
|
|
179
|
+
>
|
|
180
|
+
<Icon name="plus" />
|
|
181
|
+
{$t('workflows.rule.addTest')}
|
|
182
|
+
</ActionButton>
|
|
183
|
+
{/if}
|
|
184
|
+
|
|
185
|
+
<NextStepSelect
|
|
186
|
+
sourceId={node.id}
|
|
187
|
+
sourcePort={rule.id}
|
|
188
|
+
label={$t('workflows.rule.thenGoTo', { name: ruleName })}
|
|
189
|
+
emptyLabel={$t('workflows.trigger.nextNone')}
|
|
190
|
+
/>
|
|
191
|
+
</section>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ConditionCase, ConditionNode } from '@widgetic/workflows-engine';
|
|
2
|
+
import type { FieldChoice } from '../../editor/capabilityModel.js';
|
|
3
|
+
interface Props {
|
|
4
|
+
node: ConditionNode;
|
|
5
|
+
rule: ConditionCase;
|
|
6
|
+
/** Its place among the rules, from 0. */
|
|
7
|
+
index: number;
|
|
8
|
+
/** The values the trigger before the condition carries. */
|
|
9
|
+
choices: readonly FieldChoice[];
|
|
10
|
+
}
|
|
11
|
+
declare const RuleCard: import("svelte").Component<Props, {}, "">;
|
|
12
|
+
type RuleCard = ReturnType<typeof RuleCard>;
|
|
13
|
+
export default RuleCard;
|