applesauce-react 0.0.0-next-20250808173123 → 0.0.0-next-20250815164532
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/__tests__/exports.test.d.ts +1 -0
- package/dist/__tests__/exports.test.js +20 -0
- package/dist/helpers/__tests__/exports.test.d.ts +1 -0
- package/dist/helpers/__tests__/exports.test.js +12 -0
- package/dist/hooks/__tests__/exports.test.d.ts +1 -0
- package/dist/hooks/__tests__/exports.test.js +43 -0
- package/dist/hooks/use-query-store.d.ts +5 -0
- package/dist/hooks/use-query-store.js +12 -0
- package/dist/hooks/use-rendered-text-content.d.ts +17 -0
- package/dist/hooks/use-rendered-text-content.js +16 -0
- package/dist/hooks/use-store-query.d.ts +7 -0
- package/dist/hooks/use-store-query.js +19 -0
- package/dist/hooks/use-text-content.d.ts +6 -0
- package/dist/hooks/use-text-content.js +8 -0
- package/dist/provider.d.ts +7 -0
- package/dist/provider.js +7 -0
- package/dist/providers/__tests__/exports.test.d.ts +1 -0
- package/dist/providers/__tests__/exports.test.js +18 -0
- package/package.json +6 -6
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import * as exports from "../index.js";
|
|
3
|
+
describe("exports", () => {
|
|
4
|
+
it("should export the expected functions", () => {
|
|
5
|
+
expect(Object.keys(exports).sort()).toMatchInlineSnapshot(`
|
|
6
|
+
[
|
|
7
|
+
"AccountsContext",
|
|
8
|
+
"AccountsProvider",
|
|
9
|
+
"ActionsContext",
|
|
10
|
+
"ActionsProvider",
|
|
11
|
+
"EventStoreContext",
|
|
12
|
+
"EventStoreProvider",
|
|
13
|
+
"FactoryContext",
|
|
14
|
+
"FactoryProvider",
|
|
15
|
+
"Helpers",
|
|
16
|
+
"Hooks",
|
|
17
|
+
]
|
|
18
|
+
`);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import * as exports from "../index.js";
|
|
3
|
+
describe("exports", () => {
|
|
4
|
+
it("should export the expected functions", () => {
|
|
5
|
+
expect(Object.keys(exports).sort()).toMatchInlineSnapshot(`
|
|
6
|
+
[
|
|
7
|
+
"buildLinkRenderer",
|
|
8
|
+
"renderNast",
|
|
9
|
+
]
|
|
10
|
+
`);
|
|
11
|
+
});
|
|
12
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import * as exports from "../index.js";
|
|
3
|
+
describe("exports", () => {
|
|
4
|
+
it("should export the expected functions", () => {
|
|
5
|
+
expect(Object.keys(exports).sort()).toMatchInlineSnapshot(`
|
|
6
|
+
[
|
|
7
|
+
"ComponentMap",
|
|
8
|
+
"ObservableResource",
|
|
9
|
+
"identity",
|
|
10
|
+
"pluckCurrentTargetChecked",
|
|
11
|
+
"pluckCurrentTargetValue",
|
|
12
|
+
"pluckFirst",
|
|
13
|
+
"useAccountManager",
|
|
14
|
+
"useAccounts",
|
|
15
|
+
"useAction",
|
|
16
|
+
"useActionHub",
|
|
17
|
+
"useActiveAccount",
|
|
18
|
+
"useEventFactory",
|
|
19
|
+
"useEventModel",
|
|
20
|
+
"useEventStore",
|
|
21
|
+
"useForceUpdate",
|
|
22
|
+
"useLayoutObservable",
|
|
23
|
+
"useLayoutObservableState",
|
|
24
|
+
"useLayoutSubscription",
|
|
25
|
+
"useObservable",
|
|
26
|
+
"useObservableCallback",
|
|
27
|
+
"useObservableEagerMemo",
|
|
28
|
+
"useObservableEagerState",
|
|
29
|
+
"useObservableGetState",
|
|
30
|
+
"useObservableMemo",
|
|
31
|
+
"useObservablePickState",
|
|
32
|
+
"useObservableRef",
|
|
33
|
+
"useObservableState",
|
|
34
|
+
"useObservableSuspense",
|
|
35
|
+
"useRefFn",
|
|
36
|
+
"useRenderNast",
|
|
37
|
+
"useRenderThrow",
|
|
38
|
+
"useRenderedContent",
|
|
39
|
+
"useSubscription",
|
|
40
|
+
]
|
|
41
|
+
`);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { QueryStoreContext } from "../providers/store-provider.js";
|
|
3
|
+
/**
|
|
4
|
+
* Gets the QueryStore from a parent {@link QueryStoreProvider} component
|
|
5
|
+
* If there is none it throws an error
|
|
6
|
+
*/
|
|
7
|
+
export function useQueryStore() {
|
|
8
|
+
const store = useContext(QueryStoreContext);
|
|
9
|
+
if (!store)
|
|
10
|
+
throw new Error("Missing QueryStoreProvider");
|
|
11
|
+
return store;
|
|
12
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getParsedTextContent } from "applesauce-content/text";
|
|
2
|
+
import { EventTemplate, NostrEvent } from "nostr-tools";
|
|
3
|
+
import { ComponentMap } from "../helpers/nast.js";
|
|
4
|
+
import { LinkRenderer } from "../helpers/build-link-renderer.js";
|
|
5
|
+
export { ComponentMap };
|
|
6
|
+
type Options = {
|
|
7
|
+
/** Override transformers */
|
|
8
|
+
transformers?: Parameters<typeof getParsedTextContent>[2];
|
|
9
|
+
/** If set will use {@link buildLinkRenderer} to render links */
|
|
10
|
+
linkRenderers?: LinkRenderer[];
|
|
11
|
+
/** Override event content */
|
|
12
|
+
content?: string;
|
|
13
|
+
/** Maximum length */
|
|
14
|
+
maxLength?: number;
|
|
15
|
+
};
|
|
16
|
+
/** Returns the parsed and render text content for an event */
|
|
17
|
+
export declare function useRenderedContent(event: NostrEvent | EventTemplate | string | undefined, components: ComponentMap, opts?: Options): JSX.Element | null;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { getParsedTextContent } from "applesauce-content/text";
|
|
3
|
+
import { useRenderNast } from "./use-render-nast.js";
|
|
4
|
+
import { buildLinkRenderer } from "../helpers/build-link-renderer.js";
|
|
5
|
+
import { truncateContent } from "applesauce-content/nast";
|
|
6
|
+
/** Returns the parsed and render text content for an event */
|
|
7
|
+
export function useRenderedContent(event, components, opts) {
|
|
8
|
+
// if link renderers are set, override the link components
|
|
9
|
+
const _components = useMemo(() => (opts?.linkRenderers ? { ...components, link: buildLinkRenderer(opts.linkRenderers) } : components), [opts?.linkRenderers, components]);
|
|
10
|
+
// add additional transformers
|
|
11
|
+
const nast = useMemo(() => (event ? getParsedTextContent(event, opts?.content, opts?.transformers) : undefined), [event, opts?.content, opts?.transformers]);
|
|
12
|
+
let truncated = nast;
|
|
13
|
+
if (opts?.maxLength && nast)
|
|
14
|
+
truncated = truncateContent(nast, opts.maxLength);
|
|
15
|
+
return useRenderNast(truncated, _components);
|
|
16
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { QueryConstructor } from "applesauce-core";
|
|
2
|
+
/**
|
|
3
|
+
* Runs and subscribes to a query in the query store
|
|
4
|
+
* @example
|
|
5
|
+
* const events = useStoreQuery(TimelineQuery, [{kinds: [1]}])
|
|
6
|
+
*/
|
|
7
|
+
export declare function useStoreQuery<T extends unknown, Args extends Array<any>>(queryConstructor: QueryConstructor<T, Args>, args?: Args | null): T | undefined;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { of } from "rxjs";
|
|
3
|
+
import { useObservableEagerState } from "observable-hooks";
|
|
4
|
+
import { useQueryStore } from "./use-query-store.js";
|
|
5
|
+
/**
|
|
6
|
+
* Runs and subscribes to a query in the query store
|
|
7
|
+
* @example
|
|
8
|
+
* const events = useStoreQuery(TimelineQuery, [{kinds: [1]}])
|
|
9
|
+
*/
|
|
10
|
+
export function useStoreQuery(queryConstructor, args) {
|
|
11
|
+
const store = useQueryStore();
|
|
12
|
+
const observable = useMemo(() => {
|
|
13
|
+
if (args)
|
|
14
|
+
return store.createQuery(queryConstructor, ...args);
|
|
15
|
+
else
|
|
16
|
+
return of(undefined);
|
|
17
|
+
}, [args, store]);
|
|
18
|
+
return useObservableEagerState(observable);
|
|
19
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ParseTextContentOptions } from "applesauce-content/text";
|
|
2
|
+
import { EventTemplate, NostrEvent } from "nostr-tools";
|
|
3
|
+
import { ComponentMap } from "../helpers/nast.js";
|
|
4
|
+
export { ComponentMap };
|
|
5
|
+
/** Returns the parsed and render text content for an event */
|
|
6
|
+
export declare function useRenderedContent(event: NostrEvent | EventTemplate, components: ComponentMap, opts?: ParseTextContentOptions): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { getParedTextContent } from "applesauce-content/text";
|
|
3
|
+
import { useRenderNast } from "./use-render-nast.js";
|
|
4
|
+
/** Returns the parsed and render text content for an event */
|
|
5
|
+
export function useRenderedContent(event, components, opts) {
|
|
6
|
+
const nast = useMemo(() => getParedTextContent(event, opts), [event, opts?.overrideContent, opts?.transformers]);
|
|
7
|
+
return useRenderNast(nast, components);
|
|
8
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { QueryStore } from "applesauce-core";
|
|
2
|
+
import { PropsWithChildren } from "react";
|
|
3
|
+
export declare const QueryStoreContext: import("react").Context<QueryStore | null>;
|
|
4
|
+
/** Provides a QueryStore to the component tree */
|
|
5
|
+
export declare function QueryStoreProvider({ store, children }: PropsWithChildren<{
|
|
6
|
+
store: QueryStore;
|
|
7
|
+
}>): import("react/jsx-runtime").JSX.Element;
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext } from "react";
|
|
3
|
+
export const QueryStoreContext = createContext(null);
|
|
4
|
+
/** Provides a QueryStore to the component tree */
|
|
5
|
+
export function QueryStoreProvider({ store, children }) {
|
|
6
|
+
return _jsx(QueryStoreContext.Provider, { value: store, children: children });
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import * as exports from "../index.js";
|
|
3
|
+
describe("exports", () => {
|
|
4
|
+
it("should export the expected functions", () => {
|
|
5
|
+
expect(Object.keys(exports).sort()).toMatchInlineSnapshot(`
|
|
6
|
+
[
|
|
7
|
+
"AccountsContext",
|
|
8
|
+
"AccountsProvider",
|
|
9
|
+
"ActionsContext",
|
|
10
|
+
"ActionsProvider",
|
|
11
|
+
"EventStoreContext",
|
|
12
|
+
"EventStoreProvider",
|
|
13
|
+
"FactoryContext",
|
|
14
|
+
"FactoryProvider",
|
|
15
|
+
]
|
|
16
|
+
`);
|
|
17
|
+
});
|
|
18
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-react",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20250815164532",
|
|
4
4
|
"description": "React hooks for applesauce",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -49,11 +49,11 @@
|
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"applesauce-accounts": "0.0.0-next-
|
|
53
|
-
"applesauce-actions": "0.0.0-next-
|
|
54
|
-
"applesauce-content": "0.0.0-next-
|
|
55
|
-
"applesauce-core": "0.0.0-next-
|
|
56
|
-
"applesauce-factory": "0.0.0-next-
|
|
52
|
+
"applesauce-accounts": "0.0.0-next-20250815164532",
|
|
53
|
+
"applesauce-actions": "0.0.0-next-20250815164532",
|
|
54
|
+
"applesauce-content": "0.0.0-next-20250815164532",
|
|
55
|
+
"applesauce-core": "0.0.0-next-20250815164532",
|
|
56
|
+
"applesauce-factory": "0.0.0-next-20250815164532",
|
|
57
57
|
"hash-sum": "^2.0.0",
|
|
58
58
|
"nostr-tools": "^2.13",
|
|
59
59
|
"observable-hooks": "^4.2.4",
|