-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(devtools): add postList & open in editor
- Loading branch information
Showing
35 changed files
with
370 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# @valaxyjs/devtools | ||
|
||
## Dev | ||
|
||
```bash | ||
# in packages/devtools | ||
pnpm dev | ||
``` | ||
|
||
```bash | ||
# in root | ||
pnpm devtools | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,3 @@ | ||
<script setup lang="ts"> | ||
import { onMounted } from 'vue' | ||
import { isStaticMode } from './utils' | ||
onMounted(() => { | ||
if (isStaticMode) | ||
document.title = 'Vite Inspect (Production)' | ||
}) | ||
</script> | ||
|
||
<template> | ||
<main grid="~ rows-[min-content_1fr]" size="h-screen w-screen" text="gray-700 dark:gray-200"> | ||
<Suspense> | ||
<RouterView /> | ||
<template #fallback> | ||
Loading... | ||
</template> | ||
</Suspense> | ||
</main> | ||
<RouterView /> | ||
</template> |
15 changes: 15 additions & 0 deletions
15
packages/devtools/src/client/components/PageFrontmatter.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<script lang="ts" setup> | ||
defineProps<{ | ||
frontmatter?: object | ||
}>() | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<ul v-if="frontmatter"> | ||
<li v-for="(value, key) in frontmatter" :key="key"> | ||
<strong>{{ key }}</strong>: {{ value }} | ||
</li> | ||
</ul> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<script lang="ts" setup> | ||
import { onMounted, ref } from 'vue' | ||
import type { Router } from 'vue-router/auto' | ||
import { getGlobalValaxyProperty, getWindowProperty, openInEditor } from '../utils' | ||
import { frontmatter } from '../composables/app' | ||
const activePath = ref('') | ||
const __VUE_DEVTOOLS_ROUTER__ = getWindowProperty('__VUE_DEVTOOLS_ROUTER__') as Router | ||
__VUE_DEVTOOLS_ROUTER__.beforeEach((to, _from, next) => { | ||
activePath.value = to.path | ||
frontmatter.value = getWindowProperty('$frontmatter') | ||
next() | ||
}) | ||
const postList = ref() | ||
onMounted(() => { | ||
postList.value = getGlobalValaxyProperty('postList').value | ||
}) | ||
function onClickPost(post: any) { | ||
__VUE_DEVTOOLS_ROUTER__.push(post.path) | ||
} | ||
function launchEditor() { | ||
openInEditor({ | ||
file: getWindowProperty('$pageData').path, | ||
}) | ||
} | ||
</script> | ||
|
||
<template> | ||
<ul class="h-full" overflow="auto" pl="12" pr="4" py="4"> | ||
{{ activePath }} | ||
<li v-for="post in postList" :key="post.path" class="list-decimal"> | ||
<div flex> | ||
<span | ||
class="inline-flex flex-grow cursor-pointer underline hover:text-blue-500" | ||
:class="{ 'text-blue-500': activePath === post.path }" | ||
@click="onClickPost(post)" | ||
> | ||
{{ post.title }} | ||
</span> | ||
<button class="ml-2 text-xs" @click="launchEditor()"> | ||
<div i-vscode-icons:file-type-vscode /> | ||
</button> | ||
</div> | ||
</li> | ||
</ul> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { ref } from 'vue' | ||
|
||
export const frontmatter = ref<object>({}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
// register vue composition api globally | ||
import { createApp } from 'vue' | ||
import { createRouter, createWebHashHistory } from 'vue-router' | ||
import { routes } from 'vue-router/auto/routes' | ||
import { createRouter, createWebHashHistory } from 'vue-router/auto' | ||
import App from './App.vue' | ||
|
||
import '@unocss/reset/tailwind.css' | ||
import 'uno.css' | ||
|
||
import './styles/index.css' | ||
import 'splitpanes/dist/splitpanes.css' | ||
|
||
const app = createApp(App) | ||
|
||
const router = createRouter({ | ||
history: createWebHashHistory(), | ||
routes, | ||
}) | ||
|
||
app.use(router) | ||
app.mount('#app') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<template> | ||
<div> | ||
About | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<template> | ||
<div> | ||
Categories | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,38 @@ | ||
<script lang="ts" setup> | ||
import { Pane, Splitpanes } from 'splitpanes' | ||
import { onMounted } from 'vue' | ||
import { getWindowProperty, isStaticMode } from '../utils' | ||
import type { BlogWindow } from '../types' | ||
import { frontmatter } from '../composables/app' | ||
onMounted(() => { | ||
if (isStaticMode) | ||
document.title = 'Valaxy DevTools (Production)' | ||
const $frontmatter = getWindowProperty('$frontmatter') as BlogWindow['$frontmatter'] | ||
if ($frontmatter) | ||
frontmatter.value = $frontmatter | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div> | ||
Index | ||
</div> | ||
<main class="h-full" flex="~ col" text="gray-700 dark:gray-200"> | ||
<div class="w-full border-b shadow flex justify-end"> | ||
<a href="https://valaxy.site" target="_blank" class="bg-gray-100 inline-flex justify-center items-center w-8 h-8"> | ||
<div i-ri-book-line /> | ||
</a> | ||
</div> | ||
|
||
<div style="height: calc(100% - 32px)" overflow="auto"> | ||
<Splitpanes class="h-full"> | ||
<Pane> | ||
<VDPostList /> | ||
</Pane> | ||
<Pane> | ||
<PageFrontmatter :frontmatter="frontmatter" /> | ||
</Pane> | ||
</Splitpanes> | ||
</div> | ||
</main> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<template> | ||
<div> | ||
Tags | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
html, | ||
body { | ||
height: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface BlogWindow { | ||
$frontmatter: any | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// import from @vue/devtools-api not work | ||
import { getAppWindow } from './get' | ||
|
||
const target = getAppWindow() | ||
|
||
export interface OpenInEditorOptions { | ||
file?: string | ||
line?: number | ||
column?: number | ||
} | ||
|
||
export function openInEditor(options: OpenInEditorOptions = {}) { | ||
const { file, line = 0, column = 0 } = options | ||
if (file) { | ||
const baseUrl = window.location.origin | ||
target?.__VUE_INSPECTOR__.openInEditor(baseUrl, file, line, column) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export function getAppWindow() { | ||
return window.parent.parent as unknown as { | ||
__VUE_INSPECTOR__: { | ||
openInEditor: (baseUrl: string, file: string, line: number, column: number) => void | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* window.parent.parent is the window object of the main app | ||
*/ | ||
export function getWindowProperty(property: string) { | ||
return (window.parent.parent as any)[property] | ||
} | ||
|
||
export function getGlobalValaxyProperty(property: string) { | ||
const $valaxy = (window.parent.parent as any).$valaxy | ||
return $valaxy[property] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
export * from './api' | ||
export * from './get' | ||
|
||
export const isStaticMode = document.body.getAttribute('data-valaxy-devtools-mode') === 'BUILD' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ components.d.ts | |
|
||
# unplugin-vue-router | ||
typed-router.d.ts | ||
|
||
.env.local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.