Skip to content

Commit 5129992

Browse files
authored
fixes absolute positioning and loading issues in some cases (#73)
1 parent fda38d3 commit 5129992

6 files changed

Lines changed: 35 additions & 14 deletions

File tree

ember-tui-demo/app/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ async function startApp() {
114114
if (!process.env.VITEST || process.env.TEST_MODE) {
115115
startApp()
116116
.then(() => {
117-
console.error('[main] App started successfully, entering event loop');
117+
// console.error('[main] App started successfully, entering event loop');
118118
// Start rendering to terminal
119119
})
120120
.catch((error) => {

ember-tui/src/components/Box.gts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ export default class Box extends Component<BoxSignature> {
9898
align-items={{@alignItems}}
9999
align-self={{@alignSelf}}
100100
justify-content={{@justifyContent}}
101+
position={{@position}}
102+
top={{@top}}
103+
bottom={{@bottom}}
104+
left={{@left}}
105+
right={{@right}}
101106
width={{@width}}
102107
height={{@height}}
103108
min-width={{@minWidth}}

ember-tui/src/components/InspectorSupport.gts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default class InspectorSupport extends Component<InspectorSupportInterfac
4040
(this.highlight as any).style = {};
4141
_showHighlight.call(this, node, rect);
4242
this.highlight.setAttribute('display', 'flex');
43-
const layout = node.yogaNode!.getComputedLayout();
43+
const layout = rect;
4444
this.highlight.setAttribute(
4545
'left',
4646
layout.left,
@@ -86,9 +86,9 @@ export default class InspectorSupport extends Component<InspectorSupportInterfac
8686
}.bind(this),
8787
);
8888
<template>
89+
<Box @position='absolute' @borderStyle="single" {{this.setupHighlight}} />
90+
<Box @position='absolute' {{this.setupTooltip}} />
8991
<Box @position='absolute' {{ref this 'page'}}>
90-
<Box @borderStyle="single" {{this.setupHighlight}} />
91-
<Box {{this.setupTooltip}} />
9292
{{(this.setupInspector)}}
9393
</Box>
9494
</template>

ember-tui/src/dom/nodes/ViewNode.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,27 @@ export default class ViewNode<Attributes = any> {
318318
height: number;
319319
} | null {
320320
if (this.yogaNode) {
321-
/*return {
322-
left: this.yogaNode.getComputedLeft(),
323-
top: this.yogaNode.getComputedTop(),
324-
bottom: this.yogaNode.getComputedBottom(),
325-
width: this.yogaNode.getComputedWidth(),
326-
height: this.yogaNode.getComputedHeight()
327-
}*/
321+
let left = 0;
322+
let top = 0;
323+
324+
// Traverse up the parent chain to calculate absolute position
325+
let current = this.yogaNode as typeof this.yogaNode | null;
326+
while (current) {
327+
const layout = current.getComputedLayout();
328+
left += layout.left;
329+
top += layout.top;
330+
current = current.getParent();
331+
}
332+
333+
const layout = this.yogaNode.getComputedLayout();
334+
335+
return {
336+
left: left,
337+
top: top,
338+
bottom: top + layout.height,
339+
width: layout.width,
340+
height: layout.height
341+
};
328342
}
329343
return null;
330344
}

ember-tui/src/dom/styles.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,13 @@ const applyPositionStyles = (node: YogaNode, style: Styles): void => {
349349
node.setPosition(Yoga.EDGE_TOP, style['top'] as number || 0);
350350
}
351351
if ('bottom' in style) {
352-
node.setPosition(Yoga.EDGE_TOP, style['bottom'] as number || 0);
352+
node.setPosition(Yoga.EDGE_BOTTOM, style['bottom'] as number || 0);
353353
}
354354
if ('left' in style) {
355-
node.setPosition(Yoga.EDGE_TOP, style['left'] as number || 0);
355+
node.setPosition(Yoga.EDGE_LEFT, style['left'] as number || 0);
356356
}
357357
if ('right' in style) {
358-
node.setPosition(Yoga.EDGE_TOP, style['right'] as number || 0);
358+
node.setPosition(Yoga.EDGE_RIGHT, style['right'] as number || 0);
359359
}
360360

361361
};

ember-tui/src/loader-utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ export async function transformCode(
161161
export function shouldTransformFile(filePath: string): boolean {
162162
return (
163163
!filePath.includes('node_modules') ||
164+
filePath.includes('@embroider/macros') ||
165+
filePath.includes('@embroider/router') ||
164166
filePath.includes('.embroider') ||
165167
filePath.includes('-embroider-') ||
166168
filePath.includes('/ember-source/') ||

0 commit comments

Comments
 (0)