treege 3.0.0-beta.81 → 3.0.0-beta.83

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/editor.js CHANGED
@@ -1,3 +1,3 @@
1
- import { t as e } from "./editor-h20-TVM8.js";
2
- import { n as t, t as n } from "./ThemeContext-BgTIhoK6.js";
1
+ import { t as e } from "./editor-CbcW0OVV.js";
2
+ import { n as t, t as n } from "./ThemeContext-BnPOFQC7.js";
3
3
  export { n as ThemeProvider, e as TreegeEditor, t as useTheme };
package/dist/main.js CHANGED
@@ -1,6 +1,6 @@
1
- import { t as e } from "./editor-h20-TVM8.js";
2
- import { F as t, G as n, H as r, P as i, U as a, V as o, W as s, _ as c, a as l, c as u, g as d, h as f, i as p, l as m, m as h, n as g, o as _, r as v, s as y, t as b, v as x } from "./ThemeContext-BgTIhoK6.js";
3
- import { C as S, L as C, S as w, _ as T, a as E, b as D, c as O, d as k, g as A, h as j, i as M, m as N, n as P, o as F, r as I, u as L, v as R, x as z, y as B } from "./DefaultSubmitButton-Dg9GPvh-.js";
4
- import { a as V, c as H, i as U, l as W, n as G, o as K, r as q, s as J } from "./useRenderNode-B1sfwbia.js";
5
- import { i as Y, n as X, r as Z, t as Q } from "./renderer-DI6nF4St.js";
6
- export { S as DefaultAddressInput, w as DefaultAutocompleteInput, z as DefaultCheckboxInput, D as DefaultDateInput, B as DefaultDateRangeInput, R as DefaultFileInput, T as DefaultHiddenInput, A as DefaultHttpInput, C as DefaultInputLabel, j as DefaultNumberInput, N as DefaultPasswordInput, k as DefaultRadioInput, L as DefaultSelectInput, O as DefaultSwitchInput, F as DefaultTextAreaInput, E as DefaultTextInput, M as DefaultTimeInput, I as DefaultTimeRangeInput, X as Divider, b as ThemeProvider, Z as Title, e as TreegeEditor, Q as TreegeRenderer, H as TreegeRendererProvider, v as applyReferenceTransformation, p as buildInitialFormValues, l as calculateReferenceFieldUpdates, _ as checkFormFieldHasValue, y as convertFormValuesToNamedFormat, P as defaultInputRenderers, Y as defaultUI, K as evaluateCondition, J as evaluateConditions, h as fileToSerializable, f as filesToSerializable, q as findStartNode, d as formatFileSize, U as getFlowRenderState, o as getStaticTranslations, r as getTranslatedText, u as isFieldEmpty, a as isGroupNode, s as isInputNode, V as isStartNode, n as isUINode, c as normalizeSerializableFiles, m as resolveNodeDefaultValue, i as sanitize, t as sanitizeHttpResponse, x as serializableToFile, g as useTheme, G as useTreegeRenderer, W as useTreegeRendererConfig };
1
+ import { t as e } from "./editor-CbcW0OVV.js";
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
+ 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
+ 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-KRzuU6OD.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 };
@@ -0,0 +1,78 @@
1
+ import { Node } from '@xyflow/react';
2
+ import { FormValues } from '../../../types/renderer';
3
+ import { SerializableFile } from '../../../../shared/types/file';
4
+ import { Flow, InputNodeData, InputType } from '../../../../shared/types/node';
5
+ /**
6
+ * Display-ready representation of a submitted field value, normalized per input
7
+ * type so a viewer can render it without re-deriving formatting rules:
8
+ * - `text` free-form string (text, number, date, ranges, resolved option label…)
9
+ * - `boolean` a yes/no value (switch) — render as a read-only toggle/checkbox
10
+ * - `tags` a list of labels (multi-select checkbox) — render as chips
11
+ * - `files` uploaded documents — render names or thumbnails (often overridden)
12
+ * - `empty` no value was submitted for this field
13
+ */
14
+ export type ViewerFieldDisplay = {
15
+ kind: "text";
16
+ text: string;
17
+ } | {
18
+ kind: "boolean";
19
+ checked: boolean;
20
+ } | {
21
+ kind: "tags";
22
+ tags: string[];
23
+ } | {
24
+ kind: "files";
25
+ files: SerializableFile[];
26
+ } | {
27
+ kind: "empty";
28
+ };
29
+ /** A single resolved field of a submitted form, ready for read-only rendering. */
30
+ export interface ViewerField {
31
+ /** The flow node id. */
32
+ id: string;
33
+ /** The submission key (name > translated label > id), as used in `onSubmit`. */
34
+ name: string;
35
+ /** The input type (`text`, `select`, `daterange`, `file`, …). */
36
+ type: InputType;
37
+ /** The translated field label (falls back to `name`, then node id). */
38
+ label: string;
39
+ /** The raw submitted value, untouched. */
40
+ rawValue: unknown;
41
+ /** Normalized, render-ready representation of the value. */
42
+ display: ViewerFieldDisplay;
43
+ /** The originating flow node (escape hatch for custom rendering). */
44
+ node: Node<InputNodeData>;
45
+ }
46
+ export interface GetViewerFieldsOptions {
47
+ /** Language used to resolve translatable labels/options (defaults to `en`). */
48
+ language?: string;
49
+ /**
50
+ * Base URL used to resolve relative file paths (e.g. `uploads/x.png`) into
51
+ * absolute URLs — same role as on `TreegeRenderer`/`TreegeEditor`. Absolute,
52
+ * `data:` and `blob:` URLs are left untouched.
53
+ */
54
+ baseUrl?: string;
55
+ }
56
+ /**
57
+ * Whether a file should be previewed inline as an image — detected by MIME type
58
+ * (`image/*`), a `data:image/` data-URL, or a recognized image URL extension.
59
+ */
60
+ export declare const isImageFile: (file: SerializableFile) => boolean;
61
+ /**
62
+ * Resolve a submitted form into a flat, render-ready list of fields.
63
+ *
64
+ * Mirrors what the renderer would show for the same values: the submission is
65
+ * normalized to node-id keys (accepting both `name`- and `id`-keyed input, like
66
+ * `initialValues`), then run through the same branch-visibility logic so only
67
+ * the fields that were actually reachable for these values are returned —
68
+ * inactive branches and `hidden`/`submit` nodes are excluded.
69
+ *
70
+ * This is the headless core behind {@link TreegeViewer}: consumers wanting a
71
+ * custom layout can render straight from this list.
72
+ *
73
+ * @param flow - The flow definition the values were submitted against
74
+ * @param values - The submitted values (`name`- or `id`-keyed)
75
+ * @param options - Resolution options (language, baseUrl)
76
+ * @returns The ordered, visible, display-ready fields
77
+ */
78
+ export declare const getViewerFields: (flow: Flow | null | undefined, values: FormValues | null | undefined, options?: GetViewerFieldsOptions) => ViewerField[];
@@ -0,0 +1,70 @@
1
+ import { ReactNode } from 'react';
2
+ import { ViewerField } from '../utils/viewerFields';
3
+ import { FormValues } from '../../../types/renderer';
4
+ import { Flow, InputType } from '../../../../shared/types/node';
5
+ /** Per-type override map: `{ file: (field) => <Thumbnails /> }`. */
6
+ export type ViewerFieldRenderers = Partial<Record<InputType, (field: ViewerField) => ReactNode>>;
7
+ export interface TreegeViewerProps {
8
+ /**
9
+ * The flow the values were submitted against
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`).
18
+ */
19
+ language?: string;
20
+ /**
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.
24
+ */
25
+ baseUrl?: string;
26
+ /**
27
+ * Field names (or ids) to hide from the view.
28
+ */
29
+ excludedFields?: string[];
30
+ /**
31
+ * Text shown when a field has no submitted value (defaults to `"—"`).
32
+ */
33
+ emptyText?: string;
34
+ /**
35
+ * Extra class names on the root element. *
36
+ */
37
+ className?: string;
38
+ /**
39
+ * Per-type rendering overrides for the value cell. Use this for app-specific
40
+ * cases — typically `file` (e.g. render thumbnails from your own storage)
41
+ * while every other type keeps its built-in rendering.
42
+ */
43
+ renderField?: ViewerFieldRenderers;
44
+ /**
45
+ * Wrap or replace a whole field row (label + value). Receives the resolved
46
+ * field and the default row node; return your own layout or the default.
47
+ */
48
+ renderRow?: (field: ViewerField, defaultRow: ReactNode) => ReactNode;
49
+ }
50
+ /**
51
+ * Read-only viewer for a submitted Treege form. Given the `flow` and the
52
+ * submitted `values`, it renders every reachable field as a label/value pair —
53
+ * resolving option labels, formatting dates/ranges and i18n labels the same way
54
+ * the renderer does, scoped to the active branch.
55
+ *
56
+ * Styling matches the renderer (shadcn/Tailwind, `tg:` prefix). For values that
57
+ * need app-specific rendering (chiefly uploaded `file`s) pass `renderField`; to
58
+ * change the whole row layout pass `renderRow`.
59
+ *
60
+ * @example
61
+ * <TreegeViewer
62
+ * flow={flow}
63
+ * values={submitted}
64
+ * language="fr"
65
+ * excludedFields={["internalNote"]}
66
+ * renderField={{ file: ({ rawValue }) => <Thumbnails files={rawValue} /> }}
67
+ * />
68
+ */
69
+ declare const TreegeViewer: ({ flow, values, baseUrl, excludedFields, className, renderField, renderRow, emptyText, language, }: TreegeViewerProps) => import("react/jsx-runtime").JSX.Element;
70
+ export default TreegeViewer;
@@ -9,6 +9,9 @@ export * from './features/TreegeRenderer/web/components/DefaultSubmitButton';
9
9
  export * from './features/TreegeRenderer/web/components/DefaultUI';
