-
-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
1,544 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './linked-doc.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import type { BlockStdScope } from '@blocksuite/block-std'; | ||
|
||
import { NotificationProvider } from '@blocksuite/affine-shared/services'; | ||
|
||
import { toast } from '../toast/toast.js'; | ||
|
||
function notify(std: BlockStdScope, title: string, message: string) { | ||
const notification = std.getOptional(NotificationProvider); | ||
const { doc, host } = std; | ||
|
||
if (!notification) { | ||
toast(host, title); | ||
return; | ||
} | ||
|
||
const abortController = new AbortController(); | ||
const clear = () => { | ||
doc.history.off('stack-item-added', addHandler); | ||
doc.history.off('stack-item-popped', popHandler); | ||
disposable.dispose(); | ||
}; | ||
const closeNotify = () => { | ||
abortController.abort(); | ||
clear(); | ||
}; | ||
|
||
// edit or undo or switch doc, close notify toast | ||
const addHandler = doc.history.on('stack-item-added', closeNotify); | ||
const popHandler = doc.history.on('stack-item-popped', closeNotify); | ||
const disposable = host.slots.unmounted.on(closeNotify); | ||
|
||
notification.notify({ | ||
title, | ||
message, | ||
accent: 'info', | ||
duration: 10 * 1000, | ||
action: { | ||
label: 'Undo', | ||
onClick: () => { | ||
doc.undo(); | ||
clear(); | ||
}, | ||
}, | ||
abort: abortController.signal, | ||
onClose: clear, | ||
}); | ||
} | ||
|
||
export function notifyLinkedDocSwitchedToCard(std: BlockStdScope) { | ||
notify( | ||
std, | ||
'View Updated', | ||
'The alias modification has disabled sync. The embed has been updated to a card view.' | ||
); | ||
} | ||
|
||
export function notifyLinkedDocSwitchedToEmbed(std: BlockStdScope) { | ||
notify( | ||
std, | ||
'Embed View Restored', | ||
'Custom alias removed. The linked doc now displays the original title and description.' | ||
); | ||
} | ||
|
||
export function notifyLinkedDocClearedAliases(std: BlockStdScope) { | ||
notify( | ||
std, | ||
'Reset successful', | ||
`Card view has been restored to original doc title and description. All custom aliases have been removed.` | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.