Skip to content

Commit

Permalink
refactor: change render core export api
Browse files Browse the repository at this point in the history
  • Loading branch information
1ncounter committed Jul 26, 2024
1 parent c1356bf commit 9d0f178
Show file tree
Hide file tree
Showing 30 changed files with 476 additions and 150 deletions.
Empty file.
11 changes: 11 additions & 0 deletions packages/engine-core/src/common/uri.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface UriComponents {
path: string;
}

export class URI implements UriComponents {
readonly path: string;

constructor(path: string) {
this.path = path;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ export interface IConfigurationPropertySchema extends IJSONSchema {
* 扩展信息,用来查找对应属性的源扩展
*/
export interface IExtensionInfo {
name: string;
id: string;
displayName?: string;
version?: string;
}

export type ConfigurationDefaultValueSource = IExtensionInfo | Map<string, IExtensionInfo>;
Expand Down Expand Up @@ -640,7 +642,7 @@ export class ConfigurationRegistry implements IConfigurationRegistry {

function isSameExtension(a?: IExtensionInfo, b?: IExtensionInfo): boolean {
if (!a || !b) return false;
return a.name === b.name;
return a.id === b.id && a.version === b.version;
}

Registry.add(Extensions.Configuration, new ConfigurationRegistry());
5 changes: 3 additions & 2 deletions packages/engine-core/src/extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ export type ExtensionInitializer = <Context = any>(ctx: Context) => IExtensionIn
* 函数声明插件
*/
export interface IFunctionExtension extends ExtensionInitializer {
name: string;
id: string;
displayName?: string;
version: string;
meta?: IExtensionMetadata;
metadata?: IExtensionMetadata;
}

export interface IExtensionMetadata {
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-core/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { InstantiationService } from '@alilc/lowcode-shared';
import { IWorkbenchService } from './workbench';
import { IConfigurationService } from './configuration';

export class MainApplication {
class MainApplication {
constructor() {
console.log('main application');
}
Expand Down
140 changes: 140 additions & 0 deletions packages/engine-core/src/workspace/file/file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import { URI } from '../../common/uri';

export enum FileType {
/**
* File is unknown (neither file, directory).
*/
Unknown = 0,

/**
* File is a normal file.
*/
File = 1,

/**
* File is a directory.
*/
Directory = 2,
}

export interface IStat {
/**
* The file type.
*/
readonly type: FileType;

/**
* The last modification date represented as millis from unix epoch.
*/
readonly mtime: number;

/**
* The creation date represented as millis from unix epoch.
*/
readonly ctime: number;
}

export interface IBaseFileStat {
/**
* The unified resource identifier of this file or folder.
*/
readonly resource: URI;

/**
* The name which is the last segment
* of the {{path}}.
*/
readonly name: string;

/**
* The size of the file.
*
* The value may or may not be resolved as
* it is optional.
*/
readonly size?: number;

/**
* The last modification date represented as millis from unix epoch.
*
* The value may or may not be resolved as
* it is optional.
*/
readonly mtime?: number;

/**
* The creation date represented as millis from unix epoch.
*
* The value may or may not be resolved as
* it is optional.
*/
readonly ctime?: number;

/**
* A unique identifier that represents the
* current state of the file or directory.
*
* The value may or may not be resolved as
* it is optional.
*/
readonly etag?: string;

/**
* File is readonly. Components like editors should not
* offer to edit the contents.
*/
readonly readonly?: boolean;

/**
* File is locked. Components like editors should offer
* to edit the contents and ask the user upon saving to
* remove the lock.
*/
readonly locked?: boolean;
}

/**
* A file resource with meta information and resolved children if any.
*/
export interface IFileStat extends IBaseFileStat {
/**
* The resource is a file.
*/
readonly isFile: boolean;

/**
* The resource is a directory.
*/
readonly isDirectory: boolean;

/**
* The children of the file stat or undefined if none.
*/
children: IFileStat[] | undefined;
}

export interface IFileStatWithMetadata extends Required<IFileStat> {
readonly children: IFileStatWithMetadata[];
}

export const enum FileOperation {
CREATE,
DELETE,
MOVE,
COPY,
WRITE,
}

export interface IFileOperationEvent {
readonly resource: URI;
readonly operation: FileOperation;

isOperation(operation: FileOperation.DELETE | FileOperation.WRITE): boolean;
isOperation(
operation: FileOperation.CREATE | FileOperation.MOVE | FileOperation.COPY,
): this is IFileOperationEventWithMetadata;
}

export interface IFileOperationEventWithMetadata extends IFileOperationEvent {
readonly target: IFileStatWithMetadata;
}
6 changes: 6 additions & 0 deletions packages/engine-core/src/workspace/file/fileManagement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* URI -> file content
* URI -> file Stat
*/

export interface IFileManagement {}
1 change: 1 addition & 0 deletions packages/engine-core/src/workspace/file/fileService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export interface IFileService {}
26 changes: 26 additions & 0 deletions packages/engine-core/src/workspace/folder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { URI } from '../common/uri';

export interface IWorkspaceFolderData {
/**
* The associated URI for this workspace folder.
*/
readonly uri: URI;

/**
* The name of this workspace folder. Defaults to
* the basename of its [uri-path](#Uri.path)
*/
readonly name: string;

/**
* The ordinal number of this workspace folder.
*/
readonly index: number;
}

export interface IWorkspaceFolder extends IWorkspaceFolderData {
/**
* Given workspace folder relative path, returns the resource with the absolute path.
*/
toResource: (relativePath: string) => URI;
}
82 changes: 82 additions & 0 deletions packages/engine-core/src/workspace/window/window.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { type Event } from '@alilc/lowcode-shared';
import { URI } from '../../common/uri';

export interface IEditWindow {
// readonly onWillLoad: Event<ILoadEvent>;
readonly onDidSignalReady: Event<void>;
readonly onDidDestroy: Event<void>;

readonly onDidClose: Event<void>;

readonly id: number;

readonly config: IWindowConfiguration | undefined;

readonly isReady: boolean;
ready(): Promise<IEditWindow>;

load(config: IWindowConfiguration, options?: { isReload?: boolean }): void;
reload(): void;
}

export interface IWindowConfiguration {
filesToOpenOrCreate?: IPath[];
}

export interface IPath<T = any> {
/**
* Optional editor options to apply in the file
*/
readonly options?: T;

/**
* The file path to open within the instance
*/
fileUri?: URI;

/**
* Specifies if the file should be only be opened
* if it exists.
*/
readonly openOnlyIfExists?: boolean;
}

export const enum WindowMode {
Maximized,
Normal,
Fullscreen,
Custom,
}

export interface IWindowState {
width?: number;
height?: number;
x?: number;
y?: number;
mode?: WindowMode;
zoomLevel?: number;
readonly display?: number;
}

export interface IOpenConfiguration {
readonly urisToOpen?: IWindowOpenable[];
readonly preferNewWindow?: boolean;
readonly forceNewWindow?: boolean;
readonly forceNewTabbedWindow?: boolean;
readonly forceReuseWindow?: boolean;
readonly forceEmpty?: boolean;
}

export interface IBaseWindowOpenable {
label?: string;
}

export interface IFolderToOpen extends IBaseWindowOpenable {
readonly folderUri: URI;
}

export interface IFileToOpen extends IBaseWindowOpenable {
readonly fileUri: URI;
}

export type IWindowOpenable = IFolderToOpen | IFileToOpen;
43 changes: 43 additions & 0 deletions packages/engine-core/src/workspace/window/windowService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { type Event } from '@alilc/lowcode-shared';
import { IEditWindow, IOpenConfiguration } from './window';

export interface IWindowService {
readonly onDidOpenWindow: Event<IEditWindow>;
readonly onDidSignalReadyWindow: Event<IEditWindow>;
readonly onDidChangeFullScreen: Event<{ window: IEditWindow; fullscreen: boolean }>;
readonly onDidDestroyWindow: Event<IEditWindow>;

open(openConfig: IOpenConfiguration): Promise<IEditWindow[]>;

sendToFocused(channel: string, ...args: any[]): void;
sendToOpeningWindow(channel: string, ...args: any[]): void;
sendToAll(channel: string, payload?: any, windowIdsToIgnore?: number[]): void;

getWindows(): IEditWindow[];
getWindowCount(): number;

getFocusedWindow(): IEditWindow | undefined;
getLastActiveWindow(): IEditWindow | undefined;

getWindowById(windowId: number): IEditWindow | undefined;
}

export class WindowService implements IWindowService {
private readonly windows = new Map<number, IEditWindow>();

getWindows(): IEditWindow[] {
return [...this.windows.values()];
}

getWindowCount(): number {
return this.windows.size;
}

getFocusedWindow(): IEditWindow | undefined {
return this.getWindows().find((w) => w.focused);
}

getLastActiveWindow(): IEditWindow | undefined {
return this.getWindows().find((w) => w.lastActive);
}
}
31 changes: 29 additions & 2 deletions packages/engine-core/src/workspace/workspace.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
import { IWorkspaceFolder } from './folder';

/**
* 工作空间:一个或多个项目的集合
* workspace -> one or more folders -> virtual files
* file -> editWindow
* editorView -> component tree schema
*
* project = (one or muti folders -> files) + some configs
*/
export interface Workspace {}
export interface IWorkspace {
readonly id: string;

/**
* Folders in the workspace.
*/
readonly folders: IWorkspaceFolder[];
}

export class Workspace implements IWorkspace {
private _folders: IWorkspaceFolder[] = [];

constructor(private _id: string) {}

get id() {
return this._id;
}

get folders() {
return this._folders;
}
}
Loading

0 comments on commit 9d0f178

Please sign in to comment.