@t007/input 0.0.31 → 0.0.32
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/index.d.ts +8 -5
- package/dist/index.global.js +42 -24
- package/package.json +4 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "@t007/utils";
|
|
2
|
-
import { BaseProps, CheckboxInputAddon, DateInputAddon, FileInputAddon, SelectElementAddon } from "../react";
|
|
2
|
+
import { t007InputElement, BaseProps, CheckboxInputAddon, DateInputAddon, FileInputAddon, SelectElementAddon } from "../react";
|
|
3
3
|
|
|
4
4
|
interface BaseOptions extends Omit<BaseProps, "error"> {
|
|
5
5
|
/** Visible label text. */
|
|
@@ -50,7 +50,7 @@ export interface FormManager {
|
|
|
50
50
|
/** Toggle the filled state on a supported field.
|
|
51
51
|
* @param input Supported form control.
|
|
52
52
|
*/
|
|
53
|
-
toggleFilled(input:
|
|
53
|
+
toggleFilled(input: t007InputElement): void;
|
|
54
54
|
/** Attach a fallback helper node.
|
|
55
55
|
* @param field Field wrapper element.
|
|
56
56
|
*/
|
|
@@ -67,7 +67,10 @@ export interface FormManager {
|
|
|
67
67
|
* @param options Field configuration.
|
|
68
68
|
* @returns Created field element.
|
|
69
69
|
*/
|
|
70
|
-
field(options:
|
|
70
|
+
field(options: SelectFieldOptions): HTMLDivElement & { inputEl: HTMLSelectElement };
|
|
71
|
+
field(options: TextareaFieldOptions): HTMLDivElement & { inputEl: HTMLTextAreaElement };
|
|
72
|
+
field(options: PasswordFieldOptions | FileFieldOptions | CheckboxFieldOptions | DateFieldOptions | GenericFieldOptions): HTMLDivElement & { inputEl: HTMLInputElement };
|
|
73
|
+
field(options: FieldOptions): HTMLDivElement & { inputEl: t007InputElement };
|
|
71
74
|
/** Validate a form and attach the proper hooks.
|
|
72
75
|
* @param form Form element to validate.
|
|
73
76
|
*/
|
|
@@ -95,9 +98,9 @@ declare global {
|
|
|
95
98
|
/** Public form manager singleton. */
|
|
96
99
|
formManager: FormManager;
|
|
97
100
|
/** Public field factory. */
|
|
98
|
-
field
|
|
101
|
+
field: FormManager["field"];
|
|
99
102
|
/** Public form validation helper. */
|
|
100
|
-
handleFormValidation
|
|
103
|
+
handleFormValidation: FormManager["handleFormValidation"];
|
|
101
104
|
}
|
|
102
105
|
interface Window {
|
|
103
106
|
field?: T007Namespace["field"];
|
package/dist/index.global.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
(() => {
|
|
3
|
-
// ../../../sia-reactor/dist/chunk-
|
|
3
|
+
// ../../../sia-reactor/dist/chunk-243U74PP.js
|
|
4
4
|
function createEl(tag, props, dataset, styles, el = tag ? document?.createElement(tag) : null) {
|
|
5
|
-
return assignEl(el, props, dataset, styles)
|
|
5
|
+
return assignEl(el, props, dataset, styles);
|
|
6
6
|
}
|
|
7
7
|
function assignEl(el, props, dataset, styles) {
|
|
8
|
-
if (!el) return;
|
|
8
|
+
if (!el) return null;
|
|
9
9
|
if (props) {
|
|
10
10
|
for (const k of Object.keys(props)) if (props[k] !== void 0) el[k] = props[k];
|
|
11
11
|
}
|
|
@@ -15,50 +15,64 @@
|
|
|
15
15
|
if (styles) {
|
|
16
16
|
for (const k of Object.keys(styles)) if (styles[k] !== void 0) el.style[k] = styles[k];
|
|
17
17
|
}
|
|
18
|
+
return el;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
// ../../../sia-reactor/dist/chunk-
|
|
21
|
+
// ../../../sia-reactor/dist/chunk-2ZYYYSZ4.js
|
|
22
|
+
var RTR_BATCH = "undefined" !== typeof window ? ("undefined" !== typeof queueMicrotask ? queueMicrotask : setTimeout).bind(window) : "undefined" !== typeof process && process.nextTick ? process.nextTick : setTimeout;
|
|
23
|
+
var RTR_LOG = console.log.bind(console, "[S.I.A Reactor]");
|
|
24
|
+
var NIL = Object.freeze({});
|
|
21
25
|
var CTX = {
|
|
22
26
|
/** Flag indicating whether the application is running in development mode. */
|
|
23
27
|
isDevEnv: "undefined" !== typeof process ? process.env.NODE_ENV !== "production" : true,
|
|
24
|
-
/** Flag indicating whether
|
|
25
|
-
|
|
28
|
+
/** Flag indicating whether an operation is bypassing checks so reactors can allow all writes. */
|
|
29
|
+
usingForce: false,
|
|
26
30
|
/** Active `Autotracker` instance, override for automatic dependency collection on `Reactor` traps. */
|
|
27
|
-
autotracker: null
|
|
31
|
+
autotracker: null,
|
|
32
|
+
/** Extensible meta context for payloads and cross-cutting concerns. */
|
|
33
|
+
meta: null,
|
|
34
|
+
/** Default configuration for new `Reactor` instances and also fallback for utils that need and are called without these options. */
|
|
35
|
+
defaults: {
|
|
36
|
+
crossRealms: false,
|
|
37
|
+
smartCloning: false,
|
|
38
|
+
eventBubbling: true,
|
|
39
|
+
eventCapturing: "auto",
|
|
40
|
+
lineageTracing: false,
|
|
41
|
+
preserveContext: false,
|
|
42
|
+
equalityFunction: Object.is,
|
|
43
|
+
batchingFunction: RTR_BATCH
|
|
44
|
+
}
|
|
28
45
|
};
|
|
29
|
-
var RTR_BATCH = "undefined" !== typeof window ? ("undefined" !== typeof queueMicrotask ? queueMicrotask : setTimeout).bind(window) : "undefined" !== typeof process && process.nextTick ? process.nextTick : setTimeout;
|
|
30
|
-
var RTR_LOG = console.log.bind(console, "[S.I.A Reactor]");
|
|
31
|
-
var NIL = Object.freeze({});
|
|
32
46
|
|
|
33
|
-
// ../utils/dist/chunk-
|
|
34
|
-
var INTERACTIVE_SELECTOR = ":is(button,[href],input:not([type='hidden']),select,textarea,details>summary,[contenteditable
|
|
47
|
+
// ../utils/dist/chunk-HGUYOV3P.js
|
|
48
|
+
var INTERACTIVE_SELECTOR = ":is(button,[href],input:not([type='hidden']),select,textarea,details>summary,[contenteditable],iframe,audio[controls],video[controls],[tabindex]):not([disabled],[tabindex='-1'],[data-focus-guard],[inert],[inert] *)";
|
|
35
49
|
var VIRTUAL_RESOURCE = /* @__PURE__ */ Symbol.for("T007_VIRTUAL_RESOURCE");
|
|
36
|
-
function loadResource(req, type = "style", { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {},
|
|
37
|
-
|
|
50
|
+
function loadResource(req, type = "style", { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, win = window) {
|
|
51
|
+
win.t007 ??= {}, win.t007._resourceCache ??= {};
|
|
38
52
|
if (req === VIRTUAL_RESOURCE || isSym(req)) return Promise.resolve();
|
|
39
53
|
const src = req;
|
|
40
|
-
if (
|
|
41
|
-
const existing = type === "script" ? Array.prototype.find.call(
|
|
42
|
-
if (existing) return
|
|
43
|
-
|
|
54
|
+
if (win.t007._resourceCache[src]) return win.t007._resourceCache[src];
|
|
55
|
+
const existing = type === "script" ? Array.prototype.find.call(win.document.scripts, (s) => isSameURL(s.src, src)) : type === "style" ? Array.prototype.find.call(win.document.styleSheets, (s) => isSameURL(s.href, src)) : null;
|
|
56
|
+
if (existing) return win.t007._resourceCache[src] = Promise.resolve(existing);
|
|
57
|
+
win.t007._resourceCache[src] = new Promise((resolve, reject) => {
|
|
44
58
|
(function tryLoad(remaining, el) {
|
|
45
59
|
const onerror = () => {
|
|
46
60
|
el?.remove?.();
|
|
47
61
|
if (remaining > 1) {
|
|
48
62
|
setTimeout(tryLoad, 1e3, remaining - 1);
|
|
49
|
-
console.warn(`Retrying ${type} load (${attempts - remaining + 1})
|
|
63
|
+
console.warn(`Retrying ${type} load for "${src}" (${attempts - remaining + 1})...`);
|
|
50
64
|
} else {
|
|
51
|
-
delete
|
|
52
|
-
reject(new Error(`${type} load failed
|
|
65
|
+
delete win.t007._resourceCache[src];
|
|
66
|
+
reject(new Error(`${capitalize(type)} load failed for "${src}" after ${attempts - 1} attempts`));
|
|
53
67
|
}
|
|
54
68
|
};
|
|
55
69
|
const url = retryKey && remaining < attempts ? `${src}${src.includes("?") ? "&" : "?"}_${retryKey}=${Date.now()}` : src;
|
|
56
|
-
if (type === "script")
|
|
57
|
-
else if (type === "style")
|
|
70
|
+
if (type === "script") win.document.body.append(el = createEl("script", { src: url, type: module ? "module" : "text/javascript", crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, onload: () => resolve(el), onerror }) || "");
|
|
71
|
+
else if (type === "style") win.document.head.append(el = createEl("link", { rel: "stylesheet", href: url, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, onload: () => resolve(el), onerror }) || "");
|
|
58
72
|
else reject(new Error(`Unsupported resource type: ${type}`));
|
|
59
73
|
})(attempts);
|
|
60
74
|
});
|
|
61
|
-
return
|
|
75
|
+
return win.t007._resourceCache[src];
|
|
62
76
|
}
|
|
63
77
|
function isSym(val) {
|
|
64
78
|
return "symbol" === typeof val;
|
|
@@ -69,6 +83,9 @@
|
|
|
69
83
|
function isArr(obj) {
|
|
70
84
|
return Array.isArray(obj);
|
|
71
85
|
}
|
|
86
|
+
function capitalize(word = "") {
|
|
87
|
+
return word.replace(/^(\s*)([a-z])/i, (_, s, l) => s + l.toUpperCase());
|
|
88
|
+
}
|
|
72
89
|
function cleanURL(url) {
|
|
73
90
|
try {
|
|
74
91
|
const u = new URL(url, window.location.href);
|
|
@@ -78,6 +95,7 @@
|
|
|
78
95
|
}
|
|
79
96
|
}
|
|
80
97
|
function isSameURL(url1, url2) {
|
|
98
|
+
if (url1 === url2) return true;
|
|
81
99
|
if (!isStr(url1) || !isStr(url2) || !url1 || !url2) return false;
|
|
82
100
|
return cleanURL(url1) === cleanURL(url2);
|
|
83
101
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@t007/input",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.32",
|
|
4
4
|
"description": "A lightweight, pure JS input system.",
|
|
5
5
|
"author": "Oketade Oluwatobiloba <tobioketade007@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"types": "./dist/index.d.ts",
|
|
22
22
|
"style": "./dist/index.css",
|
|
23
23
|
"sideEffects": [
|
|
24
|
-
"
|
|
24
|
+
"**/*.css",
|
|
25
|
+
"**/*.scss"
|
|
25
26
|
],
|
|
26
27
|
"exports": {
|
|
27
28
|
".": {
|
|
@@ -68,7 +69,7 @@
|
|
|
68
69
|
"react-dom": "^18.3.1"
|
|
69
70
|
},
|
|
70
71
|
"dependencies": {
|
|
71
|
-
"@t007/utils": "^0.0.
|
|
72
|
+
"@t007/utils": "^0.0.34"
|
|
72
73
|
},
|
|
73
74
|
"peerDependencies": {
|
|
74
75
|
"react": "^18.0.0"
|