@likec4/diagram 1.42.1 → 1.43.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.
@@ -8,4 +8,4 @@ export type LikeC4DiagramProps<A extends Any = Any> = PropsWithChildren<LikeC4Di
8
8
  *
9
9
  * Use {@link ReactLikeC4} or {@link LikeC4View} for ready-to-use component
10
10
  */
11
- export declare function LikeC4Diagram<A extends Any = Any>({ onCanvasClick, onCanvasContextMenu, onCanvasDblClick, onEdgeClick, onChange, onEdgeContextMenu, onNavigateTo, onNodeClick, onNodeContextMenu, onOpenSource, onBurgerMenuClick, onInitialized, view, className, readonly, controls, fitView, fitViewPadding: _fitViewPadding, pannable, zoomable, background, enableElementTags, enableFocusMode, enableElementDetails, enableRelationshipDetails, enableRelationshipBrowser, nodesDraggable, nodesSelectable, showNotations, showNavigationButtons, enableDynamicViewWalkthrough, dynamicViewVariant, enableSearch, initialWidth, initialHeight, experimentalEdgeEditing, reduceGraphics, renderIcon, where, reactFlowProps, renderNodes, children, }: LikeC4DiagramProps<A>): import("react/jsx-runtime").JSX.Element;
11
+ export declare function LikeC4Diagram<A extends Any = Any>({ onCanvasClick, onCanvasContextMenu, onCanvasDblClick, onEdgeClick, onChange, onEdgeContextMenu, onNavigateTo, onNodeClick, onNodeContextMenu, onOpenSource, onBurgerMenuClick, onInitialized, view, className, readonly, controls, fitView, fitViewPadding: _fitViewPadding, pannable, zoomable, background, enableElementTags, enableFocusMode, enableElementDetails, enableRelationshipDetails, enableRelationshipBrowser, nodesDraggable, nodesSelectable, enableNotations, showNavigationButtons, enableDynamicViewWalkthrough, dynamicViewVariant, enableSearch, initialWidth, initialHeight, experimentalEdgeEditing, reduceGraphics, renderIcon, where, reactFlowProps, renderNodes, children, }: LikeC4DiagramProps<A>): import("react/jsx-runtime").JSX.Element;
@@ -48,7 +48,7 @@ function LikeC4Diagram({
48
48
  enableRelationshipBrowser = false,
49
49
  nodesDraggable = !readonly,
50
50
  nodesSelectable = !readonly || enableFocusMode || !!onNavigateTo || !!onNodeClick,
51
- showNotations = true,
51
+ enableNotations = false,
52
52
  showNavigationButtons = !!onNavigateTo,
53
53
  enableDynamicViewWalkthrough = false,
54
54
  dynamicViewVariant,
@@ -102,7 +102,7 @@ function LikeC4Diagram({
102
102
  enableNavigationButtons: showNavigationButtons && !!onNavigateTo,
103
103
  enableDynamicViewWalkthrough: view._type === "dynamic" && enableDynamicViewWalkthrough,
104
104
  enableEdgeEditing: experimentalEdgeEditing,
105
- enableNotations: showNotations,
105
+ enableNotations,
106
106
  enableVscode: !!onOpenSource,
107
107
  enableControls: controls,
108
108
  enableElementTags
@@ -39,6 +39,11 @@ export type PaddingWithUnit = `${number}${PaddingUnit}` | number;
39
39
  * bottom: '8px',
40
40
  * left: '8px',
41
41
  * }
42
+ *
43
+ * {
44
+ * x: '16px',
45
+ * y: '16px',
46
+ * }
42
47
  */
43
48
  export type ViewPadding = PaddingWithUnit | {
44
49
  top?: PaddingWithUnit;
@@ -78,8 +83,8 @@ export interface LikeC4DiagramProperties<A extends Any = Unknown> {
78
83
  */
79
84
  fitView?: boolean | undefined;
80
85
  /**
81
- * Padding around the diagram
82
- * @default '8px'
86
+ * Padding around the diagram (number - pixels)
87
+ * @default 16 - 16px
83
88
  *
84
89
  * @see {@link ViewPadding}
85
90
  *
@@ -88,15 +93,15 @@ export interface LikeC4DiagramProperties<A extends Any = Unknown> {
88
93
  * <LikeC4Diagram
89
94
  * fitViewPadding={{
90
95
  * x: '16px',
91
- * y: '16px',
96
+ * y: 16,
92
97
  * }}
93
98
  * />
94
99
  *
95
100
  * <LikeC4Diagram
96
101
  * fitViewPadding={{
97
- * top: '8px',
102
+ * top: 8,
98
103
  * right: '8px',
99
- * bottom: '8px',
104
+ * bottom: '1px',
100
105
  * left: '8px',
101
106
  * }}
102
107
  * />
@@ -135,9 +140,9 @@ export interface LikeC4DiagramProperties<A extends Any = Unknown> {
135
140
  * Display notations in the bottom right corner
136
141
  * (Active if only notations are present)
137
142
  *
138
- * @default true
143
+ * @default false
139
144
  */
140
- showNotations?: boolean | undefined;
145
+ enableNotations?: boolean | undefined;
141
146
  /**
142
147
  * Display dropdown with details on relationship's label click
143
148
  * @default false
@@ -56,9 +56,28 @@ export interface LikeC4ViewProps<A extends t.aux.Any = t.aux.UnknownLayouted> {
56
56
  fitView?: boolean | undefined;
57
57
  /**
58
58
  * Padding around the diagram
59
- * @default '8px'
59
+ * @default '16px'
60
60
  *
61
61
  * @see {@link ViewPadding}
62
+ *
63
+ * @example
64
+ * ```tsx
65
+ * <LikeC4View
66
+ * fitViewPadding={{
67
+ * x: '16px',
68
+ * y: 16,
69
+ * }}
70
+ * />
71
+ *
72
+ * <LikeC4View
73
+ * fitViewPadding={{
74
+ * top: 8,
75
+ * right: '8px',
76
+ * bottom: '1px',
77
+ * left: '8px',
78
+ * }}
79
+ * />
80
+ * ```
62
81
  */
63
82
  fitViewPadding?: ViewPadding | undefined;
64
83
  /**
@@ -70,7 +89,7 @@ export interface LikeC4ViewProps<A extends t.aux.Any = t.aux.UnknownLayouted> {
70
89
  * Display notations of the view
71
90
  * @default false
72
91
  */
73
- showNotations?: boolean | undefined;
92
+ enableNotations?: boolean | undefined;
74
93
  /**
75
94
  * If double click on a node should enable focus mode, i.e. highlight incoming/outgoing edges
76
95
  * Conflicts with `browser` prop
@@ -210,7 +229,7 @@ export interface LikeC4BrowserProps {
210
229
  * Display notations of the view
211
230
  * @default true
212
231
  */
213
- showNotations?: boolean | undefined;
232
+ enableNotations?: boolean | undefined;
214
233
  /**
215
234
  * Improve performance by hiding certain elements and reducing visual effects (disable mix-blend, shadows, animations)
216
235
  *
@@ -236,4 +255,4 @@ export interface LikeC4BrowserProps {
236
255
  *
237
256
  * Component is wrapped in ShadowRoot to isolate styles.
238
257
  */
239
- export declare function LikeC4View<A extends t.aux.Any = t.aux.UnknownLayouted>({ viewId, className, pannable, zoomable, keepAspectRatio, colorScheme, injectFontCss, controls, background, browser, showNavigationButtons, showNotations, enableFocusMode, enableDynamicViewWalkthrough, enableElementDetails, enableRelationshipDetails, enableRelationshipBrowser, reduceGraphics, mantineTheme, styleNonce, style, reactFlowProps, renderNodes, children, ...props }: LikeC4ViewProps<A>): import("react/jsx-runtime").JSX.Element;
258
+ export declare function LikeC4View<A extends t.aux.Any = t.aux.UnknownLayouted>({ viewId, className, pannable, zoomable, keepAspectRatio, colorScheme, injectFontCss, controls, background, browser, showNavigationButtons, enableNotations, enableFocusMode, enableDynamicViewWalkthrough, enableElementDetails, enableRelationshipDetails, enableRelationshipBrowser, reduceGraphics, mantineTheme, styleNonce, style, reactFlowProps, renderNodes, children, ...props }: LikeC4ViewProps<A>): import("react/jsx-runtime").JSX.Element;
@@ -33,7 +33,7 @@ function LikeC4View({
33
33
  background = "transparent",
34
34
  browser = true,
35
35
  showNavigationButtons = false,
36
- showNotations,
36
+ enableNotations,
37
37
  enableFocusMode = false,
38
38
  enableDynamicViewWalkthrough = false,
39
39
  enableElementDetails = false,
@@ -68,9 +68,8 @@ function LikeC4View({
68
68
  ] });
69
69
  }
70
70
  const browserView = browserViewId ? likec4model.findView(browserViewId)?.$view : null;
71
- const notations = view.notation?.nodes ?? [];
72
- const hasNotations = notations.length > 0;
73
- showNotations ??= hasNotations;
71
+ const hasNotations = !!enableNotations && (view.notation?.nodes?.length ?? 0) > 0;
72
+ const browserViewHasNotations = (browserView?.notation?.nodes?.length ?? 0) > 0;
74
73
  const isBrowserEnabled = browser !== false;
75
74
  const browserProps = isBoolean(browser) ? {} : browser;
76
75
  const bounds = getViewBounds(view, props.dynamicViewVariant);
@@ -98,7 +97,7 @@ function LikeC4View({
98
97
  background,
99
98
  fitView: true,
100
99
  fitViewPadding: FitViewPaddings.default,
101
- showNotations,
100
+ enableNotations: hasNotations,
102
101
  enableDynamicViewWalkthrough,
103
102
  showNavigationButtons,
104
103
  experimentalEdgeEditing: false,
@@ -144,11 +143,12 @@ function LikeC4View({
144
143
  enableElementTags: true,
145
144
  controls: true,
146
145
  readonly: true,
146
+ nodesDraggable: false,
147
147
  fitView: true,
148
148
  ...props,
149
149
  fitViewPadding: FitViewPaddings.withControls,
150
150
  ...browserProps,
151
- showNotations: browserProps.showNotations ?? showNotations,
151
+ enableNotations: browserViewHasNotations && (browserProps.enableNotations ?? true),
152
152
  renderNodes
153
153
  }
154
154
  ),
@@ -36,4 +36,4 @@ export type ReactLikeC4Props<A extends t.aux.Any = t.aux.UnknownLayouted> = {
36
36
  *
37
37
  * Component is wrapped in ShadowRoot to isolate styles.
38
38
  */
39
- export declare function ReactLikeC4<A extends t.aux.Any = t.aux.UnknownLayouted>({ viewId, className, colorScheme, injectFontCss, keepAspectRatio, showNotations, style, mantineTheme, styleNonce, ...props }: ReactLikeC4Props<A>): import("react/jsx-runtime").JSX.Element;
39
+ export declare function ReactLikeC4<A extends t.aux.Any = t.aux.UnknownLayouted>({ viewId, className, colorScheme, injectFontCss, enableNotations, keepAspectRatio, style, mantineTheme, styleNonce, ...props }: ReactLikeC4Props<A>): import("react/jsx-runtime").JSX.Element;
@@ -11,8 +11,8 @@ function ReactLikeC4({
11
11
  className,
12
12
  colorScheme,
13
13
  injectFontCss = true,
14
+ enableNotations,
14
15
  keepAspectRatio,
15
- showNotations,
16
16
  style,
17
17
  mantineTheme,
18
18
  styleNonce,
@@ -33,10 +33,8 @@ function ReactLikeC4({
33
33
  '" is not layouted. Make sure you have LikeC4ModelProvider with layouted model.'
34
34
  ] });
35
35
  }
36
- const notations = view.notation?.nodes ?? [];
37
- const hasNotations = notations.length > 0;
38
- showNotations ??= hasNotations;
39
36
  const bounds = getViewBounds(view, props.dynamicViewVariant);
37
+ const hasNotations = !!enableNotations && (view.notation?.nodes?.length ?? 0) > 0;
40
38
  return /* @__PURE__ */ jsx(
41
39
  ShadowRoot,
42
40
  {
@@ -54,7 +52,7 @@ function ReactLikeC4({
54
52
  LikeC4Diagram,
55
53
  {
56
54
  view,
57
- showNotations,
55
+ enableNotations: hasNotations,
58
56
  ...props
59
57
  }
60
58
  )
@@ -24,7 +24,7 @@ function StaticLikeC4Diagram({
24
24
  zoomable: false,
25
25
  controls: false,
26
26
  background,
27
- showNotations: false,
27
+ enableNotations: false,
28
28
  enableElementDetails: false,
29
29
  enableRelationshipDetails,
30
30
  enableRelationshipBrowser,
@@ -9,7 +9,7 @@ export declare const MaxZoom = 3;
9
9
  export declare const FitViewPaddings: {
10
10
  default: "16px";
11
11
  withControls: {
12
- top: "50px";
12
+ top: "58px";
13
13
  left: "16px";
14
14
  right: "16px";
15
15
  bottom: "16px";
@@ -10,7 +10,7 @@ const MaxZoom = 3;
10
10
  const FitViewPaddings = {
11
11
  default: "16px",
12
12
  withControls: {
13
- top: "50px",
13
+ top: "58px",
14
14
  left: "16px",
15
15
  right: "16px",
16
16
  bottom: "16px"
@@ -112,16 +112,13 @@ const ElementNotation = ({ value }) => {
112
112
  };
113
113
  const selector = (s) => ({
114
114
  id: s.view.id,
115
- notations: s.view.notation?.nodes ?? [],
116
- isVisible: true
117
- // isVisible: isNullish(s.focusedNodeId ?? s.activeWalkthrough),
115
+ notations: s.view.notation?.nodes ?? []
118
116
  });
119
117
  const NotationPanel = memo(() => {
120
118
  const height = useXYStore((s) => s.height);
121
119
  const {
122
120
  id,
123
- notations,
124
- isVisible
121
+ notations
125
122
  } = useDiagramContext(selector);
126
123
  const [isCollapsed, setCollapsed] = useLocalStorage({
127
124
  key: "notation-webview-collapsed",
@@ -130,7 +127,7 @@ const NotationPanel = memo(() => {
130
127
  const hasNotations = notations.length > 0;
131
128
  const portalProps = useMantinePortalProps();
132
129
  return /* @__PURE__ */ jsxs(AnimatePresence, { children: [
133
- !hasNotations && isVisible && /* @__PURE__ */ jsx(
130
+ !hasNotations && /* @__PURE__ */ jsx(
134
131
  m.div,
135
132
  {
136
133
  initial: { opacity: 0.75, translateX: "50%" },
@@ -153,7 +150,7 @@ const NotationPanel = memo(() => {
153
150
  },
154
151
  "empty"
155
152
  ),
156
- hasNotations && isVisible && isCollapsed && /* @__PURE__ */ jsx(
153
+ hasNotations && isCollapsed && /* @__PURE__ */ jsx(
157
154
  m.div,
158
155
  {
159
156
  initial: { opacity: 0.75, translateX: "50%" },
@@ -177,7 +174,7 @@ const NotationPanel = memo(() => {
177
174
  },
178
175
  "collapsed"
179
176
  ),
180
- hasNotations && isVisible && !isCollapsed && /* @__PURE__ */ jsx(
177
+ hasNotations && !isCollapsed && /* @__PURE__ */ jsx(
181
178
  m.div,
182
179
  {
183
180
  initial: {
@@ -12,6 +12,7 @@ import { Link } from '../../components/Link.js';
12
12
  import { useCurrentViewModel } from '../../hooks/useCurrentViewModel.js';
13
13
  import { useDiagram } from '../../hooks/useDiagram.js';
14
14
  import { elementIcon, card, cardHeader, title, tabsPanel, tabsTab, tabsList, tabsRoot, propertiesGrid, resizeHandle, backdropOpacity, backdropBlur, dialog, propertyLabel, viewButton, viewButtonTitle } from './ElementDetailsCard.css.js';
15
+ import { MetadataProvider, MetadataValue } from './MetadataValue.js';
15
16
  import { TabPanelDeployments } from './TabPanelDeployments.js';
16
17
  import { TabPanelRelationships } from './TabPanelRelationships.js';
17
18
  import { TabPanelStructure } from './TabPanelStructure.js';
@@ -340,7 +341,7 @@ function ElementDetailsCard({
340
341
  )
341
342
  ] })
342
343
  ] }),
343
- /* @__PURE__ */ jsxs(
344
+ /* @__PURE__ */ jsx(MetadataProvider, { children: /* @__PURE__ */ jsxs(
344
345
  Tabs,
345
346
  {
346
347
  value: activeTab,
@@ -420,7 +421,7 @@ function ElementDetailsCard({
420
421
  /* @__PURE__ */ jsx(TabsPanel, { value: "Deployments", children: /* @__PURE__ */ jsx(ScrollArea, { scrollbars: "y", type: "auto", children: /* @__PURE__ */ jsx(TabPanelDeployments, { elementFqn: elementModel.id }) }) })
421
422
  ]
422
423
  }
423
- ),
424
+ ) }),
424
425
  /* @__PURE__ */ jsx(
425
426
  m.div,
426
427
  {
@@ -476,97 +477,24 @@ function ElementProperty({
476
477
  function ElementMetata({
477
478
  value: metadata
478
479
  }) {
479
- return /* @__PURE__ */ jsxs(Fragment, { children: [
480
- /* @__PURE__ */ jsx(PropertyLabel, { children: "metadata" }),
480
+ const metadataEntries = entries(metadata).sort(([a], [b]) => a.localeCompare(b));
481
+ return /* @__PURE__ */ jsx(MetadataProvider, { children: /* @__PURE__ */ jsxs(Fragment, { children: [
482
+ /* @__PURE__ */ jsx(PropertyLabel, { style: { justifySelf: "end", textAlign: "right" }, children: "metadata" }),
481
483
  /* @__PURE__ */ jsx(
482
484
  Box,
483
485
  {
484
486
  className: css({
485
- flex: 1,
486
487
  display: "grid",
487
488
  gridTemplateColumns: "min-content 1fr",
488
- gridAutoRows: "min-content max-content",
489
- gap: `[4px 4px]`,
489
+ gridAutoRows: "min-content",
490
+ gap: `[12px 16px]`,
490
491
  alignItems: "baseline",
491
- justifyItems: "stretch",
492
- paddingRight: "xxs"
492
+ justifyItems: "stretch"
493
493
  }),
494
- children: entries(metadata).map(([key, value]) => /* @__PURE__ */ jsxs(
495
- "div",
496
- {
497
- style: {
498
- display: "contents"
499
- },
500
- className: "group",
501
- children: [
502
- /* @__PURE__ */ jsxs(
503
- "div",
504
- {
505
- className: css({
506
- fontSize: "sm",
507
- fontWeight: 500,
508
- justifySelf: "end",
509
- whiteSpace: "nowrap"
510
- }),
511
- children: [
512
- key,
513
- ":"
514
- ]
515
- }
516
- ),
517
- /* @__PURE__ */ jsx(
518
- "div",
519
- {
520
- className: css({}),
521
- children: /* @__PURE__ */ jsx(
522
- ScrollArea.Autosize,
523
- {
524
- type: "auto",
525
- mah: 200,
526
- classNames: {
527
- root: css({
528
- transitionProperty: "all",
529
- transitionDuration: "fast",
530
- transitionTimingFunction: "inOut",
531
- rounded: "sm",
532
- color: "mantine.colors.gray[8]",
533
- _dark: {
534
- color: "mantine.colors.dark[1]"
535
- },
536
- _groupHover: {
537
- transitionTimingFunction: "out",
538
- color: "mantine.colors.defaultColor",
539
- background: "mantine.colors.defaultHover"
540
- }
541
- }),
542
- viewport: css({
543
- overscrollBehavior: "none"
544
- })
545
- },
546
- children: /* @__PURE__ */ jsx(
547
- "div",
548
- {
549
- className: css({
550
- fontSize: "sm",
551
- padding: "xxs",
552
- whiteSpace: "pre",
553
- fontFamily: "mono",
554
- userSelect: "all"
555
- }),
556
- children: value
557
- }
558
- )
559
- }
560
- )
561
- }
562
- )
563
- ]
564
- },
565
- key
566
- ))
494
+ children: metadataEntries.map(([key, value]) => /* @__PURE__ */ jsx(MetadataValue, { label: key, value }, key))
567
495
  }
568
496
  )
569
- ] });
497
+ ] }) });
570
498
  }
571
499
 
572
500
  export { ElementDetailsCard };
@@ -0,0 +1,9 @@
1
+ export declare function MetadataProvider({ children }: {
2
+ children: React.ReactNode;
3
+ }): import("react/jsx-runtime").JSX.Element;
4
+ interface MetadataValueProps {
5
+ label: string;
6
+ value: string | string[];
7
+ }
8
+ export declare function MetadataValue({ label, value }: MetadataValueProps): import("react/jsx-runtime").JSX.Element;
9
+ export {};