diff --git a/docs/QUICK_REF.md b/docs/QUICK_REF.md index 8b53f5a..fb1332e 100644 --- a/docs/QUICK_REF.md +++ b/docs/QUICK_REF.md @@ -7,7 +7,7 @@ ## 版本速查 ### 当前版本 -`0.1.4` → 下一目标 `0.1.5` ([M2.5](./M2.md)) +`0.1.5` → 下一目标 `0.1.6` ([M2.6](./M2.md)) ### 模块版本范围 diff --git a/docs/README.md b/docs/README.md index 06b8a61..b25c9b7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -65,9 +65,9 @@ M11.10完成 → 1.0.0 (正式发布) ## 当前状态 -**当前版本**: `0.1.4` -**当前进度**: 9/97 (9%) -**下一任务**: [M2.5 图标点击事件](./M2.md#m25-图标点击事件--目标版本-0115) +**当前版本**: `0.1.5` +**当前进度**: 10/97 (10%) +**下一任务**: [M2.6 基础面板组件](./M2.md#m26-基础面板组件--目标版本-0116) --- diff --git a/docs/VERSION.md b/docs/VERSION.md index fcd460a..7ff5c59 100644 --- a/docs/VERSION.md +++ b/docs/VERSION.md @@ -33,7 +33,7 @@ | M2.2 | 0.1.2 | 获取选中文本坐标 | ✅ | 2026-02-09 | | M2.3 | 0.1.3 | 沙拉图标组件 | ✅ | 2026-02-09 | | M2.4 | 0.1.4 | 图标定位显示 | ✅ | 2026-02-09 | -| M2.5 | 0.1.5 | 图标点击事件 | ⬜ | - | +| M2.5 | 0.1.5 | 图标点击事件 | ✅ | 2026-02-09 | | M2.6 | 0.1.6 | 基础面板组件 | ⬜ | - | | M2.7 | 0.1.7 | 面板位置计算 | ⬜ | - | | M2.8 | 0.1.8 | 图标-面板联动 | ⬜ | - | diff --git a/manifest.json b/manifest.json index 92f2ff9..7a9bf84 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "沙拉查词", - "version": "0.1.4", + "version": "0.1.5", "description": "聚合词典划词翻译", "permissions": [ "storage", diff --git a/package.json b/package.json index 6429b17..7778fd2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salad-dict", - "version": "0.1.4", + "version": "0.1.5", "description": "聚合词典划词翻译", "private": true, "type": "module", diff --git a/src/content/components/SaladIcon.js b/src/content/components/SaladIcon.js index dd66d3c..e0352f1 100644 --- a/src/content/components/SaladIcon.js +++ b/src/content/components/SaladIcon.js @@ -12,7 +12,13 @@ const OFFSET_Y = -12; // 图标相对于选中文本的垂直偏移 * 沙拉图标类 */ export class SaladIcon { - constructor() { + /** + * @param {Object} options - 配置选项 + * @param {Function} options.onClick - 点击回调函数 + */ + constructor(options = {}) { + this.options = options; + this.onClick = options.onClick || null; this.element = this.createElement(); } @@ -69,9 +75,14 @@ export class SaladIcon { `; - // 阻止点击事件冒泡(避免触发 document click 导致图标消失) + // 处理图标点击 container.addEventListener('click', (e) => { e.stopPropagation(); + console.log('[SaladDict] Icon clicked'); + + if (this.onClick) { + this.onClick(e); + } }); // 添加到页面 @@ -113,10 +124,12 @@ export class SaladIcon { * 创建并显示沙拉图标 * @param {number} x - X坐标 * @param {number} y - Y坐标 + * @param {Object} options - 配置选项 + * @param {Function} options.onClick - 点击回调函数 * @returns {SaladIcon} 图标实例 */ -export function createSaladIcon(x, y) { - const icon = new SaladIcon(); +export function createSaladIcon(x, y, options = {}) { + const icon = new SaladIcon(options); icon.show(x, y); return icon; } diff --git a/src/content/selection.js b/src/content/selection.js index ce3b452..8a3bc88 100644 --- a/src/content/selection.js +++ b/src/content/selection.js @@ -120,8 +120,14 @@ function showSaladIcon(x, y) { currentIcon = null; } - // 创建新图标 - currentIcon = createSaladIcon(x, y); + // 创建新图标,传入点击回调 + currentIcon = createSaladIcon(x, y, { + onClick: (event) => { + logger.info('Icon click callback triggered'); + // 点击后图标不消失(后续再处理) + } + }); + console.log('[SaladDict] Icon shown at:', x, y); }