mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
chore(core): track copy block to link action (#8056)
part of [BS-1254](https://linear.app/affine-design/issue/BS-1254/增加-block-reference-的埋点)
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
||||
generateUrl,
|
||||
type UseSharingUrl,
|
||||
} from '@affine/core/hooks/affine/use-share-url';
|
||||
import { track } from '@affine/core/mixpanel';
|
||||
import { getAffineCloudBaseUrl } from '@affine/core/modules/cloud/services/fetch';
|
||||
import { EditorService } from '@affine/core/modules/editor';
|
||||
import { I18n } from '@affine/i18n';
|
||||
@@ -71,6 +72,8 @@ function createCopyLinkToBlockMenuItem(
|
||||
const str = generateUrl(options);
|
||||
if (!str) return;
|
||||
|
||||
track.doc.editor.toolbar.copyBlockToLink({ type: model.flavour });
|
||||
|
||||
navigator.clipboard
|
||||
.writeText(str)
|
||||
.then(() => {
|
||||
|
||||
@@ -3,10 +3,15 @@ import {
|
||||
generateUrl,
|
||||
type UseSharingUrl,
|
||||
} from '@affine/core/hooks/affine/use-share-url';
|
||||
import { track } from '@affine/core/mixpanel';
|
||||
import { getAffineCloudBaseUrl } from '@affine/core/modules/cloud/services/fetch';
|
||||
import { EditorService } from '@affine/core/modules/editor';
|
||||
import { I18n } from '@affine/i18n';
|
||||
import type { MenuItemGroup } from '@blocksuite/affine-components/toolbar';
|
||||
import type {
|
||||
GfxBlockElementModel,
|
||||
GfxPrimitiveElementModel,
|
||||
} from '@blocksuite/block-std/gfx';
|
||||
import type { MenuContext } from '@blocksuite/blocks';
|
||||
import { LinkIcon } from '@blocksuite/icons/lit';
|
||||
import type { FrameworkProvider } from '@toeverything/infra';
|
||||
@@ -74,27 +79,42 @@ function createCopyLinkToBlockMenuItem(
|
||||
...item,
|
||||
action: (ctx: MenuContext) => {
|
||||
const baseUrl = getAffineCloudBaseUrl();
|
||||
if (!baseUrl) return;
|
||||
if (!baseUrl) {
|
||||
ctx.close();
|
||||
return;
|
||||
}
|
||||
|
||||
const { editor } = framework.get(EditorService);
|
||||
const mode = editor.mode$.value;
|
||||
const pageId = editor.doc.id;
|
||||
const workspaceId = editor.doc.workspace.id;
|
||||
const options: UseSharingUrl = { workspaceId, pageId, shareMode: mode };
|
||||
let type = '';
|
||||
|
||||
if (mode === 'page') {
|
||||
// maybe multiple blocks
|
||||
const blockIds = ctx.selectedBlockModels.map(model => model.id);
|
||||
options.blockIds = blockIds;
|
||||
type = ctx.selectedBlockModels[0].flavour;
|
||||
} else if (mode === 'edgeless' && ctx.firstElement) {
|
||||
// single block/element
|
||||
const id = ctx.firstElement.id;
|
||||
const key = ctx.isElement() ? 'element' : 'block';
|
||||
options[`${key}Ids`] = [id];
|
||||
if (ctx.isElement()) {
|
||||
options.elementIds = [id];
|
||||
type = (ctx.firstElement as GfxPrimitiveElementModel).type;
|
||||
} else {
|
||||
options.blockIds = [id];
|
||||
type = (ctx.firstElement as GfxBlockElementModel).flavour;
|
||||
}
|
||||
}
|
||||
|
||||
const str = generateUrl(options);
|
||||
if (!str) return;
|
||||
if (!str) {
|
||||
ctx.close();
|
||||
return;
|
||||
}
|
||||
|
||||
track.doc.editor.toolbar.copyBlockToLink({ type });
|
||||
|
||||
navigator.clipboard
|
||||
.writeText(str)
|
||||
@@ -104,6 +124,8 @@ function createCopyLinkToBlockMenuItem(
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
|
||||
ctx.close();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -44,7 +44,8 @@ type DocEvents =
|
||||
| 'restoreDoc'
|
||||
| 'switchPageMode'
|
||||
| 'openDocOptionsMenu'
|
||||
| 'openDocInfo';
|
||||
| 'openDocInfo'
|
||||
| 'copyBlockToLink';
|
||||
type EditorEvents = 'bold' | 'italic' | 'underline' | 'strikeThrough';
|
||||
// END SECTION
|
||||
|
||||
@@ -265,6 +266,7 @@ const PageEvents = {
|
||||
atMenu: ['linkDoc'],
|
||||
formatToolbar: ['bold'],
|
||||
pageRef: ['navigate'],
|
||||
toolbar: ['copyBlockToLink'],
|
||||
},
|
||||
inlineDocInfo: {
|
||||
$: ['toggle'],
|
||||
@@ -382,6 +384,9 @@ export type EventArgs = {
|
||||
type: 'default' | 'doc' | 'whiteboard' | 'block' | 'element';
|
||||
};
|
||||
export: { type: string };
|
||||
copyBlockToLink: {
|
||||
type: string;
|
||||
};
|
||||
};
|
||||
|
||||
// for type checking
|
||||
|
||||
Reference in New Issue
Block a user