mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-11 05:58:56 +08:00
refact(editor): clipboard config should be in foundation (#12038)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Enhanced clipboard support with multiple adapter configurations for various MIME types, improving clipboard handling and compatibility. - **Refactor** - Relocated clipboard adapter configurations to a new location for better organization and maintainability. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -1,12 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
AttachmentAdapter,
|
|
||||||
ClipboardAdapter,
|
|
||||||
copyMiddleware,
|
copyMiddleware,
|
||||||
defaultImageProxyMiddleware,
|
defaultImageProxyMiddleware,
|
||||||
HtmlAdapter,
|
|
||||||
ImageAdapter,
|
|
||||||
MixTextAdapter,
|
|
||||||
NotionTextAdapter,
|
|
||||||
titleMiddleware,
|
titleMiddleware,
|
||||||
} from '@blocksuite/affine-shared/adapters';
|
} from '@blocksuite/affine-shared/adapters';
|
||||||
import {
|
import {
|
||||||
@@ -15,67 +9,7 @@ import {
|
|||||||
getSelectedModelsCommand,
|
getSelectedModelsCommand,
|
||||||
} from '@blocksuite/affine-shared/commands';
|
} from '@blocksuite/affine-shared/commands';
|
||||||
import { DisposableGroup } from '@blocksuite/global/disposable';
|
import { DisposableGroup } from '@blocksuite/global/disposable';
|
||||||
import {
|
import { LifeCycleWatcher, type UIEventHandler } from '@blocksuite/std';
|
||||||
ClipboardAdapterConfigExtension,
|
|
||||||
LifeCycleWatcher,
|
|
||||||
type UIEventHandler,
|
|
||||||
} from '@blocksuite/std';
|
|
||||||
import type { ExtensionType } from '@blocksuite/store';
|
|
||||||
|
|
||||||
const SnapshotClipboardConfig = ClipboardAdapterConfigExtension({
|
|
||||||
mimeType: ClipboardAdapter.MIME,
|
|
||||||
adapter: ClipboardAdapter,
|
|
||||||
priority: 100,
|
|
||||||
});
|
|
||||||
|
|
||||||
const NotionClipboardConfig = ClipboardAdapterConfigExtension({
|
|
||||||
mimeType: 'text/_notion-text-production',
|
|
||||||
adapter: NotionTextAdapter,
|
|
||||||
priority: 95,
|
|
||||||
});
|
|
||||||
|
|
||||||
const HtmlClipboardConfig = ClipboardAdapterConfigExtension({
|
|
||||||
mimeType: 'text/html',
|
|
||||||
adapter: HtmlAdapter,
|
|
||||||
priority: 90,
|
|
||||||
});
|
|
||||||
|
|
||||||
const imageClipboardConfigs = [
|
|
||||||
'image/apng',
|
|
||||||
'image/avif',
|
|
||||||
'image/gif',
|
|
||||||
'image/jpeg',
|
|
||||||
'image/png',
|
|
||||||
'image/svg+xml',
|
|
||||||
'image/webp',
|
|
||||||
].map(mimeType => {
|
|
||||||
return ClipboardAdapterConfigExtension({
|
|
||||||
mimeType,
|
|
||||||
adapter: ImageAdapter,
|
|
||||||
priority: 80,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
const PlainTextClipboardConfig = ClipboardAdapterConfigExtension({
|
|
||||||
mimeType: 'text/plain',
|
|
||||||
adapter: MixTextAdapter,
|
|
||||||
priority: 70,
|
|
||||||
});
|
|
||||||
|
|
||||||
const AttachmentClipboardConfig = ClipboardAdapterConfigExtension({
|
|
||||||
mimeType: '*/*',
|
|
||||||
adapter: AttachmentAdapter,
|
|
||||||
priority: 60,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const clipboardConfigs: ExtensionType[] = [
|
|
||||||
SnapshotClipboardConfig,
|
|
||||||
NotionClipboardConfig,
|
|
||||||
HtmlClipboardConfig,
|
|
||||||
...imageClipboardConfigs,
|
|
||||||
PlainTextClipboardConfig,
|
|
||||||
AttachmentClipboardConfig,
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ReadOnlyClipboard is a class that provides a read-only clipboard for the root block.
|
* ReadOnlyClipboard is a class that provides a read-only clipboard for the root block.
|
||||||
|
|||||||
@@ -4,14 +4,12 @@ import { BlockFlavourIdentifier, FlavourExtension } from '@blocksuite/std';
|
|||||||
import type { ExtensionType } from '@blocksuite/store';
|
import type { ExtensionType } from '@blocksuite/store';
|
||||||
|
|
||||||
import { RootBlockAdapterExtensions } from '../adapters/extension';
|
import { RootBlockAdapterExtensions } from '../adapters/extension';
|
||||||
import { clipboardConfigs } from '../clipboard';
|
|
||||||
import { builtinToolbarConfig } from '../configs/toolbar';
|
import { builtinToolbarConfig } from '../configs/toolbar';
|
||||||
import { fallbackKeymap } from '../keyboard/keymap';
|
import { fallbackKeymap } from '../keyboard/keymap';
|
||||||
|
|
||||||
export const CommonSpecs: ExtensionType[] = [
|
export const CommonSpecs: ExtensionType[] = [
|
||||||
FlavourExtension('affine:page'),
|
FlavourExtension('affine:page'),
|
||||||
...RootBlockAdapterExtensions,
|
...RootBlockAdapterExtensions,
|
||||||
...clipboardConfigs,
|
|
||||||
fallbackKeymap,
|
fallbackKeymap,
|
||||||
|
|
||||||
ToolbarModuleExtension({
|
ToolbarModuleExtension({
|
||||||
|
|||||||
@@ -3,6 +3,14 @@ import {
|
|||||||
type ViewExtensionContext,
|
type ViewExtensionContext,
|
||||||
ViewExtensionProvider,
|
ViewExtensionProvider,
|
||||||
} from '@blocksuite/affine-ext-loader';
|
} from '@blocksuite/affine-ext-loader';
|
||||||
|
import {
|
||||||
|
AttachmentAdapter,
|
||||||
|
ClipboardAdapter,
|
||||||
|
HtmlAdapter,
|
||||||
|
ImageAdapter,
|
||||||
|
MixTextAdapter,
|
||||||
|
NotionTextAdapter,
|
||||||
|
} from '@blocksuite/affine-shared/adapters';
|
||||||
import {
|
import {
|
||||||
AutoClearSelectionService,
|
AutoClearSelectionService,
|
||||||
DefaultOpenDocExtension,
|
DefaultOpenDocExtension,
|
||||||
@@ -16,10 +24,67 @@ import {
|
|||||||
ThemeService,
|
ThemeService,
|
||||||
ToolbarRegistryExtension,
|
ToolbarRegistryExtension,
|
||||||
} from '@blocksuite/affine-shared/services';
|
} from '@blocksuite/affine-shared/services';
|
||||||
|
import { ClipboardAdapterConfigExtension } from '@blocksuite/std';
|
||||||
import { InteractivityManager, ToolController } from '@blocksuite/std/gfx';
|
import { InteractivityManager, ToolController } from '@blocksuite/std/gfx';
|
||||||
|
import type { ExtensionType } from '@blocksuite/store';
|
||||||
|
|
||||||
import { effects } from './effects';
|
import { effects } from './effects';
|
||||||
|
|
||||||
|
const SnapshotClipboardConfig = ClipboardAdapterConfigExtension({
|
||||||
|
mimeType: ClipboardAdapter.MIME,
|
||||||
|
adapter: ClipboardAdapter,
|
||||||
|
priority: 100,
|
||||||
|
});
|
||||||
|
|
||||||
|
const NotionClipboardConfig = ClipboardAdapterConfigExtension({
|
||||||
|
mimeType: 'text/_notion-text-production',
|
||||||
|
adapter: NotionTextAdapter,
|
||||||
|
priority: 95,
|
||||||
|
});
|
||||||
|
|
||||||
|
const HtmlClipboardConfig = ClipboardAdapterConfigExtension({
|
||||||
|
mimeType: 'text/html',
|
||||||
|
adapter: HtmlAdapter,
|
||||||
|
priority: 90,
|
||||||
|
});
|
||||||
|
|
||||||
|
const imageClipboardConfigs = [
|
||||||
|
'image/apng',
|
||||||
|
'image/avif',
|
||||||
|
'image/gif',
|
||||||
|
'image/jpeg',
|
||||||
|
'image/png',
|
||||||
|
'image/svg+xml',
|
||||||
|
'image/webp',
|
||||||
|
].map(mimeType => {
|
||||||
|
return ClipboardAdapterConfigExtension({
|
||||||
|
mimeType,
|
||||||
|
adapter: ImageAdapter,
|
||||||
|
priority: 80,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const PlainTextClipboardConfig = ClipboardAdapterConfigExtension({
|
||||||
|
mimeType: 'text/plain',
|
||||||
|
adapter: MixTextAdapter,
|
||||||
|
priority: 70,
|
||||||
|
});
|
||||||
|
|
||||||
|
const AttachmentClipboardConfig = ClipboardAdapterConfigExtension({
|
||||||
|
mimeType: '*/*',
|
||||||
|
adapter: AttachmentAdapter,
|
||||||
|
priority: 60,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const clipboardConfigs: ExtensionType[] = [
|
||||||
|
SnapshotClipboardConfig,
|
||||||
|
NotionClipboardConfig,
|
||||||
|
HtmlClipboardConfig,
|
||||||
|
...imageClipboardConfigs,
|
||||||
|
PlainTextClipboardConfig,
|
||||||
|
AttachmentClipboardConfig,
|
||||||
|
];
|
||||||
|
|
||||||
export class FoundationViewExtension extends ViewExtensionProvider {
|
export class FoundationViewExtension extends ViewExtensionProvider {
|
||||||
override name = 'foundation';
|
override name = 'foundation';
|
||||||
|
|
||||||
@@ -45,6 +110,7 @@ export class FoundationViewExtension extends ViewExtensionProvider {
|
|||||||
ToolbarRegistryExtension,
|
ToolbarRegistryExtension,
|
||||||
AutoClearSelectionService,
|
AutoClearSelectionService,
|
||||||
]);
|
]);
|
||||||
|
context.register(clipboardConfigs);
|
||||||
if (this.isEdgeless(context.scope)) {
|
if (this.isEdgeless(context.scope)) {
|
||||||
context.register([InteractivityManager, ToolController]);
|
context.register([InteractivityManager, ToolController]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user