@t007/utils 0.0.35 → 0.0.37
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/{chunk-ZALPHCSJ.js → chunk-4S4VEQL7.js} +4 -4
- package/dist/{chunk-NX2LWYD6.js → chunk-7TIUDIEW.js} +2 -2
- package/dist/hooks/react.cjs +1 -1
- package/dist/hooks/react.js +5 -5
- package/dist/hooks/vanilla.cjs +1 -1
- package/dist/hooks/vanilla.js +2 -2
- package/dist/index.cjs +4 -4
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1 -1
- package/package.json +2 -2
|
@@ -21,7 +21,7 @@ function loadResource(req, type = "style", { module, media, crossOrigin, integri
|
|
|
21
21
|
console.warn(`Retrying ${type} load for "${src}" (${attempts - remaining + 1})...`);
|
|
22
22
|
} else {
|
|
23
23
|
delete win.t007._resourceCache[src];
|
|
24
|
-
reject(new Error(`${capitalize(type)} load failed for "${src}"
|
|
24
|
+
reject(new Error(`${capitalize(type)} load failed for "${src}"`));
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
const url = retryKey && remaining < attempts ? `${src}${src.includes("?") ? "&" : "?"}_${retryKey}=${Date.now()}` : src;
|
|
@@ -56,7 +56,7 @@ function createListRenderer({ container, getKey, createNode, updateNode = NOOP,
|
|
|
56
56
|
continue;
|
|
57
57
|
}
|
|
58
58
|
oldIndices.push(-1);
|
|
59
|
-
} else updateNode(node, item), oldIndices.push(oldPositions.get(node) ?? -1);
|
|
59
|
+
} else updateNode(node, item, i), oldIndices.push(oldPositions.get(node) ?? -1);
|
|
60
60
|
seenKeys.add(key), futureNodes.push(node), newRegistry.set(key, node);
|
|
61
61
|
}
|
|
62
62
|
for (const [key, node] of nodeRegistry.entries()) !seenKeys.has(key) && node.parentElement === container && (destroyNode(node, key), node.remove());
|
|
@@ -206,10 +206,10 @@ function RAFLoop(key, fn, signal, win) {
|
|
|
206
206
|
}
|
|
207
207
|
var cancelRAFLoop = (key) => t007._RAFLoopers ? t007._RAFLoopers.delete(key) : false;
|
|
208
208
|
function limited(FN_KEY, fn, opts = {}) {
|
|
209
|
-
let count = 0, { key, maxTimes: max = 1,
|
|
209
|
+
let count = 0, { key, maxTimes: max = 1, perSession = key != null } = isStr(opts) ? { key: opts } : opts;
|
|
210
210
|
const getReg = () => JSON.parse(localStorage.getItem(FN_KEY) || "{}"), setReg = (r) => localStorage.setItem(FN_KEY, JSON.stringify(r));
|
|
211
211
|
const handle = (...args) => {
|
|
212
|
-
if (
|
|
212
|
+
if (perSession && count >= +perSession) return;
|
|
213
213
|
if (!key) return count++ < max ? fn(...args) : void 0;
|
|
214
214
|
const r = getReg(), c = r[key] || 0;
|
|
215
215
|
return c < max ? (count++, r[key] = c + 1, setReg(r), fn(...args)) : void 0;
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
createEl,
|
|
5
5
|
getActiveEl,
|
|
6
6
|
isInteractive
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-4S4VEQL7.js";
|
|
8
8
|
|
|
9
9
|
// src/ts/hooks/vanilla/outsideClick.ts
|
|
10
10
|
import { NIL, NOOP } from "sia-reactor";
|
|
@@ -140,7 +140,7 @@ var NAV_KEYS = [...H_NAV_KEYS, ...V_NAV_KEYS];
|
|
|
140
140
|
var DEFAULT_CONFIG = {
|
|
141
141
|
enabled: null,
|
|
142
142
|
selector: "[data-arrow-item]",
|
|
143
|
-
focusOnHover:
|
|
143
|
+
focusOnHover: false,
|
|
144
144
|
loop: true,
|
|
145
145
|
virtual: false,
|
|
146
146
|
typeahead: false,
|
package/dist/hooks/react.cjs
CHANGED
package/dist/hooks/react.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useHighlight
|
|
3
|
-
} from "../chunk-RXMKMD3E.js";
|
|
4
1
|
import {
|
|
5
2
|
DEFAULT_CONFIG,
|
|
6
3
|
H_NAV_KEYS,
|
|
@@ -11,11 +8,14 @@ import {
|
|
|
11
8
|
initFocusTrap,
|
|
12
9
|
initOutsideClick,
|
|
13
10
|
rippleHandler
|
|
14
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-7TIUDIEW.js";
|
|
15
12
|
import {
|
|
16
13
|
INTERACTIVE_SELECTOR,
|
|
17
14
|
getActiveEl
|
|
18
|
-
} from "../chunk-
|
|
15
|
+
} from "../chunk-4S4VEQL7.js";
|
|
16
|
+
import {
|
|
17
|
+
useHighlight
|
|
18
|
+
} from "../chunk-RXMKMD3E.js";
|
|
19
19
|
|
|
20
20
|
// src/ts/hooks/react/useScrollAssist.ts
|
|
21
21
|
import { useEffect, useRef, useCallback } from "react";
|
package/dist/hooks/vanilla.cjs
CHANGED
package/dist/hooks/vanilla.js
CHANGED
|
@@ -11,12 +11,12 @@ import {
|
|
|
11
11
|
removeOutsideClick,
|
|
12
12
|
rippleHandler,
|
|
13
13
|
syncFocusTrap
|
|
14
|
-
} from "../chunk-
|
|
14
|
+
} from "../chunk-7TIUDIEW.js";
|
|
15
15
|
import {
|
|
16
16
|
INTERACTIVE_SELECTOR,
|
|
17
17
|
createEl,
|
|
18
18
|
getActiveEl
|
|
19
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-4S4VEQL7.js";
|
|
20
20
|
|
|
21
21
|
// src/ts/hooks/vanilla/scrollAssist.ts
|
|
22
22
|
import { NIL } from "sia-reactor";
|
package/dist/index.cjs
CHANGED
|
@@ -107,7 +107,7 @@ function loadResource(req, type = "style", { module: module2, media, crossOrigin
|
|
|
107
107
|
console.warn(`Retrying ${type} load for "${src}" (${attempts - remaining + 1})...`);
|
|
108
108
|
} else {
|
|
109
109
|
delete win.t007._resourceCache[src];
|
|
110
|
-
reject(new Error(`${capitalize(type)} load failed for "${src}"
|
|
110
|
+
reject(new Error(`${capitalize(type)} load failed for "${src}"`));
|
|
111
111
|
}
|
|
112
112
|
};
|
|
113
113
|
const url = retryKey && remaining < attempts ? `${src}${src.includes("?") ? "&" : "?"}_${retryKey}=${Date.now()}` : src;
|
|
@@ -142,7 +142,7 @@ function createListRenderer({ container, getKey, createNode, updateNode = import
|
|
|
142
142
|
continue;
|
|
143
143
|
}
|
|
144
144
|
oldIndices.push(-1);
|
|
145
|
-
} else updateNode(node, item), oldIndices.push(oldPositions.get(node) ?? -1);
|
|
145
|
+
} else updateNode(node, item, i), oldIndices.push(oldPositions.get(node) ?? -1);
|
|
146
146
|
seenKeys.add(key), futureNodes.push(node), newRegistry.set(key, node);
|
|
147
147
|
}
|
|
148
148
|
for (const [key, node] of nodeRegistry.entries()) !seenKeys.has(key) && node.parentElement === container && (destroyNode(node, key), node.remove());
|
|
@@ -292,10 +292,10 @@ function RAFLoop(key, fn, signal, win) {
|
|
|
292
292
|
}
|
|
293
293
|
var cancelRAFLoop = (key) => t007._RAFLoopers ? t007._RAFLoopers.delete(key) : false;
|
|
294
294
|
function limited(FN_KEY, fn, opts = {}) {
|
|
295
|
-
let count = 0, { key, maxTimes: max = 1,
|
|
295
|
+
let count = 0, { key, maxTimes: max = 1, perSession = key != null } = isStr(opts) ? { key: opts } : opts;
|
|
296
296
|
const getReg = () => JSON.parse(localStorage.getItem(FN_KEY) || "{}"), setReg = (r) => localStorage.setItem(FN_KEY, JSON.stringify(r));
|
|
297
297
|
const handle = (...args) => {
|
|
298
|
-
if (
|
|
298
|
+
if (perSession && count >= +perSession) return;
|
|
299
299
|
if (!key) return count++ < max ? fn(...args) : void 0;
|
|
300
300
|
const r = getReg(), c = r[key] || 0;
|
|
301
301
|
return c < max ? (count++, r[key] = c + 1, setReg(r), fn(...args)) : void 0;
|
package/dist/index.d.cts
CHANGED
|
@@ -182,8 +182,8 @@ interface LimitedOptions {
|
|
|
182
182
|
key?: string;
|
|
183
183
|
/** Maximum number of allowed calls. @default 1 */
|
|
184
184
|
maxTimes?: number;
|
|
185
|
-
/** Only allow calling
|
|
186
|
-
|
|
185
|
+
/** Only allow calling x times per session, regardless of maxTimes. @default true */
|
|
186
|
+
perSession?: boolean | number;
|
|
187
187
|
}
|
|
188
188
|
interface LimitedHandle<T extends (...args: any[]) => any> {
|
|
189
189
|
/** Call the wrapped function with the original arguments. */
|
|
@@ -286,8 +286,9 @@ type ListRendererOptions<T, El extends HTMLElement = HTMLElement> = {
|
|
|
286
286
|
/** Optional function to update an existing node with new item data, called when an item is reused.
|
|
287
287
|
* @param node The existing DOM node for the item
|
|
288
288
|
* @param item The new item data to update the node with
|
|
289
|
+
* @param index The new index of the item in the array
|
|
289
290
|
*/
|
|
290
|
-
updateNode?: (node: El, item: T) => void;
|
|
291
|
+
updateNode?: (node: El, item: T, index: number) => void;
|
|
291
292
|
/** Optional function to clean up a DOM node when an item is removed, called before the node is removed from the DOM.
|
|
292
293
|
* @param node The DOM node to be removed
|
|
293
294
|
* @param key The unique key of the item associated with the node
|
package/dist/index.d.ts
CHANGED
|
@@ -182,8 +182,8 @@ interface LimitedOptions {
|
|
|
182
182
|
key?: string;
|
|
183
183
|
/** Maximum number of allowed calls. @default 1 */
|
|
184
184
|
maxTimes?: number;
|
|
185
|
-
/** Only allow calling
|
|
186
|
-
|
|
185
|
+
/** Only allow calling x times per session, regardless of maxTimes. @default true */
|
|
186
|
+
perSession?: boolean | number;
|
|
187
187
|
}
|
|
188
188
|
interface LimitedHandle<T extends (...args: any[]) => any> {
|
|
189
189
|
/** Call the wrapped function with the original arguments. */
|
|
@@ -286,8 +286,9 @@ type ListRendererOptions<T, El extends HTMLElement = HTMLElement> = {
|
|
|
286
286
|
/** Optional function to update an existing node with new item data, called when an item is reused.
|
|
287
287
|
* @param node The existing DOM node for the item
|
|
288
288
|
* @param item The new item data to update the node with
|
|
289
|
+
* @param index The new index of the item in the array
|
|
289
290
|
*/
|
|
290
|
-
updateNode?: (node: El, item: T) => void;
|
|
291
|
+
updateNode?: (node: El, item: T, index: number) => void;
|
|
291
292
|
/** Optional function to clean up a DOM node when an item is removed, called before the node is removed from the DOM.
|
|
292
293
|
* @param node The DOM node to be removed
|
|
293
294
|
* @param key The unique key of the item associated with the node
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@t007/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.37",
|
|
4
4
|
"description": "High-performance utilities for the t007 ecosystem.",
|
|
5
5
|
"author": "Oketade Oluwatobiloba <tobioketade007@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"react-dom": "^18.3.1"
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
|
-
"sia-reactor": "^0.0.
|
|
79
|
+
"sia-reactor": "^0.0.38"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
82
|
"react": "^18.0.0"
|