Skip to content

Commit 6d4ca29

Browse files
liujupingJackLian
authored andcommitted
fix: fix workspace api ts defined
1 parent 12a22de commit 6d4ca29

37 files changed

+348
-219
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ module.exports = {
5252
'error',
5353
{ default: ['signature', 'field', 'constructor', 'method'] }
5454
],
55-
'no-unused-vars': ['error', { "destructuredArrayIgnorePattern": "^_" }]
55+
'@typescript-eslint/no-unused-vars': ['error']
5656
},
5757
};

packages/designer/src/builtin-simulator/bem-tools/border-selecting.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import { observer, computed, Tip, globalContext } from '@alilc/lowcode-editor-co
1313
import { createIcon, isReactComponent, isActionContentObject } from '@alilc/lowcode-utils';
1414
import { IPublicTypeActionContentObject } from '@alilc/lowcode-types';
1515
import { BuiltinSimulatorHost } from '../host';
16-
import { OffsetObserver } from '../../designer';
17-
import { Node } from '../../document';
16+
import { INode, OffsetObserver } from '../../designer';
1817
import NodeSelector from '../node-selector';
18+
import { ISimulatorHost } from '../../simulator';
1919

2020
@observer
2121
export class BorderSelectingInstance extends Component<{
@@ -116,8 +116,8 @@ class Toolbar extends Component<{ observed: OffsetObserver }> {
116116
}
117117
}
118118

