Skip to content

Commit 0d92011

Browse files
liujupingJackLian
authored andcommitted
chore: update ts defined
1 parent dbd9382 commit 0d92011

75 files changed

Lines changed: 226 additions & 683 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/designer/src/context-menu-actions.ts

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,6 @@ import { Menu } from '@alifd/next';
55
import { engineConfig } from '@alilc/lowcode-editor-core';
66
import './context-menu-actions.scss';
77

8-
export interface IContextMenuActions {
9-
actions: IPublicTypeContextMenuAction[];
10-
11-
adjustMenuLayoutFn: (actions: IPublicTypeContextMenuItem[]) => IPublicTypeContextMenuItem[];
12-
13-
addMenuAction: IPublicApiMaterial['addContextMenuOption'];
14-
15-
removeMenuAction: IPublicApiMaterial['removeContextMenuOption'];
16-
17-
adjustMenuLayout: IPublicApiMaterial['adjustContextMenuLayout'];
18-
}
19-
208
let adjustMenuLayoutFn: Function = (actions: IPublicTypeContextMenuAction[]) => actions;
219

2210
export class GlobalContextMenuActions {
@@ -116,7 +104,7 @@ export class GlobalContextMenuActions {
116104

117105
const globalContextMenuActions = new GlobalContextMenuActions();
118106

119-
export class ContextMenuActions implements IContextMenuActions {
107+
export class ContextMenuActions {
120108
actions: IPublicTypeContextMenuAction[] = [];
121109

122110
designer: IDesigner;
@@ -204,30 +192,32 @@ export class ContextMenuActions implements IContextMenuActions {
204192
originalEvent.stopPropagation();
205193
originalEvent.preventDefault();
206194
// 如果右键的节点不在 当前选中的节点中,选中该节点
207-
if (!designer.currentSelection.has(node.id)) {
208-
designer.currentSelection.select(node.id);
195+
if (!designer.currentSelection?.has(node.id)) {
196+
designer.currentSelection?.select(node.id);
209197
}
210-
const nodes = designer.currentSelection.getNodes();
198+
const nodes = designer.currentSelection?.getNodes();
211199
this.handleContextMenu(nodes, originalEvent);
212200
}),
213201
);
214202
}
215203

216-
addMenuAction(action: IPublicTypeContextMenuAction) {
204+
addMenuAction: IPublicApiMaterial['addContextMenuOption'] = (action: IPublicTypeContextMenuAction) => {
217205
this.actions.push({
218206
type: IPublicEnumContextMenuType.MENU_ITEM,
219207
...action,
220208
});
221-
}
209+
};
222210

223-
removeMenuAction(name: string) {
211+
removeMenuAction: IPublicApiMaterial['removeContextMenuOption'] = (name: string) => {
224212
const i = this.actions.findIndex((action) => action.name === name);
225213
if (i > -1) {
226214
this.actions.splice(i, 1);
227215
}
228-
}
216+
};
229217

230-
adjustMenuLayout(fn: (actions: IPublicTypeContextMenuItem[]) => IPublicTypeContextMenuItem[]) {
218+
adjustMenuLayout: IPublicApiMaterial['adjustContextMenuLayout'] = (fn: (actions: IPublicTypeContextMenuItem[]) => IPublicTypeContextMenuItem[]) => {
231219
adjustMenuLayoutFn = fn;
232-
}
233-
}
220+
};
221+
}
222+
223+
export interface IContextMenuActions extends ContextMenuActions {}

packages/designer/src/designer/designer-view.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { Component } from 'react';
22
import classNames from 'classnames';
33
import BuiltinDragGhostComponent from './drag-ghost';
4-
import { Designer, DesignerProps } from './designer';
4+
import { Designer, DesignerProps, IDesigner } from './designer';
55
import { ProjectView } from '../project';
66
import './designer.less';
77

88
type IProps = DesignerProps & {
9-
designer?: Designer;
9+
designer?: IDesigner;
1010
};
1111

