feat!: unified migration logic in server electron, and browser (#4079)

Co-authored-by: Mirone <Saul-Mirone@outlook.com>
This commit is contained in:
Alex Yang
2023-09-06 00:44:53 -07:00
committed by GitHub
parent 925c18300f
commit 1b6a78cd00
61 changed files with 10776 additions and 10267 deletions
+5 -5
View File
@@ -52,12 +52,12 @@
"rxjs": "^7.8.1"
},
"devDependencies": {
"@blocksuite/blocks": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/editor": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/global": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/blocks": "0.0.0-20230905170607-94acf22c-nightly",
"@blocksuite/editor": "0.0.0-20230905170607-94acf22c-nightly",
"@blocksuite/global": "0.0.0-20230905170607-94acf22c-nightly",
"@blocksuite/icons": "^2.1.32",
"@blocksuite/lit": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/store": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/lit": "0.0.0-20230905170607-94acf22c-nightly",
"@blocksuite/store": "0.0.0-20230905170607-94acf22c-nightly",
"@types/react": "^18.2.21",
"@types/react-datepicker": "^4.15.0",
"@types/react-dnd": "^3.0.2",
@@ -1,12 +1,10 @@
import { editorContainerModuleAtom } from '@affine/jotai';
import type { BlockHub } from '@blocksuite/blocks';
import type { EditorContainer } from '@blocksuite/editor';
import { EditorContainer } from '@blocksuite/editor';
import { assertExists } from '@blocksuite/global/utils';
import type { LitBlockSpec } from '@blocksuite/lit';
import type { Page } from '@blocksuite/store';
import { Skeleton } from '@mui/material';
import { use } from 'foxact/use';
import { useAtomValue } from 'jotai';
import type { CSSProperties, ReactElement } from 'react';
import { memo, Suspense, useCallback, useEffect, useRef } from 'react';
import type { FallbackProps } from 'react-error-boundary';
@@ -45,14 +43,11 @@ const BlockSuiteEditorImpl = (props: EditorProps): ReactElement => {
if (!page.loaded) {
use(page.waitForLoaded());
}
const JotaiEditorContainer = useAtomValue(
editorContainerModuleAtom
) as typeof EditorContainer;
assertExists(page, 'page should not be null');
const editorRef = useRef<EditorContainer | null>(null);
const blockHubRef = useRef<BlockHub | null>(null);
if (editorRef.current === null) {
editorRef.current = new JotaiEditorContainer();
editorRef.current = new EditorContainer();
editorRef.current.autofocus = true;
globalThis.currentEditor = editorRef.current;
+1 -1
View File
@@ -5,7 +5,7 @@
"main": "./src/index.ts",
"module": "./src/index.ts",
"devDependencies": {
"@blocksuite/global": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/global": "0.0.0-20230905170607-94acf22c-nightly",
"react": "18.2.0",
"react-dom": "18.2.0",
"zod": "^3.22.2"
+6 -6
View File
@@ -12,12 +12,12 @@
"devDependencies": {
"@affine/env": "workspace:*",
"@affine/y-provider": "workspace:*",
"@blocksuite/block-std": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/blocks": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/editor": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/global": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/lit": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/store": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/block-std": "0.0.0-20230905170607-94acf22c-nightly",
"@blocksuite/blocks": "0.0.0-20230905170607-94acf22c-nightly",
"@blocksuite/editor": "0.0.0-20230905170607-94acf22c-nightly",
"@blocksuite/global": "0.0.0-20230905170607-94acf22c-nightly",
"@blocksuite/lit": "0.0.0-20230905170607-94acf22c-nightly",
"@blocksuite/store": "0.0.0-20230905170607-94acf22c-nightly",
"@types/lodash.debounce": "^4.0.7"
},
"peerDependencies": {
+5 -5
View File
@@ -50,15 +50,15 @@
},
"dependencies": {
"@affine/sdk": "workspace:*",
"@blocksuite/blocks": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/global": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/store": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/blocks": "0.0.0-20230905170607-94acf22c-nightly",
"@blocksuite/global": "0.0.0-20230905170607-94acf22c-nightly",
"@blocksuite/store": "0.0.0-20230905170607-94acf22c-nightly",
"jotai": "^2.4.1",
"zod": "^3.22.2"
},
"devDependencies": {
"@blocksuite/editor": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/lit": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/editor": "0.0.0-20230905170607-94acf22c-nightly",
"@blocksuite/lit": "0.0.0-20230905170607-94acf22c-nightly",
"async-call-rpc": "^6.3.1",
"electron": "link:../../apps/electron/node_modules/electron",
"react": "^18.2.0",
+4 -17
View File
@@ -1,11 +1,11 @@
import type { Workspace } from '@blocksuite/store';
import { type PassiveDocProvider } from '@blocksuite/store';
import { useAtomValue } from 'jotai/react';
import { useEffect } from 'react';
import {
disablePassiveProviders,
enablePassiveProviders,
getActiveBlockSuiteWorkspaceAtom,
workspacePassiveEffectWeakMap,
} from './workspace.js';
export function useStaticBlockSuiteWorkspace(id: string): Workspace {
@@ -14,22 +14,9 @@ export function useStaticBlockSuiteWorkspace(id: string): Workspace {
export function usePassiveWorkspaceEffect(workspace: Workspace) {
useEffect(() => {
if (workspacePassiveEffectWeakMap.get(workspace) === true) {
return;
}
const providers = workspace.providers.filter(
(provider): provider is PassiveDocProvider =>
'passive' in provider && provider.passive === true
);
providers.forEach(provider => {
provider.connect();
});
workspacePassiveEffectWeakMap.set(workspace, true);
enablePassiveProviders(workspace);
return () => {
providers.forEach(provider => {
provider.disconnect();
});
workspacePassiveEffectWeakMap.delete(workspace);
disablePassiveProviders(workspace);
};
}, [workspace]);
}
+35 -6
View File
@@ -1,4 +1,5 @@
import type { ActiveDocProvider, Workspace } from '@blocksuite/store';
import type { PassiveDocProvider } from '@blocksuite/store';
import type { Atom } from 'jotai/vanilla';
import { atom } from 'jotai/vanilla';
@@ -8,16 +9,44 @@ import { atom } from 'jotai/vanilla';
*/
export const INTERNAL_BLOCKSUITE_HASH_MAP = new Map<string, Workspace>([]);
const workspacePassiveAtomWeakMap = new WeakMap<
const workspaceActiveAtomWeakMap = new WeakMap<
Workspace,
Atom<Promise<Workspace>>
>();
// Whether the workspace is active to use
export const workspaceActiveWeakMap = new WeakMap<Workspace, boolean>();
const workspaceActiveWeakMap = new WeakMap<Workspace, boolean>();
// Whether the workspace has been enabled the passive effect (background)
export const workspacePassiveEffectWeakMap = new WeakMap<Workspace, boolean>();
const workspacePassiveEffectWeakMap = new WeakMap<Workspace, boolean>();
export function enablePassiveProviders(workspace: Workspace) {
if (workspacePassiveEffectWeakMap.get(workspace) === true) {
return;
}
const providers = workspace.providers.filter(
(provider): provider is PassiveDocProvider =>
'passive' in provider && provider.passive === true
);
providers.forEach(provider => {
provider.connect();
});
workspacePassiveEffectWeakMap.set(workspace, true);
}
export function disablePassiveProviders(workspace: Workspace) {
if (workspacePassiveEffectWeakMap.get(workspace) !== true) {
return;
}
const providers = workspace.providers.filter(
(provider): provider is PassiveDocProvider =>
'passive' in provider && provider.passive === true
);
providers.forEach(provider => {
provider.disconnect();
});
workspacePassiveEffectWeakMap.delete(workspace);
}
export async function waitForWorkspace(workspace: Workspace) {
if (workspaceActiveWeakMap.get(workspace) !== true) {
@@ -48,12 +77,12 @@ export function getActiveBlockSuiteWorkspaceAtom(
throw new Error('Workspace not found');
}
const workspace = INTERNAL_BLOCKSUITE_HASH_MAP.get(id) as Workspace;
if (!workspacePassiveAtomWeakMap.has(workspace)) {
if (!workspaceActiveAtomWeakMap.has(workspace)) {
const baseAtom = atom(async () => {
await waitForWorkspace(workspace);
return workspace;
});
workspacePassiveAtomWeakMap.set(workspace, baseAtom);
workspaceActiveAtomWeakMap.set(workspace, baseAtom);
}
return workspacePassiveAtomWeakMap.get(workspace) as Atom<Promise<Workspace>>;
return workspaceActiveAtomWeakMap.get(workspace) as Atom<Promise<Workspace>>;
}
+60 -38
View File
@@ -1,6 +1,7 @@
import type { Page, PageMeta, Workspace } from '@blocksuite/store';
import { createIndexeddbStorage } from '@blocksuite/store';
import type { createStore, WritableAtom } from 'jotai/vanilla';
import type { Doc } from 'yjs';
import { Array as YArray, Doc as YDoc, Map as YMap } from 'yjs';
export async function initEmptyPage(page: Page, title?: string) {
@@ -24,6 +25,7 @@ export async function buildEmptyBlockSuite(workspace: Workspace) {
export async function buildShowcaseWorkspace(
workspace: Workspace,
options: {
schema: Schema;
atoms: {
pageMode: WritableAtom<
undefined,
@@ -196,7 +198,11 @@ export async function buildShowcaseWorkspace(
await Promise.all(
data.map(async ([id, promise]) => {
const { default: template } = await promise;
await workspace.importPageSnapshot(structuredClone(template), id);
await workspace
.importPageSnapshot(structuredClone(template), id)
.catch(error => {
console.error('error importing page', id, error);
});
workspace.setPageMeta(id, pageMetas[id]);
})
);
@@ -214,6 +220,16 @@ function deserializeXYWH(xywh: string): XYWH {
return JSON.parse(xywh) as XYWH;
}
const getLatestVersions = (schema: Schema): Record<string, number> => {
return [...schema.flavourSchemaMap.entries()].reduce(
(record, [flavour, schema]) => {
record[flavour] = schema.version;
return record;
},
{} as Record<string, number>
);
};
function migrateDatabase(data: YMap<unknown>) {
data.delete('prop:mode');
data.set('prop:views', new YArray());
@@ -450,30 +466,6 @@ export function migrateToSubdoc(oldDoc: YDoc): YDoc {
return newDoc;
}
export async function migrateDatabaseBlockTo3(rootDoc: YDoc, schema: Schema) {
const spaces = rootDoc.getMap('spaces') as YMap<any>;
spaces.forEach(space => {
schema.upgradePage(
{
'affine:note': 1,
'affine:bookmark': 1,
'affine:database': 2,
'affine:divider': 1,
'affine:image': 1,
'affine:list': 1,
'affine:code': 1,
'affine:page': 2,
'affine:paragraph': 1,
'affine:surface': 3,
},
space
);
});
const meta = rootDoc.getMap('meta') as YMap<unknown>;
const versions = meta.get('blockVersions') as YMap<number>;
versions.set('affine:database', 3);
}
export type UpgradeOptions = {
getCurrentRootDoc: () => Promise<YDoc>;
createWorkspace: () => Promise<Workspace>;
@@ -495,20 +487,42 @@ const upgradeV1ToV2 = async (options: UpgradeOptions) => {
return newWorkspace;
};
const upgradeV2ToV3 = async (options: UpgradeOptions): Promise<boolean> => {
/**
* Force upgrade block schema to the latest.
* Don't force to upgrade the pages without the check.
*
* Please note that this function will not upgrade the workspace version.
*
* @returns true if any schema is upgraded.
* @returns false if no schema is upgraded.
*/
export async function forceUpgradePages(
options: Omit<UpgradeOptions, 'createWorkspace'>
): Promise<boolean> {
const rootDoc = await options.getCurrentRootDoc();
const spaces = rootDoc.getMap('spaces') as YMap<any>;
const meta = rootDoc.getMap('meta') as YMap<unknown>;
const versions = meta.get('blockVersions') as YMap<number>;
if ('affine:database' in versions) {
if (versions['affine:database'] === 3) {
return false;
}
} else if (versions.get('affine:database') === 3) {
return false;
}
const schema = options.getSchema();
spaces.forEach(space => {
const oldVersions = versions.toJSON();
spaces.forEach((space: Doc) => {
schema.upgradePage(oldVersions, space);
});
const newVersions = getLatestVersions(schema);
meta.set('blockVersions', new YMap(Object.entries(newVersions)));
return Object.entries(oldVersions).some(
([flavour, version]) => newVersions[flavour] !== version
);
}
// database from 2 to 3
async function upgradeV2ToV3(options: UpgradeOptions): Promise<boolean> {
const rootDoc = await options.getCurrentRootDoc();
const spaces = rootDoc.getMap('spaces') as YMap<any>;
const meta = rootDoc.getMap('meta') as YMap<unknown>;
const versions = meta.get('blockVersions') as YMap<number>;
const schema = options.getSchema();
spaces.forEach((space: Doc) => {
schema.upgradePage(
{
'affine:note': 1,
@@ -526,18 +540,23 @@ const upgradeV2ToV3 = async (options: UpgradeOptions): Promise<boolean> => {
);
});
if ('affine:database' in versions) {
versions['affine:database'] = 3;
meta.set('blockVersions', new YMap(Object.entries(versions)));
meta.set(
'blockVersions',
new YMap(Object.entries(getLatestVersions(schema)))
);
} else {
versions.set('affine:database', 3);
Object.entries(getLatestVersions(schema)).map(([flavour, version]) =>
versions.set(flavour, version)
);
}
return true;
};
}
export enum WorkspaceVersion {
// v1 is treated as undefined
SubDoc = 2,
DatabaseV3 = 3,
Surface = 4,
}
/**
@@ -560,6 +579,9 @@ export async function migrateWorkspace(
}
if (currentVersion === WorkspaceVersion.SubDoc) {
return upgradeV2ToV3(options);
} else if (currentVersion === WorkspaceVersion.DatabaseV3) {
// surface from 3 to 5
return forceUpgradePages(options);
} else {
return false;
}
+6 -6
View File
@@ -6,12 +6,12 @@
"jotai": "^2.4.1"
},
"devDependencies": {
"@blocksuite/block-std": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/blocks": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/editor": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/global": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/lit": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/store": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/block-std": "0.0.0-20230905170607-94acf22c-nightly",
"@blocksuite/blocks": "0.0.0-20230905170607-94acf22c-nightly",
"@blocksuite/editor": "0.0.0-20230905170607-94acf22c-nightly",
"@blocksuite/global": "0.0.0-20230905170607-94acf22c-nightly",
"@blocksuite/lit": "0.0.0-20230905170607-94acf22c-nightly",
"@blocksuite/store": "0.0.0-20230905170607-94acf22c-nightly",
"lottie-web": "^5.12.2"
},
"peerDependencies": {
-10
View File
@@ -1,13 +1,3 @@
import type { EditorContainer } from '@blocksuite/editor';
import { atom } from 'jotai';
export const lottieAtom = atom(import('lottie-web').then(m => m.default));
export const editorContainerModuleAtom = atom<Promise<typeof EditorContainer>>(
typeof window === 'undefined'
? async () =>
import('@blocksuite/editor').then(module => module.EditorContainer)
: (import('@blocksuite/editor').then(
module => module.EditorContainer
) as any)
);
+1
View File
@@ -78,6 +78,7 @@ export class SqliteConnection {
): Promise<void>;
initVersion(): Promise<void>;
setVersion(version: number): Promise<void>;
getMaxVersion(): Promise<number>;
close(): Promise<void>;
get isClose(): boolean;
static validate(path: string): Promise<ValidationResult>;
+12 -1
View File
@@ -8,7 +8,7 @@ use sqlx::{
};
// latest version
const LATEST_VERSION: i32 = 3;
const LATEST_VERSION: i32 = 4;
#[napi(object)]
pub struct BlobRow {
@@ -265,6 +265,17 @@ impl SqliteConnection {
Ok(())
}
#[napi]
pub async fn get_max_version(&self) -> napi::Result<i32> {
// 4 is the current version
let version = sqlx::query!("SELECT COALESCE(MAX(version), 4) AS max_version FROM version_info")
.fetch_one(&self.pool)
.await
.map_err(anyhow::Error::from)?
.max_version;
Ok(version)
}
#[napi]
pub async fn close(&self) {
self.pool.close().await;
+3 -3
View File
@@ -22,9 +22,9 @@
"dist"
],
"dependencies": {
"@blocksuite/blocks": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/global": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/store": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/blocks": "0.0.0-20230905170607-94acf22c-nightly",
"@blocksuite/global": "0.0.0-20230905170607-94acf22c-nightly",
"@blocksuite/store": "0.0.0-20230905170607-94acf22c-nightly",
"jotai": "^2.4.1",
"zod": "^3.22.2"
},
@@ -14,7 +14,10 @@
"sys:id": "XSMCxudQf4",
"sys:flavour": "affine:surface",
"sys:children": [],
"prop:elements": {}
"prop:elements": {
"type": "$blocksuite:internal:native$",
"value": {}
}
},
"2xxenQgE1-": {
"sys:id": "2xxenQgE1-",
@@ -14,7 +14,10 @@
"sys:id": "_07_dOaECY",
"sys:flavour": "affine:surface",
"sys:children": [],
"prop:elements": {}
"prop:elements": {
"type": "$blocksuite:internal:native$",
"value": {}
}
},
"0n7YghSHPc": {
"sys:id": "0n7YghSHPc",
+4 -1
View File
@@ -14,7 +14,10 @@
"sys:id": "f7o2Osxfa_",
"sys:flavour": "affine:surface",
"sys:children": [],
"prop:elements": {}
"prop:elements": {
"type": "$blocksuite:internal:native$",
"value": {}
}
},
"NDAzEfCZnv": {
"sys:id": "NDAzEfCZnv",
+4 -1
View File
@@ -14,7 +14,10 @@
"sys:id": "86K_nlhKXG",
"sys:flavour": "affine:surface",
"sys:children": [],
"prop:elements": {}
"prop:elements": {
"type": "$blocksuite:internal:native$",
"value": {}
}
},
"q7fYMX90uJ": {
"sys:id": "q7fYMX90uJ",
+4 -1
View File
@@ -14,7 +14,10 @@
"sys:id": "-SeDPuI6pE",
"sys:flavour": "affine:surface",
"sys:children": [],
"prop:elements": {}
"prop:elements": {
"type": "$blocksuite:internal:native$",
"value": {}
}
},
"gjPKqwOdlZ": {
"sys:id": "gjPKqwOdlZ",
+4 -1
View File
@@ -14,7 +14,10 @@
"sys:id": "f4WAKZ67ki",
"sys:flavour": "affine:surface",
"sys:children": [],
"prop:elements": {}
"prop:elements": {
"type": "$blocksuite:internal:native$",
"value": {}
}
},
"xj7QSmgQgT": {
"sys:id": "xj7QSmgQgT",
@@ -15,45 +15,48 @@
"sys:flavour": "affine:surface",
"sys:children": [],
"prop:elements": {
"aAOeeA4jhz": {
"type": "connector",
"mode": 1,
"strokeWidth": 2,
"stroke": "--affine-palette-line-blue",
"strokeStyle": "solid",
"roughness": 1.4,
"source": {
"id": "f6Owaa00aK",
"position": [0.5, 1]
"type": "$blocksuite:internal:native$",
"value": {
"aAOeeA4jhz": {
"type": "connector",
"mode": 1,
"strokeWidth": 2,
"stroke": "--affine-palette-line-blue",
"strokeStyle": "solid",
"roughness": 1.4,
"source": {
"id": "f6Owaa00aK",
"position": [0.5, 1]
},
"target": {
"id": "W6M-MPQ5-F"
},
"controllers": [],
"id": "aAOeeA4jhz",
"index": "a1",
"seed": 1493853178,
"xywh": "[181.61467354910715,-359.54656036633406,400,379.64]"
},
"target": {
"id": "W6M-MPQ5-F"
},
"controllers": [],
"id": "aAOeeA4jhz",
"index": "a1",
"seed": 1493853178,
"xywh": "[181.61467354910715,-359.54656036633406,400,379.64]"
},
"pMyfZPwXXU": {
"type": "connector",
"mode": 1,
"strokeWidth": 2,
"stroke": "--affine-palette-line-black",
"strokeStyle": "solid",
"roughness": 1.4,
"source": {
"id": "f6Owaa00aK",
"position": [0.5010332476508476, 1]
},
"target": {
"id": "-tH5D5Hf4J"
},
"controllers": [],
"id": "pMyfZPwXXU",
"index": "a2",
"seed": 1151132732,
"xywh": "[581.9546735491072,-359.54656036633406,650.69,379.64]"
"pMyfZPwXXU": {
"type": "connector",
"mode": 1,
"strokeWidth": 2,
"stroke": "--affine-palette-line-black",
"strokeStyle": "solid",
"roughness": 1.4,
"source": {
"id": "f6Owaa00aK",
"position": [0.5010332476508476, 1]
},
"target": {
"id": "-tH5D5Hf4J"
},
"controllers": [],
"id": "pMyfZPwXXU",
"index": "a2",
"seed": 1151132732,
"xywh": "[581.9546735491072,-359.54656036633406,650.69,379.64]"
}
}
}
},
@@ -14,7 +14,10 @@
"sys:id": "9eBKQxt8ax",
"sys:flavour": "affine:surface",
"sys:children": [],
"prop:elements": {}
"prop:elements": {
"type": "$blocksuite:internal:native$",
"value": {}
}
},
"2nHeyqzDMf": {
"sys:id": "2nHeyqzDMf",
File diff suppressed because it is too large Load Diff
@@ -14,7 +14,10 @@
"sys:id": "PCxQvHuwt1",
"sys:flavour": "affine:surface",
"sys:children": [],
"prop:elements": {}
"prop:elements": {
"type": "$blocksuite:internal:native$",
"value": {}
}
},
"PMY4JPuq4o": {
"sys:id": "PMY4JPuq4o",
File diff suppressed because it is too large Load Diff
+108 -105
View File
@@ -28,111 +28,114 @@
"sys:flavour": "affine:surface",
"sys:children": [],
"prop:elements": {
"sw8Uxi4bBo": {
"type": "text",
"xywh": "[-536.8747010075784,-1579.765008069904,1543.7942406924883,394.2045498052795]",
"rotate": 0,
"text": [
{
"insert": "You can switch from edgeless mode to paper mode if you want to add more notes! "
}
],
"color": "--affine-palette-line-navy",
"fontSize": 82.63458496823259,
"fontFamily": "'Kalam', cursive",
"textAlign": "left",
"isBold": false,
"isItalic": false,
"id": "sw8Uxi4bBo",
"index": "b0u",
"seed": 615352575
},
"Tubq5p548e": {
"type": "text",
"xywh": "[-513.3186960556048,-1403.9329998657581,1624.0512882883274,77.08483854034749]",
"rotate": 0,
"text": [
{
"insert": "If you want creat your own template, click + New Page to start your journey! "
}
],
"color": "--affine-palette-line-navy",
"fontSize": 48.17803589166863,
"fontFamily": "'Kalam', cursive",
"textAlign": "left",
"isBold": false,
"isItalic": false,
"id": "Tubq5p548e",
"index": "b0v",
"seed": 1725612619
},
"ieZVmhh5WF": {
"type": "shape",
"xywh": "[-536.8747010075784,-1425.8756349679952,1777.647429124084,120.9701087448215]",
"rotate": 0,
"shapeType": "rect",
"radius": 0.1,
"filled": false,
"fillColor": "--affine-palette-transparent",
"strokeWidth": 4,
"strokeColor": "--affine-palette-line-navy",
"strokeStyle": "solid",
"roughness": 2,
"id": "ieZVmhh5WF",
"index": "b0w",
"seed": 1287209158
},
"yGt4uK3Jrz": {
"type": "frame",
"xywh": "[-559.1114681167911,-596.5645426128128,1121.628897543559,640]",
"title": [
{
"insert": "Start from here"
}
],
"batch": "a0",
"id": "yGt4uK3Jrz",
"index": "a1",
"seed": 1327354607
},
"dPCGvkzOF1": {
"type": "frame",
"xywh": "[-559.1114681167911,289.07749381963725,1075.8482127510565,640]",
"title": [
{
"insert": "Part 1"
}
],
"batch": "a0",
"id": "dPCGvkzOF1",
"index": "a2",
"seed": 122824650
},
"nIZLp-sa3n": {
"type": "frame",
"xywh": "[-559.1114681167911,1174.7195302520875,1130.582694488373,640]",
"title": [
{
"insert": "Part 2"
}
],
"batch": "a0",
"id": "nIZLp-sa3n",
"index": "a3",
"seed": 1488143224
},
"8FjxUtSCG6": {
"type": "frame",
"xywh": "[1019.2666610517662,-621.9153214705414,2150.370188968697,1619.1792632492125]",
"title": [
{
"insert": "Part 3"
}
],
"batch": "a0",
"id": "8FjxUtSCG6",
"index": "a4",
"seed": 219967056
"type": "$blocksuite:internal:native$",
"value": {
"sw8Uxi4bBo": {
"type": "text",
"xywh": "[-536.8747010075784,-1579.765008069904,1543.7942406924883,394.2045498052795]",
"rotate": 0,
"text": [
{
"insert": "You can switch from edgeless mode to paper mode if you want to add more notes! "
}
],
"color": "--affine-palette-line-navy",
"fontSize": 82.63458496823259,
"fontFamily": "'Kalam', cursive",
"textAlign": "left",
"isBold": false,
"isItalic": false,
"id": "sw8Uxi4bBo",
"index": "b0u",
"seed": 615352575
},
"Tubq5p548e": {
"type": "text",
"xywh": "[-513.3186960556048,-1403.9329998657581,1624.0512882883274,77.08483854034749]",
"rotate": 0,
"text": [
{
"insert": "If you want creat your own template, click + New Page to start your journey! "
}
],
"color": "--affine-palette-line-navy",
"fontSize": 48.17803589166863,
"fontFamily": "'Kalam', cursive",
"textAlign": "left",
"isBold": false,
"isItalic": false,
"id": "Tubq5p548e",
"index": "b0v",
"seed": 1725612619
},
"ieZVmhh5WF": {
"type": "shape",
"xywh": "[-536.8747010075784,-1425.8756349679952,1777.647429124084,120.9701087448215]",
"rotate": 0,
"shapeType": "rect",
"radius": 0.1,
"filled": false,
"fillColor": "--affine-palette-transparent",
"strokeWidth": 4,
"strokeColor": "--affine-palette-line-navy",
"strokeStyle": "solid",
"roughness": 2,
"id": "ieZVmhh5WF",
"index": "b0w",
"seed": 1287209158
},
"yGt4uK3Jrz": {
"type": "frame",
"xywh": "[-559.1114681167911,-596.5645426128128,1121.628897543559,640]",
"title": [
{
"insert": "Start from here"
}
],
"batch": "a0",
"id": "yGt4uK3Jrz",
"index": "a1",
"seed": 1327354607
},
"dPCGvkzOF1": {
"type": "frame",
"xywh": "[-559.1114681167911,289.07749381963725,1075.8482127510565,640]",
"title": [
{
"insert": "Part 1"
}
],
"batch": "a0",
"id": "dPCGvkzOF1",
"index": "a2",
"seed": 122824650
},
"nIZLp-sa3n": {
"type": "frame",
"xywh": "[-559.1114681167911,1174.7195302520875,1130.582694488373,640]",
"title": [
{
"insert": "Part 2"
}
],
"batch": "a0",
"id": "nIZLp-sa3n",
"index": "a3",
"seed": 1488143224
},
"8FjxUtSCG6": {
"type": "frame",
"xywh": "[1019.2666610517662,-621.9153214705414,2150.370188968697,1619.1792632492125]",
"title": [
{
"insert": "Part 3"
}
],
"batch": "a0",
"id": "8FjxUtSCG6",
"index": "a4",
"seed": 219967056
}
}
}
},
+4 -1
View File
@@ -14,7 +14,10 @@
"sys:id": "yC-F6Rj9bA",
"sys:flavour": "affine:surface",
"sys:children": [],
"prop:elements": {}
"prop:elements": {
"type": "$blocksuite:internal:native$",
"value": {}
}
},
"pk_Cjkpyd4": {
"sys:id": "pk_Cjkpyd4",
+2 -3
View File
@@ -7,9 +7,8 @@
"./type": "./src/type.ts",
"./migration": "./src/migration/index.ts",
"./local/crud": "./src/local/crud.ts",
"./affine/crud": "./src/affine/crud.ts",
"./affine/gql": "./src/affine/gql.ts",
"./affine/sync": "./src/affine/sync.ts",
"./affine": "./src/affine/index.ts",
"./affine/*": "./src/affine/*.ts",
"./providers": "./src/providers/index.ts"
},
"peerDependencies": {
+21
View File
@@ -1,3 +1,4 @@
import { DebugLogger } from '@affine/debug';
import type { DatasourceDocAdapter } from '@affine/y-provider';
import type { Socket } from 'socket.io-client';
import { Manager } from 'socket.io-client';
@@ -15,6 +16,7 @@ import {
} from './utils';
let ioManager: Manager | null = null;
// use lazy initialization to avoid global side effect
function getIoManager(): Manager {
if (ioManager) {
@@ -27,6 +29,8 @@ function getIoManager(): Manager {
return ioManager;
}
const logger = new DebugLogger('affine:sync');
export const createAffineDataSource = (
id: string,
rootDoc: Doc,
@@ -36,6 +40,7 @@ export const createAffineDataSource = (
console.warn('important!! please use doc.guid as roomName');
}
logger.debug('createAffineDataSource', id, rootDoc.guid, awareness);
const socket = getIoManager().socket('/');
return {
@@ -48,6 +53,11 @@ export const createAffineDataSource = (
: undefined;
return new Promise((resolve, reject) => {
logger.debug('doc-load', {
workspaceId: rootDoc.guid,
guid,
stateVector,
});
socket.emit(
'doc-load',
{
@@ -56,6 +66,12 @@ export const createAffineDataSource = (
stateVector,
},
(docState: Error | { missing: string; state: string } | null) => {
logger.debug('doc-load callback', {
workspaceId: rootDoc.guid,
guid,
stateVector,
docState,
});
if (docState instanceof Error) {
reject(docState);
return;
@@ -76,6 +92,11 @@ export const createAffineDataSource = (
});
},
sendDocUpdate: async (guid: string, update: Uint8Array) => {
logger.debug('client-update', {
workspaceId: rootDoc.guid,
guid,
update,
});
socket.emit('client-update', {
workspaceId: rootDoc.guid,
guid,
+2 -2
View File
@@ -38,8 +38,8 @@
},
"devDependencies": {
"@affine/y-provider": "workspace:*",
"@blocksuite/blocks": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/store": "0.0.0-20230829150056-df43987c-nightly",
"@blocksuite/blocks": "0.0.0-20230905170607-94acf22c-nightly",
"@blocksuite/store": "0.0.0-20230905170607-94acf22c-nightly",
"vite": "^4.4.9",
"vite-plugin-dts": "3.5.3",
"y-indexeddb": "^9.0.11"
+1 -1
View File
@@ -9,7 +9,7 @@
".": "./src/index.ts"
},
"devDependencies": {
"@blocksuite/store": "0.0.0-20230829150056-df43987c-nightly"
"@blocksuite/store": "0.0.0-20230905170607-94acf22c-nightly"
},
"peerDependencies": {
"yjs": "^13.5.51"