From 60eb89c0fbcdcf8469e2709e7ee58f9f55e51174 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Sat, 9 Aug 2025 13:05:47 +0800 Subject: [PATCH] Add commenter device info display feature --- packages/comment-widget/package.json | 3 +- .../comment-widget/src/base-comment-item.ts | 27 ++++-- packages/comment-widget/src/comment-item.ts | 1 + .../comment-widget/src/commenter-ua-bar.ts | 93 +++++++++++++++++++ packages/comment-widget/src/reply-item.ts | 1 + packages/comment-widget/src/types/index.ts | 1 + packages/example/index.html | 20 ++-- pnpm-lock.yaml | 71 ++++++++++++++ src/main/resources/extensions/settings.yaml | 4 + 9 files changed, 204 insertions(+), 17 deletions(-) create mode 100644 packages/comment-widget/src/commenter-ua-bar.ts diff --git a/packages/comment-widget/package.json b/packages/comment-widget/package.json index 1c4a8ed..612dbf2 100644 --- a/packages/comment-widget/package.json +++ b/packages/comment-widget/package.json @@ -48,7 +48,8 @@ "javascript-time-ago": "^2.5.11", "lit": "^3.3.1", "ofetch": "^1.4.1", - "tiptap-extension-code-block-shiki": "file:lib/tiptap-extension-code-block-shiki-0.5.1.tgz" + "tiptap-extension-code-block-shiki": "file:lib/tiptap-extension-code-block-shiki-0.5.1.tgz", + "ua-parser-js": "^2.0.4" }, "devDependencies": { "@iconify/json": "^2.2.367", diff --git a/packages/comment-widget/src/base-comment-item.ts b/packages/comment-widget/src/base-comment-item.ts index c7f462c..ce45c72 100644 --- a/packages/comment-widget/src/base-comment-item.ts +++ b/packages/comment-widget/src/base-comment-item.ts @@ -1,12 +1,16 @@ import './user-avatar'; import { msg } from '@lit/localize'; import { css, html, LitElement, unsafeCSS } from 'lit'; -import { property } from 'lit/decorators.js'; +import { property, state } from 'lit/decorators.js'; import { unsafeHTML } from 'lit/directives/unsafe-html.js'; import { codeToHtml } from 'shiki/bundle/full'; import baseStyles from './styles/base'; import contentStyles from './styles/content.css?inline'; import { formatDate, timeAgo } from './utils/date'; +import './commenter-ua-bar'; +import { consume } from '@lit/context'; +import { configMapDataContext } from './context'; +import type { ConfigMapData } from './types'; export class BaseCommentItem extends LitElement { @property({ type: String }) @@ -30,6 +34,13 @@ export class BaseCommentItem extends LitElement { @property({ type: String }) content = ''; + @property({ type: String }) + ua: string = ''; + + @consume({ context: configMapDataContext }) + @state() + configMapData: ConfigMapData | undefined; + protected override firstUpdated() { const codeElements = this.shadowRoot?.querySelectorAll('pre>code'); if (!codeElements?.length) return; @@ -81,22 +92,26 @@ export class BaseCommentItem extends LitElement { >
-
+
${ this.userWebsite ? html` ${this.userDisplayName} ` - : html`
${this.userDisplayName}
` + : html`${this.userDisplayName}` } -
+ + ${this.ua && this.configMapData?.basic.showCommenterDevice ? html`` : ''} + +
+ + ${ !this.approved ? html`
${msg('Reviewing')}
` diff --git a/packages/comment-widget/src/comment-item.ts b/packages/comment-widget/src/comment-item.ts index 3938e97..cfdc66a 100644 --- a/packages/comment-widget/src/comment-item.ts +++ b/packages/comment-widget/src/comment-item.ts @@ -119,6 +119,7 @@ export class CommentItem extends LitElement { .creationTime="${this.comment?.spec.creationTime}" .approved=${this.comment?.spec.approved} .userWebsite=${this.comment?.spec.owner.annotations?.website} + .ua=${this.comment?.spec.userAgent} >