diff --git a/src/app/components/App.tsx b/src/app/components/App.tsx
index 9d79347..1e223ab 100644
--- a/src/app/components/App.tsx
+++ b/src/app/components/App.tsx
@@ -16,6 +16,8 @@ import '../styles/ui.css';
import symbols from '../../symbols.json';
import {Range} from 'ace-builds';
+import Corner from './Corner';
+
declare function require(path: string): any;
const App = ({}) => {
@@ -93,8 +95,9 @@ const App = ({}) => {
onChange={onChange}
value={code}
width="100%"
- height="65px"
+ height="calc(55% - 25px)"
showGutter={false}
+ showPrintMargin={false}
focus={true}
wrapEnabled={true}
onLoad={onLoad}
@@ -104,7 +107,7 @@ const App = ({}) => {
/>
{
}}
dangerouslySetInnerHTML={{__html: preview}}
/>
-
);
};
diff --git a/src/app/components/Corner.tsx b/src/app/components/Corner.tsx
new file mode 100644
index 0000000..be4aed6
--- /dev/null
+++ b/src/app/components/Corner.tsx
@@ -0,0 +1,45 @@
+import * as React from 'react';
+
+const Corner = ({}) => {
+ const resizeIcon = React.useRef
(undefined);
+
+ const resizeWindow = e => {
+ const size = {
+ w: Math.max(50, Math.floor(e.clientX + 5)),
+ h: Math.max(50, Math.floor(e.clientY + 5)),
+ };
+ parent.postMessage({pluginMessage: {type: 'resize', size: size}}, '*');
+ };
+
+ React.useEffect(() => {
+ resizeIcon.current.onpointerdown = e => {
+ resizeIcon.current.onpointermove = resizeWindow;
+ resizeIcon.current.setPointerCapture(e.pointerId);
+ };
+ resizeIcon.current.onpointerup = e => {
+ resizeIcon.current.onpointermove = null;
+ resizeIcon.current.releasePointerCapture(e.pointerId);
+ };
+ });
+
+ return (
+
+ );
+};
+
+export default Corner;
diff --git a/src/plugin/controller.ts b/src/plugin/controller.ts
index 6f1524b..a8dec9f 100644
--- a/src/plugin/controller.ts
+++ b/src/plugin/controller.ts
@@ -1,5 +1,9 @@
figma.showUI(__html__);
+figma.clientStorage.getAsync('size').then(size => {
+ if (size) figma.ui.resize(size.w, size.h);
+});
+
const postSourceCode = () => {
const selection = figma.currentPage.selection;
if (selection.length !== 0) {
@@ -10,34 +14,42 @@ const postSourceCode = () => {
postSourceCode();
figma.ui.onmessage = msg => {
- if (msg.type === 'create-latex-svg') {
- const node = figma.createNodeFromSvg(msg.svg);
- if (node.children.length !== 0) {
- const svg = node.children[0];
- const selection = figma.currentPage.selection;
- (svg as any).setRelaunchData({edit: ''});
- svg.resize(msg.scale, svg.height * (msg.scale / svg.width));
- if (selection.length !== 0 && selection[0].getPluginData('source') != '') {
- const groupNode = selection[0];
- groupNode.setPluginData('source', msg.source);
- groupNode.name = msg.source;
- svg.x = groupNode.x;
- svg.y = groupNode.y;
- groupNode.appendChild(svg.children[0]);
- groupNode.children[0].remove();
- figma.currentPage.selection = [groupNode];
- } else {
- svg.setPluginData('source', msg.source);
- svg.name = msg.source;
- const {x, y} = figma.viewport.center;
- svg.x = x;
- svg.y = y;
- figma.currentPage.appendChild(svg);
- figma.currentPage.selection = [svg];
+ switch (msg.type) {
+ case 'create-latex-svg':
+ const node = figma.createNodeFromSvg(msg.svg);
+ if (node.children.length !== 0) {
+ const svg = node.children[0];
+ const selection = figma.currentPage.selection;
+ (svg as any).setRelaunchData({edit: ''});
+ svg.resize(msg.scale, svg.height * (msg.scale / svg.width));
+ if (selection.length !== 0 && selection[0].getPluginData('source') != '') {
+ const groupNode = selection[0];
+ groupNode.setPluginData('source', msg.source);
+ groupNode.name = msg.source;
+ svg.x = groupNode.x;
+ svg.y = groupNode.y;
+ groupNode.appendChild(svg.children[0]);
+ groupNode.children[0].remove();
+ figma.currentPage.selection = [groupNode];
+ } else {
+ svg.setPluginData('source', msg.source);
+ svg.name = msg.source;
+ const {x, y} = figma.viewport.center;
+ svg.x = x;
+ svg.y = y;
+ figma.currentPage.appendChild(svg);
+ figma.currentPage.selection = [svg];
+ }
}
- }
- node.remove();
+ node.remove();
+ figma.closePlugin();
+ break;
+ case 'resize':
+ figma.ui.resize(msg.size.w, msg.size.h);
+ figma.clientStorage.setAsync('size', msg.size);
+ break;
+ case 'cancel':
+ figma.closePlugin();
+ break;
}
-
- figma.closePlugin();
};