diff --git a/src/Components/HtmlWrapper.tsx b/src/Components/HtmlWrapper.tsx index f774b6b..f9d8251 100644 --- a/src/Components/HtmlWrapper.tsx +++ b/src/Components/HtmlWrapper.tsx @@ -8,7 +8,7 @@ import { useQuillEditor } from '../Hooks/Quill.hook'; import { findClosestParent, findUniqueIdentifier } from '../Utils/closestParent'; import { detectEmptyElement } from '../Utils/detectEmptyBody'; import { findElementInJson } from '../Utils/findElementInMjmlJson'; -import { findColumnOfElement } from '../Utils/findElementsColumn'; +import { findColumnOfElement } from '../Utils/findElementsParent'; import { generateDropItemPlaceholder } from '../Utils/generateDropItemPlaceholder'; interface HtmlWrapperProps { diff --git a/src/Utils/closestParent.ts b/src/Utils/closestParent.ts index 14b6971..d08d39d 100644 --- a/src/Utils/closestParent.ts +++ b/src/Utils/closestParent.ts @@ -1,5 +1,5 @@ import { findElementInJson } from './findElementInMjmlJson'; -import { findColumnOfElement } from './findElementsColumn'; +import { findColumnOfElement } from './findElementsParent'; const findClosestParent = (element: HTMLElement) => { const closest = element.closest('.mjml-tag'); diff --git a/src/Utils/findElementsColumn.ts b/src/Utils/findElementsColumn.ts deleted file mode 100644 index cbf4bb6..0000000 --- a/src/Utils/findElementsColumn.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { findUniqueIdentifier } from './closestParent'; - -const findColumnOfElement = (node: HTMLElement | any): any => { - if (!node) { - return null; - } - let parent = node.closest('.mjml-tag'); - if (parent && parent.classList) { - const uniqueIdentifier = findUniqueIdentifier(parent, parent.classList); - if (uniqueIdentifier && uniqueIdentifier.includes('mj-column')) { - return [parent, uniqueIdentifier]; - } - parent = parent.parentElement; - } - - return findColumnOfElement(parent); -}; - -export { findColumnOfElement }; diff --git a/src/Utils/findElementsParent.ts b/src/Utils/findElementsParent.ts new file mode 100644 index 0000000..71d1de8 --- /dev/null +++ b/src/Utils/findElementsParent.ts @@ -0,0 +1,27 @@ +import { findUniqueIdentifier } from './closestParent'; + +const recursivelyFindParent = (node: HTMLElement | any, parentClassPartial: string): any => { + if (!node) { + return null; + } + let parent = node.closest('.mjml-tag'); + if (parent && parent.classList) { + const uniqueIdentifier = findUniqueIdentifier(parent, parent.classList); + if (uniqueIdentifier && uniqueIdentifier.includes(parentClassPartial)) { + return [parent, uniqueIdentifier]; + } + parent = parent.parentElement; + } + + return recursivelyFindParent(parent, parentClassPartial); +}; + +const findColumnOfElement = (node: HTMLElement | any): any => { + return recursivelyFindParent(node, 'mj-column'); +}; + +const findSectionOfElement = (node: HTMLElement | any): any => { + return recursivelyFindParent(node, 'mj-section'); +}; + +export { findColumnOfElement, findSectionOfElement };