@likec4/diagram 1.56.0 → 1.57.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 (82) hide show
  1. package/dist/LikeC4Diagram.js +3 -1
  2. package/dist/LikeC4View.js +47 -55
  3. package/dist/adhoc-editor/ElementsTree.js +2 -6
  4. package/dist/components/RootContainer.js +19 -18
  5. package/dist/context/DiagramFeatures.d.ts +1 -1
  6. package/dist/context/DiagramFeatures.js +5 -0
  7. package/dist/context/RootContainerContext.d.ts +10 -17
  8. package/dist/context/RootContainerContext.js +1 -13
  9. package/dist/custom/index.d.ts +1 -1
  10. package/dist/custom/index.js +1 -2
  11. package/dist/editor/LikeC4EditorCallbacks.d.ts +5 -0
  12. package/dist/editor/actor/actions.d.ts +115 -0
  13. package/dist/editor/actor/actions.js +122 -0
  14. package/dist/editor/{hotkeyActor.d.ts → actor/hotkey.d.ts} +1 -1
  15. package/dist/editor/{hotkeyActor.js → actor/hotkey.js} +4 -4
  16. package/dist/editor/actor/machine.d.ts +11 -0
  17. package/dist/editor/actor/machine.js +22 -0
  18. package/dist/editor/{editorActor.setup.d.ts → actor/setup.d.ts} +13 -49
  19. package/dist/editor/{editorActor.setup.js → actor/setup.js} +13 -10
  20. package/dist/editor/actor/state.editor.d.ts +97 -0
  21. package/dist/editor/actor/state.editor.js +55 -0
  22. package/dist/editor/actor/state.sync-queue.d.ts +420 -0
  23. package/dist/editor/actor/state.sync-queue.js +235 -0
  24. package/dist/editor/actor/types.d.ts +59 -0
  25. package/dist/editor/actor/types.js +5 -0
  26. package/dist/editor/applyChangesToManualLayout.js +1 -1
  27. package/dist/editor/index.d.ts +2 -1
  28. package/dist/editor/useEditorActorLogic.d.ts +8 -2
  29. package/dist/editor/useEditorActorLogic.js +26 -6
  30. package/dist/hooks/useDiagram.js +6 -1
  31. package/dist/hooks/useDiagramCompareLayout.js +1 -1
  32. package/dist/hooks/useEditorActor.d.ts +4 -0
  33. package/dist/hooks/useEditorActor.js +26 -0
  34. package/dist/hooks/useLikeC4ElementsTree.d.ts +3 -2
  35. package/dist/hooks/useLikeC4ElementsTree.js +3 -1
  36. package/dist/likec4diagram/DiagramUI.js +8 -4
  37. package/dist/likec4diagram/DiagramXYFlow.js +12 -12
  38. package/dist/likec4diagram/state/aligners.js +3 -0
  39. package/dist/likec4diagram/state/assign.js +1 -1
  40. package/dist/likec4diagram/state/diagram-api.d.ts +16 -0
  41. package/dist/likec4diagram/state/diagram-api.js +13 -7
  42. package/dist/likec4diagram/state/machine.actions.js +7 -8
  43. package/dist/likec4diagram/state/machine.d.ts +1 -1
  44. package/dist/likec4diagram/state/machine.setup.js +1 -1
  45. package/dist/likec4diagram/state/types.d.ts +1 -1
  46. package/dist/likec4diagram/state/utils.d.ts +1 -1
  47. package/dist/likec4diagram/useLayoutConstraints.js +2 -0
  48. package/dist/navigationpanel/controls/ToggleReadonly.js +4 -2
  49. package/dist/navigationpanel/editorpanel/ApplySemanticLayout.d.ts +4 -0
  50. package/dist/navigationpanel/editorpanel/ApplySemanticLayout.js +36 -0
  51. package/dist/navigationpanel/editorpanel/EditorPanel.js +45 -33
  52. package/dist/navigationpanel/walkthrough/DynamicViewControls.d.ts +61 -61
  53. package/dist/overlays/overlay/Overlay.d.ts +16 -0
  54. package/dist/overlays/overlay/Overlay.js +50 -52
  55. package/dist/overlays/overlaysActor.js +28 -27
  56. package/dist/overlays/relationship-details/custom/nodeTypes.d.ts +4 -5
  57. package/dist/overlays/relationship-details/custom/nodeTypes.js +25 -24
  58. package/dist/overlays/relationships-browser/SelectElement.js +2 -2
  59. package/dist/search/Search.d.ts +6 -3
  60. package/dist/search/Search.js +60 -71
  61. package/dist/search/components/ElementsColumn.js +12 -8
  62. package/dist/search/searchActor.js +30 -26
  63. package/dist/shadowroot/ShadowRoot.d.ts +7 -6
  64. package/dist/shadowroot/ShadowRoot.js +59 -20
  65. package/dist/shadowroot/styles.css.d.ts +10 -2
  66. package/dist/shadowroot/styles.css.js +33 -36
  67. package/dist/styles2.js +1 -1
  68. package/package.json +17 -23
  69. package/panda.buildinfo.json +15 -15
  70. package/src/styles-font.css +114 -0
  71. package/src/styles-min.css +2 -0
  72. package/src/styles-xyflow.css +1 -0
  73. package/src/styles.css +3 -0
  74. package/styles-min.css +1 -1
  75. package/styles.css +1 -1
  76. package/dist/bundle/index.d.ts +0 -1
  77. package/dist/editor/editorActor.actions.d.ts +0 -153
  78. package/dist/editor/editorActor.actions.js +0 -133
  79. package/dist/editor/editorActor.states.d.ts +0 -9
  80. package/dist/editor/editorActor.states.js +0 -219
  81. package/dist/hooks/useOverlaysActor.js +0 -11
  82. package/dist/hooks/useSearchActor.js +0 -11
