form-js
form-js copied to clipboard
Implement copy and pasting
What should we do?
In order to make easier to model forms, we should allow copy&pasting form components
TODO
- [ ] The actions should trigger on the default copy and paste shortcuts
- [ ] The user should be able to copy only a single component at a time
- [ ] When pasting a component, it is added in a new row below the selected component's row (if any)
- [ ] If a form doesn't have a selected component, then the copied component is added in a new row at the end of the form.
- [ ] The pasted component has all properties inherited from the original component, except the Key and Path attributes where special rules apply:
-
If a form doesn't have a component with the original's component Key / Path attribute (e.g. pasting in a new form), then the component is pasted with the original Key / path attribute.
-
If a form has a component with the original's component Key attribute, then the pasted component's Key is the
original's component key
+increment by 1
.- E.g. the original component's Key is
name
. The pasted component's Key isname2
.
- E.g. the original component's Key is
-
The suggestion is to not generate a random key but follow the naming convention defined by the user.
-
If the original component has a Path attribute with a nested structure (e.g.
group.name
), then the pasted component's Path attribute is updated recursively, starting from the root node.- E.g. the original component's path is
group.name
. The pasted component's path isgroup2.name
.
- E.g. the original component's path is
-
- [ ] When a new component is added (pasted) to a form, automatically select it and expand the General section in the properties panel.
- [ ] We should run a validation on paste to check if the schema is valid, in the future we might want to show a toast notification to let users know that the schema pasted is not valid