@evoke-platform/ui-components 1.0.0-dev.243 → 1.0.0-dev.244

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.
@@ -1,4 +1,5 @@
1
1
  import { ReactComponent } from '@formio/react';
2
+ import Handlebars from 'handlebars';
2
3
  import { isArray, isEmpty, isNil, uniq } from 'lodash';
3
4
  import { DateTime } from 'luxon';
4
5
  import React from 'react';
@@ -9,20 +10,20 @@ import { isPropertyVisible } from '../utils';
9
10
  function isAddressProperties(key) {
10
11
  return /\.line1|\.line2|\.city|\.county|\.state|\.zipCode$/.test(key);
11
12
  }
12
- function addDays(addend1, addend2) {
13
+ Handlebars.registerHelper('addDays', function (addend1, addend2) {
13
14
  const dateAddend1 = DateTime.fromISO(addend1);
14
15
  if (dateAddend1.isValid) {
15
16
  return dateAddend1.plus({ days: addend2 }).toISODate();
16
17
  }
17
18
  return undefined;
18
- }
19
- function subDays(minuend, subtrahend) {
19
+ });
20
+ Handlebars.registerHelper('subDays', function (minuend, subtrahend) {
20
21
  const dateMinuend = DateTime.fromISO(minuend);
21
22
  if (dateMinuend.isValid) {
22
23
  return dateMinuend.minus({ days: subtrahend }).toISODate();
23
24
  }
24
25
  return undefined;
25
- }
26
+ });
26
27
  export class FormFieldComponent extends ReactComponent {
27
28
  /**
28
29
  * Called when the component has been instantiated. This is useful to define
@@ -344,63 +345,29 @@ export class FormFieldComponent extends ReactComponent {
344
345
  else {
345
346
  delete this.errorDetails['regexes'];
346
347
  }
347
- const evaluateDateValidation = (dateValidation) => {
348
+ if (this.component.validate.minDate || this.component.validate.maxDate) {
348
349
  const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
349
- const exactDateRegex = /^{{(?<inputProperty>input\.[a-zA-Z][a-zA-Z0-9_]*|__today__)}}$/;
350
- const relativeDateRegex = /^{{(?<operation>addDays|subDays) (?<operand1>input\.[a-zA-Z][a-zA-Z0-9_]*|__today__) (?<operand2>[0-9]+)}}$/;
351
- // If the date validation isn't a literal date, evaluate it
352
- if (dateValidation && !dateRegex.test(dateValidation)) {
350
+ const data = {
351
+ input: { ...this.root.data },
352
+ __today__: DateTime.now().toISODate(),
353
+ };
354
+ let { minDate, maxDate } = validate;
355
+ if (minDate && !dateRegex.test(minDate)) {
353
356
  try {
354
- const today = DateTime.now().toISODate();
355
- if (exactDateRegex.test(dateValidation)) {
356
- const { groups = {} } = exactDateRegex.exec(dateValidation) ?? {};
357
- const { inputProperty } = groups;
358
- if (inputProperty === '__today__') {
359
- return today;
360
- }
361
- else if (inputProperty.split('.').length > 1) {
362
- const propertyId = inputProperty.split('.')[1];
363
- if (propertyId in this.root.data) {
364
- return this.root.data[propertyId];
365
- }
366
- }
367
- }
368
- else if (relativeDateRegex.test(dateValidation)) {
369
- const { groups = {} } = relativeDateRegex.exec(dateValidation) ?? {};
370
- // eslint-disable-next-line prefer-const
371
- let { operation, operand1, operand2 } = groups;
372
- if (operation && operand1 && operand2) {
373
- if (operand1 === '__today__') {
374
- operand1 = today;
375
- }
376
- else if (operand1.split('.').length > 1) {
377
- const propertyId = operand1.split('.')[1];
378
- if (propertyId in this.root.data) {
379
- operand1 = this.root.data[propertyId];
380
- }
381
- }
382
- else {
383
- throw `Invalid operand: ${operand1}`;
384
- }
385
- if (operation === 'addDays') {
386
- return addDays(operand1, parseInt(operand2));
387
- }
388
- else {
389
- return subDays(operand1, parseInt(operand2));
390
- }
391
- }
392
- }
393
- throw `Invalid date validation: ${dateValidation}`;
357
+ minDate = Handlebars.compile(minDate)(data);
358
+ }
359
+ catch (err) {
360
+ console.log(err);
361
+ }
362
+ }
363
+ if (maxDate && !dateRegex.test(maxDate)) {
364
+ try {
365
+ maxDate = Handlebars.compile(maxDate)(data);
394
366
  }
395
367
  catch (err) {
396
368
  console.log(err);
397
- return undefined;
398
369
  }
399
370
  }
400
- };
401
- if (this.component.validate.minDate || this.component.validate.maxDate) {
402
- const minDate = validate.minDate ? evaluateDateValidation(validate.minDate) : undefined;
403
- const maxDate = validate.maxDate ? evaluateDateValidation(validate.maxDate) : undefined;
404
371
  if ((minDate && value < minDate) || (maxDate && value > maxDate)) {
405
372
  this.errorDetails['date'] = validate.customMessage;
406
373
  }
@@ -456,11 +423,7 @@ export class FormFieldComponent extends ReactComponent {
456
423
  !this.root.customErrors.some((err) => err.message === error)) {
457
424
  this.root.customErrors = [
458
425
  ...this.root.customErrors,
459
- {
460
- component: this.component,
461
- message: error,
462
- formattedKeyOrPath: this.component.key,
463
- },
426
+ { component: this.component, message: error, formattedKeyOrPath: this.component.key },
464
427
  ];
465
428
  }
466
429
  });
@@ -1,5 +1,5 @@
1
1
  import cleanDeep from 'clean-deep';
2
- import Handlebars from 'kbn-handlebars';
2
+ import Handlebars from 'handlebars';
3
3
  import { cloneDeep, debounce, isEmpty, isNil } from 'lodash';
4
4
  import React, { useCallback, useEffect, useState } from 'react';
5
5
  import { Close } from '../../../../../icons';
@@ -132,7 +132,7 @@ export const ObjectPropertyInput = (props) => {
132
132
  setOpenCreateDialog(false);
133
133
  };
134
134
  const compileExpression = (expression, instance) => {
135
- const template = Handlebars.compileAST(expression);
135
+ const template = Handlebars.compile(expression);
136
136
  return instance ? template(instance) : undefined;
137
137
  };
138
138
  const navigationSlug = defaultPages && property.objectId && defaultPages[property.objectId];
@@ -1,4 +1,4 @@
1
- import Handlebars from 'kbn-handlebars';
1
+ import Handlebars from 'handlebars';
2
2
  import { difference, isEmpty, isObject } from 'lodash';
3
3
  import React, { useEffect, useState } from 'react';
4
4
  import { FormField } from '../../../..';
@@ -60,7 +60,7 @@ export const DropdownRepeatableFieldInput = (props) => {
60
60
  }
61
61
  };
62
62
  const compileExpression = (instance, expression) => {
63
- const template = Handlebars.compileAST(expression);
63
+ const template = Handlebars.compile(expression);
64
64
  return template(instance);
65
65
  };
66
66
  return (React.createElement(React.Fragment, null, !readOnly ? (property && (React.createElement(React.Fragment, null,
@@ -87,8 +87,5 @@ export const DropdownRepeatableFieldInput = (props) => {
87
87
  } })),
88
88
  loading: loading,
89
89
  } }),
90
- React.createElement(Snackbar, { open: snackbarError.showAlert, handleClose: () => setSnackbarError({
91
- isError: snackbarError.isError,
92
- showAlert: false,
93
- }), message: snackbarError.message, error: snackbarError.isError })))) : (React.createElement(Typography, null, selectedOptions && selectedOptions.map((option) => option.label).join(', ')))));
90
+ React.createElement(Snackbar, { open: snackbarError.showAlert, handleClose: () => setSnackbarError({ isError: snackbarError.isError, showAlert: false }), message: snackbarError.message, error: snackbarError.isError })))) : (React.createElement(Typography, null, selectedOptions && selectedOptions.map((option) => option.label).join(', ')))));
94
91
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evoke-platform/ui-components",
3
- "version": "1.0.0-dev.243",
3
+ "version": "1.0.0-dev.244",
4
4
  "description": "",
5
5
  "main": "dist/published/index.js",
6
6
  "module": "dist/published/index.js",
@@ -114,8 +114,8 @@
114
114
  "eslint-plugin-no-inline-styles": "^1.0.5",
115
115
  "flat": "^6.0.1",
116
116
  "formiojs": "^4.15.0-rc.23",
117
+ "handlebars": "^4.7.8",
117
118
  "html-react-parser": "^5.1.18",
118
- "kbn-handlebars": "^1.0.0",
119
119
  "luxon": "^2.5.2",
120
120
  "nanoid": "^5.0.8",
121
121
  "nanoid-dictionary": "^4.3.0",