nostr-comments 0.4.0 → 0.7.0
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/README.md +48 -15
- package/dist/components/CommentEditor.d.ts +3 -2
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/useComments.d.ts +2 -1
- package/dist/hooks/useSigner.d.ts +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/nostr-comments.cjs +77 -19
- package/dist/nostr-comments.js +1550 -1435
- package/dist/nostr-comments.umd.js +73 -15
- package/dist/services/comment.d.ts +3 -8
- package/dist/services/nostr.d.ts +1 -1
- package/dist/types/index.d.ts +8 -1
- package/dist/utils/nip22.d.ts +2 -8
- package/dist/utils/pow-worker.d.ts +5 -0
- package/dist/utils/pubkey.d.ts +1 -0
- package/package.json +4 -14
package/README.md
CHANGED
|
@@ -25,7 +25,6 @@ npm install nostr-comments
|
|
|
25
25
|
|
|
26
26
|
```tsx
|
|
27
27
|
import { NostrComments } from "nostr-comments";
|
|
28
|
-
import "nostr-comments/style.css";
|
|
29
28
|
|
|
30
29
|
function App() {
|
|
31
30
|
return <NostrComments url="https://example.com/blog/my-post" locale="en" />;
|
|
@@ -36,20 +35,22 @@ function App() {
|
|
|
36
35
|
|
|
37
36
|
### NostrComments Component Props
|
|
38
37
|
|
|
39
|
-
| Prop | Type | Default | Description
|
|
40
|
-
| -------------------- | ----------------------------------- | ------------------ |
|
|
41
|
-
| `url` | `string` | **Required** | Web page URL, used to identify comment scope
|
|
42
|
-
| `
|
|
43
|
-
| `relays` | `string[]` | Default relay list | List of Nostr relay addresses
|
|
44
|
-
| `pageSize` | `number` | `50` | Number of comments per page
|
|
45
|
-
| `locale` | `string` | Auto-detect | Interface language (20 languages supported)
|
|
46
|
-
| `translations` | `Partial<Translations>` | - | Custom translation text
|
|
47
|
-
| `theme` | `'light' \| 'dark' \| 'auto'` | `'auto'` | Theme mode
|
|
48
|
-
| `headless` | `boolean` | `false` | Enable Headless mode
|
|
49
|
-
| `classNames` | `object` | - | Custom CSS class names
|
|
50
|
-
| `
|
|
51
|
-
| `
|
|
52
|
-
| `
|
|
38
|
+
| Prop | Type | Default | Description |
|
|
39
|
+
| -------------------- | ----------------------------------- | ------------------ | ---------------------------------------------------------- |
|
|
40
|
+
| `url` | `string` | **Required** | Web page URL, used to identify comment scope |
|
|
41
|
+
| `mention` | `string` | - | Public key to mention in comments (receives notifications) |
|
|
42
|
+
| `relays` | `string[]` | Default relay list | List of Nostr relay addresses |
|
|
43
|
+
| `pageSize` | `number` | `50` | Number of comments per page |
|
|
44
|
+
| `locale` | `string` | Auto-detect | Interface language (20 languages supported) |
|
|
45
|
+
| `translations` | `Partial<Translations>` | - | Custom translation text |
|
|
46
|
+
| `theme` | `'light' \| 'dark' \| 'auto'` | `'auto'` | Theme mode |
|
|
47
|
+
| `headless` | `boolean` | `false` | Enable Headless mode |
|
|
48
|
+
| `classNames` | `object` | - | Custom CSS class names |
|
|
49
|
+
| `signer` | `Signer` | - | External signer instance (skips login modal when provided) |
|
|
50
|
+
| `enabledSigners` | `('nip07' \| 'bunker' \| 'temp')[]` | All enabled | Enabled login methods |
|
|
51
|
+
| `pow` | `number` | `18` | POW difficulty (leading zero bits) to prevent spam |
|
|
52
|
+
| `onCommentPublished` | `(event: NostrEvent) => void` | - | Callback when comment is published |
|
|
53
|
+
| `onError` | `(error: Error) => void` | - | Error callback |
|
|
53
54
|
|
|
54
55
|
### classNames Object
|
|
55
56
|
|
|
@@ -96,12 +97,42 @@ function App() {
|
|
|
96
97
|
/>
|
|
97
98
|
```
|
|
98
99
|
|
|
100
|
+
### Anti-Spam with POW
|
|
101
|
+
|
|
102
|
+
```tsx
|
|
103
|
+
<NostrComments url="https://example.com/post/123" pow={18} />
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Requires commenters to compute a proof-of-work (NIP-13) before publishing. Higher values = more computation time = stronger spam prevention. Recommended: 10-20 bits.
|
|
107
|
+
|
|
99
108
|
### Extension Login Only
|
|
100
109
|
|
|
101
110
|
```tsx
|
|
102
111
|
<NostrComments url="https://example.com/post/123" enabledSigners={["nip07"]} />
|
|
103
112
|
```
|
|
104
113
|
|
|
114
|
+
### External Signer
|
|
115
|
+
|
|
116
|
+
Pass your own signer instance to skip the built-in login modal:
|
|
117
|
+
|
|
118
|
+
```tsx
|
|
119
|
+
import { NostrComments, Nip07Signer, TempSigner } from "nostr-comments";
|
|
120
|
+
|
|
121
|
+
// Use NIP-07 extension
|
|
122
|
+
const signer = new Nip07Signer();
|
|
123
|
+
|
|
124
|
+
// Or use a temporary signer
|
|
125
|
+
const signer = new TempSigner();
|
|
126
|
+
|
|
127
|
+
// Or any object that implements the Signer interface
|
|
128
|
+
const customSigner = {
|
|
129
|
+
getPublicKey: async () => "your-pubkey",
|
|
130
|
+
signEvent: async (event) => signedEvent,
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
<NostrComments url="https://example.com/post/123" signer={signer} />;
|
|
134
|
+
```
|
|
135
|
+
|
|
105
136
|
### Headless Mode
|
|
106
137
|
|
|
107
138
|
```tsx
|
|
@@ -160,8 +191,10 @@ For dark mode, override the base colors under `[data-theme="dark"]` or `[data-th
|
|
|
160
191
|
|
|
161
192
|
/* Border Radius */
|
|
162
193
|
--nc-radius-sm: 8px;
|
|
194
|
+
/* button, textarea radius */
|
|
163
195
|
--nc-radius-md: 12px;
|
|
164
196
|
--nc-radius-lg: 16px;
|
|
197
|
+
/* modal radius */
|
|
165
198
|
--nc-radius-xl: 24px;
|
|
166
199
|
|
|
167
200
|
/* Avatar Border Radius */
|
|
@@ -2,7 +2,8 @@ import type { NostrEvent } from "nostr-tools";
|
|
|
2
2
|
interface CommentEditorProps {
|
|
3
3
|
url: string;
|
|
4
4
|
relays?: string[];
|
|
5
|
-
|
|
5
|
+
mention?: string;
|
|
6
|
+
pow?: number;
|
|
6
7
|
parentEvent?: NostrEvent | null;
|
|
7
8
|
onClearParent?: () => void;
|
|
8
9
|
onPublished?: (event: NostrEvent) => void;
|
|
@@ -10,5 +11,5 @@ interface CommentEditorProps {
|
|
|
10
11
|
onError?: (error: Error) => void;
|
|
11
12
|
className?: string;
|
|
12
13
|
}
|
|
13
|
-
export declare function CommentEditor({ url, relays,
|
|
14
|
+
export declare function CommentEditor({ url, relays, mention, pow, parentEvent, onClearParent, onPublished, onLoginRequired, onError, className, }: CommentEditorProps): import("react/jsx-runtime").JSX.Element;
|
|
14
15
|
export {};
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { useSigner, isLoggedIn } from "./useSigner";
|
|
1
|
+
export { useSigner, isLoggedIn, setExternalSigner } from "./useSigner";
|
|
2
2
|
export { useComments } from "./useComments";
|
|
3
3
|
export type { UseCommentsOptions } from "./useComments";
|
|
4
4
|
export { useProfile } from "./useProfile";
|
|
@@ -2,9 +2,10 @@ import type { NostrEvent } from "nostr-tools";
|
|
|
2
2
|
import type { Comment } from "../types";
|
|
3
3
|
export interface UseCommentsOptions {
|
|
4
4
|
url: string;
|
|
5
|
-
|
|
5
|
+
mention?: string;
|
|
6
6
|
relays?: string[];
|
|
7
7
|
pageSize?: number;
|
|
8
|
+
pow?: number;
|
|
8
9
|
}
|
|
9
10
|
export declare function useComments(options: UseCommentsOptions): {
|
|
10
11
|
comments: Comment[];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TempSigner } from "../signers";
|
|
2
2
|
import type { Signer, SignerInfo } from "../signers/types";
|
|
3
3
|
export declare function isLoggedIn(): boolean;
|
|
4
|
+
export declare function setExternalSigner(signer: Signer): Promise<boolean>;
|
|
4
5
|
export declare function useSigner(): {
|
|
5
6
|
signer: Signer | null;
|
|
6
7
|
signerInfo: SignerInfo | null;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,13 +2,14 @@ export { NostrComments } from "./NostrComments";
|
|
|
2
2
|
export type { NostrCommentsProps, Comment, Profile, Translations, } from "./types";
|
|
3
3
|
export { Nip07Signer, TempSigner, BunkerSigner } from "./signers";
|
|
4
4
|
export type { Signer, SignerType, SignerInfo } from "./signers";
|
|
5
|
-
export { useSigner, useComments, useProfile, isLoggedIn } from "./hooks";
|
|
5
|
+
export { useSigner, useComments, useProfile, isLoggedIn, setExternalSigner } from "./hooks";
|
|
6
6
|
export type { UseCommentsOptions } from "./hooks";
|
|
7
7
|
export { Avatar, Username, CommentItem, CommentList, CommentEditor, LoginModal, } from "./components";
|
|
8
8
|
export { getDefaultRelays, queryEvents, subscribeEvents, publishEvent, } from "./services/nostr";
|
|
9
|
-
export { subscribeComments, fetchComments, publishComment,
|
|
9
|
+
export { subscribeComments, fetchComments, publishComment, buildCommentTree, } from "./services/comment";
|
|
10
10
|
export { subscribeReactions, fetchReactions, publishReaction, countLikes, hasLiked, buildReactionEvent, } from "./services/reaction";
|
|
11
|
-
export { buildWebComment,
|
|
11
|
+
export { buildWebComment, isReply, getParentId, getRootUrl, } from "./utils/nip22";
|
|
12
|
+
export { isValidPubkey } from "./utils/pubkey";
|
|
12
13
|
export { getColorFromPubkey, generateAvatarSvg, getAvatarDataUrl, } from "./utils/avatar";
|
|
13
14
|
export { I18nProvider, useI18n, en, zhCN } from "./i18n";
|
|
14
15
|
import "./styles/base.css";
|