diff --git a/packages/form-js-editor/src/features/modeling/cmd/RemoveFormFieldHandler.js b/packages/form-js-editor/src/features/modeling/cmd/RemoveFormFieldHandler.js index 57f0ed885..f24b4e36f 100644 --- a/packages/form-js-editor/src/features/modeling/cmd/RemoveFormFieldHandler.js +++ b/packages/form-js-editor/src/features/modeling/cmd/RemoveFormFieldHandler.js @@ -6,6 +6,10 @@ import { updatePath } from './Util'; +import { + runRecursively +} from '@bpmn-io/form-js-viewer'; + export default class RemoveFormFieldHandler { /** @@ -36,8 +40,8 @@ export default class RemoveFormFieldHandler { // (2) Update internal paths of its siblings (and their children) get(schema, sourcePath).forEach((formField, index) => updatePath(this._formFieldRegistry, formField, index)); - // (3) Remove form field from form field registry - this._formFieldRegistry.remove(formField); + // (3) Remove form field and children from form field registry + runRecursively(formField, (formField) => this._formFieldRegistry.remove(formField)); // TODO: Create updater/change support that automatically updates paths and schema on command execution this._formEditor._setState({ schema }); @@ -60,8 +64,8 @@ export default class RemoveFormFieldHandler { // (2) Update internal paths of its siblings (and their children) get(schema, sourcePath).forEach((formField, index) => updatePath(this._formFieldRegistry, formField, index)); - // (3) Add form field to form field registry - this._formFieldRegistry.add(formField); + // (3) Add form field and children to form field registry + runRecursively(formField, (formField) => this._formFieldRegistry.add(formField)); // TODO: Create updater/change support that automatically updates paths and schema on command execution this._formEditor._setState({ schema }); diff --git a/packages/form-js-editor/src/features/modeling/cmd/UpdateKeyClaimHandler.js b/packages/form-js-editor/src/features/modeling/cmd/UpdateKeyClaimHandler.js index e2adfad7f..7389e0449 100644 --- a/packages/form-js-editor/src/features/modeling/cmd/UpdateKeyClaimHandler.js +++ b/packages/form-js-editor/src/features/modeling/cmd/UpdateKeyClaimHandler.js @@ -36,14 +36,13 @@ export default class UpdateKeyClaimHandler { revert(context) { const { claiming, - formField, valuePath } = context; if (claiming) { this._pathRegistry.unclaimPath(valuePath); } else { - this._pathRegistry.claimPath(valuePath, formField); + this._pathRegistry.claimPath(valuePath, true); } } } diff --git a/packages/form-js-editor/src/features/modeling/cmd/UpdatePathClaimHandler.js b/packages/form-js-editor/src/features/modeling/cmd/UpdatePathClaimHandler.js index 8f9c59810..02c791031 100644 --- a/packages/form-js-editor/src/features/modeling/cmd/UpdatePathClaimHandler.js +++ b/packages/form-js-editor/src/features/modeling/cmd/UpdatePathClaimHandler.js @@ -26,35 +26,34 @@ export default class UpdatePathClaimHandler { if (claiming) { this._pathRegistry.executeRecursivelyOnFields(formField, ({ field, isClosed }) => { const valuePath = this._pathRegistry.getValuePath(field, options); - valuePaths.push(valuePath); + valuePaths.push({ valuePath, isClosed }); this._pathRegistry.claimPath(valuePath, isClosed); }); } else { this._pathRegistry.executeRecursivelyOnFields(formField, ({ field, isClosed }) => { const valuePath = this._pathRegistry.getValuePath(field, options); - valuePaths.push(valuePath); + valuePaths.push({ valuePath, isClosed }); this._pathRegistry.unclaimPath(valuePath, isClosed); }); } - // cache path for revert + // cache path info for revert context.valuePaths = valuePaths; } revert(context) { const { claiming, - formField, valuePaths } = context; if (claiming) { - valuePaths.forEach(valuePath => { + valuePaths.forEach(({ valuePath })=> { this._pathRegistry.unclaimPath(valuePath); }); } else { - valuePaths.forEach(valuePath => { - this._pathRegistry.claimPath(valuePath, formField); + valuePaths.forEach(({ valuePath, isClosed }) => { + this._pathRegistry.claimPath(valuePath, isClosed); }); } } diff --git a/packages/form-js-viewer/src/util/index.js b/packages/form-js-viewer/src/util/index.js index 3a6bd7fa3..d61cc313a 100644 --- a/packages/form-js-viewer/src/util/index.js +++ b/packages/form-js-viewer/src/util/index.js @@ -183,3 +183,13 @@ export function getSchemaVariables(schema, options = {}) { // remove duplicates return Array.from(new Set(variables)); } + +export function runRecursively(formField, fn) { + const components = formField.components || []; + + components.forEach((component, index) => { + runRecursively(component, fn); + }); + + fn(formField); +} \ No newline at end of file