@linxin666/dsh-liangshen 0.4.10 → 0.4.11
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/lib/client.js +326 -138
- package/lib/client.js.map +1 -1
- package/lib/types/client/PluginSettingsCard.d.ts +69 -22
- package/lib/types/client/RangeBubble.d.ts +46 -0
- package/lib/types/client/SegmentGroup.d.ts +28 -0
- package/lib/types/client/locales.d.ts +0 -4
- package/lib/types/client/plugin-card-seat.d.ts +2 -0
- package/lib/types/client/settings-form.d.ts +73 -51
- package/package.json +1 -1
- package/src/client/LiangShenSettingsCard.tsx +1 -0
- package/src/client/PluginSettingsCard.tsx +226 -93
- package/src/client/RangeBubble.tsx +164 -0
- package/src/client/SegmentGroup.tsx +93 -0
- package/src/client/locales.ts +36 -44
- package/src/client/plugin-card-seat.ts +6 -0
- package/src/client/settings-card.module.css +341 -94
- package/src/client/settings-form.ts +102 -60
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// Generated by scripts/sync-shared.mjs from shared/client/settings/SegmentGroup.tsx. Do not edit this copy; edit the shared source and run "node scripts/sync-shared.mjs".
|
|
2
|
+
/**
|
|
3
|
+
* The family's segmented control: a quiet track whose options share one
|
|
4
|
+
* highlight that slides to the pressed option, instead of each option fading
|
|
5
|
+
* its own background out and the next one in. The settings fields' small
|
|
6
|
+
* choices and the Web Extensions TAB strip both render through it, so the two
|
|
7
|
+
* read as one control.
|
|
8
|
+
*
|
|
9
|
+
* The caller builds the option buttons and marks the pressed one with
|
|
10
|
+
* `data-active`; the group measures that button after every render and writes
|
|
11
|
+
* its box as four custom properties, and the stylesheet draws the highlight
|
|
12
|
+
* there (`.segmentGroup[data-pill]::before`). Attribute and first placement
|
|
13
|
+
* land in the same task, so the highlight appears in place and only later
|
|
14
|
+
* changes slide. A ResizeObserver re-measures when the group or an option
|
|
15
|
+
* changes size: a longer locale, a font arriving, a container growing, a
|
|
16
|
+
* strip wrapping onto a second line.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { Children, useLayoutEffect, useRef, type HTMLAttributes, type ReactNode } from 'react'
|
|
20
|
+
import css from './settings-card.module.css'
|
|
21
|
+
|
|
22
|
+
/** The attribute marking a group whose highlight has been placed. */
|
|
23
|
+
const PILL_ATTR = 'data-pill'
|
|
24
|
+
/** The pressed option, relative to the group. */
|
|
25
|
+
const ACTIVE_SELECTOR = ':scope > [data-active]'
|
|
26
|
+
const PILL_PROPERTIES = ['--segment-pill-x', '--segment-pill-y', '--segment-pill-w', '--segment-pill-h'] as const
|
|
27
|
+
|
|
28
|
+
/** Props of {@link SegmentGroup}: the track's own attributes and the option buttons. */
|
|
29
|
+
export interface SegmentGroupProps extends HTMLAttributes<HTMLDivElement> {
|
|
30
|
+
/** The option buttons; the pressed one carries `data-active`. */
|
|
31
|
+
children: ReactNode
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Write the highlight's box from the pressed option's box, or take the
|
|
36
|
+
* highlight off when nothing is pressed or the group has no layout yet.
|
|
37
|
+
* The two boxes are read in viewport pixels and turned back into the group's
|
|
38
|
+
* own CSS pixels, so a dialog that opens through a scale transform still
|
|
39
|
+
* lands the highlight on its option.
|
|
40
|
+
*/
|
|
41
|
+
function placePill(group: HTMLElement): void {
|
|
42
|
+
const item = group.querySelector<HTMLElement>(ACTIVE_SELECTOR)
|
|
43
|
+
const box = group.getBoundingClientRect()
|
|
44
|
+
if (item === null || group.offsetWidth === 0 || box.width === 0) {
|
|
45
|
+
group.removeAttribute(PILL_ATTR)
|
|
46
|
+
for (const property of PILL_PROPERTIES) group.style.removeProperty(property)
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
const scale = box.width / group.offsetWidth
|
|
50
|
+
const itemBox = item.getBoundingClientRect()
|
|
51
|
+
const values = [
|
|
52
|
+
(itemBox.left - box.left) / scale - group.clientLeft,
|
|
53
|
+
(itemBox.top - box.top) / scale - group.clientTop,
|
|
54
|
+
itemBox.width / scale,
|
|
55
|
+
itemBox.height / scale,
|
|
56
|
+
]
|
|
57
|
+
values.forEach((value, index) => {
|
|
58
|
+
group.style.setProperty(PILL_PROPERTIES[index], `${Math.round(value * 100) / 100}px`)
|
|
59
|
+
})
|
|
60
|
+
if (!group.hasAttribute(PILL_ATTR)) group.setAttribute(PILL_ATTR, '')
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Render a segmented track around the caller's option buttons.
|
|
65
|
+
* @param props - the track's attributes (role, accessible name, key handler) and its options.
|
|
66
|
+
* @returns the track.
|
|
67
|
+
*/
|
|
68
|
+
export function SegmentGroup(props: SegmentGroupProps): ReactNode {
|
|
69
|
+
const { children, className, ...rest } = props
|
|
70
|
+
const group = useRef<HTMLDivElement | null>(null)
|
|
71
|
+
const count = Children.count(children)
|
|
72
|
+
|
|
73
|
+
// Placed before the frame is painted, after every render: a press moves the
|
|
74
|
+
// pressed mark and the highlight follows it in the same frame.
|
|
75
|
+
useLayoutEffect(() => {
|
|
76
|
+
if (group.current !== null) placePill(group.current)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
useLayoutEffect(() => {
|
|
80
|
+
const element = group.current
|
|
81
|
+
if (element === null || typeof ResizeObserver === 'undefined') return undefined
|
|
82
|
+
const observer = new ResizeObserver(() => { placePill(element) })
|
|
83
|
+
observer.observe(element)
|
|
84
|
+
for (const item of Array.from(element.children)) observer.observe(item)
|
|
85
|
+
return () => { observer.disconnect() }
|
|
86
|
+
}, [count])
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<div {...rest} ref={group} className={className === undefined ? css.segmentGroup : `${css.segmentGroup} ${className}`}>
|
|
90
|
+
{children}
|
|
91
|
+
</div>
|
|
92
|
+
)
|
|
93
|
+
}
|
package/src/client/locales.ts
CHANGED
|
@@ -22,32 +22,28 @@ export const zh = {
|
|
|
22
22
|
'burst.line1': '三秒,三辈子的代码',
|
|
23
23
|
'burst.line2': '文言文 · 二进制 · 摩斯电码',
|
|
24
24
|
'settings.title': '梁神模式',
|
|
25
|
-
'settings.description': '
|
|
26
|
-
'settings.enabled': '
|
|
27
|
-
'settings.enabledHint': '
|
|
28
|
-
'settings.announceToAgent': '
|
|
29
|
-
'settings.announceToAgentHint': '
|
|
30
|
-
'settings.presentation': '
|
|
31
|
-
'settings.presentationHint': '
|
|
32
|
-
'settings.dispatcher': '
|
|
33
|
-
'settings.dispatcherHint': '
|
|
25
|
+
'settings.description': '梁神模式的开关、工具面与调度身份。',
|
|
26
|
+
'settings.enabled': '总开关',
|
|
27
|
+
'settings.enabledHint': '关掉后不再声明预设。',
|
|
28
|
+
'settings.announceToAgent': '公告给 agent',
|
|
29
|
+
'settings.announceToAgentHint': '每一轮系统提示都带上本插件公告。',
|
|
30
|
+
'settings.presentation': '工具面',
|
|
31
|
+
'settings.presentationHint': 'ptc 把工具收进 run_code,native 保留原生清单。',
|
|
32
|
+
'settings.dispatcher': '调度身份',
|
|
33
|
+
'settings.dispatcherHint': '按调度 Agent 工作:分诊、访谈、派发子代理。',
|
|
34
34
|
'settings.on': '开',
|
|
35
35
|
'settings.off': '关',
|
|
36
|
-
'settings.inherit': '
|
|
37
|
-
'settings.overridden': '
|
|
38
|
-
'settings.reset': '
|
|
39
|
-
'settings.notExposed': '
|
|
40
|
-
'settings.readOnly': '
|
|
36
|
+
'settings.inherit': '继承',
|
|
37
|
+
'settings.overridden': '已修改',
|
|
38
|
+
'settings.reset': '恢复默认',
|
|
39
|
+
'settings.notExposed': '这个版本的 DSH 没有开放梁神模式的设置。',
|
|
40
|
+
'settings.readOnly': '设置只读。',
|
|
41
41
|
'settings.expand': '展开设置',
|
|
42
42
|
'settings.collapse': '收起设置',
|
|
43
|
-
'settings.
|
|
44
|
-
'settings.
|
|
45
|
-
'
|
|
46
|
-
'
|
|
47
|
-
'settings.saveFailed': '部署未接受这些值,已保留供你修改。',
|
|
48
|
-
'settings.invalidValue': '该取值不被接受',
|
|
49
|
-
'presentation.ptc': 'ptc(仅 run_code)',
|
|
50
|
-
'presentation.native': 'native(原生工具清单)',
|
|
43
|
+
'settings.saveFailed': '没有保存成功。',
|
|
44
|
+
'settings.invalidValue': '填一个可用的值。',
|
|
45
|
+
'presentation.ptc': 'ptc',
|
|
46
|
+
'presentation.native': 'native',
|
|
51
47
|
}
|
|
52
48
|
|
|
53
49
|
/** English counterpart; the key set mirrors {@link zh} exactly. */
|
|
@@ -68,32 +64,28 @@ export const en: Record<keyof typeof zh, string> = {
|
|
|
68
64
|
'burst.line1': 'Three seconds, three lifetimes of code',
|
|
69
65
|
'burst.line2': 'Classical Chinese · Binary · Morse code',
|
|
70
66
|
'settings.title': 'LiangShen mode',
|
|
71
|
-
'settings.description': '
|
|
72
|
-
'settings.enabled': '
|
|
73
|
-
'settings.enabledHint': 'When off, the preset is
|
|
74
|
-
'settings.announceToAgent': 'Announce
|
|
75
|
-
'settings.announceToAgentHint': '
|
|
76
|
-
'settings.presentation': 'Wire
|
|
77
|
-
'settings.presentationHint': '
|
|
78
|
-
'settings.dispatcher': 'Dispatcher
|
|
79
|
-
'settings.dispatcherHint': '
|
|
67
|
+
'settings.description': 'The mode switch, the wire presentation and the dispatcher identity.',
|
|
68
|
+
'settings.enabled': 'Master switch',
|
|
69
|
+
'settings.enabledHint': 'When off, the preset is no longer declared.',
|
|
70
|
+
'settings.announceToAgent': 'Announce to agents',
|
|
71
|
+
'settings.announceToAgentHint': 'Every system prompt carries this plugin note.',
|
|
72
|
+
'settings.presentation': 'Wire',
|
|
73
|
+
'settings.presentationHint': 'ptc folds tools into run_code; native keeps the native roster.',
|
|
74
|
+
'settings.dispatcher': 'Dispatcher',
|
|
75
|
+
'settings.dispatcherHint': 'Works as a dispatcher: triage, interview, then dispatch subagents.',
|
|
80
76
|
'settings.on': 'On',
|
|
81
77
|
'settings.off': 'Off',
|
|
82
|
-
'settings.inherit': 'Inherit
|
|
83
|
-
'settings.overridden': '
|
|
84
|
-
'settings.reset': 'Reset',
|
|
85
|
-
'settings.notExposed':
|
|
86
|
-
'settings.readOnly': '
|
|
78
|
+
'settings.inherit': 'Inherit',
|
|
79
|
+
'settings.overridden': 'Changed',
|
|
80
|
+
'settings.reset': 'Reset to default',
|
|
81
|
+
'settings.notExposed': 'This DSH version does not open the LiangShen settings.',
|
|
82
|
+
'settings.readOnly': 'Settings are read-only.',
|
|
87
83
|
'settings.expand': 'Show settings',
|
|
88
84
|
'settings.collapse': 'Hide settings',
|
|
89
|
-
'settings.
|
|
90
|
-
'settings.
|
|
91
|
-
'
|
|
92
|
-
'
|
|
93
|
-
'settings.saveFailed': 'The deployment did not accept these values; they were left for you to correct.',
|
|
94
|
-
'settings.invalidValue': 'The value is not accepted',
|
|
95
|
-
'presentation.ptc': 'ptc (run_code only)',
|
|
96
|
-
'presentation.native': 'native (native tool roster)',
|
|
85
|
+
'settings.saveFailed': 'Not saved.',
|
|
86
|
+
'settings.invalidValue': 'Enter a value this field accepts.',
|
|
87
|
+
'presentation.ptc': 'ptc',
|
|
88
|
+
'presentation.native': 'native',
|
|
97
89
|
}
|
|
98
90
|
|
|
99
91
|
/** Every key in the locale catalog. */
|
|
@@ -52,6 +52,8 @@ export const FAMILY_GROUP_SERVICE = 'webUiSettings'
|
|
|
52
52
|
export interface PluginCardSlots {
|
|
53
53
|
/** Contribution of one card entry. */
|
|
54
54
|
register(options: never, component: never): unknown
|
|
55
|
+
/** Declaration probe: a target seat may appear after this plugin applies. */
|
|
56
|
+
spec?(key: string): unknown
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
/** The slice of the client context a card contribution needs. */
|
|
@@ -154,6 +156,10 @@ export function installPluginCard(ctx: PluginCardContext, seat: PluginCardSeat):
|
|
|
154
156
|
if (reconciling) return
|
|
155
157
|
const target = familyGroupLoaded(ctx) ? FAMILY_PLUGIN_CARD_SEAT : OFFICIAL_PLUGIN_CARD_SEAT
|
|
156
158
|
if (current === target) return
|
|
159
|
+
// The group's child seat can be declared after this card applies (the
|
|
160
|
+
// parent mounts its pages through the extension service). Wait for the
|
|
161
|
+
// declaration instead of logging a refused registration on every boot.
|
|
162
|
+
if (typeof slots.spec === 'function' && slots.spec(target) === undefined) return
|
|
157
163
|
reconciling = true
|
|
158
164
|
const previous = dispose
|
|
159
165
|
dispose = undefined
|