feat(core): use zip snapshot for onboarding page (#6495)

This commit is contained in:
EYHN
2024-04-15 02:16:08 +00:00
parent 9b620ecbc9
commit 1656b33ce3
17 changed files with 108 additions and 2009 deletions
@@ -1,4 +1,5 @@
import { useWorkspace } from '@affine/core/hooks/use-workspace';
import { ZipTransformer } from '@blocksuite/blocks';
import type { Workspace } from '@toeverything/infra';
import {
ServiceProviderContext,
@@ -28,6 +29,8 @@ declare global {
*/
// eslint-disable-next-line no-var
var currentWorkspace: Workspace | undefined;
// eslint-disable-next-line no-var
var exportWorkspaceSnapshot: () => Promise<void>;
interface WindowEventMap {
'affine:workspace:change': CustomEvent<{ id: string }>;
}
@@ -60,6 +63,19 @@ export const Component = (): ReactElement => {
// for debug purpose
window.currentWorkspace = workspace;
window.exportWorkspaceSnapshot = async () => {
const zip = await ZipTransformer.exportDocs(
workspace.docCollection,
Array.from(workspace.docCollection.docs.values())
);
const url = URL.createObjectURL(zip);
// download url
const a = document.createElement('a');
a.href = url;
a.download = `${workspace.docCollection.meta.name}.zip`;
a.click();
URL.revokeObjectURL(url);
};
window.dispatchEvent(
new CustomEvent('affine:workspace:change', {
detail: {