@rotorsoft/act-diagram 0.1.3 → 0.2.1
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/README.md +2 -2
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/client/components/ActDiagram.d.ts.map +1 -1
- package/dist/@types/client/lib/layout.d.ts.map +1 -1
- package/dist/@types/client/lib/mock-builders.d.ts.map +1 -1
- package/dist/index.cjs +65 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +69 -67
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/client/components/ActDiagram.tsx
|
|
2
|
-
import { useCallback as useCallback2, useEffect as useEffect2,
|
|
2
|
+
import { useCallback as useCallback2, useEffect as useEffect2, useRef as useRef2, useState as useState3 } from "react";
|
|
3
3
|
|
|
4
4
|
// src/client/lib/evaluate.ts
|
|
5
5
|
import { transform } from "sucrase";
|
|
@@ -377,7 +377,10 @@ function captureDispatches(handler) {
|
|
|
377
377
|
if (typeof actionName === "string" && !dispatches.includes(actionName))
|
|
378
378
|
dispatches.push(actionName);
|
|
379
379
|
return Promise.resolve([]);
|
|
380
|
-
}
|
|
380
|
+
},
|
|
381
|
+
load: () => Promise.resolve({}),
|
|
382
|
+
query: () => Promise.resolve({ count: 0 }),
|
|
383
|
+
query_array: () => Promise.resolve([])
|
|
381
384
|
};
|
|
382
385
|
const mockEvent = new Proxy({}, {
|
|
383
386
|
get: (_, prop) => prop === "stream" ? "mock" : prop === "data" ? new Proxy({}, { get: () => "" }) : ""
|
|
@@ -1245,7 +1248,9 @@ function placeChain(measure, rDef, reactionY, rX, triggeredFromX, triggeredFromY
|
|
|
1245
1248
|
nextX += STATE_W + GAP;
|
|
1246
1249
|
}
|
|
1247
1250
|
const evtX = nextX;
|
|
1248
|
-
|
|
1251
|
+
const nEvents = row.emitInfos.length;
|
|
1252
|
+
const eventsOnlyH = nEvents * H + (nEvents - 1) * (GAP / 2);
|
|
1253
|
+
let emitY = rowCenterY - eventsOnlyH / 2;
|
|
1249
1254
|
for (const emit of row.emitInfos) {
|
|
1250
1255
|
ns.push({
|
|
1251
1256
|
key: `e:${emit.name}:dispatched:${rDef.handlerName}:${row.an}`,
|
|
@@ -1275,7 +1280,7 @@ function placeChain(measure, rDef, reactionY, rX, triggeredFromX, triggeredFromY
|
|
|
1275
1280
|
sliceRightXRef
|
|
1276
1281
|
);
|
|
1277
1282
|
}
|
|
1278
|
-
emitY +=
|
|
1283
|
+
emitY += H + GAP / 2;
|
|
1279
1284
|
}
|
|
1280
1285
|
if (row.emitInfos.length > 0) nextX = evtX + W + GAP;
|
|
1281
1286
|
sliceRightXRef.value = Math.max(sliceRightXRef.value, nextX);
|
|
@@ -1407,28 +1412,27 @@ function computeLayout(viewModel) {
|
|
|
1407
1412
|
const measuredEvents = [];
|
|
1408
1413
|
let evtBlockH = 0;
|
|
1409
1414
|
for (const { eventName: en, actionName } of eventRows) {
|
|
1410
|
-
const
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1415
|
+
const chains = [];
|
|
1416
|
+
if (!visitedEvents.has(en)) {
|
|
1417
|
+
const rDefs = sliceReactionsByEvent.get(en) ?? [];
|
|
1418
|
+
for (const rDef of rDefs) {
|
|
1419
|
+
if (visitedReactions.has(rDef.handlerName)) continue;
|
|
1420
|
+
visitedReactions.add(rDef.handlerName);
|
|
1421
|
+
const chain = measureChain(
|
|
1422
|
+
rDef,
|
|
1423
|
+
sliceReactionByEvent,
|
|
1424
|
+
visitedReactions,
|
|
1425
|
+
viewModel.states
|
|
1426
|
+
);
|
|
1427
|
+
chains.push({ chain, reaction: rDef });
|
|
1428
|
+
}
|
|
1429
|
+
if (rDefs.length > 0) visitedEvents.add(en);
|
|
1425
1430
|
}
|
|
1426
1431
|
measuredEvents.push({
|
|
1427
1432
|
eventName: en,
|
|
1428
1433
|
actionName,
|
|
1429
|
-
h:
|
|
1430
|
-
|
|
1431
|
-
chainReaction
|
|
1434
|
+
h: H,
|
|
1435
|
+
chains
|
|
1432
1436
|
});
|
|
1433
1437
|
if (evtBlockH > 0) evtBlockH += GAP / 2;
|
|
1434
1438
|
evtBlockH += H;
|
|
@@ -1450,12 +1454,7 @@ function computeLayout(viewModel) {
|
|
|
1450
1454
|
let chainWatermark = -Infinity;
|
|
1451
1455
|
const eventYMap = /* @__PURE__ */ new Map();
|
|
1452
1456
|
for (let ei = 0; ei < measuredEvents.length; ei++) {
|
|
1453
|
-
const {
|
|
1454
|
-
eventName: en,
|
|
1455
|
-
actionName,
|
|
1456
|
-
chain,
|
|
1457
|
-
chainReaction
|
|
1458
|
-
} = measuredEvents[ei];
|
|
1457
|
+
const { eventName: en, actionName, chains } = measuredEvents[ei];
|
|
1459
1458
|
ns.push({
|
|
1460
1459
|
key: `e:${en}:${slice.name}:${actionName}`,
|
|
1461
1460
|
pos: { x: eventColX, y: evtY },
|
|
@@ -1466,7 +1465,7 @@ function computeLayout(viewModel) {
|
|
|
1466
1465
|
reactions: eventReactions.get(en)
|
|
1467
1466
|
});
|
|
1468
1467
|
eventYMap.set(en, evtY);
|
|
1469
|
-
|
|
1468
|
+
for (const { chain, reaction: chainReaction } of chains) {
|
|
1470
1469
|
const rX = eventColX + W + GAP * 3;
|
|
1471
1470
|
const minReactionY = chainWatermark + chain.dispatchBlockH / 2 - H / 2;
|
|
1472
1471
|
const reactionY = Math.max(evtY, minReactionY);
|
|
@@ -1548,33 +1547,18 @@ function computeLayout(viewModel) {
|
|
|
1548
1547
|
y += primaryBlockH + GAP / 2;
|
|
1549
1548
|
partIdx++;
|
|
1550
1549
|
}
|
|
1551
|
-
const remainingYByEvent = /* @__PURE__ */ new Map();
|
|
1552
1550
|
for (const r of slice.reactions) {
|
|
1553
1551
|
if (r.isVoid || visitedReactions.has(r.handlerName)) continue;
|
|
1554
|
-
const trigNode = ns.find(
|
|
1555
|
-
(n) => n.type === "event" && n.label === r.event && n.key.includes(slice.name)
|
|
1556
|
-
);
|
|
1557
|
-
const baseY = trigNode ? trigNode.pos.y : y;
|
|
1558
|
-
const rY = remainingYByEvent.get(r.event) ?? baseY;
|
|
1559
1552
|
const rX = sliceRightX + GAP * 2;
|
|
1560
|
-
const rp = { x: rX, y
|
|
1553
|
+
const rp = { x: rX, y };
|
|
1561
1554
|
ns.push({
|
|
1562
1555
|
key: `r:${r.handlerName}:${slice.name}`,
|
|
1563
1556
|
pos: rp,
|
|
1564
1557
|
type: "reaction",
|
|
1565
1558
|
label: r.handlerName
|
|
1566
1559
|
});
|
|
1567
|
-
if (trigNode) {
|
|
1568
|
-
es.push({
|
|
1569
|
-
from: { x: trigNode.pos.x + W, y: trigNode.pos.y + H / 2 },
|
|
1570
|
-
to: { x: rp.x, y: rp.y + H / 2 },
|
|
1571
|
-
color: COLORS.reaction.border,
|
|
1572
|
-
dash: true
|
|
1573
|
-
});
|
|
1574
|
-
}
|
|
1575
|
-
remainingYByEvent.set(r.event, rY + H + GAP / 2);
|
|
1576
1560
|
sliceRightX = Math.max(sliceRightX, rX + W + GAP);
|
|
1577
|
-
y
|
|
1561
|
+
y += H + GAP / 2;
|
|
1578
1562
|
}
|
|
1579
1563
|
const bbox = {
|
|
1580
1564
|
minX: Infinity,
|
|
@@ -2537,6 +2521,39 @@ ${prompt}`);
|
|
|
2537
2521
|
|
|
2538
2522
|
// src/client/components/ActDiagram.tsx
|
|
2539
2523
|
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
2524
|
+
var emptyModel = {
|
|
2525
|
+
entries: [],
|
|
2526
|
+
states: [],
|
|
2527
|
+
slices: [],
|
|
2528
|
+
projections: [],
|
|
2529
|
+
reactions: []
|
|
2530
|
+
};
|
|
2531
|
+
function useExtractModel(files) {
|
|
2532
|
+
const [result, setResult] = useState3({ model: emptyModel, warnings: [] });
|
|
2533
|
+
const lastGoodRef = useRef2(null);
|
|
2534
|
+
useEffect2(() => {
|
|
2535
|
+
if (files.length === 0) {
|
|
2536
|
+
lastGoodRef.current = null;
|
|
2537
|
+
setResult({ model: emptyModel, warnings: [] });
|
|
2538
|
+
return;
|
|
2539
|
+
}
|
|
2540
|
+
const timer = setTimeout(() => {
|
|
2541
|
+
const { model, error } = extractModel(files);
|
|
2542
|
+
const warnings = validate(model);
|
|
2543
|
+
const hasErrors = !!error || model.slices.some((s) => !!s.error);
|
|
2544
|
+
if (!hasErrors) {
|
|
2545
|
+
const next = { model, warnings };
|
|
2546
|
+
lastGoodRef.current = next;
|
|
2547
|
+
setResult(next);
|
|
2548
|
+
} else if (lastGoodRef.current) {
|
|
2549
|
+
} else {
|
|
2550
|
+
setResult({ model, warnings });
|
|
2551
|
+
}
|
|
2552
|
+
}, 500);
|
|
2553
|
+
return () => clearTimeout(timer);
|
|
2554
|
+
}, [files]);
|
|
2555
|
+
return result;
|
|
2556
|
+
}
|
|
2540
2557
|
function ActDiagram({
|
|
2541
2558
|
files: propFiles,
|
|
2542
2559
|
onNavigate,
|
|
@@ -2578,22 +2595,7 @@ function ActDiagram({
|
|
|
2578
2595
|
window.addEventListener("message", handler);
|
|
2579
2596
|
return () => window.removeEventListener("message", handler);
|
|
2580
2597
|
}, [usePostMessage]);
|
|
2581
|
-
const { model, warnings } =
|
|
2582
|
-
if (files.length === 0)
|
|
2583
|
-
return {
|
|
2584
|
-
model: {
|
|
2585
|
-
entries: [],
|
|
2586
|
-
states: [],
|
|
2587
|
-
slices: [],
|
|
2588
|
-
projections: [],
|
|
2589
|
-
reactions: []
|
|
2590
|
-
},
|
|
2591
|
-
warnings: []
|
|
2592
|
-
};
|
|
2593
|
-
const { model: model2 } = extractModel(files);
|
|
2594
|
-
const warnings2 = validate(model2);
|
|
2595
|
-
return { model: model2, warnings: warnings2 };
|
|
2596
|
-
}, [files]);
|
|
2598
|
+
const { model, warnings } = useExtractModel(files);
|
|
2597
2599
|
const handleClick = useCallback2(
|
|
2598
2600
|
(name, type, file) => {
|
|
2599
2601
|
if (!onNavigate) return;
|
|
@@ -2713,7 +2715,7 @@ function Logo({ size = 24 }) {
|
|
|
2713
2715
|
}
|
|
2714
2716
|
|
|
2715
2717
|
// src/client/components/Tooltip.tsx
|
|
2716
|
-
import { useCallback as useCallback3, useRef as
|
|
2718
|
+
import { useCallback as useCallback3, useRef as useRef3, useState as useState4 } from "react";
|
|
2717
2719
|
import { createPortal } from "react-dom";
|
|
2718
2720
|
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
2719
2721
|
function Tooltip({
|
|
@@ -2726,8 +2728,8 @@ function Tooltip({
|
|
|
2726
2728
|
}) {
|
|
2727
2729
|
const [show, setShow] = useState4(false);
|
|
2728
2730
|
const [coords, setCoords] = useState4({ x: 0, y: 0, w: 0 });
|
|
2729
|
-
const timeout =
|
|
2730
|
-
const ref =
|
|
2731
|
+
const timeout = useRef3(void 0);
|
|
2732
|
+
const ref = useRef3(null);
|
|
2731
2733
|
const onEnter = useCallback3(() => {
|
|
2732
2734
|
timeout.current = setTimeout(() => {
|
|
2733
2735
|
if (ref.current) {
|
|
@@ -2836,7 +2838,7 @@ function deriveProjectName(prompt, code) {
|
|
|
2836
2838
|
}
|
|
2837
2839
|
|
|
2838
2840
|
// src/client/types/domain-model.ts
|
|
2839
|
-
function
|
|
2841
|
+
function emptyModel2() {
|
|
2840
2842
|
return {
|
|
2841
2843
|
entries: [],
|
|
2842
2844
|
states: [],
|
|
@@ -2855,7 +2857,7 @@ export {
|
|
|
2855
2857
|
buildModel,
|
|
2856
2858
|
computeLayout,
|
|
2857
2859
|
deriveProjectName,
|
|
2858
|
-
emptyModel,
|
|
2860
|
+
emptyModel2 as emptyModel,
|
|
2859
2861
|
extractModel,
|
|
2860
2862
|
navigateToCode,
|
|
2861
2863
|
parseMultiFileResponse,
|