@linxin666/dsh-liangshen 0.3.22 → 0.3.24
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/README.i18n.yaml +2 -2
- package/README.md +45 -38
- package/README.zh.md +44 -37
- package/lib/client.js +1058 -11
- package/lib/client.js.map +1 -1
- package/lib/index.js +105 -22
- package/lib/types/client/LiangShenSettingsCard.d.ts +61 -0
- package/lib/types/client/PluginSettingsCard.d.ts +133 -0
- package/lib/types/client/index.d.ts +34 -0
- package/lib/types/client/locales.d.ts +27 -1
- package/lib/types/client/plugin-card-seat.d.ts +96 -0
- package/lib/types/client/settings-form.d.ts +197 -0
- package/lib/types/core/lever.d.ts +6 -3
- package/lib/types/index.d.ts +23 -11
- package/lib/types/sync.d.ts +29 -2
- package/package.json +6 -2
- package/presets/liangshen/NOTICE +4 -4
- package/presets/liangshen/agent.cordis.yml +130 -119
- package/presets/liangshen/minimal-prompt.mjs +71 -36
- package/presets/liangshen/paging.mjs +232 -0
- package/presets/liangshen/tool-activate.mjs +176 -0
- package/presets/liangshen/tool-catalog.mjs +610 -218
- package/presets/liangshen/working-context.mjs +214 -0
- package/src/client/LiangShenLever.tsx +4 -1
- package/src/client/LiangShenSettingsCard.tsx +149 -0
- package/src/client/PluginSettingsCard.tsx +550 -0
- package/src/client/index.ts +60 -1
- package/src/client/locales.ts +53 -1
- package/src/client/plugin-card-seat.ts +185 -0
- package/src/client/settings-card.module.css +418 -0
- package/src/client/settings-form.ts +439 -0
- package/src/core/lever.ts +7 -4
- package/src/index.ts +35 -14
- package/src/sync.test.ts +86 -7
- package/src/sync.ts +108 -6
- package/tools/benchmark-live-run.mjs +24 -33
- package/presets/liangshen/custom-bash.mjs +0 -213
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
// Generated by scripts/sync-shared.mjs from shared/client/settings/PluginSettingsCard.tsx. Do not edit this copy; edit the shared source and run "node scripts/sync-shared.mjs".
|
|
2
|
+
/**
|
|
3
|
+
* Family-shared chrome for plugin settings cards: a disclosure header naming
|
|
4
|
+
* the plugin and what its settings govern, the controls inside, and the save
|
|
5
|
+
* that writes them. Renders nothing while the namespace is unavailable — a
|
|
6
|
+
* deployment that does not compose the owning plugin should show no trace of
|
|
7
|
+
* it. Inlined into each consumer's client bundle; mirrors the official
|
|
8
|
+
* ui-plugin-config PluginCard in a self-contained slice.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { useCallback, useEffect, useLayoutEffect, useRef, useState, type KeyboardEvent, type ReactNode } from 'react'
|
|
12
|
+
import type { CardShell } from './settings-form.ts'
|
|
13
|
+
import css from './settings-card.module.css'
|
|
14
|
+
|
|
15
|
+
/** Copy keys the card chrome itself reads; every consumer locale carries this shared vocabulary. */
|
|
16
|
+
export const CARD_COPY_KEYS = [
|
|
17
|
+
'settings.collapse',
|
|
18
|
+
'settings.expand',
|
|
19
|
+
'settings.notExposed',
|
|
20
|
+
'settings.unsaved',
|
|
21
|
+
'settings.readOnly',
|
|
22
|
+
'settings.saveFailed',
|
|
23
|
+
'settings.discard',
|
|
24
|
+
'settings.save',
|
|
25
|
+
'settings.saving',
|
|
26
|
+
] as const
|
|
27
|
+
|
|
28
|
+
/** Copy key the card chrome itself reads. */
|
|
29
|
+
export type CardCopyKey = (typeof CARD_COPY_KEYS)[number]
|
|
30
|
+
|
|
31
|
+
/** Key domain for the plugin's own copy (inferred per consumer). */
|
|
32
|
+
export type SettingsCardKey<TKey extends string = string> = TKey | CardCopyKey
|
|
33
|
+
|
|
34
|
+
/** Card chrome shared by every plugin settings card. */
|
|
35
|
+
export interface PluginSettingsCardProps<TKey extends string = string> {
|
|
36
|
+
/** Locale reader for this card's copy. */
|
|
37
|
+
t: (key: SettingsCardKey<TKey>, params?: Record<string, string | number>) => string
|
|
38
|
+
/** Locale key of the plugin's name. */
|
|
39
|
+
titleKey: TKey
|
|
40
|
+
/** Locale key of the line describing what this plugin's settings govern. */
|
|
41
|
+
descriptionKey: TKey
|
|
42
|
+
/** Optional rich header description rendered instead of the plain t(descriptionKey) text (the plain text stays as the tooltip). */
|
|
43
|
+
descriptionNode?: ReactNode
|
|
44
|
+
/** The card's form state: availability, writability, and what a save would do. */
|
|
45
|
+
state: CardShell
|
|
46
|
+
/** Write every staged edit. */
|
|
47
|
+
onSave: () => void
|
|
48
|
+
/** Drop every staged edit. */
|
|
49
|
+
onDiscard: () => void
|
|
50
|
+
/**
|
|
51
|
+
* Render the controls expanded on arrival (still collapsible). Defaults to
|
|
52
|
+
* true: promoted first-level sections show their settings immediately.
|
|
53
|
+
*/
|
|
54
|
+
defaultOpen?: boolean
|
|
55
|
+
/**
|
|
56
|
+
* Render without the collapse affordance: a static header and an always
|
|
57
|
+
* visible body. Used by first-level settings sections whose nav entry
|
|
58
|
+
* already provides the selection.
|
|
59
|
+
*/
|
|
60
|
+
alwaysOpen?: boolean
|
|
61
|
+
/**
|
|
62
|
+
* Hide the save/discard footer: cards whose body applies its own changes
|
|
63
|
+
* immediately (an embedded external settings section) have no staged
|
|
64
|
+
* edits, so the footer would sit there permanently disabled.
|
|
65
|
+
*/
|
|
66
|
+
hideFooter?: boolean
|
|
67
|
+
/** The plugin's controls. */
|
|
68
|
+
children: ReactNode
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Render one plugin settings card.
|
|
73
|
+
* @param props - the plugin's copy keys, its form state, and its controls.
|
|
74
|
+
* @returns the card, or nothing while the namespace is still loading.
|
|
75
|
+
*/
|
|
76
|
+
export function PluginSettingsCard<TKey extends string = string>(props: PluginSettingsCardProps<TKey>) {
|
|
77
|
+
const [open, setOpen] = useState(props.defaultOpen ?? true)
|
|
78
|
+
const { state, alwaysOpen } = props
|
|
79
|
+
if (!state.available) return null
|
|
80
|
+
const title = props.t(props.titleKey)
|
|
81
|
+
const description = props.t(props.descriptionKey)
|
|
82
|
+
const blocked = !state.dirty || state.invalid || state.saving
|
|
83
|
+
const expanded = alwaysOpen === true || open
|
|
84
|
+
const cardClass = expanded ? `${css.cardOpen} ${css.card}` : css.card
|
|
85
|
+
// With alwaysOpen the nav entry already provides the selection, so the
|
|
86
|
+
// header is a static title row instead of a disclosure button.
|
|
87
|
+
const header = alwaysOpen === true
|
|
88
|
+
? (
|
|
89
|
+
<div className={css.headerStatic}>
|
|
90
|
+
<span className={css.headText}>
|
|
91
|
+
<span className={css.name} title={title}>{title}</span>
|
|
92
|
+
<span className={css.description} title={description}>{props.descriptionNode ?? description}</span>
|
|
93
|
+
</span>
|
|
94
|
+
{state.dirty ? <span className={css.pending} title={props.t('settings.unsaved')}>{props.t('settings.unsaved')}</span> : null}
|
|
95
|
+
</div>
|
|
96
|
+
)
|
|
97
|
+
: (
|
|
98
|
+
<button
|
|
99
|
+
type="button"
|
|
100
|
+
className={css.header}
|
|
101
|
+
aria-expanded={open}
|
|
102
|
+
aria-label={`${props.t(open ? 'settings.collapse' : 'settings.expand')}: ${title}`}
|
|
103
|
+
onClick={() => { setOpen(!open) }}
|
|
104
|
+
>
|
|
105
|
+
<span className={css.headText}>
|
|
106
|
+
<span className={css.name} title={title}>{title}</span>
|
|
107
|
+
<span className={css.description} title={description}>{props.descriptionNode ?? description}</span>
|
|
108
|
+
</span>
|
|
109
|
+
{state.dirty ? <span className={css.pending} title={props.t('settings.unsaved')}>{props.t('settings.unsaved')}</span> : null}
|
|
110
|
+
<svg
|
|
111
|
+
width="14"
|
|
112
|
+
height="14"
|
|
113
|
+
viewBox="0 0 14 14"
|
|
114
|
+
fill="none"
|
|
115
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
116
|
+
className={open ? `${css.chevron} ${css.chevronOpen}` : css.chevron}
|
|
117
|
+
>
|
|
118
|
+
<path
|
|
119
|
+
d="M11.8486 5.5L11.4238 5.92383L8.69727 8.65137C8.44157 8.90706 8.21562 9.13382 8.01172 9.29785C7.79912 9.46883 7.55595 9.61756 7.25 9.66602C7.08435 9.69222 6.91565 9.69222 6.75 9.66602C6.44405 9.61756 6.20088 9.46883 5.98828 9.29785C5.78438 9.13382 5.55843 8.90706 5.30273 8.65137L2.57617 5.92383L2.15137 5.5L3 4.65137L3.42383 5.07617L6.15137 7.80273C6.42595 8.07732 6.59876 8.24849 6.74023 8.3623C6.87291 8.46904 6.92272 8.47813 6.9375 8.48047C6.97895 8.48703 7.02105 8.48703 7.0625 8.48047C7.07728 8.47813 7.12709 8.46904 7.25977 8.3623C7.40124 8.24849 7.57405 8.07732 7.84863 7.80273L10.5762 5.07617L11 4.65137L11.8486 5.5Z"
|
|
120
|
+
fill="currentColor"
|
|
121
|
+
/>
|
|
122
|
+
</svg>
|
|
123
|
+
</button>
|
|
124
|
+
)
|
|
125
|
+
// The namespace exists but the Host does not serve it to this client (the
|
|
126
|
+
// official settings allowlist omits third-party namespaces): show a card
|
|
127
|
+
// that explains the gap instead of vanishing, so a missing card never
|
|
128
|
+
// reads as a missing plugin.
|
|
129
|
+
if (!state.exposed) {
|
|
130
|
+
return (
|
|
131
|
+
<li className={cardClass}>
|
|
132
|
+
{header}
|
|
133
|
+
{expanded
|
|
134
|
+
? (
|
|
135
|
+
<div className={css.body}>
|
|
136
|
+
<p className={css.notExposed} role="status">{props.t('settings.notExposed')}</p>
|
|
137
|
+
</div>
|
|
138
|
+
)
|
|
139
|
+
: null}
|
|
140
|
+
</li>
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
return (
|
|
144
|
+
<li className={cardClass}>
|
|
145
|
+
{header}
|
|
146
|
+
{expanded
|
|
147
|
+
? (
|
|
148
|
+
<div className={css.body}>
|
|
149
|
+
{!state.writable ? <p className={css.readOnly} role="status">{props.t('settings.readOnly')}</p> : null}
|
|
150
|
+
{props.children}
|
|
151
|
+
{props.hideFooter === true
|
|
152
|
+
? null
|
|
153
|
+
: (
|
|
154
|
+
<div className={css.footer}>
|
|
155
|
+
{state.failed
|
|
156
|
+
? (
|
|
157
|
+
<p className={css.failed} role="status">
|
|
158
|
+
{props.t('settings.saveFailed')}{state.failedReason ? ' - ' + state.failedReason : ''}
|
|
159
|
+
</p>
|
|
160
|
+
)
|
|
161
|
+
: null}
|
|
162
|
+
<button
|
|
163
|
+
type="button"
|
|
164
|
+
className={css.discard}
|
|
165
|
+
disabled={!state.dirty || state.saving}
|
|
166
|
+
onClick={props.onDiscard}
|
|
167
|
+
>
|
|
168
|
+
{props.t('settings.discard')}
|
|
169
|
+
</button>
|
|
170
|
+
<button
|
|
171
|
+
type="button"
|
|
172
|
+
className={css.save}
|
|
173
|
+
disabled={blocked}
|
|
174
|
+
onClick={props.onSave}
|
|
175
|
+
>
|
|
176
|
+
{props.t(!state.saving ? 'settings.save' : 'settings.saving')}
|
|
177
|
+
</button>
|
|
178
|
+
</div>
|
|
179
|
+
)}
|
|
180
|
+
</div>
|
|
181
|
+
)
|
|
182
|
+
: null}
|
|
183
|
+
</li>
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Props every field control needs regardless of its value type. */
|
|
188
|
+
export interface FieldProps {
|
|
189
|
+
/** Stable id associating the label with its control. */
|
|
190
|
+
id: string
|
|
191
|
+
/** Visible label. */
|
|
192
|
+
label: string
|
|
193
|
+
/** One-line explanation rendered under the control. */
|
|
194
|
+
hint: string
|
|
195
|
+
/** Draft text this control renders. */
|
|
196
|
+
text: string
|
|
197
|
+
/** True when saving would leave a user-layer entry for this field. */
|
|
198
|
+
overridden: boolean
|
|
199
|
+
/** True when the draft is not a value this field accepts. */
|
|
200
|
+
invalid: boolean
|
|
201
|
+
/** Copy for the overridden badge. */
|
|
202
|
+
overriddenLabel: string
|
|
203
|
+
/** Copy for the reset control. */
|
|
204
|
+
resetLabel: string
|
|
205
|
+
/** Copy shown in place of the hint while the draft is invalid. */
|
|
206
|
+
invalidLabel: string
|
|
207
|
+
/** Disables every control (read-only document, or an unavailable namespace). */
|
|
208
|
+
disabled: boolean
|
|
209
|
+
/** Stage draft text. */
|
|
210
|
+
onEdit: (text: string) => void
|
|
211
|
+
/** Stage a clear so the field re-inherits the composition layer. */
|
|
212
|
+
onReset: () => void
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** A staged value field. `numeric` only hints the keypad: which drafts a field accepts is decided by its spec. */
|
|
216
|
+
export function ValueField(props: FieldProps & {
|
|
217
|
+
/** Hints a numeric keypad without narrowing what the control accepts. */
|
|
218
|
+
numeric?: boolean
|
|
219
|
+
/** Placeholder shown while the draft is empty. */
|
|
220
|
+
placeholder?: string
|
|
221
|
+
}) {
|
|
222
|
+
return (
|
|
223
|
+
<div className={css.field}>
|
|
224
|
+
<div className={css.head}>
|
|
225
|
+
<label className={css.label} htmlFor={props.id}>{props.label}</label>
|
|
226
|
+
{props.overridden
|
|
227
|
+
? (
|
|
228
|
+
<span className={css.badges}>
|
|
229
|
+
<span className={css.badge}>{props.overriddenLabel}</span>
|
|
230
|
+
<button
|
|
231
|
+
type="button"
|
|
232
|
+
className={css.reset}
|
|
233
|
+
disabled={props.disabled}
|
|
234
|
+
onClick={props.onReset}
|
|
235
|
+
>
|
|
236
|
+
{props.resetLabel}
|
|
237
|
+
</button>
|
|
238
|
+
</span>
|
|
239
|
+
)
|
|
240
|
+
: null}
|
|
241
|
+
</div>
|
|
242
|
+
<input
|
|
243
|
+
id={props.id}
|
|
244
|
+
className={props.invalid ? css.inputInvalid : css.input}
|
|
245
|
+
type="text"
|
|
246
|
+
{...props.numeric === true ? { inputMode: 'numeric' as const } : {}}
|
|
247
|
+
{...props.invalid ? { 'aria-invalid': true } : {}}
|
|
248
|
+
value={props.text}
|
|
249
|
+
placeholder={props.placeholder ?? ''}
|
|
250
|
+
disabled={props.disabled}
|
|
251
|
+
onChange={(event) => { props.onEdit(event.target.value) }}
|
|
252
|
+
/>
|
|
253
|
+
<p className={props.invalid ? css.invalid : css.hint}>
|
|
254
|
+
{props.invalid ? props.invalidLabel : props.hint}
|
|
255
|
+
</p>
|
|
256
|
+
</div>
|
|
257
|
+
)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const NON_SKIN_BODY_MARKERS = new Set(['dshSkinCenter', 'dshSidebarCollapsed'])
|
|
261
|
+
// 检测使用使用皮肤,用了皮肤退回原生select样式,防止样式冲突。默认外观下使用优化后的select样式。
|
|
262
|
+
function isSkinActive(): boolean {
|
|
263
|
+
const datasetList = Object.keys(document.body.dataset)
|
|
264
|
+
const isActive = datasetList.some(key => key.startsWith('dsh') && !NON_SKIN_BODY_MARKERS.has(key))
|
|
265
|
+
return isActive
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
interface SelectOption {
|
|
269
|
+
value: string
|
|
270
|
+
label: string
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const SELECT_CLOSE_MS = 100
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* The shared dual-mode select control. While an appearance skin is active it
|
|
277
|
+
* renders the legacy native `<select>` untouched, so element-level skin
|
|
278
|
+
* selectors keep working; under the default appearance it renders a
|
|
279
|
+
* self-drawn `role="listbox"` popup whose open/close is transition-animated.
|
|
280
|
+
* Staged cards reach it through BooleanField/ChoiceField; immediate-apply
|
|
281
|
+
* editors (the side-card prefs) bind it directly through onEdit.
|
|
282
|
+
* 双模式下拉框:皮肤激活时用原生 select,默认外观用自绘动画弹层。
|
|
283
|
+
*/
|
|
284
|
+
export function SelectField(props: {
|
|
285
|
+
id: string
|
|
286
|
+
options: ReadonlyArray<SelectOption>
|
|
287
|
+
value: string
|
|
288
|
+
disabled: boolean
|
|
289
|
+
invalid: boolean
|
|
290
|
+
onEdit: (text: string) => void
|
|
291
|
+
}) {
|
|
292
|
+
const { id, options, value } = props
|
|
293
|
+
const [open, setOpen] = useState(false)
|
|
294
|
+
const [closing, setClosing] = useState(false)
|
|
295
|
+
const [phase, setPhase] = useState<'initial' | 'open'>('initial')
|
|
296
|
+
const [activeIndex, setActiveIndex] = useState(0)
|
|
297
|
+
const closeTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)
|
|
298
|
+
const wrapRef = useRef<HTMLDivElement | null>(null)
|
|
299
|
+
const popupRef = useRef<HTMLDivElement | null>(null)
|
|
300
|
+
|
|
301
|
+
const currentIndex = () => {
|
|
302
|
+
const index = options.findIndex(option => option.value === value)
|
|
303
|
+
return index >= 0 ? index : 0
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const close = useCallback(() => {
|
|
307
|
+
if (closeTimer.current !== undefined) clearTimeout(closeTimer.current)
|
|
308
|
+
setClosing(true)
|
|
309
|
+
closeTimer.current = setTimeout(() => {
|
|
310
|
+
setClosing(false)
|
|
311
|
+
setOpen(false)
|
|
312
|
+
}, SELECT_CLOSE_MS)
|
|
313
|
+
}, [])
|
|
314
|
+
|
|
315
|
+
const openPopup = () => {
|
|
316
|
+
if (closeTimer.current !== undefined) clearTimeout(closeTimer.current)
|
|
317
|
+
setActiveIndex(currentIndex())
|
|
318
|
+
setPhase('initial')
|
|
319
|
+
setClosing(false)
|
|
320
|
+
setOpen(true)
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const commit = (index: number) => {
|
|
324
|
+
const option = options[index]
|
|
325
|
+
if (option) props.onEdit(option.value)
|
|
326
|
+
close()
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const onTriggerClick = () => {
|
|
330
|
+
if (props.disabled) return
|
|
331
|
+
if (open && !closing) close()
|
|
332
|
+
else openPopup()
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const onKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {
|
|
336
|
+
if (props.disabled) return
|
|
337
|
+
const count = options.length
|
|
338
|
+
switch (event.key) {
|
|
339
|
+
case 'ArrowDown':
|
|
340
|
+
case 'ArrowUp':
|
|
341
|
+
case 'Enter':
|
|
342
|
+
case ' ':
|
|
343
|
+
event.preventDefault()
|
|
344
|
+
if (!open) {
|
|
345
|
+
openPopup()
|
|
346
|
+
} else if (!closing) {
|
|
347
|
+
if (event.key === 'ArrowDown') setActiveIndex(index => (index + 1) % count)
|
|
348
|
+
else if (event.key === 'ArrowUp') setActiveIndex(index => (index - 1 + count) % count)
|
|
349
|
+
else commit(activeIndex)
|
|
350
|
+
}
|
|
351
|
+
break
|
|
352
|
+
case 'Escape':
|
|
353
|
+
if (open) {
|
|
354
|
+
event.preventDefault()
|
|
355
|
+
event.stopPropagation()
|
|
356
|
+
close()
|
|
357
|
+
}
|
|
358
|
+
break
|
|
359
|
+
case 'Tab':
|
|
360
|
+
if (open) close()
|
|
361
|
+
break
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
useEffect(() => () => {
|
|
366
|
+
if (closeTimer.current !== undefined) clearTimeout(closeTimer.current)
|
|
367
|
+
}, [])
|
|
368
|
+
useLayoutEffect(() => {
|
|
369
|
+
if (open && !closing && phase === 'initial') {
|
|
370
|
+
void popupRef.current?.offsetHeight
|
|
371
|
+
setPhase('open')
|
|
372
|
+
}
|
|
373
|
+
}, [open, closing, phase])
|
|
374
|
+
|
|
375
|
+
useEffect(() => {
|
|
376
|
+
if (!open) return
|
|
377
|
+
const onPointerDown = (event: PointerEvent) => {
|
|
378
|
+
const target = event.target
|
|
379
|
+
if (target instanceof Node && !wrapRef.current?.contains(target)) close()
|
|
380
|
+
}
|
|
381
|
+
document.addEventListener('pointerdown', onPointerDown)
|
|
382
|
+
return () => document.removeEventListener('pointerdown', onPointerDown)
|
|
383
|
+
}, [open, close])
|
|
384
|
+
|
|
385
|
+
useEffect(() => {
|
|
386
|
+
if (props.disabled && open) close()
|
|
387
|
+
}, [props.disabled, open, close])
|
|
388
|
+
|
|
389
|
+
// 使用了皮肤则退回原生select样式防止样式冲突。
|
|
390
|
+
if (isSkinActive()) {
|
|
391
|
+
return (
|
|
392
|
+
<select
|
|
393
|
+
id={id}
|
|
394
|
+
className={css.select}
|
|
395
|
+
value={value}
|
|
396
|
+
disabled={props.disabled}
|
|
397
|
+
onChange={(event) => { props.onEdit(event.target.value) }}
|
|
398
|
+
>
|
|
399
|
+
{options.map(option => (
|
|
400
|
+
<option key={option.value} value={option.value}>{option.label}</option>
|
|
401
|
+
))}
|
|
402
|
+
</select>
|
|
403
|
+
)
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const label = options.find(option => option.value === value)?.label ?? ''
|
|
407
|
+
const popupClass = closing
|
|
408
|
+
? `${css.selectPopup} ${css.selectPopupClose}`
|
|
409
|
+
: phase === 'open'
|
|
410
|
+
? `${css.selectPopup} ${css.selectPopupOpen}`
|
|
411
|
+
: css.selectPopup
|
|
412
|
+
return (
|
|
413
|
+
<div className={css.selectWrap} ref={wrapRef}>
|
|
414
|
+
<button
|
|
415
|
+
type="button"
|
|
416
|
+
id={id}
|
|
417
|
+
className={`${css.select} ${css.selectButton}`}
|
|
418
|
+
disabled={props.disabled}
|
|
419
|
+
aria-haspopup="listbox"
|
|
420
|
+
aria-expanded={open}
|
|
421
|
+
aria-activedescendant={open ? `${id}-o${activeIndex}` : undefined}
|
|
422
|
+
aria-invalid={props.invalid || undefined}
|
|
423
|
+
onClick={onTriggerClick}
|
|
424
|
+
onKeyDown={onKeyDown}
|
|
425
|
+
>
|
|
426
|
+
<span className={css.selectLabel}>{label}</span>
|
|
427
|
+
<svg
|
|
428
|
+
width="14"
|
|
429
|
+
height="14"
|
|
430
|
+
viewBox="0 0 14 14"
|
|
431
|
+
fill="none"
|
|
432
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
433
|
+
className={open ? `${css.selectChevron} ${css.selectChevronOpen}` : css.selectChevron}
|
|
434
|
+
aria-hidden="true"
|
|
435
|
+
>
|
|
436
|
+
<path
|
|
437
|
+
d="M11.8486 5.5L11.4238 5.92383L8.69727 8.65137C8.44157 8.90706 8.21562 9.13382 8.01172 9.29785C7.79912 9.46883 7.55595 9.61756 7.25 9.66602C7.08435 9.69222 6.91565 9.69222 6.75 9.66602C6.44405 9.61756 6.20088 9.46883 5.98828 9.29785C5.78438 9.13382 5.55843 8.90706 5.30273 8.65137L2.57617 5.92383L2.15137 5.5L3 4.65137L3.42383 5.07617L6.15137 7.80273C6.42595 8.07732 6.59876 8.24849 6.74023 8.3623C6.87291 8.46904 6.92272 8.47813 6.9375 8.48047C6.97895 8.48703 7.02105 8.48703 7.0625 8.48047C7.07728 8.47813 7.12709 8.46904 7.25977 8.3623C7.40124 8.24849 7.57405 8.07732 7.84863 7.80273L10.5762 5.07617L11 4.65137L11.8486 5.5Z"
|
|
438
|
+
fill="currentColor"
|
|
439
|
+
/>
|
|
440
|
+
</svg>
|
|
441
|
+
</button>
|
|
442
|
+
{open
|
|
443
|
+
? (
|
|
444
|
+
<div className={popupClass} role="listbox" ref={popupRef}>
|
|
445
|
+
{options.map((option, index) => (
|
|
446
|
+
<div
|
|
447
|
+
key={option.value}
|
|
448
|
+
id={`${id}-o${index}`}
|
|
449
|
+
role="option"
|
|
450
|
+
aria-selected={option.value === value}
|
|
451
|
+
className={`${css.selectOption}${option.value === value ? ` ${css.selectOptionSelected}` : ''}${index === activeIndex && !closing ? ` ${css.selectOptionActive}` : ''}`}
|
|
452
|
+
onClick={() => { commit(index) }}
|
|
453
|
+
>
|
|
454
|
+
{option.label}
|
|
455
|
+
</div>
|
|
456
|
+
))}
|
|
457
|
+
</div>
|
|
458
|
+
)
|
|
459
|
+
: null}
|
|
460
|
+
</div>
|
|
461
|
+
)
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/** A staged boolean field: 继承 / 开 / 关. */
|
|
465
|
+
export function BooleanField(props: FieldProps & {
|
|
466
|
+
/** Copy for the inherit option. */
|
|
467
|
+
inheritLabel: string
|
|
468
|
+
/** Copy for the on option. */
|
|
469
|
+
onLabel: string
|
|
470
|
+
/** Copy for the off option. */
|
|
471
|
+
offLabel: string
|
|
472
|
+
}) {
|
|
473
|
+
return (
|
|
474
|
+
<div className={css.field}>
|
|
475
|
+
<div className={css.head}>
|
|
476
|
+
<label className={css.label} htmlFor={props.id}>{props.label}</label>
|
|
477
|
+
{props.overridden
|
|
478
|
+
? (
|
|
479
|
+
<span className={css.badges}>
|
|
480
|
+
<span className={css.badge}>{props.overriddenLabel}</span>
|
|
481
|
+
<button
|
|
482
|
+
type="button"
|
|
483
|
+
className={css.reset}
|
|
484
|
+
disabled={props.disabled}
|
|
485
|
+
onClick={props.onReset}
|
|
486
|
+
>
|
|
487
|
+
{props.resetLabel}
|
|
488
|
+
</button>
|
|
489
|
+
</span>
|
|
490
|
+
)
|
|
491
|
+
: null}
|
|
492
|
+
</div>
|
|
493
|
+
<SelectField
|
|
494
|
+
id={props.id}
|
|
495
|
+
options={[
|
|
496
|
+
{ value: '', label: props.inheritLabel },
|
|
497
|
+
{ value: 'true', label: props.onLabel },
|
|
498
|
+
{ value: 'false', label: props.offLabel },
|
|
499
|
+
]}
|
|
500
|
+
value={props.text}
|
|
501
|
+
disabled={props.disabled}
|
|
502
|
+
invalid={props.invalid}
|
|
503
|
+
onEdit={props.onEdit}
|
|
504
|
+
/>
|
|
505
|
+
<p className={css.hint}>{props.hint}</p>
|
|
506
|
+
</div>
|
|
507
|
+
)
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/** A staged enumerated field rendered as a select. */
|
|
511
|
+
export function ChoiceField(props: FieldProps & {
|
|
512
|
+
/** Copy for the inherit option (draft text is the empty string). */
|
|
513
|
+
inheritLabel: string
|
|
514
|
+
/** Choices rendered in order; `value` is the draft/stored text. */
|
|
515
|
+
choices: ReadonlyArray<{ value: string; label: string }>
|
|
516
|
+
}) {
|
|
517
|
+
return (
|
|
518
|
+
<div className={css.field}>
|
|
519
|
+
<div className={css.head}>
|
|
520
|
+
<label className={css.label} htmlFor={props.id}>{props.label}</label>
|
|
521
|
+
{props.overridden
|
|
522
|
+
? (
|
|
523
|
+
<span className={css.badges}>
|
|
524
|
+
<span className={css.badge}>{props.overriddenLabel}</span>
|
|
525
|
+
<button
|
|
526
|
+
type="button"
|
|
527
|
+
className={css.reset}
|
|
528
|
+
disabled={props.disabled}
|
|
529
|
+
onClick={props.onReset}
|
|
530
|
+
>
|
|
531
|
+
{props.resetLabel}
|
|
532
|
+
</button>
|
|
533
|
+
</span>
|
|
534
|
+
)
|
|
535
|
+
: null}
|
|
536
|
+
</div>
|
|
537
|
+
<SelectField
|
|
538
|
+
id={props.id}
|
|
539
|
+
options={[{ value: '', label: props.inheritLabel }, ...props.choices]}
|
|
540
|
+
value={props.text}
|
|
541
|
+
disabled={props.disabled}
|
|
542
|
+
invalid={props.invalid}
|
|
543
|
+
onEdit={props.onEdit}
|
|
544
|
+
/>
|
|
545
|
+
<p className={props.invalid ? css.invalid : css.hint}>
|
|
546
|
+
{props.invalid ? props.invalidLabel : props.hint}
|
|
547
|
+
</p>
|
|
548
|
+
</div>
|
|
549
|
+
)
|
|
550
|
+
}
|
package/src/client/index.ts
CHANGED
|
@@ -24,20 +24,56 @@ import type {} from '@deepseek-ai/dsh-client-locale/client'
|
|
|
24
24
|
// Type-only: pulls the ui-conversation SlotMap merge (the composer tool row).
|
|
25
25
|
import type {} from '@deepseek-ai/dsh-client-ui-conversation/client'
|
|
26
26
|
import type {} from '@deepseek-ai/dsh-client-ui-slots'
|
|
27
|
+
import type { SettingsScopeSpec } from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
28
|
+
// Type-only: pulls the settings-surface Context merge (ctx.settingsScope).
|
|
29
|
+
import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
27
30
|
import { LiangShenLever } from './LiangShenLever.tsx'
|
|
28
31
|
import { LeverController } from './lever-controller.ts'
|
|
32
|
+
import { LiangShenSettingsCard, LiangShenSettingsCardController, type LiangShenSettings } from './LiangShenSettingsCard.tsx'
|
|
29
33
|
import { en, zh, type LiangShenKey } from './locales.ts'
|
|
34
|
+
import { installPluginCard } from './plugin-card-seat.ts'
|
|
30
35
|
|
|
31
36
|
/** Locale namespace this half owns. */
|
|
32
37
|
export const NS = 'liangshen'
|
|
33
38
|
|
|
39
|
+
/** Settings namespace the settings card edits (the Host plugin registers it). */
|
|
40
|
+
export const SETTINGS_NAMESPACE = 'dsh-liangshen'
|
|
41
|
+
|
|
42
|
+
/** Owner share of a plugin card (the section supplies nothing). */
|
|
43
|
+
export interface SettingsPluginItemOwnerProps {
|
|
44
|
+
/** Marker field: card owner props are intentionally empty. */
|
|
45
|
+
children?: never
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
49
|
+
interface SlotMap {
|
|
50
|
+
/**
|
|
51
|
+
* The child slot the Web UI plugin group declares; this card registers into
|
|
52
|
+
* the group instead of the top-level `settings.plugin.item` list. Declared
|
|
53
|
+
* here so this package needs no dependency on the sibling UI package.
|
|
54
|
+
*/
|
|
55
|
+
'web-ui.plugin.item': { kind: 'list'; scope: 'root'; owner: SettingsPluginItemOwnerProps }
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
declare module '@deepseek-ai/cordis' {
|
|
60
|
+
interface Context {
|
|
61
|
+
/**
|
|
62
|
+
* Optional compatibility binder provided by dsh-web-settings; absent when
|
|
63
|
+
* that group plugin is not installed, so callers fall back to the official
|
|
64
|
+
* settings scope.
|
|
65
|
+
*/
|
|
66
|
+
webUiSettings?: { bind<S>(spec: SettingsScopeSpec<S>): import('@deepseek-ai/dsh-client-ui-settings/client').SettingsScope<S> }
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
34
70
|
/**
|
|
35
71
|
* Required client services: the slot registry, locale, sessions, and the roster
|
|
36
72
|
* Remote. Both `remote` and `remote.agentPresets` are declared: the context
|
|
37
73
|
* proxy refuses an uninjected service, and a nested service name does not imply
|
|
38
74
|
* its parent, so reading `ctx.remote.agentPresets` needs `remote` as well.
|
|
39
75
|
*/
|
|
40
|
-
export const inject = ['slots', 'locale', 'sessions', 'remote', 'remote.agentPresets']
|
|
76
|
+
export const inject = ['slots', 'locale', 'sessions', 'settingsScope', 'remote', 'remote.agentPresets']
|
|
41
77
|
|
|
42
78
|
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
43
79
|
interface LocaleNamespaceMap {
|
|
@@ -73,6 +109,29 @@ export function apply(ctx: ClientContext): void {
|
|
|
73
109
|
// view still renders and reports what it knows.
|
|
74
110
|
}
|
|
75
111
|
|
|
112
|
+
// Plugin configuration card: one staged form over the `dsh-liangshen`
|
|
113
|
+
// settings namespace, contributed to the Web UI plugin group beside the
|
|
114
|
+
// remote-access and task-board cards.
|
|
115
|
+
try {
|
|
116
|
+
const binder = ctx.get('webUiSettings') ?? ctx.settingsScope
|
|
117
|
+
const settingsScope = binder.bind<LiangShenSettings>({ namespace: SETTINGS_NAMESPACE })
|
|
118
|
+
const settingsCard = new LiangShenSettingsCardController(settingsScope)
|
|
119
|
+
// Card seat: the family group's list seat, or the official keyed seat of
|
|
120
|
+
// the plugin-configuration tab when the group is not installed (issue #1589).
|
|
121
|
+
installPluginCard(ctx, {
|
|
122
|
+
namespace: SETTINGS_NAMESPACE,
|
|
123
|
+
id: 'liangshen',
|
|
124
|
+
order: 120,
|
|
125
|
+
locale: NS,
|
|
126
|
+
inject: () => settingsCard.inject(),
|
|
127
|
+
component: LiangShenSettingsCard,
|
|
128
|
+
})
|
|
129
|
+
ctx.effect(() => () => { settingsCard.dispose() }, 'liangshen: settings card')
|
|
130
|
+
} catch {
|
|
131
|
+
// A missing settings surface leaves the lever working and the card absent;
|
|
132
|
+
// one unavailable service must not take the browser half down.
|
|
133
|
+
}
|
|
134
|
+
|
|
76
135
|
ctx.slots.inject('conversation.input.right', () => {
|
|
77
136
|
try {
|
|
78
137
|
const unregister = ctx.slots.register({
|