@antelopejs/dms-database 0.2.2 → 0.3.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/dist/frontend-module.d.ts +2 -0
- package/dist/frontend-module.js +17 -0
- package/dist/frontend-module.js.map +1 -0
- package/dist/index.js +2 -11
- package/dist/index.js.map +1 -1
- package/dist/pages/overview.d.ts +0 -1
- package/dist/pages/overview.js +0 -14
- package/dist/pages/overview.js.map +1 -1
- package/dist/pages/schemas.js +3 -0
- package/dist/pages/schemas.js.map +1 -1
- package/frontend-vue/app/build/composables/useDatabaseHealth.ts +11 -7
- package/frontend-vue/app/build/composables/useDatabaseSchemas.ts +8 -1
- package/frontend-vue/app/build/data/cellValues.ts +50 -0
- package/frontend-vue/app/build/diagram/graph.ts +211 -47
- package/frontend-vue/app/build/diagram/packing.ts +283 -0
- package/frontend-vue/app/build/utils/fieldTypes.ts +16 -1
- package/frontend-vue/app/components/ConnectionStatus.vue +5 -1
- package/frontend-vue/app/components/DataBrowser.vue +2 -2
- package/frontend-vue/app/components/DataBrowserSidebar.vue +1 -1
- package/frontend-vue/app/components/DataGrid.vue +44 -34
- package/frontend-vue/app/components/DiagramTableNode.vue +25 -1
- package/frontend-vue/app/components/DrawerTabs.vue +57 -0
- package/frontend-vue/app/components/JsonCellPanel.vue +81 -85
- package/frontend-vue/app/components/QueryConsole.vue +6 -1
- package/frontend-vue/app/components/RowDrawer.vue +98 -124
- package/frontend-vue/app/components/SchemaDiagram.vue +134 -17
- package/frontend-vue/app/components/TableInspector.vue +122 -149
- package/frontend-vue/i18n/locales/database-en-GB.json +8 -12
- package/frontend-vue/i18n/locales/database-fr-FR.json +8 -12
- package/frontend-vue/package.json +1 -1
- package/frontend-vue/tests/clientNavigation.test.ts +93 -0
- package/frontend-vue/tests/dataBrowser.test.ts +91 -1
- package/frontend-vue/tests/diagramLayout.test.ts +383 -0
- package/frontend-vue/tests/fixtures/serverRender.ts +114 -0
- package/frontend-vue/tests/locales.test.ts +48 -0
- package/frontend-vue/tests/onDemandReads.test.ts +81 -0
- package/frontend-vue/tests/serverRender.test.ts +83 -1
- package/frontend-vue/vitest.config.ts +8 -1
- package/package.json +7 -6
- package/skills/dms-database/SKILL.md +1 -0
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import type { DiagramPosition } from '../composables/useDiagramPersistence'
|
|
2
|
+
|
|
3
|
+
// Places blocks (a group of related tables laid out by dagre, or a table on
|
|
4
|
+
// its own) in rows, so a schema of many unrelated tables fills a canvas
|
|
5
|
+
// shaped like the screen instead of one long column.
|
|
6
|
+
|
|
7
|
+
export interface Size {
|
|
8
|
+
width: number
|
|
9
|
+
height: number
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface Rect extends Size {
|
|
13
|
+
x: number
|
|
14
|
+
y: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface Block extends Size {
|
|
18
|
+
id: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Room between two blocks, and between a block and a note. */
|
|
22
|
+
export const PACK_GAP = 64
|
|
23
|
+
// Width / height of a canvas whose size is not known: a wide screen.
|
|
24
|
+
export const DEFAULT_ASPECT = 16 / 9
|
|
25
|
+
const WIDTH_CANDIDATES = 48
|
|
26
|
+
// Packings this close in shape to the best one (as a log of the ratio) count
|
|
27
|
+
// as as good: the most compact of them wins.
|
|
28
|
+
const SHAPE_TOLERANCE = 0.1
|
|
29
|
+
|
|
30
|
+
export function overlaps(a: Rect, b: Rect, margin = 0): boolean {
|
|
31
|
+
return (
|
|
32
|
+
a.x < b.x + b.width + margin &&
|
|
33
|
+
b.x < a.x + a.width + margin &&
|
|
34
|
+
a.y < b.y + b.height + margin &&
|
|
35
|
+
b.y < a.y + a.height + margin
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The smallest rectangle around `rects`; an empty one at 0, 0 for none. */
|
|
40
|
+
export function boundsOf(rects: Rect[]): Rect {
|
|
41
|
+
if (!rects.length) return { x: 0, y: 0, width: 0, height: 0 }
|
|
42
|
+
const left = Math.min(...rects.map((r) => r.x))
|
|
43
|
+
const top = Math.min(...rects.map((r) => r.y))
|
|
44
|
+
const right = Math.max(...rects.map((r) => r.x + r.width))
|
|
45
|
+
const bottom = Math.max(...rects.map((r) => r.y + r.height))
|
|
46
|
+
return { x: left, y: top, width: right - left, height: bottom - top }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Moves `rect` right, past every obstacle it would cover, keeping its row.
|
|
51
|
+
*/
|
|
52
|
+
function clearOf(rect: Rect, obstacles: Rect[]): Rect {
|
|
53
|
+
let placed = rect
|
|
54
|
+
for (;;) {
|
|
55
|
+
const hit = obstacles.find((o) => overlaps(placed, o, PACK_GAP))
|
|
56
|
+
if (!hit) return placed
|
|
57
|
+
placed = { ...placed, x: hit.x + hit.width + PACK_GAP }
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface Column extends Size {
|
|
62
|
+
blocks: Block[]
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The columns of a row: its tallest block first, on its own, as it sets the
|
|
67
|
+
* row's height; then the others in order, each under the one before while
|
|
68
|
+
* the column stays within the row's height and `stack`, so short tables can
|
|
69
|
+
* fill the room beside a tall group instead of leaving it empty.
|
|
70
|
+
*/
|
|
71
|
+
function rowColumns(row: Block[], stack: number): Column[] {
|
|
72
|
+
const tallest = row.reduce((a, b) => (b.height > a.height ? b : a))
|
|
73
|
+
const limit = Math.min(tallest.height, stack)
|
|
74
|
+
const columns: Column[] = [{ blocks: [tallest], ...sizeOf(tallest) }]
|
|
75
|
+
let current: Column | null = null
|
|
76
|
+
for (const block of row) {
|
|
77
|
+
if (block === tallest) continue
|
|
78
|
+
if (current && current.height + PACK_GAP + block.height <= limit) {
|
|
79
|
+
current.blocks.push(block)
|
|
80
|
+
current.height += PACK_GAP + block.height
|
|
81
|
+
current.width = Math.max(current.width, block.width)
|
|
82
|
+
continue
|
|
83
|
+
}
|
|
84
|
+
current = { blocks: [block], ...sizeOf(block) }
|
|
85
|
+
columns.push(current)
|
|
86
|
+
}
|
|
87
|
+
return columns
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function widthOf(columns: Column[]): number {
|
|
91
|
+
return (
|
|
92
|
+
columns.reduce((sum, c) => sum + c.width, 0) +
|
|
93
|
+
PACK_GAP * (columns.length - 1)
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Splits `blocks`, in their order, into rows at most `rowWidth` wide, with
|
|
99
|
+
* columns stacked up to `stack` high.
|
|
100
|
+
*/
|
|
101
|
+
export function shelfRows(
|
|
102
|
+
blocks: Block[],
|
|
103
|
+
rowWidth: number,
|
|
104
|
+
stack = Infinity,
|
|
105
|
+
): Block[][] {
|
|
106
|
+
const rows: Block[][] = []
|
|
107
|
+
let row: Block[] = []
|
|
108
|
+
for (const block of blocks) {
|
|
109
|
+
if (row.length && widthOf(rowColumns([...row, block], stack)) > rowWidth) {
|
|
110
|
+
rows.push(row)
|
|
111
|
+
row = []
|
|
112
|
+
}
|
|
113
|
+
row.push(block)
|
|
114
|
+
}
|
|
115
|
+
if (row.length) rows.push(row)
|
|
116
|
+
return rows
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Shelf packing: rows from `shelfRows`, top to bottom, each laid out in its
|
|
121
|
+
* columns; a column that would cover an obstacle moves right past it.
|
|
122
|
+
*/
|
|
123
|
+
function packRows(
|
|
124
|
+
blocks: Block[],
|
|
125
|
+
rowWidth: number,
|
|
126
|
+
stack: number,
|
|
127
|
+
obstacles: Rect[],
|
|
128
|
+
): Map<string, Rect> {
|
|
129
|
+
const placed = new Map<string, Rect>()
|
|
130
|
+
let y = 0
|
|
131
|
+
for (const row of shelfRows(blocks, rowWidth, stack)) {
|
|
132
|
+
let x = 0
|
|
133
|
+
let bottom = y
|
|
134
|
+
for (const column of rowColumns(row, stack)) {
|
|
135
|
+
const spot = clearOf({ x, y, ...sizeOf(column) }, obstacles)
|
|
136
|
+
let top = y
|
|
137
|
+
for (const block of column.blocks) {
|
|
138
|
+
placed.set(block.id, { x: spot.x, y: top, ...sizeOf(block) })
|
|
139
|
+
top += block.height + PACK_GAP
|
|
140
|
+
}
|
|
141
|
+
x = spot.x + column.width + PACK_GAP
|
|
142
|
+
bottom = Math.max(bottom, y + column.height)
|
|
143
|
+
}
|
|
144
|
+
y = bottom + PACK_GAP
|
|
145
|
+
}
|
|
146
|
+
return placed
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function sizeOf(block: Size): Size {
|
|
150
|
+
return { width: block.width, height: block.height }
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Where each block goes, its top-left corner from 0, 0: the packing closest
|
|
155
|
+
* to `aspect` (width / height) among rows of several widths, short blocks
|
|
156
|
+
* stacked or not; of the ones about as close, the most compact. The order of
|
|
157
|
+
* `blocks` is kept from row to row, and no block covers any of `obstacles`.
|
|
158
|
+
*/
|
|
159
|
+
export function packBlocks(
|
|
160
|
+
blocks: Block[],
|
|
161
|
+
aspect: number = DEFAULT_ASPECT,
|
|
162
|
+
obstacles: Rect[] = [],
|
|
163
|
+
): Map<string, DiagramPosition> {
|
|
164
|
+
if (!blocks.length) return new Map()
|
|
165
|
+
const widest = Math.max(...blocks.map((b) => b.width))
|
|
166
|
+
const total = blocks.reduce((sum, b) => sum + b.width + PACK_GAP, 0)
|
|
167
|
+
const area = blocks.reduce(
|
|
168
|
+
(sum, b) => sum + (b.width + PACK_GAP) * (b.height + PACK_GAP),
|
|
169
|
+
0,
|
|
170
|
+
)
|
|
171
|
+
const ideal = Math.max(widest, Math.sqrt(area * aspect))
|
|
172
|
+
// Row widths around the ideal one, from the widest block to one row.
|
|
173
|
+
const widths = new Set([widest, total])
|
|
174
|
+
for (let i = 0; i < WIDTH_CANDIDATES; i++) {
|
|
175
|
+
const width = ideal * (0.5 + (1.5 * i) / WIDTH_CANDIDATES)
|
|
176
|
+
if (width >= widest && width <= total) widths.add(width)
|
|
177
|
+
}
|
|
178
|
+
const tries = [...widths].flatMap((width) =>
|
|
179
|
+
[0, width / aspect, Infinity].map((stack) => {
|
|
180
|
+
const placed = packRows(blocks, width, stack, obstacles)
|
|
181
|
+
const bounds = boundsOf([...placed.values()])
|
|
182
|
+
const shape = bounds.width / Math.max(bounds.height, 1) / aspect
|
|
183
|
+
return {
|
|
184
|
+
placed,
|
|
185
|
+
score: Math.abs(Math.log(shape)),
|
|
186
|
+
area: bounds.width * bounds.height,
|
|
187
|
+
}
|
|
188
|
+
}),
|
|
189
|
+
)
|
|
190
|
+
const closest = Math.min(...tries.map((t) => t.score))
|
|
191
|
+
const best = tries
|
|
192
|
+
.filter((t) => t.score <= closest + SHAPE_TOLERANCE)
|
|
193
|
+
.reduce((a, b) => (b.area < a.area ? b : a))
|
|
194
|
+
const positions = new Map<string, DiagramPosition>()
|
|
195
|
+
for (const [id, rect] of best.placed)
|
|
196
|
+
positions.set(id, { x: rect.x, y: rect.y })
|
|
197
|
+
return positions
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Groups `ids` linked by `links`: each group lists its ids in the order of
|
|
202
|
+
* `ids`, and the groups come in the order of their first id.
|
|
203
|
+
*/
|
|
204
|
+
export function linkedGroups(
|
|
205
|
+
ids: string[],
|
|
206
|
+
links: [string, string][],
|
|
207
|
+
): string[][] {
|
|
208
|
+
const parent = new Map(ids.map((id) => [id, id]))
|
|
209
|
+
const root = (id: string): string => {
|
|
210
|
+
let current = id
|
|
211
|
+
while (parent.get(current) !== current)
|
|
212
|
+
current = parent.get(current) ?? current
|
|
213
|
+
parent.set(id, current)
|
|
214
|
+
return current
|
|
215
|
+
}
|
|
216
|
+
for (const [a, b] of links) {
|
|
217
|
+
if (!parent.has(a) || !parent.has(b)) continue
|
|
218
|
+
const ra = root(a)
|
|
219
|
+
const rb = root(b)
|
|
220
|
+
if (ra !== rb) parent.set(rb, ra)
|
|
221
|
+
}
|
|
222
|
+
const groups = new Map<string, string[]>()
|
|
223
|
+
for (const id of ids) {
|
|
224
|
+
const key = root(id)
|
|
225
|
+
groups.set(key, [...(groups.get(key) ?? []), id])
|
|
226
|
+
}
|
|
227
|
+
return [...groups.values()]
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** What a table name starts with before `__` (`dms-core__users`), or ''. */
|
|
231
|
+
export function namePrefix(name: string): string {
|
|
232
|
+
const at = name.indexOf('__')
|
|
233
|
+
return at > 0 ? name.slice(0, at) : ''
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Isolated tables in the order they are placed: by name prefix, the tables
|
|
238
|
+
* without one in their own group, then by name within a group.
|
|
239
|
+
*/
|
|
240
|
+
export function prefixOrder(names: string[]): string[] {
|
|
241
|
+
return [...names].sort((a, b) => {
|
|
242
|
+
const pa = namePrefix(a)
|
|
243
|
+
const pb = namePrefix(b)
|
|
244
|
+
if (pa !== pb) {
|
|
245
|
+
// The tables without a prefix come after the prefixed groups.
|
|
246
|
+
if (!pa) return 1
|
|
247
|
+
if (!pb) return -1
|
|
248
|
+
return pa.localeCompare(pb)
|
|
249
|
+
}
|
|
250
|
+
return a.localeCompare(b)
|
|
251
|
+
})
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* The zoom Vue Flow's `fitView` gives `bounds` in a canvas of `size` with
|
|
256
|
+
* `padding` (a share of the canvas), before its own zoom limits.
|
|
257
|
+
*/
|
|
258
|
+
export function fitZoom(bounds: Size, size: Size, padding: number): number {
|
|
259
|
+
const room = 1 + padding
|
|
260
|
+
return Math.min(
|
|
261
|
+
size.width / room / Math.max(bounds.width, 1),
|
|
262
|
+
size.height / room / Math.max(bounds.height, 1),
|
|
263
|
+
)
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* The view that starts the diagram: the whole layout when it fits at
|
|
268
|
+
* `minZoom` or closer, else `minZoom` framed on its top-left corner.
|
|
269
|
+
* `fitZoom` is the zoom that fits it all.
|
|
270
|
+
*/
|
|
271
|
+
export function startViewport(
|
|
272
|
+
bounds: Rect,
|
|
273
|
+
fitZoom: number,
|
|
274
|
+
minZoom: number,
|
|
275
|
+
inset: { x: number; y: number },
|
|
276
|
+
): { x: number; y: number; zoom: number } | null {
|
|
277
|
+
if (fitZoom >= minZoom) return null
|
|
278
|
+
return {
|
|
279
|
+
x: inset.x - bounds.x * minZoom,
|
|
280
|
+
y: inset.y - bounds.y * minZoom,
|
|
281
|
+
zoom: minZoom,
|
|
282
|
+
}
|
|
283
|
+
}
|
|
@@ -24,7 +24,7 @@ const BOOLEAN_ICON = 'i-ph-toggle-right'
|
|
|
24
24
|
const LIST_ICON = 'i-ph-brackets-square'
|
|
25
25
|
const OBJECT_ICON = 'i-ph-brackets-curly'
|
|
26
26
|
const ENUM_ICON = 'i-ph-list-checks'
|
|
27
|
-
const UNION_ICON = 'i-ph-split'
|
|
27
|
+
const UNION_ICON = 'i-ph-arrows-split'
|
|
28
28
|
|
|
29
29
|
const NAMED_FIELDS: Record<string, FieldTypeView> = {
|
|
30
30
|
email: { icon: 'i-ph-at', label: 'email' },
|
|
@@ -116,6 +116,21 @@ export function describeField(
|
|
|
116
116
|
return view(descriptor)
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
const NULL_KINDS = new Set<FieldDescriptor['kind']>(['null', 'undefined'])
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* The type a column holds when it holds a value: a union's `null` and
|
|
123
|
+
* `undefined` members off (`string | null` reads `string`), for a view that
|
|
124
|
+
* says apart whether the column takes null.
|
|
125
|
+
*/
|
|
126
|
+
export function valueDescriptor(descriptor: FieldDescriptor): FieldDescriptor {
|
|
127
|
+
if (descriptor.kind !== 'union') return descriptor
|
|
128
|
+
const members = descriptor.members.filter((m) => !NULL_KINDS.has(m.kind))
|
|
129
|
+
if (members.length === 0 || members.length === descriptor.members.length)
|
|
130
|
+
return descriptor
|
|
131
|
+
return members.length === 1 ? members[0]! : { ...descriptor, members }
|
|
132
|
+
}
|
|
133
|
+
|
|
119
134
|
const RUNTIME_KINDS = new Set([
|
|
120
135
|
'string',
|
|
121
136
|
'number',
|
|
@@ -10,7 +10,7 @@ const SECOND_MS = 1000
|
|
|
10
10
|
const MINUTE_S = 60
|
|
11
11
|
|
|
12
12
|
const { t, n, locale } = useI18n()
|
|
13
|
-
const { health, isLoading, error, refresh } = useDatabaseHealth({
|
|
13
|
+
const { health, isLoading, error, refresh, ready } = useDatabaseHealth({
|
|
14
14
|
refreshInterval: PROBE_INTERVAL_MS,
|
|
15
15
|
})
|
|
16
16
|
const clock = useNow({ interval: SECOND_MS })
|
|
@@ -94,6 +94,10 @@ const downMetrics = computed(() => [
|
|
|
94
94
|
sub: t('dms_database.overview.connection.next_probe_sub'),
|
|
95
95
|
},
|
|
96
96
|
])
|
|
97
|
+
|
|
98
|
+
// A client navigation shows the first probe, as a server render does, not
|
|
99
|
+
// the empty health whose missing driver and age lines it would then grow by.
|
|
100
|
+
await ready
|
|
97
101
|
</script>
|
|
98
102
|
|
|
99
103
|
<template>
|
|
@@ -65,7 +65,7 @@ function instanceLabel(instance: string): string {
|
|
|
65
65
|
|
|
66
66
|
<template>
|
|
67
67
|
<div
|
|
68
|
-
class="border-default bg-default flex min-h-
|
|
68
|
+
class="border-default bg-default flex min-h-fit flex-1 flex-col overflow-hidden rounded-xl border md:min-h-0 md:flex-row"
|
|
69
69
|
>
|
|
70
70
|
<DataBrowserSidebar
|
|
71
71
|
:schemas="schemas"
|
|
@@ -73,7 +73,7 @@ function instanceLabel(instance: string): string {
|
|
|
73
73
|
:error="Boolean(schemasError)"
|
|
74
74
|
@retry="refreshSchemas()"
|
|
75
75
|
/>
|
|
76
|
-
<section class="flex min-w-0 flex-1 flex-col">
|
|
76
|
+
<section class="flex min-w-0 flex-1 flex-col md:min-h-0">
|
|
77
77
|
<DataBrowserTabBar />
|
|
78
78
|
<DataGrid
|
|
79
79
|
v-if="activeTab"
|
|
@@ -158,7 +158,7 @@ onKeyStroke('t', (event) => {
|
|
|
158
158
|
|
|
159
159
|
<template>
|
|
160
160
|
<aside
|
|
161
|
-
class="border-default bg-default flex h-
|
|
161
|
+
class="border-default bg-default flex max-h-[40vh] w-full shrink-0 flex-col border-b md:h-full md:max-h-none md:w-[264px] md:border-r md:border-b-0"
|
|
162
162
|
>
|
|
163
163
|
<div class="border-default grid gap-2 border-b p-3">
|
|
164
164
|
<DmsEyebrow :label="t('dms_database.data.scope.schema')" />
|
|
@@ -360,12 +360,6 @@ const editing = ref<{
|
|
|
360
360
|
field: string
|
|
361
361
|
} | null>(null)
|
|
362
362
|
const invalidReason = ref<string | null>(null)
|
|
363
|
-
const jsonPanel = ref<{
|
|
364
|
-
rowId: string | null
|
|
365
|
-
field: string
|
|
366
|
-
value: unknown
|
|
367
|
-
readOnly: boolean
|
|
368
|
-
} | null>(null)
|
|
369
363
|
|
|
370
364
|
function stagedCell(row: Record<string, unknown>, field: string) {
|
|
371
365
|
const rowId = rowIdOf(row)
|
|
@@ -384,12 +378,7 @@ function openEditorAt(r: number, c: number) {
|
|
|
384
378
|
const value = currentValue(row, column.name)
|
|
385
379
|
const rowId = rowIdOf(row)
|
|
386
380
|
if (value !== null && typeof value === 'object') {
|
|
387
|
-
|
|
388
|
-
rowId,
|
|
389
|
-
field: column.name,
|
|
390
|
-
value,
|
|
391
|
-
readOnly: !isCellEditable(column.name, row),
|
|
392
|
-
}
|
|
381
|
+
openJsonEditor(rowId, column.name, value, !isCellEditable(column.name, row))
|
|
393
382
|
return
|
|
394
383
|
}
|
|
395
384
|
if (!isCellEditable(column.name, row) || rowId === null) return
|
|
@@ -437,11 +426,25 @@ function commitCell(draft: string | boolean, source: 'enter' | 'blur') {
|
|
|
437
426
|
refocusGrid()
|
|
438
427
|
}
|
|
439
428
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
429
|
+
// A structured cell opens its JSON in a DMS drawer; applying stages it.
|
|
430
|
+
function openJsonEditor(
|
|
431
|
+
rowId: string | null,
|
|
432
|
+
field: string,
|
|
433
|
+
value: unknown,
|
|
434
|
+
cellReadOnly: boolean,
|
|
435
|
+
) {
|
|
436
|
+
const editor = openDrawer<{ value: unknown } | undefined>({
|
|
437
|
+
direction: 'right',
|
|
438
|
+
component: JsonCellPanel,
|
|
439
|
+
title: t('dms_database.data.json.title', { column: field }),
|
|
440
|
+
componentOptions: { column: field, value, readOnly: cellReadOnly },
|
|
441
|
+
})
|
|
442
|
+
editor.result
|
|
443
|
+
.then((result) => {
|
|
444
|
+
if (result && !cellReadOnly && rowId !== null)
|
|
445
|
+
stage(rowId, field, result.value)
|
|
446
|
+
})
|
|
447
|
+
.finally(refocusGrid)
|
|
445
448
|
}
|
|
446
449
|
|
|
447
450
|
// --- staged changes: review, save, undo ---
|
|
@@ -468,7 +471,11 @@ function afterSave({ fields, gone }: SavedChanges) {
|
|
|
468
471
|
.map(([field]) => field)
|
|
469
472
|
if (
|
|
470
473
|
gone > 0 ||
|
|
471
|
-
mayMoveRows(fields, {
|
|
474
|
+
mayMoveRows(fields, {
|
|
475
|
+
sortKey: state.sortKey,
|
|
476
|
+
search: state.search,
|
|
477
|
+
filtered,
|
|
478
|
+
})
|
|
472
479
|
)
|
|
473
480
|
reload()
|
|
474
481
|
}
|
|
@@ -491,7 +498,13 @@ onKeyStroke('s', (event) => {
|
|
|
491
498
|
})
|
|
492
499
|
|
|
493
500
|
// --- the row drawer ---
|
|
494
|
-
|
|
501
|
+
// The DMS row header (`rowHeader`) names the row and holds its position on
|
|
502
|
+
// the page, previous / next and J / K.
|
|
503
|
+
|
|
504
|
+
/** The position over the rows of the page, "Row 3 of 50". */
|
|
505
|
+
const ROW_POSITION_KEY = 'dms_database.data.row.position'
|
|
506
|
+
|
|
507
|
+
function rowNavigation(index: number): RowNavigation {
|
|
495
508
|
return {
|
|
496
509
|
index,
|
|
497
510
|
total: rows.value.length,
|
|
@@ -506,17 +519,23 @@ let drawer: ReturnType<typeof openDrawer> | null = null
|
|
|
506
519
|
|
|
507
520
|
function rowDrawerOptions(index: number) {
|
|
508
521
|
const row = rows.value[index] ?? {}
|
|
522
|
+
const rowId = rowIdOf(row)
|
|
523
|
+
const heading = rowId ?? t('dms_database.data.row.no_id')
|
|
509
524
|
return {
|
|
510
|
-
componentKey: `${props.tab.id}:${
|
|
511
|
-
title:
|
|
525
|
+
componentKey: `${props.tab.id}:${rowId ?? index}`,
|
|
526
|
+
title: heading,
|
|
527
|
+
rowHeader: {
|
|
528
|
+
title: heading,
|
|
529
|
+
positionLabel: `$${ROW_POSITION_KEY}`,
|
|
530
|
+
navigation: rowNavigation(index),
|
|
531
|
+
},
|
|
512
532
|
componentOptions: {
|
|
513
533
|
tab: props.tab,
|
|
514
534
|
row,
|
|
515
|
-
rowId
|
|
535
|
+
rowId,
|
|
516
536
|
columns: visibleColumns.value,
|
|
517
537
|
table: props.table,
|
|
518
538
|
readOnly: readOnly.value,
|
|
519
|
-
navigation: rowNavigation(index),
|
|
520
539
|
onStage: stage,
|
|
521
540
|
onReview: review,
|
|
522
541
|
},
|
|
@@ -569,7 +588,7 @@ useEventListener('keydown', (event: KeyboardEvent) => {
|
|
|
569
588
|
</script>
|
|
570
589
|
|
|
571
590
|
<template>
|
|
572
|
-
<div class="flex
|
|
591
|
+
<div class="flex flex-1 flex-col md:min-h-0">
|
|
573
592
|
<div
|
|
574
593
|
class="border-default flex flex-wrap items-center gap-2 border-b px-3 py-2"
|
|
575
594
|
>
|
|
@@ -663,7 +682,7 @@ useEventListener('keydown', (event: KeyboardEvent) => {
|
|
|
663
682
|
|
|
664
683
|
<div
|
|
665
684
|
ref="scroller"
|
|
666
|
-
class="relative min-h-
|
|
685
|
+
class="relative min-h-80 flex-1 scroll-pl-14 scroll-pt-9 overflow-auto outline-none md:min-h-0"
|
|
667
686
|
tabindex="0"
|
|
668
687
|
@keydown="onKeydown"
|
|
669
688
|
>
|
|
@@ -942,14 +961,5 @@ useEventListener('keydown', (event: KeyboardEvent) => {
|
|
|
942
961
|
/>
|
|
943
962
|
</nav>
|
|
944
963
|
</footer>
|
|
945
|
-
|
|
946
|
-
<JsonCellPanel
|
|
947
|
-
:open="jsonPanel !== null"
|
|
948
|
-
:column="jsonPanel?.field ?? ''"
|
|
949
|
-
:value="jsonPanel?.value"
|
|
950
|
-
:read-only="jsonPanel?.readOnly ?? true"
|
|
951
|
-
@update:open="jsonPanel = $event ? jsonPanel : null"
|
|
952
|
-
@save="stageJson"
|
|
953
|
-
/>
|
|
954
964
|
</div>
|
|
955
965
|
</template>
|
|
@@ -13,6 +13,9 @@ import {
|
|
|
13
13
|
// a neutral icon. Colour only marks structure: the primary key, and the
|
|
14
14
|
// relation columns, which light up with the selected table's relations.
|
|
15
15
|
|
|
16
|
+
// A table with many columns comes folded: its first columns and every column
|
|
17
|
+
// an arrow ends on, then a row that unfolds it and folds it back.
|
|
18
|
+
|
|
16
19
|
// The canvas keeps the selection in `data.selected`: Vue Flow's own one is
|
|
17
20
|
// off for tables, so one table at most is drawn selected.
|
|
18
21
|
const props = defineProps<{ data: TableNodeData }>()
|
|
@@ -32,7 +35,8 @@ const relationTargets = computed(
|
|
|
32
35
|
)
|
|
33
36
|
|
|
34
37
|
const rows = computed(() =>
|
|
35
|
-
|
|
38
|
+
props.data.columns.map((name) => {
|
|
39
|
+
const descriptor = props.data.table.fields[name]
|
|
36
40
|
const key = isPrimaryKey(name, props.data.table.indexes ?? {})
|
|
37
41
|
const relation = relationTargets.value.get(name)
|
|
38
42
|
const role: ColumnRole = key ? 'key' : relation ? 'relation' : 'plain'
|
|
@@ -120,6 +124,26 @@ const rows = computed(() =>
|
|
|
120
124
|
{{ row.type }}
|
|
121
125
|
</span>
|
|
122
126
|
</li>
|
|
127
|
+
<li v-if="data.foldable" class="h-6">
|
|
128
|
+
<!-- `nodrag`: a click unfolds the table instead of grabbing it. -->
|
|
129
|
+
<button
|
|
130
|
+
type="button"
|
|
131
|
+
class="nodrag text-muted hover:text-highlighted hover:bg-elevated focus-visible:ring-primary flex h-full w-full cursor-pointer items-center gap-1.5 pl-3 pr-2.5 font-mono text-[11px] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset"
|
|
132
|
+
:aria-expanded="data.expanded"
|
|
133
|
+
@click.stop="data.onToggleColumns(data.tableName)"
|
|
134
|
+
@dblclick.stop
|
|
135
|
+
>
|
|
136
|
+
<UIcon
|
|
137
|
+
:name="data.expanded ? 'i-ph-caret-up' : 'i-ph-caret-down'"
|
|
138
|
+
class="size-3 shrink-0"
|
|
139
|
+
/>
|
|
140
|
+
{{
|
|
141
|
+
data.expanded
|
|
142
|
+
? $t('dms_database.diagram.columns.fold')
|
|
143
|
+
: $t('dms_database.diagram.columns.more', data.hiddenCount)
|
|
144
|
+
}}
|
|
145
|
+
</button>
|
|
146
|
+
</li>
|
|
123
147
|
</ul>
|
|
124
148
|
</div>
|
|
125
149
|
</template>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<script setup lang="ts" generic="Tab extends string">
|
|
2
|
+
import { useResizeObserver, useScroll } from '@vueuse/core'
|
|
3
|
+
|
|
4
|
+
// The tab list of a drawer: on a phone, or a drawer narrower than its tabs,
|
|
5
|
+
// it scrolls sideways, and a fade on the side more tabs hide in says so.
|
|
6
|
+
|
|
7
|
+
interface DrawerTab {
|
|
8
|
+
value: Tab
|
|
9
|
+
label: string
|
|
10
|
+
badge?: number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
defineProps<{ items: DrawerTab[] }>()
|
|
14
|
+
const active = defineModel<Tab>({ required: true })
|
|
15
|
+
|
|
16
|
+
const scroller = useTemplateRef('scroller')
|
|
17
|
+
const { arrivedState, measure } = useScroll(scroller)
|
|
18
|
+
const overflows = ref(false)
|
|
19
|
+
|
|
20
|
+
useResizeObserver(scroller, () => {
|
|
21
|
+
const element = scroller.value
|
|
22
|
+
overflows.value = Boolean(
|
|
23
|
+
element && element.scrollWidth > element.clientWidth + 1,
|
|
24
|
+
)
|
|
25
|
+
measure()
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
// A 24px fade on each side the list still scrolls to.
|
|
29
|
+
const fade = computed(() => {
|
|
30
|
+
if (!overflows.value) return undefined
|
|
31
|
+
const start = arrivedState.left ? 'black' : 'transparent'
|
|
32
|
+
const end = arrivedState.right ? 'black' : 'transparent'
|
|
33
|
+
return {
|
|
34
|
+
maskImage: `linear-gradient(to right, ${start}, black 24px, black calc(100% - 24px), ${end})`,
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<template>
|
|
40
|
+
<div
|
|
41
|
+
ref="scroller"
|
|
42
|
+
data-drawer-tabs
|
|
43
|
+
:data-overflows="overflows || undefined"
|
|
44
|
+
class="min-w-0 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden"
|
|
45
|
+
:style="fade"
|
|
46
|
+
>
|
|
47
|
+
<UTabs
|
|
48
|
+
v-model="active"
|
|
49
|
+
:items="items"
|
|
50
|
+
variant="link"
|
|
51
|
+
size="sm"
|
|
52
|
+
:content="false"
|
|
53
|
+
class="w-max min-w-full"
|
|
54
|
+
:ui="{ trigger: 'shrink-0' }"
|
|
55
|
+
/>
|
|
56
|
+
</div>
|
|
57
|
+
</template>
|