flowchart-sequence-designer 1.0.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.
@@ -0,0 +1,356 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ /**
4
+ * Top-level kind of diagram. `flowchart` uses `nodes` + `edges`; `sequence`
5
+ * uses `actors` + `messages`. The two are rendered by different editors and
6
+ * serialized differently in every exporter.
7
+ */
8
+ type DiagramType = 'flowchart' | 'sequence';
9
+ /**
10
+ * UI variant for flowchart-type models. `flowchart` is the default linear
11
+ * graph; `question` is a decision-tree variant whose nodes carry
12
+ * `metadata.answers`; `journey` is a horizontal user-journey style. The
13
+ * variant selects styling and a few interactions inside `DiagramEditor`.
14
+ */
15
+ type DiagramVariant = 'flowchart' | 'question' | 'journey';
16
+ /**
17
+ * Visual shape of a flowchart node. Defaults to `rectangle`. `diamond` is
18
+ * conventional for decisions, `circle` for start/end terminators, and
19
+ * `parallelogram` for I/O.
20
+ */
21
+ type NodeShape = 'rectangle' | 'diamond' | 'circle' | 'parallelogram';
22
+ /**
23
+ * Supported export targets.
24
+ * - `mermaid` / `plantuml` / `json` / `svg` produce a `string`.
25
+ * - `png` produces a `Blob` (browser-only — uses the Canvas API).
26
+ */
27
+ type ExportFormat = 'mermaid' | 'plantuml' | 'json' | 'svg' | 'png';
28
+ /**
29
+ * A flowchart node.
30
+ *
31
+ * @property id Stable, unique-within-model identifier. Used by edges.
32
+ * @property label Visible text. Multi-line input is wrapped by the renderer.
33
+ * @property shape Visual shape; defaults to `rectangle` when omitted.
34
+ * @property x Optional canvas x-coordinate. When omitted, the renderer
35
+ * auto-positions on first paint.
36
+ * @property y Optional canvas y-coordinate. Same defaulting as `x`.
37
+ * @property metadata Free-form bag for variant-specific data (e.g.
38
+ * `metadata.group` for journey columns, `metadata.answers`
39
+ * for question branches). Round-trips through JSON only.
40
+ */
41
+ interface DiagramNode {
42
+ id: string;
43
+ label: string;
44
+ shape?: NodeShape;
45
+ x?: number;
46
+ y?: number;
47
+ metadata?: Record<string, unknown>;
48
+ }
49
+ /**
50
+ * A directed edge between two flowchart nodes.
51
+ *
52
+ * @property id Stable, unique-within-model identifier.
53
+ * @property from Source node id. Must match an existing `DiagramNode.id`.
54
+ * @property to Target node id. Must match an existing `DiagramNode.id`.
55
+ * @property label Optional edge label rendered at the midpoint.
56
+ * @property style Line style. `solid` is default; `dashed` maps to
57
+ * Mermaid `-.->` and PlantUML `-[dashed]->`; `dotted`
58
+ * maps to Mermaid `-..->` and PlantUML `-[dotted]->`.
59
+ * @property arrowhead Arrow style at the target end. `arrow` is default.
60
+ * @property waypoint Optional manual waypoint in canvas coordinates. When
61
+ * set, the edge is routed as two cubic segments meeting
62
+ * at this point. Persisted in JSON exports; ignored by
63
+ * Mermaid/PlantUML serializers (those formats don't
64
+ * encode routing).
65
+ */
66
+ interface DiagramEdge {
67
+ id: string;
68
+ from: string;
69
+ to: string;
70
+ label?: string;
71
+ style?: 'solid' | 'dashed' | 'dotted';
72
+ arrowhead?: 'arrow' | 'none' | 'open';
73
+ waypoint?: {
74
+ x: number;
75
+ y: number;
76
+ };
77
+ }
78
+ /**
79
+ * A single message in a sequence diagram.
80
+ *
81
+ * @property id Stable, unique-within-model identifier.
82
+ * @property from Source actor name. Must appear in the model's `actors` list.
83
+ * @property to Target actor name. Must appear in the model's `actors` list.
84
+ * @property label Message text rendered above the arrow.
85
+ * @property style Arrow style. `solid` is default; `dashed` is conventional
86
+ * for asynchronous or return messages.
87
+ */
88
+ interface SequenceMessage {
89
+ id: string;
90
+ from: string;
91
+ to: string;
92
+ label: string;
93
+ style?: 'solid' | 'dashed';
94
+ }
95
+ /**
96
+ * The serialized shape of any diagram. Flowchart-type models populate
97
+ * `nodes`/`edges`; sequence-type models populate `actors`/`messages`. Both
98
+ * sub-shapes coexist on a single union to keep the JSON exporter / importer
99
+ * straightforward.
100
+ *
101
+ * @property type Discriminator — selects which sub-shape is active.
102
+ * @property variant UI variant. Only meaningful when `type === 'flowchart'`.
103
+ * @property title Optional human-readable diagram title.
104
+ * @property nodes Flowchart nodes. Always present (empty for sequence
105
+ * models) so the type stays uniform.
106
+ * @property edges Flowchart edges. Always present (empty for sequence
107
+ * models).
108
+ * @property actors Ordered list of actor names. Sequence models only.
109
+ * @property messages Ordered list of messages between actors. Sequence
110
+ * models only.
111
+ */
112
+ interface DiagramModel {
113
+ type: DiagramType;
114
+ variant?: DiagramVariant;
115
+ title?: string;
116
+ nodes: DiagramNode[];
117
+ edges: DiagramEdge[];
118
+ actors?: string[];
119
+ messages?: SequenceMessage[];
120
+ }
121
+
122
+ /**
123
+ * Color palette for the flowchart `<DiagramEditor>`. Every visual surface
124
+ * pulls from one of these tokens, so overriding any single property via
125
+ * `themeOverrides` updates every element that uses it. Built-in
126
+ * `lightTheme` and `darkTheme` are exported as ready-made values.
127
+ *
128
+ * Token groups:
129
+ * - `canvas` / `dot` — background and dot-grid color.
130
+ * - `nodeFill` / `nodeStroke` / `nodeSelectedFill` — base node styling.
131
+ * - `edgeColor` — edge stroke and arrowhead color.
132
+ * - `text*` — type ramp (primary > secondary > muted).
133
+ * - `panel*` / `ctrls*` / `input*` / `card*` / `section*` — chrome around
134
+ * the canvas (side panel, controls, form fields, card rows).
135
+ * - `labelText` / `hintText` — small-text accents inside chrome.
136
+ * - `statusBg` / `bannerBg` — bottom validation banner backdrop.
137
+ * - `btnSec*` / `shapeBtn*` — secondary button surfaces.
138
+ * - `addFormBg` — accent backdrop for the "add node" form.
139
+ */
140
+ interface ThemeColors {
141
+ canvas: string;
142
+ dot: string;
143
+ nodeFill: string;
144
+ nodeStroke: string;
145
+ nodeSelectedFill: string;
146
+ edgeColor: string;
147
+ textPrimary: string;
148
+ textSecondary: string;
149
+ textMuted: string;
150
+ panelBg: string;
151
+ panelBorder: string;
152
+ ctrlsBg: string;
153
+ ctrlsBorder: string;
154
+ inputBg: string;
155
+ inputBorder: string;
156
+ inputText: string;
157
+ cardBg: string;
158
+ cardBorder: string;
159
+ sectionBorder: string;
160
+ labelText: string;
161
+ hintText: string;
162
+ statusBg: string;
163
+ btnSecBg: string;
164
+ btnSecText: string;
165
+ shapeBtnBg: string;
166
+ shapeBtnBorder: string;
167
+ addFormBg: string;
168
+ bannerBg: string;
169
+ }
170
+ interface VariantAccent {
171
+ color: string;
172
+ fill: string;
173
+ border: string;
174
+ glow: string;
175
+ }
176
+
177
+ /**
178
+ * Props for `<DiagramEditor>`. All fields are optional — mounting with no
179
+ * props renders the flowchart preset on an `auto`-themed canvas with every
180
+ * export format and import enabled.
181
+ *
182
+ * @property initialModel Initial diagram. If a sequence model is passed,
183
+ * rendering is delegated to `<SequenceEditor>`. If
184
+ * omitted, `presetFlowchartModel(variant)` is used.
185
+ * @property onChange Fires after every committed mutation (undo/redo,
186
+ * drag, label edit, etc.). Receives the new model.
187
+ * @property onExport Optional sink for exporter output. If omitted, the
188
+ * editor triggers a browser download of `diagram.<ext>`.
189
+ * @property height Canvas height; accepts CSS units. Defaults to `600`.
190
+ * @property allowedExports Whitelist of export formats to show in the
191
+ * toolbar. Defaults to all formats.
192
+ * @property allowImport Show the import button. Defaults to `true`.
193
+ * @property variant Initial variant when `initialModel` is omitted.
194
+ * Ignored if `initialModel.variant` is set.
195
+ * @property theme `'light'`, `'dark'`, or `'auto'` (follow OS).
196
+ * Defaults to `'auto'`.
197
+ * @property themeOverrides Per-property overrides on top of the resolved
198
+ * palette. Useful for brand-matching without forking.
199
+ */
200
+ interface DiagramEditorProps {
201
+ initialModel?: DiagramModel;
202
+ onChange?: (model: DiagramModel) => void;
203
+ onExport?: (format: ExportFormat, content: string | Blob) => void;
204
+ height?: number | string;
205
+ allowedExports?: ExportFormat[];
206
+ allowImport?: boolean;
207
+ variant?: DiagramVariant;
208
+ theme?: 'light' | 'dark' | 'auto';
209
+ themeOverrides?: Partial<ThemeColors>;
210
+ }
211
+ /**
212
+ * The all-in-one editor component. Renders a smart router: if the supplied
213
+ * `initialModel.type` is `sequence`, it delegates to `<SequenceEditor>` with
214
+ * the same props pass-through. Otherwise it renders the flowchart editor.
215
+ *
216
+ * @example
217
+ * ```tsx
218
+ * import { DiagramEditor } from 'flowchart-sequence-designer/ui';
219
+ *
220
+ * export default function App() {
221
+ * return <DiagramEditor height={520} onChange={(m) => console.log(m)} />;
222
+ * }
223
+ * ```
224
+ */
225
+ declare function DiagramEditor(props: DiagramEditorProps): react_jsx_runtime.JSX.Element;
226
+
227
+ /**
228
+ * Color palette for `<SequenceEditor>`. Sequence diagrams use a smaller
229
+ * token set than flowcharts — there are no node shapes to color, but there
230
+ * are `lifeline`, `arrow`, and `actor*` tokens that flowcharts don't need.
231
+ *
232
+ * Token groups:
233
+ * - `canvas` / `dot` — background and dot-grid color.
234
+ * - `panel*` / `ctrls*` / `input*` / `card*` — chrome around the canvas.
235
+ * - `text*` — type ramp (primary > secondary > muted).
236
+ * - `lifeline` — vertical actor lifeline color.
237
+ * - `arrow` — message arrow + label color.
238
+ * - `actorFill` / `actorStroke` / `actorText` — actor header box.
239
+ */
240
+ interface SequenceThemeColors {
241
+ canvas: string;
242
+ dot: string;
243
+ panelBg: string;
244
+ panelBorder: string;
245
+ ctrlsBg: string;
246
+ ctrlsBorder: string;
247
+ inputBg: string;
248
+ inputBorder: string;
249
+ inputText: string;
250
+ textPrimary: string;
251
+ textSecondary: string;
252
+ textMuted: string;
253
+ cardBg: string;
254
+ cardBorder: string;
255
+ lifeline: string;
256
+ arrow: string;
257
+ actorFill: string;
258
+ actorStroke: string;
259
+ actorText: string;
260
+ }
261
+ /**
262
+ * Props for `<SequenceEditor>`. Mirrors `DiagramEditorProps` minus the
263
+ * flowchart-only `variant` field; the theme override type is the
264
+ * sequence-specific palette.
265
+ *
266
+ * @property initialModel Initial sequence model. Defaults to
267
+ * `presetSequenceModel()` if omitted or if a
268
+ * non-sequence model is passed.
269
+ * @property onChange Fires after every committed mutation.
270
+ * @property onExport Optional sink for exporter output. If omitted, the
271
+ * editor triggers a browser download of `sequence.<ext>`.
272
+ * @property height Canvas height; accepts CSS units. Defaults to `600`.
273
+ * @property allowedExports Whitelist of export formats. Defaults to all.
274
+ * @property allowImport Show the import button. Defaults to `true`.
275
+ * @property theme `'light'`, `'dark'`, or `'auto'` (follow OS).
276
+ * @property themeOverrides Per-property overrides on top of the resolved
277
+ * sequence palette. `themeOverrides` passed to
278
+ * `<DiagramEditor>` is forwarded here when
279
+ * `type === 'sequence'`.
280
+ */
281
+ interface SequenceEditorProps {
282
+ initialModel?: DiagramModel;
283
+ onChange?: (model: DiagramModel) => void;
284
+ onExport?: (format: ExportFormat, content: string | Blob) => void;
285
+ height?: number | string;
286
+ allowedExports?: ExportFormat[];
287
+ allowImport?: boolean;
288
+ theme?: 'light' | 'dark' | 'auto';
289
+ themeOverrides?: Partial<SequenceThemeColors>;
290
+ }
291
+ /**
292
+ * Sequence-diagram specialization of the editor. Accepts the same props as
293
+ * `<DiagramEditor>` but renders a swim-lane layout with drag-to-reorder
294
+ * messages and inline label editing.
295
+ *
296
+ * @example
297
+ * ```tsx
298
+ * import { SequenceEditor, presetSequenceModel } from 'flowchart-sequence-designer/ui';
299
+ *
300
+ * <SequenceEditor initialModel={presetSequenceModel()} theme="dark" />
301
+ * ```
302
+ */
303
+ declare function SequenceEditor({ initialModel, onChange, onExport, height, allowedExports, allowImport, theme, themeOverrides, }: SequenceEditorProps): react_jsx_runtime.JSX.Element;
304
+
305
+ interface ToolbarProps {
306
+ onExport: (format: ExportFormat) => void;
307
+ onImport?: (text: string) => void;
308
+ allowedExports?: ExportFormat[];
309
+ allowImport?: boolean;
310
+ }
311
+ declare function Toolbar({ onExport, onImport, allowedExports, allowImport }: ToolbarProps): react_jsx_runtime.JSX.Element;
312
+
313
+ interface StepEditorProps {
314
+ nodeId: string;
315
+ model: DiagramModel;
316
+ onModelChange: (model: DiagramModel) => void;
317
+ variant?: DiagramVariant;
318
+ isDark?: boolean;
319
+ t?: ThemeColors;
320
+ acc?: VariantAccent;
321
+ }
322
+ declare function StepEditor({ nodeId, model, onModelChange, variant, isDark, t, acc }: StepEditorProps): react_jsx_runtime.JSX.Element | null;
323
+
324
+ /**
325
+ * Built-in sample diagrams shown when a consumer mounts the editor without
326
+ * an `initialModel`. The goal is for the empty state to look like a real
327
+ * working diagram, not a blank canvas — so a developer evaluating the
328
+ * package immediately sees the canvas, edge styles, and side panels with
329
+ * meaningful content.
330
+ *
331
+ * Pass `initialModel={emptyModel(variant)}` (or any model of your own) to
332
+ * opt out of the preset.
333
+ */
334
+
335
+ /**
336
+ * Return a blank model of the requested type/variant. Useful as
337
+ * `initialModel={emptyModel('flowchart')}` to opt out of the demo preset.
338
+ */
339
+ declare function emptyModel(type: DiagramType, variant?: DiagramVariant): DiagramModel;
340
+ /**
341
+ * Return a fresh, ready-to-edit flowchart model for the requested variant.
342
+ * The result is a deep clone — callers may mutate freely without affecting
343
+ * future calls.
344
+ *
345
+ * - `flowchart` → 6-node order-processing example with a decision diamond
346
+ * - `question` → 1-question / 3-answer routing example
347
+ * - `journey` → 5-step linear onboarding sequence
348
+ */
349
+ declare function presetFlowchartModel(variant?: DiagramVariant): DiagramModel;
350
+ /**
351
+ * Return a fresh, ready-to-edit sequence model — a 4-message User → App →
352
+ * Server login flow. Deep-cloned; safe to mutate.
353
+ */
354
+ declare function presetSequenceModel(): DiagramModel;
355
+
356
+ export { DiagramEditor, type DiagramEditorProps, SequenceEditor, type SequenceEditorProps, type SequenceThemeColors, StepEditor, type ThemeColors, Toolbar, emptyModel, presetFlowchartModel, presetSequenceModel };