Skip to content

Commit f994f30

Browse files
committed
[6126] Remove DiagramPaletteToolExtensionPoints in favor of a PaletteQuickToolExtensionPoints
Bug: #6126 Signed-off-by: Michaël Charfadi <michael.charfadi@obeosoft.com>
1 parent 71aeff1 commit f994f30

File tree

12 files changed

+97
-107
lines changed

12 files changed

+97
-107
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
=== Breaking changes
2121

22-
22+
- https://github.com/eclipse-sirius/sirius-web/issues/6126[#6126] [diagram] `DiagramPaletteToolExtensionPoints` has been removed, use `PaletteQuickToolExtensionPoints` instead that supports multiple elements.
2323

2424

2525
=== Dependency update

packages/diagrams/frontend/sirius-components-diagrams/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ export type {
9191
DiagramPaletteToolContributionProps,
9292
} from './renderer/palette/extensions/DiagramPaletteToolContribution.types';
9393
export { diagramPaletteToolExtensionPoint } from './renderer/palette/extensions/DiagramPaletteToolExtensionPoints';
94+
export { useDiagramPalette } from './renderer/palette/useDiagramPalette';
95+
export type { DiagramPanelActionProps } from './renderer/panel/DiagramPanel.types';
96+
export { diagramPanelActionExtensionPoint } from './renderer/panel/DiagramPanelExtensionPoints';
9497
export type { DiagramToolbarActionProps } from './renderer/toolbar/DiagramToolbar.types';
9598
export { diagramToolbarActionExtensionPoint } from './renderer/toolbar/DiagramToolbarExtensionPoints';
9699
export type { IElementSVGExportHandler } from './renderer/toolbar/experimental-svg-export/SVGExportEngine.types';

