@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
package/dist/hooks/nixMemo.js
CHANGED
|
@@ -1,34 +1,30 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
1
|
import { activeContext } from "../context/context";
|
|
4
|
-
function nixMemo(factory, deps = []) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
if (!Array.isArray(deps)) {
|
|
13
|
-
console.error("[nixMemo] Second argument must be an array");
|
|
14
|
-
deps = [];
|
|
15
|
-
}
|
|
16
|
-
const idx = ctx.hookIndex++;
|
|
17
|
-
const prev = ctx.hooks[idx];
|
|
18
|
-
const hasChanged = !prev || prev.deps.length !== deps.length || deps.some((dep, i) => !Object.is(dep, prev.deps[i]));
|
|
19
|
-
if (hasChanged) {
|
|
20
|
-
try {
|
|
21
|
-
const value = factory();
|
|
22
|
-
ctx.hooks[idx] = { value, deps: [...deps] };
|
|
23
|
-
} catch (err) {
|
|
24
|
-
console.error("[nixMemo] Factory function error:", err);
|
|
25
|
-
ctx.hooks[idx] = { value: void 0, deps: [...deps] };
|
|
2
|
+
export function nixMemo(factory, deps = []) {
|
|
3
|
+
const ctx = activeContext;
|
|
4
|
+
if (!ctx)
|
|
5
|
+
throw new Error("nixMemo() called outside component");
|
|
6
|
+
if (typeof factory !== "function") {
|
|
7
|
+
console.error("[nixMemo] First argument must be a function");
|
|
8
|
+
return undefined;
|
|
26
9
|
}
|
|
27
|
-
|
|
28
|
-
|
|
10
|
+
if (!Array.isArray(deps)) {
|
|
11
|
+
console.error("[nixMemo] Second argument must be an array");
|
|
12
|
+
deps = [];
|
|
13
|
+
}
|
|
14
|
+
const idx = ctx.hookIndex++;
|
|
15
|
+
const prev = ctx.hooks[idx];
|
|
16
|
+
const hasChanged = !prev ||
|
|
17
|
+
prev.deps.length !== deps.length ||
|
|
18
|
+
deps.some((dep, i) => !Object.is(dep, prev.deps[i]));
|
|
19
|
+
if (hasChanged) {
|
|
20
|
+
try {
|
|
21
|
+
const value = factory();
|
|
22
|
+
ctx.hooks[idx] = { value, deps: [...deps] };
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
console.error("[nixMemo] Factory function error:", err);
|
|
26
|
+
ctx.hooks[idx] = { value: undefined, deps: [...deps] };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return ctx.hooks[idx]?.value;
|
|
29
30
|
}
|
|
30
|
-
__name(nixMemo, "nixMemo");
|
|
31
|
-
export {
|
|
32
|
-
nixMemo
|
|
33
|
-
};
|
|
34
|
-
//# sourceMappingURL=nixMemo.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../hooks/nixMemo.
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";;
|
|
3
|
+
"sources": ["../../hooks/nixMemo.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\nimport { 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<T>(factory: () => T, deps: any[] = []): T | undefined {\r\n type MemoHook = { value: T; deps: any[] };\r\n const ctx = activeContext as\r\n | (typeof activeContext & {\r\n hookIndex: number;\r\n hooks: Array<MemoHook | undefined>;\r\n })\r\n | undefined;\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: number = ctx.hookIndex++;\r\n const prev = ctx.hooks[idx] as MemoHook | undefined;\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 as unknown as T, deps: [...deps] };\r\n }\r\n }\r\n\r\n return (ctx.hooks[idx] as MemoHook | undefined)?.value;\r\n}\r\n"],
|
|
5
|
+
"mappings": ";;AAsBA,SAAS,qBAAqB;AASvB,SAAS,QAAW,SAAkB,OAAc,CAAC,GAAkB;AAE5E,QAAM,MAAM;AAMZ,MAAI,CAAC,IAAK,OAAM,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,MAAc,IAAI;AACxB,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,QAA2B,MAAM,CAAC,GAAG,IAAI,EAAE;AAAA,IACvE;AAAA,EACF;AAEA,SAAQ,IAAI,MAAM,GAAG,GAA4B;AACnD;AAvCgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nixPrevious.d.ts","sourceRoot":"","sources":["../../hooks/nixPrevious.ts"],"names":[],"mappings":"AA8CA,wBAAgB,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAiBpD"}
|
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
1
|
import { activeContext } from "../context/context";
|
|
4
|
-
function nixPrevious(val) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
export function nixPrevious(val) {
|
|
3
|
+
const ctx = activeContext;
|
|
4
|
+
if (!ctx)
|
|
5
|
+
throw new Error("nixPrevious() called outside component");
|
|
6
|
+
const idx = ctx.hookIndex++;
|
|
7
|
+
const prev = ctx.hooks[idx]?.value;
|
|
8
|
+
try {
|
|
9
|
+
ctx.hooks[idx] = { value: val };
|
|
10
|
+
}
|
|
11
|
+
catch (err) {
|
|
12
|
+
console.error("[nixPrevious] Error storing value:", err);
|
|
13
|
+
}
|
|
14
|
+
return prev;
|
|
16
15
|
}
|
|
17
|
-
__name(nixPrevious, "nixPrevious");
|
|
18
|
-
export {
|
|
19
|
-
nixPrevious
|
|
20
|
-
};
|
|
21
|
-
//# sourceMappingURL=nixPrevious.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../hooks/nixPrevious.
|
|
4
|
-
"sourcesContent": ["/**\r\n * @fileoverview Hook to track previous value across renders.\r\n * Useful for comparing current and previous state.\r\n */\r\n\r\nimport { activeContext } from \"../context/context\";\r\n\r\n/**\r\n * Returns the previous value of a variable across renders.\r\n * Useful for detecting changes and implementing undo functionality.\r\n *\r\n * @template T\r\n * @param {T} val - Current value\r\n * @returns {T | undefined} Previous value (undefined on first render)\r\n
|
|
5
|
-
"mappings": ";;
|
|
3
|
+
"sources": ["../../hooks/nixPrevious.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/**\r\n * @fileoverview Hook to track previous value across renders.\r\n * Useful for comparing current and previous state.\r\n */\r\n\r\nimport { activeContext } from \"../context/context\";\r\n\r\n/**\r\n * Returns the previous value of a variable across renders.\r\n * Useful for detecting changes and implementing undo functionality.\r\n *\r\n * @template T\r\n * @param {T} val - Current value\r\n * @returns {T | undefined} Previous value (undefined on first render)\r\n *\r\n * @example\r\n * const count = nixState(0);\r\n * const prevCount = nixPrevious(count.value);\r\n *\r\n * // prevCount will be undefined on first render\r\n * // then will hold the previous value on subsequent renders\r\n *\r\n * @throws {Error} If called outside a component context\r\n */\r\nexport function nixPrevious<T>(val: T): T | undefined {\r\n const ctx = activeContext as {\r\n hookIndex: number;\r\n hooks: Array<{ value: T } | undefined>;\r\n };\r\n if (!ctx) throw new Error(\"nixPrevious() called outside component\");\r\n\r\n const idx: number = ctx.hookIndex++;\r\n const prev: T | undefined = 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": ";;AA2BA,SAAS,qBAAqB;AAmBvB,SAAS,YAAe,KAAuB;AACpD,QAAM,MAAM;AAIZ,MAAI,CAAC,IAAK,OAAM,IAAI,MAAM,wCAAwC;AAElE,QAAM,MAAc,IAAI;AACxB,QAAM,OAAsB,IAAI,MAAM,GAAG,GAAG;AAE5C,MAAI;AACF,QAAI,MAAM,GAAG,IAAI,EAAE,OAAO,IAAI;AAAA,EAChC,SAAS,KAAK;AACZ,YAAQ,MAAM,sCAAsC,GAAG;AAAA,EACzD;AAEA,SAAO;AACT;AAjBgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nixRef.d.ts","sourceRoot":"","sources":["../../hooks/nixRef.ts"],"names":[],"mappings":"AA+BA,wBAAgB,MAAM,CAAC,CAAC,GAAG,GAAG,EAAE,OAAO,GAAE,CAAe,GAAG;IAAE,OAAO,EAAE,CAAC,CAAA;CAAE,CAsBxE"}
|
package/dist/hooks/nixRef.js
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
1
|
import { activeContext } from "../context/context";
|
|
4
|
-
function nixRef(initial = null) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
export function nixRef(initial = null) {
|
|
3
|
+
const ctx = activeContext;
|
|
4
|
+
if (!ctx)
|
|
5
|
+
throw new Error("nixRef() called outside component");
|
|
6
|
+
const idx = ctx.hookIndex++;
|
|
7
|
+
if (!ctx.hooks[idx]) {
|
|
8
|
+
try {
|
|
9
|
+
ctx.hooks[idx] = { current: initial };
|
|
10
|
+
}
|
|
11
|
+
catch (err) {
|
|
12
|
+
console.error("[nixRef] Error initializing ref:", err);
|
|
13
|
+
ctx.hooks[idx] = { current: null };
|
|
14
|
+
}
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
return ctx.hooks[idx];
|
|
16
|
+
return ctx.hooks[idx];
|
|
18
17
|
}
|
|
19
|
-
__name(nixRef, "nixRef");
|
|
20
|
-
export {
|
|
21
|
-
nixRef
|
|
22
|
-
};
|
|
23
|
-
//# sourceMappingURL=nixRef.js.map
|
package/dist/hooks/nixRef.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../hooks/nixRef.
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";;
|
|
3
|
+
"sources": ["../../hooks/nixRef.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\nimport { 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<T = any>(initial: T = null as any): { current: T } {\r\n type RefHook = { current: T };\r\n const ctx = activeContext as\r\n | (typeof activeContext & {\r\n hookIndex: number;\r\n hooks: Array<RefHook | undefined>;\r\n })\r\n | undefined;\r\n if (!ctx) throw new Error(\"nixRef() called outside component\");\r\n\r\n const idx: number = 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 as any };\r\n }\r\n }\r\n\r\n return ctx.hooks[idx] as RefHook;\r\n}\r\n"],
|
|
5
|
+
"mappings": ";;AAsBA,SAAS,qBAAqB;AASvB,SAAS,OAAgB,UAAa,MAA6B;AAExE,QAAM,MAAM;AAMZ,MAAI,CAAC,IAAK,OAAM,IAAI,MAAM,mCAAmC;AAE7D,QAAM,MAAc,IAAI;AAExB,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,KAAY;AAAA,IAC1C;AAAA,EACF;AAEA,SAAO,IAAI,MAAM,GAAG;AACtB;AAtBgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare function nixState<T>(initial: T): {
|
|
2
|
+
value: T;
|
|
3
|
+
subscribe: (fn: (value: T) => void) => () => void;
|
|
4
|
+
cleanup: () => void;
|
|
5
|
+
getSubscriberCount: () => number;
|
|
6
|
+
isDestroyed: () => boolean;
|
|
7
|
+
asReadOnly: () => {
|
|
8
|
+
value: T;
|
|
9
|
+
subscribe: (fn: (value: T) => void) => () => void;
|
|
10
|
+
_isNixState: true;
|
|
11
|
+
_isReadOnly: true;
|
|
12
|
+
};
|
|
13
|
+
_isNixState: true;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=nixState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nixState.d.ts","sourceRoot":"","sources":["../../hooks/nixState.ts"],"names":[],"mappings":"AAkEA,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG;IACvC,KAAK,EAAE,CAAC,CAAC;IACT,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,KAAK,MAAM,IAAI,CAAC;IAClD,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,kBAAkB,EAAE,MAAM,MAAM,CAAC;IACjC,WAAW,EAAE,MAAM,OAAO,CAAC;IAC3B,UAAU,EAAE,MAAM;QAChB,KAAK,EAAE,CAAC,CAAC;QACT,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,KAAK,MAAM,IAAI,CAAC;QAClD,WAAW,EAAE,IAAI,CAAC;QAClB,WAAW,EAAE,IAAI,CAAC;KACnB,CAAC;IACF,WAAW,EAAE,IAAI,CAAC;CACnB,CAgJA"}
|
package/dist/hooks/nixState.js
CHANGED
|
@@ -1,180 +1,127 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
1
|
import { activeContext } from "../context/context";
|
|
4
|
-
function nixState(initial) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const s = {
|
|
27
|
-
/**
|
|
28
|
-
* Get the current state value. Automatically tracks this state as a dependency.
|
|
29
|
-
* @returns {*} The current state value
|
|
30
|
-
*/
|
|
31
|
-
get value() {
|
|
32
|
-
if (isDestroyed) {
|
|
33
|
-
console.warn("[nixState] Accessing destroyed state");
|
|
34
|
-
return value;
|
|
35
|
-
}
|
|
36
|
-
if (activeContext && !isDestroyed) {
|
|
37
|
-
activeContext._accessedStates.add(s);
|
|
38
|
-
}
|
|
39
|
-
return value;
|
|
40
|
-
},
|
|
41
|
-
/**
|
|
42
|
-
* Set a new state value. Triggers all subscribers if value changed.
|
|
43
|
-
* @param {any} newVal - The new value to set
|
|
44
|
-
*/
|
|
45
|
-
set value(newVal) {
|
|
46
|
-
if (isDestroyed) {
|
|
47
|
-
console.warn("[nixState] Attempting to update destroyed state");
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
if (newVal === value)
|
|
51
|
-
return;
|
|
52
|
-
if (newVal !== null && typeof newVal === "object") {
|
|
53
|
-
if ("__proto__" in newVal || "constructor" in newVal || "prototype" in newVal) {
|
|
54
|
-
console.warn("[nixState] Security: Dangerous properties detected in new value");
|
|
55
|
-
if (Array.isArray(newVal)) {
|
|
56
|
-
newVal = [...newVal];
|
|
57
|
-
} else {
|
|
58
|
-
newVal = { ...newVal };
|
|
59
|
-
delete newVal.__proto__;
|
|
60
|
-
delete newVal.constructor;
|
|
61
|
-
delete newVal.prototype;
|
|
2
|
+
export function nixState(initial) {
|
|
3
|
+
const ctx = activeContext;
|
|
4
|
+
if (!ctx)
|
|
5
|
+
throw new Error("nixState() called outside component");
|
|
6
|
+
const idx = ctx.hookIndex++;
|
|
7
|
+
if (!ctx.hooks[idx]) {
|
|
8
|
+
let value = initial;
|
|
9
|
+
const subscribers = new Set();
|
|
10
|
+
let isDestroyed = false;
|
|
11
|
+
if (initial !== null && typeof initial === "object") {
|
|
12
|
+
if ("__proto__" in initial ||
|
|
13
|
+
"constructor" in initial ||
|
|
14
|
+
"prototype" in initial) {
|
|
15
|
+
if (Array.isArray(initial)) {
|
|
16
|
+
value = [...initial];
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
value = { ...initial };
|
|
20
|
+
delete value.__proto__;
|
|
21
|
+
delete value.constructor;
|
|
22
|
+
delete value.prototype;
|
|
23
|
+
}
|
|
62
24
|
}
|
|
63
|
-
}
|
|
64
25
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
26
|
+
const s = {
|
|
27
|
+
get value() {
|
|
28
|
+
if (isDestroyed) {
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
if (activeContext && !isDestroyed) {
|
|
32
|
+
activeContext._accessedStates.add(s);
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
35
|
+
},
|
|
36
|
+
set value(newVal) {
|
|
37
|
+
if (isDestroyed) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (newVal === value)
|
|
41
|
+
return;
|
|
42
|
+
if (newVal !== null && typeof newVal === "object") {
|
|
43
|
+
if ("__proto__" in newVal ||
|
|
44
|
+
"constructor" in newVal ||
|
|
45
|
+
"prototype" in newVal) {
|
|
46
|
+
if (Array.isArray(newVal)) {
|
|
47
|
+
newVal = [...newVal];
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
newVal = { ...newVal };
|
|
51
|
+
delete newVal.__proto__;
|
|
52
|
+
delete newVal.constructor;
|
|
53
|
+
delete newVal.prototype;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
value = newVal;
|
|
58
|
+
const subsArray = Array.from(subscribers);
|
|
59
|
+
subsArray.forEach((fn) => {
|
|
60
|
+
try {
|
|
61
|
+
fn(newVal);
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
console.error("[nixState] Subscriber error:", err);
|
|
65
|
+
subscribers.delete(fn);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
subscribe(fn) {
|
|
70
|
+
if (typeof fn !== "function") {
|
|
71
|
+
console.error("[nixState] subscribe() requires a function");
|
|
72
|
+
return () => { };
|
|
73
|
+
}
|
|
74
|
+
if (isDestroyed) {
|
|
75
|
+
console.warn("[nixState] Cannot subscribe to destroyed state");
|
|
76
|
+
return () => { };
|
|
77
|
+
}
|
|
78
|
+
const MAX_SUBSCRIBERS = 1000;
|
|
79
|
+
if (subscribers.size >= MAX_SUBSCRIBERS) {
|
|
80
|
+
console.error("[nixState] Maximum subscriber limit reached");
|
|
81
|
+
return () => { };
|
|
82
|
+
}
|
|
83
|
+
subscribers.add(fn);
|
|
84
|
+
return () => {
|
|
85
|
+
subscribers.delete(fn);
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
cleanup() {
|
|
89
|
+
if (isDestroyed)
|
|
90
|
+
return;
|
|
91
|
+
isDestroyed = true;
|
|
92
|
+
subscribers.clear();
|
|
93
|
+
if (value !== null && typeof value === "object") {
|
|
94
|
+
if (Array.isArray(value)) {
|
|
95
|
+
value = [];
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
value = null;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
console.log("[nixState] State cleaned up");
|
|
102
|
+
},
|
|
103
|
+
getSubscriberCount() {
|
|
104
|
+
return subscribers.size;
|
|
105
|
+
},
|
|
106
|
+
isDestroyed() {
|
|
107
|
+
return isDestroyed;
|
|
108
|
+
},
|
|
109
|
+
asReadOnly() {
|
|
110
|
+
return {
|
|
111
|
+
get value() {
|
|
112
|
+
return s.value;
|
|
113
|
+
},
|
|
114
|
+
subscribe: s.subscribe.bind(s),
|
|
115
|
+
_isNixState: true,
|
|
116
|
+
_isReadOnly: true,
|
|
117
|
+
};
|
|
118
|
+
},
|
|
119
|
+
_isNixState: true,
|
|
107
120
|
};
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
* Call this when component unmounts to prevent memory leaks.
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* nixEffect(() => {
|
|
115
|
-
* return () => myState.cleanup();
|
|
116
|
-
* }, []);
|
|
117
|
-
*/
|
|
118
|
-
cleanup() {
|
|
119
|
-
if (isDestroyed)
|
|
120
|
-
return;
|
|
121
|
-
isDestroyed = true;
|
|
122
|
-
subscribers.clear();
|
|
123
|
-
if (value !== null && typeof value === "object") {
|
|
124
|
-
if (Array.isArray(value)) {
|
|
125
|
-
value = [];
|
|
126
|
-
} else {
|
|
127
|
-
value = null;
|
|
128
|
-
}
|
|
121
|
+
ctx.hooks[idx] = s;
|
|
122
|
+
if (ctx.stateCleanups) {
|
|
123
|
+
ctx.stateCleanups.push(() => s.cleanup());
|
|
129
124
|
}
|
|
130
|
-
console.log("[nixState] State cleaned up");
|
|
131
|
-
},
|
|
132
|
-
/**
|
|
133
|
-
* Get the number of active subscribers (useful for debugging)
|
|
134
|
-
* @returns {number} Number of active subscribers
|
|
135
|
-
*/
|
|
136
|
-
getSubscriberCount() {
|
|
137
|
-
return subscribers.size;
|
|
138
|
-
},
|
|
139
|
-
/**
|
|
140
|
-
* Check if state has been destroyed
|
|
141
|
-
* @returns {boolean} True if state is destroyed
|
|
142
|
-
*/
|
|
143
|
-
isDestroyed() {
|
|
144
|
-
return isDestroyed;
|
|
145
|
-
},
|
|
146
|
-
/**
|
|
147
|
-
* Get a read-only version of the state (prevents modification)
|
|
148
|
-
* Useful for passing to child components
|
|
149
|
-
* @returns {Object} Read-only state object
|
|
150
|
-
*
|
|
151
|
-
* @example
|
|
152
|
-
* const readOnly = state.asReadOnly();
|
|
153
|
-
* console.log(readOnly.value); // Can read
|
|
154
|
-
* readOnly.value = 5; // Has no effect (no setter)
|
|
155
|
-
*/
|
|
156
|
-
asReadOnly() {
|
|
157
|
-
return {
|
|
158
|
-
get value() {
|
|
159
|
-
return s.value;
|
|
160
|
-
},
|
|
161
|
-
subscribe: s.subscribe.bind(s),
|
|
162
|
-
_isNixState: true,
|
|
163
|
-
_isReadOnly: true
|
|
164
|
-
};
|
|
165
|
-
},
|
|
166
|
-
// Internal flags
|
|
167
|
-
_isNixState: true
|
|
168
|
-
};
|
|
169
|
-
ctx.hooks[idx] = s;
|
|
170
|
-
if (ctx.stateCleanups) {
|
|
171
|
-
ctx.stateCleanups.push(() => s.cleanup());
|
|
172
125
|
}
|
|
173
|
-
|
|
174
|
-
return ctx.hooks[idx];
|
|
126
|
+
return ctx.hooks[idx];
|
|
175
127
|
}
|
|
176
|
-
__name(nixState, "nixState");
|
|
177
|
-
export {
|
|
178
|
-
nixState
|
|
179
|
-
};
|
|
180
|
-
//# sourceMappingURL=nixState.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../hooks/nixState.
|
|
4
|
-
"sourcesContent": ["/* ----------------------\r\n nixState - Reactive State\r\n Memory Leaks & Security Issues Resolved\r\n---------------------- */\r\nimport { activeContext } from \"../context/context\";\r\n\r\n/**\r\n * Creates a reactive state value that triggers component re-renders when changed.\r\n * Must be called within a component function.\r\n
|
|
5
|
-
"mappings": ";;
|
|
3
|
+
"sources": ["../../hooks/nixState.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/* ----------------------\r\n nixState - Reactive State\r\n Memory Leaks & Security Issues Resolved\r\n---------------------- */\r\nimport { activeContext } from \"../context/context\";\r\n\r\n/**\r\n * Creates a reactive state value that triggers component re-renders when changed.\r\n * Must be called within a component function.\r\n *\r\n * @param {any} initial - The initial value for the state\r\n * @returns {NixState} A reactive state object with value getter/setter and subscription methods\r\n *\r\n * @typedef {Object} NixState\r\n * @property {any} value - Get/set the current state value. Getting tracks the dependency, setting triggers subscribers.\r\n * @property {(fn: Function) => Function} subscribe - Subscribe to state changes. Returns unsubscribe function.\r\n * @property {() => void} cleanup - Cleanup all subscriptions to prevent memory leaks\r\n * @property {() => number} getSubscriberCount - Get number of active subscribers (debugging)\r\n * @property {() => boolean} isDestroyed - Check if state has been destroyed\r\n * @property {() => Object} asReadOnly - Get read-only version of the state\r\n * @property {boolean} _isNixState - Internal flag to identify nixState objects\r\n *\r\n * @example\r\n * const Counter = () => {\r\n * const count = nixState(0);\r\n *\r\n * return h(\"div\", {},\r\n * h(\"p\", {}, \"Count: \", count),\r\n * h(\"button\", { \"r-click\": () => count.value++ }, \"Increment\")\r\n * );\r\n * };\r\n *\r\n * @example\r\n * // With cleanup\r\n * const MyComponent = () => {\r\n * const state = nixState(0);\r\n *\r\n * nixEffect(() => {\r\n * return () => state.cleanup(); // Clean up on unmount\r\n * }, []);\r\n * };\r\n *\r\n * @throws {Error} If called outside a component context\r\n */\r\nexport function nixState<T>(initial: T): {\r\n value: T;\r\n subscribe: (fn: (value: T) => void) => () => void;\r\n cleanup: () => void;\r\n getSubscriberCount: () => number;\r\n isDestroyed: () => boolean;\r\n asReadOnly: () => {\r\n value: T;\r\n subscribe: (fn: (value: T) => void) => () => void;\r\n _isNixState: true;\r\n _isReadOnly: true;\r\n };\r\n _isNixState: true;\r\n} {\r\n const ctx = activeContext as\r\n | (typeof activeContext & {\r\n hookIndex: number;\r\n hooks: Array<any>;\r\n stateCleanups?: Array<() => void>;\r\n })\r\n | undefined;\r\n if (!ctx) throw new Error(\"nixState() called outside component\");\r\n\r\n const idx = ctx.hookIndex++;\r\n if (!ctx.hooks[idx]) {\r\n let value: T = initial;\r\n const subscribers: Set<(value: T) => void> = new Set();\r\n let isDestroyed = false;\r\n\r\n // Security: Validate initial value to prevent prototype pollution\r\n if (initial !== null && typeof initial === \"object\") {\r\n if (\r\n \"__proto__\" in (initial as any) ||\r\n \"constructor\" in (initial as any) ||\r\n \"prototype\" in (initial as any)\r\n ) {\r\n // Create a clean copy without dangerous properties\r\n if (Array.isArray(initial)) {\r\n value = [...(initial as any)] as T;\r\n } else {\r\n value = { ...(initial as any) };\r\n delete (value as any).__proto__;\r\n delete (value as any).constructor;\r\n delete (value as any).prototype;\r\n }\r\n }\r\n }\r\n\r\n const s = {\r\n get value(): T {\r\n if (isDestroyed) {\r\n /* console.warn(\"[nixState] Accessing destroyed state\"); */\r\n return value;\r\n }\r\n if (activeContext && !isDestroyed) {\r\n activeContext._accessedStates.add(s);\r\n }\r\n return value;\r\n },\r\n set value(newVal: T) {\r\n if (isDestroyed) {\r\n /* console.warn(\"[nixState] Attempting to update destroyed state\"); */\r\n return;\r\n }\r\n if (newVal === value) return;\r\n if (newVal !== null && typeof newVal === \"object\") {\r\n if (\r\n \"__proto__\" in (newVal as any) ||\r\n \"constructor\" in (newVal as any) ||\r\n \"prototype\" in (newVal as any)\r\n ) {\r\n /* console.warn(\r\n \"[nixState] Security: Dangerous properties detected in new value\"\r\n ); */\r\n if (Array.isArray(newVal)) {\r\n newVal = [...(newVal as any)] as T;\r\n } else {\r\n newVal = { ...(newVal as any) };\r\n delete (newVal as any).__proto__;\r\n delete (newVal as any).constructor;\r\n delete (newVal as any).prototype;\r\n }\r\n }\r\n }\r\n value = newVal;\r\n const subsArray = Array.from(subscribers);\r\n subsArray.forEach((fn) => {\r\n try {\r\n fn(newVal);\r\n } catch (err) {\r\n console.error(\"[nixState] Subscriber error:\", err);\r\n subscribers.delete(fn);\r\n }\r\n });\r\n },\r\n subscribe(fn: (value: T) => void): () => void {\r\n if (typeof fn !== \"function\") {\r\n console.error(\"[nixState] subscribe() requires a function\");\r\n return () => {};\r\n }\r\n if (isDestroyed) {\r\n console.warn(\"[nixState] Cannot subscribe to destroyed state\");\r\n return () => {};\r\n }\r\n const MAX_SUBSCRIBERS = 1000;\r\n if (subscribers.size >= MAX_SUBSCRIBERS) {\r\n console.error(\"[nixState] Maximum subscriber limit reached\");\r\n return () => {};\r\n }\r\n subscribers.add(fn);\r\n return () => {\r\n subscribers.delete(fn);\r\n };\r\n },\r\n cleanup(): void {\r\n if (isDestroyed) return;\r\n isDestroyed = true;\r\n subscribers.clear();\r\n if (value !== null && typeof value === \"object\") {\r\n if (Array.isArray(value)) {\r\n value = [] as any as T;\r\n } else {\r\n value = null as any as T;\r\n }\r\n }\r\n console.log(\"[nixState] State cleaned up\");\r\n },\r\n getSubscriberCount(): number {\r\n return subscribers.size;\r\n },\r\n isDestroyed(): boolean {\r\n return isDestroyed;\r\n },\r\n asReadOnly(): {\r\n value: T;\r\n subscribe: (fn: (value: T) => void) => () => void;\r\n _isNixState: true;\r\n _isReadOnly: true;\r\n } {\r\n return {\r\n get value() {\r\n return s.value;\r\n },\r\n subscribe: s.subscribe.bind(s),\r\n _isNixState: true,\r\n _isReadOnly: true,\r\n };\r\n },\r\n _isNixState: true as const,\r\n };\r\n\r\n ctx.hooks[idx] = s;\r\n if (ctx.stateCleanups) {\r\n ctx.stateCleanups.push(() => s.cleanup());\r\n }\r\n }\r\n return ctx.hooks[idx] as ReturnType<typeof nixState<T>>;\r\n}\r\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nixStore.d.ts","sourceRoot":"","sources":["../../hooks/nixStore.ts"],"names":[],"mappings":"AAgCA,wBAAgB,QAAQ,CAAC,CAAC,GAAG,GAAG,EAC9B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,CAAC,GACT;IACD,KAAK,EAAE,CAAC,CAAC;IACT,SAAS,EAAE,CAAC,EAAE,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,OAAO,CAAC;CACtB,CAgEA"}
|