GeezerVison is showing github.com — refactor: reorganize types · SuJunming/lowcode-engine@c4bfeaa
File treeExpand file treeCollapse file tree Open diff view settings modules/code-generator/src plugin-outline-pane/src/controllers rax-simulator-renderer/src react-simulator-renderer/src
Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .eslintrc.js +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -41,5 +41,12 @@ module.exports = { | 41 | 41 | '@typescript-eslint/dot-notation': 0, // for lint performance | 42 | 42 | '@typescript-eslint/restrict-plus-operands': 0, // for lint performance | 43 | 43 | '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 | + }], | 44 | 51 | } | 45 | 52 | }; |
Collapse file Copy file name to clipboardExpand all lines: modules/code-generator/src/parser/SchemaParser.ts +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 5 | 5 | import changeCase from 'change-case'; | 6 | 6 | import { | 7 | 7 | IPublicTypeUtilItem, | 8 | | - NodeDataType, | | 8 | + IPublicTypeNodeDataType, | 9 | 9 | IPublicTypeNodeSchema, | 10 | 10 | IPublicTypeContainerSchema, | 11 | 11 | IPublicTypeProjectSchema, | @@ -81,7 +81,7 @@ function processChildren(schema: IPublicTypeNodeSchema): void { | 81 | 81 | if (nodeProps.children) { | 82 | 82 | if (!schema.children) { | 83 | 83 | // eslint-disable-next-line no-param-reassign | 84 | | - schema.children = nodeProps.children as NodeDataType; | | 84 | + schema.children = nodeProps.children as IPublicTypeNodeDataType; | 85 | 85 | } else { | 86 | 86 | let _children: IPublicTypeNodeData[] = []; | 87 | 87 |
| @@ -331,7 +331,7 @@ export class SchemaParser implements ISchemaParser { | 331 | 331 | }; | 332 | 332 | } | 333 | 333 |
| 334 | | - getComponentNames(children: NodeDataType): string[] { | | 334 | + getComponentNames(children: IPublicTypeNodeDataType): string[] { | 335 | 335 | return handleSubNodes<string>( | 336 | 336 | children, | 337 | 337 | { | |
Collapse file Copy file name to clipboardExpand all lines: modules/code-generator/src/types/core.ts +12-7Lines changed: 12 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 5 | 5 | IPublicTypeCompositeObject, | 6 | 6 | ResultDir, | 7 | 7 | ResultFile, | 8 | | - NodeDataType, | | 8 | + IPublicTypeNodeDataType, | 9 | 9 | IPublicTypeProjectSchema, | 10 | 10 | IPublicTypeJSExpression, | 11 | 11 | IPublicTypeJSFunction, | @@ -65,7 +65,10 @@ export interface ICodeStruct extends IBaseCodeStruct { | 65 | 65 |
| 66 | 66 | /** 上下文数据,用来在插件之间共享一些数据 */ | 67 | 67 | export interface IContextData extends IProjectBuilderOptions { | 68 | | - /** 是否使用了 Ref 的 API (this.$/this.$$) */ | | 68 | + | | 69 | + /** | | 70 | + * 是否使用了 Ref 的 API (this.$/this.$$) | | 71 | + * */ | 69 | 72 | useRefApi?: boolean; | 70 | 73 |
| 71 | 74 | /** | @@ -108,6 +111,7 @@ export interface IModuleBuilder { | 108 | 111 | * @interface ICodeGenerator | 109 | 112 | */ | 110 | 113 | export interface ICodeGenerator { | | 114 | + | 111 | 115 | /** | 112 | 116 | * 出码接口,把 Schema 转换成代码文件系统描述 | 113 | 117 | * | @@ -138,26 +142,27 @@ export interface IProjectPlugins { | 138 | 142 | } | 139 | 143 |
| 140 | 144 | export interface IProjectBuilderOptions { | 141 | | - /** 是否处于严格模式(默认: 否) */ | | 145 | + | | 146 | + /** 是否处于严格模式 (默认:否) */ | 142 | 147 | inStrictMode?: boolean; | 143 | 148 |
| 144 | 149 | /** | 145 | 150 | * 是否要容忍对 JSExpression 求值时的异常 | 146 | 151 | * 默认:true | 147 | | - * 注: 如果容忍异常,则会在求值时包裹 try-catch 块, | | 152 | + * 注:如果容忍异常,则会在求值时包裹 try-catch 块, | 148 | 153 | * catch 到异常时默认会抛出一个 CustomEvent 事件里面包含异常信息和求值的表达式 | 149 | 154 | */ | 150 | 155 | tolerateEvalErrors?: boolean; | 151 | 156 |
| 152 | 157 | /** | 153 | 158 | * 容忍异常的时候的的错误处理语句块 | 154 | | - * 默认: 无 | | 159 | + * 默认:无 | 155 | 160 | * 您可以设置为一个语句块,比如: | 156 | 161 | * window.dispatchEvent(new CustomEvent('lowcode-eval-error', { error, expr })) | 157 | 162 | * | 158 | 163 | * 一般可以结合埋点监控模块用来监控求值异常 | 159 | 164 | * | 160 | | - * 其中: | | 165 | + * 其中: | 161 | 166 | * - error: 异常信息 | 162 | 167 | * - expr: 求值的表达式 | 163 | 168 | */ | @@ -205,7 +210,7 @@ type CompositeTypeGenerator<I, T> = | 205 | 210 | | BaseGenerator<I, T, CompositeValueGeneratorOptions> | 206 | 211 | | Array<BaseGenerator<I, T, CompositeValueGeneratorOptions>>; | 207 | 212 |
| 208 | | -export type NodeGenerator<T> = (nodeItem: NodeDataType, scope: IScope) => T; | | 213 | +export type NodeGenerator<T> = (nodeItem: IPublicTypeNodeDataType, scope: IScope) => T; | 209 | 214 |
| 210 | 215 | // FIXME: 在新的实现中,添加了第一参数 this: CustomHandlerSet 作为上下文。究其本质 | 211 | 216 | // scopeBindings?: IScopeBindings; | |
Collapse file Copy file name to clipboardExpand all lines: modules/code-generator/src/utils/nodeToJSX.ts +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import _ from 'lodash'; | 2 | 2 | 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'; | 4 | 4 |
| 5 | 5 | import { | 6 | 6 | IScope, | @@ -365,7 +365,7 @@ export function generateReactExprInJS( | 365 | 365 | const handleChildren = (v: string[]) => v.join(''); | 366 | 366 |
| 367 | 367 | export function createNodeGenerator(cfg: NodeGeneratorConfig = {}): NodeGenerator<string> { | 368 | | - const generateNode = (nodeItem: NodeDataType, scope: IScope): string => { | | 368 | + const generateNode = (nodeItem: IPublicTypeNodeDataType, scope: IScope): string => { | 369 | 369 | if (_.isArray(nodeItem)) { | 370 | 370 | const resList = nodeItem.map((n) => generateNode(n, scope)); | 371 | 371 | return handleChildren(resList); | @@ -390,7 +390,7 @@ export function createNodeGenerator(cfg: NodeGeneratorConfig = {}): NodeGenerato | 390 | 390 | return `{${valueStr}}`; | 391 | 391 | }; | 392 | 392 |
| 393 | | - return (nodeItem: NodeDataType, scope: IScope) => unwrapJsExprQuoteInJsx(generateNode(nodeItem, scope)); | | 393 | + return (nodeItem: IPublicTypeNodeDataType, scope: IScope) => unwrapJsExprQuoteInJsx(generateNode(nodeItem, scope)); | 394 | 394 | } | 395 | 395 |
| 396 | 396 | const defaultReactGeneratorConfig: NodeGeneratorConfig = { | |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/builtin-simulator/bem-tools/border-detecting.tsx -3Lines changed: 0 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -6,7 +6,6 @@ import { getClosestNode } from '@alilc/lowcode-utils'; | 6 | 6 | import { intl } from '../../locale'; | 7 | 7 | import { BuiltinSimulatorHost } from '../host'; | 8 | 8 |
| 9 | | - | 10 | 9 | export class BorderDetectingInstance extends PureComponent<{ | 11 | 10 | title: IPublicTypeTitleContent; | 12 | 11 | rect: DOMRect | null; | @@ -77,11 +76,9 @@ export class BorderDetecting extends Component<{ host: BuiltinSimulatorHost }> { | 77 | 76 | const { host } = this.props; | 78 | 77 | const { current } = this; | 79 | 78 |
| 80 | | - | 81 | 79 | const canHoverHook = current?.componentMeta.getMetadata()?.configure.advanced?.callbacks?.onHoverHook; | 82 | 80 | const canHover = (canHoverHook && typeof canHoverHook === 'function') ? canHoverHook(current.internalToShellNode()) : true; | 83 | 81 |
| 84 | | - | 85 | 82 | if (!canHover || !current || host.viewport.scrolling || host.liveEditing.editing) { | 86 | 83 | return null; | 87 | 84 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/builtin-simulator/host.ts +10-11Lines changed: 10 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -57,7 +57,7 @@ import { | 57 | 57 | IPublicEnumTransitionType, | 58 | 58 | IPublicEnumDragObjectType, | 59 | 59 | IPublicTypeDragNodeObject, | 60 | | - NodeInstance, | | 60 | + IPublicTypeNodeInstance, | 61 | 61 | IPublicTypeComponentInstance, | 62 | 62 | IPublicTypeLocationChildrenDetail, | 63 | 63 | IPublicTypeLocationDetailType, | @@ -173,7 +173,6 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp | 173 | 173 |
| 174 | 174 | readonly emitter: IEventBus = createModuleEventBus('BuiltinSimulatorHost'); | 175 | 175 |
| 176 | | - | 177 | 176 | readonly componentsConsumer: ResourceConsumer; | 178 | 177 |
| 179 | 178 | readonly injectionConsumer: ResourceConsumer; | @@ -898,7 +897,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp | 898 | 897 | /** | 899 | 898 | * @see ISimulator | 900 | 899 | */ | 901 | | - getComponentInstances(node: Node, context?: NodeInstance): IPublicTypeComponentInstance[] | null { | | 900 | + getComponentInstances(node: Node, context?: IPublicTypeNodeInstance): IPublicTypeComponentInstance[] | null { | 902 | 901 | const docId = node.document.id; | 903 | 902 |
| 904 | 903 | const instances = this.instancesMap[docId]?.get(node.id) || null; | @@ -925,7 +924,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp | 925 | 924 | getClosestNodeInstance( | 926 | 925 | from: IPublicTypeComponentInstance, | 927 | 926 | specId?: string, | 928 | | - ): NodeInstance<IPublicTypeComponentInstance> | null { | | 927 | + ): IPublicTypeNodeInstance<IPublicTypeComponentInstance> | null { | 929 | 928 | return this.renderer?.getClosestNodeInstance(from, specId) || null; | 930 | 929 | } | 931 | 930 |
| @@ -1028,7 +1027,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp | 1028 | 1027 | /** | 1029 | 1028 | * 通过 DOM 节点获取节点,依赖 simulator 的接口 | 1030 | 1029 | */ | 1031 | | - getNodeInstanceFromElement(target: Element | null): NodeInstance<IPublicTypeComponentInstance> | null { | | 1030 | + getNodeInstanceFromElement(target: Element | null): IPublicTypeNodeInstance<IPublicTypeComponentInstance> | null { | 1032 | 1031 | if (!target) { | 1033 | 1032 | return null; | 1034 | 1033 | } | @@ -1111,14 +1110,14 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp | 1111 | 1110 | private _sensorAvailable = true; | 1112 | 1111 |
| 1113 | 1112 | /** | 1114 | | - * @see ISensor | | 1113 | + * @see IPublicModelSensor | 1115 | 1114 | */ | 1116 | 1115 | get sensorAvailable(): boolean { | 1117 | 1116 | return this._sensorAvailable; | 1118 | 1117 | } | 1119 | 1118 |
| 1120 | 1119 | /** | 1121 | | - * @see ISensor | | 1120 | + * @see IPublicModelSensor | 1122 | 1121 | */ | 1123 | 1122 | fixEvent(e: ILocateEvent): ILocateEvent { | 1124 | 1123 | if (e.fixed) { | @@ -1149,7 +1148,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp | 1149 | 1148 | } | 1150 | 1149 |
| 1151 | 1150 | /** | 1152 | | - * @see ISensor | | 1151 | + * @see IPublicModelSensor | 1153 | 1152 | */ | 1154 | 1153 | isEnter(e: ILocateEvent): boolean { | 1155 | 1154 | const rect = this.viewport.bounds; | @@ -1164,7 +1163,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp | 1164 | 1163 | private sensing = false; | 1165 | 1164 |
| 1166 | 1165 | /** | 1167 | | - * @see ISensor | | 1166 | + * @see IPublicModelSensor | 1168 | 1167 | */ | 1169 | 1168 | deactiveSensor() { | 1170 | 1169 | this.sensing = false; | @@ -1174,7 +1173,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp | 1174 | 1173 | // ========= drag location logic: helper for locate ========== | 1175 | 1174 |
| 1176 | 1175 | /** | 1177 | | - * @see ISensor | | 1176 | + * @see IPublicModelSensor | 1178 | 1177 | */ | 1179 | 1178 | locate(e: ILocateEvent): any { | 1180 | 1179 | const { dragObject } = e; | @@ -1372,7 +1371,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp | 1372 | 1371 | const document = this.project.currentDocument!; | 1373 | 1372 | const { currentRoot } = document; | 1374 | 1373 | let container: INode; | 1375 | | - let nodeInstance: NodeInstance<IPublicTypeComponentInstance> | undefined; | | 1374 | + let nodeInstance: IPublicTypeNodeInstance<IPublicTypeComponentInstance> | undefined; | 1376 | 1375 |
| 1377 | 1376 | if (target) { | 1378 | 1377 | const ref = this.getNodeInstanceFromElement(target); | |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/builtin-simulator/live-editing/live-editing.ts -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -214,7 +214,6 @@ function selectRange(doc: Document, range: Range) { | 214 | 214 | } | 215 | 215 | } | 216 | 216 |
| 217 | | - | 218 | 217 | function queryPropElement(rootElement: HTMLElement, targetElement: HTMLElement, selector?: string) { | 219 | 218 | if (!selector) { | 220 | 219 | return null; | |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/builtin-simulator/renderer.ts +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { Component } from '../simulator'; | 2 | | -import { IPublicTypeNodeSchema, IPublicTypeComponentInstance, NodeInstance } from '@alilc/lowcode-types'; | | 2 | +import { IPublicTypeNodeSchema, IPublicTypeComponentInstance, IPublicTypeNodeInstance } from '@alilc/lowcode-types'; | 3 | 3 |
| 4 | 4 | export interface BuiltinSimulatorRenderer { | 5 | 5 | readonly isSimulatorRenderer: true; | @@ -8,7 +8,7 @@ export interface BuiltinSimulatorRenderer { | 8 | 8 | getClosestNodeInstance( | 9 | 9 | from: IPublicTypeComponentInstance, | 10 | 10 | nodeId?: string, | 11 | | - ): NodeInstance<IPublicTypeComponentInstance> | null; | | 11 | + ): IPublicTypeNodeInstance<IPublicTypeComponentInstance> | null; | 12 | 12 | findDOMNodes(instance: IPublicTypeComponentInstance): Array<Element | Text> | null; | 13 | 13 | getClientRects(element: Element | Text): DOMRect[]; | 14 | 14 | setNativeSelection(enableFlag: boolean): void; | |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/designer/clipboard.ts -15Lines changed: 0 additions & 15 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,23 +18,8 @@ function getDataFromPasteEvent(event: ClipboardEvent) { | 18 | 18 | }; | 19 | 19 | } | 20 | 20 | } 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 | | - */ | 31 | 21 | // TODO: open the parser implement | 32 | 22 | return { }; | 33 | | - /* | 34 | | - return { | 35 | | - code: clipboardData.getData('text/plain'), | 36 | | - maps: {}, | 37 | | - }; */ | 38 | 23 | } | 39 | 24 | } | 40 | 25 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/designer/designer.ts +13-1Lines changed: 13 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,10 +13,12 @@ import { | 13 | 13 | IShellModelFactory, | 14 | 14 | IPublicModelDragObject, | 15 | 15 | IPublicModelScrollable, | 16 | | - IDesigner, | 17 | 16 | IPublicModelScroller, | 18 | 17 | IPublicTypeLocationData, | 19 | 18 | IPublicEnumTransformStage, | | 19 | + IPublicModelDragon, | | 20 | + IPublicModelActiveTracker, | | 21 | + IPublicModelDropLocation, | 20 | 22 | } from '@alilc/lowcode-types'; | 21 | 23 | import { megreAssets, IPublicTypeAssetsJson, isNodeSchema, isDragNodeObject, isDragNodeDataObject, isLocationChildrenDetail, Logger } from '@alilc/lowcode-utils'; | 22 | 24 | import { Project } from '../project'; | @@ -57,6 +59,16 @@ export interface DesignerProps { | 57 | 59 | [key: string]: any; | 58 | 60 | } | 59 | 61 |
| | 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 | +} | 60 | 72 |
| 61 | 73 | export class Designer implements IDesigner { | 62 | 74 | dragon: Dragon; | |
|