Skip to content

Commit

Permalink
fix: should use parser.parse to parse the content text when `string…
Browse files Browse the repository at this point in the history
…ified` is disabled
  • Loading branch information
cloydlau committed Aug 12, 2024
1 parent 94f6260 commit ae5e996
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,12 @@ const JsonEditorVue = defineComponent({
const stringifiedComputed = computed(() => conclude([props.stringified, propsGlobal.stringified, true], {
type: Boolean as PropType<boolean>,
}))
let parse = JSON.parse
const onChange = debounce((updatedContent: { json?: any, text?: string }) => {
preventUpdatingContent.value = true
if (!stringifiedComputed.value && updatedContent.text) {
if (jsonEditor.value && !jsonEditor.value.validate()) {
updatedContent.json = JSON.parse(updatedContent.text)
updatedContent.json = parse(updatedContent.text)
}
updatedContent.text = undefined
}
Expand Down Expand Up @@ -173,6 +174,8 @@ const JsonEditorVue = defineComponent({
},
)

parse = initialAttrs.parser?.parse || JSON.parse

jsonEditor.value = new JSONEditor({
target: currentInstance?.$refs.jsonEditorRef as Element,
props: initialAttrs,
Expand Down Expand Up @@ -231,6 +234,7 @@ const JsonEditorVue = defineComponent({
if (newAttrs.onChangeMode || newAttrs['on-change-mode']) {
defaultFunctionAttrs.onChangeMode = onChangeMode
}
parse = (newAttrs.parser as JSON)?.parse || JSON.parse
jsonEditor.value?.updateProps(
Object.getOwnPropertyNames(defaultFunctionAttrs).length > 0
? conclude([newAttrs, defaultFunctionAttrs], {
Expand Down

0 comments on commit ae5e996

Please sign in to comment.