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: allow peek view to be closed by the caller && bump bs #8542

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: 1 addition & 1 deletion packages/common/env/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"type": "module",
"devDependencies": {
"@blocksuite/affine": "0.17.19",
"@blocksuite/affine": "0.0.0-canary-20241028080828",
"vitest": "2.1.1"
},
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@affine/debug": "workspace:*",
"@affine/env": "workspace:*",
"@affine/templates": "workspace:*",
"@blocksuite/affine": "0.17.19",
"@blocksuite/affine": "0.0.0-canary-20241028080828",
"@datastructures-js/binary-search-tree": "^5.3.2",
"foxact": "^0.2.33",
"fractional-indexing": "^3.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/apps/android/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@affine/component": "workspace:*",
"@affine/core": "workspace:*",
"@affine/i18n": "workspace:*",
"@blocksuite/affine": "0.17.19",
"@blocksuite/affine": "0.0.0-canary-20241028080828",
"@blocksuite/icons": "^2.1.67",
"@capacitor/android": "^6.1.2",
"@capacitor/core": "^6.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/apps/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@affine/core": "workspace:*",
"@affine/i18n": "workspace:*",
"@affine/native": "workspace:*",
"@blocksuite/affine": "0.17.19",
"@blocksuite/affine": "0.0.0-canary-20241028080828",
"@electron-forge/cli": "^7.3.0",
"@electron-forge/core": "^7.3.0",
"@electron-forge/core-utils": "^7.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/apps/ios/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@affine/component": "workspace:*",
"@affine/core": "workspace:*",
"@affine/i18n": "workspace:*",
"@blocksuite/affine": "0.17.19",
"@blocksuite/affine": "0.0.0-canary-20241028080828",
"@blocksuite/icons": "^2.1.67",
"@capacitor/app": "^6.0.1",
"@capacitor/browser": "^6.0.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/apps/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@affine/component": "workspace:*",
"@affine/core": "workspace:*",
"@affine/i18n": "workspace:*",
"@blocksuite/affine": "0.17.19",
"@blocksuite/affine": "0.0.0-canary-20241028080828",
"@blocksuite/icons": "^2.1.67",
"@sentry/react": "^8.0.0",
"react": "^18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"zod": "^3.22.4"
},
"devDependencies": {
"@blocksuite/affine": "0.17.19",
"@blocksuite/affine": "0.0.0-canary-20241028080828",
"@blocksuite/icons": "2.1.69",
"@chromatic-com/storybook": "^3.0.0",
"@storybook/addon-essentials": "^8.2.9",
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@affine/i18n": "workspace:*",
"@affine/templates": "workspace:*",
"@affine/track": "workspace:*",
"@blocksuite/affine": "0.17.19",
"@blocksuite/affine": "0.0.0-canary-20241028080828",
"@blocksuite/icons": "2.1.69",
"@capacitor/app": "^6.0.1",
"@capacitor/browser": "^6.0.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
} from '@blocksuite/affine/blocks';
import {
Bound,
getElementsBound,
getCommonBoundWithRotation,
type SerializedXYWH,
} from '@blocksuite/affine/global/utils';
import type { Doc } from '@blocksuite/affine/store';
Expand Down Expand Up @@ -398,7 +398,7 @@ const ADD_TO_EDGELESS_AS_NOTE = {
};

