@bpmn-io/form-js-viewer 1.21.2 → 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 +63 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.es.js +63 -5
- package/dist/index.es.js.map +1 -1
- package/dist/types/util/simple.d.ts +17 -0
- package/package.json +3 -3
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
|
|
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:
|
|
7530
|
+
errors: nextErrors
|
|
7480
7531
|
});
|
|
7481
7532
|
}
|
|
7482
7533
|
revert(context) {
|
|
@@ -9837,11 +9888,18 @@ class Form {
|
|
|
9837
9888
|
const validator = this.get('validator');
|
|
9838
9889
|
const fieldErrors = validator.validateFieldInstance(fieldInstance, value);
|
|
9839
9890
|
minDash.set(data, valuePath, value);
|
|
9840
|
-
|
|
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
|
+
}
|
|
9841
9899
|
this._emit('field.updated', update);
|
|
9842
9900
|
this._setState({
|
|
9843
9901
|
data: clone(data),
|
|
9844
|
-
errors: clone(
|
|
9902
|
+
errors: clone(nextErrors)
|
|
9845
9903
|
});
|
|
9846
9904
|
}
|
|
9847
9905
|
|
|
@@ -10107,6 +10165,7 @@ exports.iconsByType = iconsByType;
|
|
|
10107
10165
|
exports.isRequired = isRequired;
|
|
10108
10166
|
exports.pathParse = pathParse;
|
|
10109
10167
|
exports.pathsEqual = pathsEqual;
|
|
10168
|
+
exports.pruneAt = pruneAt;
|
|
10110
10169
|
exports.runExpressionEvaluation = runExpressionEvaluation;
|
|
10111
10170
|
exports.runRecursively = runRecursively;
|
|
10112
10171
|
exports.runUnaryTestEvaluation = runUnaryTestEvaluation;
|