Skip to content

Commit bf79827

Browse files
authored
Add configurable editor placeholder to comment widget (#188)
1 parent 8f3c016 commit bf79827

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import { repeat } from 'lit/directives/repeat.js';
66
import './emoji-button';
77
import contentStyles from './styles/content.css?inline';
88
import './comment-editor-skeleton';
9+
import { consume } from '@lit/context';
10+
import { configMapDataContext } from './context';
911
import baseStyles from './styles/base';
12+
import type { ConfigMapData } from './types';
1013

1114
interface ActionItem {
1215
name?: string;
@@ -78,6 +81,10 @@ export class CommentEditor extends LitElement {
7881
@state()
7982
loading = true;
8083

84+
@consume({ context: configMapDataContext })
85+
@state()
86+
configMapData: ConfigMapData | undefined;
87+
8188
protected override firstUpdated(_changedProperties: PropertyValues): void {
8289
super.firstUpdated(_changedProperties);
8390
this.createEditor();
@@ -106,7 +113,8 @@ export class CommentEditor extends LitElement {
106113
}),
107114

108115
Placeholder.configure({
109-
placeholder: msg('Write a comment'),
116+
placeholder:
117+
this.configMapData?.editor?.placeholder || msg('Write a comment'),
110118
}),
111119

112120
CodeBlockShiki.configure({

packages/comment-widget/src/types/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export interface ConfigMapData {
22
basic: BasicConfig;
33
security: SecurityConfig;
44
avatar: AvatarConfig;
5+
editor?: EditorConfig;
56
}
67

78
interface BasicConfig {
@@ -26,3 +27,7 @@ interface AvatarConfig {
2627
providerMirror: string;
2728
policy: 'anonymousUser' | 'allUser' | 'noAvatarUser';
2829
}
30+
31+
interface EditorConfig {
32+
placeholder?: string;
33+
}

src/main/resources/extensions/settings.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,9 @@ spec:
122122
- label: "匿名&无头像用户"
123123
value: "noAvatarUser"
124124
value: "anonymousUser"
125+
- group: editor
126+
label: 编辑器
127+
formSchema:
128+
- $formkit: text
129+
name: placeholder
130+
label: 自定义评论框占位符

0 commit comments

Comments
 (0)