cx-diagrams 26.3.2 → 26.3.4
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/dist/Cell.d.ts +9 -6
- package/dist/Cell.js +3 -0
- package/dist/Flow.d.ts +13 -10
- package/dist/Flow.js +117 -4
- package/dist/FourSides.d.ts +6 -6
- package/dist/Node.d.ts +25 -13
- package/dist/Node.js +7 -4
- package/dist/Shape.d.ts +31 -3
- package/dist/Shape.js +179 -51
- package/package.json +1 -1
- package/src/Cell.tsx +12 -6
- package/src/Flow.tsx +171 -53
- package/src/FourSides.tsx +6 -6
- package/src/Node.tsx +35 -16
- package/src/Shape.scss +4 -0
- package/src/Shape.tsx +299 -86
package/dist/Cell.d.ts
CHANGED
|
@@ -13,12 +13,15 @@ export interface CellConfig extends NodeConfig {
|
|
|
13
13
|
interface CellData {
|
|
14
14
|
width: number;
|
|
15
15
|
height: number;
|
|
16
|
-
ml
|
|
17
|
-
mr
|
|
18
|
-
mt
|
|
19
|
-
mb
|
|
20
|
-
ms
|
|
21
|
-
me
|
|
16
|
+
ml: number;
|
|
17
|
+
mr: number;
|
|
18
|
+
mt: number;
|
|
19
|
+
mb: number;
|
|
20
|
+
ms: number;
|
|
21
|
+
me: number;
|
|
22
|
+
grow?: boolean;
|
|
23
|
+
msAuto?: boolean;
|
|
24
|
+
meAuto?: boolean;
|
|
22
25
|
}
|
|
23
26
|
export interface CellInstance extends NodeInstance {
|
|
24
27
|
data: CellData;
|
package/dist/Cell.js
CHANGED
package/dist/Flow.d.ts
CHANGED
|
@@ -38,19 +38,22 @@ interface FlowData {
|
|
|
38
38
|
padding?: number;
|
|
39
39
|
gap: number;
|
|
40
40
|
p?: number;
|
|
41
|
-
pl
|
|
42
|
-
pr
|
|
43
|
-
pt
|
|
44
|
-
pb
|
|
41
|
+
pl: number;
|
|
42
|
+
pr: number;
|
|
43
|
+
pt: number;
|
|
44
|
+
pb: number;
|
|
45
45
|
px?: number;
|
|
46
46
|
py?: number;
|
|
47
47
|
fixed?: boolean;
|
|
48
|
-
ml
|
|
49
|
-
mr
|
|
50
|
-
mt
|
|
51
|
-
mb
|
|
52
|
-
ms
|
|
53
|
-
me
|
|
48
|
+
ml: number;
|
|
49
|
+
mr: number;
|
|
50
|
+
mt: number;
|
|
51
|
+
mb: number;
|
|
52
|
+
ms: number;
|
|
53
|
+
me: number;
|
|
54
|
+
grow?: boolean;
|
|
55
|
+
msAuto?: boolean;
|
|
56
|
+
meAuto?: boolean;
|
|
54
57
|
}
|
|
55
58
|
export interface FlowInstance extends NodeInstance {
|
|
56
59
|
data: FlowData;
|
package/dist/Flow.js
CHANGED
|
@@ -19,10 +19,10 @@ export class Flow extends Node {
|
|
|
19
19
|
}
|
|
20
20
|
prepareData(context, instance) {
|
|
21
21
|
let { data } = instance;
|
|
22
|
-
data.pl = data.pl ?? data.px ?? data.p ?? data.padding;
|
|
23
|
-
data.pr = data.pr ?? data.px ?? data.p ?? data.padding;
|
|
24
|
-
data.pt = data.pt ?? data.py ?? data.p ?? data.padding;
|
|
25
|
-
data.pb = data.pb ?? data.py ?? data.p ?? data.padding;
|
|
22
|
+
data.pl = data.pl ?? data.px ?? data.p ?? data.padding ?? 0;
|
|
23
|
+
data.pr = data.pr ?? data.px ?? data.p ?? data.padding ?? 0;
|
|
24
|
+
data.pt = data.pt ?? data.py ?? data.p ?? data.padding ?? 0;
|
|
25
|
+
data.pb = data.pb ?? data.py ?? data.p ?? data.padding ?? 0;
|
|
26
26
|
super.prepareData(context, instance);
|
|
27
27
|
}
|
|
28
28
|
exploreCleanup(context, instance) {
|
|
@@ -133,6 +133,9 @@ export class Flow extends Node {
|
|
|
133
133
|
ms,
|
|
134
134
|
me,
|
|
135
135
|
selfAlign: this.selfAlign,
|
|
136
|
+
grow: data.grow,
|
|
137
|
+
msAuto: data.msAuto,
|
|
138
|
+
meAuto: data.meAuto,
|
|
136
139
|
};
|
|
137
140
|
super.exploreCleanup(context, instance);
|
|
138
141
|
}
|
|
@@ -142,6 +145,116 @@ export class Flow extends Node {
|
|
|
142
145
|
return;
|
|
143
146
|
let innerWidth = box.width - data.pl - data.pr;
|
|
144
147
|
let innerHeight = box.height - data.pt - data.pb;
|
|
148
|
+
let horizontal = instance.direction == "left" || instance.direction == "right";
|
|
149
|
+
// Distribute free space to grow items and auto margins
|
|
150
|
+
let contentSize = 0;
|
|
151
|
+
let itemCount = 0;
|
|
152
|
+
let growCount = 0;
|
|
153
|
+
let autoMarginCount = 0;
|
|
154
|
+
for (let { box } of nodes) {
|
|
155
|
+
if (!box)
|
|
156
|
+
continue;
|
|
157
|
+
if (itemCount > 0)
|
|
158
|
+
contentSize += data.gap;
|
|
159
|
+
if (horizontal) {
|
|
160
|
+
contentSize += box.ml + box.ms + box.width + box.mr + box.me;
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
contentSize += box.mt + box.ms + box.height + box.mb + box.me;
|
|
164
|
+
}
|
|
165
|
+
if (box.grow)
|
|
166
|
+
growCount++;
|
|
167
|
+
if (box.msAuto)
|
|
168
|
+
autoMarginCount++;
|
|
169
|
+
if (box.meAuto)
|
|
170
|
+
autoMarginCount++;
|
|
171
|
+
itemCount++;
|
|
172
|
+
}
|
|
173
|
+
let freeSpace = (horizontal ? innerWidth : innerHeight) - contentSize;
|
|
174
|
+
if (freeSpace > 0 && (growCount > 0 || autoMarginCount > 0)) {
|
|
175
|
+
let growExtra = 0;
|
|
176
|
+
let marginExtra = 0;
|
|
177
|
+
if (growCount > 0) {
|
|
178
|
+
growExtra = freeSpace / growCount;
|
|
179
|
+
freeSpace = 0;
|
|
180
|
+
}
|
|
181
|
+
if (freeSpace > 0 && autoMarginCount > 0) {
|
|
182
|
+
marginExtra = freeSpace / autoMarginCount;
|
|
183
|
+
}
|
|
184
|
+
let shift = 0;
|
|
185
|
+
for (let { box } of nodes) {
|
|
186
|
+
if (!box)
|
|
187
|
+
continue;
|
|
188
|
+
switch (instance.direction) {
|
|
189
|
+
case "right":
|
|
190
|
+
box.col += shift;
|
|
191
|
+
if (box.msAuto) {
|
|
192
|
+
box.ms += marginExtra;
|
|
193
|
+
box.col += marginExtra;
|
|
194
|
+
shift += marginExtra;
|
|
195
|
+
}
|
|
196
|
+
if (box.grow) {
|
|
197
|
+
box.width += growExtra;
|
|
198
|
+
shift += growExtra;
|
|
199
|
+
}
|
|
200
|
+
if (box.meAuto) {
|
|
201
|
+
box.me += marginExtra;
|
|
202
|
+
shift += marginExtra;
|
|
203
|
+
}
|
|
204
|
+
break;
|
|
205
|
+
case "left":
|
|
206
|
+
box.col -= shift;
|
|
207
|
+
if (box.msAuto) {
|
|
208
|
+
box.ms += marginExtra;
|
|
209
|
+
box.col -= marginExtra;
|
|
210
|
+
shift += marginExtra;
|
|
211
|
+
}
|
|
212
|
+
if (box.grow) {
|
|
213
|
+
box.width += growExtra;
|
|
214
|
+
box.col -= growExtra;
|
|
215
|
+
shift += growExtra;
|
|
216
|
+
}
|
|
217
|
+
if (box.meAuto) {
|
|
218
|
+
box.me += marginExtra;
|
|
219
|
+
shift += marginExtra;
|
|
220
|
+
}
|
|
221
|
+
break;
|
|
222
|
+
case "down":
|
|
223
|
+
box.row += shift;
|
|
224
|
+
if (box.msAuto) {
|
|
225
|
+
box.ms += marginExtra;
|
|
226
|
+
box.row += marginExtra;
|
|
227
|
+
shift += marginExtra;
|
|
228
|
+
}
|
|
229
|
+
if (box.grow) {
|
|
230
|
+
box.height += growExtra;
|
|
231
|
+
shift += growExtra;
|
|
232
|
+
}
|
|
233
|
+
if (box.meAuto) {
|
|
234
|
+
box.me += marginExtra;
|
|
235
|
+
shift += marginExtra;
|
|
236
|
+
}
|
|
237
|
+
break;
|
|
238
|
+
case "up":
|
|
239
|
+
box.row -= shift;
|
|
240
|
+
if (box.msAuto) {
|
|
241
|
+
box.ms += marginExtra;
|
|
242
|
+
box.row -= marginExtra;
|
|
243
|
+
shift += marginExtra;
|
|
244
|
+
}
|
|
245
|
+
if (box.grow) {
|
|
246
|
+
box.height += growExtra;
|
|
247
|
+
box.row -= growExtra;
|
|
248
|
+
shift += growExtra;
|
|
249
|
+
}
|
|
250
|
+
if (box.meAuto) {
|
|
251
|
+
box.me += marginExtra;
|
|
252
|
+
shift += marginExtra;
|
|
253
|
+
}
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
145
258
|
let spacing = 0;
|
|
146
259
|
if (this.justify == "space-between") {
|
|
147
260
|
let contentSize = 0, count = 0, size = 0;
|
package/dist/FourSides.d.ts
CHANGED
|
@@ -10,12 +10,12 @@ export interface FourSidesConfig extends NodeConfig {
|
|
|
10
10
|
interface FourSidesData {
|
|
11
11
|
gap: number;
|
|
12
12
|
slots: Slot[];
|
|
13
|
-
ml
|
|
14
|
-
mr
|
|
15
|
-
mt
|
|
16
|
-
mb
|
|
17
|
-
ms
|
|
18
|
-
me
|
|
13
|
+
ml: number;
|
|
14
|
+
mr: number;
|
|
15
|
+
mt: number;
|
|
16
|
+
mb: number;
|
|
17
|
+
ms: number;
|
|
18
|
+
me: number;
|
|
19
19
|
}
|
|
20
20
|
export interface FourSidesInstance extends NodeInstance {
|
|
21
21
|
data: FourSidesData;
|
package/dist/Node.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Rect } from "cx/svg";
|
|
2
|
-
import { PureContainerConfig, Instance, RenderingContext, NumberProp, StringProp, PureContainerBase } from "cx/ui";
|
|
2
|
+
import { PureContainerConfig, Instance, RenderingContext, NumberProp, StringProp, BooleanProp, PureContainerBase } from "cx/ui";
|
|
3
3
|
import { DiagramState } from "./DiagramState";
|
|
4
4
|
export interface NodeConfig extends PureContainerConfig {
|
|
5
5
|
/** Unique identifier of the node. */
|
|
@@ -24,32 +24,44 @@ export interface NodeConfig extends PureContainerConfig {
|
|
|
24
24
|
ms?: NumberProp;
|
|
25
25
|
/** End margin (margin after the element in the direction of the flow). */
|
|
26
26
|
me?: NumberProp;
|
|
27
|
+
/** If set, the element will grow to fill available space in the flow direction. */
|
|
28
|
+
grow?: BooleanProp;
|
|
29
|
+
/** If set, the start margin will be automatically calculated to fill available space. */
|
|
30
|
+
msAuto?: BooleanProp;
|
|
31
|
+
/** If set, the end margin will be automatically calculated to fill available space. */
|
|
32
|
+
meAuto?: BooleanProp;
|
|
27
33
|
}
|
|
28
34
|
export interface NodeData {
|
|
29
35
|
id?: string;
|
|
30
36
|
margin?: number;
|
|
31
37
|
m?: number;
|
|
32
|
-
ml
|
|
33
|
-
mr
|
|
34
|
-
mt
|
|
35
|
-
mb
|
|
38
|
+
ml: number;
|
|
39
|
+
mr: number;
|
|
40
|
+
mt: number;
|
|
41
|
+
mb: number;
|
|
36
42
|
mx?: number;
|
|
37
43
|
my?: number;
|
|
38
|
-
ms
|
|
39
|
-
me
|
|
44
|
+
ms: number;
|
|
45
|
+
me: number;
|
|
46
|
+
grow?: boolean;
|
|
47
|
+
msAuto?: boolean;
|
|
48
|
+
meAuto?: boolean;
|
|
40
49
|
}
|
|
41
50
|
export interface Box {
|
|
42
51
|
row: number;
|
|
43
52
|
col: number;
|
|
44
53
|
width: number;
|
|
45
54
|
height: number;
|
|
46
|
-
ml
|
|
47
|
-
mr
|
|
48
|
-
mt
|
|
49
|
-
mb
|
|
50
|
-
ms
|
|
51
|
-
me
|
|
55
|
+
ml: number;
|
|
56
|
+
mr: number;
|
|
57
|
+
mt: number;
|
|
58
|
+
mb: number;
|
|
59
|
+
ms: number;
|
|
60
|
+
me: number;
|
|
52
61
|
selfAlign?: string;
|
|
62
|
+
grow?: boolean;
|
|
63
|
+
msAuto?: boolean;
|
|
64
|
+
meAuto?: boolean;
|
|
53
65
|
}
|
|
54
66
|
export interface NodeInstance extends Instance {
|
|
55
67
|
data: NodeData;
|
package/dist/Node.js
CHANGED
|
@@ -17,14 +17,17 @@ export class Node extends PureContainerBase {
|
|
|
17
17
|
my: undefined,
|
|
18
18
|
ms: undefined,
|
|
19
19
|
me: undefined,
|
|
20
|
+
grow: undefined,
|
|
21
|
+
msAuto: undefined,
|
|
22
|
+
meAuto: undefined,
|
|
20
23
|
});
|
|
21
24
|
}
|
|
22
25
|
prepareData(context, instance) {
|
|
23
26
|
let { data } = instance;
|
|
24
|
-
data.ml = data.ml ?? data.mx ?? data.m ?? data.margin;
|
|
25
|
-
data.mr = data.mr ?? data.mx ?? data.m ?? data.margin;
|
|
26
|
-
data.mt = data.mt ?? data.my ?? data.m ?? data.margin;
|
|
27
|
-
data.mb = data.mb ?? data.my ?? data.m ?? data.margin;
|
|
27
|
+
data.ml = data.ml ?? data.mx ?? data.m ?? data.margin ?? 0;
|
|
28
|
+
data.mr = data.mr ?? data.mx ?? data.m ?? data.margin ?? 0;
|
|
29
|
+
data.mt = data.mt ?? data.my ?? data.m ?? data.margin ?? 0;
|
|
30
|
+
data.mb = data.mb ?? data.my ?? data.m ?? data.margin ?? 0;
|
|
28
31
|
super.prepareData(context, instance);
|
|
29
32
|
}
|
|
30
33
|
explore(context, instance) {
|
package/dist/Shape.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/** @jsxImportSource react */
|
|
2
|
-
import { RenderingContext, Instance, StringProp, NumberProp, ClassProp, StyleProp, Prop } from "cx/ui";
|
|
3
|
-
import { TooltipParentInstance, TooltipConfig } from "cx/widgets";
|
|
4
2
|
import { BoundedObject, BoundedObjectConfig, Rect } from "cx/svg";
|
|
3
|
+
import { ClassProp, Instance, NumberProp, Prop, RenderingContext, StringProp, StructuredProp, StyleProp } from "cx/ui";
|
|
4
|
+
import type { DragEvent } from "cx/widgets";
|
|
5
|
+
import { TooltipConfig, TooltipParentInstance } from "cx/widgets";
|
|
5
6
|
type ShapeType = "rectangle" | "circle" | "rhombus";
|
|
6
7
|
export interface ShapeConfig extends BoundedObjectConfig {
|
|
7
8
|
/** Unique identifier for this shape (used for line connections). */
|
|
@@ -32,6 +33,24 @@ export interface ShapeConfig extends BoundedObjectConfig {
|
|
|
32
33
|
onDoubleClick?: string | ((e: React.MouseEvent, instance: Instance) => void);
|
|
33
34
|
/** Context menu handler. */
|
|
34
35
|
onContextMenu?: string | ((e: React.MouseEvent, instance: Instance) => void);
|
|
36
|
+
/** Data about the drag source. Enables drag source when set. */
|
|
37
|
+
dragSource?: StructuredProp;
|
|
38
|
+
/** Callback when drag starts. Return false to cancel. */
|
|
39
|
+
onDragStart?: string | ((e: DragEvent, instance: Instance) => any);
|
|
40
|
+
/** Callback when drag ends. */
|
|
41
|
+
onDragEnd?: string | ((e: DragEvent, instance: Instance) => void);
|
|
42
|
+
/** Callback when dropped on this shape. Enables drop zone when set. */
|
|
43
|
+
onDrop?: string | ((e: DragEvent, instance: Instance) => any);
|
|
44
|
+
/** Test if drag source is acceptable. */
|
|
45
|
+
onDropTest?: string | ((e: DragEvent, instance: Instance) => boolean);
|
|
46
|
+
/** CSS class on shape element when cursor is over. */
|
|
47
|
+
overShapeClass?: ClassProp;
|
|
48
|
+
/** Style on shape element when cursor is over. */
|
|
49
|
+
overShapeStyle?: StyleProp;
|
|
50
|
+
/** CSS class on shape element when drag is active but cursor is not over. */
|
|
51
|
+
farShapeClass?: ClassProp;
|
|
52
|
+
/** Style on shape element when drag is active but cursor is not over. */
|
|
53
|
+
farShapeStyle?: StyleProp;
|
|
35
54
|
}
|
|
36
55
|
interface ShapeData {
|
|
37
56
|
id?: string;
|
|
@@ -47,8 +66,13 @@ interface ShapeData {
|
|
|
47
66
|
fill?: string;
|
|
48
67
|
stroke?: string;
|
|
49
68
|
strokeWidth?: number;
|
|
69
|
+
dragSource?: any;
|
|
70
|
+
overShapeClass?: string;
|
|
71
|
+
overShapeStyle?: any;
|
|
72
|
+
farShapeClass?: string;
|
|
73
|
+
farShapeStyle?: any;
|
|
50
74
|
}
|
|
51
|
-
export interface ShapeInstance extends Instance
|
|
75
|
+
export interface ShapeInstance extends Instance<Shape>, TooltipParentInstance {
|
|
52
76
|
data: ShapeData;
|
|
53
77
|
}
|
|
54
78
|
export declare class Shape extends BoundedObject<ShapeConfig> {
|
|
@@ -62,6 +86,10 @@ export declare class Shape extends BoundedObject<ShapeConfig> {
|
|
|
62
86
|
onClick?: string | ((e: MouseEvent, instance: Instance) => void);
|
|
63
87
|
onDoubleClick?: string | ((e: MouseEvent, instance: Instance) => void);
|
|
64
88
|
onContextMenu?: string | ((e: MouseEvent, instance: Instance) => void);
|
|
89
|
+
onDragStart?: string | ((e: DragEvent, instance: Instance) => any);
|
|
90
|
+
onDragEnd?: string | ((e: DragEvent, instance: Instance) => void);
|
|
91
|
+
onDrop?: string | ((e: DragEvent, instance: Instance) => any);
|
|
92
|
+
onDropTest?: string | ((e: DragEvent, instance: Instance) => boolean);
|
|
65
93
|
el: SVGElement | null;
|
|
66
94
|
init(): void;
|
|
67
95
|
declareData(...args: any[]): void;
|
package/dist/Shape.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/** @jsxImportSource react */
|
|
3
|
+
import { BoundedObject, Svg } from "cx/svg";
|
|
4
|
+
import { VDOM, } from "cx/ui";
|
|
5
|
+
import { getTopLevelBoundingClientRect, parseStyle } from "cx/util";
|
|
6
|
+
import { ddDetect, ddMouseDown, ddMouseUp, initiateDragDrop, registerDropZone, tooltipMouseLeave, tooltipMouseMove, tooltipParentWillUnmount, } from "cx/widgets";
|
|
5
7
|
export class Shape extends BoundedObject {
|
|
6
8
|
constructor(config) {
|
|
7
9
|
super(config);
|
|
@@ -24,59 +26,20 @@ export class Shape extends BoundedObject {
|
|
|
24
26
|
shapeStyle: { structured: true },
|
|
25
27
|
textStyle: { structured: true },
|
|
26
28
|
textClass: { structured: true },
|
|
29
|
+
dragSource: { structured: true },
|
|
30
|
+
overShapeClass: { structured: true },
|
|
31
|
+
overShapeStyle: { structured: true },
|
|
32
|
+
farShapeClass: { structured: true },
|
|
33
|
+
farShapeStyle: { structured: true },
|
|
27
34
|
});
|
|
28
35
|
}
|
|
29
36
|
render(context, instance, key) {
|
|
30
37
|
let { data } = instance;
|
|
31
|
-
let { bounds
|
|
38
|
+
let { bounds } = data;
|
|
32
39
|
if (!bounds.valid())
|
|
33
40
|
return false;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
style: data.shapeStyle || data.style,
|
|
37
|
-
fill: data.fill,
|
|
38
|
-
stroke: data.stroke,
|
|
39
|
-
strokeWidth: data.strokeWidth,
|
|
40
|
-
ref: undefined,
|
|
41
|
-
};
|
|
42
|
-
let gProps = {
|
|
43
|
-
onMouseMove: (e) => {
|
|
44
|
-
tooltipMouseMove(e, instance, this.tooltip);
|
|
45
|
-
},
|
|
46
|
-
onMouseLeave: (e) => {
|
|
47
|
-
tooltipMouseLeave(e, instance, this.tooltip);
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
if (this.onClick)
|
|
51
|
-
gProps.onClick = (e) => instance.invoke("onClick", e, instance);
|
|
52
|
-
if (this.onDoubleClick)
|
|
53
|
-
gProps.onDoubleClick = (e) => instance.invoke("onDoubleClick", e, instance);
|
|
54
|
-
if (this.onContextMenu)
|
|
55
|
-
gProps.onContextMenu = (e) => instance.invoke("onContextMenu", e, instance);
|
|
56
|
-
if (this.tooltip) {
|
|
57
|
-
shapeProps.ref = (c) => {
|
|
58
|
-
this.el = c;
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
return (_jsxs("g", { id: data.id, ...gProps, className: data.classNames, style: data.style, children: [this.renderShape(shape, bounds, shapeProps), this.renderText(shape, bounds, text, data), this.renderChildren(context, instance)] }, key));
|
|
62
|
-
}
|
|
63
|
-
// componentWillUnmount() {
|
|
64
|
-
// tooltipParentWillUnmount((this as any).props.instance);
|
|
65
|
-
// }
|
|
66
|
-
// componentWillReceiveProps(props: any) {
|
|
67
|
-
// tooltipParentWillReceiveProps(
|
|
68
|
-
// this.el!,
|
|
69
|
-
// props.instance,
|
|
70
|
-
// props.instance.widget.tooltip
|
|
71
|
-
// );
|
|
72
|
-
// }
|
|
73
|
-
// componentDidMount() {
|
|
74
|
-
// tooltipParentDidMount(
|
|
75
|
-
// this.el!,
|
|
76
|
-
// this.props.instance,
|
|
77
|
-
// this.props.instance.widget.tooltip
|
|
78
|
-
// );
|
|
79
|
-
// }
|
|
41
|
+
return (_jsx(ShapeComponent, { instance: instance, children: this.renderChildren(context, instance) }, key));
|
|
42
|
+
}
|
|
80
43
|
prepare(context, instance) {
|
|
81
44
|
super.prepare(context, instance);
|
|
82
45
|
if (context.diagram) {
|
|
@@ -118,3 +81,168 @@ export class Shape extends BoundedObject {
|
|
|
118
81
|
Shape.prototype.baseClass = "shape";
|
|
119
82
|
Shape.prototype.anchors = "0 1 1 0";
|
|
120
83
|
Shape.prototype.shape = "rectangle";
|
|
84
|
+
class ShapeComponent extends VDOM.Component {
|
|
85
|
+
constructor(props) {
|
|
86
|
+
super(props);
|
|
87
|
+
this.el = null;
|
|
88
|
+
this.onMouseDown = (e) => {
|
|
89
|
+
let { instance } = this.props;
|
|
90
|
+
let { data } = instance;
|
|
91
|
+
if (data.dragSource) {
|
|
92
|
+
ddMouseDown(e);
|
|
93
|
+
e.stopPropagation();
|
|
94
|
+
e.preventDefault();
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
this.onMouseMove = (e) => {
|
|
98
|
+
let { instance } = this.props;
|
|
99
|
+
let { widget } = instance;
|
|
100
|
+
tooltipMouseMove(e, instance, widget.tooltip);
|
|
101
|
+
if (instance.data.dragSource) {
|
|
102
|
+
e.stopPropagation();
|
|
103
|
+
e.preventDefault();
|
|
104
|
+
if (ddDetect(e))
|
|
105
|
+
this.beginDragDrop(e);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
this.onMouseLeave = (e) => {
|
|
109
|
+
let { instance } = this.props;
|
|
110
|
+
let { widget } = instance;
|
|
111
|
+
tooltipMouseLeave(e, instance, widget.tooltip);
|
|
112
|
+
};
|
|
113
|
+
this.state = { dropState: false, dragged: false };
|
|
114
|
+
}
|
|
115
|
+
render() {
|
|
116
|
+
let { instance, children } = this.props;
|
|
117
|
+
let { data } = instance;
|
|
118
|
+
let { widget } = instance;
|
|
119
|
+
let { bounds, text, shape } = data;
|
|
120
|
+
let { CSS, baseClass } = widget;
|
|
121
|
+
let { dropState } = this.state;
|
|
122
|
+
let shapeClassName = CSS.expand(CSS.element(baseClass, "shape"), data.shapeClass);
|
|
123
|
+
let shapeStyle = data.shapeStyle || data.style;
|
|
124
|
+
if (dropState === "over") {
|
|
125
|
+
shapeClassName = CSS.expand(shapeClassName, data.overShapeClass);
|
|
126
|
+
if (data.overShapeStyle)
|
|
127
|
+
shapeStyle = { ...shapeStyle, ...data.overShapeStyle };
|
|
128
|
+
}
|
|
129
|
+
else if (dropState === "far") {
|
|
130
|
+
shapeClassName = CSS.expand(shapeClassName, data.farShapeClass);
|
|
131
|
+
if (data.farShapeStyle)
|
|
132
|
+
shapeStyle = { ...shapeStyle, ...data.farShapeStyle };
|
|
133
|
+
}
|
|
134
|
+
let shapeProps = {
|
|
135
|
+
className: shapeClassName,
|
|
136
|
+
style: shapeStyle,
|
|
137
|
+
fill: data.fill,
|
|
138
|
+
stroke: data.stroke,
|
|
139
|
+
strokeWidth: data.strokeWidth,
|
|
140
|
+
};
|
|
141
|
+
return (_jsxs("g", { id: data.id, ref: (el) => {
|
|
142
|
+
this.el = el;
|
|
143
|
+
}, className: CSS.expand(data.classNames, CSS.state({ dragged: this.state.dragged })), style: data.style, onMouseMove: this.onMouseMove, onMouseDown: this.onMouseDown, onMouseUp: ddMouseUp, onMouseLeave: this.onMouseLeave, onClick: widget.onClick
|
|
144
|
+
? (e) => instance.invoke("onClick", e, instance)
|
|
145
|
+
: undefined, onDoubleClick: widget.onDoubleClick
|
|
146
|
+
? (e) => instance.invoke("onDoubleClick", e, instance)
|
|
147
|
+
: undefined, onContextMenu: widget.onContextMenu
|
|
148
|
+
? (e) => instance.invoke("onContextMenu", e, instance)
|
|
149
|
+
: undefined, children: [widget.renderShape(shape, bounds, shapeProps), widget.renderText(shape, bounds, text, data), children] }));
|
|
150
|
+
}
|
|
151
|
+
beginDragDrop(e) {
|
|
152
|
+
let { instance } = this.props;
|
|
153
|
+
let { data, store } = instance;
|
|
154
|
+
let { widget } = instance;
|
|
155
|
+
if (widget.onDragStart &&
|
|
156
|
+
instance.invoke("onDragStart", e, instance) === false)
|
|
157
|
+
return;
|
|
158
|
+
initiateDragDrop(e, {
|
|
159
|
+
sourceEl: this.el,
|
|
160
|
+
source: {
|
|
161
|
+
store: store,
|
|
162
|
+
data: data.dragSource,
|
|
163
|
+
},
|
|
164
|
+
clone: {
|
|
165
|
+
widget: {
|
|
166
|
+
$type: Svg,
|
|
167
|
+
style: { width: "100%", height: "100%" },
|
|
168
|
+
children: [
|
|
169
|
+
{
|
|
170
|
+
$type: Shape,
|
|
171
|
+
anchors: "0 1 1 0",
|
|
172
|
+
shape: data.shape,
|
|
173
|
+
fill: data.fill,
|
|
174
|
+
stroke: data.stroke,
|
|
175
|
+
strokeWidth: data.strokeWidth,
|
|
176
|
+
text: data.text,
|
|
177
|
+
class: data.classNames,
|
|
178
|
+
style: data.style,
|
|
179
|
+
shapeClass: data.shapeClass,
|
|
180
|
+
shapeStyle: data.shapeStyle,
|
|
181
|
+
textClass: data.textClass,
|
|
182
|
+
textStyle: data.textStyle,
|
|
183
|
+
},
|
|
184
|
+
],
|
|
185
|
+
},
|
|
186
|
+
store: store,
|
|
187
|
+
matchSize: true,
|
|
188
|
+
matchCursorOffset: true,
|
|
189
|
+
},
|
|
190
|
+
}, (dragEvent) => {
|
|
191
|
+
this.setState({ dragged: false });
|
|
192
|
+
if (widget.onDragEnd)
|
|
193
|
+
instance.invoke("onDragEnd", dragEvent, instance);
|
|
194
|
+
});
|
|
195
|
+
this.setState({ dragged: true });
|
|
196
|
+
}
|
|
197
|
+
componentDidMount() {
|
|
198
|
+
let { widget } = this.props.instance;
|
|
199
|
+
if (widget.onDrop) {
|
|
200
|
+
this.unregisterDropZone = registerDropZone(this);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
componentWillUnmount() {
|
|
204
|
+
if (this.unregisterDropZone) {
|
|
205
|
+
this.unregisterDropZone();
|
|
206
|
+
}
|
|
207
|
+
tooltipParentWillUnmount(this.props.instance);
|
|
208
|
+
}
|
|
209
|
+
// IDropZone methods
|
|
210
|
+
onDropTest(e) {
|
|
211
|
+
let { instance } = this.props;
|
|
212
|
+
let { widget } = instance;
|
|
213
|
+
return !widget.onDropTest || instance.invoke("onDropTest", e, instance);
|
|
214
|
+
}
|
|
215
|
+
onDragStart(e) {
|
|
216
|
+
this.setState({ dropState: "far" });
|
|
217
|
+
}
|
|
218
|
+
onDragEnd(e) {
|
|
219
|
+
this.setState({ dropState: false });
|
|
220
|
+
}
|
|
221
|
+
onDragEnter(e) {
|
|
222
|
+
this.setState({ dropState: "over" });
|
|
223
|
+
}
|
|
224
|
+
onDragLeave(e) {
|
|
225
|
+
this.setState({ dropState: "far" });
|
|
226
|
+
}
|
|
227
|
+
onDragMeasure(e) {
|
|
228
|
+
let rect = getTopLevelBoundingClientRect(this.el);
|
|
229
|
+
let { clientX, clientY } = e.cursor;
|
|
230
|
+
let over = rect.left <= clientX &&
|
|
231
|
+
clientX < rect.right &&
|
|
232
|
+
rect.top <= clientY &&
|
|
233
|
+
clientY < rect.bottom;
|
|
234
|
+
return {
|
|
235
|
+
over: over &&
|
|
236
|
+
Math.abs(clientX - (rect.left + rect.right) / 2) +
|
|
237
|
+
Math.abs(clientY - (rect.top + rect.bottom) / 2),
|
|
238
|
+
near: false,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
onDrop(e) {
|
|
242
|
+
let { instance } = this.props;
|
|
243
|
+
let { widget } = instance;
|
|
244
|
+
if (this.state.dropState === "over" && widget.onDrop) {
|
|
245
|
+
instance.invoke("onDrop", e, instance);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
package/package.json
CHANGED
package/src/Cell.tsx
CHANGED
|
@@ -19,12 +19,15 @@ export interface CellConfig extends NodeConfig {
|
|
|
19
19
|
interface CellData {
|
|
20
20
|
width: number;
|
|
21
21
|
height: number;
|
|
22
|
-
ml
|
|
23
|
-
mr
|
|
24
|
-
mt
|
|
25
|
-
mb
|
|
26
|
-
ms
|
|
27
|
-
me
|
|
22
|
+
ml: number;
|
|
23
|
+
mr: number;
|
|
24
|
+
mt: number;
|
|
25
|
+
mb: number;
|
|
26
|
+
ms: number;
|
|
27
|
+
me: number;
|
|
28
|
+
grow?: boolean;
|
|
29
|
+
msAuto?: boolean;
|
|
30
|
+
meAuto?: boolean;
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
export interface CellInstance extends NodeInstance {
|
|
@@ -68,6 +71,9 @@ export class Cell extends Node {
|
|
|
68
71
|
mb: data.mb,
|
|
69
72
|
ms: data.ms,
|
|
70
73
|
me: data.me,
|
|
74
|
+
grow: data.grow,
|
|
75
|
+
msAuto: data.msAuto,
|
|
76
|
+
meAuto: data.meAuto,
|
|
71
77
|
};
|
|
72
78
|
super.explore(context, instance);
|
|
73
79
|
}
|