Skip to content

Rotate and delete with Moveable rotatable #657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 51 additions & 2 deletions app/features/position.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import $ from 'blingblingjs'
import hotkeys from 'hotkeys-js'
import { metaKey, getStyle, getSide, showHideSelected } from '../utilities/'
import Moveable from 'moveable'

const key_events = 'up,down,left,right'
.split(',')
Expand All @@ -27,8 +28,11 @@ export function Position() {
state.elements.forEach(el =>
el.teardown())

state.elements = els.map(el =>
draggable({el}))
state.elements = els.map(el => {
draggable({el})
rotatable(el)
return el
})
}

const disconnect = () => {
Expand Down Expand Up @@ -162,6 +166,51 @@ export function draggable({el, surface = el, cursor = 'move', clickEvent}) {
return el
}

export function rotatable(el) {
const mv = new Moveable(document.body, {
target: el,
rotatable: true
})
Comment on lines +170 to +173
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the ables option for adding things like a custom delete button seems to only work with react and react-moveable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lame!


const originalElPosition = el.getBoundingClientRect();
const {x:originalX, y:originalY, width:originalW} = originalElPosition

const deleteButton = document.createElement('visbug-moveable-delete-button')
deleteButton.innerText = '✕'
deleteButton.style.position = 'absolute'
deleteButton.style.left = 0
deleteButton.style.top = 0
deleteButton.style.transform = `translate(${originalX + originalW + 10}px,${originalY}px)`
deleteButton.style.zIndex = 1
deleteButton.style.background = 'var(--moveable-color, #4af)'
deleteButton.style.color = '#fff'
deleteButton.style.zIndex = 1
deleteButton.style.width = '24px'
deleteButton.style.height = '24px'
deleteButton.style.borderRadius = '4px'
deleteButton.style.opacity = 0.9
deleteButton.style.display = 'flex'
deleteButton.style.justifyContent = 'center'
deleteButton.style.alignItems = 'center'
deleteButton.style.cursor = 'pointer'
function handleDeleteButton() {
deleteButton.removeEventListener('click', handleDeleteButton)
deleteButton.remove()
mv.destroy()
el.remove()
}
deleteButton.addEventListener('click', handleDeleteButton)
document.body.appendChild(deleteButton)

mv.on('rotate', e => {
e.target.style.transform = e.drag.transform
const currentElPosition = e.target.getBoundingClientRect()
const {x,y,width,height} = currentElPosition
deleteButton.style.transformOrigin = `${x+width/2}px ${y+height/2}px`
deleteButton.style.transform = e.drag.transform + ` translate(${originalX + originalW + 10}px,${originalY}px) `
})
}

export function positionElement(els, direction) {
els
.map(el => ensurePositionable(el))
Expand Down
2 changes: 2 additions & 0 deletions app/utilities/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ export const isOffBounds = node =>
|| node.closest('visbug-corners')
|| node.closest('visbug-grip')
|| node.closest('visbug-gridlines')
|| node.closest('.moveable-control')
|| node.closest('visbug-moveable-delete-button')
Comment on lines +92 to +93
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding this didn't seem to help

)

export const isSelectorValid = (qs => (
Expand Down
2 changes: 1 addition & 1 deletion app/utilities/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ export const altKey = window.navigator.platform.includes('Mac')
? 'opt'
: 'alt'

export const notList = ':not(vis-bug):not(script):not(hotkey-map):not(.visbug-metatip):not(visbug-label):not(visbug-handles):not(visbug-corners):not(visbug-grip):not(visbug-gridlines)'
export const notList = ':not(vis-bug):not(script):not(hotkey-map):not(.visbug-metatip):not(visbug-label):not(visbug-handles):not(visbug-corners):not(visbug-grip):not(visbug-gridlines):not(.moveable-control):not(visbug-moveable-delete-button)'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only adding this here actually helped

Loading
Loading