mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-12 23:56:36 +08:00
fix: drag block issue (#9902)
### Changed - Added support for changing the preview offset during dragging. - Fixed the preview rendering for embed block and surface-ref block - Resolved an issue where the host element might be reused in certain cases, which could cause unexpected behavior - Moved viewport-related constants and methods to a more appropriate location
This commit is contained in:
@@ -51,8 +51,6 @@ const internalExtensions = [
|
||||
export class BlockStdScope {
|
||||
static internalExtensions = internalExtensions;
|
||||
|
||||
private _getHost: () => EditorHost;
|
||||
|
||||
readonly container: Container;
|
||||
|
||||
readonly store: Store;
|
||||
@@ -65,6 +63,8 @@ export class BlockStdScope {
|
||||
return this.provider.getAll(LifeCycleWatcherIdentifier);
|
||||
}
|
||||
|
||||
private _host!: EditorHost;
|
||||
|
||||
get dnd() {
|
||||
return this.get(DndController);
|
||||
}
|
||||
@@ -94,7 +94,14 @@ export class BlockStdScope {
|
||||
}
|
||||
|
||||
get host() {
|
||||
return this._getHost();
|
||||
if (!this._host) {
|
||||
throw new BlockSuiteError(
|
||||
ErrorCode.ValueNotExists,
|
||||
'Host is not ready to use, the `render` method should be called first'
|
||||
);
|
||||
}
|
||||
|
||||
return this._host;
|
||||
}
|
||||
|
||||
get range() {
|
||||
@@ -110,12 +117,6 @@ export class BlockStdScope {
|
||||
}
|
||||
|
||||
constructor(options: BlockStdOptions) {
|
||||
this._getHost = () => {
|
||||
throw new BlockSuiteError(
|
||||
ErrorCode.ValueNotExists,
|
||||
'Host is not ready to use, the `render` method should be called first'
|
||||
);
|
||||
};
|
||||
this.store = options.store;
|
||||
this.userExtensions = options.extensions;
|
||||
this.container = new Container();
|
||||
@@ -190,7 +191,7 @@ export class BlockStdScope {
|
||||
const element = new EditorHost();
|
||||
element.std = this;
|
||||
element.doc = this.store;
|
||||
this._getHost = () => element;
|
||||
this._host = element;
|
||||
this._lifeCycleWatchers.forEach(watcher => {
|
||||
watcher.rendered.call(watcher);
|
||||
});
|
||||
@@ -202,7 +203,6 @@ export class BlockStdScope {
|
||||
this._lifeCycleWatchers.forEach(watcher => {
|
||||
watcher.unmounted.call(watcher);
|
||||
});
|
||||
this._getHost = () => null as unknown as EditorHost;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user