@likec4/diagram 1.17.1 → 1.19.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.
- package/LICENSE +1 -1
- package/dist/LikeC4CustomColors.d.ts +7 -0
- package/dist/LikeC4CustomColors.js +30 -0
- package/dist/LikeC4Diagram.css.d.ts +5 -0
- package/dist/LikeC4Diagram.css.js +13 -0
- package/dist/LikeC4Diagram.d.ts +6 -0
- package/dist/LikeC4Diagram.js +194 -0
- package/dist/LikeC4Diagram.props.d.ts +166 -0
- package/dist/LikeC4ModelProvider.d.ts +9 -0
- package/dist/LikeC4ModelProvider.js +12 -0
- package/dist/LikeC4Search.css.d.ts +1 -0
- package/dist/LikeC4Search.css.js +5 -0
- package/dist/LikeC4Search.d.ts +2 -0
- package/dist/LikeC4Search.js +96 -0
- package/dist/StaticLikeC4Diagram.d.ts +3 -0
- package/dist/StaticLikeC4Diagram.js +41 -0
- package/dist/_virtual/_commonjsHelpers.js +6 -0
- package/dist/controls/Text.d.ts +2 -0
- package/dist/controls/Text.js +7 -0
- package/dist/controls/action-button-bar/ActionButtonBar.css.d.ts +1 -0
- package/dist/controls/action-button-bar/ActionButtonBar.css.js +5 -0
- package/dist/controls/action-button-bar/ActionButtonBar.d.ts +9 -0
- package/dist/controls/action-button-bar/ActionButtonBar.js +100 -0
- package/dist/controls/action-button-bar/useActionButtonBarCtx.d.ts +10 -0
- package/dist/controls/action-button-bar/useActionButtonBarCtx.js +9 -0
- package/dist/controls/action-buttons/ActionButton.css.d.ts +1 -0
- package/dist/controls/action-buttons/ActionButton.css.js +5 -0
- package/dist/controls/action-buttons/ActionButton.d.ts +9 -0
- package/dist/controls/action-buttons/ActionButton.js +66 -0
- package/dist/controls/action-buttons/ActionButtons.d.ts +12 -0
- package/dist/controls/action-buttons/ActionButtons.js +99 -0
- package/dist/globals.css.d.ts +1 -0
- package/dist/globals.css.js +92 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/useDiagramState.d.ts +6 -0
- package/dist/hooks/useDiagramState.js +27 -0
- package/dist/hooks/useMantinePortalProps.d.ts +9 -0
- package/dist/hooks/useMantinePortalProps.js +9 -0
- package/dist/hooks/useSetState.d.ts +2 -0
- package/dist/hooks/useSetState.js +19 -0
- package/dist/hooks/useUpdateEffect.d.ts +4 -0
- package/dist/hooks/useUpdateEffect.js +32 -0
- package/dist/hooks/useXYFlow.d.ts +270 -0
- package/dist/hooks/useXYFlow.js +20 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +25 -0
- package/dist/likec4model/LikeC4ModelContext.d.ts +3 -0
- package/dist/likec4model/LikeC4ModelContext.js +5 -0
- package/dist/likec4model/index.d.ts +2 -0
- package/dist/likec4model/useLikeC4ElementsTree.d.ts +12 -0
- package/dist/likec4model/useLikeC4ElementsTree.js +25 -0
- package/dist/likec4model/useLikeC4Model.d.ts +20 -0
- package/dist/likec4model/useLikeC4Model.js +55 -0
- package/dist/overlays/OverlayContext.d.ts +10 -0
- package/dist/overlays/OverlayContext.js +9 -0
- package/dist/overlays/Overlays.css.d.ts +3 -0
- package/dist/overlays/Overlays.css.js +7 -0
- package/dist/overlays/Overlays.d.ts +2 -0
- package/dist/overlays/Overlays.js +137 -0
- package/dist/overlays/edge-details/EdgeDetailsXYFlow.d.ts +5 -0
- package/dist/overlays/edge-details/EdgeDetailsXYFlow.js +185 -0
- package/dist/overlays/edge-details/SelectEdge.css.d.ts +7 -0
- package/dist/overlays/edge-details/SelectEdge.css.js +17 -0
- package/dist/overlays/edge-details/SelectEdge.d.ts +5 -0
- package/dist/overlays/edge-details/SelectEdge.js +129 -0
- package/dist/overlays/edge-details/_types.d.ts +14 -0
- package/dist/overlays/edge-details/use-layouted-edge-details.d.ts +21 -0
- package/dist/overlays/edge-details/use-layouted-edge-details.js +270 -0
- package/dist/overlays/edge-details/xyflow/CompoundNode.d.ts +5 -0
- package/dist/overlays/edge-details/xyflow/CompoundNode.js +76 -0
- package/dist/overlays/edge-details/xyflow/ElementNode.d.ts +5 -0
- package/dist/overlays/edge-details/xyflow/ElementNode.js +159 -0
- package/dist/overlays/edge-details/xyflow/RelationshipEdge.d.ts +3 -0
- package/dist/overlays/edge-details/xyflow/RelationshipEdge.js +84 -0
- package/dist/overlays/edge-details/xyflow/styles.css.d.ts +9 -0
- package/dist/overlays/edge-details/xyflow/styles.css.js +21 -0
- package/dist/overlays/element-details/ElementDetailsCard.css.d.ts +16 -0
- package/dist/overlays/element-details/ElementDetailsCard.css.js +33 -0
- package/dist/overlays/element-details/ElementDetailsCard.d.ts +7 -0
- package/dist/overlays/element-details/ElementDetailsCard.js +484 -0
- package/dist/overlays/element-details/TabPanelDeployments.css.d.ts +4 -0
- package/dist/overlays/element-details/TabPanelDeployments.css.js +11 -0
- package/dist/overlays/element-details/TabPanelDeployments.d.ts +7 -0
- package/dist/overlays/element-details/TabPanelDeployments.js +173 -0
- package/dist/overlays/element-details/TabPanelRelationships.css.d.ts +5 -0
- package/dist/overlays/element-details/TabPanelRelationships.css.js +11 -0
- package/dist/overlays/element-details/TabPanelRelationships.d.ts +8 -0
- package/dist/overlays/element-details/TabPanelRelationships.js +157 -0
- package/dist/overlays/element-details/TabPanelStructure.css.d.ts +2 -0
- package/dist/overlays/element-details/TabPanelStructure.css.js +7 -0
- package/dist/overlays/element-details/TabPanelStructure.d.ts +25 -0
- package/dist/overlays/element-details/TabPanelStructure.js +91 -0
- package/dist/overlays/index.d.ts +1 -0
- package/dist/overlays/relationships-of/RelationshipsOverlay.d.ts +5 -0
- package/dist/overlays/relationships-of/RelationshipsOverlay.js +193 -0
- package/dist/overlays/relationships-of/RelationshipsXYFlow.d.ts +19 -0
- package/dist/overlays/relationships-of/RelationshipsXYFlow.js +290 -0
- package/dist/overlays/relationships-of/SelectElement.css.d.ts +2 -0
- package/dist/overlays/relationships-of/SelectElement.css.js +7 -0
- package/dist/overlays/relationships-of/SelectElement.d.ts +7 -0
- package/dist/overlays/relationships-of/SelectElement.js +126 -0
- package/dist/overlays/relationships-of/_types.d.ts +28 -0
- package/dist/overlays/relationships-of/use-layouted-relationships.d.ts +22 -0
- package/dist/overlays/relationships-of/use-layouted-relationships.js +496 -0
- package/dist/overlays/relationships-of/xyflow/CompoundNode.d.ts +6 -0
- package/dist/overlays/relationships-of/xyflow/CompoundNode.js +120 -0
- package/dist/overlays/relationships-of/xyflow/ElementNode.d.ts +6 -0
- package/dist/overlays/relationships-of/xyflow/ElementNode.js +194 -0
- package/dist/overlays/relationships-of/xyflow/EmptyNode.d.ts +5 -0
- package/dist/overlays/relationships-of/xyflow/EmptyNode.js +18 -0
- package/dist/overlays/relationships-of/xyflow/RelationshipEdge.d.ts +3 -0
- package/dist/overlays/relationships-of/xyflow/RelationshipEdge.js +123 -0
- package/dist/overlays/relationships-of/xyflow/styles.css.d.ts +14 -0
- package/dist/overlays/relationships-of/xyflow/styles.css.js +24 -0
- package/dist/overlays/shared/xyflow/RelationshipEdge.css.d.ts +4 -0
- package/dist/overlays/shared/xyflow/RelationshipEdge.css.js +12 -0
- package/dist/overlays/shared/xyflow/_types.d.ts +77 -0
- package/dist/state/DiagramContext.d.ts +1609 -0
- package/dist/state/DiagramContext.js +101 -0
- package/dist/state/aligners.d.ts +42 -0
- package/dist/state/aligners.js +349 -0
- package/dist/state/diagram-to-xyflow.d.ts +11 -0
- package/dist/state/diagram-to-xyflow.js +113 -0
- package/dist/state/diagramStore.d.ts +1705 -0
- package/dist/state/diagramStore.js +808 -0
- package/dist/state/diagramStore.layout.d.ts +4 -0
- package/dist/state/diagramStore.layout.js +56 -0
- package/dist/style.css +1 -0
- package/dist/theme-vars.css.d.ts +72 -0
- package/dist/theme-vars.css.js +6 -0
- package/dist/theme-vars.css.ts.vanilla.css.js +1 -0
- package/dist/theme-vars.d.ts +3 -0
- package/dist/theme-vars.js +5 -0
- package/dist/ui/DiagramTitlePanel.css.d.ts +4 -0
- package/dist/ui/DiagramTitlePanel.css.js +11 -0
- package/dist/ui/DiagramTitlePanel.d.ts +1 -0
- package/dist/ui/DiagramTitlePanel.js +159 -0
- package/dist/ui/DynamicViewWalkthrough.css.d.ts +4 -0
- package/dist/ui/DynamicViewWalkthrough.css.js +11 -0
- package/dist/ui/DynamicViewWalkthrough.d.ts +1 -0
- package/dist/ui/DynamicViewWalkthrough.js +156 -0
- package/dist/ui/EnsureMantine.d.ts +7 -0
- package/dist/ui/EnsureMantine.js +14 -0
- package/dist/ui/FramerMotionConfig.d.ts +2 -0
- package/dist/ui/FramerMotionConfig.js +14 -0
- package/dist/ui/Link.d.ts +4 -0
- package/dist/ui/Link.js +36 -0
- package/dist/ui/notation/NotationPanel.css.d.ts +6 -0
- package/dist/ui/notation/NotationPanel.css.js +16 -0
- package/dist/ui/notation/NotationPanel.d.ts +1 -0
- package/dist/ui/notation/NotationPanel.js +250 -0
- package/dist/ui/notation/index.d.ts +1 -0
- package/dist/ui/top-left/ChangeAutoLayoutButton.d.ts +2 -0
- package/dist/ui/top-left/ChangeAutoLayoutButton.js +159 -0
- package/dist/ui/top-left/ManualLayoutToolsButton.d.ts +2 -0
- package/dist/ui/top-left/ManualLayoutToolsButton.js +137 -0
- package/dist/ui/top-left/TopLeftPanel.d.ts +4 -0
- package/dist/ui/top-left/TopLeftPanel.js +211 -0
- package/dist/ui/top-left/_shared.d.ts +7 -0
- package/dist/ui/top-left/_shared.js +22 -0
- package/dist/ui/top-left/styles.css.d.ts +8 -0
- package/dist/ui/top-left/styles.css.js +17 -0
- package/dist/utils/types.d.ts +8 -0
- package/dist/utils/vector.d.ts +24 -0
- package/dist/utils/vector.js +55 -0
- package/dist/xyflow/EdgeMarkers.d.ts +12 -0
- package/dist/xyflow/EdgeMarkers.js +192 -0
- package/dist/xyflow/FitviewOnDiagramChange.d.ts +4 -0
- package/dist/xyflow/FitviewOnDiagramChange.js +72 -0
- package/dist/xyflow/SelectEdgesOnNodeFocus.d.ts +1 -0
- package/dist/xyflow/SelectEdgesOnNodeFocus.js +96 -0
- package/dist/xyflow/XYFlow.d.ts +8 -0
- package/dist/xyflow/XYFlow.js +145 -0
- package/dist/xyflow/XYFlowBackground.d.ts +10 -0
- package/dist/xyflow/XYFlowBackground.js +25 -0
- package/dist/xyflow/XYFlowInner.d.ts +8 -0
- package/dist/xyflow/XYFlowInner.js +41 -0
- package/dist/xyflow/const.d.ts +7 -0
- package/dist/xyflow/const.js +12 -0
- package/dist/xyflow/edges/EdgeLabel.d.ts +7 -0
- package/dist/xyflow/edges/EdgeLabel.js +160 -0
- package/dist/xyflow/edges/RelationshipEdge.d.ts +6 -0
- package/dist/xyflow/edges/RelationshipEdge.js +443 -0
- package/dist/xyflow/edges/RelationshipsDropdownMenu.css.d.ts +4 -0
- package/dist/xyflow/edges/RelationshipsDropdownMenu.css.js +11 -0
- package/dist/xyflow/edges/RelationshipsDropdownMenu.d.ts +13 -0
- package/dist/xyflow/edges/RelationshipsDropdownMenu.js +211 -0
- package/dist/xyflow/edges/edges.css.d.ts +17 -0
- package/dist/xyflow/edges/edges.css.js +37 -0
- package/dist/xyflow/edges/utils.d.ts +16 -0
- package/dist/xyflow/edges/utils.js +24 -0
- package/dist/xyflow/nodes/AnimateVariants.d.ts +1313 -0
- package/dist/xyflow/nodes/AnimateVariants.js +123 -0
- package/dist/xyflow/nodes/Node.css.d.ts +3 -0
- package/dist/xyflow/nodes/Node.css.js +9 -0
- package/dist/xyflow/nodes/compound/CompoundNode.css.d.ts +14 -0
- package/dist/xyflow/nodes/compound/CompoundNode.css.js +27 -0
- package/dist/xyflow/nodes/compound/CompoundNode.d.ts +6 -0
- package/dist/xyflow/nodes/compound/CompoundNode.js +216 -0
- package/dist/xyflow/nodes/compound/index.d.ts +1 -0
- package/dist/xyflow/nodes/element/ElementLink.css.d.ts +3 -0
- package/dist/xyflow/nodes/element/ElementLink.d.ts +6 -0
- package/dist/xyflow/nodes/element/ElementNode.d.ts +6 -0
- package/dist/xyflow/nodes/element/ElementNode.js +190 -0
- package/dist/xyflow/nodes/element/ElementShapeSvg.d.ts +17 -0
- package/dist/xyflow/nodes/element/ElementShapeSvg.js +175 -0
- package/dist/xyflow/nodes/element/element.css.d.ts +18 -0
- package/dist/xyflow/nodes/element/element.css.js +31 -0
- package/dist/xyflow/nodes/element/index.d.ts +1 -0
- package/dist/xyflow/nodes/shared/ElementIcon.d.ts +8 -0
- package/dist/xyflow/nodes/shared/ElementIcon.js +38 -0
- package/dist/xyflow/nodes/shared/Toolbar.d.ts +9 -0
- package/dist/xyflow/nodes/shared/Toolbar.js +436 -0
- package/dist/xyflow/types.d.ts +36 -0
- package/dist/xyflow/useLayoutConstraints.d.ts +42 -0
- package/dist/xyflow/useLayoutConstraints.js +226 -0
- package/dist/xyflow/useXYFlowEvents.d.ts +160 -0
- package/dist/xyflow/useXYFlowEvents.js +275 -0
- package/dist/xyflow/utils.d.ts +22 -0
- package/dist/xyflow/utils.js +72 -0
- package/package.json +40 -31
- package/src/LikeC4Diagram.props.ts +21 -12
- package/src/LikeC4Diagram.tsx +8 -10
- package/src/LikeC4Search.css.ts +12 -0
- package/src/LikeC4Search.tsx +45 -93
- package/src/controls/Text.ts +5 -0
- package/src/controls/action-button-bar/ActionButtonBar.css.ts +13 -0
- package/src/controls/action-button-bar/ActionButtonBar.tsx +138 -0
- package/src/controls/action-button-bar/useActionButtonBarCtx.ts +13 -0
- package/src/controls/action-buttons/ActionButton.css.ts +29 -0
- package/src/controls/action-buttons/ActionButton.tsx +66 -0
- package/src/controls/action-buttons/ActionButtons.tsx +138 -0
- package/src/hooks/useDiagramState.ts +8 -3
- package/src/hooks/useXYFlow.ts +9 -8
- package/src/index.ts +12 -6
- package/src/likec4model/index.ts +12 -2
- package/src/likec4model/useLikeC4ElementsTree.ts +6 -13
- package/src/likec4model/useLikeC4Model.ts +21 -11
- package/src/overlays/Overlays.tsx +96 -63
- package/src/overlays/edge-details/EdgeDetailsXYFlow.tsx +18 -10
- package/src/overlays/edge-details/_types.ts +13 -33
- package/src/overlays/edge-details/use-layouted-edge-details.ts +35 -26
- package/src/overlays/edge-details/xyflow/CompoundNode.tsx +3 -11
- package/src/overlays/edge-details/xyflow/ElementNode.tsx +8 -13
- package/src/overlays/edge-details/xyflow/RelationshipEdge.tsx +7 -7
- package/src/overlays/edge-details/xyflow/styles.css.ts +1 -59
- package/src/overlays/element-details/ElementDetailsCard.tsx +91 -78
- package/src/overlays/element-details/TabPanelDeployments.css.ts +69 -0
- package/src/overlays/element-details/TabPanelDeployments.tsx +217 -0
- package/src/overlays/element-details/TabPanelRelationships.tsx +8 -9
- package/src/overlays/element-details/TabPanelStructure.tsx +10 -10
- package/src/overlays/relationships-of/RelationshipsOverlay.tsx +1 -1
- package/src/overlays/relationships-of/RelationshipsXYFlow.tsx +26 -34
- package/src/overlays/relationships-of/SelectElement.tsx +2 -2
- package/src/overlays/relationships-of/_types.ts +20 -58
- package/src/overlays/relationships-of/use-layouted-relationships.ts +54 -59
- package/src/overlays/relationships-of/xyflow/CompoundNode.tsx +10 -16
- package/src/overlays/relationships-of/xyflow/ElementNode.tsx +24 -21
- package/src/overlays/relationships-of/xyflow/EmptyNode.tsx +4 -7
- package/src/overlays/relationships-of/xyflow/RelationshipEdge.tsx +16 -15
- package/src/overlays/shared/xyflow/RelationshipEdge.css.ts +60 -0
- package/src/overlays/shared/xyflow/_types.ts +87 -0
- package/src/state/diagram-to-xyflow.ts +6 -7
- package/src/state/diagramStore.layout.ts +3 -4
- package/src/state/diagramStore.ts +63 -48
- package/src/theme-vars.css.ts +81 -0
- package/src/theme-vars.ts +8 -81
- package/src/ui/DiagramTitlePanel.tsx +7 -34
- package/src/ui/Link.tsx +40 -0
- package/src/ui/notation/NotationPanel.tsx +4 -2
- package/src/ui/top-left/ChangeAutoLayoutButton.tsx +2 -2
- package/src/ui/top-left/TopLeftPanel.tsx +5 -5
- package/src/utils/types.ts +6 -0
- package/src/xyflow/SelectEdgesOnNodeFocus.tsx +3 -3
- package/src/xyflow/XYFlow.tsx +2 -2
- package/src/xyflow/edges/EdgeLabel.tsx +26 -19
- package/src/xyflow/edges/RelationshipEdge.tsx +5 -3
- package/src/xyflow/edges/RelationshipsDropdownMenu.tsx +23 -10
- package/src/xyflow/edges/edges.css.ts +68 -74
- package/src/xyflow/edges/utils.ts +6 -6
- package/src/xyflow/nodes/AnimateVariants.ts +143 -0
- package/src/xyflow/nodes/Node.css.ts +44 -0
- package/src/xyflow/nodes/compound/CompoundNode.css.ts +27 -75
- package/src/xyflow/nodes/compound/CompoundNode.tsx +82 -163
- package/src/xyflow/nodes/element/ElementLink.tsx +2 -3
- package/src/xyflow/nodes/element/ElementNode.tsx +73 -252
- package/src/xyflow/nodes/element/element.css.ts +40 -64
- package/src/xyflow/nodes/shared/ElementIcon.tsx +1 -1
- package/src/xyflow/nodes/shared/Toolbar.tsx +51 -35
- package/src/xyflow/types.ts +48 -51
- package/src/xyflow/useLayoutConstraints.ts +10 -10
- package/src/xyflow/useXYFlowEvents.ts +31 -35
- package/src/xyflow/utils.ts +2 -2
- package/src/ui/OptionsPanel.css.ts +0 -9
- package/src/ui/OptionsPanel.tsx +0 -70
- package/src/ui/options/EdgeOptions.tsx +0 -142
- package/src/ui/options/NodeOptions.tsx +0 -362
- package/src/xyflow/nodes/element/ElementDetails.css.ts +0 -101
- package/src/xyflow/nodes/element/ElementDetails.tsx +0 -393
- package/src/xyflow/nodes/use-animate-variants.tsx +0 -64
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { invariant, hasAtLeast } from "@likec4/core";
|
|
2
|
+
import { getNodeDimensions } from "@xyflow/system";
|
|
3
|
+
import { Bezier } from "../node_modules/bezier-js/src/bezier.js";
|
|
4
|
+
import { isArray } from "remeda";
|
|
5
|
+
function toDomPrecision(v) {
|
|
6
|
+
if (v === null) {
|
|
7
|
+
return 0.01;
|
|
8
|
+
}
|
|
9
|
+
return Math.round(v * 100) / 100;
|
|
10
|
+
}
|
|
11
|
+
const nodeToRect = (nd) => ({
|
|
12
|
+
x: nd.internals.positionAbsolute.x,
|
|
13
|
+
y: nd.internals.positionAbsolute.y,
|
|
14
|
+
width: nd.measured.width ?? nd.width ?? nd.data.element.width,
|
|
15
|
+
height: nd.measured.height ?? nd.height ?? nd.data.element.height
|
|
16
|
+
});
|
|
17
|
+
const isInside = (test, target) => {
|
|
18
|
+
return test.x >= target.x && test.y >= target.y && test.x + test.width <= target.x + target.width && test.y + test.height <= target.y + target.height;
|
|
19
|
+
};
|
|
20
|
+
function bezierControlPoints(diagramEdge) {
|
|
21
|
+
let [start, ...bezierPoints] = diagramEdge.points;
|
|
22
|
+
invariant(start, "start should be defined");
|
|
23
|
+
const handles = [
|
|
24
|
+
// start
|
|
25
|
+
];
|
|
26
|
+
while (hasAtLeast(bezierPoints, 3)) {
|
|
27
|
+
const [cp1, cp2, end, ...rest] = bezierPoints;
|
|
28
|
+
const bezier = new Bezier(start[0], start[1], cp1[0], cp1[1], cp2[0], cp2[1], end[0], end[1]);
|
|
29
|
+
const inflections = bezier.inflections();
|
|
30
|
+
if (inflections.length === 0) {
|
|
31
|
+
inflections.push(0.5);
|
|
32
|
+
}
|
|
33
|
+
inflections.forEach((t) => {
|
|
34
|
+
const { x, y } = bezier.get(t);
|
|
35
|
+
handles.push({
|
|
36
|
+
x: Math.round(x),
|
|
37
|
+
y: Math.round(y)
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
bezierPoints = rest;
|
|
41
|
+
start = end;
|
|
42
|
+
}
|
|
43
|
+
invariant(bezierPoints.length === 0, "all points should be consumed");
|
|
44
|
+
return handles;
|
|
45
|
+
}
|
|
46
|
+
const isClose = (a, b) => {
|
|
47
|
+
return Math.abs(a - b) < 3.1;
|
|
48
|
+
};
|
|
49
|
+
function isSamePoint(a, b) {
|
|
50
|
+
const [ax, ay] = isArray(a) ? a : [a.x, a.y];
|
|
51
|
+
const [bx, by] = isArray(b) ? b : [b.x, b.y];
|
|
52
|
+
return isClose(ax, bx) && isClose(ay, by);
|
|
53
|
+
}
|
|
54
|
+
function stopPropagation(e) {
|
|
55
|
+
return e.stopPropagation();
|
|
56
|
+
}
|
|
57
|
+
function centerXYInternalNode(nd) {
|
|
58
|
+
const { width, height } = getNodeDimensions(nd);
|
|
59
|
+
return {
|
|
60
|
+
x: nd.internals.positionAbsolute.x + width / 2,
|
|
61
|
+
y: nd.internals.positionAbsolute.y + height / 2
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export {
|
|
65
|
+
bezierControlPoints,
|
|
66
|
+
centerXYInternalNode,
|
|
67
|
+
isInside,
|
|
68
|
+
isSamePoint,
|
|
69
|
+
nodeToRect,
|
|
70
|
+
stopPropagation,
|
|
71
|
+
toDomPrecision
|
|
72
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@likec4/diagram",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"bugs": "https://github.com/likec4/likec4/issues",
|
|
6
6
|
"homepage": "https://likec4.dev",
|
|
@@ -11,9 +11,7 @@
|
|
|
11
11
|
"directory": "packages/diagram"
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
|
-
"
|
|
15
|
-
"LICENSE",
|
|
16
|
-
"README.md",
|
|
14
|
+
"dist",
|
|
17
15
|
"src",
|
|
18
16
|
"!**/*.spec.*",
|
|
19
17
|
"!**/*.d.ts.map"
|
|
@@ -21,57 +19,68 @@
|
|
|
21
19
|
"sideEffects": false,
|
|
22
20
|
"type": "module",
|
|
23
21
|
"exports": {
|
|
24
|
-
".":
|
|
22
|
+
".": {
|
|
23
|
+
"development": "./src/index.ts",
|
|
24
|
+
"default": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.js",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"./style.css": "./dist/style.css"
|
|
25
31
|
},
|
|
26
32
|
"packageManager": "yarn@4.5.3",
|
|
27
33
|
"scripts": {
|
|
28
34
|
"typecheck": "tsc --noEmit",
|
|
35
|
+
"build": "vite build",
|
|
29
36
|
"lint": "run -T eslint src/ --fix",
|
|
30
37
|
"clean": "rm -r -f -g 'dist/*' .tsbuildinfo",
|
|
31
38
|
"test": "vitest run --no-isolate"
|
|
32
39
|
},
|
|
33
40
|
"dependencies": {
|
|
34
|
-
"@dagrejs/dagre": "
|
|
35
|
-
"@likec4/core": "1.
|
|
36
|
-
"@mantine/vanilla-extract": "7.
|
|
41
|
+
"@dagrejs/dagre": "1.1.4",
|
|
42
|
+
"@likec4/core": "1.19.0",
|
|
43
|
+
"@mantine/vanilla-extract": "7.15.2",
|
|
37
44
|
"@react-hookz/web": "^24.0.4",
|
|
38
45
|
"@tabler/icons-react": "3.17.0",
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
41
|
-
"@vanilla-extract/dynamic": "^2.1.2",
|
|
42
|
-
"@xyflow/react": "12.3.5",
|
|
43
|
-
"@xyflow/system": "0.0.46",
|
|
44
|
-
"bezier-js": "^6.1.4",
|
|
46
|
+
"@xyflow/react": "12.3.6",
|
|
47
|
+
"@xyflow/system": "0.0.47",
|
|
45
48
|
"clsx": "^2.1.1",
|
|
46
49
|
"d3-shape": "^3.2.0",
|
|
47
|
-
"esm-env": "^1.1
|
|
50
|
+
"esm-env": "^1.2.1",
|
|
48
51
|
"fast-equals": "^5.0.1",
|
|
49
|
-
"framer-motion": "^11.
|
|
52
|
+
"framer-motion": "^11.14.1",
|
|
50
53
|
"khroma": "^2.1.0",
|
|
51
|
-
"
|
|
52
|
-
"
|
|
54
|
+
"react-error-boundary": "^4.1.2",
|
|
55
|
+
"remeda": "^2.17.4",
|
|
56
|
+
"type-fest": "4.28.1",
|
|
53
57
|
"zustand": "^4.5.5"
|
|
54
58
|
},
|
|
55
59
|
"peerDependencies": {
|
|
56
|
-
"@mantine/core": "^7.
|
|
57
|
-
"@mantine/hooks": "^7.
|
|
58
|
-
"@mantine/spotlight": "^7.
|
|
60
|
+
"@mantine/core": "^7.15.2",
|
|
61
|
+
"@mantine/hooks": "^7.15.2",
|
|
62
|
+
"@mantine/spotlight": "^7.15.2",
|
|
59
63
|
"react": "^18.3.1",
|
|
60
64
|
"react-dom": "^18.3.1"
|
|
61
65
|
},
|
|
62
66
|
"devDependencies": {
|
|
63
|
-
"@likec4/tsconfig": "1.
|
|
64
|
-
"@mantine/core": "7.
|
|
65
|
-
"@mantine/hooks": "7.
|
|
66
|
-
"@mantine/spotlight": "7.
|
|
67
|
+
"@likec4/tsconfig": "1.19.0",
|
|
68
|
+
"@mantine/core": "7.15.2",
|
|
69
|
+
"@mantine/hooks": "7.15.2",
|
|
70
|
+
"@mantine/spotlight": "7.15.2",
|
|
67
71
|
"@types/bezier-js": "^4.1.3",
|
|
68
72
|
"@types/d3-shape": "^3.1.6",
|
|
69
|
-
"@types/react": "
|
|
70
|
-
"@types/react-dom": "
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
73
|
+
"@types/react": "18.3.11",
|
|
74
|
+
"@types/react-dom": "18.3.1",
|
|
75
|
+
"@vanilla-extract/css": "^1.16.1",
|
|
76
|
+
"@vanilla-extract/css-utils": "^0.1.4",
|
|
77
|
+
"@vanilla-extract/dynamic": "^2.1.2",
|
|
78
|
+
"bezier-js": "^6.1.4",
|
|
79
|
+
"react": "18.3.1",
|
|
80
|
+
"react-dom": "18.3.1",
|
|
74
81
|
"typescript": "^5.7.2",
|
|
75
|
-
"
|
|
82
|
+
"vite": "5.4.11",
|
|
83
|
+
"vite-plugin-dts": "^4.4.0",
|
|
84
|
+
"vitest": "^2.1.8"
|
|
76
85
|
}
|
|
77
86
|
}
|
|
@@ -3,9 +3,9 @@ import type {
|
|
|
3
3
|
DiagramNode,
|
|
4
4
|
DiagramView,
|
|
5
5
|
Fqn,
|
|
6
|
-
|
|
6
|
+
RelationId,
|
|
7
7
|
ViewChange,
|
|
8
|
-
|
|
8
|
+
ViewId,
|
|
9
9
|
WhereOperator
|
|
10
10
|
} from '@likec4/core'
|
|
11
11
|
import type { MouseEvent as ReactMouseEvent, ReactNode } from 'react'
|
|
@@ -13,7 +13,7 @@ import type { XYBackground } from './xyflow/XYFlowBackground'
|
|
|
13
13
|
|
|
14
14
|
export type { WhereOperator }
|
|
15
15
|
|
|
16
|
-
export type DiagramNodeWithNavigate<ID extends string =
|
|
16
|
+
export type DiagramNodeWithNavigate<ID extends string = ViewId> = Omit<DiagramNode, 'navigateTo'> & {
|
|
17
17
|
navigateTo: ID
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -27,7 +27,7 @@ export type ElementIconRenderer = (props: {
|
|
|
27
27
|
node: ElementIconNodeProps
|
|
28
28
|
}) => ReactNode
|
|
29
29
|
|
|
30
|
-
export type OnNavigateTo<ID extends string =
|
|
30
|
+
export type OnNavigateTo<ID extends string = ViewId> = (
|
|
31
31
|
to: ID,
|
|
32
32
|
// These fields present if navigateTo triggered by a node click
|
|
33
33
|
event?: ReactMouseEvent,
|
|
@@ -191,6 +191,22 @@ export interface LikeC4DiagramProperties {
|
|
|
191
191
|
where?: WhereOperator<string, string> | undefined
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
+
export type OpenSourceParams =
|
|
195
|
+
| {
|
|
196
|
+
element: Fqn
|
|
197
|
+
property?: string
|
|
198
|
+
}
|
|
199
|
+
| {
|
|
200
|
+
relation: RelationId
|
|
201
|
+
}
|
|
202
|
+
| {
|
|
203
|
+
deployment: Fqn
|
|
204
|
+
property?: string
|
|
205
|
+
}
|
|
206
|
+
| {
|
|
207
|
+
view: ViewId
|
|
208
|
+
}
|
|
209
|
+
|
|
194
210
|
export interface LikeC4DiagramEventHandlers {
|
|
195
211
|
onChange?: OnChange | null | undefined
|
|
196
212
|
onNavigateTo?: OnNavigateTo | null | undefined
|
|
@@ -205,12 +221,5 @@ export interface LikeC4DiagramEventHandlers {
|
|
|
205
221
|
// if set, will render a burger menu icon in the top left corner
|
|
206
222
|
onBurgerMenuClick?: null | undefined | (() => void)
|
|
207
223
|
|
|
208
|
-
|
|
209
|
-
onOpenSourceView?: null | undefined | (() => void)
|
|
210
|
-
|
|
211
|
-
// if set, will render an icon in properties webview for each element
|
|
212
|
-
onOpenSourceElement?: null | undefined | ((fqn: Fqn) => void)
|
|
213
|
-
|
|
214
|
-
// if set, will be called on edge click
|
|
215
|
-
onOpenSourceRelation?: null | undefined | ((id: RelationID) => void)
|
|
224
|
+
onOpenSource?: null | undefined | ((params: OpenSourceParams) => void)
|
|
216
225
|
}
|
package/src/LikeC4Diagram.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isDeploymentView } from '@likec4/core'
|
|
1
2
|
import { ReactFlowProvider as XYFlowProvider } from '@xyflow/react'
|
|
2
3
|
import clsx from 'clsx'
|
|
3
4
|
import { deepEqual } from 'fast-equals'
|
|
@@ -16,7 +17,7 @@ import { EnsureMantine } from './ui/EnsureMantine'
|
|
|
16
17
|
import { FramerMotionConfig } from './ui/FramerMotionConfig'
|
|
17
18
|
import { FitViewOnDiagramChange } from './xyflow/FitviewOnDiagramChange'
|
|
18
19
|
import { SelectEdgesOnNodeFocus } from './xyflow/SelectEdgesOnNodeFocus'
|
|
19
|
-
import type {
|
|
20
|
+
import type { DiagramFlowTypes } from './xyflow/types'
|
|
20
21
|
import { XYFlow } from './xyflow/XYFlow'
|
|
21
22
|
import { XYFlowInner } from './xyflow/XYFlowInner'
|
|
22
23
|
|
|
@@ -54,9 +55,7 @@ export function LikeC4Diagram({
|
|
|
54
55
|
onNavigateTo,
|
|
55
56
|
onNodeClick,
|
|
56
57
|
onNodeContextMenu,
|
|
57
|
-
|
|
58
|
-
onOpenSourceView,
|
|
59
|
-
onOpenSourceRelation,
|
|
58
|
+
onOpenSource,
|
|
60
59
|
onBurgerMenuClick,
|
|
61
60
|
renderIcon,
|
|
62
61
|
where,
|
|
@@ -64,8 +63,8 @@ export function LikeC4Diagram({
|
|
|
64
63
|
}: LikeC4DiagramProps) {
|
|
65
64
|
const hasLikec4model = !!useLikeC4Model()
|
|
66
65
|
const initialRef = useRef({
|
|
67
|
-
defaultNodes: [] as
|
|
68
|
-
defaultEdges: [] as
|
|
66
|
+
defaultNodes: [] as DiagramFlowTypes.Node[],
|
|
67
|
+
defaultEdges: [] as DiagramFlowTypes.Edge[],
|
|
69
68
|
initialWidth: initialWidth ?? view.bounds.width,
|
|
70
69
|
initialHeight: initialHeight ?? view.bounds.height
|
|
71
70
|
})
|
|
@@ -112,11 +111,12 @@ export function LikeC4Diagram({
|
|
|
112
111
|
showNavigationButtons={showNavigationButtons && !!onNavigateTo}
|
|
113
112
|
showNotations={showNotations}
|
|
114
113
|
enableFocusMode={enableFocusMode}
|
|
115
|
-
enableRelationshipDetails={enableRelationshipDetails && hasLikec4model}
|
|
116
114
|
enableSearch={hasLikec4model && enableSearch}
|
|
117
115
|
enableElementDetails={enableElementDetails && hasLikec4model}
|
|
118
116
|
enableDynamicViewWalkthrough={enableDynamicViewWalkthrough}
|
|
119
117
|
enableRelationshipBrowser={enableRelationshipBrowser && hasLikec4model}
|
|
118
|
+
// TODO: temporary disable relationship details for deployment views
|
|
119
|
+
enableRelationshipDetails={enableRelationshipDetails && hasLikec4model && !isDeploymentView(view)}
|
|
120
120
|
// Apply where filter only in readonly mode
|
|
121
121
|
whereFilter={readonly ? (where ?? null) : null}
|
|
122
122
|
renderIcon={renderIcon ?? null}
|
|
@@ -129,9 +129,7 @@ export function LikeC4Diagram({
|
|
|
129
129
|
onChange={onChange ?? null}
|
|
130
130
|
onNavigateTo={onNavigateTo ?? null}
|
|
131
131
|
onCanvasDblClick={onCanvasDblClick ?? null}
|
|
132
|
-
|
|
133
|
-
onOpenSourceElement={onOpenSourceElement ?? null}
|
|
134
|
-
onOpenSourceRelation={onOpenSourceRelation ?? null}
|
|
132
|
+
onOpenSource={onOpenSource ?? null}
|
|
135
133
|
onBurgerMenuClick={onBurgerMenuClick ?? null}
|
|
136
134
|
>
|
|
137
135
|
<LikeC4DiagramInnerMemo
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { rem } from '@mantine/core'
|
|
2
|
+
import { globalStyle, style } from '@vanilla-extract/css'
|
|
3
|
+
|
|
4
|
+
export const actionSection = style({
|
|
5
|
+
marginInlineEnd: 4
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
globalStyle(`:where(${actionSection}) .tabler-icon`, {
|
|
9
|
+
opacity: 0.8,
|
|
10
|
+
width: '70%',
|
|
11
|
+
height: '70%'
|
|
12
|
+
})
|
package/src/LikeC4Search.tsx
CHANGED
|
@@ -1,72 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Spotlight,
|
|
3
|
-
import { IconRectangularPrism, IconSitemap,
|
|
4
|
-
import { memo, useMemo
|
|
1
|
+
import { rem } from '@mantine/core'
|
|
2
|
+
import { Spotlight, type SpotlightActionData } from '@mantine/spotlight'
|
|
3
|
+
import { IconRectangularPrism, IconSearch, IconSitemap, IconStack2 } from '@tabler/icons-react'
|
|
4
|
+
import { memo, useMemo } from 'react'
|
|
5
5
|
import { filter, map, pipe } from 'remeda'
|
|
6
6
|
import { useDiagramState, useDiagramStoreApi, useMantinePortalProps } from './hooks'
|
|
7
7
|
import { useLikeC4Model } from './likec4model'
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
interface QueryMatch {
|
|
11
|
-
data: SpotlightActionData,
|
|
12
|
-
keyword: string,
|
|
13
|
-
match: string
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function filterAction(actionData: SpotlightActionData, query: string) : QueryMatch | undefined {
|
|
17
|
-
const queryLower = query.toLowerCase();
|
|
18
|
-
const keywords = Array.isArray(actionData.keywords) ? actionData.keywords : [];
|
|
19
|
-
const keywordMatch = keywords
|
|
20
|
-
.map(keyword => {
|
|
21
|
-
const index = keyword.toLowerCase().indexOf(queryLower);
|
|
22
|
-
return index !== -1 ? {
|
|
23
|
-
keyword: keyword,
|
|
24
|
-
match: keyword.substring(index, index + query.length)
|
|
25
|
-
} : null;
|
|
26
|
-
})
|
|
27
|
-
.find(match => !!match);
|
|
28
|
-
return !!keywordMatch ? {
|
|
29
|
-
data: actionData,
|
|
30
|
-
keyword: keywordMatch.keyword,
|
|
31
|
-
match: keywordMatch.match
|
|
32
|
-
} : undefined;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function buildFilteredActions(actionsData: SpotlightActionData[], query: string): JSX.Element[] {
|
|
36
|
-
return pipe(
|
|
37
|
-
actionsData,
|
|
38
|
-
map(a => filterAction(a, query)),
|
|
39
|
-
filter(qm => !!qm),
|
|
40
|
-
map(qm => buildSpotlightAction(qm))
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function highlightMatch(match: QueryMatch): JSX.Element {
|
|
45
|
-
return <Highlight highlight={match.match}>{match.keyword}</Highlight>
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function buildSpotlightAction(matchedAction: QueryMatch): JSX.Element {
|
|
49
|
-
const isMatchInLabel = matchedAction.keyword == matchedAction.data.label;
|
|
50
|
-
return <Spotlight.Action onClick={matchedAction.data.onClick}>
|
|
51
|
-
<Center style={{ marginRight: '8px '}}>
|
|
52
|
-
{matchedAction.data.leftSection}
|
|
53
|
-
</Center>
|
|
54
|
-
<Group wrap="nowrap" w="100%">
|
|
55
|
-
<div style={{ flex: 1 }}>
|
|
56
|
-
<Text>
|
|
57
|
-
{isMatchInLabel ? highlightMatch(matchedAction) : matchedAction.data.label}
|
|
58
|
-
</Text>
|
|
59
|
-
{!isMatchInLabel && <Text opacity={0.6} size="xs">{highlightMatch(matchedAction)}</Text>}
|
|
60
|
-
</div>
|
|
61
|
-
</Group>
|
|
62
|
-
</Spotlight.Action>
|
|
63
|
-
}
|
|
8
|
+
import * as css from './LikeC4Search.css'
|
|
64
9
|
|
|
65
10
|
export const LikeC4Search = memo(() => {
|
|
66
11
|
const view = useDiagramState(s => s.view)
|
|
67
12
|
const model = useLikeC4Model(true)
|
|
68
13
|
const store = useDiagramStoreApi()
|
|
69
|
-
const [ query, setQuery ] = useState('')
|
|
70
14
|
|
|
71
15
|
const getNodeActionsData = (): SpotlightActionData[] => {
|
|
72
16
|
const { focusOnNode } = store.getState()
|
|
@@ -77,6 +21,9 @@ export const LikeC4Search = memo(() => {
|
|
|
77
21
|
map(n => ({
|
|
78
22
|
id: n.id,
|
|
79
23
|
label: n.title,
|
|
24
|
+
...(n.description && {
|
|
25
|
+
description: n.description
|
|
26
|
+
}),
|
|
80
27
|
keywords: [
|
|
81
28
|
n.title,
|
|
82
29
|
...(n.tags ?? []).map(t => `#${t}`),
|
|
@@ -85,62 +32,67 @@ export const LikeC4Search = memo(() => {
|
|
|
85
32
|
onClick: () => focusOnNode(n.id),
|
|
86
33
|
leftSection: <IconRectangularPrism />
|
|
87
34
|
}))
|
|
88
|
-
)
|
|
35
|
+
)
|
|
89
36
|
}
|
|
90
37
|
|
|
91
38
|
const getViewActionsData = (): SpotlightActionData[] => {
|
|
92
|
-
const
|
|
93
|
-
const views = model.views()
|
|
39
|
+
const views = [...model.views()]
|
|
94
40
|
|
|
95
41
|
return map(views, v => ({
|
|
96
42
|
id: v.id,
|
|
97
43
|
label: v.title ?? v.id,
|
|
44
|
+
...(v.$view.description && {
|
|
45
|
+
description: v.$view.description
|
|
46
|
+
}),
|
|
98
47
|
keywords: [
|
|
99
48
|
v.title ?? v.id,
|
|
100
49
|
...(v.tags ?? []),
|
|
101
|
-
...(v
|
|
50
|
+
...(v.$view.description ? [v.$view.description] : [])
|
|
102
51
|
],
|
|
103
52
|
onClick: () => {
|
|
104
53
|
store.setState({
|
|
105
|
-
hoveredNodeId: null,
|
|
106
54
|
lastOnNavigate: {
|
|
107
55
|
fromView: view.id,
|
|
108
56
|
toView: v.id,
|
|
109
57
|
fromNode: null
|
|
110
58
|
}
|
|
111
59
|
})
|
|
112
|
-
onNavigateTo?.(v.id)
|
|
60
|
+
store.getState().onNavigateTo?.(v.id)
|
|
113
61
|
},
|
|
114
|
-
leftSection:
|
|
115
|
-
|
|
62
|
+
leftSection: v.isDeploymentView()
|
|
63
|
+
? <IconStack2 />
|
|
64
|
+
: <IconSitemap />
|
|
65
|
+
}))
|
|
116
66
|
}
|
|
117
67
|
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
68
|
+
const actions = useMemo(() => [
|
|
69
|
+
{
|
|
70
|
+
group: 'Elements',
|
|
71
|
+
actions: getNodeActionsData()
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
group: 'Views',
|
|
75
|
+
actions: getViewActionsData()
|
|
76
|
+
}
|
|
77
|
+
], [model, store, view])
|
|
124
78
|
|
|
125
|
-
const portalProps = useMantinePortalProps()
|
|
79
|
+
const portalProps = useMantinePortalProps()
|
|
126
80
|
return (
|
|
127
|
-
<Spotlight
|
|
81
|
+
<Spotlight
|
|
128
82
|
{...portalProps}
|
|
83
|
+
actions={actions}
|
|
84
|
+
nothingFound="Nothing found..."
|
|
129
85
|
shortcut={['mod + f', 'mod + k']}
|
|
130
|
-
query={query}
|
|
131
|
-
onQueryChange={setQuery}
|
|
132
86
|
scrollable
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
);
|
|
146
|
-
});
|
|
87
|
+
highlightQuery
|
|
88
|
+
maxHeight={350}
|
|
89
|
+
classNames={{
|
|
90
|
+
actionSection: css.actionSection
|
|
91
|
+
}}
|
|
92
|
+
searchProps={{
|
|
93
|
+
leftSection: <IconSearch style={{ width: rem(18), height: rem(18) }} stroke={1.5} />,
|
|
94
|
+
placeholder: 'Search elements and views...'
|
|
95
|
+
}}
|
|
96
|
+
/>
|
|
97
|
+
)
|
|
98
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { style } from "@vanilla-extract/css";
|
|
2
|
+
|
|
3
|
+
export const container = style({
|
|
4
|
+
zIndex: 100,
|
|
5
|
+
width: '100%',
|
|
6
|
+
display: 'flex',
|
|
7
|
+
flexDirection: 'row',
|
|
8
|
+
flexWrap: 'nowrap',
|
|
9
|
+
alignItems: 'center',
|
|
10
|
+
gap: 2,
|
|
11
|
+
justifyContent: 'center',
|
|
12
|
+
pointerEvents: 'none',
|
|
13
|
+
})
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { Box } from '@mantine/core'
|
|
2
|
+
import { useId } from '@mantine/hooks'
|
|
3
|
+
import clsx from 'clsx'
|
|
4
|
+
import { type Variants } from 'framer-motion'
|
|
5
|
+
import type { PropsWithChildren } from 'react'
|
|
6
|
+
import * as css from './ActionButtonBar.css'
|
|
7
|
+
import { ActionButtonBarContext } from './useActionButtonBarCtx'
|
|
8
|
+
|
|
9
|
+
const TRANSLATE_DIFF = 5
|
|
10
|
+
|
|
11
|
+
type ShiftX = 'left' | 'spread' | 'right'
|
|
12
|
+
type ShiftY = 'top' | 'spread' | 'bottom'
|
|
13
|
+
type ShiftMode = number | 'spread'
|
|
14
|
+
|
|
15
|
+
type ActionButtonBarProps = PropsWithChildren<{
|
|
16
|
+
shiftX?: ShiftX
|
|
17
|
+
shiftY?: ShiftY
|
|
18
|
+
}>
|
|
19
|
+
|
|
20
|
+
const elementVariants = (prefix: string, index: number, count: number, shiftX: ShiftMode, shiftY: ShiftMode) => {
|
|
21
|
+
const name = `${prefix}${index + 1}`
|
|
22
|
+
const translation = count > 1
|
|
23
|
+
? {
|
|
24
|
+
x: shiftX === 'spread' ? 1 - count + index * 2 : shiftX,
|
|
25
|
+
y: shiftY === 'spread' ? 1 - count + index * 2 : shiftY,
|
|
26
|
+
}
|
|
27
|
+
: {
|
|
28
|
+
x: 0,
|
|
29
|
+
y: 1,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const variants = {
|
|
33
|
+
idle: {
|
|
34
|
+
'--icon-scale': 'scale(1)',
|
|
35
|
+
'--ai-bg': 'var(--ai-bg-idle)',
|
|
36
|
+
scale: 1,
|
|
37
|
+
opacity: 0.8,
|
|
38
|
+
translateX: 0,
|
|
39
|
+
translateY: 0,
|
|
40
|
+
originX: 0.5,
|
|
41
|
+
originY: 0.5,
|
|
42
|
+
// translateY: 0,
|
|
43
|
+
// ...align === 'left' && {
|
|
44
|
+
// originX: 0.75,
|
|
45
|
+
// translateX: -1
|
|
46
|
+
// },
|
|
47
|
+
// ...align === 'right' && {
|
|
48
|
+
// originX: 0.25,
|
|
49
|
+
// translateX: 1
|
|
50
|
+
// }
|
|
51
|
+
},
|
|
52
|
+
hovered: {
|
|
53
|
+
'--ai-bg': 'var(--ai-bg-hover)',
|
|
54
|
+
'--icon-scale': 'scale(1)',
|
|
55
|
+
// translateY: 3,
|
|
56
|
+
scale: 1.28,
|
|
57
|
+
opacity: 1,
|
|
58
|
+
translateX: translation.x * TRANSLATE_DIFF,
|
|
59
|
+
translateY: translation.y * TRANSLATE_DIFF,
|
|
60
|
+
// ...align === 'left' && {
|
|
61
|
+
// translateX: -4
|
|
62
|
+
// },
|
|
63
|
+
// ...align === 'right' && {
|
|
64
|
+
// translateX: 4
|
|
65
|
+
// }
|
|
66
|
+
},
|
|
67
|
+
[`hovered:${name}`]: {
|
|
68
|
+
'--ai-bg': 'var(--ai-hover)',
|
|
69
|
+
'--icon-scale': 'scale(1.08)',
|
|
70
|
+
scale: 1.45,
|
|
71
|
+
},
|
|
72
|
+
[`tap:${name}`]: {
|
|
73
|
+
'--icon-scale': 'scale(1)',
|
|
74
|
+
scale: 1.15,
|
|
75
|
+
},
|
|
76
|
+
selected: {},
|
|
77
|
+
} satisfies Variants
|
|
78
|
+
variants['selected'] = variants['hovered']
|
|
79
|
+
variants['hovered:details'] = variants['idle']
|
|
80
|
+
return {
|
|
81
|
+
variants,
|
|
82
|
+
['data-animate-target']: name,
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export const ActionButtonBar = ({
|
|
87
|
+
shiftX = 'spread',
|
|
88
|
+
shiftY = 'spread',
|
|
89
|
+
children,
|
|
90
|
+
}: ActionButtonBarProps) => {
|
|
91
|
+
const id = useId()
|
|
92
|
+
const childrenArray = Array.isArray(children) ? children : [children]
|
|
93
|
+
|
|
94
|
+
// determine offsets for shifting
|
|
95
|
+
let shiftDiffX: ShiftMode = 'spread'
|
|
96
|
+
if (shiftX == 'left') {
|
|
97
|
+
shiftDiffX = -1
|
|
98
|
+
}
|
|
99
|
+
else if (shiftX == 'right') {
|
|
100
|
+
shiftDiffX = 1
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
let shiftDiffY: ShiftMode = 'spread'
|
|
104
|
+
if (shiftY == 'top') {
|
|
105
|
+
shiftDiffY = -1
|
|
106
|
+
}
|
|
107
|
+
else if (shiftY == 'bottom') {
|
|
108
|
+
shiftDiffY = 1
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<Box className={clsx(css.container)}>
|
|
113
|
+
{childrenArray.map((child, i, all) => (
|
|
114
|
+
<ActionButtonBarContext.Provider
|
|
115
|
+
value={elementVariants(id, i, all.length, shiftDiffX, shiftDiffY)}>
|
|
116
|
+
{child}
|
|
117
|
+
</ActionButtonBarContext.Provider>
|
|
118
|
+
// <>{cloneElement(child, {
|
|
119
|
+
// key: i,
|
|
120
|
+
// variants: elementVariants(i, all.length, shiftDiffX, shiftDiffY),
|
|
121
|
+
// ['data-animate-target']: `i${i + 1}`,
|
|
122
|
+
// ...props
|
|
123
|
+
// })}</>
|
|
124
|
+
))}
|
|
125
|
+
{
|
|
126
|
+
/* {childrenArray.filter(child => !!child).map((child, i) => (
|
|
127
|
+
<m.div
|
|
128
|
+
key={i}
|
|
129
|
+
variants={elementVariants(i, childrenArray.length, shiftDiffX, shiftDiffY)}
|
|
130
|
+
{...props}
|
|
131
|
+
>
|
|
132
|
+
{child}
|
|
133
|
+
</m.div>
|
|
134
|
+
))} */
|
|
135
|
+
}
|
|
136
|
+
</Box>
|
|
137
|
+
)
|
|
138
|
+
}
|