treege 3.0.0-beta.62 → 3.0.0-beta.64

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.
Files changed (60) hide show
  1. package/README.md +95 -43
  2. package/dist/DefaultInputs-2wzCRMKH.js +1742 -0
  3. package/dist/{ThemeContext-cGSTk24y.js → ThemeContext-7cghqUb0.js} +108 -602
  4. package/dist/{editor-K1jjfc5n.js → editor-DPECN9XS.js} +1799 -1800
  5. package/dist/editor.js +2 -2
  6. package/dist/main.js +6 -4
  7. package/dist/renderer/features/TreegeRenderer/native/TreegeRenderer.d.ts +1 -1
  8. package/dist/renderer/features/TreegeRenderer/native/components/DefaultInputs.d.ts +1 -2
  9. package/dist/renderer/features/TreegeRenderer/native/components/DefaultStep.d.ts +1 -1
  10. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultAddressInput.d.ts +2 -2
  11. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultAutocompleteInput.d.ts +2 -2
  12. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultCheckboxInput.d.ts +2 -2
  13. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultDateInput.d.ts +2 -2
  14. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultDateRangeInput.d.ts +2 -2
  15. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultFileInput.d.ts +2 -2
  16. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultHiddenInput.d.ts +2 -2
  17. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultHttpInput.d.ts +2 -2
  18. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultNumberInput.d.ts +2 -2
  19. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultPasswordInput.d.ts +2 -2
  20. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultRadioInput.d.ts +2 -2
  21. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultSelectInput.d.ts +2 -2
  22. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultSubmitInput.d.ts +11 -0
  23. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultSwitchInput.d.ts +2 -2
  24. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultTextInput.d.ts +2 -2
  25. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultTextareaInput.d.ts +2 -2
  26. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultTimeInput.d.ts +2 -2
  27. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultTimeRangeInput.d.ts +2 -2
  28. package/dist/renderer/features/TreegeRenderer/useTreegeRenderer.d.ts +2 -0
  29. package/dist/renderer/features/TreegeRenderer/web/TreegeRenderer.d.ts +1 -1
  30. package/dist/renderer/features/TreegeRenderer/web/components/DefaultFormWrapper.d.ts +2 -1
  31. package/dist/renderer/features/TreegeRenderer/web/components/DefaultStep.d.ts +1 -1
  32. package/dist/renderer/features/TreegeRenderer/web/components/DefaultSubmitButton.d.ts +4 -0
  33. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultAddressInput.d.ts +2 -2
  34. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultAutocompleteInput.d.ts +2 -2
  35. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultCheckboxInput.d.ts +2 -2
  36. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultDateInput.d.ts +2 -2
  37. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultDateRangeInput.d.ts +2 -2
  38. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultFileInput.d.ts +2 -2
  39. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultHiddenInput.d.ts +2 -2
  40. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultHttpInput.d.ts +2 -2
  41. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultNumberInput.d.ts +2 -2
  42. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultPasswordInput.d.ts +2 -2
  43. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultRadioInput.d.ts +2 -2
  44. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultSelectInput.d.ts +2 -2
  45. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultSubmitInput.d.ts +10 -2
  46. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultSwitchInput.d.ts +2 -2
  47. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultTextAreaInput.d.ts +2 -2
  48. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultTextInput.d.ts +2 -2
  49. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultTimeInput.d.ts +2 -2
  50. package/dist/renderer/features/TreegeRenderer/web/components/inputs/DefaultTimeRangeInput.d.ts +2 -2
  51. package/dist/renderer/hooks/useRenderNode.d.ts +4 -1
  52. package/dist/renderer/types/renderer.d.ts +73 -11
  53. package/dist/renderer/utils/form.d.ts +16 -0
  54. package/dist/renderer-DlAYvOLz.js +272 -0
  55. package/dist/renderer-native.js +1011 -1002
  56. package/dist/renderer.js +5 -3
  57. package/dist/useRenderNode-CZt7LwVV.js +504 -0
  58. package/package.json +1 -1
  59. package/dist/DefaultInputs-DamDWb5R.js +0 -1988
  60. package/dist/renderer/features/TreegeRenderer/InputRendererHost.d.ts +0 -15
