MCPcopy Create free account
hub / github.com/astercloud/aster / saveFocusState

Function saveFocusState

ui/src/composables/useStreamingState.ts:163–186  ·  view source on GitHub ↗

* Save currently focused element

()

Source from the content-addressed store, hash-verified

161 * Save currently focused element
162 */
163 function saveFocusState(): void {
164 if (!preserveFocus || !containerRef.value) return;
165
166 const state = getPreservedState(surfaceId);
167 const activeElement = document.activeElement;
168
169 if (activeElement && containerRef.value.contains(activeElement)) {
170 // Try to get a unique identifier for the element
171 const id = activeElement.id
172 || activeElement.getAttribute('data-component-id')
173 || activeElement.getAttribute('name');
174
175 if (id) {
176 state.focusedElementId = id;
177
178 // Save pending input value if it's an input element
179 if (activeElement instanceof HTMLInputElement || activeElement instanceof HTMLTextAreaElement) {
180 state.pendingInputValues.set(id, activeElement.value);
181 }
182 }
183 } else {
184 state.focusedElementId = null;
185 }
186 }
187
188 /**
189 * Restore focus to previously focused element

Callers 1

saveStateFunction · 0.85

Calls 2

getPreservedStateFunction · 0.85
setMethod · 0.45

Tested by

no test coverage detected