treege 3.0.0-beta.86 → 3.0.0-beta.88
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 +112 -56
- package/dist/{editor-BK8Mbi-D.js → editor-BPx-285N.js} +2 -2
- package/dist/editor.js +1 -1
- package/dist/main.js +4 -4
- package/dist/renderer/features/TreegeRenderer/useTreegeRenderer.d.ts +1 -1
- package/dist/renderer/features/TreegeRenderer/web/TreegeRenderer.d.ts +1 -1
- package/dist/renderer/features/TreegeViewer/utils/viewerFields.d.ts +26 -2
- package/dist/renderer/features/TreegeViewer/web/TreegeViewer.d.ts +41 -27
- package/dist/renderer/hooks/useSubmitHandler.d.ts +3 -2
- package/dist/renderer/types/renderer.d.ts +24 -0
- package/dist/renderer/utils/extraPayload.d.ts +21 -0
- package/dist/renderer/utils/submit.d.ts +3 -2
- package/dist/renderer-Bpgwbsub.js +446 -0
- package/dist/renderer-native.js +167 -166
- package/dist/renderer.js +3 -3
- package/dist/{useRenderNode-DQ5lvXuj.js → useRenderNode-CgDdKXTw.js} +203 -192
- package/package.json +1 -1
- package/dist/renderer-8xCEZin9.js +0 -424
|
@@ -1,48 +1,44 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import { ViewerField } from '../utils/viewerFields';
|
|
2
|
+
import { FlowResponseEntry, ViewerField } from '../utils/viewerFields';
|
|
3
3
|
import { FormValues } from '../../../types/renderer';
|
|
4
4
|
import { Flow, InputType } from '../../../../shared/types/node';
|
|
5
5
|
/** Per-type override map: `{ file: (field) => <Thumbnails /> }`. */
|
|
6
6
|
export type ViewerFieldRenderers = Partial<Record<InputType, (field: ViewerField) => ReactNode>>;
|
|
7
|
-
|
|
7
|
+
interface TreegeViewerBaseProps {
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
*/
|
|
11
|
-
flow: Flow;
|
|
12
|
-
/**
|
|
13
|
-
* The submitted values (`name`- or `id`-keyed, e.g. the `onSubmit` payload).
|
|
14
|
-
*/
|
|
15
|
-
values: FormValues;
|
|
16
|
-
/**
|
|
17
|
-
* Language used to resolve translatable labels/options (defaults to `en`).
|
|
9
|
+
* Language used to resolve translatable labels/options (defaults to the provider config, then `en`).
|
|
18
10
|
*/
|
|
19
11
|
language?: string;
|
|
20
12
|
/**
|
|
21
|
-
* Light/dark theme. Falls back to the `TreegeRendererProvider` config, then
|
|
22
|
-
* `"dark"` — same resolution as `TreegeRenderer`.
|
|
13
|
+
* Light/dark theme. Falls back to the `TreegeRendererProvider` config, then `"dark"`.
|
|
23
14
|
*/
|
|
24
15
|
theme?: "light" | "dark";
|
|
25
16
|
/**
|
|
26
|
-
* Base URL
|
|
27
|
-
* as on `TreegeRenderer`/`TreegeEditor`. `data:`/`blob:`/absolute URLs are
|
|
28
|
-
* left untouched.
|
|
17
|
+
* Base URL to resolve relative file paths into absolute URLs. `data:`/`blob:`/absolute URLs are left untouched.
|
|
29
18
|
*/
|
|
30
19
|
baseUrl?: string;
|
|
31
20
|
/**
|
|
32
|
-
*
|
|
21
|
+
* Field names (or ids) to hide from the view.
|
|
33
22
|
*/
|
|
34
23
|
excludedFields?: string[];
|
|
35
24
|
/**
|
|
36
25
|
* Hide fields that have no submitted value (instead of showing `emptyText`).
|
|
37
|
-
* Useful to render a compact recap of only the filled-in fields.
|
|
38
26
|
*/
|
|
39
27
|
excludeEmptyFields?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* When `true`, only the first `collapsedVisibleCount` fields are rendered.
|
|
30
|
+
*/
|
|
31
|
+
collapsed?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Number of fields kept visible while `collapsed` (defaults to all).
|
|
34
|
+
*/
|
|
35
|
+
collapsedVisibleCount?: number;
|
|
40
36
|
/**
|
|
41
37
|
* Text shown when a field has no submitted value (defaults to `"—"`).
|
|
42
38
|
*/
|
|
43
39
|
emptyText?: string;
|
|
44
40
|
/**
|
|
45
|
-
* Extra class names on the root element.
|
|
41
|
+
* Extra class names on the root element.
|
|
46
42
|
*/
|
|
47
43
|
className?: string;
|
|
48
44
|
/**
|
|
@@ -57,6 +53,26 @@ export interface TreegeViewerProps {
|
|
|
57
53
|
*/
|
|
58
54
|
renderRow?: (field: ViewerField, defaultRow: ReactNode) => ReactNode;
|
|
59
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* `flowResponse` is typed conditionally on `flow`:
|
|
58
|
+
* - **with** a `flow` → the renderer's `FormValues` (`name`- or `id`-keyed), resolved against the flow;
|
|
59
|
+
* - **without** a `flow` → a self-describing `FlowResponseEntry[]` (each carries its own
|
|
60
|
+
* `name`/`type`/`value`/`label`), rendered as-is.
|
|
61
|
+
*/
|
|
62
|
+
export type TreegeViewerProps = TreegeViewerBaseProps & ({
|
|
63
|
+
/**
|
|
64
|
+
* The flow the values were submitted against.
|
|
65
|
+
*/
|
|
66
|
+
flow: Flow;
|
|
67
|
+
/** The submitted values as the renderer's `FormValues` (`name`- or `id`-keyed). */
|
|
68
|
+
flowResponse: FormValues;
|
|
69
|
+
} | {
|
|
70
|
+
flow?: undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Self-describing stored values rendered without a flow.
|
|
73
|
+
*/
|
|
74
|
+
flowResponse: FlowResponseEntry[];
|
|
75
|
+
});
|
|
60
76
|
/**
|
|
61
77
|
* Read-only viewer for a submitted Treege form. Given the `flow` and the
|
|
62
78
|
* submitted `values`, it renders every reachable field as a label/value pair —
|
|
@@ -68,13 +84,11 @@ export interface TreegeViewerProps {
|
|
|
68
84
|
* change the whole row layout pass `renderRow`.
|
|
69
85
|
*
|
|
70
86
|
* @example
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* renderField={{ file: ({ rawValue }) => <Thumbnails files={rawValue} /> }}
|
|
77
|
-
* />
|
|
87
|
+
* // With a flow — `flowResponse` is the renderer's FormValues:
|
|
88
|
+
* <TreegeViewer flow={flow} flowResponse={submitted} language="fr" excludeEmptyFields />
|
|
89
|
+
*
|
|
90
|
+
* // Without a flow — `flowResponse` is a self-describing list:
|
|
91
|
+
* <TreegeViewer flowResponse={[{ name: "city", type: "text", value: "Paris", label: { en: "City" } }]} />
|
|
78
92
|
*/
|
|
79
|
-
declare const TreegeViewer: ({ flow,
|
|
93
|
+
declare const TreegeViewer: ({ flow, flowResponse, baseUrl, theme, excludedFields, excludeEmptyFields, collapsed, collapsedVisibleCount, className, renderField, renderRow, language, emptyText, }: TreegeViewerProps) => import("react/jsx-runtime").JSX.Element;
|
|
80
94
|
export default TreegeViewer;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Node } from '@xyflow/react';
|
|
2
|
-
import { FormValues } from '../types/renderer';
|
|
2
|
+
import { ExtraPayload, FormValues } from '../types/renderer';
|
|
3
3
|
import { SubmitResult } from '../utils/submit';
|
|
4
4
|
import { HttpHeaders, InputNodeData, TreegeNodeData } from '../../shared/types/node';
|
|
5
5
|
/**
|
|
@@ -18,9 +18,10 @@ import { HttpHeaders, InputNodeData, TreegeNodeData } from '../../shared/types/n
|
|
|
18
18
|
* @param inputNodes - All input nodes for form data conversion
|
|
19
19
|
* @param headers
|
|
20
20
|
* @param baseUrl - Base URL prepended to a relative submit url
|
|
21
|
+
* @param extraPayload - Consumer-injected fields merged into the submit body
|
|
21
22
|
* @returns Submit handler state and functions
|
|
22
23
|
*/
|
|
23
|
-
export declare const useSubmitHandler: (visibleNodes: Node<TreegeNodeData>[], formValues: FormValues, language: string, inputNodes: Node<InputNodeData>[], headers?: HttpHeaders, baseUrl?: string) => {
|
|
24
|
+
export declare const useSubmitHandler: (visibleNodes: Node<TreegeNodeData>[], formValues: FormValues, language: string, inputNodes: Node<InputNodeData>[], headers?: HttpHeaders, baseUrl?: string, extraPayload?: ExtraPayload) => {
|
|
24
25
|
clearSubmitMessage: () => void;
|
|
25
26
|
handleSubmitWithConfig: (onSuccess?: (data: unknown) => void) => Promise<SubmitResult | null>;
|
|
26
27
|
hasSubmitConfig: boolean;
|
|
@@ -33,6 +33,18 @@ export type FormValues = Record<string, any>;
|
|
|
33
33
|
export type Meta = {
|
|
34
34
|
httpResponse?: unknown;
|
|
35
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* Extra data injected by the consuming app into every submission, merged at the
|
|
38
|
+
* top level of the payload — both the object passed to `onSubmit` and the body
|
|
39
|
+
* of the built-in HTTP submit request. Use it for fields that live in the host
|
|
40
|
+
* app rather than the form itself (e.g. the logged-in `userId`, a tenant id).
|
|
41
|
+
*
|
|
42
|
+
* Either a static object or a function of the current (name-keyed) form values,
|
|
43
|
+
* evaluated at submit time so the extra data can be derived from the answers or
|
|
44
|
+
* read fresh (e.g. a rotating auth token). The extra keys are spread last, so
|
|
45
|
+
* they intentionally override a same-named form field.
|
|
46
|
+
*/
|
|
47
|
+
export type ExtraPayload = Record<string, unknown> | ((values: FormValues) => Record<string, unknown>);
|
|
36
48
|
/**
|
|
37
49
|
* Union of all possible input value types
|
|
38
50
|
*/
|
|
@@ -400,6 +412,18 @@ export interface TreegeRendererProps extends TreegeRendererConfig {
|
|
|
400
412
|
* Additional class name for the renderer container
|
|
401
413
|
*/
|
|
402
414
|
className?: string;
|
|
415
|
+
/**
|
|
416
|
+
* Extra data injected into every submission, merged at the top level of both
|
|
417
|
+
* the `onSubmit` payload and the built-in HTTP submit body. Use it for values
|
|
418
|
+
* owned by the host app rather than the form (e.g. the logged-in `userId`).
|
|
419
|
+
* See {@link ExtraPayload}.
|
|
420
|
+
*
|
|
421
|
+
* @example
|
|
422
|
+
* <TreegeRenderer flow={tree} extraPayload={{ userId }} />
|
|
423
|
+
* @example
|
|
424
|
+
* <TreegeRenderer flow={tree} extraPayload={() => ({ token: getToken() })} />
|
|
425
|
+
*/
|
|
426
|
+
extraPayload?: ExtraPayload;
|
|
403
427
|
/**
|
|
404
428
|
* Flow to render. `null` / `undefined` renders nothing.
|
|
405
429
|
*/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ExtraPayload, FormValues } from '../types/renderer';
|
|
2
|
+
/**
|
|
3
|
+
* Merge the consumer-provided `extraPayload` onto a base submission payload.
|
|
4
|
+
* This is the single chokepoint behind the `extraPayload` prop, used both for
|
|
5
|
+
* the `onSubmit` callback payload and the built-in HTTP submit body.
|
|
6
|
+
*
|
|
7
|
+
* `extraPayload` may be a static object or a function of the current
|
|
8
|
+
* (name-keyed) values — the function form lets the extra data be read at submit
|
|
9
|
+
* time (e.g. a freshly-read auth token). The extra fields are spread **last**,
|
|
10
|
+
* so a consumer-injected key (e.g. `userId`) intentionally wins over a
|
|
11
|
+
* same-named form field.
|
|
12
|
+
*
|
|
13
|
+
* Edge cases:
|
|
14
|
+
* - No `extraPayload`, or it resolves to a non-object (array / primitive) →
|
|
15
|
+
* the base is returned untouched (nothing to merge).
|
|
16
|
+
* - Base is `undefined`/`null` (e.g. a submit config that would otherwise send
|
|
17
|
+
* no body) → the extra is sent on its own, so the injected data still goes out.
|
|
18
|
+
* - Base is a non-object → returned untouched, since there is no top level to
|
|
19
|
+
* merge into.
|
|
20
|
+
*/
|
|
21
|
+
export declare const mergeExtraPayload: <T>(base: T, extraPayload: ExtraPayload | undefined, values: FormValues) => T | Record<string, unknown>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Node } from '@xyflow/react';
|
|
2
|
-
import { FormValues } from '../types/renderer';
|
|
2
|
+
import { ExtraPayload, FormValues } from '../types/renderer';
|
|
3
3
|
import { HttpHeaders, InputNodeData, SubmitConfig } from '../../shared/types/node';
|
|
4
4
|
/**
|
|
5
5
|
* Result of a form submission
|
|
@@ -36,9 +36,10 @@ export interface SubmitResult {
|
|
|
36
36
|
* @param inputNodes - All input nodes (required when sendAllFormValues is true)
|
|
37
37
|
* @param headers
|
|
38
38
|
* @param baseUrl - Base URL prepended to a relative submit url
|
|
39
|
+
* @param extraPayload - Consumer-injected fields merged into the request body
|
|
39
40
|
* @returns Promise with submission result
|
|
40
41
|
*/
|
|
41
|
-
export declare const submitFormData: (config: SubmitConfig, formValues: FormValues, inputNodes: Node<InputNodeData>[], headers?: HttpHeaders, baseUrl?: string) => Promise<SubmitResult>;
|
|
42
|
+
export declare const submitFormData: (config: SubmitConfig, formValues: FormValues, inputNodes: Node<InputNodeData>[], headers?: HttpHeaders, baseUrl?: string, extraPayload?: ExtraPayload) => Promise<SubmitResult>;
|
|
42
43
|
/**
|
|
43
44
|
* Perform redirect to the specified URL
|
|
44
45
|
*
|