mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-24 13:58:50 +08:00
feat(editor): life cycle ext (#10668)
This commit is contained in:
@@ -10,7 +10,7 @@ import {
|
|||||||
import { EMBED_CARD_HEIGHT } from '@blocksuite/affine-shared/consts';
|
import { EMBED_CARD_HEIGHT } from '@blocksuite/affine-shared/consts';
|
||||||
import { NotificationProvider } from '@blocksuite/affine-shared/services';
|
import { NotificationProvider } from '@blocksuite/affine-shared/services';
|
||||||
import { matchModels, SpecProvider } from '@blocksuite/affine-shared/utils';
|
import { matchModels, SpecProvider } from '@blocksuite/affine-shared/utils';
|
||||||
import { BlockStdScope } from '@blocksuite/block-std';
|
import { BlockStdScope, EditorLifeCycleExtension } from '@blocksuite/block-std';
|
||||||
import {
|
import {
|
||||||
type BlockModel,
|
type BlockModel,
|
||||||
type BlockSnapshot,
|
type BlockSnapshot,
|
||||||
@@ -351,7 +351,9 @@ export function notifyDocCreated(std: BlockStdScope, doc: Store) {
|
|||||||
// edit or undo or switch doc, close notify toast
|
// edit or undo or switch doc, close notify toast
|
||||||
const addHandler = doc.history.on('stack-item-added', closeNotify);
|
const addHandler = doc.history.on('stack-item-added', closeNotify);
|
||||||
const popHandler = doc.history.on('stack-item-popped', closeNotify);
|
const popHandler = doc.history.on('stack-item-popped', closeNotify);
|
||||||
const disposable = std.host.slots.unmounted.on(closeNotify);
|
const disposable = std
|
||||||
|
.get(EditorLifeCycleExtension)
|
||||||
|
.slots.unmounted.on(closeNotify);
|
||||||
|
|
||||||
notification.notify({
|
notification.notify({
|
||||||
title: 'Linked doc created',
|
title: 'Linked doc created',
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import {
|
|||||||
TelemetryProvider,
|
TelemetryProvider,
|
||||||
ThemeProvider,
|
ThemeProvider,
|
||||||
} from '@blocksuite/affine-shared/services';
|
} from '@blocksuite/affine-shared/services';
|
||||||
|
import { EditorLifeCycleExtension } from '@blocksuite/block-std';
|
||||||
import { Bound } from '@blocksuite/global/gfx';
|
import { Bound } from '@blocksuite/global/gfx';
|
||||||
import { WithDisposable } from '@blocksuite/global/lit';
|
import { WithDisposable } from '@blocksuite/global/lit';
|
||||||
import {
|
import {
|
||||||
@@ -210,7 +211,9 @@ export class EdgelessChangeNoteButton extends WithDisposable(LitElement) {
|
|||||||
|
|
||||||
const addHandler = this.doc.history.on('stack-item-added', closeNotify);
|
const addHandler = this.doc.history.on('stack-item-added', closeNotify);
|
||||||
const popHandler = this.doc.history.on('stack-item-popped', closeNotify);
|
const popHandler = this.doc.history.on('stack-item-popped', closeNotify);
|
||||||
const disposable = this.edgeless.std.host.slots.unmounted.on(closeNotify);
|
const disposable = this.edgeless.std
|
||||||
|
.get(EditorLifeCycleExtension)
|
||||||
|
.slots.unmounted.on(closeNotify);
|
||||||
|
|
||||||
const undo = () => {
|
const undo = () => {
|
||||||
this.doc.undo();
|
this.doc.undo();
|
||||||
|
|||||||
@@ -15,10 +15,11 @@ import {
|
|||||||
listenClickAway,
|
listenClickAway,
|
||||||
stopPropagation,
|
stopPropagation,
|
||||||
} from '@blocksuite/affine-shared/utils';
|
} from '@blocksuite/affine-shared/utils';
|
||||||
import type {
|
import {
|
||||||
BlockComponent,
|
type BlockComponent,
|
||||||
BlockStdScope,
|
type BlockStdScope,
|
||||||
EditorHost,
|
type EditorHost,
|
||||||
|
EditorLifeCycleExtension,
|
||||||
} from '@blocksuite/block-std';
|
} from '@blocksuite/block-std';
|
||||||
import { SignalWatcher, WithDisposable } from '@blocksuite/global/lit';
|
import { SignalWatcher, WithDisposable } from '@blocksuite/global/lit';
|
||||||
import { nextTick } from '@blocksuite/global/utils';
|
import { nextTick } from '@blocksuite/global/utils';
|
||||||
@@ -256,7 +257,9 @@ export class EmbedCardEditModal extends SignalWatcher(
|
|||||||
override connectedCallback() {
|
override connectedCallback() {
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
|
|
||||||
this.disposables.add(this.host.slots.unmounted.on(this._hide));
|
this.disposables.add(
|
||||||
|
this.host.std.get(EditorLifeCycleExtension).slots.unmounted.on(this._hide)
|
||||||
|
);
|
||||||
this._updateInfo();
|
this._updateInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
import { NotificationProvider } from '@blocksuite/affine-shared/services';
|
import { NotificationProvider } from '@blocksuite/affine-shared/services';
|
||||||
import type { BlockStdScope } from '@blocksuite/block-std';
|
import {
|
||||||
|
type BlockStdScope,
|
||||||
|
EditorLifeCycleExtension,
|
||||||
|
} from '@blocksuite/block-std';
|
||||||
|
|
||||||
import { toast } from '../toast/toast.js';
|
import { toast } from '../toast/toast.js';
|
||||||
|
|
||||||
@@ -26,7 +29,9 @@ function notify(std: BlockStdScope, title: string, message: string) {
|
|||||||
// edit or undo or switch doc, close notify toast
|
// edit or undo or switch doc, close notify toast
|
||||||
const addHandler = doc.history.on('stack-item-added', closeNotify);
|
const addHandler = doc.history.on('stack-item-added', closeNotify);
|
||||||
const popHandler = doc.history.on('stack-item-popped', closeNotify);
|
const popHandler = doc.history.on('stack-item-popped', closeNotify);
|
||||||
const disposable = host.slots.unmounted.on(closeNotify);
|
const disposable = host.std
|
||||||
|
.get(EditorLifeCycleExtension)
|
||||||
|
.slots.unmounted.on(closeNotify);
|
||||||
|
|
||||||
notification.notify({
|
notification.notify({
|
||||||
title,
|
title,
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import { DisposableGroup, Slot } from '@blocksuite/global/slot';
|
||||||
|
|
||||||
|
import type { BlockStdScope } from '../scope/block-std-scope';
|
||||||
|
import { LifeCycleWatcher } from './lifecycle-watcher';
|
||||||
|
|
||||||
|
export class EditorLifeCycleExtension extends LifeCycleWatcher {
|
||||||
|
static override key = 'editor-life-cycle';
|
||||||
|
|
||||||
|
disposables = new DisposableGroup();
|
||||||
|
|
||||||
|
readonly slots = {
|
||||||
|
created: new Slot(),
|
||||||
|
mounted: new Slot(),
|
||||||
|
rendered: new Slot(),
|
||||||
|
unmounted: new Slot(),
|
||||||
|
};
|
||||||
|
|
||||||
|
constructor(override readonly std: BlockStdScope) {
|
||||||
|
super(std);
|
||||||
|
|
||||||
|
this.disposables.add(this.slots.created);
|
||||||
|
this.disposables.add(this.slots.mounted);
|
||||||
|
this.disposables.add(this.slots.rendered);
|
||||||
|
this.disposables.add(this.slots.unmounted);
|
||||||
|
}
|
||||||
|
|
||||||
|
override created() {
|
||||||
|
super.created();
|
||||||
|
this.slots.created.emit();
|
||||||
|
}
|
||||||
|
|
||||||
|
override mounted() {
|
||||||
|
super.mounted();
|
||||||
|
this.slots.mounted.emit();
|
||||||
|
}
|
||||||
|
|
||||||
|
override rendered() {
|
||||||
|
super.rendered();
|
||||||
|
this.slots.rendered.emit();
|
||||||
|
}
|
||||||
|
|
||||||
|
override unmounted() {
|
||||||
|
super.unmounted();
|
||||||
|
this.slots.unmounted.emit();
|
||||||
|
|
||||||
|
this.disposables.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
export * from './block-view.js';
|
export * from './block-view.js';
|
||||||
export * from './config.js';
|
export * from './config.js';
|
||||||
export * from './dnd/index.js';
|
export * from './dnd/index.js';
|
||||||
|
export * from './editor-life-cycle.js';
|
||||||
export * from './flavour.js';
|
export * from './flavour.js';
|
||||||
export * from './keymap.js';
|
export * from './keymap.js';
|
||||||
export * from './lifecycle-watcher.js';
|
export * from './lifecycle-watcher.js';
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { Clipboard } from '../clipboard/index.js';
|
|||||||
import { CommandManager } from '../command/index.js';
|
import { CommandManager } from '../command/index.js';
|
||||||
import { UIEventDispatcher } from '../event/index.js';
|
import { UIEventDispatcher } from '../event/index.js';
|
||||||
import { DndController } from '../extension/dnd/index.js';
|
import { DndController } from '../extension/dnd/index.js';
|
||||||
|
import { EditorLifeCycleExtension } from '../extension/editor-life-cycle.js';
|
||||||
import { GfxController } from '../gfx/controller.js';
|
import { GfxController } from '../gfx/controller.js';
|
||||||
import { GfxSelectionManager } from '../gfx/selection.js';
|
import { GfxSelectionManager } from '../gfx/selection.js';
|
||||||
import { SurfaceMiddlewareExtension } from '../gfx/surface-middleware.js';
|
import { SurfaceMiddlewareExtension } from '../gfx/surface-middleware.js';
|
||||||
@@ -41,6 +42,7 @@ const internalExtensions = [
|
|||||||
SurfaceMiddlewareExtension,
|
SurfaceMiddlewareExtension,
|
||||||
ViewManager,
|
ViewManager,
|
||||||
DndController,
|
DndController,
|
||||||
|
EditorLifeCycleExtension,
|
||||||
];
|
];
|
||||||
|
|
||||||
export class BlockStdScope {
|
export class BlockStdScope {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import {
|
|||||||
handleError,
|
handleError,
|
||||||
} from '@blocksuite/global/exceptions';
|
} from '@blocksuite/global/exceptions';
|
||||||
import { SignalWatcher, WithDisposable } from '@blocksuite/global/lit';
|
import { SignalWatcher, WithDisposable } from '@blocksuite/global/lit';
|
||||||
import { Slot } from '@blocksuite/global/slot';
|
|
||||||
import {
|
import {
|
||||||
type BlockModel,
|
type BlockModel,
|
||||||
Store,
|
Store,
|
||||||
@@ -90,10 +89,6 @@ export class EditorHost extends SignalWatcher(
|
|||||||
)}`;
|
)}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
readonly slots = {
|
|
||||||
unmounted: new Slot(),
|
|
||||||
};
|
|
||||||
|
|
||||||
get command(): CommandManager {
|
get command(): CommandManager {
|
||||||
return this.std.command;
|
return this.std.command;
|
||||||
}
|
}
|
||||||
@@ -131,8 +126,6 @@ export class EditorHost extends SignalWatcher(
|
|||||||
override disconnectedCallback() {
|
override disconnectedCallback() {
|
||||||
super.disconnectedCallback();
|
super.disconnectedCallback();
|
||||||
this.std.unmount();
|
this.std.unmount();
|
||||||
this.slots.unmounted.emit();
|
|
||||||
this.slots.unmounted.dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override async getUpdateComplete(): Promise<boolean> {
|
override async getUpdateComplete(): Promise<boolean> {
|
||||||
|
|||||||
@@ -330,7 +330,7 @@ type EditorType {
|
|||||||
name: String!
|
name: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
union ErrorDataUnion = AlreadyInSpaceDataType | BlobNotFoundDataType | CopilotContextFileNotSupportedDataType | CopilotDocNotFoundDataType | CopilotFailedToMatchContextDataType | CopilotFailedToModifyContextDataType | CopilotInvalidContextDataType | CopilotMessageNotFoundDataType | CopilotPromptNotFoundDataType | CopilotProviderSideErrorDataType | DocActionDeniedDataType | DocHistoryNotFoundDataType | DocNotFoundDataType | DocUpdateBlockedDataType | ExpectToGrantDocUserRolesDataType | ExpectToRevokeDocUserRolesDataType | ExpectToUpdateDocUserRoleDataType | GraphqlBadRequestDataType | InvalidEmailDataType | InvalidHistoryTimestampDataType | InvalidLicenseUpdateParamsDataType | InvalidOauthCallbackCodeDataType | InvalidPasswordLengthDataType | InvalidRuntimeConfigTypeDataType | MemberNotFoundInSpaceDataType | MissingOauthQueryParameterDataType | NotInSpaceDataType | QueryTooLongDataType | RuntimeConfigNotFoundDataType | SameSubscriptionRecurringDataType | SpaceAccessDeniedDataType | SpaceNotFoundDataType | SpaceOwnerNotFoundDataType | SpaceShouldHaveOnlyOneOwnerDataType | SubscriptionAlreadyExistsDataType | SubscriptionNotExistsDataType | SubscriptionPlanNotFoundDataType | UnknownOauthProviderDataType | UnsupportedClientVersionDataType | UnsupportedSubscriptionPlanDataType | VersionRejectedDataType | WorkspaceMembersExceedLimitToDowngradeDataType | WorkspacePermissionNotFoundDataType | WrongSignInCredentialsDataType
|
union ErrorDataUnion = AlreadyInSpaceDataType | BlobNotFoundDataType | CopilotContextFileNotSupportedDataType | CopilotDocNotFoundDataType | CopilotFailedToMatchContextDataType | CopilotFailedToModifyContextDataType | CopilotInvalidContextDataType | CopilotMessageNotFoundDataType | CopilotPromptNotFoundDataType | CopilotProviderSideErrorDataType | DocActionDeniedDataType | DocHistoryNotFoundDataType | DocNotFoundDataType | DocUpdateBlockedDataType | ExpectToGrantDocUserRolesDataType | ExpectToRevokeDocUserRolesDataType | ExpectToUpdateDocUserRoleDataType | GraphqlBadRequestDataType | InvalidEmailDataType | InvalidHistoryTimestampDataType | InvalidLicenseUpdateParamsDataType | InvalidOauthCallbackCodeDataType | InvalidPasswordLengthDataType | InvalidRuntimeConfigTypeDataType | MemberNotFoundInSpaceDataType | MissingOauthQueryParameterDataType | NotInSpaceDataType | QueryTooLongDataType | RuntimeConfigNotFoundDataType | SameSubscriptionRecurringDataType | SpaceAccessDeniedDataType | SpaceNotFoundDataType | SpaceOwnerNotFoundDataType | SpaceShouldHaveOnlyOneOwnerDataType | SubscriptionAlreadyExistsDataType | SubscriptionNotExistsDataType | SubscriptionPlanNotFoundDataType | UnknownOauthProviderDataType | UnsupportedClientVersionDataType | UnsupportedSubscriptionPlanDataType | ValidationErrorDataType | VersionRejectedDataType | WorkspaceMembersExceedLimitToDowngradeDataType | WorkspacePermissionNotFoundDataType | WrongSignInCredentialsDataType
|
||||||
|
|
||||||
enum ErrorNames {
|
enum ErrorNames {
|
||||||
ACCESS_DENIED
|
ACCESS_DENIED
|
||||||
@@ -1231,6 +1231,10 @@ type UserType {
|
|||||||
token: tokenType! @deprecated(reason: "use [/api/auth/sign-in?native=true] instead")
|
token: tokenType! @deprecated(reason: "use [/api/auth/sign-in?native=true] instead")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ValidationErrorDataType {
|
||||||
|
errors: String!
|
||||||
|
}
|
||||||
|
|
||||||
type VersionRejectedDataType {
|
type VersionRejectedDataType {
|
||||||
serverVersion: String!
|
serverVersion: String!
|
||||||
version: String!
|
version: String!
|
||||||
|
|||||||
Reference in New Issue
Block a user