@signalsafe/tree-spec-editor-react 0.2.1 → 0.2.5
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 +13 -1
- package/dist/canvas/edgeStyle.d.ts +1 -1
- package/dist/nodes/PromptNode.js +1 -1
- package/docs/UI_KIT_AGNOSTIC_CANVAS.md +4 -0
- package/docs/demo/editor-demo.css +298 -0
- package/docs/demo/generate-doc-images.mjs +161 -0
- package/docs/demo/index.html +12 -0
- package/docs/demo/main.jsx +42 -0
- package/docs/demo/treeSpecExample.mjs +85 -0
- package/docs/tree-spec-example-flow.svg +714 -0
- package/package.json +13 -9
package/README.md
CHANGED
|
@@ -101,6 +101,18 @@ For full authoring flows (load/save/validate), compose **`useTreeSpecEditor`** w
|
|
|
101
101
|
|
|
102
102
|
Import from `@signalsafe/tree-spec-editor-react` only (no subpath exports).
|
|
103
103
|
|
|
104
|
+
## Documentation preview
|
|
105
|
+
|
|
106
|
+
The graph image below is generated from the live example data with the built
|
|
107
|
+
`TreeSpecGraphEditor` component. The browser-backed generator captures the
|
|
108
|
+
same React Flow canvas that this package exports, including the editor's
|
|
109
|
+
virtual `END` node.
|
|
110
|
+
|
|
111
|
+

