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.

fix: modify with new blocksuite version about subpage (#2060)

Qi9ec67682722c
diff --git a/apps/web/package.json b/apps/web/package.json
index c9d7755ecf..c6822d2b12 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -18,11 +18,11 @@
"@affine/jotai": "workspace:*",
"@affine/templates": "workspace:*",
"@affine/workspace": "workspace:*",
- "@blocksuite/blocks": "0.0.0-20230420160324-857b396c-nightly",
- "@blocksuite/editor": "0.0.0-20230420160324-857b396c-nightly",
- "@blocksuite/global": "0.0.0-20230420160324-857b396c-nightly",
+ "@blocksuite/blocks": "0.0.0-20230420210727-85b7de79-nightly",
+ "@blocksuite/editor": "0.0.0-20230420210727-85b7de79-nightly",
+ "@blocksuite/global": "0.0.0-20230420210727-85b7de79-nightly",
"@blocksuite/icons": "^2.1.10",
- "@blocksuite/store": "0.0.0-20230420160324-857b396c-nightly",
+ "@blocksuite/store": "0.0.0-20230420210727-85b7de79-nightly",
"@dnd-kit/core": "^6.0.8",
"@dnd-kit/sortable": "^7.0.2",
"@emotion/cache": "^11.10.7",
diff --git a/apps/web/src/atoms/public-workspace/index.ts b/apps/web/src/atoms/public-workspace/index.ts
index 63df516d8d..7567db3c59 100644
--- a/apps/web/src/atoms/public-workspace/index.ts
+++ b/apps/web/src/atoms/public-workspace/index.ts
@@ -25,7 +25,7 @@ function createPublicWorkspace(
);
blockSuiteWorkspace.awarenessStore.setFlag('enable_block_hub', false);
blockSuiteWorkspace.awarenessStore.setFlag('enable_set_remote_flag', false);
- blockSuiteWorkspace.awarenessStore.setFlag('enable_database', true);
+ blockSuiteWorkspace.awarenessStore.setFlag('enable_database', false);
blockSuiteWorkspace.awarenessStore.setFlag('enable_edgeless_toolbar', false);
blockSuiteWorkspace.awarenessStore.setFlag('enable_slash_menu', false);
blockSuiteWorkspace.awarenessStore.setFlag('enable_drag_handle', false);
diff --git a/apps/web/src/components/__tests__/PinBoard.spec.tsx b/apps/web/src/components/__tests__/PinBoard.spec.tsx
deleted file mode 100644
index 0021ef1625..0000000000
--- a/apps/web/src/components/__tests__/PinBoard.spec.tsx
+++ /dev/null
@@ -1,235 +0,0 @@
-/**
- * @vitest-environment happy-dom
- */
-import 'fake-indexeddb/auto';
-
-import { rootCurrentWorkspaceIdAtom } from '@affine/workspace/atom';
-import matchers from '@testing-library/jest-dom/matchers';
-import type { RenderResult } from '@testing-library/react';
-import { render, renderHook } from '@testing-library/react';
-import { createStore, getDefaultStore, Provider } from 'jotai';
-import type { FC, PropsWithChildren } from 'react';
-import { beforeEach, describe, expect, test } from 'vitest';
-
-import { workspacesAtom } from '../../atoms';
-import { rootCurrentWorkspaceAtom } from '../../atoms/root';
-import { useCurrentWorkspace } from '../../hooks/current/use-current-workspace';
-import { useAppHelper } from '../../hooks/use-workspaces';
-import { ThemeProvider } from '../../providers/ThemeProvider';
-import type { BlockSuiteWorkspace } from '../../shared';
-import type { PinboardProps } from '../pure/workspace-slider-bar/Pinboard';
-import Pinboard from '../pure/workspace-slider-bar/Pinboard';
-
-expect.extend(matchers);
-
-let store = getDefaultStore();
-beforeEach(async () => {
- store = createStore();
- await store.get(workspacesAtom);
-});
-
-const ProviderWrapper: FC<PropsWithChildren> = ({ children }) => {
- return <Provider store={store}>{children}</Provider>;
-};
-
-const initPinBoard = async () => {
- // create one workspace with 2 root pages and 2 pinboard pages
- // - hasPinboardPage
- // - hasPinboardPage
- // - pinboard1
- // - pinboard2
- // - noPinboardPage
-
- const mutationHook = renderHook(() => useAppHelper(), {
- wrapper: ProviderWrapper,
- });
- const rootPageIds = ['hasPinboardPage', 'noPinboardPage'];
- const pinboardPageIds = ['pinboard1', 'pinboard2'];
- const id = await mutationHook.result.current.createLocalWorkspace('test0');
-
- store.set(rootCurrentWorkspaceIdAtom, id);
- await store.get(workspacesAtom);
-
- await store.get(rootCurrentWorkspaceAtom);
- const currentWorkspaceHook = renderHook(() => useCurrentWorkspace(), {
- wrapper: ProviderWrapper,
- });
- currentWorkspaceHook.result.current[1](id);
- const currentWorkspace = await store.get(rootCurrentWorkspaceAtom);
- const blockSuiteWorkspace =
- currentWorkspace?.blockSuiteWorkspace as BlockSuiteWorkspace;
-
- mutationHook.rerender();
- // create root pinboard
- mutationHook.result.current.createWorkspacePage(id, 'rootPinboard');
- blockSuiteWorkspace.meta.setPageMeta('rootPinboard', {
- isRootPinboard: true,
- subpageIds: rootPageIds,
- });
- // create parent
- rootPageIds.forEach(rootPageId => {
- mutationHook.result.current.createWorkspacePage(id, rootPageId);
- blockSuiteWorkspace.meta.setPageMeta(rootPageId, {
- subpageIds: rootPageId === rootPageIds[0] ? pinboardPageIds : [],
- });
- });
- // create children to first parent
- pinboardPageIds.forEach(pinboardId => {
- mutationHook.result.current.createWorkspacePage(id, pinboardId);
- blockSuiteWorkspace.meta.setPageMeta(pinboardId, {
- title: pinboardId,
- });
- });
-
- const App = (props: PinboardProps) => {
- return (
- <ThemeProvider>
- <ProviderWrapper>
- <Pinboard {...props} />
- </ProviderWrapper>
- </ThemeProvider>
- );
- };
-
- const app = render(
- <App
- blockSuiteWorkspace={blockSuiteWorkspace as BlockSuiteWorkspace}
- openPage={() => {}}
- />
- );
-
- return {
- rootPageIds,
- pinboardPageIds,
- app,
- blockSuiteWorkspace,
- };
-};
-const openOperationMenu = async (app: RenderResult, pageId: string) => {
- const rootPinboard = await app.findByTestId(`pinboard-${pageId}`);
- const operationBtn = (await rootPinboard.querySelector(
- '[data-testid="pinboard-operation-button"]'
- )) as HTMLElement;
- await operationBtn.click();
- const menu = await app.findByTestId('pinboard-operation-menu');
- expect(menu).toBeInTheDocument();
-};
-describe('PinBoard', () => {
- test('add pinboard', async () => {
- const { app, blockSuiteWorkspace, rootPageIds } = await initPinBoard();
- const [hasChildrenPageId] = rootPageIds;
- await openOperationMenu(app, hasChildrenPageId);
-
- const addBtn = await app.findByTestId('pinboard-operation-add');
- await addBtn.click();
-
- const hasChildrenPageMeta =
- blockSuiteWorkspace.meta.getPageMeta(hasChildrenPageId);
-
- // Page meta have been added
- expect(blockSuiteWorkspace.meta.pageMetas.length).toBe(6);
- // New page meta is added in initial page meta
-
- expect(hasChildrenPageMeta?.subpageIds.length).toBe(3);
- app.unmount();
- });
-
- test('delete pinboard', async () => {
- const {
- app,
- blockSuiteWorkspace,
- rootPageIds: [hasChildrenPageId],
- } = await initPinBoard();
- await openOperationMenu(app, hasChildrenPageId);
-
- const deleteBtn = await app.findByTestId(
- 'pinboard-operation-move-to-trash'
- );
- await deleteBtn.click();
-
- const confirmBtn = await app.findByTestId('move-to-trash-confirm');
- expect(confirmBtn).toBeInTheDocument();
- await confirmBtn.click();
-
- // Every page should be tagged as trash
- expect(blockSuiteWorkspace.meta.pageMetas.filter(m => m.trash).length).toBe(
- 3
- );
- app.unmount();
- });
-
- test('rename pinboard', async () => {
- const {
- app,
- rootPageIds: [hasChildrenPageId],
- } = await initPinBoard();
- await openOperationMenu(app, hasChildrenPageId);
-
- const renameBtn = await app.findByTestId('pinboard-operation-rename');
- await renameBtn.click();
-
- const input = await app.findByTestId(`pinboard-input-${hasChildrenPageId}`);
- expect(input).toBeInTheDocument();
-
- // TODO: Fix this test
- // fireEvent.change(input, { target: { value: 'tteesstt' } });
- // expect(
- // blockSuiteWorkspace.meta.getPageMeta(hasChildrenPageId)?.name
- // ).toBe('tteesstt');
- app.unmount();
- });
-
- test('move pinboard', async () => {
- const {
- app,
- blockSuiteWorkspace,
- rootPageIds: [hasChildrenPageId],
- pinboardPageIds: [pinboardId1, pinboardId2],
- } = await initPinBoard();
- await openOperationMenu(app, pinboardId1);
-
- const moveToBtn = await app.findByTestId('pinboard-operation-move-to');
- await moveToBtn.click();
-
- const pinboardMenu = await app.findByTestId('pinboard-menu');
- expect(pinboardMenu).toBeInTheDocument();
-
- await (
- pinboardMenu.querySelector(
- `[data-testid="pinboard-${pinboardId2}"]`
- ) as HTMLElement
- ).click();
-
- const hasChildrenPageMeta =
- blockSuiteWorkspace.meta.getPageMeta(hasChildrenPageId);
-
- expect(hasChildrenPageMeta?.subpageIds.includes(pinboardId1)).toBe(false);
- expect(hasChildrenPageMeta?.subpageIds.includes(pinboardId2)).toBe(true);
- app.unmount();
- });
-
- test('remove from pinboard', async () => {
- const {
- app,
- blockSuiteWorkspace,
- rootPageIds: [hasChildrenPageId],
- pinboardPageIds: [pinboardId1],
- } = await initPinBoard();
- await openOperationMenu(app, pinboardId1);
-
- const moveToBtn = await app.findByTestId('pinboard-operation-move-to');
- await moveToBtn.click();
-
- const removeFromPinboardBtn = await app.findByTestId(
- 'remove-from-pinboard-button'
- );
- removeFromPinboardBtn.click();
-
- const hasPinboardPageMeta =
- blockSuiteWorkspace.meta.getPageMeta(hasChildrenPageId);
-
- expect(hasPinboardPageMeta?.subpageIds.length).toBe(1);
- expect(hasPinboardPageMeta?.subpageIds.includes(pinboardId1)).toBe(false);
- app.unmount();
- });
-});
diff --git a/apps/web/src/components/affine/pinboard/pinboard-menu/index.tsx b/apps/web/src/components/affine/pinboard/pinboard-menu/index.tsx
index d42e80751d..2457390ba7 100644
--- a/apps/web/src/components/affine/pinboard/pinboard-menu/index.tsx
+++ b/apps/web/src/components/affine/pinboard/pinboard-menu/index.tsx
@@ -3,9 +3,9 @@ import { Input, PureMenu, TreeView } from '@affine/component';
import { useTranslation } from '@affine/i18n';
import { RemoveIcon, SearchIcon } from '@blocksuite/icons';
import type { PageMeta } from '@blocksuite/store';
-import { usePageMetaHelper } from '@toeverything/hooks/use-block-suite-page-meta';
import React, { useCallback, useMemo, useState } from 'react';
+import { useReferenceLinkHelper } from '../../../../hooks/affine/use-reference-link-helper';
import { usePinboardData } from '../../../../hooks/use-pinboard-data';
import { usePinboardHandler } from '../../../../hooks/use-pinboard-handler';
import type { BlockSuiteWorkspace } from '../../../../shared';
@@ -41,13 +41,13 @@ export const PinboardMenu = ({
[currentMeta.id, propsMetas]
);
const { t } = useTranslation();
- const { setPageMeta } = usePageMetaHelper(blockSuiteWorkspace);
const [query, setQuery] = useState('');
const isSearching = query.length > 0;
const searchResult = metas.filter(
meta => !meta.trash && meta.title.includes(query)
);
+ const { removeReferenceLink } = useReferenceLinkHelper(blockSuiteWorkspace);
const { dropPin } = usePinboardHandler({
blockSuiteWorkspace,
@@ -117,16 +117,7 @@ export const PinboardMenu = ({
<StyledPinboard
data-testid={'remove-from-pinboard-button'}
onClick={() => {
- const parentMeta = metas.find(m =>
- m.subpageIds.includes(currentMeta.id)
- );
- if (!parentMeta) return;
- const newSubpageIds = [...parentMeta.subpageIds];
- const deleteIndex = newSubpageIds.findIndex(
- id => id === currentMeta.id
- );
- newSubpageIds.splice(deleteIndex, 1);
- setPageMeta(parentMeta.id, { subpageIds: newSubpageIds });
+ removeReferenceLink(currentMeta.id);
}}
>
<RemoveIcon />
diff --git a/apps/web/src/components/affine/pinboard/pinboard-render/AddButton.tsx b/apps/web/src/components/affine/pinboard/pinboard-render/AddButton.tsx
new file mode 100644
index 0000000000..45d6fa1b06
--- /dev/null
+++ b/apps/web/src/components/affine/pinboard/pinboard-render/AddButton.tsx
@@ -0,0 +1,22 @@
+import { PlusIcon } from '@blocksuite/icons';
+
+import { StyledOperationButton } from '../styles';
+import type { OperationButtonProps } from './OperationButton';
+
+export const AddButton = ({
+ onAdd,
+ visible,
+}: Pick<OperationButtonProps, 'onAdd' | 'visible'>) => {
+ return (
+ <StyledOperationButton
+ visible={visible}
+ size="small"
+ onClick={e => {
+ e.stopPropagation();
+ onAdd();
+ }}
+ >
+ <PlusIcon />
+ </StyledOperationButton>
+ );
+};
diff --git a/apps/web/src/components/affine/pinboard/pinboard-render/OperationButton.tsx b/apps/web/src/components/affine/pinboard/pinboard-render/OperationButton.tsx
index abe926b62b..af3cca9a04 100644
--- a/apps/web/src/components/affine/pinboard/pinboard-render/OperationButton.tsx
+++ b/apps/web/src/components/affine/pinboard/pinboard-render/OperationButton.tsx
@@ -28,7 +28,7 @@ export type OperationButtonProps = {
metas: PageMeta[];
currentMeta: PageMeta;
blockSuiteWorkspace: BlockSuiteWorkspace;
- isHover: boolean;
+ visible: boolean;
onRename?: () => void;
onMenuClose?: () => void;
};
@@ -39,7 +39,7 @@ export const OperationButton = ({
metas,
currentMeta,
blockSuiteWorkspace,
- isHover,
+ visible,
onMenuClose,
onRename,
}: OperationButtonProps) => {
@@ -61,6 +61,7 @@ export const OperationButton = ({
}}
>
<div
+ style={{ display: 'flex' }}
onClick={e => {
e.stopPropagation();
}}
@@ -81,7 +82,7 @@ export const OperationButton = ({
onClick={() => {
setOperationMenuOpen(!operationMenuOpen);
}}
- visible={isHover}
+ visible={visible}
>
<MoreVerticalIcon />
</StyledOperationButton>
diff --git a/apps/web/src/components/affine/pinboard/pinboard-render/index.tsx b/apps/web/src/components/affine/pinboard/pinboard-render/index.tsx
index 2e6497634e..0b2a1fa3f6 100644
--- a/apps/web/src/components/affine/pinboard/pinboard-render/index.tsx
+++ b/apps/web/src/components/affine/pinboard/pinboard-render/index.tsx
@@ -14,6 +14,7 @@ import { useMemo, useState } from 'react';
import { workspacePreferredModeAtom } from '../../../../atoms';
import type { PinboardNode } from '../../../../hooks/use-pinboard-data';
import { StyledCollapsedButton, StyledPinboard } from '../styles';
+import { AddButton } from './AddButton';
import EmptyItem from './EmptyItem';
import { OperationButton } from './OperationButton';
@@ -84,10 +85,8 @@ export const PinboardRender: PinboardNode['render'] = (
<ArrowDownSmallIcon />
</StyledCollapsedButton>
)}
-
{asPath && !isRoot ? <LevelIcon className="path-icon" /> : null}
{getIcon(isRoot ? 'root' : record[node.id])}
-
{showRename ? (
<Input
data-testid={`pinboard-input-${node.id}`}
@@ -106,6 +105,7 @@ export const PinboardRender: PinboardNode['render'] = (
) : (
<span>{isRoot ? 'Pinboard' : currentMeta.title || 'Untitled'}</span>
)}
+ {showOperationButton && <AddButton onAdd={onAdd} visible={isHover} />}
{showOperationButton && (
<OperationButton
@@ -115,7 +115,7 @@ export const PinboardRender: PinboardNode['render'] = (
metas={metas}
currentMeta={currentMeta!}
blockSuiteWorkspace={blockSuiteWorkspace!}
- isHover={isHover}
+ visible={isHover}
onMenuClose={() => setIsHover(false)}
onRename={() => {
setShowRename(true);
diff --git a/apps/web/src/hooks/affine/use-block-suite-meta-helper.ts b/apps/web/src/hooks/affine/use-block-suite-meta-helper.ts
index a838495307..38dd829803 100644
--- a/apps/web/src/hooks/affine/use-block-suite-meta-helper.ts
+++ b/apps/web/src/hooks/affine/use-block-suite-meta-helper.ts
@@ -5,11 +5,14 @@ import {
import { useCallback } from 'react';
import type { BlockSuiteWorkspace } from '../../shared';
+import { useReferenceLinkHelper } from './use-reference-link-helper';
export function useBlockSuiteMetaHelper(
blockSuiteWorkspace: BlockSuiteWorkspace
) {
const { setPageMeta, getPageMeta } = usePageMetaHelper(blockSuiteWorkspace);
+ const { addReferenceLink, removeReferenceLink } =
+ useReferenceLinkHelper(blockSuiteWorkspace);
const metas = useBlockSuitePageMeta(blockSuiteWorkspace);
const removeToTrash = useCallback(
@@ -29,17 +32,10 @@ export function useBlockSuiteMetaHelper(
// Just the trash root need delete its id from parent
if (parentMeta && isRoot) {
- const deleteIndex = parentMeta.subpageIds.findIndex(
- id => id === pageId
- );
- const newSubpageIds = [...parentMeta.subpageIds];
- newSubpageIds.splice(deleteIndex, 1);
- setPageMeta(parentMeta.id, {
- subpageIds: newSubpageIds,
- });
+ removeReferenceLink(pageId);
}
},
- [getPageMeta, metas, setPageMeta]
+ [getPageMeta, metas, removeReferenceLink, setPageMeta]
);
const restoreFromTrash = useCallback(
@@ -47,11 +43,7 @@ export function useBlockSuiteMetaHelper(
const { subpageIds = [], trashRelate } = getPageMeta(pageId) ?? {};
if (trashRelate) {
- const parentMeta = metas.find(m => m.id === trashRelate);
- parentMeta &&
- setPageMeta(parentMeta.id, {
- subpageIds: [...parentMeta.subpageIds, pageId],
- });
+ addReferenceLink(trashRelate, pageId);
}
setPageMeta(pageId, {
@@ -63,7 +55,7 @@ export function useBlockSuiteMetaHelper(
restoreFromTrash(id);
});
},
- [getPageMeta, metas, setPageMeta]
+ [addReferenceLink, getPageMeta, setPageMeta]
);
return {
diff --git a/apps/web/src/hooks/affine/use-reference-link-helper.ts b/apps/web/src/hooks/affine/use-reference-link-helper.ts
new file mode 100644
index 0000000000..67ef178cbb
--- /dev/null
+++ b/apps/web/src/hooks/affine/use-reference-link-helper.ts
@@ -0,0 +1,45 @@
+import { useCallback } from 'react';
+
+import type { BlockSuiteWorkspace } from '../../shared';
+
+export function useReferenceLinkHelper(
+ blockSuiteWorkspace: BlockSuiteWorkspace
+) {
+ const addReferenceLink = useCallback(
+ (pageId: string, referenceId: string) => {
+ const page = blockSuiteWorkspace?.getPage(pageId);
+ if (!page) {
+ return;
+ }
+ const text = page.Text.fromDelta([
+ {
+ insert: ' ',
+ attributes: {
+ reference: {
+ type: 'Subpage',
+ pageId: referenceId,
+ },
+ },
+ },
+ ]);
+ const [frame] = page.getBlockByFlavour('affine:frame');
+
+ frame && page.addBlock('affine:paragraph', { text }, frame.id);
+ },
+ [blockSuiteWorkspace]
+ );
+ const removeReferenceLink = useCallback(
+ (deleteId: string) => {
+ blockSuiteWorkspace.indexer.backlink.removeSubpageNode(
+ blockSuiteWorkspace,
+ deleteId
+ );
+ },
+ [blockSuiteWorkspace]
+ );
+
+ return {
+ addReferenceLink,
+ removeReferenceLink,
+ };
+}
diff --git a/apps/web/src/hooks/use-pinboard-handler.ts b/apps/web/src/hooks/use-pinboard-handler.ts
index 88b0fe619f..c0a0482638 100644
--- a/apps/web/src/hooks/use-pinboard-handler.ts
+++ b/apps/web/src/hooks/use-pinboard-handler.ts
@@ -4,10 +4,11 @@ import type { PageMeta } from '@blocksuite/store';
import { nanoid } from '@blocksuite/store';
import { usePageMetaHelper } from '@toeverything/hooks/use-block-suite-page-meta';
import { useBlockSuiteWorkspaceHelper } from '@toeverything/hooks/use-block-suite-workspace-helper';
-import { useCallback } from 'react';
+import { useCallback, useMemo } from 'react';
import type { BlockSuiteWorkspace } from '../shared';
import { useBlockSuiteMetaHelper } from './affine/use-block-suite-meta-helper';
+import { useReferenceLinkHelper } from './affine/use-reference-link-helper';
import type { NodeRenderProps } from './use-pinboard-data';
const logger = new DebugLogger('pinboard');
@@ -21,50 +22,32 @@ function findRootIds(metas: PageMeta[], id: string): string[] {
}
export function usePinboardHandler({
blockSuiteWorkspace,
- metas,
+ metas: propsMetas,
onAdd,
onDelete,
onDrop,
}: {
blockSuiteWorkspace: BlockSuiteWorkspace;
- metas: PageMeta[];
+ metas?: PageMeta[];
onAdd?: (addedId: string, parentId: string) => void;
onDelete?: TreeViewProps<NodeRenderProps>['onDelete'];
onDrop?: TreeViewProps<NodeRenderProps>['onDrop'];
}) {
+ const metas = useMemo(
+ () => propsMetas || blockSuiteWorkspace.meta.pageMetas || [],
+ [blockSuiteWorkspace.meta.pageMetas, propsMetas]
+ );
const { createPage } = useBlockSuiteWorkspaceHelper(blockSuiteWorkspace);
const { setPageMeta } = usePageMetaHelper(blockSuiteWorkspace);
const { removeToTrash: removeToTrashHelper } =
useBlockSuiteMetaHelper(blockSuiteWorkspace);
- // Just need handle add operation, delete check is handled in blockSuite's reference link
- const addReferenceLink = useCallback(
- (pageId: string, referenceId: string) => {
- const page = blockSuiteWorkspace?.getPage(pageId);
- if (!page) {
- return;
- }
- const text = page.Text.fromDelta([
- {
- insert: ' ',
- attributes: {
- reference: {
- type: 'Subpage',
- pageId: referenceId,
- },
- },
- },
- ]);
- const [frame] = page.getBlockByFlavour('affine:frame');
-
- frame && page.addBlock('affine:paragraph', { text }, frame.id);
- },
- [blockSuiteWorkspace]
- );
+ const { addReferenceLink, removeReferenceLink } =
+ useReferenceLinkHelper(blockSuiteWorkspace);
const addPin = useCallback(
(parentId: string) => {
const id = nanoid();
- createPage(id, parentId);
+ createPage(id);
onAdd?.(id, parentId);
addReferenceLink(parentId, id);
},
@@ -127,24 +110,7 @@ export function usePinboardHandler({
return onDrop?.(dragId, dropId, position);
}
// Old parent will delete drag node, new parent will be added
- const newDragParentSubpageIds = [...(dragParentMeta?.subpageIds ?? [])];
- const deleteIndex = newDragParentSubpageIds.findIndex(
- id => id === dragId
- );
- newDragParentSubpageIds.splice(deleteIndex, 1);
-
- const newDropParentSubpageIds = [...(dropParentMeta?.subpageIds ?? [])];
- const insertIndex =
- newDropParentSubpageIds.findIndex(id => id === dropId) + insertOffset;
- newDropParentSubpageIds.splice(insertIndex, 0, dragId);
- dragParentMeta &&
- setPageMeta(dragParentMeta.id, {
- subpageIds: newDragParentSubpageIds,
- });
- dropParentMeta &&
- setPageMeta(dropParentMeta.id, {
- subpageIds: newDropParentSubpageIds,
- });
+ removeReferenceLink(dragId);
dropParentMeta && addReferenceLink(dropParentMeta.id, dragId);
return onDrop?.(dragId, dropId, position);
}
@@ -154,23 +120,12 @@ export function usePinboardHandler({
return;
}
if (dragParentMeta) {
- const metaIndex = dragParentMeta.subpageIds.findIndex(
- id => id === dragId
- );
- const newSubpageIds = [...dragParentMeta.subpageIds];
- newSubpageIds.splice(metaIndex, 1);
- setPageMeta(dragParentMeta.id, {
- subpageIds: newSubpageIds,
- });
+ removeReferenceLink(dragId);
}
const dropMeta = metas.find(meta => meta.id === dropId)!;
- const newSubpageIds = [dragId, ...(dropMeta.subpageIds ?? [])];
- setPageMeta(dropMeta.id, {
- subpageIds: newSubpageIds,
- });
addReferenceLink(dropMeta.id, dragId);
},
- [addReferenceLink, metas, onDrop, setPageMeta]
+ [addReferenceLink, metas, onDrop, removeReferenceLink, setPageMeta]
);
return {
diff --git a/apps/web/src/pages/workspace/[workspaceId]/[pageId].tsx b/apps/web/src/pages/workspace/[workspaceId]/[pageId].tsx
index afe722d277..48043e3a39 100644
--- a/apps/web/src/pages/workspace/[workspaceId]/[pageId].tsx
+++ b/apps/web/src/pages/workspace/[workspaceId]/[pageId].tsx
@@ -27,7 +27,7 @@ import type { BlockSuiteWorkspace, NextPageWithLayout } from '../../../shared';
function enableFullFlags(blockSuiteWorkspace: BlockSuiteWorkspace) {
blockSuiteWorkspace.awarenessStore.setFlag('enable_set_remote_flag', false);
- blockSuiteWorkspace.awarenessStore.setFlag('enable_database', true);
+ blockSuiteWorkspace.awarenessStore.setFlag('enable_database', false);
blockSuiteWorkspace.awarenessStore.setFlag('enable_slash_menu', true);
blockSuiteWorkspace.awarenessStore.setFlag('enable_edgeless_toolbar', true);
blockSuiteWorkspace.awarenessStore.setFlag('enable_block_hub', true);
diff --git a/packages/component/package.json b/packages/component/package.json
index 9d616d14c6..e5b6b87e8e 100644
--- a/packages/component/package.json
+++ b/packages/component/package.json
@@ -45,11 +45,11 @@
"react-is": "^18.2.0"
},
"devDependencies": {
- "@blocksuite/blocks": "0.0.0-20230420160324-857b396c-nightly",
- "@blocksuite/editor": "0.0.0-20230420160324-857b396c-nightly",
- "@blocksuite/global": "0.0.0-20230420160324-857b396c-nightly",
+ "@blocksuite/blocks": "0.0.0-20230420210727-85b7de79-nightly",
+ "@blocksuite/editor": "0.0.0-20230420210727-85b7de79-nightly",
+ "@blocksuite/global": "0.0.0-20230420210727-85b7de79-nightly",
"@blocksuite/icons": "^2.1.10",
- "@blocksuite/store": "0.0.0-20230420160324-857b396c-nightly",
+ "@blocksuite/store": "0.0.0-20230420210727-85b7de79-nightly",
"@storybook/addon-actions": "^7.0.5",
"@storybook/addon-coverage": "^0.0.8",
"@storybook/addon-essentials": "^7.0.5",
diff --git a/packages/component/src/ui/tree-view/TreeView.tsx b/packages/component/src/ui/tree-view/TreeView.tsx
index 0a256a023d..5799e32fc0 100644
--- a/packages/component/src/ui/tree-view/TreeView.tsx
+++ b/packages/component/src/ui/tree-view/TreeView.tsx
@@ -1,12 +1,11 @@
-import type {
- DragEndEvent} from '@dnd-kit/core';
+import type { DragEndEvent } from '@dnd-kit/core';
import {
closestCenter,
DndContext,
DragOverlay,
PointerSensor,
useSensor,
- useSensors
+ useSensors,
} from '@dnd-kit/core';
import { useCallback, useState } from 'react';
@@ -47,7 +46,7 @@ export const TreeView = <RenderProps,>({
const { active, over } = e;
const position = over?.data.current?.position;
const dropId = over?.data.current?.node.id;
-
+ setDraggingId(undefined);
if (!over || !active || !position) {
return;
}
diff --git a/packages/env/package.json b/packages/env/package.json
index 27d261342c..a21f24bb81 100644
--- a/packages/env/package.json
+++ b/packages/env/package.json
@@ -4,7 +4,7 @@
"main": "./src/index.ts",
"module": "./src/index.ts",
"devDependencies": {
- "@blocksuite/global": "0.0.0-20230420160324-857b396c-nightly",
+ "@blocksuite/global": "0.0.0-20230420210727-85b7de79-nightly",
"next": "=13.2.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
diff --git a/packages/hooks/src/use-block-suite-workspace-helper.ts b/packages/hooks/src/use-block-suite-workspace-helper.ts
index 6c69d9800a..096dbee579 100644
--- a/packages/hooks/src/use-block-suite-workspace-helper.ts
+++ b/packages/hooks/src/use-block-suite-workspace-helper.ts
@@ -10,9 +10,9 @@ import { useMemo } from 'react';
export function useBlockSuiteWorkspaceHelper(blockSuiteWorkspace: Workspace) {
return useMemo(
() => ({
- createPage: (pageId: string, parentId?: string): Page => {
+ createPage: (pageId: string): Page => {
assertExists(blockSuiteWorkspace);
- return blockSuiteWorkspace.createPage(pageId, parentId);
+ return blockSuiteWorkspace.createPage(pageId);
},
markMilestone: async (name: string) => {
assertExists(blockSuiteWorkspace);
diff --git a/packages/jotai/package.json b/packages/jotai/package.json
index d770e0fe87..d78a60f1af 100644
--- a/packages/jotai/package.json
+++ b/packages/jotai/package.json
@@ -7,10 +7,10 @@
"jotai": "^2.0.4"
},
"devDependencies": {
- "@blocksuite/blocks": "0.0.0-20230420160324-857b396c-nightly",
- "@blocksuite/editor": "0.0.0-20230420160324-857b396c-nightly",
- "@blocksuite/global": "0.0.0-20230420160324-857b396c-nightly",
- "@blocksuite/store": "0.0.0-20230420160324-857b396c-nightly",
+ "@blocksuite/blocks": "0.0.0-20230420210727-85b7de79-nightly",
+ "@blocksuite/editor": "0.0.0-20230420210727-85b7de79-nightly",
+ "@blocksuite/global": "0.0.0-20230420210727-85b7de79-nightly",
+ "@blocksuite/store": "0.0.0-20230420210727-85b7de79-nightly",
"lottie-web": "^5.11.0"
},
"peerDependencies": {
diff --git a/packages/y-indexeddb/package.json b/packages/y-indexeddb/package.json
index 3f5961fe2e..5d1a5e7169 100644
--- a/packages/y-indexeddb/package.json
+++ b/packages/y-indexeddb/package.json
@@ -27,8 +27,8 @@
"idb": "^7.1.1"
},
"devDependencies": {
- "@blocksuite/blocks": "0.0.0-20230420160324-857b396c-nightly",
- "@blocksuite/store": "0.0.0-20230420160324-857b396c-nightly",
+ "@blocksuite/blocks": "0.0.0-20230420210727-85b7de79-nightly",
+ "@blocksuite/store": "0.0.0-20230420210727-85b7de79-nightly",
"vite": "^4.2.1",
"vite-plugin-dts": "^2.2.0",
"y-indexeddb": "^9.0.10"
diff --git a/yarn.lock b/yarn.lock
index 046b8a4219..ca4c575a5a 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -38,11 +38,11 @@ __metadata:
"@affine/i18n": "workspace:*"
"@affine/jotai": "workspace:*"
"@affine/workspace": "workspace:^"
- "@blocksuite/blocks": 0.0.0-20230420160324-857b396c-nightly
- "@blocksuite/editor": 0.0.0-20230420160324-857b396c-nightly
- "@blocksuite/global": 0.0.0-20230420160324-857b396c-nightly
+ "@blocksuite/blocks": 0.0.0-20230420210727-85b7de79-nightly
+ "@blocksuite/editor": 0.0.0-20230420210727-85b7de79-nightly
+ "@blocksuite/global": 0.0.0-20230420210727-85b7de79-nightly
"@blocksuite/icons": ^2.1.10
- "@blocksuite/store": 0.0.0-20230420160324-857b396c-nightly
+ "@blocksuite/store": 0.0.0-20230420210727-85b7de79-nightly
"@dnd-kit/core": ^6.0.8
"@dnd-kit/sortable": ^7.0.2
"@emotion/cache": ^11.10.7
@@ -139,7 +139,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@affine/env@workspace:packages/env"
dependencies:
- "@blocksuite/global": 0.0.0-20230420160324-857b396c-nightly
+ "@blocksuite/global": 0.0.0-20230420210727-85b7de79-nightly
lit: ^2.7.2
next: =13.2.3
react: ^18.2.0
@@ -173,10 +173,10 @@ __metadata:
resolution: "@affine/jotai@workspace:packages/jotai"
dependencies:
"@affine/env": "workspace:*"
- "@blocksuite/blocks": 0.0.0-20230420160324-857b396c-nightly
- "@blocksuite/editor": 0.0.0-20230420160324-857b396c-nightly
- "@blocksuite/global": 0.0.0-20230420160324-857b396c-nightly
- "@blocksuite/store": 0.0.0-20230420160324-857b396c-nightly
+ "@blocksuite/blocks": 0.0.0-20230420210727-85b7de79-nightly
+ "@blocksuite/editor": 0.0.0-20230420210727-85b7de79-nightly
+ "@blocksuite/global": 0.0.0-20230420210727-85b7de79-nightly
+ "@blocksuite/store": 0.0.0-20230420210727-85b7de79-nightly
jotai: ^2.0.4
lottie-web: ^5.11.0
peerDependencies:
@@ -248,11 +248,11 @@ __metadata:
"@affine/jotai": "workspace:*"
"@affine/templates": "workspace:*"
"@affine/workspace": "workspace:*"
- "@blocksuite/blocks": 0.0.0-20230420160324-857b396c-nightly
- "@blocksuite/editor": 0.0.0-20230420160324-857b396c-nightly
- "@blocksuite/global": 0.0.0-20230420160324-857b396c-nightly
+ "@blocksuite/blocks": 0.0.0-20230420210727-85b7de79-nightly
+ "@blocksuite/editor": 0.0.0-20230420210727-85b7de79-nightly
+ "@blocksuite/global": 0.0.0-20230420210727-85b7de79-nightly
"@blocksuite/icons": ^2.1.10
- "@blocksuite/store": 0.0.0-20230420160324-857b396c-nightly
+ "@blocksuite/store": 0.0.0-20230420210727-85b7de79-nightly
"@dnd-kit/core": ^6.0.8
"@dnd-kit/sortable": ^7.0.2
"@emotion/cache": ^11.10.7
@@ -2046,14 +2046,14 @@ __metadata:
languageName: node
linkType: hard
-"@blocksuite/blocks@npm:0.0.0-20230420160324-857b396c-nightly":
- version: 0.0.0-20230420160324-857b396c-nightly
- resolution: "@blocksuite/blocks@npm:0.0.0-20230420160324-857b396c-nightly"
+"@blocksuite/blocks@npm:0.0.0-20230420210727-85b7de79-nightly":
+ version: 0.0.0-20230420210727-85b7de79-nightly
+ resolution: "@blocksuite/blocks@npm:0.0.0-20230420210727-85b7de79-nightly"
dependencies:
- "@blocksuite/connector": 0.0.0-20230420160324-857b396c-nightly
- "@blocksuite/global": 0.0.0-20230420160324-857b396c-nightly
- "@blocksuite/phasor": 0.0.0-20230420160324-857b396c-nightly
- "@blocksuite/virgo": 0.0.0-20230420160324-857b396c-nightly
+ "@blocksuite/connector": 0.0.0-20230420210727-85b7de79-nightly
+ "@blocksuite/global": 0.0.0-20230420210727-85b7de79-nightly
+ "@blocksuite/phasor": 0.0.0-20230420210727-85b7de79-nightly
+ "@blocksuite/virgo": 0.0.0-20230420210727-85b7de79-nightly
"@popperjs/core": ^2.11.6
hotkeys-js: ^3.10.1
lit: ^2.6.1
@@ -2062,36 +2062,36 @@ __metadata:
turndown: ^7.1.1
zod: ^3.21.4
peerDependencies:
- "@blocksuite/store": 0.0.0-20230420160324-857b396c-nightly
- checksum: 629fefbed1aa45c8a8672df9d75fbb9ee23351278d5e7c05af81ac1a5f4d07eba79d017340baace53c0a644654284bb41bb3056662bc8eb16751e7c22a496337
+ "@blocksuite/store": 0.0.0-20230420210727-85b7de79-nightly
+ checksum: db77e6eea73249792fb923d0e219a7f9192f42eb90d2331e7148504b024777973fd29b06c543157be821fa52e2858718ea7b8a35bf5d93ff70d2a112d30b886d
languageName: node
linkType: hard
-"@blocksuite/connector@npm:0.0.0-20230420160324-857b396c-nightly":
- version: 0.0.0-20230420160324-857b396c-nightly
- resolution: "@blocksuite/connector@npm:0.0.0-20230420160324-857b396c-nightly"
- checksum: 8c6d65e73722265e2c0c537947a14720fae1db6fa11d74ecb78bbc2b9d9124da52eeb4b9387a9383edb548acce568b14185d4f47739efa28f81dbf14f13d5395
+"@blocksuite/connector@npm:0.0.0-20230420210727-85b7de79-nightly":
+ version: 0.0.0-20230420210727-85b7de79-nightly
+ resolution: "@blocksuite/connector@npm:0.0.0-20230420210727-85b7de79-nightly"
+ checksum: 25cd55b2ca735935f314df56cd2e02d7949fb2e629b75ff49ad9207bd815d3047c36a783bf9a2d6f17e78d18fefe707ce097e5867fa6a864f9caf2d5d648c700
languageName: node
linkType: hard
-"@blocksuite/editor@npm:0.0.0-20230420160324-857b396c-nightly":
- version: 0.0.0-20230420160324-857b396c-nightly
- resolution: "@blocksuite/editor@npm:0.0.0-20230420160324-857b396c-nightly"
+"@blocksuite/editor@npm:0.0.0-20230420210727-85b7de79-nightly":
+ version: 0.0.0-20230420210727-85b7de79-nightly
+ resolution: "@blocksuite/editor@npm:0.0.0-20230420210727-85b7de79-nightly"
dependencies:
- "@blocksuite/global": 0.0.0-20230420160324-857b396c-nightly
+ "@blocksuite/global": 0.0.0-20230420210727-85b7de79-nightly
lit: ^2.6.1
marked: ^4.2.12
turndown: ^7.1.1
peerDependencies:
- "@blocksuite/blocks": 0.0.0-20230420160324-857b396c-nightly
- "@blocksuite/store": 0.0.0-20230420160324-857b396c-nightly
- checksum: eca3f2e3edfa13d6fb15eb789fb03b572a4394be624f3fcbb2eda5b9028e46e17fcd0f68962368c702a3684e1a73adddb76f5690fcf6bf569d38f695935e3003
+ "@blocksuite/blocks": 0.0.0-20230420210727-85b7de79-nightly
+ "@blocksuite/store": 0.0.0-20230420210727-85b7de79-nightly
+ checksum: 5d35e374cc2f217587f5020bb20eafd011b652f3f36004b8bbd9ea45a7a4469e61ec08458e0c37d32c66612f1386b8b3364ff8144af61e52fa53d2bb17baa62c
languageName: node
linkType: hard
-"@blocksuite/global@npm:0.0.0-20230420160324-857b396c-nightly":
- version: 0.0.0-20230420160324-857b396c-nightly
- resolution: "@blocksuite/global@npm:0.0.0-20230420160324-857b396c-nightly"
+"@blocksuite/global@npm:0.0.0-20230420210727-85b7de79-nightly":
+ version: 0.0.0-20230420210727-85b7de79-nightly
+ resolution: "@blocksuite/global@npm:0.0.0-20230420210727-85b7de79-nightly"
dependencies:
ansi-colors: ^4.1.3
zod: ^3.21.4
@@ -2100,7 +2100,7 @@ __metadata:
peerDependenciesMeta:
lit:
optional: true
- checksum: 2ab996bbc43ac5cffdd43ba3f4f632d68b01c23f2c647ea19e092f087b434ea4f117c00a848e9fbeb6cdef45b41c5a731ff3f0635c7b5f3974bc554a8ea88b40
+ checksum: 8dea674935ce703601eb528bd18c498c2cea0469a741f28f342606f6ab9eb088be3074a73ce5a7fefe987890326fcd3f3a3deda4a88c8b4a2087d5fac3def137
languageName: node
linkType: hard
@@ -2114,25 +2114,25 @@ __metadata:
languageName: node
linkType: hard
-"@blocksuite/phasor@npm:0.0.0-20230420160324-857b396c-nightly":
- version: 0.0.0-20230420160324-857b396c-nightly
- resolution: "@blocksuite/phasor@npm:0.0.0-20230420160324-857b396c-nightly"
+"@blocksuite/phasor@npm:0.0.0-20230420210727-85b7de79-nightly":
+ version: 0.0.0-20230420210727-85b7de79-nightly
+ resolution: "@blocksuite/phasor@npm:0.0.0-20230420210727-85b7de79-nightly"
dependencies:
- "@blocksuite/global": 0.0.0-20230420160324-857b396c-nightly
+ "@blocksuite/global": 0.0.0-20230420210727-85b7de79-nightly
fractional-indexing: ^3.2.0
peerDependencies:
nanoid: ^4
yjs: ^13
- checksum: 4651d0ee841a0305ef0194c6d8fa18e190fa985df66d86558c36eb5209f8e829b10fdd17b8c9a4d0f801caf3a0ea5f7b6a9101b672f12d4bba9c537c748c5e86
+ checksum: 6b08fcdd8a576746dd64b59ab380012e4b0d280801515b7f74bbe108f7ede58af120e209ca082234bdece25a1e58e993d4549c9f82f3b8a6be26b024f965c21d
languageName: node
linkType: hard
-"@blocksuite/store@npm:0.0.0-20230420160324-857b396c-nightly":
- version: 0.0.0-20230420160324-857b396c-nightly
- resolution: "@blocksuite/store@npm:0.0.0-20230420160324-857b396c-nightly"
+"@blocksuite/store@npm:0.0.0-20230420210727-85b7de79-nightly":
+ version: 0.0.0-20230420210727-85b7de79-nightly
+ resolution: "@blocksuite/store@npm:0.0.0-20230420210727-85b7de79-nightly"
dependencies:
- "@blocksuite/global": 0.0.0-20230420160324-857b396c-nightly
- "@blocksuite/virgo": 0.0.0-20230420160324-857b396c-nightly
+ "@blocksuite/global": 0.0.0-20230420210727-85b7de79-nightly
+ "@blocksuite/virgo": 0.0.0-20230420210727-85b7de79-nightly
"@types/flexsearch": ^0.7.3
buffer: ^6.0.3
flexsearch: 0.7.21
@@ -2146,20 +2146,20 @@ __metadata:
zod: ^3.21.4
peerDependencies:
yjs: ^13
- checksum: a6629b1f62f54bf8583679bdce5077f950ea4b27b2ba08a1d563f7efa44a2800342def7d64ad4f8d95491214b94acb463cf5959e3438fb75281db68565c0c0c1
+ checksum: 9a8f293d4d5480e8dc6a45ed5d01eebf551a2c94543f1ddef0d1707a3b193cb5ade5c05a79d3c91a5c3e4b29752a9dded2f037ea379f437e9a53fe9460e03f92
languageName: node
linkType: hard
-"@blocksuite/virgo@npm:0.0.0-20230420160324-857b396c-nightly":
- version: 0.0.0-20230420160324-857b396c-nightly
- resolution: "@blocksuite/virgo@npm:0.0.0-20230420160324-857b396c-nightly"
+"@blocksuite/virgo@npm:0.0.0-20230420210727-85b7de79-nightly":
+ version: 0.0.0-20230420210727-85b7de79-nightly
+ resolution: "@blocksuite/virgo@npm:0.0.0-20230420210727-85b7de79-nightly"
dependencies:
- "@blocksuite/global": 0.0.0-20230420160324-857b396c-nightly
+ "@blocksuite/global": 0.0.0-20230420210727-85b7de79-nightly
zod: ^3.21.4
peerDependencies:
lit: ^2
yjs: ^13
- checksum: e46dc780536c83e29bd6688f6b02e2e3b84dc99d068827f8d85d4a79700ee8d6e6207de89ec0ff6c31ccd7d51b123f244c6c2952fc06d8f2ef5ec880a04441a3
+ checksum: 9e887260fbb5517ebe1495ac853ac66131f5593fd0b5eb20caf946aa7c9c59bf7173155752ea5a0310d245550b7c7bf0d9f3163c4acfbee9af75ce0200b5f9ff
languageName: node
linkType: hard
@@ -7581,8 +7581,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "@toeverything/y-indexeddb@workspace:packages/y-indexeddb"
dependencies:
- "@blocksuite/blocks": 0.0.0-20230420160324-857b396c-nightly
- "@blocksuite/store": 0.0.0-20230420160324-857b396c-nightly
+ "@blocksuite/blocks": 0.0.0-20230420210727-85b7de79-nightly
+ "@blocksuite/store": 0.0.0-20230420210727-85b7de79-nightly
idb: ^7.1.1
vite: ^4.2.1
vite-plugin-dts: ^2.2.0