@likec4/diagram 1.44.0 → 1.45.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 (134) hide show
  1. package/bundle/index.js +18160 -17671
  2. package/dist/LikeC4Diagram.js +7 -5
  3. package/dist/LikeC4Diagram.props.d.ts +9 -8
  4. package/dist/LikeC4Styles.js +0 -3
  5. package/dist/LikeC4View.d.ts +3 -3
  6. package/dist/LikeC4View.js +7 -3
  7. package/dist/ReactLikeC4.d.ts +2 -2
  8. package/dist/base/Base.d.ts +1 -1
  9. package/dist/base/updateEdges.js +25 -15
  10. package/dist/base/updateNodes.d.ts +14 -0
  11. package/dist/base/updateNodes.js +51 -18
  12. package/dist/base-primitives/Markdown.d.ts +30 -4
  13. package/dist/base-primitives/Markdown.js +3 -2
  14. package/dist/base-primitives/compound/CompoundActionButton.d.ts +3 -2
  15. package/dist/base-primitives/compound/CompoundDetailsButton.d.ts +3 -2
  16. package/dist/base-primitives/edge/EdgeActionButton.d.ts +3 -2
  17. package/dist/base-primitives/edge/EdgeContainer.d.ts +1 -1
  18. package/dist/base-primitives/edge/EdgeContainer.js +4 -1
  19. package/dist/base-primitives/edge/EdgeLabel.d.ts +2 -2
  20. package/dist/base-primitives/edge/EdgePath.js +24 -4
  21. package/dist/base-primitives/element/ElementActionButtons.d.ts +3 -2
  22. package/dist/base-primitives/element/ElementActionButtons.js +2 -2
  23. package/dist/base-primitives/element/ElementData.d.ts +3 -3
  24. package/dist/base-primitives/element/ElementData.js +13 -7
  25. package/dist/base-primitives/element/ElementDetailsButton.d.ts +3 -2
  26. package/dist/base-primitives/element/ElementDetailsButton.js +3 -0
  27. package/dist/base-primitives/element/ElementShape.js +5 -5
  28. package/dist/base-primitives/element/ElementTags.d.ts +6 -4
  29. package/dist/context/DiagramFeatures.d.ts +1 -0
  30. package/dist/context/TagStylesContext.js +1 -1
  31. package/dist/custom/hooks.d.ts +2 -2
  32. package/dist/custom/index.js +1 -1
  33. package/dist/hooks/index.d.ts +2 -1
  34. package/dist/hooks/useDiagramCompareLayout.js +7 -2
  35. package/dist/hooks/useLikeC4Project.d.ts +6 -1
  36. package/dist/hooks/useLikeC4Project.js +14 -2
  37. package/dist/hooks/useMediaPrint.d.ts +6 -0
  38. package/dist/likec4diagram/DiagramXYFlow.js +11 -6
  39. package/dist/likec4diagram/custom/edges/EdgeDrifts.d.ts +6 -0
  40. package/dist/likec4diagram/custom/edges/EdgeDrifts.js +38 -0
  41. package/dist/likec4diagram/custom/edges/RelationshipEdge.js +24 -14
  42. package/dist/likec4diagram/custom/edges/SequenceStepEdge.js +3 -1
  43. package/dist/likec4diagram/custom/edges/useControlPoints.js +3 -3
  44. package/dist/likec4diagram/custom/edges/useRelationshipEdgePath.js +5 -5
  45. package/dist/likec4diagram/custom/nodes/NodeDrifts.d.ts +6 -0
  46. package/dist/likec4diagram/custom/nodes/{ElementNodeDrifts.js → NodeDrifts.js} +8 -4
  47. package/dist/likec4diagram/custom/nodes/SequenceActorNode.js +4 -2
  48. package/dist/likec4diagram/custom/nodes/index.d.ts +1 -0
  49. package/dist/likec4diagram/custom/nodes/nodes.js +64 -23
  50. package/dist/likec4diagram/relationship-popover/RelationshipPopover.js +3 -3
  51. package/dist/likec4diagram/relationship-popover/actor.d.ts +1 -1
  52. package/dist/likec4diagram/state/DiagramActorProvider.d.ts +2 -2
  53. package/dist/likec4diagram/state/DiagramActorProvider.js +0 -1
  54. package/dist/likec4diagram/state/assign.d.ts +10 -6
  55. package/dist/likec4diagram/state/assign.js +17 -192
  56. package/dist/likec4diagram/state/createViewChange.js +15 -26
  57. package/dist/likec4diagram/state/diagram-api.d.ts +2 -6
  58. package/dist/likec4diagram/state/diagram-api.js +2 -10
  59. package/dist/likec4diagram/state/hotkeyActor.d.ts +0 -7
  60. package/dist/likec4diagram/state/hotkeyActor.js +1 -17
  61. package/dist/likec4diagram/state/machine.actions.d.ts +430 -746
  62. package/dist/likec4diagram/state/machine.actions.js +193 -284
  63. package/dist/likec4diagram/state/machine.actions.layout.d.ts +579 -0
  64. package/dist/likec4diagram/state/machine.actions.layout.js +129 -0
  65. package/dist/likec4diagram/state/machine.d.ts +17 -3712
  66. package/dist/likec4diagram/state/machine.js +59 -73
  67. package/dist/likec4diagram/state/machine.setup.d.ts +61 -18
  68. package/dist/likec4diagram/state/machine.setup.js +27 -5
  69. package/dist/likec4diagram/state/machine.state.initializing.d.ts +25 -0
  70. package/dist/likec4diagram/state/machine.state.initializing.js +5 -5
  71. package/dist/likec4diagram/state/machine.state.navigating.d.ts +5 -108
  72. package/dist/likec4diagram/state/machine.state.navigating.js +167 -34
  73. package/dist/likec4diagram/state/machine.state.ready.d.ts +2316 -2851
  74. package/dist/likec4diagram/state/machine.state.ready.focused.d.ts +386 -0
  75. package/dist/likec4diagram/state/machine.state.ready.focused.js +85 -0
  76. package/dist/likec4diagram/state/machine.state.ready.idle.d.ts +474 -0
  77. package/dist/likec4diagram/state/machine.state.ready.idle.js +96 -0
  78. package/dist/likec4diagram/state/machine.state.ready.js +144 -319
  79. package/dist/likec4diagram/state/machine.state.ready.printing.d.ts +128 -0
  80. package/dist/likec4diagram/state/machine.state.ready.printing.js +40 -0
  81. package/dist/likec4diagram/state/machine.state.ready.walkthrough.d.ts +511 -0
  82. package/dist/likec4diagram/state/machine.state.ready.walkthrough.js +177 -0
  83. package/dist/likec4diagram/state/mediaPrintActor.d.ts +12 -0
  84. package/dist/likec4diagram/state/mediaPrintActor.js +18 -0
  85. package/dist/likec4diagram/state/syncManualLayoutActor.d.ts +6 -240
  86. package/dist/likec4diagram/state/syncManualLayoutActor.js +150 -89
  87. package/dist/likec4diagram/state/types.d.ts +5 -7
  88. package/dist/likec4diagram/state/utils.d.ts +15 -2
  89. package/dist/likec4diagram/state/utils.js +43 -3
  90. package/dist/likec4diagram/types.d.ts +8 -13
  91. package/dist/likec4diagram/ui/notation/NotationPanel.css.js +5 -2
  92. package/dist/likec4diagram/useLayoutConstraints.js +107 -102
  93. package/dist/likec4diagram/xyflow-diagram/diagram-view.js +12 -15
  94. package/dist/likec4diagram/xyflow-sequence/sequence-layout.js +11 -8
  95. package/dist/navigationpanel/NavigationPanel.js +5 -1
  96. package/dist/navigationpanel/actor.d.ts +4 -204
  97. package/dist/navigationpanel/actor.js +1 -1
  98. package/dist/navigationpanel/controls/ToggleReadonly.js +8 -3
  99. package/dist/navigationpanel/walkthrough/DynamicViewControls.d.ts +66 -66
  100. package/dist/navigationpanel/walkthrough/WalkthroughPanel.js +4 -3
  101. package/dist/overlays/element-details/ElementDetailsCard.css.js +3 -3
  102. package/dist/overlays/element-details/MetadataValue.d.ts +2 -1
  103. package/dist/overlays/element-details/actor.d.ts +8 -83
  104. package/dist/overlays/element-details/actor.js +0 -8
  105. package/dist/overlays/overlay/Overlay.js +10 -10
  106. package/dist/overlays/overlaysActor.d.ts +7 -392
  107. package/dist/overlays/overlaysActor.js +67 -46
  108. package/dist/overlays/relationship-details/_types.d.ts +3 -4
  109. package/dist/overlays/relationship-details/actor.d.ts +6 -562
  110. package/dist/overlays/relationship-details/actor.js +1 -0
  111. package/dist/overlays/relationship-details/layout-to-xyflow.js +3 -5
  112. package/dist/overlays/relationship-details/layout.d.ts +3 -3
  113. package/dist/overlays/relationship-details/layout.js +4 -4
  114. package/dist/overlays/relationships-browser/_types.d.ts +2 -3
  115. package/dist/overlays/relationships-browser/actor.d.ts +7 -739
  116. package/dist/overlays/relationships-browser/layout.d.ts +2 -2
  117. package/dist/overlays/relationships-browser/layout.js +3 -3
  118. package/dist/overlays/relationships-browser/useViewToNodesEdges.js +0 -3
  119. package/dist/overlays/types.d.ts +12 -13
  120. package/dist/search/components/_shared.css.d.ts +1 -1
  121. package/dist/search/searchActor.d.ts +3 -66
  122. package/dist/shadowroot/ShadowRoot.d.ts +5 -7
  123. package/dist/shadowroot/ShadowRoot.js +7 -5
  124. package/dist/styles.css2.js +1 -1
  125. package/dist/utils/vector.d.ts +5 -0
  126. package/dist/utils/vector.js +7 -0
  127. package/dist/utils/view-bounds.js +7 -6
  128. package/dist/utils/xyflow.d.ts +4 -2
  129. package/dist/utils/xyflow.js +18 -50
  130. package/package.json +19 -18
  131. package/panda.buildinfo.json +17 -5
  132. package/styles-min.css +1 -1
  133. package/styles.css +1 -1
  134. package/dist/likec4diagram/custom/nodes/ElementNodeDrifts.d.ts +0 -4
