@dartech/arsenal-ui 1.3.60 → 1.3.62

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
@@ -241,18 +241,15 @@ const ControlInput = _a => {
241
241
  _d = _c.field,
242
242
  {
243
243
  ref,
244
- onChange
244
+ onChange,
245
+ value
245
246
  } = _d,
246
- fieldProps = __rest(_d, ["ref", "onChange"]),
247
+ fieldProps = __rest(_d, ["ref", "onChange", "value"]),
247
248
  {
248
249
  fieldState: {
249
250
  error
250
251
  }
251
252
  } = _c;
252
- const value = useWatch({
253
- control,
254
- name
255
- });
256
253
  return jsx(TextField, Object.assign({}, fieldProps, {
257
254
  fullWidth: true,
258
255
  size: "small",
@@ -431,18 +428,15 @@ const ControlSelect = _a => {
431
428
  _d = _c.field,
432
429
  {
433
430
  ref,
434
- onChange
431
+ onChange,
432
+ value
435
433
  } = _d,
436
- fieldProps = __rest(_d, ["ref", "onChange"]),
434
+ fieldProps = __rest(_d, ["ref", "onChange", "value"]),
437
435
  {
438
436
  fieldState: {
439
437
  error
440
438
  }
441
439
  } = _c;
442
- const value = useWatch({
443
- control,
444
- name
445
- });
446
440
  const getValue = useCallback(option => {
447
441
  if (typeof option === 'string') return option;
448
442
  return valueKey ? option[valueKey] : option.value;
@@ -538,18 +532,15 @@ const ControlCheckbox = _a => {
538
532
  _c = _b.field,
539
533
  {
540
534
  ref,
541
- onChange
535
+ onChange,
536
+ value
542
537
  } = _c,
543
- fieldProps = __rest(_c, ["ref", "onChange"]),
538
+ fieldProps = __rest(_c, ["ref", "onChange", "value"]),
544
539
  {
545
540
  fieldState: {
546
541
  error
547
542
  }
548
543
  } = _b;
549
- const value = useWatch({
550
- control,
551
- name
552
- });
553
544
  const checked = useMemo(() => {
554
545
  if (typeof value === 'boolean') {
555
546
  return value;
@@ -617,19 +608,15 @@ const ControlRadio = ({
617
608
  }),
618
609
  _b = _a.field,
619
610
  {
620
- ref,
621
611
  onChange
622
612
  } = _b,
623
- fieldProps = __rest(_b, ["ref", "onChange"]),
613
+ fieldProps = __rest(_b, ["onChange"]),
624
614
  {
625
615
  fieldState: {
626
616
  error
627
617
  }
628
618
  } = _a;
629
- const value = useWatch({
630
- control,
631
- name
632
- });
619
+ // const value = useWatch({ control, name });
633
620
  const getValue = useCallback(option => {
634
621
  if (typeof option === 'string') return option;
635
622
  return valueKey ? option[valueKey] : option.value;
@@ -649,9 +636,6 @@ const ControlRadio = ({
649
636
  })), jsx(RadioGroup, Object.assign({}, fieldProps, {
650
637
  row: row,
651
638
  "aria-labelledby": "radio-buttons-group",
652
- ref: ref,
653
- name: name,
654
- value: value,
655
639
  onChange: customOnChange ? customOnChange : onChange
656
640
  }, {
657
641
  children: _values.map((item, i) => jsx(FormControlLabel, {
@@ -726,28 +710,26 @@ const ControlAutocomplete = _a => {
726
710
  disableCloseOnSelect
727
711
  } = _a,
728
712
  autocompleteProps = __rest(_a, ["control", "validate", "name", "label", "required", "defaultValue", "disabled", "hideErrorMessage", "onChange", "labelKey", "valueKey", "options", "multiple", "textFieldProps", "disableCloseOnSelect"]);
729
- const {
730
- field: {
713
+ const _b = useController({
714
+ name,
715
+ control,
716
+ defaultValue: defaultValue || (multiple ? [] : null),
717
+ rules: {
718
+ required: required && 'Please, fill this field',
719
+ validate
720
+ }
721
+ }),
722
+ _c = _b.field,
723
+ {
731
724
  ref,
732
725
  onChange
733
- },
734
- fieldState: {
735
- error
736
- }
737
- } = useController({
738
- name,
739
- control,
740
- defaultValue,
741
- rules: {
742
- required: required && 'Please, fill this field',
743
- validate
744
- }
745
- });
746
- const formValue = useWatch({
747
- control,
748
- name,
749
- defaultValue: multiple ? [] : null
750
- });
726
+ } = _c,
727
+ fieldProps = __rest(_c, ["ref", "onChange"]),
728
+ {
729
+ fieldState: {
730
+ error
731
+ }
732
+ } = _b;
751
733
  const {
752
734
  getOptionLabel,
753
735
  isOptionEqualToValue,
@@ -759,7 +741,7 @@ const ControlAutocomplete = _a => {
759
741
  const handleChange = (_, value) => {
760
742
  onChange(value);
761
743
  };
762
- return jsx(Autocomplete, Object.assign({
744
+ return jsx(Autocomplete, Object.assign({}, fieldProps, {
763
745
  fullWidth: true,
764
746
  disablePortal: true,
765
747
  size: "small",
@@ -770,7 +752,6 @@ const ControlAutocomplete = _a => {
770
752
  isOptionEqualToValue: isOptionEqualToValue,
771
753
  disableCloseOnSelect: disableCloseOnSelect || multiple,
772
754
  filterSelectedOptions: multiple,
773
- value: formValue,
774
755
  onChange: customOnChange ? customOnChange : handleChange,
775
756
  renderOption: renderOption,
776
757
  renderInput: params => {
@@ -816,28 +797,29 @@ function ControlQueryAutocomplete(_a) {
816
797
  itemQueryFunction
817
798
  } = _a,
818
799
  autocompleteProps = __rest(_a, ["name", "label", "control", "required", "searchBy", "labelKey", "multiple", "disabled", "valueKey", "sortBy", "hideErrorMessage", "disableCloseOnSelect", "textFieldProps", "onChange", "queryFunction", "validate", "itemQueryFunction"]);
819
- const {
820
- field: {
800
+ const _b = useController({
801
+ control,
802
+ name,
803
+ defaultValue: multiple ? [] : null,
804
+ rules: {
805
+ required: required && 'Please, fill this field',
806
+ validate
807
+ }
808
+ }),
809
+ _c = _b.field,
810
+ {
821
811
  ref,
822
- onChange: setFieldValue
823
- },
824
- fieldState: {
825
- error,
826
- isDirty
827
- }
828
- } = useController({
829
- control,
830
- name,
831
- rules: {
832
- required: required && 'Please, fill this field',
833
- validate
834
- }
835
- });
836
- const formValue = useWatch({
837
- control,
838
- name,
839
- defaultValue: multiple ? [] : null
840
- });
812
+ onChange: setFieldValue,
813
+ value: formValue
814
+ } = _c,
815
+ fieldProps = __rest(_c, ["ref", "onChange", "value"]),
816
+ {
817
+ fieldState: {
818
+ error,
819
+ isDirty
820
+ }
821
+ } = _b;
822
+ // const formValue = useWatch({ control, name, defaultValue: });
841
823
  const {
842
824
  getOptionLabel,
843
825
  isOptionEqualToValue,
@@ -913,7 +895,7 @@ function ControlQueryAutocomplete(_a) {
913
895
  setTotalItems(data.totalItems);
914
896
  }
915
897
  }, [data]);
916
- return jsx(Autocomplete, Object.assign({
898
+ return jsx(Autocomplete, Object.assign({}, fieldProps, {
917
899
  fullWidth: true,
918
900
  disablePortal: true,
919
901
  size: "small",
@@ -1056,25 +1038,25 @@ const ControlAceEditor = /*#__PURE__*/forwardRef((_a, ref) => {
1056
1038
  setError,
1057
1039
  clearErrors
1058
1040
  } = useFormContext();
1059
- const {
1060
- field: {
1041
+ const _b = useController({
1042
+ control,
1043
+ name,
1044
+ rules: {
1045
+ required: required && 'Please, fill this field'
1046
+ }
1047
+ }),
1048
+ _c = _b.field,
1049
+ {
1061
1050
  onChange,
1051
+ value,
1062
1052
  ref: formRef
1063
- },
1064
- fieldState: {
1065
- error
1066
- }
1067
- } = useController({
1068
- control,
1069
- name,
1070
- rules: {
1071
- required: required && 'Please, fill this field'
1072
- }
1073
- });
1074
- const value = useWatch({
1075
- control,
1076
- name
1077
- });
1053
+ } = _c,
1054
+ fieldProps = __rest(_c, ["onChange", "value", "ref"]),
1055
+ {
1056
+ fieldState: {
1057
+ error
1058
+ }
1059
+ } = _b;
1078
1060
  const extensions = useMemo(() => ({
1079
1061
  json: [langs.json()],
1080
1062
  javascript: [langs.javascript()],
@@ -1093,6 +1075,7 @@ const ControlAceEditor = /*#__PURE__*/forwardRef((_a, ref) => {
1093
1075
  JSON.parse(value);
1094
1076
  clearErrors(name);
1095
1077
  } catch (error) {
1078
+ console.error(error);
1096
1079
  setError(name, {
1097
1080
  message: 'Invalid JSON'
1098
1081
  });
@@ -1108,7 +1091,7 @@ const ControlAceEditor = /*#__PURE__*/forwardRef((_a, ref) => {
1108
1091
  } else {
1109
1092
  onChange(value);
1110
1093
  }
1111
- }, [setError, clearErrors, onChange, required, name, parseValue, validateJson]);
1094
+ }, [setError, clearErrors, onChange, name, parseValue, validateJson, required]);
1112
1095
  return jsxs(Box, Object.assign({
1113
1096
  display: "flex",
1114
1097
  flexDirection: "column",
@@ -1132,7 +1115,7 @@ const ControlAceEditor = /*#__PURE__*/forwardRef((_a, ref) => {
1132
1115
  }) : label
1133
1116
  }))
1134
1117
  }), jsxs(Fragment, {
1135
- children: [jsx(CodeMirror, Object.assign({
1118
+ children: [jsx(CodeMirror, Object.assign({}, fieldProps, {
1136
1119
  ref: ref || formRef,
1137
1120
  basicSetup: {
1138
1121
  autocompletion: true,
@@ -1958,13 +1941,10 @@ const ControlSwitch = _a => {
1958
1941
  }).field,
1959
1942
  {
1960
1943
  ref,
1961
- onChange
1944
+ onChange,
1945
+ value
1962
1946
  } = _b,
1963
- fieldProps = __rest(_b, ["ref", "onChange"]);
1964
- const value = useWatch({
1965
- control,
1966
- name
1967
- });
1947
+ fieldProps = __rest(_b, ["ref", "onChange", "value"]);
1968
1948
  const checked = useMemo(() => {
1969
1949
  if (typeof value === 'boolean') {
1970
1950
  return value;
@@ -2156,18 +2136,15 @@ const ControlTime = ({
2156
2136
  _b = _a.field,
2157
2137
  {
2158
2138
  onChange,
2159
- ref
2139
+ ref,
2140
+ value
2160
2141
  } = _b,
2161
- fieldProps = __rest(_b, ["onChange", "ref"]),
2142
+ fieldProps = __rest(_b, ["onChange", "ref", "value"]),
2162
2143
  {
2163
2144
  fieldState: {
2164
2145
  error
2165
2146
  }
2166
2147
  } = _a;
2167
- const value = useWatch({
2168
- control,
2169
- name
2170
- });
2171
2148
  const [fieldValue, setFieldValue] = useState(null);
2172
2149
  const handleChange = date => {
2173
2150
  setFieldValue(date);
@@ -3596,53 +3573,6 @@ const PropertyAdditionalFields = ({
3596
3573
  }
3597
3574
  };
3598
3575
 
3599
- const JsonEditor = /*#__PURE__*/forwardRef(({
3600
- validate: _validate = false,
3601
- name,
3602
- useParsedValue
3603
- }, ref) => {
3604
- const {
3605
- control,
3606
- setValue,
3607
- setError,
3608
- clearErrors
3609
- } = useFormContext();
3610
- const value = useWatch({
3611
- control,
3612
- name
3613
- });
3614
- const handleChange = value => {
3615
- try {
3616
- if (value) setValue(name, useParsedValue ? JSON.parse(value) : value);
3617
- clearErrors(name);
3618
- } catch (e) {
3619
- if (_validate) setError(name, {
3620
- message: 'Invalid JSON'
3621
- });
3622
- }
3623
- };
3624
- return jsx(CodeMirror, {
3625
- ref: ref,
3626
- basicSetup: {
3627
- autocompletion: true,
3628
- history: true
3629
- },
3630
- theme: abcdef,
3631
- width: "100%",
3632
- height: "200px",
3633
- style: {
3634
- fontSize: 14,
3635
- lineHeight: 1.4,
3636
- zIndex: 0,
3637
- isolation: 'isolate'
3638
- },
3639
- value: typeof value !== 'string' ? value === null ? '' : JSON.stringify(value) : value,
3640
- onChange: handleChange,
3641
- extensions: [langs.json()]
3642
- });
3643
- });
3644
- var JsonEditor$1 = JsonEditor;
3645
-
3646
3576
  const StringValueField = ({
3647
3577
  name,
3648
3578
  label,
@@ -3704,21 +3634,20 @@ const StringValueField = ({
3704
3634
  };
3705
3635
  var StringValueField$1 = StringValueField;
3706
3636
 
3707
- const PropertyWidget = /*#__PURE__*/forwardRef(({
3637
+ const PropertyWidget = ({
3708
3638
  property,
3709
3639
  name,
3710
3640
  label,
3711
- useExpression
3712
- }, ref) => {
3713
- const {
3714
- control
3715
- } = useFormContext();
3641
+ useExpression,
3642
+ control
3643
+ }) => {
3716
3644
  const propertyType = useMemo(() => typeof property.propertyType === 'string' ? property.propertyType : property['propertyType']['value'], [property]);
3717
3645
  switch (propertyType) {
3718
3646
  case PropertyType.BIG_DECIMAL:
3719
3647
  case PropertyType.FLOAT:
3720
3648
  case PropertyType.DOUBLE:
3721
3649
  return jsx(ControlNumberInput, {
3650
+ required: true,
3722
3651
  decimal: true,
3723
3652
  hideErrorMessage: true,
3724
3653
  control: control,
@@ -3729,10 +3658,8 @@ const PropertyWidget = /*#__PURE__*/forwardRef(({
3729
3658
  case PropertyType.INTEGER:
3730
3659
  case PropertyType.BIG_INTEGER:
3731
3660
  case PropertyType.LONG:
3732
- return jsx(ControlNumberInput
3733
- // required
3734
- , {
3735
- // required
3661
+ return jsx(ControlNumberInput, {
3662
+ required: true,
3736
3663
  hideErrorMessage: true,
3737
3664
  control: control,
3738
3665
  name: name,
@@ -3778,12 +3705,15 @@ const PropertyWidget = /*#__PURE__*/forwardRef(({
3778
3705
  format: property.format
3779
3706
  });
3780
3707
  case PropertyType.JSON:
3781
- return jsx(JsonEditor$1, {
3782
- validate: true,
3708
+ return jsx(ControlAceEditor, {
3709
+ control: control,
3783
3710
  name: name,
3784
- ref: ref,
3785
- useParsedValue: true
3711
+ label: label,
3712
+ parseValue: true,
3713
+ hideErrorMessage: true,
3714
+ validateJson: true
3786
3715
  });
3716
+ // return <JsonEditor validate name={name} ref={ref} useParsedValue />;
3787
3717
  case PropertyType.STRING:
3788
3718
  return jsx(StringValueField$1
3789
3719
  // required={!property.isRequired}
@@ -3802,9 +3732,11 @@ const PropertyWidget = /*#__PURE__*/forwardRef(({
3802
3732
  control: control
3803
3733
  });
3804
3734
  case PropertyType.ANY:
3805
- return jsx(JsonEditor$1, {
3735
+ return jsx(ControlAceEditor, {
3736
+ control: control,
3806
3737
  name: name,
3807
- ref: ref
3738
+ hideErrorMessage: true,
3739
+ label: label
3808
3740
  });
3809
3741
  case PropertyType.ENTITY:
3810
3742
  return jsx(DefinitionFiller, {
@@ -3817,7 +3749,7 @@ const PropertyWidget = /*#__PURE__*/forwardRef(({
3817
3749
  children: "No widget"
3818
3750
  });
3819
3751
  }
3820
- });
3752
+ };
3821
3753
 
3822
3754
  const usePropertyFiller = ({
3823
3755
  value,
@@ -3845,31 +3777,36 @@ const usePropertyFiller = ({
3845
3777
  useExpression: _useExpression
3846
3778
  }), [_useExpression, _required, propertyType, _multipleOptions]);
3847
3779
  const defaultProperyValue = useMemo(() => {
3848
- if (property.isRequired || property.isMultiple) {
3849
- switch (propertyType) {
3850
- case PropertyType.STRING:
3851
- case PropertyType.DATE:
3852
- case PropertyType.TIME:
3853
- case PropertyType.DATE_TIME:
3854
- case PropertyType.ENTITY_REFERENCE:
3855
- case PropertyType.ANY:
3856
- return '';
3857
- case PropertyType.JSON:
3858
- return {};
3859
- case PropertyType.BOOLEAN:
3860
- return true;
3861
- case PropertyType.INTEGER:
3862
- case PropertyType.BIG_DECIMAL:
3863
- case PropertyType.BIG_INTEGER:
3864
- case PropertyType.DOUBLE:
3865
- case PropertyType.LONG:
3866
- case PropertyType.FLOAT:
3867
- return 0;
3868
- default:
3869
- return {};
3870
- }
3871
- } else return null;
3872
- }, [propertyType, property]);
3780
+ switch (propertyType) {
3781
+ case PropertyType.STRING:
3782
+ case PropertyType.DATE:
3783
+ case PropertyType.TIME:
3784
+ case PropertyType.DATE_TIME:
3785
+ case PropertyType.ENTITY_REFERENCE:
3786
+ case PropertyType.ANY:
3787
+ return '';
3788
+ case PropertyType.JSON:
3789
+ return {};
3790
+ case PropertyType.BOOLEAN:
3791
+ return true;
3792
+ case PropertyType.INTEGER:
3793
+ case PropertyType.BIG_DECIMAL:
3794
+ case PropertyType.BIG_INTEGER:
3795
+ case PropertyType.DOUBLE:
3796
+ case PropertyType.LONG:
3797
+ case PropertyType.FLOAT:
3798
+ return 0;
3799
+ default:
3800
+ return {};
3801
+ }
3802
+ }, [propertyType]);
3803
+ const checkFillOption = useCallback(() => {
3804
+ if (isExpression(value) && fillOption !== 'expression') {
3805
+ setFillOption('expression');
3806
+ } else if (value !== null && value !== undefined && !isExpression(value) && fillOption !== 'widget') {
3807
+ setFillOption('widget');
3808
+ }
3809
+ }, [value, fillOption]);
3873
3810
  useEffect(() => {
3874
3811
  if (!fillOption) {
3875
3812
  if (isPropertyValueEmpty(value) && (fillOptions === null || fillOptions === void 0 ? void 0 : fillOptions.length)) {
@@ -3880,13 +3817,9 @@ const usePropertyFiller = ({
3880
3817
  setFillOption('widget');
3881
3818
  }
3882
3819
  } else if (!isDirty) {
3883
- if (isExpression(value) && fillOption !== 'expression') {
3884
- setFillOption('expression');
3885
- } else if (value !== null && value !== undefined && !isExpression(value) && fillOption !== 'widget') {
3886
- setFillOption('widget');
3887
- }
3820
+ checkFillOption();
3888
3821
  }
3889
- }, [value, fillOption, fillOptions, _useExpression, isDirty]);
3822
+ }, [value, fillOption, fillOptions, _useExpression, isDirty, checkFillOption]);
3890
3823
  return {
3891
3824
  propertyType,
3892
3825
  valueLabel,
@@ -3894,7 +3827,8 @@ const usePropertyFiller = ({
3894
3827
  fillOption,
3895
3828
  fillOptions,
3896
3829
  setFillOption,
3897
- defaultProperyValue
3830
+ defaultProperyValue,
3831
+ checkFillOption
3898
3832
  };
3899
3833
  };
3900
3834
  var usePropertyFiller$1 = usePropertyFiller;
@@ -3923,8 +3857,6 @@ const PropertyFiller = ({
3923
3857
  } = useFormContext();
3924
3858
  const {
3925
3859
  field: {
3926
- ref,
3927
- onChange,
3928
3860
  value
3929
3861
  },
3930
3862
  fieldState: {
@@ -3966,7 +3898,7 @@ const PropertyFiller = ({
3966
3898
  properties: propertiesArrayToObject(value.property || [])
3967
3899
  });
3968
3900
  try {
3969
- onChange(JSON.stringify(definitionValue, null, '\t'));
3901
+ setValue(name, JSON.stringify(definitionValue, null, '\t'));
3970
3902
  } catch (error) {
3971
3903
  console.log('Stringify failed', error);
3972
3904
  }
@@ -3974,7 +3906,7 @@ const PropertyFiller = ({
3974
3906
  setValue(name, property.defaultValue || defaultProperyValue);
3975
3907
  }
3976
3908
  } else if (selectedType === 'expression' || selectedType === 'string') {
3977
- onChange('');
3909
+ setValue(name, '');
3978
3910
  } else if (selectedType === 'dem_builder') {
3979
3911
  const defaultArrayValue = {
3980
3912
  code: '',
@@ -3986,22 +3918,27 @@ const PropertyFiller = ({
3986
3918
  try {
3987
3919
  const definitionValue = JSON.parse(value);
3988
3920
  definitionValue['properties'] = propertiesObjectToArray(definitionValue['properties'] || {});
3989
- onChange(definitionValue);
3921
+ setValue(name, definitionValue);
3990
3922
  } catch (error) {
3991
- onChange(defaultArrayValue);
3923
+ setValue(name, defaultArrayValue);
3992
3924
  // console.log('Parse failed');
3993
3925
  }
3994
3926
  } else {
3995
- onChange(defaultArrayValue);
3927
+ setValue(name, defaultArrayValue);
3996
3928
  }
3997
3929
  }
3998
3930
  clearErrors();
3999
- }, [name, defaultProperyValue, clearErrors, value, setFillOption, onChange, fillOption, propertyType, setValue, property]);
3931
+ }, [name, defaultProperyValue, clearErrors, value, setFillOption, fillOption, propertyType, setValue, property]);
4000
3932
  useEffect(() => {
4001
- if (value === undefined) {
4002
- onChange(property.defaultValue || defaultProperyValue);
3933
+ if (!isDirty && property.defaultValue) {
3934
+ setValue(name, property.defaultValue);
4003
3935
  }
4004
- }, [value, onChange, defaultProperyValue, property]);
3936
+ }, [isDirty, property, name, setValue]);
3937
+ useEffect(() => {
3938
+ if (property.isRequired && !value) {
3939
+ setValue(name, defaultProperyValue);
3940
+ }
3941
+ }, [value, setValue, defaultProperyValue, property, name, isDirty]);
4005
3942
  return jsxs(Grid$1, Object.assign({
4006
3943
  xs: 12
4007
3944
  }, {
@@ -4038,10 +3975,15 @@ const PropertyFiller = ({
4038
3975
  }), option.value))
4039
3976
  }))]
4040
3977
  }))
4041
- })) : null, fillOption === 'expression' && (propertyType === PropertyType.JSON || propertyType === PropertyType.ENTITY || propertyType === PropertyType.ANY ? jsx(JsonEditor$1, {
3978
+ })) : null, fillOption === 'expression' && (propertyType === PropertyType.JSON || propertyType === PropertyType.ENTITY || propertyType === PropertyType.ANY ?
3979
+ // <JsonEditor validate name={name} useParsedValue />
3980
+ jsx(ControlAceEditor, {
4042
3981
  name: name,
4043
- ref: ref,
4044
- useParsedValue: true
3982
+ control: control,
3983
+ label: valueLabel,
3984
+ parseValue: true,
3985
+ validateJson: true,
3986
+ hideErrorMessage: true
4045
3987
  }) : jsx(ControlInput, {
4046
3988
  control: control,
4047
3989
  name: name,
@@ -4054,15 +3996,19 @@ const PropertyFiller = ({
4054
3996
  label: valueLabel,
4055
3997
  required: true,
4056
3998
  hideErrorMessage: true
4057
- }), fillOption === 'json_notvalid' && jsx(JsonEditor$1, {
3999
+ }), fillOption === 'json_notvalid' &&
4000
+ // <JsonEditor validate name={name} />
4001
+ jsx(ControlAceEditor, {
4058
4002
  name: name,
4059
- ref: ref
4003
+ control: control,
4004
+ label: valueLabel,
4005
+ hideErrorMessage: true
4060
4006
  }), fillOption === 'widget' && jsx(PropertyWidget, {
4007
+ control: control,
4061
4008
  property: property,
4062
4009
  name: name,
4063
4010
  useExpression: useExpression,
4064
4011
  label: valueLabel,
4065
- ref: ref,
4066
4012
  required: required
4067
4013
  }), fillOption === 'dem_builder' && jsx(CreateDefinition, {
4068
4014
  title: "JSON",
@@ -4075,6 +4021,53 @@ const PropertyFiller = ({
4075
4021
  }));
4076
4022
  };
4077
4023
 
4024
+ const JsonEditor = /*#__PURE__*/forwardRef(({
4025
+ validate: _validate = false,
4026
+ name,
4027
+ useParsedValue
4028
+ }, ref) => {
4029
+ const {
4030
+ control,
4031
+ setValue,
4032
+ setError,
4033
+ clearErrors
4034
+ } = useFormContext();
4035
+ const value = useWatch({
4036
+ control,
4037
+ name
4038
+ });
4039
+ const handleChange = value => {
4040
+ try {
4041
+ if (value) setValue(name, useParsedValue ? JSON.parse(value) : value);
4042
+ clearErrors(name);
4043
+ } catch (e) {
4044
+ if (_validate) setError(name, {
4045
+ message: 'Invalid JSON'
4046
+ });
4047
+ }
4048
+ };
4049
+ return jsx(CodeMirror, {
4050
+ ref: ref,
4051
+ basicSetup: {
4052
+ autocompletion: true,
4053
+ history: true
4054
+ },
4055
+ theme: abcdef,
4056
+ width: "100%",
4057
+ height: "200px",
4058
+ style: {
4059
+ fontSize: 14,
4060
+ lineHeight: 1.4,
4061
+ zIndex: 0,
4062
+ isolation: 'isolate'
4063
+ },
4064
+ value: typeof value !== 'string' ? value === null ? '' : JSON.stringify(value) : value,
4065
+ onChange: handleChange,
4066
+ extensions: [langs.json()]
4067
+ });
4068
+ });
4069
+ var JsonEditor$1 = JsonEditor;
4070
+
4078
4071
  const MultiplePropertyWidget = ({
4079
4072
  name,
4080
4073
  property,
@@ -4166,6 +4159,8 @@ const MultiplePropertyFiller = ({
4166
4159
  label,
4167
4160
  title
4168
4161
  }) => {
4162
+ var _a;
4163
+ const [selectTouched, setSelectTouched] = useState(false);
4169
4164
  const {
4170
4165
  control,
4171
4166
  clearErrors,
@@ -4174,7 +4169,8 @@ const MultiplePropertyFiller = ({
4174
4169
  const {
4175
4170
  field: {
4176
4171
  ref,
4177
- onChange
4172
+ onChange,
4173
+ value
4178
4174
  },
4179
4175
  fieldState: {
4180
4176
  error,
@@ -4183,7 +4179,7 @@ const MultiplePropertyFiller = ({
4183
4179
  } = useController({
4184
4180
  control,
4185
4181
  name,
4186
- defaultValue: property.defaultValue,
4182
+ defaultValue: (_a = property.defaultValue) !== null && _a !== void 0 ? _a : [],
4187
4183
  rules: {
4188
4184
  validate: val => {
4189
4185
  if (required && !val) return 'Please, fill this field';
@@ -4191,17 +4187,14 @@ const MultiplePropertyFiller = ({
4191
4187
  }
4192
4188
  }
4193
4189
  });
4194
- const value = useWatch({
4195
- control,
4196
- name
4197
- });
4198
4190
  const {
4199
4191
  propertyType,
4200
4192
  valueLabel,
4201
4193
  fillOptionLabel,
4202
4194
  fillOption,
4203
4195
  fillOptions,
4204
- setFillOption
4196
+ setFillOption,
4197
+ checkFillOption
4205
4198
  } = usePropertyFiller$1({
4206
4199
  property,
4207
4200
  value,
@@ -4212,23 +4205,28 @@ const MultiplePropertyFiller = ({
4212
4205
  multipleOptions: true
4213
4206
  });
4214
4207
  const handleFillOptionChange = event => {
4208
+ setSelectTouched(true);
4215
4209
  const selectedType = event.target.value;
4216
4210
  if (selectedType === 'null') {
4217
4211
  setValue(name, null);
4218
4212
  } else if (selectedType === 'expression' || selectedType === 'json_valid' || selectedType === 'json_notvalid') {
4219
4213
  onChange('');
4220
4214
  } else if (selectedType === 'widget') {
4221
- console.log('WiDGET??');
4222
4215
  onChange([]);
4223
4216
  }
4224
4217
  setFillOption(selectedType);
4225
4218
  clearErrors(name);
4226
4219
  };
4227
4220
  useEffect(() => {
4228
- if (value === undefined) {
4221
+ if (!value) {
4229
4222
  onChange(property.isRequired ? [] : null);
4230
4223
  }
4231
4224
  }, [value, property, onChange]);
4225
+ useEffect(() => {
4226
+ if (value && !selectTouched) {
4227
+ checkFillOption();
4228
+ }
4229
+ }, [checkFillOption, selectTouched, value]);
4232
4230
  return jsxs(Grid$1, {
4233
4231
  children: [title && jsx(Box, Object.assign({
4234
4232
  mb: 2
@@ -4328,7 +4326,7 @@ const PropertyValueField = ({
4328
4326
  const typeValue = typeof propertyType === 'string' ? propertyType : propertyType.value;
4329
4327
  return {
4330
4328
  name: _label,
4331
- isRequired,
4329
+ isRequired: required !== null && required !== void 0 ? required : isRequired,
4332
4330
  isMultiple,
4333
4331
  format,
4334
4332
  restrictedValues,
@@ -4341,7 +4339,7 @@ const PropertyValueField = ({
4341
4339
  uiSettings: null,
4342
4340
  validationNode: null
4343
4341
  };
4344
- }, [propertyType, format, restrictedValues, isMultiple, _label, isRequired, properties]);
4342
+ }, [propertyType, format, restrictedValues, isMultiple, _label, isRequired, properties, required]);
4345
4343
  return isMultiple ? jsx(MultiplePropertyFiller, {
4346
4344
  name: name,
4347
4345
  property: fillerProperty,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dartech/arsenal-ui",
3
- "version": "1.3.60",
3
+ "version": "1.3.62",
4
4
  "author": "DAR",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -21,5 +21,6 @@ declare const usePropertyFiller: ({ value, property, label, isDirty, required, u
21
21
  }[];
22
22
  setFillOption: import("react").Dispatch<import("react").SetStateAction<PropertyFillType>>;
23
23
  defaultProperyValue: {};
24
+ checkFillOption: () => void;
24
25
  };
25
26
  export default usePropertyFiller;
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ import { Control } from 'react-hook-form';
2
3
  import { PropertyUnion } from '../../../interfaces';
3
4
  type Props = {
4
5
  property: PropertyUnion;
@@ -6,6 +7,7 @@ type Props = {
6
7
  label?: string;
7
8
  useExpression?: boolean;
8
9
  required?: boolean;
10
+ control: Control<any>;
9
11
  };
10
- export declare const PropertyWidget: import("react").ForwardRefExoticComponent<Props & import("react").RefAttributes<any>>;
12
+ export declare const PropertyWidget: ({ property, name, label, useExpression, control }: Props) => JSX.Element;
11
13
  export default PropertyWidget;
@@ -1,2 +1,3 @@
1
1
  export * from './CreatePropertiesList';
2
2
  export * from './CreatePropertyFormFields';
3
+ export * from './PropertyValueField';
@@ -1,5 +1,4 @@
1
1
  export * from './UpsertProperty';
2
- export * from './PropertyValueField';
3
2
  export * from './ViewProperty';
4
3
  export * from './ViewPropertiesList';
5
4
  export * from './PropertyFiller';