Add ability to reposition nodes and insert before/after
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -91,6 +91,32 @@ export class EditorService {
|
||||
}));
|
||||
|
||||
await this.saveNodesAsPage(this.currentPage, this.currentNodes);
|
||||
this.dirtyOverride = false;
|
||||
}
|
||||
|
||||
async moveNode(node: HostRecord, direction: 'up' | 'down') {
|
||||
if ( !this.currentPage ) {
|
||||
throw new NoPageLoadedError();
|
||||
}
|
||||
|
||||
const nodeIndex = this.currentNodes.findIndex(maybeNode => maybeNode.UUID === node.UUID);
|
||||
if ( nodeIndex < 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( direction === 'up' && nodeIndex > 0 ) {
|
||||
const otherIdx = nodeIndex - 1;
|
||||
const otherNode = this.currentNodes[otherIdx];
|
||||
this.currentNodes[otherIdx] = this.currentNodes[nodeIndex];
|
||||
this.currentNodes[nodeIndex] = otherNode;
|
||||
} else if ( direction === 'down' && nodeIndex !== (this.currentNodes.length - 1) ) {
|
||||
const otherIdx = nodeIndex + 1;
|
||||
const otherNode = this.currentNodes[otherIdx];
|
||||
this.currentNodes[otherIdx] = this.currentNodes[nodeIndex];
|
||||
this.currentNodes[nodeIndex] = otherNode;
|
||||
}
|
||||
|
||||
this.dirtyOverride = true;
|
||||
}
|
||||
|
||||
async saveNodesAsPage(page: PageRecord, nodes: HostRecord[]): Promise<HostRecord[]> {
|
||||
|
||||
Reference in New Issue
Block a user