@stacksjs/components 0.2.855 → 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.
Files changed (100) hide show
  1. package/dist/ContextMenu-43g3w5tp.stx +188 -0
  2. package/dist/DataGrid-7rt7v865.stx +376 -0
  3. package/dist/GraphView-0t3t9mec.stx +320 -0
  4. package/dist/JsonTree-satc4010.stx +317 -0
  5. package/dist/PreviewFrame-erbgvzj8.stx +257 -0
  6. package/dist/SplitPane-7sqfdwqa.stx +159 -0
  7. package/dist/component-api/component-api.js +36 -0
  8. package/dist/context-menu/context-menu.js +575 -0
  9. package/dist/data-grid/data-grid.js +1244 -0
  10. package/dist/graph-view/graph-view.js +1408 -0
  11. package/dist/index.d.ts +8 -0
  12. package/dist/index.js +22 -20
  13. package/dist/json-tree/json-tree.js +1121 -0
  14. package/dist/preview-frame/preview-frame.js +356 -0
  15. package/dist/split-pane/split-pane.js +364 -0
  16. package/dist/ui/context-menu/ContextMenu.d.ts +14 -0
  17. package/dist/ui/context-menu/context-menu.d.ts +8 -0
  18. package/dist/ui/context-menu/core.d.ts +74 -0
  19. package/dist/ui/context-menu/index.d.ts +11 -0
  20. package/dist/ui/context-menu/view.d.ts +36 -0
  21. package/dist/ui/data-grid/DataGrid.d.ts +30 -0
  22. package/dist/ui/data-grid/core.d.ts +141 -0
  23. package/dist/ui/data-grid/data-grid.d.ts +9 -0
  24. package/dist/ui/data-grid/index.d.ts +20 -0
  25. package/dist/ui/data-grid/view.d.ts +56 -0
  26. package/dist/ui/graph-view/GraphView.d.ts +21 -0
  27. package/dist/ui/graph-view/core/edges.d.ts +34 -0
  28. package/dist/ui/graph-view/core/force.d.ts +10 -0
  29. package/dist/ui/graph-view/core/graph.d.ts +83 -0
  30. package/dist/ui/graph-view/core/index.d.ts +5 -0
  31. package/dist/ui/graph-view/core/layered.d.ts +24 -0
  32. package/dist/ui/graph-view/core/viewport.d.ts +34 -0
  33. package/dist/ui/graph-view/graph-view.d.ts +9 -0
  34. package/dist/ui/graph-view/index.d.ts +21 -0
  35. package/dist/ui/graph-view/view.d.ts +51 -0
  36. package/dist/ui/json-tree/JsonTree.d.ts +18 -0
  37. package/dist/ui/json-tree/core.d.ts +108 -0
  38. package/dist/ui/json-tree/index.d.ts +18 -0
  39. package/dist/ui/json-tree/json-tree.d.ts +10 -0
  40. package/dist/ui/json-tree/tinker.d.ts +84 -0
  41. package/dist/ui/json-tree/view.d.ts +59 -0
  42. package/dist/ui/preview-frame/PreviewFrame.d.ts +44 -0
  43. package/dist/ui/preview-frame/core.d.ts +81 -0
  44. package/dist/ui/preview-frame/index.d.ts +19 -0
  45. package/dist/ui/preview-frame/preview-frame.d.ts +8 -0
  46. package/dist/ui/preview-frame/view.d.ts +37 -0
  47. package/dist/ui/split-pane/SplitPane.d.ts +18 -0
  48. package/dist/ui/split-pane/core.d.ts +58 -0
  49. package/dist/ui/split-pane/index.d.ts +15 -0
  50. package/dist/ui/split-pane/split-pane.d.ts +8 -0
  51. package/dist/ui/split-pane/view.d.ts +27 -0
  52. package/dist/ui/virtual-table/index.d.ts +6 -0
  53. package/dist/utils/component-api.d.ts +4 -0
  54. package/package.json +38 -3
  55. package/src/index.ts +8 -0
  56. package/src/ui/code-editor/README.md +2 -1
  57. package/src/ui/context-menu/ContextMenu.stx +188 -0
  58. package/src/ui/context-menu/README.md +117 -0
  59. package/src/ui/context-menu/context-menu.ts +8 -0
  60. package/src/ui/context-menu/core.ts +250 -0
  61. package/src/ui/context-menu/index.ts +16 -0
  62. package/src/ui/context-menu/view.ts +540 -0
  63. package/src/ui/data-grid/DataGrid.stx +376 -0
  64. package/src/ui/data-grid/README.md +204 -0
  65. package/src/ui/data-grid/core.ts +813 -0
  66. package/src/ui/data-grid/data-grid.ts +9 -0
  67. package/src/ui/data-grid/index.ts +34 -0
  68. package/src/ui/data-grid/view.ts +806 -0
  69. package/src/ui/graph-view/GraphView.stx +320 -0
  70. package/src/ui/graph-view/README.md +210 -0
  71. package/src/ui/graph-view/core/edges.ts +180 -0
  72. package/src/ui/graph-view/core/force.ts +237 -0
  73. package/src/ui/graph-view/core/graph.ts +277 -0
  74. package/src/ui/graph-view/core/index.ts +5 -0
  75. package/src/ui/graph-view/core/layered.ts +256 -0
  76. package/src/ui/graph-view/core/viewport.ts +141 -0
  77. package/src/ui/graph-view/graph-view.ts +9 -0
  78. package/src/ui/graph-view/index.ts +35 -0
  79. package/src/ui/graph-view/view.ts +809 -0
  80. package/src/ui/json-tree/JsonTree.stx +317 -0
  81. package/src/ui/json-tree/README.md +193 -0
  82. package/src/ui/json-tree/core.ts +588 -0
  83. package/src/ui/json-tree/index.ts +28 -0
  84. package/src/ui/json-tree/json-tree.ts +10 -0
  85. package/src/ui/json-tree/tinker.ts +349 -0
  86. package/src/ui/json-tree/view.ts +665 -0
  87. package/src/ui/preview-frame/PreviewFrame.stx +257 -0
  88. package/src/ui/preview-frame/README.md +107 -0
  89. package/src/ui/preview-frame/core.ts +195 -0
  90. package/src/ui/preview-frame/index.ts +31 -0
  91. package/src/ui/preview-frame/preview-frame.ts +8 -0
  92. package/src/ui/preview-frame/view.ts +336 -0
  93. package/src/ui/split-pane/README.md +87 -0
  94. package/src/ui/split-pane/SplitPane.stx +159 -0
  95. package/src/ui/split-pane/core.ts +200 -0
  96. package/src/ui/split-pane/index.ts +24 -0
  97. package/src/ui/split-pane/split-pane.ts +8 -0
  98. package/src/ui/split-pane/view.ts +305 -0
  99. package/src/ui/virtual-table/index.ts +6 -0
  100. package/src/utils/component-api.ts +72 -0
