treege 3.0.0-beta.25 → 3.0.0-beta.27
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 +188 -24
- package/dist/ThemeContext-Cc71SvqK.js +410 -0
- package/dist/{TreegeEditor-WqTXkYl3.js → TreegeEditor-PuRxHufZ.js} +198 -197
- package/dist/TreegeRenderer-COBf5Nh3.js +1047 -0
- package/dist/editor.js +2 -2
- package/dist/main.js +54 -52
- package/dist/node-gfy3ym4p.js +340 -0
- package/dist/renderer/features/TreegeRenderer/native/TreegeRenderer.d.ts +20 -11
- package/dist/renderer/features/TreegeRenderer/native/components/DefaultFormWrapper.d.ts +7 -7
- package/dist/renderer/features/TreegeRenderer/native/components/DefaultGroup.d.ts +7 -7
- package/dist/renderer/features/TreegeRenderer/native/components/DefaultInputs.d.ts +26 -15
- 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/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/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 +81 -23
- package/dist/renderer/features/TreegeRenderer/web/TreegeRenderer.d.ts +1 -1
- package/dist/renderer/hooks/useRenderNode.d.ts +55 -0
- package/dist/renderer/index.d.ts +1 -0
- package/dist/renderer/index.native.d.ts +19 -0
- package/dist/renderer/types/renderer.d.ts +20 -4
- package/dist/renderer/utils/sanitize.native.d.ts +69 -0
- package/dist/renderer/utils/submit.d.ts +1 -1
- package/dist/renderer-native.d.ts +2 -0
- package/dist/renderer-native.js +2979 -0
- package/dist/renderer.js +49 -47
- package/dist/shared/locales/ar.json.d.ts +13 -5
- package/dist/shared/locales/de.json.d.ts +13 -5
- package/dist/shared/locales/en.json.d.ts +13 -5
- package/dist/shared/locales/es.json.d.ts +13 -5
- package/dist/shared/locales/fr.json.d.ts +13 -5
- package/dist/shared/locales/it.json.d.ts +13 -5
- package/dist/shared/locales/pt.json.d.ts +13 -5
- package/dist/shared/types/node.d.ts +2 -2
- package/dist/useRenderNode-B9cpomOv.js +863 -0
- package/package.json +24 -1
- package/dist/ThemeContext-BIT4DHqC.js +0 -764
- package/dist/TreegeRenderer-BSR_ez96.js +0 -1812
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<p><strong>Build powerful decision trees with a visual node-based editor</strong></p>
|
|
6
6
|
|
|
7
7
|
[](https://badge.fury.io/js/treege)
|
|
8
|
-
[](https://opensource.org/licenses/MIT)
|
|
9
9
|
|
|
10
10
|
<p>
|
|
11
11
|
<a href="https://treege.io/">🌐 Website</a> •
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
<a href="#features">Features</a> •
|
|
14
14
|
<a href="#installation">Installation</a> •
|
|
15
15
|
<a href="#quick-start">Quick Start</a> •
|
|
16
|
-
<a href="#examples">Examples</a>
|
|
16
|
+
<a href="#examples">Examples</a> •
|
|
17
|
+
<a href="./AI_GENERATION.md">🪄 AI Generation</a>
|
|
17
18
|
</p>
|
|
18
19
|
</div>
|
|
19
20
|
|
|
@@ -29,6 +30,7 @@ Treege is a modern React library for creating and rendering interactive decision
|
|
|
29
30
|
- **Node-based Interface**: Drag-and-drop editor powered by ReactFlow
|
|
30
31
|
- **4 Node Types**: Flow, Group, Input, and UI nodes
|
|
31
32
|
- **Conditional Edges**: Advanced logic with AND/OR operators (`===`, `!==`, `>`, `<`, `>=`, `<=`)
|
|
33
|
+
- **AI-Powered Generation**: Generate decision trees from natural language descriptions using Gemini, OpenAI, DeepSeek, or Claude ([Learn more](./AI_GENERATION.md))
|
|
32
34
|
- **Multi-language Support**: Built-in translation system for all labels
|
|
33
35
|
- **Type-safe**: Full TypeScript support
|
|
34
36
|
- **Mini-map & Controls**: Navigation tools for complex trees
|
|
@@ -37,13 +39,14 @@ Treege is a modern React library for creating and rendering interactive decision
|
|
|
37
39
|
### Runtime Renderer (`treege/renderer`)
|
|
38
40
|
- **Production Ready**: Full-featured form generation and validation system
|
|
39
41
|
- **16 Input Types**: text, number, select, checkbox, radio, date, daterange, time, timerange, file, address, http, textarea, password, switch, autocomplete, and hidden
|
|
42
|
+
- **Cross-Platform**: Full support for both React Web and React Native with dedicated implementations
|
|
40
43
|
- **HTTP Integration**: Built-in API integration with response mapping and search functionality
|
|
41
44
|
- **Advanced Validation**: Required fields, pattern matching, custom validation functions
|
|
42
45
|
- **Security**: Built-in input sanitization to prevent XSS attacks
|
|
43
46
|
- **Enhanced Error Messages**: Clear, user-friendly error messages for HTTP inputs and validation
|
|
44
47
|
- **Conditional Logic**: Dynamic field visibility based on user input and conditional edges
|
|
45
|
-
- **Web & Native**: Both web (React) and React Native renderer implementations
|
|
46
48
|
- **Fully Customizable**: Override any component (FormWrapper, Group, Inputs, SubmitButton, UI elements)
|
|
49
|
+
- **Optional Dependencies**: Graceful degradation when optional packages like `react-native-document-picker` aren't installed
|
|
47
50
|
- **Theme Support**: Dark/light mode out of the box
|
|
48
51
|
- **Google API Integration**: Address autocomplete support
|
|
49
52
|
|
|
@@ -163,7 +166,7 @@ function App() {
|
|
|
163
166
|
|
|
164
167
|
## Module Structure
|
|
165
168
|
|
|
166
|
-
Treege provides
|
|
169
|
+
Treege provides multiple import paths for optimal bundle size:
|
|
167
170
|
|
|
168
171
|
```tsx
|
|
169
172
|
// Import everything (editor + renderer + types)
|
|
@@ -172,10 +175,167 @@ import { TreegeEditor, TreegeRenderer } from "treege";
|
|
|
172
175
|
// Import only the editor
|
|
173
176
|
import { TreegeEditor } from "treege/editor";
|
|
174
177
|
|
|
175
|
-
// Import only the renderer
|
|
178
|
+
// Import only the web renderer
|
|
176
179
|
import { TreegeRenderer } from "treege/renderer";
|
|
180
|
+
|
|
181
|
+
// Import only the React Native renderer
|
|
182
|
+
import { TreegeRenderer } from "treege/renderer-native";
|
|
177
183
|
```
|
|
178
184
|
|
|
185
|
+
## React Native Support
|
|
186
|
+
|
|
187
|
+
Treege 3.0 includes full React Native support with a dedicated renderer implementation.
|
|
188
|
+
|
|
189
|
+
### Installation for React Native
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
# Install Treege
|
|
193
|
+
npm install treege
|
|
194
|
+
|
|
195
|
+
# Install peer dependencies
|
|
196
|
+
npm install react-native
|
|
197
|
+
|
|
198
|
+
# Optional: Install for file input support
|
|
199
|
+
npm install react-native-document-picker
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Basic Usage
|
|
203
|
+
|
|
204
|
+
```tsx
|
|
205
|
+
import { TreegeRenderer } from "treege/renderer-native";
|
|
206
|
+
import type { Flow, FormValues } from "treege";
|
|
207
|
+
|
|
208
|
+
function App() {
|
|
209
|
+
const flow: Flow = {
|
|
210
|
+
id: "flow-1",
|
|
211
|
+
nodes: [
|
|
212
|
+
{
|
|
213
|
+
id: "name",
|
|
214
|
+
type: "input",
|
|
215
|
+
data: {
|
|
216
|
+
type: "text",
|
|
217
|
+
name: "fullName",
|
|
218
|
+
label: "Full Name",
|
|
219
|
+
required: true
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
id: "email",
|
|
224
|
+
type: "input",
|
|
225
|
+
data: {
|
|
226
|
+
type: "text",
|
|
227
|
+
name: "email",
|
|
228
|
+
label: "Email",
|
|
229
|
+
required: true,
|
|
230
|
+
pattern: "^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$"
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
],
|
|
234
|
+
edges: []
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const handleSubmit = (values: FormValues) => {
|
|
238
|
+
console.log("Form submitted:", values);
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
return (
|
|
242
|
+
<TreegeRenderer
|
|
243
|
+
flows={flow}
|
|
244
|
+
onSubmit={handleSubmit}
|
|
245
|
+
/>
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Custom Styling
|
|
251
|
+
|
|
252
|
+
You can customize the appearance using the `style` and `contentContainerStyle` props:
|
|
253
|
+
|
|
254
|
+
```tsx
|
|
255
|
+
<TreegeRenderer
|
|
256
|
+
flows={flow}
|
|
257
|
+
onSubmit={handleSubmit}
|
|
258
|
+
style={{ flex: 1, backgroundColor: "#f5f5f5" }}
|
|
259
|
+
contentContainerStyle={{ padding: 20 }}
|
|
260
|
+
/>
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Custom Components
|
|
264
|
+
|
|
265
|
+
Override default components with your own React Native components:
|
|
266
|
+
|
|
267
|
+
```tsx
|
|
268
|
+
import { Text, TextInput, View } from "react-native";
|
|
269
|
+
import { TreegeRenderer } from "treege/renderer-native";
|
|
270
|
+
|
|
271
|
+
const CustomTextInput = ({ value, setValue, label, error }) => {
|
|
272
|
+
return (
|
|
273
|
+
<View style={{ marginBottom: 16 }}>
|
|
274
|
+
<Text style={{ fontSize: 14, marginBottom: 4 }}>{label}</Text>
|
|
275
|
+
<TextInput
|
|
276
|
+
value={value}
|
|
277
|
+
onChangeText={setValue}
|
|
278
|
+
style={{
|
|
279
|
+
borderWidth: 1,
|
|
280
|
+
borderColor: error ? "red" : "#ccc",
|
|
281
|
+
padding: 10,
|
|
282
|
+
borderRadius: 8
|
|
283
|
+
}}
|
|
284
|
+
/>
|
|
285
|
+
{error && <Text style={{ color: "red", fontSize: 12 }}>{error}</Text>}
|
|
286
|
+
</View>
|
|
287
|
+
);
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
<TreegeRenderer
|
|
291
|
+
flows={flow}
|
|
292
|
+
components={{
|
|
293
|
+
inputs: {
|
|
294
|
+
text: CustomTextInput
|
|
295
|
+
}
|
|
296
|
+
}}
|
|
297
|
+
/>
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### Supported Input Types
|
|
301
|
+
|
|
302
|
+
The React Native renderer includes default implementations for all input types:
|
|
303
|
+
|
|
304
|
+
**Fully Implemented (Vanilla React Native)**:
|
|
305
|
+
- `text`, `number`, `textarea`, `password`
|
|
306
|
+
- `checkbox`, `switch`, `hidden`
|
|
307
|
+
|
|
308
|
+
**With Optional Dependencies** (gracefully degrades if not installed):
|
|
309
|
+
- `file` - Requires [react-native-document-picker](https://github.com/rnmods/react-native-document-picker) (optional)
|
|
310
|
+
|
|
311
|
+
**Requires Custom Implementation** (placeholder provided):
|
|
312
|
+
- `select`, `radio`, `autocomplete`
|
|
313
|
+
- `date`, `daterange`, `time`, `timerange`
|
|
314
|
+
- `address`, `http`
|
|
315
|
+
|
|
316
|
+
You can implement these inputs using popular React Native libraries:
|
|
317
|
+
- [@react-native-picker/picker](https://github.com/react-native-picker/picker) for `select` and `radio`
|
|
318
|
+
- [react-native-date-picker](https://github.com/henninghall/react-native-date-picker) for `date` and `time` inputs
|
|
319
|
+
- [@react-native-community/google-places-autocomplete](https://github.com/FaridSafi/react-native-google-places-autocomplete) for `address`
|
|
320
|
+
|
|
321
|
+
### API Reference
|
|
322
|
+
|
|
323
|
+
The React Native renderer shares the same API as the web renderer, with some platform-specific props:
|
|
324
|
+
|
|
325
|
+
| Prop | Type | Default | Description |
|
|
326
|
+
|-------------------------|---------------------------------------------|--------------|------------------------------------------------------------|
|
|
327
|
+
| `flows` | `Flow \| Flow[] \| null` | - | Decision tree to render (single Flow or array of Flows) |
|
|
328
|
+
| `onSubmit` | `(values: FormValues, meta?: Meta) => void` | - | Form submission handler (meta includes HTTP response data) |
|
|
329
|
+
| `onChange` | `(values: FormValues) => void` | - | Form change handler |
|
|
330
|
+
| `validate` | `(values, nodes) => Record<string, string>` | - | Custom validation function |
|
|
331
|
+
| `initialValues` | `FormValues` | `{}` | Initial form values |
|
|
332
|
+
| `components` | `TreegeRendererComponents` | - | Custom component overrides |
|
|
333
|
+
| `language` | `string` | `"en"` | UI language |
|
|
334
|
+
| `validationMode` | `"onSubmit" \| "onChange"` | `"onSubmit"` | When to validate |
|
|
335
|
+
| `googleApiKey` | `string` | - | API key for address input |
|
|
336
|
+
| `style` | `ViewStyle` | - | ScrollView style (RN only) |
|
|
337
|
+
| `contentContainerStyle` | `ViewStyle` | - | Content container style (RN) |
|
|
338
|
+
|
|
179
339
|
## Node Types
|
|
180
340
|
|
|
181
341
|
### Flow Node
|
|
@@ -441,27 +601,31 @@ Once the development server is running, you can access these examples:
|
|
|
441
601
|
|
|
442
602
|
### TreegeEditor Props
|
|
443
603
|
|
|
444
|
-
| Prop
|
|
445
|
-
|
|
446
|
-
| `flow`
|
|
447
|
-
| `onSave`
|
|
448
|
-
| `
|
|
449
|
-
| `
|
|
604
|
+
| Prop | Type | Default | Description |
|
|
605
|
+
|----------------|------------------------------------------|----------|--------------------------------------------------------------------------------|
|
|
606
|
+
| `flow` | `Flow \| null` | `null` | Initial decision tree |
|
|
607
|
+
| `onSave` | `(flow: Flow) => void` | - | Callback when tree is saved |
|
|
608
|
+
| `onExportJson` | `() => { nodes: Node[]; edges: Edge[] }` | - | Callback for exporting JSON data |
|
|
609
|
+
| `language` | `string` | `"en"` | UI language |
|
|
610
|
+
| `theme` | `"light" \| "dark"` | `"dark"` | Editor theme |
|
|
611
|
+
| `aiConfig` | `AIConfig` | - | AI configuration for tree generation (see [AI Generation](./AI_GENERATION.md)) |
|
|
612
|
+
| `className` | `string` | - | Additional CSS class names for custom styling |
|
|
450
613
|
|
|
451
614
|
### TreegeRenderer Props
|
|
452
615
|
|
|
453
|
-
| Prop | Type | Default | Description
|
|
454
|
-
|
|
455
|
-
| `flows` | `Flow \| null`
|
|
456
|
-
| `onSubmit` | `(values: FormValues) => void`
|
|
457
|
-
| `onChange` | `(values: FormValues) => void` | - | Form change handler
|
|
458
|
-
| `validate` | `(values, nodes) => Record<string, string>` | - | Custom validation function
|
|
459
|
-
| `initialValues` | `FormValues` | `{}` | Initial form values
|
|
460
|
-
| `components` | `
|
|
461
|
-
| `language` | `string` | `"en"` | UI language
|
|
462
|
-
| `validationMode` | `"onSubmit" \| "onChange"` | `"onSubmit"` | When to validate
|
|
463
|
-
| `theme` | `"light" \| "dark"` | `"dark"` | Renderer theme
|
|
464
|
-
| `googleApiKey` | `string` | - | API key for address input
|
|
616
|
+
| Prop | Type | Default | Description |
|
|
617
|
+
|------------------|---------------------------------------------|--------------|------------------------------------------------------------|
|
|
618
|
+
| `flows` | `Flow \| Flow[] \| null` | - | Decision tree to render (single Flow or array of Flows) |
|
|
619
|
+
| `onSubmit` | `(values: FormValues, meta?: Meta) => void` | - | Form submission handler (meta includes HTTP response data) |
|
|
620
|
+
| `onChange` | `(values: FormValues) => void` | - | Form change handler |
|
|
621
|
+
| `validate` | `(values, nodes) => Record<string, string>` | - | Custom validation function |
|
|
622
|
+
| `initialValues` | `FormValues` | `{}` | Initial form values |
|
|
623
|
+
| `components` | `TreegeRendererComponents` | - | Custom component overrides |
|
|
624
|
+
| `language` | `string` | `"en"` | UI language |
|
|
625
|
+
| `validationMode` | `"onSubmit" \| "onChange"` | `"onSubmit"` | When to validate |
|
|
626
|
+
| `theme` | `"light" \| "dark"` | `"dark"` | Renderer theme |
|
|
627
|
+
| `googleApiKey` | `string` | - | API key for address input |
|
|
628
|
+
| `className` | `string` | - | Additional CSS class names for custom styling |
|
|
465
629
|
|
|
466
630
|
## Development
|
|
467
631
|
|
|
@@ -498,7 +662,7 @@ Contributions are welcome! Please feel free to submit a Pull Request.
|
|
|
498
662
|
|
|
499
663
|
## License
|
|
500
664
|
|
|
501
|
-
|
|
665
|
+
MIT
|
|
502
666
|
|
|
503
667
|
## Credits
|
|
504
668
|
|