Govern task context and advance execution pointer
This commit is contained in:
@@ -11,6 +11,12 @@ export interface InputModalState {
|
||||
mainCommitCount: number;
|
||||
}
|
||||
|
||||
export interface InputModalEvent {
|
||||
type: "pointerdown" | "pointerup" | "pointercancel";
|
||||
pointerType: "touch" | "pen";
|
||||
pointerId: number;
|
||||
}
|
||||
|
||||
export function createInputModalState(): InputModalState {
|
||||
return { schemaVersion: 1, kind: "NONE", activePointerIds: [], cancelled: false, navigationRevision: 0, mainCommitCount: 0 };
|
||||
}
|
||||
@@ -39,3 +45,15 @@ export function commitPenStroke(state: InputModalState, pointerId: number): Inpu
|
||||
if (state.kind !== "PEN_STROKE" || !state.activePointerIds.includes(pointerId) || state.cancelled) return state;
|
||||
return { ...state, kind: "NONE", activePointerIds: [], mainCommitCount: state.mainCommitCount + 1 };
|
||||
}
|
||||
|
||||
export function reduceInputModal(state: InputModalState, event: InputModalEvent): InputModalState {
|
||||
if (!Number.isSafeInteger(event.pointerId) || event.pointerId < 0) throw new Error("POINTER_ID_INVALID");
|
||||
if (event.pointerType === "touch") {
|
||||
if (event.type === "pointerdown") return beginTouch(state, event.pointerId);
|
||||
if (event.type === "pointerup") return endTouch(state, event.pointerId);
|
||||
return cancelInputModal(state);
|
||||
}
|
||||
if (event.type === "pointerdown") return beginPenStroke(state, event.pointerId);
|
||||
if (event.type === "pointerup") return commitPenStroke(state, event.pointerId);
|
||||
return cancelInputModal(state);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user