@likec4/diagram 1.56.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 (208) hide show
  1. package/dist/LikeC4Diagram.js +3 -1
  2. package/dist/LikeC4View.js +47 -55
  3. package/dist/adhoc-editor/EditorPanel.d.ts +1 -1
  4. package/dist/adhoc-editor/ElementsTree.d.ts +1 -1
  5. package/dist/adhoc-editor/ElementsTree.js +2 -6
  6. package/dist/adhoc-editor/LikeC4AdHocViewEditor.d.ts +1 -1
  7. package/dist/adhoc-editor/components/Tree.d.ts +5 -5
  8. package/dist/adhoc-editor/state/ActorProvider.d.ts +1 -1
  9. package/dist/adhoc-editor/state/panel.d.ts +1 -1
  10. package/dist/adhoc-editor/viewrules/ViewRulesPanel.d.ts +1 -1
  11. package/dist/base/BaseXYFlow.d.ts +1 -1
  12. package/dist/base-primitives/Markdown.d.ts +1 -1
  13. package/dist/base-primitives/NodeHandles.d.ts +1 -1
  14. package/dist/base-primitives/compound/CompoundActionButton.d.ts +1 -1
  15. package/dist/base-primitives/compound/CompoundDetailsButton.d.ts +1 -1
  16. package/dist/base-primitives/compound/CompoundNodeContainer.d.ts +1 -1
  17. package/dist/base-primitives/compound/CompoundTitle.d.ts +1 -1
  18. package/dist/base-primitives/compound/actionbtns.css.d.ts +1 -1
  19. package/dist/base-primitives/edge/EdgeActionButton.d.ts +1 -1
  20. package/dist/base-primitives/edge/EdgeContainer.d.ts +1 -1
  21. package/dist/base-primitives/edge/EdgeLabelContainer.d.ts +1 -1
  22. package/dist/base-primitives/edge/EdgeMarkers.d.ts +8 -8
  23. package/dist/base-primitives/element/ElementActionButtons.d.ts +1 -1
  24. package/dist/base-primitives/element/ElementData.d.ts +2 -2
  25. package/dist/base-primitives/element/ElementDetailsButton.d.ts +1 -1
  26. package/dist/base-primitives/element/ElementShape.d.ts +1 -1
  27. package/dist/base-primitives/element/ElementTags.d.ts +1 -1
  28. package/dist/base-primitives/element/ElementTags.js +1 -3
  29. package/dist/components/ErrorFallback.d.ts +2 -2
  30. package/dist/components/NavigationPanel.d.ts +2 -2
  31. package/dist/components/PortalToContainer.d.ts +1 -1
  32. package/dist/components/RootContainer.d.ts +1 -1
  33. package/dist/components/RootContainer.js +19 -18
  34. package/dist/components/SearchControl.d.ts +2 -2
  35. package/dist/components/ViewNotFound.d.ts +2 -2
  36. package/dist/context/CurrentViewModelProvider.d.ts +1 -1
  37. package/dist/context/DefaultMantineProvider.d.ts +1 -1
  38. package/dist/context/DiagramEventHandlers.d.ts +1 -1
  39. package/dist/context/DiagramFeatures.d.ts +1 -1
  40. package/dist/context/DiagramFeatures.js +5 -0
  41. package/dist/context/EnsureMantine.d.ts +1 -1
  42. package/dist/context/FramerMotionConfig.d.ts +3 -3
  43. package/dist/context/FramerMotionConfig.js +2 -2
  44. package/dist/context/IconRenderer.d.ts +2 -2
  45. package/dist/context/IconRenderer.js +32 -12
  46. package/dist/context/LikeC4ModelContext.d.ts +1 -1
  47. package/dist/context/RootContainerContext.d.ts +10 -17
  48. package/dist/context/RootContainerContext.js +1 -13
  49. package/dist/context/ShadowRootContext.d.ts +3 -0
  50. package/dist/context/ShadowRootContext.js +5 -0
  51. package/dist/context/TagStylesContext.d.ts +2 -1
  52. package/dist/context/TagStylesContext.js +5 -7
  53. package/dist/custom/index.d.ts +1 -1
  54. package/dist/custom/index.js +1 -2
  55. package/dist/editor/LikeC4EditorCallbacks.d.ts +5 -0
  56. package/dist/editor/LikeC4EditorProvider.d.ts +2 -2
  57. package/dist/editor/actor/actions.d.ts +174 -0
  58. package/dist/editor/actor/actions.js +188 -0
  59. package/dist/editor/{hotkeyActor.d.ts → actor/hotkey.d.ts} +2 -2
  60. package/dist/editor/{hotkeyActor.js → actor/hotkey.js} +11 -4
  61. package/dist/editor/{editorActor.states.d.ts → actor/machine.d.ts} +5 -3
  62. package/dist/editor/actor/machine.js +23 -0
  63. package/dist/editor/actor/setup.d.ts +55 -0
  64. package/dist/editor/{editorActor.setup.js → actor/setup.js} +14 -10
  65. package/dist/editor/actor/state.editor.d.ts +147 -0
  66. package/dist/editor/actor/state.editor.js +56 -0
  67. package/dist/editor/actor/state.sync-queue.d.ts +612 -0
  68. package/dist/editor/actor/state.sync-queue.js +272 -0
  69. package/dist/editor/actor/types.d.ts +64 -0
  70. package/dist/editor/actor/types.js +5 -0
  71. package/dist/editor/applyChangesToManualLayout.js +1 -1
  72. package/dist/editor/index.d.ts +2 -1
  73. package/dist/editor/useEditorActorLogic.d.ts +8 -2
  74. package/dist/editor/useEditorActorLogic.js +39 -7
  75. package/dist/hooks/useDiagram.js +6 -1
  76. package/dist/hooks/useDiagramCompareLayout.js +1 -1
  77. package/dist/hooks/useEditorActor.d.ts +9 -0
  78. package/dist/hooks/useEditorActor.js +27 -0
  79. package/dist/hooks/useLikeC4ElementsTree.d.ts +3 -2
  80. package/dist/hooks/useLikeC4ElementsTree.js +3 -1
  81. package/dist/index.d.ts +2 -0
  82. package/dist/index.js +3 -1
  83. package/dist/likec4diagram/DiagramUI.d.ts +1 -1
  84. package/dist/likec4diagram/DiagramUI.js +8 -4
  85. package/dist/likec4diagram/DiagramXYFlow.js +26 -14
  86. package/dist/likec4diagram/custom/edges/EdgeDrifts.d.ts +1 -1
  87. package/dist/likec4diagram/custom/edges/RelationshipEdge.js +127 -14
  88. package/dist/likec4diagram/custom/edges/SequenceStepEdge.d.ts +1 -1
  89. package/dist/likec4diagram/custom/edges/edges.css.d.ts +1 -0
  90. package/dist/likec4diagram/custom/edges/edges.css.js +5 -1
  91. package/dist/likec4diagram/custom/nodes/CompoundActions.d.ts +1 -1
  92. package/dist/likec4diagram/custom/nodes/ElementActions.d.ts +2 -2
  93. package/dist/likec4diagram/custom/nodes/NodeDrifts.d.ts +1 -1
  94. package/dist/likec4diagram/custom/nodes/NodeNotes.d.ts +1 -1
  95. package/dist/likec4diagram/custom/nodes/SequenceActorNode.d.ts +2 -2
  96. package/dist/likec4diagram/custom/nodes/nodes.d.ts +7 -7
  97. package/dist/likec4diagram/custom/nodes/toolbar/ColorButton.d.ts +3 -3
  98. package/dist/likec4diagram/custom/nodes/toolbar/CompoundToolbar.d.ts +2 -2
  99. package/dist/likec4diagram/custom/nodes/toolbar/ElementToolbar.d.ts +2 -2
  100. package/dist/likec4diagram/custom/nodes/toolbar/Toolbar.d.ts +1 -1
  101. package/dist/likec4diagram/custom/nodes/toolbar/_shared.d.ts +3 -3
  102. package/dist/likec4diagram/relationship-popover/RelationshipPopover.d.ts +1 -1
  103. package/dist/likec4diagram/relationship-popover/components.d.ts +2 -2
  104. package/dist/likec4diagram/state/DiagramActorProvider.d.ts +1 -1
  105. package/dist/likec4diagram/state/aligners.js +3 -0
  106. package/dist/likec4diagram/state/assign.js +1 -1
  107. package/dist/likec4diagram/state/createViewChange.js +1 -0
  108. package/dist/likec4diagram/state/diagram-api.d.ts +16 -0
  109. package/dist/likec4diagram/state/diagram-api.js +13 -7
  110. package/dist/likec4diagram/state/machine.actions.js +10 -10
  111. package/dist/likec4diagram/state/machine.d.ts +1 -1
  112. package/dist/likec4diagram/state/machine.setup.js +1 -1
  113. package/dist/likec4diagram/state/types.d.ts +1 -1
  114. package/dist/likec4diagram/state/utils.d.ts +1 -1
  115. package/dist/likec4diagram/types.d.ts +2 -0
  116. package/dist/likec4diagram/ui/LayoutDriftFrame.d.ts +1 -1
  117. package/dist/likec4diagram/ui/notation/NotationPanel.d.ts +1 -1
  118. package/dist/likec4diagram/useLayoutConstraints.js +2 -0
  119. package/dist/likec4diagram/xyflow-diagram/diagram-view.js +4 -2
  120. package/dist/likec4diagram/xyflow-sequence/sequence-layout.js +1 -0
  121. package/dist/navigationpanel/NavigationPanel.d.ts +1 -1
  122. package/dist/navigationpanel/NavigationPanelControls.d.ts +1 -1
  123. package/dist/navigationpanel/NavigationPanelDropdown.d.ts +1 -1
  124. package/dist/navigationpanel/NavigationPanelDropdown.js +2 -2
  125. package/dist/navigationpanel/_common.d.ts +2 -2
  126. package/dist/navigationpanel/comparepanel/CompareActionsMenu.d.ts +1 -1
  127. package/dist/navigationpanel/comparepanel/ComparePanel.d.ts +1 -1
  128. package/dist/navigationpanel/comparepanel/ComparePanelControls.d.ts +1 -1
  129. package/dist/navigationpanel/comparepanel/DriftsSummary.d.ts +1 -1
  130. package/dist/navigationpanel/comparepanel/LayoutTypeSwitcher.d.ts +1 -1
  131. package/dist/navigationpanel/controls/DetailsControls.d.ts +1 -1
  132. package/dist/navigationpanel/controls/LayoutWarning.d.ts +1 -1
  133. package/dist/navigationpanel/controls/LogoButton.d.ts +1 -1
  134. package/dist/navigationpanel/controls/NavigationButtons.d.ts +1 -1
  135. package/dist/navigationpanel/controls/OpenSource.d.ts +1 -1
  136. package/dist/navigationpanel/controls/SearchControl.d.ts +1 -1
  137. package/dist/navigationpanel/controls/ToggleReadonly.d.ts +1 -1
  138. package/dist/navigationpanel/controls/ToggleReadonly.js +4 -2
  139. package/dist/navigationpanel/editorpanel/ApplySemanticLayout.d.ts +4 -0
  140. package/dist/navigationpanel/editorpanel/ApplySemanticLayout.js +36 -0
  141. package/dist/navigationpanel/editorpanel/CenterCamera.d.ts +1 -1
  142. package/dist/navigationpanel/editorpanel/ChangeAutoLayoutButton.d.ts +1 -1
  143. package/dist/navigationpanel/editorpanel/EditorPanel.d.ts +1 -1
  144. package/dist/navigationpanel/editorpanel/EditorPanel.js +45 -33
  145. package/dist/navigationpanel/editorpanel/ManualLayoutToolsButton.d.ts +1 -1
  146. package/dist/navigationpanel/editorpanel/ToggleReadonly.d.ts +1 -1
  147. package/dist/navigationpanel/styles.css.d.ts +1 -1
  148. package/dist/navigationpanel/walkthrough/ActiveWalkthroughControls.d.ts +1 -1
  149. package/dist/navigationpanel/walkthrough/DynamicViewControls.d.ts +62 -62
  150. package/dist/navigationpanel/walkthrough/WalkthroughPanel.d.ts +1 -1
  151. package/dist/overlays/Overlays.d.ts +1 -1
  152. package/dist/overlays/element-details/ElementDetails.d.ts +1 -1
  153. package/dist/overlays/element-details/ElementDetailsCard.d.ts +1 -1
  154. package/dist/overlays/element-details/MetadataValue.d.ts +2 -2
  155. package/dist/overlays/element-details/TabPanelRelationships.d.ts +1 -1
  156. package/dist/overlays/element-details/TabPanelStructure.d.ts +2 -2
  157. package/dist/overlays/overlay/Overlay.d.ts +16 -0
  158. package/dist/overlays/overlay/Overlay.js +50 -52
  159. package/dist/overlays/overlaysActor.js +28 -27
  160. package/dist/overlays/relationship-details/RelationshipDetails.d.ts +1 -1
  161. package/dist/overlays/relationship-details/SelectEdge.d.ts +1 -1
  162. package/dist/overlays/relationship-details/custom/ElementActions.d.ts +1 -1
  163. package/dist/overlays/relationship-details/custom/nodeTypes.d.ts +4 -5
  164. package/dist/overlays/relationship-details/custom/nodeTypes.js +25 -24
  165. package/dist/overlays/relationships-browser/RelationshipsBrowser.d.ts +1 -1
  166. package/dist/overlays/relationships-browser/SelectElement.d.ts +1 -1
  167. package/dist/overlays/relationships-browser/SelectElement.js +2 -2
  168. package/dist/overlays/relationships-browser/custom/ElementActions.d.ts +1 -1
  169. package/dist/overlays/relationships-browser/custom/EmptyNode.d.ts +1 -1
  170. package/dist/overlays/relationships-browser/custom/nodeTypes.d.ts +4 -4
  171. package/dist/projects-overview/ProjectsOverview.d.ts +1 -1
  172. package/dist/projects-overview/custom/nodeTypes.d.ts +1 -1
  173. package/dist/projects-overview/panel/ProjectsOverviewPanel.d.ts +1 -1
  174. package/dist/search/Search.d.ts +6 -3
  175. package/dist/search/Search.js +60 -71
  176. package/dist/search/XStateSearchAdapter.d.ts +1 -1
  177. package/dist/search/components/ElementsColumn.d.ts +1 -1
  178. package/dist/search/components/ElementsColumn.js +12 -8
  179. package/dist/search/components/PickView.d.ts +1 -1
  180. package/dist/search/components/SearchByTags.d.ts +1 -1
  181. package/dist/search/components/SearchInput.d.ts +1 -1
  182. package/dist/search/components/ViewsColum.d.ts +3 -3
  183. package/dist/search/components/_shared.css.d.ts +1 -1
  184. package/dist/search/searchActor.js +30 -26
  185. package/dist/shadowroot/ShadowRoot.d.ts +6 -6
  186. package/dist/shadowroot/ShadowRoot.js +68 -23
  187. package/dist/shadowroot/index.d.ts +1 -0
  188. package/dist/shadowroot/styles.d.ts +13 -0
  189. package/dist/shadowroot/styles.js +60 -0
  190. package/dist/styles2.js +1 -1
  191. package/package.json +33 -40
  192. package/panda.buildinfo.json +19 -22
  193. package/src/styles-font.css +114 -0
  194. package/src/styles-min.css +2 -0
  195. package/src/styles-xyflow.css +1 -0
  196. package/src/styles.css +3 -0
  197. package/styles-min.css +1 -1
  198. package/styles-xyflow.css +1 -1
  199. package/styles.css +1 -1
  200. package/dist/bundle/index.d.ts +0 -1
  201. package/dist/editor/editorActor.actions.d.ts +0 -153
  202. package/dist/editor/editorActor.actions.js +0 -133
  203. package/dist/editor/editorActor.setup.d.ts +0 -84
  204. package/dist/editor/editorActor.states.js +0 -219
  205. package/dist/hooks/useOverlaysActor.js +0 -11
  206. package/dist/hooks/useSearchActor.js +0 -11
  207. package/dist/shadowroot/styles.css.d.ts +0 -4
  208. package/dist/shadowroot/styles.css.js +0 -62
