mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-12 23:56:36 +08:00
feat(editor): support preview mode in code block (#11805)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a preview mode for code blocks, allowing users to toggle between code and rendered previews (e.g., HTML output) directly within the editor. - Added a preview toggle button to the code block toolbar for supported languages. - Enabled dynamic rendering of code block previews using a shared WebContainer, allowing live HTML previews in an embedded iframe. - Added HTML preview support with loading and error states for enhanced user feedback. - Integrated the preview feature as a view extension provider for seamless framework support. - **Bug Fixes** - Improved toolbar layout and button alignment for a cleaner user interface. - **Tests** - Added end-to-end tests to verify the new code block preview functionality and language switching behavior. - **Chores** - Updated development server configuration to include enhanced security headers. - Added a new runtime dependency for WebContainer support. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import type { CodeBlockModel } from '@blocksuite/affine-model';
|
||||
import { createIdentifier } from '@blocksuite/global/di';
|
||||
import type { ExtensionType } from '@blocksuite/store';
|
||||
import type { HTMLTemplateResult } from 'lit';
|
||||
|
||||
export type CodeBlockPreviewRenderer = (
|
||||
model: CodeBlockModel
|
||||
) => HTMLTemplateResult | null;
|
||||
|
||||
export type CodeBlockPreviewContext = {
|
||||
renderer: CodeBlockPreviewRenderer;
|
||||
lang: string;
|
||||
};
|
||||
|
||||
export const CodeBlockPreviewIdentifier =
|
||||
createIdentifier<CodeBlockPreviewContext>('CodeBlockPreview');
|
||||
|
||||
export function CodeBlockPreviewExtension(
|
||||
lang: string,
|
||||
renderer: CodeBlockPreviewRenderer
|
||||
): ExtensionType {
|
||||
return {
|
||||
setup: di => {
|
||||
di.addImpl(CodeBlockPreviewIdentifier(lang), { renderer, lang });
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user