You've already forked obsidian-visualiser
Update DB schema to include an ID and split overview and content. Progressing on ContentEditor with the ID fixing many issues. Adding modal and sync features.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Content, getPath, type LocalContent } from "./content.util";
|
||||
import { Content, type LocalContent } from "./content.util";
|
||||
import { dom } from "./dom.util";
|
||||
import { clamp } from "./general.util";
|
||||
|
||||
@@ -17,9 +17,9 @@ export class Tree<T extends Omit<LocalContent, 'content'>>
|
||||
this._flatten = this.accumulate(e => e);
|
||||
}
|
||||
|
||||
remove(path: string)
|
||||
remove(id: string)
|
||||
{
|
||||
const recursive = (data?: Recursive<T>[], parent?: T) => data?.filter(e => getPath(e) !== path)?.map((e, i) => {
|
||||
const recursive = (data?: Recursive<T>[], parent?: T) => data?.filter(e => e.id !== id)?.map((e, i) => {
|
||||
e.order = i;
|
||||
e.children = recursive(e.children as T[], e);
|
||||
return e;
|
||||
@@ -30,9 +30,9 @@ export class Tree<T extends Omit<LocalContent, 'content'>>
|
||||
}
|
||||
insertAt(item: Recursive<T>, pos: number)
|
||||
{
|
||||
const parent = item.parent ? getPath(item.parent) : undefined;
|
||||
const parent = item.parent ? item.parent.id : undefined;
|
||||
const recursive = (data?: Recursive<T>[]) => data?.flatMap(e => {
|
||||
if(getPath(e) === parent)
|
||||
if(e.id === parent)
|
||||
{
|
||||
e.children = e.children ?? [];
|
||||
e.children.splice(clamp(pos, 0, e.children.length), 0, item);
|
||||
@@ -53,7 +53,7 @@ export class Tree<T extends Omit<LocalContent, 'content'>>
|
||||
|
||||
this._flatten = this.accumulate(e => e);
|
||||
}
|
||||
find(path: string): T | undefined
|
||||
find(id: string): T | undefined
|
||||
{
|
||||
const recursive = (data?: Recursive<T>[]): T | undefined => {
|
||||
if(!data)
|
||||
@@ -61,7 +61,7 @@ export class Tree<T extends Omit<LocalContent, 'content'>>
|
||||
|
||||
for(const e of data)
|
||||
{
|
||||
if(getPath(e) === path)
|
||||
if(e.id === id)
|
||||
return e;
|
||||
|
||||
const result = recursive(e.children as T[]);
|
||||
@@ -94,9 +94,9 @@ export class Tree<T extends Omit<LocalContent, 'content'>>
|
||||
|
||||
return recursive(this._data);
|
||||
}
|
||||
subset(path: string): Tree<T> | undefined
|
||||
subset(id: string): Tree<T> | undefined
|
||||
{
|
||||
const subset = this.find(path);
|
||||
const subset = this.find(id);
|
||||
return subset ? new Tree([subset]) : undefined;
|
||||
}
|
||||
each(callback: (item: T, depth: number, parent?: T) => void)
|
||||
|
||||
Reference in New Issue
Block a user