mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-17 22:37:04 +08:00
fix: edgeless object creation events (#7206)
related to AFF-1154 upstream: https://github.com/toeverything/blocksuite/pull/7297
This commit is contained in:
@@ -15,13 +15,7 @@ import {
|
||||
PageEditor,
|
||||
} from '@blocksuite/presets';
|
||||
import type { Doc } from '@blocksuite/store';
|
||||
import {
|
||||
type DocMode,
|
||||
DocService,
|
||||
DocsService,
|
||||
useLiveData,
|
||||
useService,
|
||||
} from '@toeverything/infra';
|
||||
import { type DocMode, useLiveData, useService } from '@toeverything/infra';
|
||||
import React, {
|
||||
forwardRef,
|
||||
Fragment,
|
||||
@@ -36,7 +30,6 @@ import { PagePropertiesTable } from '../../affine/page-properties';
|
||||
import { AffinePageReference } from '../../affine/reference-link';
|
||||
import { BlocksuiteEditorJournalDocTitle } from './journal-doc-title';
|
||||
import {
|
||||
patchDocModeService,
|
||||
patchForSharedPage,
|
||||
patchNotificationService,
|
||||
patchPeekViewService,
|
||||
@@ -80,8 +73,6 @@ const usePatchSpecs = (page: Doc, shared: boolean, mode: DocMode) => {
|
||||
const [reactToLit, portals] = useLitPortalFactory();
|
||||
const peekViewService = useService(PeekViewService);
|
||||
const quickSearchService = useService(QuickSearchService);
|
||||
const docService = useService(DocService);
|
||||
const docsService = useService(DocsService);
|
||||
const referenceRenderer: ReferenceReactRenderer = useMemo(() => {
|
||||
return function customReference(reference) {
|
||||
const pageId = reference.delta.attributes?.reference?.pageId;
|
||||
@@ -110,14 +101,9 @@ const usePatchSpecs = (page: Doc, shared: boolean, mode: DocMode) => {
|
||||
if (shared) {
|
||||
patched = patchForSharedPage(patched);
|
||||
}
|
||||
if (!page.readonly) {
|
||||
patched = patchDocModeService(patched, docService, docsService);
|
||||
}
|
||||
return patched;
|
||||
}, [
|
||||
confirmModal,
|
||||
docService,
|
||||
docsService,
|
||||
page.readonly,
|
||||
peekViewService,
|
||||
quickSearchService,
|
||||
|
||||
@@ -10,7 +10,6 @@ import {
|
||||
AIEdgelessRootBlockSpec,
|
||||
AIPageRootBlockSpec,
|
||||
} from '@blocksuite/presets';
|
||||
import type { BlockModel } from '@blocksuite/store';
|
||||
|
||||
function customLoadFonts(service: RootService): void {
|
||||
if (runtimeConfig.isSelfHosted) {
|
||||
@@ -25,55 +24,26 @@ function customLoadFonts(service: RootService): void {
|
||||
}
|
||||
}
|
||||
|
||||
class CustomPageRootService extends PageRootService {
|
||||
override loadFonts(): void {
|
||||
customLoadFonts(this);
|
||||
}
|
||||
}
|
||||
function withAffineRootService(Service: typeof RootService) {
|
||||
return class extends Service {
|
||||
override loadFonts(): void {
|
||||
customLoadFonts(this);
|
||||
}
|
||||
|
||||
class CustomEdgelessRootService extends EdgelessRootService {
|
||||
override loadFonts(): void {
|
||||
customLoadFonts(this);
|
||||
}
|
||||
|
||||
override addElement<T = Record<string, unknown>>(type: string, props: T) {
|
||||
const res = super.addElement(type, props);
|
||||
mixpanel.track('WhiteboardObjectCreated', {
|
||||
page: 'whiteboard editor',
|
||||
module: 'whiteboard',
|
||||
segment: 'canvas',
|
||||
// control:
|
||||
type: 'whiteboard object',
|
||||
category: type,
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
override addBlock(
|
||||
flavour: string,
|
||||
props: Record<string, unknown>,
|
||||
parent?: string | BlockModel,
|
||||
parentIndex?: number
|
||||
) {
|
||||
const res = super.addBlock(flavour, props, parent, parentIndex);
|
||||
mixpanel.track('WhiteboardObjectCreated', {
|
||||
page: 'whiteboard editor',
|
||||
module: 'whiteboard',
|
||||
segment: 'canvas',
|
||||
// control:
|
||||
type: 'whiteboard object',
|
||||
category: flavour.split(':')[1], // affine:paragraph -> paragraph
|
||||
});
|
||||
return res;
|
||||
}
|
||||
telemetryService = {
|
||||
track: (event: string, data: Record<string, unknown>) => {
|
||||
mixpanel.track(event, data);
|
||||
},
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export const CustomPageRootBlockSpec: BlockSpec = {
|
||||
...AIPageRootBlockSpec,
|
||||
service: CustomPageRootService,
|
||||
service: withAffineRootService(PageRootService),
|
||||
};
|
||||
|
||||
export const CustomEdgelessRootBlockSpec: BlockSpec = {
|
||||
...AIEdgelessRootBlockSpec,
|
||||
service: CustomEdgelessRootService,
|
||||
service: withAffineRootService(EdgelessRootService),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user