Skip to content

Commit 7ea1a88

Browse files
committed
Cleanup
1 parent 2897bd1 commit 7ea1a88

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

packages/debugger/src/locator/element-overlay.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,36 @@ export function createElementsOverlay<TEl extends object>(
1414
const component = () => active() ? componentRaw() : null
1515

1616
const name = () => component()?.name
17-
17+
1818
const rect = s.createMemo((prev: Rect) => {
1919
let comp = component()
2020
if (comp === null) return prev
21-
21+
2222
let rect = eli.getRect(comp.element)
2323
if (rect === null) return prev
2424

2525
return rect
2626
}, {x: 0, y: 0, w: 0, h: 0})
27-
27+
2828
const transform = () => `translate(${Math.round(rect().x)}px, ${Math.round(rect().y)}px)`
2929
const placeOnTop = () => rect().y > window.innerHeight / 2
3030

3131
const tag = () => {
3232
let comp = component()
3333
if (comp === null) return UNKNOWN
34-
34+
3535
return eli.getName(comp.element) ?? UNKNOWN
3636
}
37-
37+
3838
return (
3939
<>
4040
<style>{styles}</style>
4141
<div
4242
class="element-overlay"
4343
style={{
4444
transform: transform(),
45-
width: rect().w + 'px',
46-
height: rect().h + 'px',
45+
width: rect().width + 'px',
46+
height: rect().height + 'px',
4747
}}
4848
>
4949
<div class="border" />

packages/debugger/src/locator/locator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ const LOC_ATTR_REGEX_UNIX =
3939

4040
export const LOC_ATTR_REGEX = isWindows ? LOC_ATTR_REGEX_WIN : LOC_ATTR_REGEX_UNIX
4141

42-
export function getLocationAttr(element: Element): LocationAttr | undefined {
43-
const attr = element.getAttribute(LOCATION_ATTRIBUTE_NAME)
44-
if (!attr || !LOC_ATTR_REGEX.test(attr)) return
42+
export function getLocationAttr(element: Element): LocationAttr | null {
43+
let attr = element.getAttribute(LOCATION_ATTRIBUTE_NAME)
44+
if (!attr || !LOC_ATTR_REGEX.test(attr)) return null
4545
return attr as LocationAttr
4646
}
4747

packages/debugger/src/main/types.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ export type SourceLocation = {
137137
}
138138

139139
export type Rect = {
140-
x: number
141-
y: number
142-
w: number
143-
h: number
140+
x: number
141+
y: number
142+
width: number
143+
height: number
144144
}
145145

146146
/**
@@ -149,10 +149,10 @@ export type Rect = {
149149
*/
150150
export type ElementInterface<T extends object> = {
151151
isElement: (obj: object | T) => obj is T,
152+
getElementAt: (e: MouseEvent) => T | null,
152153
getName: (el: T) => string | null,
153154
getChildren: (el: T) => Iterable<T>,
154155
getParent: (el: T) => T | null,
155-
getElementAt: (e: MouseEvent) => T | null,
156156
getLocation: (el: T) => SourceLocation | null,
157157
getRect: (el: T) => Rect | null,
158158
}
@@ -162,18 +162,14 @@ export type ElementInterface<T extends object> = {
162162
*/
163163
export const dom_element_interface: ElementInterface<Element> = {
164164
isElement: obj => obj instanceof Element,
165+
getElementAt: e => e.target as Element | null,
165166
getName: el => el.localName,
166167
getChildren: el => el.children,
167168
getParent: el => el.parentElement,
168-
getElementAt: e => e.target as Element | null,
169+
getRect: el => el.getBoundingClientRect(),
169170
getLocation: el => {
170171
let attr = locator.getLocationAttr(el)
171-
if (attr == null) return null
172-
return locator.parseLocationString(attr) ?? null
173-
},
174-
getRect: el => {
175-
let rect = el.getBoundingClientRect()
176-
return {x: rect.x, y: rect.y, w: rect.width, h: rect.height}
172+
return attr && locator.parseLocationString(attr) || null
177173
},
178174
}
179175

0 commit comments

Comments
 (0)