zero-db-tool 0.0.0-stage → 1.0.1

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.
@@ -0,0 +1,33 @@
1
+ /** 用内联 SVG 替代 @remixicon/react,避免给宿主增加客户端依赖。 */
2
+ import React from "react";
3
+
4
+ type IconProps = { size?: number; "aria-hidden"?: boolean | "true" | "false" };
5
+
6
+ function icon(path: React.ReactNode, props: IconProps) {
7
+ const size = props.size ?? 16;
8
+ return (
9
+ <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={1.7}
10
+ strokeLinecap="round" strokeLinejoin="round" aria-hidden={props["aria-hidden"] ?? "true"}>
11
+ {path}
12
+ </svg>
13
+ );
14
+ }
15
+
16
+ export function RiDatabase2Line(props: IconProps) {
17
+ return icon(<><ellipse cx="12" cy="5" rx="8" ry="3" /><path d="M4 5v6c0 1.7 3.6 3 8 3s8-1.3 8-3V5" /><path d="M4 11v6c0 1.7 3.6 3 8 3s8-1.3 8-3v-6" /></>, props);
18
+ }
19
+ export function RiDownload2Line(props: IconProps) {
20
+ return icon(<><path d="M12 3v12" /><path d="m7 10 5 5 5-5" /><path d="M4 19h16" /></>, props);
21
+ }
22
+ export function RiUpload2Line(props: IconProps) {
23
+ return icon(<><path d="M12 15V3" /><path d="m7 8 5-5 5 5" /><path d="M4 19h16" /></>, props);
24
+ }
25
+ export function RiPlayLine(props: IconProps) {
26
+ return icon(<path d="M7 4.5v15l12-7.5-12-7.5Z" />, props);
27
+ }
28
+ export function RiRefreshLine(props: IconProps) {
29
+ return icon(<><path d="M20 11a8 8 0 1 0-2.3 6.3" /><path d="M20 4v7h-7" /></>, props);
30
+ }
31
+ export function RiShieldCheckLine(props: IconProps) {
32
+ return icon(<><path d="M12 3 4 6v6c0 5 3.4 8 8 9 4.6-1 8-4 8-9V6l-8-3Z" /><path d="m8.5 12 2.5 2.5 4.5-5" /></>, props);
33
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * 右侧栏入口:antd 数据库工作台。主题令牌从宿主 --dsw-alias-* 解析。
3
+ */
4
+ import React, { useEffect } from "react";
5
+ import { App as AntdApp, ConfigProvider, theme } from "antd";
6
+ import zhCN from "antd/locale/zh_CN";
7
+ import { AntdWorkbench } from "./AntdWorkbench";
8
+ import { isDarkTheme, resolveColor } from "./theme";
9
+ import css from "./workbench.css";
10
+
11
+ const TAB_ID = "zero-db-tool";
12
+ let styleInjected = false;
13
+
14
+ function ensureStyle(): void {
15
+ if (styleInjected || typeof document === "undefined") return;
16
+ const node = document.createElement("style");
17
+ node.setAttribute("data-zero-db-tool", "1");
18
+ node.textContent = css;
19
+ document.head.appendChild(node);
20
+ styleInjected = true;
21
+ }
22
+
23
+ function Body(): React.JSX.Element {
24
+ useEffect(() => { ensureStyle(); }, []);
25
+ const dark = isDarkTheme();
26
+ const token = {
27
+ colorPrimary: resolveColor("--dsw-alias-button-primary-fill", "#1677ff"),
28
+ colorInfo: resolveColor("--dsw-alias-state-business-primary", "#1677ff"),
29
+ colorBgBase: resolveColor("--dsw-alias-bg-base", "#ffffff"),
30
+ colorBgContainer: resolveColor("--dsw-alias-bg-layer-1", "#ffffff"),
31
+ colorText: resolveColor("--dsw-alias-label-primary", "#1a1a1a"),
32
+ colorTextSecondary: resolveColor("--dsw-alias-label-secondary", "#6b7280"),
33
+ colorBorder: resolveColor("--dsw-alias-border-l3", "#d9d9d9"),
34
+ colorBorderSecondary: resolveColor("--dsw-alias-border-l1", "#e5e7eb"),
35
+ borderRadius: 8,
36
+ fontSize: 12,
37
+ controlHeightSM: 24,
38
+ };
39
+ return (
40
+ <ConfigProvider
41
+ locale={zhCN}
42
+ theme={{ algorithm: [dark ? theme.darkAlgorithm : theme.defaultAlgorithm, theme.compactAlgorithm], token }}
43
+ >
44
+ <AntdApp>
45
+ <div className="dbw-host">
46
+ <AntdWorkbench />
47
+ </div>
48
+ </AntdApp>
49
+ </ConfigProvider>
50
+ );
51
+ }
52
+
53
+ function Title(): React.JSX.Element {
54
+ return <span style={{ display: "inline-flex", alignItems: "center", gap: 6 }}>数据库</span>;
55
+ }
56
+
57
+ export const inject = ["slots", "sidebarRightTabs"];
58
+
59
+ export function apply(ctx: {
60
+ effect: (fn: () => unknown, label?: string) => void;
61
+ sidebarRightTabs: { register: (definition: unknown) => unknown };
62
+ slots: { inject: (name: string, fn: () => unknown) => unknown; register: (options: { name: string; key: string }, component: unknown) => unknown };
63
+ }): void {
64
+ ctx.effect(() => ctx.sidebarRightTabs.register({
65
+ id: TAB_ID,
66
+ kind: TAB_ID,
67
+ keepMounted: true,
68
+ priority: "extension",
69
+ title: () => "数据库",
70
+ guide: [{
71
+ id: TAB_ID,
72
+ order: 46,
73
+ title: () => "数据库工作台",
74
+ description: () => "连接管理、表浏览与只读 SQL",
75
+ }],
76
+ }), "zero-db-tool: register tab type");
77
+
78
+ ctx.effect(() => ctx.slots.inject("sidebar.right.pane.tab", () =>
79
+ ctx.slots.register({ name: "sidebar.right.pane.tab", key: TAB_ID }, Body)), "zero-db-tool: register tab body");
80
+
81
+ ctx.effect(() => ctx.slots.inject("sidebar.right.pane.tab.title", () =>
82
+ ctx.slots.register({ name: "sidebar.right.pane.tab.title", key: TAB_ID }, Title)), "zero-db-tool: register tab title");
83
+ }
@@ -0,0 +1,4 @@
1
+ declare module "*.css" {
2
+ const text: string;
3
+ export default text;
4
+ }
@@ -0,0 +1,29 @@
1
+ /* 原页面为 Console 的暖暗主题写死过两处深色(SQL 编辑区),在 DSH 的浅色主题下会突兀。
2
+ * 这里只做主题化覆盖,不改原样式文件,便于对照上游。 */
3
+ .dbw-scope .database-query-panel textarea {
4
+ background: var(--canvas-soft);
5
+ color: var(--ink);
6
+ }
7
+ .dbw-scope .database-query-panel textarea:focus {
8
+ border-color: var(--accent);
9
+ outline: 2px solid color-mix(in srgb, var(--accent) 18%, transparent);
10
+ box-shadow: none;
11
+ }
12
+ .dbw-scope .database-query-panel textarea::placeholder { color: var(--muted); }
13
+ /* 右侧栏通常只有 400–700px:标题与操作挤在一行会把「导出」裁掉。
14
+ * 窄容器下让操作区独占一行并允许换行(原页面在 Console 宽详情栏里不需要)。 */
15
+ @container (max-width: 720px) {
16
+ .dbw-scope .database-connections-header {
17
+ display: grid;
18
+ grid-template-columns: minmax(0, 1fr);
19
+ gap: 8px;
20
+ padding: 12px;
21
+ }
22
+ .dbw-scope .database-header-actions {
23
+ width: 100%;
24
+ justify-content: flex-start;
25
+ }
26
+ .dbw-scope .database-header-actions .btn {
27
+ flex: 1 1 auto;
28
+ }
29
+ }
@@ -0,0 +1,25 @@
1
+ /** 从宿主 CSS 变量解析出 antd 需要的具体颜色值。 */
2
+ export function resolveColor(name: string, fallback: string): string {
3
+ try {
4
+ const probe = document.createElement("div");
5
+ probe.style.color = `var(${name})`;
6
+ probe.style.display = "none";
7
+ document.body.appendChild(probe);
8
+ const color = getComputedStyle(probe).color;
9
+ probe.remove();
10
+ return color && color !== "rgba(0, 0, 0, 0)" ? color : fallback;
11
+ } catch {
12
+ return fallback;
13
+ }
14
+ }
15
+
16
+ export function isDarkTheme(): boolean {
17
+ try {
18
+ const scheme = getComputedStyle(document.documentElement).colorScheme;
19
+ if (scheme.includes("dark")) return true;
20
+ if (scheme.includes("light")) return false;
21
+ return window.matchMedia("(prefers-color-scheme: dark)").matches;
22
+ } catch {
23
+ return false;
24
+ }
25
+ }
@@ -0,0 +1,156 @@
1
+ /* 数据库工作台的本地样式:密度、层次与 hover 细节。 */
2
+ .dbw-app {
3
+ display: flex;
4
+ flex-direction: column;
5
+ height: 100%;
6
+ min-height: 0;
7
+ background: var(--dsw-alias-bg-base, transparent);
8
+ color: var(--dsw-alias-label-primary, inherit);
9
+ font-size: 12px;
10
+ }
11
+ .dbw-topbar {
12
+ display: flex;
13
+ align-items: center;
14
+ justify-content: space-between;
15
+ gap: 8px;
16
+ padding: 10px 12px 6px;
17
+ }
18
+ .dbw-brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
19
+ .dbw-logo {
20
+ width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
21
+ font-size: 15px;
22
+ background: color-mix(in srgb, var(--dsw-alias-button-primary-fill, #1677ff) 12%, transparent);
23
+ color: var(--dsw-alias-button-primary-fill, #1677ff);
24
+ }
25
+ .dbw-title { display: block; font-size: 13px; font-weight: 650; letter-spacing: 0.01em; line-height: 1.2; }
26
+ .dbw-subtitle { display: block; font-size: 10.5px; color: var(--dsw-alias-label-secondary, #888); margin-top: 2px; }
27
+ .dbw-connbar { display: flex; align-items: center; gap: 6px; padding: 0 12px 8px; }
28
+ .dbw-statusline {
29
+ display: flex; align-items: center; gap: 6px;
30
+ padding: 0 12px 8px; font-size: 11px; color: var(--dsw-alias-label-secondary, #888);
31
+ }
32
+ .dbw-statusline .dbw-path { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
33
+
34
+ .dbw-workarea { flex: 1; min-height: 0; display: flex; }
35
+ .dbw-tree {
36
+ display: flex; flex-direction: column; min-height: 0;
37
+ border-right: 1px solid var(--dsw-alias-border-l1, rgb(0 0 0 / 8%));
38
+ background: color-mix(in srgb, var(--dsw-alias-bg-layer-1, #fff) 55%, transparent);
39
+ }
40
+ .dbw-tree-head { display: flex; align-items: center; gap: 6px; padding: 8px 10px 6px; }
41
+ .dbw-section-label {
42
+ font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase;
43
+ color: var(--dsw-alias-label-secondary, #888); white-space: nowrap;
44
+ }
45
+ .dbw-tree-body { flex: 1; min-height: 0; overflow: auto; padding: 0 6px 10px; }
46
+ .dbw-tree-body::-webkit-scrollbar { width: 8px; }
47
+ .dbw-tree-body::-webkit-scrollbar-thumb { background: var(--dsh-scrollbar-thumb, rgb(0 0 0 / 20%)); border-radius: 8px; }
48
+
49
+ .dbw-main { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
50
+ .dbw-main-head {
51
+ display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
52
+ padding: 10px 12px 4px;
53
+ }
54
+ .dbw-table-name { display: block; font-size: 13px; font-weight: 650; line-height: 1.2; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
55
+ .dbw-table-path { display: block; font-size: 10.5px; color: var(--dsw-alias-label-secondary, #888); margin-top: 2px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
56
+ .dbw-main .ant-tabs { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 0 12px; }
57
+ .dbw-main .ant-tabs-nav { margin-bottom: 8px; }
58
+ .dbw-main .ant-tabs-content-holder { flex: 1; min-height: 0; overflow: auto; padding-bottom: 12px; }
59
+
60
+ .dbw-app .ant-table-thead > tr > th {
61
+ background: color-mix(in srgb, var(--dsw-alias-label-primary, #000) 3%, transparent) !important;
62
+ color: var(--dsw-alias-label-secondary, #888);
63
+ font-size: 10px !important;
64
+ letter-spacing: 0.04em;
65
+ text-transform: uppercase;
66
+ font-weight: 600;
67
+ }
68
+ .dbw-app .ant-table-tbody > tr > td {
69
+ font-family: ui-monospace, Consolas, "SF Mono", monospace;
70
+ font-size: 11px;
71
+ }
72
+ .dbw-app .ant-table-tbody > tr:nth-child(even) > td {
73
+ background: color-mix(in srgb, var(--dsw-alias-label-primary, #000) 2.5%, transparent);
74
+ }
75
+ .dbw-app .ant-table-tbody > tr:hover > td {
76
+ background: color-mix(in srgb, var(--dsw-alias-button-primary-fill, #1677ff) 6%, transparent) !important;
77
+ }
78
+ .dbw-app .ant-tree .ant-tree-node-content-wrapper { border-radius: 6px; height: 24px; line-height: 24px; }
79
+ .dbw-app .ant-tree .ant-tree-node-selected {
80
+ background: color-mix(in srgb, var(--dsw-alias-button-primary-fill, #1677ff) 12%, transparent) !important;
81
+ color: var(--dsw-alias-button-primary-fill, #1677ff);
82
+ font-weight: 600;
83
+ }
84
+ .dbw-app .ant-splitter-bar { background: var(--dsw-alias-border-l1, rgb(0 0 0 / 8%)); }
85
+ .dbw-app .ant-empty { margin: 22px 0; }
86
+ .dbw-sql textarea { font-family: ui-monospace, Consolas, "SF Mono", monospace; font-size: 12px; }
87
+ .dbw-empty-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 16px; }
88
+ .dbw-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }
89
+ .dbw-ok { color: var(--dsw-alias-state-success-primary, #2f8e5f); }
90
+ .dbw-bad { color: var(--dsw-alias-state-error-primary, #c0392b); }
91
+ .dbw-main .ant-tabs-content-holder { display: flex; flex-direction: column; }
92
+ .dbw-main .ant-tabs-tabpane { height: 100%; }
93
+ .dbw-grid-wrap { flex: 1; min-height: 0; overflow: auto; }
94
+ .dbw-grid-wrap .ant-table-thead > tr > th { position: sticky; top: 0; z-index: 2; }
95
+ .dbw-rownum { color: var(--dsw-alias-label-secondary, #888); font-size: 10px; }
96
+ .dbw-main {
97
+ margin: 4px 8px 8px 0;
98
+ border: 1px solid var(--dsw-alias-border-l1, rgb(0 0 0 / 8%));
99
+ border-radius: 12px;
100
+ overflow: hidden;
101
+ background: var(--dsw-alias-bg-layer-1, #fff);
102
+ }
103
+ .dbw-tree {
104
+ margin: 4px 6px 8px 8px;
105
+ border: 1px solid var(--dsw-alias-border-l1, rgb(0 0 0 / 8%));
106
+ border-radius: 12px;
107
+ overflow: hidden;
108
+ }
109
+ .dbw-main .ant-tabs { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 0 12px; }
110
+ .dbw-main .ant-tabs-content-holder { flex: 1; min-height: 0; display: flex; overflow: hidden; }
111
+ .dbw-main .ant-tabs-content { flex: 1; min-height: 0; display: flex; }
112
+ .dbw-main .ant-tabs-tabpane { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
113
+ .dbw-footer {
114
+ display: flex; align-items: center; gap: 10px;
115
+ padding: 4px 12px; border-top: 1px solid var(--dsw-alias-border-l1, rgb(0 0 0 / 8%));
116
+ font-size: 10px; color: var(--dsw-alias-label-secondary, #888);
117
+ background: color-mix(in srgb, var(--dsw-alias-bg-layer-1, #fff) 70%, transparent);
118
+ }
119
+ .dbw-footer-grow { flex: 1; }
120
+ /* 宿主的 tab 面板是 flex,这里把 antd App 与我们的根节点接上高度链。 */
121
+ .ant-app:has(> .dbw-host) { height: 100%; display: flex; flex-direction: column; }
122
+ .dbw-host { flex: 1; min-height: 0; display: flex; flex-direction: column; }
123
+ .dbw-app { flex: 1; min-height: 0; }
124
+ .dbw-sql { height: 100%; overflow: auto; padding-right: 2px; }
125
+ .dbw-grid-wrap { overflow: auto; }
126
+ .dbw-tree-body .ant-tree { font-size: 12px; }
127
+ .dbw-tree-body .ant-tree-node-content-wrapper { width: 100%; overflow: hidden; display: flex; align-items: center; gap: 4px; }
128
+ .dbw-tree-body .ant-tree-iconEle { flex: none; }
129
+ .dbw-tree-body .ant-tree-title { flex: 1; min-width: 0; }
130
+ .dbw-tree-body .ant-tree-title { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
131
+ .dbw-tree-body .ant-tree-node-content-wrapper:hover .ant-tree-title { color: var(--dsw-alias-button-primary-fill, #1677ff); }
132
+ .dbw-tree-body .ant-tree-title { display: block; width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
133
+ .dbw-tree-body .ant-tree-switcher { flex: none; }
134
+ .dbw-workarea { flex: 1; min-height: 0; display: flex; overflow: hidden; }
135
+ .dbw-workarea > .dbw-main { margin: 4px 8px 8px; }
136
+ .dbw-tree {
137
+ width: 100%; min-width: 0;
138
+ margin: 4px 0 8px 8px;
139
+ border: 1px solid var(--dsw-alias-border-l1, rgb(0 0 0 / 8%));
140
+ border-radius: 12px;
141
+ overflow: hidden;
142
+ display: flex; flex-direction: column; min-height: 0;
143
+ background: color-mix(in srgb, var(--dsw-alias-bg-layer-1, #fff) 55%, transparent);
144
+ }
145
+ .dbw-tree-drawer { width: 100%; flex: 1 1 auto; margin: 0; border: 0; border-radius: 0; height: 100%; }
146
+ .dbw-main-title { display: flex; align-items: center; gap: 4px; min-width: 0; }
147
+ .dbw-main-title > div { min-width: 0; }
148
+ .dbw-splitter { flex: 1; min-height: 0; display: flex; }
149
+ .dbw-splitter > .ant-splitter-panel { display: flex; min-height: 0; }
150
+ .dbw-splitter .dbw-tree { margin: 4px 0 8px 8px; }
151
+ .dbw-splitter .dbw-main { flex: 1; margin: 4px 8px 8px 6px; }
152
+ .dbw-splitter .ant-splitter-bar { width: 6px !important; }
153
+ .dbw-splitter .ant-splitter-bar:hover { background: color-mix(in srgb, var(--dsw-alias-button-primary-fill, #1677ff) 35%, transparent); }
154
+ /* 只在当前页签显示内容:我们的 flex 规则会盖掉 antd 的 hidden 类。 */
155
+ .dbw-main .ant-tabs-tabpane-hidden { display: none !important; }
156
+ .dbw-main .ant-tabs-tabpane { overflow: auto; }
@@ -0,0 +1,4 @@
1
+ # zero-db-tool bundle patch(dsh.bundle.patch:顶层数组 loader patch entries)
2
+ - insert:
3
+ - id: db-workbench
4
+ name: zero-db-tool