Skip to content

Commit ba171ff

Browse files
committed
Merge branch 'main' into feat/hidden
2 parents 1d82a41 + 8e49b63 commit ba171ff

14 files changed

+547
-472
lines changed

biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/2.1.4/schema.json",
2+
"$schema": "https://biomejs.dev/schemas/2.2.0/schema.json",
33
"vcs": {
44
"enabled": true,
55
"clientKind": "git",

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
]
2525
},
2626
"devDependencies": {
27-
"@biomejs/biome": "^2.1.4",
27+
"@biomejs/biome": "^2.2.0",
2828
"@tsconfig/node18": "^18.2.4",
29-
"@types/node": "^18.19.122",
29+
"@types/node": "^18.19.123",
3030
"husky": "^9.1.7",
3131
"lint-staged": "^16.1.5",
3232
"typescript": "~5.3.3",

packages/comment-widget/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838
"@halo-dev/api-client": "https://pkg.pr.new/@halo-dev/api-client@7679",
3939
"@lit/context": "^1.1.6",
4040
"@lit/localize": "^0.12.2",
41-
"@tiptap/core": "^3.1.0",
42-
"@tiptap/extensions": "^3.1.0",
43-
"@tiptap/pm": "^3.1.0",
44-
"@tiptap/starter-kit": "^3.1.0",
41+
"@tiptap/core": "^3.2.0",
42+
"@tiptap/extensions": "^3.2.0",
43+
"@tiptap/pm": "^3.2.0",
44+
"@tiptap/starter-kit": "^3.2.0",
4545
"dayjs": "^1.11.13",
4646
"emoji-mart": "^5.6.0",
4747
"es-toolkit": "^1.39.9",
@@ -53,7 +53,7 @@
5353
"ua-parser-js": "^2.0.4"
5454
},
5555
"devDependencies": {
56-
"@iconify/json": "^2.2.371",
56+
"@iconify/json": "^2.2.373",
5757
"@lit/localize-tools": "^0.8.0",
5858
"@types/sanitize-html": "^2.16.0",
5959
"@unocss/reset": "^66.4.2",

packages/comment-widget/src/base-comment-item.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { consume } from '@lit/context';
99
import { configMapDataContext } from './context';
1010
import type { ConfigMapData } from './types';
1111
import './comment-content';
12+
import { ifDefined } from 'lit/directives/if-defined.js';
13+
import { when } from 'lit/directives/when.js';
1214

1315
export class BaseCommentItem extends LitElement {
1416
@property({ type: String })
@@ -48,25 +50,27 @@ export class BaseCommentItem extends LitElement {
4850
<user-avatar
4951
src="${this.userAvatar || ''}"
5052
alt="${this.userDisplayName || ''}"
51-
href=${this.userWebsite}
53+
href=${ifDefined(this.userWebsite)}
5254
></user-avatar>
5355
</div>
5456
<div class="item-main flex-[1_1_auto] min-w-0 w-full">
5557
<div class="item-meta flex items-center gap-2 flex-wrap">
56-
${
57-
this.userWebsite
58-
? html`<a
58+
${when(
59+
this.userWebsite,
60+
() => html`
61+
<a
5962
class="item-author font-medium text-sm text-text-1 hover:underline"
6063
target="_blank"
61-
href=${this.userWebsite}
64+
href=${ifDefined(this.userWebsite)}
6265
rel="noopener noreferrer"
6366
>
6467
${this.userDisplayName}
65-
</a>`
66-
: html`<span class="item-author font-medium text-sm text-text-1">${this.userDisplayName}</span>`
67-
}
68-
69-
${this.ua && this.configMapData?.basic.showCommenterDevice ? html`<commenter-ua-bar .ua=${this.ua}></commenter-ua-bar>` : ''}
68+
</a>
69+
`,
70+
() => html`
71+
<span class="item-author font-medium text-sm text-text-1">${this.userDisplayName}</span>
72+
`
73+
)}
7074
7175
7276
${
@@ -78,17 +82,14 @@ export class BaseCommentItem extends LitElement {
7882
</div>`
7983
: ''
8084
}
81-
8285
86+
${when(this.ua && this.configMapData?.basic.showCommenterDevice, () => html`<commenter-ua-bar .ua=${this.ua}></commenter-ua-bar>`)}
87+
8388
<time class="item-meta-info text-xs text-text-3" title=${formatDate(this.creationTime)}>
8489
${timeAgo(this.creationTime)}
8590
</time>
8691
87-
${
88-
!this.approved
89-
? html`<div class="item-meta-info text-xs text-text-3">${msg('Reviewing')}</div>`
90-
: ''
91-
}
92+
${when(!this.approved, () => html`<div class="item-meta-info text-xs text-text-3">${msg('Reviewing')}</div>`)}
9293
</div>
9394
9495
<div class="item-content mt-2.5 space-y-2.5"><slot name="pre-content"></slot><comment-content .content=${this.content}></comment-content></div>

packages/comment-widget/src/base-form.ts

Lines changed: 43 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import type { ToastManager } from './lit-toast';
2020
import baseStyles from './styles/base';
2121
import type { ConfigMapData } from './types';
2222
import './comment-editor';
23+
import { when } from 'lit/directives/when.js';
2324
import { ofetch } from 'ofetch';
2425
import type { CommentEditor } from './comment-editor';
2526
import { cleanHtml } from './utils/html';
26-
import './base-tooltip';
2727

2828
export class BaseForm extends LitElement {
2929
@consume({ context: baseUrlContext })
@@ -154,14 +154,11 @@ export class BaseForm extends LitElement {
154154

155155
renderAccountInfo() {
156156
return html`<div class="form-account flex items-center gap-2">
157-
${
158-
this.currentUser?.spec.avatar
159-
? html`
160-
<div class="form-account-avatar avatar">
161-
<img src=${this.currentUser.spec.avatar} class="size-full object-cover" />
162-
</div>`
163-
: ''
164-
}
157+
${when(
158+
this.currentUser?.spec.avatar,
159+
() => html`<div class="form-account-avatar avatar"><img src=${this.currentUser?.spec.avatar || ''} class="size-full object-cover" /></div>
160+
`
161+
)}
165162
<span class="form-account-name text-base text-text-1 font-semibold">
166163
${this.currentUser?.spec.displayName || this.currentUser?.metadata.name}
167164
</span>
@@ -198,9 +195,11 @@ export class BaseForm extends LitElement {
198195
return html`
199196
<form class="form w-full flex flex-col gap-4" @submit="${this.onSubmit}">
200197
<comment-editor ${ref(this.editorRef)} .placeholder=${this.configMapData?.editor?.placeholder}></comment-editor>
201-
${
202-
!this.currentUser && this.allowAnonymousComments
203-
? html`<div class="form-inputs grid grid-cols-1 md:grid-cols-4 gap-2 items-center">
198+
199+
${when(
200+
!this.currentUser && this.allowAnonymousComments,
201+
() => html`
202+
<div class="form-inputs grid grid-cols-1 md:grid-cols-4 gap-2 items-center">
204203
<input
205204
name="displayName"
206205
value=${this.customAccount.displayName}
@@ -225,45 +224,41 @@ export class BaseForm extends LitElement {
225224
class="input"
226225
/>
227226
<a tabindex="-1" href=${this.loginUrl} rel="nofollow" class="form-login-link text-text-3 hover:text-text-1 text-xs transition-all select-none">${msg('(Or login)')}</a>
228-
</div>`
229-
: ''
230-
}
227+
</div>
228+
`
229+
)}
231230
232231
<div class="form__footer">
233232
${this.currentUser ? this.renderAccountInfo() : ''}
234-
${
235-
!this.currentUser && !this.allowAnonymousComments
236-
? html`<button
233+
${when(
234+
!this.currentUser && !this.allowAnonymousComments,
235+
() => html`
236+
<button
237237
@click=${this.handleOpenLoginPage}
238238
class="form-login text-xs text-text-3 hover:text-text-1 px-3 transition-all py-2 rounded-base border border-muted-3 opacity-100 hover:border-muted-4 hover:opacity-70 border-solid"
239239
type="button"
240240
tabindex="-1"
241241
>
242242
${msg('Login')}
243-
</button> `
244-
: ''
245-
}
243+
</button>
244+
`
245+
)}
246246
<div class="form-actions justify-end flex gap-3 flex-wrap items-center">
247-
248-
${
247+
${when(
249248
!this.hidePrivateCheckbox &&
250-
this.configMapData?.basic.enablePrivateComment
251-
? html`
252-
<div class="flex items-center gap-2">
253-
<input id="hidden" name="hidden" type="checkbox" />
254-
<label for="hidden" class="text-xs select-none text-text-3 hover:text-text-1 transition-all">${msg('Private')}</label>
255-
<base-tooltip content=${this.currentUser ? msg('Currently logged in. After selecting the private option, comments will only be visible to yourself and the site administrator.') : msg('You are currently anonymous. After selecting the private option, the comment will only be visible to the site administrator.')}>
256-
<i class="i-mingcute:information-line size-3.5 text-text-3 block"></i>
257-
</base-tooltip>
258-
</div>
259-
`
260-
: ''
261-
}
262-
263-
264-
${
265-
this.showCaptcha && this.captcha
266-
? html`
249+
this.configMapData?.basic.enablePrivateComment,
250+
() => html`<div class="flex items-center gap-2">
251+
<input id="hidden" name="hidden" type="checkbox" />
252+
<label for="hidden" class="text-xs select-none text-text-3 hover:text-text-1 transition-all">${msg('Private')}</label>
253+
<base-tooltip content=${this.currentUser ? msg('Currently logged in. After selecting the private option, comments will only be visible to yourself and the site administrator.') : msg('You are currently anonymous. After selecting the private option, the comment will only be visible to the site administrator.')}>
254+
<i class="i-mingcute:information-line size-3.5 text-text-3 block"></i>
255+
</base-tooltip>
256+
</div>`
257+
)}
258+
259+
${when(
260+
this.showCaptcha && this.captcha,
261+
() => html`
267262
<div class="form-captcha gap-2 flex items-center">
268263
<img
269264
@click=${this.handleFetchCaptcha}
@@ -278,20 +273,20 @@ export class BaseForm extends LitElement {
278273
class="input "
279274
/>
280275
</div>
281-
`
282-
: ''
283-
}
276+
`
277+
)}
284278
285279
<button
286280
.disabled=${this.submitting}
287281
type="submit"
288282
class="form-submit outline-none focus:shadow-input h-12 text-sm inline-flex border border-primary-1 border-solid items-center justify-center gap-2 bg-primary-1 text-white px-3 rounded-base hover:opacity-80 transition-all"
289283
>
290-
${
291-
this.submitting
292-
? html`<icon-loading></icon-loading>`
293-
: html`<i class="i-mingcute-send-line size-5" aria-hidden="true"></i>`
294-
}
284+
${when(
285+
this.submitting,
286+
() => html`<icon-loading></icon-loading>`,
287+
() =>
288+
html`<i class="i-mingcute-send-line size-5" aria-hidden="true"></i>`
289+
)}
295290
${msg('Submit')}
296291
</button>
297292
</div>

packages/comment-widget/src/comment-editor.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import './emoji-button';
77
import contentStyles from './styles/content.css?inline';
88
import './comment-editor-skeleton';
99
import { property } from 'lit/decorators.js';
10+
import { ifDefined } from 'lit/directives/if-defined.js';
11+
import { when } from 'lit/directives/when.js';
1012
import baseStyles from './styles/base';
1113
import { cleanHtml } from './utils/html';
1214

@@ -169,7 +171,8 @@ export class CommentEditor extends LitElement {
169171
}
170172

171173
protected override render() {
172-
return html` ${this.loading ? html`<comment-editor-skeleton></comment-editor-skeleton>` : ''}
174+
return html`
175+
${when(this.loading, () => html`<comment-editor-skeleton></comment-editor-skeleton>`)}
173176
<div
174177
class="border rounded-base border-solid border-muted-1 focus-within:border-primary-1 focus-within:shadow-input transition-all"
175178
?hidden=${this.loading}
@@ -203,8 +206,8 @@ export class CommentEditor extends LitElement {
203206
return html`
204207
<li>
205208
<div
206-
aria-label=${item.displayName?.()}
207-
title=${item.displayName?.()}
209+
aria-label=${ifDefined(item.displayName?.())}
210+
title=${ifDefined(item.displayName?.())}
208211
@click=${() => item.run?.(editor)}
209212
role="button"
210213
class="size-7 hover:bg-muted-3 active:bg-muted-2 ${isActive ? 'bg-muted-3 text-text-1' : 'text-text-3 hover:text-text-1'} rounded-base flex items-center justify-center cursor-pointer transition-all"

packages/comment-widget/src/comment-item.ts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import './base-comment-item';
88
import { consume } from '@lit/context';
99
import { msg } from '@lit/localize';
1010
import { createRef, type Ref, ref } from 'lit/directives/ref.js';
11+
import { when } from 'lit/directives/when.js';
1112
import { ofetch } from 'ofetch';
1213
import { getPolicyInstance } from './avatar/avatar-policy';
1314
import type { CommentReplies } from './comment-replies';
@@ -124,11 +125,13 @@ export class CommentItem extends LitElement {
124125
>
125126
<button slot="action" class="icon-button group -ml-2" type="button" @click="${this.handleUpvote}" aria-label=${msg('Upvote')}>
126127
<div class="icon-button-icon">
127-
${
128-
this.upvoted
129-
? html`<i slot="icon" class="i-mingcute-heart-fill size-4 text-red-500" aria-hidden="true"></i>`
130-
: html`<i slot="icon" class="i-mingcute-heart-line size-4" aria-hidden="true"></i>`
131-
}
128+
${when(
129+
this.upvoted,
130+
() =>
131+
html`<i slot="icon" class="i-mingcute-heart-fill size-4 text-red-500" aria-hidden="true"></i>`,
132+
() =>
133+
html`<i slot="icon" class="i-mingcute-heart-line size-4" aria-hidden="true"></i>`
134+
)}
132135
</div>
133136
<span class="icon-button-text">${`${this.upvoteCount || 0}`}</span>
134137
</button>
@@ -145,38 +148,39 @@ export class CommentItem extends LitElement {
145148
<span class="icon-button-text">${this.comment?.status?.visibleReplyCount || 0}</span>
146149
</button>`
147150
}
148-
${
149-
this.configMapData?.basic.withReplies
150-
? html`
151+
152+
${when(
153+
this.configMapData?.basic.withReplies,
154+
() => html`
151155
<button slot="action" class="icon-button group" type="button" @click="${this.handleToggleReplyForm}" aria-label=${this.showReplyForm ? msg('Cancel reply') : msg('Add reply')}>
152156
<div class="icon-button-icon ">
153157
<i slot="icon" class="i-tabler:message-circle-plus size-4" aria-hidden="true"></i>
154158
</div>
155159
<span class="icon-button-text">${this.showReplyForm ? msg('Cancel reply') : msg('Add reply')}</span>
156-
</button>`
157-
: ''
158-
}
160+
</button>
161+
`
162+
)}
159163
160164
<div slot="footer">
161-
${
162-
this.showReplyForm
163-
? html`<div class="mt-2">
165+
${when(
166+
this.showReplyForm,
167+
() => html`
168+
<div class="mt-2">
164169
<reply-form
165170
@reload=${this.onReplyCreated}
166171
.comment=${this.comment}
167172
></reply-form>
168-
</div>`
169-
: ''
170-
}
171-
${
172-
this.showReplies
173-
? html`<comment-replies
173+
</div>
174+
`
175+
)}
176+
${when(
177+
this.showReplies,
178+
() => html`<comment-replies
174179
${ref(this.commentRepliesRef)}
175180
.comment="${this.comment}"
176181
.showReplyForm=${this.showReplyForm}
177182
></comment-replies>`
178-
: ``
179-
}
183+
)}
180184
</div>
181185
</base-comment-item>`;
182186
}

0 commit comments

Comments
 (0)