Eingebette Loops
This commit is contained in:
1 parent
684217bdf4
commit
5a171987b2
5 files changed
+722
-50
No files matched your search
@@ -7,6 +7,7 @@ export interface LoopRuntimeState {
|
||||
items: unknown[]; // Committed items
|
||||
draft: Record<string, unknown>; // Current draft being edited
|
||||
editIndex: number | null; // Index of item being edited, or null for new item
|
||||
activeItemStepIndex: number; // Current step index in subwizard (0-based)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -17,6 +18,7 @@ export function createLoopState(): LoopRuntimeState {
|
||||
items: [],
|
||||
draft: {},
|
||||
editIndex: null,
|
||||
activeItemStepIndex: 0,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -94,6 +96,7 @@ export function commitDraft(state: LoopRuntimeState): LoopRuntimeState {
|
||||
items: newItems,
|
||||
draft: {},
|
||||
editIndex: null,
|
||||
activeItemStepIndex: 0,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -117,6 +120,7 @@ export function startEdit(
|
||||
...state,
|
||||
draft: { ...(item as Record<string, unknown>) },
|
||||
editIndex: index,
|
||||
activeItemStepIndex: 0, // Reset to first step when starting edit
|
||||
};
|
||||
}
|
||||
|
||||
@@ -152,6 +156,7 @@ export function deleteItem(
|
||||
editIndex: newEditIndex,
|
||||
// Clear draft if we were editing the deleted item
|
||||
draft: newEditIndex === null ? {} : state.draft,
|
||||
activeItemStepIndex: newEditIndex === null ? 0 : state.activeItemStepIndex,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -229,5 +234,64 @@ export function clearDraft(state: LoopRuntimeState): LoopRuntimeState {
|
||||
...state,
|
||||
draft: {},
|
||||
editIndex: null,
|
||||
activeItemStepIndex: 0,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Set active item step index.
|
||||
*/
|
||||
export function setActiveItemStepIndex(
|
||||
state: LoopRuntimeState,
|
||||
index: number
|
||||
): LoopRuntimeState {
|
||||
if (index < 0) {
|
||||
return state; // Invalid index
|
||||
}
|
||||
|
||||
return {
|
||||
...state,
|
||||
activeItemStepIndex: index,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Move to next step in item subwizard.
|
||||
*/
|
||||
export function itemNextStep(
|
||||
state: LoopRuntimeState,
|
||||
childStepCount: number
|
||||
): LoopRuntimeState {
|
||||
if (state.activeItemStepIndex >= childStepCount - 1) {
|
||||
return state; // Already at last step
|
||||
}
|
||||
|
||||
return {
|
||||
...state,
|
||||
activeItemStepIndex: state.activeItemStepIndex + 1,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Move to previous step in item subwizard.
|
||||
*/
|
||||
export function itemPrevStep(state: LoopRuntimeState): LoopRuntimeState {
|
||||
if (state.activeItemStepIndex <= 0) {
|
||||
return state; // Already at first step
|
||||
}
|
||||
|
||||
return {
|
||||
...state,
|
||||
activeItemStepIndex: state.activeItemStepIndex - 1,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset item wizard to first step.
|
||||
*/
|
||||
export function resetItemWizard(state: LoopRuntimeState): LoopRuntimeState {
|
||||
return {
|
||||
...state,
|
||||
activeItemStepIndex: 0,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user