1212
export class DesignerView extends Component<IProps> {
13-
readonly designer: Designer;
13+
readonly designer: IDesigner;
1414
readonly viewName: string | undefined;
1515

1616
constructor(props: IProps) {

packages/designer/src/designer/designer.ts

Lines changed: 11 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
IPublicTypeComponentAction,
77
IPublicTypeNpmInfo,
88
IPublicModelEditor,
9-
IPublicTypeCompositeObject,
109
IPublicTypePropsList,
1110
IPublicTypeNodeSchema,
1211
IPublicTypePropsTransducer,
@@ -17,15 +16,16 @@ import {
1716
IPublicTypeLocationData,
1817
IPublicEnumTransformStage,
1918
IPublicModelLocateEvent,
19+
IPublicTypePropsMap,
2020
} from '@alilc/lowcode-types';
2121
import { mergeAssets, IPublicTypeAssetsJson, isNodeSchema, isDragNodeObject, isDragNodeDataObject, isLocationChildrenDetail, Logger } from '@alilc/lowcode-utils';
2222
import { IProject, Project } from '../project';
23-
import { Node, DocumentModel, insertChildren, INode, ISelection } from '../document';
23+
import { Node, DocumentModel, insertChildren, INode } from '../document';
2424
import { ComponentMeta, IComponentMeta } from '../component-meta';
2525
import { INodeSelector, Component } from '../simulator';
2626
import { Scroller } from './scroller';
2727
import { Dragon, IDragon } from './dragon';
28-
import { ActiveTracker, IActiveTracker } from './active-tracker';
28+
import { ActiveTracker } from './active-tracker';
2929
import { Detecting } from './detecting';
3030
import { DropLocation } from './location';
3131
import { OffsetObserver, createOffsetObserver } from './offset-observer';
@@ -47,7 +47,7 @@ export interface DesignerProps {
4747
viewName?: string;
4848
simulatorProps?: Record<string, any> | ((document: DocumentModel) => object);
4949
simulatorComponent?: ComponentType<any>;
50-
dragGhostComponent?: ComponentType<any>;
50+
dragGhostComponent?: ComponentType<{ designer: IDesigner }>;
5151
suspensed?: boolean;
5252
componentMetadatas?: IPublicTypeComponentMetadata[];
5353
globalComponentActions?: IPublicTypeComponentAction[];
@@ -60,70 +60,10 @@ export interface DesignerProps {
6060
) => void;
6161
}
6262

63-
export interface IDesigner {
64-
readonly shellModelFactory: IShellModelFactory;
65-
66-
viewName: string | undefined;
67-
68-
readonly project: IProject;
69-
70-
get dragon(): IDragon;
71-
72-
get activeTracker(): IActiveTracker;
73-
74-
get componentActions(): ComponentActions;
75-
76-
get contextMenuActions(): ContextMenuActions;
77-
78-
get editor(): IPublicModelEditor;
79-
80-
get detecting(): Detecting;
81-
82-
get simulatorComponent(): ComponentType<any> | undefined;
83-
84-
get currentSelection(): ISelection;
85-
86-
createScroller(scrollable: IPublicTypeScrollable): IPublicModelScroller;
87-
88-
refreshComponentMetasMap(): void;
89-
90-
createOffsetObserver(nodeInstance: INodeSelector): OffsetObserver | null;
91-
92-
/**
93-
* 创建插入位置,考虑放到 dragon 中
94-
*/
95-
createLocation(locationData: IPublicTypeLocationData<INode>): DropLocation;
96-
97-
get componentsMap(): { [key: string]: IPublicTypeNpmInfo | Component };
98-
99-
loadIncrementalAssets(incrementalAssets: IPublicTypeAssetsJson): Promise<void>;
100-
101-
getComponentMeta(
102-
componentName: string,
103-
generateMetadata?: () => IPublicTypeComponentMetadata | null,
104-
): IComponentMeta;
105-
106-
clearLocation(): void;
107-
108-
createComponentMeta(data: IPublicTypeComponentMetadata): IComponentMeta | null;
109-
110-
getComponentMetasMap(): Map<string, IComponentMeta>;
111-
112-
addPropsReducer(reducer: IPublicTypePropsTransducer, stage: IPublicEnumTransformStage): void;
113-
114-
postEvent(event: string, ...args: any[]): void;
115-
116-
transformProps(props: IPublicTypeCompositeObject | IPublicTypePropsList, node: Node, stage: IPublicEnumTransformStage): IPublicTypeCompositeObject | IPublicTypePropsList;
117-
118-
createSettingEntry(nodes: INode[]): ISettingTopEntry;
119-
120-
autorun(effect: (reaction: IReactionPublic) => void, options?: IReactionOptions<any, any>): IReactionDisposer;
121-
}
122-
123-
export class Designer implements IDesigner {
63+
export class Designer {
12464
dragon: IDragon;
12565

126-
viewName: string | undefined;
66+
readonly viewName: string | undefined;
12767

12868
readonly componentActions = new ComponentActions();
12969

@@ -423,7 +363,7 @@ export class Designer implements IDesigner {
423363
if (props.simulatorProps !== this.props.simulatorProps) {
424364
this._simulatorProps = props.simulatorProps;
425365
// 重新 setupSelection
426-
if (props.simulatorProps?.designMode !== this.props.simulatorProps?.designMode) {
366+
if ((props.simulatorProps as any)?.designMode !== (this.props.simulatorProps as any)?.designMode) {
427367
this.setupSelection();
428368
}
429369
}
@@ -612,7 +552,7 @@ export class Designer implements IDesigner {
612552
return maps;
613553
}
614554

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

626-
return reducers.reduce((xprops, reducer) => {
566+
return reducers.reduce((xprops, reducer: IPublicTypePropsTransducer) => {
627567
try {
628568
return reducer(xprops, node.internalToShellNode() as any, { stage });
629569
} catch (e) {
@@ -655,3 +595,5 @@ export class Designer implements IDesigner {
655595
// TODO:
656596
}
657597
}
598+
599+
export interface IDesigner extends Designer {}

packages/designer/src/designer/dragon.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,13 @@ function isDragEvent(e: any): e is DragEvent {
9595
return e?.type?.startsWith('drag');
9696
}
9797

98-
export interface IDragon extends IPublicModelDragon<
99-
INode,
100-
ILocateEvent
101-
> {
102-
emitter: IEventBus;
103-
}
104-
10598
/**
10699
* Drag-on 拖拽引擎
107100
*/
108-
export class Dragon implements IDragon {
101+
export class Dragon implements IPublicModelDragon<
102+
INode,
103+
ILocateEvent
104+
> {
109105
private sensors: IPublicModelSensor[] = [];
110106

111107
private nodeInstPointerEvents: boolean;
@@ -637,3 +633,5 @@ export class Dragon implements IDragon {
637633
};
638634
}
639635
}
636+
637+
export interface IDragon extends Dragon { }

packages/designer/src/designer/offset-observer.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ export class OffsetObserver {
2828
@obx private _bottom = 0;
2929

3030
@computed get height() {
31-
return this.isRoot ? this.viewport.height : this._height * this.scale;
31+
return this.isRoot ? this.viewport?.height : this._height * this.scale;
3232
}
3333

3434
@computed get width() {
35-
return this.isRoot ? this.viewport.width : this._width * this.scale;
35+
return this.isRoot ? this.viewport?.width : this._width * this.scale;
3636
}
3737

3838
@computed get top() {
@@ -44,51 +44,51 @@ export class OffsetObserver {
4444
}
4545

4646
@computed get bottom() {
47-
return this.isRoot ? this.viewport.height : this._bottom * this.scale;
47+
return this.isRoot ? this.viewport?.height : this._bottom * this.scale;
4848
}
4949

5050
@computed get right() {
51-
return this.isRoot ? this.viewport.width : this._right * this.scale;
51+
return this.isRoot ? this.viewport?.width : this._right * this.scale;
5252
}
5353

5454
@obx hasOffset = false;
5555

5656
@computed get offsetLeft() {
5757
if (this.isRoot) {
58-
return this.viewport.scrollX * this.scale;
58+
return (this.viewport?.scrollX || 0) * this.scale;
5959
}
60-
if (!this.viewport.scrolling || this.lastOffsetLeft == null) {
61-
this.lastOffsetLeft = this.left + this.viewport.scrollX * this.scale;
60+
if (!this.viewport?.scrolling || this.lastOffsetLeft == null) {
61+
this.lastOffsetLeft = this.left + (this.viewport?.scrollX || 0) * this.scale;
6262
}
6363
return this.lastOffsetLeft;
6464
}
6565

6666
@computed get offsetTop() {
6767
if (this.isRoot) {
68-
return this.viewport.scrollY * this.scale;
68+
return (this.viewport?.scrollY || 0) * this.scale;
6969
}
70-
if (!this.viewport.scrolling || this.lastOffsetTop == null) {
71-
this.lastOffsetTop = this.top + this.viewport.scrollY * this.scale;
70+
if (!this.viewport?.scrolling || this.lastOffsetTop == null) {
71+
this.lastOffsetTop = this.top + (this.viewport?.scrollY || 0) * this.scale;
7272
}
7373
return this.lastOffsetTop;
7474
}
7575

7676
@computed get offsetHeight() {
77-
if (!this.viewport.scrolling || this.lastOffsetHeight == null) {
78-
this.lastOffsetHeight = this.isRoot ? this.viewport.height : this.height;
77+
if (!this.viewport?.scrolling || this.lastOffsetHeight == null) {
78+
this.lastOffsetHeight = this.isRoot ? (this.viewport?.height || 0) : this.height;
7979
}
8080
return this.lastOffsetHeight;
8181
}
8282

8383
@computed get offsetWidth() {
84-
if (!this.viewport.scrolling || this.lastOffsetWidth == null) {
85-
this.lastOffsetWidth = this.isRoot ? this.viewport.width : this.width;
84+
if (!(this.viewport?.scrolling || 0) || this.lastOffsetWidth == null) {
85+
this.lastOffsetWidth = this.isRoot ? (this.viewport?.width || 0) : this.width;
8686
}
8787
return this.lastOffsetWidth;
8888
}
8989

9090
@computed get scale() {
91-
return this.viewport.scale;
91+
return this.viewport?.scale || 0;
9292
}
9393

9494
private pid: number | undefined;
@@ -124,11 +124,11 @@ export class OffsetObserver {
124124
return;
125125
}
126126

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

129129
if (!rect) {
130130
this.hasOffset = false;
131-
} else if (!this.viewport.scrolling || !this.hasOffset) {
131+
} else if (!this.viewport?.scrolling || !this.hasOffset) {
132132
this._height = rect.height;
133133
this._width = rect.width;
134134
this._left = rect.left;

0 commit comments

Comments
 (0)