@ziteh/yangchun-comment-client 0.1.0 → 0.2.0-alpha.1

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.
Files changed (50) hide show
  1. package/README.md +6 -0
  2. package/dist/src/api/apiService.d.ts +22 -0
  3. package/dist/src/api/globalApiService.d.ts +10 -0
  4. package/dist/src/components/comment-admin.d.ts +25 -0
  5. package/dist/src/components/comment-dialog.d.ts +18 -0
  6. package/dist/src/components/comment-info.d.ts +14 -0
  7. package/dist/src/components/comment-input.d.ts +31 -0
  8. package/dist/src/components/list/comment-list-item.d.ts +19 -0
  9. package/dist/src/components/list/comment-list.d.ts +9 -0
  10. package/dist/src/components/yangchun-comment.d.ts +58 -0
  11. package/dist/src/components/yangchun-comment.styles.d.ts +2 -0
  12. package/dist/src/index.d.ts +1 -0
  13. package/dist/src/utils/comment.d.ts +6 -0
  14. package/dist/src/utils/format.d.ts +2 -0
  15. package/dist/src/utils/i18n.d.ts +46 -0
  16. package/dist/src/utils/pow.d.ts +9 -0
  17. package/dist/{utils → src/utils}/pseudonym.d.ts +0 -1
  18. package/dist/src/utils/sanitize.d.ts +1 -0
  19. package/dist/test/sanitize.test.d.ts +1 -0
  20. package/dist/yangchun-comment.js +962 -0
  21. package/dist/yangchun-comment.js.map +1 -0
  22. package/dist/yangchun-comment.umd.cjs +962 -0
  23. package/dist/yangchun-comment.umd.cjs.map +1 -0
  24. package/package.json +17 -13
  25. package/dist/element.d.ts +0 -97
  26. package/dist/element.js +0 -680
  27. package/dist/index.d.ts +0 -9
  28. package/dist/index.js +0 -23
  29. package/dist/types.d.ts +0 -3
  30. package/dist/utils/apiService.d.ts +0 -15
  31. package/dist/utils/apiService.js +0 -118
  32. package/dist/utils/format.d.ts +0 -1
  33. package/dist/utils/format.js +0 -14
  34. package/dist/utils/i18n.d.ts +0 -51
  35. package/dist/utils/i18n.js +0 -98
  36. package/dist/utils/pseudonym.js +0 -34
  37. package/dist/utils/sanitize.d.ts +0 -4
  38. package/dist/utils/sanitize.js +0 -59
  39. package/dist/utils/wordBank.js +0 -692
  40. package/dist/views/comments.d.ts +0 -3
  41. package/dist/views/comments.js +0 -119
  42. package/dist/views/preview.d.ts +0 -3
  43. package/dist/views/preview.js +0 -53
  44. package/dist/yangchun-comment.css +0 -1
  45. package/dist/yangchun-comment.es.js +0 -317
  46. package/dist/yangchun-comment.es.js.map +0 -1
  47. package/dist/yangchun-comment.umd.js +0 -317
  48. package/dist/yangchun-comment.umd.js.map +0 -1
  49. /package/dist/{types.js → src/utils/pow.worker.d.ts} +0 -0
  50. /package/dist/{utils → src/utils}/wordBank.d.ts +0 -0
