@erd-studio/renderer 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 +167 -0
- package/README.md +132 -0
- package/dist/chunk-3PJCC7BX.js +5049 -0
- package/dist/chunk-6XQXDZ4R.js +0 -0
- package/dist/chunk-HOQPSLHQ.js +90 -0
- package/dist/chunk-QZGU5NZH.js +0 -0
- package/dist/chunk-WOTSQZCQ.js +151 -0
- package/dist/editor.js +124 -0
- package/dist/index.js +16 -0
- package/dist/sizing.js +16 -0
- package/dist/store.js +15 -0
- package/dist/styles.css +2963 -0
- package/dist/types/ErdCanvas.d.ts +54 -0
- package/dist/types/canvas/CanvasBackdrop.d.ts +7 -0
- package/dist/types/canvas/flowTypes.d.ts +10 -0
- package/dist/types/canvas/useCanvasGraph.d.ts +37 -0
- package/dist/types/components/DetailPanel/BulkColumnActions.d.ts +15 -0
- package/dist/types/components/DetailPanel/ColumnEditor.d.ts +19 -0
- package/dist/types/components/DetailPanel/DescriptionEditor.d.ts +16 -0
- package/dist/types/components/DetailPanel/DetailPanel.d.ts +10 -0
- package/dist/types/components/DetailPanel/GrainEditor.d.ts +16 -0
- package/dist/types/components/DetailPanel/ModelRationale.d.ts +27 -0
- package/dist/types/components/DetailPanel/RationaleField.d.ts +28 -0
- package/dist/types/components/DetailPanel/RoleEditor.d.ts +13 -0
- package/dist/types/components/Graph/AnnotationEdge.d.ts +11 -0
- package/dist/types/components/Graph/AnnotationNode.d.ts +18 -0
- package/dist/types/components/Graph/ColumnTooltip.d.ts +25 -0
- package/dist/types/components/Graph/FkEdge.d.ts +21 -0
- package/dist/types/components/Graph/HoverTip.d.ts +47 -0
- package/dist/types/components/Graph/ModelNode.d.ts +21 -0
- package/dist/types/components/Legend/Legend.d.ts +11 -0
- package/dist/types/components/common/ColumnRowEditor.d.ts +75 -0
- package/dist/types/components/common/DataTypeSelect.d.ts +20 -0
- package/dist/types/components/common/KeyBadge.d.ts +16 -0
- package/dist/types/components/common/KeyBadgeGroup.d.ts +20 -0
- package/dist/types/editor.d.ts +27 -0
- package/dist/types/hooks/useColumnExpansion.d.ts +36 -0
- package/dist/types/hooks/useColumnReorder.d.ts +36 -0
- package/dist/types/hooks/useFocusWithinRow.d.ts +23 -0
- package/dist/types/hooks/useLongPressDrag.d.ts +31 -0
- package/dist/types/host/canvasEnvironment.d.ts +36 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/lib/annotationColors.d.ts +13 -0
- package/dist/types/lib/badgeLabels.d.ts +63 -0
- package/dist/types/lib/cardinalityUtils.d.ts +14 -0
- package/dist/types/lib/dataTypeColors.d.ts +15 -0
- package/dist/types/lib/dragHandleSides.d.ts +27 -0
- package/dist/types/lib/edgeDistribution.d.ts +165 -0
- package/dist/types/lib/graphTransformer.d.ts +65 -0
- package/dist/types/lib/nodeOverlays.d.ts +41 -0
- package/dist/types/lib/nodeSizing.d.ts +50 -0
- package/dist/types/lib/stageColors.d.ts +16 -0
- package/dist/types/sizing.d.ts +1 -0
- package/dist/types/store/editorStore.d.ts +185 -0
- package/dist/types/store.d.ts +2 -0
- package/dist/types/types/graph.d.ts +145 -0
- package/package.json +72 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
Required Notice: Copyright Liam Wynne (https://github.com/liam-machine)
|
|
2
|
+
Licensor Line of Business: ERD Studio, a visual ERD designer for dbt (https://github.com/liam-machine/erd-studio)
|
|
3
|
+
|
|
4
|
+
# PolyForm Shield License 1.0.0
|
|
5
|
+
|
|
6
|
+
<https://polyformproject.org/licenses/shield/1.0.0>
|
|
7
|
+
|
|
8
|
+
## Acceptance
|
|
9
|
+
|
|
10
|
+
In order to get any license under these terms, you must agree
|
|
11
|
+
to them as both strict obligations and conditions to all
|
|
12
|
+
your licenses.
|
|
13
|
+
|
|
14
|
+
## Copyright License
|
|
15
|
+
|
|
16
|
+
The licensor grants you a copyright license for the
|
|
17
|
+
software to do everything you might do with the software
|
|
18
|
+
that would otherwise infringe the licensor's copyright
|
|
19
|
+
in it for any permitted purpose. However, you may
|
|
20
|
+
only distribute the software according to [Distribution
|
|
21
|
+
License](#distribution-license) and make changes or new works
|
|
22
|
+
based on the software according to [Changes and New Works
|
|
23
|
+
License](#changes-and-new-works-license).
|
|
24
|
+
|
|
25
|
+
## Distribution License
|
|
26
|
+
|
|
27
|
+
The licensor grants you an additional copyright license
|
|
28
|
+
to distribute copies of the software. Your license
|
|
29
|
+
to distribute covers distributing the software with
|
|
30
|
+
changes and new works permitted by [Changes and New Works
|
|
31
|
+
License](#changes-and-new-works-license).
|
|
32
|
+
|
|
33
|
+
## Notices
|
|
34
|
+
|
|
35
|
+
You must ensure that anyone who gets a copy of any part of
|
|
36
|
+
the software from you also gets a copy of these terms or the
|
|
37
|
+
URL for them above, as well as copies of any plain-text lines
|
|
38
|
+
beginning with `Required Notice:` that the licensor provided
|
|
39
|
+
with the software. For example:
|
|
40
|
+
|
|
41
|
+
> Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
|
|
42
|
+
|
|
43
|
+
## Changes and New Works License
|
|
44
|
+
|
|
45
|
+
The licensor grants you an additional copyright license to
|
|
46
|
+
make changes and new works based on the software for any
|
|
47
|
+
permitted purpose.
|
|
48
|
+
|
|
49
|
+
## Patent License
|
|
50
|
+
|
|
51
|
+
The licensor grants you a patent license for the software that
|
|
52
|
+
covers patent claims the licensor can license, or becomes able
|
|
53
|
+
to license, that you would infringe by using the software.
|
|
54
|
+
|
|
55
|
+
## Noncompete
|
|
56
|
+
|
|
57
|
+
Any purpose is a permitted purpose, except for providing any
|
|
58
|
+
product that competes with the software or any product the
|
|
59
|
+
licensor or any of its affiliates provides using the software.
|
|
60
|
+
|
|
61
|
+
## Competition
|
|
62
|
+
|
|
63
|
+
Goods and services compete even when they provide functionality
|
|
64
|
+
through different kinds of interfaces or for different technical
|
|
65
|
+
platforms. Applications can compete with services, libraries
|
|
66
|
+
with plugins, frameworks with development tools, and so on,
|
|
67
|
+
even if they're written in different programming languages
|
|
68
|
+
or for different computer architectures. Goods and services
|
|
69
|
+
compete even when provided free of charge. If you market a
|
|
70
|
+
product as a practical substitute for the software or another
|
|
71
|
+
product, it definitely competes.
|
|
72
|
+
|
|
73
|
+
## New Products
|
|
74
|
+
|
|
75
|
+
If you are using the software to provide a product that does
|
|
76
|
+
not compete, but the licensor or any of its affiliates brings
|
|
77
|
+
your product into competition by providing a new version of
|
|
78
|
+
the software or another product using the software, you may
|
|
79
|
+
continue using versions of the software available under these
|
|
80
|
+
terms beforehand to provide your competing product, but not
|
|
81
|
+
any later versions.
|
|
82
|
+
|
|
83
|
+
## Discontinued Products
|
|
84
|
+
|
|
85
|
+
You may begin using the software to compete with a product
|
|
86
|
+
or service that the licensor or any of its affiliates has
|
|
87
|
+
stopped providing, unless the licensor includes a plain-text
|
|
88
|
+
line beginning with `Licensor Line of Business:` with the
|
|
89
|
+
software that mentions that line of business. For example:
|
|
90
|
+
|
|
91
|
+
> Licensor Line of Business: YoyodyneCMS Content Management
|
|
92
|
+
System (http://example.com/cms)
|
|
93
|
+
|
|
94
|
+
## Sales of Business
|
|
95
|
+
|
|
96
|
+
If the licensor or any of its affiliates sells a line of
|
|
97
|
+
business developing the software or using the software
|
|
98
|
+
to provide a product, the buyer can also enforce
|
|
99
|
+
[Noncompete](#noncompete) for that product.
|
|
100
|
+
|
|
101
|
+
## Fair Use
|
|
102
|
+
|
|
103
|
+
You may have "fair use" rights for the software under the
|
|
104
|
+
law. These terms do not limit them.
|
|
105
|
+
|
|
106
|
+
## No Other Rights
|
|
107
|
+
|
|
108
|
+
These terms do not allow you to sublicense or transfer any of
|
|
109
|
+
your licenses to anyone else, or prevent the licensor from
|
|
110
|
+
granting licenses to anyone else. These terms do not imply
|
|
111
|
+
any other licenses.
|
|
112
|
+
|
|
113
|
+
## Patent Defense
|
|
114
|
+
|
|
115
|
+
If you make any written claim that the software infringes or
|
|
116
|
+
contributes to infringement of any patent, your patent license
|
|
117
|
+
for the software granted under these terms ends immediately. If
|
|
118
|
+
your company makes such a claim, your patent license ends
|
|
119
|
+
immediately for work on behalf of your company.
|
|
120
|
+
|
|
121
|
+
## Violations
|
|
122
|
+
|
|
123
|
+
The first time you are notified in writing that you have
|
|
124
|
+
violated any of these terms, or done anything with the software
|
|
125
|
+
not covered by your licenses, your licenses can nonetheless
|
|
126
|
+
continue if you come into full compliance with these terms,
|
|
127
|
+
and take practical steps to correct past violations, within
|
|
128
|
+
32 days of receiving notice. Otherwise, all your licenses
|
|
129
|
+
end immediately.
|
|
130
|
+
|
|
131
|
+
## No Liability
|
|
132
|
+
|
|
133
|
+
***As far as the law allows, the software comes as is, without
|
|
134
|
+
any warranty or condition, and the licensor will not be liable
|
|
135
|
+
to you for any damages arising out of these terms or the use
|
|
136
|
+
or nature of the software, under any kind of legal claim.***
|
|
137
|
+
|
|
138
|
+
## Definitions
|
|
139
|
+
|
|
140
|
+
The **licensor** is the individual or entity offering these
|
|
141
|
+
terms, and the **software** is the software the licensor makes
|
|
142
|
+
available under these terms.
|
|
143
|
+
|
|
144
|
+
A **product** can be a good or service, or a combination
|
|
145
|
+
of them.
|
|
146
|
+
|
|
147
|
+
**You** refers to the individual or entity agreeing to these
|
|
148
|
+
terms.
|
|
149
|
+
|
|
150
|
+
**Your company** is any legal entity, sole proprietorship,
|
|
151
|
+
or other kind of organization that you work for, plus all
|
|
152
|
+
its affiliates.
|
|
153
|
+
|
|
154
|
+
**Affiliates** means the other organizations than an
|
|
155
|
+
organization has control over, is under the control of, or is
|
|
156
|
+
under common control with.
|
|
157
|
+
|
|
158
|
+
**Control** means ownership of substantially all the assets of
|
|
159
|
+
an entity, or the power to direct its management and policies
|
|
160
|
+
by vote, contract, or otherwise. Control can be direct or
|
|
161
|
+
indirect.
|
|
162
|
+
|
|
163
|
+
**Your licenses** are all the licenses granted to you for the
|
|
164
|
+
software under these terms.
|
|
165
|
+
|
|
166
|
+
**Use** means anything you do with the software requiring one
|
|
167
|
+
of your licenses.
|
package/README.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# @erd-studio/renderer
|
|
2
|
+
|
|
3
|
+
The entity-relationship diagram canvas from the [ERD Studio](https://github.com/liam-machine/erd-studio) VS Code extension, packaged for reuse. It is built on React Flow and renders a `DisplayDomain` from `@erd-studio/core`: model nodes with their columns and key badges, FK edges with cardinality, annotations, the detail panel and the legend.
|
|
4
|
+
|
|
5
|
+
Peer dependencies: `react` and `react-dom` 18.3+, `@xyflow/react` 12.4+.
|
|
6
|
+
|
|
7
|
+
## Entry points
|
|
8
|
+
|
|
9
|
+
| Import | What it is for |
|
|
10
|
+
|---|---|
|
|
11
|
+
| `@erd-studio/renderer` | Showing a domain: the `ErdCanvas` viewer component (below), plus `transformDomain` (a `DisplayDomain` to React Flow nodes and edges), `pickHandleSides`, `repickHandleSides` / `nodeRect`, and the display, domain and graph types (`DisplayDomain`, `ModelFlowNode`, `FkFlowEdge`, …). |
|
|
12
|
+
| `@erd-studio/renderer/editor` | Everything above plus what a host needs to build a full editor around the canvas, as the extension's webview does: the store (below), the host adapter, `useCanvasGraph`, `CanvasBackdrop`, `canvasNodeTypes` / `canvasEdgeTypes`, the components (`ModelNode`, `FkEdge`, `AnnotationNode`, `AnnotationEdge`, `DetailPanel`, `Legend`, `KeyBadge`, `KeyBadgeGroup`, `DataTypeSelect`, `ColumnRowEditor`), the canvas hooks and the pure helpers. |
|
|
13
|
+
| `@erd-studio/renderer/store` | The canvas store on its own, with no React Flow runtime: `createCanvasSlice`, `createCanvasStore`, `CanvasStoreProvider`, `useEditorStore`, `useEditorStoreApi` and their types. |
|
|
14
|
+
| `@erd-studio/renderer/sizing` | Model node size estimation (`NODE_WIDTH`, `estimateNodeWidth`, `estimateNodeHeight`, `countVisibleColumnRows`, `resolveNodeDimensions`), for layout code that needs node sizes before React Flow has measured them. No components. |
|
|
15
|
+
| `@erd-studio/renderer/styles.css` | The stylesheet: every component's CSS in cascade order, then the theme tokens. It `@import`s `@xyflow/react/dist/style.css`, which your bundler resolves. |
|
|
16
|
+
|
|
17
|
+
All four JavaScript entry points share their modules, so a store or context created through one is the same one the others see.
|
|
18
|
+
|
|
19
|
+
## Viewer: `ErdCanvas`
|
|
20
|
+
|
|
21
|
+
`ErdCanvas` renders a `DisplayDomain` read-only, the way the extension shows a read-only domain: model nodes with their columns and key badges, FK edges, annotations, the minimap, the legend, and the detail panel a click on a model opens. It presents no editing affordances and posts nothing anywhere.
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import { useRef, useState } from 'react';
|
|
25
|
+
import { ErdCanvas, type ErdCanvasHandle, type DisplayDomain } from '@erd-studio/renderer';
|
|
26
|
+
import '@erd-studio/renderer/styles.css';
|
|
27
|
+
|
|
28
|
+
function Diagram({ domain }: { domain: DisplayDomain }) {
|
|
29
|
+
const canvas = useRef<ErdCanvasHandle>(null);
|
|
30
|
+
const [moved, setMoved] = useState(false);
|
|
31
|
+
return (
|
|
32
|
+
<div style={{ height: 600, position: 'relative' }}>
|
|
33
|
+
<ErdCanvas ref={canvas} domain={domain} nodesDraggable onLayoutModifiedChange={setMoved} />
|
|
34
|
+
{moved && <button onClick={() => canvas.current?.resetLayout()}>Reset layout</button>}
|
|
35
|
+
</div>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
| Prop | |
|
|
41
|
+
|---|---|
|
|
42
|
+
| `domain` | The domain to show. It is rendered read-only whatever its `readOnly` flag says. Missing `layer`, `stage`, `relationships`, `viewConfig`, model `columns` and column `dataType` are filled with defaults. Pass a new object to show a new domain; re-rendering with the same object keeps the reader's view. |
|
|
43
|
+
| `nodesDraggable` | Let readers move model and annotation nodes (default `false`). Moves are never saved; the edges on a moved node re-pick their sides as it moves. |
|
|
44
|
+
| `onLayoutModifiedChange(modified)` | Called when the layout starts or stops differing from the domain's positions (a node moved; `resetLayout()`, a new domain, or a node moved back). |
|
|
45
|
+
| `onReady()` | Called once, after the first nodes are measured and fitted into view (straight away for an empty domain). |
|
|
46
|
+
| `className`, `style` | Applied to the canvas's wrapper element, which fills its parent. |
|
|
47
|
+
|
|
48
|
+
The ref exposes `resetLayout()`, which puts every node back at its position in the domain with its original edge sides.
|
|
49
|
+
|
|
50
|
+
Each `ErdCanvas` has its own store, so several can share a page.
|
|
51
|
+
|
|
52
|
+
## Editor: store and host
|
|
53
|
+
|
|
54
|
+
The canvas components read their state from the store supplied by the nearest `CanvasStoreProvider`, and post the edits a user makes on the canvas (renaming a column, moving an annotation, changing a cardinality, …) as `CanvasEditMessage`s to the `CanvasHost` supplied by `CanvasEnvironmentProvider`.
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import { ReactFlowProvider } from '@xyflow/react';
|
|
58
|
+
import {
|
|
59
|
+
createCanvasStore,
|
|
60
|
+
CanvasStoreProvider,
|
|
61
|
+
CanvasEnvironmentProvider,
|
|
62
|
+
type CanvasHost,
|
|
63
|
+
} from '@erd-studio/renderer/editor';
|
|
64
|
+
import '@erd-studio/renderer/styles.css';
|
|
65
|
+
|
|
66
|
+
const store = createCanvasStore({ domain });
|
|
67
|
+
const host: CanvasHost = { postMessage: (edit) => applyEdit(edit) };
|
|
68
|
+
|
|
69
|
+
<CanvasStoreProvider store={store}>
|
|
70
|
+
<CanvasEnvironmentProvider host={host}>
|
|
71
|
+
<ReactFlowProvider>{/* <ReactFlow nodeTypes={canvasNodeTypes} … /> */}</ReactFlowProvider>
|
|
72
|
+
</CanvasEnvironmentProvider>
|
|
73
|
+
</CanvasStoreProvider>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
- Without a `CanvasEnvironmentProvider`, edits go to a no-op host.
|
|
77
|
+
- `CanvasEnvironmentProvider`'s `viewer` flag switches the components to the read-only presentation `ErdCanvas` uses. It is separate from a domain's `readOnly` flag, which the extension sets for the physical stage and which still offers menus such as the key-type picker.
|
|
78
|
+
- A host with more state of its own can build its store from `createCanvasSlice(set)` and pass that to `CanvasStoreProvider`, which is what the extension does.
|
|
79
|
+
- Components used outside a `CanvasStoreProvider` throw.
|
|
80
|
+
|
|
81
|
+
## CSS variables
|
|
82
|
+
|
|
83
|
+
The styles are written against VS Code's theme variables. A page that is not a VS Code webview must define these 31 on `:root` (or any ancestor of the canvas). Most have fallbacks, but the canvas only matches your theme when they are set.
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
--vscode-button-background --vscode-font-family
|
|
87
|
+
--vscode-button-foreground --vscode-font-size
|
|
88
|
+
--vscode-button-hoverBackground --vscode-font-weight
|
|
89
|
+
--vscode-charts-green --vscode-input-background
|
|
90
|
+
--vscode-charts-purple --vscode-input-border
|
|
91
|
+
--vscode-descriptionForeground --vscode-input-foreground
|
|
92
|
+
--vscode-editor-background --vscode-list-activeSelectionBackground
|
|
93
|
+
--vscode-editor-font-family --vscode-list-activeSelectionForeground
|
|
94
|
+
--vscode-editor-foreground --vscode-panel-border
|
|
95
|
+
--vscode-editor-inactiveSelectionBackground --vscode-sideBar-background
|
|
96
|
+
--vscode-editor-selectionBackground --vscode-textLink-activeForeground
|
|
97
|
+
--vscode-editorGroup-border --vscode-textLink-foreground
|
|
98
|
+
--vscode-editorHoverWidget-background
|
|
99
|
+
--vscode-editorHoverWidget-border
|
|
100
|
+
--vscode-editorHoverWidget-foreground
|
|
101
|
+
--vscode-editorWarning-foreground
|
|
102
|
+
--vscode-editorWidget-background
|
|
103
|
+
--vscode-errorForeground
|
|
104
|
+
--vscode-focusBorder
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
These four more are read only by the data-type picker, which appears only while editing a column (never in `ErdCanvas`):
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
--vscode-dropdown-background --vscode-dropdown-border
|
|
111
|
+
--vscode-dropdown-foreground --vscode-list-hoverBackground
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Dark-theme variants of a few annotation and legend colours key off `body[data-vscode-theme-kind="vscode-dark"]` (and `vscode-high-contrast`).
|
|
115
|
+
|
|
116
|
+
The stylesheet does not size the page. Give the element the canvas is mounted in an explicit height.
|
|
117
|
+
|
|
118
|
+
## Development
|
|
119
|
+
|
|
120
|
+
This package lives in the `packages/renderer` workspace of the ERD Studio repository. Inside the repository it is consumed from source (TypeScript `paths` and vitest aliases); the published package ships only `dist/`.
|
|
121
|
+
|
|
122
|
+
```sh
|
|
123
|
+
npm run build -w @erd-studio/renderer # dist/*.js (esbuild, ESM), dist/styles.css, dist/types/*.d.ts
|
|
124
|
+
npm run typecheck -w @erd-studio/renderer
|
|
125
|
+
npm test -w @erd-studio/renderer
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
The sources import each other without file extensions, as bundlers expect. The build's last step (`scripts/dts-extensions.mjs`) adds `.js` to the relative imports in the emitted declarations, so the types also work for consumers on `moduleResolution: node16` or `nodenext`.
|
|
129
|
+
|
|
130
|
+
## License
|
|
131
|
+
|
|
132
|
+
[PolyForm Shield 1.0.0](./LICENSE), the same licence as the rest of the repository.
|