@typeonce/effect-machine-devtools 0.27.0 → 0.27.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.
@@ -340,6 +340,7 @@ const render = (
340
340
  const transitionElements = new Map<string, Array<Element>>()
341
341
  const edgeElements = new Map<string, Array<Element>>()
342
342
  const transitionControls = new Map<string, Array<HTMLButtonElement>>()
343
+ const parentByState = new Map(layout.nodes.map(({ node }) => [node.path, node.parent]))
343
344
  const chartEdges = new Map(
344
345
  layout.edges.flatMap((laidOut) => laidOut.kind === "transition" ? [[laidOut.edge.id, laidOut.edge] as const] : [])
345
346
  )
@@ -429,13 +430,15 @@ const render = (
429
430
  }
430
431
 
431
432
  for (const laidOut of layout.edges) {
433
+ const parentChild = laidOut.kind === "transition" && laidOut.edge.target !== null &&
434
+ parentByState.get(laidOut.edge.target) === laidOut.edge.source
432
435
  const group = svgElement(
433
436
  "g",
434
437
  `chart-edge-group chart-edge-${laidOut.kind}${
435
438
  laidOut.kind === "transition"
436
439
  ? ` chart-transition-${laidOut.edge.kind} chart-edge-trigger-${laidOut.edge.trigger.type}${
437
440
  laidOut.edge.activityKind === null ? "" : ` chart-edge-activity-${laidOut.edge.activityKind}`
438
- }`
441
+ }${parentChild ? " chart-edge-parent-child" : ""}`
439
442
  : ""
440
443
  }`
441
444
  )
@@ -448,6 +451,16 @@ const render = (
448
451
  const hit = svgElement("path", "chart-edge-hit")
449
452
  hit.setAttribute("d", route)
450
453
  group.append(casing, visible)
454
+ if (parentChild) {
455
+ const origin = laidOut.points[0]
456
+ if (origin !== undefined) {
457
+ const sourceAnchor = svgElement("circle", "chart-edge-parent-origin")
458
+ sourceAnchor.setAttribute("cx", String(origin.x))
459
+ sourceAnchor.setAttribute("cy", String(origin.y))
460
+ sourceAnchor.setAttribute("r", "4")
461
+ group.append(sourceAnchor)
462
+ }
463
+ }
451
464
  if (laidOut.kind === "transition") {
452
465
  const cue = chartDirectionCue(laidOut.points)
453
466
  if (cue !== null) {
@@ -467,10 +480,11 @@ const render = (
467
480
  "button",
468
481
  `chart-edge-label chart-edge-label-${laidOut.edge.trigger.type}${
469
482
  laidOut.edge.activityKind === null ? "" : ` chart-edge-activity-${laidOut.edge.activityKind}`
470
- }`,
483
+ }${parentChild ? " chart-edge-label-parent-child" : ""}`,
471
484
  laidOut.edge.label
472
485
  )
473
486
  label.type = "button"
487
+ if (parentChild) label.title = "Transition declared by the parent state"
474
488
  label.dataset.transitionId = laidOut.edge.transitionId
475
489
  position(label, {
476
490
  x: laidOut.label.x - laidOut.labelWidth / 2,
@@ -0,0 +1,91 @@
1
+ import { Machine } from "@typeonce/effect-machine"
2
+ import { Effect, Schema } from "effect"
3
+
4
+ const ReviewState = Schema.TaggedUnion({
5
+ Review: { title: Schema.String },
6
+ ReviewFailed: { message: Schema.String },
7
+ Complete: { slug: Schema.String }
8
+ })
9
+
10
+ const ReviewStates = Machine.states({
11
+ Workflow: {
12
+ initial: "Review",
13
+ states: {
14
+ Review: {
15
+ schema: ReviewState.cases.Review,
16
+ initial: "Form",
17
+ states: {
18
+ Form: {},
19
+ Failed: ReviewState.cases.ReviewFailed
20
+ }
21
+ },
22
+ Saving: {},
23
+ Publishing: {},
24
+ Complete: ReviewState.cases.Complete
25
+ }
26
+ }
27
+ })
28
+
29
+ const ReviewEvents = Machine.events(
30
+ Schema.TaggedUnion({
31
+ Submit: { route: Schema.Literals(["save", "invalid"]) }
32
+ })
33
+ )
34
+
35
+ const saveReview: Effect.Effect<string, string> = Effect.succeed("deterministic-chart")
36
+ const publishReview = Effect.succeed("deterministic-chart")
37
+
38
+ export const hierarchyRoutingMachine = Machine.make({
39
+ id: "hierarchy-routing",
40
+ states: ReviewStates.states,
41
+ events: ReviewEvents,
42
+ initial: (to) =>
43
+ to.Workflow.initial.resolve(({ target }) =>
44
+ target.from((workflow) =>
45
+ workflow.Review.from({ title: "A deterministic chart" }, (review) => review.Form.from())
46
+ )
47
+ )
48
+ }).handle({
49
+ Workflow: {
50
+ states: {
51
+ Review: {
52
+ on: {
53
+ Submit: (to) =>
54
+ to.branches({
55
+ save: {
56
+ title: "Save the review",
57
+ target: to.branch.Workflow.Saving()
58
+ },
59
+ invalid: {
60
+ title: "Show validation failure",
61
+ target: to.local.Failed()
62
+ }
63
+ }).resolve(({ event, select }) =>
64
+ event.route === "save"
65
+ ? select.save.from()
66
+ : select.invalid.from({ message: "Add a title before continuing." })
67
+ )
68
+ },
69
+ states: {
70
+ Form: {},
71
+ Failed: {}
72
+ }
73
+ },
74
+ Saving: {
75
+ invoke: (from) =>
76
+ from.effect("save-review", () => saveReview).onDone((to) => to.branch.Workflow.Publishing()).onFailure((to) =>
77
+ to.branch.Workflow.Review.Failed().resolve(({ target }) =>
78
+ target.from({ message: "The review could not be saved." })
79
+ )
80
+ )
81
+ },
82
+ Publishing: {
83
+ invoke: (from) =>
84
+ from.effect("publish-review", () => publishReview).onDone((to) =>
85
+ to.branch.Workflow.Complete().resolve(({ output, target }) => target.from({ slug: output }))
86
+ )
87
+ },
88
+ Complete: {}
89
+ }
90
+ }
91
+ })
@@ -680,6 +680,13 @@ button {
680
680
  fill: none;
681
681
  }
682
682
 
683
+ .chart-edge-parent-origin {
684
+ fill: #101318;
685
+ stroke: #89929e;
686
+ stroke-width: 1.8;
687
+ vector-effect: non-scaling-stroke;
688
+ }
689
+
683
690
  .chart-edge-casing {
684
691
  stroke: #0b0c0e;
685
692
  stroke-width: 5.5;
@@ -729,6 +736,23 @@ button {
729
736
  user-select: none;
730
737
  }
731
738
 
739
+ .chart-edge-group.chart-edge-parent-child .chart-edge-line,
740
+ .chart-edge-group.chart-edge-parent-child .chart-edge-direction,
741
+ .chart-edge-group.chart-edge-parent-child .chart-edge-parent-origin {
742
+ stroke: #9187a7;
743
+ }
744
+
745
+ .chart-edge-group.chart-edge-parent-child .chart-edge-parent-origin {
746
+ fill: #1b1820;
747
+ }
748
+
749
+ .chart-edge-label-parent-child {
750
+ border-color: #4d465a;
751
+ color: #aea5c1;
752
+ background: #17151b;
753
+ box-shadow: inset 2px 0 #6f6681;
754
+ }
755
+
732
756
  .chart-edge-label:not(:disabled):hover,
733
757
  .chart-edge-label:focus-visible,
734
758
  .chart-edge-group.is-hovered + .chart-edge-label {
@@ -744,7 +768,8 @@ button {
744
768
  }
745
769
 
746
770
  .chart-edge-group.is-hovered .chart-edge-line,
747
- .chart-edge-group.is-hovered .chart-edge-direction {
771
+ .chart-edge-group.is-hovered .chart-edge-direction,
772
+ .chart-edge-group.is-hovered .chart-edge-parent-origin {
748
773
  stroke: #7c9ed2;
749
774
  stroke-width: 1.8;
750
775
  }
@@ -774,7 +799,12 @@ button {
774
799
  .chart-edge-group.chart-edge-activity-effect .chart-edge-direction,
775
800
  .chart-edge-group.chart-edge-activity-timer .chart-edge-direction,
776
801
  .chart-edge-group.chart-edge-activity-stream .chart-edge-direction,
777
- .chart-edge-group.chart-edge-activity-machine .chart-edge-direction {
802
+ .chart-edge-group.chart-edge-activity-machine .chart-edge-direction,
803
+ .chart-edge-group.chart-edge-activity-process .chart-edge-parent-origin,
804
+ .chart-edge-group.chart-edge-activity-effect .chart-edge-parent-origin,
805
+ .chart-edge-group.chart-edge-activity-timer .chart-edge-parent-origin,
806
+ .chart-edge-group.chart-edge-activity-stream .chart-edge-parent-origin,
807
+ .chart-edge-group.chart-edge-activity-machine .chart-edge-parent-origin {
778
808
  stroke: var(--chart-activity-color);
779
809
  }
780
810
 
@@ -789,19 +819,22 @@ button {
789
819
  }
790
820
 
791
821
  .chart-edge-group.is-incoming .chart-edge-line,
792
- .chart-edge-group.is-incoming .chart-edge-direction {
822
+ .chart-edge-group.is-incoming .chart-edge-direction,
823
+ .chart-edge-group.is-incoming .chart-edge-parent-origin {
793
824
  stroke: #ed6a70;
794
825
  stroke-width: 2;
795
826
  }
796
827
 
797
828
  .chart-edge-group.is-outgoing .chart-edge-line,
798
- .chart-edge-group.is-outgoing .chart-edge-direction {
829
+ .chart-edge-group.is-outgoing .chart-edge-direction,
830
+ .chart-edge-group.is-outgoing .chart-edge-parent-origin {
799
831
  stroke: #6eb6dc;
800
832
  stroke-width: 2;
801
833
  }
802
834
 
803
835
  .chart-edge-group.is-selected .chart-edge-line,
804
- .chart-edge-group.is-selected .chart-edge-direction {
836
+ .chart-edge-group.is-selected .chart-edge-direction,
837
+ .chart-edge-group.is-selected .chart-edge-parent-origin {
805
838
  stroke: #8ab5ff;
806
839
  stroke-width: 2.5;
807
840
  }