fundon
2024-09-20 03:42:08 +00:00
parent e3e15c6134
commit 661594aec8
4 changed files with 71 additions and 30 deletions
@@ -1,7 +1,9 @@
import { toURLSearchParams } from '@affine/core/utils';
import { Unreachable } from '@affine/env/constant';
import type { DocMode } from '@blocksuite/blocks';
import type { ReferenceParams } from '@blocksuite/blocks';
import { Entity, LiveData } from '@toeverything/infra';
import { type To } from 'history';
import { omit } from 'lodash-es';
import { nanoid } from 'nanoid';
import type { WorkbenchNewTabHandler } from '../services/workbench-new-tab-handler';
@@ -122,14 +124,7 @@ export class Workbench extends Entity {
}
openDoc(
id:
| string
| {
docId: string;
mode?: DocMode;
blockIds?: string[];
elementIds?: string[];
},
id: string | ({ docId: string } & ReferenceParams),
options?: WorkbenchOpenOptions
) {
const isString = typeof id === 'string';
@@ -137,12 +132,10 @@ export class Workbench extends Entity {
let query = '';
if (!isString) {
const { mode, blockIds, elementIds } = id;
const search = new URLSearchParams();
if (mode) search.set('mode', mode);
if (blockIds?.length) search.set('blockIds', blockIds.join(','));
if (elementIds?.length) search.set('elementIds', elementIds.join(','));
if (search.size > 0) query = `?${search.toString()}`;
const search = toURLSearchParams(omit(id, ['docId']));
if (search?.size) {
query = `?${search.toString()}`;
}
}
this.open(`/${docId}${query}`, options);