dsh-data-window 0.1.1 → 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/AGENTS.md +1 -1
- package/CHANGELOG.md +67 -0
- package/README.md +17 -3
- package/client.js +1760 -214
- package/docs/BRIDGE.md +6 -0
- package/docs/DETAIL.md +50 -5
- package/locale/en.json +64 -1
- package/locale/zh.json +64 -1
- package/package.json +1 -1
- package/src/client/00-css.js +204 -1
- package/src/client/05-icons.js +21 -0
- package/src/client/07-bridge.js +10 -1
- package/src/client/10-core.js +182 -64
- package/src/client/20-tree.js +51 -17
- package/src/client/27-favorites.js +331 -0
- package/src/client/30-editor.js +490 -94
- package/src/client/40-results.js +3 -0
- package/src/client/50-panel.js +203 -25
- package/src/client/63-schema.js +1 -0
- package/src/client/64-manual.js +6 -1
- package/src/client/65-ai.js +1 -0
- package/src/client/66-optimize.js +120 -1
- package/src/host/favorites.js +188 -0
- package/src/host/rpc.js +51 -0
- package/src/host/shared.js +10 -2
package/client.js
CHANGED
|
@@ -12,7 +12,10 @@ window.__ModuleLoader__.load({
|
|
|
12
12
|
"openPanel": "Data window",
|
|
13
13
|
"openPanelHint": "Open the data window",
|
|
14
14
|
"treeTitle": "Explorer",
|
|
15
|
+
"treeTabsLabel": "Resource manager tabs",
|
|
16
|
+
"treeTabDatabases": "Databases",
|
|
15
17
|
"filterPlaceholder": "Filter the loaded databases and tables",
|
|
18
|
+
"filterFavoritesPlaceholder": "Filter saved SQL by name, schema or table",
|
|
16
19
|
"treeLoading": "Loading…",
|
|
17
20
|
"treeNoMatch": "Nothing matches this filter",
|
|
18
21
|
"treeEmpty": "No database configuration found for this workspace",
|
|
@@ -101,6 +104,7 @@ window.__ModuleLoader__.load({
|
|
|
101
104
|
"warning.unparsed-jdbc-url": "A datasource URL could not be parsed as jdbc:mysql.",
|
|
102
105
|
"projectSwitch": "Switch workspace",
|
|
103
106
|
"resizeTree": "Drag to resize the list (double-click resets)",
|
|
107
|
+
"resizeLog": "Drag to resize the run log (double-click resets)",
|
|
104
108
|
"hideSidebar": "Hide the DSH sidebar",
|
|
105
109
|
"showSidebar": "Show the DSH sidebar",
|
|
106
110
|
"formatSql": "Format",
|
|
@@ -288,12 +292,74 @@ window.__ModuleLoader__.load({
|
|
|
288
292
|
"optimizeNotes": "Notes",
|
|
289
293
|
"optimizeCopy": "Copy SQL",
|
|
290
294
|
"log.optimizeCopied": "Optimized SQL copied",
|
|
295
|
+
"tabClose": "Close",
|
|
296
|
+
"tabCloseOthers": "Close other tabs",
|
|
297
|
+
"tabCloseAll": "Close all tabs",
|
|
298
|
+
"tabCloseLeft": "Close tabs to the left",
|
|
299
|
+
"tabCloseRight": "Close tabs to the right",
|
|
300
|
+
"copyReference": "Copy reference",
|
|
301
|
+
"copyReferenceToChat": "Copy reference to chat",
|
|
302
|
+
"log.copiedReference": "Reference copied: {reference}",
|
|
303
|
+
"log.copiedReferenceToChat": "Reference inserted into the chat: {reference}",
|
|
304
|
+
"log.copiedReferenceOnly": "Chat input is closed; reference copied: {reference}",
|
|
305
|
+
"tabMenuLabel": "Tab menu",
|
|
306
|
+
"optimizeOriginal": "Original SQL",
|
|
307
|
+
"optimizeOptimized": "Optimized SQL",
|
|
308
|
+
"menuDdlAll": "Show all create statements",
|
|
309
|
+
"ddlAllEmpty": "This database has no tables",
|
|
310
|
+
"ddlAllPartial": "{count} table(s) could not be read; noted at the end of the script",
|
|
311
|
+
"log.ddlAll": "Read all create statements of {database}: {count} tables · {ms}",
|
|
312
|
+
"log.copiedDdlAll": "Copied all create statements of {database} ({count} tables)",
|
|
313
|
+
"favoritesTitle": "Favorites",
|
|
314
|
+
"favoritesCount": "saved",
|
|
315
|
+
"favoritesEmptyHint": "No saved SQL yet. Right-click in the editor and choose “Save SQL”.",
|
|
316
|
+
"favoritesReload": "Reload favorites",
|
|
317
|
+
"favoriteNoTable": "No table",
|
|
318
|
+
"favoriteNoDatabase": "Unknown schema",
|
|
319
|
+
"favoriteSave": "Save SQL",
|
|
320
|
+
"favoriteSaveTitle": "Save SQL",
|
|
321
|
+
"favoriteEditTitle": "Edit saved SQL",
|
|
322
|
+
"favoriteDialogHint": "The schema and table are stored with the statement and group the favorites node; typing @ indexes it by name.",
|
|
323
|
+
"favoriteName": "Name",
|
|
324
|
+
"favoriteNameHint": "Unique among saved SQL, and the keyword used by the @ index",
|
|
325
|
+
"favoriteDatabase": "Schema",
|
|
326
|
+
"favoriteDatabaseHint": "Prefilled from the workbench; editable",
|
|
327
|
+
"favoriteTable": "Table",
|
|
328
|
+
"favoriteTableHint": "Optional; empty goes under “No table”",
|
|
329
|
+
"favoriteSql": "SQL",
|
|
330
|
+
"favoriteSaveAction": "Save",
|
|
331
|
+
"favoriteUpdateAction": "Save changes",
|
|
332
|
+
"favoriteNameRequired": "Give this statement a name first",
|
|
333
|
+
"favoriteDatabaseRequired": "A schema name is required",
|
|
334
|
+
"favoriteMentionLabel": "Saved SQL",
|
|
335
|
+
"favoriteMentionEmpty": "No saved SQL matches",
|
|
336
|
+
"favoriteMentionNoFavorites": "No saved SQL yet: right-click in the editor and choose “Save SQL”",
|
|
337
|
+
"suggestFavorite": "saved",
|
|
338
|
+
"menuOpenFavorite": "Open saved SQL",
|
|
339
|
+
"menuCopyFavoriteSql": "Copy SQL",
|
|
340
|
+
"menuEditFavorite": "Edit saved SQL",
|
|
341
|
+
"menuRemoveFavorite": "Delete saved SQL",
|
|
342
|
+
"removeFavoriteTitle": "Delete saved SQL",
|
|
343
|
+
"removeFavoriteHint": "Delete “{name}”? This cannot be undone.",
|
|
344
|
+
"removeFavoriteConfirm": "Delete",
|
|
345
|
+
"log.favoriteSaved": "Saved SQL: {name} ({database})",
|
|
346
|
+
"log.favoriteRemoved": "Deleted saved SQL: {name}",
|
|
347
|
+
"log.favoriteOpened": "Opened saved SQL: {name}",
|
|
348
|
+
"log.favoriteNoDatabase": "The tree has no schema {database}, so this saved statement cannot be opened",
|
|
349
|
+
"log.favoriteLoadFailed": "Reading saved SQL failed: {message}",
|
|
350
|
+
"log.favoriteInserted": "Inserted saved SQL: {name}",
|
|
351
|
+
"log.favoriteCopied": "Copied saved SQL: {name}",
|
|
352
|
+
"log.favoriteRemoveFailed": "Deleting saved SQL failed: {message}",
|
|
353
|
+
"error.duplicateFavorite": "That name is already taken by another saved statement",
|
|
291
354
|
}
|
|
292
355
|
const DW_TEXT_ZH = {
|
|
293
356
|
"openPanel": "数据窗口",
|
|
294
357
|
"openPanelHint": "打开数据窗口",
|
|
295
358
|
"treeTitle": "资源管理器",
|
|
359
|
+
"treeTabsLabel": "资源管理标签",
|
|
360
|
+
"treeTabDatabases": "数据库",
|
|
296
361
|
"filterPlaceholder": "过滤已加载的库名与表名",
|
|
362
|
+
"filterFavoritesPlaceholder": "过滤收藏的名称、库名与表名",
|
|
297
363
|
"treeLoading": "加载中…",
|
|
298
364
|
"treeNoMatch": "没有匹配的节点",
|
|
299
365
|
"treeEmpty": "没有在当前工作区发现数据库配置",
|
|
@@ -382,6 +448,7 @@ window.__ModuleLoader__.load({
|
|
|
382
448
|
"warning.unparsed-jdbc-url": "有数据源地址无法解析为 jdbc:mysql。",
|
|
383
449
|
"projectSwitch": "切换工作区",
|
|
384
450
|
"resizeTree": "拖动调整列表宽度(双击还原)",
|
|
451
|
+
"resizeLog": "拖动调整运行日志高度(双击还原)",
|
|
385
452
|
"hideSidebar": "隐藏 DSH 侧栏",
|
|
386
453
|
"showSidebar": "显示 DSH 侧栏",
|
|
387
454
|
"formatSql": "格式化",
|
|
@@ -569,6 +636,65 @@ window.__ModuleLoader__.load({
|
|
|
569
636
|
"optimizeNotes": "优化说明",
|
|
570
637
|
"optimizeCopy": "复制 SQL",
|
|
571
638
|
"log.optimizeCopied": "优化后的 SQL 已复制",
|
|
639
|
+
"tabClose": "关闭",
|
|
640
|
+
"tabCloseOthers": "关闭其他标签页",
|
|
641
|
+
"tabCloseAll": "关闭所有标签页",
|
|
642
|
+
"tabCloseLeft": "关闭左侧标签页",
|
|
643
|
+
"tabCloseRight": "关闭右侧标签页",
|
|
644
|
+
"copyReference": "复制引用",
|
|
645
|
+
"copyReferenceToChat": "复制引用到对话",
|
|
646
|
+
"log.copiedReference": "已复制引用:{reference}",
|
|
647
|
+
"log.copiedReferenceToChat": "已把引用插入对话:{reference}",
|
|
648
|
+
"log.copiedReferenceOnly": "对话输入框未打开,已复制引用:{reference}",
|
|
649
|
+
"tabMenuLabel": "标签页菜单",
|
|
650
|
+
"optimizeOriginal": "原始 SQL",
|
|
651
|
+
"optimizeOptimized": "优化后 SQL",
|
|
652
|
+
"menuDdlAll": "查看全部建表语句",
|
|
653
|
+
"ddlAllEmpty": "这个库还没有表",
|
|
654
|
+
"ddlAllPartial": "{count} 张表读取失败,已在脚本末尾用注释标出",
|
|
655
|
+
"log.ddlAll": "读取 {database} 的全部建表语句:{count} 张表 · {ms}",
|
|
656
|
+
"log.copiedDdlAll": "已复制 {database} 的全部建表语句({count} 张表)",
|
|
657
|
+
"favoritesTitle": "收藏夹",
|
|
658
|
+
"favoritesCount": "条",
|
|
659
|
+
"favoritesEmptyHint": "还没有收藏 SQL。在编辑器里右键 →「收藏 SQL」即可收藏当前语句。",
|
|
660
|
+
"favoritesReload": "刷新收藏夹",
|
|
661
|
+
"favoriteNoTable": "未指定表",
|
|
662
|
+
"favoriteNoDatabase": "未知库",
|
|
663
|
+
"favoriteSave": "收藏 SQL",
|
|
664
|
+
"favoriteSaveTitle": "收藏 SQL",
|
|
665
|
+
"favoriteEditTitle": "编辑收藏",
|
|
666
|
+
"favoriteDialogHint": "保存时会连同库名与表名一起记录,收藏夹按这两层分组;输入 @ 时用名称索引这条 SQL。",
|
|
667
|
+
"favoriteName": "名称",
|
|
668
|
+
"favoriteNameHint": "名称在收藏夹里唯一,也是 @ 索引时输入的关键字",
|
|
669
|
+
"favoriteDatabase": "库名",
|
|
670
|
+
"favoriteDatabaseHint": "从工作台带入,可修改",
|
|
671
|
+
"favoriteTable": "表名",
|
|
672
|
+
"favoriteTableHint": "可选;留空归入「未指定表」",
|
|
673
|
+
"favoriteSql": "SQL",
|
|
674
|
+
"favoriteSaveAction": "收藏",
|
|
675
|
+
"favoriteUpdateAction": "保存修改",
|
|
676
|
+
"favoriteNameRequired": "请先给这条 SQL 起一个名称",
|
|
677
|
+
"favoriteDatabaseRequired": "请填写库名",
|
|
678
|
+
"favoriteMentionLabel": "收藏的 SQL",
|
|
679
|
+
"favoriteMentionEmpty": "没有匹配的收藏 SQL",
|
|
680
|
+
"favoriteMentionNoFavorites": "还没有收藏 SQL:在编辑器里右键 →「收藏 SQL」",
|
|
681
|
+
"suggestFavorite": "收藏",
|
|
682
|
+
"menuOpenFavorite": "打开收藏的 SQL",
|
|
683
|
+
"menuCopyFavoriteSql": "复制 SQL",
|
|
684
|
+
"menuEditFavorite": "编辑收藏",
|
|
685
|
+
"menuRemoveFavorite": "删除收藏",
|
|
686
|
+
"removeFavoriteTitle": "删除收藏",
|
|
687
|
+
"removeFavoriteHint": "确定删除收藏「{name}」?删除后不可恢复。",
|
|
688
|
+
"removeFavoriteConfirm": "删除",
|
|
689
|
+
"log.favoriteSaved": "已收藏 SQL:{name}({database})",
|
|
690
|
+
"log.favoriteRemoved": "已删除收藏:{name}",
|
|
691
|
+
"log.favoriteOpened": "已打开收藏的 SQL:{name}",
|
|
692
|
+
"log.favoriteNoDatabase": "资源树里没有库 {database},无法打开这条收藏",
|
|
693
|
+
"log.favoriteLoadFailed": "读取收藏夹失败:{message}",
|
|
694
|
+
"log.favoriteInserted": "已插入收藏的 SQL:{name}",
|
|
695
|
+
"log.favoriteCopied": "已复制收藏的 SQL:{name}",
|
|
696
|
+
"log.favoriteRemoveFailed": "删除收藏失败:{message}",
|
|
697
|
+
"error.duplicateFavorite": "这个名称已经被收藏了,请换一个名称",
|
|
572
698
|
}
|
|
573
699
|
|
|
574
700
|
// ---- 00-css.js -----------------------------------------------------------
|
|
@@ -715,6 +841,13 @@ const DW_CSS = `
|
|
|
715
841
|
color: var(--dsw-alias-label-primary-inverted, #fff);
|
|
716
842
|
font-weight: 600;
|
|
717
843
|
}
|
|
844
|
+
/*
|
|
845
|
+
* The panel and the sidebar-foot action each inject this stylesheet, so the second
|
|
846
|
+
* copy's plain .dw-btn color rule would otherwise override the first copy's accent
|
|
847
|
+
* label and paint white text on the brand fill. The extra class keeps the inverted
|
|
848
|
+
* label winning wherever the rules land.
|
|
849
|
+
*/
|
|
850
|
+
.dw-btn.dw-btn-accent { color: var(--dsw-alias-label-primary-inverted, #fff); }
|
|
718
851
|
.dw-btn-accent:hover { filter: brightness(1.08); background: var(--dsw-alias-brand-primary, #4b8bf5); }
|
|
719
852
|
.dw-btn-icon { width: 26px; padding: 0; justify-content: center; }
|
|
720
853
|
/*
|
|
@@ -799,6 +932,59 @@ const DW_CSS = `
|
|
|
799
932
|
letter-spacing: .04em;
|
|
800
933
|
text-transform: uppercase;
|
|
801
934
|
}
|
|
935
|
+
/* The resource manager's tabs: the configured tree and the saved statements. */
|
|
936
|
+
.dw-tree-tabs {
|
|
937
|
+
display: flex;
|
|
938
|
+
align-items: center;
|
|
939
|
+
gap: 2px;
|
|
940
|
+
flex: 0 0 auto;
|
|
941
|
+
padding: 4px 6px 0;
|
|
942
|
+
border-bottom: 1px solid var(--dsw-alias-border-l1, #2c2f36);
|
|
943
|
+
}
|
|
944
|
+
.dw-tree-tab {
|
|
945
|
+
display: inline-flex;
|
|
946
|
+
align-items: center;
|
|
947
|
+
gap: 5px;
|
|
948
|
+
height: 24px;
|
|
949
|
+
padding: 0 8px;
|
|
950
|
+
border: 0;
|
|
951
|
+
border-bottom: 2px solid transparent;
|
|
952
|
+
border-radius: 6px 6px 0 0;
|
|
953
|
+
background: transparent;
|
|
954
|
+
color: var(--dsw-alias-label-secondary, #8b919d);
|
|
955
|
+
font: inherit;
|
|
956
|
+
font-size: 11.5px;
|
|
957
|
+
cursor: pointer;
|
|
958
|
+
white-space: nowrap;
|
|
959
|
+
}
|
|
960
|
+
.dw-tree-tab:hover { background: var(--dsw-alias-interactive-bg-hover, rgba(127, 127, 127, .12)); color: var(--dsw-alias-label-primary, #e6e8ec); }
|
|
961
|
+
.dw-tree-tab.on {
|
|
962
|
+
color: var(--dsw-alias-label-primary, #e6e8ec);
|
|
963
|
+
border-bottom-color: var(--dsw-alias-brand-primary, #4b8bf5);
|
|
964
|
+
}
|
|
965
|
+
.dw-tree-tab-count {
|
|
966
|
+
min-width: 14px;
|
|
967
|
+
padding: 0 4px;
|
|
968
|
+
border-radius: 7px;
|
|
969
|
+
background: var(--dsw-alias-interactive-bg-hover, rgba(127, 127, 127, .12));
|
|
970
|
+
color: var(--dsw-alias-label-secondary, #8b919d);
|
|
971
|
+
font-size: 10px;
|
|
972
|
+
line-height: 14px;
|
|
973
|
+
text-align: center;
|
|
974
|
+
}
|
|
975
|
+
.dw-tree-tabs .dw-btn {
|
|
976
|
+
width: 22px;
|
|
977
|
+
height: 22px;
|
|
978
|
+
padding: 0;
|
|
979
|
+
justify-content: center;
|
|
980
|
+
border-color: transparent;
|
|
981
|
+
background: transparent;
|
|
982
|
+
color: var(--dsw-alias-label-secondary, #8b919d);
|
|
983
|
+
}
|
|
984
|
+
.dw-tree-tabs .dw-btn:hover:not(:disabled) {
|
|
985
|
+
background: var(--dsw-alias-interactive-bg-hover, rgba(127, 127, 127, .12));
|
|
986
|
+
color: var(--dsw-alias-label-primary, #e6e8ec);
|
|
987
|
+
}
|
|
802
988
|
.dw-tree { flex: 1 1 auto; overflow: auto; padding: 4px 0 12px; }
|
|
803
989
|
.dw-node {
|
|
804
990
|
display: flex;
|
|
@@ -1024,6 +1210,32 @@ const DW_CSS = `
|
|
|
1024
1210
|
.dw-complete-label { flex: 1 1 auto; font-family: var(--ds-font-family-code, ui-monospace, Menlo, monospace); font-size: 12px; }
|
|
1025
1211
|
.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; }
|
|
1026
1212
|
.dw-complete-kind { flex: 0 0 auto; color: var(--dsw-alias-label-secondary, #8b919d); font-size: 10px; opacity: .8; }
|
|
1213
|
+
.dw-complete-empty {
|
|
1214
|
+
padding: 6px 9px;
|
|
1215
|
+
max-width: 300px;
|
|
1216
|
+
color: var(--dsw-alias-label-secondary, #8b919d);
|
|
1217
|
+
font-size: 11.5px;
|
|
1218
|
+
line-height: 1.55;
|
|
1219
|
+
}
|
|
1220
|
+
/* The at-sign index: statements, so a little wider than the column list. */
|
|
1221
|
+
.dw-mention { min-width: 280px; max-width: 420px; }
|
|
1222
|
+
.dw-fav-sql {
|
|
1223
|
+
margin: 0;
|
|
1224
|
+
max-height: 170px;
|
|
1225
|
+
overflow: auto;
|
|
1226
|
+
padding: 8px 10px;
|
|
1227
|
+
border: 1px solid var(--dsw-alias-border-l1, #31353d);
|
|
1228
|
+
border-radius: 6px;
|
|
1229
|
+
background: var(--dsw-alias-bg-layer-2, #262930);
|
|
1230
|
+
color: var(--dsw-alias-label-primary, #e6e8ec);
|
|
1231
|
+
font-family: var(--ds-font-family-code, ui-monospace, Menlo, monospace);
|
|
1232
|
+
font-size: 11.5px;
|
|
1233
|
+
line-height: 1.55;
|
|
1234
|
+
white-space: pre;
|
|
1235
|
+
}
|
|
1236
|
+
.dw-fav-dialog { width: min(620px, 100%); }
|
|
1237
|
+
.dw-fav-split { display: flex; gap: 10px; }
|
|
1238
|
+
.dw-fav-split .dw-form-row { flex: 1 1 0; min-width: 0; }
|
|
1027
1239
|
|
|
1028
1240
|
.dw-drag {
|
|
1029
1241
|
height: 5px;
|
|
@@ -1205,6 +1417,63 @@ const DW_CSS = `
|
|
|
1205
1417
|
background: var(--dsw-alias-bg-overlay, #23262d);
|
|
1206
1418
|
box-shadow: 0 10px 26px rgba(0,0,0,.42);
|
|
1207
1419
|
}
|
|
1420
|
+
.dw-tabmenu-backdrop {
|
|
1421
|
+
position: fixed;
|
|
1422
|
+
inset: 0;
|
|
1423
|
+
z-index: 70;
|
|
1424
|
+
background: transparent;
|
|
1425
|
+
}
|
|
1426
|
+
/* The tab menu mirrors the code workspace's menu (icons + labels, IDEA-like). */
|
|
1427
|
+
.dw-tabmenu {
|
|
1428
|
+
position: fixed;
|
|
1429
|
+
overflow-y: auto;
|
|
1430
|
+
overscroll-behavior: contain;
|
|
1431
|
+
min-width: 232px;
|
|
1432
|
+
padding: 5px;
|
|
1433
|
+
border: 0.5px solid var(--dsw-alias-border-l2, rgba(255, 255, 255, .1));
|
|
1434
|
+
border-radius: var(--dsw-radius-md, 10px);
|
|
1435
|
+
background: var(--dsw-specific-menu, var(--dsw-alias-bg-layer-2, #23262b));
|
|
1436
|
+
backdrop-filter: var(--dsw-menu-backdrop-filter, none);
|
|
1437
|
+
box-shadow: var(--dsw-elevation-prominent, 0 12px 32px rgba(0, 0, 0, .35));
|
|
1438
|
+
color: var(--dsw-alias-label-primary, inherit);
|
|
1439
|
+
}
|
|
1440
|
+
.dw-tabmenu-item {
|
|
1441
|
+
display: flex;
|
|
1442
|
+
align-items: center;
|
|
1443
|
+
gap: 9px;
|
|
1444
|
+
width: 100%;
|
|
1445
|
+
height: 27px;
|
|
1446
|
+
padding: 0 9px;
|
|
1447
|
+
border: 0;
|
|
1448
|
+
border-radius: var(--dsw-radius-sm, 6px);
|
|
1449
|
+
background: transparent;
|
|
1450
|
+
color: inherit;
|
|
1451
|
+
font: inherit;
|
|
1452
|
+
font-size: 12.5px;
|
|
1453
|
+
line-height: 27px;
|
|
1454
|
+
text-align: left;
|
|
1455
|
+
cursor: default;
|
|
1456
|
+
}
|
|
1457
|
+
.dw-tabmenu-item:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover, rgba(255, 255, 255, .08)); }
|
|
1458
|
+
.dw-tabmenu-item:disabled { opacity: .45; }
|
|
1459
|
+
.dw-tabmenu-item:focus-visible {
|
|
1460
|
+
outline: none;
|
|
1461
|
+
box-shadow: inset 0 0 0 2px var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary, #4a7dff));
|
|
1462
|
+
}
|
|
1463
|
+
.dw-tabmenu-icon {
|
|
1464
|
+
display: inline-flex;
|
|
1465
|
+
flex: none;
|
|
1466
|
+
align-items: center;
|
|
1467
|
+
justify-content: center;
|
|
1468
|
+
width: 14px;
|
|
1469
|
+
color: var(--dsw-alias-label-secondary, inherit);
|
|
1470
|
+
}
|
|
1471
|
+
.dw-tabmenu-label { flex: 1 1 auto; }
|
|
1472
|
+
.dw-tabmenu-sep {
|
|
1473
|
+
height: 0.5px;
|
|
1474
|
+
margin: 5px 8px;
|
|
1475
|
+
background: var(--dsw-alias-border-l1, rgba(255, 255, 255, .08));
|
|
1476
|
+
}
|
|
1208
1477
|
.dw-menu-note {
|
|
1209
1478
|
padding: 4px 8px 5px;
|
|
1210
1479
|
color: var(--dsw-alias-label-secondary, #8b919d);
|
|
@@ -1482,7 +1751,67 @@ const DW_CSS = `
|
|
|
1482
1751
|
word-break: break-all;
|
|
1483
1752
|
}
|
|
1484
1753
|
.dw-cell-dialog { width: min(720px, 100%); }
|
|
1485
|
-
.dw-optimize-dialog { width: min(
|
|
1754
|
+
.dw-optimize-dialog { width: min(1100px, 100%); }
|
|
1755
|
+
.dw-ddl-dialog { width: min(900px, 100%); }
|
|
1756
|
+
/*
|
|
1757
|
+
* The DDL is the only scroll container in this dialog: one scrollbar pair, at the
|
|
1758
|
+
* code box, instead of the modal body plus the pre each growing their own.
|
|
1759
|
+
*/
|
|
1760
|
+
.dw-ddl-dialog .dw-modal-body {
|
|
1761
|
+
display: flex;
|
|
1762
|
+
flex-direction: column;
|
|
1763
|
+
min-height: 0;
|
|
1764
|
+
overflow: hidden;
|
|
1765
|
+
}
|
|
1766
|
+
.dw-ddl-result {
|
|
1767
|
+
display: flex;
|
|
1768
|
+
flex: 1 1 auto;
|
|
1769
|
+
flex-direction: column;
|
|
1770
|
+
min-height: 0;
|
|
1771
|
+
}
|
|
1772
|
+
.dw-ddl-result .dw-log-warn { margin-bottom: 6px; }
|
|
1773
|
+
.dw-ddl-code {
|
|
1774
|
+
flex: 1 1 auto;
|
|
1775
|
+
min-height: 0;
|
|
1776
|
+
max-height: none;
|
|
1777
|
+
overflow: auto;
|
|
1778
|
+
/* Keep the server's line breaks: long COMMENTs scroll sideways, never wrap. */
|
|
1779
|
+
white-space: pre;
|
|
1780
|
+
word-break: normal;
|
|
1781
|
+
}
|
|
1782
|
+
.dw-diff { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
|
|
1783
|
+
.dw-diff-col { display: flex; flex-direction: column; min-width: 0; }
|
|
1784
|
+
.dw-diff-head {
|
|
1785
|
+
padding-bottom: 5px;
|
|
1786
|
+
color: var(--dsw-alias-label-secondary, #8b919d);
|
|
1787
|
+
font-size: 11px;
|
|
1788
|
+
}
|
|
1789
|
+
.dw-diff-pane {
|
|
1790
|
+
margin: 0;
|
|
1791
|
+
padding: 10px 12px;
|
|
1792
|
+
max-height: 320px;
|
|
1793
|
+
overflow: auto;
|
|
1794
|
+
border: 1px solid var(--dsw-alias-border-l1, #31353d);
|
|
1795
|
+
border-radius: 8px;
|
|
1796
|
+
background: var(--dsw-alias-bg-layer-2, #262930);
|
|
1797
|
+
color: var(--dsw-alias-label-primary, #e6e8ec);
|
|
1798
|
+
font-family: var(--dsw-font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
|
|
1799
|
+
font-size: 12px;
|
|
1800
|
+
line-height: 1.55;
|
|
1801
|
+
white-space: pre-wrap;
|
|
1802
|
+
word-break: break-word;
|
|
1803
|
+
}
|
|
1804
|
+
.dw-diff-del {
|
|
1805
|
+
border-radius: 2px;
|
|
1806
|
+
background: color-mix(in srgb, var(--dsw-alias-state-error-primary, #e5534b) 26%, transparent);
|
|
1807
|
+
}
|
|
1808
|
+
.dw-diff-add {
|
|
1809
|
+
border-radius: 2px;
|
|
1810
|
+
background: color-mix(in srgb, var(--dsw-alias-state-success-primary, #3fb950) 26%, transparent);
|
|
1811
|
+
}
|
|
1812
|
+
@media (max-width: 720px) {
|
|
1813
|
+
.dw-diff { grid-template-columns: 1fr; }
|
|
1814
|
+
}
|
|
1486
1815
|
.dw-optimize-model { padding-bottom: 8px; color: var(--dsw-alias-label-secondary, #8b919d); font-size: 11px; }
|
|
1487
1816
|
.dw-optimize-notes {
|
|
1488
1817
|
max-height: 120px;
|
|
@@ -1634,6 +1963,27 @@ function DwIcon({ name, size = 14, className }) {
|
|
|
1634
1963
|
return h('svg', { ...common, fill: 'currentColor', stroke: 'none' }, [h('path', { d: 'M4.6 2.9l8 5.1-8 5.1z' })])
|
|
1635
1964
|
case 'stop':
|
|
1636
1965
|
return h('svg', { ...common, fill: 'currentColor', stroke: 'none' }, [h('rect', { x: 4, y: 4, width: 8, height: 8, rx: 1.4 })])
|
|
1966
|
+
case 'layers':
|
|
1967
|
+
return h('svg', common, [
|
|
1968
|
+
h('rect', { key: 'a', x: 2.4, y: 2.4, width: 7, height: 7, rx: 1.4 }),
|
|
1969
|
+
h('rect', { key: 'b', x: 6.6, y: 6.6, width: 7, height: 7, rx: 1.4 }),
|
|
1970
|
+
])
|
|
1971
|
+
case 'stack':
|
|
1972
|
+
return h('svg', common, [
|
|
1973
|
+
h('path', { key: 'a', d: 'M2 6 8 3.2 14 6 8 8.8Z' }),
|
|
1974
|
+
h('path', { key: 'b', d: 'M2 10.4 8 13.2 14 10.4' }),
|
|
1975
|
+
])
|
|
1976
|
+
case 'arrow-left':
|
|
1977
|
+
return h('svg', common, [h('path', { key: 'a', d: 'M12.5 8H3.5M7 4.5 3.5 8 7 11.5' })])
|
|
1978
|
+
case 'arrow-right':
|
|
1979
|
+
return h('svg', common, [h('path', { key: 'a', d: 'M3.5 8h9M9 4.5 12.5 8 9 11.5' })])
|
|
1980
|
+
case 'at':
|
|
1981
|
+
return h('svg', common, [
|
|
1982
|
+
h('circle', { key: 'a', cx: 8, cy: 8, r: 2.4 }),
|
|
1983
|
+
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' }),
|
|
1984
|
+
])
|
|
1985
|
+
case 'star':
|
|
1986
|
+
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' })])
|
|
1637
1987
|
case 'close':
|
|
1638
1988
|
return h('svg', common, [h('path', { d: 'M4.2 4.2l7.6 7.6M11.8 4.2l-7.6 7.6' })])
|
|
1639
1989
|
case 'download':
|
|
@@ -1951,6 +2301,9 @@ function dwBridgeDatabases(state) {
|
|
|
1951
2301
|
env: environment.env,
|
|
1952
2302
|
envLabel: environment.label ?? environment.env,
|
|
1953
2303
|
instanceLabel: instance.label ?? '',
|
|
2304
|
+
// 资源树是全机共享的,同一个实例下会挂着别的项目的库;只有本项目发现出来的
|
|
2305
|
+
// 库才带这个标记,`openSql` 靠它选库。
|
|
2306
|
+
inWorkspace: database.inWorkspace === true,
|
|
1954
2307
|
})
|
|
1955
2308
|
}
|
|
1956
2309
|
}
|
|
@@ -2062,7 +2415,13 @@ async function dwBridgeHandle(detail, deps) {
|
|
|
2062
2415
|
return
|
|
2063
2416
|
}
|
|
2064
2417
|
const schema = typeof detail.schema === 'string' ? detail.schema.trim() : ''
|
|
2065
|
-
|
|
2418
|
+
// 库的定位:显式 schema 优先;没有就只在本项目发现出来的库里挑。
|
|
2419
|
+
// 以前直接取 databases[0],共享资源树里第一个常常是别的项目的库
|
|
2420
|
+
// (bluewhale-order-service 的 Mapper 被打开在 tiangong_tk_order 下)。
|
|
2421
|
+
const own = databases.filter((entry) => entry.inWorkspace === true)
|
|
2422
|
+
const pool = own.length > 0 ? own : databases
|
|
2423
|
+
const target = (schema === '' ? null : databases.find((entry) => entry.database === schema))
|
|
2424
|
+
?? pool[0]
|
|
2066
2425
|
layout()?.selectPanel?.(DW_PANEL_ID)
|
|
2067
2426
|
// Paste only: Mapper SQL usually carries #{...} parameters and dynamic
|
|
2068
2427
|
// fragments, so running it automatically would just produce an error.
|
|
@@ -2237,6 +2596,20 @@ function dwLogEntry(level, text) {
|
|
|
2237
2596
|
return { id: `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`, at: new Date(), level, text }
|
|
2238
2597
|
}
|
|
2239
2598
|
|
|
2599
|
+
/**
|
|
2600
|
+
* Whether a key event belongs to an input-method composition.
|
|
2601
|
+
*
|
|
2602
|
+
* The Enter/Escape that picks or cancels a Chinese or Japanese candidate belongs
|
|
2603
|
+
* to the IME, not to this window: it must never submit a dialog, blur a cell or
|
|
2604
|
+
* pick a suggestion. Chromium marks those events with `isComposing` and the legacy
|
|
2605
|
+
* 229 keyCode; React's synthetic keyboard event does not expose `isComposing`, so
|
|
2606
|
+
* the native event is what is checked.
|
|
2607
|
+
*/
|
|
2608
|
+
function dwImeComposing(event) {
|
|
2609
|
+
const native = event?.nativeEvent ?? event
|
|
2610
|
+
return native?.isComposing === true || (native?.keyCode ?? event?.keyCode) === 229
|
|
2611
|
+
}
|
|
2612
|
+
|
|
2240
2613
|
/**
|
|
2241
2614
|
* Turn a Host failure into a sentence.
|
|
2242
2615
|
*
|
|
@@ -2260,6 +2633,7 @@ function dwExplainFailure(translate, error) {
|
|
|
2260
2633
|
'ER_QUERY_INTERRUPTED': 'error.interrupted',
|
|
2261
2634
|
'manual-connect-failed': 'error.manualConnectFailed',
|
|
2262
2635
|
'saved-connection-missing': 'error.savedConnectionMissing',
|
|
2636
|
+
'duplicate-favorite': 'error.duplicateFavorite',
|
|
2263
2637
|
}
|
|
2264
2638
|
const key = known[code]
|
|
2265
2639
|
if (key !== undefined) {
|
|
@@ -2331,6 +2705,19 @@ const DW_CONSOLE_KEY = 'dsh-data-window:consoles'
|
|
|
2331
2705
|
/** Client-side preferences edited in the plugin's settings section. */
|
|
2332
2706
|
const DW_PREFS_KEY = 'dsh-data-window:prefs'
|
|
2333
2707
|
|
|
2708
|
+
/** Which side-panel tab was last shown: the database tree or the favorites list. */
|
|
2709
|
+
const DW_TREE_TAB_KEY = 'dsh-data-window:tree-tab'
|
|
2710
|
+
|
|
2711
|
+
/** The remembered side-panel tab; unknown or blocked storage means the tree. */
|
|
2712
|
+
function dwReadTreeTab() {
|
|
2713
|
+
try {
|
|
2714
|
+
return globalThis.localStorage?.getItem(DW_TREE_TAB_KEY) === 'favorites' ? 'favorites' : 'databases'
|
|
2715
|
+
} catch (error) {
|
|
2716
|
+
void error
|
|
2717
|
+
return 'databases'
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2720
|
+
|
|
2334
2721
|
/** Read the display preferences, tolerating a blocked storage. */
|
|
2335
2722
|
function dwReadPrefs() {
|
|
2336
2723
|
const fallback = { autoHideSidebar: true, defaultLimit: 0, shortcutOpen: null, aiModel: null }
|
|
@@ -2432,6 +2819,9 @@ function dwCreateStore(translate) {
|
|
|
2432
2819
|
aiRunning: false,
|
|
2433
2820
|
// tree
|
|
2434
2821
|
filter: '',
|
|
2822
|
+
// The resource manager has two tabs, like DataGrip's Database window: the
|
|
2823
|
+
// configured tree and the saved statements. Both read the same filter.
|
|
2824
|
+
treeTab: dwReadTreeTab(),
|
|
2435
2825
|
expanded: new Set(),
|
|
2436
2826
|
loadState: new Map(),
|
|
2437
2827
|
children: new Map(),
|
|
@@ -2443,6 +2833,11 @@ function dwCreateStore(translate) {
|
|
|
2443
2833
|
// Table/column maps for the editor's completion, one per database.
|
|
2444
2834
|
schemas: new Map(),
|
|
2445
2835
|
limit: DW_DEFAULT_LIMIT,
|
|
2836
|
+
// Saved statements (machine-wide, not per workspace) and the `@` index they
|
|
2837
|
+
// feed; the tree's favorites node is rendered from this list.
|
|
2838
|
+
favorites: [],
|
|
2839
|
+
favoritesLoading: false,
|
|
2840
|
+
favoritesError: '',
|
|
2446
2841
|
// log
|
|
2447
2842
|
logOpen: false,
|
|
2448
2843
|
log: [dwLogEntry('info', t('log.ready'))],
|
|
@@ -2846,6 +3241,108 @@ function dwCreateStore(translate) {
|
|
|
2846
3241
|
}
|
|
2847
3242
|
},
|
|
2848
3243
|
|
|
3244
|
+
/**
|
|
3245
|
+
* Read the saved statements.
|
|
3246
|
+
*
|
|
3247
|
+
* The list belongs to the machine, not to one workspace, so it is loaded when
|
|
3248
|
+
* the panel opens; saves and deletes patch it in place. No workspace is needed.
|
|
3249
|
+
*/
|
|
3250
|
+
async loadFavorites(options = {}) {
|
|
3251
|
+
if (state.favoritesLoading === true && options.force !== true) return
|
|
3252
|
+
patch({ favoritesLoading: true })
|
|
3253
|
+
try {
|
|
3254
|
+
const value = await dwRpc('favorites')
|
|
3255
|
+
patch({
|
|
3256
|
+
favorites: Array.isArray(value?.favorites) ? value.favorites : [],
|
|
3257
|
+
favoritesLoading: false,
|
|
3258
|
+
favoritesError: '',
|
|
3259
|
+
})
|
|
3260
|
+
} catch (error) {
|
|
3261
|
+
patch({ favoritesLoading: false, favoritesError: dwExplainFailure(t, error) })
|
|
3262
|
+
if (options.quiet !== true) pushLog('warn', t('log.favoriteLoadFailed', { message: dwExplainFailure(t, error) }))
|
|
3263
|
+
}
|
|
3264
|
+
},
|
|
3265
|
+
|
|
3266
|
+
/** Save one statement under its unique name, and open the favorites node. */
|
|
3267
|
+
async saveFavorite(input) {
|
|
3268
|
+
const value = await dwRpc('saveFavorite', { favorite: { ...input } })
|
|
3269
|
+
const favorite = value?.favorite
|
|
3270
|
+
if (favorite !== undefined && favorite !== null) {
|
|
3271
|
+
const favorites = [...state.favorites]
|
|
3272
|
+
const index = favorites.findIndex((entry) => entry.id === favorite.id)
|
|
3273
|
+
if (index >= 0) favorites[index] = favorite
|
|
3274
|
+
else favorites.push(favorite)
|
|
3275
|
+
patch({ favorites })
|
|
3276
|
+
pushLog('info', t('log.favoriteSaved', { name: favorite.name, database: favorite.database }))
|
|
3277
|
+
const tableKey = String(favorite.table ?? '').trim().toLowerCase()
|
|
3278
|
+
// The saved statement lives on the favorites tab now; switching there and
|
|
3279
|
+
// expanding its schema/table is the only visible acknowledgement that the
|
|
3280
|
+
// save landed, since the database tree cannot show it.
|
|
3281
|
+
store.setTreeTab('favorites')
|
|
3282
|
+
store.expand(
|
|
3283
|
+
dwNodeKey('favoriteDatabase', favorite.database),
|
|
3284
|
+
dwNodeKey('favoriteTable', favorite.database, tableKey),
|
|
3285
|
+
)
|
|
3286
|
+
const favoriteKey = dwNodeKey('favorite', favorite.id)
|
|
3287
|
+
store.select({ key: favoriteKey, kind: 'favorite', label: favorite.name, favorite })
|
|
3288
|
+
}
|
|
3289
|
+
return value
|
|
3290
|
+
},
|
|
3291
|
+
|
|
3292
|
+
/** Delete one saved statement. */
|
|
3293
|
+
async removeFavorite(id) {
|
|
3294
|
+
const value = await dwRpc('removeFavorite', { id })
|
|
3295
|
+
if (value?.removed === true) {
|
|
3296
|
+
const favorite = state.favorites.find((entry) => entry.id === id)
|
|
3297
|
+
patch({ favorites: state.favorites.filter((entry) => entry.id !== id) })
|
|
3298
|
+
pushLog('info', t('log.favoriteRemoved', { name: favorite?.name ?? id }))
|
|
3299
|
+
}
|
|
3300
|
+
return value
|
|
3301
|
+
},
|
|
3302
|
+
|
|
3303
|
+
/**
|
|
3304
|
+
* Open a saved statement in the workbench of the schema it was saved from.
|
|
3305
|
+
*
|
|
3306
|
+
* Opening by name is what keeps a favorite useful across workspaces: the
|
|
3307
|
+
* statement was written in `bw_order` in one project and is still a `bw_order`
|
|
3308
|
+
* statement in the next tree. When that schema is not in the tree at all, the
|
|
3309
|
+
* log says which one is missing instead of opening an unrelated console.
|
|
3310
|
+
*/
|
|
3311
|
+
openFavorite(favorite) {
|
|
3312
|
+
if (favorite === null || favorite === undefined) return false
|
|
3313
|
+
const target = dwFindDatabaseTarget(state.environments, favorite.database, favorite.env)
|
|
3314
|
+
if (target === undefined) {
|
|
3315
|
+
pushLog('warn', t('log.favoriteNoDatabase', { database: favorite.database }))
|
|
3316
|
+
return false
|
|
3317
|
+
}
|
|
3318
|
+
const opened = store.openDatabase(target.node)
|
|
3319
|
+
const tabId = typeof opened?.id === 'string' ? opened.id : ''
|
|
3320
|
+
if (tabId === '') return false
|
|
3321
|
+
store.appendStatement(tabId, favorite.sql)
|
|
3322
|
+
pushLog('info', t('log.favoriteOpened', { name: favorite.name }))
|
|
3323
|
+
return true
|
|
3324
|
+
},
|
|
3325
|
+
|
|
3326
|
+
/** Append a statement to one console without touching what is already typed. */
|
|
3327
|
+
appendStatement(tabId, sql) {
|
|
3328
|
+
const statement = String(sql ?? '').trim()
|
|
3329
|
+
const tab = state.tabs.find((entry) => entry.id === tabId)
|
|
3330
|
+
if (statement === '' || tab === undefined) return
|
|
3331
|
+
const current = String(tab.sql ?? '').replace(/\s+$/, '')
|
|
3332
|
+
if (current.includes(statement)) {
|
|
3333
|
+
store.setActiveTab(tabId)
|
|
3334
|
+
return
|
|
3335
|
+
}
|
|
3336
|
+
const next = current === '' ? statement : `${current}\n\n${statement}`
|
|
3337
|
+
patch({
|
|
3338
|
+
tabs: state.tabs.map((entry) => (entry.id === tabId
|
|
3339
|
+
? { ...entry, sql: next, result: undefined, error: '' }
|
|
3340
|
+
: entry)),
|
|
3341
|
+
activeTab: tabId,
|
|
3342
|
+
})
|
|
3343
|
+
scheduleConsoles()
|
|
3344
|
+
},
|
|
3345
|
+
|
|
2849
3346
|
/** Delete a whole manually added environment, then re-read the tree. */
|
|
2850
3347
|
async removeManualEnvironment(label) {
|
|
2851
3348
|
const root = state.root
|
|
@@ -2925,10 +3422,6 @@ function dwCreateStore(translate) {
|
|
|
2925
3422
|
void store.loadSchema(node.dbId)
|
|
2926
3423
|
await store.ensureChildren(node)
|
|
2927
3424
|
if (state.loadState.get(node.key) === 'error') return
|
|
2928
|
-
if (node.kind === 'table' || node.kind === 'view') {
|
|
2929
|
-
const tab = state.tabs.find((entry) => entry.kind === 'ddl' && entry.dbId === node.dbId && entry.table === node.table)
|
|
2930
|
-
if (tab !== undefined) await store.refreshDdl(tab.id)
|
|
2931
|
-
}
|
|
2932
3425
|
pushLog('info', t('log.refreshedStructure', { name: node.label }))
|
|
2933
3426
|
},
|
|
2934
3427
|
|
|
@@ -3032,6 +3525,18 @@ function dwCreateStore(translate) {
|
|
|
3032
3525
|
patch({ selected: node?.key ?? '', selectedNode: node ?? null })
|
|
3033
3526
|
},
|
|
3034
3527
|
|
|
3528
|
+
/** Switch the resource manager between the database tree and the favorites. */
|
|
3529
|
+
setTreeTab(tab) {
|
|
3530
|
+
const next = tab === 'favorites' ? 'favorites' : 'databases'
|
|
3531
|
+
if (next === state.treeTab) return
|
|
3532
|
+
try {
|
|
3533
|
+
globalThis.localStorage?.setItem(DW_TREE_TAB_KEY, next)
|
|
3534
|
+
} catch (error) {
|
|
3535
|
+
void error
|
|
3536
|
+
}
|
|
3537
|
+
patch({ treeTab: next })
|
|
3538
|
+
},
|
|
3539
|
+
|
|
3035
3540
|
/**
|
|
3036
3541
|
* Open (or focus) the SQL workbench of one database.
|
|
3037
3542
|
*
|
|
@@ -3163,73 +3668,45 @@ function dwCreateStore(translate) {
|
|
|
3163
3668
|
return tab
|
|
3164
3669
|
},
|
|
3165
3670
|
|
|
3166
|
-
/**
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
patch({ activeTab: id })
|
|
3178
|
-
if (existing.loading !== true && existing.ddl !== '') return
|
|
3179
|
-
await store.refreshDdl(id)
|
|
3180
|
-
return
|
|
3181
|
-
}
|
|
3182
|
-
const tab = {
|
|
3183
|
-
id,
|
|
3184
|
-
kind: 'ddl',
|
|
3185
|
-
title: node.table,
|
|
3186
|
-
env: node.env ?? '',
|
|
3187
|
-
subtitle: [node.env, node.database].filter((part) => typeof part === 'string' && part !== '').join(' · '),
|
|
3188
|
-
dbId: node.dbId,
|
|
3189
|
-
database: node.database,
|
|
3190
|
-
instanceLabel: node.instanceLabel ?? '',
|
|
3191
|
-
table: node.table,
|
|
3192
|
-
ddl: '',
|
|
3193
|
-
columns: [],
|
|
3194
|
-
loading: true,
|
|
3195
|
-
error: '',
|
|
3671
|
+
/** Close one or more tabs and keep the active selection on a neighbour. */
|
|
3672
|
+
closeTabs(ids) {
|
|
3673
|
+
const removing = new Set(Array.isArray(ids) ? ids : [])
|
|
3674
|
+
if (removing.size === 0) return
|
|
3675
|
+
const tabs = state.tabs.filter((tab) => !removing.has(tab.id))
|
|
3676
|
+
let activeTab = state.activeTab
|
|
3677
|
+
if (removing.has(activeTab)) {
|
|
3678
|
+
const index = state.tabs.findIndex((tab) => tab.id === activeTab)
|
|
3679
|
+
const neighbour = state.tabs.slice(index + 1).find((tab) => !removing.has(tab.id))
|
|
3680
|
+
?? state.tabs.slice(0, index).reverse().find((tab) => !removing.has(tab.id))
|
|
3681
|
+
activeTab = neighbour?.id ?? ''
|
|
3196
3682
|
}
|
|
3197
|
-
patch({ tabs
|
|
3198
|
-
|
|
3683
|
+
patch({ tabs, activeTab })
|
|
3684
|
+
// Closing a console is deliberate: drop it from storage now, not later.
|
|
3685
|
+
flushConsoles()
|
|
3199
3686
|
},
|
|
3200
3687
|
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
const tab = state.tabs.find((entry) => entry.id === id)
|
|
3204
|
-
if (tab === undefined || tab.kind !== 'ddl') return
|
|
3205
|
-
patch({ tabs: state.tabs.map((entry) => (entry.id === id ? { ...entry, loading: true, error: '' } : entry)) })
|
|
3206
|
-
try {
|
|
3207
|
-
const value = await call('ddl', { id: tab.dbId, table: tab.table })
|
|
3208
|
-
patch({
|
|
3209
|
-
tabs: state.tabs.map((entry) => (entry.id === id
|
|
3210
|
-
? { ...entry, ddl: value.ddl ?? '', columns: value.columns ?? [], loading: false, error: '' }
|
|
3211
|
-
: entry)),
|
|
3212
|
-
})
|
|
3213
|
-
pushLog('info', t('log.ddl', { table: tab.table, ms: dwDuration(value.statementTime) }))
|
|
3214
|
-
} catch (error) {
|
|
3215
|
-
patch({ tabs: state.tabs.map((entry) => (entry.id === id ? { ...entry, loading: false, error: dwExplainFailure(t, error) } : entry)) })
|
|
3216
|
-
pushLog('error', t('log.loadFailed', { name: tab.table, message: dwExplainFailure(t, error) }))
|
|
3217
|
-
}
|
|
3688
|
+
closeTab(id) {
|
|
3689
|
+
store.closeTabs([id])
|
|
3218
3690
|
},
|
|
3219
3691
|
|
|
3220
|
-
|
|
3221
|
-
|
|
3692
|
+
closeOtherTabs(id) {
|
|
3693
|
+
store.closeTabs(state.tabs.filter((tab) => tab.id !== id).map((tab) => tab.id))
|
|
3694
|
+
},
|
|
3695
|
+
|
|
3696
|
+
closeAllTabs() {
|
|
3697
|
+
store.closeTabs(state.tabs.map((tab) => tab.id))
|
|
3698
|
+
},
|
|
3699
|
+
|
|
3700
|
+
closeTabsToLeft(id) {
|
|
3701
|
+
const index = state.tabs.findIndex((tab) => tab.id === id)
|
|
3702
|
+
if (index <= 0) return
|
|
3703
|
+
store.closeTabs(state.tabs.slice(0, index).map((tab) => tab.id))
|
|
3704
|
+
},
|
|
3705
|
+
|
|
3706
|
+
closeTabsToRight(id) {
|
|
3222
3707
|
const index = state.tabs.findIndex((tab) => tab.id === id)
|
|
3223
3708
|
if (index < 0) return
|
|
3224
|
-
|
|
3225
|
-
let activeTab = state.activeTab
|
|
3226
|
-
if (activeTab === id) {
|
|
3227
|
-
const neighbour = tabs[index] ?? tabs[index - 1]
|
|
3228
|
-
activeTab = neighbour?.id ?? ''
|
|
3229
|
-
}
|
|
3230
|
-
patch({ tabs, activeTab })
|
|
3231
|
-
// Closing a console is deliberate: drop it from storage now, not later.
|
|
3232
|
-
flushConsoles()
|
|
3709
|
+
store.closeTabs(state.tabs.slice(index + 1).map((tab) => tab.id))
|
|
3233
3710
|
},
|
|
3234
3711
|
|
|
3235
3712
|
setActiveTab(id) {
|
|
@@ -3466,7 +3943,7 @@ function dwCreateStore(translate) {
|
|
|
3466
3943
|
*/
|
|
3467
3944
|
|
|
3468
3945
|
/** One nested tree of what the store currently knows, before filtering. */
|
|
3469
|
-
function dwBuildTree(state, tr) {
|
|
3946
|
+
function dwBuildTree(state, tr, mode = 'databases') {
|
|
3470
3947
|
const loadStateOf = (key) => state.loadState.get(key)
|
|
3471
3948
|
const childrenOf = (node, depth) => {
|
|
3472
3949
|
const rows = []
|
|
@@ -3482,7 +3959,12 @@ function dwBuildTree(state, tr) {
|
|
|
3482
3959
|
return rows
|
|
3483
3960
|
}
|
|
3484
3961
|
|
|
3485
|
-
|
|
3962
|
+
// The favorites tab is derived from the saved list, not from `children`: it never
|
|
3963
|
+
// needs a round trip to expand, and a save anywhere in the panel is visible the
|
|
3964
|
+
// moment the store patches the list.
|
|
3965
|
+
if (mode === 'favorites') return dwBuildFavoriteRows(state.favorites, tr)
|
|
3966
|
+
|
|
3967
|
+
const rows = []
|
|
3486
3968
|
for (const environment of state.environments ?? []) {
|
|
3487
3969
|
const envKey = dwNodeKey('env', environment.env)
|
|
3488
3970
|
const instanceRows = []
|
|
@@ -3529,7 +4011,7 @@ function dwBuildTree(state, tr) {
|
|
|
3529
4011
|
children: databaseRows,
|
|
3530
4012
|
})
|
|
3531
4013
|
}
|
|
3532
|
-
|
|
4014
|
+
rows.push({
|
|
3533
4015
|
node: {
|
|
3534
4016
|
key: envKey,
|
|
3535
4017
|
kind: 'env',
|
|
@@ -3543,7 +4025,7 @@ function dwBuildTree(state, tr) {
|
|
|
3543
4025
|
children: instanceRows,
|
|
3544
4026
|
})
|
|
3545
4027
|
}
|
|
3546
|
-
return
|
|
4028
|
+
return rows
|
|
3547
4029
|
}
|
|
3548
4030
|
|
|
3549
4031
|
/** Prune a tree to the nodes that match, keeping their ancestors. */
|
|
@@ -3586,7 +4068,7 @@ function dwFlattenTree(tree, state, filter, depth = 0, into = []) {
|
|
|
3586
4068
|
/** One row per visible node, in display order. */
|
|
3587
4069
|
function dwVisibleRows(state, tr) {
|
|
3588
4070
|
const filter = String(state.filter ?? '').trim().toLowerCase()
|
|
3589
|
-
const tree = dwPruneTree(dwBuildTree(state, tr), filter)
|
|
4071
|
+
const tree = dwPruneTree(dwBuildTree(state, tr, state.treeTab), filter)
|
|
3590
4072
|
return dwFlattenTree(tree, state, filter)
|
|
3591
4073
|
}
|
|
3592
4074
|
|
|
@@ -3599,6 +4081,9 @@ function dwNodeIconName(node) {
|
|
|
3599
4081
|
case 'view': return 'view'
|
|
3600
4082
|
case 'table': return 'table'
|
|
3601
4083
|
case 'column': return node.column?.key === 'PRI' ? 'key' : 'column'
|
|
4084
|
+
case 'favorite': return 'star'
|
|
4085
|
+
case 'favoriteDatabase': return 'database'
|
|
4086
|
+
case 'favoriteTable': return 'table'
|
|
3602
4087
|
case 'retry': return 'refresh'
|
|
3603
4088
|
case 'error': return 'close'
|
|
3604
4089
|
default: return 'panel'
|
|
@@ -3608,9 +4093,11 @@ function dwNodeIconName(node) {
|
|
|
3608
4093
|
function DwTree({ store, state, tr, onContextMenu, onChooseDatabases }) {
|
|
3609
4094
|
const rows = useMemo(
|
|
3610
4095
|
() => dwVisibleRows(state, tr),
|
|
3611
|
-
[state.environments, state.expanded, state.children, state.loadState, state.filter],
|
|
4096
|
+
[state.root, state.treeTab, state.environments, state.expanded, state.children, state.loadState, state.filter, state.favorites, state.favoritesError],
|
|
3612
4097
|
)
|
|
3613
4098
|
|
|
4099
|
+
// A row click only selects: expanding belongs to the twisty (and to double-click
|
|
4100
|
+
// for the kinds whose whole purpose is to be opened).
|
|
3614
4101
|
const activate = (row) => {
|
|
3615
4102
|
const node = row.node
|
|
3616
4103
|
if (node.kind === 'retry') {
|
|
@@ -3618,13 +4105,31 @@ function DwTree({ store, state, tr, onContextMenu, onChooseDatabases }) {
|
|
|
3618
4105
|
return
|
|
3619
4106
|
}
|
|
3620
4107
|
store.select(node)
|
|
4108
|
+
// The favorites branches exist to be browsed, so a single click unfolds them;
|
|
4109
|
+
// every other row keeps the "select only" behaviour of the tree.
|
|
4110
|
+
if (node.kind === 'favoriteDatabase' || node.kind === 'favoriteTable') void store.toggleNode(node)
|
|
4111
|
+
}
|
|
4112
|
+
|
|
4113
|
+
const openRow = (row) => {
|
|
4114
|
+
const node = row.node
|
|
4115
|
+
if (node.kind === 'retry') {
|
|
4116
|
+
store.retryNode(node.retryOf)
|
|
4117
|
+
return
|
|
4118
|
+
}
|
|
4119
|
+
store.select(node)
|
|
4120
|
+
if (node.kind === 'favorite') {
|
|
4121
|
+
store.openFavorite(node.favorite)
|
|
4122
|
+
return
|
|
4123
|
+
}
|
|
3621
4124
|
if (node.kind === 'database') {
|
|
3622
4125
|
store.openDatabase(node)
|
|
3623
|
-
// Opening the workbench also reveals its tables: that is the list the user
|
|
3624
|
-
// came for, and one click is better than two.
|
|
3625
4126
|
if (row.open !== true) void store.toggleNode(node)
|
|
3626
4127
|
return
|
|
3627
4128
|
}
|
|
4129
|
+
if (node.kind === 'table' || node.kind === 'view') {
|
|
4130
|
+
openTableData(row)
|
|
4131
|
+
return
|
|
4132
|
+
}
|
|
3628
4133
|
if (node.kind === 'instance' && (node.databases ?? []).length === 0) {
|
|
3629
4134
|
onChooseDatabases(node)
|
|
3630
4135
|
return
|
|
@@ -3643,14 +4148,21 @@ function DwTree({ store, state, tr, onContextMenu, onChooseDatabases }) {
|
|
|
3643
4148
|
}
|
|
3644
4149
|
|
|
3645
4150
|
if (rows.length === 0) {
|
|
3646
|
-
const
|
|
3647
|
-
|
|
3648
|
-
|
|
4151
|
+
const filtered = String(state.filter ?? '') !== ''
|
|
4152
|
+
const empty = state.treeTab === 'favorites'
|
|
4153
|
+
? filtered
|
|
3649
4154
|
? tr('treeNoMatch')
|
|
3650
|
-
:
|
|
4155
|
+
: String(state.favoritesError ?? '') !== ''
|
|
4156
|
+
? tr('log.favoriteLoadFailed', { message: state.favoritesError })
|
|
4157
|
+
: tr('favoritesEmptyHint')
|
|
4158
|
+
: state.phase === 'loading'
|
|
4159
|
+
? tr('treeLoading')
|
|
4160
|
+
: filtered
|
|
4161
|
+
? tr('treeNoMatch')
|
|
4162
|
+
: tr('treeEmpty')
|
|
3651
4163
|
return h('div', { className: 'dw-tree' }, h('div', { className: 'dw-empty', style: { padding: 18 } }, [
|
|
3652
4164
|
h('div', { key: 't', className: 'dw-empty-hint' }, empty),
|
|
3653
|
-
|
|
4165
|
+
filtered
|
|
3654
4166
|
? h('button', {
|
|
3655
4167
|
key: 'c',
|
|
3656
4168
|
type: 'button',
|
|
@@ -3670,10 +4182,9 @@ function DwTree({ store, state, tr, onContextMenu, onChooseDatabases }) {
|
|
|
3670
4182
|
className: 'dw-node-twisty',
|
|
3671
4183
|
style: { transform: row.open === true ? 'rotate(90deg)' : 'none', transition: 'transform 110ms ease', cursor: 'pointer' },
|
|
3672
4184
|
onClick: (event) => {
|
|
3673
|
-
// The twisty is the only control that collapses a node
|
|
3674
|
-
//
|
|
4185
|
+
// The twisty is the only control that expands or collapses a node;
|
|
4186
|
+
// clicking the row never changes the expansion.
|
|
3675
4187
|
event.stopPropagation()
|
|
3676
|
-
store.select(node)
|
|
3677
4188
|
void store.toggleNode(node)
|
|
3678
4189
|
},
|
|
3679
4190
|
}, row.loading === true ? h(DwIcon, { name: 'spinner', size: 11 }) : h(DwIcon, { name: 'chevron', size: 11 }))
|
|
@@ -3700,7 +4211,7 @@ function DwTree({ store, state, tr, onContextMenu, onChooseDatabases }) {
|
|
|
3700
4211
|
].filter((part) => part !== '').join(' · ')
|
|
3701
4212
|
: `${node.title ?? `${node.label}${node.detail ? ` ${node.detail}` : ''}`}`,
|
|
3702
4213
|
onClick: () => activate(row),
|
|
3703
|
-
onDoubleClick: () => (
|
|
4214
|
+
onDoubleClick: () => openRow(row),
|
|
3704
4215
|
onContextMenu: (event) => {
|
|
3705
4216
|
event.preventDefault()
|
|
3706
4217
|
store.select(node)
|
|
@@ -4367,72 +4878,547 @@ function dwFormatSql(text) {
|
|
|
4367
4878
|
}
|
|
4368
4879
|
|
|
4369
4880
|
|
|
4370
|
-
// ----
|
|
4881
|
+
// ---- 27-favorites.js -----------------------------------------------------
|
|
4371
4882
|
/**
|
|
4372
|
-
*
|
|
4883
|
+
* Saved SQL: the favorites tab's rows, the dialog that names one, and the `@`
|
|
4884
|
+
* index the workbench inserts from.
|
|
4373
4885
|
*
|
|
4374
|
-
* One
|
|
4375
|
-
*
|
|
4376
|
-
*
|
|
4377
|
-
*
|
|
4886
|
+
* One statement is saved with its name, its schema and its table. The favorites
|
|
4887
|
+
* tab groups by schema then table, which is the shape the user recognised the
|
|
4888
|
+
* statement in; the workbench only needs the name, because the caret is already in
|
|
4889
|
+
* a console. Both views read the same list, so a save from one is visible in the
|
|
4890
|
+
* other without a reload.
|
|
4378
4891
|
*/
|
|
4379
4892
|
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
h('span', { key: 'lb', className: 'dw-tab-label' }, tab.title),
|
|
4400
|
-
// Several environments can hold a schema of the same name, so the tab says
|
|
4401
|
-
// which one it is; the full text stays in the tooltip.
|
|
4402
|
-
tab.env !== '' ? h('span', { key: 'env', className: 'dw-badge', style: { marginLeft: 2 } }, tab.env) : null,
|
|
4403
|
-
h('button', {
|
|
4404
|
-
key: 'cl',
|
|
4405
|
-
type: 'button',
|
|
4406
|
-
className: 'dw-tab-close',
|
|
4407
|
-
title: tr('closeTab'),
|
|
4408
|
-
'aria-label': tr('closeTab'),
|
|
4409
|
-
onClick: (event) => {
|
|
4410
|
-
event.stopPropagation()
|
|
4411
|
-
store.closeTab(tab.id)
|
|
4412
|
-
},
|
|
4413
|
-
}, h(DwIcon, { name: 'close', size: 10 })),
|
|
4414
|
-
])
|
|
4415
|
-
}))
|
|
4893
|
+
/** A console's table, from its id (`sql:<dbId>:tbl:<table>`). */
|
|
4894
|
+
function dwTabTableName(tab) {
|
|
4895
|
+
const id = String(tab?.id ?? '')
|
|
4896
|
+
const index = id.indexOf(':tbl:')
|
|
4897
|
+
return index < 0 ? '' : id.slice(index + 5)
|
|
4898
|
+
}
|
|
4899
|
+
|
|
4900
|
+
/** Every schema name the tree knows, for the favorite dialog's datalist. */
|
|
4901
|
+
function dwDatabaseNames(environments) {
|
|
4902
|
+
const names = new Set()
|
|
4903
|
+
for (const environment of Array.isArray(environments) ? environments : []) {
|
|
4904
|
+
for (const instance of Array.isArray(environment?.instances) ? environment.instances : []) {
|
|
4905
|
+
for (const database of Array.isArray(instance?.databases) ? instance.databases : []) {
|
|
4906
|
+
const name = String(database?.name ?? '')
|
|
4907
|
+
if (name !== '') names.add(name)
|
|
4908
|
+
}
|
|
4909
|
+
}
|
|
4910
|
+
}
|
|
4911
|
+
return [...names].sort((left, right) => left.localeCompare(right))
|
|
4416
4912
|
}
|
|
4417
4913
|
|
|
4418
|
-
/**
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4914
|
+
/**
|
|
4915
|
+
* The tree node a favorite's schema name points at.
|
|
4916
|
+
*
|
|
4917
|
+
* A favorite stores a name, not a database id, because the tree is shared and the
|
|
4918
|
+
* same schema may be reachable through another workspace later. The environment
|
|
4919
|
+
* the statement was saved under breaks ties when two environments hold a schema of
|
|
4920
|
+
* the same name.
|
|
4921
|
+
*/
|
|
4922
|
+
function dwFindDatabaseTarget(environments, database, env) {
|
|
4923
|
+
const name = String(database ?? '').trim().toLowerCase()
|
|
4924
|
+
if (name === '') return undefined
|
|
4925
|
+
const preferred = String(env ?? '').trim().toLowerCase()
|
|
4926
|
+
let fallback
|
|
4927
|
+
for (const environment of Array.isArray(environments) ? environments : []) {
|
|
4928
|
+
for (const instance of Array.isArray(environment?.instances) ? environment.instances : []) {
|
|
4929
|
+
for (const entry of Array.isArray(instance?.databases) ? instance.databases : []) {
|
|
4930
|
+
if (String(entry?.name ?? '').toLowerCase() !== name) continue
|
|
4931
|
+
if (typeof entry?.id !== 'string' || entry.id === '') continue
|
|
4932
|
+
const target = {
|
|
4933
|
+
env: environment.env,
|
|
4934
|
+
node: {
|
|
4935
|
+
key: dwNodeKey('db', entry.id),
|
|
4936
|
+
kind: 'database',
|
|
4937
|
+
label: entry.name,
|
|
4938
|
+
detail: '',
|
|
4939
|
+
dbId: entry.id,
|
|
4940
|
+
database: entry.name,
|
|
4941
|
+
env: environment.env,
|
|
4942
|
+
instanceLabel: instance.label ?? '',
|
|
4943
|
+
configured: entry.discovered !== true,
|
|
4944
|
+
},
|
|
4945
|
+
}
|
|
4946
|
+
if (preferred !== '' && String(environment.env ?? '').toLowerCase() === preferred) return target
|
|
4947
|
+
if (fallback === undefined) fallback = target
|
|
4948
|
+
}
|
|
4949
|
+
}
|
|
4950
|
+
}
|
|
4951
|
+
return fallback
|
|
4952
|
+
}
|
|
4953
|
+
|
|
4954
|
+
/** One favorite as a tree leaf. */
|
|
4955
|
+
function dwFavoriteLeaf(favorite) {
|
|
4956
|
+
const reference = [favorite.database, favorite.table].filter((part) => typeof part === 'string' && part !== '').join('.')
|
|
4957
|
+
return {
|
|
4958
|
+
node: {
|
|
4959
|
+
key: dwNodeKey('favorite', favorite.id),
|
|
4960
|
+
kind: 'favorite',
|
|
4961
|
+
label: favorite.name,
|
|
4962
|
+
detail: '',
|
|
4963
|
+
title: `${favorite.name} · ${reference}\n\n${favorite.sql}`,
|
|
4964
|
+
favorite,
|
|
4965
|
+
},
|
|
4966
|
+
children: [],
|
|
4967
|
+
}
|
|
4968
|
+
}
|
|
4969
|
+
|
|
4970
|
+
/**
|
|
4971
|
+
* The favorites tab's rows: schema → table → statement.
|
|
4972
|
+
*
|
|
4973
|
+
* A statement saved without a table name still gets a table group, so the tab
|
|
4974
|
+
* keeps one shape instead of mixing leaves and groups under a schema.
|
|
4975
|
+
*/
|
|
4976
|
+
function dwBuildFavoriteRows(favorites, tr) {
|
|
4977
|
+
const list = (Array.isArray(favorites) ? favorites : []).filter((favorite) => favorite !== null
|
|
4978
|
+
&& typeof favorite === 'object'
|
|
4979
|
+
&& typeof favorite.id === 'string'
|
|
4980
|
+
&& favorite.id !== '')
|
|
4981
|
+
if (list.length === 0) return []
|
|
4982
|
+
const byDatabase = new Map()
|
|
4983
|
+
for (const favorite of list) {
|
|
4984
|
+
const database = String(favorite.database ?? '').trim() || tr('favoriteNoDatabase')
|
|
4985
|
+
const table = String(favorite.table ?? '').trim()
|
|
4986
|
+
const tableKey = table === '' ? '' : table.toLowerCase()
|
|
4987
|
+
if (!byDatabase.has(database)) byDatabase.set(database, new Map())
|
|
4988
|
+
const tables = byDatabase.get(database)
|
|
4989
|
+
if (!tables.has(tableKey)) tables.set(tableKey, { table, favorites: [] })
|
|
4990
|
+
tables.get(tableKey).favorites.push(favorite)
|
|
4991
|
+
}
|
|
4992
|
+
|
|
4993
|
+
const rows = []
|
|
4994
|
+
const databaseNames = [...byDatabase.keys()].sort((left, right) => left.localeCompare(right))
|
|
4995
|
+
for (const databaseName of databaseNames) {
|
|
4996
|
+
const tables = byDatabase.get(databaseName)
|
|
4997
|
+
const tableKeys = [...tables.keys()].sort((left, right) => {
|
|
4998
|
+
if (left === '') return 1
|
|
4999
|
+
if (right === '') return -1
|
|
5000
|
+
return left.localeCompare(right)
|
|
5001
|
+
})
|
|
5002
|
+
const tableRows = []
|
|
5003
|
+
let statementCount = 0
|
|
5004
|
+
for (const tableKey of tableKeys) {
|
|
5005
|
+
const group = tables.get(tableKey)
|
|
5006
|
+
const leaves = group.favorites
|
|
5007
|
+
.slice()
|
|
5008
|
+
.sort((left, right) => String(left.name ?? '').localeCompare(String(right.name ?? '')))
|
|
5009
|
+
.map(dwFavoriteLeaf)
|
|
5010
|
+
statementCount += leaves.length
|
|
5011
|
+
tableRows.push({
|
|
5012
|
+
node: {
|
|
5013
|
+
key: dwNodeKey('favoriteTable', databaseName, tableKey),
|
|
5014
|
+
kind: 'favoriteTable',
|
|
5015
|
+
label: tableKey === '' ? tr('favoriteNoTable') : group.table,
|
|
5016
|
+
detail: `${leaves.length} ${tr('favoritesCount')}`,
|
|
5017
|
+
title: `${databaseName}${tableKey === '' ? '' : `.${group.table}`}`,
|
|
5018
|
+
database: databaseName,
|
|
5019
|
+
table: group.table,
|
|
5020
|
+
},
|
|
5021
|
+
children: leaves,
|
|
5022
|
+
})
|
|
5023
|
+
}
|
|
5024
|
+
rows.push({
|
|
5025
|
+
node: {
|
|
5026
|
+
key: dwNodeKey('favoriteDatabase', databaseName),
|
|
5027
|
+
kind: 'favoriteDatabase',
|
|
5028
|
+
label: databaseName,
|
|
5029
|
+
detail: `${statementCount} ${tr('favoritesCount')}`,
|
|
5030
|
+
title: `${tr('favoritesTitle')} · ${databaseName}`,
|
|
5031
|
+
database: databaseName,
|
|
5032
|
+
},
|
|
5033
|
+
children: tableRows,
|
|
5034
|
+
})
|
|
5035
|
+
}
|
|
5036
|
+
return rows
|
|
5037
|
+
}
|
|
5038
|
+
|
|
5039
|
+
/** Whether an `@` typed at `index` starts a favorite mention rather than `@var`. */
|
|
5040
|
+
function dwFavoriteMentionStart(text, index) {
|
|
5041
|
+
if (index <= 0) return true
|
|
5042
|
+
const before = text[index - 1]
|
|
5043
|
+
return /\s/.test(before) || '(),;=<>+-*/'.includes(before)
|
|
5044
|
+
}
|
|
5045
|
+
|
|
5046
|
+
/** The saved statements matching what was typed after `@`, name first. */
|
|
5047
|
+
function dwFavoriteMatches(favorites, query) {
|
|
5048
|
+
const needle = String(query ?? '').trim().toLowerCase()
|
|
5049
|
+
const list = (Array.isArray(favorites) ? favorites : []).filter((favorite) => favorite !== null
|
|
5050
|
+
&& typeof favorite === 'object'
|
|
5051
|
+
&& typeof favorite.name === 'string')
|
|
5052
|
+
const matched = needle === ''
|
|
5053
|
+
? list
|
|
5054
|
+
: list.filter((favorite) => [favorite.name, favorite.database, favorite.table]
|
|
5055
|
+
.some((value) => String(value ?? '').toLowerCase().includes(needle)))
|
|
5056
|
+
return matched
|
|
5057
|
+
.slice()
|
|
5058
|
+
.sort((left, right) => left.name.localeCompare(right.name))
|
|
5059
|
+
.slice(0, 50)
|
|
5060
|
+
}
|
|
5061
|
+
|
|
5062
|
+
/**
|
|
5063
|
+
* Name one statement and keep it.
|
|
5064
|
+
*
|
|
5065
|
+
* The SQL is a read-only preview: what is collected is exactly the selection (or
|
|
5066
|
+
* the whole editor) the user right-clicked, and a rename or a re-collection is the
|
|
5067
|
+
* way to change it. The schema and table are editable because the console only
|
|
5068
|
+
* knows its own database — a statement that joins another schema is the user's
|
|
5069
|
+
* call, and it is what the tree groups by.
|
|
5070
|
+
*/
|
|
5071
|
+
function DwFavoriteDialog({ store, tr, draft, onClose, onSaved }) {
|
|
5072
|
+
const editing = String(draft?.id ?? '') !== ''
|
|
5073
|
+
const [name, setName] = useState(String(draft?.name ?? ''))
|
|
5074
|
+
const [database, setDatabase] = useState(String(draft?.database ?? ''))
|
|
5075
|
+
const [table, setTable] = useState(String(draft?.table ?? ''))
|
|
5076
|
+
const [saving, setSaving] = useState(false)
|
|
5077
|
+
const [error, setError] = useState('')
|
|
5078
|
+
const sql = String(draft?.sql ?? '')
|
|
5079
|
+
const savingRef = useRef(false)
|
|
5080
|
+
savingRef.current = saving
|
|
5081
|
+
// A Chinese/Japanese name is typed through the IME: its Enter belongs to the
|
|
5082
|
+
// candidate list, not to the dialog. Chromium already flags the composition
|
|
5083
|
+
// keystroke, and the short grace period covers a browser that ends the
|
|
5084
|
+
// composition just before delivering that Enter.
|
|
5085
|
+
const composingRef = useRef(false)
|
|
5086
|
+
const compositionEndedAtRef = useRef(0)
|
|
5087
|
+
const imeBusy = (event) => dwImeComposing(event)
|
|
5088
|
+
|| composingRef.current === true
|
|
5089
|
+
|| Date.now() - compositionEndedAtRef.current < 100
|
|
5090
|
+
const databaseNames = dwDatabaseNames(store.getState?.()?.environments)
|
|
5091
|
+
|
|
5092
|
+
useEffect(() => {
|
|
5093
|
+
const onKey = (event) => {
|
|
5094
|
+
if (event.key !== 'Escape' || savingRef.current) return
|
|
5095
|
+
if (imeBusy(event)) return
|
|
5096
|
+
onClose()
|
|
5097
|
+
}
|
|
5098
|
+
globalThis.addEventListener('keydown', onKey)
|
|
5099
|
+
return () => globalThis.removeEventListener('keydown', onKey)
|
|
5100
|
+
}, [onClose])
|
|
5101
|
+
|
|
5102
|
+
const submit = async () => {
|
|
5103
|
+
if (saving === true) return
|
|
5104
|
+
const nextName = name.trim()
|
|
5105
|
+
const nextDatabase = database.trim()
|
|
5106
|
+
if (nextName === '') {
|
|
5107
|
+
setError(tr('favoriteNameRequired'))
|
|
5108
|
+
return
|
|
5109
|
+
}
|
|
5110
|
+
if (nextDatabase === '') {
|
|
5111
|
+
setError(tr('favoriteDatabaseRequired'))
|
|
5112
|
+
return
|
|
5113
|
+
}
|
|
5114
|
+
// The Host owns the real check; this one only saves a round trip on the
|
|
5115
|
+
// failure the user is most likely to hit while typing a name.
|
|
5116
|
+
const taken = (store.getState?.()?.favorites ?? []).find((favorite) => String(favorite?.name ?? '').trim().toLowerCase() === nextName.toLowerCase()
|
|
5117
|
+
&& favorite?.id !== draft?.id)
|
|
5118
|
+
if (taken !== undefined) {
|
|
5119
|
+
setError(tr('error.duplicateFavorite'))
|
|
5120
|
+
return
|
|
5121
|
+
}
|
|
5122
|
+
setSaving(true)
|
|
5123
|
+
setError('')
|
|
5124
|
+
try {
|
|
5125
|
+
const value = await store.saveFavorite({
|
|
5126
|
+
id: draft?.id,
|
|
5127
|
+
name: nextName,
|
|
5128
|
+
database: nextDatabase,
|
|
5129
|
+
table: table.trim(),
|
|
5130
|
+
env: draft?.env ?? '',
|
|
5131
|
+
sql,
|
|
5132
|
+
})
|
|
5133
|
+
if (typeof onSaved === 'function') onSaved(value?.favorite)
|
|
5134
|
+
onClose()
|
|
5135
|
+
} catch (failure) {
|
|
5136
|
+
setError(dwExplainFailure(tr, failure))
|
|
5137
|
+
setSaving(false)
|
|
5138
|
+
}
|
|
5139
|
+
}
|
|
5140
|
+
|
|
5141
|
+
const field = (key, label, value, onChange, hint, options) => h('label', { key, className: 'dw-form-row' }, [
|
|
5142
|
+
h('span', { key: 'l', className: 'dw-form-label' }, label),
|
|
5143
|
+
h('input', {
|
|
5144
|
+
key: 'i',
|
|
5145
|
+
className: 'dw-form-input',
|
|
5146
|
+
value,
|
|
5147
|
+
spellCheck: false,
|
|
5148
|
+
autoComplete: 'off',
|
|
5149
|
+
autoFocus: options?.focus === true,
|
|
5150
|
+
list: options?.list,
|
|
5151
|
+
maxLength: options?.maxLength,
|
|
5152
|
+
onChange: (event) => onChange(event.target.value),
|
|
5153
|
+
onCompositionStart: () => {
|
|
5154
|
+
composingRef.current = true
|
|
5155
|
+
},
|
|
5156
|
+
onCompositionEnd: () => {
|
|
5157
|
+
composingRef.current = false
|
|
5158
|
+
compositionEndedAtRef.current = Date.now()
|
|
5159
|
+
},
|
|
5160
|
+
onKeyDown: (event) => {
|
|
5161
|
+
if (event.key !== 'Enter') return
|
|
5162
|
+
if (imeBusy(event)) return
|
|
5163
|
+
void submit()
|
|
5164
|
+
},
|
|
5165
|
+
}),
|
|
5166
|
+
hint === undefined ? null : h('span', { key: 'h', className: 'dw-form-hint' }, hint),
|
|
5167
|
+
])
|
|
5168
|
+
|
|
5169
|
+
return h('div', {
|
|
5170
|
+
className: 'dw-modal',
|
|
5171
|
+
onClick: (event) => {
|
|
5172
|
+
if (event.target === event.currentTarget && saving !== true) onClose()
|
|
5173
|
+
},
|
|
5174
|
+
}, h('div', {
|
|
5175
|
+
key: 'card',
|
|
5176
|
+
className: 'dw-modal-card dw-favorite-dialog',
|
|
5177
|
+
role: 'dialog',
|
|
5178
|
+
'aria-modal': 'true',
|
|
5179
|
+
'aria-label': tr(editing ? 'favoriteEditTitle' : 'favoriteSaveTitle'),
|
|
5180
|
+
}, [
|
|
5181
|
+
h('div', { key: 'title', className: 'dw-modal-title' }, [
|
|
5182
|
+
h(DwIcon, { key: 'i', name: 'star', size: 15 }),
|
|
5183
|
+
h('span', { key: 't' }, tr(editing ? 'favoriteEditTitle' : 'favoriteSaveTitle')),
|
|
5184
|
+
]),
|
|
5185
|
+
h('div', { key: 'body', className: 'dw-modal-body' }, h('div', { key: 'form', className: 'dw-form' }, [
|
|
5186
|
+
field('name', tr('favoriteName'), name, setName, tr('favoriteNameHint'), { focus: true, maxLength: 80 }),
|
|
5187
|
+
h('div', { key: 'split', className: 'dw-fav-split' }, [
|
|
5188
|
+
field('database', tr('favoriteDatabase'), database, setDatabase, tr('favoriteDatabaseHint'), { list: 'dw-favorite-databases', maxLength: 64 }),
|
|
5189
|
+
field('table', tr('favoriteTable'), table, setTable, tr('favoriteTableHint'), { maxLength: 64 }),
|
|
5190
|
+
]),
|
|
5191
|
+
h('datalist', { key: 'names', id: 'dw-favorite-databases' }, databaseNames.map((value) => h('option', { key: value, value }))),
|
|
5192
|
+
h('div', { key: 'sql-label', className: 'dw-form-label' }, tr('favoriteSql')),
|
|
5193
|
+
h('pre', { key: 'sql', className: 'dw-fav-sql' }, sql),
|
|
5194
|
+
h('div', { key: 'hint', className: 'dw-ai-note' }, tr('favoriteDialogHint')),
|
|
5195
|
+
error === ''
|
|
5196
|
+
? null
|
|
5197
|
+
: h('div', { key: 'err', className: 'dw-ai-note dw-ai-warn' }, error),
|
|
5198
|
+
])),
|
|
5199
|
+
h('div', { key: 'foot', className: 'dw-modal-foot' }, [
|
|
5200
|
+
h('button', { key: 'cancel', type: 'button', className: 'dw-btn', disabled: saving === true, onClick: onClose }, tr('cancel')),
|
|
5201
|
+
h('button', {
|
|
5202
|
+
key: 'save',
|
|
5203
|
+
type: 'button',
|
|
5204
|
+
className: 'dw-btn dw-btn-accent',
|
|
5205
|
+
disabled: saving === true,
|
|
5206
|
+
onClick: () => void submit(),
|
|
5207
|
+
}, saving === true ? tr('schemaApplying') : tr(editing ? 'favoriteUpdateAction' : 'favoriteSaveAction')),
|
|
5208
|
+
]),
|
|
5209
|
+
]))
|
|
5210
|
+
}
|
|
5211
|
+
|
|
5212
|
+
|
|
5213
|
+
// ---- 30-editor.js --------------------------------------------------------
|
|
5214
|
+
/**
|
|
5215
|
+
* Workbench tabs, the SQL editor and the DDL document.
|
|
5216
|
+
*
|
|
5217
|
+
* One tab per database is what requirement 4 asks for, so the tab id is the
|
|
5218
|
+
* database target id: asking for the same database twice focuses the console that
|
|
5219
|
+
* already exists instead of opening a second one. A tab that needs a second
|
|
5220
|
+
* statement gets its own id from the store, never a rewrite of the first.
|
|
5221
|
+
*/
|
|
5222
|
+
|
|
5223
|
+
/** The reference a tab copies: `schema.table`, or the schema alone. */
|
|
5224
|
+
function dwTabReference(tab) {
|
|
5225
|
+
const database = String(tab?.database ?? '').trim()
|
|
5226
|
+
// Table consoles keep the table in their id (`sql:<dbId>:tbl:<table>`).
|
|
5227
|
+
const id = String(tab?.id ?? '')
|
|
5228
|
+
const table = String(tab?.table ?? '').trim()
|
|
5229
|
+
|| (id.includes(':tbl:') ? id.split(':tbl:').slice(1).join(':tbl:') : '')
|
|
5230
|
+
if (database !== '' && table !== '') return `${database}.${table}`
|
|
5231
|
+
if (database !== '') return database
|
|
5232
|
+
return String(tab?.title ?? '')
|
|
5233
|
+
}
|
|
5234
|
+
|
|
5235
|
+
/** Insert text into the chat composer when it is open; false when it is not. */
|
|
5236
|
+
function dwInsertComposerText(text) {
|
|
5237
|
+
const doc = globalThis.document
|
|
5238
|
+
if (doc === undefined || typeof doc.querySelector !== 'function') return false
|
|
5239
|
+
const seat = doc.querySelector('[data-composer-seat]')
|
|
5240
|
+
if (seat === null) return false
|
|
5241
|
+
const editor = seat.querySelector('[contenteditable="true"], textarea')
|
|
5242
|
+
if (editor === null) return false
|
|
5243
|
+
try {
|
|
5244
|
+
editor.focus()
|
|
5245
|
+
if (editor.tagName === 'TEXTAREA') {
|
|
5246
|
+
const setter = Object.getOwnPropertyDescriptor(globalThis.HTMLTextAreaElement.prototype, 'value')?.set
|
|
5247
|
+
const start = editor.selectionStart ?? editor.value.length
|
|
5248
|
+
const end = editor.selectionEnd ?? start
|
|
5249
|
+
if (typeof setter === 'function') setter.call(editor, `${editor.value.slice(0, start)}${text}${editor.value.slice(end)}`)
|
|
5250
|
+
editor.setSelectionRange(start + text.length, start + text.length)
|
|
5251
|
+
editor.dispatchEvent(new Event('input', { bubbles: true }))
|
|
5252
|
+
return true
|
|
5253
|
+
}
|
|
5254
|
+
const before = editor.textContent
|
|
5255
|
+
const selection = typeof globalThis.getSelection === 'function' ? globalThis.getSelection() : null
|
|
5256
|
+
if (selection === null || selection === undefined) return false
|
|
5257
|
+
const range = doc.createRange()
|
|
5258
|
+
range.selectNodeContents(editor)
|
|
5259
|
+
range.collapse(false)
|
|
5260
|
+
selection.removeAllRanges()
|
|
5261
|
+
selection.addRange(range)
|
|
5262
|
+
doc.execCommand('insertText', false, text)
|
|
5263
|
+
return editor.textContent !== before
|
|
5264
|
+
} catch (error) {
|
|
5265
|
+
void error
|
|
5266
|
+
return false
|
|
5267
|
+
}
|
|
5268
|
+
}
|
|
5269
|
+
|
|
5270
|
+
function DwTabs({ store, state, tr, onFavorite }) {
|
|
5271
|
+
const [menu, setMenu] = useState(null)
|
|
5272
|
+
if ((state.tabs ?? []).length === 0) return null
|
|
5273
|
+
|
|
5274
|
+
const copyReference = (tab) => {
|
|
5275
|
+
const reference = dwTabReference(tab)
|
|
5276
|
+
const write = globalThis.navigator?.clipboard?.writeText?.(reference)
|
|
5277
|
+
if (write === undefined) {
|
|
5278
|
+
store.pushLog('warn', tr('copyUpdateFailed'))
|
|
5279
|
+
return
|
|
5280
|
+
}
|
|
5281
|
+
write
|
|
5282
|
+
.then(() => store.pushLog('info', tr('log.copiedReference', { reference })))
|
|
5283
|
+
.catch(() => store.pushLog('warn', tr('copyUpdateFailed')))
|
|
5284
|
+
}
|
|
5285
|
+
|
|
5286
|
+
const copyReferenceToChat = (tab) => {
|
|
5287
|
+
const reference = dwTabReference(tab)
|
|
5288
|
+
const inserted = dwInsertComposerText(`${reference} `)
|
|
5289
|
+
const write = globalThis.navigator?.clipboard?.writeText?.(reference)
|
|
5290
|
+
if (write !== undefined) write.catch(() => undefined)
|
|
5291
|
+
store.pushLog('info', tr(inserted ? 'log.copiedReferenceToChat' : 'log.copiedReferenceOnly', { reference }))
|
|
5292
|
+
}
|
|
5293
|
+
|
|
5294
|
+
const menuItem = (key, icon, label, disabled, run) => h('button', {
|
|
5295
|
+
key,
|
|
5296
|
+
type: 'button',
|
|
5297
|
+
role: 'menuitem',
|
|
5298
|
+
className: 'dw-tabmenu-item',
|
|
5299
|
+
disabled,
|
|
5300
|
+
onClick: () => {
|
|
5301
|
+
setMenu(null)
|
|
5302
|
+
run()
|
|
5303
|
+
},
|
|
5304
|
+
}, [
|
|
5305
|
+
h('span', { key: 'ic', className: 'dw-tabmenu-icon' }, h(DwIcon, { name: icon, size: 13 })),
|
|
5306
|
+
h('span', { key: 'lb', className: 'dw-tabmenu-label' }, label),
|
|
5307
|
+
])
|
|
5308
|
+
|
|
5309
|
+
const index = menu === null ? -1 : (state.tabs ?? []).findIndex((tab) => tab.id === menu.tab.id)
|
|
5310
|
+
const menuLayer = menu === null ? null : h('div', {
|
|
5311
|
+
key: 'backdrop',
|
|
5312
|
+
className: 'dw-tabmenu-backdrop',
|
|
5313
|
+
onPointerDown: () => setMenu(null),
|
|
5314
|
+
onContextMenu: (event) => {
|
|
5315
|
+
event.preventDefault()
|
|
5316
|
+
setMenu(null)
|
|
5317
|
+
},
|
|
5318
|
+
}, h('div', {
|
|
5319
|
+
key: 'menu',
|
|
5320
|
+
className: 'dw-tabmenu',
|
|
5321
|
+
role: 'menu',
|
|
5322
|
+
'aria-label': tr('tabMenuLabel'),
|
|
5323
|
+
style: { left: menu.x, top: menu.y },
|
|
5324
|
+
onPointerDown: (event) => event.stopPropagation(),
|
|
5325
|
+
}, [
|
|
5326
|
+
menuItem('close', 'close', tr('tabClose'), false, () => store.closeTab(menu.tab.id)),
|
|
5327
|
+
menuItem('close-others', 'layers', tr('tabCloseOthers'), (state.tabs ?? []).length <= 1, () => store.closeOtherTabs(menu.tab.id)),
|
|
5328
|
+
menuItem('close-all', 'stack', tr('tabCloseAll'), false, () => store.closeAllTabs()),
|
|
5329
|
+
menuItem('close-left', 'arrow-left', tr('tabCloseLeft'), index <= 0, () => store.closeTabsToLeft(menu.tab.id)),
|
|
5330
|
+
menuItem('close-right', 'arrow-right', tr('tabCloseRight'), index < 0 || index >= (state.tabs ?? []).length - 1, () => store.closeTabsToRight(menu.tab.id)),
|
|
5331
|
+
h('div', { key: 'sep', className: 'dw-tabmenu-sep' }),
|
|
5332
|
+
menuItem('favorite', 'star', tr('favoriteSave'), String(menu.tab.sql ?? '').trim() === '', () => {
|
|
5333
|
+
if (typeof onFavorite === 'function') onFavorite(menu.tab)
|
|
5334
|
+
}),
|
|
5335
|
+
menuItem('copy-reference', 'copy', tr('copyReference'), false, () => copyReference(menu.tab)),
|
|
5336
|
+
menuItem('copy-reference-chat', 'at', tr('copyReferenceToChat'), false, () => copyReferenceToChat(menu.tab)),
|
|
5337
|
+
]))
|
|
5338
|
+
|
|
5339
|
+
return h(React.Fragment, null, [
|
|
5340
|
+
h('div', { key: 'tabs', className: 'dw-tabs', role: 'tablist' }, state.tabs.map((tab) => {
|
|
5341
|
+
const active = tab.id === state.activeTab
|
|
5342
|
+
return h('div', {
|
|
5343
|
+
key: tab.id,
|
|
5344
|
+
role: 'tab',
|
|
5345
|
+
'aria-selected': active,
|
|
5346
|
+
className: `dw-tab${active ? ' dw-tab-active' : ''}`,
|
|
5347
|
+
title: tab.subtitle ?? tab.title,
|
|
5348
|
+
onClick: () => store.setActiveTab(tab.id),
|
|
5349
|
+
onContextMenu: (event) => {
|
|
5350
|
+
event.preventDefault()
|
|
5351
|
+
// Keep the menu inside the panel, like the code workspace's menu does.
|
|
5352
|
+
const rect = typeof document === 'undefined' ? null : document.querySelector('.dw-root')?.getBoundingClientRect()
|
|
5353
|
+
const left = rect === null || rect === undefined ? 8 : Math.max(8, rect.left + 8)
|
|
5354
|
+
const top = rect === null || rect === undefined ? 8 : Math.max(8, rect.top + 8)
|
|
5355
|
+
const right = (rect === null || rect === undefined ? (globalThis.innerWidth ?? 1200) : rect.right) - 248
|
|
5356
|
+
const bottom = (rect === null || rect === undefined ? (globalThis.innerHeight ?? 800) : rect.bottom) - 268
|
|
5357
|
+
setMenu({
|
|
5358
|
+
x: Math.max(left, Math.min(event.clientX, Math.max(left, right))),
|
|
5359
|
+
y: Math.max(top, Math.min(event.clientY, Math.max(top, bottom))),
|
|
5360
|
+
tab,
|
|
5361
|
+
})
|
|
5362
|
+
},
|
|
5363
|
+
onAuxClick: (event) => {
|
|
5364
|
+
if (event.button === 1) {
|
|
5365
|
+
event.preventDefault()
|
|
5366
|
+
store.closeTab(tab.id)
|
|
5367
|
+
}
|
|
5368
|
+
},
|
|
5369
|
+
}, [
|
|
5370
|
+
h(DwIcon, { key: 'ic', name: 'database', size: 12 }),
|
|
5371
|
+
h('span', { key: 'lb', className: 'dw-tab-label' }, tab.title),
|
|
5372
|
+
// Several environments can hold a schema of the same name, so the tab says
|
|
5373
|
+
// which one it is; the full text stays in the tooltip.
|
|
5374
|
+
tab.env !== '' ? h('span', { key: 'env', className: 'dw-badge', style: { marginLeft: 2 } }, tab.env) : null,
|
|
5375
|
+
h('button', {
|
|
5376
|
+
key: 'cl',
|
|
5377
|
+
type: 'button',
|
|
5378
|
+
className: 'dw-tab-close',
|
|
5379
|
+
title: tr('closeTab'),
|
|
5380
|
+
'aria-label': tr('closeTab'),
|
|
5381
|
+
onClick: (event) => {
|
|
5382
|
+
event.stopPropagation()
|
|
5383
|
+
store.closeTab(tab.id)
|
|
5384
|
+
},
|
|
5385
|
+
}, h(DwIcon, { name: 'close', size: 10 })),
|
|
5386
|
+
])
|
|
5387
|
+
})),
|
|
5388
|
+
menuLayer,
|
|
5389
|
+
])
|
|
5390
|
+
}
|
|
5391
|
+
|
|
5392
|
+
/**
|
|
5393
|
+
* A draggable horizontal divider.
|
|
5394
|
+
*
|
|
5395
|
+
* `invert` is for a handle whose panel grows upward (the run log): dragging up
|
|
5396
|
+
* must make it taller. `onCommit` fires once on release, which is when a caller
|
|
5397
|
+
* should persist the value; writing on every pointermove would hit storage
|
|
5398
|
+
* sixty times a second.
|
|
5399
|
+
*/
|
|
5400
|
+
function DwDragHandle({ value, onChange, min, max, invert, title, onStart, onCommit, onReset }) {
|
|
5401
|
+
return h('div', {
|
|
5402
|
+
className: 'dw-drag',
|
|
4422
5403
|
role: 'separator',
|
|
4423
5404
|
'aria-orientation': 'horizontal',
|
|
4424
|
-
title: '↕',
|
|
5405
|
+
title: title ?? '↕',
|
|
5406
|
+
onDoubleClick: typeof onReset === 'function' ? onReset : undefined,
|
|
4425
5407
|
onPointerDown: (event) => {
|
|
4426
5408
|
event.preventDefault()
|
|
5409
|
+
if (typeof onStart === 'function') onStart()
|
|
4427
5410
|
const startY = event.clientY
|
|
4428
5411
|
const startValue = value
|
|
5412
|
+
const direction = invert === true ? -1 : 1
|
|
5413
|
+
let latest = value
|
|
4429
5414
|
const onMove = (moveEvent) => {
|
|
4430
|
-
|
|
4431
|
-
onChange(
|
|
5415
|
+
latest = Math.min(max, Math.max(min, startValue + (moveEvent.clientY - startY) * direction))
|
|
5416
|
+
onChange(latest)
|
|
4432
5417
|
}
|
|
4433
5418
|
const onUp = () => {
|
|
4434
5419
|
globalThis.removeEventListener('pointermove', onMove)
|
|
4435
5420
|
globalThis.removeEventListener('pointerup', onUp)
|
|
5421
|
+
if (typeof onCommit === 'function') onCommit(latest)
|
|
4436
5422
|
}
|
|
4437
5423
|
globalThis.addEventListener('pointermove', onMove)
|
|
4438
5424
|
globalThis.addEventListener('pointerup', onUp)
|
|
@@ -4474,17 +5460,21 @@ function dwCaretPoint(area, text, caret) {
|
|
|
4474
5460
|
}
|
|
4475
5461
|
|
|
4476
5462
|
/** The SQL editor: highlighted text, completion and one-keystroke formatting. */
|
|
4477
|
-
function DwEditor({ store, tab, tr, onRun, height, schema }) {
|
|
5463
|
+
function DwEditor({ store, tab, tr, onRun, height, schema, favorites }) {
|
|
4478
5464
|
const value = tab.sql ?? ''
|
|
4479
5465
|
const tokens = useMemo(() => dwSqlLex(value), [value])
|
|
4480
5466
|
const lines = useMemo(() => value.split('\n').length, [value])
|
|
5467
|
+
const favoriteList = Array.isArray(favorites) ? favorites : []
|
|
4481
5468
|
const gutterRef = useRef(null)
|
|
4482
5469
|
const areaRef = useRef(null)
|
|
4483
5470
|
const highlightRef = useRef(null)
|
|
4484
5471
|
const completionRef = useRef(null)
|
|
5472
|
+
const mentionRef = useRef(null)
|
|
4485
5473
|
const [completion, setCompletion] = useState(null)
|
|
5474
|
+
const [mention, setMention] = useState(null)
|
|
4486
5475
|
const [editorMenu, setEditorMenu] = useState(null)
|
|
4487
5476
|
const [optimize, setOptimize] = useState(null)
|
|
5477
|
+
const [favoriteDraft, setFavoriteDraft] = useState(null)
|
|
4488
5478
|
|
|
4489
5479
|
useEffect(() => {
|
|
4490
5480
|
const area = areaRef.current
|
|
@@ -4493,8 +5483,15 @@ function DwEditor({ store, tab, tr, onRun, height, schema }) {
|
|
|
4493
5483
|
// lands where the user is about to type.
|
|
4494
5484
|
area.focus()
|
|
4495
5485
|
area.setSelectionRange(area.value.length, area.value.length)
|
|
5486
|
+
setMention(null)
|
|
4496
5487
|
}, [tab.id])
|
|
4497
5488
|
|
|
5489
|
+
// The `@` index reads the machine-wide saved statements; one round trip the
|
|
5490
|
+
// first time a console opens, cached in the store afterwards.
|
|
5491
|
+
useEffect(() => {
|
|
5492
|
+
void store.loadFavorites()
|
|
5493
|
+
}, [store])
|
|
5494
|
+
|
|
4498
5495
|
// The completion list needs the schema of this database; one round trip, cached
|
|
4499
5496
|
// by the store. A failure only degrades the list to keywords.
|
|
4500
5497
|
useEffect(() => {
|
|
@@ -4532,6 +5529,7 @@ function DwEditor({ store, tab, tr, onRun, height, schema }) {
|
|
|
4532
5529
|
// Re-evaluate the caret once the map arrives so the popup appears on its own.
|
|
4533
5530
|
useEffect(() => {
|
|
4534
5531
|
if (schema === undefined) return
|
|
5532
|
+
if (mention !== null) return
|
|
4535
5533
|
const area = areaRef.current
|
|
4536
5534
|
if (area === null || document.activeElement !== area) return
|
|
4537
5535
|
refreshCompletion(value, area.selectionStart)
|
|
@@ -4550,6 +5548,18 @@ function DwEditor({ store, tab, tr, onRun, height, schema }) {
|
|
|
4550
5548
|
else if (bottom > popup.scrollTop + popup.clientHeight) popup.scrollTop = bottom - popup.clientHeight
|
|
4551
5549
|
}, [completion])
|
|
4552
5550
|
|
|
5551
|
+
// Same keyboard-follows-list behaviour for the `@` index.
|
|
5552
|
+
useEffect(() => {
|
|
5553
|
+
const popup = mentionRef.current
|
|
5554
|
+
if (popup === null || mention === null) return
|
|
5555
|
+
const active = popup.querySelector('.dw-complete-row.active')
|
|
5556
|
+
if (active === null) return
|
|
5557
|
+
const top = active.offsetTop
|
|
5558
|
+
const bottom = top + active.offsetHeight
|
|
5559
|
+
if (top < popup.scrollTop) popup.scrollTop = top
|
|
5560
|
+
else if (bottom > popup.scrollTop + popup.clientHeight) popup.scrollTop = bottom - popup.clientHeight
|
|
5561
|
+
}, [mention])
|
|
5562
|
+
|
|
4553
5563
|
const applyCompletion = (item) => {
|
|
4554
5564
|
const current = completion
|
|
4555
5565
|
if (current === null || item === undefined) return
|
|
@@ -4565,6 +5575,54 @@ function DwEditor({ store, tab, tr, onRun, height, schema }) {
|
|
|
4565
5575
|
})
|
|
4566
5576
|
}
|
|
4567
5577
|
|
|
5578
|
+
/**
|
|
5579
|
+
* The text a mention is filtering on, or `undefined` when the caret left it.
|
|
5580
|
+
*
|
|
5581
|
+
* A name may contain spaces (and Chinese), so the popup only ends at characters
|
|
5582
|
+
* that cannot appear in a name the user would type.
|
|
5583
|
+
*/
|
|
5584
|
+
const mentionQueryAt = (text, from, caret) => {
|
|
5585
|
+
if (from < 0 || text[from] !== '@' || caret <= from) return undefined
|
|
5586
|
+
const query = text.slice(from + 1, caret)
|
|
5587
|
+
if (query.length > 60 || /[\r\n,;()]/.test(query)) return undefined
|
|
5588
|
+
// `@ ` is a sentence, not a mention: keep whitespace only once a name started.
|
|
5589
|
+
if (query !== '' && query.trim() === '') return undefined
|
|
5590
|
+
return query
|
|
5591
|
+
}
|
|
5592
|
+
|
|
5593
|
+
/** Grow the mention popup while its query is typed, or close it. */
|
|
5594
|
+
const refreshMention = (area, text, caret) => {
|
|
5595
|
+
const query = mentionQueryAt(text, mention.from, caret)
|
|
5596
|
+
if (query === undefined) {
|
|
5597
|
+
setMention(null)
|
|
5598
|
+
return false
|
|
5599
|
+
}
|
|
5600
|
+
const point = dwCaretPoint(area, text, caret)
|
|
5601
|
+
setMention({ ...mention, to: caret, query, index: 0, left: point.left, top: point.top + 20 })
|
|
5602
|
+
return true
|
|
5603
|
+
}
|
|
5604
|
+
|
|
5605
|
+
/** Put one saved statement where the `@…` token is, and keep the caret after it. */
|
|
5606
|
+
const insertFavorite = (favorite) => {
|
|
5607
|
+
const current = mention
|
|
5608
|
+
if (current === null || favorite === undefined || favorite === null) return
|
|
5609
|
+
const statement = String(favorite.sql ?? '')
|
|
5610
|
+
if (statement.trim() === '') return
|
|
5611
|
+
const next = `${value.slice(0, current.from)}${statement}${value.slice(current.to)}`
|
|
5612
|
+
const position = current.from + statement.length
|
|
5613
|
+
store.setTabSql(tab.id, next)
|
|
5614
|
+
setMention(null)
|
|
5615
|
+
requestAnimationFrame(() => {
|
|
5616
|
+
const area = areaRef.current
|
|
5617
|
+
if (area === null) return
|
|
5618
|
+
area.focus()
|
|
5619
|
+
area.setSelectionRange(position, position)
|
|
5620
|
+
})
|
|
5621
|
+
store.pushLog('info', tr('log.favoriteInserted', { name: favorite.name }))
|
|
5622
|
+
}
|
|
5623
|
+
|
|
5624
|
+
const mentionItems = mention === null ? [] : dwFavoriteMatches(favoriteList, mention.query)
|
|
5625
|
+
|
|
4568
5626
|
const runStatement = () => {
|
|
4569
5627
|
const area = areaRef.current
|
|
4570
5628
|
const selected = area !== null && area.selectionEnd > area.selectionStart
|
|
@@ -4662,6 +5720,28 @@ function DwEditor({ store, tab, tr, onRun, height, schema }) {
|
|
|
4662
5720
|
setOptimize({ sql: text, database: tab.database })
|
|
4663
5721
|
}
|
|
4664
5722
|
|
|
5723
|
+
// Collect the selection when there is one, the whole console otherwise: that is
|
|
5724
|
+
// exactly the statement the user right-clicked. The schema comes from the console
|
|
5725
|
+
// and the table from its id, falling back to the first table the statement names.
|
|
5726
|
+
const openFavorite = () => {
|
|
5727
|
+
const area = areaRef.current
|
|
5728
|
+
const selected = area !== null && area.selectionEnd > area.selectionStart
|
|
5729
|
+
? value.slice(area.selectionStart, area.selectionEnd)
|
|
5730
|
+
: ''
|
|
5731
|
+
const text = selected.trim() === '' ? value.trim() : selected.trim()
|
|
5732
|
+
if (text === '') {
|
|
5733
|
+
store.pushLog('warn', tr('log.noStatement'))
|
|
5734
|
+
return
|
|
5735
|
+
}
|
|
5736
|
+
setFavoriteDraft({
|
|
5737
|
+
sql: text,
|
|
5738
|
+
name: '',
|
|
5739
|
+
database: tab.database,
|
|
5740
|
+
table: dwTabTableName(tab) || (dwSqlTableRefs(text)[0]?.table ?? ''),
|
|
5741
|
+
env: tab.env ?? '',
|
|
5742
|
+
})
|
|
5743
|
+
}
|
|
5744
|
+
|
|
4665
5745
|
const menuItem = (key, label, shortcut, run) => h('button', {
|
|
4666
5746
|
key,
|
|
4667
5747
|
type: 'button',
|
|
@@ -4726,6 +5806,7 @@ function DwEditor({ store, tab, tr, onRun, height, schema }) {
|
|
|
4726
5806
|
menuItem('paste', tr('editorPaste'), '⌘V', () => void editorPaste()),
|
|
4727
5807
|
menuItem('select-all', tr('editorSelectAll'), '⌘A', editorSelectAll),
|
|
4728
5808
|
h('div', { key: 'sep2', className: 'dw-project-sep' }),
|
|
5809
|
+
menuItem('favorite', tr('favoriteSave'), '', openFavorite),
|
|
4729
5810
|
menuItem('optimize', tr('sqlOptimize'), '', openOptimize),
|
|
4730
5811
|
]),
|
|
4731
5812
|
])
|
|
@@ -4755,13 +5836,29 @@ function DwEditor({ store, tab, tr, onRun, height, schema }) {
|
|
|
4755
5836
|
const text = event.target.value
|
|
4756
5837
|
const caret = event.target.selectionStart
|
|
4757
5838
|
store.setTabSql(tab.id, text)
|
|
5839
|
+
if (mention !== null) {
|
|
5840
|
+
// Still inside the same `@…` token: filter it instead of letting the
|
|
5841
|
+
// column list fight the favorites list for the same keystrokes.
|
|
5842
|
+
if (refreshMention(event.target, text, caret)) return
|
|
5843
|
+
}
|
|
5844
|
+
if (caret > 0 && text[caret - 1] === '@' && dwFavoriteMentionStart(text, caret - 1)) {
|
|
5845
|
+
const point = dwCaretPoint(event.target, text, caret)
|
|
5846
|
+
setCompletion(null)
|
|
5847
|
+
setMention({ from: caret - 1, to: caret, query: '', index: 0, left: point.left, top: point.top + 20 })
|
|
5848
|
+
return
|
|
5849
|
+
}
|
|
4758
5850
|
refreshCompletion(text, caret)
|
|
4759
5851
|
},
|
|
4760
|
-
onClick: (event) =>
|
|
5852
|
+
onClick: (event) => {
|
|
5853
|
+
setMention(null)
|
|
5854
|
+
refreshCompletion(event.target.value, event.target.selectionStart)
|
|
5855
|
+
},
|
|
4761
5856
|
onContextMenu: (event) => {
|
|
4762
5857
|
event.preventDefault()
|
|
5858
|
+
setMention(null)
|
|
5859
|
+
setCompletion(null)
|
|
4763
5860
|
const width = 210
|
|
4764
|
-
const height =
|
|
5861
|
+
const height = 300
|
|
4765
5862
|
const maxX = (globalThis.innerWidth ?? 1200) - width
|
|
4766
5863
|
const maxY = (globalThis.innerHeight ?? 800) - height
|
|
4767
5864
|
setEditorMenu({
|
|
@@ -4769,10 +5866,42 @@ function DwEditor({ store, tab, tr, onRun, height, schema }) {
|
|
|
4769
5866
|
y: Math.max(8, Math.min(event.clientY, maxY)),
|
|
4770
5867
|
})
|
|
4771
5868
|
},
|
|
4772
|
-
onBlur: () =>
|
|
5869
|
+
onBlur: () => {
|
|
5870
|
+
setCompletion(null)
|
|
5871
|
+
setMention(null)
|
|
5872
|
+
},
|
|
4773
5873
|
onScroll: (event) => syncScroll(event.target),
|
|
4774
5874
|
onKeyDown: (event) => {
|
|
5875
|
+
// An IME candidate key (Enter to commit, Escape to cancel, arrows to
|
|
5876
|
+
// move through the list) belongs to the IME: never turn it into a
|
|
5877
|
+
// command, a suggestion pick or a run.
|
|
5878
|
+
if (dwImeComposing(event)) return
|
|
4775
5879
|
const modifier = event.metaKey || event.ctrlKey
|
|
5880
|
+
if (mention !== null) {
|
|
5881
|
+
const size = mentionItems.length
|
|
5882
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
5883
|
+
if (size === 0) {
|
|
5884
|
+
setMention(null)
|
|
5885
|
+
return
|
|
5886
|
+
}
|
|
5887
|
+
event.preventDefault()
|
|
5888
|
+
const delta = event.key === 'ArrowDown' ? 1 : -1
|
|
5889
|
+
setMention({ ...mention, index: (mention.index + delta + size) % size })
|
|
5890
|
+
return
|
|
5891
|
+
}
|
|
5892
|
+
if ((event.key === 'Enter' && !modifier) || event.key === 'Tab') {
|
|
5893
|
+
if (size > 0) {
|
|
5894
|
+
event.preventDefault()
|
|
5895
|
+
insertFavorite(mentionItems[Math.min(mention.index, size - 1)])
|
|
5896
|
+
return
|
|
5897
|
+
}
|
|
5898
|
+
}
|
|
5899
|
+
if (event.key === 'Escape') {
|
|
5900
|
+
event.preventDefault()
|
|
5901
|
+
setMention(null)
|
|
5902
|
+
return
|
|
5903
|
+
}
|
|
5904
|
+
}
|
|
4776
5905
|
if (completion !== null) {
|
|
4777
5906
|
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
4778
5907
|
event.preventDefault()
|
|
@@ -4835,6 +5964,32 @@ function DwEditor({ store, tab, tr, onRun, height, schema }) {
|
|
|
4835
5964
|
h('span', { key: 'd', className: 'dw-complete-detail' }, item.detail ?? ''),
|
|
4836
5965
|
h('span', { key: 'k', className: 'dw-complete-kind' }, item.kind === 'column' ? tr('suggestColumn') : item.kind === 'table' ? tr('suggestTable') : tr('suggestKeyword')),
|
|
4837
5966
|
]))),
|
|
5967
|
+
mention === null
|
|
5968
|
+
? null
|
|
5969
|
+
: h('div', {
|
|
5970
|
+
key: 'mention',
|
|
5971
|
+
ref: mentionRef,
|
|
5972
|
+
className: 'dw-complete dw-mention',
|
|
5973
|
+
style: { left: mention.left, top: mention.top },
|
|
5974
|
+
role: 'listbox',
|
|
5975
|
+
'aria-label': tr('favoriteMentionLabel'),
|
|
5976
|
+
}, mentionItems.length === 0
|
|
5977
|
+
? h('div', { key: 'none', className: 'dw-complete-empty' },
|
|
5978
|
+
favoriteList.length === 0 ? tr('favoriteMentionNoFavorites') : tr('favoriteMentionEmpty'))
|
|
5979
|
+
: mentionItems.map((favorite, index) => h('div', {
|
|
5980
|
+
key: favorite.id,
|
|
5981
|
+
role: 'option',
|
|
5982
|
+
'aria-selected': index === mention.index,
|
|
5983
|
+
className: index === mention.index ? 'dw-complete-row active' : 'dw-complete-row',
|
|
5984
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
5985
|
+
onClick: () => insertFavorite(favorite),
|
|
5986
|
+
}, [
|
|
5987
|
+
h('span', { key: 'ic', className: 'dw-node-icon' }, h(DwIcon, { name: 'star', size: 11 })),
|
|
5988
|
+
h('span', { key: 'l', className: 'dw-complete-label' }, favorite.name),
|
|
5989
|
+
h('span', { key: 'd', className: 'dw-complete-detail' },
|
|
5990
|
+
[favorite.database, favorite.table].filter((part) => typeof part === 'string' && part !== '').join('.')),
|
|
5991
|
+
h('span', { key: 'k', className: 'dw-complete-kind' }, tr('suggestFavorite')),
|
|
5992
|
+
]))),
|
|
4838
5993
|
]),
|
|
4839
5994
|
]),
|
|
4840
5995
|
editorMenuLayer,
|
|
@@ -4846,62 +6001,146 @@ function DwEditor({ store, tab, tr, onRun, height, schema }) {
|
|
|
4846
6001
|
database: optimize.database,
|
|
4847
6002
|
onClose: () => setOptimize(null),
|
|
4848
6003
|
}),
|
|
6004
|
+
favoriteDraft === null ? null : h(DwFavoriteDialog, {
|
|
6005
|
+
key: 'favorite',
|
|
6006
|
+
store,
|
|
6007
|
+
tr,
|
|
6008
|
+
draft: favoriteDraft,
|
|
6009
|
+
onClose: () => setFavoriteDraft(null),
|
|
6010
|
+
}),
|
|
4849
6011
|
])
|
|
4850
6012
|
}
|
|
4851
6013
|
|
|
4852
|
-
/** The
|
|
4853
|
-
function
|
|
4854
|
-
const
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
6014
|
+
/** The create statement as a dialog: copy it and close, no work tab involved. */
|
|
6015
|
+
function DwDdlDialog({ node, tr, store, onClose }) {
|
|
6016
|
+
const allTables = node.kind === 'database'
|
|
6017
|
+
const [phase, setPhase] = useState('loading')
|
|
6018
|
+
const [ddl, setDdl] = useState('')
|
|
6019
|
+
const [error, setError] = useState('')
|
|
6020
|
+
const [progress, setProgress] = useState({ done: 0, total: 0 })
|
|
6021
|
+
const [failureCount, setFailureCount] = useState(0)
|
|
6022
|
+
const [count, setCount] = useState(0)
|
|
6023
|
+
|
|
6024
|
+
useEffect(() => {
|
|
6025
|
+
let alive = true
|
|
6026
|
+
const fail = (failure, name) => {
|
|
6027
|
+
if (!alive) return
|
|
6028
|
+
const message = dwExplainFailure(tr, failure)
|
|
6029
|
+
setError(message)
|
|
6030
|
+
setPhase('error')
|
|
6031
|
+
store.pushLog('error', tr('log.loadFailed', { name, message }))
|
|
6032
|
+
}
|
|
6033
|
+
|
|
6034
|
+
const loadTable = async () => {
|
|
6035
|
+
try {
|
|
6036
|
+
const value = await dwRpc('ddl', { id: node.dbId, table: node.table })
|
|
6037
|
+
if (!alive) return
|
|
6038
|
+
setDdl(String(value?.ddl ?? ''))
|
|
6039
|
+
setCount(1)
|
|
6040
|
+
setPhase('done')
|
|
6041
|
+
store.pushLog('info', tr('log.ddl', { table: node.table, ms: dwDuration(value?.statementTime ?? 0) }))
|
|
6042
|
+
} catch (failure) {
|
|
6043
|
+
fail(failure, node.table)
|
|
6044
|
+
}
|
|
6045
|
+
}
|
|
6046
|
+
|
|
6047
|
+
// A whole database: list the tables, then read each statement in turn so the
|
|
6048
|
+
// dialog can show progress and a closed dialog stops issuing round trips.
|
|
6049
|
+
const loadDatabase = async () => {
|
|
6050
|
+
const startedAt = Date.now()
|
|
6051
|
+
try {
|
|
6052
|
+
const listed = await dwRpc('tables', { id: node.dbId })
|
|
6053
|
+
if (!alive) return
|
|
6054
|
+
const names = (Array.isArray(listed?.tables) ? listed.tables : [])
|
|
6055
|
+
.map((table) => String(table?.name ?? ''))
|
|
6056
|
+
.filter((name) => name !== '')
|
|
6057
|
+
setProgress({ done: 0, total: names.length })
|
|
6058
|
+
const parts = []
|
|
6059
|
+
const failures = []
|
|
6060
|
+
for (let index = 0; index < names.length; index += 1) {
|
|
6061
|
+
if (!alive) return
|
|
6062
|
+
try {
|
|
6063
|
+
const value = await dwRpc('ddl', { id: node.dbId, table: names[index] })
|
|
6064
|
+
const text = String(value?.ddl ?? '').trim().replace(/;+$/, '')
|
|
6065
|
+
if (text !== '') parts.push(`-- ${names[index]}\n${text};`)
|
|
6066
|
+
} catch (failure) {
|
|
6067
|
+
failures.push(`${names[index]}: ${dwExplainFailure(tr, failure).replace(/\s+/g, ' ')}`)
|
|
6068
|
+
}
|
|
6069
|
+
if (alive) setProgress({ done: index + 1, total: names.length })
|
|
6070
|
+
}
|
|
6071
|
+
if (!alive) return
|
|
6072
|
+
const failedBlock = failures.length === 0 ? '' : failures.map((line) => `-- ${line}`).join('\n')
|
|
6073
|
+
setDdl([...parts, failedBlock].filter((part) => part !== '').join('\n\n'))
|
|
6074
|
+
setCount(parts.length)
|
|
6075
|
+
setFailureCount(failures.length)
|
|
6076
|
+
setPhase('done')
|
|
6077
|
+
store.pushLog('info', tr('log.ddlAll', { database: node.database, count: parts.length, ms: Date.now() - startedAt }))
|
|
6078
|
+
} catch (failure) {
|
|
6079
|
+
fail(failure, node.database)
|
|
6080
|
+
}
|
|
6081
|
+
}
|
|
4888
6082
|
|
|
4889
|
-
|
|
4890
|
-
|
|
6083
|
+
if (allTables) void loadDatabase()
|
|
6084
|
+
else void loadTable()
|
|
6085
|
+
return () => { alive = false }
|
|
6086
|
+
}, [])
|
|
6087
|
+
|
|
6088
|
+
const loadingHint = allTables && progress.total > 0
|
|
6089
|
+
? `${tr('ddlLoading')} ${progress.done}/${progress.total}`
|
|
6090
|
+
: tr('ddlLoading')
|
|
6091
|
+
const body = phase === 'loading'
|
|
6092
|
+
? h('div', { key: 'loading', className: 'dw-empty', style: { minHeight: 120 } }, [
|
|
4891
6093
|
h(DwIcon, { key: 'i', name: 'spinner', size: 18 }),
|
|
4892
|
-
h('div', { key: 't', className: 'dw-empty-hint' },
|
|
4893
|
-
])
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
6094
|
+
h('div', { key: 't', className: 'dw-empty-hint' }, loadingHint),
|
|
6095
|
+
])
|
|
6096
|
+
: phase === 'error'
|
|
6097
|
+
? h('div', { key: 'error' }, [
|
|
6098
|
+
h('div', { key: 't', className: 'dw-empty-title', style: { color: 'var(--dsw-alias-state-error-primary)', fontSize: 12 } }, tr('ddlFailed')),
|
|
6099
|
+
h('div', { key: 'm', className: 'dw-error-text' }, error),
|
|
6100
|
+
])
|
|
6101
|
+
: h('div', { key: 'done', className: 'dw-ddl-result' }, [
|
|
6102
|
+
failureCount > 0
|
|
6103
|
+
? h('div', { key: 'warn', className: 'dw-log-warn' }, tr('ddlAllPartial', { count: failureCount }))
|
|
6104
|
+
: null,
|
|
6105
|
+
h('pre', { key: 'ddl', className: 'dw-cell-view dw-ddl-code' },
|
|
6106
|
+
ddl === '' ? tr(allTables ? 'ddlAllEmpty' : 'ddlEmpty') : ddl),
|
|
6107
|
+
])
|
|
6108
|
+
|
|
6109
|
+
return h('div', { className: 'dw-modal', onClick: onClose }, h('div', {
|
|
6110
|
+
key: 'card',
|
|
6111
|
+
className: 'dw-modal-card dw-ddl-dialog',
|
|
6112
|
+
onClick: (event) => event.stopPropagation(),
|
|
6113
|
+
}, [
|
|
6114
|
+
h('div', { key: 'title', className: 'dw-modal-title' }, [
|
|
6115
|
+
h(DwIcon, { key: 'i', name: 'ddl', size: 13 }),
|
|
6116
|
+
h('span', { key: 't' }, tr(allTables ? 'menuDdlAll' : 'menuDdl')),
|
|
6117
|
+
h('span', { key: 'p', style: { color: 'var(--dsw-alias-label-secondary)', fontWeight: 400, fontSize: 11 } },
|
|
6118
|
+
[node.env, node.database, node.table].filter((part) => typeof part === 'string' && part !== '').join(' / ')),
|
|
6119
|
+
]),
|
|
6120
|
+
h('div', { key: 'body', className: 'dw-modal-body' }, body),
|
|
6121
|
+
h('div', { key: 'foot', className: 'dw-modal-foot' }, [
|
|
6122
|
+
phase === 'done' && ddl !== ''
|
|
6123
|
+
? h('button', {
|
|
6124
|
+
key: 'copy',
|
|
6125
|
+
type: 'button',
|
|
6126
|
+
className: 'dw-btn',
|
|
6127
|
+
onClick: () => {
|
|
6128
|
+
const write = globalThis.navigator?.clipboard?.writeText?.(ddl)
|
|
6129
|
+
if (write === undefined) {
|
|
6130
|
+
store.pushLog('warn', tr('copyUpdateFailed'))
|
|
6131
|
+
return
|
|
6132
|
+
}
|
|
6133
|
+
write
|
|
6134
|
+
.then(() => store.pushLog('info', allTables
|
|
6135
|
+
? tr('log.copiedDdlAll', { database: node.database, count })
|
|
6136
|
+
: tr('log.copiedDdl', { table: node.table })))
|
|
6137
|
+
.catch(() => store.pushLog('warn', tr('copyUpdateFailed')))
|
|
6138
|
+
},
|
|
6139
|
+
}, [h(DwIcon, { key: 'i', name: 'copy', size: 11 }), h('span', { key: 't' }, tr('copyDdl'))])
|
|
6140
|
+
: null,
|
|
6141
|
+
h('button', { key: 'close', type: 'button', className: 'dw-btn dw-btn-accent', onClick: onClose }, tr('close')),
|
|
6142
|
+
]),
|
|
6143
|
+
]))
|
|
4905
6144
|
}
|
|
4906
6145
|
|
|
4907
6146
|
|
|
@@ -4999,6 +6238,9 @@ const DwGrid = React.memo(function DwGrid({
|
|
|
4999
6238
|
props.title = tr('editingCellHint')
|
|
5000
6239
|
props.onBlur = (event) => onEditCommit(rowIndex, cellIndex, column.name, event.currentTarget.textContent)
|
|
5001
6240
|
props.onKeyDown = (event) => {
|
|
6241
|
+
// Committing an IME candidate with Enter must not blur the editor: the
|
|
6242
|
+
// cell is still being typed, and blur would write the pre-commit value.
|
|
6243
|
+
if (dwImeComposing(event)) return
|
|
5002
6244
|
if (event.key === 'Enter') {
|
|
5003
6245
|
event.preventDefault()
|
|
5004
6246
|
event.currentTarget.blur()
|
|
@@ -5704,6 +6946,19 @@ const DW_SIDE_MAX = 720
|
|
|
5704
6946
|
const DW_SIDE_DEFAULT = 268
|
|
5705
6947
|
const DW_SIDE_KEY = 'dsh-data-window:side-width'
|
|
5706
6948
|
|
|
6949
|
+
/** Bounds for the run log at the bottom of the panel, in pixels. */
|
|
6950
|
+
const DW_LOG_MIN = 72
|
|
6951
|
+
const DW_LOG_DEFAULT = 132
|
|
6952
|
+
const DW_LOG_MAX = 560
|
|
6953
|
+
const DW_LOG_KEY = 'dsh-data-window:log-height'
|
|
6954
|
+
|
|
6955
|
+
/** Stored run-log height, clamped so a bad value cannot hide the workbench. */
|
|
6956
|
+
function dwReadLogHeight() {
|
|
6957
|
+
const raw = Number(globalThis.localStorage?.getItem(DW_LOG_KEY))
|
|
6958
|
+
if (!Number.isFinite(raw) || raw <= 0) return DW_LOG_DEFAULT
|
|
6959
|
+
return Math.min(DW_LOG_MAX, Math.max(DW_LOG_MIN, raw))
|
|
6960
|
+
}
|
|
6961
|
+
|
|
5707
6962
|
/** Wide layouts collapse the navigation column; below this the toggle is a drawer. */
|
|
5708
6963
|
const DW_WIDE_LAYOUT = 1024
|
|
5709
6964
|
|
|
@@ -5880,12 +7135,17 @@ function DwPanel({ store, translate, useSessions, useWorkspaces, pickDirectory }
|
|
|
5880
7135
|
const [menu, setMenu] = useState(null)
|
|
5881
7136
|
const [editorHeight, setEditorHeight] = useState(168)
|
|
5882
7137
|
const [sideWidth, setSideWidth] = useState(() => dwReadSideWidth())
|
|
7138
|
+
const [logHeight, setLogHeight] = useState(() => dwReadLogHeight())
|
|
7139
|
+
const [logDragging, setLogDragging] = useState(false)
|
|
5883
7140
|
const [sidebarHidden, setSidebarHidden] = useState(false)
|
|
5884
7141
|
const [aiOpen, setAiOpen] = useState(false)
|
|
5885
7142
|
const [manualOpen, setManualOpen] = useState(false)
|
|
5886
7143
|
const [schemaTarget, setSchemaTarget] = useState(null)
|
|
7144
|
+
const [ddlTarget, setDdlTarget] = useState(null)
|
|
5887
7145
|
const [renameTarget, setRenameTarget] = useState(null)
|
|
5888
7146
|
const [removeEnvTarget, setRemoveEnvTarget] = useState(null)
|
|
7147
|
+
const [favoriteDraft, setFavoriteDraft] = useState(null)
|
|
7148
|
+
const [removeFavoriteTarget, setRemoveFavoriteTarget] = useState(null)
|
|
5889
7149
|
const aiPrompted = useRef(false)
|
|
5890
7150
|
const panelRef = useRef(null)
|
|
5891
7151
|
const logRef = useRef(null)
|
|
@@ -5904,6 +7164,12 @@ function DwPanel({ store, translate, useSessions, useWorkspaces, pickDirectory }
|
|
|
5904
7164
|
if (detected !== '') store.setDetectedRoot(detected)
|
|
5905
7165
|
}, [detected, store])
|
|
5906
7166
|
|
|
7167
|
+
// Saved statements are shared by every workspace, so they load once when the
|
|
7168
|
+
// panel opens rather than on each discovery.
|
|
7169
|
+
useEffect(() => {
|
|
7170
|
+
void store.loadFavorites()
|
|
7171
|
+
}, [store])
|
|
7172
|
+
|
|
5907
7173
|
// First open of a workspace the rule-based scan cannot read: offer the model
|
|
5908
7174
|
// picker instead of leaving the user with an empty tree and no next step. It
|
|
5909
7175
|
// asks once per mount and only while no model has been chosen yet.
|
|
@@ -5978,6 +7244,20 @@ function DwPanel({ store, translate, useSessions, useWorkspaces, pickDirectory }
|
|
|
5978
7244
|
globalThis.localStorage?.setItem(DW_SIDE_KEY, String(DW_SIDE_DEFAULT))
|
|
5979
7245
|
}
|
|
5980
7246
|
|
|
7247
|
+
/** Keep the run-log height for the next open; release is the write moment. */
|
|
7248
|
+
const persistLogHeight = (height) => {
|
|
7249
|
+
try {
|
|
7250
|
+
globalThis.localStorage?.setItem(DW_LOG_KEY, String(height))
|
|
7251
|
+
} catch (error) {
|
|
7252
|
+
void error
|
|
7253
|
+
}
|
|
7254
|
+
}
|
|
7255
|
+
|
|
7256
|
+
const resetLogHeight = () => {
|
|
7257
|
+
setLogHeight(DW_LOG_DEFAULT)
|
|
7258
|
+
persistLogHeight(DW_LOG_DEFAULT)
|
|
7259
|
+
}
|
|
7260
|
+
|
|
5981
7261
|
// Requirement 3: one keystroke from the selected table to its create statement.
|
|
5982
7262
|
useEffect(() => {
|
|
5983
7263
|
const onKey = (event) => {
|
|
@@ -5986,10 +7266,10 @@ function DwPanel({ store, translate, useSessions, useWorkspaces, pickDirectory }
|
|
|
5986
7266
|
if (!isDdl) return
|
|
5987
7267
|
const selected = store.getState().selectedNode
|
|
5988
7268
|
if (selected === null || selected === undefined) return
|
|
5989
|
-
if (selected.kind !== 'table' && selected.kind !== 'view') return
|
|
7269
|
+
if (selected.kind !== 'table' && selected.kind !== 'view' && selected.kind !== 'database') return
|
|
5990
7270
|
event.preventDefault()
|
|
5991
7271
|
event.stopPropagation()
|
|
5992
|
-
|
|
7272
|
+
setDdlTarget(selected)
|
|
5993
7273
|
}
|
|
5994
7274
|
globalThis.addEventListener('keydown', onKey, true)
|
|
5995
7275
|
return () => globalThis.removeEventListener('keydown', onKey, true)
|
|
@@ -6073,29 +7353,47 @@ function DwPanel({ store, translate, useSessions, useWorkspaces, pickDirectory }
|
|
|
6073
7353
|
title: sidebarHidden ? tr('showSidebar') : tr('hideSidebar'),
|
|
6074
7354
|
'aria-label': sidebarHidden ? tr('showSidebar') : tr('hideSidebar'),
|
|
6075
7355
|
}, h(DwIcon, { name: 'panel', size: 13 })),
|
|
6076
|
-
h('button', {
|
|
6077
|
-
key: 'refresh',
|
|
6078
|
-
type: 'button',
|
|
6079
|
-
className: 'dw-btn',
|
|
6080
|
-
disabled: state.root === '' || state.refreshing === true || state.phase === 'loading',
|
|
6081
|
-
onClick: () => void store.loadDiscovery({ refresh: true }),
|
|
6082
|
-
title: tr('refreshHint'),
|
|
6083
|
-
}, [
|
|
6084
|
-
h(DwIcon, { key: 'i', name: state.refreshing === true || state.phase === 'loading' ? 'spinner' : 'refresh', size: 12 }),
|
|
6085
|
-
h('span', { key: 't' }, tr('refresh')),
|
|
6086
|
-
]),
|
|
6087
7356
|
])
|
|
6088
7357
|
|
|
6089
7358
|
const selectedTable = state.selectedNode !== null
|
|
6090
7359
|
&& state.selectedNode !== undefined
|
|
6091
|
-
&& (state.selectedNode.kind === 'table' || state.selectedNode.kind === 'view')
|
|
7360
|
+
&& (state.selectedNode.kind === 'table' || state.selectedNode.kind === 'view' || state.selectedNode.kind === 'database')
|
|
7361
|
+
|
|
7362
|
+
// The resource manager has two tabs, like DataGrip's Database window: the
|
|
7363
|
+
// configured tree and the saved statements. The tab strip sits above the filter
|
|
7364
|
+
// so the same search applies to whichever list is showing.
|
|
7365
|
+
const treeTab = state.treeTab === 'favorites' ? 'favorites' : 'databases'
|
|
7366
|
+
const treeTabButton = (key, icon, label, count) => h('button', {
|
|
7367
|
+
key,
|
|
7368
|
+
type: 'button',
|
|
7369
|
+
role: 'tab',
|
|
7370
|
+
'aria-selected': treeTab === key,
|
|
7371
|
+
className: treeTab === key ? 'dw-tree-tab on' : 'dw-tree-tab',
|
|
7372
|
+
onClick: () => store.setTreeTab(key),
|
|
7373
|
+
}, [
|
|
7374
|
+
h(DwIcon, { key: 'i', name: icon, size: 12 }),
|
|
7375
|
+
h('span', { key: 'l' }, label),
|
|
7376
|
+
typeof count === 'number' && count > 0
|
|
7377
|
+
? h('span', { key: 'c', className: 'dw-tree-tab-count' }, String(count))
|
|
7378
|
+
: null,
|
|
7379
|
+
])
|
|
6092
7380
|
|
|
6093
7381
|
const side = h('aside', { key: 'side', className: 'dw-side', style: { width: sideWidth } }, [
|
|
6094
7382
|
h('div', { key: 'head', className: 'dw-side-head' }, [
|
|
6095
7383
|
h('span', { key: 't' }, tr('treeTitle')),
|
|
6096
7384
|
h('span', { key: 'sp', className: 'dw-spacer' }),
|
|
6097
7385
|
selectedTable === true ? h('span', { key: 'n' }, tr('ddlShortcutHint')) : null,
|
|
6098
|
-
// These
|
|
7386
|
+
// These belong to the explorer, so they live in the explorer's own header:
|
|
7387
|
+
// re-read the workspace, let a model look at it, or add a connection.
|
|
7388
|
+
h('button', {
|
|
7389
|
+
key: 'reload-workspace',
|
|
7390
|
+
type: 'button',
|
|
7391
|
+
className: 'dw-btn dw-btn-icon',
|
|
7392
|
+
disabled: state.root === '' || state.refreshing === true || state.phase === 'loading',
|
|
7393
|
+
onClick: () => void store.loadDiscovery({ refresh: true }),
|
|
7394
|
+
title: tr('refreshHint'),
|
|
7395
|
+
'aria-label': tr('refresh'),
|
|
7396
|
+
}, h(DwIcon, { key: 'i', name: state.refreshing === true || state.phase === 'loading' ? 'spinner' : 'refresh', size: 12 })),
|
|
6099
7397
|
h('button', {
|
|
6100
7398
|
key: 'ai',
|
|
6101
7399
|
type: 'button',
|
|
@@ -6117,12 +7415,27 @@ function DwPanel({ store, translate, useSessions, useWorkspaces, pickDirectory }
|
|
|
6117
7415
|
'aria-label': tr('manualOpen'),
|
|
6118
7416
|
}, h(DwIcon, { key: 'i', name: 'plus', size: 12 })),
|
|
6119
7417
|
]),
|
|
7418
|
+
h('div', { key: 'tabs', className: 'dw-tree-tabs', role: 'tablist', 'aria-label': tr('treeTabsLabel') }, [
|
|
7419
|
+
treeTabButton('databases', 'database', tr('treeTabDatabases')),
|
|
7420
|
+
treeTabButton('favorites', 'star', tr('favoritesTitle'), (state.favorites ?? []).length),
|
|
7421
|
+
h('span', { key: 'sp', className: 'dw-spacer' }),
|
|
7422
|
+
treeTab === 'favorites'
|
|
7423
|
+
? h('button', {
|
|
7424
|
+
key: 'reload-favorites',
|
|
7425
|
+
type: 'button',
|
|
7426
|
+
className: 'dw-btn dw-btn-icon',
|
|
7427
|
+
title: tr('favoritesReload'),
|
|
7428
|
+
'aria-label': tr('favoritesReload'),
|
|
7429
|
+
onClick: () => void store.loadFavorites({ force: true }),
|
|
7430
|
+
}, h(DwIcon, { key: 'i', name: 'refresh', size: 12 }))
|
|
7431
|
+
: null,
|
|
7432
|
+
]),
|
|
6120
7433
|
h('div', { key: 'filter', style: { padding: '5px 8px', borderBottom: '1px solid var(--dsw-alias-border-l1)' } }, [
|
|
6121
7434
|
h('input', {
|
|
6122
7435
|
key: 'i',
|
|
6123
7436
|
type: 'search',
|
|
6124
7437
|
value: state.filter ?? '',
|
|
6125
|
-
placeholder: tr('filterPlaceholder'),
|
|
7438
|
+
placeholder: tr(treeTab === 'favorites' ? 'filterFavoritesPlaceholder' : 'filterPlaceholder'),
|
|
6126
7439
|
onChange: (event) => store.patch({ filter: event.target.value }),
|
|
6127
7440
|
style: {
|
|
6128
7441
|
width: '100%',
|
|
@@ -6165,12 +7478,31 @@ function DwPanel({ store, translate, useSessions, useWorkspaces, pickDirectory }
|
|
|
6165
7478
|
]))
|
|
6166
7479
|
} else {
|
|
6167
7480
|
main = h('div', { key: 'main', className: 'dw-main' }, [
|
|
6168
|
-
h(DwTabs, {
|
|
7481
|
+
h(DwTabs, {
|
|
7482
|
+
key: 'tabs',
|
|
7483
|
+
store,
|
|
7484
|
+
state,
|
|
7485
|
+
tr,
|
|
7486
|
+
// A console tab can be collected whole: the tab knows its schema and table,
|
|
7487
|
+
// which is exactly what the favorite has to carry.
|
|
7488
|
+
onFavorite: (tab) => {
|
|
7489
|
+
const sql = String(tab.sql ?? '').trim()
|
|
7490
|
+
if (sql === '') {
|
|
7491
|
+
store.pushLog('warn', tr('log.noStatement'))
|
|
7492
|
+
return
|
|
7493
|
+
}
|
|
7494
|
+
setFavoriteDraft({
|
|
7495
|
+
sql,
|
|
7496
|
+
name: '',
|
|
7497
|
+
database: tab.database,
|
|
7498
|
+
table: dwTabTableName(tab),
|
|
7499
|
+
env: tab.env ?? '',
|
|
7500
|
+
})
|
|
7501
|
+
},
|
|
7502
|
+
}),
|
|
6169
7503
|
activeTab === undefined
|
|
6170
7504
|
? h(DwEmpty, { key: 'empty', tr, state, onPick: pickWorkspace, onOpenAi: () => setAiOpen(true), onOpenManual: () => setManualOpen(true) })
|
|
6171
|
-
: activeTab.
|
|
6172
|
-
? h(DwDdlView, { key: activeTab.id, tab: activeTab, tr, store })
|
|
6173
|
-
: h(React.Fragment, { key: activeTab.id }, [
|
|
7505
|
+
: h(React.Fragment, { key: activeTab.id }, [
|
|
6174
7506
|
h(DwEditor, {
|
|
6175
7507
|
key: 'editor',
|
|
6176
7508
|
store,
|
|
@@ -6178,6 +7510,7 @@ function DwPanel({ store, translate, useSessions, useWorkspaces, pickDirectory }
|
|
|
6178
7510
|
tr,
|
|
6179
7511
|
height: editorHeight,
|
|
6180
7512
|
schema: state.schemas?.get(activeTab.dbId),
|
|
7513
|
+
favorites: state.favorites ?? [],
|
|
6181
7514
|
onRun: (statement) => void store.runActiveTab(statement),
|
|
6182
7515
|
}),
|
|
6183
7516
|
h(DwDragHandle, {
|
|
@@ -6192,7 +7525,23 @@ function DwPanel({ store, translate, useSessions, useWorkspaces, pickDirectory }
|
|
|
6192
7525
|
])
|
|
6193
7526
|
}
|
|
6194
7527
|
|
|
6195
|
-
|
|
7528
|
+
// The log grows upward; leave the tab strip plus a usable editor/results area
|
|
7529
|
+
// above it, and never exceed the fixed ceiling.
|
|
7530
|
+
const panelHeight = panelRef.current?.getBoundingClientRect?.().height ?? (globalThis.innerHeight ?? 800)
|
|
7531
|
+
const logMax = Math.max(DW_LOG_MIN + 40, Math.min(DW_LOG_MAX, Math.round(panelHeight - 300)))
|
|
7532
|
+
// A window that shrank after the height was stored must not push the workbench
|
|
7533
|
+
// out of the panel; the stored value is kept for when there is room again.
|
|
7534
|
+
const visibleLogHeight = Math.min(logHeight, logMax)
|
|
7535
|
+
|
|
7536
|
+
const log = h('div', {
|
|
7537
|
+
key: 'log',
|
|
7538
|
+
className: `dw-log${state.logOpen === true ? '' : ' dw-log-collapsed'}`,
|
|
7539
|
+
// An open log follows the stored height; while dragging, the CSS open/close
|
|
7540
|
+
// transition must not lag behind the pointer.
|
|
7541
|
+
style: state.logOpen === true
|
|
7542
|
+
? { height: visibleLogHeight, transition: logDragging === true ? 'none' : undefined }
|
|
7543
|
+
: undefined,
|
|
7544
|
+
}, [
|
|
6196
7545
|
h('div', { key: 'bar', className: 'dw-log-bar' }, [
|
|
6197
7546
|
h('button', {
|
|
6198
7547
|
key: 'toggle',
|
|
@@ -6246,7 +7595,18 @@ function DwPanel({ store, translate, useSessions, useWorkspaces, pickDirectory }
|
|
|
6246
7595
|
left: Math.max(rect === undefined ? 0 : rect.left, left),
|
|
6247
7596
|
top: Math.max(rect === undefined ? 0 : rect.top, top),
|
|
6248
7597
|
},
|
|
6249
|
-
}, dwMenuItems(
|
|
7598
|
+
}, dwMenuItems(
|
|
7599
|
+
menu.node,
|
|
7600
|
+
store,
|
|
7601
|
+
tr,
|
|
7602
|
+
() => setMenu(null),
|
|
7603
|
+
(node) => setSchemaTarget(node),
|
|
7604
|
+
(node) => setRenameTarget(node),
|
|
7605
|
+
(node) => setRemoveEnvTarget(node),
|
|
7606
|
+
(node) => setDdlTarget(node),
|
|
7607
|
+
(favorite) => setFavoriteDraft({ ...favorite }),
|
|
7608
|
+
(favorite) => setRemoveFavoriteTarget(favorite),
|
|
7609
|
+
)),
|
|
6250
7610
|
])
|
|
6251
7611
|
}
|
|
6252
7612
|
|
|
@@ -6266,6 +7626,23 @@ function DwPanel({ store, translate, useSessions, useWorkspaces, pickDirectory }
|
|
|
6266
7626
|
}),
|
|
6267
7627
|
main,
|
|
6268
7628
|
]),
|
|
7629
|
+
state.logOpen === true
|
|
7630
|
+
? h(DwDragHandle, {
|
|
7631
|
+
key: 'log-drag',
|
|
7632
|
+
value: visibleLogHeight,
|
|
7633
|
+
min: DW_LOG_MIN,
|
|
7634
|
+
max: logMax,
|
|
7635
|
+
invert: true,
|
|
7636
|
+
title: tr('resizeLog'),
|
|
7637
|
+
onChange: setLogHeight,
|
|
7638
|
+
onStart: () => setLogDragging(true),
|
|
7639
|
+
onCommit: (height) => {
|
|
7640
|
+
setLogDragging(false)
|
|
7641
|
+
persistLogHeight(height)
|
|
7642
|
+
},
|
|
7643
|
+
onReset: resetLogHeight,
|
|
7644
|
+
})
|
|
7645
|
+
: null,
|
|
6269
7646
|
log,
|
|
6270
7647
|
menuLayer,
|
|
6271
7648
|
aiOpen ? h(DwAiDialog, {
|
|
@@ -6285,6 +7662,13 @@ function DwPanel({ store, translate, useSessions, useWorkspaces, pickDirectory }
|
|
|
6285
7662
|
onClose: () => setManualOpen(false),
|
|
6286
7663
|
onSaved: () => void store.loadDiscovery({ quiet: true }),
|
|
6287
7664
|
}) : null,
|
|
7665
|
+
ddlTarget === null ? null : h(DwDdlDialog, {
|
|
7666
|
+
key: 'ddl-dialog',
|
|
7667
|
+
store,
|
|
7668
|
+
tr,
|
|
7669
|
+
node: ddlTarget,
|
|
7670
|
+
onClose: () => setDdlTarget(null),
|
|
7671
|
+
}),
|
|
6288
7672
|
removeEnvTarget === null ? null : h(DwConfirmDialog, {
|
|
6289
7673
|
key: 'remove-env-dialog',
|
|
6290
7674
|
tr,
|
|
@@ -6312,6 +7696,30 @@ function DwPanel({ store, translate, useSessions, useWorkspaces, pickDirectory }
|
|
|
6312
7696
|
instance: schemaTarget,
|
|
6313
7697
|
onClose: () => setSchemaTarget(null),
|
|
6314
7698
|
}),
|
|
7699
|
+
favoriteDraft === null ? null : h(DwFavoriteDialog, {
|
|
7700
|
+
key: 'favorite-dialog',
|
|
7701
|
+
store,
|
|
7702
|
+
tr,
|
|
7703
|
+
draft: favoriteDraft,
|
|
7704
|
+
onClose: () => setFavoriteDraft(null),
|
|
7705
|
+
onSaved: () => setMenu(null),
|
|
7706
|
+
}),
|
|
7707
|
+
removeFavoriteTarget === null ? null : h(DwConfirmDialog, {
|
|
7708
|
+
key: 'remove-favorite-dialog',
|
|
7709
|
+
tr,
|
|
7710
|
+
title: tr('removeFavoriteTitle'),
|
|
7711
|
+
message: tr('removeFavoriteHint', { name: removeFavoriteTarget.name }),
|
|
7712
|
+
confirmLabel: tr('removeFavoriteConfirm'),
|
|
7713
|
+
onClose: () => setRemoveFavoriteTarget(null),
|
|
7714
|
+
onConfirm: async () => {
|
|
7715
|
+
try {
|
|
7716
|
+
await store.removeFavorite(removeFavoriteTarget.id)
|
|
7717
|
+
} catch (error) {
|
|
7718
|
+
store.pushLog('error', tr('log.favoriteRemoveFailed', { message: dwExplainFailure(tr, error) }))
|
|
7719
|
+
}
|
|
7720
|
+
setRemoveFavoriteTarget(null)
|
|
7721
|
+
},
|
|
7722
|
+
}),
|
|
6315
7723
|
])
|
|
6316
7724
|
}
|
|
6317
7725
|
|
|
@@ -6323,7 +7731,7 @@ function dwClock(date) {
|
|
|
6323
7731
|
}
|
|
6324
7732
|
|
|
6325
7733
|
/** The context menu of one node. */
|
|
6326
|
-
function dwMenuItems(node, store, tr, close, openSchemaDialog, openRenameEnv, openRemoveEnv) {
|
|
7734
|
+
function dwMenuItems(node, store, tr, close, openSchemaDialog, openRenameEnv, openRemoveEnv, openDdlDialog, openFavoriteDialog, confirmRemoveFavorite) {
|
|
6327
7735
|
const items = []
|
|
6328
7736
|
const add = (key, label, shortcut, run, tone) => items.push(h('button', {
|
|
6329
7737
|
key,
|
|
@@ -6335,8 +7743,19 @@ function dwMenuItems(node, store, tr, close, openSchemaDialog, openRenameEnv, op
|
|
|
6335
7743
|
},
|
|
6336
7744
|
}, [h('span', { key: 'l' }, label), shortcut === '' ? null : h('span', { key: 's', className: 'dw-menu-shortcut' }, shortcut)]))
|
|
6337
7745
|
|
|
6338
|
-
if (node.kind === '
|
|
6339
|
-
|
|
7746
|
+
if (node.kind === 'favorite') {
|
|
7747
|
+
const favorite = node.favorite
|
|
7748
|
+
add('open-favorite', tr('menuOpenFavorite'), '', () => store.openFavorite(favorite))
|
|
7749
|
+
add('copy-favorite-sql', tr('menuCopyFavoriteSql'), '', () => {
|
|
7750
|
+
const write = globalThis.navigator?.clipboard?.writeText?.(String(favorite.sql ?? ''))
|
|
7751
|
+
if (write !== undefined) write.then(() => store.pushLog('info', tr('log.favoriteCopied', { name: favorite.name }))).catch(() => undefined)
|
|
7752
|
+
})
|
|
7753
|
+
add('edit-favorite', tr('menuEditFavorite'), '', () => openFavoriteDialog(favorite))
|
|
7754
|
+
add('remove-favorite', tr('menuRemoveFavorite'), '', () => confirmRemoveFavorite(favorite), 'dw-menu-danger')
|
|
7755
|
+
} else if (node.kind === 'favoriteDatabase' || node.kind === 'favoriteTable') {
|
|
7756
|
+
add('expand', tr('menuExpand'), '', () => void store.toggleNode(node))
|
|
7757
|
+
} else if (node.kind === 'table' || node.kind === 'view') {
|
|
7758
|
+
add('ddl', tr('menuDdl'), 'F4', () => openDdlDialog(node))
|
|
6340
7759
|
add('data', tr('menuOpenData'), '', () => {
|
|
6341
7760
|
const statement = `SELECT *\nFROM \`${node.database}\`.\`${node.table}\`\nLIMIT 100`
|
|
6342
7761
|
store.seedStatement(node, statement)
|
|
@@ -6349,6 +7768,7 @@ function dwMenuItems(node, store, tr, close, openSchemaDialog, openRenameEnv, op
|
|
|
6349
7768
|
})
|
|
6350
7769
|
} else if (node.kind === 'database') {
|
|
6351
7770
|
add('open', tr('menuOpenConsole'), '', () => store.openDatabase(node))
|
|
7771
|
+
add('ddl', tr('menuDdlAll'), 'F4', () => openDdlDialog(node))
|
|
6352
7772
|
add('refresh', tr('refreshStructure'), '', () => void store.refreshNode(node))
|
|
6353
7773
|
if (node.remembered === true) {
|
|
6354
7774
|
add('forget-database', tr('forgetDatabase'), '', () => void store.forgetDatabase(node), 'dw-menu-danger')
|
|
@@ -6662,6 +8082,7 @@ function DwSchemaDialog({ store, tr, instance, onClose }) {
|
|
|
6662
8082
|
useEffect(() => {
|
|
6663
8083
|
const onKey = (event) => {
|
|
6664
8084
|
if (event.key !== 'Escape' || savingRef.current) return
|
|
8085
|
+
if (dwImeComposing(event)) return
|
|
6665
8086
|
onClose()
|
|
6666
8087
|
}
|
|
6667
8088
|
globalThis.addEventListener('keydown', onKey)
|
|
@@ -6847,6 +8268,7 @@ function DwManualDialog({ store, tr, onClose, onSaved }) {
|
|
|
6847
8268
|
useEffect(() => {
|
|
6848
8269
|
const onKey = (event) => {
|
|
6849
8270
|
if (event.key !== 'Escape' || savingRef.current) return
|
|
8271
|
+
if (dwImeComposing(event)) return
|
|
6850
8272
|
onClose()
|
|
6851
8273
|
}
|
|
6852
8274
|
globalThis.addEventListener('keydown', onKey)
|
|
@@ -7028,6 +8450,7 @@ function DwRenameEnvDialog({ store, tr, label, onClose, onRenamed }) {
|
|
|
7028
8450
|
useEffect(() => {
|
|
7029
8451
|
const onKey = (event) => {
|
|
7030
8452
|
if (event.key !== 'Escape' || savingRef.current) return
|
|
8453
|
+
if (dwImeComposing(event)) return
|
|
7031
8454
|
onClose()
|
|
7032
8455
|
}
|
|
7033
8456
|
globalThis.addEventListener('keydown', onKey)
|
|
@@ -7081,7 +8504,9 @@ function DwRenameEnvDialog({ store, tr, label, onClose, onRenamed }) {
|
|
|
7081
8504
|
autoComplete: 'off',
|
|
7082
8505
|
onChange: (event) => setValue(event.target.value),
|
|
7083
8506
|
onKeyDown: (event) => {
|
|
7084
|
-
if (event.key
|
|
8507
|
+
if (event.key !== 'Enter') return
|
|
8508
|
+
if (dwImeComposing(event)) return
|
|
8509
|
+
void save()
|
|
7085
8510
|
},
|
|
7086
8511
|
}),
|
|
7087
8512
|
]),
|
|
@@ -7117,6 +8542,7 @@ function DwConfirmDialog({ tr, title, message, confirmLabel, onConfirm, onClose
|
|
|
7117
8542
|
useEffect(() => {
|
|
7118
8543
|
const onKey = (event) => {
|
|
7119
8544
|
if (event.key !== 'Escape' || busyRef.current) return
|
|
8545
|
+
if (dwImeComposing(event)) return
|
|
7120
8546
|
onClose()
|
|
7121
8547
|
}
|
|
7122
8548
|
globalThis.addEventListener('keydown', onKey)
|
|
@@ -7265,6 +8691,7 @@ function DwAiDialog({ store, tr, onClose, onManual }) {
|
|
|
7265
8691
|
const onKey = (event) => {
|
|
7266
8692
|
if (event.key !== 'Escape') return
|
|
7267
8693
|
if (modeRef.current === 'running') return
|
|
8694
|
+
if (dwImeComposing(event)) return
|
|
7268
8695
|
onClose()
|
|
7269
8696
|
}
|
|
7270
8697
|
globalThis.addEventListener('keydown', onKey)
|
|
@@ -7499,6 +8926,97 @@ function DwAiSettingsRow({ tr, prefs, onOpen }) {
|
|
|
7499
8926
|
* overwrite user SQL" rule intact.
|
|
7500
8927
|
*/
|
|
7501
8928
|
|
|
8929
|
+
/** SQL tokens keep whitespace, so the diff can highlight words without reformatting. */
|
|
8930
|
+
const DW_DIFF_TOKEN = /(\s+|[A-Za-z0-9_$]+|[^\sA-Za-z0-9_$]+)/g
|
|
8931
|
+
|
|
8932
|
+
function dwDiffTokenize(text) {
|
|
8933
|
+
const tokens = []
|
|
8934
|
+
DW_DIFF_TOKEN.lastIndex = 0
|
|
8935
|
+
let match
|
|
8936
|
+
const source = String(text ?? '')
|
|
8937
|
+
while ((match = DW_DIFF_TOKEN.exec(source)) !== null) tokens.push({ value: match[1], space: /^\s+$/.test(match[1]) })
|
|
8938
|
+
return tokens
|
|
8939
|
+
}
|
|
8940
|
+
|
|
8941
|
+
/**
|
|
8942
|
+
* Token-level LCS between the two statements.
|
|
8943
|
+
*
|
|
8944
|
+
* Line-based diffs are useless here: a model often returns the same query as one
|
|
8945
|
+
* long line, so every line would look changed. Common prefixes and suffixes are
|
|
8946
|
+
* trimmed first; the matrix is capped so a pathological statement cannot hang the
|
|
8947
|
+
* dialog (the middle is then reported as changed as a whole).
|
|
8948
|
+
*/
|
|
8949
|
+
function dwDiffMarks(leftTokens, rightTokens) {
|
|
8950
|
+
const a = leftTokens.filter((token) => !token.space)
|
|
8951
|
+
const b = rightTokens.filter((token) => !token.space)
|
|
8952
|
+
const removed = new Array(a.length).fill(false)
|
|
8953
|
+
const added = new Array(b.length).fill(false)
|
|
8954
|
+
let start = 0
|
|
8955
|
+
while (start < a.length && start < b.length && a[start].value === b[start].value) start += 1
|
|
8956
|
+
let endA = a.length - 1
|
|
8957
|
+
let endB = b.length - 1
|
|
8958
|
+
while (endA >= start && endB >= start && a[endA].value === b[endB].value) {
|
|
8959
|
+
endA -= 1
|
|
8960
|
+
endB -= 1
|
|
8961
|
+
}
|
|
8962
|
+
const n = endA - start + 1
|
|
8963
|
+
const m = endB - start + 1
|
|
8964
|
+
if (n > 0 && m > 0 && n * m <= 2000000) {
|
|
8965
|
+
const width = m + 1
|
|
8966
|
+
const dp = new Uint32Array((n + 1) * width)
|
|
8967
|
+
for (let i = n - 1; i >= 0; i -= 1) {
|
|
8968
|
+
for (let j = m - 1; j >= 0; j -= 1) {
|
|
8969
|
+
dp[i * width + j] = a[start + i].value === b[start + j].value
|
|
8970
|
+
? dp[(i + 1) * width + j + 1] + 1
|
|
8971
|
+
: Math.max(dp[(i + 1) * width + j], dp[i * width + j + 1])
|
|
8972
|
+
}
|
|
8973
|
+
}
|
|
8974
|
+
let i = 0
|
|
8975
|
+
let j = 0
|
|
8976
|
+
while (i < n && j < m) {
|
|
8977
|
+
if (a[start + i].value === b[start + j].value) {
|
|
8978
|
+
i += 1
|
|
8979
|
+
j += 1
|
|
8980
|
+
} else if (dp[(i + 1) * width + j] >= dp[i * width + j + 1]) {
|
|
8981
|
+
removed[start + i] = true
|
|
8982
|
+
i += 1
|
|
8983
|
+
} else {
|
|
8984
|
+
added[start + j] = true
|
|
8985
|
+
j += 1
|
|
8986
|
+
}
|
|
8987
|
+
}
|
|
8988
|
+
while (i < n) {
|
|
8989
|
+
removed[start + i] = true
|
|
8990
|
+
i += 1
|
|
8991
|
+
}
|
|
8992
|
+
while (j < m) {
|
|
8993
|
+
added[start + j] = true
|
|
8994
|
+
j += 1
|
|
8995
|
+
}
|
|
8996
|
+
} else {
|
|
8997
|
+
for (let i = start; i <= endA; i += 1) removed[i] = true
|
|
8998
|
+
for (let j = start; j <= endB; j += 1) added[j] = true
|
|
8999
|
+
}
|
|
9000
|
+
return { removed, added }
|
|
9001
|
+
}
|
|
9002
|
+
|
|
9003
|
+
/** Render one side: changed significant tokens wrapped, whitespace left alone. */
|
|
9004
|
+
function dwDiffNodes(tokens, marks, className) {
|
|
9005
|
+
const nodes = []
|
|
9006
|
+
let significant = 0
|
|
9007
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
9008
|
+
const token = tokens[index]
|
|
9009
|
+
if (token.space) {
|
|
9010
|
+
nodes.push(token.value)
|
|
9011
|
+
continue
|
|
9012
|
+
}
|
|
9013
|
+
const changed = marks[significant] === true
|
|
9014
|
+
significant += 1
|
|
9015
|
+
nodes.push(changed ? h('span', { key: index, className }, token.value) : token.value)
|
|
9016
|
+
}
|
|
9017
|
+
return nodes
|
|
9018
|
+
}
|
|
9019
|
+
|
|
7502
9020
|
function dwOptimizeModelName(model) {
|
|
7503
9021
|
return String(model?.name ?? model?.model ?? '')
|
|
7504
9022
|
}
|
|
@@ -7508,6 +9026,15 @@ function DwSqlOptimizeDialog({ store, tr, sql, database, onClose }) {
|
|
|
7508
9026
|
const [result, setResult] = useState(null)
|
|
7509
9027
|
const [error, setError] = useState('')
|
|
7510
9028
|
const model = dwAiModel()
|
|
9029
|
+
const leftRef = useRef(null)
|
|
9030
|
+
const rightRef = useRef(null)
|
|
9031
|
+
const originalTokens = useMemo(() => dwDiffTokenize(sql), [sql])
|
|
9032
|
+
const optimizedTokens = useMemo(() => dwDiffTokenize(result?.sql ?? ''), [result?.sql])
|
|
9033
|
+
const diffMarks = useMemo(() => dwDiffMarks(originalTokens, optimizedTokens), [originalTokens, optimizedTokens])
|
|
9034
|
+
const syncScroll = (from, to) => (event) => {
|
|
9035
|
+
const target = to.current
|
|
9036
|
+
if (target !== null) target.scrollTop = event.currentTarget.scrollTop
|
|
9037
|
+
}
|
|
7511
9038
|
|
|
7512
9039
|
useEffect(() => {
|
|
7513
9040
|
if (model === null) {
|
|
@@ -7550,7 +9077,26 @@ function DwSqlOptimizeDialog({ store, tr, sql, database, onClose }) {
|
|
|
7550
9077
|
h('div', { key: 'm', className: 'dw-optimize-model' }, tr('optimizeModelLabel', {
|
|
7551
9078
|
model: dwOptimizeModelName(result?.model) === '' ? tr('aiModelUnknown') : dwOptimizeModelName(result?.model),
|
|
7552
9079
|
})),
|
|
7553
|
-
h('
|
|
9080
|
+
h('div', { key: 'diff', className: 'dw-diff' }, [
|
|
9081
|
+
h('div', { key: 'left', className: 'dw-diff-col' }, [
|
|
9082
|
+
h('div', { key: 'h', className: 'dw-diff-head' }, tr('optimizeOriginal')),
|
|
9083
|
+
h('pre', {
|
|
9084
|
+
key: 'p',
|
|
9085
|
+
className: 'dw-diff-pane',
|
|
9086
|
+
ref: leftRef,
|
|
9087
|
+
onScroll: syncScroll(leftRef, rightRef),
|
|
9088
|
+
}, dwDiffNodes(originalTokens, diffMarks.removed, 'dw-diff-del')),
|
|
9089
|
+
]),
|
|
9090
|
+
h('div', { key: 'right', className: 'dw-diff-col' }, [
|
|
9091
|
+
h('div', { key: 'h', className: 'dw-diff-head' }, tr('optimizeOptimized')),
|
|
9092
|
+
h('pre', {
|
|
9093
|
+
key: 'p',
|
|
9094
|
+
className: 'dw-diff-pane',
|
|
9095
|
+
ref: rightRef,
|
|
9096
|
+
onScroll: syncScroll(rightRef, leftRef),
|
|
9097
|
+
}, dwDiffNodes(optimizedTokens, diffMarks.added, 'dw-diff-add')),
|
|
9098
|
+
]),
|
|
9099
|
+
]),
|
|
7554
9100
|
result?.notes === undefined || result.notes === ''
|
|
7555
9101
|
? null
|
|
7556
9102
|
: h('div', { key: 'notes' }, [
|