@bpmn-io/form-js-playground 1.8.4 → 1.8.5

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.
@@ -60350,6 +60350,20 @@
60350
60350
  function clone(data, replacer) {
60351
60351
  return JSON.parse(JSON.stringify(data, replacer));
60352
60352
  }
60353
+ function runRecursively(formField, fn) {
60354
+ const components = formField.components || [];
60355
+ components.forEach((component, _) => {
60356
+ runRecursively(component, fn);
60357
+ });
60358
+ fn(formField);
60359
+ }
60360
+ function wrapObjectKeysWithUnderscores(obj) {
60361
+ const newObj = {};
60362
+ for (const [key, value] of Object.entries(obj)) {
60363
+ newObj[`_${key}_`] = value;
60364
+ }
60365
+ return newObj;
60366
+ }
60353
60367
 
60354
60368
  /**
60355
60369
  * Transform a LocalExpressionContext object into a usable FEEL context.
@@ -60366,25 +60380,24 @@
60366
60380
  return {
60367
60381
  ...specialContextKeys,
60368
60382
  ...data,
60369
- ..._wrapObjectKeysWithUnderscores(specialContextKeys)
60383
+ ...wrapObjectKeysWithUnderscores(specialContextKeys)
60370
60384
  };
60371
60385
  }
60372
- function runRecursively(formField, fn) {
60373
- const components = formField.components || [];
60374
- components.forEach((component, index) => {
60375
- runRecursively(component, fn);
60376
- });
60377
- fn(formField);
60378
- }
60379
-
60380
- // helpers //////////////////////
60381
60386
 
60382
- function _wrapObjectKeysWithUnderscores(obj) {
60383
- const newObj = {};
60384
- for (const [key, value] of Object.entries(obj)) {
60385
- newObj[`_${key}_`] = value;
60387
+ /**
60388
+ * Evaluate a string based on the expressionLanguage and context information.
60389
+ * If the string is not an expression, it is returned as is.
60390
+ *
60391
+ * @param {any} expressionLanguage - The expression language to use.
60392
+ * @param {string} value - The string to evaluate.
60393
+ * @param {Object} expressionContextInfo - The context information to use.
60394
+ * @returns {any} - Evaluated value or the original value if not an expression.
60395
+ */
60396
+ function runExpressionEvaluation(expressionLanguage, value, expressionContextInfo) {
60397
+ if (expressionLanguage && expressionLanguage.isExpression(value)) {
60398
+ return expressionLanguage.evaluate(value, buildExpressionContext(expressionContextInfo));
60386
60399
  }
60387
- return newObj;
60400
+ return value;
60388
60401
  }
60389
60402
 