if (elements.length > 0) {
const bound = getElementsBound(
const bound = getCommonBoundWithRotation(
elements.map(e => Bound.deserialize(e.xywh))
);
const newBound = new Bound(bound.x, bound.maxY + 10, bound.w);
Expand Down Expand Up @@ -494,7 +494,7 @@ const CREATE_AS_LINKED_DOC = {
let y = 0;
if (elements.length) {
// Calculate the bound of the selected elements first
const bound = getElementsBound(
const bound = getCommonBoundWithRotation(
elements.map(e => Bound.deserialize(e.xywh))
);
x = bound.x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
import {
type AIItemGroupConfig,
type AISubItemConfig,
type CopilotSelectionController,
type CopilotTool,
EDGELESS_ELEMENT_TOOLBAR_WIDGET,
type EdgelessElementToolbarWidget,
matchFlavours,
Expand Down Expand Up @@ -251,10 +251,9 @@ function edgelessHandler<T extends keyof BlockSuitePresets.AIActions>(
if (!edgeless) {
AIProvider.slots.requestRunInEdgeless.emit({ host });
} else {
edgeless.tools.setEdgelessTool({ type: 'copilot' });
const currentController = edgeless.tools.controllers[
'copilot'
] as CopilotSelectionController;
edgeless.gfx.tool.setTool({ type: 'copilot' });
const currentController =
edgeless.gfx.tool.currentTool$.peek() as CopilotTool;
const selectedElements = edgeless.service.selection.selectedElements;
currentController.updateDragPointsWith(selectedElements, 10);
currentController.draggingAreaUpdated.emit(false); // do not show edgeless panel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ function updateEdgelessAIPanelConfig<
config.hideCallback = () => {
aiPanel.updateComplete
.finally(() => {
edgelessCopilot.edgeless.service.tool.switchToDefaultMode({
edgelessCopilot.edgeless.gfx.tool.setTool('default');
edgelessCopilot.edgeless.gfx.selection.set({
elements: [],
editing: false,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
SurfaceBlockModel,
} from '@blocksuite/affine/blocks';
import {
addImages,
DeleteIcon,
EDGELESS_ELEMENT_TOOLBAR_WIDGET,
EDGELESS_TEXT_BLOCK_MIN_HEIGHT,
Expand Down Expand Up @@ -312,8 +313,7 @@ const imageHandler = (host: EditorHost) => {
const [x, y] = edgelessRoot.service.viewport.toViewCoord(minX, minY);

host.doc.transact(() => {
edgelessRoot
.addImages([img], [x, y])
addImages(edgelessRoot.std, [img], [x, y])
.then(blockIds => {
const imageBlockId = blockIds[0];
const imageBlock = host.doc.getBlock(imageBlockId);
Expand Down Expand Up @@ -413,7 +413,7 @@ export const responses: {
const mindmap = elements[0].group as MindmapElementModel;
const xywh = mindmap.tree.element.xywh;

surface.removeElement(mindmap.id);
surface.deleteElement(mindmap.id);

if (data.node) {
data.node.xywh = xywh;
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/core/src/blocksuite/presets/ai/ai-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
EdgelessCopilotWidget,
EdgelessElementToolbarWidget,
EdgelessRootBlockSpec,
edgelessRootWigetViewMap,
edgelessRootWidgetViewMap,
ImageBlockSpec,
PageRootBlockSpec,
pageRootWidgetViewMap,
Expand Down Expand Up @@ -114,7 +114,7 @@ export const AIEdgelessRootBlockSpec: ExtensionType[] = [
setup: di => {
di.override(WidgetViewMapIdentifier('affine:page'), () => {
return {
...edgelessRootWigetViewMap,
...edgelessRootWidgetViewMap,
[AFFINE_EDGELESS_COPILOT_WIDGET]: literal`${unsafeStatic(
AFFINE_EDGELESS_COPILOT_WIDGET
)}`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { EditorHost } from '@blocksuite/affine/block-std';
import {
type CopilotSelectionController,
type CopilotTool,
type FrameBlockModel,
ImageBlockModel,
type SurfaceBlockComponent,
Expand Down Expand Up @@ -279,7 +279,7 @@ export function getCopilotSelectedElems(
const copilotWidget = getEdgelessCopilotWidget(host);

if (copilotWidget.visible) {
return (service.tool.controllers['copilot'] as CopilotSelectionController)
return (service.gfx.tool.currentTool$.peek() as CopilotTool)
.selectedElements;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ export function AffinePageReference({
if (e.shiftKey && ref.current) {
e.preventDefault();
e.stopPropagation();
peekView.open(ref.current).catch(console.error);
peekView
.open({
element: ref.current,
})
.catch(console.error);
}

if (isInPeekView) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
useRef,
} from 'react';

import type { DefaultOpenProperty } from '../../doc-properties';
import { BlocksuiteDocEditor, BlocksuiteEdgelessEditor } from './lit-adaper';
import * as styles from './styles.css';

Expand All @@ -29,6 +30,7 @@ interface BlocksuiteEditorContainerProps {
mode: DocMode;
shared?: boolean;
className?: string;
defaultOpenProperty?: DefaultOpenProperty;
style?: React.CSSProperties;
}

Expand All @@ -43,7 +45,7 @@ export const BlocksuiteEditorContainer = forwardRef<
AffineEditorContainer,
BlocksuiteEditorContainerProps
>(function AffineEditorContainer(
{ page, mode, className, style, shared },
{ page, mode, className, style, shared, defaultOpenProperty },
ref
) {
const rootRef = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -171,6 +173,7 @@ export const BlocksuiteEditorContainer = forwardRef<
ref={docRef}
titleRef={docTitleRef}
onClickBlank={handleClickPageModeBlank}
defaultOpenProperty={defaultOpenProperty}
/>
) : (
<BlocksuiteEdgelessEditor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ import { use } from 'foxact/use';
import type { CSSProperties } from 'react';
import { Suspense, useEffect } from 'react';

import type { DefaultOpenProperty } from '../../doc-properties';
import { BlocksuiteEditorContainer } from './blocksuite-editor-container';
import { NoPageRootError } from './no-page-error';

export type EditorProps = {
page: Doc;
mode: DocMode;
shared?: boolean;
defaultOpenProperty?: DefaultOpenProperty;
// on Editor ready
onEditorReady?: (editor: AffineEditorContainer) => (() => void) | void;
style?: CSSProperties;
Expand Down Expand Up @@ -58,6 +60,7 @@ const BlockSuiteEditorImpl = ({
shared,
style,
onEditorReady,
defaultOpenProperty,
}: EditorProps) => {
usePageRoot(page);

Expand Down Expand Up @@ -134,6 +137,7 @@ const BlockSuiteEditorImpl = ({
mode={mode}
page={page}
shared={shared}
defaultOpenProperty={defaultOpenProperty}
ref={editorRef}
className={className}
style={style}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ import {
AffinePageReference,
AffineSharedPageReference,
} from '../../affine/reference-link';
import { DocPropertiesTable } from '../../doc-properties';
import {
type DefaultOpenProperty,
DocPropertiesTable,
} from '../../doc-properties';
import { BiDirectionalLinkPanel } from './bi-directional-link-panel';
import { BlocksuiteEditorJournalDocTitle } from './journal-doc-title';
import {
Expand Down Expand Up @@ -76,6 +79,7 @@ const adapted = {
interface BlocksuiteEditorProps {
page: Doc;
shared?: boolean;
defaultOpenProperty?: DefaultOpenProperty;
}

const usePatchSpecs = (shared: boolean, mode: DocMode) => {
Expand Down Expand Up @@ -191,7 +195,13 @@ export const BlocksuiteDocEditor = forwardRef<
titleRef?: React.Ref<DocTitle>;
}
>(function BlocksuiteDocEditor(
{ page, shared, onClickBlank, titleRef: externalTitleRef },
{
page,
shared,
onClickBlank,
titleRef: externalTitleRef,
defaultOpenProperty,
},
ref
) {
const titleRef = useRef<DocTitle | null>(null);
Expand Down Expand Up @@ -245,7 +255,9 @@ export const BlocksuiteDocEditor = forwardRef<
) : (
<BlocksuiteEditorJournalDocTitle page={page} />
)}
{!shared ? <DocPropertiesTable /> : null}
{!shared ? (
<DocPropertiesTable defaultOpenProperty={defaultOpenProperty} />
) : null}
<adapted.DocEditor
className={styles.docContainer}
ref={onDocRef}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import {
type ExtensionType,
} from '@blocksuite/affine/block-std';
import {
EdgelessBuiltInManager,
EdgelessRootBlockSpec,
EdgelessToolExtension,
EditorSettingExtension,
FontLoaderService,
PageRootBlockSpec,
Expand Down Expand Up @@ -74,6 +76,8 @@ export function createEdgelessRootBlockSpec(
return [
enableAI ? AIEdgelessRootBlockSpec : EdgelessRootBlockSpec,
FontLoaderService,
EdgelessToolExtension,
EdgelessBuiltInManager,
getFontConfigExtension(),
getTelemetryExtension(),
getEditorConfigExtension(framework),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type { EditorService } from '@affine/core/modules/editor';
import { EditorSettingService } from '@affine/core/modules/editor-settting';
import { resolveLinkToDoc } from '@affine/core/modules/navigation';
import type { PeekViewService } from '@affine/core/modules/peek-view';
import type { ActivePeekView } from '@affine/core/modules/peek-view/entities/peek-view';
import {
CreationQuickSearchSession,
DocsQuickSearchSession,
Expand All @@ -35,6 +34,8 @@ import type {
AffineReference,
DocMode,
DocModeProvider,
PeekOptions,
PeekViewService as BSPeekViewService,
QuickSearchResult,
RootService,
} from '@blocksuite/affine/blocks';
Expand Down Expand Up @@ -243,11 +244,28 @@ export function patchEmbedLinkedDocBlockConfig(framework: FrameworkProvider) {

export function patchPeekViewService(service: PeekViewService) {
return PeekViewExtension({
peek: (target: ActivePeekView['target'], template?: TemplateResult) => {
logger.debug('center peek', target, template);
return service.peekView.open(target, template);
peek: (
element: {
target: HTMLElement;
docId: string;
blockIds?: string[];
template?: TemplateResult;
},
options?: PeekOptions
) => {
logger.debug('center peek', element);
const { template, target, ...props } = element;

return service.peekView.open(
{
element: target,
docRef: props,
},
template,
options?.abortSignal
);
},
});
} satisfies BSPeekViewService);
}

export function patchDocModeService(
Expand Down
Loading
Loading