@likec4/diagram 1.21.1 → 1.22.1

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 (120) hide show
  1. package/dist/LikeC4Diagram.js +9 -13
  2. package/dist/base/index.d.ts +0 -1
  3. package/dist/base/primitives/element/styles.css.js +1 -1
  4. package/dist/{base → components}/Link.css.js +3 -3
  5. package/dist/components/SearchControl.css.d.ts +2 -0
  6. package/dist/components/SearchControl.css.js +7 -0
  7. package/dist/components/SearchControl.d.ts +5 -0
  8. package/dist/components/SearchControl.js +17 -0
  9. package/dist/context/DiagramFeatures.d.ts +1 -1
  10. package/dist/context/IconRenderer.d.ts +10 -0
  11. package/dist/context/IconRenderer.js +34 -0
  12. package/dist/hooks/useCurrentViewId.js +8 -0
  13. package/dist/hooks/useDiagram.d.ts +108 -72
  14. package/dist/hooks/useDiagram.js +3 -0
  15. package/dist/likec4diagram/DiagramActor.js +13 -2
  16. package/dist/likec4diagram/DiagramUI.js +0 -2
  17. package/dist/likec4diagram/XYFlow.d.ts +6 -1
  18. package/dist/likec4diagram/XYFlow.js +37 -31
  19. package/dist/likec4diagram/custom/edges/RelationshipsDropdownMenu.js +2 -1
  20. package/dist/likec4diagram/state/actorContext.d.ts +620 -468
  21. package/dist/likec4diagram/state/assign.js +1 -1
  22. package/dist/likec4diagram/state/machine.d.ts +120 -74
  23. package/dist/likec4diagram/state/machine.js +32 -12
  24. package/dist/likec4diagram/state/syncManualLayoutActor.js +4 -8
  25. package/dist/likec4diagram/ui/controls/Controls.js +65 -48
  26. package/dist/likec4diagram/ui/controls/NavigationButtons.js +44 -69
  27. package/dist/likec4diagram/ui/controls/ToggleReadonly.d.ts +1 -0
  28. package/dist/likec4diagram/ui/controls/ToggleReadonly.js +29 -0
  29. package/dist/likec4diagram/ui/controls/_shared.js +1 -1
  30. package/dist/likec4diagram/ui/diagram-title/DiagramTitlePanel.js +1 -1
  31. package/dist/likec4diagram/ui/search/ElementsColumn.css.d.ts +15 -0
  32. package/dist/likec4diagram/ui/search/ElementsColumn.css.js +30 -0
  33. package/dist/likec4diagram/ui/search/ElementsColumn.d.ts +1 -0
  34. package/dist/likec4diagram/ui/search/ElementsColumn.js +243 -0
  35. package/dist/likec4diagram/ui/search/LikeC4Search.css.d.ts +8 -0
  36. package/dist/likec4diagram/ui/search/LikeC4Search.css.js +20 -0
  37. package/dist/likec4diagram/ui/search/LikeC4Search.d.ts +1 -0
  38. package/dist/likec4diagram/ui/search/LikeC4Search.js +265 -0
  39. package/dist/likec4diagram/ui/search/SearchInput.d.ts +1 -0
  40. package/dist/likec4diagram/ui/search/SearchInput.js +196 -0
  41. package/dist/likec4diagram/ui/search/ViewsColum.d.ts +9 -0
  42. package/dist/likec4diagram/ui/search/ViewsColum.js +130 -0
  43. package/dist/likec4diagram/ui/search/ViewsColumn.css.d.ts +5 -0
  44. package/dist/likec4diagram/ui/search/ViewsColumn.css.js +12 -0
  45. package/dist/likec4diagram/ui/search/_shared.css.d.ts +16 -0
  46. package/dist/likec4diagram/ui/search/_shared.css.js +5 -0
  47. package/dist/likec4diagram/ui/search/state.d.ts +19 -0
  48. package/dist/likec4diagram/ui/search/state.js +72 -0
  49. package/dist/likec4diagram/ui/search/utils.d.ts +3 -0
  50. package/dist/likec4diagram/ui/search/utils.js +23 -0
  51. package/dist/likec4diagram/useLayoutConstraints.js +4 -5
  52. package/dist/likec4model/useLikeC4ElementsTree.d.ts +1 -0
  53. package/dist/likec4model/useLikeC4ElementsTree.js +1 -0
  54. package/dist/overlays/Overlays.js +9 -9
  55. package/dist/overlays/element-details/ElementDetailsCard.js +20 -13
  56. package/dist/overlays/overlay/Overlay.d.ts +6 -2
  57. package/dist/overlays/overlay/Overlay.js +18 -29
  58. package/dist/overlays/relationship-details/SelectEdge.js +1 -3
  59. package/dist/overlays/relationships-browser/RelationshipsBrowser.js +6 -5
  60. package/dist/overlays/relationships-browser/SelectElement.js +10 -6
  61. package/dist/overlays/relationships-browser/actor.d.ts +2 -2
  62. package/dist/overlays/relationships-browser/actor.js +8 -8
  63. package/dist/overlays/relationships-browser/custom/nodeTypes.js +2 -2
  64. package/dist/style.css +1 -1
  65. package/package.json +13 -13
  66. package/src/LikeC4Diagram.tsx +0 -1
  67. package/src/base/index.ts +0 -2
  68. package/src/base/primitives/element/styles.css.ts +2 -2
  69. package/src/{base → components}/Link.css.ts +3 -3
  70. package/src/components/SearchControl.css.ts +69 -0
  71. package/src/components/SearchControl.tsx +33 -0
  72. package/src/context/DiagramFeatures.tsx +1 -1
  73. package/src/context/IconRenderer.tsx +54 -1
  74. package/src/globals.css.ts +0 -2
  75. package/src/hooks/useDiagram.ts +5 -0
  76. package/src/likec4diagram/DiagramActor.tsx +15 -2
  77. package/src/likec4diagram/DiagramUI.tsx +0 -4
  78. package/src/likec4diagram/XYFlow.tsx +39 -31
  79. package/src/likec4diagram/custom/edges/RelationshipsDropdownMenu.tsx +2 -1
  80. package/src/likec4diagram/state/assign.ts +1 -1
  81. package/src/likec4diagram/state/machine.ts +40 -14
  82. package/src/likec4diagram/state/syncManualLayoutActor.ts +6 -9
  83. package/src/likec4diagram/ui/controls/Controls.tsx +37 -25
  84. package/src/likec4diagram/ui/controls/NavigationButtons.tsx +36 -58
  85. package/src/likec4diagram/ui/controls/ToggleReadonly.tsx +31 -0
  86. package/src/likec4diagram/ui/controls/styles.css.ts +3 -1
  87. package/src/likec4diagram/ui/diagram-title/DiagramTitlePanel.tsx +1 -1
  88. package/src/likec4diagram/ui/search/ElementsColumn.css.ts +119 -0
  89. package/src/likec4diagram/ui/search/ElementsColumn.tsx +291 -0
  90. package/src/likec4diagram/ui/search/LikeC4Search.css.ts +117 -0
  91. package/src/likec4diagram/ui/search/LikeC4Search.tsx +312 -0
  92. package/src/likec4diagram/ui/search/SearchInput.tsx +235 -0
  93. package/src/likec4diagram/ui/search/ViewsColum.tsx +158 -0
  94. package/src/likec4diagram/ui/search/ViewsColumn.css.ts +37 -0
  95. package/src/likec4diagram/ui/search/_shared.css.ts +104 -0
  96. package/src/likec4diagram/ui/search/state.ts +76 -0
  97. package/src/likec4diagram/ui/search/utils.ts +20 -0
  98. package/src/likec4diagram/useLayoutConstraints.ts +4 -5
  99. package/src/likec4model/useLikeC4ElementsTree.ts +4 -4
  100. package/src/overlays/Overlays.tsx +31 -25
  101. package/src/overlays/element-details/ElementDetailsCard.css.ts +4 -4
  102. package/src/overlays/element-details/ElementDetailsCard.tsx +245 -240
  103. package/src/overlays/overlay/Overlay.css.ts +10 -9
  104. package/src/overlays/overlay/Overlay.tsx +38 -26
  105. package/src/overlays/relationship-details/SelectEdge.css.ts +1 -0
  106. package/src/overlays/relationship-details/SelectEdge.tsx +2 -4
  107. package/src/overlays/relationships-browser/RelationshipsBrowser.tsx +10 -5
  108. package/src/overlays/relationships-browser/SelectElement.tsx +88 -82
  109. package/src/overlays/relationships-browser/actor.ts +10 -10
  110. package/src/overlays/relationships-browser/custom/nodeTypes.tsx +2 -2
  111. package/dist/LikeC4Search.css.d.ts +0 -1
  112. package/dist/LikeC4Search.css.js +0 -5
  113. package/dist/LikeC4Search.d.ts +0 -2
  114. package/dist/LikeC4Search.js +0 -88
  115. package/src/LikeC4Search.css.ts +0 -12
  116. package/src/LikeC4Search.tsx +0 -91
  117. /package/dist/{base → components}/Link.css.d.ts +0 -0
  118. /package/dist/{base → components}/Link.d.ts +0 -0
  119. /package/dist/{base → components}/Link.js +0 -0
  120. /package/src/{base → components}/Link.tsx +0 -0