package/README.md CHANGED
@@ -45,8 +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
- - **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
48
+ - **Multi-Step Forms**: Group nodes are automatically turned into navigable steps with Back/Continue controls, an `onBack` bridge to outer flows, and external-button submission via `formId`
49
+ - **Edit Mode**: Pre-fill with `initialValues` (accepts name keys, reactive) to round-trip and edit previously submitted records
50
+ - **Loading State**: Built-in `isLoading` prop renders a customizable skeleton while the flow is being fetched, plus `isSubmitting` to drive the button's loading state from async submits
50
51
  - **Fully Customizable**: Override any component (form, inputs, ui, step, submitButton, submitButtonWrapper, loadingSkeleton)
51
52
  - **Optional Dependencies**: Graceful degradation when optional packages like `react-native-document-picker` aren't installed
52
53
  - **Theme Support**: Dark/light mode out of the box
@@ -266,7 +267,7 @@ You can customize the appearance using the `style` and `contentContainerStyle` p
266
267
 
267
268
  Override default components with your own React Native components.
268
269
 
269
- Each input renderer receives **two arguments**:
270
+ Each input renderer is a **React component** receiving a single props object with two keys:
270
271
 
271
272
  1. `field` — DOM-safe props (`id`, `name`, `value`, `placeholder`, `required`, `aria-invalid`). On the web you can spread them onto an element (`<input {...field} />`); on React Native pick the ones you need.