@@ -0,0 +1,18 @@
1
+ import { fromCallback } from 'xstate';
2
+
3
+ const mediaPrintActorLogic = fromCallback(({ sendBack }) => {
4
+ const beforePrint = () => {
5
+ sendBack({ type: "media.print.on" });
6
+ };
7
+ const afterPrint = () => {
8
+ sendBack({ type: "media.print.off" });
9
+ };
10
+ window.addEventListener("beforeprint", beforePrint);
11
+ window.addEventListener("afterprint", afterPrint);
12
+ return () => {
13
+ window.removeEventListener("beforeprint", beforePrint);
14
+ window.removeEventListener("afterprint", afterPrint);
15
+ };
16
+ });
17
+
18
+ export { mediaPrintActorLogic };
@@ -1,7 +1,6 @@
1
1
  import { LayoutedView, ViewChange, ViewId } from '@likec4/core/types';
2
- import { ActorLogicFrom, ActorRef, ActorRefFromLogic, MachineSnapshot, SnapshotFrom, StateMachine, NonReducibleUnknown, EventObject, MetaObject, ConditionalRequired, InputFrom, RequiredActorOptions, IsNotNever, GetConcreteByKey, AnyActorLogic, RequiredLogicInput, AnyActorRef, StateValue, AnyEventObject, ActionFunction } from 'xstate';
2
+ import { ActorRef, MachineSnapshot, StateMachine } from 'xstate';
3
3
  import { Types } from '../types';
