Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update ts defined #2940

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 13 additions & 23 deletions packages/designer/src/context-menu-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@ import { Menu } from '@alifd/next';
import { engineConfig } from '@alilc/lowcode-editor-core';
import './context-menu-actions.scss';

export interface IContextMenuActions {
actions: IPublicTypeContextMenuAction[];

adjustMenuLayoutFn: (actions: IPublicTypeContextMenuItem[]) => IPublicTypeContextMenuItem[];

addMenuAction: IPublicApiMaterial['addContextMenuOption'];

removeMenuAction: IPublicApiMaterial['removeContextMenuOption'];

adjustMenuLayout: IPublicApiMaterial['adjustContextMenuLayout'];
}

let adjustMenuLayoutFn: Function = (actions: IPublicTypeContextMenuAction[]) => actions;

export class GlobalContextMenuActions {
Expand Down Expand Up @@ -116,7 +104,7 @@ export class GlobalContextMenuActions {

const globalContextMenuActions = new GlobalContextMenuActions();

export class ContextMenuActions implements IContextMenuActions {
export class ContextMenuActions {
actions: IPublicTypeContextMenuAction[] = [];

designer: IDesigner;
Expand Down Expand Up @@ -204,30 +192,32 @@ export class ContextMenuActions implements IContextMenuActions {
originalEvent.stopPropagation();
originalEvent.preventDefault();
// 如果右键的节点不在 当前选中的节点中,选中该节点
if (!designer.currentSelection.has(node.id)) {
designer.currentSelection.select(node.id);
if (!designer.currentSelection?.has(node.id)) {
designer.currentSelection?.select(node.id);
}
const nodes = designer.currentSelection.getNodes();
const nodes = designer.currentSelection?.getNodes();
this.handleContextMenu(nodes, originalEvent);
}),
);
}

addMenuAction(action: IPublicTypeContextMenuAction) {
addMenuAction: IPublicApiMaterial['addContextMenuOption'] = (action: IPublicTypeContextMenuAction) => {
this.actions.push({
type: IPublicEnumContextMenuType.MENU_ITEM,
...action,
});
}
};

removeMenuAction(name: string) {
removeMenuAction: IPublicApiMaterial['removeContextMenuOption'] = (name: string) => {
const i = this.actions.findIndex((action) => action.name === name);
if (i > -1) {
this.actions.splice(i, 1);
}
}
};

adjustMenuLayout(fn: (actions: IPublicTypeContextMenuItem[]) => IPublicTypeContextMenuItem[]) {
adjustMenuLayout: IPublicApiMaterial['adjustContextMenuLayout'] = (fn: (actions: IPublicTypeContextMenuItem[]) => IPublicTypeContextMenuItem[]) => {
adjustMenuLayoutFn = fn;
}
}
};
}

export interface IContextMenuActions extends ContextMenuActions {}
6 changes: 3 additions & 3 deletions packages/designer/src/designer/designer-view.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Component } from 'react';
import classNames from 'classnames';
import BuiltinDragGhostComponent from './drag-ghost';
import { Designer, DesignerProps } from './designer';
import { Designer, DesignerProps, IDesigner } from './designer';
import { ProjectView } from '../project';
import './designer.less';

type IProps = DesignerProps & {
designer?: Designer;
designer?: IDesigner;
};

