Skip to content

Commit

Permalink
feat: Perform saving on client side
Browse files Browse the repository at this point in the history
  • Loading branch information
Azurewarth0920 committed Jul 29, 2024
1 parent 8d82035 commit 7b41e0b
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 3 deletions.
8 changes: 8 additions & 0 deletions packages/applet/src/utils/search.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { INFINITY, NAN, NEGATIVE_INFINITY, UNDEFINED, isPlainObject } from '@vue/devtools-kit'
import type { CustomInspectorNode } from '@vue/devtools-kit'

/**
* Searches a key or value in the object, with a maximum deepness
Expand Down Expand Up @@ -132,3 +133,10 @@ function internalSearchArray(array, searchTerm, seen, depth) {
}
return match
}

/**
* Recursively search for target tree Id in nodes and there children
*/
export function getValidNodeId(treeNode: CustomInspectorNode[], targetId?: string) {
return treeNode.some(({ id: treeNodeId, children }) => (children && getValidNodeId(children, targetId)) || treeNodeId === targetId) && (targetId as string)
}
18 changes: 18 additions & 0 deletions packages/client/src/composables/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,21 @@ export function useSelectWithContext(groupId: string, id: string, onSelect?: (id
toggleSelected,
}
}

export function useDefaultSelect() {
const router = useRouter()
const route = useRoute()

function saveSelectedId(id: string) {
router.push({
params: {
id,
},
})
}

return {
saveSelectedId,
savedSelectedId: route.params.id as string,
}
}
5 changes: 5 additions & 0 deletions packages/client/src/pages/components.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Components as ComponentsPanel } from '@vue/devtools-applet'
import '@vue/devtools-applet/style.css'
import { rpc } from '@vue/devtools-core'
import { openInEditor } from '../composables/open-in-editor'
import { useDefaultSelect } from '../composables/select'
function onInspectComponentStart() {
rpc.value.emit('toggle-panel', false)
Expand All @@ -11,12 +12,16 @@ function onInspectComponentStart() {
function onInspectComponentEnd() {
rpc.value.emit('toggle-panel', true)
}
const { saveSelectedId, savedSelectedId } = useDefaultSelect()
</script>

<template>
<ComponentsPanel
:saved-selected-id="savedSelectedId"
@open-in-editor="openInEditor"
@on-inspect-component-start="onInspectComponentStart"
@on-inspect-component-end="onInspectComponentEnd"
@on-select-id="saveSelectedId"
/>
</template>
8 changes: 7 additions & 1 deletion packages/client/src/pages/custom-inspector-tab-view.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { CustomInspector as CustomInspectorPanel } from '@vue/devtools-applet'
import { useDefaultSelect } from '../composables/select'
import '@vue/devtools-applet/style.css'
const route = useRoute()
Expand All @@ -13,6 +14,8 @@ function onLoadError() {
router.replace('/overview')
}, 2000)
}
const { saveSelectedId, savedSelectedId } = useDefaultSelect()
</script>

<template>
Expand All @@ -27,5 +30,8 @@ function onLoadError() {
</p>
</div>
</div>
<CustomInspectorPanel v-else :id="route.params.name" @load-error="onLoadError" />
<CustomInspectorPanel
v-else :id="(route.params.name as string)" :saved-selected-id="savedSelectedId" @load-error="onLoadError"
@on-select-id="saveSelectedId"
/>
</template>
8 changes: 7 additions & 1 deletion packages/client/src/pages/pinia.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<script setup lang="ts">
import { Pinia as PiniaPanel } from '@vue/devtools-applet'
import { useDefaultSelect } from '../composables/select'
import '@vue/devtools-applet/style.css'
const { saveSelectedId, savedSelectedId } = useDefaultSelect()
</script>

<template>
<PiniaPanel />
<PiniaPanel
:saved-selected-id="savedSelectedId"
@on-select-id="saveSelectedId"
/>
</template>
8 changes: 7 additions & 1 deletion packages/client/src/pages/router.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
<script setup lang="ts">
import { Router as RouterPanel, useCustomInspector } from '@vue/devtools-applet'
import { useDefaultSelect } from '../composables/select'
import '@vue/devtools-applet/style.css'
const { registeredInspector } = useCustomInspector()
const { saveSelectedId, savedSelectedId } = useDefaultSelect()
// @ts-expect-error skip type check
const vueRouterInspector = computed(() => registeredInspector.value?.find(item => item.packageName === 'vue-router'))
// @ts-expect-error skip type check
const inspectorId = computed(() => vueRouterInspector.value?.id)
</script>

<template>
<RouterPanel :id="inspectorId" />
<RouterPanel
:id="inspectorId" :saved-selected-id="savedSelectedId"
@on-select-id="saveSelectedId"
/>
</template>

0 comments on commit 7b41e0b

Please sign in to comment.