@bluprynt/forms-viewer 1.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.
package/dist/index.cjs ADDED
@@ -0,0 +1,488 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _bluprynt_forms_core = require("@bluprynt/forms-core");
3
+ let react = require("react");
4
+ let react_jsx_runtime = require("react/jsx-runtime");
5
+ //#region src/constants.ts
6
+ const ROOT = Symbol("ROOT");
7
+ //#endregion
8
+ //#region src/form-context.tsx
9
+ const FormContext = (0, react.createContext)(void 0);
10
+ const useFormContext = () => {
11
+ const context = (0, react.useContext)(FormContext);
12
+ if (!context) throw new Error("useFormContext must be used within a <Form> provider");
13
+ return context;
14
+ };
15
+ const Form = ({ definition, data, section, showInlineValidation = true, children }) => {
16
+ const { engine, documentErrors: definitionErrors } = (0, react.useMemo)(() => {
17
+ if (!definition) return {};
18
+ try {
19
+ return { engine: new _bluprynt_forms_core.FormEngine(definition) };
20
+ } catch (error) {
21
+ if (error instanceof _bluprynt_forms_core.DocumentError) return { documentErrors: error.errors };
22
+ throw error;
23
+ }
24
+ }, [definition]);
25
+ const { visibilityMap, validation, documentErrors, fieldErrors } = (0, react.useMemo)(() => {
26
+ const visibilityMap = engine && data ? engine.getVisibilityMap(data) : /* @__PURE__ */ new Map();
27
+ const validation = engine && data ? engine.validate(data) : {
28
+ valid: true,
29
+ fieldErrors: /* @__PURE__ */ new Map()
30
+ };
31
+ return {
32
+ visibilityMap,
33
+ validation,
34
+ documentErrors: [...definitionErrors ?? [], ...validation?.documentErrors ?? []],
35
+ fieldErrors: validation?.fieldErrors ?? /* @__PURE__ */ new Map()
36
+ };
37
+ }, [
38
+ engine,
39
+ data,
40
+ definitionErrors
41
+ ]);
42
+ const value = {
43
+ definition,
44
+ data,
45
+ engine,
46
+ visibilityMap,
47
+ validation,
48
+ documentErrors,
49
+ fieldErrors,
50
+ section,
51
+ showInlineValidation
52
+ };
53
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FormContext.Provider, {
54
+ value,
55
+ children
56
+ });
57
+ };
58
+ //#endregion
59
+ //#region src/form-document-validation.tsx
60
+ const FormDocumentValidation = ({ container: ContainerComponent, error: ErrorComponent }) => {
61
+ const { documentErrors } = useFormContext();
62
+ if (!documentErrors?.length) return null;
63
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ContainerComponent, { children: documentErrors.map((error, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorComponent, { ...error }, `error-${error.code}-${error.itemId ?? ""}-${index}`)) });
64
+ };
65
+ //#endregion
66
+ //#region src/form/utils.ts
67
+ /**
68
+ * Retrieves validation errors for a specific field from the pre-indexed error map.
69
+ *
70
+ * Uses O(1) map lookup by `fieldId`. When `itemIndex` is omitted, returns only
71
+ * **field-level** errors (those without an `itemIndex`). When `itemIndex` is
72
+ * provided, returns only **item-level** errors matching the given array item index.
73
+ *
74
+ * @param fieldErrors - Map from field id to its validation errors.
75
+ * @param fieldId - The numeric ID of the field to retrieve errors for.
76
+ * @param itemIndex - Optional zero-based index of the array item. When omitted, only
77
+ * field-level errors (where `itemIndex` is `null` / `undefined`) are returned.
78
+ * @returns Errors for the given field (and optionally item index). Empty array if none.
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * // Field-level errors only (no itemIndex on the error)
83
+ * getFieldErrors(fieldErrors, 5)
84
+ *
85
+ * // Errors for the third item of array field 5
86
+ * getFieldErrors(fieldErrors, 5, 2)
87
+ * ```
88
+ */
89
+ const getFieldErrors = (fieldErrors, fieldId, itemIndex) => {
90
+ const errors = fieldErrors.get(fieldId) ?? [];
91
+ if (itemIndex === void 0) return errors.filter((e) => e.itemIndex == null);
92
+ return errors.filter((e) => e.itemIndex === itemIndex);
93
+ };
94
+ /**
95
+ * Creates a synthetic {@link FieldContentItem} that represents a single item inside an array field.
96
+ *
97
+ * Array fields store their per-item schema in `arrayField.item` ({@link ArrayItemDef}).
98
+ * Components that render individual array items need a standard `FieldContentItem` shape,
99
+ * so this helper projects the item definition into one, preserving the parent field's `id`
100
+ * while adopting the item's `type`, `label`, `description`, `validation`, and `options`.
101
+ *
102
+ * @param arrayField - The array field definition whose `.item` property describes the item schema.
103
+ * @param _index - The zero-based position of the item in the array (reserved for future use,
104
+ * e.g. per-item overrides).
105
+ * @returns A `FieldContentItem` that can be passed directly to a typed field component.
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * const arrayField: FieldContentItem = {
110
+ * id: 10, type: 'array', label: 'Tags',
111
+ * item: { type: 'string', label: 'Tag' },
112
+ * }
113
+ *
114
+ * const itemDef = getArrayField(arrayField, 0)
115
+ * // → { id: 10, type: 'string', label: 'Tag', ... }
116
+ * ```
117
+ */
118
+ const getArrayField = (arrayField, _index) => {
119
+ const itemDef = arrayField.item;
120
+ return {
121
+ id: arrayField.id,
122
+ type: itemDef.type,
123
+ label: itemDef.label,
124
+ description: itemDef.description,
125
+ validation: itemDef.validation,
126
+ options: itemDef.options
127
+ };
128
+ };
129
+ /**
130
+ * Recursively searches content items for a section with the given id.
131
+ *
132
+ * Walks the content tree depth-first, checking sections and their nested
133
+ * content. Returns the first matching {@link SectionContentItem}, or
134
+ * `undefined` if no section with that id exists.
135
+ *
136
+ * @param items - The content items to search through.
137
+ * @param sectionId - The numeric id of the section to find.
138
+ * @returns The matching section, or `undefined` if not found.
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * const section = findSection(definition.content, 42)
143
+ * if (section) {
144
+ * // render section.content
145
+ * }
146
+ * ```
147
+ */
148
+ const findSection = (items, sectionId) => {
149
+ for (const item of items) if (item.type === "section") {
150
+ if (item.id === sectionId) return item;
151
+ const found = findSection(item.content, sectionId);
152
+ if (found) return found;
153
+ }
154
+ };
155
+ //#endregion
156
+ //#region src/form/form-items.tsx
157
+ const FormItems = ({ items, visibilityMap, values, fieldErrors, components, showInlineValidation, renderFieldProps, renderArrayItemProps }) => {
158
+ const SectionComponent = components.section;
159
+ const ErrorComponent = showInlineValidation ? components.error : void 0;
160
+ const elements = [];
161
+ for (const item of items) {
162
+ if (!visibilityMap.get(item.id)) continue;
163
+ if (item.type === "section") elements.push(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SectionComponent, {
164
+ section: item,
165
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FormItems, {
166
+ items: item.content,
167
+ visibilityMap,
168
+ values,
169
+ fieldErrors,
170
+ components,
171
+ showInlineValidation,
172
+ renderFieldProps,
173
+ renderArrayItemProps
174
+ })
175
+ }, item.id));
176
+ else if (item.type === "array") {
177
+ const errors = getFieldErrors(fieldErrors, item.id);
178
+ const modeProps = renderFieldProps?.(item) ?? {};
179
+ const ArrayComponent = components.array;
180
+ const arrayValue = values[String(item.id)] ?? [];
181
+ const itemDef = item.item;
182
+ const ItemComponent = components[itemDef.type];
183
+ elements.push(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ArrayComponent, {
184
+ field: item,
185
+ value: values[String(item.id)],
186
+ itemDef: item.item,
187
+ errors,
188
+ ...modeProps,
189
+ children: ItemComponent ? arrayValue.map((itemValue, index) => {
190
+ const itemErrors = getFieldErrors(fieldErrors, item.id, index);
191
+ const synthetic = getArrayField(item, index);
192
+ const baseProps = {
193
+ field: synthetic,
194
+ value: itemValue,
195
+ errors: itemErrors,
196
+ ...renderArrayItemProps?.(item, index) ?? {}
197
+ };
198
+ if (itemDef.type === "select") baseProps.options = itemDef.options ?? [];
199
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ItemComponent, { ...baseProps }), ErrorComponent && itemErrors.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorComponent, {
200
+ errors: itemErrors,
201
+ field: synthetic
202
+ })] }, `${item.id}-${index}`);
203
+ }) : null
204
+ }, item.id));
205
+ if (ErrorComponent && errors.length > 0) elements.push(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorComponent, {
206
+ errors,
207
+ field: item
208
+ }, `${item.id}-error`));
209
+ } else {
210
+ const errors = getFieldErrors(fieldErrors, item.id);
211
+ const modeProps = renderFieldProps?.(item) ?? {};
212
+ const fieldProps = {
213
+ field: item,
214
+ value: values[String(item.id)],
215
+ errors,
216
+ ...modeProps
217
+ };
218
+ if (item.type === "select") fieldProps.options = item.options ?? [];
219
+ const FieldComponent = components[item.type];
220
+ elements.push(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(FieldComponent, { ...fieldProps }, item.id));
221
+ if (ErrorComponent && errors.length > 0) elements.push(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorComponent, {
222
+ errors,
223
+ field: item
224
+ }, `${item.id}-error`));
225
+ }
226
+ }
227
+ if (elements.length === 0) return null;
228
+ return elements;
229
+ };
230
+ //#endregion
231
+ //#region src/form/form-content.tsx
232
+ const FormContent = (props) => {
233
+ const { items, visibilityMap, values, fieldErrors, section, showInlineValidation } = props;
234
+ const sharedProps = props.mode === "editor" ? {
235
+ visibilityMap,
236
+ values,
237
+ fieldErrors,
238
+ components: props.components,
239
+ showInlineValidation,
240
+ renderFieldProps: props.renderFieldProps,
241
+ renderArrayItemProps: props.renderArrayItemProps
242
+ } : {
243
+ visibilityMap,
244
+ values,
245
+ fieldErrors,
246
+ components: props.components,
247
+ showInlineValidation
248
+ };
249
+ if (section === void 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FormItems, {
250
+ items,
251
+ ...sharedProps
252
+ });
253
+ if (section === ROOT) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FormItems, {
254
+ items: items.filter((item) => item.type !== "section"),
255
+ ...sharedProps
256
+ });
257
+ const foundSection = findSection(items, section);
258
+ if (!foundSection || !visibilityMap.get(foundSection.id)) return null;
259
+ const Section = props.components.section;
260
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Section, {
261
+ section: foundSection,
262
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FormItems, {
263
+ items: foundSection.content,
264
+ ...sharedProps
265
+ })
266
+ }, foundSection.id);
267
+ };
268
+ //#endregion
269
+ //#region src/form-editor.tsx
270
+ const FormEditor = ({ components, onChange }) => {
271
+ const { definition, data, visibilityMap, fieldErrors, section, engine, showInlineValidation, documentErrors } = useFormContext();
272
+ const { renderFieldProps, renderArrayItemProps } = useEditorHandlers(engine, data, onChange);
273
+ if (!definition || !data || documentErrors && documentErrors.length > 0) return null;
274
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FormContent, {
275
+ mode: "editor",
276
+ items: definition.content,
277
+ visibilityMap,
278
+ values: data.values,
279
+ fieldErrors,
280
+ components,
281
+ section,
282
+ showInlineValidation,
283
+ renderFieldProps,
284
+ renderArrayItemProps
285
+ });
286
+ };
287
+ const useEditorHandlers = (engine, data, onChange) => {
288
+ const stateRef = (0, react.useRef)({
289
+ data,
290
+ onChange,
291
+ engine
292
+ });
293
+ stateRef.current = {
294
+ data,
295
+ onChange,
296
+ engine
297
+ };
298
+ const fieldOnChangeMap = (0, react.useRef)(/* @__PURE__ */ new Map());
299
+ const getFieldOnChange = (0, react.useCallback)((fieldId) => {
300
+ const key = String(fieldId);
301
+ let handler = fieldOnChangeMap.current.get(key);
302
+ if (!handler) {
303
+ handler = (newValue) => {
304
+ const { data, onChange, engine } = stateRef.current;
305
+ if (!data || !engine) return;
306
+ const document = {
307
+ ...data,
308
+ values: {
309
+ ...data.values,
310
+ [key]: newValue
311
+ }
312
+ };
313
+ onChange(document, engine.validate(document));
314
+ };
315
+ fieldOnChangeMap.current.set(key, handler);
316
+ }
317
+ return handler;
318
+ }, []);
319
+ const arrayHandlersMap = (0, react.useRef)(/* @__PURE__ */ new Map());
320
+ const getArrayHandlers = (0, react.useCallback)((fieldId) => {
321
+ const key = String(fieldId);
322
+ let handlers = arrayHandlersMap.current.get(key);
323
+ if (!handlers) {
324
+ const fire = (mutate) => {
325
+ const { data, onChange, engine } = stateRef.current;
326
+ if (!data || !engine) return;
327
+ const items = data.values[key] ?? [];
328
+ const document = {
329
+ ...data,
330
+ values: {
331
+ ...data.values,
332
+ [key]: mutate([...items])
333
+ }
334
+ };
335
+ onChange(document, engine.validate(document));
336
+ };
337
+ handlers = {
338
+ onAddItem: () => fire((values) => {
339
+ values.push(void 0);
340
+ return values;
341
+ }),
342
+ onRemoveItem: (index) => fire((values) => {
343
+ values.splice(index, 1);
344
+ return values;
345
+ }),
346
+ onMoveItem: (fromIndex, toIndex) => fire((values) => {
347
+ const [moved] = values.splice(fromIndex, 1);
348
+ values.splice(toIndex, 0, moved);
349
+ return values;
350
+ })
351
+ };
352
+ arrayHandlersMap.current.set(key, handlers);
353
+ }
354
+ return handlers;
355
+ }, []);
356
+ const arrayItemOnChangeMap = (0, react.useRef)(/* @__PURE__ */ new Map());
357
+ const getArrayItemOnChange = (0, react.useCallback)((fieldId, index) => {
358
+ const mapKey = `${fieldId}-${index}`;
359
+ let handler = arrayItemOnChangeMap.current.get(mapKey);
360
+ if (!handler) {
361
+ handler = (newValue) => {
362
+ const fieldKey = String(fieldId);
363
+ const { data, onChange, engine } = stateRef.current;
364
+ if (!data || !engine) return;
365
+ const items = [...data.values[fieldKey] ?? []];
366
+ items[index] = newValue;
367
+ const document = {
368
+ ...data,
369
+ values: {
370
+ ...data.values,
371
+ [fieldKey]: items
372
+ }
373
+ };
374
+ onChange(document, engine.validate(document));
375
+ };
376
+ arrayItemOnChangeMap.current.set(mapKey, handler);
377
+ }
378
+ return handler;
379
+ }, []);
380
+ return {
381
+ renderFieldProps: (field) => {
382
+ if (field.type === "array") return {
383
+ onChange: getFieldOnChange(field.id),
384
+ ...getArrayHandlers(field.id)
385
+ };
386
+ return { onChange: getFieldOnChange(field.id) };
387
+ },
388
+ renderArrayItemProps: (field, index) => ({ onChange: getArrayItemOnChange(field.id, index) })
389
+ };
390
+ };
391
+ //#endregion
392
+ //#region src/form-fields-validation.tsx
393
+ const FormFieldsValidation = ({ container: ContainerComponent, field: FieldComponent, error: ErrorComponent }) => {
394
+ const { engine, data, fieldErrors, visibilityMap } = useFormContext();
395
+ const groups = (0, react.useMemo)(() => {
396
+ if (!engine || !data || fieldErrors.size === 0) return [];
397
+ const result = [];
398
+ for (const [fieldId, errors] of fieldErrors) {
399
+ if (visibilityMap.get(fieldId) === false) continue;
400
+ result.push({
401
+ field: engine.getFieldDef(fieldId),
402
+ errors
403
+ });
404
+ }
405
+ return result;
406
+ }, [
407
+ engine,
408
+ data,
409
+ fieldErrors,
410
+ visibilityMap
411
+ ]);
412
+ if (groups.length === 0) return null;
413
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ContainerComponent, { children: groups.map((group) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FieldComponent, {
414
+ ...group,
415
+ children: group.errors.map((error) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorComponent, { ...error }, `${error.fieldId}-${error.rule}-${error.itemIndex ?? ""}`))
416
+ }, group.field?.id)) });
417
+ };
418
+ //#endregion
419
+ //#region src/form-sections.tsx
420
+ const FormSections = ({ container: Container, item: Item, defaultSectionTitle = "General", defaultSectionDescription, onSelect }) => {
421
+ const { definition, section, visibilityMap, data, documentErrors } = useFormContext();
422
+ const entries = (0, react.useMemo)(() => {
423
+ if (!definition) return [];
424
+ const result = [];
425
+ const rootFields = definition.content.filter((item) => item.type !== "section");
426
+ if (rootFields.some((item) => visibilityMap.get(item.id))) result.push({
427
+ id: ROOT,
428
+ title: defaultSectionTitle,
429
+ description: defaultSectionDescription,
430
+ content: rootFields,
431
+ condition: void 0
432
+ });
433
+ for (const item of definition.content) if (item.type === "section") {
434
+ if (visibilityMap.get(item.id) === false) continue;
435
+ result.push(item);
436
+ }
437
+ return result;
438
+ }, [
439
+ definition?.content,
440
+ visibilityMap,
441
+ data,
442
+ defaultSectionTitle,
443
+ defaultSectionDescription
444
+ ]);
445
+ if (!definition || !data || documentErrors && documentErrors.length > 0) return null;
446
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Container, { children: entries.map((entry) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Item, {
447
+ section: entry,
448
+ active: entry.id === section,
449
+ select: () => onSelect?.(entry.id)
450
+ }, entry.id === ROOT ? "root" : String(entry.id))) });
451
+ };
452
+ //#endregion
453
+ //#region src/form-viewer.tsx
454
+ const FormViewer = ({ components }) => {
455
+ const { definition, data, visibilityMap, fieldErrors, section, showInlineValidation, documentErrors } = useFormContext();
456
+ if (!definition || !data || documentErrors && documentErrors.length > 0) return null;
457
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FormContent, {
458
+ mode: "viewer",
459
+ items: definition.content,
460
+ visibilityMap,
461
+ values: data.values,
462
+ fieldErrors,
463
+ components,
464
+ section,
465
+ showInlineValidation
466
+ });
467
+ };
468
+ //#endregion
469
+ Object.defineProperty(exports, "DocumentError", {
470
+ enumerable: true,
471
+ get: function() {
472
+ return _bluprynt_forms_core.DocumentError;
473
+ }
474
+ });
475
+ exports.Form = Form;
476
+ exports.FormDocumentValidation = FormDocumentValidation;
477
+ exports.FormEditor = FormEditor;
478
+ exports.FormFieldsValidation = FormFieldsValidation;
479
+ exports.FormSections = FormSections;
480
+ Object.defineProperty(exports, "FormValuesEditor", {
481
+ enumerable: true,
482
+ get: function() {
483
+ return _bluprynt_forms_core.FormValuesEditor;
484
+ }
485
+ });
486
+ exports.FormViewer = FormViewer;
487
+ exports.ROOT = ROOT;
488
+ exports.useFormContext = useFormContext;
@@ -0,0 +1,194 @@
1
+ import { ArrayItemDef, ArrayItemDef as ArrayItemDef$1, ContentItem, DocumentError, DocumentValidationError, DocumentValidationError as DocumentValidationError$1, DocumentValidationErrorCode, FieldContentItem, FieldContentItem as FieldContentItem$1, FieldEntry, FieldEntry as FieldEntry$1, FieldType, FieldValidationError, FieldValidationError as FieldValidationError$1, FileValue, FileValue as FileValue$1, FormDefinition, FormDefinition as FormDefinition$1, FormDocument, FormDocument as FormDocument$1, FormEngine, FormSnapshot, FormValidationResult, FormValidationResult as FormValidationResult$1, FormValues, FormValuesEditor, SectionContentItem, SectionContentItem as SectionContentItem$1, SelectOption, SelectOption as SelectOption$1 } from "@bluprynt/forms-core";
2
+ import { ComponentType, FC, PropsWithChildren, ReactNode } from "react";
3
+
4
+ //#region src/constants.d.ts
5
+ declare const ROOT: unique symbol;
6
+ type ROOT = typeof ROOT;
7
+ //#endregion
8
+ //#region src/form-context.d.ts
9
+ type FormContextValue = {
10
+ definition: FormDefinition$1 | undefined;
11
+ data: FormDocument$1 | undefined;
12
+ engine: FormEngine | undefined;
13
+ visibilityMap: Map<number, boolean>;
14
+ validation: FormValidationResult$1 | undefined;
15
+ documentErrors: readonly DocumentValidationError$1[] | undefined;
16
+ fieldErrors: Map<number, FieldValidationError$1[]>;
17
+ section: typeof ROOT | number | undefined;
18
+ showInlineValidation: boolean;
19
+ };
20
+ declare const useFormContext: () => FormContextValue;
21
+ type FormProps = {
22
+ definition?: FormDefinition$1;
23
+ data?: FormDocument$1;
24
+ section?: typeof ROOT | number;
25
+ showInlineValidation?: boolean;
26
+ children: ReactNode;
27
+ };
28
+ declare const Form: FC<FormProps>;
29
+ //#endregion
30
+ //#region src/form-document-validation.d.ts
31
+ type FormDocumentValidationProps = {
32
+ container: ComponentType<PropsWithChildren>;
33
+ error: ComponentType<DocumentValidationError$1>;
34
+ };
35
+ declare const FormDocumentValidation: FC<FormDocumentValidationProps>;
36
+ //#endregion
37
+ //#region src/types/base.d.ts
38
+ type BaseViewFieldProps = {
39
+ field: FieldContentItem$1;
40
+ errors: FieldValidationError$1[];
41
+ };
42
+ type BaseEditFieldProps = BaseViewFieldProps & {
43
+ onChange: (value: unknown) => void;
44
+ };
45
+ type ErrorProps = {
46
+ errors: FieldValidationError$1[];
47
+ field: FieldContentItem$1;
48
+ };
49
+ //#endregion
50
+ //#region src/types/editor.d.ts
51
+ type StringEditProps = BaseEditFieldProps & {
52
+ value: string | undefined;
53
+ onChange: (value: string | undefined) => void;
54
+ };
55
+ type NumberEditProps = BaseEditFieldProps & {
56
+ value: number | undefined;
57
+ onChange: (value: number | undefined) => void;
58
+ };
59
+ type BooleanEditProps = BaseEditFieldProps & {
60
+ value: boolean | undefined;
61
+ onChange: (value: boolean | undefined) => void;
62
+ };
63
+ type DateEditProps = BaseEditFieldProps & {
64
+ value: string | undefined;
65
+ onChange: (value: string | undefined) => void;
66
+ };
67
+ type SelectEditProps = BaseEditFieldProps & {
68
+ value: string | number | undefined;
69
+ options: SelectOption$1[];
70
+ onChange: (value: string | number | undefined) => void;
71
+ };
72
+ type ArrayEditProps = BaseEditFieldProps & {
73
+ value: unknown[] | undefined;
74
+ itemDef: ArrayItemDef$1;
75
+ children: ReactNode[];
76
+ onAddItem: () => void;
77
+ onRemoveItem: (index: number) => void;
78
+ onMoveItem: (fromIndex: number, toIndex: number) => void;
79
+ };
80
+ type FileEditProps = BaseEditFieldProps & {
81
+ value: FileValue$1 | undefined;
82
+ onChange: (value: FileValue$1 | undefined) => void;
83
+ };
84
+ type SectionEditProps = {
85
+ section: SectionContentItem$1;
86
+ children: ReactNode;
87
+ };
88
+ type EditorComponentMap = {
89
+ string: ComponentType<StringEditProps>;
90
+ number: ComponentType<NumberEditProps>;
91
+ boolean: ComponentType<BooleanEditProps>;
92
+ date: ComponentType<DateEditProps>;
93
+ select: ComponentType<SelectEditProps>;
94
+ array: ComponentType<ArrayEditProps>;
95
+ file: ComponentType<FileEditProps>;
96
+ section: ComponentType<SectionEditProps>;
97
+ error?: ComponentType<ErrorProps>;
98
+ };
99
+ type EditorFieldProps = {
100
+ onChange: (value: unknown) => void;
101
+ onAddItem?: () => void;
102
+ onRemoveItem?: (index: number) => void;
103
+ onMoveItem?: (fromIndex: number, toIndex: number) => void;
104
+ };
105
+ type EditorArrayItemProps = {
106
+ onChange: (value: unknown) => void;
107
+ };
108
+ //#endregion
109
+ //#region src/types/viewer.d.ts
110
+ type StringViewProps = BaseViewFieldProps & {
111
+ value: string | undefined;
112
+ };
113
+ type NumberViewProps = BaseViewFieldProps & {
114
+ value: number | undefined;
115
+ };
116
+ type BooleanViewProps = BaseViewFieldProps & {
117
+ value: boolean | undefined;
118
+ };
119
+ type DateViewProps = BaseViewFieldProps & {
120
+ value: string | undefined;
121
+ };
122
+ type SelectViewProps = BaseViewFieldProps & {
123
+ value: string | number | undefined;
124
+ options: SelectOption$1[];
125
+ };
126
+ type ArrayViewProps = BaseViewFieldProps & {
127
+ value: unknown[] | undefined;
128
+ itemDef: ArrayItemDef$1;
129
+ children: ReactNode[];
130
+ };
131
+ type FileViewProps = BaseViewFieldProps & {
132
+ value: FileValue$1 | undefined;
133
+ };
134
+ type SectionViewProps = {
135
+ section: SectionContentItem$1;
136
+ children: ReactNode;
137
+ };
138
+ type ViewerComponentMap = {
139
+ string: ComponentType<StringViewProps>;
140
+ number: ComponentType<NumberViewProps>;
141
+ boolean: ComponentType<BooleanViewProps>;
142
+ date: ComponentType<DateViewProps>;
143
+ select: ComponentType<SelectViewProps>;
144
+ array: ComponentType<ArrayViewProps>;
145
+ file: ComponentType<FileViewProps>;
146
+ section: ComponentType<SectionViewProps>;
147
+ error?: ComponentType<ErrorProps>;
148
+ };
149
+ //#endregion
150
+ //#region src/form-editor.d.ts
151
+ type FormEditorProps = {
152
+ components: EditorComponentMap;
153
+ onChange: (data: FormDocument$1, validation: FormValidationResult$1) => void;
154
+ };
155
+ declare const FormEditor: FC<FormEditorProps>;
156
+ //#endregion
157
+ //#region src/form-fields-validation.d.ts
158
+ type FieldValidationFieldEntry = {
159
+ field: FieldEntry$1 | undefined;
160
+ errors: FieldValidationError$1[];
161
+ };
162
+ type FormFieldsValidationProps = {
163
+ container: ComponentType<PropsWithChildren>;
164
+ field: ComponentType<PropsWithChildren<FieldValidationFieldEntry>>;
165
+ error: ComponentType<FieldValidationError$1>;
166
+ };
167
+ declare const FormFieldsValidation: FC<FormFieldsValidationProps>;
168
+ //#endregion
169
+ //#region src/form-sections.d.ts
170
+ type FormSectionEntry = Omit<SectionContentItem$1, 'id' | 'type'> & {
171
+ id: typeof ROOT | number;
172
+ };
173
+ type FormSectionItemProps = {
174
+ section: FormSectionEntry;
175
+ active: boolean;
176
+ select: () => void;
177
+ };
178
+ type FormSectionsProps = {
179
+ container: ComponentType<PropsWithChildren>;
180
+ item: ComponentType<FormSectionItemProps>;
181
+ defaultSectionTitle?: string;
182
+ defaultSectionDescription?: string;
183
+ onSelect?: (id: typeof ROOT | number) => void;
184
+ };
185
+ declare const FormSections: FC<FormSectionsProps>;
186
+ //#endregion
187
+ //#region src/form-viewer.d.ts
188
+ type FormViewerProps = {
189
+ components: ViewerComponentMap;
190
+ };
191
+ declare const FormViewer: FC<FormViewerProps>;
192
+ //#endregion
193
+ export { type ArrayEditProps, type ArrayItemDef, type ArrayViewProps, type BaseEditFieldProps, type BaseViewFieldProps, type BooleanEditProps, type BooleanViewProps, type ContentItem, type DateEditProps, type DateViewProps, DocumentError, type DocumentValidationError, type DocumentValidationErrorCode, type EditorArrayItemProps, type EditorComponentMap, type EditorFieldProps, type ErrorProps, type FieldContentItem, type FieldEntry, type FieldType, type FieldValidationError, type FieldValidationFieldEntry, type FileEditProps, type FileValue, type FileViewProps, Form, type FormDefinition, type FormDocument, FormDocumentValidation, FormEditor, FormFieldsValidation, type FormSectionEntry, type FormSectionItemProps, FormSections, type FormSnapshot, type FormValidationResult, type FormValues, FormValuesEditor, FormViewer, type NumberEditProps, type NumberViewProps, ROOT, type SectionContentItem, type SectionEditProps, type SectionViewProps, type SelectEditProps, type SelectOption, type SelectViewProps, type StringEditProps, type StringViewProps, type ViewerComponentMap, useFormContext };
194
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/constants.ts","../src/form-context.tsx","../src/form-document-validation.tsx","../src/types/base.ts","../src/types/editor.ts","../src/types/viewer.ts","../src/form-editor.tsx","../src/form-fields-validation.tsx","../src/form-sections.tsx","../src/form-viewer.tsx"],"mappings":";;;;cAAa,IAAA;AAAA,KACD,IAA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