@adecore/database 0.26.0 → 0.26.2
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/DatabaseProvider.js +3 -10
- package/dist/grid/DataGrid.js +5 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +1 -0
- package/dist/use-database-resources.d.ts +1 -0
- package/dist/use-database-resources.js +12 -0
- package/package.json +7 -7
- package/src/DatabaseProvider.tsx +3 -10
- package/src/grid/DataGrid.tsx +6 -1
- package/src/grid/types.ts +1 -0
- package/src/index.ts +6 -0
- package/src/use-database-resources.ts +14 -0
package/dist/DatabaseProvider.js
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { use, useMemo
|
|
3
|
-
import { useTranslation } from 'react-i18next';
|
|
2
|
+
import { use, useMemo } from 'react';
|
|
4
3
|
import { DatabaseContext } from './client-context.js';
|
|
5
|
-
import {
|
|
4
|
+
import { useDatabaseResources } from './use-database-resources.js';
|
|
6
5
|
/* Hands every view below it the client and the app's hooks, and adds the package's words to the i18next the app's `UIProvider` was given. Mount it inside that provider. */
|
|
7
6
|
export function DatabaseProvider({ client, onAction, onNotice, storage, files, numberNotation, children }) {
|
|
8
|
-
|
|
7
|
+
useDatabaseResources();
|
|
9
8
|
const outer = use(DatabaseContext);
|
|
10
|
-
const [added, setAdded] = useState(null);
|
|
11
|
-
// In render, as `UIProvider` does, so the first view already reads its words.
|
|
12
|
-
if (added !== i18n) {
|
|
13
|
-
addDatabaseResources(i18n);
|
|
14
|
-
setAdded(i18n);
|
|
15
|
-
}
|
|
16
9
|
const ownClient = client ?? outer?.client;
|
|
17
10
|
const ownAction = onAction ?? outer?.onAction;
|
|
18
11
|
const ownNotice = onNotice ?? outer?.onNotice;
|
package/dist/grid/DataGrid.js
CHANGED
|
@@ -8,6 +8,7 @@ import { formatNumber } from '@adecore/ui/format';
|
|
|
8
8
|
import { assignRef } from '../assign-ref.js';
|
|
9
9
|
import { useNumberNotation } from '../client-context.js';
|
|
10
10
|
import { usePopupPress } from '../use-popup-press.js';
|
|
11
|
+
import { useDatabaseResources } from '../use-database-resources.js';
|
|
11
12
|
import { useStableCallback } from '../use-stable-callback.js';
|
|
12
13
|
import { fullRect, rectBetween, rectContains } from './cell-range.js';
|
|
13
14
|
import { captureLayout, restoreLayout, sameLayout } from './column-layout.js';
|
|
@@ -32,12 +33,15 @@ const signatureOf = (columns) => columns.map((column) => column.name).join('\u00
|
|
|
32
33
|
const textOf = (view) => (view.suffix === undefined ? view.text : `${view.text} ${view.suffix}`);
|
|
33
34
|
const estimateWidths = (columns, rows, notation) => columns.map((column, index) => estimateColumnWidth(column.name, rows.slice(0, 50).map((row) => textOf(cellView(row.cells[index] ?? null, column.kind, columnNotation(column, notation)))), column.primaryKey === true));
|
|
34
35
|
/*
|
|
35
|
-
* The table of the table view and of the console
|
|
36
|
+
* The table of the table view and of the console, and of any rows an app has on its own: it needs no
|
|
37
|
+
* `DatabaseProvider`, only the `UIProvider` of `@adecore/ui`. Only the rows in view are drawn, at a fixed
|
|
36
38
|
* height, inside a box as tall as all of them; the header and the row-number gutter stick to the edges
|
|
37
39
|
* of the scroll box. Focus stays on that box and points at the cell with `aria-activedescendant`, so
|
|
38
40
|
* a cell scrolled out of the window loses nothing.
|
|
39
41
|
*/
|
|
40
42
|
export function DataGrid({ columns, rows, label, editable = false, selectedKeys, onSelectedKeysChange, onCommit, loadValue, onNotice, sorts, onSortsChange, onFocusedCellChange, onDeleteSelected, sqlTarget, queryMenu, menu, onDuplicateRows, onFollow, canFollow, onRangeChange, initialLayout, onLayoutChange, focusRequest, columnRequest, empty, className, ref }) {
|
|
43
|
+
// A grid drawn without a `DatabaseProvider`, such as one over the rows of a file, still reads its words.
|
|
44
|
+
useDatabaseResources();
|
|
41
45
|
const { t } = useTranslation('database');
|
|
42
46
|
const gridId = useId();
|
|
43
47
|
const scroller = useRef(null);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { createDatabaseClient, DatabaseRequestError, type Connection, type DatabaseClient, type DatabaseClientOptions, type DatabaseSession, type DatabaseTransport, type ExecuteOptions, type ExecuteResult, type ExportRequest, type ExportResult, type ImportRequest, type PageQuery, type RequestOptions, type RowsQuery, type SchemaChange, type TableRef } from './client/index.ts';
|
|
2
2
|
export type { DatabaseAction, DatabaseFiles, DatabaseNotice, DatabaseStorage, ExplorerSelection } from './actions.ts';
|
|
3
|
+
export type { Cell, Value, ValueKind } from './protocol/index.ts';
|
|
4
|
+
export type { SortDirection } from './sql.ts';
|
|
3
5
|
export { ConnectionForm, type ConnectionFormProps } from './connections/ConnectionForm.tsx';
|
|
4
6
|
export { isValidConfig, type ConfigProblem, type ConfigProblems } from './connections/connection-config.ts';
|
|
5
7
|
export { ConnectionManager, type ConnectionManagerProps } from './connections/ConnectionManager.tsx';
|
|
@@ -9,7 +11,11 @@ export type { ExplorerFolder, ExplorerItem } from './explorer/folders.ts';
|
|
|
9
11
|
export { TableDesigner, type TableDesignerProps } from './designer/TableDesigner.tsx';
|
|
10
12
|
export { DatabaseProvider, type DatabaseProviderProps } from './DatabaseProvider.tsx';
|
|
11
13
|
export { useDatabaseClient } from './client-context.ts';
|
|
14
|
+
export { DataGrid, type DataGridProps } from './grid/DataGrid.tsx';
|
|
15
|
+
export type { GridLayout } from './grid/column-layout.ts';
|
|
12
16
|
export type { NumberNotation } from './grid/display.ts';
|
|
17
|
+
export type { GridSort } from './grid/sort.ts';
|
|
18
|
+
export type { FocusedCell, GridColumn, GridMenuContext, GridRow, GridRowState } from './grid/types.ts';
|
|
13
19
|
export { QueryConsole, type QueryConsoleProps } from './console/QueryConsole.tsx';
|
|
14
20
|
export type { QueryConsoleEditorHandle, QueryConsoleEditorProps, QueryConsoleRunScope } from './console/editor-slot.ts';
|
|
15
21
|
export { runScopeOf } from './console/shortcuts.ts';
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export { DatabaseExplorer } from './explorer/DatabaseExplorer.js';
|
|
|
8
8
|
export { TableDesigner } from './designer/TableDesigner.js';
|
|
9
9
|
export { DatabaseProvider } from './DatabaseProvider.js';
|
|
10
10
|
export { useDatabaseClient } from './client-context.js';
|
|
11
|
+
export { DataGrid } from './grid/DataGrid.js';
|
|
11
12
|
export { QueryConsole } from './console/QueryConsole.js';
|
|
12
13
|
export { runScopeOf } from './console/shortcuts.js';
|
|
13
14
|
export { StructureView } from './structure/StructureView.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useDatabaseResources(): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import { addDatabaseResources } from './locales.js';
|
|
4
|
+
/* Adds the package's words to the i18next the app's `UIProvider` was given. In render, as `UIProvider` does, so the first view already reads them. */
|
|
5
|
+
export function useDatabaseResources() {
|
|
6
|
+
const { i18n } = useTranslation();
|
|
7
|
+
const [added, setAdded] = useState(null);
|
|
8
|
+
if (added !== i18n) {
|
|
9
|
+
addDatabaseResources(i18n);
|
|
10
|
+
setAdded(i18n);
|
|
11
|
+
}
|
|
12
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adecore/database",
|
|
3
|
-
"version": "0.26.
|
|
3
|
+
"version": "0.26.2",
|
|
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,20 +61,20 @@
|
|
|
61
61
|
"lucide-react": "^1.47.0"
|
|
62
62
|
},
|
|
63
63
|
"optionalDependencies": {
|
|
64
|
-
"@adecore/database-darwin-arm64": "0.26.
|
|
65
|
-
"@adecore/database-linux-arm64": "0.26.
|
|
66
|
-
"@adecore/database-linux-x64": "0.26.
|
|
67
|
-
"@adecore/database-win32-x64": "0.26.
|
|
64
|
+
"@adecore/database-darwin-arm64": "0.26.2",
|
|
65
|
+
"@adecore/database-linux-arm64": "0.26.2",
|
|
66
|
+
"@adecore/database-linux-x64": "0.26.2",
|
|
67
|
+
"@adecore/database-win32-x64": "0.26.2"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
|
-
"@adecore/ui": "^0.26.
|
|
70
|
+
"@adecore/ui": "^0.26.2",
|
|
71
71
|
"i18next": "^26.4.2",
|
|
72
72
|
"react": "^19.3.0",
|
|
73
73
|
"react-dom": "^19.3.0",
|
|
74
74
|
"react-i18next": "^17.0.15"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
|
-
"@adecore/ui": "0.26.
|
|
77
|
+
"@adecore/ui": "0.26.2",
|
|
78
78
|
"@happy-dom/global-registrator": "^20.14.5",
|
|
79
79
|
"@types/bun": "^1.4.2",
|
|
80
80
|
"@types/node": "^24.13.6",
|
package/src/DatabaseProvider.tsx
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { use, useMemo,
|
|
2
|
-
import { useTranslation } from 'react-i18next';
|
|
1
|
+
import { use, useMemo, type ReactNode } from 'react';
|
|
3
2
|
import type { DatabaseAction, DatabaseFiles, DatabaseNotice, DatabaseStorage } from './actions.ts';
|
|
4
3
|
import type { DatabaseClient } from './client/types.ts';
|
|
5
4
|
import { DatabaseContext } from './client-context.ts';
|
|
6
5
|
import type { NumberNotation } from './grid/display.ts';
|
|
7
|
-
import {
|
|
6
|
+
import { useDatabaseResources } from './use-database-resources.ts';
|
|
8
7
|
|
|
9
8
|
export interface DatabaseProviderProps {
|
|
10
9
|
/* Required on the outermost provider. A provider inside another takes every prop it leaves out from the one above. */
|
|
@@ -26,14 +25,8 @@ export interface DatabaseProviderProps {
|
|
|
26
25
|
|
|
27
26
|
/* Hands every view below it the client and the app's hooks, and adds the package's words to the i18next the app's `UIProvider` was given. Mount it inside that provider. */
|
|
28
27
|
export function DatabaseProvider({ client, onAction, onNotice, storage, files, numberNotation, children }: DatabaseProviderProps) {
|
|
29
|
-
|
|
28
|
+
useDatabaseResources();
|
|
30
29
|
const outer = use(DatabaseContext);
|
|
31
|
-
const [added, setAdded] = useState<typeof i18n | null>(null);
|
|
32
|
-
// In render, as `UIProvider` does, so the first view already reads its words.
|
|
33
|
-
if (added !== i18n) {
|
|
34
|
-
addDatabaseResources(i18n);
|
|
35
|
-
setAdded(i18n);
|
|
36
|
-
}
|
|
37
30
|
|
|
38
31
|
const ownClient = client ?? outer?.client;
|
|
39
32
|
const ownAction = onAction ?? outer?.onAction;
|
package/src/grid/DataGrid.tsx
CHANGED
|
@@ -22,6 +22,7 @@ import { assignRef } from '../assign-ref.ts';
|
|
|
22
22
|
import type { SqlTarget } from '../sql.ts';
|
|
23
23
|
import { useNumberNotation } from '../client-context.ts';
|
|
24
24
|
import { usePopupPress } from '../use-popup-press.ts';
|
|
25
|
+
import { useDatabaseResources } from '../use-database-resources.ts';
|
|
25
26
|
import { useStableCallback } from '../use-stable-callback.ts';
|
|
26
27
|
import type { RangeBlock } from './aggregates.ts';
|
|
27
28
|
import { fullRect, rectBetween, rectContains } from './cell-range.ts';
|
|
@@ -75,6 +76,7 @@ export interface DataGridProps {
|
|
|
75
76
|
onNotice?(notice: DatabaseNotice): void;
|
|
76
77
|
/* The sorted columns by name, in order. Only shown unless `onSortsChange` is given, which is what makes the headers sort. */
|
|
77
78
|
sorts?: readonly GridSort[];
|
|
79
|
+
/* A header's menu picked a sort. The grid draws `rows` in the order given, so the handler orders them and passes `sorts` back. */
|
|
78
80
|
onSortsChange?(sorts: readonly GridSort[]): void;
|
|
79
81
|
/* The cell that holds the focus changed, or lost it. */
|
|
80
82
|
onFocusedCellChange?(cell: FocusedCell | null): void;
|
|
@@ -141,7 +143,8 @@ const estimateWidths = (columns: readonly GridColumn[], rows: readonly GridRow[]
|
|
|
141
143
|
);
|
|
142
144
|
|
|
143
145
|
/*
|
|
144
|
-
* The table of the table view and of the console
|
|
146
|
+
* The table of the table view and of the console, and of any rows an app has on its own: it needs no
|
|
147
|
+
* `DatabaseProvider`, only the `UIProvider` of `@adecore/ui`. Only the rows in view are drawn, at a fixed
|
|
145
148
|
* height, inside a box as tall as all of them; the header and the row-number gutter stick to the edges
|
|
146
149
|
* of the scroll box. Focus stays on that box and points at the cell with `aria-activedescendant`, so
|
|
147
150
|
* a cell scrolled out of the window loses nothing.
|
|
@@ -175,6 +178,8 @@ export function DataGrid({
|
|
|
175
178
|
className,
|
|
176
179
|
ref
|
|
177
180
|
}: DataGridProps) {
|
|
181
|
+
// A grid drawn without a `DatabaseProvider`, such as one over the rows of a file, still reads its words.
|
|
182
|
+
useDatabaseResources();
|
|
178
183
|
const { t } = useTranslation('database');
|
|
179
184
|
const gridId = useId();
|
|
180
185
|
const scroller = useRef<HTMLDivElement | null>(null);
|
package/src/grid/types.ts
CHANGED
|
@@ -23,6 +23,7 @@ export interface GridRow {
|
|
|
23
23
|
readonly key: string;
|
|
24
24
|
/* The number in the gutter; `null` for a row that does not exist yet. */
|
|
25
25
|
readonly number: number | null;
|
|
26
|
+
/* One per column, in the order of the columns. A `null` draws as a faint NULL, so an empty text is `''`. */
|
|
26
27
|
readonly cells: readonly Shown[];
|
|
27
28
|
readonly state?: GridRowState;
|
|
28
29
|
/* Indexes of the cells with a pending edit. */
|
package/src/index.ts
CHANGED
|
@@ -21,6 +21,8 @@ export {
|
|
|
21
21
|
} from './client/index.ts';
|
|
22
22
|
|
|
23
23
|
export type { DatabaseAction, DatabaseFiles, DatabaseNotice, DatabaseStorage, ExplorerSelection } from './actions.ts';
|
|
24
|
+
export type { Cell, Value, ValueKind } from './protocol/index.ts';
|
|
25
|
+
export type { SortDirection } from './sql.ts';
|
|
24
26
|
|
|
25
27
|
export { ConnectionForm, type ConnectionFormProps } from './connections/ConnectionForm.tsx';
|
|
26
28
|
export { isValidConfig, type ConfigProblem, type ConfigProblems } from './connections/connection-config.ts';
|
|
@@ -31,7 +33,11 @@ export type { ExplorerFolder, ExplorerItem } from './explorer/folders.ts';
|
|
|
31
33
|
export { TableDesigner, type TableDesignerProps } from './designer/TableDesigner.tsx';
|
|
32
34
|
export { DatabaseProvider, type DatabaseProviderProps } from './DatabaseProvider.tsx';
|
|
33
35
|
export { useDatabaseClient } from './client-context.ts';
|
|
36
|
+
export { DataGrid, type DataGridProps } from './grid/DataGrid.tsx';
|
|
37
|
+
export type { GridLayout } from './grid/column-layout.ts';
|
|
34
38
|
export type { NumberNotation } from './grid/display.ts';
|
|
39
|
+
export type { GridSort } from './grid/sort.ts';
|
|
40
|
+
export type { FocusedCell, GridColumn, GridMenuContext, GridRow, GridRowState } from './grid/types.ts';
|
|
35
41
|
export { QueryConsole, type QueryConsoleProps } from './console/QueryConsole.tsx';
|
|
36
42
|
export type { QueryConsoleEditorHandle, QueryConsoleEditorProps, QueryConsoleRunScope } from './console/editor-slot.ts';
|
|
37
43
|
export { runScopeOf } from './console/shortcuts.ts';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import type { i18n as I18n } from 'i18next';
|
|
4
|
+
import { addDatabaseResources } from './locales.ts';
|
|
5
|
+
|
|
6
|
+
/* Adds the package's words to the i18next the app's `UIProvider` was given. In render, as `UIProvider` does, so the first view already reads them. */
|
|
7
|
+
export function useDatabaseResources(): void {
|
|
8
|
+
const { i18n } = useTranslation();
|
|
9
|
+
const [added, setAdded] = useState<I18n | null>(null);
|
|
10
|
+
if (added !== i18n) {
|
|
11
|
+
addDatabaseResources(i18n);
|
|
12
|
+
setAdded(i18n);
|
|
13
|
+
}
|
|
14
|
+
}
|