@dynamicforms/vue-forms 0.2.6 → 0.3.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.d.ts CHANGED
@@ -5,12 +5,12 @@ export declare class AbortEventHandlingException extends Error {
5
5
  }
6
6
 
7
7
  export declare class Action extends FieldBase {
8
- private readonly _value;
9
- protected constructor(params?: Partial<IFieldConstructorParams<ActionValue>>);
8
+ private _value;
9
+ protected constructor();
10
+ private init;
10
11
  static create(params?: Partial<IField<ActionValue>>): Action;
11
12
  get value(): ActionValue;
12
13
  set value(newValue: ActionValue);
13
- setValue(newValue: ActionValue): Promise<void>;
14
14
  get icon(): string | undefined;
15
15
  set icon(newValue: string | undefined);
16
16
  get label(): string | undefined;
@@ -19,7 +19,7 @@ export declare class Action extends FieldBase {
19
19
  execute(params: any): void;
20
20
  }
21
21
 
22
- declare type ActionExecutor = (field: IField, supr: FieldActionExecute, ...params: any[]) => Promise<any>;
22
+ declare type ActionExecutor = (field: IField, supr: FieldActionExecute, ...params: any[]) => any;
23
23
 
24
24
  export declare class ActionsMap extends Map<symbol, FieldActionExecute> {
25
25
  private readonly eagerActions;
@@ -28,8 +28,9 @@ export declare class ActionsMap extends Map<symbol, FieldActionExecute> {
28
28
  trigger<T extends FieldActionBase>(ActionClass: {
29
29
  new (...args: any[]): T;
30
30
  classIdentifier: symbol;
31
- }, field: IField, ...params: any[]): Promise<any>;
32
- triggerEager(field: IField, ...params: any[]): Promise<any>;
31
+ }, field: IField, ...params: any[]): any;
32
+ triggerEager(field: IField, ...params: any[]): any;
33
+ clone(): ActionsMap;
33
34
  cloneWithoutValidators(): ActionsMap;
34
35
  }
35
36
 
@@ -52,7 +53,7 @@ export declare class ConditionalEnabledAction extends ConditionalStatementAction
52
53
  constructor(statement: Statement);
53
54
  }
54
55
 
55
- declare type ConditionalExecutorFn = (field: IField, currentResult: boolean, previousResult: boolean | undefined) => Promise<void>;
56
+ declare type ConditionalExecutorFn = (field: IField, currentResult: boolean, previousResult: boolean | undefined) => void;
56
57
 
