-
Notifications
You must be signed in to change notification settings - Fork 781
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3273 from udecode/fix/toc
toc controller optimize
- Loading branch information
Showing
8 changed files
with
47 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
"@udecode/plate-heading": patch | ||
--- | ||
Fix closure issue,incorrect height calculation and expose behavior parameters |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import type React from 'react'; | ||
|
||
export const heightToTop = ( | ||
ele: Element | HTMLElement, | ||
ele: HTMLElement, | ||
editorContentRef?: React.RefObject<HTMLDivElement> | ||
) => { | ||
// ele为指定跳转到该位置的DOM节点 | ||
const root = editorContentRef ? editorContentRef.current : document.body; | ||
let height = 0; | ||
|
||
do { | ||
height += (ele as HTMLElement).offsetTop; | ||
// eslint-disable-next-line no-param-reassign | ||
ele = (ele as HTMLElement).offsetParent as unknown as Element; | ||
} while (ele !== root); | ||
if (!root || !ele) return 0; | ||
|
||
return height; | ||
const containerRect = root.getBoundingClientRect(); | ||
const elementRect = ele.getBoundingClientRect(); | ||
|
||
const scrollY = root.scrollTop; | ||
const absoluteElementTop = elementRect.top + scrollY - containerRect.top; | ||
|
||
return absoluteElementTop; | ||
}; |