feat: update the ts definition of the shell module

This commit is contained in:
liujuping 2023-03-01 18:32:10 +08:00 committed by 林熠
parent 810ef478e5
commit 9cec5d833c
9 changed files with 58 additions and 10 deletions

View File

@ -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"] }

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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[];

View File

@ -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

View File

@ -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];

View File

@ -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);

View File

@ -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<IPublicApiWorkspace<
LowCodePluginManager
>, '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);
}