@fynixorg/ui 1.0.4 → 1.0.5
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/build.d.ts +1 -0
- package/dist/context/context.d.ts +2 -0
- package/dist/context/context.js +3 -0
- package/dist/context/context.js.map +1 -1
- package/dist/custom/button.d.ts +19 -0
- package/dist/custom/button.js +3 -0
- package/dist/custom/button.js.map +1 -1
- package/dist/custom/index.d.ts +2 -0
- package/dist/custom/path.d.ts +20 -0
- package/dist/custom/path.js +3 -0
- package/dist/custom/path.js.map +2 -2
- package/dist/error/errorOverlay.d.ts +2 -0
- package/dist/error/errorOverlay.js +4 -0
- package/dist/error/errorOverlay.js.map +1 -1
- package/dist/fynix/index.d.ts +4 -0
- package/dist/hooks/nixAsync.d.ts +13 -0
- package/dist/hooks/nixAsync.js +7 -4
- package/dist/hooks/nixAsync.js.map +1 -1
- package/dist/hooks/nixAsyncCache.d.ts +7 -0
- package/dist/hooks/nixAsyncCache.js +7 -4
- package/dist/hooks/nixAsyncCache.js.map +1 -1
- package/dist/hooks/nixAsyncDebounce.d.ts +28 -0
- package/dist/hooks/nixAsyncDebounce.js +9 -6
- package/dist/hooks/nixAsyncDebounce.js.map +1 -1
- package/dist/hooks/nixAsyncQuery.d.ts +40 -0
- package/dist/hooks/nixAsyncQuery.js +7 -4
- package/dist/hooks/nixAsyncQuery.js.map +1 -1
- package/dist/hooks/nixCallback.d.ts +30 -0
- package/dist/hooks/nixCallback.js +4 -0
- package/dist/hooks/nixCallback.js.map +1 -1
- package/dist/hooks/nixComputed.d.ts +94 -0
- package/dist/hooks/nixComputed.js +4 -0
- package/dist/hooks/nixComputed.js.map +1 -1
- package/dist/hooks/nixDebounce.d.ts +28 -0
- package/dist/hooks/nixDebounce.js +7 -4
- package/dist/hooks/nixDebounce.js.map +1 -1
- package/dist/hooks/nixEffect.d.ts +64 -0
- package/dist/hooks/nixEffect.js +6 -0
- package/dist/hooks/nixEffect.js.map +1 -1
- package/dist/hooks/nixForm.d.ts +15 -0
- package/dist/hooks/nixForm.js +11 -0
- package/dist/hooks/nixForm.js.map +1 -1
- package/dist/hooks/nixFormAsync.d.ts +20 -0
- package/dist/hooks/nixFormAsync.js +12 -0
- package/dist/hooks/nixFormAsync.js.map +1 -1
- package/dist/hooks/nixInterval.d.ts +19 -0
- package/dist/hooks/nixInterval.js +6 -3
- package/dist/hooks/nixInterval.js.map +1 -1
- package/dist/hooks/nixLazy.d.ts +19 -0
- package/dist/hooks/nixLazy.js +6 -2
- package/dist/hooks/nixLazy.js.map +1 -1
- package/dist/hooks/nixLazyAsync.d.ts +26 -0
- package/dist/hooks/nixLazyAsync.js +10 -6
- package/dist/hooks/nixLazyAsync.js.map +1 -1
- package/dist/hooks/nixLazyFormAsync.d.ts +29 -0
- package/dist/hooks/nixLazyFormAsync.js +18 -6
- package/dist/hooks/nixLazyFormAsync.js.map +1 -1
- package/dist/hooks/nixLocalStorage.d.ts +11 -0
- package/dist/hooks/nixLocalStorage.js +5 -2
- package/dist/hooks/nixLocalStorage.js.map +1 -1
- package/dist/hooks/nixMemo.d.ts +8 -0
- package/dist/hooks/nixMemo.js +3 -0
- package/dist/hooks/nixMemo.js.map +1 -1
- package/dist/hooks/nixPrevious.d.ts +7 -0
- package/dist/hooks/nixPrevious.js +3 -0
- package/dist/hooks/nixPrevious.js.map +1 -1
- package/dist/hooks/nixRef.d.ts +10 -0
- package/dist/hooks/nixRef.js +3 -0
- package/dist/hooks/nixRef.js.map +1 -1
- package/dist/hooks/nixState.d.ts +73 -0
- package/dist/hooks/nixState.js +3 -0
- package/dist/hooks/nixState.js.map +1 -1
- package/dist/hooks/nixStore.d.ts +9 -0
- package/dist/hooks/nixStore.js +3 -0
- package/dist/hooks/nixStore.js.map +1 -1
- package/dist/plugins/vite-plugin-res.d.ts +12 -0
- package/dist/plugins/vite-plugin-res.js +3 -0
- package/dist/plugins/vite-plugin-res.js.map +1 -1
- package/dist/router/router.d.ts +53 -0
- package/dist/router/router.js +25 -2
- package/dist/router/router.js.map +1 -1
- package/dist/runtime.d.ts +91 -0
- package/dist/runtime.js +18 -0
- package/dist/runtime.js.map +1 -1
- package/package.json +2 -1
- package/types/global.d.ts +29 -19
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safe interval with automatic cleanup support and optional AbortController.
|
|
3
|
+
*
|
|
4
|
+
* @param {Function} fn - Function to run at each interval.
|
|
5
|
+
* @param {number} ms - Interval duration in milliseconds.
|
|
6
|
+
* @param {AbortSignal} [signal] - Optional AbortSignal to cancel the interval.
|
|
7
|
+
* @returns {Function} Cleanup function to stop the interval.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const cancel = nixInterval(() => console.log('tick'), 1000);
|
|
11
|
+
* // stop interval
|
|
12
|
+
* cancel();
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const controller = new AbortController();
|
|
16
|
+
* nixInterval(() => console.log('tick'), 1000, controller.signal);
|
|
17
|
+
* controller.abort(); // automatically clears interval
|
|
18
|
+
*/
|
|
19
|
+
export function nixInterval(fn: Function, ms: number, signal?: AbortSignal): Function;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
1
3
|
function nixInterval(fn, ms, signal) {
|
|
2
4
|
if (typeof fn !== "function") {
|
|
3
5
|
throw new TypeError("nixInterval: first argument must be a function");
|
|
@@ -6,20 +8,21 @@ function nixInterval(fn, ms, signal) {
|
|
|
6
8
|
throw new TypeError("nixInterval: second argument must be a non-negative number");
|
|
7
9
|
}
|
|
8
10
|
const id = setInterval(fn, ms);
|
|
9
|
-
const cancel = () => clearInterval(id);
|
|
11
|
+
const cancel = /* @__PURE__ */ __name(() => clearInterval(id), "cancel");
|
|
10
12
|
if (signal) {
|
|
11
13
|
if (signal.aborted) {
|
|
12
14
|
cancel();
|
|
13
15
|
} else {
|
|
14
|
-
const listener = () => {
|
|
16
|
+
const listener = /* @__PURE__ */ __name(() => {
|
|
15
17
|
cancel();
|
|
16
18
|
signal.removeEventListener("abort", listener);
|
|
17
|
-
};
|
|
19
|
+
}, "listener");
|
|
18
20
|
signal.addEventListener("abort", listener);
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
return cancel;
|
|
22
24
|
}
|
|
25
|
+
__name(nixInterval, "nixInterval");
|
|
23
26
|
export {
|
|
24
27
|
nixInterval
|
|
25
28
|
};
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../hooks/nixInterval.js"],
|
|
4
4
|
"sourcesContent": ["/**\r\n * Safe interval with automatic cleanup support and optional AbortController.\r\n *\r\n * @param {Function} fn - Function to run at each interval.\r\n * @param {number} ms - Interval duration in milliseconds.\r\n * @param {AbortSignal} [signal] - Optional AbortSignal to cancel the interval.\r\n * @returns {Function} Cleanup function to stop the interval.\r\n *\r\n * @example\r\n * const cancel = nixInterval(() => console.log('tick'), 1000);\r\n * // stop interval\r\n * cancel();\r\n *\r\n * @example\r\n * const controller = new AbortController();\r\n * nixInterval(() => console.log('tick'), 1000, controller.signal);\r\n * controller.abort(); // automatically clears interval\r\n */\r\nexport function nixInterval(fn, ms, signal) {\r\n if (typeof fn !== \"function\") {\r\n throw new TypeError(\"nixInterval: first argument must be a function\");\r\n }\r\n if (typeof ms !== \"number\" || ms < 0) {\r\n throw new TypeError(\"nixInterval: second argument must be a non-negative number\");\r\n }\r\n\r\n const id = setInterval(fn, ms);\r\n\r\n const cancel = () => clearInterval(id);\r\n\r\n if (signal) {\r\n if (signal.aborted) {\r\n cancel();\r\n } else {\r\n const listener = () => {\r\n cancel();\r\n signal.removeEventListener(\"abort\", listener);\r\n };\r\n signal.addEventListener(\"abort\", listener);\r\n }\r\n }\r\n\r\n return cancel;\r\n}\r\n"],
|
|
5
|
-
"mappings": "AAkBO,SAAS,YAAY,IAAI,IAAI,QAAQ;AAC1C,MAAI,OAAO,OAAO,YAAY;AAC5B,UAAM,IAAI,UAAU,gDAAgD;AAAA,EACtE;AACA,MAAI,OAAO,OAAO,YAAY,KAAK,GAAG;AACpC,UAAM,IAAI,UAAU,4DAA4D;AAAA,EAClF;AAEA,QAAM,KAAK,YAAY,IAAI,EAAE;AAE7B,QAAM,SAAS,
|
|
5
|
+
"mappings": ";;AAkBO,SAAS,YAAY,IAAI,IAAI,QAAQ;AAC1C,MAAI,OAAO,OAAO,YAAY;AAC5B,UAAM,IAAI,UAAU,gDAAgD;AAAA,EACtE;AACA,MAAI,OAAO,OAAO,YAAY,KAAK,GAAG;AACpC,UAAM,IAAI,UAAU,4DAA4D;AAAA,EAClF;AAEA,QAAM,KAAK,YAAY,IAAI,EAAE;AAE7B,QAAM,SAAS,6BAAM,cAAc,EAAE,GAAtB;AAEf,MAAI,QAAQ;AACV,QAAI,OAAO,SAAS;AAClB,aAAO;AAAA,IACT,OAAO;AACL,YAAM,WAAW,6BAAM;AACrB,eAAO;AACP,eAAO,oBAAoB,SAAS,QAAQ;AAAA,MAC9C,GAHiB;AAIjB,aAAO,iBAAiB,SAAS,QAAQ;AAAA,IAC3C;AAAA,EACF;AAEA,SAAO;AACT;AAzBgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy-load a module/component with caching.
|
|
3
|
+
*
|
|
4
|
+
* @param {() => Promise<any>} importFn - Function that returns a dynamic import.
|
|
5
|
+
* @returns {Function} Component wrapper for lazy-loaded module.
|
|
6
|
+
*/
|
|
7
|
+
export function nixLazy(importFn: () => Promise<any>): Function;
|
|
8
|
+
/**
|
|
9
|
+
* Suspense-like wrapper for lazy components.
|
|
10
|
+
*
|
|
11
|
+
* @param {Object} props
|
|
12
|
+
* @param {any} props.fallback - Element to render while loading.
|
|
13
|
+
* @param {Function} props.children - Function returning child component.
|
|
14
|
+
* @returns {any} Rendered fallback or child.
|
|
15
|
+
*/
|
|
16
|
+
export function Suspense({ fallback, children }: {
|
|
17
|
+
fallback: any;
|
|
18
|
+
children: Function;
|
|
19
|
+
}): any;
|
package/dist/hooks/nixLazy.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
1
3
|
import { activeContext } from "../context/context.js";
|
|
2
4
|
import { nixState } from "./nixState.js";
|
|
3
5
|
function nixLazy(importFn) {
|
|
@@ -20,7 +22,7 @@ function nixLazy(importFn) {
|
|
|
20
22
|
cache.error = err;
|
|
21
23
|
}
|
|
22
24
|
});
|
|
23
|
-
return function LazyWrapper(props) {
|
|
25
|
+
return /* @__PURE__ */ __name(function LazyWrapper(props) {
|
|
24
26
|
const ctx = activeContext;
|
|
25
27
|
if (!ctx)
|
|
26
28
|
throw new Error("nixLazy() called outside component");
|
|
@@ -31,8 +33,9 @@ function nixLazy(importFn) {
|
|
|
31
33
|
throw cache.error;
|
|
32
34
|
}
|
|
33
35
|
return cache.component(props);
|
|
34
|
-
};
|
|
36
|
+
}, "LazyWrapper");
|
|
35
37
|
}
|
|
38
|
+
__name(nixLazy, "nixLazy");
|
|
36
39
|
function Suspense({ fallback, children }) {
|
|
37
40
|
const loading = nixState(false);
|
|
38
41
|
const error = nixState(null);
|
|
@@ -52,6 +55,7 @@ function Suspense({ fallback, children }) {
|
|
|
52
55
|
throw promise;
|
|
53
56
|
}
|
|
54
57
|
}
|
|
58
|
+
__name(Suspense, "Suspense");
|
|
55
59
|
export {
|
|
56
60
|
Suspense,
|
|
57
61
|
nixLazy
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../hooks/nixLazy.js"],
|
|
4
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 const cache = {\r\n status: \"pending\", // pending | success | error\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.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) {\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({ fallback, children }) {\r\n const loading = nixState(false);\r\n const error = nixState(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": "AACA,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AAQlB,SAAS,QAAQ,UAAU;AAChC,QAAM,QAAQ;AAAA,IACZ,QAAQ;AAAA;AAAA,IACR,WAAW;AAAA,IACX,OAAO;AAAA,IACP,SAAS;AAAA,EACX;AAEA,MAAI,WAAW;AAEf,QAAM,UAAU,SAAS,E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;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;AArBgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy-load a module/component with caching, retry, and abort support.
|
|
3
|
+
*
|
|
4
|
+
* @param {() => Promise<any>} importFn - Function returning a dynamic import.
|
|
5
|
+
* @param {Object} [options={}] - Options for lazy loading.
|
|
6
|
+
* @param {number} [options.retry=0] - Number of retry attempts on failure.
|
|
7
|
+
* @returns {Function} Component wrapper for lazy-loaded module.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const LazyComp = nixLazyAsync(() => import("./MyComponent"), { retry: 2 });
|
|
11
|
+
*/
|
|
12
|
+
export function nixLazyAsync(importFn: () => Promise<any>, options?: {
|
|
13
|
+
retry?: number;
|
|
14
|
+
}): Function;
|
|
15
|
+
/**
|
|
16
|
+
* Suspense wrapper to catch pending promises and render fallback.
|
|
17
|
+
*
|
|
18
|
+
* @param {Object} props
|
|
19
|
+
* @param {any} props.fallback - Element to render while loading.
|
|
20
|
+
* @param {Function} props.children - Function returning child component.
|
|
21
|
+
* @returns {any} Rendered fallback or child component.
|
|
22
|
+
*/
|
|
23
|
+
export function Suspense({ fallback, children }: {
|
|
24
|
+
fallback: any;
|
|
25
|
+
children: Function;
|
|
26
|
+
}): any;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
1
3
|
import { activeContext } from "../context/context.js";
|
|
2
4
|
import { nixState } from "./nixState.js";
|
|
3
5
|
function nixLazyAsync(importFn, options = {}) {
|
|
@@ -12,7 +14,7 @@ function nixLazyAsync(importFn, options = {}) {
|
|
|
12
14
|
};
|
|
13
15
|
let abortController = new AbortController();
|
|
14
16
|
let canceled = false;
|
|
15
|
-
const loadModule = () => {
|
|
17
|
+
const loadModule = /* @__PURE__ */ __name(() => {
|
|
16
18
|
cache.promise = importFn().then((module) => {
|
|
17
19
|
if (!canceled) {
|
|
18
20
|
cache.status = "success";
|
|
@@ -29,14 +31,14 @@ function nixLazyAsync(importFn, options = {}) {
|
|
|
29
31
|
}
|
|
30
32
|
});
|
|
31
33
|
return cache.promise;
|
|
32
|
-
};
|
|
34
|
+
}, "loadModule");
|
|
33
35
|
loadModule();
|
|
34
|
-
const cancel = () => {
|
|
36
|
+
const cancel = /* @__PURE__ */ __name(() => {
|
|
35
37
|
canceled = true;
|
|
36
38
|
abortController.abort();
|
|
37
39
|
abortController = null;
|
|
38
|
-
};
|
|
39
|
-
return function LazyWrapper(props) {
|
|
40
|
+
}, "cancel");
|
|
41
|
+
return /* @__PURE__ */ __name(function LazyWrapper(props) {
|
|
40
42
|
const ctx = activeContext;
|
|
41
43
|
if (!ctx)
|
|
42
44
|
throw new Error("nixLazyAsync() called outside component");
|
|
@@ -47,8 +49,9 @@ function nixLazyAsync(importFn, options = {}) {
|
|
|
47
49
|
throw cache.error;
|
|
48
50
|
}
|
|
49
51
|
return cache.component(props);
|
|
50
|
-
};
|
|
52
|
+
}, "LazyWrapper");
|
|
51
53
|
}
|
|
54
|
+
__name(nixLazyAsync, "nixLazyAsync");
|
|
52
55
|
function Suspense({ fallback, children }) {
|
|
53
56
|
const loading = nixState(false);
|
|
54
57
|
const error = nixState(null);
|
|
@@ -66,6 +69,7 @@ function Suspense({ fallback, children }) {
|
|
|
66
69
|
throw promise;
|
|
67
70
|
}
|
|
68
71
|
}
|
|
72
|
+
__name(Suspense, "Suspense");
|
|
69
73
|
export {
|
|
70
74
|
Suspense,
|
|
71
75
|
nixLazyAsync
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../hooks/nixLazyAsync.js"],
|
|
4
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, options = {}) {\r\n const { retry = 0 } = options;\r\n\r\n const cache = {\r\n status: \"pending\", // pending | success | error\r\n component: null,\r\n error: null,\r\n promise: null,\r\n retriesLeft: retry,\r\n };\r\n\r\n let abortController = new AbortController();\r\n let canceled = false;\r\n\r\n const loadModule = () => {\r\n cache.promise = importFn()\r\n .then((module) => {\r\n if (!canceled) {\r\n cache.status = \"success\";\r\n cache.component = module.default || module;\r\n }\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 });\r\n\r\n return cache.promise;\r\n };\r\n\r\n loadModule();\r\n\r\n const cancel = () => {\r\n canceled = true;\r\n abortController.abort();\r\n abortController = null;\r\n };\r\n\r\n return function LazyWrapper(props) {\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 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({ fallback, children }) {\r\n const loading = nixState(false);\r\n const error = nixState(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": "AACA,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AAalB,SAAS,aAAa,UAAU,UAAU,CAAC,GAAG;AACnD,QAAM,EAAE,QAAQ,EAAE,IAAI;AAEtB,QAAM,QAAQ;AAAA,IACZ,QAAQ;AAAA;AAAA,IACR,WAAW;AAAA,IACX,OAAO;AAAA,IACP,SAAS;AAAA,IACT,aAAa;AAAA,EACf;AAEA,MAAI,kBAAkB,IAAI,gBAAgB;AAC1C,MAAI,WAAW;AAEf,QAAM,aAAa,
|
|
5
|
+
"mappings": ";;AACA,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AAalB,SAAS,aAAa,UAAU,UAAU,CAAC,GAAG;AACnD,QAAM,EAAE,QAAQ,EAAE,IAAI;AAEtB,QAAM,QAAQ;AAAA,IACZ,QAAQ;AAAA;AAAA,IACR,WAAW;AAAA,IACX,OAAO;AAAA,IACP,SAAS;AAAA,IACT,aAAa;AAAA,EACf;AAEA,MAAI,kBAAkB,IAAI,gBAAgB;AAC1C,MAAI,WAAW;AAEf,QAAM,aAAa,6BAAM;AACvB,UAAM,UAAU,SAAS,EACtB,KAAK,CAAC,WAAW;AAChB,UAAI,CAAC,UAAU;AACb,cAAM,SAAS;AACf,cAAM,YAAY,OAAO,WAAW;AAAA,MACtC;AAAA,IACF,CAAC,EACA,MAAM,CAAC,QAAQ;AACd,UAAI,CAAC,UAAU;AACb,YAAI,MAAM,cAAc,GAAG;AACzB,gBAAM;AACN,iBAAO,WAAW;AAAA,QACpB;AACA,cAAM,SAAS;AACf,cAAM,QAAQ;AAAA,MAChB;AAAA,IACF,CAAC;AAEH,WAAO,MAAM;AAAA,EACf,GApBmB;AAsBnB,aAAW;AAEX,QAAM,SAAS,6BAAM;AACnB,eAAW;AACX,oBAAgB,MAAM;AACtB,sBAAkB;AAAA,EACpB,GAJe;AAMf,SAAO,gCAAS,YAAY,OAAO;AACjC,UAAM,MAAM;AACZ,QAAI,CAAC;AAAK,YAAM,IAAI,MAAM,yCAAyC;AAEnE,QAAI,MAAM,WAAW,WAAW;AAC9B,YAAM,MAAM;AAAA,IACd;AAEA,QAAI,MAAM,WAAW,SAAS;AAC5B,YAAM,MAAM;AAAA,IACd;AAEA,WAAO,MAAM,UAAU,KAAK;AAAA,EAC9B,GAbO;AAcT;AA1DgB;AAoET,SAAS,SAAS,EAAE,UAAU,SAAS,GAAG;AAC/C,QAAM,UAAU,SAAS,KAAK;AAC9B,QAAM,QAAQ,SAAS,IAAI;AAE3B,MAAI;AACF,WAAO,SAAS;AAAA,EAClB,SAAS,SAAS;AAChB,QAAI,mBAAmB,SAAS;AAC9B,cAAQ,QAAQ;AAChB,cACG,KAAK,MAAO,QAAQ,QAAQ,KAAM,EAClC,MAAM,CAAC,QAAQ;AACd,cAAM,QAAQ;AACd,gBAAQ,QAAQ;AAAA,MAClB,CAAC;AACH,aAAO;AAAA,IACT;AACA,UAAM;AAAA,EACR;AACF;AAnBgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy-load a form component and manage its state with debounced async submissions.
|
|
3
|
+
*
|
|
4
|
+
* @param {() => Promise<any>} importFn - Function returning a dynamic import of the form component.
|
|
5
|
+
* @param {Object} [formOptions={}] - Initial values and validation rules.
|
|
6
|
+
* @param {Object} [formOptions.initialValues={}] - Initial field values.
|
|
7
|
+
* @param {Object} [formOptions.validationRules={}] - Validation rules per field.
|
|
8
|
+
* @param {Object} [submitOptions={}] - Debounce and async submission options.
|
|
9
|
+
* @param {number} [submitOptions.delay=300] - Debounce delay.
|
|
10
|
+
* @param {boolean} [submitOptions.leading=false] - Invoke submit on leading edge.
|
|
11
|
+
* @param {boolean} [submitOptions.trailing=true] - Invoke submit on trailing edge.
|
|
12
|
+
* @param {number} [submitOptions.maxWait] - Max wait before forced submission.
|
|
13
|
+
* @param {boolean} [submitOptions.cache=true] - Cache last submission result.
|
|
14
|
+
* @param {Object} [lazyOptions={}] - Options for lazy-loaded component import.
|
|
15
|
+
* @param {number} [lazyOptions.retry=0] - Retry count for lazy-loaded component import.
|
|
16
|
+
* @returns {Object} Lazy-loaded form component and reactive form API.
|
|
17
|
+
*/
|
|
18
|
+
export function nixLazyFormAsync(importFn: () => Promise<any>, formOptions?: {
|
|
19
|
+
initialValues?: any;
|
|
20
|
+
validationRules?: any;
|
|
21
|
+
}, submitOptions?: {
|
|
22
|
+
delay?: number;
|
|
23
|
+
leading?: boolean;
|
|
24
|
+
trailing?: boolean;
|
|
25
|
+
maxWait?: number;
|
|
26
|
+
cache?: boolean;
|
|
27
|
+
}, lazyOptions?: {
|
|
28
|
+
retry?: number;
|
|
29
|
+
}): any;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
1
3
|
import { nixState } from "./nixState.js";
|
|
2
4
|
import { nixComputed } from "./nixComputed.js";
|
|
3
5
|
import { activeContext } from "../context/context.js";
|
|
@@ -14,7 +16,7 @@ function nixLazyFormAsync(importFn, formOptions = {}, submitOptions = {}, lazyOp
|
|
|
14
16
|
};
|
|
15
17
|
let lazyAbortController = new AbortController();
|
|
16
18
|
let lazyCanceled = false;
|
|
17
|
-
const loadLazy = () => {
|
|
19
|
+
const loadLazy = /* @__PURE__ */ __name(() => {
|
|
18
20
|
lazyCache.promise = importFn().then((module) => {
|
|
19
21
|
if (!lazyCanceled) {
|
|
20
22
|
lazyCache.status = "success";
|
|
@@ -31,14 +33,14 @@ function nixLazyFormAsync(importFn, formOptions = {}, submitOptions = {}, lazyOp
|
|
|
31
33
|
}
|
|
32
34
|
});
|
|
33
35
|
return lazyCache.promise;
|
|
34
|
-
};
|
|
36
|
+
}, "loadLazy");
|
|
35
37
|
loadLazy();
|
|
36
|
-
const cancelLazyLoad = () => {
|
|
38
|
+
const cancelLazyLoad = /* @__PURE__ */ __name(() => {
|
|
37
39
|
lazyCanceled = true;
|
|
38
40
|
lazyAbortController.abort();
|
|
39
41
|
lazyAbortController = null;
|
|
40
|
-
};
|
|
41
|
-
const LazyComponentWrapper = (props) => {
|
|
42
|
+
}, "cancelLazyLoad");
|
|
43
|
+
const LazyComponentWrapper = /* @__PURE__ */ __name((props) => {
|
|
42
44
|
const ctx = activeContext;
|
|
43
45
|
if (!ctx)
|
|
44
46
|
throw new Error("nixLazyFormAsync: called outside component");
|
|
@@ -47,7 +49,7 @@ function nixLazyFormAsync(importFn, formOptions = {}, submitOptions = {}, lazyOp
|
|
|
47
49
|
if (lazyCache.status === "error")
|
|
48
50
|
throw lazyCache.error;
|
|
49
51
|
return lazyCache.component(props);
|
|
50
|
-
};
|
|
52
|
+
}, "LazyComponentWrapper");
|
|
51
53
|
const values = nixState({ ...initialValues });
|
|
52
54
|
const errors = nixState({});
|
|
53
55
|
const touched = nixState({});
|
|
@@ -78,6 +80,7 @@ function nixLazyFormAsync(importFn, formOptions = {}, submitOptions = {}, lazyOp
|
|
|
78
80
|
return rules.message || `${fieldName} is invalid`;
|
|
79
81
|
return null;
|
|
80
82
|
}
|
|
83
|
+
__name(validate, "validate");
|
|
81
84
|
function handleChange(fieldName, value) {
|
|
82
85
|
values.value = { ...values.value, [fieldName]: value };
|
|
83
86
|
if (touched.value[fieldName]) {
|
|
@@ -91,12 +94,14 @@ function nixLazyFormAsync(importFn, formOptions = {}, submitOptions = {}, lazyOp
|
|
|
91
94
|
}
|
|
92
95
|
}
|
|
93
96
|
}
|
|
97
|
+
__name(handleChange, "handleChange");
|
|
94
98
|
function handleBlur(fieldName) {
|
|
95
99
|
touched.value = { ...touched.value, [fieldName]: true };
|
|
96
100
|
const err = validate(fieldName, values.value[fieldName]);
|
|
97
101
|
if (err)
|
|
98
102
|
errors.value = { ...errors.value, [fieldName]: err };
|
|
99
103
|
}
|
|
104
|
+
__name(handleBlur, "handleBlur");
|
|
100
105
|
function validateAll() {
|
|
101
106
|
const newErrors = {};
|
|
102
107
|
Object.keys(validationRules).forEach((fieldName) => {
|
|
@@ -107,6 +112,7 @@ function nixLazyFormAsync(importFn, formOptions = {}, submitOptions = {}, lazyOp
|
|
|
107
112
|
errors.value = newErrors;
|
|
108
113
|
return Object.keys(newErrors).length === 0;
|
|
109
114
|
}
|
|
115
|
+
__name(validateAll, "validateAll");
|
|
110
116
|
async function invokeAsync(onSubmit) {
|
|
111
117
|
if (cache && lastResult !== null) {
|
|
112
118
|
data.value = lastResult;
|
|
@@ -138,6 +144,7 @@ function nixLazyFormAsync(importFn, formOptions = {}, submitOptions = {}, lazyOp
|
|
|
138
144
|
lastInvokeTime = Date.now();
|
|
139
145
|
}
|
|
140
146
|
}
|
|
147
|
+
__name(invokeAsync, "invokeAsync");
|
|
141
148
|
function handleSubmit(onSubmit) {
|
|
142
149
|
if (!validateAll())
|
|
143
150
|
return;
|
|
@@ -162,6 +169,7 @@ function nixLazyFormAsync(importFn, formOptions = {}, submitOptions = {}, lazyOp
|
|
|
162
169
|
}, remainingTime > 0 ? remainingTime : delay);
|
|
163
170
|
}
|
|
164
171
|
}
|
|
172
|
+
__name(handleSubmit, "handleSubmit");
|
|
165
173
|
function cancelSubmit() {
|
|
166
174
|
if (abortController) {
|
|
167
175
|
abortController.abort();
|
|
@@ -171,6 +179,7 @@ function nixLazyFormAsync(importFn, formOptions = {}, submitOptions = {}, lazyOp
|
|
|
171
179
|
clearTimeout(timerId);
|
|
172
180
|
timerId = null;
|
|
173
181
|
}
|
|
182
|
+
__name(cancelSubmit, "cancelSubmit");
|
|
174
183
|
function reset() {
|
|
175
184
|
values.value = { ...initialValues };
|
|
176
185
|
errors.value = {};
|
|
@@ -182,6 +191,7 @@ function nixLazyFormAsync(importFn, formOptions = {}, submitOptions = {}, lazyOp
|
|
|
182
191
|
error.value = null;
|
|
183
192
|
loading.value = false;
|
|
184
193
|
}
|
|
194
|
+
__name(reset, "reset");
|
|
185
195
|
function getFieldProps(fieldName) {
|
|
186
196
|
return {
|
|
187
197
|
value: values.value[fieldName] || "",
|
|
@@ -189,6 +199,7 @@ function nixLazyFormAsync(importFn, formOptions = {}, submitOptions = {}, lazyOp
|
|
|
189
199
|
"r-blur": () => handleBlur(fieldName)
|
|
190
200
|
};
|
|
191
201
|
}
|
|
202
|
+
__name(getFieldProps, "getFieldProps");
|
|
192
203
|
return {
|
|
193
204
|
LazyComponentWrapper,
|
|
194
205
|
values,
|
|
@@ -207,6 +218,7 @@ function nixLazyFormAsync(importFn, formOptions = {}, submitOptions = {}, lazyOp
|
|
|
207
218
|
getFieldProps
|
|
208
219
|
};
|
|
209
220
|
}
|
|
221
|
+
__name(nixLazyFormAsync, "nixLazyFormAsync");
|
|
210
222
|
export {
|
|
211
223
|
nixLazyFormAsync
|
|
212
224
|
};
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../hooks/nixLazyFormAsync.js"],
|
|
4
4
|
"sourcesContent": ["// core/hooks/nixLazyFormAsync.js\r\nimport { nixState } from \"./nixState.js\";\r\nimport { nixComputed } from \"./nixComputed.js\";\r\nimport { activeContext } from \"../context/context.js\";\r\n\r\n/**\r\n * Lazy-load a form component and manage its state with debounced async submissions.\r\n *\r\n * @param {() => Promise<any>} importFn - Function returning a dynamic import of the form component.\r\n * @param {Object} [formOptions={}] - Initial values and validation rules.\r\n * @param {Object} [formOptions.initialValues={}] - Initial field values.\r\n * @param {Object} [formOptions.validationRules={}] - Validation rules per field.\r\n * @param {Object} [submitOptions={}] - Debounce and async submission options.\r\n * @param {number} [submitOptions.delay=300] - Debounce delay.\r\n * @param {boolean} [submitOptions.leading=false] - Invoke submit on leading edge.\r\n * @param {boolean} [submitOptions.trailing=true] - Invoke submit on trailing edge.\r\n * @param {number} [submitOptions.maxWait] - Max wait before forced submission.\r\n * @param {boolean} [submitOptions.cache=true] - Cache last submission result.\r\n * @param {Object} [lazyOptions={}] - Options for lazy-loaded component import.\r\n * @param {number} [lazyOptions.retry=0] - Retry count for lazy-loaded component import.\r\n * @returns {Object} Lazy-loaded form component and reactive form API.\r\n */\r\nexport function nixLazyFormAsync(\r\n importFn,\r\n formOptions = {},\r\n submitOptions = {},\r\n lazyOptions = {}\r\n) {\r\n const { initialValues = {}, validationRules = {} } = formOptions;\r\n const { retry = 0 } = lazyOptions;\r\n const { delay = 300, leading = false, trailing = true, maxWait, cache = true } =\r\n submitOptions;\r\n\r\n /** ---------------- Lazy-load Component ---------------- */\r\n const lazyCache = {\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 lazyAbortController = new AbortController();\r\n let lazyCanceled = false;\r\n\r\n const loadLazy = () => {\r\n lazyCache.promise = importFn()\r\n .then((module) => {\r\n if (!lazyCanceled) {\r\n lazyCache.status = \"success\";\r\n lazyCache.component = module.default || module;\r\n }\r\n })\r\n .catch((err) => {\r\n if (!lazyCanceled) {\r\n if (lazyCache.retriesLeft > 0) {\r\n lazyCache.retriesLeft--;\r\n return loadLazy();\r\n }\r\n lazyCache.status = \"error\";\r\n lazyCache.error = err;\r\n }\r\n });\r\n\r\n return lazyCache.promise;\r\n };\r\n\r\n loadLazy();\r\n\r\n const cancelLazyLoad = () => {\r\n lazyCanceled = true;\r\n lazyAbortController.abort();\r\n lazyAbortController = null;\r\n };\r\n\r\n const LazyComponentWrapper = (props) => {\r\n const ctx = activeContext;\r\n if (!ctx) throw new Error(\"nixLazyFormAsync: called outside component\");\r\n\r\n if (lazyCache.status === \"pending\") throw lazyCache.promise;\r\n if (lazyCache.status === \"error\") throw lazyCache.error;\r\n\r\n return lazyCache.component(props);\r\n };\r\n\r\n /** ---------------- Form State ---------------- */\r\n const values = nixState({ ...initialValues });\r\n const errors = nixState({});\r\n const touched = nixState({});\r\n const isSubmitting = nixState(false);\r\n const isValid = nixComputed(() => Object.keys(errors.value).length === 0);\r\n\r\n /** Async submit state */\r\n const data = nixState(null);\r\n const error = nixState(null);\r\n const loading = nixState(false);\r\n\r\n let abortController = null;\r\n let timerId = null;\r\n let lastInvokeTime = 0;\r\n let lastResult = null;\r\n let lastError = null;\r\n let pendingPromise = null;\r\n\r\n /** ---------------- Form Validation ---------------- */\r\n function validate(fieldName, value) {\r\n const rules = validationRules[fieldName];\r\n if (!rules) return null;\r\n\r\n if (rules.required && !value) return rules.message || `${fieldName} is required`;\r\n if (rules.minLength && value.length < rules.minLength)\r\n return rules.message || `${fieldName} must be at least ${rules.minLength} characters`;\r\n if (rules.maxLength && value.length > rules.maxLength)\r\n return rules.message || `${fieldName} must be at most ${rules.maxLength} characters`;\r\n if (rules.pattern && !rules.pattern.test(value))\r\n return rules.message || `${fieldName} is invalid`;\r\n if (rules.custom && !rules.custom(value, values.value))\r\n return rules.message || `${fieldName} is invalid`;\r\n\r\n return null;\r\n }\r\n\r\n function handleChange(fieldName, value) {\r\n values.value = { ...values.value, [fieldName]: value };\r\n\r\n if (touched.value[fieldName]) {\r\n const err = validate(fieldName, value);\r\n if (err) errors.value = { ...errors.value, [fieldName]: err };\r\n else {\r\n const newErrors = { ...errors.value };\r\n delete newErrors[fieldName];\r\n errors.value = newErrors;\r\n }\r\n }\r\n }\r\n\r\n function handleBlur(fieldName) {\r\n touched.value = { ...touched.value, [fieldName]: true };\r\n const err = validate(fieldName, values.value[fieldName]);\r\n if (err) errors.value = { ...errors.value, [fieldName]: err };\r\n }\r\n\r\n function validateAll() {\r\n const newErrors = {};\r\n Object.keys(validationRules).forEach((fieldName) => {\r\n const err = validate(fieldName, values.value[fieldName]);\r\n if (err) newErrors[fieldName] = err;\r\n });\r\n errors.value = newErrors;\r\n return Object.keys(newErrors).length === 0;\r\n }\r\n\r\n /** ---------------- Debounced Async Submit ---------------- */\r\n async function invokeAsync(onSubmit) {\r\n if (cache && lastResult !== null) {\r\n data.value = lastResult;\r\n error.value = lastError;\r\n loading.value = false;\r\n return lastResult;\r\n }\r\n\r\n if (abortController) abortController.abort();\r\n abortController = new AbortController();\r\n const signal = abortController.signal;\r\n\r\n loading.value = true;\r\n error.value = null;\r\n\r\n pendingPromise = onSubmit(values.value, signal);\r\n\r\n try {\r\n const result = await pendingPromise;\r\n lastResult = result;\r\n data.value = result;\r\n return result;\r\n } catch (err) {\r\n if (err.name !== \"AbortError\") {\r\n lastError = err;\r\n error.value = err;\r\n }\r\n throw err;\r\n } finally {\r\n loading.value = false;\r\n pendingPromise = null;\r\n lastInvokeTime = Date.now();\r\n }\r\n }\r\n\r\n function handleSubmit(onSubmit) {\r\n if (!validateAll()) return;\r\n\r\n const now = Date.now();\r\n const timeSinceLastInvoke = now - lastInvokeTime;\r\n const remainingTime = delay - timeSinceLastInvoke;\r\n const shouldInvokeLeading = leading && !timerId;\r\n\r\n if (maxWait !== undefined && timeSinceLastInvoke >= maxWait) {\r\n if (timerId) clearTimeout(timerId);\r\n timerId = null;\r\n return invokeAsync(onSubmit);\r\n }\r\n\r\n if (timerId) clearTimeout(timerId);\r\n\r\n if (shouldInvokeLeading) return invokeAsync(onSubmit);\r\n\r\n if (trailing) {\r\n timerId = setTimeout(() => {\r\n timerId = null;\r\n invokeAsync(onSubmit);\r\n }, remainingTime > 0 ? remainingTime : delay);\r\n }\r\n }\r\n\r\n /** Cancel pending submit */\r\n function cancelSubmit() {\r\n if (abortController) {\r\n abortController.abort();\r\n abortController = null;\r\n }\r\n if (timerId) clearTimeout(timerId);\r\n timerId = null;\r\n }\r\n\r\n /** Reset form and cancel pending submit and lazy load */\r\n function reset() {\r\n values.value = { ...initialValues };\r\n errors.value = {};\r\n touched.value = {};\r\n isSubmitting.value = false;\r\n cancelSubmit();\r\n cancelLazyLoad();\r\n data.value = null;\r\n error.value = null;\r\n loading.value = false;\r\n }\r\n\r\n function getFieldProps(fieldName) {\r\n return {\r\n value: values.value[fieldName] || \"\",\r\n \"r-input\": (e) => handleChange(fieldName, e.target.value),\r\n \"r-blur\": () => handleBlur(fieldName),\r\n };\r\n }\r\n\r\n return {\r\n LazyComponentWrapper,\r\n values,\r\n errors,\r\n touched,\r\n isSubmitting,\r\n isValid,\r\n data,\r\n error,\r\n loading,\r\n handleChange,\r\n handleBlur,\r\n handleSubmit,\r\n cancelSubmit,\r\n reset,\r\n getFieldProps,\r\n };\r\n}\r\n"],
|
|
5
|
-
"mappings": "AACA,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAmBvB,SAAS,iBACd,UACA,cAAc,CAAC,GACf,gBAAgB,CAAC,GACjB,cAAc,CAAC,GACf;AACA,QAAM,EAAE,gBAAgB,CAAC,GAAG,kBAAkB,CAAC,EAAE,IAAI;AACrD,QAAM,EAAE,QAAQ,EAAE,IAAI;AACtB,QAAM,EAAE,QAAQ,KAAK,UAAU,OAAO,WAAW,MAAM,SAAS,QAAQ,KAAK,IAC3E;AAGF,QAAM,YAAY;AAAA,IAChB,QAAQ;AAAA,IACR,WAAW;AAAA,IACX,OAAO;AAAA,IACP,SAAS;AAAA,IACT,aAAa;AAAA,EACf;AAEA,MAAI,sBAAsB,IAAI,gBAAgB;AAC9C,MAAI,eAAe;AAEnB,QAAM,WAAW,
|
|
5
|
+
"mappings": ";;AACA,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAmBvB,SAAS,iBACd,UACA,cAAc,CAAC,GACf,gBAAgB,CAAC,GACjB,cAAc,CAAC,GACf;AACA,QAAM,EAAE,gBAAgB,CAAC,GAAG,kBAAkB,CAAC,EAAE,IAAI;AACrD,QAAM,EAAE,QAAQ,EAAE,IAAI;AACtB,QAAM,EAAE,QAAQ,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ing/stringifying.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} key - LocalStorage key
|
|
5
|
+
* @param {any} initial - Initial value if key does not exist
|
|
6
|
+
* @returns {{ value: any, set: (v: any) => void }}
|
|
7
|
+
*/
|
|
8
|
+
export function nixLocalStorage(key: string, initial: any): {
|
|
9
|
+
value: any;
|
|
10
|
+
set: (v: any) => void;
|
|
11
|
+
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
1
3
|
import { nixState } from "./nixState";
|
|
2
4
|
function nixLocalStorage(key, initial) {
|
|
3
5
|
const s = nixState(() => {
|
|
@@ -11,16 +13,17 @@ function nixLocalStorage(key, initial) {
|
|
|
11
13
|
return initial;
|
|
12
14
|
}
|
|
13
15
|
});
|
|
14
|
-
const set = (v) => {
|
|
16
|
+
const set = /* @__PURE__ */ __name((v) => {
|
|
15
17
|
s.value = v;
|
|
16
18
|
try {
|
|
17
19
|
localStorage.setItem(key, JSON.stringify(v));
|
|
18
20
|
} catch (err) {
|
|
19
21
|
console.error(`[nixLocalStorage] Error setting key "${key}":`, err);
|
|
20
22
|
}
|
|
21
|
-
};
|
|
23
|
+
}, "set");
|
|
22
24
|
return { value: s.value, set };
|
|
23
25
|
}
|
|
26
|
+
__name(nixLocalStorage, "nixLocalStorage");
|
|
24
27
|
export {
|
|
25
28
|
nixLocalStorage
|
|
26
29
|
};
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../hooks/nixLocalStorage.js"],
|
|
4
4
|
"sourcesContent": ["import { nixState } from \"./nixState\";\r\n\r\n/**\r\n * Reactive wrapper around localStorage with safe JSON parsing/stringifying.\r\n *\r\n * @param {string} key - LocalStorage key\r\n * @param {any} initial - Initial value if key does not exist\r\n * @returns {{ value: any, set: (v: any) => void }}\r\n */\r\nexport function nixLocalStorage(key, initial) {\r\n const s = nixState(() => {\r\n try {\r\n const v = localStorage.getItem(key);\r\n if (v != null) return JSON.parse(v);\r\n return initial;\r\n } catch (err) {\r\n console.error(`[nixLocalStorage] Error reading key \"${key}\":`, err);\r\n return initial;\r\n }\r\n });\r\n\r\n const set = (v) => {\r\n s.value = v;\r\n try {\r\n localStorage.setItem(key, JSON.stringify(v));\r\n } catch (err) {\r\n console.error(`[nixLocalStorage] Error setting key \"${key}\":`, err);\r\n }\r\n };\r\n\r\n return { value: s.value, set };\r\n}\r\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,gBAAgB;AASlB,SAAS,gBAAgB,KAAK,SAAS;AAC5C,QAAM,IAAI,SAAS,MAAM;AACvB,QAAI;AACF,YAAM,IAAI,aAAa,QAAQ,GAAG;AAClC,UAAI,KAAK;AAAM,eAAO,KAAK,MAAM,CAAC;AAClC,aAAO;AAAA,IACT,SAAS,KAAK;AACZ,cAAQ,MAAM,wCAAwC,GAAG,MAAM,GAAG;AAClE,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AAED,QAAM,MAAM,
|
|
5
|
+
"mappings": ";;AAAA,SAAS,gBAAgB;AASlB,SAAS,gBAAgB,KAAK,SAAS;AAC5C,QAAM,IAAI,SAAS,MAAM;AACvB,QAAI;AACF,YAAM,IAAI,aAAa,QAAQ,GAAG;AAClC,UAAI,KAAK;AAAM,eAAO,KAAK,MAAM,CAAC;AAClC,aAAO;AAAA,IACT,SAAS,KAAK;AACZ,cAAQ,MAAM,wCAAwC,GAAG,MAAM,GAAG;AAClE,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AAED,QAAM,MAAM,wBAAC,MAAM;AACjB,MAAE,QAAQ;AACV,QAAI;AACF,mBAAa,QAAQ,KAAK,KAAK,UAAU,CAAC,CAAC;AAAA,IAC7C,SAAS,KAAK;AACZ,cAAQ,MAAM,wCAAwC,GAAG,MAAM,GAAG;AAAA,IACpE;AAAA,EACF,GAPY;AASZ,SAAO,EAAE,OAAO,EAAE,OAAO,IAAI;AAC/B;AAtBgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memoize a value based on dependencies, similar to React's useMemo.
|
|
3
|
+
*
|
|
4
|
+
* @param {() => any} factory - Function to compute the memoized value
|
|
5
|
+
* @param {Array<any>} deps - Dependency array
|
|
6
|
+
* @returns {any} Memoized value
|
|
7
|
+
*/
|
|
8
|
+
export function nixMemo(factory: () => any, deps?: Array<any>): any;
|
package/dist/hooks/nixMemo.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
1
3
|
import { activeContext } from "../context/context";
|
|
2
4
|
function nixMemo(factory, deps = []) {
|
|
3
5
|
const ctx = activeContext;
|
|
@@ -25,6 +27,7 @@ function nixMemo(factory, deps = []) {
|
|
|
25
27
|
}
|
|
26
28
|
return ctx.hooks[idx].value;
|
|
27
29
|
}
|
|
30
|
+
__name(nixMemo, "nixMemo");
|
|
28
31
|
export {
|
|
29
32
|
nixMemo
|
|
30
33
|
};
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../hooks/nixMemo.js"],
|
|
4
4
|
"sourcesContent": ["import { activeContext } from \"../context/context\";\r\n\r\n/**\r\n * Memoize a value based on dependencies, similar to React's useMemo.\r\n *\r\n * @param {() => any} factory - Function to compute the memoized value\r\n * @param {Array<any>} deps - Dependency array\r\n * @returns {any} Memoized value\r\n */\r\nexport function nixMemo(factory, deps = []) {\r\n const ctx = activeContext;\r\n if (!ctx) throw new Error(\"nixMemo() called outside component\");\r\n\r\n if (typeof factory !== \"function\") {\r\n console.error(\"[nixMemo] First argument must be a function\");\r\n return undefined;\r\n }\r\n\r\n if (!Array.isArray(deps)) {\r\n console.error(\"[nixMemo] Second argument must be an array\");\r\n deps = [];\r\n }\r\n\r\n const idx = ctx.hookIndex++;\r\n const prev = ctx.hooks[idx];\r\n\r\n const hasChanged =\r\n !prev ||\r\n prev.deps.length !== deps.length ||\r\n deps.some((dep, i) => !Object.is(dep, prev.deps[i]));\r\n\r\n if (hasChanged) {\r\n try {\r\n const value = factory();\r\n ctx.hooks[idx] = { value, deps: [...deps] };\r\n } catch (err) {\r\n console.error(\"[nixMemo] Factory function error:\", err);\r\n ctx.hooks[idx] = { value: undefined, deps: [...deps] };\r\n }\r\n }\r\n\r\n return ctx.hooks[idx].value;\r\n}\r\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,qBAAqB;AASvB,SAAS,QAAQ,SAAS,OAAO,CAAC,GAAG;AAC1C,QAAM,MAAM;AACZ,MAAI,CAAC;AAAK,UAAM,IAAI,MAAM,oCAAoC;AAE9D,MAAI,OAAO,YAAY,YAAY;AACjC,YAAQ,MAAM,6CAA6C;AAC3D,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,MAAM,QAAQ,IAAI,GAAG;AACxB,YAAQ,MAAM,4CAA4C;AAC1D,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,MAAM,IAAI;AAChB,QAAM,OAAO,IAAI,MAAM,GAAG;AAE1B,QAAM,aACJ,CAAC,QACD,KAAK,KAAK,WAAW,KAAK,UAC1B,KAAK,KAAK,CAAC,KAAK,MAAM,CAAC,OAAO,GAAG,KAAK,KAAK,KAAK,CAAC,CAAC,CAAC;AAErD,MAAI,YAAY;AACd,QAAI;AACF,YAAM,QAAQ,QAAQ;AACtB,UAAI,MAAM,GAAG,IAAI,EAAE,OAAO,MAAM,CAAC,GAAG,IAAI,EAAE;AAAA,IAC5C,SAAS,KAAK;AACZ,cAAQ,MAAM,qCAAqC,GAAG;AACtD,UAAI,MAAM,GAAG,IAAI,EAAE,OAAO,QAAW,MAAM,CAAC,GAAG,IAAI,EAAE;AAAA,IACvD;AAAA,EACF;AAEA,SAAO,IAAI,MAAM,GAAG,EAAE;AACxB;",
|
|
5
|
+
"mappings": ";;AAAA,SAAS,qBAAqB;AASvB,SAAS,QAAQ,SAAS,OAAO,CAAC,GAAG;AAC1C,QAAM,MAAM;AACZ,MAAI,CAAC;AAAK,UAAM,IAAI,MAAM,oCAAoC;AAE9D,MAAI,OAAO,YAAY,YAAY;AACjC,YAAQ,MAAM,6CAA6C;AAC3D,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,MAAM,QAAQ,IAAI,GAAG;AACxB,YAAQ,MAAM,4CAA4C;AAC1D,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,MAAM,IAAI;AAChB,QAAM,OAAO,IAAI,MAAM,GAAG;AAE1B,QAAM,aACJ,CAAC,QACD,KAAK,KAAK,WAAW,KAAK,UAC1B,KAAK,KAAK,CAAC,KAAK,MAAM,CAAC,OAAO,GAAG,KAAK,KAAK,KAAK,CAAC,CAAC,CAAC;AAErD,MAAI,YAAY;AACd,QAAI;AACF,YAAM,QAAQ,QAAQ;AACtB,UAAI,MAAM,GAAG,IAAI,EAAE,OAAO,MAAM,CAAC,GAAG,IAAI,EAAE;AAAA,IAC5C,SAAS,KAAK;AACZ,cAAQ,MAAM,qCAAqC,GAAG;AACtD,UAAI,MAAM,GAAG,IAAI,EAAE,OAAO,QAAW,MAAM,CAAC,GAAG,IAAI,EAAE;AAAA,IACvD;AAAA,EACF;AAEA,SAAO,IAAI,MAAM,GAAG,EAAE;AACxB;AAjCgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
1
3
|
import { activeContext } from "../context/context";
|
|
2
4
|
function nixPrevious(val) {
|
|
3
5
|
const ctx = activeContext;
|
|
@@ -12,6 +14,7 @@ function nixPrevious(val) {
|
|
|
12
14
|
}
|
|
13
15
|
return prev;
|
|
14
16
|
}
|
|
17
|
+
__name(nixPrevious, "nixPrevious");
|
|
15
18
|
export {
|
|
16
19
|
nixPrevious
|
|
17
20
|
};
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../hooks/nixPrevious.js"],
|
|
4
4
|
"sourcesContent": ["import { activeContext } from \"../context/context\";\r\n\r\n/**\r\n * Returns the previous value of a variable across renders.\r\n *\r\n * @param {any} val - Current value\r\n * @returns {any} Previous value\r\n */\r\nexport function nixPrevious(val) {\r\n const ctx = activeContext;\r\n if (!ctx) throw new Error(\"nixPrevious() called outside component\");\r\n\r\n const idx = ctx.hookIndex++;\r\n const prev = ctx.hooks[idx]?.value;\r\n\r\n try {\r\n ctx.hooks[idx] = { value: val };\r\n } catch (err) {\r\n console.error(\"[nixPrevious] Error storing value:\", err);\r\n }\r\n\r\n return prev;\r\n}\r\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,qBAAqB;AAQvB,SAAS,YAAY,KAAK;AAC/B,QAAM,MAAM;AACZ,MAAI,CAAC;AAAK,UAAM,IAAI,MAAM,wCAAwC;AAElE,QAAM,MAAM,IAAI;AAChB,QAAM,OAAO,IAAI,MAAM,GAAG,GAAG;AAE7B,MAAI;AACF,QAAI,MAAM,GAAG,IAAI,EAAE,OAAO,IAAI;AAAA,EAChC,SAAS,KAAK;AACZ,YAAQ,MAAM,sCAAsC,GAAG;AAAA,EACzD;AAEA,SAAO;AACT;",
|
|
5
|
+
"mappings": ";;AAAA,SAAS,qBAAqB;AAQvB,SAAS,YAAY,KAAK;AAC/B,QAAM,MAAM;AACZ,MAAI,CAAC;AAAK,UAAM,IAAI,MAAM,wCAAwC;AAElE,QAAM,MAAM,IAAI;AAChB,QAAM,OAAO,IAAI,MAAM,GAAG,GAAG;AAE7B,MAAI;AACF,QAAI,MAAM,GAAG,IAAI,EAAE,OAAO,IAAI;AAAA,EAChC,SAAS,KAAK;AACZ,YAAQ,MAAM,sCAAsC,GAAG;AAAA,EACzD;AAEA,SAAO;AACT;AAdgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a mutable ref object that persists across renders.
|
|
3
|
+
* Similar to React's useRef.
|
|
4
|
+
*
|
|
5
|
+
* @param {any} initial - Initial value for the ref
|
|
6
|
+
* @returns {{ current: any }} Ref object
|
|
7
|
+
*/
|
|
8
|
+
export function nixRef(initial?: any): {
|
|
9
|
+
current: any;
|
|
10
|
+
};
|
package/dist/hooks/nixRef.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
1
3
|
import { activeContext } from "../context/context";
|
|
2
4
|
function nixRef(initial = null) {
|
|
3
5
|
const ctx = activeContext;
|
|
@@ -14,6 +16,7 @@ function nixRef(initial = null) {
|
|
|
14
16
|
}
|
|
15
17
|
return ctx.hooks[idx];
|
|
16
18
|
}
|
|
19
|
+
__name(nixRef, "nixRef");
|
|
17
20
|
export {
|
|
18
21
|
nixRef
|
|
19
22
|
};
|
package/dist/hooks/nixRef.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../hooks/nixRef.js"],
|
|
4
4
|
"sourcesContent": ["import { activeContext } from \"../context/context\";\r\n\r\n/**\r\n * Returns a mutable ref object that persists across renders.\r\n * Similar to React's useRef.\r\n *\r\n * @param {any} initial - Initial value for the ref\r\n * @returns {{ current: any }} Ref object\r\n */\r\nexport function nixRef(initial = null) {\r\n const ctx = activeContext;\r\n if (!ctx) throw new Error(\"nixRef() called outside component\");\r\n\r\n const idx = ctx.hookIndex++;\r\n\r\n if (!ctx.hooks[idx]) {\r\n try {\r\n ctx.hooks[idx] = { current: initial };\r\n } catch (err) {\r\n console.error(\"[nixRef] Error initializing ref:\", err);\r\n ctx.hooks[idx] = { current: null };\r\n }\r\n }\r\n\r\n return ctx.hooks[idx];\r\n}\r\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,qBAAqB;AASvB,SAAS,OAAO,UAAU,MAAM;AACrC,QAAM,MAAM;AACZ,MAAI,CAAC;AAAK,UAAM,IAAI,MAAM,mCAAmC;AAE7D,QAAM,MAAM,IAAI;AAEhB,MAAI,CAAC,IAAI,MAAM,GAAG,GAAG;AACnB,QAAI;AACF,UAAI,MAAM,GAAG,IAAI,EAAE,SAAS,QAAQ;AAAA,IACtC,SAAS,KAAK;AACZ,cAAQ,MAAM,oCAAoC,GAAG;AACrD,UAAI,MAAM,GAAG,IAAI,EAAE,SAAS,KAAK;AAAA,IACnC;AAAA,EACF;AAEA,SAAO,IAAI,MAAM,GAAG;AACtB;",
|
|
5
|
+
"mappings": ";;AAAA,SAAS,qBAAqB;AASvB,SAAS,OAAO,UAAU,MAAM;AACrC,QAAM,MAAM;AACZ,MAAI,CAAC;AAAK,UAAM,IAAI,MAAM,mCAAmC;AAE7D,QAAM,MAAM,IAAI;AAEhB,MAAI,CAAC,IAAI,MAAM,GAAG,GAAG;AACnB,QAAI;AACF,UAAI,MAAM,GAAG,IAAI,EAAE,SAAS,QAAQ;AAAA,IACtC,SAAS,KAAK;AACZ,cAAQ,MAAM,oCAAoC,GAAG;AACrD,UAAI,MAAM,GAAG,IAAI,EAAE,SAAS,KAAK;AAAA,IACnC;AAAA,EACF;AAEA,SAAO,IAAI,MAAM,GAAG;AACtB;AAhBgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|