@likec4/diagram 1.57.0 → 1.58.0

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.
Files changed (155) hide show
  1. package/dist/adhoc-editor/EditorPanel.d.ts +1 -1
  2. package/dist/adhoc-editor/ElementsTree.d.ts +1 -1
  3. package/dist/adhoc-editor/LikeC4AdHocViewEditor.d.ts +1 -1
  4. package/dist/adhoc-editor/components/Tree.d.ts +5 -5
  5. package/dist/adhoc-editor/state/ActorProvider.d.ts +1 -1
  6. package/dist/adhoc-editor/state/panel.d.ts +1 -1
  7. package/dist/adhoc-editor/viewrules/ViewRulesPanel.d.ts +1 -1
  8. package/dist/base/BaseXYFlow.d.ts +1 -1
  9. package/dist/base-primitives/Markdown.d.ts +1 -1
  10. package/dist/base-primitives/NodeHandles.d.ts +1 -1
  11. package/dist/base-primitives/compound/CompoundActionButton.d.ts +1 -1
  12. package/dist/base-primitives/compound/CompoundDetailsButton.d.ts +1 -1
  13. package/dist/base-primitives/compound/CompoundNodeContainer.d.ts +1 -1
  14. package/dist/base-primitives/compound/CompoundTitle.d.ts +1 -1
  15. package/dist/base-primitives/compound/actionbtns.css.d.ts +1 -1
  16. package/dist/base-primitives/edge/EdgeActionButton.d.ts +1 -1
  17. package/dist/base-primitives/edge/EdgeContainer.d.ts +1 -1
  18. package/dist/base-primitives/edge/EdgeLabelContainer.d.ts +1 -1
  19. package/dist/base-primitives/edge/EdgeMarkers.d.ts +8 -8
  20. package/dist/base-primitives/element/ElementActionButtons.d.ts +1 -1
  21. package/dist/base-primitives/element/ElementData.d.ts +2 -2
  22. package/dist/base-primitives/element/ElementDetailsButton.d.ts +1 -1
  23. package/dist/base-primitives/element/ElementShape.d.ts +1 -1
  24. package/dist/base-primitives/element/ElementTags.d.ts +1 -1
  25. package/dist/base-primitives/element/ElementTags.js +1 -3
  26. package/dist/components/ErrorFallback.d.ts +2 -2
  27. package/dist/components/NavigationPanel.d.ts +2 -2
  28. package/dist/components/PortalToContainer.d.ts +1 -1
  29. package/dist/components/RootContainer.d.ts +1 -1
  30. package/dist/components/SearchControl.d.ts +2 -2
  31. package/dist/components/ViewNotFound.d.ts +2 -2
  32. package/dist/context/CurrentViewModelProvider.d.ts +1 -1
  33. package/dist/context/DefaultMantineProvider.d.ts +1 -1
  34. package/dist/context/DiagramEventHandlers.d.ts +1 -1
  35. package/dist/context/EnsureMantine.d.ts +1 -1
  36. package/dist/context/FramerMotionConfig.d.ts +3 -3
  37. package/dist/context/FramerMotionConfig.js +2 -2
  38. package/dist/context/IconRenderer.d.ts +2 -2
  39. package/dist/context/IconRenderer.js +32 -12
  40. package/dist/context/LikeC4ModelContext.d.ts +1 -1
  41. package/dist/context/ShadowRootContext.d.ts +3 -0
  42. package/dist/context/ShadowRootContext.js +5 -0
  43. package/dist/context/TagStylesContext.d.ts +2 -1
  44. package/dist/context/TagStylesContext.js +5 -7
  45. package/dist/editor/LikeC4EditorProvider.d.ts +2 -2
  46. package/dist/editor/actor/actions.d.ts +74 -15
  47. package/dist/editor/actor/actions.js +91 -25
  48. package/dist/editor/actor/hotkey.d.ts +1 -1
  49. package/dist/editor/actor/hotkey.js +7 -0
  50. package/dist/editor/actor/machine.d.ts +1 -1
  51. package/dist/editor/actor/machine.js +1 -0
  52. package/dist/editor/actor/setup.d.ts +10 -3
  53. package/dist/editor/actor/setup.js +3 -2
  54. package/dist/editor/actor/state.editor.d.ts +64 -14
  55. package/dist/editor/actor/state.editor.js +12 -11
  56. package/dist/editor/actor/state.sync-queue.d.ts +283 -91
  57. package/dist/editor/actor/state.sync-queue.js +93 -56
  58. package/dist/editor/actor/types.d.ts +6 -1
  59. package/dist/editor/actor/types.js +1 -1
  60. package/dist/editor/useEditorActorLogic.js +14 -2
  61. package/dist/hooks/useEditorActor.d.ts +5 -0
  62. package/dist/hooks/useEditorActor.js +3 -2
  63. package/dist/index.d.ts +2 -0
  64. package/dist/index.js +3 -1
  65. package/dist/likec4diagram/DiagramUI.d.ts +1 -1
  66. package/dist/likec4diagram/DiagramXYFlow.js +15 -3
  67. package/dist/likec4diagram/custom/edges/EdgeDrifts.d.ts +1 -1
  68. package/dist/likec4diagram/custom/edges/RelationshipEdge.js +127 -14
  69. package/dist/likec4diagram/custom/edges/SequenceStepEdge.d.ts +1 -1
  70. package/dist/likec4diagram/custom/edges/edges.css.d.ts +1 -0
  71. package/dist/likec4diagram/custom/edges/edges.css.js +5 -1
  72. package/dist/likec4diagram/custom/nodes/CompoundActions.d.ts +1 -1
  73. package/dist/likec4diagram/custom/nodes/ElementActions.d.ts +2 -2
  74. package/dist/likec4diagram/custom/nodes/NodeDrifts.d.ts +1 -1
  75. package/dist/likec4diagram/custom/nodes/NodeNotes.d.ts +1 -1
  76. package/dist/likec4diagram/custom/nodes/SequenceActorNode.d.ts +2 -2
  77. package/dist/likec4diagram/custom/nodes/nodes.d.ts +7 -7
  78. package/dist/likec4diagram/custom/nodes/toolbar/ColorButton.d.ts +3 -3
  79. package/dist/likec4diagram/custom/nodes/toolbar/CompoundToolbar.d.ts +2 -2
  80. package/dist/likec4diagram/custom/nodes/toolbar/ElementToolbar.d.ts +2 -2
  81. package/dist/likec4diagram/custom/nodes/toolbar/Toolbar.d.ts +1 -1
  82. package/dist/likec4diagram/custom/nodes/toolbar/_shared.d.ts +3 -3
  83. package/dist/likec4diagram/relationship-popover/RelationshipPopover.d.ts +1 -1
  84. package/dist/likec4diagram/relationship-popover/components.d.ts +2 -2
  85. package/dist/likec4diagram/state/DiagramActorProvider.d.ts +1 -1
  86. package/dist/likec4diagram/state/createViewChange.js +1 -0
  87. package/dist/likec4diagram/state/machine.actions.js +3 -2
  88. package/dist/likec4diagram/types.d.ts +2 -0
  89. package/dist/likec4diagram/ui/LayoutDriftFrame.d.ts +1 -1
  90. package/dist/likec4diagram/ui/notation/NotationPanel.d.ts +1 -1
  91. package/dist/likec4diagram/xyflow-diagram/diagram-view.js +4 -2
  92. package/dist/likec4diagram/xyflow-sequence/sequence-layout.js +1 -0
  93. package/dist/navigationpanel/NavigationPanel.d.ts +1 -1
  94. package/dist/navigationpanel/NavigationPanelControls.d.ts +1 -1
  95. package/dist/navigationpanel/NavigationPanelDropdown.d.ts +1 -1
  96. package/dist/navigationpanel/NavigationPanelDropdown.js +2 -2
  97. package/dist/navigationpanel/_common.d.ts +2 -2
  98. package/dist/navigationpanel/comparepanel/CompareActionsMenu.d.ts +1 -1
  99. package/dist/navigationpanel/comparepanel/ComparePanel.d.ts +1 -1
  100. package/dist/navigationpanel/comparepanel/ComparePanelControls.d.ts +1 -1
  101. package/dist/navigationpanel/comparepanel/DriftsSummary.d.ts +1 -1
  102. package/dist/navigationpanel/comparepanel/LayoutTypeSwitcher.d.ts +1 -1
  103. package/dist/navigationpanel/controls/DetailsControls.d.ts +1 -1
  104. package/dist/navigationpanel/controls/LayoutWarning.d.ts +1 -1
  105. package/dist/navigationpanel/controls/LogoButton.d.ts +1 -1
  106. package/dist/navigationpanel/controls/NavigationButtons.d.ts +1 -1
  107. package/dist/navigationpanel/controls/OpenSource.d.ts +1 -1
  108. package/dist/navigationpanel/controls/SearchControl.d.ts +1 -1
  109. package/dist/navigationpanel/controls/ToggleReadonly.d.ts +1 -1
  110. package/dist/navigationpanel/editorpanel/CenterCamera.d.ts +1 -1
  111. package/dist/navigationpanel/editorpanel/ChangeAutoLayoutButton.d.ts +1 -1
  112. package/dist/navigationpanel/editorpanel/EditorPanel.d.ts +1 -1
  113. package/dist/navigationpanel/editorpanel/ManualLayoutToolsButton.d.ts +1 -1
  114. package/dist/navigationpanel/editorpanel/ToggleReadonly.d.ts +1 -1
  115. package/dist/navigationpanel/styles.css.d.ts +1 -1
  116. package/dist/navigationpanel/walkthrough/ActiveWalkthroughControls.d.ts +1 -1
  117. package/dist/navigationpanel/walkthrough/DynamicViewControls.d.ts +1 -1
  118. package/dist/navigationpanel/walkthrough/WalkthroughPanel.d.ts +1 -1
  119. package/dist/overlays/Overlays.d.ts +1 -1
  120. package/dist/overlays/element-details/ElementDetails.d.ts +1 -1
  121. package/dist/overlays/element-details/ElementDetailsCard.d.ts +1 -1
  122. package/dist/overlays/element-details/MetadataValue.d.ts +2 -2
  123. package/dist/overlays/element-details/TabPanelRelationships.d.ts +1 -1
  124. package/dist/overlays/element-details/TabPanelStructure.d.ts +2 -2
  125. package/dist/overlays/relationship-details/RelationshipDetails.d.ts +1 -1
  126. package/dist/overlays/relationship-details/SelectEdge.d.ts +1 -1
  127. package/dist/overlays/relationship-details/custom/ElementActions.d.ts +1 -1
  128. package/dist/overlays/relationship-details/custom/nodeTypes.d.ts +4 -4
  129. package/dist/overlays/relationships-browser/RelationshipsBrowser.d.ts +1 -1
  130. package/dist/overlays/relationships-browser/SelectElement.d.ts +1 -1
  131. package/dist/overlays/relationships-browser/custom/ElementActions.d.ts +1 -1
  132. package/dist/overlays/relationships-browser/custom/EmptyNode.d.ts +1 -1
  133. package/dist/overlays/relationships-browser/custom/nodeTypes.d.ts +4 -4
  134. package/dist/projects-overview/ProjectsOverview.d.ts +1 -1
  135. package/dist/projects-overview/custom/nodeTypes.d.ts +1 -1
  136. package/dist/projects-overview/panel/ProjectsOverviewPanel.d.ts +1 -1
  137. package/dist/search/Search.d.ts +1 -1
  138. package/dist/search/XStateSearchAdapter.d.ts +1 -1
  139. package/dist/search/components/ElementsColumn.d.ts +1 -1
  140. package/dist/search/components/PickView.d.ts +1 -1
  141. package/dist/search/components/SearchByTags.d.ts +1 -1
  142. package/dist/search/components/SearchInput.d.ts +1 -1
  143. package/dist/search/components/ViewsColum.d.ts +3 -3
  144. package/dist/search/components/_shared.css.d.ts +1 -1
  145. package/dist/shadowroot/ShadowRoot.d.ts +1 -2
  146. package/dist/shadowroot/ShadowRoot.js +27 -21
  147. package/dist/shadowroot/index.d.ts +1 -0
  148. package/dist/shadowroot/{styles.css.d.ts → styles.d.ts} +3 -2
  149. package/dist/shadowroot/{styles.css.js → styles.js} +9 -8
  150. package/dist/styles2.js +1 -1
  151. package/package.json +27 -28
  152. package/panda.buildinfo.json +4 -7
  153. package/styles-min.css +1 -1
  154. package/styles-xyflow.css +1 -1
  155. package/styles.css +1 -1
