treege 3.0.0-beta.85 → 3.0.0-beta.87

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/dist/main.js CHANGED
@@ -1,6 +1,6 @@
1
- import { t as e } from "./editor-Cd5_DOUg.js";
1
+ import { t as e } from "./editor-B3qu0VAn.js";
2
2
  import { G as t, I as n, J as r, K as i, L as a, U as o, W as s, Y as c, _ as l, a as u, b as d, c as f, g as p, h as m, i as h, l as g, m as _, n as v, o as y, q as b, r as x, s as S, t as C, v as w, y as T } from "./ThemeContext-BnPOFQC7.js";
3
3
  import { C as E, L as D, S as O, _ as k, a as A, b as j, c as M, d as N, g as P, h as F, i as I, m as L, n as R, o as z, r as B, u as V, v as H, x as U, y as W } from "./DefaultSubmitButton-DpeL3OxC.js";
4
4
  import { a as G, c as K, i as q, l as J, n as Y, o as X, r as Z, s as Q } from "./useRenderNode-DQ5lvXuj.js";
5
- import { a as $, i as ee, n as te, o as ne, r as re, s as ie, t as ae } from "./renderer-DrHbS6NW.js";
6
- export { E as DefaultAddressInput, O as DefaultAutocompleteInput, U as DefaultCheckboxInput, j as DefaultDateInput, W as DefaultDateRangeInput, H as DefaultFileInput, k as DefaultHiddenInput, P as DefaultHttpInput, D as DefaultInputLabel, F as DefaultNumberInput, L as DefaultPasswordInput, N as DefaultRadioInput, V as DefaultSelectInput, M as DefaultSwitchInput, z as DefaultTextAreaInput, A as DefaultTextInput, I as DefaultTimeInput, B as DefaultTimeRangeInput, $ as Divider, C as ThemeProvider, ne as Title, e as TreegeEditor, ee as TreegeRenderer, K as TreegeRendererProvider, ae as TreegeViewer, x as applyReferenceTransformation, h as buildInitialFormValues, u as calculateReferenceFieldUpdates, y as checkFormFieldHasValue, S as convertFormValuesToNamedFormat, R as defaultInputRenderers, ie as defaultUI, X as evaluateCondition, Q as evaluateConditions, _ as fileNameFromUrl, m as fileToSerializable, p as filesToSerializable, Z as findStartNode, l as formatFileSize, q as getFlowRenderState, o as getStaticTranslations, s as getTranslatableValue, t as getTranslatedText, te as getViewerFields, f as isFieldEmpty, b as isGroupNode, re as isImageFile, r as isInputNode, w as isRemoteFileData, G as isStartNode, c as isUINode, T as normalizeSerializableFiles, g as resolveNodeDefaultValue, n as sanitize, a as sanitizeHttpResponse, d as serializableToFile, i as setTranslatableValue, v as useTheme, Y as useTreegeRenderer, J as useTreegeRendererConfig };
5
+ import { a as $, c as ee, i as te, l as ne, n as re, o as ie, r as ae, s as oe, t as se } from "./renderer-D2-LozgF.js";
6
+ export { E as DefaultAddressInput, O as DefaultAutocompleteInput, U as DefaultCheckboxInput, j as DefaultDateInput, W as DefaultDateRangeInput, H as DefaultFileInput, k as DefaultHiddenInput, P as DefaultHttpInput, D as DefaultInputLabel, F as DefaultNumberInput, L as DefaultPasswordInput, N as DefaultRadioInput, V as DefaultSelectInput, M as DefaultSwitchInput, z as DefaultTextAreaInput, A as DefaultTextInput, I as DefaultTimeInput, B as DefaultTimeRangeInput, ie as Divider, C as ThemeProvider, oe as Title, e as TreegeEditor, $ as TreegeRenderer, K as TreegeRendererProvider, se as TreegeViewer, ne as TreegeViewerProvider, x as applyReferenceTransformation, h as buildInitialFormValues, u as calculateReferenceFieldUpdates, y as checkFormFieldHasValue, S as convertFormValuesToNamedFormat, R as defaultInputRenderers, ee as defaultUI, X as evaluateCondition, Q as evaluateConditions, _ as fileNameFromUrl, m as fileToSerializable, p as filesToSerializable, Z as findStartNode, l as formatFileSize, q as getFlowRenderState, o as getStaticTranslations, s as getTranslatableValue, t as getTranslatedText, re as getViewerFields, f as isFieldEmpty, b as isGroupNode, ae as isImageFile, r as isInputNode, w as isRemoteFileData, G as isStartNode, c as isUINode, T as normalizeSerializableFiles, g as resolveNodeDefaultValue, n as sanitize, a as sanitizeHttpResponse, d as serializableToFile, i as setTranslatableValue, v as useTheme, Y as useTreegeRenderer, J as useTreegeRendererConfig, te as viewerFieldsFromResponse };
@@ -0,0 +1,28 @@
1
+ import { ReactNode } from 'react';
2
+ export interface TreegeViewerProviderProps {
3
+ children: ReactNode;
4
+ /**
5
+ * Light/dark theme applied to every `TreegeViewer` underneath.
6
+ */
7
+ theme?: "light" | "dark";
8
+ /**
9
+ * Base URL used to resolve relative file paths into absolute URLs.
10
+ */
11
+ baseUrl?: string;
12
+ /**
13
+ * Language used to resolve translatable labels/options.
14
+ */
15
+ language?: string;
16
+ }
17
+ /**
18
+ * Config provider for {@link TreegeViewer}. It's a thin wrapper over
19
+ * `TreegeRendererProvider` that exposes only the options a read-only viewer
20
+ * actually uses — `theme`, `baseUrl` and `language` — so an app that consumes
21
+ * `TreegeViewer` (without `TreegeRenderer`) gets a focused API and can set them
22
+ * once for the whole subtree instead of on every viewer.
23
+ *
24
+ * Since it delegates to `TreegeRendererProvider`, `TreegeViewer` reads the values
25
+ * through the same `useTreegeRendererConfig` context.
26
+ */
27
+ declare const TreegeViewerProvider: ({ children, theme, baseUrl, language }: TreegeViewerProviderProps) => import("react/jsx-runtime").JSX.Element;
28
+ export default TreegeViewerProvider;
@@ -2,6 +2,7 @@ import { Node } from '@xyflow/react';
2
2
  import { FormValues } from '../../../types/renderer';
