mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-21 20:16:26 +08:00
cb550b7b21
<!-- 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 -->
64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
import {
|
|
type ViewExtensionContext,
|
|
ViewExtensionProvider,
|
|
} from '@blocksuite/affine-ext-loader';
|
|
import { SlashMenuConfigExtension } from '@blocksuite/affine-widget-slash-menu';
|
|
import {
|
|
BlockViewExtension,
|
|
FlavourExtension,
|
|
WidgetViewExtension,
|
|
} from '@blocksuite/std';
|
|
import { literal, unsafeStatic } from 'lit/static-html.js';
|
|
|
|
import { getCodeClipboardExtensions } from './clipboard/index.js';
|
|
import { CodeBlockConfigExtension } from './code-block-config';
|
|
import {
|
|
CodeBlockInlineManagerExtension,
|
|
CodeBlockUnitSpecExtension,
|
|
} from './code-block-inline.js';
|
|
import { CodeBlockHighlighter } from './code-block-service.js';
|
|
import { CodeKeymapExtension } from './code-keymap.js';
|
|
import { AFFINE_CODE_TOOLBAR_WIDGET } from './code-toolbar/index.js';
|
|
import { codeSlashMenuConfig } from './configs/slash-menu.js';
|
|
import { effects } from './effects.js';
|
|
|
|
const codeToolbarWidget = WidgetViewExtension(
|
|
'affine:code',
|
|
AFFINE_CODE_TOOLBAR_WIDGET,
|
|
literal`${unsafeStatic(AFFINE_CODE_TOOLBAR_WIDGET)}`
|
|
);
|
|
|
|
export class CodeBlockViewExtension extends ViewExtensionProvider {
|
|
override name = 'affine-code-block';
|
|
|
|
override effect() {
|
|
super.effect();
|
|
effects();
|
|
}
|
|
|
|
override setup(context: ViewExtensionContext) {
|
|
super.setup(context);
|
|
context.register([
|
|
FlavourExtension('affine:code'),
|
|
CodeBlockHighlighter,
|
|
BlockViewExtension('affine:code', literal`affine-code`),
|
|
SlashMenuConfigExtension('affine:code', codeSlashMenuConfig),
|
|
CodeKeymapExtension,
|
|
...getCodeClipboardExtensions(),
|
|
]);
|
|
context.register([
|
|
CodeBlockInlineManagerExtension,
|
|
CodeBlockUnitSpecExtension,
|
|
]);
|
|
if (!this.isMobile(context.scope)) {
|
|
context.register(codeToolbarWidget);
|
|
} else {
|
|
context.register(
|
|
CodeBlockConfigExtension({
|
|
showLineNumbers: false,
|
|
})
|
|
);
|
|
}
|
|
}
|
|
}
|