2024-06-06 10:24:59 -05:00
|
|
|
import { PenpotDocument } from '@ui/types';
|
|
|
|
|
|
|
|
import { Steps } from '.';
|
|
|
|
|
|
|
|
export type MessageData = { pluginMessage?: PluginMessage };
|
|
|
|
|
|
|
|
type PluginMessage =
|
|
|
|
| PenpotDocumentMessage
|
|
|
|
| CustomFontsMessage
|
|
|
|
| ChangesDetectedMessage
|
|
|
|
| ProgressStepMessage
|
|
|
|
| ProgressCurrentItemMessage
|
|
|
|
| ProgressTotalItemsMessage
|
2024-10-18 06:34:10 -05:00
|
|
|
| ProgressProcessedItemsMessage
|
2024-10-28 05:22:50 -05:00
|
|
|
| ErrorMessage
|
|
|
|
| UserDataMessage;
|
2024-06-06 10:24:59 -05:00
|
|
|
|
|
|
|
type PenpotDocumentMessage = {
|
|
|
|
type: 'PENPOT_DOCUMENT';
|
|
|
|
data: PenpotDocument;
|
|
|
|
};
|
|
|
|
|
|
|
|
type CustomFontsMessage = {
|
|
|
|
type: 'CUSTOM_FONTS';
|
|
|
|
data: string[];
|
|
|
|
};
|
|
|
|
|
|
|
|
type ChangesDetectedMessage = {
|
|
|
|
type: 'CHANGES_DETECTED';
|
|
|
|
};
|
|
|
|
|
|
|
|
type ProgressStepMessage = {
|
|
|
|
type: 'PROGRESS_STEP';
|
|
|
|
data: Steps;
|
|
|
|
};
|
|
|
|
|
|
|
|
type ProgressCurrentItemMessage = {
|
|
|
|
type: 'PROGRESS_CURRENT_ITEM';
|
|
|
|
data: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
type ProgressTotalItemsMessage = {
|
|
|
|
type: 'PROGRESS_TOTAL_ITEMS';
|
|
|
|
data: number;
|
|
|
|
};
|
|
|
|
|
|
|
|
type ProgressProcessedItemsMessage = {
|
|
|
|
type: 'PROGRESS_PROCESSED_ITEMS';
|
|
|
|
data: number;
|
|
|
|
};
|
|
|
|
|
2024-10-18 06:34:10 -05:00
|
|
|
type ErrorMessage = {
|
|
|
|
type: 'ERROR';
|
|
|
|
data: string;
|
|
|
|
};
|
|
|
|
|
2024-10-28 05:22:50 -05:00
|
|
|
type UserDataMessage = {
|
|
|
|
type: 'USER_DATA';
|
|
|
|
data: {
|
|
|
|
userId: string;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-06-06 10:24:59 -05:00
|
|
|
export const sendMessage = (pluginMessage: PluginMessage) => {
|
|
|
|
window.dispatchEvent(
|
|
|
|
new MessageEvent<MessageData>('message', {
|
|
|
|
data: {
|
|
|
|
pluginMessage
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
};
|