treege 3.0.0-beta.6 → 3.0.0-beta.60

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 (197) hide show
  1. package/LICENSE +18 -12
  2. package/README.md +425 -81
  3. package/dist/DefaultInputs-nRQc9BHG.js +1881 -0
  4. package/dist/ThemeContext-Ddk_Y-Dz.js +1402 -0
  5. package/dist/editor/components/input/ComboboxWithCreate.d.ts +2 -1
  6. package/dist/editor/components/styles/EditorStyles.d.ts +2 -0
  7. package/dist/editor/constants/defaultNode.d.ts +1 -1
  8. package/dist/editor/constants/edgeTypes.d.ts +3 -2
  9. package/dist/editor/constants/inputTypeIcons.d.ts +3 -0
  10. package/dist/editor/constants/nodeSpacing.d.ts +25 -0
  11. package/dist/editor/constants/nodeTypes.d.ts +4 -5
  12. package/dist/editor/context/OpenApiContext.d.ts +79 -0
  13. package/dist/editor/context/TreegeEditorRuntimeProvider.d.ts +78 -0
  14. package/dist/editor/features/TreegeEditor/TreegeEditor.d.ts +1 -1
  15. package/dist/editor/features/TreegeEditor/controls/MiniMapControl.d.ts +6 -0
  16. package/dist/editor/features/TreegeEditor/dialogs/AuthorizeDialog.d.ts +20 -0
  17. package/dist/editor/features/TreegeEditor/dialogs/ChangeNodeTypeDialog.d.ts +2 -0
  18. package/dist/editor/features/TreegeEditor/dialogs/DeleteNodeDialog.d.ts +2 -0
  19. package/dist/editor/features/TreegeEditor/dialogs/HeadersDialog.d.ts +19 -0
  20. package/dist/editor/features/TreegeEditor/dialogs/OpenApiDialog.d.ts +6 -0
  21. package/dist/editor/features/TreegeEditor/edges/ConditionalEdge.d.ts +2 -2
  22. package/dist/editor/features/TreegeEditor/edges/DefaultEdge.d.ts +3 -0
  23. package/dist/editor/features/TreegeEditor/forms/OptionsMappingFields.d.ts +34 -0
  24. package/dist/editor/features/TreegeEditor/forms/OptionsSourceForm.d.ts +7 -0
  25. package/dist/editor/features/TreegeEditor/forms/SensitiveHeaderWarning.d.ts +13 -0
  26. package/dist/editor/features/TreegeEditor/forms/SubmitConfigForm.d.ts +7 -0
  27. package/dist/editor/features/TreegeEditor/inputs/ApiUrlCombobox.d.ts +20 -0
  28. package/dist/editor/features/TreegeEditor/inputs/ComboboxPattern.d.ts +2 -1
  29. package/dist/editor/features/TreegeEditor/inputs/OptionImageField.d.ts +6 -0
  30. package/dist/editor/features/TreegeEditor/inputs/SelectNodeGroup.d.ts +22 -1
  31. package/dist/editor/features/TreegeEditor/layout/AutoLayout.d.ts +15 -0
  32. package/dist/editor/features/TreegeEditor/nodes/TreegeNode.d.ts +5 -0
  33. package/dist/editor/features/TreegeEditor/nodes/components/BottomHandleDropdown.d.ts +25 -0
  34. package/dist/editor/features/TreegeEditor/nodes/components/NodeGroupBadge.d.ts +6 -0
  35. package/dist/editor/features/TreegeEditor/nodes/components/NodeImage.d.ts +5 -0
  36. package/dist/editor/features/TreegeEditor/nodes/components/NodeImageButton.d.ts +6 -0
  37. package/dist/editor/features/TreegeEditor/nodes/components/NodeInputPreview.d.ts +12 -0
  38. package/dist/editor/features/TreegeEditor/nodes/components/NodeLabelInput.d.ts +10 -0
  39. package/dist/editor/features/TreegeEditor/nodes/components/NodeMoreMenu.d.ts +6 -0
  40. package/dist/editor/features/TreegeEditor/nodes/components/NodeRequiredButton.d.ts +6 -0
  41. package/dist/editor/features/TreegeEditor/nodes/components/NodeStackOrderButtons.d.ts +6 -0
  42. package/dist/editor/features/TreegeEditor/nodes/components/NodeTypeBadge.d.ts +7 -0
  43. package/dist/editor/features/TreegeEditor/nodes/components/NodeTypePickerMenuContent.d.ts +12 -0
  44. package/dist/editor/features/TreegeEditor/nodes/layout/NodeWrapper.d.ts +4 -2
  45. package/dist/editor/features/TreegeEditor/panel/AIGeneratorDialog.d.ts +16 -0
  46. package/dist/editor/features/TreegeEditor/panel/ActionsPanel.d.ts +7 -2
  47. package/dist/editor/features/TreegeEditor/panel/MultiSelectionPanel.d.ts +7 -0
  48. package/dist/editor/hooks/useAvailableParentFields.d.ts +13 -0
  49. package/dist/editor/hooks/useFlowActions.d.ts +6 -2
  50. package/dist/editor/hooks/useFlowConnections.d.ts +14 -0
  51. package/dist/editor/hooks/useHistoryStore.d.ts +26 -0
  52. package/dist/editor/hooks/useIsStackedEdge.d.ts +8 -0
  53. package/dist/editor/hooks/useNodesSelection.d.ts +5 -5
  54. package/dist/editor/hooks/useStackPosition.d.ts +14 -0
  55. package/dist/editor/hooks/useTranslate.d.ts +1 -1
  56. package/dist/editor/hooks/useUndoRedo.d.ts +31 -0
  57. package/dist/editor/types/ai.d.ts +65 -0
  58. package/dist/editor/types/editor.d.ts +103 -10
  59. package/dist/editor/types/openapi.d.ts +81 -0
  60. package/dist/editor/utils/aiFlowGenerator.d.ts +5 -0
  61. package/dist/editor/utils/cleanNodeConfig.d.ts +5 -0
  62. package/dist/editor/utils/dagreLayout.d.ts +8 -0
  63. package/dist/editor/utils/edge.d.ts +50 -0
  64. package/dist/editor/utils/groupColor.d.ts +14 -0
  65. package/dist/editor/utils/image.d.ts +7 -0
  66. package/dist/editor/utils/inputTypeIcon.d.ts +6 -0
  67. package/dist/editor/utils/openapi.d.ts +35 -0
  68. package/dist/editor/utils/sensitiveHeaders.d.ts +15 -0
  69. package/dist/editor/utils/stackPositionIndex.d.ts +9 -0
  70. package/dist/editor-D2pBjE7E.js +6251 -0
  71. package/dist/editor.js +3 -7
  72. package/dist/main.js +4 -52
  73. package/dist/renderer/context/TreegeRenderRuntimeProvider.d.ts +135 -0
  74. package/dist/renderer/context/TreegeRendererProvider.d.ts +15 -0
  75. package/dist/renderer/features/TreegeRenderer/InputRendererHost.d.ts +15 -0
  76. package/dist/renderer/features/TreegeRenderer/native/TreegeRenderer.d.ts +19 -11
  77. package/dist/renderer/features/TreegeRenderer/native/components/DefaultFormWrapper.d.ts +7 -7
  78. package/dist/renderer/features/TreegeRenderer/native/components/DefaultInputWrapper.d.ts +9 -0
  79. package/dist/renderer/features/TreegeRenderer/native/components/DefaultInputs.d.ts +21 -15
  80. package/dist/renderer/features/TreegeRenderer/native/components/DefaultLoadingSkeleton.d.ts +8 -0
  81. package/dist/renderer/features/TreegeRenderer/native/components/DefaultStep.d.ts +3 -0
  82. package/dist/renderer/features/TreegeRenderer/native/components/DefaultSubmitButton.d.ts +9 -7
  83. package/dist/renderer/features/TreegeRenderer/native/components/DefaultSubmitButtonWrapper.d.ts +11 -0
  84. package/dist/renderer/features/TreegeRenderer/native/components/DefaultUI.d.ts +8 -7
  85. package/dist/renderer/features/TreegeRenderer/native/components/DependencyHint.d.ts +15 -0
  86. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultAddressInput.d.ts +3 -0
  87. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultAutocompleteInput.d.ts +3 -0
  88. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultCheckboxInput.d.ts +3 -0
  89. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultDateInput.d.ts +3 -0
  90. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultDateRangeInput.d.ts +3 -0
  91. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultFileInput.d.ts +3 -0
  92. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultHiddenInput.d.ts +3 -0
  93. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultHttpInput.d.ts +3 -0
  94. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultNumberInput.d.ts +3 -0
  95. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultPasswordInput.d.ts +3 -0
  96. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultRadioInput.d.ts +3 -0
  97. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultSelectInput.d.ts +3 -0
  98. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultSwitchInput.d.ts +3 -0
  99. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultTextInput.d.ts +3 -0
  100. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultTextareaInput.d.ts +3 -0
  101. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultTimeInput.d.ts +3 -0
  102. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultTimeRangeInput.d.ts +3 -0
  103. package/dist/renderer/features/TreegeRenderer/useTreegeRenderer.d.ts +94 -24
  104. package/dist/renderer/features/TreegeRenderer/web/TreegeRenderer.d.ts +1 -1
  105. package/dist/renderer/features/TreegeRenderer/web/components/DefaultFormWrapper.d.ts +1 -1
  106. package/dist/renderer/features/TreegeRenderer/web/components/DefaultInputWrapper.d.ts +9 -0
  107. package/dist/renderer/features/TreegeRenderer/web/components/DefaultLoadingSkeleton.d.ts +7 -0
  108. package/dist/renderer/features/TreegeRenderer/web/components/DefaultStep.d.ts +3 -0
  109. package/dist/renderer/features/TreegeRenderer/web/components/DefaultSubmitButton.d.ts +1 -1
  110. package/dist/renderer/features/TreegeRenderer/web/components/DependencyHint.d.ts +22 -0
  111. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultAddressInput.d.ts +2 -2
  112. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultAutocompleteInput.d.ts +2 -2
  113. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultCheckboxInput.d.ts +2 -2
  114. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultDateInput.d.ts +2 -2
  115. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultDateRangeInput.d.ts +2 -2
  116. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultFileInput.d.ts +2 -2
  117. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultHiddenInput.d.ts +2 -2
  118. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultHttpInput.d.ts +2 -2
  119. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultNumberInput.d.ts +2 -2
  120. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultPasswordInput.d.ts +2 -2
  121. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultRadioInput.d.ts +2 -2
  122. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultSelectInput.d.ts +2 -2
  123. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultSubmitInput.d.ts +3 -0
  124. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultSwitchInput.d.ts +2 -2
  125. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultTextAreaInput.d.ts +2 -2
  126. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultTextInput.d.ts +2 -2
  127. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultTimeInput.d.ts +2 -2
  128. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultTimeRangeInput.d.ts +2 -2
  129. package/dist/renderer/features/TreegeRenderer/web/components/styles/RendererStyles.d.ts +2 -0
  130. package/dist/renderer/hooks/useInputOptions.d.ts +28 -0
  131. package/dist/renderer/hooks/useRenderNode.d.ts +58 -0
  132. package/dist/renderer/hooks/useSubmitHandler.d.ts +36 -0
  133. package/dist/renderer/hooks/useTranslate.d.ts +7 -5
  134. package/dist/renderer/index.d.ts +4 -2
  135. package/dist/renderer/index.native.d.ts +19 -0
  136. package/dist/renderer/types/renderer.d.ts +208 -41
  137. package/dist/renderer/utils/flow.d.ts +1 -18
  138. package/dist/renderer/utils/form.d.ts +22 -2
  139. package/dist/renderer/utils/http.d.ts +152 -0
  140. package/dist/renderer/utils/node.d.ts +29 -1
  141. package/dist/renderer/utils/sanitize.d.ts +85 -0
  142. package/dist/renderer/utils/sanitize.native.d.ts +69 -0
  143. package/dist/renderer/utils/step.d.ts +27 -0
  144. package/dist/renderer/utils/submit.d.ts +49 -0
  145. package/dist/renderer/utils/templateDependencies.d.ts +17 -0
  146. package/dist/renderer-native.d.ts +2 -0
  147. package/dist/renderer-native.js +3702 -0
  148. package/dist/renderer.js +3 -45
  149. package/dist/shared/components/ui/badge.d.ts +2 -2
  150. package/dist/shared/components/ui/button.d.ts +3 -3
  151. package/dist/shared/components/ui/collapsible.d.ts +1 -1
  152. package/dist/shared/components/ui/command.d.ts +1 -1
  153. package/dist/shared/components/ui/dropdown-menu.d.ts +1 -1
  154. package/dist/shared/components/ui/field.d.ts +24 -0
  155. package/dist/shared/components/ui/form.d.ts +1 -1
  156. package/dist/shared/components/ui/popover.d.ts +4 -2
  157. package/dist/shared/components/ui/select.d.ts +3 -1
  158. package/dist/shared/components/ui/sheet.d.ts +1 -1
  159. package/dist/shared/components/ui/skeleton.d.ts +3 -0
  160. package/dist/shared/components/ui/toggle-group.d.ts +7 -0
  161. package/dist/shared/components/ui/toggle.d.ts +9 -0
  162. package/dist/shared/components/ui/tooltip.d.ts +1 -1
  163. package/dist/shared/constants/colors.d.ts +45 -0
  164. package/dist/shared/constants/inputType.d.ts +6 -0
  165. package/dist/shared/constants/node.d.ts +0 -1
  166. package/dist/shared/context/ThemeContext.d.ts +2 -0
  167. package/dist/shared/context/ThemeContext.native.d.ts +22 -0
  168. package/dist/shared/hooks/useMediaQuery.d.ts +12 -0
  169. package/dist/shared/hooks/useThemeColors.d.ts +37 -0
  170. package/dist/shared/locales/ar.json.d.ts +243 -19
  171. package/dist/shared/locales/de.json.d.ts +244 -20
  172. package/dist/shared/locales/en.json.d.ts +245 -21
  173. package/dist/shared/locales/es.json.d.ts +244 -20
  174. package/dist/shared/locales/fr.json.d.ts +244 -20
  175. package/dist/shared/locales/it.json.d.ts +244 -20
  176. package/dist/shared/locales/pt.json.d.ts +244 -20
  177. package/dist/shared/types/edge.d.ts +6 -0
  178. package/dist/shared/types/node.d.ts +129 -7
  179. package/dist/shared/utils/inputTypeGuards.d.ts +7 -0
  180. package/dist/shared/utils/nodeTypeGuards.d.ts +1 -6
  181. package/package.json +48 -22
  182. package/dist/ThemeContext-BIvs8Kw-.js +0 -758
  183. package/dist/TreegeEditor-Lv5Tn9_F.js +0 -2152
  184. package/dist/TreegeRenderer-D3EvsEfJ.js +0 -1413
  185. package/dist/editor/context/TreegeEditorContext.d.ts +0 -12
  186. package/dist/editor/features/TreegeEditor/forms/FlowNodeForm.d.ts +0 -2
  187. package/dist/editor/features/TreegeEditor/inputs/SelectInputType.d.ts +0 -7
  188. package/dist/editor/features/TreegeEditor/nodes/FlowNode.d.ts +0 -6
  189. package/dist/editor/features/TreegeEditor/nodes/GroupNode.d.ts +0 -6
  190. package/dist/editor/features/TreegeEditor/nodes/InputNode.d.ts +0 -6
  191. package/dist/editor/features/TreegeEditor/nodes/UINode.d.ts +0 -6
  192. package/dist/editor/hooks/useEdgesSelection.d.ts +0 -11
  193. package/dist/renderer/context/TreegeConfigContext.d.ts +0 -39
  194. package/dist/renderer/context/TreegeRendererContext.d.ts +0 -25
  195. package/dist/renderer/features/TreegeRenderer/native/components/DefaultGroup.d.ts +0 -7
  196. package/dist/renderer/features/TreegeRenderer/web/components/DefaultGroup.d.ts +0 -6
  197. /package/dist/editor/components/{data-display/logo.d.ts → branding/Logo.d.ts} +0 -0