4
- import { UndoHotKeyActorLogic } from './hotkeyActor';
5
4
  export type Input = {
6
5
  viewId: ViewId;
7
6
  };
@@ -34,247 +33,14 @@ export type Events = {
34
33
  } | {
35
34
  type: 'stop';
36
35
  };
37
- declare const _syncManualLayoutActorLogic: StateMachine<Readonly<Input & {
38
- history: ReadonlyArray<HistorySnapshot>;
39
- beforeEditing: HistorySnapshot | null;
40
- editing: "node" | "edge" | null;
41
- }>, Events, {
42
- undoHotKey?: ActorRefFromLogic< UndoHotKeyActorLogic>;
43
- }, {
44
- src: "undoHotKeyActorLogic";
45
- logic: UndoHotKeyActorLogic;
46
- id: "undoHotKey";
47
- }, never, {
48
- type: "can undo";
49
- params: unknown;
50
- }, "timeout", "stopped" | "editing" | "pending" | "idle" | "paused", "pending" | "ready", Input, NonReducibleUnknown, EventObject, MetaObject, {
51
- readonly initial: "idle";
52
- readonly context: ({ input }: {
53
- spawn: {
54
- <TSrc extends "undoHotKeyActorLogic">(logic: TSrc, ...[options]: {
55
- src: "undoHotKeyActorLogic";
56
- logic: UndoHotKeyActorLogic;
57
- id: "undoHotKey";
58
- } extends infer T ? T extends {
59
- src: "undoHotKeyActorLogic";
60
- logic: UndoHotKeyActorLogic;
61
- id: "undoHotKey";
62
- } ? T extends {
63
- src: TSrc;
64
- } ? ConditionalRequired<[options?: {
65
- id?: T["id"];
66
- systemId?: string;
67
- input?: InputFrom<T["logic"]>;
68
- syncSnapshot?: boolean;
69
- } & { [K in RequiredActorOptions<T>]: unknown; }], IsNotNever<RequiredActorOptions<T>>> : never : never : never): ActorRefFromLogic< GetConcreteByKey<{
70
- src: "undoHotKeyActorLogic";
71
- logic: UndoHotKeyActorLogic;
72
- id: "undoHotKey";
73
- }, "src", TSrc>["logic"]>;
74
- <TLogic extends AnyActorLogic>(src: TLogic, ...[options]: ConditionalRequired<[options?: {
75
- id?: never;
76
- systemId?: string;
77
- input?: InputFrom<TLogic>;
78
- syncSnapshot?: boolean;
79
- } & { [K in RequiredLogicInput<TLogic>]: unknown; }], IsNotNever<RequiredLogicInput<TLogic>>>): ActorRefFromLogic<TLogic>;
80
- };
81
- input: Input;
82
- self: ActorRef<MachineSnapshot<Readonly<Input & {
83
- history: ReadonlyArray<HistorySnapshot>;
84
- beforeEditing: HistorySnapshot | null;
85
- editing: "node" | "edge" | null;
86
- }>, Events, Record<string, AnyActorRef | undefined>, StateValue, string, unknown, any, any>, Events, AnyEventObject>;
87
- }) => {
88
- history: never[];
89
- beforeEditing: null;
90
- editing: null;
91
- viewId: ViewId;
92
- };
93
- readonly states: {
94
- readonly idle: {
95
- tags: "ready";
96
- entry: ActionFunction<Readonly<Input & {
97
- history: ReadonlyArray<HistorySnapshot>;
98
- beforeEditing: HistorySnapshot | null;
99
- editing: "node" | "edge" | null;
100
- }>, Events, Events, undefined, {
101
- src: "undoHotKeyActorLogic";
102
- logic: UndoHotKeyActorLogic;
103
- id: "undoHotKey";
104
- }, never, never, never, never>[];
105
- on: {
106
- sync: {
107
- target: string;
108
- };
109
- 'editing.start': {
110
- actions: ActionFunction<Readonly<Input & {
111
- history: ReadonlyArray<HistorySnapshot>;
112
- beforeEditing: HistorySnapshot | null;
113
- editing: "node" | "edge" | null;
114
- }>, Events, Events, undefined, {
115
- src: "undoHotKeyActorLogic";
116
- logic: UndoHotKeyActorLogic;
117
- id: "undoHotKey";
118
- }, never, never, never, never>;
119
- target: string;
120
- };
121
- undo: {
122
- guard: "can undo";
123
- actions: ActionFunction<Readonly<Input & {
124
- history: ReadonlyArray<HistorySnapshot>;
125
- beforeEditing: HistorySnapshot | null;
126
- editing: "node" | "edge" | null;
127
- }>, Events, Events, undefined, {
128
- src: "undoHotKeyActorLogic";
129
- logic: UndoHotKeyActorLogic;
130
- id: "undoHotKey";
131
- }, never, {
132
- type: "can undo";
133
- params: unknown;
134
- }, "timeout", EventObject>;
135
- };
136
- };
137
- };
138
- readonly editing: {
139
- on: {
140
- 'editing.stop': {
141
- actions: ActionFunction<Readonly<Input & {
142
- history: ReadonlyArray<HistorySnapshot>;
143
- beforeEditing: HistorySnapshot | null;
144
- editing: "node" | "edge" | null;
145
- }>, Events, Events, undefined, {
146
- src: "undoHotKeyActorLogic";
147
- logic: UndoHotKeyActorLogic;
148
- id: "undoHotKey";
149
- }, never, {
150
- type: "can undo";
151
- params: unknown;
152
- }, "timeout", EventObject>[];
153
- target: string;
154
- };
155
- undo: {};
156
- };
157
- };
158
- readonly pending: {
159
- tags: "pending";
160
- on: {
161
- sync: {
162
- target: string;
163
- reenter: true;
164
- };
165
- 'editing.start': {
166
- target: string;
167
- actions: ActionFunction<Readonly<Input & {
168
- history: ReadonlyArray<HistorySnapshot>;
169
- beforeEditing: HistorySnapshot | null;
170
- editing: "node" | "edge" | null;
171
- }>, Events, Events, undefined, {
172
- src: "undoHotKeyActorLogic";
173
- logic: UndoHotKeyActorLogic;
174
- id: "undoHotKey";
175
- }, never, never, never, never>;
176
- };
177
- undo: {
178
- guard: "can undo";
179
- actions: ActionFunction<Readonly<Input & {
180
- history: ReadonlyArray<HistorySnapshot>;
181
- beforeEditing: HistorySnapshot | null;
182
- editing: "node" | "edge" | null;
183
- }>, Events, Events, undefined, {
184
- src: "undoHotKeyActorLogic";
185
- logic: UndoHotKeyActorLogic;
186
- id: "undoHotKey";
187
- }, never, {
188
- type: "can undo";
189
- params: unknown;
190
- }, "timeout", EventObject>;
191
- target: string;
192
- };
193
- };
194
- after: {
195
- timeout: {
196
- target: string;
197
- actions: ActionFunction<Readonly<Input & {
198
- history: ReadonlyArray<HistorySnapshot>;
199
- beforeEditing: HistorySnapshot | null;
200
- editing: "node" | "edge" | null;
201
- }>, Events, Events, undefined, never, never, never, "timeout", never>;
202
- };
203
- };
204
- };
205
- readonly paused: {
206
- tags: "pending";
207
- on: {
208
- 'editing.stop': {
209
- actions: ActionFunction<Readonly<Input & {
210
- history: ReadonlyArray<HistorySnapshot>;
211
- beforeEditing: HistorySnapshot | null;
212
- editing: "node" | "edge" | null;
213
- }>, Events, Events, undefined, {
214
- src: "undoHotKeyActorLogic";
215
- logic: UndoHotKeyActorLogic;
216
- id: "undoHotKey";
217
- }, never, {
218
- type: "can undo";
219
- params: unknown;
220
- }, "timeout", EventObject>[];
221
- target: string;
222
- };
223
- undo: {};
224
- };
225
- };
226
- readonly stopped: {
227
- readonly entry: readonly [ ActionFunction<Readonly<Input & {
228
- history: ReadonlyArray<HistorySnapshot>;
229
- beforeEditing: HistorySnapshot | null;
230
- editing: "node" | "edge" | null;
231
- }>, Events, Events, undefined, {
232
- src: "undoHotKeyActorLogic";
233
- logic: UndoHotKeyActorLogic;
234
- id: "undoHotKey";
235
- }, never, never, never, never>, ActionFunction<Readonly<Input & {
236
- history: ReadonlyArray<HistorySnapshot>;
237
- beforeEditing: HistorySnapshot | null;
238
- editing: "node" | "edge" | null;
239
- }>, Events, Events, undefined, {
240
- src: "undoHotKeyActorLogic";
241
- logic: UndoHotKeyActorLogic;
242
- id: "undoHotKey";
243
- }, never, {
244
- type: "can undo";
245
- params: unknown;
246
- }, "timeout", EventObject>];
247
- readonly type: "final";
248
- };
249
- };
250
- readonly on: {
251
- readonly cancel: {
252
- readonly target: ".idle";
253
- };
254
- readonly synced: {
255
- readonly actions: ActionFunction<Readonly<Input & {
256
- history: ReadonlyArray<HistorySnapshot>;
257
- beforeEditing: HistorySnapshot | null;
258
- editing: "node" | "edge" | null;
259
- }>, Events, Events, undefined, {
260
- src: "undoHotKeyActorLogic";
261
- logic: UndoHotKeyActorLogic;
262
- id: "undoHotKey";
263
- }, never, never, never, never>;
264
- readonly target: ".idle";
265
- };
266
- readonly stop: {
267
- readonly target: ".stopped";
268
- };
269
- };
270
- }>;
36
+ type Tags = 'pending' | 'ready';
271
37
  /**
272
38
  * Here is a trick to reduce inference types
273
39
  */
