Browse Source

fix(nc-gui): use withDefaults insted of directly assigning default props value in defineProps call

pull/7855/head
Ramesh Mane 7 months ago
parent
commit
4058f34dc2
  1. 28
      packages/nc-gui/components/monaco/Editor.vue

28
packages/nc-gui/components/monaco/Editor.vue

@ -15,28 +15,30 @@ interface Props {
autoFocus?: boolean
}
const {
hideMinimap,
lang = 'json',
validate = true,
disableDeepCompare = false,
readOnly,
autoFocus = true,
modelValue = '',
} = defineProps<Props>()
const props = withDefaults(defineProps<Props>(), {
modelValue: '',
lang: 'json',
validate: true,
disableDeepCompare: false,
autoFocus: true,
})
const { modelValue } = toRefs(props)
const { hideMinimap, lang, validate, disableDeepCompare, readOnly, autoFocus } = props
const emits = defineEmits(['update:modelValue'])
const vModel = computed<string>({
get: () => {
if (typeof modelValue === 'object') {
return JSON.stringify(modelValue, null, 2)
if (typeof modelValue.value === 'object') {
return JSON.stringify(modelValue.value, null, 2)
} else {
return modelValue
return modelValue.value ?? ''
}
},
set: (newVal: string | Record<string, any>) => {
if (typeof modelValue === 'object') {
if (typeof modelValue.value === 'object') {
try {
emits('update:modelValue', typeof newVal === 'object' ? newVal : JSON.parse(newVal))
} catch (e) {

Loading…
Cancel
Save