Skip to content

Commit 0aeb36f

Browse files
committed
refactor
1 parent 7059e38 commit 0aeb36f

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
11
# Vue Tree
22

3-
A simple Vue component to beautify tree-like visualization.
3+
A simple Vue component to beautify tree-like visualization.
4+
5+
Important note:
6+
User of this component must have `whitespace: 'preserve'` defined in the vue compilerOptions.
7+
8+
vite.config.ts
9+
```ts
10+
plugins: [vue(
11+
{
12+
template: {
13+
compilerOptions: {
14+
whitespace: "preserve",
15+
},
16+
}
17+
}
18+
)],
19+
```
20+
21+
within ts/js
22+
```js
23+
const app = Vue.createApp({
24+
compilerOptions: {
25+
whitespace: 'preserve'
26+
}
27+
})
28+
```

docs/api-examples.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ outline: deep
44

55
<VueTree>
66
C:/course/
7-
textbook/
7+
textbook/
88
index.md
99
index.md
1010
reading.md
@@ -42,8 +42,9 @@ const { theme, page, frontmatter } = useData()
4242

4343
<script setup>
4444
import { useData } from 'vitepress'
45-
import { VueTree } from '@tlylt/vue-tree'
46-
import '@tlylt/vue-tree/style.css'
45+
import { VueTree } from '../src/index'
46+
// import { VueTree } from '@tlylt/vue-tree'
47+
// import '@tlylt/vue-tree/style.css'
4748

4849
const { site, theme, page, frontmatter } = useData()
4950
</script>

src/components/VueTree.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default defineComponent({
3030
this.treeVisualized = this.treeRaw;
3131
this.treeVisualized = TreeNode.visualize(this.treeRaw);
3232
}
33-
}
33+
},
3434
});
3535
</script>
3636

src/components/tree.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const TOKEN = {
1616
lastChild: '└── ',
1717
connector: '│ ',
1818
space: ' ',
19+
newLine: '\n',
1920
};
2021

2122
export class TreeNode {
@@ -74,7 +75,7 @@ export class TreeNode {
7475
* @return The dummy root node of the tree.
7576
*/
7677
static parse(raw: string): TreeNode {
77-
const lines = raw.split('\n').filter(line => line.trim() !== '');
78+
const lines = raw.split(TOKEN.newLine).filter(line => line.trim() !== '');
7879
const rootNode = new TreeNode('.', null, [], -1); // dummy root node
7980
const prevParentStack = [rootNode];
8081
let prevLevel = rootNode.level;
@@ -113,10 +114,10 @@ export class TreeNode {
113114
return;
114115
}
115116
if (currNode.parent === null) {
116-
result.push(`${currNode.content}\n`);
117+
result.push(`${currNode.content}${TOKEN.newLine}`);
117118
} else {
118119
const tokens = [
119-
'\n',
120+
TOKEN.newLine,
120121
currNode.content,
121122
currNode.getPositionalToken(),
122123
];

0 commit comments

Comments
 (0)