Allow quick duplicating via ctrl/cmd + drag
This commit is contained in:
parent
b62371d1be
commit
a755fe7630
|
@ -144,7 +144,12 @@
|
||||||
const rootComponent = get(selectedScreen).props
|
const rootComponent = get(selectedScreen).props
|
||||||
const component = findComponent(rootComponent, data.id)
|
const component = findComponent(rootComponent, data.id)
|
||||||
componentStore.copy(component)
|
componentStore.copy(component)
|
||||||
await componentStore.paste(component)
|
await componentStore.paste(
|
||||||
|
component,
|
||||||
|
data.mode,
|
||||||
|
null,
|
||||||
|
data.selectComponent
|
||||||
|
)
|
||||||
} else if (type === "preview-loaded") {
|
} else if (type === "preview-loaded") {
|
||||||
// Wait for this event to show the client library if intelligent
|
// Wait for this event to show the client library if intelligent
|
||||||
// loading is supported
|
// loading is supported
|
||||||
|
|
|
@ -653,7 +653,7 @@ export class ComponentStore extends BudiStore {
|
||||||
* @param {object} targetScreen
|
* @param {object} targetScreen
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async paste(targetComponent, mode, targetScreen) {
|
async paste(targetComponent, mode, targetScreen, selectComponent = true) {
|
||||||
const state = get(this.store)
|
const state = get(this.store)
|
||||||
if (!state.componentToPaste) {
|
if (!state.componentToPaste) {
|
||||||
return
|
return
|
||||||
|
@ -728,12 +728,13 @@ export class ComponentStore extends BudiStore {
|
||||||
await screenStore.patch(patch, targetScreenId)
|
await screenStore.patch(patch, targetScreenId)
|
||||||
|
|
||||||
// Select the new component
|
// Select the new component
|
||||||
this.update(state => {
|
if (selectComponent) {
|
||||||
state.selectedScreenId = targetScreenId
|
this.update(state => {
|
||||||
state.selectedComponentId = newComponentId
|
state.selectedScreenId = targetScreenId
|
||||||
|
state.selectedComponentId = newComponentId
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
componentTreeNodesStore.makeNodeVisible(newComponentId)
|
componentTreeNodesStore.makeNodeVisible(newComponentId)
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,6 +120,11 @@
|
||||||
id = component.dataset.id
|
id = component.dataset.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If holding ctrl/cmd then leave behind a duplicate of this component
|
||||||
|
if (mode === GridDragModes.Move && (e.ctrlKey || e.metaKey)) {
|
||||||
|
builderStore.actions.duplicateComponent(id, "above", false)
|
||||||
|
}
|
||||||
|
|
||||||
// Find grid parent and read from DOM
|
// Find grid parent and read from DOM
|
||||||
const domComponent = document.getElementsByClassName(id)[0]
|
const domComponent = document.getElementsByClassName(id)[0]
|
||||||
const domGrid = domComponent?.closest(".grid")
|
const domGrid = domComponent?.closest(".grid")
|
||||||
|
|
|
@ -49,8 +49,12 @@ const createBuilderStore = () => {
|
||||||
keyDown: (key, ctrlKey) => {
|
keyDown: (key, ctrlKey) => {
|
||||||
eventStore.actions.dispatchEvent("key-down", { key, ctrlKey })
|
eventStore.actions.dispatchEvent("key-down", { key, ctrlKey })
|
||||||
},
|
},
|
||||||
duplicateComponent: id => {
|
duplicateComponent: (id, mode = "below", selectComponent = true) => {
|
||||||
eventStore.actions.dispatchEvent("duplicate-component", { id })
|
eventStore.actions.dispatchEvent("duplicate-component", {
|
||||||
|
id,
|
||||||
|
mode,
|
||||||
|
selectComponent,
|
||||||
|
})
|
||||||
},
|
},
|
||||||
deleteComponent: id => {
|
deleteComponent: id => {
|
||||||
eventStore.actions.dispatchEvent("delete-component", { id })
|
eventStore.actions.dispatchEvent("delete-component", { id })
|
||||||
|
|
Loading…
Reference in New Issue