@@ -1,23 +1,18 @@
1
- import { ActorSystem, ActionFunction, CancelAction, PromiseActorLogic, EventObject, NonReducibleUnknown } from 'xstate';
2
- import { DiagramMachineRef } from '../../likec4diagram/state/machine';
3
- import { Snapshot, EditorActorContext, EditorActorEvent, EditorActorEmitedEvent } from './types';
1
+ import { ActorSystem, ActionFunction, CancelAction, PromiseActorLogic, EventObject } from 'xstate';
2
+ import { Snapshot, SyncOp, EditorActorContext, EditorActorEvent, EditorActorEmitedEvent } from './types';
4
3
  import { HotkeyActorLogic } from './hotkey';
5
4
  import type * as t from '@likec4/core/types';
6
- /**
7
- * Actually this is DiagramActorRef
8
- * But we can't use it here due to circular type inference
9
- */
10
- export declare const diagramActorRef: (system: ActorSystem<any>) => DiagramMachineRef;
11
5
  export declare function makeSnapshot(system: ActorSystem<any>): Snapshot;
12
6
  type LayoutChanges = t.ViewChange.ResetManualLayout | t.ViewChange.SaveViewSnapshot;
13
7
  export declare const isLayoutChange: (change: t.ViewChange) => change is LayoutChanges;
