mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-19 23:37:15 +08:00
refactor(editor): improve implementation of lit adapter (#12101)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Improved mobile experience by disabling certain toolbars and slash menu features on mobile devices. - Introduced new modular extension classes for editor and view customization, enabling more flexible configuration of themes, AI features, and editor enhancements. - Added clipboard adapter configurations for a wide range of data types, improving clipboard compatibility. - Added a new theme extension specifically for preview scenarios. - Provided new hooks for block scope management in document modules. - **Refactor** - Streamlined editor extension setup, consolidating options and reducing complexity for better maintainability. - Reorganized mobile-specific extension exports for clearer usage. - Refined React-to-Lit rendering API by introducing a typed alias and updating related function signatures. - Simplified extension registration by splitting monolithic view extension into separate common and editor view extensions. - **Bug Fixes** - Corrected naming inconsistencies in internal effect tracking. - **Chores** - Updated type exports and documentation comments for improved clarity and consistency. - Removed unused or redundant exports and functions to clean up the codebase. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -208,21 +208,21 @@ it('should effect only run once', () => {
|
||||
|
||||
const manager = new ViewExtensionManager([ViewExt1]);
|
||||
|
||||
expect(ViewExt1.effectRunned).toBe(false);
|
||||
expect(ViewExt2.effectRunned).toBe(false);
|
||||
expect(ViewExt1.effectRan).toBe(false);
|
||||
expect(ViewExt2.effectRan).toBe(false);
|
||||
|
||||
manager.get('page');
|
||||
|
||||
expect(ViewExt1.effectRunned).toBe(true);
|
||||
expect(ViewExt2.effectRunned).toBe(false);
|
||||
expect(ViewExt1.effectRan).toBe(true);
|
||||
expect(ViewExt2.effectRan).toBe(false);
|
||||
|
||||
expect(effect1).toHaveBeenCalledTimes(1);
|
||||
expect(effect2).toHaveBeenCalledTimes(0);
|
||||
|
||||
manager.get('edgeless');
|
||||
|
||||
expect(ViewExt1.effectRunned).toBe(true);
|
||||
expect(ViewExt2.effectRunned).toBe(false);
|
||||
expect(ViewExt1.effectRan).toBe(true);
|
||||
expect(ViewExt2.effectRan).toBe(false);
|
||||
|
||||
expect(effect1).toHaveBeenCalledTimes(1);
|
||||
expect(effect2).toHaveBeenCalledTimes(0);
|
||||
|
||||
@@ -64,7 +64,7 @@ export class ViewExtensionProvider<
|
||||
* Static flag to ensure effect is only run once per provider class
|
||||
* @internal
|
||||
*/
|
||||
static effectRunned = false;
|
||||
static effectRan = false;
|
||||
|
||||
/**
|
||||
* Override this method to implement one-time initialization logic for the provider.
|
||||
@@ -94,11 +94,29 @@ export class ViewExtensionProvider<
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if the scope is preview
|
||||
* @param scope - The scope to check
|
||||
* @returns True if the scope is preview, false otherwise
|
||||
*/
|
||||
isPreview = (scope: ViewScope) => {
|
||||
return scope === 'preview-page' || scope === 'preview-edgeless';
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if the scope is mobile
|
||||
* @param scope - The scope to check
|
||||
* @returns True if the scope is mobile, false otherwise
|
||||
*/
|
||||
isMobile = (scope: ViewScope) => {
|
||||
return scope === 'mobile-page' || scope === 'mobile-edgeless';
|
||||
};
|
||||
|
||||
override setup(context: ViewExtensionContext, options?: Options) {
|
||||
super.setup(context, options);
|
||||
const constructer = this.constructor as typeof ViewExtensionProvider;
|
||||
if (!constructer.effectRunned) {
|
||||
constructer.effectRunned = true;
|
||||
const constructor = this.constructor as typeof ViewExtensionProvider;
|
||||
if (!constructor.effectRan) {
|
||||
constructor.effectRan = true;
|
||||
this.effect();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user