@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
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,46 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.9.0] - 2026-10-04
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Autocomplete config fields (`format: 'autocomplete'` with `autocomplete.url`)
|
|
13
|
+
render as autocompletes again in the node config panel and `SchemaForm`.
|
|
14
|
+
They had been plain text boxes since 2.0.0-beta.2, when both moved to
|
|
15
|
+
`FormFieldLight`, which had no built-in fallback; a registered override on
|
|
16
|
+
`fd.fields` still wins.
|
|
17
|
+
- `readOnly: true` on a config field now disables it in the node config panel
|
|
18
|
+
and `SchemaForm`. `FormFieldLight` never passed `disabled` on, so read-only
|
|
19
|
+
fields were editable; it now reaches every built-in field, the textarea
|
|
20
|
+
fallback for an unregistered editor, and registered components (as the
|
|
21
|
+
`disabled` prop). Hosts that marked fields `readOnly` but relied on editing
|
|
22
|
+
them will find them locked.
|
|
23
|
+
- Number fields honour `step` in the node config panel and `SchemaForm`.
|
|
24
|
+
- An `object` field whose `format` the form does not render itself (anything
|
|
25
|
+
but `hidden`, `autocomplete` and `ports`) gets the JSON editor. It used to
|
|
26
|
+
fall through to a text field that showed `[object Object]` and saved a string
|
|
27
|
+
over the object on the first keystroke.
|
|
28
|
+
- The markdown and template editors accept a value that is not a string:
|
|
29
|
+
`null` shows an empty editor and a number its text, where a number used to
|
|
30
|
+
throw from CodeMirror (`(config.doc || "").split is not a function`).
|
|
31
|
+
`FormFieldFull` used to coerce the value before handing it over; it now
|
|
32
|
+
reaches the editors as stored, as it always did in the config panel.
|
|
33
|
+
|
|
34
|
+
### Changed
|
|
35
|
+
|
|
36
|
+
- **`FormFieldFull`** (`@flowdrop/flowdrop/form/full`) and `FormField`
|
|
37
|
+
(`@flowdrop/flowdrop/form`) now render through one internal field factory;
|
|
38
|
+
`FormFieldFull` only adds the bundled code, markdown and template editors.
|
|
39
|
+
They used to be two copies of the factory, and the copies had drifted, which
|
|
40
|
+
is how the autocomplete and `readOnly` bugs above shipped. One behaviour
|
|
41
|
+
difference for `FormFieldFull` users: a component registered on `fd.fields`
|
|
42
|
+
now wins for every field, as it always did for `FormField`, where before
|
|
43
|
+
`FormFieldFull` consulted the registry only for autocomplete fields. Neither
|
|
44
|
+
component gained or lost a prop; their props type, `FormFieldFactoryProps`,
|
|
45
|
+
now also lists `node`, `nodes`, `edges`, `workflowId` and `authProvider`,
|
|
46
|
+
which both always accepted.
|
|
47
|
+
|
|
8
48
|
## [2.8.0] - 2026-09-10
|
|
9
49
|
|
|
10
50
|
### Added
|
|
@@ -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;
|