274
- type InferredMachine = ActorLogicFrom<typeof _syncManualLayoutActorLogic>;
275
- export interface SyncLayoutActorLogic extends InferredMachine {
40
+ export interface SyncLayoutActorLogic extends StateMachine<Context, Events, {}, any, any, any, any, any, Tags, Input, any, any, any, any> {
41
+ }
42
+ export type SyncLayoutActorSnapshot = MachineSnapshot<Context, Events, {}, never, Tags, never, {}, {}>;
43
+ export interface SyncLayoutActorRef extends ActorRef<SyncLayoutActorSnapshot, Events> {
276
44
  }
277
- export type SyncLayoutActorRef = ActorRefFromLogic<SyncLayoutActorLogic>;
278
- export type SyncLayoutActorSnapshot = SnapshotFrom<SyncLayoutActorLogic>;
279
45
  export declare const syncManualLayoutActorLogic: SyncLayoutActorLogic;
280
46
  export {};
@@ -1,9 +1,22 @@
1
- import { deepEqual } from 'fast-equals';
2
- import { last, map } from 'remeda';
3
- import { setup, assign, assertEvent } from 'xstate';
1
+ import { getHotkeyHandler } from '@mantine/hooks';
2
+ import { last, omit } from 'remeda';
3
+ import { setup, assign, stopChild, fromCallback, assertEvent } from 'xstate';
4
4
  import { createViewChange } from './createViewChange.js';
5
- import { undoHotKeyActorLogic } from './hotkeyActor.js';
6
5
 
6
+ const undoHotKeyActorLogic = fromCallback(({ sendBack }) => {
7
+ const ctrlZHandler = getHotkeyHandler([
8
+ ["mod + z", (event) => {
9
+ event.stopPropagation();
10
+ sendBack({ type: "undo" });
11
+ }, {
12
+ preventDefault: true
13
+ }]
14
+ ]);
15
+ document.body.addEventListener("keydown", ctrlZHandler, { capture: true });
16
+ return () => {
17
+ document.body.removeEventListener("keydown", ctrlZHandler, { capture: true });
18
+ };
19
+ });
7
20
  const diagramActorRef = function(system) {
8
21
  return system.get("diagram");
9
22
  };
@@ -25,49 +38,36 @@ const syncManualLayout = setup({
25
38
  undoHotKeyActorLogic
26
39
  }
27
40
  });
