mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-01 17:39:55 +08:00
feat: seperate createDoc and createStore (#11182)
This commit is contained in:
@@ -174,11 +174,9 @@ export const useSnapshotPage = (
|
||||
docCollection.id,
|
||||
workspacesService.getWorkspaceFlavourProvider(affineWorkspace.meta)
|
||||
);
|
||||
let page = historyShellWorkspace.getDoc(pageId);
|
||||
let page = historyShellWorkspace.getDoc(pageId)?.getStore();
|
||||
if (!page && snapshot) {
|
||||
page = historyShellWorkspace.createDoc({
|
||||
id: pageId,
|
||||
});
|
||||
page = historyShellWorkspace.createDoc(pageId).getStore();
|
||||
page.readonly = true;
|
||||
const spaceDoc = page.spaceDoc;
|
||||
page.load(() => {
|
||||
|
||||
@@ -65,8 +65,8 @@ async function exportDoc(
|
||||
schema: getAFFiNEWorkspaceSchema(),
|
||||
blobCRUD: doc.workspace.blobSync,
|
||||
docCRUD: {
|
||||
create: (id: string) => doc.workspace.createDoc({ id }),
|
||||
get: (id: string) => doc.workspace.getDoc(id),
|
||||
create: (id: string) => doc.workspace.createDoc(id).getStore({ id }),
|
||||
get: (id: string) => doc.workspace.getDoc(id)?.getStore({ id }) ?? null,
|
||||
delete: (id: string) => doc.workspace.removeDoc(id),
|
||||
},
|
||||
middlewares: [
|
||||
|
||||
@@ -9,7 +9,7 @@ import { useCallback } from 'react';
|
||||
export function useReferenceLinkHelper(docCollection: Workspace) {
|
||||
const addReferenceLink = useCallback(
|
||||
(pageId: string, referenceId: string) => {
|
||||
const page = docCollection?.getDoc(pageId);
|
||||
const page = docCollection?.getDoc(pageId)?.getStore();
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ export function useDocCollectionHelper(docCollection: Workspace) {
|
||||
return useMemo(
|
||||
() => ({
|
||||
createDoc: (pageId?: string): Store => {
|
||||
return docCollection.createDoc({ id: pageId });
|
||||
return docCollection.createDoc(pageId).getStore();
|
||||
},
|
||||
}),
|
||||
[docCollection]
|
||||
|
||||
@@ -9,8 +9,8 @@ export function useDocCollectionPage(
|
||||
docCollection: Workspace,
|
||||
pageId: string | null
|
||||
): Store | null {
|
||||
const [page, setPage] = useState(
|
||||
pageId ? docCollection.getDoc(pageId) : null
|
||||
const [page, setPage] = useState<Store | null>(
|
||||
pageId ? (docCollection.getDoc(pageId)?.getStore() ?? null) : null
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -18,7 +18,7 @@ export function useDocCollectionPage(
|
||||
group.add(
|
||||
docCollection.slots.docCreated.subscribe(id => {
|
||||
if (pageId === id) {
|
||||
setPage(docCollection.getDoc(id));
|
||||
setPage(docCollection.getDoc(id)?.getStore() ?? null);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
+6
-2
@@ -33,12 +33,16 @@ beforeEach(async () => {
|
||||
const frameId = page.addBlock('affine:note', {}, pageBlockId);
|
||||
page.addBlock('affine:paragraph', {}, frameId);
|
||||
};
|
||||
await initPage(docCollection.createDoc({ id: 'page0', extensions }));
|
||||
const store = docCollection.createDoc('page0').getStore({ extensions });
|
||||
await initPage(store);
|
||||
});
|
||||
|
||||
describe('useBlockSuitePagePreview', () => {
|
||||
test('basic', async () => {
|
||||
const page = docCollection.getDoc('page0') as Store;
|
||||
const page = docCollection.getDoc('page0')?.getStore();
|
||||
if (!page) {
|
||||
throw new Error('Page not found');
|
||||
}
|
||||
const id = page.addBlock(
|
||||
'affine:paragraph',
|
||||
{
|
||||
|
||||
@@ -9,8 +9,8 @@ export function useDocCollectionPage(
|
||||
docCollection: Workspace,
|
||||
pageId: string | null
|
||||
): Store | null {
|
||||
const [page, setPage] = useState(
|
||||
pageId ? docCollection.getDoc(pageId) : null
|
||||
const [page, setPage] = useState<Store | null>(
|
||||
pageId ? (docCollection.getDoc(pageId)?.getStore() ?? null) : null
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -18,7 +18,7 @@ export function useDocCollectionPage(
|
||||
group.add(
|
||||
docCollection.slots.docCreated.subscribe(id => {
|
||||
if (pageId === id) {
|
||||
setPage(docCollection.getDoc(id));
|
||||
setPage(docCollection.getDoc(id)?.getStore() ?? null);
|
||||
}
|
||||
})
|
||||
);
|
||||
@@ -46,7 +46,9 @@ export function useDocCollectionPage(
|
||||
|
||||
useEffect(() => {
|
||||
if (page?.id !== pageId) {
|
||||
setPage(pageId ? docCollection.getDoc(pageId) : null);
|
||||
setPage(
|
||||
pageId ? (docCollection.getDoc(pageId)?.getStore() ?? null) : null
|
||||
);
|
||||
}
|
||||
}, [docCollection, page?.id, pageId]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user