|
|
112
|
+
|
|
113
|
+
Run `yarn docs:images` to regenerate the image locally. CI runs
|
|
114
|
+
`yarn docs:check` with Chromium to keep the committed asset in sync.
|
|
115
|
+
|
|
104
116
|
## Package boundaries
|
|
105
117
|
|
|
106
118
|
| Layer | Package |
|
|
@@ -122,7 +134,7 @@ Pass `contextualZoom={false}` to disable automatic viewport fitting.
|
|
|
122
134
|
|
|
123
135
|
## Development
|
|
124
136
|
|
|
125
|
-
Requires Node.js **>=22.12.0** (`engines.node`). CI runs checks, tests, and smoke on Node **22** and **24**; publish uses Node **24**.
|
|
137
|
+
Requires Node.js **>=22.12.0** (`engines.node`). CI runs checks, tests, and smoke on Node **22** and **24**; publish uses Node **24**. Node 20 is no longer supported (GitHub Actions Node 20 deprecation).
|
|
126
138
|
|
|
127
139
|
`yarn build` uses `tsconfig.build.json` and resolves `@signalsafe/*` from `node_modules`. Ecosystem sibling `paths` in `tsconfig.json` apply to local typecheck/tests only.
|
|
128
140
|
|
|
@@ -3,10 +3,10 @@ export declare function getPromptNodeBorderClass(hasErrors: boolean, warningCoun
|
|
|
3
3
|
export declare function getIssueEdgeStyle(style: Edge['style'], hasIssue: boolean): Edge['style'];
|
|
4
4
|
export declare function resolveEdgePathStroke(style: Edge['style'] | undefined): string;
|
|
5
5
|
export declare function buildEdgeMarker(stroke: string): {
|
|
6
|
-
color: string;
|
|
7
6
|
type: import("reactflow").MarkerType;
|
|
8
7
|
width: number;
|
|
9
8
|
height: number;
|
|
9
|
+
color: string;
|
|
10
10
|
};
|
|
11
11
|
export declare function buildEdgeStyle(strokeColor: string | undefined): Edge['style'];
|
|
12
12
|
export declare function resolveSelectedEdgeStroke(style: Edge['style'], isEdgeSelected: boolean): {
|
package/dist/nodes/PromptNode.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useEffect } from 'react';
|
|
3
3
|
import { Handle, NodeResizer, Position, useUpdateNodeInternals } from 'reactflow';
|
|
4
4
|
import { editorHintsToStyle, getEditorHints, nodeTextWrapClassName, resolveNodeTextWrap, } from '@signalsafe/tree-spec-editor-core';
|
|
@@ -43,6 +43,10 @@ Text wrap helpers from `@signalsafe/tree-spec-editor-core` already use `graph-ed
|
|
|
43
43
|
|
|
44
44
|
This package ships **no CSS file** and does **not** import React Flow styles from built JavaScript. Host apps load `reactflow/dist/style.css` from their own entrypoint when default React Flow chrome is desired.
|
|
45
45
|
|
|
46
|
+
The package documentation includes a live preview generated by the exported
|
|
47
|
+
`TreeSpecGraphEditor`; see [tree-spec-example-flow.svg](./tree-spec-example-flow.svg).
|
|
48
|
+
The source data and browser-backed generator are in [`demo/`](./demo/).
|
|
49
|
+
|
|
46
50
|
---
|
|
47
51
|
|
|
48
52
|
## Migration from 0.1.x
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--graph-editor-bg: #ffffff;
|
|
3
|
+
--graph-editor-text: #212529;
|
|
4
|
+
--graph-editor-muted: #6c757d;
|
|
5
|
+
--graph-editor-panel-bg: #f8f9fa;
|
|
6
|
+
--graph-editor-border: #dee2e6;
|
|
7
|
+
--graph-editor-border-subtle: #e9ecef;
|
|
8
|
+
--graph-editor-accent: #0d6efd;
|
|
9
|
+
--graph-editor-danger: #dc3545;
|
|
10
|
+
--graph-editor-success: #198754;
|
|
11
|
+
--graph-editor-radius: 0.375rem;
|
|
12
|
+
--graph-editor-border-width: 1px;
|
|
13
|
+
--graph-editor-node-border-width: 4px;
|
|
14
|
+
--bs-primary-bg-subtle: #cfe2ff;
|
|
15
|
+
--bs-warning: #ffc107;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
* {
|
|
19
|
+
box-sizing: border-box;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
html,
|
|
23
|
+
body,
|
|
24
|
+
#root {
|
|
25
|
+
width: 1400px;
|
|
26
|
+
height: 840px;
|
|
27
|
+
margin: 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
body {
|
|
31
|
+
background: #eef1f5;
|
|
32
|
+
color: var(--graph-editor-text);
|
|
33
|
+
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
34
|
+
font-size: 16px;
|
|
35
|
+
line-height: 1.5;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.docs-preview {
|
|
39
|
+
display: flex;
|
|
40
|
+
width: 1400px;
|
|
41
|
+
height: 840px;
|
|
42
|
+
flex-direction: column;
|
|
43
|
+
gap: 12px;
|
|
44
|
+
padding: 34px 38px 38px;
|
|
45
|
+
background: linear-gradient(135deg, #f7f9fc 0%, #edf1f6 100%);
|
|
46
|
+
color: var(--graph-editor-text);
|
|
47
|
+
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
48
|
+
font-size: 16px;
|
|
49
|
+
line-height: 1.5;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.docs-preview__header {
|
|
53
|
+
display: flex;
|
|
54
|
+
align-items: flex-start;
|
|
55
|
+
justify-content: space-between;
|
|
56
|
+
gap: 24px;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.docs-preview__eyebrow {
|
|
60
|
+
color: #0d6efd;
|
|
61
|
+
font-size: 12px;
|
|
62
|
+
font-weight: 700;
|
|
63
|
+
letter-spacing: 0.09em;
|
|
64
|
+
text-transform: uppercase;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.docs-preview h1 {
|
|
68
|
+
margin: 2px 0 0;
|
|
69
|
+
font-size: 27px;
|
|
70
|
+
line-height: 1.2;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.docs-preview__status {
|
|
74
|
+
border: 1px solid #b8d4fe;
|
|
75
|
+
border-radius: 999px;
|
|
76
|
+
color: #0a58ca;
|
|
77
|
+
background: #e7f1ff;
|
|
78
|
+
font-size: 13px;
|
|
79
|
+
font-weight: 600;
|
|
80
|
+
padding: 7px 12px;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.docs-preview__description {
|
|
84
|
+
margin: 0;
|
|
85
|
+
color: #536273;
|
|
86
|
+
font-size: 14px;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.docs-preview code {
|
|
90
|
+
border-radius: 4px;
|
|
91
|
+
color: #495057;
|
|
92
|
+
background: #e9ecef;
|
|
93
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
|
94
|
+
font-size: 0.92em;
|
|
95
|
+
padding: 2px 5px;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.docs-preview__canvas {
|
|
99
|
+
min-height: 0;
|
|
100
|
+
flex: 1 1 auto;
|
|
101
|
+
overflow: hidden;
|
|
102
|
+
border: 1px solid #d6dde6;
|
|
103
|
+
border-radius: 10px;
|
|
104
|
+
background: #ffffff;
|
|
105
|
+
box-shadow: 0 9px 28px rgb(32 51 74 / 10%);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.docs-preview .graph-editor-canvas-root,
|
|
109
|
+
.docs-preview .graph-editor-canvas {
|
|
110
|
+
width: 100%;
|
|
111
|
+
height: 100%;
|
|
112
|
+
min-height: 0;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.docs-preview .graph-editor-canvas {
|
|
116
|
+
color: var(--graph-editor-text);
|
|
117
|
+
font-family: inherit;
|
|
118
|
+
font-size: 16px;
|
|
119
|
+
line-height: 1.5;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.docs-preview .graph-editor-card {
|
|
123
|
+
border: var(--graph-editor-border-width) solid var(--graph-editor-border);
|
|
124
|
+
border-radius: var(--graph-editor-radius);
|
|
125
|
+
background: var(--graph-editor-bg);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.docs-preview .graph-editor-card__header {
|
|
129
|
+
padding: 8px 12px;
|
|
130
|
+
border-bottom: var(--graph-editor-border-width) solid var(--graph-editor-border);
|
|
131
|
+
background: var(--graph-editor-panel-bg);
|
|
132
|
+
font-weight: 600;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.docs-preview .graph-editor-card__body {
|
|
136
|
+
padding: 12px;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.docs-preview .graph-editor-canvas-node {
|
|
140
|
+
min-width: 0;
|
|
141
|
+
overflow: visible;
|
|
142
|
+
border-radius: var(--graph-editor-radius);
|
|
143
|
+
border-style: solid;
|
|
144
|
+
border-width: var(--graph-editor-node-border-width);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.docs-preview .graph-editor-canvas-node--end-width {
|
|
148
|
+
width: 180px;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.docs-preview .graph-editor-canvas-node-body {
|
|
152
|
+
min-width: 0;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.docs-preview .graph-editor-canvas-node .graph-editor-card__body {
|
|
156
|
+
min-width: 0;
|
|
157
|
+
background: transparent;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.docs-preview .graph-editor-canvas-node .graph-editor-list__item {
|
|
161
|
+
width: 100%;
|
|
162
|
+
padding: 5px 8px;
|
|
163
|
+
border-top: 1px solid var(--graph-editor-border-subtle);
|
|
164
|
+
background: transparent;
|
|
165
|
+
color: inherit;
|
|
166
|
+
font: inherit;
|
|
167
|
+
text-align: start;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.docs-preview .graph-editor-canvas-node .graph-editor-list__item:first-child {
|
|
171
|
+
border-top: 0;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
.docs-preview .graph-editor-list--flush {
|
|
175
|
+
margin: 0;
|
|
176
|
+
padding: 0;
|
|
177
|
+
list-style: none;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
.docs-preview .graph-editor-canvas .react-flow__node:has(.graph-editor-canvas-node) {
|
|
181
|
+
overflow: visible;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.docs-preview .graph-editor-text--sm {
|
|
185
|
+
font-size: 14px;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
.docs-preview .graph-editor-text--md {
|
|
189
|
+
font-size: 16px;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
.docs-preview .graph-editor-text--xs {
|
|
193
|
+
font-size: 12px;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.docs-preview .graph-editor-text--bold {
|
|
197
|
+
font-weight: 700;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
.docs-preview .graph-editor-text--danger {
|
|
201
|
+
color: var(--graph-editor-danger);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.docs-preview .graph-editor-text--center {
|
|
205
|
+
text-align: center;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.docs-preview .graph-editor-muted {
|
|
209
|
+
color: var(--graph-editor-muted);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
.docs-preview .graph-editor-flex {
|
|
213
|
+
display: flex;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
.docs-preview .graph-editor-flex--row {
|
|
217
|
+
flex-direction: row;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
.docs-preview .graph-editor-flex--between {
|
|
221
|
+
justify-content: space-between;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.docs-preview .graph-editor-flex--align-start {
|
|
225
|
+
align-items: flex-start;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.docs-preview .graph-editor-flex-shrink-0 {
|
|
229
|
+
flex-shrink: 0;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
.docs-preview .graph-editor-flex-grow-1 {
|
|
233
|
+
flex-grow: 1;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
.docs-preview .graph-editor-min-w-0 {
|
|
237
|
+
min-width: 0;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.docs-preview .graph-editor-overflow-hidden {
|
|
241
|
+
overflow: hidden;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
.docs-preview .graph-editor-spacing--py-2 {
|
|
245
|
+
padding-top: 8px;
|
|
246
|
+
padding-bottom: 8px;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
.docs-preview .graph-editor-spacing--px-2 {
|
|
250
|
+
padding-right: 8px;
|
|
251
|
+
padding-left: 8px;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
.docs-preview .graph-editor-spacing--p-2 {
|
|
255
|
+
padding: 8px;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
.docs-preview .graph-editor-spacing--mb-0 {
|
|
259
|
+
margin-bottom: 0;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
.docs-preview .graph-editor-spacing--ms-1 {
|
|
263
|
+
margin-left: 4px;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
.docs-preview .graph-editor-spacing--gap-1 {
|
|
267
|
+
gap: 4px;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
.docs-preview .graph-editor-spacing--gap-2 {
|
|
271
|
+
gap: 8px;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
.docs-preview .graph-editor-rounded {
|
|
275
|
+
border-radius: var(--graph-editor-radius);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
.docs-preview .graph-editor-icon {
|
|
279
|
+
display: inline-block;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
.docs-preview .graph-editor-choice-row-select {
|
|
283
|
+
width: 100%;
|
|
284
|
+
border: 0;
|
|
285
|
+
padding: 0;
|
|
286
|
+
background: transparent;
|
|
287
|
+
color: inherit;
|
|
288
|
+
font: inherit;
|
|
289
|
+
text-align: start;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
.docs-preview .graph-editor-canvas-node--border-danger {
|
|
293
|
+
border-color: var(--graph-editor-danger) !important;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
.docs-preview .react-flow__controls {
|
|
297
|
+
display: none;
|
|
298
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { mkdir, readdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { createServer } from "vite";
|
|
5
|
+
import { chromium } from "playwright";
|
|
6
|
+
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
const demoRoot = new URL("./", import.meta.url);
|
|
9
|
+
const outputPath = new URL("../tree-spec-example-flow.svg", import.meta.url);
|
|
10
|
+
const demoStylesPath = new URL("./editor-demo.css", import.meta.url);
|
|
11
|
+
const distributionRoot = new URL("../../dist/", demoRoot);
|
|
12
|
+
const reactFlowStylesPath = require.resolve("reactflow/dist/style.css");
|
|
13
|
+
const checkOnly = process.argv.includes("--check");
|
|
14
|
+
|
|
15
|
+
const width = 1400;
|
|
16
|
+
const height = 840;
|
|
17
|
+
const expectedSvgFragments = [
|
|
18
|
+
'<main class="docs-preview" id="editor-preview">',
|
|
19
|
+
'data-id="triage"',
|
|
20
|
+
'data-id="investigate"',
|
|
21
|
+
'data-id="recovery"',
|
|
22
|
+
'data-id="END"',
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
function escapeXml(value) {
|
|
26
|
+
return value
|
|
27
|
+
.replaceAll("&", "&")
|
|
28
|
+
.replaceAll("<", "<")
|
|
29
|
+
.replaceAll(">", ">");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function readGeneratedStyles() {
|
|
33
|
+
const [reactFlowStyles, demoStyles] = await Promise.all(
|
|
34
|
+
[reactFlowStylesPath, demoStylesPath].map((path) => readFile(path, "utf8")),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
return `${reactFlowStyles.trimEnd()}\n${demoStyles.trimEnd()}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function listJavaScriptFiles(directoryUrl) {
|
|
41
|
+
const entries = await readdir(directoryUrl, { withFileTypes: true });
|
|
42
|
+
const nestedFiles = await Promise.all(
|
|
43
|
+
entries
|
|
44
|
+
.sort((left, right) => left.name.localeCompare(right.name))
|
|
45
|
+
.map(async (entry) => {
|
|
46
|
+
const entryUrl = new URL(entry.name, directoryUrl);
|
|
47
|
+
if (entry.isDirectory()) {
|
|
48
|
+
return listJavaScriptFiles(new URL(`${entry.name}/`, directoryUrl));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return entry.isFile() && entry.name.endsWith(".js") ? [entryUrl] : [];
|
|
52
|
+
}),
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
return nestedFiles.flat();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function getSourceFingerprint() {
|
|
59
|
+
const distributionFiles = await listJavaScriptFiles(distributionRoot);
|
|
60
|
+
const inputs = [
|
|
61
|
+
{ id: "docs/demo/editor-demo.css", path: demoStylesPath },
|
|
62
|
+
{ id: "docs/demo/generate-doc-images.mjs", path: new URL("./generate-doc-images.mjs", demoRoot) },
|
|
63
|
+
{ id: "docs/demo/index.html", path: new URL("./index.html", demoRoot) },
|
|
64
|
+
{ id: "docs/demo/main.jsx", path: new URL("./main.jsx", demoRoot) },
|
|
65
|
+
{ id: "docs/demo/treeSpecExample.mjs", path: new URL("./treeSpecExample.mjs", demoRoot) },
|
|
66
|
+
{ id: "node_modules/reactflow/dist/style.css", path: reactFlowStylesPath },
|
|
67
|
+
{ id: "package.json", path: new URL("../../package.json", demoRoot) },
|
|
68
|
+
{ id: "yarn.lock", path: new URL("../../yarn.lock", demoRoot) },
|
|
69
|
+
...distributionFiles.map((path) => ({
|
|
70
|
+
id: `dist/${path.pathname.slice(distributionRoot.pathname.length)}`,
|
|
71
|
+
path,
|
|
72
|
+
})),
|
|
73
|
+
].sort((left, right) => left.id.localeCompare(right.id));
|
|
74
|
+
const hash = createHash("sha256");
|
|
75
|
+
|
|
76
|
+
for (const input of inputs) {
|
|
77
|
+
hash.update(input.id);
|
|
78
|
+
hash.update("\0");
|
|
79
|
+
hash.update(await readFile(input.path));
|
|
80
|
+
hash.update("\0");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return hash.digest("hex");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function buildSvg(markup, styles, sourceFingerprint) {
|
|
87
|
+
const markupWithSvgNamespaces = markup.replace(
|
|
88
|
+
/<svg (?!xmlns=)/g,
|
|
89
|
+
'<svg xmlns="http://www.w3.org/2000/svg" ',
|
|
90
|
+
);
|
|
91
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
92
|
+
<!-- Generated by docs/demo/generate-doc-images.mjs. Do not edit by hand. -->
|
|
93
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" data-tree-spec-demo-source-hash="${sourceFingerprint}">
|
|
94
|
+
<title>TreeSpec editor incident response example</title>
|
|
95
|
+
<foreignObject x="0" y="0" width="${width}" height="${height}">
|
|
96
|
+
<div xmlns="http://www.w3.org/1999/xhtml">
|
|
97
|
+
<style>${escapeXml(styles)}</style>
|
|
98
|
+
${markupWithSvgNamespaces}
|
|
99
|
+
</div>
|
|
100
|
+
</foreignObject>
|
|
101
|
+
</svg>
|
|
102
|
+
`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function verifyGeneratedImage(sourceFingerprint) {
|
|
106
|
+
const existing = await readFile(outputPath, "utf8");
|
|
107
|
+
const hasCurrentSources = existing.includes(`data-tree-spec-demo-source-hash="${sourceFingerprint}"`);
|
|
108
|
+
const hasExpectedStructure = expectedSvgFragments.every((fragment) => existing.includes(fragment));
|
|
109
|
+
|
|
110
|
+
if (!hasCurrentSources || !hasExpectedStructure) {
|
|
111
|
+
throw new Error("docs/tree-spec-example-flow.svg is stale; run yarn docs:images");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async function main() {
|
|
116
|
+
const server = await createServer({
|
|
117
|
+
root: demoRoot.pathname,
|
|
118
|
+
configFile: false,
|
|
119
|
+
server: { host: "127.0.0.1", port: 0 },
|
|
120
|
+
optimizeDeps: { force: true },
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
await server.listen();
|
|
124
|
+
const address = server.httpServer?.address();
|
|
125
|
+
if (!address || typeof address === "string") {
|
|
126
|
+
await server.close();
|
|
127
|
+
throw new Error("Vite did not expose a local HTTP address");
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const browser = await chromium.launch({ headless: true });
|
|
131
|
+
try {
|
|
132
|
+
const page = await browser.newPage({ viewport: { width, height } });
|
|
133
|
+
await page.goto(`http://127.0.0.1:${address.port}/`, { waitUntil: "networkidle" });
|
|
134
|
+
await page.waitForFunction(
|
|
135
|
+
() =>
|
|
136
|
+
document.querySelectorAll(".react-flow__node .graph-editor-canvas-node").length === 4 &&
|
|
137
|
+
document.querySelector('.react-flow__node[data-id="END"] .graph-editor-canvas-node'),
|
|
138
|
+
);
|
|
139
|
+
await page.waitForTimeout(150);
|
|
140
|
+
|
|
141
|
+
const sourceFingerprint = await getSourceFingerprint();
|
|
142
|
+
|
|
143
|
+
if (checkOnly) {
|
|
144
|
+
await verifyGeneratedImage(sourceFingerprint);
|
|
145
|
+
} else {
|
|
146
|
+
const markup = await page.locator("#editor-preview").evaluate((element) => element.outerHTML);
|
|
147
|
+
const styles = await readGeneratedStyles();
|
|
148
|
+
const svg = buildSvg(markup, styles, sourceFingerprint);
|
|
149
|
+
await mkdir(new URL("../", import.meta.url), { recursive: true });
|
|
150
|
+
await writeFile(outputPath, svg, "utf8");
|
|
151
|
+
}
|
|
152
|
+
} finally {
|
|
153
|
+
await browser.close();
|
|
154
|
+
await server.close();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
main().catch((error) => {
|
|
159
|
+
console.error(error);
|
|
160
|
+
process.exitCode = 1;
|
|
161
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>TreeSpec editor documentation preview</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="root"></div>
|
|
10
|
+
<script type="module" src="./main.jsx"></script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { createRoot } from "react-dom/client";
|
|
3
|
+
import "reactflow/dist/style.css";
|
|
4
|
+
import "./editor-demo.css";
|
|
5
|
+
|
|
6
|
+
import { autoLayoutTree, patchGraphEditorMeta } from "@signalsafe/tree-spec-editor-core";
|
|
7
|
+
import TreeSpecGraphEditor from "../../dist/index.js";
|
|
8
|
+
import { incidentResponseEditorTree } from "./treeSpecExample.mjs";
|
|
9
|
+
|
|
10
|
+
const laidOutTree = patchGraphEditorMeta(autoLayoutTree(incidentResponseEditorTree), {
|
|
11
|
+
viewport: { x: 36, y: 72, zoom: 0.82 },
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
function EditorDocumentationPreview() {
|
|
15
|
+
return (
|
|
16
|
+
<main className="docs-preview" id="editor-preview">
|
|
17
|
+
<header className="docs-preview__header">
|
|
18
|
+
<div>
|
|
19
|
+
<div className="docs-preview__eyebrow">TreeSpec editor</div>
|
|
20
|
+
<h1>Incident response decision tree</h1>
|
|
21
|
+
</div>
|
|
22
|
+
<div className="docs-preview__status">Read-only example</div>
|
|
23
|
+
</header>
|
|
24
|
+
<p className="docs-preview__description">
|
|
25
|
+
Generated from the exported <code>TreeSpecGraphEditor</code> with the editor model and live
|
|
26
|
+
example data.
|
|
27
|
+
</p>
|
|
28
|
+
<section className="docs-preview__canvas" aria-label="TreeSpec editor graph">
|
|
29
|
+
<TreeSpecGraphEditor
|
|
30
|
+
tree={laidOutTree}
|
|
31
|
+
onChange={() => undefined}
|
|
32
|
+
readOnly
|
|
33
|
+
showMiniMap={false}
|
|
34
|
+
contextualZoom={false}
|
|
35
|
+
className="graph-editor-canvas-root"
|
|
36
|
+
/>
|
|
37
|
+
</section>
|
|
38
|
+
</main>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
createRoot(document.getElementById("root")).render(<EditorDocumentationPreview />);
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { END_NODE_ID } from "@signalsafe/tree-spec-editor-core";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Single source of truth for the editor documentation preview.
|
|
5
|
+
*
|
|
6
|
+
* This is the authoring graph shape consumed by TreeSpecGraphEditor rather
|
|
7
|
+
* than the compiled wire format, so the preview exercises the editor model
|
|
8
|
+
* and its terminal END node directly.
|
|
9
|
+
*/
|
|
10
|
+
export const incidentResponseEditorTree = {
|
|
11
|
+
start_node: "triage",
|
|
12
|
+
nodes: {
|
|
13
|
+
triage: {
|
|
14
|
+
id: "triage",
|
|
15
|
+
type: "prompt",
|
|
16
|
+
prompt: "An employee reports a suspicious attachment. What is the first response?",
|
|
17
|
+
choices: [
|
|
18
|
+
{
|
|
19
|
+
id: "investigate",
|
|
20
|
+
label: "Investigate the email headers and isolate the device",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: "dismiss",
|
|
24
|
+
label: "Assume it is harmless and dismiss the report",
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
investigate: {
|
|
29
|
+
id: "investigate",
|
|
30
|
+
type: "prompt",
|
|
31
|
+
prompt: "The attachment contacted an unknown host. What do you do next?",
|
|
32
|
+
choices: [
|
|
33
|
+
{
|
|
34
|
+
id: "escalate",
|
|
35
|
+
label: "Escalate to incident response and preserve evidence",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: "reimage",
|
|
39
|
+
label: "Reimage immediately without collecting evidence",
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
recovery: {
|
|
44
|
+
id: "recovery",
|
|
45
|
+
type: "info",
|
|
46
|
+
prompt: "Notify stakeholders, document the timeline, and restore the endpoint safely.",
|
|
47
|
+
choices: [{ id: "close", label: "Close incident" }],
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
transitions: [
|
|
51
|
+
{
|
|
52
|
+
id: "triage-investigate",
|
|
53
|
+
fromNodeId: "triage",
|
|
54
|
+
fromChoiceId: "investigate",
|
|
55
|
+
toNodeId: "investigate",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: "triage-dismiss",
|
|
59
|
+
fromNodeId: "triage",
|
|
60
|
+
fromChoiceId: "dismiss",
|
|
61
|
+
toNodeId: END_NODE_ID,
|
|
62
|
+
outcome: "compromised",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
id: "investigate-escalate",
|
|
66
|
+
fromNodeId: "investigate",
|
|
67
|
+
fromChoiceId: "escalate",
|
|
68
|
+
toNodeId: "recovery",
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: "investigate-reimage",
|
|
72
|
+
fromNodeId: "investigate",
|
|
73
|
+
fromChoiceId: "reimage",
|
|
74
|
+
toNodeId: END_NODE_ID,
|
|
75
|
+
outcome: "at_risk",
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
id: "recovery-close",
|
|
79
|
+
fromNodeId: "recovery",
|
|
80
|
+
fromChoiceId: "close",
|
|
81
|
+
toNodeId: END_NODE_ID,
|
|
82
|
+
outcome: "safe",
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
};
|