dsh-thinking-lang 1.0.5 → 1.0.7
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.
- package/DEVELOPMENT.md +156 -0
- package/README.md +26 -178
- package/assets/plugin-config.png +0 -0
- package/assets/settings-general.png +0 -0
- package/client/client.js +231 -51
- package/client/client.raw.cjs +231 -51
- package/lib/core.d.ts +25 -4
- package/lib/core.js +43 -6
- package/lib/index.js +21 -13
- package/package.json +3 -1
- package/src/client/index.ts +32 -1
- package/src/client/locales.ts +37 -61
- package/src/client/panel.ts +232 -72
- package/src/core.ts +53 -6
- package/src/index.ts +23 -13
package/src/client/index.ts
CHANGED
|
@@ -10,11 +10,14 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { SETTINGS_NAMESPACE } from "../core.js";
|
|
12
12
|
import { dictionaries, type Dict } from "./locales.js";
|
|
13
|
-
import { createRow, mountRowStyles, type SettingsDoc, type UiPrimitives } from "./panel.js";
|
|
13
|
+
import { createConfigCard, createRow, mountRowStyles, type SettingsDoc, type UiPrimitives } from "./panel.js";
|
|
14
14
|
|
|
15
15
|
/** Stable Cordis plugin name. / 稳定的 Cordis 插件名。 */
|
|
16
16
|
export const name = "ay-dsh-tk-lang";
|
|
17
17
|
|
|
18
|
+
/** Package name; the key Plugins page uses to find a bundle's configuration page. / 包名;插件页用它查找某个 bundle 的配置页。 */
|
|
19
|
+
const PACKAGE_NAME = "dsh-thinking-lang";
|
|
20
|
+
|
|
18
21
|
/** The one client service this plugin requires. / 本插件唯一需要的客户端服务。 */
|
|
19
22
|
export const inject = ["slots"];
|
|
20
23
|
|
|
@@ -36,6 +39,8 @@ declare const require: (specifier: string) => unknown;
|
|
|
36
39
|
/** The slice of the config-forms service used to reach the settings document. / 用于取得设置文档的 config-forms 服务切片。 */
|
|
37
40
|
interface ConfigFormsService {
|
|
38
41
|
get(ns: string): SettingsDoc;
|
|
42
|
+
/** Run `callback` while the namespace is served; returns its disposer. / 命名空间处于服务状态时执行回调,返回其回收函数。 */
|
|
43
|
+
whileServed?(namespaces: string[], callback: () => unknown): () => void;
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
/** The slice of the locale service used for row copy. / 用于行文案的 locale 服务切片。 */
|
|
@@ -126,5 +131,31 @@ export function apply(ctx: UiContext): void {
|
|
|
126
131
|
Row
|
|
127
132
|
);
|
|
128
133
|
});
|
|
134
|
+
|
|
135
|
+
// The Plugins page renders a bundle's configuration through this slot,
|
|
136
|
+
// keyed by the package name. / 插件页按包名通过该插槽渲染 bundle 的配置页。
|
|
137
|
+
const whileServed = typeof forms.whileServed === "function" ? forms.whileServed.bind(forms) : undefined;
|
|
138
|
+
if (whileServed === undefined) {
|
|
139
|
+
report(uiCtx, "configForms.whileServed unavailable; plugin configuration page disabled");
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const Card = createConfigCard(primitives);
|
|
143
|
+
uiCtx.effect(
|
|
144
|
+
() =>
|
|
145
|
+
whileServed([SETTINGS_NAMESPACE], () =>
|
|
146
|
+
uiCtx.slots.inject("plugins.bundle.config", () =>
|
|
147
|
+
uiCtx.slots.register(
|
|
148
|
+
{
|
|
149
|
+
name: "plugins.bundle.config",
|
|
150
|
+
key: PACKAGE_NAME,
|
|
151
|
+
locale: LOCALE_NS,
|
|
152
|
+
inject: () => ({ doc, t })
|
|
153
|
+
},
|
|
154
|
+
Card
|
|
155
|
+
)
|
|
156
|
+
)
|
|
157
|
+
),
|
|
158
|
+
"dsh-thinking-lang: plugin configuration page"
|
|
159
|
+
);
|
|
129
160
|
});
|
|
130
161
|
}
|
package/src/client/locales.ts
CHANGED
|
@@ -1,44 +1,48 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Settings
|
|
3
|
-
*
|
|
2
|
+
* Settings copy for the General row and the plugin's configuration card.
|
|
3
|
+
* 「通用」设置行与插件配置卡片使用的文案。
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* - {@link dictionaries} is keyed by UI locale and handed to the host locale
|
|
10
|
-
* service. The host resolves it against the *interface* language.
|
|
11
|
-
* - {@link DICTIONARIES} is keyed by thinking-language tag and read by the row
|
|
12
|
-
* itself, so the copy can follow the *thinking* language instead.
|
|
13
|
-
*
|
|
14
|
-
* - {@link dictionaries} 以界面语言为键,交给宿主的 locale 服务,由宿主按
|
|
15
|
-
* **界面语言**解析。
|
|
16
|
-
* - {@link DICTIONARIES} 以思考语言标签为键,由设置行自己读取,使文案可以跟随
|
|
17
|
-
* **思考语言**。
|
|
5
|
+
* The host resolves {@link dictionaries} against the interface language; the
|
|
6
|
+
* settings card renders its own controls from the same keys.
|
|
7
|
+
* 宿主按界面语言解析 {@link dictionaries};配置卡片用同一批键渲染自己的控件。
|
|
18
8
|
*/
|
|
19
9
|
|
|
20
|
-
/** One dictionary of settings
|
|
10
|
+
/** One dictionary of settings copy. / 一份设置文案字典。 */
|
|
21
11
|
export interface Dict {
|
|
22
12
|
/** Row heading. / 行标题。 */
|
|
23
13
|
heading: string;
|
|
24
|
-
/** Row description
|
|
14
|
+
/** Row description. / 行说明。 */
|
|
25
15
|
description: string;
|
|
26
16
|
/** Label of the "follow the host locale" option. / 「跟随宿主语言」选项的标签。 */
|
|
27
17
|
autoLabel: string;
|
|
18
|
+
/** Reminder row heading. / 提醒行标题。 */
|
|
19
|
+
reminderHeading: string;
|
|
20
|
+
/** Reminder row description. / 提醒行说明。 */
|
|
21
|
+
reminderDescription: string;
|
|
22
|
+
/** Label of the "disabled" reminder option. / 关闭提醒的选项标签。 */
|
|
23
|
+
reminderOff: string;
|
|
24
|
+
/** Label of the "every turn" reminder option. / 每轮提醒的选项标签。 */
|
|
25
|
+
reminderTurn: string;
|
|
26
|
+
/** Label of the custom interval option. / 自定义间隔的选项标签。 */
|
|
27
|
+
reminderCustom: string;
|
|
28
|
+
/** Suffix for a preset interval. / 预设间隔的单位后缀。 */
|
|
29
|
+
reminderUnit: string;
|
|
30
|
+
/** Hint under the custom interval input. / 自定义间隔输入框的提示。 */
|
|
31
|
+
reminderCustomHint: string;
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
/** Simplified Chinese copy. / 简体中文文案。 */
|
|
31
35
|
export const zh: Dict = {
|
|
32
36
|
heading: "思考语言",
|
|
33
37
|
description: "内部推理与规划使用的语言。「自动」优先跟随操作系统语言,其次是界面语言。",
|
|
34
|
-
autoLabel: "自动"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
autoLabel: "自动",
|
|
39
|
+
reminderHeading: "提醒间隔",
|
|
40
|
+
reminderDescription: "两次提醒之间的最小间隔;关闭后只保留系统提示里的规则。",
|
|
41
|
+
reminderOff: "关闭",
|
|
42
|
+
reminderTurn: "每轮",
|
|
43
|
+
reminderCustom: "自定义",
|
|
44
|
+
reminderUnit: "分钟",
|
|
45
|
+
reminderCustomHint: "1–1440 分钟"
|
|
42
46
|
};
|
|
43
47
|
|
|
44
48
|
/** English copy. / 英文文案。 */
|
|
@@ -46,43 +50,15 @@ export const en: Dict = {
|
|
|
46
50
|
heading: "Thinking language",
|
|
47
51
|
description:
|
|
48
52
|
"Language used for internal reasoning and planning. Automatic follows the operating-system language first, then the UI language.",
|
|
49
|
-
autoLabel: "Automatic"
|
|
53
|
+
autoLabel: "Automatic",
|
|
54
|
+
reminderHeading: "Reminder interval",
|
|
55
|
+
reminderDescription: "Minimum gap between reminders. Off keeps only the system-prompt rule.",
|
|
56
|
+
reminderOff: "Off",
|
|
57
|
+
reminderTurn: "Every turn",
|
|
58
|
+
reminderCustom: "Custom",
|
|
59
|
+
reminderUnit: "min",
|
|
60
|
+
reminderCustomHint: "1–1440 minutes"
|
|
50
61
|
};
|
|
51
62
|
|
|
52
|
-
/**
|
|
53
|
-
* Whether the row copy follows the thinking language instead of the UI language.
|
|
54
|
-
* 行文案是否跟随思考语言,而不是界面语言。
|
|
55
|
-
*
|
|
56
|
-
* Reserved and currently OFF: the whole mechanism is implemented and wired up,
|
|
57
|
-
* but this stays `false` so the row keeps following the interface language.
|
|
58
|
-
* Flip it to `true` to switch the behaviour on — no other file needs to change.
|
|
59
|
-
* 预留中,当前关闭:整套机制已实现并接线完毕,但此处保持 `false`,使设置行继续
|
|
60
|
-
* 跟随界面语言。改为 `true` 即可启用,无需改动任何其它文件。
|
|
61
|
-
*/
|
|
62
|
-
export const COPY_FOLLOWS_THINKING_LANGUAGE = false;
|
|
63
|
-
|
|
64
|
-
/** Dictionaries keyed by thinking-language tag, read by the row. / 以思考语言标签为键、由设置行读取的字典。 */
|
|
65
|
-
const DICTIONARIES: Record<string, Dict> = {
|
|
66
|
-
"zh-CN": zh,
|
|
67
|
-
"zh-TW": zhTW,
|
|
68
|
-
en
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Pick the dictionary the row should use, honouring the feature flag.
|
|
73
|
-
* 依据功能开关,挑选设置行应当使用的字典。
|
|
74
|
-
*
|
|
75
|
-
* Returns `undefined` whenever the host dictionary should win: the flag is off,
|
|
76
|
-
* or the language is `auto` and is therefore resolved by the host against the
|
|
77
|
-
* interface language.
|
|
78
|
-
* 返回 `undefined` 表示应当采用宿主字典:开关关闭,或语言为 `auto`(此时由宿主按
|
|
79
|
-
* 界面语言解析)。
|
|
80
|
-
*/
|
|
81
|
-
export function dictionaryFor(language: string, autoValue: string): Dict | undefined {
|
|
82
|
-
if (!COPY_FOLLOWS_THINKING_LANGUAGE) return undefined;
|
|
83
|
-
if (language === autoValue) return undefined;
|
|
84
|
-
return DICTIONARIES[language];
|
|
85
|
-
}
|
|
86
|
-
|
|
87
63
|
/** Dictionaries keyed by UI locale, handed to the host locale service. / 以界面语言为键、交给宿主 locale 服务的字典。 */
|
|
88
64
|
export const dictionaries: Record<string, Dict> = { zh, en };
|
package/src/client/panel.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Settings UI: the General row and the plugin's configuration card.
|
|
3
|
+
* 设置界面:「通用」页的设置行,以及插件详情页的配置卡片。
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* 语言设置项下方。
|
|
5
|
+
* Both surfaces bind to the same host settings document, so a change in either
|
|
6
|
+
* place is visible in the other. / 两个入口绑定同一份宿主设置文档,任一处修改
|
|
7
|
+
* 另一处都会看到。
|
|
9
8
|
*
|
|
10
|
-
* The row owns no state of its own: it reads the
|
|
11
|
-
*
|
|
12
|
-
* 本行不持有自己的状态:它读取宿主的设置文档、订阅其变化,并回写那唯一一个字段。
|
|
9
|
+
* The row owns no state of its own: it reads the document, subscribes to it, and
|
|
10
|
+
* writes the fields back. / 控件不持有自己的状态:读取文档、订阅变化、回写字段。
|
|
13
11
|
*/
|
|
14
12
|
import { createElement as h, useEffect, useState } from "react";
|
|
15
13
|
import {
|
|
@@ -17,11 +15,15 @@ import {
|
|
|
17
15
|
CATALOGUE,
|
|
18
16
|
DEFAULTS,
|
|
19
17
|
FIELD_LANGUAGE,
|
|
18
|
+
FIELD_REMINDER,
|
|
19
|
+
MAX_REMINDER_MINUTES,
|
|
20
|
+
REMINDER_EVERY_TURN,
|
|
21
|
+
REMINDER_OFF,
|
|
20
22
|
type ThinkingSettings,
|
|
21
23
|
nativeNameFor,
|
|
22
24
|
normalizeSettings
|
|
23
25
|
} from "../core.js";
|
|
24
|
-
import {
|
|
26
|
+
import type { Dict } from "./locales.js";
|
|
25
27
|
|
|
26
28
|
/** The settings document handle the host hands to a client plugin. / 宿主交给客户端插件的设置文档句柄。 */
|
|
27
29
|
export interface SettingsDoc {
|
|
@@ -31,7 +33,7 @@ export interface SettingsDoc {
|
|
|
31
33
|
unset(field: string): unknown;
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
/** UI primitives this
|
|
36
|
+
/** UI primitives this plugin can use when the host provides them. / 宿主提供时本插件可用的 UI 原语。 */
|
|
35
37
|
export interface UiPrimitives {
|
|
36
38
|
Menu?: unknown;
|
|
37
39
|
IconChevronDownOutlineRegular?: unknown;
|
|
@@ -39,14 +41,17 @@ export interface UiPrimitives {
|
|
|
39
41
|
[key: string]: unknown;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
|
-
/** What
|
|
43
|
-
interface
|
|
44
|
+
/** What both surfaces receive from their slot. / 两个界面从插槽收到的内容。 */
|
|
45
|
+
interface Binding {
|
|
44
46
|
/** Live settings document for the plugin namespace. / 插件命名空间的实时设置文档。 */
|
|
45
47
|
doc: SettingsDoc;
|
|
46
|
-
/** Bound translator for the host locale namespace
|
|
48
|
+
/** Bound translator for the host locale namespace. / 绑定到宿主 locale 命名空间的翻译函数。 */
|
|
47
49
|
t: (key: keyof Dict) => string;
|
|
48
50
|
}
|
|
49
51
|
|
|
52
|
+
/** Preset reminder intervals in minutes. / 预设提醒间隔(分钟)。 */
|
|
53
|
+
const PRESET_MINUTES = [10, 30, 60] as const;
|
|
54
|
+
|
|
50
55
|
/**
|
|
51
56
|
* Read and normalize the current settings, falling back to defaults on refusal.
|
|
52
57
|
* 读取并归一化当前设置;被拒绝时回退到默认值。
|
|
@@ -60,12 +65,8 @@ function readSettings(doc: SettingsDoc): ThinkingSettings {
|
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
/**
|
|
63
|
-
* Write one field back, swallowing a refusal so a read-only host cannot break the
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* A host may return a promise instead of a value; an unhandled rejection from a
|
|
67
|
-
* read-only document is not worth surfacing, so it is discarded here.
|
|
68
|
-
* 宿主可能返回 promise 而不是值;只读文档产生的未处理拒绝不值得上抛,因此在此丢弃。
|
|
68
|
+
* Write one field back, swallowing a refusal so a read-only host cannot break the UI.
|
|
69
|
+
* 回写单个字段,并吞掉拒绝异常,使只读宿主不会让控件崩溃。
|
|
69
70
|
*/
|
|
70
71
|
function writeField(doc: SettingsDoc, field: string, value: unknown): void {
|
|
71
72
|
try {
|
|
@@ -78,53 +79,42 @@ function writeField(doc: SettingsDoc, field: string, value: unknown): void {
|
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
|
|
82
|
+
/** Subscribe one component to the document and re-read it on every revision. / 订阅设置文档,并在每次修订时重新读取。 */
|
|
83
|
+
function useSettings(doc: SettingsDoc): ThinkingSettings {
|
|
84
|
+
const [settings, setSettings] = useState<ThinkingSettings>(() => readSettings(doc));
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
const sync = (): void => setSettings(readSettings(doc));
|
|
87
|
+
sync();
|
|
88
|
+
return doc.subscribe(sync);
|
|
89
|
+
}, [doc]);
|
|
90
|
+
return settings;
|
|
91
|
+
}
|
|
92
|
+
|
|
81
93
|
/**
|
|
82
|
-
* Build the
|
|
83
|
-
* 构建绑定到宿主 UI
|
|
94
|
+
* Build the language picker bound to the host's UI primitives.
|
|
95
|
+
* 构建绑定到宿主 UI 原语的语言选择器。
|
|
84
96
|
*/
|
|
85
|
-
|
|
97
|
+
function createLanguagePicker(primitives: UiPrimitives | undefined) {
|
|
86
98
|
const Menu = primitives?.Menu;
|
|
87
99
|
const Chevron =
|
|
88
100
|
primitives?.IconChevronDownOutlineRegular ??
|
|
89
101
|
primitives?.IconChevronDownOutline14 ??
|
|
90
102
|
primitives?.IconChevronDownOutlineMedium;
|
|
91
103
|
|
|
92
|
-
return function
|
|
93
|
-
const { doc, t
|
|
94
|
-
const [settings, setSettings] = useState<ThinkingSettings>(() => readSettings(doc));
|
|
104
|
+
return function LanguagePicker(props: Binding & { settings: ThinkingSettings }): unknown {
|
|
105
|
+
const { doc, t, settings } = props;
|
|
95
106
|
const [open, setOpen] = useState<boolean>(false);
|
|
96
|
-
|
|
97
|
-
// Copy follows the THINKING language only while the feature flag is on;
|
|
98
|
-
// otherwise the host dictionary — resolved against the interface language —
|
|
99
|
-
// is used throughout. `auto` always defers to the host.
|
|
100
|
-
// 只有功能开关打开时,文案才跟随**思考语言**;否则一律使用宿主字典(按界面
|
|
101
|
-
// 语言解析)。`auto` 始终交给宿主。
|
|
102
|
-
const dict = dictionaryFor(settings.language, AUTO);
|
|
103
|
-
const t = (key: keyof Dict): string => (dict ? dict[key] : hostT(key));
|
|
104
|
-
|
|
105
|
-
// Re-read on every document revision; the initial call covers the gap
|
|
106
|
-
// between the first render and the subscription.
|
|
107
|
-
// 每次文档修订都重新读取;首次调用用于覆盖「首次渲染」到「订阅生效」之间的空档。
|
|
108
|
-
useEffect(() => {
|
|
109
|
-
const sync = () => setSettings(readSettings(doc));
|
|
110
|
-
sync();
|
|
111
|
-
return doc.subscribe(sync);
|
|
112
|
-
}, [doc]);
|
|
113
|
-
|
|
114
107
|
const items = [
|
|
115
108
|
{ id: AUTO, label: t("autoLabel") },
|
|
116
109
|
...CATALOGUE.map((language) => ({ id: language.tag, label: language.nativeName }))
|
|
117
110
|
];
|
|
118
111
|
const activeLabel =
|
|
119
112
|
settings.language === AUTO ? t("autoLabel") : nativeNameFor(settings.language) ?? settings.language;
|
|
120
|
-
|
|
121
113
|
const close = (): void => setOpen(false);
|
|
122
|
-
const toggle = (): void => setOpen((value: boolean) => !value);
|
|
123
114
|
const choose = (id: string): void => {
|
|
124
115
|
writeField(doc, FIELD_LANGUAGE, id);
|
|
125
116
|
close();
|
|
126
117
|
};
|
|
127
|
-
|
|
128
118
|
const picker = h(
|
|
129
119
|
"button",
|
|
130
120
|
{
|
|
@@ -132,50 +122,226 @@ export function createRow(primitives: UiPrimitives | undefined): (props: RowBind
|
|
|
132
122
|
className: "dsh_desk_lang_picker",
|
|
133
123
|
"aria-haspopup": "menu",
|
|
134
124
|
"aria-expanded": open,
|
|
135
|
-
onClick:
|
|
125
|
+
onClick: (): void => setOpen((value: boolean) => !value)
|
|
136
126
|
},
|
|
137
127
|
activeLabel,
|
|
138
128
|
Chevron === undefined ? null : h(Chevron, { className: "dsh_desk_lang_chevron" })
|
|
139
129
|
);
|
|
130
|
+
if (!Menu) return picker;
|
|
131
|
+
return h(Menu, {
|
|
132
|
+
open,
|
|
133
|
+
anchor: picker,
|
|
134
|
+
items,
|
|
135
|
+
selectedId: settings.language,
|
|
136
|
+
align: "end",
|
|
137
|
+
portal: true,
|
|
138
|
+
onClose: close,
|
|
139
|
+
onSelect: choose
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Map a stored minute count onto the picker id it should show. / 把存储的分钟数映射成选择器应显示的选项 id。 */
|
|
145
|
+
function derivedPreset(minutes: number): string {
|
|
146
|
+
if (minutes < 0) return "off";
|
|
147
|
+
if (minutes === REMINDER_EVERY_TURN) return "turn";
|
|
148
|
+
const preset = PRESET_MINUTES.find((candidate) => candidate === minutes);
|
|
149
|
+
return preset === undefined ? "custom" : String(preset);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Build the reminder picker: presets, every turn, off, and a custom minute count.
|
|
154
|
+
* 构建提醒选择器:预设、每轮、关闭,以及自定义分钟数。
|
|
155
|
+
*
|
|
156
|
+
* It uses the host Menu like the language picker, so the two controls match;
|
|
157
|
+
* a native `<select>` renders its own list chrome and breaks the row style.
|
|
158
|
+
* 与语言选择器一样使用宿主 Menu,两个控件因此外观一致;原生 `<select>` 的下拉列表
|
|
159
|
+
* 自带浏览器样式,会破坏这一行。
|
|
160
|
+
*/
|
|
161
|
+
function createReminderPicker(primitives: UiPrimitives | undefined) {
|
|
162
|
+
const Menu = primitives?.Menu;
|
|
163
|
+
const Chevron =
|
|
164
|
+
primitives?.IconChevronDownOutlineRegular ??
|
|
165
|
+
primitives?.IconChevronDownOutline14 ??
|
|
166
|
+
primitives?.IconChevronDownOutlineMedium;
|
|
167
|
+
|
|
168
|
+
return function ReminderPicker(props: Binding & { settings: ThinkingSettings }): unknown {
|
|
169
|
+
const { doc, t, settings } = props;
|
|
170
|
+
const derived = derivedPreset(settings.reminderMinutes);
|
|
171
|
+
const current = settings.reminderMinutes > 0 ? settings.reminderMinutes : 30;
|
|
172
|
+
const [selected, setSelected] = useState<string>(derived);
|
|
173
|
+
const [open, setOpen] = useState<boolean>(false);
|
|
174
|
+
const [draft, setDraft] = useState<string>(String(current));
|
|
175
|
+
|
|
176
|
+
// An external change (the other surface, or a re-read) wins over a local
|
|
177
|
+
// selection; a local "custom" survives because it leaves `derived` alone.
|
|
178
|
+
// 外部改动(另一入口或重新读取)优先于本地选择;本地的「自定义」不会改变
|
|
179
|
+
// `derived`,因此能保持选中。
|
|
180
|
+
useEffect(() => {
|
|
181
|
+
setSelected(derived);
|
|
182
|
+
}, [derived]);
|
|
183
|
+
|
|
184
|
+
// Keep the input in step with the stored value, so an accepted edit never
|
|
185
|
+
// falls back to the previous number while the document update lands.
|
|
186
|
+
// 让输入框跟随存储值,避免写入落盘前先闪回上一个数字。
|
|
187
|
+
useEffect(() => {
|
|
188
|
+
setDraft(String(current));
|
|
189
|
+
}, [current]);
|
|
190
|
+
|
|
191
|
+
const labelOf = (id: string): string => {
|
|
192
|
+
if (id === "off") return t("reminderOff");
|
|
193
|
+
if (id === "turn") return t("reminderTurn");
|
|
194
|
+
if (id === "custom") return t("reminderCustom");
|
|
195
|
+
return `${id} ${t("reminderUnit")}`;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
const items = ["off", "turn", ...PRESET_MINUTES.map(String), "custom"].map((id) => ({
|
|
199
|
+
id,
|
|
200
|
+
label: labelOf(id)
|
|
201
|
+
}));
|
|
202
|
+
|
|
203
|
+
const choose = (id: string): void => {
|
|
204
|
+
setOpen(false);
|
|
205
|
+
setSelected(id);
|
|
206
|
+
if (id === "off") writeField(doc, FIELD_REMINDER, REMINDER_OFF);
|
|
207
|
+
else if (id === "turn") writeField(doc, FIELD_REMINDER, REMINDER_EVERY_TURN);
|
|
208
|
+
else if (id !== "custom") writeField(doc, FIELD_REMINDER, Number(id));
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const commit = (): void => {
|
|
212
|
+
const minutes = Math.round(Number(draft));
|
|
213
|
+
if (!Number.isFinite(minutes) || draft.trim() === "") {
|
|
214
|
+
setDraft(String(current));
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const clamped = Math.min(MAX_REMINDER_MINUTES, Math.max(1, minutes));
|
|
218
|
+
writeField(doc, FIELD_REMINDER, clamped);
|
|
219
|
+
setDraft(String(clamped));
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const picker = h(
|
|
223
|
+
"button",
|
|
224
|
+
{
|
|
225
|
+
type: "button",
|
|
226
|
+
className: "dsh_desk_lang_picker",
|
|
227
|
+
"aria-haspopup": "menu",
|
|
228
|
+
"aria-expanded": open,
|
|
229
|
+
onClick: (): void => setOpen((value: boolean) => !value)
|
|
230
|
+
},
|
|
231
|
+
labelOf(selected),
|
|
232
|
+
Chevron === undefined ? null : h(Chevron, { className: "dsh_desk_lang_chevron" })
|
|
233
|
+
);
|
|
140
234
|
|
|
141
235
|
const control = Menu
|
|
142
236
|
? h(Menu, {
|
|
143
237
|
open,
|
|
144
238
|
anchor: picker,
|
|
145
239
|
items,
|
|
146
|
-
selectedId:
|
|
240
|
+
selectedId: selected,
|
|
147
241
|
align: "end",
|
|
148
242
|
portal: true,
|
|
149
|
-
onClose:
|
|
243
|
+
onClose: (): void => setOpen(false),
|
|
150
244
|
onSelect: choose
|
|
151
245
|
})
|
|
152
246
|
: picker;
|
|
153
247
|
|
|
248
|
+
if (selected !== "custom") return control;
|
|
249
|
+
return h(
|
|
250
|
+
"div",
|
|
251
|
+
{ className: "dsh_desk_lang_control" },
|
|
252
|
+
control,
|
|
253
|
+
h("input", {
|
|
254
|
+
type: "number",
|
|
255
|
+
className: "dsh_desk_lang_input",
|
|
256
|
+
min: 1,
|
|
257
|
+
max: MAX_REMINDER_MINUTES,
|
|
258
|
+
placeholder: String(settings.reminderMinutes > 0 ? settings.reminderMinutes : 30),
|
|
259
|
+
value: draft,
|
|
260
|
+
onChange: (event: { currentTarget: { value: string } }): void => setDraft(event.currentTarget.value),
|
|
261
|
+
onBlur: commit,
|
|
262
|
+
onKeyDown: (event: { key: string }): void => {
|
|
263
|
+
if (event.key === "Enter") commit();
|
|
264
|
+
}
|
|
265
|
+
}),
|
|
266
|
+
h("span", { className: "dsh_desk_lang_hint" }, t("reminderCustomHint"))
|
|
267
|
+
);
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Build the General settings row: heading, description and the language picker.
|
|
273
|
+
* 构建「通用」设置行:标题、说明与语言选择器。
|
|
274
|
+
*/
|
|
275
|
+
export function createRow(primitives: UiPrimitives | undefined): (props: Binding) => unknown {
|
|
276
|
+
const LanguagePicker = createLanguagePicker(primitives);
|
|
277
|
+
return function ThinkingLanguageRow(props: Binding): unknown {
|
|
278
|
+
const settings = useSettings(props.doc);
|
|
154
279
|
return h(
|
|
155
280
|
"div",
|
|
156
281
|
{ className: "dsh_desk_lang_row" },
|
|
157
282
|
h(
|
|
158
283
|
"div",
|
|
159
284
|
{ className: "dsh_desk_lang_text" },
|
|
160
|
-
h("div", { className: "dsh_desk_lang_title" }, t("heading")),
|
|
161
|
-
h("div", { className: "dsh_desk_lang_desc" }, t("description"))
|
|
285
|
+
h("div", { className: "dsh_desk_lang_title" }, props.t("heading")),
|
|
286
|
+
h("div", { className: "dsh_desk_lang_desc" }, props.t("description"))
|
|
162
287
|
),
|
|
163
|
-
|
|
288
|
+
h(LanguagePicker, { doc: props.doc, t: props.t, settings })
|
|
289
|
+
);
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Build the plugin configuration card: language and reminder interval.
|
|
295
|
+
* 构建插件配置卡片:思考语言与提醒间隔。
|
|
296
|
+
*
|
|
297
|
+
* The host renders this inside the plugin's detail page; `view: 'summary'` is the
|
|
298
|
+
* one-line form a card may ask for, which this plugin leaves empty.
|
|
299
|
+
* 宿主把它渲染在插件详情页里;`view: 'summary'` 是卡片可能请求的单行形式,本插件
|
|
300
|
+
* 留空。
|
|
301
|
+
*/
|
|
302
|
+
export function createConfigCard(primitives: UiPrimitives | undefined): (props: Binding & { view?: string }) => unknown {
|
|
303
|
+
const LanguagePicker = createLanguagePicker(primitives);
|
|
304
|
+
const ReminderPicker = createReminderPicker(primitives);
|
|
305
|
+
return function ThinkingLanguageCard(props: Binding & { view?: string }): unknown {
|
|
306
|
+
const settings = useSettings(props.doc);
|
|
307
|
+
if (props.view === "summary") return null;
|
|
308
|
+
const binding = { doc: props.doc, t: props.t, settings };
|
|
309
|
+
return h(
|
|
310
|
+
"div",
|
|
311
|
+
null,
|
|
312
|
+
h(
|
|
313
|
+
"div",
|
|
314
|
+
{ className: "dsh_desk_lang_row" },
|
|
315
|
+
h(
|
|
316
|
+
"div",
|
|
317
|
+
{ className: "dsh_desk_lang_text" },
|
|
318
|
+
h("div", { className: "dsh_desk_lang_title" }, props.t("heading")),
|
|
319
|
+
h("div", { className: "dsh_desk_lang_desc" }, props.t("description"))
|
|
320
|
+
),
|
|
321
|
+
h(LanguagePicker, binding)
|
|
322
|
+
),
|
|
323
|
+
h(
|
|
324
|
+
"div",
|
|
325
|
+
{ className: "dsh_desk_lang_row" },
|
|
326
|
+
h(
|
|
327
|
+
"div",
|
|
328
|
+
{ className: "dsh_desk_lang_text" },
|
|
329
|
+
h("div", { className: "dsh_desk_lang_title" }, props.t("reminderHeading")),
|
|
330
|
+
h("div", { className: "dsh_desk_lang_desc" }, props.t("reminderDescription"))
|
|
331
|
+
),
|
|
332
|
+
h(ReminderPicker, binding)
|
|
333
|
+
)
|
|
164
334
|
);
|
|
165
335
|
};
|
|
166
336
|
}
|
|
167
337
|
|
|
168
338
|
// Declaration order follows the host's own PreferenceRow verbatim —
|
|
169
339
|
// packages/client/ui-chat/src/client/settings/PreferenceRow.module.css, MIT,
|
|
170
|
-
// Copyright (c) 2026 DeepSeek — because that is the row this one sits beside
|
|
171
|
-
// the two can be diffed property by property whenever the host styles move.
|
|
340
|
+
// Copyright (c) 2026 DeepSeek — because that is the row this one sits beside.
|
|
172
341
|
// Class names differ (the host's are CSS-Modules hashes) and the picker carries a
|
|
173
342
|
// trailing `flex:none` the host does not need; every other character matches.
|
|
174
|
-
// 声明顺序逐字照宿主自己的 PreferenceRow
|
|
175
|
-
//
|
|
176
|
-
// Copyright (c) 2026 DeepSeek——因为那就是本行紧邻的邻居,宿主样式变动时可以逐属性
|
|
177
|
-
// 对照。类名不同(宿主的是 CSS Modules 哈希),且选择器末尾多一个宿主不需要的
|
|
178
|
-
// `flex:none`;除此之外逐字符一致。
|
|
343
|
+
// 声明顺序逐字照宿主自己的 PreferenceRow——因为那就是本行紧邻的邻居。类名不同,
|
|
344
|
+
// 选择器末尾多一个宿主不需要的 `flex:none`;除此之外逐字符一致。
|
|
179
345
|
const rowCss = [
|
|
180
346
|
".dsh_desk_lang_row{border-bottom:.5px solid var(--dsw-alias-border-l2);align-items:center;gap:8px;padding:16px 0;display:flex}",
|
|
181
347
|
".dsh_desk_lang_text{flex-direction:column;flex:1;gap:4px;min-width:0;padding-right:48px;display:flex}",
|
|
@@ -183,24 +349,18 @@ const rowCss = [
|
|
|
183
349
|
".dsh_desk_lang_desc{color:var(--dsw-alias-label-tertiary);font-size:12px;font-weight:400;line-height:18px}",
|
|
184
350
|
".dsh_desk_lang_picker{border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-module-platform);height:36px;font:inherit;color:var(--dsw-alias-label-primary);cursor:pointer;border:none;align-items:center;gap:12px;padding:0 14px;font-size:14px;line-height:22px;display:inline-flex;flex:none}",
|
|
185
351
|
".dsh_desk_lang_picker:hover{background:var(--dsw-alias-interactive-bg-hover)}",
|
|
186
|
-
".dsh_desk_lang_chevron{flex:none}"
|
|
352
|
+
".dsh_desk_lang_chevron{flex:none}",
|
|
353
|
+
".dsh_desk_lang_control{align-items:center;gap:8px;display:flex;flex:none}",
|
|
354
|
+
".dsh_desk_lang_input{border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-module-platform);height:36px;width:88px;font:inherit;color:var(--dsw-alias-label-primary);border:none;padding:0 12px;font-size:14px}",
|
|
355
|
+
".dsh_desk_lang_hint{color:var(--dsw-alias-label-tertiary);font-size:12px;white-space:nowrap}"
|
|
187
356
|
].join("\n");
|
|
188
357
|
|
|
189
358
|
/** Marks the injected stylesheet, so a second mount can detect the first. / 标记已注入的样式表,使第二次挂载能发现第一次。 */
|
|
190
359
|
const STYLE_MARKER = "dsh-thinking-lang";
|
|
191
360
|
|
|
192
361
|
/**
|
|
193
|
-
* Inject the
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
* The guard reads the document rather than a module-level flag: a client plugin
|
|
197
|
-
* can be mounted more than once against the same page, and only the DOM knows
|
|
198
|
-
* whether this sheet is already there. Content is compared as well, because a
|
|
199
|
-
* hot-reloaded bundle keeps its marker while its CSS changes; skipping on the
|
|
200
|
-
* marker alone would leave the row styled by class names that no longer exist.
|
|
201
|
-
* 判重依据是文档本身而不是模块级标志:客户端插件可能被重复挂载到同一页面,只有 DOM
|
|
202
|
-
* 知道这张样式表是否已经存在。同时比对内容:热重载的 bundle 标记不变而 CSS 已变,
|
|
203
|
-
* 只看标记就跳过会让这一行按已不存在的类名取样式。
|
|
362
|
+
* Inject the settings stylesheet once per document, replacing a stale one.
|
|
363
|
+
* 每份文档只注入一次设置样式表,已过期的那张会被替换。
|
|
204
364
|
*/
|
|
205
365
|
export function mountRowStyles(): void {
|
|
206
366
|
if (typeof document === "undefined") return;
|