Skip to content

Commit

Permalink
feat: enhance state editor (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannchie committed Jul 30, 2023
1 parent b4dfc37 commit ad56f47
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions packages/devtools/client/components/StateEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import JsonEditorVue from 'json-editor-vue'
const props = defineProps<{
name?: string
open?: boolean
state?: Record<string, any>
state?: any
readonly?: boolean
}>()
Expand All @@ -13,14 +13,21 @@ const emit = defineEmits<{
}>()
const isOpen = useVModel(props, 'open', emit, { passive: true })
const colorMode = useColorMode()
const proxy = ref()
proxy.value = JSON.parse(JSON.stringify(props.state))
const state = useState(props.name)
if (props.state)
proxy.value = JSON.parse(JSON.stringify(props.state))
else if (typeof props.state === 'number' || typeof props.state !== 'string')
proxy.value = props.state
const watcher = watchPausable(proxy,
(value) => {
deepSync(value, props.state)
if (typeof value !== 'number' && typeof value !== 'string')
deepSync(value, props.state)
else
state.value = value
},
{ deep: true },
)
Expand Down Expand Up @@ -70,7 +77,6 @@ async function refresh() {
</div>
<template v-if="isOpen || !name">
<JsonEditorVue
v-if="state && Object.keys(state).length > 0"
v-model="proxy"
v-bind="$attrs"
class="json-editor-vue"
Expand All @@ -85,9 +91,6 @@ async function refresh() {
:indentation="2"
:tab-size="2"
/>
<div v-else bg-active p5 italic>
<span op50>No data</span>
</div>
</template>
</div>
</template>

0 comments on commit ad56f47

Please sign in to comment.