28
- const pushHistory = syncManualLayout.assign(({ context }) => {
29
- const snapshot = context.beforeEditing;
30
- if (!snapshot) {
31
- return {};
32
- }
33
- const prevHistoryItem = last(context.history);
34
- if (deepEqual(prevHistoryItem?.xyedges, snapshot.xyedges) && deepEqual(prevHistoryItem?.xynodes, snapshot.xynodes)) {
35
- return {
36
- beforeEditing: null
37
- };
38
- }
39
- return {
40
- beforeEditing: null,
41
- history: [
42
- ...context.history,
43
- snapshot
44
- ]
45
- };
46
- });
47
- const popHistory = syncManualLayout.assign(({ context }) => {
48
- if (context.history.length === 0) {
49
- return {};
50
- }
51
- return {
52
- history: context.history.slice(0, -1)
53
- };
54
- });
55
- const startEditing = syncManualLayout.assign(({ system, event }) => {
41
+ const raiseSync = syncManualLayout.raise({ type: "sync" }, { delay: 300, id: "sync" });
42
+ const cancelSync = syncManualLayout.cancel("sync");
43
+ const startEditing = syncManualLayout.enqueueActions(({ check, enqueue, system, event, self, context }) => {
56
44
  assertEvent(event, "editing.start");
57
45
  const parentContext = diagramActorRef(system).getSnapshot().context;
58
- return {
46
+ enqueue.assign({
59
47
  editing: event.subject,
60
48
  beforeEditing: {
61
- xynodes: map(parentContext.xynodes, (n) => ({ ...n })),
62
- xyedges: map(parentContext.xyedges, (e) => ({ ...e })),
49
+ xynodes: parentContext.xynodes.map(
50
+ ({ measured, style, ...n }) => ({
51
+ ...omit(n, ["selected", "dragging", "resizing"]),
52
+ data: omit(n.data, ["dimmed", "hovered"]),
53
+ initialWidth: measured?.width ?? n.width ?? n.initialWidth,
54
+ initialHeight: measured?.height ?? n.height ?? n.initialHeight
55
+ })
56
+ ),
57
+ xyedges: parentContext.xyedges.map(
58
+ (e) => ({
59
+ ...omit(e, ["selected"]),
60
+ data: omit(e.data, ["active", "dimmed", "hovered"])
61
+ })
62
+ ),
63
63
  change: createViewChange(parentContext),
64
64
  view: parentContext.view,
65
65
  synched: false
66
66
  }
67
- };
67
+ });
68
68
  });
69
- const ensureHotKey = syncManualLayout.enqueueActions(({ check, enqueue, self }) => {
70
- const hasUndo = check("can undo");
69
+ const ensureHotKey = syncManualLayout.enqueueActions(({ check, context, enqueue, self }) => {
70
+ const hasUndo = context.history.length > 0;
71
71
  const undoHotKey = self.getSnapshot().children["undoHotKey"];
72
72
  if (undoHotKey && !hasUndo) {
73
73
  enqueue.stopChild(undoHotKey);
@@ -79,42 +79,56 @@ const ensureHotKey = syncManualLayout.enqueueActions(({ check, enqueue, self })
79
79
  });
80
80
  }
81
81
  });
82
+ const pushHistory = syncManualLayout.assign(({ context }) => {
83
+ const snapshot = context.beforeEditing;
84
+ if (!snapshot) {
85
+ return {
86
+ editing: null
87
+ };
88
+ }
89
+ return {
90
+ beforeEditing: null,
91
+ editing: null,
92
+ history: [
93
+ ...context.history,
94
+ snapshot
95
+ ]
96
+ };
97
+ });
82
98
  const stopEditing = syncManualLayout.enqueueActions(({ event, enqueue }) => {
83
- assertEvent(event, "editing.stop");
84
- if (event.wasChanged) {
85
- enqueue.cancel("sync");
99
+ assertEvent(event, ["editing.stop", "cancel", "undo"]);
100
+ if (event.type === "editing.stop" && event.wasChanged) {
86
101
  enqueue(pushHistory);
87
- enqueue.raise({ type: "sync" }, { id: "sync", delay: 50 });
102
+ enqueue(ensureHotKey);
103
+ enqueue(raiseSync);
104
+ return;
88
105
  }
89
106
  enqueue.assign({
90
107
  beforeEditing: null,
91
108
  editing: null
92
109
  });
93
110
  });
94
- const emitOnChange = syncManualLayout.sendTo(
95
- ({ system }) => diagramActorRef(system),
96
- ({ system }) => {
97
- const parentContext = diagramActorRef(system).getSnapshot().context;
98
- return {
99
- type: "emit.onChange",
100
- change: createViewChange(parentContext)
101
- };
102
- }
103
- );
104
111
  const markHistoryAsSynched = syncManualLayout.assign(({ context, event }) => {
105
112
  assertEvent(event, "synced");
106
113
  return {
107
114
  history: context.history.map((i) => ({
108
115
  ...i,
109
116
  synched: true
110
- })),
111
- beforeEditing: context.beforeEditing ? {
112
- ...context.beforeEditing,
113
- synched: true
114
- } : null
117
+ }))
118
+ };
119
+ });
120
+ const popHistory = syncManualLayout.assign(({ context }) => {
121
+ if (context.history.length === 0 || context.history.length === 1) {
122
+ return {
123
+ history: []
124
+ };
125
+ }
126
+ return {
127
+ history: context.history.slice(0, context.history.length - 1)
115
128
  };
116
129
  });
117
130
  const undo = syncManualLayout.enqueueActions(({ context, enqueue, system }) => {
131
+ enqueue(cancelSync);
118
132
  const lastHistoryItem = last(context.history);
119
133
  if (!lastHistoryItem) {
120
134
  return;
@@ -126,23 +140,37 @@ const undo = syncManualLayout.enqueueActions(({ context, enqueue, system }) => {
126
140
  type: "update.view",
127
141
  view: lastHistoryItem.view,
128
142
  xyedges: lastHistoryItem.xyedges,
129
- xynodes: lastHistoryItem.xynodes
143
+ xynodes: lastHistoryItem.xynodes,
144
+ source: "internal"
130
145
  });
131
146
  if (lastHistoryItem.synched) {
132
- enqueue.sendTo(diagramActor, {
133
- type: "emit.onChange",
134
- change: lastHistoryItem.change
135
- });
147
+ enqueue.sendTo(
148
+ diagramActor,
149
+ {
150
+ type: "emit.onChange",
151
+ change: lastHistoryItem.change
152
+ }
153
+ );
154
+ } else {
155
+ enqueue(raiseSync);
136
156
  }
137
157
  });
158
+ const emitOnChange = syncManualLayout.enqueueActions(({ context, enqueue, system }) => {
159
+ enqueue(cancelSync);
160
+ const diagramActor = diagramActorRef(system);
161
+ const parentContext = diagramActor.getSnapshot().context;
162
+ const change = createViewChange(parentContext);
163
+ enqueue.sendTo(diagramActor, {
164
+ type: "update.view-bounds",
165
+ bounds: change.layout.bounds
166
+ });
167
+ enqueue.sendTo(diagramActor, {
168
+ type: "emit.onChange",
169
+ change
170
+ });
171
+ });
138
172
  const idle = syncManualLayout.createStateConfig({
139
173
  tags: "ready",
140
- entry: [
141
- assign({
142
- beforeEditing: null,
143
- editing: null
144
- })
145
- ],
146
174
  on: {
147
175
  sync: {
148
176
  target: "pending"
@@ -150,28 +178,40 @@ const idle = syncManualLayout.createStateConfig({
150
178
  "editing.start": {
151
179
  actions: startEditing,
152
180
  target: "editing"
153
- },
154
- undo: {
155
- guard: "can undo",
156
- actions: undo
157
181
  }
158
182
  }
159
183
  });
160
184
  const editing = syncManualLayout.createStateConfig({
185
+ entry: [
186
+ cancelSync
187
+ ],
161
188
  on: {
189
+ cancel: {
190
+ actions: stopEditing,
191
+ target: "idle"
192
+ },
162
193
  "editing.stop": {
163
- actions: [
164
- stopEditing,
165
- ensureHotKey
166
- ],
194
+ actions: stopEditing,
167
195
  target: "idle"
168
196
  },
169
- undo: {}
197
+ undo: {
198
+ actions: stopEditing,
199
+ target: "idle"
200
+ },
201
+ synced: {
202
+ actions: [
203
+ markHistoryAsSynched
204
+ ]
205
+ }
170
206
  }
171
207
  });
172
208
  const pending = syncManualLayout.createStateConfig({
173
209
  tags: "pending",
174
210
  on: {
211
+ cancel: {
212
+ actions: cancelSync,
213
+ target: "idle"
214
+ },
175
215
  sync: {
176
216
  target: "pending",
177
217
  reenter: true
@@ -179,11 +219,6 @@ const pending = syncManualLayout.createStateConfig({
179
219
  "editing.start": {
180
220
  target: "paused",
181
221
  actions: startEditing
182
- },
183
- undo: {
184
- guard: "can undo",
185
- actions: undo,
186
- target: "idle"
187
222
  }
188
223
  },
189
224
  after: {
@@ -195,15 +230,30 @@ const pending = syncManualLayout.createStateConfig({
195
230
  });
196
231
  const paused = syncManualLayout.createStateConfig({
197
232
  tags: "pending",
233
+ entry: [
234
+ cancelSync
235
+ ],
198
236
  on: {
237
+ cancel: {
238
+ actions: stopEditing,
239
+ target: "idle"
240
+ },
199
241
  "editing.stop": {
200
- actions: [
201
- stopEditing,
202
- ensureHotKey
203
- ],
242
+ actions: stopEditing,
204
243
  target: "pending"
205
244
  },
206
- undo: {}
245
+ undo: {
246
+ actions: stopEditing,
247
+ target: "idle"
248
+ },
249
+ // When external sync is done while editing, we just mark history as synced
250
+ // but go to editing state (that does not return to pending)
251
+ synced: {
252
+ actions: [
253
+ markHistoryAsSynched
254
+ ],
255
+ target: "editing"
256
+ }
207
257
  }
208
258
  });
209
259
  const _syncManualLayoutActorLogic = syncManualLayout.createMachine({
@@ -225,17 +275,28 @@ const _syncManualLayoutActorLogic = syncManualLayout.createMachine({
225
275
  beforeEditing: null,
226
276
  history: []
227
277
  }),
228
- ensureHotKey
278
+ stopChild("undoHotKey")
229
279
  ],
230
280
  type: "final"
231
281
  }
232
282
  },
233
283
  on: {
234
284
  cancel: {
285
+ actions: [
286
+ cancelSync
287
+ ],
235
288
  target: ".idle"
236
289
  },
237
290
  synced: {
238
- actions: markHistoryAsSynched,
291
+ actions: [
292
+ markHistoryAsSynched,
293
+ cancelSync
294
+ ],
295
+ target: ".idle"
296
+ },
297
+ undo: {
298
+ guard: "can undo",
299
+ actions: undo,
239
300
  target: ".idle"
240
301
  },
241
302
  stop: {
@@ -1,19 +1,17 @@
1
- import { ActorRefFromLogic, ActorSystem, EventFromLogic, SnapshotFrom } from 'xstate';
1
+ import { ActorSystem } from 'xstate';
2
2
  import { OverlaysActorRef } from '../../overlays/overlaysActor';
3
3
  import { SearchActorRef } from '../../search/searchActor';
4
- import { DiagramMachineLogic } from './machine';
4
+ import { DiagramMachineRef } from './machine';
5
5
  import { SyncLayoutActorRef } from './syncManualLayoutActor';
6
6
  export type System = ActorSystem<{
7
7
  actors: {
8
- diagram: ActorRefFromLogic<DiagramMachineLogic>;
8
+ diagram: DiagramMachineRef;
9
9
  overlays: OverlaysActorRef;
10
10
  search: SearchActorRef;
11
11
  syncLayout: SyncLayoutActorRef;
12
12
  };
13
13
  }>;
14
- export interface DiagramActorRef extends ActorRefFromLogic<DiagramMachineLogic> {
14
+ export interface DiagramActorRef extends DiagramMachineRef {
15
15
  system: System;
16
16
  }
17
- export type DiagramActorSnapshot = SnapshotFrom<DiagramMachineLogic>;
18
- export type DiagramActorEvent = EventFromLogic<DiagramMachineLogic>;
19
- export type { Context as DiagramContext, EmittedEvents as DiagramEmittedEvents, } from './machine.setup';
17
+ export type { DiagramContext, DiagramEmittedEvents, DiagramEvents, DiagramMachineSnapshot as DiagramActorSnapshot, } from './machine';
@@ -1,10 +1,13 @@
1
- import { DiagramEdge, DiagramNode, BBox } from '@likec4/core/types';
1
+ import { DiagramEdge, DiagramNode, DiagramView, BBox } from '@likec4/core/types';
2
+ import { Viewport } from '@xyflow/system';
2
3
  import { ActorSystem } from 'xstate';
3
4
  import { OverlaysActorRef } from '../../overlays/overlaysActor';
4
5
  import { SearchActorRef } from '../../search/searchActor';
6
+ import { Types } from '../types';
5
7
  import { Context } from './machine.setup';
6
8
  import { SyncLayoutActorRef } from './syncManualLayoutActor';
7
9
  import { DiagramActorRef } from './types';
10
+ import { Fqn, DeploymentFqn } from '@likec4/core';
8
11
  export declare function typedSystem(system: ActorSystem<any>): {
9
12
  readonly syncLayoutActorRef: SyncLayoutActorRef | null;
10
13
  readonly overlaysActorRef: OverlaysActorRef | null;
@@ -23,5 +26,15 @@ export declare function activeSequenceBounds(params: {
23
26
  context: Context;
24
27
  }): {
25
28
  bounds: BBox;
26
- duration?: number;
29
+ duration: number;
30
+ };
31
+ export declare function nodeRef(node: Types.Node): Fqn | DeploymentFqn | null;
32
+ export declare function findCorrespondingNode(context: Pick<Context, 'lastOnNavigate' | 'xynodes'>, event: {
33
+ view: DiagramView;
34
+ xynodes: Types.Node[];
35
+ }): {
36
+ fromNode: Types.Node<"element" | "deployment" | "compound-element" | "compound-deployment" | "view-group" | "seq-actor" | "seq-parallel"> | null | undefined;
37
+ toNode: Types.Node<"element" | "deployment" | "compound-element" | "compound-deployment" | "view-group" | "seq-actor" | "seq-parallel"> | null | undefined;
27
38
  };
39
+ export declare function calcViewportForBounds(context: Pick<Context, 'xystore' | 'xyflow' | 'fitViewPadding'>, bounds: BBox): Viewport;
40
+ export declare function parseAsNumber(value: string | number | undefined): number;