applesauce-react 0.0.0-next-20250312162115 → 0.0.0-next-20250312201602

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.
@@ -1,10 +1,12 @@
1
1
  export * from "./use-account-manager.js";
2
2
  export * from "./use-accounts.js";
3
+ export * from "./use-action-hub.js";
4
+ export * from "./use-action.js";
3
5
  export * from "./use-active-account.js";
4
6
  export * from "./use-event-factory.js";
7
+ export * from "./use-event-store.js";
5
8
  export * from "./use-observable.js";
6
9
  export * from "./use-query-store.js";
7
10
  export * from "./use-render-nast.js";
8
11
  export * from "./use-rendered-content.js";
9
12
  export * from "./use-store-query.js";
10
- export * from "./use-event-store.js";
@@ -1,10 +1,12 @@
1
1
  export * from "./use-account-manager.js";
2
2
  export * from "./use-accounts.js";
3
+ export * from "./use-action-hub.js";
4
+ export * from "./use-action.js";
3
5
  export * from "./use-active-account.js";
4
6
  export * from "./use-event-factory.js";
7
+ export * from "./use-event-store.js";
5
8
  export * from "./use-observable.js";
6
9
  export * from "./use-query-store.js";
7
10
  export * from "./use-render-nast.js";
8
11
  export * from "./use-rendered-content.js";
9
12
  export * from "./use-store-query.js";
10
- export * from "./use-event-store.js";
@@ -0,0 +1 @@
1
+ export declare function useActionHub(): import("applesauce-actions").ActionHub;
@@ -0,0 +1,8 @@
1
+ import { useContext } from "react";
2
+ import { ActionsContext } from "../providers/actions-provider.js";
3
+ export function useActionHub() {
4
+ const hub = useContext(ActionsContext);
5
+ if (!hub)
6
+ throw new Error("Missing ActionsProvider");
7
+ return hub;
8
+ }
@@ -0,0 +1,5 @@
1
+ import { ActionConstructor } from "applesauce-actions";
2
+ export declare function useAction<Args extends Array<any>, T extends unknown = unknown>(Action: ActionConstructor<Args, T>, args: Args | undefined): {
3
+ loading: boolean;
4
+ run: () => Promise<void>;
5
+ };
@@ -0,0 +1,22 @@
1
+ import { useCallback, useRef, useState } from "react";
2
+ import { useActionHub } from "./use-action-hub.js";
3
+ export function useAction(Action, args) {
4
+ const [loading, setLoading] = useState(false);
5
+ const ref = useRef(args);
6
+ ref.current = args;
7
+ const hub = useActionHub();
8
+ const run = useCallback(async () => {
9
+ if (args === undefined)
10
+ return;
11
+ setLoading(true);
12
+ try {
13
+ await hub.run(Action, ...args);
14
+ setLoading(false);
15
+ }
16
+ catch (error) {
17
+ setLoading(false);
18
+ throw error;
19
+ }
20
+ }, [Action]);
21
+ return { loading, run };
22
+ }
@@ -0,0 +1,7 @@
1
+ import { PropsWithChildren } from "react";
2
+ import { ActionHub } from "applesauce-actions";
3
+ export declare const ActionsContext: import("react").Context<ActionHub | undefined>;
4
+ /** Provides an ActionHub to the component tree */
5
+ export declare function ActionsProvider({ actionHub, children }: PropsWithChildren<{
6
+ actionHub?: ActionHub;
7
+ }>): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext } from "react";
3
+ export const ActionsContext = createContext(undefined);
4
+ /** Provides an ActionHub to the component tree */
5
+ export function ActionsProvider({ actionHub, children }) {
6
+ return _jsx(ActionsContext.Provider, { value: actionHub, children: children });
7
+ }
@@ -1,3 +1,4 @@
1
1
  export * from "./factory-provider.js";
2
2
  export * from "./store-provider.js";
3
3
  export * from "./accounts-provider.js";
4
+ export * from "./actions-provider.js";
@@ -1,3 +1,4 @@
1
1
  export * from "./factory-provider.js";
2
2
  export * from "./store-provider.js";
3
3
  export * from "./accounts-provider.js";
4
+ export * from "./actions-provider.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-react",
3
- "version": "0.0.0-next-20250312162115",
3
+ "version": "0.0.0-next-20250312201602",
4
4
  "description": "React hooks for applesauce",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -49,10 +49,11 @@
49
49
  }
50
50
  },
51
51
  "dependencies": {
52
- "applesauce-accounts": "0.0.0-next-20250312162115",
53
- "applesauce-content": "0.0.0-next-20250312162115",
54
- "applesauce-core": "0.0.0-next-20250312162115",
55
- "applesauce-factory": "0.0.0-next-20250312162115",
52
+ "applesauce-accounts": "0.0.0-next-20250312201602",
53
+ "applesauce-actions": "0.0.0-next-20250312201602",
54
+ "applesauce-content": "0.0.0-next-20250312201602",
55
+ "applesauce-core": "0.0.0-next-20250312201602",
56
+ "applesauce-factory": "0.0.0-next-20250312201602",
56
57
  "nostr-tools": "^2.10.4",
57
58
  "observable-hooks": "^4.2.4",
58
59
  "react": "^18.3.1",