@@ -1,18 +1,20 @@
1
- import { jsx, Fragment, jsxs } from "react/jsx-runtime";
2
- import { Stack, ActionIconGroup, Badge, Loader } from "@mantine/core";
3
- import { openSpotlight } from "@mantine/spotlight";
4
- import { IconSearch, IconFileSymlink, IconFocusCentered } from "@tabler/icons-react";
1
+ import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
+ import { Group, Stack, ActionIconGroup, Badge, Loader } from "@mantine/core";
3
+ import { IconMenu2, IconFileSymlink, IconFocusCentered } from "@tabler/icons-react";
5
4
  import { clsx } from "clsx";
5
+ import { LayoutGroup } from "framer-motion";
6
6
  import { memo } from "react";
7
7
  import { useDiagram } from "../../../hooks/useDiagram.js";
8
8
  import { useDiagramSyncLayoutState } from "../../../hooks/useDiagramActor.js";
9
9
  import { useDiagramContext } from "../../../hooks/useDiagramContext.js";
10
- import { Tooltip, ActionIcon } from "./_shared.js";
10
+ import { LikeC4Search } from "../search/LikeC4Search.js";
11
+ import { ActionIcon, Tooltip } from "./_shared.js";
11
12
  import { ChangeAutoLayoutButton } from "./ChangeAutoLayoutButton.js";
