treege 3.0.0-beta.9 → 3.0.0-beta.90
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/LICENSE +18 -12
- package/README.md +598 -79
- package/dist/DefaultSubmitButton-NeSDqyzv.js +1909 -0
- package/dist/ThemeContext-CPsC8QIP.js +1008 -0
- package/dist/editor/components/input/ComboboxWithCreate.d.ts +2 -1
- package/dist/editor/components/styles/EditorStyles.d.ts +2 -0
- package/dist/editor/constants/defaultNode.d.ts +1 -1
- package/dist/editor/constants/edgeTypes.d.ts +3 -2
- package/dist/editor/constants/inputTypeIcons.d.ts +3 -0
- package/dist/editor/constants/nodeSpacing.d.ts +25 -0
- package/dist/editor/constants/nodeTypes.d.ts +4 -5
- package/dist/editor/context/OpenApiContext.d.ts +79 -0
- package/dist/editor/context/TreegeEditorRuntimeProvider.d.ts +78 -0
- package/dist/editor/features/TreegeEditor/TreegeEditor.d.ts +1 -1
- package/dist/editor/features/TreegeEditor/controls/MiniMapControl.d.ts +6 -0
- package/dist/editor/features/TreegeEditor/dialogs/AuthorizeDialog.d.ts +20 -0
- package/dist/editor/features/TreegeEditor/dialogs/ChangeNodeTypeDialog.d.ts +2 -0
- package/dist/editor/features/TreegeEditor/dialogs/DeleteNodeDialog.d.ts +2 -0
- package/dist/editor/features/TreegeEditor/dialogs/HeadersDialog.d.ts +19 -0
- package/dist/editor/features/TreegeEditor/dialogs/OpenApiDialog.d.ts +6 -0
- package/dist/editor/features/TreegeEditor/edges/ConditionalEdge.d.ts +2 -2
- package/dist/editor/features/TreegeEditor/edges/DefaultEdge.d.ts +3 -0
- package/dist/editor/features/TreegeEditor/forms/HttpConfigForm.d.ts +4 -1
- package/dist/editor/features/TreegeEditor/forms/JsonTemplateEditor.d.ts +13 -0
- package/dist/editor/features/TreegeEditor/forms/OptionsMappingFields.d.ts +34 -0
- package/dist/editor/features/TreegeEditor/forms/OptionsSourceForm.d.ts +7 -0
- package/dist/editor/features/TreegeEditor/forms/SensitiveHeaderWarning.d.ts +13 -0
- package/dist/editor/features/TreegeEditor/forms/SubmitConfigForm.d.ts +7 -0
- package/dist/editor/features/TreegeEditor/inputs/ApiUrlCombobox.d.ts +20 -0
- package/dist/editor/features/TreegeEditor/inputs/ComboboxPattern.d.ts +2 -1
- package/dist/editor/features/TreegeEditor/inputs/DefaultFileValueField.d.ts +14 -0
- package/dist/editor/features/TreegeEditor/inputs/OptionImageField.d.ts +6 -0
- package/dist/editor/features/TreegeEditor/inputs/SelectNodeGroup.d.ts +22 -1
- package/dist/editor/features/TreegeEditor/inputs/TranslatableInput.d.ts +20 -0
- package/dist/editor/features/TreegeEditor/layout/AutoLayout.d.ts +15 -0
- package/dist/editor/features/TreegeEditor/listeners/FlowChangeEmitter.d.ts +19 -0
- package/dist/editor/features/TreegeEditor/nodes/TreegeNode.d.ts +5 -0
- package/dist/editor/features/TreegeEditor/nodes/components/BottomHandleDropdown.d.ts +25 -0
- package/dist/editor/features/TreegeEditor/nodes/components/NodeGroupBadge.d.ts +6 -0
- package/dist/editor/features/TreegeEditor/nodes/components/NodeImage.d.ts +5 -0
- package/dist/editor/features/TreegeEditor/nodes/components/NodeImageButton.d.ts +6 -0
- package/dist/editor/features/TreegeEditor/nodes/components/NodeInputPreview.d.ts +12 -0
- package/dist/editor/features/TreegeEditor/nodes/components/NodeLabelInput.d.ts +10 -0
- package/dist/editor/features/TreegeEditor/nodes/components/NodeMoreMenu.d.ts +6 -0
- package/dist/editor/features/TreegeEditor/nodes/components/NodeRequiredButton.d.ts +6 -0
- package/dist/editor/features/TreegeEditor/nodes/components/NodeStackOrderButtons.d.ts +6 -0
- package/dist/editor/features/TreegeEditor/nodes/components/NodeTypeBadge.d.ts +7 -0
- package/dist/editor/features/TreegeEditor/nodes/components/NodeTypePickerMenuContent.d.ts +12 -0
- package/dist/editor/features/TreegeEditor/nodes/layout/NodeWrapper.d.ts +4 -2
- package/dist/editor/features/TreegeEditor/panel/AIGeneratorDialog.d.ts +16 -0
- package/dist/editor/features/TreegeEditor/panel/ActionsPanel.d.ts +7 -2
- package/dist/editor/features/TreegeEditor/panel/MultiSelectionPanel.d.ts +7 -0
- package/dist/editor/hooks/useAvailableParentFields.d.ts +13 -0
- package/dist/editor/hooks/useFlowActions.d.ts +6 -2
- package/dist/editor/hooks/useFlowConnections.d.ts +14 -0
- package/dist/editor/hooks/useFlowContent.d.ts +16 -0
- package/dist/editor/hooks/useHistoryStore.d.ts +26 -0
- package/dist/editor/hooks/useIsStackedEdge.d.ts +8 -0
- package/dist/editor/hooks/useKeyValueRows.d.ts +15 -0
- package/dist/editor/hooks/useNodesSelection.d.ts +5 -5
- package/dist/editor/hooks/useStackPosition.d.ts +14 -0
- package/dist/editor/hooks/useTranslate.d.ts +1 -1
- package/dist/editor/hooks/useUndoRedo.d.ts +31 -0
- package/dist/editor/types/ai.d.ts +65 -0
- package/dist/editor/types/editor.d.ts +106 -10
- package/dist/editor/types/openapi.d.ts +106 -0
- package/dist/editor/utils/aiFlowGenerator.d.ts +5 -0
- package/dist/editor/utils/cleanEmptyData.d.ts +18 -0
- package/dist/editor/utils/cleanNodeConfig.d.ts +5 -0
- package/dist/editor/utils/dagreLayout.d.ts +8 -0
- package/dist/editor/utils/edge.d.ts +50 -0
- package/dist/editor/utils/groupColor.d.ts +14 -0
- package/dist/editor/utils/image.d.ts +7 -0
- package/dist/editor/utils/inputTypeIcon.d.ts +6 -0
- package/dist/editor/utils/jsonBindTarget.d.ts +15 -0
- package/dist/editor/utils/openApiPayload.d.ts +12 -0
- package/dist/editor/utils/openapi.d.ts +35 -0
- package/dist/editor/utils/sensitiveHeaders.d.ts +20 -0
- package/dist/editor/utils/stackPositionIndex.d.ts +9 -0
- package/dist/editor-D3EmQ-8C.js +6485 -0
- package/dist/editor.js +3 -7
- package/dist/main.js +6 -52
- package/dist/renderer/context/TreegeRenderRuntimeProvider.d.ts +135 -0
- package/dist/renderer/context/TreegeRendererProvider.d.ts +15 -0
- package/dist/renderer/context/TreegeViewerProvider.d.ts +28 -0
- package/dist/renderer/features/TreegeRenderer/native/TreegeRenderer.d.ts +19 -11
- package/dist/renderer/features/TreegeRenderer/native/components/DefaultFormWrapper.d.ts +7 -7
- package/dist/renderer/features/TreegeRenderer/native/components/DefaultInputLabel.d.ts +10 -0
- package/dist/renderer/features/TreegeRenderer/native/components/DefaultInputWrapper.d.ts +9 -0
- package/dist/renderer/features/TreegeRenderer/native/components/DefaultInputs.d.ts +20 -15
- package/dist/renderer/features/TreegeRenderer/native/components/DefaultLoadingSkeleton.d.ts +8 -0
- package/dist/renderer/features/TreegeRenderer/native/components/DefaultStep.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/native/components/DefaultSubmitButton.d.ts +9 -7
- package/dist/renderer/features/TreegeRenderer/native/components/DefaultSubmitButtonWrapper.d.ts +11 -0
- package/dist/renderer/features/TreegeRenderer/native/components/DefaultUI.d.ts +8 -7
- package/dist/renderer/features/TreegeRenderer/native/components/DependencyHint.d.ts +15 -0
- package/dist/renderer/features/TreegeRenderer/native/components/OptionItemContent.d.ts +17 -0
- package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultAddressInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultAutocompleteInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultCheckboxInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultDateInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultDateRangeInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultFileInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultHiddenInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultHttpInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultNumberInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultPasswordInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultRadioInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultSelectInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultSubmitInput.d.ts +11 -0
- package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultSwitchInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultTextInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultTextareaInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultTimeInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultTimeRangeInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/useTreegeRenderer.d.ts +97 -24
- package/dist/renderer/features/TreegeRenderer/web/TreegeRenderer.d.ts +1 -1
- package/dist/renderer/features/TreegeRenderer/web/components/DefaultFormWrapper.d.ts +3 -2
- package/dist/renderer/features/TreegeRenderer/web/components/DefaultInputLabel.d.ts +9 -0
- package/dist/renderer/features/TreegeRenderer/web/components/DefaultInputWrapper.d.ts +9 -0
- package/dist/renderer/features/TreegeRenderer/web/components/DefaultLoadingSkeleton.d.ts +7 -0
- package/dist/renderer/features/TreegeRenderer/web/components/DefaultStep.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/web/components/DefaultSubmitButton.d.ts +5 -1
- package/dist/renderer/features/TreegeRenderer/web/components/DependencyHint.d.ts +22 -0
- package/dist/renderer/features/TreegeRenderer/web/components/OptionItemContent.d.ts +17 -0
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultAddressInput.d.ts +1 -1
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultAutocompleteInput.d.ts +1 -1
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultCheckboxInput.d.ts +1 -1
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultDateInput.d.ts +1 -1
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultDateRangeInput.d.ts +1 -1
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultFileInput.d.ts +1 -1
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultHiddenInput.d.ts +1 -1
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultHttpInput.d.ts +1 -1
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultNumberInput.d.ts +1 -1
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultPasswordInput.d.ts +1 -1
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultRadioInput.d.ts +1 -1
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultSelectInput.d.ts +1 -1
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultSubmitInput.d.ts +11 -0
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultSwitchInput.d.ts +1 -1
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultTextAreaInput.d.ts +1 -1
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultTextInput.d.ts +1 -1
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultTimeInput.d.ts +1 -1
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultTimeRangeInput.d.ts +1 -1
- package/dist/renderer/features/TreegeRenderer/web/components/styles/RendererStyles.d.ts +2 -0
- package/dist/renderer/features/TreegeViewer/utils/viewerFields.d.ts +102 -0
- package/dist/renderer/features/TreegeViewer/web/TreegeViewer.d.ts +94 -0
- package/dist/renderer/hooks/useInputOptions.d.ts +28 -0
- package/dist/renderer/hooks/useRenderNode.d.ts +62 -0
- package/dist/renderer/hooks/useSubmitHandler.d.ts +37 -0
- package/dist/renderer/hooks/useTranslate.d.ts +7 -5
- package/dist/renderer/index.d.ts +10 -2
- package/dist/renderer/index.native.d.ts +20 -0
- package/dist/renderer/types/renderer.d.ts +332 -49
- package/dist/renderer/utils/extraPayload.d.ts +21 -0
- package/dist/renderer/utils/file.d.ts +24 -10
- package/dist/renderer/utils/flow.d.ts +1 -18
- package/dist/renderer/utils/form.d.ts +54 -2
- package/dist/renderer/utils/http.d.ts +177 -0
- package/dist/renderer/utils/jsonTemplate.d.ts +30 -0
- package/dist/renderer/utils/node.d.ts +29 -1
- package/dist/renderer/utils/sanitize.d.ts +85 -0
- package/dist/renderer/utils/sanitize.native.d.ts +69 -0
- package/dist/renderer/utils/step.d.ts +27 -0
- package/dist/renderer/utils/submit.d.ts +50 -0
- package/dist/renderer/utils/templateDependencies.d.ts +17 -0
- package/dist/renderer-CNbSt_QW.js +446 -0
- package/dist/renderer-native.d.ts +2 -0
- package/dist/renderer-native.js +3692 -0
- package/dist/renderer.js +5 -45
- package/dist/shared/components/ui/badge.d.ts +2 -2
- package/dist/shared/components/ui/button.d.ts +3 -3
- package/dist/shared/components/ui/collapsible.d.ts +1 -1
- package/dist/shared/components/ui/command.d.ts +1 -1
- package/dist/shared/components/ui/dropdown-menu.d.ts +1 -1
- package/dist/shared/components/ui/field.d.ts +24 -0
- package/dist/shared/components/ui/form.d.ts +1 -1
- package/dist/shared/components/ui/item.d.ts +23 -0
- package/dist/shared/components/ui/popover.d.ts +10 -2
- package/dist/shared/components/ui/select.d.ts +3 -1
- package/dist/shared/components/ui/sheet.d.ts +1 -1
- package/dist/shared/components/ui/skeleton.d.ts +3 -0
- package/dist/shared/components/ui/toggle-group.d.ts +7 -0
- package/dist/shared/components/ui/toggle.d.ts +9 -0
- package/dist/shared/components/ui/tooltip.d.ts +1 -1
- package/dist/shared/constants/colors.d.ts +45 -0
- package/dist/shared/constants/inputType.d.ts +6 -0
- package/dist/shared/constants/node.d.ts +0 -1
- package/dist/shared/context/PortalContainerContext.d.ts +5 -0
- package/dist/shared/context/ThemeContext.d.ts +2 -0
- package/dist/shared/context/ThemeContext.native.d.ts +22 -0
- package/dist/shared/hooks/useMediaQuery.d.ts +12 -0
- package/dist/shared/hooks/useThemeColors.d.ts +37 -0
- package/dist/shared/locales/ar.json.d.ts +259 -19
- package/dist/shared/locales/de.json.d.ts +260 -20
- package/dist/shared/locales/en.json.d.ts +261 -21
- package/dist/shared/locales/es.json.d.ts +260 -20
- package/dist/shared/locales/fr.json.d.ts +260 -20
- package/dist/shared/locales/it.json.d.ts +260 -20
- package/dist/shared/locales/pt.json.d.ts +260 -20
- package/dist/shared/types/edge.d.ts +6 -0
- package/dist/shared/types/file.d.ts +14 -0
- package/dist/shared/types/node.d.ts +155 -19
- package/dist/shared/utils/httpRecord.d.ts +20 -0
- package/dist/shared/utils/inputTypeGuards.d.ts +7 -0
- package/dist/shared/utils/nodeTypeGuards.d.ts +1 -6
- package/dist/shared/utils/normalizeLabel.d.ts +22 -0
- package/dist/shared/utils/translations.d.ts +21 -1
- package/dist/useRenderNode-CG466pNk.js +538 -0
- package/package.json +54 -22
- package/dist/ThemeContext-BIvs8Kw-.js +0 -758
- package/dist/TreegeEditor-Lv5Tn9_F.js +0 -2152
- package/dist/TreegeRenderer-BVaqgInZ.js +0 -1405
- package/dist/editor/context/TreegeEditorContext.d.ts +0 -12
- package/dist/editor/features/TreegeEditor/forms/FlowNodeForm.d.ts +0 -2
- package/dist/editor/features/TreegeEditor/inputs/SelectInputType.d.ts +0 -7
- package/dist/editor/features/TreegeEditor/nodes/FlowNode.d.ts +0 -6
- package/dist/editor/features/TreegeEditor/nodes/GroupNode.d.ts +0 -6
- package/dist/editor/features/TreegeEditor/nodes/InputNode.d.ts +0 -6
- package/dist/editor/features/TreegeEditor/nodes/UINode.d.ts +0 -6
- package/dist/editor/hooks/useEdgesSelection.d.ts +0 -11
- package/dist/renderer/context/TreegeConfigContext.d.ts +0 -39
- package/dist/renderer/context/TreegeRendererContext.d.ts +0 -25
- package/dist/renderer/features/TreegeRenderer/native/components/DefaultGroup.d.ts +0 -7
- package/dist/renderer/features/TreegeRenderer/web/components/DefaultGroup.d.ts +0 -6
- /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
|
-
import { FormEvent, ReactNode } from 'react';
|
|
2
|
+
import { ComponentType, FormEvent, ReactNode } from 'react';
|
|
3
3
|
import { SerializableFile } from '../utils/file';
|
|
4
|
-
import {
|
|
4
|
+
import { FlowStep } from '../utils/step';
|
|
5
|
+
import { Flow, GroupNodeData, HttpHeaders, 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,48 +30,178 @@ 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
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Extra data injected by the consuming app into every submission, merged at the
|
|
38
|
+
* top level of the payload — both the object passed to `onSubmit` and the body
|
|
39
|
+
* of the built-in HTTP submit request. Use it for fields that live in the host
|
|
40
|
+
* app rather than the form itself (e.g. the logged-in `userId`, a tenant id).
|
|
41
|
+
*
|
|
42
|
+
* Either a static object or a function of the current (name-keyed) form values,
|
|
43
|
+
* evaluated at submit time so the extra data can be derived from the answers or
|
|
44
|
+
* read fresh (e.g. a rotating auth token). The extra keys are spread last, so
|
|
45
|
+
* they intentionally override a same-named form field.
|
|
46
|
+
*/
|
|
47
|
+
export type ExtraPayload = Record<string, unknown> | ((values: FormValues) => Record<string, unknown>);
|
|
31
48
|
/**
|
|
32
49
|
* Union of all possible input value types
|
|
33
50
|
*/
|
|
34
|
-
export type InputValue = string | number | boolean | string[] | SerializableFile | SerializableFile[] | [string, string] | [string | undefined, string | undefined] | null;
|
|
51
|
+
export type InputValue = string | number | boolean | string[] | SerializableFile | SerializableFile[] | [string, string] | [string | undefined, string | undefined] | null | undefined;
|
|
35
52
|
/**
|
|
36
|
-
*
|
|
37
|
-
* All form state is provided via props for easier custom component implementation
|
|
53
|
+
* A field the input's dynamic options depend on that is not yet filled.
|
|
38
54
|
*/
|
|
39
|
-
export type
|
|
55
|
+
export type MissingDependency = {
|
|
40
56
|
/**
|
|
41
|
-
* The node
|
|
57
|
+
* The referenced node id.
|
|
42
58
|
*/
|
|
43
|
-
|
|
59
|
+
id: string;
|
|
44
60
|
/**
|
|
45
|
-
*
|
|
61
|
+
* The referenced field's translated, end-user-facing label.
|
|
62
|
+
*/
|
|
63
|
+
label: string;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* HTML-spreadable props for an input control — safe to spread directly onto a
|
|
67
|
+
* DOM element: `<input {...field} />`. Intentionally excludes `label`,
|
|
68
|
+
* `helperText`, and `error` (not valid DOM attributes); those live in
|
|
69
|
+
* `InputExtraProps`.
|
|
70
|
+
*/
|
|
71
|
+
export type InputFieldProps<T extends InputType = InputType> = {
|
|
72
|
+
/**
|
|
73
|
+
* Unique field id (nodeId). Use for the element `id`.
|
|
74
|
+
*/
|
|
75
|
+
id: string;
|
|
76
|
+
/**
|
|
77
|
+
* Field name (resolved using priority: name > label > nodeId).
|
|
78
|
+
*/
|
|
79
|
+
name: string;
|
|
80
|
+
/**
|
|
81
|
+
* Current value of the input (typed by input type when T is specified).
|
|
46
82
|
*/
|
|
47
83
|
value: InputValueTypeMap[T];
|
|
48
84
|
/**
|
|
49
|
-
*
|
|
50
|
-
* @param value - The new value (typed based on input type when T is specified)
|
|
85
|
+
* Translated placeholder (already processed with current language).
|
|
51
86
|
*/
|
|
52
|
-
|
|
87
|
+
placeholder?: string;
|
|
53
88
|
/**
|
|
54
|
-
*
|
|
89
|
+
* Whether the field is required.
|
|
55
90
|
*/
|
|
56
|
-
|
|
91
|
+
required?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Set when the field has a validation error.
|
|
94
|
+
*/
|
|
95
|
+
"aria-invalid"?: boolean;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Treege-specific props that are NOT DOM attributes: state setters, resolved
|
|
99
|
+
* translations, validation and runtime metadata. Passed as the second argument
|
|
100
|
+
* of an input renderer so the first one (`InputFieldProps`) stays spreadable.
|
|
101
|
+
*/
|
|
102
|
+
export type InputExtraProps<T extends InputType = InputType> = {
|
|
103
|
+
/**
|
|
104
|
+
* The node data for this input field.
|
|
105
|
+
*/
|
|
106
|
+
node: Node<InputNodeData>;
|
|
57
107
|
/**
|
|
58
|
-
*
|
|
108
|
+
* Function to update the input value.
|
|
109
|
+
* @param value - The new value (typed by input type when T is specified)
|
|
59
110
|
*/
|
|
111
|
+
setValue: (value: InputValueTypeMap[T]) => void;
|
|
112
|
+
/**
|
|
113
|
+
* Validation error message for this field (if any).
|
|
114
|
+
*/
|
|
115
|
+
error?: string;
|
|
116
|
+
/** Translated label (already processed with current language). */
|
|
60
117
|
label?: string;
|
|
61
118
|
/**
|
|
62
|
-
*
|
|
119
|
+
* Resolved input label component: the consumer's `components.inputLabel` when
|
|
120
|
+
* provided, otherwise the platform `DefaultInputLabel`. Default inputs render
|
|
121
|
+
* it as `<InputLabel label={label} required={node.data.required} htmlFor={id} />`;
|
|
122
|
+
* it renders nothing when no label is configured. Exposed so custom input
|
|
123
|
+
* renderers can reuse the same (overridable) label.
|
|
63
124
|
*/
|
|
64
|
-
|
|
125
|
+
InputLabel: InputLabelRenderer;
|
|
65
126
|
/**
|
|
66
|
-
* Translated helper text (already processed with current language)
|
|
127
|
+
* Translated helper text (already processed with current language).
|
|
67
128
|
*/
|
|
68
129
|
helperText?: string;
|
|
130
|
+
/**
|
|
131
|
+
* Fields this input's dynamic options depend on that are not yet filled
|
|
132
|
+
* (its unresolved `{{nodeId}}` template variables). Empty when none — use it
|
|
133
|
+
* to hint the user which fields to complete before this input can load.
|
|
134
|
+
*/
|
|
135
|
+
missingDependencies: MissingDependency[];
|
|
136
|
+
/**
|
|
137
|
+
* Missing required fields on form submit (for submit inputs).
|
|
138
|
+
*/
|
|
139
|
+
missingRequiredFields?: string[];
|
|
140
|
+
/**
|
|
141
|
+
* Whether the form is currently being submitted (for submit inputs).
|
|
142
|
+
*/
|
|
143
|
+
isSubmitting?: boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Editor-only extension slot: when provided, option-based renderers (radio,
|
|
146
|
+
* checkbox) call this for each option to paint inline extras next to it
|
|
147
|
+
* (e.g. value preview, edit / delete buttons). `variant` is a renderer-side
|
|
148
|
+
* layout hint (e.g. `"card"` for radio cards). Returning `null` skips the
|
|
149
|
+
* slot for that option. Left undefined in runtime so the renderers stay
|
|
150
|
+
* runtime-pure.
|
|
151
|
+
*/
|
|
152
|
+
renderOptionExtras?: (option: {
|
|
153
|
+
option: InputOption;
|
|
154
|
+
index: number;
|
|
155
|
+
variant?: string;
|
|
156
|
+
}) => ReactNode;
|
|
157
|
+
/**
|
|
158
|
+
* Editor-only layout flag. When `true`, option-based renderers force their
|
|
159
|
+
* option labels to a single truncated line (block + max-w-full + truncate)
|
|
160
|
+
* and reserve room on the right for the `renderOptionExtras` overlay.
|
|
161
|
+
* Defaults to `false` (multi-line, runtime-pure).
|
|
162
|
+
*/
|
|
163
|
+
compactOptions?: boolean;
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* Props passed to an input renderer: the spreadable `field` props (DOM-safe, so
|
|
167
|
+
* `field` can be spread onto a control — `<input {...field} />`) and the Treege
|
|
168
|
+
* `extra` props (state setters, translations, metadata).
|
|
169
|
+
*/
|
|
170
|
+
export type InputRenderProps<T extends InputType = InputType> = {
|
|
171
|
+
field: InputFieldProps<T>;
|
|
172
|
+
extra: InputExtraProps<T>;
|
|
69
173
|
};
|
|
174
|
+
/**
|
|
175
|
+
* An input renderer — a React component, so it can use hooks and is rendered
|
|
176
|
+
* directly (`<Renderer field={field} extra={extra} />`) without a wrapper.
|
|
177
|
+
*/
|
|
178
|
+
export type InputRenderer<T extends InputType = InputType> = ComponentType<InputRenderProps<T>>;
|
|
70
179
|
export type UiRenderProps = {
|
|
71
180
|
node: Node<UINodeData>;
|
|
72
181
|
};
|
|
182
|
+
/**
|
|
183
|
+
* Props for the input label component shared by all default input renderers.
|
|
184
|
+
* `label` + `required` are platform-agnostic; the remaining fields are
|
|
185
|
+
* passthrough hints for the platform (web: `htmlFor`/`id`/`className`,
|
|
186
|
+
* native: `style`). Implementations should render nothing when `label` is empty
|
|
187
|
+
* so the technical node key never leaks into the form.
|
|
188
|
+
*/
|
|
189
|
+
export type InputLabelRenderProps = {
|
|
190
|
+
/** End-user-facing label. Render nothing when empty. */
|
|
191
|
+
label?: string;
|
|
192
|
+
/** Whether to render the required marker. */
|
|
193
|
+
required?: boolean;
|
|
194
|
+
/** Web: associates the label with the control. */
|
|
195
|
+
htmlFor?: string;
|
|
196
|
+
/** Web: id used for `aria-labelledby` on option groups. */
|
|
197
|
+
id?: string;
|
|
198
|
+
/** Web: extra class names. */
|
|
199
|
+
className?: string;
|
|
200
|
+
/** Native: extra style (typed loosely to avoid a react-native dependency here). */
|
|
201
|
+
style?: unknown;
|
|
202
|
+
};
|
|
203
|
+
/** Input label component (custom `components.inputLabel` or the platform default). */
|
|
204
|
+
export type InputLabelRenderer = ComponentType<InputLabelRenderProps>;
|
|
73
205
|
/**
|
|
74
206
|
* Props for UI/Group components (use useTreegeContext for state)
|
|
75
207
|
*/
|
|
@@ -81,7 +213,69 @@ export type NodeRenderProps = {
|
|
|
81
213
|
* Each input type gets its own properly typed InputRenderProps
|
|
82
214
|
*/
|
|
83
215
|
export type InputRenderers = {
|
|
84
|
-
[K in InputType]?:
|
|
216
|
+
[K in InputType]?: InputRenderer<K>;
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Props passed to a step renderer. Steps are derived at runtime from the flow's
|
|
220
|
+
* groups: each contiguous slice of visible nodes sharing the same `parentId`
|
|
221
|
+
* (or no parent — orphan steps) becomes one step.
|
|
222
|
+
*/
|
|
223
|
+
export type StepRenderProps = {
|
|
224
|
+
/** The step being rendered (its group id and ordered child nodes). */
|
|
225
|
+
step: FlowStep;
|
|
226
|
+
/** Hidden group node carrying the step's metadata (label) — undefined for orphan steps. */
|
|
227
|
+
groupNode?: Node<GroupNodeData>;
|
|
228
|
+
/** Zero-based index of this step in the current step sequence. */
|
|
229
|
+
stepIndex: number;
|
|
230
|
+
/** Total number of steps currently visible. Recomputes when branching changes. */
|
|
231
|
+
totalSteps: number;
|
|
232
|
+
/** True when this is the first step (Back should be hidden/disabled). */
|
|
233
|
+
isFirstStep: boolean;
|
|
234
|
+
/**
|
|
235
|
+
* Whether a Back button should be shown. True on any step past the first, and
|
|
236
|
+
* also on the first step when the consumer passes an `onBack` prop (to bridge
|
|
237
|
+
* back-navigation to an outer flow, e.g. a parent modal's steps). Prefer this
|
|
238
|
+
* over `isFirstStep` to decide whether to render the Back control.
|
|
239
|
+
*/
|
|
240
|
+
canGoBack: boolean;
|
|
241
|
+
/**
|
|
242
|
+
* True when this is the last visible step. The renderer turns Continue
|
|
243
|
+
* into a submit action on the last step.
|
|
244
|
+
*/
|
|
245
|
+
isLastStep: boolean;
|
|
246
|
+
/** Whether all required visible inputs of the step are filled. */
|
|
247
|
+
canContinue: boolean;
|
|
248
|
+
/**
|
|
249
|
+
* True when the step contains an explicit `submit` input node. Such a node is
|
|
250
|
+
* declarative — it renders no button itself; the step renders the single
|
|
251
|
+
* submit button (reusing the node's label). Exposed for custom step
|
|
252
|
+
* implementations that need to know a submit node is present.
|
|
253
|
+
*/
|
|
254
|
+
hasSubmitInput?: boolean;
|
|
255
|
+
/**
|
|
256
|
+
* Translated labels of the current step's required fields still empty. Lines
|
|
257
|
+
* up with `canContinue`, so the action button can show a tooltip explaining
|
|
258
|
+
* why Continue/Submit is disabled — on every step, not just the last.
|
|
259
|
+
*/
|
|
260
|
+
missingFields?: string[];
|
|
261
|
+
/** Submission in progress (passed through from `useTreegeRenderer`). */
|
|
262
|
+
isSubmitting?: boolean;
|
|
263
|
+
/**
|
|
264
|
+
* Go back: advances to the previous step, or — on the first step, when the
|
|
265
|
+
* consumer passed an `onBack` prop — invokes that callback instead. No-op on
|
|
266
|
+
* the first step when no `onBack` prop was provided.
|
|
267
|
+
*/
|
|
268
|
+
onBack: () => void;
|
|
269
|
+
/**
|
|
270
|
+
* Advance to the next step (or trigger submit on the last step). The wrapper
|
|
271
|
+
* passes `isLastStep` so the implementation can decide between an in-flow
|
|
272
|
+
* advance and a form submit.
|
|
273
|
+
*/
|
|
274
|
+
onContinue: () => void;
|
|
275
|
+
/** Translated label of the group, or empty string for orphan steps. */
|
|
276
|
+
label?: string;
|
|
277
|
+
/** The rendered child nodes belonging to this step. */
|
|
278
|
+
children: ReactNode;
|
|
85
279
|
};
|
|
86
280
|
/**
|
|
87
281
|
* Custom renderer components
|
|
@@ -97,21 +291,42 @@ export type TreegeRendererComponents = {
|
|
|
97
291
|
*/
|
|
98
292
|
ui?: Partial<Record<UIType, (props: NodeRenderProps) => ReactNode>>;
|
|
99
293
|
/**
|
|
100
|
-
* Custom
|
|
294
|
+
* Custom input label, shared by every default input renderer. Receives
|
|
295
|
+
* `{ label, required, ...platformProps }` and should render nothing when
|
|
296
|
+
* `label` is empty. Defaults to `DefaultInputLabel` (web/native).
|
|
297
|
+
*/
|
|
298
|
+
inputLabel?: InputLabelRenderer;
|
|
299
|
+
/**
|
|
300
|
+
* Custom step renderer — wraps the current step's nodes and renders the
|
|
301
|
+
* Back/Continue navigation. Defaults are provided by `DefaultStep` (web/native).
|
|
101
302
|
*/
|
|
102
|
-
|
|
303
|
+
step?: (props: StepRenderProps) => ReactNode;
|
|
103
304
|
/**
|
|
104
|
-
* Custom form wrapper
|
|
305
|
+
* Custom form wrapper. `id` (when provided via the `formId` prop) should be
|
|
306
|
+
* forwarded to the underlying `<form>` element to keep external submit
|
|
307
|
+
* buttons working.
|
|
105
308
|
*/
|
|
106
309
|
form?: (props: {
|
|
107
310
|
children: ReactNode;
|
|
108
|
-
|
|
311
|
+
id?: string;
|
|
312
|
+
onSubmit: (e: FormEvent<HTMLFormElement>) => void;
|
|
109
313
|
}) => ReactNode;
|
|
110
314
|
/**
|
|
111
|
-
* Custom submit button (
|
|
315
|
+
* Custom submit button (supports both web and native variants)
|
|
316
|
+
* Web variant: { label?: string; disabled?: boolean; isSubmitting?: boolean; ...otherHTMLAttributes }
|
|
317
|
+
* Native variant: { children?: ReactNode; disabled?: boolean; isSubmitting?: boolean; onPress?: () => void }
|
|
112
318
|
*/
|
|
113
319
|
submitButton?: (props: {
|
|
114
320
|
label?: string;
|
|
321
|
+
disabled?: boolean;
|
|
322
|
+
isSubmitting?: boolean;
|
|
323
|
+
[key: string]: unknown;
|
|
324
|
+
} | {
|
|
325
|
+
children?: ReactNode;
|
|
326
|
+
disabled?: boolean;
|
|
327
|
+
isSubmitting?: boolean;
|
|
328
|
+
onPress?: () => void;
|
|
329
|
+
[key: string]: unknown;
|
|
115
330
|
}) => ReactNode;
|
|
116
331
|
/**
|
|
117
332
|
* Custom submit button wrapper (e.g., for tooltip with missing fields)
|
|
@@ -120,9 +335,14 @@ export type TreegeRendererComponents = {
|
|
|
120
335
|
children: ReactNode;
|
|
121
336
|
missingFields?: string[];
|
|
122
337
|
}) => ReactNode;
|
|
338
|
+
/**
|
|
339
|
+
* Custom loading skeleton, rendered in place of the form while the
|
|
340
|
+
* `isLoading` prop is true. Defaults to `DefaultLoadingSkeleton` (web).
|
|
341
|
+
*/
|
|
342
|
+
loadingSkeleton?: () => ReactNode;
|
|
123
343
|
};
|
|
124
344
|
/**
|
|
125
|
-
* Configuration options that can be set globally via
|
|
345
|
+
* Configuration options that can be set globally via TreegeRendererProvider
|
|
126
346
|
* or locally via TreegeRenderer config prop
|
|
127
347
|
*/
|
|
128
348
|
export type TreegeRendererConfig = {
|
|
@@ -130,6 +350,15 @@ export type TreegeRendererConfig = {
|
|
|
130
350
|
* Custom component renderers
|
|
131
351
|
*/
|
|
132
352
|
components?: TreegeRendererComponents;
|
|
353
|
+
/**
|
|
354
|
+
* Global HTTP headers applied to every request issued by the renderer
|
|
355
|
+
* (HTTP inputs, submit buttons). Field-level headers with the same key
|
|
356
|
+
* (case-insensitive) take precedence over these.
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
* headers={{ Authorization: `Bearer ${accessToken}` }}
|
|
360
|
+
*/
|
|
361
|
+
headers?: HttpHeaders;
|
|
133
362
|
/**
|
|
134
363
|
* Google Maps API key for address autocomplete
|
|
135
364
|
* If not provided, falls back to free Nominatim (OpenStreetMap)
|
|
@@ -150,53 +379,107 @@ export type TreegeRendererConfig = {
|
|
|
150
379
|
* @default "onSubmit"
|
|
151
380
|
*/
|
|
152
381
|
validationMode?: "onChange" | "onSubmit";
|
|
382
|
+
/**
|
|
383
|
+
* Whether to display the "Powered by Treege" credit at the bottom of the form.
|
|
384
|
+
* @default true
|
|
385
|
+
*/
|
|
386
|
+
showPoweredBy?: boolean;
|
|
387
|
+
/**
|
|
388
|
+
* Base URL prepended to every **relative** HTTP url issued by the renderer
|
|
389
|
+
* (HTTP inputs, dynamic options, and submit). Use this to keep the tree
|
|
390
|
+
* JSON environment-agnostic — store relative paths in the tree and supply
|
|
391
|
+
* the host here per environment:
|
|
392
|
+
*
|
|
393
|
+
* @example
|
|
394
|
+
* // In the tree: "url": "/v2/entities/{{nodeId}}/sub-entities"
|
|
395
|
+
* <TreegeRenderer flow={tree} baseUrl={import.meta.env.VITE_API_URL} />
|
|
396
|
+
*
|
|
397
|
+
* Absolute urls (starting with `http://` or `https://`) are left untouched,
|
|
398
|
+
* so a field can still point at an external API. Template variables are
|
|
399
|
+
* resolved first, then the base URL is applied to the result.
|
|
400
|
+
*/
|
|
401
|
+
baseUrl?: string;
|
|
153
402
|
};
|
|
154
403
|
/**
|
|
155
404
|
* Props for the TreegeRenderer component
|
|
405
|
+
*
|
|
406
|
+
* Inherits all configuration fields from TreegeRendererConfig (components,
|
|
407
|
+
* headers, googleApiKey, language, theme, validationMode) and adds the
|
|
408
|
+
* instance-specific ones (flow, callbacks, initial values, etc.).
|
|
156
409
|
*/
|
|
157
|
-
export
|
|
410
|
+
export interface TreegeRendererProps extends TreegeRendererConfig {
|
|
158
411
|
/**
|
|
159
|
-
*
|
|
412
|
+
* Additional class name for the renderer container
|
|
160
413
|
*/
|
|
161
|
-
|
|
414
|
+
className?: string;
|
|
162
415
|
/**
|
|
163
|
-
*
|
|
164
|
-
* -
|
|
165
|
-
*
|
|
416
|
+
* Extra data injected into every submission, merged at the top level of both
|
|
417
|
+
* the `onSubmit` payload and the built-in HTTP submit body. Use it for values
|
|
418
|
+
* owned by the host app rather than the form (e.g. the logged-in `userId`).
|
|
419
|
+
* See {@link ExtraPayload}.
|
|
420
|
+
*
|
|
421
|
+
* @example
|
|
422
|
+
* <TreegeRenderer flow={tree} extraPayload={{ userId }} />
|
|
423
|
+
* @example
|
|
424
|
+
* <TreegeRenderer flow={tree} extraPayload={() => ({ token: getToken() })} />
|
|
166
425
|
*/
|
|
167
|
-
|
|
426
|
+
extraPayload?: ExtraPayload;
|
|
168
427
|
/**
|
|
169
|
-
*
|
|
170
|
-
* If not provided, falls back to free Nominatim (OpenStreetMap)
|
|
428
|
+
* Flow to render. `null` / `undefined` renders nothing.
|
|
171
429
|
*/
|
|
172
|
-
|
|
430
|
+
flow?: Flow | null;
|
|
173
431
|
/**
|
|
174
|
-
*
|
|
432
|
+
* Sets the `id` attribute on the underlying `<form>` element, so a submit
|
|
433
|
+
* button rendered outside the renderer can target it via the native HTML
|
|
434
|
+
* `form` attribute: `<button type="submit" form={formId}>`. Web only.
|
|
435
|
+
*/
|
|
436
|
+
formId?: string;
|
|
437
|
+
/**
|
|
438
|
+
* Initial form values — use this to pre-fill the form when editing a record
|
|
439
|
+
* that was already submitted.
|
|
440
|
+
*
|
|
441
|
+
* Keys can be either `node.id` OR the same name-based keys you receive back in
|
|
442
|
+
* `onChange` / `onSubmit`, so the previously-submitted object can be fed
|
|
443
|
+
* straight back in without any remapping.
|
|
444
|
+
*
|
|
445
|
+
* Reactive: if this changes after mount (e.g. an async-fetched record resolves
|
|
446
|
+
* later), the form is re-seeded automatically. A new object literal of
|
|
447
|
+
* identical content does NOT reset the form, so in-progress user edits are
|
|
448
|
+
* preserved.
|
|
175
449
|
*/
|
|
176
450
|
initialValues?: FormValues;
|
|
177
451
|
/**
|
|
178
|
-
*
|
|
452
|
+
* When true, renders a loading skeleton instead of the form. Useful while
|
|
453
|
+
* the flow is being fetched. Customizable via `components.loadingSkeleton`.
|
|
179
454
|
*/
|
|
180
|
-
|
|
455
|
+
isLoading?: boolean;
|
|
456
|
+
/**
|
|
457
|
+
* When true, forces the submit/continue button into its loading state
|
|
458
|
+
* (spinner + disabled). Use this to keep the button busy while an async
|
|
459
|
+
* `onSubmit` is still resolving on the consumer side. It is OR-ed with the
|
|
460
|
+
* renderer's own internal submitting state, so it only ever adds to it.
|
|
461
|
+
*/
|
|
462
|
+
isSubmitting?: boolean;
|
|
463
|
+
/**
|
|
464
|
+
* Called when the user clicks Back on the FIRST step. Provide this to bridge
|
|
465
|
+
* back-navigation to an outer flow (e.g. a parent modal's steps): when set, a
|
|
466
|
+
* Back button is shown on the first step and triggers this callback instead
|
|
467
|
+
* of being a no-op. Has no effect on later steps, which always navigate back
|
|
468
|
+
* internally.
|
|
469
|
+
*/
|
|
470
|
+
onBack?: () => void;
|
|
181
471
|
/**
|
|
182
472
|
* Callback when form values change
|
|
183
473
|
*/
|
|
184
474
|
onChange?: (values: FormValues) => void;
|
|
185
475
|
/**
|
|
186
476
|
* Callback when form is submitted
|
|
477
|
+
* @param values - Form values (keyed by field name or node ID)
|
|
478
|
+
* @param meta - Optional metadata about the submission (e.g., HTTP response data)
|
|
187
479
|
*/
|
|
188
|
-
onSubmit?: (values: FormValues) => void;
|
|
189
|
-
/**
|
|
190
|
-
* Theme for the renderer
|
|
191
|
-
* @default "dark"
|
|
192
|
-
*/
|
|
193
|
-
theme?: "dark" | "light";
|
|
480
|
+
onSubmit?: (values: FormValues, meta?: Meta) => void;
|
|
194
481
|
/**
|
|
195
482
|
* Custom validation function
|
|
196
483
|
*/
|
|
197
484
|
validate?: (values: FormValues, nodes: Node<TreegeNodeData>[]) => Record<string, string>;
|
|
198
|
-
|
|
199
|
-
* Validation mode
|
|
200
|
-
*/
|
|
201
|
-
validationMode?: "onChange" | "onSubmit";
|
|
202
|
-
};
|
|
485
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ExtraPayload, FormValues } from '../types/renderer';
|
|
2
|
+
/**
|
|
3
|
+
* Merge the consumer-provided `extraPayload` onto a base submission payload.
|
|
4
|
+
* This is the single chokepoint behind the `extraPayload` prop, used both for
|
|
5
|
+
* the `onSubmit` callback payload and the built-in HTTP submit body.
|
|
6
|
+
*
|
|
7
|
+
* `extraPayload` may be a static object or a function of the current
|
|
8
|
+
* (name-keyed) values — the function form lets the extra data be read at submit
|
|
9
|
+
* time (e.g. a freshly-read auth token). The extra fields are spread **last**,
|
|
10
|
+
* so a consumer-injected key (e.g. `userId`) intentionally wins over a
|
|
11
|
+
* same-named form field.
|
|
12
|
+
*
|
|
13
|
+
* Edge cases:
|
|
14
|
+
* - No `extraPayload`, or it resolves to a non-object (array / primitive) →
|
|
15
|
+
* the base is returned untouched (nothing to merge).
|
|
16
|
+
* - Base is `undefined`/`null` (e.g. a submit config that would otherwise send
|
|
17
|
+
* no body) → the extra is sent on its own, so the injected data still goes out.
|
|
18
|
+
* - Base is a non-object → returned untouched, since there is no top level to
|
|
19
|
+
* merge into.
|
|
20
|
+
*/
|
|
21
|
+
export declare const mergeExtraPayload: <T>(base: T, extraPayload: ExtraPayload | undefined, values: FormValues) => T | Record<string, unknown>;
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
export interface SerializableFile {
|
|
5
|
-
name: string;
|
|
6
|
-
size: number;
|
|
7
|
-
type: string;
|
|
8
|
-
lastModified: number;
|
|
9
|
-
data: string;
|
|
10
|
-
}
|
|
1
|
+
import { SerializableFile } from '../../shared/types/file';
|
|
2
|
+
export type { SerializableFile };
|
|
11
3
|
/**
|
|
12
4
|
* Converts a File object to a serializable format with base64 data
|
|
13
5
|
*/
|
|
@@ -20,3 +12,25 @@ export declare const serializableToFile: (serializable: SerializableFile) => Fil
|
|
|
20
12
|
* Converts multiple File objects to serializable format
|
|
21
13
|
*/
|
|
22
14
|
export declare const filesToSerializable: (files: File[]) => Promise<SerializableFile[]>;
|
|
15
|
+
/**
|
|
16
|
+
* Derive a readable file name from a URL's last path segment (query/hash stripped).
|
|
17
|
+
*/
|
|
18
|
+
export declare const fileNameFromUrl: (url: string) => string;
|
|
19
|
+
/**
|
|
20
|
+
* Whether a file's `data` is a URL to fetch/link to (an http(s) or relative
|
|
21
|
+
* path) rather than inline base64/blob content. Useful to decide whether to
|
|
22
|
+
* render the file as a clickable link or resolve it against a base URL.
|
|
23
|
+
*/
|
|
24
|
+
export declare const isRemoteFileData: (data: string | null | undefined) => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Normalizes a file field value into an array of `SerializableFile`.
|
|
27
|
+
* Handles a single file, an array, and empty (`null`/`undefined`) values. A
|
|
28
|
+
* stored document may also be referenced by a bare URL string (or an array
|
|
29
|
+
* containing some) — those are coerced into a `SerializableFile` whose `data`
|
|
30
|
+
* holds the URL and whose `name` is derived from it.
|
|
31
|
+
*/
|
|
32
|
+
export declare const normalizeSerializableFiles: (value: SerializableFile | string | Array<SerializableFile | string> | null | undefined) => SerializableFile[];
|
|
33
|
+
/**
|
|
34
|
+
* Formats a byte size into a human-readable string (B / KB / MB)
|
|
35
|
+
*/
|
|
36
|
+
export declare const formatFileSize: (size: number) => string;
|
|
@@ -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 {
|
|
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;
|
|
@@ -17,10 +17,62 @@ export declare const isFieldEmpty: (value: unknown) => boolean;
|
|
|
17
17
|
* @returns True if the field has been filled (any value except undefined/null), false otherwise
|
|
18
18
|
*/
|
|
19
19
|
export declare const checkFormFieldHasValue: (fieldName: string | undefined, formValues: FormValues) => boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Resolve the default value for a single input node given the current form
|
|
22
|
+
* values. Mirrors the seeding rules used at mount:
|
|
23
|
+
* - `static`: returns the configured `staticValue`
|
|
24
|
+
* - `reference`: returns the (raw, untransformed) value of the referenced field
|
|
25
|
+
* if that field currently has a value
|
|
26
|
+
*
|
|
27
|
+
* Returns `undefined` when the node has no applicable default. The raw
|
|
28
|
+
* reference value is intentionally returned untransformed — transformations are
|
|
29
|
+
* handled separately by `calculateReferenceFieldUpdates`.
|
|
30
|
+
*
|
|
31
|
+
* @param node - The input node
|
|
32
|
+
* @param values - Current form values (keyed by node id)
|
|
33
|
+
* @returns The default value to apply, or `undefined`
|
|
34
|
+
*/
|
|
35
|
+
export declare const resolveNodeDefaultValue: (node: Node<InputNodeData>, values: FormValues) => unknown;
|
|
36
|
+
/**
|
|
37
|
+
* Build the initial (nodeId-keyed) form state from consumer-provided values.
|
|
38
|
+
*
|
|
39
|
+
* Consumers can pass `initialValues` keyed either by `node.id` OR by the same
|
|
40
|
+
* key shape they receive back in `onChange`/`onSubmit` (resolved via
|
|
41
|
+
* `resolveNodeKey`: name > label > node.id). This lets an edit screen feed the
|
|
42
|
+
* previously-submitted object straight back in without any remapping.
|
|
43
|
+
*
|
|
44
|
+
* After normalizing provided values, node `defaultValue`s (static / reference)
|
|
45
|
+
* are applied to any field still left unset — matching a fresh mount.
|
|
46
|
+
*
|
|
47
|
+
* @param initialValues - Values provided by the consumer (id- or name-keyed)
|
|
48
|
+
* @param inputNodes - All input nodes of the flow
|
|
49
|
+
* @returns Form values keyed strictly by node id
|
|
50
|
+
*/
|
|
51
|
+
export declare const buildInitialFormValues: (initialValues: FormValues, inputNodes: Node<InputNodeData>[]) => FormValues;
|
|
20
52
|
/**
|
|
21
53
|
* Convert internal form values (keyed by nodeId) to external format (keyed by name)
|
|
22
54
|
* When multiple nodes share the same name, later values overwrite earlier ones
|
|
23
|
-
*
|
|
24
|
-
*
|
|
55
|
+
* Priority for key naming: name > label (en) > nodeId
|
|
56
|
+
* example: convertFormValuesToNamedFormat({ id1: 'Alice', id2: 'Bob' }, [ { id: 'id1', data: { name: 'firstName' } }, { id: 'id2', data: { label: { en: 'Last Name' } } } ])
|
|
57
|
+
* returns { firstName: 'Alice', 'Last Name': 'Bob' }
|
|
25
58
|
*/
|
|
26
59
|
export declare const convertFormValuesToNamedFormat: (formValues: FormValues, nodes: Node<InputNodeData>[]) => Record<string, unknown>;
|
|
60
|
+
/**
|
|
61
|
+
* Apply transformation to a reference field value
|
|
62
|
+
* @param value - The source value to transform
|
|
63
|
+
* @param transformFunction - The transformation function to apply
|
|
64
|
+
* @param objectMapping - Optional mapping for toObject transformation
|
|
65
|
+
* @returns The transformed value
|
|
66
|
+
*/
|
|
67
|
+
export declare const applyReferenceTransformation: (value: unknown, transformFunction: "toString" | "toNumber" | "toBoolean" | "toArray" | "toObject" | null | undefined, objectMapping?: Array<{
|
|
68
|
+
sourceKey: string;
|
|
69
|
+
targetKey: string;
|
|
70
|
+
}>) => unknown;
|
|
71
|
+
/**
|
|
72
|
+
* Calculate updated values for fields with reference defaults
|
|
73
|
+
* @param inputNodes - Array of input nodes
|
|
74
|
+
* @param formValues - Current form values
|
|
75
|
+
* @param prevFormValues - Previous form values (for change detection)
|
|
76
|
+
* @returns Object containing fields that need to be updated
|
|
77
|
+
*/
|
|
78
|
+
export declare const calculateReferenceFieldUpdates: (inputNodes: Node<InputNodeData>[], formValues: FormValues, prevFormValues: FormValues) => FormValues;
|