chore: replace all cn comments of fe to en version by volc api (#320)
This commit is contained in:
@@ -50,7 +50,7 @@ export class Application {
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始应用
|
||||
* Start application
|
||||
*/
|
||||
async start(): Promise<void> {
|
||||
const contribs = this.contributionProvider.getContributions();
|
||||
@@ -69,7 +69,7 @@ export class Application {
|
||||
}
|
||||
|
||||
/**
|
||||
* 结束应用
|
||||
* end application
|
||||
*/
|
||||
|
||||
async dispose(): Promise<void> {
|
||||
|
||||
@@ -27,13 +27,13 @@ export const ContextMatcher = Symbol('ContextMatcher');
|
||||
|
||||
export interface ContextMatcher {
|
||||
/**
|
||||
* 判断 expression 是否命中上下文
|
||||
* Determines whether the expression hits the context
|
||||
*/
|
||||
match: (expression: string) => boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 全局 context key 上下文管理
|
||||
* Global context key context management
|
||||
*/
|
||||
@injectable()
|
||||
export class ContextKeyService implements ContextMatcher {
|
||||
|
||||
@@ -19,31 +19,31 @@ import { type MaybePromise } from '@flowgram-adapter/common';
|
||||
|
||||
export const LifecycleContribution = Symbol('LifecycleContribution');
|
||||
/**
|
||||
* IDE 全局生命周期注册
|
||||
* IDE Global Lifecycle Registration
|
||||
*/
|
||||
export interface LifecycleContribution {
|
||||
/**
|
||||
* IDE 注册阶段
|
||||
* IDE registration phase
|
||||
*/
|
||||
onInit?(): void;
|
||||
/**
|
||||
* IDE loading 阶段, 一般用于加载全局配置,如 i18n 数据
|
||||
* IDE loading phase, generally used to load global configuration, such as i18n data
|
||||
*/
|
||||
onLoading?(): MaybePromise<void>;
|
||||
/**
|
||||
* IDE 布局初始化阶段,在 onLoading 之后执行
|
||||
* IDE layout initialization phase, executed after onLoading
|
||||
*/
|
||||
onLayoutInit?(): MaybePromise<void>;
|
||||
/**
|
||||
* IDE 开始执行, 可以加载业务逻辑
|
||||
* The IDE starts to execute and the business logic can be loaded
|
||||
*/
|
||||
onStart?(): MaybePromise<void>;
|
||||
/**
|
||||
* 在浏览器 `beforeunload` 之前执行,如果返回true,则会阻止
|
||||
* Execute before the browser'beforeunload ', if it returns true, it will be blocked
|
||||
*/
|
||||
onWillDispose?(): boolean | void;
|
||||
/**
|
||||
* IDE 销毁
|
||||
* IDE destruction
|
||||
*/
|
||||
onDispose?(): void;
|
||||
}
|
||||
|
||||
@@ -37,14 +37,14 @@ export interface OpenHandler {
|
||||
export const OpenerService = Symbol('OpenerService');
|
||||
export interface OpenerService {
|
||||
/**
|
||||
* 跳转定位
|
||||
* Jump Positioning
|
||||
* @param uri
|
||||
* @param options
|
||||
*/
|
||||
open: (uri: URI, options?: OpenerOptions) => Promise<object | undefined>;
|
||||
|
||||
/**
|
||||
* 某个请求触发
|
||||
* A request is triggered
|
||||
*/
|
||||
onURIOpen: Event<{ uri: URI; options?: OpenerOptions }>;
|
||||
}
|
||||
|
||||
@@ -21,17 +21,17 @@ import { LifecycleContribution } from './lifecycle-contribution';
|
||||
|
||||
export interface PluginContext {
|
||||
/**
|
||||
* 获取 IOC 容器
|
||||
* Get IOC container
|
||||
*/
|
||||
container: interfaces.Container;
|
||||
/**
|
||||
* 获取 IOC 容器的 单例模块
|
||||
* Get the singleton module for the IOC container
|
||||
* @param identifier
|
||||
*/
|
||||
get: <T>(identifier: interfaces.ServiceIdentifier<T>) => T;
|
||||
|
||||
/**
|
||||
* 获取 IOC 容器的 多例模块
|
||||
* Get the multi-instance module of the IOC container
|
||||
*/
|
||||
getAll: <T>(identifier: interfaces.ServiceIdentifier<T>) => T[];
|
||||
}
|
||||
@@ -47,27 +47,27 @@ export interface PluginBindConfig {
|
||||
|
||||
interface PluginLifeCycle<CTX extends PluginContext, OPTS> {
|
||||
/**
|
||||
* IDE 注册阶段
|
||||
* IDE registration phase
|
||||
*/
|
||||
onInit?: (ctx: CTX, opts: OPTS) => void;
|
||||
/**
|
||||
* IDE loading 阶段, 一般用于加载全局配置,如 i18n 数据
|
||||
* IDE loading phase, generally used to load global configuration, such as i18n data
|
||||
*/
|
||||
onLoading?: (ctx: CTX, opts: OPTS) => MaybePromise<void>;
|
||||
/**
|
||||
* IDE 布局初始化阶段,在 onLoading 之后执行
|
||||
* IDE layout initialization phase, executed after onLoading
|
||||
*/
|
||||
onLayoutInit?: (ctx: CTX, opts: OPTS) => MaybePromise<void>;
|
||||
/**
|
||||
* IDE 开始执行, 可以加载业务逻辑
|
||||
* The IDE starts to execute and the business logic can be loaded
|
||||
*/
|
||||
onStart?: (ctx: CTX, opts: OPTS) => MaybePromise<void>;
|
||||
/**
|
||||
* 在浏览器 `beforeunload` 之前执行,如果返回true,则会阻止
|
||||
* Execute before the browser'beforeunload ', if it returns true, it will be blocked
|
||||
*/
|
||||
onWillDispose?: (ctx: CTX, opts: OPTS) => boolean | void;
|
||||
/**
|
||||
* IDE 销毁
|
||||
* IDE destruction
|
||||
*/
|
||||
onDispose?: (ctx: CTX, opts: OPTS) => void;
|
||||
}
|
||||
@@ -75,12 +75,12 @@ interface PluginLifeCycle<CTX extends PluginContext, OPTS> {
|
||||
export interface PluginConfig<OPTS, CTX extends PluginContext = PluginContext>
|
||||
extends PluginLifeCycle<CTX, OPTS> {
|
||||
/**
|
||||
* 插件 IOC 注册, 等价于 containerModule
|
||||
* Plugin IOC registration, equivalent to containerModule
|
||||
* @param ctx
|
||||
*/
|
||||
onBind?: (bindConfig: PluginBindConfig, opts: OPTS) => void;
|
||||
/**
|
||||
* IOC 模块,用于更底层的插件扩展
|
||||
* IOC module for lower-level plug-in extensions
|
||||
*/
|
||||
containerModules?: interfaces.ContainerModule[];
|
||||
}
|
||||
@@ -114,7 +114,7 @@ export function loadPlugins(
|
||||
}
|
||||
if (plugin.containerModules && plugin.containerModules.length > 0) {
|
||||
for (const module of plugin.containerModules) {
|
||||
// 去重
|
||||
// deduplicate
|
||||
if (!res.includes(module)) {
|
||||
res.push(module);
|
||||
}
|
||||
@@ -177,7 +177,7 @@ export function definePluginCreator<
|
||||
return {
|
||||
pluginId,
|
||||
initPlugin: () => {
|
||||
// 防止 plugin 被上层业务多次 init
|
||||
// Prevent the plugin from being inited multiple times by the upper business
|
||||
if (isInit) {
|
||||
return;
|
||||
}
|
||||
@@ -224,17 +224,17 @@ export function definePluginCreator<
|
||||
/**
|
||||
* @example
|
||||
* createLifecyclePlugin({
|
||||
* // IOC 注册
|
||||
* //IOC Registrationgistration
|
||||
* onBind(bind) {
|
||||
* bind('xxx').toSelf().inSingletonScope()
|
||||
* },
|
||||
* // IDE 初始化
|
||||
* //IDE initializationtialization
|
||||
* onInit() {
|
||||
* },
|
||||
* // IDE 销毁
|
||||
* //IDE destructionstruction
|
||||
* onDispose() {
|
||||
* },
|
||||
* // IOC 模块
|
||||
* //IOC moduledule
|
||||
* containerModules: [new ContainerModule(() => {})]
|
||||
* })
|
||||
*/
|
||||
|
||||
@@ -19,7 +19,7 @@ import { injectable, postConstruct } from 'inversify';
|
||||
export const StorageService = Symbol('StorageService');
|
||||
|
||||
/**
|
||||
* 存储数据到缓存
|
||||
* Store data to cache
|
||||
*/
|
||||
export interface StorageService {
|
||||
/**
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
import { URI as Uri } from 'vscode-uri';
|
||||
|
||||
import { prioritizeAllSync, prioritizeAll } from './prioritizeable';
|
||||
@@ -241,23 +241,23 @@ export class URI {
|
||||
match(uri: URI) {
|
||||
const path = `/${uri.authority}${uri.path.toString()}`;
|
||||
const params: any[] = [];
|
||||
const pattern = `/${this.authority}${this.path.toString()}`; // 以 / 开头
|
||||
const pattern = `/${this.authority}${this.path.toString()}`; // Start with/
|
||||
let regexpSource = pattern
|
||||
.replace(/\/*\*?$/, '') // 去掉末尾的 / 和 /*
|
||||
.replace(/[\\.*+^${}|()[\]]/g, '\\$&') // 转译一些特殊字符
|
||||
.replace(/\/*\*?$/, '') // remove the/and/* at the endnd/* at the end
|
||||
.replace(/[\\. *+ ^ ${} | () [\]]/g, '\\ $&') //Translate some special characterse some special characters
|
||||
.replace(/\/:([\w-]+)(\?)?/g, (_, paramName, optional) => {
|
||||
// 收集 url 上的参数 /:param/, /:param?/
|
||||
//Collect the parameters on the url/: param/,/: param?/RL/: param/,/: param?/
|
||||
params.push({
|
||||
paramName,
|
||||
// eslint-disable-next-line eqeqeq
|
||||
optional: optional != null,
|
||||
});
|
||||
// 是否是可选参数
|
||||
// Is it an optional parameter?n optional parameter?
|
||||
return optional ? '/?([^\\/]+)?' : '/([^\\/]+)';
|
||||
});
|
||||
if (pattern.endsWith('*')) {
|
||||
params.push({ paramName: '*' });
|
||||
// 也许路径只有 *
|
||||
//Maybe the path is only *e path is only *
|
||||
regexpSource += pattern === '/*' ? '(.*)$' : '(?:\\/(.+)|\\/*)$';
|
||||
} else {
|
||||
regexpSource += '\\/*$';
|
||||
@@ -273,16 +273,16 @@ export interface URIHandler {
|
||||
|
||||
export namespace URIHandler {
|
||||
/**
|
||||
* 上层注册的优先级最高
|
||||
* Upper level registration has the highest priority
|
||||
*/
|
||||
export const MAX_PRIORITY = 500;
|
||||
/**
|
||||
* 默认兜底
|
||||
* Default bottom line
|
||||
*/
|
||||
export const DEFAULT_PRIORITY = 0;
|
||||
|
||||
/**
|
||||
* 优先级排序
|
||||
* prioritization
|
||||
* @param uri
|
||||
* @param handlers
|
||||
*/
|
||||
@@ -292,7 +292,7 @@ export namespace URIHandler {
|
||||
): Promise<T> {
|
||||
const prioritized = await prioritizeAll<T>(handlers, async handler => {
|
||||
const priority = handler.canHandle(uri);
|
||||
// boolean 情况默认采用 500
|
||||
// In the boolean case, 500 is used by default.
|
||||
if (typeof priority === 'boolean') {
|
||||
return priority ? MAX_PRIORITY : DEFAULT_PRIORITY;
|
||||
}
|
||||
@@ -303,7 +303,7 @@ export namespace URIHandler {
|
||||
export function findSync<T extends URIHandler>(uri: URI, handlers: T[]): T {
|
||||
const prioritized = prioritizeAllSync<T>(handlers, handler => {
|
||||
const priority = handler.canHandle(uri);
|
||||
// boolean 情况默认采用 500
|
||||
// In the boolean case, 500 is used by default.
|
||||
if (typeof priority === 'boolean') {
|
||||
return priority ? MAX_PRIORITY : DEFAULT_PRIORITY;
|
||||
}
|
||||
|
||||
@@ -36,10 +36,10 @@ export interface EventRegsiter {
|
||||
|
||||
export interface EventService {
|
||||
/**
|
||||
* 监听全局的事件
|
||||
* @param name 触发的事件名
|
||||
* @param handle 触发事件后执行
|
||||
* @param priority 优先级
|
||||
* Monitor global events
|
||||
* @Param name The name of the event fired
|
||||
* @Param handles execution after triggering event
|
||||
* @param priority priority
|
||||
*/
|
||||
listenGlobalEvent: (
|
||||
name: EventName,
|
||||
@@ -52,7 +52,7 @@ export const EventContribution = Symbol('EventContribution');
|
||||
|
||||
export interface EventContribution {
|
||||
/**
|
||||
* 注册 event
|
||||
* Register for events
|
||||
*/
|
||||
registerEvent: (service: EventService) => void;
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ export class EventRegistry implements EventService, LifecycleContribution {
|
||||
}
|
||||
|
||||
/**
|
||||
* 全局监听事件
|
||||
* global listening event
|
||||
*/
|
||||
listenGlobalEvent(
|
||||
name: EventName,
|
||||
@@ -93,9 +93,9 @@ export class EventRegistry implements EventService, LifecycleContribution {
|
||||
const { handlers } = eventRegister;
|
||||
const item = { handle, priority };
|
||||
/**
|
||||
* handlers 排序:
|
||||
* 1. 后注册先执行 (符合冒泡规则)
|
||||
* 2. 按 priority 排序
|
||||
* Handlers sort:
|
||||
* 1. Execute first after registration (in line with bubbling rules)
|
||||
* 2. Sort by priority
|
||||
*/
|
||||
handlers.unshift(item);
|
||||
handlers.sort((a, b) => b.priority - a.priority);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/** 公共函数 */
|
||||
/** public function */
|
||||
|
||||
export {
|
||||
Emitter,
|
||||
|
||||
@@ -41,7 +41,7 @@ export interface LabelHandler {
|
||||
getIcon?: (uri: URI) => string | undefined | React.ReactNode;
|
||||
|
||||
/**
|
||||
* 自定义渲染 label
|
||||
* Custom render label
|
||||
*/
|
||||
renderer?: (uri: URI, opt?: any) => React.ReactNode;
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ interface LabelChangeEvent {
|
||||
}
|
||||
|
||||
/**
|
||||
* 提供 全局的 label 数据获取
|
||||
* Provide, global label data acquisition
|
||||
*/
|
||||
@injectable()
|
||||
export class LabelManager implements LabelService, LifecycleContribution {
|
||||
@@ -56,7 +56,7 @@ export class LabelManager implements LabelService, LifecycleContribution {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 label 的 icon
|
||||
* Get label icon
|
||||
* @param element
|
||||
*/
|
||||
getIcon(element: URI): string | React.ReactNode {
|
||||
@@ -72,7 +72,7 @@ export class LabelManager implements LabelService, LifecycleContribution {
|
||||
}
|
||||
|
||||
/**
|
||||
* label 的自定义渲染
|
||||
* Custom rendering of labels
|
||||
*/
|
||||
renderer(element: URI, opts?: any): ReactNode {
|
||||
const handler = this.findContribution(element).find(i => i.renderer);
|
||||
@@ -83,7 +83,7 @@ export class LabelManager implements LabelService, LifecycleContribution {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 label 名字
|
||||
* Get label name
|
||||
* @param element
|
||||
*/
|
||||
getName(element: URI): string {
|
||||
@@ -99,7 +99,7 @@ export class LabelManager implements LabelService, LifecycleContribution {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 label 的详细描述
|
||||
* Get a detailed description of the label
|
||||
* @param element
|
||||
*/
|
||||
getDescription(element: URI): string {
|
||||
@@ -136,7 +136,7 @@ export class LabelManager implements LabelService, LifecycleContribution {
|
||||
}
|
||||
|
||||
/**
|
||||
* label 变化后触发
|
||||
* Triggered after label change
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error
|
||||
// @ts-ignore
|
||||
|
||||
@@ -21,33 +21,33 @@ import { type LabelChangeEvent } from './label-handler';
|
||||
|
||||
export const LabelService = Symbol('LabelService');
|
||||
/**
|
||||
* 提供 全局的 label 数据获取
|
||||
* Provide, global label data acquisition
|
||||
*/
|
||||
export interface LabelService {
|
||||
/**
|
||||
* label 变化后触发
|
||||
* Triggered after label change
|
||||
*/
|
||||
get onChange(): Event<LabelChangeEvent>;
|
||||
|
||||
/**
|
||||
* 获取 label 的 icon
|
||||
* Get label icon
|
||||
* @param element
|
||||
*/
|
||||
getIcon: (element: URI) => string | React.ReactNode;
|
||||
|
||||
/**
|
||||
* 获取 label 的自定义渲染
|
||||
* Get custom rendering of label
|
||||
*/
|
||||
renderer: (element: URI, opts?: any) => React.ReactNode;
|
||||
|
||||
/**
|
||||
* 获取 label 名字
|
||||
* Get label name
|
||||
* @param element
|
||||
*/
|
||||
getName: (element: URI) => string;
|
||||
|
||||
/**
|
||||
* 获取 label 的描述
|
||||
* Get the description of the label
|
||||
* @param element
|
||||
*/
|
||||
getDescription: (element: URI) => string;
|
||||
|
||||
@@ -29,7 +29,7 @@ export interface URILabelProps {
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染 Label 的 react 组件
|
||||
* React component for rendering Label
|
||||
* @param props
|
||||
* @constructor
|
||||
*/
|
||||
|
||||
@@ -25,8 +25,8 @@ export interface HistoryState {
|
||||
uri?: string;
|
||||
|
||||
/**
|
||||
* 在栈中的索引
|
||||
* react-router 使用「idx」,使用「fIdx」防止串数据
|
||||
* Index on the stack
|
||||
* React-router uses "idx" and "fIdx" to prevent string data
|
||||
*/
|
||||
fIdx?: number;
|
||||
}
|
||||
@@ -71,8 +71,8 @@ export class BrowserHistory implements Disposable {
|
||||
|
||||
init() {
|
||||
/**
|
||||
* 初始化的时候 index 必然为 null
|
||||
* 如果不是,说明有别的框架或者在直接使用 history.pushState 或者 history.replaceState 污染
|
||||
* When initializing, the index must be null.
|
||||
* If not, it means that there is another framework or pollution directly using history.pushState or history.replaceState
|
||||
*/
|
||||
if (this.idx === null) {
|
||||
this.history.replaceState({ ...this.state, fIdx: -1, uri: '' }, '');
|
||||
@@ -95,8 +95,8 @@ export class BrowserHistory implements Disposable {
|
||||
this.history.pushState(state, '', url);
|
||||
} catch {
|
||||
/**
|
||||
* history 还是有可能因为 state 或者浏览器等原因挂掉的
|
||||
* 降级成直接跳转
|
||||
* History may still die due to state or browser reasons
|
||||
* Downgrade to direct jump
|
||||
*/
|
||||
this.window.location.assign(url);
|
||||
}
|
||||
|
||||
@@ -25,11 +25,11 @@ import {
|
||||
import { type URI } from '../common';
|
||||
import { BrowserHistory, type HistoryState } from './browser-history';
|
||||
|
||||
/** location 结构 */
|
||||
/** Location structure */
|
||||
interface Location {
|
||||
/** 唯一标识,一般来说是 uri */
|
||||
/** The unique identifier is usually a uri. */
|
||||
uri: URI;
|
||||
/** 预留字段 */
|
||||
/** reserved field */
|
||||
}
|
||||
|
||||
@injectable()
|
||||
@@ -68,7 +68,7 @@ class NavigationHistory {
|
||||
}
|
||||
|
||||
pushOrReplace(location: Location, replace = false) {
|
||||
// 如果处于回退状态,则清除之后所有的历史
|
||||
// If it is in a fallback state, all subsequent history is cleared
|
||||
if (this.stack.length > this.idx + 1) {
|
||||
this.stack = this.stack.slice(0, this.idx + 1);
|
||||
}
|
||||
@@ -99,7 +99,7 @@ class NavigationHistory {
|
||||
private go(delta: number) {
|
||||
const next = this.idx + delta;
|
||||
const nextLocation = this.stack[next];
|
||||
// 越界按照无效处理
|
||||
// Crossing the border is treated as invalid
|
||||
if (next >= this.stack.length || next < 0 || !nextLocation) {
|
||||
return;
|
||||
}
|
||||
@@ -126,12 +126,12 @@ class NavigationHistory {
|
||||
}
|
||||
|
||||
private listener = (state: HistoryState) => {
|
||||
/** 无法正确识别 state 时不做任何处理 */
|
||||
/** Do nothing when the state cannot be correctly recognized */
|
||||
if (!state || !isNumber(state.fIdx) || !state.uri) {
|
||||
return;
|
||||
}
|
||||
const { fIdx: idx } = state;
|
||||
/** 索引越界 */
|
||||
/** Index out of bounds */
|
||||
if (idx >= this.stack.length || idx < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ class PreferencesManager {
|
||||
|
||||
public init(data: any) {
|
||||
/**
|
||||
* 从远程或者本地读取用户配置
|
||||
* Read user configuration remotely or locally
|
||||
*/
|
||||
Object.assign(this.preferences, data);
|
||||
this.preferencesChange.fire();
|
||||
@@ -41,13 +41,13 @@ class PreferencesManager {
|
||||
|
||||
public setSchema(schema: PreferenceSchema) {
|
||||
const { properties } = schema;
|
||||
/** 这里先做简单校验,后面要做整个 validateSchema */
|
||||
/** Here is a simple verification first, followed by the entire validateSchema. */
|
||||
if (!properties || !isObject(properties)) {
|
||||
return;
|
||||
}
|
||||
Object.entries<SchemaDecoration>(properties).forEach(([key, value]) => {
|
||||
if (this.schema.properties[key]) {
|
||||
// 重复定义的不覆盖,先报个警告
|
||||
// Repeatedly defined do not cover, report a warning first
|
||||
console.error(
|
||||
'Preference name collision detected in the schema for property: ',
|
||||
key,
|
||||
|
||||
@@ -29,9 +29,9 @@ import { Application, IDEContainerModule } from '../application';
|
||||
import { IDEContainerContext } from './context';
|
||||
|
||||
export interface IDEProviderProps {
|
||||
containerModules?: interfaces.ContainerModule[]; // 注入的 IOC 包
|
||||
containerModules?: interfaces.ContainerModule[]; // Injected IOC packet
|
||||
container?: interfaces.Container;
|
||||
customPluginContext?: (container: interfaces.Container) => PluginContext; // 自定义插件的上下文
|
||||
customPluginContext?: (container: interfaces.Container) => PluginContext; // Customize the plugin's context
|
||||
plugins?: PluginsProvider<any>;
|
||||
children?: React.ReactElement<any, any> | null;
|
||||
}
|
||||
@@ -41,7 +41,7 @@ export interface IDEProviderRef {
|
||||
}
|
||||
|
||||
/**
|
||||
* IDE 容器
|
||||
* IDE Container
|
||||
*/
|
||||
const IDEProviderWithRef: ForwardRefRenderFunction<
|
||||
IDEProviderRef,
|
||||
@@ -55,7 +55,7 @@ const IDEProviderWithRef: ForwardRefRenderFunction<
|
||||
} = props;
|
||||
|
||||
/**
|
||||
* 创建 IOC 包
|
||||
* Create IOC package
|
||||
*/
|
||||
const container = useMemo(() => {
|
||||
const mainContainer: interfaces.Container =
|
||||
@@ -74,7 +74,7 @@ const IDEProviderWithRef: ForwardRefRenderFunction<
|
||||
}
|
||||
mainContainer.get(Application).init();
|
||||
return mainContainer;
|
||||
// @action 这里 props 数据如果更改不会触发刷新,不允许修改
|
||||
// @action Here props data will not trigger a refresh if changed, no modification is allowed
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -21,7 +21,7 @@ import { type interfaces } from 'inversify';
|
||||
import { IDEContainerContext } from './context';
|
||||
|
||||
/**
|
||||
* 获取 ide inversify container
|
||||
* Acquire ide inversified container
|
||||
*/
|
||||
export function useIDEContainer(): interfaces.Container {
|
||||
return React.useContext(IDEContainerContext);
|
||||
|
||||
@@ -19,7 +19,7 @@ import { type interfaces } from 'inversify';
|
||||
import { useIDEContainer } from './use-ide-container';
|
||||
|
||||
/**
|
||||
* 获取IDE的 IOC 模块
|
||||
* Get the IOC module of the IDE
|
||||
* @param identifier
|
||||
*/
|
||||
export function useIDEService<T>(identifier: interfaces.ServiceIdentifier): T {
|
||||
|
||||
@@ -21,7 +21,7 @@ import { type URI } from '../common';
|
||||
import { useIDEService } from './use-ide-service';
|
||||
|
||||
const useNavigation = (): {
|
||||
/** 可传入 URI 或 string,传入 string 时以 / 开头,和 react-router-dom 对齐 */
|
||||
/** You can pass in a URI or string, starting with/when passing in a string, aligned with react-router-dom */
|
||||
navigate: (uri: URI | string, replace?: boolean, options?: any) => void;
|
||||
history: NavigationHistory;
|
||||
back: () => Promise<void>;
|
||||
|
||||
@@ -34,7 +34,7 @@ export interface AutoSaveResourceOptions {
|
||||
uri: URI;
|
||||
}
|
||||
/**
|
||||
* 资源文件自动保存服务,目前只适用于文本文件
|
||||
* Resource file auto-save service, currently only available for text files
|
||||
*/
|
||||
@injectable()
|
||||
export abstract class AutoSaveResource<
|
||||
@@ -155,7 +155,7 @@ export abstract class AutoSaveResource<
|
||||
return;
|
||||
}
|
||||
await this.readContent(false);
|
||||
// TODO sync 逻辑需要刷新 widget 数据
|
||||
// TODO sync logic needs to refresh widget data
|
||||
// if (token.isCancellationRequested || this._dirty) {
|
||||
// return;
|
||||
// }
|
||||
@@ -163,7 +163,7 @@ export abstract class AutoSaveResource<
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动保存
|
||||
* auto save
|
||||
*/
|
||||
protected doAutoSave(): void {
|
||||
if (this.autoSave === 'on') {
|
||||
@@ -323,7 +323,7 @@ export abstract class AutoSaveResource<
|
||||
}
|
||||
|
||||
saveContent(content: CHANGE_SET, patch = false): void {
|
||||
// 若支持增量改动 (仅一层)
|
||||
// If incremental changes are supported (only one layer)
|
||||
let newContent = content;
|
||||
const preSaveContent =
|
||||
this.contentChanges[this.contentChanges.length - 1] ?? this.lastContent;
|
||||
@@ -344,7 +344,7 @@ export abstract class AutoSaveResource<
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取正在保存中的内容
|
||||
* Get the content being saved
|
||||
*/
|
||||
getPreSaveContent(): CHANGE_SET | undefined {
|
||||
return (
|
||||
|
||||
@@ -23,8 +23,8 @@ import {
|
||||
import { type URI, type URIHandler } from '../common';
|
||||
|
||||
export interface ResourceInfo {
|
||||
displayName?: string; // 显示标题
|
||||
lastModification?: number | string; // 最后修改时间
|
||||
displayName?: string; // Show title
|
||||
lastModification?: number | string; // Last modification time
|
||||
version?: number | string;
|
||||
}
|
||||
export interface Resource<T = any, INFO extends ResourceInfo = ResourceInfo>
|
||||
@@ -62,7 +62,7 @@ export const ResourceHandler = Symbol('ResourceHandler');
|
||||
export interface ResourceHandler<T extends Resource = Resource>
|
||||
extends URIHandler {
|
||||
/**
|
||||
* 创建资源
|
||||
* Create a resource
|
||||
* @param uri
|
||||
*/
|
||||
resolve: (uri: URI) => T;
|
||||
|
||||
@@ -18,33 +18,33 @@ import { getKeyLabel, isKeyStringMatch } from '../utils';
|
||||
|
||||
export interface Keybinding {
|
||||
/**
|
||||
* 关联 command,该 keybinding 触发后执行的 command
|
||||
* Associated command, the command executed after the keybinding is triggered
|
||||
*/
|
||||
command: string;
|
||||
/**
|
||||
* 关联的快捷键,like:meta c
|
||||
* Associated shortcuts, like: meta c
|
||||
*/
|
||||
keybinding: string;
|
||||
/**
|
||||
* 是否阻止浏览器的默认行为
|
||||
* Whether to block the browser's default behavior
|
||||
*/
|
||||
preventDefault?: boolean;
|
||||
/**
|
||||
* keybinding 触发上下文,和 contextkey service 关联
|
||||
* Keybinding triggering context, associated with the contextkey service
|
||||
*/
|
||||
when?: string;
|
||||
/**
|
||||
* 通过 keybinding 的触发 command 的参数
|
||||
* Parameters to trigger commands via keybinding
|
||||
*/
|
||||
args?: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* kiybinding 相关导出方法
|
||||
* KiyBinding related export method
|
||||
*/
|
||||
export namespace Keybinding {
|
||||
/**
|
||||
* 匹配键盘事件是否 macth 快捷键配置
|
||||
* Match keyboard event whether macth shortcut configuration
|
||||
*/
|
||||
export const isKeyEventMatch = isKeyStringMatch;
|
||||
|
||||
|
||||
@@ -34,27 +34,27 @@ import { type Keybinding, KeybindingRegistry } from './keybinding';
|
||||
export interface ShortcutsHandler
|
||||
extends Partial<Pick<CommandHandler, 'execute' | 'isEnabled'>> {
|
||||
/**
|
||||
* 注册快捷键 Id
|
||||
* Register shortcut IDs
|
||||
*/
|
||||
commandId: string;
|
||||
/**
|
||||
* 注册快捷键 label
|
||||
* Register shortcut label
|
||||
*/
|
||||
commandLabel?: string;
|
||||
/**
|
||||
* 执行上下文
|
||||
* execution context
|
||||
*/
|
||||
when?: string;
|
||||
/**
|
||||
* 涉及到的快捷键
|
||||
* The shortcuts involved
|
||||
*/
|
||||
keybinding: string[] | string;
|
||||
/**
|
||||
* 是否阻止浏览器的默认行为
|
||||
* Whether to block the browser's default behavior
|
||||
*/
|
||||
preventDefault?: boolean;
|
||||
/**
|
||||
* 快捷键来源
|
||||
* Shortcut source
|
||||
*/
|
||||
source?: string;
|
||||
}
|
||||
@@ -67,7 +67,7 @@ export interface ShortcutsContribution {
|
||||
|
||||
export interface ShortcutsRegistry {
|
||||
/**
|
||||
* 新增 shortcutHandlers
|
||||
* Add shortcutHandlers
|
||||
*/
|
||||
registerHandlers: (...handlers: ShortcutsHandler[]) => void;
|
||||
}
|
||||
@@ -108,14 +108,14 @@ export class ShortcutsService
|
||||
}
|
||||
|
||||
/**
|
||||
* IDE 初始化阶段注册 listener
|
||||
* IDE initialization phase registration listener
|
||||
*/
|
||||
onInit(): void {
|
||||
document.addEventListener('keydown', this.listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* IDE 销毁阶段移除 listener
|
||||
* IDE destruction phase to remove listeners
|
||||
*/
|
||||
onDispose(): void {
|
||||
document.removeEventListener('keydown', this.listener);
|
||||
@@ -135,7 +135,7 @@ export class ShortcutsService
|
||||
logger.log('ShortcutsRegistry - listener', ev, keybindings);
|
||||
keybindings.forEach(keybinding => {
|
||||
/**
|
||||
* 定义的全局快捷键不生效于输入组件,避免冲突
|
||||
* Defined global shortcuts do not take effect on input components to avoid conflicts
|
||||
*/
|
||||
if (domEditable(ev.target as HTMLElement) && !keybinding.when) {
|
||||
return;
|
||||
@@ -146,7 +146,7 @@ export class ShortcutsService
|
||||
};
|
||||
|
||||
registerHandlers(...handlers: ShortcutsHandler[]): void {
|
||||
// 注册 handler
|
||||
// Registration handler
|
||||
handlers.forEach(handler => {
|
||||
const keybindings = Array.isArray(handler.keybinding)
|
||||
? handler.keybinding
|
||||
@@ -273,14 +273,14 @@ export class ShortcutsService
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 source 获取 ShortcutsHandler
|
||||
* Get ShortcutsHandler from source
|
||||
*/
|
||||
public getShortcutsBySource(source: string): ShortcutsHandler[] {
|
||||
return this.shortcutsHandlers.filter(v => v.source === source);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据键盘事件获取 keybinding
|
||||
* Get keybinding based on keyboard events
|
||||
*/
|
||||
public getKeybindingMatchKeyEvent(
|
||||
keybindings: Keybinding[],
|
||||
@@ -292,7 +292,7 @@ export class ShortcutsService
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行 keybinding
|
||||
* Execute keybinding
|
||||
*/
|
||||
public executeKeybinding(keybinding: Keybinding, ev: KeyboardEvent) {
|
||||
this.commandRegistry.executeCommand(keybinding.command, keybinding.args);
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
import { isAppleDevice } from './device';
|
||||
|
||||
// 键盘事件 keyCode 别名
|
||||
// Keyboard Event keyCode Alias
|
||||
const aliasKeyCodeMap: Record<string, number | number[]> = {
|
||||
'0': 48,
|
||||
'1': 49,
|
||||
@@ -135,7 +135,7 @@ const modifierKey: any = {
|
||||
},
|
||||
};
|
||||
|
||||
// 根据 event 计算激活键数量
|
||||
// Number of activation keys based on event
|
||||
function countKeyByEvent(event: KeyboardEvent): number {
|
||||
const countOfModifier = Object.keys(modifierKey).reduce((total, key) => {
|
||||
if (modifierKey[key](event)) {
|
||||
@@ -145,7 +145,7 @@ function countKeyByEvent(event: KeyboardEvent): number {
|
||||
return total;
|
||||
}, 0);
|
||||
|
||||
// 16 17 18 91 92 是修饰键的 keyCode,如果 keyCode 是修饰键,那么激活数量就是修饰键的数量,如果不是,那么就需要 +1
|
||||
// 16 17 18 91 92 is the keyCode of the modifier key. If keyCode is a modifier key, then the number of activations is the number of modifier keys. If not, then + 1 is required.
|
||||
return [16, 17, 18, 91, 92].includes(event.keyCode)
|
||||
? countOfModifier
|
||||
: countOfModifier + 1;
|
||||
@@ -162,11 +162,11 @@ export function isKeyStringMatch(
|
||||
keyString: string,
|
||||
exactMatch = true,
|
||||
): boolean {
|
||||
// 浏览器自动补全 input 的时候,会触发 keyDown、keyUp 事件,但此时 event.key 等为空
|
||||
// When the browser automatically completes the input, keyDown and keyUp events will be triggered, but at this time event.key, etc. are empty
|
||||
if (!event.key || !keyString) {
|
||||
return false;
|
||||
}
|
||||
// 字符串依次判断是否有组合键
|
||||
// String in turn determines whether there is a key combination
|
||||
const genArr = keyString.split(/\s+/);
|
||||
let genLen = 0;
|
||||
|
||||
@@ -177,9 +177,9 @@ export function isKeyStringMatch(
|
||||
// }
|
||||
|
||||
for (const key of genArr) {
|
||||
// 组合键
|
||||
// key combination
|
||||
const genModifier = modifierKey[key];
|
||||
// keyCode 别名
|
||||
// keyCode alias
|
||||
const aliasKeyCode: number | number[] = aliasKeyCodeMap[key.toLowerCase()];
|
||||
|
||||
if (
|
||||
@@ -191,10 +191,10 @@ export function isKeyStringMatch(
|
||||
}
|
||||
|
||||
/**
|
||||
* 需要判断触发的键位和监听的键位完全一致,判断方法就是触发的键位里有且等于监听的键位
|
||||
* genLen === genArr.length 能判断出来触发的键位里有监听的键位
|
||||
* countKeyByEvent(event) === genArr.length 判断出来触发的键位数量里有且等于监听的键位数量
|
||||
* 主要用来防止按组合键其子集也会触发的情况,例如监听 ctrl+a 会触发监听 ctrl 和 a 两个键的事件。
|
||||
* It is necessary to determine that the triggered key is exactly the same as the monitored key. The judgment method is that the triggered key is equal to the monitored key.
|
||||
* genLen == genArr.length can determine that there is a listening key among the triggered keys
|
||||
* countKeyByEvent (event) === genArr.length The number of keys triggered by the judgment is equal to the number of keys listened to
|
||||
* It is mainly used to prevent the situation that pressing a subset of the key combination will also trigger, such as listening to the event that ctrl + a will trigger listening to the two keys ctrl and a.
|
||||
*/
|
||||
if (exactMatch) {
|
||||
return genLen === genArr.length && countKeyByEvent(event) === genArr.length;
|
||||
|
||||
@@ -36,13 +36,13 @@ class ColorService {
|
||||
@named(ColorContribution)
|
||||
colorContributions: ContributionProvider<ColorContribution>;
|
||||
|
||||
/** 颜色表 */
|
||||
/** Color chart */
|
||||
private colors: Record<string, ColorDefinition> = {};
|
||||
|
||||
/** 颜色的 schema */
|
||||
/** Color schema */
|
||||
private schema: ColorSchemaType = { type: 'object', properties: {} };
|
||||
|
||||
/** 颜色偏好设置的 schema */
|
||||
/** Color preference schema */
|
||||
// private referenceSchema = { type: 'string', enum: [], enumDescriptions: [] };
|
||||
|
||||
init() {
|
||||
@@ -52,7 +52,7 @@ class ColorService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量注册 color
|
||||
* Bulk registration color
|
||||
*/
|
||||
register(...colors: ColorDefinition[]): Disposable[] {
|
||||
return colors.map(definition => {
|
||||
@@ -67,7 +67,7 @@ class ColorService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 注销 color
|
||||
* Logout color
|
||||
*/
|
||||
deregisterColor(id: string): void {
|
||||
delete this.colors[id];
|
||||
@@ -75,7 +75,7 @@ class ColorService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的 color definition
|
||||
* Get all color definitions
|
||||
*/
|
||||
getColors(): ColorDefinition[] {
|
||||
return Object.keys(this.colors).map(id => this.colors[id]);
|
||||
@@ -86,12 +86,12 @@ class ColorService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定 theme 的 color value
|
||||
* Gets the color value of the specified theme
|
||||
*/
|
||||
getThemeColor(id: string, themeType: ThemeType) {
|
||||
const color = this.getColor(id);
|
||||
let value = color.defaults?.[themeType];
|
||||
// 色值可以从其他色值继承
|
||||
// Color values can be inherited from other color values
|
||||
if (
|
||||
value &&
|
||||
typeof value === 'string' &&
|
||||
@@ -105,14 +105,14 @@ class ColorService {
|
||||
}
|
||||
|
||||
toCssColor(id: string, themeType: ThemeType) {
|
||||
// 转换为变量名
|
||||
// Convert to variable name
|
||||
const variableName = `--${id.replace(/\./g, '-')}`;
|
||||
const value = this.getThemeColor(id, themeType);
|
||||
return `${variableName}: ${value};`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 所有色值转化为 css 变量
|
||||
* All color values are converted to CSS variables
|
||||
*/
|
||||
toCss(themeType: ThemeType) {
|
||||
return `body {\n${this.getColors()
|
||||
|
||||
@@ -45,14 +45,14 @@ class StylingService {
|
||||
static readonly PREFIX = 'flowide';
|
||||
|
||||
/**
|
||||
* 后面移到 map 里面,现在暂时没想好
|
||||
* Move it to the map later, I haven't thought about it for the time being.
|
||||
*/
|
||||
private cssElement: HTMLStyleElement | undefined;
|
||||
|
||||
private css = new Map<string, HTMLStyleElement>();
|
||||
|
||||
/**
|
||||
* 收集所有 css 挂载到 <head> 上
|
||||
* Collect all css mounts to < head >
|
||||
*/
|
||||
apply(theme: Theme) {
|
||||
const rules: string[] = [];
|
||||
|
||||
@@ -41,13 +41,13 @@ class ThemeService {
|
||||
@inject(PreferencesManager)
|
||||
protected readonly preferencesManager: PreferencesManager;
|
||||
|
||||
/** 所有注册的 theme */
|
||||
/** All registered themes */
|
||||
private themes: Map<string, Theme> = new Map([
|
||||
[DEFAULT_THEME.type, DEFAULT_THEME],
|
||||
[DEFAULT_LIGHT_THEME.type, DEFAULT_LIGHT_THEME],
|
||||
]);
|
||||
|
||||
/** 当前 theme */
|
||||
/** Current theme */
|
||||
private current: Theme = DEFAULT_THEME;
|
||||
|
||||
private readonly themeChange = new Emitter<ThemeDidChangeEvent>();
|
||||
@@ -57,7 +57,7 @@ class ThemeService {
|
||||
|
||||
init() {
|
||||
this.changeWithPreferences();
|
||||
// 先手动触发一次 change 模拟从 preference 读取配置
|
||||
// First manually trigger a change simulation to read the configuration from preference
|
||||
this.preferencesManager.onDidPreferencesChange(() => {
|
||||
this.changeWithPreferences();
|
||||
});
|
||||
@@ -76,7 +76,7 @@ class ThemeService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册 theme
|
||||
* Register theme
|
||||
*/
|
||||
register(...themes: Theme[]) {
|
||||
themes.forEach(theme => this.themes.set(theme.id, theme));
|
||||
|
||||
@@ -30,7 +30,7 @@ export default defineConfig({
|
||||
exclude: [
|
||||
'**/node_modules/**',
|
||||
'**/dist/**',
|
||||
'**/lib/**', // lib 编译结果忽略掉
|
||||
'**/lib/**', // The lib compilation result is ignored
|
||||
'**/cypress/**',
|
||||
'**/.{idea,git,cache,output,temp}/**',
|
||||
'**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*',
|
||||
|
||||
Reference in New Issue
Block a user