60390
60403
  /**
@@ -60517,12 +60530,7 @@
60517
60530
  function useExpressionEvaluation(value) {
60518
60531
  const expressionLanguage = useService$2('expressionLanguage');
60519
60532
  const expressionContextInfo = F$1(LocalExpressionContext);
60520
- return d(() => {
60521
- if (expressionLanguage && expressionLanguage.isExpression(value)) {
60522
- return expressionLanguage.evaluate(value, buildExpressionContext(expressionContextInfo));
60523
- }
60524
- return value;
60525
- }, [expressionLanguage, expressionContextInfo, value]);
60533
+ return d(() => runExpressionEvaluation(expressionLanguage, value, expressionContextInfo), [expressionLanguage, expressionContextInfo, value]);
60526
60534
  }
60527
60535
 
60528
60536
  /**
@@ -61387,7 +61395,6 @@
61387
61395
  target
61388
61396
  }) => {
61389
61397
  props.onChange({
61390
- field,
61391
61398
  value: target.checked
61392
61399
  });
61393
61400
  };
@@ -61465,7 +61472,6 @@
61465
61472
  const toggleCheckbox = toggledValue => {
61466
61473
  const newValues = hasEqualValue(toggledValue, values) ? values.filter(value => !isEqual$1(value, toggledValue)) : [...values, toggledValue];
61467
61474
  props.onChange({
61468
- field,
61469
61475
  value: newValues
61470
61476
  });
61471
61477
  };
@@ -61552,7 +61558,7 @@
61552
61558
  const {
61553
61559
  field,
61554
61560
  indexes,
61555
- onChange
61561
+ onChange: _onChange
61556
61562
  } = props;
61557
61563
  const formFields = useService$2('formFields'),
61558
61564
  viewerCommands = useService$2('viewerCommands', false),
@@ -61594,21 +61600,22 @@
61594
61600
  // add precedence: global readonly > form field disabled
61595
61601
  const disabled = !properties.readOnly && (properties.disabled || field.disabled || false);
61596
61602
  const hidden = useCondition(field.conditional && field.conditional.hide || null);
61603
+ const fieldInstance = d(() => ({
61604
+ id: field.id,
61605
+ expressionContextInfo: localExpressionContext,
61606
+ valuePath,
61607
+ indexes
61608
+ }), [field.id, valuePath, localExpressionContext, indexes]);
61597
61609
 
61598
61610
  // register form field instance
61599
61611
  y(() => {
61600
61612
  if (formFieldInstanceRegistry && !hidden) {
61601
- const instanceId = formFieldInstanceRegistry.add({
61602
- id: field.id,
61603
- expressionContextInfo: localExpressionContext,
61604
- valuePath,
61605
- indexes
61606
- });
61613
+ const instanceId = formFieldInstanceRegistry.add(fieldInstance);
61607
61614
  return () => {
61608
61615
  formFieldInstanceRegistry.remove(instanceId);
61609
61616
  };
61610
61617
  }
61611
- }, [formFieldInstanceRegistry, field.id, localExpressionContext, valuePath, indexes, hidden]);
61618
+ }, [fieldInstance, formFieldInstanceRegistry, hidden]);
61612
61619
 
61613
61620
  // ensures the initial validation behavior can be re-triggered upon form reset
61614
61621
  y(() => {
@@ -61629,34 +61636,33 @@
61629
61636
  const hasInitialValue = initialValue && !isEqual$1(initialValue, []);
61630
61637
  if (initialValidationTrigger && hasInitialValue) {
61631
61638
  setInitialValidationTrigger(false);
61632
- viewerCommands.updateFieldValidation(field, initialValue, indexes);
61639
+ viewerCommands.updateFieldInstanceValidation(fieldInstance, initialValue);
61633
61640
  }
61634
- }, [viewerCommands, field, initialValue, initialValidationTrigger, indexes]);
61641
+ }, [fieldInstance, initialValidationTrigger, initialValue, viewerCommands]);
61635
61642
  const onBlur = A$1(() => {
61636
61643
  const value = get$1(data, valuePath);
61637
61644
  if (initialValidationTrigger) {
61638
61645
  setInitialValidationTrigger(false);
61639
- viewerCommands.updateFieldValidation(field, value, indexes);
61646
+ viewerCommands.updateFieldInstanceValidation(fieldInstance, value);
61640
61647
  }
61641
61648
  eventBus.fire('formField.blur', {
61642
61649
  formField: field
61643
61650
  });
61644
- }, [eventBus, field, indexes, viewerCommands, initialValidationTrigger, data, valuePath]);
61651
+ }, [data, eventBus, field, fieldInstance, initialValidationTrigger, valuePath, viewerCommands]);
61645
61652
  const onFocus = A$1(() => {
61646
61653
  eventBus.fire('formField.focus', {
61647
61654
  formField: field
61648
61655
  });
61649
61656
  }, [eventBus, field]);
61650
- const onChangeIndexed = A$1(update => {
61651
- // any data change will trigger validation
61657
+ const onChange = A$1(update => {
61652
61658
  setInitialValidationTrigger(false);
61653
-
61654
- // add indexes of the keyed field to the update, if any
61655
- onChange(fieldConfig.keyed ? {
61656
- ...update,
61657
- indexes
61658
- } : update);
61659
- }, [onChange, fieldConfig.keyed, indexes]);
61659
+ _onChange({
61660
+ field,
61661
+ indexes,
61662
+ fieldInstance,
61663
+ ...update
61664
+ });
61665
+ }, [_onChange, field, fieldInstance, indexes]);
61660
61666
  if (hidden) {
61661
61667
  return e(Hidden, {
61662
61668
  field: field
@@ -61669,11 +61675,12 @@
61669
61675
  disabled: disabled,
61670
61676
  errors: fieldErrors,
61671
61677
  domId: domId,
61672
- onChange: disabled || readonly ? noop$1$1 : onChangeIndexed,
61678
+ onChange: disabled || readonly ? noop$1$1 : onChange,
61673
61679
  onBlur: disabled || readonly ? noop$1$1 : onBlur,
61674
61680
  onFocus: disabled || readonly ? noop$1$1 : onFocus,
61675
61681
  readonly: readonly,
61676
- value: value
61682
+ value: value,
61683
+ fieldInstance: fieldInstance
61677
61684
  });
61678
61685
  if (fieldConfig.escapeGridRender) {
61679
61686
  return formFieldElement;
@@ -63795,7 +63802,6 @@
63795
63802
  } = validate;
63796
63803
  const onChange = v => {
63797
63804
  props.onChange({
63798
- field,
63799
63805
  value: v
63800
63806
  });
63801
63807
  };
@@ -63954,10 +63960,9 @@
63954
63960
  const setValue = A$1(option => {
63955
63961
  setFilter(option && option.label || '');
63956
63962
  props.onChange({
63957
- value: option && option.value || null,
63958
- field
63963
+ value: option && option.value || null
63959
63964
  });
63960
- }, [field, props]);
63965
+ }, [props]);
63961
63966
  const displayState = d(() => {
63962
63967
  const ds = {};
63963
63968
  ds.componentReady = !disabled && !readonly && loadState === LOAD_STATES.LOADED;
@@ -64102,10 +64107,9 @@
64102
64107
  const valueLabel = d(() => value && getLabelCorrelation(value), [value, getLabelCorrelation]);
64103
64108
  const setValue = A$1(option => {
64104
64109
  props.onChange({
64105
- value: option && option.value || null,
64106
- field
64110
+ value: option && option.value || null
64107
64111
  });
64108
- }, [field, props]);
64112
+ }, [props]);
64109
64113
  const displayState = d(() => {
64110
64114
  const ds = {};
64111
64115
  ds.componentReady = !disabled && !readonly && loadState === LOAD_STATES.LOADED;
@@ -64437,15 +64441,13 @@
64437
64441
  return;
64438
64442
  }
64439
64443
  props.onChange({
64440
- value: [...values, value],
64441
- field
64444
+ value: [...values, value]
64442
64445
  });
64443
64446
  };
64444
64447
  const deselectValue = value => {
64445
64448
  const newValues = values.filter(v => !isEqual$1(v, value));
64446
64449
  props.onChange({
64447
- value: newValues,
64448
- field
64450
+ value: newValues
64449
64451
  });
64450
64452
  };
64451
64453
  const onInputChange = ({
@@ -64929,7 +64931,6 @@
64929
64931
  target
64930
64932
  }) => {
64931
64933
  props.onChange({
64932
- field,
64933
64934
  value: target.value
64934
64935
  });
64935
64936
  });
@@ -65028,7 +65029,6 @@
65028
65029
  target
65029
65030
  }) => {
65030
65031
  props.onChange({
65031
- field,
65032
65032
  value: target.value
65033
65033
  });
65034
65034
  });
@@ -66534,6 +66534,10 @@
66534
66534
  var commandModule$1 = {
66535
66535
  commandStack: ['type', CommandStack$1]
66536
66536
  };
66537
+
66538
+ /**
66539
+ * @deprecated
66540
+ */
66537
66541
  class UpdateFieldValidationHandler {
66538
66542
  constructor(form, validator) {
66539
66543
  this._form = form;
@@ -66562,6 +66566,37 @@
66562
66566
  }
66563
66567
  }
