From 313b1317ec18c9b6945726e7f55bb1b055d6bd8d Mon Sep 17 00:00:00 2001 From: BugCreators <502461775@qq.com> Date: Wed, 10 Apr 2024 17:24:42 +0800 Subject: [PATCH] refactor: move 'restoreScrollPosition' to the 'features' option --- src/clone-node.ts | 2 +- src/create-context.ts | 4 +++- src/options.ts | 14 +++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/clone-node.ts b/src/clone-node.ts index 860f8cd..489d616 100644 --- a/src/clone-node.ts +++ b/src/clone-node.ts @@ -41,7 +41,7 @@ async function appendChildNode( const childCloned = await cloneNode(child, context) - if (context.restoreScrollPosition) { + if (context.isEnable('restoreScrollPosition')) { restoreScrollPosition(node, childCloned) } diff --git a/src/create-context.ts b/src/create-context.ts index 1a379f7..9970795 100644 --- a/src/create-context.ts +++ b/src/create-context.ts @@ -59,7 +59,6 @@ export async function createContext(node: T, options?: Options & onCreateForeignObjectSvg: null, includeStyleProperties: null, autoDestruct: false, - restoreScrollPosition: false, ...options, // InternalContext @@ -114,6 +113,9 @@ export async function createContext(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 } diff --git a/src/options.ts b/src/options.ts index 36cadd4..3ed06f0 100644 --- a/src/options.ts +++ b/src/options.ts @@ -166,6 +166,13 @@ export interface Options { * default: true */ fixSvgXmlDecode?: boolean + + /** + * Render scrolled children with scrolled content + * + * default: false + */ + restoreScrollPosition?: boolean } /** @@ -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 }