@muutot/dsh-session-color 0.2.1 → 0.3.0
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.md +41 -41
- package/README.zh.md +22 -19
- package/client/client.js +293 -204
- package/cordis.patch.yml +7 -7
- package/lib/index.js +3 -3
- package/package.json +5 -3
- package/shared/contract.mjs +11 -0
package/README.md
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
# dsh-session-color
|
|
2
|
-
|
|
3
|
-
Set a custom background color for **individual conversation rows** in the DSH
|
|
4
|
-
workspace sidebar.
|
|
5
|
-
|
|
6
|
-
Right-click a session row → **会话背景色** (Session background color) → pick a
|
|
7
|
-
preset color, or "清除颜色" (Clear). The choice is persisted on the host, so it
|
|
8
|
-
survives restarts and is shared across browsers connecting to the same DSH.
|
|
9
|
-
|
|
10
|
-
## Where colors live
|
|
11
|
-
|
|
12
|
-
`$DSH_HOME/dsh-session-color/colors.json` (default `~/.dsh/dsh-session-color/colors.json`):
|
|
13
|
-
|
|
14
|
-
```json
|
|
15
|
-
{ "01J...": "green", "01K...": "red" }
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
Pure display state — never enters model context or session logs. Delete the file
|
|
19
|
-
to reset everything.
|
|
20
|
-
|
|
21
|
-
## Implementation
|
|
22
|
-
|
|
23
|
-
- Host half (`lib/index.js`): registers the `/dsh-session-color` RPC channel and
|
|
24
|
-
reads/writes `colors.json`.
|
|
25
|
-
- Client half (`client/client.js`): contributes a `target: 'session'` context
|
|
26
|
-
menu with a color submenu, injects a `<style>` keyed by
|
|
27
|
-
`[data-row-key="session:<id>"]`, and calls the RPC.
|
|
28
|
-
- `package.json` declares `dsh.bundle.patch` and `dsh.client` (platform `web`).
|
|
29
|
-
|
|
30
|
-
The client bundle is plain CJS with no JSX, so there is no build step. See
|
|
31
|
-
[README.zh.md](README.zh.md) for the full source-level rationale (DSH 0.2.2-rc.1
|
|
32
|
-
extension points, RPC envelope contract, theme detection, and the `rpc.handle`
|
|
33
|
-
compatibility note).
|
|
34
|
-
|
|
35
|
-
## Develop
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
node test/smoke.mjs
|
|
39
|
-
node test/host.mjs
|
|
40
|
-
node --check lib/index.js && node --check client/client.js
|
|
41
|
-
```
|
|
1
|
+
# dsh-session-color
|
|
2
|
+
|
|
3
|
+
Set a custom background color for **individual conversation rows** in the DSH
|
|
4
|
+
workspace sidebar.
|
|
5
|
+
|
|
6
|
+
Right-click a session row → **会话背景色** (Session background color) → pick a
|
|
7
|
+
preset color, or "清除颜色" (Clear). The choice is persisted on the host, so it
|
|
8
|
+
survives restarts and is shared across browsers connecting to the same DSH.
|
|
9
|
+
|
|
10
|
+
## Where colors live
|
|
11
|
+
|
|
12
|
+
`$DSH_HOME/dsh-session-color/colors.json` (default `~/.dsh/dsh-session-color/colors.json`):
|
|
13
|
+
|
|
14
|
+
```json
|
|
15
|
+
{ "01J...": "green", "01K...": "red" }
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Pure display state — never enters model context or session logs. Delete the file
|
|
19
|
+
to reset everything.
|
|
20
|
+
|
|
21
|
+
## Implementation
|
|
22
|
+
|
|
23
|
+
- Host half (`lib/index.js`): registers the `/dsh-session-color` RPC channel and
|
|
24
|
+
reads/writes `colors.json`.
|
|
25
|
+
- Client half (`client/client.js`): contributes a `target: 'session'` context
|
|
26
|
+
menu with a color submenu, injects a `<style>` keyed by
|
|
27
|
+
`[data-row-key="session:<id>"]`, and calls the RPC.
|
|
28
|
+
- `package.json` declares `dsh.bundle.patch` and `dsh.client` (platform `web`).
|
|
29
|
+
|
|
30
|
+
The client bundle is plain CJS with no JSX, so there is no build step. See
|
|
31
|
+
[README.zh.md](README.zh.md) for the full source-level rationale (DSH 0.2.2-rc.1
|
|
32
|
+
extension points, RPC envelope contract, theme detection, and the `rpc.handle`
|
|
33
|
+
compatibility note).
|
|
34
|
+
|
|
35
|
+
## Develop
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
node test/smoke.mjs
|
|
39
|
+
node test/host.mjs
|
|
40
|
+
node --check lib/index.js && node --check client/client.js
|
|
41
|
+
```
|
package/README.zh.md
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
## 用法
|
|
6
6
|
|
|
7
7
|
在会话行上点右键 → **会话背景色** → 选一个预设色(或「清除颜色」)。
|
|
8
|
+
每个颜色项前有一个小色块(走 DSH 官方 `contextMenu.icon` 扩展点渲染,非自绘)。
|
|
8
9
|
选中即生效,颜色写入主机的配置文件,重启 DSH、换浏览器访问都还在。
|
|
9
10
|
|
|
10
11
|
## 颜色存哪
|
|
@@ -17,25 +18,27 @@
|
|
|
17
18
|
|
|
18
19
|
纯展示状态,不进模型上下文,不写会话日志。想全部清掉,删这个文件即可。
|
|
19
20
|
|
|
20
|
-
##
|
|
21
|
+
## 兼容性(仅官方菜单)
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
**只支持 DSH ≥ 0.2.2-rc.1**(提供 `contextMenus` 服务的版本)。
|
|
24
|
+
菜单一律走官方 `ctx.contextMenus.register({ target: 'session' })`,
|
|
25
|
+
**不提供任何自绘浮层/覆盖层退路**——这是硬性 UI 规则:
|
|
26
|
+
UI 扩展只用宿主官方扩展点,不自己画浮层模拟宿主菜单。
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
- 前端 `inject = ['connection', 'contextMenus', 'slots']`,三者是硬依赖,
|
|
29
|
+
由 Cordis 保证服务就绪后才激活本行;不做存在性探测、不留退路。
|
|
30
|
+
- `package.json` 的 `dsh.client.inject` 同时列
|
|
31
|
+
`@deepseek-ai/dsh-client-connection`、`@deepseek-ai/dsh-client-ui-context-menu`、
|
|
32
|
+
`@deepseek-ai/dsh-client-ui-slots`,保证浏览器模块加载顺序(依赖包先于本插件)。
|
|
33
|
+
- 色块:颜色动作带 `icon: { key, src }`(src 是纯色 SVG 的 data URI,深浅各一份),
|
|
34
|
+
并 `ctx.slots.inject('contextMenu.icon', ...)` 注册一个把 src 渲染成 14×14 `<img>` 的
|
|
35
|
+
组件——与 open-in-app 应用图标同一官方机制,不是自绘浮层。
|
|
36
|
+
`require('react')` / `require('react/jsx-runtime')` 是 baseline 模块,无需 manifest 声明。
|
|
28
37
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
>
|
|
33
|
-
> 0.2.1 没有这个服务,写进去整条 client row 会永远
|
|
34
|
-
> `pending (waiting for service: contextMenus)`,Web 启动审计判为致命错误
|
|
35
|
-
> (`crash-*-web-boot.log`:`web boot: 1 entry did not activate`),
|
|
36
|
-
> 桌面端随后走「禁用全部插件」恢复,把所有插件和 `cordis.patch.yml` 一起清掉。
|
|
37
|
-
> 同理,`package.json` 的 `dsh.client.inject` 里也不能列
|
|
38
|
-
> `@deepseek-ai/dsh-client-ui-context-menu`(0.2.1 里根本没有这个包)。
|
|
38
|
+
> **历史坑(0.2.x 兼容年代踩过,现已不适用)**:早期为兼容没有该服务的 0.2.1,
|
|
39
|
+
> 曾用 `ctx.get('contextMenus')` 运行时探测 + 自绘浮层退路;在 rc.5 上该探测
|
|
40
|
+
> 误判成「无服务」,结果右键直接弹自绘色板而不是官方菜单里的二级选项。
|
|
41
|
+
> 现已按硬规则砍掉全部自绘代码,只走官方菜单,故不再兼容 0.2.1。
|
|
39
42
|
|
|
40
43
|
## 实现要点
|
|
41
44
|
|
|
@@ -52,10 +55,10 @@
|
|
|
52
55
|
- 会话行 DOM 自带 `data-row-key="session:<id>"`(0.2.1-rc.5:
|
|
53
56
|
`dsh-client-ui-workspace/lib/client.js:2276`)。
|
|
54
57
|
CSS 用属性选择器命中,不依赖会随构建变化的 CSS Modules 哈希类名。
|
|
55
|
-
-
|
|
58
|
+
- 会话右键菜单:一律用
|
|
56
59
|
`ctx.contextMenus.register({ target: 'session', ... })`
|
|
57
60
|
(`dsh-client-ui-context-menu/README.zh.md:32-38`),菜单项支持 `children` 子菜单;
|
|
58
|
-
|
|
61
|
+
无自绘退路。
|
|
59
62
|
- 浏览器端 RPC `ctx.connection.rpc.call(channel, endpoint, payload)`
|
|
60
63
|
(`dsh-client-connection/lib/client.browser.js:1212`)。
|
|
61
64
|
|
|
@@ -79,7 +82,7 @@
|
|
|
79
82
|
## 开发
|
|
80
83
|
|
|
81
84
|
```bash
|
|
82
|
-
node test/smoke.mjs # 前端:官方菜单
|
|
85
|
+
node test/smoke.mjs # 前端:官方菜单 / CSS / RPC 信封 / 深浅主题(并断言无自绘代码)
|
|
83
86
|
node test/host.mjs # 宿主:读写落盘 / 输入校验 / 信封 / 404
|
|
84
87
|
node --check lib/index.js && node --check client/client.js
|
|
85
88
|
```
|
package/client/client.js
CHANGED
|
@@ -3,15 +3,13 @@
|
|
|
3
3
|
// 由 dsh-client-modules 通过 /plugins 提供,注册成一条 client row。
|
|
4
4
|
// 纯 CJS factory,不用 React/JSX;导出 { name, inject, apply }。
|
|
5
5
|
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
// "pending (waiting for service: contextMenus)",进而让 web boot 直接失败
|
|
14
|
-
// (crash-*-web-boot.log: "1 entry did not activate"),把整个 profile 拖进恢复模式。
|
|
6
|
+
// 菜单只走一条路:DSH 官方 contextMenus 服务(ctx.contextMenus.register)。
|
|
7
|
+
// 不提供任何自绘浮层/覆盖层退路——用户硬规则:UI 一律用宿主官方扩展点。
|
|
8
|
+
//
|
|
9
|
+
// 颜色项的色块走官方 contextMenu.icon 扩展点(keyed slot):
|
|
10
|
+
// 动作带 icon:{ key, src },注册一个 icon 组件把 src 渲染成 14x14 的 <img>。
|
|
11
|
+
// 与 open-in-app 的应用图标同一官方机制(ContextMenuApplicationIcon),
|
|
12
|
+
// 不是自绘浮层。src 用 data: URI 的纯色 SVG,深浅主题各一份。
|
|
15
13
|
//
|
|
16
14
|
// 契约(源码查证):
|
|
17
15
|
// - 会话行 DOM 自带 data-row-key="session:<id>"
|
|
@@ -19,8 +17,12 @@
|
|
|
19
17
|
// - ctx.connection.rpc.call(channel, endpoint, payload)
|
|
20
18
|
// 返回 full.result = { ok:true, value } / { ok:false, error }。
|
|
21
19
|
// dsh-client-connection/lib/client.browser.js:1212 / :1288-1298
|
|
22
|
-
// - ctx.
|
|
23
|
-
//
|
|
20
|
+
// - ctx.contextMenus.register(...)
|
|
21
|
+
// dsh-client-ui-context-menu/README.zh.md:32-38
|
|
22
|
+
// 会话注册范例 dsh-client-ui-workspace/lib/client.js:133122。
|
|
23
|
+
// - 官方服务由 dsh-client-ui-context-menu 以 ctx.provide('contextMenus', ...) 暴露
|
|
24
|
+
// (dsh-client-ui-context-menu/lib/client.js ~41324);本插件在 inject 里
|
|
25
|
+
// 声明该服务包,保证加载顺序,服务就绪后才激活本行。
|
|
24
26
|
|
|
25
27
|
// 注册 id 必须等于 npm 包名:dsh-client-modules 按包名找 factory,
|
|
26
28
|
// 对不上就「loaded without registering」+ 重拉一次 → duplicate registration。
|
|
@@ -31,11 +33,13 @@ window.__ModuleLoader__.load({
|
|
|
31
33
|
const module = { exports: {} };
|
|
32
34
|
const exports = module.exports;
|
|
33
35
|
|
|
36
|
+
// baseline 模块:官方插件都直接 require,无需在 manifest 里声明。
|
|
37
|
+
const React = require('react');
|
|
38
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
39
|
+
|
|
34
40
|
const RPC_CHANNEL = '/dsh-session-color';
|
|
35
41
|
const ENDPOINTS = { list: 'colors.list', set: 'colors.set' };
|
|
36
42
|
const STYLE_ID = 'dsh-session-color-style';
|
|
37
|
-
const MENU_STYLE_ID = 'dsh-session-color-menu-style';
|
|
38
|
-
const MENU_ID = 'dsh-session-color-menu';
|
|
39
43
|
const ROW_ATTR = 'data-row-key';
|
|
40
44
|
|
|
41
45
|
// 与 shared/contract.mjs 保持一致。
|
|
@@ -52,28 +56,182 @@ window.__ModuleLoader__.load({
|
|
|
52
56
|
];
|
|
53
57
|
|
|
54
58
|
const name = 'dsh-session-color';
|
|
55
|
-
//
|
|
56
|
-
const inject = ['connection'];
|
|
59
|
+
// 官方菜单服务 + slots 都是硬依赖:inject 后由 Cordis 保证服务就绪才激活本行。
|
|
60
|
+
const inject = ['connection', 'contextMenus', 'slots'];
|
|
57
61
|
|
|
58
62
|
const BY_KEY = Object.fromEntries(PALETTE.map((p) => [p.key, p]));
|
|
59
63
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
.
|
|
75
|
-
|
|
76
|
-
|
|
64
|
+
// 自定义色:存储形如 custom:#aabbcc,与 shared/contract.mjs 一致。
|
|
65
|
+
// 自定义色深浅主题都用用户选的同一个 hex(所见即所得)。
|
|
66
|
+
const CUSTOM_KEY_PREFIX = 'custom:';
|
|
67
|
+
const HEX_RE = /^#[0-9a-fA-F]{6}$/;
|
|
68
|
+
|
|
69
|
+
// 右键锚点:contextmenu 事件触发时记录,作为自定义面板的定位基准。
|
|
70
|
+
// 面板要出现在「当初右键会话行」的位置,而不是后来点菜单项的位置。
|
|
71
|
+
let menuAnchor = { x: 0, y: 0 };
|
|
72
|
+
|
|
73
|
+
// 官方 contextMenu.icon 的 key 前缀;每个色块一个稳定 key。
|
|
74
|
+
const ICON_KEY_PREFIX = 'dsh-session-color.swatch.';
|
|
75
|
+
|
|
76
|
+
/** 生成 14x14 纯色圆角色块的 data: SVG(深浅主题各一份)。 */
|
|
77
|
+
function swatchSrc(hex) {
|
|
78
|
+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 14 14"><rect x="0.5" y="0.5" width="13" height="13" rx="3" fill="${hex}" stroke="rgba(127,127,127,.45)"/></svg>`;
|
|
79
|
+
return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 注册到官方 keyed slot 'contextMenu.icon' 的色块组件。
|
|
84
|
+
* 官方把动作的 icon 元数据({ key, src })作为 props.icon 传进来。
|
|
85
|
+
* 用 <img src> 显示,与 open-in-app 的 ContextMenuApplicationIcon 同一机制。
|
|
86
|
+
*/
|
|
87
|
+
function SwatchIcon({ icon }) {
|
|
88
|
+
return icon && icon.src
|
|
89
|
+
? jsxRuntime.jsx('img', { src: icon.src, width: 14, height: 14, alt: '', draggable: false })
|
|
90
|
+
: null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 当前打开的取色面板(同时只开一个)。
|
|
94
|
+
let activePicker = null;
|
|
95
|
+
// 由 apply 注入的「清实时预览」函数(预览样式在 apply 作用域里管理)。
|
|
96
|
+
let clearPickerPreview = () => {};
|
|
97
|
+
|
|
98
|
+
function closePicker() {
|
|
99
|
+
if (!activePicker) return;
|
|
100
|
+
const { panel, onKey, onOutside, onClose } = activePicker;
|
|
101
|
+
document.removeEventListener('keydown', onKey, true);
|
|
102
|
+
document.removeEventListener('pointerdown', onOutside, true);
|
|
103
|
+
if (panel.parentNode) panel.parentNode.removeChild(panel);
|
|
104
|
+
activePicker = null;
|
|
105
|
+
if (onClose) onClose(); // 清掉实时预览样式(确定/取消/Esc 都会走这里)。
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 自绘取色面板(Muu 2026-11-22 明确授权破例:原生取色器位置被浏览器锁死左上角,
|
|
110
|
+
* 无法改;contextMenu.content 的 session key 又被 workspace 占用,官方无取色组件)。
|
|
111
|
+
*
|
|
112
|
+
* 定位:锚定 menuAnchor(当初右键会话行的位置),贴近右键处弹出。
|
|
113
|
+
* 取色器:面板内嵌原生 <input type="color"> 作色盘——点它弹出的系统色盘位置
|
|
114
|
+
* 由浏览器定(无所谓),但选完的颜色同步进 hex 框,用户在面板内完成取色。
|
|
115
|
+
* 确认口径:只有点面板里的「确定」才 onPick 落盘;点取消/外部/Esc 都不落盘——
|
|
116
|
+
* 彻底解决「随便点一下就确认」。
|
|
117
|
+
*/
|
|
118
|
+
function openCustomPicker(currentHex, onPick, onPreview) {
|
|
119
|
+
closePicker();
|
|
120
|
+
const initial = HEX_RE.test(currentHex || '') ? currentHex : '#dbe8fb';
|
|
121
|
+
const dark = isDark();
|
|
122
|
+
const panel = document.createElement('div');
|
|
123
|
+
panel.id = 'dsh-session-color-picker';
|
|
124
|
+
Object.assign(panel.style, {
|
|
125
|
+
position: 'fixed',
|
|
126
|
+
left: `${Math.max(8, Math.min(menuAnchor.x, window.innerWidth - 236))}px`,
|
|
127
|
+
top: `${Math.max(8, Math.min(menuAnchor.y, window.innerHeight - 168))}px`,
|
|
128
|
+
zIndex: '2147483001',
|
|
129
|
+
background: dark ? '#22252a' : '#ffffff',
|
|
130
|
+
color: dark ? '#e9ebee' : '#1f2329',
|
|
131
|
+
border: '1px solid rgba(127,127,127,.35)',
|
|
132
|
+
borderRadius: '10px',
|
|
133
|
+
boxShadow: '0 10px 30px rgba(0,0,0,.25)',
|
|
134
|
+
padding: '12px',
|
|
135
|
+
width: '228px',
|
|
136
|
+
boxSizing: 'border-box',
|
|
137
|
+
font: '13px/1.4 system-ui,-apple-system,"Segoe UI",sans-serif',
|
|
138
|
+
userSelect: 'none',
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const hint = document.createElement('div');
|
|
142
|
+
hint.textContent = '自定义背景色(输入 #RRGGBB)';
|
|
143
|
+
hint.style.cssText = 'opacity:.75;margin-bottom:8px;font-size:12px';
|
|
144
|
+
panel.appendChild(hint);
|
|
145
|
+
|
|
146
|
+
const row = document.createElement('div');
|
|
147
|
+
row.style.cssText = 'display:flex;gap:8px;align-items:center';
|
|
148
|
+
// 原生取色器控件:点它打开系统色盘,选完同步到 hex 框(面板是主 UI,色盘只是取色手段)。
|
|
149
|
+
const colorInput = document.createElement('input');
|
|
150
|
+
colorInput.type = 'color';
|
|
151
|
+
colorInput.value = initial;
|
|
152
|
+
colorInput.title = '点此打开取色器';
|
|
153
|
+
Object.assign(colorInput.style, {
|
|
154
|
+
width: '30px', height: '28px', flex: 'none', padding: '0',
|
|
155
|
+
border: '1px solid rgba(127,127,127,.45)', borderRadius: '6px',
|
|
156
|
+
background: 'transparent', cursor: 'pointer',
|
|
157
|
+
});
|
|
158
|
+
const preview = colorInput; // 预览即取色控件本身,随 hex 同步。
|
|
159
|
+
const hexInput = document.createElement('input');
|
|
160
|
+
hexInput.type = 'text';
|
|
161
|
+
hexInput.value = initial;
|
|
162
|
+
hexInput.maxLength = 7;
|
|
163
|
+
hexInput.setAttribute('aria-label', '颜色十六进制值');
|
|
164
|
+
Object.assign(hexInput.style, {
|
|
165
|
+
flex: '1', minWidth: '0', padding: '5px 7px', borderRadius: '6px',
|
|
166
|
+
border: '1px solid rgba(127,127,127,.4)',
|
|
167
|
+
background: dark ? '#2a2d33' : '#fafafa',
|
|
168
|
+
color: dark ? '#e9ebee' : '#1f2329',
|
|
169
|
+
font: '13px ui-monospace,SFMono-Regular,Consolas,monospace',
|
|
170
|
+
});
|
|
171
|
+
const syncFromInput = () => {
|
|
172
|
+
const v = hexInput.value.trim();
|
|
173
|
+
if (HEX_RE.test(v)) {
|
|
174
|
+
colorInput.value = v;
|
|
175
|
+
hexInput.style.borderColor = 'rgba(127,127,127,.4)';
|
|
176
|
+
if (onPreview) onPreview(v); // 实时预览到会话行(不落盘)。
|
|
177
|
+
return v;
|
|
178
|
+
}
|
|
179
|
+
hexInput.style.borderColor = '#e55';
|
|
180
|
+
return null;
|
|
181
|
+
};
|
|
182
|
+
hexInput.addEventListener('input', syncFromInput);
|
|
183
|
+
// 系统色盘拖动/选完 → 同步到 hex 框并实时预览会话行(落盘仍只在点「确定」)。
|
|
184
|
+
colorInput.addEventListener('input', () => { hexInput.value = colorInput.value; syncFromInput(); });
|
|
185
|
+
colorInput.addEventListener('change', () => { hexInput.value = colorInput.value; syncFromInput(); });
|
|
186
|
+
row.appendChild(preview);
|
|
187
|
+
row.appendChild(hexInput);
|
|
188
|
+
panel.appendChild(row);
|
|
189
|
+
|
|
190
|
+
// 按钮行:取消 / 确定。只有「确定」落盘。
|
|
191
|
+
const btns = document.createElement('div');
|
|
192
|
+
btns.style.cssText = 'display:flex;justify-content:flex-end;gap:8px;margin-top:10px';
|
|
193
|
+
const mkBtn = (text, primary) => {
|
|
194
|
+
const b = document.createElement('button');
|
|
195
|
+
b.type = 'button';
|
|
196
|
+
b.textContent = text;
|
|
197
|
+
Object.assign(b.style, {
|
|
198
|
+
padding: '4px 12px', borderRadius: '6px', cursor: 'default',
|
|
199
|
+
border: primary ? 'none' : '1px solid rgba(127,127,127,.4)',
|
|
200
|
+
background: primary ? '#3a7afe' : (dark ? '#2a2d33' : '#fafafa'),
|
|
201
|
+
color: primary ? '#fff' : (dark ? '#e9ebee' : '#1f2329'),
|
|
202
|
+
font: '13px system-ui,sans-serif',
|
|
203
|
+
});
|
|
204
|
+
return b;
|
|
205
|
+
};
|
|
206
|
+
const cancel = mkBtn('取消', false);
|
|
207
|
+
const ok = mkBtn('确定', true);
|
|
208
|
+
cancel.addEventListener('click', closePicker);
|
|
209
|
+
ok.addEventListener('click', () => {
|
|
210
|
+
const picked = syncFromInput();
|
|
211
|
+
if (!picked) return;
|
|
212
|
+
closePicker();
|
|
213
|
+
onPick(picked);
|
|
214
|
+
});
|
|
215
|
+
btns.appendChild(cancel);
|
|
216
|
+
btns.appendChild(ok);
|
|
217
|
+
panel.appendChild(btns);
|
|
218
|
+
|
|
219
|
+
document.body.appendChild(panel);
|
|
220
|
+
hexInput.focus();
|
|
221
|
+
hexInput.select();
|
|
222
|
+
|
|
223
|
+
// 点面板外 / Esc 关闭,均不落盘。
|
|
224
|
+
const onKey = (e) => { if (e.key === 'Escape') closePicker(); };
|
|
225
|
+
const onOutside = (e) => { if (!panel.contains(e.target)) closePicker(); };
|
|
226
|
+
activePicker = { panel, onKey, onOutside, onClose: clearPickerPreview };
|
|
227
|
+
// 延迟挂监听,避免打开这一次点击立即触发 onOutside 关闭。
|
|
228
|
+
setTimeout(() => {
|
|
229
|
+
if (activePicker && activePicker.panel === panel) {
|
|
230
|
+
document.addEventListener('keydown', onKey, true);
|
|
231
|
+
document.addEventListener('pointerdown', onOutside, true);
|
|
232
|
+
}
|
|
233
|
+
}, 0);
|
|
234
|
+
}
|
|
77
235
|
|
|
78
236
|
/**
|
|
79
237
|
* 当前是否深色主题。
|
|
@@ -102,13 +260,23 @@ window.__ModuleLoader__.load({
|
|
|
102
260
|
});
|
|
103
261
|
}
|
|
104
262
|
|
|
263
|
+
/** key → 背景色值;预设按深浅取色,自定义色两主题同值。 */
|
|
264
|
+
function bgFor(key) {
|
|
265
|
+
if (typeof key !== 'string') return null;
|
|
266
|
+
if (key.startsWith(CUSTOM_KEY_PREFIX)) {
|
|
267
|
+
const hex = key.slice(CUSTOM_KEY_PREFIX.length);
|
|
268
|
+
return HEX_RE.test(hex) ? hex : null;
|
|
269
|
+
}
|
|
270
|
+
const entry = BY_KEY[key];
|
|
271
|
+
if (!entry) return null;
|
|
272
|
+
return isDark() ? entry.dark : entry.color;
|
|
273
|
+
}
|
|
274
|
+
|
|
105
275
|
function buildCss(colors) {
|
|
106
|
-
const dark = isDark();
|
|
107
276
|
const lines = [];
|
|
108
277
|
for (const [id, key] of Object.entries(colors)) {
|
|
109
|
-
const
|
|
110
|
-
if (!
|
|
111
|
-
const bg = dark ? entry.dark : entry.color;
|
|
278
|
+
const bg = bgFor(key);
|
|
279
|
+
if (!bg) continue;
|
|
112
280
|
lines.push(`[${ROW_ATTR}="session:${cssEscape(id)}"]{background-color:${bg} !important;}`);
|
|
113
281
|
}
|
|
114
282
|
return lines.join('\n');
|
|
@@ -125,150 +293,52 @@ window.__ModuleLoader__.load({
|
|
|
125
293
|
return style;
|
|
126
294
|
}
|
|
127
295
|
|
|
128
|
-
function ensureMenuStyle() {
|
|
129
|
-
let style = document.getElementById(MENU_STYLE_ID);
|
|
130
|
-
if (!style) {
|
|
131
|
-
style = document.createElement('style');
|
|
132
|
-
style.id = MENU_STYLE_ID;
|
|
133
|
-
style.setAttribute('data-plugin-css', 'dsh-session-color-menu');
|
|
134
|
-
style.textContent = MENU_CSS;
|
|
135
|
-
document.head.appendChild(style);
|
|
136
|
-
}
|
|
137
|
-
return style;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* 自绘右键菜单:0.2.1 及更早没有 contextMenus 服务时的退路。
|
|
142
|
-
* 只认 [data-row-key="session:<id>"] 的行,不猜类名。
|
|
143
|
-
* @returns disposer,移除监听、浮层与样式。
|
|
144
|
-
*/
|
|
145
|
-
function installDomMenu(state, setColor) {
|
|
146
|
-
ensureMenuStyle();
|
|
147
|
-
let menu = null;
|
|
148
|
-
|
|
149
|
-
const close = () => {
|
|
150
|
-
if (menu && menu.parentNode) menu.parentNode.removeChild(menu);
|
|
151
|
-
menu = null;
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
const item = (label, swatchColor, active, onClick) => {
|
|
155
|
-
const row = document.createElement('div');
|
|
156
|
-
row.className = 'dsc-item';
|
|
157
|
-
row.setAttribute('role', 'menuitem');
|
|
158
|
-
|
|
159
|
-
if (swatchColor) {
|
|
160
|
-
const sw = document.createElement('span');
|
|
161
|
-
sw.className = 'dsc-sw';
|
|
162
|
-
sw.style.background = swatchColor;
|
|
163
|
-
row.appendChild(sw);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const text = document.createElement('span');
|
|
167
|
-
text.className = 'dsc-label';
|
|
168
|
-
text.textContent = label;
|
|
169
|
-
row.appendChild(text);
|
|
170
|
-
|
|
171
|
-
const check = document.createElement('span');
|
|
172
|
-
check.className = 'dsc-check';
|
|
173
|
-
check.textContent = active ? '✓' : '';
|
|
174
|
-
row.appendChild(check);
|
|
175
|
-
|
|
176
|
-
row.addEventListener('mousedown', (event) => event.stopPropagation());
|
|
177
|
-
row.addEventListener('click', (event) => {
|
|
178
|
-
event.stopPropagation();
|
|
179
|
-
event.preventDefault();
|
|
180
|
-
close();
|
|
181
|
-
onClick();
|
|
182
|
-
});
|
|
183
|
-
return row;
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
const open = (sessionId, x, y) => {
|
|
187
|
-
close();
|
|
188
|
-
const dark = isDark();
|
|
189
|
-
const current = state.colors[sessionId];
|
|
190
|
-
|
|
191
|
-
const box = document.createElement('div');
|
|
192
|
-
box.id = MENU_ID;
|
|
193
|
-
box.className = `dsc-menu ${dark ? 'dsc-dark' : 'dsc-light'}`;
|
|
194
|
-
box.setAttribute('role', 'menu');
|
|
195
|
-
|
|
196
|
-
for (const p of PALETTE) {
|
|
197
|
-
box.appendChild(item(p.label, dark ? p.dark : p.color, current === p.key, () => {
|
|
198
|
-
setColor(sessionId, p.key);
|
|
199
|
-
}));
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
const sep = document.createElement('div');
|
|
203
|
-
sep.className = 'dsc-sep';
|
|
204
|
-
box.appendChild(sep);
|
|
205
|
-
box.appendChild(item('清除颜色', null, current === undefined, () => {
|
|
206
|
-
setColor(sessionId, null);
|
|
207
|
-
}));
|
|
208
|
-
|
|
209
|
-
// 先挂到 body 再量尺寸,避免读到 0 宽高。
|
|
210
|
-
box.style.left = '0px';
|
|
211
|
-
box.style.top = '0px';
|
|
212
|
-
document.body.appendChild(box);
|
|
213
|
-
menu = box;
|
|
214
|
-
|
|
215
|
-
const rect = box.getBoundingClientRect();
|
|
216
|
-
const margin = 8;
|
|
217
|
-
const left = Math.max(margin, Math.min(x, window.innerWidth - rect.width - margin));
|
|
218
|
-
const top = Math.max(margin, Math.min(y, window.innerHeight - rect.height - margin));
|
|
219
|
-
box.style.left = `${left}px`;
|
|
220
|
-
box.style.top = `${top}px`;
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
const onContextMenu = (event) => {
|
|
224
|
-
const target = event.target;
|
|
225
|
-
const row = target && typeof target.closest === 'function'
|
|
226
|
-
? target.closest(`[${ROW_ATTR}]`) : null;
|
|
227
|
-
if (!row) return;
|
|
228
|
-
const key = row.getAttribute(ROW_ATTR) || '';
|
|
229
|
-
if (!key.startsWith('session:')) return;
|
|
230
|
-
event.preventDefault();
|
|
231
|
-
event.stopPropagation();
|
|
232
|
-
open(key.slice('session:'.length), event.clientX, event.clientY);
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
const onMouseDown = (event) => {
|
|
236
|
-
if (menu && !menu.contains(event.target)) close();
|
|
237
|
-
};
|
|
238
|
-
const onKeyDown = (event) => {
|
|
239
|
-
if (event.key === 'Escape') close();
|
|
240
|
-
};
|
|
241
|
-
const onViewportChange = () => close();
|
|
242
|
-
|
|
243
|
-
document.addEventListener('contextmenu', onContextMenu, true);
|
|
244
|
-
document.addEventListener('mousedown', onMouseDown, true);
|
|
245
|
-
document.addEventListener('keydown', onKeyDown, true);
|
|
246
|
-
window.addEventListener('resize', onViewportChange);
|
|
247
|
-
window.addEventListener('blur', onViewportChange);
|
|
248
|
-
window.addEventListener('scroll', onViewportChange, true);
|
|
249
|
-
|
|
250
|
-
return () => {
|
|
251
|
-
close();
|
|
252
|
-
document.removeEventListener('contextmenu', onContextMenu, true);
|
|
253
|
-
document.removeEventListener('mousedown', onMouseDown, true);
|
|
254
|
-
document.removeEventListener('keydown', onKeyDown, true);
|
|
255
|
-
window.removeEventListener('resize', onViewportChange);
|
|
256
|
-
window.removeEventListener('blur', onViewportChange);
|
|
257
|
-
window.removeEventListener('scroll', onViewportChange, true);
|
|
258
|
-
const style = document.getElementById(MENU_STYLE_ID);
|
|
259
|
-
if (style && style.parentNode) style.parentNode.removeChild(style);
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
|
|
263
296
|
function apply(ctx) {
|
|
264
297
|
const state = { colors: {} };
|
|
265
298
|
let disposed = false;
|
|
266
299
|
const style = ensureStyle();
|
|
267
300
|
|
|
301
|
+
// 记录右键锚点:菜单项 run() 拿不到事件对象,用 capture 阶段的 contextmenu
|
|
302
|
+
// 记下当初右键的位置,供自定义面板定位在「右键处」而非菜单项处。
|
|
303
|
+
ctx.effect(() => {
|
|
304
|
+
const onContextMenu = (e) => {
|
|
305
|
+
if (typeof e.clientX === 'number' && typeof e.clientY === 'number') {
|
|
306
|
+
menuAnchor = { x: e.clientX, y: e.clientY };
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
document.addEventListener('contextmenu', onContextMenu, true);
|
|
310
|
+
return () => document.removeEventListener('contextmenu', onContextMenu, true);
|
|
311
|
+
}, 'dsh-session-color: contextmenu anchor');
|
|
312
|
+
|
|
268
313
|
const render = () => {
|
|
269
314
|
if (!disposed) style.textContent = buildCss(state.colors);
|
|
270
315
|
};
|
|
271
316
|
|
|
317
|
+
// 实时预览:系统取色器拖动改色时,把颜色临时写到会话行(不改 state、不落盘)。
|
|
318
|
+
// 用独立 <style> 且排在正式样式之后,!important 保证预览覆盖当前已落盘颜色。
|
|
319
|
+
const PREVIEW_STYLE_ID = 'dsh-session-color-preview';
|
|
320
|
+
function getPreviewStyle() {
|
|
321
|
+
let el = document.getElementById(PREVIEW_STYLE_ID);
|
|
322
|
+
if (!el) {
|
|
323
|
+
el = document.createElement('style');
|
|
324
|
+
el.id = PREVIEW_STYLE_ID;
|
|
325
|
+
el.setAttribute('data-plugin-css', 'dsh-session-color-preview');
|
|
326
|
+
document.head.appendChild(el);
|
|
327
|
+
}
|
|
328
|
+
return el;
|
|
329
|
+
}
|
|
330
|
+
const setPreview = (sessionId, hex) => {
|
|
331
|
+
if (disposed) return;
|
|
332
|
+
getPreviewStyle().textContent = HEX_RE.test(hex || '')
|
|
333
|
+
? `[${ROW_ATTR}="session:${cssEscape(sessionId)}"]{background-color:${hex} !important;}`
|
|
334
|
+
: '';
|
|
335
|
+
};
|
|
336
|
+
const clearPreview = () => {
|
|
337
|
+
const el = document.getElementById(PREVIEW_STYLE_ID);
|
|
338
|
+
if (el) el.textContent = '';
|
|
339
|
+
};
|
|
340
|
+
clearPickerPreview = clearPreview;
|
|
341
|
+
|
|
272
342
|
// 主题切换时重算深浅色(DSH 改 body[data-ds-dark-theme])。
|
|
273
343
|
const onThemeChange = () => render();
|
|
274
344
|
const themeObserver = (typeof MutationObserver === 'function')
|
|
@@ -346,38 +416,56 @@ window.__ModuleLoader__.load({
|
|
|
346
416
|
});
|
|
347
417
|
};
|
|
348
418
|
|
|
349
|
-
//
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
419
|
+
// 色块图标:注册到官方 keyed slot,供菜单动作的 icon:{key,src} 取用。
|
|
420
|
+
ctx.effect(() => ctx.slots.inject('contextMenu.icon', () =>
|
|
421
|
+
ctx.slots.register({ name: 'contextMenu.icon', key: ICON_KEY_PREFIX + 'preset' }, SwatchIcon)
|
|
422
|
+
), 'dsh-session-color: menu icon');
|
|
423
|
+
|
|
424
|
+
// 唯一的菜单路径:官方 contextMenus。inject 已保证服务就绪,不做存在性探测,
|
|
425
|
+
// 也没有任何自绘退路。
|
|
426
|
+
ctx.effect(() => ctx.contextMenus.register({
|
|
427
|
+
id: 'dsh-session-color.pick',
|
|
428
|
+
target: 'session',
|
|
429
|
+
order: 500,
|
|
430
|
+
resolve: ({ sessionId }) => {
|
|
431
|
+
const current = state.colors[sessionId];
|
|
432
|
+
const dark = isDark();
|
|
433
|
+
const children = PALETTE.map((p) => ({
|
|
434
|
+
id: p.key,
|
|
435
|
+
label: `${current === p.key ? '✓ ' : ''}${p.label}`,
|
|
436
|
+
// 官方菜单 icon:key 指向上面注册的 slot 条目,src 决定色块颜色。
|
|
437
|
+
icon: { key: ICON_KEY_PREFIX + 'preset', src: swatchSrc(dark ? p.dark : p.color) },
|
|
438
|
+
run: () => setColor(sessionId, p.key),
|
|
439
|
+
}));
|
|
440
|
+
// 当前若为自定义色,勾选项且取色器以该色为初值。
|
|
441
|
+
const customHex = (typeof current === 'string' && current.startsWith(CUSTOM_KEY_PREFIX))
|
|
442
|
+
? current.slice(CUSTOM_KEY_PREFIX.length) : null;
|
|
443
|
+
const rainbow = 'data:image/svg+xml;charset=utf-8,'
|
|
444
|
+
+ encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 14 14"><defs><linearGradient id="g" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#f66"/><stop offset=".5" stop-color="#6c6"/><stop offset="1" stop-color="#68f"/></linearGradient></defs><rect x="0.5" y="0.5" width="13" height="13" rx="3" fill="url(#g)"/></svg>');
|
|
445
|
+
children.push({
|
|
446
|
+
id: 'custom',
|
|
447
|
+
label: `${customHex ? '✓ ' : ''}自定义颜色…`,
|
|
448
|
+
icon: { key: ICON_KEY_PREFIX + 'preset', src: rainbow },
|
|
449
|
+
run: () => openCustomPicker(
|
|
450
|
+
customHex,
|
|
451
|
+
(hex) => setColor(sessionId, CUSTOM_KEY_PREFIX + hex),
|
|
452
|
+
(hex) => setPreview(sessionId, hex),
|
|
453
|
+
),
|
|
454
|
+
});
|
|
455
|
+
children.push({
|
|
456
|
+
id: 'clear',
|
|
457
|
+
label: `${current === undefined ? '✓ ' : ''}清除颜色`,
|
|
458
|
+
separatorBefore: true,
|
|
459
|
+
run: () => setColor(sessionId, null),
|
|
460
|
+
});
|
|
461
|
+
return [{
|
|
462
|
+
id: 'background',
|
|
463
|
+
label: '会话背景色',
|
|
464
|
+
separatorBefore: true,
|
|
465
|
+
children,
|
|
466
|
+
}];
|
|
467
|
+
},
|
|
468
|
+
}), 'dsh-session-color: context menu');
|
|
381
469
|
|
|
382
470
|
// 会话列表异步渲染时重刷样式。
|
|
383
471
|
ctx.effect(() => {
|
|
@@ -390,8 +478,9 @@ window.__ModuleLoader__.load({
|
|
|
390
478
|
// 插件停用时回收 <style> 与监听器。
|
|
391
479
|
ctx.effect(() => () => {
|
|
392
480
|
disposed = true;
|
|
481
|
+
closePicker();
|
|
393
482
|
if (themeObserver) themeObserver.disconnect();
|
|
394
|
-
for (const id of [STYLE_ID,
|
|
483
|
+
for (const id of [STYLE_ID, PREVIEW_STYLE_ID]) {
|
|
395
484
|
const el = document.getElementById(id);
|
|
396
485
|
if (el && el.parentNode) el.parentNode.removeChild(el);
|
|
397
486
|
}
|
package/cordis.patch.yml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
# @muutot/dsh-session-color bundle patch(dsh.bundle manifest 要求的加载配置)
|
|
2
|
-
# 单包单插件:宿主半侧提供 RPC + 颜色持久化,dsh.client 声明让 Web 应用加载 ./client。
|
|
3
|
-
# id 保持裸名 dsh-session-color:它是入口 id / 设置命名空间 / RPC 路由前缀,改了会丢历史数据;
|
|
4
|
-
# 只有 name(node_modules 里解析的包名)带 @muutot scope(同 @dmh2002/dsh-connect-qoder 先例)。
|
|
5
|
-
- insert:
|
|
6
|
-
- id: dsh-session-color
|
|
7
|
-
name: '@muutot/dsh-session-color'
|
|
1
|
+
# @muutot/dsh-session-color bundle patch(dsh.bundle manifest 要求的加载配置)
|
|
2
|
+
# 单包单插件:宿主半侧提供 RPC + 颜色持久化,dsh.client 声明让 Web 应用加载 ./client。
|
|
3
|
+
# id 保持裸名 dsh-session-color:它是入口 id / 设置命名空间 / RPC 路由前缀,改了会丢历史数据;
|
|
4
|
+
# 只有 name(node_modules 里解析的包名)带 @muutot scope(同 @dmh2002/dsh-connect-qoder 先例)。
|
|
5
|
+
- insert:
|
|
6
|
+
- id: dsh-session-color
|
|
7
|
+
name: '@muutot/dsh-session-color'
|
package/lib/index.js
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
22
22
|
import { join, dirname } from 'node:path';
|
|
23
23
|
import { homedir } from 'node:os';
|
|
24
|
-
import { RPC_CHANNEL, ENDPOINTS, PALETTE } from '../shared/contract.mjs';
|
|
24
|
+
import { RPC_CHANNEL, ENDPOINTS, PALETTE, isValidColorKey } from '../shared/contract.mjs';
|
|
25
25
|
|
|
26
26
|
const name = 'dsh-session-color';
|
|
27
27
|
const inject = ['connection', 'webServer'];
|
|
@@ -43,7 +43,7 @@ function readColors() {
|
|
|
43
43
|
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return {};
|
|
44
44
|
const clean = {};
|
|
45
45
|
for (const [id, key] of Object.entries(raw)) {
|
|
46
|
-
if (SESSION_ID_RE.test(id) && (key === null ||
|
|
46
|
+
if (SESSION_ID_RE.test(id) && (key === null || isValidColorKey(key, VALID_KEYS))) clean[id] = key;
|
|
47
47
|
}
|
|
48
48
|
return clean;
|
|
49
49
|
} catch {
|
|
@@ -74,7 +74,7 @@ function handleRpc(endpoint, payload) {
|
|
|
74
74
|
if (typeof sessionId !== 'string' || !SESSION_ID_RE.test(sessionId)) {
|
|
75
75
|
throw new Error('invalid sessionId');
|
|
76
76
|
}
|
|
77
|
-
if (key !== null && !
|
|
77
|
+
if (key !== null && !isValidColorKey(key, VALID_KEYS)) {
|
|
78
78
|
throw new Error('invalid color key');
|
|
79
79
|
}
|
|
80
80
|
const colors = readColors();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@muutot/dsh-session-color",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "给 DSH 左侧会话列表里的单条对话换背景色:右键会话 → 选颜色,跨会话/跨设备持久保存。兼容 0.2.1-rc.5(自绘菜单)与 0.2.2+(官方 contextMenus)。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"url": "git+https://github.com/muutot/dsh-session-color.git"
|
|
25
25
|
},
|
|
26
26
|
"engines": {
|
|
27
|
-
"dsh": ">=0.2.
|
|
27
|
+
"dsh": ">=0.2.2-rc.1 <0.3.0-0"
|
|
28
28
|
},
|
|
29
29
|
"dsh": {
|
|
30
30
|
"bundle": {
|
|
@@ -32,7 +32,9 @@
|
|
|
32
32
|
},
|
|
33
33
|
"client": {
|
|
34
34
|
"inject": [
|
|
35
|
-
"@deepseek-ai/dsh-client-connection"
|
|
35
|
+
"@deepseek-ai/dsh-client-connection",
|
|
36
|
+
"@deepseek-ai/dsh-client-ui-context-menu",
|
|
37
|
+
"@deepseek-ai/dsh-client-ui-slots"
|
|
36
38
|
],
|
|
37
39
|
"platform": "web"
|
|
38
40
|
}
|
package/shared/contract.mjs
CHANGED
|
@@ -9,6 +9,17 @@ export const ENDPOINTS = Object.freeze({
|
|
|
9
9
|
set: 'colors.set',
|
|
10
10
|
});
|
|
11
11
|
|
|
12
|
+
/** 自定义色值的 key 前缀:存储形如 custom:#aabbcc。 */
|
|
13
|
+
export const CUSTOM_KEY_PREFIX = 'custom:';
|
|
14
|
+
|
|
15
|
+
/** 合法的自定义色 key:custom: + 6 位十六进制。 */
|
|
16
|
+
export const CUSTOM_KEY_RE = /^custom:#[0-9a-fA-F]{6}$/;
|
|
17
|
+
|
|
18
|
+
/** key 是否为合法色值(预设 key 或自定义色)。 */
|
|
19
|
+
export function isValidColorKey(key, validKeys) {
|
|
20
|
+
return validKeys.has(key) || CUSTOM_KEY_RE.test(key);
|
|
21
|
+
}
|
|
22
|
+
|
|
12
23
|
/** 预设色板。key 用于持久化与菜单项 id,label 为中文显示名。 */
|
|
13
24
|
export const PALETTE = Object.freeze([
|
|
14
25
|
{ key: 'red', label: '红', color: '#fde2e2', dark: '#5c2b2b' },
|