@dynamicforms/vue-forms 0.1.1 → 0.1.2
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
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { ComputedRef } from 'vue';
|
|
2
|
+
import { Reactive } from 'vue';
|
|
2
3
|
|
|
3
4
|
export declare class AbortEventHandlingException extends Error {
|
|
4
5
|
}
|
|
5
6
|
|
|
6
7
|
export declare class Action extends FieldBase {
|
|
7
8
|
private readonly _value;
|
|
8
|
-
constructor(params?: Partial<IField
|
|
9
|
+
protected constructor(params?: Partial<IField<ActionValue>>);
|
|
10
|
+
static create(params?: Partial<IField<ActionValue>>): Reactive<Action>;
|
|
9
11
|
get value(): ActionValue;
|
|
10
12
|
set value(newValue: ActionValue);
|
|
11
13
|
get icon(): string | undefined;
|
|
12
14
|
set icon(newValue: string | undefined);
|
|
13
15
|
get label(): string | undefined;
|
|
14
16
|
set label(newValue: string | undefined);
|
|
15
|
-
clone(overrides?: Partial<IField>): Action
|
|
17
|
+
clone(overrides?: Partial<IField>): Reactive<Action>;
|
|
16
18
|
execute(params: any): void;
|
|
17
19
|
}
|
|
18
20
|
|
|
@@ -28,6 +30,8 @@ export declare interface ActionValue {
|
|
|
28
30
|
icon?: string;
|
|
29
31
|
}
|
|
30
32
|
|
|
33
|
+
export declare const defaultDisplayMode = DisplayMode.FULL;
|
|
34
|
+
|
|
31
35
|
/**
|
|
32
36
|
* DisplayMode enum provides an enumeration for supported ways of rendering a particular object in the DOM
|
|
33
37
|
*/
|
|
@@ -66,10 +70,11 @@ export declare class ExecuteAction extends FieldActionBase {
|
|
|
66
70
|
|
|
67
71
|
export declare class Field<T = any> extends FieldBase {
|
|
68
72
|
private _value;
|
|
69
|
-
constructor(params?: Partial<IField<T>>);
|
|
73
|
+
protected constructor(params?: Partial<IField<T>>);
|
|
74
|
+
static create<T = any>(params?: Partial<IField<T>>): Reactive<Field<T>>;
|
|
70
75
|
get value(): T;
|
|
71
76
|
set value(newValue: T);
|
|
72
|
-
clone(overrides?: Partial<IField<T>>): Field<T
|
|
77
|
+
clone(overrides?: Partial<IField<T>>): Reactive<Field<T>>;
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
export declare abstract class FieldActionBase implements IFieldAction {
|
|
@@ -84,6 +89,7 @@ export declare type FieldActionExecute<T = any> = (field: IField<T>, ...params:
|
|
|
84
89
|
declare abstract class FieldBase<T = any> implements IField<T> {
|
|
85
90
|
abstract get value(): T;
|
|
86
91
|
abstract set value(newValue: T);
|
|
92
|
+
readonly reactiveValue: ComputedRef<T>;
|
|
87
93
|
abstract clone(overrides?: Partial<IField<T>>): IField<T>;
|
|
88
94
|
originalValue: T;
|
|
89
95
|
valid: boolean;
|
|
@@ -102,20 +108,52 @@ declare abstract class FieldBase<T = any> implements IField<T> {
|
|
|
102
108
|
validate(): void;
|
|
103
109
|
get fullValue(): any;
|
|
104
110
|
get isChanged(): boolean;
|
|
105
|
-
get reactive(): IField;
|
|
106
111
|
registerAction(action: IFieldAction<T>): this;
|
|
107
112
|
triggerAction<T2 extends IFieldAction<T>>(actionClass: new (...args: any[]) => T2, ...params: any[]): any;
|
|
108
113
|
}
|
|
109
114
|
|
|
115
|
+
declare namespace Form {
|
|
116
|
+
export {
|
|
117
|
+
defaultDisplayMode,
|
|
118
|
+
ValidationError,
|
|
119
|
+
ValidationErrorText,
|
|
120
|
+
FieldActionBase,
|
|
121
|
+
ActionsMap,
|
|
122
|
+
EnabledChangedAction,
|
|
123
|
+
EnabledChangingAction,
|
|
124
|
+
ExecuteAction,
|
|
125
|
+
VisibilityChangedAction,
|
|
126
|
+
VisibilityChangingAction,
|
|
127
|
+
ValidChangedAction,
|
|
128
|
+
ValueChangedAction,
|
|
129
|
+
ListItemAddedAction,
|
|
130
|
+
ListItemRemovedAction,
|
|
131
|
+
ActionValue,
|
|
132
|
+
Action,
|
|
133
|
+
NullableAction,
|
|
134
|
+
Field,
|
|
135
|
+
NullableField,
|
|
136
|
+
EmptyField,
|
|
137
|
+
IField,
|
|
138
|
+
AbortEventHandlingException,
|
|
139
|
+
FieldActionExecute,
|
|
140
|
+
IFieldAction,
|
|
141
|
+
GenericFieldsInterface,
|
|
142
|
+
Group,
|
|
143
|
+
NullableGroup,
|
|
144
|
+
List,
|
|
145
|
+
NullableList
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
export default Form;
|
|
149
|
+
|
|
110
150
|
export declare type GenericFieldsInterface = Record<string, IField>;
|
|
111
151
|
|
|
112
152
|
export declare class Group<T extends GenericFieldsInterface = GenericFieldsInterface> extends FieldBase {
|
|
113
153
|
private readonly _fields;
|
|
114
154
|
private _value;
|
|
115
|
-
readonly reactiveValue: ComputedRef<Record<string, any> | null>;
|
|
116
155
|
private suppressNotifyValueChanged;
|
|
117
156
|
constructor(fields: T, params?: Partial<IField>);
|
|
118
|
-
get reactive(): this;
|
|
119
157
|
private static isValidFields;
|
|
120
158
|
static createFromFormData(data: Record<string, any> | null): Group;
|
|
121
159
|
field(fieldName: string): IField | null;
|
|
@@ -129,6 +167,7 @@ export declare class Group<T extends GenericFieldsInterface = GenericFieldsInter
|
|
|
129
167
|
|
|
130
168
|
export declare interface IField<T = any> {
|
|
131
169
|
value: T;
|
|
170
|
+
reactiveValue: ComputedRef<T>;
|
|
132
171
|
fullValue: T;
|
|
133
172
|
originalValue: T;
|
|
134
173
|
valid: boolean;
|
|
@@ -153,7 +192,6 @@ export declare class List<T extends GenericFieldsInterface = GenericFieldsInterf
|
|
|
153
192
|
private _itemTemplate?;
|
|
154
193
|
private _previousValue;
|
|
155
194
|
constructor(itemTemplate?: Group<T>, params?: Partial<IField>);
|
|
156
|
-
get reactive(): this;
|
|
157
195
|
private processSetValueItem;
|
|
158
196
|
private setValue;
|
|
159
197
|
get value(): Record<string, any>[] | null;
|
|
@@ -188,11 +226,20 @@ export declare type NullableGroup = Group | null;
|
|
|
188
226
|
|
|
189
227
|
export declare type NullableList = List | null;
|
|
190
228
|
|
|
191
|
-
declare class ValidationError {
|
|
229
|
+
export declare class ValidationError {
|
|
192
230
|
get componentName(): string;
|
|
193
231
|
get componentBindings(): {};
|
|
194
232
|
}
|
|
195
233
|
|
|
234
|
+
export declare class ValidationErrorText extends ValidationError {
|
|
235
|
+
text: string;
|
|
236
|
+
constructor(text: string);
|
|
237
|
+
get componentName(): string;
|
|
238
|
+
get componentBindings(): {
|
|
239
|
+
class: string;
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
196
243
|
export declare class ValidChangedAction extends FieldActionBase {
|
|
197
244
|
constructor(executorFn: (field: IField, supr: FieldActionExecute, newValue: boolean, oldValue: boolean) => Promise<void>);
|
|
198
245
|
get classIdentifier(): symbol;
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -39,10 +39,10 @@ import { Field, Group, ValueChangedAction } from '@dynamicforms/vue-forms';
|
|
|
39
39
|
|
|
40
40
|
// Create a form with fields
|
|
41
41
|
const personForm = new Group({
|
|
42
|
-
firstName:
|
|
43
|
-
lastName:
|
|
44
|
-
age:
|
|
45
|
-
active:
|
|
42
|
+
firstName: Field.create({ value: 'John' }),
|
|
43
|
+
lastName: Field.create({ value: 'Doe' }),
|
|
44
|
+
age: Field.create({ value: 30 }),
|
|
45
|
+
active: Field.create({ value: true })
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
// Access values
|
|
@@ -65,7 +65,7 @@ The library provides a powerful event system for field changes and other actions
|
|
|
65
65
|
```typescript
|
|
66
66
|
import { Field, Group, ValueChangedAction, ValidationErrorText } from '@dynamicforms/vue-forms';
|
|
67
67
|
|
|
68
|
-
const emailField =
|
|
68
|
+
const emailField = Field.create({ value: '' })
|
|
69
69
|
.registerAction(new ValueChangedAction(async (field, supr, newValue, oldValue) => {
|
|
70
70
|
// Custom validation on value change
|
|
71
71
|
if (!newValue.includes('@')) {
|
|
@@ -81,7 +81,7 @@ const emailField = new Field({ value: '' })
|
|
|
81
81
|
// Or register events on a form
|
|
82
82
|
const form = new Group({
|
|
83
83
|
email: emailField,
|
|
84
|
-
username:
|
|
84
|
+
username: Field.create()
|
|
85
85
|
}).registerAction(new ValueChangedAction(async (field, supr, newValue, oldValue) => {
|
|
86
86
|
console.log('Form data changed:', newValue);
|
|
87
87
|
return supr(field, newValue, oldValue);
|
|
@@ -107,11 +107,11 @@ interface UserFormData {
|
|
|
107
107
|
|
|
108
108
|
// Create the form with type checking
|
|
109
109
|
const userForm = new Group<UserFormData>({
|
|
110
|
-
username:
|
|
111
|
-
email:
|
|
110
|
+
username: Field.create({ value: '' }),
|
|
111
|
+
email: Field.create({ value: '' }),
|
|
112
112
|
preferences: new Group({
|
|
113
|
-
darkMode:
|
|
114
|
-
notifications:
|
|
113
|
+
darkMode: Field.create({ value: true }),
|
|
114
|
+
notifications: Field.create({ value: true })
|
|
115
115
|
})
|
|
116
116
|
});
|
|
117
117
|
|