12
13
  import { LayoutDriftNotification } from "./LayoutDriftNotification.js";
13
14
  import { ManualLayoutToolsButton } from "./ManualLayoutToolsButton.js";
14
15
  import { NavigationButtons } from "./NavigationButtons.js";
15
- import { actionIconGroup, panel } from "./styles.css.js";
16
+ import { navigationButtons, actionIconGroup, panel } from "./styles.css.js";
17
+ import { ToggleReadonly } from "./ToggleReadonly.js";
16
18
  import { useDiagramEventHandlers } from "../../../context/DiagramEventHandlers.js";
17
19
  import { useEnabledFeatures } from "../../../context/DiagramFeatures.js";
18
20
  import { useMantinePortalProps } from "../../../hooks/useMantinePortalProps.js";
@@ -25,72 +27,87 @@ const Controls = memo(() => {
25
27
  }));
26
28
  const diagram = useDiagram();
27
29
  const {
28
- onOpenSource
30
+ onOpenSource,
31
+ onBurgerMenuClick
29
32
  } = useDiagramEventHandlers();
30
33
  const {
31
34
  enableControls,
32
35
  enableSearch,
33
36
  enableNavigationButtons,
34
37
  enableReadOnly,
35
- enableEdgeEditing,
36
38
  enableVscode
37
39
  } = useEnabledFeatures();
38
40
  const notReadOnly = !enableReadOnly;
39
41
  const portalProps = useMantinePortalProps();
