@dartech/arsenal-ui 1.3.76 → 1.3.78

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
@@ -1473,10 +1473,24 @@ const formatTableRowValue = ({
1473
1473
 
1474
1474
  const digitsOnly = new RegExp('^[-+]?[0-9]+$');
1475
1475
  const floatsOnly = new RegExp(/^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/);
1476
- const isExpression = value => {
1476
+ const isExpression = (value, useRecursion) => {
1477
1477
  if (typeof value === 'string') return /\$(?:S?JS)?\(/g.test(value);
1478
+ if (useRecursion) {
1479
+ if (Array.isArray(value)) {
1480
+ for (const item of value) {
1481
+ if (isExpression(item, useRecursion)) return true;
1482
+ }
1483
+ }
1484
+ if (typeof value === 'object') {
1485
+ for (const key in value) {
1486
+ if (isExpression(value[key], useRecursion)) return true;
1487
+ }
1488
+ }
1489
+ }
1478
1490
  return false;
1491
+ // return typeof value === 'string' ? /\$(?:S?JS)?\(/g.test(value) : false;
1479
1492
  };
1493
+
1480
1494
  const isDateType = propertyType => {
1481
1495
  return propertyType === PropertyType.DATE || propertyType === PropertyType.DATE_TIME || propertyType === PropertyType.TIME;
1482
1496
  };
@@ -3921,18 +3935,19 @@ const usePropertyFiller = ({
3921
3935
  return {};
3922
3936
  }
3923
3937
  }, [propertyType]);
3938
+ const needRecursionCheck = useMemo(() => propertyType === PropertyType.JSON, [propertyType]);
3924
3939
  const checkFillOption = useCallback(() => {
3925
- if (isExpression(value) && fillOption !== 'expression') {
3940
+ if (isExpression(value, needRecursionCheck)) {
3926
3941
  setFillOption('expression');
3927
- } else if (value !== null && value !== undefined && !isExpression(value) && fillOption !== 'widget' && fillOption !== 'string') {
3942
+ } else if (value !== null && value !== undefined && !isExpression(value, needRecursionCheck) && fillOption !== 'widget' && fillOption !== 'string') {
3928
3943
  setFillOption('widget');
3929
3944
  }
3930
- }, [value, fillOption]);
3945
+ }, [value, fillOption, needRecursionCheck]);
3931
3946
  useEffect(() => {
3932
3947
  if (!fillOption) {
3933
3948
  if (isPropertyValueEmpty(value) && (fillOptions === null || fillOptions === void 0 ? void 0 : fillOptions.length)) {
3934
3949
  setFillOption(fillOptions[0].value);
3935
- } else if (_useExpression && isExpression(value)) {
3950
+ } else if (_useExpression && isExpression(value, needRecursionCheck)) {
3936
3951
  setFillOption('expression');
3937
3952
  } else {
3938
3953
  setFillOption('widget');
@@ -3940,7 +3955,7 @@ const usePropertyFiller = ({
3940
3955
  } else if (!isDirty) {
3941
3956
  checkFillOption();
3942
3957
  }
3943
- }, [value, fillOption, fillOptions, _useExpression, isDirty, checkFillOption]);
3958
+ }, [value, fillOption, fillOptions, _useExpression, isDirty, checkFillOption, needRecursionCheck]);
3944
3959
  return {
3945
3960
  propertyType,
3946
3961
  valueLabel,
@@ -4155,53 +4170,6 @@ const PropertyFiller = ({
4155
4170
  }));
4156
4171
  };
4157
4172
 
4158
- const JsonEditor = /*#__PURE__*/forwardRef(({
4159
- validate: _validate = false,
4160
- name,
4161
- useParsedValue
4162
- }, ref) => {
4163
- const {
4164
- control,
4165
- setValue,
4166
- setError,
4167
- clearErrors
4168
- } = useFormContext();
4169
- const value = useWatch({
4170
- control,
4171
- name
4172
- });
4173
- const handleChange = value => {
4174
- try {
4175
- if (value) setValue(name, useParsedValue ? JSON.parse(value) : value);
4176
- clearErrors(name);
4177
- } catch (e) {
4178
- if (_validate) setError(name, {
4179
- message: 'Invalid JSON'
4180
- });
4181
- }
4182
- };
4183
- return jsx(CodeMirror, {
4184
- ref: ref,
4185
- basicSetup: {
4186
- autocompletion: true,
4187
- history: true
4188
- },
4189
- theme: abcdef,
4190
- width: "100%",
4191
- height: "200px",
4192
- style: {
4193
- fontSize: 14,
4194
- lineHeight: 1.4,
4195
- zIndex: 0,
4196
- isolation: 'isolate'
4197
- },
4198
- value: typeof value !== 'string' ? value === null ? '' : JSON.stringify(value) : value,
4199
- onChange: handleChange,
4200
- extensions: [langs.json()]
4201
- });
4202
- });
4203
- var JsonEditor$1 = JsonEditor;
4204
-
4205
4173
  const MultiplePropertyWidget = ({
4206
4174
  name,
4207
4175
  property,
@@ -4367,7 +4335,7 @@ const MultiplePropertyFiller = ({
4367
4335
  };
4368
4336
  useEffect(() => {
4369
4337
  if (!value) {
4370
- onChange(property.isRequired ? [] : null);
4338
+ onChange(property.isRequired && property.isMultiple ? [] : null);
4371
4339
  }
4372
4340
  }, [value, property, onChange]);
4373
4341
  useEffect(() => {
@@ -4410,21 +4378,29 @@ const MultiplePropertyFiller = ({
4410
4378
  }), option.value))
4411
4379
  }))]
4412
4380
  }))
