@flowgram.ai/renderer 0.1.26 → 0.1.28
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/esm/index.js +131 -65
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +192 -126
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/esm/index.js
CHANGED
|
@@ -1049,32 +1049,49 @@ import {
|
|
|
1049
1049
|
} from "@flowgram.ai/document";
|
|
1050
1050
|
import { Layer as Layer3, observeEntity as observeEntity3, observeEntityDatas as observeEntityDatas3 } from "@flowgram.ai/core";
|
|
1051
1051
|
|
|
1052
|
-
// src/components/
|
|
1052
|
+
// src/components/LinesRenderer.tsx
|
|
1053
|
+
import React7 from "react";
|
|
1054
|
+
import { Rectangle as Rectangle4 } from "@flowgram.ai/utils";
|
|
1055
|
+
import {
|
|
1056
|
+
FlowTransitionLineEnum as FlowTransitionLineEnum2,
|
|
1057
|
+
DefaultSpacingKey as DefaultSpacingKey2
|
|
1058
|
+
} from "@flowgram.ai/document";
|
|
1059
|
+
import { getDefaultSpacing } from "@flowgram.ai/document";
|
|
1060
|
+
|
|
1061
|
+
// src/components/StraightLine.tsx
|
|
1053
1062
|
import React2 from "react";
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
return /* @__PURE__ */ React2.createElement("marker", { id: MARK_ARROW_ID, markerWidth: "11", markerHeight: "14", refX: "10", refY: "7", orient: "auto" }, /* @__PURE__ */ React2.createElement(
|
|
1063
|
+
function StraightLine(props) {
|
|
1064
|
+
const { from, to, activated, style } = props;
|
|
1065
|
+
const { baseColor, baseActivatedColor } = useBaseColor();
|
|
1066
|
+
return /* @__PURE__ */ React2.createElement(
|
|
1059
1067
|
"path",
|
|
1060
1068
|
{
|
|
1061
|
-
|
|
1062
|
-
|
|
1069
|
+
"data-line-id": props.lineId,
|
|
1070
|
+
d: `M ${from.x} ${from.y} L ${to.x} ${to.y}`,
|
|
1071
|
+
...DEFAULT_LINE_ATTRS,
|
|
1072
|
+
stroke: activated ? baseActivatedColor : baseColor,
|
|
1073
|
+
style
|
|
1063
1074
|
}
|
|
1064
|
-
)
|
|
1075
|
+
);
|
|
1065
1076
|
}
|
|
1066
|
-
var
|
|
1077
|
+
var StraightLine_default = StraightLine;
|
|
1067
1078
|
|
|
1068
|
-
// src/components/
|
|
1079
|
+
// src/components/RoundedTurningLine.tsx
|
|
1080
|
+
import React5, { useMemo } from "react";
|
|
1081
|
+
import { isNil as isNil2 } from "lodash";
|
|
1082
|
+
import { Point } from "@flowgram.ai/utils";
|
|
1083
|
+
import { useService as useService2 } from "@flowgram.ai/core";
|
|
1084
|
+
|
|
1085
|
+
// src/components/MarkerArrow.tsx
|
|
1069
1086
|
import React3 from "react";
|
|
1070
|
-
var
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
const { baseActivatedColor } = useBaseColor();
|
|
1087
|
+
var MARK_ARROW_ID = "$marker_arrow$";
|
|
1088
|
+
function MarkerArrow(props) {
|
|
1089
|
+
const { baseColor } = useBaseColor();
|
|
1074
1090
|
return /* @__PURE__ */ React3.createElement(
|
|
1075
1091
|
"marker",
|
|
1076
1092
|
{
|
|
1077
|
-
id:
|
|
1093
|
+
"data-line-id": props.id,
|
|
1094
|
+
id: props.id || MARK_ARROW_ID,
|
|
1078
1095
|
markerWidth: "11",
|
|
1079
1096
|
markerHeight: "14",
|
|
1080
1097
|
refX: "10",
|
|
@@ -1085,43 +1102,54 @@ function MarkerActivatedArrow() {
|
|
|
1085
1102
|
"path",
|
|
1086
1103
|
{
|
|
1087
1104
|
d: "M9.6 5.2C10.8 6.1 10.8 7.9 9.6 8.8L3.6 13.3C2.11672 14.4125 0 13.3541 0 11.5L0 2.5C0 0.645898 2.11672 -0.412461 3.6 0.7L9.6 5.2Z",
|
|
1088
|
-
fill:
|
|
1105
|
+
fill: baseColor
|
|
1089
1106
|
}
|
|
1090
1107
|
)
|
|
1091
1108
|
);
|
|
1092
1109
|
}
|
|
1093
|
-
var
|
|
1094
|
-
|
|
1095
|
-
// src/components/LinesRenderer.tsx
|
|
1096
|
-
import React7 from "react";
|
|
1097
|
-
import { Rectangle as Rectangle4 } from "@flowgram.ai/utils";
|
|
1098
|
-
import {
|
|
1099
|
-
FlowTransitionLineEnum as FlowTransitionLineEnum2,
|
|
1100
|
-
DefaultSpacingKey as DefaultSpacingKey2
|
|
1101
|
-
} from "@flowgram.ai/document";
|
|
1102
|
-
import { getDefaultSpacing } from "@flowgram.ai/document";
|
|
1110
|
+
var MarkerArrow_default = MarkerArrow;
|
|
1103
1111
|
|
|
1104
|
-
// src/components/
|
|
1112
|
+
// src/components/MarkerActivatedArrow.tsx
|
|
1105
1113
|
import React4 from "react";
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
const {
|
|
1114
|
+
var MARK_ACTIVATED_ARROW_ID = "$marker_arrow_activated$";
|
|
1115
|
+
function MarkerActivatedArrow(props) {
|
|
1116
|
+
const { baseActivatedColor } = useBaseColor();
|
|
1109
1117
|
return /* @__PURE__ */ React4.createElement(
|
|
1110
|
-
"
|
|
1118
|
+
"marker",
|
|
1111
1119
|
{
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1120
|
+
"data-line-id": props.id,
|
|
1121
|
+
id: props.id || MARK_ACTIVATED_ARROW_ID,
|
|
1122
|
+
markerWidth: "11",
|
|
1123
|
+
markerHeight: "14",
|
|
1124
|
+
refX: "10",
|
|
1125
|
+
refY: "7",
|
|
1126
|
+
orient: "auto"
|
|
1127
|
+
},
|
|
1128
|
+
/* @__PURE__ */ React4.createElement(
|
|
1129
|
+
"path",
|
|
1130
|
+
{
|
|
1131
|
+
d: "M9.6 5.2C10.8 6.1 10.8 7.9 9.6 8.8L3.6 13.3C2.11672 14.4125 0 13.3541 0 11.5L0 2.5C0 0.645898 2.11672 -0.412461 3.6 0.7L9.6 5.2Z",
|
|
1132
|
+
fill: baseActivatedColor
|
|
1133
|
+
}
|
|
1134
|
+
)
|
|
1117
1135
|
);
|
|
1118
1136
|
}
|
|
1119
|
-
var
|
|
1137
|
+
var MarkerActivatedArrow_default = MarkerActivatedArrow;
|
|
1120
1138
|
|
|
1121
1139
|
// src/components/RoundedTurningLine.tsx
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1140
|
+
function MarkerDefs(props) {
|
|
1141
|
+
const renderRegistry = useService2(FlowRendererRegistry);
|
|
1142
|
+
const ArrowRenderer = renderRegistry?.tryToGetRendererComponent(
|
|
1143
|
+
props.activated ? "marker-active-arrow" /* MARKER_ACTIVATE_ARROW */ : "marker-arrow" /* MARKER_ARROW */
|
|
1144
|
+
);
|
|
1145
|
+
if (ArrowRenderer) {
|
|
1146
|
+
return /* @__PURE__ */ React5.createElement(ArrowRenderer.renderer, { ...props });
|
|
1147
|
+
}
|
|
1148
|
+
if (props.activated) {
|
|
1149
|
+
return /* @__PURE__ */ React5.createElement("defs", null, /* @__PURE__ */ React5.createElement(MarkerActivatedArrow_default, { id: props.id }));
|
|
1150
|
+
}
|
|
1151
|
+
return /* @__PURE__ */ React5.createElement("defs", null, /* @__PURE__ */ React5.createElement(MarkerArrow_default, { id: props.id }));
|
|
1152
|
+
}
|
|
1125
1153
|
function RoundedTurningLine(props) {
|
|
1126
1154
|
const { vertices, radius = DEFAULT_RADIUS, hide, xRadius, yRadius, ...line } = props;
|
|
1127
1155
|
const { from, to, arrow, activated, style } = line || {};
|
|
@@ -1171,18 +1199,20 @@ function RoundedTurningLine(props) {
|
|
|
1171
1199
|
return null;
|
|
1172
1200
|
}
|
|
1173
1201
|
const pathStr = `M ${from.x} ${from.y} ${middleStr} L ${to.x} ${to.y}`;
|
|
1174
|
-
|
|
1202
|
+
const markerId = activated ? `${MARK_ACTIVATED_ARROW_ID}${props.lineId}` : `${MARK_ARROW_ID}${props.lineId}`;
|
|
1203
|
+
return /* @__PURE__ */ React5.createElement(React5.Fragment, null, arrow ? /* @__PURE__ */ React5.createElement(MarkerDefs, { id: markerId, activated }) : null, /* @__PURE__ */ React5.createElement(
|
|
1175
1204
|
"path",
|
|
1176
1205
|
{
|
|
1206
|
+
"data-line-id": props.lineId,
|
|
1177
1207
|
d: pathStr,
|
|
1178
1208
|
...DEFAULT_LINE_ATTRS,
|
|
1179
1209
|
stroke: activated ? baseActivatedColor : baseColor,
|
|
1180
1210
|
...arrow ? {
|
|
1181
|
-
markerEnd:
|
|
1211
|
+
markerEnd: `url(#${markerId})`
|
|
1182
1212
|
} : {},
|
|
1183
1213
|
style
|
|
1184
1214
|
}
|
|
1185
|
-
);
|
|
1215
|
+
));
|
|
1186
1216
|
}
|
|
1187
1217
|
var RoundedTurningLine_default = RoundedTurningLine;
|
|
1188
1218
|
|
|
@@ -1198,7 +1228,7 @@ function CustomLine(props) {
|
|
|
1198
1228
|
return /* @__PURE__ */ React6.createElement(React6.Fragment, null);
|
|
1199
1229
|
}
|
|
1200
1230
|
const Component = renderer.renderer;
|
|
1201
|
-
return /* @__PURE__ */ React6.createElement(Component, { ...line });
|
|
1231
|
+
return /* @__PURE__ */ React6.createElement(Component, { lineId: props.lineId, ...line });
|
|
1202
1232
|
}
|
|
1203
1233
|
var CustomLine_default = CustomLine;
|
|
1204
1234
|
|
|
@@ -1216,7 +1246,15 @@ function createLines(props) {
|
|
|
1216
1246
|
const draggingLineActivated = line.type === FlowTransitionLineEnum2.DRAGGING_LINE && data.entity?.id === dragService.dropNodeId && line.side === dragService.labelSide;
|
|
1217
1247
|
switch (line.type) {
|
|
1218
1248
|
case FlowTransitionLineEnum2.STRAIGHT_LINE:
|
|
1219
|
-
return /* @__PURE__ */ React7.createElement(
|
|
1249
|
+
return /* @__PURE__ */ React7.createElement(
|
|
1250
|
+
StraightLine_default,
|
|
1251
|
+
{
|
|
1252
|
+
key: `${data.entity.id}_${index}`,
|
|
1253
|
+
lineId: data.entity.id,
|
|
1254
|
+
activated: lineActivated,
|
|
1255
|
+
...line
|
|
1256
|
+
}
|
|
1257
|
+
);
|
|
1220
1258
|
case FlowTransitionLineEnum2.DIVERGE_LINE:
|
|
1221
1259
|
case FlowTransitionLineEnum2.DRAGGING_LINE:
|
|
1222
1260
|
case FlowTransitionLineEnum2.MERGE_LINE:
|
|
@@ -1224,7 +1262,8 @@ function createLines(props) {
|
|
|
1224
1262
|
return /* @__PURE__ */ React7.createElement(
|
|
1225
1263
|
RoundedTurningLine_default,
|
|
1226
1264
|
{
|
|
1227
|
-
key: `${data.entity.id}${index}`,
|
|
1265
|
+
key: `${data.entity.id}_${index}`,
|
|
1266
|
+
lineId: data.entity.id,
|
|
1228
1267
|
isHorizontal: !isVertical,
|
|
1229
1268
|
activated: lineActivated || draggingLineActivated,
|
|
1230
1269
|
...line,
|
|
@@ -1237,7 +1276,8 @@ function createLines(props) {
|
|
|
1237
1276
|
return /* @__PURE__ */ React7.createElement(
|
|
1238
1277
|
CustomLine_default,
|
|
1239
1278
|
{
|
|
1240
|
-
key: `${data.entity.id}${index}`,
|
|
1279
|
+
key: `${data.entity.id}_${index}`,
|
|
1280
|
+
lineId: data.entity.id,
|
|
1241
1281
|
...line,
|
|
1242
1282
|
rendererRegistry
|
|
1243
1283
|
}
|
|
@@ -1301,14 +1341,6 @@ var FlowLinesLayer = class extends Layer3 {
|
|
|
1301
1341
|
(line) => line.props.activated ? "activateLines" : "normalLines"
|
|
1302
1342
|
);
|
|
1303
1343
|
const resultLines = [...normalLines, ...activateLines];
|
|
1304
|
-
const arrowRenderer = this.rendererRegistry.tryToGetRendererComponent(
|
|
1305
|
-
"marker-arrow" /* MARKER_ARROW */
|
|
1306
|
-
);
|
|
1307
|
-
const activateArrowRenderer = this.rendererRegistry.tryToGetRendererComponent(
|
|
1308
|
-
"marker-active-arrow" /* MARKER_ACTIVATE_ARROW */
|
|
1309
|
-
);
|
|
1310
|
-
const arrow = arrowRenderer ? React8.createElement(arrowRenderer.renderer) : null;
|
|
1311
|
-
const activateArrow = activateArrowRenderer ? React8.createElement(activateArrowRenderer.renderer) : null;
|
|
1312
1344
|
return /* @__PURE__ */ React8.createElement(
|
|
1313
1345
|
"svg",
|
|
1314
1346
|
{
|
|
@@ -1319,7 +1351,6 @@ var FlowLinesLayer = class extends Layer3 {
|
|
|
1319
1351
|
viewBox: this.viewBox,
|
|
1320
1352
|
xmlns: "http://www.w3.org/2000/svg"
|
|
1321
1353
|
},
|
|
1322
|
-
/* @__PURE__ */ React8.createElement("defs", null, arrowRenderer ? arrow : /* @__PURE__ */ React8.createElement(MarkerArrow_default, null), activateArrow ? activateArrow : /* @__PURE__ */ React8.createElement(MarkerActivatedArrow_default, null)),
|
|
1323
1354
|
resultLines
|
|
1324
1355
|
);
|
|
1325
1356
|
}
|
|
@@ -1435,7 +1466,7 @@ import React10, { useCallback as useCallback2, useState as useState2 } from "rea
|
|
|
1435
1466
|
import {
|
|
1436
1467
|
FlowDragService as FlowDragService3
|
|
1437
1468
|
} from "@flowgram.ai/document";
|
|
1438
|
-
import { useService as
|
|
1469
|
+
import { useService as useService3 } from "@flowgram.ai/core";
|
|
1439
1470
|
var getFlowRenderKey = (node, { dragService }) => {
|
|
1440
1471
|
if (dragService && dragService.dragging && dragService.isDroppableNode(node)) {
|
|
1441
1472
|
if (dragService.dropNodeId === node.id) {
|
|
@@ -1457,7 +1488,7 @@ function Adder(props) {
|
|
|
1457
1488
|
const handleMouseEnter = useCallback2(() => setHoverActivated(true), []);
|
|
1458
1489
|
const handleMouseLeave = useCallback2(() => setHoverActivated(false), []);
|
|
1459
1490
|
const node = data.entity;
|
|
1460
|
-
const dragService =
|
|
1491
|
+
const dragService = useService3(FlowDragService3);
|
|
1461
1492
|
const flowRenderKey = getFlowRenderKey(node, { dragService });
|
|
1462
1493
|
const adder = rendererRegistry.getRendererComponent(flowRenderKey);
|
|
1463
1494
|
const from = node;
|
|
@@ -1567,7 +1598,7 @@ import React12 from "react";
|
|
|
1567
1598
|
import {
|
|
1568
1599
|
FlowDragService as FlowDragService4
|
|
1569
1600
|
} from "@flowgram.ai/document";
|
|
1570
|
-
import { useService as
|
|
1601
|
+
import { useService as useService4 } from "@flowgram.ai/core";
|
|
1571
1602
|
var getFlowRenderKey2 = (node, { dragService, side }) => {
|
|
1572
1603
|
if (dragService.isDragBranch && side && dragService.labelSide === side && dragService.isDroppableBranch(node, side)) {
|
|
1573
1604
|
if (dragService.dropNodeId === node.id) {
|
|
@@ -1580,7 +1611,7 @@ var getFlowRenderKey2 = (node, { dragService, side }) => {
|
|
|
1580
1611
|
function BranchDraggableRenderer(props) {
|
|
1581
1612
|
const { data, rendererRegistry, side, ...restProps } = props;
|
|
1582
1613
|
const node = data.entity;
|
|
1583
|
-
const dragService =
|
|
1614
|
+
const dragService = useService4(FlowDragService4);
|
|
1584
1615
|
const flowRenderKey = getFlowRenderKey2(node, { side, dragService });
|
|
1585
1616
|
if (!flowRenderKey) {
|
|
1586
1617
|
return null;
|
|
@@ -1632,16 +1663,48 @@ function createLabels(labelProps) {
|
|
|
1632
1663
|
let child = null;
|
|
1633
1664
|
switch (type) {
|
|
1634
1665
|
case FlowTransitionLabelEnum2.BRANCH_DRAGGING_LABEL:
|
|
1635
|
-
child = /* @__PURE__ */ React13.createElement(
|
|
1666
|
+
child = /* @__PURE__ */ React13.createElement(
|
|
1667
|
+
BranchDraggableRenderer,
|
|
1668
|
+
{
|
|
1669
|
+
labelId: label.labelId || labelProps.data.entity.id,
|
|
1670
|
+
rendererRegistry,
|
|
1671
|
+
data,
|
|
1672
|
+
...props
|
|
1673
|
+
}
|
|
1674
|
+
);
|
|
1636
1675
|
break;
|
|
1637
1676
|
case FlowTransitionLabelEnum2.ADDER_LABEL:
|
|
1638
|
-
child = /* @__PURE__ */ React13.createElement(
|
|
1677
|
+
child = /* @__PURE__ */ React13.createElement(
|
|
1678
|
+
Adder,
|
|
1679
|
+
{
|
|
1680
|
+
labelId: label.labelId || labelProps.data.entity.id,
|
|
1681
|
+
rendererRegistry,
|
|
1682
|
+
data,
|
|
1683
|
+
...props
|
|
1684
|
+
}
|
|
1685
|
+
);
|
|
1639
1686
|
break;
|
|
1640
1687
|
case FlowTransitionLabelEnum2.COLLAPSE_LABEL:
|
|
1641
|
-
child = /* @__PURE__ */ React13.createElement(
|
|
1688
|
+
child = /* @__PURE__ */ React13.createElement(
|
|
1689
|
+
Collapse,
|
|
1690
|
+
{
|
|
1691
|
+
labelId: label.labelId || labelProps.data.entity.id,
|
|
1692
|
+
rendererRegistry,
|
|
1693
|
+
data,
|
|
1694
|
+
...props
|
|
1695
|
+
}
|
|
1696
|
+
);
|
|
1642
1697
|
break;
|
|
1643
1698
|
case FlowTransitionLabelEnum2.COLLAPSE_ADDER_LABEL:
|
|
1644
|
-
child = /* @__PURE__ */ React13.createElement(
|
|
1699
|
+
child = /* @__PURE__ */ React13.createElement(
|
|
1700
|
+
CollapseAdder,
|
|
1701
|
+
{
|
|
1702
|
+
labelId: label.labelId || labelProps.data.entity.id,
|
|
1703
|
+
rendererRegistry,
|
|
1704
|
+
data,
|
|
1705
|
+
...props
|
|
1706
|
+
}
|
|
1707
|
+
);
|
|
1645
1708
|
break;
|
|
1646
1709
|
case FlowTransitionLabelEnum2.TEXT_LABEL:
|
|
1647
1710
|
if (!renderKey) {
|
|
@@ -1651,6 +1714,7 @@ function createLabels(labelProps) {
|
|
|
1651
1714
|
child = /* @__PURE__ */ React13.createElement(
|
|
1652
1715
|
"div",
|
|
1653
1716
|
{
|
|
1717
|
+
"data-label-id": label.labelId || labelProps.data.entity.id,
|
|
1654
1718
|
style: {
|
|
1655
1719
|
...TEXT_LABEL_STYLE,
|
|
1656
1720
|
...props?.style,
|
|
@@ -1671,6 +1735,7 @@ function createLabels(labelProps) {
|
|
|
1671
1735
|
renderer.renderer,
|
|
1672
1736
|
{
|
|
1673
1737
|
node: data.entity,
|
|
1738
|
+
labelId: label.labelId || labelProps.data.entity.id,
|
|
1674
1739
|
...props
|
|
1675
1740
|
}
|
|
1676
1741
|
);
|
|
@@ -1686,6 +1751,7 @@ function createLabels(labelProps) {
|
|
|
1686
1751
|
"div",
|
|
1687
1752
|
{
|
|
1688
1753
|
key: `${data.entity.id}${index}`,
|
|
1754
|
+
"data-label-id": label.labelId || labelProps.data.entity.id,
|
|
1689
1755
|
style: {
|
|
1690
1756
|
position: "absolute",
|
|
1691
1757
|
left: offsetX,
|