From 9cec5d833c224665bd41f74b20b9014327c6abfa Mon Sep 17 00:00:00 2001 From: liujuping Date: Wed, 1 Mar 2023 18:32:10 +0800 Subject: [PATCH] feat: update the ts definition of the shell module --- .eslintrc.js | 1 + .../src/views/tree-branches.tsx | 4 ++-- packages/types/src/shell/api/canvas.ts | 8 ++++++++ packages/types/src/shell/api/material.ts | 17 +++++++++++++++++ packages/types/src/shell/api/workspace.ts | 6 ++++-- packages/types/src/shell/model/node-children.ts | 14 ++++++++++++++ packages/utils/src/schema.ts | 6 +++--- packages/workspace/src/context/base-context.ts | 2 ++ packages/workspace/src/workspace.ts | 10 +++++++--- 9 files changed, 58 insertions(+), 10 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index f3ebedbbe..4f9620d3d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -48,6 +48,7 @@ module.exports = { "afterLineComment": false, "allowBlockStart": true, }], + "no-unused-vars": ['error', { "destructuredArrayIgnorePattern": "^_" }], "@typescript-eslint/member-ordering": [ "error", { "default": ["signature", "field", "constructor", "method"] } diff --git a/packages/plugin-outline-pane/src/views/tree-branches.tsx b/packages/plugin-outline-pane/src/views/tree-branches.tsx index 9af2dbd09..eb2084508 100644 --- a/packages/plugin-outline-pane/src/views/tree-branches.tsx +++ b/packages/plugin-outline-pane/src/views/tree-branches.tsx @@ -2,7 +2,7 @@ import { Component } from 'react'; import classNames from 'classnames'; import TreeNode from '../controllers/tree-node'; import TreeNodeView from './tree-node'; -import { IPublicModelPluginContext, IPublicModelExclusiveGroup } from '@alilc/lowcode-types'; +import { IPublicModelPluginContext, IPublicModelExclusiveGroup, IPublicTypeDisposable } from '@alilc/lowcode-types'; export default class TreeBranches extends Component<{ treeNode: TreeNode; @@ -73,7 +73,7 @@ class TreeNodeChildren extends Component<{ keywords: null, dropDetail: null, }; - offLocationChanged: () => void; + offLocationChanged: IPublicTypeDisposable; componentDidMount() { const { treeNode, pluginContext } = this.props; const { project } = pluginContext; diff --git a/packages/types/src/shell/api/canvas.ts b/packages/types/src/shell/api/canvas.ts index b7ad196ce..6cb3df9fc 100644 --- a/packages/types/src/shell/api/canvas.ts +++ b/packages/types/src/shell/api/canvas.ts @@ -2,12 +2,14 @@ import { IPublicModelDragon, IPublicModelDropLocation, IPublicModelScrollTarget, import { IPublicTypeLocationData, IPublicTypeScrollable } from '../type'; /** + * canvas - 画布 API * @since v1.1.0 */ export interface IPublicApiCanvas { /** * 创一个滚动控制器 Scroller,赋予一个视图滚动的基本能力, + * * a Scroller is a controller that gives a view (IPublicTypeScrollable) the ability scrolling * to some cordination by api scrollTo. * @@ -20,6 +22,7 @@ export interface IPublicApiCanvas { /** * 创建一个 ScrollTarget,与 Scroller 一起发挥作用,详见 createScroller 中的描述 + * * this works with Scroller, refer to createScroller`s description * @since v1.1.0 */ @@ -27,6 +30,7 @@ export interface IPublicApiCanvas { /** * 创建一个文档插入位置对象,该对象用来描述一个即将插入的节点在文档中的位置 + * * create a drop location for document, drop location describes a location in document * @since v1.1.0 */ @@ -34,6 +38,7 @@ export interface IPublicApiCanvas { /** * 获取拖拽操作对象的实例 + * * get dragon instance, you can use this to obtain draging related abilities and lifecycle hooks * @since v1.1.0 */ @@ -41,6 +46,7 @@ export interface IPublicApiCanvas { /** * 获取活动追踪器实例 + * * get activeTracker instance, which is a singleton running in engine. * it tracks document`s current focusing node/node[], and notify it`s subscribers that when * focusing node/node[] changed. @@ -50,6 +56,7 @@ export interface IPublicApiCanvas { /** * 是否处于 LiveEditing 状态 + * * check if canvas is in liveEditing state * @since v1.1.0 */ @@ -57,6 +64,7 @@ export interface IPublicApiCanvas { /** * 获取全局剪贴板实例 + * * get clipboard instance * * @since v1.1.0 diff --git a/packages/types/src/shell/api/material.ts b/packages/types/src/shell/api/material.ts index 19e42e4a8..7771aa6ba 100644 --- a/packages/types/src/shell/api/material.ts +++ b/packages/types/src/shell/api/material.ts @@ -76,8 +76,25 @@ export interface IPublicApiMaterial { /** * 在设计器辅助层增加一个扩展 action + * * add an action button in canvas context menu area * @param action + * @example + * ```ts + * import { plugins } from '@alilc/lowcode-engine'; + * import { IPublicModelPluginContext } from '@alilc/lowcode-types'; + * + * const removeCopyAction = (ctx: IPublicModelPluginContext) => { + * return { + * async init() { + * const { removeBuiltinComponentAction } = ctx.material; + * removeBuiltinComponentAction('copy'); + * } + * } + * }; + * removeCopyAction.pluginName = 'removeCopyAction'; + * await plugins.register(removeCopyAction); + * ``` */ addBuiltinComponentAction(action: IPublicTypeComponentAction): void; diff --git a/packages/types/src/shell/api/workspace.ts b/packages/types/src/shell/api/workspace.ts index 8f8b16e39..c1be4cb7e 100644 --- a/packages/types/src/shell/api/workspace.ts +++ b/packages/types/src/shell/api/workspace.ts @@ -1,7 +1,9 @@ import { IPublicModelWindow } from '../model'; import { IPublicApiPlugins, IPublicModelResource, IPublicResourceList, IPublicTypeDisposable, IPublicTypeResourceType } from '@alilc/lowcode-types'; -export interface IPublicApiWorkspace { +export interface IPublicApiWorkspace< + Plugins = IPublicApiPlugins +> { /** 是否启用 workspace 模式 */ isActive: boolean; @@ -9,7 +11,7 @@ export interface IPublicApiWorkspace { /** 当前设计器窗口 */ window: IPublicModelWindow; - plugins: IPublicApiPlugins; + plugins: Plugins; /** 当前设计器的编辑窗口 */ windows: IPublicModelWindow[]; diff --git a/packages/types/src/shell/model/node-children.ts b/packages/types/src/shell/model/node-children.ts index ecab5fd33..f2be13250 100644 --- a/packages/types/src/shell/model/node-children.ts +++ b/packages/types/src/shell/model/node-children.ts @@ -27,6 +27,7 @@ export interface IPublicModelNodeChildren< /** * 是否为空 + * * @returns */ get isEmptyNode(): boolean; @@ -44,6 +45,7 @@ export interface IPublicModelNodeChildren< /** * 删除指定节点 + * * delete the node * @param node */ @@ -51,6 +53,7 @@ export interface IPublicModelNodeChildren< /** * 插入一个节点 + * * insert a node at specific position * @param node 待插入节点 * @param at 插入下标 @@ -60,6 +63,7 @@ export interface IPublicModelNodeChildren< /** * 返回指定节点的下标 + * * get index of node in current children * @param node * @returns @@ -68,6 +72,7 @@ export interface IPublicModelNodeChildren< /** * 类似数组 splice 操作 + * * provide the same function with {Array.prototype.splice} * @param start * @param deleteCount @@ -77,6 +82,7 @@ export interface IPublicModelNodeChildren< /** * 返回指定下标的节点 + * * get node with index * @param index * @returns @@ -85,6 +91,7 @@ export interface IPublicModelNodeChildren< /** * 是否包含指定节点 + * * check if node exists in current children * @param node * @returns @@ -93,6 +100,7 @@ export interface IPublicModelNodeChildren< /** * 类似数组的 forEach + * * provide the same function with {Array.prototype.forEach} * @param fn */ @@ -100,12 +108,14 @@ export interface IPublicModelNodeChildren< /** * 类似数组的 reverse + * * provide the same function with {Array.prototype.reverse} */ reverse(): Node[]; /** * 类似数组的 map + * * provide the same function with {Array.prototype.map} * @param fn */ @@ -141,6 +151,7 @@ export interface IPublicModelNodeChildren< /** * 类似数组的 reduce + * * provide the same function with {Array.prototype.reduce} * @param fn */ @@ -148,6 +159,7 @@ export interface IPublicModelNodeChildren< /** * 导入 schema + * * import schema * @param data */ @@ -155,6 +167,7 @@ export interface IPublicModelNodeChildren< /** * 导出 schema + * * export schema * @param stage */ @@ -162,6 +175,7 @@ export interface IPublicModelNodeChildren< /** * 执行新增、删除、排序等操作 + * * excute remove/add/sort operations * @param remover * @param adder diff --git a/packages/utils/src/schema.ts b/packages/utils/src/schema.ts index 58dfb3045..2e7dec70f 100644 --- a/packages/utils/src/schema.ts +++ b/packages/utils/src/schema.ts @@ -79,7 +79,7 @@ export function compatibleLegaoSchema(props: any): any { } export function getNodeSchemaById(schema: IPublicTypeNodeSchema, nodeId: string): IPublicTypeNodeSchema | undefined { - let found: NodeSIPublicTypeNodeSchemachema | undefined; + let found: IPublicTypeNodeSchema | undefined; if (schema.id === nodeId) { return schema; } @@ -100,7 +100,7 @@ export function getNodeSchemaById(schema: IPublicTypeNodeSchema, nodeId: string) function getNodeSchemaFromPropsById(props: any, nodeId: string): IPublicTypeNodeSchema | undefined { let found: IPublicTypeNodeSchema | undefined; - for (const [key, value] of Object.entries(props)) { + for (const [_key, value] of Object.entries(props)) { if (isJSSlot(value)) { // value 是数组类型 { type: 'JSSlot', value: IPublicTypeNodeSchema[] } if (Array.isArray(value.value)) { @@ -123,7 +123,7 @@ function getNodeSchemaFromPropsById(props: any, nodeId: string): IPublicTypeNode * TODO: not sure if this is used anywhere * @deprecated */ -export function applyActivities(pivotSchema: IPublicTypeRootSchema, activities: any, options?: any): IPublicTypeRootSchema { +export function applyActivities(pivotSchema: IPublicTypeRootSchema, activities: any): IPublicTypeRootSchema { let schema = { ...pivotSchema }; if (!Array.isArray(activities)) { activities = [activities]; diff --git a/packages/workspace/src/context/base-context.ts b/packages/workspace/src/context/base-context.ts index 37ce7fafa..b67842fe8 100644 --- a/packages/workspace/src/context/base-context.ts +++ b/packages/workspace/src/context/base-context.ts @@ -30,6 +30,7 @@ import { import { IPluginPreferenceMananger, IPublicApiEvent, + IPublicApiWorkspace, IPublicModelPluginContext, IPublicTypePluginMeta, } from '@alilc/lowcode-types'; @@ -59,6 +60,7 @@ export class BasicContext implements IPublicModelPluginContext { canvas: Canvas; pluginEvent: IPublicApiEvent; preference: IPluginPreferenceMananger; + workspace: IPublicApiWorkspace; constructor(innerWorkspace: InnerWorkspace, viewName: string, public editorWindow?: EditorWindow) { const editor = new Editor(viewName, true); diff --git a/packages/workspace/src/workspace.ts b/packages/workspace/src/workspace.ts index 0b7181cd8..f7d49ed49 100644 --- a/packages/workspace/src/workspace.ts +++ b/packages/workspace/src/workspace.ts @@ -1,4 +1,4 @@ -import { Designer } from '@alilc/lowcode-designer'; +import { Designer, LowCodePluginManager } from '@alilc/lowcode-designer'; import { createModuleEventBus, Editor, IEventBus, makeObservable, obx } from '@alilc/lowcode-editor-core'; import { Plugins } from '@alilc/lowcode-shell'; import { IPublicApiWorkspace, IPublicResourceList, IPublicTypeResourceType } from '@alilc/lowcode-types'; @@ -15,7 +15,11 @@ enum event { const CHANGE_EVENT = 'resource.list.change'; -export class Workspace implements IPublicApiWorkspace { +interface IWorkspace extends Omit, 'resourceList'> {} + +export class Workspace implements IWorkspace { context: BasicContext; private emitter: IEventBus = createModuleEventBus('workspace'); @@ -134,7 +138,7 @@ export class Workspace implements IPublicApiWorkspace { this.emitChangeWindow(); } - removeEditorWindow(resourceName: string, title: string) { + removeEditorWindow(resourceName: string) { const index = this.windows.findIndex(d => (d.resource.name === resourceName && d.title)); this.remove(index); }