@ship-it-ui/graph-editor 0.0.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/LICENSE +21 -0
- package/README.md +71 -0
- package/dist/index.cjs +874 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +225 -0
- package/dist/index.d.ts +225 -0
- package/dist/index.js +856 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +49 -0
- package/dist/styles.css.map +1 -0
- package/package.json +88 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ship-it-ops
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# @ship-it-ui/graph-editor
|
|
2
|
+
|
|
3
|
+
`<GraphEditorCanvas>` — the editing analog of `<GraphCanvas>` (from `@ship-it-ui/cytoscape`). React Flow under the hood; same `elements[]` shape on the input so consumers can swap viewer ↔ editor without reshaping data.
|
|
4
|
+
|
|
5
|
+
## How this fits in
|
|
6
|
+
|
|
7
|
+
Part of the [Ship-It Design System](../../docs/architecture.md). Sibling to `@ship-it-ui/cytoscape` (read-only graph viewer). Both packages consume `@ship-it-ui/graph-tokens` for theme-token resolution; neither imports the other at runtime — tree-shaking is enforced by package boundary.
|
|
8
|
+
|
|
9
|
+
## Install + import the stylesheet
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @ship-it-ui/graph-editor
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Then **once** at your app entry (`app/layout.tsx` for Next.js, `main.tsx` for Vite, etc.):
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import '@ship-it-ui/graph-editor/styles.css';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The component intentionally does not import its own CSS. Next.js's App Router rejects library-internal global CSS, and explicit consumer imports let you control load order against your own theme. The stylesheet pulls in `@xyflow/react/dist/style.css` and layers Ship-It overrides on top.
|
|
22
|
+
|
|
23
|
+
## Quick start
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
'use client';
|
|
27
|
+
|
|
28
|
+
import '@ship-it-ui/graph-editor/styles.css';
|
|
29
|
+
|
|
30
|
+
import { GraphEditorCanvas, type GraphElement } from '@ship-it-ui/graph-editor';
|
|
31
|
+
import { useState } from 'react';
|
|
32
|
+
|
|
33
|
+
const INITIAL: GraphElement[] = [
|
|
34
|
+
{ data: { id: 'a', label: 'Alpha', entityType: 'service' }, position: { x: 0, y: 0 } },
|
|
35
|
+
{ data: { id: 'b', label: 'Beta', entityType: 'service' }, position: { x: 200, y: 0 } },
|
|
36
|
+
{ data: { id: 'e-ab', source: 'a', target: 'b' } },
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
export default function Editor() {
|
|
40
|
+
const [elements, setElements] = useState(INITIAL);
|
|
41
|
+
return (
|
|
42
|
+
<div style={{ width: '100%', height: 480 }}>
|
|
43
|
+
<GraphEditorCanvas
|
|
44
|
+
elements={elements}
|
|
45
|
+
onConnect={({ id, source, target }) =>
|
|
46
|
+
setElements((prev) => [...prev, { data: { id, source, target } }])
|
|
47
|
+
}
|
|
48
|
+
onNodeMove={(id, position) =>
|
|
49
|
+
setElements((prev) => prev.map((el) => (el.data.id === id ? { ...el, position } : el)))
|
|
50
|
+
}
|
|
51
|
+
/>
|
|
52
|
+
</div>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
See the [docs site](https://ship-it-ops.github.io/ship-it-design/graph/editor) for the full API and live examples (toolbar slot, custom-node renderer, keyboard, undo/redo).
|
|
58
|
+
|
|
59
|
+
## Built-in behaviors
|
|
60
|
+
|
|
61
|
+
- Pan + zoom + mini-map (wraps `@ship-it-ui/shipit`'s `<GraphMinimap>` so the editor looks identical to the viewer).
|
|
62
|
+
- Click-to-select; pane-click to clear.
|
|
63
|
+
- Drag-to-connect; drag-to-move (`onNodeMove`).
|
|
64
|
+
- `Delete` / `Backspace` removes selection; arrow keys nudge (Shift = 32px); `Escape` clears; `⌘Z` / `⌘⇧Z` undo / redo.
|
|
65
|
+
- Theme-token sync via `@ship-it-ui/graph-tokens`.
|
|
66
|
+
- Built-in keyboard-accessible "+ Add" button when no `toolbar` is supplied.
|
|
67
|
+
- `role="application"` on the canvas root.
|
|
68
|
+
|
|
69
|
+
## Engine
|
|
70
|
+
|
|
71
|
+
React Flow (`@xyflow/react@^12`). The viewer (`<GraphCanvas>`) uses Cytoscape.js — same `elements[]` shape passes through via the round-trip-tested adapter (`toFlowElements` / `toCytoscapeElements`).
|