package/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # Yang Chun Comment Client
2
+
3
+ Frontend Web Component for Yang Chun Comment — a simple, lightweight, privacy-first commenting system.
4
+
5
+ - [Docs](https://ycc.ziteh.dev/)
6
+ - [GitHub](https://github.com/ziteh/yangchun-comment)
@@ -0,0 +1,22 @@
1
+ import { type GetCommentsResponse, type AdminLoginResponse } from '@ziteh/yangchun-comment-shared';
2
+ export interface AuthInfo {
3
+ timestamp: number;
4
+ token: string;
5
+ }
6
+ export interface CommentAuthInfo {
7
+ id: string;
8
+ timestamp: number;
9
+ token: string;
10
+ }
11
+ export interface ApiService {
12
+ getComments: (post: string) => Promise<GetCommentsResponse>;
13
+ addComment: (post: string, pseudonym: string, msg: string, replyTo?: string) => Promise<string | null>;
14
+ updateComment: (post: string, commentId: string, pseudonym: string, msg: string) => Promise<boolean>;
15
+ deleteComment: (post: string, commentId: string) => Promise<boolean>;
16
+ canEditComment: (commentId: string) => boolean;
17
+ isMyComment: (commentId: string) => boolean;
18
+ adminLogin: (username: string, password: string) => Promise<AdminLoginResponse | null>;
19
+ adminLogout: () => Promise<boolean>;
20
+ checkAdminAuth: () => Promise<boolean>;
21
+ }
22
+ export declare const createApiService: (apiUrl: string, prePowDifficulty: number, prePowSalt: string) => ApiService;
@@ -0,0 +1,10 @@
1
+ import type { ApiService } from './apiService';
2
+ declare class GlobalApiService {
3
+ private instance;
4
+ setInstance(service: ApiService): void;
5
+ getInstance(): ApiService;
6
+ isInitialized(): boolean;
7
+ clear(): void;
8
+ }
9
+ export declare const globalApiService: GlobalApiService;
10
+ export {};
@@ -0,0 +1,25 @@
1
+ import { LitElement } from 'lit';
2
+ export declare class CommentAdmin extends LitElement {
3
+ static styles: import("lit").CSSResult[];
4
+ private accessor username;
5
+ private accessor password;
6
+ private accessor errorMessage;
7
+ private accessor successMessage;
8
+ private accessor isLoading;
9
+ private accessor isLoggedIn;
10
+ private accessor isCheckingAuth;
11
+ private accessor hasCheckedAuthFromComments;
12
+ render(): import("lit").TemplateResult<1>;
13
+ connectedCallback(): Promise<void>;
14
+ disconnectedCallback(): void;
15
+ updateAuthStatus(isAdmin: boolean): void;
16
+ private handleAdminStatusUpdated;
17
+ private renderLoginForm;
18
+ private renderAdminPanel;
19
+ private handleSubmit;
20
+ private checkAuthStatus;
21
+ private handleLogout;
22
+ private handleUsernameChange;
23
+ private handlePasswordChange;
24
+ private handleAuthStatusChange;
25
+ }
@@ -0,0 +1,18 @@
1
+ import { LitElement, type PropertyValues } from 'lit';
2
+ export declare class CommentDialog extends LitElement {
3
+ static styles: import("lit").CSSResult[];
4
+ accessor open: boolean;
5
+ accessor header: string;
6
+ private accessor dialogElement;
7
+ private accessor closeButton;
8
+ private previousFocus;
9
+ render(): import("lit").TemplateResult<1> | null;
10
+ protected updated(changedProperties: PropertyValues): void;
11
+ disconnectedCallback(): void;
12
+ private addEventListeners;
13
+ private removeEventListeners;
14
+ private handleKeyDown;
15
+ private trapFocus;
16
+ private handleClose;
17
+ private handleOverlayClick;
18
+ }
@@ -0,0 +1,14 @@
1
+ import { LitElement } from 'lit';
2
+ import type { Comment } from '@ziteh/yangchun-comment-shared';
3
+ export declare class CommentInfo extends LitElement {
4
+ static styles: import("lit").CSSResult[];
5
+ accessor comment: Comment | null;
6
+ accessor isReply: boolean;
7
+ accessor errorMessage: string;
8
+ render(): import("lit").TemplateResult<1>;
9
+ private handleAdmin;
10
+ private handleHelp;
11
+ private handleNotify;
12
+ private handleErrorClear;
13
+ private handleCancel;
14
+ }
@@ -0,0 +1,31 @@
1
+ import { LitElement } from 'lit';
2
+ import './list/comment-list-item';
3
+ export declare class CommentInput extends LitElement {
4
+ static shadowRootOptions: {
5
+ delegatesFocus: boolean;
6
+ clonable?: boolean;
7
+ customElementRegistry?: CustomElementRegistry;
8
+ mode: ShadowRootMode;
9
+ serializable?: boolean;
10
+ slotAssignment?: SlotAssignmentMode;
11
+ };
12
+ static styles: import("lit").CSSResult[];
13
+ static readonly MAX_NICKNAME_LENGTH: number;
14
+ static readonly MAX_MESSAGE_LENGTH: number;
15
+ accessor draft: string;
16
+ accessor nickname: string;
17
+ accessor editPseudonym: string;
18
+ accessor adminName: string;
19
+ accessor isAdmin: boolean;
20
+ private accessor isPreview;
21
+ private accessor previewComment;
22
+ private accessor honeypot;
23
+ render(): import("lit").TemplateResult<1>;
24
+ private createPreviewComment;
25
+ private isValidComment;
26
+ private handleTogglePreview;
27
+ private handleDraftInput;
28
+ private handleNicknameInput;
29
+ private handleHoneypotInput;
30
+ private handleSubmit;
31
+ }
@@ -0,0 +1,19 @@
1
+ import { LitElement } from 'lit';
2
+ import type { Comment } from '@ziteh/yangchun-comment-shared';
3
+ export declare class CommentListItem extends LitElement {
4
+ static styles: import("lit").CSSResult[];
5
+ accessor comment: Comment;
6
+ accessor replyComments: Comment[];
7
+ accessor author: string;
8
+ private isContentExpanded;
9
+ private readonly MAX_LINES;
10
+ render(): import("lit").TemplateResult<1>;
11
+ private isPreviewComment;
12
+ private handleDelete;
13
+ private handleEdit;
14
+ private handleReply;
15
+ private handleContentClick;
16
+ private renderMarkdown;
17
+ private shouldShowExpandBtn;
18
+ private handleToggleExpand;
19
+ }
@@ -0,0 +1,9 @@
1
+ import { LitElement } from 'lit';
2
+ import type { Comment } from '@ziteh/yangchun-comment-shared';
3
+ import './comment-list-item';
4
+ export declare class CommentList extends LitElement {
5
+ static styles: import("lit").CSSResult[];
6
+ accessor comments: Comment[];
7
+ accessor author: string;
8
+ render(): import("lit").TemplateResult<1>;
9
+ }
@@ -0,0 +1,58 @@
1
+ import { LitElement, type PropertyValues } from 'lit';
2
+ import './comment-input';
3
+ import './comment-info';
4
+ import './comment-dialog';
5
+ import './list/comment-list';
6
+ import './comment-admin';
7
+ import { type I18nStrings } from '../utils/i18n';
8
+ export declare class YangChunComment extends LitElement {
9
+ static styles: import("lit").CSSResult[];
10
+ accessor post: string;
11
+ accessor apiUrl: string;
12
+ accessor adminName: string;
13
+ accessor lang: string;
14
+ accessor prePowSalt: string;
15
+ accessor prePowDifficulty: number;
16
+ accessor customMessages: I18nStrings | undefined;
17
+ private accessor draft;
18
+ private accessor nickname;
19
+ private accessor comments;
20
+ private accessor editPseudonym;
21
+ private accessor deleteCommentId;
22
+ private accessor referenceComment;
23
+ private accessor isReply;
24
+ private accessor showAdmin;
25
+ private accessor showHelp;
26
+ private accessor showNotify;
27
+ private accessor showExternalLink;
28
+ private accessor externalLinkUrl;
29
+ private accessor isAdmin;
30
+ private accessor rssFeedUrl;
31
+ private accessor errorMessage;
32
+ private accessor commentInput;
33
+ private accessor commentAdmin;
34
+ render(): import("lit").TemplateResult<1>;
35
+ protected willUpdate(changedProperties: PropertyValues<this>): void;
36
+ protected updated(changedProperties: PropertyValues<this>): void;
37
+ firstUpdated(): Promise<void>;
38
+ disconnectedCallback(): void;
39
+ private updatedComments;
40
+ private handleRefCommentCancel;
41
+ private handleDraftChange;
42
+ private handleNicknameChange;
43
+ private editedSubmit;
44
+ private handleCommentSubmit;
45
+ private handleCommentReply;
46
+ private handleCommentDelete;
47
+ private handleCommentEdit;
48
+ private handleAuthStatusChange;
49
+ private handleDeleteComment;
50
+ private handleExternalLinkClick;
51
+ private handleOpenLink;
52
+ private handleCopyLink;
53
+ }
54
+ declare global {
55
+ interface HTMLElementTagNameMap {
56
+ 'yangchun-comment': YangChunComment;
57
+ }
58
+ }
@@ -0,0 +1,2 @@
1
+ export declare const yangChunCommentVars: import("lit").CSSResult;
2
+ export declare const yangChunCommentStyles: import("lit").CSSResult;
@@ -0,0 +1 @@
1
+ export { YangChunComment } from './components/yangchun-comment';
@@ -0,0 +1,6 @@
1
+ import type { Comment } from '@ziteh/yangchun-comment-shared';
2
+ export declare function sortCommentsByDate(comments: Comment[], newFirst: boolean): Comment[];
3
+ export declare function filterRootComments(comments: Comment[]): Comment[];
4
+ export declare function filterReplyComments(comments: Comment[], replyToId: string): Comment[];
5
+ export declare function findRootComment(comments: Comment[], commentId: string): Comment | undefined;
6
+ export declare function findReplyComments(comments: Comment[], rootCommentId: string): Comment[];
@@ -0,0 +1,2 @@
1
+ export declare function formatAbsoluteDate(timestamp: number): string;
2
+ export declare function formatRelativeDate(timestamp: number, locales?: string): string;
@@ -0,0 +1,46 @@
1
+ export interface I18nStrings {
2
+ bcp47: string;
3
+ anonymous: string;
4
+ submit: string;
5
+ preview: string;
6
+ edit: string;
7
+ edited: string;
8
+ editing: string;
9
+ delete: string;
10
+ reply: string;
11
+ replyTo: string;
12
+ replyingTo: string;
13
+ notify: string;
14
+ help: string;
15
+ cancel: string;
16
+ close: string;
17
+ author: string;
18
+ me: string;
19
+ messagePlaceholder: string;
20
+ nicknamePlaceholder: string;
21
+ confirmDelete: string;
22
+ confirmDeleteDesc1: string;
23
+ confirmDeleteDesc2: string;
24
+ helpDesc: string;
25
+ helpMdLink: string;
26
+ helpMdImage: string;
27
+ helpMdItalic: string;
28
+ helpMdBold: string;
29
+ helpMdList: string;
30
+ helpMdOrderedList: string;
31
+ helpMdInlineCode: string;
32
+ helpMdCodeBlock: string;
33
+ helpMdNoHtml: string;
34
+ notifyDesc: string;
35
+ noComments: string;
36
+ showMore: string;
37
+ showLess: string;
38
+ externalLinkWarning: string;
39
+ externalLinkDesc: string;
40
+ openLink: string;
41
+ copyLink: string;
42
+ }
43
+ export declare const enUS: I18nStrings;
44
+ export declare const zhTW: I18nStrings;
45
+ export declare function t(key: keyof I18nStrings): string;
46
+ export declare function initI18n(lang: I18nStrings): void;
@@ -0,0 +1,9 @@
1
+ export declare function solvePrePow(difficulty: number, payload: string): Promise<{
2
+ challenge: string;
3
+ nonce: number;
4
+ }>;
5
+ export declare function solveFormalPow(difficulty: number, challenge: string, post: string): Promise<number>;
6
+ export declare function genFormalPowChallenge(difficulty: number): Promise<string>;
7
+ export declare function verifyPrePow(difficulty: number, challenge: string, nonce: number): Promise<boolean>;
8
+ export declare function verifyFormalPow(challenge: string, post: string, nonce: number): Promise<boolean>;
9
+ export declare function cleanupPowWorker(): void;
@@ -1,4 +1,3 @@
1
- export declare function generateSHA256Hash(text: string): Promise<string>;
2
1
  export declare function generatePseudonymAndHash(originalName: string | null | undefined): Promise<{
3
2
  pseudonym: string;
4
3
  hash: string;
@@ -0,0 +1 @@
1
+ export declare function sanitizeHtml(dirtyHtml: string): string;
@@ -0,0 +1 @@
1
+ export {};