4413
- })) : null, fillOption === 'expression' && (propertyType === PropertyType.JSON || propertyType === PropertyType.ENTITY || propertyType === PropertyType.ANY ? jsx(JsonEditor$1, {
4381
+ })) : null, fillOption === 'expression' && (propertyType === PropertyType.JSON || propertyType === PropertyType.ENTITY || propertyType === PropertyType.ANY ? jsx(ControlAceEditor, {
4414
4382
  name: name,
4415
- ref: ref
4383
+ control: control,
4384
+ label: valueLabel,
4385
+ parseValue: true,
4386
+ validateJson: true,
4387
+ hideErrorMessage: true
4416
4388
  }) : jsx(ControlInput, {
4417
4389
  required: true,
4418
4390
  hideErrorMessage: true,
4419
4391
  control: control,
4420
4392
  name: name,
4421
4393
  label: valueLabel
4422
- })), fillOption === 'json_valid' && jsx(JsonEditor$1, {
4423
- validate: true,
4394
+ })), fillOption === 'json_valid' && jsx(ControlAceEditor, {
4424
4395
  name: name,
4425
- ref: ref,
4426
- useParsedValue: true
4427
- }), fillOption === 'widget' && jsx(MultiplePropertyWidget$1, {
4396
+ control: control,
4397
+ label: valueLabel,
4398
+ parseValue: true,
4399
+ validateJson: true,
4400
+ hideErrorMessage: true
4401
+ })
4402
+ // <JsonEditor validate name={name} ref={ref} useParsedValue />
4403
+ , fillOption === 'widget' && jsx(MultiplePropertyWidget$1, {
4428
4404
  property: property,
4429
4405
  name: name,
4430
4406
  useExpression: useExpression,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dartech/arsenal-ui",
3
- "version": "1.3.76",
3
+ "version": "1.3.78",
4
4
  "author": "DAR",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -1,5 +1,5 @@
1
1
  import { PropertyType } from '../interfaces';
2
2
  export declare const digitsOnly: RegExp;
3
3
  export declare const floatsOnly: RegExp;
4
- export declare const isExpression: (value: unknown) => boolean;
4
+ export declare const isExpression: (value: unknown, useRecursion?: boolean) => boolean;
5
5
  export declare const isDateType: (propertyType: PropertyType) => boolean;