2023-07-27 08:31:52 +03:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2022-01-04 16:37:26 +02:00
|
|
|
<template>
|
|
|
|
<div class="igpposuu _monospace">
|
|
|
|
<div v-if="value === null" class="null">null</div>
|
2022-06-29 09:41:06 +03:00
|
|
|
<div v-else-if="typeof value === 'boolean'" class="boolean" :class="{ true: value, false: !value }">{{ value ? 'true' : 'false' }}</div>
|
2022-01-04 16:37:26 +02:00
|
|
|
<div v-else-if="typeof value === 'string'" class="string">"{{ value }}"</div>
|
|
|
|
<div v-else-if="typeof value === 'number'" class="number">{{ number(value) }}</div>
|
2022-06-29 09:41:06 +03:00
|
|
|
<div v-else-if="isArray(value) && isEmpty(value)" class="array empty">[]</div>
|
|
|
|
<div v-else-if="isArray(value)" class="array">
|
|
|
|
<div v-for="i in value.length" class="element">
|
|
|
|
{{ i }}: <XValue :value="value[i - 1]" collapsed/>
|
|
|
|
</div>
|
2022-01-04 16:37:26 +02:00
|
|
|
</div>
|
2022-06-29 09:41:06 +03:00
|
|
|
<div v-else-if="isObject(value) && isEmpty(value)" class="object empty">{}</div>
|
|
|
|
<div v-else-if="isObject(value)" class="object">
|
|
|
|
<div v-for="k in Object.keys(value)" class="kv">
|
|
|
|
<button class="toggle _button" :class="{ visible: collapsable(value[k]) }" @click="collapsed[k] = !collapsed[k]">{{ collapsed[k] ? '+' : '-' }}</button>
|
|
|
|
<div class="k">{{ k }}:</div>
|
|
|
|
<div v-if="collapsed[k]" class="v">
|
|
|
|
<button class="_button" @click="collapsed[k] = !collapsed[k]">
|
|
|
|
<template v-if="typeof value[k] === 'string'">"..."</template>
|
|
|
|
<template v-else-if="isArray(value[k])">[...]</template>
|
|
|
|
<template v-else-if="isObject(value[k])">{...}</template>
|
|
|
|
</button>
|
2022-01-04 16:37:26 +02:00
|
|
|
</div>
|
2022-06-29 09:41:06 +03:00
|
|
|
<div v-else class="v"><XValue :value="value[k]"/></div>
|
|
|
|
</div>
|
2022-01-04 16:37:26 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2023-05-14 06:23:39 +03:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { reactive } from 'vue';
|
2023-09-19 10:37:43 +03:00
|
|
|
import number from '@/filters/number.js';
|
2023-05-14 06:23:39 +03:00
|
|
|
import XValue from '@/components/MkObjectView.value.vue';
|
2022-01-04 16:37:26 +02:00
|
|
|
|
2023-05-14 06:23:39 +03:00
|
|
|
const props = defineProps<{
|
|
|
|
value: any;
|
|
|
|
}>();
|
2022-01-04 16:37:26 +02:00
|
|
|
|
2023-05-14 06:23:39 +03:00
|
|
|
const collapsed = reactive({});
|
2022-01-04 16:37:26 +02:00
|
|
|
|
2023-05-14 06:23:39 +03:00
|
|
|
if (isObject(props.value)) {
|
|
|
|
for (const key in props.value) {
|
|
|
|
collapsed[key] = collapsable(props.value[key]);
|
|
|
|
}
|
|
|
|
}
|
2022-06-29 09:41:06 +03:00
|
|
|
|
2023-05-14 06:23:39 +03:00
|
|
|
function isObject(v): boolean {
|
|
|
|
return typeof v === 'object' && !Array.isArray(v) && v !== null;
|
|
|
|
}
|
2022-06-29 09:41:06 +03:00
|
|
|
|
2023-05-14 06:23:39 +03:00
|
|
|
function isArray(v): boolean {
|
|
|
|
return Array.isArray(v);
|
|
|
|
}
|
2022-06-29 09:41:06 +03:00
|
|
|
|
2023-05-14 06:23:39 +03:00
|
|
|
function isEmpty(v): boolean {
|
|
|
|
return (isArray(v) && v.length === 0) || (isObject(v) && Object.keys(v).length === 0);
|
|
|
|
}
|
2022-01-04 16:37:26 +02:00
|
|
|
|
2023-05-14 06:23:39 +03:00
|
|
|
function collapsable(v): boolean {
|
|
|
|
return (isObject(v) || isArray(v)) && !isEmpty(v);
|
|
|
|
}
|
2022-01-04 16:37:26 +02:00
|
|
|
</script>
|
|
|
|
|
2022-12-27 11:29:39 +02:00
|
|
|
<style lang="scss" scoped>
|
2022-01-04 16:37:26 +02:00
|
|
|
.igpposuu {
|
|
|
|
display: inline;
|
|
|
|
|
|
|
|
> .null {
|
|
|
|
display: inline;
|
|
|
|
opacity: 0.7;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .boolean {
|
|
|
|
display: inline;
|
|
|
|
color: var(--codeBoolean);
|
2022-06-29 09:41:06 +03:00
|
|
|
|
|
|
|
&.true {
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.false {
|
|
|
|
opacity: 0.7;
|
|
|
|
}
|
2022-01-04 16:37:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
> .string {
|
|
|
|
display: inline;
|
|
|
|
color: var(--codeString);
|
|
|
|
}
|
|
|
|
|
|
|
|
> .number {
|
|
|
|
display: inline;
|
|
|
|
color: var(--codeNumber);
|
|
|
|
}
|
|
|
|
|
2022-06-29 09:41:06 +03:00
|
|
|
> .array.empty {
|
|
|
|
display: inline;
|
|
|
|
opacity: 0.7;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .array:not(.empty) {
|
2022-01-04 16:37:26 +02:00
|
|
|
display: inline;
|
|
|
|
|
|
|
|
> .element {
|
|
|
|
display: block;
|
|
|
|
padding-left: 16px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-29 09:41:06 +03:00
|
|
|
> .object.empty {
|
|
|
|
display: inline;
|
|
|
|
opacity: 0.7;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .object:not(.empty) {
|
2022-01-04 16:37:26 +02:00
|
|
|
display: inline;
|
|
|
|
|
|
|
|
> .kv {
|
|
|
|
display: block;
|
|
|
|
padding-left: 16px;
|
|
|
|
|
2022-06-29 09:41:06 +03:00
|
|
|
> .toggle {
|
|
|
|
width: 16px;
|
|
|
|
color: var(--accent);
|
|
|
|
visibility: hidden;
|
|
|
|
|
|
|
|
&.visible {
|
|
|
|
visibility: visible;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-04 16:37:26 +02:00
|
|
|
> .k {
|
|
|
|
display: inline;
|
|
|
|
margin-right: 8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .v {
|
|
|
|
display: inline;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|