Skip to content

Commit 2d82e2a

Browse files
authored
Fix page is bottom function to handle non-scrollable elements (#373)
* fix for page is bottom bug * fix type file * formatting and add biome * remove problematic code * update to fix bottommode hashes showing as highlight on first load * final updates for this fix/feature
1 parent c7d7333 commit 2d82e2a

30 files changed

+22488
-22099
lines changed

.babelrc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"presets": [
3-
["@babel/preset-env", {
4-
"targets": {
5-
"esmodules": true
3+
[
4+
"@babel/preset-env",
5+
{
6+
"targets": {
7+
"esmodules": true
8+
}
69
}
7-
}],
10+
],
811
"@babel/preset-react"
912
],
10-
"plugins": [
11-
"@babel/plugin-syntax-dynamic-import"
12-
],
13+
"plugins": ["@babel/plugin-syntax-dynamic-import"],
1314
"ignore": []
1415
}

biome.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
3+
"vcs": {
4+
"enabled": true,
5+
"clientKind": "git",
6+
"useIgnoreFile": true
7+
},
8+
"files": {
9+
"ignoreUnknown": false,
10+
"ignore": [".gitignore", "dist/", "test/", "data/"]
11+
},
12+
"formatter": {
13+
"enabled": true,
14+
"indentWidth": 2,
15+
"indentStyle": "space"
16+
},
17+
"organizeImports": {
18+
"enabled": true
19+
},
20+
"linter": {
21+
"enabled": true,
22+
"rules": {
23+
"recommended": true
24+
}
25+
},
26+
"javascript": {
27+
"formatter": {
28+
"enabled": true,
29+
"quoteStyle": "double",
30+
"semicolons": "asNeeded"
31+
}
32+
}
33+
}

bower.json

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
{
22
"name": "tocbot",
33
"description": "Generate a table of contents based on the heading structure of a html document.",
4-
"main": [
5-
"dist/tocbot.js",
6-
"dist/tocbot.css"
7-
],
8-
"authors": [
9-
"Tim Scanlin"
10-
],
4+
"main": ["dist/tocbot.js", "dist/tocbot.css"],
5+
"authors": ["Tim Scanlin"],
116
"license": "MIT",
127
"keywords": [
138
"tocbot",
@@ -21,11 +16,5 @@
2116
"vanilla"
2217
],
2318
"homepage": "https://github.com/tscanlin/tocbot",
24-
"ignore": [
25-
"**/.*",
26-
"node_modules",
27-
"bower_components",
28-
"test",
29-
"tests"
30-
]
19+
"ignore": ["**/.*", "node_modules", "bower_components", "test", "tests"]
3120
}

index.d.ts