8
+ export declare const isLayoutChangeOp: <T extends SyncOp>(op: T) => op is Extract<T, string | LayoutChanges>;
14
9
  export declare const withoutSnapshotChanges: (data: t.ViewChange[]) => (t.ViewChange.ChangeElementStyle | t.ViewChange.ChangeAutoLayout | t.ViewChange.ChangeProperty)[];
15
10
  export declare const scheduleSync: (delay?: number) => ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, never, never, never, "500ms" | "wait-after-edit", never>;
16
11
  export declare const cancelSync: () => CancelAction<EditorActorContext, EditorActorEvent, undefined, EditorActorEvent>;
17
12
  /**
18
13
  * Save the state before editing starts
19
14
  */
20
- export declare const saveBeforeEditing: ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
15
+ export declare const saveBeforeEditing: () => ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
21
16
  src: "hotkey";
22
17
  logic: HotkeyActorLogic;
23
18
  id: "hotkey";
@@ -27,7 +22,7 @@ export declare const saveBeforeEditing: ActionFunction<EditorActorContext, Edito
27
22
  id: string | undefined;
28
23
  } | {
29
24
  src: "executeChange";
30
- logic: PromiseActorLogic<NonReducibleUnknown, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
25
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ExecuteChange.Output, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
31
26
  id: string | undefined;
32
27
  } | {
33
28
  src: "applySemanticLayout";
@@ -47,13 +42,22 @@ export declare const pushHistory: () => ActionFunction<EditorActorContext, Edito
47
42
  id: string | undefined;
48
43
  } | {
49
44
  src: "executeChange";
50
- logic: PromiseActorLogic<NonReducibleUnknown, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
45
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ExecuteChange.Output, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
51
46
  id: string | undefined;
52
47
  } | {
53
48
  src: "applySemanticLayout";
54
49
  logic: PromiseActorLogic<import("./setup").EditorCalls.ApplySemanticLayout.Output, import("./setup").EditorCalls.ApplySemanticLayout.Input, EventObject>;
55
50
  id: string | undefined;
56
- }, never, never, never, never>;
51
+ }, never, {
52
+ type: "has pending";
53
+ params: unknown;
54
+ } | {
55
+ type: "can undo";
56
+ params: unknown;
57
+ } | {
58
+ type: "can redo";
59
+ params: unknown;
60
+ }, "500ms" | "wait-after-edit", EditorActorEmitedEvent>;
57
61
  export declare const reschedule: (delay?: number) => ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, never, never, never, "500ms" | "wait-after-edit", never>;
