treege 2.1.0 → 3.0.0-beta.10
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 +448 -63
- package/dist/ThemeContext-BIvs8Kw-.js +758 -0
- package/dist/TreegeEditor--L4cWrS3.js +2152 -0
- package/dist/TreegeRenderer-BVaqgInZ.js +1405 -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 +29 -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 +202 -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 +70 -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,489 @@
|
|
|
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="https://treege.io/">🌐 Website</a> •
|
|
12
|
+
<a href="https://treege.io/playground/">🎮 Playground</a> •
|
|
13
|
+
<a href="#features">Features</a> •
|
|
14
|
+
<a href="#installation">Installation</a> •
|
|
15
|
+
<a href="#quick-start">Quick Start</a> •
|
|
16
|
+
<a href="#examples">Examples</a>
|
|
17
|
+
</p>
|
|
4
18
|
</div>
|
|
5
19
|
|
|
6
|
-
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Overview
|
|
23
|
+
|
|
24
|
+
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.
|
|
25
|
+
|
|
26
|
+
## Features
|
|
27
|
+
|
|
28
|
+
### Visual Editor (`treege/editor`)
|
|
29
|
+
- **Node-based Interface**: Drag-and-drop editor powered by ReactFlow
|
|
30
|
+
- **4 Node Types**: Flow, Group, Input, and UI nodes
|
|
31
|
+
- **Conditional Edges**: Advanced logic with AND/OR operators (`===`, `!==`, `>`, `<`, `>=`, `<=`)
|
|
32
|
+
- **Multi-language Support**: Built-in translation system for all labels
|
|
33
|
+
- **Type-safe**: Full TypeScript support
|
|
34
|
+
- **Mini-map & Controls**: Navigation tools for complex trees
|
|
35
|
+
- **Theme Support**: Dark/light mode with customizable backgrounds
|
|
7
36
|
|
|
8
|
-
|
|
37
|
+
### Runtime Renderer (`treege/renderer`)
|
|
38
|
+
- **Production Ready**: Full-featured form generation and validation system
|
|
39
|
+
- **16 Input Types**: text, number, select, checkbox, radio, date, daterange, time, timerange, file, address, http, textarea, password, switch, autocomplete, and hidden
|
|
40
|
+
- **HTTP Integration**: Built-in API integration with response mapping and search functionality
|
|
41
|
+
- **Advanced Validation**: Required fields, pattern matching, custom validation functions
|
|
42
|
+
- **Conditional Logic**: Dynamic field visibility based on user input and conditional edges
|
|
43
|
+
- **Web & Native**: Both web (React) and React Native renderer implementations
|
|
44
|
+
- **Fully Customizable**: Override any component (FormWrapper, Group, Inputs, SubmitButton, UI elements)
|
|
45
|
+
- **Theme Support**: Dark/light mode out of the box
|
|
46
|
+
- **Google API Integration**: Address autocomplete support
|
|
9
47
|
|
|
10
|
-
|
|
11
|
-
-
|
|
12
|
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
- [Available Scripts](#Available-Scripts)
|
|
16
|
-
- [yarn dev](#yarn-dev)
|
|
17
|
-
- [yarn build](#yarn-build)
|
|
18
|
-
- [yarn preview](#yarn-preview)
|
|
19
|
-
- [Convention](#Convention)
|
|
48
|
+
### Developer Experience
|
|
49
|
+
- **Modular**: Import only what you need (editor, renderer, or both)
|
|
50
|
+
- **Modern Stack**: React 18/19, TailwindCSS 4, TypeScript 5
|
|
51
|
+
- **Well-typed**: Comprehensive TypeScript definitions
|
|
52
|
+
- **Production Ready**: Battle-tested and actively maintained
|
|
20
53
|
|
|
21
54
|
## Installation
|
|
22
55
|
|
|
23
|
-
```
|
|
56
|
+
```bash
|
|
57
|
+
# npm
|
|
58
|
+
npm install treege
|
|
59
|
+
|
|
60
|
+
# pnpm
|
|
61
|
+
pnpm add treege
|
|
62
|
+
|
|
63
|
+
# yarn
|
|
24
64
|
yarn add treege
|
|
65
|
+
|
|
66
|
+
# bun
|
|
67
|
+
bun add treege
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Quick Start
|
|
71
|
+
|
|
72
|
+
### Using the Editor
|
|
73
|
+
|
|
74
|
+
Create and edit decision trees visually:
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
import { TreegeEditor } from "treege/editor";
|
|
78
|
+
import type { Flow } from "treege";
|
|
79
|
+
|
|
80
|
+
function App() {
|
|
81
|
+
const [flow, setFlow] = useState<Flow | null>(null);
|
|
82
|
+
|
|
83
|
+
const handleSave = (updatedFlow: Flow) => {
|
|
84
|
+
setFlow(updatedFlow);
|
|
85
|
+
console.log("Decision tree saved:", updatedFlow);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<TreegeEditor
|
|
90
|
+
flow={flow}
|
|
91
|
+
onSave={handleSave}
|
|
92
|
+
/>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Using the Renderer
|
|
98
|
+
|
|
99
|
+
Render interactive forms from decision trees:
|
|
100
|
+
|
|
101
|
+
```tsx
|
|
102
|
+
import { TreegeRenderer } from "treege/renderer";
|
|
103
|
+
import type { Flow, FormValues } from "treege";
|
|
104
|
+
|
|
105
|
+
function App() {
|
|
106
|
+
const flow: Flow = {
|
|
107
|
+
id: "flow-1",
|
|
108
|
+
nodes: [
|
|
109
|
+
{
|
|
110
|
+
id: "start",
|
|
111
|
+
type: "input",
|
|
112
|
+
data: {
|
|
113
|
+
name: "username",
|
|
114
|
+
label: "Enter your username",
|
|
115
|
+
required: true
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
],
|
|
119
|
+
edges: []
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const handleSubmit = (values: FormValues) => {
|
|
123
|
+
console.log("Form submitted:", values);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
<TreegeRenderer
|
|
128
|
+
flows={flow}
|
|
129
|
+
onSubmit={handleSubmit}
|
|
130
|
+
/>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Using Both Together
|
|
136
|
+
|
|
137
|
+
```tsx
|
|
138
|
+
import { TreegeEditor } from "treege/editor";
|
|
139
|
+
import { TreegeRenderer } from "treege/renderer";
|
|
140
|
+
import { useState } from "react";
|
|
141
|
+
|
|
142
|
+
function App() {
|
|
143
|
+
const [flow, setFlow] = useState(null);
|
|
144
|
+
const [mode, setMode] = useState<"edit" | "preview">("edit");
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<div>
|
|
148
|
+
<button onClick={() => setMode(mode === "edit" ? "preview" : "edit")}>
|
|
149
|
+
{mode === "edit" ? "Preview" : "Edit"}
|
|
150
|
+
</button>
|
|
151
|
+
|
|
152
|
+
{mode === "edit" ? (
|
|
153
|
+
<TreegeEditor flow={flow} onSave={setFlow} />
|
|
154
|
+
) : (
|
|
155
|
+
<TreegeRenderer flows={flow} onSubmit={console.log} />
|
|
156
|
+
)}
|
|
157
|
+
</div>
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Module Structure
|
|
163
|
+
|
|
164
|
+
Treege provides three import paths for optimal bundle size:
|
|
165
|
+
|
|
166
|
+
```tsx
|
|
167
|
+
// Import everything (editor + renderer + types)
|
|
168
|
+
import { TreegeEditor, TreegeRenderer } from "treege";
|
|
169
|
+
|
|
170
|
+
// Import only the editor
|
|
171
|
+
import { TreegeEditor } from "treege/editor";
|
|
172
|
+
|
|
173
|
+
// Import only the renderer
|
|
174
|
+
import { TreegeRenderer } from "treege/renderer";
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Node Types
|
|
178
|
+
|
|
179
|
+
### Flow Node
|
|
180
|
+
Navigation node that controls the flow between different parts of the tree.
|
|
181
|
+
|
|
182
|
+
```tsx
|
|
183
|
+
{
|
|
184
|
+
type: "flow",
|
|
185
|
+
data: {
|
|
186
|
+
targetId: "next-node-id",
|
|
187
|
+
label: "Continue"
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Input Node
|
|
193
|
+
Form input with validation, patterns, and conditional logic.
|
|
194
|
+
|
|
195
|
+
```tsx
|
|
196
|
+
{
|
|
197
|
+
type: "input",
|
|
198
|
+
data: {
|
|
199
|
+
type: "text",
|
|
200
|
+
name: "email",
|
|
201
|
+
label: "Email Address",
|
|
202
|
+
required: true,
|
|
203
|
+
pattern: "^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$",
|
|
204
|
+
errorMessage: "Please enter a valid email"
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Supported input types: `text`, `number`, `textarea`, `password`, `select`, `radio`, `checkbox`, `switch`, `autocomplete`, `date`, `daterange`, `time`, `timerange`, `file`, `address`, `http`, `hidden`
|
|
210
|
+
|
|
211
|
+
### Group Node
|
|
212
|
+
Container for organizing multiple nodes together.
|
|
213
|
+
|
|
214
|
+
```tsx
|
|
215
|
+
{
|
|
216
|
+
type: "group",
|
|
217
|
+
data: {
|
|
218
|
+
label: "Personal Information"
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### UI Node
|
|
224
|
+
Display-only elements for visual organization and content display.
|
|
225
|
+
|
|
226
|
+
```tsx
|
|
227
|
+
{
|
|
228
|
+
type: "ui",
|
|
229
|
+
data: {
|
|
230
|
+
type: "title", // or "divider"
|
|
231
|
+
label: "Welcome to the form"
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Supported UI types:
|
|
237
|
+
- `title` - Display headings and titles
|
|
238
|
+
- `divider` - Visual separator between sections
|
|
239
|
+
|
|
240
|
+
## Conditional Edges
|
|
241
|
+
|
|
242
|
+
Create dynamic flows with conditional logic:
|
|
243
|
+
|
|
244
|
+
```tsx
|
|
245
|
+
{
|
|
246
|
+
type: "conditional",
|
|
247
|
+
data: {
|
|
248
|
+
conditions: [
|
|
249
|
+
{
|
|
250
|
+
field: "age",
|
|
251
|
+
operator: ">=",
|
|
252
|
+
value: "18"
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
field: "country",
|
|
256
|
+
operator: "===",
|
|
257
|
+
value: "US"
|
|
258
|
+
}
|
|
259
|
+
],
|
|
260
|
+
logicalOperator: "AND"
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Supported operators: `===`, `!==`, `>`, `<`, `>=`, `<=`
|
|
266
|
+
|
|
267
|
+
## Translation Support
|
|
268
|
+
|
|
269
|
+
Treege supports multiple languages out of the box:
|
|
270
|
+
|
|
271
|
+
```tsx
|
|
272
|
+
{
|
|
273
|
+
type: "input",
|
|
274
|
+
data: {
|
|
275
|
+
label: {
|
|
276
|
+
en: "First Name",
|
|
277
|
+
fr: "Prénom",
|
|
278
|
+
es: "Nombre"
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
25
282
|
```
|
|
26
283
|
|
|
27
|
-
##
|
|
284
|
+
## Customization
|
|
285
|
+
|
|
286
|
+
### Custom Input Components
|
|
287
|
+
|
|
288
|
+
Override default input renderers with your own:
|
|
28
289
|
|
|
29
|
-
```
|
|
30
|
-
import {
|
|
290
|
+
```tsx
|
|
291
|
+
import { TreegeRenderer } from "treege/renderer";
|
|
31
292
|
|
|
32
|
-
const
|
|
33
|
-
return <
|
|
293
|
+
const CustomTextInput = ({ node }) => {
|
|
294
|
+
return <input className="my-custom-input" />;
|
|
34
295
|
};
|
|
35
296
|
|
|
36
|
-
|
|
297
|
+
<TreegeRenderer
|
|
298
|
+
flows={flow}
|
|
299
|
+
components={{
|
|
300
|
+
inputs: {
|
|
301
|
+
text: CustomTextInput
|
|
302
|
+
}
|
|
303
|
+
}}
|
|
304
|
+
/>
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### Custom Validation
|
|
308
|
+
|
|
309
|
+
Add custom validation logic:
|
|
310
|
+
|
|
311
|
+
```tsx
|
|
312
|
+
<TreegeRenderer
|
|
313
|
+
flows={flow}
|
|
314
|
+
validate={(values, visibleNodes) => {
|
|
315
|
+
const errors = {};
|
|
316
|
+
|
|
317
|
+
if (values.password !== values.confirmPassword) {
|
|
318
|
+
errors.confirmPassword = "Passwords must match";
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return errors;
|
|
322
|
+
}}
|
|
323
|
+
/>
|
|
37
324
|
```
|
|
38
325
|
|
|
39
|
-
###
|
|
326
|
+
### Validation Modes
|
|
40
327
|
|
|
41
|
-
|
|
42
|
-
|---------------|--------|-----------|----------|-----------------------------------------------------------------------------------------------|
|
|
43
|
-
| backendConfig | object | undefined | false | Backend configuration. Only necessary if you want backend communication. |
|
|
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 |
|
|
328
|
+
Control when validation occurs:
|
|
46
329
|
|
|
330
|
+
```tsx
|
|
331
|
+
// Validate only on submit (default)
|
|
332
|
+
<TreegeRenderer validationMode="onSubmit" />
|
|
47
333
|
|
|
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 |
|
|
334
|
+
// Validate on every change
|
|
335
|
+
<TreegeRenderer validationMode="onChange" />
|
|
336
|
+
```
|
|
54
337
|
|
|
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` |
|
|
338
|
+
### HTTP Input Integration
|
|
60
339
|
|
|
61
|
-
|
|
340
|
+
Use the HTTP input type to fetch and map data from APIs:
|
|
62
341
|
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
342
|
+
```tsx
|
|
343
|
+
{
|
|
344
|
+
type: "input",
|
|
345
|
+
data: {
|
|
346
|
+
type: "http",
|
|
347
|
+
name: "country",
|
|
348
|
+
label: "Select your country",
|
|
349
|
+
httpConfig: {
|
|
350
|
+
method: "GET",
|
|
351
|
+
url: "https://api.example.com/countries",
|
|
352
|
+
responsePath: "$.data.countries", // JSONPath to extract data
|
|
353
|
+
mapping: {
|
|
354
|
+
label: "name",
|
|
355
|
+
value: "code"
|
|
356
|
+
},
|
|
357
|
+
searchParam: "query", // Enable search functionality
|
|
358
|
+
fetchOnMount: true
|
|
359
|
+
}
|
|
360
|
+
}
|
|
69
361
|
}
|
|
70
362
|
```
|
|
71
363
|
|
|
72
|
-
|
|
364
|
+
### Global Configuration
|
|
365
|
+
|
|
366
|
+
Configure the renderer globally using the TreegeConfigProvider:
|
|
73
367
|
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
368
|
+
```tsx
|
|
369
|
+
import { TreegeConfigProvider } from "treege/renderer";
|
|
370
|
+
|
|
371
|
+
function App() {
|
|
372
|
+
return (
|
|
373
|
+
<TreegeConfigProvider
|
|
374
|
+
config={{
|
|
375
|
+
language: "fr",
|
|
376
|
+
googleApiKey: "your-google-api-key",
|
|
377
|
+
components: {
|
|
378
|
+
// Your custom components
|
|
379
|
+
}
|
|
380
|
+
}}
|
|
381
|
+
>
|
|
382
|
+
<TreegeRenderer flows={flow} />
|
|
383
|
+
</TreegeConfigProvider>
|
|
384
|
+
);
|
|
80
385
|
}
|
|
81
386
|
```
|
|
82
387
|
|
|
83
|
-
|
|
388
|
+
### Programmatic Control
|
|
389
|
+
|
|
390
|
+
Use the `useTreegeRenderer` hook for programmatic control:
|
|
391
|
+
|
|
392
|
+
```tsx
|
|
393
|
+
import { useTreegeRenderer } from "treege/renderer";
|
|
394
|
+
|
|
395
|
+
function CustomForm() {
|
|
396
|
+
const { values, setFieldValue, submit, reset } = useTreegeRenderer();
|
|
397
|
+
|
|
398
|
+
return (
|
|
399
|
+
<div>
|
|
400
|
+
<button onClick={() => setFieldValue("email", "test@example.com")}>
|
|
401
|
+
Prefill Email
|
|
402
|
+
</button>
|
|
403
|
+
<button onClick={submit}>Submit</button>
|
|
404
|
+
<button onClick={reset}>Reset</button>
|
|
405
|
+
</div>
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
## Examples
|
|
411
|
+
|
|
412
|
+
Check out the `/example` directory for complete examples:
|
|
413
|
+
|
|
414
|
+
```bash
|
|
415
|
+
# Run the example app
|
|
416
|
+
bun example
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
## API Reference
|
|
420
|
+
|
|
421
|
+
### TreegeEditor Props
|
|
84
422
|
|
|
85
|
-
|
|
423
|
+
| Prop | Type | Default | Description |
|
|
424
|
+
|------------|------------------------|----------|-----------------------------|
|
|
425
|
+
| `flow` | `Flow \| null` | `null` | Initial decision tree |
|
|
426
|
+
| `onSave` | `(flow: Flow) => void` | - | Callback when tree is saved |
|
|
427
|
+
| `language` | `string` | `"en"` | UI language |
|
|
428
|
+
| `theme` | `"light" \| "dark"` | `"dark"` | Editor theme |
|
|
86
429
|
|
|
87
|
-
|
|
430
|
+
### TreegeRenderer Props
|
|
88
431
|
|
|
89
|
-
|
|
432
|
+
| Prop | Type | Default | Description |
|
|
433
|
+
|------------------|---------------------------------------------|--------------|----------------------------|
|
|
434
|
+
| `flows` | `Flow \| null` | - | Decision tree to render |
|
|
435
|
+
| `onSubmit` | `(values: FormValues) => void` | - | Form submission handler |
|
|
436
|
+
| `onChange` | `(values: FormValues) => void` | - | Form change handler |
|
|
437
|
+
| `validate` | `(values, nodes) => Record<string, string>` | - | Custom validation function |
|
|
438
|
+
| `initialValues` | `FormValues` | `{}` | Initial form values |
|
|
439
|
+
| `components` | `RendererComponents` | - | Custom component overrides |
|
|
440
|
+
| `language` | `string` | `"en"` | UI language |
|
|
441
|
+
| `validationMode` | `"onSubmit" \| "onChange"` | `"onSubmit"` | When to validate |
|
|
442
|
+
| `theme` | `"light" \| "dark"` | `"dark"` | Renderer theme |
|
|
443
|
+
| `googleApiKey` | `string` | - | API key for address input |
|
|
90
444
|
|
|
91
|
-
|
|
445
|
+
## Development
|
|
446
|
+
|
|
447
|
+
```bash
|
|
448
|
+
# Install dependencies
|
|
92
449
|
yarn install
|
|
450
|
+
|
|
451
|
+
# Start dev server
|
|
452
|
+
yarn dev
|
|
453
|
+
|
|
454
|
+
# Build library
|
|
455
|
+
yarn build
|
|
456
|
+
|
|
457
|
+
# Run linter and type check
|
|
458
|
+
yarn lint
|
|
459
|
+
|
|
460
|
+
# Preview build
|
|
461
|
+
yarn preview
|
|
93
462
|
```
|
|
94
|
-
Locally preview production build
|
|
95
463
|
|
|
96
|
-
##
|
|
464
|
+
## Tech Stack
|
|
465
|
+
|
|
466
|
+
- **React** 18/19 - UI library
|
|
467
|
+
- **TypeScript** - Type safety
|
|
468
|
+
- **TailwindCSS** 4 - Styling
|
|
469
|
+
- **ReactFlow** - Node-based UI
|
|
470
|
+
- **Radix UI** - Accessible components
|
|
471
|
+
- **Zustand** - State management
|
|
472
|
+
- **Vite** - Build tool
|
|
473
|
+
|
|
474
|
+
## Contributing
|
|
475
|
+
|
|
476
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
477
|
+
|
|
478
|
+
## License
|
|
479
|
+
|
|
480
|
+
ISC
|
|
481
|
+
|
|
482
|
+
## Credits
|
|
97
483
|
|
|
98
|
-
|
|
99
|
-
- [Versioning](https://semver.org)
|
|
100
|
-
- [Conventional Commits](https://www.conventionalcommits.org)
|
|
484
|
+
Created and maintained by [Mickaël Austoni](https://github.com/Tracktor)
|
|
101
485
|
|
|
102
|
-
##
|
|
486
|
+
## Support
|
|
103
487
|
|
|
104
|
-
|
|
488
|
+
- [GitHub Issues](https://github.com/Tracktor/treege/issues)
|
|
489
|
+
- [Repository](https://github.com/Tracktor/treege)
|