Skip to content

Commit 9cec5d8

Browse files
liujupingJackLian
authored andcommitted
feat: update the ts definition of the shell module
1 parent 810ef47 commit 9cec5d8

File tree

9 files changed

+58
-10
lines changed

9 files changed

+58
-10
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ module.exports = {
4848
"afterLineComment": false,
4949
"allowBlockStart": true,
5050
}],
51+
"no-unused-vars": ['error', { "destructuredArrayIgnorePattern": "^_" }],
5152
"@typescript-eslint/member-ordering": [
5253
"error",
5354
{ "default": ["signature", "field", "constructor", "method"] }

packages/plugin-outline-pane/src/views/tree-branches.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Component } from 'react';
22
import classNames from 'classnames';
33
import TreeNode from '../controllers/tree-node';
44
import TreeNodeView from './tree-node';
5-
import { IPublicModelPluginContext, IPublicModelExclusiveGroup } from '@alilc/lowcode-types';
5+
import { IPublicModelPluginContext, IPublicModelExclusiveGroup, IPublicTypeDisposable } from '@alilc/lowcode-types';
66

77
export default class TreeBranches extends Component<{
88
treeNode: TreeNode;
@@ -73,7 +73,7 @@ class TreeNodeChildren extends Component<{
7373
keywords: null,
7474
dropDetail: null,
7575
};
76-
offLocationChanged: () => void;
76+
offLocationChanged: IPublicTypeDisposable;
7777
componentDidMount() {
7878
const { treeNode, pluginContext } = this.props;
7979
const { project } = pluginContext;

packages/types/src/shell/api/canvas.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import { IPublicModelDragon, IPublicModelDropLocation, IPublicModelScrollTarget,
22
import { IPublicTypeLocationData, IPublicTypeScrollable } from '../type';
33

44
/**
5+
* canvas - 画布 API
56
* @since v1.1.0
67
*/
78
export interface IPublicApiCanvas {
89

910
/**
1011
* 创一个滚动控制器 Scroller,赋予一个视图滚动的基本能力,
12+
*
1113
* a Scroller is a controller that gives a view (IPublicTypeScrollable) the ability scrolling
1214
* to some cordination by api scrollTo.
1315
*
@@ -20,27 +22,31 @@ export interface IPublicApiCanvas {
2022

2123
/**
2224
* 创建一个 ScrollTarget,与 Scroller 一起发挥作用,详见 createScroller 中的描述
25+
*
2326
* this works with Scroller, refer to createScroller`s description
2427
* @since v1.1.0
2528
*/
2629
createScrollTarget(shell: HTMLDivElement): IPublicModelScrollTarget;
2730

2831
/**
2932
* 创建一个文档插入位置对象,该对象用来描述一个即将插入的节点在文档中的位置
33+
*
3034
* create a drop location for document, drop location describes a location in document
3135
* @since v1.1.0
3236
*/
3337
createLocation(locationData: IPublicTypeLocationData): IPublicModelDropLocation;
3438

3539
/**
3640
* 获取拖拽操作对象的实例
41+
*
3742
* get dragon instance, you can use this to obtain draging related abilities and lifecycle hooks
3843
* @since v1.1.0
3944
*/
4045
get dragon(): IPublicModelDragon | null;
4146

4247
/**
4348
* 获取活动追踪器实例
49+
*
4450
* get activeTracker instance, which is a singleton running in engine.
4551
* it tracks document`s current focusing node/node[], and notify it`s subscribers that when
4652
* focusing node/node[] changed.
@@ -50,13 +56,15 @@ export interface IPublicApiCanvas {
5056

5157
/**
5258
* 是否处于 LiveEditing 状态
59+
*
5360
* check if canvas is in liveEditing state
5461
* @since v1.1.0
5562
*/
5663
get isInLiveEditing(): boolean;
5764

5865
/**
5966
* 获取全局剪贴板实例
67+
*
6068
* get clipboard instance
6169
*
6270
* @since v1.1.0

packages/types/src/shell/api/material.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,25 @@ export interface IPublicApiMaterial {
7676

7777
/**
7878
* 在设计器辅助层增加一个扩展 action
79+
*
7980
* add an action button in canvas context menu area
8081
* @param action
82+
* @example
83+
* ```ts
84+
* import { plugins } from '@alilc/lowcode-engine';
85+
* import { IPublicModelPluginContext } from '@alilc/lowcode-types';
86+
*
87+
* const removeCopyAction = (ctx: IPublicModelPluginContext) => {
88+
* return {
89+
* async init() {
90+
* const { removeBuiltinComponentAction } = ctx.material;
91+
* removeBuiltinComponentAction('copy');
92+
* }
93+
* }
94+
* };
95+
* removeCopyAction.pluginName = 'removeCopyAction';
96+
* await plugins.register(removeCopyAction);
97+
* ```
8198
*/
8299
addBuiltinComponentAction(action: IPublicTypeComponentAction): void;
83100

packages/types/src/shell/api/workspace.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import { IPublicModelWindow } from '../model';
22
import { IPublicApiPlugins, IPublicModelResource, IPublicResourceList, IPublicTypeDisposable, IPublicTypeResourceType } from '@alilc/lowcode-types';
33

4-
export interface IPublicApiWorkspace {
4+
export interface IPublicApiWorkspace<
5+
Plugins = IPublicApiPlugins
6+
> {
57

68
/** 是否启用 workspace 模式 */
79
isActive: boolean;
810

911
/** 当前设计器窗口 */
1012
window: IPublicModelWindow;
1113

12-
plugins: IPublicApiPlugins;
14+
plugins: Plugins;
1315

1416
/** 当前设计器的编辑窗口 */
1517
windows: IPublicModelWindow[];

packages/types/src/shell/model/node-children.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface IPublicModelNodeChildren<
2727

2828
/**
2929
* 是否为空
30+
*
3031
* @returns
3132
*/
3233
get isEmptyNode(): boolean;
@@ -44,13 +45,15 @@ export interface IPublicModelNodeChildren<
4445

4546
/**
4647
* 删除指定节点
48+
*
4749
* delete the node
4850
* @param node
4951
*/
5052
delete(node: Node): boolean;
5153

5254
/**
5355
* 插入一个节点
56+
*
5457
* insert a node at specific position
5558
* @param node 待插入节点
5659
* @param at 插入下标
@@ -60,6 +63,7 @@ export interface IPublicModelNodeChildren<
6063

6164
/**
6265
* 返回指定节点的下标
66+
*
6367
* get index of node in current children
6468
* @param node
6569
* @returns
@@ -68,6 +72,7 @@ export interface IPublicModelNodeChildren<
6872

6973
/**
7074
* 类似数组 splice 操作
75+
*
7176
* provide the same function with {Array.prototype.splice}
7277
* @param start
7378
* @param deleteCount
@@ -77,6 +82,7 @@ export interface IPublicModelNodeChildren<
7782

7883
/**
7984
* 返回指定下标的节点
85+
*
8086
* get node with index
8187
* @param index
8288
* @returns
@@ -85,6 +91,7 @@ export interface IPublicModelNodeChildren<
8591

8692
/**
8793
* 是否包含指定节点
94+
*
8895
* check if node exists in current children
8996
* @param node
9097
* @returns
@@ -93,19 +100,22 @@ export interface IPublicModelNodeChildren<
93100

94101
/**
95102
* 类似数组的 forEach
103+
*
96104
* provide the same function with {Array.prototype.forEach}
97105
* @param fn
98106
*/
99107
forEach(fn: (node: Node, index: number) => void): void;
100108

101109
/**
102110
* 类似数组的 reverse
111+
*
103112
* provide the same function with {Array.prototype.reverse}
104113
*/
105114
reverse(): Node[];
106115

107116
/**
108117
* 类似数组的 map
118+
*
109119
* provide the same function with {Array.prototype.map}
110120
* @param fn
111121
*/
@@ -141,27 +151,31 @@ export interface IPublicModelNodeChildren<
141151

142152
/**
143153
* 类似数组的 reduce
154+
*
144155
* provide the same function with {Array.prototype.reduce}
145156
* @param fn
146157
*/
147158
reduce(fn: (acc: any, cur: Node) => any, initialValue: any): void;
148159

149160
/**
150161
* 导入 schema
162+
*
151163
* import schema
152164
* @param data
153165
*/
154166
importSchema(data?: IPublicTypeNodeData | IPublicTypeNodeData[]): void;
155167

156168
/**
157169
* 导出 schema
170+
*
158171
* export schema
159172
* @param stage
160173
*/
161174
exportSchema(stage: IPublicEnumTransformStage): IPublicTypeNodeSchema;
162175

163176
/**
164177
* 执行新增、删除、排序等操作
178+
*
165179
* excute remove/add/sort operations
166180
* @param remover
167181
* @param adder

packages/utils/src/schema.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export function compatibleLegaoSchema(props: any): any {
7979
}
8080

8181
export function getNodeSchemaById(schema: IPublicTypeNodeSchema, nodeId: string): IPublicTypeNodeSchema | undefined {
82-
let found: NodeSIPublicTypeNodeSchemachema | undefined;
82+
let found: IPublicTypeNodeSchema | undefined;
8383
if (schema.id === nodeId) {
8484
return schema;
8585
}
@@ -100,7 +100,7 @@ export function getNodeSchemaById(schema: IPublicTypeNodeSchema, nodeId: string)
100100

101101
function getNodeSchemaFromPropsById(props: any, nodeId: string): IPublicTypeNodeSchema | undefined {
102102
let found: IPublicTypeNodeSchema | undefined;
103-
for (const [key, value] of Object.entries(props)) {
103+
for (const [_key, value] of Object.entries(props)) {
104104
if (isJSSlot(value)) {
105105
// value 是数组类型 { type: 'JSSlot', value: IPublicTypeNodeSchema[] }
106106
if (Array.isArray(value.value)) {
@@ -123,7 +123,7 @@ function getNodeSchemaFromPropsById(props: any, nodeId: string): IPublicTypeNode
123123
* TODO: not sure if this is used anywhere
124124
* @deprecated
125125
*/
126-
export function applyActivities(pivotSchema: IPublicTypeRootSchema, activities: any, options?: any): IPublicTypeRootSchema {
126+
export function applyActivities(pivotSchema: IPublicTypeRootSchema, activities: any): IPublicTypeRootSchema {
127127
let schema = { ...pivotSchema };
128128
if (!Array.isArray(activities)) {
129129
activities = [activities];

packages/workspace/src/context/base-context.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
import {
3131
IPluginPreferenceMananger,
3232
IPublicApiEvent,
33+
IPublicApiWorkspace,
3334
IPublicModelPluginContext,
3435
IPublicTypePluginMeta,
3536
} from '@alilc/lowcode-types';
@@ -59,6 +60,7 @@ export class BasicContext implements IPublicModelPluginContext {
5960
canvas: Canvas;
6061
pluginEvent: IPublicApiEvent;
6162
preference: IPluginPreferenceMananger;
63+
workspace: IPublicApiWorkspace;
6264

6365
constructor(innerWorkspace: InnerWorkspace, viewName: string, public editorWindow?: EditorWindow) {
6466
const editor = new Editor(viewName, true);

packages/workspace/src/workspace.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Designer } from '@alilc/lowcode-designer';
1+
import { Designer, LowCodePluginManager } from '@alilc/lowcode-designer';
22
import { createModuleEventBus, Editor, IEventBus, makeObservable, obx } from '@alilc/lowcode-editor-core';
33
import { Plugins } from '@alilc/lowcode-shell';
44
import { IPublicApiWorkspace, IPublicResourceList, IPublicTypeResourceType } from '@alilc/lowcode-types';
@@ -15,7 +15,11 @@ enum event {
1515

1616
const CHANGE_EVENT = 'resource.list.change';
1717

18-
export class Workspace implements IPublicApiWorkspace {
18+
interface IWorkspace extends Omit<IPublicApiWorkspace<
19+
LowCodePluginManager
20+
>, 'resourceList'> {}
21+
22+
export class Workspace implements IWorkspace {
1923
context: BasicContext;
2024

2125
private emitter: IEventBus = createModuleEventBus('workspace');
@@ -134,7 +138,7 @@ export class Workspace implements IPublicApiWorkspace {
134138
this.emitChangeWindow();
135139
}
136140

137-
removeEditorWindow(resourceName: string, title: string) {
141+
removeEditorWindow(resourceName: string) {
138142
const index = this.windows.findIndex(d => (d.resource.name === resourceName && d.title));
139143
this.remove(index);
140144
}

0 commit comments

Comments
 (0)