GeezerVison is showing github.com — feat: fix render-core leaf hoc component condition config should get … · webstager/lowcode-engine@85704c3
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/document/node/props/props.ts +7-3Lines changed: 7 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,6 +5,10 @@ import { Prop, IPropParent, UNSET } from './prop'; | 5 | 5 | import { Node } from '../node'; | 6 | 6 | import { TransformStage } from '../transform-stage'; | 7 | 7 |
| | 8 | +interface ExtrasObject { | | 9 | + [key: string]: any; | | 10 | +} | | 11 | + | 8 | 12 | export const EXTRA_KEY_PREFIX = '___'; | 9 | 13 | export function getConvertedExtraKey(key: string): string { | 10 | 14 | if (!key) { | @@ -53,7 +57,7 @@ export class Props implements IPropParent { | 53 | 57 |
| 54 | 58 | @obx type: 'map' | 'list' = 'map'; | 55 | 59 |
| 56 | | - constructor(owner: Node, value?: PropsMap | PropsList | null, extras?: object) { | | 60 | + constructor(owner: Node, value?: PropsMap | PropsList | null, extras?: ExtrasObject) { | 57 | 61 | makeObservable(this); | 58 | 62 | this.owner = owner; | 59 | 63 | if (Array.isArray(value)) { | @@ -70,7 +74,7 @@ export class Props implements IPropParent { | 70 | 74 | } | 71 | 75 |
| 72 | 76 | @action | 73 | | - import(value?: PropsMap | PropsList | null, extras?: object) { | | 77 | + import(value?: PropsMap | PropsList | null, extras?: ExtrasObject) { | 74 | 78 | const originItems = this.items; | 75 | 79 | if (Array.isArray(value)) { | 76 | 80 | this.type = 'list'; | @@ -104,7 +108,7 @@ export class Props implements IPropParent { | 104 | 108 | } | 105 | 109 | } | 106 | 110 |
| 107 | | - export(stage: TransformStage = TransformStage.Save): { props?: PropsMap | PropsList; extras?: object } { | | 111 | + export(stage: TransformStage = TransformStage.Save): { props?: PropsMap | PropsList; extras?: ExtrasObject } { | 108 | 112 | stage = compatStage(stage); | 109 | 113 | if (this.items.length < 1) { | 110 | 114 | return {}; | |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/document/selection.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -117,7 +117,7 @@ export class Selection { | 117 | 117 | /** | 118 | 118 | * 获取选中的节点 | 119 | 119 | */ | 120 | | - getNodes() { | | 120 | + getNodes(): Node[] { | 121 | 121 | const nodes = []; | 122 | 122 | for (const id of this._selected) { | 123 | 123 | const node = this.doc.getNode(id); | |
Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/jest.config.js +5-13Lines changed: 5 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,23 +14,15 @@ const jestConfig = { | 14 | 14 | transformIgnorePatterns: [ | 15 | 15 | `/node_modules/(?!${esModules})/`, | 16 | 16 | ], | 17 | | - setupFiles: ['./tests/fixtures/unhandled-rejection.ts'], | | 17 | + setupFiles: [ | | 18 | + './tests/fixtures/unhandled-rejection.ts', | | 19 | + './tests/setup.ts', | | 20 | + ], | 18 | 21 | moduleFileExtensions: ['ts', 'tsx', 'js', 'json'], | 19 | 22 | collectCoverage: true, | 20 | 23 | collectCoverageFrom: [ | 21 | 24 | 'src/**/*.ts', | 22 | | - '!src/**/*.d.ts', | 23 | | - '!src/icons/**', | 24 | | - '!src/locale/**', | 25 | | - '!src/builtin-simulator/utils/**', | 26 | | - '!src/plugin/sequencify.ts', | 27 | | - '!src/document/node/exclusive-group.ts', | 28 | | - '!src/document/node/props/value-to-source.ts', | 29 | | - '!src/builtin-simulator/live-editing/live-editing.ts', | 30 | | - '!src/designer/offset-observer.ts', | 31 | | - '!src/designer/clipboard.ts', | 32 | | - '!**/node_modules/**', | 33 | | - '!**/vendor/**', | | 25 | + 'src/**/*.tsx', | 34 | 26 | ], | 35 | 27 | }; | 36 | 28 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/src/hoc/leaf.tsx +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -412,11 +412,12 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, { | 412 | 412 | const node = leaf; | 413 | 413 |
| 414 | 414 | if (key === '___condition___') { | 415 | | - const condition = parseData(newValue, scope); | | 415 | + const { condition = true } = this.leaf?.export(TransformStage.Render) || {}; | | 416 | + const conditionValue = parseData(condition, scope); | 416 | 417 | __debug(`key is ___condition___, change condition value to [${condition}]`); | 417 | 418 | // 条件表达式改变 | 418 | 419 | this.setState({ | 419 | | - condition, | | 420 | + condition: conditionValue, | 420 | 421 | }); | 421 | 422 | return; | 422 | 423 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/src/renderer/renderer.tsx +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -108,6 +108,9 @@ export default function rendererFactory(): IRenderComponent { | 108 | 108 | if (SetComponent.patchedCatch) { | 109 | 109 | return; | 110 | 110 | } | | 111 | + if (!SetComponent.prototype) { | | 112 | + return; | | 113 | + } | 111 | 114 | SetComponent.patchedCatch = true; | 112 | 115 |
| 113 | 116 | // Rax 的 getDerivedStateFromError 有 BUG,这里先用 componentDidCatch 来替代 | |
Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/tests/hoc/__snapshots__/leaf.test.tsx.snap +46Lines changed: 46 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -25,6 +25,52 @@ exports[`leafWrapper base 1`] = ` | 25 | 25 | </div> | 26 | 26 | `; | 27 | 27 |
| | 28 | +exports[`leafWrapper change ___condition___ props 1`] = ` | | 29 | +<div | | 30 | + _leaf={ | | 31 | + Node { | | 32 | + "emitter": EventEmitter { | | 33 | + "_events": Object { | | 34 | + "onChildrenChange": [Function], | | 35 | + "onPropChange": [Function], | | 36 | + "onVisibleChange": [Function], | | 37 | + }, | | 38 | + "_eventsCount": 3, | | 39 | + "_maxListeners": undefined, | | 40 | + Symbol(kCapture): false, | | 41 | + }, | | 42 | + "hasLoop": false, | | 43 | + "schema": Object {}, | | 44 | + } | | 45 | + } | | 46 | +/> | | 47 | +`; | | 48 | + | | 49 | +exports[`leafWrapper change ___condition___ props, but not hidden component 1`] = ` | | 50 | +<div | | 51 | + _leaf={ | | 52 | + Node { | | 53 | + "emitter": EventEmitter { | | 54 | + "_events": Object { | | 55 | + "onChildrenChange": [Function], | | 56 | + "onPropChange": [Function], | | 57 | + "onVisibleChange": [Function], | | 58 | + }, | | 59 | + "_eventsCount": 3, | | 60 | + "_maxListeners": undefined, | | 61 | + Symbol(kCapture): false, | | 62 | + }, | | 63 | + "hasLoop": false, | | 64 | + "schema": Object {}, | | 65 | + } | | 66 | + } | | 67 | +> | | 68 | + <div> | | 69 | + new content | | 70 | + </div> | | 71 | +</div> | | 72 | +`; | | 73 | + | 28 | 74 | exports[`leafWrapper change props 1`] = ` | 29 | 75 | <div | 30 | 76 | _leaf={ | |
Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/tests/hoc/leaf.test.tsx +23-3Lines changed: 23 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -6,7 +6,6 @@ import { leafWrapper } from '../../src/hoc/leaf'; | 6 | 6 | import components from '../utils/components'; | 7 | 7 | import Node from '../utils/node'; | 8 | 8 |
| 9 | | - | 10 | 9 | const baseRenderer: any = { | 11 | 10 | __debug () {}, | 12 | 11 | __getComponentProps (schema: any) { | @@ -71,8 +70,29 @@ describe('leafWrapper', () => { | 71 | 70 | let tree = component.toJSON(); | 72 | 71 | expect(tree).toMatchSnapshot(); | 73 | 72 | }); | 74 | | -}); | 75 | 73 |
| | 74 | + it('change ___condition___ props', () => { | | 75 | + TextNode.schema.condition = false; | | 76 | + TextNode.emitPropChange({ | | 77 | + key: '___condition___', | | 78 | + newValue: false, | | 79 | + } as any); | | 80 | + | | 81 | + let tree = component.toJSON(); | | 82 | + expect(tree).toMatchSnapshot(); | | 83 | + }); | | 84 | + | | 85 | + it('change ___condition___ props, but not hidden component', () => { | | 86 | + TextNode.schema.condition = true; | | 87 | + TextNode.emitPropChange({ | | 88 | + key: '___condition___', | | 89 | + newValue: false, | | 90 | + } as any); | | 91 | + | | 92 | + let tree = component.toJSON(); | | 93 | + expect(tree).toMatchSnapshot(); | | 94 | + }) | | 95 | +}); | 76 | 96 |
| 77 | 97 | describe('loop', () => { | 78 | 98 | const Div = leafWrapper(components.Div as any, { | @@ -105,4 +125,4 @@ describe('loop', () => { | 105 | 125 | <Text _leaf={TextNode} content="content"></Text> | 106 | 126 | </Div> | 107 | 127 | ); | 108 | | -}) | | 128 | +}); |
Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/tests/renderer/renderer.test.tsx +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import React from 'react'; | 2 | | -import renderer from 'react-test-renderer'; | | 2 | +import renderer from 'react-test-renderer/'; | 3 | 3 | import schema from '../fixtures/schema/basic'; | 4 | 4 | import '../utils/react-env-init'; | 5 | 5 | import rendererFactory from '../../src/renderer/renderer'; | |
Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/tests/setup.ts +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,4 +9,9 @@ jest.mock('zen-logger', () => { | 9 | 9 | __esModule: true, | 10 | 10 | default: Logger, | 11 | 11 | }; | 12 | | -}); | | 12 | +}); | | 13 | + | | 14 | +export const mockConsoleWarn = jest.fn(); | | 15 | +console.warn = mockConsoleWarn; | | 16 | + | | 17 | +process.env.NODE_ENV = 'production'; |
Collapse file Copy file name to clipboardExpand all lines: packages/shell/src/selection.ts +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,14 +18,14 @@ export default class Selection { | 18 | 18 | /** | 19 | 19 | * 返回选中的节点 id | 20 | 20 | */ | 21 | | - get selected() { | | 21 | + get selected(): string[] { | 22 | 22 | return this[selectionSymbol].selected; | 23 | 23 | } | 24 | 24 |
| 25 | 25 | /** | 26 | 26 | * return selected Node instance | 27 | 27 | */ | 28 | | - get node() { | | 28 | + get node(): Node { | 29 | 29 | return this.getNodes()[0]; | 30 | 30 | } | 31 | 31 |
| @@ -81,7 +81,7 @@ export default class Selection { | 81 | 81 | * 获取选中的节点实例 | 82 | 82 | * @returns | 83 | 83 | */ | 84 | | - getNodes() { | | 84 | + getNodes(): Node[] { | 85 | 85 | return this[selectionSymbol].getNodes().map((node: InnerNode) => Node.create(node)); | 86 | 86 | } | 87 | 87 | } |
|