@adecore/database 0.19.0 → 0.20.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.
@@ -1,16 +1,19 @@
1
- import { type Ref } from 'react';
1
+ import { type DragEvent, type Ref } from 'react';
2
2
  import type { ExplorerSelection } from '../actions.ts';
3
- import type { Connection } from '../client/types.ts';
3
+ import type { Connection, TableRef } from '../client/types.ts';
4
+ import type { TableKind } from '../protocol/index.ts';
4
5
  import type { ExplorerFolder } from './folders.ts';
5
6
  export interface DatabaseExplorerProps {
6
7
  connections: readonly Connection[];
7
8
  value?: ExplorerSelection | null;
8
9
  defaultValue?: ExplorerSelection | null;
9
10
  onValueChange?(selection: ExplorerSelection | null): void;
11
+ onTableDragStart?(ref: TableRef, event: DragEvent<HTMLElement>, kind: TableKind): void;
12
+ onTableDragEnd?(event: DragEvent<HTMLElement>): void;
10
13
  showSystemSchemas?: boolean;
11
14
  openOnClick?: boolean;
12
15
  folders?: Readonly<Record<string, readonly ExplorerFolder[]>>;
13
16
  className?: string;
14
17
  ref?: Ref<HTMLDivElement>;
15
18
  }
16
- export declare function DatabaseExplorer({ connections, value, defaultValue, onValueChange, showSystemSchemas, openOnClick, folders, className, ref }: DatabaseExplorerProps): import("react").JSX.Element;
19
+ export declare function DatabaseExplorer({ connections, value, defaultValue, onValueChange, onTableDragStart, onTableDragEnd, showSystemSchemas, openOnClick, folders, className, ref }: DatabaseExplorerProps): import("react").JSX.Element;
@@ -20,7 +20,7 @@ import { useStoredExpansion } from './use-stored-expansion.js';
20
20
  * selects; a double click or Enter on a table asks the app to open it through `useDatabaseAction`,
21
21
  * and on an item of a folder the app added opens it through the item's own `onOpen`.
22
22
  */
