@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.
Files changed (99) hide show
  1. package/CHANGELOG.md +227 -0
  2. package/dist/commands/executor.js +52 -8
  3. package/dist/commands/types.d.ts +3 -0
  4. package/dist/components/App.svelte +8 -0
  5. package/dist/components/App.svelte.d.ts +6 -0
  6. package/dist/components/CanvasContextMenu.stories.svelte +63 -0
  7. package/dist/components/CanvasContextMenu.stories.svelte.d.ts +19 -0
  8. package/dist/components/CanvasContextMenu.svelte +259 -0
  9. package/dist/components/CanvasContextMenu.svelte.d.ts +16 -0
  10. package/dist/components/CanvasController.svelte +23 -1
  11. package/dist/components/CanvasController.svelte.d.ts +16 -0
  12. package/dist/components/UniversalNode.svelte +12 -13
  13. package/dist/components/WorkflowEditor.svelte +364 -27
  14. package/dist/components/WorkflowEditor.svelte.d.ts +7 -0
  15. package/dist/components/WorkflowInterfaceEditor.svelte +28 -3
  16. package/dist/components/WorkflowInterfaceEntryCard.svelte +112 -2
  17. package/dist/components/WorkflowInterfaceEntryCard.svelte.d.ts +3 -1
  18. package/dist/components/form/FieldFactory.svelte +478 -0
  19. package/dist/components/form/FieldFactory.svelte.d.ts +14 -0
  20. package/dist/components/form/FormField.svelte +19 -404
  21. package/dist/components/form/FormField.svelte.d.ts +2 -27
  22. package/dist/components/form/FormFieldLight.svelte +11 -424
  23. package/dist/components/form/FormFieldLight.svelte.d.ts +2 -28
  24. package/dist/components/form/FormMarkdownEditor.svelte +11 -4
  25. package/dist/components/form/FormTemplateEditor.svelte +12 -5
  26. package/dist/components/form/resolveFieldType.d.ts +18 -15
  27. package/dist/components/form/resolveFieldType.js +33 -12
  28. package/dist/components/form/types.d.ts +14 -2
  29. package/dist/components/nodes/CaptionNode.stories.svelte +65 -0
  30. package/dist/components/nodes/CaptionNode.stories.svelte.d.ts +18 -0
  31. package/dist/components/nodes/CaptionNode.svelte +313 -0
  32. package/dist/components/nodes/CaptionNode.svelte.d.ts +16 -0
  33. package/dist/components/nodes/NotesNode.svelte +6 -0
  34. package/dist/components/playground/ChatBubble.svelte +2 -0
  35. package/dist/components/playground/ChatInput.svelte +18 -34
  36. package/dist/components/playground/ChatInput.svelte.d.ts +7 -0
  37. package/dist/components/playground/ControlPanel.svelte +27 -0
  38. package/dist/components/playground/ControlPanel.svelte.d.ts +12 -0
  39. package/dist/components/playground/ExecutionLogs.svelte +11 -8
  40. package/dist/components/playground/InterfaceInputForm.svelte +74 -0
  41. package/dist/components/playground/InterfaceInputForm.svelte.d.ts +14 -0
  42. package/dist/components/playground/LogRow.svelte +2 -0
  43. package/dist/components/playground/MessageCard.svelte +15 -3
  44. package/dist/components/playground/MessageNotice.svelte +2 -0
  45. package/dist/components/playground/MessageStream.svelte +87 -23
  46. package/dist/components/playground/OriginBadge.svelte +48 -0
  47. package/dist/components/playground/OriginBadge.svelte.d.ts +7 -0
  48. package/dist/components/playground/Playground.svelte +155 -38
  49. package/dist/components/playground/messageDisplay.d.ts +23 -1
  50. package/dist/components/playground/messageDisplay.js +49 -0
  51. package/dist/config/endpoints.d.ts +65 -0
  52. package/dist/config/endpoints.js +39 -0
  53. package/dist/core/index.d.ts +6 -3
  54. package/dist/core/index.js +2 -1
  55. package/dist/editor/contextMenu.d.ts +107 -0
  56. package/dist/editor/contextMenu.js +134 -0
  57. package/dist/editor/index.d.ts +2 -0
  58. package/dist/editor/index.js +1 -0
  59. package/dist/index.d.ts +1 -1
  60. package/dist/index.js +1 -1
  61. package/dist/messages/defaults.d.ts +63 -0
  62. package/dist/messages/defaults.js +59 -0
  63. package/dist/openapi/v1/openapi.yaml +356 -7
  64. package/dist/playground/commands/registry.js +4 -2
  65. package/dist/playground/index.d.ts +3 -2
  66. package/dist/playground/index.js +2 -1
  67. package/dist/registry/builtinNodeTypes.d.ts +1 -1
  68. package/dist/registry/builtinNodeTypes.js +1 -0
  69. package/dist/registry/builtinNodes.js +13 -0
  70. package/dist/registry/nodeComponentRegistry.d.ts +18 -0
  71. package/dist/registry/nodeComponentRegistry.js +14 -2
  72. package/dist/schemas/v1/workflow.schema.json +22 -1
  73. package/dist/services/historyService.d.ts +1 -1
  74. package/dist/services/historyService.js +2 -2
  75. package/dist/services/playgroundService.d.ts +35 -1
  76. package/dist/services/playgroundService.js +82 -36
  77. package/dist/stores/inlineEditStore.svelte.d.ts +35 -0
  78. package/dist/stores/inlineEditStore.svelte.js +63 -0
  79. package/dist/stores/instanceContainer.svelte.d.ts +6 -0
  80. package/dist/stores/instanceContainer.svelte.js +2 -0
  81. package/dist/stores/playgroundStore.svelte.d.ts +59 -2
  82. package/dist/stores/playgroundStore.svelte.js +128 -2
  83. package/dist/styles/base.css +8 -0
  84. package/dist/styles/tokens.css +8 -0
  85. package/dist/svelte-app.d.ts +15 -0
  86. package/dist/svelte-app.js +6 -4
  87. package/dist/types/index.d.ts +34 -1
  88. package/dist/types/index.js +11 -0
  89. package/dist/types/playground.d.ts +90 -9
  90. package/dist/types/playground.js +12 -4
  91. package/dist/utils/captionText.d.ts +43 -0
  92. package/dist/utils/captionText.js +49 -0
  93. package/dist/utils/focus.d.ts +16 -0
  94. package/dist/utils/focus.js +40 -0
  95. package/dist/utils/nodeTypes.js +1 -0
  96. package/dist/utils/nodeWrapper.js +2 -0
  97. package/dist/utils/workflowInterface.d.ts +83 -1
  98. package/dist/utils/workflowInterface.js +192 -1
  99. package/package.json +1 -1
