@flowdrop/flowdrop 2.8.0 → 2.9.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 +40 -0
- 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/package.json +1 -1
|
@@ -1,432 +1,19 @@
|
|
|
1
1
|
<!--
|
|
2
|
-
FormFieldLight Component
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Heavy components are only loaded if registered via:
|
|
9
|
-
- `registerCodeEditorField()` from "@flowdrop/flowdrop/form/code"
|
|
10
|
-
- `registerMarkdownEditorField()` from "@flowdrop/flowdrop/form/markdown"
|
|
11
|
-
|
|
12
|
-
Features:
|
|
13
|
-
- Automatically selects the correct field component based on schema
|
|
14
|
-
- Wraps fields with FormFieldWrapper for consistent layout
|
|
15
|
-
- Supports all basic field types (string, number, boolean, checkbox group, range)
|
|
16
|
-
- Uses standard JSON Schema patterns (enum, oneOf) for select fields
|
|
17
|
-
- Heavy editors (code, markdown, template) require explicit registration
|
|
18
|
-
- Shows helpful fallback when heavy editors aren't registered
|
|
19
|
-
|
|
20
|
-
Type Resolution Order:
|
|
21
|
-
1. Check field registry for custom/heavy components (highest priority)
|
|
22
|
-
2. format: 'hidden' -> skip rendering (return nothing)
|
|
23
|
-
3. enum with multiple: true -> FormCheckboxGroup
|
|
24
|
-
4. enum -> FormSelect (simple values without labels)
|
|
25
|
-
5. oneOf with const/title (labeled options) -> FormSelect
|
|
26
|
-
6. format: 'multiline' -> FormTextarea
|
|
27
|
-
7. format: 'range' (number/integer) -> FormRangeField
|
|
28
|
-
8. type: 'string' -> FormTextField
|
|
29
|
-
9. type: 'number' or 'integer' -> FormNumberField
|
|
30
|
-
10. type: 'boolean' -> FormToggle
|
|
31
|
-
11. type: 'array' -> FormArray
|
|
32
|
-
12. fallback -> FormTextField
|
|
2
|
+
FormFieldLight Component (exported as `FormField` from "@flowdrop/flowdrop/form")
|
|
3
|
+
|
|
4
|
+
The field factory without heavy editors: code, markdown and template fields
|
|
5
|
+
render through the instance's field registry, or as a plain textarea with a
|
|
6
|
+
hint naming the registration call. All field resolution lives in
|
|
7
|
+
FieldFactory; see its header for the order.
|
|
33
8
|
-->
|
|
34
9
|
|
|
35
10
|
<script lang="ts">
|
|
36
|
-
import
|
|
37
|
-
import FormTextField from './FormTextField.svelte';
|
|
38
|
-
import FormTextarea from './FormTextarea.svelte';
|
|
39
|
-
import FormNumberField from './FormNumberField.svelte';
|
|
40
|
-
import FormRangeField from './FormRangeField.svelte';
|
|
41
|
-
import FormToggle from './FormToggle.svelte';
|
|
42
|
-
import FormSelect from './FormSelect.svelte';
|
|
43
|
-
import FormCheckboxGroup from './FormCheckboxGroup.svelte';
|
|
44
|
-
import FormArray from './FormArray.svelte';
|
|
45
|
-
import FormPorts from './FormPorts.svelte';
|
|
46
|
-
import { getInstance } from '../../stores/getInstance.svelte.js';
|
|
47
|
-
import { getResolvedTheme } from '../../stores/settingsStore.svelte.js';
|
|
48
|
-
|
|
49
|
-
const fd = getInstance();
|
|
50
|
-
import type { FieldSchema } from './types.js';
|
|
51
|
-
import { getSchemaOptions } from './types.js';
|
|
52
|
-
import { resolveBaseFieldType } from './resolveFieldType.js';
|
|
53
|
-
import type { WorkflowNode, WorkflowEdge } from '../../types/index.js';
|
|
54
|
-
import type { AuthProvider } from '../../types/auth.js';
|
|
55
|
-
|
|
56
|
-
interface Props {
|
|
57
|
-
/** Unique key/id for the field */
|
|
58
|
-
fieldKey: string;
|
|
59
|
-
/** Field schema definition */
|
|
60
|
-
schema: FieldSchema;
|
|
61
|
-
/** Current field value */
|
|
62
|
-
value: unknown;
|
|
63
|
-
/** Whether the field is required */
|
|
64
|
-
required?: boolean;
|
|
65
|
-
/** Animation delay index for staggered animations */
|
|
66
|
-
animationIndex?: number;
|
|
67
|
-
/** Current workflow node (optional, forwarded to registered editors for template variable API mode) */
|
|
68
|
-
node?: WorkflowNode;
|
|
69
|
-
/** All workflow nodes (optional, forwarded to registered editors for port-derived variables) */
|
|
70
|
-
nodes?: WorkflowNode[];
|
|
71
|
-
/** All workflow edges (optional, forwarded to registered editors for port-derived variables) */
|
|
72
|
-
edges?: WorkflowEdge[];
|
|
73
|
-
/** Workflow ID (optional, forwarded to registered editors for template variable API mode) */
|
|
74
|
-
workflowId?: string;
|
|
75
|
-
/** Auth provider (optional, forwarded to registered editors for API requests) */
|
|
76
|
-
authProvider?: AuthProvider;
|
|
77
|
-
/** Callback when the field value changes */
|
|
78
|
-
onChange: (value: unknown) => void;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
let {
|
|
82
|
-
fieldKey,
|
|
83
|
-
schema,
|
|
84
|
-
value,
|
|
85
|
-
required = false,
|
|
86
|
-
animationIndex = 0,
|
|
87
|
-
node,
|
|
88
|
-
nodes,
|
|
89
|
-
edges,
|
|
90
|
-
workflowId,
|
|
91
|
-
authProvider,
|
|
92
|
-
onChange
|
|
93
|
-
}: Props = $props();
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Computed description ID for ARIA association
|
|
97
|
-
*/
|
|
98
|
-
const descriptionId = $derived(
|
|
99
|
-
schema.description && schema.title ? `${fieldKey}-description` : undefined
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Animation delay based on index
|
|
104
|
-
*/
|
|
105
|
-
const animationDelay = $derived(animationIndex * 30);
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Field label - prefer title, fall back to description, then key
|
|
109
|
-
*/
|
|
110
|
-
const fieldLabel = $derived(String(schema.title ?? schema.description ?? fieldKey));
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Check if there's a registered custom component for this schema
|
|
114
|
-
*/
|
|
115
|
-
const registeredComponent = $derived(fd.fields.resolveFieldComponent(schema));
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Determine the field type to render (for non-registered components)
|
|
119
|
-
*/
|
|
120
|
-
const fieldType = $derived.by(() => {
|
|
121
|
-
// If a custom component is registered, use it
|
|
122
|
-
if (registeredComponent) {
|
|
123
|
-
return 'registered';
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Hidden fields should not be rendered
|
|
127
|
-
if (schema.format === 'hidden') {
|
|
128
|
-
return 'hidden';
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Check for heavy editor formats that need registration
|
|
132
|
-
if (schema.format === 'json' || schema.format === 'code') {
|
|
133
|
-
return 'code-editor-fallback';
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (schema.format === 'markdown') {
|
|
137
|
-
return 'markdown-editor-fallback';
|
|
138
|
-
}
|
|
11
|
+
import FieldFactory from './FieldFactory.svelte';
|
|
139
12
|
|
|
140
|
-
|
|
141
|
-
return 'template-editor-fallback';
|
|
142
|
-
}
|
|
13
|
+
import type { FormFieldFactoryProps } from './types.js';
|
|
143
14
|
|
|
144
|
-
|
|
145
|
-
if (schema.format === 'ports') {
|
|
146
|
-
return 'ports';
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Object type without specific format would use code editor
|
|
150
|
-
if (schema.type === 'object' && !schema.format) {
|
|
151
|
-
return 'code-editor-fallback';
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// Shared basic field resolution (enum/oneOf/primitive types).
|
|
155
|
-
const base = resolveBaseFieldType(schema);
|
|
156
|
-
if (base) {
|
|
157
|
-
return base;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Fallback to text
|
|
161
|
-
return 'text';
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Get enum options as string array for select/checkbox components
|
|
166
|
-
*/
|
|
167
|
-
const enumOptions = $derived.by((): string[] => {
|
|
168
|
-
if (!schema.enum) return [];
|
|
169
|
-
return schema.enum.map((opt) => String(opt));
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Get select options for select-options type
|
|
174
|
-
* Handles both oneOf (standard) and options (legacy) patterns
|
|
175
|
-
*/
|
|
176
|
-
const selectOptions = $derived(getSchemaOptions(schema));
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Get current value as the appropriate type
|
|
180
|
-
*/
|
|
181
|
-
const stringValue = $derived(String(value ?? ''));
|
|
182
|
-
const numberValue = $derived(value as number | string);
|
|
183
|
-
const booleanValue = $derived(Boolean(value ?? schema.default ?? false));
|
|
184
|
-
const arrayValue = $derived.by((): string[] => {
|
|
185
|
-
if (Array.isArray(value)) {
|
|
186
|
-
return value.map((v) => String(v));
|
|
187
|
-
}
|
|
188
|
-
return [];
|
|
189
|
-
});
|
|
190
|
-
const arrayItems = $derived.by((): unknown[] => {
|
|
191
|
-
if (Array.isArray(value)) {
|
|
192
|
-
return value;
|
|
193
|
-
}
|
|
194
|
-
return [];
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Get helpful message for missing editor registration
|
|
199
|
-
*/
|
|
200
|
-
function getEditorHint(editorType: string): string {
|
|
201
|
-
switch (editorType) {
|
|
202
|
-
case 'code-editor-fallback':
|
|
203
|
-
return "Code editor not registered. Register it on the instance's field registry: import { registerCodeEditorField } from '@flowdrop/flowdrop/form/code'; registerCodeEditorField(instance.fields);";
|
|
204
|
-
case 'markdown-editor-fallback':
|
|
205
|
-
return "Markdown editor not registered. Register it on the instance's field registry: import { registerMarkdownEditorField } from '@flowdrop/flowdrop/form/markdown'; registerMarkdownEditorField(instance.fields);";
|
|
206
|
-
case 'template-editor-fallback':
|
|
207
|
-
return "Template editor not registered. Register it on the instance's field registry: import { registerTemplateEditorField } from '@flowdrop/flowdrop/form/code'; registerTemplateEditorField(instance.fields);";
|
|
208
|
-
default:
|
|
209
|
-
return 'This field type requires additional registration.';
|
|
210
|
-
}
|
|
211
|
-
}
|
|
15
|
+
let props: FormFieldFactoryProps = $props();
|
|
212
16
|
</script>
|
|
213
17
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
id={fieldKey}
|
|
217
|
-
label={fieldLabel}
|
|
218
|
-
{required}
|
|
219
|
-
description={schema.title ? schema.description : undefined}
|
|
220
|
-
{animationDelay}
|
|
221
|
-
>
|
|
222
|
-
{#if fieldType === 'registered' && registeredComponent}
|
|
223
|
-
<!-- Render registered custom component -->
|
|
224
|
-
<!-- darkTheme: use schema value if explicitly set, otherwise derive from resolved theme -->
|
|
225
|
-
<registeredComponent.component
|
|
226
|
-
id={fieldKey}
|
|
227
|
-
{value}
|
|
228
|
-
placeholder={schema.placeholder ?? ''}
|
|
229
|
-
{required}
|
|
230
|
-
ariaDescribedBy={descriptionId}
|
|
231
|
-
height={schema.height as string | undefined}
|
|
232
|
-
darkTheme={schema.darkTheme ?? getResolvedTheme() === 'dark'}
|
|
233
|
-
autoFormat={schema.autoFormat as boolean | undefined}
|
|
234
|
-
showToolbar={schema.showToolbar as boolean | undefined}
|
|
235
|
-
showStatusBar={schema.showStatusBar as boolean | undefined}
|
|
236
|
-
spellChecker={schema.spellChecker as boolean | undefined}
|
|
237
|
-
variables={schema.variables}
|
|
238
|
-
placeholderExample={schema.placeholderExample as string | undefined}
|
|
239
|
-
autocomplete={schema.autocomplete}
|
|
240
|
-
{node}
|
|
241
|
-
{nodes}
|
|
242
|
-
{edges}
|
|
243
|
-
{workflowId}
|
|
244
|
-
{authProvider}
|
|
245
|
-
onChange={(val: unknown) => onChange(val)}
|
|
246
|
-
/>
|
|
247
|
-
{:else if fieldType === 'checkbox-group'}
|
|
248
|
-
<FormCheckboxGroup
|
|
249
|
-
id={fieldKey}
|
|
250
|
-
value={arrayValue}
|
|
251
|
-
options={enumOptions}
|
|
252
|
-
ariaDescribedBy={descriptionId}
|
|
253
|
-
onChange={(val) => onChange(val)}
|
|
254
|
-
/>
|
|
255
|
-
{:else if fieldType === 'select-enum'}
|
|
256
|
-
<FormSelect
|
|
257
|
-
id={fieldKey}
|
|
258
|
-
value={stringValue}
|
|
259
|
-
options={enumOptions}
|
|
260
|
-
{required}
|
|
261
|
-
ariaDescribedBy={descriptionId}
|
|
262
|
-
onChange={(val) => onChange(val)}
|
|
263
|
-
/>
|
|
264
|
-
{:else if fieldType === 'textarea'}
|
|
265
|
-
<FormTextarea
|
|
266
|
-
id={fieldKey}
|
|
267
|
-
value={stringValue}
|
|
268
|
-
placeholder={schema.placeholder ?? ''}
|
|
269
|
-
{required}
|
|
270
|
-
ariaDescribedBy={descriptionId}
|
|
271
|
-
onChange={(val) => onChange(val)}
|
|
272
|
-
/>
|
|
273
|
-
{:else if fieldType === 'text'}
|
|
274
|
-
<FormTextField
|
|
275
|
-
id={fieldKey}
|
|
276
|
-
value={stringValue}
|
|
277
|
-
placeholder={schema.placeholder ?? ''}
|
|
278
|
-
{required}
|
|
279
|
-
ariaDescribedBy={descriptionId}
|
|
280
|
-
onChange={(val) => onChange(val)}
|
|
281
|
-
/>
|
|
282
|
-
{:else if fieldType === 'number'}
|
|
283
|
-
<FormNumberField
|
|
284
|
-
id={fieldKey}
|
|
285
|
-
value={numberValue}
|
|
286
|
-
placeholder={schema.placeholder ?? ''}
|
|
287
|
-
min={schema.minimum}
|
|
288
|
-
max={schema.maximum}
|
|
289
|
-
{required}
|
|
290
|
-
ariaDescribedBy={descriptionId}
|
|
291
|
-
onChange={(val) => onChange(val)}
|
|
292
|
-
/>
|
|
293
|
-
{:else if fieldType === 'range'}
|
|
294
|
-
<FormRangeField
|
|
295
|
-
id={fieldKey}
|
|
296
|
-
value={numberValue}
|
|
297
|
-
min={schema.minimum}
|
|
298
|
-
max={schema.maximum}
|
|
299
|
-
step={schema.step}
|
|
300
|
-
{required}
|
|
301
|
-
ariaDescribedBy={descriptionId}
|
|
302
|
-
onChange={(val) => onChange(val)}
|
|
303
|
-
/>
|
|
304
|
-
{:else if fieldType === 'toggle'}
|
|
305
|
-
<FormToggle
|
|
306
|
-
id={fieldKey}
|
|
307
|
-
value={booleanValue}
|
|
308
|
-
ariaDescribedBy={descriptionId}
|
|
309
|
-
onChange={(val) => onChange(val)}
|
|
310
|
-
/>
|
|
311
|
-
{:else if fieldType === 'select-options'}
|
|
312
|
-
<FormSelect
|
|
313
|
-
id={fieldKey}
|
|
314
|
-
value={stringValue}
|
|
315
|
-
options={selectOptions}
|
|
316
|
-
{required}
|
|
317
|
-
ariaDescribedBy={descriptionId}
|
|
318
|
-
onChange={(val) => onChange(val)}
|
|
319
|
-
/>
|
|
320
|
-
{:else if fieldType === 'array' && schema.items}
|
|
321
|
-
<FormArray
|
|
322
|
-
id={fieldKey}
|
|
323
|
-
value={arrayItems}
|
|
324
|
-
itemSchema={schema.items}
|
|
325
|
-
minItems={schema.minItems}
|
|
326
|
-
maxItems={schema.maxItems}
|
|
327
|
-
addLabel={`Add ${schema.items.title ?? 'Item'}`}
|
|
328
|
-
onChange={(val) => onChange(val)}
|
|
329
|
-
/>
|
|
330
|
-
{:else if fieldType === 'ports'}
|
|
331
|
-
<FormPorts
|
|
332
|
-
id={fieldKey}
|
|
333
|
-
{value}
|
|
334
|
-
ariaDescribedBy={descriptionId}
|
|
335
|
-
{node}
|
|
336
|
-
onChange={(val) => onChange(val)}
|
|
337
|
-
/>
|
|
338
|
-
{:else if fieldType.endsWith('-fallback')}
|
|
339
|
-
<!-- Fallback for unregistered heavy editors -->
|
|
340
|
-
<div class="form-field-fallback">
|
|
341
|
-
<div class="form-field-fallback__message">
|
|
342
|
-
<svg
|
|
343
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
344
|
-
viewBox="0 0 20 20"
|
|
345
|
-
fill="currentColor"
|
|
346
|
-
class="form-field-fallback__icon"
|
|
347
|
-
>
|
|
348
|
-
<path
|
|
349
|
-
fill-rule="evenodd"
|
|
350
|
-
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"
|
|
351
|
-
clip-rule="evenodd"
|
|
352
|
-
/>
|
|
353
|
-
</svg>
|
|
354
|
-
<span>Editor component not registered</span>
|
|
355
|
-
</div>
|
|
356
|
-
<p class="form-field-fallback__hint">
|
|
357
|
-
{getEditorHint(fieldType)}
|
|
358
|
-
</p>
|
|
359
|
-
<!-- Provide a basic textarea fallback for editing -->
|
|
360
|
-
<FormTextarea
|
|
361
|
-
id={fieldKey}
|
|
362
|
-
value={typeof value === 'string' ? value : JSON.stringify(value, null, 2)}
|
|
363
|
-
placeholder={schema.placeholder ?? 'Enter value...'}
|
|
364
|
-
{required}
|
|
365
|
-
ariaDescribedBy={descriptionId}
|
|
366
|
-
onChange={(val) => {
|
|
367
|
-
// Try to parse as JSON for object types
|
|
368
|
-
if (schema.type === 'object' || schema.format === 'json') {
|
|
369
|
-
try {
|
|
370
|
-
onChange(JSON.parse(val));
|
|
371
|
-
} catch {
|
|
372
|
-
onChange(val);
|
|
373
|
-
}
|
|
374
|
-
} else {
|
|
375
|
-
onChange(val);
|
|
376
|
-
}
|
|
377
|
-
}}
|
|
378
|
-
/>
|
|
379
|
-
</div>
|
|
380
|
-
{:else}
|
|
381
|
-
<!-- Fallback to text input -->
|
|
382
|
-
<FormTextField
|
|
383
|
-
id={fieldKey}
|
|
384
|
-
value={stringValue}
|
|
385
|
-
placeholder={schema.placeholder ?? ''}
|
|
386
|
-
ariaDescribedBy={descriptionId}
|
|
387
|
-
onChange={(val) => onChange(val)}
|
|
388
|
-
/>
|
|
389
|
-
{/if}
|
|
390
|
-
</FormFieldWrapper>
|
|
391
|
-
{/if}
|
|
392
|
-
|
|
393
|
-
<style>
|
|
394
|
-
.form-field-fallback {
|
|
395
|
-
display: flex;
|
|
396
|
-
flex-direction: column;
|
|
397
|
-
gap: 0.5rem;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
.form-field-fallback__message {
|
|
401
|
-
display: flex;
|
|
402
|
-
align-items: center;
|
|
403
|
-
gap: 0.5rem;
|
|
404
|
-
padding: 0.5rem 0.75rem;
|
|
405
|
-
background-color: var(--fd-warning-muted);
|
|
406
|
-
border: 1px solid var(--fd-warning);
|
|
407
|
-
border-radius: var(--fd-radius-md);
|
|
408
|
-
color: var(--fd-warning-hover);
|
|
409
|
-
font-size: 0.8125rem;
|
|
410
|
-
font-weight: 500;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
.form-field-fallback__icon {
|
|
414
|
-
width: 1rem;
|
|
415
|
-
height: 1rem;
|
|
416
|
-
flex-shrink: 0;
|
|
417
|
-
color: var(--fd-warning);
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
.form-field-fallback__hint {
|
|
421
|
-
margin: 0;
|
|
422
|
-
padding: 0.5rem 0.75rem;
|
|
423
|
-
background-color: var(--fd-muted);
|
|
424
|
-
border: 1px solid var(--fd-border);
|
|
425
|
-
border-radius: var(--fd-radius-md);
|
|
426
|
-
font-family: 'JetBrains Mono', 'Fira Code', 'Monaco', 'Menlo', monospace;
|
|
427
|
-
font-size: 0.6875rem;
|
|
428
|
-
line-height: 1.5;
|
|
429
|
-
color: var(--fd-muted-foreground);
|
|
430
|
-
word-break: break-word;
|
|
431
|
-
}
|
|
432
|
-
</style>
|
|
18
|
+
<!-- editors after the spread: an untyped caller cannot pass them through -->
|
|
19
|
+
<FieldFactory {...props} editors={undefined} />
|
|
@@ -1,30 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
import type { AuthProvider } from '../../types/auth.js';
|
|
4
|
-
interface Props {
|
|
5
|
-
/** Unique key/id for the field */
|
|
6
|
-
fieldKey: string;
|
|
7
|
-
/** Field schema definition */
|
|
8
|
-
schema: FieldSchema;
|
|
9
|
-
/** Current field value */
|
|
10
|
-
value: unknown;
|
|
11
|
-
/** Whether the field is required */
|
|
12
|
-
required?: boolean;
|
|
13
|
-
/** Animation delay index for staggered animations */
|
|
14
|
-
animationIndex?: number;
|
|
15
|
-
/** Current workflow node (optional, forwarded to registered editors for template variable API mode) */
|
|
16
|
-
node?: WorkflowNode;
|
|
17
|
-
/** All workflow nodes (optional, forwarded to registered editors for port-derived variables) */
|
|
18
|
-
nodes?: WorkflowNode[];
|
|
19
|
-
/** All workflow edges (optional, forwarded to registered editors for port-derived variables) */
|
|
20
|
-
edges?: WorkflowEdge[];
|
|
21
|
-
/** Workflow ID (optional, forwarded to registered editors for template variable API mode) */
|
|
22
|
-
workflowId?: string;
|
|
23
|
-
/** Auth provider (optional, forwarded to registered editors for API requests) */
|
|
24
|
-
authProvider?: AuthProvider;
|
|
25
|
-
/** Callback when the field value changes */
|
|
26
|
-
onChange: (value: unknown) => void;
|
|
27
|
-
}
|
|
28
|
-
declare const FormFieldLight: import("svelte").Component<Props, {}, "">;
|
|
1
|
+
import type { FormFieldFactoryProps } from './types.js';
|
|
2
|
+
declare const FormFieldLight: import("svelte").Component<FormFieldFactoryProps, {}, "">;
|
|
29
3
|
type FormFieldLight = ReturnType<typeof FormFieldLight>;
|
|
30
4
|
export default FormFieldLight;
|
|
@@ -75,6 +75,13 @@
|
|
|
75
75
|
onChange
|
|
76
76
|
}: Props = $props();
|
|
77
77
|
|
|
78
|
+
/**
|
|
79
|
+
* The value as editor text. Registered editors get the raw config value,
|
|
80
|
+
* which is not always a string (null for an unset field, a number from a
|
|
81
|
+
* mistyped schema); CodeMirror throws on anything but a string.
|
|
82
|
+
*/
|
|
83
|
+
const text = $derived(typeof value === 'string' ? value : value == null ? '' : String(value));
|
|
84
|
+
|
|
78
85
|
/** Reference to the editor container element */
|
|
79
86
|
let containerRef: HTMLDivElement | undefined = $state(undefined);
|
|
80
87
|
|
|
@@ -426,7 +433,7 @@
|
|
|
426
433
|
if (!containerRef) return;
|
|
427
434
|
|
|
428
435
|
// Load autosaved content if available
|
|
429
|
-
let initialContent =
|
|
436
|
+
let initialContent = text;
|
|
430
437
|
if (autosave) {
|
|
431
438
|
try {
|
|
432
439
|
const saved = localStorage.getItem(`flowdrop-markdown-${id}`);
|
|
@@ -468,13 +475,13 @@
|
|
|
468
475
|
}
|
|
469
476
|
|
|
470
477
|
const currentContent = editorView.state.doc.toString();
|
|
471
|
-
if (
|
|
478
|
+
if (text !== currentContent && !isInternalUpdate) {
|
|
472
479
|
isInternalUpdate = true;
|
|
473
480
|
editorView.dispatch({
|
|
474
481
|
changes: {
|
|
475
482
|
from: 0,
|
|
476
483
|
to: editorView.state.doc.length,
|
|
477
|
-
insert:
|
|
484
|
+
insert: text
|
|
478
485
|
}
|
|
479
486
|
});
|
|
480
487
|
isInternalUpdate = false;
|
|
@@ -515,7 +522,7 @@
|
|
|
515
522
|
type="hidden"
|
|
516
523
|
{id}
|
|
517
524
|
name={id}
|
|
518
|
-
{
|
|
525
|
+
value={text}
|
|
519
526
|
aria-describedby={ariaDescribedBy}
|
|
520
527
|
aria-required={required}
|
|
521
528
|
/>
|
|
@@ -107,6 +107,13 @@
|
|
|
107
107
|
authProvider
|
|
108
108
|
}: Props = $props();
|
|
109
109
|
|
|
110
|
+
/**
|
|
111
|
+
* The value as editor text. Registered editors get the raw config value,
|
|
112
|
+
* which is not always a string (null for an unset field, a number from a
|
|
113
|
+
* mistyped schema); CodeMirror throws on anything but a string.
|
|
114
|
+
*/
|
|
115
|
+
const text = $derived(typeof value === 'string' ? value : value == null ? '' : String(value));
|
|
116
|
+
|
|
110
117
|
// Active instance — supplies endpoint configuration for API variable fetching.
|
|
111
118
|
const fd = getInstance();
|
|
112
119
|
|
|
@@ -434,7 +441,7 @@
|
|
|
434
441
|
// Then create editor with loaded schema
|
|
435
442
|
editorView = new EditorView({
|
|
436
443
|
state: EditorState.create({
|
|
437
|
-
doc:
|
|
444
|
+
doc: text,
|
|
438
445
|
extensions: createExtensions()
|
|
439
446
|
}),
|
|
440
447
|
parent: containerRef
|
|
@@ -462,13 +469,13 @@
|
|
|
462
469
|
const currentContent = editorView.state.doc.toString();
|
|
463
470
|
|
|
464
471
|
// Only update if content actually changed and wasn't from internal edit
|
|
465
|
-
if (
|
|
472
|
+
if (text !== currentContent && !isInternalUpdate) {
|
|
466
473
|
isInternalUpdate = true;
|
|
467
474
|
editorView.dispatch({
|
|
468
475
|
changes: {
|
|
469
476
|
from: 0,
|
|
470
477
|
to: editorView.state.doc.length,
|
|
471
|
-
insert:
|
|
478
|
+
insert: text
|
|
472
479
|
}
|
|
473
480
|
});
|
|
474
481
|
isInternalUpdate = false;
|
|
@@ -502,7 +509,7 @@
|
|
|
502
509
|
type="hidden"
|
|
503
510
|
{id}
|
|
504
511
|
name={id}
|
|
505
|
-
{
|
|
512
|
+
value={text}
|
|
506
513
|
aria-describedby={ariaDescribedBy}
|
|
507
514
|
aria-required={required}
|
|
508
515
|
/>
|
|
@@ -585,7 +592,7 @@
|
|
|
585
592
|
{/if}
|
|
586
593
|
|
|
587
594
|
<!-- Placeholder hint when empty -->
|
|
588
|
-
{#if !
|
|
595
|
+
{#if !text && placeholderExample}
|
|
589
596
|
<div class="form-template-editor__placeholder">
|
|
590
597
|
<span class="form-template-editor__placeholder-label">Example template:</span>
|
|
591
598
|
<code class="form-template-editor__placeholder-example">{placeholderExample}</code>
|
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
import type { FieldSchema } from './types.js';
|
|
2
2
|
/**
|
|
3
|
-
* The dependency-free field kinds that
|
|
4
|
-
*
|
|
5
|
-
* pull in a heavy editor or depend on the field registry.
|
|
3
|
+
* The dependency-free field kinds — everything that does not pull in a heavy
|
|
4
|
+
* editor or depend on the field registry.
|
|
6
5
|
*/
|
|
7
6
|
export type BaseFieldType = 'checkbox-group' | 'select-enum' | 'select-options' | 'textarea' | 'range' | 'text' | 'number' | 'toggle' | 'array';
|
|
8
7
|
/**
|
|
9
|
-
* Resolve the basic field type for a schema
|
|
10
|
-
* the decision both the full and light field factories share.
|
|
8
|
+
* Resolve the basic field type for a schema.
|
|
11
9
|
*
|
|
12
|
-
* Returns `null` when none of the basic cases match, so
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* NOT decided here: `FormField` and `FormFieldLight` route those differently
|
|
17
|
-
* (static imports vs. the lazy field registry that keeps the `/form` light
|
|
18
|
-
* entry free of heavy deps), and must keep doing so before delegating here.
|
|
10
|
+
* Returns `null` when none of the basic cases match, so the caller applies its
|
|
11
|
+
* own special cases (hidden, autocomplete, ports, heavy editors, registry
|
|
12
|
+
* overrides) first and its fallback last. Its one caller is the internal
|
|
13
|
+
* `FieldFactory`, which both `FormFieldLight` and `FormFieldFull` render.
|
|
19
14
|
*
|
|
20
|
-
* Order matters and
|
|
21
|
-
*
|
|
22
|
-
* schemas frequently carry `type: 'string'`.
|
|
15
|
+
* Order matters: `enum` and `oneOf` are checked before the primitive `type`
|
|
16
|
+
* branches because option schemas frequently carry `type: 'string'`.
|
|
23
17
|
*/
|
|
24
18
|
export declare function resolveBaseFieldType(schema: FieldSchema): BaseFieldType | null;
|
|
19
|
+
/** The editors too heavy for the light `/form` entry (CodeMirror and friends). */
|
|
20
|
+
export type HeavyEditorKind = 'code-editor' | 'markdown-editor' | 'template-editor';
|
|
21
|
+
/**
|
|
22
|
+
* Which heavy editor a schema asks for, or `null` for none. The light factory
|
|
23
|
+
* renders it from the field registry, or from the statically bundled set that
|
|
24
|
+
* `FormFieldFull` passes in, or as a plain textarea with a registration hint.
|
|
25
|
+
* A registered component for the schema wins before this is consulted.
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveHeavyEditorKind(schema: FieldSchema): HeavyEditorKind | null;
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Resolve the basic field type for a schema
|
|
3
|
-
* the decision both the full and light field factories share.
|
|
2
|
+
* Resolve the basic field type for a schema.
|
|
4
3
|
*
|
|
5
|
-
* Returns `null` when none of the basic cases match, so
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* NOT decided here: `FormField` and `FormFieldLight` route those differently
|
|
10
|
-
* (static imports vs. the lazy field registry that keeps the `/form` light
|
|
11
|
-
* entry free of heavy deps), and must keep doing so before delegating here.
|
|
4
|
+
* Returns `null` when none of the basic cases match, so the caller applies its
|
|
5
|
+
* own special cases (hidden, autocomplete, ports, heavy editors, registry
|
|
6
|
+
* overrides) first and its fallback last. Its one caller is the internal
|
|
7
|
+
* `FieldFactory`, which both `FormFieldLight` and `FormFieldFull` render.
|
|
12
8
|
*
|
|
13
|
-
* Order matters and
|
|
14
|
-
*
|
|
15
|
-
* schemas frequently carry `type: 'string'`.
|
|
9
|
+
* Order matters: `enum` and `oneOf` are checked before the primitive `type`
|
|
10
|
+
* branches because option schemas frequently carry `type: 'string'`.
|
|
16
11
|
*/
|
|
17
12
|
export function resolveBaseFieldType(schema) {
|
|
18
13
|
// Enum with multiple selection -> checkbox group
|
|
@@ -53,3 +48,29 @@ export function resolveBaseFieldType(schema) {
|
|
|
53
48
|
}
|
|
54
49
|
return null;
|
|
55
50
|
}
|
|
51
|
+
/** Formats the factory renders itself even on an `object` (`ports` is one). */
|
|
52
|
+
const OBJECT_FORMATS_WITH_OWN_FIELD = new Set(['hidden', 'autocomplete', 'ports']);
|
|
53
|
+
/**
|
|
54
|
+
* Which heavy editor a schema asks for, or `null` for none. The light factory
|
|
55
|
+
* renders it from the field registry, or from the statically bundled set that
|
|
56
|
+
* `FormFieldFull` passes in, or as a plain textarea with a registration hint.
|
|
57
|
+
* A registered component for the schema wins before this is consulted.
|
|
58
|
+
*/
|
|
59
|
+
export function resolveHeavyEditorKind(schema) {
|
|
60
|
+
if (schema.format === 'json' || schema.format === 'code') {
|
|
61
|
+
return 'code-editor';
|
|
62
|
+
}
|
|
63
|
+
if (schema.format === 'markdown') {
|
|
64
|
+
return 'markdown-editor';
|
|
65
|
+
}
|
|
66
|
+
if (schema.format === 'template') {
|
|
67
|
+
return 'template-editor';
|
|
68
|
+
}
|
|
69
|
+
// An object is edited as JSON unless its format is one the factory renders
|
|
70
|
+
// itself. An unknown format must not fall through to a text field, which
|
|
71
|
+
// would show "[object Object]" and save a string over the object.
|
|
72
|
+
if (schema.type === 'object' && !OBJECT_FORMATS_WITH_OWN_FIELD.has(schema.format ?? '')) {
|
|
73
|
+
return 'code-editor';
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|