Skip to content

Commit c4bfeaa

Browse files
JackLianliujuping
authored andcommitted
refactor: reorganize types
1 parent b07d33e commit c4bfeaa

File tree

47 files changed

+300
-342
lines changed

Some content is hidden

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

47 files changed

+300
-342
lines changed

.eslintrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,12 @@ module.exports = {
4141
'@typescript-eslint/dot-notation': 0, // for lint performance
4242
'@typescript-eslint/restrict-plus-operands': 0, // for lint performance
4343
'no-unexpected-multiline': 1,
44+
'no-multiple-empty-lines': ['error', { "max": 1 }],
45+
'lines-around-comment': ['error', {
46+
"beforeBlockComment": true,
47+
"afterBlockComment": false,
48+
"afterLineComment": false,
49+
"allowBlockStart": true,
50+
}],
4451
}
4552
};

modules/code-generator/src/parser/SchemaParser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import changeCase from 'change-case';
66
import {
77
IPublicTypeUtilItem,
8-
NodeDataType,
8+
IPublicTypeNodeDataType,
99
IPublicTypeNodeSchema,
1010
IPublicTypeContainerSchema,
1111
IPublicTypeProjectSchema,
@@ -81,7 +81,7 @@ function processChildren(schema: IPublicTypeNodeSchema): void {
8181
if (nodeProps.children) {
8282
if (!schema.children) {
8383
// eslint-disable-next-line no-param-reassign
84-
schema.children = nodeProps.children as NodeDataType;
84+
schema.children = nodeProps.children as IPublicTypeNodeDataType;
8585
} else {
8686
let _children: IPublicTypeNodeData[] = [];
8787

@@ -331,7 +331,7 @@ export class SchemaParser implements ISchemaParser {
331331
};
332332
}
333333

334-
getComponentNames(children: NodeDataType): string[] {
334+
getComponentNames(children: IPublicTypeNodeDataType): string[] {
335335
return handleSubNodes<string>(
336336
children,
337337
{

modules/code-generator/src/types/core.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
IPublicTypeCompositeObject,
66
ResultDir,
77
ResultFile,
8-
NodeDataType,
8+
IPublicTypeNodeDataType,
99
IPublicTypeProjectSchema,
1010
IPublicTypeJSExpression,
1111
IPublicTypeJSFunction,
@@ -65,7 +65,10 @@ export interface ICodeStruct extends IBaseCodeStruct {
6565

6666
/** 上下文数据,用来在插件之间共享一些数据 */
6767
export interface IContextData extends IProjectBuilderOptions {
68-
/** 是否使用了 Ref 的 API (this.$/this.$$) */
68+
69+
/**
70+
* 是否使用了 Ref 的 API (this.$/this.$$)
71+
* */
6972
useRefApi?: boolean;
7073

7174
/**
@@ -108,6 +111,7 @@ export interface IModuleBuilder {
108111
* @interface ICodeGenerator
109112
*/
110113
export interface ICodeGenerator {
114+
111115
/**
112116
* 出码接口,把 Schema 转换成代码文件系统描述
113117
*
@@ -138,26 +142,27 @@ export interface IProjectPlugins {
138142
}
139143

140144
export interface IProjectBuilderOptions {
141-
/** 是否处于严格模式(默认: 否) */
145+
146+
/** 是否处于严格模式 (默认:否) */
142147
inStrictMode?: boolean;
143148

144149
/**
145150
* 是否要容忍对 JSExpression 求值时的异常
146151
* 默认:true
147-
* 注: 如果容忍异常,则会在求值时包裹 try-catch 块,
152+
* 注如果容忍异常,则会在求值时包裹 try-catch 块,
148153
* catch 到异常时默认会抛出一个 CustomEvent 事件里面包含异常信息和求值的表达式
149154
*/
150155
tolerateEvalErrors?: boolean;
151156

152157
/**
153158
* 容忍异常的时候的的错误处理语句块
154-
* 默认:
159+
* 默认
155160
* 您可以设置为一个语句块,比如:
156161
* window.dispatchEvent(new CustomEvent('lowcode-eval-error', { error, expr }))
157162
*
158163
* 一般可以结合埋点监控模块用来监控求值异常
159164
*
160-
* 其中:
165+
* 其中
161166
* - error: 异常信息
162167
* - expr: 求值的表达式
163168
*/
@@ -205,7 +210,7 @@ type CompositeTypeGenerator<I, T> =
205210
| BaseGenerator<I, T, CompositeValueGeneratorOptions>
206211
| Array<BaseGenerator<I, T, CompositeValueGeneratorOptions>>;
207212

208-
export type NodeGenerator<T> = (nodeItem: NodeDataType, scope: IScope) => T;
213+
export type NodeGenerator<T> = (nodeItem: IPublicTypeNodeDataType, scope: IScope) => T;
209214

210215
// FIXME: 在新的实现中,添加了第一参数 this: CustomHandlerSet 作为上下文。究其本质
211216
// scopeBindings?: IScopeBindings;

modules/code-generator/src/utils/nodeToJSX.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import _ from 'lodash';
22
import { pipe } from 'fp-ts/function';
3-
import { IPublicTypeNodeSchema, isNodeSchema, NodeDataType, IPublicTypeCompositeValue } from '@alilc/lowcode-types';
3+
import { IPublicTypeNodeSchema, isNodeSchema, IPublicTypeNodeDataType, IPublicTypeCompositeValue } from '@alilc/lowcode-types';
44

55
import {
66
IScope,
@@ -365,7 +365,7 @@ export function generateReactExprInJS(
365365
const handleChildren = (v: string[]) => v.join('');
366366

367367
export function createNodeGenerator(cfg: NodeGeneratorConfig = {}): NodeGenerator<string> {
368-
const generateNode = (nodeItem: NodeDataType, scope: IScope): string => {
368+
const generateNode = (nodeItem: IPublicTypeNodeDataType, scope: IScope): string => {
369369
if (_.isArray(nodeItem)) {
370370
const resList = nodeItem.map((n) => generateNode(n, scope));
371371
return handleChildren(resList);
@@ -390,7 +390,7 @@ export function createNodeGenerator(cfg: NodeGeneratorConfig = {}): NodeGenerato
390390
return `{${valueStr}}`;
391391
};
392392

393-
return (nodeItem: NodeDataType, scope: IScope) => unwrapJsExprQuoteInJsx(generateNode(nodeItem, scope));
393+
return (nodeItem: IPublicTypeNodeDataType, scope: IScope) => unwrapJsExprQuoteInJsx(generateNode(nodeItem, scope));
394394
}
395395

396396
const defaultReactGeneratorConfig: NodeGeneratorConfig = {

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { getClosestNode } from '@alilc/lowcode-utils';
66
import { intl } from '../../locale';
77
import { BuiltinSimulatorHost } from '../host';
88

9-
109
export class BorderDetectingInstance extends PureComponent<{
1110
title: IPublicTypeTitleContent;
1211
rect: DOMRect | null;
@@ -77,11 +76,9 @@ export class BorderDetecting extends Component<{ host: BuiltinSimulatorHost }> {
7776
const { host } = this.props;
7877
const { current } = this;
7978

80-
8179
const canHoverHook = current?.componentMeta.getMetadata()?.configure.advanced?.callbacks?.onHoverHook;
8280
const canHover = (canHoverHook && typeof canHoverHook === 'function') ? canHoverHook(current.internalToShellNode()) : true;
8381

84-
8582
if (!canHover || !current || host.viewport.scrolling || host.liveEditing.editing) {
8683
return null;
8784
}

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import {
5757
IPublicEnumTransitionType,
5858
IPublicEnumDragObjectType,
5959
IPublicTypeDragNodeObject,
60-
NodeInstance,
60+
IPublicTypeNodeInstance,
6161
IPublicTypeComponentInstance,
6262
IPublicTypeLocationChildrenDetail,
6363
IPublicTypeLocationDetailType,
@@ -173,7 +173,6 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
173173

174174
readonly emitter: IEventBus = createModuleEventBus('BuiltinSimulatorHost');
175175

176-
177176
readonly componentsConsumer: ResourceConsumer;
178177

179178
readonly injectionConsumer: ResourceConsumer;
@@ -898,7 +897,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
898897
/**
899898
* @see ISimulator
900899
*/
901-
getComponentInstances(node: Node, context?: NodeInstance): IPublicTypeComponentInstance[] | null {
900+
getComponentInstances(node: Node, context?: IPublicTypeNodeInstance): IPublicTypeComponentInstance[] | null {
902901
const docId = node.document.id;
903902

904903
const instances = this.instancesMap[docId]?.get(node.id) || null;
@@ -925,7 +924,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
925924
getClosestNodeInstance(
926925
from: IPublicTypeComponentInstance,
927926
specId?: string,
928-
): NodeInstance<IPublicTypeComponentInstance> | null {
927+
): IPublicTypeNodeInstance<IPublicTypeComponentInstance> | null {
929928
return this.renderer?.getClosestNodeInstance(from, specId) || null;
930929
}
931930

@@ -1028,7 +1027,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
10281027
/**
10291028
* 通过 DOM 节点获取节点,依赖 simulator 的接口
10301029
*/
1031-
getNodeInstanceFromElement(target: Element | null): NodeInstance<IPublicTypeComponentInstance> | null {
1030+
getNodeInstanceFromElement(target: Element | null): IPublicTypeNodeInstance<IPublicTypeComponentInstance> | null {
10321031
if (!target) {
10331032
return null;
10341033
}
@@ -1111,14 +1110,14 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
11111110
private _sensorAvailable = true;
11121111

11131112
/**
1114-
* @see ISensor
1113+
* @see IPublicModelSensor
11151114
*/
11161115
get sensorAvailable(): boolean {
11171116
return this._sensorAvailable;
11181117
}
11191118

11201119
/**
1121-
* @see ISensor
1120+
* @see IPublicModelSensor
11221121
*/
11231122
fixEvent(e: ILocateEvent): ILocateEvent {
11241123
if (e.fixed) {
@@ -1149,7 +1148,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
11491148
}
11501149

11511150
/**
1152-
* @see ISensor
1151+
* @see IPublicModelSensor
11531152
*/
11541153
isEnter(e: ILocateEvent): boolean {
11551154
const rect = this.viewport.bounds;
@@ -1164,7 +1163,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
11641163
private sensing = false;
11651164

11661165
/**
1167-
* @see ISensor
1166+
* @see IPublicModelSensor
11681167
*/
11691168
deactiveSensor() {
11701169
this.sensing = false;
@@ -1174,7 +1173,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
11741173
// ========= drag location logic: helper for locate ==========
11751174

11761175
/**
1177-
* @see ISensor
1176+
* @see IPublicModelSensor
11781177
*/
11791178
locate(e: ILocateEvent): any {
11801179
const { dragObject } = e;
@@ -1372,7 +1371,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
13721371
const document = this.project.currentDocument!;
13731372
const { currentRoot } = document;
13741373
let container: INode;
1375-
let nodeInstance: NodeInstance<IPublicTypeComponentInstance> | undefined;
1374+
let nodeInstance: IPublicTypeNodeInstance<IPublicTypeComponentInstance> | undefined;
13761375

13771376
if (target) {
13781377
const ref = this.getNodeInstanceFromElement(target);

packages/designer/src/builtin-simulator/live-editing/live-editing.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ function selectRange(doc: Document, range: Range) {
214214
}
215215
}
216216

217-
218217
function queryPropElement(rootElement: HTMLElement, targetElement: HTMLElement, selector?: string) {
219218
if (!selector) {
220219
return null;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component } from '../simulator';
2-
import { IPublicTypeNodeSchema, IPublicTypeComponentInstance, NodeInstance } from '@alilc/lowcode-types';
2+
import { IPublicTypeNodeSchema, IPublicTypeComponentInstance, IPublicTypeNodeInstance } from '@alilc/lowcode-types';
33

44
export interface BuiltinSimulatorRenderer {
55
readonly isSimulatorRenderer: true;
@@ -8,7 +8,7 @@ export interface BuiltinSimulatorRenderer {
88
getClosestNodeInstance(
99
from: IPublicTypeComponentInstance,
1010
nodeId?: string,
11-
): NodeInstance<IPublicTypeComponentInstance> | null;
11+
): IPublicTypeNodeInstance<IPublicTypeComponentInstance> | null;
1212
findDOMNodes(instance: IPublicTypeComponentInstance): Array<Element | Text> | null;
1313
getClientRects(element: Element | Text): DOMRect[];
1414
setNativeSelection(enableFlag: boolean): void;

packages/designer/src/designer/clipboard.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,8 @@ function getDataFromPasteEvent(event: ClipboardEvent) {
1818
};
1919
}
2020
} catch (error) {
21-
/*
22-
const html = clipboardData.getData('text/html');
23-
if (html !== '') {
24-
// TODO: clear the html
25-
return {
26-
code: '<div dangerouslySetInnerHTML={ __html: html } />',
27-
maps: {},
28-
};
29-
}
30-
*/
3121
// TODO: open the parser implement
3222
return { };
33-
/*
34-
return {
35-
code: clipboardData.getData('text/plain'),
36-
maps: {},
37-
}; */
3823
}
3924
}
4025

packages/designer/src/designer/designer.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import {
1313
IShellModelFactory,
1414
IPublicModelDragObject,
1515
IPublicModelScrollable,
16-
IDesigner,
1716
IPublicModelScroller,
1817
IPublicTypeLocationData,
1918
IPublicEnumTransformStage,
19+
IPublicModelDragon,
20+
IPublicModelActiveTracker,
21+
IPublicModelDropLocation,
2022
} from '@alilc/lowcode-types';
2123
import { megreAssets, IPublicTypeAssetsJson, isNodeSchema, isDragNodeObject, isDragNodeDataObject, isLocationChildrenDetail, Logger } from '@alilc/lowcode-utils';
2224
import { Project } from '../project';
@@ -57,6 +59,16 @@ export interface DesignerProps {
5759
[key: string]: any;
5860
}
5961

62+
export interface IDesigner {
63+
get dragon(): IPublicModelDragon;
64+
get activeTracker(): IPublicModelActiveTracker;
65+
createScroller(scrollable: IPublicModelScrollable): IPublicModelScroller;
66+
67+
/**
68+
* 创建插入位置,考虑放到 dragon 中
69+
*/
70+
createLocation(locationData: IPublicTypeLocationData): IPublicModelDropLocation;
71+
}
6072

6173
export class Designer implements IDesigner {
6274
dragon: Dragon;

0 commit comments

Comments
 (0)