3
3
  import { SerializableFile } from '../../../../shared/types/file';
4
4
  import { Flow, InputNodeData, InputType } from '../../../../shared/types/node';
5
+ import { Translatable } from '../../../../shared/types/translate';
5
6
  /**
6
7
  * Display-ready representation of a submitted field value, normalized per input
7
8
  * type so a viewer can render it without re-deriving formatting rules:
@@ -40,8 +41,19 @@ export interface ViewerField {
40
41
  rawValue: unknown;
41
42
  /** Normalized, render-ready representation of the value. */
42
43
  display: ViewerFieldDisplay;
43
- /** The originating flow node (escape hatch for custom rendering). */
44
- node: Node<InputNodeData>;
44
+ /** The originating flow node — present only in flow-based resolution (escape hatch for custom rendering). */
45
+ node?: Node<InputNodeData>;
46
+ }
47
+ /**
48
+ * A self-describing stored value, used to render a viewer **without** a `flow`
49
+ * (e.g. a persisted `WorkflowValue[]`). Each entry carries its own metadata so
50
+ * the value can be formatted by type and labelled without a flow definition.
51
+ */
52
+ export interface FlowResponseEntry {
53
+ name?: string;
54
+ type?: string;
55
+ value?: unknown;
56
+ label?: Translatable | string;
45
57
  }
