refactor(editor): add helper function for undo notification (#11903)

### What Changes
- Refactors the `notify` function call with undo button. It is called `notifyWithUndo`, which can  associate the visibility of the `NotificationCard` with the top undo item in history stack, such as undo by shortcut `Cmd+Z`.
- change icon of the "Insert into page" button. Close [BS-3267](https://linear.app/affine-design/issue/BS-3267/frame和group的insert-into-page图标也更换一下)
This commit is contained in:
L-Sun
2025-04-23 02:43:56 +00:00
committed by L-Sun
parent 27ff9ab9f4
commit 9dbdd4b7ba
14 changed files with 136 additions and 157 deletions

View File

@@ -31,10 +31,7 @@ import {
LinkedPageIcon,
ScissorsIcon,
} from '@blocksuite/icons/lit';
import {
BlockFlavourIdentifier,
EditorLifeCycleExtension,
} from '@blocksuite/std';
import { BlockFlavourIdentifier } from '@blocksuite/std';
import type { ExtensionType } from '@blocksuite/store';
import { computed } from '@preact/signals-core';
import { html } from 'lit';
@@ -504,34 +501,6 @@ function setDisplayMode(
ctx.selection.clear();
}
const abortController = new AbortController();
const clear = () => {
ctx.history.off('stack-item-added', addHandler);
ctx.history.off('stack-item-popped', popHandler);
disposable.unsubscribe();
};
const closeNotify = () => {
abortController.abort();
clear();
};
const addHandler = ctx.history.on('stack-item-added', closeNotify);
const popHandler = ctx.history.on('stack-item-popped', closeNotify);
const disposable = ctx.std
.get(EditorLifeCycleExtension)
.slots.unmounted.subscribe(closeNotify);
const undo = () => {
ctx.store.undo();
closeNotify();
};
const viewInToc = () => {
const sidebar = ctx.std.getOptional(SidebarExtensionIdentifier);
sidebar?.open('outline');
closeNotify();
};
const data =
newMode === NoteDisplayMode.EdgelessOnly
? {
@@ -544,27 +513,21 @@ function setDisplayMode(
};
const notification = ctx.std.getOptional(NotificationProvider);
notification?.notify({
notification?.notifyWithUndoAction({
title: data.title,
message: `${data.message} Find it in the TOC for quick navigation.`,
accent: 'success',
duration: 5 * 1000,
actions: [
{
key: 'undo-display-in-page',
label: 'Undo',
onClick: () => undo(),
},
{
key: 'view-in-toc',
label: 'View in Toc',
onClick: () => viewInToc(),
onClick: () => {
const sidebar = ctx.std.getOptional(SidebarExtensionIdentifier);
sidebar?.open('outline');
},
},
],
abort: abortController.signal,
onClose: () => {
clear();
},
});
ctx.track('NoteDisplayModeChanged', {

View File

@@ -58,7 +58,7 @@ export const quickActionConfig: QuickActionConfig[] = [
draftedModels,
title
).catch(console.error);
notifyDocCreated(std, doc);
notifyDocCreated(std);
})
.catch(console.error);
},