Skip to content

Commit 0c4d77e

Browse files
committed
Add prop "showLine" to toggle line.
1 parent 187564b commit 0c4d77e

File tree

8 files changed

+60
-33
lines changed

8 files changed

+60
-33
lines changed

.travis.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
language: node_js
22
node_js:
3-
- "7"
3+
- "10"
44

55
cache:
66
directories:
77
- "node_modules"
88

99
install:
1010
- npm i
11-
- npm install vue@2
1211

1312
stages:
1413
- lint
@@ -24,15 +23,15 @@ jobs:
2423
- stage: gh_pages
2524
script: npm run build
2625
after_script:
27-
- cd ./example-dist
28-
- git init
29-
- git remote add origin "https://${GH_TOKEN}@${GH_REF}"
30-
- git checkout -b gh-pages
26+
- git clone -b gh-pages "https://${GH_TOKEN}@${GH_REF}" gh-pages
27+
- rm -r gh-pages/*
28+
- cp -r example-dist/. gh-pages
29+
- cd ./gh-pages
3130
- git config user.name "leezng"
3231
- git config user.email "[email protected]"
3332
- git add .
34-
- git commit -m "update example page"
35-
- git push --force --quiet "https://${GH_TOKEN}@${GH_REF}" gh-pages:gh-pages
33+
- git commit -m "update gh-pages"
34+
- git push --quiet "https://${GH_TOKEN}@${GH_REF}" gh-pages:gh-pages
3635
- stage: github_release
3736
script: echo "Deploying to GitHub releases ..."
3837
deploy:

example/App.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
<label>showLength</label>
5050
<input type="checkbox" v-model="showLength">
5151
</div>
52+
<div>
53+
<label>showLine</label>
54+
<input type="checkbox" v-model="showLine">
55+
</div>
5256
<div>
5357
<label>showDoubleQuotes</label>
5458
<input type="checkbox" v-model="showDoubleQuotes">
@@ -70,14 +74,14 @@
7074
</select>
7175
</div>
7276
</div>
73-
74-
<h3>Latest Click Result:</h3>
77+
<h3>v-model:</h3>
78+
<div>{{value}}</div>
79+
<h3>Current Click:</h3>
7580
<div>path: {{itemPath}}</div>
7681
<div>data: <pre>{{itemData}}</pre></div>
7782
</div>
7883
<div class="block">
7984
<h3>JSON Tree:</h3>
80-
{{value}}
8185
<vue-json-pretty
8286
v-if="renderOK"
8387
:data="json"
@@ -87,6 +91,7 @@
8791
:highlight-mouseover-node="highlightMouseoverNode"
8892
:highlight-selected-node="highlightSelectedNode"
8993
:show-length="showLength"
94+
:show-line="showLine"
9095
:select-on-click-node="selectOnClickNode"
9196
v-model="value"
9297
:path-selectable="((path, data) => typeof data !== 'number')"
@@ -135,6 +140,7 @@ export default {
135140
selectableType: 'single',
136141
showSelectController: true,
137142
showLength: true,
143+
showLine: true,
138144
showDoubleQuotes: true,
139145
highlightMouseoverNode: true,
140146
highlightSelectedNode: true,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-json-pretty",
3-
"version": "1.4.1",
3+
"version": "1.6.0",
44
"description": "A Vue.js 2.0 Toolkit for JSON",
55
"author": "leezng <[email protected]>",
66
"main": "vue-json-pretty.js",

src/assets/less/tree.less

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929

3030
.@{css-prefix}-tree__content {
3131
padding-left: @content-padding;
32-
border-left: 1px dotted @border-color;
32+
&.has-line {
33+
border-left: 1px dotted @border-color;
34+
}
3335
}
3436

3537
.@{css-prefix}-tree__brackets {
@@ -39,6 +41,10 @@
3941
}
4042
}
4143

44+
.@{css-prefix}-comment {
45+
color: @comment-color;
46+
}
47+
4248
.@{css-prefix}-value__null {
4349
.mixin-value-style(@color-null);
4450
}

src/assets/less/var.less

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
/* highlight */
1717
@highlight-bg-color: #e6f7ff;
1818

19+
/* comment */
20+
@comment-color: #bfcbd9;
21+
1922
/* common border-color */
2023
@border-color: #bfcbd9;
2124

src/components/app.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
<div
3232
v-for="(item, key) in data"
3333
v-show="visible"
34-
class="vjs-tree__content"
34+
:class="{
35+
'vjs-tree__content': true,
36+
'has-line': showLine
37+
}"
3538
:key="key">
3639
<vue-json-pretty
3740
v-model="model"
@@ -40,6 +43,7 @@
4043
:deep="deep"
4144
:show-length="showLength"
4245
:show-double-quotes="showDoubleQuotes"
46+
:show-line="showLine"
4347
:highlight-mouseover-node="highlightMouseoverNode"
4448
:highlight-selected-node="highlightSelectedNode"
4549
:path="path + (Array.isArray(data) ? `[${key}]` : `.${key}`)"
@@ -125,6 +129,10 @@
125129
type: Boolean,
126130
default: false
127131
},
132+
showLine: {
133+
type: Boolean,
134+
default: true
135+
},
128136
// 是否在点击树的时候选中节点
129137
selectOnClickNode: {
130138
type: Boolean,

src/components/brackets-left.vue

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@
1111
</span>
1212

1313
<!-- Collapse -->
14-
<span
15-
v-show="!dataVisiable"
16-
class="vjs-tree__brackets"
17-
@click.stop="toggleBrackets">
18-
{{ doubleBracketsGenerator(data) }}
14+
<span v-show="!dataVisiable">
15+
<span
16+
class="vjs-tree__brackets"
17+
@click.stop="toggleBrackets">
18+
{{ closedBracketsGenerator(data) }}
19+
</span>
20+
21+
<span v-if="showLength" class="vjs-comment">
22+
{{ lengthGenerator(data) }}
23+
</span>
1924
</span>
2025
</div>
2126
</template>
@@ -29,19 +34,19 @@
2934
showLength: Boolean
3035
},
3136
methods: {
32-
// 双括号内容生成器
33-
doubleBracketsGenerator (data) {
34-
const isArray = Array.isArray(data)
35-
const brackets = isArray ? '[...]' : '{...}'
36-
let str = this.bracketsFormatter(brackets)
37-
if (this.showLength) {
38-
// 若展示长度, 形如 [...] // 3 items
39-
const text = isArray
40-
? `${data.length} items`
41-
: `${Object.keys(data).length} keys`
42-
str += ` // ${text}`
43-
}
44-
return str
37+
// 关闭括号生成器
38+
closedBracketsGenerator (data) {
39+
const brackets = Array.isArray(data) ? '[...]' : '{...}'
40+
return this.bracketsFormatter(brackets)
41+
},
42+
43+
// 长度标记生成器
44+
lengthGenerator (data) {
45+
// 若展示长度, 形如 [...] // 3 items
46+
const text = Array.isArray(data)
47+
? `${data.length} items`
48+
: `${Object.keys(data).length} keys`
49+
return ` // ${text}`
4550
}
4651
}
4752
}

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import App from './components/app.vue'
22
import './assets/less/index.less'
33

44
export default Object.assign({}, App, {
5-
version: '1.4.0'
5+
version: '1.6.0'
66
})

0 commit comments

Comments
 (0)