Skip to content

Commit e365553

Browse files
committed
docs(playground): support ast tree viewer
1 parent 362c8d1 commit e365553

40 files changed

+1170
-418
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"changelogithub",
2626
"codecov",
2727
"hkern",
28+
"iconify",
2829
"lcov",
2930
"lezer",
3031
"mpath",

docs/.vitepress/components/DropZone.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async function onImportFile(files?: FileList | null) {
4545
const fileContent = await file.text()
4646
4747
if (fileExt !== 'svg') {
48-
return console.log('Expected SVG file, but got ' + fileExt)
48+
return console.log(`Expected SVG file, but got ${fileExt}`)
4949
}
5050
5151
if (!fileContent.trim().length) {

docs/.vitepress/components/Editor/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<script lang="ts" setup>
2+
import { useData } from 'vitepress/client'
23
import { computed } from 'vue'
34
import { Codemirror } from 'vue-codemirror'
4-
import { useData } from 'vitepress/client'
5-
import { githubDark, githubLight } from './theme'
65
import { languages, type SupportLanguage } from './language'
6+
import { githubDark, githubLight } from './theme'
77
import type { Extension } from '@codemirror/state'
88
99
const props = withDefaults(

docs/.vitepress/components/Playground/ActionContainer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts" setup>
2+
import { useFileDialog } from '@vueuse/core'
23
import { VPButton } from 'vitepress/theme'
34
import { useSharedPlaygroundState } from '../../composables/playground'
4-
import { useFileDialog } from '@vueuse/core'
55
66
const {
77
open: openFileDialog,

docs/.vitepress/components/Playground/InputContainer.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { shallowRef } from 'vue'
33
import { useSharedPlaygroundState } from '../../composables/playground'
44
import { InputTab } from '../../constants'
5-
import { ITabItem } from '../ui/tabs'
5+
import type { ITabItem } from '../ui/tabs'
66
77
const { activeInputTab, setActiveInputTab } = useSharedPlaygroundState()
88
@@ -26,8 +26,9 @@ function handleTabsChanage(tabName: string) {
2626
<div class="w-full h-full flex gap-2 flex-col relative">
2727
<Tabs
2828
@change="handleTabsChanage"
29-
class="flex-none"
29+
v-model="activeInputTab"
3030
:options="inputTabOptions"
31+
class="flex-none"
3132
/>
3233
<div class="h-[calc(100%-60px)]">
3334
<CodeContainer v-if="activeInputTab === InputTab.Code" />

docs/.vitepress/components/Playground/OutputContainer.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import { shallowRef } from 'vue'
33
import { useSharedPlaygroundState } from '../../composables/playground'
44
import { OutputTab } from '../../constants'
5-
import { ITabItem } from '../ui/tabs'
65
import JsonContainer from './JsonContainer.vue'
6+
import type { ITabItem } from '../ui/tabs'
77
88
const { activeOutputTab, setActiveOutputTab } = useSharedPlaygroundState()
99
@@ -27,8 +27,9 @@ function handleTabsChanage(tabName: string) {
2727
<div class="w-full h-full flex gap-2 flex-col relative">
2828
<Tabs
2929
@change="handleTabsChanage"
30-
class="flex-none"
30+
v-model="activeOutputTab"
3131
:options="outputTabOptions"
32+
class="flex-none"
3233
/>
3334
<div class="h-[calc(100%-60px)]">
3435
<JsonContainer v-if="activeOutputTab === OutputTab.Json" />

docs/.vitepress/components/Playground/PreviewContainer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const { code } = useSharedPlaygroundState()
77
<template>
88
<div class="relative w-full h-full">
99
<div
10-
class="max-w-full max-h-full absolute left-1/2 top-1/2 -translate-1/2"
1110
v-html="code"
11+
class="max-w-full max-h-full absolute left-1/2 top-1/2 -translate-1/2"
1212
/>
1313
</div>
1414
</template>

docs/.vitepress/components/Playground/TreeContainer.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ const { astTree } = useSharedPlaygroundState()
55
</script>
66

77
<template>
8-
<div class="relative w-full h-full flex-center">
9-
<h1 class="text-3xl op-70 font-semibold">Todo</h1>
10-
<p v-if="astTree">{{ astTree }}</p>
8+
<div class="relative w-full h-full of-auto">
9+
<AstViewer :value="astTree" />
1110
</div>
1211
</template>

docs/.vitepress/components/Playground/index.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@ import { Panel, PanelGroup, PanelResizeHandle } from 'vue-resizable-panels'
1111
class="panel-group"
1212
>
1313
<Panel
14-
collapsible
1514
class="panel-column"
15+
collapsible
1616
>
1717
<InputContainer />
1818
</Panel>
1919
<PanelResizeHandle class="panel-resize-handle" />
2020
<Panel
21-
collapsible
2221
class="panel-column"
22+
collapsible
2323
>
2424
<OutputContainer />
2525
</Panel>
2626
<PanelResizeHandle class="panel-resize-handle" />
2727
<Panel
28-
collapsible
2928
:min-size="12"
3029
:max-size="24"
3130
:default-size="18"
3231
class="panel-column"
32+
collapsible
3333
>
3434
<ActionContainer />
3535
</Panel>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<script lang="ts" setup>
2+
import './style.css'
3+
import { isNil, isObject } from '@ntnyq/utils'
4+
import { computed } from 'vue'
5+
import type { OnHoverNodeFn } from './types'
6+
7+
const props = defineProps<{
8+
cursorPosition?: number
9+
enableScrolling?: boolean
10+
hideCopyButton?: boolean
11+
onHoverNode?: OnHoverNodeFn
12+
showTokens?: boolean
13+
value: unknown
14+
}>()
15+
16+
const model = computed(() => props.value)
17+
18+
const selectedPath = computed(() => {
19+
if (isNil(props.cursorPosition) || !model.value || !isObject(model.value)) {
20+
return 'ast'
21+
}
22+
return 'ast'
23+
})
24+
</script>
25+
26+
<template>
27+
<div class="ast-list">
28+
<DataRender
29+
:value="model"
30+
:selected-path="selectedPath"
31+
level="ast"
32+
last-element
33+
/>
34+
35+
<CopyButton
36+
v-if="!hideCopyButton"
37+
:value="model"
38+
/>
39+
</div>
40+
</template>

0 commit comments

Comments
 (0)