chore(editor): add event track for html preview (#12592)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Enhanced tracking for code block interactions, including language selection and preview toggling.
  - Improved error reporting for HTML block preview failures, providing better visibility into issues.
- **Bug Fixes**
  - Added explicit feedback and tracking when cross-origin isolation is not supported during code block preview setup.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Flrande
2025-05-28 10:08:19 +00:00
parent 9e5d132bd0
commit f610d7b8af
7 changed files with 63 additions and 3 deletions

View File

@@ -1,3 +1,4 @@
import track from '@affine/track';
import { CodeBlockPreviewExtension } from '@blocksuite/affine/blocks/code';
import { SignalWatcher, WithDisposable } from '@blocksuite/affine/global/lit';
import type { CodeBlockModel } from '@blocksuite/affine/model';
@@ -87,7 +88,13 @@ export class HTMLPreview extends SignalWatcher(WithDisposable(LitElement)) {
this.state = 'finish';
})
.catch(error => {
console.error('Failed to link WebContainer:', error);
const errorMessage = `Failed to link WebContainer: ${error}`;
console.error(errorMessage);
track.doc.editor.codeBlock.htmlBlockPreviewFailed({
type: errorMessage,
});
this.state = 'error';
});
}

View File

@@ -1,4 +1,5 @@
import { FeatureFlagService } from '@affine/core/modules/feature-flag';
import track from '@affine/track';
import {
type ViewExtensionContext,
ViewExtensionProvider,
@@ -39,7 +40,13 @@ export class CodeBlockPreviewViewExtension extends ViewExtensionProvider {
.value;
if (!flag) return;
if (!window.crossOriginIsolated) return;
if (!window.crossOriginIsolated) {
track.doc.editor.codeBlock.htmlBlockPreviewFailed({
type: 'cross-origin-isolated not supported',
});
return;
}
context.register(CodeBlockHtmlPreview);
}