applesauce-react 0.0.0-next-20250312111321 → 0.0.0-next-20250312152821
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/hooks/use-event-store.d.ts +2 -1
- 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-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/store-provider.d.ts +3 -3
- package/package.json +5 -5
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { IEventStore } from "applesauce-core/event-store";
|
|
1
2
|
/**
|
|
2
3
|
* Gets the EventStore from a parent {@link EventStoreProvider} component
|
|
3
4
|
* If there is none it throws an error
|
|
4
5
|
*/
|
|
5
|
-
export declare function useEventStore():
|
|
6
|
+
export declare function useEventStore(): IEventStore;
|
|
@@ -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,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
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { PropsWithChildren } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { IEventStore, QueryStore } from "applesauce-core";
|
|
3
3
|
export declare const QueryStoreContext: import("react").Context<QueryStore | null>;
|
|
4
|
-
export declare const EventStoreContext: import("react").Context<
|
|
4
|
+
export declare const EventStoreContext: import("react").Context<IEventStore | null>;
|
|
5
5
|
/** Provides a EventStore to the component tree */
|
|
6
6
|
export declare function EventStoreProvider({ eventStore, children }: PropsWithChildren<{
|
|
7
|
-
eventStore:
|
|
7
|
+
eventStore: IEventStore;
|
|
8
8
|
}>): import("react/jsx-runtime").JSX.Element;
|
|
9
9
|
/** Provides a QueryStore and EventStore to the component tree */
|
|
10
10
|
export declare function QueryStoreProvider({ queryStore, children }: PropsWithChildren<{
|
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-20250312152821",
|
|
4
4
|
"description": "React hooks for applesauce",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"applesauce-accounts": "0.0.0-next-
|
|
53
|
-
"applesauce-content": "0.0.0-next-
|
|
54
|
-
"applesauce-core": "0.0.0-next-
|
|
55
|
-
"applesauce-factory": "0.0.0-next-
|
|
52
|
+
"applesauce-accounts": "0.0.0-next-20250312152821",
|
|
53
|
+
"applesauce-content": "0.0.0-next-20250312152821",
|
|
54
|
+
"applesauce-core": "0.0.0-next-20250312152821",
|
|
55
|
+
"applesauce-factory": "0.0.0-next-20250312152821",
|
|
56
56
|
"nostr-tools": "^2.10.4",
|
|
57
57
|
"observable-hooks": "^4.2.4",
|
|
58
58
|
"react": "^18.3.1",
|