Skip to content

Commit 94ade15

Browse files
committed
Improve array visualization
1 parent 542f41f commit 94ade15

File tree

3 files changed

+65
-42
lines changed

3 files changed

+65
-42
lines changed

etc/js/components/widgets/inspector/entity-inspector-field.vue

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,16 +363,14 @@ div.value-bool::after {
363363
div.value-bool label.bool-checkbox {
364364
display: flex;
365365
align-items: center;
366-
padding: 4px;
367-
padding-left: 8px;
368366
}
369367
370368
div.value-bool label.bool-checkbox input[type="checkbox"] {
371369
-webkit-appearance: none;
372370
appearance: none;
373371
background-color: var(--bg-input);
374-
width: 16px;
375-
height: 16px;
372+
width: 15.5px;
373+
height: 19.5px;
376374
border-radius: var(--border-radius-medium);
377375
cursor: pointer;
378376
position: relative;
@@ -382,7 +380,7 @@ div.value-bool label.bool-checkbox input[type="checkbox"]:checked::after {
382380
content: '';
383381
position: absolute;
384382
left: 9px;
385-
top: 3px;
383+
top: 5px;
386384
width: 5px;
387385
height: 10px;
388386
border: solid #4981B5;

etc/js/components/widgets/inspector/entity-inspector-kv.vue

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<template>
2-
<div class="chevron noselect" @click.stop="toggle">
2+
<div v-if="showChevron" class="chevron noselect" @click.stop="toggle">
33
<template v-if="typeof value === 'object' && value !== null">
44
<expand-button
55
:expand="expand">
66
</expand-button>
77
</template>
88
</div>
9-
<div class="key noselect" @click.stop="toggle">
9+
<div class="key noselect" :class="{'no-chevron': !showChevron}" @click.stop="toggle">
1010
{{ keyname }}
1111
</div>
12-
<div class="value noselect" @click.stop="toggle">
12+
<div class="value noselect" :class="{'no-chevron': !showChevron}" @click.stop="toggle">
1313
<template v-if="typeof value === 'object'">
1414
<entity-inspector-preview
1515
:value="value"
@@ -54,6 +54,7 @@ const props = defineProps({
5454
value: {required: true},
5555
type: {type: Object, required: true},
5656
readonly: {type: Boolean, required: true},
57+
showChevron: {type: Boolean, required: false, default: true},
5758
});
5859
5960
const emit = defineEmits(["setValue"]);
@@ -66,7 +67,11 @@ function toggle() {
6667
6768
function setValue(evt, key) {
6869
if (evt.hasOwnProperty("key")) {
69-
emit('setValue', { key: `${key}.${evt.key}`, value: evt.value });
70+
if (evt.key.startsWith('[')) {
71+
emit('setValue', { key: `${key}${evt.key}`, value: evt.value });
72+
} else {
73+
emit('setValue', { key: `${key}.${evt.key}`, value: evt.value });
74+
}
7075
} else {
7176
emit('setValue', { key: key, value: evt.value });
7277
}
@@ -98,11 +103,19 @@ div.key {
98103
min-height: 28px;
99104
}
100105
106+
div.key.no-chevron {
107+
grid-column: 1;
108+
}
109+
101110
div.value {
102111
grid-column: 3;
103112
cursor: pointer;
104113
}
105114
115+
div.value.no-chevron {
116+
grid-column: 2;
117+
}
118+
106119
div.nested-value {
107120
grid-column: 1 / -1;
108121
padding-left: 5px;
Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
<template>
22
<div>
33
<template v-if="isArray(type, value)">
4-
<div class="array-list">
4+
<div class="prop-grid" :class="{'no-chevron': !hasComplexChildren}">
55
<template v-for="(item, index) in value">
6-
<div class="array-item">
7-
<span class="array-index">{{ index }}:</span>
8-
<span class="array-value">{{ item }}</span>
9-
</div>
6+
<entity-inspector-kv
7+
:path="path + '[' + index + ']'"
8+
:keyname="String(index)"
9+
:value="item"
10+
:type="type[1]"
11+
:readonly="readonly"
12+
:showChevron="hasComplexChildren"
13+
@setValue="(evt) => emitArrayValue(evt, index)">
14+
</entity-inspector-kv>
1015
</template>
1116
</div>
1217
</template>
1318
<template v-else-if="isObject(type, value)">
14-
<div class="prop-grid">
19+
<div class="prop-grid" :class="{'no-chevron': !hasComplexChildren}">
1520
<template v-for="(value, key) in value">
1621
<entity-inspector-kv
1722
:path="path + '.' + key"
1823
:keyname="key"
1924
:value="value"
2025
:type="type[key]"
2126
:readonly="readonly"
27+
:showChevron="hasComplexChildren"
2228
@setValue="(evt) => emit('setValue', evt)">
2329
</entity-inspector-kv>
2430
</template>
@@ -40,7 +46,7 @@ export default { name: "entity-inspector-value" }
4046
</script>
4147

4248
<script setup>
43-
import { defineProps, defineEmits } from 'vue';
49+
import { defineProps, defineEmits, computed } from 'vue';
4450
4551
const props = defineProps({
4652
path: {type: String, required: true},
@@ -51,13 +57,40 @@ const props = defineProps({
5157
5258
const emit = defineEmits(["setValue"]);
5359
54-
function isArray(type, value) {
55-
if (type) {
56-
return Array.isArray(type);
60+
const hasComplexChildren = computed(() => {
61+
if (Array.isArray(props.value)) {
62+
return props.value.some(v => typeof v === 'object' && v !== null);
63+
} else if (typeof props.value === 'object' && props.value !== null) {
64+
return Object.values(props.value).some(v => typeof v === 'object' && v !== null);
5765
}
66+
return false;
67+
});
68+
69+
function emitArrayValue(evt, index) {
70+
const prefix = String(index);
71+
if (evt.hasOwnProperty("key")) {
72+
let subkey = evt.key;
73+
if (subkey === prefix) {
74+
emit('setValue', { key: `[${index}]`, value: evt.value });
75+
} else if (subkey.startsWith(prefix + '.')) {
76+
emit('setValue', { key: `[${index}].${subkey.slice(prefix.length + 1)}`, value: evt.value });
77+
}
78+
} else {
79+
emit('setValue', { key: `[${index}]`, value: evt.value });
80+
}
81+
}
82+
83+
function isArray(type, value) {
5884
return Array.isArray(value);
5985
}
6086
87+
function arrayElementType(type) {
88+
if (Array.isArray(type) && type[0] === "array") {
89+
return type[1];
90+
}
91+
return type;
92+
}
93+
6194
function isObject(type, value) {
6295
if (type) {
6396
if (Array.isArray(type)) {
@@ -78,30 +111,9 @@ div.prop-grid {
78111
grid-template-columns: 16px auto 1fr;
79112
}
80113
81-
div.array-list {
82-
display: flex;
83-
flex-direction: column;
84-
gap: 4px;
114+
div.prop-grid.no-chevron {
115+
grid-template-columns: auto 1fr;
85116
}
86117
87-
div.array-item {
88-
display: flex;
89-
gap: 8px;
90-
padding: 4px;
91-
background-color: var(--bg-content);
92-
border-radius: var(--border-radius-small);
93-
}
94-
95-
span.array-index {
96-
color: var(--secondary-text);
97-
font-weight: 500;
98-
min-width: 2em;
99-
}
100-
101-
span.array-value {
102-
color: var(--orange);
103-
word-wrap: break-word;
104-
overflow-wrap: break-word;
105-
}
106118
107119
</style>

0 commit comments

Comments
 (0)