Lines changed: 125 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,125 @@
1-
export = tocbot;
2-
export as namespace tocbot;
3-
4-
declare namespace tocbot {
5-
/**
6-
* @see https://github.com/tscanlin/tocbot#options
7-
*/
8-
interface IStaticOptions {
9-
// Where to render the table of contents.
10-
tocSelector?: string
11-
// Where to grab the headings to build the table of contents.
12-
contentSelector?: string
13-
// Which headings to grab inside of the contentSelector element.
14-
headingSelector?: string
15-
// Headings that match the ignoreSelector will be skipped.
16-
ignoreSelector?: string
17-
// For headings inside relative or absolute positioned containers within content.
18-
hasInnerContainers?: boolean
19-
// Main class to add to links.
20-
linkClass?: string
21-
// Extra classes to add to links.
22-
extraLinkClasses?: string
23-
// Class to add to active links // the link corresponding to the top most heading on the page.
24-
activeLinkClass?: string
25-
// Main class to add to lists.
26-
listClass?: string
27-
// Extra classes to add to lists.
28-
extraListClasses?: string
29-
// Class that gets added when a list should be collapsed.
30-
isCollapsedClass?: string
31-
// Class that gets added when a list should be able
32-
// to be collapsed but isn't necessarily collapsed.
33-
collapsibleClass?: string
34-
// Class to add to list items.
35-
listItemClass?: string
36-
// Class to add to active list items.
37-
activeListItemClass?: string
38-
// How many heading levels should not be collapsed.
39-
// For example; number 6 will show everything since
40-
// there are only 6 heading levels and number 0 will collapse them all.
41-
// The sections that are hidden will open
42-
// and close as you scroll to headings within them.
43-
collapseDepth?: number
44-
// Smooth scrolling enabled.
45-
scrollSmooth?: boolean
46-
// Smooth scroll duration.
47-
scrollSmoothDuration?: number
48-
// Smooth scroll offset.
49-
scrollSmoothOffset?: number
50-
// Callback for scroll end.
51-
scrollEndCallback?(e: WheelEvent): void
52-
// Headings offset between the headings and the top of the document (this is meant for minor adjustments).
53-
headingsOffset?: number
54-
// Timeout between events firing to make sure it's
55-
// not too rapid (for performance reasons).
56-
throttleTimeout?: number
57-
// Element to add the positionFixedClass to.
58-
positionFixedSelector?: string | null
59-
// Fixed position class to add to make sidebar fixed after scrolling
60-
// down past the fixedSidebarOffset.
61-
positionFixedClass?: string
62-
// fixedSidebarOffset can be any number but by default is set
63-
// to auto which sets the fixedSidebarOffset to the sidebar
64-
// element's offsetTop from the top of the document on init.
65-
fixedSidebarOffset?: 'auto' | number
66-
// includeHtml can be set to true to include the HTML markup from the
67-
// heading node instead of just including the innerText.
68-
includeHtml?: boolean
69-
// includeTitleTags automatically sets the html title tag of the link
70-
// to match the title. This can be useful for SEO purposes or
71-
// when truncating titles.
72-
includeTitleTags?: boolean
73-
// onclick function to apply to all links in toc. will be called with
74-
// the event as the first parameter; and this can be used to stop // propagation; prevent default or perform action
75-
onClick?: (e: MouseEvent) => void
76-
// orderedList can be set to false to generate unordered lists (ul)
77-
// instead of ordered lists (ol)
78-
orderedList?: boolean
79-
// If there is a fixed article scroll container; set to calculate titles' offset
80-
scrollContainer?: string | null
81-
// prevent ToC DOM rendering if it's already rendered by an external system
82-
skipRendering?: boolean
83-
// Optional callback to change heading labels.
84-
// For example it can be used to cut down and put ellipses on multiline headings you deem too long.
85-
// Called each time a heading is parsed. Expects a string in return, the modified label to display.
86-
headingLabelCallback?: (headingLabel: string) => string
87-
// ignore headings that are hidden in DOM
88-
ignoreHiddenElements?: boolean
89-
// Optional callback to modify properties of parsed headings.
90-
// The heading element is passed in node parameter and information parsed by default parser is provided in obj parameter.
91-
// Function has to return the same or modified obj.
92-
// The heading will be excluded from TOC if nothing is returned.
93-
headingObjectCallback?: (obj: object, node: HTMLElement) => object | void
94-
// Set the base path, useful if you use a `base` tag in `head`.
95-
basePath?: string
96-
// Only takes affect when `tocSelector` is scrolling,
97-
// keep the toc scroll position in sync with the content.
98-
disableTocScrollSync?: boolean
99-
// Offset for the toc scroll (top) position when scrolling the page.
100-
// Only effective if `disableTocScrollSync` is false.
101-
tocScrollOffset?: number
102-
// Enable the URL hash to update with the proper heading ID as
103-
// a user scrolls the page.
104-
enableUrlHashUpdateOnScroll?: boolean
105-
}
106-
107-
/**
108-
* Initialize tocbot with an options object.
109-
* @see https://github.com/tscanlin/tocbot#init
110-
*/
111-
function init(options?: IStaticOptions): void
112-
/**
113-
* Destroy tocbot and remove event listeners.
114-
* @see https://github.com/tscanlin/tocbot#destroy
115-
*/
116-
function destroy(): void
117-
/**
118-
* Refresh tocbot if the document changes and it needs to be rebuilt.
119-
* @see https://github.com/tscanlin/tocbot#refresh
120-
*/
121-
function refresh(options?: IStaticOptions): void
122-
}
1+
export = tocbot
2+
export as namespace tocbot
3+
4+
declare namespace tocbot {
5+
/**
6+
* @see https://github.com/tscanlin/tocbot#options
7+
*/
8+
interface IStaticOptions {
9+
// Where to render the table of contents.
10+
tocSelector?: string
11+
// Where to grab the headings to build the table of contents.
12+
contentSelector?: string
13+
// Which headings to grab inside of the contentSelector element.
14+
headingSelector?: string
15+
// Headings that match the ignoreSelector will be skipped.
16+
ignoreSelector?: string
17+
// For headings inside relative or absolute positioned containers within content.
18+
hasInnerContainers?: boolean
19+
// Main class to add to links.
20+
linkClass?: string
21+
// Extra classes to add to links.
22+
extraLinkClasses?: string
23+
// Class to add to active links // the link corresponding to the top most heading on the page.
24+
activeLinkClass?: string
25+
// Main class to add to lists.
26+
listClass?: string
27+
// Extra classes to add to lists.
28+
extraListClasses?: string
29+
// Class that gets added when a list should be collapsed.
30+
isCollapsedClass?: string
31+
// Class that gets added when a list should be able
32+
// to be collapsed but isn't necessarily collapsed.
33+
collapsibleClass?: string
34+
// Class to add to list items.
35+
listItemClass?: string
36+
// Class to add to active list items.
37+
activeListItemClass?: string
38+
// How many heading levels should not be collapsed.
39+
// For example; number 6 will show everything since
40+
// there are only 6 heading levels and number 0 will collapse them all.
41+
// The sections that are hidden will open
42+
// and close as you scroll to headings within them.
43+
collapseDepth?: number
44+
// Smooth scrolling enabled.
45+
scrollSmooth?: boolean
46+
// Smooth scroll duration.
47+
scrollSmoothDuration?: number
48+
// Smooth scroll offset.
49+
scrollSmoothOffset?: number
50+
// Callback for scroll end.
51+
scrollEndCallback?(e: WheelEvent): void
52+
// Headings offset between the headings and the top of the document (this is meant for minor adjustments).
53+
headingsOffset?: number
54+
// Timeout between events firing to make sure it's
55+
// not too rapid (for performance reasons).
56+
throttleTimeout?: number
57+
// Element to add the positionFixedClass to.
58+
positionFixedSelector?: string | null
59+
// Fixed position class to add to make sidebar fixed after scrolling
60+
// down past the fixedSidebarOffset.
61+
positionFixedClass?: string
62+
// fixedSidebarOffset can be any number but by default is set
63+
// to auto which sets the fixedSidebarOffset to the sidebar
64+
// element's offsetTop from the top of the document on init.
65+
fixedSidebarOffset?: "auto" | number
66+
// includeHtml can be set to true to include the HTML markup from the
67+
// heading node instead of just including the innerText.
68+
includeHtml?: boolean
69+
// includeTitleTags automatically sets the html title tag of the link
70+
// to match the title. This can be useful for SEO purposes or
71+
// when truncating titles.
72+
includeTitleTags?: boolean
73+
// onclick function to apply to all links in toc. will be called with
74+
// the event as the first parameter; and this can be used to stop // propagation; prevent default or perform action
75+
onClick?: (e: MouseEvent) => void
76+
// orderedList can be set to false to generate unordered lists (ul)
77+
// instead of ordered lists (ol)
78+
orderedList?: boolean
79+
// If there is a fixed article scroll container; set to calculate titles' offset
80+
scrollContainer?: string | null
81+
// prevent ToC DOM rendering if it's already rendered by an external system
82+
skipRendering?: boolean
83+
// Optional callback to change heading labels.
84+
// For example it can be used to cut down and put ellipses on multiline headings you deem too long.
85+
// Called each time a heading is parsed. Expects a string in return, the modified label to display.
86+
headingLabelCallback?: (headingLabel: string) => string
87+
// ignore headings that are hidden in DOM
88+
ignoreHiddenElements?: boolean
89+
// Optional callback to modify properties of parsed headings.
90+
// The heading element is passed in node parameter and information parsed by default parser is provided in obj parameter.
91+
// Function has to return the same or modified obj.
92+
// The heading will be excluded from TOC if nothing is returned.
93+
headingObjectCallback?: (obj: object, node: HTMLElement) => object | void
94+
// Set the base path, useful if you use a `base` tag in `head`.
95+
basePath?: string
96+
// Only takes affect when `tocSelector` is scrolling,
97+
// keep the toc scroll position in sync with the content.
98+
disableTocScrollSync?: boolean
99+
// Offset for the toc scroll (top) position when scrolling the page.
100+
// Only effective if `disableTocScrollSync` is false.
101+
tocScrollOffset?: number
102+
// Enable the URL hash to update with the proper heading ID as
103+
// a user scrolls the page.
104+
enableUrlHashUpdateOnScroll?: boolean
105+
// Threshold for when bottom mode should be enabled to handle
106+
// highlighting links that cannot be scrolled to.
107+
bottomModeThreshold?: number
108+
}
109+
110+
/**
111+
* Initialize tocbot with an options object.
112+
* @see https://github.com/tscanlin/tocbot#init
113+
*/
114+
function init(options?: IStaticOptions): void
115+
/**
116+
* Destroy tocbot and remove event listeners.
117+
* @see https://github.com/tscanlin/tocbot#destroy
118+
*/
119+
function destroy(): void
120+
/**
121+
* Refresh tocbot if the document changes and it needs to be rebuilt.
122+
* @see https://github.com/tscanlin/tocbot#refresh
123+
*/
124+
function refresh(options?: IStaticOptions): void
125+
}

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { destroy, init, refresh } from './src/js/index-esm.js'
1+
import { destroy, init, refresh } from "./src/js/index-esm.js"
22
const tocbot = { destroy, init, refresh }
33

44
export { destroy, init, refresh }

index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { destroy, init, refresh } from './src/js/index-esm.js'
1+
import { destroy, init, refresh } from "./src/js/index-esm.js"
22
const tocbot = { destroy, init, refresh }
33

44
export { destroy, init, refresh }

next.config.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const assetPrefix = '/tocbot'
1+
const assetPrefix = "/tocbot"
22

33
export default {
44
assetPrefix,
@@ -7,7 +7,7 @@ export default {
77
return newConfig
88
},
99
exportPathMap: () => ({
10-
'/': { page: '/' },
11-
'/changelog': { page: '/changelog' }
12-
})
10+
"/": { page: "/" },
11+
"/changelog": { page: "/changelog" },
12+
}),
1313
}

0 commit comments

Comments
 (0)