@laser-ui/components 1.5.0 → 1.5.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 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
+ ## [1.5.1](https://github.com/laser-ui/laser-ui/compare/v1.5.0...v1.5.1) (2024-11-01)
6
+
7
+ ### Bug Fixes
8
+
9
+ - **components:** fix form run async validator ([82010e8](https://github.com/laser-ui/laser-ui/commit/82010e83ad8c4de021a3bda9f1a552564ac06c54))
10
+
5
11
  # [1.5.0](https://github.com/laser-ui/laser-ui/compare/v1.4.0...v1.5.0) (2024-10-15)
6
12
 
7
13
  ### Features
package/form/FormItem.js CHANGED
@@ -6,7 +6,7 @@ import CheckCircleFilled from '@material-design-icons/svg/filled/check_circle.sv
6
6
  import ErrorFilled from '@material-design-icons/svg/filled/error.svg?react';
7
7
  import HelpOutlineOutlined from '@material-design-icons/svg/outlined/help_outline.svg?react';
8
8
  import { isBoolean, isFunction, isNull, isNumber, isString, isUndefined } from 'lodash';
9
- import { useContext, useId, useRef } from 'react';
9
+ import { useContext, useEffect, useId, useRef } from 'react';
10
10
  import { FormError } from './internal/FormError';
11
11
  import { Validators } from './model/validators';
12
12
  import { CLASSES, FormContext, FormGroupContext } from './vars';
@@ -41,7 +41,9 @@ export function FormItem(props) {
41
41
  if (isNull(formControl)) {
42
42
  throw new Error(`Cant find '${controlName}', please check if name exists!`);
43
43
  }
44
- formControl._emitChange = forceUpdate;
44
+ formControl._emitChange = () => {
45
+ formControl._emitChange = true;
46
+ };
45
47
  obj[controlName] = {
46
48
  control: formControl,
47
49
  invalid: false,
@@ -52,6 +54,24 @@ export function FormItem(props) {
52
54
  });
53
55
  return obj;
54
56
  })();
57
+ useEffect(() => {
58
+ const clear = [];
59
+ for (const { control } of Object.values(formControlProviders)) {
60
+ if (control._emitChange === true) {
61
+ forceUpdate();
62
+ }
63
+ control._emitChange = forceUpdate;
64
+ clear.push(() => {
65
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
66
+ control._emitChange = () => { };
67
+ });
68
+ }
69
+ return () => {
70
+ for (const cb of clear) {
71
+ cb();
72
+ }
73
+ };
74
+ }, []);
55
75
  const required = (() => {
56
76
  if (isBoolean(requiredProp)) {
57
77
  return requiredProp;
package/form/hooks.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { useEventCallback, useForceUpdate, useIsomorphicLayoutEffect } from '@laser-ui/hooks';
2
2
  import { isString } from 'lodash';
3
- import { useRef, useState } from 'react';
3
+ import { useEffect, useRef, useState } from 'react';
4
4
  export function useForm(initForm, deps) {
5
5
  const forceUpdate = useForceUpdate();
6
6
  const emitChange = useEventCallback((control) => {
@@ -39,7 +39,9 @@ export function useForm(initForm, deps) {
39
39
  });
40
40
  const [form, setForm] = useState(() => {
41
41
  const form = initForm();
42
- form._emitChange = emitChange;
42
+ form._emitChange = () => {
43
+ form._emitChange = true;
44
+ };
43
45
  return form;
44
46
  });
45
47
  const previousDeps = useRef([]);
@@ -55,5 +57,15 @@ export function useForm(initForm, deps) {
55
57
  }
56
58
  forceUpdate();
57
59
  });
60
+ useEffect(() => {
61
+ if (form._emitChange === true) {
62
+ forceUpdate();
63
+ }
64
+ form._emitChange = emitChange;
65
+ return () => {
66
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
67
+ form._emitChange = () => { };
68
+ };
69
+ }, []);
58
70
  return [form, updateForm];
59
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@laser-ui/components",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "React components.",
5
5
  "keywords": [
6
6
  "ui",
@@ -40,5 +40,5 @@
40
40
  "access": "public",
41
41
  "directory": "../../dist/libs/components"
42
42
  },
43
- "gitHead": "316da1ed34c626ca27819993998c0a745455d0b4"
43
+ "gitHead": "4867e61f312f16adc087c0a4ed0c3b9bdbf83afe"
44
44
  }