272
273
  2. `extra` — Treege-specific props: `setValue`, `error`, `label`, `helperText`, `node`, and `missingDependencies` (the unfilled fields this input's dynamic options depend on).
@@ -275,7 +276,7 @@ Each input renderer receives **two arguments**:
275
276
  import { Text, TextInput, View } from "react-native";
276
277
  import { TreegeRenderer } from "treege/renderer-native";
277
278
 
278
- const CustomTextInput = (field, extra) => {
279
+ const CustomTextInput = ({ field, extra }) => {
279
280
  return (
280
281
  <View style={{ marginBottom: 16 }}>
281
282
  <Text style={{ fontSize: 14, marginBottom: 4 }}>{extra.label}</Text>
@@ -335,22 +336,24 @@ You can implement these inputs using popular React Native libraries:
335
336
 
336
337
  The React Native renderer shares the same API as the web renderer, with some platform-specific props:
337
338
 
338
- | Prop | Type | Default | Description |
339
- |-------------------------|---------------------------------------------|--------------|--------------------------------------------------------------------------------|
340
- | `flow` | `Flow \| null` | - | Decision tree to render |
341
- | `onSubmit` | `(values: FormValues, meta?: Meta) => void` | - | Form submission handler (meta includes HTTP response data) |
342
- | `onChange` | `(values: FormValues) => void` | - | Form change handler |
343
- | `validate` | `(values, nodes) => Record<string, string>` | - | Custom validation function |
344
- | `initialValues` | `FormValues` | `{}` | Initial form values |
345
- | `components` | `TreegeRendererComponents` | - | Custom component overrides |
346
- | `language` | `string` | `"en"` | UI language |
347
- | `validationMode` | `"onSubmit" \| "onChange"` | `"onSubmit"` | When to validate |
348
- | `theme` | `"light" \| "dark"` | `"dark"` | Renderer theme |
349
- | `googleApiKey` | `string` | - | API key for address input |
350
- | `headers` | `HttpHeaders` | - | HTTP headers as `{ name: value }`, applied to every request (field-level wins) |
351
- | `isLoading` | `boolean` | `false` | Render a loading skeleton instead of the form |
352
- | `style` | `ViewStyle` | - | ScrollView style (RN only) |
353
- | `contentContainerStyle` | `ViewStyle` | - | Content container style (RN) |
339
+ | Prop | Type | Default | Description |
340
+ |-------------------------|---------------------------------------------|--------------|-----------------------------------------------------------------------------------------------------------------|
341
+ | `flow` | `Flow \| null` | - | Decision tree to render |
342
+ | `onSubmit` | `(values: FormValues, meta?: Meta) => void` | - | Form submission handler (meta includes HTTP response data) |
343
+ | `onChange` | `(values: FormValues) => void` | - | Form change handler |
344
+ | `validate` | `(values, nodes) => Record<string, string>` | - | Custom validation function |
345
+ | `initialValues` | `FormValues` | `{}` | Pre-fill values to edit a record. Accepts `node.id` or name keys; reactive (re-seeds if it changes after mount) |
346
+ | `components` | `TreegeRendererComponents` | - | Custom component overrides |
347
+ | `language` | `string` | `"en"` | UI language |
348
+ | `validationMode` | `"onSubmit" \| "onChange"` | `"onSubmit"` | When to validate |
349
+ | `theme` | `"light" \| "dark"` | `"dark"` | Renderer theme |
350
+ | `googleApiKey` | `string` | - | API key for address input |
351
+ | `headers` | `HttpHeaders` | - | HTTP headers as `{ name: value }`, applied to every request (field-level wins) |
352
+ | `isLoading` | `boolean` | `false` | Render a loading skeleton instead of the form |
353
+ | `isSubmitting` | `boolean` | `false` | Force the submit/continue button into its loading state (OR-ed with internal state) |
354
+ | `onBack` | `() => void` | - | Called when Back is clicked on the first step; bridges to an outer flow |
355
+ | `style` | `ViewStyle` | - | ScrollView style (RN only) |
356
+ | `contentContainerStyle` | `ViewStyle` | - | Content container style (RN) |
354
357
 
355
358
  ## Node Types
356
359
 
@@ -452,14 +455,15 @@ Treege supports multiple languages out of the box:
452
455
 
453
456
  ### Custom Input Components
454
457
 
455
- Override default input renderers with your own. A renderer receives two
456
- arguments: `field` (DOM-safe props, spreadable onto an element) and `extra`
457
- (`setValue`, `error`, `label`, `helperText`, `node`, `missingDependencies`).
458
+ Override default input renderers with your own. A renderer is a React component
459
+ receiving a single props object: `field` (DOM-safe props, spreadable onto an
460
+ element) and `extra` (`setValue`, `error`, `label`, `helperText`, `node`,
461
+ `missingDependencies`).
458
462
 
459
463
  ```tsx
460
464
  import { TreegeRenderer } from "treege/renderer";
461
465
 
462
- const CustomTextInput = (field, extra) => {
466
+ const CustomTextInput = ({ field, extra }) => {
463
467
  return (
464
468
  <label>
465
469
  {extra.label}
@@ -586,6 +590,32 @@ Customize the skeleton via `components.loadingSkeleton`:
586
590
  />
587
591
  ```
588
592
 
593
+ ### Editing an Existing Submission
594
+
595
+ To edit a record that was already filled in, pass it to `initialValues`. The keys can be either `node.id` **or** the same name-based keys you receive from `onSubmit`/`onChange`, so you can round-trip the submitted object directly — no remapping needed:
596
+
597
+ ```tsx
598
+ const handleSubmit = (values) => save(values); // e.g. { firstName: "Alice", email: "a@b.com" }
599
+
600
+ // later, to edit the saved record:
601
+ <TreegeRenderer flow={flow} initialValues={savedRecord} onSubmit={handleSubmit} />
602
+ ```
603
+
604
+ `initialValues` is **reactive**: if it changes after mount (e.g. an async-fetched record resolves later), the form is re-seeded automatically — no `key` prop or `isLoading` gate required. Passing a new object of identical content does not reset the form, so in-progress edits are preserved.
605
+
606
+ ```tsx
607
+ const { data } = useQuery(/* ... */);
608
+ <TreegeRenderer flow={flow} initialValues={data ?? {}} onSubmit={handleSubmit} />
609
+ ```
610
+
611
+ ### Submitting State
612
+
613
+ Pass `isSubmitting` to keep the submit/continue button in its loading state (spinner + disabled) while an async `onSubmit` resolves on your side. It's OR-ed with the renderer's own internal submitting state (e.g. during an HTTP `submitConfig` call):
614
+
615
+ ```tsx
616
+ <TreegeRenderer flow={flow} isSubmitting={mutation.isPending} onSubmit={handleSubmit} />
617
+ ```
618
+
589
619
  ### Multi-Step Forms
590
620
 
591
621
  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.
@@ -596,13 +626,13 @@ Override the default step layout via `components.step`:
596
626
  <TreegeRenderer
597
627
  flow={flow}
598
628
  components={{
599
- step: ({ label, children, isFirstStep, isLastStep, canContinue, onBack, onContinue }) => (
629
+ step: ({ label, children, canGoBack, isLastStep, canContinue, isSubmitting, onBack, onContinue }) => (
600
630
  <section>
601
631
  <h2>{label}</h2>
602
632
  {children}
603
- {!isFirstStep && <button onClick={onBack}>Back</button>}
604
- <button disabled={!canContinue} onClick={onContinue}>
605
- {isLastStep ? "Submit" : "Continue"}
633
+ {canGoBack && <button onClick={onBack}>Back</button>}
634
+ <button disabled={!canContinue || isSubmitting} onClick={onContinue}>
635
+ {isSubmitting ? "Submitting…" : isLastStep ? "Submit" : "Continue"}
606
636
  </button>
607
637
  </section>
608
638
  ),
@@ -610,6 +640,25 @@ Override the default step layout via `components.step`:
610
640
  />
611
641
  ```
612
642
 
643
+ Use **`canGoBack`** (not `!isFirstStep`) to decide whether to show the Back control: it's `true` on any step past the first, and also on the first step when an `onBack` prop is provided.
644
+
645
+ #### Bridging navigation to an outer flow
646
+
647
+ When the renderer is embedded in a surrounding wizard (e.g. a modal with its own steps), use `onBack` to step back out of the renderer's first step, and `formId` to drive submission from an external button:
648
+
649
+ ```tsx
650
+ <TreegeRenderer
651
+ flow={flow}
652
+ formId="treege-form"
653
+ onBack={() => modal.goToPreviousStep()} // Back on step 0 → previous modal step
654
+ onSubmit={handleSubmit}
655
+ />
656
+
657
+ // A submit button living outside the renderer (web): only submits on the last
658
+ // step — on earlier steps it advances, like the built-in Continue button.
659
+ <button type="submit" form="treege-form">Save</button>
660
+ ```
661
+
613
662
  ### Headless / Programmatic Control
614
663
 
615
664
  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:
@@ -701,21 +750,24 @@ Once the development server is running, you can access these examples:
701
750
 
702
751
  ### TreegeRenderer Props
703
752
 
704
- | Prop | Type | Default | Description |
705
- |------------------|---------------------------------------------|--------------|--------------------------------------------------------------------------------|
706
- | `flow` | `Flow \| null` | - | Decision tree to render |
707
- | `onSubmit` | `(values: FormValues, meta?: Meta) => void` | - | Form submission handler (meta includes HTTP response data) |
708
- | `onChange` | `(values: FormValues) => void` | - | Form change handler |
709
- | `validate` | `(values, nodes) => Record<string, string>` | - | Custom validation function |
710
- | `initialValues` | `FormValues` | `{}` | Initial form values |
711
- | `components` | `TreegeRendererComponents` | - | Custom component overrides |
712
- | `language` | `string` | `"en"` | UI language |
713
- | `validationMode` | `"onSubmit" \| "onChange"` | `"onSubmit"` | When to validate |
714
- | `theme` | `"light" \| "dark"` | `"dark"` | Renderer theme |
715
- | `googleApiKey` | `string` | - | API key for address input |
716
- | `headers` | `HttpHeaders` | - | HTTP headers as `{ name: value }`, applied to every request (field-level wins) |
717
- | `isLoading` | `boolean` | `false` | Render a loading skeleton instead of the form (see below) |
718
- | `className` | `string` | - | Additional CSS class names for custom styling |
753
+ | Prop | Type | Default | Description |
754
+ |------------------|---------------------------------------------|--------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
755
+ | `flow` | `Flow \| null` | - | Decision tree to render |
756
+ | `onSubmit` | `(values: FormValues, meta?: Meta) => void` | - | Form submission handler (meta includes HTTP response data) |
757
+ | `onChange` | `(values: FormValues) => void` | - | Form change handler |
758
+ | `validate` | `(values, nodes) => Record<string, string>` | - | Custom validation function |
759
+ | `initialValues` | `FormValues` | `{}` | Pre-fill values to edit a submitted record. Accepts `node.id` **or** name keys (same shape as `onSubmit`); reactive — re-seeds if it changes after mount (see below) |
760
+ | `components` | `TreegeRendererComponents` | - | Custom component overrides |
761
+ | `language` | `string` | `"en"` | UI language |
762
+ | `validationMode` | `"onSubmit" \| "onChange"` | `"onSubmit"` | When to validate |
763
+ | `theme` | `"light" \| "dark"` | `"dark"` | Renderer theme |
764
+ | `googleApiKey` | `string` | - | API key for address input |
765
+ | `headers` | `HttpHeaders` | - | HTTP headers as `{ name: value }`, applied to every request (field-level wins) |
766
+ | `isLoading` | `boolean` | `false` | Render a loading skeleton instead of the form (see below) |
767
+ | `isSubmitting` | `boolean` | `false` | Force the submit/continue button into its loading state (spinner + disabled). OR-ed with the internal submitting state — useful with an async `onSubmit` |
768
+ | `onBack` | `() => void` | - | Called when Back is clicked on the **first step**; bridges back-navigation to an outer flow (e.g. a parent modal). Shows a Back button on step 0 when provided |
769
+ | `formId` | `string` | - | Sets the `<form>` `id` so a submit button outside the renderer can target it via the native `form` attribute. Web only; submits only on the last step in multi-step flows |
770
+ | `className` | `string` | - | Additional CSS class names for custom styling |
719
771
 
720
772
  ## Development
721
773