@@ -0,0 +1,420 @@
1
+ import { ActionFunction, PromiseActorLogic, EventObject, NonReducibleUnknown, GuardArgs, ActorRef, MachineSnapshot, AnyActorRef, StateValue, AnyEventObject, DoneActorEvent, ActionArgs, ErrorActorEvent } from 'xstate';
2
+ import { EditorActorContext, EditorActorEvent, EditorActorEmitedEvent } from './types';
3
+ import { HotkeyActorLogic } from './hotkey';
4
+ import { DiagramView, Any, ViewId, ViewChange } from '@likec4/core';
5
+ export declare const syncQueue: {
6
+ initial: string;
7
+ states: {
8
+ idle: {
9
+ always: {
10
+ target: "#queue-pending";
11
+ guard: "has pending";
12
+ };
13
+ on: {
14
+ 'change.sync-snapshot': {
15
+ target: "#queue-pending";
16
+ actions: ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
17
+ src: "hotkey";
18
+ logic: HotkeyActorLogic;
19
+ id: "hotkey";
20
+ } | {
21
+ src: "applyLatest";
22
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplyLatestToManual.Output, import("./setup").EditorCalls.ApplyLatestToManual.Input, EventObject>;
23
+ id: string | undefined;
24
+ } | {
25
+ src: "executeChange";
26
+ logic: PromiseActorLogic<NonReducibleUnknown, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
27
+ id: string | undefined;
28
+ } | {
29
+ src: "applySemanticLayout";
30
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplySemanticLayout.Output, import("./setup").EditorCalls.ApplySemanticLayout.Input, EventObject>;
31
+ id: string | undefined;
32
+ }, never, never, never, never>;
33
+ };
34
+ 'change.*': {
35
+ target: "#queue-process";
36
+ actions: ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
37
+ src: "hotkey";
38
+ logic: HotkeyActorLogic;
39
+ id: "hotkey";
40
+ } | {
41
+ src: "applyLatest";
42
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplyLatestToManual.Output, import("./setup").EditorCalls.ApplyLatestToManual.Input, EventObject>;
43
+ id: string | undefined;
44
+ } | {
45
+ src: "executeChange";
46
+ logic: PromiseActorLogic<NonReducibleUnknown, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
47
+ id: string | undefined;
48
+ } | {
49
+ src: "applySemanticLayout";
50
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplySemanticLayout.Output, import("./setup").EditorCalls.ApplySemanticLayout.Input, EventObject>;
51
+ id: string | undefined;
52
+ }, never, never, never, never>;
53
+ };
54
+ undo: {
55
+ target: "#queue-idle";
56
+ actions: ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
57
+ src: "hotkey";
58
+ logic: HotkeyActorLogic;
59
+ id: "hotkey";
60
+ } | {
61
+ src: "applyLatest";
62
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplyLatestToManual.Output, import("./setup").EditorCalls.ApplyLatestToManual.Input, EventObject>;
63
+ id: string | undefined;
64
+ } | {
65
+ src: "executeChange";
66
+ logic: PromiseActorLogic<NonReducibleUnknown, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
67
+ id: string | undefined;
68
+ } | {
69
+ src: "applySemanticLayout";
70
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplySemanticLayout.Output, import("./setup").EditorCalls.ApplySemanticLayout.Input, EventObject>;
71
+ id: string | undefined;
72
+ }, never, {
73
+ type: "has pending";
74
+ params: unknown;
75
+ } | {
76
+ type: "can undo";
77
+ params: unknown;
78
+ }, "500ms" | "wait-after-edit", EditorActorEmitedEvent>;
79
+ reenter: true;
80
+ };
81
+ };
82
+ id: string;
83
+ };
84
+ pending: {
85
+ on: {
86
+ 'change.sync-snapshot': {
87
+ target: "#queue-pending";
88
+ reenter: true;
89
+ actions: ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
90
+ src: "hotkey";
91
+ logic: HotkeyActorLogic;
92
+ id: "hotkey";
93
+ } | {
94
+ src: "applyLatest";
95
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplyLatestToManual.Output, import("./setup").EditorCalls.ApplyLatestToManual.Input, EventObject>;
96
+ id: string | undefined;
97
+ } | {
98
+ src: "executeChange";
99
+ logic: PromiseActorLogic<NonReducibleUnknown, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
100
+ id: string | undefined;
101
+ } | {
102
+ src: "applySemanticLayout";
103
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplySemanticLayout.Output, import("./setup").EditorCalls.ApplySemanticLayout.Input, EventObject>;
104
+ id: string | undefined;
105
+ }, never, never, never, never>;
106
+ };
107
+ 'change.*': {
108
+ target: "#queue-process";
109
+ actions: ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
110
+ src: "hotkey";
111
+ logic: HotkeyActorLogic;
112
+ id: "hotkey";
113
+ } | {
114
+ src: "applyLatest";
115
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplyLatestToManual.Output, import("./setup").EditorCalls.ApplyLatestToManual.Input, EventObject>;
116
+ id: string | undefined;
117
+ } | {
118
+ src: "executeChange";
119
+ logic: PromiseActorLogic<NonReducibleUnknown, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
120
+ id: string | undefined;
121
+ } | {
122
+ src: "applySemanticLayout";
123
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplySemanticLayout.Output, import("./setup").EditorCalls.ApplySemanticLayout.Input, EventObject>;
124
+ id: string | undefined;
125
+ }, never, never, never, never>;
126
+ };
127
+ 'edit.move.start': {
128
+ target: "#queue-suspended";
129
+ };
130
+ undo: {
131
+ target: "#queue-idle";
132
+ actions: ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
133
+ src: "hotkey";
134
+ logic: HotkeyActorLogic;
135
+ id: "hotkey";
136
+ } | {
137
+ src: "applyLatest";
138
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplyLatestToManual.Output, import("./setup").EditorCalls.ApplyLatestToManual.Input, EventObject>;
139
+ id: string | undefined;
140
+ } | {
141
+ src: "executeChange";
142
+ logic: PromiseActorLogic<NonReducibleUnknown, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
143
+ id: string | undefined;
144
+ } | {
145
+ src: "applySemanticLayout";
146
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplySemanticLayout.Output, import("./setup").EditorCalls.ApplySemanticLayout.Input, EventObject>;
147
+ id: string | undefined;
148
+ }, never, {
149
+ type: "has pending";
150
+ params: unknown;
151
+ } | {
152
+ type: "can undo";
153
+ params: unknown;
154
+ }, "500ms" | "wait-after-edit", EditorActorEmitedEvent>;
155
+ };
156
+ 'view.synched': {
157
+ target: "#queue-process";
158
+ guard: "has pending";
159
+ actions: () => void;
160
+ };
161
+ };
162
+ after: {
163
+ 'wait-after-edit': ({
164
+ target: "#queue-process";
165
+ guard: "has pending";
166
+ } | {
167
+ target: "#queue-idle";
168
+ })[];
169
+ };
170
+ id: string;
171
+ };
172
+ suspended: {
173
+ on: {
174
+ undo: {
175
+ target: "#queue-idle";
176
+ actions: ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
177
+ src: "hotkey";
178
+ logic: HotkeyActorLogic;
179
+ id: "hotkey";
180
+ } | {
181
+ src: "applyLatest";
182
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplyLatestToManual.Output, import("./setup").EditorCalls.ApplyLatestToManual.Input, EventObject>;
183
+ id: string | undefined;
184
+ } | {
185
+ src: "executeChange";
186
+ logic: PromiseActorLogic<NonReducibleUnknown, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
187
+ id: string | undefined;
188
+ } | {
189
+ src: "applySemanticLayout";
190
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplySemanticLayout.Output, import("./setup").EditorCalls.ApplySemanticLayout.Input, EventObject>;
191
+ id: string | undefined;
192
+ }, never, {
193
+ type: "has pending";
194
+ params: unknown;
195
+ } | {
196
+ type: "can undo";
197
+ params: unknown;
198
+ }, "500ms" | "wait-after-edit", EditorActorEmitedEvent>;
199
+ };
200
+ 'edit.*': {
201
+ target: "#queue-pending";
202
+ };
203
+ 'change.*': {
204
+ actions: ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, never, never, never, "500ms" | "wait-after-edit", never>;
205
+ };
206
+ cancel: {
207
+ target: "#queue-idle";
208
+ };
209
+ };
210
+ id: string;
211
+ };
212
+ process: {
213
+ initial: string;
214
+ tags: "busy"[];
215
+ states: {
216
+ enter: {
217
+ entry: ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
218
+ src: "hotkey";
219
+ logic: HotkeyActorLogic;
220
+ id: "hotkey";
221
+ } | {
222
+ src: "applyLatest";
223
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplyLatestToManual.Output, import("./setup").EditorCalls.ApplyLatestToManual.Input, EventObject>;
224
+ id: string | undefined;
225
+ } | {
226
+ src: "executeChange";
227
+ logic: PromiseActorLogic<NonReducibleUnknown, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
228
+ id: string | undefined;
229
+ } | {
230
+ src: "applySemanticLayout";
231
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplySemanticLayout.Output, import("./setup").EditorCalls.ApplySemanticLayout.Input, EventObject>;
232
+ id: string | undefined;
233
+ }, never, never, never, never>;
234
+ always: ({
235
+ guard: ({ context: { processing } }: GuardArgs<EditorActorContext, EditorActorEvent>) => boolean;
236
+ target: string;
237
+ } | {
238
+ target: string;
239
+ guard?: never;
240
+ })[];
241
+ };
242
+ /**
243
+ * Syncing state, some edits are not yet synced
244
+ */
245
+ applyLatestToManual: {
246
+ initial: string;
247
+ states: {
248
+ call: {
249
+ invoke: {
250
+ src: "applyLatest";
251
+ input: ({ context }: {
252
+ context: EditorActorContext;
253
+ event: EditorActorEvent;
254
+ self: ActorRef<MachineSnapshot<EditorActorContext, EditorActorEvent, Record<string, AnyActorRef>, StateValue, string, unknown, any, any>, EditorActorEvent, AnyEventObject>;
255
+ }) => {
256
+ current: DiagramView<Any> | undefined;
257
+ viewId: ViewId;
258
+ };
259
+ onDone: {
260
+ actions: ActionFunction<EditorActorContext, DoneActorEvent<import("./setup").EditorCalls.ApplyLatestToManual.Output, string>, EditorActorEvent, undefined, never, never, never, "500ms" | "wait-after-edit", never>;
261
+ target: string;
262
+ };
263
+ onError: {
264
+ target: "#queue-idle";
265
+ actions: (({ event }: ActionArgs<EditorActorContext, ErrorActorEvent<unknown, string>, EditorActorEvent>) => void)[];
266
+ };
267
+ };
268
+ };
269
+ wait: {
270
+ entry: ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
271
+ src: "hotkey";
272
+ logic: HotkeyActorLogic;
273
+ id: "hotkey";
274
+ } | {
275
+ src: "applyLatest";
276
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplyLatestToManual.Output, import("./setup").EditorCalls.ApplyLatestToManual.Input, EventObject>;
277
+ id: string | undefined;
278
+ } | {
279
+ src: "executeChange";
280
+ logic: PromiseActorLogic<NonReducibleUnknown, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
281
+ id: string | undefined;
282
+ } | {
283
+ src: "applySemanticLayout";
284
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplySemanticLayout.Output, import("./setup").EditorCalls.ApplySemanticLayout.Input, EventObject>;
285
+ id: string | undefined;
286
+ }, never, never, never, never>;
287
+ after: {
288
+ '500ms': {
289
+ target: "#queue-idle";
290
+ actions: ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, never, never, never, "500ms" | "wait-after-edit", never>;
291
+ };
292
+ };
293
+ };
294
+ };
295
+ };
296
+ /**
297
+ * User requested semantic layout, we will call the AI
298
+ */
299
+ applySemanticLayout: {
300
+ tags: "ai-semantic-layout"[];
301
+ invoke: {
302
+ src: "applySemanticLayout";
303
+ input: ({ context }: {
304
+ context: EditorActorContext;
305
+ event: EditorActorEvent;
306
+ self: ActorRef<MachineSnapshot<EditorActorContext, EditorActorEvent, Record<string, AnyActorRef>, StateValue, string, unknown, any, any>, EditorActorEvent, AnyEventObject>;
307
+ }) => {
308
+ viewId: ViewId;
309
+ };
310
+ onDone: {
311
+ target: string;
312
+ };
313
+ onError: {
314
+ actions: (({ event }: ActionArgs<EditorActorContext, ErrorActorEvent<unknown, string>, EditorActorEvent>) => void)[];
315
+ target: string;
316
+ };
317
+ };
318
+ };
319
+ /**
320
+ * Calls `executeChange` to save the snapshot
321
+ */
322
+ executeChanges: {
323
+ invoke: {
324
+ src: "executeChange";
325
+ input: ({ context: { processing, syncQueue, viewId } }: {
326
+ context: EditorActorContext;
327
+ event: EditorActorEvent;
328
+ self: ActorRef<MachineSnapshot<EditorActorContext, EditorActorEvent, Record<string, AnyActorRef>, StateValue, string, unknown, any, any>, EditorActorEvent, AnyEventObject>;
329
+ }) => {
330
+ changes: ViewChange[];
331
+ viewId: ViewId;
332
+ };
333
+ onDone: {
334
+ actions: ActionFunction<EditorActorContext, DoneActorEvent<NonReducibleUnknown, string>, EditorActorEvent, undefined, {
335
+ src: "hotkey";
336
+ logic: HotkeyActorLogic;
337
+ id: "hotkey";
338
+ } | {
339
+ src: "applyLatest";
340
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplyLatestToManual.Output, import("./setup").EditorCalls.ApplyLatestToManual.Input, EventObject>;
341
+ id: string | undefined;
342
+ } | {
343
+ src: "executeChange";
344
+ logic: PromiseActorLogic<NonReducibleUnknown, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
345
+ id: string | undefined;
346
+ } | {
347
+ src: "applySemanticLayout";
348
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplySemanticLayout.Output, import("./setup").EditorCalls.ApplySemanticLayout.Input, EventObject>;
349
+ id: string | undefined;
350
+ }, never, {
351
+ type: "has pending";
352
+ params: unknown;
353
+ } | {
354
+ type: "can undo";
355
+ params: unknown;
356
+ }, "500ms" | "wait-after-edit", EditorActorEmitedEvent>;
357
+ target: string;
358
+ };
359
+ onError: {
360
+ target: "#queue-idle";
361
+ actions: ActionFunction<EditorActorContext, ErrorActorEvent<unknown, string>, EditorActorEvent, undefined, {
362
+ src: "hotkey";
363
+ logic: HotkeyActorLogic;
364
+ id: "hotkey";
365
+ } | {
366
+ src: "applyLatest";
367
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplyLatestToManual.Output, import("./setup").EditorCalls.ApplyLatestToManual.Input, EventObject>;
368
+ id: string | undefined;
369
+ } | {
370
+ src: "executeChange";
371
+ logic: PromiseActorLogic<NonReducibleUnknown, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
372
+ id: string | undefined;
373
+ } | {
374
+ src: "applySemanticLayout";
375
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplySemanticLayout.Output, import("./setup").EditorCalls.ApplySemanticLayout.Input, EventObject>;
376
+ id: string | undefined;
377
+ }, never, never, never, never>;
378
+ };
379
+ };
380
+ };
381
+ decideNext: {
382
+ entry: ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
383
+ src: "hotkey";
384
+ logic: HotkeyActorLogic;
385
+ id: "hotkey";
386
+ } | {
387
+ src: "applyLatest";
388
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplyLatestToManual.Output, import("./setup").EditorCalls.ApplyLatestToManual.Input, EventObject>;
389
+ id: string | undefined;
390
+ } | {
391
+ src: "executeChange";
392
+ logic: PromiseActorLogic<NonReducibleUnknown, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
393
+ id: string | undefined;
394
+ } | {
395
+ src: "applySemanticLayout";
396
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplySemanticLayout.Output, import("./setup").EditorCalls.ApplySemanticLayout.Input, EventObject>;
397
+ id: string | undefined;
398
+ }, never, never, never, never>;
399
+ always: ({
400
+ guard: "has pending";
401
+ target: string;
402
+ } | {
403
+ target: "#queue-idle";
404
+ guard?: never;
405
+ })[];
406
+ };
407
+ };
408
+ on: {
409
+ 'change.*': {
410
+ actions: ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, never, never, never, "500ms" | "wait-after-edit", never>;
411
+ };
412
+ 'view.synched': {
413
+ actions: () => void;
414
+ };
415
+ };
416
+ id: string;
417
+ };
418
+ };
419
+ on: {};
420
+ };
@@ -0,0 +1,235 @@
1
+ import "../../_virtual/_rolldown/runtime.js";
2
+ import { machine } from "./setup.js";
3
+ import { typedSystem } from "../../likec4diagram/state/utils.js";
4
+ import { isViewChange } from "./types.js";
5
+ import { makeSnapshot, pushToSyncQueue, reschedule, scheduleSync, undo } from "./actions.js";
6
+ import { isNot } from "remeda";
7
+ import { invariant } from "@likec4/core";
8
+ import { assign, enqueueActions, sendTo } from "xstate";
9
+ //#region src/editor/actor/state.sync-queue.ts
10
+ var to = {
11
+ idle: { target: "#queue-idle" },
12
+ pending: { target: "#queue-pending" },
13
+ suspended: { target: "#queue-suspended" },
14
+ process: { target: "#queue-process" }
15
+ };
16
+ var idOf = (t) => ({ id: t.target.substring(1) });
17
+ /**
18
+ * Idle state, no pending operations
19
+ */
20
+ var idle = machine.createStateConfig({
21
+ ...idOf(to.idle),
22
+ always: {
23
+ guard: "has pending",
24
+ ...to.pending
25
+ },
26
+ on: {
27
+ "change.sync-snapshot": {
28
+ actions: pushToSyncQueue(),
29
+ ...to.pending
30
+ },
31
+ "change.*": {
32
+ actions: pushToSyncQueue(),
33
+ ...to.process
34
+ },
35
+ "undo": {
36
+ actions: undo(),
37
+ reenter: true,
38
+ ...to.idle
39
+ }
40
+ }
41
+ });
42
+ /**
43
+ * Has pending operations
44
+ */
45
+ var pending = machine.createStateConfig({
46
+ ...idOf(to.pending),
47
+ on: {
48
+ "change.sync-snapshot": {
49
+ reenter: true,
50
+ actions: pushToSyncQueue(),
51
+ ...to.pending
52
+ },
53
+ "change.*": {
54
+ actions: pushToSyncQueue(),
55
+ ...to.process
56
+ },
57
+ "edit.move.start": { ...to.suspended },
58
+ "undo": {
59
+ actions: undo(),
60
+ ...to.idle
61
+ },
62
+ "view.synched": {
63
+ guard: "has pending",
64
+ actions: () => {},
65
+ ...to.process
66
+ }
67
+ },
68
+ after: { "wait-after-edit": [{
69
+ guard: "has pending",
70
+ ...to.process
71
+ }, { ...to.idle }] }
72
+ });
73
+ /**
74
+ * When editing starts, we suspend the queue
75
+ */
76
+ var suspended = machine.createStateConfig({
77
+ ...idOf(to.suspended),
78
+ on: {
79
+ "undo": {
80
+ actions: undo(),
81
+ ...to.idle
82
+ },
83
+ "edit.*": { ...to.pending },
84
+ "change.*": { actions: reschedule() },
85
+ "cancel": { ...to.idle }
86
+ }
87
+ });
88
+ var peekFromQueue = () => machine.assign(({ system, context: { syncQueue, processing } }) => {
89
+ if (processing) return {};
90
+ let [head, ...tail] = syncQueue;
91
+ if (head === "sync-snapshot") head = makeSnapshot(system).change;
92
+ return {
93
+ processing: head ?? null,
94
+ syncQueue: tail
95
+ };
96
+ });
97
+ var clearProcessing = () => ({ processing: null });
98
+ /**
99
+ * Processing pending operation
100
+ */
101
+ var process = machine.createStateConfig({
102
+ ...idOf(to.process),
103
+ initial: "enter",
104
+ tags: ["busy"],
105
+ states: {
106
+ enter: {
107
+ entry: peekFromQueue(),
108
+ always: [
109
+ {
110
+ guard: ({ context: { processing } }) => !processing,
111
+ ...to.idle
112
+ },
113
+ {
114
+ guard: ({ context: { processing } }) => processing === "apply-latest-to-manual",
115
+ target: "applyLatestToManual"
116
+ },
117
+ {
118
+ guard: ({ context: { processing } }) => processing === "apply-semantic-layout",
119
+ target: "applySemanticLayout"
120
+ },
121
+ { target: "executeChanges" }
122
+ ]
123
+ },
124
+ /**
125
+ * Syncing state, some edits are not yet synced
126
+ */
127
+ applyLatestToManual: machine.createStateConfig({
128
+ initial: "call",
129
+ states: {
130
+ call: { invoke: {
131
+ src: "applyLatest",
132
+ input: ({ context }) => {
133
+ const current = context.history?.head.change.layout;
134
+ return {
135
+ current: current?._layout === "manual" ? current : void 0,
136
+ viewId: context.viewId
137
+ };
138
+ },
139
+ onDone: {
140
+ actions: sendTo(typedSystem.diagramActor, ({ event }) => ({
141
+ type: "update.view",
142
+ view: event.output.updated
143
+ }), { delay: 10 }),
144
+ target: "wait"
145
+ },
146
+ onError: {
147
+ actions: [({ event }) => {
148
+ console.error(event.error);
149
+ }],
150
+ ...to.idle
151
+ }
152
+ } },
153
+ wait: {
154
+ entry: assign(clearProcessing),
155
+ after: { "500ms": {
156
+ actions: scheduleSync(),
157
+ ...to.idle
158
+ } }
159
+ }
160
+ }
161
+ }),
162
+ /**
163
+ * User requested semantic layout, we will call the AI
164
+ */
165
+ applySemanticLayout: machine.createStateConfig({
166
+ tags: ["ai-semantic-layout"],
167
+ invoke: {
168
+ src: "applySemanticLayout",
169
+ input: ({ context }) => ({ viewId: context.viewId }),
170
+ onDone: { target: "decideNext" },
171
+ onError: {
172
+ actions: [({ event }) => {
173
+ console.error(event.error);
174
+ }],
175
+ target: "decideNext"
176
+ }
177
+ }
178
+ }),
179
+ /**
180
+ * Calls `executeChange` to save the snapshot
181
+ */
182
+ executeChanges: machine.createStateConfig({ invoke: {
183
+ src: "executeChange",
184
+ input: ({ context: { processing, syncQueue, viewId } }) => {
185
+ invariant(processing && isViewChange(processing));
186
+ return {
187
+ changes: [processing, ...syncQueue.filter(isViewChange)],
188
+ viewId
189
+ };
190
+ },
191
+ onDone: {
192
+ actions: enqueueActions(({ context, event, enqueue }) => {
193
+ enqueue.assign({
194
+ processing: null,
195
+ syncQueue: context.syncQueue.filter(isNot(isViewChange))
196
+ });
197
+ }),
198
+ target: "decideNext"
199
+ },
200
+ onError: {
201
+ actions: assign(({ event }) => {
202
+ console.error("executeChanges onError", { error: event.error });
203
+ return {
204
+ processing: null,
205
+ syncQueue: []
206
+ };
207
+ }),
208
+ ...to.idle
209
+ }
210
+ } }),
211
+ decideNext: {
212
+ entry: assign(clearProcessing),
213
+ always: [{
214
+ guard: "has pending",
215
+ target: "enter"
216
+ }, { ...to.idle }]
217
+ }
218
+ },
219
+ on: {
220
+ "change.*": { actions: reschedule() },
221
+ "view.synched": { actions: () => {} }
222
+ }
223
+ });
224
+ var syncQueue = machine.createStateConfig({
225
+ initial: "idle",
226
+ states: {
227
+ idle,
228
+ pending,
229
+ suspended,
230
+ process
231
+ },
232
+ on: {}
233
+ });
234
+ //#endregion
235
+ export { syncQueue };