likec4 1.12.0 → 1.12.2

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.
@@ -11,7 +11,7 @@ import {
11
11
  import { memo, type PropsWithChildren, useCallback, useState } from 'react'
12
12
  import { Icons } from 'virtual:likec4/icons'
13
13
  import type { DiagramView, LikeC4ElementKind, LikeC4Tag, LikeC4ViewId } from 'virtual:likec4/model'
14
- import { likec4model as likeC4Model, LikeC4Views, useLikeC4ModelAtom } from 'virtual:likec4/model'
14
+ import { likec4model as likeC4Model, LikeC4Views, useLikeC4ModelAtom as useLikeC4Model } from 'virtual:likec4/model'
15
15
 
16
16
  type IconRendererProps = {
17
17
  node: {
@@ -26,16 +26,12 @@ export function RenderIcon({ node }: IconRendererProps) {
26
26
  return IconComponent ? <IconComponent /> : null
27
27
  }
28
28
 
29
- export { likeC4Model, LikeC4Views }
30
-
31
- export function useLikeC4Model() {
32
- return useLikeC4ModelAtom()
33
- }
29
+ export { likeC4Model, LikeC4Views, useLikeC4Model }
34
30
 
35
31
  export const useLikeC4ViewModel = (viewId: LikeC4ViewId): LikeC4Model.Layouted.ViewModel =>
36
- useLikeC4ModelAtom().view(viewId)
32
+ useLikeC4Model().view(viewId)
37
33
 
38
- export const useLikeC4View = (viewId: LikeC4ViewId): DiagramView => useLikeC4ModelAtom().view(viewId).view as any
34
+ export const useLikeC4View = (viewId: LikeC4ViewId): DiagramView => useLikeC4Model().view(viewId).view as any
39
35
 
40
36
  export type LikeC4ViewProps = BaseLikeC4ViewProps<LikeC4ViewId, LikeC4Tag, LikeC4ElementKind>
41
37
 
@@ -66,7 +62,7 @@ const NotFound = ({ viewId }: { viewId: string }) => (
66
62
  )
67
63
 
68
64
  export function LikeC4ModelProvider({ children }: PropsWithChildren) {
69
- const likeC4Model = useLikeC4ModelAtom()
65
+ const likeC4Model = useLikeC4Model()
70
66
  return (
71
67
  <GenericLikeC4ModelProvider likec4model={likeC4Model}>
72
68
  {children}
@@ -91,6 +87,7 @@ const LikeC4ViewMemo = /* @__PURE__ */ memo<LikeC4ViewProps>(function LikeC4View
91
87
  browserClassName,
92
88
  browserStyle,
93
89
  mantineTheme,
90
+ styleNonce,
94
91
  ...props
95
92
  }) {
96
93
  const view = LikeC4Views[viewId]
@@ -134,6 +131,7 @@ const LikeC4ViewMemo = /* @__PURE__ */ memo<LikeC4ViewProps>(function LikeC4View
134
131
  showRelationshipDetails={showRelationshipDetails}
135
132
  where={where}
136
133
  mantineTheme={mantineTheme}
134
+ styleNonce={styleNonce}
137
135
  {...props}
138
136
  />
139
137
  {browserView && (
@@ -149,13 +147,13 @@ const LikeC4ViewMemo = /* @__PURE__ */ memo<LikeC4ViewProps>(function LikeC4View
149
147
  className={browserClassName}
150
148
  style={browserStyle}
151
149
  mantineTheme={mantineTheme}
150
+ styleNonce={styleNonce}
152
151
  />
153
152
  )}
154
153
  </LikeC4ModelProvider>
155
154
  )
156
155
  })
157
156
  LikeC4ViewMemo.displayName = 'LikeC4ViewMemo'
158
- export { LikeC4ViewMemo as LikeC4View }
159
157
 
160
158
  export type ReactLikeC4Props =
161
159
  & Omit<GenericReactLikeC4Props<LikeC4ViewId, LikeC4Tag, LikeC4ElementKind>, 'view' | 'renderIcon'>
@@ -163,7 +161,7 @@ export type ReactLikeC4Props =
163
161
  viewId: LikeC4ViewId
164
162
  }
165
163
 
166
- export function ReactLikeC4({ viewId, ...props }: ReactLikeC4Props) {
164
+ const ReactLikeC4Memo = /* @__PURE__ */ memo<ReactLikeC4Props>(function ReactLikeC4({ viewId, ...props }) {
167
165
  const view = LikeC4Views[viewId]
168
166
  if (!view) {
169
167
  return <NotFound viewId={viewId} />
@@ -177,4 +175,7 @@ export function ReactLikeC4({ viewId, ...props }: ReactLikeC4Props) {
177
175
  />
178
176
  </LikeC4ModelProvider>
179
177
  )
180
- }
178
+ })
179
+ ReactLikeC4Memo.displayName = 'ReactLikeC4Memo'
180
+
181
+ export { LikeC4ViewMemo as LikeC4View, ReactLikeC4Memo as ReactLikeC4 }
@@ -1,10 +1,10 @@
1
1
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
2
  import { useOverviewGraph } from "virtual:likec4/overview-graph";
3
- import { u, c as createReactComponent, I as IconFolderFilled, e, a as useUpdateEffect, n as nonexhaustive } from "./main-Bc_PC5BH.js";
4
- import { u as useRouter } from "./tanstack-router-CU5V4Ll-.js";
5
- import { B as BaseEdge, H as Handle, P as Position, u as useNodesState, a as useEdgesState, i as index, b as Background, c as BackgroundVariant } from "./likec4-DlkyDuSp.js";
3
+ import { u, c as createReactComponent, I as IconFolderFilled, e, a as useUpdateEffect, n as nonexhaustive } from "./main-BqtsxvKL.js";
4
+ import { u as useRouter } from "./tanstack-router-COsz5nw6.js";
5
+ import { B as BaseEdge, H as Handle, P as Position, u as useNodesState, a as useEdgesState, i as index, b as Background, c as BackgroundVariant } from "./likec4-CNg5BLwi.js";
6
6
  import { memo, useRef, useMemo } from "react";
7
- import { P as Paper, c as clsx, G as Group, T as ThemeIcon, a as Text, C as Card, b as CardSection, d as Center, I as Image, B as Box, u as useMantineColorScheme } from "./mantine-IOl1S4mZ.js";
7
+ import { P as Paper, c as clsx, G as Group, T as ThemeIcon, a as Text, C as Card, b as CardSection, d as Center, I as Image, B as Box, u as useMantineColorScheme } from "./mantine-CN5aX5HW.js";
8
8
  import { usePreviewUrl } from "virtual:likec4/previews";
9
9
  function a(...n) {
10
10
  return u(c, n);
@@ -15,14 +15,14 @@ function c(n, r) {
15
15
  return o;
16
16
  }
17
17
  /**
18
- * @license @tabler/icons-react v3.19.0 - MIT
18
+ * @license @tabler/icons-react v3.17.0 - MIT
19
19
  *
20
20
  * This source code is licensed under the MIT license.
21
21
  * See the LICENSE file in the root directory of this source tree.
22
22
  */
23
23
  var IconLoader = createReactComponent("outline", "loader", "IconLoader", [["path", { d: "M12 6l0 -3", key: "svg-0" }], ["path", { d: "M16.25 7.75l2.15 -2.15", key: "svg-1" }], ["path", { d: "M18 12l3 0", key: "svg-2" }], ["path", { d: "M16.25 16.25l2.15 2.15", key: "svg-3" }], ["path", { d: "M12 18l0 3", key: "svg-4" }], ["path", { d: "M7.75 16.25l-2.15 2.15", key: "svg-5" }], ["path", { d: "M6 12l-3 0", key: "svg-6" }], ["path", { d: "M7.75 7.75l-2.15 -2.15", key: "svg-7" }]]);
24
24
  /**
25
- * @license @tabler/icons-react v3.19.0 - MIT
25
+ * @license @tabler/icons-react v3.17.0 - MIT
26
26
  *
27
27
  * This source code is licensed under the MIT license.
28
28
  * See the LICENSE file in the root directory of this source tree.
@@ -197,13 +197,13 @@ function creator(name) {
197
197
  }
198
198
  function none() {
199
199
  }
200
- function selector(selector2) {
200
+ function selector$4(selector2) {
201
201
  return selector2 == null ? none : function() {
202
202
  return this.querySelector(selector2);
203
203
  };
204
204
  }
205
205
  function selection_select(select2) {
206
- typeof select2 != "function" && (select2 = selector(select2));
206
+ typeof select2 != "function" && (select2 = selector$4(select2));
207
207
  for (var groups = this._groups, m2 = groups.length, subgroups = new Array(m2), j = 0; j < m2; ++j)
208
208
  for (var group = groups[j], n2 = group.length, subgroup = subgroups[j] = new Array(n2), node, subnode, i = 0; i < n2; ++i)
209
209
  (node = group[i]) && (subnode = select2.call(node, node.__data__, i, group)) && ("__data__" in node && (subnode.__data__ = node.__data__), subgroup[i] = subnode);
@@ -594,7 +594,7 @@ function constantNull() {
594
594
  return null;
595
595
  }
596
596
  function selection_insert(name, before) {
597
- var create2 = typeof name == "function" ? name : creator(name), select2 = before == null ? constantNull : typeof before == "function" ? before : selector(before);
597
+ var create2 = typeof name == "function" ? name : creator(name), select2 = before == null ? constantNull : typeof before == "function" ? before : selector$4(before);
598
598
  return this.select(function() {
599
599
  return this.insertBefore(create2.apply(this, arguments), select2.apply(this, arguments) || null);
600
600
  });
@@ -1747,7 +1747,7 @@ function transition_remove() {
1747
1747
  }
1748
1748
  function transition_select(select2) {
1749
1749
  var name = this._name, id2 = this._id;
1750
- typeof select2 != "function" && (select2 = selector(select2));
1750
+ typeof select2 != "function" && (select2 = selector$4(select2));
1751
1751
  for (var groups = this._groups, m2 = groups.length, subgroups = new Array(m2), j = 0; j < m2; ++j)
1752
1752
  for (var group = groups[j], n2 = group.length, subgroup = subgroups[j] = new Array(n2), node, subnode, i = 0; i < n2; ++i)
1753
1753
  (node = group[i]) && (subnode = select2.call(node, node.__data__, i, group)) && ("__data__" in node && (subnode.__data__ = node.__data__), subgroup[i] = subnode, schedule(subgroup[i], name, id2, i, subgroup, get(node, id2)));
@@ -2772,6 +2772,32 @@ function createMarkerIds(edges, { id: id2, defaultColor, defaultMarkerStart, def
2772
2772
  }
2773
2773
  }), markers), []).sort((a, b) => a.id.localeCompare(b.id));
2774
2774
  }
2775
+ function getNodeToolbarTransform(nodeRect, viewport, position, offset, align) {
2776
+ let alignmentOffset = 0.5;
2777
+ align === "start" ? alignmentOffset = 0 : align === "end" && (alignmentOffset = 1);
2778
+ let pos = [
2779
+ (nodeRect.x + nodeRect.width * alignmentOffset) * viewport.zoom + viewport.x,
2780
+ nodeRect.y * viewport.zoom + viewport.y - offset
2781
+ ], shift = [-100 * alignmentOffset, -100];
2782
+ switch (position) {
2783
+ case Position.Right:
2784
+ pos = [
2785
+ (nodeRect.x + nodeRect.width) * viewport.zoom + viewport.x + offset,
2786
+ (nodeRect.y + nodeRect.height * alignmentOffset) * viewport.zoom + viewport.y
2787
+ ], shift = [0, -100 * alignmentOffset];
2788
+ break;
2789
+ case Position.Bottom:
2790
+ pos[1] = (nodeRect.y + nodeRect.height) * viewport.zoom + viewport.y + offset, shift[1] = 0;
2791
+ break;
2792
+ case Position.Left:
2793
+ pos = [
2794
+ nodeRect.x * viewport.zoom + viewport.x - offset,
2795
+ (nodeRect.y + nodeRect.height * alignmentOffset) * viewport.zoom + viewport.y
2796
+ ], shift = [-100, -100 * alignmentOffset];
2797
+ break;
2798
+ }
2799
+ return `translate(${pos[0]}px, ${pos[1]}px) translate(${shift[0]}%, ${shift[1]}%)`;
2800
+ }
2775
2801
  const defaultOptions = {
2776
2802
  nodeOrigin: [0, 0],
2777
2803
  nodeExtent: infiniteExtent,
@@ -5662,16 +5688,6 @@ function useOnViewportChange({ onStart, onChange, onEnd }) {
5662
5688
  store.setState({ onViewportChangeEnd: onEnd });
5663
5689
  }, [onEnd]);
5664
5690
  }
5665
- function useOnSelectionChange({ onChange }) {
5666
- const store = useStoreApi();
5667
- useEffect(() => {
5668
- const nextOnSelectionChangeHandlers = [...store.getState().onSelectionChangeHandlers, onChange];
5669
- return store.setState({ onSelectionChangeHandlers: nextOnSelectionChangeHandlers }), () => {
5670
- const nextHandlers = store.getState().onSelectionChangeHandlers.filter((fn) => fn !== onChange);
5671
- store.setState({ onSelectionChangeHandlers: nextHandlers });
5672
- };
5673
- }, [onChange]);
5674
- }
5675
5691
  function useNodesData(nodeIds) {
5676
5692
  return useStore(useCallback((s) => {
5677
5693
  const data = [], isArrayOfIds = Array.isArray(nodeIds), _nodeIds = isArrayOfIds ? nodeIds : [nodeIds];
@@ -6004,11 +6020,45 @@ function ResizeControl({ nodeId, position, variant = ResizeControlVariant.Handle
6004
6020
  return jsx("div", { className: cc(["react-flow__resize-control", "nodrag", ...positionClassNames, variant, className]), ref: resizeControlRef, style: controlStyle, children: children2 });
6005
6021
  }
6006
6022
  memo(ResizeControl);
6023
+ const selector = (state) => state.domNode?.querySelector(".react-flow__renderer");
6024
+ function NodeToolbarPortal({ children: children2 }) {
6025
+ const wrapperRef = useStore(selector);
6026
+ return wrapperRef ? createPortal(children2, wrapperRef) : null;
6027
+ }
6028
+ const nodeEqualityFn = (a, b) => a?.internals.positionAbsolute.x !== b?.internals.positionAbsolute.x || a?.internals.positionAbsolute.y !== b?.internals.positionAbsolute.y || a?.measured.width !== b?.measured.width || a?.measured.height !== b?.measured.height || a?.selected !== b?.selected || a?.internals.z !== b?.internals.z, nodesEqualityFn = (a, b) => {
6029
+ if (a.size !== b.size)
6030
+ return !1;
6031
+ for (const [key, node] of a)
6032
+ if (nodeEqualityFn(node, b.get(key)))
6033
+ return !1;
6034
+ return !0;
6035
+ }, storeSelector = (state) => ({
6036
+ x: state.transform[0],
6037
+ y: state.transform[1],
6038
+ zoom: state.transform[2],
6039
+ selectedNodesCount: state.nodes.filter((node) => node.selected).length
6040
+ });
6041
+ function NodeToolbar({ nodeId, children: children2, className, style: style2, isVisible, position = Position.Top, offset = 10, align = "center", ...rest }) {
6042
+ const contextNodeId = useNodeId(), nodesSelector2 = useCallback((state) => (Array.isArray(nodeId) ? nodeId : [nodeId || contextNodeId || ""]).reduce((res, id2) => {
6043
+ const node = state.nodeLookup.get(id2);
6044
+ return node && res.set(node.id, node), res;
6045
+ }, /* @__PURE__ */ new Map()), [nodeId, contextNodeId]), nodes = useStore(nodesSelector2, nodesEqualityFn), { x, y, zoom: zoom2, selectedNodesCount } = useStore(storeSelector, shallow$1);
6046
+ if (!(typeof isVisible == "boolean" ? isVisible : nodes.size === 1 && nodes.values().next().value.selected && selectedNodesCount === 1) || !nodes.size)
6047
+ return null;
6048
+ const nodeRect = getInternalNodesBounds(nodes), nodesArray = Array.from(nodes.values()), zIndex = Math.max(...nodesArray.map((node) => node.internals.z + 1)), wrapperStyle2 = {
6049
+ position: "absolute",
6050
+ transform: getNodeToolbarTransform(nodeRect, { x, y, zoom: zoom2 }, position, offset, align),
6051
+ zIndex,
6052
+ ...style2
6053
+ };
6054
+ return jsx(NodeToolbarPortal, { children: jsx("div", { style: wrapperStyle2, className: cc(["react-flow__node-toolbar", className]), ...rest, "data-id": nodesArray.reduce((acc, node) => `${acc}${node.id} `, "").trim(), children: children2 }) });
6055
+ }
6007
6056
  export {
6008
6057
  BaseEdge as B,
6009
6058
  Controls as C,
6010
6059
  EdgeLabelRenderer as E,
6011
6060
  Handle as H,
6061
+ NodeToolbar as N,
6012
6062
  Position as P,
6013
6063
  ReactFlowProvider as R,
6014
6064
  useEdgesState as a,
@@ -6016,8 +6066,8 @@ export {
6016
6066
  BackgroundVariant as c,
6017
6067
  useReactFlow as d,
6018
6068
  useStoreApi as e,
6019
- useNodesData as f,
6020
- useStore as g,
6069
+ useStore as f,
6070
+ useNodesData as g,
6021
6071
  createWithEqualityFn as h,
6022
6072
  index as i,
6023
6073
  applyNodeChanges as j,
@@ -6030,7 +6080,6 @@ export {
6030
6080
  getDefaultExportFromCjs as q,
6031
6081
  useOnViewportChange as r,
6032
6082
  shallow$1 as s,
6033
- useOnSelectionChange as t,
6034
6083
  useNodesState as u,
6035
6084
  withSelectorExports as w
6036
6085
  };