@nice2dev/ui-forms 1.0.22 → 1.0.23

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.d.ts CHANGED
@@ -4,15 +4,18 @@ import { NiceBaseProps } from '@nice2dev/ui-core';
4
4
  import { NiceComponentTutorial } from '@nice2dev/ui';
5
5
  import { NiceComponentTutorial as NiceComponentTutorial_2 } from '@nice2dev/ui-core';
6
6
  import { NiceConsoleTab } from '@nice2dev/ui';
7
+ import { NiceDataSourceDef } from '@nice2dev/ui';
7
8
  import { NiceFormItem } from '@nice2dev/ui';
8
9
  import { NiceHookBinding } from '@nice2dev/ui';
9
10
  import { NiceLifecycleHandlerOption } from '@nice2dev/ui';
10
11
  import { NiceLifecycleTrigger } from '@nice2dev/ui';
11
12
  import { NiceLogEntry } from '@nice2dev/ui';
13
+ import { NiceRbacModel } from '@nice2dev/ui';
12
14
  import { NiceRevision } from '@nice2dev/ui';
13
15
  import { NiceScriptRunnerProps } from '@nice2dev/ui';
14
16
  import { NiceStandardProps } from '@nice2dev/ui';
15
- import { NiceViewDefinitionV2 } from '@nice2dev/ui';
17
+ import { NiceViewDefinition } from '@nice2dev/ui';
18
+ import { NiceWorkflowDefinition } from '@nice2dev/ui';
16
19
  import { RefAttributes } from 'react';
17
20
 
