mirror of
https://github.com/penpot/penpot-exporter-figma-plugin.git
synced 2025-01-03 05:10:13 -05:00
parent
a1f1eb495e
commit
0dbd7d00f1
5 changed files with 585 additions and 518 deletions
40
ui-src/components/LibraryError.tsx
Normal file
40
ui-src/components/LibraryError.tsx
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
import { Banner, Button, IconWarning32, Link } from '@create-figma-plugin/ui';
|
||||||
|
|
||||||
|
import { useFigmaContext } from '@ui/context';
|
||||||
|
|
||||||
|
import { Stack } from './Stack';
|
||||||
|
|
||||||
|
export const LibraryError = () => {
|
||||||
|
const { reload, cancel, error } = useFigmaContext();
|
||||||
|
|
||||||
|
if (!error) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack space="small">
|
||||||
|
<Stack space="xsmall">
|
||||||
|
<Banner icon={<IconWarning32 />} variant="warning">
|
||||||
|
Oops! It looks like there was an <b>error generating the export file</b>.
|
||||||
|
</Banner>
|
||||||
|
<span>
|
||||||
|
Please open an issue in our{' '}
|
||||||
|
<Link
|
||||||
|
href="https://github.com/penpot/penpot-exporter-figma-plugin/issues"
|
||||||
|
target="_blank"
|
||||||
|
rel="noreferrer"
|
||||||
|
>
|
||||||
|
Github repository
|
||||||
|
</Link>
|
||||||
|
, and we'll be happy to assist you!
|
||||||
|
</span>
|
||||||
|
<Stack space="xsmall" direction="row">
|
||||||
|
<Button onClick={reload} fullWidth>
|
||||||
|
Reload
|
||||||
|
</Button>
|
||||||
|
<Button secondary onClick={cancel} fullWidth>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
|
@ -1,5 +1,6 @@
|
||||||
import { LoadingIndicator } from '@create-figma-plugin/ui';
|
import { LoadingIndicator } from '@create-figma-plugin/ui';
|
||||||
|
|
||||||
|
import { LibraryError } from '@ui/components/LibraryError';
|
||||||
import { useFigmaContext } from '@ui/context';
|
import { useFigmaContext } from '@ui/context';
|
||||||
|
|
||||||
import { ExportForm } from './ExportForm';
|
import { ExportForm } from './ExportForm';
|
||||||
|
@ -7,7 +8,7 @@ import { ExporterProgress } from './ExporterProgress';
|
||||||
import { PluginReload } from './PluginReload';
|
import { PluginReload } from './PluginReload';
|
||||||
|
|
||||||
export const PenpotExporter = () => {
|
export const PenpotExporter = () => {
|
||||||
const { loading, needsReload, exporting } = useFigmaContext();
|
const { loading, needsReload, exporting, error } = useFigmaContext();
|
||||||
|
|
||||||
if (loading) return <LoadingIndicator />;
|
if (loading) return <LoadingIndicator />;
|
||||||
|
|
||||||
|
@ -15,5 +16,7 @@ export const PenpotExporter = () => {
|
||||||
|
|
||||||
if (needsReload) return <PluginReload />;
|
if (needsReload) return <PluginReload />;
|
||||||
|
|
||||||
|
if (error) return <LibraryError />;
|
||||||
|
|
||||||
return <ExportForm />;
|
return <ExportForm />;
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,7 +11,8 @@ type PluginMessage =
|
||||||
| ProgressStepMessage
|
| ProgressStepMessage
|
||||||
| ProgressCurrentItemMessage
|
| ProgressCurrentItemMessage
|
||||||
| ProgressTotalItemsMessage
|
| ProgressTotalItemsMessage
|
||||||
| ProgressProcessedItemsMessage;
|
| ProgressProcessedItemsMessage
|
||||||
|
| ErrorMessage;
|
||||||
|
|
||||||
type PenpotDocumentMessage = {
|
type PenpotDocumentMessage = {
|
||||||
type: 'PENPOT_DOCUMENT';
|
type: 'PENPOT_DOCUMENT';
|
||||||
|
@ -47,6 +48,11 @@ type ProgressProcessedItemsMessage = {
|
||||||
data: number;
|
data: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type ErrorMessage = {
|
||||||
|
type: 'ERROR';
|
||||||
|
data: string;
|
||||||
|
};
|
||||||
|
|
||||||
export const sendMessage = (pluginMessage: PluginMessage) => {
|
export const sendMessage = (pluginMessage: PluginMessage) => {
|
||||||
window.dispatchEvent(
|
window.dispatchEvent(
|
||||||
new MessageEvent<MessageData>('message', {
|
new MessageEvent<MessageData>('message', {
|
||||||
|
|
|
@ -10,6 +10,7 @@ export type UseFigmaHook = {
|
||||||
needsReload: boolean;
|
needsReload: boolean;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
exporting: boolean;
|
exporting: boolean;
|
||||||
|
error: boolean;
|
||||||
step: Steps | undefined;
|
step: Steps | undefined;
|
||||||
currentItem: string | undefined;
|
currentItem: string | undefined;
|
||||||
totalItems: number;
|
totalItems: number;
|
||||||
|
@ -38,6 +39,7 @@ export const useFigma = (): UseFigmaHook => {
|
||||||
const [needsReload, setNeedsReload] = useState(false);
|
const [needsReload, setNeedsReload] = useState(false);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [exporting, setExporting] = useState(false);
|
const [exporting, setExporting] = useState(false);
|
||||||
|
const [error, setError] = useState(false);
|
||||||
|
|
||||||
const [step, setStep] = useState<Steps>();
|
const [step, setStep] = useState<Steps>();
|
||||||
const [currentItem, setCurrentItem] = useState<string | undefined>();
|
const [currentItem, setCurrentItem] = useState<string | undefined>();
|
||||||
|
@ -62,9 +64,16 @@ export const useFigma = (): UseFigmaHook => {
|
||||||
data: 'exporting'
|
data: 'exporting'
|
||||||
});
|
});
|
||||||
|
|
||||||
const blob = await file.export();
|
const blob = await file.export().catch(error => {
|
||||||
|
sendMessage({
|
||||||
|
type: 'ERROR',
|
||||||
|
data: error.message
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
download(blob, `${pluginMessage.data.name}.zip`);
|
if (blob) {
|
||||||
|
download(blob, `${pluginMessage.data.name}.zip`);
|
||||||
|
}
|
||||||
|
|
||||||
setExporting(false);
|
setExporting(false);
|
||||||
setStep(undefined);
|
setStep(undefined);
|
||||||
|
@ -98,6 +107,12 @@ export const useFigma = (): UseFigmaHook => {
|
||||||
setProcessedItems(pluginMessage.data);
|
setProcessedItems(pluginMessage.data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'ERROR': {
|
||||||
|
setError(true);
|
||||||
|
setLoading(false);
|
||||||
|
setExporting(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -113,6 +128,7 @@ export const useFigma = (): UseFigmaHook => {
|
||||||
|
|
||||||
const reload = () => {
|
const reload = () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
setError(false);
|
||||||
postMessage('reload');
|
postMessage('reload');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -143,6 +159,7 @@ export const useFigma = (): UseFigmaHook => {
|
||||||
needsReload,
|
needsReload,
|
||||||
loading,
|
loading,
|
||||||
exporting,
|
exporting,
|
||||||
|
error,
|
||||||
step,
|
step,
|
||||||
currentItem,
|
currentItem,
|
||||||
totalItems,
|
totalItems,
|
||||||
|
|
1029
ui-src/lib/penpot.js
1029
ui-src/lib/penpot.js
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue