dsh-data-window 0.1.2 → 0.1.3

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/docs/DETAIL.md CHANGED
@@ -107,7 +107,7 @@ bootstrap.yml spring.application.name = demo-order-service
107
107
 
108
108
  | 需求 | 实现 |
109
109
  |---|---|
110
- | 点工作区自动加载配置、缓存地址与账号 | 打开面板即解析工作区 → 环境 → 实例 → 库,结果按工作区缓存;`重新读取配置` 强制刷新 |
110
+ | 点工作区自动加载配置、缓存地址与账号 | 打开面板即解析工作区 → 环境 → 实例 → 库,结果按工作区缓存;资源管理器标题栏的刷新按钮强制重新读取 |
111
111
  | 看到实例、库、表、字段 | 左侧树逐层展开;实例上的网格按钮打开「选择数据库」勾选面板,表可展开字段(类型、主键、NOT NULL、注释) |
112
112
  | 快捷键查看建表语句 | 选中表后按 **F4** 或 **⌘/Ctrl + Shift + D**;也可右键「查看建表语句」;在弹窗里查看并复制,不打开工作标签。右键**库**(或选中库按 F4)则是「查看全部建表语句」:逐表读取,带 `x/y` 进度,失败的表在末尾用注释标出 |
113
113
  | 每个库一个 SQL 工作台 | 点库名打开该库的工作台,标签页常驻 |
@@ -117,9 +117,11 @@ bootstrap.yml spring.application.name = demo-order-service
117
117
  | SQL 高亮 | 关键字、函数、字符串、数字、注释分色显示,颜色跟着深/浅色主题可读 |
118
118
  | 字段提示 | 输入时列出表、字段、关键字;`别名.` 只列该表字段;数据来自 Host 一次性读取的库结构,每库缓存 |
119
119
  | 一键格式化 | 编辑栏「格式化」:子句换行、select 列表一行一项、join 与 and 缩进,关键字大小写保持原样 |
120
- | 运行日志 | 每条执行语句(含总行数刷新用的 `COUNT`)都以 `SQL` 行记入日志,失败语句也会记录 |
120
+ | 运行日志 | 每条执行语句(含总行数刷新用的 `COUNT`)都以 `SQL` 行记入日志,失败语句也会记录;展开后拖动日志顶部的分隔条调整高度(双击还原),高度按浏览器记住 |
121
121
  | 总行数 | 结果栏「共 — 行」旁的刷新按钮按当前语句执行一次 `COUNT(*)`,统计前会去掉最外层的 `LIMIT`(子查询里的保留);只读、按需触发 |
122
122
  | 控制台持久化 | 每个工作区的 SQL 存成 Host 文件(`workspaces/<hash>-<名字>.consoles.json`,0600),切换工作区、刷新或重启后自动恢复;关掉标签即删除;只恢复语句,不恢复结果 |
123
+ | 收藏 SQL | 编辑器或标签页右键「收藏 SQL」:起一个唯一名称,连同库名、表名一起保存;资源管理器顶部的「数据库 / 收藏夹」两个标签页分开显示,收藏页按 库 → 表 → 语句 分组 |
124
+ | `@` 索引收藏 | 工作台输入 `@` 弹出收藏列表(按名称/库名/表名过滤,↑↓ 选择,Enter 或点击插入),选中的 SQL 直接替换光标处的 `@…` |
123
125
  | 设置页 | DSH 设置里独立一页「数据窗口」:进入时收起侧栏、默认行数上限、快捷键与控制台保存位置 |
124
126
  | 全局快捷键 | 默认 `⌘3`(Windows/Linux `Ctrl+3`)在任意界面打开数据窗口;设置页「快捷键」可修改/恢复默认 |
125
127
  | 界面配色 | 跟随 `dsh-ide-window` 选择的主题(同一套 `dsh-theme` 契约);没有选择时跟随 DSH 默认配色 |
@@ -127,6 +129,25 @@ bootstrap.yml spring.application.name = demo-order-service
127
129
  | 调整列表宽度 | 拖动资源管理器与工作台之间的分隔条;双击分隔条恢复默认宽度 |
128
130
  | 进入即全宽 | 进入数据窗口时自动收起 DSH 侧栏;工具栏按钮可随时展开或收起 |
129
131
 
132
+ ## 收藏 SQL 与 `@` 索引
133
+
134
+ 编辑器右键菜单(以及 SQL 标签页右键菜单)里的「收藏 SQL」打开命名弹窗:
135
+
136
+ | 字段 | 说明 |
137
+ |---|---|
138
+ | 名称 | 必填,在收藏夹里唯一(大小写不敏感);也是 `@` 索引时输入的关键字 |
139
+ | 库名 | 从当前工作台带入,可修改;收藏夹按它分组 |
140
+ | 表名 | 可选,留空归入「未指定表」;表控制台或语句里第一个表会自动带入 |
141
+ | SQL | 只读预览:右键时选中的那一段,没选中就是整段语句 |
142
+
143
+ - 保存到 `~/.dsh/storages/dsh-data-window/favorites/favorites.json`(0600,临时文件 + rename 原子写),**全机共享**,和资源树一样不随工作区切换;
144
+ - 资源管理器顶部是 **数据库 / ★ 收藏夹** 两个标签页(同 DataGrip 的 Database 窗口):数据库页是配置解析出来的环境树,收藏页按 **库 → 表 → 语句名称** 分组;收藏页标签带条数角标,右侧有刷新按钮;
145
+ - 保存成功后自动切到收藏页、展开对应的库/表并选中新条目;单击展开目录,双击语句在对应库的工作台打开(树里没有这个库时,运行日志会说明是哪个库);
146
+ - 收藏节点的右键菜单:打开、复制 SQL、编辑收藏(改名/改库名表名)、删除收藏;
147
+ - 工作台输入 `@` 弹出收藏索引:继续输入按名称/库名/表名过滤,↑↓ 移动、Enter 或 Tab 插入、Esc 关闭;插入时把光标处的 `@关键字` 换成整段 SQL,光标停在 SQL 末尾;
148
+ - 输入框与 `@` 索引兼容中文输入法:候选词确认/取消的 Enter、Esc 只交给输入法,不会触发保存、关闭弹窗、插入候选或结束单元格编辑;收藏名称框在 `compositionend` 后 100ms 内的回车也按输入法处理(覆盖把确认回车当普通按键投递的浏览器);
149
+ - 只保存和插入语句,**不会执行**;Host 校验名称、库名与大小上限(单条 128KB,最多 500 条),重名返回 `duplicate-favorite`。
150
+
130
151
  ## 编辑器右键菜单与 AI 优化
131
152
 
132
153
  SQL 编辑器接管了浏览器右键菜单,保留常用编辑动作并多了一项「AI 优化 SQL」:
@@ -134,7 +155,8 @@ SQL 编辑器接管了浏览器右键菜单,保留常用编辑动作并多了
134
155
  | 菜单项 | 行为 |
135
156
  |---|---|
136
157
  | 撤销 / 重做 | 走 textarea 原生历史 |
137
- | 剪切 / 复制 / 粘贴 / 全选 | 异步剪贴板;浏览器拒绝读剪贴板时提示改用 ⌘V |
158
+ | 剪贴/复制/全选 | 异步剪贴板;浏览器拒绝读剪贴板时提示改用 ⌘V |
159
+ | **收藏 SQL** | 把**选中的部分**(没选中则整段)收藏为一条命名 SQL,连同当前库名、表名保存 |
138
160
  | **AI 优化 SQL** | 把**选中的部分**(没选中则整段)交给设置里配置的模型,弹出优化建议 |
139
161
 
140
162
  - 模型来源:设置 → 数据库窗口 → AI 里选的那个(`aiModel`),不是另配一套;
@@ -147,7 +169,7 @@ SQL 编辑器接管了浏览器右键菜单,保留常用编辑动作并多了
147
169
 
148
170
  ## 资源树的点击
149
171
 
150
- 行点击只**选中**,不展开;展开/收起只由行首的三角控制。双击是"打开":库打开控制台并展开,表/视图打开数据,环境/实例展开;实例行右侧的网格按钮仍然打开选库面板。
172
+ 行点击只**选中**,不展开;展开/收起只由行首的三角控制(收藏页的库/表目录是例外:单击即展开或收起,因为它们只用于浏览)。双击是"打开":库打开控制台并展开,表/视图打开数据,环境/实例展开;实例行右侧的网格按钮仍然打开选库面板;双击收藏的 SQL 则在它保存时那个库的工作台打开。
151
173
 
152
174
  ## 标签页右键菜单
153
175
 
@@ -158,6 +180,7 @@ SQL 标签页(库控制台 / 表控制台)右键出菜单:
158
180
  | 关闭 | 关闭当前标签,激活右侧邻居(没有就左侧) |
159
181
  | 关闭其他标签页 / 关闭所有标签页 | 批量关闭,同样把激活位置落到邻居 |
160
182
  | 关闭左侧标签页 / 关闭右侧标签页 | 只关一侧;没有可关的就置灰 |
183
+ | 收藏 SQL | 把整个标签页的语句收藏为一条命名 SQL(选中片段请用编辑器里的右键菜单) |
161
184
  | 复制引用 | 复制 `库.表`(表控制台)或 `库`(库控制台) |
162
185
  | 复制引用到对话 | 先复制,再尝试把引用插入 DSH 对话输入框(`[data-composer-seat]` 的 contenteditable);输入框没打开时只复制并提示 |
163
186
 
package/locale/en.json CHANGED
@@ -7,7 +7,10 @@
7
7
  "openPanel": "Data window",
8
8
  "openPanelHint": "Open the data window",
9
9
  "treeTitle": "Explorer",
10
+ "treeTabsLabel": "Resource manager tabs",
11
+ "treeTabDatabases": "Databases",
10
12
  "filterPlaceholder": "Filter the loaded databases and tables",
13
+ "filterFavoritesPlaceholder": "Filter saved SQL by name, schema or table",
11
14
  "treeLoading": "Loading…",
12
15
  "treeNoMatch": "Nothing matches this filter",
13
16
  "treeEmpty": "No database configuration found for this workspace",
@@ -96,6 +99,7 @@
96
99
  "warning.unparsed-jdbc-url": "A datasource URL could not be parsed as jdbc:mysql.",
97
100
  "projectSwitch": "Switch workspace",
98
101
  "resizeTree": "Drag to resize the list (double-click resets)",
102
+ "resizeLog": "Drag to resize the run log (double-click resets)",
99
103
  "hideSidebar": "Hide the DSH sidebar",
100
104
  "showSidebar": "Show the DSH sidebar",
101
105
  "formatSql": "Format",
@@ -300,5 +304,46 @@
300
304
  "ddlAllEmpty": "This database has no tables",
301
305
  "ddlAllPartial": "{count} table(s) could not be read; noted at the end of the script",
302
306
  "log.ddlAll": "Read all create statements of {database}: {count} tables · {ms}",
303
- "log.copiedDdlAll": "Copied all create statements of {database} ({count} tables)"
307
+ "log.copiedDdlAll": "Copied all create statements of {database} ({count} tables)",
308
+ "favoritesTitle": "Favorites",
309
+ "favoritesCount": "saved",
310
+ "favoritesEmptyHint": "No saved SQL yet. Right-click in the editor and choose “Save SQL”.",
311
+ "favoritesReload": "Reload favorites",
312
+ "favoriteNoTable": "No table",
313
+ "favoriteNoDatabase": "Unknown schema",
314
+ "favoriteSave": "Save SQL",
315
+ "favoriteSaveTitle": "Save SQL",
316
+ "favoriteEditTitle": "Edit saved SQL",
317
+ "favoriteDialogHint": "The schema and table are stored with the statement and group the favorites node; typing @ indexes it by name.",
318
+ "favoriteName": "Name",
319
+ "favoriteNameHint": "Unique among saved SQL, and the keyword used by the @ index",
320
+ "favoriteDatabase": "Schema",
321
+ "favoriteDatabaseHint": "Prefilled from the workbench; editable",
322
+ "favoriteTable": "Table",
323
+ "favoriteTableHint": "Optional; empty goes under “No table”",
324
+ "favoriteSql": "SQL",
325
+ "favoriteSaveAction": "Save",
326
+ "favoriteUpdateAction": "Save changes",
327
+ "favoriteNameRequired": "Give this statement a name first",
328
+ "favoriteDatabaseRequired": "A schema name is required",
329
+ "favoriteMentionLabel": "Saved SQL",
330
+ "favoriteMentionEmpty": "No saved SQL matches",
331
+ "favoriteMentionNoFavorites": "No saved SQL yet: right-click in the editor and choose “Save SQL”",
332
+ "suggestFavorite": "saved",
333
+ "menuOpenFavorite": "Open saved SQL",
334
+ "menuCopyFavoriteSql": "Copy SQL",
335
+ "menuEditFavorite": "Edit saved SQL",
336
+ "menuRemoveFavorite": "Delete saved SQL",
337
+ "removeFavoriteTitle": "Delete saved SQL",
338
+ "removeFavoriteHint": "Delete “{name}”? This cannot be undone.",
339
+ "removeFavoriteConfirm": "Delete",
340
+ "log.favoriteSaved": "Saved SQL: {name} ({database})",
341
+ "log.favoriteRemoved": "Deleted saved SQL: {name}",
342
+ "log.favoriteOpened": "Opened saved SQL: {name}",
343
+ "log.favoriteNoDatabase": "The tree has no schema {database}, so this saved statement cannot be opened",
344
+ "log.favoriteLoadFailed": "Reading saved SQL failed: {message}",
345
+ "log.favoriteInserted": "Inserted saved SQL: {name}",
346
+ "log.favoriteCopied": "Copied saved SQL: {name}",
347
+ "log.favoriteRemoveFailed": "Deleting saved SQL failed: {message}",
348
+ "error.duplicateFavorite": "That name is already taken by another saved statement"
304
349
  }
package/locale/zh.json CHANGED
@@ -7,7 +7,10 @@
7
7
  "openPanel": "数据窗口",
8
8
  "openPanelHint": "打开数据窗口",
9
9
  "treeTitle": "资源管理器",
10
+ "treeTabsLabel": "资源管理标签",
11
+ "treeTabDatabases": "数据库",
10
12
  "filterPlaceholder": "过滤已加载的库名与表名",
13
+ "filterFavoritesPlaceholder": "过滤收藏的名称、库名与表名",
11
14
  "treeLoading": "加载中…",
12
15
  "treeNoMatch": "没有匹配的节点",
13
16
  "treeEmpty": "没有在当前工作区发现数据库配置",
@@ -96,6 +99,7 @@
96
99
  "warning.unparsed-jdbc-url": "有数据源地址无法解析为 jdbc:mysql。",
97
100
  "projectSwitch": "切换工作区",
98
101
  "resizeTree": "拖动调整列表宽度(双击还原)",
102
+ "resizeLog": "拖动调整运行日志高度(双击还原)",
99
103
  "hideSidebar": "隐藏 DSH 侧栏",
100
104
  "showSidebar": "显示 DSH 侧栏",
101
105
  "formatSql": "格式化",
@@ -300,5 +304,46 @@
300
304
  "ddlAllEmpty": "这个库还没有表",
301
305
  "ddlAllPartial": "{count} 张表读取失败,已在脚本末尾用注释标出",
302
306
  "log.ddlAll": "读取 {database} 的全部建表语句:{count} 张表 · {ms}",
303
- "log.copiedDdlAll": "已复制 {database} 的全部建表语句({count} 张表)"
307
+ "log.copiedDdlAll": "已复制 {database} 的全部建表语句({count} 张表)",
308
+ "favoritesTitle": "收藏夹",
309
+ "favoritesCount": "条",
310
+ "favoritesEmptyHint": "还没有收藏 SQL。在编辑器里右键 →「收藏 SQL」即可收藏当前语句。",
311
+ "favoritesReload": "刷新收藏夹",
312
+ "favoriteNoTable": "未指定表",
313
+ "favoriteNoDatabase": "未知库",
314
+ "favoriteSave": "收藏 SQL",
315
+ "favoriteSaveTitle": "收藏 SQL",
316
+ "favoriteEditTitle": "编辑收藏",
317
+ "favoriteDialogHint": "保存时会连同库名与表名一起记录,收藏夹按这两层分组;输入 @ 时用名称索引这条 SQL。",
318
+ "favoriteName": "名称",
319
+ "favoriteNameHint": "名称在收藏夹里唯一,也是 @ 索引时输入的关键字",
320
+ "favoriteDatabase": "库名",
321
+ "favoriteDatabaseHint": "从工作台带入,可修改",
322
+ "favoriteTable": "表名",
323
+ "favoriteTableHint": "可选;留空归入「未指定表」",
324
+ "favoriteSql": "SQL",
325
+ "favoriteSaveAction": "收藏",
326
+ "favoriteUpdateAction": "保存修改",
327
+ "favoriteNameRequired": "请先给这条 SQL 起一个名称",
328
+ "favoriteDatabaseRequired": "请填写库名",
329
+ "favoriteMentionLabel": "收藏的 SQL",
330
+ "favoriteMentionEmpty": "没有匹配的收藏 SQL",
331
+ "favoriteMentionNoFavorites": "还没有收藏 SQL:在编辑器里右键 →「收藏 SQL」",
332
+ "suggestFavorite": "收藏",
333
+ "menuOpenFavorite": "打开收藏的 SQL",
334
+ "menuCopyFavoriteSql": "复制 SQL",
335
+ "menuEditFavorite": "编辑收藏",
336
+ "menuRemoveFavorite": "删除收藏",
337
+ "removeFavoriteTitle": "删除收藏",
338
+ "removeFavoriteHint": "确定删除收藏「{name}」?删除后不可恢复。",
339
+ "removeFavoriteConfirm": "删除",
340
+ "log.favoriteSaved": "已收藏 SQL:{name}({database})",
341
+ "log.favoriteRemoved": "已删除收藏:{name}",
342
+ "log.favoriteOpened": "已打开收藏的 SQL:{name}",
343
+ "log.favoriteNoDatabase": "资源树里没有库 {database},无法打开这条收藏",
344
+ "log.favoriteLoadFailed": "读取收藏夹失败:{message}",
345
+ "log.favoriteInserted": "已插入收藏的 SQL:{name}",
346
+ "log.favoriteCopied": "已复制收藏的 SQL:{name}",
347
+ "log.favoriteRemoveFailed": "删除收藏失败:{message}",
348
+ "error.duplicateFavorite": "这个名称已经被收藏了,请换一个名称"
304
349
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-data-window",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "DataGrip-style database window for DeepSeek Harness: reads the workspace's own config to find the environment hosts, then browses instances, databases, tables and columns and runs read-only SQL in one workbench per database.",
5
5
  "type": "module",
6
6
  "icon": "icon.svg",
@@ -141,6 +141,13 @@ const DW_CSS = `
141
141
  color: var(--dsw-alias-label-primary-inverted, #fff);
142
142
  font-weight: 600;
143
143
  }
144
+ /*
145
+ * The panel and the sidebar-foot action each inject this stylesheet, so the second
146
+ * copy's plain .dw-btn color rule would otherwise override the first copy's accent
147
+ * label and paint white text on the brand fill. The extra class keeps the inverted
148
+ * label winning wherever the rules land.
149
+ */
150
+ .dw-btn.dw-btn-accent { color: var(--dsw-alias-label-primary-inverted, #fff); }
144
151
  .dw-btn-accent:hover { filter: brightness(1.08); background: var(--dsw-alias-brand-primary, #4b8bf5); }
145
152
  .dw-btn-icon { width: 26px; padding: 0; justify-content: center; }
146
153
  /*
@@ -225,6 +232,59 @@ const DW_CSS = `
225
232
  letter-spacing: .04em;
226
233
  text-transform: uppercase;
227
234
  }
