feat(workbench): add junction tools workspace shell
This commit is contained in:
1 parent
96833d3a63
commit
2504e8342f
6 files changed
+277
No files matched your search
@@ -0,0 +1,51 @@
|
||||
import type { JunctionDescriptor, JunctionRef } from './hotspots';
|
||||
|
||||
export type JunctionSessionStatus = 'draft' | 'applied' | 'saved' | 'cancelled';
|
||||
export type LeaveAction = 'apply' | 'discard' | 'stay';
|
||||
|
||||
export interface JunctionSession {
|
||||
ref: JunctionRef;
|
||||
status: JunctionSessionStatus;
|
||||
dirty: boolean;
|
||||
openedRevision?: number;
|
||||
appliedRevision?: number;
|
||||
}
|
||||
|
||||
export function createJunctionSession(ref: JunctionRef, revision?: number): JunctionSession {
|
||||
return { ref, status: 'draft', dirty: false, openedRevision: revision };
|
||||
}
|
||||
|
||||
export function markJunctionDraft(session: JunctionSession): JunctionSession {
|
||||
return { ...session, status: 'draft', dirty: true };
|
||||
}
|
||||
|
||||
export function applyJunctionDraft(session: JunctionSession): JunctionSession {
|
||||
return session.dirty
|
||||
? { ...session, status: 'applied', dirty: false, appliedRevision: session.openedRevision }
|
||||
: session;
|
||||
}
|
||||
|
||||
export function saveJunctionSession(session: JunctionSession, currentRevision?: number): JunctionSession {
|
||||
if (
|
||||
session.openedRevision !== undefined &&
|
||||
currentRevision !== undefined &&
|
||||
currentRevision !== session.openedRevision
|
||||
) {
|
||||
throw new Error('路口文档已发生变化,请重新加载后再保存');
|
||||
}
|
||||
return { ...session, status: 'saved', dirty: false, openedRevision: currentRevision ?? session.openedRevision };
|
||||
}
|
||||
|
||||
export function cancelJunctionSession(session: JunctionSession): JunctionSession {
|
||||
return { ...session, status: 'cancelled', dirty: false };
|
||||
}
|
||||
|
||||
export function leaveJunctionSession(session: JunctionSession, action: LeaveAction): JunctionSession | null {
|
||||
if (action === 'stay') return session;
|
||||
if (action === 'discard') return cancelJunctionSession(session);
|
||||
return applyJunctionDraft(session);
|
||||
}
|
||||
|
||||
export function canEditJunction(descriptor: JunctionDescriptor): boolean {
|
||||
return descriptor.ref.type === 'node' && descriptor.status === 'editable';
|
||||
}
|
||||
Reference in new issue
Block a user