refactor(editor): extract edgeless legacy slots (#9363)
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@blocksuite/affine-block-embed": "workspace:*",
|
"@blocksuite/affine-block-embed": "workspace:*",
|
||||||
|
"@blocksuite/affine-block-surface": "workspace:*",
|
||||||
"@blocksuite/affine-components": "workspace:*",
|
"@blocksuite/affine-components": "workspace:*",
|
||||||
"@blocksuite/affine-model": "workspace:*",
|
"@blocksuite/affine-model": "workspace:*",
|
||||||
"@blocksuite/affine-shared": "workspace:*",
|
"@blocksuite/affine-shared": "workspace:*",
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
|
import { EdgelessLegacySlotIdentifier } from '@blocksuite/affine-block-surface';
|
||||||
import type { HoverController } from '@blocksuite/affine-components/hover';
|
import type { HoverController } from '@blocksuite/affine-components/hover';
|
||||||
import { AttachmentBlockStyles } from '@blocksuite/affine-model';
|
import { AttachmentBlockStyles } from '@blocksuite/affine-model';
|
||||||
import {
|
import {
|
||||||
EMBED_CARD_HEIGHT,
|
EMBED_CARD_HEIGHT,
|
||||||
EMBED_CARD_WIDTH,
|
EMBED_CARD_WIDTH,
|
||||||
} from '@blocksuite/affine-shared/consts';
|
} from '@blocksuite/affine-shared/consts';
|
||||||
import { type BlockService, toGfxBlockComponent } from '@blocksuite/block-std';
|
import { toGfxBlockComponent } from '@blocksuite/block-std';
|
||||||
import type { Slot } from '@blocksuite/store';
|
|
||||||
import { styleMap } from 'lit/directives/style-map.js';
|
import { styleMap } from 'lit/directives/style-map.js';
|
||||||
|
|
||||||
import { AttachmentBlockComponent } from './attachment-block.js';
|
import { AttachmentBlockComponent } from './attachment-block.js';
|
||||||
@@ -17,30 +17,22 @@ export class AttachmentEdgelessBlockComponent extends toGfxBlockComponent(
|
|||||||
|
|
||||||
override blockDraggable = false;
|
override blockDraggable = false;
|
||||||
|
|
||||||
get rootService(): null | (BlockService & { slots: Record<string, Slot> }) {
|
get slots() {
|
||||||
return this.std.getService('affine:page');
|
return this.std.get(EdgelessLegacySlotIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
override connectedCallback(): void {
|
override connectedCallback(): void {
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
|
|
||||||
const rootService = this.rootService;
|
|
||||||
if (!rootService) {
|
|
||||||
console.warn('rootService is not found');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: move root service slots to extension
|
|
||||||
this._disposables.add(
|
this._disposables.add(
|
||||||
rootService.slots.elementResizeStart.on(() => {
|
this.slots.elementResizeStart.on(() => {
|
||||||
this._isResizing = true;
|
this._isResizing = true;
|
||||||
this._showOverlay = true;
|
this._showOverlay = true;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO: move root service slots to extension
|
|
||||||
this._disposables.add(
|
this._disposables.add(
|
||||||
rootService.slots.elementResizeEnd.on(() => {
|
this.slots.elementResizeEnd.on(() => {
|
||||||
this._isResizing = false;
|
this._isResizing = false;
|
||||||
this._showOverlay =
|
this._showOverlay =
|
||||||
this._isResizing || this._isDragging || !this._isSelected;
|
this._isResizing || this._isDragging || !this._isSelected;
|
||||||
|
|||||||
@@ -30,6 +30,9 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "../block-embed"
|
"path": "../block-embed"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "../block-surface"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,9 +76,9 @@ export function insertEmbedCard(
|
|||||||
editing: false,
|
editing: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
// @ts-expect-error TODO: fix after edgeless refactor
|
gfx.tool.setTool(
|
||||||
edgelessRoot.tools.setEdgelessTool({
|
// @ts-expect-error FIXME: resolve after gfx tool refactor
|
||||||
type: 'default',
|
'default'
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { EdgelessLegacySlotIdentifier } from '@blocksuite/affine-block-surface';
|
||||||
import {
|
import {
|
||||||
blockComponentSymbol,
|
blockComponentSymbol,
|
||||||
type BlockService,
|
type BlockService,
|
||||||
@@ -49,21 +50,22 @@ export function toEdgelessEmbedBlock<
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get edgelessSlots() {
|
||||||
|
return this.std.get(EdgelessLegacySlotIdentifier);
|
||||||
|
}
|
||||||
|
|
||||||
override connectedCallback(): void {
|
override connectedCallback(): void {
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
const rootService = this.rootService;
|
|
||||||
|
|
||||||
this._disposables.add(
|
this._disposables.add(
|
||||||
// @ts-expect-error TODO: fix after edgeless slots are migrated to extension
|
this.edgelessSlots.elementResizeStart.on(() => {
|
||||||
rootService.slots.elementResizeStart.on(() => {
|
|
||||||
this._isResizing = true;
|
this._isResizing = true;
|
||||||
this._showOverlay = true;
|
this._showOverlay = true;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
this._disposables.add(
|
this._disposables.add(
|
||||||
// @ts-expect-error TODO: fix after edgeless slots are migrated to extension
|
this.edgelessSlots.elementResizeEnd.on(() => {
|
||||||
rootService.slots.elementResizeEnd.on(() => {
|
|
||||||
this._isResizing = false;
|
this._isResizing = false;
|
||||||
this._showOverlay =
|
this._showOverlay =
|
||||||
this._isResizing || this._isDragging || !this._isSelected;
|
this._isResizing || this._isDragging || !this._isSelected;
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import type * as SurfaceEffects from '@blocksuite/affine-block-surface/effects';
|
||||||
|
|
||||||
import { EmbedFigmaBlockComponent } from './embed-figma-block';
|
import { EmbedFigmaBlockComponent } from './embed-figma-block';
|
||||||
import { EmbedEdgelessBlockComponent } from './embed-figma-block/embed-edgeless-figma-block';
|
import { EmbedEdgelessBlockComponent } from './embed-figma-block/embed-edgeless-figma-block';
|
||||||
import type { EmbedFigmaBlockService } from './embed-figma-block/embed-figma-service';
|
import type { EmbedFigmaBlockService } from './embed-figma-block/embed-figma-service';
|
||||||
@@ -90,6 +92,8 @@ export function effects() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare type _GLOBAL = typeof SurfaceEffects;
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface HTMLElementTagNameMap {
|
interface HTMLElementTagNameMap {
|
||||||
'affine-embed-figma-block': EmbedFigmaBlockComponent;
|
'affine-embed-figma-block': EmbedFigmaBlockComponent;
|
||||||
|
|||||||
@@ -27,6 +27,9 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "../shared"
|
"path": "../shared"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "../block-surface"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export * from './latex-block';
|
|||||||
export * from './latex-spec';
|
export * from './latex-spec';
|
||||||
|
|
||||||
// Global types
|
// Global types
|
||||||
declare type _Global =
|
declare type _GLOBAl =
|
||||||
| typeof NoteType
|
| typeof NoteType
|
||||||
| typeof CommandsType
|
| typeof CommandsType
|
||||||
| typeof RemarkMathType;
|
| typeof RemarkMathType;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@blocksuite/affine-block-embed": "workspace:*",
|
"@blocksuite/affine-block-embed": "workspace:*",
|
||||||
|
"@blocksuite/affine-block-surface": "workspace:*",
|
||||||
"@blocksuite/affine-components": "workspace:*",
|
"@blocksuite/affine-components": "workspace:*",
|
||||||
"@blocksuite/affine-model": "workspace:*",
|
"@blocksuite/affine-model": "workspace:*",
|
||||||
"@blocksuite/affine-shared": "workspace:*",
|
"@blocksuite/affine-shared": "workspace:*",
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { EdgelessLegacySlotIdentifier } from '@blocksuite/affine-block-surface';
|
||||||
import { MoreIndicatorIcon } from '@blocksuite/affine-components/icons';
|
import { MoreIndicatorIcon } from '@blocksuite/affine-components/icons';
|
||||||
import type { NoteBlockModel } from '@blocksuite/affine-model';
|
import type { NoteBlockModel } from '@blocksuite/affine-model';
|
||||||
import {
|
import {
|
||||||
@@ -13,11 +14,7 @@ import {
|
|||||||
matchFlavours,
|
matchFlavours,
|
||||||
stopPropagation,
|
stopPropagation,
|
||||||
} from '@blocksuite/affine-shared/utils';
|
} from '@blocksuite/affine-shared/utils';
|
||||||
import type {
|
import type { BlockComponent, EditorHost } from '@blocksuite/block-std';
|
||||||
BlockComponent,
|
|
||||||
BlockService,
|
|
||||||
EditorHost,
|
|
||||||
} from '@blocksuite/block-std';
|
|
||||||
import { ShadowlessElement, toGfxBlockComponent } from '@blocksuite/block-std';
|
import { ShadowlessElement, toGfxBlockComponent } from '@blocksuite/block-std';
|
||||||
import {
|
import {
|
||||||
almostEqual,
|
almostEqual,
|
||||||
@@ -26,7 +23,7 @@ import {
|
|||||||
Point,
|
Point,
|
||||||
WithDisposable,
|
WithDisposable,
|
||||||
} from '@blocksuite/global/utils';
|
} from '@blocksuite/global/utils';
|
||||||
import type { BlockModel, Slot } from '@blocksuite/store';
|
import type { BlockModel } from '@blocksuite/store';
|
||||||
import { css, html, nothing } from 'lit';
|
import { css, html, nothing } from 'lit';
|
||||||
import { property, query, state } from 'lit/decorators.js';
|
import { property, query, state } from 'lit/decorators.js';
|
||||||
import { classMap } from 'lit/directives/class-map.js';
|
import { classMap } from 'lit/directives/class-map.js';
|
||||||
@@ -153,9 +150,7 @@ export class EdgelessNoteBlockComponent extends toGfxBlockComponent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
get rootService() {
|
get rootService() {
|
||||||
return this.std.getService('affine:page') as BlockService & {
|
return this.std.getService('affine:page');
|
||||||
slots: Record<string, Slot>;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _collapsedContent() {
|
private _collapsedContent() {
|
||||||
@@ -330,12 +325,16 @@ export class EdgelessNoteBlockComponent extends toGfxBlockComponent(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get edgelessSlots() {
|
||||||
|
return this.std.get(EdgelessLegacySlotIdentifier);
|
||||||
|
}
|
||||||
|
|
||||||
override firstUpdated() {
|
override firstUpdated() {
|
||||||
const { _disposables } = this;
|
const { _disposables } = this;
|
||||||
const selection = this.gfx.selection;
|
const selection = this.gfx.selection;
|
||||||
|
|
||||||
_disposables.add(
|
_disposables.add(
|
||||||
this.rootService.slots.elementResizeStart.on(() => {
|
this.edgelessSlots.elementResizeStart.on(() => {
|
||||||
if (selection.selectedElements.includes(this.model)) {
|
if (selection.selectedElements.includes(this.model)) {
|
||||||
this._isResizing = true;
|
this._isResizing = true;
|
||||||
}
|
}
|
||||||
@@ -343,7 +342,7 @@ export class EdgelessNoteBlockComponent extends toGfxBlockComponent(
|
|||||||
);
|
);
|
||||||
|
|
||||||
_disposables.add(
|
_disposables.add(
|
||||||
this.rootService.slots.elementResizeEnd.on(() => {
|
this.edgelessSlots.elementResizeEnd.on(() => {
|
||||||
this._isResizing = false;
|
this._isResizing = false;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -30,6 +30,9 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "../block-embed"
|
"path": "../block-embed"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "../block-surface"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
export * from './crud-extension';
|
export * from './crud-extension';
|
||||||
|
export * from './legacy-slot-extension';
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import type { FrameBlockModel } from '@blocksuite/affine-model';
|
||||||
|
import type { ExtensionType } from '@blocksuite/block-std';
|
||||||
|
import { createIdentifier } from '@blocksuite/global/di';
|
||||||
|
import { Slot } from '@blocksuite/global/utils';
|
||||||
|
|
||||||
|
export const EdgelessLegacySlotIdentifier = createIdentifier<{
|
||||||
|
readonlyUpdated: Slot<boolean>;
|
||||||
|
navigatorSettingUpdated: Slot<{
|
||||||
|
hideToolbar?: boolean;
|
||||||
|
blackBackground?: boolean;
|
||||||
|
fillScreen?: boolean;
|
||||||
|
}>;
|
||||||
|
navigatorFrameChanged: Slot<FrameBlockModel>;
|
||||||
|
fullScreenToggled: Slot;
|
||||||
|
|
||||||
|
elementResizeStart: Slot;
|
||||||
|
elementResizeEnd: Slot;
|
||||||
|
toggleNoteSlicer: Slot;
|
||||||
|
|
||||||
|
toolbarLocked: Slot<boolean>;
|
||||||
|
}>('AffineEdgelessLegacySlotService');
|
||||||
|
|
||||||
|
export const EdgelessLegacySlotExtension: ExtensionType = {
|
||||||
|
setup: di => {
|
||||||
|
di.addImpl(EdgelessLegacySlotIdentifier, () => ({
|
||||||
|
readonlyUpdated: new Slot<boolean>(),
|
||||||
|
navigatorSettingUpdated: new Slot<{
|
||||||
|
hideToolbar?: boolean;
|
||||||
|
blackBackground?: boolean;
|
||||||
|
fillScreen?: boolean;
|
||||||
|
}>(),
|
||||||
|
navigatorFrameChanged: new Slot<FrameBlockModel>(),
|
||||||
|
fullScreenToggled: new Slot(),
|
||||||
|
elementResizeStart: new Slot(),
|
||||||
|
elementResizeEnd: new Slot(),
|
||||||
|
toggleNoteSlicer: new Slot(),
|
||||||
|
toolbarLocked: new Slot<boolean>(),
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -10,11 +10,14 @@ import { literal } from 'lit/static-html.js';
|
|||||||
import {
|
import {
|
||||||
EdgelessSurfaceBlockAdapterExtensions,
|
EdgelessSurfaceBlockAdapterExtensions,
|
||||||
SurfaceBlockAdapterExtensions,
|
SurfaceBlockAdapterExtensions,
|
||||||
} from './adapters/extension.js';
|
} from './adapters/extension';
|
||||||
import { commands } from './commands/index.js';
|
import { commands } from './commands';
|
||||||
import { EdgelessCRUDExtension } from './extensions/crud-extension.js';
|
import {
|
||||||
import { SurfaceBlockService } from './surface-service.js';
|
EdgelessCRUDExtension,
|
||||||
import { MindMapView } from './view/mindmap.js';
|
EdgelessLegacySlotExtension,
|
||||||
|
} from './extensions';
|
||||||
|
import { SurfaceBlockService } from './surface-service';
|
||||||
|
import { MindMapView } from './view/mindmap';
|
||||||
|
|
||||||
const CommonSurfaceBlockSpec: ExtensionType[] = [
|
const CommonSurfaceBlockSpec: ExtensionType[] = [
|
||||||
FlavourExtension('affine:surface'),
|
FlavourExtension('affine:surface'),
|
||||||
@@ -23,6 +26,7 @@ const CommonSurfaceBlockSpec: ExtensionType[] = [
|
|||||||
HighlightSelectionExtension,
|
HighlightSelectionExtension,
|
||||||
MindMapView,
|
MindMapView,
|
||||||
EdgelessCRUDExtension,
|
EdgelessCRUDExtension,
|
||||||
|
EdgelessLegacySlotExtension,
|
||||||
];
|
];
|
||||||
|
|
||||||
export const PageSurfaceBlockSpec: ExtensionType[] = [
|
export const PageSurfaceBlockSpec: ExtensionType[] = [
|
||||||
|
|||||||
@@ -64,8 +64,8 @@ export interface ResolvedOptions extends Options {
|
|||||||
preserveVertices: boolean;
|
preserveVertices: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare type OpType = 'move' | 'bcurveTo' | 'lineTo';
|
export type OpType = 'move' | 'bcurveTo' | 'lineTo';
|
||||||
export declare type OpSetType = 'path' | 'fillPath' | 'fillSketch';
|
export type OpSetType = 'path' | 'fillPath' | 'fillSketch';
|
||||||
|
|
||||||
export interface Op {
|
export interface Op {
|
||||||
op: OpType;
|
op: OpType;
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ import type {
|
|||||||
SurfaceBlockComponent,
|
SurfaceBlockComponent,
|
||||||
SurfaceBlockModel,
|
SurfaceBlockModel,
|
||||||
} from '@blocksuite/affine-block-surface';
|
} from '@blocksuite/affine-block-surface';
|
||||||
import { CommonUtils } from '@blocksuite/affine-block-surface';
|
import {
|
||||||
|
CommonUtils,
|
||||||
|
EdgelessLegacySlotIdentifier,
|
||||||
|
} from '@blocksuite/affine-block-surface';
|
||||||
import type {
|
import type {
|
||||||
RootBlockModel,
|
RootBlockModel,
|
||||||
ShapeElementModel,
|
ShapeElementModel,
|
||||||
@@ -143,7 +146,7 @@ export class EdgelessRootBlockComponent extends BlockComponent<
|
|||||||
}
|
}
|
||||||
|
|
||||||
get slots() {
|
get slots() {
|
||||||
return this.service.slots;
|
return this.std.get(EdgelessLegacySlotIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
get surfaceBlockModel() {
|
get surfaceBlockModel() {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
EdgelessCRUDIdentifier,
|
EdgelessCRUDIdentifier,
|
||||||
|
EdgelessLegacySlotIdentifier,
|
||||||
type ElementRenderer,
|
type ElementRenderer,
|
||||||
elementRenderers,
|
elementRenderers,
|
||||||
type SurfaceBlockModel,
|
type SurfaceBlockModel,
|
||||||
@@ -7,7 +8,6 @@ import {
|
|||||||
} from '@blocksuite/affine-block-surface';
|
} from '@blocksuite/affine-block-surface';
|
||||||
import {
|
import {
|
||||||
type ConnectorElementModel,
|
type ConnectorElementModel,
|
||||||
type FrameBlockModel,
|
|
||||||
type GroupElementModel,
|
type GroupElementModel,
|
||||||
MindmapElementModel,
|
MindmapElementModel,
|
||||||
RootBlockSchema,
|
RootBlockSchema,
|
||||||
@@ -28,7 +28,6 @@ import {
|
|||||||
} from '@blocksuite/block-std/gfx';
|
} from '@blocksuite/block-std/gfx';
|
||||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||||
import { Bound, getCommonBound } from '@blocksuite/global/utils';
|
import { Bound, getCommonBound } from '@blocksuite/global/utils';
|
||||||
import { Slot } from '@blocksuite/store';
|
|
||||||
import { effect } from '@preact/signals-core';
|
import { effect } from '@preact/signals-core';
|
||||||
|
|
||||||
import { getSurfaceBlock } from '../../surface-ref-block/utils.js';
|
import { getSurfaceBlock } from '../../surface-ref-block/utils.js';
|
||||||
@@ -59,23 +58,6 @@ export class EdgelessRootService extends RootService implements SurfaceContext {
|
|||||||
|
|
||||||
elementRenderers: Record<string, ElementRenderer> = elementRenderers;
|
elementRenderers: Record<string, ElementRenderer> = elementRenderers;
|
||||||
|
|
||||||
slots = {
|
|
||||||
readonlyUpdated: new Slot<boolean>(),
|
|
||||||
navigatorSettingUpdated: new Slot<{
|
|
||||||
hideToolbar?: boolean;
|
|
||||||
blackBackground?: boolean;
|
|
||||||
fillScreen?: boolean;
|
|
||||||
}>(),
|
|
||||||
navigatorFrameChanged: new Slot<FrameBlockModel>(),
|
|
||||||
fullScreenToggled: new Slot(),
|
|
||||||
|
|
||||||
elementResizeStart: new Slot(),
|
|
||||||
elementResizeEnd: new Slot(),
|
|
||||||
toggleNoteSlicer: new Slot(),
|
|
||||||
|
|
||||||
toolbarLocked: new Slot<boolean>(),
|
|
||||||
};
|
|
||||||
|
|
||||||
TemplateJob = TemplateJob;
|
TemplateJob = TemplateJob;
|
||||||
|
|
||||||
get blocks(): GfxBlockModel[] {
|
get blocks(): GfxBlockModel[] {
|
||||||
@@ -168,12 +150,14 @@ export class EdgelessRootService extends RootService implements SurfaceContext {
|
|||||||
private _initReadonlyListener() {
|
private _initReadonlyListener() {
|
||||||
const doc = this.doc;
|
const doc = this.doc;
|
||||||
|
|
||||||
|
const slots = this.std.get(EdgelessLegacySlotIdentifier);
|
||||||
|
|
||||||
let readonly = doc.readonly;
|
let readonly = doc.readonly;
|
||||||
this.disposables.add(
|
this.disposables.add(
|
||||||
doc.awarenessStore.slots.update.on(() => {
|
doc.awarenessStore.slots.update.on(() => {
|
||||||
if (readonly !== doc.readonly) {
|
if (readonly !== doc.readonly) {
|
||||||
readonly = doc.readonly;
|
readonly = doc.readonly;
|
||||||
this.slots.readonlyUpdated.emit(readonly);
|
slots.readonlyUpdated.emit(readonly);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
import {
|
||||||
|
EdgelessLegacySlotIdentifier,
|
||||||
|
type SurfaceBlockComponent,
|
||||||
|
} from '@blocksuite/affine-block-surface';
|
||||||
import type { DndEventState } from '@blocksuite/block-std';
|
import type { DndEventState } from '@blocksuite/block-std';
|
||||||
import {
|
import {
|
||||||
GfxControllerIdentifier,
|
GfxControllerIdentifier,
|
||||||
@@ -6,10 +10,6 @@ import {
|
|||||||
import { type IVec, Rect } from '@blocksuite/global/utils';
|
import { type IVec, Rect } from '@blocksuite/global/utils';
|
||||||
import { effect } from '@preact/signals-core';
|
import { effect } from '@preact/signals-core';
|
||||||
|
|
||||||
import type {
|
|
||||||
EdgelessRootBlockComponent,
|
|
||||||
EdgelessRootService,
|
|
||||||
} from '../../../edgeless/index.js';
|
|
||||||
import {
|
import {
|
||||||
getSelectedRect,
|
getSelectedRect,
|
||||||
isTopLevelBlock,
|
isTopLevelBlock,
|
||||||
@@ -64,8 +64,12 @@ export class EdgelessWatcher {
|
|||||||
|
|
||||||
private readonly _showDragHandleOnTopLevelBlocks = async () => {
|
private readonly _showDragHandleOnTopLevelBlocks = async () => {
|
||||||
if (this.widget.mode === 'page') return;
|
if (this.widget.mode === 'page') return;
|
||||||
const { edgelessRoot } = this;
|
|
||||||
await edgelessRoot.surface.updateComplete;
|
const surfaceModel = this.widget.doc.getBlockByFlavour('affine:surface');
|
||||||
|
const surface = this.widget.std.view.getBlock(
|
||||||
|
surfaceModel[0]!.id
|
||||||
|
) as SurfaceBlockComponent;
|
||||||
|
await surface.updateComplete;
|
||||||
|
|
||||||
if (!this.widget.anchorBlockId) return;
|
if (!this.widget.anchorBlockId) return;
|
||||||
|
|
||||||
@@ -121,9 +125,11 @@ export class EdgelessWatcher {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { edgelessRoot } = this;
|
const { std } = this.widget;
|
||||||
const editing = edgelessRoot.service.selection.editing;
|
const gfx = std.get(GfxControllerIdentifier);
|
||||||
const selectedElements = edgelessRoot.service.selection.selectedElements;
|
const { selection } = gfx;
|
||||||
|
const editing = selection.editing;
|
||||||
|
const selectedElements = selection.selectedElements;
|
||||||
if (editing || selectedElements.length !== 1) {
|
if (editing || selectedElements.length !== 1) {
|
||||||
this.widget.hide();
|
this.widget.hide();
|
||||||
return;
|
return;
|
||||||
@@ -158,10 +164,6 @@ export class EdgelessWatcher {
|
|||||||
this.widget.dragPreview.style.opacity = altKey ? '1' : '0.5';
|
this.widget.dragPreview.style.opacity = altKey ? '1' : '0.5';
|
||||||
};
|
};
|
||||||
|
|
||||||
get edgelessRoot() {
|
|
||||||
return this.widget.rootComponent as EdgelessRootBlockComponent;
|
|
||||||
}
|
|
||||||
|
|
||||||
get hoverAreaRectTopLevelBlock() {
|
get hoverAreaRectTopLevelBlock() {
|
||||||
const area = this.hoverAreaTopLevelBlock;
|
const area = this.hoverAreaTopLevelBlock;
|
||||||
if (!area) return null;
|
if (!area) return null;
|
||||||
@@ -174,12 +176,11 @@ export class EdgelessWatcher {
|
|||||||
|
|
||||||
if (!edgelessElement) return null;
|
if (!edgelessElement) return null;
|
||||||
|
|
||||||
const { edgelessRoot } = this;
|
const { std } = this.widget;
|
||||||
|
const gfx = std.get(GfxControllerIdentifier);
|
||||||
|
const { viewport } = gfx;
|
||||||
const rect = getSelectedRect([edgelessElement]);
|
const rect = getSelectedRect([edgelessElement]);
|
||||||
let [left, top] = edgelessRoot.service.viewport.toViewCoord(
|
let [left, top] = viewport.toViewCoord(rect.left, rect.top);
|
||||||
rect.left,
|
|
||||||
rect.top
|
|
||||||
);
|
|
||||||
const scale = this.widget.scale.peek();
|
const scale = this.widget.scale.peek();
|
||||||
const width = rect.width * scale;
|
const width = rect.width * scale;
|
||||||
const height = rect.height * scale;
|
const height = rect.height * scale;
|
||||||
@@ -212,26 +213,23 @@ export class EdgelessWatcher {
|
|||||||
|
|
||||||
watch() {
|
watch() {
|
||||||
const { disposables, std } = this.widget;
|
const { disposables, std } = this.widget;
|
||||||
const gfxController = std.get(GfxControllerIdentifier);
|
const gfx = std.get(GfxControllerIdentifier);
|
||||||
const { viewport } = gfxController;
|
const { viewport, selection, tool } = gfx;
|
||||||
const edgelessService = std.getService(
|
const edgelessSlots = std.get(EdgelessLegacySlotIdentifier);
|
||||||
'affine:page'
|
|
||||||
) as EdgelessRootService;
|
|
||||||
const edgelessSlots = edgelessService.slots;
|
|
||||||
|
|
||||||
disposables.add(
|
disposables.add(
|
||||||
viewport.viewportUpdated.on(this._handleEdgelessViewPortUpdated)
|
viewport.viewportUpdated.on(this._handleEdgelessViewPortUpdated)
|
||||||
);
|
);
|
||||||
|
|
||||||
disposables.add(
|
disposables.add(
|
||||||
edgelessService.selection.slots.updated.on(() => {
|
selection.slots.updated.on(() => {
|
||||||
this.checkTopLevelBlockSelection();
|
this.checkTopLevelBlockSelection();
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
disposables.add(
|
disposables.add(
|
||||||
effect(() => {
|
effect(() => {
|
||||||
const value = gfxController.tool.currentToolOption$.value;
|
const value = tool.currentToolOption$.value;
|
||||||
|
|
||||||
value && this._handleEdgelessToolUpdated(value);
|
value && this._handleEdgelessToolUpdated(value);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { EdgelessLegacySlotIdentifier } from '@blocksuite/affine-block-surface';
|
||||||
import {
|
import {
|
||||||
AutoConnectLeftIcon,
|
AutoConnectLeftIcon,
|
||||||
AutoConnectRightIcon,
|
AutoConnectRightIcon,
|
||||||
@@ -16,6 +17,7 @@ import {
|
|||||||
stopPropagation,
|
stopPropagation,
|
||||||
} from '@blocksuite/affine-shared/utils';
|
} from '@blocksuite/affine-shared/utils';
|
||||||
import { WidgetComponent } from '@blocksuite/block-std';
|
import { WidgetComponent } from '@blocksuite/block-std';
|
||||||
|
import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';
|
||||||
import { Bound } from '@blocksuite/global/utils';
|
import { Bound } from '@blocksuite/global/utils';
|
||||||
import { css, html, nothing, type TemplateResult } from 'lit';
|
import { css, html, nothing, type TemplateResult } from 'lit';
|
||||||
import { state } from 'lit/decorators.js';
|
import { state } from 'lit/decorators.js';
|
||||||
@@ -426,7 +428,7 @@ export class EdgelessAutoConnectWidget extends WidgetComponent<
|
|||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
});
|
});
|
||||||
const components = [];
|
const components: TemplateResult[] = [];
|
||||||
const count = counts[i];
|
const count = counts[i];
|
||||||
const initGap = 24 / count - 24;
|
const initGap = 24 / count - 24;
|
||||||
const positions = calculatePosition(
|
const positions = calculatePosition(
|
||||||
@@ -509,17 +511,19 @@ export class EdgelessAutoConnectWidget extends WidgetComponent<
|
|||||||
}
|
}
|
||||||
|
|
||||||
override firstUpdated(): void {
|
override firstUpdated(): void {
|
||||||
const { _disposables, service } = this;
|
const { _disposables, std } = this;
|
||||||
|
const slots = std.get(EdgelessLegacySlotIdentifier);
|
||||||
|
const gfx = std.get(GfxControllerIdentifier);
|
||||||
|
|
||||||
_disposables.add(
|
_disposables.add(
|
||||||
service.viewport.viewportUpdated.on(() => {
|
gfx.viewport.viewportUpdated.on(() => {
|
||||||
this.requestUpdate();
|
this.requestUpdate();
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
_disposables.add(
|
_disposables.add(
|
||||||
service.selection.slots.updated.on(() => {
|
gfx.selection.slots.updated.on(() => {
|
||||||
const { selectedElements } = service.selection;
|
const { selectedElements } = gfx.selection;
|
||||||
if (
|
if (
|
||||||
!(selectedElements.length === 1 && isNoteBlock(selectedElements[0]))
|
!(selectedElements.length === 1 && isNoteBlock(selectedElements[0]))
|
||||||
) {
|
) {
|
||||||
@@ -529,22 +533,22 @@ export class EdgelessAutoConnectWidget extends WidgetComponent<
|
|||||||
);
|
);
|
||||||
|
|
||||||
_disposables.add(
|
_disposables.add(
|
||||||
service.uiEventDispatcher.add('dragStart', () => {
|
std.event.add('dragStart', () => {
|
||||||
this._dragging = true;
|
this._dragging = true;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
_disposables.add(
|
_disposables.add(
|
||||||
service.uiEventDispatcher.add('dragEnd', () => {
|
std.event.add('dragEnd', () => {
|
||||||
this._dragging = false;
|
this._dragging = false;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
_disposables.add(
|
_disposables.add(
|
||||||
service.slots.elementResizeStart.on(() => {
|
slots.elementResizeStart.on(() => {
|
||||||
this._dragging = true;
|
this._dragging = true;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
_disposables.add(
|
_disposables.add(
|
||||||
service.slots.elementResizeEnd.on(() => {
|
slots.elementResizeEnd.on(() => {
|
||||||
this._dragging = false;
|
this._dragging = false;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { EdgelessLegacySlotIdentifier } from '@blocksuite/affine-block-surface';
|
||||||
import type { RootBlockModel } from '@blocksuite/affine-model';
|
import type { RootBlockModel } from '@blocksuite/affine-model';
|
||||||
import { WidgetComponent } from '@blocksuite/block-std';
|
import { WidgetComponent } from '@blocksuite/block-std';
|
||||||
import { effect } from '@preact/signals-core';
|
import { effect } from '@preact/signals-core';
|
||||||
@@ -58,10 +59,8 @@ export class AffineEdgelessZoomToolbarWidget extends WidgetComponent<
|
|||||||
}
|
}
|
||||||
|
|
||||||
override firstUpdated() {
|
override firstUpdated() {
|
||||||
const {
|
const { disposables, std } = this;
|
||||||
disposables,
|
const slots = std.get(EdgelessLegacySlotIdentifier);
|
||||||
edgeless: { slots },
|
|
||||||
} = this;
|
|
||||||
|
|
||||||
disposables.add(
|
disposables.add(
|
||||||
slots.navigatorSettingUpdated.on(({ hideToolbar }) => {
|
slots.navigatorSettingUpdated.on(({ hideToolbar }) => {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import type { EditorHost } from '@blocksuite/block-std';
|
|||||||
import {
|
import {
|
||||||
createButtonPopper,
|
createButtonPopper,
|
||||||
DocModeProvider,
|
DocModeProvider,
|
||||||
|
EdgelessLegacySlotIdentifier,
|
||||||
EdgelessRootService,
|
EdgelessRootService,
|
||||||
EditPropsStore,
|
EditPropsStore,
|
||||||
type NavigatorMode,
|
type NavigatorMode,
|
||||||
@@ -134,14 +135,14 @@ export class FramePanelHeader extends WithDisposable(LitElement) {
|
|||||||
private readonly _setEdgelessDisposables = () => {
|
private readonly _setEdgelessDisposables = () => {
|
||||||
if (!this._edgelessRootService) return;
|
if (!this._edgelessRootService) return;
|
||||||
|
|
||||||
|
const slots = this.editorHost.std.get(EdgelessLegacySlotIdentifier);
|
||||||
|
|
||||||
this._clearEdgelessDisposables();
|
this._clearEdgelessDisposables();
|
||||||
this._edgelessDisposables = new DisposableGroup();
|
this._edgelessDisposables = new DisposableGroup();
|
||||||
this._edgelessDisposables.add(
|
this._edgelessDisposables.add(
|
||||||
this._edgelessRootService.slots.navigatorSettingUpdated.on(
|
slots.navigatorSettingUpdated.on(({ fillScreen }) => {
|
||||||
({ fillScreen }) => {
|
|
||||||
this._navigatorMode = fillScreen ? 'fill' : 'fit';
|
this._navigatorMode = fillScreen ? 'fill' : 'fit';
|
||||||
}
|
})
|
||||||
)
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import type { EditorHost } from '@blocksuite/block-std';
|
import type { EditorHost } from '@blocksuite/block-std';
|
||||||
import { EdgelessRootService, EditPropsStore } from '@blocksuite/blocks';
|
import {
|
||||||
|
EdgelessLegacySlotIdentifier,
|
||||||
|
EdgelessRootService,
|
||||||
|
EditPropsStore,
|
||||||
|
} from '@blocksuite/blocks';
|
||||||
import { WithDisposable } from '@blocksuite/global/utils';
|
import { WithDisposable } from '@blocksuite/global/utils';
|
||||||
import { css, html, LitElement, type PropertyValues } from 'lit';
|
import { css, html, LitElement, type PropertyValues } from 'lit';
|
||||||
import { property, state } from 'lit/decorators.js';
|
import { property, state } from 'lit/decorators.js';
|
||||||
@@ -72,16 +76,20 @@ export const AFFINE_FRAMES_SETTING_MENU = 'affine-frames-setting-menu';
|
|||||||
export class FramesSettingMenu extends WithDisposable(LitElement) {
|
export class FramesSettingMenu extends WithDisposable(LitElement) {
|
||||||
static override styles = styles;
|
static override styles = styles;
|
||||||
|
|
||||||
|
get slots() {
|
||||||
|
return this.editorHost.std.get(EdgelessLegacySlotIdentifier);
|
||||||
|
}
|
||||||
|
|
||||||
private readonly _onBlackBackgroundChange = (checked: boolean) => {
|
private readonly _onBlackBackgroundChange = (checked: boolean) => {
|
||||||
this.blackBackground = checked;
|
this.blackBackground = checked;
|
||||||
this._edgelessRootService?.slots.navigatorSettingUpdated.emit({
|
this.slots.navigatorSettingUpdated.emit({
|
||||||
blackBackground: this.blackBackground,
|
blackBackground: this.blackBackground,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly _onFillScreenChange = (checked: boolean) => {
|
private readonly _onFillScreenChange = (checked: boolean) => {
|
||||||
this.fillScreen = checked;
|
this.fillScreen = checked;
|
||||||
this._edgelessRootService?.slots.navigatorSettingUpdated.emit({
|
this.slots.navigatorSettingUpdated.emit({
|
||||||
fillScreen: this.fillScreen,
|
fillScreen: this.fillScreen,
|
||||||
});
|
});
|
||||||
this._editPropsStore.setStorage('presentFillScreen', this.fillScreen);
|
this._editPropsStore.setStorage('presentFillScreen', this.fillScreen);
|
||||||
@@ -89,7 +97,7 @@ export class FramesSettingMenu extends WithDisposable(LitElement) {
|
|||||||
|
|
||||||
private readonly _onHideToolBarChange = (checked: boolean) => {
|
private readonly _onHideToolBarChange = (checked: boolean) => {
|
||||||
this.hideToolbar = checked;
|
this.hideToolbar = checked;
|
||||||
this._edgelessRootService?.slots.navigatorSettingUpdated.emit({
|
this.slots.navigatorSettingUpdated.emit({
|
||||||
hideToolbar: this.hideToolbar,
|
hideToolbar: this.hideToolbar,
|
||||||
});
|
});
|
||||||
this._editPropsStore.setStorage('presentHideToolbar', this.hideToolbar);
|
this._editPropsStore.setStorage('presentHideToolbar', this.hideToolbar);
|
||||||
@@ -170,7 +178,7 @@ export class FramesSettingMenu extends WithDisposable(LitElement) {
|
|||||||
if (_changedProperties.has('editorHost')) {
|
if (_changedProperties.has('editorHost')) {
|
||||||
if (this._edgelessRootService) {
|
if (this._edgelessRootService) {
|
||||||
this.disposables.add(
|
this.disposables.add(
|
||||||
this._edgelessRootService.slots.navigatorSettingUpdated.on(
|
this.slots.navigatorSettingUpdated.on(
|
||||||
({ blackBackground, hideToolbar }) => {
|
({ blackBackground, hideToolbar }) => {
|
||||||
if (
|
if (
|
||||||
blackBackground !== undefined &&
|
blackBackground !== undefined &&
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export const PackageList = [
|
|||||||
name: '@blocksuite/affine-block-attachment',
|
name: '@blocksuite/affine-block-attachment',
|
||||||
workspaceDependencies: [
|
workspaceDependencies: [
|
||||||
'blocksuite/affine/block-embed',
|
'blocksuite/affine/block-embed',
|
||||||
|
'blocksuite/affine/block-surface',
|
||||||
'blocksuite/affine/components',
|
'blocksuite/affine/components',
|
||||||
'blocksuite/affine/model',
|
'blocksuite/affine/model',
|
||||||
'blocksuite/affine/shared',
|
'blocksuite/affine/shared',
|
||||||
@@ -113,6 +114,7 @@ export const PackageList = [
|
|||||||
name: '@blocksuite/affine-block-note',
|
name: '@blocksuite/affine-block-note',
|
||||||
workspaceDependencies: [
|
workspaceDependencies: [
|
||||||
'blocksuite/affine/block-embed',
|
'blocksuite/affine/block-embed',
|
||||||
|
'blocksuite/affine/block-surface',
|
||||||
'blocksuite/affine/components',
|
'blocksuite/affine/components',
|
||||||
'blocksuite/affine/model',
|
'blocksuite/affine/model',
|
||||||
'blocksuite/affine/shared',
|
'blocksuite/affine/shared',
|
||||||
|
|||||||
@@ -3244,6 +3244,7 @@ __metadata:
|
|||||||
resolution: "@blocksuite/affine-block-attachment@workspace:blocksuite/affine/block-attachment"
|
resolution: "@blocksuite/affine-block-attachment@workspace:blocksuite/affine/block-attachment"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@blocksuite/affine-block-embed": "workspace:*"
|
"@blocksuite/affine-block-embed": "workspace:*"
|
||||||
|
"@blocksuite/affine-block-surface": "workspace:*"
|
||||||
"@blocksuite/affine-components": "workspace:*"
|
"@blocksuite/affine-components": "workspace:*"
|
||||||
"@blocksuite/affine-model": "workspace:*"
|
"@blocksuite/affine-model": "workspace:*"
|
||||||
"@blocksuite/affine-shared": "workspace:*"
|
"@blocksuite/affine-shared": "workspace:*"
|
||||||
@@ -3407,6 +3408,7 @@ __metadata:
|
|||||||
resolution: "@blocksuite/affine-block-note@workspace:blocksuite/affine/block-note"
|
resolution: "@blocksuite/affine-block-note@workspace:blocksuite/affine/block-note"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@blocksuite/affine-block-embed": "workspace:*"
|
"@blocksuite/affine-block-embed": "workspace:*"
|
||||||
|
"@blocksuite/affine-block-surface": "workspace:*"
|
||||||
"@blocksuite/affine-components": "workspace:*"
|
"@blocksuite/affine-components": "workspace:*"
|
||||||
"@blocksuite/affine-model": "workspace:*"
|
"@blocksuite/affine-model": "workspace:*"
|
||||||
"@blocksuite/affine-shared": "workspace:*"
|
"@blocksuite/affine-shared": "workspace:*"
|
||||||
|
|||||||
Reference in New Issue
Block a user