@@ -1,432 +1,19 @@
1
1
  <!--
2
- FormFieldLight Component
3
- Factory component that renders the appropriate field based on schema type.
4
-
5
- This is the "light" version that uses the field registry for heavy components
6
- (code editor, markdown editor, template editor) instead of static imports.
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 FormFieldWrapper from './FormFieldWrapper.svelte';
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
- if (schema.format === 'template') {
141
- return 'template-editor-fallback';
142
- }
13
+ import type { FormFieldFactoryProps } from './types.js';
143
14
 
144
- // Injected port order + exposure widget (the `ports` reserved config prop).
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
- {#if fieldType !== 'hidden'}
215
- <FormFieldWrapper
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 { FieldSchema } from './types.js';
2
- import type { WorkflowNode, WorkflowEdge } from '../../types/index.js';
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 = value;
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 (value !== currentContent && !isInternalUpdate) {
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: value
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
- {value}
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: value,
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 (value !== currentContent && !isInternalUpdate) {
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: value
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
- {value}
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 !value && placeholderExample}
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 {@link FormField} and
4
- * {@link FormFieldLight} render identically — i.e. everything that does not
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 — the single source of truth for
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 each caller can apply
13
- * its OWN special-case handling and fallback in its own order. The heavy and
14
- * entry-point-specific cases (hidden, autocomplete, code/markdown/template
15
- * editors, `object` → editor, registry-resolved components) are deliberately
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 mirrors the original in-component chains: `enum` and
21
- * `oneOf` are checked before the primitive `type` branches because option
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 — the single source of truth for
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 each caller can apply
6
- * its OWN special-case handling and fallback in its own order. The heavy and
7
- * entry-point-specific cases (hidden, autocomplete, code/markdown/template
8
- * editors, `object` → editor, registry-resolved components) are deliberately
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 mirrors the original in-component chains: `enum` and
14
- * `oneOf` are checked before the primitive `type` branches because option
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
+ }