@dartech/arsenal-ui 1.3.77 → 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 => {
1477
- // return typeof value === 'string' ? value.includes('$(') : false;
1478
- return typeof value === 'string' ? /\$(?:S?JS)?\(/g.test(value) : false;
1476
+ const isExpression = (value, useRecursion) => {
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
+ }
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
  };
@@ -1645,7 +1659,6 @@ const propertiesArrayToObject = (properties, isGlobalParameter) => {
1645
1659
  resultProperty['restrictedValues'] = property.restrictedValues;
1646
1660
  }
1647
1661
  if (propertyType === PropertyType.ENTITY_REFERENCE) {
1648
- resultProperty['source'] = property.source;
1649
1662
  resultProperty['definitionCode'] = property.definitionCode;
1650
1663
  resultProperty['definitionVersion'] = property.definitionVersion;
1651
1664
  resultProperty['labelPropertyCode'] = property.labelPropertyCode;
@@ -1889,7 +1902,7 @@ const ControlNumberInput = _a => {
1889
1902
  } else if (!decimal && !digitsOnly.test(val)) {
1890
1903
  return 'Not valid integer';
1891
1904
  }
1892
- return true;
1905
+ return validate ? typeof validate === 'function' ? validate(val) : true : true;
1893
1906
  }
1894
1907
  }
1895
1908
  }),