@@ -3,7 +3,7 @@ import { jsx } from "react/jsx-runtime";
3
3
  import { useMantineStyleNonce } from "@mantine/core";
4
4
  import { LazyMotion, MotionConfig, domMax } from "motion/react";
5
5
  //#region src/context/FramerMotionConfig.tsx
6
- var FramerMotionConfig = ({ reducedMotion = "user", children }) => {
6
+ function FramerMotionConfig({ reducedMotion = "user", children }) {
7
7
  const nonce = useMantineStyleNonce()?.();
8
8
  return /* @__PURE__ */ jsx(LazyMotion, {
9
9
  features: domMax,
@@ -14,6 +14,6 @@ var FramerMotionConfig = ({ reducedMotion = "user", children }) => {
14
14
  children
15
15
  })
16
16
  });
17
- };
17
+ }
18
18
  //#endregion
19
19
  export { FramerMotionConfig };
@@ -17,7 +17,7 @@ import { ElementIconRenderer } from '../LikeC4Diagram.props';
17
17
  */
18
18
  export declare function IconRendererProvider({ value, children, }: PropsWithChildren<{
19
19
  value: ElementIconRenderer | null;
20
- }>): import("react/jsx-runtime").JSX.Element;
20
+ }>): import("react").JSX.Element;
21
21
  export declare function IconRenderer({ element, className, style, }: {
22
22
  element?: {
23
23
  id: string;
@@ -36,4 +36,4 @@ export declare function IconOrShapeRenderer({ element, className, style, }: {
36
36
  };
37
37
  className?: string;
38
38
  style?: CSSProperties | undefined;
39
- }): import("react/jsx-runtime").JSX.Element;
39
+ }): import("react").JSX.Element;
@@ -1,7 +1,7 @@
1
1
  import "../_virtual/_rolldown/runtime.js";
