cx-diagrams 26.3.2 → 26.3.3
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/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/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/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
|
}
|
package/src/Flow.tsx
CHANGED
|
@@ -54,19 +54,22 @@ interface FlowData {
|
|
|
54
54
|
padding?: number;
|
|
55
55
|
gap: number;
|
|
56
56
|
p?: number;
|
|
57
|
-
pl
|
|
58
|
-
pr
|
|
59
|
-
pt
|
|
60
|
-
pb
|
|
57
|
+
pl: number;
|
|
58
|
+
pr: number;
|
|
59
|
+
pt: number;
|
|
60
|
+
pb: number;
|
|
61
61
|
px?: number;
|
|
62
62
|
py?: number;
|
|
63
63
|
fixed?: boolean;
|
|
64
|
-
ml
|
|
65
|
-
mr
|
|
66
|
-
mt
|
|
67
|
-
mb
|
|
68
|
-
ms
|
|
69
|
-
me
|
|
64
|
+
ml: number;
|
|
65
|
+
mr: number;
|
|
66
|
+
mt: number;
|
|
67
|
+
mb: number;
|
|
68
|
+
ms: number;
|
|
69
|
+
me: number;
|
|
70
|
+
grow?: boolean;
|
|
71
|
+
msAuto?: boolean;
|
|
72
|
+
meAuto?: boolean;
|
|
70
73
|
}
|
|
71
74
|
|
|
72
75
|
export interface FlowInstance extends NodeInstance {
|
|
@@ -111,10 +114,10 @@ export class Flow extends Node {
|
|
|
111
114
|
|
|
112
115
|
prepareData(context: RenderingContext, instance: FlowInstance) {
|
|
113
116
|
let { data } = instance;
|
|
114
|
-
data.pl = data.pl ?? data.px ?? data.p ?? data.padding;
|
|
115
|
-
data.pr = data.pr ?? data.px ?? data.p ?? data.padding;
|
|
116
|
-
data.pt = data.pt ?? data.py ?? data.p ?? data.padding;
|
|
117
|
-
data.pb = data.pb ?? data.py ?? data.p ?? data.padding;
|
|
117
|
+
data.pl = data.pl ?? data.px ?? data.p ?? data.padding ?? 0;
|
|
118
|
+
data.pr = data.pr ?? data.px ?? data.p ?? data.padding ?? 0;
|
|
119
|
+
data.pt = data.pt ?? data.py ?? data.p ?? data.padding ?? 0;
|
|
120
|
+
data.pb = data.pb ?? data.py ?? data.p ?? data.padding ?? 0;
|
|
118
121
|
super.prepareData(context, instance);
|
|
119
122
|
}
|
|
120
123
|
|
|
@@ -134,75 +137,75 @@ export class Flow extends Node {
|
|
|
134
137
|
|
|
135
138
|
let { pl, pr, pt, pb, gap, ml, mr, mt, mb, ms, me } = data;
|
|
136
139
|
if (direction == "right") {
|
|
137
|
-
width += pl
|
|
140
|
+
width += pl;
|
|
138
141
|
for (let { box } of nodes) {
|
|
139
142
|
if (!box) continue;
|
|
140
|
-
if (width > pl
|
|
141
|
-
width += box.ml
|
|
142
|
-
width += box.ms
|
|
143
|
+
if (width > pl) width += gap;
|
|
144
|
+
width += box.ml;
|
|
145
|
+
width += box.ms;
|
|
143
146
|
box.col += width;
|
|
144
|
-
box.row += pt
|
|
147
|
+
box.row += pt + box.mt;
|
|
145
148
|
width += box.width;
|
|
146
|
-
width += box.mr
|
|
147
|
-
width += box.me
|
|
148
|
-
height = Math.max(height, box.row + box.height + box.mb
|
|
149
|
+
width += box.mr;
|
|
150
|
+
width += box.me;
|
|
151
|
+
height = Math.max(height, box.row + box.height + box.mb + pb);
|
|
149
152
|
if (box.selfAlign == "stretch") stretchItems.push(box);
|
|
150
153
|
}
|
|
151
|
-
width += pr
|
|
154
|
+
width += pr;
|
|
152
155
|
}
|
|
153
156
|
if (direction == "left") {
|
|
154
|
-
width += pr
|
|
157
|
+
width += pr;
|
|
155
158
|
for (let { box } of nodes) {
|
|
156
159
|
if (!box) continue;
|
|
157
|
-
if (width > pr
|
|
158
|
-
width += box.mr
|
|
159
|
-
width += box.ms
|
|
160
|
+
if (width > pr) width += gap;
|
|
161
|
+
width += box.mr;
|
|
162
|
+
width += box.ms;
|
|
160
163
|
box.col -= width + box.width;
|
|
161
|
-
box.row += pt
|
|
164
|
+
box.row += pt + box.mt;
|
|
162
165
|
width += box.width;
|
|
163
|
-
width += box.ml
|
|
164
|
-
width += box.me
|
|
165
|
-
height = Math.max(height, box.row + box.height + box.mb
|
|
166
|
+
width += box.ml;
|
|
167
|
+
width += box.me;
|
|
168
|
+
height = Math.max(height, box.row + box.height + box.mb + pb);
|
|
166
169
|
if (box.selfAlign == "stretch") stretchItems.push(box);
|
|
167
170
|
}
|
|
168
|
-
width += pl
|
|
171
|
+
width += pl;
|
|
169
172
|
} else if (direction == "down") {
|
|
170
|
-
height += pt
|
|
173
|
+
height += pt;
|
|
171
174
|
for (let { box } of nodes) {
|
|
172
175
|
if (!box) continue;
|
|
173
|
-
if (height > pt
|
|
174
|
-
height += box.mt
|
|
175
|
-
height += box.ms
|
|
176
|
-
box.col += pl
|
|
176
|
+
if (height > pt) height += gap;
|
|
177
|
+
height += box.mt;
|
|
178
|
+
height += box.ms;
|
|
179
|
+
box.col += pl + box.ml;
|
|
177
180
|
box.row += height;
|
|
178
181
|
height += box.height;
|
|
179
|
-
height += box.mb
|
|
180
|
-
width = Math.max(width, box.col + box.width + box.mr
|
|
182
|
+
height += box.mb;
|
|
183
|
+
width = Math.max(width, box.col + box.width + box.mr + pr);
|
|
181
184
|
if (box.selfAlign == "stretch") stretchItems.push(box);
|
|
182
185
|
}
|
|
183
|
-
height += pb
|
|
186
|
+
height += pb;
|
|
184
187
|
} else if (direction == "up") {
|
|
185
|
-
height += pb
|
|
188
|
+
height += pb;
|
|
186
189
|
for (let { box } of nodes) {
|
|
187
190
|
if (!box) continue;
|
|
188
|
-
if (height > pb
|
|
189
|
-
height += box.mb
|
|
190
|
-
height += box.ms
|
|
191
|
-
box.col += pl
|
|
191
|
+
if (height > pb) height += gap;
|
|
192
|
+
height += box.mb;
|
|
193
|
+
height += box.ms;
|
|
194
|
+
box.col += pl + box.ml;
|
|
192
195
|
box.row -= height + box.height;
|
|
193
196
|
height += box.height;
|
|
194
|
-
height += box.mt
|
|
195
|
-
height += box.me
|
|
196
|
-
width = Math.max(width, box.col + box.width + box.mr
|
|
197
|
+
height += box.mt;
|
|
198
|
+
height += box.me;
|
|
199
|
+
width = Math.max(width, box.col + box.width + box.mr + pr);
|
|
197
200
|
if (box.selfAlign == "stretch") stretchItems.push(box);
|
|
198
201
|
}
|
|
199
|
-
height += pt
|
|
202
|
+
height += pt;
|
|
200
203
|
}
|
|
201
204
|
|
|
202
205
|
if (direction == "left" || direction == "right") {
|
|
203
|
-
for (let box of stretchItems) box.height = height - pt
|
|
206
|
+
for (let box of stretchItems) box.height = height - pt - pb;
|
|
204
207
|
} else if (direction == "up" || direction == "down") {
|
|
205
|
-
for (let box of stretchItems) box.width = width - pl
|
|
208
|
+
for (let box of stretchItems) box.width = width - pl - pr;
|
|
206
209
|
}
|
|
207
210
|
|
|
208
211
|
instance.box = {
|
|
@@ -217,6 +220,9 @@ export class Flow extends Node {
|
|
|
217
220
|
ms,
|
|
218
221
|
me,
|
|
219
222
|
selfAlign: this.selfAlign,
|
|
223
|
+
grow: data.grow,
|
|
224
|
+
msAuto: data.msAuto,
|
|
225
|
+
meAuto: data.meAuto,
|
|
220
226
|
};
|
|
221
227
|
|
|
222
228
|
super.exploreCleanup(context, instance);
|
|
@@ -226,8 +232,120 @@ export class Flow extends Node {
|
|
|
226
232
|
let { box, nodes, data } = instance;
|
|
227
233
|
if (!box) return;
|
|
228
234
|
|
|
229
|
-
let innerWidth = box.width - data.pl
|
|
230
|
-
let innerHeight = box.height - data.pt
|
|
235
|
+
let innerWidth = box.width - data.pl - data.pr;
|
|
236
|
+
let innerHeight = box.height - data.pt - data.pb;
|
|
237
|
+
|
|
238
|
+
let horizontal =
|
|
239
|
+
instance.direction == "left" || instance.direction == "right";
|
|
240
|
+
|
|
241
|
+
// Distribute free space to grow items and auto margins
|
|
242
|
+
let contentSize = 0;
|
|
243
|
+
let itemCount = 0;
|
|
244
|
+
let growCount = 0;
|
|
245
|
+
let autoMarginCount = 0;
|
|
246
|
+
|
|
247
|
+
for (let { box } of nodes) {
|
|
248
|
+
if (!box) continue;
|
|
249
|
+
if (itemCount > 0) contentSize += data.gap;
|
|
250
|
+
if (horizontal) {
|
|
251
|
+
contentSize += box.ml + box.ms + box.width + box.mr + box.me;
|
|
252
|
+
} else {
|
|
253
|
+
contentSize += box.mt + box.ms + box.height + box.mb + box.me;
|
|
254
|
+
}
|
|
255
|
+
if (box.grow) growCount++;
|
|
256
|
+
if (box.msAuto) autoMarginCount++;
|
|
257
|
+
if (box.meAuto) autoMarginCount++;
|
|
258
|
+
itemCount++;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
let freeSpace = (horizontal ? innerWidth : innerHeight) - contentSize;
|
|
262
|
+
|
|
263
|
+
if (freeSpace > 0 && (growCount > 0 || autoMarginCount > 0)) {
|
|
264
|
+
let growExtra = 0;
|
|
265
|
+
let marginExtra = 0;
|
|
266
|
+
|
|
267
|
+
if (growCount > 0) {
|
|
268
|
+
growExtra = freeSpace / growCount;
|
|
269
|
+
freeSpace = 0;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (freeSpace > 0 && autoMarginCount > 0) {
|
|
273
|
+
marginExtra = freeSpace / autoMarginCount;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
let shift = 0;
|
|
277
|
+
for (let { box } of nodes) {
|
|
278
|
+
if (!box) continue;
|
|
279
|
+
switch (instance.direction) {
|
|
280
|
+
case "right":
|
|
281
|
+
box.col += shift;
|
|
282
|
+
if (box.msAuto) {
|
|
283
|
+
box.ms += marginExtra;
|
|
284
|
+
box.col += marginExtra;
|
|
285
|
+
shift += marginExtra;
|
|
286
|
+
}
|
|
287
|
+
if (box.grow) {
|
|
288
|
+
box.width += growExtra;
|
|
289
|
+
shift += growExtra;
|
|
290
|
+
}
|
|
291
|
+
if (box.meAuto) {
|
|
292
|
+
box.me += marginExtra;
|
|
293
|
+
shift += marginExtra;
|
|
294
|
+
}
|
|
295
|
+
break;
|
|
296
|
+
case "left":
|
|
297
|
+
box.col -= shift;
|
|
298
|
+
if (box.msAuto) {
|
|
299
|
+
box.ms += marginExtra;
|
|
300
|
+
box.col -= marginExtra;
|
|
301
|
+
shift += marginExtra;
|
|
302
|
+
}
|
|
303
|
+
if (box.grow) {
|
|
304
|
+
box.width += growExtra;
|
|
305
|
+
box.col -= growExtra;
|
|
306
|
+
shift += growExtra;
|
|
307
|
+
}
|
|
308
|
+
if (box.meAuto) {
|
|
309
|
+
box.me += marginExtra;
|
|
310
|
+
shift += marginExtra;
|
|
311
|
+
}
|
|
312
|
+
break;
|
|
313
|
+
case "down":
|
|
314
|
+
box.row += shift;
|
|
315
|
+
if (box.msAuto) {
|
|
316
|
+
box.ms += marginExtra;
|
|
317
|
+
box.row += marginExtra;
|
|
318
|
+
shift += marginExtra;
|
|
319
|
+
}
|
|
320
|
+
if (box.grow) {
|
|
321
|
+
box.height += growExtra;
|
|
322
|
+
shift += growExtra;
|
|
323
|
+
}
|
|
324
|
+
if (box.meAuto) {
|
|
325
|
+
box.me += marginExtra;
|
|
326
|
+
shift += marginExtra;
|
|
327
|
+
}
|
|
328
|
+
break;
|
|
329
|
+
case "up":
|
|
330
|
+
box.row -= shift;
|
|
331
|
+
if (box.msAuto) {
|
|
332
|
+
box.ms += marginExtra;
|
|
333
|
+
box.row -= marginExtra;
|
|
334
|
+
shift += marginExtra;
|
|
335
|
+
}
|
|
336
|
+
if (box.grow) {
|
|
337
|
+
box.height += growExtra;
|
|
338
|
+
box.row -= growExtra;
|
|
339
|
+
shift += growExtra;
|
|
340
|
+
}
|
|
341
|
+
if (box.meAuto) {
|
|
342
|
+
box.me += marginExtra;
|
|
343
|
+
shift += marginExtra;
|
|
344
|
+
}
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
231
349
|
|
|
232
350
|
let spacing = 0;
|
|
233
351
|
|
package/src/FourSides.tsx
CHANGED
|
@@ -14,12 +14,12 @@ export interface FourSidesConfig extends NodeConfig {
|
|
|
14
14
|
interface FourSidesData {
|
|
15
15
|
gap: number;
|
|
16
16
|
slots: Slot[];
|
|
17
|
-
ml
|
|
18
|
-
mr
|
|
19
|
-
mt
|
|
20
|
-
mb
|
|
21
|
-
ms
|
|
22
|
-
me
|
|
17
|
+
ml: number;
|
|
18
|
+
mr: number;
|
|
19
|
+
mt: number;
|
|
20
|
+
mb: number;
|
|
21
|
+
ms: number;
|
|
22
|
+
me: number;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export interface FourSidesInstance extends NodeInstance {
|
package/src/Node.tsx
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
RenderingContext,
|
|
7
7
|
NumberProp,
|
|
8
8
|
StringProp,
|
|
9
|
+
BooleanProp,
|
|
9
10
|
PureContainerBase,
|
|
10
11
|
} from "cx/ui";
|
|
11
12
|
import { DiagramState } from "./DiagramState";
|
|
@@ -43,20 +44,32 @@ export interface NodeConfig extends PureContainerConfig {
|
|
|
43
44
|
|
|
44
45
|
/** End margin (margin after the element in the direction of the flow). */
|
|
45
46
|
me?: NumberProp;
|
|
47
|
+
|
|
48
|
+
/** If set, the element will grow to fill available space in the flow direction. */
|
|
49
|
+
grow?: BooleanProp;
|
|
50
|
+
|
|
51
|
+
/** If set, the start margin will be automatically calculated to fill available space. */
|
|
52
|
+
msAuto?: BooleanProp;
|
|
53
|
+
|
|
54
|
+
/** If set, the end margin will be automatically calculated to fill available space. */
|
|
55
|
+
meAuto?: BooleanProp;
|
|
46
56
|
}
|
|
47
57
|
|
|
48
58
|
export interface NodeData {
|
|
49
59
|
id?: string;
|
|
50
60
|
margin?: number;
|
|
51
61
|
m?: number;
|
|
52
|
-
ml
|
|
53
|
-
mr
|
|
54
|
-
mt
|
|
55
|
-
mb
|
|
62
|
+
ml: number;
|
|
63
|
+
mr: number;
|
|
64
|
+
mt: number;
|
|
65
|
+
mb: number;
|
|
56
66
|
mx?: number;
|
|
57
67
|
my?: number;
|
|
58
|
-
ms
|
|
59
|
-
me
|
|
68
|
+
ms: number;
|
|
69
|
+
me: number;
|
|
70
|
+
grow?: boolean;
|
|
71
|
+
msAuto?: boolean;
|
|
72
|
+
meAuto?: boolean;
|
|
60
73
|
}
|
|
61
74
|
|
|
62
75
|
export interface Box {
|
|
@@ -64,13 +77,16 @@ export interface Box {
|
|
|
64
77
|
col: number;
|
|
65
78
|
width: number;
|
|
66
79
|
height: number;
|
|
67
|
-
ml
|
|
68
|
-
mr
|
|
69
|
-
mt
|
|
70
|
-
mb
|
|
71
|
-
ms
|
|
72
|
-
me
|
|
80
|
+
ml: number;
|
|
81
|
+
mr: number;
|
|
82
|
+
mt: number;
|
|
83
|
+
mb: number;
|
|
84
|
+
ms: number;
|
|
85
|
+
me: number;
|
|
73
86
|
selfAlign?: string;
|
|
87
|
+
grow?: boolean;
|
|
88
|
+
msAuto?: boolean;
|
|
89
|
+
meAuto?: boolean;
|
|
74
90
|
}
|
|
75
91
|
|
|
76
92
|
export interface NodeInstance extends Instance {
|
|
@@ -110,15 +126,18 @@ export class Node extends PureContainerBase<NodeConfig> {
|
|
|
110
126
|
my: undefined,
|
|
111
127
|
ms: undefined,
|
|
112
128
|
me: undefined,
|
|
129
|
+
grow: undefined,
|
|
130
|
+
msAuto: undefined,
|
|
131
|
+
meAuto: undefined,
|
|
113
132
|
});
|
|
114
133
|
}
|
|
115
134
|
|
|
116
135
|
prepareData(context: RenderingContext, instance: NodeInstance) {
|
|
117
136
|
let { data } = instance;
|
|
118
|
-
data.ml = data.ml ?? data.mx ?? data.m ?? data.margin;
|
|
119
|
-
data.mr = data.mr ?? data.mx ?? data.m ?? data.margin;
|
|
120
|
-
data.mt = data.mt ?? data.my ?? data.m ?? data.margin;
|
|
121
|
-
data.mb = data.mb ?? data.my ?? data.m ?? data.margin;
|
|
137
|
+
data.ml = data.ml ?? data.mx ?? data.m ?? data.margin ?? 0;
|
|
138
|
+
data.mr = data.mr ?? data.mx ?? data.m ?? data.margin ?? 0;
|
|
139
|
+
data.mt = data.mt ?? data.my ?? data.m ?? data.margin ?? 0;
|
|
140
|
+
data.mb = data.mb ?? data.my ?? data.m ?? data.margin ?? 0;
|
|
122
141
|
super.prepareData(context, instance);
|
|
123
142
|
}
|
|
124
143
|
|