orcasvn-react-diagrams 0.2.11 → 0.2.13
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/CHANGELOG.md +27 -0
- package/README.md +15 -7
- package/ai/api-contract.json +90 -1
- package/ai/invariants.json +6 -2
- package/ai/manifest.json +1 -1
- package/dist/cjs/examples.js +916 -331
- package/dist/cjs/index.js +406 -97
- package/dist/cjs/types/api/createDiagramEditor.d.ts +3 -1
- package/dist/cjs/types/api/types.d.ts +64 -0
- package/dist/cjs/types/displaybox/demos/LinkPortCreationDemoTab.d.ts +3 -0
- package/dist/cjs/types/displaybox/demos/deletionEventsDemo.d.ts +2 -0
- package/dist/cjs/types/displaybox/demos/focusElementDemo.d.ts +4 -0
- package/dist/cjs/types/displaybox/demos/linkLabelsDemo.d.ts +4 -0
- package/dist/cjs/types/displaybox/types.d.ts +3 -0
- package/dist/cjs/types/displaybox/useDemoEditor.d.ts +3 -2
- package/dist/cjs/types/engine/DiagramEngine.d.ts +11 -1
- package/dist/cjs/types/engine/TextLayoutService.d.ts +1 -0
- package/dist/cjs/types/examples/index.d.ts +1 -1
- package/dist/cjs/types/renderer/konva/KonvaInteraction.d.ts +10 -1
- package/dist/esm/examples.js +916 -331
- package/dist/esm/examples.js.map +1 -1
- package/dist/esm/index.js +406 -97
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/api/createDiagramEditor.d.ts +3 -1
- package/dist/esm/types/api/types.d.ts +64 -0
- package/dist/esm/types/displaybox/demos/LinkPortCreationDemoTab.d.ts +3 -0
- package/dist/esm/types/displaybox/demos/deletionEventsDemo.d.ts +2 -0
- package/dist/esm/types/displaybox/demos/focusElementDemo.d.ts +4 -0
- package/dist/esm/types/displaybox/demos/linkLabelsDemo.d.ts +4 -0
- package/dist/esm/types/displaybox/types.d.ts +3 -0
- package/dist/esm/types/displaybox/useDemoEditor.d.ts +3 -2
- package/dist/esm/types/engine/DiagramEngine.d.ts +11 -1
- package/dist/esm/types/engine/TextLayoutService.d.ts +1 -0
- package/dist/esm/types/examples/index.d.ts +1 -1
- package/dist/esm/types/renderer/konva/KonvaInteraction.d.ts +10 -1
- package/dist/examples.d.ts +55 -1
- package/dist/index.d.ts +67 -1
- package/docs/API_CONTRACT.md +88 -1
- package/docs/ARCHITECTURE.md +9 -7
- package/docs/CAPABILITIES.md +5 -0
- package/docs/COMMANDS_EVENTS.md +16 -6
- package/docs/DOCUMENTATION_WORKFLOW.md +5 -1
- package/docs/INTEGRATION_PLAYBOOK.md +8 -0
- package/docs/PORTING_CHECKLIST.md +4 -1
- package/docs/STATE_INVARIANTS.md +3 -0
- package/package.json +1 -1
- package/src/displaybox/demos/DeletionEventsDemoTab.tsx +167 -9
- package/src/displaybox/demos/LinkPortCreationDemoTab.tsx +98 -0
- package/src/displaybox/demos/deletionEventsDemo.ts +2 -2
- package/src/displaybox/demos/focusElementDemo.ts +91 -0
- package/src/displaybox/demos/index.tsx +124 -221
- package/src/displaybox/demos/linkLabelsDemo.ts +164 -0
- package/src/displaybox/demos/linkPortCreationDemo.ts +7 -7
- package/src/displaybox/types.ts +21 -11
- package/src/examples/index.ts +1 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DiagramEngineHandle, Point, DiagramState, ElementShapeHoverControlActivationEvent, ElementShapeHoverControlInteractionEvent, ElementShapeHoverControls, EngineChangeEvent, EngineSelectionEvent, LinkColorPoolPolicy, LinkRouteRefreshPolicy, ViewportFitOptions } from './types';
|
|
1
|
+
import { DiagramEngineHandle, Point, DiagramState, ElementShapeHoverControlActivationEvent, ElementShapeHoverControlInteractionEvent, ElementShapeHoverControls, EngineChangeEvent, EngineSelectionEvent, LinkTargetPortCreationHandler, LinkColorPoolPolicy, LinkRouteRefreshPolicy, FocusElementOptions, ViewportFitOptions } from './types';
|
|
2
2
|
import { type BuiltInShapeKind } from '../shapes';
|
|
3
3
|
export type SimpleShape = {
|
|
4
4
|
id: string;
|
|
@@ -16,6 +16,7 @@ export type DiagramEditorConfig = {
|
|
|
16
16
|
elementShapeHoverControls?: ElementShapeHoverControls;
|
|
17
17
|
onElementShapeHoverControlInteraction?: (event: ElementShapeHoverControlInteractionEvent) => void;
|
|
18
18
|
onElementShapeHoverControlActivated?: (event: ElementShapeHoverControlActivationEvent) => void;
|
|
19
|
+
onCreateLinkTargetPort?: LinkTargetPortCreationHandler;
|
|
19
20
|
onChange?: (event: EngineChangeEvent) => void;
|
|
20
21
|
onSelection?: (event: EngineSelectionEvent) => void;
|
|
21
22
|
linkRouteRefreshPolicy?: LinkRouteRefreshPolicy;
|
|
@@ -40,6 +41,7 @@ export type DiagramEditorHandle = DiagramEngineHandle & {
|
|
|
40
41
|
completeLinkToElement: (targetElementId: string, pointer: Point) => void;
|
|
41
42
|
cancelLink: () => void;
|
|
42
43
|
zoomToFitElements: (options?: ViewportFitOptions) => void;
|
|
44
|
+
focusElement: (elementId: string, options?: FocusElementOptions) => void;
|
|
43
45
|
exportImage: (options?: DiagramImageExportOptions) => string;
|
|
44
46
|
resize: (width: number, height: number) => void;
|
|
45
47
|
setElementShapeHoverControls: (controls?: ElementShapeHoverControls) => void;
|
|
@@ -24,6 +24,9 @@ export type ViewportFitOptions = {
|
|
|
24
24
|
minZoom?: number;
|
|
25
25
|
maxZoom?: number;
|
|
26
26
|
};
|
|
27
|
+
export type FocusElementOptions = {
|
|
28
|
+
zoom?: number;
|
|
29
|
+
};
|
|
27
30
|
export type MoveConstraint = 'free' | 'inside' | 'border';
|
|
28
31
|
export type TextInteractionPolicy = {
|
|
29
32
|
movable?: boolean;
|
|
@@ -297,6 +300,20 @@ export type PortData = {
|
|
|
297
300
|
rotationPivot?: Point;
|
|
298
301
|
currentAnchorId?: string;
|
|
299
302
|
};
|
|
303
|
+
export type LinkTargetPortCreationPhase = 'preview' | 'commit';
|
|
304
|
+
export type LinkTargetPortDraft = Omit<PortData, 'id' | 'elementId'>;
|
|
305
|
+
export type LinkTargetPortCreationContext = {
|
|
306
|
+
phase: LinkTargetPortCreationPhase;
|
|
307
|
+
pointer: Point;
|
|
308
|
+
sourcePortId: string;
|
|
309
|
+
sourceElementId: string;
|
|
310
|
+
targetElementId: string;
|
|
311
|
+
sourcePort: PortData;
|
|
312
|
+
targetElement: ElementData;
|
|
313
|
+
defaultPort: LinkTargetPortDraft;
|
|
314
|
+
};
|
|
315
|
+
export type LinkTargetPortCreationResult = Partial<LinkTargetPortDraft> | void;
|
|
316
|
+
export type LinkTargetPortCreationHandler = (context: LinkTargetPortCreationContext) => LinkTargetPortCreationResult;
|
|
300
317
|
export type ShapeDrawContext = {
|
|
301
318
|
ctx: CanvasRenderingContext2D;
|
|
302
319
|
model: ElementData | PortData;
|
|
@@ -380,6 +397,11 @@ export type ElementPointerEvent = {
|
|
|
380
397
|
pointer: EnginePointerInfo;
|
|
381
398
|
isMulti: boolean;
|
|
382
399
|
};
|
|
400
|
+
export type ElementDoubleClickEvent = {
|
|
401
|
+
elementId: string;
|
|
402
|
+
pointer: EnginePointerInfo;
|
|
403
|
+
isMulti: boolean;
|
|
404
|
+
};
|
|
383
405
|
export type ElementMovedEvent = {
|
|
384
406
|
elementId: string;
|
|
385
407
|
oldWorld: Point;
|
|
@@ -404,18 +426,55 @@ export type GridLayoutChangedEvent = {
|
|
|
404
426
|
beforeGridTemplate?: ElementLayoutGridRowTemplate[];
|
|
405
427
|
afterGridTemplate: ElementLayoutGridRowTemplate[];
|
|
406
428
|
};
|
|
429
|
+
export type DeletionTrigger = 'direct' | 'selection' | 'cascade';
|
|
430
|
+
export type DeletionRootRef = {
|
|
431
|
+
entity: 'element' | 'port' | 'link' | 'text';
|
|
432
|
+
id: string;
|
|
433
|
+
};
|
|
434
|
+
export type ElementDeletingEvent = {
|
|
435
|
+
elementId: string;
|
|
436
|
+
trigger: DeletionTrigger;
|
|
437
|
+
root: DeletionRootRef;
|
|
438
|
+
cancel: () => void;
|
|
439
|
+
cancelled: boolean;
|
|
440
|
+
};
|
|
407
441
|
export type ElementDeletedEvent = {
|
|
408
442
|
elementId: string;
|
|
409
443
|
};
|
|
444
|
+
export type PortDeletingEvent = {
|
|
445
|
+
portId: string;
|
|
446
|
+
elementId: string;
|
|
447
|
+
trigger: DeletionTrigger;
|
|
448
|
+
root: DeletionRootRef;
|
|
449
|
+
cancel: () => void;
|
|
450
|
+
cancelled: boolean;
|
|
451
|
+
};
|
|
410
452
|
export type PortDeletedEvent = {
|
|
411
453
|
portId: string;
|
|
412
454
|
elementId: string;
|
|
413
455
|
};
|
|
456
|
+
export type LinkDeletingEvent = {
|
|
457
|
+
linkId: string;
|
|
458
|
+
sourcePortId: string;
|
|
459
|
+
targetPortId: string;
|
|
460
|
+
trigger: DeletionTrigger;
|
|
461
|
+
root: DeletionRootRef;
|
|
462
|
+
cancel: () => void;
|
|
463
|
+
cancelled: boolean;
|
|
464
|
+
};
|
|
414
465
|
export type LinkDeletedEvent = {
|
|
415
466
|
linkId: string;
|
|
416
467
|
sourcePortId: string;
|
|
417
468
|
targetPortId: string;
|
|
418
469
|
};
|
|
470
|
+
export type TextDeletingEvent = {
|
|
471
|
+
textId: string;
|
|
472
|
+
ownerId?: string | null;
|
|
473
|
+
trigger: DeletionTrigger;
|
|
474
|
+
root: DeletionRootRef;
|
|
475
|
+
cancel: () => void;
|
|
476
|
+
cancelled: boolean;
|
|
477
|
+
};
|
|
419
478
|
export type TextDeletedEvent = {
|
|
420
479
|
textId: string;
|
|
421
480
|
ownerId?: string | null;
|
|
@@ -469,13 +528,18 @@ export type EngineEventMap = {
|
|
|
469
528
|
portMoved: PortMovedEvent;
|
|
470
529
|
portSelected: PortSelectedEvent;
|
|
471
530
|
elementClick: ElementPointerEvent;
|
|
531
|
+
elementDoubleClick: ElementDoubleClickEvent;
|
|
472
532
|
elementDragged: ElementDropEvent;
|
|
473
533
|
elementMoved: ElementMovedEvent;
|
|
474
534
|
elementResized: ElementResizedEvent;
|
|
475
535
|
gridLayoutChanged: GridLayoutChangedEvent;
|
|
536
|
+
elementDeleting: ElementDeletingEvent;
|
|
476
537
|
elementDeleted: ElementDeletedEvent;
|
|
538
|
+
portDeleting: PortDeletingEvent;
|
|
477
539
|
portDeleted: PortDeletedEvent;
|
|
540
|
+
linkDeleting: LinkDeletingEvent;
|
|
478
541
|
linkDeleted: LinkDeletedEvent;
|
|
542
|
+
textDeleting: TextDeletingEvent;
|
|
479
543
|
textDeleted: TextDeletedEvent;
|
|
480
544
|
textUpdated: TextUpdatedEvent;
|
|
481
545
|
elementSelected: ElementSelectedEvent;
|
|
@@ -25,11 +25,14 @@ export type DemoConfig = {
|
|
|
25
25
|
stageStyle?: CSSProperties;
|
|
26
26
|
actions: DemoAction[];
|
|
27
27
|
};
|
|
28
|
+
export type DemoMenuGroup = 'basics' | 'layoutText' | 'shapes' | 'portsAnchors' | 'linksRouting' | 'eventsIntegration';
|
|
28
29
|
export type DemoDefinition = {
|
|
29
30
|
id: string;
|
|
30
31
|
title: string;
|
|
31
32
|
description: string;
|
|
32
33
|
Component: React.ComponentType;
|
|
34
|
+
menuGroup: DemoMenuGroup;
|
|
35
|
+
menuOrder: number;
|
|
33
36
|
};
|
|
34
37
|
export type ToolboxItem = {
|
|
35
38
|
id: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { DiagramEditorHandle, DiagramState, ElementShapeHoverControlActivationEvent, ElementShapeHoverControlInteractionEvent, ElementShapeHoverControls, LinkColorPoolPolicy, LinkRouteRefreshPolicy, SimpleShape } from '../api';
|
|
2
|
+
import type { DiagramEditorHandle, DiagramState, ElementShapeHoverControlActivationEvent, ElementShapeHoverControlInteractionEvent, ElementShapeHoverControls, LinkColorPoolPolicy, LinkTargetPortCreationHandler, LinkRouteRefreshPolicy, SimpleShape } from '../api';
|
|
3
3
|
import type { RouterStrategy } from '../strategies/RouterStrategy';
|
|
4
4
|
import type { ViewportSnapshot } from './types';
|
|
5
5
|
type DemoEditorConfig = {
|
|
@@ -13,8 +13,9 @@ type DemoEditorConfig = {
|
|
|
13
13
|
elementShapeHoverControls?: ElementShapeHoverControls;
|
|
14
14
|
onElementShapeHoverControlInteraction?: (event: ElementShapeHoverControlInteractionEvent) => void;
|
|
15
15
|
onElementShapeHoverControlActivated?: (event: ElementShapeHoverControlActivationEvent) => void;
|
|
16
|
+
onCreateLinkTargetPort?: LinkTargetPortCreationHandler;
|
|
16
17
|
};
|
|
17
|
-
declare const useDemoEditor: ({ createState, elementShapes, portShapes, router, snapDefault, linkRouteRefreshPolicy, linkColorPoolPolicy, elementShapeHoverControls, onElementShapeHoverControlInteraction, onElementShapeHoverControlActivated, }: DemoEditorConfig) => {
|
|
18
|
+
declare const useDemoEditor: ({ createState, elementShapes, portShapes, router, snapDefault, linkRouteRefreshPolicy, linkColorPoolPolicy, elementShapeHoverControls, onElementShapeHoverControlInteraction, onElementShapeHoverControlActivated, onCreateLinkTargetPort, }: DemoEditorConfig) => {
|
|
18
19
|
containerRef: import("react").MutableRefObject<HTMLDivElement | null>;
|
|
19
20
|
editorRef: import("react").MutableRefObject<DiagramEditorHandle | null>;
|
|
20
21
|
diagramState: DiagramState | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DiagramEngineHandle, DiagramState, ElementData, EngineEventMap, ElementDropEvent, EnginePointerInfo, LinkData, LinkColorPoolPolicy, ElementLinkConnectingEvent, LinkRoutingMode, LinkRouteRefreshPolicy, OverlayShapeConfig, OverlayShapeHandle, Point, PortData, RerouteLinksOptions, TextData, PortMouseEvent } from '../api/types';
|
|
1
|
+
import { DiagramEngineHandle, DiagramState, ElementData, EngineEventMap, ElementDropEvent, EnginePointerInfo, LinkData, LinkColorPoolPolicy, ElementLinkConnectingEvent, LinkRoutingMode, LinkRouteRefreshPolicy, LinkTargetPortDraft, OverlayShapeConfig, OverlayShapeHandle, Point, PortData, RerouteLinksOptions, TextData, PortMouseEvent } from '../api/types';
|
|
2
2
|
import { Renderer } from '../renderer/Renderer';
|
|
3
3
|
import RenderScheduler from '../renderer/RenderScheduler';
|
|
4
4
|
import { RouterStrategy } from '../strategies/RouterStrategy';
|
|
@@ -61,6 +61,7 @@ export default class DiagramEngine {
|
|
|
61
61
|
setElementLayout(id: string, layout: ElementData['layout']): void;
|
|
62
62
|
removeElement(id: string): void;
|
|
63
63
|
addPortToElement(elementId: string, port: PortData): void;
|
|
64
|
+
normalizePortDraftForElement(elementId: string, draft: LinkTargetPortDraft): LinkTargetPortDraft | null;
|
|
64
65
|
movePortTo(id: string, x: number, y: number): void;
|
|
65
66
|
removePort(id: string): void;
|
|
66
67
|
addLink(link: LinkData): void;
|
|
@@ -119,6 +120,7 @@ export default class DiagramEngine {
|
|
|
119
120
|
emitPortMouseDown(event: PortMouseEvent): void;
|
|
120
121
|
emitPortMouseUp(event: PortMouseEvent): void;
|
|
121
122
|
emitElementClick(elementId: string, pointer: EnginePointerInfo, isMulti: boolean): void;
|
|
123
|
+
emitElementDoubleClick(elementId: string, pointer: EnginePointerInfo, isMulti: boolean): void;
|
|
122
124
|
emitElementLinkStarted(event: {
|
|
123
125
|
sourcePortId: string;
|
|
124
126
|
sourceElementId: string;
|
|
@@ -171,6 +173,14 @@ export default class DiagramEngine {
|
|
|
171
173
|
private refreshLinksForRenderCycle;
|
|
172
174
|
private normalizePortsForHostPolicies;
|
|
173
175
|
private computeRemovalDiff;
|
|
176
|
+
private resolveDeletionRoot;
|
|
177
|
+
private applyRemovalCommand;
|
|
178
|
+
private planRemoval;
|
|
179
|
+
private emitDeletionLifecycleEvents;
|
|
180
|
+
private emitElementDeleting;
|
|
181
|
+
private emitPortDeleting;
|
|
182
|
+
private emitLinkDeleting;
|
|
183
|
+
private emitTextDeleting;
|
|
174
184
|
private emitEntityDeletionEvents;
|
|
175
185
|
}
|
|
176
186
|
export declare const createDiagramEngine: (config: DiagramEngineConfig) => DiagramEngineHandle;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { demoTabs, baseElementShapes, basePortShapes, customGalleryShapes, defaultGhostSize, defaultSvgPath, defaultSvgPathSize, externalToolboxItems, } from '../displaybox/demos';
|
|
2
|
-
export type { DemoAction, DemoActionHelpers, DemoConfig, DemoDefinition, ToolboxItem, DiagramCounts, ViewportSnapshot, DisplayBoxMetrics, } from '../displaybox/types';
|
|
2
|
+
export type { DemoAction, DemoActionHelpers, DemoConfig, DemoDefinition, DemoMenuGroup, ToolboxItem, DiagramCounts, ViewportSnapshot, DisplayBoxMetrics, } from '../displaybox/types';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ElementShapeHoverControlActivationEvent, ElementShapeHoverControlInteractionEvent, ElementShapeHoverControls, Point, PortData } from '../../api/types';
|
|
1
|
+
import { ElementShapeHoverControlActivationEvent, ElementShapeHoverControlInteractionEvent, ElementShapeHoverControls, LinkTargetPortCreationHandler, Point, PortData } from '../../api/types';
|
|
2
2
|
import DiagramEngine from '../../engine/DiagramEngine';
|
|
3
3
|
import KonvaHitTester from './KonvaHitTester';
|
|
4
4
|
import { KonvaStageLike, ShapeHoverControlRenderConfig } from './KonvaRenderer';
|
|
@@ -11,6 +11,7 @@ export type InteractionConfig = {
|
|
|
11
11
|
shapeHoverControls?: ElementShapeHoverControls;
|
|
12
12
|
onShapeHoverControlInteracted?: (event: ElementShapeHoverControlInteractionEvent) => void;
|
|
13
13
|
onShapeHoverControlActivated?: (event: ElementShapeHoverControlActivationEvent) => void;
|
|
14
|
+
onCreateLinkTargetPort?: LinkTargetPortCreationHandler;
|
|
14
15
|
renderer?: {
|
|
15
16
|
renderResizeHandles: (elementId: string, position: Point, size: {
|
|
16
17
|
width: number;
|
|
@@ -55,6 +56,7 @@ export default class KonvaInteraction {
|
|
|
55
56
|
private shapeHoverControls?;
|
|
56
57
|
private onShapeHoverControlInteracted?;
|
|
57
58
|
private onShapeHoverControlActivated?;
|
|
59
|
+
private onCreateLinkTargetPort?;
|
|
58
60
|
private linkDragContext;
|
|
59
61
|
private programmaticLinkSession;
|
|
60
62
|
private bound;
|
|
@@ -142,6 +144,13 @@ export default class KonvaInteraction {
|
|
|
142
144
|
private tryCreateLinkToElement;
|
|
143
145
|
private createPortForLink;
|
|
144
146
|
private createPlaceholderPort;
|
|
147
|
+
private resolveLinkTargetPortDraft;
|
|
148
|
+
private buildDefaultLinkTargetPortDraft;
|
|
149
|
+
private mergeLinkTargetPortDraft;
|
|
150
|
+
private resolveLinkSourcePort;
|
|
151
|
+
private clonePortData;
|
|
152
|
+
private cloneLinkTargetPortDraft;
|
|
153
|
+
private cloneElementData;
|
|
145
154
|
private getElementById;
|
|
146
155
|
private getPortById;
|
|
147
156
|
private getTextById;
|