@likec4/diagram 1.59.2 → 1.59.4

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 (233) hide show
  1. package/README.md +53 -0
  2. package/dist/LikeC4Diagram.d.ts +1 -1
  3. package/dist/LikeC4Diagram.js +36 -21
  4. package/dist/LikeC4Diagram.props.d.ts +23 -0
  5. package/dist/LikeC4MantineProvider.d.ts +24 -0
  6. package/dist/LikeC4MantineProvider.js +156 -0
  7. package/dist/LikeC4ProjectsOverview.js +1 -1
  8. package/dist/LikeC4ProjectsProvider.d.ts +17 -2
  9. package/dist/LikeC4Styles.d.ts +13 -3
  10. package/dist/LikeC4Styles.js +10 -6
  11. package/dist/LikeC4View.js +2 -2
  12. package/dist/StaticLikeC4Diagram.d.ts +1 -1
  13. package/dist/base/BaseXYFlow.d.ts +1 -1
  14. package/dist/base/BaseXYFlow.js +19 -9
  15. package/dist/base/const.d.ts +1 -0
  16. package/dist/base/const.js +3 -1
  17. package/dist/base-primitives/Markdown.d.ts +3 -3
  18. package/dist/base-primitives/compound/CompoundNodeContainer.js +2 -3
  19. package/dist/base-primitives/compound/CompoundTitle.js +5 -4
  20. package/dist/base-primitives/compound/actionbtns.css.d.ts +3 -3
  21. package/dist/base-primitives/compound/actionbtns.css.js +3 -3
  22. package/dist/base-primitives/element/ElementData.js +6 -1
  23. package/dist/base-primitives/element/ElementShape.js +9 -10
  24. package/dist/base-primitives/element/ElementTags.d.ts +2 -2
  25. package/dist/base-primitives/element/ElementTags.js +5 -5
  26. package/dist/components/EmptyBox.d.ts +3 -0
  27. package/dist/components/EmptyBox.js +9 -0
  28. package/dist/components/ErrorFallback.js +7 -6
  29. package/dist/components/FloatingWindow.d.ts +18 -0
  30. package/dist/components/FloatingWindow.js +89 -0
  31. package/dist/components/Link.js +7 -7
  32. package/dist/components/NavigationPanel.d.ts +2 -2
  33. package/dist/components/NavigationPanel.js +5 -6
  34. package/dist/components/SearchControl.css.js +10 -12
  35. package/dist/components/ViewIcon.d.ts +11 -0
  36. package/dist/components/ViewIcon.js +71 -0
  37. package/dist/context/CurrentViewModelProvider.js +2 -1
  38. package/dist/context/DiagramEventHandlers.js +4 -2
  39. package/dist/context/EnsureMantine.js +3 -3
  40. package/dist/context/IconRenderer.d.ts +2 -1
  41. package/dist/context/IconRenderer.js +78 -26
  42. package/dist/context/LikeC4ProjectsContext.d.ts +3 -2
  43. package/dist/context/TagStylesContext.d.ts +11 -4
  44. package/dist/context/TagStylesContext.js +39 -27
  45. package/dist/custom/index.d.ts +3 -0
  46. package/dist/custom/index.js +7 -4
  47. package/dist/editor/LikeC4EditorCallbacks.d.ts +20 -1
  48. package/dist/editor/LikeC4EditorCallbacks.js +4 -1
  49. package/dist/editor/actor/setup.d.ts +1 -0
  50. package/dist/editor/actor/setup.js +17 -12
  51. package/dist/editor/actor/state.sync-queue.js +1 -0
  52. package/dist/editor/applyChangesToManualLayout.js +5 -2
  53. package/dist/editor/index.d.ts +1 -1
  54. package/dist/editor/useEditorActorLogic.js +10 -3
  55. package/dist/hooks/safeContext.d.ts +12 -4
  56. package/dist/hooks/safeContext.js +2 -2
  57. package/dist/hooks/useCurrentView.js +5 -5
  58. package/dist/hooks/useDiagram.js +3 -23
  59. package/dist/hooks/useDiagramCompareLayout.d.ts +16 -6
  60. package/dist/hooks/useDiagramCompareLayout.js +20 -17
  61. package/dist/hooks/useEditorActor.js +3 -5
  62. package/dist/hooks/useLikeC4Model.js +8 -3
  63. package/dist/hooks/useLikeC4Project.d.ts +4 -3
  64. package/dist/hooks/useOverlaysActor.d.ts +1 -1
  65. package/dist/hooks/useUpdateEffect.js +2 -1
  66. package/dist/index.d.ts +6 -4
  67. package/dist/index.js +8 -6
  68. package/dist/likec4diagram/DiagramUI.js +4 -3
  69. package/dist/likec4diagram/DiagramXYFlow.d.ts +6 -0
  70. package/dist/likec4diagram/DiagramXYFlow.js +33 -19
  71. package/dist/likec4diagram/custom/edges/EdgeDrifts.js +4 -4
  72. package/dist/likec4diagram/custom/edges/RelationshipEdge.js +2 -4
  73. package/dist/likec4diagram/custom/edges/SequenceStepEdge.js +1 -3
  74. package/dist/likec4diagram/custom/edges/edges.css.js +13 -13
  75. package/dist/likec4diagram/custom/edges/useRelationshipEdgePath.js +3 -2
  76. package/dist/likec4diagram/custom/nodes/NodeDrifts.js +2 -2
  77. package/dist/likec4diagram/custom/nodes/NodeNotes.js +4 -4
  78. package/dist/likec4diagram/custom/nodes/SequenceActorNode.js +2 -2
  79. package/dist/likec4diagram/custom/nodes/SequenceSubFlow.js +8 -5
  80. package/dist/likec4diagram/custom/nodes/nodes.js +8 -5
  81. package/dist/likec4diagram/custom/nodes/toolbar/ColorButton.js +2 -2
  82. package/dist/likec4diagram/custom/nodes/toolbar/Toolbar.js +9 -8
  83. package/dist/likec4diagram/custom/nodes/toolbar/styles.css.js +1 -1
  84. package/dist/likec4diagram/relationship-popover/RelationshipPopover.js +3 -2
  85. package/dist/likec4diagram/relationship-popover/components.d.ts +1 -1
  86. package/dist/likec4diagram/relationship-popover/components.js +6 -2
  87. package/dist/likec4diagram/state/DiagramActorProvider.d.ts +7 -2
  88. package/dist/likec4diagram/state/DiagramActorProvider.js +20 -4
  89. package/dist/likec4diagram/state/assign.js +1 -1
  90. package/dist/likec4diagram/state/createViewChange.js +1 -6
  91. package/dist/likec4diagram/state/diagram-api.d.ts +2 -2
  92. package/dist/likec4diagram/state/diagram-api.js +3 -2
  93. package/dist/likec4diagram/state/machine.actions.js +15 -8
  94. package/dist/likec4diagram/state/machine.actions.layout.d.ts +1 -0
  95. package/dist/likec4diagram/state/machine.actions.layout.js +7 -5
  96. package/dist/likec4diagram/state/machine.setup.d.ts +10 -1
  97. package/dist/likec4diagram/state/machine.setup.js +15 -9
  98. package/dist/likec4diagram/state/machine.state.initializing.d.ts +2 -26
  99. package/dist/likec4diagram/state/machine.state.initializing.js +9 -6
  100. package/dist/likec4diagram/state/machine.state.navigating.js +1 -1
  101. package/dist/likec4diagram/state/machine.state.ready.d.ts +134 -3
  102. package/dist/likec4diagram/state/machine.state.ready.js +2 -1
  103. package/dist/likec4diagram/state/machine.state.ready.walkthrough.d.ts +106 -1
  104. package/dist/likec4diagram/state/machine.state.ready.walkthrough.js +40 -7
  105. package/dist/likec4diagram/state/utils.d.ts +1 -1
  106. package/dist/likec4diagram/state/utils.js +7 -4
  107. package/dist/likec4diagram/ui/FloatingSequenceActors.js +2 -1
  108. package/dist/likec4diagram/ui/LayoutDriftFrame.js +16 -10
  109. package/dist/likec4diagram/ui/index.d.ts +1 -1
  110. package/dist/likec4diagram/ui/notation/NotationPanel.css.js +13 -15
  111. package/dist/likec4diagram/ui/notation/NotationPanel.js +9 -9
  112. package/dist/likec4diagram/ui/sequence-outline/ActiveTrail.d.ts +9 -0
  113. package/dist/likec4diagram/ui/sequence-outline/ActiveTrail.js +81 -0
  114. package/dist/likec4diagram/ui/sequence-outline/FlowRow.d.ts +11 -0
  115. package/dist/likec4diagram/ui/sequence-outline/FlowRow.js +70 -0
  116. package/dist/likec4diagram/ui/sequence-outline/OutlineBody.d.ts +2 -0
  117. package/dist/likec4diagram/ui/sequence-outline/OutlineBody.js +106 -0
  118. package/dist/likec4diagram/ui/sequence-outline/OutlineHeader.d.ts +2 -0
  119. package/dist/likec4diagram/ui/sequence-outline/OutlineHeader.js +140 -0
  120. package/dist/likec4diagram/ui/sequence-outline/OutlineNodes.d.ts +17 -0
  121. package/dist/likec4diagram/ui/sequence-outline/OutlineNodes.js +83 -0
  122. package/dist/likec4diagram/ui/sequence-outline/SequenceOutlinePanel.d.ts +4 -0
  123. package/dist/likec4diagram/ui/sequence-outline/SequenceOutlinePanel.js +49 -525
  124. package/dist/likec4diagram/ui/sequence-outline/StepBadge.d.ts +8 -0
  125. package/dist/likec4diagram/ui/sequence-outline/StepBadge.js +52 -0
  126. package/dist/likec4diagram/ui/sequence-outline/StepRow.d.ts +7 -0
  127. package/dist/likec4diagram/ui/sequence-outline/StepRow.js +190 -0
  128. package/dist/likec4diagram/ui/sequence-outline/StoreProvider.d.ts +238 -0
  129. package/dist/likec4diagram/ui/sequence-outline/StoreProvider.js +94 -0
  130. package/dist/likec4diagram/ui/sequence-outline/depth-of-field.d.ts +21 -0
  131. package/dist/likec4diagram/ui/sequence-outline/depth-of-field.js +71 -0
  132. package/dist/likec4diagram/ui/sequence-outline/index.d.ts +2 -0
  133. package/dist/likec4diagram/ui/sequence-outline/motion.d.ts +13 -0
  134. package/dist/likec4diagram/ui/sequence-outline/motion.js +21 -0
  135. package/dist/likec4diagram/ui/sequence-outline/presentation.d.ts +10 -0
  136. package/dist/likec4diagram/ui/sequence-outline/presentation.js +80 -0
  137. package/dist/likec4diagram/ui/sequence-outline/tree.d.ts +9 -0
  138. package/dist/likec4diagram/ui/sequence-outline/tree.js +67 -0
  139. package/dist/likec4diagram/ui/sequence-outline/{state.d.ts → types.d.ts} +4 -2
  140. package/dist/likec4diagram/ui/sequence-outline/types.js +12 -0
  141. package/dist/likec4diagram/useLayoutConstraints.js +13 -1
  142. package/dist/likec4diagram/xyflow-sequence/layouter.js +8 -10
  143. package/dist/likec4diagram/xyflow-sequence/sequence-view-to-xy.js +1 -0
  144. package/dist/likec4diagram/xyflow-sequence/utils.js +0 -1
  145. package/dist/navigationpanel/NavigationPanel.js +45 -41
  146. package/dist/navigationpanel/NavigationPanelControls.js +102 -63
  147. package/dist/navigationpanel/NavigationPanelDropdown.js +52 -77
  148. package/dist/navigationpanel/_common.d.ts +6 -6
  149. package/dist/navigationpanel/_common.js +31 -42
  150. package/dist/navigationpanel/actor.actions.js +6 -5
  151. package/dist/navigationpanel/actor.js +2 -2
  152. package/dist/navigationpanel/actor.setup.d.ts +6 -6
  153. package/dist/navigationpanel/actor.setup.js +2 -1
  154. package/dist/navigationpanel/comparepanel/CompareActionsMenu.js +2 -4
  155. package/dist/navigationpanel/comparepanel/ComparePanel.js +8 -10
  156. package/dist/navigationpanel/comparepanel/DriftsSummary.d.ts +1 -1
  157. package/dist/navigationpanel/comparepanel/DriftsSummary.js +11 -9
  158. package/dist/navigationpanel/controls/LayoutWarning.js +69 -72
  159. package/dist/navigationpanel/controls/NavigationButtons.d.ts +1 -1
  160. package/dist/navigationpanel/controls/NavigationButtons.js +8 -8
  161. package/dist/navigationpanel/controls/OpenSource.d.ts +1 -1
  162. package/dist/navigationpanel/controls/OpenSource.js +5 -8
  163. package/dist/navigationpanel/controls/SearchControl.js +24 -9
  164. package/dist/navigationpanel/controls/ToggleReadonly.d.ts +4 -1
  165. package/dist/navigationpanel/controls/ToggleReadonly.js +56 -76
  166. package/dist/navigationpanel/controls/ViewDetailsButton.d.ts +5 -0
  167. package/dist/navigationpanel/controls/ViewDetailsButton.js +121 -0
  168. package/dist/navigationpanel/controls/index.d.ts +1 -1
  169. package/dist/navigationpanel/dropdown/ProjectsMenu.js +27 -16
  170. package/dist/navigationpanel/editorpanel/ApplySemanticLayout.js +2 -1
  171. package/dist/navigationpanel/editorpanel/ChangeAutoLayoutButton.js +12 -10
  172. package/dist/navigationpanel/editorpanel/ManualLayoutToolsButton.d.ts +2 -0
  173. package/dist/navigationpanel/editorpanel/ManualLayoutToolsButton.js +19 -10
  174. package/dist/navigationpanel/editorpanel/styles.js +8 -15
  175. package/dist/navigationpanel/hooks.d.ts +6 -2
  176. package/dist/navigationpanel/styles.css.d.ts +2 -2
  177. package/dist/navigationpanel/styles.css.js +0 -1
  178. package/dist/navigationpanel/walkthrough/ActiveWalkthroughControls.js +3 -2
  179. package/dist/navigationpanel/walkthrough/DynamicViewControls.d.ts +5 -4
  180. package/dist/navigationpanel/walkthrough/DynamicViewControls.js +10 -39
  181. package/dist/navigationpanel/walkthrough/DynamicViewModeSwitcher.d.ts +1 -0
  182. package/dist/navigationpanel/walkthrough/DynamicViewModeSwitcher.js +49 -0
  183. package/dist/navigationpanel/walkthrough/WalkthroughPanel.js +8 -8
  184. package/dist/navigationpanel/windows/ViewDetailsWindow.d.ts +1 -0
  185. package/dist/navigationpanel/windows/ViewDetailsWindow.js +379 -0
  186. package/dist/overlays/Overlays.js +29 -17
  187. package/dist/overlays/element-details/ElementDetailsCard.css.js +28 -36
  188. package/dist/overlays/element-details/ElementDetailsCard.js +3 -3
  189. package/dist/overlays/element-details/MetadataValue.js +18 -16
  190. package/dist/overlays/element-details/TabPanelDeployments.css.js +6 -14
  191. package/dist/overlays/element-details/TabPanelRelationships.css.js +8 -12
  192. package/dist/overlays/element-details/TabPanelStructure.css.js +4 -8
  193. package/dist/overlays/hooks.d.ts +3 -1
  194. package/dist/overlays/overlay/Overlay.js +8 -7
  195. package/dist/overlays/overlaysActor.js +20 -17
  196. package/dist/overlays/relationship-details/RelationshipDetails.js +2 -1
  197. package/dist/overlays/relationship-details/SelectEdge.css.js +14 -9
  198. package/dist/overlays/relationship-details/actor.js +1 -1
  199. package/dist/overlays/relationship-details/hooks.js +2 -1
  200. package/dist/overlays/relationships-browser/RelationshipsBrowser.d.ts +6 -0
  201. package/dist/overlays/relationships-browser/RelationshipsBrowser.js +15 -8
  202. package/dist/overlays/relationships-browser/SelectElement.css.js +2 -8
  203. package/dist/overlays/relationships-browser/SelectElement.js +5 -1
  204. package/dist/overlays/relationships-browser/actor.js +3 -2
  205. package/dist/overlays/relationships-browser/custom/ElementActions.js +39 -38
  206. package/dist/overlays/relationships-browser/custom/EmptyNode.js +7 -9
  207. package/dist/overlays/relationships-browser/hooks.js +2 -1
  208. package/dist/projects-overview/ProjectsOverview.js +8 -7
  209. package/dist/projects-overview/actor.js +1 -1
  210. package/dist/projects-overview/hooks.js +2 -1
  211. package/dist/search/Search.js +9 -7
  212. package/dist/search/components/ElementsColumn.css.js +6 -5
  213. package/dist/search/components/ElementsColumn.js +4 -3
  214. package/dist/search/components/SearchByTags.js +3 -3
  215. package/dist/search/components/ViewsColum.js +46 -43
  216. package/dist/search/components/ViewsColumn.css.js +4 -4
  217. package/dist/search/components/_shared.css.d.ts +2 -2
  218. package/dist/search/components/_shared.css.js +31 -46
  219. package/dist/search/components/styles.css.js +4 -4
  220. package/dist/search/hooks.js +2 -1
  221. package/dist/shadowroot/ShadowRoot.js +6 -5
  222. package/dist/styles2.js +1 -1
  223. package/dist/utils/index.js +3 -3
  224. package/package.json +29 -29
  225. package/panda.buildinfo.json +342 -299
  226. package/styles-min.css +1 -1
  227. package/styles-xyflow.css +1 -1
  228. package/styles.css +1 -1
  229. package/dist/context/DefaultMantineProvider.d.ts +0 -2
  230. package/dist/context/DefaultMantineProvider.js +0 -48
  231. package/dist/likec4diagram/ui/sequence-outline/state.js +0 -55
  232. package/dist/navigationpanel/controls/DetailsControls.d.ts +0 -2
  233. package/dist/navigationpanel/controls/DetailsControls.js +0 -223
