@laser-ui/components 2.3.0 → 2.3.1
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/CHANGELOG.md +6 -0
- package/form/FormItem.js +1 -26
- package/form/hooks.d.ts +1 -1
- package/form/hooks.js +52 -62
- package/form/model/abstract-control.d.ts +3 -0
- package/form/model/abstract-control.js +47 -2
- package/form/model/form-control.js +6 -0
- package/form/model/form-group.d.ts +2 -0
- package/form/model/form-group.js +18 -0
- package/hooks/useControlled.js +2 -4
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [2.3.1](https://github.com/laser-ui/laser-ui/compare/v2.3.0...v2.3.1) (2026-02-27)
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
- **components:** form changes trigger rendering automatically ([f971bcd](https://github.com/laser-ui/laser-ui/commit/f971bcd4bd5c4dcc57cd704910767ba08e06abbf))
|
|
10
|
+
|
|
5
11
|
# [2.3.0](https://github.com/laser-ui/laser-ui/compare/v2.2.0...v2.3.0) (2025-08-07)
|
|
6
12
|
|
|
7
13
|
### Features
|
package/form/FormItem.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useForceUpdate } from '@laser-ui/hooks';
|
|
4
3
|
import CancelFilled from '@material-design-icons/svg/filled/cancel.svg?react';
|
|
5
4
|
import CheckCircleFilled from '@material-design-icons/svg/filled/check_circle.svg?react';
|
|
6
5
|
import ErrorFilled from '@material-design-icons/svg/filled/error.svg?react';
|
|
7
6
|
import HelpOutlineOutlined from '@material-design-icons/svg/outlined/help_outline.svg?react';
|
|
8
7
|
import { isBoolean, isFunction, isNull, isNumber, isString, isUndefined } from 'lodash';
|
|
9
|
-
import { use,
|
|
8
|
+
import { use, useId, useRef } from 'react';
|
|
10
9
|
import { FormError } from './internal/FormError';
|
|
11
10
|
import { Validators } from './model/validators';
|
|
12
11
|
import { CLASSES, FormContext, FormGroupContext } from './vars';
|
|
@@ -27,7 +26,6 @@ export function FormItem(props) {
|
|
|
27
26
|
const namespace = useNamespace();
|
|
28
27
|
const styled = useStyled(CLASSES, { form: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.form }, styleOverrides);
|
|
29
28
|
const { t } = useTranslation();
|
|
30
|
-
const forceUpdate = useForceUpdate();
|
|
31
29
|
const formContext = use(FormContext);
|
|
32
30
|
const formGroupContext = use(FormGroupContext);
|
|
33
31
|
const divRef = useRef(null);
|
|
@@ -42,11 +40,6 @@ export function FormItem(props) {
|
|
|
42
40
|
if (isNull(formControl)) {
|
|
43
41
|
throw new Error(`Cant find '${controlName}', please check if name exists!`);
|
|
44
42
|
}
|
|
45
|
-
formControl._emitChange = () => {
|
|
46
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
47
|
-
formControl._emitChange = () => { };
|
|
48
|
-
formControl._emitChanged = true;
|
|
49
|
-
};
|
|
50
43
|
obj[controlName] = {
|
|
51
44
|
control: formControl,
|
|
52
45
|
invalid: false,
|
|
@@ -57,24 +50,6 @@ export function FormItem(props) {
|
|
|
57
50
|
});
|
|
58
51
|
return obj;
|
|
59
52
|
})();
|
|
60
|
-
useEffect(() => {
|
|
61
|
-
const clear = [];
|
|
62
|
-
for (const { control } of Object.values(formControlProviders)) {
|
|
63
|
-
if (control._emitChanged === true) {
|
|
64
|
-
forceUpdate();
|
|
65
|
-
}
|
|
66
|
-
control._emitChange = forceUpdate;
|
|
67
|
-
clear.push(() => {
|
|
68
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
69
|
-
control._emitChange = () => { };
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
return () => {
|
|
73
|
-
for (const cb of clear) {
|
|
74
|
-
cb();
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
}, []);
|
|
78
53
|
const required = (() => {
|
|
79
54
|
if (isBoolean(requiredProp)) {
|
|
80
55
|
return requiredProp;
|
package/form/hooks.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ import type { AbstractControl } from './model/abstract-control';
|
|
|
2
2
|
import type { FormGroup } from './model/form-group';
|
|
3
3
|
export declare function useForm<T extends {
|
|
4
4
|
[K in keyof T]: AbstractControl;
|
|
5
|
-
} = any>(initForm: () => FormGroup<T
|
|
5
|
+
} = any>(initForm: () => FormGroup<T>): readonly [FormGroup<T>, (newForm?: FormGroup) => void];
|
package/form/hooks.js
CHANGED
|
@@ -1,73 +1,63 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
function createUltimateProxy(instance) {
|
|
3
|
+
return new Proxy(instance, {
|
|
4
|
+
get(target, prop, receiver) {
|
|
5
|
+
const value = Reflect.get(target, prop, receiver);
|
|
6
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
7
|
+
},
|
|
8
|
+
set(target, prop, value, receiver) {
|
|
9
|
+
return Reflect.set(target, prop, value, receiver);
|
|
10
|
+
},
|
|
11
|
+
has(target, prop) {
|
|
12
|
+
return Reflect.has(target, prop);
|
|
13
|
+
},
|
|
14
|
+
deleteProperty(target, prop) {
|
|
15
|
+
return Reflect.deleteProperty(target, prop);
|
|
16
|
+
},
|
|
17
|
+
ownKeys(target) {
|
|
18
|
+
return Reflect.ownKeys(target);
|
|
19
|
+
},
|
|
20
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
21
|
+
return Reflect.getOwnPropertyDescriptor(target, prop);
|
|
22
|
+
},
|
|
23
|
+
defineProperty(target, prop, descriptor) {
|
|
24
|
+
return Reflect.defineProperty(target, prop, descriptor);
|
|
25
|
+
},
|
|
26
|
+
getPrototypeOf(target) {
|
|
27
|
+
return Reflect.getPrototypeOf(target);
|
|
28
|
+
},
|
|
29
|
+
setPrototypeOf(target, proto) {
|
|
30
|
+
return Reflect.setPrototypeOf(target, proto);
|
|
31
|
+
},
|
|
32
|
+
isExtensible(target) {
|
|
33
|
+
return Reflect.isExtensible(target);
|
|
34
|
+
},
|
|
35
|
+
preventExtensions(target) {
|
|
36
|
+
return Reflect.preventExtensions(target);
|
|
37
|
+
},
|
|
39
38
|
});
|
|
39
|
+
}
|
|
40
|
+
export function useForm(initForm) {
|
|
41
|
+
const emitRender = useRef(() => { });
|
|
40
42
|
const [form, setForm] = useState(() => {
|
|
41
43
|
const form = initForm();
|
|
42
|
-
form.
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
44
|
-
form._emitChange = () => { };
|
|
45
|
-
form._emitChanged = true;
|
|
46
|
-
};
|
|
44
|
+
form.setEmitRender(emitRender);
|
|
47
45
|
return form;
|
|
48
46
|
});
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
const updateForm = useCallback((newForm) => {
|
|
48
|
+
if (newForm) {
|
|
49
|
+
newForm.setEmitRender(emitRender);
|
|
50
|
+
setForm(newForm);
|
|
53
51
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (form) {
|
|
57
|
-
form._emitChange = emitChange;
|
|
58
|
-
setForm(form);
|
|
52
|
+
else {
|
|
53
|
+
setForm(createUltimateProxy(form));
|
|
59
54
|
}
|
|
60
|
-
|
|
61
|
-
});
|
|
55
|
+
}, []);
|
|
62
56
|
useEffect(() => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
form._emitChange = emitChange;
|
|
67
|
-
return () => {
|
|
68
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
69
|
-
form._emitChange = () => { };
|
|
57
|
+
emitRender.current = () => {
|
|
58
|
+
updateForm();
|
|
59
|
+
emitRender.current = () => { };
|
|
70
60
|
};
|
|
71
|
-
}
|
|
61
|
+
});
|
|
72
62
|
return [form, updateForm];
|
|
73
63
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { FormGroup } from './form-group';
|
|
2
2
|
import type { AsyncValidatorFn, FormControlStatus, ValidationErrors, ValidatorFn } from './types';
|
|
3
|
+
import type { RefObject } from 'react';
|
|
3
4
|
export declare abstract class AbstractControl<V = any> {
|
|
5
|
+
protected _emitRender?: RefObject<() => void>;
|
|
4
6
|
private _parent;
|
|
5
7
|
private _pristine;
|
|
6
8
|
private _errors;
|
|
@@ -11,6 +13,7 @@ export declare abstract class AbstractControl<V = any> {
|
|
|
11
13
|
private _rawValidators;
|
|
12
14
|
private _rawAsyncValidators;
|
|
13
15
|
constructor(validators: ValidatorFn | ValidatorFn[] | null, asyncValidators: AsyncValidatorFn | AsyncValidatorFn[] | null);
|
|
16
|
+
setEmitRender(emitRender?: RefObject<() => void>): void;
|
|
14
17
|
get validator(): ValidatorFn | null;
|
|
15
18
|
set validator(validatorFn: ValidatorFn | null);
|
|
16
19
|
get asyncValidator(): AsyncValidatorFn | null;
|
|
@@ -56,6 +56,12 @@ function removeValidators(validators, currentValidators) {
|
|
|
56
56
|
}
|
|
57
57
|
export class AbstractControl {
|
|
58
58
|
constructor(validators, asyncValidators) {
|
|
59
|
+
Object.defineProperty(this, "_emitRender", {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
configurable: true,
|
|
62
|
+
writable: true,
|
|
63
|
+
value: void 0
|
|
64
|
+
});
|
|
59
65
|
Object.defineProperty(this, "_parent", {
|
|
60
66
|
enumerable: true,
|
|
61
67
|
configurable: true,
|
|
@@ -115,17 +121,24 @@ export class AbstractControl {
|
|
|
115
121
|
this._composedValidatorFn = coerceToValidator(this._rawValidators);
|
|
116
122
|
this._composedAsyncValidatorFn = coerceToAsyncValidator(this._rawAsyncValidators);
|
|
117
123
|
}
|
|
124
|
+
setEmitRender(emitRender) {
|
|
125
|
+
this._emitRender = emitRender;
|
|
126
|
+
}
|
|
118
127
|
get validator() {
|
|
119
128
|
return this._composedValidatorFn;
|
|
120
129
|
}
|
|
121
130
|
set validator(validatorFn) {
|
|
131
|
+
var _a;
|
|
122
132
|
this._rawValidators = this._composedValidatorFn = validatorFn;
|
|
133
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
123
134
|
}
|
|
124
135
|
get asyncValidator() {
|
|
125
136
|
return this._composedAsyncValidatorFn;
|
|
126
137
|
}
|
|
127
138
|
set asyncValidator(asyncValidatorFn) {
|
|
139
|
+
var _a;
|
|
128
140
|
this._rawAsyncValidators = this._composedAsyncValidatorFn = asyncValidatorFn;
|
|
141
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
129
142
|
}
|
|
130
143
|
get parent() {
|
|
131
144
|
return this._parent;
|
|
@@ -169,24 +182,36 @@ export class AbstractControl {
|
|
|
169
182
|
return !this._pristine;
|
|
170
183
|
}
|
|
171
184
|
setValidators(validators) {
|
|
185
|
+
var _a;
|
|
172
186
|
this._rawValidators = validators;
|
|
173
187
|
this._composedValidatorFn = coerceToValidator(validators);
|
|
188
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
174
189
|
}
|
|
175
190
|
setAsyncValidators(validators) {
|
|
191
|
+
var _a;
|
|
176
192
|
this._rawAsyncValidators = validators;
|
|
177
193
|
this._composedAsyncValidatorFn = coerceToAsyncValidator(validators);
|
|
194
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
178
195
|
}
|
|
179
196
|
addValidators(validators) {
|
|
197
|
+
var _a;
|
|
180
198
|
this.setValidators(addValidators(validators, this._rawValidators));
|
|
199
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
181
200
|
}
|
|
182
201
|
addAsyncValidators(validators) {
|
|
202
|
+
var _a;
|
|
183
203
|
this.setAsyncValidators(addValidators(validators, this._rawAsyncValidators));
|
|
204
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
184
205
|
}
|
|
185
206
|
removeValidators(validators) {
|
|
207
|
+
var _a;
|
|
186
208
|
this.setValidators(removeValidators(validators, this._rawValidators));
|
|
209
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
187
210
|
}
|
|
188
211
|
removeAsyncValidators(validators) {
|
|
212
|
+
var _a;
|
|
189
213
|
this.setAsyncValidators(removeValidators(validators, this._rawAsyncValidators));
|
|
214
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
190
215
|
}
|
|
191
216
|
hasValidator(validator) {
|
|
192
217
|
return hasValidator(this._rawValidators, validator);
|
|
@@ -195,18 +220,25 @@ export class AbstractControl {
|
|
|
195
220
|
return hasValidator(this._rawAsyncValidators, validator);
|
|
196
221
|
}
|
|
197
222
|
clearValidators() {
|
|
223
|
+
var _a;
|
|
198
224
|
this.validator = null;
|
|
225
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
199
226
|
}
|
|
200
227
|
clearAsyncValidators() {
|
|
228
|
+
var _a;
|
|
201
229
|
this.asyncValidator = null;
|
|
230
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
202
231
|
}
|
|
203
232
|
markAsDirty(onlySelf = false) {
|
|
233
|
+
var _a;
|
|
204
234
|
this._pristine = false;
|
|
205
235
|
if (this._parent && !onlySelf) {
|
|
206
236
|
this._parent.markAsDirty(onlySelf);
|
|
207
237
|
}
|
|
238
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
208
239
|
}
|
|
209
240
|
markAsPristine(onlySelf = false) {
|
|
241
|
+
var _a;
|
|
210
242
|
this._pristine = true;
|
|
211
243
|
this._forEachChild((control) => {
|
|
212
244
|
control.markAsPristine(true);
|
|
@@ -214,14 +246,18 @@ export class AbstractControl {
|
|
|
214
246
|
if (this._parent && !onlySelf) {
|
|
215
247
|
this._parent._updatePristine(onlySelf);
|
|
216
248
|
}
|
|
249
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
217
250
|
}
|
|
218
251
|
markAsPending(onlySelf = false) {
|
|
252
|
+
var _a;
|
|
219
253
|
this._status = PENDING;
|
|
220
254
|
if (this._parent && !onlySelf) {
|
|
221
255
|
this._parent.markAsPending(onlySelf);
|
|
222
256
|
}
|
|
257
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
223
258
|
}
|
|
224
259
|
disable(onlySelf = false) {
|
|
260
|
+
var _a;
|
|
225
261
|
// If parent has been marked artificially dirty we don't want to re-calculate the
|
|
226
262
|
// parent's dirtiness based on the children.
|
|
227
263
|
const skipPristineCheck = this._parentMarkedDirty(onlySelf);
|
|
@@ -231,8 +267,10 @@ export class AbstractControl {
|
|
|
231
267
|
control.disable(true);
|
|
232
268
|
});
|
|
233
269
|
this._updateAncestors(onlySelf, skipPristineCheck);
|
|
270
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
234
271
|
}
|
|
235
272
|
enable(onlySelf = false) {
|
|
273
|
+
var _a;
|
|
236
274
|
// If parent has been marked artificially dirty we don't want to re-calculate the
|
|
237
275
|
// parent's dirtiness based on the children.
|
|
238
276
|
const skipPristineCheck = this._parentMarkedDirty(onlySelf);
|
|
@@ -242,15 +280,21 @@ export class AbstractControl {
|
|
|
242
280
|
});
|
|
243
281
|
this.updateValueAndValidity(true);
|
|
244
282
|
this._updateAncestors(onlySelf, skipPristineCheck);
|
|
283
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
245
284
|
}
|
|
246
285
|
setParent(parent) {
|
|
286
|
+
var _a;
|
|
247
287
|
this._parent = parent;
|
|
288
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
248
289
|
}
|
|
249
290
|
setErrors(errors) {
|
|
291
|
+
var _a;
|
|
250
292
|
this._errors = errors;
|
|
251
293
|
this._updateControlsErrors();
|
|
294
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
252
295
|
}
|
|
253
296
|
updateValueAndValidity(onlySelf = false) {
|
|
297
|
+
var _a;
|
|
254
298
|
this._updateValue();
|
|
255
299
|
if (this.enabled) {
|
|
256
300
|
this._cancelExistingSubscription();
|
|
@@ -263,6 +307,7 @@ export class AbstractControl {
|
|
|
263
307
|
if (this._parent && !onlySelf) {
|
|
264
308
|
this._parent.updateValueAndValidity(onlySelf);
|
|
265
309
|
}
|
|
310
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
266
311
|
}
|
|
267
312
|
_anyControlsHaveStatus(status) {
|
|
268
313
|
return this._anyControls((control) => control.status === status);
|
|
@@ -322,14 +367,14 @@ export class AbstractControl {
|
|
|
322
367
|
abort = true;
|
|
323
368
|
};
|
|
324
369
|
this.asyncValidator(this).then((errors) => {
|
|
325
|
-
var _a
|
|
370
|
+
var _a;
|
|
326
371
|
if (!abort) {
|
|
327
372
|
this._hasOwnPendingAsyncValidator = false;
|
|
328
373
|
// This will trigger the recalculation of the validation status, which depends on
|
|
329
374
|
// the state of the asynchronous validation (whether it is in progress or not). So, it is
|
|
330
375
|
// necessary that we have updated the `_hasOwnPendingAsyncValidator` boolean flag first.
|
|
331
376
|
this.setErrors(errors);
|
|
332
|
-
(
|
|
377
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
333
378
|
}
|
|
334
379
|
});
|
|
335
380
|
}
|
|
@@ -32,16 +32,22 @@ export class FormControl extends AbstractControl {
|
|
|
32
32
|
return !!this.getError(errorCode);
|
|
33
33
|
}
|
|
34
34
|
setValue(value, onlySelf) {
|
|
35
|
+
var _a;
|
|
35
36
|
this._value = value;
|
|
36
37
|
this.updateValueAndValidity(onlySelf);
|
|
38
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
37
39
|
}
|
|
38
40
|
patchValue(value, onlySelf) {
|
|
41
|
+
var _a;
|
|
39
42
|
this.setValue(value, onlySelf);
|
|
43
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
40
44
|
}
|
|
41
45
|
reset(formState = this.defaultState, onlySelf) {
|
|
46
|
+
var _a;
|
|
42
47
|
this._applyFormState(formState);
|
|
43
48
|
this.markAsPristine(onlySelf);
|
|
44
49
|
this.setValue(this.value, onlySelf);
|
|
50
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
45
51
|
}
|
|
46
52
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
47
53
|
_updateValue() { }
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AsyncValidatorFn, FormControlStatus, ValidatorFn } from './types';
|
|
2
|
+
import type { RefObject } from 'react';
|
|
2
3
|
import { AbstractControl } from './abstract-control';
|
|
3
4
|
type Mutable<T> = {
|
|
4
5
|
-readonly [P in keyof T]: T[P];
|
|
@@ -22,6 +23,7 @@ export declare class FormGroup<T extends {
|
|
|
22
23
|
};
|
|
23
24
|
protected _status: FormControlStatus;
|
|
24
25
|
constructor(controls: T, validators?: ValidatorFn | ValidatorFn[] | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null);
|
|
26
|
+
setEmitRender(emitRender?: RefObject<() => void>): void;
|
|
25
27
|
get<S extends string>(path: S): AbstractControl<GetFormControlProperty<{
|
|
26
28
|
[K in keyof T]: T[K]['value'];
|
|
27
29
|
}, S>>;
|
package/form/model/form-group.js
CHANGED
|
@@ -45,6 +45,12 @@ export class FormGroup extends AbstractControl {
|
|
|
45
45
|
this._setUpControls();
|
|
46
46
|
this.updateValueAndValidity(true);
|
|
47
47
|
}
|
|
48
|
+
setEmitRender(emitRender) {
|
|
49
|
+
this._emitRender = emitRender;
|
|
50
|
+
this._forEachChild((control) => {
|
|
51
|
+
control.setEmitRender(emitRender);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
48
54
|
get(path) {
|
|
49
55
|
return find(this, path, '.');
|
|
50
56
|
}
|
|
@@ -56,46 +62,58 @@ export class FormGroup extends AbstractControl {
|
|
|
56
62
|
return !!this.getError(errorCode, path);
|
|
57
63
|
}
|
|
58
64
|
addControl(name, control) {
|
|
65
|
+
var _a;
|
|
59
66
|
if (!(name in this.controls)) {
|
|
60
67
|
this.controls[name] = control;
|
|
61
68
|
control.setParent(this);
|
|
62
69
|
}
|
|
63
70
|
this.updateValueAndValidity();
|
|
71
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
64
72
|
}
|
|
65
73
|
removeControl(name) {
|
|
74
|
+
var _a;
|
|
66
75
|
delete this.controls[name];
|
|
67
76
|
this.updateValueAndValidity();
|
|
77
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
68
78
|
}
|
|
69
79
|
setControl(name, control) {
|
|
80
|
+
var _a;
|
|
70
81
|
delete this.controls[name];
|
|
71
82
|
this.addControl(name, control);
|
|
72
83
|
this.updateValueAndValidity();
|
|
84
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
73
85
|
}
|
|
74
86
|
contains(controlName) {
|
|
75
87
|
return controlName in this.controls;
|
|
76
88
|
}
|
|
77
89
|
setValue(value, onlySelf) {
|
|
90
|
+
var _a;
|
|
78
91
|
this._checkAllValuesPresent(value);
|
|
79
92
|
Object.keys(value).forEach((name) => {
|
|
80
93
|
this._throwIfControlMissing(name);
|
|
81
94
|
this.controls[name].setValue(value[name], true);
|
|
82
95
|
});
|
|
83
96
|
this.updateValueAndValidity(onlySelf);
|
|
97
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
84
98
|
}
|
|
85
99
|
patchValue(value, onlySelf) {
|
|
100
|
+
var _a;
|
|
86
101
|
Object.keys(value).forEach((name) => {
|
|
87
102
|
if (this.controls[name]) {
|
|
88
103
|
this.controls[name].patchValue(value[name], true);
|
|
89
104
|
}
|
|
90
105
|
});
|
|
91
106
|
this.updateValueAndValidity(onlySelf);
|
|
107
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
92
108
|
}
|
|
93
109
|
reset(value = {}, onlySelf) {
|
|
110
|
+
var _a;
|
|
94
111
|
this._forEachChild((control, name) => {
|
|
95
112
|
control.reset(value[name], true);
|
|
96
113
|
});
|
|
97
114
|
this._updatePristine(onlySelf);
|
|
98
115
|
this.updateValueAndValidity(onlySelf);
|
|
116
|
+
(_a = this._emitRender) === null || _a === void 0 ? void 0 : _a.current();
|
|
99
117
|
}
|
|
100
118
|
_updateValue() {
|
|
101
119
|
this._value = this._reduceValue();
|
package/hooks/useControlled.js
CHANGED
|
@@ -8,16 +8,14 @@ export function useControlled(initialValue, value, onChange, deepCompare, formCo
|
|
|
8
8
|
return [
|
|
9
9
|
valueRef.current,
|
|
10
10
|
(value) => {
|
|
11
|
-
var _a, _b;
|
|
12
11
|
const newValue = isFunction(value) ? produce(valueRef.current, value) : freeze(value);
|
|
13
|
-
const
|
|
14
|
-
if (
|
|
12
|
+
const rerender = deepCompare ? !deepCompare(valueRef.current, newValue) : !Object.is(valueRef.current, newValue);
|
|
13
|
+
if (rerender) {
|
|
15
14
|
setValue(newValue);
|
|
16
15
|
onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
|
|
17
16
|
if (formControl) {
|
|
18
17
|
formControl.markAsDirty(true);
|
|
19
18
|
formControl.setValue(newValue);
|
|
20
|
-
(_b = (_a = formControl.root)._emitChange) === null || _b === void 0 ? void 0 : _b.call(_a, formControl);
|
|
21
19
|
}
|
|
22
20
|
}
|
|
23
21
|
return newValue;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@laser-ui/components",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"description": "React components.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ui",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"access": "public",
|
|
38
38
|
"directory": "../../dist/libs/components"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "47407fd068d48e0fc60793e5d74b010e955f09f9"
|
|
41
41
|
}
|