@bian-womp/spark-workbench 0.2.87 → 0.2.89

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/lib/cjs/index.cjs CHANGED
@@ -5123,30 +5123,26 @@ const WorkbenchCanvas = React.forwardRef(({ showValues, toString, toElement, get
5123
5123
  };
5124
5124
  const onContextMenu = (e) => {
5125
5125
  e.preventDefault();
5126
- // First, check if the cursor is inside the rectangular bounds of the current selection
5127
- const selectionBounds = getSelectionScreenBounds();
5128
- if (selectionBounds) {
5129
- const { left, top, right, bottom } = selectionBounds;
5130
- if (e.clientX >= left &&
5131
- e.clientX <= right &&
5132
- e.clientY >= top &&
5133
- e.clientY <= bottom) {
5134
- setSelectionMenuPos({ x: e.clientX, y: e.clientY });
5135
- setSelectionMenuOpen(true);
5136
- setMenuOpen(false);
5137
- setNodeMenuOpen(false);
5138
- return;
5139
- }
5140
- }
5126
+ const selection = wb.getSelection();
5127
+ const isSingleNodeSelected = selection.nodes.length === 1;
5128
+ const hasMultipleNodesSelected = selection.nodes.length > 1;
5141
5129
  // Determine if right-clicked over a node by hit-testing
5142
5130
  const target = e.target?.closest(".react-flow__node");
5143
5131
  if (target) {
5144
5132
  // Resolve node id from data-id attribute React Flow sets
5145
5133
  const nodeId = target.getAttribute("data-id");
5146
- const selection = wb.getSelection();
5147
5134
  const isSelected = nodeId && selection.nodes.includes(nodeId);
5148
- if (isSelected) {
5149
- // Right-clicked on a selected node - show selection menu
5135
+ if (isSelected && isSingleNodeSelected) {
5136
+ // Right-clicked on the single selected node - show node menu
5137
+ setNodeAtMenu(nodeId);
5138
+ setNodeMenuPos({ x: e.clientX, y: e.clientY });
5139
+ setNodeMenuOpen(true);
5140
+ setMenuOpen(false);
5141
+ setSelectionMenuOpen(false);
5142
+ return;
5143
+ }
5144
+ else if (isSelected) {
5145
+ // Right-clicked on a node that's part of multi-selection - show selection menu
5150
5146
  setSelectionMenuPos({ x: e.clientX, y: e.clientY });
5151
5147
  setSelectionMenuOpen(true);
5152
5148
  setMenuOpen(false);
@@ -5167,10 +5163,45 @@ const WorkbenchCanvas = React.forwardRef(({ showValues, toString, toElement, get
5167
5163
  const edgeTarget = e.target?.closest(".react-flow__edge");
5168
5164
  if (edgeTarget) {
5169
5165
  const edgeId = edgeTarget.getAttribute("data-id");
5170
- const selection = wb.getSelection();
5171
5166
  const isSelected = edgeId && selection.edges.includes(edgeId);
5172
- if (isSelected) {
5173
- // Right-clicked on a selected edge - show selection menu
5167
+ if (isSelected && isSingleNodeSelected) {
5168
+ // Right-clicked on an edge, but only one node is selected - show node menu
5169
+ const nodeId = selection.nodes[0];
5170
+ setNodeAtMenu(nodeId);
5171
+ setNodeMenuPos({ x: e.clientX, y: e.clientY });
5172
+ setNodeMenuOpen(true);
5173
+ setMenuOpen(false);
5174
+ setSelectionMenuOpen(false);
5175
+ return;
5176
+ }
5177
+ else if (isSelected) {
5178
+ // Right-clicked on a selected edge with multiple nodes - show selection menu
5179
+ setSelectionMenuPos({ x: e.clientX, y: e.clientY });
5180
+ setSelectionMenuOpen(true);
5181
+ setMenuOpen(false);
5182
+ setNodeMenuOpen(false);
5183
+ return;
5184
+ }
5185
+ }
5186
+ // If only one node is selected (even with edges), show node menu for empty space clicks
5187
+ if (isSingleNodeSelected) {
5188
+ const nodeId = selection.nodes[0];
5189
+ setNodeAtMenu(nodeId);
5190
+ setNodeMenuPos({ x: e.clientX, y: e.clientY });
5191
+ setNodeMenuOpen(true);
5192
+ setMenuOpen(false);
5193
+ setSelectionMenuOpen(false);
5194
+ return;
5195
+ }
5196
+ // Check if the cursor is inside the rectangular bounds of the current selection
5197
+ // (for multi-selection when right-clicking on empty space within selection bounds)
5198
+ const selectionBounds = getSelectionScreenBounds();
5199
+ if (selectionBounds && hasMultipleNodesSelected) {
5200
+ const { left, top, right, bottom } = selectionBounds;
5201
+ if (e.clientX >= left &&
5202
+ e.clientX <= right &&
5203
+ e.clientY >= top &&
5204
+ e.clientY <= bottom) {
5174
5205
  setSelectionMenuPos({ x: e.clientX, y: e.clientY });
5175
5206
  setSelectionMenuOpen(true);
5176
5207
  setMenuOpen(false);
@@ -5178,7 +5209,7 @@ const WorkbenchCanvas = React.forwardRef(({ showValues, toString, toElement, get
5178
5209
  return;
5179
5210
  }
5180
5211
  }
5181
- // Right-clicked on empty space - show default menu
5212
+ // Right-clicked on empty space with no selection - show default menu
5182
5213
  setMenuPos({ x: e.clientX, y: e.clientY });
5183
5214
  setMenuOpen(true);
5184
5215
  setNodeMenuOpen(false);