Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new components/pinia/router panel (#345)
- Loading branch information
1 parent
4e1777f
commit 6359b3e
Showing
73 changed files
with
1,351 additions
and
783 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
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,64 @@ | ||
<script setup lang="ts"> | ||
// This components requires to run in DevTools to render correctly | ||
import { computed, nextTick } from 'vue' | ||
import type { BuiltinLanguage } from 'shiki' | ||
import { renderCodeHighlight } from '~/composables/shiki' | ||
const props = withDefaults( | ||
defineProps<{ | ||
code: string | ||
lang?: BuiltinLanguage | 'text' | ||
lines?: boolean | ||
transformRendered?: (code: string) => string | ||
}>(), | ||
{ | ||
lines: true, | ||
}, | ||
) | ||
const emit = defineEmits(['loaded']) | ||
const rendered = computed(() => { | ||
const result = props.lang === 'text' | ||
? { code: props.code, supported: false } | ||
: renderCodeHighlight(props.code, props.lang) || { code: props.code, supported: false } | ||
if (result.supported && props.transformRendered) | ||
result.code = props.transformRendered(result.code) | ||
if (result.supported) | ||
nextTick(() => emit('loaded')) | ||
return result | ||
}) | ||
</script> | ||
|
||
<template> | ||
<template v-if="lang && rendered.supported"> | ||
<pre | ||
class="code-block" | ||
:class="lines ? 'code-block-lines' : ''" | ||
v-html="rendered.code" | ||
/> | ||
</template> | ||
<template v-else> | ||
<pre | ||
class="code-block" | ||
:class="lines ? 'code-block-lines' : ''" | ||
><pre class="shiki"><code><template v-for="line, _idx in code.split('\n')" :key="_idx"><span class="line" v-text="line" /><br></template></code></pre></pre> | ||
</template> | ||
</template> | ||
|
||
<style> | ||
.code-block-lines .shiki code { | ||
counter-reset: step; | ||
counter-increment: step calc(var(--start, 1) - 1); | ||
} | ||
.code-block-lines .shiki code .line::before { | ||
content: counter(step); | ||
counter-increment: step; | ||
width: 2.5rem; | ||
padding-right: 0.5rem; | ||
margin-right: 0.5rem; | ||
display: inline-block; | ||
text-align: right; | ||
--at-apply: 'text-truegray:50'; | ||
} | ||
</style> |
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,25 @@ | ||
<script setup lang="ts"> | ||
import type { InspectorNodeTag } from '@vue/devtools-kit' | ||
import { VTooltip as vTooltip } from '@vue/devtools-ui' | ||
import { toHex } from '~/utils' | ||
defineProps<{ | ||
tag: InspectorNodeTag | ||
}>() | ||
</script> | ||
|
||
<template> | ||
<span | ||
v-tooltip="{ | ||
content: tag.tooltip, | ||
html: true, | ||
}" | ||
:style="{ | ||
color: `#${toHex(tag.textColor)}`, | ||
backgroundColor: `#${toHex(tag.backgroundColor)}`, | ||
}" | ||
class="ml-2 rounded-sm px-1 text-[0.75rem] leading-snug" | ||
> | ||
{{ tag.label }} | ||
</span> | ||
</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
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
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,57 @@ | ||
<script setup lang="ts"> | ||
import type { ComponentTreeNode } from '@vue/devtools-kit' | ||
import ToggleExpanded from '~/components/basic/ToggleExpanded.vue' | ||
import ComponentTreeViewer from '~/components/tree/TreeViewer.vue' | ||
import NodeTag from '~/components/basic/NodeTag.vue' | ||
import { useToggleExpanded } from '~/composables/toggle-expanded' | ||
import { useSelect } from '~/composables/select' | ||
withDefaults(defineProps<{ | ||
data: ComponentTreeNode[] | ||
depth: number | ||
}>(), { | ||
depth: 0, | ||
}) | ||
const selectedNodeId = defineModel() | ||
const { expanded, toggleExpanded } = useToggleExpanded() | ||
const { select: _select } = useSelect() | ||
function select(id: string) { | ||
selectedNodeId.value = id | ||
} | ||
</script> | ||
|
||
<template> | ||
<div | ||
v-for="(item, index) in data" | ||
:key="index" | ||
> | ||
<div | ||
class="group flex cursor-pointer items-center rounded-1 hover:(bg-primary-300 dark:bg-gray-600)" | ||
:style=" { paddingLeft: `${15 * depth + 4}px` }" | ||
:class="{ 'bg-primary-600! active': selectedNodeId === item.id }" | ||
@click="select(item.id)" | ||
> | ||
<ToggleExpanded | ||
v-if="item?.children?.length" | ||
:value="expanded.includes(item.id)" | ||
class="[.active_&]:op20 group-hover:op20" | ||
@click.stop="toggleExpanded(item.id)" | ||
/> | ||
<!-- placeholder --> | ||
<span v-else pl5 /> | ||
<span font-state-field text-4> | ||
<span class="text-gray-400 dark:text-gray-600 group-hover:(text-white op50) [.active_&]:(op50 text-white!)"><</span> | ||
<span group-hover:text-white class="[.active_&]:(text-white)">{{ item.name }}</span> | ||
<span class="text-gray-400 dark:text-gray-600 group-hover:(text-white op50) [.active_&]:(op50 text-white!)">></span> | ||
</span> | ||
<NodeTag v-for="(_item, index) in item.tags" :key="index" :tag="_item" /> | ||
Check warning on line 49 in packages/applet/src/components/tree/TreeViewer.vue GitHub Actions / lint
|
||
</div> | ||
<div | ||
v-if="item?.children?.length && expanded.includes(item.id)" | ||
> | ||
<ComponentTreeViewer v-model="selectedNodeId" :data="item?.children" :depth="depth + 1" /> | ||
</div> | ||
</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,44 @@ | ||
import { getDevToolsState, onDevToolsStateUpdated } from '@vue/devtools-core' | ||
import type { InjectionKey, Ref } from 'vue' | ||
import { inject, provide, ref } from 'vue' | ||
|
||
import type { AppRecord } from '@vue/devtools-kit' | ||
|
||
export type DevtoolsBridgeAppRecord = Pick<AppRecord, 'name' | 'id' | 'version' | 'routerId' | 'moduleDetectives'> | ||
|
||
const VueDevToolsStateSymbol: InjectionKey<{ | ||
appRecords: Ref<Array<DevtoolsBridgeAppRecord>> | ||
activeAppRecordId: Ref<string> | ||
}> = Symbol('VueDevToolsStateSymbol') | ||
|
||
export function createDevToolsStateContext() { | ||
const appRecords = ref<Array<DevtoolsBridgeAppRecord>>([]) | ||
const activeAppRecordId = ref('') | ||
|
||
getDevToolsState().then((data) => { | ||
appRecords.value = data!.appRecords | ||
activeAppRecordId.value = data!.activeAppRecordId! | ||
}) | ||
|
||
onDevToolsStateUpdated((data) => { | ||
appRecords.value = data.appRecords | ||
activeAppRecordId.value = data.activeAppRecordId! | ||
}) | ||
|
||
provide(VueDevToolsStateSymbol, { | ||
appRecords, | ||
activeAppRecordId, | ||
}) | ||
|
||
return { | ||
appRecords, | ||
activeAppRecordId, | ||
} | ||
} | ||
|
||
export function useDevToolsState() { | ||
return inject(VueDevToolsStateSymbol, { | ||
appRecords: ref([]), | ||
activeAppRecordId: ref(''), | ||
}) | ||
} |
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,27 @@ | ||
import type { InjectionKey, Ref } from 'vue' | ||
import { inject, provide, ref } from 'vue' | ||
|
||
const SelectedSymbolKey: InjectionKey<Ref<string>> = Symbol('SelectedSymbolKey') | ||
|
||
export function createSelectedContext() { | ||
const selected = ref<string>('') | ||
|
||
provide<Ref<string>>(SelectedSymbolKey, selected) | ||
|
||
return { | ||
selected, | ||
} | ||
} | ||
|
||
export function useSelect() { | ||
const selected = inject<Ref<string>>(SelectedSymbolKey, ref(''))! | ||
|
||
function select(value: string) { | ||
selected.value = value | ||
} | ||
|
||
return { | ||
selected, | ||
select, | ||
} | ||
} |
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,54 @@ | ||
import type { BuiltinLanguage, HighlighterCore } from 'shiki' | ||
import { getHighlighterCore } from 'shiki/core' | ||
import getWasm from 'shiki/wasm' | ||
import { shallowRef } from 'vue' | ||
|
||
export const shiki = shallowRef<HighlighterCore>() | ||
|
||
let promise: Promise<any> | null = null | ||
|
||
export function renderCodeHighlight(code: string, lang: BuiltinLanguage | 'text' = 'text') { | ||
if (!promise && !shiki.value) { | ||
// Only loading when needed | ||
promise = getHighlighterCore({ | ||
themes: [ | ||
import('shiki/themes/vitesse-dark.mjs'), | ||
import('shiki/themes/vitesse-light.mjs'), | ||
], | ||
langs: [ | ||
import('shiki/langs/json.mjs'), | ||
import('shiki/langs/yaml.mjs'), | ||
import('shiki/langs/css.mjs'), | ||
import('shiki/langs/javascript.mjs'), | ||
import('shiki/langs/typescript.mjs'), | ||
import('shiki/langs/vue.mjs'), | ||
import('shiki/langs/vue-html.mjs'), | ||
import('shiki/langs/html.mjs'), | ||
import('shiki/langs/diff.mjs'), | ||
import('shiki/langs/shellscript.mjs'), | ||
], | ||
loadWasm: getWasm, | ||
}).then((i) => { | ||
shiki.value = i | ||
}) | ||
} | ||
|
||
const supported = shiki.value?.getLoadedLanguages().includes(lang) | ||
if (!supported) { | ||
return { | ||
code, | ||
supported, | ||
} | ||
} | ||
|
||
return { | ||
code: shiki.value!.codeToHtml(code, { | ||
lang, | ||
themes: { | ||
dark: 'vitesse-dark', | ||
light: 'vitesse-light', | ||
}, | ||
}), | ||
supported: true, | ||
} | ||
} |
Oops, something went wrong.