Skip to content
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ typings/
# Yarn Integrity file
.yarn-integrity

# Yarn Berry cache directory
.yarn

# dotenv environment variables file
.env
.env.test
Expand Down
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.13.1
16
8 changes: 8 additions & 0 deletions src/@types/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ type NotifyMessage = {
message: string
options?: NotificationOptions
}
type ResizeMessage = {
type: 'resize'
size: {
width: number
height: number
}
}

type PluginMessage =
| ClosePluginMessage
Expand All @@ -45,6 +52,7 @@ type PluginMessage =
| SetOptionsMessage
| ExecMessage
| NotifyMessage
| ResizeMessage

type PostMessage = {
pluginMessage: PluginMessage
Expand Down
9 changes: 9 additions & 0 deletions src/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
NotifyMessage,
Options,
PluginMessage,
ResizeMessage,
SetOptionsMessage
} from '@/@types/common'
import defaultOptions from '@/defaultOptions'
Expand Down Expand Up @@ -72,6 +73,10 @@ function notify(msg: NotifyMessage) {
figma.notify(message, options)
}

function resizeWindow(msg: ResizeMessage) {
figma.ui.resize(msg.size.width, msg.size.height)
}

figma.ui.onmessage = (msg: PluginMessage) => {
switch (msg.type) {
case 'exec':
Expand All @@ -94,6 +99,10 @@ figma.ui.onmessage = (msg: PluginMessage) => {
notify(msg)
break

case 'resize':
resizeWindow(msg)
break;

default:
break
}
Expand Down
2 changes: 2 additions & 0 deletions src/ui/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Store from '@/ui/Store'
import Main from '@/ui/components/Main'
import Setting from '@/ui/components/Setting'
import { typography, color } from '@/ui/styles'
import Corner from './components/Corner'

// change cdn url to custom builded monaco-editor
loader.config({
Expand Down Expand Up @@ -70,6 +71,7 @@ const AppContent: React.FC = () => {
/>
{currentScreen === 'main' && <Main />}
{currentScreen === 'setting' && <Setting />}
<Corner />
</>
)
}
Expand Down
53 changes: 53 additions & 0 deletions src/ui/components/Corner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Global, css } from '@emotion/react';
import React from 'react';

function resizeWindow(e: MouseEvent) {
const size = {
width: Math.max(50, Math.floor(e.clientX + 5)),
height: Math.max(50, Math.floor(e.clientY + 5)),
};

parent.postMessage({ pluginMessage: { type: 'resize', size: size } }, '*');
}

const Corner: React.FC = () => {

const handlePointerDown = (e: React.PointerEvent<HTMLDivElement>) => {
e.currentTarget.onpointermove = resizeWindow;
e.currentTarget.setPointerCapture(e.pointerId);
};

const handlePointerUp = (e: React.PointerEvent<HTMLDivElement>) => {
e.currentTarget.onpointermove = null;
e.currentTarget.releasePointerCapture(e.pointerId);
};

<svg id="corner" width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M16 0V16H0L16 0Z" fill="white"/>
<path d="M6.22577 16H3L16 3V6.22576L6.22577 16Z" fill="#8C8C8C"/>
<path d="M11.8602 16H8.63441L16 8.63441V11.8602L11.8602 16Z" fill="#8C8C8C"/>
</svg>

return (
<>
<Global
styles={css`
#corner{
position: fixed;
right: 1px;
bottom: 2px;
cursor: nwse-resize;
}
`}
/>
<div id='corner' onPointerDown={handlePointerDown} onPointerUp={handlePointerUp}>
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M16 0V16H0L16 0Z" fill="white"/>
<path d="M6.22577 16H3L16 3V6.22576L6.22577 16Z" fill="#b5b5b5"/>
<path d="M11.8602 16H8.63441L16 8.63441V11.8602L11.8602 16Z" fill="#a5a5a5"/>
</svg>
</div>
</>);
};

export default Corner;
2 changes: 2 additions & 0 deletions src/ui/components/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ const Main: React.FC = () => {
<div
css={css`
flex: 1;
overflow: hidden;
flex-grow: 1;
`}
>
<ReactMonacoEditor
Expand Down
Loading