23
- export function DatabaseExplorer({ connections, value, defaultValue = null, onValueChange, showSystemSchemas = false, openOnClick = false, folders, className, ref }) {
23
+ export function DatabaseExplorer({ connections, value, defaultValue = null, onValueChange, onTableDragStart, onTableDragEnd, showSystemSchemas = false, openOnClick = false, folders, className, ref }) {
24
24
  const { t } = useTranslation('database');
25
25
  const client = useDatabaseClient();
26
26
  const act = useDatabaseAction();
@@ -210,6 +210,11 @@ export function DatabaseExplorer({ connections, value, defaultValue = null, onVa
210
210
  rowElements.current.set(row.key, element);
211
211
  }
212
212
  },
213
+ draggable: row.kind === 'table' && onTableDragStart !== undefined,
214
+ onDragStart: row.kind === 'table' && onTableDragStart !== undefined
215
+ ? (event) => onTableDragStart(row.ref, event, row.table.kind)
216
+ : undefined,
217
+ onDragEnd: row.kind === 'table' && onTableDragStart !== undefined ? onTableDragEnd : undefined,
213
218
  onClick: (event) => click(row, event.detail),
214
219
  onDoubleClick: tableOf(row) === null && row.kind !== 'appItem' ? undefined : () => open(row),
215
220
  onFocus: () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adecore/database",
3
- "version": "0.19.0",
3
+ "version": "0.20.1",
4
4
  "description": "Browse, query and edit SQLite and MySQL databases: React views for the page, a host for the backend and a native helper that talks to the server.",
5
5
  "license": "FSL-1.1-MIT",
6
6
  "author": "Bas Milius",
@@ -61,13 +61,13 @@
61
61
  "lucide-react": "^1.47.0"
62
62
  },
63
63
  "optionalDependencies": {
64
- "@adecore/database-darwin-arm64": "0.19.0",
65
- "@adecore/database-linux-arm64": "0.19.0",
66
- "@adecore/database-linux-x64": "0.19.0",
67
- "@adecore/database-win32-x64": "0.19.0"
64
+ "@adecore/database-darwin-arm64": "0.20.1",
65
+ "@adecore/database-linux-arm64": "0.20.1",
66
+ "@adecore/database-linux-x64": "0.20.1",
67
+ "@adecore/database-win32-x64": "0.20.1"
68
68
  },
69
69
  "peerDependencies": {
70
- "@adecore/ui": "^0.19.0",
70
+ "@adecore/ui": "^0.20.1",
71
71
  "i18next": "^26.4.2",
72
72
  "react": "^19.3.0",
73
73
  "react-dom": "^19.3.0",
@@ -1,4 +1,4 @@
1
- import { useEffect, useRef, useState, type KeyboardEvent, type MouseEvent, type ReactNode, type Ref } from 'react';
1
+ import { useEffect, useRef, useState, type DragEvent, type KeyboardEvent, type MouseEvent, type ReactNode, type Ref } from 'react';
2
2
  import clsx from 'clsx';
3
3
  import { CircleAlert, Columns2, Database, Eye, Folder, KeyRound, ListOrdered, Lock, Search, ShieldCheck, Table, Zap, type LucideIcon } from 'lucide-react';
4
4
  import { useTranslation } from 'react-i18next';
@@ -6,7 +6,8 @@ import { Button, ContextMenu, EmptyState, Icon, Input, Spinner, Tooltip, Tree }
6
6
  import { formatNumber } from '@adecore/ui/format';
7
7
  import type { ExplorerSelection } from '../actions.ts';
8
8
  import { useDatabaseAction, useDatabaseClient } from '../client-context.ts';
9
- import type { Connection } from '../client/types.ts';
9
+ import type { Connection, TableRef } from '../client/types.ts';
10
+ import type { TableKind } from '../protocol/index.ts';
10
11
  import { EngineIcon } from '../connections/EngineIcon.tsx';
11
12
  import { keyLabelOf, type ColumnKeys } from '../column-keys.ts';
12
13
  import { KeyIcon } from '../KeyIcon.tsx';
@@ -44,6 +45,9 @@ export interface DatabaseExplorerProps {
44
45
  value?: ExplorerSelection | null;
45
46
  defaultValue?: ExplorerSelection | null;
46
47
  onValueChange?(selection: ExplorerSelection | null): void;
48
+ /* Providing a handler makes table and view rows draggable; the app writes its own payload. */
49
+ onTableDragStart?(ref: TableRef, event: DragEvent<HTMLElement>, kind: TableKind): void;
50
+ onTableDragEnd?(event: DragEvent<HTMLElement>): void;
47
51
  showSystemSchemas?: boolean;
48
52
  /* Opens a table on a click too, with `preview: true`; a double click or Enter then sends `preview: false`. */
49
53
  openOnClick?: boolean;
@@ -63,6 +67,8 @@ export function DatabaseExplorer({
63
67
  value,
64
68
  defaultValue = null,
65
69
  onValueChange,
70
+ onTableDragStart,
71
+ onTableDragEnd,
66
72
  showSystemSchemas = false,
67
73
  openOnClick = false,
68
74
  folders,
@@ -275,6 +281,12 @@ export function DatabaseExplorer({
275
281
  rowElements.current.set(row.key, element);
276
282
  }
277
283
  },
284
+ draggable: row.kind === 'table' && onTableDragStart !== undefined,
285
+ onDragStart:
286
+ row.kind === 'table' && onTableDragStart !== undefined
287
+ ? (event: DragEvent<HTMLElement>) => onTableDragStart(row.ref, event, row.table.kind)
288
+ : undefined,
289
+ onDragEnd: row.kind === 'table' && onTableDragStart !== undefined ? onTableDragEnd : undefined,
278
290
  onClick: (event: MouseEvent) => click(row, event.detail),
279
291
  onDoubleClick: tableOf(row) === null && row.kind !== 'appItem' ? undefined : () => open(row),
280
292
  onFocus: () => {