-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[2094] Add the support for a diagram palette
Bug: #2094 Signed-off-by: Guillaume Coutable <guillaume.coutable@obeo.fr>
- Loading branch information
Showing
16 changed files
with
241 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
= [ADR-106] Add the support for the palette with reactflow | ||
|
||
== Context | ||
|
||
We have chosen to use reactflow to do the layout of diagram. | ||
In the early use, the layout will be done in the frontend. | ||
We need to support features like a palette. | ||
The palette will be displayed on top of the selected node and at the position of the click on the diagram pane. | ||
|
||
== Decision | ||
|
||
We will rely on the https://reactflow.dev/docs/api/nodes/node-toolbar/[reactflow NodeToolbar] for node and our implementation for the diagram palette. | ||
|
||
In the first version, when a node is selected, its palette will be displayed. | ||
Once opened, the diagram palette will be displayed until the selection is changed. | ||
The palette will be closed when the diagram pane is dragged. | ||
|
||
== Status | ||
|
||
Accepted. | ||
|
||
== Consequences | ||
|
||
Once opened the palette will almost always be opened. | ||
We may add a way to close the palette manually later. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...ams/frontend/sirius-components-diagrams-reactflow/src/renderer/palette/DiagramPalette.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
import { makeStyles } from '@material-ui/core/styles'; | ||
import { DiagramPaletteProps } from './DiagramPalette.types'; | ||
import { DiagramPalettePortal } from './DiagramPalettePortal'; | ||
import { Palette } from './Palette'; | ||
|
||
const useDiagramPaletteStyle = makeStyles((theme) => ({ | ||
toolbar: { | ||
background: theme.palette.background.paper, | ||
border: '1px solid #d1dadb', | ||
boxShadow: '0px 2px 5px #002b3c40', | ||
borderRadius: '2px', | ||
zIndex: 2, | ||
position: 'fixed', | ||
display: 'flex', | ||
alignItems: 'center', | ||
}, | ||
})); | ||
|
||
export const DiagramPalette = ({ targetObjectId, x, y }: DiagramPaletteProps) => { | ||
const classes = useDiagramPaletteStyle(); | ||
return ( | ||
<DiagramPalettePortal> | ||
<div className={classes.toolbar} style={{ position: 'absolute', left: x, top: y }}> | ||
<Palette diagramElementId={targetObjectId} /> | ||
</div> | ||
</DiagramPalettePortal> | ||
); | ||
}; |
25 changes: 25 additions & 0 deletions
25
...rontend/sirius-components-diagrams-reactflow/src/renderer/palette/DiagramPalette.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
import { ReactNode } from 'react'; | ||
|
||
export interface DiagramPaletteProps { | ||
targetObjectId: string; | ||
|
||
x: number; | ||
y: number; | ||
} | ||
|
||
export interface DiagramPalettePortalProps { | ||
children: ReactNode; | ||
} |
28 changes: 28 additions & 0 deletions
28
...ontend/sirius-components-diagrams-reactflow/src/renderer/palette/DiagramPalettePortal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
import { createPortal } from 'react-dom'; | ||
import { ReactFlowState, useStore } from 'reactflow'; | ||
import { DiagramPalettePortalProps } from './DiagramPalette.types'; | ||
|
||
const selector = (state: ReactFlowState) => state.domNode?.querySelector('.react-flow__renderer'); | ||
|
||
export const DiagramPalettePortal = ({ children }: DiagramPalettePortalProps) => { | ||
const wrapperRef = useStore(selector); | ||
|
||
if (!wrapperRef) { | ||
return null; | ||
} | ||
|
||
return createPortal(children, wrapperRef); | ||
}; |
39 changes: 39 additions & 0 deletions
39
...agrams/frontend/sirius-components-diagrams-reactflow/src/renderer/palette/NodePalette.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
import { makeStyles } from '@material-ui/core/styles'; | ||
import { NodeToolbar, Position } from 'reactflow'; | ||
import { NodePaletteProps } from './NodePalette.types'; | ||
import { Palette } from './Palette'; | ||
|
||
const useNodePaletteStyle = makeStyles((theme) => ({ | ||
toolbar: { | ||
background: theme.palette.background.paper, | ||
border: '1px solid #d1dadb', | ||
boxShadow: '0px 2px 5px #002b3c40', | ||
borderRadius: '2px', | ||
zIndex: 2, | ||
position: 'fixed', | ||
display: 'flex', | ||
alignItems: 'center', | ||
}, | ||
})); | ||
|
||
export const NodePalette = ({ diagramElementId }: NodePaletteProps) => { | ||
const classes = useNodePaletteStyle(); | ||
return ( | ||
<NodeToolbar className={classes.toolbar} position={Position.Top}> | ||
<Palette diagramElementId={diagramElementId} /> | ||
</NodeToolbar> | ||
); | ||
}; |
16 changes: 16 additions & 0 deletions
16
...s/frontend/sirius-components-diagrams-reactflow/src/renderer/palette/NodePalette.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
export interface NodePaletteProps { | ||
diagramElementId: string; | ||
} |
Oops, something went wrong.