mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-06 11:59:51 +08:00
fix: move workspace to top level (#2717)
(cherry picked from commit 4958d096b0)
This commit is contained in:
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
export type LiteralValue =
|
||||
| number
|
||||
| string
|
||||
| boolean
|
||||
| { [K: string]: LiteralValue }
|
||||
| Array<LiteralValue>;
|
||||
|
||||
export type Ref = {
|
||||
type: 'ref';
|
||||
name: keyof VariableMap;
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
export interface VariableMap {}
|
||||
|
||||
export type Literal = {
|
||||
type: 'literal';
|
||||
value: LiteralValue;
|
||||
};
|
||||
|
||||
export type Filter = {
|
||||
type: 'filter';
|
||||
left: Ref;
|
||||
funcName: string;
|
||||
args: Literal[];
|
||||
};
|
||||
|
||||
export type View = {
|
||||
id: string;
|
||||
name: string;
|
||||
filterList: Filter[];
|
||||
};
|
||||
Vendored
+232
@@ -0,0 +1,232 @@
|
||||
import type { EditorContainer } from '@blocksuite/editor';
|
||||
import type { Page } from '@blocksuite/store';
|
||||
import type { Workspace as BlockSuiteWorkspace } from '@blocksuite/store';
|
||||
import type { FC, PropsWithChildren } from 'react';
|
||||
|
||||
import type { View } from './filter';
|
||||
import type { Workspace as RemoteWorkspace } from './workspace/legacy-cloud';
|
||||
|
||||
export enum WorkspaceSubPath {
|
||||
ALL = 'all',
|
||||
SETTING = 'setting',
|
||||
TRASH = 'trash',
|
||||
SHARED = 'shared',
|
||||
}
|
||||
|
||||
export type BaseProvider = {
|
||||
flavour: string;
|
||||
|
||||
// cleanup data when workspace is removed
|
||||
cleanup: () => void;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description
|
||||
* If a provider is marked as a background provider,
|
||||
* we will connect it in the `useEffect` in React.js.
|
||||
*
|
||||
* This means that the data might be stale when you use it.
|
||||
*/
|
||||
export interface BackgroundProvider extends BaseProvider {
|
||||
// if this is true,
|
||||
// we will connect the provider on the background
|
||||
background: true;
|
||||
get connected(): boolean;
|
||||
connect(): void;
|
||||
disconnect(): void;
|
||||
callbacks: Set<() => void>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description
|
||||
* If a provider is marked as a necessary provider,
|
||||
* we will connect it once you read the workspace.
|
||||
*
|
||||
* This means that the data will be fresh when you use it.
|
||||
*
|
||||
* Currently, there is only on necessary provider: `local-indexeddb`.
|
||||
*/
|
||||
export interface NecessaryProvider extends Omit<BaseProvider, 'disconnect'> {
|
||||
// if this is true,
|
||||
// we will ensure that the provider is connected before you can use it
|
||||
necessary: true;
|
||||
sync(): void;
|
||||
get whenReady(): Promise<void>;
|
||||
}
|
||||
|
||||
export interface AffineDownloadProvider extends BackgroundProvider {
|
||||
flavour: 'affine-download';
|
||||
}
|
||||
|
||||
/**
|
||||
* Download the first binary from local indexeddb
|
||||
*/
|
||||
export interface BroadCastChannelProvider extends BackgroundProvider {
|
||||
flavour: 'broadcast-channel';
|
||||
}
|
||||
|
||||
/**
|
||||
* Long polling provider with local indexeddb
|
||||
*/
|
||||
export interface LocalIndexedDBBackgroundProvider extends BackgroundProvider {
|
||||
flavour: 'local-indexeddb-background';
|
||||
}
|
||||
|
||||
export interface LocalIndexedDBDownloadProvider extends NecessaryProvider {
|
||||
flavour: 'local-indexeddb';
|
||||
}
|
||||
|
||||
export interface SQLiteProvider extends BackgroundProvider {
|
||||
flavour: 'sqlite';
|
||||
}
|
||||
|
||||
export interface SQLiteDBDownloadProvider extends NecessaryProvider {
|
||||
flavour: 'sqlite-download';
|
||||
}
|
||||
|
||||
export interface AffineWebSocketProvider extends BackgroundProvider {
|
||||
flavour: 'affine-websocket';
|
||||
}
|
||||
|
||||
export type Provider = BackgroundProvider | NecessaryProvider;
|
||||
|
||||
export interface AffineLegacyCloudWorkspace extends RemoteWorkspace {
|
||||
flavour: WorkspaceFlavour.AFFINE;
|
||||
// empty
|
||||
blockSuiteWorkspace: BlockSuiteWorkspace;
|
||||
providers: Provider[];
|
||||
}
|
||||
|
||||
// todo: update type with nest.js
|
||||
export type AffineCloudWorkspace = LocalWorkspace;
|
||||
|
||||
export interface LocalWorkspace {
|
||||
flavour: WorkspaceFlavour.LOCAL;
|
||||
id: string;
|
||||
blockSuiteWorkspace: BlockSuiteWorkspace;
|
||||
providers: Provider[];
|
||||
}
|
||||
|
||||
export interface AffinePublicWorkspace {
|
||||
flavour: WorkspaceFlavour.PUBLIC;
|
||||
id: string;
|
||||
blockSuiteWorkspace: BlockSuiteWorkspace;
|
||||
providers: Provider[];
|
||||
}
|
||||
|
||||
export enum ReleaseType {
|
||||
// if workspace is not released yet, we will not show it in the workspace list
|
||||
UNRELEASED = 'unreleased',
|
||||
STABLE = 'stable',
|
||||
}
|
||||
|
||||
export enum LoadPriority {
|
||||
HIGH = 1,
|
||||
MEDIUM = 2,
|
||||
LOW = 3,
|
||||
}
|
||||
|
||||
export enum WorkspaceFlavour {
|
||||
/**
|
||||
* AFFiNE Workspace is the workspace
|
||||
* that hosted on the Legacy AFFiNE Cloud Server.
|
||||
*
|
||||
* @deprecated
|
||||
* We no longer maintain this kind of workspace, please use AFFiNE-Cloud instead.
|
||||
*/
|
||||
AFFINE = 'affine',
|
||||
/**
|
||||
* New AFFiNE Cloud Workspace using Nest.js Server.
|
||||
*/
|
||||
AFFINE_CLOUD = 'affine-cloud',
|
||||
LOCAL = 'local',
|
||||
PUBLIC = 'affine-public',
|
||||
}
|
||||
|
||||
export const settingPanel = {
|
||||
General: 'general',
|
||||
Collaboration: 'collaboration',
|
||||
Publish: 'publish',
|
||||
Export: 'export',
|
||||
Sync: 'sync',
|
||||
} as const;
|
||||
export const settingPanelValues = [...Object.values(settingPanel)] as const;
|
||||
export type SettingPanel = (typeof settingPanel)[keyof typeof settingPanel];
|
||||
|
||||
// built-in workspaces
|
||||
export interface WorkspaceRegistry {
|
||||
[WorkspaceFlavour.AFFINE]: AffineLegacyCloudWorkspace;
|
||||
[WorkspaceFlavour.LOCAL]: LocalWorkspace;
|
||||
[WorkspaceFlavour.PUBLIC]: AffinePublicWorkspace;
|
||||
// todo: update workspace type to new
|
||||
[WorkspaceFlavour.AFFINE_CLOUD]: AffineCloudWorkspace;
|
||||
}
|
||||
|
||||
export interface WorkspaceCRUD<Flavour extends keyof WorkspaceRegistry> {
|
||||
create: (blockSuiteWorkspace: BlockSuiteWorkspace) => Promise<string>;
|
||||
delete: (workspace: WorkspaceRegistry[Flavour]) => Promise<void>;
|
||||
get: (workspaceId: string) => Promise<WorkspaceRegistry[Flavour] | null>;
|
||||
// not supported yet
|
||||
// update: (workspace: FlavourToWorkspace[Flavour]) => Promise<void>;
|
||||
list: () => Promise<WorkspaceRegistry[Flavour][]>;
|
||||
}
|
||||
|
||||
type UIBaseProps<Flavour extends keyof WorkspaceRegistry> = {
|
||||
currentWorkspace: WorkspaceRegistry[Flavour];
|
||||
};
|
||||
|
||||
export type WorkspaceHeaderProps<Flavour extends keyof WorkspaceRegistry> =
|
||||
UIBaseProps<Flavour> & {
|
||||
currentEntry:
|
||||
| {
|
||||
subPath: WorkspaceSubPath;
|
||||
}
|
||||
| {
|
||||
pageId: string;
|
||||
};
|
||||
};
|
||||
|
||||
type SettingProps<Flavour extends keyof WorkspaceRegistry> =
|
||||
UIBaseProps<Flavour> & {
|
||||
currentTab: SettingPanel;
|
||||
onChangeTab: (tab: SettingPanel) => void;
|
||||
onDeleteWorkspace: () => Promise<void>;
|
||||
onTransformWorkspace: <
|
||||
From extends keyof WorkspaceRegistry,
|
||||
To extends keyof WorkspaceRegistry
|
||||
>(
|
||||
from: From,
|
||||
to: To,
|
||||
workspace: WorkspaceRegistry[From]
|
||||
) => void;
|
||||
};
|
||||
|
||||
type PageDetailProps<Flavour extends keyof WorkspaceRegistry> =
|
||||
UIBaseProps<Flavour> & {
|
||||
currentPageId: string;
|
||||
onLoadEditor: (page: Page, editor: EditorContainer) => () => void;
|
||||
};
|
||||
|
||||
type PageListProps<_Flavour extends keyof WorkspaceRegistry> = {
|
||||
blockSuiteWorkspace: BlockSuiteWorkspace;
|
||||
onOpenPage: (pageId: string, newTab?: boolean) => void;
|
||||
view: View;
|
||||
};
|
||||
|
||||
export interface WorkspaceUISchema<Flavour extends keyof WorkspaceRegistry> {
|
||||
Header: FC<WorkspaceHeaderProps<Flavour>>;
|
||||
PageDetail: FC<PageDetailProps<Flavour>>;
|
||||
PageList: FC<PageListProps<Flavour>>;
|
||||
SettingsDetail: FC<SettingProps<Flavour>>;
|
||||
Provider: FC<PropsWithChildren>;
|
||||
}
|
||||
|
||||
export interface AppEvents {
|
||||
// event there is no workspace
|
||||
// usually used to initialize workspace plugin
|
||||
'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>;
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export interface User {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
avatar_url: string;
|
||||
create_at: string;
|
||||
}
|
||||
|
||||
export interface GetUserByEmailParams {
|
||||
email: string;
|
||||
workspace_id: string;
|
||||
}
|
||||
|
||||
export const usageResponseSchema = z.object({
|
||||
blob_usage: z.object({
|
||||
usage: z.number(),
|
||||
max_usage: z.number(),
|
||||
}),
|
||||
});
|
||||
|
||||
export type UsageResponse = z.infer<typeof usageResponseSchema>;
|
||||
|
||||
export interface GetWorkspaceDetailParams {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export enum WorkspaceType {
|
||||
Private = 0,
|
||||
Normal = 1,
|
||||
}
|
||||
|
||||
export enum PermissionType {
|
||||
Read = 0,
|
||||
Write = 1,
|
||||
Admin = 10,
|
||||
Owner = 99,
|
||||
}
|
||||
|
||||
export const userSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
email: z.string(),
|
||||
avatar_url: z.string(),
|
||||
created_at: z.number(),
|
||||
});
|
||||
|
||||
export const workspaceSchema = z.object({
|
||||
id: z.string(),
|
||||
type: z.nativeEnum(WorkspaceType),
|
||||
public: z.boolean(),
|
||||
permission: z.nativeEnum(PermissionType),
|
||||
});
|
||||
|
||||
export type Workspace = z.infer<typeof workspaceSchema>;
|
||||
|
||||
export const workspaceDetailSchema = z.object({
|
||||
...workspaceSchema.shape,
|
||||
permission: z.undefined(),
|
||||
owner: userSchema,
|
||||
member_count: z.number(),
|
||||
});
|
||||
|
||||
export type WorkspaceDetail = z.infer<typeof workspaceDetailSchema>;
|
||||
|
||||
export interface Permission {
|
||||
id: string;
|
||||
type: PermissionType;
|
||||
workspace_id: string;
|
||||
user_id: string;
|
||||
user_email: string;
|
||||
accepted: boolean;
|
||||
create_at: number;
|
||||
}
|
||||
|
||||
export interface RegisteredUser extends User {
|
||||
type: 'Registered';
|
||||
}
|
||||
|
||||
export interface UnregisteredUser {
|
||||
type: 'Unregistered';
|
||||
email: string;
|
||||
}
|
||||
|
||||
export interface Member extends Permission {
|
||||
user: RegisteredUser | UnregisteredUser;
|
||||
}
|
||||
|
||||
export interface GetWorkspaceMembersParams {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface CreateWorkspaceParams {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface UpdateWorkspaceParams {
|
||||
id: string;
|
||||
public: boolean;
|
||||
}
|
||||
|
||||
export interface DeleteWorkspaceParams {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface InviteMemberParams {
|
||||
id: string;
|
||||
email: string;
|
||||
}
|
||||
|
||||
export interface RemoveMemberParams {
|
||||
permissionId: number;
|
||||
}
|
||||
|
||||
export interface AcceptInvitingParams {
|
||||
invitingCode: string;
|
||||
}
|
||||
|
||||
export interface LeaveWorkspaceParams {
|
||||
id: number | string;
|
||||
}
|
||||
|
||||
export const createWorkspaceResponseSchema = z.object({
|
||||
id: z.string(),
|
||||
public: z.boolean(),
|
||||
type: z.nativeEnum(WorkspaceType),
|
||||
created_at: z.number(),
|
||||
});
|
||||
Reference in New Issue
Block a user