Registers site.download-zip (WHP mode only; shows in the ⋯ menu and the palette) via ExportCommand, mounted in CanvasOverlays. useSiteExport POSTs ?action=export_zip with the CSRF header: a zip answer is saved through a Blob + anchor click, anything else (JSON error, older backend, network failure, a stream cut short) becomes an error notice. Refs #42 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
30 lines
948 B
TypeScript
30 lines
948 B
TypeScript
import React from 'react';
|
|
import { useRegisterCommands } from '../../editor/commands';
|
|
import { useEditorConfig } from '../../state/EditorConfigContext';
|
|
import { useSiteExport } from '../../hooks/useSiteExport';
|
|
|
|
/**
|
|
* Registers `site.download-zip` ("Download site (.zip)") in WHP mode -- it then shows
|
|
* in the top-bar ⋯ menu and the Cmd+K palette. Renders nothing; mounted once in
|
|
* CanvasOverlays. Standalone mode registers nothing.
|
|
*/
|
|
export const ExportCommand: React.FC = () => {
|
|
const { isWHP } = useEditorConfig();
|
|
const { downloadZip } = useSiteExport();
|
|
|
|
useRegisterCommands(
|
|
isWHP
|
|
? [{
|
|
id: 'site.download-zip',
|
|
title: 'Download site (.zip)',
|
|
group: 'site',
|
|
keywords: ['export', 'zip', 'backup', 'download', 'archive'],
|
|
when: () => isWHP,
|
|
run: async () => { await downloadZip(); },
|
|
}]
|
|
: [],
|
|
[isWHP, downloadZip],
|
|
);
|
|
return null;
|
|
};
|