Copy parameters that are not present in the meta-model

Our custom meta-model contains references, which are not part of the parameters itself. Thus, they are loaded manually in a custom property panel, in which they can be set, resulting in something like this:

const myCustomProperty = { custom: 'test' }
const modeling = this.bpmnModeler.get('modeling')
if (this.element) {
    modeling.updateProperties(this.element, myCustomProperty)
}

While setting the parameters works without trouble, problems occur as soon as we copyPaste or replace the element. Since the “parameters” are not set as parameters, but instead added as a part of $attrs, they do not get copied on these actions and are missing afterwards.

For replace, I could use the following workaround:

this.postExecute('shape.replace', ({ context }) => {
    const { oldShape, newShape } = context
    const oldShapeCustom = oldShape?.businessObject?.$attrs?.custom
    if (!oldShapeCustom || !newShape.id) {
        return
    }
    const customProperty = {
        custom: oldShapeCustom
    }
    modeling.updateProperties(elementRegistry.get(newShape.id), customProperty)
})

However, I could not use postExecute on events like copyPaste.pasteElements.

  1. Is it possible to copy “custom” properties / $attrs that are not part of the defined meta-model?
  2. … or is it possible to add a workaround using a postExecute on a copyPaste event ? Using shape.create, I cannot receive the copied element’s attributes.

Thank you for any help.

How are you defining your custom meta model? No properties should ever end up in $attrs, if they do, you’re doing it wrong.

No properties should ever end up in $attrs

Okay, I ended up adding our references as properties, too. Now, everything works fine – thank you for this hint.