@@ -61,6 +61,16 @@ export default defineComponent({
6161 const preventUpdatingContent = ref ( false )
6262
6363 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+ }
6474 preventUpdatingContent . value = true
6575 emit (
6676 updateModelValue ,
@@ -70,9 +80,6 @@ export default defineComponent({
7080 )
7181 } , 100 )
7282
73- const onChangeMode = ( mode : Mode ) => {
74- emit ( 'update:mode' , mode )
75- }
7683
7784 const mergeFunction = ( previousValue : ( ...args : any ) => unknown , currentValue : ( ...args : any ) => unknown ) => ( ...args : any ) => {
7885 previousValue ( ...args )
@@ -86,13 +93,6 @@ export default defineComponent({
8693 } )
8794
8895 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- }
9696 const initialValue = conclude ( [ props [ modelValueProp ] , globalProps [ modelValueProp ] ] )
9797 const initialBoolAttrs = Object . fromEntries (
9898 Array . from ( boolAttrs , boolAttr => [ boolAttr , conclude ( [ props [ boolAttr ] , globalProps [ boolAttr ] ] ) ] ) . filter (
@@ -107,9 +107,9 @@ export default defineComponent({
107107 {
108108 onChange,
109109 onChangeMode,
110- mode : initialMode ,
110+ mode : computedMode . value ,
111111 ...( initialValue !== undefined && {
112- content : { [ typeof initialValue === 'string' ? 'text' : 'json' ] : initialValue } ,
112+ content : { [ ( typeof initialValue === 'string' && computedMode . value === 'text' ) ? 'text' : 'json' ] : initialValue } ,
113113 } ) ,
114114 } ,
115115 ] ,
@@ -140,7 +140,7 @@ export default defineComponent({
140140 jsonEditor . value . set (
141141 [ undefined , '' ] . includes ( newModelValue )
142142 ? { text : '' }
143- : { [ typeof newModelValue === 'string' ? 'text' : 'json' ] : newModelValue } ,
143+ : { [ ( typeof newModelValue === 'string' && computedMode . value === 'text' ) ? 'text' : 'json' ] : newModelValue } ,
144144 )
145145 }
146146 } ,
0 commit comments