46
58
  export interface GetViewerFieldsOptions {
47
59
  /** Language used to resolve translatable labels/options (defaults to `en`). */
@@ -76,3 +88,15 @@ export declare const isImageFile: (file: SerializableFile) => boolean;
76
88
  * @returns The ordered, visible, display-ready fields
77
89
  */
78
90
  export declare const getViewerFields: (flow: Flow | null | undefined, values: FormValues | null | undefined, options?: GetViewerFieldsOptions) => ViewerField[];
91
+ /**
92
+ * Build a render-ready field list straight from a self-describing response —
93
+ * each entry supplies its own `name`/`type`/`value`/`label`, so no `flow` is
94
+ * needed. Used by {@link TreegeViewer} in its flow-less mode. Option values are
95
+ * shown as-is (there's no flow to resolve their labels), and `hidden`/`submit`
96
+ * entries are skipped.
97
+ *
98
+ * @param response - The self-describing stored values
99
+ * @param options - Resolution options (language, baseUrl)
100
+ * @returns The ordered, display-ready fields
101
+ */
102
+ export declare const viewerFieldsFromResponse: (response: readonly FlowResponseEntry[] | null | undefined, options?: GetViewerFieldsOptions) => ViewerField[];
@@ -1,43 +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
- export interface TreegeViewerProps {
7
+ interface TreegeViewerBaseProps {
8
8
  /**
9
- * The flow the values were submitted against
9
+ * Language used to resolve translatable labels/options (defaults to the provider config, then `en`).
10
10
  */
11
- flow: Flow;
12
- /**
13
- * The submitted values (`name`- or `id`-keyed, e.g. the `onSubmit` payload).
14
- */
15
- values: FormValues;
11
+ language?: string;
16
12
  /**
17
- * Language used to resolve translatable labels/options (defaults to `en`).
13
+ * Light/dark theme. Falls back to the `TreegeRendererProvider` config, then `"dark"`.
18
14
  */
19
- language?: string;
15
+ theme?: "light" | "dark";
20
16
  /**
21
- * Base URL used to resolve relative file paths into absolute URLs same role
22
- * as on `TreegeRenderer`/`TreegeEditor`. `data:`/`blob:`/absolute URLs are
23
- * left untouched.
17
+ * Base URL to resolve relative file paths into absolute URLs. `data:`/`blob:`/absolute URLs are left untouched.
24
18
  */
25
19
  baseUrl?: string;
26
20
  /**
27
- * Field names (or ids) to hide from the view.
21
+ * Field names (or ids) to hide from the view.
28
22
  */
29
23
  excludedFields?: string[];
30
24
  /**
31
25
  * Hide fields that have no submitted value (instead of showing `emptyText`).
32
- * Useful to render a compact recap of only the filled-in fields.
33
26
  */
34
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;
35
36
  /**
36
37
  * Text shown when a field has no submitted value (defaults to `"—"`).
37
38
  */
38
39
  emptyText?: string;
39
40
  /**
40
- * Extra class names on the root element. *
41
+ * Extra class names on the root element.
41
42
  */
42
43
  className?: string;
43
44
  /**
@@ -52,6 +53,26 @@ export interface TreegeViewerProps {
52
53
  */
53
54
  renderRow?: (field: ViewerField, defaultRow: ReactNode) => ReactNode;
54
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
+ });
55
76
  /**
56
77
  * Read-only viewer for a submitted Treege form. Given the `flow` and the
57
78
  * submitted `values`, it renders every reachable field as a label/value pair —
@@ -63,13 +84,11 @@ export interface TreegeViewerProps {
63
84
  * change the whole row layout pass `renderRow`.
64
85
  *
65
86
  * @example
66
- * <TreegeViewer
67
- * flow={flow}
68
- * values={submitted}
69
- * language="fr"
70
- * excludedFields={["internalNote"]}
71
- * renderField={{ file: ({ rawValue }) => <Thumbnails files={rawValue} /> }}
72
- * />
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" } }]} />
73
92
  */
74
- declare const TreegeViewer: ({ flow, values, baseUrl, excludedFields, excludeEmptyFields, className, renderField, renderRow, emptyText, language, }: TreegeViewerProps) => import("react/jsx-runtime").JSX.Element;
93
+ declare const TreegeViewer: ({ flow, flowResponse, baseUrl, theme, excludedFields, excludeEmptyFields, collapsed, collapsedVisibleCount, className, renderField, renderRow, language, emptyText, }: TreegeViewerProps) => import("react/jsx-runtime").JSX.Element;
75
94
  export default TreegeViewer;
@@ -1,4 +1,6 @@
1
1
  export { TreegeRendererProvider, useTreegeRendererConfig } from './context/TreegeRendererProvider';
2
+ export type { TreegeViewerProviderProps } from './context/TreegeViewerProvider';
3
+ export { default as TreegeViewerProvider } from './context/TreegeViewerProvider';
2
4
  export type { UseTreegeRendererReturn } from './features/TreegeRenderer/useTreegeRenderer';
3
5
  export { useTreegeRenderer } from './features/TreegeRenderer/useTreegeRenderer';
4
6
  export * from './features/TreegeRenderer/web/components/DefaultFormWrapper';