@bpmn-io/form-js-viewer 1.21.1 → 1.21.3

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/dist/index.cjs CHANGED
@@ -863,6 +863,50 @@ function runRecursively(formField, fn) {
863
863
  });
864
864
  fn(formField);
865
865
  }
866
+
867
+ /**
868
+ * Returns a copy of `target` with the value at `path` removed, pruning any
869
+ * ancestor that becomes empty. Pure: the input is not mutated and untouched
870
+ * sibling branches keep their original references (path-cloning).
871
+ *
872
+ * Pruning rules:
873
+ * - An object ancestor is removed when it has no own keys left.
874
+ * - An array ancestor is removed when every entry is nullish. Arrays are
875
+ * never compacted; `delete` leaves a sparse hole so sibling indexes stay
876
+ * stable.
877
+ *
878
+ * @template T
879
+ * @param {T} target
880
+ * @param {Array<string|number>} path
881
+ * @returns {T}
882
+ */
883
+ function pruneAt(target, path) {
884
+ if (!path.length) {
885
+ return target;
886
+ }
887
+ const cloneContainer = c => Array.isArray(c) ? c.slice() : {
888
+ ...c
889
+ };
890
+ const clones = [cloneContainer(target)];
891
+ for (let i = 0; i < path.length - 1; i++) {
892
+ const next = clones[i][path[i]];
893
+ if (next == null || typeof next !== 'object') {
894
+ return target;
895
+ }
896
+ const cloned = cloneContainer(next);
897
+ clones[i][path[i]] = cloned;
898
+ clones.push(cloned);
899
+ }
900
+ delete clones[clones.length - 1][path[path.length - 1]];
901
+ for (let i = clones.length - 1; i > 0; i--) {
902
+ if (Object.values(clones[i]).every(v => v == null)) {
903
+ delete clones[i - 1][path[i - 1]];
904
+ } else {
905
+ break;
906
+ }
907
+ }
908
+ return clones[0];
909
+ }
866
910
  function wrapObjectKeysWithUnderscores(obj) {
867
911
  const newObj = {};
868
912
  for (const [key, value] of Object.entries(obj)) {
@@ -7474,9 +7518,16 @@ class UpdateFieldInstanceValidationHandler {
7474
7518
  } = this._form._getState();
7475
7519
  context.oldErrors = clone(errors);
7476
7520
  const fieldErrors = this._validator.validateFieldInstance(fieldInstance, value);
7477
- const updatedErrors = minDash.set(errors, [id, ...Object.values(indexes || {})], fieldErrors.length ? fieldErrors : undefined);
7521
+ const errorPath = [id, ...Object.values(indexes || {})];
7522
+ let nextErrors;
7523
+ if (fieldErrors.length) {
7524
+ minDash.set(errors, errorPath, fieldErrors);
7525
+ nextErrors = errors;
7526
+ } else {
7527
+ nextErrors = pruneAt(errors, errorPath);
7528
+ }
7478
7529
  this._form._setState({
7479
- errors: updatedErrors
7530
+ errors: nextErrors
7480
7531
  });
7481
7532
  }
7482
7533
  revert(context) {
@@ -8499,11 +8550,23 @@ function runPresetValidation(field, validation, value) {
8499
8550
  errors.push('Field is required.');
8500
8551
  }
8501
8552
  }
8502
- if ('min' in validation && (value || value === 0) && value < validation.min) {
8503
- errors.push(`Field must have minimum value of ${validation.min}.`);
8553
+ if ('min' in validation && (value || value === 0)) {
8554
+ try {
8555
+ if (Big(value).lt(Big(validation.min))) {
8556
+ errors.push(`Field must have minimum value of ${validation.min}.`);
8557
+ }
8558
+ } catch {
8559
+ errors.push('Min validation value is not a valid number.');
8560
+ }
8504
8561
  }
8505
- if ('max' in validation && (value || value === 0) && value > validation.max) {
8506
- errors.push(`Field must have maximum value of ${validation.max}.`);
8562
+ if ('max' in validation && (value || value === 0)) {
8563
+ try {
8564
+ if (Big(value).gt(Big(validation.max))) {
8565
+ errors.push(`Field must have maximum value of ${validation.max}.`);
8566
+ }
8567
+ } catch {
8568
+ errors.push('Max validation value is not a valid number.');
8569
+ }
8507
8570
  }
8508
8571
  if ('minLength' in validation && value && value.trim().length < validation.minLength) {
8509
8572
  errors.push(`Field must have minimum length of ${validation.minLength}.`);
@@ -9825,11 +9888,18 @@ class Form {
9825
9888
  const validator = this.get('validator');
9826
9889
  const fieldErrors = validator.validateFieldInstance(fieldInstance, value);
9827
9890
  minDash.set(data, valuePath, value);
9828
- minDash.set(errors, [id, ...Object.values(indexes || {})], fieldErrors.length ? fieldErrors : undefined);
9891
+ const errorPath = [id, ...Object.values(indexes || {})];
9892
+ let nextErrors;
9893
+ if (fieldErrors.length) {
9894
+ minDash.set(errors, errorPath, fieldErrors);
9895
+ nextErrors = errors;
9896
+ } else {
9897
+ nextErrors = pruneAt(errors, errorPath);
9898
+ }
9829
9899
  this._emit('field.updated', update);
9830
9900
  this._setState({
9831
9901
  data: clone(data),
9832
- errors: clone(errors)
9902
+ errors: clone(nextErrors)
9833
9903
  });
9834
9904
  }
9835
9905
 
@@ -10095,6 +10165,7 @@ exports.iconsByType = iconsByType;
10095
10165
  exports.isRequired = isRequired;
10096
10166
  exports.pathParse = pathParse;
10097
10167
  exports.pathsEqual = pathsEqual;
10168
+ exports.pruneAt = pruneAt;
10098
10169
  exports.runExpressionEvaluation = runExpressionEvaluation;
10099
10170
  exports.runRecursively = runRecursively;
10100
10171
  exports.runUnaryTestEvaluation = runUnaryTestEvaluation;