@flowdrop/flowdrop 2.8.0 → 2.10.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/CHANGELOG.md +227 -0
- package/dist/commands/executor.js +52 -8
- package/dist/commands/types.d.ts +3 -0
- package/dist/components/App.svelte +8 -0
- package/dist/components/App.svelte.d.ts +6 -0
- package/dist/components/CanvasContextMenu.stories.svelte +63 -0
- package/dist/components/CanvasContextMenu.stories.svelte.d.ts +19 -0
- package/dist/components/CanvasContextMenu.svelte +259 -0
- package/dist/components/CanvasContextMenu.svelte.d.ts +16 -0
- package/dist/components/CanvasController.svelte +23 -1
- package/dist/components/CanvasController.svelte.d.ts +16 -0
- package/dist/components/UniversalNode.svelte +12 -13
- package/dist/components/WorkflowEditor.svelte +364 -27
- package/dist/components/WorkflowEditor.svelte.d.ts +7 -0
- package/dist/components/WorkflowInterfaceEditor.svelte +28 -3
- package/dist/components/WorkflowInterfaceEntryCard.svelte +112 -2
- package/dist/components/WorkflowInterfaceEntryCard.svelte.d.ts +3 -1
- package/dist/components/form/FieldFactory.svelte +478 -0
- package/dist/components/form/FieldFactory.svelte.d.ts +14 -0
- package/dist/components/form/FormField.svelte +19 -404
- package/dist/components/form/FormField.svelte.d.ts +2 -27
- package/dist/components/form/FormFieldLight.svelte +11 -424
- package/dist/components/form/FormFieldLight.svelte.d.ts +2 -28
- package/dist/components/form/FormMarkdownEditor.svelte +11 -4
- package/dist/components/form/FormTemplateEditor.svelte +12 -5
- package/dist/components/form/resolveFieldType.d.ts +18 -15
- package/dist/components/form/resolveFieldType.js +33 -12
- package/dist/components/form/types.d.ts +14 -2
- package/dist/components/nodes/CaptionNode.stories.svelte +65 -0
- package/dist/components/nodes/CaptionNode.stories.svelte.d.ts +18 -0
- package/dist/components/nodes/CaptionNode.svelte +313 -0
- package/dist/components/nodes/CaptionNode.svelte.d.ts +16 -0
- package/dist/components/nodes/NotesNode.svelte +6 -0
- package/dist/components/playground/ChatBubble.svelte +2 -0
- package/dist/components/playground/ChatInput.svelte +18 -34
- package/dist/components/playground/ChatInput.svelte.d.ts +7 -0
- package/dist/components/playground/ControlPanel.svelte +27 -0
- package/dist/components/playground/ControlPanel.svelte.d.ts +12 -0
- package/dist/components/playground/ExecutionLogs.svelte +11 -8
- package/dist/components/playground/InterfaceInputForm.svelte +74 -0
- package/dist/components/playground/InterfaceInputForm.svelte.d.ts +14 -0
- package/dist/components/playground/LogRow.svelte +2 -0
- package/dist/components/playground/MessageCard.svelte +15 -3
- package/dist/components/playground/MessageNotice.svelte +2 -0
- package/dist/components/playground/MessageStream.svelte +87 -23
- package/dist/components/playground/OriginBadge.svelte +48 -0
- package/dist/components/playground/OriginBadge.svelte.d.ts +7 -0
- package/dist/components/playground/Playground.svelte +155 -38
- package/dist/components/playground/messageDisplay.d.ts +23 -1
- package/dist/components/playground/messageDisplay.js +49 -0
- package/dist/config/endpoints.d.ts +65 -0
- package/dist/config/endpoints.js +39 -0
- package/dist/core/index.d.ts +6 -3
- package/dist/core/index.js +2 -1
- package/dist/editor/contextMenu.d.ts +107 -0
- package/dist/editor/contextMenu.js +134 -0
- package/dist/editor/index.d.ts +2 -0
- package/dist/editor/index.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/messages/defaults.d.ts +63 -0
- package/dist/messages/defaults.js +59 -0
- package/dist/openapi/v1/openapi.yaml +356 -7
- package/dist/playground/commands/registry.js +4 -2
- package/dist/playground/index.d.ts +3 -2
- package/dist/playground/index.js +2 -1
- package/dist/registry/builtinNodeTypes.d.ts +1 -1
- package/dist/registry/builtinNodeTypes.js +1 -0
- package/dist/registry/builtinNodes.js +13 -0
- package/dist/registry/nodeComponentRegistry.d.ts +18 -0
- package/dist/registry/nodeComponentRegistry.js +14 -2
- package/dist/schemas/v1/workflow.schema.json +22 -1
- package/dist/services/historyService.d.ts +1 -1
- package/dist/services/historyService.js +2 -2
- package/dist/services/playgroundService.d.ts +35 -1
- package/dist/services/playgroundService.js +82 -36
- package/dist/stores/inlineEditStore.svelte.d.ts +35 -0
- package/dist/stores/inlineEditStore.svelte.js +63 -0
- package/dist/stores/instanceContainer.svelte.d.ts +6 -0
- package/dist/stores/instanceContainer.svelte.js +2 -0
- package/dist/stores/playgroundStore.svelte.d.ts +59 -2
- package/dist/stores/playgroundStore.svelte.js +128 -2
- package/dist/styles/base.css +8 -0
- package/dist/styles/tokens.css +8 -0
- package/dist/svelte-app.d.ts +15 -0
- package/dist/svelte-app.js +6 -4
- package/dist/types/index.d.ts +34 -1
- package/dist/types/index.js +11 -0
- package/dist/types/playground.d.ts +90 -9
- package/dist/types/playground.js +12 -4
- package/dist/utils/captionText.d.ts +43 -0
- package/dist/utils/captionText.js +49 -0
- package/dist/utils/focus.d.ts +16 -0
- package/dist/utils/focus.js +40 -0
- package/dist/utils/nodeTypes.js +1 -0
- package/dist/utils/nodeWrapper.js +2 -0
- package/dist/utils/workflowInterface.d.ts +83 -1
- package/dist/utils/workflowInterface.js +192 -1
- package/package.json +1 -1
|
@@ -28,12 +28,21 @@
|
|
|
28
28
|
import PortShapeSymbol from './ports/PortShapeSymbol.svelte';
|
|
29
29
|
import PortLaneChip from './ports/PortLaneChip.svelte';
|
|
30
30
|
import { m } from '../messages/index.js';
|
|
31
|
-
import
|
|
31
|
+
import {
|
|
32
|
+
DEFAULT_HISTORY_TURN_LIMIT,
|
|
33
|
+
type PortDataTypeConfig,
|
|
34
|
+
type WorkflowInterfaceEntry
|
|
35
|
+
} from '../types/index.js';
|
|
32
36
|
import type { PortCompatibilityChecker } from '../utils/connections.js';
|
|
33
37
|
import {
|
|
34
38
|
bindablePortKey,
|
|
35
39
|
describeInterfaceEntryStatus,
|
|
40
|
+
historyLimitOf,
|
|
41
|
+
historyLimitPatch,
|
|
42
|
+
isKnownTurn,
|
|
36
43
|
pullEntryFieldsFromPort,
|
|
44
|
+
turnPatch,
|
|
45
|
+
turnsFor,
|
|
37
46
|
type RankedBindablePort,
|
|
38
47
|
type InterfaceIssue,
|
|
39
48
|
type ResolvedInterfaceEntry
|
|
@@ -55,6 +64,8 @@
|
|
|
55
64
|
alreadyConnected?: boolean;
|
|
56
65
|
/** Label of the node feeding that competing edge, when there is one. */
|
|
57
66
|
conflictingSource?: string;
|
|
67
|
+
/** Input side only: the id of another input that already has this entry's turn. */
|
|
68
|
+
turnTakenBy?: string;
|
|
58
69
|
isFirst: boolean;
|
|
59
70
|
isLast: boolean;
|
|
60
71
|
onPatch: (patch: Partial<WorkflowInterfaceEntry>) => void;
|
|
@@ -72,6 +83,7 @@
|
|
|
72
83
|
footerIssues,
|
|
73
84
|
alreadyConnected = false,
|
|
74
85
|
conflictingSource,
|
|
86
|
+
turnTakenBy,
|
|
75
87
|
isFirst,
|
|
76
88
|
isLast,
|
|
77
89
|
onPatch,
|
|
@@ -86,7 +98,7 @@
|
|
|
86
98
|
*/
|
|
87
99
|
// The seed is meant to be read once.
|
|
88
100
|
// svelte-ignore state_referenced_locally
|
|
89
|
-
let fieldsOpen = $state(status?.status === 'type-mismatch');
|
|
101
|
+
let fieldsOpen = $state(status?.status === 'type-mismatch' || turnTakenBy !== undefined);
|
|
90
102
|
|
|
91
103
|
/** Statuses still explained in the footer (the rest render inline or as the dot). */
|
|
92
104
|
const FOOTER_STATUSES = new Set(['unbound', 'dangling', 'hidden', 'over-bound']);
|
|
@@ -106,6 +118,40 @@
|
|
|
106
118
|
return options;
|
|
107
119
|
}
|
|
108
120
|
|
|
121
|
+
/**
|
|
122
|
+
* Chat turn options for this direction. A stored value outside them — one
|
|
123
|
+
* from a newer server, or a value of the other direction — is listed too,
|
|
124
|
+
* so the select shows what is stored and never silently rewrites it.
|
|
125
|
+
*/
|
|
126
|
+
const turnOptions = $derived.by(() => {
|
|
127
|
+
const options: Array<{ value: string; label: string }> = turnsFor(
|
|
128
|
+
isInput ? 'input' : 'output'
|
|
129
|
+
).map((value) => ({ value, label: m().workflowInterface.turns[value] }));
|
|
130
|
+
const current = entry.turn;
|
|
131
|
+
if (current !== undefined && !options.some((option) => option.value === current)) {
|
|
132
|
+
options.push({
|
|
133
|
+
value: current,
|
|
134
|
+
label: isKnownTurn(current)
|
|
135
|
+
? m().workflowInterface.turns[current]
|
|
136
|
+
: m().workflowInterface.turnUnknown({ value: current })
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
return options;
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
/** The current turn's one-line description, when it is a known value. */
|
|
143
|
+
const turnDescription = $derived(
|
|
144
|
+
entry.turn !== undefined && isKnownTurn(entry.turn)
|
|
145
|
+
? m().workflowInterface.turnDescriptions[entry.turn]
|
|
146
|
+
: undefined
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
function setTurn(value: string): void {
|
|
150
|
+
// Only values the select offers reach here: the direction's vocabulary,
|
|
151
|
+
// '' for none, or the stored value itself (a no-op patch).
|
|
152
|
+
onPatch(turnPatch(entry, value));
|
|
153
|
+
}
|
|
154
|
+
|
|
109
155
|
/** Whether the binding picker is unfolded under the "Bound port" control. */
|
|
110
156
|
let pickerOpen = $state(false);
|
|
111
157
|
|
|
@@ -312,8 +358,53 @@
|
|
|
312
358
|
<summary>
|
|
313
359
|
<Icon icon="heroicons:chevron-right" />
|
|
314
360
|
{m().workflowInterface.moreOptions}
|
|
361
|
+
{#if entry.turn !== undefined}
|
|
362
|
+
<span class="wf-interface__turn-chip">
|
|
363
|
+
{isKnownTurn(entry.turn) ? m().workflowInterface.turns[entry.turn] : entry.turn}
|
|
364
|
+
</span>
|
|
365
|
+
{/if}
|
|
315
366
|
</summary>
|
|
316
367
|
<div class="wf-interface__more-body">
|
|
368
|
+
<div class="wf-interface__row">
|
|
369
|
+
<label class="wf-interface__field">
|
|
370
|
+
<span class="wf-interface__label">{m().workflowInterface.turnLabel}</span>
|
|
371
|
+
<Select
|
|
372
|
+
size="sm"
|
|
373
|
+
invalid={turnTakenBy !== undefined}
|
|
374
|
+
value={entry.turn ?? ''}
|
|
375
|
+
onchange={(e) => setTurn(e.currentTarget.value)}
|
|
376
|
+
>
|
|
377
|
+
<option value="">{m().workflowInterface.turnNone}</option>
|
|
378
|
+
{#each turnOptions as option (option.value)}
|
|
379
|
+
<option value={option.value}>{option.label}</option>
|
|
380
|
+
{/each}
|
|
381
|
+
</Select>
|
|
382
|
+
{#if turnTakenBy !== undefined}
|
|
383
|
+
<span class="wf-interface__inline wf-interface__inline--warning">
|
|
384
|
+
{m().workflowInterface.turnTakenInline({ id: turnTakenBy })}
|
|
385
|
+
</span>
|
|
386
|
+
{:else if turnDescription}
|
|
387
|
+
<span class="wf-interface__hint">{turnDescription}</span>
|
|
388
|
+
{/if}
|
|
389
|
+
</label>
|
|
390
|
+
{#if entry.turn === 'history'}
|
|
391
|
+
<label class="wf-interface__field">
|
|
392
|
+
<span class="wf-interface__label">{m().workflowInterface.historyLimitLabel}</span>
|
|
393
|
+
<Input
|
|
394
|
+
size="sm"
|
|
395
|
+
type="number"
|
|
396
|
+
min="1"
|
|
397
|
+
step="1"
|
|
398
|
+
value={historyLimitOf(entry) ?? ''}
|
|
399
|
+
placeholder={m().workflowInterface.historyLimitPlaceholder({
|
|
400
|
+
limit: DEFAULT_HISTORY_TURN_LIMIT
|
|
401
|
+
})}
|
|
402
|
+
onchange={(e) => onPatch(historyLimitPatch(entry, e.currentTarget.value))}
|
|
403
|
+
/>
|
|
404
|
+
</label>
|
|
405
|
+
{/if}
|
|
406
|
+
</div>
|
|
407
|
+
|
|
317
408
|
{#if boundTarget}
|
|
318
409
|
<div class="wf-interface__pull-row">
|
|
319
410
|
<Button
|
|
@@ -737,6 +828,25 @@
|
|
|
737
828
|
line-height: 1.4;
|
|
738
829
|
}
|
|
739
830
|
|
|
831
|
+
.wf-interface__hint {
|
|
832
|
+
font-size: var(--fd-text-xs);
|
|
833
|
+
line-height: 1.4;
|
|
834
|
+
color: var(--fd-muted-foreground);
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
/* The entry's chat turn, said at rest on the disclosure's summary. */
|
|
838
|
+
.wf-interface__turn-chip {
|
|
839
|
+
margin-left: var(--fd-space-xs);
|
|
840
|
+
padding: 0 var(--fd-space-xs);
|
|
841
|
+
border: 1px solid var(--fd-border);
|
|
842
|
+
border-radius: var(--fd-radius-full);
|
|
843
|
+
background-color: var(--fd-muted);
|
|
844
|
+
color: var(--fd-foreground);
|
|
845
|
+
font-size: var(--fd-text-2xs);
|
|
846
|
+
font-weight: 600;
|
|
847
|
+
line-height: 1.5;
|
|
848
|
+
}
|
|
849
|
+
|
|
740
850
|
.wf-interface__inline--warning {
|
|
741
851
|
color: var(--fd-warning);
|
|
742
852
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type PortDataTypeConfig, type WorkflowInterfaceEntry } from '../types/index.js';
|
|
2
2
|
import type { PortCompatibilityChecker } from '../utils/connections.js';
|
|
3
3
|
import { type RankedBindablePort, type InterfaceIssue, type ResolvedInterfaceEntry } from '../utils/workflowInterface.js';
|
|
4
4
|
interface Props {
|
|
@@ -17,6 +17,8 @@ interface Props {
|
|
|
17
17
|
alreadyConnected?: boolean;
|
|
18
18
|
/** Label of the node feeding that competing edge, when there is one. */
|
|
19
19
|
conflictingSource?: string;
|
|
20
|
+
/** Input side only: the id of another input that already has this entry's turn. */
|
|
21
|
+
turnTakenBy?: string;
|
|
20
22
|
isFirst: boolean;
|
|
21
23
|
isLast: boolean;
|
|
22
24
|
onPatch: (patch: Partial<WorkflowInterfaceEntry>) => void;
|
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
FieldFactory Component (internal — not exported)
|
|
3
|
+
Factory component that renders the appropriate field based on schema type.
|
|
4
|
+
|
|
5
|
+
The one field factory. The public components are thin wrappers around it:
|
|
6
|
+
- FormFieldLight (exported as `FormField` from "@flowdrop/flowdrop/form")
|
|
7
|
+
passes no editors, so CodeMirror stays out of the light entry
|
|
8
|
+
- FormField (exported as `FormFieldFull` from "@flowdrop/flowdrop/form/full")
|
|
9
|
+
passes the statically imported code, markdown and template editors
|
|
10
|
+
|
|
11
|
+
Heavy editors (code, markdown, template) are not imported here; they come
|
|
12
|
+
from, in order:
|
|
13
|
+
- the instance's field registry — `registerCodeEditorField()` from
|
|
14
|
+
"@flowdrop/flowdrop/form/code", `registerMarkdownEditorField()` from
|
|
15
|
+
"@flowdrop/flowdrop/form/markdown", or any host override
|
|
16
|
+
- the `editors` prop, which only the two wrappers above set
|
|
17
|
+
- otherwise a plain textarea with a hint naming the registration call
|
|
18
|
+
|
|
19
|
+
Features:
|
|
20
|
+
- Automatically selects the correct field component based on schema
|
|
21
|
+
- Wraps fields with FormFieldWrapper for consistent layout
|
|
22
|
+
- Supports all basic field types (string, number, boolean, checkbox group, range)
|
|
23
|
+
- Uses standard JSON Schema patterns (enum, oneOf) for select fields
|
|
24
|
+
- schema.readOnly disables every input, built-in or registered
|
|
25
|
+
|
|
26
|
+
Type Resolution Order:
|
|
27
|
+
1. Check field registry for custom/heavy components (highest priority)
|
|
28
|
+
2. format: 'hidden' -> skip rendering (return nothing)
|
|
29
|
+
3. format: 'autocomplete' with autocomplete.url -> FormAutocomplete
|
|
30
|
+
4. format: 'json' | 'code' | 'markdown' | 'template', or type: 'object' with
|
|
31
|
+
no format of its own -> `editors` prop, else the textarea fallback
|
|
32
|
+
5. format: 'ports' -> FormPorts
|
|
33
|
+
6. enum with multiple: true -> FormCheckboxGroup
|
|
34
|
+
7. enum -> FormSelect (simple values without labels)
|
|
35
|
+
8. oneOf with const/title (labeled options) -> FormSelect
|
|
36
|
+
9. format: 'multiline' -> FormTextarea
|
|
37
|
+
10. format: 'range' (number/integer) -> FormRangeField
|
|
38
|
+
11. type: 'string' -> FormTextField
|
|
39
|
+
12. type: 'number' or 'integer' -> FormNumberField
|
|
40
|
+
13. type: 'boolean' -> FormToggle
|
|
41
|
+
14. type: 'array' -> FormArray
|
|
42
|
+
15. fallback -> FormTextField
|
|
43
|
+
-->
|
|
44
|
+
|
|
45
|
+
<script lang="ts">
|
|
46
|
+
import FormFieldWrapper from './FormFieldWrapper.svelte';
|
|
47
|
+
import FormTextField from './FormTextField.svelte';
|
|
48
|
+
import FormTextarea from './FormTextarea.svelte';
|
|
49
|
+
import FormNumberField from './FormNumberField.svelte';
|
|
50
|
+
import FormRangeField from './FormRangeField.svelte';
|
|
51
|
+
import FormToggle from './FormToggle.svelte';
|
|
52
|
+
import FormSelect from './FormSelect.svelte';
|
|
53
|
+
import FormCheckboxGroup from './FormCheckboxGroup.svelte';
|
|
54
|
+
import FormArray from './FormArray.svelte';
|
|
55
|
+
import FormPorts from './FormPorts.svelte';
|
|
56
|
+
import FormAutocomplete from './FormAutocomplete.svelte';
|
|
57
|
+
import { getInstance } from '../../stores/getInstance.svelte.js';
|
|
58
|
+
import { getResolvedTheme } from '../../stores/settingsStore.svelte.js';
|
|
59
|
+
import type { FormFieldFactoryProps } from './types.js';
|
|
60
|
+
import { getSchemaOptions } from './types.js';
|
|
61
|
+
import {
|
|
62
|
+
resolveBaseFieldType,
|
|
63
|
+
resolveHeavyEditorKind,
|
|
64
|
+
type HeavyEditorKind
|
|
65
|
+
} from './resolveFieldType.js';
|
|
66
|
+
import type { FieldComponent } from '../../form/fieldRegistry.js';
|
|
67
|
+
|
|
68
|
+
const fd = getInstance();
|
|
69
|
+
|
|
70
|
+
interface Props extends FormFieldFactoryProps {
|
|
71
|
+
/**
|
|
72
|
+
* Heavy editors to use when the field registry has none for the schema.
|
|
73
|
+
* Set only by the wrappers: `FormFieldFull` passes the statically imported
|
|
74
|
+
* set; `FormFieldLight` passes none so CodeMirror stays out of its bundle.
|
|
75
|
+
*/
|
|
76
|
+
editors?: Partial<Record<HeavyEditorKind, FieldComponent>>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let {
|
|
80
|
+
fieldKey,
|
|
81
|
+
schema,
|
|
82
|
+
value,
|
|
83
|
+
required = false,
|
|
84
|
+
animationIndex = 0,
|
|
85
|
+
node,
|
|
86
|
+
nodes,
|
|
87
|
+
edges,
|
|
88
|
+
workflowId,
|
|
89
|
+
authProvider,
|
|
90
|
+
editors,
|
|
91
|
+
onChange
|
|
92
|
+
}: Props = $props();
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* When schema.readOnly is true, disable all inputs (no editing).
|
|
96
|
+
*/
|
|
97
|
+
const isReadOnly = $derived(schema.readOnly === true);
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Computed description ID for ARIA association
|
|
101
|
+
*/
|
|
102
|
+
const descriptionId = $derived(
|
|
103
|
+
schema.description && schema.title ? `${fieldKey}-description` : undefined
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Animation delay based on index
|
|
108
|
+
*/
|
|
109
|
+
const animationDelay = $derived(animationIndex * 30);
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Field label - prefer title, fall back to description, then key
|
|
113
|
+
*/
|
|
114
|
+
const fieldLabel = $derived(String(schema.title ?? schema.description ?? fieldKey));
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The heavy editor this schema asks for, if any
|
|
118
|
+
*/
|
|
119
|
+
const heavyEditorKind = $derived(resolveHeavyEditorKind(schema));
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* The component to render instead of a built-in field: a registry match
|
|
123
|
+
* (host overrides and registered heavy editors) wins, then the heavy editor
|
|
124
|
+
* handed in through `editors`
|
|
125
|
+
*/
|
|
126
|
+
const RegisteredComponent = $derived(
|
|
127
|
+
fd.fields.resolveFieldComponent(schema)?.component ??
|
|
128
|
+
(heavyEditorKind ? editors?.[heavyEditorKind] : undefined)
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Determine the field type to render
|
|
133
|
+
*/
|
|
134
|
+
const fieldType = $derived.by(() => {
|
|
135
|
+
if (RegisteredComponent) {
|
|
136
|
+
return 'registered';
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Hidden fields should not be rendered
|
|
140
|
+
if (schema.format === 'hidden') {
|
|
141
|
+
return 'hidden';
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Autocomplete for format: "autocomplete" with autocomplete.url. A
|
|
145
|
+
// registered override already won above.
|
|
146
|
+
if (schema.format === 'autocomplete' && schema.autocomplete?.url) {
|
|
147
|
+
return 'autocomplete';
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// A heavy editor nobody registered or passed in
|
|
151
|
+
if (heavyEditorKind) {
|
|
152
|
+
return `${heavyEditorKind}-fallback` as const;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Injected port order + exposure widget (the `ports` reserved config prop).
|
|
156
|
+
if (schema.format === 'ports') {
|
|
157
|
+
return 'ports';
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Shared basic field resolution (enum/oneOf/primitive types).
|
|
161
|
+
const base = resolveBaseFieldType(schema);
|
|
162
|
+
if (base) {
|
|
163
|
+
return base;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Fallback to text
|
|
167
|
+
return 'text';
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Get enum options as string array for select/checkbox components
|
|
172
|
+
*/
|
|
173
|
+
const enumOptions = $derived.by((): string[] => {
|
|
174
|
+
if (!schema.enum) return [];
|
|
175
|
+
return schema.enum.map((opt) => String(opt));
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Get select options for select-options type
|
|
180
|
+
* Handles both oneOf (standard) and options (legacy) patterns
|
|
181
|
+
*/
|
|
182
|
+
const selectOptions = $derived(getSchemaOptions(schema));
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Get current value as the appropriate type
|
|
186
|
+
*/
|
|
187
|
+
const stringValue = $derived(String(value ?? ''));
|
|
188
|
+
const numberValue = $derived(value as number | string);
|
|
189
|
+
const booleanValue = $derived(Boolean(value ?? schema.default ?? false));
|
|
190
|
+
const arrayValue = $derived.by((): string[] => {
|
|
191
|
+
if (Array.isArray(value)) {
|
|
192
|
+
return value.map((v) => String(v));
|
|
193
|
+
}
|
|
194
|
+
return [];
|
|
195
|
+
});
|
|
196
|
+
const arrayItems = $derived.by((): unknown[] => {
|
|
197
|
+
if (Array.isArray(value)) {
|
|
198
|
+
return value;
|
|
199
|
+
}
|
|
200
|
+
return [];
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Autocomplete value - string or string[] depending on `autocomplete.multiple`
|
|
205
|
+
*/
|
|
206
|
+
const autocompleteValue = $derived.by((): string | string[] => {
|
|
207
|
+
if (schema.autocomplete?.multiple) {
|
|
208
|
+
if (Array.isArray(value)) {
|
|
209
|
+
return value.map((v) => String(v));
|
|
210
|
+
}
|
|
211
|
+
return value ? [String(value)] : [];
|
|
212
|
+
}
|
|
213
|
+
return String(value ?? '');
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Get helpful message for missing editor registration
|
|
218
|
+
*/
|
|
219
|
+
function getEditorHint(editorType: string): string {
|
|
220
|
+
switch (editorType) {
|
|
221
|
+
case 'code-editor-fallback':
|
|
222
|
+
return "Code editor not registered. Register it on the instance's field registry: import { registerCodeEditorField } from '@flowdrop/flowdrop/form/code'; registerCodeEditorField(instance.fields);";
|
|
223
|
+
case 'markdown-editor-fallback':
|
|
224
|
+
return "Markdown editor not registered. Register it on the instance's field registry: import { registerMarkdownEditorField } from '@flowdrop/flowdrop/form/markdown'; registerMarkdownEditorField(instance.fields);";
|
|
225
|
+
case 'template-editor-fallback':
|
|
226
|
+
return "Template editor not registered. Register it on the instance's field registry: import { registerTemplateEditorField } from '@flowdrop/flowdrop/form/code'; registerTemplateEditorField(instance.fields);";
|
|
227
|
+
default:
|
|
228
|
+
return 'This field type requires additional registration.';
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
</script>
|
|
232
|
+
|
|
233
|
+
{#if fieldType !== 'hidden'}
|
|
234
|
+
<FormFieldWrapper
|
|
235
|
+
id={fieldKey}
|
|
236
|
+
label={fieldLabel}
|
|
237
|
+
{required}
|
|
238
|
+
description={schema.title ? schema.description : undefined}
|
|
239
|
+
{animationDelay}
|
|
240
|
+
>
|
|
241
|
+
{#if fieldType === 'registered' && RegisteredComponent}
|
|
242
|
+
<!-- Render registered custom component -->
|
|
243
|
+
<!-- darkTheme: use schema value if explicitly set, otherwise derive from resolved theme -->
|
|
244
|
+
<!-- placeholder stays undefined when unset so each editor keeps its own default -->
|
|
245
|
+
<RegisteredComponent
|
|
246
|
+
id={fieldKey}
|
|
247
|
+
{value}
|
|
248
|
+
placeholder={schema.placeholder}
|
|
249
|
+
{required}
|
|
250
|
+
{schema}
|
|
251
|
+
ariaDescribedBy={descriptionId}
|
|
252
|
+
disabled={isReadOnly}
|
|
253
|
+
height={schema.height as string | undefined}
|
|
254
|
+
darkTheme={schema.darkTheme ?? getResolvedTheme() === 'dark'}
|
|
255
|
+
autoFormat={schema.autoFormat as boolean | undefined}
|
|
256
|
+
showToolbar={schema.showToolbar as boolean | undefined}
|
|
257
|
+
showStatusBar={schema.showStatusBar as boolean | undefined}
|
|
258
|
+
spellChecker={schema.spellChecker as boolean | undefined}
|
|
259
|
+
variables={schema.variables}
|
|
260
|
+
placeholderExample={schema.placeholderExample as string | undefined}
|
|
261
|
+
autocomplete={schema.autocomplete}
|
|
262
|
+
{node}
|
|
263
|
+
{nodes}
|
|
264
|
+
{edges}
|
|
265
|
+
{workflowId}
|
|
266
|
+
{authProvider}
|
|
267
|
+
onChange={(val: unknown) => onChange(val)}
|
|
268
|
+
/>
|
|
269
|
+
{:else if fieldType === 'autocomplete' && schema.autocomplete}
|
|
270
|
+
<FormAutocomplete
|
|
271
|
+
id={fieldKey}
|
|
272
|
+
value={autocompleteValue}
|
|
273
|
+
autocomplete={schema.autocomplete}
|
|
274
|
+
placeholder={schema.placeholder ?? ''}
|
|
275
|
+
{required}
|
|
276
|
+
ariaDescribedBy={descriptionId}
|
|
277
|
+
disabled={isReadOnly}
|
|
278
|
+
onChange={(val) => onChange(val)}
|
|
279
|
+
/>
|
|
280
|
+
{:else if fieldType === 'checkbox-group'}
|
|
281
|
+
<FormCheckboxGroup
|
|
282
|
+
id={fieldKey}
|
|
283
|
+
value={arrayValue}
|
|
284
|
+
options={enumOptions}
|
|
285
|
+
ariaDescribedBy={descriptionId}
|
|
286
|
+
disabled={isReadOnly}
|
|
287
|
+
onChange={(val) => onChange(val)}
|
|
288
|
+
/>
|
|
289
|
+
{:else if fieldType === 'select-enum'}
|
|
290
|
+
<FormSelect
|
|
291
|
+
id={fieldKey}
|
|
292
|
+
value={stringValue}
|
|
293
|
+
options={enumOptions}
|
|
294
|
+
{required}
|
|
295
|
+
ariaDescribedBy={descriptionId}
|
|
296
|
+
disabled={isReadOnly}
|
|
297
|
+
onChange={(val) => onChange(val)}
|
|
298
|
+
/>
|
|
299
|
+
{:else if fieldType === 'textarea'}
|
|
300
|
+
<FormTextarea
|
|
301
|
+
id={fieldKey}
|
|
302
|
+
value={stringValue}
|
|
303
|
+
placeholder={schema.placeholder ?? ''}
|
|
304
|
+
{required}
|
|
305
|
+
ariaDescribedBy={descriptionId}
|
|
306
|
+
disabled={isReadOnly}
|
|
307
|
+
onChange={(val) => onChange(val)}
|
|
308
|
+
/>
|
|
309
|
+
{:else if fieldType === 'text'}
|
|
310
|
+
<FormTextField
|
|
311
|
+
id={fieldKey}
|
|
312
|
+
value={stringValue}
|
|
313
|
+
placeholder={schema.placeholder ?? ''}
|
|
314
|
+
{required}
|
|
315
|
+
ariaDescribedBy={descriptionId}
|
|
316
|
+
disabled={isReadOnly}
|
|
317
|
+
onChange={(val) => onChange(val)}
|
|
318
|
+
/>
|
|
319
|
+
{:else if fieldType === 'number'}
|
|
320
|
+
<FormNumberField
|
|
321
|
+
id={fieldKey}
|
|
322
|
+
value={numberValue}
|
|
323
|
+
placeholder={schema.placeholder ?? ''}
|
|
324
|
+
min={schema.minimum}
|
|
325
|
+
max={schema.maximum}
|
|
326
|
+
step={schema.step}
|
|
327
|
+
{required}
|
|
328
|
+
ariaDescribedBy={descriptionId}
|
|
329
|
+
disabled={isReadOnly}
|
|
330
|
+
onChange={(val) => onChange(val)}
|
|
331
|
+
/>
|
|
332
|
+
{:else if fieldType === 'range'}
|
|
333
|
+
<FormRangeField
|
|
334
|
+
id={fieldKey}
|
|
335
|
+
value={numberValue}
|
|
336
|
+
min={schema.minimum}
|
|
337
|
+
max={schema.maximum}
|
|
338
|
+
step={schema.step}
|
|
339
|
+
{required}
|
|
340
|
+
ariaDescribedBy={descriptionId}
|
|
341
|
+
disabled={isReadOnly}
|
|
342
|
+
onChange={(val) => onChange(val)}
|
|
343
|
+
/>
|
|
344
|
+
{:else if fieldType === 'toggle'}
|
|
345
|
+
<FormToggle
|
|
346
|
+
id={fieldKey}
|
|
347
|
+
value={booleanValue}
|
|
348
|
+
ariaDescribedBy={descriptionId}
|
|
349
|
+
disabled={isReadOnly}
|
|
350
|
+
onChange={(val) => onChange(val)}
|
|
351
|
+
/>
|
|
352
|
+
{:else if fieldType === 'select-options'}
|
|
353
|
+
<FormSelect
|
|
354
|
+
id={fieldKey}
|
|
355
|
+
value={stringValue}
|
|
356
|
+
options={selectOptions}
|
|
357
|
+
{required}
|
|
358
|
+
ariaDescribedBy={descriptionId}
|
|
359
|
+
disabled={isReadOnly}
|
|
360
|
+
onChange={(val) => onChange(val)}
|
|
361
|
+
/>
|
|
362
|
+
{:else if fieldType === 'array' && schema.items}
|
|
363
|
+
<FormArray
|
|
364
|
+
id={fieldKey}
|
|
365
|
+
value={arrayItems}
|
|
366
|
+
itemSchema={schema.items}
|
|
367
|
+
minItems={schema.minItems}
|
|
368
|
+
maxItems={schema.maxItems}
|
|
369
|
+
addLabel={`Add ${schema.items.title ?? 'Item'}`}
|
|
370
|
+
disabled={isReadOnly}
|
|
371
|
+
onChange={(val) => onChange(val)}
|
|
372
|
+
/>
|
|
373
|
+
{:else if fieldType === 'ports'}
|
|
374
|
+
<FormPorts
|
|
375
|
+
id={fieldKey}
|
|
376
|
+
{value}
|
|
377
|
+
ariaDescribedBy={descriptionId}
|
|
378
|
+
{node}
|
|
379
|
+
disabled={isReadOnly}
|
|
380
|
+
onChange={(val) => onChange(val)}
|
|
381
|
+
/>
|
|
382
|
+
{:else if fieldType.endsWith('-fallback')}
|
|
383
|
+
<!-- Fallback for unregistered heavy editors -->
|
|
384
|
+
<div class="form-field-fallback">
|
|
385
|
+
<div class="form-field-fallback__message">
|
|
386
|
+
<svg
|
|
387
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
388
|
+
viewBox="0 0 20 20"
|
|
389
|
+
fill="currentColor"
|
|
390
|
+
class="form-field-fallback__icon"
|
|
391
|
+
>
|
|
392
|
+
<path
|
|
393
|
+
fill-rule="evenodd"
|
|
394
|
+
d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z"
|
|
395
|
+
clip-rule="evenodd"
|
|
396
|
+
/>
|
|
397
|
+
</svg>
|
|
398
|
+
<span>Editor component not registered</span>
|
|
399
|
+
</div>
|
|
400
|
+
<p class="form-field-fallback__hint">
|
|
401
|
+
{getEditorHint(fieldType)}
|
|
402
|
+
</p>
|
|
403
|
+
<!-- Provide a basic textarea fallback for editing -->
|
|
404
|
+
<FormTextarea
|
|
405
|
+
id={fieldKey}
|
|
406
|
+
value={typeof value === 'string' ? value : JSON.stringify(value, null, 2)}
|
|
407
|
+
placeholder={schema.placeholder ?? 'Enter value...'}
|
|
408
|
+
{required}
|
|
409
|
+
ariaDescribedBy={descriptionId}
|
|
410
|
+
disabled={isReadOnly}
|
|
411
|
+
onChange={(val) => {
|
|
412
|
+
// Try to parse as JSON for object types
|
|
413
|
+
if (schema.type === 'object' || schema.format === 'json') {
|
|
414
|
+
try {
|
|
415
|
+
onChange(JSON.parse(val));
|
|
416
|
+
} catch {
|
|
417
|
+
onChange(val);
|
|
418
|
+
}
|
|
419
|
+
} else {
|
|
420
|
+
onChange(val);
|
|
421
|
+
}
|
|
422
|
+
}}
|
|
423
|
+
/>
|
|
424
|
+
</div>
|
|
425
|
+
{:else}
|
|
426
|
+
<!-- Fallback to text input -->
|
|
427
|
+
<FormTextField
|
|
428
|
+
id={fieldKey}
|
|
429
|
+
value={stringValue}
|
|
430
|
+
placeholder={schema.placeholder ?? ''}
|
|
431
|
+
ariaDescribedBy={descriptionId}
|
|
432
|
+
disabled={isReadOnly}
|
|
433
|
+
onChange={(val) => onChange(val)}
|
|
434
|
+
/>
|
|
435
|
+
{/if}
|
|
436
|
+
</FormFieldWrapper>
|
|
437
|
+
{/if}
|
|
438
|
+
|
|
439
|
+
<style>
|
|
440
|
+
.form-field-fallback {
|
|
441
|
+
display: flex;
|
|
442
|
+
flex-direction: column;
|
|
443
|
+
gap: 0.5rem;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
.form-field-fallback__message {
|
|
447
|
+
display: flex;
|
|
448
|
+
align-items: center;
|
|
449
|
+
gap: 0.5rem;
|
|
450
|
+
padding: 0.5rem 0.75rem;
|
|
451
|
+
background-color: var(--fd-warning-muted);
|
|
452
|
+
border: 1px solid var(--fd-warning);
|
|
453
|
+
border-radius: var(--fd-radius-md);
|
|
454
|
+
color: var(--fd-warning-hover);
|
|
455
|
+
font-size: 0.8125rem;
|
|
456
|
+
font-weight: 500;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
.form-field-fallback__icon {
|
|
460
|
+
width: 1rem;
|
|
461
|
+
height: 1rem;
|
|
462
|
+
flex-shrink: 0;
|
|
463
|
+
color: var(--fd-warning);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
.form-field-fallback__hint {
|
|
467
|
+
margin: 0;
|
|
468
|
+
padding: 0.5rem 0.75rem;
|
|
469
|
+
background-color: var(--fd-muted);
|
|
470
|
+
border: 1px solid var(--fd-border);
|
|
471
|
+
border-radius: var(--fd-radius-md);
|
|
472
|
+
font-family: 'JetBrains Mono', 'Fira Code', 'Monaco', 'Menlo', monospace;
|
|
473
|
+
font-size: 0.6875rem;
|
|
474
|
+
line-height: 1.5;
|
|
475
|
+
color: var(--fd-muted-foreground);
|
|
476
|
+
word-break: break-word;
|
|
477
|
+
}
|
|
478
|
+
</style>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { FormFieldFactoryProps } from './types.js';
|
|
2
|
+
import { type HeavyEditorKind } from './resolveFieldType.js';
|
|
3
|
+
import type { FieldComponent } from '../../form/fieldRegistry.js';
|
|
4
|
+
interface Props extends FormFieldFactoryProps {
|
|
5
|
+
/**
|
|
6
|
+
* Heavy editors to use when the field registry has none for the schema.
|
|
7
|
+
* Set only by the wrappers: `FormFieldFull` passes the statically imported
|
|
8
|
+
* set; `FormFieldLight` passes none so CodeMirror stays out of its bundle.
|
|
9
|
+
*/
|
|
10
|
+
editors?: Partial<Record<HeavyEditorKind, FieldComponent>>;
|
|
11
|
+
}
|
|
12
|
+
declare const FieldFactory: import("svelte").Component<Props, {}, "">;
|
|
13
|
+
type FieldFactory = ReturnType<typeof FieldFactory>;
|
|
14
|
+
export default FieldFactory;
|