mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-22 03:33:06 +08:00
Merge pull request #678 from toeverything/0106/surface
feat: compat with surface block structure
This commit is contained in:
@@ -11,10 +11,10 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@affine/datacenter": "workspace:*",
|
"@affine/datacenter": "workspace:*",
|
||||||
"@blocksuite/blocks": "0.3.1",
|
"@blocksuite/blocks": "=0.3.1-20230106060050-1aad55d",
|
||||||
"@blocksuite/editor": "0.3.1",
|
"@blocksuite/editor": "=0.3.1-20230106060050-1aad55d",
|
||||||
"@blocksuite/icons": "^2.0.2",
|
"@blocksuite/icons": "^2.0.2",
|
||||||
"@blocksuite/store": "0.3.1",
|
"@blocksuite/store": "=0.3.1-20230106060050-1aad55d",
|
||||||
"@emotion/css": "^11.10.0",
|
"@emotion/css": "^11.10.0",
|
||||||
"@emotion/react": "^11.10.4",
|
"@emotion/react": "^11.10.4",
|
||||||
"@emotion/server": "^11.10.0",
|
"@emotion/server": "^11.10.0",
|
||||||
|
|||||||
@@ -22,14 +22,14 @@ export const EditorHeader = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
onPropsUpdated(editor => {
|
onPropsUpdated(editor => {
|
||||||
setTitle(editor.model?.title || 'Untitled');
|
setTitle(editor.pageBlockModel?.title || 'Untitled');
|
||||||
});
|
});
|
||||||
}, [onPropsUpdated]);
|
}, [onPropsUpdated]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
// If first time in, need to wait for editor to be inserted into DOM
|
// If first time in, need to wait for editor to be inserted into DOM
|
||||||
setTitle(editor?.model?.title || 'Untitled');
|
setTitle(editor?.pageBlockModel?.title || 'Untitled');
|
||||||
}, 300);
|
}, 300);
|
||||||
}, [editor]);
|
}, [editor]);
|
||||||
|
|
||||||
|
|||||||
@@ -31,9 +31,10 @@ export const ImportModal = ({ open, onClose }: ImportModalProps) => {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const editor = document.querySelector('editor-container');
|
const editor = document.querySelector('editor-container');
|
||||||
if (editor) {
|
if (editor) {
|
||||||
const groupId = page.addBlock({ flavour: 'affine:group' }, pageId);
|
page.addBlock({ flavour: 'affine:surface' }, null);
|
||||||
|
const frameId = page.addBlock({ flavour: 'affine:frame' }, pageId);
|
||||||
// TODO blocksuite should offer a method to import markdown from store
|
// TODO blocksuite should offer a method to import markdown from store
|
||||||
editor.clipboard.importMarkdown(template.source, `${groupId}`);
|
editor.clipboard.importMarkdown(template.source, `${frameId}`);
|
||||||
page.resetHistory();
|
page.resetHistory();
|
||||||
editor.requestUpdate();
|
editor.requestUpdate();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export const usePropsUpdated: UsePropsUpdated = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
editor.model?.propsUpdated.on(() => {
|
editor.pageBlockModel?.propsUpdated.on(() => {
|
||||||
callbackQueue.current.forEach(callback => {
|
callbackQueue.current.forEach(callback => {
|
||||||
callback(editor);
|
callback(editor);
|
||||||
});
|
});
|
||||||
@@ -26,7 +26,7 @@ export const usePropsUpdated: UsePropsUpdated = () => {
|
|||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
callbackQueue.current = [];
|
callbackQueue.current = [];
|
||||||
editor?.model?.propsUpdated.dispose();
|
editor?.pageBlockModel?.propsUpdated?.dispose();
|
||||||
};
|
};
|
||||||
}, [editor]);
|
}, [editor]);
|
||||||
|
|
||||||
|
|||||||
@@ -43,12 +43,16 @@ const All = () => {
|
|||||||
if (page) {
|
if (page) {
|
||||||
currentWorkspace?.setPageMeta(page.id, { title });
|
currentWorkspace?.setPageMeta(page.id, { title });
|
||||||
if (page && page.root === null) {
|
if (page && page.root === null) {
|
||||||
setTimeout(() => {
|
setTimeout(async () => {
|
||||||
const editor = document.querySelector('editor-container');
|
const editor = document.querySelector('editor-container');
|
||||||
if (editor) {
|
if (editor) {
|
||||||
const groupId = page.addBlock({ flavour: 'affine:group' }, pageId);
|
page.addBlock({ flavour: 'affine:surface' }, null);
|
||||||
|
const frameId = page.addBlock({ flavour: 'affine:frame' }, pageId);
|
||||||
// TODO blocksuite should offer a method to import markdown from store
|
// TODO blocksuite should offer a method to import markdown from store
|
||||||
editor.clipboard.importMarkdown(template.source, `${groupId}`);
|
await editor.clipboard.importMarkdown(
|
||||||
|
template.source,
|
||||||
|
`${frameId}`
|
||||||
|
);
|
||||||
page.resetHistory();
|
page.resetHistory();
|
||||||
editor.requestUpdate();
|
editor.requestUpdate();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,14 +55,15 @@ const Page: NextPageWithLayout = () => {
|
|||||||
flavour: 'affine:page',
|
flavour: 'affine:page',
|
||||||
title,
|
title,
|
||||||
});
|
});
|
||||||
const groupId = currentPage!.addBlock(
|
currentPage!.addBlock({ flavour: 'affine:surface' }, null);
|
||||||
{ flavour: 'affine:group' },
|
const frameId = currentPage!.addBlock(
|
||||||
|
{ flavour: 'affine:frame' },
|
||||||
pageId
|
pageId
|
||||||
);
|
);
|
||||||
currentPage!.addBlock({ flavour: 'affine:group' }, pageId);
|
currentPage!.addBlock({ flavour: 'affine:frame' }, pageId);
|
||||||
// If this is a first page in workspace, init an introduction markdown
|
// If this is a first page in workspace, init an introduction markdown
|
||||||
if (isFirstPage) {
|
if (isFirstPage) {
|
||||||
editor.clipboard.importMarkdown(exampleMarkdown, `${groupId}`);
|
editor.clipboard.importMarkdown(exampleMarkdown, `${frameId}`);
|
||||||
currentWorkspace!.setPageMeta(currentPage!.id, { title });
|
currentWorkspace!.setPageMeta(currentPage!.id, { title });
|
||||||
}
|
}
|
||||||
currentPage!.resetHistory();
|
currentPage!.resetHistory();
|
||||||
|
|||||||
@@ -26,8 +26,8 @@
|
|||||||
"typescript": "^4.8.4"
|
"typescript": "^4.8.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@blocksuite/blocks": "^0.3.1",
|
"@blocksuite/blocks": "=0.3.1-20230106060050-1aad55d",
|
||||||
"@blocksuite/store": "^0.3.1",
|
"@blocksuite/store": "=0.3.1-20230106060050-1aad55d",
|
||||||
"debug": "^4.3.4",
|
"debug": "^4.3.4",
|
||||||
"encoding": "^0.1.13",
|
"encoding": "^0.1.13",
|
||||||
"firebase": "^9.15.0",
|
"firebase": "^9.15.0",
|
||||||
|
|||||||
Generated
+28
-19
@@ -45,10 +45,10 @@ importers:
|
|||||||
packages/app:
|
packages/app:
|
||||||
specifiers:
|
specifiers:
|
||||||
'@affine/datacenter': workspace:*
|
'@affine/datacenter': workspace:*
|
||||||
'@blocksuite/blocks': 0.3.1
|
'@blocksuite/blocks': '=0.3.1-20230106060050-1aad55d'
|
||||||
'@blocksuite/editor': 0.3.1
|
'@blocksuite/editor': '=0.3.1-20230106060050-1aad55d'
|
||||||
'@blocksuite/icons': ^2.0.2
|
'@blocksuite/icons': ^2.0.2
|
||||||
'@blocksuite/store': 0.3.1
|
'@blocksuite/store': '=0.3.1-20230106060050-1aad55d'
|
||||||
'@emotion/css': ^11.10.0
|
'@emotion/css': ^11.10.0
|
||||||
'@emotion/react': ^11.10.4
|
'@emotion/react': ^11.10.4
|
||||||
'@emotion/server': ^11.10.0
|
'@emotion/server': ^11.10.0
|
||||||
@@ -87,10 +87,10 @@ importers:
|
|||||||
yjs: ^13.5.44
|
yjs: ^13.5.44
|
||||||
dependencies:
|
dependencies:
|
||||||
'@affine/datacenter': link:../data-center
|
'@affine/datacenter': link:../data-center
|
||||||
'@blocksuite/blocks': 0.3.1_yjs@13.5.44
|
'@blocksuite/blocks': 0.3.1-20230106060050-1aad55d_yjs@13.5.44
|
||||||
'@blocksuite/editor': 0.3.1_yjs@13.5.44
|
'@blocksuite/editor': 0.3.1-20230106060050-1aad55d_yjs@13.5.44
|
||||||
'@blocksuite/icons': 2.0.4_w5j4k42lgipnm43s3brx6h3c34
|
'@blocksuite/icons': 2.0.4_w5j4k42lgipnm43s3brx6h3c34
|
||||||
'@blocksuite/store': 0.3.1_yjs@13.5.44
|
'@blocksuite/store': 0.3.1-20230106060050-1aad55d_yjs@13.5.44
|
||||||
'@emotion/css': 11.10.0
|
'@emotion/css': 11.10.0
|
||||||
'@emotion/react': 11.10.4_w5j4k42lgipnm43s3brx6h3c34
|
'@emotion/react': 11.10.4_w5j4k42lgipnm43s3brx6h3c34
|
||||||
'@emotion/server': 11.10.0_@emotion+css@11.10.0
|
'@emotion/server': 11.10.0_@emotion+css@11.10.0
|
||||||
@@ -131,8 +131,8 @@ importers:
|
|||||||
|
|
||||||
packages/data-center:
|
packages/data-center:
|
||||||
specifiers:
|
specifiers:
|
||||||
'@blocksuite/blocks': ^0.3.1
|
'@blocksuite/blocks': '=0.3.1-20230106060050-1aad55d'
|
||||||
'@blocksuite/store': ^0.3.1
|
'@blocksuite/store': '=0.3.1-20230106060050-1aad55d'
|
||||||
'@playwright/test': ^1.29.1
|
'@playwright/test': ^1.29.1
|
||||||
'@types/debug': ^4.1.7
|
'@types/debug': ^4.1.7
|
||||||
debug: ^4.3.4
|
debug: ^4.3.4
|
||||||
@@ -148,8 +148,8 @@ importers:
|
|||||||
y-protocols: ^1.0.5
|
y-protocols: ^1.0.5
|
||||||
yjs: ^13.5.44
|
yjs: ^13.5.44
|
||||||
dependencies:
|
dependencies:
|
||||||
'@blocksuite/blocks': 0.3.1_yjs@13.5.44
|
'@blocksuite/blocks': 0.3.1-20230106060050-1aad55d_yjs@13.5.44
|
||||||
'@blocksuite/store': 0.3.1_yjs@13.5.44
|
'@blocksuite/store': 0.3.1-20230106060050-1aad55d_yjs@13.5.44
|
||||||
debug: 4.3.4
|
debug: 4.3.4
|
||||||
encoding: 0.1.13
|
encoding: 0.1.13
|
||||||
firebase: 9.15.0_encoding@0.1.13
|
firebase: 9.15.0_encoding@0.1.13
|
||||||
@@ -1496,10 +1496,11 @@ packages:
|
|||||||
resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==}
|
resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/@blocksuite/blocks/0.3.1_yjs@13.5.44:
|
/@blocksuite/blocks/0.3.1-20230106060050-1aad55d_yjs@13.5.44:
|
||||||
resolution: {integrity: sha512-b0dGz2MG4yIgngJPRumaMY58wAsd2FEVSZl3tpCXlagK9I0HD165Bq70PxcaRHVjBSV1Gf29ZVHUF6BVTYogPw==}
|
resolution: {integrity: sha512-qRNXmhjw+GAGsV1mI2XXPxYTlHfsFHv9ttTCNQ6IIcxvc5Hh6lWmdwVibxvlpYUkgEc1zv3/GxOEsR/ngpZXzQ==}
|
||||||
dependencies:
|
dependencies:
|
||||||
'@blocksuite/store': 0.3.1_yjs@13.5.44
|
'@blocksuite/phasor': 0.3.1_yjs@13.5.44
|
||||||
|
'@blocksuite/store': 0.3.1-20230106060050-1aad55d_yjs@13.5.44
|
||||||
'@tldraw/intersect': 1.8.0
|
'@tldraw/intersect': 1.8.0
|
||||||
autosize: 5.0.2
|
autosize: 5.0.2
|
||||||
highlight.js: 11.7.0
|
highlight.js: 11.7.0
|
||||||
@@ -1515,11 +1516,11 @@ packages:
|
|||||||
- yjs
|
- yjs
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/@blocksuite/editor/0.3.1_yjs@13.5.44:
|
/@blocksuite/editor/0.3.1-20230106060050-1aad55d_yjs@13.5.44:
|
||||||
resolution: {integrity: sha512-ycKcyvPW6R8R2GZOFneGH1xNi5gJBx5WtWjW9YwcQslFzXVWMCCBips1Bud2uL4kkbWQoodyua6k2vsXxGAKLw==}
|
resolution: {integrity: sha512-wSlAF9XVxIkHFJ1qCzn7oQ/gwXybFYMrzRl35UTJV509D+DuWZefRZWvpdIDCOUJ24uQscr1HxwsON11ltfWgA==}
|
||||||
dependencies:
|
dependencies:
|
||||||
'@blocksuite/blocks': 0.3.1_yjs@13.5.44
|
'@blocksuite/blocks': 0.3.1-20230106060050-1aad55d_yjs@13.5.44
|
||||||
'@blocksuite/store': 0.3.1_yjs@13.5.44
|
'@blocksuite/store': 0.3.1-20230106060050-1aad55d_yjs@13.5.44
|
||||||
lit: 2.5.0
|
lit: 2.5.0
|
||||||
marked: 4.2.5
|
marked: 4.2.5
|
||||||
turndown: 7.1.1
|
turndown: 7.1.1
|
||||||
@@ -1540,8 +1541,16 @@ packages:
|
|||||||
react: 18.2.0
|
react: 18.2.0
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/@blocksuite/store/0.3.1_yjs@13.5.44:
|
/@blocksuite/phasor/0.3.1_yjs@13.5.44:
|
||||||
resolution: {integrity: sha512-kynVTDfNCSChz2JI2rtGHxRIV2YrLzvAgVajcbfDVCuXKG0siBoEjLasG1a0kvevbvW/FabrNAj+xaIplklioA==}
|
resolution: {integrity: sha512-aJmAQn2qoF6HxFZWgq7xa/pWVyzg3MmD6dynIHAKdfN7rBdKk3PNA+lRX919QkD2e270N/zgHEGFFQI1Nj5xrA==}
|
||||||
|
peerDependencies:
|
||||||
|
yjs: ^13
|
||||||
|
dependencies:
|
||||||
|
yjs: 13.5.44
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/@blocksuite/store/0.3.1-20230106060050-1aad55d_yjs@13.5.44:
|
||||||
|
resolution: {integrity: sha512-dRy+YzlWMwiYq0Im9NogK/NTkV+NKK+lgejYq56m6nH2m16/G9AMODqP0oQy/XeYFevUpL9i9RdV0rHsJ2gc0Q==}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
yjs: ^13
|
yjs: ^13
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|||||||
@@ -7,10 +7,13 @@ loadPage();
|
|||||||
const openQuickSearchByShortcut = async (page: Page) =>
|
const openQuickSearchByShortcut = async (page: Page) =>
|
||||||
await withCtrlOrMeta(page, () => page.keyboard.press('k', { delay: 50 }));
|
await withCtrlOrMeta(page, () => page.keyboard.press('k', { delay: 50 }));
|
||||||
|
|
||||||
async function assertTitleTexts(page: Page, texts: string[]) {
|
async function assertTitleTexts(page: Page, texts: string) {
|
||||||
const actual = await page
|
const actual = await page.evaluate(() => {
|
||||||
.locator('.affine-default-page-block-title')
|
const titleElement = <HTMLTextAreaElement>(
|
||||||
.allTextContents();
|
document.querySelector('.affine-default-page-block-title')
|
||||||
|
);
|
||||||
|
return titleElement.value;
|
||||||
|
});
|
||||||
expect(actual).toEqual(texts);
|
expect(actual).toEqual(texts);
|
||||||
}
|
}
|
||||||
async function assertResultList(page: Page, texts: string[]) {
|
async function assertResultList(page: Page, texts: string[]) {
|
||||||
@@ -55,7 +58,7 @@ test.describe('Add new page in quick search', () => {
|
|||||||
const addNewPage = page.locator('[data-testid=quickSearch-addNewPage]');
|
const addNewPage = page.locator('[data-testid=quickSearch-addNewPage]');
|
||||||
await addNewPage.click();
|
await addNewPage.click();
|
||||||
await page.waitForTimeout(200);
|
await page.waitForTimeout(200);
|
||||||
await assertTitleTexts(page, ['']);
|
await assertTitleTexts(page, '');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Create a new page with keyword', async ({ page }) => {
|
test('Create a new page with keyword', async ({ page }) => {
|
||||||
@@ -65,7 +68,7 @@ test.describe('Add new page in quick search', () => {
|
|||||||
const addNewPage = page.locator('[data-testid=quickSearch-addNewPage]');
|
const addNewPage = page.locator('[data-testid=quickSearch-addNewPage]');
|
||||||
await addNewPage.click();
|
await addNewPage.click();
|
||||||
await page.waitForTimeout(200);
|
await page.waitForTimeout(200);
|
||||||
await assertTitleTexts(page, ['test123456']);
|
await assertTitleTexts(page, 'test123456');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -81,6 +84,6 @@ test.describe('Search and select', () => {
|
|||||||
await page.keyboard.insertText('test123456');
|
await page.keyboard.insertText('test123456');
|
||||||
await assertResultList(page, ['test123456']);
|
await assertResultList(page, ['test123456']);
|
||||||
await page.keyboard.press('Enter', { delay: 50 });
|
await page.keyboard.press('Enter', { delay: 50 });
|
||||||
await assertTitleTexts(page, ['test123456']);
|
await assertTitleTexts(page, 'test123456');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user