From bc9b2e60e9cf88cd5186bce40f54dba7f777ad51 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Wed, 9 Sep 2026 13:08:11 +0200 Subject: [PATCH] feat: window docking buttons (left/center/right) via figma.ui.reposition - main.ts: add DOCK_WINDOW handler using figma.viewport.bounds + figma.ui.resize/reposition - ui.tsx: add dock buttons (Left/Center/Right) + keep expand/collapse + drag handle --- src/main.ts | 18 ++++++++++++++++++ src/ui.tsx | 14 ++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/main.ts b/src/main.ts index c1b8026..fe237f3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -10,5 +10,23 @@ export default function () { figma.ui.resize(width, height) }) + // Эмуляция докинга: прижать окно плагина к краям canvas (left/right/center). + // reposition() принимает canvas-space координаты (как figma.viewport.center). + // Ширину панелей Figma API не отдаёт, поэтому прижимаем к bounds видимой области. + on('DOCK_WINDOW', function (payload: { position: 'left' | 'right' | 'center'; width: number; height: number }) { + const { position, width, height } = payload + figma.ui.resize(width, height) + const b = figma.viewport.bounds + let x = b.x + let y = b.y + if (position === 'right') { + x = b.x + b.width - width + } else if (position === 'center') { + x = b.x + (b.width - width) / 2 + y = b.y + (b.height - height) / 2 + } + figma.ui.reposition(x, y) + }) + showUI({ width: 320, height: 200, themeColors: true, title: 'AI assistant (MVP)' }) } diff --git a/src/ui.tsx b/src/ui.tsx index fe80e97..3bf4e18 100644 --- a/src/ui.tsx +++ b/src/ui.tsx @@ -4,6 +4,7 @@ import { Text, Muted, VerticalSpace, + Button, IconButton, IconExpand24, IconCollapse24, @@ -58,6 +59,14 @@ function Plugin () { emit('RESIZE_WINDOW', next) } + function dockWindow (position: 'left' | 'right' | 'center') { + emit('DOCK_WINDOW', { + position, + width: currentWindowSize.width, + height: currentWindowSize.height + }) + } + const isMaximized = currentWindowSize.width >= MAX_WINDOW_SIZE.width && currentWindowSize.height >= MAX_WINDOW_SIZE.height @@ -74,6 +83,11 @@ function Plugin () { {isMaximized ? : } +
+ + + +