treege 2.1.0 → 3.0.0-beta.2
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/README.md +378 -64
- package/dist/ThemeContext-BIvs8Kw-.js +758 -0
- package/dist/TreegeEditor-BSPfQQk3.js +2151 -0
- package/dist/TreegeRenderer-D3EvsEfJ.js +1413 -0
- package/dist/_name_.css +1 -0
- package/dist/editor/components/data-display/logo.d.ts +5 -0
- package/dist/editor/components/input/ComboboxWithCreate.d.ts +21 -0
- package/dist/editor/constants/defaultNode.d.ts +11 -0
- package/dist/editor/constants/edgeTypes.d.ts +3 -0
- package/dist/editor/constants/nodeTypes.d.ts +6 -0
- package/dist/editor/context/TreegeEditorContext.d.ts +12 -0
- package/dist/editor/features/TreegeEditor/TreegeEditor.d.ts +3 -0
- package/dist/editor/features/TreegeEditor/edges/ConditionalEdge.d.ts +6 -0
- package/dist/editor/features/TreegeEditor/forms/FlowNodeForm.d.ts +2 -0
- package/dist/editor/features/TreegeEditor/forms/GroupNodeForm.d.ts +2 -0
- package/dist/editor/features/TreegeEditor/forms/HttpConfigForm.d.ts +7 -0
- package/dist/editor/features/TreegeEditor/forms/InputNodeForm.d.ts +2 -0
- package/dist/editor/features/TreegeEditor/forms/UINodeForm.d.ts +2 -0
- package/dist/editor/features/TreegeEditor/inputs/ComboboxPattern.d.ts +6 -0
- package/dist/editor/features/TreegeEditor/inputs/SelectInputType.d.ts +7 -0
- package/dist/editor/features/TreegeEditor/inputs/SelectLanguage.d.ts +7 -0
- package/dist/editor/features/TreegeEditor/inputs/SelectNodeGroup.d.ts +2 -0
- package/dist/editor/features/TreegeEditor/inputs/SelectNodeType.d.ts +2 -0
- package/dist/editor/features/TreegeEditor/nodes/FlowNode.d.ts +6 -0
- package/dist/editor/features/TreegeEditor/nodes/GroupNode.d.ts +6 -0
- package/dist/editor/features/TreegeEditor/nodes/InputNode.d.ts +6 -0
- package/dist/editor/features/TreegeEditor/nodes/UINode.d.ts +6 -0
- package/dist/editor/features/TreegeEditor/nodes/layout/NodeWrapper.d.ts +6 -0
- package/dist/editor/features/TreegeEditor/panel/ActionsPanel.d.ts +7 -0
- package/dist/editor/features/TreegeEditor/sheets/NodeActionsSheet.d.ts +2 -0
- package/dist/editor/hooks/useAvailableParentFields.d.ts +7 -0
- package/dist/editor/hooks/useEdgesSelection.d.ts +11 -0
- package/dist/editor/hooks/useFlowActions.d.ts +12 -0
- package/dist/editor/hooks/useFlowConnections.d.ts +15 -0
- package/dist/editor/hooks/useNodesSelection.d.ts +54 -0
- package/dist/editor/hooks/useTranslate.d.ts +19 -0
- package/dist/editor/index.d.ts +4 -0
- package/dist/editor/types/editor.d.ts +37 -0
- package/dist/editor.d.ts +2 -0
- package/dist/editor.js +7 -0
- package/dist/favicon.svg +12 -0
- package/dist/main.d.ts +7 -4
- package/dist/main.js +50 -7672
- package/dist/renderer/context/TreegeConfigContext.d.ts +39 -0
- package/dist/renderer/context/TreegeRendererContext.d.ts +25 -0
- package/dist/renderer/features/TreegeRenderer/native/TreegeRenderer.d.ts +13 -0
- package/dist/renderer/features/TreegeRenderer/native/components/DefaultFormWrapper.d.ts +7 -0
- package/dist/renderer/features/TreegeRenderer/native/components/DefaultGroup.d.ts +7 -0
- package/dist/renderer/features/TreegeRenderer/native/components/DefaultHttpInput.d.ts +15 -0
- package/dist/renderer/features/TreegeRenderer/native/components/DefaultInputs.d.ts +15 -0
- package/dist/renderer/features/TreegeRenderer/native/components/DefaultSubmitButton.d.ts +7 -0
- package/dist/renderer/features/TreegeRenderer/native/components/DefaultUI.d.ts +7 -0
- package/dist/renderer/features/TreegeRenderer/useTreegeRenderer.d.ts +50 -0
- package/dist/renderer/features/TreegeRenderer/web/TreegeRenderer.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/web/components/DefaultFormWrapper.d.ts +6 -0
- package/dist/renderer/features/TreegeRenderer/web/components/DefaultGroup.d.ts +6 -0
- package/dist/renderer/features/TreegeRenderer/web/components/DefaultInputs.d.ts +20 -0
- package/dist/renderer/features/TreegeRenderer/web/components/DefaultSubmitButton.d.ts +9 -0
- package/dist/renderer/features/TreegeRenderer/web/components/DefaultSubmitButtonWrapper.d.ts +10 -0
- package/dist/renderer/features/TreegeRenderer/web/components/DefaultUI.d.ts +7 -0
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultAddressInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultAutocompleteInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultCheckboxInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultDateInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultDateRangeInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultFileInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultHiddenInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultHttpInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultNumberInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultPasswordInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultRadioInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultSelectInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultSwitchInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultTextAreaInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultTextInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultTimeInput.d.ts +3 -0
- package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultTimeRangeInput.d.ts +3 -0
- package/dist/renderer/hooks/useTranslate.d.ts +24 -0
- package/dist/renderer/index.d.ts +17 -0
- package/dist/renderer/types/renderer.d.ts +187 -0
- package/dist/renderer/utils/conditions.d.ts +14 -0
- package/dist/renderer/utils/file.d.ts +22 -0
- package/dist/renderer/utils/flow.d.ts +91 -0
- package/dist/renderer/utils/form.d.ts +26 -0
- package/dist/renderer/utils/node.d.ts +16 -0
- package/dist/renderer.d.ts +2 -0
- package/dist/renderer.js +45 -0
- package/dist/shared/components/ui/badge.d.ts +9 -0
- package/dist/shared/components/ui/button.d.ts +10 -0
- package/dist/shared/components/ui/calendar.d.ts +8 -0
- package/dist/shared/components/ui/checkbox.d.ts +4 -0
- package/dist/shared/components/ui/collapsible.d.ts +5 -0
- package/dist/shared/components/ui/command.d.ts +18 -0
- package/dist/shared/components/ui/dialog.d.ts +15 -0
- package/dist/shared/components/ui/dropdown-menu.d.ts +25 -0
- package/dist/shared/components/ui/form.d.ts +5 -0
- package/dist/shared/components/ui/input.d.ts +3 -0
- package/dist/shared/components/ui/label.d.ts +4 -0
- package/dist/shared/components/ui/popover.d.ts +7 -0
- package/dist/shared/components/ui/radio-group.d.ts +5 -0
- package/dist/shared/components/ui/scroll-area.d.ts +5 -0
- package/dist/shared/components/ui/select.d.ts +15 -0
- package/dist/shared/components/ui/separator.d.ts +4 -0
- package/dist/shared/components/ui/sheet.d.ts +13 -0
- package/dist/shared/components/ui/sonner.d.ts +3 -0
- package/dist/shared/components/ui/switch.d.ts +4 -0
- package/dist/shared/components/ui/textarea.d.ts +3 -0
- package/dist/shared/components/ui/tooltip.d.ts +7 -0
- package/dist/shared/constants/inputType.d.ts +19 -0
- package/dist/shared/constants/languages.d.ts +10 -0
- package/dist/shared/constants/node.d.ts +6 -0
- package/dist/shared/constants/operator.d.ts +4 -0
- package/dist/shared/constants/pattern.d.ts +7 -0
- package/dist/shared/constants/uiType.d.ts +4 -0
- package/dist/shared/context/ThemeContext.d.ts +15 -0
- package/dist/shared/hooks/useTranslate.d.ts +23 -0
- package/dist/shared/lib/utils.d.ts +2 -0
- package/dist/shared/locales/ar.json.d.ts +229 -0
- package/dist/shared/locales/de.json.d.ts +229 -0
- package/dist/shared/locales/en.json.d.ts +229 -0
- package/dist/shared/locales/es.json.d.ts +229 -0
- package/dist/shared/locales/fr.json.d.ts +229 -0
- package/dist/shared/locales/it.json.d.ts +229 -0
- package/dist/shared/locales/pt.json.d.ts +229 -0
- package/dist/shared/types/edge.d.ts +34 -0
- package/dist/shared/types/languages.d.ts +5 -0
- package/dist/shared/types/node.d.ts +171 -0
- package/dist/shared/types/operator.d.ts +9 -0
- package/dist/shared/types/translate.d.ts +9 -0
- package/dist/shared/utils/nodeTypeGuards.d.ts +22 -0
- package/dist/shared/utils/translations.d.ts +30 -0
- package/package.json +69 -41
- package/CHANGELOG.md +0 -7
- package/dist/components/DataDisplay/Icons/TreePlusIcon.d.ts +0 -7
- package/dist/components/DataDisplay/Logo/Logo.d.ts +0 -2
- package/dist/components/DataDisplay/Tree/Tree.d.ts +0 -14
- package/dist/components/DataDisplay/Tree/useTree.d.ts +0 -12
- package/dist/components/DataDisplay/TreeCard/TreeCard.d.ts +0 -14
- package/dist/components/DataDisplay/ViewerJSON/ViewerJSON.d.ts +0 -6
- package/dist/components/DataDisplay/ViewerJSON/useViewerJSON.d.ts +0 -4
- package/dist/components/DataDisplay/ViewerJSONAction/ViewerJSONAction.d.ts +0 -6
- package/dist/components/DataDisplay/ViewerJSONAction/useViewerJSONAction.d.ts +0 -11
- package/dist/components/FeedBack/MainModal/MainModal.d.ts +0 -10
- package/dist/components/FeedBack/TreeModal/TreeModal.d.ts +0 -13
- package/dist/components/Layouts/Action/Action.d.ts +0 -6
- package/dist/components/Layouts/Header/Header.d.ts +0 -6
- package/dist/components/Layouts/Main/Main.d.ts +0 -6
- package/dist/components/Layouts/MosaicLayout/MosaicLayout.d.ts +0 -6
- package/dist/components/Layouts/Sidebar/Sidebar.d.ts +0 -6
- package/dist/components/Theme/DarkTheme/DarkTheme.d.ts +0 -6
- package/dist/config/i18n.config.d.ts +0 -2
- package/dist/config/query.config.d.ts +0 -3
- package/dist/config/test.config.d.ts +0 -0
- package/dist/config/theme.config.d.ts +0 -3
- package/dist/constants/colors.d.ts +0 -10
- package/dist/constants/fields.d.ts +0 -152
- package/dist/context/Auth/AuthContext.d.ts +0 -7
- package/dist/context/Auth/AuthProvider.d.ts +0 -7
- package/dist/features/Treege/Treege.d.ts +0 -24
- package/dist/features/Treege/components/Feedback/EndPointWarning.d.ts +0 -8
- package/dist/features/Treege/components/Forms/AssignValueToChildren/AssignValueToChildren.d.ts +0 -8
- package/dist/features/Treege/components/Forms/AssignValueToChildren/Examples/ObjectMappingExample.d.ts +0 -2
- package/dist/features/Treege/components/Forms/FormTreeCardDelete/FormTreeCardDelete.d.ts +0 -5
- package/dist/features/Treege/components/Forms/FormTreeCardDelete/useFormTreeCardDelete.d.ts +0 -5
- package/dist/features/Treege/components/Forms/FormTreeCardMutation/Fields/ApiFieldsConfigAccordion.d.ts +0 -32
- package/dist/features/Treege/components/Forms/FormTreeCardMutation/Fields/ExtraField.d.ts +0 -15
- package/dist/features/Treege/components/Forms/FormTreeCardMutation/Fields/FillerFieldAccordion.d.ts +0 -14
- package/dist/features/Treege/components/Forms/FormTreeCardMutation/FormTreeCardMutation.d.ts +0 -6
- package/dist/features/Treege/components/Forms/FormTreeCardMutation/useFormTreeCardMutation.d.ts +0 -110
- package/dist/features/Treege/components/Inputs/AutocompleteSelectType/AutocompleteSelectType.d.ts +0 -12
- package/dist/features/Treege/components/Inputs/AutocompleteSelectType/index.d.ts +0 -3
- package/dist/features/Treege/components/Inputs/AutocompleteSelectType/useAutocompleteSelectType.d.ts +0 -305
- package/dist/features/Treege/components/Inputs/ButtonCreateTree/ButtonCreateTree.d.ts +0 -2
- package/dist/features/Treege/components/Inputs/ButtonCreateTree/useButtonCreateTree.d.ts +0 -4
- package/dist/features/Treege/components/Inputs/FieldSelectAutocompleteCreatable.d.ts +0 -12
- package/dist/features/Treege/components/TreeCardContainer/TreeCardContainer.d.ts +0 -8
- package/dist/features/Treege/components/TreeCardContainer/useTreeCardContainer.d.ts +0 -10
- package/dist/features/Treege/components/TreeGrid/TreeGrid.d.ts +0 -2
- package/dist/features/Treege/components/TreeGrid/useTreeGrid.d.ts +0 -9
- package/dist/features/Treege/components/TreeNameTextField/TreeNameTextField.d.ts +0 -2
- package/dist/features/Treege/components/TreeNameTextField/index.d.ts +0 -2
- package/dist/features/Treege/components/TreeNameTextField/useTreeNameTextField.d.ts +0 -9
- package/dist/features/Treege/components/TreeSelect/TreeSelect.d.ts +0 -12
- package/dist/features/Treege/components/TreeSelect/index.d.ts +0 -2
- package/dist/features/Treege/components/TreeSelect/useTreeSelect.d.ts +0 -16
- package/dist/features/Treege/context/TreegeProvider.d.ts +0 -90
- package/dist/features/Treege/reducer/treeReducer.d.ts +0 -35
- package/dist/hooks/useTreegeContext/index.d.ts +0 -3
- package/dist/hooks/useTreegeContext/useTreegeContext.d.ts +0 -2
- package/dist/locales/en/button-en.d.ts +0 -11
- package/dist/locales/en/form-en.d.ts +0 -93
- package/dist/locales/en/modal-en.d.ts +0 -9
- package/dist/locales/en/snackMessage-en.d.ts +0 -13
- package/dist/locales/en/translation-en.d.ts +0 -30
- package/dist/locales/fr/button-fr.d.ts +0 -11
- package/dist/locales/fr/form-fr.d.ts +0 -93
- package/dist/locales/fr/modal-fr.d.ts +0 -9
- package/dist/locales/fr/snackMessage-fr.d.ts +0 -13
- package/dist/locales/fr/translation-fr.d.ts +0 -30
- package/dist/main.umd.cjs +0 -97
- package/dist/services/workflows/mutation/usePatchWorkflowsMutation.d.ts +0 -12
- package/dist/services/workflows/mutation/usePostWorkflowMutation.d.ts +0 -11
- package/dist/services/workflows/query/useWorkflowQuery.d.ts +0 -10
- package/dist/services/workflows/query/useWorkflowsQuery.d.ts +0 -10
- package/dist/utils/index.d.ts +0 -3
- package/dist/utils/tree/appendNode/appendNode.d.ts +0 -83
- package/dist/utils/tree/appendNode/test/mock.d.ts +0 -16
- package/dist/utils/tree/findNodeByUUIDInTree/findNodeByUUIDInTree.d.ts +0 -8
- package/dist/utils/tree/findNodeByUUIDInTree/test/mock.d.ts +0 -12
- package/dist/utils/tree/findParentNodeByUUIDInTree/findParentNodeByUUIDInTree.d.ts +0 -9
- package/dist/utils/tree/findParentNodeByUUIDInTree/test/mock.d.ts +0 -11
- package/dist/utils/tree/getAllAncestorFromTree/getAllAncestorFromTree.d.ts +0 -12
- package/dist/utils/tree/getAllAncestorFromTree/test/mock.d.ts +0 -3
- package/dist/utils/tree/getNode/getNode.d.ts +0 -9
- package/dist/utils/tree/getNode/test/mock.d.ts +0 -12
- package/dist/utils/tree/getTree/getTree.d.ts +0 -9
- package/dist/utils/tree/getTree/test/mock.d.ts +0 -13
- package/dist/utils/tree/getUniqueTagsInTree/getUniqueTagsInTree.d.ts +0 -7
- package/dist/utils/tree/getUniqueTagsInTree/test/getUniqueTagsInTree.d.ts +0 -1
- package/dist/utils/tree/getUniqueTagsInTree/test/mock.d.ts +0 -10
- package/dist/utils/tree/index.d.ts +0 -9
- package/dist/utils/tree/removeNode/removeNode.d.ts +0 -14
- package/dist/utils/tree/removeNode/test/mock.d.ts +0 -14
- package/dist/utils/tree/updateNodeInTree/test/mock.d.ts +0 -14
- package/dist/utils/tree/updateNodeInTree/updateNodeInTree.d.ts +0 -16
- package/dist/utils/uuid/getUUID.d.ts +0 -5
package/README.md
CHANGED
|
@@ -1,104 +1,418 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
<img alt="Treege" src="https://user-images.githubusercontent.com/108873902/189673125-5d1fdaf3-82d1-486f-bb16-01b0554bd4f1.png" style="padding: 20px;" width="auto" height="100" />
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
<h1>Treege</h1>
|
|
5
|
+
<p><strong>Build powerful decision trees with a visual node-based editor</strong></p>
|
|
6
|
+
|
|
7
|
+
[](https://badge.fury.io/js/treege)
|
|
8
|
+
[](https://opensource.org/licenses/ISC)
|
|
9
|
+
|
|
10
|
+
<p>
|
|
11
|
+
<a href="#features">Features</a> •
|
|
12
|
+
<a href="#installation">Installation</a> •
|
|
13
|
+
<a href="#quick-start">Quick Start</a> •
|
|
14
|
+
<a href="#documentation">Documentation</a> •
|
|
15
|
+
<a href="#examples">Examples</a>
|
|
16
|
+
</p>
|
|
4
17
|
</div>
|
|
5
18
|
|
|
6
|
-
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Overview
|
|
22
|
+
|
|
23
|
+
Treege is a modern React library for creating and rendering interactive decision trees. Built on top of ReactFlow, it provides a complete solution for building complex form flows, decision logic, and conditional workflows with an intuitive visual editor.
|
|
24
|
+
|
|
25
|
+
## Features
|
|
7
26
|
|
|
8
|
-
|
|
27
|
+
### Visual Editor (`treege/editor`)
|
|
28
|
+
- **Node-based Interface**: Drag-and-drop editor powered by ReactFlow
|
|
29
|
+
- **5 Node Types**: Flow, Group, Input, JSON, and UI nodes
|
|
30
|
+
- **Conditional Edges**: Advanced logic with AND/OR operators
|
|
31
|
+
- **Multi-language Support**: Built-in translation system
|
|
32
|
+
- **Type-safe**: Full TypeScript support
|
|
9
33
|
|
|
10
|
-
|
|
11
|
-
-
|
|
12
|
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
-
|
|
34
|
+
### Runtime Renderer (`treege/renderer`)
|
|
35
|
+
- **Form Generation**: Automatically render forms from decision trees
|
|
36
|
+
- **Validation**: Built-in required and pattern validation
|
|
37
|
+
- **Conditional Logic**: Dynamic field visibility based on user input
|
|
38
|
+
- **Customizable**: Override default components with your own
|
|
39
|
+
- **Theme Support**: Dark/light mode out of the box
|
|
40
|
+
|
|
41
|
+
### Developer Experience
|
|
42
|
+
- **Modular**: Import only what you need (editor, renderer, or both)
|
|
43
|
+
- **Modern Stack**: React 18/19, TailwindCSS 4, TypeScript 5
|
|
44
|
+
- **Well-typed**: Comprehensive TypeScript definitions
|
|
45
|
+
- **Production Ready**: Battle-tested and actively maintained
|
|
20
46
|
|
|
21
47
|
## Installation
|
|
22
48
|
|
|
23
|
-
```
|
|
49
|
+
```bash
|
|
50
|
+
# npm
|
|
51
|
+
npm install treege
|
|
52
|
+
|
|
53
|
+
# pnpm
|
|
54
|
+
pnpm add treege
|
|
55
|
+
|
|
56
|
+
# yarn
|
|
24
57
|
yarn add treege
|
|
58
|
+
|
|
59
|
+
# bun
|
|
60
|
+
bun add treege
|
|
25
61
|
```
|
|
26
62
|
|
|
27
|
-
##
|
|
63
|
+
## Quick Start
|
|
28
64
|
|
|
29
|
-
|
|
30
|
-
import { Treege } from "treege";
|
|
65
|
+
### Using the Editor
|
|
31
66
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
67
|
+
Create and edit decision trees visually:
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
import { TreegeEditor } from "treege/editor";
|
|
71
|
+
import type { Flow } from "treege";
|
|
72
|
+
|
|
73
|
+
function App() {
|
|
74
|
+
const [flow, setFlow] = useState<Flow | null>(null);
|
|
75
|
+
|
|
76
|
+
const handleSave = (updatedFlow: Flow) => {
|
|
77
|
+
setFlow(updatedFlow);
|
|
78
|
+
console.log("Decision tree saved:", updatedFlow);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<TreegeEditor
|
|
83
|
+
flow={flow}
|
|
84
|
+
onSave={handleSave}
|
|
85
|
+
/>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Using the Renderer
|
|
91
|
+
|
|
92
|
+
Render interactive forms from decision trees:
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
import { TreegeRenderer } from "treege/renderer";
|
|
96
|
+
import type { Flow, FormValues } from "treege";
|
|
97
|
+
|
|
98
|
+
function App() {
|
|
99
|
+
const flow: Flow = {
|
|
100
|
+
id: "flow-1",
|
|
101
|
+
nodes: [
|
|
102
|
+
{
|
|
103
|
+
id: "start",
|
|
104
|
+
type: "input",
|
|
105
|
+
data: {
|
|
106
|
+
name: "username",
|
|
107
|
+
label: "Enter your username",
|
|
108
|
+
required: true
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
],
|
|
112
|
+
edges: []
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const handleSubmit = (values: FormValues) => {
|
|
116
|
+
console.log("Form submitted:", values);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<TreegeRenderer
|
|
121
|
+
flows={flow}
|
|
122
|
+
onSubmit={handleSubmit}
|
|
123
|
+
/>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Using Both Together
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
import { TreegeEditor } from "treege/editor";
|
|
132
|
+
import { TreegeRenderer } from "treege/renderer";
|
|
133
|
+
import { useState } from "react";
|
|
134
|
+
|
|
135
|
+
function App() {
|
|
136
|
+
const [flow, setFlow] = useState(null);
|
|
137
|
+
const [mode, setMode] = useState<"edit" | "preview">("edit");
|
|
138
|
+
|
|
139
|
+
return (
|
|
140
|
+
<div>
|
|
141
|
+
<button onClick={() => setMode(mode === "edit" ? "preview" : "edit")}>
|
|
142
|
+
{mode === "edit" ? "Preview" : "Edit"}
|
|
143
|
+
</button>
|
|
35
144
|
|
|
36
|
-
|
|
145
|
+
{mode === "edit" ? (
|
|
146
|
+
<TreegeEditor flow={flow} onSave={setFlow} />
|
|
147
|
+
) : (
|
|
148
|
+
<TreegeRenderer flows={flow} onSubmit={console.log} />
|
|
149
|
+
)}
|
|
150
|
+
</div>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
37
153
|
```
|
|
38
154
|
|
|
39
|
-
|
|
155
|
+
## Module Structure
|
|
156
|
+
|
|
157
|
+
Treege provides three import paths for optimal bundle size:
|
|
40
158
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
| initialTreeId | string | undefined | false | If provided, this will fetch initial tree id. Cannot provided with `initialTree` in same time |
|
|
45
|
-
| initialTree | object | undefined | false | Initial tree data. Cannot provided with `initialTreeId` in same time |
|
|
159
|
+
```tsx
|
|
160
|
+
// Import everything (editor + renderer + types)
|
|
161
|
+
import { TreegeEditor, TreegeRenderer } from "treege";
|
|
46
162
|
|
|
163
|
+
// Import only the editor
|
|
164
|
+
import { TreegeEditor } from "treege/editor";
|
|
47
165
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
| baseUrl | string | undefined | true | Base url for API communication. ex : https://api.treege.com |
|
|
52
|
-
| authToken | string | undefined | false | Authentication token |
|
|
53
|
-
| endpoints | object | undefined | false | Endpoints configuration |
|
|
166
|
+
// Import only the renderer
|
|
167
|
+
import { TreegeRenderer } from "treege/renderer";
|
|
168
|
+
```
|
|
54
169
|
|
|
55
|
-
|
|
56
|
-
| Props | Type | Default | Required | Detail |
|
|
57
|
-
|-----------|--------|-----------|-----------------|-------------------------------------------------------------|
|
|
58
|
-
| workflow | string | undefined | "/v1/workflow" | Endpoint for `get/post/patch` single `workflow` |
|
|
59
|
-
| workflows | string | undefined | "/v1/workflows" | Endpoint for get all workflows. It is a array on `workflow` |
|
|
170
|
+
## Node Types
|
|
60
171
|
|
|
61
|
-
|
|
172
|
+
### Flow Node
|
|
173
|
+
Navigation node that controls the flow between different parts of the tree.
|
|
62
174
|
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
175
|
+
```tsx
|
|
176
|
+
{
|
|
177
|
+
type: "flow",
|
|
178
|
+
data: {
|
|
179
|
+
targetId: "next-node-id",
|
|
180
|
+
label: "Continue"
|
|
181
|
+
}
|
|
69
182
|
}
|
|
70
183
|
```
|
|
71
184
|
|
|
72
|
-
|
|
185
|
+
### Input Node
|
|
186
|
+
Form input with validation, patterns, and conditional logic.
|
|
73
187
|
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
188
|
+
```tsx
|
|
189
|
+
{
|
|
190
|
+
type: "input",
|
|
191
|
+
data: {
|
|
192
|
+
type: "text",
|
|
193
|
+
name: "email",
|
|
194
|
+
label: "Email Address",
|
|
195
|
+
required: true,
|
|
196
|
+
pattern: "^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$",
|
|
197
|
+
errorMessage: "Please enter a valid email"
|
|
198
|
+
}
|
|
80
199
|
}
|
|
81
200
|
```
|
|
82
201
|
|
|
83
|
-
|
|
202
|
+
Supported input types: `text`, `email`, `password`, `number`, `textarea`, `select`, `radio`, `checkbox`, `switch`, `date`, `dateRange`, `time`, `timeRange`, `file`, `address`, `http`
|
|
84
203
|
|
|
85
|
-
|
|
204
|
+
### Group Node
|
|
205
|
+
Container for organizing multiple nodes together.
|
|
206
|
+
|
|
207
|
+
```tsx
|
|
208
|
+
{
|
|
209
|
+
type: "group",
|
|
210
|
+
data: {
|
|
211
|
+
label: "Personal Information"
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
```
|
|
86
215
|
|
|
87
|
-
|
|
216
|
+
### JSON Node
|
|
217
|
+
Store and manage JSON data within the tree.
|
|
88
218
|
|
|
89
|
-
|
|
219
|
+
```tsx
|
|
220
|
+
{
|
|
221
|
+
type: "json",
|
|
222
|
+
data: {
|
|
223
|
+
json: { key: "value" }
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### UI Node
|
|
229
|
+
Display-only elements (titles, descriptions, separators).
|
|
230
|
+
|
|
231
|
+
```tsx
|
|
232
|
+
{
|
|
233
|
+
type: "ui",
|
|
234
|
+
data: {
|
|
235
|
+
type: "title",
|
|
236
|
+
label: "Welcome to the form"
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Conditional Edges
|
|
242
|
+
|
|
243
|
+
Create dynamic flows with conditional logic:
|
|
244
|
+
|
|
245
|
+
```tsx
|
|
246
|
+
{
|
|
247
|
+
type: "conditional",
|
|
248
|
+
data: {
|
|
249
|
+
conditions: [
|
|
250
|
+
{
|
|
251
|
+
field: "age",
|
|
252
|
+
operator: ">=",
|
|
253
|
+
value: "18"
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
field: "country",
|
|
257
|
+
operator: "===",
|
|
258
|
+
value: "US"
|
|
259
|
+
}
|
|
260
|
+
],
|
|
261
|
+
logicalOperator: "AND"
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
```
|
|
90
265
|
|
|
91
|
-
|
|
266
|
+
Supported operators: `===`, `!==`, `>`, `<`, `>=`, `<=`
|
|
267
|
+
|
|
268
|
+
## Translation Support
|
|
269
|
+
|
|
270
|
+
Treege supports multiple languages out of the box:
|
|
271
|
+
|
|
272
|
+
```tsx
|
|
273
|
+
{
|
|
274
|
+
type: "input",
|
|
275
|
+
data: {
|
|
276
|
+
label: {
|
|
277
|
+
en: "First Name",
|
|
278
|
+
fr: "Prénom",
|
|
279
|
+
es: "Nombre"
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## Customization
|
|
286
|
+
|
|
287
|
+
### Custom Input Components
|
|
288
|
+
|
|
289
|
+
Override default input renderers with your own:
|
|
290
|
+
|
|
291
|
+
```tsx
|
|
292
|
+
import { TreegeRenderer } from "treege/renderer";
|
|
293
|
+
|
|
294
|
+
const CustomTextInput = ({ node }) => {
|
|
295
|
+
return <input className="my-custom-input" />;
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
<TreegeRenderer
|
|
299
|
+
flows={flow}
|
|
300
|
+
components={{
|
|
301
|
+
inputs: {
|
|
302
|
+
text: CustomTextInput
|
|
303
|
+
}
|
|
304
|
+
}}
|
|
305
|
+
/>
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### Custom Validation
|
|
309
|
+
|
|
310
|
+
Add custom validation logic:
|
|
311
|
+
|
|
312
|
+
```tsx
|
|
313
|
+
<TreegeRenderer
|
|
314
|
+
flows={flow}
|
|
315
|
+
validate={(values, visibleNodes) => {
|
|
316
|
+
const errors = {};
|
|
317
|
+
|
|
318
|
+
if (values.password !== values.confirmPassword) {
|
|
319
|
+
errors.confirmPassword = "Passwords must match";
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
return errors;
|
|
323
|
+
}}
|
|
324
|
+
/>
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### Validation Modes
|
|
328
|
+
|
|
329
|
+
Control when validation occurs:
|
|
330
|
+
|
|
331
|
+
```tsx
|
|
332
|
+
// Validate only on submit (default)
|
|
333
|
+
<TreegeRenderer validationMode="onSubmit" />
|
|
334
|
+
|
|
335
|
+
// Validate on every change
|
|
336
|
+
<TreegeRenderer validationMode="onChange" />
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
## Examples
|
|
340
|
+
|
|
341
|
+
Check out the `/example` directory for complete examples:
|
|
342
|
+
|
|
343
|
+
```bash
|
|
344
|
+
# Run the example app
|
|
345
|
+
bun example
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
## API Reference
|
|
349
|
+
|
|
350
|
+
### TreegeEditor Props
|
|
351
|
+
|
|
352
|
+
| Prop | Type | Default | Description |
|
|
353
|
+
|------------|------------------------|----------|-----------------------------|
|
|
354
|
+
| `flow` | `Flow \| null` | `null` | Initial decision tree |
|
|
355
|
+
| `onSave` | `(flow: Flow) => void` | - | Callback when tree is saved |
|
|
356
|
+
| `language` | `string` | `"en"` | UI language |
|
|
357
|
+
| `theme` | `"light" \| "dark"` | `"dark"` | Editor theme |
|
|
358
|
+
|
|
359
|
+
### TreegeRenderer Props
|
|
360
|
+
|
|
361
|
+
| Prop | Type | Default | Description |
|
|
362
|
+
|------------------|---------------------------------------------|--------------|----------------------------|
|
|
363
|
+
| `flows` | `Flow \| null` | - | Decision tree to render |
|
|
364
|
+
| `onSubmit` | `(values: FormValues) => void` | - | Form submission handler |
|
|
365
|
+
| `onChange` | `(values: FormValues) => void` | - | Form change handler |
|
|
366
|
+
| `validate` | `(values, nodes) => Record<string, string>` | - | Custom validation function |
|
|
367
|
+
| `initialValues` | `FormValues` | `{}` | Initial form values |
|
|
368
|
+
| `components` | `RendererComponents` | - | Custom component overrides |
|
|
369
|
+
| `language` | `string` | `"en"` | UI language |
|
|
370
|
+
| `validationMode` | `"onSubmit" \| "onChange"` | `"onSubmit"` | When to validate |
|
|
371
|
+
| `theme` | `"light" \| "dark"` | `"dark"` | Renderer theme |
|
|
372
|
+
| `googleApiKey` | `string` | - | API key for address input |
|
|
373
|
+
|
|
374
|
+
## Development
|
|
375
|
+
|
|
376
|
+
```bash
|
|
377
|
+
# Install dependencies
|
|
92
378
|
yarn install
|
|
379
|
+
|
|
380
|
+
# Start dev server
|
|
381
|
+
yarn dev
|
|
382
|
+
|
|
383
|
+
# Build library
|
|
384
|
+
yarn build
|
|
385
|
+
|
|
386
|
+
# Run linter and type check
|
|
387
|
+
yarn lint
|
|
388
|
+
|
|
389
|
+
# Preview build
|
|
390
|
+
yarn preview
|
|
93
391
|
```
|
|
94
|
-
Locally preview production build
|
|
95
392
|
|
|
96
|
-
##
|
|
393
|
+
## Tech Stack
|
|
394
|
+
|
|
395
|
+
- **React** 18/19 - UI library
|
|
396
|
+
- **TypeScript** - Type safety
|
|
397
|
+
- **TailwindCSS** 4 - Styling
|
|
398
|
+
- **ReactFlow** - Node-based UI
|
|
399
|
+
- **Radix UI** - Accessible components
|
|
400
|
+
- **Zustand** - State management
|
|
401
|
+
- **Vite** - Build tool
|
|
402
|
+
|
|
403
|
+
## Contributing
|
|
404
|
+
|
|
405
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
406
|
+
|
|
407
|
+
## License
|
|
408
|
+
|
|
409
|
+
ISC
|
|
410
|
+
|
|
411
|
+
## Credits
|
|
97
412
|
|
|
98
|
-
|
|
99
|
-
- [Versioning](https://semver.org)
|
|
100
|
-
- [Conventional Commits](https://www.conventionalcommits.org)
|
|
413
|
+
Created and maintained by [Mickaël Austoni](https://github.com/Tracktor)
|
|
101
414
|
|
|
102
|
-
##
|
|
415
|
+
## Support
|
|
103
416
|
|
|
104
|
-
|
|
417
|
+
- [GitHub Issues](https://github.com/Tracktor/treege/issues)
|
|
418
|
+
- [Repository](https://github.com/Tracktor/treege)
|