0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-23 06:04:01 -05:00
penpot-exporter-figma-plugin/plugin-src/code.ts
Alex Sánchez 8d5c5c15eb
Dynamic plugin size calculation, and cap the height to a safe value (#98)
* dynamic size

* fixes

* fixes

* fix dynamic size

* add changelog

---------

Co-authored-by: Jordi Sala Morales <jordism91@gmail.com>
2024-05-13 10:08:26 +02:00

34 lines
827 B
TypeScript

import { findAllTextNodes } from './findAllTextnodes';
import { handleExportMessage } from './handleExportMessage';
import { registerChange } from './registerChange';
const BASE_HEIGHT = 135;
const BASE_WIDTH = 290;
figma.showUI(__html__, { themeColors: true, width: BASE_WIDTH, height: BASE_HEIGHT });
figma.ui.onmessage = message => {
if (message.type === 'ready') {
findAllTextNodes();
}
if (message.type === 'export') {
handleExportMessage(message.data as Record<string, string>);
}
if (message.type === 'cancel') {
figma.closePlugin();
}
if (message.type === 'reload') {
findAllTextNodes();
}
if (message.type === 'resize') {
figma.ui.resize(BASE_WIDTH, message.height);
}
};
figma.on('currentpagechange', () => {
figma.currentPage.once('nodechange', registerChange);
});