@sonata-innovations/fiber-fbre 2.0.0

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.
@@ -0,0 +1,237 @@
1
+ import { Component } from '@sonata-innovations/fiber-types';
2
+ import { ComponentData } from '@sonata-innovations/fiber-types';
3
+ import { ComponentDisplayProperties } from '@sonata-innovations/fiber-types';
4
+ import { ComponentDividerProperties } from '@sonata-innovations/fiber-types';
5
+ import { ComponentFileUploadProperties } from '@sonata-innovations/fiber-types';
6
+ import { ComponentGroupProperties } from '@sonata-innovations/fiber-types';
7
+ import { ComponentInputProperties } from '@sonata-innovations/fiber-types';
8
+ import { ComponentOptionProperties } from '@sonata-innovations/fiber-types';
9
+ import { ComponentProperties } from '@sonata-innovations/fiber-types';
10
+ import { ComponentRatingProperties } from '@sonata-innovations/fiber-types';
11
+ import { ComponentSliderProperties } from '@sonata-innovations/fiber-types';
12
+ import { ComponentSwitchProperties } from '@sonata-innovations/fiber-types';
13
+ import { ConditionGroup } from '@sonata-innovations/fiber-types';
14
+ import { ConditionOperator } from '@sonata-innovations/fiber-types';
15
+ import { ConditionRule } from '@sonata-innovations/fiber-types';
16
+ import { ControlsConfig } from '@sonata-innovations/fiber-types';
17
+ import { FC } from 'react';
18
+ import { FileUploadBase64Data } from '@sonata-innovations/fiber-types';
19
+ import { FileUploadData } from '@sonata-innovations/fiber-types';
20
+ import { FileUploadS3Data } from '@sonata-innovations/fiber-types';
21
+ import { Flow } from '@sonata-innovations/fiber-types';
22
+ import { FlowCalculation } from '@sonata-innovations/fiber-types';
23
+ import { FlowConditionConfig } from '@sonata-innovations/fiber-types';
24
+ import { FlowConfiguration } from '@sonata-innovations/fiber-types';
25
+ import { FlowData } from '@sonata-innovations/fiber-types';
26
+ import { FlowMetadata } from '@sonata-innovations/fiber-types';
27
+ import { FlowScreen } from '@sonata-innovations/fiber-types';
28
+ import { FlowValidationConfig } from '@sonata-innovations/fiber-types';
29
+ import { NavigationConfig } from '@sonata-innovations/fiber-types';
30
+ import { ScreenData } from '@sonata-innovations/fiber-types';
31
+ import { StoreApi } from 'zustand';
32
+ import { ThemeConfig } from '@sonata-innovations/fiber-types';
33
+
34
+ export declare const addFBREEventListener: (type: string, callback: EventCallback) => void;
35
+
36
+ export declare class ApiError extends Error {
37
+ status: number;
38
+ code?: string;
39
+ validationErrors?: Record<string, string[]>;
40
+ constructor(message: string, status: number, code?: string, validationErrors?: Record<string, string[]>);
41
+ }
42
+
43
+ export { Component }
44
+
45
+ export { ComponentData }
46
+
47
+ export { ComponentDisplayProperties }
48
+
49
+ export { ComponentDividerProperties }
50
+
51
+ export { ComponentFileUploadProperties }
52
+
53
+ export { ComponentGroupProperties }
54
+
55
+ export { ComponentInputProperties }
56
+
57
+ export { ComponentOptionProperties }
58
+
59
+ export { ComponentProperties }
60
+
61
+ export { ComponentRatingProperties }
62
+
63
+ export { ComponentSliderProperties }
64
+
65
+ export { ComponentSwitchProperties }
66
+
67
+ /**
68
+ * Condition dependency entry — one per target that depends on a source.
69
+ * The key in conditionsByDependency is the source UUID.
70
+ */
71
+ export declare type ConditionDependency = {
72
+ /** UUID of the target component or screen */
73
+ target: string;
74
+ /** Whether the target is a "component" or "screen" */
75
+ type: "component" | "screen";
76
+ /** Full condition config for the target */
77
+ config: FlowConditionConfig;
78
+ };
79
+
80
+ export { ConditionGroup }
81
+
82
+ export { ConditionOperator }
83
+
84
+ export { ConditionRule }
85
+
86
+ export { ControlsConfig }
87
+
88
+ declare type EventCallback = (id: string, data: any) => void;
89
+
90
+ export declare const FBRE: FC<FBREProps>;
91
+
92
+ export declare interface FBREApiConfig {
93
+ apiEndpoint: string;
94
+ apiKey?: string;
95
+ /** Fetch timeout in milliseconds (default: 30000) */
96
+ timeout?: number;
97
+ }
98
+
99
+ declare interface FBREApiContextValue {
100
+ config: FBREApiConfig;
101
+ flowId: string;
102
+ flowVersionId: string;
103
+ tenantId: string;
104
+ }
105
+
106
+ declare interface FBRECallbackProps {
107
+ theme?: ThemeConfig;
108
+ navigation?: NavigationConfig;
109
+ controls?: ControlsConfig;
110
+ screenIndex?: number;
111
+ context?: Record<string, string | boolean | number>;
112
+ storeRef?: React.MutableRefObject<StoreApi<FBREStoreState> | null>;
113
+ onFlowComplete: (data: any) => void | Promise<void>;
114
+ onScreenChange?: (index: number, data: any) => void;
115
+ onScreenValidationChange?: (index: number, data: any) => void;
116
+ }
117
+
118
+ export declare interface FBRELocalProps extends FBRECallbackProps {
119
+ flow: Flow;
120
+ data?: FlowData;
121
+ flowId?: never;
122
+ apiEndpoint?: never;
123
+ apiKey?: never;
124
+ sessionEndpoint?: never;
125
+ }
126
+
127
+ export declare type FBREProps = FBRELocalProps | FBRERemoteProps | FBREServerDrivenModeProps;
128
+
129
+ export declare interface FBRERemoteProps extends FBRECallbackProps {
130
+ flow?: never;
131
+ data?: FlowData;
132
+ flowId: string;
133
+ apiEndpoint: string;
134
+ apiKey?: string;
135
+ sessionEndpoint?: never;
136
+ }
137
+
138
+ export declare interface FBREServerDrivenModeProps {
139
+ sessionEndpoint: string;
140
+ flowId: string;
141
+ apiKey?: string;
142
+ theme?: ThemeConfig;
143
+ context?: Record<string, string | boolean | number>;
144
+ onFlowComplete: (data: any) => void;
145
+ onScreenChange?: (screenNumber: number) => void;
146
+ }
147
+
148
+ export declare type FBREStoreState = {
149
+ flowUUID: string;
150
+ metadata: FlowMetadata;
151
+ config: FlowConfiguration;
152
+ externalContext: Record<string, string | boolean | number>;
153
+ screenOrder: string[];
154
+ screens: Record<string, FlowScreen>;
155
+ screenValidity: Record<string, boolean>;
156
+ components: Record<string, Component>;
157
+ groupComponentMap: Record<string, string>;
158
+ templateComponentMap: Record<string, string>;
159
+ /** Source UUID → list of targets that depend on it */
160
+ conditionsByDependency: Record<string, ConditionDependency[]>;
161
+ /** Target UUID → boolean (true = condition met) — runtime only, never serialised */
162
+ conditionResults: Record<string, boolean>;
163
+ /** Component UUID → array of error message strings */
164
+ validationErrors: Record<string, string[]>;
165
+ /** Source UUID → list of targets with matchesField rules depending on it */
166
+ validationsByDependency: Record<string, ValidationDependency[]>;
167
+ /** All flow calculations */
168
+ calculations: FlowCalculation[];
169
+ /** Calculation UUID → computed numeric result (null if unresolvable) */
170
+ calculationResults: Record<string, number | null>;
171
+ /** Source UUID → list of calculation UUIDs that depend on it */
172
+ calculationsByDependency: Record<string, string[]>;
173
+ /** Source template UUID → list of computed component template UUIDs that depend on it */
174
+ computedByDependency: Record<string, string[]>;
175
+ loadFlow: (flow: Flow, data?: FlowData, context?: Record<string, string | boolean | number>) => void;
176
+ updateComponentValue: (uuid: string, value: any) => void;
177
+ addGroupIteration: (groupUUID: string) => Component[][] | undefined;
178
+ addRepeaterIteration: (repeaterUUID: string) => Component[][] | undefined;
179
+ removeRepeaterIteration: (repeaterUUID: string, iterIndex: number) => void;
180
+ getFlowData: () => FlowData;
181
+ getScreenByIndex: (index: number) => FlowScreen | null;
182
+ getScreenValidity: (index: number) => boolean;
183
+ getValidationErrors: (uuid: string) => string[];
184
+ updateContext: (context: Record<string, string | boolean | number>) => void;
185
+ evaluateFlowValidation: () => boolean;
186
+ getMaxScreenCount: () => number;
187
+ getCalculationResult: (uuid: string) => number | null;
188
+ };
189
+
190
+ export { FileUploadBase64Data }
191
+
192
+ export { FileUploadData }
193
+
194
+ export { FileUploadS3Data }
195
+
196
+ export { Flow }
197
+
198
+ export { FlowConditionConfig }
199
+
200
+ export { FlowConfiguration }
201
+
202
+ export { FlowData }
203
+
204
+ export { FlowMetadata }
205
+
206
+ export { FlowScreen }
207
+
208
+ export { NavigationConfig }
209
+
210
+ export declare const removeFBREEventListener: (type: string, callback: EventCallback) => void;
211
+
212
+ export { ScreenData }
213
+
214
+ export { ThemeConfig }
215
+
216
+ export declare class TimeoutError extends ApiError {
217
+ constructor(url: string, timeoutMs: number);
218
+ }
219
+
220
+ export declare function useFBREApi(): FBREApiContextValue | null;
221
+
222
+ export declare function useFBREStore<T>(selector: (state: FBREStoreState) => T): T;
223
+
224
+ export declare const useFBREStoreApi: () => StoreApi<FBREStoreState>;
225
+
226
+ /**
227
+ * A validation dependency entry — one per target that depends on a source field.
228
+ * The key in validationsByDependency is the source UUID.
229
+ */
230
+ declare type ValidationDependency = {
231
+ /** UUID of the target component that has the matchesField rule */
232
+ target: string;
233
+ /** Full validation config for the target */
234
+ config: FlowValidationConfig;
235
+ };
236
+
237
+ export { }
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@sonata-innovations/fiber-fbre",
3
+ "version": "2.0.0",
4
+ "description": "Fiber Render Engine — renders Flow JSON forms with conditional logic, validation, and screen transitions",
5
+ "keywords": ["fiber", "form-builder", "form-renderer", "react", "flow-json", "data-collection"],
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/sonata-innovations/fiber.git",
10
+ "directory": "fbre"
11
+ },
12
+ "bugs": { "url": "https://github.com/sonata-innovations/fiber/issues" },
13
+ "homepage": "https://github.com/sonata-innovations/fiber",
14
+ "type": "module",
15
+ "main": "dist/fiber-fbre.cjs",
16
+ "module": "dist/fiber-fbre.js",
17
+ "types": "dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/fiber-fbre.js",
22
+ "require": "./dist/fiber-fbre.cjs"
23
+ },
24
+ "./styles": "./dist/fiber-fbre.css"
25
+ },
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "sideEffects": ["./dist/*.css"],
30
+ "scripts": {
31
+ "dev": "vite",
32
+ "build": "tsc --noEmit && vite build",
33
+ "preview": "vite preview"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "peerDependencies": {
39
+ "react": "^18.0.0 || ^19.0.0",
40
+ "react-dom": "^18.0.0 || ^19.0.0"
41
+ },
42
+ "dependencies": {
43
+ "@sonata-innovations/fiber-shared": "^1.0.0",
44
+ "@sonata-innovations/fiber-types": "^1.0.0",
45
+ "zustand": "^5.0.0"
46
+ },
47
+ "devDependencies": {
48
+ "@types/react": "^19.0.0",
49
+ "@types/react-dom": "^19.0.0",
50
+ "react": "^19.0.0",
51
+ "react-dom": "^19.0.0",
52
+ "typescript": "^5.7.0",
53
+ "vite": "^6.0.0",
54
+ "vite-plugin-dts": "^4.3.0"
55
+ }
56
+ }