Skip to content

Commit c5e0901

Browse files
committed
2 parents f9f1efb + 1b0f93a commit c5e0901

File tree

5 files changed

+47
-57
lines changed

5 files changed

+47
-57
lines changed

jsr.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cloydlau/json-editor-vue",
3-
"version": "0.13.0",
3+
"version": "0.13.1",
44
"exports": "./dist/json-editor-vue.mjs",
55
"publish": {
66
"include": [

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "json-editor-vue",
33
"PascalCasedName": "JsonEditorVue",
4-
"version": "0.13.0",
4+
"version": "0.13.1",
55
"private": false,
66
"description": "Vue 2.6/2.7/3 & Nuxt 2/3 isomorphic JSON editor, viewer, formatter and validator.",
77
"author": {

pnpm-lock.yaml

Lines changed: 21 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Component.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ export default defineComponent({
5858
setup(props, { attrs, emit, expose }) {
5959
const currentInstance = getCurrentInstance()?.proxy
6060
const jsonEditor = ref()
61+
const preventUpdatingContent = ref(false)
6162

6263
const onChange = debounce((updatedContent: Content) => {
64+
preventUpdatingContent.value = true
6365
emit(
6466
updateModelValue,
6567
(updatedContent as TextContent).text === undefined
@@ -111,8 +113,9 @@ export default defineComponent({
111113
},
112114
],
113115
{
114-
type: Object,
116+
camelizeObjectKeys: true,
115117
mergeFunction,
118+
type: Object,
116119
},
117120
)
118121

@@ -124,14 +127,21 @@ export default defineComponent({
124127
watch(
125128
() => props[modelValueProp],
126129
(newModelValue: any) => {
127-
jsonEditor.value?.set(
128-
[undefined, ''].includes(newModelValue)
129-
// `undefined` is not accepted by vanilla-jsoneditor
130-
// The default value is `{ text: '' }`
131-
// Only default value can clear the editor
132-
? { text: '' }
133-
: { json: newModelValue },
134-
)
130+
if (preventUpdatingContent.value) {
131+
preventUpdatingContent.value = false
132+
return
133+
}
134+
if (jsonEditor.value) {
135+
// jsonEditor.value.update cannot render new props in json
136+
jsonEditor.value.set(
137+
[undefined, ''].includes(newModelValue)
138+
// `undefined` is not accepted by vanilla-jsoneditor
139+
// The default value is `{ text: '' }`
140+
// Only default value can clear the editor
141+
? { text: '' }
142+
: { json: newModelValue },
143+
)
144+
}
135145
},
136146
{
137147
deep: true,
@@ -165,17 +175,18 @@ export default defineComponent({
165175
onChange?: (...args: any) => unknown
166176
onChangeMode?: (...args: any) => unknown
167177
} = {}
168-
if (newAttrs.onChange) {
178+
if (newAttrs.onChange || newAttrs['on-change']) {
169179
defaultFunctionAttrs.onChange = onChange
170180
}
171-
if (newAttrs.onChangeMode) {
181+
if (newAttrs.onChangeMode || newAttrs['on-change-mode']) {
172182
defaultFunctionAttrs.onChangeMode = onChangeMode
173183
}
174184
jsonEditor.value?.updateProps(
175185
Object.getOwnPropertyNames(defaultFunctionAttrs).length > 0
176186
? conclude([newAttrs, defaultFunctionAttrs], {
177-
type: Object,
187+
camelizeObjectKeys: true,
178188
mergeFunction,
189+
type: Object,
179190
})
180191
: newAttrs,
181192
)

stats.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)