99 unref ,
1010 watch ,
1111} from 'vue-demi'
12- import type { PropType } from 'vue-demi'
12+ import type { HTMLAttributes , PropType } from 'vue-demi'
1313import { JSONEditor } from 'vanilla-jsoneditor'
1414import { conclude } from 'vue-global-config'
1515import { debounce } from 'lodash-es'
@@ -18,31 +18,32 @@ import { globalAttrs, globalProps } from './install'
1818
1919export type Mode = 'tree' | 'text' | 'table'
2020
21- const modelValueProp = isVue3 ? 'modelValue' : 'value'
22- const updateModelValue = isVue3 ? 'update:modelValue' : 'input'
23- const boolAttrs = [
21+ type ModalValue = typeof isVue3 extends true ? 'modelValue' : 'value'
22+ type UpdateModalValue = typeof isVue3 extends true ? 'update:modelValue' : 'input'
23+
24+ const modelValueProp : ModalValue = ( isVue3 ? 'modelValue' : 'value' ) as any
25+ const updateModelValue : UpdateModalValue = ( isVue3 ? 'update:modelValue' : 'input' ) as any
26+
27+ const boolAttributes = [
2428 'mainMenuBar' ,
2529 'navigationBar' ,
2630 'statusBar' ,
2731 'readOnly' ,
2832 'escapeControlCharacters' ,
2933 'escapeUnicodeCharacters' ,
3034 'flattenColumns' ,
31- ]
35+ ] as const
36+
37+ type Attributes = ModalValue | UpdateModalValue
38+ type BoolAttributes = {
39+ [ K in typeof boolAttributes [ number ] ] : {
40+ type : Boolean
41+ default : undefined
42+ }
43+ }
3244
33- export default defineComponent ( {
45+ export default defineComponent < HTMLAttributes & { mode : PropType < Mode > } & { [ K in Attributes ] : any } & BoolAttributes , { } , { } , { } , { } , { } , { } , { 'update:mode' : ( mode : Mode ) => void ; 'update:modalValue' : ( value : unknown ) => void ; 'input' : ( value : unknown ) => void } > ( {
3446 name,
35- props : {
36- [ modelValueProp ] : { } ,
37- mode : {
38- type : String as PropType < Mode > ,
39- } ,
40- ...Object . fromEntries ( Array . from ( boolAttrs , boolAttr => [ boolAttr , {
41- type : Boolean ,
42- default : undefined ,
43- } ] ) ) ,
44- } ,
45- emits : [ updateModelValue , 'update:mode' ] ,
4647 setup ( props , { attrs, emit, expose } ) {
4748 const currentInstance = getCurrentInstance ( ) ?. proxy
4849 const jsonEditor = ref ( )
@@ -54,7 +55,7 @@ export default defineComponent({
5455 type : String as PropType < Mode > ,
5556 } )
5657 const initialValue = conclude ( [ props [ modelValueProp ] , globalProps [ modelValueProp ] ] )
57- const initialBoolAttrs = Object . fromEntries ( Array . from ( boolAttrs , boolAttr =>
58+ const initialBoolAttrs = Object . fromEntries ( Array . from ( boolAttributes , boolAttr =>
5859 [ boolAttr , conclude ( [ props [ boolAttr ] , globalProps [ boolAttr ] ] ) ] )
5960 . filter ( ( [ , v ] ) => v !== undefined ) )
6061
@@ -64,7 +65,7 @@ export default defineComponent({
6465 return
6566 }
6667 preventUpdate . value = true
67- emit ( updateModelValue , updatedContent . text === undefined
68+ emit ( updateModelValue as any , updatedContent . text === undefined
6869 ? updatedContent . json
6970 : updatedContent . text )
7071 } , 100 )
@@ -117,9 +118,9 @@ export default defineComponent({
117118 } )
118119 } )
119120
120- watch ( ( ) => Array . from ( boolAttrs , boolAttr => props [ boolAttr ] ) , ( values ) => {
121+ watch ( ( ) => Array . from ( boolAttributes , boolAttr => props [ boolAttr ] ) , ( values ) => {
121122 jsonEditor . value . updateProps ( Object . fromEntries ( Array . from ( values , ( v , i ) =>
122- [ boolAttrs [ i ] , v ] ) . filter ( ( [ , v ] ) => v !== undefined ) ) )
123+ [ boolAttributes [ i ] , v ] ) . filter ( ( [ , v ] ) => v !== undefined ) ) )
123124 } )
124125
125126 watch ( ( ) => attrs , ( newAttrs ) => {
0 commit comments