@glyphlab/diagram-react 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +28 -2
- package/diagram.css +892 -0
- package/index.d.ts +192 -0
- package/index.js +1727 -0
- package/index.js.map +1 -0
- package/package.json +46 -4
- package/theme.css +102 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Subtubes
|
|
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
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @glyphlab/diagram-react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The default React canvas for a `@glyphlab/diagram-core` controller: pan and zoom, nodes, groups and edges, drag and resize, connect by dragging, edit in place, colours, a right-click menu, and a read-only viewer. Peer dependencies: `react`, `zustand`, `@glyphlab/diagram-core`.
|
|
4
|
+
|
|
5
|
+
```tsx
|
|
6
|
+
import { createDiagramController } from '@glyphlab/diagram-core'
|
|
7
|
+
import { DiagramCanvas, DiagramProvider, createDiagramInstance } from '@glyphlab/diagram-react'
|
|
8
|
+
import '@glyphlab/diagram-react/theme.css' // default colours; skip it if the host defines the variables itself
|
|
9
|
+
import '@glyphlab/diagram-react/diagram.css'
|
|
10
|
+
|
|
11
|
+
const controller = createDiagramController()
|
|
12
|
+
const instance = createDiagramInstance(controller) // one per diagram on the page
|
|
13
|
+
|
|
14
|
+
<DiagramProvider instance={instance} slots={{ renderMarkdown }}>
|
|
15
|
+
<DiagramCanvas title="Orders" designKey="orders" empty={<strong>Nothing here yet</strong>} />
|
|
16
|
+
</DiagramProvider>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- **What a person does is a change to the diagram**: each drag, resize, connect, edit, colour choice and delete is one `controller.apply({ source: 'user' })`. A host sees them all in `controller.onChange`.
|
|
20
|
+
- **`DiagramInstance`** = a controller and the canvas state for it (view, selection, edit in progress, connect, highlights). When the diagram changes or another is loaded, the canvas lets go of what it can no longer show.
|
|
21
|
+
- **Slots**: `renderMarkdown(source)` draws a node's content (plain text without it).
|
|
22
|
+
Optional `openNodeContent(id, section?)` adds a keyboard-accessible expand icon to editable nodes and calls the host to show the
|
|
23
|
+
full content, without dragging the node or starting inline editing. The host owns its drawer and edit/save UI.
|
|
24
|
+
The `empty` prop is what the canvas says when there is nothing on it.
|
|
25
|
+
- **Hooks** for building around it: `useDiagram`, `useNodes`, `useEdges`, `useGroups`, `useMeta`, `useSelection`, `useViewport`, ... Each reads one slice of one store. `bindStore(api)` makes a global-style hook for code written that way.
|
|
26
|
+
- **`DiagramViewer`**: a diagram from a file with no controller: pan, zoom, highlights. For saved copies, previews, pages that only show.
|
|
27
|
+
- **Theme**: the canvas reads CSS variables only. `theme.css` lists them with light and dark values. Colour presets are `--c-red` ... `--c-gray`; a node's own `#rrggbb` is used as it is.
|
|
28
|
+
|
|
29
|
+
Known issues: [docs/known-issues.md](docs/known-issues.md).
|