pengx17
2024-06-05 09:33:18 +00:00
parent 928e133655
commit fa4e4c738a
12 changed files with 206 additions and 108 deletions

View File

@@ -18,13 +18,13 @@
"@affine/graphql": "workspace:*",
"@affine/i18n": "workspace:*",
"@affine/templates": "workspace:*",
"@blocksuite/block-std": "0.15.0-canary-202406041254-00772be",
"@blocksuite/blocks": "0.15.0-canary-202406041254-00772be",
"@blocksuite/global": "0.15.0-canary-202406041254-00772be",
"@blocksuite/block-std": "0.15.0-canary-202406050645-7721c3e",
"@blocksuite/blocks": "0.15.0-canary-202406050645-7721c3e",
"@blocksuite/global": "0.15.0-canary-202406050645-7721c3e",
"@blocksuite/icons": "2.1.52",
"@blocksuite/inline": "0.15.0-canary-202406041254-00772be",
"@blocksuite/presets": "0.15.0-canary-202406041254-00772be",
"@blocksuite/store": "0.15.0-canary-202406041254-00772be",
"@blocksuite/inline": "0.15.0-canary-202406050645-7721c3e",
"@blocksuite/presets": "0.15.0-canary-202406050645-7721c3e",
"@blocksuite/store": "0.15.0-canary-202406050645-7721c3e",
"@dnd-kit/core": "^6.1.0",
"@dnd-kit/modifiers": "^7.0.0",
"@dnd-kit/sortable": "^8.0.0",

View File

@@ -2,6 +2,7 @@ import {
createReactComponentFromLit,
useConfirmModal,
useLitPortalFactory,
usePromptModal,
} from '@affine/component';
import { useJournalInfoHelper } from '@affine/core/hooks/use-journal';
import { PeekViewService } from '@affine/core/modules/peek-view';
@@ -80,11 +81,12 @@ const usePatchSpecs = (page: Doc, specs: BlockSpec[]) => {
}, [page.collection]);
const confirmModal = useConfirmModal();
const openPromptModal = usePromptModal();
const patchedSpecs = useMemo(() => {
let patched = patchReferenceRenderer(specs, reactToLit, referenceRenderer);
patched = patchNotificationService(
patchReferenceRenderer(patched, reactToLit, referenceRenderer),
confirmModal
{ ...confirmModal, prompt: openPromptModal }
);
if (!page.readonly && runtimeConfig.enablePeekView) {
patched = patchPeekViewService(patched, peekViewService);
@@ -92,6 +94,7 @@ const usePatchSpecs = (page: Doc, specs: BlockSpec[]) => {
return patched;
}, [
confirmModal,
openPromptModal,
page.readonly,
peekViewService,
reactToLit,

View File

@@ -5,6 +5,7 @@ import {
toast,
type ToastOptions,
type useConfirmModal,
type usePromptModal,
} from '@affine/component';
import type { PeekViewService } from '@affine/core/modules/peek-view';
import type { ActivePeekView } from '@affine/core/modules/peek-view/entities/peek-view';
@@ -114,7 +115,13 @@ export function patchReferenceRenderer(
export function patchNotificationService(
specs: BlockSpec[],
{ closeConfirmModal, openConfirmModal }: ReturnType<typeof useConfirmModal>
{
closeConfirmModal,
openConfirmModal,
prompt,
}: ReturnType<typeof useConfirmModal> & {
prompt: ReturnType<typeof usePromptModal>;
}
) {
const rootSpec = specs.find(
spec => spec.schema.model.flavour === 'affine:page'
@@ -126,22 +133,10 @@ export function patchNotificationService(
patchSpecService(rootSpec, service => {
service.notificationService = {
confirm: async ({
title,
message,
confirmText,
cancelText,
abort,
}: {
title: string;
message: string | TemplateResult;
confirmText: string;
cancelText: string;
abort?: AbortSignal;
}) => {
confirm: async ({ title, message, confirmText, cancelText, abort }) => {
return new Promise<boolean>(resolve => {
openConfirmModal({
title,
title: toReactNode(title),
description: toReactNode(message),
confirmButtonOptions: {
children: confirmText,
@@ -161,6 +156,23 @@ export function patchNotificationService(
});
});
},
prompt: async ({
title,
message,
confirmText,
placeholder,
cancelText,
abort,
}) => {
return prompt({
message: toReactNode(message),
title: toReactNode(title),
confirmText,
cancelText,
placeholder,
abort,
});
},
toast: (message: string, options: ToastOptions) => {
return toast(message, options);
},
@@ -181,6 +193,12 @@ export function patchNotificationService(
{
title: toReactNode(notification.title),
message: toReactNode(notification.message),
action: notification.action?.onClick
? {
label: toReactNode(notification.action?.label),
onClick: notification.action.onClick,
}
: undefined,
},
{
duration: notification.duration || 0,