66564
66568
  UpdateFieldValidationHandler.$inject = ['form', 'validator'];
66569
+ class UpdateFieldInstanceValidationHandler {
66570
+ constructor(form, validator) {
66571
+ this._form = form;
66572
+ this._validator = validator;
66573
+ }
66574
+ execute(context) {
66575
+ const {
66576
+ fieldInstance,
66577
+ value
66578
+ } = context;
66579
+ const {
66580
+ id,
66581
+ indexes
66582
+ } = fieldInstance;
66583
+ const {
66584
+ errors
66585
+ } = this._form._getState();
66586
+ context.oldErrors = clone(errors);
66587
+ const fieldErrors = this._validator.validateFieldInstance(fieldInstance, value);
66588
+ const updatedErrors = set$2(errors, [id, ...Object.values(indexes || {})], fieldErrors.length ? fieldErrors : undefined);
66589
+ this._form._setState({
66590
+ errors: updatedErrors
66591
+ });
66592
+ }
66593
+ revert(context) {
66594
+ this._form._setState({
66595
+ errors: context.oldErrors
66596
+ });
66597
+ }
66598
+ }
66599
+ UpdateFieldInstanceValidationHandler.$inject = ['form', 'validator'];
66565
66600
  class ViewerCommands {
66566
66601
  constructor(commandStack, eventBus) {
66567
66602
  this._commandStack = commandStack;
@@ -66576,9 +66611,14 @@
66576
66611
  }
66577
66612
  getHandlers() {
66578
66613
  return {
66579
- 'formField.validation.update': UpdateFieldValidationHandler
66614
+ 'formField.validation.update': UpdateFieldValidationHandler,
66615
+ 'formFieldInstance.validation.update': UpdateFieldInstanceValidationHandler
66580
66616
  };
66581
66617
  }
66618
+
66619
+ /**
66620
+ * @deprecated
66621
+ */
66582
66622
  updateFieldValidation(field, value, indexes) {
66583
66623
  const context = {
66584
66624
  field,
@@ -66587,6 +66627,13 @@
66587
66627
  };
66588
66628
  this._commandStack.execute('formField.validation.update', context);
66589
66629
  }
66630
+ updateFieldInstanceValidation(fieldInstance, value) {
66631
+ const context = {
66632
+ fieldInstance,
66633
+ value
66634
+ };
66635
+ this._commandStack.execute('formFieldInstance.validation.update', context);
66636
+ }
66590
66637
  }
