@fynixorg/ui 1.0.11 → 1.0.13
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/LICENSE +21 -0
- package/dist/README.md +36 -0
- package/dist/context/context.d.ts +19 -0
- package/dist/context/context.d.ts.map +1 -0
- package/dist/context/context.js +3 -11
- package/dist/context/context.js.map +3 -3
- package/dist/custom/button.d.ts +2 -0
- package/dist/custom/button.d.ts.map +1 -0
- package/dist/custom/button.js +2 -9
- package/dist/custom/button.js.map +3 -3
- package/dist/custom/index.d.ts +3 -0
- package/dist/custom/index.d.ts.map +1 -0
- package/dist/custom/index.js +2 -7
- package/dist/custom/index.js.map +3 -3
- package/dist/custom/path.d.ts +14 -0
- package/dist/custom/path.d.ts.map +1 -0
- package/dist/custom/path.js +17 -34
- package/dist/custom/path.js.map +3 -3
- package/dist/error/errorOverlay.d.ts +3 -0
- package/dist/error/errorOverlay.d.ts.map +1 -0
- package/dist/error/errorOverlay.js +82 -91
- package/dist/error/errorOverlay.js.map +3 -3
- package/dist/fynix/index.d.ts +5 -0
- package/dist/fynix/index.d.ts.map +1 -0
- package/dist/fynix/index.js +2 -7
- package/dist/fynix/index.js.map +3 -3
- package/dist/hooks/nixAsync.d.ts +14 -0
- package/dist/hooks/nixAsync.d.ts.map +1 -0
- package/dist/hooks/nixAsync.js +38 -43
- package/dist/hooks/nixAsync.js.map +3 -3
- package/dist/hooks/nixAsyncCache.d.ts +14 -0
- package/dist/hooks/nixAsyncCache.d.ts.map +1 -0
- package/dist/hooks/nixAsyncCache.js +57 -59
- package/dist/hooks/nixAsyncCache.js.map +3 -3
- package/dist/hooks/nixAsyncDebounce.d.ts +22 -0
- package/dist/hooks/nixAsyncDebounce.d.ts.map +1 -0
- package/dist/hooks/nixAsyncDebounce.js +74 -85
- package/dist/hooks/nixAsyncDebounce.js.map +3 -3
- package/dist/hooks/nixAsyncQuery.d.ts +16 -0
- package/dist/hooks/nixAsyncQuery.d.ts.map +1 -0
- package/dist/hooks/nixAsyncQuery.js +85 -79
- package/dist/hooks/nixAsyncQuery.js.map +3 -3
- package/dist/hooks/nixCallback.d.ts +2 -0
- package/dist/hooks/nixCallback.d.ts.map +1 -0
- package/dist/hooks/nixCallback.js +30 -40
- package/dist/hooks/nixCallback.js.map +3 -3
- package/dist/hooks/nixComputed.d.ts +16 -0
- package/dist/hooks/nixComputed.d.ts.map +1 -0
- package/dist/hooks/nixComputed.js +166 -198
- package/dist/hooks/nixComputed.js.map +4 -4
- package/dist/hooks/nixDebounce.d.ts +11 -0
- package/dist/hooks/nixDebounce.d.ts.map +1 -0
- package/dist/hooks/nixDebounce.js +53 -58
- package/dist/hooks/nixDebounce.js.map +3 -3
- package/dist/hooks/nixEffect.d.ts +4 -0
- package/dist/hooks/nixEffect.d.ts.map +1 -0
- package/dist/hooks/nixEffect.js +65 -75
- package/dist/hooks/nixEffect.js.map +3 -3
- package/dist/hooks/nixForm.d.ts +33 -0
- package/dist/hooks/nixForm.d.ts.map +1 -0
- package/dist/hooks/nixForm.js +110 -120
- package/dist/hooks/nixForm.js.map +3 -3
- package/dist/hooks/nixFormAsync.d.ts +42 -0
- package/dist/hooks/nixFormAsync.d.ts.map +1 -0
- package/dist/hooks/nixFormAsync.js +158 -167
- package/dist/hooks/nixFormAsync.js.map +3 -3
- package/dist/hooks/nixInterval.d.ts +2 -0
- package/dist/hooks/nixInterval.d.ts.map +1 -0
- package/dist/hooks/nixInterval.js +21 -27
- package/dist/hooks/nixInterval.js.map +3 -3
- package/dist/hooks/nixLazy.d.ts +8 -0
- package/dist/hooks/nixLazy.d.ts.map +1 -0
- package/dist/hooks/nixLazy.js +53 -58
- package/dist/hooks/nixLazy.js.map +3 -3
- package/dist/hooks/nixLazyAsync.d.ts +10 -0
- package/dist/hooks/nixLazyAsync.d.ts.map +1 -0
- package/dist/hooks/nixLazyAsync.js +65 -71
- package/dist/hooks/nixLazyAsync.js.map +3 -3
- package/dist/hooks/nixLazyFormAsync.d.ts +50 -0
- package/dist/hooks/nixLazyFormAsync.d.ts.map +1 -0
- package/dist/hooks/nixLazyFormAsync.js +209 -213
- package/dist/hooks/nixLazyFormAsync.js.map +3 -3
- package/dist/hooks/nixLocalStorage.d.ts +5 -0
- package/dist/hooks/nixLocalStorage.d.ts.map +1 -0
- package/dist/hooks/nixLocalStorage.js +21 -25
- package/dist/hooks/nixLocalStorage.js.map +3 -3
- package/dist/hooks/nixMemo.d.ts +2 -0
- package/dist/hooks/nixMemo.d.ts.map +1 -0
- package/dist/hooks/nixMemo.js +27 -31
- package/dist/hooks/nixMemo.js.map +3 -3
- package/dist/hooks/nixPrevious.d.ts +2 -0
- package/dist/hooks/nixPrevious.d.ts.map +1 -0
- package/dist/hooks/nixPrevious.js +13 -19
- package/dist/hooks/nixPrevious.js.map +3 -3
- package/dist/hooks/nixRef.d.ts +4 -0
- package/dist/hooks/nixRef.d.ts.map +1 -0
- package/dist/hooks/nixRef.js +14 -20
- package/dist/hooks/nixRef.js.map +3 -3
- package/dist/hooks/nixState.d.ts +15 -0
- package/dist/hooks/nixState.d.ts.map +1 -0
- package/dist/hooks/nixState.js +120 -173
- package/dist/hooks/nixState.js.map +3 -3
- package/dist/hooks/nixStore.d.ts +7 -0
- package/dist/hooks/nixStore.d.ts.map +1 -0
- package/dist/hooks/nixStore.js +48 -54
- package/dist/hooks/nixStore.js.map +3 -3
- package/dist/package.json +213 -0
- package/dist/plugins/vite-plugin-res.d.ts +41 -0
- package/dist/plugins/vite-plugin-res.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-res.js +620 -36
- package/dist/plugins/vite-plugin-res.js.map +4 -4
- package/dist/router/router.d.ts +35 -0
- package/dist/router/router.d.ts.map +1 -0
- package/dist/router/router.js +520 -486
- package/dist/router/router.js.map +3 -3
- package/dist/runtime.d.ts +62 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +833 -820
- package/dist/runtime.js.map +4 -4
- package/package.json +227 -44
- package/types/fnx.d.ts +72 -0
- package/types/fynix-ui.d.ts +323 -0
- package/types/global.d.ts +46 -6
- package/types/index.d.ts +37 -0
- package/types/vite-env.d.ts +553 -0
- package/runtime.d.ts +0 -83
- package/types/jsx.d.ts +0 -692
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../hooks/nixLazy.
|
|
4
|
-
"sourcesContent": ["// core/hooks/nixLazy.js\r\nimport { activeContext } from \"../context/context.js\";\r\nimport { nixState } from \"./nixState.js\";\r\n\r\n/**\r\n * Lazy-load a module/component with caching.\r\n *\r\n * @param {() => Promise<any>} importFn - Function that returns a dynamic import.\r\n * @returns {Function} Component wrapper for lazy-loaded module.\r\n */\r\nexport function nixLazy(importFn) {\r\n
|
|
5
|
-
"mappings": ";;
|
|
3
|
+
"sources": ["../../hooks/nixLazy.ts"],
|
|
4
|
+
"sourcesContent": ["/* MIT License\r\n\r\n* Copyright (c) 2026 Resty Gonzales\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy\r\nof this software and associated documentation files (the \"Software\"), to deal\r\nin the Software without restriction, including without limitation the rights\r\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\ncopies of the Software, and to permit persons to whom the Software is\r\nfurnished to do so, subject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in all\r\ncopies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n* SOFTWARE.\r\n */\r\n// core/hooks/nixLazy.js\r\nimport { activeContext } from \"../context/context.js\";\r\nimport { nixState } from \"./nixState.js\";\r\n\r\n/**\r\n * Lazy-load a module/component with caching.\r\n *\r\n * @param {() => Promise<any>} importFn - Function that returns a dynamic import.\r\n * @returns {Function} Component wrapper for lazy-loaded module.\r\n */\r\nexport function nixLazy<TProps = any>(\r\n importFn: () => Promise<\r\n { default?: (props: TProps) => any } | ((props: TProps) => any)\r\n >\r\n): (props: TProps) => any {\r\n type Cache = {\r\n status: \"pending\" | \"success\" | \"error\";\r\n component: ((props: TProps) => any) | null;\r\n error: any;\r\n promise: Promise<any> | null;\r\n };\r\n const cache: Cache = {\r\n status: \"pending\",\r\n component: null,\r\n error: null,\r\n promise: null,\r\n };\r\n\r\n let canceled = false;\r\n\r\n cache.promise = importFn()\r\n .then((module) => {\r\n if (!canceled) {\r\n cache.status = \"success\";\r\n cache.component = (module as any).default || module;\r\n }\r\n })\r\n .catch((err) => {\r\n if (!canceled) {\r\n cache.status = \"error\";\r\n cache.error = err;\r\n }\r\n });\r\n\r\n return function LazyWrapper(props: TProps): any {\r\n const ctx = activeContext;\r\n if (!ctx) throw new Error(\"nixLazy() called outside component\");\r\n\r\n if (cache.status === \"pending\") {\r\n throw cache.promise; // Suspense-like behavior\r\n }\r\n\r\n if (cache.status === \"error\") {\r\n throw cache.error;\r\n }\r\n\r\n return cache.component!(props);\r\n };\r\n}\r\n\r\n/**\r\n * Suspense-like wrapper for lazy components.\r\n *\r\n * @param {Object} props\r\n * @param {any} props.fallback - Element to render while loading.\r\n * @param {Function} props.children - Function returning child component.\r\n * @returns {any} Rendered fallback or child.\r\n */\r\nexport function Suspense<T = any>({\r\n fallback,\r\n children,\r\n}: {\r\n fallback: any;\r\n children: () => T;\r\n}): T | any {\r\n const loading = nixState<boolean>(false);\r\n const error = nixState<any>(null);\r\n\r\n try {\r\n return children();\r\n } catch (promise) {\r\n if (promise instanceof Promise) {\r\n loading.value = true;\r\n promise\r\n .then(() => {\r\n loading.value = false;\r\n })\r\n .catch((err) => {\r\n error.value = err;\r\n loading.value = false;\r\n });\r\n return fallback;\r\n }\r\n throw promise;\r\n }\r\n}\r\n"],
|
|
5
|
+
"mappings": ";;AAuBA,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AAQlB,SAAS,QACd,UAGwB;AAOxB,QAAM,QAAe;AAAA,IACnB,QAAQ;AAAA,IACR,WAAW;AAAA,IACX,OAAO;AAAA,IACP,SAAS;AAAA,EACX;AAEA,MAAI,WAAW;AAEf,QAAM,UAAU,SAAS,EACtB,KAAK,CAAC,WAAW;AAChB,QAAI,CAAC,UAAU;AACb,YAAM,SAAS;AACf,YAAM,YAAa,OAAe,WAAW;AAAA,IAC/C;AAAA,EACF,CAAC,EACA,MAAM,CAAC,QAAQ;AACd,QAAI,CAAC,UAAU;AACb,YAAM,SAAS;AACf,YAAM,QAAQ;AAAA,IAChB;AAAA,EACF,CAAC;AAEH,SAAO,gCAAS,YAAY,OAAoB;AAC9C,UAAM,MAAM;AACZ,QAAI,CAAC,IAAK,OAAM,IAAI,MAAM,oCAAoC;AAE9D,QAAI,MAAM,WAAW,WAAW;AAC9B,YAAM,MAAM;AAAA,IACd;AAEA,QAAI,MAAM,WAAW,SAAS;AAC5B,YAAM,MAAM;AAAA,IACd;AAEA,WAAO,MAAM,UAAW,KAAK;AAAA,EAC/B,GAbO;AAcT;AAhDgB;AA0DT,SAAS,SAAkB;AAAA,EAChC;AAAA,EACA;AACF,GAGY;AACV,QAAM,UAAU,SAAkB,KAAK;AACvC,QAAM,QAAQ,SAAc,IAAI;AAEhC,MAAI;AACF,WAAO,SAAS;AAAA,EAClB,SAAS,SAAS;AAChB,QAAI,mBAAmB,SAAS;AAC9B,cAAQ,QAAQ;AAChB,cACG,KAAK,MAAM;AACV,gBAAQ,QAAQ;AAAA,MAClB,CAAC,EACA,MAAM,CAAC,QAAQ;AACd,cAAM,QAAQ;AACd,gBAAQ,QAAQ;AAAA,MAClB,CAAC;AACH,aAAO;AAAA,IACT;AACA,UAAM;AAAA,EACR;AACF;AA3BgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function nixLazyAsync<TProps = any>(importFn: () => Promise<{
|
|
2
|
+
default?: (props: TProps) => any;
|
|
3
|
+
} | ((props: TProps) => any)>, options?: {
|
|
4
|
+
retry?: number;
|
|
5
|
+
}): (props: TProps) => any;
|
|
6
|
+
export declare function Suspense<T = any>({ fallback, children, }: {
|
|
7
|
+
fallback: any;
|
|
8
|
+
children: () => T;
|
|
9
|
+
}): T | any;
|
|
10
|
+
//# sourceMappingURL=nixLazyAsync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nixLazyAsync.d.ts","sourceRoot":"","sources":["../../hooks/nixLazyAsync.ts"],"names":[],"mappings":"AAqCA,wBAAgB,YAAY,CAAC,MAAM,GAAG,GAAG,EACvC,QAAQ,EAAE,MAAM,OAAO,CACrB;IAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,GAAG,CAAA;CAAE,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,GAAG,CAAC,CAChE,EACD,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,GAC/B,CAAC,KAAK,EAAE,MAAM,KAAK,GAAG,CAgExB;AAUD,wBAAgB,QAAQ,CAAC,CAAC,GAAG,GAAG,EAAE,EAChC,QAAQ,EACR,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,GAAG,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC,CAAC;CACnB,GAAG,CAAC,GAAG,GAAG,CAmBV"}
|
|
@@ -1,77 +1,71 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
1
|
import { activeContext } from "../context/context.js";
|
|
4
2
|
import { nixState } from "./nixState.js";
|
|
5
|
-
function nixLazyAsync(importFn, options = {}) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
3
|
+
export function nixLazyAsync(importFn, options = {}) {
|
|
4
|
+
const { retry = 0 } = options;
|
|
5
|
+
const cache = {
|
|
6
|
+
status: "pending",
|
|
7
|
+
component: null,
|
|
8
|
+
error: null,
|
|
9
|
+
promise: null,
|
|
10
|
+
retriesLeft: retry,
|
|
11
|
+
};
|
|
12
|
+
let canceled = false;
|
|
13
|
+
const loadModule = () => {
|
|
14
|
+
cache.promise = importFn()
|
|
15
|
+
.then((module) => {
|
|
16
|
+
if (!canceled) {
|
|
17
|
+
cache.status = "success";
|
|
18
|
+
cache.component = module.default || module;
|
|
19
|
+
}
|
|
20
|
+
return cache.component;
|
|
21
|
+
})
|
|
22
|
+
.catch((err) => {
|
|
23
|
+
if (!canceled) {
|
|
24
|
+
if (cache.retriesLeft > 0) {
|
|
25
|
+
cache.retriesLeft--;
|
|
26
|
+
return loadModule();
|
|
27
|
+
}
|
|
28
|
+
cache.status = "error";
|
|
29
|
+
cache.error = err;
|
|
30
|
+
}
|
|
31
|
+
return Promise.reject(cache.error);
|
|
32
|
+
});
|
|
33
|
+
return cache.promise;
|
|
34
|
+
};
|
|
35
|
+
loadModule();
|
|
36
|
+
return function LazyWrapper(props) {
|
|
37
|
+
const ctx = activeContext;
|
|
38
|
+
if (!ctx)
|
|
39
|
+
throw new Error("nixLazyAsync() called outside component");
|
|
40
|
+
if (cache.status === "pending") {
|
|
41
|
+
throw cache.promise;
|
|
28
42
|
}
|
|
29
|
-
cache.status
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
canceled = true;
|
|
38
|
-
abortController.abort();
|
|
39
|
-
abortController = null;
|
|
40
|
-
}, "cancel");
|
|
41
|
-
return /* @__PURE__ */ __name(function LazyWrapper(props) {
|
|
42
|
-
const ctx = activeContext;
|
|
43
|
-
if (!ctx)
|
|
44
|
-
throw new Error("nixLazyAsync() called outside component");
|
|
45
|
-
if (cache.status === "pending") {
|
|
46
|
-
throw cache.promise;
|
|
47
|
-
}
|
|
48
|
-
if (cache.status === "error") {
|
|
49
|
-
throw cache.error;
|
|
50
|
-
}
|
|
51
|
-
return cache.component(props);
|
|
52
|
-
}, "LazyWrapper");
|
|
43
|
+
if (cache.status === "error") {
|
|
44
|
+
throw cache.error;
|
|
45
|
+
}
|
|
46
|
+
if (!cache.component) {
|
|
47
|
+
throw new Error("nixLazyAsync: component not loaded");
|
|
48
|
+
}
|
|
49
|
+
return cache.component(props);
|
|
50
|
+
};
|
|
53
51
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
52
|
+
export function Suspense({ fallback, children, }) {
|
|
53
|
+
const loading = nixState(false);
|
|
54
|
+
const error = nixState(null);
|
|
55
|
+
try {
|
|
56
|
+
return children();
|
|
57
|
+
}
|
|
58
|
+
catch (promise) {
|
|
59
|
+
if (promise instanceof Promise) {
|
|
60
|
+
loading.value = true;
|
|
61
|
+
promise
|
|
62
|
+
.then(() => (loading.value = false))
|
|
63
|
+
.catch((err) => {
|
|
64
|
+
error.value = err;
|
|
65
|
+
loading.value = false;
|
|
66
|
+
});
|
|
67
|
+
return fallback;
|
|
68
|
+
}
|
|
69
|
+
throw promise;
|
|
68
70
|
}
|
|
69
|
-
throw promise;
|
|
70
|
-
}
|
|
71
71
|
}
|
|
72
|
-
__name(Suspense, "Suspense");
|
|
73
|
-
export {
|
|
74
|
-
Suspense,
|
|
75
|
-
nixLazyAsync
|
|
76
|
-
};
|
|
77
|
-
//# sourceMappingURL=nixLazyAsync.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../hooks/nixLazyAsync.
|
|
4
|
-
"sourcesContent": ["// core/hooks/nixLazyAsync.js\r\nimport { activeContext } from \"../context/context.js\";\r\nimport { nixState } from \"./nixState.js\";\r\n\r\n/**\r\n * Lazy-load a module/component with caching, retry, and abort support.\r\n *\r\n * @param {() => Promise<any>} importFn - Function returning a dynamic import.\r\n * @param {Object} [options={}] - Options for lazy loading.\r\n * @param {number} [options.retry=0] - Number of retry attempts on failure.\r\n * @returns {Function} Component wrapper for lazy-loaded module.\r\n *\r\n * @example\r\n * const LazyComp = nixLazyAsync(() => import(\"./MyComponent\"), { retry: 2 });\r\n */\r\nexport function nixLazyAsync(importFn
|
|
5
|
-
"mappings": ";;
|
|
3
|
+
"sources": ["../../hooks/nixLazyAsync.ts"],
|
|
4
|
+
"sourcesContent": ["/* MIT License\r\n\r\n* Copyright (c) 2026 Resty Gonzales\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy\r\nof this software and associated documentation files (the \"Software\"), to deal\r\nin the Software without restriction, including without limitation the rights\r\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\ncopies of the Software, and to permit persons to whom the Software is\r\nfurnished to do so, subject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in all\r\ncopies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n* SOFTWARE.\r\n */\r\n// core/hooks/nixLazyAsync.js\r\nimport { activeContext } from \"../context/context.js\";\r\nimport { nixState } from \"./nixState.js\";\r\n\r\n/**\r\n * Lazy-load a module/component with caching, retry, and abort support.\r\n *\r\n * @param {() => Promise<any>} importFn - Function returning a dynamic import.\r\n * @param {Object} [options={}] - Options for lazy loading.\r\n * @param {number} [options.retry=0] - Number of retry attempts on failure.\r\n * @returns {Function} Component wrapper for lazy-loaded module.\r\n *\r\n * @example\r\n * const LazyComp = nixLazyAsync(() => import(\"./MyComponent\"), { retry: 2 });\r\n */\r\nexport function nixLazyAsync<TProps = any>(\r\n importFn: () => Promise<\r\n { default?: (props: TProps) => any } | ((props: TProps) => any)\r\n >,\r\n options: { retry?: number } = {}\r\n): (props: TProps) => any {\r\n const { retry = 0 } = options;\r\n\r\n type Cache = {\r\n status: \"pending\" | \"success\" | \"error\";\r\n component: ((props: TProps) => any) | null;\r\n error: any;\r\n promise: Promise<any> | null;\r\n retriesLeft: number;\r\n };\r\n const cache: Cache = {\r\n status: \"pending\",\r\n component: null,\r\n error: null,\r\n promise: null,\r\n retriesLeft: retry,\r\n };\r\n\r\n let canceled = false;\r\n\r\n const loadModule = (): Promise<any> => {\r\n cache.promise = importFn()\r\n .then((module) => {\r\n if (!canceled) {\r\n cache.status = \"success\";\r\n cache.component = (module as any).default || module;\r\n }\r\n return cache.component;\r\n })\r\n .catch((err) => {\r\n if (!canceled) {\r\n if (cache.retriesLeft > 0) {\r\n cache.retriesLeft--;\r\n return loadModule();\r\n }\r\n cache.status = \"error\";\r\n cache.error = err;\r\n }\r\n return Promise.reject(cache.error);\r\n });\r\n return cache.promise;\r\n };\r\n\r\n loadModule();\r\n\r\n // Removed unused 'cancel' function\r\n\r\n return function LazyWrapper(props: TProps): any {\r\n const ctx = activeContext;\r\n if (!ctx) throw new Error(\"nixLazyAsync() called outside component\");\r\n\r\n if (cache.status === \"pending\") {\r\n throw cache.promise; // Suspense fallback\r\n }\r\n\r\n if (cache.status === \"error\") {\r\n throw cache.error;\r\n }\r\n\r\n if (!cache.component) {\r\n throw new Error(\"nixLazyAsync: component not loaded\");\r\n }\r\n return cache.component(props);\r\n };\r\n}\r\n\r\n/**\r\n * Suspense wrapper to catch pending promises and render fallback.\r\n *\r\n * @param {Object} props\r\n * @param {any} props.fallback - Element to render while loading.\r\n * @param {Function} props.children - Function returning child component.\r\n * @returns {any} Rendered fallback or child component.\r\n */\r\nexport function Suspense<T = any>({\r\n fallback,\r\n children,\r\n}: {\r\n fallback: any;\r\n children: () => T;\r\n}): T | any {\r\n const loading = nixState<boolean>(false);\r\n const error = nixState<any>(null);\r\n\r\n try {\r\n return children();\r\n } catch (promise) {\r\n if (promise instanceof Promise) {\r\n loading.value = true;\r\n promise\r\n .then(() => (loading.value = false))\r\n .catch((err) => {\r\n error.value = err;\r\n loading.value = false;\r\n });\r\n return fallback;\r\n }\r\n throw promise;\r\n }\r\n}\r\n"],
|
|
5
|
+
"mappings": ";;AAuBA,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AAalB,SAAS,aACd,UAGA,UAA8B,CAAC,GACP;AACxB,QAAM,EAAE,QAAQ,EAAE,IAAI;AAStB,QAAM,QAAe;AAAA,IACnB,QAAQ;AAAA,IACR,WAAW;AAAA,IACX,OAAO;AAAA,IACP,SAAS;AAAA,IACT,aAAa;AAAA,EACf;AAEA,MAAI,WAAW;AAEf,QAAM,aAAa,6BAAoB;AACrC,UAAM,UAAU,SAAS,EACtB,KAAK,CAAC,WAAW;AAChB,UAAI,CAAC,UAAU;AACb,cAAM,SAAS;AACf,cAAM,YAAa,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ValidationRule<T> = {
|
|
4
|
+
required?: boolean;
|
|
5
|
+
minLength?: number;
|
|
6
|
+
maxLength?: number;
|
|
7
|
+
pattern?: RegExp;
|
|
8
|
+
custom?: (value: any, values: T) => boolean;
|
|
9
|
+
message?: string;
|
|
10
|
+
};
|
|
11
|
+
type ValidationRules<T> = {
|
|
12
|
+
[K in keyof T]?: ValidationRule<T>;
|
|
13
|
+
};
|
|
14
|
+
type LazyFormAsyncReturn<T, D = any, E = any, P = any> = {
|
|
15
|
+
LazyComponentWrapper: (props: P) => any;
|
|
16
|
+
values: ReturnType<typeof nixState<T>>;
|
|
17
|
+
errors: ReturnType<typeof nixState<Partial<Record<keyof T, string>>>>;
|
|
18
|
+
touched: ReturnType<typeof nixState<Partial<Record<keyof T, boolean>>>>;
|
|
19
|
+
isSubmitting: ReturnType<typeof nixState<boolean>>;
|
|
20
|
+
isValid: ReturnType<typeof nixComputed<boolean>>;
|
|
21
|
+
data: ReturnType<typeof nixState<D | null>>;
|
|
22
|
+
error: ReturnType<typeof nixState<E | null>>;
|
|
23
|
+
loading: ReturnType<typeof nixState<boolean>>;
|
|
24
|
+
handleChange: (fieldName: keyof T, value: any) => void;
|
|
25
|
+
handleBlur: (fieldName: keyof T) => void;
|
|
26
|
+
handleSubmit: (onSubmit: (values: T, signal: AbortSignal) => Promise<D>) => void;
|
|
27
|
+
cancelSubmit: () => void;
|
|
28
|
+
reset: () => void;
|
|
29
|
+
getFieldProps: (fieldName: keyof T) => {
|
|
30
|
+
value: any;
|
|
31
|
+
"r-input": (e: any) => void;
|
|
32
|
+
"r-blur": () => void;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export declare function nixLazyFormAsync<T extends Record<string, any> = Record<string, any>, D = any, E = any, P = any>(importFn: () => Promise<{
|
|
36
|
+
default?: (props: P) => any;
|
|
37
|
+
} | ((props: P) => any)>, formOptions?: {
|
|
38
|
+
initialValues?: T;
|
|
39
|
+
validationRules?: ValidationRules<T>;
|
|
40
|
+
}, submitOptions?: {
|
|
41
|
+
delay?: number;
|
|
42
|
+
leading?: boolean;
|
|
43
|
+
trailing?: boolean;
|
|
44
|
+
maxWait?: number;
|
|
45
|
+
cache?: boolean;
|
|
46
|
+
}, lazyOptions?: {
|
|
47
|
+
retry?: number;
|
|
48
|
+
}): LazyFormAsyncReturn<T, D, E, P>;
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=nixLazyFormAsync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nixLazyFormAsync.d.ts","sourceRoot":"","sources":["../../hooks/nixLazyFormAsync.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAmBzC,KAAK,cAAc,CAAC,CAAC,IAAI;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,KAAK,OAAO,CAAC;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,KAAK,eAAe,CAAC,CAAC,IAAI;KACvB,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC;CACnC,CAAC;AAEF,KAAK,mBAAmB,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,IAAI;IACvD,oBAAoB,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,GAAG,CAAC;IACxC,MAAM,EAAE,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IACvC,MAAM,EAAE,UAAU,CAAC,OAAO,QA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