@@ -26,23 +26,6 @@ function IconRendererProvider({ value, children }) {
26
26
  children
27
27
  });
28
28
  }
29
- /**
30
- * Attempts to extract and decode SVG content from a data URL.
31
- * Returns the decoded SVG string if successful, or null if not an SVG data URL.
32
- */
33
- function decodeSvgDataUrl(dataUrl) {
34
- if (!dataUrl.startsWith("data:image/svg+xml")) return null;
35
- try {
36
- if (dataUrl.includes(";base64,")) {
37
- const base64Content = dataUrl.split(";base64,")[1];
38
- if (base64Content) return atob(base64Content);
39
- } else {
40
- const encodedContent = dataUrl.split(",")[1];
41
- if (encodedContent) return decodeURIComponent(encodedContent);
42
- }
43
- } catch {}
44
- return null;
45
- }
46
29
  function IconRenderer({ element, className, style }) {
47
30
  const RenderIcon = useContext(IconRendererContext);
48
31
  if (!element || !element.icon || element.icon === "none") return null;
@@ -65,9 +48,7 @@ function IconRenderer({ element, className, style }) {
65
48
  case !!RenderIcon:
66
49
  icon = /* @__PURE__ */ jsx(RenderIcon, { node: element });
67
50
  break;
68
- default:
69
- icon = null;
70
- break;
51
+ default: icon = /* @__PURE__ */ jsx(DefaultIconRenderer, { node: element });
71
52
  }
72
53
  if (!icon) return null;
73
54
  return /* @__PURE__ */ jsx("div", {
@@ -104,14 +85,85 @@ function IconOrShapeRenderer({ element, className, style }) {
104
85
  style
105
86
  });
106
87
  }
107
- function SvgDataUrlIcon({ dataUrl, ...props }) {
108
- const svgContent = useMemo(() => decodeSvgDataUrl(dataUrl), [dataUrl]);
109
- if (!svgContent) return null;
88
+ function SvgDataUrlIcon({ dataUrl, alt }) {
89
+ if (!useMemo(() => hasCurrentColorReference(dataUrl), [dataUrl])) return /* @__PURE__ */ jsx("img", {
90
+ src: dataUrl,
91
+ alt
92
+ });
93
+ const maskUrl = `url(${JSON.stringify(dataUrl)})`;
94
+ return /* @__PURE__ */ jsx("span", {
95
+ role: alt ? "img" : void 0,
96
+ "aria-label": alt,
97
+ style: {
98
+ display: "inline-block",
99
+ width: "100%",
100
+ height: "100%",
101
+ backgroundColor: "currentColor",
102
+ maskImage: maskUrl,
103
+ maskRepeat: "no-repeat",
104
+ maskPosition: "center",
105
+ maskSize: "contain",
106
+ WebkitMaskImage: maskUrl,
107
+ WebkitMaskRepeat: "no-repeat",
108
+ WebkitMaskPosition: "center",
109
+ WebkitMaskSize: "contain"
110
+ }
111
+ });
112
+ }
113
+ function hasCurrentColorReference(dataUrl) {
114
+ return /currentcolor/i.test(decodeSvgDataUrl(dataUrl) ?? "");
115
+ }
116
+ function decodeSvgDataUrl(dataUrl) {
117
+ if (!dataUrl.startsWith("data:image/svg+xml")) return null;
118
+ try {
119
+ const comma = dataUrl.indexOf(",");
120
+ if (comma === -1) return null;
121
+ const payload = dataUrl.slice(comma + 1);
122
+ if (dataUrl.slice(0, comma).endsWith(";base64")) return new TextDecoder().decode(Uint8Array.from(atob(payload), (c) => c.charCodeAt(0)));
123
+ try {
124
+ return decodeURIComponent(payload);
125
+ } catch {
126
+ return payload;
127
+ }
128
+ } catch {
129
+ return null;
130
+ }
131
+ }
132
+ var iconUrl = (group, name) => `https://icons.like-c4.dev/${encodeURIComponent(group)}/${encodeURIComponent(name)}.svg`;
133
+ function BootstrapIconMask({ name, ...props }) {
134
+ const url = iconUrl("bootstrap", name);
135
+ const style = {
136
+ display: "inline-block",
137
+ width: "100%",
138
+ height: "100%",
139
+ backgroundColor: "currentColor",
140
+ maskImage: `url("${url}")`,
141
+ maskRepeat: "no-repeat",
142
+ maskPosition: "center",
143
+ maskSize: "contain",
144
+ WebkitMaskImage: `url("${url}")`,
145
+ WebkitMaskRepeat: "no-repeat",
146
+ WebkitMaskPosition: "center",
147
+ WebkitMaskSize: "contain"
148
+ };
110
149
  return /* @__PURE__ */ jsx("span", {
111
150
  ...props,
112
- style: { display: "contents" },
113
- dangerouslySetInnerHTML: { __html: svgContent }
151
+ "aria-hidden": "true",
152
+ style
153
+ });
154
+ }
155
+ function DefaultIconRenderer({ node, ...props }) {
156
+ if (!node.icon || node.icon === "none") return null;
157
+ const [group, name, ...rest] = node.icon.split(":");
158
+ if (!group || !name || rest.length > 0) return null;
159
+ if (group === "bootstrap") return /* @__PURE__ */ jsx(BootstrapIconMask, {
160
+ ...props,
161
+ name
162
+ });
163
+ return /* @__PURE__ */ jsx("img", {
164
+ ...props,
165
+ src: iconUrl(group, name)
114
166
  });
115
167
  }
116
168
  //#endregion
117
- export { IconOrShapeRenderer, IconRenderer, IconRendererProvider };
169
+ export { DefaultIconRenderer, IconOrShapeRenderer, IconRenderer, IconRendererProvider };
@@ -1,7 +1,8 @@
1
- import { LikeC4Project, ProjectId } from '@likec4/core/types';
1
+ import { ProjectId } from '@likec4/core/types';
2
+ import { LikeC4ProjectData } from '../LikeC4ProjectsProvider';
2
3
  import { Provider } from 'react';
3
4
  export type LikeC4ProjectsContext = {
4
- projects: ReadonlyArray<LikeC4Project>;
5
+ projects: ReadonlyArray<LikeC4ProjectData>;
5
6
  onProjectChange: (id: ProjectId) => void;
6
7
  };
7
8
  export declare const LikeC4ProjectsContextProvider: Provider<LikeC4ProjectsContext | null>;
@@ -1,8 +1,15 @@
1
1
  import { TagSpecification } from '@likec4/core';
2
+ import { LikeC4Styles } from '@likec4/core/styles';
2
3
  import { PropsWithChildren } from 'react';
3
- export declare function generateColorVars(spec: TagSpecification): string;
4
- export declare function TagStylesProvider({ children, id }: PropsWithChildren<{
5
- id: string;
6
- }>): import("react").JSX.Element;
4
+ export declare function generateColorVars(spec: TagSpecification, styles?: LikeC4Styles): string;
5
+ type TagStylesProviderProps = PropsWithChildren<{
6
+ /**
7
+ * Root element selector to scope the tag styles to (e.g., "#diagram-root")
8
+ * Must be a valid CSS selector
9
+ */
10
+ rootSelector: string;
11
+ }>;
12
+ export declare function TagStylesProvider({ children, rootSelector }: TagStylesProviderProps): import("react").JSX.Element;
7
13
  export declare function useTagSpecifications(): Record<string, TagSpecification>;
8
14
  export declare function useTagSpecification(tag: string): TagSpecification;
15
+ export {};
@@ -1,56 +1,68 @@
1
1
  import "../_virtual/_rolldown/runtime.js";
2
2
  import { useLikeC4Specification } from "../hooks/useLikeC4Model.js";
3
+ import { useLikeC4Styles } from "../hooks/useLikeC4Styles.js";
3
4
  import { createContext, memo } from "react";
4
- import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
5
6
  import { entries, flatMap, isEmpty, join, pipe } from "remeda";
6
7
  import { isTagColorSpecified } from "@likec4/core";
7
8
  import { useMantineStyleNonce } from "@mantine/core";
8
- import { DefaultTagColors, getContrastedColorsAPCA, isValidColor } from "@likec4/core/styles";
9
+ import { DefaultTagColors, LikeC4Styles, getContrastedColorsAPCA, isValidColor } from "@likec4/core/styles";
9
10
  //#region src/context/TagStylesContext.tsx
10
11
  var radixColors = DefaultTagColors;
11
- function generateColorVars(spec) {
12
+ function generateColorVars(spec, styles = LikeC4Styles.DEFAULT) {
12
13
  const color = spec.color;
13
14
  if (isTagColorSpecified(spec) && isValidColor(color)) return `
14
- --colors-likec4-tag-bg: ${color};
15
- --colors-likec4-tag-bg-hover: color-mix(in oklab, ${color}, var(--colors-likec4-mix-color) 20%);
16
- --colors-likec4-tag-text: ${getContrastedColorsAPCA(color).hiContrast};
15
+ --colors-likec4-tag-bg: ${color};
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
- if (!radixColors.includes(color)) return "";
19
- let textcolor = `var(--colors-${color}-12)`;
20
- if ([
21
- "mint",
22
- "grass",
23
- "lime",
24
- "yellow",
25
- "amber"
26
- ].includes(color)) textcolor = "rgba(0 0 0 / 0.85)";
27
- return `
19
+ if (radixColors.includes(color)) {
20
+ let textcolor = `var(--colors-${color}-12)`;
21
+ if ([
22
+ "mint",
23
+ "grass",
24
+ "lime",
25
+ "yellow",
26
+ "amber"
27
+ ].includes(color)) textcolor = "rgba(0 0 0 / 0.85)";
28
+ return `
28
29
  --colors-likec4-tag-border: var(--colors-${color}-8);
29
30
  --colors-likec4-tag-bg: var(--colors-${color}-9);
30
31
  --colors-likec4-tag-bg-hover: var(--colors-${color}-10);
31
32
  --colors-likec4-tag-text: ${textcolor};
32
- `;
33
+ `;
34
+ }
35
+ if (styles.isThemeColor(color)) {
36
+ const { fill, hiContrast } = styles.tagColor(color);
37
+ return `
38
+ --colors-likec4-tag-bg: ${fill};
39
+ --colors-likec4-tag-bg-hover: color-mix(in oklab, ${fill}, var(--colors-likec4-mix-color) 20%);
40
+ --colors-likec4-tag-text: ${hiContrast};
41
+ `;
42
+ }
43
+ return "";
33
44
  }
34
45
  var TagStylesContext = createContext({});
35
- function generateStylesheet(tags, rootSelector) {
46
+ function generateStylesheet(tags, rootSelector, styles) {
36
47
  if (!tags || isEmpty(tags)) return "";
37
48
  return pipe(entries(tags), flatMap(([tag, spec]) => [
38
49
  `:is(${rootSelector} [data-likec4-tag="${tag}"]) {`,
39
- generateColorVars(spec),
50
+ generateColorVars(spec, styles),
40
51
  "}"
41
52
  ]), join("\n"));
42
53
  }
43
- function TagStylesProvider({ children, id }) {
54
+ function TagStylesProvider({ children, rootSelector }) {
44
55
  const tags = useLikeC4Specification().tags;
56
+ const styles = useLikeC4Styles();
45
57
  const nonce = useMantineStyleNonce()?.();
46
- const stylesheet = generateStylesheet(tags, `#${id}`);
47
- return /* @__PURE__ */ jsxs(Fragment$1, { children: [stylesheet !== "" && /* @__PURE__ */ jsx(TagStylesheet, {
48
- nonce,
49
- stylesheet
50
- }), /* @__PURE__ */ jsx(TagStylesContext.Provider, {
58
+ const stylesheet = generateStylesheet(tags, rootSelector, styles);
59
+ return /* @__PURE__ */ jsxs(TagStylesContext.Provider, {
51
60
  value: tags,
52
- children
53
- })] });
61
+ children: [stylesheet !== "" && /* @__PURE__ */ jsx(TagStylesheet, {
62
+ nonce,
63
+ stylesheet
64
+ }), children]
65
+ });
54
66
  }
55
67
  var TagStylesheet = memo(({ stylesheet, nonce }) => {
56
68
  return /* @__PURE__ */ jsx("style", {
@@ -14,3 +14,6 @@ export { PortalToContainer } from '../components/PortalToContainer';
14
14
  export { FramerMotionConfig } from '../context/FramerMotionConfig';
15
15
  export { NavigationPanel } from '../components/NavigationPanel';
16
16
  export { ErrorBoundary, ErrorFallback } from '../components/ErrorFallback';
17
+ export { LikeC4MantineProvider } from '../LikeC4MantineProvider';
18
+ export { LikeC4Styles } from '../LikeC4Styles';
19
+ export { TagStylesProvider } from '../context/TagStylesContext';
@@ -3,16 +3,18 @@ import { Base } from "../base/Base.js";
3
3
  import { useDiagramEventHandlers } from "../context/DiagramEventHandlers.js";
4
4
  import { useSetState } from "../hooks/useSetState.js";
5
5
  import { IfEnabled, IfNotEnabled, IfNotReadOnly, IfReadOnly, useEnabledFeatures } from "../context/DiagramFeatures.js";
6
+ import { LikeC4MantineProvider } from "../LikeC4MantineProvider.js";
6
7
  import { FramerMotionConfig } from "../context/FramerMotionConfig.js";
7
8
  import { useDiagram, useDiagramActorRef } from "../hooks/safeContext.js";
8
9
  import { useDiagramContext, useOnDiagramEvent } from "../hooks/useDiagram.js";
9
10
  import { useCurrentView, useCurrentViewId } from "../hooks/useCurrentView.js";
10
11
  import { useOptionalCurrentViewModel, useOptionalLikeC4Model } from "../context/LikeC4ModelContext.js";
11
12
  import { useLikeC4Model, useLikeC4Specification, useLikeC4ViewModel } from "../hooks/useLikeC4Model.js";
13
+ import { useLikeC4Styles } from "../hooks/useLikeC4Styles.js";
14
+ import { TagStylesProvider } from "../context/TagStylesContext.js";
12
15
  import { ErrorBoundary, ErrorFallback } from "../components/ErrorFallback.js";
13
16
  import { useCurrentViewModel } from "../hooks/useCurrentViewModel.js";
14
17
  import { useHasProjects, useLikeC4Project, useLikeC4ProjectId, useLikeC4Projects, useLikeC4ProjectsContext } from "../hooks/useLikeC4Project.js";
15
- import { useLikeC4Styles } from "../hooks/useLikeC4Styles.js";
16
18
  import { CompoundActionButton } from "../base-primitives/compound/CompoundActionButton.js";
17
19
  import { CompoundDetailsButton } from "../base-primitives/compound/CompoundDetailsButton.js";
18
20
  import { CompoundNodeContainer } from "../base-primitives/compound/CompoundNodeContainer.js";
@@ -27,8 +29,6 @@ import { ElementTag, ElementTags } from "../base-primitives/element/ElementTags.
27
29
  import { memoEdge } from "../base-primitives/memoEdge.js";
28
30
  import { memoNode } from "../base-primitives/memoNode.js";
29
31
  import { DefaultHandles } from "../base-primitives/NodeHandles.js";
30
- import { Overlay } from "../overlays/overlay/Overlay.js";
31
- import { PortalToContainer } from "../components/PortalToContainer.js";
32
32
  import { CompoundActions } from "../likec4diagram/custom/nodes/CompoundActions.js";
33
33
  import { DeploymentElementActions, ElementActions } from "../likec4diagram/custom/nodes/ElementActions.js";
34
34
  import { Toolbar } from "../likec4diagram/custom/nodes/toolbar/Toolbar.js";
@@ -37,5 +37,8 @@ import { DeploymentElementToolbar, ElementToolbar } from "../likec4diagram/custo
37
37
  import { CompoundDeploymentNode, CompoundDetailsButtonWithHandler, CompoundElementNode, DeploymentNode, ElementDetailsButtonWithHandler, ElementNode, ViewGroupNode } from "../likec4diagram/custom/nodes/nodes.js";
38
38
  import { SequenceActorNode, SequenceParallelArea } from "../likec4diagram/custom/nodes/SequenceActorNode.js";
39
39
  import { compoundDeploymentNode, compoundElementNode, deploymentNode, elementNode, sequenceActorNode, viewGroupNode } from "./customNodes.js";
40
+ import { Overlay } from "../overlays/overlay/Overlay.js";
41
+ import { PortalToContainer } from "../components/PortalToContainer.js";
40
42
  import { NavigationPanel } from "../components/NavigationPanel.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, ErrorBoundary, ErrorFallback, 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 };
43
+ import { LikeC4Styles } from "../LikeC4Styles.js";
44
+ 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, ErrorBoundary, ErrorFallback, FramerMotionConfig, IfEnabled, IfNotEnabled, IfNotReadOnly, IfReadOnly, LikeC4MantineProvider, LikeC4Styles, Markdown, NavigationPanel, Overlay, PortalToContainer, SequenceActorNode, SequenceParallelArea, TagStylesProvider, 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 };
@@ -1,4 +1,19 @@
1
1
  import type * as t from '@likec4/core/types';
2
+ /**
3
+ * Result of applying a change from the LikeC4 Editor.
4
+ */
5
+ export interface LikeC4EditorChangeResult {
6
+ /**
7
+ * Whether applying the change will publish a refreshed view to the diagram
8
+ * that the editor should wait for.
9
+ *
10
+ * Returning no result from `handleChange` defaults this to `true`,
11
+ * preserving the existing behavior for integrations that persist changes
12
+ * through an external model service.
13
+ */
14
+ waitForViewSync: boolean;
15
+ }
16
+ export declare function shouldWaitForViewSync(result?: void | LikeC4EditorChangeResult): boolean;
2
17
  /**
3
18
  * Callbacks from LikeC4 Editor.
4
19
  */
@@ -17,7 +32,11 @@ export interface LikeC4EditorCallbacks {
17
32
  fetchView(viewId: t.ViewId, layout?: t.LayoutType): t.LayoutedView | Promise<t.LayoutedView>;
18
33
  /**
19
34
  * Callback invoked when the view changes.
35
+ *
36
+ * Return `{ waitForViewSync: false }` when the integration applies the
37
+ * change locally and will not publish a refreshed view. When changes are
38
+ * batched, the editor waits if any callback invocation expects a refresh.
20
39
  */
21
- handleChange(viewId: t.ViewId, change: t.ViewChange): void | Promise<void>;
40
+ handleChange(viewId: t.ViewId, change: t.ViewChange): void | LikeC4EditorChangeResult | Promise<void | LikeC4EditorChangeResult>;
22
41
  }
23
42
  export declare function createLikeC4Editor(callbacks: LikeC4EditorCallbacks): LikeC4EditorCallbacks;
@@ -1,7 +1,10 @@
1
1
  import "../_virtual/_rolldown/runtime.js";
2
2
  //#region src/editor/LikeC4EditorCallbacks.tsx
3
+ function shouldWaitForViewSync(result) {
4
+ return result?.waitForViewSync ?? true;
5
+ }
3
6
  function createLikeC4Editor(callbacks) {
4
7
  return callbacks;
5
8
  }
6
9
  //#endregion
7
- export { createLikeC4Editor };
10
+ export { createLikeC4Editor, shouldWaitForViewSync };
@@ -39,6 +39,7 @@ export declare namespace EditorCalls {
39
39
  type Output = {
40
40
  requested: t.ViewChange[];
41
41
  applied: t.ViewChange[];
42
+ waitForViewSync: boolean;
42
43
  };
43
44
  }
44
45
  }
@@ -2,6 +2,22 @@ import "../../_virtual/_rolldown/runtime.js";
2
2
  import { defineActors } from "../../utils/defineActors.js";
3
3
  import { hotkey } from "./hotkey.js";
4
4
  import { fromPromise, setup } from "xstate";
5
+ //#region src/editor/actor/setup.ts
6
+ var applyLatest = fromPromise(() => {
7
+ throw new Error("Not implemented");
8
+ });
9
+ var executeChange = fromPromise(() => {
10
+ throw new Error("Not implemented");
11
+ });
12
+ var applySemanticLayout = fromPromise(() => {
13
+ throw new Error("Not implemented");
14
+ });
15
+ var actors = defineActors({
16
+ hotkey,
17
+ applyLatest,
18
+ executeChange,
19
+ applySemanticLayout
20
+ });
5
21
  var machine = setup({
6
22
  types: {
7
23
  context: {},
@@ -11,18 +27,7 @@ var machine = setup({
11
27
  children: {},
12
28
  tags: ""
13
29
  },
14
- actors: defineActors({
15
- hotkey,
16
- applyLatest: fromPromise(() => {
17
- throw new Error("Not implemented");
18
- }),
19
- executeChange: fromPromise(() => {
20
- throw new Error("Not implemented");
21
- }),
22
- applySemanticLayout: fromPromise(() => {
23
- throw new Error("Not implemented");
24
- })
25
- }),
30
+ actors,
26
31
  delays: {
27
32
  "500ms": 500,
28
33
  "wait-after-edit": 1e3
@@ -229,6 +229,7 @@ var process = machine.createStateConfig({
229
229
  type: "update.view-bounds",
230
230
  bounds: lastSyncSnapshot.layout.bounds
231
231
  });
232
+ if (!event.output.waitForViewSync) enqueue.raise({ type: "view.synched" });
232
233
  }),
233
234
  target: "waitViewSynced"
234
235
  },
@@ -56,7 +56,7 @@ function _applyChangesToManualLayout(manualView, latestView) {
56
56
  manual
57
57
  });
58
58
  if (isBetweenNewLeafNodes(latest)) return removeDrift(latest);
59
- return makeAsStraightLine(latest, nodesMap.get(latest.source), nodesMap.get(latest.target));
59
+ return makeAsStraightLine(latest, nonNullable(nodesMap.get(latest.source), `Source node ${latest.source} not found in processed nodes`), nonNullable(nodesMap.get(latest.target), `Target node ${latest.target} not found in processed nodes`));
60
60
  });
61
61
  const bounds = BBox$1.merge(...nodes.filter(isRootNode));
62
62
  return produce(latestView, (draft) => {
@@ -117,6 +117,8 @@ function applyFromManualEdge(edges) {
117
117
  draft.labelBBox.x = manual.labelBBox.x;
118
118
  draft.labelBBox.y = manual.labelBBox.y;
119
119
  }
120
+ if (manual.isLabelCustomized === true) draft.isLabelCustomized = true;
121
+ else delete draft.isLabelCustomized;
120
122
  draft.drifts = null;
121
123
  });
122
124
  }
@@ -137,6 +139,7 @@ function makeAsStraightLine(edge, sourceNode, targetNode) {
137
139
  if (edge.labelBBox) {
138
140
  draft.labelBBox.x = labelPos.x;
139
141
  draft.labelBBox.y = labelPos.y;
142
+ if (edge.isLabelCustomized === true) delete draft.isLabelCustomized;
140
143
  }
141
144
  delete draft.drifts;
142
145
  });
@@ -153,7 +156,7 @@ function edgeControlPoints(source, target) {
153
156
  if (source === target) {
154
157
  const loopSize = 80;
155
158
  const centerOfTopBoundary = vector(0, source.height || 0).multiply(-.5).add(sourceCenter);
156
- return [centerOfTopBoundary.add(vector(-80 / 2.5, -80)).trunc().toObject(), centerOfTopBoundary.add(vector(loopSize / 2.5, -80)).trunc().toObject()];
159
+ return [centerOfTopBoundary.add(vector(-32, -80)).trunc().toObject(), centerOfTopBoundary.add(vector(loopSize / 2.5, -80)).trunc().toObject()];
157
160
  }
158
161
  const sourceToTargetVector = targetCenter.subtract(sourceCenter);
159
162
  const sourceBorderPoint = getBorderPointOnVector(source, sourceCenter, sourceToTargetVector);
@@ -1,5 +1,5 @@
1
1
  export type * from './actor/machine';
2
2
  export type * from './actor/types';
3
3
  export { createLikeC4Editor } from './LikeC4EditorCallbacks';
4
- export type { LikeC4EditorCallbacks } from './LikeC4EditorCallbacks';
4
+ export type { LikeC4EditorCallbacks, LikeC4EditorChangeResult, } from './LikeC4EditorCallbacks';
5
5
  export { EnsureEditorContext, LikeC4EditorProvider, useOptionalLikeC4Editor, } from './LikeC4EditorProvider';
@@ -1,5 +1,6 @@
1
1
  import "../_virtual/_rolldown/runtime.js";
2
2
  import { useCallbackRef } from "../hooks/useCallbackRef.js";
3
+ import { shouldWaitForViewSync } from "./LikeC4EditorCallbacks.js";
3
4
  import { useOptionalLikeC4Editor } from "./LikeC4EditorProvider.js";
4
5
  import { editorActorLogic } from "./actor/machine.js";
5
6
  import { applyChangesToManualLayout } from "./applyChangesToManualLayout.js";
@@ -18,7 +19,9 @@ function useEditorActorLogic() {
18
19
  console.error("No editor port available for applying latest to manual layout");
19
20
  throw new Error("No editor port");
20
21
  }
21
- return { updated: applyChangesToManualLayout(await promisify(() => current ?? port.fetchView(viewId, "manual")), await promisify(() => port.fetchView(viewId, "auto"))) };
22
+ const manual = await promisify(() => current ?? port.fetchView(viewId, "manual"));
23
+ const latest = await promisify(() => port.fetchView(viewId, "auto"));
24
+ return { updated: applyChangesToManualLayout(manual, latest) };
22
25
  });
23
26
  const executeChange = useCallbackRef(async ({ input }) => {
24
27
  if (!port) {
@@ -26,18 +29,22 @@ function useEditorActorLogic() {
26
29
  throw new Error("No editor port");
27
30
  }
28
31
  const applied = [];
32
+ let waitForViewSync = false;
29
33
  for (const change of input.changes) try {
30
- await promisify(() => port.handleChange(input.viewId, change));
34
+ const result = await promisify(() => port.handleChange(input.viewId, change));
31
35
  applied.push(change);
36
+ waitForViewSync ||= shouldWaitForViewSync(result);
32
37
  } catch (error) {
33
38
  console.error("Failed to execute change", {
34
39
  change,
35
40
  error
36
41
  });
42
+ waitForViewSync ||= shouldWaitForViewSync();
37
43
  }
38
44
  return {
39
45
  requested: input.changes,
40
- applied
46
+ applied,
47
+ waitForViewSync
41
48
  };
42
49
  });
43
50
  const applySemanticLayout = useCallbackRef(async ({ input }) => {
@@ -35,12 +35,16 @@ type SafeContextForActor<A extends AnyActorRef, Snapshot, Context> = {
35
35
  * and the selected value from the current snapshot. If the comparison returns true,
36
36
  * the component will not re-render.
37
37
  */
38
- selectSnapshot<T>(select: (state: Snapshot) => T, compare?: (old: NoInfer<T>, next: NoInfer<T>) => boolean): SelectAndCompare<Snapshot, T>;
38
+ selectSnapshot<T>(select: (state: Snapshot) => T, compare?: (old: NoInfer<T>, next: NoInfer<T>) => boolean): SelectAndCompare<Snapshot, T> & {
39
+ Out: T;
40
+ };
39
41
  /**
40
42
  * @param select - Function to extract a value from the actor's context
41
43
  * @param compare - Optional comparison function. If not provided, shallow equality is used.
42
44
  */
43
- selectContext<T>(select: (state: Context) => T, compare?: (old: NoInfer<T>, next: NoInfer<T>) => boolean): SelectAndCompare<Snapshot, T>;
45
+ selectContext<T>(select: (state: Context) => T, compare?: (old: NoInfer<T>, next: NoInfer<T>) => boolean): SelectAndCompare<Snapshot, T> & {
46
+ Out: T;
47
+ };
44
48
  useActorSelector<T>(select: (state: Snapshot) => T): T;
45
49
  useActorSelector<T>(selectorCompare: SelectAndCompare<Snapshot, T>): T;
46
50
  useActorSelector<T>(...selectorCompare: SelectAndCompare<Snapshot, T>): T;
@@ -96,7 +100,9 @@ export declare const DiagramActorContextProvider: Provider<DiagramActorRef>, sel
96
100
  navigationPanel: ActorRefFromLogic<NavigationPanelActorLogic> | undefined;
97
101
  }, "search" | "overlays" | "editor" | "navigationPanel">, "final" | "isReady" | "navigating" | "ready" | "initializing" | {
98
102
  ready?: NonNullable<"idle" | "walkthrough" | "focused" | "printing">;
99
- }, never, never, never, never>, T>, selectDiagramContext: <T>(select: (state: DiagramContext) => T, compare?: ((old: NoInfer<T>, next: NoInfer<T>) => boolean) | undefined) => SelectAndCompare< MachineSnapshot<DiagramContext, DiagramEvents, {
103
+ }, never, never, never, never>, T> & {
104
+ Out: T;
105
+ }, selectDiagramContext: <T>(select: (state: DiagramContext) => T, compare?: ((old: NoInfer<T>, next: NoInfer<T>) => boolean) | undefined) => SelectAndCompare< MachineSnapshot<DiagramContext, DiagramEvents, {
100
106
  overlays: OverlaysActorRef | undefined;
101
107
  search: SearchActorRef | undefined;
102
108
  editor: BaseEditorActorRef | undefined;
@@ -110,7 +116,9 @@ export declare const DiagramActorContextProvider: Provider<DiagramActorRef>, sel
110
116
  navigationPanel: ActorRefFromLogic<NavigationPanelActorLogic> | undefined;
111
117
  }, "search" | "overlays" | "editor" | "navigationPanel">, "final" | "isReady" | "navigating" | "ready" | "initializing" | {
112
118
  ready?: NonNullable<"idle" | "walkthrough" | "focused" | "printing">;
113
- }, never, never, never, never>, T>, useDiagramSelector: {
119
+ }, never, never, never, never>, T> & {
120
+ Out: T;
121
+ }, useDiagramSelector: {
114
122
  <T>(select: (state: MachineSnapshot<DiagramContext, DiagramEvents, {
115
123
  overlays: OverlaysActorRef | undefined;
116
124
  search: SearchActorRef | undefined;
@@ -1,5 +1,5 @@
1
1
  import "../_virtual/_rolldown/runtime.js";
2
- import { createContext, useContext } from "react";
2
+ import { createContext, use, useContext } from "react";
3
3
  import { shallowEqual } from "fast-equals";
4
4
  import { isFunction } from "remeda";
5
5
  import { useSelector } from "@xstate/react";
@@ -9,7 +9,7 @@ var DiagramApiSafeContext = createContext(null);
9
9
  DiagramApiSafeContext.displayName = "DiagramApiSafeContext";
10
10
  var DiagramApiContextProvider = DiagramApiSafeContext.Provider;
11
11
  function useDiagram() {
12
- const ctx = useContext(DiagramApiSafeContext);
12
+ const ctx = use(DiagramApiSafeContext);
13
13
  if (ctx === null) throw new Error("DiagramApi is not provided");
14
14
  return ctx;
15
15
  }
@@ -1,21 +1,21 @@
1
1
  import "../_virtual/_rolldown/runtime.js";
2
- import { selectDiagramActor, useDiagramSnapshot } from "./useDiagram.js";
2
+ import { selectDiagramContext, useDiagramSelector } from "./safeContext.js";
3
3
  //#region src/hooks/useCurrentView.ts
4
- var selectViewId = selectDiagramActor((s) => s.context.view.id);
4
+ var selectViewId = selectDiagramContext((s) => s.view.id);
5
5
  /**
6
6
  * Returns current view id
7
7
  * Should be used only inside LikeC4Diagram
8
8
  */
9
9
  function useCurrentViewId() {
10
- return useDiagramSnapshot(selectViewId);
10
+ return useDiagramSelector(selectViewId);
11
11
  }
12
- var selectView = selectDiagramActor((s) => s.context.view);
12
+ var selectView = selectDiagramContext((s) => s.view);
13
13
  /**
14
14
  * Returns current view
15
15
  * Should be used only inside LikeC4Diagram
16
16
  */
17
17
  function useCurrentView() {
18
- return useDiagramSnapshot(selectView);
18
+ return useDiagramSelector(selectView);
19
19
  }
20
20
  //#endregion
21
21
  export { useCurrentView, useCurrentViewId };
@@ -6,34 +6,14 @@ import { shallowEqual } from "fast-equals";
6
6
  import { useSelector } from "@xstate/react";
7
7
  //#region src/hooks/useDiagram.ts
8
8
  /**
9
- * Helper to create a selector for diagram actor snapshot
10
- * @deprecated use {@link selectDiagramSnapshot}
11
- */
12
- function selectDiagramActor(selector) {
13
- return selector;
14
- }
15
- /**
16
- * Read diagram actor snapshot
17
- * @deprecated use {@link useDiagramSelector}
18
- */
19
- function useDiagramSnapshot(selector, compare = shallowEqual) {
20
- return useSelector(useDiagramActorRef(), selector, compare);
21
- }
22
- /**
23
- * Helper to create a selector for diagram actor snapshot
24
- * @deprecated use {@link selectDiagramContext}
25
- */
26
- function selectDiagramActorContext(selector) {
27
- return (state) => selector(state.context);
28
- }
29
- /**
30
9
  * Read diagram context
31
10
  * @deprecated use {@link useDiagramSelector}
32
11
  */
33
12
  function useDiagramContext(selector, compare = shallowEqual, deps = []) {
34
13
  const actorRef = useDiagramActorRef();
35
14
  const selectorRef = useCallbackRef(selector);
36
- return useSelector(actorRef, useCallback((s) => selectorRef(s.context), deps), compare);
15
+ const select = useCallback((s) => selectorRef(s.context), deps);
16
+ return useSelector(actorRef, select, compare);
37
17
  }
38
18
  /**
39
19
  * Subscribe to diagram emitted events
@@ -74,4 +54,4 @@ function useOnDiagramEvent(event, callback, options) {
74
54
  ]);
75
55
  }
76
56
  //#endregion
77
- export { selectDiagramActor, selectDiagramActorContext, selectDiagramContext, selectDiagramSnapshot, useDiagram, useDiagramActorRef, useDiagramContext, useDiagramSelector, useDiagramSnapshot, useOnDiagramEvent };
57
+ export { selectDiagramContext, selectDiagramSnapshot, useDiagram, useDiagramActorRef, useDiagramContext, useDiagramSelector, useOnDiagramEvent };