@antelopejs/dms-database 0.4.4 → 0.5.0
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/README.md +12 -10
- package/dist/automation/tableWatch.d.ts +2 -2
- package/dist/automation/tableWatch.js +3 -3
- package/dist/automation/tableWatch.js.map +1 -1
- package/dist/config.d.ts +11 -0
- package/dist/config.js +12 -0
- package/dist/config.js.map +1 -1
- package/dist/connectionAccess.d.ts +3 -0
- package/dist/connectionAccess.js +20 -0
- package/dist/connectionAccess.js.map +1 -0
- package/dist/db/models/connection_selections.model.d.ts +27 -0
- package/dist/db/models/connection_selections.model.js +17 -0
- package/dist/db/models/connection_selections.model.js.map +1 -0
- package/dist/db/models/diagram_layouts.model.d.ts +4 -4
- package/dist/db/models/diagram_layouts.model.js +14 -12
- package/dist/db/models/diagram_layouts.model.js.map +1 -1
- package/dist/db/models/diagram_notes.model.d.ts +3 -3
- package/dist/db/models/index.d.ts +1 -0
- package/dist/db/models/index.js +1 -0
- package/dist/db/models/index.js.map +1 -1
- package/dist/db/models/query_history.model.d.ts +3 -3
- package/dist/db/models/saved_queries.model.d.ts +3 -3
- package/dist/db/tables/connection_selections.table.d.ts +6 -0
- package/dist/db/tables/connection_selections.table.js +30 -0
- package/dist/db/tables/connection_selections.table.js.map +1 -0
- package/dist/db/tables/index.d.ts +1 -0
- package/dist/db/tables/index.js +1 -0
- package/dist/db/tables/index.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/pages/externalLock.d.ts +8 -0
- package/dist/pages/externalLock.js +32 -0
- package/dist/pages/externalLock.js.map +1 -0
- package/dist/pages/overview.js +6 -3
- package/dist/pages/overview.js.map +1 -1
- package/dist/pages/schemas.js +6 -2
- package/dist/pages/schemas.js.map +1 -1
- package/dist/routes/connections.d.ts +14 -0
- package/dist/routes/connections.js +116 -0
- package/dist/routes/connections.js.map +1 -0
- package/dist/routes/data.d.ts +10 -9
- package/dist/routes/data.js +43 -62
- package/dist/routes/data.js.map +1 -1
- package/dist/routes/diagram.d.ts +6 -6
- package/dist/routes/diagram.js +16 -6
- package/dist/routes/diagram.js.map +1 -1
- package/dist/routes/health.d.ts +1 -1
- package/dist/routes/health.js +3 -2
- package/dist/routes/health.js.map +1 -1
- package/dist/routes/index.d.ts +1 -0
- package/dist/routes/index.js +1 -0
- package/dist/routes/index.js.map +1 -1
- package/dist/routes/overview.d.ts +2 -2
- package/dist/routes/overview.js +11 -4
- package/dist/routes/overview.js.map +1 -1
- package/dist/routes/query.d.ts +1 -1
- package/dist/routes/query.js +26 -10
- package/dist/routes/query.js.map +1 -1
- package/dist/routes/schemas.d.ts +1 -1
- package/dist/routes/schemas.js +4 -2
- package/dist/routes/schemas.js.map +1 -1
- package/dist/routes/tables.d.ts +2 -1
- package/dist/routes/tables.js +29 -21
- package/dist/routes/tables.js.map +1 -1
- package/dist/service/browse.d.ts +14 -6
- package/dist/service/browse.js +120 -18
- package/dist/service/browse.js.map +1 -1
- package/dist/service/catalog.js +2 -1
- package/dist/service/catalog.js.map +1 -1
- package/dist/service/connectionState.d.ts +29 -0
- package/dist/service/connectionState.js +157 -0
- package/dist/service/connectionState.js.map +1 -0
- package/dist/service/connections.d.ts +12 -0
- package/dist/service/connections.js +72 -0
- package/dist/service/connections.js.map +1 -0
- package/dist/service/database.d.ts +12 -0
- package/dist/service/database.js +30 -0
- package/dist/service/database.js.map +1 -0
- package/dist/service/declaredFields.d.ts +3 -2
- package/dist/service/declaredFields.js +6 -7
- package/dist/service/declaredFields.js.map +1 -1
- package/dist/service/health.d.ts +2 -1
- package/dist/service/health.js +48 -21
- package/dist/service/health.js.map +1 -1
- package/dist/service/introspect.d.ts +7 -5
- package/dist/service/introspect.js +49 -41
- package/dist/service/introspect.js.map +1 -1
- package/dist/service/overview.d.ts +3 -2
- package/dist/service/overview.js +4 -4
- package/dist/service/overview.js.map +1 -1
- package/dist/service/queryInspection.js +6 -3
- package/dist/service/queryInspection.js.map +1 -1
- package/dist/service/references.d.ts +3 -2
- package/dist/service/references.js +9 -8
- package/dist/service/references.js.map +1 -1
- package/dist/service/rowEdit.d.ts +3 -0
- package/dist/service/rowEdit.js +36 -3
- package/dist/service/rowEdit.js.map +1 -1
- package/dist/service/types.d.ts +1 -1
- package/dist/utils/deadline.d.ts +2 -0
- package/dist/utils/deadline.js +18 -0
- package/dist/utils/deadline.js.map +1 -0
- package/dist/utils/guards.d.ts +2 -0
- package/dist/utils/guards.js +8 -0
- package/dist/utils/guards.js.map +1 -1
- package/dist/utils/query.js +5 -4
- package/dist/utils/query.js.map +1 -1
- package/frontend-vue/app/build/components/DataBrowserAccessBar.vue +88 -0
- package/frontend-vue/app/build/components/DataGridToolbar.vue +10 -5
- package/frontend-vue/app/build/components/FeatureLocked.vue +16 -0
- package/frontend-vue/app/build/components/QueryConsoleBoard.vue +601 -0
- package/frontend-vue/app/build/components/SchemaDiagramBoard.vue +691 -0
- package/frontend-vue/app/build/composables/registerDatabaseSwitcher.ts +16 -0
- package/frontend-vue/app/build/composables/reloadForSelection.ts +13 -0
- package/frontend-vue/app/build/composables/useDataBrowserTabs.ts +9 -0
- package/frontend-vue/app/build/composables/useDatabaseConnections.ts +164 -0
- package/frontend-vue/app/build/composables/useGridAccess.ts +25 -0
- package/frontend-vue/app/build/composables/useLockedPages.ts +53 -0
- package/frontend-vue/app/build/composables/useQueryRuntime.ts +4 -4
- package/frontend-vue/app/build/composables/useSelectionRecheck.ts +23 -0
- package/frontend-vue/app/build/data/assistantOnboarding.ts +12 -0
- package/frontend-vue/app/build/data/readOnlyReason.ts +30 -0
- package/frontend-vue/app/build/data/recentTables.ts +6 -0
- package/frontend-vue/app/build/data/staleDatabase.ts +58 -0
- package/frontend-vue/app/build/data/useStagedSave.ts +10 -1
- package/frontend-vue/app/components/DataBrowser.vue +9 -1
- package/frontend-vue/app/components/DataBrowserSidebar.vue +23 -13
- package/frontend-vue/app/components/DataGrid.vue +17 -6
- package/frontend-vue/app/components/DataGridCell.vue +5 -2
- package/frontend-vue/app/components/DatabaseSwitcher.vue +103 -0
- package/frontend-vue/app/components/QueryBuilderPanel.vue +4 -4
- package/frontend-vue/app/components/QueryConsole.vue +11 -592
- package/frontend-vue/app/components/QueryLibrary.vue +3 -3
- package/frontend-vue/app/components/QueryResultPanel.vue +5 -5
- package/frontend-vue/app/components/RowDrawer.vue +21 -14
- package/frontend-vue/app/components/SchemaDiagram.vue +10 -683
- package/frontend-vue/app/components/SchemasFilterBar.vue +3 -0
- package/frontend-vue/app/components/TableInspector.vue +8 -4
- package/frontend-vue/build/backend-boundary.ts +8 -3
- package/frontend-vue/dms.frontend.ts +2 -0
- package/frontend-vue/eslint.config.mjs +0 -1
- package/frontend-vue/i18n/locales/database-en-GB.json +31 -1
- package/frontend-vue/i18n/locales/database-fr-FR.json +31 -1
- package/frontend-vue/package.json +3 -3
- package/frontend-vue/pnpm-lock.yaml +14 -11
- package/frontend-vue/tests/accessBar.test.ts +196 -0
- package/frontend-vue/tests/backend-boundary.test.ts +15 -7
- package/frontend-vue/tests/databaseSwitcher.test.ts +339 -0
- package/frontend-vue/tests/editRequest.test.ts +146 -0
- package/frontend-vue/tests/externalBrowser.test.ts +193 -0
- package/frontend-vue/tests/fixtures/connections.ts +73 -0
- package/frontend-vue/tests/fixtures/serverRender.ts +135 -12
- package/frontend-vue/tests/lockedPages.test.ts +68 -0
- package/frontend-vue/tests/onDemandReads.test.ts +1 -1
- package/frontend-vue/tests/registration.test.ts +15 -1
- package/frontend-vue/tests/serverRender.test.ts +58 -4
- package/frontend-vue/vitest.config.ts +11 -1
- package/package.json +19 -15
- package/dist/service/schemaRegistry.d.ts +0 -2
- package/dist/service/schemaRegistry.js +0 -8
- package/dist/service/schemaRegistry.js.map +0 -1
|
@@ -0,0 +1,691 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { useDatabaseSchemas } from '../composables/useDatabaseSchemas'
|
|
3
|
+
import { useDiagramDrag } from '../composables/useDiagramDrag'
|
|
4
|
+
import { useDiagramNotes } from '../composables/useDiagramNotes'
|
|
5
|
+
import { RESET_ZOOM, useDiagramView } from '../composables/useDiagramView'
|
|
6
|
+
import { useDiagramSaveStatus } from '../composables/useDiagramSaveStatus'
|
|
7
|
+
import { useDiagramSearch } from '../composables/useDiagramSearch'
|
|
8
|
+
import { useDiagramPersistence } from '../composables/useDiagramPersistence'
|
|
9
|
+
import type { NodeMouseEvent, VueFlowStore } from '@vue-flow/core'
|
|
10
|
+
import { useEventListener } from '@vueuse/core'
|
|
11
|
+
import type { ShallowUnwrapRef } from 'vue'
|
|
12
|
+
import { DiagramAutosave } from '../diagram/autosave'
|
|
13
|
+
import {
|
|
14
|
+
buildGraph,
|
|
15
|
+
type LayoutOptions,
|
|
16
|
+
layOutSchema,
|
|
17
|
+
NOTE_NODE_TYPE,
|
|
18
|
+
neighbourIds,
|
|
19
|
+
RELATION_EDGE_TYPE,
|
|
20
|
+
type Sides,
|
|
21
|
+
STUB_NODE_TYPE,
|
|
22
|
+
TABLE_NODE_TYPE,
|
|
23
|
+
tableNodeId,
|
|
24
|
+
} from '../diagram/graph'
|
|
25
|
+
import {
|
|
26
|
+
clonePositions,
|
|
27
|
+
DiagramHistory,
|
|
28
|
+
type DiagramOperation,
|
|
29
|
+
type DiagramState,
|
|
30
|
+
} from '../diagram/history'
|
|
31
|
+
import {
|
|
32
|
+
canvasOwnsKey,
|
|
33
|
+
type DiagramCommand,
|
|
34
|
+
diagramCommand,
|
|
35
|
+
} from '../diagram/shortcuts'
|
|
36
|
+
import { DiagramSync, noteFromStored } from '../diagram/sync'
|
|
37
|
+
import DiagramLegend from './DiagramLegend.vue'
|
|
38
|
+
import DiagramSearchBar from './DiagramSearchBar.vue'
|
|
39
|
+
import DiagramStatusBar from './DiagramStatusBar.vue'
|
|
40
|
+
import DiagramToolbar from './DiagramToolbar.vue'
|
|
41
|
+
import DiagramViewBar from './DiagramViewBar.vue'
|
|
42
|
+
import DiagramNoteNode from '../../components/DiagramNoteNode.vue'
|
|
43
|
+
import DiagramRelationEdge from '../../components/DiagramRelationEdge.vue'
|
|
44
|
+
import DiagramStubNode from '../../components/DiagramStubNode.vue'
|
|
45
|
+
import DiagramTableNode from '../../components/DiagramTableNode.vue'
|
|
46
|
+
import TableInspector from '../../components/TableInspector.vue'
|
|
47
|
+
|
|
48
|
+
// The Diagram page: the tables of one schema and their relations. Moving a
|
|
49
|
+
// table saves the layout on its own (D-10), with undo and redo; auto layout
|
|
50
|
+
// is previewed before it is kept, because it moves every table at once.
|
|
51
|
+
|
|
52
|
+
const SAVE_DELAY_MS = 800
|
|
53
|
+
// Far enough out for a large schema to fit in the view (D-16).
|
|
54
|
+
const MIN_ZOOM = 0.1
|
|
55
|
+
const NOTE_WIDTH = 220
|
|
56
|
+
const NOTE_HEIGHT = 140
|
|
57
|
+
// Above this many tables the canvas suggests focusing on one of them.
|
|
58
|
+
const LARGE_SCHEMA_TABLES = 40
|
|
59
|
+
|
|
60
|
+
const { t } = useI18n()
|
|
61
|
+
const route = useDmsRoute()
|
|
62
|
+
const router = useDmsRouter()
|
|
63
|
+
const toast = useToast()
|
|
64
|
+
const { schemas, isLoading: schemasLoading } = useDatabaseSchemas()
|
|
65
|
+
const persistence = useDiagramPersistence()
|
|
66
|
+
const { open: openDrawer } = useDrawer()
|
|
67
|
+
|
|
68
|
+
const canvas = shallowRef<ShallowUnwrapRef<VueFlowStore> | null>(null)
|
|
69
|
+
const canvasWrapper = useTemplateRef<HTMLElement>('canvasWrapper')
|
|
70
|
+
const searchBar = useTemplateRef<{ focus: () => void; blur: () => void }>(
|
|
71
|
+
'searchBar',
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
const state = reactive<DiagramState>({ positions: {}, notes: [] })
|
|
75
|
+
const history = new DiagramHistory()
|
|
76
|
+
const historyRevision = ref(0)
|
|
77
|
+
const routing = new Map<string, Sides>()
|
|
78
|
+
|
|
79
|
+
const selectedId = ref<string | null>(null)
|
|
80
|
+
const focusId = ref<string | null>(null)
|
|
81
|
+
const panMode = ref(false)
|
|
82
|
+
const viewport = ref({ x: 0, y: 0, zoom: RESET_ZOOM })
|
|
83
|
+
const preview = ref<{
|
|
84
|
+
from: DiagramState['positions']
|
|
85
|
+
basis: LayoutOptions
|
|
86
|
+
} | null>(null)
|
|
87
|
+
// Tables showing all their columns, per schema: a view setting of this
|
|
88
|
+
// visit, not part of the shared layout.
|
|
89
|
+
const expanded = shallowRef(new Set<string>())
|
|
90
|
+
const expandedBySchema = new Map<string, Set<string>>()
|
|
91
|
+
// The canvas shape and the notes the layout of unsaved tables works around,
|
|
92
|
+
// read when the schema loads and when auto layout runs, so a note moved
|
|
93
|
+
// later does not move them.
|
|
94
|
+
const layoutBasis = shallowRef<LayoutOptions>({})
|
|
95
|
+
const loadedId = ref<string | null>(null)
|
|
96
|
+
const loaded = computed(
|
|
97
|
+
() => loadedId.value !== null && loadedId.value === schemaId.value,
|
|
98
|
+
)
|
|
99
|
+
// The note just created, opened ready to write until its edit ends.
|
|
100
|
+
const editNoteId = ref<string | null>(null)
|
|
101
|
+
let sync: DiagramSync | null = null
|
|
102
|
+
let autosave: DiagramAutosave | null = null
|
|
103
|
+
const { saveState, savedAt, savedLabel, statusReporter } = useDiagramSaveStatus(
|
|
104
|
+
() => sync,
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
// --- schema ---
|
|
108
|
+
const schemaId = computed<string | null>(() => {
|
|
109
|
+
const asked = route.query.schema
|
|
110
|
+
if (typeof asked === 'string' && schemas.value.some((s) => s.id === asked))
|
|
111
|
+
return asked
|
|
112
|
+
return schemas.value[0]?.id ?? null
|
|
113
|
+
})
|
|
114
|
+
const schema = computed(
|
|
115
|
+
() => schemas.value.find((s) => s.id === schemaId.value) ?? null,
|
|
116
|
+
)
|
|
117
|
+
const schemaItems = computed(() =>
|
|
118
|
+
schemas.value.map((s) => ({ label: s.id, value: s.id, icon: 'i-ph-stack' })),
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
const { fitAll, startView, centerOn, onNodesInitialized, requestFit } =
|
|
122
|
+
useDiagramView({
|
|
123
|
+
canvas,
|
|
124
|
+
canvasWrapper,
|
|
125
|
+
viewport,
|
|
126
|
+
selectedId,
|
|
127
|
+
schema,
|
|
128
|
+
route,
|
|
129
|
+
router,
|
|
130
|
+
warn,
|
|
131
|
+
})
|
|
132
|
+
const {
|
|
133
|
+
addNote,
|
|
134
|
+
changeNoteText,
|
|
135
|
+
deleteNote,
|
|
136
|
+
endNoteEdit,
|
|
137
|
+
onDeleteNodes,
|
|
138
|
+
selectNode,
|
|
139
|
+
} = useDiagramNotes({
|
|
140
|
+
state,
|
|
141
|
+
canvas,
|
|
142
|
+
canvasWrapper,
|
|
143
|
+
schema,
|
|
144
|
+
schemaId,
|
|
145
|
+
viewport,
|
|
146
|
+
selectedId,
|
|
147
|
+
editNoteId,
|
|
148
|
+
record,
|
|
149
|
+
render,
|
|
150
|
+
})
|
|
151
|
+
const { onNodeDragStart, onNodeDragStop } = useDiagramDrag({
|
|
152
|
+
state,
|
|
153
|
+
preview,
|
|
154
|
+
selectedId,
|
|
155
|
+
record,
|
|
156
|
+
render,
|
|
157
|
+
selectNode,
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
// Each schema is a step of the browser history (D-11).
|
|
161
|
+
function openSchema(id: string) {
|
|
162
|
+
if (id === schemaId.value) return
|
|
163
|
+
router.push({ query: { ...route.query, schema: id, table: undefined } })
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Opens the table a stub stands for (D-10). */
|
|
167
|
+
function openTable(schemaName: string, tableName: string) {
|
|
168
|
+
if (schemaName !== schemaId.value) {
|
|
169
|
+
router.push({
|
|
170
|
+
query: { ...route.query, schema: schemaName, table: tableName },
|
|
171
|
+
})
|
|
172
|
+
return
|
|
173
|
+
}
|
|
174
|
+
const id = tableNodeId(schemaName, tableName)
|
|
175
|
+
if (focusIds.value && !focusIds.value.has(id)) focusId.value = null
|
|
176
|
+
nextTick(() => centerOn(id))
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function warn(title: string) {
|
|
180
|
+
toast.add({ title, color: 'warning', icon: 'i-ph-warning' })
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// A schema the URL names that does not exist: say so, and drop it from the
|
|
184
|
+
// URL (D-12).
|
|
185
|
+
onMounted(() => {
|
|
186
|
+
watch(
|
|
187
|
+
[() => route.query.schema, schemas, schemasLoading],
|
|
188
|
+
() => {
|
|
189
|
+
const asked = route.query.schema
|
|
190
|
+
if (typeof asked !== 'string' || schemasLoading.value) return
|
|
191
|
+
if (!schemas.value.length || schemas.value.some((s) => s.id === asked))
|
|
192
|
+
return
|
|
193
|
+
warn(t('dms_database.diagram.not_found.schema', { schema: asked }))
|
|
194
|
+
router.replace({
|
|
195
|
+
query: { ...route.query, schema: undefined, table: undefined },
|
|
196
|
+
})
|
|
197
|
+
},
|
|
198
|
+
{ immediate: true },
|
|
199
|
+
)
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
// --- graph ---
|
|
203
|
+
const focusIds = computed(() =>
|
|
204
|
+
focusId.value && schema.value
|
|
205
|
+
? neighbourIds(schema.value, focusId.value.split('::')[1] ?? '')
|
|
206
|
+
: null,
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
// Where the layout puts every table of the schema: the place of a table
|
|
210
|
+
// without a saved one, focused or not (D-4).
|
|
211
|
+
const fullLayout = computed(() =>
|
|
212
|
+
schema.value ? layOutSchema(schema.value, layoutBasis.value) : undefined,
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
function currentLayoutBasis(): LayoutOptions {
|
|
216
|
+
const rect = canvasWrapper.value?.getBoundingClientRect()
|
|
217
|
+
return {
|
|
218
|
+
aspect: rect?.width && rect.height ? rect.width / rect.height : undefined,
|
|
219
|
+
obstacles: state.notes.map(({ x, y, width, height }) => ({
|
|
220
|
+
x,
|
|
221
|
+
y,
|
|
222
|
+
width,
|
|
223
|
+
height,
|
|
224
|
+
})),
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function toggleColumns(tableName: string) {
|
|
229
|
+
const next = new Set(expanded.value)
|
|
230
|
+
if (!next.delete(tableName)) next.add(tableName)
|
|
231
|
+
setExpanded(next)
|
|
232
|
+
render()
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function setExpanded(next: Set<string>) {
|
|
236
|
+
expanded.value = next
|
|
237
|
+
if (schemaId.value) expandedBySchema.set(schemaId.value, next)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function render() {
|
|
241
|
+
if (!canvas.value) return
|
|
242
|
+
if (!schema.value || !loaded.value) {
|
|
243
|
+
canvas.value.setNodes([])
|
|
244
|
+
canvas.value.setEdges([])
|
|
245
|
+
return
|
|
246
|
+
}
|
|
247
|
+
const built = buildGraph({
|
|
248
|
+
schema: schema.value,
|
|
249
|
+
positions: state.positions,
|
|
250
|
+
notes: state.notes,
|
|
251
|
+
selectedId: selectedId.value,
|
|
252
|
+
focusIds: focusIds.value,
|
|
253
|
+
noteHandlers: {
|
|
254
|
+
onTextChange: changeNoteText,
|
|
255
|
+
onDelete: deleteNote,
|
|
256
|
+
onEditEnd: endNoteEdit,
|
|
257
|
+
},
|
|
258
|
+
editNoteId: editNoteId.value,
|
|
259
|
+
onOpenSchema: openTable,
|
|
260
|
+
routing,
|
|
261
|
+
layout: fullLayout.value,
|
|
262
|
+
expanded: expanded.value,
|
|
263
|
+
onToggleColumns: toggleColumns,
|
|
264
|
+
})
|
|
265
|
+
canvas.value.setNodes(built.nodes)
|
|
266
|
+
canvas.value.setEdges(built.edges)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
watch([canvas, schema, selectedId, focusIds, loaded], render)
|
|
270
|
+
|
|
271
|
+
const { search, searchIndex, searchMissed, searchPosition, runSearch } =
|
|
272
|
+
useDiagramSearch({
|
|
273
|
+
schema,
|
|
274
|
+
schemaId,
|
|
275
|
+
focusIds,
|
|
276
|
+
focusId,
|
|
277
|
+
expanded,
|
|
278
|
+
setExpanded,
|
|
279
|
+
render,
|
|
280
|
+
centerOn,
|
|
281
|
+
})
|
|
282
|
+
|
|
283
|
+
// --- loading and saving ---
|
|
284
|
+
// An auto layout being previewed is not kept yet: a save writes the layout
|
|
285
|
+
// from before it.
|
|
286
|
+
function stateToSave(): DiagramState {
|
|
287
|
+
return preview.value
|
|
288
|
+
? { positions: preview.value.from, notes: state.notes }
|
|
289
|
+
: state
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function scheduleSave() {
|
|
293
|
+
autosave?.schedule()
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function saveNow() {
|
|
297
|
+
autosave?.schedule()
|
|
298
|
+
void autosave?.flush()
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
async function load(id: string) {
|
|
302
|
+
// What is left of the shown schema's changes is copied now and written
|
|
303
|
+
// under its own id before the next schema loads (D-2).
|
|
304
|
+
const leaving = autosave?.flush()
|
|
305
|
+
autosave = null
|
|
306
|
+
loadedId.value = null
|
|
307
|
+
routing.clear()
|
|
308
|
+
history.clear()
|
|
309
|
+
historyRevision.value++
|
|
310
|
+
preview.value = null
|
|
311
|
+
selectedId.value = null
|
|
312
|
+
focusId.value = null
|
|
313
|
+
editNoteId.value = null
|
|
314
|
+
searchIndex.value = -1
|
|
315
|
+
const owner = new DiagramSync(persistence, id)
|
|
316
|
+
sync = owner
|
|
317
|
+
await leaving
|
|
318
|
+
if (sync !== owner) return
|
|
319
|
+
try {
|
|
320
|
+
const stored = await persistence.readDiagram(id)
|
|
321
|
+
if (sync !== owner) return
|
|
322
|
+
state.positions = stored.positions
|
|
323
|
+
state.notes = stored.notes.map(noteFromStored)
|
|
324
|
+
} catch {
|
|
325
|
+
if (sync !== owner) return
|
|
326
|
+
state.positions = {}
|
|
327
|
+
state.notes = []
|
|
328
|
+
}
|
|
329
|
+
expanded.value = expandedBySchema.get(id) ?? new Set()
|
|
330
|
+
layoutBasis.value = currentLayoutBasis()
|
|
331
|
+
owner.reset(state)
|
|
332
|
+
autosave = new DiagramAutosave(
|
|
333
|
+
owner,
|
|
334
|
+
stateToSave,
|
|
335
|
+
SAVE_DELAY_MS,
|
|
336
|
+
statusReporter(owner),
|
|
337
|
+
)
|
|
338
|
+
saveState.value = 'idle'
|
|
339
|
+
savedAt.value = null
|
|
340
|
+
requestFit()
|
|
341
|
+
loadedId.value = id
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// The canvas is drawn in the browser, from a working copy of the layout and
|
|
345
|
+
// notes it reads there: a server render, which would read them without
|
|
346
|
+
// handing them over, never starts it.
|
|
347
|
+
onMounted(() => watch(schemaId, (id) => id && load(id), { immediate: true }))
|
|
348
|
+
|
|
349
|
+
function record(op: DiagramOperation) {
|
|
350
|
+
history.push(op)
|
|
351
|
+
historyRevision.value++
|
|
352
|
+
scheduleSave()
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
onBeforeUnmount(() => void autosave?.flush())
|
|
356
|
+
|
|
357
|
+
// --- undo / redo ---
|
|
358
|
+
const canUndo = computed(
|
|
359
|
+
() => historyRevision.value >= 0 && history.canUndo && !preview.value,
|
|
360
|
+
)
|
|
361
|
+
const canRedo = computed(
|
|
362
|
+
() => historyRevision.value >= 0 && history.canRedo && !preview.value,
|
|
363
|
+
)
|
|
364
|
+
|
|
365
|
+
function undo() {
|
|
366
|
+
if (!canUndo.value || !history.undo(state)) return
|
|
367
|
+
historyRevision.value++
|
|
368
|
+
render()
|
|
369
|
+
scheduleSave()
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function redo() {
|
|
373
|
+
if (!canRedo.value || !history.redo(state)) return
|
|
374
|
+
historyRevision.value++
|
|
375
|
+
render()
|
|
376
|
+
scheduleSave()
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// --- auto layout, previewed before it is kept ---
|
|
380
|
+
const movedCount = computed(() => {
|
|
381
|
+
if (!preview.value || !schema.value) return 0
|
|
382
|
+
return schema.value.tables.filter((table) => {
|
|
383
|
+
// A table without a saved position already sat where the layout puts it.
|
|
384
|
+
const before = preview.value?.from[table.name]
|
|
385
|
+
const after = state.positions[table.name]
|
|
386
|
+
return Boolean(
|
|
387
|
+
before && after && (before.x !== after.x || before.y !== after.y),
|
|
388
|
+
)
|
|
389
|
+
}).length
|
|
390
|
+
})
|
|
391
|
+
|
|
392
|
+
function startAutoLayout() {
|
|
393
|
+
if (!fullLayout.value || preview.value) return
|
|
394
|
+
preview.value = {
|
|
395
|
+
from: clonePositions(state.positions),
|
|
396
|
+
basis: layoutBasis.value,
|
|
397
|
+
}
|
|
398
|
+
// Laid out for the canvas and the notes as they are now.
|
|
399
|
+
layoutBasis.value = currentLayoutBasis()
|
|
400
|
+
state.positions = clonePositions(fullLayout.value.tables)
|
|
401
|
+
routing.clear()
|
|
402
|
+
render()
|
|
403
|
+
nextTick(startView)
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function keepLayout() {
|
|
407
|
+
if (!preview.value) return
|
|
408
|
+
const from = preview.value.from
|
|
409
|
+
preview.value = null
|
|
410
|
+
record({ kind: 'layout', from, to: clonePositions(state.positions) })
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
function discardLayout() {
|
|
414
|
+
if (!preview.value) return
|
|
415
|
+
state.positions = preview.value.from
|
|
416
|
+
// Unsaved tables go back where they were before the preview.
|
|
417
|
+
layoutBasis.value = preview.value.basis
|
|
418
|
+
preview.value = null
|
|
419
|
+
render()
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// --- selection and inspection ---
|
|
423
|
+
function onNodeClick({ node }: NodeMouseEvent) {
|
|
424
|
+
if (node.type === STUB_NODE_TYPE) return
|
|
425
|
+
selectedId.value = node.type === TABLE_NODE_TYPE ? node.id : null
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function onPaneClick() {
|
|
429
|
+
selectedId.value = null
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// The drawer is titled with the table it shows, as the Schemas page's; a
|
|
433
|
+
// relation the inspector follows shows its table in the same drawer. No
|
|
434
|
+
// position nor J / K: the diagram's tables are not a list.
|
|
435
|
+
let inspector: ReturnType<typeof openDrawer> | null = null
|
|
436
|
+
|
|
437
|
+
function inspectorOptions(schema: string, name: string) {
|
|
438
|
+
return {
|
|
439
|
+
componentKey: `${schema}::${name}`,
|
|
440
|
+
title: name,
|
|
441
|
+
componentOptions: {
|
|
442
|
+
rowData: { schema, name },
|
|
443
|
+
showRow: async (row: object | string) => {
|
|
444
|
+
if (typeof row !== 'string') throw new Error('not a table id')
|
|
445
|
+
const [toSchema = '', toName = ''] = row.split('::')
|
|
446
|
+
inspector?.patch(inspectorOptions(toSchema, toName))
|
|
447
|
+
},
|
|
448
|
+
},
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
function inspect(tableName: string) {
|
|
453
|
+
if (!schemaId.value) return
|
|
454
|
+
inspector = openDrawer({
|
|
455
|
+
direction: 'right',
|
|
456
|
+
component: TableInspector,
|
|
457
|
+
...inspectorOptions(schemaId.value, tableName),
|
|
458
|
+
})
|
|
459
|
+
inspector.result.finally(() => {
|
|
460
|
+
inspector = null
|
|
461
|
+
})
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
function onNodeDoubleClick({ node }: NodeMouseEvent) {
|
|
465
|
+
if (node.type !== TABLE_NODE_TYPE) return
|
|
466
|
+
inspect((node.data as { tableName: string }).tableName)
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
const selectedTable = computed(() => selectedId.value?.split('::')[1] ?? null)
|
|
470
|
+
|
|
471
|
+
function toggleFocus() {
|
|
472
|
+
focusId.value = focusId.value ? null : selectedId.value
|
|
473
|
+
render()
|
|
474
|
+
nextTick(fitAll)
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
function leaveSearch() {
|
|
478
|
+
searchBar.value?.blur()
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// --- viewport ---
|
|
482
|
+
const zoomPercent = computed(() => `${Math.round(viewport.value.zoom * 100)}%`)
|
|
483
|
+
|
|
484
|
+
function onViewportChange(next: { x: number; y: number; zoom: number }) {
|
|
485
|
+
viewport.value = { ...next }
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// --- keyboard: the shortcuts the toolbar's tooltips name ---
|
|
489
|
+
// Escape steps back one level: the auto layout preview, then the focus,
|
|
490
|
+
// then the selection (D-14).
|
|
491
|
+
function escape(): boolean {
|
|
492
|
+
if (preview.value) {
|
|
493
|
+
discardLayout()
|
|
494
|
+
return true
|
|
495
|
+
}
|
|
496
|
+
if (focusId.value) {
|
|
497
|
+
toggleFocus()
|
|
498
|
+
return true
|
|
499
|
+
}
|
|
500
|
+
const selectedNotes = canvas.value?.getSelectedNodes ?? []
|
|
501
|
+
if (!selectedId.value && !selectedNotes.length) return false
|
|
502
|
+
selectedId.value = null
|
|
503
|
+
canvas.value?.removeSelectedNodes(selectedNotes)
|
|
504
|
+
return true
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
function always(run: () => unknown): () => boolean {
|
|
508
|
+
return () => {
|
|
509
|
+
run()
|
|
510
|
+
return true
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
const COMMANDS: Record<DiagramCommand, () => boolean> = {
|
|
515
|
+
search: always(() => searchBar.value?.focus()),
|
|
516
|
+
note: always(() => !isEmpty.value && addNote()),
|
|
517
|
+
select: always(() => (panMode.value = false)),
|
|
518
|
+
pan: always(() => (panMode.value = true)),
|
|
519
|
+
fit: always(fitAll),
|
|
520
|
+
resetZoom: always(() => canvas.value?.zoomTo(RESET_ZOOM)),
|
|
521
|
+
undo: always(undo),
|
|
522
|
+
redo: always(redo),
|
|
523
|
+
escape,
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// Keys reach the canvas only from the canvas or the page itself: not while
|
|
527
|
+
// typing, and not while a dialog such as the inspector is open (D-6).
|
|
528
|
+
useEventListener('keydown', (event: KeyboardEvent) => {
|
|
529
|
+
const command = diagramCommand(event)
|
|
530
|
+
if (!command || event.defaultPrevented) return
|
|
531
|
+
if (!canvasOwnsKey(event.target, canvasWrapper.value)) return
|
|
532
|
+
if (COMMANDS[command]()) event.preventDefault()
|
|
533
|
+
})
|
|
534
|
+
|
|
535
|
+
// Imported, not resolved by name: the edge must mount in the SVG namespace,
|
|
536
|
+
// which an async global component does not.
|
|
537
|
+
const nodeTypes = markRaw({
|
|
538
|
+
[TABLE_NODE_TYPE]: DiagramTableNode,
|
|
539
|
+
[STUB_NODE_TYPE]: DiagramStubNode,
|
|
540
|
+
[NOTE_NODE_TYPE]: DiagramNoteNode,
|
|
541
|
+
})
|
|
542
|
+
const edgeTypes = markRaw({ [RELATION_EDGE_TYPE]: DiagramRelationEdge })
|
|
543
|
+
|
|
544
|
+
const isEmpty = computed(
|
|
545
|
+
() => loaded.value && (schema.value?.tables.length ?? 0) === 0,
|
|
546
|
+
)
|
|
547
|
+
const isLarge = computed(
|
|
548
|
+
() =>
|
|
549
|
+
!focusId.value && (schema.value?.tables.length ?? 0) > LARGE_SCHEMA_TABLES,
|
|
550
|
+
)
|
|
551
|
+
</script>
|
|
552
|
+
|
|
553
|
+
<template>
|
|
554
|
+
<div class="flex min-h-0 flex-1 flex-col">
|
|
555
|
+
<DmsEmptyState
|
|
556
|
+
v-if="!schemasLoading && schemas.length === 0"
|
|
557
|
+
class="flex-1"
|
|
558
|
+
icon="i-ph-graph"
|
|
559
|
+
hatched
|
|
560
|
+
:title="t('dms_database.diagram.empty.no_schema')"
|
|
561
|
+
/>
|
|
562
|
+
<DmsClientOnly v-else>
|
|
563
|
+
<div
|
|
564
|
+
ref="canvasWrapper"
|
|
565
|
+
class="border-default relative min-h-0 flex-1 overflow-hidden rounded-xl border"
|
|
566
|
+
:class="panMode ? 'diagram-pan-mode' : ''"
|
|
567
|
+
>
|
|
568
|
+
<!-- Notes carry their own delete button, named in the page's
|
|
569
|
+
language: the canvas's generic badge would only repeat it. -->
|
|
570
|
+
<DmsFlowCanvas
|
|
571
|
+
ref="canvas"
|
|
572
|
+
:node-types="nodeTypes"
|
|
573
|
+
:edge-types="edgeTypes"
|
|
574
|
+
:controls="false"
|
|
575
|
+
:fit-view-on-init="false"
|
|
576
|
+
:min-zoom="MIN_ZOOM"
|
|
577
|
+
minimap
|
|
578
|
+
deletable-nodes
|
|
579
|
+
:delete-badge="false"
|
|
580
|
+
:pan-on-drag="panMode"
|
|
581
|
+
:nodes-draggable="!panMode"
|
|
582
|
+
:select-nodes-on-drag="false"
|
|
583
|
+
@delete-nodes="onDeleteNodes"
|
|
584
|
+
@nodes-initialized="onNodesInitialized"
|
|
585
|
+
@viewport-change="onViewportChange"
|
|
586
|
+
@node-drag-start="onNodeDragStart"
|
|
587
|
+
@node-drag-stop="onNodeDragStop"
|
|
588
|
+
@node-click="onNodeClick"
|
|
589
|
+
@node-double-click="onNodeDoubleClick"
|
|
590
|
+
@pane-click="onPaneClick"
|
|
591
|
+
>
|
|
592
|
+
<template #top-left>
|
|
593
|
+
<DiagramSearchBar
|
|
594
|
+
ref="searchBar"
|
|
595
|
+
v-model:search="search"
|
|
596
|
+
:schema-id="schemaId"
|
|
597
|
+
:schema-items="schemaItems"
|
|
598
|
+
:search-missed="searchMissed"
|
|
599
|
+
:search-position="searchPosition"
|
|
600
|
+
@open-schema="openSchema"
|
|
601
|
+
@run-search="runSearch"
|
|
602
|
+
@leave-search="leaveSearch"
|
|
603
|
+
/>
|
|
604
|
+
</template>
|
|
605
|
+
|
|
606
|
+
<template #top-right>
|
|
607
|
+
<DiagramToolbar
|
|
608
|
+
:save-state="saveState"
|
|
609
|
+
:saved-label="savedLabel"
|
|
610
|
+
:can-undo="canUndo"
|
|
611
|
+
:can-redo="canRedo"
|
|
612
|
+
:auto-layout-disabled="Boolean(preview) || isEmpty"
|
|
613
|
+
@save-now="saveNow"
|
|
614
|
+
@undo="undo"
|
|
615
|
+
@redo="redo"
|
|
616
|
+
@auto-layout="startAutoLayout"
|
|
617
|
+
/>
|
|
618
|
+
</template>
|
|
619
|
+
|
|
620
|
+
<template #top-center>
|
|
621
|
+
<DiagramStatusBar
|
|
622
|
+
:preview="Boolean(preview)"
|
|
623
|
+
:moved-count="movedCount"
|
|
624
|
+
:selected-table="selectedTable"
|
|
625
|
+
:focus-id="focusId"
|
|
626
|
+
:is-large="isLarge"
|
|
627
|
+
:table-count="schema?.tables.length ?? 0"
|
|
628
|
+
@discard-layout="discardLayout"
|
|
629
|
+
@keep-layout="keepLayout"
|
|
630
|
+
@inspect="inspect"
|
|
631
|
+
@toggle-focus="toggleFocus"
|
|
632
|
+
/>
|
|
633
|
+
</template>
|
|
634
|
+
|
|
635
|
+
<template #bottom-left>
|
|
636
|
+
<DiagramLegend />
|
|
637
|
+
</template>
|
|
638
|
+
|
|
639
|
+
<template #bottom-center>
|
|
640
|
+
<DiagramViewBar
|
|
641
|
+
v-model:pan-mode="panMode"
|
|
642
|
+
:zoom-percent="zoomPercent"
|
|
643
|
+
:is-empty="isEmpty"
|
|
644
|
+
@zoom-out="canvas?.zoomOut()"
|
|
645
|
+
@reset-zoom="canvas?.zoomTo(RESET_ZOOM)"
|
|
646
|
+
@zoom-in="canvas?.zoomIn()"
|
|
647
|
+
@fit="fitAll"
|
|
648
|
+
@add-note="addNote"
|
|
649
|
+
/>
|
|
650
|
+
</template>
|
|
651
|
+
</DmsFlowCanvas>
|
|
652
|
+
|
|
653
|
+
<div
|
|
654
|
+
v-if="isEmpty"
|
|
655
|
+
class="pointer-events-none absolute inset-0 grid place-items-center"
|
|
656
|
+
>
|
|
657
|
+
<DmsEmptyState
|
|
658
|
+
class="pointer-events-auto"
|
|
659
|
+
icon="i-ph-graph"
|
|
660
|
+
:title="t('dms_database.diagram.empty.title', { schema: schemaId })"
|
|
661
|
+
:description="t('dms_database.diagram.empty.description')"
|
|
662
|
+
/>
|
|
663
|
+
</div>
|
|
664
|
+
</div>
|
|
665
|
+
</DmsClientOnly>
|
|
666
|
+
</div>
|
|
667
|
+
</template>
|
|
668
|
+
|
|
669
|
+
<style scoped>
|
|
670
|
+
.diagram-pan-mode :deep(.vue-flow__pane) {
|
|
671
|
+
cursor: grab;
|
|
672
|
+
}
|
|
673
|
+
.diagram-pan-mode :deep(.vue-flow__pane.dragging) {
|
|
674
|
+
cursor: grabbing;
|
|
675
|
+
}
|
|
676
|
+
:deep(.vue-flow__minimap) {
|
|
677
|
+
border: 1px solid var(--ui-border-accented);
|
|
678
|
+
border-radius: calc(var(--ui-radius) * 0.75);
|
|
679
|
+
background: var(--ui-bg-elevated);
|
|
680
|
+
overflow: hidden;
|
|
681
|
+
}
|
|
682
|
+
:deep(.vue-flow__minimap-node) {
|
|
683
|
+
fill: var(--ui-border-accented);
|
|
684
|
+
}
|
|
685
|
+
/* Below md the overview gives its room to the canvas, as the legend does. */
|
|
686
|
+
@media (max-width: 767.98px) {
|
|
687
|
+
:deep(.vue-flow__minimap) {
|
|
688
|
+
display: none;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
</style>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The module's own id and the switcher's registered name: the sidebar mounts
|
|
3
|
+
* the widget by that name, under the title card of this module only.
|
|
4
|
+
*/
|
|
5
|
+
export const DATABASE_SWITCHER_WIDGET = {
|
|
6
|
+
id: 'dms-database:switcher',
|
|
7
|
+
component: 'DmsDatabaseDatabaseSwitcher',
|
|
8
|
+
module: 'database',
|
|
9
|
+
position: 'below-search-bar',
|
|
10
|
+
order: -100,
|
|
11
|
+
} satisfies SidebarWidget
|
|
12
|
+
|
|
13
|
+
/** Puts the database switcher in the sidebar, at the top of the module's. */
|
|
14
|
+
export function registerDatabaseSwitcher(): void {
|
|
15
|
+
useSidebarWidgets().register(DATABASE_SWITCHER_WIDGET)
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { forgetRecentTables } from '../data/recentTables'
|
|
2
|
+
import { forgetBrowserTabs } from './useDataBrowserTabs'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Reloads the page on the database the server now serves, once another tab
|
|
6
|
+
* switched it: the tabs and recent tables this tab kept belong to the one it
|
|
7
|
+
* showed.
|
|
8
|
+
*/
|
|
9
|
+
export function reloadForSelection(): void {
|
|
10
|
+
forgetBrowserTabs()
|
|
11
|
+
forgetRecentTables()
|
|
12
|
+
window.location.reload()
|
|
13
|
+
}
|