$emit('note-open', ...args)" />
`
export default {
name: 'LinkTree',
props: ['filename', 'title', 'linenum', 'direction'],
emits: ['note-open'],
data() {
return {
expanded: false,
children: [],
}
},
methods: {
toggle() {
this.expanded = !this.expanded;
if (this.expanded && this.children.length === 0) {
this.fetchChildren();
}
},
fetchChildren() {
fetch('/api/raw/links?color=true&filename=' + this.filename)
.then(response => response.text())
.then(text => {
const PATTERN = /^(.*?):(.*?):\s*(?:\x1b\[0;36m(.*?)\x1b\[0m\s*)?(.*)$/
this.children = text.trim().split('\n').map(line => {
const matches = PATTERN.exec(line);
if (!matches) return null;
const Filename = matches[1];
const Linenum = parseInt(matches[2], 10);
const Colored = matches[3] || '';
const Content = matches[4];
return { title: Content, filename: Filename, linenum: (Colored == 'outgoing') ? 1 : Linenum, direction: Colored };
}).filter(Boolean);
});
},
},
template: t
}