feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import React, {
|
||||
useMemo,
|
||||
forwardRef,
|
||||
type ForwardRefRenderFunction,
|
||||
} from 'react';
|
||||
|
||||
import { type interfaces } from 'inversify';
|
||||
import {
|
||||
IDEProvider,
|
||||
IDERenderer,
|
||||
type IDEProviderProps,
|
||||
type IDEProviderRef,
|
||||
} from '@coze-project-ide/core';
|
||||
|
||||
import { type IDEClientOptions, IDEClientContext } from '../types';
|
||||
import { createDefaultPreset } from '../create-default-preset';
|
||||
|
||||
export interface IDEClientProps {
|
||||
options: (ctx: IDEClientContext) => IDEClientOptions;
|
||||
container?: interfaces.Container;
|
||||
containerModules?: interfaces.ContainerModule[]; // 注入的 IOC 包
|
||||
children?: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const IDEClientWithRef: ForwardRefRenderFunction<
|
||||
IDEProviderRef,
|
||||
IDEClientProps
|
||||
> = ({ options, container, containerModules, children, className }, ref) => {
|
||||
const props = useMemo<IDEProviderProps>(
|
||||
() => ({
|
||||
containerModules,
|
||||
container,
|
||||
plugins: createDefaultPreset<IDEClientContext>(options),
|
||||
customPluginContext: c => IDEClientContext.create(c),
|
||||
}),
|
||||
[],
|
||||
);
|
||||
return (
|
||||
<IDEProvider {...props} ref={ref}>
|
||||
<>
|
||||
<IDERenderer className={className} />
|
||||
{children}
|
||||
</>
|
||||
</IDEProvider>
|
||||
);
|
||||
};
|
||||
|
||||
export const IDEClient = forwardRef(IDEClientWithRef);
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { IDEClient, type IDEClientProps } from './ide-client';
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-empty-function */
|
||||
import { inject, injectable } from 'inversify';
|
||||
import {
|
||||
OpenerService,
|
||||
NavigationService,
|
||||
type CommandContribution,
|
||||
type CommandRegistry,
|
||||
type LifecycleContribution,
|
||||
} from '@coze-project-ide/core';
|
||||
|
||||
@injectable()
|
||||
export class ClientDefaultContribution
|
||||
implements CommandContribution, LifecycleContribution
|
||||
{
|
||||
@inject(NavigationService)
|
||||
protected readonly navigationService: NavigationService;
|
||||
|
||||
@inject(OpenerService)
|
||||
protected readonly openerService: OpenerService;
|
||||
|
||||
/**
|
||||
* IDE 初始化阶段
|
||||
*/
|
||||
onInit() {}
|
||||
|
||||
/**
|
||||
* 注册 commands
|
||||
* @param registry
|
||||
*/
|
||||
registerCommands(registry: CommandRegistry) {}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { bindContributions } from '@flowgram-adapter/common';
|
||||
import { createHistoryPlugin } from '@flowgram-adapter/common';
|
||||
import {
|
||||
createViewPlugin,
|
||||
createContextMenuPlugin,
|
||||
} from '@coze-project-ide/view';
|
||||
import {
|
||||
OpenHandler,
|
||||
createEventPlugin,
|
||||
createPreferencesPlugin,
|
||||
CommandContribution,
|
||||
createCommandPlugin,
|
||||
createResourcePlugin,
|
||||
createStylesPlugin,
|
||||
type PluginsProvider,
|
||||
type Plugin,
|
||||
createShortcutsPlugin,
|
||||
createLifecyclePlugin,
|
||||
LifecycleContribution,
|
||||
createNavigationPlugin,
|
||||
createLabelPlugin,
|
||||
} from '@coze-project-ide/core';
|
||||
|
||||
import { type IDEClientOptions, type IDEClientContext } from './types';
|
||||
import { ClientDefaultContribution } from './contributions/client-default-contribution';
|
||||
|
||||
export function createDefaultPreset<CTX extends IDEClientContext>(
|
||||
optionsProvider: (ctx: CTX) => IDEClientOptions,
|
||||
): PluginsProvider<CTX> {
|
||||
return (ctx: CTX) => {
|
||||
const opts = optionsProvider(ctx);
|
||||
const plugins: Plugin[] = [];
|
||||
/**
|
||||
* 注册内置插件
|
||||
*/
|
||||
plugins.push(
|
||||
createResourcePlugin(opts.resource || {}), // 资源系统
|
||||
createViewPlugin(
|
||||
opts.view || {
|
||||
widgetFactories: [],
|
||||
defaultLayoutData: {
|
||||
activityBarItems: [],
|
||||
defaultWidgets: [],
|
||||
},
|
||||
},
|
||||
), // 布局系统
|
||||
// Breaking change:bw 额外从业务侧引入
|
||||
createNavigationPlugin(opts.navigation || {}),
|
||||
createCommandPlugin(opts.command || {}), // 指令注册
|
||||
createHistoryPlugin(opts.history || {}), // 历史注册
|
||||
createLifecyclePlugin(opts), // IDE 生命周期注册
|
||||
createLabelPlugin(opts.label || {}), // 标签注册
|
||||
createShortcutsPlugin(opts.shortcut || {}), // 快捷键
|
||||
createPreferencesPlugin(opts.preferences || {}), // 偏好设置
|
||||
createStylesPlugin({}),
|
||||
createContextMenuPlugin(), // 右键菜单注册
|
||||
createEventPlugin(), // 全局事件注册
|
||||
);
|
||||
/**
|
||||
* client 扩展
|
||||
*/
|
||||
plugins.push(
|
||||
createLifecyclePlugin({
|
||||
onBind({ bind }) {
|
||||
bindContributions(bind, ClientDefaultContribution, [
|
||||
CommandContribution,
|
||||
LifecycleContribution,
|
||||
]);
|
||||
if (opts.openHandlers) {
|
||||
opts.openHandlers.forEach(handler => {
|
||||
if (typeof handler === 'function') {
|
||||
bind(handler).toSelf().inSingletonScope();
|
||||
bind(OpenHandler).toService(handler);
|
||||
} else {
|
||||
bind(OpenHandler).toConstantValue(handler);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
}),
|
||||
);
|
||||
/**
|
||||
* 注册业务扩展的插件
|
||||
*/
|
||||
if (opts.plugins) {
|
||||
plugins.push(...opts.plugins);
|
||||
}
|
||||
return plugins;
|
||||
};
|
||||
}
|
||||
69
frontend/packages/project-ide/client/src/index.ts
Normal file
69
frontend/packages/project-ide/client/src/index.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export * from '@coze-project-ide/core';
|
||||
|
||||
export {
|
||||
type CustomTitleType,
|
||||
type ViewOptionRegisterService,
|
||||
type CustomPreferenceConfig,
|
||||
type CustomTitleChanged,
|
||||
LayoutPanelType,
|
||||
ToolbarAlign,
|
||||
ReactWidget,
|
||||
ViewManager,
|
||||
WidgetFactory,
|
||||
WidgetManager,
|
||||
CurrentResourceContext,
|
||||
ReactWidgetContext,
|
||||
ViewContribution,
|
||||
useCurrentWidget,
|
||||
useCurrentWidgetFromArea,
|
||||
useCurrentResource,
|
||||
Widget,
|
||||
StatefulWidget,
|
||||
ApplicationShell,
|
||||
LayoutRestorer,
|
||||
CustomPreferenceContribution,
|
||||
ViewService,
|
||||
FlowDockPanel,
|
||||
HoverService,
|
||||
MenuService,
|
||||
DebugService,
|
||||
DEBUG_BAR_DRAGGABLE,
|
||||
SplitWidget,
|
||||
BoxLayout,
|
||||
DockLayout,
|
||||
BoxPanel,
|
||||
SplitLayout,
|
||||
SplitPanel,
|
||||
createBoxLayout,
|
||||
createSplitLayout,
|
||||
PerfectScrollbar,
|
||||
DISABLE_HANDLE_EVENT,
|
||||
TabBarToolbar,
|
||||
ACTIVITY_BAR_CONTENT,
|
||||
ViewRenderer,
|
||||
DragService,
|
||||
CustomTabBar,
|
||||
TabBar,
|
||||
type DragPropsType,
|
||||
type PresetConfigType,
|
||||
type ToolbarItem,
|
||||
} from '@coze-project-ide/view';
|
||||
export { createDefaultPreset } from './create-default-preset';
|
||||
export { type IDEClientOptions, IDEClientContext } from './types';
|
||||
export * from './components';
|
||||
17
frontend/packages/project-ide/client/src/types/index.ts
Normal file
17
frontend/packages/project-ide/client/src/types/index.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { type IDEClientOptions, IDEClientContext } from './options';
|
||||
86
frontend/packages/project-ide/client/src/types/options.ts
Normal file
86
frontend/packages/project-ide/client/src/types/options.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-namespace */
|
||||
import { type interfaces } from 'inversify';
|
||||
import { type AsClass } from '@flowgram-adapter/common';
|
||||
import {
|
||||
type HistoryPluginOptions,
|
||||
HistoryService,
|
||||
} from '@flowgram-adapter/common';
|
||||
import { type ViewPluginOptions } from '@coze-project-ide/view';
|
||||
import {
|
||||
type OpenHandler,
|
||||
type NavigationPluginOptions,
|
||||
type CommandPluginOptions,
|
||||
CommandService,
|
||||
type ShortcutsPluginOptions,
|
||||
ResourceService,
|
||||
type ResourcePluginOptions,
|
||||
type LabelPluginOptions,
|
||||
type PreferencesPluginOptions,
|
||||
type URI,
|
||||
type PluginContext,
|
||||
type Plugin,
|
||||
type LifecycleContribution,
|
||||
} from '@coze-project-ide/core';
|
||||
|
||||
export interface IDEClientContext extends PluginContext {
|
||||
resourceService: ResourceService;
|
||||
historyService: HistoryService;
|
||||
commandService: CommandService;
|
||||
}
|
||||
|
||||
export namespace IDEClientContext {
|
||||
export function create(container: interfaces.Container): IDEClientContext {
|
||||
return {
|
||||
container,
|
||||
get resourceService() {
|
||||
return container.get<ResourceService>(ResourceService)!;
|
||||
},
|
||||
get historyService() {
|
||||
return container.get<HistoryService>(HistoryService)!;
|
||||
},
|
||||
get commandService() {
|
||||
return container.get<CommandService>(CommandService)!;
|
||||
},
|
||||
get<T>(identifier: interfaces.ServiceIdentifier<T>): T {
|
||||
return container.get<T>(identifier);
|
||||
},
|
||||
getAll<T>(identifier: interfaces.ServiceIdentifier<T>): T[] {
|
||||
return container.getAll<T>(identifier);
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export interface HandlerItem {
|
||||
canHandle: (uri: URI) => number;
|
||||
open: (uri: URI) => Promise<void>;
|
||||
}
|
||||
|
||||
export interface IDEClientOptions extends LifecycleContribution {
|
||||
openHandlers?: (AsClass<OpenHandler> | OpenHandler)[];
|
||||
resource?: ResourcePluginOptions;
|
||||
view?: ViewPluginOptions;
|
||||
navigation?: NavigationPluginOptions;
|
||||
command?: CommandPluginOptions;
|
||||
history?: HistoryPluginOptions;
|
||||
label?: LabelPluginOptions;
|
||||
shortcut?: ShortcutsPluginOptions;
|
||||
preferences?: PreferencesPluginOptions;
|
||||
plugins?: Plugin[];
|
||||
}
|
||||
Reference in New Issue
Block a user