235
+ /* The resource manager's tabs: the configured tree and the saved statements. */
236
+ .dw-tree-tabs {
237
+ display: flex;
238
+ align-items: center;
239
+ gap: 2px;
240
+ flex: 0 0 auto;
241
+ padding: 4px 6px 0;
242
+ border-bottom: 1px solid var(--dsw-alias-border-l1, #2c2f36);
243
+ }
244
+ .dw-tree-tab {
245
+ display: inline-flex;
246
+ align-items: center;
247
+ gap: 5px;
248
+ height: 24px;
249
+ padding: 0 8px;
250
+ border: 0;
251
+ border-bottom: 2px solid transparent;
252
+ border-radius: 6px 6px 0 0;
253
+ background: transparent;
254
+ color: var(--dsw-alias-label-secondary, #8b919d);
255
+ font: inherit;
256
+ font-size: 11.5px;
257
+ cursor: pointer;
258
+ white-space: nowrap;
259
+ }
260
+ .dw-tree-tab:hover { background: var(--dsw-alias-interactive-bg-hover, rgba(127, 127, 127, .12)); color: var(--dsw-alias-label-primary, #e6e8ec); }
261
+ .dw-tree-tab.on {
262
+ color: var(--dsw-alias-label-primary, #e6e8ec);
263
+ border-bottom-color: var(--dsw-alias-brand-primary, #4b8bf5);
264
+ }
265
+ .dw-tree-tab-count {
266
+ min-width: 14px;
267
+ padding: 0 4px;
268
+ border-radius: 7px;
269
+ background: var(--dsw-alias-interactive-bg-hover, rgba(127, 127, 127, .12));
270
+ color: var(--dsw-alias-label-secondary, #8b919d);
271
+ font-size: 10px;
272
+ line-height: 14px;
273
+ text-align: center;
274
+ }
275
+ .dw-tree-tabs .dw-btn {
276
+ width: 22px;
277
+ height: 22px;
278
+ padding: 0;
279
+ justify-content: center;
280
+ border-color: transparent;
281
+ background: transparent;
282
+ color: var(--dsw-alias-label-secondary, #8b919d);
283
+ }
284
+ .dw-tree-tabs .dw-btn:hover:not(:disabled) {
285
+ background: var(--dsw-alias-interactive-bg-hover, rgba(127, 127, 127, .12));
286
+ color: var(--dsw-alias-label-primary, #e6e8ec);
287
+ }
228
288
  .dw-tree { flex: 1 1 auto; overflow: auto; padding: 4px 0 12px; }
229
289
  .dw-node {
230
290
  display: flex;
@@ -450,6 +510,32 @@ const DW_CSS = `
450
510
  .dw-complete-label { flex: 1 1 auto; font-family: var(--ds-font-family-code, ui-monospace, Menlo, monospace); font-size: 12px; }
451
511
  .dw-complete-detail { flex: 0 1 auto; max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dsw-alias-label-secondary, #8b919d); font-size: 10.5px; }
452
512
  .dw-complete-kind { flex: 0 0 auto; color: var(--dsw-alias-label-secondary, #8b919d); font-size: 10px; opacity: .8; }
513
+ .dw-complete-empty {
514
+ padding: 6px 9px;
515
+ max-width: 300px;
516
+ color: var(--dsw-alias-label-secondary, #8b919d);
517
+ font-size: 11.5px;
518
+ line-height: 1.55;
519
+ }
520
+ /* The at-sign index: statements, so a little wider than the column list. */
521
+ .dw-mention { min-width: 280px; max-width: 420px; }
522
+ .dw-fav-sql {
523
+ margin: 0;
524
+ max-height: 170px;
525
+ overflow: auto;
526
+ padding: 8px 10px;
527
+ border: 1px solid var(--dsw-alias-border-l1, #31353d);
528
+ border-radius: 6px;
529
+ background: var(--dsw-alias-bg-layer-2, #262930);
530
+ color: var(--dsw-alias-label-primary, #e6e8ec);
531
+ font-family: var(--ds-font-family-code, ui-monospace, Menlo, monospace);
532
+ font-size: 11.5px;
533
+ line-height: 1.55;
534
+ white-space: pre;
535
+ }
536
+ .dw-fav-dialog { width: min(620px, 100%); }
537
+ .dw-fav-split { display: flex; gap: 10px; }
538
+ .dw-fav-split .dw-form-row { flex: 1 1 0; min-width: 0; }
453
539
 
454
540
  .dw-drag {
455
541
  height: 5px;
@@ -84,6 +84,8 @@ function DwIcon({ name, size = 14, className }) {
84
84
  h('circle', { key: 'a', cx: 8, cy: 8, r: 2.4 }),
85
85
  h('path', { key: 'b', d: 'M10.4 8v1.4a2.1 2.1 0 0 0 4.2 0V8A6.4 6.4 0 1 0 8 14.4c1.2 0 2.2-.2 3-.7' }),
86
86
  ])
87
+ case 'star':
88
+ return h('svg', common, [h('path', { d: 'M8 2.1l1.82 3.69 4.07.59-2.94 2.87.69 4.06L8 11.4l-3.64 1.91.69-4.06L2.11 6.38l4.07-.59z' })])
87
89
  case 'close':
88
90
  return h('svg', common, [h('path', { d: 'M4.2 4.2l7.6 7.6M11.8 4.2l-7.6 7.6' })])
89
91
  case 'download':
@@ -134,6 +134,20 @@ function dwLogEntry(level, text) {
134
134
  return { id: `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`, at: new Date(), level, text }
135
135
  }
136
136
 
137
+ /**
138
+ * Whether a key event belongs to an input-method composition.
139
+ *
140
+ * The Enter/Escape that picks or cancels a Chinese or Japanese candidate belongs
141
+ * to the IME, not to this window: it must never submit a dialog, blur a cell or
142
+ * pick a suggestion. Chromium marks those events with `isComposing` and the legacy
143
+ * 229 keyCode; React's synthetic keyboard event does not expose `isComposing`, so
144
+ * the native event is what is checked.
145
+ */
146
+ function dwImeComposing(event) {
147
+ const native = event?.nativeEvent ?? event
148
+ return native?.isComposing === true || (native?.keyCode ?? event?.keyCode) === 229
149
+ }
150
+
137
151
  /**
138
152
  * Turn a Host failure into a sentence.
139
153
  *
@@ -157,6 +171,7 @@ function dwExplainFailure(translate, error) {
157
171
  'ER_QUERY_INTERRUPTED': 'error.interrupted',
158
172
  'manual-connect-failed': 'error.manualConnectFailed',
159
173
  'saved-connection-missing': 'error.savedConnectionMissing',
174
+ 'duplicate-favorite': 'error.duplicateFavorite',
160
175
  }
161
176
  const key = known[code]
162
177
  if (key !== undefined) {
@@ -228,6 +243,19 @@ const DW_CONSOLE_KEY = 'dsh-data-window:consoles'
228
243
  /** Client-side preferences edited in the plugin's settings section. */
229
244
  const DW_PREFS_KEY = 'dsh-data-window:prefs'
230
245
 
246
+ /** Which side-panel tab was last shown: the database tree or the favorites list. */
247
+ const DW_TREE_TAB_KEY = 'dsh-data-window:tree-tab'
248
+
249
+ /** The remembered side-panel tab; unknown or blocked storage means the tree. */
250
+ function dwReadTreeTab() {
251
+ try {
252
+ return globalThis.localStorage?.getItem(DW_TREE_TAB_KEY) === 'favorites' ? 'favorites' : 'databases'
253
+ } catch (error) {
254
+ void error
255
+ return 'databases'
256
+ }
257
+ }
258
+
231
259
  /** Read the display preferences, tolerating a blocked storage. */
232
260
  function dwReadPrefs() {
233
261
  const fallback = { autoHideSidebar: true, defaultLimit: 0, shortcutOpen: null, aiModel: null }
@@ -329,6 +357,9 @@ function dwCreateStore(translate) {
329
357
  aiRunning: false,
330
358
  // tree
331
359
  filter: '',
360
+ // The resource manager has two tabs, like DataGrip's Database window: the
361
+ // configured tree and the saved statements. Both read the same filter.
362
+ treeTab: dwReadTreeTab(),
332
363
  expanded: new Set(),
333
364
  loadState: new Map(),
334
365
  children: new Map(),
@@ -340,6 +371,11 @@ function dwCreateStore(translate) {
340
371
  // Table/column maps for the editor's completion, one per database.
341
372
  schemas: new Map(),
342
373
  limit: DW_DEFAULT_LIMIT,
374
+ // Saved statements (machine-wide, not per workspace) and the `@` index they
375
+ // feed; the tree's favorites node is rendered from this list.
376
+ favorites: [],
377
+ favoritesLoading: false,
378
+ favoritesError: '',
343
379
  // log
344
380
  logOpen: false,
345
381
  log: [dwLogEntry('info', t('log.ready'))],
@@ -743,6 +779,108 @@ function dwCreateStore(translate) {
743
779
  }
744
780
  },
745
781
 
782
+ /**
783
+ * Read the saved statements.
784
+ *
785
+ * The list belongs to the machine, not to one workspace, so it is loaded when
786
+ * the panel opens; saves and deletes patch it in place. No workspace is needed.
787
+ */
788
+ async loadFavorites(options = {}) {
789
+ if (state.favoritesLoading === true && options.force !== true) return
790
+ patch({ favoritesLoading: true })
791
+ try {
792
+ const value = await dwRpc('favorites')
793
+ patch({
794
+ favorites: Array.isArray(value?.favorites) ? value.favorites : [],
795
+ favoritesLoading: false,
796
+ favoritesError: '',
797
+ })
798
+ } catch (error) {
799
+ patch({ favoritesLoading: false, favoritesError: dwExplainFailure(t, error) })
800
+ if (options.quiet !== true) pushLog('warn', t('log.favoriteLoadFailed', { message: dwExplainFailure(t, error) }))
801
+ }
802
+ },
803
+
804
+ /** Save one statement under its unique name, and open the favorites node. */
805
+ async saveFavorite(input) {
806
+ const value = await dwRpc('saveFavorite', { favorite: { ...input } })
807
+ const favorite = value?.favorite
808
+ if (favorite !== undefined && favorite !== null) {
809
+ const favorites = [...state.favorites]
810
+ const index = favorites.findIndex((entry) => entry.id === favorite.id)
811
+ if (index >= 0) favorites[index] = favorite
812
+ else favorites.push(favorite)
813
+ patch({ favorites })
814
+ pushLog('info', t('log.favoriteSaved', { name: favorite.name, database: favorite.database }))
815
+ const tableKey = String(favorite.table ?? '').trim().toLowerCase()
816
+ // The saved statement lives on the favorites tab now; switching there and
817
+ // expanding its schema/table is the only visible acknowledgement that the
818
+ // save landed, since the database tree cannot show it.
819
+ store.setTreeTab('favorites')
820
+ store.expand(
821
+ dwNodeKey('favoriteDatabase', favorite.database),
822
+ dwNodeKey('favoriteTable', favorite.database, tableKey),
823
+ )
824
+ const favoriteKey = dwNodeKey('favorite', favorite.id)
825
+ store.select({ key: favoriteKey, kind: 'favorite', label: favorite.name, favorite })
826
+ }
827
+ return value
828
+ },
829
+
830
+ /** Delete one saved statement. */
831
+ async removeFavorite(id) {
832
+ const value = await dwRpc('removeFavorite', { id })
833
+ if (value?.removed === true) {
834
+ const favorite = state.favorites.find((entry) => entry.id === id)
835
+ patch({ favorites: state.favorites.filter((entry) => entry.id !== id) })
836
+ pushLog('info', t('log.favoriteRemoved', { name: favorite?.name ?? id }))
837
+ }
838
+ return value
839
+ },
840
+
841
+ /**
842
+ * Open a saved statement in the workbench of the schema it was saved from.
843
+ *
844
+ * Opening by name is what keeps a favorite useful across workspaces: the
845
+ * statement was written in `bw_order` in one project and is still a `bw_order`
846
+ * statement in the next tree. When that schema is not in the tree at all, the
847
+ * log says which one is missing instead of opening an unrelated console.
848
+ */
849
+ openFavorite(favorite) {
850
+ if (favorite === null || favorite === undefined) return false
851
+ const target = dwFindDatabaseTarget(state.environments, favorite.database, favorite.env)
852
+ if (target === undefined) {
853
+ pushLog('warn', t('log.favoriteNoDatabase', { database: favorite.database }))
854
+ return false
855
+ }
856
+ const opened = store.openDatabase(target.node)
857
+ const tabId = typeof opened?.id === 'string' ? opened.id : ''
858
+ if (tabId === '') return false
859
+ store.appendStatement(tabId, favorite.sql)
860
+ pushLog('info', t('log.favoriteOpened', { name: favorite.name }))
861
+ return true
862
+ },
863
+
864
+ /** Append a statement to one console without touching what is already typed. */
865
+ appendStatement(tabId, sql) {
866
+ const statement = String(sql ?? '').trim()
867
+ const tab = state.tabs.find((entry) => entry.id === tabId)
868
+ if (statement === '' || tab === undefined) return
869
+ const current = String(tab.sql ?? '').replace(/\s+$/, '')
870
+ if (current.includes(statement)) {
871
+ store.setActiveTab(tabId)
872
+ return
873
+ }
874
+ const next = current === '' ? statement : `${current}\n\n${statement}`
875
+ patch({
876
+ tabs: state.tabs.map((entry) => (entry.id === tabId
877
+ ? { ...entry, sql: next, result: undefined, error: '' }
878
+ : entry)),
879
+ activeTab: tabId,
880
+ })
881
+ scheduleConsoles()
882
+ },
883
+
746
884
  /** Delete a whole manually added environment, then re-read the tree. */
747
885
  async removeManualEnvironment(label) {
748
886
  const root = state.root
@@ -925,6 +1063,18 @@ function dwCreateStore(translate) {
925
1063
  patch({ selected: node?.key ?? '', selectedNode: node ?? null })
926
1064
  },
927
1065
 
1066
+ /** Switch the resource manager between the database tree and the favorites. */
1067
+ setTreeTab(tab) {
1068
+ const next = tab === 'favorites' ? 'favorites' : 'databases'
1069
+ if (next === state.treeTab) return
1070
+ try {
1071
+ globalThis.localStorage?.setItem(DW_TREE_TAB_KEY, next)
1072
+ } catch (error) {
1073
+ void error
1074
+ }
1075
+ patch({ treeTab: next })
1076
+ },
1077
+
928
1078
  /**
929
1079
  * Open (or focus) the SQL workbench of one database.
930
1080
  *
@@ -10,7 +10,7 @@
10
10
  */
11
11
 
12
12
  /** One nested tree of what the store currently knows, before filtering. */
13
- function dwBuildTree(state, tr) {
13
+ function dwBuildTree(state, tr, mode = 'databases') {
14
14
  const loadStateOf = (key) => state.loadState.get(key)
15
15
  const childrenOf = (node, depth) => {
16
16
  const rows = []
@@ -26,7 +26,12 @@ function dwBuildTree(state, tr) {
26
26
  return rows
27
27
  }
28
28
 
29
- const environments = []
29
+ // The favorites tab is derived from the saved list, not from `children`: it never
30
+ // needs a round trip to expand, and a save anywhere in the panel is visible the
31
+ // moment the store patches the list.
32
+ if (mode === 'favorites') return dwBuildFavoriteRows(state.favorites, tr)
33
+
34
+ const rows = []
30
35
  for (const environment of state.environments ?? []) {
31
36
  const envKey = dwNodeKey('env', environment.env)
32
37
  const instanceRows = []
@@ -73,7 +78,7 @@ function dwBuildTree(state, tr) {
73
78
  children: databaseRows,
74
79
  })
75
80
  }
76
- environments.push({
81
+ rows.push({
77
82
  node: {
78
83
  key: envKey,
79
84
  kind: 'env',
@@ -87,7 +92,7 @@ function dwBuildTree(state, tr) {
87
92
  children: instanceRows,
88
93
  })
89
94
  }
90
- return environments
95
+ return rows
91
96
  }
92
97
 
93
98
  /** Prune a tree to the nodes that match, keeping their ancestors. */
@@ -130,7 +135,7 @@ function dwFlattenTree(tree, state, filter, depth = 0, into = []) {
130
135
  /** One row per visible node, in display order. */
131
136
  function dwVisibleRows(state, tr) {
132
137
  const filter = String(state.filter ?? '').trim().toLowerCase()
133
- const tree = dwPruneTree(dwBuildTree(state, tr), filter)
138
+ const tree = dwPruneTree(dwBuildTree(state, tr, state.treeTab), filter)
134
139
  return dwFlattenTree(tree, state, filter)
135
140
  }
136
141
 
@@ -143,6 +148,9 @@ function dwNodeIconName(node) {
143
148
  case 'view': return 'view'
144
149
  case 'table': return 'table'
145
150
  case 'column': return node.column?.key === 'PRI' ? 'key' : 'column'
151
+ case 'favorite': return 'star'
152
+ case 'favoriteDatabase': return 'database'
153
+ case 'favoriteTable': return 'table'
146
154
  case 'retry': return 'refresh'
147
155
  case 'error': return 'close'
148
156
  default: return 'panel'
@@ -152,7 +160,7 @@ function dwNodeIconName(node) {
152
160
  function DwTree({ store, state, tr, onContextMenu, onChooseDatabases }) {
153
161
  const rows = useMemo(
154
162
  () => dwVisibleRows(state, tr),
155
- [state.environments, state.expanded, state.children, state.loadState, state.filter],
163
+ [state.root, state.treeTab, state.environments, state.expanded, state.children, state.loadState, state.filter, state.favorites, state.favoritesError],
156
164
  )
157
165
 
158
166
  // A row click only selects: expanding belongs to the twisty (and to double-click
@@ -164,6 +172,9 @@ function DwTree({ store, state, tr, onContextMenu, onChooseDatabases }) {
164
172
  return
165
173
  }
166
174
  store.select(node)
175
+ // The favorites branches exist to be browsed, so a single click unfolds them;
176
+ // every other row keeps the "select only" behaviour of the tree.
177
+ if (node.kind === 'favoriteDatabase' || node.kind === 'favoriteTable') void store.toggleNode(node)
167
178
  }
168
179
 
169
180
  const openRow = (row) => {
@@ -173,6 +184,10 @@ function DwTree({ store, state, tr, onContextMenu, onChooseDatabases }) {
173
184
  return
174
185
  }
175
186
  store.select(node)
187
+ if (node.kind === 'favorite') {
188
+ store.openFavorite(node.favorite)
189
+ return
190
+ }
176
191
  if (node.kind === 'database') {
177
192
  store.openDatabase(node)
178
193
  if (row.open !== true) void store.toggleNode(node)
@@ -200,14 +215,21 @@ function DwTree({ store, state, tr, onContextMenu, onChooseDatabases }) {
200
215
  }
201
216
 
202
217
  if (rows.length === 0) {
203
- const empty = state.phase === 'loading'
204
- ? tr('treeLoading')
205
- : String(state.filter ?? '') !== ''
218
+ const filtered = String(state.filter ?? '') !== ''
219
+ const empty = state.treeTab === 'favorites'
220
+ ? filtered
206
221
  ? tr('treeNoMatch')
207
- : tr('treeEmpty')
222
+ : String(state.favoritesError ?? '') !== ''
223
+ ? tr('log.favoriteLoadFailed', { message: state.favoritesError })
224
+ : tr('favoritesEmptyHint')
225
+ : state.phase === 'loading'
226
+ ? tr('treeLoading')
227
+ : filtered
228
+ ? tr('treeNoMatch')
229
+ : tr('treeEmpty')
208
230
  return h('div', { className: 'dw-tree' }, h('div', { className: 'dw-empty', style: { padding: 18 } }, [
209
231
  h('div', { key: 't', className: 'dw-empty-hint' }, empty),
210
- String(state.filter ?? '') !== ''
232
+ filtered
211
233
  ? h('button', {
212
234
  key: 'c',
213
235
  type: 'button',