2
2
  import { cx } from "@likec4/styles/css";
3
3
  import { IconBrowser, IconCylinder, IconDeviceMobile, IconFileText, IconRectangularPrism, IconReorder, IconUser } from "@tabler/icons-react";
4
- import { createContext, useContext } from "react";
4
+ import { createContext, useContext, useMemo } from "react";
5
5
  import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
6
6
  //#region src/context/IconRenderer.tsx
7
7
  var IconRendererContext = createContext(null);
@@ -47,17 +47,28 @@ function IconRenderer({ element, className, style }) {
47
47
  const RenderIcon = useContext(IconRendererContext);
48
48
  if (!element || !element.icon || element.icon === "none") return null;
49
49
  let icon;
50
- if (element.icon.startsWith("http://") || element.icon.startsWith("https://") || element.icon.startsWith("data:image")) {
51
- const svgContent = element.icon.startsWith("data:image/svg+xml") ? decodeSvgDataUrl(element.icon) : null;
52
- if (svgContent) icon = /* @__PURE__ */ jsx("span", {
53
- style: { display: "contents" },
54
- dangerouslySetInnerHTML: { __html: svgContent }
55
- });
56
- else icon = /* @__PURE__ */ jsx("img", {
57
- src: element.icon,
58
- alt: element.title
59
- });
60
- } else if (RenderIcon) icon = /* @__PURE__ */ jsx(RenderIcon, { node: element });
50
+ switch (true) {
51
+ case element.icon.startsWith("data:image/svg+xml"):
52
+ icon = /* @__PURE__ */ jsx(SvgDataUrlIcon, {
53
+ dataUrl: element.icon,
54
+ alt: element.title
55
+ });
56
+ break;
57
+ case element.icon.startsWith("http://"):
58
+ case element.icon.startsWith("https://"):
59
+ case element.icon.startsWith("data:image"):
60
+ icon = /* @__PURE__ */ jsx("img", {
61
+ src: element.icon,
62
+ alt: element.title
63
+ });
64
+ break;
65
+ case !!RenderIcon:
66
+ icon = /* @__PURE__ */ jsx(RenderIcon, { node: element });
67
+ break;
68
+ default:
69
+ icon = null;
70
+ break;
71
+ }
61
72
  if (!icon) return null;
62
73
  return /* @__PURE__ */ jsx("div", {
63
74
  className: cx(className, "likec4-element-icon"),
@@ -93,5 +104,14 @@ function IconOrShapeRenderer({ element, className, style }) {
93
104
  style
94
105
  });
95
106
  }
107
+ function SvgDataUrlIcon({ dataUrl, ...props }) {
108
+ const svgContent = useMemo(() => decodeSvgDataUrl(dataUrl), [dataUrl]);
109
+ if (!svgContent) return null;
110
+ return /* @__PURE__ */ jsx("span", {
111
+ ...props,
112
+ style: { display: "contents" },
113
+ dangerouslySetInnerHTML: { __html: svgContent }
114
+ });
115
+ }
96
116
  //#endregion
97
117
  export { IconOrShapeRenderer, IconRenderer, IconRendererProvider };
@@ -6,7 +6,7 @@ type UnknownLayouted = t.aux.UnknownLayouted;
6
6
  export declare const LikeC4ModelContextProvider: Provider<LikeC4Model<any> | null>;
7
7
  export type CurrentViewModel = LikeC4ViewModel<UnknownLayouted, LayoutedView<UnknownLayouted>>;
8
8
  export declare const CurrentViewModelContext: Provider<CurrentViewModel | null>;
9
- export declare function EnsureCurrentViewModel({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element | null;
9
+ export declare function EnsureCurrentViewModel({ children }: PropsWithChildren): import("react").JSX.Element | null;
10
10
  /**
11
11
  * @returns The LikeC4Model from context, or null if no LikeC4ModelProvider is found.
12
12
  */
@@ -1,26 +1,19 @@
1
1
  import { WritableAtom } from 'nanostores';
2
- import { RefObject, Provider, Context } from 'react';
3
- export declare const RootContainerContextProvider: Provider<{
4
- id: string;
5
- selector: string;
6
- ref: RefObject<HTMLDivElement | null>;
7
- } | null>;
8
- export declare function useRootContainerContext(): {
9
- id: string;
10
- selector: string;
11
- ref: RefObject<HTMLDivElement | null>;
12
- } | null;
13
- export declare function useRootContainer(): {
14
- id: string;
15
- selector: string;
16
- ref: RefObject<HTMLDivElement | null>;
2
+ import { RefObject, Provider } from 'react';
3
+ export type RootContainerContextType = {
4
+ readonly id: string;
5
+ readonly selector: string;
6
+ readonly ref: RefObject<HTMLDivElement | null>;
7
+ readonly $panning: WritableAtom<boolean>;
8
+ readonly reducedGraphics: boolean;
17
9
  };
10
+ export declare const RootContainerContextProvider: Provider<RootContainerContextType | null>;
11
+ export declare function useRootContainerContext(): RootContainerContextType | null;
12
+ export declare function useRootContainer(): RootContainerContextType;
18
13
  export declare function useRootContainerRef(): RefObject<HTMLDivElement | null>;
19
14
  export declare function useRootContainerElement(): HTMLDivElement | null;
20
- export declare const ReduceGraphicsModeProvider: Provider<boolean | null>;
21
15
  /**
22
16
  * Hook to determine if reduced graphics mode is enabled.
23
17
  */
24
18
  export declare function useIsReducedGraphics(): boolean;
25
- export declare const PanningAtomSafeCtx: Context<WritableAtom<boolean> | null>, usePanningAtom: () => WritableAtom<boolean>;
26
19
  export declare function useIsPanning(): boolean;
@@ -1,6 +1,5 @@
1
1
  import "../_virtual/_rolldown/runtime.js";
2
2
  import { createContext, useContext } from "react";
3
- import { createSafeContext } from "@mantine/core";
4
3
  import "@nanostores/react";
5
4
  //#region src/context/RootContainerContext.tsx
6
5
  var RootContainerContext = createContext(null);
@@ -19,16 +18,5 @@ function useRootContainerRef() {
19
18
  function useRootContainerElement() {
20
19
  return useRootContainer().ref.current;
21
20
  }
22
- var ReduceGraphicsModeCtx = createContext(null);
23
- var ReduceGraphicsModeProvider = ReduceGraphicsModeCtx.Provider;
24
- /**
25
- * Hook to determine if reduced graphics mode is enabled.
26
- */
27
- function useIsReducedGraphics() {
28
- const isReduced = useContext(ReduceGraphicsModeCtx);
29
- if (isReduced === null) console.warn("ReduceGraphicsMode is not provided");
30
- return isReduced ?? false;
31
- }
32
- var [PanningAtomSafeCtx, usePanningAtom] = createSafeContext("PanningAtomSafeCtx is not provided");
33
21
  //#endregion
34
- export { PanningAtomSafeCtx, ReduceGraphicsModeProvider, RootContainerContextProvider, useIsReducedGraphics, usePanningAtom, useRootContainerContext, useRootContainerElement, useRootContainerRef };
22
+ export { RootContainerContextProvider, useRootContainer, useRootContainerContext, useRootContainerElement, useRootContainerRef };
@@ -0,0 +1,3 @@
1
+ import { Context } from 'react';
2
+ export declare const ShadowRootContext: Context<ShadowRoot | null>;
3
+ export declare function useShadowRoot(): ShadowRoot;
@@ -0,0 +1,5 @@
1
+ import { createContext } from "react";
2
+ //#region src/context/ShadowRootContext.tsx
3
+ var ShadowRootContext = createContext(null);
4
+ //#endregion
5
+ export { ShadowRootContext };
@@ -1,7 +1,8 @@
1
1
  import { TagSpecification } from '@likec4/core';
2
2
  import { PropsWithChildren } from 'react';
3
+ export declare const generateColorVars: (spec: TagSpecification) => string;
3
4
  export declare function TagStylesProvider({ children, rootSelector }: PropsWithChildren<{
4
5
  rootSelector: string;
5
- }>): import("react/jsx-runtime").JSX.Element;
6
+ }>): import("react").JSX.Element;
6
7
  export declare function useTagSpecifications(): Record<string, TagSpecification>;
7
8
  export declare function useTagSpecification(tag: string): TagSpecification;
@@ -1,19 +1,20 @@
1
1
  import "../_virtual/_rolldown/runtime.js";
2
2
  import { useLikeC4Specification } from "../hooks/useLikeC4Model.js";
3
- import { createContext, memo, useContext } from "react";
3
+ import { createContext, memo } from "react";
4
4
  import { jsx, jsxs } from "react/jsx-runtime";
5
5
  import { entries, flatMap, isEmpty, join, pipe } from "remeda";
6
6
  import { isTagColorSpecified } from "@likec4/core";
7
7
  import { useMantineStyleNonce } from "@mantine/core";
8
- import { DefaultTagColors } from "@likec4/core/styles";
8
+ import { DefaultTagColors, getContrastedColorsAPCA, isValidColor } from "@likec4/core/styles";
9
9
  //#region src/context/TagStylesContext.tsx
10
10
  var TagStylesContext = createContext({});
11
11
  var radixColors = DefaultTagColors;
12
12
  var generateColorVars = (spec) => {
13
13
  const color = spec.color;
14
- if (isTagColorSpecified(spec)) return `
14
+ if (isTagColorSpecified(spec) && isValidColor(color)) return `
15
15
  --colors-likec4-tag-bg: ${color};
16
16
  --colors-likec4-tag-bg-hover: color-mix(in oklab, ${color}, var(--colors-likec4-mix-color) 20%);
17
+ --colors-likec4-tag-text: ${getContrastedColorsAPCA(color).hiContrast};
17
18
  `;
18
19
  if (!radixColors.includes(color)) return "";
19
20
  let textcolor = "12";
@@ -59,8 +60,5 @@ var TagStylesheet = memo(({ stylesheet, nonce }) => {
59
60
  nonce
60
61
  });
61
62
  });
62
- function useTagSpecification(tag) {
63
- return useContext(TagStylesContext)[tag] ?? { color: "tomato" };
64
- }
65
63
  //#endregion
66
- export { TagStylesProvider, useTagSpecification };
64
+ export { TagStylesProvider };
@@ -5,11 +5,11 @@ export * from './primitives';
5
5
  export type { BaseEdge, BaseEdgeData, BaseEdgeProps, BaseEdgePropsWithData, BaseNode, BaseNodeData, BaseNodeProps, BaseNodePropsWithData, } from '../base/types';
6
6
  export type { DiagramNodeWithNavigate, ElementIconRenderer, ElementIconRendererProps, LikeC4ColorScheme, LikeC4DiagramEventHandlers, LikeC4DiagramProperties, NodeRenderers, OnCanvasClick, OnEdgeClick, OnNavigateTo, OnNodeClick, OpenSourceParams, PaddingUnit, PaddingWithUnit, ViewPadding, WhereOperator, } from '../LikeC4Diagram.props';
7
7
  export { Base } from '../base/Base';
8
+ export type { XYStoreState } from '../hooks/useXYFlow';
8
9
  export type { Types } from '../likec4diagram/types';
9
10
  export { type EnabledFeatures, IfEnabled, IfNotEnabled, IfNotReadOnly, IfReadOnly, useEnabledFeatures, } from '../context/DiagramFeatures';
10
11
  export { Overlay } from '../overlays/overlay/Overlay';
11
12
  export type { OverlayProps } from '../overlays/overlay/Overlay';
12
13
  export { PortalToContainer } from '../components/PortalToContainer';
13
- export { ShadowRoot } from '../shadowroot/ShadowRoot';
14
14
  export { FramerMotionConfig } from '../context/FramerMotionConfig';
15
15
  export { NavigationPanel } from '../components/NavigationPanel';
@@ -35,7 +35,6 @@ import { CompoundDeploymentToolbar, CompoundElementToolbar } from "../likec4diag
35
35
  import { DeploymentElementToolbar, ElementToolbar } from "../likec4diagram/custom/nodes/toolbar/ElementToolbar.js";
36
36
  import { CompoundDeploymentNode, CompoundDetailsButtonWithHandler, CompoundElementNode, DeploymentNode, ElementDetailsButtonWithHandler, ElementNode, ViewGroupNode } from "../likec4diagram/custom/nodes/nodes.js";
37
37
  import { SequenceActorNode, SequenceParallelArea } from "../likec4diagram/custom/nodes/SequenceActorNode.js";
38
- import { ShadowRoot } from "../shadowroot/ShadowRoot.js";
39
38
  import { NavigationPanel } from "../components/NavigationPanel.js";
40
39
  import { compoundDeploymentNode, compoundElementNode, deploymentNode, elementNode, sequenceActorNode, viewGroupNode } from "./customNodes.js";
41
- export { Base, CompoundActionButton, CompoundActions, CompoundDeploymentNode, CompoundDeploymentToolbar, CompoundDetailsButton, CompoundDetailsButtonWithHandler, CompoundElementNode, CompoundElementToolbar, CompoundNodeContainer, CompoundTitle, DefaultHandles, DeploymentElementActions, DeploymentElementToolbar, DeploymentNode, ElementActionButtons, ElementActions, ElementData, ElementDetailsButton, ElementDetailsButtonWithHandler, ElementNode, ElementNodeContainer, ElementShape, ElementTag, ElementTags, ElementToolbar, FramerMotionConfig, IfEnabled, IfNotEnabled, IfNotReadOnly, IfReadOnly, Markdown, NavigationPanel, Overlay, PortalToContainer, SequenceActorNode, SequenceParallelArea, ShadowRoot, Toolbar, ViewGroupNode, compoundDeploymentNode, compoundElementNode, deploymentNode, elementNode, memoEdge, memoNode, sequenceActorNode, useCurrentView, useCurrentViewId, useCurrentViewModel, useDiagram, useDiagramActorRef, useDiagramContext, useDiagramEventHandlers, useEnabledFeatures, useHasProjects, useLikeC4Model, useLikeC4Project, useLikeC4ProjectId, useLikeC4Projects, useLikeC4ProjectsContext, useLikeC4Specification, useLikeC4Styles, useLikeC4ViewModel, useOnDiagramEvent, useOptionalCurrentViewModel, useOptionalLikeC4Model, useSetState, useUpdateEffect, viewGroupNode };
40
+ export { Base, CompoundActionButton, CompoundActions, CompoundDeploymentNode, CompoundDeploymentToolbar, CompoundDetailsButton, CompoundDetailsButtonWithHandler, CompoundElementNode, CompoundElementToolbar, CompoundNodeContainer, CompoundTitle, DefaultHandles, DeploymentElementActions, DeploymentElementToolbar, DeploymentNode, ElementActionButtons, ElementActions, ElementData, ElementDetailsButton, ElementDetailsButtonWithHandler, ElementNode, ElementNodeContainer, ElementShape, ElementTag, ElementTags, ElementToolbar, FramerMotionConfig, IfEnabled, IfNotEnabled, IfNotReadOnly, IfReadOnly, Markdown, NavigationPanel, Overlay, PortalToContainer, SequenceActorNode, SequenceParallelArea, Toolbar, ViewGroupNode, compoundDeploymentNode, compoundElementNode, deploymentNode, elementNode, memoEdge, memoNode, sequenceActorNode, useCurrentView, useCurrentViewId, useCurrentViewModel, useDiagram, useDiagramActorRef, useDiagramContext, useDiagramEventHandlers, useEnabledFeatures, useHasProjects, useLikeC4Model, useLikeC4Project, useLikeC4ProjectId, useLikeC4Projects, useLikeC4ProjectsContext, useLikeC4Specification, useLikeC4Styles, useLikeC4ViewModel, useOnDiagramEvent, useOptionalCurrentViewModel, useOptionalLikeC4Model, useSetState, useUpdateEffect, viewGroupNode };
@@ -3,6 +3,11 @@ import type * as t from '@likec4/core/types';
3
3
  * Callbacks from LikeC4 Editor.
4
4
  */
5
5
  export interface LikeC4EditorCallbacks {
6
+ /**
7
+ * Apply semantic layout to a view (if AI is available)
8
+ * See vite-plugin settings for more details
9
+ */
10
+ applySemanticLayout?: undefined | ((viewId: t.ViewId) => Promise<void>);
6
11
  /**
7
12
  * Fetch a view by its ID and layout type.
8
13
  *
@@ -24,11 +24,11 @@ export type LikeC4EditorProviderProps = PropsWithChildren<{
24
24
  * </LikeC4EditorProvider>
25
25
  * ```
26
26
  */
27
- export declare function LikeC4EditorProvider({ children, editor }: LikeC4EditorProviderProps): import("react/jsx-runtime").JSX.Element;
27
+ export declare function LikeC4EditorProvider({ children, editor }: LikeC4EditorProviderProps): import("react").JSX.Element;
28
28
  /**
29
29
  * Component that ensures the editor context is available.
30
30
  *
31
31
  * @param children - The children to render.
32
32
  */
33
- export declare function EnsureEditorContext({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element | null;
33
+ export declare function EnsureEditorContext({ children }: PropsWithChildren): import("react").JSX.Element | null;
34
34
  export declare function useOptionalLikeC4Editor(): LikeC4EditorCallbacks | null;
@@ -0,0 +1,174 @@
1
+ import { ActorSystem, ActionFunction, CancelAction, PromiseActorLogic, EventObject } from 'xstate';
2
+ import { Snapshot, SyncOp, EditorActorContext, EditorActorEvent, EditorActorEmitedEvent } from './types';
3
+ import { HotkeyActorLogic } from './hotkey';
4
+ import type * as t from '@likec4/core/types';
5
+ export declare function makeSnapshot(system: ActorSystem<any>): Snapshot;
6
+ type LayoutChanges = t.ViewChange.ResetManualLayout | t.ViewChange.SaveViewSnapshot;
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>;
9
+ export declare const withoutSnapshotChanges: (data: t.ViewChange[]) => (t.ViewChange.ChangeElementStyle | t.ViewChange.ChangeAutoLayout | t.ViewChange.ChangeProperty)[];
10
+ export declare const scheduleSync: (delay?: number) => ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, never, never, never, "500ms" | "wait-after-edit", never>;
11
+ export declare const cancelSync: () => CancelAction<EditorActorContext, EditorActorEvent, undefined, EditorActorEvent>;
12
+ /**
13
+ * Save the state before editing starts
14
+ */
15
+ export declare const saveBeforeEditing: () => ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
16
+ src: "hotkey";
17
+ logic: HotkeyActorLogic;
18
+ id: "hotkey";
19
+ } | {
20
+ src: "applyLatest";
21
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplyLatestToManual.Output, import("./setup").EditorCalls.ApplyLatestToManual.Input, EventObject>;
22
+ id: string | undefined;
23
+ } | {
24
+ src: "executeChange";
25
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ExecuteChange.Output, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
26
+ id: string | undefined;
27
+ } | {
28
+ src: "applySemanticLayout";
29
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplySemanticLayout.Output, import("./setup").EditorCalls.ApplySemanticLayout.Input, EventObject>;
30
+ id: string | undefined;
31
+ }, never, never, never, never>;
32
+ /**
33
+ * When editing finishes, push the "beforeEditing" state to the history stack
34
+ */
35
+ export declare const pushHistory: () => ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
36
+ src: "hotkey";
37
+ logic: HotkeyActorLogic;
38
+ id: "hotkey";
39
+ } | {
40
+ src: "applyLatest";
41
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplyLatestToManual.Output, import("./setup").EditorCalls.ApplyLatestToManual.Input, EventObject>;
42
+ id: string | undefined;
43
+ } | {
44
+ src: "executeChange";
45
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ExecuteChange.Output, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
46
+ id: string | undefined;
47
+ } | {
48
+ src: "applySemanticLayout";
49
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplySemanticLayout.Output, import("./setup").EditorCalls.ApplySemanticLayout.Input, EventObject>;
50
+ id: string | undefined;
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>;
61
+ export declare const reschedule: (delay?: number) => ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, never, never, never, "500ms" | "wait-after-edit", never>;
62
+ export declare const undo: () => ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
63
+ src: "hotkey";
64
+ logic: HotkeyActorLogic;
65
+ id: "hotkey";
66
+ } | {
67
+ src: "applyLatest";
68
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplyLatestToManual.Output, import("./setup").EditorCalls.ApplyLatestToManual.Input, EventObject>;
69
+ id: string | undefined;
70
+ } | {
71
+ src: "executeChange";
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>;
125
+ id: string | undefined;
126
+ } | {
127
+ src: "applySemanticLayout";
128
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplySemanticLayout.Output, import("./setup").EditorCalls.ApplySemanticLayout.Input, EventObject>;
129
+ id: string | undefined;
130
+ }, never, {
131
+ type: "has pending";
132
+ params: unknown;
133
+ } | {
134
+ type: "can undo";
135
+ params: unknown;
136
+ } | {
137
+ type: "can redo";
138
+ params: unknown;
139
+ }, "500ms" | "wait-after-edit", EditorActorEmitedEvent>;
140
+ export declare const pushToSyncQueue: () => ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
141
+ src: "hotkey";
142
+ logic: HotkeyActorLogic;
143
+ id: "hotkey";
144
+ } | {
145
+ src: "applyLatest";
146
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplyLatestToManual.Output, import("./setup").EditorCalls.ApplyLatestToManual.Input, EventObject>;
147
+ id: string | undefined;
148
+ } | {
149
+ src: "executeChange";
150
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ExecuteChange.Output, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
151
+ id: string | undefined;
152
+ } | {
153
+ src: "applySemanticLayout";
154
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplySemanticLayout.Output, import("./setup").EditorCalls.ApplySemanticLayout.Input, EventObject>;
155
+ id: string | undefined;
156
+ }, never, never, never, never>;
157
+ export declare const clearQueue: () => ActionFunction<EditorActorContext, EditorActorEvent, EditorActorEvent, undefined, {
158
+ src: "hotkey";
159
+ logic: HotkeyActorLogic;
160
+ id: "hotkey";
161
+ } | {
162
+ src: "applyLatest";
163
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplyLatestToManual.Output, import("./setup").EditorCalls.ApplyLatestToManual.Input, EventObject>;
164
+ id: string | undefined;
165
+ } | {
166
+ src: "executeChange";
167
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ExecuteChange.Output, import("./setup").EditorCalls.ExecuteChange.Input, EventObject>;
168
+ id: string | undefined;
169
+ } | {
170
+ src: "applySemanticLayout";
171
+ logic: PromiseActorLogic<import("./setup").EditorCalls.ApplySemanticLayout.Output, import("./setup").EditorCalls.ApplySemanticLayout.Input, EventObject>;
172
+ id: string | undefined;
173
+ }, never, never, never, never>;
174
+ export {};
@@ -0,0 +1,188 @@
1
+ import "../../_virtual/_rolldown/runtime.js";
2
+ import { machine } from "./setup.js";
3
+ import { createViewChange } from "../../likec4diagram/state/createViewChange.js";
4
+ import { typedSystem } from "../../likec4diagram/state/utils.js";
5
+ import { filter, isNot, omit } from "remeda";
6
+ import { assertEvent } from "xstate";
7
+ //#region src/editor/actor/actions.ts
8
+ /**
9
+ * Actually this is DiagramActorRef
10
+ * But we can't use it here due to circular type inference
11
+ */
12
+ var getDiagramContext = function(system) {
13
+ return system.get("diagram").getSnapshot().context;
14
+ };
15
+ function makeSnapshot(system) {
16
+ const parentContext = getDiagramContext(system);
17
+ return {
18
+ xynodes: parentContext.xynodes.map(({ measured, data, ...n }) => ({
19
+ ...omit(n, [
20
+ "selected",
21
+ "dragging",
22
+ "resizing"
23
+ ]),
24
+ data: omit(data, ["dimmed", "hovered"]),
25
+ measured,
26
+ initialWidth: measured?.width ?? n.width ?? n.initialWidth,
27
+ initialHeight: measured?.height ?? n.height ?? n.initialHeight
28
+ })),
29
+ xyedges: parentContext.xyedges.map(({ data, ...e }) => ({
30
+ ...omit(e, ["selected"]),
31
+ data: omit(data, [
32
+ "active",
33
+ "dimmed",
34
+ "hovered"
35
+ ])
36
+ })),
37
+ change: createViewChange(parentContext),
38
+ view: parentContext.view
39
+ };
40
+ }
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
+ filter(isNot(isLayoutChange));
44
+ var scheduleSync = (delay = 50) => {
45
+ return machine.raise({ type: "change.sync-snapshot" }, delay ? {
46
+ delay,
47
+ id: "sync-snapshot"
48
+ } : void 0);
49
+ };
50
+ var cancelSync = () => {
51
+ return machine.cancel("sync-snapshot");
52
+ };
53
+ /**
54
+ * Save the state before editing starts
55
+ */
56
+ var saveBeforeEditing = () => machine.assign(({ system, event }) => {
57
+ assertEvent(event, "edit.move.start");
58
+ return { editing: {
59
+ subject: event.subject,
60
+ before: makeSnapshot(system)
61
+ } };
62
+ });
63
+ /**
64
+ * When editing finishes, push the "beforeEditing" state to the history stack
65
+ */
66
+ var pushHistory = () => machine.enqueueActions(({ context, enqueue }) => {
67
+ const editing = context.editing;
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
+ }
79
+ });
80
+ var undo = () => machine.enqueueActions(({ context: { history, redo }, system, enqueue }) => {
81
+ if (!history) return;
82
+ const last = history.head;
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));
112
+ enqueue.sendTo(typedSystem.diagramActor, {
113
+ type: "update.view",
114
+ view: last.view,
115
+ xyedges: last.xyedges,
116
+ xynodes: last.xynodes,
117
+ source: "editor"
118
+ });
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"
154
+ });
155
+ });
156
+ var pushToSyncQueue = () => machine.assign(({ context: { syncQueue }, event }) => {
157
+ let nextOp;
158
+ switch (event.type) {
159
+ case "change.view":
160
+ nextOp = event.change;
161
+ break;
162
+ case "change.semantic-layout":
163
+ nextOp = "apply-semantic-layout";
164
+ break;
165
+ case "change.latest-to-manual":
166
+ nextOp = "apply-latest-to-manual";
167
+ break;
168
+ case "change.sync-snapshot":
169
+ nextOp = "sync-snapshot";
170
+ break;
171
+ default: throw new Error(`Invalid event type: ${event.type}`);
172
+ }
173
+ if (syncQueue.length === 0) return { syncQueue: [nextOp] };
174
+ if (syncQueue.length === 1 && syncQueue[0] === nextOp) return {};
175
+ const isNextLayoutChange = isLayoutChangeOp(nextOp);
176
+ let pending = syncQueue.filter((existingOp) => {
177
+ if (existingOp === nextOp) return false;
178
+ if (isNextLayoutChange && isLayoutChangeOp(existingOp)) return false;
179
+ return true;
180
+ });
181
+ return { syncQueue: pending.length > 0 ? [...pending, nextOp] : [nextOp] };
182
+ });
183
+ var clearQueue = () => machine.assign({
184
+ syncQueue: [],
185
+ processing: null
186
+ });
187
+ //#endregion
188
+ export { cancelSync, clearQueue, deleteNodesAndEdges, makeSnapshot, pushHistory, pushToSyncQueue, redo, saveBeforeEditing, scheduleSync, undo };
@@ -1,7 +1,7 @@
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
  }
7
- export declare const hotkeyActorLogic: HotkeyActorLogic;
7
+ export declare const hotkey: HotkeyActorLogic;