57
58
  export declare class ConditionalStatementAction extends ValueChangedAction {
58
59
  private lastResult;
@@ -98,26 +99,27 @@ export declare namespace DisplayMode {
98
99
  export declare const EmptyField: Field<string>;
99
100
 
100
101
  export declare class EnabledChangedAction extends FieldActionBase {
101
- constructor(executorFn: (field: IField, supr: FieldActionExecute, newValue: boolean, oldValue: boolean) => Promise<void>);
102
+ constructor(executorFn: (field: IField, supr: FieldActionExecute, newValue: boolean, oldValue: boolean) => void);
102
103
  static get classIdentifier(): symbol;
103
- execute(field: IField, supr: FieldActionExecute, newValue: boolean, oldValue: boolean): Promise<void>;
104
+ execute(field: IField, supr: FieldActionExecute, newValue: boolean, oldValue: boolean): void;
104
105
  }
105
106
 
106
107
  export declare class EnabledChangingAction extends FieldActionBase {
107
- constructor(executorFn: (field: IField, supr: FieldActionExecute, newValue: boolean, oldValue: boolean) => Promise<boolean>);
108
+ constructor(executorFn: (field: IField, supr: FieldActionExecute, newValue: boolean, oldValue: boolean) => boolean);
108
109
  static get classIdentifier(): symbol;
109
- execute(field: IField, supr: FieldActionExecute, newValue: boolean, oldValue: boolean): Promise<boolean>;
110
+ execute(field: IField, supr: FieldActionExecute, newValue: boolean, oldValue: boolean): boolean;
110
111
  }
111
112
 
112
113
  export declare class ExecuteAction extends FieldActionBase {
113
- constructor(executorFn: (field: IField, supr: FieldActionExecute, params: any) => Promise<any>);
114
+ constructor(executorFn: (field: IField, supr: FieldActionExecute, params: any) => any);
114
115
  static get classIdentifier(): symbol;
115
- execute(field: IField, supr: FieldActionExecute, params: any): Promise<any>;
116
+ execute(field: IField, supr: FieldActionExecute, params: any): any;
116
117
  }
117
118
 
118
119
  export declare class Field<T = any> extends FieldBase {
119
120
  private _value;
120
- protected constructor(params?: Partial<IFieldConstructorParams<T>>);
121
+ protected constructor();
122
+ private init;
121
123
  /**
122
124
  * Creates a new reactive Field instance.
123
125
  * @param params Initial field parameters
@@ -126,7 +128,6 @@ export declare class Field<T = any> extends FieldBase {
126
128
  static create<T = any>(params?: Partial<IFieldConstructorParams<T>>): Field<T>;
127
129
  get value(): T;
128
130
  set value(newValue: T);
129
- setValue(newValue: T): Promise<void>;
130
131
  clone(overrides?: Partial<IField<T>>): Field<T>;
131
132
  }
132
133
 
@@ -135,22 +136,23 @@ export declare abstract class FieldActionBase implements IFieldAction {
135
136
  get classIdentifier(): symbol;
136
137
  private readonly executorFn;
137
138
  constructor(executorFn: ActionExecutor);
138
- execute(field: IField, supr: IFieldAction['execute'], ...params: any[]): Promise<any>;
139
+ execute(field: IField, supr: IFieldAction['execute'], ...params: any[]): any;
139
140
  get eager(): boolean;
140
141
  boundToField(field: IField): void;
141
142
  unregister(): void;
142
143
  }
143
144
 
144
- export declare type FieldActionExecute<T = any> = (field: IField<T>, ...params: any[]) => Promise<any>;
145
+ export declare type FieldActionExecute<T = any> = (field: IField<T>, ...params: any[]) => any;
145
146
 
146
147
  export declare abstract class FieldBase<T = any> implements IField<T> {
147
148
  abstract get value(): T;
148
149
  abstract set value(newValue: T);
149
- abstract setValue(newValue: T): Promise<void>;
150
150
  readonly reactiveValue: ComputedRef<T>;
151
151
  abstract clone(overrides?: Partial<IField<T>>): IField<T>;
152
152
  originalValue: T;
153
- valid: boolean;
153
+ protected validatingCount: number;
154
+ readonly validating = false;
155
+ protected _valid: boolean;
154
156
  errors: ValidationError[];
155
157
  parent?: Group;
156
158
  fieldName?: string;
@@ -158,12 +160,11 @@ export declare abstract class FieldBase<T = any> implements IField<T> {
158
160
  private _visibility;
159
161
  get visibility(): DisplayMode;
160
162
  set visibility(newValue: DisplayMode);
161
- setVisibility(newValue: DisplayMode): Promise<void>;
162
163
  private _enabled;
163
164
  get enabled(): boolean;
164
165
  set enabled(newValue: boolean);
165
- setEnabled(newValue: boolean): Promise<void>;
166
166
  validate(): void;
167
+ get valid(): boolean;
167
168
  get fullValue(): any;
168
169
  get isChanged(): boolean;
169
170
  registerAction(action: IFieldAction<T>): this;
@@ -220,6 +221,7 @@ declare namespace Form {
220
221
  ValidationError,
221
222
  ValidationErrorText,
222
223
  ValidationErrorRenderContent,
224
+ ValidationFunctionResult,
223
225
  ValidationFunction,
224
226
  Validator
225
227
  }
@@ -241,16 +243,16 @@ export declare class Group<T extends GenericFieldsInterface = GenericFieldsInter
241
243
  private _value;
242
244
  private suppressNotifyValueChanged;
243
245
  constructor(fields: T, params?: Partial<IFieldConstructorParams>);
244
- addField(fieldName: string, field: IField): void;
246
+ private addField;
245
247
  private static isValidFields;
246
248
  static createFromFormData(data: Record<string, any> | null): Group;
247
249
  field<K extends keyof T>(fieldName: K): T[K] | null;
248
250
  get fields(): T;
249
251
  get value(): Record<string, any> | null;
250
252
  set value(newValue: Record<string, any> | null);
251
- setValue(newValue: Record<string, any> | null): Promise<void>;
252
253
  get fullValue(): Record<string, any>;
253
- notifyValueChanged(): Promise<void>;
254
+ notifyValueChanged(): void;
255
+ get valid(): boolean;
254
256
  clone(overrides?: Partial<IField>): Group<T>;
255
257
  }
256
258
 
@@ -260,15 +262,13 @@ export declare interface IField<T = any> {
260
262
  fullValue: T;
261
263
  originalValue: T;
262
264
  valid: boolean;
265
+ validating: boolean;
263
266
  errors: ValidationError[];
264
267
  enabled: boolean;
265
268
  visibility: DisplayMode;
266
269
  parent?: any;
267
270
  fieldName?: string;
268
271
  clone(overrides?: Partial<IField<T>>): IField<T>;
269
- setVisibility(newValue: DisplayMode): Promise<void>;
270
- setEnabled(newValue: boolean): Promise<void>;
271
- setValue(newValue: T): Promise<void>;
272
272
  registerAction(action: IFieldAction<T>): this;
273
273
  triggerAction<T2 extends IFieldAction<T>>(actionClass: abstract new (...args: any[]) => T2, ...params: any[]): any;
274
274
  validate(): void;
@@ -311,9 +311,9 @@ export declare class List<T extends GenericFieldsInterface = GenericFieldsInterf
311
311
  private setValueInternal;
312
312
  get value(): Record<string, any>[] | null;
313
313
  set value(newValue: Record<string, any>[]);
314
- setValue(newValue: Record<string, any>[]): Promise<void>;
315
314
  clone(overrides?: Partial<IField>): List<T>;
316
315
  notifyValueChanged(): void;
316
+ get valid(): boolean;
317
317
  get(index: number): Group<T> | undefined;
318
318
  push(item: any): number;
319
319
  pop(): Group<T> | undefined;
@@ -323,15 +323,15 @@ export declare class List<T extends GenericFieldsInterface = GenericFieldsInterf
323
323
  }
324
324
 
325
325
  export declare class ListItemAddedAction extends FieldActionBase {
326
- constructor(executorFn: (field: IField, supr: FieldActionExecute, item: any, index: number) => Promise<void>);
326
+ constructor(executorFn: (field: IField, supr: FieldActionExecute, item: any, index: number) => void);
327
327
  static get classIdentifier(): symbol;
328
- execute(field: IField, supr: FieldActionExecute, item: any, index: number): Promise<void>;
328
+ execute(field: IField, supr: FieldActionExecute, item: any, index: number): void;
329
329
  }
330
330
 
331
331
  export declare class ListItemRemovedAction extends FieldActionBase {
332
- constructor(executorFn: (field: IField, supr: FieldActionExecute, item: any, index: number) => Promise<void>);
332
+ constructor(executorFn: (field: IField, supr: FieldActionExecute, item: any, index: number) => void);
333
333
  static get classIdentifier(): symbol;
334
- execute(field: IField, supr: FieldActionExecute, item: any, index: number): Promise<void>;
334
+ execute(field: IField, supr: FieldActionExecute, item: any, index: number): void;
335
335
  }
336
336
 
337
337
  declare class MaxLength<T = any> extends Validator {
@@ -461,7 +461,9 @@ export declare class ValidationErrorText extends ValidationError {
461
461
  get componentBody(): string;
462
462
  }
463
463
 
464
- export declare type ValidationFunction<T = any> = (newValue: T, oldValue: T, field: IField<T>) => ValidationError[] | null;
464
+ export declare type ValidationFunction<T = any> = (newValue: T, oldValue: T, field: IField<T>) => ValidationFunctionResult | Promise<ValidationFunctionResult>;
465
+
466
+ export declare type ValidationFunctionResult = ValidationError[] | null;
465
467
 
466
468
  /**
467
469
  * Validator is a specialized action that performs validation when a field's value changes.
@@ -485,6 +487,9 @@ export declare namespace Validators {
485
487
  InAllowedValues,
486
488
  Required_2 as Required,
487
489
  Pattern,
490
+ ValidationFunctionResult,
491
+ ValidationFunction,
492
+ Validator,
488
493
  MinValue,
489
494
  MaxValue,
490
495
  ValueInRange,
@@ -495,15 +500,15 @@ export declare namespace Validators {
495
500
  }
496
501
 
497
502
  export declare class ValidChangedAction extends FieldActionBase {
498
- constructor(executorFn: (field: IField, supr: FieldActionExecute, newValue: boolean, oldValue: boolean) => Promise<void>);
503
+ constructor(executorFn: (field: IField, supr: FieldActionExecute, newValue: boolean, oldValue: boolean) => void);
499
504
  static get classIdentifier(): symbol;
500
- execute(field: IField, supr: FieldActionExecute, newValue: boolean, oldValue: boolean): Promise<void>;
505
+ execute(field: IField, supr: FieldActionExecute, newValue: boolean, oldValue: boolean): void;
501
506
  }
502
507
 
503
508
  export declare class ValueChangedAction<T = any> extends FieldActionBase {
504
- constructor(executorFn: (field: IField<T>, supr: FieldActionExecute<T>, newValue: T, oldValue: T) => Promise<void>);
509
+ constructor(executorFn: (field: IField<T>, supr: FieldActionExecute<T>, newValue: T, oldValue: T) => void);
505
510
  static get classIdentifier(): symbol;
506
- execute(field: IField<T>, supr: FieldActionExecute<T>, newValue: T, oldValue: T): Promise<void>;
511
+ execute(field: IField<T>, supr: FieldActionExecute<T>, newValue: T, oldValue: T): void;
507
512
  }
508
513
 
509
514
  declare class ValueInRange<T = any> extends Validator {
@@ -511,15 +516,15 @@ declare class ValueInRange<T = any> extends Validator {
511
516
  }
512
517
 
513
518
  export declare class VisibilityChangedAction extends FieldActionBase {
514
- constructor(executorFn: (field: IField, supr: FieldActionExecute, newValue: DisplayMode, oldValue: DisplayMode) => Promise<void>);
519
+ constructor(executorFn: (field: IField, supr: FieldActionExecute, newValue: DisplayMode, oldValue: DisplayMode) => void);
515
520
  static get classIdentifier(): symbol;
516
- execute(field: IField, supr: FieldActionExecute, newValue: DisplayMode, oldValue: DisplayMode): Promise<void>;
521
+ execute(field: IField, supr: FieldActionExecute, newValue: DisplayMode, oldValue: DisplayMode): void;
517
522
  }
518
523
 
519
524
  export declare class VisibilityChangingAction extends FieldActionBase {
520
- constructor(executorFn: (field: IField, supr: FieldActionExecute, newValue: DisplayMode, oldValue: DisplayMode) => Promise<DisplayMode>);
525
+ constructor(executorFn: (field: IField, supr: FieldActionExecute, newValue: DisplayMode, oldValue: DisplayMode) => DisplayMode);
521
526
  static get classIdentifier(): symbol;
522
- execute(field: IField, supr: FieldActionExecute, newValue: DisplayMode, oldValue: DisplayMode): Promise<DisplayMode>;
527
+ execute(field: IField, supr: FieldActionExecute, newValue: DisplayMode, oldValue: DisplayMode): DisplayMode;
523
528
  }
524
529
 
525
530
  export { }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dynamicforms/vue-forms",
3
3
  "private": false,
4
- "version": "0.2.6",
4
+ "version": "0.3.0",
5
5
  "type": "module",
6
6
  "description": "Data entry forms for vue - logic (no controls here)",
7
7
  "author": "Jure Erznožnik",
package/readme.md CHANGED
@@ -68,7 +68,7 @@ The library provides a powerful event system for field changes and other actions
68
68
  import { Field, Group, ValueChangedAction, ValidationErrorText } from '@dynamicforms/vue-forms';
69
69
 
70
70
  const emailField = Field.create({ value: '' })
71
- .registerAction(new ValueChangedAction(async (field, supr, newValue, oldValue) => {
71
+ .registerAction(new ValueChangedAction((field, supr, newValue, oldValue) => {
72
72
  // Custom validation on value change
73
73
  if (!newValue.includes('@')) {
74
74
  field.errors = [new ValidationErrorText('Invalid email format')];
@@ -84,7 +84,7 @@ const emailField = Field.create({ value: '' })
84
84
  const form = new Group({
85
85
  email: emailField,
86
86
  username: Field.create()
87
- }).registerAction(new ValueChangedAction(async (field, supr, newValue, oldValue) => {
87
+ }).registerAction(new ValueChangedAction((field, supr, newValue, oldValue) => {
88
88
  console.log('Form data changed:', newValue);
89
89
  return supr(field, newValue, oldValue);
90
90
  }));