export class DesignerView extends Component<IProps> {
readonly designer: Designer;
readonly designer: IDesigner;
readonly viewName: string | undefined;

constructor(props: IProps) {
Expand Down
80 changes: 11 additions & 69 deletions packages/designer/src/designer/designer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
IPublicTypeComponentAction,
IPublicTypeNpmInfo,
IPublicModelEditor,
IPublicTypeCompositeObject,
IPublicTypePropsList,
IPublicTypeNodeSchema,
IPublicTypePropsTransducer,
Expand All @@ -17,15 +16,16 @@ import {
IPublicTypeLocationData,
IPublicEnumTransformStage,
IPublicModelLocateEvent,
IPublicTypePropsMap,
} from '@alilc/lowcode-types';
import { mergeAssets, IPublicTypeAssetsJson, isNodeSchema, isDragNodeObject, isDragNodeDataObject, isLocationChildrenDetail, Logger } from '@alilc/lowcode-utils';
import { IProject, Project } from '../project';
import { Node, DocumentModel, insertChildren, INode, ISelection } from '../document';
import { Node, DocumentModel, insertChildren, INode } from '../document';
import { ComponentMeta, IComponentMeta } from '../component-meta';
import { INodeSelector, Component } from '../simulator';
import { Scroller } from './scroller';
import { Dragon, IDragon } from './dragon';
import { ActiveTracker, IActiveTracker } from './active-tracker';
import { ActiveTracker } from './active-tracker';
import { Detecting } from './detecting';
import { DropLocation } from './location';
import { OffsetObserver, createOffsetObserver } from './offset-observer';
Expand All @@ -47,7 +47,7 @@ export interface DesignerProps {
viewName?: string;
simulatorProps?: Record<string, any> | ((document: DocumentModel) => object);
simulatorComponent?: ComponentType<any>;
dragGhostComponent?: ComponentType<any>;
dragGhostComponent?: ComponentType<{ designer: IDesigner }>;
suspensed?: boolean;
componentMetadatas?: IPublicTypeComponentMetadata[];
globalComponentActions?: IPublicTypeComponentAction[];
Expand All @@ -60,70 +60,10 @@ export interface DesignerProps {
) => void;
}

export interface IDesigner {
readonly shellModelFactory: IShellModelFactory;

viewName: string | undefined;

readonly project: IProject;

get dragon(): IDragon;

get activeTracker(): IActiveTracker;

get componentActions(): ComponentActions;

get contextMenuActions(): ContextMenuActions;

get editor(): IPublicModelEditor;

get detecting(): Detecting;

get simulatorComponent(): ComponentType<any> | undefined;

get currentSelection(): ISelection;

createScroller(scrollable: IPublicTypeScrollable): IPublicModelScroller;

refreshComponentMetasMap(): void;

createOffsetObserver(nodeInstance: INodeSelector): OffsetObserver | null;

/**
* 创建插入位置,考虑放到 dragon 中
*/
createLocation(locationData: IPublicTypeLocationData<INode>): DropLocation;

get componentsMap(): { [key: string]: IPublicTypeNpmInfo | Component };

loadIncrementalAssets(incrementalAssets: IPublicTypeAssetsJson): Promise<void>;

getComponentMeta(
componentName: string,
generateMetadata?: () => IPublicTypeComponentMetadata | null,
): IComponentMeta;

clearLocation(): void;

createComponentMeta(data: IPublicTypeComponentMetadata): IComponentMeta | null;

getComponentMetasMap(): Map<string, IComponentMeta>;

addPropsReducer(reducer: IPublicTypePropsTransducer, stage: IPublicEnumTransformStage): void;

postEvent(event: string, ...args: any[]): void;

transformProps(props: IPublicTypeCompositeObject | IPublicTypePropsList, node: Node, stage: IPublicEnumTransformStage): IPublicTypeCompositeObject | IPublicTypePropsList;

createSettingEntry(nodes: INode[]): ISettingTopEntry;

autorun(effect: (reaction: IReactionPublic) => void, options?: IReactionOptions<any, any>): IReactionDisposer;
}

export class Designer implements IDesigner {
export class Designer {
dragon: IDragon;

viewName: string | undefined;
readonly viewName: string | undefined;

readonly componentActions = new ComponentActions();

Expand Down Expand Up @@ -423,7 +363,7 @@ export class Designer implements IDesigner {
if (props.simulatorProps !== this.props.simulatorProps) {
this._simulatorProps = props.simulatorProps;
// 重新 setupSelection
if (props.simulatorProps?.designMode !== this.props.simulatorProps?.designMode) {
if ((props.simulatorProps as any)?.designMode !== (this.props.simulatorProps as any)?.designMode) {
this.setupSelection();
}
}
Expand Down Expand Up @@ -612,7 +552,7 @@ export class Designer implements IDesigner {
return maps;
}

transformProps(props: IPublicTypeCompositeObject | IPublicTypePropsList, node: Node, stage: IPublicEnumTransformStage) {
transformProps(props: IPublicTypePropsMap | IPublicTypePropsList, node: Node, stage: IPublicEnumTransformStage): IPublicTypePropsMap | IPublicTypePropsList {
if (Array.isArray(props)) {
// current not support, make this future
return props;
Expand All @@ -623,7 +563,7 @@ export class Designer implements IDesigner {
return props;
}

return reducers.reduce((xprops, reducer) => {
return reducers.reduce((xprops, reducer: IPublicTypePropsTransducer) => {
try {
return reducer(xprops, node.internalToShellNode() as any, { stage });
} catch (e) {
Expand Down Expand Up @@ -655,3 +595,5 @@ export class Designer implements IDesigner {
// TODO:
}
}

export interface IDesigner extends Designer {}
14 changes: 6 additions & 8 deletions packages/designer/src/designer/dragon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,13 @@ function isDragEvent(e: any): e is DragEvent {
return e?.type?.startsWith('drag');
}

export interface IDragon extends IPublicModelDragon<
INode,
ILocateEvent
> {
emitter: IEventBus;
}

/**
* Drag-on 拖拽引擎
*/
export class Dragon implements IDragon {
export class Dragon implements IPublicModelDragon<
INode,
ILocateEvent
> {
private sensors: IPublicModelSensor[] = [];

private nodeInstPointerEvents: boolean;
Expand Down Expand Up @@ -637,3 +633,5 @@ export class Dragon implements IDragon {
};
}
}

export interface IDragon extends Dragon { }
34 changes: 17 additions & 17 deletions packages/designer/src/designer/offset-observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ export class OffsetObserver {
@obx private _bottom = 0;

@computed get height() {
return this.isRoot ? this.viewport.height : this._height * this.scale;
return this.isRoot ? this.viewport?.height : this._height * this.scale;
}

@computed get width() {
return this.isRoot ? this.viewport.width : this._width * this.scale;
return this.isRoot ? this.viewport?.width : this._width * this.scale;
}

@computed get top() {
Expand All @@ -44,51 +44,51 @@ export class OffsetObserver {
}

@computed get bottom() {
return this.isRoot ? this.viewport.height : this._bottom * this.scale;
return this.isRoot ? this.viewport?.height : this._bottom * this.scale;
}

@computed get right() {
return this.isRoot ? this.viewport.width : this._right * this.scale;
return this.isRoot ? this.viewport?.width : this._right * this.scale;
}

@obx hasOffset = false;

@computed get offsetLeft() {
if (this.isRoot) {
return this.viewport.scrollX * this.scale;
return (this.viewport?.scrollX || 0) * this.scale;
}
if (!this.viewport.scrolling || this.lastOffsetLeft == null) {
this.lastOffsetLeft = this.left + this.viewport.scrollX * this.scale;
if (!this.viewport?.scrolling || this.lastOffsetLeft == null) {
this.lastOffsetLeft = this.left + (this.viewport?.scrollX || 0) * this.scale;
}
return this.lastOffsetLeft;
}

@computed get offsetTop() {
if (this.isRoot) {
return this.viewport.scrollY * this.scale;
return (this.viewport?.scrollY || 0) * this.scale;
}
if (!this.viewport.scrolling || this.lastOffsetTop == null) {
this.lastOffsetTop = this.top + this.viewport.scrollY * this.scale;
if (!this.viewport?.scrolling || this.lastOffsetTop == null) {
this.lastOffsetTop = this.top + (this.viewport?.scrollY || 0) * this.scale;
}
return this.lastOffsetTop;
}

@computed get offsetHeight() {
if (!this.viewport.scrolling || this.lastOffsetHeight == null) {
this.lastOffsetHeight = this.isRoot ? this.viewport.height : this.height;
if (!this.viewport?.scrolling || this.lastOffsetHeight == null) {
this.lastOffsetHeight = this.isRoot ? (this.viewport?.height || 0) : this.height;
}
return this.lastOffsetHeight;
}

@computed get offsetWidth() {
if (!this.viewport.scrolling || this.lastOffsetWidth == null) {
this.lastOffsetWidth = this.isRoot ? this.viewport.width : this.width;
if (!(this.viewport?.scrolling || 0) || this.lastOffsetWidth == null) {
this.lastOffsetWidth = this.isRoot ? (this.viewport?.width || 0) : this.width;
}
return this.lastOffsetWidth;
}

@computed get scale() {
return this.viewport.scale;
return this.viewport?.scale || 0;
}

private pid: number | undefined;
Expand Down Expand Up @@ -124,11 +124,11 @@ export class OffsetObserver {
return;
}

const rect = host.computeComponentInstanceRect(instance!, node.componentMeta.rootSelector);
const rect = host?.computeComponentInstanceRect(instance!, node.componentMeta.rootSelector);

if (!rect) {
this.hasOffset = false;
} else if (!this.viewport.scrolling || !this.hasOffset) {
} else if (!this.viewport?.scrolling || !this.hasOffset) {
this._height = rect.height;
this._width = rect.width;
this._left = rect.left;
Expand Down
Loading
Loading