Skip to content

Commit ade5493

Browse files
authored
Merge pull request #238 from leezng/dev
release 2.2.4
2 parents b01ed0b + 8f509d6 commit ade5493

File tree

5 files changed

+44
-17
lines changed

5 files changed

+44
-17
lines changed

example/Basic.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
<label>showDoubleQuotes</label>
2727
<input v-model="state.showDoubleQuotes" type="checkbox" />
2828
</div>
29+
<div>
30+
<label>showKeyValueSpace</label>
31+
<input v-model="state.showKeyValueSpace" type="checkbox" />
32+
</div>
2933
<div>
3034
<label>collapsedOnClickBrackets</label>
3135
<input v-model="state.collapsedOnClickBrackets" type="checkbox" />
@@ -68,6 +72,7 @@
6872
:show-line-number="state.showLineNumber"
6973
:collapsed-on-click-brackets="state.collapsedOnClickBrackets"
7074
:show-icon="state.showIcon"
75+
:show-key-value-space="state.showKeyValueSpace"
7176
style="position: relative"
7277
>
7378
<template v-if="state.useRenderNodeKeySlot" #renderNodeKey="{ node, defaultKey }">
@@ -139,6 +144,7 @@ export default defineComponent({
139144
deep: 4,
140145
setPathCollapsible: false,
141146
showIcon: false,
147+
showKeyValueSpace: true,
142148
});
143149
144150
const pathCollapsible = node => {

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/Tree/index.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
reactive,
44
computed,
55
watchEffect,
6+
watch,
67
ref,
78
PropType,
89
CSSProperties,
@@ -18,7 +19,7 @@ export default defineComponent({
1819
...treeNodePropsPass,
1920
// JSONLike data.
2021
data: {
21-
type: Object as PropType<JSONDataType>,
22+
type: [String, Number, Boolean, Array, Object] as PropType<JSONDataType>,
2223
default: null,
2324
},
2425
// Define the depth of the tree, nodes greater than this depth will not be expanded.
@@ -83,11 +84,9 @@ export default defineComponent({
8384

8485
const originFlatData = computed(() => jsonFlatten(props.data, props.rootPath));
8586

86-
const state = reactive({
87-
translateY: 0,
88-
visibleData: null as NodeDataType[] | null,
89-
hiddenPaths: originFlatData.value.reduce((acc, item) => {
90-
const depthComparison = item.level >= props.deep;
87+
const initHiddenPaths = (deep: number) => {
88+
return originFlatData.value.reduce((acc, item) => {
89+
const depthComparison = item.level >= deep;
9190
const pathComparison = props.pathCollapsible?.(item as NodeDataType);
9291
if (
9392
(item.type === 'objectStart' || item.type === 'arrayStart') &&
@@ -99,7 +98,13 @@ export default defineComponent({
9998
};
10099
}
101100
return acc;
102-
}, {}) as Record<string, 1>,
101+
}, {}) as Record<string, 1>;
102+
};
103+
104+
const state = reactive({
105+
translateY: 0,
106+
visibleData: null as NodeDataType[] | null,
107+
hiddenPaths: initHiddenPaths(props.deep),
103108
});
104109

105110
const flatData = computed(() => {
@@ -247,6 +252,13 @@ export default defineComponent({
247252
}
248253
});
249254

255+
watch(
256+
() => props.deep,
257+
val => {
258+
if (val) state.hiddenPaths = initHiddenPaths(val);
259+
},
260+
);
261+
250262
return () => {
251263
const renderNodeKey = props.renderNodeKey ?? slots.renderNodeKey;
252264
const renderNodeValue = props.renderNodeValue ?? slots.renderNodeValue;
@@ -271,6 +283,7 @@ export default defineComponent({
271283
editable={props.editable}
272284
editableTrigger={props.editableTrigger}
273285
showIcon={props.showIcon}
286+
showKeyValueSpace={props.showKeyValueSpace}
274287
renderNodeKey={renderNodeKey}
275288
renderNodeValue={renderNodeValue}
276289
onNodeClick={handleNodeClick}

src/components/TreeNode/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ export const treeNodePropsPass = {
6464
type: Boolean,
6565
default: false,
6666
},
67+
showKeyValueSpace: {
68+
type: Boolean,
69+
default: true,
70+
},
6771
editable: {
6872
type: Boolean,
6973
default: false,
@@ -242,7 +246,7 @@ export default defineComponent({
242246
{node.key && (
243247
<span class="vjs-key">
244248
{renderKey()}
245-
<span>:</span>
249+
<span class="vjs-colon">{`:${props.showKeyValueSpace ? ' ' : ''}`}</span>
246250
</span>
247251
)}
248252

src/components/TreeNode/styles.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
margin-right: 4px;
4444
}
4545

46+
.@{css-prefix}-colon {
47+
white-space: pre;
48+
}
49+
4650
.@{css-prefix}-comment {
4751
color: @comment-color;
4852
}

0 commit comments

Comments
 (0)