@dartech/arsenal-ui 1.3.56 → 1.3.58

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
@@ -216,7 +216,6 @@ const AlertDialog = ({
216
216
  * @category Forms
217
217
  */
218
218
  const ControlInput = _a => {
219
- var _b;
220
219
  var {
221
220
  control,
222
221
  validate,
@@ -233,7 +232,8 @@ const ControlInput = _a => {
233
232
  const {
234
233
  field: {
235
234
  ref,
236
- onChange
235
+ onChange,
236
+ value
237
237
  },
238
238
  fieldState: {
239
239
  error
@@ -247,10 +247,6 @@ const ControlInput = _a => {
247
247
  validate
248
248
  }
249
249
  });
250
- const value = useWatch({
251
- control,
252
- name
253
- });
254
250
  return jsx(TextField, Object.assign({
255
251
  fullWidth: true,
256
252
  size: "small",
@@ -275,11 +271,7 @@ const ControlInput = _a => {
275
271
  minRows: textarea ? 3 : 1,
276
272
  value: value !== null && value !== void 0 ? value : '',
277
273
  onChange: customOnChange ? customOnChange : onChange
278
- }, textFieldProps, {
279
- inputProps: Object.assign(Object.assign({}, (_b = textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.inputProps) !== null && _b !== void 0 ? _b : {}), {
280
- value: value !== null && value !== void 0 ? value : ''
281
- })
282
- }));
274
+ }, textFieldProps));
283
275
  };
284
276
 
285
277
  function useDebounce(func, delay) {
@@ -1036,30 +1028,33 @@ const ControlAceEditor = /*#__PURE__*/forwardRef((_a, ref) => {
1036
1028
  readOnly,
1037
1029
  required = false,
1038
1030
  validateJson = false,
1031
+ hideErrorMessage = false,
1039
1032
  fontSize = 16,
1040
1033
  validate = true,
1041
1034
  parseValue
1042
1035
  } = _a,
1043
- otherProps = __rest(_a, ["control", "name", "mode", "label", "width", "height", "readOnly", "required", "validateJson", "fontSize", "validate", "parseValue"]);
1036
+ otherProps = __rest(_a, ["control", "name", "mode", "label", "width", "height", "readOnly", "required", "validateJson", "hideErrorMessage", "fontSize", "validate", "parseValue"]);
1044
1037
  const {
1045
1038
  setError,
1046
1039
  clearErrors
1047
1040
  } = useFormContext();
1048
1041
  const {
1049
1042
  field: {
1050
- onChange
1043
+ onChange,
1044
+ value,
1045
+ ref: fromRef
1051
1046
  },
1052
1047
  fieldState: {
1053
1048
  error
1054
1049
  }
1055
1050
  } = useController({
1056
1051
  control,
1057
- name
1058
- });
1059
- const value = useWatch({
1060
- control,
1061
- name
1052
+ name,
1053
+ rules: {
1054
+ required: required && 'Please, fill this field'
1055
+ }
1062
1056
  });
1057
+ // const value = useWatch({ control, name });
1063
1058
  const extensions = useMemo(() => ({
1064
1059
  json: [langs.json()],
1065
1060
  javascript: [langs.javascript()],
@@ -1086,7 +1081,6 @@ const ControlAceEditor = /*#__PURE__*/forwardRef((_a, ref) => {
1086
1081
  if (parseValue) {
1087
1082
  try {
1088
1083
  const val = JSON.parse(value);
1089
- console.log('parsed val:', val);
1090
1084
  onChange(val);
1091
1085
  } catch (e) {
1092
1086
  onChange(value);
@@ -1119,7 +1113,7 @@ const ControlAceEditor = /*#__PURE__*/forwardRef((_a, ref) => {
1119
1113
  }))
1120
1114
  }), jsxs(Fragment, {
1121
1115
  children: [jsx(CodeMirror, Object.assign({
1122
- ref: ref,
1116
+ ref: ref || fromRef,
1123
1117
  basicSetup: {
1124
1118
  autocompletion: true,
1125
1119
  history: true
@@ -1137,7 +1131,7 @@ const ControlAceEditor = /*#__PURE__*/forwardRef((_a, ref) => {
1137
1131
  value: mode === 'json' && typeof value !== 'string' ? value === null ? '' : JSON.stringify(value, null, 2) : value,
1138
1132
  onChange: handleChange,
1139
1133
  extensions: extensions[mode]
1140
- }, otherProps)), error && jsx(FormHelperText, Object.assign({
1134
+ }, otherProps)), error && !hideErrorMessage && jsx(FormHelperText, Object.assign({
1141
1135
  error: true
1142
1136
  }, {
1143
1137
  children: error.message
@@ -3580,12 +3574,11 @@ const PropertyAdditionalFields = ({
3580
3574
  }
3581
3575
  };
3582
3576
 
3583
- const JsonEditor = ({
3577
+ const JsonEditor = /*#__PURE__*/forwardRef(({
3584
3578
  validate: _validate = false,
3585
3579
  name,
3586
- inputRef,
3587
3580
  useParsedValue
3588
- }) => {
3581
+ }, ref) => {
3589
3582
  const {
3590
3583
  control,
3591
3584
  setValue,
@@ -3607,7 +3600,7 @@ const JsonEditor = ({
3607
3600
  }
3608
3601
  };
3609
3602
  return jsx(CodeMirror, {
3610
- ref: inputRef,
3603
+ ref: ref,
3611
3604
  basicSetup: {
3612
3605
  autocompletion: true,
3613
3606
  history: true
@@ -3621,39 +3614,11 @@ const JsonEditor = ({
3621
3614
  zIndex: 0,
3622
3615
  isolation: 'isolate'
3623
3616
  },
3624
- value: typeof value !== 'string' ? value === null ? '' : JSON.stringify(value) : value,
3617
+ value: typeof value !== 'string' ? value === null ? '' : JSON.stringify(value, null, 2) : value,
3625
3618
  onChange: handleChange,
3626
3619
  extensions: [langs.json()]
3627
- })
3628
- // <AceEditor
3629
- // wrapEnabled
3630
- // width="100%"
3631
- // height="200px"
3632
- // theme="monokai"
3633
- // fontSize={14}
3634
- // showPrintMargin={false}
3635
- // style={{ lineHeight: 1.4, zIndex: 0, isolation: 'isolate' }}
3636
- // setOptions={{
3637
- // enableLiveAutocompletion: true,
3638
- // enableBasicAutocompletion: true,
3639
- // showLineNumbers: true,
3640
- // tabSize: 2,
3641
- // useWorker: false
3642
- // }}
3643
- // ref={inputRef}
3644
- // name={name}
3645
- // value={typeof value !== 'string' ? (value === null ? '' : JSON.stringify(value)) : value}
3646
- // onChange={handleChange}
3647
- // mode="json"
3648
- // onLoad={(editor) => {
3649
- // if (!validate) {
3650
- // editor.getSession().setUseWorker(false);
3651
- // }
3652
- // }}
3653
- // />
3654
- ;
3655
- };
3656
-
3620
+ });
3621
+ });
3657
3622
  var JsonEditor$1 = JsonEditor;
3658
3623
 
3659
3624
  const StringValueField = ({
@@ -3788,7 +3753,8 @@ const PropertyWidget = ({
3788
3753
  return jsx(JsonEditor$1, {
3789
3754
  validate: true,
3790
3755
  name: name,
3791
- inputRef: inputRef
3756
+ ref: inputRef,
3757
+ useParsedValue: true
3792
3758
  });
3793
3759
  case PropertyType.STRING:
3794
3760
  return jsx(StringValueField$1, {
@@ -3808,7 +3774,7 @@ const PropertyWidget = ({
3808
3774
  case PropertyType.ANY:
3809
3775
  return jsx(JsonEditor$1, {
3810
3776
  name: name,
3811
- inputRef: inputRef
3777
+ ref: inputRef
3812
3778
  });
3813
3779
  case PropertyType.ENTITY:
3814
3780
  return jsx(DefinitionFiller, {
@@ -3834,7 +3800,10 @@ const usePropertyFiller = ({
3834
3800
  }) => {
3835
3801
  const valueLabel = useMemo(() => label ? `${label} (value)` : `${property.name} (value)`, [label, property]);
3836
3802
  const fillOptionLabel = useMemo(() => label ? `${label} (widget)` : `${property.name} (widget)`, [label, property]);
3837
- const propertyType = useMemo(() => typeof property.propertyType === 'string' ? property.propertyType : property['propertyType']['value'], [property]);
3803
+ const propertyType = useMemo(() => {
3804
+ var _a;
3805
+ return typeof property.propertyType === 'string' ? property.propertyType : (_a = property['propertyType']) === null || _a === void 0 ? void 0 : _a['value'];
3806
+ }, [property]);
3838
3807
  const [fillOption, setFillOption] = useState(null);
3839
3808
  const fillOptions = useMemo(() => _multipleOptions ? getMultiplePropertyFillOptions({
3840
3809
  propertyType,
@@ -3845,6 +3814,29 @@ const usePropertyFiller = ({
3845
3814
  required: _required,
3846
3815
  useExpression: _useExpression
3847
3816
  }), [_useExpression, _required, propertyType, _multipleOptions]);
3817
+ const defaultProperyValue = useMemo(() => {
3818
+ switch (propertyType) {
3819
+ case PropertyType.STRING:
3820
+ case PropertyType.DATE:
3821
+ case PropertyType.TIME:
3822
+ case PropertyType.DATE_TIME:
3823
+ case PropertyType.ANY:
3824
+ return '';
3825
+ case PropertyType.JSON:
3826
+ return {};
3827
+ case PropertyType.BOOLEAN:
3828
+ return true;
3829
+ case PropertyType.INTEGER:
3830
+ case PropertyType.BIG_DECIMAL:
3831
+ case PropertyType.BIG_INTEGER:
3832
+ case PropertyType.DOUBLE:
3833
+ case PropertyType.LONG:
3834
+ case PropertyType.FLOAT:
3835
+ return 0;
3836
+ default:
3837
+ return {};
3838
+ }
3839
+ }, [propertyType]);
3848
3840
  useEffect(() => {
3849
3841
  if (!fillOption) {
3850
3842
  if (isPropertyValueEmpty(value) && (fillOptions === null || fillOptions === void 0 ? void 0 : fillOptions.length)) {
@@ -3868,7 +3860,8 @@ const usePropertyFiller = ({
3868
3860
  fillOptionLabel,
3869
3861
  fillOption,
3870
3862
  fillOptions,
3871
- setFillOption
3863
+ setFillOption,
3864
+ defaultProperyValue
3872
3865
  };
3873
3866
  };
3874
3867
  var usePropertyFiller$1 = usePropertyFiller;
@@ -3898,7 +3891,8 @@ const PropertyFiller = ({
3898
3891
  const {
3899
3892
  field: {
3900
3893
  ref,
3901
- onChange
3894
+ onChange,
3895
+ value
3902
3896
  },
3903
3897
  fieldState: {
3904
3898
  error,
@@ -3911,17 +3905,15 @@ const PropertyFiller = ({
3911
3905
  required
3912
3906
  }
3913
3907
  });
3914
- const value = useWatch({
3915
- control,
3916
- name
3917
- });
3908
+ // const value = useWatch({ control, name });
3918
3909
  const {
3919
3910
  propertyType,
3920
3911
  valueLabel,
3921
3912
  fillOptionLabel,
3922
3913
  fillOption,
3923
3914
  fillOptions,
3924
- setFillOption
3915
+ setFillOption,
3916
+ defaultProperyValue
3925
3917
  } = usePropertyFiller$1({
3926
3918
  value,
3927
3919
  property,
@@ -3943,10 +3935,10 @@ const PropertyFiller = ({
3943
3935
  try {
3944
3936
  onChange(JSON.stringify(definitionValue, null, '\t'));
3945
3937
  } catch (error) {
3946
- console.log('Stringify failed');
3938
+ console.log('Stringify failed', error);
3947
3939
  }
3948
3940
  } else {
3949
- setValue(name, null);
3941
+ setValue(name, defaultProperyValue);
3950
3942
  }
3951
3943
  } else if (selectedType === 'expression' || selectedType === 'string') {
3952
3944
  onChange('');
@@ -3971,12 +3963,12 @@ const PropertyFiller = ({
3971
3963
  }
3972
3964
  }
3973
3965
  clearErrors();
3974
- }, [name, clearErrors, value, setFillOption, onChange, fillOption, propertyType, setValue]);
3966
+ }, [name, defaultProperyValue, clearErrors, value, setFillOption, onChange, fillOption, propertyType, setValue]);
3975
3967
  useEffect(() => {
3976
3968
  if (value === undefined) {
3977
3969
  onChange(null);
3978
3970
  }
3979
- }, [value, onChange]);
3971
+ }, [value, onChange, defaultProperyValue]);
3980
3972
  return jsxs(Grid$1, Object.assign({
3981
3973
  xs: 12
3982
3974
  }, {
@@ -4015,13 +4007,21 @@ const PropertyFiller = ({
4015
4007
  }))
4016
4008
  })) : null, fillOption === 'expression' && (propertyType === PropertyType.JSON || propertyType === PropertyType.ENTITY || propertyType === PropertyType.ANY ? jsx(JsonEditor$1, {
4017
4009
  name: name,
4018
- inputRef: ref
4010
+ ref: ref
4019
4011
  }) : jsx(ControlInput, {
4020
4012
  control: control,
4021
4013
  name: name,
4022
4014
  label: valueLabel,
4023
4015
  required: true,
4024
- hideErrorMessage: true
4016
+ hideErrorMessage: true,
4017
+ onChange: e => {
4018
+ try {
4019
+ onChange(JSON.parse(e.target.value));
4020
+ } catch (err) {
4021
+ onChange(e.target.value);
4022
+ }
4023
+ },
4024
+ value: typeof value === 'string' ? value : JSON.stringify(value)
4025
4025
  })), fillOption === 'string' && jsx(ControlInput, {
4026
4026
  control: control,
4027
4027
  name: name,
@@ -4030,7 +4030,7 @@ const PropertyFiller = ({
4030
4030
  hideErrorMessage: true
4031
4031
  }), fillOption === 'json_notvalid' && jsx(JsonEditor$1, {
4032
4032
  name: name,
4033
- inputRef: ref
4033
+ ref: ref
4034
4034
  }), fillOption === 'widget' && jsx(PropertyWidget, {
4035
4035
  property: property,
4036
4036
  name: name,
@@ -4041,8 +4041,8 @@ const PropertyFiller = ({
4041
4041
  }), fillOption === 'dem_builder' && jsx(CreateDefinition, {
4042
4042
  title: "JSON",
4043
4043
  definitionFieldName: name
4044
- }), error && jsx(Typography, Object.assign({
4045
- color: "secondary"
4044
+ }), error && jsx(FormHelperText, Object.assign({
4045
+ error: true
4046
4046
  }, {
4047
4047
  children: error.message
4048
4048
  }))]
@@ -4061,18 +4061,6 @@ const MultiplePropertyWidget = ({
4061
4061
  setValue,
4062
4062
  clearErrors
4063
4063
  } = useFormContext();
4064
- // const controller = useController({
4065
- // control,
4066
- // name,
4067
- // rules: {
4068
- // validate: (val) => {
4069
- // if (!val || (Array.isArray(val) && !val.length)) {
4070
- // return 'Please, fill array';
4071
- // }
4072
- // return true;
4073
- // },
4074
- // },
4075
- // });
4076
4064
  const values = useWatch({
4077
4065
  control,
4078
4066
  name
@@ -4081,7 +4069,7 @@ const MultiplePropertyWidget = ({
4081
4069
  if (values && Array.isArray(values)) {
4082
4070
  setValue(`${name}.${values.length}`, null);
4083
4071
  } else {
4084
- setValue(name, [null]);
4072
+ setValue(name, []);
4085
4073
  }
4086
4074
  clearErrors(name);
4087
4075
  }, [name, values, setValue, clearErrors]);
@@ -4094,7 +4082,7 @@ const MultiplePropertyWidget = ({
4094
4082
  direction: "column",
4095
4083
  xs: 12
4096
4084
  }, {
4097
- children: [values && Array.isArray(values) ? values.map((value, index) => jsx(Grid$1, Object.assign({
4085
+ children: [Array.isArray(values) && values.length ? values.map((value, index) => jsx(Grid$1, Object.assign({
4098
4086
  xs: 12
4099
4087
  }, {
4100
4088
  children: jsxs(Box, Object.assign({
@@ -4150,7 +4138,8 @@ const MultiplePropertyFiller = ({
4150
4138
  }) => {
4151
4139
  const {
4152
4140
  control,
4153
- clearErrors
4141
+ clearErrors,
4142
+ setValue
4154
4143
  } = useFormContext();
4155
4144
  const {
4156
4145
  field: {
@@ -4164,11 +4153,10 @@ const MultiplePropertyFiller = ({
4164
4153
  } = useController({
4165
4154
  control,
4166
4155
  name,
4156
+ defaultValue: [],
4167
4157
  rules: {
4168
4158
  validate: val => {
4169
- if (required && !val) {
4170
- return 'Please, fill this field';
4171
- }
4159
+ if (required && !val) return 'Please, fill this field';
4172
4160
  return true;
4173
4161
  }
4174
4162
  }
@@ -4196,7 +4184,7 @@ const MultiplePropertyFiller = ({
4196
4184
  const handleFillOptionChange = event => {
4197
4185
  const selectedType = event.target.value;
4198
4186
  if (selectedType === 'null') {
4199
- onChange(null);
4187
+ setValue(name, null);
4200
4188
  } else if (selectedType === 'expression' || selectedType === 'json_valid' || selectedType === 'json_notvalid') {
4201
4189
  onChange('');
4202
4190
  } else if (selectedType === 'widget') {
@@ -4205,11 +4193,11 @@ const MultiplePropertyFiller = ({
4205
4193
  setFillOption(selectedType);
4206
4194
  clearErrors(name);
4207
4195
  };
4208
- useEffect(() => {
4209
- if (value === undefined) {
4210
- onChange(null);
4211
- }
4212
- }, [value, onChange]);
4196
+ // useEffect(() => {
4197
+ // if (value === undefined) {
4198
+ // onChange([]);
4199
+ // }
4200
+ // }, [value, property, onChange]);
4213
4201
  return jsxs(Grid$1, {
4214
4202
  children: [title && jsx(Box, Object.assign({
4215
4203
  mb: 2
@@ -4246,7 +4234,7 @@ const MultiplePropertyFiller = ({
4246
4234
  }))
4247
4235
  })) : null, fillOption === 'expression' && (propertyType === PropertyType.JSON || propertyType === PropertyType.ENTITY || propertyType === PropertyType.ANY ? jsx(JsonEditor$1, {
4248
4236
  name: name,
4249
- inputRef: ref
4237
+ ref: ref
4250
4238
  }) : jsx(ControlInput, {
4251
4239
  required: true,
4252
4240
  hideErrorMessage: true,
@@ -4256,7 +4244,7 @@ const MultiplePropertyFiller = ({
4256
4244
  })), fillOption === 'json_valid' && jsx(JsonEditor$1, {
4257
4245
  validate: true,
4258
4246
  name: name,
4259
- inputRef: ref,
4247
+ ref: ref,
4260
4248
  useParsedValue: true
4261
4249
  }), fillOption === 'widget' && jsx(MultiplePropertyWidget$1, {
4262
4250
  property: property,
@@ -4264,8 +4252,8 @@ const MultiplePropertyFiller = ({
4264
4252
  useExpression: useExpression,
4265
4253
  required: required,
4266
4254
  label: label
4267
- }), error && jsx(Typography, Object.assign({
4268
- color: "secondary"
4255
+ }), error && jsx(FormHelperText, Object.assign({
4256
+ error: true
4269
4257
  }, {
4270
4258
  children: error.message
4271
4259
  }))]
@@ -5334,7 +5322,8 @@ const DefinitionFiller = ({
5334
5322
  const stepperData = useMemo(() => {
5335
5323
  if (properties) {
5336
5324
  return properties.map(property => {
5337
- const propertyType = typeof property.propertyType === 'string' ? property.propertyType : property['propertyType']['value'];
5325
+ var _a;
5326
+ const propertyType = typeof property.propertyType === 'string' ? property.propertyType : (_a = property['propertyType']) === null || _a === void 0 ? void 0 : _a['value'];
5338
5327
  return {
5339
5328
  label: jsxs(Box, Object.assign({
5340
5329
  display: "flex",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dartech/arsenal-ui",
3
- "version": "1.3.56",
3
+ "version": "1.3.58",
4
4
  "author": "DAR",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -13,6 +13,7 @@ export interface ControlAceEditorProps {
13
13
  validateJson?: boolean;
14
14
  fontSize?: number;
15
15
  validate?: boolean;
16
+ hideErrorMessage?: boolean;
16
17
  parseValue?: boolean;
17
18
  [key: string]: unknown;
18
19
  }
@@ -1,10 +1,9 @@
1
1
  /// <reference types="react" />
2
- import { RefCallBack } from 'react-hook-form';
2
+ import { ReactCodeMirrorRef } from '@uiw/react-codemirror';
3
3
  type Props = {
4
4
  useParsedValue?: boolean;
5
5
  validate?: boolean;
6
6
  name: string;
7
- inputRef: RefCallBack;
8
7
  };
9
- declare const JsonEditor: ({ validate, name, inputRef, useParsedValue }: Props) => JSX.Element;
8
+ declare const JsonEditor: import("react").ForwardRefExoticComponent<Props & import("react").RefAttributes<ReactCodeMirrorRef>>;
10
9
  export default JsonEditor;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { PropertyFillType, PropertyUnion } from '../../../interfaces';
2
+ import { PropertyFillType, PropertyUnion, PropertyType } from '../../../interfaces';
3
3
  type Props = {
4
4
  value: unknown;
5
5
  property: PropertyUnion;
@@ -10,7 +10,7 @@ type Props = {
10
10
  multipleOptions?: boolean;
11
11
  };
12
12
  declare const usePropertyFiller: ({ value, property, label, isDirty, required, useExpression, multipleOptions, }: Props) => {
13
- propertyType: import("../../../interfaces").PropertyType;
13
+ propertyType: PropertyType;
14
14
  valueLabel: string;
15
15
  fillOptionLabel: string;
16
16
  fillOption: PropertyFillType;
@@ -20,5 +20,6 @@ declare const usePropertyFiller: ({ value, property, label, isDirty, required, u
20
20
  sortOrder: number;
21
21
  }[];
22
22
  setFillOption: import("react").Dispatch<import("react").SetStateAction<PropertyFillType>>;
23
+ defaultProperyValue: {};
23
24
  };
24
25
  export default usePropertyFiller;