Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Changes as per review comment
  • Loading branch information
mauryapari committed Aug 16, 2025
commit 3504c8def264923f533cd2ecbc44c0b697da1698
28 changes: 10 additions & 18 deletions packages/applet/src/modules/components/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -279,28 +279,20 @@ useEventListener('keydown', (event) => {
}
})

onKeyStroke('ArrowRight', handleArrowRight)
onKeyStroke('ArrowLeft', handleArrowLeft)
onKeyStroke('ArrowDown', handleArrowDown)
onKeyStroke('ArrowUp', handleArrowUp)
onKeyStroke([' ', 'Enter'], handleEnter)

function handleArrowRight() {
onKeyStroke('ArrowRight', () => {
const isPresentInExpandedNodes = expandedTreeNodes.value.includes(activeComponentId.value)
const hasChildren = flattenedTreeNodes.value.find(item => item.id === activeComponentId.value)?.children?.length

if (!isPresentInExpandedNodes && hasChildren) {
expandedTreeNodes.value.push(activeComponentId.value)
}
}

function handleArrowLeft() {
})
onKeyStroke('ArrowLeft', () => {
if (expandedTreeNodes.value.includes(activeComponentId.value)) {
expandedTreeNodes.value.splice(expandedTreeNodes.value.indexOf(activeComponentId.value), 1)
}
}

function handleArrowDown() {
})
onKeyStroke('ArrowDown', () => {
const activeComponentIdIndex = flattenedTreeNodesIds.value.indexOf(activeComponentId.value)
const isActiveComponentExpanded = expandedTreeNodes.value.includes(activeComponentId.value)

Expand All @@ -313,9 +305,9 @@ function handleArrowDown() {
else {
activeComponentId.value = getNearestNextNode()
}
}
})

function handleArrowUp() {
onKeyStroke('ArrowUp', () => {
const activeId = activeComponentId.value
const list = treeNodeLinkedList.value.find(item => item.includes(activeId))
if (!list)
Expand All @@ -329,9 +321,9 @@ function handleArrowUp() {
if (element) {
activeComponentId.value = element.id
}
}
})

function handleEnter() {
onKeyStroke([' ', 'Enter'], () => {
const node = flattenedTreeNodes.value.find(item => item.id === activeComponentId.value)
if (!node?.children?.length)
return
Expand All @@ -340,7 +332,7 @@ function handleEnter() {
if (index === -1)
expandedTreeNodes.value.push(activeComponentId.value)
else expandedTreeNodes.value.splice(index, 1)
}
})

function getNearestPreviousNode(parentId: string) {
const parentNode = flattenedTreeNodes.value.find(item => item.id === parentId)
Expand Down
Loading