prince-ui-bpmn 1.0.1

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,284 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+
4
+ /**
5
+ * Kanonische Camunda-7-Datenshapes, die die BPMN-Komponenten direkt konsumieren.
6
+ * Quelle: finops `backend/app/models.py` / `frontend/src/.../api.ts`.
7
+ * Bewusste Entscheidung (Brainstorming): Komponenten nehmen Camunda-Shapes direkt
8
+ * statt eines abstrahierten Modells.
9
+ */
10
+ /** Status einer Aktivität, abgeleitet aus der Camunda-Historie. */
11
+ type ActivityStatus = "active" | "completed" | "incident" | "canceled";
12
+ /** Eintrag aus `GET /history/activity-instance`. */
13
+ interface HistoryActivityInstance {
14
+ id: string;
15
+ activityId: string;
16
+ activityName?: string | null;
17
+ activityType?: string | null;
18
+ processInstanceId?: string;
19
+ executionId?: string;
20
+ startTime?: string | null;
21
+ endTime?: string | null;
22
+ cancelTime?: string | null;
23
+ durationInMillis?: number | null;
24
+ /** gesetzt, wenn die Aktivität ein CallActivity ist */
25
+ calledProcessInstanceId?: string | null;
26
+ canceled?: boolean;
27
+ completeScope?: boolean;
28
+ }
29
+ /** Eintrag aus `GET /incident`. */
30
+ interface Incident {
31
+ id: string;
32
+ incidentType?: string;
33
+ activityId?: string | null;
34
+ failedActivityId?: string | null;
35
+ incidentMessage?: string | null;
36
+ processInstanceId?: string;
37
+ rootCauseIncidentId?: string | null;
38
+ causeIncidentId?: string | null;
39
+ incidentTimestamp?: string | null;
40
+ }
41
+ /** Eintrag aus `GET /history/variable-instance`. */
42
+ interface HistoryVariableInstance {
43
+ id: string;
44
+ name: string;
45
+ type?: string;
46
+ value?: unknown;
47
+ activityInstanceId?: string;
48
+ processInstanceId?: string;
49
+ }
50
+ /** Daten, die ein Klick auf ein Diagramm-Element liefert. */
51
+ interface BpmnElementClick {
52
+ elementId: string;
53
+ elementType: string;
54
+ businessObject: unknown;
55
+ /** Bildschirmposition (für Popover/Intervention) */
56
+ screenPosition?: {
57
+ x: number;
58
+ y: number;
59
+ };
60
+ }
61
+ /** Light/Dark-Steuerung der Diagramm-Komponenten. */
62
+ type DiagramColorScheme = "auto" | "light" | "dark";
63
+
64
+ /**
65
+ * Theme-Bridge für bpmn-js/diagram-js.
66
+ *
67
+ * SVG-Diagramme von bpmn.io werden NICHT über CSS gethemt, sondern über die
68
+ * Renderer-Config (`bpmnRenderer`/`textRenderer`). Diese Bridge liest die
69
+ * prince-ui-Tokens (`--prn-*`) vom Dokument und liefert konkrete Farbwerte —
70
+ * ersetzt das frühere `data-sap-theme`-Coupling aus finops/maco-process-studio.
71
+ *
72
+ * Kolokiert je Paket (kein geteiltes 4. Paket) — das dmn-Paket hält eine Kopie.
73
+ */
74
+
75
+ interface DiagramColors {
76
+ /** Füllfarbe der Shapes */
77
+ defaultFillColor: string;
78
+ /** Konturfarbe der Shapes/Connections */
79
+ defaultStrokeColor: string;
80
+ /** Textfarbe der Labels */
81
+ defaultLabelColor: string;
82
+ /** Canvas-Hintergrund (für den umgebenden Container) */
83
+ canvasBackground: string;
84
+ /** Akzentfarbe (Selektion/aktive Elemente) */
85
+ accent: string;
86
+ }
87
+ /** Liest einen CSS-Custom-Property-Wert vom `:root`, mit Fallback. */
88
+ declare function readToken(name: string, fallback: string): string;
89
+ /** Ermittelt, ob der Dark-Mode aktiv ist (data-theme bzw. System). */
90
+ declare function isDarkMode(scheme?: DiagramColorScheme): boolean;
91
+ /**
92
+ * Liefert die Diagrammfarben aus den prince-ui-Tokens.
93
+ * Fallbacks entsprechen den Token-Defaults aus `packages/tokens/src/tokens.css`.
94
+ */
95
+ declare function getDiagramColors(scheme?: DiagramColorScheme): DiagramColors;
96
+ /**
97
+ * Beobachtet `data-theme`-Wechsel am `<html>` und ruft `onChange` auf.
98
+ * Gibt eine Cleanup-Funktion zurück.
99
+ */
100
+ declare function onThemeChange(onChange: () => void): () => void;
101
+
102
+ interface BpmnViewerProps {
103
+ /** Das anzuzeigende BPMN 2.0 XML. */
104
+ xml: string;
105
+ /** Camunda-7-History-Einträge zur Status-Färbung. */
106
+ activityHistory?: HistoryActivityInstance[];
107
+ /** Camunda-7-Incidents (färben das betroffene Element rot). */
108
+ incidents?: Incident[];
109
+ /** IDs der zur Laufzeit aktiven Aktivitäten (überschreiben History → blau). */
110
+ runtimeActiveActivityIds?: string[];
111
+ /** Light/Dark-Steuerung. Default `auto` (folgt `data-theme`). */
112
+ colorScheme?: DiagramColorScheme;
113
+ /** Klick auf ein Element. */
114
+ onElementClick?: (event: BpmnElementClick) => void;
115
+ /** Bei Container-Resize automatisch neu einpassen. Default `true`. */
116
+ fitOnResize?: boolean;
117
+ /** Zoom-Steuerung (Buttons) anzeigen. Default `true`. */
118
+ showZoomControls?: boolean;
119
+ /** Höhe des Containers. Default `"100%"`. Canvas braucht eine feste Höhe. */
120
+ height?: string | number;
121
+ /** Optionaler Klassennamen-Override für den äußeren Container. */
122
+ className?: string;
123
+ }
124
+ /**
125
+ * Apple-styled, read-only BPMN-Viewer mit deklarativem Status-Highlighting.
126
+ */
127
+ declare function BpmnViewer({ xml, activityHistory, incidents, runtimeActiveActivityIds, colorScheme, onElementClick, fitOnResize, showZoomControls, height, className, }: BpmnViewerProps): react.JSX.Element;
128
+
129
+ /**
130
+ * Reine Logik für das Status/Historie-Highlighting des BpmnViewers.
131
+ *
132
+ * Ersetzt das fragile imperative SVG-Recoloring aus finops `BpmnDiagram.tsx`
133
+ * durch pure, getestete Funktionen:
134
+ * - Activity↔Element-Matching (direkt, case-insensitive, Name-Matching für CallActivities)
135
+ * - Status-Ableitung aus History/Incidents/Runtime
136
+ * - Status→Token-Mapping
137
+ * - Sequenzfluss-„ausgeführt"-Erkennung
138
+ *
139
+ * Das DOM/Overlay-/Marker-Setup baut darauf auf (siehe `overlays.ts`).
140
+ */
141
+
142
+ /** Minimaler Ausschnitt eines diagram-js-Elements, den die Logik braucht. */
143
+ interface DiagramElementLike {
144
+ id: string;
145
+ type?: string;
146
+ businessObject?: {
147
+ id?: string;
148
+ name?: string;
149
+ $type?: string;
150
+ sourceRef?: {
151
+ id?: string;
152
+ };
153
+ targetRef?: {
154
+ id?: string;
155
+ };
156
+ };
157
+ }
158
+ /** Status→prince-ui-Token (CSS-Custom-Property-Name). */
159
+ declare const STATUS_TOKEN: Record<ActivityStatus, string>;
160
+ /** Deutsche Kurzbezeichnung je Status (für Tooltips/Legende/A11y). */
161
+ declare const STATUS_LABEL: Record<ActivityStatus, string>;
162
+ /**
163
+ * Baut eine Lookup-Map über alle Matching-Schlüssel einer Aktivität:
164
+ * `activityId`, `id` und (lowercased) `activityName`. Mehrere History-Einträge
165
+ * derselben `activityId` werden zusammengeführt (jüngster „gewinnt" beim Status).
166
+ */
167
+ declare function buildActivityMap(activities: HistoryActivityInstance[]): Map<string, HistoryActivityInstance>;
168
+ /**
169
+ * Matcht ein Diagramm-Element auf einen History-Eintrag.
170
+ * Strategien (in Reihenfolge): direktes ID-Matching, case-insensitive,
171
+ * Name-Matching für CallActivities.
172
+ */
173
+ declare function matchActivity(element: DiagramElementLike, map: Map<string, HistoryActivityInstance>): HistoryActivityInstance | null;
174
+ interface StatusContext {
175
+ incidents: Incident[];
176
+ runtimeActiveActivityIds?: Set<string>;
177
+ multiExecutionIds?: Set<string>;
178
+ }
179
+ /**
180
+ * Leitet den Status eines Elements aus History + Incidents + Runtime ab.
181
+ * Priorität: Incident > Runtime-aktiv > abgeschlossen > History-aktiv > abgebrochen.
182
+ * Gibt `null` für „nicht ausgeführt" zurück.
183
+ */
184
+ declare function deriveStatus(element: DiagramElementLike, activity: HistoryActivityInstance | null, ctx: StatusContext): {
185
+ status: ActivityStatus;
186
+ isMultiExecution: boolean;
187
+ } | null;
188
+ interface ElementStatusEntry {
189
+ elementId: string;
190
+ status: ActivityStatus;
191
+ token: string;
192
+ label: string;
193
+ isMultiExecution: boolean;
194
+ activity: HistoryActivityInstance | null;
195
+ }
196
+ /**
197
+ * Berechnet den Status aller Flow-Knoten aus den gegebenen Elementen.
198
+ * Reines Mapping — kein DOM-Zugriff. Die Komponente übersetzt das Ergebnis
199
+ * in diagram-js-Marker + Overlays.
200
+ */
201
+ declare function computeElementStatuses(elements: DiagramElementLike[], activities: HistoryActivityInstance[], options?: {
202
+ incidents?: Incident[];
203
+ runtimeActiveActivityIds?: string[];
204
+ }): ElementStatusEntry[];
205
+ /** Liefert die IDs aller ausgeführten Sequenzflüsse. */
206
+ declare function computeExecutedFlows(elements: DiagramElementLike[], activities: HistoryActivityInstance[]): string[];
207
+
208
+ /**
209
+ * bpmnlint-Konfiguration für den BpmnEditor.
210
+ *
211
+ * Die Regel-Module von `bpmnlint` werden im Editor **lazy** geladen und hier
212
+ * über einen Resolver injiziert — so bleibt der Paket-Entry frei von
213
+ * Top-Level-Engine-Imports. Portiert aus maco `BpmnEditor/lintConfig.ts`
214
+ * (4 Regeln: label-required, no-disconnected, no-implicit-split, no-complex-gateway).
215
+ */
216
+ /** Ein einzelnes, flach normalisiertes Lint-Ergebnis aus bpmn-js-bpmnlint. */
217
+ interface LintIssue {
218
+ id: string;
219
+ message: string;
220
+ category: "error" | "warning";
221
+ element?: string;
222
+ }
223
+ /** Severity je Regel. */
224
+ type LintSeverity = "error" | "warn" | "off";
225
+ /** Regel-Konfiguration: Regelname → Severity. */
226
+ type LintRuleConfig = Record<string, LintSeverity>;
227
+
228
+ interface BpmnEditorProps {
229
+ /** Controlled BPMN-XML. Bei gesetztem `value` ist die Komponente controlled. */
230
+ value?: string;
231
+ /** Uncontrolled Initial-XML. */
232
+ defaultValue?: string;
233
+ /** Wird bei jeder Modell-Änderung mit dem aktuellen XML aufgerufen. */
234
+ onChange?: (xml: string) => void;
235
+ /** Speichern (z. B. ⌘S / Toolbar-Button) → erhält `saveXML({format:true})`. */
236
+ onSave?: (xml: string) => void | Promise<void>;
237
+ /** bpmnlint-Regeln (Default: 4 MaKo-Regeln). */
238
+ lintRules?: LintRuleConfig;
239
+ /** Element-Selektion (ID + Name). */
240
+ onElementSelect?: (selection: {
241
+ id: string;
242
+ name?: string;
243
+ } | null) => void;
244
+ /** Dirty-State (ungespeicherte Änderungen). */
245
+ onDirtyChange?: (dirty: boolean) => void;
246
+ /** App-Slot für Zusatzaktionen in der Toolbar (z. B. KI-Button). */
247
+ actionsSlot?: ReactNode;
248
+ /** App-Slot im ErrorPanel (z. B. KI-Fix-Handler stellt eigenen Button bereit). */
249
+ onKiFix?: (issues: LintIssue[]) => void;
250
+ /** Light/Dark. Default `auto`. */
251
+ colorScheme?: DiagramColorScheme;
252
+ /** Properties-Panel anzeigen. Default `true`. */
253
+ propertiesPanel?: boolean;
254
+ /** Minimap (Übersichtskarte) anzeigen. Default `true`. */
255
+ minimap?: boolean;
256
+ /** Camunda-Element-Templates (JSON-Array) — im Properties-Panel anwendbar. */
257
+ elementTemplates?: unknown[];
258
+ /** Höhe des Editors. Default `"100%"`. */
259
+ height?: string | number;
260
+ /** Klassennamen-Override. */
261
+ className?: string;
262
+ }
263
+ declare function BpmnEditor({ value, defaultValue, onChange, onSave, lintRules, onElementSelect, onDirtyChange, actionsSlot, onKiFix, colorScheme, propertiesPanel, minimap, elementTemplates, height, className, }: BpmnEditorProps): react.JSX.Element;
264
+
265
+ /** Kuratierte, deutsche Erklärungen + Handlungsempfehlungen je bpmnlint-Regel.
266
+ * Portiert aus maco `BpmnEditor/lintHints.ts`. */
267
+ interface LintHint {
268
+ title: string;
269
+ explanation: string;
270
+ howto: string;
271
+ }
272
+ declare function lintHint(ruleId: string): LintHint;
273
+
274
+ interface BpmnTableViewProps {
275
+ /** BPMN 2.0 XML. */
276
+ xml: string;
277
+ /** Sichtbare Zeilen (Höhe der Tabelle). Default 30. */
278
+ visibleRows?: number;
279
+ /** Klassennamen-Override. */
280
+ className?: string;
281
+ }
282
+ declare function BpmnTableView({ xml, visibleRows, className }: BpmnTableViewProps): react.JSX.Element;
283
+
284
+ export { type ActivityStatus, BpmnEditor, BpmnEditor as BpmnEditorDefault, type BpmnEditorProps, type BpmnElementClick, BpmnTableView, type BpmnTableViewProps, BpmnViewer, BpmnViewer as BpmnViewerDefault, type BpmnViewerProps, type DiagramColorScheme, type DiagramColors, type ElementStatusEntry, type HistoryActivityInstance, type HistoryVariableInstance, type Incident, type LintHint, type LintIssue, type LintRuleConfig, STATUS_LABEL, STATUS_TOKEN, buildActivityMap, computeElementStatuses, computeExecutedFlows, deriveStatus, getDiagramColors, isDarkMode, lintHint, matchActivity, onThemeChange, readToken };