Remove undo redo support from flow editor
This commit is contained in:
parent
a82afa3999
commit
4d3f35a422
|
|
@ -344,7 +344,7 @@ export class GenericNodeComponent {
|
|||
private markFlowDirty() {
|
||||
const flow = this.editorState.currentFlow();
|
||||
if (!flow) return;
|
||||
this.editorState.updateData(flow.data);
|
||||
this.editorState.updateData(this.cloneFlowData(flow.data));
|
||||
}
|
||||
|
||||
private async loadSchemaContext() {
|
||||
|
|
@ -809,6 +809,13 @@ export class GenericNodeComponent {
|
|||
});
|
||||
}
|
||||
|
||||
private cloneFlowData<T>(value: T): T {
|
||||
if (typeof globalThis.structuredClone === 'function') {
|
||||
return globalThis.structuredClone(value);
|
||||
}
|
||||
return JSON.parse(JSON.stringify(value)) as T;
|
||||
}
|
||||
|
||||
private maybeCreateBlockOnServer() {
|
||||
const nodeData = this.data?.data as Record<string, unknown> | undefined;
|
||||
if (!nodeData?.['__needsServerCreate']) return;
|
||||
|
|
|
|||
|
|
@ -159,6 +159,7 @@ export class ReteEditor implements OnChanges, OnDestroy {
|
|||
if (this.readonly()) return;
|
||||
this.syncNodePositionFromContext(rete, context);
|
||||
if (this.flowState.currentFlow()?.id !== this.flowId()) return;
|
||||
|
||||
const updatedData = exportGraph(rete.editor);
|
||||
this.flowState.updateData(updatedData);
|
||||
this.flowChanged.emit(updatedData);
|
||||
|
|
|
|||
|
|
@ -52,25 +52,6 @@
|
|||
<i class="bi bi-save"></i>
|
||||
</button>
|
||||
|
||||
<div class="w-px h-5 bg-gray-200 mx-2"></div>
|
||||
|
||||
<button tabindex="-1"
|
||||
class="border-0
|
||||
flex items-center gap-1
|
||||
enabled:hover:bg-gray-100 enabled:text-gray-600 disabled:text-gray-300 p-1"
|
||||
title="Undo" [disabled]="!editorState.undoEnabled()" (click)="undo()">
|
||||
<i class="bi bi-arrow-counterclockwise"></i>
|
||||
</button>
|
||||
|
||||
<button tabindex="-1"
|
||||
class="border-0
|
||||
flex items-center gap-1
|
||||
enabled:hover:bg-gray-100 enabled:text-gray-600 disabled:text-gray-300 p-1"
|
||||
[disabled]="!editorState.redoEnabled()"
|
||||
title="Redo" (click)="redo()">
|
||||
<i class="bi bi-arrow-clockwise"></i>
|
||||
</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -66,14 +66,6 @@ export class TitleToolbar {
|
|||
});
|
||||
}
|
||||
|
||||
undo() {
|
||||
this.editorState.undo();
|
||||
}
|
||||
|
||||
redo() {
|
||||
this.editorState.redo();
|
||||
}
|
||||
|
||||
execute() {
|
||||
const flow = this.flow();
|
||||
if (!flow || !this.canExecute() || this.executeLoading()) return;
|
||||
|
|
|
|||
|
|
@ -18,13 +18,6 @@ export class EditorStateHolder {
|
|||
|
||||
constructor(private confirm: ConfirmDialogService) { }
|
||||
|
||||
|
||||
previousDataStack : FlowData[] = [];
|
||||
nextDataStack : FlowData[] = [];
|
||||
|
||||
redoEnabled = computed(() => this.nextDataStack.length > 0);
|
||||
undoEnabled = computed(() => this.previousDataStack.length > 1);
|
||||
|
||||
/** Intent: open document */
|
||||
async openDocument(doc: Flow, options?: { skipDirtyCheck?: boolean }): Promise<boolean> {
|
||||
if (this.isDirty() && !options?.skipDirtyCheck) {
|
||||
|
|
@ -60,22 +53,17 @@ export class EditorStateHolder {
|
|||
const current = this.currentFlow();
|
||||
if (!current) return;
|
||||
|
||||
this.currentFlow.update(flow => {
|
||||
if (!flow) return flow;
|
||||
return { ...flow, data };
|
||||
});
|
||||
this.previousDataStack.push(data);
|
||||
const nextFlow = { ...current, data };
|
||||
this.currentFlow.set(nextFlow);
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
updateFlowTitle(newTitle: string) {
|
||||
const flow = this.currentFlow();
|
||||
if (!flow) return;
|
||||
this.currentFlow.update(flow => {
|
||||
if (!flow) return flow;
|
||||
return { ...flow, name: newTitle };
|
||||
});
|
||||
this.previousDataStack.push(flow.data);
|
||||
const current = this.currentFlow();
|
||||
if (!current) return;
|
||||
|
||||
const nextFlow = { ...current, name: newTitle };
|
||||
this.currentFlow.set(nextFlow);
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
|
|
@ -87,26 +75,4 @@ export class EditorStateHolder {
|
|||
})
|
||||
)
|
||||
}
|
||||
|
||||
undo() {
|
||||
const stack = this.previousDataStack;
|
||||
if (stack.length < 2) return; // Nothing to undo
|
||||
|
||||
// Remove the current state
|
||||
this.nextDataStack.push(stack.pop()!);
|
||||
// Get the previous state
|
||||
const previousData = stack[stack.length - 1];
|
||||
this.updateData(previousData);
|
||||
}
|
||||
|
||||
redo() {
|
||||
const stack = this.nextDataStack;
|
||||
if (stack.length === 0) return; // Nothing to redo
|
||||
|
||||
const nextData = stack.pop()!;
|
||||
this.previousDataStack.push(nextData);
|
||||
this.updateData(nextData);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ export function exportGraph(editor: NodeEditor<HFSchemes>) {
|
|||
position: blockData?.position,
|
||||
inputs,
|
||||
outputs,
|
||||
specificConfiguration: blockData?.specificConfiguration ?? {},
|
||||
specificConfiguration: cloneValue(blockData?.specificConfiguration ?? {}),
|
||||
typeName: blockData?.typeName ?? "LLMBlock"
|
||||
};
|
||||
});
|
||||
|
|
@ -140,7 +140,7 @@ export async function addBlockToEditor(
|
|||
await addBlockToEditor(editor, area, { ...createdBlock, position: currentPosition }, currentPosition);
|
||||
};
|
||||
node.data = {
|
||||
...block,
|
||||
...cloneValue(block),
|
||||
position: position ?? block.position,
|
||||
deleteNode: removeNode,
|
||||
replaceWithCreatedBlock
|
||||
|
|
@ -206,3 +206,10 @@ function toNodeLabel(typeName: string) {
|
|||
if (typeName === "OutputBlock") return "Output";
|
||||
return typeName;
|
||||
}
|
||||
|
||||
function cloneValue<T>(value: T): T {
|
||||
if (typeof globalThis.structuredClone === "function") {
|
||||
return globalThis.structuredClone(value);
|
||||
}
|
||||
return JSON.parse(JSON.stringify(value)) as T;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue