refactor: auto-refresh window info after dock/resize/drag; drop manual Info button
This commit is contained in:
1 parent
85e9433626
commit
dc8ab7421e
1 file changed
+28
-20
+28
-20
@@ -42,21 +42,6 @@ function Plugin () {
|
||||
maxHeight: 800
|
||||
})
|
||||
|
||||
// Обновляем цифры размера ТОЛЬКО после окончания drag'а (отпускание кнопки).
|
||||
// К моменту pointerup Figma уже применила новый размер окна.
|
||||
useEffect(function () {
|
||||
const handlePointerUp = function () {
|
||||
setCurrentWindowSize({
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight
|
||||
})
|
||||
}
|
||||
window.addEventListener('pointerup', handlePointerUp)
|
||||
return function () {
|
||||
window.removeEventListener('pointerup', handlePointerUp)
|
||||
}
|
||||
}, [])
|
||||
|
||||
// Слушаем ответ от main с актуальными x/y (canvas-space) и размерами окна
|
||||
useEffect(function () {
|
||||
const off = on('WINDOW_INFO', function (info: {
|
||||
@@ -71,6 +56,32 @@ function Plugin () {
|
||||
return function () { off() }
|
||||
}, [])
|
||||
|
||||
// Запрашиваем свежие данные об окне у main (после любого действия/старта).
|
||||
function refreshInfo () {
|
||||
emit('GET_WINDOW_INFO')
|
||||
}
|
||||
|
||||
// Обновляем цифры размера и инфо ТОЛЬКО после окончания drag'а (отпускание кнопки).
|
||||
// К моменту pointerup Figma уже применила новый размер окна.
|
||||
useEffect(function () {
|
||||
const handlePointerUp = function () {
|
||||
setCurrentWindowSize({
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight
|
||||
})
|
||||
refreshInfo()
|
||||
}
|
||||
window.addEventListener('pointerup', handlePointerUp)
|
||||
return function () {
|
||||
window.removeEventListener('pointerup', handlePointerUp)
|
||||
}
|
||||
}, [])
|
||||
|
||||
// Первичное заполнение инфо при старте плагина.
|
||||
useEffect(function () {
|
||||
refreshInfo()
|
||||
}, [])
|
||||
|
||||
function toggleWindowSize () {
|
||||
const isMaximized =
|
||||
currentWindowSize.width >= MAX_WINDOW_SIZE.width &&
|
||||
@@ -78,10 +89,7 @@ function Plugin () {
|
||||
const next = isMaximized ? { ...MIN_WINDOW_SIZE } : { ...MAX_WINDOW_SIZE }
|
||||
setCurrentWindowSize(next)
|
||||
emit('RESIZE_WINDOW', next)
|
||||
}
|
||||
|
||||
function requestWindowInfo () {
|
||||
emit('GET_WINDOW_INFO')
|
||||
refreshInfo()
|
||||
}
|
||||
|
||||
function dockWindow (position: 'left' | 'right' | 'center') {
|
||||
@@ -90,6 +98,7 @@ function Plugin () {
|
||||
width: currentWindowSize.width,
|
||||
height: currentWindowSize.height
|
||||
})
|
||||
refreshInfo()
|
||||
}
|
||||
|
||||
const isMaximized =
|
||||
@@ -112,7 +121,6 @@ function Plugin () {
|
||||
<Button onClick={function () { dockWindow('left') }}>◧ Лево</Button>
|
||||
<Button onClick={function () { dockWindow('center') }}>▣ Центр</Button>
|
||||
<Button onClick={function () { dockWindow('right') }}>Право ◨</Button>
|
||||
<Button onClick={requestWindowInfo}>🔍 Инфо</Button>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
|
||||
Reference in new issue
Block a user