ljmotta commented on code in PR #3720:
URL: 
https://github.com/apache/incubator-kie-tools/pull/3720#discussion_r3870854314


##########
packages/xyflow-react-kie-diagram/src/diagram/XyFlowReactKieDiagram.tsx:
##########
@@ -632,21 +670,22 @@ export function XyFlowReactKieDiagram<
                         dropTarget,
                         {
                           ...(node ?? 
state.xyFlowReactKieDiagram.newNodeProjection).data.shape["dc:Bounds"],
-                          "@_x": change.positionAbsolute.x,
-                          "@_y": change.positionAbsolute.y,
+                          "@_x": positionAbsolute.x,
+                          "@_y": positionAbsolute.y,
                         },
-                        (node ?? 
state.xyFlowReactKieDiagram.newNodeProjection).type!,
+                        (node ?? 
state.xyFlowReactKieDiagram.newNodeProjection).type! as N,

Review Comment:
   Casting to `N`



##########
packages/bpmn-editor/src/clipboard/Clipboard.ts:
##########
@@ -170,7 +175,7 @@ export function buildClipboardFromDiagram(xyFlowState: 
RF.ReactFlowState, bpmnEd
     }
   );
 
-  clipboard.edges = xyFlowState.edges.flatMap((edge: 
RF.Edge<BpmnDiagramEdgeData>) => {
+  clipboard.edges = (xyFlowState.edges as 
RF.Edge<BpmnDiagramEdgeData>[]).flatMap((edge) => {

Review Comment:
   `edges` must have the correct type.



##########
packages/xyflow-react-kie-diagram/src/diagram/XyFlowReactKieDiagram.tsx:
##########
@@ -920,7 +965,10 @@ export function XyFlowReactKieDiagram<
           nodeIdBeingDraggedRef.current = newNodeId;
         });
 
-        onNodeDragStop(undefined as any, { dragging: true } as any, []);
+        // Palette drops count as "moved"; invoke onNodeDragStop with a 
synthetic event to trigger parenting logic
+        // (callback only reads nodeIdBeingDraggedRef, not `node`).
+        nodeActuallyMovedRef.current = true;
+        onNodeDragStop(new MouseEvent("mouseup"), {} as RF.Node<NData, N>, []);

Review Comment:
   👍 I don't think we can avoid this one.



##########
packages/xyflow-react-kie-diagram/src/diagram/XyFlowReactKieDiagram.tsx:
##########
@@ -751,7 +794,7 @@ export function XyFlowReactKieDiagram<
           // Un-parent
           if (nodeBeingDragged.data.parentXyFlowNode) {
             const p = 
state.computed(state).getDiagramData().nodesById.get(nodeBeingDragged.data.parentXyFlowNode.id);
-            if (p?.type && containmentMap.get(p.type)) {
+            if (p?.type && (containmentMap as Map<string, 
unknown>).has(p.type)) {

Review Comment:
   Casting to `Map<string, unknown>`



##########
packages/xyflow-react-kie-diagram/src/diagram/XyFlowReactKieDiagram.tsx:
##########
@@ -1035,85 +1083,103 @@ export function XyFlowReactKieDiagram<
   );
 
   return (
-    <>
-      <I18nDictionariesProvider
-        defaults={kieDiagramI18nDefaults}
-        dictionaries={kieDiagramI18nDictionaries}
-        initialLocale={navigator.language}
-        ctx={KieDiagramI18nContext}
-      >
-        <WaypointActionsContextProvider value={waypointActionsContextValue}>
-          <RF.ReactFlow
-            connectionMode={RF.ConnectionMode.Loose} // Allow target handles 
to be used as source. This is very important for allowing the positional 
handles to be updated for the base of an edge.
-            onKeyDownCapture={handleRfKeyDownCapture} // Override Reactflow's 
keyboard listeners.
-            nodes={nodes}
-            edges={edges}
-            onNodesChange={onNodesChange}
-            onEdgesChange={onEdgesChange}
-            onEdgeUpdateStart={onEdgeUpdateStart}
-            onEdgeUpdateEnd={onEdgeUpdateEnd}
-            onEdgeUpdate={onEdgeUpdate}
-            onlyRenderVisibleElements={true}
-            zoomOnDoubleClick={false}
-            elementsSelectable={true}
-            panOnScroll={true}
-            zoomOnScroll={false}
-            preventScrolling={true}
-            selectionOnDrag={true}
-            panOnDrag={PAN_ON_DRAG}
-            selectionMode={RF.SelectionMode.Full} // For selections happening 
inside Containment nodes it's better to leave it as "Full"
-            isValidConnection={isValidConnection}
-            connectionLineComponent={connectionLineComponent}
-            onConnect={onConnect}
-            onConnectStart={onConnectStart}
-            onConnectEnd={onConnectEnd}
-            // (begin)
-            // 'Starting to drag' and 'dragging' should have the same 
behavior. Otherwise,
-            // clicking a node and letting it go, without moving, won't work 
properly, and
-            // Nodes will be removed from Containment Nodes.
-            onNodeDragStart={onNodeDragStart}
-            onNodeDrag={onNodeDrag}
-            // (end)
-            onNodeDragStop={onNodeDragStop}
-            nodeTypes={nodeComponents}
-            edgeTypes={edgeComponents}
-            snapToGrid={true}
-            snapGrid={xyFlowSnapGrid}
-            defaultViewport={DEFAULT_VIEWPORT}
-            fitView={false}
-            fitViewOptions={FIT_VIEW_OPTIONS}
-            attributionPosition={"bottom-right"}
-            onInit={setReactFlowInstance}
-            deleteKeyCode={DELETE_NODE_KEY_CODES}
-            // (begin)
-            // Used to make the Palette work by dropping nodes on the 
Reactflow Canvas
-            onDrop={onDrop}
-            onDragOver={onDragOver}
-            // (end)
-          >
-            {children}
-            <SelectionStatusLabel />
-            {!isFirefox && <RF.Background />}
-            <RF.Controls fitViewOptions={FIT_VIEW_OPTIONS} 
position={"bottom-right"} />
-            <SetConnectionToReactFlowStore />
-          </RF.ReactFlow>
-        </WaypointActionsContextProvider>
-      </I18nDictionariesProvider>
-    </>
+    <I18nDictionariesProvider
+      defaults={kieDiagramI18nDefaults}
+      dictionaries={kieDiagramI18nDictionaries}
+      initialLocale={navigator.language}
+      ctx={KieDiagramI18nContext}
+    >
+      <WaypointActionsContextProvider value={waypointActionsContextValue}>
+        <RF.ReactFlow
+          connectionMode={RF.ConnectionMode.Loose} // Allow target handles to 
be used as source. This is very important for allowing the positional handles 
to be updated for the base of an edge.
+          onKeyDownCapture={handleRfKeyDownCapture} // Override Reactflow's 
keyboard listeners.
+          nodes={nodes}
+          edges={edges}
+          onNodesChange={onNodesChange}
+          onEdgesChange={onEdgesChange}
+          onReconnectStart={onReconnectStart}
+          onReconnectEnd={onReconnectEnd}
+          onReconnect={onReconnect}
+          onlyRenderVisibleElements={true}
+          zoomOnDoubleClick={false}
+          elementsSelectable={true}
+          panOnScroll={true}
+          zoomOnScroll={false}
+          preventScrolling={true}
+          selectionOnDrag={true}
+          panOnDrag={PAN_ON_DRAG}
+          selectionMode={RF.SelectionMode.Full} // For selections happening 
inside Containment nodes it's better to leave it as "Full"
+          isValidConnection={isValidConnection}
+          connectionLineComponent={connectionLineComponent}
+          onConnect={onConnect}
+          onConnectStart={onConnectStart}
+          onConnectEnd={onConnectEnd}
+          // (begin)
+          // 'Starting to drag' and 'dragging' should have the same behavior. 
Otherwise,
+          // clicking a node and letting it go, without moving, won't work 
properly, and
+          // Nodes will be removed from Containment Nodes.
+          onNodeDragStart={onNodeDragStart}
+          onNodeDrag={onNodeDrag}
+          // (end)
+          onNodeDragStop={onNodeDragStop}
+          nodeTypes={nodeComponents}
+          edgeTypes={edgeComponents}
+          snapToGrid={true}
+          snapGrid={xyFlowSnapGrid}
+          defaultViewport={DEFAULT_VIEWPORT}
+          fitView={false}
+          fitViewOptions={FIT_VIEW_OPTIONS}
+          attributionPosition={"bottom-right"}
+          onInit={(instance) =>
+            setReactFlowInstance(instance as 
RF.ReactFlowInstance<RF.Node<NData, N>, RF.Edge<EData>>)
+          }

Review Comment:
   Can't we type `intance` instead?



##########
packages/xyflow-react-kie-diagram/src/diagram/XyFlowReactKieDiagram.tsx:
##########
@@ -527,8 +562,11 @@ export function XyFlowReactKieDiagram<
                     state.xyFlowReactKieDiagram.newNodeProjection!;
 
                   let foundContainer = false;
-                  for (const potentialContainer of 
reactFlowInstance?.getNodes().reverse() ??
-                    [] /* Respect the nodes z-index */) {
+                  // Use xyFlowStoreApi for synchronous access; nodeLookup 
stores InternalNode<Node> so we cast
+                  // through unknown to Node<NData, N> (safe since NData 
satisfies Record<string, unknown>).
+                  for (const potentialContainer of (
+                    Array.from(xyFlowStoreApi.getState().nodeLookup.values()) 
as unknown as RF.Node<NData, N>[]

Review Comment:
   Casting to `unknown`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to