create-aziz-app 3.0.9 → 3.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -271,7 +271,15 @@ export const router = {
|
|
|
271
271
|
};
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
-
// Render
|
|
274
|
+
// Render — preserve focus so inputs don't lose cursor on state update
|
|
275
|
+
const activeEl = document.activeElement;
|
|
276
|
+
const activeId = activeEl?.id || null;
|
|
277
|
+
const activeName = activeEl?.getAttribute?.('name') || null;
|
|
278
|
+
const activePlaceholder = activeEl?.getAttribute?.('placeholder') || null;
|
|
279
|
+
const activeTag = activeEl?.tagName || null;
|
|
280
|
+
const activeCursorStart = activeEl?.selectionStart ?? null;
|
|
281
|
+
const activeCursorEnd = activeEl?.selectionEnd ?? null;
|
|
282
|
+
|
|
275
283
|
root.innerHTML = '';
|
|
276
284
|
const tree = content();
|
|
277
285
|
if (Array.isArray(tree)) {
|
|
@@ -281,6 +289,24 @@ export const router = {
|
|
|
281
289
|
} else if (tree instanceof Node) {
|
|
282
290
|
root.appendChild(tree);
|
|
283
291
|
}
|
|
292
|
+
|
|
293
|
+
// Restore focus to the previously active input
|
|
294
|
+
let restored = null;
|
|
295
|
+
if (activeId) {
|
|
296
|
+
restored = root.querySelector(`#${CSS.escape(activeId)}`);
|
|
297
|
+
}
|
|
298
|
+
if (!restored && activeName) {
|
|
299
|
+
restored = root.querySelector(`[name="${activeName}"]`);
|
|
300
|
+
}
|
|
301
|
+
if (!restored && activePlaceholder && activeTag) {
|
|
302
|
+
restored = root.querySelector(`${activeTag.toLowerCase()}[placeholder="${activePlaceholder}"]`);
|
|
303
|
+
}
|
|
304
|
+
if (restored && typeof restored.focus === 'function') {
|
|
305
|
+
restored.focus();
|
|
306
|
+
if (activeCursorStart !== null && restored.setSelectionRange) {
|
|
307
|
+
try { restored.setSelectionRange(activeCursorStart, activeCursorEnd); } catch {}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
284
310
|
}
|
|
285
311
|
};
|
|
286
312
|
|