packages/diagrams/frontend/sirius-components-diagrams/src/renderer/palette/Palette.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2023, 2025 Obeo.
2+
* Copyright (c) 2023, 2026 Obeo.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -183,8 +183,6 @@ export const Palette = ({
183183
diagramElementIds={diagramElementIds}
184184
onToolClick={handleToolClick}
185185
quickAccessTools={palette.quickAccessTools}
186-
x={paletteX}
187-
y={paletteY}
188186
/>
189187
<PaletteSearchField onValueChanged={onSearchFieldValueChanged} />
190188
{state.searchToolValue.length > 0 ? (

packages/diagrams/frontend/sirius-components-diagrams/src/renderer/palette/extensions/DiagramPaletteToolContribution.types.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

packages/diagrams/frontend/sirius-components-diagrams/src/renderer/palette/quick-access-tool/PaletteQuickAccessToolBar.tsx

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2024, 2025 Obeo.
2+
* Copyright (c) 2024, 2026 Obeo.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -12,14 +12,14 @@
1212
*******************************************************************************/
1313

1414
import { DataExtension, useData } from '@eclipse-sirius/sirius-components-core';
15+
import {
16+
PaletteQuickToolContributionProps,
17+
paletteQuickToolExtensionPoint,
18+
} from '@eclipse-sirius/sirius-components-palette';
1519
import Box from '@mui/material/Box';
1620
import Divider from '@mui/material/Divider';
1721
import { Theme } from '@mui/material/styles';
18-
import { Edge, Node, useStoreApi } from '@xyflow/react';
1922
import { makeStyles } from 'tss-react/mui';
20-
import { EdgeData, NodeData } from '../../DiagramRenderer.types';
21-
import { diagramPaletteToolExtensionPoint } from '../extensions/DiagramPaletteToolExtensionPoints';
22-
import { DiagramPaletteToolContributionProps } from './../extensions/DiagramPaletteToolContribution.types';
2323
import { PaletteQuickAccessToolBarProps } from './PaletteQuickAccessToolBar.types';
2424
import { Tool } from './Tool';
2525

@@ -40,40 +40,28 @@ export const PaletteQuickAccessToolBar = ({
4040
diagramElementIds,
4141
quickAccessTools,
4242
onToolClick,
43-
x,
44-
y,
4543
}: PaletteQuickAccessToolBarProps) => {
4644
const { classes } = useStyle();
47-
const { nodeLookup, edgeLookup } = useStoreApi<Node<NodeData>, Edge<EdgeData>>().getState();
4845

4946
const quickAccessToolComponents: JSX.Element[] = [];
5047
quickAccessTools.forEach((tool) =>
5148
quickAccessToolComponents.push(<Tool tool={tool} onClick={onToolClick} key={'tool_' + tool.id} />)
5249
);
5350

54-
if (diagramElementIds.length === 1 && diagramElementIds[0]) {
55-
const diagramElementId = diagramElementIds[0];
56-
let diagramElement = edgeLookup.get(diagramElementId) || nodeLookup.get(diagramElementId);
51+
const paletteToolData: DataExtension<PaletteQuickToolContributionProps[]> = useData(paletteQuickToolExtensionPoint);
5752

58-
const paletteToolData: DataExtension<DiagramPaletteToolContributionProps[]> = useData(
59-
diagramPaletteToolExtensionPoint
53+
paletteToolData.data
54+
.filter((data) => data.canHandle(diagramElementIds))
55+
.map((data) => data.component)
56+
.forEach((PaletteToolComponent, index) =>
57+
quickAccessToolComponents.push(
58+
<PaletteToolComponent
59+
representationElementIds={diagramElementIds}
60+
key={'paletteToolComponents_' + index.toString()}
61+
/>
62+
)
6063
);
6164

62-
paletteToolData.data
63-
.filter((data) => data.canHandle(diagramElement ?? null))
64-
.map((data) => data.component)
65-
.forEach((PaletteToolComponent, index) =>
66-
quickAccessToolComponents.push(
67-
<PaletteToolComponent
68-
x={x}
69-
y={y}
70-
diagramElementId={diagramElementId}
71-
key={'paletteToolComponents_' + index.toString()}
72-
/>
73-
)
74-
);
75-
}
76-
7765
return quickAccessToolComponents.length > 0 ? (
7866
<>
7967
<div>

packages/diagrams/frontend/sirius-components-diagrams/src/renderer/palette/quick-access-tool/PaletteQuickAccessToolBar.types.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2024, 2025 Obeo.
2+
* Copyright (c) 2024, 2026 Obeo.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -14,9 +14,7 @@
1414
import { GQLTool } from '../Palette.types';
1515

1616
export interface PaletteQuickAccessToolBarProps {
17-
x: number;
18-
y: number;
1917
diagramElementIds: string[];
20-
onToolClick: (tool: GQLTool) => void;
2118
quickAccessTools: GQLTool[];
19+
onToolClick: (tool: GQLTool) => void;
2220
}

packages/diagrams/frontend/sirius-components-diagrams/src/renderer/palette/extensions/DiagramPaletteTool.types.ts renamed to packages/palette/frontend/sirius-components-palette/src/extensions/PaletteQuickToolContribution.types.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2024 Obeo.
2+
* Copyright (c) 2024, 2026 Obeo.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -11,8 +11,11 @@
1111
* Obeo - initial API and implementation
1212
*******************************************************************************/
1313

14-
export interface DiagramPaletteToolComponentProps {
15-
x: number;
16-
y: number;
17-
diagramElementId: string;
14+
export interface PaletteQuickToolContributionProps {
15+
canHandle: (representationElementIds: string[]) => boolean;
16+
component: React.ComponentType<PaletteQuickToolContributionComponentProps>;
17+
}
18+
19+
export interface PaletteQuickToolContributionComponentProps {
20+
representationElementIds: string[];
1821
}

packages/diagrams/frontend/sirius-components-diagrams/src/renderer/palette/extensions/DiagramPaletteToolExtensionPoints.tsx renamed to packages/palette/frontend/sirius-components-palette/src/extensions/PaletteQuickToolExtensionPoints.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2024, 2025 Obeo.
2+
* Copyright (c) 2024, 2026 Obeo.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -12,17 +12,17 @@
1212
*******************************************************************************/
1313

1414
import { DataExtensionPoint } from '@eclipse-sirius/sirius-components-core';
15-
import { DiagramPaletteToolContributionProps } from './DiagramPaletteToolContribution.types';
15+
import { PaletteQuickToolContributionProps } from './PaletteQuickToolContribution.types';
1616

1717
/**
18-
* Extension point for diagram palette tools.
18+
* Extension point for palette quick tools.
1919
*
20-
* This extension point allows the addition of custom tools to the diagram palette.
20+
* This extension point allows the addition of custom quick tools to the diagram palette.
2121
* Each contribution can define how a tool should be rendered and behave.
2222
*
23-
* @since v2024.9.0
23+
* @since v2026.3.0
2424
*/
25-
export const diagramPaletteToolExtensionPoint: DataExtensionPoint<Array<DiagramPaletteToolContributionProps>> = {
26-
identifier: 'diagramPalette#tool',
25+
export const paletteQuickToolExtensionPoint: DataExtensionPoint<Array<PaletteQuickToolContributionProps>> = {
26+
identifier: 'palette#quickTool',
2727
fallback: [],
2828
};

packages/palette/frontend/sirius-components-palette/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
* Obeo - initial API and implementation
1212
*******************************************************************************/
1313

14+
export type {
15+
PaletteQuickToolContributionComponentProps,
16+
PaletteQuickToolContributionProps,
17+
} from './extensions/PaletteQuickToolContribution.types';
18+
export { paletteQuickToolExtensionPoint } from './extensions/PaletteQuickToolExtensionPoints';
1419
export { PaletteExtensionSection } from './PaletteExtensionSection';
1520
export type {
1621
PaletteExtensionSectionComponentProps,

packages/sirius-web/frontend/sirius-web-papaya/src/PapayaExtensionRegistry.tsx

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ import {
2121
import {
2222
ActionProps,
2323
DiagramNodeActionOverrideContribution,
24-
DiagramPaletteToolContributionProps,
2524
EdgeData,
2625
NodeData,
2726
ReactFlowPropsCustomizer,
2827
diagramNodeActionOverrideContributionExtensionPoint,
29-
diagramPaletteToolExtensionPoint,
3028
diagramRendererReactFlowPropsCustomizerExtensionPoint,
3129
} from '@eclipse-sirius/sirius-components-diagrams';
3230
import {
@@ -35,6 +33,10 @@ import {
3533
OmniboxCommandOverrideContribution,
3634
omniboxCommandOverrideContributionExtensionPoint,
3735
} from '@eclipse-sirius/sirius-components-omnibox';
36+
import {
37+
PaletteQuickToolContributionProps,
38+
paletteQuickToolExtensionPoint,
39+
} from '@eclipse-sirius/sirius-components-palette';
3840
import {
3941
NavigationBarProps,
4042
navigationBarCenterContributionExtensionPoint,
@@ -45,7 +47,7 @@ import ListItemButton from '@mui/material/ListItemButton';
4547
import ListItemIcon from '@mui/material/ListItemIcon';
4648
import ListItemText from '@mui/material/ListItemText';
4749
import Typography from '@mui/material/Typography';
48-
import { Edge, Node, ReactFlowProps } from '@xyflow/react';
50+
import { Edge, Node, ReactFlowProps, useStoreApi } from '@xyflow/react';
4951
import { PapayaDiagramInformationPanel } from './diagrams/PapayaDiagramInformationPanel';
5052
import { PapayaComponentLabelDetailNodeActionContribution } from './nodeactions/PapayaComponentLabelDetailNodeActionContribution';
5153
import { PapayaComponentDiagramToolContribution } from './tools/PapayaComponentDiagramToolContribution';
@@ -100,22 +102,34 @@ const papayaDiagramToolbarExtension: DataExtension<Array<ReactFlowPropsCustomize
100102
data: [reactFlowPropsCustomizer],
101103
};
102104
papayaExtensionRegistry.putData(diagramRendererReactFlowPropsCustomizerExtensionPoint, papayaDiagramToolbarExtension);
103-
const diagramPaletteToolContributions: DiagramPaletteToolContributionProps[] = [
105+
const diagramPaletteToolContributions: PaletteQuickToolContributionProps[] = [
104106
{
105-
canHandle: (diagramElement: Node<NodeData> | Edge<EdgeData> | null) => {
106-
return diagramElement?.data
107-
? diagramElement.data.targetObjectKind.startsWith('siriusComponents://semantic?domain=papaya&entity=Component')
108-
: false;
107+
canHandle: (representationElementIds: string[]) => {
108+
const store = useStoreApi<Node<NodeData>, Edge<EdgeData>>();
109+
return representationElementIds.every((elementId) =>
110+
store
111+
.getState()
112+
.nodeLookup.get(elementId)
113+
?.data.targetObjectKind.startsWith('siriusComponents://semantic?domain=papaya&entity=Component')
114+
);
109115
},
110116
component: PapayaComponentLabelDetailToolContribution,
111117
},
112118
{
113-
canHandle: (diagramElement: Node<NodeData> | Edge<EdgeData> | null) => diagramElement === null,
119+
canHandle: (representationElementIds: string[]) => {
120+
const store = useStoreApi<Node<NodeData>, Edge<EdgeData>>();
121+
return !(
122+
representationElementIds.length === 1 &&
123+
representationElementIds[0] &&
124+
(store.getState().nodeLookup.get(representationElementIds[0]) ||
125+
store.getState().edgeLookup.get(representationElementIds[0]))
126+
);
127+
},
114128
component: PapayaComponentDiagramToolContribution,
115129
},
116130
];
117-
papayaExtensionRegistry.putData<DiagramPaletteToolContributionProps[]>(diagramPaletteToolExtensionPoint, {
118-
identifier: `papaya_${diagramPaletteToolExtensionPoint.identifier}`,
131+
papayaExtensionRegistry.putData<PaletteQuickToolContributionProps[]>(paletteQuickToolExtensionPoint, {
132+
identifier: `papaya_${paletteQuickToolExtensionPoint.identifier}`,
119133
data: diagramPaletteToolContributions,
120134
});
121135

0 commit comments

Comments
 (0)