@likec4/diagram 1.36.0 → 1.36.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.
- package/bundle/{chunk-7MPUJFHj.js → chunk-DHvr-RGh.js} +54 -46
- package/bundle/custom.js +21 -21
- package/bundle/index.js +17 -16
- package/dist/likec4diagram/DiagramUI.js +2 -1
- package/dist/likec4diagram/ui/diagram-title/DiagramTitlePanel.js +4 -4
- package/dist/likec4model/LikeC4ModelContext.d.ts +2 -1
- package/dist/likec4model/LikeC4ModelContext.js +10 -2
- package/dist/likec4model/useCurrentViewModel.d.ts +1 -0
- package/dist/likec4model/useCurrentViewModel.js +4 -1
- package/dist/navigationpanel/controls/OpenSource.js +1 -1
- package/dist/state/DiagramActorProvider.js +9 -10
- package/dist/styles-min.css +1 -1
- package/dist/styles.css +1 -1
- package/dist/styles.css2.js +1 -1
- package/package.json +4 -4
- package/src/likec4diagram/DiagramUI.tsx +8 -2
- package/src/likec4diagram/ui/diagram-title/DiagramTitlePanel.tsx +4 -5
- package/src/likec4model/{LikeC4ModelContext.ts → LikeC4ModelContext.tsx} +9 -1
- package/src/likec4model/useCurrentViewModel.ts +4 -0
- package/src/navigationpanel/controls/OpenSource.tsx +1 -1
- package/src/state/DiagramActorProvider.tsx +11 -10
|
@@ -2,6 +2,7 @@ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
|
2
2
|
import { memo } from 'react';
|
|
3
3
|
import { useOverlaysActorRef } from '../hooks/useOverlaysActor.js';
|
|
4
4
|
import { useSearchActorRef } from '../hooks/useSearchActor.js';
|
|
5
|
+
import { EnsureCurrentViewModel } from '../likec4model/LikeC4ModelContext.js';
|
|
5
6
|
import { Overlays } from '../overlays/Overlays.js';
|
|
6
7
|
import { Search } from '../search/Search.js';
|
|
7
8
|
import { useEnabledFeatures } from '../context/DiagramFeatures.js';
|
|
@@ -22,7 +23,7 @@ const DiagramUI = memo(() => {
|
|
|
22
23
|
const overlaysActorRef = useOverlaysActorRef();
|
|
23
24
|
const searchActorRef = useSearchActorRef();
|
|
24
25
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
25
|
-
enableControls === "next" ? /* @__PURE__ */ jsx(NavigationPanel, {}) : /* @__PURE__ */ jsx(Controls, {}),
|
|
26
|
+
enableControls === "next" ? /* @__PURE__ */ jsx(EnsureCurrentViewModel, { children: /* @__PURE__ */ jsx(NavigationPanel, {}) }) : /* @__PURE__ */ jsx(Controls, {}),
|
|
26
27
|
overlaysActorRef && /* @__PURE__ */ jsx(Overlays, { overlaysActorRef }),
|
|
27
28
|
enableNotations && /* @__PURE__ */ jsx(NotationPanel, {}),
|
|
28
29
|
enableControls !== "next" && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
@@ -5,8 +5,8 @@ import { useLocalStorage } from '@mantine/hooks';
|
|
|
5
5
|
import { AnimatePresence, m } from 'motion/react';
|
|
6
6
|
import { Link } from '../../../components/Link.js';
|
|
7
7
|
import { useDiagramContext } from '../../../hooks/useDiagram.js';
|
|
8
|
+
import { useOptionalCurrentViewModel } from '../../../likec4model/useCurrentViewModel.js';
|
|
8
9
|
import { card, title, description } from './DiagramTitlePanel.css.js';
|
|
9
|
-
import { useCurrentViewModel } from '../../../likec4model/useCurrentViewModel.js';
|
|
10
10
|
import IconMenu from '../../../node_modules/.pnpm/@tabler_icons-react@3.34.1_react@19.1.1/node_modules/@tabler/icons-react/dist/esm/icons/IconMenu.js';
|
|
11
11
|
import { MarkdownBlock } from '../../../base/primitives/MarkdownBlock.js';
|
|
12
12
|
|
|
@@ -20,15 +20,15 @@ function selector(context) {
|
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
function DiagramTitlePanel() {
|
|
23
|
-
const view =
|
|
23
|
+
const view = useOptionalCurrentViewModel();
|
|
24
24
|
const { isNotActiveWalkthrough } = useDiagramContext(selector);
|
|
25
25
|
const [isCollapsed, setCollapsed] = useLocalStorage({
|
|
26
26
|
key: "diagram-title-webview-collapsed",
|
|
27
27
|
defaultValue: false
|
|
28
28
|
});
|
|
29
|
-
const title$1 = view
|
|
29
|
+
const title$1 = view?.title ?? "untitled";
|
|
30
30
|
const toggle = () => setCollapsed((v) => !v);
|
|
31
|
-
return /* @__PURE__ */ jsx(AnimatePresence, { mode: "wait", children: isNotActiveWalkthrough && /* @__PURE__ */ jsx(
|
|
31
|
+
return /* @__PURE__ */ jsx(AnimatePresence, { mode: "wait", children: view && isNotActiveWalkthrough && /* @__PURE__ */ jsx(
|
|
32
32
|
m.div,
|
|
33
33
|
{
|
|
34
34
|
initial: { opacity: 0.05, scale: 0.7 },
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { LikeC4Model, LikeC4ViewModel } from '@likec4/core/model';
|
|
2
2
|
import { aux, DiagramView } from '@likec4/core/types';
|
|
3
|
-
import { Context } from 'react';
|
|
3
|
+
import { PropsWithChildren, Context } from 'react';
|
|
4
4
|
export declare const LikeC4ModelContext: Context<LikeC4Model<any> | null>;
|
|
5
5
|
export type CurrentViewModel = LikeC4ViewModel<aux.UnknownLayouted, DiagramView<aux.UnknownLayouted>>;
|
|
6
6
|
export declare const CurrentViewModelContext: Context<CurrentViewModel | null>;
|
|
7
|
+
export declare function EnsureCurrentViewModel({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import { createContext, useContext } from 'react';
|
|
2
3
|
|
|
3
4
|
const LikeC4ModelContext = createContext(null);
|
|
4
5
|
const CurrentViewModelContext = createContext(null);
|
|
6
|
+
function EnsureCurrentViewModel({ children }) {
|
|
7
|
+
const viewmodel = useContext(CurrentViewModelContext);
|
|
8
|
+
if (!viewmodel) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
12
|
+
}
|
|
5
13
|
|
|
6
|
-
export { CurrentViewModelContext, LikeC4ModelContext };
|
|
14
|
+
export { CurrentViewModelContext, EnsureCurrentViewModel, LikeC4ModelContext };
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
2
|
import { CurrentViewModelContext } from './LikeC4ModelContext.js';
|
|
3
3
|
|
|
4
|
+
function useOptionalCurrentViewModel() {
|
|
5
|
+
return useContext(CurrentViewModelContext);
|
|
6
|
+
}
|
|
4
7
|
function useCurrentViewModel() {
|
|
5
8
|
const vm = useContext(CurrentViewModelContext);
|
|
6
9
|
if (!vm) {
|
|
@@ -9,4 +12,4 @@ function useCurrentViewModel() {
|
|
|
9
12
|
return vm;
|
|
10
13
|
}
|
|
11
14
|
|
|
12
|
-
export { useCurrentViewModel };
|
|
15
|
+
export { useCurrentViewModel, useOptionalCurrentViewModel };
|
|
@@ -19,7 +19,7 @@ const OpenSource = () => {
|
|
|
19
19
|
e.stopPropagation();
|
|
20
20
|
onOpenSource?.({ view: viewId });
|
|
21
21
|
},
|
|
22
|
-
children: /* @__PURE__ */ jsx(IconFileSymlink, {
|
|
22
|
+
children: /* @__PURE__ */ jsx(IconFileSymlink, { style: { width: "60%", height: "60%" } })
|
|
23
23
|
}
|
|
24
24
|
) });
|
|
25
25
|
};
|
|
@@ -8,7 +8,6 @@ import { ErrorBoundary } from '../components/ErrorFallback.js';
|
|
|
8
8
|
import { useDiagramEventHandlers } from '../context/DiagramEventHandlers.js';
|
|
9
9
|
import { useEnabledFeatures, DiagramFeatures } from '../context/DiagramFeatures.js';
|
|
10
10
|
import { DiagramActorContextProvider } from '../hooks/safeContext.js';
|
|
11
|
-
import { useCurrentViewId } from '../hooks/useCurrentViewId.js';
|
|
12
11
|
import { useViewToNodesEdges } from '../likec4diagram/useViewToNodesEdges.js';
|
|
13
12
|
import { CurrentViewModelContext } from '../likec4model/LikeC4ModelContext.js';
|
|
14
13
|
import { useLikeC4Model } from '../likec4model/useLikeC4Model.js';
|
|
@@ -90,31 +89,31 @@ function DiagramActorProvider({
|
|
|
90
89
|
actorRef.send({ type: "update.view", view, xyedges, xynodes });
|
|
91
90
|
}, [view, xyedges, xynodes]);
|
|
92
91
|
const toggledFeatures = useSelector(actorRef, selectToggledFeatures, shallowEqual);
|
|
93
|
-
return /* @__PURE__ */ jsx(DiagramActorContextProvider, { value: actorRef, children: /* @__PURE__ */ jsx(DiagramFeatures, { overrides: toggledFeatures, children: /* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsx(CurrentViewModelProvider, { children }) }) }) });
|
|
92
|
+
return /* @__PURE__ */ jsx(DiagramActorContextProvider, { value: actorRef, children: /* @__PURE__ */ jsx(DiagramFeatures, { overrides: toggledFeatures, children: /* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsx(CurrentViewModelProvider, { viewId: view.id, children }) }) }) });
|
|
94
93
|
}
|
|
95
94
|
function CurrentViewModelProvider({
|
|
96
|
-
children
|
|
95
|
+
children,
|
|
96
|
+
viewId
|
|
97
97
|
}) {
|
|
98
|
-
const viewId = useCurrentViewId();
|
|
99
98
|
const likec4model = useLikeC4Model();
|
|
100
|
-
const [viewmodel, setViewmodel] = useState(() => likec4model.
|
|
99
|
+
const [viewmodel, setViewmodel] = useState(() => likec4model.findView(viewId));
|
|
101
100
|
useEffect(() => {
|
|
102
101
|
setViewmodel((current) => {
|
|
103
102
|
const nextviewmodel = likec4model.findView(viewId);
|
|
104
103
|
if (!nextviewmodel) {
|
|
105
|
-
console.error(`View "${viewId}" not found in likec4model, current viewmodel: ${current
|
|
104
|
+
console.error(`View "${viewId}" not found in likec4model, current viewmodel: ${current?.id}`, {
|
|
106
105
|
currentViewModel: current,
|
|
107
106
|
likec4model
|
|
108
107
|
});
|
|
109
108
|
return current;
|
|
110
109
|
}
|
|
110
|
+
if (!nextviewmodel.isDiagram()) {
|
|
111
|
+
console.warn(`View "${viewId}" is not diagram.
|
|
112
|
+
Make sure you have LikeC4ModelProvider with layouted model.`);
|
|
113
|
+
}
|
|
111
114
|
return nextviewmodel;
|
|
112
115
|
});
|
|
113
116
|
}, [likec4model, viewId]);
|
|
114
|
-
if (!viewmodel.isDiagram()) {
|
|
115
|
-
console.warn(`View "${viewId}" is not diagram.
|
|
116
|
-
Make sure you have LikeC4ModelProvider with layouted model.`);
|
|
117
|
-
}
|
|
118
117
|
return /* @__PURE__ */ jsx(CurrentViewModelContext.Provider, { value: viewmodel, children });
|
|
119
118
|
}
|
|
120
119
|
function useActorEventHandlers(actorRef) {
|