From 03e379dd0313cea2370e580a7c937fa33c09be3b Mon Sep 17 00:00:00 2001
From: Achim Fritz <achim.fritz@b13.com>
Date: Sun, 21 Apr 2024 16:22:21 +0200
Subject: [PATCH] js-12

---
 .../backend/layout-module/drag-drop.ts        | 27 ++++++++++++++----
 .../TypeScript/backend/layout-module/paste.ts | 28 ++++++++++++++-----
 2 files changed, 43 insertions(+), 12 deletions(-)

diff --git a/Build/Sources/TypeScript/backend/layout-module/drag-drop.ts b/Build/Sources/TypeScript/backend/layout-module/drag-drop.ts
index 897f3d390b..ee877f3094 100644
--- a/Build/Sources/TypeScript/backend/layout-module/drag-drop.ts
+++ b/Build/Sources/TypeScript/backend/layout-module/drag-drop.ts
@@ -20,11 +20,11 @@ import { BaseEvent } from '@interactjs/core/BaseEvent';
 import { Interactable } from '@interactjs/core/Interactable';
 import { DragEvent } from '@interactjs/actions/drag/plugin';
 import { DropEvent } from '@interactjs/actions/drop/DropEvent';
-import DocumentService from '@typo3/core/document-service';
-import DataHandler from '../ajax-data-handler';
-import Icons from '../icons';
-import ResponseInterface from '../ajax-data-handler/response-interface';
-import RegularEvent from '@typo3/core/event/regular-event';
+import DocumentService from '@typo3/core/document-service.js';
+import DataHandler from '@typo3/backend/ajax-data-handler.js';
+import Icons from '@typo3/backend/icons.js';
+import ResponseInterface from '@typo3/backend/ajax-data-handler/response-interface.js';
+import RegularEvent from '@typo3/core/event/regular-event.js';
 
 interface Parameters {
   cmd?: { [key: string]: { [key: string]: any } };
@@ -194,6 +194,7 @@ class DragDrop {
     const dropContainer = e.target as HTMLElement;
     const draggedElement = e.relatedTarget as HTMLElement;
     const newColumn = DragDrop.getColumnPositionForElement(dropContainer);
+    const newTxContainerParent = DragDrop.getTxContainerParentPositionForElement(dropContainer);
     const contentElementUid: number = parseInt(draggedElement.dataset.uid, 10);
 
     if (typeof (contentElementUid) === 'number' && contentElementUid > 0) {
@@ -218,9 +219,12 @@ class DragDrop {
       }
 
       let colPos: number | boolean = 0;
+      let txContainerParent: number = 0;
       if (targetPid !== 0) {
         colPos = newColumn;
+        txContainerParent = newTxContainerParent;
       }
+
       const isCopyAction = (e.dragEvent.ctrlKey || dropContainer.classList.contains('t3js-paste-copy'));
       const datahandlerCommand = isCopyAction ? 'copy' : 'move';
       parameters.cmd = {
@@ -232,6 +236,7 @@ class DragDrop {
               update: {
                 colPos: colPos,
                 sys_language_uid: language,
+                tx_container_parent: txContainerParent,
               },
             }
           }
@@ -300,6 +305,18 @@ class DragDrop {
     }
     return false;
   }
+
+  /**
+   * @param element HTMLElement
+   * @return int
+   */
+  private static getTxContainerParentPositionForElement(element: HTMLElement) {
+    const columnContainer = element.closest('[data-tx-container-parent]') as HTMLElement;
+    if (columnContainer !== null && columnContainer.dataset.txContainerParent !== undefined) {
+      return parseInt(columnContainer.dataset.txContainerParent, 10);
+    }
+    return 0;
+  }
 }
 
 export default new DragDrop();
diff --git a/Build/Sources/TypeScript/backend/layout-module/paste.ts b/Build/Sources/TypeScript/backend/layout-module/paste.ts
index b692c62c84..74a96a8d0f 100644
--- a/Build/Sources/TypeScript/backend/layout-module/paste.ts
+++ b/Build/Sources/TypeScript/backend/layout-module/paste.ts
@@ -11,7 +11,7 @@
  * The TYPO3 project - inspiring people to share!
  */
 
-import DocumentService from '@typo3/core/document-service';
+import DocumentService from '@typo3/core/document-service.js';
 /**
  * Module: @typo3/backend/layout-module/paste
  * Dynamically adds "Paste" Icons in the Page Layout module (Web => Page)
@@ -19,12 +19,12 @@ import DocumentService from '@typo3/core/document-service';
  * to execute the action to paste the current clipboard contents.
  */
 import $ from 'jquery';
-import ResponseInterface from '../ajax-data-handler/response-interface';
-import DataHandler from '../ajax-data-handler';
-import { default as Modal, ModalElement, Button } from '@typo3/backend/modal';
-import Severity from '../severity';
-import '@typo3/backend/element/icon-element';
-import { SeverityEnum } from '../enum/severity';
+import ResponseInterface from '@typo3/backend/ajax-data-handler/response-interface.js';
+import DataHandler from '@typo3/backend/ajax-data-handler.js';
+import { default as Modal, ModalElement, Button } from '@typo3/backend/modal.js';
+import Severity from '@typo3/backend/severity.js';
+import '@typo3/backend/element/icon-element.js';
+import { SeverityEnum } from '@typo3/backend/enum/severity.js';
 
 type PasteOptions = {
   itemOnClipboardUid: number;
@@ -70,6 +70,18 @@ class Paste {
     return 0;
   }
 
+  /**
+   * @param {JQuery} $element
+   * @return number
+   */
+  private static determineTxContainerParent($element: JQuery): number {
+    const $columnContainer = $element.closest('[data-tx-container-parent]');
+    if ($columnContainer.length && $columnContainer.data('txContainerParent') !== 'undefined') {
+      return $columnContainer.data('txContainerParent');
+    }
+    return 0;
+  }
+
   private initializeEvents(): void
   {
     $(document).on('click', '.t3js-paste', (evt: Event): void => {
@@ -144,6 +156,7 @@ class Paste {
    */
   private execute($element: JQuery): void {
     const colPos = Paste.determineColumn($element);
+    const txContainerParent = Paste.determineTxContainerParent($element);
     const closestElement = $element.closest(this.elementIdentifier);
     const targetFound = closestElement.data('uid');
     let targetPid;
@@ -160,6 +173,7 @@ class Paste {
         update: {
           colPos: colPos,
           sys_language_uid: language,
+          tx_container_parent: txContainerParent,
         },
       },
     };
-- 
2.39.2 (Apple Git-143)

