Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

基本设置中增加匿名评论时昵称、电子邮件、网站的输入提示配置,可以修改评论时对应输入框的提示文字 #166

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions packages/comment-widget/src/base-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import {
kindContext,
nameContext,
toastContext,
nicknamePlaceholderContext,
emailPlaceholderContext,
websitePlaceholderContext,
} from './context';
import './emoji-button';
import './icons/icon-loading';
Expand Down Expand Up @@ -60,6 +63,18 @@ export class BaseForm extends LitElement {
@state()
toastManager: ToastManager | undefined;

@consume({ context: nicknamePlaceholderContext, subscribe: true })
@state()
nicknamePlaceholder = '';

@consume({ context: emailPlaceholderContext, subscribe: true })
@state()
emailPlaceholder = '';

@consume({ context: websitePlaceholderContext, subscribe: true })
@state()
websitePlaceholder = '';

textareaRef: Ref<HTMLTextAreaElement> = createRef<HTMLTextAreaElement>();

get customAccount() {
Expand Down Expand Up @@ -182,21 +197,21 @@ export class BaseForm extends LitElement {
name="displayName"
value=${this.customAccount.displayName}
type="text"
placeholder="昵称"
placeholder=${this.nicknamePlaceholder}
required
/>
<input
name="email"
value=${this.customAccount.email}
type="email"
placeholder="电子邮件"
placeholder=${this.emailPlaceholder}
required
/>
<input
name="website"
value=${this.customAccount.website}
type="url"
placeholder="网站"
placeholder=${this.websitePlaceholder}
/>
<a href=${this.loginUrl} rel="nofollow">(或登录账号)</a>
</div>`
Expand Down
15 changes: 15 additions & 0 deletions packages/comment-widget/src/comment-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ import {
useAvatarProviderContext,
versionContext,
withRepliesContext,
nicknamePlaceholderContext,
emailPlaceholderContext,
websitePlaceholderContext,
} from './context';
import { ToastManager } from './lit-toast';
import baseStyles from './styles/base';
Expand Down Expand Up @@ -71,6 +74,18 @@ export class CommentWidget extends LitElement {
@property({ type: Number, attribute: 'with-reply-size' })
withReplySize = 10;

@provide({ context: nicknamePlaceholderContext })
@property({ type: String, attribute: 'nickname-placeholder' })
nicknamePlaceholder = '';

@provide({ context: emailPlaceholderContext })
@property({ type: String, attribute: 'email-placeholder' })
emailPlaceholder = '';

@provide({ context: websitePlaceholderContext })
@property({ type: String, attribute: 'website-placeholder' })
websitePlaceholder = '';

@provide({ context: useAvatarProviderContext })
@property({ type: Boolean, attribute: 'use-avatar-provider' })
useAvatarProvider = false;
Expand Down
3 changes: 3 additions & 0 deletions packages/comment-widget/src/context/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export const useAvatarProviderContext = createContext<boolean>(Symbol('useAvatar
export const avatarProviderContext = createContext<string>(Symbol('avatarProvider'));
export const avatarProviderMirrorContext = createContext<string>(Symbol('avatarProviderMirror'));
export const avatarPolicyContext = createContext<string>(Symbol('avatarPolicy'));
export const nicknamePlaceholderContext = createContext<string>(Symbol('nicknamePlaceholder'));
export const emailPlaceholderContext = createContext<string>(Symbol('emailPlaceholder'));
export const websitePlaceholderContext = createContext<string>(Symbol('websitePlaceholder'));

export const allowAnonymousCommentsContext = createContext<boolean>(
Symbol('allowAnonymousComments')
Expand Down
6 changes: 6 additions & 0 deletions packages/widget/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ interface Props {
avatarProviderMirror?: string;
avatarPolicy?: string;
captchaEnabled: boolean;
nicknamePlaceholder?: string;
emailPlaceholder?: string;
websitePlaceholder?: string;
}

export function init(el: string, props: Props) {
Expand Down Expand Up @@ -44,6 +47,9 @@ export function init(el: string, props: Props) {
commentWidget.avatarProviderMirror = props.avatarProviderMirror || '';
commentWidget.avatarPolicy = props.avatarPolicy || '';
commentWidget.captchaEnabled = props.captchaEnabled || false;
commentWidget.nicknamePlaceholder = props.nicknamePlaceholder || '';
commentWidget.emailPlaceholder = props.emailPlaceholder || '';
commentWidget.websitePlaceholder = props.websitePlaceholder || '';

const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ private String commentHtml(IAttribute groupAttribute, IAttribute kindAttribute,
properties.setProperty("replySize", String.valueOf(basicConfig.getReplySize()));
properties.setProperty("withReplies", String.valueOf(basicConfig.isWithReplies()));
properties.setProperty("withReplySize", String.valueOf(basicConfig.getWithReplySize()));
properties.setProperty("nicknamePlaceholder", String.valueOf(basicConfig.getNicknamePlaceholder()));
properties.setProperty("emailPlaceholder", String.valueOf(basicConfig.getEmailPlaceholder()));
properties.setProperty("websitePlaceholder", String.valueOf(basicConfig.getWebsitePlaceholder()));

var avatarConfig = settingConfigGetter.getAvatarConfig().blockOptional().orElseThrow();
properties.setProperty("useAvatarProvider", String.valueOf(avatarConfig.isEnable()));
Expand Down Expand Up @@ -100,6 +103,9 @@ private String commentHtml(IAttribute groupAttribute, IAttribute kindAttribute,
avatarProviderMirror: "${avatarProviderMirror}",
avatarPolicy: "${avatarPolicy}",
captchaEnabled: ${captchaEnabled},
nicknamePlaceholder: "${nicknamePlaceholder}",
emailPlaceholder: "${emailPlaceholder}",
websitePlaceholder: "${websitePlaceholder}",
}
);
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class BasicConfig {
private int replySize;
private boolean withReplies;
private int withReplySize;
private String nicknamePlaceholder;
private String emailPlaceholder;
private String websitePlaceholder;
}

@Data
Expand Down
24 changes: 24 additions & 0 deletions src/main/resources/extensions/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,30 @@ spec:
key: withReplySize
validation: required
value: 5
- $formkit: text
label: 昵称输入提示
name: nicknamePlaceholder
id: nicknamePlaceholder
key: nicknamePlaceholder
value: "昵称"
help: 匿名评论时昵称输入栏的提示信息
validation: required
- $formkit: text
label: 电子邮件输入提示
name: emailPlaceholder
id: emailPlaceholder
key: emailPlaceholder
value: "电子邮件"
help: 匿名评论时电子邮件输入栏的提示信息
validation: required
- $formkit: text
label: 网站输入提示
name: websitePlaceholder
id: websitePlaceholder
key: websitePlaceholder
value: "网站"
help: 匿名评论时网站输入栏的提示信息
validation: required
- group: security
label: 安全设置
formSchema:
Expand Down