@g9tm/lynxcontrols-graph 0.0.0-stage → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,94 @@
1
- # Temporary Holding Version
1
+ # @g9tm/lynxcontrols-graph
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ `G9GraphCanvas`, a node graph editor for ReactLynx (2.9.0, from G9 Proxy Manager's route editor). The app draws each
4
+ card; the canvas places the cards, draws the edges and lanes, and handles pan, zoom, drag, selection, keys, menus and
5
+ drops. An optional package: an app that does not import it never bundles it.
6
+
7
+ ```sh
8
+ npm install @g9tm/lynxcontrols-graph
9
+ ```
10
+
11
+ The canvas is at `@g9tm/lynxcontrols-graph`. The plain-TypeScript core (view maths, edge geometry, culling, the layered
12
+ auto-layout) is at `@g9tm/lynxcontrols-graph/core`. It holds no JSX and imports nothing at run time, so Node and hosts
13
+ load it.
14
+
15
+ ## G9GraphCanvas
16
+
17
+ ```tsx
18
+ import { G9GraphCanvas, layeredLayout, type G9GraphNode } from '@g9tm/lynxcontrols-graph';
19
+ import { G9Menu } from '@g9tm/lynxcontrols/popover';
20
+
21
+ const nodes: G9GraphNode[] = proxies.map((p) => ({
22
+ id: p.id, x: p.x, y: p.y, width: 220, height: 96,
23
+ ports: [{ id: 'in', side: 'left' }, { id: 'out', side: 'right' }],
24
+ acceptsDrop: (payload) => payload.kind === 'rule',
25
+ }));
26
+
27
+ <G9GraphCanvas
28
+ id="Routes"
29
+ nodes={nodes}
30
+ edges={[{ id: 'e1', from: { node: 'a', port: 'out' }, to: { node: 'b', port: 'in' }, label: 'fallback', style: 'active' }]}
31
+ groups={[{ id: 'inbound', title: 'Inbound', x: -40, y: -60, width: 300, height: 700 }]}
32
+ renderNode={renderCard} // a stable function: (node, state) => ReactNode
33
+ snap={8}
34
+ onMoveEnd={(moves) => save(moves)} // [{ id, x, y }] of every moved node
35
+ onSelectionChange={setSelected}
36
+ onDelete={(ids) => remove(ids)}
37
+ onContextMenu={(e) => setMenu(e)} // { target, x, y, world, source }
38
+ onDrop={(e) => attach(e.payload, e.nodeId)}
39
+ />;
40
+ <G9Menu
41
+ open={menu !== null}
42
+ anchorPoint={menu ? { x: menu.x, y: menu.y } : undefined}
43
+ items={itemsFor(menu?.target)}
44
+ onSelect={(key) => run(key, menu?.target)}
45
+ onClose={() => setMenu(null)}
46
+ />;
47
+ ```
48
+
49
+ | Area | What it does |
50
+ | --- | --- |
51
+ | Cards | `renderNode(node, state)` draws anything inside the node's box. `state` has `selected`, `focused`, `dragging`, `dropCandidate`, `dropOver` and `zoom`. A card re-renders only when its node or state changes. |
52
+ | Edges | SVG bezier curves from a source port (right side by default) to a target port (left side by default). Each edge can have a `label` (tap: `onEdgePress`), a `color`, a `width` and a `style`: `'solid'`, `'dashed'`, or `'active'` (dashed and moving; it stays still with reduced motion or `animateActive={false}`). |
53
+ | Lanes | `groups` are rects with an optional title, drawn behind the edges. |
54
+ | View | Drag empty space to pan. Two-finger and trackpad scrolls pan. The wheel and pinch zoom around the pointer. There are zoom-in, zoom-out and fit buttons (`controls`, `labels`). `view` + `onViewChange` make the view controlled, `defaultView` sets where it starts (default: fit). `minZoom` / `maxZoom` bound the zoom. `wheel: 'zoom' \| 'pan'` forces one wheel behaviour. |
55
+ | Drag | Nodes move on the main thread: no background render per frame, and the edges that touch moving nodes are redrawn there too. `snap` rounds to a grid. `onMove` reports live moves, `onMoveEnd` the final positions. A node with `draggable: false` stays put. |
56
+ | Selection | A tap selects. Shift or Ctrl/⌘ adds or removes. `selection` / `defaultSelection` / `onSelectionChange`. |
57
+ | Keys | After a press inside the canvas (`keyboard: 'auto'`; `'always'` / `'off'`): arrows move the focus to the nearest node that way (Shift adds it), Ctrl/⌘+arrows nudge the selection by the grid, Delete and Backspace call `onDelete`, Enter calls `onActivate`, Ctrl/⌘+A selects all, `+` / `-` / `0` zoom and fit, and Escape clears the selection, then leaves. |
58
+ | Menus | Right click, long press, the context-menu key and Shift+F10 call `onContextMenu` with the target (node, edge or canvas), the pointer in the LynxView's space (for `G9Menu` `anchorPoint`), the world point and the source. |
59
+ | Drops | A `G9DragSource` from `@g9tm/lynxcontrols/pointer` (a `G9VirtualList` row, for example) dragged over the canvas lights each node whose `acceptsDrop` takes the payload (`dropCandidate`), and the node under the pointer (`dropOver`). A drop calls `onDrop` with `{ nodeId, payload, world }`. |
60
+ | Culling | Only nodes, edges and groups inside the viewport, plus `cullMargin` of it on each side, are drawn. |
61
+ | Handle | `handleRef`: `fit`, `zoomIn`, `zoomOut`, `setView`, `centerOn(id)`, `getView`. |
62
+
63
+ The chrome follows the reading direction: in RTL, the zoom buttons move to the bottom left. The world itself does not
64
+ mirror, since an app's positions are absolute. Ids are safe: `#Routes`, a node's element `#Routes__n_<id>`, the
65
+ buttons `#Routes_ZoomIn`, `#Routes_ZoomOut`, `#Routes_Fit`.
66
+
67
+ ### Positions
68
+
69
+ The app owns positions. `onMoveEnd` reports them, and the app writes them back to `nodes`. To place a new graph,
70
+ `layeredLayout(nodes, edges, { direction, layerGap, nodeGap })` answers a top-left for every node. Sources come first,
71
+ and each node sits one layer past its deepest predecessor. Ordering sweeps reduce crossings, and cycles are broken at
72
+ the edge that closes them.
73
+
74
+ ### The core
75
+
76
+ The canvas uses the same core functions an app or a host can call:
77
+ - `toWorld` / `toScreen`, `zoomAt`, `panBy`, `fitView`, `visibleWorld`;
78
+ - `portPoint`, `edgeCurve`, `edgePathData`, `bezierPoint`, `edgeGeometry`, `cullGraph`, `contentBounds`;
79
+ - `snapTo`, `nodeAt`, `nextSelection`, `nodeInDirection`, `clampZoom`, `intersects`, `layeredLayout`.
80
+
81
+ ## Hosts
82
+
83
+ The canvas runs on Android, iOS, Lynxtron and Lynx for Web:
84
+ - Pointer and wheel come from the engine's mouse, wheel and touch events. A right press, the wheel and the
85
+ context-menu key need a desktop host (Lynxtron, Lynx for Web).
86
+ - Ctrl+click and Shift+click read the held modifiers (`g9HeldModifiers`). A desktop host's key events feed them:
87
+ `G9KeyCapture` on Lynxtron, `forwardG9Keys` from `@g9tm/lynxcontrols-web` on the web.
88
+ - What has not been seen in a real window yet is listed in `plan/execution/Native-Validation-Pending.md`.
89
+
90
+ ## Tests
91
+
92
+ `npx rstest run packages/graph`. The core has pure tests. The main-thread twins run inside a main-thread handler and
93
+ are compared with the core. The canvas tests send the engine's main-thread pointer events and check the background's
94
+ menus, keys, buttons and drops.
@@ -0,0 +1,17 @@
1
+ # G9GraphCanvas
2
+
3
+ `import { G9GraphCanvas } from '@g9tm/lynxcontrols-graph';`
4
+
5
+ A node graph editor: app-drawn cards at app-given positions, edges between their ports, lanes behind them.
6
+
7
+ Props:
8
+ - `nodes`: G9GraphNode[]
9
+ - `renderNode`: (node, state) => ReactNode
10
+ - `onActivate?`: (id: string) => void
11
+ - `onContextMenu?`: (event: G9GraphContextMenuEvent) => void
12
+ - `onDelete?`: (ids: string[]) => void
13
+ - `onDrop?`: (event: G9GraphDropEvent) => void
14
+ - `onEdgePress?`: (id: string) => void
15
+ - `onMove?`: (id: string, x: number, y: number) => void
16
+
17
+ Example: `<G9GraphCanvas nodes={nodes} renderNode={renderNode} />`