@stacksjs/components 0.2.854 → 0.2.857
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/CodeEditor-jg4w7e15.stx +497 -0
- package/dist/ContextMenu-43g3w5tp.stx +188 -0
- package/dist/DataGrid-7rt7v865.stx +376 -0
- package/dist/GraphView-0t3t9mec.stx +320 -0
- package/dist/JsonTree-satc4010.stx +317 -0
- package/dist/PreviewFrame-erbgvzj8.stx +257 -0
- package/dist/SplitPane-7sqfdwqa.stx +159 -0
- package/dist/code-editor/editor.js +2166 -0
- package/dist/component-api/component-api.js +36 -0
- package/dist/components/CodeBlock.d.ts +12 -5
- package/dist/context-menu/context-menu.js +575 -0
- package/dist/data-grid/data-grid.js +1244 -0
- package/dist/graph-view/graph-view.js +1408 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +34 -15
- package/dist/json-tree/json-tree.js +1121 -0
- package/dist/preview-frame/preview-frame.js +356 -0
- package/dist/split-pane/split-pane.js +364 -0
- package/dist/ui/code-editor/CodeEditor.d.ts +46 -0
- package/dist/ui/code-editor/controller.d.ts +103 -0
- package/dist/ui/code-editor/core/commands.d.ts +55 -0
- package/dist/ui/code-editor/core/completion.d.ts +40 -0
- package/dist/ui/code-editor/core/editor.d.ts +69 -0
- package/dist/ui/code-editor/core/highlight.d.ts +61 -0
- package/dist/ui/code-editor/core/history.d.ts +27 -0
- package/dist/ui/code-editor/core/index.d.ts +13 -0
- package/dist/ui/code-editor/core/keymap.d.ts +38 -0
- package/dist/ui/code-editor/core/selection.d.ts +30 -0
- package/dist/ui/code-editor/core/text.d.ts +64 -0
- package/dist/ui/code-editor/editor.d.ts +15 -0
- package/dist/ui/code-editor/index.d.ts +29 -0
- package/dist/ui/code-editor/tokenizer.d.ts +18 -0
- package/dist/ui/code-editor/view.d.ts +59 -0
- package/dist/ui/context-menu/ContextMenu.d.ts +14 -0
- package/dist/ui/context-menu/context-menu.d.ts +8 -0
- package/dist/ui/context-menu/core.d.ts +74 -0
- package/dist/ui/context-menu/index.d.ts +11 -0
- package/dist/ui/context-menu/view.d.ts +36 -0
- package/dist/ui/data-grid/DataGrid.d.ts +30 -0
- package/dist/ui/data-grid/core.d.ts +141 -0
- package/dist/ui/data-grid/data-grid.d.ts +9 -0
- package/dist/ui/data-grid/index.d.ts +20 -0
- package/dist/ui/data-grid/view.d.ts +56 -0
- package/dist/ui/graph-view/GraphView.d.ts +21 -0
- package/dist/ui/graph-view/core/edges.d.ts +34 -0
- package/dist/ui/graph-view/core/force.d.ts +10 -0
- package/dist/ui/graph-view/core/graph.d.ts +83 -0
- package/dist/ui/graph-view/core/index.d.ts +5 -0
- package/dist/ui/graph-view/core/layered.d.ts +24 -0
- package/dist/ui/graph-view/core/viewport.d.ts +34 -0
- package/dist/ui/graph-view/graph-view.d.ts +9 -0
- package/dist/ui/graph-view/index.d.ts +21 -0
- package/dist/ui/graph-view/view.d.ts +51 -0
- package/dist/ui/json-tree/JsonTree.d.ts +18 -0
- package/dist/ui/json-tree/core.d.ts +108 -0
- package/dist/ui/json-tree/index.d.ts +18 -0
- package/dist/ui/json-tree/json-tree.d.ts +10 -0
- package/dist/ui/json-tree/tinker.d.ts +84 -0
- package/dist/ui/json-tree/view.d.ts +59 -0
- package/dist/ui/preview-frame/PreviewFrame.d.ts +44 -0
- package/dist/ui/preview-frame/core.d.ts +81 -0
- package/dist/ui/preview-frame/index.d.ts +19 -0
- package/dist/ui/preview-frame/preview-frame.d.ts +8 -0
- package/dist/ui/preview-frame/view.d.ts +37 -0
- package/dist/ui/split-pane/SplitPane.d.ts +18 -0
- package/dist/ui/split-pane/core.d.ts +58 -0
- package/dist/ui/split-pane/index.d.ts +15 -0
- package/dist/ui/split-pane/split-pane.d.ts +8 -0
- package/dist/ui/split-pane/view.d.ts +27 -0
- package/dist/ui/virtual-table/index.d.ts +6 -0
- package/dist/utils/component-api.d.ts +4 -0
- package/dist/utils/highlighter.d.ts +19 -1
- package/dist/utils/highlighter.js +24 -7
- package/dist/utils/syntax-theme.d.ts +44 -0
- package/package.json +44 -4
- package/src/components/CodeBlock.stx +195 -17
- package/src/index.ts +10 -0
- package/src/ui/code-editor/CodeEditor.stx +497 -0
- package/src/ui/code-editor/README.md +135 -0
- package/src/ui/code-editor/controller.ts +517 -0
- package/src/ui/code-editor/core/commands.ts +381 -0
- package/src/ui/code-editor/core/completion.ts +212 -0
- package/src/ui/code-editor/core/editor.ts +319 -0
- package/src/ui/code-editor/core/highlight.ts +203 -0
- package/src/ui/code-editor/core/history.ts +190 -0
- package/src/ui/code-editor/core/index.ts +14 -0
- package/src/ui/code-editor/core/keymap.ts +125 -0
- package/src/ui/code-editor/core/selection.ts +104 -0
- package/src/ui/code-editor/core/text.ts +252 -0
- package/src/ui/code-editor/editor.ts +16 -0
- package/src/ui/code-editor/index.ts +46 -0
- package/src/ui/code-editor/tokenizer.ts +74 -0
- package/src/ui/code-editor/view.ts +1066 -0
- package/src/ui/context-menu/ContextMenu.stx +188 -0
- package/src/ui/context-menu/README.md +117 -0
- package/src/ui/context-menu/context-menu.ts +8 -0
- package/src/ui/context-menu/core.ts +250 -0
- package/src/ui/context-menu/index.ts +16 -0
- package/src/ui/context-menu/view.ts +540 -0
- package/src/ui/data-grid/DataGrid.stx +376 -0
- package/src/ui/data-grid/README.md +204 -0
- package/src/ui/data-grid/core.ts +813 -0
- package/src/ui/data-grid/data-grid.ts +9 -0
- package/src/ui/data-grid/index.ts +34 -0
- package/src/ui/data-grid/view.ts +806 -0
- package/src/ui/graph-view/GraphView.stx +320 -0
- package/src/ui/graph-view/README.md +210 -0
- package/src/ui/graph-view/core/edges.ts +180 -0
- package/src/ui/graph-view/core/force.ts +237 -0
- package/src/ui/graph-view/core/graph.ts +277 -0
- package/src/ui/graph-view/core/index.ts +5 -0
- package/src/ui/graph-view/core/layered.ts +256 -0
- package/src/ui/graph-view/core/viewport.ts +141 -0
- package/src/ui/graph-view/graph-view.ts +9 -0
- package/src/ui/graph-view/index.ts +35 -0
- package/src/ui/graph-view/view.ts +809 -0
- package/src/ui/json-tree/JsonTree.stx +317 -0
- package/src/ui/json-tree/README.md +193 -0
- package/src/ui/json-tree/core.ts +588 -0
- package/src/ui/json-tree/index.ts +28 -0
- package/src/ui/json-tree/json-tree.ts +10 -0
- package/src/ui/json-tree/tinker.ts +349 -0
- package/src/ui/json-tree/view.ts +665 -0
- package/src/ui/preview-frame/PreviewFrame.stx +257 -0
- package/src/ui/preview-frame/README.md +107 -0
- package/src/ui/preview-frame/core.ts +195 -0
- package/src/ui/preview-frame/index.ts +31 -0
- package/src/ui/preview-frame/preview-frame.ts +8 -0
- package/src/ui/preview-frame/view.ts +336 -0
- package/src/ui/split-pane/README.md +87 -0
- package/src/ui/split-pane/SplitPane.stx +159 -0
- package/src/ui/split-pane/core.ts +200 -0
- package/src/ui/split-pane/index.ts +24 -0
- package/src/ui/split-pane/split-pane.ts +8 -0
- package/src/ui/split-pane/view.ts +305 -0
- package/src/ui/virtual-table/index.ts +6 -0
- package/src/utils/component-api.ts +72 -0
- package/src/utils/highlighter.ts +121 -218
- package/src/utils/syntax-theme.ts +144 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/** The cell a column shows for a row. */
|
|
2
|
+
export declare function cellValue<Row>(row: Row, column: GridColumn<Row>): unknown;
|
|
3
|
+
/**
|
|
4
|
+
* What kind of column a list of values makes.
|
|
5
|
+
*
|
|
6
|
+
* Nulls say nothing and are skipped. A column is a number column only when
|
|
7
|
+
* every value is a number or reads as one: a single `n/a` among the figures
|
|
8
|
+
* makes it text, because sorting it as numbers would have to put that
|
|
9
|
+
* somewhere it does not belong.
|
|
10
|
+
*/
|
|
11
|
+
export declare function inferType(values: readonly unknown[]): GridColumnType;
|
|
12
|
+
/**
|
|
13
|
+
* Columns for rows nobody described: every key of the first `sample` rows, in
|
|
14
|
+
* the order first seen. Rows that are arrays get a column per position.
|
|
15
|
+
*/
|
|
16
|
+
export declare function inferColumns<Row>(rows: readonly Row[], sample?: number): GridColumn<Row>[];
|
|
17
|
+
/** Whether a cell is empty, and which kind of empty. */
|
|
18
|
+
export declare function cellKind(value: unknown): 'null' | 'undefined' | 'value';
|
|
19
|
+
/**
|
|
20
|
+
* The text of a cell.
|
|
21
|
+
*
|
|
22
|
+
* A number is shown as it is, digit for digit: a grid of results is for
|
|
23
|
+
* reading values, and grouping or rounding would show something other than
|
|
24
|
+
* what is there. Lining the digits up is the stylesheet's job.
|
|
25
|
+
*/
|
|
26
|
+
export declare function formatCell(value: unknown, type?: GridColumnType): string;
|
|
27
|
+
/** A cell as JSON, the way it is copied. */
|
|
28
|
+
export declare function cellJson(value: unknown): string;
|
|
29
|
+
/** A row as an object of its columns. */
|
|
30
|
+
export declare function projectRow<Row>(row: Row, columns: readonly GridColumn<Row>[]): Record<string, unknown>;
|
|
31
|
+
/** A row as JSON, the way it is copied: its columns, indented. */
|
|
32
|
+
export declare function rowJson<Row>(row: Row, columns: readonly GridColumn<Row>[]): string;
|
|
33
|
+
/** Rows as a JSON array of objects, one property per column. */
|
|
34
|
+
export declare function toJson<Row>(rows: readonly Row[], columns: readonly GridColumn<Row>[]): string;
|
|
35
|
+
/** Rows as CSV: a header row, CRLF line ends, RFC 4180 quoting. */
|
|
36
|
+
export declare function toCsv<Row>(rows: readonly Row[], columns: readonly GridColumn<Row>[]): string;
|
|
37
|
+
/** The rows (or columns) that intersect a viewport, widened by `overscan`. */
|
|
38
|
+
export declare function rowRange(scroll: number, viewport: number, rowHeight: number, count: number, overscan?: number): GridRange;
|
|
39
|
+
/**
|
|
40
|
+
* Where a key takes the active cell.
|
|
41
|
+
*
|
|
42
|
+
* Row -1 is the header, so the header is part of the grid a keyboard can
|
|
43
|
+
* reach: up from the first row lands on it, and down leaves it.
|
|
44
|
+
*/
|
|
45
|
+
export declare function moveCell(cell: GridCell, key: string, bounds: { rows: number, columns: number, page: number, mod?: boolean }): GridCell;
|
|
46
|
+
/** The next sort after a click on a column: ascending, descending, then none. */
|
|
47
|
+
export declare function cycleSort(sort: readonly GridSort[], key: string, additive?: boolean): GridSort[];
|
|
48
|
+
export declare const DEFAULT_MIN_WIDTH: 48;
|
|
49
|
+
export declare const DEFAULT_MAX_WIDTH: 2000;
|
|
50
|
+
/** A column fitted to its content stops here, however long a value is. */
|
|
51
|
+
export declare const FIT_MAX_WIDTH: 420;
|
|
52
|
+
/** JSON shown in a cell is cut here. The whole value is still what is copied. */
|
|
53
|
+
export declare const JSON_PREVIEW_LENGTH: 160;
|
|
54
|
+
export declare interface GridColumn<Row = any> {
|
|
55
|
+
key: string
|
|
56
|
+
label?: string
|
|
57
|
+
type?: GridColumnType
|
|
58
|
+
width?: number
|
|
59
|
+
minWidth?: number
|
|
60
|
+
maxWidth?: number
|
|
61
|
+
align?: GridAlign
|
|
62
|
+
sortable?: boolean
|
|
63
|
+
accessor?: (row: Row) => unknown
|
|
64
|
+
}
|
|
65
|
+
export declare interface ResolvedColumn<Row = any> extends GridColumn<Row> {
|
|
66
|
+
label: string
|
|
67
|
+
type: GridColumnType
|
|
68
|
+
width: number
|
|
69
|
+
minWidth: number
|
|
70
|
+
maxWidth: number
|
|
71
|
+
align: GridAlign
|
|
72
|
+
sortable: boolean
|
|
73
|
+
}
|
|
74
|
+
export declare interface GridSort {
|
|
75
|
+
key: string
|
|
76
|
+
direction: SortDirection
|
|
77
|
+
}
|
|
78
|
+
export declare interface GridCell {
|
|
79
|
+
row: number
|
|
80
|
+
column: number
|
|
81
|
+
}
|
|
82
|
+
export declare interface GridRange {
|
|
83
|
+
start: number
|
|
84
|
+
end: number
|
|
85
|
+
}
|
|
86
|
+
export declare interface GridModelOptions {
|
|
87
|
+
charWidth?: number
|
|
88
|
+
cellPadding?: number
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The model of a data grid. No DOM.
|
|
92
|
+
*
|
|
93
|
+
* A grid is a list of rows somebody else owns, a list of columns, and a view:
|
|
94
|
+
* the source indices of the rows that pass the filter, in sorted order. The
|
|
95
|
+
* rows are never copied or reordered, so a hundred thousand of them cost one
|
|
96
|
+
* `Uint32Array` to show, and selection (kept as source indices) survives a
|
|
97
|
+
* sort or a filter.
|
|
98
|
+
*
|
|
99
|
+
* Everything that is slow to work out per row is worked out once and kept:
|
|
100
|
+
* the text a filter searches, and a number per cell to sort by. A second
|
|
101
|
+
* filter is then a plain `includes` over strings, and a second sort compares
|
|
102
|
+
* numbers whatever the column holds.
|
|
103
|
+
*/
|
|
104
|
+
export type GridColumnType = 'string' | 'number' | 'date' | 'boolean' | 'json';
|
|
105
|
+
export type GridAlign = 'left' | 'right' | 'center';
|
|
106
|
+
export type SortDirection = 'asc' | 'desc';
|
|
107
|
+
export declare class GridModel<Row = any> {
|
|
108
|
+
rows: readonly Row[];
|
|
109
|
+
columns: ResolvedColumn<Row>[];
|
|
110
|
+
view: Uint32Array;
|
|
111
|
+
sort: GridSort[];
|
|
112
|
+
filter: string;
|
|
113
|
+
readonly selected: Set<number>;
|
|
114
|
+
readonly rows: Row[];
|
|
115
|
+
readonly columns: GridColumn<Row>[] | null;
|
|
116
|
+
constructor(rows?: readonly Row[], columns?: readonly GridColumn<Row>[] | null, options?: GridModelOptions);
|
|
117
|
+
get count(): number;
|
|
118
|
+
get totalWidth(): number;
|
|
119
|
+
setRows(rows: readonly Row[] | null | undefined): void;
|
|
120
|
+
setColumns(columns: readonly GridColumn<Row>[] | null | undefined): void;
|
|
121
|
+
setFilter(text: string | null | undefined): number;
|
|
122
|
+
setSort(sort: readonly GridSort[] | null | undefined): void;
|
|
123
|
+
toggleSort(key: string, additive?: boolean): GridSort[];
|
|
124
|
+
sortOf(key: string): { direction: SortDirection, priority: number } | null;
|
|
125
|
+
rowAt(viewIndex: number): Row | undefined;
|
|
126
|
+
valueAt(viewIndex: number, columnIndex: number): unknown;
|
|
127
|
+
viewRows(): Row[];
|
|
128
|
+
toCsv(): string;
|
|
129
|
+
toJson(): string;
|
|
130
|
+
select(viewIndex: number, mode?: 'replace' | 'toggle' | 'range'): void;
|
|
131
|
+
selectAll(): void;
|
|
132
|
+
clearSelection(): void;
|
|
133
|
+
isSelected(viewIndex: number): boolean;
|
|
134
|
+
selectedIndices(): number[];
|
|
135
|
+
selectedRows(): Row[];
|
|
136
|
+
offsetOf(columnIndex: number): number;
|
|
137
|
+
columnAt(x: number): number;
|
|
138
|
+
columnRange(scrollLeft: number, viewportWidth: number, overscan?: number): GridRange;
|
|
139
|
+
resizeColumn(columnIndex: number, width: number): number;
|
|
140
|
+
autoWidth(columnIndex: number, sample?: number): number;
|
|
141
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The data grid without its stx template.
|
|
3
|
+
*
|
|
4
|
+
* `@stacksjs/components/data-grid`. The model (`./core`, no DOM: inference,
|
|
5
|
+
* sort, filter, selection, column geometry, CSV and JSON) and the view that
|
|
6
|
+
* draws it into an element with the grid's parts.
|
|
7
|
+
*/
|
|
8
|
+
export * from './core';
|
|
9
|
+
export * from './view';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { GridColumn } from './core';
|
|
2
|
+
export declare interface DataGridProps<Row = any> {
|
|
3
|
+
rows?: Row[]
|
|
4
|
+
columns?: GridColumn<Row>[]
|
|
5
|
+
rowHeight?: number
|
|
6
|
+
headerHeight?: number
|
|
7
|
+
height?: string
|
|
8
|
+
filterable?: boolean
|
|
9
|
+
exportable?: boolean
|
|
10
|
+
selectable?: boolean
|
|
11
|
+
filter?: string
|
|
12
|
+
label?: string
|
|
13
|
+
fileName?: string
|
|
14
|
+
contextMenu?: boolean
|
|
15
|
+
id?: string
|
|
16
|
+
className?: string
|
|
17
|
+
}
|
|
18
|
+
export * from './core';
|
|
19
|
+
export { default as DataGrid } from './DataGrid';
|
|
20
|
+
export * from './view';
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { GridModel } from './core';
|
|
2
|
+
import type { GridCell, GridColumn, GridSort, ResolvedColumn } from './core';
|
|
3
|
+
export declare interface DataGridOptions<Row = any> {
|
|
4
|
+
rows?: readonly Row[]
|
|
5
|
+
columns?: readonly GridColumn<Row>[] | null
|
|
6
|
+
rowHeight?: number
|
|
7
|
+
headerHeight?: number
|
|
8
|
+
overscan?: number
|
|
9
|
+
columnOverscan?: number
|
|
10
|
+
selectable?: boolean
|
|
11
|
+
filter?: string
|
|
12
|
+
fileName?: string
|
|
13
|
+
contextMenu?: boolean
|
|
14
|
+
resizeStep?: number
|
|
15
|
+
}
|
|
16
|
+
export declare interface GridCellDetail<Row = any> {
|
|
17
|
+
row: Row | undefined
|
|
18
|
+
rowIndex: number
|
|
19
|
+
column: ResolvedColumn<Row> | undefined
|
|
20
|
+
value: unknown
|
|
21
|
+
}
|
|
22
|
+
export declare interface DataGridCallbacks<Row = any> {
|
|
23
|
+
onSort?: (sort: GridSort[]) => void
|
|
24
|
+
onFilter?: (detail: { text: string, count: number }) => void
|
|
25
|
+
onSelect?: (detail: { rows: Row[], indices: number[] }) => void
|
|
26
|
+
onCell?: (detail: GridCellDetail<Row>) => void
|
|
27
|
+
onActivate?: (detail: { row: Row, rowIndex: number }) => void
|
|
28
|
+
onCopy?: (detail: { what: 'cell' | 'row', text: string }) => void
|
|
29
|
+
onExport?: (detail: { format: 'csv' | 'json', text: string, rows: number }) => void
|
|
30
|
+
onContext?: (detail: GridCellDetail<Row> & { x: number, y: number }) => void
|
|
31
|
+
}
|
|
32
|
+
declare type Inert = HTMLElement & { __stx_inert_content?: boolean }
|
|
33
|
+
declare type CellElement = HTMLElement & { __dgColumn?: number }
|
|
34
|
+
declare type RowElement = HTMLElement & { __dgRow?: number }
|
|
35
|
+
export declare class DataGridView<Row = any> {
|
|
36
|
+
readonly model: GridModel<Row>;
|
|
37
|
+
constructor(root: HTMLElement, options?: DataGridOptions<Row>, callbacks?: DataGridCallbacks<Row>);
|
|
38
|
+
setRows(rows: readonly Row[] | null | undefined): void;
|
|
39
|
+
setColumns(columns: readonly GridColumn<Row>[] | null | undefined): void;
|
|
40
|
+
setFilter(text: string | null | undefined): void;
|
|
41
|
+
setSort(sort: readonly GridSort[] | null | undefined): void;
|
|
42
|
+
setFileName(name: string): void;
|
|
43
|
+
getView(): Row[];
|
|
44
|
+
getSelection(): { rows: Row[], indices: number[] };
|
|
45
|
+
clearSelection(): void;
|
|
46
|
+
exportCsv(): string;
|
|
47
|
+
exportJson(): string;
|
|
48
|
+
download(format: 'csv' | 'json'): string;
|
|
49
|
+
scrollToRow(viewIndex: number): void;
|
|
50
|
+
focus(): void;
|
|
51
|
+
getActiveCell(): GridCell;
|
|
52
|
+
setActiveCell(row: number, column: number): void;
|
|
53
|
+
destroy(): void;
|
|
54
|
+
refresh(): void;
|
|
55
|
+
render(): void;
|
|
56
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { DefineComponent } from '@stacksjs/stx';
|
|
2
|
+
declare const __dtsx_component__: __DtsxStxComponentType;
|
|
3
|
+
export declare const nodes: unknown;
|
|
4
|
+
export declare const edges: unknown;
|
|
5
|
+
export declare const layout: boolean;
|
|
6
|
+
export declare const direction: boolean;
|
|
7
|
+
export declare const selected: boolean;
|
|
8
|
+
/* A CSS length. `100%` fills a sized parent, which is what a pane wants. */
|
|
9
|
+
export declare const height: unknown;
|
|
10
|
+
export declare const minZoom: unknown;
|
|
11
|
+
export declare const maxZoom: unknown;
|
|
12
|
+
export declare const toolbar: unknown;
|
|
13
|
+
export declare const contextMenu: ReturnType<typeof $bool>;
|
|
14
|
+
/* Nodes glide to a new layout. Off, they are simply there. */
|
|
15
|
+
export declare const animate: unknown;
|
|
16
|
+
export declare const label: unknown;
|
|
17
|
+
export declare const className: unknown;
|
|
18
|
+
export declare const graphId: unknown;
|
|
19
|
+
export declare const statusId: string;
|
|
20
|
+
declare type __DtsxStxComponentType = DefineComponent<{ nodes?: unknown, edges?: unknown, layout?: unknown, direction?: unknown, selected?: unknown, height?: string, minZoom?: unknown, maxZoom?: unknown, toolbar?: unknown, contextMenu?: unknown, animate?: unknown, label?: string, className?: string, id?: string }> & { readonly __stxEmits?: ["select", "expand", "open", "move", "viewport", "context", "layout"] }
|
|
21
|
+
export default __dtsx_component__;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Point, ResolvedEdge, Size } from './graph';
|
|
2
|
+
/**
|
|
3
|
+
* Where the line from a box's centre towards a point leaves the box.
|
|
4
|
+
* The centre itself when the point is the centre.
|
|
5
|
+
*/
|
|
6
|
+
export declare function clipToRect(centre: Point, size: Size, towards: Point): Point;
|
|
7
|
+
/** An edge from a node to itself: a loop off its top right corner. */
|
|
8
|
+
export declare function selfLoopShape(centre: Point, size: Size, offset?: number): EdgeShape;
|
|
9
|
+
export declare function edgeShape(ends: EdgeEnds, options?: EdgeShapeOptions): EdgeShape;
|
|
10
|
+
/**
|
|
11
|
+
* A sideways shift for each edge that shares its two ends with another, so
|
|
12
|
+
* they are drawn beside each other. An edge alone between its nodes gets none.
|
|
13
|
+
*/
|
|
14
|
+
export declare function parallelOffsets(edges: readonly ResolvedEdge[], spacing?: number): Map<string, number>;
|
|
15
|
+
export declare interface EdgeEnds {
|
|
16
|
+
source: Point
|
|
17
|
+
sourceSize: Size
|
|
18
|
+
target: Point
|
|
19
|
+
targetSize: Size
|
|
20
|
+
}
|
|
21
|
+
export declare interface EdgeShapeOptions {
|
|
22
|
+
curve?: EdgeCurve
|
|
23
|
+
direction?: 'LR' | 'TB'
|
|
24
|
+
offset?: number
|
|
25
|
+
inset?: number
|
|
26
|
+
}
|
|
27
|
+
export declare interface EdgeShape {
|
|
28
|
+
d: string
|
|
29
|
+
start: Point
|
|
30
|
+
end: Point
|
|
31
|
+
label: Point
|
|
32
|
+
angle: number
|
|
33
|
+
}
|
|
34
|
+
export type EdgeCurve = 'straight' | 'bezier';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { GraphModel, Positions } from './graph';
|
|
2
|
+
export declare function forceLayout(graph: GraphModel, options?: ForceOptions): Positions;
|
|
3
|
+
export declare interface ForceOptions {
|
|
4
|
+
iterations?: number
|
|
5
|
+
seed?: number
|
|
6
|
+
positions?: Positions | null
|
|
7
|
+
pinned?: Iterable<string> | null
|
|
8
|
+
linkDistance?: number
|
|
9
|
+
padding?: number
|
|
10
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export declare function labelOf(node: GraphNode): string;
|
|
2
|
+
/** The id an edge gets when it did not bring one. */
|
|
3
|
+
export declare function edgeIdOf(edge: GraphEdge): string;
|
|
4
|
+
/** The size of a node, from the length of what is written in it. */
|
|
5
|
+
export declare function nodeSize(node: GraphNode, metrics?: NodeMetrics): Size;
|
|
6
|
+
/** How many characters of a label fit in a node of the widest size. */
|
|
7
|
+
export declare function maxLabelLength(metrics?: NodeMetrics): number;
|
|
8
|
+
/** A label cut to fit, with an ellipsis where it was cut. */
|
|
9
|
+
export declare function fitLabel(text: string, limit: number): string;
|
|
10
|
+
/** A small, fast, seeded random source. The same seed gives the same layout. */
|
|
11
|
+
export declare function seededRandom(seed: number): () => number;
|
|
12
|
+
export declare const defaultNodeMetrics: NodeMetrics;
|
|
13
|
+
/**
|
|
14
|
+
* A graph: nodes, the edges between them, and who is next to whom. No DOM.
|
|
15
|
+
*
|
|
16
|
+
* Everything the layouts and the view need to ask ("what does this node
|
|
17
|
+
* connect to", "how big is it") is answered here, so neither of them keeps a
|
|
18
|
+
* second copy of the structure that could disagree with the first.
|
|
19
|
+
*/
|
|
20
|
+
export declare interface GraphNode {
|
|
21
|
+
id: string
|
|
22
|
+
label?: string
|
|
23
|
+
kind?: string
|
|
24
|
+
detail?: string
|
|
25
|
+
expandable?: boolean
|
|
26
|
+
data?: unknown
|
|
27
|
+
}
|
|
28
|
+
export declare interface GraphEdge {
|
|
29
|
+
id?: string
|
|
30
|
+
source: string
|
|
31
|
+
target: string
|
|
32
|
+
label?: string
|
|
33
|
+
directed?: boolean
|
|
34
|
+
}
|
|
35
|
+
/** An edge once it is in a graph: it always has an id. */
|
|
36
|
+
export declare interface ResolvedEdge extends GraphEdge {
|
|
37
|
+
id: string
|
|
38
|
+
}
|
|
39
|
+
export declare interface Point {
|
|
40
|
+
x: number
|
|
41
|
+
y: number
|
|
42
|
+
}
|
|
43
|
+
export declare interface Size {
|
|
44
|
+
width: number
|
|
45
|
+
height: number
|
|
46
|
+
}
|
|
47
|
+
/** A box by its top left corner. */
|
|
48
|
+
export declare interface Rect extends Point, Size {}
|
|
49
|
+
/** How a label becomes a size. No measuring: a character is so many pixels. */
|
|
50
|
+
export declare interface NodeMetrics {
|
|
51
|
+
charWidth: number
|
|
52
|
+
paddingX: number
|
|
53
|
+
minWidth: number
|
|
54
|
+
maxWidth: number
|
|
55
|
+
height: number
|
|
56
|
+
detailHeight: number
|
|
57
|
+
}
|
|
58
|
+
/** Positions are node centres, by node id. */
|
|
59
|
+
export type Positions = Map<string, Point>;
|
|
60
|
+
export declare class GraphModel {
|
|
61
|
+
readonly nodes: GraphNode[];
|
|
62
|
+
readonly edges: GraphEdge[];
|
|
63
|
+
readonly metrics: NodeMetrics;
|
|
64
|
+
constructor(nodes?: readonly GraphNode[], edges?: readonly GraphEdge[], metrics?: NodeMetrics);
|
|
65
|
+
get nodes(): GraphNode[];
|
|
66
|
+
get edges(): ResolvedEdge[];
|
|
67
|
+
get nodeCount(): number;
|
|
68
|
+
get edgeCount(): number;
|
|
69
|
+
has(id: string): boolean;
|
|
70
|
+
node(id: string): GraphNode | undefined;
|
|
71
|
+
edge(id: string): ResolvedEdge | undefined;
|
|
72
|
+
addNode(node: GraphNode): boolean;
|
|
73
|
+
addEdge(edge: GraphEdge): boolean;
|
|
74
|
+
updateNode(id: string, patch: Partial<Omit<GraphNode, 'id'>>): boolean;
|
|
75
|
+
removeNode(id: string): boolean;
|
|
76
|
+
removeEdge(id: string): boolean;
|
|
77
|
+
merge(nodes?: readonly GraphNode[], edges?: readonly GraphEdge[]): { nodes: string[], edges: string[] };
|
|
78
|
+
edgesOf(id: string): ResolvedEdge[];
|
|
79
|
+
neighbours(id: string): string[];
|
|
80
|
+
degree(id: string): number;
|
|
81
|
+
size(id: string): Size;
|
|
82
|
+
bounds(positions: Positions): Rect | null;
|
|
83
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { GraphModel, Positions, Rect } from './graph';
|
|
2
|
+
/** The connected parts of the graph, in the order their first node was added. */
|
|
3
|
+
export declare function connectedComponents(graph: GraphModel): string[][];
|
|
4
|
+
/**
|
|
5
|
+
* The edges that have to be turned round for the graph to have no cycle: the
|
|
6
|
+
* ones a depth-first walk finds leading back to a node it is still inside.
|
|
7
|
+
*/
|
|
8
|
+
export declare function findBackEdges(graph: GraphModel): Set<string>;
|
|
9
|
+
export declare function layeredLayout(graph: GraphModel, options?: LayeredOptions): LayeredResult;
|
|
10
|
+
export declare interface LayeredOptions {
|
|
11
|
+
direction?: LayeredDirection
|
|
12
|
+
nodeGap?: number
|
|
13
|
+
layerGap?: number
|
|
14
|
+
componentGap?: number
|
|
15
|
+
sweeps?: number
|
|
16
|
+
}
|
|
17
|
+
export declare interface LayeredResult {
|
|
18
|
+
positions: Positions
|
|
19
|
+
layerOf: Map<string, number>
|
|
20
|
+
reversed: Set<string>
|
|
21
|
+
components: string[][][]
|
|
22
|
+
bounds: Rect | null
|
|
23
|
+
}
|
|
24
|
+
export type LayeredDirection = 'LR' | 'TB';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { GraphModel, Point, Positions, Rect, Size } from './graph';
|
|
2
|
+
export declare function clampZoom(k: number, min: number, max: number): number;
|
|
3
|
+
export declare function toScreen(view: Viewport, point: Point): Point;
|
|
4
|
+
export declare function toGraph(view: Viewport, point: Point): Point;
|
|
5
|
+
export declare function pan(view: Viewport, dx: number, dy: number): Viewport;
|
|
6
|
+
/** Zoom by a factor, keeping the graph point under a screen point where it is. */
|
|
7
|
+
export declare function zoomAt(view: Viewport, point: Point, factor: number, min?: number, max?: number): Viewport;
|
|
8
|
+
/**
|
|
9
|
+
* The view that shows all of `bounds` in a box of `size`, centred, with
|
|
10
|
+
* `padding` clear on every side. It never zooms in past `max`, so a graph of
|
|
11
|
+
* three nodes is not blown up to fill the window.
|
|
12
|
+
*/
|
|
13
|
+
export declare function fit(bounds: Rect | null, size: Size, padding?: number, min?: number, max?: number): Viewport;
|
|
14
|
+
/** The view with a graph point in the middle of the box, at the same zoom. */
|
|
15
|
+
export declare function centreOn(view: Viewport, point: Point, size: Size): Viewport;
|
|
16
|
+
/** The smallest pan that brings a graph box fully inside the screen box. */
|
|
17
|
+
export declare function reveal(view: Viewport, box: Rect, size: Size, margin?: number): Viewport;
|
|
18
|
+
/**
|
|
19
|
+
* The node an arrow key moves to: the nearest one that way, where a node
|
|
20
|
+
* straight ahead beats a closer one off to the side. Null at the edge of the
|
|
21
|
+
* graph.
|
|
22
|
+
*/
|
|
23
|
+
export declare function nearestInDirection(positions: Positions, from: string, heading: Heading): string | null;
|
|
24
|
+
/** The node whose centre is nearest a graph point. For a first focus. */
|
|
25
|
+
export declare function nearestTo(positions: Positions, point: Point): string | null;
|
|
26
|
+
/** The node box under a graph point, the one added last when two overlap. */
|
|
27
|
+
export declare function nodeAt(graph: GraphModel, positions: Positions, point: Point): string | null;
|
|
28
|
+
export declare const identityViewport: Viewport;
|
|
29
|
+
export declare interface Viewport {
|
|
30
|
+
x: number
|
|
31
|
+
y: number
|
|
32
|
+
k: number
|
|
33
|
+
}
|
|
34
|
+
export type Heading = 'left' | 'right' | 'up' | 'down';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The graph view without its stx template.
|
|
3
|
+
*
|
|
4
|
+
* `@stacksjs/components/graph-view`. The model, the two layouts, the edge
|
|
5
|
+
* geometry and the viewport arithmetic (`./core`, no DOM), and the canvas that
|
|
6
|
+
* draws them into an SVG inside any element.
|
|
7
|
+
*/
|
|
8
|
+
export * from './core/index';
|
|
9
|
+
export * from './view';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { GraphEdge, GraphNode, LayeredDirection } from './core/index';
|
|
2
|
+
import type { GraphLayoutName } from './view';
|
|
3
|
+
export declare interface GraphViewProps {
|
|
4
|
+
nodes?: GraphNode[]
|
|
5
|
+
edges?: GraphEdge[]
|
|
6
|
+
layout?: GraphLayoutName
|
|
7
|
+
direction?: LayeredDirection
|
|
8
|
+
selected?: string
|
|
9
|
+
height?: string
|
|
10
|
+
minZoom?: number
|
|
11
|
+
maxZoom?: number
|
|
12
|
+
toolbar?: boolean
|
|
13
|
+
contextMenu?: boolean
|
|
14
|
+
animate?: boolean
|
|
15
|
+
label?: string
|
|
16
|
+
id?: string
|
|
17
|
+
className?: string
|
|
18
|
+
}
|
|
19
|
+
export * from './core/index';
|
|
20
|
+
export { default as GraphView } from './GraphView';
|
|
21
|
+
export * from './view';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { fit, GraphModel } from './core/index';
|
|
2
|
+
import type { GraphEdge, GraphNode, LayeredDirection, Point, Viewport } from './core/index';
|
|
3
|
+
export declare interface GraphCanvasOptions {
|
|
4
|
+
nodes?: readonly GraphNode[]
|
|
5
|
+
edges?: readonly GraphEdge[]
|
|
6
|
+
layout?: GraphLayoutName
|
|
7
|
+
direction?: LayeredDirection
|
|
8
|
+
selected?: string | null
|
|
9
|
+
minZoom?: number
|
|
10
|
+
maxZoom?: number
|
|
11
|
+
label?: string
|
|
12
|
+
contextMenu?: boolean
|
|
13
|
+
animate?: boolean
|
|
14
|
+
}
|
|
15
|
+
export declare interface GraphSelectDetail {
|
|
16
|
+
node: GraphNode | null
|
|
17
|
+
neighbours: GraphNode[]
|
|
18
|
+
}
|
|
19
|
+
export declare interface GraphCanvasCallbacks {
|
|
20
|
+
onSelect?: (detail: GraphSelectDetail) => void
|
|
21
|
+
onExpand?: (detail: { node: GraphNode }) => void
|
|
22
|
+
onOpen?: (detail: { node: GraphNode }) => void
|
|
23
|
+
onMove?: (detail: { node: GraphNode, x: number, y: number }) => void
|
|
24
|
+
onViewport?: (detail: Viewport) => void
|
|
25
|
+
onContext?: (detail: { node: GraphNode | null, x: number, y: number }) => void
|
|
26
|
+
onLayout?: (detail: { layout: GraphLayoutName }) => void
|
|
27
|
+
}
|
|
28
|
+
export type GraphLayoutName = 'layered' | 'force';
|
|
29
|
+
export declare class GraphCanvas {
|
|
30
|
+
readonly timings: Record<string, unknown>;
|
|
31
|
+
constructor(root: HTMLElement, options?: GraphCanvasOptions, callbacks?: GraphCanvasCallbacks);
|
|
32
|
+
graph(): GraphModel;
|
|
33
|
+
getViewport(): Viewport;
|
|
34
|
+
getLayout(): GraphLayoutName;
|
|
35
|
+
getSelected(): string | null;
|
|
36
|
+
getPositions(): Record<string, Point>;
|
|
37
|
+
setGraph(nodes: readonly GraphNode[], edges: readonly GraphEdge[]): void;
|
|
38
|
+
addNeighbours(id: string, nodes: readonly GraphNode[], edges: readonly GraphEdge[]): { nodes: string[], edges: string[] };
|
|
39
|
+
updateNode(id: string, patch: Partial<Omit<GraphNode, 'id'>>): void;
|
|
40
|
+
setLayout(name: GraphLayoutName): void;
|
|
41
|
+
setDirection(direction: LayeredDirection): void;
|
|
42
|
+
select(id: string | null, options?: { silent?: boolean }): void;
|
|
43
|
+
focusNode(id: string): void;
|
|
44
|
+
fit(): void;
|
|
45
|
+
zoomIn(): void;
|
|
46
|
+
zoomOut(): void;
|
|
47
|
+
zoomBy(factor: number, point?: Point): void;
|
|
48
|
+
panBy(dx: number, dy: number): void;
|
|
49
|
+
setZoomLimits(min: number, max: number): void;
|
|
50
|
+
destroy(): void;
|
|
51
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DefineComponent } from '@stacksjs/stx';
|
|
2
|
+
declare const __dtsx_component__: __DtsxStxComponentType;
|
|
3
|
+
/*
|
|
4
|
+
* Either prop can arrive here as an object (a value known on the server) or
|
|
5
|
+
* not at all (a bound one, which the client script reads live).
|
|
6
|
+
*/
|
|
7
|
+
export declare const value: boolean;
|
|
8
|
+
export declare const tinker: boolean;
|
|
9
|
+
export declare const depth: unknown;
|
|
10
|
+
export declare const rowHeight: unknown;
|
|
11
|
+
export declare const contextMenu: ReturnType<typeof $bool>;
|
|
12
|
+
/* A CSS length. `100%` fills a sized parent, which is what a pane wants. */
|
|
13
|
+
export declare const height: unknown;
|
|
14
|
+
export declare const label: unknown;
|
|
15
|
+
export declare const className: unknown;
|
|
16
|
+
export declare const treeId: unknown;
|
|
17
|
+
declare type __DtsxStxComponentType = DefineComponent<{ value?: unknown, tinker?: unknown, depth?: unknown, rowHeight?: unknown, contextMenu?: unknown, height?: string, label?: string, className?: string, id?: string }> & { readonly __stxEmits?: ["select", "toggle", "copy", "open", "load-more", "context"] }
|
|
18
|
+
export default __dtsx_component__;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/** Whether a node's children are numbered rather than named. */
|
|
2
|
+
export declare function isIndexed(node: TreeNode): boolean;
|
|
3
|
+
/** Whether a node can be opened to show something under it. */
|
|
4
|
+
export declare function isExpandable(node: TreeNode): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* A path as JavaScript would write it: `$.users[0]["first name"]`.
|
|
7
|
+
*
|
|
8
|
+
* `$` is the value itself. A name that is a plain identifier is dotted, a
|
|
9
|
+
* number is an index, and anything else is quoted in brackets.
|
|
10
|
+
*/
|
|
11
|
+
export declare function formatPath(path: readonly (string | number)[], root?: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* The plain value a node describes, as far as the description goes.
|
|
14
|
+
*
|
|
15
|
+
* A container becomes an array or an object of what is present: children that
|
|
16
|
+
* were never sent (`more`) are simply not there, and nothing is put in their
|
|
17
|
+
* place, so the result is always the honest JSON of what the tree holds. A
|
|
18
|
+
* cycle becomes the text `[Circular]`. A scalar is its `value` when it has
|
|
19
|
+
* one and its preview otherwise.
|
|
20
|
+
*/
|
|
21
|
+
export declare function nodeToPlain(node: TreeNode): unknown;
|
|
22
|
+
/** The node as indented JSON. `undefined`, which JSON has no word for, is the text `undefined`. */
|
|
23
|
+
export declare function nodeToJson(node: TreeNode, indent?: number): string;
|
|
24
|
+
/** One line for a node that did not bring its own. */
|
|
25
|
+
export declare function previewOf(node: TreeNode): string;
|
|
26
|
+
/**
|
|
27
|
+
* Describe a plain JavaScript value: what `JSON.parse` returns, or any object
|
|
28
|
+
* graph. Cycles become `ref` nodes rather than a loop.
|
|
29
|
+
*/
|
|
30
|
+
export declare function fromValue(value: unknown, label?: string, options?: FromValueOptions): TreeNode;
|
|
31
|
+
export declare interface TreeNode {
|
|
32
|
+
id?: string
|
|
33
|
+
kind: string
|
|
34
|
+
label?: string
|
|
35
|
+
key?: string | number
|
|
36
|
+
preview?: string
|
|
37
|
+
value?: unknown
|
|
38
|
+
children?: TreeNode[]
|
|
39
|
+
more?: number
|
|
40
|
+
ref?: string
|
|
41
|
+
openable?: TreeOpenKind | TreeOpenKind[]
|
|
42
|
+
meta?: unknown
|
|
43
|
+
}
|
|
44
|
+
/** One visible line of the tree. */
|
|
45
|
+
export declare interface TreeRow {
|
|
46
|
+
id: string
|
|
47
|
+
node: TreeNode
|
|
48
|
+
depth: number
|
|
49
|
+
key: string | number
|
|
50
|
+
parent: number
|
|
51
|
+
expandable: boolean
|
|
52
|
+
expanded: boolean
|
|
53
|
+
posInSet: number
|
|
54
|
+
setSize: number
|
|
55
|
+
isMore: boolean
|
|
56
|
+
}
|
|
57
|
+
export declare interface TreeModelOptions {
|
|
58
|
+
depth?: number
|
|
59
|
+
}
|
|
60
|
+
export declare interface FromValueOptions {
|
|
61
|
+
maxItems?: number
|
|
62
|
+
maxDepth?: number
|
|
63
|
+
}
|
|
64
|
+
/** What a key does to a tree: where the cursor goes, and whether the rows changed. */
|
|
65
|
+
export declare interface TreeMove {
|
|
66
|
+
index: number
|
|
67
|
+
changed: boolean
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The model of a value inspector. No DOM.
|
|
71
|
+
*
|
|
72
|
+
* A value is described as a tree of nodes, each saying what kind of thing it
|
|
73
|
+
* is, what to call it and how to show it on one line. The shape is generic on
|
|
74
|
+
* purpose: nothing here knows which serializer produced the description, so
|
|
75
|
+
* the same tree shows a tinker result, a parsed JSON document or a debugger
|
|
76
|
+
* frame. `./tinker` adapts one such serializer; `fromValue` below describes a
|
|
77
|
+
* plain JavaScript value.
|
|
78
|
+
*
|
|
79
|
+
* The model turns that tree into the list of rows currently visible, which is
|
|
80
|
+
* what a virtualized view draws. Only expanded containers are walked, so the
|
|
81
|
+
* cost of every operation follows what is on show, not what exists.
|
|
82
|
+
*/
|
|
83
|
+
/** The ways a node can be opened outside the tree. Any other string is the host's own. */
|
|
84
|
+
export type TreeOpenKind = 'table' | 'graph' | 'preview' | (string & {});
|
|
85
|
+
export type TreePath = Array<string | number>;
|
|
86
|
+
/**
|
|
87
|
+
* The visible rows of a tree, and what is expanded.
|
|
88
|
+
*/
|
|
89
|
+
export declare class TreeModel {
|
|
90
|
+
rows: TreeRow[];
|
|
91
|
+
version: number;
|
|
92
|
+
constructor(value?: TreeNode | TreeNode[] | null, options?: TreeModelOptions);
|
|
93
|
+
setValue(value: TreeNode | TreeNode[] | null | undefined): void;
|
|
94
|
+
setDepth(depth: number): void;
|
|
95
|
+
getRoots(): readonly TreeNode[];
|
|
96
|
+
indexOf(id: string): number;
|
|
97
|
+
pathOf(index: number): TreePath;
|
|
98
|
+
isExpanded(id: string, depth: number): boolean;
|
|
99
|
+
expand(id: string): boolean;
|
|
100
|
+
collapse(id: string): boolean;
|
|
101
|
+
toggle(id: string): boolean;
|
|
102
|
+
expandAll(id?: string): void;
|
|
103
|
+
collapseAll(): void;
|
|
104
|
+
reveal(id: string): number;
|
|
105
|
+
appendChildren(id: string, nodes: TreeNode[], more?: number): boolean;
|
|
106
|
+
move(index: number, key: string, pageSize?: number): TreeMove;
|
|
107
|
+
typeahead(index: number, text: string): number;
|
|
108
|
+
}
|