feat!: affine cloud support (#3813)

Co-authored-by: Hongtao Lye <codert.sn@gmail.com>
Co-authored-by: liuyi <forehalo@gmail.com>
Co-authored-by: LongYinan <lynweklm@gmail.com>
Co-authored-by: X1a0t <405028157@qq.com>
Co-authored-by: JimmFly <yangjinfei001@gmail.com>
Co-authored-by: Peng Xiao <pengxiao@outlook.com>
Co-authored-by: xiaodong zuo <53252747+zuoxiaodong0815@users.noreply.github.com>
Co-authored-by: DarkSky <25152247+darkskygit@users.noreply.github.com>
Co-authored-by: Qi <474021214@qq.com>
Co-authored-by: danielchim <kahungchim@gmail.com>
This commit is contained in:
Alex Yang
2023-08-29 05:07:05 -05:00
committed by GitHub
parent d0145c6f38
commit 2f6c4e3696
414 changed files with 19469 additions and 7591 deletions

View File

@@ -5,6 +5,7 @@ declare global {
interface Window {
appInfo: {
electron: boolean;
schema: string;
};
}
}

View File

@@ -2,8 +2,7 @@
import { assertEquals } from '@blocksuite/global/utils';
import { z } from 'zod';
import { isBrowser, isDesktop, isServer } from './constant.js';
import { isValidIPAddress } from './is-valid-ip-address.js';
import { isDesktop, isServer } from './constant.js';
import { UaHelper } from './ua-helper.js';
export const blockSuiteFeatureFlags = z.object({
@@ -37,8 +36,10 @@ export const runtimeFlagsSchema = z.object({
enableSQLiteProvider: z.boolean(),
enableNotificationCenter: z.boolean(),
enableCloud: z.boolean(),
enableEnhanceShareMode: z.boolean(),
// this is for the electron app
serverUrlPrefix: z.string(),
enableMoveDatabase: z.boolean(),
serverAPI: z.string(),
editorFlags: blockSuiteFeatureFlags,
appVersion: z.string(),
editorVersion: z.string(),
@@ -163,31 +164,5 @@ export function setupGlobal() {
}
globalThis.environment = environment;
let prefixUrl: string;
if (!isBrowser || isDesktop) {
// SSR or Desktop
const serverAPI = runtimeConfig.serverAPI;
if (isValidIPAddress(serverAPI.split(':')[0])) {
// This is for Server side rendering support
prefixUrl = new URL('http://' + runtimeConfig.serverAPI + '/').origin;
} else {
prefixUrl = serverAPI;
}
prefixUrl = prefixUrl.endsWith('/') ? prefixUrl : prefixUrl + '/';
} else {
const params = new URLSearchParams(window.location.search);
if (params.get('prefixUrl')) {
prefixUrl = params.get('prefixUrl') as string;
} else {
prefixUrl = window.location.origin + '/';
}
}
const apiUrl = new URL(prefixUrl);
const wsProtocol = apiUrl.protocol === 'https:' ? 'wss' : 'ws';
const websocketPrefixUrl = `${wsProtocol}://${apiUrl.host}`;
globalThis.prefixUrl = prefixUrl;
globalThis.websocketPrefixUrl = websocketPrefixUrl;
globalThis.$AFFINE_SETUP = true;
}

View File

@@ -49,6 +49,10 @@ export interface SQLiteDBDownloadProvider extends ActiveDocProvider {
flavour: 'sqlite-download';
}
export interface AffineSocketIOProvider extends PassiveDocProvider {
flavour: 'affine-socket-io';
}
type BaseWorkspace = {
flavour: string;
id: string;
@@ -68,11 +72,16 @@ export interface LocalWorkspace extends BaseWorkspace {
}
export interface AffinePublicWorkspace extends BaseWorkspace {
flavour: WorkspaceFlavour.PUBLIC;
flavour: WorkspaceFlavour.AFFINE_PUBLIC;
id: string;
blockSuiteWorkspace: BlockSuiteWorkspace;
}
export type AffineOfficialWorkspace =
| AffineCloudWorkspace
| LocalWorkspace
| AffinePublicWorkspace;
export enum ReleaseType {
// if workspace is not released yet, we will not show it in the workspace list
UNRELEASED = 'unreleased',
@@ -91,7 +100,7 @@ export enum WorkspaceFlavour {
*/
AFFINE_CLOUD = 'affine-cloud',
LOCAL = 'local',
PUBLIC = 'affine-public',
AFFINE_PUBLIC = 'affine-public',
}
export const settingPanel = {
@@ -107,7 +116,7 @@ export type SettingPanel = (typeof settingPanel)[keyof typeof settingPanel];
// built-in workspaces
export interface WorkspaceRegistry {
[WorkspaceFlavour.LOCAL]: LocalWorkspace;
[WorkspaceFlavour.PUBLIC]: AffinePublicWorkspace;
[WorkspaceFlavour.AFFINE_PUBLIC]: AffinePublicWorkspace;
[WorkspaceFlavour.AFFINE_CLOUD]: AffineCloudWorkspace;
}
@@ -137,7 +146,9 @@ export type WorkspaceHeaderProps<Flavour extends keyof WorkspaceRegistry> =
type NewSettingProps<Flavour extends keyof WorkspaceRegistry> =
UIBaseProps<Flavour> & {
onDeleteWorkspace: (id: string) => Promise<void>;
onDeleteLocalWorkspace: () => void;
onDeleteCloudWorkspace: () => void;
onLeaveWorkspace: () => void;
onTransformWorkspace: <
From extends keyof WorkspaceRegistry,
To extends keyof WorkspaceRegistry,
@@ -170,16 +181,15 @@ export interface WorkspaceUISchema<Flavour extends keyof WorkspaceRegistry> {
PageList: FC<PageListProps<Flavour>>;
NewSettingsDetail: FC<NewSettingProps<Flavour>>;
Provider: FC<PropsWithChildren>;
LoginCard?: FC<object>;
}
export interface AppEvents {
// event there is no workspace
// usually used to initialize workspace plugin
// usually used to initialize workspace adapter
'app:init': () => string[];
// request to gain access to workspace plugin
'workspace:access': () => Promise<void>;
// request to revoke access to workspace plugin
'workspace:revoke': () => Promise<void>;
// event if you have access to workspace adapter
'app:access': () => Promise<boolean>;
}
export interface WorkspaceAdapter<Flavour extends WorkspaceFlavour> {