@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.
- package/README.md +53 -0
- package/dist/LikeC4Diagram.d.ts +1 -1
- package/dist/LikeC4Diagram.js +36 -21
- package/dist/LikeC4Diagram.props.d.ts +23 -0
- package/dist/LikeC4MantineProvider.d.ts +24 -0
- package/dist/LikeC4MantineProvider.js +156 -0
- package/dist/LikeC4ProjectsOverview.js +1 -1
- package/dist/LikeC4ProjectsProvider.d.ts +17 -2
- package/dist/LikeC4Styles.d.ts +13 -3
- package/dist/LikeC4Styles.js +10 -6
- package/dist/LikeC4View.js +2 -2
- package/dist/StaticLikeC4Diagram.d.ts +1 -1
- package/dist/base/BaseXYFlow.d.ts +1 -1
- package/dist/base/BaseXYFlow.js +19 -9
- package/dist/base/const.d.ts +1 -0
- package/dist/base/const.js +3 -1
- package/dist/base-primitives/Markdown.d.ts +3 -3
- package/dist/base-primitives/compound/CompoundNodeContainer.js +2 -3
- package/dist/base-primitives/compound/CompoundTitle.js +5 -4
- package/dist/base-primitives/compound/actionbtns.css.d.ts +3 -3
- package/dist/base-primitives/compound/actionbtns.css.js +3 -3
- package/dist/base-primitives/element/ElementData.js +6 -1
- package/dist/base-primitives/element/ElementShape.js +9 -10
- package/dist/base-primitives/element/ElementTags.d.ts +2 -2
- package/dist/base-primitives/element/ElementTags.js +5 -5
- package/dist/components/EmptyBox.d.ts +3 -0
- package/dist/components/EmptyBox.js +9 -0
- package/dist/components/ErrorFallback.js +7 -6
- package/dist/components/FloatingWindow.d.ts +18 -0
- package/dist/components/FloatingWindow.js +89 -0
- package/dist/components/Link.js +7 -7
- package/dist/components/NavigationPanel.d.ts +2 -2
- package/dist/components/NavigationPanel.js +5 -6
- package/dist/components/SearchControl.css.js +10 -12
- package/dist/components/ViewIcon.d.ts +11 -0
- package/dist/components/ViewIcon.js +71 -0
- package/dist/context/CurrentViewModelProvider.js +2 -1
- package/dist/context/DiagramEventHandlers.js +4 -2
- package/dist/context/EnsureMantine.js +3 -3
- package/dist/context/IconRenderer.d.ts +2 -1
- package/dist/context/IconRenderer.js +78 -26
- package/dist/context/LikeC4ProjectsContext.d.ts +3 -2
- package/dist/context/TagStylesContext.d.ts +11 -4
- package/dist/context/TagStylesContext.js +39 -27
- package/dist/custom/index.d.ts +3 -0
- package/dist/custom/index.js +7 -4
- package/dist/editor/LikeC4EditorCallbacks.d.ts +20 -1
- package/dist/editor/LikeC4EditorCallbacks.js +4 -1
- package/dist/editor/actor/setup.d.ts +1 -0
- package/dist/editor/actor/setup.js +17 -12
- package/dist/editor/actor/state.sync-queue.js +1 -0
- package/dist/editor/applyChangesToManualLayout.js +5 -2
- package/dist/editor/index.d.ts +1 -1
- package/dist/editor/useEditorActorLogic.js +10 -3
- package/dist/hooks/safeContext.d.ts +12 -4
- package/dist/hooks/safeContext.js +2 -2
- package/dist/hooks/useCurrentView.js +5 -5
- package/dist/hooks/useDiagram.js +3 -23
- package/dist/hooks/useDiagramCompareLayout.d.ts +16 -6
- package/dist/hooks/useDiagramCompareLayout.js +20 -17
- package/dist/hooks/useEditorActor.js +3 -5
- package/dist/hooks/useLikeC4Model.js +8 -3
- package/dist/hooks/useLikeC4Project.d.ts +4 -3
- package/dist/hooks/useOverlaysActor.d.ts +1 -1
- package/dist/hooks/useUpdateEffect.js +2 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.js +8 -6
- package/dist/likec4diagram/DiagramUI.js +4 -3
- package/dist/likec4diagram/DiagramXYFlow.d.ts +6 -0
- package/dist/likec4diagram/DiagramXYFlow.js +33 -19
- package/dist/likec4diagram/custom/edges/EdgeDrifts.js +4 -4
- package/dist/likec4diagram/custom/edges/RelationshipEdge.js +2 -4
- package/dist/likec4diagram/custom/edges/SequenceStepEdge.js +1 -3
- package/dist/likec4diagram/custom/edges/edges.css.js +13 -13
- package/dist/likec4diagram/custom/edges/useRelationshipEdgePath.js +3 -2
- package/dist/likec4diagram/custom/nodes/NodeDrifts.js +2 -2
- package/dist/likec4diagram/custom/nodes/NodeNotes.js +4 -4
- package/dist/likec4diagram/custom/nodes/SequenceActorNode.js +2 -2
- package/dist/likec4diagram/custom/nodes/SequenceSubFlow.js +8 -5
- package/dist/likec4diagram/custom/nodes/nodes.js +8 -5
- package/dist/likec4diagram/custom/nodes/toolbar/ColorButton.js +2 -2
- package/dist/likec4diagram/custom/nodes/toolbar/Toolbar.js +9 -8
- package/dist/likec4diagram/custom/nodes/toolbar/styles.css.js +1 -1
- package/dist/likec4diagram/relationship-popover/RelationshipPopover.js +3 -2
- package/dist/likec4diagram/relationship-popover/components.d.ts +1 -1
- package/dist/likec4diagram/relationship-popover/components.js +6 -2
- package/dist/likec4diagram/state/DiagramActorProvider.d.ts +7 -2
- package/dist/likec4diagram/state/DiagramActorProvider.js +20 -4
- package/dist/likec4diagram/state/assign.js +1 -1
- package/dist/likec4diagram/state/createViewChange.js +1 -6
- package/dist/likec4diagram/state/diagram-api.d.ts +2 -2
- package/dist/likec4diagram/state/diagram-api.js +3 -2
- package/dist/likec4diagram/state/machine.actions.js +15 -8
- package/dist/likec4diagram/state/machine.actions.layout.d.ts +1 -0
- package/dist/likec4diagram/state/machine.actions.layout.js +7 -5
- package/dist/likec4diagram/state/machine.setup.d.ts +10 -1
- package/dist/likec4diagram/state/machine.setup.js +15 -9
- package/dist/likec4diagram/state/machine.state.initializing.d.ts +2 -26
- package/dist/likec4diagram/state/machine.state.initializing.js +9 -6
- package/dist/likec4diagram/state/machine.state.navigating.js +1 -1
- package/dist/likec4diagram/state/machine.state.ready.d.ts +134 -3
- package/dist/likec4diagram/state/machine.state.ready.js +2 -1
- package/dist/likec4diagram/state/machine.state.ready.walkthrough.d.ts +106 -1
- package/dist/likec4diagram/state/machine.state.ready.walkthrough.js +40 -7
- package/dist/likec4diagram/state/utils.d.ts +1 -1
- package/dist/likec4diagram/state/utils.js +7 -4
- package/dist/likec4diagram/ui/FloatingSequenceActors.js +2 -1
- package/dist/likec4diagram/ui/LayoutDriftFrame.js +16 -10
- package/dist/likec4diagram/ui/index.d.ts +1 -1
- package/dist/likec4diagram/ui/notation/NotationPanel.css.js +13 -15
- package/dist/likec4diagram/ui/notation/NotationPanel.js +9 -9
- package/dist/likec4diagram/ui/sequence-outline/ActiveTrail.d.ts +9 -0
- package/dist/likec4diagram/ui/sequence-outline/ActiveTrail.js +81 -0
- package/dist/likec4diagram/ui/sequence-outline/FlowRow.d.ts +11 -0
- package/dist/likec4diagram/ui/sequence-outline/FlowRow.js +70 -0
- package/dist/likec4diagram/ui/sequence-outline/OutlineBody.d.ts +2 -0
- package/dist/likec4diagram/ui/sequence-outline/OutlineBody.js +106 -0
- package/dist/likec4diagram/ui/sequence-outline/OutlineHeader.d.ts +2 -0
- package/dist/likec4diagram/ui/sequence-outline/OutlineHeader.js +140 -0
- package/dist/likec4diagram/ui/sequence-outline/OutlineNodes.d.ts +17 -0
- package/dist/likec4diagram/ui/sequence-outline/OutlineNodes.js +83 -0
- package/dist/likec4diagram/ui/sequence-outline/SequenceOutlinePanel.d.ts +4 -0
- package/dist/likec4diagram/ui/sequence-outline/SequenceOutlinePanel.js +49 -525
- package/dist/likec4diagram/ui/sequence-outline/StepBadge.d.ts +8 -0
- package/dist/likec4diagram/ui/sequence-outline/StepBadge.js +52 -0
- package/dist/likec4diagram/ui/sequence-outline/StepRow.d.ts +7 -0
- package/dist/likec4diagram/ui/sequence-outline/StepRow.js +190 -0
- package/dist/likec4diagram/ui/sequence-outline/StoreProvider.d.ts +238 -0
- package/dist/likec4diagram/ui/sequence-outline/StoreProvider.js +94 -0
- package/dist/likec4diagram/ui/sequence-outline/depth-of-field.d.ts +21 -0
- package/dist/likec4diagram/ui/sequence-outline/depth-of-field.js +71 -0
- package/dist/likec4diagram/ui/sequence-outline/index.d.ts +2 -0
- package/dist/likec4diagram/ui/sequence-outline/motion.d.ts +13 -0
- package/dist/likec4diagram/ui/sequence-outline/motion.js +21 -0
- package/dist/likec4diagram/ui/sequence-outline/presentation.d.ts +10 -0
- package/dist/likec4diagram/ui/sequence-outline/presentation.js +80 -0
- package/dist/likec4diagram/ui/sequence-outline/tree.d.ts +9 -0
- package/dist/likec4diagram/ui/sequence-outline/tree.js +67 -0
- package/dist/likec4diagram/ui/sequence-outline/{state.d.ts → types.d.ts} +4 -2
- package/dist/likec4diagram/ui/sequence-outline/types.js +12 -0
- package/dist/likec4diagram/useLayoutConstraints.js +13 -1
- package/dist/likec4diagram/xyflow-sequence/layouter.js +8 -10
- package/dist/likec4diagram/xyflow-sequence/sequence-view-to-xy.js +1 -0
- package/dist/likec4diagram/xyflow-sequence/utils.js +0 -1
- package/dist/navigationpanel/NavigationPanel.js +45 -41
- package/dist/navigationpanel/NavigationPanelControls.js +102 -63
- package/dist/navigationpanel/NavigationPanelDropdown.js +52 -77
- package/dist/navigationpanel/_common.d.ts +6 -6
- package/dist/navigationpanel/_common.js +31 -42
- package/dist/navigationpanel/actor.actions.js +6 -5
- package/dist/navigationpanel/actor.js +2 -2
- package/dist/navigationpanel/actor.setup.d.ts +6 -6
- package/dist/navigationpanel/actor.setup.js +2 -1
- package/dist/navigationpanel/comparepanel/CompareActionsMenu.js +2 -4
- package/dist/navigationpanel/comparepanel/ComparePanel.js +8 -10
- package/dist/navigationpanel/comparepanel/DriftsSummary.d.ts +1 -1
- package/dist/navigationpanel/comparepanel/DriftsSummary.js +11 -9
- package/dist/navigationpanel/controls/LayoutWarning.js +69 -72
- package/dist/navigationpanel/controls/NavigationButtons.d.ts +1 -1
- package/dist/navigationpanel/controls/NavigationButtons.js +8 -8
- package/dist/navigationpanel/controls/OpenSource.d.ts +1 -1
- package/dist/navigationpanel/controls/OpenSource.js +5 -8
- package/dist/navigationpanel/controls/SearchControl.js +24 -9
- package/dist/navigationpanel/controls/ToggleReadonly.d.ts +4 -1
- package/dist/navigationpanel/controls/ToggleReadonly.js +56 -76
- package/dist/navigationpanel/controls/ViewDetailsButton.d.ts +5 -0
- package/dist/navigationpanel/controls/ViewDetailsButton.js +121 -0
- package/dist/navigationpanel/controls/index.d.ts +1 -1
- package/dist/navigationpanel/dropdown/ProjectsMenu.js +27 -16
- package/dist/navigationpanel/editorpanel/ApplySemanticLayout.js +2 -1
- package/dist/navigationpanel/editorpanel/ChangeAutoLayoutButton.js +12 -10
- package/dist/navigationpanel/editorpanel/ManualLayoutToolsButton.d.ts +2 -0
- package/dist/navigationpanel/editorpanel/ManualLayoutToolsButton.js +19 -10
- package/dist/navigationpanel/editorpanel/styles.js +8 -15
- package/dist/navigationpanel/hooks.d.ts +6 -2
- package/dist/navigationpanel/styles.css.d.ts +2 -2
- package/dist/navigationpanel/styles.css.js +0 -1
- package/dist/navigationpanel/walkthrough/ActiveWalkthroughControls.js +3 -2
- package/dist/navigationpanel/walkthrough/DynamicViewControls.d.ts +5 -4
- package/dist/navigationpanel/walkthrough/DynamicViewControls.js +10 -39
- package/dist/navigationpanel/walkthrough/DynamicViewModeSwitcher.d.ts +1 -0
- package/dist/navigationpanel/walkthrough/DynamicViewModeSwitcher.js +49 -0
- package/dist/navigationpanel/walkthrough/WalkthroughPanel.js +8 -8
- package/dist/navigationpanel/windows/ViewDetailsWindow.d.ts +1 -0
- package/dist/navigationpanel/windows/ViewDetailsWindow.js +379 -0
- package/dist/overlays/Overlays.js +29 -17
- package/dist/overlays/element-details/ElementDetailsCard.css.js +28 -36
- package/dist/overlays/element-details/ElementDetailsCard.js +3 -3
- package/dist/overlays/element-details/MetadataValue.js +18 -16
- package/dist/overlays/element-details/TabPanelDeployments.css.js +6 -14
- package/dist/overlays/element-details/TabPanelRelationships.css.js +8 -12
- package/dist/overlays/element-details/TabPanelStructure.css.js +4 -8
- package/dist/overlays/hooks.d.ts +3 -1
- package/dist/overlays/overlay/Overlay.js +8 -7
- package/dist/overlays/overlaysActor.js +20 -17
- package/dist/overlays/relationship-details/RelationshipDetails.js +2 -1
- package/dist/overlays/relationship-details/SelectEdge.css.js +14 -9
- package/dist/overlays/relationship-details/actor.js +1 -1
- package/dist/overlays/relationship-details/hooks.js +2 -1
- package/dist/overlays/relationships-browser/RelationshipsBrowser.d.ts +6 -0
- package/dist/overlays/relationships-browser/RelationshipsBrowser.js +15 -8
- package/dist/overlays/relationships-browser/SelectElement.css.js +2 -8
- package/dist/overlays/relationships-browser/SelectElement.js +5 -1
- package/dist/overlays/relationships-browser/actor.js +3 -2
- package/dist/overlays/relationships-browser/custom/ElementActions.js +39 -38
- package/dist/overlays/relationships-browser/custom/EmptyNode.js +7 -9
- package/dist/overlays/relationships-browser/hooks.js +2 -1
- package/dist/projects-overview/ProjectsOverview.js +8 -7
- package/dist/projects-overview/actor.js +1 -1
- package/dist/projects-overview/hooks.js +2 -1
- package/dist/search/Search.js +9 -7
- package/dist/search/components/ElementsColumn.css.js +6 -5
- package/dist/search/components/ElementsColumn.js +4 -3
- package/dist/search/components/SearchByTags.js +3 -3
- package/dist/search/components/ViewsColum.js +46 -43
- package/dist/search/components/ViewsColumn.css.js +4 -4
- package/dist/search/components/_shared.css.d.ts +2 -2
- package/dist/search/components/_shared.css.js +31 -46
- package/dist/search/components/styles.css.js +4 -4
- package/dist/search/hooks.js +2 -1
- package/dist/shadowroot/ShadowRoot.js +6 -5
- package/dist/styles2.js +1 -1
- package/dist/utils/index.js +3 -3
- package/package.json +29 -29
- package/panda.buildinfo.json +342 -299
- package/styles-min.css +1 -1
- package/styles-xyflow.css +1 -1
- package/styles.css +1 -1
- package/dist/context/DefaultMantineProvider.d.ts +0 -2
- package/dist/context/DefaultMantineProvider.js +0 -48
- package/dist/likec4diagram/ui/sequence-outline/state.js +0 -55
- package/dist/navigationpanel/controls/DetailsControls.d.ts +0 -2
- 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,
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
113
|
-
|
|
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 {
|
|
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<
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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 {
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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 (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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,
|
|
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,
|
|
47
|
-
return /* @__PURE__ */ jsxs(
|
|
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", {
|
package/dist/custom/index.d.ts
CHANGED
|
@@ -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';
|
package/dist/custom/index.js
CHANGED
|
@@ -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
|
-
|
|
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 };
|
|
@@ -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
|
|
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
|
|
@@ -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(-
|
|
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);
|
package/dist/editor/index.d.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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
|
|
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 =
|
|
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 {
|
|
2
|
+
import { selectDiagramContext, useDiagramSelector } from "./safeContext.js";
|
|
3
3
|
//#region src/hooks/useCurrentView.ts
|
|
4
|
-
var selectViewId =
|
|
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
|
|
10
|
+
return useDiagramSelector(selectViewId);
|
|
11
11
|
}
|
|
12
|
-
var selectView =
|
|
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
|
|
18
|
+
return useDiagramSelector(selectView);
|
|
19
19
|
}
|
|
20
20
|
//#endregion
|
|
21
21
|
export { useCurrentView, useCurrentViewId };
|
package/dist/hooks/useDiagram.js
CHANGED
|
@@ -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
|
-
|
|
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 {
|
|
57
|
+
export { selectDiagramContext, selectDiagramSnapshot, useDiagram, useDiagramActorRef, useDiagramContext, useDiagramSelector, useOnDiagramEvent };
|