Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(blocks): parse doc url with mode #8333

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/affine/shared/src/services/parse-url-service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { DocMode } from '@blocksuite/affine-model';
import type { ExtensionType } from '@blocksuite/block-std';

import { createIdentifier } from '@blocksuite/global/di';
Expand All @@ -8,6 +9,7 @@ export interface ParseDocUrlService {
docId: string;
blockIds?: string[];
elementIds?: string[];
mode?: DocMode;
}
| undefined;
}
Expand Down
7 changes: 6 additions & 1 deletion packages/blocks/src/database-block/columns/title/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,17 @@ export class HeaderAreaTextCellEditing extends BaseTextCell {
if (isValidUrl(text)) {
const std = this.std;
const result = std?.getOptional(ParseDocUrlProvider)?.parseDocUrl(text);
if (result && 'docId' in result) {
if (result) {
const text = ' ';
inlineEditor.insertText(inlineRange, text, {
reference: {
type: 'LinkedPage',
pageId: result.docId,
params: {
blockIds: result.blockIds,
elementIds: result.elementIds,
mode: result.mode,
},
},
});
inlineEditor.setInlineRange({
Expand Down
20 changes: 9 additions & 11 deletions packages/blocks/src/root-block/edgeless/clipboard/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import {
} from '../../../_common/consts.js';
import { ExportManager } from '../../../_common/export-manager/export-manager.js';
import { getRootByEditorHost } from '../../../_common/utils/query.js';
import { extractSearchParams } from '../../../_common/utils/url.js';
import { ClipboardAdapter } from '../../clipboard/adapter.js';
import { PageClipboard } from '../../clipboard/index.js';
import {
Expand Down Expand Up @@ -261,28 +260,27 @@ export class EdgelessClipboardController extends PageClipboard {

// try to interpret url as affine doc url
const parseDocUrlService = this.std.getOptional(ParseDocUrlProvider);
const doc = parseDocUrlService?.parseDocUrl(url);
const pageId = doc && 'docId' in doc ? doc.docId : undefined;
const docUrlInfo = parseDocUrlService?.parseDocUrl(url);
const options: Record<string, unknown> = {};

let flavour = 'affine:bookmark';
let style = BookmarkStyles[0];
let isLinkToNode = false;

if (pageId) {
options.pageId = pageId;
if (docUrlInfo) {
options.pageId = docUrlInfo.docId;
flavour = 'affine:embed-linked-doc';
style = 'vertical';

const extracted = extractSearchParams(url);

isLinkToNode = Boolean(
extracted?.params?.mode &&
(extracted.params.blockIds?.length ||
extracted.params.elementIds?.length)
docUrlInfo.blockIds?.length || docUrlInfo.elementIds?.length
);

Object.assign(options, extracted);
Object.assign(options, {
mode: docUrlInfo.mode,
blockIds: docUrlInfo.blockIds,
elementIds: docUrlInfo.elementIds,
});
} else {
options.url = url;

Expand Down
Loading