@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,127 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The side panel for a composition block: which composition it shows, whether it is where visitors start, and what the
|
|
3
|
+
composition can do for a workflow (the values it keeps and the actions its widget reports), which decides what triggers
|
|
4
|
+
can follow it. Choosing another composition keeps the block and the lines around it.
|
|
5
|
+
-->
|
|
6
|
+
<script lang="ts">
|
|
7
|
+
import type { CompositionNode } from '@widgetic/workflows-engine';
|
|
8
|
+
import type { CompositionOption } from '../../api/types.js';
|
|
9
|
+
import { CAPABILITY_REASON_MESSAGE_KEYS } from '../../editor/blockLabels.js';
|
|
10
|
+
import {
|
|
11
|
+
listActionChoices,
|
|
12
|
+
listInputTables,
|
|
13
|
+
readTriggerAvailability
|
|
14
|
+
} from '../../editor/capabilityModel.js';
|
|
15
|
+
import { useEditorState } from '../../editor/editorState.svelte.js';
|
|
16
|
+
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
17
|
+
import ActionButton from '../ui/ActionButton.svelte';
|
|
18
|
+
import Icon from '../ui/Icon.svelte';
|
|
19
|
+
import BlockProblems from './BlockProblems.svelte';
|
|
20
|
+
import CompositionPicker from './CompositionPicker.svelte';
|
|
21
|
+
|
|
22
|
+
interface Props {
|
|
23
|
+
node: CompositionNode;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let { node }: Props = $props();
|
|
27
|
+
|
|
28
|
+
const editor = useEditorState();
|
|
29
|
+
const { t } = useWorkflowsLanguage();
|
|
30
|
+
const capabilitiesHeadingId = $props.id();
|
|
31
|
+
|
|
32
|
+
/** What the API says about the composition of this block; `undefined` before it answers, `null` when it is not there. */
|
|
33
|
+
const option = $derived(node.compositionId ? editor.options[node.compositionId] : undefined);
|
|
34
|
+
const otherCompositionIds = $derived(
|
|
35
|
+
editor.compositionIds.filter((compositionId) => compositionId !== node.compositionId)
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const inputAvailability = $derived(readTriggerAvailability(option, 'input'));
|
|
39
|
+
const actionAvailability = $derived(readTriggerAvailability(option, 'action'));
|
|
40
|
+
|
|
41
|
+
function chooseComposition(chosen: CompositionOption): void {
|
|
42
|
+
editor.rememberCompositions([chosen]);
|
|
43
|
+
editor.replaceBlock({ ...node, compositionId: chosen.id });
|
|
44
|
+
}
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<div class="flex flex-col gap-4">
|
|
48
|
+
<div>
|
|
49
|
+
<h3 class="text-sm font-semibold">{$t('workflows.composition.heading')}</h3>
|
|
50
|
+
<p class="text-xs text-ink-muted">{$t('workflows.composition.help')}</p>
|
|
51
|
+
</div>
|
|
52
|
+
|
|
53
|
+
<BlockProblems nodeId={node.id} />
|
|
54
|
+
|
|
55
|
+
{#if !editor.isReadOnly}
|
|
56
|
+
<CompositionPicker
|
|
57
|
+
selectedId={node.compositionId || null}
|
|
58
|
+
takenIds={otherCompositionIds}
|
|
59
|
+
onpick={chooseComposition}
|
|
60
|
+
onread={(options) => editor.rememberCompositions(options)}
|
|
61
|
+
/>
|
|
62
|
+
{/if}
|
|
63
|
+
|
|
64
|
+
{#if node.startsHere}
|
|
65
|
+
<p class="flex items-center gap-2 text-xs text-primary-green">
|
|
66
|
+
<Icon name="check" class="size-3.5" />
|
|
67
|
+
{$t('workflows.composition.isStart')}
|
|
68
|
+
</p>
|
|
69
|
+
{:else if !editor.isReadOnly}
|
|
70
|
+
<ActionButton size="small" onclick={() => editor.makeStart(node.id)}
|
|
71
|
+
>{$t('workflows.composition.makeStart')}</ActionButton
|
|
72
|
+
>
|
|
73
|
+
{/if}
|
|
74
|
+
|
|
75
|
+
{#if option}
|
|
76
|
+
<section
|
|
77
|
+
class="flex flex-col gap-2 border-t border-grey2 pt-3"
|
|
78
|
+
aria-labelledby={capabilitiesHeadingId}
|
|
79
|
+
>
|
|
80
|
+
<h4 id={capabilitiesHeadingId} class="text-xs font-semibold">
|
|
81
|
+
{$t('workflows.composition.capabilitiesHeading')}
|
|
82
|
+
</h4>
|
|
83
|
+
<dl class="flex flex-col gap-2 text-xs">
|
|
84
|
+
<div class="flex flex-col gap-0.5">
|
|
85
|
+
<dt class="text-ink-muted">{$t('workflows.composition.capabilityInput')}</dt>
|
|
86
|
+
<dd>
|
|
87
|
+
{#if inputAvailability.enabled}
|
|
88
|
+
{$t('workflows.composition.inputTables', {
|
|
89
|
+
tables: listInputTables(option).join(', ')
|
|
90
|
+
})}
|
|
91
|
+
{:else}
|
|
92
|
+
{$t(CAPABILITY_REASON_MESSAGE_KEYS[inputAvailability.reason])}
|
|
93
|
+
{/if}
|
|
94
|
+
</dd>
|
|
95
|
+
</div>
|
|
96
|
+
<div class="flex flex-col gap-0.5">
|
|
97
|
+
<dt class="text-ink-muted">{$t('workflows.composition.capabilityAction')}</dt>
|
|
98
|
+
<dd>
|
|
99
|
+
{#if actionAvailability.enabled}
|
|
100
|
+
{$t('workflows.composition.actionCount', { count: listActionChoices(option).length })}
|
|
101
|
+
{:else}
|
|
102
|
+
{$t(CAPABILITY_REASON_MESSAGE_KEYS[actionAvailability.reason])}
|
|
103
|
+
{/if}
|
|
104
|
+
</dd>
|
|
105
|
+
</div>
|
|
106
|
+
{#if option.allowedWebsites.length > 0}
|
|
107
|
+
<div class="flex flex-col gap-0.5">
|
|
108
|
+
<dt class="text-ink-muted">{$t('workflows.composition.capabilityWebsites')}</dt>
|
|
109
|
+
<dd class="break-words">{option.allowedWebsites.join(', ')}</dd>
|
|
110
|
+
</div>
|
|
111
|
+
{/if}
|
|
112
|
+
</dl>
|
|
113
|
+
</section>
|
|
114
|
+
{/if}
|
|
115
|
+
|
|
116
|
+
{#if !editor.isReadOnly}
|
|
117
|
+
<ActionButton
|
|
118
|
+
variant="danger"
|
|
119
|
+
size="small"
|
|
120
|
+
class="self-start"
|
|
121
|
+
onclick={() => editor.removeBlock(node.id)}
|
|
122
|
+
>
|
|
123
|
+
<Icon name="trash" />
|
|
124
|
+
{$t('workflows.panel.removeBlock')}
|
|
125
|
+
</ActionButton>
|
|
126
|
+
{/if}
|
|
127
|
+
</div>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CompositionNode } from '@widgetic/workflows-engine';
|
|
2
|
+
interface Props {
|
|
3
|
+
node: CompositionNode;
|
|
4
|
+
}
|
|
5
|
+
declare const CompositionForm: import("svelte").Component<Props, {}, "">;
|
|
6
|
+
type CompositionForm = ReturnType<typeof CompositionForm>;
|
|
7
|
+
export default CompositionForm;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
A list of the compositions a person may use in a workflow, with a search above it. Used where a composition is chosen: when a
|
|
3
|
+
workflow is made, and on a composition block. Each line has the composition's picture and name; one that is already in the
|
|
4
|
+
workflow is shown but cannot be chosen again (a composition has one block), and one whose widget was never published says so.
|
|
5
|
+
|
|
6
|
+
It asks the API for twenty at a time (`composition-options`), and for the next twenty when asked. Every search replaces the
|
|
7
|
+
one before it: an answer to an older search that arrives late is dropped.
|
|
8
|
+
-->
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
import { onDestroy, onMount } from 'svelte';
|
|
11
|
+
import { useWorkflowsApi } from '../../api/apiContext.js';
|
|
12
|
+
import { isCancelled } from '../../api/workflowsApi.js';
|
|
13
|
+
import type { CompositionOption } from '../../api/types.js';
|
|
14
|
+
import { pickApiErrorMessage } from '../../editor/apiErrorText.js';
|
|
15
|
+
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
16
|
+
import type { WorkflowsMessageKey } from '../../i18n/messages.js';
|
|
17
|
+
import { workflowsError } from '../../utils/logger.js';
|
|
18
|
+
import ActionButton from '../ui/ActionButton.svelte';
|
|
19
|
+
import Icon from '../ui/Icon.svelte';
|
|
20
|
+
import TextField from '../ui/TextField.svelte';
|
|
21
|
+
|
|
22
|
+
interface Props {
|
|
23
|
+
/** The composition that is chosen now, if any. */
|
|
24
|
+
selectedId?: string | null;
|
|
25
|
+
/** Compositions already in the workflow: shown, but cannot be chosen. */
|
|
26
|
+
takenIds?: readonly string[];
|
|
27
|
+
/** Called with every composition the person picks, so the owner can remember its name and picture. */
|
|
28
|
+
onpick: (option: CompositionOption) => void;
|
|
29
|
+
/** Called with each page of compositions that was read, so the owner can remember them. */
|
|
30
|
+
onread?: (options: readonly CompositionOption[]) => void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let { selectedId = null, takenIds = [], onpick, onread }: Props = $props();
|
|
34
|
+
|
|
35
|
+
const PAGE_SIZE = 20;
|
|
36
|
+
const SEARCH_DELAY_MILLISECONDS = 300;
|
|
37
|
+
|
|
38
|
+
const api = useWorkflowsApi();
|
|
39
|
+
const { t } = useWorkflowsLanguage();
|
|
40
|
+
|
|
41
|
+
let search = $state('');
|
|
42
|
+
let items = $state.raw<readonly CompositionOption[]>([]);
|
|
43
|
+
let total = $state(0);
|
|
44
|
+
let loadState = $state<'loading' | 'ready' | 'failed'>('loading');
|
|
45
|
+
let failureKey = $state.raw<WorkflowsMessageKey | null>(null);
|
|
46
|
+
let isLoadingMore = $state(false);
|
|
47
|
+
|
|
48
|
+
let controller: AbortController | null = null;
|
|
49
|
+
let searchTimer: ReturnType<typeof setTimeout> | null = null;
|
|
50
|
+
|
|
51
|
+
const taken = $derived(new Set(takenIds));
|
|
52
|
+
const hasMore = $derived(items.length < total);
|
|
53
|
+
|
|
54
|
+
/** Reads the first page for what is in the search box now (or the next page, when `append`). */
|
|
55
|
+
async function read(append: boolean): Promise<void> {
|
|
56
|
+
controller?.abort();
|
|
57
|
+
const current = new AbortController();
|
|
58
|
+
controller = current;
|
|
59
|
+
if (append) isLoadingMore = true;
|
|
60
|
+
else loadState = items.length === 0 ? 'loading' : loadState;
|
|
61
|
+
failureKey = null;
|
|
62
|
+
try {
|
|
63
|
+
const trimmed = search.trim();
|
|
64
|
+
const page = await api.listCompositionOptions(
|
|
65
|
+
{
|
|
66
|
+
...(trimmed === '' ? {} : { search: trimmed }),
|
|
67
|
+
limit: PAGE_SIZE,
|
|
68
|
+
offset: append ? items.length : 0
|
|
69
|
+
},
|
|
70
|
+
{ signal: current.signal }
|
|
71
|
+
);
|
|
72
|
+
if (current.signal.aborted) return;
|
|
73
|
+
const known = new Set(append ? items.map((item) => item.id) : []);
|
|
74
|
+
items = append ? [...items, ...page.items.filter((item) => !known.has(item.id))] : page.items;
|
|
75
|
+
total = page.total;
|
|
76
|
+
loadState = 'ready';
|
|
77
|
+
onread?.(page.items);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (isCancelled(error)) return;
|
|
80
|
+
workflowsError('Reading the compositions failed.', error);
|
|
81
|
+
failureKey = pickApiErrorMessage(error) ?? 'workflows.error.generic';
|
|
82
|
+
loadState = 'failed';
|
|
83
|
+
} finally {
|
|
84
|
+
if (controller === current) isLoadingMore = false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function handleSearchChange(): void {
|
|
89
|
+
if (searchTimer !== null) clearTimeout(searchTimer);
|
|
90
|
+
searchTimer = setTimeout(() => {
|
|
91
|
+
searchTimer = null;
|
|
92
|
+
void read(false);
|
|
93
|
+
}, SEARCH_DELAY_MILLISECONDS);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
onMount(() => {
|
|
97
|
+
void read(false);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
onDestroy(() => {
|
|
101
|
+
controller?.abort();
|
|
102
|
+
if (searchTimer !== null) clearTimeout(searchTimer);
|
|
103
|
+
});
|
|
104
|
+
</script>
|
|
105
|
+
|
|
106
|
+
<div class="flex min-h-0 flex-col gap-2">
|
|
107
|
+
<TextField
|
|
108
|
+
type="search"
|
|
109
|
+
label={$t('workflows.composition.searchLabel')}
|
|
110
|
+
placeholder={$t('workflows.composition.searchPlaceholder')}
|
|
111
|
+
hideLabel
|
|
112
|
+
bind:value={search}
|
|
113
|
+
oninput={handleSearchChange}
|
|
114
|
+
/>
|
|
115
|
+
|
|
116
|
+
{#if loadState === 'loading'}
|
|
117
|
+
<p class="py-4 text-center text-sm text-ink-muted" role="status">
|
|
118
|
+
{$t('workflows.common.loading')}
|
|
119
|
+
</p>
|
|
120
|
+
{:else if loadState === 'failed'}
|
|
121
|
+
<div class="flex flex-col items-start gap-2 py-2">
|
|
122
|
+
<p class="text-sm text-error" role="alert">{failureKey ? $t(failureKey) : ''}</p>
|
|
123
|
+
<ActionButton size="small" onclick={() => void read(false)}
|
|
124
|
+
>{$t('workflows.error.retry')}</ActionButton
|
|
125
|
+
>
|
|
126
|
+
</div>
|
|
127
|
+
{:else if items.length === 0}
|
|
128
|
+
<p class="py-4 text-center text-sm text-ink-muted">{$t('workflows.composition.none')}</p>
|
|
129
|
+
{:else}
|
|
130
|
+
<ul class="flex max-h-72 flex-col gap-1 overflow-auto">
|
|
131
|
+
{#each items as option (option.id)}
|
|
132
|
+
{@const isSelected = option.id === selectedId}
|
|
133
|
+
{@const isTaken = taken.has(option.id) && !isSelected}
|
|
134
|
+
<li>
|
|
135
|
+
<button
|
|
136
|
+
type="button"
|
|
137
|
+
disabled={isTaken}
|
|
138
|
+
aria-current={isSelected ? 'true' : undefined}
|
|
139
|
+
class="flex w-full items-center gap-3 rounded-medium border px-2 py-2 text-start text-sm focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary-green disabled:cursor-not-allowed disabled:opacity-50 {isSelected
|
|
140
|
+
? 'border-primary-green'
|
|
141
|
+
: 'border-grey2 hover:border-ink-subtle'}"
|
|
142
|
+
onclick={() => onpick(option)}
|
|
143
|
+
>
|
|
144
|
+
{#if option.thumbnailUrl}
|
|
145
|
+
<img
|
|
146
|
+
src={option.thumbnailUrl}
|
|
147
|
+
alt=""
|
|
148
|
+
loading="lazy"
|
|
149
|
+
draggable="false"
|
|
150
|
+
class="h-10 w-14 shrink-0 rounded-small border border-grey2 object-cover"
|
|
151
|
+
/>
|
|
152
|
+
{:else}
|
|
153
|
+
<span
|
|
154
|
+
class="flex h-10 w-14 shrink-0 items-center justify-center rounded-small border border-grey2 text-ink-muted"
|
|
155
|
+
>
|
|
156
|
+
<Icon name="composition" />
|
|
157
|
+
</span>
|
|
158
|
+
{/if}
|
|
159
|
+
<span class="flex min-w-0 flex-1 flex-col">
|
|
160
|
+
<span class="truncate font-medium" dir="auto">{option.name}</span>
|
|
161
|
+
{#if isTaken}
|
|
162
|
+
<span class="text-xs text-ink-muted">{$t('workflows.composition.alreadyUsed')}</span
|
|
163
|
+
>
|
|
164
|
+
{:else if !option.published}
|
|
165
|
+
<span class="text-xs text-ink-muted">{$t('workflows.block.notPublished')}</span>
|
|
166
|
+
{/if}
|
|
167
|
+
</span>
|
|
168
|
+
{#if isSelected}<Icon name="check" class="size-4 text-primary-green" />{/if}
|
|
169
|
+
</button>
|
|
170
|
+
</li>
|
|
171
|
+
{/each}
|
|
172
|
+
</ul>
|
|
173
|
+
{#if hasMore}
|
|
174
|
+
<ActionButton size="small" disabled={isLoadingMore} onclick={() => void read(true)}>
|
|
175
|
+
{isLoadingMore ? $t('workflows.common.loading') : $t('workflows.list.showMore')}
|
|
176
|
+
</ActionButton>
|
|
177
|
+
{/if}
|
|
178
|
+
{/if}
|
|
179
|
+
</div>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CompositionOption } from '../../api/types.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
/** The composition that is chosen now, if any. */
|
|
4
|
+
selectedId?: string | null;
|
|
5
|
+
/** Compositions already in the workflow: shown, but cannot be chosen. */
|
|
6
|
+
takenIds?: readonly string[];
|
|
7
|
+
/** Called with every composition the person picks, so the owner can remember its name and picture. */
|
|
8
|
+
onpick: (option: CompositionOption) => void;
|
|
9
|
+
/** Called with each page of compositions that was read, so the owner can remember them. */
|
|
10
|
+
onread?: (options: readonly CompositionOption[]) => void;
|
|
11
|
+
}
|
|
12
|
+
declare const CompositionPicker: import("svelte").Component<Props, {}, "">;
|
|
13
|
+
type CompositionPicker = ReturnType<typeof CompositionPicker>;
|
|
14
|
+
export default CompositionPicker;
|
|
@@ -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;
|