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 { isPeekable, Peekable } from '@blocksuite/affine-components/peek';
|
||||||
import {
|
import { RefNodeSlotsProvider } from '@blocksuite/affine-components/rich-text';
|
||||||
REFERENCE_NODE,
|
|
||||||
RefNodeSlotsProvider,
|
|
||||||
} from '@blocksuite/affine-components/rich-text';
|
|
||||||
import type {
|
import type {
|
||||||
DocMode,
|
DocMode,
|
||||||
EmbedLinkedDocModel,
|
EmbedLinkedDocModel,
|
||||||
@@ -11,6 +8,7 @@ import type {
|
|||||||
import {
|
import {
|
||||||
EMBED_CARD_HEIGHT,
|
EMBED_CARD_HEIGHT,
|
||||||
EMBED_CARD_WIDTH,
|
EMBED_CARD_WIDTH,
|
||||||
|
REFERENCE_NODE,
|
||||||
} from '@blocksuite/affine-shared/consts';
|
} from '@blocksuite/affine-shared/consts';
|
||||||
import {
|
import {
|
||||||
DocDisplayMetaProvider,
|
DocDisplayMetaProvider,
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
import { Peekable } from '@blocksuite/affine-components/peek';
|
import { Peekable } from '@blocksuite/affine-components/peek';
|
||||||
import {
|
import { RefNodeSlotsProvider } from '@blocksuite/affine-components/rich-text';
|
||||||
REFERENCE_NODE,
|
|
||||||
RefNodeSlotsProvider,
|
|
||||||
} from '@blocksuite/affine-components/rich-text';
|
|
||||||
import {
|
import {
|
||||||
type AliasInfo,
|
type AliasInfo,
|
||||||
type DocMode,
|
type DocMode,
|
||||||
@@ -10,6 +7,7 @@ import {
|
|||||||
NoteDisplayMode,
|
NoteDisplayMode,
|
||||||
type ReferenceInfo,
|
type ReferenceInfo,
|
||||||
} from '@blocksuite/affine-model';
|
} from '@blocksuite/affine-model';
|
||||||
|
import { REFERENCE_NODE } from '@blocksuite/affine-shared/consts';
|
||||||
import {
|
import {
|
||||||
DocDisplayMetaProvider,
|
DocDisplayMetaProvider,
|
||||||
DocModeProvider,
|
DocModeProvider,
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
export { DEFAULT_DOC_NAME, REFERENCE_NODE } from './consts.js';
|
|
||||||
export { AffineLink, toggleLinkPopup } from './link-node/index.js';
|
export { AffineLink, toggleLinkPopup } from './link-node/index.js';
|
||||||
export * from './reference-node/reference-config.js';
|
export * from './reference-node/reference-config.js';
|
||||||
export { AffineReference } from './reference-node/reference-node.js';
|
export { AffineReference } from './reference-node/reference-node.js';
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { ReferenceInfo } from '@blocksuite/affine-model';
|
import type { ReferenceInfo } from '@blocksuite/affine-model';
|
||||||
|
import { REFERENCE_NODE } from '@blocksuite/affine-shared/consts';
|
||||||
import {
|
import {
|
||||||
type LinkEventType,
|
type LinkEventType,
|
||||||
type TelemetryEvent,
|
type TelemetryEvent,
|
||||||
@@ -22,7 +23,6 @@ import { live } from 'lit/directives/live.js';
|
|||||||
|
|
||||||
import type { EditorIconButton } from '../../../../../toolbar/index.js';
|
import type { EditorIconButton } from '../../../../../toolbar/index.js';
|
||||||
import type { AffineInlineEditor } from '../../affine-inline-specs.js';
|
import type { AffineInlineEditor } from '../../affine-inline-specs.js';
|
||||||
import { REFERENCE_NODE } from '../consts.js';
|
|
||||||
|
|
||||||
export class ReferenceAliasPopup extends SignalWatcher(
|
export class ReferenceAliasPopup extends SignalWatcher(
|
||||||
WithDisposable(ShadowlessElement)
|
WithDisposable(ShadowlessElement)
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
import type { ReferenceInfo } from '@blocksuite/affine-model';
|
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 { DocDisplayMetaProvider } from '@blocksuite/affine-shared/services';
|
||||||
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
||||||
import {
|
import {
|
||||||
@@ -32,7 +36,6 @@ import { HoverController } from '../../../../../hover/index.js';
|
|||||||
import { Peekable } from '../../../../../peek/index.js';
|
import { Peekable } from '../../../../../peek/index.js';
|
||||||
import { RefNodeSlotsProvider } from '../../../../extension/index.js';
|
import { RefNodeSlotsProvider } from '../../../../extension/index.js';
|
||||||
import { affineTextStyles } from '../affine-text.js';
|
import { affineTextStyles } from '../affine-text.js';
|
||||||
import { DEFAULT_DOC_NAME, REFERENCE_NODE } from '../consts.js';
|
|
||||||
import type { ReferenceNodeConfigProvider } from './reference-config.js';
|
import type { ReferenceNodeConfigProvider } from './reference-config.js';
|
||||||
import { toggleReferencePopup } from './reference-popup.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({
|
export function insertLinkedNode({
|
||||||
inlineEditor,
|
inlineEditor,
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ export {
|
|||||||
MarkdownASTToDeltaMatcherIdentifier,
|
MarkdownASTToDeltaMatcherIdentifier,
|
||||||
MarkdownDeltaConverter,
|
MarkdownDeltaConverter,
|
||||||
} from './markdown';
|
} from './markdown';
|
||||||
|
export * from './middlewares';
|
||||||
export {
|
export {
|
||||||
BlockNotionHtmlAdapterExtension,
|
BlockNotionHtmlAdapterExtension,
|
||||||
type BlockNotionHtmlAdapterMatcher,
|
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 {
|
import type {
|
||||||
BlockSnapshot,
|
BlockSnapshot,
|
||||||
DraftModel,
|
DraftModel,
|
||||||
@@ -6,7 +10,7 @@ import type {
|
|||||||
JobSlots,
|
JobSlots,
|
||||||
} from '@blocksuite/store';
|
} from '@blocksuite/store';
|
||||||
|
|
||||||
import { matchFlavours } from '../../../_common/utils/index.js';
|
import { matchFlavours } from '../../utils';
|
||||||
|
|
||||||
const handlePoint = (
|
const handlePoint = (
|
||||||
point: TextRangePoint,
|
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 }) => {
|
return ({ slots }) => {
|
||||||
sliceText(slots, std);
|
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 {
|
import {
|
||||||
ParseDocUrlProvider,
|
type DocMode,
|
||||||
type ParseDocUrlService,
|
DocModes,
|
||||||
TelemetryProvider,
|
type ParagraphBlockModel,
|
||||||
} from '@blocksuite/affine-shared/services';
|
type ReferenceInfo,
|
||||||
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
} from '@blocksuite/affine-model';
|
||||||
import { referenceToNode } from '@blocksuite/affine-shared/utils';
|
|
||||||
import {
|
import {
|
||||||
BLOCK_ID_ATTR,
|
BLOCK_ID_ATTR,
|
||||||
type BlockComponent,
|
type BlockComponent,
|
||||||
@@ -27,8 +24,14 @@ import {
|
|||||||
type Text,
|
type Text,
|
||||||
} from '@blocksuite/store';
|
} from '@blocksuite/store';
|
||||||
|
|
||||||
import { matchFlavours } from '../../../_common/utils/index.js';
|
import { REFERENCE_NODE } from '../../consts';
|
||||||
import { extractSearchParams } from '../../../_common/utils/url.js';
|
import {
|
||||||
|
ParseDocUrlProvider,
|
||||||
|
type ParseDocUrlService,
|
||||||
|
TelemetryProvider,
|
||||||
|
} from '../../services';
|
||||||
|
import type { AffineTextAttributes } from '../../types';
|
||||||
|
import { matchFlavours, referenceToNode } from '../../utils';
|
||||||
|
|
||||||
function findLastMatchingNode(
|
function findLastMatchingNode(
|
||||||
root: BlockSnapshot[],
|
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 './bracket-pairs.js';
|
||||||
export * from './note.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 {
|
import {
|
||||||
HtmlAdapter,
|
HtmlAdapter,
|
||||||
|
pasteMiddleware,
|
||||||
PlainTextAdapter,
|
PlainTextAdapter,
|
||||||
} from '@blocksuite/affine-shared/adapters';
|
} from '@blocksuite/affine-shared/adapters';
|
||||||
import {
|
import {
|
||||||
@@ -9,8 +10,6 @@ import {
|
|||||||
} from '@blocksuite/block-std';
|
} from '@blocksuite/block-std';
|
||||||
import { assertExists, DisposableGroup } from '@blocksuite/global/utils';
|
import { assertExists, DisposableGroup } from '@blocksuite/global/utils';
|
||||||
|
|
||||||
import { pasteMiddleware } from '../../root-block/clipboard/middlewares/index.js';
|
|
||||||
|
|
||||||
export class CodeClipboardController {
|
export class CodeClipboardController {
|
||||||
private _clipboard!: Clipboard;
|
private _clipboard!: Clipboard;
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,10 @@ import {
|
|||||||
} from '@blocksuite/affine-components/rich-text';
|
} from '@blocksuite/affine-components/rich-text';
|
||||||
import type { CodeBlockModel } from '@blocksuite/affine-model';
|
import type { CodeBlockModel } from '@blocksuite/affine-model';
|
||||||
import { BRACKET_PAIRS, NOTE_SELECTOR } from '@blocksuite/affine-shared/consts';
|
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 { getViewportElement } from '@blocksuite/affine-shared/utils';
|
||||||
import type { BlockComponent } from '@blocksuite/block-std';
|
import type { BlockComponent } from '@blocksuite/block-std';
|
||||||
import { getInlineRangeProvider } 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 { classMap } from 'lit/directives/class-map.js';
|
||||||
import type { ThemedToken } from 'shiki';
|
import type { ThemedToken } from 'shiki';
|
||||||
|
|
||||||
import { EdgelessRootBlockComponent } from '../root-block/edgeless/edgeless-root-block.js';
|
|
||||||
import { CodeClipboardController } from './clipboard/index.js';
|
import { CodeClipboardController } from './clipboard/index.js';
|
||||||
import { CodeBlockInlineManagerExtension } from './code-block-inline.js';
|
import { CodeBlockInlineManagerExtension } from './code-block-inline.js';
|
||||||
import type { CodeBlockService } from './code-block-service.js';
|
import type { CodeBlockService } from './code-block-service.js';
|
||||||
@@ -72,9 +74,8 @@ export class CodeBlockComponent extends CaptionedBlockComponent<
|
|||||||
}
|
}
|
||||||
|
|
||||||
override get topContenteditableElement() {
|
override get topContenteditableElement() {
|
||||||
if (this.rootComponent instanceof EdgelessRootBlockComponent) {
|
if (this.std.get(DocModeProvider).getEditorMode() === 'edgeless') {
|
||||||
const el = this.closest<BlockComponent>(NOTE_SELECTOR);
|
return this.closest<BlockComponent>(NOTE_SELECTOR);
|
||||||
return el;
|
|
||||||
}
|
}
|
||||||
return this.rootComponent;
|
return this.rootComponent;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { REFERENCE_NODE } from '@blocksuite/affine-components/rich-text';
|
|
||||||
import type {
|
import type {
|
||||||
DatabaseBlockModel,
|
DatabaseBlockModel,
|
||||||
RootBlockModel,
|
RootBlockModel,
|
||||||
} from '@blocksuite/affine-model';
|
} from '@blocksuite/affine-model';
|
||||||
|
import { REFERENCE_NODE } from '@blocksuite/affine-shared/consts';
|
||||||
import { TelemetryProvider } from '@blocksuite/affine-shared/services';
|
import { TelemetryProvider } from '@blocksuite/affine-shared/services';
|
||||||
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
||||||
import {
|
import {
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import {
|
import {
|
||||||
AttachmentAdapter,
|
AttachmentAdapter,
|
||||||
|
copyMiddleware,
|
||||||
HtmlAdapter,
|
HtmlAdapter,
|
||||||
ImageAdapter,
|
ImageAdapter,
|
||||||
NotionTextAdapter,
|
NotionTextAdapter,
|
||||||
|
pasteMiddleware,
|
||||||
} from '@blocksuite/affine-shared/adapters';
|
} from '@blocksuite/affine-shared/adapters';
|
||||||
import type { BlockComponent, UIEventHandler } from '@blocksuite/block-std';
|
import type { BlockComponent, UIEventHandler } from '@blocksuite/block-std';
|
||||||
import { DisposableGroup } from '@blocksuite/global/utils';
|
import { DisposableGroup } from '@blocksuite/global/utils';
|
||||||
@@ -15,7 +17,6 @@ import {
|
|||||||
titleMiddleware,
|
titleMiddleware,
|
||||||
} from '../../_common/transformers/middlewares.js';
|
} from '../../_common/transformers/middlewares.js';
|
||||||
import { ClipboardAdapter } from './adapter.js';
|
import { ClipboardAdapter } from './adapter.js';
|
||||||
import { copyMiddleware, pasteMiddleware } from './middlewares/index.js';
|
|
||||||
|
|
||||||
export class PageClipboard {
|
export class PageClipboard {
|
||||||
private readonly _copySelected = (onCopy?: () => void) => {
|
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 {
|
import {
|
||||||
getInlineEditorByModel,
|
getInlineEditorByModel,
|
||||||
insertContent,
|
insertContent,
|
||||||
REFERENCE_NODE,
|
|
||||||
} from '@blocksuite/affine-components/rich-text';
|
} from '@blocksuite/affine-components/rich-text';
|
||||||
import { toast } from '@blocksuite/affine-components/toast';
|
import { toast } from '@blocksuite/affine-components/toast';
|
||||||
import type { FrameBlockModel } from '@blocksuite/affine-model';
|
import type { FrameBlockModel } from '@blocksuite/affine-model';
|
||||||
|
import { REFERENCE_NODE } from '@blocksuite/affine-shared/consts';
|
||||||
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
||||||
import {
|
import {
|
||||||
createDefaultDoc,
|
createDefaultDoc,
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import {
|
|||||||
import {
|
import {
|
||||||
getInlineEditorByModel,
|
getInlineEditorByModel,
|
||||||
insertContent,
|
insertContent,
|
||||||
REFERENCE_NODE,
|
|
||||||
textConversionConfigs,
|
textConversionConfigs,
|
||||||
textFormatConfigs,
|
textFormatConfigs,
|
||||||
} from '@blocksuite/affine-components/rich-text';
|
} from '@blocksuite/affine-components/rich-text';
|
||||||
@@ -37,6 +36,7 @@ import type {
|
|||||||
FrameBlockModel,
|
FrameBlockModel,
|
||||||
ParagraphBlockModel,
|
ParagraphBlockModel,
|
||||||
} from '@blocksuite/affine-model';
|
} from '@blocksuite/affine-model';
|
||||||
|
import { REFERENCE_NODE } from '@blocksuite/affine-shared/consts';
|
||||||
import { TelemetryProvider } from '@blocksuite/affine-shared/services';
|
import { TelemetryProvider } from '@blocksuite/affine-shared/services';
|
||||||
import {
|
import {
|
||||||
createDefaultDoc,
|
createDefaultDoc,
|
||||||
|
|||||||
Reference in New Issue
Block a user