fix(frontend): duplicate

This commit is contained in:
Faton Ramadani
2023-02-24 18:04:31 +01:00
committed by Ruben Fiszel
parent 65ccae6837
commit 084c2254ee
2 changed files with 19 additions and 24 deletions

View File

@@ -151,3 +151,20 @@ export function deleteGridItem(app: App, id: string) {
}
}
}
export function duplicateGridItem(
app: App,
focusedGrid: FocusedGrid,
id: string
): string | undefined {
const gridItem = findGridItem(app, id)
if (gridItem) {
const newId = getNextGridItemId(app)
const newItem = JSON.parse(JSON.stringify(gridItem))
newItem.id = newId
newItem.data.id = newId
return insertNewGridItem(app, newItem.data, focusedGrid)
}
return undefined
}

View File

@@ -21,6 +21,7 @@
import CssProperty from '../componentsPanel/CssProperty.svelte'
import { dirtyStore } from '$lib/components/common/confirmationModal/dirtyStore'
import GridTab from './GridTab.svelte'
import { duplicateGridItem } from '../appUtils'
export let component: AppComponent | undefined
export let rowColumns = false
@@ -30,30 +31,7 @@
getContext<AppEditorContext>('AppEditorContext')
function duplicateElement(id: string) {
/*
const parent = findGridItem($app.grid, id)
if (!parent) {
return
}
const data: AppComponent = JSON.parse(JSON.stringify(parent.data))
$dirtyStore = true
const grid = $app.grid ?? []
const newId = getNextGridItemId(grid)
if ($focusedGrid) {
const { parentComponentId, subGridIndex } = $focusedGrid
$app.grid = insertNewGridItem($app.grid, parentComponentId, subGridIndex, newId, data)
} else {
const newItem = createNewGridItem(grid, newId, data)
$app.grid = [...grid, newItem]
}
$selectedComponent = newId
*/
$selectedComponent = duplicateGridItem($app, $focusedGrid, id)
}
function removeGridElement() {