@@ -3430,83 +3443,6 @@ const EntityAdditionalFields = ({
3430
3443
  };
3431
3444
  var EntityAdditionalFields$1 = EntityAdditionalFields;
3432
3445
 
3433
- const sources = [{
3434
- label: 'Arsenal',
3435
- value: 'ARSENAL'
3436
- }, {
3437
- label: 'Scalend',
3438
- value: 'SCALEND'
3439
- }];
3440
- const modules = [{
3441
- label: 'Customers',
3442
- value: 'CUSTOMERS'
3443
- }, {
3444
- label: 'Products',
3445
- value: 'PRODUCTS'
3446
- }, {
3447
- label: 'Pledges',
3448
- value: 'PLEDGES'
3449
- }];
3450
- const EntityReferencePropertyFields = ({
3451
- propertyFieldName
3452
- }) => {
3453
- const {
3454
- control
3455
- } = useFormContext();
3456
- const source = useWatch({
3457
- control,
3458
- name: `${propertyFieldName}.source`
3459
- });
3460
- return jsxs(Fragment, {
3461
- children: [jsx(Grid, {
3462
- children: jsx(ControlSelect, {
3463
- required: true,
3464
- control: control,
3465
- name: `${propertyFieldName}.source`,
3466
- label: "Source",
3467
- options: sources
3468
- })
3469
- }), source && jsx(Grid, {
3470
- children: source === 'ARSENAL' ? jsx(ControlInput, {
3471
- required: true,
3472
- control: control,
3473
- name: `${propertyFieldName}.definitionCode`,
3474
- label: "Definition Code"
3475
- }) : jsx(ControlSelect, {
3476
- required: true,
3477
- control: control,
3478
- name: `${propertyFieldName}.definitionCode`,
3479
- label: "Definition Code",
3480
- valueKey: "value",
3481
- options: modules
3482
- })
3483
- }), jsx(Grid, {
3484
- children: jsx(ControlInput, {
3485
- required: true,
3486
- control: control,
3487
- name: `${propertyFieldName}.definitionVersion`,
3488
- label: "Definition Version",
3489
- defaultValue: 1
3490
- })
3491
- }), jsx(Grid, {
3492
- children: jsx(ControlInput, {
3493
- required: true,
3494
- control: control,
3495
- name: `${propertyFieldName}.labelPropertyCode`,
3496
- label: "Label Property Code"
3497
- })
3498
- }), jsx(Grid, {
3499
- children: jsx(ControlInput, {
3500
- required: true,
3501
- control: control,
3502
- name: `${propertyFieldName}.valuePropertyCode`,
3503
- label: "Value Property Code"
3504
- })
3505
- })]
3506
- });
3507
- };
3508
- var EntityReferencePropertyFields$1 = EntityReferencePropertyFields;
3509
-
3510
3446
  const StringPropertyFields = ({
3511
3447
  propertyFieldName
3512
3448
  }) => {
@@ -3633,7 +3569,8 @@ const PropertyAdditionalFields = ({
3633
3569
  defaultValue: DATE_TIME_DEFAULT_FORMAT
3634
3570
  });
3635
3571
  case PropertyType.ENTITY_REFERENCE:
3636
- return jsx(EntityReferencePropertyFields$1, {
3572
+ // return <EntityReferencePropertyFields propertyFieldName={propertyFieldName} />;
3573
+ return jsx(StringPropertyFields$1, {
3637
3574
  propertyFieldName: propertyFieldName
3638
3575
  });
3639
3576
  case PropertyType.ENTITY:
@@ -3998,18 +3935,19 @@ const usePropertyFiller = ({
3998
3935
  return {};
3999
3936
  }
4000
3937
  }, [propertyType]);
3938
+ const needRecursionCheck = useMemo(() => propertyType === PropertyType.JSON, [propertyType]);
4001
3939
  const checkFillOption = useCallback(() => {
4002
- if (isExpression(value) && fillOption !== 'expression') {
3940
+ if (isExpression(value, needRecursionCheck)) {
4003
3941
  setFillOption('expression');
4004
- } 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') {
4005
3943
  setFillOption('widget');
4006
3944
  }
4007
- }, [value, fillOption]);
3945
+ }, [value, fillOption, needRecursionCheck]);
4008
3946
  useEffect(() => {
4009
3947
  if (!fillOption) {
4010
3948
  if (isPropertyValueEmpty(value) && (fillOptions === null || fillOptions === void 0 ? void 0 : fillOptions.length)) {
4011
3949
  setFillOption(fillOptions[0].value);
4012
- } else if (_useExpression && isExpression(value)) {
3950
+ } else if (_useExpression && isExpression(value, needRecursionCheck)) {
4013
3951
  setFillOption('expression');
4014
3952
  } else {
4015
3953
  setFillOption('widget');
@@ -4017,7 +3955,7 @@ const usePropertyFiller = ({
4017
3955
  } else if (!isDirty) {
4018
3956
  checkFillOption();
4019
3957
  }
4020
- }, [value, fillOption, fillOptions, _useExpression, isDirty, checkFillOption]);
3958
+ }, [value, fillOption, fillOptions, _useExpression, isDirty, checkFillOption, needRecursionCheck]);
4021
3959
  return {
4022
3960
  propertyType,
4023
3961
  valueLabel,
@@ -4232,53 +4170,6 @@ const PropertyFiller = ({
4232
4170
  }));
4233
4171
  };
4234
4172
 
4235
- const JsonEditor = /*#__PURE__*/forwardRef(({
4236
- validate: _validate = false,
4237
- name,
4238
- useParsedValue
4239
- }, ref) => {
4240
- const {
4241
- control,
4242
- setValue,
4243
- setError,
4244
- clearErrors
4245
- } = useFormContext();
4246
- const value = useWatch({
4247
- control,
4248
- name
4249
- });
4250
- const handleChange = value => {
4251
- try {
4252
- if (value) setValue(name, useParsedValue ? JSON.parse(value) : value);
4253
- clearErrors(name);
4254
- } catch (e) {
4255
- if (_validate) setError(name, {
4256
- message: 'Invalid JSON'
4257
- });
4258
- }
4259
- };
4260
- return jsx(CodeMirror, {
4261
- ref: ref,
4262
- basicSetup: {
4263
- autocompletion: true,
4264
- history: true
4265
- },
4266
- theme: abcdef,
4267
- width: "100%",
4268
- height: "200px",
4269
- style: {
4270
- fontSize: 14,
4271
- lineHeight: 1.4,
4272
- zIndex: 0,
4273
- isolation: 'isolate'
4274
- },
4275
- value: typeof value !== 'string' ? value === null ? '' : JSON.stringify(value) : value,
4276
- onChange: handleChange,
4277
- extensions: [langs.json()]
4278
- });
4279
- });
4280
- var JsonEditor$1 = JsonEditor;
4281
-
4282
4173
  const MultiplePropertyWidget = ({
4283
4174
  name,
4284
4175
  property,
@@ -4444,7 +4335,7 @@ const MultiplePropertyFiller = ({
4444
4335
  };
4445
4336
  useEffect(() => {
4446
4337
  if (!value) {
4447
- onChange(property.isRequired ? [] : null);
4338
+ onChange(property.isRequired && property.isMultiple ? [] : null);
4448
4339
  }
4449
4340
  }, [value, property, onChange]);
4450
4341
  useEffect(() => {
@@ -4487,21 +4378,29 @@ const MultiplePropertyFiller = ({
4487
4378
  }), option.value))
4488
4379
  }))]