@@ -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,5 @@
1
+ export * from './edges';
2
+ export * from './force';
3
+ export * from './graph';
4
+ export * from './layered';
5
+ export * from './viewport';
@@ -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
+ }
@@ -0,0 +1,18 @@
1
+ import type { TinkerValue } from './tinker';
2
+ import type { TreeNode, TreeOpenKind, TreePath } from './core';
3
+ export declare interface JsonTreeProps {
4
+ value?: TreeNode | TreeNode[] | null
5
+ tinker?: TinkerValue | null
6
+ depth?: number
7
+ rowHeight?: number
8
+ height?: string
9
+ label?: string
10
+ openable?: (node: TreeNode, path: TreePath) => TreeOpenKind | TreeOpenKind[] | null | undefined
11
+ contextMenu?: boolean
12
+ id?: string
13
+ className?: string
14
+ }
15
+ export * from './core';
16
+ export { default as JsonTree } from './JsonTree';
17
+ export * from './tinker';
18
+ export * from './view';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The value inspector without its stx template.
3
+ *
4
+ * `@stacksjs/components/json-tree`. The model (`./core`, no DOM), the adapter
5
+ * for tinker results (`./tinker`) and the view that draws a model into any
6
+ * element.
7
+ */
8
+ export * from './core';
9
+ export * from './tinker';
10
+ export * from './view';
@@ -0,0 +1,84 @@
1
+ import type { TreeNode } from './core';
2
+ /**
3
+ * Turn a tinker value into a tree node.
4
+ *
5
+ * Every container keeps the serializer's object id (prefixed), which is what a
6
+ * `ref` names, so following a cycle in the tree lands on the right node.
7
+ */
8
+ export declare function fromTinkerValue(value: TinkerValue, label?: string, options?: FromTinkerOptions): TreeNode;
9
+ export declare interface TinkerStackFrame {
10
+ function?: string
11
+ file?: string
12
+ line?: number
13
+ column?: number
14
+ }
15
+ export declare interface TinkerErrorValue {
16
+ t: 'error'
17
+ name: string
18
+ message: string
19
+ stack?: string
20
+ frames?: TinkerStackFrame[]
21
+ cause?: TinkerValue
22
+ entries?: Array<[string, TinkerValue]>
23
+ }
24
+ export declare interface TinkerModelValue {
25
+ t: 'model'
26
+ id: number
27
+ model: string
28
+ table?: string
29
+ primaryKey?: string
30
+ key?: TinkerValue
31
+ attributes: Array<[string, TinkerValue]>
32
+ hidden?: string[]
33
+ loaded?: Array<[string, TinkerValue]>
34
+ relations?: Array<{ kind: string, model: string, name?: string }>
35
+ more?: number
36
+ }
37
+ export declare interface TinkerHtmlValue {
38
+ t: 'html'
39
+ kind: 'mail' | 'view' | 'html'
40
+ title?: string
41
+ html: string
42
+ text?: string
43
+ truncated?: number
44
+ }
45
+ export declare interface FromTinkerOptions {
46
+ idPrefix?: string
47
+ }
48
+ /** What the tree's `meta` holds for a model node. */
49
+ export declare interface TinkerModelMeta {
50
+ model: string
51
+ table?: string
52
+ primaryKey?: string
53
+ hidden: string[]
54
+ relations: Array<{ kind: string, model: string, name?: string }>
55
+ }
56
+ /** What the tree's `meta` holds for rendered markup. */
57
+ export declare interface TinkerHtmlMeta {
58
+ kind: TinkerHtmlValue['kind']
59
+ title?: string
60
+ text?: string
61
+ truncated?: number
62
+ }
63
+ export type TinkerValue = | { t: 'undefined' }
64
+ | { t: 'null' }
65
+ | { t: 'boolean', v: boolean }
66
+ | { t: 'number', v: number | 'NaN' | 'Infinity' | '-Infinity' | '-0' }
67
+ | { t: 'bigint', v: string }
68
+ | { t: 'string', v: string, truncated?: number }
69
+ | { t: 'symbol', v: string }
70
+ | { t: 'function', name: string, kind: 'function' | 'async' | 'class' | 'generator' }
71
+ | { t: 'date', v: string | null }
72
+ | { t: 'regexp', v: string }
73
+ | { t: 'url', v: string }
74
+ | { t: 'promise' }
75
+ | { t: 'bytes', ctor: string, length: number, hex: string }
76
+ | { t: 'array', id: number, ctor?: string, length: number, items: TinkerValue[], more?: number }
77
+ | { t: 'object', id: number, ctor?: string, entries: Array<[string, TinkerValue]>, more?: number }
78
+ | { t: 'map', id: number, size: number, entries: Array<[TinkerValue, TinkerValue]>, more?: number }
79
+ | { t: 'set', id: number, size: number, items: TinkerValue[], more?: number }
80
+ | TinkerModelValue
81
+ | TinkerHtmlValue
82
+ | { t: 'ref', id: number }
83
+ | { t: 'cut', reason: 'depth' | 'nodes', ctor?: string }
84
+ | TinkerErrorValue;