intelliwaketssveltekitv25 1.0.54 → 1.0.56
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/dist/Functions.d.ts +4 -1
- package/dist/Functions.js +33 -37
- package/package.json +1 -1
package/dist/Functions.d.ts
CHANGED
|
@@ -34,7 +34,10 @@ export declare const DoIDsMatch: (a: any, b: any) => boolean;
|
|
|
34
34
|
* - `update(nextEnabled: boolean)`: Updates the enabled state.
|
|
35
35
|
* - `destroy()`: Cancels the auto-focus behavior and cleans up resources.
|
|
36
36
|
*/
|
|
37
|
-
export declare function autoFocus(el: HTMLElement | HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement
|
|
37
|
+
export declare function autoFocus(el: HTMLElement | HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement, enabled?: boolean): {
|
|
38
|
+
update(nextEnabled: boolean): void;
|
|
39
|
+
destroy(): void;
|
|
40
|
+
};
|
|
38
41
|
export declare function autoGrow(node: HTMLTextAreaElement, _value?: string | null): {
|
|
39
42
|
update(): void;
|
|
40
43
|
destroy(): void;
|
package/dist/Functions.js
CHANGED
|
@@ -184,46 +184,42 @@ export const DoIDsMatch = (a, b) => IsEqual(a, b) || IsEqual(a?.id, b?.id);
|
|
|
184
184
|
* - `update(nextEnabled: boolean)`: Updates the enabled state.
|
|
185
185
|
* - `destroy()`: Cancels the auto-focus behavior and cleans up resources.
|
|
186
186
|
*/
|
|
187
|
+
export function autoFocus(el, enabled = true) {
|
|
188
|
+
let cancelled = false;
|
|
189
|
+
async function run() {
|
|
190
|
+
if (!enabled)
|
|
191
|
+
return;
|
|
192
|
+
await tick();
|
|
193
|
+
if (cancelled)
|
|
194
|
+
return;
|
|
195
|
+
// Avoid focusing detached nodes
|
|
196
|
+
if (!el.isConnected)
|
|
197
|
+
return;
|
|
198
|
+
// Sometimes modals need the next frame (transitions/portals)
|
|
199
|
+
requestAnimationFrame(() => {
|
|
200
|
+
if (!cancelled)
|
|
201
|
+
el.focus();
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
void run();
|
|
205
|
+
return {
|
|
206
|
+
update(nextEnabled) {
|
|
207
|
+
enabled = nextEnabled;
|
|
208
|
+
void run();
|
|
209
|
+
},
|
|
210
|
+
destroy() {
|
|
211
|
+
cancelled = true;
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
}
|
|
187
215
|
// export function autoFocus(
|
|
188
|
-
// el: HTMLElement | HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement
|
|
189
|
-
// enabled: boolean = true
|
|
216
|
+
// el: HTMLElement | HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement | never
|
|
190
217
|
// ) {
|
|
191
|
-
//
|
|
192
|
-
//
|
|
193
|
-
//
|
|
194
|
-
//
|
|
195
|
-
//
|
|
196
|
-
// await tick()
|
|
197
|
-
// if (cancelled) return
|
|
198
|
-
//
|
|
199
|
-
// // Avoid focusing detached nodes
|
|
200
|
-
// if (!el.isConnected) return
|
|
201
|
-
//
|
|
202
|
-
// // Sometimes modals need the next frame (transitions/portals)
|
|
203
|
-
// requestAnimationFrame(() => {
|
|
204
|
-
// if (!cancelled) el.focus()
|
|
205
|
-
// })
|
|
206
|
-
// }
|
|
207
|
-
//
|
|
208
|
-
// void run()
|
|
209
|
-
//
|
|
210
|
-
// return {
|
|
211
|
-
// update(nextEnabled: boolean) {
|
|
212
|
-
// enabled = nextEnabled
|
|
213
|
-
// void run()
|
|
214
|
-
// },
|
|
215
|
-
// destroy() {
|
|
216
|
-
// cancelled = true
|
|
217
|
-
// }
|
|
218
|
-
// }
|
|
218
|
+
// tick().then(() => {
|
|
219
|
+
// if (!el) console.error('autoFocus el not available')
|
|
220
|
+
// el?.focus()
|
|
221
|
+
// })
|
|
219
222
|
// }
|
|
220
|
-
export function autoFocus(el) {
|
|
221
|
-
tick().then(() => {
|
|
222
|
-
if (!el)
|
|
223
|
-
console.error('autoFocus el not available');
|
|
224
|
-
el?.focus();
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
223
|
export function autoGrow(node, _value) {
|
|
228
224
|
let userResized = false;
|
|
229
225
|
let pointerDown = false;
|