Skip to content

Commit

Permalink
chore(blocks): improve ParseDocUrlService type (#8334)
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Sep 13, 2024
1 parent 7a7929c commit 5032321
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
13 changes: 4 additions & 9 deletions packages/affine/shared/src/services/parse-url-service.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import type { DocMode } from '@blocksuite/affine-model';
import type { ReferenceParams } from '@blocksuite/affine-model';
import type { ExtensionType } from '@blocksuite/block-std';

import { createIdentifier } from '@blocksuite/global/di';

export interface ParseDocUrlService {
parseDocUrl: (url: string) =>
| {
docId: string;
blockIds?: string[];
elementIds?: string[];
mode?: DocMode;
}
| undefined;
parseDocUrl: (
url: string
) => ({ docId: string } & ReferenceParams) | undefined;
}

export const ParseDocUrlProvider =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ export const insertLinkByQuickSearchCommand: Command<
}

const insertedLinkType = quickSearchService.openQuickSearch().then(result => {
if (!result) return null;

// add linked doc
if (result && 'docId' in result) {
if ('docId' in result) {
std.command.exec('insertEmbedLinkedDoc', {
docId: result.docId,
params: result.params,
Expand All @@ -26,7 +28,7 @@ export const insertLinkByQuickSearchCommand: Command<
}

// add normal link;
if (result && 'userInput' in result) {
if ('userInput' in result) {
std.command.exec('insertBookmark', { url: result.externalUrl });
return {
flavour: 'affine:bookmark',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ export const buildLinkDenseMenu: DenseMenuBuilder = edgeless => ({

insertedLinkType
?.then(type => {
if (!type) return;
const flavour = type?.flavour;
if (!flavour) return;

edgeless.std
.getOptional(TelemetryProvider)
?.track('CanvasElementAdded', {
control: 'toolbar:general',
page: 'whiteboard editor',
module: 'toolbar',
type: type.flavour?.split(':')[1],
type: flavour.split(':')[1],
});
})
.catch(console.error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export class EdgelessLinkToolButton extends QuickToolMixin(LitElement) {
);
insertedLinkType
?.then(type => {
if (!type) return;
const flavour = type?.flavour;
if (!flavour) return;

this.edgeless.std
.getOptional(TelemetryProvider)
Expand All @@ -31,7 +32,7 @@ export class EdgelessLinkToolButton extends QuickToolMixin(LitElement) {
page: 'whiteboard editor',
module: 'toolbar',
segment: 'toolbar',
type: type.flavour?.split(':')[1],
type: flavour.split(':')[1],
});

this.edgeless.std
Expand All @@ -41,7 +42,7 @@ export class EdgelessLinkToolButton extends QuickToolMixin(LitElement) {
page: 'whiteboard editor',
module: 'edgeless toolbar',
segment: 'whiteboard',
type: type.flavour?.split(':')[1],
type: flavour.split(':')[1],
other: 'existing doc',
});
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,16 @@ export class EdgelessNoteMenu extends EdgelessToolbarToolMixin(LitElement) {

insertedLinkType
?.then(type => {
if (!type) return;
const flavour = type?.flavour;
if (!flavour) return;

this.edgeless.std
.getOptional(TelemetryProvider)
?.track('CanvasElementAdded', {
control: 'toolbar:general',
page: 'whiteboard editor',
module: 'toolbar',
type: type.flavour?.split(':')[1],
type: flavour.split(':')[1],
});
})
.catch(console.error);
Expand Down
5 changes: 3 additions & 2 deletions packages/blocks/src/root-block/edgeless/edgeless-keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ export class EdgelessPageKeyboardManager extends PageKeyboardManager {

insertedLinkType
?.then(type => {
if (!type) return;
const flavour = type?.flavour;
if (!flavour) return;

rootComponent.std
.getOptional(TelemetryProvider)
Expand All @@ -198,7 +199,7 @@ export class EdgelessPageKeyboardManager extends PageKeyboardManager {
page: 'whiteboard editor',
module: 'toolbar',
segment: 'toolbar',
type: type.flavour?.split(':')[1],
type: flavour.split(':')[1],
});
})
.catch(console.error);
Expand Down

0 comments on commit 5032321

Please sign in to comment.