Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

feat: add helper function for debug (#1241)

Himself6571a0951c776c
diff --git a/apps/web/.env.local.template b/apps/web/.env.local.template
index 1f9c38a138..f7c16ce930 100644
--- a/apps/web/.env.local.template
+++ b/apps/web/.env.local.template
@@ -13,3 +13,4 @@ NODE_API_SERVER=
ENABLE_IDB_PROVIDER=1
PREFETCH_WORKSPACE=1
ENABLE_BC_PROVIDER=1
+EXPOSE_INTERNAL=1
diff --git a/apps/web/preset.config.mjs b/apps/web/preset.config.mjs
index 22a62c81df..b8e9b4f458 100644
--- a/apps/web/preset.config.mjs
+++ b/apps/web/preset.config.mjs
@@ -6,4 +6,5 @@ export default {
process.env.ENABLE_BC_PROVIDER ?? '1'
),
prefetchWorkspace: Boolean(process.env.PREFETCH_WORKSPACE ?? '1'),
+ exposeInternal: Boolean(process.env.EXPOSE_INTERNAL ?? '1'),
};
diff --git a/apps/web/src/components/blocksuite/block-suite-editor/index.tsx b/apps/web/src/components/blocksuite/block-suite-editor/index.tsx
index c1c5735417..5ba4d7dd0d 100644
--- a/apps/web/src/components/blocksuite/block-suite-editor/index.tsx
+++ b/apps/web/src/components/blocksuite/block-suite-editor/index.tsx
@@ -5,6 +5,7 @@ import { assertExists } from '@blocksuite/store';
import { useEffect, useRef } from 'react';
import { BlockSuiteWorkspace } from '../../../shared';
+import { config } from '../../../shared/env';
export type EditorProps = {
blockSuiteWorkspace: BlockSuiteWorkspace;
@@ -26,6 +27,13 @@ const exampleText = markdown.split('\n').slice(1).join('\n');
const kFirstPage = 'affine-first-page';
+declare global {
+ // eslint-disable-next-line no-var
+ var currentBlockSuiteWorkspace: BlockSuiteWorkspace | undefined;
+ // eslint-disable-next-line no-var
+ var currentPage: Page | undefined;
+}
+
export const BlockSuiteEditor = (props: EditorProps) => {
const page = props.page;
const editorRef = useRef<EditorContainer | null>(null);
@@ -73,6 +81,11 @@ export const BlockSuiteEditor = (props: EditorProps) => {
page.resetHistory();
}
}
+
+ if (config.exposeInternal) {
+ globalThis.currentBlockSuiteWorkspace = props.blockSuiteWorkspace;
+ globalThis.currentPage = page;
+ }
props.onLoad?.(page, editor);
return;
}, [page, props]);
diff --git a/apps/web/src/types/index.ts b/apps/web/src/types/index.ts
index c33d6d29b7..cafdd95172 100644
--- a/apps/web/src/types/index.ts
+++ b/apps/web/src/types/index.ts
@@ -10,6 +10,8 @@ export const publicRuntimeConfigSchema = z.object({
enableIndexedDBProvider: z.boolean(),
enableBroadCastChannelProvider: z.boolean(),
prefetchWorkspace: z.boolean(),
+ // expose internal api to globalThis, **development only**
+ exposeInternal: z.boolean(),
});
export type PublicRuntimeConfig = z.infer<typeof publicRuntimeConfigSchema>;
diff --git a/scripts/vitest/next-config-mock.ts b/scripts/vitest/next-config-mock.ts
index 37873c82b6..c49f254a3c 100644
--- a/scripts/vitest/next-config-mock.ts
+++ b/scripts/vitest/next-config-mock.ts
@@ -10,6 +10,7 @@ export default function getConfig() {
enableBroadCastChannelProvider: true,
enableIndexedDBProvider: true,
prefetchWorkspace: false,
+ exposeInternal: true,
},
};
}