@dartech/arsenal-ui 1.4.4 → 1.4.6

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/index.js CHANGED
@@ -1054,8 +1054,7 @@ const ControlAceEditor = /*#__PURE__*/forwardRef((_a, ref) => {
1054
1054
  rules: {
1055
1055
  required: required && 'Please, fill this field',
1056
1056
  validate: val => {
1057
- console.log('_____', val);
1058
- if (val && validateJson) {
1057
+ if (val && validateJson && typeof val === 'string') {
1059
1058
  try {
1060
1059
  JSON.parse(val);
1061
1060
  return true;
@@ -1112,7 +1111,7 @@ const ControlAceEditor = /*#__PURE__*/forwardRef((_a, ref) => {
1112
1111
  }
1113
1112
  }, {
1114
1113
  children: required ? jsxs(Fragment, {
1115
- children: [label, " ", jsx(Box, Object.assign({
1114
+ children: [label, ' ', jsx(Box, Object.assign({
1116
1115
  component: "span",
1117
1116
  color: "#D6331F"
1118
1117
  }, {
@@ -2548,33 +2547,23 @@ var img$2 = "data:image/svg+xml,%3csvg width='32' height='24' viewBox='0 0 32 24
2548
2547
 
2549
2548
  const ControlPhoneInput = _a => {
2550
2549
  var {
2550
+ control,
2551
2551
  name,
2552
2552
  label,
2553
2553
  required,
2554
2554
  mask = '+7 (799) 999 99 99'
2555
2555
  } = _a,
2556
- textFieldProps = __rest(_a, ["name", "label", "required", "mask"]);
2557
- const {
2558
- control,
2559
- watch,
2560
- trigger
2561
- } = useFormContext();
2562
- const phoneNumber = watch(name);
2563
- useEffect(() => {
2564
- if (/(\+7\s\(\d{3}\)\s)(\d{3}\s\d{2})(\s\d{2})/.test(phoneNumber)) {
2565
- trigger(name);
2566
- }
2567
- }, [phoneNumber, trigger, name]);
2556
+ textFieldProps = __rest(_a, ["control", "name", "label", "required", "mask"]);
2568
2557
  return jsx(Controller, {
2569
2558
  control: control,
2570
2559
  name: name,
2571
2560
  rules: {
2572
2561
  required: required && 'Please, fill this field',
2573
2562
  validate: val => {
2574
- if (/(\+7\s\(\d{3}\)\s)(\d{3}\s\d{2})(\s\d{2})/.test(val)) {
2575
- return true;
2563
+ if (!/(\+7\s\(\d{3}\)\s)(\d{3}\s\d{2})(\s\d{2})/.test(val)) {
2564
+ return 'Incorrect phone number format';
2576
2565
  }
2577
- return 'Incorrect phone number format';
2566
+ return true;
2578
2567
  }
2579
2568
  },
2580
2569
  render: ({
@@ -2585,7 +2574,7 @@ const ControlPhoneInput = _a => {
2585
2574
  }) => jsx(InputMask, Object.assign({
2586
2575
  mask: mask
2587
2576
  }, field, {
2588
- children: () => jsx(TextField, Object.assign({
2577
+ children: jsx(TextField, Object.assign({
2589
2578
  fullWidth: true,
2590
2579
  size: "small",
2591
2580
  label: required && label ? jsxs(Fragment, {
@@ -5826,11 +5815,12 @@ const PropertyFiller = ({
5826
5815
  const {
5827
5816
  control,
5828
5817
  clearErrors,
5829
- setValue,
5830
- watch
5818
+ setValue
5831
5819
  } = useFormContext();
5832
5820
  const {
5833
- // field: { value },
5821
+ field: {
5822
+ value
5823
+ },
5834
5824
  fieldState: {
5835
5825
  error,
5836
5826
  isDirty
@@ -5845,11 +5835,6 @@ const PropertyFiller = ({
5845
5835
  }
5846
5836
  }
5847
5837
  });
5848
- // const value = watch(name);
5849
- const value = useWatch({
5850
- control,
5851
- name
5852
- });
5853
5838
  const prevValueRef = useRef({});
5854
5839
  const {
5855
5840
  propertyType,
@@ -5923,26 +5908,22 @@ const PropertyFiller = ({
5923
5908
  clearErrors();
5924
5909
  }, [name, defaultProperyValue, clearErrors, value, setFillOption, fillOption, propertyType, setValue, property]);
5925
5910
  useEffect(() => {
5926
- if (!isDirty && (property.defaultValue || property.value) && isPropertyValueEmpty(value)) {
5927
- setValue(name, property.defaultValue || property.value, {
5928
- shouldDirty: true
5929
- });
5911
+ var _a;
5912
+ if (!isDirty && isPropertyValueEmpty(value)) {
5913
+ if (property.isRequired && (property.defaultValue === null || property.value === null)) {
5914
+ setValue(name, (_a = prevValueRef.current[fillOption]) !== null && _a !== void 0 ? _a : defaultProperyValue);
5915
+ } else if (!property.isRequired && (property.defaultValue === null || property.value === null)) {
5916
+ setValue(name, null);
5917
+ } else if (!(isPropertyValueEmpty(property.defaultValue) || isPropertyValueEmpty(property.value))) {
5918
+ setValue(name, property.defaultValue || property.value);
5919
+ }
5930
5920
  }
5931
- }, [isDirty, property, name, setValue, value, required]);
5921
+ }, [value, setValue, defaultProperyValue, property, name, fillOption, isDirty]);
5932
5922
  useEffect(() => {
5933
- var _a;
5934
- if (
5935
- // value === undefined ||
5936
- property.isRequired && isPropertyValueEmpty(value) && (property.defaultValue === null || property.value === null)) {
5937
- setValue(name, (_a = prevValueRef.current[fillOption]) !== null && _a !== void 0 ? _a : defaultProperyValue, {
5938
- shouldDirty: true
5939
- });
5940
- } else if ((value === undefined || value === null) && !property.isRequired && (property.defaultValue === null || property.value === null)) {
5941
- setValue(name, null, {
5942
- shouldDirty: true
5943
- });
5923
+ if (!isPropertyValueEmpty(value) && property.propertyType !== PropertyType.JSON) {
5924
+ setValue(name, value);
5944
5925
  }
5945
- }, [value, setValue, defaultProperyValue, property, name, fillOption]);
5926
+ }, [name, setValue, value, property]);
5946
5927
  return jsxs(Grid, Object.assign({
5947
5928
  xs: 12
5948
5929
  }, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dartech/arsenal-ui",
3
- "version": "1.4.4",
3
+ "version": "1.4.6",
4
4
  "author": "DAR",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -29,7 +29,7 @@
29
29
  "@rollup/plugin-node-resolve": "13.3.0",
30
30
  "lodash": "4.17.21",
31
31
  "qs": "6.11.0",
32
- "react-input-mask": "2.0.4"
32
+ "react-input-mask": "3.0.0-alpha.2"
33
33
  },
34
34
  "module": "./index.js",
35
35
  "main": "./index.js",
@@ -1,10 +1,12 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { TextFieldProps } from '@mui/material/TextField';
3
+ import { Control } from 'react-hook-form';
3
4
  type Props = TextFieldProps & {
5
+ control: Control<any>;
4
6
  name: string;
5
7
  required?: boolean;
6
8
  mask?: string;
7
9
  label?: ReactNode;
8
10
  };
9
- export declare const ControlPhoneInput: ({ name, label, required, mask, ...textFieldProps }: Props) => JSX.Element;
11
+ export declare const ControlPhoneInput: ({ control, name, label, required, mask, ...textFieldProps }: Props) => JSX.Element;
10
12
  export default ControlPhoneInput;