@@ -61,6 +61,16 @@ export default defineComponent({
61
61
const preventUpdatingContent = ref ( false )
62
62
63
63
const onChange = debounce ( ( updatedContent : Content ) => {
64
+ const computedMode = computed ( ( ) => conclude ( [ props . mode , globalProps . mode ] , {
65
+ type : String as PropType < Mode > ,
66
+ } ) )
67
+ const onChangeMode = ( mode : Mode ) => {
68
+ emit ( 'update:mode' , mode )
69
+ }
70
+ // Synchronize the local `mode` with the global one
71
+ if ( globalProps . mode !== undefined && props . mode === undefined ) {
72
+ onChangeMode ( globalProps . mode )
73
+ }
64
74
preventUpdatingContent . value = true
65
75
emit (
66
76
updateModelValue ,
@@ -70,9 +80,6 @@ export default defineComponent({
70
80
)
71
81
} , 100 )
72
82
73
- const onChangeMode = ( mode : Mode ) => {
74
- emit ( 'update:mode' , mode )
75
- }
76
83
77
84
const mergeFunction = ( previousValue : ( ...args : any ) => unknown , currentValue : ( ...args : any ) => unknown ) => ( ...args : any ) => {
78
85
previousValue ( ...args )
@@ -86,13 +93,6 @@ export default defineComponent({
86
93
} )
87
94
88
95
onMounted ( ( ) => {
89
- const initialMode = conclude ( [ props . mode , globalProps . mode ] , {
90
- type : String as PropType < Mode > ,
91
- } )
92
- if ( globalProps . mode !== undefined && props . mode === undefined ) {
93
- // will trigger watch
94
- onChangeMode ( globalProps . mode )
95
- }
96
96
const initialValue = conclude ( [ props [ modelValueProp ] , globalProps [ modelValueProp ] ] )
97
97
const initialBoolAttrs = Object . fromEntries (
98
98
Array . from ( boolAttrs , boolAttr => [ boolAttr , conclude ( [ props [ boolAttr ] , globalProps [ boolAttr ] ] ) ] ) . filter (
@@ -107,9 +107,9 @@ export default defineComponent({
107
107
{
108
108
onChange,
109
109
onChangeMode,
110
- mode : initialMode ,
110
+ mode : computedMode . value ,
111
111
...( initialValue !== undefined && {
112
- content : { [ typeof initialValue === 'string' ? 'text' : 'json' ] : initialValue } ,
112
+ content : { [ ( typeof initialValue === 'string' && computedMode . value === 'text' ) ? 'text' : 'json' ] : initialValue } ,
113
113
} ) ,
114
114
} ,
115
115
] ,
@@ -140,7 +140,7 @@ export default defineComponent({
140
140
jsonEditor . value . set (
141
141
[ undefined , '' ] . includes ( newModelValue )
142
142
? { text : '' }
143
- : { [ typeof newModelValue === 'string' ? 'text' : 'json' ] : newModelValue } ,
143
+ : { [ ( typeof newModelValue === 'string' && computedMode . value === 'text' ) ? 'text' : 'json' ] : newModelValue } ,
144
144
)
145
145
}
146
146
} ,
0 commit comments