40
- return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(
41
- Stack,
42
+ return /* @__PURE__ */ jsxs(
43
+ Group,
42
44
  {
45
+ align: "flex-start",
43
46
  className: clsx(
44
47
  "react-flow__panel",
45
48
  panel,
46
49
  "likec4-top-left-panel"
47
50
  ),
48
- align: "flex-start",
49
- onClick: stopPropagation,
50
51
  gap: "xs",
52
+ onClick: stopPropagation,
51
53
  children: [
52
- enableNavigationButtons && /* @__PURE__ */ jsx(NavigationButtons, {}),
53
- /* @__PURE__ */ jsxs(ActionIconGroup, { className: actionIconGroup, orientation: "vertical", children: [
54
- enableControls && enableSearch && /* @__PURE__ */ jsx(Tooltip, { label: "Search (Ctrl+F or ⌘+F)", ...portalProps, children: /* @__PURE__ */ jsx(
55
- ActionIcon,
54
+ /* @__PURE__ */ jsxs(Stack, { align: "flex-start", gap: "xs", children: [
55
+ /* @__PURE__ */ jsx(LayoutGroup, { children: /* @__PURE__ */ jsxs(
56
+ Group,
56
57
  {
57
- onClick: (e) => {
58
- e.stopPropagation();
59
- openSpotlight();
60
- },
61
- children: /* @__PURE__ */ jsx(IconSearch, {})
58
+ className: clsx(navigationButtons, "likec4-navigation-webview"),
59
+ gap: "xs",
60
+ children: [
61
+ onBurgerMenuClick && /* @__PURE__ */ jsx(
62
+ ActionIcon,
63
+ {
64
+ onClick: (e) => {
65
+ e.stopPropagation();
66
+ onBurgerMenuClick();
67
+ },
68
+ children: /* @__PURE__ */ jsx(IconMenu2, {})
69
+ }
70
+ ),
71
+ enableNavigationButtons && /* @__PURE__ */ jsx(NavigationButtons, {})
72
+ ]
62
73
  }
63
74
  ) }),
64
- enableVscode && /* @__PURE__ */ jsx(Tooltip, { label: "Open source", ...portalProps, children: /* @__PURE__ */ jsx(
65
- ActionIcon,
66
- {
67
- onClick: (e) => {
68
- e.stopPropagation();
69
- onOpenSource == null ? void 0 : onOpenSource({ view: viewId });
70
- },
71
- children: /* @__PURE__ */ jsx(IconFileSymlink, { stroke: 1.5 })
72
- }
73
- ) }),
74
- enableControls && hasLayoutDrift && /* @__PURE__ */ jsx(LayoutDriftNotification, { ...portalProps }),
75
- enableControls && notReadOnly && /* @__PURE__ */ jsxs(Fragment, { children: [
76
- /* @__PURE__ */ jsx(ChangeAutoLayoutButton, { ...portalProps }),
77
- /* @__PURE__ */ jsx(ManualLayoutToolsButton, { ...portalProps })
78
- ] }),
79
- enableControls && /* @__PURE__ */ jsx(Tooltip, { label: viewportChanged ? "Center camera" : "Camera is centered", ...portalProps, children: /* @__PURE__ */ jsx(
80
- ActionIcon,
81
- {
82
- onClick: (e) => {
83
- e.stopPropagation();
84
- diagram.fitDiagram();
85
- },
86
- children: /* @__PURE__ */ jsx(IconFocusCentered, {})
87
- }
88
- ) })
75
+ /* @__PURE__ */ jsxs(ActionIconGroup, { className: actionIconGroup, orientation: "vertical", children: [
76
+ enableVscode && /* @__PURE__ */ jsx(Tooltip, { label: "Open source", ...portalProps, children: /* @__PURE__ */ jsx(
77
+ ActionIcon,
78
+ {
79
+ onClick: (e) => {
80
+ e.stopPropagation();
81
+ onOpenSource == null ? void 0 : onOpenSource({ view: viewId });
82
+ },
83
+ children: /* @__PURE__ */ jsx(IconFileSymlink, { stroke: 1.5 })
84
+ }
85
+ ) }),
86
+ enableControls && /* @__PURE__ */ jsx(ToggleReadonly, {}),
87
+ enableControls && hasLayoutDrift && /* @__PURE__ */ jsx(LayoutDriftNotification, { ...portalProps }),
88
+ enableControls && notReadOnly && /* @__PURE__ */ jsxs(Fragment, { children: [
89
+ /* @__PURE__ */ jsx(ChangeAutoLayoutButton, { ...portalProps }),
90
+ /* @__PURE__ */ jsx(ManualLayoutToolsButton, { ...portalProps })
91
+ ] }),
92
+ enableControls && /* @__PURE__ */ jsx(Tooltip, { label: viewportChanged ? "Center camera" : "Camera is centered", ...portalProps, children: /* @__PURE__ */ jsx(
93
+ ActionIcon,
94
+ {
95
+ onClick: (e) => {
96
+ e.stopPropagation();
97
+ diagram.fitDiagram();
98
+ },
99
+ children: /* @__PURE__ */ jsx(IconFocusCentered, {})
100
+ }
101
+ ) })
102
+ ] })
89
103
  ] }),
90
- notReadOnly && /* @__PURE__ */ jsx(SyncLayoutBadge, {})
104
+ /* @__PURE__ */ jsxs(Group, { children: [
105
+ enableSearch && /* @__PURE__ */ jsx(LikeC4Search, {}),
106
+ notReadOnly && /* @__PURE__ */ jsx(SyncLayoutBadge, {})
107
+ ] })
91
108
  ]
92
109
  }
93
- ) });
110
+ );
94
111
  });
95
112
  const SyncLayoutBadge = () => {
96
113
  const isPending = useDiagramSyncLayoutState((s) => s.hasTag("pending"));
@@ -1,16 +1,11 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
2
- import { IconMenu2, IconChevronLeft, IconChevronRight } from "@tabler/icons-react";
3
- import { LayoutGroup, AnimatePresence, m } from "framer-motion";
4
- import { Group } from "@mantine/core";
5
- import clsx from "clsx";
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { IconChevronLeft, IconChevronRight } from "@tabler/icons-react";
3
+ import { AnimatePresence, m } from "framer-motion";
6
4
  import { useDiagram } from "../../../hooks/useDiagram.js";
7
5
  import { useDiagramContext } from "../../../hooks/useDiagramContext.js";
8
6
  import { ActionIcon } from "./_shared.js";
9
- import { navigationButtons } from "./styles.css.js";
10
- import { useDiagramEventHandlers } from "../../../context/DiagramEventHandlers.js";
11
7
  const NavigationButtons = () => {
12
8
  const diagram = useDiagram();
13
- const { onBurgerMenuClick } = useDiagramEventHandlers();
14
9
  const {
15
10
  hasStepBack,
16
11
  hasStepForward
@@ -18,74 +13,54 @@ const NavigationButtons = () => {
18
13
  hasStepBack: s.navigationHistory.currentIndex > 0,
19
14
  hasStepForward: s.navigationHistory.currentIndex < s.navigationHistory.history.length - 1
20
15
  }));
21
- return /* @__PURE__ */ jsx(LayoutGroup, { children: /* @__PURE__ */ jsxs(
22
- Group,
23
- {
24
- className: clsx(navigationButtons, "likec4-navigation-webview"),
25
- align: "flex-start",
26
- gap: "xs",
27
- children: [
28
- onBurgerMenuClick && /* @__PURE__ */ jsx(
16
+ return /* @__PURE__ */ jsxs(AnimatePresence, { children: [
17
+ hasStepBack && /* @__PURE__ */ jsx(
18
+ m.div,
19
+ {
20
+ layout: true,
21
+ initial: { opacity: 0.05, transform: "translateX(-10px)" },
22
+ animate: { opacity: 1, transform: "translateX(0)" },
23
+ exit: {
24
+ opacity: 0.05,
25
+ transform: "translateX(-10px)"
26
+ },
27
+ children: /* @__PURE__ */ jsx(
29
28
  ActionIcon,
30
29
  {
31
30
  onClick: (e) => {
32
31
  e.stopPropagation();
33
- onBurgerMenuClick();
32
+ diagram.navigate("back");
34
33
  },
35
- children: /* @__PURE__ */ jsx(IconMenu2, {})
34
+ children: /* @__PURE__ */ jsx(IconChevronLeft, {})
36
35
  }
37
- ),
38
- /* @__PURE__ */ jsxs(AnimatePresence, { children: [
39
- hasStepBack && /* @__PURE__ */ jsx(
40
- m.div,
41
- {
42
- layout: true,
43
- initial: { opacity: 0.05, transform: "translateX(-10px)" },
44
- animate: { opacity: 1, transform: "translateX(0)" },
45
- exit: {
46
- opacity: 0.05,
47
- transform: "translateX(-10px)"
48
- },
49
- children: /* @__PURE__ */ jsx(
50
- ActionIcon,
51
- {
52
- onClick: (e) => {
53
- e.stopPropagation();
54
- diagram.navigate("back");
55
- },
56
- children: /* @__PURE__ */ jsx(IconChevronLeft, {})
57
- }
58
- )
59
- },
60
- "back"
61
- ),
62
- hasStepForward && /* @__PURE__ */ jsx(
63
- m.div,
64
- {
65
- layout: true,
66
- initial: { opacity: 0.05, transform: "translateX(10px)" },
67
- animate: { opacity: 1, transform: "translateX(0)" },
68
- exit: {
69
- opacity: 0,
70
- transform: "translateX(10px)"
71
- },
72
- children: /* @__PURE__ */ jsx(
73
- ActionIcon,
74
- {
75
- onClick: (e) => {
76
- e.stopPropagation();
77
- diagram.navigate("forward");
78
- },
79
- children: /* @__PURE__ */ jsx(IconChevronRight, {})
80
- }
81
- )
36
+ )
37
+ },
38
+ "back"
39
+ ),
40
+ hasStepForward && /* @__PURE__ */ jsx(
41
+ m.div,
42
+ {
43
+ layout: true,
44
+ initial: { opacity: 0.05, transform: "translateX(10px)" },
45
+ animate: { opacity: 1, transform: "translateX(0)" },
46
+ exit: {
47
+ opacity: 0,
48
+ transform: "translateX(10px)"
49
+ },
50
+ children: /* @__PURE__ */ jsx(
51
+ ActionIcon,
52
+ {
53
+ onClick: (e) => {
54
+ e.stopPropagation();
55
+ diagram.navigate("forward");
82
56
  },
83
- "forward"
84
- )
85
- ] })
86
- ]
87
- }
88
- ) });
57
+ children: /* @__PURE__ */ jsx(IconChevronRight, {})
58
+ }
59
+ )
60
+ },
61
+ "forward"
62
+ )
63
+ ] });
89
64
  };
90
65
  export {
91
66
  NavigationButtons
@@ -0,0 +1 @@
1
+ export declare const ToggleReadonly: () => import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,29 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { IconLock, IconLockOpen2 } from "@tabler/icons-react";
3
+ import { useDiagram } from "../../../hooks/useDiagram.js";
4
+ import { useDiagramContext } from "../../../hooks/useDiagramContext.js";
5
+ import { Tooltip, ActionIcon } from "./_shared.js";
6
+ const selector = (state) => ({
7
+ visible: state.features.enableReadOnly !== true,
8
+ isReadOnly: state.toggledFeatures.enableReadOnly ?? state.features.enableReadOnly
9
+ });
10
+ const ToggleReadonly = () => {
11
+ const { visible, isReadOnly } = useDiagramContext(selector);
12
+ const diagram = useDiagram();
13
+ if (!visible) {
14
+ return null;
15
+ }
16
+ return /* @__PURE__ */ jsx(Tooltip, { label: isReadOnly ? "Enable editing" : "Disable editing", children: /* @__PURE__ */ jsx(
17
+ ActionIcon,
18
+ {
19
+ onClick: (e) => {
20
+ e.stopPropagation();
21
+ diagram.toggleFeature("ReadOnly");
22
+ },
23
+ children: isReadOnly ? /* @__PURE__ */ jsx(IconLock, {}) : /* @__PURE__ */ jsx(IconLockOpen2, {})
24
+ }
25
+ ) });
26
+ };
27
+ export {
28
+ ToggleReadonly
29
+ };
@@ -1,4 +1,4 @@
1
- import { Tooltip as Tooltip$1, ActionIcon as ActionIcon$1 } from "@mantine/core";
1
+ import { ActionIcon as ActionIcon$1, Tooltip as Tooltip$1 } from "@mantine/core";
2
2
  const Tooltip = Tooltip$1.withProps({
3
3
  color: "dark",
4
4
  fz: "xs",
@@ -4,9 +4,9 @@ import { useLocalStorage } from "@mantine/hooks";
4
4
  import { IconMenu } from "@tabler/icons-react";
5
5
  import clsx from "clsx";
6
6
  import { AnimatePresence, m } from "framer-motion";
7
+ import { Link } from "../../../components/Link.js";
7
8
  import { useDiagramContext } from "../../../hooks/useDiagramContext.js";
8
9
  import { card, title, description, container } from "./DiagramTitlePanel.css.js";
9
- import { Link } from "../../../base/Link.js";
10
10
  const selector = (s) => ({
11
11
  id: s.view.id,
12
12
  title: s.view.title ?? "untitled",
@@ -0,0 +1,15 @@
1
+ export { focusable } from './_shared.css';
2
+ export declare const treeContainer: string;
3
+ export declare const treeNode: string;
4
+ export declare const treeRoot: string;
5
+ export declare const treeLabel: string;
6
+ export declare const treeSubtree: string;
7
+ export declare const iconSize: `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
8
+ export declare const elementExpandIcon: string;
9
+ export declare const elementButton: string;
10
+ export declare const elementTitleAndId: string;
11
+ export declare const elementTitle: string;
12
+ export declare const elementId: string;
13
+ export declare const elementDescription: string;
14
+ export declare const elementIcon: string;
15
+ export declare const elementViewsCount: string;
@@ -0,0 +1,30 @@
1
+ /* empty css */
2
+ /* empty css */
3
+ var focusable = "_1cfw8gr4";
4
+ var treeNode = "basone1";
5
+ var treeRoot = "basone2";
6
+ var treeLabel = "basone3";
7
+ var treeSubtree = "basone4";
8
+ var elementExpandIcon = "basone5";
9
+ var elementButton = "basone6 _1cfw8gr3";
10
+ var elementTitleAndId = "basone7";
11
+ var elementTitle = "basone8 _1cfw8gr5";
12
+ var elementId = "basone9";
13
+ var elementDescription = "basonea _1cfw8gr6";
14
+ var elementIcon = "basoneb";
15
+ var elementViewsCount = "basonec";
16
+ export {
17
+ elementButton,
18
+ elementDescription,
19
+ elementExpandIcon,
20
+ elementIcon,
21
+ elementId,
22
+ elementTitle,
23
+ elementTitleAndId,
24
+ elementViewsCount,
25
+ focusable,
26
+ treeLabel,
27
+ treeNode,
28
+ treeRoot,
29
+ treeSubtree
30
+ };
@@ -0,0 +1 @@
1
+ export declare function ElementsColumn(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,243 @@
1
+ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
2
+ import { ifilter, toArray, sortParentsFirst, isAncestor, nameFromFqn } from "@likec4/core";
3
+ import { useTree, Tree, ActionIcon, UnstyledButton, Box, Group, Highlight, Tooltip, Text } from "@mantine/core";
4
+ import { useCallbackRef } from "@mantine/hooks";
5
+ import { IconChevronRight } from "@tabler/icons-react";
6
+ import clsx from "clsx";
7
+ import { m } from "framer-motion";
8
+ import { useMemo, useEffect } from "react";
9
+ import { isEmpty, pipe, reduce, indexBy, prop, first, only, partition } from "remeda";
10
+ import { IconOrShapeRenderer } from "../../../context/IconRenderer.js";
11
+ import { sortByLabel } from "../../../likec4model/useLikeC4ElementsTree.js";
12
+ import { useLikeC4Model } from "../../../likec4model/useLikeC4Model.js";
13
+ import { treeSubtree, treeLabel, treeRoot, focusable, treeNode, elementExpandIcon, elementTitleAndId, elementTitle, elementId, elementDescription, elementViewsCount, elementButton, elementIcon } from "./ElementsColumn.css.js";
14
+ import { useNormalizedSearch, useCloseSearchAndNavigateTo, setPickView } from "./state.js";
15
+ import { stopAndPrevent, moveFocusToSearchInput, centerY } from "./utils.js";
16
+ import { NothingFound } from "./ViewsColum.js";
17
+ function ElementsColumn() {
18
+ const search = useNormalizedSearch();
19
+ const model = useLikeC4Model(true);
20
+ const {
21
+ all,
22
+ byid,
23
+ roots: data
24
+ } = useMemo(() => {
25
+ const searchTerms = search.split(".");
26
+ let elements;
27
+ if (isEmpty(search) || search === "kind:") {
28
+ elements = model.elements();
29
+ } else {
30
+ elements = ifilter(model.elements(), (element) => {
31
+ if (search.startsWith("kind:")) {
32
+ return element.kind.toLocaleLowerCase().startsWith(search.slice(5));
33
+ }
34
+ if (search.startsWith("#")) {
35
+ return element.tags.some((tag) => tag.toLocaleLowerCase().includes(search.slice(1)));
36
+ }
37
+ return (element.title + " " + element.id + " " + (element.description ?? "")).toLocaleLowerCase().includes(search);
38
+ });
39
+ }
40
+ const { all: all2, roots } = pipe(
41
+ elements,
42
+ toArray(),
43
+ sortParentsFirst,
44
+ reduce((acc, element) => {
45
+ const treeItem = {
46
+ label: element.title,
47
+ value: element.id,
48
+ element,
49
+ searchTerms,
50
+ children: []
51
+ };
52
+ const parent = acc.all.findLast((root) => isAncestor(root.value, treeItem.value));
53
+ if (parent) {
54
+ parent.children.push(treeItem);
55
+ if (parent.children.length > 1) {
56
+ parent.children.sort(sortByLabel);
57
+ }
58
+ } else {
59
+ acc.roots.push(treeItem);
60
+ }
61
+ acc.all.push(treeItem);
62
+ return acc;
63
+ }, {
64
+ all: [],
65
+ roots: []
66
+ })
67
+ );
68
+ return {
69
+ all: all2,
70
+ byid: indexBy(all2, prop("value")),
71
+ roots: roots.sort(sortByLabel)
72
+ };
73
+ }, [model, search]);
74
+ const tree = useTree({
75
+ multiple: false
76
+ });
77
+ useEffect(() => {
78
+ tree.collapseAllNodes();
79
+ for (const nd of all) {
80
+ if (nd.children.length > 0) {
81
+ tree.expand(nd.value);
82
+ }
83
+ }
84
+ }, [all]);
85
+ const handleClick = useHandleElementSelection();
86
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
87
+ data.length === 0 && /* @__PURE__ */ jsx(NothingFound, {}),
88
+ /* @__PURE__ */ jsx(
89
+ Tree,
90
+ {
91
+ "data-likec4-search-elements": true,
92
+ allowRangeSelection: false,
93
+ clearSelectionOnOutsideClick: true,
94
+ selectOnClick: false,
95
+ tree,
96
+ data,
97
+ levelOffset: "lg",
98
+ classNames: {
99
+ root: treeRoot,
100
+ node: clsx(focusable, treeNode),
101
+ label: treeLabel,
102
+ subtree: treeSubtree
103
+ },
104
+ onKeyDownCapture: (e) => {
105
+ var _a;
106
+ const target = e.target;
107
+ const id = target.getAttribute("data-value");
108
+ const node = !!id && byid[id];
109
+ if (!node) return;
110
+ if (e.key === "ArrowUp") {
111
+ if (id === ((_a = data[0]) == null ? void 0 : _a.value)) {
112
+ stopAndPrevent(e);
113
+ moveFocusToSearchInput();
114
+ }
115
+ return;
116
+ }
117
+ if (e.key === "ArrowRight") {
118
+ const hasChildren = node.children.length > 0;
119
+ if (hasChildren && tree.expandedState[id] === false) {
120
+ return;
121
+ }
122
+ const label = e.target.querySelector(".mantine-Tree-label") ?? target;
123
+ const maxY = label.getBoundingClientRect().y;
124
+ const viewButtons = [...document.querySelectorAll(
125
+ `[data-likec4-search-views] .${focusable}`
126
+ )];
127
+ let view = viewButtons.length > 1 ? viewButtons.find((el, i, all2) => centerY(el) > maxY || i === all2.length - 1) : null;
128
+ view ?? (view = first(viewButtons));
129
+ if (view) {
130
+ stopAndPrevent(e);
131
+ view.focus();
132
+ }
133
+ return;
134
+ }
135
+ if (e.key === " " || e.key === "Enter") {
136
+ stopAndPrevent(e);
137
+ handleClick(node.element);
138
+ return;
139
+ }
140
+ },
141
+ renderNode: ElementTreeNode
142
+ }
143
+ )
144
+ ] });
145
+ }
146
+ function ElementTreeNode({ node, elementProps, hasChildren, expanded }) {
147
+ const { element, searchTerms } = node;
148
+ const elementIcon$1 = IconOrShapeRenderer({
149
+ element: {
150
+ id: element.id,
151
+ title: element.title,
152
+ shape: element.shape,
153
+ icon: element.icon
154
+ },
155
+ className: elementIcon
156
+ });
157
+ const views = [...element.views()];
158
+ const handleClick = useHandleElementSelection();
159
+ const key = `@tree.${node.value}`;
160
+ return /* @__PURE__ */ jsxs(m.div, { layoutId: key, ...elementProps, children: [
161
+ /* @__PURE__ */ jsx(
162
+ ActionIcon,
163
+ {
164
+ variant: "transparent",
165
+ size: 16,
166
+ tabIndex: -1,
167
+ className: clsx(elementExpandIcon),
168
+ style: {
169
+ visibility: hasChildren ? "visible" : "hidden"
170
+ },
171
+ children: /* @__PURE__ */ jsx(
172
+ IconChevronRight,
173
+ {
174
+ stroke: 3.5,
175
+ style: {
176
+ transition: "transform 150ms ease",
177
+ transform: `rotate(${expanded ? "90deg" : "0"})`,
178
+ width: "100%"
179
+ }
180
+ }
181
+ )
182
+ }
183
+ ),
184
+ /* @__PURE__ */ jsxs(
185
+ UnstyledButton,
186
+ {
187
+ component: m.button,
188
+ layout: true,
189
+ tabIndex: -1,
190
+ className: clsx(elementButton, "likec4-element-button"),
191
+ ...views.length > 0 && {
192
+ onClick: (e) => {
193
+ if (!hasChildren || expanded) {
194
+ e.stopPropagation();
195
+ handleClick(element);
196
+ }
197
+ }
198
+ },
199
+ children: [
200
+ elementIcon$1,
201
+ /* @__PURE__ */ jsxs(Box, { style: { flexGrow: 1 }, children: [
202
+ /* @__PURE__ */ jsxs(Group, { gap: "xs", wrap: "nowrap", align: "center", className: elementTitleAndId, children: [
203
+ /* @__PURE__ */ jsx(Highlight, { component: "div", highlight: searchTerms, className: elementTitle, children: node.label }),
204
+ /* @__PURE__ */ jsx(Tooltip, { label: element.id, withinPortal: false, fz: "xs", disabled: !element.id.includes("."), children: /* @__PURE__ */ jsx(Highlight, { component: "div", highlight: searchTerms, className: elementId, children: nameFromFqn(element.id) }) })
205
+ ] }),
206
+ /* @__PURE__ */ jsx(Highlight, { component: "div", highlight: searchTerms, className: elementDescription, lineClamp: 1, children: element.description || "No description" })
207
+ ] }),
208
+ /* @__PURE__ */ jsx(Text, { component: "div", className: elementViewsCount, children: views.length === 0 ? "No views" : /* @__PURE__ */ jsxs(Fragment, { children: [
209
+ views.length,
210
+ " view",
211
+ views.length > 1 ? "s" : ""
212
+ ] }) })
213
+ ]
214
+ }
215
+ )
216
+ ] }, key);
217
+ }
218
+ function useHandleElementSelection() {
219
+ const navigateTo = useCloseSearchAndNavigateTo();
220
+ return useCallbackRef((element) => {
221
+ const views = [...element.views()];
222
+ if (views.length === 0) {
223
+ return;
224
+ }
225
+ const singleView = only(views);
226
+ if (singleView) {
227
+ navigateTo(singleView.id, element.id);
228
+ return;
229
+ }
230
+ const [scoped, others] = partition(views, (v) => {
231
+ var _a;
232
+ return ((_a = v.viewOf) == null ? void 0 : _a.id) === element.id;
233
+ });
234
+ setPickView({
235
+ elementFqn: element.id,
236
+ scoped,
237
+ others
238
+ });
239
+ });
240
+ }
241
+ export {
242
+ ElementsColumn
243
+ };
@@ -0,0 +1,8 @@
1
+ export { focusable } from './_shared.css';
2
+ export declare const backdrop: string;
3
+ export declare const root: string;
4
+ export declare const input: string;
5
+ export declare const pickviewBackdrop: string;
6
+ export declare const pickview: string;
7
+ export declare const pickviewGroup: string;
8
+ export declare const scrollArea: string;
@@ -0,0 +1,20 @@
1
+ /* empty css */
2
+ /* empty css */
3
+ var focusable = "_1cfw8gr4";
4
+ var backdrop = "eien2d0";
5
+ var root = "eien2d1";
6
+ var input = "eien2d2";
7
+ var pickviewBackdrop = "eien2d3";
8
+ var pickview = "eien2d4";
9
+ var pickviewGroup = "eien2d5";
10
+ var scrollArea = "eien2d6";
11
+ export {
12
+ backdrop,
13
+ focusable,
14
+ input,
15
+ pickview,
16
+ pickviewBackdrop,
17
+ pickviewGroup,
18
+ root,
19
+ scrollArea
20
+ };