Skip to content

Commit

Permalink
refactor: move 'restoreScrollPosition' to the 'features' option
Browse files Browse the repository at this point in the history
  • Loading branch information
BugCreators authored and qq15725 committed Apr 10, 2024
1 parent 0a09e9a commit 313b131
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/clone-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function appendChildNode<T extends Node>(

const childCloned = await cloneNode(child, context)

if (context.restoreScrollPosition) {
if (context.isEnable('restoreScrollPosition')) {
restoreScrollPosition(node, childCloned)
}

Expand Down
4 changes: 3 additions & 1 deletion src/create-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export async function createContext<T extends Node>(node: T, options?: Options &
onCreateForeignObjectSvg: null,
includeStyleProperties: null,
autoDestruct: false,
restoreScrollPosition: false,
...options,

// InternalContext
Expand Down Expand Up @@ -114,6 +113,9 @@ export async function createContext<T extends Node>(node: T, options?: Options &

features,
isEnable: (key: string): boolean => {
if (key === 'restoreScrollPosition') {
return typeof features === 'boolean' ? false : (features as any)[key] ?? false
}
if (typeof features === 'boolean') {
return features
}
Expand Down
14 changes: 7 additions & 7 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ export interface Options {
* default: true
*/
fixSvgXmlDecode?: boolean

/**
* Render scrolled children with scrolled content
*
* default: false
*/
restoreScrollPosition?: boolean
}

/**
Expand Down Expand Up @@ -208,11 +215,4 @@ export interface Options {
* This can be useful for performance-critical scenarios.
*/
includeStyleProperties?: string[] | null

/**
* Render scrolled children with scrolled content
*
* default: false
*/
restoreScrollPosition?: boolean
}

0 comments on commit 313b131

Please sign in to comment.