mirror of
https://github.com/tenrok/vue-json-viewer.git
synced 2026-06-20 20:00:37 +03:00
Migrate all types
This commit is contained in:
+14
-27
@@ -1,4 +1,5 @@
|
|||||||
<script>
|
<script>
|
||||||
|
import { h } from 'vue'
|
||||||
import JsonBox from '../json-box'
|
import JsonBox from '../json-box'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -57,9 +58,9 @@ export default {
|
|||||||
this.$el.dispatchEvent(evt)
|
this.$el.dispatchEvent(evt)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
},
|
},
|
||||||
render (h) {
|
render () {
|
||||||
let elements = []
|
let elements = []
|
||||||
|
|
||||||
if (!this.previewMode && !this.keyName) {
|
if (!this.previewMode && !this.keyName) {
|
||||||
@@ -68,9 +69,7 @@ export default {
|
|||||||
'jv-toggle': true,
|
'jv-toggle': true,
|
||||||
'open': !!this.expand,
|
'open': !!this.expand,
|
||||||
},
|
},
|
||||||
on: {
|
onClick: this.toggle
|
||||||
click: this.toggle
|
|
||||||
}
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,9 +78,7 @@ export default {
|
|||||||
'jv-item': true,
|
'jv-item': true,
|
||||||
'jv-array': true,
|
'jv-array': true,
|
||||||
},
|
},
|
||||||
domProps: {
|
innerText: '['
|
||||||
innerText: '['
|
|
||||||
}
|
|
||||||
}))
|
}))
|
||||||
if (this.expand) {
|
if (this.expand) {
|
||||||
this.value.forEach((value, key) => {
|
this.value.forEach((value, key) => {
|
||||||
@@ -90,13 +87,11 @@ export default {
|
|||||||
style: {
|
style: {
|
||||||
display: this.expand ? undefined : 'none'
|
display: this.expand ? undefined : 'none'
|
||||||
},
|
},
|
||||||
props: {
|
sort: this.sort,
|
||||||
sort: this.sort,
|
// keyName: key,
|
||||||
// keyName: key,
|
depth: this.depth + 1,
|
||||||
depth: this.depth + 1,
|
value,
|
||||||
value,
|
previewMode: this.previewMode,
|
||||||
previewMode: this.previewMode,
|
|
||||||
}
|
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -109,15 +104,9 @@ export default {
|
|||||||
class: {
|
class: {
|
||||||
'jv-ellipsis': true,
|
'jv-ellipsis': true,
|
||||||
},
|
},
|
||||||
on: {
|
onClick: this.toggle,
|
||||||
click: this.toggle
|
title: `click to reveal ${this.value.length} hidden items`,
|
||||||
},
|
innerText: '...'
|
||||||
attrs: {
|
|
||||||
title: `click to reveal ${this.value.length} hidden items`
|
|
||||||
},
|
|
||||||
domProps: {
|
|
||||||
innerText: '...'
|
|
||||||
}
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,9 +115,7 @@ export default {
|
|||||||
'jv-item': true,
|
'jv-item': true,
|
||||||
'jv-array': true,
|
'jv-array': true,
|
||||||
},
|
},
|
||||||
domProps: {
|
innerText: ']'
|
||||||
innerText: ']'
|
|
||||||
}
|
|
||||||
}))
|
}))
|
||||||
|
|
||||||
return h('span', elements)
|
return h('span', elements)
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
<script>
|
<script>
|
||||||
|
import { h } from 'vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'JsonBoolean',
|
name: 'JsonBoolean',
|
||||||
functional: true,
|
functional: true,
|
||||||
props: {
|
props: {
|
||||||
jsonValue: Boolean
|
jsonValue: Boolean
|
||||||
},
|
},
|
||||||
render (h, { props }) {
|
render () {
|
||||||
return h('span', {
|
return h('span', {
|
||||||
class: {
|
class: {
|
||||||
'jv-item': true,
|
'jv-item': true,
|
||||||
'jv-boolean': true,
|
'jv-boolean': true,
|
||||||
},
|
},
|
||||||
domProps: {
|
innerText: this.jsonValue.toString()
|
||||||
innerText: props.jsonValue.toString()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
<script>
|
<script>
|
||||||
|
import { h } from 'vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'JsonDate',
|
name: 'JsonDate',
|
||||||
inject: ['timeformat'],
|
inject: ['timeformat'],
|
||||||
@@ -9,18 +11,16 @@ export default {
|
|||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
render (h, { props, injections }) {
|
render () {
|
||||||
const value = props.jsonValue;
|
const value = this.jsonValue;
|
||||||
const timeformat = injections.timeformat;
|
const timeformat = this.timeformat;
|
||||||
|
|
||||||
return h('span', {
|
return h('span', {
|
||||||
class: {
|
class: {
|
||||||
'jv-item': true,
|
'jv-item': true,
|
||||||
'jv-string': true,
|
'jv-string': true,
|
||||||
},
|
},
|
||||||
domProps: {
|
innerText: `"${timeformat(value)}"`
|
||||||
innerText: `"${timeformat(value)}"`
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
<script>
|
<script>
|
||||||
|
import { h } from 'vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'JsonFunction',
|
name: 'JsonFunction',
|
||||||
functional: true,
|
functional: true,
|
||||||
@@ -8,18 +10,16 @@ export default {
|
|||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
render (h, { props }) {
|
render () {
|
||||||
return h('span', {
|
return h('span', {
|
||||||
class: {
|
class: {
|
||||||
'jv-item': true,
|
'jv-item': true,
|
||||||
'jv-function': true,
|
'jv-function': true,
|
||||||
},
|
},
|
||||||
attrs: {
|
attrs: {
|
||||||
title: props.jsonValue.toString()
|
title: this.jsonValue.toString()
|
||||||
},
|
},
|
||||||
domProps: {
|
innerHTML: '<function>'
|
||||||
innerHTML: '<function>'
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
<script>
|
<script>
|
||||||
|
import { h } from 'vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'JsonNumber',
|
name: 'JsonNumber',
|
||||||
functional: true,
|
functional: true,
|
||||||
@@ -8,8 +10,8 @@ export default {
|
|||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
render (h, { props }) {
|
render () {
|
||||||
const isInteger = Number.isInteger(props.jsonValue)
|
const isInteger = Number.isInteger(this.jsonValue)
|
||||||
|
|
||||||
return h('span', {
|
return h('span', {
|
||||||
class: {
|
class: {
|
||||||
@@ -18,9 +20,7 @@ export default {
|
|||||||
'jv-number-integer': isInteger,
|
'jv-number-integer': isInteger,
|
||||||
'jv-number-float': !isInteger,
|
'jv-number-float': !isInteger,
|
||||||
},
|
},
|
||||||
domProps: {
|
innerText: this.jsonValue.toString()
|
||||||
innerText: props.jsonValue.toString()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-26
@@ -1,4 +1,5 @@
|
|||||||
<script>
|
<script>
|
||||||
|
import { h } from 'vue'
|
||||||
import JsonBox from '../json-box'
|
import JsonBox from '../json-box'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -67,7 +68,7 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
render (h) {
|
render () {
|
||||||
let elements = []
|
let elements = []
|
||||||
|
|
||||||
if (!this.previewMode && !this.keyName) {
|
if (!this.previewMode && !this.keyName) {
|
||||||
@@ -76,9 +77,7 @@ export default {
|
|||||||
'jv-toggle': true,
|
'jv-toggle': true,
|
||||||
'open': !!this.expand,
|
'open': !!this.expand,
|
||||||
},
|
},
|
||||||
on: {
|
onClick: this.toggle
|
||||||
click: this.toggle
|
|
||||||
}
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,9 +86,7 @@ export default {
|
|||||||
'jv-item': true,
|
'jv-item': true,
|
||||||
'jv-object': true,
|
'jv-object': true,
|
||||||
},
|
},
|
||||||
domProps: {
|
innerText: '{'
|
||||||
innerText: '{'
|
|
||||||
}
|
|
||||||
}))
|
}))
|
||||||
|
|
||||||
if (this.expand) {
|
if (this.expand) {
|
||||||
@@ -102,13 +99,12 @@ export default {
|
|||||||
style: {
|
style: {
|
||||||
display: !this.expand ? 'none' : undefined
|
display: !this.expand ? 'none' : undefined
|
||||||
},
|
},
|
||||||
props: {
|
|
||||||
sort: this.sort,
|
sort: this.sort,
|
||||||
keyName: key,
|
keyName: key,
|
||||||
depth: this.depth + 1,
|
depth: this.depth + 1,
|
||||||
value,
|
value,
|
||||||
previewMode: this.previewMode,
|
previewMode: this.previewMode,
|
||||||
}
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -122,15 +118,9 @@ export default {
|
|||||||
class: {
|
class: {
|
||||||
'jv-ellipsis': true,
|
'jv-ellipsis': true,
|
||||||
},
|
},
|
||||||
on: {
|
onClick: this.toggle,
|
||||||
click: this.toggle
|
title: `click to reveal object content (keys: ${Object.keys(this.ordered).join(', ')})`,
|
||||||
},
|
innerText: '...'
|
||||||
attrs: {
|
|
||||||
title: `click to reveal object content (keys: ${Object.keys(this.ordered).join(', ')})`
|
|
||||||
},
|
|
||||||
domProps: {
|
|
||||||
innerText: '...'
|
|
||||||
}
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,9 +129,7 @@ export default {
|
|||||||
'jv-item': true,
|
'jv-item': true,
|
||||||
'jv-object': true,
|
'jv-object': true,
|
||||||
},
|
},
|
||||||
domProps: {
|
innerText: '}'
|
||||||
innerText: '}'
|
|
||||||
}
|
|
||||||
}))
|
}))
|
||||||
|
|
||||||
return h('span', elements)
|
return h('span', elements)
|
||||||
|
|||||||
+11
-17
@@ -1,5 +1,9 @@
|
|||||||
<script>
|
<script>
|
||||||
|
import { h } from 'vue'
|
||||||
|
|
||||||
|
// TODO: check?
|
||||||
const REG_LINK = /^\w+:\/\//;
|
const REG_LINK = /^\w+:\/\//;
|
||||||
|
// const REG_LINK =/^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(([A-Za-z0-9-~]+)\.)+([A-Za-z0-9-~\/])+$/;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'JsonString',
|
name: 'JsonString',
|
||||||
@@ -25,7 +29,7 @@ export default {
|
|||||||
this.expand = !this.expand;
|
this.expand = !this.expand;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
render (h) {
|
render () {
|
||||||
let value = this.jsonValue;
|
let value = this.jsonValue;
|
||||||
const islink = REG_LINK.test(value)
|
const islink = REG_LINK.test(value)
|
||||||
let domItem
|
let domItem
|
||||||
@@ -35,12 +39,8 @@ export default {
|
|||||||
class: {
|
class: {
|
||||||
'jv-ellipsis': true,
|
'jv-ellipsis': true,
|
||||||
},
|
},
|
||||||
on: {
|
onClick: this.toggle,
|
||||||
click: this.toggle
|
innerText: '...'
|
||||||
},
|
|
||||||
domProps: {
|
|
||||||
innerText: '...'
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
domItem = {
|
domItem = {
|
||||||
@@ -52,16 +52,12 @@ export default {
|
|||||||
}
|
}
|
||||||
if (islink) {
|
if (islink) {
|
||||||
value = `<a href="${value}" target="_blank" class="jv-link">${value}</a>`;
|
value = `<a href="${value}" target="_blank" class="jv-link">${value}</a>`;
|
||||||
domItem.domProps = {
|
domItem.innerHTML = `"${value.toString()}"`
|
||||||
innerHTML: `"${value.toString()}"`
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
domItem.domProps = {
|
domItem.innerText = `"${value.toString()}"`
|
||||||
innerText: `"${value.toString()}"`
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return h('span', {}, [
|
return h('span', {}, [
|
||||||
this.canExtend && h('span', {
|
this.canExtend && h('span', {
|
||||||
@@ -69,9 +65,7 @@ export default {
|
|||||||
'jv-toggle': true,
|
'jv-toggle': true,
|
||||||
open: this.expand,
|
open: this.expand,
|
||||||
},
|
},
|
||||||
on: {
|
onClick: this.toggle,
|
||||||
click: this.toggle,
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
h('span', {
|
h('span', {
|
||||||
class: {
|
class: {
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
<script>
|
<script>
|
||||||
|
import { h } from 'vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'JsonUndefined',
|
name: 'JsonUndefined',
|
||||||
functional: true,
|
functional: true,
|
||||||
@@ -8,15 +10,13 @@ export default {
|
|||||||
default: null
|
default: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
render (h, { props }) {
|
render () {
|
||||||
return h('span', {
|
return h('span', {
|
||||||
class: {
|
class: {
|
||||||
'jv-item': true,
|
'jv-item': true,
|
||||||
'jv-undefined': true,
|
'jv-undefined': true,
|
||||||
},
|
},
|
||||||
domProps: {
|
innerText: this.jsonValue === null ? 'null' : 'undefined'
|
||||||
innerText: props.jsonValue === null ? 'null' : 'undefined'
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user