10
10
  export * from './features/TreegeRenderer/web/TreegeRenderer';
11
11
  export { default as TreegeRenderer } from './features/TreegeRenderer/web/TreegeRenderer';
12
+ export * from './features/TreegeViewer/utils/viewerFields';
13
+ export * from './features/TreegeViewer/web/TreegeViewer';
14
+ export { default as TreegeViewer } from './features/TreegeViewer/web/TreegeViewer';
12
15
  export type { TreegeRendererConfig } from './types/renderer';
13
16
  export * from './types/renderer';
14
17
  export * from './utils/conditions';
@@ -12,11 +12,24 @@ export declare const serializableToFile: (serializable: SerializableFile) => Fil
12
12
  * Converts multiple File objects to serializable format
13
13
  */
14
14
  export declare const filesToSerializable: (files: File[]) => Promise<SerializableFile[]>;
15
+ /**
16
+ * Derive a readable file name from a URL's last path segment (query/hash stripped).
17
+ */
18
+ export declare const fileNameFromUrl: (url: string) => string;
19
+ /**
20
+ * Whether a file's `data` is a URL to fetch/link to (an http(s) or relative
21
+ * path) rather than inline base64/blob content. Useful to decide whether to
22
+ * render the file as a clickable link or resolve it against a base URL.
23
+ */
24
+ export declare const isRemoteFileData: (data: string | null | undefined) => boolean;
15
25
  /**
16
26
  * Normalizes a file field value into an array of `SerializableFile`.
17
- * Handles single file, array of files, and empty (`null`/`undefined`) values.
27
+ * Handles a single file, an array, and empty (`null`/`undefined`) values. A
28
+ * stored document may also be referenced by a bare URL string (or an array
29
+ * containing some) — those are coerced into a `SerializableFile` whose `data`
30
+ * holds the URL and whose `name` is derived from it.
18
31
  */
19
- export declare const normalizeSerializableFiles: (value: SerializableFile | SerializableFile[] | null | undefined) => SerializableFile[];
32
+ export declare const normalizeSerializableFiles: (value: SerializableFile | string | Array<SerializableFile | string> | null | undefined) => SerializableFile[];
20
33
  /**
21
34
  * Formats a byte size into a human-readable string (B / KB / MB)
22
35
  */