66591
66638
  ViewerCommands.$inject = ['commandStack', 'eventBus'];
66592
66639
  const ViewerCommandsModule = {
@@ -66818,9 +66865,7 @@
66818
66865
  updatedValues.push(newItem);
66819
66866
  shouldScroll.current = true;
66820
66867
  props.onChange({
66821
- field: repeaterField,
66822
- value: updatedValues,
66823
- indexes
66868
+ value: updatedValues
66824
66869
  });
66825
66870
  setSharedRepeatState(state => ({
66826
66871
  ...state,
@@ -67476,11 +67521,18 @@
67476
67521
  const PHONE_PATTERN = /(\+|00)(297|93|244|1264|358|355|376|971|54|374|1684|1268|61|43|994|257|32|229|226|880|359|973|1242|387|590|375|501|1441|591|55|1246|673|975|267|236|1|61|41|56|86|225|237|243|242|682|57|269|238|506|53|5999|61|1345|357|420|49|253|1767|45|1809|1829|1849|213|593|20|291|212|34|372|251|358|679|500|33|298|691|241|44|995|44|233|350|224|590|220|245|240|30|1473|299|502|594|1671|592|852|504|385|509|36|62|44|91|246|353|98|964|354|972|39|1876|44|962|81|76|77|254|996|855|686|1869|82|383|965|856|961|231|218|1758|423|94|266|370|352|371|853|590|212|377|373|261|960|52|692|389|223|356|95|382|976|1670|258|222|1664|596|230|265|60|262|264|687|227|672|234|505|683|31|47|977|674|64|968|92|507|64|51|63|680|675|48|1787|1939|850|351|595|970|689|974|262|40|7|250|966|249|221|65|500|4779|677|232|503|378|252|508|381|211|239|597|421|386|46|268|1721|248|963|1649|235|228|66|992|690|993|670|676|1868|216|90|688|886|255|256|380|598|1|998|3906698|379|1784|58|1284|1340|84|678|681|685|967|27|260|263)(9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1)\d{4,20}$/;
67477
67522
  const VALIDATE_FEEL_PROPERTIES = ['min', 'max', 'minLength', 'maxLength'];
67478
67523
  class Validator {
67479
- constructor(expressionLanguage, conditionChecker, form) {
67524
+ constructor(expressionLanguage, conditionChecker, form, formFieldRegistry) {
67480
67525
  this._expressionLanguage = expressionLanguage;
67481
67526
  this._conditionChecker = conditionChecker;
67482
67527
  this._form = form;
67528
+ this._formFieldRegistry = formFieldRegistry;
67483
67529
  }
67530
+
67531
+ /**
67532
+ * Validate against a field definition, does not support proper expression evaluation.
67533
+ *
67534
+ * @deprecated use validateFieldInstance instead
67535
+ */
67484
67536
  validateField(field, value) {
67485
67537
  const {
67486
67538
  type,
@@ -67488,72 +67540,121 @@
67488
67540
  } = field;
67489
67541
  let errors = [];
67490
67542
  if (type === 'number') {
67491
- const {
67492
- decimalDigits,
67493
- increment
67494
- } = field;
67495
- if (value === 'NaN') {
67496
- errors = [...errors, 'Value is not a number.'];
67497
- } else if (value) {
67498
- if (decimalDigits >= 0 && countDecimals$1(value) > decimalDigits) {
67499
- errors = [...errors, 'Value is expected to ' + (decimalDigits === 0 ? 'be an integer' : `have at most ${decimalDigits} decimal digit${decimalDigits > 1 ? 's' : ''}`) + '.'];
67500
- }
67501
- if (increment) {
67502
- const bigValue = Big$1(value);
67503
- const bigIncrement = Big$1(increment);
67504
- const offset = bigValue.mod(bigIncrement);
67505
- if (offset.cmp(0) !== 0) {
67506
- const previousValue = bigValue.minus(offset);
67507
- const nextValue = previousValue.plus(bigIncrement);
67508
- errors = [...errors, `Please select a valid value, the two nearest valid values are ${previousValue} and ${nextValue}.`];
67509
- }
67510
- }
67511
- }
67543
+ errors = [...errors, ...runNumberValidation(field, value)];
67512
67544
  }
67513
67545
  if (!validate) {
67514
67546
  return errors;
67515
67547
  }
67516
- const evaluatedValidation = evaluateFEELValues(validate, this._expressionLanguage, this._conditionChecker, this._form);
67517
- if (evaluatedValidation.pattern && value && !new RegExp(evaluatedValidation.pattern).test(value)) {
67518
- errors = [...errors, `Field must match pattern ${evaluatedValidation.pattern}.`];
67519
- }
67520
- if (evaluatedValidation.required) {
67521
- const isUncheckedCheckbox = type === 'checkbox' && value === false;
67522
- const isUnsetValue = isNil$1(value) || value === '';
67523
- const isEmptyMultiselect = Array.isArray(value) && value.length === 0;
67524
- if (isUncheckedCheckbox || isUnsetValue || isEmptyMultiselect) {
67525
- errors = [...errors, 'Field is required.'];
67526
- }
67527
- }
67528
- if ('min' in evaluatedValidation && (value || value === 0) && value < evaluatedValidation.min) {
67529
- errors = [...errors, `Field must have minimum value of ${evaluatedValidation.min}.`];
67530
- }
67531
- if ('max' in evaluatedValidation && (value || value === 0) && value > evaluatedValidation.max) {
67532
- errors = [...errors, `Field must have maximum value of ${evaluatedValidation.max}.`];
67533
- }
67534
- if ('minLength' in evaluatedValidation && value && value.trim().length < evaluatedValidation.minLength) {
67535
- errors = [...errors, `Field must have minimum length of ${evaluatedValidation.minLength}.`];
67536
- }
67537
- if ('maxLength' in evaluatedValidation && value && value.trim().length > evaluatedValidation.maxLength) {
67538
- errors = [...errors, `Field must have maximum length of ${evaluatedValidation.maxLength}.`];
67539
- }
67540
- if ('validationType' in evaluatedValidation && value && evaluatedValidation.validationType === 'phone' && !PHONE_PATTERN.test(value)) {
67541
- errors = [...errors, 'Field must be a valid international phone number. (e.g. +4930664040900)'];
67548
+ const evaluatedValidation = oldEvaluateFEELValues(validate, this._expressionLanguage, this._conditionChecker, this._form);
67549
+ errors = [...errors, ...runPresetValidation(field, evaluatedValidation, value)];
67550
+ return errors;
67551
+ }
67552
+
67553
+ /**
67554
+ * Validate a field instance.
67555
+ *
67556
+ * @param {Object} fieldInstance
67557
+ * @param {string} value
67558
+ *
67559
+ * @returns {Array<string>}
67560
+ */
67561
+ validateFieldInstance(fieldInstance, value) {
67562
+ const {
67563
+ id,
67564
+ expressionContextInfo
67565
+ } = fieldInstance;
67566
+ const field = this._formFieldRegistry.get(id);
67567
+ const {
67568
+ type,
67569
+ validate
67570
+ } = field;
67571
+ let errors = [];
67572
+ if (type === 'number') {
67573
+ errors = [...errors, ...runNumberValidation(field, value)];
67542
67574
  }
67543
- if ('validationType' in evaluatedValidation && value && evaluatedValidation.validationType === 'email' && !EMAIL_PATTERN.test(value)) {
67544
- errors = [...errors, 'Field must be a valid email.'];
67575
+ if (!validate) {
67576
+ return errors;
67545
67577
  }
67578
+ const evaluatedValidation = evaluateFEELValues(validate, this._expressionLanguage, expressionContextInfo);
67579
+ errors = [...errors, ...runPresetValidation(field, evaluatedValidation, value)];
67546
67580
  return errors;
67547
67581
  }
67548
67582
  }
67549
- Validator.$inject = ['expressionLanguage', 'conditionChecker', 'form'];
67583
+ Validator.$inject = ['expressionLanguage', 'conditionChecker', 'form', 'formFieldRegistry'];
67550
67584
 
67551
67585
  // helpers //////////
67552
67586
 
67553
- /**
67554
- * Helper function to evaluate optional FEEL validation values.
67555
- */
67556
- function evaluateFEELValues(validate, expressionLanguage, conditionChecker, form) {
67587
+ function runNumberValidation(field, value) {
67588
+ const {
67589
+ decimalDigits,
67590
+ increment
67591
+ } = field;
67592
+ const errors = [];
67593
+ if (value === 'NaN') {
67594
+ errors.push('Value is not a number.');
67595
+ } else if (value) {
67596
+ if (decimalDigits >= 0 && countDecimals$1(value) > decimalDigits) {
67597
+ errors.push('Value is expected to ' + (decimalDigits === 0 ? 'be an integer' : `have at most ${decimalDigits} decimal digit${decimalDigits > 1 ? 's' : ''}`) + '.');
67598
+ }
67599
+ if (increment) {
67600
+ const bigValue = Big$1(value);
67601
+ const bigIncrement = Big$1(increment);
67602
+ const offset = bigValue.mod(bigIncrement);
67603
+ if (offset.cmp(0) !== 0) {
67604
+ const previousValue = bigValue.minus(offset);
67605
+ const nextValue = previousValue.plus(bigIncrement);
67606
+ errors.push(`Please select a valid value, the two nearest valid values are ${previousValue} and ${nextValue}.`);
67607
+ }
67608
+ }
67609
+ }
67610
+ return errors;
67611
+ }
67612
+ function runPresetValidation(field, validation, value) {
67613
+ const errors = [];
67614
+ if (validation.pattern && value && !new RegExp(validation.pattern).test(value)) {
67615
+ errors.push(`Field must match pattern ${validation.pattern}.`);
67616
+ }
67617
+ if (validation.required) {
67618
+ const isUncheckedCheckbox = field.type === 'checkbox' && value === false;
67619
+ const isUnsetValue = isNil$1(value) || value === '';
67620
+ const isEmptyMultiselect = Array.isArray(value) && value.length === 0;
67621
+ if (isUncheckedCheckbox || isUnsetValue || isEmptyMultiselect) {
67622
+ errors.push('Field is required.');
67623
+ }
67624
+ }
67625
+ if ('min' in validation && (value || value === 0) && value < validation.min) {
67626
+ errors.push(`Field must have minimum value of ${validation.min}.`);
67627
+ }
67628
+ if ('max' in validation && (value || value === 0) && value > validation.max) {
67629
+ errors.push(`Field must have maximum value of ${validation.max}.`);
67630
+ }
67631
+ if ('minLength' in validation && value && value.trim().length < validation.minLength) {
67632
+ errors.push(`Field must have minimum length of ${validation.minLength}.`);
67633
+ }
67634
+ if ('maxLength' in validation && value && value.trim().length > validation.maxLength) {
67635
+ errors.push(`Field must have maximum length of ${validation.maxLength}.`);
67636
+ }
67637
+ if ('validationType' in validation && value && validation.validationType === 'phone' && !PHONE_PATTERN.test(value)) {
67638
+ errors.push('Field must be a valid international phone number. (e.g. +4930664040900)');
67639
+ }
67640
+ if ('validationType' in validation && value && validation.validationType === 'email' && !EMAIL_PATTERN.test(value)) {
67641
+ errors.push('Field must be a valid email.');
67642
+ }
67643
+ return errors;
67644
+ }
67645
+ function evaluateFEELValues(validate, expressionLanguage, expressionContextInfo) {
67646
+ const evaluatedValidate = {
67647
+ ...validate
67648
+ };
67649
+ VALIDATE_FEEL_PROPERTIES.forEach(property => {
67650
+ const path = property.split('.');
67651
+ const value = get$1(evaluatedValidate, path);
67652
+ const evaluatedValue = runExpressionEvaluation(expressionLanguage, value, expressionContextInfo);
67653
+ set$2(evaluatedValidate, path, evaluatedValue === null ? undefined : evaluatedValue);
67654
+ });
67655
+ return evaluatedValidate;
67656
+ }
67657
+ function oldEvaluateFEELValues(validate, expressionLanguage, conditionChecker, form) {
67557
67658
  const evaluatedValidate = {
67558
67659
  ...validate
67559
67660
  };
@@ -68294,9 +68395,13 @@
68294
68395
  return this.getAll().filter(({
68295
68396
  id
68296
68397
  }) => {
68398
+ const formFieldDefinition = this._formFieldRegistry.get(id);
68399
+ if (!formFieldDefinition) {
68400
+ return false;
68401
+ }
68297
68402
  const {
68298
68403
  type
68299
- } = this._formFieldRegistry.get(id);
68404
+ } = formFieldDefinition;
68300
68405
  const {
68301
68406
  config
68302
68407
  } = this._formFields.get(type);
@@ -68553,11 +68658,12 @@
68553
68658
  } = this._getState();
68554
68659
  const errors = {};
68555
68660
  const getErrorPath = (id, indexes) => [id, ...Object.values(indexes || {})];
68556
- formFieldInstanceRegistry.getAllKeyed().forEach(({
68557
- id,
68558
- valuePath,
68559
- indexes
68560
- }) => {
68661
+ formFieldInstanceRegistry.getAllKeyed().forEach(fieldInstance => {
68662
+ const {
68663
+ id,
68664
+ valuePath,
68665
+ indexes
68666
+ } = fieldInstance;
68561
68667
  const field = formFieldRegistry.get(id);
68562
68668
 
68563
68669
  // (1) Skip disabled fields
@@ -68565,9 +68671,9 @@
68565
68671
  return;
68566
68672
  }
68567
68673
 
68568
- // (2) Validate the field
68674
+ // (2) Validate the field instance
68569
68675
  const value = get$1(data, valuePath);
68570
- const fieldErrors = validator.validateField(field, value);
68676
+ const fieldErrors = validator.validateFieldInstance(fieldInstance, value);
68571
68677
  if (fieldErrors.length) {
68572
68678
  set$2(errors, getErrorPath(field.id, indexes), fieldErrors);
68573
68679
  }
@@ -68672,26 +68778,26 @@
68672
68778
  /**
68673
68779
  * @internal
68674
68780
  *
68675
- * @param { { field: any, indexes: object, value: any } } update
68781
+ * @param { { fieldInstance: any, value: any } } update
68676
68782
  */
68677
68783
  _update(update) {
68678
68784
  const {
68679
- field,
68680
- indexes,
68785
+ fieldInstance,
68681
68786
  value
68682
68787
  } = update;
68788
+ const {
68789
+ id,
68790
+ valuePath,
68791
+ indexes
68792
+ } = fieldInstance;
68683
68793
  const {
68684
68794
  data,
68685
68795
  errors
68686
68796
  } = this._getState();
68687
- const validator = this.get('validator'),
68688
- pathRegistry = this.get('pathRegistry');
68689
- const fieldErrors = validator.validateField(field, value);
68690
- const valuePath = pathRegistry.getValuePath(field, {
68691
- indexes
68692
- });
68797
+ const validator = this.get('validator');
68798
+ const fieldErrors = validator.validateFieldInstance(fieldInstance, value);
68693
68799
  set$2(data, valuePath, value);
68694
- set$2(errors, [field.id, ...Object.values(indexes || {})], fieldErrors.length ? fieldErrors : undefined);
68800
+ set$2(errors, [id, ...Object.values(indexes || {})], fieldErrors.length ? fieldErrors : undefined);
68695
68801
  this._emit('field.updated', update);
68696
68802
  this._setState({
68697
68803
  data: clone(data),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bpmn-io/form-js-playground",
3
- "version": "1.8.4",
3
+ "version": "1.8.5",
4
4
  "description": "A form-js playground",
5
5
  "files": [
6
6
  "dist"
@@ -45,8 +45,8 @@
45
45
  "url": "https://github.com/bpmn-io"
46
46
  },
47
47
  "dependencies": {
48
- "@bpmn-io/form-js-editor": "^1.8.4",
49
- "@bpmn-io/form-js-viewer": "^1.8.4",
48
+ "@bpmn-io/form-js-editor": "^1.8.5",
49
+ "@bpmn-io/form-js-viewer": "^1.8.5",
50
50
  "@codemirror/autocomplete": "^6.12.0",
51
51
  "@codemirror/commands": "^6.1.2",
52
52
  "@codemirror/lang-json": "^6.0.1",
@@ -71,5 +71,5 @@
71
71
  "rollup-plugin-css-only": "^4.0.0",
72
72
  "style-loader": "^4.0.0"
73
73
  },
74
- "gitHead": "c9a4761209756fce5711053526023f42bf3b7b54"
74
+ "gitHead": "cc2823143bb6974e9c1355e4af494164122fd829"
75
75
  }