119-
function createAction(content: ReactNode | ComponentType<any> | IPublicTypeActionContentObject, key: string, node: Node) {
120-
if (isValidElement(content)) {
119+
function createAction(content: ReactNode | ComponentType<any> | IPublicTypeActionContentObject, key: string, node: INode) {
120+
if (isValidElement<{ key: string; node: INode }>(content)) {
121121
return cloneElement(content, { key, node });
122122
}
123123
if (isReactComponent(content)) {
@@ -130,7 +130,7 @@ function createAction(content: ReactNode | ComponentType<any> | IPublicTypeActio
130130
key={key}
131131
className="lc-borders-action"
132132
onClick={() => {
133-
action && action(node);
133+
action && action(node.internalToShellNode()!);
134134
const workspace = globalContext.get('workspace');
135135
const editor = workspace.isActive ? workspace.window.editor : globalContext.get('editor');
136136
const npm = node?.componentMeta?.npm;
@@ -153,8 +153,8 @@ function createAction(content: ReactNode | ComponentType<any> | IPublicTypeActio
153153
}
154154

155155
@observer
156-
export class BorderSelectingForNode extends Component<{ host: BuiltinSimulatorHost; node: Node }> {
157-
get host(): BuiltinSimulatorHost {
156+
export class BorderSelectingForNode extends Component<{ host: ISimulatorHost; node: INode }> {
157+
get host(): ISimulatorHost {
158158
return this.props.host;
159159
}
160160

packages/designer/src/builtin-simulator/host.ts

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,26 @@ import {
4747
getRectTarget,
4848
CanvasPoint,
4949
Designer,
50+
IDesigner,
5051
} from '../designer';
5152
import { parseMetadata } from './utils/parse-metadata';
5253
import { getClosestClickableNode } from './utils/clickable';
5354
import {
5455
IPublicTypeComponentMetadata,
55-
IPublicTypeComponentSchema,
5656
IPublicTypePackage,
5757
IPublicEnumTransitionType,
5858
IPublicEnumDragObjectType,
59-
IPublicTypeDragNodeObject,
6059
IPublicTypeNodeInstance,
6160
IPublicTypeComponentInstance,
6261
IPublicTypeLocationChildrenDetail,
6362
IPublicTypeLocationDetailType,
6463
IPublicTypeRect,
64+
IPublicModelNode,
6565
} from '@alilc/lowcode-types';
6666
import { BuiltinSimulatorRenderer } from './renderer';
6767
import { clipboard } from '../designer/clipboard';
6868
import { LiveEditing } from './live-editing/live-editing';
69-
import { Project } from '../project';
69+
import { IProject, Project } from '../project';
7070
import { IScroller } from '../designer/scroller';
7171
import { isElementNode, isDOMNodeVisible } from '../utils/misc';
7272
import { debounce } from 'lodash';
@@ -164,9 +164,9 @@ const defaultRaxEnvironment = [
164164
export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProps> {
165165
readonly isSimulator = true;
166166

167-
readonly project: Project;
167+
readonly project: IProject;
168168

169-
readonly designer: Designer;
169+
readonly designer: IDesigner;
170170

171171
readonly viewport = new Viewport();
172172

@@ -217,7 +217,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
217217
return this.get('requestHandlersMap') || null;
218218
}
219219

220-
get thisRequiredInJSE(): any {
220+
get thisRequiredInJSE(): boolean {
221221
return engineConfig.get('thisRequiredInJSE') ?? true;
222222
}
223223

@@ -559,8 +559,8 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
559559
return;
560560
}
561561
// FIXME: dirty fix remove label-for fro liveEditing
562-
(downEvent.target as HTMLElement).removeAttribute('for');
563-
const nodeInst = this.getNodeInstanceFromElement(downEvent.target as Element);
562+
downEvent.target?.removeAttribute('for');
563+
const nodeInst = this.getNodeInstanceFromElement(downEvent.target);
564564
const { focusNode } = documentModel;
565565
const node = getClosestClickableNode(nodeInst?.node || focusNode, downEvent);
566566
// 如果找不到可点击的节点,直接返回
@@ -675,11 +675,11 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
675675
const x = new Event('click');
676676
x.initEvent('click', true);
677677
this._iframe?.dispatchEvent(x);
678-
const target = e.target as HTMLElement;
678+
const target = e.target;
679679

680680
const customizeIgnoreSelectors = engineConfig.get('customizeIgnoreSelectors');
681681
// TODO: need more elegant solution to ignore click events of components in designer
682-
const defaultIgnoreSelectors: any = [
682+
const defaultIgnoreSelectors: string[] = [
683683
'.next-input-group',
684684
'.next-checkbox-group',
685685
'.next-checkbox-wrapper',
@@ -741,7 +741,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
741741
}
742742
};
743743
const leave = () => {
744-
this.project.currentDocument && detecting.leave(this.project.currentDocument)
744+
this.project.currentDocument && detecting.leave(this.project.currentDocument);
745745
};
746746

747747
doc.addEventListener('mouseover', hover, true);
@@ -812,7 +812,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
812812
/**
813813
* @see ISimulator
814814
*/
815-
setSuspense(suspended: boolean) {
815+
setSuspense(/** _suspended: boolean */) {
816816
return false;
817817
// if (suspended) {
818818
// /*
@@ -897,7 +897,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
897897
return this.renderer?.getComponent(componentName) || null;
898898
}
899899

900-
createComponent(schema: IPublicTypeComponentSchema): Component | null {
900+
createComponent(/** _schema: IPublicTypeComponentSchema */): Component | null {
901901
return null;
902902
// return this.renderer?.createComponent(schema) || null;
903903
}
@@ -1018,7 +1018,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
10181018
}
10191019

10201020
if (last) {
1021-
const r: any = new DOMRect(last.x, last.y, last.r - last.x, last.b - last.y);
1021+
const r: IPublicTypeRect = new DOMRect(last.x, last.y, last.r - last.x, last.b - last.y);
10221022
r.elements = elements;
10231023
r.computed = _computed;
10241024
return r;
@@ -1186,13 +1186,14 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
11861186
*/
11871187
locate(e: ILocateEvent): any {
11881188
const { dragObject } = e;
1189-
const { nodes } = dragObject as IPublicTypeDragNodeObject;
1189+
1190+
const nodes = dragObject?.nodes;
11901191

11911192
const operationalNodes = nodes?.filter((node) => {
11921193
const onMoveHook = node.componentMeta?.advanced.callbacks?.onMoveHook;
11931194
const canMove = onMoveHook && typeof onMoveHook === 'function' ? onMoveHook(node.internalToShellNode()) : true;
11941195

1195-
let parentContainerNode: Node | null = null;
1196+
let parentContainerNode: INode | null = null;
11961197
let parentNode = node.parent;
11971198

11981199
while (parentNode) {
@@ -1254,7 +1255,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
12541255
};
12551256

12561257
const locationData = {
1257-
target: container as INode,
1258+
target: container,
12581259
detail,
12591260
source: `simulator${document.id}`,
12601261
event: e,
@@ -1279,12 +1280,12 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
12791280
return this.designer.createLocation(locationData);
12801281
}
12811282

1282-
let nearRect = null;
1283-
let nearIndex = 0;
1284-
let nearNode = null;
1285-
let nearDistance = null;
1286-
let minTop = null;
1287-
let maxBottom = null;
1283+
let nearRect: IPublicTypeRect | null = null;
1284+
let nearIndex: number = 0;
1285+
let nearNode: INode | null = null;
1286+
let nearDistance: number | null = null;
1287+
let minTop: number | null = null;
1288+
let maxBottom: number | null = null;
12881289

12891290
for (let i = 0, l = children.size; i < l; i++) {
12901291
const node = children.get(i)!;
@@ -1341,8 +1342,13 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
13411342
const vertical = inline || row;
13421343

13431344
// TODO: fix type
1344-
const near: any = {
1345-
node: nearNode,
1345+
const near: {
1346+
node: IPublicModelNode;
1347+
pos: 'before' | 'after' | 'replace';
1348+
rect?: IPublicTypeRect;
1349+
align?: 'V' | 'H';
1350+
} = {
1351+
node: nearNode.internalToShellNode()!,
13461352
pos: 'before',
13471353
align: vertical ? 'V' : 'H',
13481354
};
@@ -1465,7 +1471,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
14651471
container = container.parent;
14661472
instance = this.getClosestNodeInstance(dropContainer.instance, container.id)?.instance;
14671473
dropContainer = {
1468-
container: container,
1474+
container,
14691475
instance,
14701476
};
14711477
} else {
@@ -1483,12 +1489,12 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
14831489
/**
14841490
* 控制接受
14851491
*/
1486-
handleAccept({ container, instance }: DropContainer, e: ILocateEvent): boolean {
1492+
handleAccept({ container }: DropContainer, e: ILocateEvent): boolean {
14871493
const { dragObject } = e;
14881494
const document = this.currentDocument!;
14891495
const focusNode = document.focusNode;
14901496
if (isRootNode(container) || container.contains(focusNode)) {
1491-
return document.checkNesting(focusNode, dragObject as any);
1497+
return document.checkNesting(focusNode!, dragObject as any);
14921498
}
14931499

14941500
const meta = (container as Node).componentMeta;
@@ -1509,15 +1515,12 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
15091515
getNearByContainer(
15101516
{ container, instance }: DropContainer,
15111517
drillDownExcludes: Set<INode>,
1512-
e: ILocateEvent,
15131518
) {
15141519
const { children } = container;
1515-
const document = this.project.currentDocument!;
15161520
if (!children || children.isEmpty()) {
15171521
return null;
15181522
}
15191523

1520-
const nearDistance: any = null;
15211524
const nearBy: any = null;
15221525
for (let i = 0, l = children.size; i < l; i++) {
15231526
let child = children.get(i);

packages/designer/src/builtin-simulator/node-selector/index.tsx

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { Overlay } from '@alifd/next';
2-
import React from 'react';
2+
import React, { MouseEvent } from 'react';
33
import { Title, globalContext } from '@alilc/lowcode-editor-core';
44
import { canClickNode } from '@alilc/lowcode-utils';
55
import './index.less';
66

7-
import { Node, INode } from '@alilc/lowcode-designer';
7+
import { INode } from '@alilc/lowcode-designer';
88

99
const { Popup } = Overlay;
1010

1111
export interface IProps {
12-
node: Node;
12+
node: INode;
1313
}
1414

1515
export interface IState {
16-
parentNodes: Node[];
16+
parentNodes: INode[];
1717
}
1818

1919
type UnionNode = INode | null;
@@ -26,14 +26,18 @@ export default class InstanceNodeSelector extends React.Component<IProps, IState
2626
componentDidMount() {
2727
const parentNodes = this.getParentNodes(this.props.node);
2828
this.setState({
29-
parentNodes,
29+
parentNodes: parentNodes ?? [],
3030
});
3131
}
3232

3333
// 获取节点的父级节点(最多获取 5 层)
34-
getParentNodes = (node: Node) => {
34+
getParentNodes = (node: INode) => {
3535
const parentNodes: any[] = [];
36-
const { focusNode } = node.document;
36+
const focusNode = node.document?.focusNode;
37+
38+
if (!focusNode) {
39+
return null;
40+
}
3741

3842
if (node.contains(focusNode) || !focusNode.contains(node)) {
3943
return parentNodes;
@@ -53,12 +57,12 @@ export default class InstanceNodeSelector extends React.Component<IProps, IState
5357
return parentNodes;
5458
};
5559

56-
onSelect = (node: Node) => (e: unknown) => {
60+
onSelect = (node: INode) => (event: MouseEvent) => {
5761
if (!node) {
5862
return;
5963
}
6064

61-
const canClick = canClickNode(node, e as MouseEvent);
65+
const canClick = canClickNode(node.internalToShellNode()!, event);
6266

6367
if (canClick && typeof node.select === 'function') {
6468
node.select();
@@ -76,19 +80,19 @@ export default class InstanceNodeSelector extends React.Component<IProps, IState
7680
}
7781
};
7882

79-
onMouseOver = (node: Node) => (_: any, flag = true) => {
83+
onMouseOver = (node: INode) => (_: any, flag = true) => {
8084
if (node && typeof node.hover === 'function') {
8185
node.hover(flag);
8286
}
8387
};
8488

85-
onMouseOut = (node: Node) => (_: any, flag = false) => {
89+
onMouseOut = (node: INode) => (_: any, flag = false) => {
8690
if (node && typeof node.hover === 'function') {
8791
node.hover(flag);
8892
}
8993
};
9094

91-
renderNodes = (/* node: Node */) => {
95+
renderNodes = () => {
9296
const nodes = this.state.parentNodes;
9397
if (!nodes || nodes.length < 1) {
9498
return null;
@@ -136,7 +140,7 @@ export default class InstanceNodeSelector extends React.Component<IProps, IState
136140
triggerType="hover"
137141
offset={[0, 0]}
138142
>
139-
<div className="instance-node-selector">{this.renderNodes(node)}</div>
143+
<div className="instance-node-selector">{this.renderNodes()}</div>
140144
</Popup>
141145
</div>
142146
);

0 commit comments

Comments
 (0)