Skip to content

Commit 62adb37

Browse files
committed
feat(components): scroll into component
1 parent ca3cfa0 commit 62adb37

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

packages/app-backend-core/src/index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,26 @@ async function connect () {
203203
}
204204
})
205205

206+
ctx.bridge.on(BridgeEvents.TO_BACK_COMPONENT_SCROLL_TO, async ({ instanceId }) => {
207+
const instance = getComponentInstance(ctx.currentAppRecord, instanceId, ctx)
208+
if (instance) {
209+
const [el] = await ctx.api.getComponentRootElements(instance)
210+
if (el) {
211+
el.scrollIntoView({
212+
behavior: 'smooth',
213+
block: 'center',
214+
inline: 'center'
215+
})
216+
setTimeout(() => {
217+
highlight(instance, ctx)
218+
}, 500)
219+
setTimeout(() => {
220+
unHighlight()
221+
}, 2000)
222+
}
223+
}
224+
})
225+
206226
// Component perf
207227

208228
hook.on(HookEvents.PERFORMANCE_START, (app, uid, vm, type, time) => {

packages/app-frontend/src/features/components/SelectedComponentPane.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,17 @@ export default defineComponent({
3939
class="search flex-1 flat"
4040
/>
4141

42+
<VueButton
43+
v-tooltip="'Scroll to component'"
44+
icon-left="preview"
45+
class="flat icon-button"
46+
@click="scrollToComponent()"
47+
/>
48+
4249
<VueButton
4350
v-if="$isChrome"
4451
v-tooltip="'Inspect DOM'"
45-
icon-left="code"
52+
icon-left="menu_open"
4653
class="flat icon-button"
4754
@click="inspectDOM()"
4855
/>

packages/app-frontend/src/features/components/composable/components.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,21 @@ export function useSelectedComponent () {
216216
})
217217
}
218218

219+
function scrollToComponent () {
220+
bridge.send(BridgeEvents.TO_BACK_COMPONENT_SCROLL_TO, {
221+
instanceId: data.value.id
222+
})
223+
}
224+
219225
return {
220226
data,
221227
state,
222228
stateFilter: selectedComponentStateFilter,
223229
inspectDOM,
224230
fileIsPath,
225231
openFile,
226-
editState
232+
editState,
233+
scrollToComponent
227234
}
228235
}
229236

0 commit comments

Comments
 (0)