GeezerVison is showing github.com — fix: when designMode is not design, the hidden attribute does not tak… · xzlinux/lowcode-engine@3dd0b6d
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/renderer-core/src/hoc/leaf.tsx +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -367,7 +367,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, { | 367 | 367 | return null; | 368 | 368 | } | 369 | 369 |
| 370 | | - _leaf = _leaf || getNode(componentId); | | 370 | + _leaf = _leaf || getNode?.(componentId); | 371 | 371 | if (_leaf && this.curEventLeaf && _leaf !== this.curEventLeaf) { | 372 | 372 | this.disposeFunctions.forEach((fn) => fn()); | 373 | 373 | this.disposeFunctions = []; | @@ -513,7 +513,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, { | 513 | 513 | } | 514 | 514 |
| 515 | 515 | get leaf(): Node | undefined { | 516 | | - return this.props._leaf || getNode(componentCacheId); | | 516 | + return this.props._leaf || getNode?.(componentCacheId); | 517 | 517 | } | 518 | 518 |
| 519 | 519 | render() { | |
Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/src/renderer/base.tsx -4Lines changed: 0 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -475,10 +475,6 @@ export default function baseRendererFactory(): IBaseRenderComponent { | 475 | 475 | // DesignMode 为 design 情况下,需要进入 leaf Hoc,进行相关事件注册 | 476 | 476 | const displayInHook = engine?.props?.designMode === 'design'; | 477 | 477 |
| 478 | | - if (schema.hidden && !displayInHook) { | 479 | | - return null; | 480 | | - } | 481 | | - | 482 | 478 | if (schema.loop != null) { | 483 | 479 | const loop = parseData(schema.loop, scope); | 484 | 480 | const useLoop = isUseLoop(loop, this._designModeIsDesign); | |
Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/tests/renderer/__snapshots__/renderer.test.tsx.snap +17Lines changed: 17 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1121,3 +1121,20 @@ exports[`JSExpression base props 1`] = ` | 1121 | 1121 | /> | 1122 | 1122 | </div> | 1123 | 1123 | `; | | 1124 | + | | 1125 | +exports[`designMode designMode:default 1`] = ` | | 1126 | +<div | | 1127 | + className="lce-page" | | 1128 | + style={Object {}} | | 1129 | +> | | 1130 | + <div | | 1131 | + className="div-ut" | | 1132 | + forwardRef={[Function]} | | 1133 | + > | | 1134 | + <div | | 1135 | + className="div-ut-children" | | 1136 | + forwardRef={[Function]} | | 1137 | + /> | | 1138 | + </div> | | 1139 | +</div> | | 1140 | +`; |
Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/tests/renderer/renderer.test.tsx +80-1Lines changed: 80 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,7 +7,7 @@ import components from '../utils/components'; | 7 | 7 |
| 8 | 8 | const Renderer = rendererFactory(); | 9 | 9 |
| 10 | | -function getComp(schema, comp = null): Promise<{ | | 10 | +function getComp(schema, comp = null, others = {}): Promise<{ | 11 | 11 | component, | 12 | 12 | inst, | 13 | 13 | }> { | @@ -17,6 +17,7 @@ function getComp(schema, comp = null): Promise<{ | 17 | 17 | <Renderer | 18 | 18 | schema={schema} | 19 | 19 | components={components as any} | | 20 | + {...others} | 20 | 21 | />); | 21 | 22 |
| 22 | 23 | const componentInstance = component.root; | @@ -321,4 +322,82 @@ describe('JSExpression', () => { | 321 | 322 | done(); | 322 | 323 | }); | 323 | 324 | }) | | 325 | +}); | | 326 | + | | 327 | +describe("designMode", () => { | | 328 | + it('designMode:default', (done) => { | | 329 | + const schema = { | | 330 | + componentName: 'Page', | | 331 | + props: {}, | | 332 | + children: [ | | 333 | + { | | 334 | + componentName: "Div", | | 335 | + props: { | | 336 | + className: 'div-ut', | | 337 | + children: [ | | 338 | + { | | 339 | + componentName: "Div", | | 340 | + visible: true, | | 341 | + props: { | | 342 | + className: 'div-ut-children', | | 343 | + } | | 344 | + } | | 345 | + ] | | 346 | + } | | 347 | + } | | 348 | + ] | | 349 | + }; | | 350 | + | | 351 | + getComp(schema, components.Div).then(({ component, inst }) => { | | 352 | + expect(inst.length).toBe(2); | | 353 | + expect(inst[0].props.className).toBe('div-ut'); | | 354 | + expect(inst[1].props.className).toBe('div-ut-children'); | | 355 | + componentSnapshot = component; | | 356 | + done(); | | 357 | + }); | | 358 | + }); | | 359 | + it('designMode:design', (done) => { | | 360 | + const schema = { | | 361 | + componentName: 'Page', | | 362 | + props: {}, | | 363 | + children: [ | | 364 | + { | | 365 | + componentName: "Div", | | 366 | + id: '0', | | 367 | + props: { | | 368 | + className: 'div-ut', | | 369 | + children: [ | | 370 | + { | | 371 | + componentName: "Div", | | 372 | + id: 'hiddenId', | | 373 | + hidden: true, | | 374 | + props: { | | 375 | + className: 'div-ut-children', | | 376 | + } | | 377 | + } | | 378 | + ] | | 379 | + } | | 380 | + } | | 381 | + ] | | 382 | + }; | | 383 | + | | 384 | + getComp(schema, components.Div, { | | 385 | + designMode: 'design', | | 386 | + getNode: (id) => { | | 387 | + if (id === 'hiddenId') { | | 388 | + return { | | 389 | + export() { | | 390 | + return { | | 391 | + hidden: true, | | 392 | + }; | | 393 | + } | | 394 | + } | | 395 | + } | | 396 | + } | | 397 | + }).then(({ component, inst }) => { | | 398 | + expect(inst.length).toBe(1); | | 399 | + expect(inst[0].props.className).toBe('div-ut'); | | 400 | + done(); | | 401 | + }); | | 402 | + }); | 324 | 403 | }) |
|