Mentions légales du service

Skip to content
Snippets Groups Projects

Resolve "Element duplication works only for the element at index 0"

1 file
+ 9
1
Compare changes
  • Side-by-side
  • Inline
@@ -138,6 +138,7 @@ export const useEditorStore = defineStore('editor', {
@@ -138,6 +138,7 @@ export const useEditorStore = defineStore('editor', {
node.data.formValues.components.push({ action: action });
node.data.formValues.components.push({ action: action });
}
}
},
},
 
//? The parameter nodeMoved is used when openedParentId is not usable
removeElementFromScreen(index: number, parentNodeId, nodeMoved?: boolean): void {
removeElementFromScreen(index: number, parentNodeId, nodeMoved?: boolean): void {
this.closeFormPanel();
this.closeFormPanel();
const node = findNode(parentNodeId);
const node = findNode(parentNodeId);
@@ -245,7 +246,14 @@ export const useEditorStore = defineStore('editor', {
@@ -245,7 +246,14 @@ export const useEditorStore = defineStore('editor', {
duplicateElement() {
duplicateElement() {
const node = findNode(this.openedParentId);
const node = findNode(this.openedParentId);
const newElement = structuredClone(toRaw(node.data.elements.find(element => element.id === this.openedNodeId)));
const element = node.data.elements.find(element => element.id === this.openedNodeId);
 
 
//! Structured Clone create error
 
// const newElement = structuredClone(toRaw(element));
 
const newElement = JSON.parse(JSON.stringify(toRaw(element)));
 
 
console.log('new Element', newElement);
 
newElement.id = this.generateId();
newElement.id = this.generateId();
newElement.parentId = node.id;
newElement.parentId = node.id;
Loading