@@ -1,7 +1,8 @@
1
1
  import { Node } from '@xyflow/react';
2
2
  import { FormEvent, ReactNode } from 'react';
3
3
  import { SerializableFile } from '../utils/file';
4
- import { Flow, InputNodeData, InputType, TreegeNodeData, UINodeData, UIType } from '../../shared/types/node';
4
+ import { FlowStep } from '../utils/step';
5
+ import { Flow, GroupNodeData, HttpHeader, InputNodeData, InputOption, InputType, TreegeNodeData, UINodeData, UIType } from '../../shared/types/node';
5
6
  /**
6
7
  * Type mapping for input values based on input type
7
8
  */
@@ -18,6 +19,7 @@ export type InputValueTypeMap = {
18
19
  password: string;
19
20
  radio: string;
20
21
  select: string | string[];
22
+ submit: undefined;
21
23
  switch: boolean;
22
24
  text: string;
23
25
  textarea: string;
@@ -28,30 +30,124 @@ export type InputValueTypeMap = {
28
30
  * Form values stored during rendering
29
31
  */
30
32
  export type FormValues = Record<string, any>;
33
+ export type Meta = {
34
+ httpResponse?: unknown;
35
+ };
31
36
  /**
32
37
  * Union of all possible input value types
33
38
  */
34
- export type InputValue = string | number | boolean | string[] | SerializableFile | SerializableFile[] | [string, string] | [string | undefined, string | undefined] | null;
39
+ export type InputValue = string | number | boolean | string[] | SerializableFile | SerializableFile[] | [string, string] | [string | undefined, string | undefined] | null | undefined;
35
40
  /**
36
- * Props for input components with dynamic value typing
37
- * All form state is provided via props for easier custom component implementation
41
+ * A field the input's dynamic options depend on that is not yet filled.
38
42
  */
39
- export type InputRenderProps<T extends InputType = InputType> = {
40
- node: Node<InputNodeData>;
43
+ export type MissingDependency = {
44
+ /**
45
+ * The referenced node id.
46
+ */
47
+ id: string;
48
+ /**
49
+ * The referenced field's translated, end-user-facing label.
50
+ */
51
+ label: string;
52
+ };
53
+ /**
54
+ * HTML-spreadable props for an input control — safe to spread directly onto a
55
+ * DOM element: `<input {...field} />`. Intentionally excludes `label`,
56
+ * `helperText`, and `error` (not valid DOM attributes); those live in
57
+ * `InputExtraProps`.
58
+ */
59
+ export type InputFieldProps<T extends InputType = InputType> = {
41
60
  /**
42
- * Current value of the input field (typed based on input type when T is specified)
61
+ * Unique field id (nodeId). Use for the element `id`.
62
+ */
63
+ id: string;
64
+ /**
65
+ * Field name (resolved using priority: name > label > nodeId).
66
+ */
67
+ name: string;
68
+ /**
69
+ * Current value of the input (typed by input type when T is specified).
43
70
  */
44
71
  value: InputValueTypeMap[T];
45
72
  /**
46
- * Function to update the input value
47
- * @param value - The new value (typed based on input type when T is specified)
73
+ * Translated placeholder (already processed with current language).
74
+ */
75
+ placeholder?: string;
76
+ /**
77
+ * Whether the field is required.
78
+ */
79
+ required?: boolean;
80
+ /**
81
+ * Set when the field has a validation error.
82
+ */
83
+ "aria-invalid"?: boolean;
84
+ };
85
+ /**
86
+ * Treege-specific props that are NOT DOM attributes: state setters, resolved
87
+ * translations, validation and runtime metadata. Passed as the second argument
88
+ * of an input renderer so the first one (`InputFieldProps`) stays spreadable.
89
+ */
90
+ export type InputExtraProps<T extends InputType = InputType> = {
91
+ /**
92
+ * The node data for this input field.
93
+ */
94
+ node: Node<InputNodeData>;
95
+ /**
96
+ * Function to update the input value.
97
+ * @param value - The new value (typed by input type when T is specified)
48
98
  */
49
99
  setValue: (value: InputValueTypeMap[T]) => void;
50
100
  /**
51
- * Validation error message for this field (if any)
101
+ * Validation error message for this field (if any).
52
102
  */
53
103
  error?: string;
104
+ /** Translated label (already processed with current language). */
105
+ label?: string;
106
+ /**
107
+ * Translated helper text (already processed with current language).
108
+ */
109
+ helperText?: string;
110
+ /**
111
+ * Fields this input's dynamic options depend on that are not yet filled
112
+ * (its unresolved `{{nodeId}}` template variables). Empty when none — use it
113
+ * to hint the user which fields to complete before this input can load.
114
+ */
115
+ missingDependencies: MissingDependency[];
116
+ /**
117
+ * Missing required fields on form submit (for submit inputs).
118
+ */
119
+ missingRequiredFields?: string[];
120
+ /**
121
+ * Whether the form is currently being submitted (for submit inputs).
122
+ */
123
+ isSubmitting?: boolean;
124
+ /**
125
+ * Editor-only extension slot: when provided, option-based renderers (radio,
126
+ * checkbox) call this for each option to paint inline extras next to it
127
+ * (e.g. value preview, edit / delete buttons). `variant` is a renderer-side
128
+ * layout hint (e.g. `"card"` for radio cards). Returning `null` skips the
129
+ * slot for that option. Left undefined in runtime so the renderers stay
130
+ * runtime-pure.
131
+ */
132
+ renderOptionExtras?: (option: {
133
+ option: InputOption;
134
+ index: number;
135
+ variant?: string;
136
+ }) => ReactNode;
137
+ /**
138
+ * Editor-only layout flag. When `true`, option-based renderers force their
139
+ * option labels to a single truncated line (block + max-w-full + truncate)
140
+ * and reserve room on the right for the `renderOptionExtras` overlay.
141
+ * Defaults to `false` (multi-line, runtime-pure).
142
+ */
143
+ compactOptions?: boolean;
54
144
  };
145
+ /**
146
+ * An input renderer. Receives the spreadable `field` props (DOM-safe) and the
147
+ * Treege `extra` props (state setters, translations, metadata) as two separate
148
+ * arguments, so `field` can be spread onto a control: `<input {...field} />`.
149
+ */
150
+ export type InputRenderer<T extends InputType = InputType> = (field: InputFieldProps<T>, extra: InputExtraProps<T>) => ReactNode;
55
151
  export type UiRenderProps = {
56
152
  node: Node<UINodeData>;
57
153
  };
@@ -66,7 +162,50 @@ export type NodeRenderProps = {
66
162
  * Each input type gets its own properly typed InputRenderProps
67
163
  */
68
164
  export type InputRenderers = {
69
- [K in InputType]?: (props: InputRenderProps<K>) => ReactNode;
165
+ [K in InputType]?: InputRenderer<K>;
166
+ };
167
+ /**
168
+ * Props passed to a step renderer. Steps are derived at runtime from the flow's
169
+ * groups: each contiguous slice of visible nodes sharing the same `parentId`
170
+ * (or no parent — orphan steps) becomes one step.
171
+ */
172
+ export type StepRenderProps = {
173
+ /** The step being rendered (its group id and ordered child nodes). */
174
+ step: FlowStep;
175
+ /** Hidden group node carrying the step's metadata (label) — undefined for orphan steps. */
176
+ groupNode?: Node<GroupNodeData>;
177
+ /** Zero-based index of this step in the current step sequence. */
178
+ stepIndex: number;
179
+ /** Total number of steps currently visible. Recomputes when branching changes. */
180
+ totalSteps: number;
181
+ /** True when this is the first step (Back should be hidden/disabled). */
182
+ isFirstStep: boolean;
183
+ /**
184
+ * True when this is the last visible step. The renderer turns Continue
185
+ * into a submit action on the last step.
186
+ */
187
+ isLastStep: boolean;
188
+ /** Whether all required visible inputs of the step are filled. */
189
+ canContinue: boolean;
190
+ /**
191
+ * Translated labels of required fields still empty. Only populated on the
192
+ * last step so the step can show a tooltip explaining why submit is disabled.
193
+ */
194
+ missingFields?: string[];
195
+ /** Submission in progress (passed through from `useTreegeRenderer`). */
196
+ isSubmitting?: boolean;
197
+ /** Advance to the previous step. No-op on the first step. */
198
+ onBack: () => void;
199
+ /**
200
+ * Advance to the next step (or trigger submit on the last step). The wrapper
201
+ * passes `isLastStep` so the implementation can decide between an in-flow
202
+ * advance and a form submit.
203
+ */
204
+ onContinue: () => void;
205
+ /** Translated label of the group, or empty string for orphan steps. */
206
+ label?: string;
207
+ /** The rendered child nodes belonging to this step. */
208
+ children: ReactNode;
70
209
  };
71
210
  /**
72
211
  * Custom renderer components
@@ -82,21 +221,32 @@ export type TreegeRendererComponents = {
82
221
  */
83
222
  ui?: Partial<Record<UIType, (props: NodeRenderProps) => ReactNode>>;
84
223
  /**
85
- * Custom group container renderer
224
+ * Custom step renderer — wraps the current step's nodes and renders the
225
+ * Back/Continue navigation. Defaults are provided by `DefaultStep` (web/native).
86
226
  */
87
- group?: (props: NodeRenderProps) => ReactNode;
227
+ step?: (props: StepRenderProps) => ReactNode;
88
228
  /**
89
229
  * Custom form wrapper
90
230
  */
91
231
  form?: (props: {
92
232
  children: ReactNode;
93
- onSubmit: (e: FormEvent) => void;
233
+ onSubmit: (e: FormEvent<HTMLFormElement>) => void;
94
234
  }) => ReactNode;
95
235
  /**
96
- * Custom submit button (pure button without wrapper)
236
+ * Custom submit button (supports both web and native variants)
237
+ * Web variant: { label?: string; disabled?: boolean; ...otherHTMLAttributes }
238
+ * Native variant: { children?: ReactNode; disabled?: boolean; isSubmitting?: boolean; onPress?: () => void }
97
239
  */
98
240
  submitButton?: (props: {
99
241
  label?: string;
242
+ disabled?: boolean;
243
+ [key: string]: unknown;
244
+ } | {
245
+ children?: ReactNode;
246
+ disabled?: boolean;
247
+ isSubmitting?: boolean;
248
+ onPress?: () => void;
249
+ [key: string]: unknown;
100
250
  }) => ReactNode;
101
251
  /**
102
252
  * Custom submit button wrapper (e.g., for tooltip with missing fields)
@@ -105,9 +255,14 @@ export type TreegeRendererComponents = {
105
255
  children: ReactNode;
106
256
  missingFields?: string[];
107
257
  }) => ReactNode;
258
+ /**
259
+ * Custom loading skeleton, rendered in place of the form while the
260
+ * `isLoading` prop is true. Defaults to `DefaultLoadingSkeleton` (web).
261
+ */
262
+ loadingSkeleton?: () => ReactNode;
108
263
  };
109
264
  /**
110
- * Configuration options that can be set globally via TreegeConfigProvider
265
+ * Configuration options that can be set globally via TreegeRendererProvider
111
266
  * or locally via TreegeRenderer config prop
112
267
  */
113
268
  export type TreegeRendererConfig = {
@@ -115,6 +270,12 @@ export type TreegeRendererConfig = {
115
270
  * Custom component renderers
116
271
  */
117
272
  components?: TreegeRendererComponents;
273
+ /**
274
+ * Global HTTP headers applied to every request issued by the renderer
275
+ * (HTTP inputs, submit buttons). Field-level headers with the same key
276
+ * (case-insensitive) take precedence over these.
277
+ */
278
+ headers?: HttpHeader[];
118
279
  /**
119
280
  * Google Maps API key for address autocomplete
120
281
  * If not provided, falls back to free Nominatim (OpenStreetMap)
@@ -135,53 +296,59 @@ export type TreegeRendererConfig = {
135
296
  * @default "onSubmit"
136
297
  */
137
298
  validationMode?: "onChange" | "onSubmit";
299
+ /**
300
+ * Base URL prepended to every **relative** HTTP url issued by the renderer
301
+ * (HTTP inputs, dynamic options, and submit). Use this to keep the tree
302
+ * JSON environment-agnostic — store relative paths in the tree and supply
303
+ * the host here per environment:
304
+ *
305
+ * @example
306
+ * // In the tree: "url": "/v2/entities/{{nodeId}}/sub-entities"
307
+ * <TreegeRenderer flow={tree} baseUrl={import.meta.env.VITE_API_URL} />
308
+ *
309
+ * Absolute urls (starting with `http://` or `https://`) are left untouched,
310
+ * so a field can still point at an external API. Template variables are
311
+ * resolved first, then the base URL is applied to the result.
312
+ */
313
+ baseUrl?: string;
138
314
  };
139
315
  /**
140
316
  * Props for the TreegeRenderer component
317
+ *
318
+ * Inherits all configuration fields from TreegeRendererConfig (components,
319
+ * headers, googleApiKey, language, theme, validationMode) and adds the
320
+ * instance-specific ones (flow, callbacks, initial values, etc.).
141
321
  */
142
- export type TreegeRendererProps = {
322
+ export interface TreegeRendererProps extends TreegeRendererConfig {
143
323
  /**
144
- * Custom component renderers
324
+ * Additional class name for the renderer container
145
325
  */
146
- components?: TreegeRendererComponents;
326
+ className?: string;
147
327
  /**
148
- * Flow or array of flows
149
- * - If a single Flow: renders that flow
150
- * - If an array: first flow is the main flow, others are sub-flows available for FlowNodes
328
+ * Flow to render. `null` / `undefined` renders nothing.
151
329
  */
152
- flows?: Flow | Flow[] | null;
153
- /**
154
- * Google Maps API key for address autocomplete
155
- * If not provided, falls back to free Nominatim (OpenStreetMap)
156
- */
157
- googleApiKey?: string;
330
+ flow?: Flow | null;
158
331
  /**
159
332
  * Initial form values
160
333
  */
161
334
  initialValues?: FormValues;
162
335
  /**
163
- * Current language for translations
336
+ * When true, renders a loading skeleton instead of the form. Useful while
337
+ * the flow is being fetched. Customizable via `components.loadingSkeleton`.
164
338
  */
165
- language?: string;
339
+ isLoading?: boolean;
166
340
  /**
167
341
  * Callback when form values change
168
342
  */
169
343
  onChange?: (values: FormValues) => void;
170
344
  /**
171
345
  * Callback when form is submitted
346
+ * @param values - Form values (keyed by field name or node ID)
347
+ * @param meta - Optional metadata about the submission (e.g., HTTP response data)
172
348
  */
173
- onSubmit?: (values: FormValues) => void;
174
- /**
175
- * Theme for the renderer
176
- * @default "dark"
177
- */
178
- theme?: "dark" | "light";
349
+ onSubmit?: (values: FormValues, meta?: Meta) => void;
179
350
  /**
180
351
  * Custom validation function
181
352
  */
182
353
  validate?: (values: FormValues, nodes: Node<TreegeNodeData>[]) => Record<string, string>;
183
- /**
184
- * Validation mode
185
- */
186
- validationMode?: "onChange" | "onSubmit";
187
- };
354
+ }
@@ -1,7 +1,7 @@
1
1
  import { Edge, Node } from '@xyflow/react';
2
2
  import { FormValues } from '../types/renderer';
3
3
  import { ConditionalEdgeData } from '../../shared/types/edge';
4
- import { Flow, TreegeNodeData } from '../../shared/types/node';
4
+ import { TreegeNodeData } from '../../shared/types/node';
5
5
  /**
6
6
  * Result from computing the flow render state
7
7
  * Contains everything needed to render the form and determine its state
@@ -72,20 +72,3 @@ export declare const findStartNode: (nodes: Node<TreegeNodeData>[], edges: Edge[
72
72
  * @returns Complete flow render state (visible nodes, end-of-path flag, etc.)
73
73
  */
74
74
  export declare const getFlowRenderState: (nodes: Node<TreegeNodeData>[], edges: Edge<ConditionalEdgeData>[], formValues: FormValues) => FlowRenderState;
75
- /**
76
- * Merge multiple flows into a single flow by recursively replacing FlowNodes with their target flow's nodes
77
- *
78
- * This function takes a flow or an array of flows, automatically detects the main flow, then:
79
- * 1. Replaces each FlowNode with the nodes from its target flow
80
- * 2. Preserves the order of nodes by inserting sub-flow nodes at the FlowNode position
81
- * 3. Redirects edges that point to FlowNodes to the first node of the target flow
82
- * 4. Connects the last nodes of sub-flows to the nodes that followed the FlowNode
83
- *
84
- * Main flow detection:
85
- * - The main flow is automatically identified as the one that references other flows but is not referenced itself
86
- * - This allows flows to be passed in any order without breaking the merge logic
87
- *
88
- * @param flows - A single Flow or an array of flows (can be null/undefined)
89
- * @returns A single merged Flow containing all nodes and edges
90
- */
91
- export declare const mergeFlows: (flows?: Flow | Flow[] | null) => Flow;
@@ -20,7 +20,27 @@ export declare const checkFormFieldHasValue: (fieldName: string | undefined, for
20
20
  /**
21
21
  * Convert internal form values (keyed by nodeId) to external format (keyed by name)
22
22
  * When multiple nodes share the same name, later values overwrite earlier ones
23
- * example: convertFormValuesToNamedFormat({ id1: 'Alice', id2: 'Bob' }, [ { id: 'id1', data: { name: 'firstName' } }, { id: 'id2', data: { name: 'lastName' } } ])
24
- * returns { firstName: 'Alice', lastName: 'Bob' }
23
+ * Priority for key naming: name > label (en) > nodeId
24
+ * example: convertFormValuesToNamedFormat({ id1: 'Alice', id2: 'Bob' }, [ { id: 'id1', data: { name: 'firstName' } }, { id: 'id2', data: { label: { en: 'Last Name' } } } ])
25
+ * returns { firstName: 'Alice', 'Last Name': 'Bob' }
25
26
  */
26
27
  export declare const convertFormValuesToNamedFormat: (formValues: FormValues, nodes: Node<InputNodeData>[]) => Record<string, unknown>;
28
+ /**
29
+ * Apply transformation to a reference field value
30
+ * @param value - The source value to transform
31
+ * @param transformFunction - The transformation function to apply
32
+ * @param objectMapping - Optional mapping for toObject transformation
33
+ * @returns The transformed value
34
+ */
35
+ export declare const applyReferenceTransformation: (value: unknown, transformFunction: "toString" | "toNumber" | "toBoolean" | "toArray" | "toObject" | null | undefined, objectMapping?: Array<{
36
+ sourceKey: string;
37
+ targetKey: string;
38
+ }>) => unknown;
39
+ /**
40
+ * Calculate updated values for fields with reference defaults
41
+ * @param inputNodes - Array of input nodes
42
+ * @param formValues - Current form values
43
+ * @param prevFormValues - Previous form values (for change detection)
44
+ * @returns Object containing fields that need to be updated
45
+ */
46
+ export declare const calculateReferenceFieldUpdates: (inputNodes: Node<InputNodeData>[], formValues: FormValues, prevFormValues: FormValues) => FormValues;
@@ -0,0 +1,152 @@
1
+ import { FormValues } from '../types/renderer';
2
+ import { HttpHeader, InputOption, OptionsSourceMapping, QueryParam } from '../../shared/types/node';
3
+ /**
4
+ * Merge multiple lists of HTTP headers. Later sources override earlier ones
5
+ * when they specify the same key (case-insensitive comparison, since HTTP
6
+ * header names are case-insensitive). The casing of the latest occurrence
7
+ * is preserved in the output.
8
+ */
9
+ export declare const mergeHttpHeaders: (...sources: (HttpHeader[] | undefined)[]) => HttpHeader[];
10
+ /**
11
+ * Append query parameters to a URL. Entries with an empty key are skipped,
12
+ * keys and values are URL-encoded, and `?` or `&` is chosen automatically
13
+ * based on whether the URL already has a query string. Values are expected
14
+ * to already have their template variables resolved.
15
+ */
16
+ export declare const appendQueryParams: (url: string, params?: QueryParam[]) => string;
17
+ /**
18
+ * Prepend a base URL to a relative URL. Absolute urls (starting with
19
+ * `http://` or `https://`, case-insensitive) and protocol-relative urls
20
+ * (`//host/...`) are returned untouched, so individual fields can still
21
+ * target an external API. A single slash is enforced at the join so a
22
+ * trailing slash on the base and/or a leading slash on the path don't
23
+ * produce `//`. When no base URL is configured, the url is returned as-is.
24
+ *
25
+ * Expects the url to already have its template variables resolved.
26
+ */
27
+ export declare const resolveUrl: (url: string, baseUrl?: string) => string;
28
+ /**
29
+ * Result of an HTTP request
30
+ */
31
+ export interface HttpRequestResult {
32
+ /**
33
+ * Whether the request was successful (2xx status code)
34
+ */
35
+ success: boolean;
36
+ /**
37
+ * Response data (parsed JSON or raw text)
38
+ */
39
+ data?: unknown;
40
+ /**
41
+ * Error message if request failed
42
+ */
43
+ error?: string;
44
+ /**
45
+ * HTTP status code
46
+ */
47
+ status?: number;
48
+ /**
49
+ * HTTP status text
50
+ */
51
+ statusText?: string;
52
+ }
53
+ /**
54
+ * Options for making an HTTP request
55
+ */
56
+ export interface HttpRequestOptions {
57
+ /**
58
+ * The URL to call (should already have variables replaced)
59
+ */
60
+ url: string;
61
+ /**
62
+ * HTTP method
63
+ */
64
+ method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
65
+ /**
66
+ * Request headers
67
+ */
68
+ headers?: HttpHeader[];
69
+ /**
70
+ * Query parameters appended to the URL (values should already have their
71
+ * template variables resolved; keys/values are URL-encoded here)
72
+ */
73
+ queryParams?: QueryParam[];
74
+ /**
75
+ * Request body (for POST/PUT/PATCH)
76
+ */
77
+ body?: string;
78
+ /**
79
+ * Optional abort signal to cancel the request
80
+ */
81
+ signal?: AbortSignal;
82
+ }
83
+ /**
84
+ * Make an HTTP request with common error handling and response parsing
85
+ *
86
+ * This is a shared utility used by both HTTP inputs and submit buttons
87
+ * to ensure consistent behavior across the library.
88
+ *
89
+ * @param options - Request options
90
+ * @returns Promise with request result
91
+ */
92
+ export declare const makeHttpRequest: (options: HttpRequestOptions) => Promise<HttpRequestResult>;
93
+ /**
94
+ * Replace template variables in a string with actual values from form data
95
+ *
96
+ * Uses {{fieldId}} syntax for all replacements (URLs, JSON bodies, etc.)
97
+ *
98
+ * Smart JSON handling:
99
+ * - Strings: automatically wrapped in quotes and escaped
100
+ * - Numbers/Booleans: converted to JSON-safe format
101
+ * - Arrays/Objects: JSON.stringify
102
+ *
103
+ * @param template - The template string containing variables
104
+ * @param values - Form values to substitute
105
+ * @param options - Replacement options
106
+ * @param options.encode - Whether to URL-encode the replaced values (for URLs)
107
+ * @param options.json - Whether to use smart JSON handling (for request bodies)
108
+ * @returns The string with variables replaced
109
+ *
110
+ * @example
111
+ * // For URLs (with encoding)
112
+ * replaceTemplateVariables("https://api.com/users/{{userId}}", { userId: "john doe" }, { encode: true })
113
+ * // => "https://api.com/users/john%20doe"
114
+ *
115
+ * // For JSON bodies (smart handling)
116
+ * replaceTemplateVariables('{"name": {{userName}}}', { userName: "John" }, { json: true })
117
+ * // => '{"name": "John"}'
118
+ *
119
+ * replaceTemplateVariables('{"age": {{userAge}}}', { userAge: 25 }, { json: true })
120
+ * // => '{"age": 25}'
121
+ */
122
+ export declare const replaceTemplateVariables: (template: string | undefined, values: FormValues, options?: {
123
+ encode?: boolean;
124
+ json?: boolean;
125
+ }) => string;
126
+ /**
127
+ * Replace template variables in response data (for redirect URLs)
128
+ *
129
+ * Supports {{response.field}} format to access response data
130
+ *
131
+ * @param template - The template string containing variables
132
+ * @param responseData - Response data object
133
+ * @returns The string with variables replaced
134
+ */
135
+ export declare const replaceResponseVariables: (template: string | undefined, responseData: unknown) => string;
136
+ /**
137
+ * Extract a value from an object using a path that supports dot notation
138
+ * and array indexing. Examples:
139
+ * - "data.users" → obj.data.users
140
+ * - "results[0].name" → obj.results[0].name
141
+ *
142
+ * @param obj - The object to extract value from
143
+ * @param path - The path expression (empty string returns the object as-is)
144
+ * @returns The value at the path, or undefined if not found
145
+ */
146
+ export declare const getValueByPath: (obj: unknown, path: string) => unknown;
147
+ /**
148
+ * Project a list-shaped HTTP response into InputOption objects, applying
149
+ * a field-to-property mapping. Returns an empty array when the data is not
150
+ * iterable or required fields are missing.
151
+ */
152
+ export declare const extractOptionsFromResponse: (response: unknown, responsePath: string | undefined, mapping: OptionsSourceMapping) => InputOption[];
@@ -6,9 +6,37 @@ import { InputNodeData, TreegeNodeData } from '../../shared/types/node';
6
6
  * @returns Array of input nodes only
7
7
  */
8
8
  export declare const getInputNodes: (nodes: Node<TreegeNodeData>[]) => Node<InputNodeData>[];
9
+ /**
10
+ * Resolve the key name for an input node using priority: name > label (en) > nodeId
11
+ * This is the single source of truth for key resolution across the application
12
+ * @param node - The input node
13
+ * @returns The resolved key (name, label, or node ID)
14
+ */
15
+ export declare const resolveNodeKey: (node: Node<InputNodeData>) => string;
16
+ /**
17
+ * Resolve a human, end-user-facing label for an input node, preferring the
18
+ * translated `label` for the given language over the technical `name`. Used
19
+ * when surfacing field references to users (e.g. dependency hints). Priority:
20
+ * translated label > name > node id. This differs from `resolveNodeKey`, which
21
+ * prioritizes `name` for form-submission keys.
22
+ * @param node - The input node
23
+ * @param language - The current language code
24
+ * @returns The resolved display label
25
+ */
26
+ export declare const resolveNodeLabel: (node: Node<InputNodeData>, language: string) => string;
27
+ /**
28
+ * Resolve the placeholder text for an input, falling back to the static
29
+ * "newAnswer" translation for textfield-like types when the user has not
30
+ * defined a placeholder for the current language.
31
+ * @param data - The input node data
32
+ * @param language - The current language code
33
+ * @returns The resolved placeholder string (empty string if none available)
34
+ */
35
+ export declare const resolveInputPlaceholder: (data: InputNodeData, language: string) => string;
9
36
  /**
10
37
  * Get the field name (DOM name attribute) for a given node ID
11
- * Uses node.data.name if available, otherwise falls back to nodeId
38
+ * Priority: name > label (en) > nodeId
39
+ * This must match the logic in convertFormValuesToNamedFormat for consistency
12
40
  * @param nodeId - The ID of the input node
13
41
  * @param nodes - Array of input nodes
14
42
  * @returns The field name to use in the DOM, or undefined if node not found