You've already forked obsidian-visualiser
Fix dynamic character sheet loading.
This commit is contained in:
@@ -141,13 +141,13 @@ export class Content
|
||||
const overview = await Content.read('overview', { create: true });
|
||||
try
|
||||
{
|
||||
Content._overview = parse<Record<string, Omit<LocalContent, 'content'>>>(overview);
|
||||
Content._overview = reactive(parse<Record<string, Omit<LocalContent, 'content'>>>(overview));
|
||||
Content._reverseMapping = Object.values(Content._overview).reduce((p, v) => { p[v.path] = v.id; return p; }, {} as Record<string, string>);
|
||||
await Content.pull();
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
Content._overview = {};
|
||||
Content._overview = reactive({});
|
||||
await Content.pull(true);
|
||||
}
|
||||
|
||||
@@ -284,11 +284,12 @@ export class Content
|
||||
}
|
||||
static async push()
|
||||
{
|
||||
const blocked = (await useRequestFetch()('/api/file/overview', { method: 'POST', body: Object.values(Content._overview), cache: 'no-cache' }));
|
||||
const requested = (await useRequestFetch()('/api/file/overview', { method: 'POST', body: Object.values(Content._overview), cache: 'no-cache' }));
|
||||
|
||||
for(const [id, value] of Object.entries(Content._overview).filter(e => !blocked.includes(e[0])))
|
||||
for(let id of requested)
|
||||
{
|
||||
if(value.type === 'folder')
|
||||
const value = Content.get(id);
|
||||
if(!value || value.type === 'folder')
|
||||
continue;
|
||||
|
||||
Content.queue.queue(() => Content.read(id).then(e => {
|
||||
@@ -651,6 +652,7 @@ export class Editor
|
||||
this.tree.update();
|
||||
},
|
||||
redo: (action) => {
|
||||
|
||||
this.tree.tree.remove(action.element.id);
|
||||
if(this.selected === action.element) this.select();
|
||||
action.element.cleanup();
|
||||
@@ -741,11 +743,11 @@ export class Editor
|
||||
{
|
||||
const count = Object.values(Content.files).filter(e => e.title.match(/^Nouveau( \(\d+\))?$/)).length;
|
||||
const item: Recursive<Omit<LocalContent, 'path' | 'content'> & { element?: HTMLElement }> = { id: getID(), navigable: true, private: false, owner: 0, order: nextTo.order + 1, timestamp: new Date(), title: count === 0 ? 'Nouveau' : `Nouveau (${count})`, type: type, parent: nextTo.parent };
|
||||
this.history.add('overview', 'add', [{ element: item, from: undefined, to: nextTo.order + 1 }]);
|
||||
this.history.add('overview', [{ element: item, from: undefined, to: nextTo.order + 1, event: 'add' }]);
|
||||
}
|
||||
private remove(item: LocalContent & { element?: HTMLElement })
|
||||
{
|
||||
this.history.add('overview', 'remove', [{ element: item, from: item.order, to: undefined }], true);
|
||||
this.history.add('overview', [{ element: item, from: item.order, to: undefined, event: 'remove' }, { element: item, from: item.timestamp, to: new Date(), event: 'timestamp' }], true);
|
||||
}
|
||||
private rename(item: LocalContent & { element?: HTMLElement })
|
||||
{
|
||||
@@ -760,7 +762,7 @@ export class Editor
|
||||
|
||||
input.parentElement?.replaceChild(text!, input);
|
||||
input.remove();
|
||||
if(value !== item.title) this.history.add('overview', 'rename', [{ element: item, from: item.title, to: value }], true);
|
||||
if(value !== item.title) this.history.add('overview', [{ element: item, from: item.title, to: value, event: 'rename' }, { element: item, from: item.timestamp, to: new Date(), event: 'timestamp' }], true);
|
||||
}
|
||||
}
|
||||
const text = item.element!.children[0]?.children[1];
|
||||
@@ -773,13 +775,13 @@ export class Editor
|
||||
{
|
||||
cancelPropagation(e);
|
||||
|
||||
this.history.add('overview', 'navigable', [{ element: item, from: item.navigable, to: !item.navigable }], true);
|
||||
this.history.add('overview', [{ element: item, from: item.navigable, to: !item.navigable, event: 'navigable' }, { element: item, from: item.timestamp, to: new Date(), event: 'timestamp' }], true);
|
||||
}
|
||||
private togglePrivate(e: Event, item: LocalContent & { element?: HTMLElement })
|
||||
{
|
||||
cancelPropagation(e);
|
||||
|
||||
this.history.add('overview', 'private', [{ element: item, from: item.private, to: !item.private }], true);
|
||||
this.history.add('overview', [{ element: item, from: item.private, to: !item.private, event: 'private' }, { element: item, from: item.timestamp, to: new Date(), event: 'timestamp' }], true);
|
||||
}
|
||||
private setupDnD(): CleanupFn
|
||||
{
|
||||
@@ -884,13 +886,13 @@ export class Editor
|
||||
return;
|
||||
|
||||
if (instruction.type === 'reorder-above')
|
||||
this.history.add('overview', 'move', [{ element: sourceItem, from: from, to: { parent: (targetItem as Recursive<typeof targetItem>).parent, order: targetItem!.order }}], true);
|
||||
this.history.add('overview', [{ element: sourceItem, from: from, to: { parent: (targetItem as Recursive<typeof targetItem>).parent, order: targetItem!.order }, event: 'move' }, { element: sourceItem, from: sourceItem.timestamp, to: new Date(), event: 'timestamp' }], true);
|
||||
|
||||
if (instruction.type === 'reorder-below')
|
||||
this.history.add('overview', 'move', [{ element: sourceItem, from: from, to: { parent: (targetItem as Recursive<typeof targetItem>).parent, order: targetItem!.order + 1 }}], true);
|
||||
this.history.add('overview', [{ element: sourceItem, from: from, to: { parent: (targetItem as Recursive<typeof targetItem>).parent, order: targetItem!.order + 1 }, event: 'move' }, { element: sourceItem, from: sourceItem.timestamp, to: new Date(), event: 'timestamp' }], true);
|
||||
|
||||
if (instruction.type === 'make-child' && targetItem.type === 'folder')
|
||||
this.history.add('overview', 'move', [{ element: sourceItem, from: from, to: { parent: targetItem, order: 0 }}], true);
|
||||
this.history.add('overview', [{ element: sourceItem, from: from, to: { parent: targetItem, order: 0 }, event: 'move' }, { element: sourceItem, from: sourceItem.timestamp, to: new Date(), event: 'timestamp' }], true);
|
||||
}
|
||||
private render<T extends FileType>(item: LocalContent<T>): Node
|
||||
{
|
||||
@@ -923,6 +925,14 @@ export class Editor
|
||||
{
|
||||
this.cleanup && this.cleanup();
|
||||
}
|
||||
undo()
|
||||
{
|
||||
this.history.undo();
|
||||
}
|
||||
redo()
|
||||
{
|
||||
this.history.redo();
|
||||
}
|
||||
}
|
||||
|
||||
export function getPath(item: Recursive<Omit<LocalContent, 'content'>>): string
|
||||
|
||||
Reference in New Issue
Block a user