Merge remote-tracking branch 'refs/remotes/origin/feat/cloud-sync-saika'
Conflicts: packages/data-center/package.json packages/data-center/src/datacenter.ts packages/data-center/src/index.ts pnpm-lock.yaml
This commit is contained in:
@@ -11,7 +11,7 @@ const EDITOR_VERSION = enableDebugLocal
|
|||||||
|
|
||||||
const profileTarget = {
|
const profileTarget = {
|
||||||
ac: '100.85.73.88:12001',
|
ac: '100.85.73.88:12001',
|
||||||
dev: '100.85.73.88:12001',
|
dev: '100.77.180.48:11001',
|
||||||
local: '127.0.0.1:3000',
|
local: '127.0.0.1:3000',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -11,10 +11,10 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@affine/datacenter": "workspace:*",
|
"@affine/datacenter": "workspace:*",
|
||||||
"@affine/i18n": "workspace:*",
|
"@affine/i18n": "workspace:*",
|
||||||
"@blocksuite/blocks": "0.3.1-20230109032243-37ad3ba",
|
"@blocksuite/blocks": "0.4.0-20230110112105-ef07332",
|
||||||
"@blocksuite/editor": "0.3.1-20230109032243-37ad3ba",
|
"@blocksuite/editor": "0.4.0-20230110112105-ef07332",
|
||||||
"@blocksuite/icons": "^2.0.2",
|
"@blocksuite/icons": "^2.0.2",
|
||||||
"@blocksuite/store": "0.3.1-20230109032243-37ad3ba",
|
"@blocksuite/store": "0.4.0-20230110112105-ef07332",
|
||||||
"@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",
|
||||||
|
|||||||
@@ -27,8 +27,8 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tauri-apps/api": "^1.2.0",
|
"@tauri-apps/api": "^1.2.0",
|
||||||
"@blocksuite/blocks": "^0.3.1-20230109032243-37ad3ba",
|
"@blocksuite/blocks": "0.4.0-20230110112105-ef07332",
|
||||||
"@blocksuite/store": "^0.3.1-20230109032243-37ad3ba",
|
"@blocksuite/store": "0.4.0-20230110112105-ef07332",
|
||||||
"debug": "^4.3.4",
|
"debug": "^4.3.4",
|
||||||
"encoding": "^0.1.13",
|
"encoding": "^0.1.13",
|
||||||
"firebase": "^9.15.0",
|
"firebase": "^9.15.0",
|
||||||
@@ -37,7 +37,6 @@
|
|||||||
"ky-universal": "^0.11.0",
|
"ky-universal": "^0.11.0",
|
||||||
"lib0": "^0.2.58",
|
"lib0": "^0.2.58",
|
||||||
"swr": "^2.0.0",
|
"swr": "^2.0.0",
|
||||||
"yjs": "^13.5.44",
|
|
||||||
"y-protocols": "^1.0.5"
|
"y-protocols": "^1.0.5"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
|||||||
@@ -1,22 +1,26 @@
|
|||||||
import { WorkspaceMetaCollection } from './workspace-meta-collection.js';
|
import { WorkspaceUnitCollection } from './workspace-unit-collection.js';
|
||||||
import type { WorkspaceMetaCollectionChangeEvent } from './workspace-meta-collection';
|
import type { WorkspaceUnitCollectionChangeEvent } from './workspace-unit-collection';
|
||||||
import { Workspace as BlocksuiteWorkspace } from '@blocksuite/store';
|
import { Workspace as BlocksuiteWorkspace } from '@blocksuite/store';
|
||||||
import { BaseProvider } from './provider/base';
|
import type {
|
||||||
|
BaseProvider,
|
||||||
|
CreateWorkspaceInfoParams,
|
||||||
|
UpdateWorkspaceMetaParams,
|
||||||
|
} from './provider/base';
|
||||||
import { LocalProvider } from './provider/local/local';
|
import { LocalProvider } from './provider/local/local';
|
||||||
import { AffineProvider } from './provider';
|
import { AffineProvider } from './provider';
|
||||||
import type { Message, WorkspaceMeta } from './types';
|
import type { Message } from './types';
|
||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import { getLogger } from './logger';
|
import { getLogger } from './logger';
|
||||||
import { applyUpdate, encodeStateAsUpdate } from 'yjs';
|
|
||||||
import { createBlocksuiteWorkspace } from './utils/index.js';
|
import { createBlocksuiteWorkspace } from './utils/index.js';
|
||||||
import { MessageCenter } from './message';
|
import { MessageCenter } from './message';
|
||||||
|
import type { WorkspaceUnit } from './workspace-unit';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class DataCenter
|
* @class DataCenter
|
||||||
* @classdesc Data center is made for managing different providers for business
|
* @classdesc Data center is made for managing different providers for business
|
||||||
*/
|
*/
|
||||||
export class DataCenter {
|
export class DataCenter {
|
||||||
private readonly _workspaceMetaCollection = new WorkspaceMetaCollection();
|
private readonly _workspaceUnitCollection = new WorkspaceUnitCollection();
|
||||||
private readonly _logger = getLogger('dc');
|
private readonly _logger = getLogger('dc');
|
||||||
private _workspaceInstances: Map<string, BlocksuiteWorkspace> = new Map();
|
private _workspaceInstances: Map<string, BlocksuiteWorkspace> = new Map();
|
||||||
private _messageCenter = new MessageCenter();
|
private _messageCenter = new MessageCenter();
|
||||||
@@ -35,7 +39,7 @@ export class DataCenter {
|
|||||||
const getInitParams = () => {
|
const getInitParams = () => {
|
||||||
return {
|
return {
|
||||||
logger: dc._logger,
|
logger: dc._logger,
|
||||||
workspaces: dc._workspaceMetaCollection.createScope(),
|
workspaces: dc._workspaceUnitCollection.createScope(),
|
||||||
messageCenter: dc._messageCenter,
|
messageCenter: dc._messageCenter,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -46,11 +50,15 @@ export class DataCenter {
|
|||||||
typeof window.__TAURI_IPC__ === 'function'
|
typeof window.__TAURI_IPC__ === 'function'
|
||||||
) {
|
) {
|
||||||
const { TauriIPCProvider } = await import('./provider/tauri-ipc');
|
const { TauriIPCProvider } = await import('./provider/tauri-ipc');
|
||||||
dc.registerProvider(new TauriIPCProvider(getInitParams()));
|
await dc.registerProvider(new TauriIPCProvider(getInitParams()));
|
||||||
} else {
|
} else {
|
||||||
dc.registerProvider(new LocalProvider(getInitParams()));
|
await dc.registerProvider(new LocalProvider(getInitParams()));
|
||||||
|
}
|
||||||
|
await dc.registerProvider(new AffineProvider(getInitParams()));
|
||||||
|
|
||||||
|
for (const provider of dc.providerMap.values()) {
|
||||||
|
await provider.loadWorkspaces();
|
||||||
}
|
}
|
||||||
dc.registerProvider(new AffineProvider(getInitParams()));
|
|
||||||
|
|
||||||
return dc;
|
return dc;
|
||||||
}
|
}
|
||||||
@@ -59,12 +67,12 @@ export class DataCenter {
|
|||||||
* Register provider.
|
* Register provider.
|
||||||
* We will automatically set the first provider to default provider.
|
* We will automatically set the first provider to default provider.
|
||||||
*/
|
*/
|
||||||
registerProvider(provider: BaseProvider) {
|
async registerProvider(provider: BaseProvider) {
|
||||||
if (!this._mainProvider) {
|
if (!this._mainProvider) {
|
||||||
this._mainProvider = provider;
|
this._mainProvider = provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
provider.init();
|
await provider.init();
|
||||||
this.providerMap.set(provider.id, provider);
|
this.providerMap.set(provider.id, provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +85,7 @@ export class DataCenter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public get workspaces() {
|
public get workspaces() {
|
||||||
return this._workspaceMetaCollection.workspaces;
|
return this._workspaceUnitCollection.workspaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async refreshWorkspaces() {
|
public async refreshWorkspaces() {
|
||||||
@@ -91,20 +99,19 @@ export class DataCenter {
|
|||||||
* @param {string} name workspace name
|
* @param {string} name workspace name
|
||||||
* @returns {Promise<Workspace>}
|
* @returns {Promise<Workspace>}
|
||||||
*/
|
*/
|
||||||
public async createWorkspace(workspaceMeta: WorkspaceMeta) {
|
public async createWorkspace(params: CreateWorkspaceInfoParams) {
|
||||||
assert(
|
assert(
|
||||||
this._mainProvider,
|
this._mainProvider,
|
||||||
'There is no provider. You should add provider first.'
|
'There is no provider. You should add provider first.'
|
||||||
);
|
);
|
||||||
|
|
||||||
const workspaceInfo = await this._mainProvider.createWorkspaceInfo(
|
const workspaceMeta = await this._mainProvider.createWorkspaceInfo(params);
|
||||||
workspaceMeta
|
|
||||||
);
|
|
||||||
|
|
||||||
const workspace = createBlocksuiteWorkspace(workspaceInfo.id);
|
const workspace = createBlocksuiteWorkspace(workspaceMeta.id);
|
||||||
|
|
||||||
await this._mainProvider.createWorkspace(workspace, workspaceMeta);
|
await this._mainProvider.createWorkspace(workspace, workspaceMeta);
|
||||||
return workspace;
|
const workspaceUnit = this._workspaceUnitCollection.find(workspaceMeta.id);
|
||||||
|
return workspaceUnit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -112,7 +119,7 @@ export class DataCenter {
|
|||||||
* @param {string} workspaceId workspace id
|
* @param {string} workspaceId workspace id
|
||||||
*/
|
*/
|
||||||
public async deleteWorkspace(workspaceId: string) {
|
public async deleteWorkspace(workspaceId: string) {
|
||||||
const workspaceInfo = this._workspaceMetaCollection.find(workspaceId);
|
const workspaceInfo = this._workspaceUnitCollection.find(workspaceId);
|
||||||
assert(workspaceInfo, 'Workspace not found');
|
assert(workspaceInfo, 'Workspace not found');
|
||||||
const provider = this.providerMap.get(workspaceInfo.provider);
|
const provider = this.providerMap.get(workspaceInfo.provider);
|
||||||
assert(provider, `Workspace exists, but we couldn't find its provider.`);
|
assert(provider, `Workspace exists, but we couldn't find its provider.`);
|
||||||
@@ -124,10 +131,10 @@ export class DataCenter {
|
|||||||
* @param {string} workspaceId workspace id
|
* @param {string} workspaceId workspace id
|
||||||
*/
|
*/
|
||||||
private _getBlocksuiteWorkspace(workspaceId: string) {
|
private _getBlocksuiteWorkspace(workspaceId: string) {
|
||||||
const workspaceInfo = this._workspaceMetaCollection.find(workspaceId);
|
const workspaceInfo = this._workspaceUnitCollection.find(workspaceId);
|
||||||
assert(workspaceInfo, 'Workspace not found');
|
assert(workspaceInfo, 'Workspace not found');
|
||||||
return (
|
return (
|
||||||
this._workspaceInstances.get(workspaceId) ||
|
// this._workspaceInstances.get(workspaceId) ||
|
||||||
createBlocksuiteWorkspace(workspaceId)
|
createBlocksuiteWorkspace(workspaceId)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -155,21 +162,26 @@ export class DataCenter {
|
|||||||
/**
|
/**
|
||||||
* load workspace instance by id
|
* load workspace instance by id
|
||||||
* @param {string} workspaceId workspace id
|
* @param {string} workspaceId workspace id
|
||||||
* @returns {Promise<BlocksuiteWorkspace>}
|
* @returns {Promise<WorkspaceUnit>}
|
||||||
*/
|
*/
|
||||||
public async loadWorkspace(workspaceId: string) {
|
public async loadWorkspace(workspaceId: string) {
|
||||||
const workspaceInfo = this._workspaceMetaCollection.find(workspaceId);
|
const workspaceUnit = this._workspaceUnitCollection.find(workspaceId);
|
||||||
assert(workspaceInfo, 'Workspace not found');
|
assert(workspaceUnit, 'Workspace not found');
|
||||||
const currentProvider = this.providerMap.get(workspaceInfo.provider);
|
const currentProvider = this.providerMap.get(workspaceUnit.provider);
|
||||||
if (currentProvider) {
|
if (currentProvider) {
|
||||||
currentProvider.closeWorkspace(workspaceId);
|
currentProvider.closeWorkspace(workspaceId);
|
||||||
}
|
}
|
||||||
const provider = this.providerMap.get(workspaceInfo.provider);
|
const provider = this.providerMap.get(workspaceUnit.provider);
|
||||||
assert(provider, `provide '${workspaceInfo.provider}' is not registered`);
|
assert(provider, `provide '${workspaceUnit.provider}' is not registered`);
|
||||||
this._logger(`Loading ${workspaceInfo.provider} workspace: `, workspaceId);
|
this._logger(`Loading ${workspaceUnit.provider} workspace: `, workspaceId);
|
||||||
const workspace = this._getBlocksuiteWorkspace(workspaceId);
|
const workspace = this._getBlocksuiteWorkspace(workspaceId);
|
||||||
this._workspaceInstances.set(workspaceId, workspace);
|
this._workspaceInstances.set(workspaceId, workspace);
|
||||||
return await provider.warpWorkspace(workspace);
|
await provider.warpWorkspace(workspace);
|
||||||
|
this._workspaceUnitCollection.workspaces.forEach(workspaceUnit => {
|
||||||
|
workspaceUnit.setBlocksuiteWorkspace(null);
|
||||||
|
});
|
||||||
|
workspaceUnit.setBlocksuiteWorkspace(workspace);
|
||||||
|
return workspaceUnit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -189,22 +201,30 @@ export class DataCenter {
|
|||||||
* @param {Function} callback callback function
|
* @param {Function} callback callback function
|
||||||
*/
|
*/
|
||||||
public async onWorkspacesChange(
|
public async onWorkspacesChange(
|
||||||
callback: (workspaces: WorkspaceMetaCollectionChangeEvent) => void
|
callback: (workspaces: WorkspaceUnitCollectionChangeEvent) => void,
|
||||||
|
{ immediate = true }: { immediate?: boolean } = {}
|
||||||
) {
|
) {
|
||||||
this._workspaceMetaCollection.on('change', callback);
|
if (immediate) {
|
||||||
|
callback({
|
||||||
|
added: this._workspaceUnitCollection.workspaces,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this._workspaceUnitCollection.on('change', callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* change workspaces meta
|
* change workspaces meta
|
||||||
* @param {WorkspaceMeta} workspaceMeta workspace meta
|
* @param {WorkspaceMeta} workspaceMeta workspace meta
|
||||||
* @param {BlocksuiteWorkspace} workspace workspace instance
|
* @param {WorkspaceUnit} workspace workspace instance
|
||||||
*/
|
*/
|
||||||
public async updateWorkspaceMeta(
|
public async updateWorkspaceMeta(
|
||||||
{ name, avatar }: Partial<WorkspaceMeta>,
|
{ name, avatar }: UpdateWorkspaceMetaParams,
|
||||||
workspace: BlocksuiteWorkspace
|
workspaceUnit: WorkspaceUnit
|
||||||
) {
|
) {
|
||||||
assert(workspace?.room, 'No workspace to set meta');
|
assert(workspaceUnit?.id, 'No workspace to set meta');
|
||||||
const update: Partial<WorkspaceMeta> = {};
|
const workspace = workspaceUnit.blocksuiteWorkspace;
|
||||||
|
assert(workspace);
|
||||||
|
const update: Partial<UpdateWorkspaceMetaParams> = {};
|
||||||
if (name) {
|
if (name) {
|
||||||
workspace.meta.setName(name);
|
workspace.meta.setName(name);
|
||||||
update.name = name;
|
update.name = name;
|
||||||
@@ -214,10 +234,10 @@ export class DataCenter {
|
|||||||
update.avatar = avatar;
|
update.avatar = avatar;
|
||||||
}
|
}
|
||||||
// may run for change workspace meta
|
// may run for change workspace meta
|
||||||
const workspaceInfo = this._workspaceMetaCollection.find(workspace.room);
|
const workspaceInfo = this._workspaceUnitCollection.find(workspaceUnit.id);
|
||||||
assert(workspaceInfo, 'Workspace not found');
|
assert(workspaceInfo, 'Workspace not found');
|
||||||
const provider = this.providerMap.get(workspaceInfo.provider);
|
const provider = this.providerMap.get(workspaceInfo.provider);
|
||||||
provider?.updateWorkspaceMeta(workspace.room, update);
|
provider?.updateWorkspaceMeta(workspaceUnit.id, update);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -226,7 +246,7 @@ export class DataCenter {
|
|||||||
* @param id workspace id
|
* @param id workspace id
|
||||||
*/
|
*/
|
||||||
public async leaveWorkspace(workspaceId: string) {
|
public async leaveWorkspace(workspaceId: string) {
|
||||||
const workspaceInfo = this._workspaceMetaCollection.find(workspaceId);
|
const workspaceInfo = this._workspaceUnitCollection.find(workspaceId);
|
||||||
assert(workspaceInfo, 'Workspace not found');
|
assert(workspaceInfo, 'Workspace not found');
|
||||||
const provider = this.providerMap.get(workspaceInfo.provider);
|
const provider = this.providerMap.get(workspaceInfo.provider);
|
||||||
if (provider) {
|
if (provider) {
|
||||||
@@ -236,7 +256,7 @@ export class DataCenter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async setWorkspacePublish(workspaceId: string, isPublish: boolean) {
|
public async setWorkspacePublish(workspaceId: string, isPublish: boolean) {
|
||||||
const workspaceInfo = this._workspaceMetaCollection.find(workspaceId);
|
const workspaceInfo = this._workspaceUnitCollection.find(workspaceId);
|
||||||
assert(workspaceInfo, 'Workspace not found');
|
assert(workspaceInfo, 'Workspace not found');
|
||||||
const provider = this.providerMap.get(workspaceInfo.provider);
|
const provider = this.providerMap.get(workspaceInfo.provider);
|
||||||
if (provider) {
|
if (provider) {
|
||||||
@@ -244,12 +264,17 @@ export class DataCenter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async inviteMember(id: string, email: string) {
|
/**
|
||||||
const workspaceInfo = this._workspaceMetaCollection.find(id);
|
* invite the new member to the workspace
|
||||||
|
* @param {string} workspaceId workspace id
|
||||||
|
* @param {string} email
|
||||||
|
*/
|
||||||
|
public async inviteMember(workspaceId: string, email: string) {
|
||||||
|
const workspaceInfo = this._workspaceUnitCollection.find(workspaceId);
|
||||||
assert(workspaceInfo, 'Workspace not found');
|
assert(workspaceInfo, 'Workspace not found');
|
||||||
const provider = this.providerMap.get(workspaceInfo.provider);
|
const provider = this.providerMap.get(workspaceInfo.provider);
|
||||||
if (provider) {
|
if (provider) {
|
||||||
await provider.invite(id, email);
|
await provider.invite(workspaceId, email);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,7 +283,7 @@ export class DataCenter {
|
|||||||
* @param {number} permissionId permission id
|
* @param {number} permissionId permission id
|
||||||
*/
|
*/
|
||||||
public async removeMember(workspaceId: string, permissionId: number) {
|
public async removeMember(workspaceId: string, permissionId: number) {
|
||||||
const workspaceInfo = this._workspaceMetaCollection.find(workspaceId);
|
const workspaceInfo = this._workspaceUnitCollection.find(workspaceId);
|
||||||
assert(workspaceInfo, 'Workspace not found');
|
assert(workspaceInfo, 'Workspace not found');
|
||||||
const provider = this.providerMap.get(workspaceInfo.provider);
|
const provider = this.providerMap.get(workspaceInfo.provider);
|
||||||
if (provider) {
|
if (provider) {
|
||||||
@@ -289,7 +314,7 @@ export class DataCenter {
|
|||||||
providerId: string
|
providerId: string
|
||||||
) {
|
) {
|
||||||
assert(workspace.room, 'No workspace id');
|
assert(workspace.room, 'No workspace id');
|
||||||
const workspaceInfo = this._workspaceMetaCollection.find(workspace.room);
|
const workspaceInfo = this._workspaceUnitCollection.find(workspace.room);
|
||||||
assert(workspaceInfo, 'Workspace not found');
|
assert(workspaceInfo, 'Workspace not found');
|
||||||
if (workspaceInfo.provider === providerId) {
|
if (workspaceInfo.provider === providerId) {
|
||||||
this._logger('Workspace provider is same');
|
this._logger('Workspace provider is same');
|
||||||
@@ -302,11 +327,12 @@ export class DataCenter {
|
|||||||
this._logger(`create ${providerId} workspace: `, workspaceInfo.name);
|
this._logger(`create ${providerId} workspace: `, workspaceInfo.name);
|
||||||
const newWorkspaceInfo = await newProvider.createWorkspaceInfo({
|
const newWorkspaceInfo = await newProvider.createWorkspaceInfo({
|
||||||
name: workspaceInfo.name,
|
name: workspaceInfo.name,
|
||||||
avatar: workspaceInfo.avatar,
|
// avatar: workspaceInfo.avatar,
|
||||||
});
|
});
|
||||||
const newWorkspace = createBlocksuiteWorkspace(newWorkspaceInfo.id);
|
const newWorkspace = createBlocksuiteWorkspace(newWorkspaceInfo.id);
|
||||||
// TODO optimize this function
|
// TODO optimize this function
|
||||||
await newProvider.createWorkspace(newWorkspace, {
|
await newProvider.createWorkspace(newWorkspace, {
|
||||||
|
...newWorkspaceInfo,
|
||||||
name: workspaceInfo.name,
|
name: workspaceInfo.name,
|
||||||
avatar: workspaceInfo.avatar,
|
avatar: workspaceInfo.avatar,
|
||||||
});
|
});
|
||||||
@@ -315,7 +341,7 @@ export class DataCenter {
|
|||||||
this._logger(
|
this._logger(
|
||||||
`update workspace data from ${workspaceInfo.provider} to ${providerId}`
|
`update workspace data from ${workspaceInfo.provider} to ${providerId}`
|
||||||
);
|
);
|
||||||
applyUpdate(newWorkspace.doc, encodeStateAsUpdate(workspace.doc));
|
await newProvider.assign(newWorkspace, workspace);
|
||||||
assert(newWorkspace, 'Create workspace failed');
|
assert(newWorkspace, 'Create workspace failed');
|
||||||
await currentProvider.deleteWorkspace(workspace.room);
|
await currentProvider.deleteWorkspace(workspace.room);
|
||||||
return newWorkspace.room;
|
return newWorkspace.room;
|
||||||
@@ -325,9 +351,13 @@ export class DataCenter {
|
|||||||
* Enable workspace cloud
|
* Enable workspace cloud
|
||||||
* @param {string} id ID of workspace.
|
* @param {string} id ID of workspace.
|
||||||
*/
|
*/
|
||||||
public async enableWorkspaceCloud(workspace: BlocksuiteWorkspace) {
|
public async enableWorkspaceCloud(workspace: WorkspaceUnit) {
|
||||||
assert(workspace?.room, 'No workspace to enable cloud');
|
assert(workspace?.id, 'No workspace to enable cloud');
|
||||||
return await this._transWorkspaceProvider(workspace, 'affine');
|
assert(workspace.blocksuiteWorkspace);
|
||||||
|
return await this._transWorkspaceProvider(
|
||||||
|
workspace.blocksuiteWorkspace,
|
||||||
|
'affine'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -364,10 +394,10 @@ export class DataCenter {
|
|||||||
* @returns {Promise<string | null>} blob url
|
* @returns {Promise<string | null>} blob url
|
||||||
*/
|
*/
|
||||||
async getBlob(
|
async getBlob(
|
||||||
workspace: BlocksuiteWorkspace,
|
workspaceUnit: WorkspaceUnit,
|
||||||
id: string
|
id: string
|
||||||
): Promise<string | null> {
|
): Promise<string | null> {
|
||||||
const blob = await workspace.blobs;
|
const blob = await workspaceUnit.blocksuiteWorkspace?.blobs;
|
||||||
return (await blob?.get(id)) || '';
|
return (await blob?.get(id)) || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,11 +406,25 @@ export class DataCenter {
|
|||||||
* @param id
|
* @param id
|
||||||
* @returns {Promise<string | null>} blob url
|
* @returns {Promise<string | null>} blob url
|
||||||
*/
|
*/
|
||||||
async setBlob(workspace: BlocksuiteWorkspace, blob: Blob): Promise<string> {
|
async setBlob(workspace: WorkspaceUnit, blob: Blob): Promise<string> {
|
||||||
const blobStorage = await workspace.blobs;
|
const blobStorage = await workspace.blocksuiteWorkspace?.blobs;
|
||||||
return (await blobStorage?.set(blob)) || '';
|
return (await blobStorage?.set(blob)) || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get members of a workspace
|
||||||
|
* @param workspaceId
|
||||||
|
*/
|
||||||
|
async getMembers(workspaceId: string) {
|
||||||
|
const workspaceInfo = this._workspaceUnitCollection.find(workspaceId);
|
||||||
|
assert(workspaceInfo, 'Workspace not found');
|
||||||
|
const provider = this.providerMap.get(workspaceInfo.provider);
|
||||||
|
if (provider) {
|
||||||
|
return await provider.getWorkspaceMembers(workspaceId);
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
onMessage(cb: (message: Message) => void) {
|
onMessage(cb: (message: Message) => void) {
|
||||||
return this._messageCenter.onMessage(cb);
|
return this._messageCenter.onMessage(cb);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,6 @@ export const getDataCenter = _initializeDataCenter();
|
|||||||
|
|
||||||
export type { DataCenter };
|
export type { DataCenter };
|
||||||
export type { AccessTokenMessage } from './provider/affine/apis';
|
export type { AccessTokenMessage } from './provider/affine/apis';
|
||||||
export * from './types';
|
export { WorkspaceUnit } from './workspace-unit';
|
||||||
export { getLogger } from './logger';
|
export { getLogger } from './logger';
|
||||||
export * from './message';
|
export * from './message';
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
export { MessageCenter } from './message';
|
export { MessageCenter } from './message.js';
|
||||||
export { MessageCode } from './code';
|
export { MessageCode } from './code.js';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Observable } from 'lib0/observable';
|
import { Observable } from 'lib0/observable';
|
||||||
import { Message } from '../types';
|
import { Message } from '../types';
|
||||||
import { MessageCode } from './code';
|
import { MessageCode } from './code.js';
|
||||||
|
|
||||||
export class MessageCenter extends Observable<string> {
|
export class MessageCenter extends Observable<string> {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
import { BaseProvider } from '../base.js';
|
import { BaseProvider } from '../base.js';
|
||||||
import type { ProviderConstructorParams } from '../base';
|
import type {
|
||||||
import type { User, WorkspaceInfo, WorkspaceMeta } from '../../types';
|
ProviderConstructorParams,
|
||||||
|
CreateWorkspaceInfoParams,
|
||||||
|
WorkspaceMeta0,
|
||||||
|
} from '../base';
|
||||||
|
import type { User } from '../../types';
|
||||||
import { Workspace as BlocksuiteWorkspace } from '@blocksuite/store';
|
import { Workspace as BlocksuiteWorkspace } from '@blocksuite/store';
|
||||||
import { BlockSchema } from '@blocksuite/blocks/models';
|
import { BlockSchema } from '@blocksuite/blocks/models';
|
||||||
import { applyUpdate } from 'yjs';
|
|
||||||
import { storage } from './storage.js';
|
import { storage } from './storage.js';
|
||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import { WebsocketProvider } from './sync.js';
|
import { WebsocketProvider } from './sync.js';
|
||||||
@@ -12,28 +15,39 @@ import { getApis } from './apis/index.js';
|
|||||||
import type { Apis, WorkspaceDetail, Callback } from './apis';
|
import type { Apis, WorkspaceDetail, Callback } from './apis';
|
||||||
import { setDefaultAvatar } from '../utils.js';
|
import { setDefaultAvatar } from '../utils.js';
|
||||||
import { MessageCode } from '../../message';
|
import { MessageCode } from '../../message';
|
||||||
|
import { token } from './apis/token.js';
|
||||||
|
import { WebsocketClient } from './channel';
|
||||||
|
|
||||||
export interface AffineProviderConstructorParams
|
export interface AffineProviderConstructorParams
|
||||||
extends ProviderConstructorParams {
|
extends ProviderConstructorParams {
|
||||||
apis?: Apis;
|
apis?: Apis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const {
|
||||||
|
Y: { applyUpdate, encodeStateAsUpdate },
|
||||||
|
} = BlocksuiteWorkspace;
|
||||||
|
|
||||||
export class AffineProvider extends BaseProvider {
|
export class AffineProvider extends BaseProvider {
|
||||||
public id = 'affine';
|
public id = 'affine';
|
||||||
private _workspacesCache: Map<string, BlocksuiteWorkspace> = new Map();
|
private _workspacesCache: Map<string, BlocksuiteWorkspace> = new Map();
|
||||||
private _onTokenRefresh?: Callback = undefined;
|
private _onTokenRefresh?: Callback = undefined;
|
||||||
private _wsMap: Map<string, WebsocketProvider> = new Map();
|
private _wsMap: Map<string, WebsocketProvider> = new Map();
|
||||||
private _apis: Apis;
|
private _apis: Apis;
|
||||||
|
private _channel: WebsocketClient;
|
||||||
// private _idbMap: Map<string, IndexedDBProvider> = new Map();
|
// private _idbMap: Map<string, IndexedDBProvider> = new Map();
|
||||||
|
|
||||||
constructor({ apis, ...params }: AffineProviderConstructorParams) {
|
constructor({ apis, ...params }: AffineProviderConstructorParams) {
|
||||||
super(params);
|
super(params);
|
||||||
this._apis = apis || getApis();
|
this._apis = apis || getApis();
|
||||||
this.init().then(() => {
|
this._channel = new WebsocketClient(
|
||||||
if (this._apis.token.isLogin) {
|
`${window.location.protocol === 'https:' ? 'wss' : 'ws'}://${
|
||||||
this.loadWorkspaces();
|
window.location.host
|
||||||
}
|
}/global/sync/`,
|
||||||
});
|
this._logger
|
||||||
|
);
|
||||||
|
if (token.isLogin) {
|
||||||
|
this._connectChannel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override async init() {
|
override async init() {
|
||||||
@@ -64,6 +78,32 @@ export class AffineProvider extends BaseProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _connectChannel() {
|
||||||
|
this._channel.connect();
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
this._channel.on('message', (message: any) => {
|
||||||
|
console.log('message', message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private _getWebsocketProvider(workspace: BlocksuiteWorkspace) {
|
||||||
|
const { doc, room } = workspace;
|
||||||
|
assert(room);
|
||||||
|
assert(doc);
|
||||||
|
let ws = this._wsMap.get(room);
|
||||||
|
if (!ws) {
|
||||||
|
const wsUrl = `${
|
||||||
|
window.location.protocol === 'https:' ? 'wss' : 'ws'
|
||||||
|
}://${window.location.host}/api/sync/`;
|
||||||
|
ws = new WebsocketProvider(wsUrl, room, doc, {
|
||||||
|
params: { token: this._apis.token.refresh },
|
||||||
|
});
|
||||||
|
this._wsMap.set(room, ws);
|
||||||
|
}
|
||||||
|
return ws;
|
||||||
|
}
|
||||||
|
|
||||||
private async _applyCloudUpdates(blocksuiteWorkspace: BlocksuiteWorkspace) {
|
private async _applyCloudUpdates(blocksuiteWorkspace: BlocksuiteWorkspace) {
|
||||||
const { doc, room: workspaceId } = blocksuiteWorkspace;
|
const { doc, room: workspaceId } = blocksuiteWorkspace;
|
||||||
assert(workspaceId, 'Blocksuite Workspace without room(workspaceId).');
|
assert(workspaceId, 'Blocksuite Workspace without room(workspaceId).');
|
||||||
@@ -78,20 +118,10 @@ export class AffineProvider extends BaseProvider {
|
|||||||
|
|
||||||
override async warpWorkspace(workspace: BlocksuiteWorkspace) {
|
override async warpWorkspace(workspace: BlocksuiteWorkspace) {
|
||||||
await this._applyCloudUpdates(workspace);
|
await this._applyCloudUpdates(workspace);
|
||||||
const { doc, room } = workspace;
|
const { room } = workspace;
|
||||||
assert(room);
|
assert(room);
|
||||||
this.linkLocal(workspace);
|
this.linkLocal(workspace);
|
||||||
|
const ws = this._getWebsocketProvider(workspace);
|
||||||
let ws = this._wsMap.get(room);
|
|
||||||
if (!ws) {
|
|
||||||
const wsUrl = `${
|
|
||||||
window.location.protocol === 'https:' ? 'wss' : 'ws'
|
|
||||||
}://${window.location.host}/api/sync/`;
|
|
||||||
ws = new WebsocketProvider(wsUrl, room, doc, {
|
|
||||||
params: { token: this._apis.token.refresh },
|
|
||||||
});
|
|
||||||
this._wsMap.set(room, ws);
|
|
||||||
}
|
|
||||||
// close all websocket links
|
// close all websocket links
|
||||||
Array.from(this._wsMap.entries()).forEach(([id, ws]) => {
|
Array.from(this._wsMap.entries()).forEach(([id, ws]) => {
|
||||||
if (id !== room) {
|
if (id !== room) {
|
||||||
@@ -115,12 +145,13 @@ export class AffineProvider extends BaseProvider {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
const workspacesList = await this._apis.getWorkspaces();
|
const workspacesList = await this._apis.getWorkspaces();
|
||||||
const workspaces: WorkspaceInfo[] = workspacesList.map(w => {
|
const workspaces: WorkspaceMeta0[] = workspacesList.map(w => {
|
||||||
return {
|
return {
|
||||||
...w,
|
...w,
|
||||||
memberCount: 0,
|
memberCount: 0,
|
||||||
name: '',
|
name: '',
|
||||||
provider: 'affine',
|
provider: 'affine',
|
||||||
|
syncMode: 'core',
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
const workspaceInstances = workspaces.map(({ id }) => {
|
const workspaceInstances = workspaces.map(({ id }) => {
|
||||||
@@ -198,6 +229,9 @@ export class AffineProvider extends BaseProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const user = await this._apis.signInWithGoogle?.();
|
const user = await this._apis.signInWithGoogle?.();
|
||||||
|
if (!this._channel.connected) {
|
||||||
|
this._connectChannel();
|
||||||
|
}
|
||||||
if (!user) {
|
if (!user) {
|
||||||
this._messageCenter.send(MessageCode.loginError);
|
this._messageCenter.send(MessageCode.loginError);
|
||||||
}
|
}
|
||||||
@@ -205,6 +239,7 @@ export class AffineProvider extends BaseProvider {
|
|||||||
|
|
||||||
public override async getUserInfo(): Promise<User | undefined> {
|
public override async getUserInfo(): Promise<User | undefined> {
|
||||||
const user = this._apis.token.user;
|
const user = this._apis.token.user;
|
||||||
|
await this.init;
|
||||||
return user
|
return user
|
||||||
? {
|
? {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
@@ -268,19 +303,17 @@ export class AffineProvider extends BaseProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override async createWorkspaceInfo(
|
public override async createWorkspaceInfo(
|
||||||
meta: WorkspaceMeta
|
meta: CreateWorkspaceInfoParams
|
||||||
): Promise<WorkspaceInfo> {
|
): Promise<WorkspaceMeta0> {
|
||||||
const { id } = await this._apis.createWorkspace(
|
const { id } = await this._apis.createWorkspace(meta);
|
||||||
meta as Required<WorkspaceMeta>
|
|
||||||
);
|
|
||||||
|
|
||||||
const workspaceInfo: WorkspaceInfo = {
|
const workspaceInfo: WorkspaceMeta0 = {
|
||||||
name: meta.name,
|
name: meta.name,
|
||||||
id: id,
|
id: id,
|
||||||
isPublish: false,
|
published: false,
|
||||||
avatar: '',
|
avatar: '',
|
||||||
owner: await this.getUserInfo(),
|
owner: await this.getUserInfo(),
|
||||||
isLocal: true,
|
syncMode: 'core',
|
||||||
memberCount: 1,
|
memberCount: 1,
|
||||||
provider: 'affine',
|
provider: 'affine',
|
||||||
};
|
};
|
||||||
@@ -289,7 +322,7 @@ export class AffineProvider extends BaseProvider {
|
|||||||
|
|
||||||
public override async createWorkspace(
|
public override async createWorkspace(
|
||||||
blocksuiteWorkspace: BlocksuiteWorkspace,
|
blocksuiteWorkspace: BlocksuiteWorkspace,
|
||||||
meta: WorkspaceMeta
|
meta: WorkspaceMeta0
|
||||||
): Promise<BlocksuiteWorkspace | undefined> {
|
): Promise<BlocksuiteWorkspace | undefined> {
|
||||||
const workspaceId = blocksuiteWorkspace.room;
|
const workspaceId = blocksuiteWorkspace.room;
|
||||||
assert(workspaceId, 'Blocksuite Workspace without room(workspaceId).');
|
assert(workspaceId, 'Blocksuite Workspace without room(workspaceId).');
|
||||||
@@ -298,13 +331,13 @@ export class AffineProvider extends BaseProvider {
|
|||||||
this._applyCloudUpdates(blocksuiteWorkspace);
|
this._applyCloudUpdates(blocksuiteWorkspace);
|
||||||
this.linkLocal(blocksuiteWorkspace);
|
this.linkLocal(blocksuiteWorkspace);
|
||||||
|
|
||||||
const workspaceInfo: WorkspaceInfo = {
|
const workspaceInfo: WorkspaceMeta0 = {
|
||||||
name: meta.name,
|
name: meta.name,
|
||||||
id: workspaceId,
|
id: workspaceId,
|
||||||
isPublish: false,
|
published: false,
|
||||||
avatar: '',
|
avatar: '',
|
||||||
owner: undefined,
|
owner: undefined,
|
||||||
isLocal: true,
|
syncMode: 'core',
|
||||||
memberCount: 1,
|
memberCount: 1,
|
||||||
provider: 'affine',
|
provider: 'affine',
|
||||||
};
|
};
|
||||||
@@ -335,4 +368,33 @@ export class AffineProvider extends BaseProvider {
|
|||||||
}
|
}
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override async assign(
|
||||||
|
to: BlocksuiteWorkspace,
|
||||||
|
from: BlocksuiteWorkspace
|
||||||
|
): Promise<BlocksuiteWorkspace> {
|
||||||
|
assert(to.room, 'Blocksuite Workspace without room(workspaceId).');
|
||||||
|
const ws = this._getWebsocketProvider(to);
|
||||||
|
applyUpdate(to.doc, encodeStateAsUpdate(from.doc));
|
||||||
|
// TODO: upload blobs and make sure doc is synced
|
||||||
|
await new Promise<void>((resolve, reject) => {
|
||||||
|
ws.once('synced', () => {
|
||||||
|
setTimeout(() => resolve(), 1000);
|
||||||
|
});
|
||||||
|
ws.once('lost-connection', () => reject());
|
||||||
|
ws.once('connection-error', () => reject());
|
||||||
|
});
|
||||||
|
return to;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async logout(): Promise<void> {
|
||||||
|
token.clear();
|
||||||
|
this._channel.disconnect();
|
||||||
|
this._wsMap.forEach(ws => ws.disconnect());
|
||||||
|
storage.removeItem('token');
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async getWorkspaceMembers(id: string) {
|
||||||
|
return this._apis.getWorkspaceMembers({ id });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,6 +140,10 @@ class Token {
|
|||||||
this.callbacks.splice(index, 1);
|
this.callbacks.splice(index, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clear() {
|
||||||
|
this._setToken();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const token = new Token();
|
export const token = new Token();
|
||||||
|
|||||||
@@ -79,7 +79,6 @@ export async function getWorkspaceMembers(
|
|||||||
|
|
||||||
export interface CreateWorkspaceParams {
|
export interface CreateWorkspaceParams {
|
||||||
name: string;
|
name: string;
|
||||||
avatar: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createWorkspace(
|
export async function createWorkspace(
|
||||||
|
|||||||
53
packages/data-center/src/provider/affine/channel.ts
Normal file
53
packages/data-center/src/provider/affine/channel.ts
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import websocket from 'lib0/websocket';
|
||||||
|
import { Logger } from 'src/types';
|
||||||
|
import { token } from './apis/token';
|
||||||
|
|
||||||
|
const RECONNECT_INTERVAL_TIME = 5000;
|
||||||
|
const MAX_RECONNECT_TIMES = 50;
|
||||||
|
|
||||||
|
export class WebsocketClient extends websocket.WebsocketClient {
|
||||||
|
public shouldReconnect = false;
|
||||||
|
private _reconnectInterval: number | null = null;
|
||||||
|
private _logger: Logger;
|
||||||
|
constructor(
|
||||||
|
url: string,
|
||||||
|
logger: Logger,
|
||||||
|
options?: { binaryType: 'arraybuffer' | 'blob' | null }
|
||||||
|
) {
|
||||||
|
super(url, options);
|
||||||
|
this._logger = logger;
|
||||||
|
this._setupChannel();
|
||||||
|
}
|
||||||
|
|
||||||
|
private _setupChannel() {
|
||||||
|
this.on('connect', () => {
|
||||||
|
this._logger('Affine channel connected');
|
||||||
|
this.shouldReconnect = true;
|
||||||
|
if (this._reconnectInterval) {
|
||||||
|
window.clearInterval(this._reconnectInterval);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.on('disconnect', ({ error }: { error: Error }) => {
|
||||||
|
if (error) {
|
||||||
|
let times = 0;
|
||||||
|
// Try reconnect if connect error has occurred
|
||||||
|
this._reconnectInterval = window.setInterval(() => {
|
||||||
|
if (this.shouldReconnect && token.isLogin && !this.connected) {
|
||||||
|
try {
|
||||||
|
this.connect();
|
||||||
|
this._logger(`try reconnect channel ${++times} times`);
|
||||||
|
if (times > MAX_RECONNECT_TIMES) {
|
||||||
|
this._logger('reconnect failed, max reconnect times reached');
|
||||||
|
this._reconnectInterval &&
|
||||||
|
window.clearInterval(this._reconnectInterval);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
this._logger('reconnect failed', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, RECONNECT_INTERVAL_TIME);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
import { Workspace as BlocksuiteWorkspace, uuidv4 } from '@blocksuite/store';
|
import { Workspace as BlocksuiteWorkspace, uuidv4 } from '@blocksuite/store';
|
||||||
import { MessageCenter } from '../message';
|
import { MessageCenter } from '../message';
|
||||||
import { Logger, User, WorkspaceInfo, WorkspaceMeta } from '../types';
|
import { Logger, User } from '../types';
|
||||||
import type { WorkspaceMetaCollectionScope } from '../workspace-meta-collection';
|
import type { WorkspaceUnitCollectionScope } from '../workspace-unit-collection';
|
||||||
|
import type { WorkspaceUnitCtorParams } from '../workspace-unit';
|
||||||
|
import { Member } from './affine/apis';
|
||||||
|
|
||||||
const defaultLogger = () => {
|
const defaultLogger = () => {
|
||||||
return;
|
return;
|
||||||
@@ -9,13 +11,19 @@ const defaultLogger = () => {
|
|||||||
|
|
||||||
export interface ProviderConstructorParams {
|
export interface ProviderConstructorParams {
|
||||||
logger?: Logger;
|
logger?: Logger;
|
||||||
workspaces: WorkspaceMetaCollectionScope;
|
workspaces: WorkspaceUnitCollectionScope;
|
||||||
messageCenter: MessageCenter;
|
messageCenter: MessageCenter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type WorkspaceMeta0 = WorkspaceUnitCtorParams;
|
||||||
|
export type CreateWorkspaceInfoParams = Pick<WorkspaceUnitCtorParams, 'name'>;
|
||||||
|
export type UpdateWorkspaceMetaParams = Partial<
|
||||||
|
Pick<WorkspaceUnitCtorParams, 'name' | 'avatar'>
|
||||||
|
>;
|
||||||
|
|
||||||
export class BaseProvider {
|
export class BaseProvider {
|
||||||
public readonly id: string = 'base';
|
public readonly id: string = 'base';
|
||||||
protected _workspaces!: WorkspaceMetaCollectionScope;
|
protected _workspaces!: WorkspaceUnitCollectionScope;
|
||||||
protected _logger!: Logger;
|
protected _logger!: Logger;
|
||||||
protected _messageCenter!: MessageCenter;
|
protected _messageCenter!: MessageCenter;
|
||||||
|
|
||||||
@@ -37,8 +45,8 @@ export class BaseProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async createWorkspaceInfo(
|
public async createWorkspaceInfo(
|
||||||
meta: WorkspaceMeta
|
params: CreateWorkspaceInfoParams
|
||||||
): Promise<WorkspaceInfo> {
|
): Promise<WorkspaceMeta0> {
|
||||||
throw new Error(`provider: ${this.id} createWorkspaceInfo Not implemented`);
|
throw new Error(`provider: ${this.id} createWorkspaceInfo Not implemented`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +78,7 @@ export class BaseProvider {
|
|||||||
/**
|
/**
|
||||||
* load workspaces
|
* load workspaces
|
||||||
**/
|
**/
|
||||||
public async loadWorkspaces(): Promise<WorkspaceInfo[]> {
|
public async loadWorkspaces(): Promise<WorkspaceMeta0[]> {
|
||||||
throw new Error(`provider: ${this.id} loadWorkSpace Not implemented`);
|
throw new Error(`provider: ${this.id} loadWorkSpace Not implemented`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,10 +165,10 @@ export class BaseProvider {
|
|||||||
*/
|
*/
|
||||||
public async updateWorkspaceMeta(
|
public async updateWorkspaceMeta(
|
||||||
id: string,
|
id: string,
|
||||||
meta: Partial<WorkspaceMeta>
|
params: UpdateWorkspaceMetaParams
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
id;
|
id;
|
||||||
meta;
|
params;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +178,7 @@ export class BaseProvider {
|
|||||||
*/
|
*/
|
||||||
public async createWorkspace(
|
public async createWorkspace(
|
||||||
blocksuiteWorkspace: BlocksuiteWorkspace,
|
blocksuiteWorkspace: BlocksuiteWorkspace,
|
||||||
meta: WorkspaceMeta
|
meta: WorkspaceMeta0
|
||||||
): Promise<BlocksuiteWorkspace | undefined> {
|
): Promise<BlocksuiteWorkspace | undefined> {
|
||||||
return blocksuiteWorkspace;
|
return blocksuiteWorkspace;
|
||||||
}
|
}
|
||||||
@@ -196,4 +204,24 @@ export class BaseProvider {
|
|||||||
): Promise<BlocksuiteWorkspace> {
|
): Promise<BlocksuiteWorkspace> {
|
||||||
return workspace;
|
return workspace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* merge one workspaces to another
|
||||||
|
* @param workspace
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
public async assign(to: BlocksuiteWorkspace, from: BlocksuiteWorkspace) {
|
||||||
|
from;
|
||||||
|
return to;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get workspace members
|
||||||
|
* @param {string} workspaceId
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
public getWorkspaceMembers(workspaceId: string): Promise<Member[]> {
|
||||||
|
workspaceId;
|
||||||
|
return Promise.resolve([]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
import * as idb from 'lib0/indexeddb.js';
|
import * as idb from 'lib0/indexeddb.js';
|
||||||
import { Observable } from 'lib0/observable.js';
|
import { Observable } from 'lib0/observable.js';
|
||||||
import type { Doc } from 'yjs';
|
import { Workspace as BlocksuiteWorkspace } from '@blocksuite/store';
|
||||||
import { applyUpdate, encodeStateAsUpdate, transact } from 'yjs';
|
|
||||||
|
|
||||||
const customStoreName = 'custom';
|
const customStoreName = 'custom';
|
||||||
const updatesStoreName = 'updates';
|
const updatesStoreName = 'updates';
|
||||||
|
|
||||||
const PREFERRED_TRIM_SIZE = 500;
|
const PREFERRED_TRIM_SIZE = 500;
|
||||||
|
|
||||||
|
const {
|
||||||
|
Y: { applyUpdate, transact, encodeStateAsUpdate },
|
||||||
|
} = BlocksuiteWorkspace;
|
||||||
|
|
||||||
|
type Doc = Parameters<typeof transact>[0];
|
||||||
|
|
||||||
const fetchUpdates = async (provider: IndexedDBProvider) => {
|
const fetchUpdates = async (provider: IndexedDBProvider) => {
|
||||||
const [updatesStore] = idb.transact(provider.db as IDBDatabase, [
|
const [updatesStore] = idb.transact(provider.db as IDBDatabase, [
|
||||||
updatesStoreName,
|
updatesStoreName,
|
||||||
20
packages/data-center/src/provider/local/indexeddb/utils.ts
Normal file
20
packages/data-center/src/provider/local/indexeddb/utils.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import assert from 'assert';
|
||||||
|
import * as idb from 'lib0/indexeddb.js';
|
||||||
|
import { Workspace as BlocksuiteWorkspace } from '@blocksuite/store';
|
||||||
|
|
||||||
|
const { encodeStateAsUpdate } = BlocksuiteWorkspace.Y;
|
||||||
|
|
||||||
|
export const initStore = async (blocksuiteWorkspace: BlocksuiteWorkspace) => {
|
||||||
|
const workspaceId = blocksuiteWorkspace.room;
|
||||||
|
assert(workspaceId);
|
||||||
|
await idb.deleteDB(workspaceId);
|
||||||
|
const db = await idb.openDB(workspaceId, db =>
|
||||||
|
idb.createStores(db, [['updates', { autoIncrement: true }], ['custom']])
|
||||||
|
);
|
||||||
|
const currState = encodeStateAsUpdate(blocksuiteWorkspace.doc);
|
||||||
|
const [updatesStore] = idb.transact(db, ['updates']); // , 'readonly')
|
||||||
|
|
||||||
|
if (updatesStore) {
|
||||||
|
await idb.addAutoKey(updatesStore, currState);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,13 +1,15 @@
|
|||||||
import { test, expect } from '@playwright/test';
|
import { test, expect } from '@playwright/test';
|
||||||
import { WorkspaceMetaCollection } from '../../workspace-meta-collection.js';
|
import { WorkspaceUnitCollection } from '../../workspace-unit-collection.js';
|
||||||
import { LocalProvider } from './local.js';
|
import { LocalProvider } from './local.js';
|
||||||
import { createBlocksuiteWorkspace } from '../../utils/index.js';
|
import { createBlocksuiteWorkspace } from '../../utils/index.js';
|
||||||
|
import { MessageCenter } from '../../message/index.js';
|
||||||
import 'fake-indexeddb/auto';
|
import 'fake-indexeddb/auto';
|
||||||
|
|
||||||
test.describe.serial('local provider', () => {
|
test.describe.serial('local provider', () => {
|
||||||
const workspaceMetaCollection = new WorkspaceMetaCollection();
|
const workspaceMetaCollection = new WorkspaceUnitCollection();
|
||||||
const provider = new LocalProvider({
|
const provider = new LocalProvider({
|
||||||
workspaces: workspaceMetaCollection.createScope(),
|
workspaces: workspaceMetaCollection.createScope(),
|
||||||
|
messageCenter: new MessageCenter(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const workspaceName = 'workspace-test';
|
const workspaceName = 'workspace-test';
|
||||||
@@ -16,23 +18,20 @@ test.describe.serial('local provider', () => {
|
|||||||
test('create workspace', async () => {
|
test('create workspace', async () => {
|
||||||
const workspaceInfo = await provider.createWorkspaceInfo({
|
const workspaceInfo = await provider.createWorkspaceInfo({
|
||||||
name: workspaceName,
|
name: workspaceName,
|
||||||
avatar: 'avatar-url-test',
|
|
||||||
});
|
});
|
||||||
workspaceId = workspaceInfo.id;
|
workspaceId = workspaceInfo.id;
|
||||||
const blocksuiteWorkspace = createBlocksuiteWorkspace(workspaceId);
|
const blocksuiteWorkspace = createBlocksuiteWorkspace(workspaceId);
|
||||||
await provider.createWorkspace(blocksuiteWorkspace, {
|
await provider.createWorkspace(blocksuiteWorkspace, workspaceInfo);
|
||||||
name: workspaceName,
|
|
||||||
avatar: 'avatar-url-test',
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(workspaceMetaCollection.workspaces.length).toEqual(1);
|
expect(workspaceMetaCollection.workspaces.length).toEqual(1);
|
||||||
expect(workspaceMetaCollection.workspaces[0].name).toEqual(workspaceName);
|
expect(workspaceMetaCollection.workspaces[0].name).toEqual(workspaceName);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('workspace list cache', async () => {
|
test('workspace list cache', async () => {
|
||||||
const workspacesMetaCollection1 = new WorkspaceMetaCollection();
|
const workspacesMetaCollection1 = new WorkspaceUnitCollection();
|
||||||
const provider1 = new LocalProvider({
|
const provider1 = new LocalProvider({
|
||||||
workspaces: workspacesMetaCollection1.createScope(),
|
workspaces: workspacesMetaCollection1.createScope(),
|
||||||
|
messageCenter: new MessageCenter(),
|
||||||
});
|
});
|
||||||
await provider1.loadWorkspaces();
|
await provider1.loadWorkspaces();
|
||||||
expect(workspacesMetaCollection1.workspaces.length).toEqual(1);
|
expect(workspacesMetaCollection1.workspaces.length).toEqual(1);
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
import { BaseProvider } from '../base.js';
|
import { BaseProvider } from '../base.js';
|
||||||
import type { ProviderConstructorParams } from '../base';
|
import type {
|
||||||
|
ProviderConstructorParams,
|
||||||
|
WorkspaceMeta0,
|
||||||
|
UpdateWorkspaceMetaParams,
|
||||||
|
CreateWorkspaceInfoParams,
|
||||||
|
} from '../base';
|
||||||
import { varStorage as storage } from 'lib0/storage';
|
import { varStorage as storage } from 'lib0/storage';
|
||||||
import { WorkspaceInfo, WorkspaceMeta } from '../../types';
|
|
||||||
import { Workspace as BlocksuiteWorkspace, uuidv4 } from '@blocksuite/store';
|
import { Workspace as BlocksuiteWorkspace, uuidv4 } from '@blocksuite/store';
|
||||||
import { IndexedDBProvider } from './indexeddb.js';
|
import { IndexedDBProvider } from './indexeddb/indexeddb.js';
|
||||||
|
import { initStore } from './indexeddb/utils.js';
|
||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import { setDefaultAvatar } from '../utils.js';
|
import { setDefaultAvatar } from '../utils.js';
|
||||||
|
|
||||||
@@ -15,11 +20,26 @@ export class LocalProvider extends BaseProvider {
|
|||||||
|
|
||||||
constructor(params: ProviderConstructorParams) {
|
constructor(params: ProviderConstructorParams) {
|
||||||
super(params);
|
super(params);
|
||||||
this.loadWorkspaces();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _storeWorkspaces(workspaces: WorkspaceInfo[]) {
|
private _storeWorkspaces(workspaces: WorkspaceMeta0[]) {
|
||||||
storage.setItem(WORKSPACE_KEY, JSON.stringify(workspaces));
|
storage.setItem(
|
||||||
|
WORKSPACE_KEY,
|
||||||
|
JSON.stringify(
|
||||||
|
workspaces.map(w => {
|
||||||
|
return {
|
||||||
|
id: w.id,
|
||||||
|
name: w.name,
|
||||||
|
avatar: w.avatar,
|
||||||
|
owner: w.owner,
|
||||||
|
published: w.published,
|
||||||
|
memberCount: w.memberCount,
|
||||||
|
provider: w.provider,
|
||||||
|
syncMode: w.syncMode,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async linkLocal(workspace: BlocksuiteWorkspace) {
|
public override async linkLocal(workspace: BlocksuiteWorkspace) {
|
||||||
@@ -41,12 +61,12 @@ export class LocalProvider extends BaseProvider {
|
|||||||
return workspace;
|
return workspace;
|
||||||
}
|
}
|
||||||
|
|
||||||
override loadWorkspaces(): Promise<WorkspaceInfo[]> {
|
override loadWorkspaces(): Promise<WorkspaceMeta0[]> {
|
||||||
const workspaceStr = storage.getItem(WORKSPACE_KEY);
|
const workspaceStr = storage.getItem(WORKSPACE_KEY);
|
||||||
let workspaces: WorkspaceInfo[] = [];
|
let workspaces: WorkspaceMeta0[] = [];
|
||||||
if (workspaceStr) {
|
if (workspaceStr) {
|
||||||
try {
|
try {
|
||||||
workspaces = JSON.parse(workspaceStr) as WorkspaceInfo[];
|
workspaces = JSON.parse(workspaceStr) as WorkspaceMeta0[];
|
||||||
workspaces.forEach(workspace => {
|
workspaces.forEach(workspace => {
|
||||||
this._workspaces.add(workspace);
|
this._workspaces.add(workspace);
|
||||||
});
|
});
|
||||||
@@ -70,22 +90,22 @@ export class LocalProvider extends BaseProvider {
|
|||||||
|
|
||||||
public override async updateWorkspaceMeta(
|
public override async updateWorkspaceMeta(
|
||||||
id: string,
|
id: string,
|
||||||
meta: Partial<WorkspaceMeta>
|
meta: UpdateWorkspaceMetaParams
|
||||||
) {
|
) {
|
||||||
this._workspaces.update(id, meta);
|
this._workspaces.update(id, meta);
|
||||||
this._storeWorkspaces(this._workspaces.list());
|
this._storeWorkspaces(this._workspaces.list());
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async createWorkspaceInfo(
|
public override async createWorkspaceInfo(
|
||||||
meta: WorkspaceMeta
|
meta: CreateWorkspaceInfoParams
|
||||||
): Promise<WorkspaceInfo> {
|
): Promise<WorkspaceMeta0> {
|
||||||
const workspaceInfo: WorkspaceInfo = {
|
const workspaceInfo: WorkspaceMeta0 = {
|
||||||
name: meta.name,
|
name: meta.name,
|
||||||
id: uuidv4(),
|
id: uuidv4(),
|
||||||
isPublish: false,
|
published: false,
|
||||||
avatar: '',
|
avatar: '',
|
||||||
owner: undefined,
|
owner: undefined,
|
||||||
isLocal: true,
|
syncMode: 'core',
|
||||||
memberCount: 1,
|
memberCount: 1,
|
||||||
provider: 'local',
|
provider: 'local',
|
||||||
};
|
};
|
||||||
@@ -94,25 +114,16 @@ export class LocalProvider extends BaseProvider {
|
|||||||
|
|
||||||
public override async createWorkspace(
|
public override async createWorkspace(
|
||||||
blocksuiteWorkspace: BlocksuiteWorkspace,
|
blocksuiteWorkspace: BlocksuiteWorkspace,
|
||||||
meta: WorkspaceMeta
|
meta: WorkspaceMeta0
|
||||||
): Promise<BlocksuiteWorkspace | undefined> {
|
): Promise<BlocksuiteWorkspace | undefined> {
|
||||||
const workspaceId = blocksuiteWorkspace.room;
|
const workspaceId = blocksuiteWorkspace.room;
|
||||||
assert(workspaceId, 'Blocksuite Workspace without room(workspaceId).');
|
assert(workspaceId, 'Blocksuite Workspace without room(workspaceId).');
|
||||||
assert(meta.name, 'Workspace name is required');
|
|
||||||
this._logger('Creating affine workspace');
|
this._logger('Creating affine workspace');
|
||||||
|
|
||||||
const workspaceInfo: WorkspaceInfo = {
|
const workspaceInfo: WorkspaceMeta0 = {
|
||||||
name: meta.name,
|
...meta,
|
||||||
id: workspaceId,
|
|
||||||
isPublish: false,
|
|
||||||
avatar: '',
|
|
||||||
owner: undefined,
|
|
||||||
isLocal: true,
|
|
||||||
memberCount: 1,
|
|
||||||
provider: 'local',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.linkLocal(blocksuiteWorkspace);
|
|
||||||
blocksuiteWorkspace.meta.setName(meta.name);
|
blocksuiteWorkspace.meta.setName(meta.name);
|
||||||
|
|
||||||
if (!meta.avatar) {
|
if (!meta.avatar) {
|
||||||
@@ -120,6 +131,8 @@ export class LocalProvider extends BaseProvider {
|
|||||||
workspaceInfo.avatar = blocksuiteWorkspace.meta.avatar;
|
workspaceInfo.avatar = blocksuiteWorkspace.meta.avatar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await initStore(blocksuiteWorkspace);
|
||||||
|
|
||||||
this._workspaces.add(workspaceInfo);
|
this._workspaces.add(workspaceInfo);
|
||||||
this._storeWorkspaces(this._workspaces.list());
|
this._storeWorkspaces(this._workspaces.list());
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ import { getDefaultHeadImgBlob } from '../utils/index.js';
|
|||||||
export const setDefaultAvatar = async (
|
export const setDefaultAvatar = async (
|
||||||
blocksuiteWorkspace: BlocksuiteWorkspace
|
blocksuiteWorkspace: BlocksuiteWorkspace
|
||||||
) => {
|
) => {
|
||||||
|
if (typeof document === 'undefined') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const blob = await getDefaultHeadImgBlob(blocksuiteWorkspace.meta.name);
|
const blob = await getDefaultHeadImgBlob(blocksuiteWorkspace.meta.name);
|
||||||
const blobStorage = await blocksuiteWorkspace.blobs;
|
const blobStorage = await blocksuiteWorkspace.blobs;
|
||||||
assert(blobStorage, 'No blob storage');
|
assert(blobStorage, 'No blob storage');
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
import { getLogger } from '../logger';
|
import { getLogger } from '../logger';
|
||||||
|
|
||||||
export type WorkspaceInfo = {
|
// export type WorkspaceInfo = {
|
||||||
name: string;
|
// name: string;
|
||||||
id: string;
|
// id: string;
|
||||||
isPublish?: boolean;
|
// isPublish?: boolean;
|
||||||
avatar?: string;
|
// avatar?: string;
|
||||||
owner?: User;
|
// owner?: User;
|
||||||
isLocal?: boolean;
|
// isLocal?: boolean;
|
||||||
memberCount: number;
|
// memberCount: number;
|
||||||
provider: string;
|
// provider: string;
|
||||||
};
|
// };
|
||||||
|
|
||||||
export type User = {
|
export type User = {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -18,7 +18,7 @@ export type User = {
|
|||||||
avatar: string;
|
avatar: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type WorkspaceMeta = Pick<WorkspaceInfo, 'name' | 'avatar'>;
|
// export type WorkspaceMeta = Pick<WorkspaceInfo, 'name' | 'avatar'>;
|
||||||
|
|
||||||
export type Logger = ReturnType<typeof getLogger>;
|
export type Logger = ReturnType<typeof getLogger>;
|
||||||
|
|
||||||
|
|||||||
@@ -1,50 +0,0 @@
|
|||||||
import { test, expect } from '@playwright/test';
|
|
||||||
import { WorkspaceMetaCollection } from './workspace-meta-collection.js';
|
|
||||||
import type { WorkspaceMetaCollectionChangeEvent } from './workspace-meta-collection';
|
|
||||||
|
|
||||||
test.describe.serial('workspace meta collection observable', () => {
|
|
||||||
const workspaces = new WorkspaceMetaCollection();
|
|
||||||
|
|
||||||
const scope = workspaces.createScope();
|
|
||||||
|
|
||||||
test('add workspace', () => {
|
|
||||||
workspaces.once('change', (event: WorkspaceMetaCollectionChangeEvent) => {
|
|
||||||
expect(event.added?.id).toEqual('123');
|
|
||||||
});
|
|
||||||
scope.add({
|
|
||||||
id: '123',
|
|
||||||
name: 'test',
|
|
||||||
memberCount: 1,
|
|
||||||
provider: '',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('list workspace', () => {
|
|
||||||
const list = scope.list();
|
|
||||||
expect(list.length).toEqual(1);
|
|
||||||
expect(list[0].id).toEqual('123');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('get workspace', () => {
|
|
||||||
expect(scope.get('123')?.id).toEqual('123');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('update workspace', () => {
|
|
||||||
workspaces.once('change', (event: WorkspaceMetaCollectionChangeEvent) => {
|
|
||||||
expect(event.updated?.name).toEqual('demo');
|
|
||||||
});
|
|
||||||
scope.update('123', { name: 'demo' });
|
|
||||||
});
|
|
||||||
|
|
||||||
test('get workspace form other scope', () => {
|
|
||||||
const scope1 = workspaces.createScope();
|
|
||||||
expect(scope1.get('123')).toBeFalsy();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('delete workspace', () => {
|
|
||||||
workspaces.once('change', (event: WorkspaceMetaCollectionChangeEvent) => {
|
|
||||||
expect(event.deleted?.id).toEqual('123');
|
|
||||||
});
|
|
||||||
scope.remove('123');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,127 +0,0 @@
|
|||||||
import { Observable } from 'lib0/observable';
|
|
||||||
import type { WorkspaceInfo, WorkspaceMeta } from './types';
|
|
||||||
|
|
||||||
export interface WorkspaceMetaCollectionScope {
|
|
||||||
get: (workspaceId: string) => WorkspaceInfo | undefined;
|
|
||||||
list: () => WorkspaceInfo[];
|
|
||||||
add: (workspace: WorkspaceInfo) => void;
|
|
||||||
remove: (workspaceId: string) => boolean;
|
|
||||||
clear: () => void;
|
|
||||||
update: (workspaceId: string, workspaceMeta: Partial<WorkspaceMeta>) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface WorkspaceMetaCollectionChangeEvent {
|
|
||||||
added?: WorkspaceInfo;
|
|
||||||
deleted?: WorkspaceInfo;
|
|
||||||
updated?: WorkspaceInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class WorkspaceMetaCollection extends Observable<'change'> {
|
|
||||||
private _workspacesMap = new Map<string, WorkspaceInfo>();
|
|
||||||
|
|
||||||
get workspaces(): WorkspaceInfo[] {
|
|
||||||
return Array.from(this._workspacesMap.values());
|
|
||||||
}
|
|
||||||
|
|
||||||
find(workspaceId: string) {
|
|
||||||
return this._workspacesMap.get(workspaceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
createScope(): WorkspaceMetaCollectionScope {
|
|
||||||
const scopedWorkspaceIds = new Set<string>();
|
|
||||||
|
|
||||||
const get = (workspaceId: string) => {
|
|
||||||
if (!scopedWorkspaceIds.has(workspaceId)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return this._workspacesMap.get(workspaceId);
|
|
||||||
};
|
|
||||||
|
|
||||||
const add = (workspace: WorkspaceInfo) => {
|
|
||||||
if (this._workspacesMap.has(workspace.id)) {
|
|
||||||
throw new Error(`Duplicate workspace id.`);
|
|
||||||
}
|
|
||||||
this._workspacesMap.set(workspace.id, workspace);
|
|
||||||
scopedWorkspaceIds.add(workspace.id);
|
|
||||||
|
|
||||||
this.emit('change', [
|
|
||||||
{
|
|
||||||
added: workspace,
|
|
||||||
} as WorkspaceMetaCollectionChangeEvent,
|
|
||||||
]);
|
|
||||||
};
|
|
||||||
|
|
||||||
const remove = (workspaceId: string) => {
|
|
||||||
if (!scopedWorkspaceIds.has(workspaceId)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const workspace = this._workspacesMap.get(workspaceId);
|
|
||||||
if (workspace) {
|
|
||||||
const ret = this._workspacesMap.delete(workspaceId);
|
|
||||||
// If deletion failed, return.
|
|
||||||
if (!ret) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
scopedWorkspaceIds.delete(workspaceId);
|
|
||||||
|
|
||||||
this.emit('change', [
|
|
||||||
{
|
|
||||||
deleted: workspace,
|
|
||||||
} as WorkspaceMetaCollectionChangeEvent,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
const clear = () => {
|
|
||||||
scopedWorkspaceIds.forEach(id => {
|
|
||||||
remove(id);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const update = (
|
|
||||||
workspaceId: string,
|
|
||||||
workspaceMeta: Partial<WorkspaceMeta>
|
|
||||||
) => {
|
|
||||||
if (!scopedWorkspaceIds.has(workspaceId)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const workspace = this._workspacesMap.get(workspaceId);
|
|
||||||
if (!workspace) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._workspacesMap.set(workspaceId, { ...workspace, ...workspaceMeta });
|
|
||||||
|
|
||||||
this.emit('change', [
|
|
||||||
{
|
|
||||||
updated: this._workspacesMap.get(workspaceId),
|
|
||||||
} as WorkspaceMetaCollectionChangeEvent,
|
|
||||||
]);
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: need to optimize
|
|
||||||
const list = () => {
|
|
||||||
const workspaces: WorkspaceInfo[] = [];
|
|
||||||
scopedWorkspaceIds.forEach(id => {
|
|
||||||
const workspace = this._workspacesMap.get(id);
|
|
||||||
if (workspace) {
|
|
||||||
workspaces.push(workspace);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return workspaces;
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
get,
|
|
||||||
list,
|
|
||||||
add,
|
|
||||||
remove,
|
|
||||||
clear,
|
|
||||||
update,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
60
packages/data-center/src/workspace-unit-collection.spec.ts
Normal file
60
packages/data-center/src/workspace-unit-collection.spec.ts
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import { WorkspaceUnitCollection } from './workspace-unit-collection.js';
|
||||||
|
import type { WorkspaceUnitCollectionChangeEvent } from './workspace-unit-collection';
|
||||||
|
|
||||||
|
test.describe.serial('workspace meta collection observable', () => {
|
||||||
|
const workspaceUnitCollection = new WorkspaceUnitCollection();
|
||||||
|
|
||||||
|
const scope = workspaceUnitCollection.createScope();
|
||||||
|
|
||||||
|
test('add workspace', () => {
|
||||||
|
workspaceUnitCollection.once(
|
||||||
|
'change',
|
||||||
|
(event: WorkspaceUnitCollectionChangeEvent) => {
|
||||||
|
expect(event.added?.[0]?.id).toEqual('123');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
scope.add({
|
||||||
|
id: '123',
|
||||||
|
name: 'test',
|
||||||
|
memberCount: 1,
|
||||||
|
provider: '',
|
||||||
|
syncMode: 'core',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('list workspace', () => {
|
||||||
|
const list = scope.list();
|
||||||
|
expect(list.length).toEqual(1);
|
||||||
|
expect(list[0].id).toEqual('123');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('get workspace', () => {
|
||||||
|
expect(scope.get('123')?.id).toEqual('123');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('update workspace', () => {
|
||||||
|
workspaceUnitCollection.once(
|
||||||
|
'change',
|
||||||
|
(event: WorkspaceUnitCollectionChangeEvent) => {
|
||||||
|
expect(event.updated?.name).toEqual('demo');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
scope.update('123', { name: 'demo' });
|
||||||
|
});
|
||||||
|
|
||||||
|
test('get workspace form other scope', () => {
|
||||||
|
const scope1 = workspaceUnitCollection.createScope();
|
||||||
|
expect(scope1.get('123')).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('delete workspace', () => {
|
||||||
|
workspaceUnitCollection.once(
|
||||||
|
'change',
|
||||||
|
(event: WorkspaceUnitCollectionChangeEvent) => {
|
||||||
|
expect(event.deleted?.id).toEqual('123');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
scope.remove('123');
|
||||||
|
});
|
||||||
|
});
|
||||||
152
packages/data-center/src/workspace-unit-collection.ts
Normal file
152
packages/data-center/src/workspace-unit-collection.ts
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
import { Observable } from 'lib0/observable';
|
||||||
|
import { WorkspaceUnit } from './workspace-unit.js';
|
||||||
|
import type {
|
||||||
|
WorkspaceUnitCtorParams,
|
||||||
|
UpdateWorkspaceUnitParams,
|
||||||
|
} from './workspace-unit';
|
||||||
|
|
||||||
|
export interface WorkspaceUnitCollectionScope {
|
||||||
|
get: (workspaceId: string) => WorkspaceUnit | undefined;
|
||||||
|
list: () => WorkspaceUnit[];
|
||||||
|
add: (workspace: WorkspaceUnitCtorParams) => void;
|
||||||
|
remove: (workspaceId: string) => boolean;
|
||||||
|
clear: () => void;
|
||||||
|
update: (
|
||||||
|
workspaceId: string,
|
||||||
|
workspaceMeta: UpdateWorkspaceUnitParams
|
||||||
|
) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface WorkspaceUnitCollectionChangeEvent {
|
||||||
|
added?: WorkspaceUnit[];
|
||||||
|
deleted?: WorkspaceUnit;
|
||||||
|
updated?: WorkspaceUnit;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class WorkspaceUnitCollection {
|
||||||
|
private _events = new Observable();
|
||||||
|
private _workspaceUnitMap = new Map<string, WorkspaceUnit>();
|
||||||
|
|
||||||
|
get workspaces(): WorkspaceUnit[] {
|
||||||
|
return Array.from(this._workspaceUnitMap.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
public on(
|
||||||
|
type: 'change',
|
||||||
|
callback: (event: WorkspaceUnitCollectionChangeEvent) => void
|
||||||
|
) {
|
||||||
|
this._events.on(type, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
public once(
|
||||||
|
type: 'change',
|
||||||
|
callback: (event: WorkspaceUnitCollectionChangeEvent) => void
|
||||||
|
) {
|
||||||
|
this._events.once(type, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
find(workspaceId: string) {
|
||||||
|
return this._workspaceUnitMap.get(workspaceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
createScope(): WorkspaceUnitCollectionScope {
|
||||||
|
const scopedWorkspaceIds = new Set<string>();
|
||||||
|
|
||||||
|
const get = (workspaceId: string) => {
|
||||||
|
if (!scopedWorkspaceIds.has(workspaceId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return this._workspaceUnitMap.get(workspaceId);
|
||||||
|
};
|
||||||
|
|
||||||
|
const add = (workspace: WorkspaceUnitCtorParams) => {
|
||||||
|
if (this._workspaceUnitMap.has(workspace.id)) {
|
||||||
|
throw new Error(`Duplicate workspace id.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const workspaceUnit = new WorkspaceUnit(workspace);
|
||||||
|
this._workspaceUnitMap.set(workspace.id, workspaceUnit);
|
||||||
|
|
||||||
|
scopedWorkspaceIds.add(workspace.id);
|
||||||
|
|
||||||
|
this._events.emit('change', [
|
||||||
|
{
|
||||||
|
added: [workspaceUnit],
|
||||||
|
} as WorkspaceUnitCollectionChangeEvent,
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const remove = (workspaceId: string) => {
|
||||||
|
if (!scopedWorkspaceIds.has(workspaceId)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const workspaceUnit = this._workspaceUnitMap.get(workspaceId);
|
||||||
|
if (workspaceUnit) {
|
||||||
|
const ret = this._workspaceUnitMap.delete(workspaceId);
|
||||||
|
// If deletion failed, return.
|
||||||
|
if (!ret) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
scopedWorkspaceIds.delete(workspaceId);
|
||||||
|
|
||||||
|
this._events.emit('change', [
|
||||||
|
{
|
||||||
|
deleted: workspaceUnit,
|
||||||
|
} as WorkspaceUnitCollectionChangeEvent,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const clear = () => {
|
||||||
|
scopedWorkspaceIds.forEach(id => {
|
||||||
|
remove(id);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const update = (
|
||||||
|
workspaceId: string,
|
||||||
|
workspaceMeta: UpdateWorkspaceUnitParams
|
||||||
|
) => {
|
||||||
|
if (!scopedWorkspaceIds.has(workspaceId)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const workspaceUnit = this._workspaceUnitMap.get(workspaceId);
|
||||||
|
if (!workspaceUnit) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
workspaceUnit.update(workspaceMeta);
|
||||||
|
|
||||||
|
this._events.emit('change', [
|
||||||
|
{
|
||||||
|
updated: workspaceUnit,
|
||||||
|
} as WorkspaceUnitCollectionChangeEvent,
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: need to optimize
|
||||||
|
const list = () => {
|
||||||
|
const workspaceUnits: WorkspaceUnit[] = [];
|
||||||
|
scopedWorkspaceIds.forEach(id => {
|
||||||
|
const workspaceUnit = this._workspaceUnitMap.get(id);
|
||||||
|
if (workspaceUnit) {
|
||||||
|
workspaceUnits.push(workspaceUnit);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return workspaceUnits;
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
get,
|
||||||
|
list,
|
||||||
|
add,
|
||||||
|
remove,
|
||||||
|
clear,
|
||||||
|
update,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
64
packages/data-center/src/workspace-unit.ts
Normal file
64
packages/data-center/src/workspace-unit.ts
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
import { Workspace as BlocksuiteWorkspace } from '@blocksuite/store';
|
||||||
|
import type { User } from './types';
|
||||||
|
|
||||||
|
export type SyncMode = 'all' | 'core';
|
||||||
|
|
||||||
|
export interface WorkspaceUnitCtorParams {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
avatar?: string;
|
||||||
|
owner?: User;
|
||||||
|
published?: boolean;
|
||||||
|
memberCount: number;
|
||||||
|
provider: string;
|
||||||
|
syncMode: SyncMode;
|
||||||
|
|
||||||
|
blocksuiteWorkspace?: BlocksuiteWorkspace | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type UpdateWorkspaceUnitParams = Partial<
|
||||||
|
Omit<WorkspaceUnitCtorParams, 'id'>
|
||||||
|
>;
|
||||||
|
|
||||||
|
export class WorkspaceUnit {
|
||||||
|
public readonly id: string;
|
||||||
|
public name!: string;
|
||||||
|
public avatar?: string;
|
||||||
|
public owner?: User;
|
||||||
|
public published?: boolean;
|
||||||
|
public memberCount!: number;
|
||||||
|
public provider!: string;
|
||||||
|
public syncMode: 'all' | 'core' = 'core';
|
||||||
|
|
||||||
|
private _blocksuiteWorkspace?: BlocksuiteWorkspace | null;
|
||||||
|
|
||||||
|
constructor(params: WorkspaceUnitCtorParams) {
|
||||||
|
this.id = params.id;
|
||||||
|
this.update(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
get blocksuiteWorkspace() {
|
||||||
|
return this._blocksuiteWorkspace;
|
||||||
|
}
|
||||||
|
|
||||||
|
setBlocksuiteWorkspace(blocksuiteWorkspace: BlocksuiteWorkspace | null) {
|
||||||
|
if (blocksuiteWorkspace && blocksuiteWorkspace?.room !== this.id) {
|
||||||
|
throw new Error('Workspace id inconsistent.');
|
||||||
|
}
|
||||||
|
this._blocksuiteWorkspace = blocksuiteWorkspace;
|
||||||
|
}
|
||||||
|
|
||||||
|
update(params: UpdateWorkspaceUnitParams) {
|
||||||
|
Object.assign(this, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
get isPublish() {
|
||||||
|
console.error('Suggest changing to published');
|
||||||
|
return this.published;
|
||||||
|
}
|
||||||
|
|
||||||
|
get isLocal() {
|
||||||
|
console.error('Suggest changing to syncMode');
|
||||||
|
return this.syncMode === 'all';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import i18next, { Resource } from 'i18next';
|
import i18next, { Resource } from 'i18next';
|
||||||
import { initReactI18next, useTranslation } from 'react-i18next';
|
import { Trans, initReactI18next, useTranslation } from 'react-i18next';
|
||||||
import { LOCALES } from './resources/index.js';
|
import { LOCALES } from './resources/index.js';
|
||||||
import type en_US from './resources/en.json';
|
import type en_US from './resources/en.json';
|
||||||
|
|
||||||
@@ -21,9 +21,9 @@ declare module 'react-i18next' {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// const STORAGE_KEY = 'i18n_lng';
|
const STORAGE_KEY = 'i18n_lng';
|
||||||
|
|
||||||
export { i18n, useTranslation, LOCALES };
|
export { Trans, i18n, useTranslation, LOCALES };
|
||||||
|
|
||||||
const resources = LOCALES.reduce<Resource>(
|
const resources = LOCALES.reduce<Resource>(
|
||||||
(acc, { tag, res }) => ({ ...acc, [tag]: { translation: res } }),
|
(acc, { tag, res }) => ({ ...acc, [tag]: { translation: res } }),
|
||||||
@@ -33,17 +33,26 @@ const resources = LOCALES.reduce<Resource>(
|
|||||||
const fallbackLng = LOCALES[0].tag;
|
const fallbackLng = LOCALES[0].tag;
|
||||||
const standardizeLocale = (language: string) => {
|
const standardizeLocale = (language: string) => {
|
||||||
if (LOCALES.find(locale => locale.tag === language)) return language;
|
if (LOCALES.find(locale => locale.tag === language)) return language;
|
||||||
|
if (language === 'zh-CN' || language === 'zh') {
|
||||||
|
return 'zh-Hans';
|
||||||
|
}
|
||||||
|
if (language.slice(0, 2).toLowerCase() === 'zh') {
|
||||||
|
return 'zh-Hant';
|
||||||
|
}
|
||||||
if (LOCALES.find(locale => locale.tag === language.slice(0, 2).toLowerCase()))
|
if (LOCALES.find(locale => locale.tag === language.slice(0, 2).toLowerCase()))
|
||||||
return language;
|
return language;
|
||||||
return fallbackLng;
|
return fallbackLng;
|
||||||
};
|
};
|
||||||
|
let language = 'en';
|
||||||
|
|
||||||
const language = standardizeLocale(
|
if (typeof window !== 'undefined') {
|
||||||
// localStorage.getItem(STORAGE_KEY) ??
|
const localStorageLanguage = localStorage.getItem(STORAGE_KEY);
|
||||||
// (typeof navigator !== 'undefined' ? navigator.language : 'en')
|
if (localStorageLanguage) {
|
||||||
'en'
|
language = standardizeLocale(localStorageLanguage);
|
||||||
);
|
} else {
|
||||||
|
language = standardizeLocale(navigator.language);
|
||||||
|
}
|
||||||
|
}
|
||||||
const i18n = i18next.createInstance();
|
const i18n = i18next.createInstance();
|
||||||
i18n.use(initReactI18next).init({
|
i18n.use(initReactI18next).init({
|
||||||
lng: language,
|
lng: language,
|
||||||
@@ -55,8 +64,8 @@ i18n.use(initReactI18next).init({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
i18n.on('languageChanged', () => {
|
i18n.on('languageChanged', lng => {
|
||||||
// localStorage.setItem(STORAGE_KEY, lng);
|
localStorage.setItem(STORAGE_KEY, lng);
|
||||||
});
|
});
|
||||||
|
|
||||||
// const I18nProvider = I18nextProvider;
|
// const I18nProvider = I18nextProvider;
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
{
|
{
|
||||||
"Quick search": "Quick search",
|
"Quick search": "Quick search",
|
||||||
|
"Quick search placeholder": "Quick Search...",
|
||||||
|
"Quick search placeholder2": "Search in {{workspace}}",
|
||||||
"All pages": "All pages",
|
"All pages": "All pages",
|
||||||
"Favourites": "Favourites",
|
"Favourites": "Favourites",
|
||||||
"No item": "No item",
|
"No item": "No item",
|
||||||
|
"Settings": "Settings",
|
||||||
"Import": "Import",
|
"Import": "Import",
|
||||||
"Trash": "Trash",
|
"Trash": "Trash",
|
||||||
"New Page": "New Page",
|
"New Page": "New Page",
|
||||||
@@ -54,7 +57,7 @@
|
|||||||
"Strikethrough": "Strikethrough",
|
"Strikethrough": "Strikethrough",
|
||||||
"Inline code": "Inline code",
|
"Inline code": "Inline code",
|
||||||
"Code block": "Code block",
|
"Code block": "Code block",
|
||||||
"Link": "Hyperlink(with selected text)",
|
"Link": "Hyperlink (with selected text)",
|
||||||
"Body text": "Body text",
|
"Body text": "Body text",
|
||||||
"Heading": "Heading {{number}}",
|
"Heading": "Heading {{number}}",
|
||||||
"Increase indent": "Increase indent",
|
"Increase indent": "Increase indent",
|
||||||
@@ -75,5 +78,66 @@
|
|||||||
"Restore it": "Restore it",
|
"Restore it": "Restore it",
|
||||||
"TrashButtonGroupTitle": "Permanently delete",
|
"TrashButtonGroupTitle": "Permanently delete",
|
||||||
"TrashButtonGroupDescription": "Once deleted, you can't undo this action. Do you confirm?",
|
"TrashButtonGroupDescription": "Once deleted, you can't undo this action. Do you confirm?",
|
||||||
"Delete permanently": "Delete permanently"
|
"Delete permanently": "Delete permanently",
|
||||||
|
"recommendBrowser": " We recommend the <1>Chrome</1> browser for optimal experience.",
|
||||||
|
"upgradeBrowser": "Please upgrade to the latest version of Chrome for the best experience.",
|
||||||
|
"Invite Members": "Invite Members",
|
||||||
|
"Invite placeholder": "Search mail (Gmail support only)",
|
||||||
|
"Non-Gmail": "Non-Gmail is not supported",
|
||||||
|
"Invite": "Invite",
|
||||||
|
"Loading": "Loading...",
|
||||||
|
"NotLoggedIn": "Currently not logged in",
|
||||||
|
"ClearData": "Clear local data",
|
||||||
|
"Continue with Google": "Continue with Google",
|
||||||
|
"Set up an AFFiNE account to sync data": "Set up an AFFiNE account to sync data",
|
||||||
|
"Stay logged out": "Stay logged out",
|
||||||
|
"All changes are saved locally": "All changes are saved locally",
|
||||||
|
"Ooops!": "Ooops!",
|
||||||
|
"mobile device": "Looks like you are browsing on a mobile device.",
|
||||||
|
"mobile device description": "We are still working on mobile support and recommend you use a desktop device.",
|
||||||
|
"Got it": "Got it",
|
||||||
|
"emptyAllPages": "This workspace is empty. Create a new page to begin editing.",
|
||||||
|
"emptyFavourite": "Click Add to Favourites and the page will appear here.",
|
||||||
|
"emptyTrash": "Click Add to Trash and the page will appear here.",
|
||||||
|
"still designed": "(This page is still being designed.)",
|
||||||
|
"My Workspaces": "My Workspaces",
|
||||||
|
"Create Or Import": "Create Or Import",
|
||||||
|
"Tips": "Tips: ",
|
||||||
|
"login success": "Login success",
|
||||||
|
"Sign in": "Sign in AFFiNE Cloud",
|
||||||
|
"Sign out": "Sign out of AFFiNE Cloud",
|
||||||
|
"Delete Workspace": "Delete Workspace",
|
||||||
|
"Delete Workspace Description": "Deleting (<1>{{workspace}}</1>) cannot be undone, please proceed with caution. along with all its content.",
|
||||||
|
"Delete Workspace Description2": "Deleting (<1>{{workspace}}</1>) will delete both local and cloud data, this operation cannot be undone, please proceed with caution.",
|
||||||
|
"Delete Workspace placeholder": "Please type “Delete” to confirm",
|
||||||
|
"Leave Workspace": "Leave Workspace",
|
||||||
|
"Leave Workspace Description": "After you leave, you will not be able to access all the contents of this workspace.",
|
||||||
|
"Leave": "Leave",
|
||||||
|
"Workspace Icon": "Workspace Icon",
|
||||||
|
"Workspace Name": "Workspace Name",
|
||||||
|
"Workspace Type": "Workspace Type",
|
||||||
|
"Export Workspace": "Export Workspace <1>{{workspace}}</1> Is Coming",
|
||||||
|
"Users": "Users",
|
||||||
|
"Access level": "Access level",
|
||||||
|
"Pending": "Pending",
|
||||||
|
"Collaboration Description": "Collaborating with other members requires AFFiNE Cloud service.",
|
||||||
|
"Enable AFFiNE Cloud": "Enable AFFiNE Cloud",
|
||||||
|
"Enable AFFiNE Cloud Description": "If enabled, the data in this workspace will be backed up and synchronised via AFFiNE Cloud.",
|
||||||
|
"Enable": "Enable",
|
||||||
|
"Sign in and Enable": "Sign in and Enable",
|
||||||
|
"Skip": "Skip",
|
||||||
|
"Publishing": "Publishing to web requires AFFiNE Cloud service.",
|
||||||
|
"Share with link": "Share with link",
|
||||||
|
"Copy Link": "Copy Link",
|
||||||
|
"Publishing Description": "After publishing to the web, everyone can view the content of this workspace through the link.",
|
||||||
|
"Stop publishing": "Stop publishing",
|
||||||
|
"Publish to web": "Publish to web",
|
||||||
|
"Sync Description": "{{workspaceName}} is Local Workspace. All data is stored on the current device. You can enable AFFiNE Cloud for this workspace to keep data in sync with the cloud.",
|
||||||
|
"Sync Description2": "<1>{{workspaceName}}</1> is Cloud Workspace. All data will be synchronized and saved to the AFFiNE",
|
||||||
|
"Download data to device": "Download {{CoreOrAll}} data to device",
|
||||||
|
"General": "General",
|
||||||
|
"Sync": "Sync",
|
||||||
|
"Collaboration": "Collaboration",
|
||||||
|
"Publish": "Publish",
|
||||||
|
"Workspace Settings": "Workspace Settings"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,65 +1 @@
|
|||||||
{
|
{}
|
||||||
"Quick search": "快速搜索",
|
|
||||||
"All pages": "全部页面",
|
|
||||||
"Favourites": "收藏夹",
|
|
||||||
"No item": "没有项目",
|
|
||||||
"Import": "导入",
|
|
||||||
"Trash": "回收站",
|
|
||||||
"New Page": "新建文章",
|
|
||||||
"New Keyword Page": "新建 '{{query}}' 为标题的文章",
|
|
||||||
"Find 0 result": "找到 0 个结果",
|
|
||||||
"Find results": "找到 {{number}} 个结果",
|
|
||||||
"Collapse sidebar": "关闭侧边栏",
|
|
||||||
"Expand sidebar": "展开侧边栏",
|
|
||||||
"Removed from Favourites": "已从收藏中移除",
|
|
||||||
"Remove from favourites": "从收藏中移除",
|
|
||||||
"Added to Favourites": "已添加到收藏",
|
|
||||||
"Add to favourites": "添加到收藏",
|
|
||||||
"Paper": "文章",
|
|
||||||
"Edgeless": "无边模式",
|
|
||||||
"Switch to": "跳转到",
|
|
||||||
"Convert to ": "转换成 ",
|
|
||||||
"Page": "文章",
|
|
||||||
"Export": "导出",
|
|
||||||
"Export to HTML": "导出到 HTML",
|
|
||||||
"Export to Markdown": "导出到 Markdown",
|
|
||||||
"Delete": "删除",
|
|
||||||
"Title": "标题",
|
|
||||||
"Untitled": "无标题",
|
|
||||||
"Created": "创建时间",
|
|
||||||
"Updated": "更新时间",
|
|
||||||
"Open in new tab": "在新页面打开",
|
|
||||||
"Favourite": "收藏",
|
|
||||||
"Favourited": "已收藏",
|
|
||||||
"Delete page?": "删除文章?",
|
|
||||||
"Delete permanently?": "永久删除?",
|
|
||||||
"will be moved to Trash": "{{title}} 将被移动到回收站",
|
|
||||||
"Once deleted, you can't undo this action.": "一次性删除,无法恢复。",
|
|
||||||
"Moved to Trash": "已移动到回收站",
|
|
||||||
"Permanently deleted": "已永久删除",
|
|
||||||
"restored": "{{title}} 已恢复",
|
|
||||||
"Cancel": "取消",
|
|
||||||
"Keyboard Shortcuts": "快捷键",
|
|
||||||
"Contact Us": "联系我们",
|
|
||||||
"Official Website": "官网",
|
|
||||||
"Get in touch!": "Get in touch!",
|
|
||||||
"AFFiNE Community": "AFFiNE Community",
|
|
||||||
"How is AFFiNE Alpha different?": "How is AFFiNE Alpha different?",
|
|
||||||
"Shortcuts": "Shortcuts",
|
|
||||||
"Undo": "Undo",
|
|
||||||
"Redo": "Redo",
|
|
||||||
"Bold": "Bold",
|
|
||||||
"Italic": "Italic",
|
|
||||||
"Underline": "Underline",
|
|
||||||
"Strikethrough": "Strikethrough",
|
|
||||||
"Inline code": "Inline code",
|
|
||||||
"Code block": "Code block",
|
|
||||||
"Link": "Link",
|
|
||||||
"Body text": "Body text",
|
|
||||||
"Heading": "Heading {{number}}",
|
|
||||||
"Increase indent": "Increase indent",
|
|
||||||
"Reduce indent": "Reduce indent",
|
|
||||||
"Markdown Syntax": "Markdown Syntax",
|
|
||||||
"Divider": "Divider",
|
|
||||||
"404 - Page Not Found": "404 - Page Not Found"
|
|
||||||
}
|
|
||||||
|
|||||||
3549
pnpm-lock.yaml
generated
3549
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user