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, "afterLineComment": false,
"allowBlockStart": true, "allowBlockStart": true,
}], }],
"no-unused-vars": ['error', { "destructuredArrayIgnorePattern": "^_" }],
"@typescript-eslint/member-ordering": [ "@typescript-eslint/member-ordering": [
"error", "error",
{ "default": ["signature", "field", "constructor", "method"] } { "default": ["signature", "field", "constructor", "method"] }

View File

@ -2,7 +2,7 @@ import { Component } from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import TreeNode from '../controllers/tree-node'; import TreeNode from '../controllers/tree-node';
import TreeNodeView from './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<{ export default class TreeBranches extends Component<{
treeNode: TreeNode; treeNode: TreeNode;
@ -73,7 +73,7 @@ class TreeNodeChildren extends Component<{
keywords: null, keywords: null,
dropDetail: null, dropDetail: null,
}; };
offLocationChanged: () => void; offLocationChanged: IPublicTypeDisposable;
componentDidMount() { componentDidMount() {
const { treeNode, pluginContext } = this.props; const { treeNode, pluginContext } = this.props;
const { project } = pluginContext; const { project } = pluginContext;

View File

@ -2,12 +2,14 @@ import { IPublicModelDragon, IPublicModelDropLocation, IPublicModelScrollTarget,
import { IPublicTypeLocationData, IPublicTypeScrollable } from '../type'; import { IPublicTypeLocationData, IPublicTypeScrollable } from '../type';
/** /**
* canvas - API
* @since v1.1.0 * @since v1.1.0
*/ */
export interface IPublicApiCanvas { export interface IPublicApiCanvas {
/** /**
* Scroller * Scroller
*
* a Scroller is a controller that gives a view (IPublicTypeScrollable) the ability scrolling * a Scroller is a controller that gives a view (IPublicTypeScrollable) the ability scrolling
* to some cordination by api scrollTo. * to some cordination by api scrollTo.
* *
@ -20,6 +22,7 @@ export interface IPublicApiCanvas {
/** /**
* ScrollTarget Scroller createScroller * ScrollTarget Scroller createScroller
*
* this works with Scroller, refer to createScroller`s description * this works with Scroller, refer to createScroller`s description
* @since v1.1.0 * @since v1.1.0
*/ */
@ -27,6 +30,7 @@ export interface IPublicApiCanvas {
/** /**
* *
*
* create a drop location for document, drop location describes a location in document * create a drop location for document, drop location describes a location in document
* @since v1.1.0 * @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 * get dragon instance, you can use this to obtain draging related abilities and lifecycle hooks
* @since v1.1.0 * @since v1.1.0
*/ */
@ -41,6 +46,7 @@ export interface IPublicApiCanvas {
/** /**
* *
*
* get activeTracker instance, which is a singleton running in engine. * 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 * it tracks document`s current focusing node/node[], and notify it`s subscribers that when
* focusing node/node[] changed. * focusing node/node[] changed.
@ -50,6 +56,7 @@ export interface IPublicApiCanvas {
/** /**
* LiveEditing * LiveEditing
*
* check if canvas is in liveEditing state * check if canvas is in liveEditing state
* @since v1.1.0 * @since v1.1.0
*/ */
@ -57,6 +64,7 @@ export interface IPublicApiCanvas {
/** /**
* *
*
* get clipboard instance * get clipboard instance
* *
* @since v1.1.0 * @since v1.1.0

View File

@ -76,8 +76,25 @@ export interface IPublicApiMaterial {
/** /**
* action * action
*
* add an action button in canvas context menu area * add an action button in canvas context menu area
* @param action * @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; addBuiltinComponentAction(action: IPublicTypeComponentAction): void;

View File

@ -1,7 +1,9 @@
import { IPublicModelWindow } from '../model'; import { IPublicModelWindow } from '../model';
import { IPublicApiPlugins, IPublicModelResource, IPublicResourceList, IPublicTypeDisposable, IPublicTypeResourceType } from '@alilc/lowcode-types'; import { IPublicApiPlugins, IPublicModelResource, IPublicResourceList, IPublicTypeDisposable, IPublicTypeResourceType } from '@alilc/lowcode-types';
export interface IPublicApiWorkspace { export interface IPublicApiWorkspace<
Plugins = IPublicApiPlugins
> {
/** 是否启用 workspace 模式 */ /** 是否启用 workspace 模式 */
isActive: boolean; isActive: boolean;
@ -9,7 +11,7 @@ export interface IPublicApiWorkspace {
/** 当前设计器窗口 */ /** 当前设计器窗口 */
window: IPublicModelWindow; window: IPublicModelWindow;
plugins: IPublicApiPlugins; plugins: Plugins;
/** 当前设计器的编辑窗口 */ /** 当前设计器的编辑窗口 */
windows: IPublicModelWindow[]; windows: IPublicModelWindow[];

View File

@ -27,6 +27,7 @@ export interface IPublicModelNodeChildren<
/** /**
* *
*
* @returns * @returns
*/ */
get isEmptyNode(): boolean; get isEmptyNode(): boolean;
@ -44,6 +45,7 @@ export interface IPublicModelNodeChildren<
/** /**
* *
*
* delete the node * delete the node
* @param node * @param node
*/ */
@ -51,6 +53,7 @@ export interface IPublicModelNodeChildren<
/** /**
* *
*
* insert a node at specific position * insert a node at specific position
* @param node * @param node
* @param at * @param at
@ -60,6 +63,7 @@ export interface IPublicModelNodeChildren<
/** /**
* *
*
* get index of node in current children * get index of node in current children
* @param node * @param node
* @returns * @returns
@ -68,6 +72,7 @@ export interface IPublicModelNodeChildren<
/** /**
* splice * splice
*
* provide the same function with {Array.prototype.splice} * provide the same function with {Array.prototype.splice}
* @param start * @param start
* @param deleteCount * @param deleteCount
@ -77,6 +82,7 @@ export interface IPublicModelNodeChildren<
/** /**
* *
*
* get node with index * get node with index
* @param index * @param index
* @returns * @returns
@ -85,6 +91,7 @@ export interface IPublicModelNodeChildren<
/** /**
* *
*
* check if node exists in current children * check if node exists in current children
* @param node * @param node
* @returns * @returns
@ -93,6 +100,7 @@ export interface IPublicModelNodeChildren<
/** /**
* forEach * forEach
*
* provide the same function with {Array.prototype.forEach} * provide the same function with {Array.prototype.forEach}
* @param fn * @param fn
*/ */
@ -100,12 +108,14 @@ export interface IPublicModelNodeChildren<
/** /**
* reverse * reverse
*
* provide the same function with {Array.prototype.reverse} * provide the same function with {Array.prototype.reverse}
*/ */
reverse(): Node[]; reverse(): Node[];
/** /**
* map * map
*
* provide the same function with {Array.prototype.map} * provide the same function with {Array.prototype.map}
* @param fn * @param fn
*/ */
@ -141,6 +151,7 @@ export interface IPublicModelNodeChildren<
/** /**
* reduce * reduce
*
* provide the same function with {Array.prototype.reduce} * provide the same function with {Array.prototype.reduce}
* @param fn * @param fn
*/ */
@ -148,6 +159,7 @@ export interface IPublicModelNodeChildren<
/** /**
* schema * schema
*
* import schema * import schema
* @param data * @param data
*/ */
@ -155,6 +167,7 @@ export interface IPublicModelNodeChildren<
/** /**
* schema * schema
*
* export schema * export schema
* @param stage * @param stage
*/ */
@ -162,6 +175,7 @@ export interface IPublicModelNodeChildren<
/** /**
* *
*
* excute remove/add/sort operations * excute remove/add/sort operations
* @param remover * @param remover
* @param adder * @param adder

View File

@ -79,7 +79,7 @@ export function compatibleLegaoSchema(props: any): any {
} }
export function getNodeSchemaById(schema: IPublicTypeNodeSchema, nodeId: string): IPublicTypeNodeSchema | undefined { export function getNodeSchemaById(schema: IPublicTypeNodeSchema, nodeId: string): IPublicTypeNodeSchema | undefined {
let found: NodeSIPublicTypeNodeSchemachema | undefined; let found: IPublicTypeNodeSchema | undefined;
if (schema.id === nodeId) { if (schema.id === nodeId) {
return schema; return schema;
} }
@ -100,7 +100,7 @@ export function getNodeSchemaById(schema: IPublicTypeNodeSchema, nodeId: string)
function getNodeSchemaFromPropsById(props: any, nodeId: string): IPublicTypeNodeSchema | undefined { function getNodeSchemaFromPropsById(props: any, nodeId: string): IPublicTypeNodeSchema | undefined {
let found: 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)) { if (isJSSlot(value)) {
// value 是数组类型 { type: 'JSSlot', value: IPublicTypeNodeSchema[] } // value 是数组类型 { type: 'JSSlot', value: IPublicTypeNodeSchema[] }
if (Array.isArray(value.value)) { if (Array.isArray(value.value)) {
@ -123,7 +123,7 @@ function getNodeSchemaFromPropsById(props: any, nodeId: string): IPublicTypeNode
* TODO: not sure if this is used anywhere * TODO: not sure if this is used anywhere
* @deprecated * @deprecated
*/ */
export function applyActivities(pivotSchema: IPublicTypeRootSchema, activities: any, options?: any): IPublicTypeRootSchema { export function applyActivities(pivotSchema: IPublicTypeRootSchema, activities: any): IPublicTypeRootSchema {
let schema = { ...pivotSchema }; let schema = { ...pivotSchema };
if (!Array.isArray(activities)) { if (!Array.isArray(activities)) {
activities = [activities]; activities = [activities];

View File

@ -30,6 +30,7 @@ import {
import { import {
IPluginPreferenceMananger, IPluginPreferenceMananger,
IPublicApiEvent, IPublicApiEvent,
IPublicApiWorkspace,
IPublicModelPluginContext, IPublicModelPluginContext,
IPublicTypePluginMeta, IPublicTypePluginMeta,
} from '@alilc/lowcode-types'; } from '@alilc/lowcode-types';
@ -59,6 +60,7 @@ export class BasicContext implements IPublicModelPluginContext {
canvas: Canvas; canvas: Canvas;
pluginEvent: IPublicApiEvent; pluginEvent: IPublicApiEvent;
preference: IPluginPreferenceMananger; preference: IPluginPreferenceMananger;
workspace: IPublicApiWorkspace;
constructor(innerWorkspace: InnerWorkspace, viewName: string, public editorWindow?: EditorWindow) { constructor(innerWorkspace: InnerWorkspace, viewName: string, public editorWindow?: EditorWindow) {
const editor = new Editor(viewName, true); 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 { createModuleEventBus, Editor, IEventBus, makeObservable, obx } from '@alilc/lowcode-editor-core';
import { Plugins } from '@alilc/lowcode-shell'; import { Plugins } from '@alilc/lowcode-shell';
import { IPublicApiWorkspace, IPublicResourceList, IPublicTypeResourceType } from '@alilc/lowcode-types'; import { IPublicApiWorkspace, IPublicResourceList, IPublicTypeResourceType } from '@alilc/lowcode-types';
@ -15,7 +15,11 @@ enum event {
const CHANGE_EVENT = 'resource.list.change'; 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; context: BasicContext;
private emitter: IEventBus = createModuleEventBus('workspace'); private emitter: IEventBus = createModuleEventBus('workspace');
@ -134,7 +138,7 @@ export class Workspace implements IPublicApiWorkspace {
this.emitChangeWindow(); this.emitChangeWindow();
} }
removeEditorWindow(resourceName: string, title: string) { removeEditorWindow(resourceName: string) {
const index = this.windows.findIndex(d => (d.resource.name === resourceName && d.title)); const index = this.windows.findIndex(d => (d.resource.name === resourceName && d.title));
this.remove(index); this.remove(index);
} }