2024-10-28 05:22:50 -05:00
|
|
|
import { getUserData } from '@plugin/getUserData';
|
|
|
|
|
2024-05-03 06:43:07 -05:00
|
|
|
import { findAllTextNodes } from './findAllTextnodes';
|
2024-05-09 05:56:45 -05:00
|
|
|
import { handleExportMessage } from './handleExportMessage';
|
|
|
|
import { registerChange } from './registerChange';
|
2022-10-11 08:55:08 -05:00
|
|
|
|
2024-05-13 03:08:26 -05:00
|
|
|
const BASE_HEIGHT = 135;
|
|
|
|
const BASE_WIDTH = 290;
|
|
|
|
|
|
|
|
figma.showUI(__html__, { themeColors: true, width: BASE_WIDTH, height: BASE_HEIGHT });
|
2024-05-03 06:43:07 -05:00
|
|
|
|
|
|
|
figma.ui.onmessage = message => {
|
|
|
|
if (message.type === 'ready') {
|
2024-10-28 05:22:50 -05:00
|
|
|
getUserData();
|
2024-05-03 06:43:07 -05:00
|
|
|
findAllTextNodes();
|
2024-04-08 10:03:34 -05:00
|
|
|
}
|
2024-05-03 06:43:07 -05:00
|
|
|
|
|
|
|
if (message.type === 'export') {
|
|
|
|
handleExportMessage(message.data as Record<string, string>);
|
2022-10-11 08:55:08 -05:00
|
|
|
}
|
2024-05-03 06:43:07 -05:00
|
|
|
|
|
|
|
if (message.type === 'cancel') {
|
|
|
|
figma.closePlugin();
|
2022-10-11 08:55:08 -05:00
|
|
|
}
|
2024-05-03 06:43:07 -05:00
|
|
|
|
2024-05-09 05:56:45 -05:00
|
|
|
if (message.type === 'reload') {
|
|
|
|
findAllTextNodes();
|
|
|
|
}
|
2024-05-13 03:08:26 -05:00
|
|
|
|
|
|
|
if (message.type === 'resize') {
|
|
|
|
figma.ui.resize(BASE_WIDTH, message.height);
|
|
|
|
}
|
2024-05-03 06:43:07 -05:00
|
|
|
};
|
2024-05-09 05:56:45 -05:00
|
|
|
|
2024-06-18 06:20:09 -05:00
|
|
|
let currentPage = figma.currentPage;
|
|
|
|
|
|
|
|
currentPage.on('nodechange', registerChange);
|
|
|
|
|
2024-05-09 05:56:45 -05:00
|
|
|
figma.on('currentpagechange', () => {
|
2024-06-18 06:20:09 -05:00
|
|
|
currentPage.off('nodechange', registerChange);
|
|
|
|
|
|
|
|
currentPage = figma.currentPage;
|
|
|
|
|
|
|
|
currentPage.on('nodechange', registerChange);
|
2024-05-09 05:56:45 -05:00
|
|
|
});
|