feat: add helper function for debug (#1241)

This commit is contained in:
Himself65 2023-03-01 16:33:52 -06:00 committed by GitHub
parent 5cda4a5ebc
commit 71a0951c77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 0 deletions

View File

@ -13,3 +13,4 @@ NODE_API_SERVER=
ENABLE_IDB_PROVIDER=1
PREFETCH_WORKSPACE=1
ENABLE_BC_PROVIDER=1
EXPOSE_INTERNAL=1

View File

@ -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'),
};

View File

@ -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]);

View File

@ -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>;

View File

@ -10,6 +10,7 @@ export default function getConfig() {
enableBroadCastChannelProvider: true,
enableIndexedDBProvider: true,
prefetchWorkspace: false,
exposeInternal: true,
},
};
}