refactor(editor): extract mobile extension builder (#12239)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a new mobile view extension that activates mobile-specific UI features based on the runtime environment. - Automatically enables mobile keyboard toolbar and linked document menu features in mobile contexts. - **Improvements** - Simplified code and paragraph block configurations on mobile, including disabling line numbers and adjusting placeholders. - Enhanced configuration chaining to include mobile-specific settings by default. - Improved extension registration flow with method chaining support. - **Refactor** - Removed deprecated mobile patch classes and configurations, consolidating mobile logic into dedicated extensions. - Streamlined mobile-related code for better maintainability and performance. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
import { literal, unsafeStatic } from 'lit/static-html.js';
|
||||
|
||||
import { getCodeClipboardExtensions } from './clipboard/index.js';
|
||||
import { CodeBlockConfigExtension } from './code-block-config';
|
||||
import {
|
||||
CodeBlockInlineManagerExtension,
|
||||
CodeBlockUnitSpecExtension,
|
||||
@@ -21,7 +22,7 @@ import { AFFINE_CODE_TOOLBAR_WIDGET } from './code-toolbar/index.js';
|
||||
import { codeSlashMenuConfig } from './configs/slash-menu.js';
|
||||
import { effects } from './effects.js';
|
||||
|
||||
export const codeToolbarWidget = WidgetViewExtension(
|
||||
const codeToolbarWidget = WidgetViewExtension(
|
||||
'affine:code',
|
||||
AFFINE_CODE_TOOLBAR_WIDGET,
|
||||
literal`${unsafeStatic(AFFINE_CODE_TOOLBAR_WIDGET)}`
|
||||
@@ -51,6 +52,12 @@ export class CodeBlockViewExtension extends ViewExtensionProvider {
|
||||
]);
|
||||
if (!this.isMobile(context.scope)) {
|
||||
context.register(codeToolbarWidget);
|
||||
} else {
|
||||
context.register(
|
||||
CodeBlockConfigExtension({
|
||||
showLineNumbers: false,
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ export type Context<Scope extends string> = {
|
||||
/** The scope this context is associated with */
|
||||
scope: Scope;
|
||||
/** Function to register one or more extensions */
|
||||
register(extensions: ExtensionType[] | ExtensionType): void;
|
||||
register(extensions: ExtensionType[] | ExtensionType): Context<Scope>;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -75,11 +75,14 @@ export class ExtensionManager<Scope extends string> {
|
||||
|
||||
/** @internal */
|
||||
private readonly _getContextByScope = (scope: Scope): Context<Scope> => {
|
||||
return {
|
||||
const context: Context<Scope> = {
|
||||
scope,
|
||||
register: (extensions: ExtensionType[] | ExtensionType) =>
|
||||
this._registerToScope(scope, extensions),
|
||||
register: (extensions: ExtensionType[] | ExtensionType) => {
|
||||
this._registerToScope(scope, extensions);
|
||||
return context;
|
||||
},
|
||||
};
|
||||
return context;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user