Skip to content

Commit

Permalink
feat: elements arrow moving (#20)
Browse files Browse the repository at this point in the history
* fix: Elements Overlay and Deleting

* fix: editor overflow & change elements type

* feat: elements arrow moving

* feat: more moving with shift

* fix: Elements Overlay and Deleting

* fix: typecheck

---------

Co-authored-by: Tom Lienard <[email protected]>
  • Loading branch information
vshakitskiy and QuiiBz authored Dec 29, 2023
1 parent 76d6c20 commit 3be62b8
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
8 changes: 8 additions & 0 deletions apps/dashboard/src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
}
}

input[type=number] {
-moz-appearance: textfield;
}

input[type=number]::-webkit-outer-spin-button, input[type=number]::-webkit-inner-spin-button {
-webkit-appearance: none;
}

.element:focus {
outline: none;
}
Expand Down
54 changes: 53 additions & 1 deletion apps/dashboard/src/components/OgEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,58 @@ export function OgEditor({ initialElements, localStorageKey: key, width, height
return
}

// Move down
if (event.key === 'ArrowDown' && selectedElement) {
event.preventDefault()
const element = elements.find(item => item.id === selectedElement)

if (element) {
updateElement({
...element,
y: element.y + (event.shiftKey ? 10 : 1)
})
}
}

// Move up
if (event.key === 'ArrowUp' && selectedElement) {
event.preventDefault()
const element = elements.find(item => item.id === selectedElement)

if (element) {
updateElement({
...element,
y: element.y - (event.shiftKey ? 10 : 1)
})
}
}

// Move left
if (event.key === 'ArrowLeft' && selectedElement) {
event.preventDefault()
const element = elements.find(item => item.id === selectedElement)

if (element) {
updateElement({
...element,
x: element.x - (event.shiftKey ? 10 : 1)
})
}
}

// Move right
if (event.key === 'ArrowRight' && selectedElement) {
event.preventDefault()
const element = elements.find(item => item.id === selectedElement)

if (element) {
updateElement({
...element,
x: element.x + (event.shiftKey ? 10 : 1)
})
}
}

// Delete any selected element
if ((event.key === 'Backspace' || event.key === 'Delete') && selectedElement) {
event.preventDefault()
Expand Down Expand Up @@ -289,6 +341,6 @@ export function OgEditor({ initialElements, localStorageKey: key, width, height
<RightPanel />
</div>
</div>
</OgContext.Provider>
</OgContext.Provider >
)
}

0 comments on commit 3be62b8

Please sign in to comment.