58
62
  export declare const undo: () => ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
59
63
  src: "hotkey";
@@ -65,7 +69,59 @@ export declare const undo: () => ActionFunction<EditorActorContext, EditorActorE
65
69
  id: string | undefined;
66
70
  } | {
67
71
  src: "executeChange";
68
- logic: PromiseActorLogic<NonReducibleUnknown, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
72
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ExecuteChange.Output, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
73
+ id: string | undefined;
74
+ } | {
75
+ src: "applySemanticLayout";
76
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplySemanticLayout.Output, import("./setup").EditorCalls.ApplySemanticLayout.Input, EventObject>;
77
+ id: string | undefined;
78
+ }, never, {
79
+ type: "has pending";
80
+ params: unknown;
81
+ } | {
82
+ type: "can undo";
83
+ params: unknown;
84
+ } | {
85
+ type: "can redo";
86
+ params: unknown;
87
+ }, "500ms" | "wait-after-edit", EditorActorEmitedEvent>;
88
+ export declare const redo: () => ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
89
+ src: "hotkey";
90
+ logic: HotkeyActorLogic;
91
+ id: "hotkey";
92
+ } | {
93
+ src: "applyLatest";
94
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplyLatestToManual.Output, import("./setup").EditorCalls.ApplyLatestToManual.Input, EventObject>;
95
+ id: string | undefined;
96
+ } | {
97
+ src: "executeChange";
98
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ExecuteChange.Output, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
99
+ id: string | undefined;
100
+ } | {
101
+ src: "applySemanticLayout";
102
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplySemanticLayout.Output, import("./setup").EditorCalls.ApplySemanticLayout.Input, EventObject>;
103
+ id: string | undefined;
104
+ }, never, {
105
+ type: "has pending";
106
+ params: unknown;
107
+ } | {
108
+ type: "can undo";
109
+ params: unknown;
110
+ } | {
111
+ type: "can redo";
112
+ params: unknown;
113
+ }, "500ms" | "wait-after-edit", EditorActorEmitedEvent>;
114
+ export declare const deleteNodesAndEdges: () => ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
115
+ src: "hotkey";
116
+ logic: HotkeyActorLogic;
117
+ id: "hotkey";
118
+ } | {
119
+ src: "applyLatest";
120
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplyLatestToManual.Output, import("./setup").EditorCalls.ApplyLatestToManual.Input, EventObject>;
121
+ id: string | undefined;
122
+ } | {
123
+ src: "executeChange";
124
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ExecuteChange.Output, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
69
125
  id: string | undefined;
70
126
  } | {
71
127
  src: "applySemanticLayout";
@@ -77,6 +133,9 @@ export declare const undo: () => ActionFunction<EditorActorContext, EditorActorE
77
133
  } | {
78
134
  type: "can undo";
79
135
  params: unknown;
136
+ } | {
137
+ type: "can redo";
138
+ params: unknown;
80
139
  }, "500ms" | "wait-after-edit", EditorActorEmitedEvent>;
81
140
  export declare const pushToSyncQueue: () => ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
82
141
  src: "hotkey";
@@ -88,7 +147,7 @@ export declare const pushToSyncQueue: () => ActionFunction<EditorActorContext, E
88
147
  id: string | undefined;
89
148
  } | {
90
149
  src: "executeChange";
91
- logic: PromiseActorLogic<NonReducibleUnknown, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
150
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ExecuteChange.Output, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
92
151
  id: string | undefined;
93
152
  } | {
94
153
  src: "applySemanticLayout";
@@ -105,7 +164,7 @@ export declare const clearQueue: () => ActionFunction<EditorActorContext, Editor
105
164
  id: string | undefined;
106
165
  } | {
107
166
  src: "executeChange";
108
- logic: PromiseActorLogic<NonReducibleUnknown, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
167
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ExecuteChange.Output, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
109
168
  id: string | undefined;
110
169
  } | {
111
170
  src: "applySemanticLayout";
@@ -2,7 +2,6 @@ import "../../_virtual/_rolldown/runtime.js";
2
2
  import { machine } from "./setup.js";
3
3
  import { createViewChange } from "../../likec4diagram/state/createViewChange.js";
4
4
  import { typedSystem } from "../../likec4diagram/state/utils.js";
5
- import { isViewChange } from "./types.js";
6
5
  import { filter, isNot, omit } from "remeda";
7
6
  import { assertEvent } from "xstate";
8
7
  //#region src/editor/actor/actions.ts
@@ -40,6 +39,7 @@ function makeSnapshot(system) {
40
39
  };
41
40
  }
42
41
  var isLayoutChange = (change) => change.op === "reset-manual-layout" || change.op === "save-view-snapshot";
