mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-27 02:42:25 +08:00
refactor(editor): add middlewares in shared adapter (#9395)
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
import { isPeekable, Peekable } from '@blocksuite/affine-components/peek';
|
||||
import {
|
||||
REFERENCE_NODE,
|
||||
RefNodeSlotsProvider,
|
||||
} from '@blocksuite/affine-components/rich-text';
|
||||
import { RefNodeSlotsProvider } from '@blocksuite/affine-components/rich-text';
|
||||
import type {
|
||||
DocMode,
|
||||
EmbedLinkedDocModel,
|
||||
@@ -11,6 +8,7 @@ import type {
|
||||
import {
|
||||
EMBED_CARD_HEIGHT,
|
||||
EMBED_CARD_WIDTH,
|
||||
REFERENCE_NODE,
|
||||
} from '@blocksuite/affine-shared/consts';
|
||||
import {
|
||||
DocDisplayMetaProvider,
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import { Peekable } from '@blocksuite/affine-components/peek';
|
||||
import {
|
||||
REFERENCE_NODE,
|
||||
RefNodeSlotsProvider,
|
||||
} from '@blocksuite/affine-components/rich-text';
|
||||
import { RefNodeSlotsProvider } from '@blocksuite/affine-components/rich-text';
|
||||
import {
|
||||
type AliasInfo,
|
||||
type DocMode,
|
||||
@@ -10,6 +7,7 @@ import {
|
||||
NoteDisplayMode,
|
||||
type ReferenceInfo,
|
||||
} from '@blocksuite/affine-model';
|
||||
import { REFERENCE_NODE } from '@blocksuite/affine-shared/consts';
|
||||
import {
|
||||
DocDisplayMetaProvider,
|
||||
DocModeProvider,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
export { DEFAULT_DOC_NAME, REFERENCE_NODE } from './consts.js';
|
||||
export { AffineLink, toggleLinkPopup } from './link-node/index.js';
|
||||
export * from './reference-node/reference-config.js';
|
||||
export { AffineReference } from './reference-node/reference-node.js';
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { ReferenceInfo } from '@blocksuite/affine-model';
|
||||
import { REFERENCE_NODE } from '@blocksuite/affine-shared/consts';
|
||||
import {
|
||||
type LinkEventType,
|
||||
type TelemetryEvent,
|
||||
@@ -22,7 +23,6 @@ import { live } from 'lit/directives/live.js';
|
||||
|
||||
import type { EditorIconButton } from '../../../../../toolbar/index.js';
|
||||
import type { AffineInlineEditor } from '../../affine-inline-specs.js';
|
||||
import { REFERENCE_NODE } from '../consts.js';
|
||||
|
||||
export class ReferenceAliasPopup extends SignalWatcher(
|
||||
WithDisposable(ShadowlessElement)
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import type { ReferenceInfo } from '@blocksuite/affine-model';
|
||||
import {
|
||||
DEFAULT_DOC_NAME,
|
||||
REFERENCE_NODE,
|
||||
} from '@blocksuite/affine-shared/consts';
|
||||
import { DocDisplayMetaProvider } from '@blocksuite/affine-shared/services';
|
||||
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
||||
import {
|
||||
@@ -32,7 +36,6 @@ import { HoverController } from '../../../../../hover/index.js';
|
||||
import { Peekable } from '../../../../../peek/index.js';
|
||||
import { RefNodeSlotsProvider } from '../../../../extension/index.js';
|
||||
import { affineTextStyles } from '../affine-text.js';
|
||||
import { DEFAULT_DOC_NAME, REFERENCE_NODE } from '../consts.js';
|
||||
import type { ReferenceNodeConfigProvider } from './reference-config.js';
|
||||
import { toggleReferencePopup } from './reference-popup.js';
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { type AffineInlineEditor, REFERENCE_NODE } from './inline/index.js';
|
||||
import { REFERENCE_NODE } from '@blocksuite/affine-shared/consts';
|
||||
|
||||
import { type AffineInlineEditor } from './inline/index.js';
|
||||
|
||||
export function insertLinkedNode({
|
||||
inlineEditor,
|
||||
|
||||
@@ -29,6 +29,7 @@ export {
|
||||
MarkdownASTToDeltaMatcherIdentifier,
|
||||
MarkdownDeltaConverter,
|
||||
} from './markdown';
|
||||
export * from './middlewares';
|
||||
export {
|
||||
BlockNotionHtmlAdapterExtension,
|
||||
type BlockNotionHtmlAdapterMatcher,
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import type { EditorHost, TextRangePoint } from '@blocksuite/block-std';
|
||||
import type {
|
||||
BlockStdScope,
|
||||
EditorHost,
|
||||
TextRangePoint,
|
||||
} from '@blocksuite/block-std';
|
||||
import type {
|
||||
BlockSnapshot,
|
||||
DraftModel,
|
||||
@@ -6,7 +10,7 @@ import type {
|
||||
JobSlots,
|
||||
} from '@blocksuite/store';
|
||||
|
||||
import { matchFlavours } from '../../../_common/utils/index.js';
|
||||
import { matchFlavours } from '../../utils';
|
||||
|
||||
const handlePoint = (
|
||||
point: TextRangePoint,
|
||||
@@ -47,7 +51,7 @@ const sliceText = (slots: JobSlots, std: EditorHost['std']) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const copyMiddleware = (std: EditorHost['std']): JobMiddleware => {
|
||||
export const copyMiddleware = (std: BlockStdScope): JobMiddleware => {
|
||||
return ({ slots }) => {
|
||||
sliceText(slots, std);
|
||||
};
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './copy';
|
||||
export * from './paste';
|
||||
@@ -1,12 +1,9 @@
|
||||
import { REFERENCE_NODE } from '@blocksuite/affine-components/rich-text';
|
||||
import type { ParagraphBlockModel } from '@blocksuite/affine-model';
|
||||
import {
|
||||
ParseDocUrlProvider,
|
||||
type ParseDocUrlService,
|
||||
TelemetryProvider,
|
||||
} from '@blocksuite/affine-shared/services';
|
||||
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
||||
import { referenceToNode } from '@blocksuite/affine-shared/utils';
|
||||
type DocMode,
|
||||
DocModes,
|
||||
type ParagraphBlockModel,
|
||||
type ReferenceInfo,
|
||||
} from '@blocksuite/affine-model';
|
||||
import {
|
||||
BLOCK_ID_ATTR,
|
||||
type BlockComponent,
|
||||
@@ -27,8 +24,14 @@ import {
|
||||
type Text,
|
||||
} from '@blocksuite/store';
|
||||
|
||||
import { matchFlavours } from '../../../_common/utils/index.js';
|
||||
import { extractSearchParams } from '../../../_common/utils/url.js';
|
||||
import { REFERENCE_NODE } from '../../consts';
|
||||
import {
|
||||
ParseDocUrlProvider,
|
||||
type ParseDocUrlService,
|
||||
TelemetryProvider,
|
||||
} from '../../services';
|
||||
import type { AffineTextAttributes } from '../../types';
|
||||
import { matchFlavours, referenceToNode } from '../../utils';
|
||||
|
||||
function findLastMatchingNode(
|
||||
root: BlockSnapshot[],
|
||||
@@ -527,3 +530,40 @@ export const pasteMiddleware = (std: EditorHost['std']): JobMiddleware => {
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
function extractSearchParams(link: string) {
|
||||
try {
|
||||
const url = new URL(link);
|
||||
const mode = url.searchParams.get('mode') as DocMode | undefined;
|
||||
|
||||
if (mode && DocModes.includes(mode)) {
|
||||
const params: ReferenceInfo['params'] = { mode: mode as DocMode };
|
||||
const blockIds = url.searchParams
|
||||
.get('blockIds')
|
||||
?.trim()
|
||||
.split(',')
|
||||
.map(id => id.trim())
|
||||
.filter(id => id.length);
|
||||
const elementIds = url.searchParams
|
||||
.get('elementIds')
|
||||
?.trim()
|
||||
.split(',')
|
||||
.map(id => id.trim())
|
||||
.filter(id => id.length);
|
||||
|
||||
if (blockIds?.length) {
|
||||
params.blockIds = blockIds;
|
||||
}
|
||||
|
||||
if (elementIds?.length) {
|
||||
params.elementIds = elementIds;
|
||||
}
|
||||
|
||||
return { params };
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -65,3 +65,4 @@ export const CANVAS_EXPORT_IGNORE_TAGS = [
|
||||
|
||||
export * from './bracket-pairs.js';
|
||||
export * from './note.js';
|
||||
export * from './text.js';
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
import {
|
||||
type DocMode,
|
||||
DocModes,
|
||||
type ReferenceInfo,
|
||||
} from '@blocksuite/affine-model';
|
||||
|
||||
export function extractSearchParams(link: string) {
|
||||
try {
|
||||
const url = new URL(link);
|
||||
const mode = url.searchParams.get('mode') as DocMode | undefined;
|
||||
|
||||
if (mode && DocModes.includes(mode)) {
|
||||
const params: ReferenceInfo['params'] = { mode: mode as DocMode };
|
||||
const blockIds = url.searchParams
|
||||
.get('blockIds')
|
||||
?.trim()
|
||||
.split(',')
|
||||
.map(id => id.trim())
|
||||
.filter(id => id.length);
|
||||
const elementIds = url.searchParams
|
||||
.get('elementIds')
|
||||
?.trim()
|
||||
.split(',')
|
||||
.map(id => id.trim())
|
||||
.filter(id => id.length);
|
||||
|
||||
if (blockIds?.length) {
|
||||
params.blockIds = blockIds;
|
||||
}
|
||||
|
||||
if (elementIds?.length) {
|
||||
params.elementIds = elementIds;
|
||||
}
|
||||
|
||||
return { params };
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
HtmlAdapter,
|
||||
pasteMiddleware,
|
||||
PlainTextAdapter,
|
||||
} from '@blocksuite/affine-shared/adapters';
|
||||
import {
|
||||
@@ -9,8 +10,6 @@ import {
|
||||
} from '@blocksuite/block-std';
|
||||
import { assertExists, DisposableGroup } from '@blocksuite/global/utils';
|
||||
|
||||
import { pasteMiddleware } from '../../root-block/clipboard/middlewares/index.js';
|
||||
|
||||
export class CodeClipboardController {
|
||||
private _clipboard!: Clipboard;
|
||||
|
||||
|
||||
@@ -5,7 +5,10 @@ import {
|
||||
} from '@blocksuite/affine-components/rich-text';
|
||||
import type { CodeBlockModel } from '@blocksuite/affine-model';
|
||||
import { BRACKET_PAIRS, NOTE_SELECTOR } from '@blocksuite/affine-shared/consts';
|
||||
import { NotificationProvider } from '@blocksuite/affine-shared/services';
|
||||
import {
|
||||
DocModeProvider,
|
||||
NotificationProvider,
|
||||
} from '@blocksuite/affine-shared/services';
|
||||
import { getViewportElement } from '@blocksuite/affine-shared/utils';
|
||||
import type { BlockComponent } from '@blocksuite/block-std';
|
||||
import { getInlineRangeProvider } from '@blocksuite/block-std';
|
||||
@@ -24,7 +27,6 @@ import { query } from 'lit/decorators.js';
|
||||
import { classMap } from 'lit/directives/class-map.js';
|
||||
import type { ThemedToken } from 'shiki';
|
||||
|
||||
import { EdgelessRootBlockComponent } from '../root-block/edgeless/edgeless-root-block.js';
|
||||
import { CodeClipboardController } from './clipboard/index.js';
|
||||
import { CodeBlockInlineManagerExtension } from './code-block-inline.js';
|
||||
import type { CodeBlockService } from './code-block-service.js';
|
||||
@@ -72,9 +74,8 @@ export class CodeBlockComponent extends CaptionedBlockComponent<
|
||||
}
|
||||
|
||||
override get topContenteditableElement() {
|
||||
if (this.rootComponent instanceof EdgelessRootBlockComponent) {
|
||||
const el = this.closest<BlockComponent>(NOTE_SELECTOR);
|
||||
return el;
|
||||
if (this.std.get(DocModeProvider).getEditorMode() === 'edgeless') {
|
||||
return this.closest<BlockComponent>(NOTE_SELECTOR);
|
||||
}
|
||||
return this.rootComponent;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { REFERENCE_NODE } from '@blocksuite/affine-components/rich-text';
|
||||
import type {
|
||||
DatabaseBlockModel,
|
||||
RootBlockModel,
|
||||
} from '@blocksuite/affine-model';
|
||||
import { REFERENCE_NODE } from '@blocksuite/affine-shared/consts';
|
||||
import { TelemetryProvider } from '@blocksuite/affine-shared/services';
|
||||
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
||||
import {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import {
|
||||
AttachmentAdapter,
|
||||
copyMiddleware,
|
||||
HtmlAdapter,
|
||||
ImageAdapter,
|
||||
NotionTextAdapter,
|
||||
pasteMiddleware,
|
||||
} from '@blocksuite/affine-shared/adapters';
|
||||
import type { BlockComponent, UIEventHandler } from '@blocksuite/block-std';
|
||||
import { DisposableGroup } from '@blocksuite/global/utils';
|
||||
@@ -15,7 +17,6 @@ import {
|
||||
titleMiddleware,
|
||||
} from '../../_common/transformers/middlewares.js';
|
||||
import { ClipboardAdapter } from './adapter.js';
|
||||
import { copyMiddleware, pasteMiddleware } from './middlewares/index.js';
|
||||
|
||||
export class PageClipboard {
|
||||
private readonly _copySelected = (onCopy?: () => void) => {
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from './copy.js';
|
||||
export * from './paste.js';
|
||||
@@ -3,10 +3,10 @@ import { getSurfaceBlock } from '@blocksuite/affine-block-surface';
|
||||
import {
|
||||
getInlineEditorByModel,
|
||||
insertContent,
|
||||
REFERENCE_NODE,
|
||||
} from '@blocksuite/affine-components/rich-text';
|
||||
import { toast } from '@blocksuite/affine-components/toast';
|
||||
import type { FrameBlockModel } from '@blocksuite/affine-model';
|
||||
import { REFERENCE_NODE } from '@blocksuite/affine-shared/consts';
|
||||
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
||||
import {
|
||||
createDefaultDoc,
|
||||
|
||||
@@ -28,7 +28,6 @@ import {
|
||||
import {
|
||||
getInlineEditorByModel,
|
||||
insertContent,
|
||||
REFERENCE_NODE,
|
||||
textConversionConfigs,
|
||||
textFormatConfigs,
|
||||
} from '@blocksuite/affine-components/rich-text';
|
||||
@@ -37,6 +36,7 @@ import type {
|
||||
FrameBlockModel,
|
||||
ParagraphBlockModel,
|
||||
} from '@blocksuite/affine-model';
|
||||
import { REFERENCE_NODE } from '@blocksuite/affine-shared/consts';
|
||||
import { TelemetryProvider } from '@blocksuite/affine-shared/services';
|
||||
import {
|
||||
createDefaultDoc,
|
||||
|
||||
Reference in New Issue
Block a user