4489
4380
  }))
4490
- })) : 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, {
4491
4382
  name: name,
4492
- ref: ref
4383
+ control: control,
4384
+ label: valueLabel,
4385
+ parseValue: true,
4386
+ validateJson: true,
4387
+ hideErrorMessage: true
4493
4388
  }) : jsx(ControlInput, {
4494
4389
  required: true,
4495
4390
  hideErrorMessage: true,
4496
4391
  control: control,
4497
4392
  name: name,
4498
4393
  label: valueLabel
4499
- })), fillOption === 'json_valid' && jsx(JsonEditor$1, {
4500
- validate: true,
4394
+ })), fillOption === 'json_valid' && jsx(ControlAceEditor, {
4501
4395
  name: name,
4502
- ref: ref,
4503
- useParsedValue: true
4504
- }), 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, {
4505
4404
  property: property,
4506
4405
  name: name,
4507
4406
  useExpression: useExpression,
@@ -5662,29 +5561,25 @@ const PropertyValueComponent = ({
5662
5561
  padding: '4px'
5663
5562
  }
5664
5563
  }, {
5665
- children: value === null ? 'null' : value === null || value === void 0 ? void 0 : value.toString()
5564
+ children: value === null ? 'null' : value.toString()
5666
5565
  }));
5667
- if (isExpression(data)) {
5668
- return defaultRender(data);
5669
- } else {
5670
- switch (property.propertyType) {
5671
- case PropertyType.JSON:
5672
- return jsx(JsonView, {
5673
- value: data
5674
- });
5675
- case PropertyType.ENTITY:
5676
- return jsx(DefinitionValueView, {
5677
- properties: properties,
5678
- data: data
5679
- });
5680
- case PropertyType.ANY:
5681
- // TODO need to prefetch data and show as is
5682
- return typeof data === 'object' ? jsx(JsonView, {
5683
- value: data
5684
- }) : defaultRender(data);
5685
- default:
5686
- return defaultRender(data);
5687
- }
5566
+ switch (property.propertyType) {
5567
+ case PropertyType.JSON:
5568
+ return jsx(JsonView, {
5569
+ value: data
5570
+ });
5571
+ case PropertyType.ENTITY:
5572
+ return jsx(DefinitionValueView, {
5573
+ properties: properties,
5574
+ data: data
5575
+ });
5576
+ case PropertyType.ANY:
5577
+ // TODO need to prefetch data and show as is
5578
+ return typeof data === 'object' ? jsx(JsonView, {
5579
+ value: data
5580
+ }) : defaultRender(data);
5581
+ default:
5582
+ return defaultRender(data);
5688
5583
  }
5689
5584
  };
5690
5585
  const PropertyDataView = ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dartech/arsenal-ui",
3
- "version": "1.3.77",
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;