42
+ var isLayoutChangeOp = (op) => op === "apply-latest-to-manual" || op === "apply-semantic-layout" || op === "sync-snapshot" || isLayoutChange(op);
43
43
  filter(isNot(isLayoutChange));
44
44
  var scheduleSync = (delay = 50) => {
45
45
  return machine.raise({ type: "change.sync-snapshot" }, delay ? {
@@ -47,10 +47,13 @@ var scheduleSync = (delay = 50) => {
47
47
  id: "sync-snapshot"
48
48
  } : void 0);
49
49
  };
50
+ var cancelSync = () => {
51
+ return machine.cancel("sync-snapshot");
52
+ };
50
53
  /**
51
54
  * Save the state before editing starts
52
55
  */
53
- var saveBeforeEditing = machine.assign(({ system, event }) => {
56
+ var saveBeforeEditing = () => machine.assign(({ system, event }) => {
54
57
  assertEvent(event, "edit.move.start");
55
58
  return { editing: {
56
59
  subject: event.subject,
@@ -60,22 +63,52 @@ var saveBeforeEditing = machine.assign(({ system, event }) => {
60
63
  /**
61
64
  * When editing finishes, push the "beforeEditing" state to the history stack
62
65
  */
63
- var pushHistory = () => machine.assign(({ context }) => {
66
+ var pushHistory = () => machine.enqueueActions(({ context, enqueue }) => {
64
67
  const editing = context.editing;
65
- if (editing) return {
66
- editing: null,
67
- history: {
68
- head: editing.before,
69
- tail: context.history
70
- }
71
- };
72
- return {};
68
+ if (editing) {
69
+ enqueue.assign({
70
+ editing: null,
71
+ history: {
72
+ head: editing.before,
73
+ tail: context.history
74
+ },
75
+ redo: null
76
+ });
77
+ enqueue(scheduleSync());
78
+ }
73
79
  });
74
- var reschedule = (delay = 300) => machine.raise(({ event }) => ({ ...event }), { delay });
75
- var undo = () => machine.enqueueActions(({ context: { history }, enqueue }) => {
80
+ var undo = () => machine.enqueueActions(({ context: { history, redo }, system, enqueue }) => {
76
81
  if (!history) return;
77
82
  const last = history.head;
78
- enqueue.assign({ history: history.tail });
83
+ enqueue.assign({
84
+ history: history.tail,
85
+ redo: {
86
+ head: makeSnapshot(system),
87
+ tail: redo
88
+ }
89
+ });
90
+ enqueue(cancelSync());
91
+ enqueue(scheduleSync(100));
92
+ enqueue.sendTo(typedSystem.diagramActor, {
93
+ type: "update.view",
94
+ view: last.view,
95
+ xyedges: last.xyedges,
96
+ xynodes: last.xynodes,
97
+ source: "editor"
98
+ });
99
+ });
100
+ var redo = () => machine.enqueueActions(({ context: { history, redo }, system, enqueue }) => {
101
+ if (!redo) return;
102
+ const last = redo.head;
103
+ enqueue.assign({
104
+ history: {
105
+ head: makeSnapshot(system),
106
+ tail: history
107
+ },
108
+ redo: redo.tail
109
+ });
110
+ enqueue(cancelSync());
111
+ enqueue(scheduleSync(100));
79
112
  enqueue.sendTo(typedSystem.diagramActor, {
80
113
  type: "update.view",
81
114
  view: last.view,
@@ -83,13 +116,41 @@ var undo = () => machine.enqueueActions(({ context: { history }, enqueue }) => {
83
116
  xynodes: last.xynodes,
84
117
  source: "editor"
85
118
  });
86
- enqueue.cancel("undo-view");
87
- enqueue.raise({
88
- type: "change.view",
89
- change: last.change
90
- }, {
91
- delay: 200,
92
- id: "undo-view"
119
+ });
120
+ var deleteNodesAndEdges = () => machine.enqueueActions(({ context, system, event, enqueue }) => {
121
+ assertEvent(event, "delete.nodes-edges");
122
+ const deletedNodeIds = new Set(event.nodeIds);
123
+ const willNotBeDeletedNode = (node) => !deletedNodeIds.has(typeof node === "string" ? node : node.id);
124
+ const snapshot = makeSnapshot(system);
125
+ const deletedEdgeIds = new Set(event.edgeIds);
126
+ for (const edge of snapshot.view.edges) if (deletedNodeIds.has(edge.source) || deletedNodeIds.has(edge.target)) deletedEdgeIds.add(edge.id);
127
+ const willNotBeDeletedEdge = (edge) => !deletedEdgeIds.has(typeof edge === "string" ? edge : edge.id);
128
+ enqueue.assign({
129
+ history: {
130
+ head: snapshot,
131
+ tail: context.history
132
+ },
133
+ redo: null
134
+ });
135
+ const cleanupNode = (node) => {
136
+ if (node.children.every(willNotBeDeletedNode) && node.inEdges.every(willNotBeDeletedEdge) && node.outEdges.every(willNotBeDeletedEdge)) return node;
137
+ return {
138
+ ...node,
139
+ children: node.children.filter(willNotBeDeletedNode),
140
+ inEdges: node.inEdges.filter(willNotBeDeletedEdge),
141
+ outEdges: node.outEdges.filter(willNotBeDeletedEdge)
142
+ };
143
+ };
144
+ enqueue(cancelSync());
145
+ enqueue(scheduleSync());
146
+ enqueue.sendTo(typedSystem.diagramActor, {
147
+ type: "update.view",
148
+ view: {
149
+ ...snapshot.view,
150
+ nodes: snapshot.view.nodes.filter(willNotBeDeletedNode).map(cleanupNode),
151
+ edges: snapshot.view.edges.filter(willNotBeDeletedEdge)
152
+ },
153
+ source: "editor"
93
154
  });
94
155
  });
95
156
  var pushToSyncQueue = () => machine.assign(({ context: { syncQueue }, event }) => {
@@ -102,7 +163,7 @@ var pushToSyncQueue = () => machine.assign(({ context: { syncQueue }, event }) =
102
163
  nextOp = "apply-semantic-layout";
103
164
  break;
104
165
  case "change.latest-to-manual":
105
- nextOp = "apply-semantic-layout";
166
+ nextOp = "apply-latest-to-manual";
106
167
  break;
107
168
  case "change.sync-snapshot":
108
169
  nextOp = "sync-snapshot";
@@ -110,13 +171,18 @@ var pushToSyncQueue = () => machine.assign(({ context: { syncQueue }, event }) =
110
171
  default: throw new Error(`Invalid event type: ${event.type}`);
111
172
  }
112
173
  if (syncQueue.length === 0) return { syncQueue: [nextOp] };
113
- const isNextLayoutChange = isViewChange(nextOp) && isLayoutChange(nextOp);
174
+ if (syncQueue.length === 1 && syncQueue[0] === nextOp) return {};
175
+ const isNextLayoutChange = isLayoutChangeOp(nextOp);
114
176
  let pending = syncQueue.filter((existingOp) => {
115
177
  if (existingOp === nextOp) return false;
116
- if (isNextLayoutChange && isViewChange(existingOp) && isLayoutChange(existingOp)) return false;
178
+ if (isNextLayoutChange && isLayoutChangeOp(existingOp)) return false;
117
179
  return true;
118
180
  });
119
181
  return { syncQueue: pending.length > 0 ? [...pending, nextOp] : [nextOp] };
120
182
  });
183
+ var clearQueue = () => machine.assign({
184
+ syncQueue: [],
185
+ processing: null
186
+ });
121
187
  //#endregion
122
- export { makeSnapshot, pushHistory, pushToSyncQueue, reschedule, saveBeforeEditing, scheduleSync, undo };
188
+ export { cancelSync, clearQueue, deleteNodesAndEdges, makeSnapshot, pushHistory, pushToSyncQueue, redo, saveBeforeEditing, scheduleSync, undo };
@@ -1,6 +1,6 @@
1
1
  import { AnyEventObject, CallbackActorLogic, NonReducibleUnknown } from 'xstate';
2
2
  export type HotKeyEvent = {
3
- type: 'undo';
3
+ type: 'undo' | 'redo';
4
4
  };
5
5
  export interface HotkeyActorLogic extends CallbackActorLogic<AnyEventObject, NonReducibleUnknown, HotKeyEvent> {
6
6
  }
@@ -10,6 +10,13 @@ var hotkey = fromCallback(({ sendBack }) => {
10
10
  sendBack({ type: "undo" });
11
11
  },
12
12
  { preventDefault: true }
13
+ ], [
14
+ "mod + shift + z",
15
+ (event) => {
16
+ event.stopPropagation();
17
+ sendBack({ type: "redo" });
18
+ },
19
+ { preventDefault: true }
13
20
  ]]);
14
21
  document.body.addEventListener("keydown", ctrlZHandler, { capture: true });
15
22
  return () => {
@@ -1,5 +1,5 @@
1
1
  import { ActorRef, SnapshotFrom, StateMachine } from 'xstate';
2
- import { EditorActorEvent, EditorActorContext, EditorActorEmitedEvent, EditorActorInput, EditorActorStateTag } from './types';
2
+ import { EditorActorContext, EditorActorEmitedEvent, EditorActorEvent, EditorActorInput, EditorActorStateTag } from './types';
3
3
  export interface EditorActorLogic extends StateMachine<EditorActorContext, EditorActorEvent, any, any, any, any, any, {
4
4
  editor: 'idle' | 'moving';
5
5
  syncQueue: 'idle' | 'pending' | 'suspended' | 'process';
@@ -8,6 +8,7 @@ var editorActorLogic = machine.createMachine({
8
8
  viewId: input.viewId,
9
9
  editing: null,
10
10
  history: null,
11
+ redo: null,
11
12
  pending: null,
12
13
  syncQueue: [],
13
14
  processing: null
@@ -1,5 +1,5 @@
1
- import { NonReducibleUnknown, SetupReturn, PromiseActorLogic, EventObject, MetaObject } from 'xstate';
2
1
  import { EditorActorContext, EditorActorEmitedEvent, EditorActorEvent, EditorActorInput, EditorActorStateTag } from './types';
2
+ import { SetupReturn, PromiseActorLogic, EventObject, NonReducibleUnknown, MetaObject } from 'xstate';
3
3
  import { HotkeyActorLogic } from './hotkey';
4
4
  import type * as t from '@likec4/core/types';
5
5
  export declare namespace EditorCalls {
@@ -32,12 +32,18 @@ export declare namespace EditorCalls {
32
32
  viewId: t.ViewId;
33
33
  changes: t.ViewChange[];
34
34
  };
35
- type Output = NonReducibleUnknown;
35
+ /**
36
+ * Returns the changes that were applied to the view
37
+ */
38
+ type Output = {
39
+ requested: t.ViewChange[];
40
+ applied: t.ViewChange[];
41
+ };
36
42
  }
37
43
  }
38
44
  export declare const machine: SetupReturn<EditorActorContext, EditorActorEvent, {
39
45
  applyLatest: PromiseActorLogic<EditorCalls.ApplyLatestToManual.Output, EditorCalls.ApplyLatestToManual.Input, EventObject>;
40
- executeChange: PromiseActorLogic<NonReducibleUnknown, EditorCalls.ExecuteChange.Input, EventObject>;
46
+ executeChange: PromiseActorLogic<EditorCalls.ExecuteChange.Output, EditorCalls.ExecuteChange.Input, EventObject>;
41
47
  applySemanticLayout: PromiseActorLogic<EditorCalls.ApplySemanticLayout.Output, EditorCalls.ApplySemanticLayout.Input, EventObject>;
42
48
  hotkey: HotkeyActorLogic;
43
49
  }, {
@@ -45,4 +51,5 @@ export declare const machine: SetupReturn<EditorActorContext, EditorActorEvent,
45
51
  }, {}, {
46
52
  'has pending': unknown;
47
53
  'can undo': unknown;
54
+ 'can redo': unknown;
48
55
  }, "500ms" | "wait-after-edit", EditorActorStateTag, EditorActorInput, NonReducibleUnknown, EditorActorEmitedEvent, MetaObject>;
@@ -27,8 +27,9 @@ var machine = setup({
27
27
  "wait-after-edit": 1e3
28
28
  },
29
29
  guards: {
30
- "has pending": ({ context }) => context.syncQueue.length > 0 || !!context.processing,
31
- "can undo": ({ context }) => context.history !== null
30
+ "has pending": ({ context }) => context.syncQueue.length > 0,
31
+ "can undo": ({ context }) => context.history !== null,
32
+ "can redo": ({ context }) => context.redo !== null
32
33
  }
33
34
  });
34
35
  //#endregion
@@ -1,4 +1,4 @@
1
- import { StopAction, ActionFunction, PromiseActorLogic, EventObject, NonReducibleUnknown } from 'xstate';
1
+ import { StopAction, ActionFunction, PromiseActorLogic, EventObject } from 'xstate';
2
2
  import { EditorActorContext, EditorActorEvent, EditorActorEmitedEvent } from './types';
3
3
  import { HotkeyActorLogic } from './hotkey';
4
4
  export declare const editor: {
@@ -14,10 +14,36 @@ export declare const editor: {
14
14
  };
15
15
  moving: {
16
16
  entry: StopAction<EditorActorContext, EditorActorEvent, undefined, EditorActorEvent>[];
17
+ exit: ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
18
+ src: "hotkey";
19
+ logic: HotkeyActorLogic;
20
+ id: "hotkey";
21
+ } | {
22
+ src: "applyLatest";
23
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplyLatestToManual.Output, import("./setup").EditorCalls.ApplyLatestToManual.Input, EventObject>;
24
+ id: string | undefined;
25
+ } | {
26
+ src: "executeChange";
27
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ExecuteChange.Output, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
28
+ id: string | undefined;
29
+ } | {
30
+ src: "applySemanticLayout";
31
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplySemanticLayout.Output, import("./setup").EditorCalls.ApplySemanticLayout.Input, EventObject>;
32
+ id: string | undefined;
33
+ }, never, {
34
+ type: "has pending";
35
+ params: unknown;
36
+ } | {
37
+ type: "can undo";
38
+ params: unknown;
39
+ } | {
40
+ type: "can redo";
41
+ params: unknown;
42
+ }, "500ms" | "wait-after-edit", EditorActorEmitedEvent>[];
17
43
  on: {
18
44
  'edit.move.end': {
19
45
  target: "#idle";
20
- actions: ( ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, never, never, never, "500ms" | "wait-after-edit", never> | ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
46
+ actions: ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
21
47
  src: "hotkey";
22
48
  logic: HotkeyActorLogic;
23
49
  id: "hotkey";
@@ -27,19 +53,26 @@ export declare const editor: {
27
53
  id: string | undefined;
28
54
  } | {
29
55
  src: "executeChange";
30
- logic: PromiseActorLogic<NonReducibleUnknown, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
56
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ExecuteChange.Output, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
31
57
  id: string | undefined;
32
58
  } | {
33
59
  src: "applySemanticLayout";
34
60
  logic: PromiseActorLogic<import("./setup").EditorCalls.ApplySemanticLayout.Output, import("./setup").EditorCalls.ApplySemanticLayout.Input, EventObject>;
35
61
  id: string | undefined;
36
- }, never, never, never, never>)[];
62
+ }, never, {
63
+ type: "has pending";
64
+ params: unknown;
65
+ } | {
66
+ type: "can undo";
67
+ params: unknown;
68
+ } | {
69
+ type: "can redo";
70
+ params: unknown;
71
+ }, "500ms" | "wait-after-edit", EditorActorEmitedEvent>;
37
72
  };
38
73
  'edit.move.cancel': {
39
74
  target: "#idle";
40
- actions: ActionFunction<EditorActorContext, {
41
- type: "edit.move.cancel";
42
- }, EditorActorEvent, undefined, {
75
+ actions: ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
43
76
  src: "hotkey";
44
77
  logic: HotkeyActorLogic;
45
78
  id: "hotkey";
@@ -49,25 +82,39 @@ export declare const editor: {
49
82
  id: string | undefined;
50
83
  } | {
51
84
  src: "executeChange";
52
- logic: PromiseActorLogic<NonReducibleUnknown, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
85
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ExecuteChange.Output, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
53
86
  id: string | undefined;
54
87
  } | {
55
88
  src: "applySemanticLayout";
56
89
  logic: PromiseActorLogic<import("./setup").EditorCalls.ApplySemanticLayout.Output, import("./setup").EditorCalls.ApplySemanticLayout.Input, EventObject>;
57
90
  id: string | undefined;
58
- }, never, never, never, never>[];
91
+ }, never, never, never, never>;
59
92
  };
60
- undo: {
93
+ cancel: {
61
94
  target: "#idle";
95
+ actions: ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
96
+ src: "hotkey";
97
+ logic: HotkeyActorLogic;
98
+ id: "hotkey";
99
+ } | {
100
+ src: "applyLatest";
101
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplyLatestToManual.Output, import("./setup").EditorCalls.ApplyLatestToManual.Input, EventObject>;
102
+ id: string | undefined;
103
+ } | {
104
+ src: "executeChange";
105
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ExecuteChange.Output, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
106
+ id: string | undefined;
107
+ } | {
108
+ src: "applySemanticLayout";
109
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplySemanticLayout.Output, import("./setup").EditorCalls.ApplySemanticLayout.Input, EventObject>;
110
+ id: string | undefined;
111
+ }, never, never, never, never>;
62
112
  };
63
113
  };
64
114
  id: string;
65
115
  };
66
116
  };
67
117
  on: {
68
- cancel: {
69
- target: "#idle";
70
- };
71
118
  '*': {
72
119
  actions: ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
73
120
  src: "hotkey";
@@ -79,7 +126,7 @@ export declare const editor: {
79
126
  id: string | undefined;
80
127
  } | {
81
128
  src: "executeChange";
82
- logic: PromiseActorLogic<NonReducibleUnknown, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
129
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ExecuteChange.Output, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
83
130
  id: string | undefined;
84
131
  } | {
85
132
  src: "applySemanticLayout";
@@ -91,6 +138,9 @@ export declare const editor: {
91
138
  } | {
92
139
  type: "can undo";
93
140
  params: unknown;
141
+ } | {
142
+ type: "can redo";
143
+ params: unknown;
94
144
  }, "500ms" | "wait-after-edit", EditorActorEmitedEvent>;
95
145
  };
96
146
  };
@@ -1,7 +1,6 @@
1
1
  import "../../_virtual/_rolldown/runtime.js";
2
2
  import { machine } from "./setup.js";
3
- import { pushHistory, saveBeforeEditing, scheduleSync } from "./actions.js";
4
- import { assign } from "xstate";
3
+ import { pushHistory, saveBeforeEditing } from "./actions.js";
5
4
  //#region src/editor/actor/state.editor.ts
6
5
  var to = {
7
6
  idle: { target: "#idle" },
@@ -10,7 +9,7 @@ var to = {
10
9
  var idOf = (t) => ({ id: t.target.substring(1) });
11
10
  var stopHotkey = () => machine.stopChild("hotkey");
12
11
  var ensureHotKey = () => machine.enqueueActions(({ check, enqueue, self }) => {
13
- const hasUndo = check("can undo");
12
+ const hasUndo = check("can undo") || check("can redo");
14
13
  const hotkey = self.getSnapshot().children["hotkey"];
15
14
  if (!hasUndo && hotkey) {
16
15
  enqueue.stopChild(hotkey);
@@ -25,19 +24,24 @@ var idle = machine.createStateConfig({
25
24
  ...idOf(to.idle),
26
25
  on: { "edit.move.start": { ...to.moving } }
27
26
  });
27
+ var clearEditing = () => machine.assign({ editing: null });
28
28
  var moving = machine.createStateConfig({
29
29
  ...idOf(to.moving),
30
- entry: [saveBeforeEditing, stopHotkey()],
30
+ entry: [saveBeforeEditing(), stopHotkey()],
31
+ exit: [ensureHotKey()],
31
32
  on: {
32
33
  "edit.move.end": {
33
- actions: [pushHistory(), scheduleSync()],
34
+ actions: pushHistory(),
34
35
  ...to.idle
35
36
  },
36
37
  "edit.move.cancel": {
37
- actions: [assign({ editing: null })],
38
+ actions: clearEditing(),
38
39
  ...to.idle
39
40
  },
40
- "undo": { ...to.idle }
41
+ "cancel": {
42
+ actions: clearEditing(),
43
+ ...to.idle
44
+ }
41
45
  }
42
46
  });
43
47
  var editor = machine.createStateConfig({
@@ -46,10 +50,7 @@ var editor = machine.createStateConfig({
46
50
  idle,
47
51
  moving
48
52
  },
49
- on: {
50
- "cancel": { ...to.idle },
51
- "*": { actions: ensureHotKey() }
52
- }
53
+ on: { "*": { actions: ensureHotKey() } }
53
54
  });
54
55
  //#endregion
55
56
  export { editor };