18
21
  declare interface AIGeneratedField {
@@ -25,186 +28,24 @@ declare interface AIGeneratedField {
25
28
  helpText?: string;
26
29
  }
27
30
 
28
- declare interface BarcodeConfig {
29
- formats: ('ean13' | 'ean8' | 'code128' | 'code39' | 'qr' | 'datamatrix' | 'pdf417')[];
30
- autoFill?: {
31
- field: string;
32
- property: string;
33
- }[];
34
- enableCamera?: boolean;
35
- enableManualEntry?: boolean;
36
- }
37
-
38
- declare interface CalculationConfig {
39
- expression: string;
40
- dependencies: string[];
41
- format?: 'number' | 'currency' | 'percentage' | 'date';
42
- precision?: number;
43
- currencyCode?: string;
44
- }
45
-
46
- declare interface DataBindingConfig {
47
- entityType: string;
48
- fieldPath: string;
49
- direction: 'read' | 'write' | 'both';
50
- transform?: string;
51
- defaultFromEntity?: boolean;
52
- }
53
-
54
- declare interface FieldI18n {
55
- label?: Record<string, string>;
56
- placeholder?: Record<string, string>;
57
- helpText?: Record<string, string>;
58
- options?: Record<string, {
59
- value: string;
60
- label: string;
61
- }[]>;
62
- }
63
-
64
- declare interface FormDesignerContextValue {
65
- schema: FormDesignerSchema;
66
- selectedFieldId: string | null;
67
- selectedTabId: string | null;
68
- locale: string;
69
- setSchema: (schema: FormDesignerSchema) => void;
70
- selectField: (fieldId: string | null) => void;
71
- selectTab: (tabId: string | null) => void;
72
- addField: (containerId: string, field: FormDesignerField, index?: number) => void;
73
- updateField: (fieldId: string, updates: Partial<FormDesignerField>) => void;
74
- removeField: (fieldId: string) => void;
75
- moveField: (fieldId: string, toContainerId: string, toIndex: number) => void;
76
- duplicateField: (fieldId: string) => void;
77
- addTab: (tab: FormDesignerTab, index?: number) => void;
78
- updateTab: (tabId: string, updates: Partial<FormDesignerTab>) => void;
79
- removeTab: (tabId: string) => void;
80
- setLocale: (locale: string) => void;
81
- loadTemplate: (template: FormTemplate) => void;
82
- saveAsTemplate: (name: string, category: string) => FormTemplate;
83
- }
84
-
85
- declare interface FormDesignerField {
86
- id: string;
87
- type: FormDesignerFieldType;
88
- name: string;
89
- label?: string;
90
- placeholder?: string;
91
- helpText?: string;
92
- defaultValue?: unknown;
93
- options?: FormFieldOption_2[];
94
- validations?: FormFieldValidation_2[];
95
- conditions?: FormFieldCondition_2[];
96
- colSpan?: number;
97
- rowSpan?: number;
98
- className?: string;
99
- style?: default_2.CSSProperties;
100
- disabled?: boolean;
101
- readonly?: boolean;
102
- hidden?: boolean;
103
- lookup?: LookupConfig;
104
- calculation?: CalculationConfig;
105
- barcode?: BarcodeConfig;
106
- dataBinding?: DataBindingConfig;
107
- i18n?: FieldI18n;
108
- children?: FormDesignerField[];
109
- props?: Record<string, unknown>;
110
- }
111
-
112
- declare type FormDesignerFieldType = 'text' | 'textarea' | 'number' | 'email' | 'password' | 'phone' | 'url' | 'date' | 'datetime' | 'time' | 'dateRange' | 'select' | 'multiselect' | 'checkbox' | 'toggle' | 'radio' | 'slider' | 'rating' | 'richtext' | 'markdown' | 'code' | 'file' | 'image' | 'signature' | 'lookup' | 'calculated' | 'barcode' | 'qrcode' | 'currency' | 'percentage' | 'section' | 'tab' | 'divider' | 'spacer' | 'heading' | 'paragraph' | 'repeater' | 'table' | 'address' | 'geolocation';
113
-
114
- declare interface FormDesignerSchema {
115
- version: string;
116
- id: string;
117
- title?: string;
118
- description?: string;
119
- entityType?: string;
120
- layout: {
121
- type: 'flat' | 'tabs' | 'wizard' | 'accordion';
122
- columns: 1 | 2 | 3 | 4;
123
- labelPosition: 'top' | 'left' | 'floating';
124
- size: 'sm' | 'md' | 'lg';
125
- gap: 'sm' | 'md' | 'lg';
126
- };
127
- sections?: FormDesignerSection[];
128
- tabs?: FormDesignerTab[];
129
- submit?: {
130
- label: string;
131
- labelKey?: string;
132
- style?: 'primary' | 'secondary' | 'success';
133
- position?: 'left' | 'center' | 'right';
134
- showCancel?: boolean;
135
- cancelLabel?: string;
136
- cancelLabelKey?: string;
137
- };
138
- computedFields?: {
139
- name: string;
140
- expression: string;
141
- dependencies: string[];
142
- }[];
143
- validations?: {
144
- type: 'crossField';
145
- expression: string;
146
- message: string;
147
- messageKey?: string;
148
- }[];
149
- defaultLocale?: string;
150
- supportedLocales?: string[];
151
- i18n?: {
152
- title?: Record<string, string>;
153
- description?: Record<string, string>;
154
- };
155
- meta?: {
156
- createdAt?: string;
157
- updatedAt?: string;
158
- author?: string;
159
- tags?: string[];
160
- };
161
- }
162
-
163
- declare interface FormDesignerSection {
164
- id: string;
165
- title?: string;
166
- description?: string;
167
- collapsible?: boolean;
168
- defaultCollapsed?: boolean;
169
- columns?: 1 | 2 | 3 | 4;
170
- fields: FormDesignerField[];
171
- i18n?: {
172
- title?: Record<string, string>;
173
- description?: Record<string, string>;
174
- };
175
- }
176
-
177
- declare interface FormDesignerTab {
178
- id: string;
179
- title: string;
180
- icon?: string;
181
- disabled?: boolean;
182
- badge?: string | number;
183
- fields: FormDesignerField[];
184
- i18n?: {
185
- title?: Record<string, string>;
186
- };
187
- }
188
-
189
31
  /**
190
- * Conditional visibility rule
32
+ * Identity helper that infers the precise `schema` type from a section literal,
33
+ * so consumers can write a plain JSON-Schema object without `as JsonSchema`
34
+ * assertions. `const general = defineManifestSection({ id, title, schema: {…} });`
191
35
  */
192
- declare interface FormFieldCondition {
36
+ export declare function defineManifestSection<TSchema extends JsonSchema>(section: NiceManifestSection<TSchema>): NiceManifestSection<TSchema>;
37
+
38
+ /** Convert a FormSchema into NiceForm items (for `NiceForm`). */
39
+ export declare function formBuilderSchemaToNiceFormItems(schema: FormSchema): NiceFormItem[];
40
+
41
+ /** Conditional visibility rule. */
42
+ export declare interface FormFieldCondition {
193
43
  field: string;
194
44
  operator: 'equals' | 'notEquals' | 'contains' | 'greaterThan' | 'lessThan' | 'isEmpty' | 'isNotEmpty';
195
45
  value?: any;
196
46
  }
197
47
 
198
- declare interface FormFieldCondition_2 {
199
- field: string;
200
- operator: 'equals' | 'notEquals' | 'contains' | 'startsWith' | 'endsWith' | 'greaterThan' | 'lessThan' | 'isEmpty' | 'isNotEmpty' | 'in' | 'notIn';
201
- value?: unknown;
202
- logicalOperator?: 'and' | 'or';
203
- }
204
-
205
- /**
206
- * Form field definition
207
- */
48
+ /** Form field definition. */
208
49
  export declare interface FormFieldDefinition {
209
50
  /** Unique field ID */
210
51
  id: string;
@@ -244,10 +85,8 @@ export declare interface FormFieldDefinition {
244
85
  children?: FormFieldDefinition[];
245
86
  }
246
87
 
247
- /**
248
- * Option for select/radio fields
249
- */
250
- declare interface FormFieldOption {
88
+ /** Option for select/radio fields. */
89
+ export declare interface FormFieldOption {
251
90
  value: string | number;
252
91
  label: string;
253
92
  disabled?: boolean;
@@ -255,43 +94,23 @@ declare interface FormFieldOption {
255
94
  id?: string;
256
95
  }
257
96
 
258
- declare interface FormFieldOption_2 {
259
- value: string | number;
260
- label: string;
261
- disabled?: boolean;
262
- icon?: string;
263
- }
264
-
265
97
  /**
266
98
  * Convert the repo's own {@link FormFieldDefinition}[] model into NiceForm items.
267
99
  * Layout-only field types (heading/paragraph/divider/spacer/section/image) are skipped.
268
100
  */
269
101
  export declare function formFieldsToFormItems(fields: FormFieldDefinition[], options?: JsonSchemaToFormItemsOptions): NiceFormItem[];
270
102
 
271
- /**
272
- * Available field types
273
- */
103
+ /** Available field types. */
274
104
  export declare type FormFieldType = 'text' | 'textarea' | 'number' | 'email' | 'password' | 'phone' | 'url' | 'date' | 'datetime' | 'time' | 'select' | 'multiselect' | 'checkbox' | 'toggle' | 'radio' | 'slider' | 'rating' | 'color' | 'file' | 'signature' | 'richtext' | 'markdown' | 'code' | 'heading' | 'paragraph' | 'divider' | 'spacer' | 'image' | 'section';
275
105
 
276
- /**
277
- * Validation rule
278
- */
279
- declare interface FormFieldValidation {
106
+ /** Validation rule. */
107
+ export declare interface FormFieldValidation {
280
108
  type: 'required' | 'minLength' | 'maxLength' | 'min' | 'max' | 'pattern' | 'email' | 'url' | 'custom';
281
109
  value?: string | number | boolean;
282
110
  message?: string;
283
111
  }
284
112
 
285
- declare interface FormFieldValidation_2 {
286
- type: 'required' | 'minLength' | 'maxLength' | 'min' | 'max' | 'pattern' | 'email' | 'url' | 'custom' | 'unique';
287
- value?: string | number | boolean;
288
- message?: string;
289
- errorMessageKey?: string;
290
- }
291
-
292
- /**
293
- * Complete form schema
294
- */
113
+ /** Complete form schema. */
295
114
  export declare interface FormSchema {
296
115
  /** Schema version */
297
116
  version: string;
@@ -330,19 +149,7 @@ export declare interface FormSchema {
330
149
  */
331
150
  export declare function formSchemaToJsonSchema(form: FormSchema): JsonSchema;
332
151
 
333
- /** Convert a {@link FormSchema} to a {@link NiceViewDefinitionV2} (form kind). */
334
- export declare function formSchemaToV2(schema: FormSchema, options?: FormSchemaToV2Options): NiceViewDefinitionV2;
335
-
336
- export declare interface FormSchemaToV2Options {
337
- /** Data source key the fields bind to. Default `'record'`. */
338
- source?: string;
339
- /** V2 grid column count. Default `12`. */
340
- columns?: number;
341
- }
342
-
343
- /**
344
- * Form section definition
345
- */
152
+ /** Form section definition. */
346
153
  export declare interface FormSectionDefinition {
347
154
  id: string;
348
155
  title?: string;
@@ -353,17 +160,6 @@ export declare interface FormSectionDefinition {
353
160
  fields: FormFieldDefinition[];
354
161
  }
355
162
 
356
- declare interface FormTemplate {
357
- id: string;
358
- name: string;
359
- description?: string;
360
- category: string;
361
- schema: FormDesignerSchema;
362
- thumbnail?: string;
363
- createdAt?: string;
364
- updatedAt?: string;
365
- }
366
-
367
163
  export declare interface JsonSchema {
368
164
  $schema?: string;
369
165
  $id?: string;
@@ -403,23 +199,6 @@ export declare interface JsonSchemaToFormItemsOptions {
403
199
  renderObjectField?: (value: Record<string, unknown>, onChange: (v: Record<string, unknown>) => void, schema: JsonSchema, label?: string) => default_2.ReactNode;
404
200
  }
405
201
 
406
- declare interface LookupConfig {
407
- entityType: string;
408
- displayField: string;
409
- valueField: string;
410
- searchFields?: string[];
411
- filterExpression?: string;
412
- sortField?: string;
413
- sortDirection?: 'asc' | 'desc';
414
- pageSize?: number;
415
- fetchUrl?: string;
416
- dependsOn?: string[];
417
- cascadeFields?: {
418
- source: string;
419
- target: string;
420
- }[];
421
- }
422
-
423
202
  export declare const NiceArrayField: ForwardRefExoticComponent<NiceArrayFieldProps & RefAttributes<HTMLDivElement>>;
424
203
 
425
204
  export declare interface NiceArrayFieldProps {
@@ -465,11 +244,9 @@ export declare interface NiceEntityEditorProps extends NiceStandardProps {
465
244
  tutorial?: NiceComponentTutorial;
466
245
  }
467
246
 
468
- export declare function NiceFormBuilder({ initialSchema, fields, onChange, onExport, onPreview, className, style, tutorial, }: NiceFormBuilderProps): JSX.Element;
469
-
470
247
  export declare const NiceFormBuilderAI: default_2.ForwardRefExoticComponent<NiceFormBuilderAIProps & default_2.RefAttributes<NiceFormBuilderAIRef>>;
471
248
 
472
- export declare interface NiceFormBuilderAIProps extends Omit<NiceFormBuilderProps, 'ref' | 'onChange' | 'initialSchema'> {
249
+ export declare interface NiceFormBuilderAIProps {
473
250
  /** Enable AI features (requires NiceAIProvider) */
474
251
  enableAI?: boolean;
475
252
  /** AI model to use */
@@ -506,74 +283,6 @@ declare interface NiceFormBuilderAIRef {
506
283
  clearFields: () => void;
507
284
  }
508
285
 
509
- export declare interface NiceFormBuilderProps {
510
- /** Initial form schema */
511
- initialSchema?: FormSchema;
512
- /** Convenience flat list of fields — wrapped into a default schema if `initialSchema` is omitted. */
513
- fields?: Array<Partial<FormFieldDefinition> & {
514
- id: string;
515
- type: string;
516
- label?: string;
517
- }>;
518
- /** Called when schema changes */
519
- onChange?: (schema: FormSchema) => void;
520
- /** Called when export is requested */
521
- onExport?: (schema: FormSchema) => void;
522
- /** Called when preview is requested */
523
- onPreview?: (schema: FormSchema) => void;
524
- /** Custom class */
525
- className?: string;
526
- /** Style */
527
- style?: default_2.CSSProperties;
528
- /** Optional guided tour. `true` = built-in; array/object = custom steps. Shows a "?" button. */
529
- tutorial?: NiceComponentTutorial;
530
- }
531
-
532
- export declare const NiceFormDesigner: default_2.FC<NiceFormDesignerProps>;
533
-
534
- export declare interface NiceFormDesignerProps extends NiceStandardProps {
535
- /** Initial form schema */
536
- schema?: FormDesignerSchema;
537
- /** Called when schema changes */
538
- onChange?: (schema: FormDesignerSchema) => void;
539
- /** Read-only mode */
540
- readOnly?: boolean;
541
- /** Current locale for preview */
542
- locale?: string;
543
- /** Available locales */
544
- locales?: {
545
- code: string;
546
- name: string;
547
- }[];
548
- /** Show palette */
549
- showPalette?: boolean;
550
- /** Show properties panel */
551
- showProperties?: boolean;
552
- /** Show preview toggle */
553
- showPreview?: boolean;
554
- /** Show toolbar */
555
- showToolbar?: boolean;
556
- /** Available entity types for data binding */
557
- entityTypes?: {
558
- name: string;
559
- fields: {
560
- name: string;
561
- type: string;
562
- label: string;
563
- }[];
564
- }[];
565
- /** Form templates */
566
- templates?: FormTemplate[];
567
- /** Called to save as template */
568
- onSaveTemplate?: (template: FormTemplate) => void;
569
- /** Called to load template */
570
- onLoadTemplate?: (templateId: string) => FormTemplate | null;
571
- /** Enable validation */
572
- enableValidation?: boolean;
573
- /** Optional guided tour. `true` = built-in; array/object = custom steps. Shows a "?" button. */
574
- tutorial?: NiceComponentTutorial;
575
- }
576
-
577
286
  export declare const NiceI18nEditor: ForwardRefExoticComponent<NiceI18nEditorProps & RefAttributes<HTMLDivElement>>;
578
287
 
579
288
  export declare interface NiceI18nEditorProps extends NiceBaseProps {
@@ -640,13 +349,20 @@ export declare interface NiceManifestEditorProps extends NiceStandardProps {
640
349
  tutorial?: NiceComponentTutorial;
641
350
  }
642
351
 
643
- /** One editable manifest section, described by a JSON Schema or field model. */
644
- export declare interface NiceManifestSection {
352
+ /**
353
+ * One editable manifest section, described by a JSON Schema or field model.
354
+ *
355
+ * Generic over `TSchema` so a literal JSON-Schema object keeps its precise type
356
+ * (use {@link defineManifestSection} for inference) — no `as JsonSchema` casts on
357
+ * nested `properties`. Defaults to `JsonSchema`, so `NiceManifestSection` and
358
+ * `NiceManifestSection[]` keep working unchanged.
359
+ */
360
+ export declare interface NiceManifestSection<TSchema extends JsonSchema = JsonSchema> {
645
361
  id: string;
646
362
  title: string;
647
363
  icon?: React.ReactNode;
648
364
  /** JSON Schema describing this section's fields (subset of the manifest). */
649
- schema?: JsonSchema;
365
+ schema?: TSchema;
650
366
  /** Or the repo's field-descriptor model. */
651
367
  fields?: FormFieldDefinition[];
652
368
  /** Per-field UI overrides forwarded to NiceSchemaForm. */
@@ -709,8 +425,14 @@ export declare interface NiceModuleFiles {
709
425
  manifest: Record<string, unknown>;
710
426
  entities?: NiceEntity[];
711
427
  i18n?: NiceI18nValue;
712
- /** The module's views (`*.view.json`) — unified `NiceViewDefinitionV2` standard. */
713
- views?: NiceViewDefinitionV2[];
428
+ /** The module's views (`*.view.json`) — unified `NiceViewDefinition` standard. */
429
+ views?: NiceViewDefinition[];
430
+ /** The module's workflows (`*.workflow.json`). */
431
+ workflows?: NiceWorkflowDefinition[];
432
+ /** The module's data sources (no-SQL query definitions). */
433
+ dataSources?: NiceDataSourceDef[];
434
+ /** The module's RBAC model (roles + per-resource access). */
435
+ rbac?: NiceRbacModel;
714
436
  /** Any extra parts the adapter wants to round-trip untouched. */
715
437
  extra?: Record<string, unknown>;
716
438
  }
@@ -758,25 +480,16 @@ export declare interface NiceSchemaFormProps extends NiceStandardProps {
758
480
  tutorial?: NiceComponentTutorial;
759
481
  }
760
482
 
761
- /**
762
- * Convert form schema to NiceForm items
763
- */
483
+ /** Convert a FormSchema into DevExtreme-style form items. */
764
484
  export declare function schemaToFormItems(schema: FormSchema): any[];
765
485
 
766
- export declare function useFormDesigner(): FormDesignerContextValue;
767
-
768
- /** Convert a {@link NiceViewDefinitionV2} back to a {@link FormSchema} (best-effort). */
769
- export declare function v2ToFormSchema(view: NiceViewDefinitionV2): FormSchema;
770
-
771
486
  /**
772
487
  * Validate a value object against a (subset of) Draft-07 JSON Schema.
773
488
  * Covers required, type, enum, minLength/maxLength, minimum/maximum and pattern.
774
489
  */
775
490
  export declare function validateAgainstJsonSchema(value: Record<string, unknown>, schema: JsonSchema): NiceSchemaFormError[];
776
491
 
777
- /**
778
- * Validate form schema
779
- */
492
+ /** Validate a FormSchema; returns `{ valid, errors }`. */
780
493
  export declare function validateFormSchema(schema: FormSchema): {
781
494
  valid: boolean;
782
495
  errors: string[];