@fynixorg/ui 1.0.4 → 1.0.6
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 +99 -0
- package/dist/context/context.js +3 -0
- package/dist/context/context.js.map +2 -2
- package/dist/custom/Outlet.d.ts +0 -0
- package/dist/custom/button.d.ts +62 -0
- package/dist/custom/button.js +3 -0
- package/dist/custom/button.js.map +2 -2
- package/dist/custom/index.d.ts +2 -0
- package/dist/custom/index.js.map +2 -2
- package/dist/custom/path.d.ts +71 -0
- package/dist/custom/path.js +3 -0
- package/dist/custom/path.js.map +2 -2
- package/dist/error/errorOverlay.d.ts +26 -0
- package/dist/error/errorOverlay.js +4 -0
- package/dist/error/errorOverlay.js.map +2 -2
- 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 +93 -0
- package/dist/hooks/nixComputed.js +4 -0
- package/dist/hooks/nixComputed.js.map +2 -2
- package/dist/hooks/nixDebounce.d.ts +32 -0
- package/dist/hooks/nixDebounce.js +7 -4
- package/dist/hooks/nixDebounce.js.map +2 -2
- 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 +26 -0
- package/dist/hooks/nixInterval.js +6 -3
- package/dist/hooks/nixInterval.js.map +2 -2
- 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 +22 -0
- package/dist/hooks/nixLocalStorage.js +5 -2
- package/dist/hooks/nixLocalStorage.js.map +2 -2
- 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 +18 -0
- package/dist/hooks/nixPrevious.js +3 -0
- package/dist/hooks/nixPrevious.js.map +2 -2
- 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 +16 -0
- package/dist/plugins/vite-plugin-res.js +80 -17
- package/dist/plugins/vite-plugin-res.js.map +2 -2
- package/dist/router/router.d.ts +53 -0
- package/dist/router/router.js +55 -8
- package/dist/router/router.js.map +2 -2
- package/dist/runtime.d.ts +91 -0
- package/dist/runtime.js +23 -4
- package/dist/runtime.js.map +2 -2
- package/package.json +4 -5
- package/types/global.d.ts +33 -20
- package/router/router.d.ts +0 -21
- package/router/router.js +0 -678
- package/runtime.d.ts +0 -83
package/dist/build.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set the active component context.
|
|
3
|
+
* Called internally by the runtime when entering/exiting component rendering.
|
|
4
|
+
*
|
|
5
|
+
* @param {ComponentContext|null} ctx - The component context to set as active, or null to clear
|
|
6
|
+
* @returns {void}
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // Internal usage in runtime
|
|
10
|
+
* setActiveContext(componentContext);
|
|
11
|
+
* const result = Component(props);
|
|
12
|
+
* setActiveContext(null);
|
|
13
|
+
*/
|
|
14
|
+
export function setActiveContext(ctx: ComponentContext | null): void;
|
|
15
|
+
/**
|
|
16
|
+
* @fileoverview Component context management for Fynix framework.
|
|
17
|
+
* Tracks the currently rendering component to enable hooks to access component state.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* @typedef {Object} ComponentContext
|
|
21
|
+
* @property {Array<any>} hooks - Array of hook states
|
|
22
|
+
* @property {number} hookIndex - Current hook index during render
|
|
23
|
+
* @property {Array<Function>} effects - Array of effect cleanup functions
|
|
24
|
+
* @property {Array<Function>} cleanups - Array of cleanup functions
|
|
25
|
+
* @property {Array<Function>} [stateCleanups] - Array of state cleanup functions
|
|
26
|
+
* @property {Object} _vnode - Associated virtual node
|
|
27
|
+
* @property {Set<any>} _accessedStates - Set of states accessed during render
|
|
28
|
+
* @property {Set<any>} _subscriptions - Set of active subscriptions
|
|
29
|
+
* @property {Array<Function>} _subscriptionCleanups - Array of subscription cleanup functions
|
|
30
|
+
* @property {number} version - Component version for tracking updates
|
|
31
|
+
* @property {Function|null} rerender - Function to trigger component re-render
|
|
32
|
+
* @property {Function} Component - Component function
|
|
33
|
+
* @property {boolean} _isMounted - Whether component is mounted
|
|
34
|
+
* @property {boolean} _isRerendering - Whether component is currently re-rendering
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* The currently active component context.
|
|
38
|
+
* This is set during component rendering to allow hooks to access the component's state.
|
|
39
|
+
* @type {ComponentContext|null}
|
|
40
|
+
*/
|
|
41
|
+
export let activeContext: ComponentContext | null;
|
|
42
|
+
export type ComponentContext = {
|
|
43
|
+
/**
|
|
44
|
+
* - Array of hook states
|
|
45
|
+
*/
|
|
46
|
+
hooks: Array<any>;
|
|
47
|
+
/**
|
|
48
|
+
* - Current hook index during render
|
|
49
|
+
*/
|
|
50
|
+
hookIndex: number;
|
|
51
|
+
/**
|
|
52
|
+
* - Array of effect cleanup functions
|
|
53
|
+
*/
|
|
54
|
+
effects: Array<Function>;
|
|
55
|
+
/**
|
|
56
|
+
* - Array of cleanup functions
|
|
57
|
+
*/
|
|
58
|
+
cleanups: Array<Function>;
|
|
59
|
+
/**
|
|
60
|
+
* - Array of state cleanup functions
|
|
61
|
+
*/
|
|
62
|
+
stateCleanups?: Array<Function>;
|
|
63
|
+
/**
|
|
64
|
+
* - Associated virtual node
|
|
65
|
+
*/
|
|
66
|
+
_vnode: any;
|
|
67
|
+
/**
|
|
68
|
+
* - Set of states accessed during render
|
|
69
|
+
*/
|
|
70
|
+
_accessedStates: Set<any>;
|
|
71
|
+
/**
|
|
72
|
+
* - Set of active subscriptions
|
|
73
|
+
*/
|
|
74
|
+
_subscriptions: Set<any>;
|
|
75
|
+
/**
|
|
76
|
+
* - Array of subscription cleanup functions
|
|
77
|
+
*/
|
|
78
|
+
_subscriptionCleanups: Array<Function>;
|
|
79
|
+
/**
|
|
80
|
+
* - Component version for tracking updates
|
|
81
|
+
*/
|
|
82
|
+
version: number;
|
|
83
|
+
/**
|
|
84
|
+
* - Function to trigger component re-render
|
|
85
|
+
*/
|
|
86
|
+
rerender: Function | null;
|
|
87
|
+
/**
|
|
88
|
+
* - Component function
|
|
89
|
+
*/
|
|
90
|
+
Component: Function;
|
|
91
|
+
/**
|
|
92
|
+
* - Whether component is mounted
|
|
93
|
+
*/
|
|
94
|
+
_isMounted: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* - Whether component is currently re-rendering
|
|
97
|
+
*/
|
|
98
|
+
_isRerendering: boolean;
|
|
99
|
+
};
|
package/dist/context/context.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
1
3
|
let activeContext = null;
|
|
2
4
|
function setActiveContext(ctx) {
|
|
3
5
|
activeContext = ctx;
|
|
4
6
|
}
|
|
7
|
+
__name(setActiveContext, "setActiveContext");
|
|
5
8
|
export {
|
|
6
9
|
activeContext,
|
|
7
10
|
setActiveContext
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../context/context.js"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\r\n * @fileoverview Component context management for Fynix framework.\r\n * Tracks the currently rendering component to enable hooks to access component state.\r\n */\r\n\r\n/**\r\n * @typedef {Object} ComponentContext\r\n * @property {Array<any>} hooks - Array of hook states\r\n * @property {number} hookIndex - Current hook index during render\r\n * @property {Array<Function>} effects - Array of effect cleanup functions\r\n * @property {Array<Function>} cleanups - Array of cleanup functions\r\n * @property {Array<Function>} [stateCleanups] - Array of state cleanup functions\r\n * @property {Object} _vnode - Associated virtual node\r\n * @property {Set<any>} _accessedStates - Set of states accessed during render\r\n * @property {Set<any>} _subscriptions - Set of active subscriptions\r\n * @property {Array<Function>} _subscriptionCleanups - Array of subscription cleanup functions\r\n * @property {number} version - Component version for tracking updates\r\n * @property {Function|null} rerender - Function to trigger component re-render\r\n * @property {Function} Component - Component function\r\n * @property {boolean} _isMounted - Whether component is mounted\r\n * @property {boolean} _isRerendering - Whether component is currently re-rendering\r\n */\r\n\r\n/**\r\n * The currently active component context.\r\n * This is set during component rendering to allow hooks to access the component's state.\r\n * @type {ComponentContext|null}\r\n */\r\nexport let activeContext = null;\r\n\r\n/**\r\n * Set the active component context.\r\n * Called internally by the runtime when entering/exiting component rendering.\r\n * \r\n * @param {ComponentContext|null} ctx - The component context to set as active, or null to clear\r\n * @returns {void}\r\n * \r\n * @example\r\n * // Internal usage in runtime\r\n * setActiveContext(componentContext);\r\n * const result = Component(props);\r\n * setActiveContext(null);\r\n */\r\nexport function setActiveContext(ctx) {\r\n activeContext = ctx;\r\n}\r\n"],
|
|
5
|
+
"mappings": ";;AA4BO,IAAI,gBAAgB;AAepB,SAAS,iBAAiB,KAAK;AACpC,kBAAgB;AAClB;AAFgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
File without changes
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {Object} ButtonProps
|
|
3
|
+
* @property {string} [value=""] - Button text content
|
|
4
|
+
* @property {string} [type="button"] - Button type (button, submit, reset)
|
|
5
|
+
* @property {boolean} [disabled=false] - Whether button is disabled
|
|
6
|
+
* @property {string} [rc] - Reactive class attribute (Fynix-specific)
|
|
7
|
+
* @property {string} [class] - CSS class names
|
|
8
|
+
* @property {(this: HTMLElement, event: MouseEvent) => void} [r-click] - Click event handler
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Button component for Fynix applications.
|
|
12
|
+
* Renders a native HTML button element with Fynix event handling.
|
|
13
|
+
*
|
|
14
|
+
* @param {ButtonProps & Record<string, any>} props - Component props
|
|
15
|
+
* @returns {VNode} Button element virtual node
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // Basic button
|
|
19
|
+
* <Button value="Click Me" />
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // With click handler
|
|
23
|
+
* <Button
|
|
24
|
+
* value="Submit"
|
|
25
|
+
* r-click={() => console.log('Clicked!')}
|
|
26
|
+
* />
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Submit button with styling
|
|
30
|
+
* <Button
|
|
31
|
+
* value="Save"
|
|
32
|
+
* type="submit"
|
|
33
|
+
* rc="px-4 py-2 bg-blue-500 text-white rounded"
|
|
34
|
+
* />
|
|
35
|
+
*/
|
|
36
|
+
export function Button({ value, ...props }: ButtonProps & Record<string, any>): VNode;
|
|
37
|
+
export type ButtonProps = {
|
|
38
|
+
/**
|
|
39
|
+
* - Button text content
|
|
40
|
+
*/
|
|
41
|
+
value?: string;
|
|
42
|
+
/**
|
|
43
|
+
* - Button type (button, submit, reset)
|
|
44
|
+
*/
|
|
45
|
+
type?: string;
|
|
46
|
+
/**
|
|
47
|
+
* - Whether button is disabled
|
|
48
|
+
*/
|
|
49
|
+
disabled?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* - Reactive class attribute (Fynix-specific)
|
|
52
|
+
*/
|
|
53
|
+
rc?: string;
|
|
54
|
+
/**
|
|
55
|
+
* - CSS class names
|
|
56
|
+
*/
|
|
57
|
+
class?: string;
|
|
58
|
+
/**
|
|
59
|
+
* - Click event handler
|
|
60
|
+
*/
|
|
61
|
+
"r-click"?: (this: HTMLElement, event: MouseEvent) => void;
|
|
62
|
+
};
|
package/dist/custom/button.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
1
3
|
import { Fynix } from "../runtime.js";
|
|
2
4
|
function Button({ value = "", ...props }) {
|
|
3
5
|
return Fynix("button", props, value);
|
|
4
6
|
}
|
|
7
|
+
__name(Button, "Button");
|
|
5
8
|
export {
|
|
6
9
|
Button
|
|
7
10
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../custom/button.js"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\r\n * @fileoverview Button component for Fynix applications.\r\n * Simple wrapper around native button element with Fynix integration.\r\n */\r\n\r\nimport { Fynix } from \"../runtime.js\";\r\n\r\n/**\r\n * @typedef {Object} ButtonProps\r\n * @property {string} [value=\"\"] - Button text content\r\n * @property {string} [type=\"button\"] - Button type (button, submit, reset)\r\n * @property {boolean} [disabled=false] - Whether button is disabled\r\n * @property {string} [rc] - Reactive class attribute (Fynix-specific)\r\n * @property {string} [class] - CSS class names\r\n * @property {(this: HTMLElement, event: MouseEvent) => void} [r-click] - Click event handler\r\n */\r\n\r\n/**\r\n * Button component for Fynix applications.\r\n * Renders a native HTML button element with Fynix event handling.\r\n * \r\n * @param {ButtonProps & Record<string, any>} props - Component props\r\n * @returns {VNode} Button element virtual node\r\n * \r\n * @example\r\n * // Basic button\r\n * <Button value=\"Click Me\" />\r\n * \r\n * @example\r\n * // With click handler\r\n * <Button \r\n * value=\"Submit\"\r\n * r-click={() => console.log('Clicked!')}\r\n * />\r\n * \r\n * @example\r\n * // Submit button with styling\r\n * <Button\r\n * value=\"Save\"\r\n * type=\"submit\"\r\n * rc=\"px-4 py-2 bg-blue-500 text-white rounded\"\r\n * />\r\n */\r\nexport function Button({ value = \"\", ...props }) {\r\n return Fynix(\"button\", props, value);\r\n}\r\n"],
|
|
5
|
+
"mappings": ";;AAKA,SAAS,aAAa;AAsCf,SAAS,OAAO,EAAE,QAAQ,IAAI,GAAG,MAAM,GAAG;AAC/C,SAAO,MAAM,UAAU,OAAO,KAAK;AACrC;AAFgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/custom/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../custom/index.js"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\r\n * @fileoverview Custom Fynix components export module.\r\n * Re-exports Button and Path components for convenient importing.\r\n * \r\n * @example\r\n * import { Button, Path } from '@fynixorg/ui/custom';\r\n */\r\n\r\nexport { Button } from \"./button\";\r\nexport { Path } from \"./path\";\r\n"],
|
|
5
|
+
"mappings": "AAQA,SAAS,cAAc;AACvB,SAAS,YAAY;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPA navigation link component for Fynix router.
|
|
3
|
+
* Automatically handles client-side navigation and prop passing between routes.
|
|
4
|
+
*
|
|
5
|
+
* @param {PathProps & Record<string, any>} options - Component props
|
|
6
|
+
* @returns {VNode} Anchor element virtual node
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // Basic navigation
|
|
10
|
+
* <Path to="/about" value="About Us" />
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Navigate with props
|
|
14
|
+
* <Path
|
|
15
|
+
* to="/user/123"
|
|
16
|
+
* value="View Profile"
|
|
17
|
+
* props={{ userId: 123, fromSearch: true }}
|
|
18
|
+
* />
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // External link
|
|
22
|
+
* <Path
|
|
23
|
+
* to="https://github.com"
|
|
24
|
+
* value="GitHub"
|
|
25
|
+
* target="_blank"
|
|
26
|
+
* rel="noopener noreferrer"
|
|
27
|
+
* />
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // With styling
|
|
31
|
+
* <Path
|
|
32
|
+
* to="/dashboard"
|
|
33
|
+
* value="Dashboard"
|
|
34
|
+
* rc="px-4 py-2 bg-blue-500 text-white rounded"
|
|
35
|
+
* />
|
|
36
|
+
*/
|
|
37
|
+
export function Path({ to, value, props: routeProps, ...attrs }: PathProps & Record<string, any>): VNode;
|
|
38
|
+
export type PathProps = {
|
|
39
|
+
/**
|
|
40
|
+
* - URL to navigate to (relative or absolute)
|
|
41
|
+
*/
|
|
42
|
+
to?: string;
|
|
43
|
+
/**
|
|
44
|
+
* - Link text content
|
|
45
|
+
*/
|
|
46
|
+
value?: string;
|
|
47
|
+
/**
|
|
48
|
+
* - Props to pass to the destination route component
|
|
49
|
+
*/
|
|
50
|
+
props?: Record<string, any>;
|
|
51
|
+
/**
|
|
52
|
+
* - Link target (_blank, _self, etc.)
|
|
53
|
+
*/
|
|
54
|
+
target?: string;
|
|
55
|
+
/**
|
|
56
|
+
* - Link relationship (noopener, noreferrer, etc.)
|
|
57
|
+
*/
|
|
58
|
+
rel?: string;
|
|
59
|
+
/**
|
|
60
|
+
* - Reactive class attribute (Fynix-specific)
|
|
61
|
+
*/
|
|
62
|
+
rc?: string;
|
|
63
|
+
/**
|
|
64
|
+
* - CSS class names
|
|
65
|
+
*/
|
|
66
|
+
class?: string;
|
|
67
|
+
/**
|
|
68
|
+
* - Element ID
|
|
69
|
+
*/
|
|
70
|
+
id?: string;
|
|
71
|
+
};
|
package/dist/custom/path.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 { Fynix, nixState } from "../runtime.js";
|
|
2
4
|
let propsCounter = 0;
|
|
3
5
|
function Path({
|
|
@@ -28,6 +30,7 @@ function Path({
|
|
|
28
30
|
);
|
|
29
31
|
return el;
|
|
30
32
|
}
|
|
33
|
+
__name(Path, "Path");
|
|
31
34
|
export {
|
|
32
35
|
Path
|
|
33
36
|
};
|
package/dist/custom/path.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../custom/path.js"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\r\n * @fileoverview Path component for SPA navigation in Fynix applications.\r\n * Provides client-side routing with prop passing between routes.\r\n */\r\n\r\nimport { Fynix, nixState } from \"../runtime.js\";\r\n\r\n/**\r\n * @typedef {Object} PathProps\r\n * @property {string} [to=\"#\"] - URL to navigate to (relative or absolute)\r\n * @property {string} [value=\"\"] - Link text content\r\n * @property {Record<string, any>} [props={}] - Props to pass to the destination route component\r\n * @property {string} [target] - Link target (_blank, _self, etc.)\r\n * @property {string} [rel] - Link relationship (noopener, noreferrer, etc.)\r\n * @property {string} [rc] - Reactive class attribute (Fynix-specific)\r\n * @property {string} [class] - CSS class names\r\n * @property {string} [id] - Element ID\r\n */\r\n\r\n/** Unique counter for props keys */\r\nlet propsCounter = 0;\r\n\r\n/**\r\n * SPA navigation link component for Fynix router.\r\n * Automatically handles client-side navigation and prop passing between routes.\r\n * \r\n * @param {PathProps & Record<string, any>} options - Component props\r\n * @returns {VNode} Anchor element virtual node\r\n * \r\n * @example\r\n * // Basic navigation\r\n * <Path to=\"/about\" value=\"About Us\" />\r\n * \r\n * @example\r\n * // Navigate with props\r\n * <Path \r\n * to=\"/user/123\" \r\n * value=\"View Profile\"\r\n * props={{ userId: 123, fromSearch: true }}\r\n * />\r\n * \r\n * @example\r\n * // External link\r\n * <Path\r\n * to=\"https://github.com\"\r\n * value=\"GitHub\"\r\n * target=\"_blank\"\r\n * rel=\"noopener noreferrer\"\r\n * />\r\n * \r\n * @example\r\n * // With styling\r\n * <Path\r\n * to=\"/dashboard\"\r\n * value=\"Dashboard\"\r\n * rc=\"px-4 py-2 bg-blue-500 text-white rounded\"\r\n * />\r\n */\r\nexport function Path({\r\n to = \"#\",\r\n value = \"\",\r\n props: routeProps = {},\r\n ...attrs\r\n}) {\r\n ///console.log(\"[Path Component] Received routeProps:\", routeProps);\r\n\r\n // Wrap plain props in nixState if not already\r\n const wrappedProps = {};\r\n for (const [k, v] of Object.entries(routeProps)) {\r\n wrappedProps[k] = v && v._isNixState ? v : nixState(v);\r\n }\r\n\r\n // Generate a unique key for this props object\r\n // FIX: Do not use __ prefix as router blocks it for security\r\n const propsKey = `fynixProp_${Date.now()}_${propsCounter++}`;\r\n\r\n // FIX: Store props in the namespace expected by the router\r\n if (!window.__fynixLinkProps__) {\r\n window.__fynixLinkProps__ = {};\r\n }\r\n\r\n // Debug log\r\n // console.log(\"[Path] Storage props:\", propsKey, wrappedProps);\r\n\r\n window.__fynixLinkProps__[propsKey] = wrappedProps;\r\n\r\n // Create the anchor element\r\n const el = Fynix(\r\n \"a\",\r\n {\r\n href: to,\r\n \"data-fynix-link\": true, // SPA link detection\r\n \"data-props-key\": propsKey,\r\n ...attrs,\r\n },\r\n value\r\n );\r\n\r\n return el;\r\n}\r\n"],
|
|
5
|
+
"mappings": ";;AAKA,SAAS,OAAO,gBAAgB;AAehC,IAAI,eAAe;AAsCZ,SAAS,KAAK;AAAA,EACnB,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,OAAO,aAAa,CAAC;AAAA,EACrB,GAAG;AACL,GAAG;AAID,QAAM,eAAe,CAAC;AACtB,aAAW,CAAC,GAAG,CAAC,KAAK,OAAO,QAAQ,UAAU,GAAG;AAC/C,iBAAa,CAAC,IAAI,KAAK,EAAE,cAAc,IAAI,SAAS,CAAC;AAAA,EACvD;AAIA,QAAM,WAAW,aAAa,KAAK,IAAI,CAAC,IAAI,cAAc;AAG1D,MAAI,CAAC,OAAO,oBAAoB;AAC9B,WAAO,qBAAqB,CAAC;AAAA,EAC/B;AAKA,SAAO,mBAAmB,QAAQ,IAAI;AAGtC,QAAM,KAAK;AAAA,IACT;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,mBAAmB;AAAA;AAAA,MACnB,kBAAkB;AAAA,MAClB,GAAG;AAAA,IACL;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AACT;AAzCgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Development error overlay for Fynix applications.
|
|
3
|
+
* Displays runtime errors in a user-friendly overlay during development.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Display an error overlay with error details.
|
|
7
|
+
* Shows error message, stack trace, and a close button.
|
|
8
|
+
*
|
|
9
|
+
* @param {Error} error - The error object to display
|
|
10
|
+
* @returns {void}
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* try {
|
|
14
|
+
* // some code
|
|
15
|
+
* } catch (err) {
|
|
16
|
+
* showErrorOverlay(err);
|
|
17
|
+
* }
|
|
18
|
+
*/
|
|
19
|
+
export function showErrorOverlay(error: Error): void;
|
|
20
|
+
/**
|
|
21
|
+
* Remove the error overlay from the DOM.
|
|
22
|
+
* Fades out the overlay before removing it.
|
|
23
|
+
*
|
|
24
|
+
* @returns {void}
|
|
25
|
+
*/
|
|
26
|
+
export function removeErrorOverlay(): void;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
1
3
|
function showErrorOverlay(error) {
|
|
2
4
|
removeErrorOverlay();
|
|
3
5
|
const overlay = document.createElement("div");
|
|
@@ -75,6 +77,7 @@ function showErrorOverlay(error) {
|
|
|
75
77
|
});
|
|
76
78
|
console.error("FynixJS Runtime Error]", error);
|
|
77
79
|
}
|
|
80
|
+
__name(showErrorOverlay, "showErrorOverlay");
|
|
78
81
|
function removeErrorOverlay() {
|
|
79
82
|
const existing = document.getElementById("dev-error-overlay");
|
|
80
83
|
if (existing) {
|
|
@@ -82,6 +85,7 @@ function removeErrorOverlay() {
|
|
|
82
85
|
setTimeout(() => existing.remove(), 200);
|
|
83
86
|
}
|
|
84
87
|
}
|
|
88
|
+
__name(removeErrorOverlay, "removeErrorOverlay");
|
|
85
89
|
export {
|
|
86
90
|
removeErrorOverlay,
|
|
87
91
|
showErrorOverlay
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../error/errorOverlay.js"],
|
|
4
|
-
"sourcesContent": ["//
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\r\n * @fileoverview Development error overlay for Fynix applications.\r\n * Displays runtime errors in a user-friendly overlay during development.\r\n */\r\n\r\n/**\r\n * Display an error overlay with error details.\r\n * Shows error message, stack trace, and a close button.\r\n * \r\n * @param {Error} error - The error object to display\r\n * @returns {void}\r\n * \r\n * @example\r\n * try {\r\n * // some code\r\n * } catch (err) {\r\n * showErrorOverlay(err);\r\n * }\r\n */\r\nexport function showErrorOverlay(error) {\r\n removeErrorOverlay();\r\n\r\n const overlay = document.createElement(\"div\");\r\n overlay.id = \"dev-error-overlay\";\r\n Object.assign(overlay.style, {\r\n position: \"fixed\",\r\n inset: 0,\r\n width: \"100%\",\r\n height: \"100%\",\r\n backgroundColor: \"rgba(0, 0, 0, 0.9)\",\r\n color: \"#fff\",\r\n fontFamily: \"Consolas, monospace\",\r\n padding: \"30px\",\r\n zIndex: 99999,\r\n overflowY: \"auto\",\r\n transition: \"opacity 0.25s ease\",\r\n opacity: \"0\",\r\n });\r\n\r\n const container = document.createElement(\"div\");\r\n container.style.position = \"relative\"; // important for absolute button\r\n container.style.maxWidth = \"900px\";\r\n container.style.margin = \"50px auto\";\r\n container.style.background = \"rgba(255, 255, 255, 0.05)\";\r\n container.style.borderRadius = \"8px\";\r\n container.style.padding = \"20px 30px\";\r\n container.style.boxShadow = \"0 0 10px rgba(255, 0, 0, 0.3)\";\r\n\r\n // Close Button\r\n const closeBtn = document.createElement(\"button\");\r\n closeBtn.textContent = \"\u00D7 Close\";\r\n Object.assign(closeBtn.style, {\r\n position: \"absolute\",\r\n top: \"10px\",\r\n right: \"10px\",\r\n background: \"#ff5555\",\r\n color: \"#fff\",\r\n border: \"none\",\r\n padding: \"6px 12px\",\r\n fontSize: \"16px\",\r\n borderRadius: \"4px\",\r\n cursor: \"pointer\",\r\n zIndex: 10,\r\n });\r\n closeBtn.addEventListener(\"click\", () => removeErrorOverlay());\r\n container.appendChild(closeBtn);\r\n\r\n // Title\r\n const title = document.createElement(\"h1\");\r\n title.textContent = \"Runtime Error\";\r\n Object.assign(title.style, {\r\n color: \"#ff5555\",\r\n fontSize: \"24px\",\r\n marginBottom: \"10px\",\r\n });\r\n\r\n // Message\r\n const message = document.createElement(\"pre\");\r\n message.textContent = error?.message || \"Unknown error\";\r\n Object.assign(message.style, {\r\n whiteSpace: \"pre-wrap\",\r\n background: \"rgba(255, 255, 255, 0.1)\",\r\n padding: \"10px\",\r\n borderRadius: \"6px\",\r\n marginTop: \"10px\",\r\n color: \"#ffaaaa\",\r\n });\r\n\r\n // Stack trace\r\n const stack = document.createElement(\"pre\");\r\n stack.textContent = error?.stack || \"\";\r\n Object.assign(stack.style, {\r\n whiteSpace: \"pre-wrap\",\r\n marginTop: \"15px\",\r\n color: \"#ccc\",\r\n });\r\n\r\n container.appendChild(title);\r\n container.appendChild(message);\r\n container.appendChild(stack);\r\n overlay.appendChild(container);\r\n document.body.appendChild(overlay);\r\n\r\n // Smooth fade-in\r\n requestAnimationFrame(() => {\r\n overlay.style.opacity = \"1\";\r\n });\r\n\r\n // Console log\r\n console.error(\"FynixJS Runtime Error]\", error);\r\n}\r\n\r\n/**\r\n * Remove the error overlay from the DOM.\r\n * Fades out the overlay before removing it.\r\n * \r\n * @returns {void}\r\n */\r\nexport function removeErrorOverlay() {\r\n const existing = document.getElementById(\"dev-error-overlay\");\r\n if (existing) {\r\n existing.style.opacity = \"0\";\r\n setTimeout(() => existing.remove(), 200);\r\n }\r\n}\r\n"],
|
|
5
|
+
"mappings": ";;AAmBO,SAAS,iBAAiB,OAAO;AACtC,qBAAmB;AAEnB,QAAM,UAAU,SAAS,cAAc,KAAK;AAC5C,UAAQ,KAAK;AACb,SAAO,OAAO,QAAQ,OAAO;AAAA,IAC3B,UAAU;AAAA,IACV,OAAO;AAAA,IACP,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,iBAAiB;AAAA,IACjB,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,SAAS;AAAA,EACX,CAAC;AAED,QAAM,YAAY,SAAS,cAAc,KAAK;AAC9C,YAAU,MAAM,WAAW;AAC3B,YAAU,MAAM,WAAW;AAC3B,YAAU,MAAM,SAAS;AACzB,YAAU,MAAM,aAAa;AAC7B,YAAU,MAAM,eAAe;AAC/B,YAAU,MAAM,UAAU;AAC1B,YAAU,MAAM,YAAY;AAG5B,QAAM,WAAW,SAAS,cAAc,QAAQ;AAChD,WAAS,cAAc;AACvB,SAAO,OAAO,SAAS,OAAO;AAAA,IAC5B,UAAU;AAAA,IACV,KAAK;AAAA,IACL,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,UAAU;AAAA,IACV,cAAc;AAAA,IACd,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV,CAAC;AACD,WAAS,iBAAiB,SAAS,MAAM,mBAAmB,CAAC;AAC7D,YAAU,YAAY,QAAQ;AAG9B,QAAM,QAAQ,SAAS,cAAc,IAAI;AACzC,QAAM,cAAc;AACpB,SAAO,OAAO,MAAM,OAAO;AAAA,IACzB,OAAO;AAAA,IACP,UAAU;AAAA,IACV,cAAc;AAAA,EAChB,CAAC;AAGD,QAAM,UAAU,SAAS,cAAc,KAAK;AAC5C,UAAQ,cAAc,OAAO,WAAW;AACxC,SAAO,OAAO,QAAQ,OAAO;AAAA,IAC3B,YAAY;AAAA,IACZ,YAAY;AAAA,IACZ,SAAS;AAAA,IACT,cAAc;AAAA,IACd,WAAW;AAAA,IACX,OAAO;AAAA,EACT,CAAC;AAGD,QAAM,QAAQ,SAAS,cAAc,KAAK;AAC1C,QAAM,cAAc,OAAO,SAAS;AACpC,SAAO,OAAO,MAAM,OAAO;AAAA,IACzB,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,OAAO;AAAA,EACT,CAAC;AAED,YAAU,YAAY,KAAK;AAC3B,YAAU,YAAY,OAAO;AAC7B,YAAU,YAAY,KAAK;AAC3B,UAAQ,YAAY,SAAS;AAC7B,WAAS,KAAK,YAAY,OAAO;AAGjC,wBAAsB,MAAM;AAC1B,YAAQ,MAAM,UAAU;AAAA,EAC1B,CAAC;AAGD,UAAQ,MAAM,0BAA0B,KAAK;AAC/C;AA3FgB;AAmGT,SAAS,qBAAqB;AACnC,QAAM,WAAW,SAAS,eAAe,mBAAmB;AAC5D,MAAI,UAAU;AACZ,aAAS,MAAM,UAAU;AACzB,eAAW,MAAM,SAAS,OAAO,GAAG,GAAG;AAAA,EACzC;AACF;AANgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Async state helper with AbortController support.
|
|
3
|
+
*
|
|
4
|
+
* @template T
|
|
5
|
+
* @param {(signal: AbortSignal) => Promise<T>} promiseFactory
|
|
6
|
+
*/
|
|
7
|
+
export function nixAsync<T>(promiseFactory: (signal: AbortSignal) => Promise<T>): {
|
|
8
|
+
data: import("./nixState").NixState;
|
|
9
|
+
error: import("./nixState").NixState;
|
|
10
|
+
loading: import("./nixState").NixState;
|
|
11
|
+
run: () => Promise<void>;
|
|
12
|
+
cancel: () => void;
|
|
13
|
+
};
|
package/dist/hooks/nixAsync.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 { nixState } from "./nixState";
|
|
2
4
|
function nixAsync(promiseFactory) {
|
|
3
5
|
const data = nixState(null);
|
|
@@ -6,7 +8,7 @@ function nixAsync(promiseFactory) {
|
|
|
6
8
|
let active = true;
|
|
7
9
|
let controller = null;
|
|
8
10
|
let callId = 0;
|
|
9
|
-
const run = async () => {
|
|
11
|
+
const run = /* @__PURE__ */ __name(async () => {
|
|
10
12
|
if (controller)
|
|
11
13
|
controller.abort();
|
|
12
14
|
controller = new AbortController();
|
|
@@ -28,14 +30,15 @@ function nixAsync(promiseFactory) {
|
|
|
28
30
|
loading.value = false;
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
|
-
};
|
|
32
|
-
const cancel = () => {
|
|
33
|
+
}, "run");
|
|
34
|
+
const cancel = /* @__PURE__ */ __name(() => {
|
|
33
35
|
active = false;
|
|
34
36
|
if (controller)
|
|
35
37
|
controller.abort();
|
|
36
|
-
};
|
|
38
|
+
}, "cancel");
|
|
37
39
|
return { data, error, loading, run, cancel };
|
|
38
40
|
}
|
|
41
|
+
__name(nixAsync, "nixAsync");
|
|
39
42
|
export {
|
|
40
43
|
nixAsync
|
|
41
44
|
};
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../hooks/nixAsync.js"],
|
|
4
4
|
"sourcesContent": ["import { nixState } from \"./nixState\";\r\n\r\n/**\r\n * Async state helper with AbortController support.\r\n *\r\n * @template T\r\n * @param {(signal: AbortSignal) => Promise<T>} promiseFactory\r\n */\r\nexport function nixAsync(promiseFactory) {\r\n const data = nixState(null);\r\n const error = nixState(null);\r\n const loading = nixState(false);\r\n\r\n let active = true;\r\n let controller = null;\r\n let callId = 0;\r\n\r\n const run = async () => {\r\n // Cancel previous request\r\n if (controller) controller.abort();\r\n\r\n controller = new AbortController();\r\n const signal = controller.signal;\r\n const id = ++callId;\r\n\r\n loading.value = true;\r\n error.value = null;\r\n\r\n try {\r\n const result = await promiseFactory(signal);\r\n if (!active || id !== callId || signal.aborted) return;\r\n data.value = result;\r\n } catch (e) {\r\n if (!active || id !== callId || signal.aborted) return;\r\n error.value = e instanceof Error ? e : new Error(String(e));\r\n } finally {\r\n if (active && id === callId && !signal.aborted) {\r\n loading.value = false;\r\n }\r\n }\r\n };\r\n\r\n const cancel = () => {\r\n active = false;\r\n if (controller) controller.abort();\r\n };\r\n\r\n return { data, error, loading, run, cancel };\r\n}\r\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,gBAAgB;AAQlB,SAAS,SAAS,gBAAgB;AACvC,QAAM,OAAO,SAAS,IAAI;AAC1B,QAAM,QAAQ,SAAS,IAAI;AAC3B,QAAM,UAAU,SAAS,KAAK;AAE9B,MAAI,SAAS;AACb,MAAI,aAAa;AACjB,MAAI,SAAS;AAEb,QAAM,MAAM,
|
|
5
|
+
"mappings": ";;AAAA,SAAS,gBAAgB;AAQlB,SAAS,SAAS,gBAAgB;AACvC,QAAM,OAAO,SAAS,IAAI;AAC1B,QAAM,QAAQ,SAAS,IAAI;AAC3B,QAAM,UAAU,SAAS,KAAK;AAE9B,MAAI,SAAS;AACb,MAAI,aAAa;AACjB,MAAI,SAAS;AAEb,QAAM,MAAM,mCAAY;AAEtB,QAAI;AAAY,iBAAW,MAAM;AAEjC,iBAAa,IAAI,gBAAgB;AACjC,UAAM,SAAS,WAAW;AAC1B,UAAM,KAAK,EAAE;AAEb,YAAQ,QAAQ;AAChB,UAAM,QAAQ;AAEd,QAAI;AACF,YAAM,SAAS,MAAM,eAAe,MAAM;AAC1C,UAAI,CAAC,UAAU,OAAO,UAAU,OAAO;AAAS;AAChD,WAAK,QAAQ;AAAA,IACf,SAAS,GAAG;AACV,UAAI,CAAC,UAAU,OAAO,UAAU,OAAO;AAAS;AAChD,YAAM,QAAQ,aAAa,QAAQ,IAAI,IAAI,MAAM,OAAO,CAAC,CAAC;AAAA,IAC5D,UAAE;AACA,UAAI,UAAU,OAAO,UAAU,CAAC,OAAO,SAAS;AAC9C,gBAAQ,QAAQ;AAAA,MAClB;AAAA,IACF;AAAA,EACF,GAvBY;AAyBZ,QAAM,SAAS,6BAAM;AACnB,aAAS;AACT,QAAI;AAAY,iBAAW,MAAM;AAAA,EACnC,GAHe;AAKf,SAAO,EAAE,MAAM,OAAO,SAAS,KAAK,OAAO;AAC7C;AAxCgB;",
|
|
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 { nixState } from "./nixState";
|
|
2
4
|
const asyncCache = /* @__PURE__ */ new Map();
|
|
3
5
|
function nixAsyncCached(key, promiseFactory) {
|
|
@@ -5,7 +7,7 @@ function nixAsyncCached(key, promiseFactory) {
|
|
|
5
7
|
const error = nixState(null);
|
|
6
8
|
const loading = nixState(false);
|
|
7
9
|
let active = true;
|
|
8
|
-
const run = async () => {
|
|
10
|
+
const run = /* @__PURE__ */ __name(async () => {
|
|
9
11
|
loading.value = true;
|
|
10
12
|
error.value = null;
|
|
11
13
|
if (asyncCache.has(key)) {
|
|
@@ -46,12 +48,13 @@ function nixAsyncCached(key, promiseFactory) {
|
|
|
46
48
|
if (active)
|
|
47
49
|
loading.value = false;
|
|
48
50
|
}
|
|
49
|
-
};
|
|
50
|
-
const cancel = () => {
|
|
51
|
+
}, "run");
|
|
52
|
+
const cancel = /* @__PURE__ */ __name(() => {
|
|
51
53
|
active = false;
|
|
52
|
-
};
|
|
54
|
+
}, "cancel");
|
|
53
55
|
return { data, error, loading, run, cancel };
|
|
54
56
|
}
|
|
57
|
+
__name(nixAsyncCached, "nixAsyncCached");
|
|
55
58
|
export {
|
|
56
59
|
nixAsyncCached
|
|
57
60
|
};
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../hooks/nixAsyncCache.js"],
|
|
4
4
|
"sourcesContent": ["import { nixState } from \"./nixState\";\r\n\r\nconst asyncCache = new Map();\r\n\r\nexport function nixAsyncCached(key, promiseFactory) {\r\n const data = nixState(null);\r\n const error = nixState(null);\r\n const loading = nixState(false);\r\n\r\n let active = true;\r\n\r\n const run = async () => {\r\n loading.value = true;\r\n error.value = null;\r\n\r\n // Cache hit with resolved data\r\n if (asyncCache.has(key)) {\r\n const cached = asyncCache.get(key);\r\n\r\n if (cached.data) {\r\n data.value = cached.data;\r\n loading.value = false;\r\n return;\r\n }\r\n\r\n // Deduping: reuse in-flight promise\r\n try {\r\n const result = await cached.promise;\r\n if (!active) return;\r\n data.value = result;\r\n loading.value = false;\r\n } catch (e) {\r\n if (!active) return;\r\n error.value = e;\r\n loading.value = false;\r\n }\r\n return;\r\n }\r\n\r\n // Cache miss\r\n const promise = Promise.resolve().then(promiseFactory);\r\n asyncCache.set(key, { promise });\r\n\r\n try {\r\n const result = await promise;\r\n asyncCache.set(key, { data: result });\r\n if (!active) return;\r\n data.value = result;\r\n } catch (e) {\r\n asyncCache.delete(key);\r\n if (!active) return;\r\n error.value = e;\r\n } finally {\r\n if (active) loading.value = false;\r\n }\r\n };\r\n\r\n const cancel = () => {\r\n active = false;\r\n };\r\n\r\n return { data, error, loading, run, cancel };\r\n}\r\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,gBAAgB;AAEzB,MAAM,aAAa,oBAAI,IAAI;AAEpB,SAAS,eAAe,KAAK,gBAAgB;AAClD,QAAM,OAAO,SAAS,IAAI;AAC1B,QAAM,QAAQ,SAAS,IAAI;AAC3B,QAAM,UAAU,SAAS,KAAK;AAE9B,MAAI,SAAS;AAEb,QAAM,MAAM,
|
|
5
|
+
"mappings": ";;AAAA,SAAS,gBAAgB;AAEzB,MAAM,aAAa,oBAAI,IAAI;AAEpB,SAAS,eAAe,KAAK,gBAAgB;AAClD,QAAM,OAAO,SAAS,IAAI;AAC1B,QAAM,QAAQ,SAAS,IAAI;AAC3B,QAAM,UAAU,SAAS,KAAK;AAE9B,MAAI,SAAS;AAEb,QAAM,MAAM,mCAAY;AACtB,YAAQ,QAAQ;AAChB,UAAM,QAAQ;AAGd,QAAI,WAAW,IAAI,GAAG,GAAG;AACvB,YAAM,SAAS,WAAW,IAAI,GAAG;AAEjC,UAAI,OAAO,MAAM;AACf,aAAK,QAAQ,OAAO;AACpB,gBAAQ,QAAQ;AAChB;AAAA,MACF;AAGA,UAAI;AACF,cAAM,SAAS,MAAM,OAAO;AAC5B,YAAI,CAAC;AAAQ;AACb,aAAK,QAAQ;AACb,gBAAQ,QAAQ;AAAA,MAClB,SAAS,GAAG;AACV,YAAI,CAAC;AAAQ;AACb,cAAM,QAAQ;AACd,gBAAQ,QAAQ;AAAA,MAClB;AACA;AAAA,IACF;AAGA,UAAM,UAAU,QAAQ,QAAQ,EAAE,KAAK,cAAc;AACrD,eAAW,IAAI,KAAK,EAAE,QAAQ,CAAC;AAE/B,QAAI;AACF,YAAM,SAAS,MAAM;AACrB,iBAAW,IAAI,KAAK,EAAE,MAAM,OAAO,CAAC;AACpC,UAAI,CAAC;AAAQ;AACb,WAAK,QAAQ;AAAA,IACf,SAAS,GAAG;AACV,iBAAW,OAAO,GAAG;AACrB,UAAI,CAAC;AAAQ;AACb,YAAM,QAAQ;AAAA,IAChB,UAAE;AACA,UAAI;AAAQ,gBAAQ,QAAQ;AAAA,IAC9B;AAAA,EACF,GA5CY;AA8CZ,QAAM,SAAS,6BAAM;AACnB,aAAS;AAAA,EACX,GAFe;AAIf,SAAO,EAAE,MAAM,OAAO,SAAS,KAAK,OAAO;AAC7C;AA1DgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Debounced and cancellable async data fetcher with caching and deduping.
|
|
3
|
+
*
|
|
4
|
+
* @param {() => Promise<any>} promiseFactory - Async function that returns a promise.
|
|
5
|
+
* @param {Object} [options={}] - Options for debounce, caching, and abort.
|
|
6
|
+
* @param {number} [options.delay=300] - Debounce delay in ms.
|
|
7
|
+
* @param {boolean} [options.leading=false] - Run on leading edge.
|
|
8
|
+
* @param {boolean} [options.trailing=true] - Run on trailing edge.
|
|
9
|
+
* @param {number} [options.maxWait] - Max wait time before forced invocation.
|
|
10
|
+
* @param {boolean} [options.cache=true] - Enable caching of last result.
|
|
11
|
+
* @param {AbortSignal} [options.signal] - Optional AbortSignal to cancel request.
|
|
12
|
+
* @returns {Object} { data, error, loading, run, cancel }
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const controller = new AbortController();
|
|
16
|
+
* const { data, error, loading, run, cancel } = nixAsyncDebounce(
|
|
17
|
+
* () => fetch('/api/data').then(r => r.json()),
|
|
18
|
+
* { delay: 500, maxWait: 2000, leading: true, signal: controller.signal }
|
|
19
|
+
* );
|
|
20
|
+
*/
|
|
21
|
+
export function nixAsyncDebounce(promiseFactory: () => Promise<any>, options?: {
|
|
22
|
+
delay?: number;
|
|
23
|
+
leading?: boolean;
|
|
24
|
+
trailing?: boolean;
|
|
25
|
+
maxWait?: number;
|
|
26
|
+
cache?: boolean;
|
|
27
|
+
signal?: AbortSignal;
|
|
28
|
+
}): 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";
|
|
2
4
|
function nixAsyncDebounce(promiseFactory, options = {}) {
|
|
3
5
|
const data = nixState(null);
|
|
@@ -16,7 +18,7 @@ function nixAsyncDebounce(promiseFactory, options = {}) {
|
|
|
16
18
|
let timerId = null;
|
|
17
19
|
let lastInvokeTime = 0;
|
|
18
20
|
let pendingPromise = null;
|
|
19
|
-
const invoke = async () => {
|
|
21
|
+
const invoke = /* @__PURE__ */ __name(async () => {
|
|
20
22
|
if (cache && lastResult !== null) {
|
|
21
23
|
data.value = lastResult;
|
|
22
24
|
error.value = lastError;
|
|
@@ -49,8 +51,8 @@ function nixAsyncDebounce(promiseFactory, options = {}) {
|
|
|
49
51
|
pendingPromise = null;
|
|
50
52
|
lastInvokeTime = Date.now();
|
|
51
53
|
}
|
|
52
|
-
};
|
|
53
|
-
const run = () => {
|
|
54
|
+
}, "invoke");
|
|
55
|
+
const run = /* @__PURE__ */ __name(() => {
|
|
54
56
|
const now = Date.now();
|
|
55
57
|
const timeSinceLastInvoke = now - lastInvokeTime;
|
|
56
58
|
const remainingTime = delay - timeSinceLastInvoke;
|
|
@@ -71,14 +73,15 @@ function nixAsyncDebounce(promiseFactory, options = {}) {
|
|
|
71
73
|
invoke();
|
|
72
74
|
}, remainingTime > 0 ? remainingTime : delay);
|
|
73
75
|
}
|
|
74
|
-
};
|
|
75
|
-
const cancel = () => {
|
|
76
|
+
}, "run");
|
|
77
|
+
const cancel = /* @__PURE__ */ __name(() => {
|
|
76
78
|
if (timerId)
|
|
77
79
|
clearTimeout(timerId);
|
|
78
80
|
timerId = pendingPromise = null;
|
|
79
|
-
};
|
|
81
|
+
}, "cancel");
|
|
80
82
|
return { data, error, loading, run, cancel };
|
|
81
83
|
}
|
|
84
|
+
__name(nixAsyncDebounce, "nixAsyncDebounce");
|
|
82
85
|
export {
|
|
83
86
|
nixAsyncDebounce
|
|
84
87
|
};
|