mirror of
https://github.com/robonen/tools.git
synced 2026-03-20 02:44:45 +00:00
30 lines
696 B
TypeScript
30 lines
696 B
TypeScript
export interface FocusScopeAPI {
|
|
paused: boolean;
|
|
pause: () => void;
|
|
resume: () => void;
|
|
}
|
|
|
|
const stack: FocusScopeAPI[] = [];
|
|
|
|
export function createFocusScopesStack() {
|
|
return {
|
|
add(focusScope: FocusScopeAPI) {
|
|
const current = stack.at(-1);
|
|
if (focusScope !== current) current?.pause();
|
|
|
|
// Remove if already in stack (deduplicate), then push to top
|
|
const index = stack.indexOf(focusScope);
|
|
if (index !== -1) stack.splice(index, 1);
|
|
|
|
stack.push(focusScope);
|
|
},
|
|
|
|
remove(focusScope: FocusScopeAPI) {
|
|
const index = stack.indexOf(focusScope);
|
|
if (index !== -1) stack.splice(index, 1);
|
|
|
|
stack.at(-1)?.resume();
|
|
},
|
|
};
|
|
}
|