dsh-data-window 0.0.0-stage → 0.1.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.
- package/AGENTS.md +111 -0
- package/CHANGELOG.md +239 -0
- package/LICENSE +21 -0
- package/README.md +146 -2
- package/client.js +7779 -0
- package/cordis.patch.yml +4 -0
- package/docs/BRIDGE.md +100 -0
- package/docs/DESIGN.md +417 -0
- package/docs/DETAIL.md +220 -0
- package/docs/screenshots/ddl.png +0 -0
- package/docs/screenshots/workbench.png +0 -0
- package/icon.svg +30 -0
- package/index.js +180 -0
- package/locale/en.json +286 -0
- package/locale/zh.json +286 -0
- package/package.json +68 -4
- package/src/client/00-css.js +993 -0
- package/src/client/05-icons.js +137 -0
- package/src/client/05-theme.js +107 -0
- package/src/client/06-shortcuts.js +89 -0
- package/src/client/07-bridge.js +193 -0
- package/src/client/10-core.js +1352 -0
- package/src/client/20-tree.js +281 -0
- package/src/client/25-sql.js +631 -0
- package/src/client/30-editor.js +537 -0
- package/src/client/40-results.js +556 -0
- package/src/client/45-export.js +219 -0
- package/src/client/50-panel.js +761 -0
- package/src/client/60-settings.js +180 -0
- package/src/client/63-schema.js +186 -0
- package/src/client/64-manual.js +350 -0
- package/src/client/65-ai.js +320 -0
- package/src/client/66-optimize.js +98 -0
- package/src/client/90-apply.js +183 -0
- package/src/host/ai.js +721 -0
- package/src/host/cache.js +157 -0
- package/src/host/catalog.js +161 -0
- package/src/host/consoles.js +116 -0
- package/src/host/discovery.js +603 -0
- package/src/host/manual.js +276 -0
- package/src/host/mysql.js +650 -0
- package/src/host/remembered.js +225 -0
- package/src/host/rpc.js +487 -0
- package/src/host/shared.js +172 -0
- package/src/host/yaml.js +335 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The plugin's own settings page.
|
|
3
|
+
*
|
|
4
|
+
* It is a `settings.section`, so it gets its own row in DSH's settings navigation
|
|
5
|
+
* (next to the other plugins' pages) instead of being buried in 通用设置. The
|
|
6
|
+
* preferences are display defaults, not project data, so they live in the browser:
|
|
7
|
+
* a different machine is expected to have its own window size and habits.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** Rows the settings page renders; a zero limit means "use the Host config". */
|
|
11
|
+
const DW_LIMIT_CHOICES = [0, 50, 100, 200, 500, 1000, 2000]
|
|
12
|
+
|
|
13
|
+
function DwSettingsSection({ translate, store }) {
|
|
14
|
+
const tr = typeof translate === 'function' ? translate : (key) => key
|
|
15
|
+
const [prefs, setPrefs] = useState(() => dwReadPrefs())
|
|
16
|
+
const [recording, setRecording] = useState(false)
|
|
17
|
+
const [aiOpen, setAiOpen] = useState(false)
|
|
18
|
+
const [recordError, setRecordError] = useState('')
|
|
19
|
+
const themeId = useSyncExternalStore(dwSubscribeTheme, dwSharedTheme, dwSharedTheme)
|
|
20
|
+
const binding = prefs.shortcutOpen ?? dwDefaultOpenShortcut()
|
|
21
|
+
useEffect(() => { dwWatchTheme() }, [])
|
|
22
|
+
|
|
23
|
+
const update = (changes) => {
|
|
24
|
+
const next = dwWritePrefs(changes)
|
|
25
|
+
setPrefs(next)
|
|
26
|
+
if (changes.defaultLimit !== undefined && store !== undefined) {
|
|
27
|
+
const configured = Number(store.getState?.()?.settings?.defaultLimit)
|
|
28
|
+
store.setLimit(next.defaultLimit > 0 ? next.defaultLimit : (Number.isFinite(configured) && configured > 0 ? configured : 200))
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Capture the next combination while "change" is armed. The window-level
|
|
33
|
+
// open-shortcut listener checks the same flag, so the new key does not fire
|
|
34
|
+
// while it is being recorded.
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
globalThis.__dwShortcutRecording = recording
|
|
37
|
+
if (!recording) return undefined
|
|
38
|
+
const onKey = (event) => {
|
|
39
|
+
event.preventDefault()
|
|
40
|
+
event.stopPropagation()
|
|
41
|
+
if (event.key === 'Escape') {
|
|
42
|
+
setRecording(false)
|
|
43
|
+
setRecordError('')
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
if (DW_MODIFIER_KEYS.has(event.key)) return
|
|
47
|
+
const modifiers = dwShortcutModifiers(event)
|
|
48
|
+
if (!modifiers.includes('meta') && !modifiers.includes('ctrl') && !modifiers.includes('alt')) {
|
|
49
|
+
setRecordError(tr('settingsShortcutNeedsModifier'))
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
const next = dwWritePrefs({ shortcutOpen: { code: event.code, modifiers } })
|
|
53
|
+
setPrefs(next)
|
|
54
|
+
setRecording(false)
|
|
55
|
+
setRecordError('')
|
|
56
|
+
}
|
|
57
|
+
globalThis.addEventListener('keydown', onKey, true)
|
|
58
|
+
return () => {
|
|
59
|
+
globalThis.removeEventListener('keydown', onKey, true)
|
|
60
|
+
globalThis.__dwShortcutRecording = false
|
|
61
|
+
}
|
|
62
|
+
}, [recording])
|
|
63
|
+
|
|
64
|
+
const resetShortcut = () => {
|
|
65
|
+
const next = dwWritePrefs({ shortcutOpen: null })
|
|
66
|
+
setPrefs(next)
|
|
67
|
+
setRecording(false)
|
|
68
|
+
setRecordError('')
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const row = (key, label, description, control) => h('div', { key, className: 'dw-settings-row' }, [
|
|
72
|
+
h('div', { key: 'head', className: 'dw-settings-head' }, [
|
|
73
|
+
h('span', { key: 'label', className: 'dw-settings-label' }, label),
|
|
74
|
+
control,
|
|
75
|
+
]),
|
|
76
|
+
h('div', { key: 'desc', className: 'dw-settings-desc' }, description),
|
|
77
|
+
])
|
|
78
|
+
|
|
79
|
+
const section = (key, title, children) => h('div', { key, className: 'dw-settings-section' }, [
|
|
80
|
+
h('div', { key: 'title', className: 'dw-settings-section-title' }, title),
|
|
81
|
+
...children,
|
|
82
|
+
])
|
|
83
|
+
|
|
84
|
+
return h('div', { className: 'dw-settings' }, [
|
|
85
|
+
h('p', { key: 'intro', className: 'dw-settings-intro' }, tr('settingsIntro')),
|
|
86
|
+
section('display', tr('settingsGroupDisplay'), [
|
|
87
|
+
row(
|
|
88
|
+
'sidebar',
|
|
89
|
+
tr('settingsAutoHide'),
|
|
90
|
+
tr('settingsAutoHideHint'),
|
|
91
|
+
h('input', {
|
|
92
|
+
key: 'control',
|
|
93
|
+
type: 'checkbox',
|
|
94
|
+
className: 'dw-settings-check',
|
|
95
|
+
checked: prefs.autoHideSidebar,
|
|
96
|
+
onChange: (event) => update({ autoHideSidebar: event.target.checked }),
|
|
97
|
+
}),
|
|
98
|
+
),
|
|
99
|
+
row(
|
|
100
|
+
'limit',
|
|
101
|
+
tr('settingsLimit'),
|
|
102
|
+
tr('settingsLimitHint'),
|
|
103
|
+
h('select', {
|
|
104
|
+
key: 'control',
|
|
105
|
+
className: 'dw-settings-select',
|
|
106
|
+
value: String(prefs.defaultLimit),
|
|
107
|
+
onChange: (event) => update({ defaultLimit: Number(event.target.value) }),
|
|
108
|
+
}, DW_LIMIT_CHOICES.map((value) => h('option', {
|
|
109
|
+
key: value,
|
|
110
|
+
value: String(value),
|
|
111
|
+
}, value === 0 ? tr('settingsLimitAuto') : String(value)))),
|
|
112
|
+
),
|
|
113
|
+
row(
|
|
114
|
+
'theme',
|
|
115
|
+
tr('settingsTheme'),
|
|
116
|
+
tr('settingsThemeHint'),
|
|
117
|
+
h('span', { key: 'control', className: 'dw-settings-value' }, themeId === '' ? tr('settingsThemeDsh') : themeId),
|
|
118
|
+
),
|
|
119
|
+
]),
|
|
120
|
+
section('ai', tr('settingsGroupAi'), [
|
|
121
|
+
h(DwAiSettingsRow, {
|
|
122
|
+
key: 'model',
|
|
123
|
+
tr,
|
|
124
|
+
prefs,
|
|
125
|
+
onOpen: () => setAiOpen(true),
|
|
126
|
+
}),
|
|
127
|
+
]),
|
|
128
|
+
section('shortcuts', tr('settingsShortcuts'), [
|
|
129
|
+
h('div', { key: 'hint', className: 'dw-settings-desc' }, tr('settingsShortcutsHint')),
|
|
130
|
+
h('div', { key: 'shortcut', className: 'dw-settings-row' }, [
|
|
131
|
+
h('div', { key: 'head', className: 'dw-settings-head' }, [
|
|
132
|
+
h('span', { key: 'label', className: 'dw-settings-label' }, tr('settingsShortcut')),
|
|
133
|
+
h('div', { key: 'right', className: 'dw-settings-shortcut-actions' }, [
|
|
134
|
+
h('span', { key: 'keys', className: recording ? 'dw-settings-key dw-settings-key-live' : 'dw-settings-key' },
|
|
135
|
+
recording ? tr('settingsShortcutRecording') : dwFormatShortcut(binding)),
|
|
136
|
+
h('button', {
|
|
137
|
+
key: 'edit',
|
|
138
|
+
type: 'button',
|
|
139
|
+
className: 'dw-btn',
|
|
140
|
+
onClick: () => {
|
|
141
|
+
setRecording(recording !== true)
|
|
142
|
+
setRecordError('')
|
|
143
|
+
},
|
|
144
|
+
}, recording ? tr('settingsShortcutCancel') : tr('settingsShortcutChange')),
|
|
145
|
+
h('button', {
|
|
146
|
+
key: 'reset',
|
|
147
|
+
type: 'button',
|
|
148
|
+
className: 'dw-btn',
|
|
149
|
+
disabled: prefs.shortcutOpen === null,
|
|
150
|
+
onClick: resetShortcut,
|
|
151
|
+
}, tr('settingsShortcutReset')),
|
|
152
|
+
]),
|
|
153
|
+
]),
|
|
154
|
+
h('div', { key: 'desc', className: 'dw-settings-desc' },
|
|
155
|
+
recording ? tr('settingsShortcutRecordingHint') : tr('settingsShortcutHint')),
|
|
156
|
+
recordError === '' ? null : h('div', { key: 'err', className: 'dw-settings-warn' }, recordError),
|
|
157
|
+
]),
|
|
158
|
+
]),
|
|
159
|
+
section('storage', tr('settingsGroupStorage'), [
|
|
160
|
+
h('div', { key: 'path', className: 'dw-settings-row' }, [
|
|
161
|
+
h('div', { key: 'head', className: 'dw-settings-head' }, [
|
|
162
|
+
h('span', { key: 'label', className: 'dw-settings-label' }, tr('settingsStorage')),
|
|
163
|
+
]),
|
|
164
|
+
h('div', { key: 'desc', className: 'dw-settings-desc' }, tr('settingsStorageHint')),
|
|
165
|
+
h('code', { key: 'value', className: 'dw-settings-path' }, '~/.dsh/storages/dsh-data-window/workspaces/'),
|
|
166
|
+
]),
|
|
167
|
+
]),
|
|
168
|
+
aiOpen === true
|
|
169
|
+
? h(DwAiDialog, {
|
|
170
|
+
key: 'ai-dialog',
|
|
171
|
+
store,
|
|
172
|
+
tr,
|
|
173
|
+
onClose: () => {
|
|
174
|
+
setAiOpen(false)
|
|
175
|
+
setPrefs(dwReadPrefs())
|
|
176
|
+
},
|
|
177
|
+
})
|
|
178
|
+
: null,
|
|
179
|
+
])
|
|
180
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The schema picker.
|
|
3
|
+
*
|
|
4
|
+
* An instance carries far more schemas than the project's configuration names, and
|
|
5
|
+
* dropping all of them into the tree buries the few a user actually works with. This
|
|
6
|
+
* dialog is the explicit choice: every schema the server reports on the left of a
|
|
7
|
+
* checkbox, the configured ones locked on, and only the checked ones reach the tree.
|
|
8
|
+
*
|
|
9
|
+
* What the user picks is stored per workspace by the Host (`selectDatabases`), so
|
|
10
|
+
* the choice survives a restart and a browser change.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The "choose databases" modal for one instance.
|
|
15
|
+
*
|
|
16
|
+
* @param props `{ store, tr, instance, onClose }`; `instance` is the tree node, which
|
|
17
|
+
* carries the configured databases and the id the server answers for
|
|
18
|
+
*/
|
|
19
|
+
function DwSchemaDialog({ store, tr, instance, onClose }) {
|
|
20
|
+
const [phase, setPhase] = useState('loading')
|
|
21
|
+
const [schemas, setSchemas] = useState([])
|
|
22
|
+
const [checked, setChecked] = useState(() => new Set((instance?.databases ?? []).map((database) => database.name)))
|
|
23
|
+
const [locked] = useState(() => new Set((instance?.databases ?? [])
|
|
24
|
+
.filter((database) => database.remembered !== true)
|
|
25
|
+
.map((database) => database.name)))
|
|
26
|
+
const [query, setQuery] = useState('')
|
|
27
|
+
const [saving, setSaving] = useState(false)
|
|
28
|
+
const [error, setError] = useState('')
|
|
29
|
+
const savingRef = useRef(false)
|
|
30
|
+
savingRef.current = saving
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
const onKey = (event) => {
|
|
34
|
+
if (event.key !== 'Escape' || savingRef.current) return
|
|
35
|
+
onClose()
|
|
36
|
+
}
|
|
37
|
+
globalThis.addEventListener('keydown', onKey)
|
|
38
|
+
return () => globalThis.removeEventListener('keydown', onKey)
|
|
39
|
+
}, [onClose])
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
let alive = true
|
|
43
|
+
setPhase('loading')
|
|
44
|
+
dwRpc('databases', { id: instance?.id }).then((value) => {
|
|
45
|
+
if (!alive) return
|
|
46
|
+
const names = (Array.isArray(value?.databases) ? value.databases : [])
|
|
47
|
+
.map((entry) => String(entry?.name ?? ''))
|
|
48
|
+
.filter((name) => name !== '')
|
|
49
|
+
setSchemas(names)
|
|
50
|
+
// A schema that is configured is always shown; anything the server still has
|
|
51
|
+
// but the workspace no longer remembers comes back unchecked.
|
|
52
|
+
setChecked((current) => {
|
|
53
|
+
const next = new Set([...current].filter((name) => names.includes(name)))
|
|
54
|
+
for (const name of current) {
|
|
55
|
+
if (!names.includes(name)) continue
|
|
56
|
+
next.add(name)
|
|
57
|
+
}
|
|
58
|
+
return next
|
|
59
|
+
})
|
|
60
|
+
setPhase('ready')
|
|
61
|
+
}).catch((failure) => {
|
|
62
|
+
if (!alive) return
|
|
63
|
+
setError(dwExplainFailure(tr, failure))
|
|
64
|
+
setPhase('error')
|
|
65
|
+
})
|
|
66
|
+
return () => {
|
|
67
|
+
alive = false
|
|
68
|
+
}
|
|
69
|
+
}, [instance?.id])
|
|
70
|
+
|
|
71
|
+
const toggle = (name) => {
|
|
72
|
+
if (locked.has(name)) return
|
|
73
|
+
const next = new Set(checked)
|
|
74
|
+
if (next.has(name)) next.delete(name)
|
|
75
|
+
else next.add(name)
|
|
76
|
+
setChecked(next)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const apply = async () => {
|
|
80
|
+
if (saving === true) return
|
|
81
|
+
const root = String(store.getState?.()?.root ?? '')
|
|
82
|
+
if (root === '') {
|
|
83
|
+
setError(tr('manualNoWorkspace'))
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
setSaving(true)
|
|
87
|
+
setError('')
|
|
88
|
+
try {
|
|
89
|
+
// Configured schemas are always shown by discovery itself; storing them too
|
|
90
|
+
// would make a schema that later leaves the configuration look hand-picked.
|
|
91
|
+
const names = [...checked].filter((name) => !locked.has(name))
|
|
92
|
+
await dwRpc('selectDatabases', { root, instanceId: instance.id, databases: names })
|
|
93
|
+
await store.loadDiscovery({ quiet: true })
|
|
94
|
+
onClose()
|
|
95
|
+
} catch (failure) {
|
|
96
|
+
setError(dwExplainFailure(tr, failure))
|
|
97
|
+
setSaving(false)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const filter = query.trim().toLowerCase()
|
|
102
|
+
const visible = filter === '' ? schemas : schemas.filter((name) => name.toLowerCase().includes(filter))
|
|
103
|
+
const chosenCount = [...checked].filter((name) => schemas.includes(name)).length
|
|
104
|
+
|
|
105
|
+
const body = []
|
|
106
|
+
if (phase === 'loading') {
|
|
107
|
+
body.push(h('div', { key: 'loading', className: 'dw-ai-loading' }, [
|
|
108
|
+
h(DwIcon, { key: 'i', name: 'spinner', size: 16 }),
|
|
109
|
+
h('span', { key: 't' }, tr('schemaLoading')),
|
|
110
|
+
]))
|
|
111
|
+
} else if (phase === 'error') {
|
|
112
|
+
body.push(h('div', { key: 'error', className: 'dw-ai-error' }, [
|
|
113
|
+
h('div', { key: 't' }, tr('schemaFailed')),
|
|
114
|
+
h('div', { key: 'm', className: 'dw-ai-note' }, error),
|
|
115
|
+
]))
|
|
116
|
+
} else {
|
|
117
|
+
body.push(h('div', { key: 'head', className: 'dw-schema-head' }, [
|
|
118
|
+
h('input', {
|
|
119
|
+
key: 'search',
|
|
120
|
+
className: 'dw-form-input',
|
|
121
|
+
type: 'search',
|
|
122
|
+
value: query,
|
|
123
|
+
placeholder: tr('schemaSearch'),
|
|
124
|
+
onChange: (event) => setQuery(event.target.value),
|
|
125
|
+
style: { width: 240 },
|
|
126
|
+
}),
|
|
127
|
+
h('span', { key: 'count', className: 'dw-ai-note' }, tr('schemaCount', { chosen: chosenCount, total: schemas.length })),
|
|
128
|
+
]))
|
|
129
|
+
body.push(h('div', { key: 'list', className: 'dw-schema-list' }, visible.length === 0
|
|
130
|
+
? [h('div', { key: 'empty', className: 'dw-ai-note' }, tr('schemaNoMatch'))]
|
|
131
|
+
: visible.map((name) => h('label', {
|
|
132
|
+
key: name,
|
|
133
|
+
className: locked.has(name) ? 'dw-schema-row locked' : 'dw-schema-row',
|
|
134
|
+
}, [
|
|
135
|
+
h('input', {
|
|
136
|
+
key: 'c',
|
|
137
|
+
type: 'checkbox',
|
|
138
|
+
className: 'dw-schema-box',
|
|
139
|
+
checked: checked.has(name),
|
|
140
|
+
disabled: locked.has(name),
|
|
141
|
+
onChange: () => toggle(name),
|
|
142
|
+
}),
|
|
143
|
+
h('span', { key: 'n', className: 'dw-schema-name' }, name),
|
|
144
|
+
locked.has(name) ? h('span', { key: 't', className: 'dw-node-tag' }, tr('schemaConfigured')) : null,
|
|
145
|
+
]))))
|
|
146
|
+
body.push(h('div', { key: 'note', className: 'dw-ai-note' }, tr('schemaHint')))
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return h('div', {
|
|
150
|
+
className: 'dw-modal',
|
|
151
|
+
onClick: (event) => {
|
|
152
|
+
if (event.target === event.currentTarget && saving !== true) onClose()
|
|
153
|
+
},
|
|
154
|
+
}, h('div', {
|
|
155
|
+
key: 'card',
|
|
156
|
+
className: 'dw-modal-card',
|
|
157
|
+
role: 'dialog',
|
|
158
|
+
'aria-modal': 'true',
|
|
159
|
+
'aria-label': tr('schemaTitle'),
|
|
160
|
+
}, [
|
|
161
|
+
h('div', { key: 'title', className: 'dw-modal-title' }, [
|
|
162
|
+
h(DwIcon, { key: 'i', name: 'database', size: 15 }),
|
|
163
|
+
h('span', { key: 't' }, `${tr('schemaTitle')} · ${instance?.label ?? instance?.host ?? ''}`),
|
|
164
|
+
]),
|
|
165
|
+
h('div', { key: 'body', className: 'dw-modal-body' }, body),
|
|
166
|
+
error === '' || phase === 'error'
|
|
167
|
+
? null
|
|
168
|
+
: h('div', { key: 'err', className: 'dw-ai-note dw-ai-warn', style: { padding: '0 16px 8px' } }, error),
|
|
169
|
+
h('div', { key: 'foot', className: 'dw-modal-foot' }, [
|
|
170
|
+
h('button', {
|
|
171
|
+
key: 'cancel',
|
|
172
|
+
type: 'button',
|
|
173
|
+
className: 'dw-btn',
|
|
174
|
+
disabled: saving === true,
|
|
175
|
+
onClick: onClose,
|
|
176
|
+
}, tr('cancel')),
|
|
177
|
+
h('button', {
|
|
178
|
+
key: 'apply',
|
|
179
|
+
type: 'button',
|
|
180
|
+
className: 'dw-btn dw-btn-accent',
|
|
181
|
+
disabled: saving === true || phase !== 'ready',
|
|
182
|
+
onClick: () => void apply(),
|
|
183
|
+
}, saving === true ? tr('schemaApplying') : tr('schemaApply')),
|
|
184
|
+
]),
|
|
185
|
+
]))
|
|
186
|
+
}
|