treege 3.0.0-beta.54 → 3.0.0-beta.56
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 +98 -35
- package/dist/DefaultInputs-DklwwMaZ.js +1807 -0
- package/dist/ThemeContext-DAMkr9gW.js +1362 -0
- package/dist/editor/constants/edgeTypes.d.ts +1 -1
- package/dist/editor/features/TreegeEditor/edges/DefaultEdge.d.ts +1 -1
- package/dist/editor/features/TreegeEditor/forms/OptionsMappingFields.d.ts +34 -0
- package/dist/editor/features/TreegeEditor/nodes/components/BottomHandleDropdown.d.ts +18 -2
- package/dist/editor/features/TreegeEditor/nodes/components/NodeTypePickerMenuContent.d.ts +12 -0
- package/dist/editor/utils/edge.d.ts +37 -1
- package/dist/editor-uMYOjG2i.js +6079 -0
- package/dist/editor.js +2 -2
- package/dist/main.js +4 -4
- package/dist/renderer/utils/http.d.ts +13 -1
- package/dist/renderer-native.js +899 -896
- package/dist/renderer.js +3 -3
- package/dist/shared/locales/ar.json.d.ts +8 -0
- package/dist/shared/locales/de.json.d.ts +8 -0
- package/dist/shared/locales/en.json.d.ts +8 -0
- package/dist/shared/locales/es.json.d.ts +8 -0
- package/dist/shared/locales/fr.json.d.ts +8 -0
- package/dist/shared/locales/it.json.d.ts +8 -0
- package/dist/shared/locales/pt.json.d.ts +8 -0
- package/dist/shared/types/node.d.ts +20 -0
- package/package.json +1 -1
- package/dist/DefaultInputs-BbfholiM.js +0 -1799
- package/dist/ThemeContext-C9418UR6.js +0 -1354
- package/dist/editor-DgUCBTZ0.js +0 -5831
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ Treege is a modern React library for creating and rendering interactive decision
|
|
|
28
28
|
|
|
29
29
|
### Visual Editor (`treege/editor`)
|
|
30
30
|
- **Node-based Interface**: Drag-and-drop editor powered by ReactFlow
|
|
31
|
-
- **
|
|
31
|
+
- **3 Node Types**: Input, UI, and Group nodes
|
|
32
32
|
- **Conditional Edges**: Advanced logic with AND/OR operators (`===`, `!==`, `>`, `<`, `>=`, `<=`)
|
|
33
33
|
- **AI-Powered Generation**: Generate decision trees from natural language descriptions using Gemini, OpenAI, DeepSeek, or Claude ([Learn more](./AI_GENERATION.md))
|
|
34
34
|
- **Multi-language Support**: Built-in translation system for all labels
|
|
@@ -45,7 +45,9 @@ Treege is a modern React library for creating and rendering interactive decision
|
|
|
45
45
|
- **Security**: Built-in input sanitization to prevent XSS attacks
|
|
46
46
|
- **Enhanced Error Messages**: Clear, user-friendly error messages for HTTP inputs and validation
|
|
47
47
|
- **Conditional Logic**: Dynamic field visibility based on user input and conditional edges
|
|
48
|
-
- **
|
|
48
|
+
- **Multi-Step Forms**: Group nodes are automatically turned into navigable steps with Back/Continue controls
|
|
49
|
+
- **Loading State**: Built-in `isLoading` prop renders a customizable skeleton while the flow is being fetched
|
|
50
|
+
- **Fully Customizable**: Override any component (form, inputs, ui, step, submitButton, submitButtonWrapper, loadingSkeleton)
|
|
49
51
|
- **Optional Dependencies**: Graceful degradation when optional packages like `react-native-document-picker` aren't installed
|
|
50
52
|
- **Theme Support**: Dark/light mode out of the box
|
|
51
53
|
- **Google API Integration**: Address autocomplete support
|
|
@@ -59,6 +61,9 @@ Treege is a modern React library for creating and rendering interactive decision
|
|
|
59
61
|
## Installation
|
|
60
62
|
|
|
61
63
|
```bash
|
|
64
|
+
# bun
|
|
65
|
+
bun add treege
|
|
66
|
+
|
|
62
67
|
# npm
|
|
63
68
|
npm install treege
|
|
64
69
|
|
|
@@ -67,9 +72,6 @@ pnpm add treege
|
|
|
67
72
|
|
|
68
73
|
# yarn
|
|
69
74
|
yarn add treege
|
|
70
|
-
|
|
71
|
-
# bun
|
|
72
|
-
bun add treege
|
|
73
75
|
```
|
|
74
76
|
|
|
75
77
|
## Quick Start
|
|
@@ -324,7 +326,7 @@ The React Native renderer shares the same API as the web renderer, with some pla
|
|
|
324
326
|
|
|
325
327
|
| Prop | Type | Default | Description |
|
|
326
328
|
|-------------------------|---------------------------------------------|--------------|------------------------------------------------------------|
|
|
327
|
-
| `flows` | `Flow \|
|
|
329
|
+
| `flows` | `Flow \| null` | - | Decision tree to render |
|
|
328
330
|
| `onSubmit` | `(values: FormValues, meta?: Meta) => void` | - | Form submission handler (meta includes HTTP response data) |
|
|
329
331
|
| `onChange` | `(values: FormValues) => void` | - | Form change handler |
|
|
330
332
|
| `validate` | `(values, nodes) => Record<string, string>` | - | Custom validation function |
|
|
@@ -332,24 +334,16 @@ The React Native renderer shares the same API as the web renderer, with some pla
|
|
|
332
334
|
| `components` | `TreegeRendererComponents` | - | Custom component overrides |
|
|
333
335
|
| `language` | `string` | `"en"` | UI language |
|
|
334
336
|
| `validationMode` | `"onSubmit" \| "onChange"` | `"onSubmit"` | When to validate |
|
|
337
|
+
| `theme` | `"light" \| "dark"` | `"dark"` | Renderer theme |
|
|
335
338
|
| `googleApiKey` | `string` | - | API key for address input |
|
|
339
|
+
| `headers` | `HttpHeader[]` | - | HTTP headers applied to every request (field-level wins) |
|
|
340
|
+
| `isLoading` | `boolean` | `false` | Render a loading skeleton instead of the form |
|
|
336
341
|
| `style` | `ViewStyle` | - | ScrollView style (RN only) |
|
|
337
342
|
| `contentContainerStyle` | `ViewStyle` | - | Content container style (RN) |
|
|
338
343
|
|
|
339
344
|
## Node Types
|
|
340
345
|
|
|
341
|
-
|
|
342
|
-
Navigation node that controls the flow between different parts of the tree.
|
|
343
|
-
|
|
344
|
-
```tsx
|
|
345
|
-
{
|
|
346
|
-
type: "flow",
|
|
347
|
-
data: {
|
|
348
|
-
targetId: "next-node-id",
|
|
349
|
-
label: "Continue"
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
```
|
|
346
|
+
Treege has three node types: `input`, `ui`, and `group`. Navigation is automatic — group nodes drive step navigation and conditional edges drive branching.
|
|
353
347
|
|
|
354
348
|
### Input Node
|
|
355
349
|
Form input with validation, patterns, and conditional logic.
|
|
@@ -371,7 +365,7 @@ Form input with validation, patterns, and conditional logic.
|
|
|
371
365
|
Supported input types: `text`, `number`, `textarea`, `password`, `select`, `radio`, `checkbox`, `switch`, `autocomplete`, `date`, `daterange`, `time`, `timerange`, `file`, `address`, `http`, `hidden`
|
|
372
366
|
|
|
373
367
|
### Group Node
|
|
374
|
-
Container for organizing multiple nodes together.
|
|
368
|
+
Container for organizing multiple nodes together. Groups also drive **multi-step forms**: at runtime each group of visible nodes becomes a navigable step (Back/Continue). Child nodes belong to a group via their `parentId`.
|
|
375
369
|
|
|
376
370
|
```tsx
|
|
377
371
|
{
|
|
@@ -547,35 +541,103 @@ function App() {
|
|
|
547
541
|
}
|
|
548
542
|
```
|
|
549
543
|
|
|
550
|
-
###
|
|
544
|
+
### Loading State
|
|
545
|
+
|
|
546
|
+
When the flow is being fetched asynchronously, pass `isLoading` to render a skeleton in place of the form:
|
|
547
|
+
|
|
548
|
+
```tsx
|
|
549
|
+
function App() {
|
|
550
|
+
const { data: flow, isPending } = useQuery(/* ... */);
|
|
551
|
+
|
|
552
|
+
return <TreegeRenderer flows={flow ?? null} isLoading={isPending} onSubmit={console.log} />;
|
|
553
|
+
}
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
Customize the skeleton via `components.loadingSkeleton`:
|
|
557
|
+
|
|
558
|
+
```tsx
|
|
559
|
+
<TreegeRenderer
|
|
560
|
+
flows={flow}
|
|
561
|
+
isLoading={isPending}
|
|
562
|
+
components={{
|
|
563
|
+
loadingSkeleton: () => <MyCustomSkeleton />,
|
|
564
|
+
}}
|
|
565
|
+
/>
|
|
566
|
+
```
|
|
567
|
+
|
|
568
|
+
### Multi-Step Forms
|
|
569
|
+
|
|
570
|
+
When a flow contains **Group** nodes, the renderer automatically splits the form into navigable steps — each contiguous slice of visible nodes sharing the same group becomes one step, with built-in Back/Continue controls (Continue turns into Submit on the last step). Branching via conditional edges recomputes the steps on the fly.
|
|
571
|
+
|
|
572
|
+
Override the default step layout via `components.step`:
|
|
573
|
+
|
|
574
|
+
```tsx
|
|
575
|
+
<TreegeRenderer
|
|
576
|
+
flows={flow}
|
|
577
|
+
components={{
|
|
578
|
+
step: ({ label, children, isFirstStep, isLastStep, canContinue, onBack, onContinue }) => (
|
|
579
|
+
<section>
|
|
580
|
+
<h2>{label}</h2>
|
|
581
|
+
{children}
|
|
582
|
+
{!isFirstStep && <button onClick={onBack}>Back</button>}
|
|
583
|
+
<button disabled={!canContinue} onClick={onContinue}>
|
|
584
|
+
{isLastStep ? "Submit" : "Continue"}
|
|
585
|
+
</button>
|
|
586
|
+
</section>
|
|
587
|
+
),
|
|
588
|
+
}}
|
|
589
|
+
/>
|
|
590
|
+
```
|
|
591
|
+
|
|
592
|
+
### Headless / Programmatic Control
|
|
551
593
|
|
|
552
|
-
Use the `useTreegeRenderer` hook
|
|
594
|
+
Use the `useTreegeRenderer` hook to drive the form yourself (headless mode). It takes the same configuration as `TreegeRenderer` and returns the full form state and control methods:
|
|
553
595
|
|
|
554
596
|
```tsx
|
|
555
597
|
import { useTreegeRenderer } from "treege/renderer";
|
|
556
598
|
|
|
557
|
-
function CustomForm() {
|
|
558
|
-
const {
|
|
599
|
+
function CustomForm({ flow }) {
|
|
600
|
+
const {
|
|
601
|
+
formValues,
|
|
602
|
+
setFieldValue,
|
|
603
|
+
handleSubmit,
|
|
604
|
+
formErrors,
|
|
605
|
+
visibleNodes,
|
|
606
|
+
isSubmitting,
|
|
607
|
+
// step navigation
|
|
608
|
+
currentStep,
|
|
609
|
+
goToNextStep,
|
|
610
|
+
goToPreviousStep,
|
|
611
|
+
} = useTreegeRenderer({
|
|
612
|
+
flows: flow,
|
|
613
|
+
onSubmit: (values) => console.log("Submitted:", values),
|
|
614
|
+
});
|
|
559
615
|
|
|
560
616
|
return (
|
|
561
617
|
<div>
|
|
562
618
|
<button onClick={() => setFieldValue("email", "test@example.com")}>
|
|
563
619
|
Prefill Email
|
|
564
620
|
</button>
|
|
565
|
-
<button onClick={
|
|
566
|
-
|
|
621
|
+
<button onClick={handleSubmit} disabled={isSubmitting}>
|
|
622
|
+
Submit
|
|
623
|
+
</button>
|
|
567
624
|
</div>
|
|
568
625
|
);
|
|
569
626
|
}
|
|
570
627
|
```
|
|
571
628
|
|
|
629
|
+
> The `useTreegeRenderer` return type is exported as `UseTreegeRendererReturn` for TypeScript consumers building custom components.
|
|
630
|
+
|
|
572
631
|
## Examples
|
|
573
632
|
|
|
574
633
|
Check out the `/example` directory for complete examples:
|
|
575
634
|
|
|
576
635
|
```bash
|
|
577
|
-
# Run the example app
|
|
578
|
-
bun example
|
|
636
|
+
# Run the web example app (Vite, opens /example)
|
|
637
|
+
bun run example
|
|
638
|
+
|
|
639
|
+
# Run the React Native example app (Expo)
|
|
640
|
+
bun run example:native
|
|
579
641
|
```
|
|
580
642
|
|
|
581
643
|
### Available Example URLs
|
|
@@ -621,7 +683,7 @@ Once the development server is running, you can access these examples:
|
|
|
621
683
|
|
|
622
684
|
| Prop | Type | Default | Description |
|
|
623
685
|
|------------------|---------------------------------------------|--------------|------------------------------------------------------------|
|
|
624
|
-
| `flows` | `Flow \|
|
|
686
|
+
| `flows` | `Flow \| null` | - | Decision tree to render |
|
|
625
687
|
| `onSubmit` | `(values: FormValues, meta?: Meta) => void` | - | Form submission handler (meta includes HTTP response data) |
|
|
626
688
|
| `onChange` | `(values: FormValues) => void` | - | Form change handler |
|
|
627
689
|
| `validate` | `(values, nodes) => Record<string, string>` | - | Custom validation function |
|
|
@@ -632,25 +694,26 @@ Once the development server is running, you can access these examples:
|
|
|
632
694
|
| `theme` | `"light" \| "dark"` | `"dark"` | Renderer theme |
|
|
633
695
|
| `googleApiKey` | `string` | - | API key for address input |
|
|
634
696
|
| `headers` | `HttpHeader[]` | - | HTTP headers applied to every request (field-level wins) |
|
|
697
|
+
| `isLoading` | `boolean` | `false` | Render a loading skeleton instead of the form (see below) |
|
|
635
698
|
| `className` | `string` | - | Additional CSS class names for custom styling |
|
|
636
699
|
|
|
637
700
|
## Development
|
|
638
701
|
|
|
639
702
|
```bash
|
|
640
703
|
# Install dependencies
|
|
641
|
-
|
|
704
|
+
bun install
|
|
642
705
|
|
|
643
706
|
# Start dev server
|
|
644
|
-
|
|
707
|
+
bun run dev
|
|
645
708
|
|
|
646
709
|
# Build library
|
|
647
|
-
|
|
710
|
+
bun run build
|
|
648
711
|
|
|
649
712
|
# Run linter and type check
|
|
650
|
-
|
|
713
|
+
bun run lint
|
|
651
714
|
|
|
652
715
|
# Preview build
|
|
653
|
-
|
|
716
|
+
bun run preview
|
|
654
717
|
```
|
|
655
718
|
|
|
656
719
|
## Tech Stack
|
|
@@ -675,5 +738,5 @@ Created and maintained by [Mickaël Austoni](https://github.com/MickaelAustoni)
|
|
|
675
738
|
|
|
676
739
|
## Support
|
|
677
740
|
|
|
678
|
-
- [GitHub Issues](https://github.com/
|
|
679
|
-
- [Repository](https://github.com/
|
|
741
|
+
- [GitHub Issues](https://github.com/MickaelAustoni/treege/issues)
|
|
742
|
+
- [Repository](https://github.com/MickaelAustoni/treege)
|