orcasvn-react-diagrams 0.2.5 → 0.2.6
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 +23 -0
- package/README.md +15 -34
- package/ai/api-contract.json +38 -1
- package/ai/manifest.json +1 -1
- package/dist/cjs/examples.js +1252 -113
- package/dist/cjs/index.js +876 -81
- package/dist/cjs/types/api/createDiagramEditor.d.ts +2 -1
- package/dist/cjs/types/api/types.d.ts +26 -1
- package/dist/cjs/types/displaybox/demos/OffsetAnchorAvoidanceDemoTab.d.ts +3 -0
- package/dist/cjs/types/displaybox/demos/ZoomToFitElementsDemoTab.d.ts +3 -0
- package/dist/cjs/types/displaybox/demos/offsetAnchorAvoidanceDemo.d.ts +4 -0
- package/dist/cjs/types/displaybox/demos/textDemo.d.ts +3 -0
- package/dist/cjs/types/displaybox/demos/zoomToFitElementsDemo.d.ts +4 -0
- package/dist/cjs/types/engine/AutoLayoutService.d.ts +44 -1
- package/dist/cjs/types/engine/DiagramEngine.d.ts +12 -0
- package/dist/cjs/types/engine/LinkRoutingService.d.ts +1 -0
- package/dist/cjs/types/models/TextModel.d.ts +1 -0
- package/dist/cjs/types/renderer/konva/KonvaInteraction.d.ts +2 -0
- package/dist/esm/examples.js +1252 -113
- package/dist/esm/examples.js.map +1 -1
- package/dist/esm/index.js +876 -81
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/api/createDiagramEditor.d.ts +2 -1
- package/dist/esm/types/api/types.d.ts +26 -1
- package/dist/esm/types/displaybox/demos/OffsetAnchorAvoidanceDemoTab.d.ts +3 -0
- package/dist/esm/types/displaybox/demos/ZoomToFitElementsDemoTab.d.ts +3 -0
- package/dist/esm/types/displaybox/demos/offsetAnchorAvoidanceDemo.d.ts +4 -0
- package/dist/esm/types/displaybox/demos/textDemo.d.ts +3 -0
- package/dist/esm/types/displaybox/demos/zoomToFitElementsDemo.d.ts +4 -0
- package/dist/esm/types/engine/AutoLayoutService.d.ts +44 -1
- package/dist/esm/types/engine/DiagramEngine.d.ts +12 -0
- package/dist/esm/types/engine/LinkRoutingService.d.ts +1 -0
- package/dist/esm/types/models/TextModel.d.ts +1 -0
- package/dist/esm/types/renderer/konva/KonvaInteraction.d.ts +2 -0
- package/dist/examples.d.ts +27 -1
- package/dist/index.d.ts +29 -2
- package/docs/API_CONTRACT.md +38 -3
- package/docs/CAPABILITIES.md +3 -0
- package/docs/COMMANDS_EVENTS.md +8 -0
- package/docs/DOCUMENTATION_WORKFLOW.md +2 -1
- package/docs/INTEGRATION_PLAYBOOK.md +3 -0
- package/docs/STATE_INVARIANTS.md +4 -0
- package/package.json +1 -1
- package/src/displaybox/demos/AutoLayoutDemoTab.tsx +337 -316
- package/src/displaybox/demos/EngineEventsDemoTab.tsx +12 -11
- package/src/displaybox/demos/OffsetAnchorAvoidanceDemoTab.tsx +30 -0
- package/src/displaybox/demos/TextLayoutDemoTab.tsx +18 -1
- package/src/displaybox/demos/ZoomToFitElementsDemoTab.tsx +29 -0
- package/src/displaybox/demos/autoLayoutDemo.ts +74 -73
- package/src/displaybox/demos/index.tsx +80 -64
- package/src/displaybox/demos/offsetAnchorAvoidanceDemo.ts +211 -0
- package/src/displaybox/demos/textDemo.ts +6 -2
- package/src/displaybox/demos/zoomToFitElementsDemo.ts +83 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DiagramEngineHandle, Point, DiagramState, ElementShapeHoverControlActivationEvent, ElementShapeHoverControlInteractionEvent, ElementShapeHoverControls, EngineChangeEvent, EngineSelectionEvent, LinkColorPoolPolicy, LinkRouteRefreshPolicy } from './types';
|
|
1
|
+
import { DiagramEngineHandle, Point, DiagramState, ElementShapeHoverControlActivationEvent, ElementShapeHoverControlInteractionEvent, ElementShapeHoverControls, EngineChangeEvent, EngineSelectionEvent, LinkColorPoolPolicy, LinkRouteRefreshPolicy, ViewportFitOptions } from './types';
|
|
2
2
|
import { type BuiltInShapeKind } from '../shapes';
|
|
3
3
|
export type SimpleShape = {
|
|
4
4
|
id: string;
|
|
@@ -39,6 +39,7 @@ export type DiagramEditorHandle = DiagramEngineHandle & {
|
|
|
39
39
|
completeLinkToPort: (targetPortId: string) => void;
|
|
40
40
|
completeLinkToElement: (targetElementId: string, pointer: Point) => void;
|
|
41
41
|
cancelLink: () => void;
|
|
42
|
+
zoomToFitElements: (options?: ViewportFitOptions) => void;
|
|
42
43
|
exportImage: (options?: DiagramImageExportOptions) => string;
|
|
43
44
|
resize: (width: number, height: number) => void;
|
|
44
45
|
setElementShapeHoverControls: (controls?: ElementShapeHoverControls) => void;
|
|
@@ -19,7 +19,16 @@ export type ClientRectLike = {
|
|
|
19
19
|
export type DiagramContainer = {
|
|
20
20
|
getBoundingClientRect: () => ClientRectLike;
|
|
21
21
|
};
|
|
22
|
+
export type ViewportFitOptions = {
|
|
23
|
+
padding?: number;
|
|
24
|
+
minZoom?: number;
|
|
25
|
+
maxZoom?: number;
|
|
26
|
+
};
|
|
22
27
|
export type MoveConstraint = 'free' | 'inside' | 'border';
|
|
28
|
+
export type TextInteractionPolicy = {
|
|
29
|
+
movable?: boolean;
|
|
30
|
+
editable?: boolean;
|
|
31
|
+
};
|
|
23
32
|
export type BorderSide = 'left' | 'right' | 'top' | 'bottom';
|
|
24
33
|
export type HostAnchorPreset = 'vertices' | 'cardinal';
|
|
25
34
|
export type PortLinkAttachMode = 'external' | 'internal';
|
|
@@ -187,7 +196,7 @@ export type ElementLayoutAlign = 'start' | 'center' | 'end';
|
|
|
187
196
|
export type ElementLayoutChildFitMainAxis = 'none' | 'distribute';
|
|
188
197
|
export type ElementLayoutChildFitCrossAxis = 'none' | 'stretch';
|
|
189
198
|
export type ElementLayoutAutoResizeMode = 'grow' | 'grow-shrink';
|
|
190
|
-
export type ElementLayoutGridRowTemplate = number
|
|
199
|
+
export type ElementLayoutGridRowTemplate = number;
|
|
191
200
|
export type ElementLayoutLabelReservedSpaceMode = 'none' | 'fixed' | 'flexible';
|
|
192
201
|
export type ElementLayoutLabelReservedSpacePlacement = 'top';
|
|
193
202
|
export type ElementLayoutLabelReservedSpace = {
|
|
@@ -210,6 +219,7 @@ export type ElementLayout = {
|
|
|
210
219
|
align?: ElementLayoutAlign;
|
|
211
220
|
autoResize?: ElementLayoutAutoResizeMode;
|
|
212
221
|
gridTemplate?: ElementLayoutGridRowTemplate[];
|
|
222
|
+
gridChildWidthResizeEnabled?: boolean;
|
|
213
223
|
childFitMainAxis?: ElementLayoutChildFitMainAxis;
|
|
214
224
|
childFitCrossAxis?: ElementLayoutChildFitCrossAxis;
|
|
215
225
|
childMinWidth?: number;
|
|
@@ -300,6 +310,7 @@ export type TextData = {
|
|
|
300
310
|
size?: Size;
|
|
301
311
|
style?: Record<string, unknown>;
|
|
302
312
|
ownerId?: string | null;
|
|
313
|
+
interaction?: TextInteractionPolicy;
|
|
303
314
|
layout?: TextLayout;
|
|
304
315
|
displayContent?: string;
|
|
305
316
|
displayOffset?: Point;
|
|
@@ -373,6 +384,19 @@ export type ElementResizedEvent = {
|
|
|
373
384
|
oldSize: Size;
|
|
374
385
|
newSize: Size;
|
|
375
386
|
};
|
|
387
|
+
export type GridLayoutChangedReason = 'child-resize-split' | 'child-resize-redistribute';
|
|
388
|
+
export type GridRowSnapshot = {
|
|
389
|
+
childIds: string[];
|
|
390
|
+
};
|
|
391
|
+
export type GridLayoutChangedEvent = {
|
|
392
|
+
parentId: string;
|
|
393
|
+
triggerChildId: string;
|
|
394
|
+
reason: GridLayoutChangedReason;
|
|
395
|
+
beforeRows: GridRowSnapshot[];
|
|
396
|
+
afterRows: GridRowSnapshot[];
|
|
397
|
+
beforeGridTemplate?: ElementLayoutGridRowTemplate[];
|
|
398
|
+
afterGridTemplate: ElementLayoutGridRowTemplate[];
|
|
399
|
+
};
|
|
376
400
|
export type ElementDeletedEvent = {
|
|
377
401
|
elementId: string;
|
|
378
402
|
};
|
|
@@ -441,6 +465,7 @@ export type EngineEventMap = {
|
|
|
441
465
|
elementDragged: ElementDropEvent;
|
|
442
466
|
elementMoved: ElementMovedEvent;
|
|
443
467
|
elementResized: ElementResizedEvent;
|
|
468
|
+
gridLayoutChanged: GridLayoutChangedEvent;
|
|
444
469
|
elementDeleted: ElementDeletedEvent;
|
|
445
470
|
portDeleted: PortDeletedEvent;
|
|
446
471
|
linkDeleted: LinkDeletedEvent;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import type { TextInteractionPolicy } from '../../api';
|
|
1
2
|
import type { DemoConfig } from '../types';
|
|
2
3
|
export declare const textDemoOwnerId = "text-layout-owner";
|
|
3
4
|
export declare const textDemoOwnedTextId = "text-owned-overflow";
|
|
4
5
|
export declare const textDemoFloatingTextId = "text-floating-overflow";
|
|
5
6
|
export declare const textDemoLongSample = "Long diagram label: middle ellipsis should keep the beginning and end visible while preserving the full canonical content in model state.";
|
|
7
|
+
export declare const textDemoOwnedInteraction: TextInteractionPolicy;
|
|
8
|
+
export declare const textDemoFloatingInteraction: TextInteractionPolicy;
|
|
6
9
|
export declare const textDemoConfig: DemoConfig;
|
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
import { DiagramPatch } from '../api/types';
|
|
1
|
+
import { DiagramPatch, ElementData, GridLayoutChangedReason, GridRowSnapshot } from '../api/types';
|
|
2
2
|
import DiagramModel from '../models/DiagramModel';
|
|
3
3
|
import CommandQueue from './CommandQueue';
|
|
4
4
|
export type AutoLayoutResult = {
|
|
5
5
|
patches: DiagramPatch[];
|
|
6
6
|
movedPortIds: string[];
|
|
7
7
|
};
|
|
8
|
+
export type GridChildResizeTopologyChange = {
|
|
9
|
+
parentId: string;
|
|
10
|
+
triggerChildId: string;
|
|
11
|
+
reason: GridLayoutChangedReason;
|
|
12
|
+
beforeRows: GridRowSnapshot[];
|
|
13
|
+
afterRows: GridRowSnapshot[];
|
|
14
|
+
nextLayout: NonNullable<ElementData['layout']>;
|
|
15
|
+
};
|
|
8
16
|
export type AutoLayoutServiceConfig = {
|
|
9
17
|
model: DiagramModel;
|
|
10
18
|
commandQueue: CommandQueue;
|
|
@@ -12,6 +20,8 @@ export type AutoLayoutServiceConfig = {
|
|
|
12
20
|
};
|
|
13
21
|
type ParentLayoutOptions = {
|
|
14
22
|
preserveParentSize?: boolean;
|
|
23
|
+
preserveParentWidth?: boolean;
|
|
24
|
+
preserveParentHeight?: boolean;
|
|
15
25
|
};
|
|
16
26
|
export default class AutoLayoutService {
|
|
17
27
|
private model;
|
|
@@ -21,15 +31,48 @@ export default class AutoLayoutService {
|
|
|
21
31
|
applyLayoutForParent(parentId: string, options?: ParentLayoutOptions): AutoLayoutResult;
|
|
22
32
|
applyLayoutCascade(startParentId: string | null): AutoLayoutResult;
|
|
23
33
|
applyAllLayouts(): AutoLayoutResult;
|
|
34
|
+
describeGridRows(parentId: string): GridRowSnapshot[];
|
|
35
|
+
describeGridSlotState(parentId: string): {
|
|
36
|
+
orderedChildIds: string[];
|
|
37
|
+
slotWeights: number[];
|
|
38
|
+
} | null;
|
|
39
|
+
resolveGridReorderedLayout(parentId: string, previousState: {
|
|
40
|
+
orderedChildIds: string[];
|
|
41
|
+
slotWeights: number[];
|
|
42
|
+
}): NonNullable<ElementData['layout']> | null;
|
|
43
|
+
resolveGridChildResizeTopologyChange(parentId: string, childId: string, requestedWidth: number): GridChildResizeTopologyChange | null;
|
|
44
|
+
snapGridChildRequestedWidth(parentId: string, childId: string, requestedWidth: number): number;
|
|
45
|
+
canGridChildGrowRightward(parentId: string, childId: string): boolean;
|
|
24
46
|
private applyAxisLayoutForParent;
|
|
25
47
|
private applyGridLayoutForParent;
|
|
48
|
+
private resolveGridCellWidths;
|
|
26
49
|
private applyResolvedLayout;
|
|
27
50
|
private resolveLayoutPadding;
|
|
28
51
|
private resolveAutoResizeMode;
|
|
29
52
|
private resolveAutoResizedDimension;
|
|
30
53
|
private resolveChildSizeConstraints;
|
|
54
|
+
private resolveAssignedGridRows;
|
|
55
|
+
private repartitionAssignedGridRows;
|
|
56
|
+
private fitGridRowWeights;
|
|
57
|
+
private gridRowSnapshotsEqual;
|
|
31
58
|
private normalizeGridTemplate;
|
|
32
59
|
private assignChildrenToGridRows;
|
|
60
|
+
private resolveGridChildSlotState;
|
|
61
|
+
private packGridRowsFromSlots;
|
|
62
|
+
private resolveRequestedGridUnits;
|
|
63
|
+
private sortGridChildrenForLayout;
|
|
64
|
+
private resolveRightwardGridOverflowChange;
|
|
65
|
+
private resolveSameRowGridUnitResizeChange;
|
|
66
|
+
private splitGridRowIntoTwelveUnits;
|
|
67
|
+
private reflowTrailingGridRows;
|
|
68
|
+
private flattenAssignedRowsToGridTemplate;
|
|
69
|
+
private buildEqualGridUnits;
|
|
70
|
+
private normalizeRowWeightsToTwelveUnits;
|
|
71
|
+
private normalizeGridSlotUnits;
|
|
72
|
+
private clampGridUnits;
|
|
73
|
+
private distributeUnitsWithMinimums;
|
|
74
|
+
private gridWeightsEqual;
|
|
75
|
+
private resolveGridRowUnitWidth;
|
|
33
76
|
private resolveLabelReservedTopLane;
|
|
34
77
|
private resolveFlexibleLabelLaneFromText;
|
|
35
78
|
private resolveAlignmentOffset;
|
|
@@ -48,7 +48,15 @@ export default class DiagramEngine {
|
|
|
48
48
|
createOverlayShape(config: OverlayShapeConfig): OverlayShapeHandle;
|
|
49
49
|
on<TEvent extends keyof EngineEventMap>(event: TEvent, handler: (payload: EngineEventMap[TEvent]) => void): () => void;
|
|
50
50
|
addElement(element: ElementData): void;
|
|
51
|
+
private resolveElementMovePosition;
|
|
52
|
+
private buildChildMutationLayoutSteps;
|
|
51
53
|
moveElementTo(id: string, x: number, y: number): void;
|
|
54
|
+
resizeElementBounds(id: string, bounds: {
|
|
55
|
+
x: number;
|
|
56
|
+
y: number;
|
|
57
|
+
width: number;
|
|
58
|
+
height: number;
|
|
59
|
+
}): void;
|
|
52
60
|
resizeElement(id: string, width: number, height: number): void;
|
|
53
61
|
setElementLayout(id: string, layout: ElementData['layout']): void;
|
|
54
62
|
removeElement(id: string): void;
|
|
@@ -82,6 +90,10 @@ export default class DiagramEngine {
|
|
|
82
90
|
height: number;
|
|
83
91
|
};
|
|
84
92
|
private shouldLockAutoLayoutChildHorizontalResize;
|
|
93
|
+
private shouldAnchorAutoLayoutGridChildWidthToLeft;
|
|
94
|
+
private shouldRestrictAutoLayoutChildRightGrowth;
|
|
95
|
+
private resolveSnappedGridChildWidth;
|
|
96
|
+
private resolveGridChildWidthResizeTopologyChange;
|
|
85
97
|
getPortWorldPosition(id: string): Point | null;
|
|
86
98
|
getPortLinkWorldPosition(id: string, options?: {
|
|
87
99
|
oppositePortId?: string;
|
|
@@ -146,6 +146,8 @@ export default class KonvaInteraction {
|
|
|
146
146
|
private getElementById;
|
|
147
147
|
private getPortById;
|
|
148
148
|
private getTextById;
|
|
149
|
+
private isTextMovable;
|
|
150
|
+
private isTextEditable;
|
|
149
151
|
private getLinkById;
|
|
150
152
|
private resolveTextScreenPosition;
|
|
151
153
|
private applyViewportPatch;
|