mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-03-24 16:18:39 +08:00
chore(editor): add track event for latex (#12541)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Enhanced telemetry tracking for LaTeX and equation creation actions, capturing detailed context such as editor mode and location within the app. - **Chores** - Expanded telemetry event types to include LaTeX-specific actions for improved analytics and observability. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
import {
|
||||
DocModeProvider,
|
||||
TelemetryProvider,
|
||||
} from '@blocksuite/affine-shared/services';
|
||||
import type { Command, TextSelection } from '@blocksuite/std';
|
||||
|
||||
export const insertInlineLatex: Command<{
|
||||
@@ -37,6 +41,21 @@ export const insertInlineLatex: Command<{
|
||||
length: 1,
|
||||
});
|
||||
|
||||
const mode = ctx.std.get(DocModeProvider).getEditorMode() ?? 'page';
|
||||
const ifEdgelessText = blockComponent.closest('affine-edgeless-text');
|
||||
ctx.std.getOptional(TelemetryProvider)?.track('Latex', {
|
||||
from:
|
||||
mode === 'page'
|
||||
? 'doc'
|
||||
: ifEdgelessText
|
||||
? 'edgeless text'
|
||||
: 'edgeless note',
|
||||
page: mode === 'page' ? 'doc' : 'edgeless',
|
||||
segment: mode === 'page' ? 'doc' : 'whiteboard',
|
||||
module: 'inline equation',
|
||||
control: 'create inline equation',
|
||||
});
|
||||
|
||||
inlineEditor
|
||||
.waitForUpdate()
|
||||
.then(async () => {
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
import {
|
||||
DocModeProvider,
|
||||
TelemetryProvider,
|
||||
} from '@blocksuite/affine-shared/services';
|
||||
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
||||
import type { BlockComponent } from '@blocksuite/std';
|
||||
import { InlineMarkdownExtension } from '@blocksuite/std/inline';
|
||||
@@ -14,6 +18,20 @@ export const LatexExtension = InlineMarkdownExtension<AffineTextAttributes>({
|
||||
const inlinePrefix = match.groups['inlinePrefix'];
|
||||
const blockPrefix = match.groups['blockPrefix'];
|
||||
|
||||
if (!inlineEditor.rootElement) return;
|
||||
const blockComponent =
|
||||
inlineEditor.rootElement.closest<BlockComponent>('[data-block-id]');
|
||||
if (!blockComponent) return;
|
||||
|
||||
const doc = blockComponent.store;
|
||||
const std = blockComponent.std;
|
||||
const parentComponent = blockComponent.parentComponent;
|
||||
if (!parentComponent) return;
|
||||
const index = parentComponent.model.children.indexOf(blockComponent.model);
|
||||
if (index === -1) return;
|
||||
const mode = std.get(DocModeProvider).getEditorMode() ?? 'page';
|
||||
const ifEdgelessText = blockComponent.closest('affine-edgeless-text');
|
||||
|
||||
if (blockPrefix === '$$$$') {
|
||||
inlineEditor.insertText(
|
||||
{
|
||||
@@ -29,20 +47,6 @@ export const LatexExtension = InlineMarkdownExtension<AffineTextAttributes>({
|
||||
|
||||
undoManager.stopCapturing();
|
||||
|
||||
if (!inlineEditor.rootElement) return;
|
||||
const blockComponent =
|
||||
inlineEditor.rootElement.closest<BlockComponent>('[data-block-id]');
|
||||
if (!blockComponent) return;
|
||||
|
||||
const doc = blockComponent.store;
|
||||
const parentComponent = blockComponent.parentComponent;
|
||||
if (!parentComponent) return;
|
||||
|
||||
const index = parentComponent.model.children.indexOf(
|
||||
blockComponent.model
|
||||
);
|
||||
if (index === -1) return;
|
||||
|
||||
inlineEditor.deleteText({
|
||||
index: inlineRange.index - 4,
|
||||
length: 5,
|
||||
@@ -67,6 +71,19 @@ export const LatexExtension = InlineMarkdownExtension<AffineTextAttributes>({
|
||||
})
|
||||
.catch(console.error);
|
||||
|
||||
std.getOptional(TelemetryProvider)?.track('Latex', {
|
||||
from:
|
||||
mode === 'page'
|
||||
? 'doc'
|
||||
: ifEdgelessText
|
||||
? 'edgeless text'
|
||||
: 'edgeless note',
|
||||
page: mode === 'page' ? 'doc' : 'edgeless',
|
||||
segment: mode === 'page' ? 'doc' : 'whiteboard',
|
||||
module: 'equation',
|
||||
control: 'create equation',
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -124,6 +141,19 @@ export const LatexExtension = InlineMarkdownExtension<AffineTextAttributes>({
|
||||
})
|
||||
.catch(console.error);
|
||||
|
||||
std.getOptional(TelemetryProvider)?.track('Latex', {
|
||||
from:
|
||||
mode === 'page'
|
||||
? 'doc'
|
||||
: ifEdgelessText
|
||||
? 'edgeless text'
|
||||
: 'edgeless note',
|
||||
page: mode === 'page' ? 'doc' : 'edgeless',
|
||||
segment: mode === 'page' ? 'doc' : 'whiteboard',
|
||||
module: 'inline equation',
|
||||
control: 'create inline equation',
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -169,5 +199,18 @@ export const LatexExtension = InlineMarkdownExtension<AffineTextAttributes>({
|
||||
index: startIndex + 1,
|
||||
length: 0,
|
||||
});
|
||||
|
||||
std.getOptional(TelemetryProvider)?.track('Latex', {
|
||||
from:
|
||||
mode === 'page'
|
||||
? 'doc'
|
||||
: ifEdgelessText
|
||||
? 'edgeless text'
|
||||
: 'edgeless note',
|
||||
page: mode === 'page' ? 'doc' : 'edgeless',
|
||||
segment: mode === 'page' ? 'doc' : 'whiteboard',
|
||||
module: 'inline equation',
|
||||
control: 'create inline equation',
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user