mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-29 08:09:52 +08:00
chore: merge blocksuite source code (#9213)
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import { EmbedExtensions } from '@blocksuite/affine-block-embed';
|
||||
import { ListBlockSpec } from '@blocksuite/affine-block-list';
|
||||
import { ParagraphBlockSpec } from '@blocksuite/affine-block-paragraph';
|
||||
import { RichTextExtensions } from '@blocksuite/affine-components/rich-text';
|
||||
import { EditPropsStore } from '@blocksuite/affine-shared/services';
|
||||
import type { ExtensionType } from '@blocksuite/block-std';
|
||||
|
||||
import {
|
||||
AdapterFactoryExtensions,
|
||||
BlockAdapterMatcherExtensions,
|
||||
} from '../_common/adapters/extension.js';
|
||||
import { AttachmentBlockSpec } from '../attachment-block/attachment-spec.js';
|
||||
import { BookmarkBlockSpec } from '../bookmark-block/bookmark-spec.js';
|
||||
import { CodeBlockSpec } from '../code-block/code-block-spec.js';
|
||||
import { DataViewBlockSpec } from '../data-view-block/data-view-spec.js';
|
||||
import { DatabaseBlockSpec } from '../database-block/database-spec.js';
|
||||
import { DividerBlockSpec } from '../divider-block/divider-spec.js';
|
||||
import { ImageBlockSpec } from '../image-block/image-spec.js';
|
||||
import {
|
||||
EdgelessNoteBlockSpec,
|
||||
NoteBlockSpec,
|
||||
} from '../note-block/note-spec.js';
|
||||
|
||||
export const CommonFirstPartyBlockSpecs: ExtensionType[] = [
|
||||
RichTextExtensions,
|
||||
EditPropsStore,
|
||||
ListBlockSpec,
|
||||
NoteBlockSpec,
|
||||
DatabaseBlockSpec,
|
||||
DataViewBlockSpec,
|
||||
DividerBlockSpec,
|
||||
CodeBlockSpec,
|
||||
ImageBlockSpec,
|
||||
ParagraphBlockSpec,
|
||||
BookmarkBlockSpec,
|
||||
AttachmentBlockSpec,
|
||||
EmbedExtensions,
|
||||
BlockAdapterMatcherExtensions,
|
||||
AdapterFactoryExtensions,
|
||||
].flat();
|
||||
|
||||
export const EdgelessFirstPartyBlockSpecs: ExtensionType[] = [
|
||||
RichTextExtensions,
|
||||
EditPropsStore,
|
||||
ListBlockSpec,
|
||||
EdgelessNoteBlockSpec,
|
||||
DatabaseBlockSpec,
|
||||
DataViewBlockSpec,
|
||||
DividerBlockSpec,
|
||||
CodeBlockSpec,
|
||||
ImageBlockSpec,
|
||||
ParagraphBlockSpec,
|
||||
BookmarkBlockSpec,
|
||||
AttachmentBlockSpec,
|
||||
EmbedExtensions,
|
||||
BlockAdapterMatcherExtensions,
|
||||
AdapterFactoryExtensions,
|
||||
].flat();
|
||||
@@ -0,0 +1,44 @@
|
||||
import {
|
||||
EmbedFigmaBlockSpec,
|
||||
EmbedGithubBlockSpec,
|
||||
EmbedHtmlBlockSpec,
|
||||
EmbedLinkedDocBlockSpec,
|
||||
EmbedLoomBlockSpec,
|
||||
EmbedSyncedDocBlockSpec,
|
||||
EmbedYoutubeBlockSpec,
|
||||
} from '@blocksuite/affine-block-embed';
|
||||
import { ListBlockSpec } from '@blocksuite/affine-block-list';
|
||||
import { ParagraphBlockSpec } from '@blocksuite/affine-block-paragraph';
|
||||
|
||||
import { AttachmentBlockSpec } from '../../attachment-block/attachment-spec.js';
|
||||
import { BookmarkBlockSpec } from '../../bookmark-block/bookmark-spec.js';
|
||||
import { CodeBlockSpec } from '../../code-block/code-block-spec.js';
|
||||
import { DataViewBlockSpec } from '../../data-view-block/data-view-spec.js';
|
||||
import { DatabaseBlockSpec } from '../../database-block/database-spec.js';
|
||||
import { DividerBlockSpec } from '../../divider-block/divider-spec.js';
|
||||
import { ImageBlockSpec } from '../../image-block/image-spec.js';
|
||||
import {
|
||||
EdgelessNoteBlockSpec,
|
||||
NoteBlockSpec,
|
||||
} from '../../note-block/note-spec.js';
|
||||
|
||||
export {
|
||||
AttachmentBlockSpec,
|
||||
BookmarkBlockSpec,
|
||||
CodeBlockSpec,
|
||||
DatabaseBlockSpec,
|
||||
DataViewBlockSpec,
|
||||
DividerBlockSpec,
|
||||
EdgelessNoteBlockSpec,
|
||||
EmbedFigmaBlockSpec,
|
||||
EmbedGithubBlockSpec,
|
||||
EmbedHtmlBlockSpec,
|
||||
EmbedLinkedDocBlockSpec,
|
||||
EmbedLoomBlockSpec,
|
||||
EmbedSyncedDocBlockSpec,
|
||||
EmbedYoutubeBlockSpec,
|
||||
ImageBlockSpec,
|
||||
ListBlockSpec,
|
||||
NoteBlockSpec,
|
||||
ParagraphBlockSpec,
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
import { EdgelessSurfaceBlockSpec } from '@blocksuite/affine-block-surface';
|
||||
|
||||
import { EdgelessTextBlockSpec } from '../../edgeless-text-block/index.js';
|
||||
import { FrameBlockSpec } from '../../frame-block/frame-spec.js';
|
||||
import { LatexBlockSpec } from '../../latex-block/latex-spec.js';
|
||||
import { EdgelessRootBlockSpec } from '../../root-block/edgeless/edgeless-root-spec.js';
|
||||
import { EdgelessSurfaceRefBlockSpec } from '../../surface-ref-block/surface-ref-spec.js';
|
||||
|
||||
export {
|
||||
EdgelessRootBlockSpec,
|
||||
EdgelessSurfaceBlockSpec,
|
||||
EdgelessSurfaceRefBlockSpec,
|
||||
EdgelessTextBlockSpec,
|
||||
FrameBlockSpec,
|
||||
LatexBlockSpec,
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
import { PageSurfaceBlockSpec } from '@blocksuite/affine-block-surface';
|
||||
|
||||
import { PageRootBlockSpec } from '../../root-block/page/page-root-spec.js';
|
||||
import { PageSurfaceRefBlockSpec } from '../../surface-ref-block/surface-ref-spec.js';
|
||||
|
||||
export { PageRootBlockSpec, PageSurfaceBlockSpec, PageSurfaceRefBlockSpec };
|
||||
@@ -0,0 +1,6 @@
|
||||
export * from './group/common.js';
|
||||
export * from './preset/edgeless-specs.js';
|
||||
export * from './preset/mobile-patch.js';
|
||||
export * from './preset/page-specs.js';
|
||||
export * from './preset/preview-specs.js';
|
||||
export { SpecBuilder, SpecProvider } from '@blocksuite/affine-shared/utils';
|
||||
@@ -0,0 +1,73 @@
|
||||
import {
|
||||
ConnectionOverlay,
|
||||
EdgelessSurfaceBlockSpec,
|
||||
} from '@blocksuite/affine-block-surface';
|
||||
import { FontLoaderService } from '@blocksuite/affine-shared/services';
|
||||
import type { ExtensionType } from '@blocksuite/block-std';
|
||||
|
||||
import { EdgelessTextBlockSpec } from '../../edgeless-text-block/edgeless-text-spec.js';
|
||||
import { FrameBlockSpec } from '../../frame-block/frame-spec.js';
|
||||
import { LatexBlockSpec } from '../../latex-block/latex-spec.js';
|
||||
import { EdgelessRootBlockSpec } from '../../root-block/edgeless/edgeless-root-spec.js';
|
||||
import {
|
||||
EdgelessFrameManager,
|
||||
FrameOverlay,
|
||||
} from '../../root-block/edgeless/frame-manager.js';
|
||||
import { BrushTool } from '../../root-block/edgeless/gfx-tool/brush-tool.js';
|
||||
import { ConnectorTool } from '../../root-block/edgeless/gfx-tool/connector-tool.js';
|
||||
import { CopilotTool } from '../../root-block/edgeless/gfx-tool/copilot-tool.js';
|
||||
import { DefaultTool } from '../../root-block/edgeless/gfx-tool/default-tool.js';
|
||||
import { MindMapIndicatorOverlay } from '../../root-block/edgeless/gfx-tool/default-tool-ext/mind-map-ext/indicator-overlay.js';
|
||||
import { EmptyTool } from '../../root-block/edgeless/gfx-tool/empty-tool.js';
|
||||
import { EraserTool } from '../../root-block/edgeless/gfx-tool/eraser-tool.js';
|
||||
import { PresentTool } from '../../root-block/edgeless/gfx-tool/frame-navigator-tool.js';
|
||||
import { FrameTool } from '../../root-block/edgeless/gfx-tool/frame-tool.js';
|
||||
import { LassoTool } from '../../root-block/edgeless/gfx-tool/lasso-tool.js';
|
||||
import { NoteTool } from '../../root-block/edgeless/gfx-tool/note-tool.js';
|
||||
import { PanTool } from '../../root-block/edgeless/gfx-tool/pan-tool.js';
|
||||
import { ShapeTool } from '../../root-block/edgeless/gfx-tool/shape-tool.js';
|
||||
import { TemplateTool } from '../../root-block/edgeless/gfx-tool/template-tool.js';
|
||||
import { TextTool } from '../../root-block/edgeless/gfx-tool/text-tool.js';
|
||||
import { EditPropsMiddlewareBuilder } from '../../root-block/edgeless/middlewares/base.js';
|
||||
import { EdgelessSnapManager } from '../../root-block/edgeless/utils/snap-manager.js';
|
||||
import { EdgelessSurfaceRefBlockSpec } from '../../surface-ref-block/surface-ref-spec.js';
|
||||
import { EdgelessFirstPartyBlockSpecs } from '../common.js';
|
||||
|
||||
export const EdgelessToolExtension: ExtensionType[] = [
|
||||
DefaultTool,
|
||||
PanTool,
|
||||
EraserTool,
|
||||
TextTool,
|
||||
ShapeTool,
|
||||
NoteTool,
|
||||
BrushTool,
|
||||
ConnectorTool,
|
||||
CopilotTool,
|
||||
TemplateTool,
|
||||
EmptyTool,
|
||||
FrameTool,
|
||||
LassoTool,
|
||||
PresentTool,
|
||||
];
|
||||
|
||||
export const EdgelessBuiltInManager: ExtensionType[] = [
|
||||
ConnectionOverlay,
|
||||
FrameOverlay,
|
||||
MindMapIndicatorOverlay,
|
||||
EdgelessSnapManager,
|
||||
EdgelessFrameManager,
|
||||
EditPropsMiddlewareBuilder,
|
||||
];
|
||||
|
||||
export const EdgelessEditorBlockSpecs: ExtensionType[] = [
|
||||
EdgelessRootBlockSpec,
|
||||
...EdgelessFirstPartyBlockSpecs,
|
||||
EdgelessSurfaceBlockSpec,
|
||||
EdgelessSurfaceRefBlockSpec,
|
||||
FrameBlockSpec,
|
||||
EdgelessTextBlockSpec,
|
||||
LatexBlockSpec,
|
||||
FontLoaderService,
|
||||
EdgelessToolExtension,
|
||||
EdgelessBuiltInManager,
|
||||
].flat();
|
||||
@@ -0,0 +1,119 @@
|
||||
import {
|
||||
type ReferenceNodeConfig,
|
||||
ReferenceNodeConfigIdentifier,
|
||||
} from '@blocksuite/affine-components/rich-text';
|
||||
import {
|
||||
type BlockStdScope,
|
||||
ConfigIdentifier,
|
||||
LifeCycleWatcher,
|
||||
WidgetViewMapIdentifier,
|
||||
type WidgetViewMapType,
|
||||
} from '@blocksuite/block-std';
|
||||
import type { Container } from '@blocksuite/global/di';
|
||||
|
||||
import type { CodeBlockConfig } from '../../code-block/code-block-config.js';
|
||||
import { AFFINE_EMBED_CARD_TOOLBAR_WIDGET } from '../../root-block/widgets/embed-card-toolbar/embed-card-toolbar.js';
|
||||
import { AFFINE_FORMAT_BAR_WIDGET } from '../../root-block/widgets/format-bar/format-bar.js';
|
||||
import { AFFINE_SLASH_MENU_WIDGET } from '../../root-block/widgets/slash-menu/index.js';
|
||||
|
||||
export class MobileSpecsPatches extends LifeCycleWatcher {
|
||||
static override key = 'mobile-patches';
|
||||
|
||||
constructor(std: BlockStdScope) {
|
||||
super(std);
|
||||
|
||||
std.doc.awarenessStore.setFlag('enable_mobile_keyboard_toolbar', true);
|
||||
std.doc.awarenessStore.setFlag('enable_mobile_linked_doc_menu', true);
|
||||
}
|
||||
|
||||
static override setup(di: Container) {
|
||||
super.setup(di);
|
||||
|
||||
// Hide reference popup on mobile.
|
||||
{
|
||||
const prev = di.getFactory(ReferenceNodeConfigIdentifier);
|
||||
di.override(ReferenceNodeConfigIdentifier, provider => {
|
||||
return {
|
||||
...prev?.(provider),
|
||||
hidePopup: true,
|
||||
} satisfies ReferenceNodeConfig;
|
||||
});
|
||||
}
|
||||
|
||||
// Hide number lines for code block on mobile.
|
||||
{
|
||||
const codeConfigIdentifier = ConfigIdentifier('affine:code');
|
||||
const prev = di.getFactory(codeConfigIdentifier);
|
||||
di.override(codeConfigIdentifier, provider => {
|
||||
return {
|
||||
...prev?.(provider),
|
||||
showLineNumbers: false,
|
||||
} satisfies CodeBlockConfig;
|
||||
});
|
||||
}
|
||||
|
||||
// Disable root level widgets for mobile.
|
||||
{
|
||||
const rootWidgetViewMapIdentifier =
|
||||
WidgetViewMapIdentifier('affine:page');
|
||||
|
||||
const prev = di.getFactory(rootWidgetViewMapIdentifier);
|
||||
|
||||
di.override(rootWidgetViewMapIdentifier, provider => {
|
||||
const ignoreWidgets = [
|
||||
AFFINE_FORMAT_BAR_WIDGET,
|
||||
AFFINE_EMBED_CARD_TOOLBAR_WIDGET,
|
||||
AFFINE_SLASH_MENU_WIDGET,
|
||||
];
|
||||
|
||||
const newMap = { ...prev?.(provider) };
|
||||
|
||||
ignoreWidgets.forEach(widget => {
|
||||
if (widget in newMap) delete newMap[widget];
|
||||
});
|
||||
|
||||
return newMap;
|
||||
});
|
||||
}
|
||||
|
||||
// Disable block level toolbar widgets for mobile.
|
||||
{
|
||||
di.override(
|
||||
WidgetViewMapIdentifier('affine:code'),
|
||||
(): WidgetViewMapType => ({})
|
||||
);
|
||||
|
||||
di.override(
|
||||
WidgetViewMapIdentifier('affine:image'),
|
||||
(): WidgetViewMapType => ({})
|
||||
);
|
||||
|
||||
di.override(
|
||||
WidgetViewMapIdentifier('affine:surface-ref'),
|
||||
(): WidgetViewMapType => ({})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
override mounted() {
|
||||
// remove slash placeholder for mobile: `type / ...`
|
||||
{
|
||||
const paragraphService = this.std.getService('affine:paragraph');
|
||||
if (!paragraphService) return;
|
||||
|
||||
paragraphService.placeholderGenerator = model => {
|
||||
const placeholders = {
|
||||
text: '',
|
||||
h1: 'Heading 1',
|
||||
h2: 'Heading 2',
|
||||
h3: 'Heading 3',
|
||||
h4: 'Heading 4',
|
||||
h5: 'Heading 5',
|
||||
h6: 'Heading 6',
|
||||
quote: '',
|
||||
};
|
||||
return placeholders[model.type];
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { PageSurfaceBlockSpec } from '@blocksuite/affine-block-surface';
|
||||
import { FontLoaderService } from '@blocksuite/affine-shared/services';
|
||||
import type { ExtensionType } from '@blocksuite/block-std';
|
||||
|
||||
import { LatexBlockSpec } from '../../latex-block/latex-spec.js';
|
||||
import { PageRootBlockSpec } from '../../root-block/page/page-root-spec.js';
|
||||
import { PageSurfaceRefBlockSpec } from '../../surface-ref-block/surface-ref-spec.js';
|
||||
import { CommonFirstPartyBlockSpecs } from '../common.js';
|
||||
|
||||
export const PageEditorBlockSpecs: ExtensionType[] = [
|
||||
PageRootBlockSpec,
|
||||
...CommonFirstPartyBlockSpecs,
|
||||
PageSurfaceBlockSpec,
|
||||
PageSurfaceRefBlockSpec,
|
||||
LatexBlockSpec,
|
||||
FontLoaderService,
|
||||
].flat();
|
||||
@@ -0,0 +1,64 @@
|
||||
import {
|
||||
EdgelessSurfaceBlockSpec,
|
||||
PageSurfaceBlockSpec,
|
||||
} from '@blocksuite/affine-block-surface';
|
||||
import { RefNodeSlotsExtension } from '@blocksuite/affine-components/rich-text';
|
||||
import {
|
||||
DocDisplayMetaService,
|
||||
DocModeService,
|
||||
EmbedOptionService,
|
||||
FontLoaderService,
|
||||
ThemeService,
|
||||
} from '@blocksuite/affine-shared/services';
|
||||
import {
|
||||
BlockViewExtension,
|
||||
type ExtensionType,
|
||||
FlavourExtension,
|
||||
} from '@blocksuite/block-std';
|
||||
import { literal } from 'lit/static-html.js';
|
||||
|
||||
import { EdgelessTextBlockSpec } from '../../edgeless-text-block/index.js';
|
||||
import { FrameBlockSpec } from '../../frame-block/frame-spec.js';
|
||||
import { LatexBlockSpec } from '../../latex-block/latex-spec.js';
|
||||
import { PreviewEdgelessRootBlockSpec } from '../../root-block/edgeless/edgeless-root-spec.js';
|
||||
import { PageRootService } from '../../root-block/page/page-root-service.js';
|
||||
import {
|
||||
EdgelessSurfaceRefBlockSpec,
|
||||
PageSurfaceRefBlockSpec,
|
||||
} from '../../surface-ref-block/surface-ref-spec.js';
|
||||
import {
|
||||
CommonFirstPartyBlockSpecs,
|
||||
EdgelessFirstPartyBlockSpecs,
|
||||
} from '../common.js';
|
||||
|
||||
const PreviewPageSpec: ExtensionType[] = [
|
||||
FlavourExtension('affine:page'),
|
||||
PageRootService,
|
||||
DocModeService,
|
||||
ThemeService,
|
||||
EmbedOptionService,
|
||||
BlockViewExtension('affine:page', literal`affine-preview-root`),
|
||||
DocDisplayMetaService,
|
||||
];
|
||||
|
||||
export const PreviewEdgelessEditorBlockSpecs: ExtensionType[] = [
|
||||
PreviewEdgelessRootBlockSpec,
|
||||
...EdgelessFirstPartyBlockSpecs,
|
||||
EdgelessSurfaceBlockSpec,
|
||||
EdgelessSurfaceRefBlockSpec,
|
||||
FrameBlockSpec,
|
||||
EdgelessTextBlockSpec,
|
||||
LatexBlockSpec,
|
||||
FontLoaderService,
|
||||
RefNodeSlotsExtension(),
|
||||
].flat();
|
||||
|
||||
export const PreviewEditorBlockSpecs: ExtensionType[] = [
|
||||
PreviewPageSpec,
|
||||
...CommonFirstPartyBlockSpecs,
|
||||
PageSurfaceBlockSpec,
|
||||
PageSurfaceRefBlockSpec,
|
||||
LatexBlockSpec,
|
||||
FontLoaderService,
|
||||
RefNodeSlotsExtension(),
|
||||
].flat();
|
||||
@@ -0,0 +1,18 @@
|
||||
import { SpecProvider } from '@blocksuite/affine-shared/utils';
|
||||
|
||||
import { EdgelessEditorBlockSpecs } from './preset/edgeless-specs.js';
|
||||
import { PageEditorBlockSpecs } from './preset/page-specs.js';
|
||||
import {
|
||||
PreviewEdgelessEditorBlockSpecs,
|
||||
PreviewEditorBlockSpecs,
|
||||
} from './preset/preview-specs.js';
|
||||
|
||||
export function registerSpecs() {
|
||||
SpecProvider.getInstance().addSpec('page', PageEditorBlockSpecs);
|
||||
SpecProvider.getInstance().addSpec('edgeless', EdgelessEditorBlockSpecs);
|
||||
SpecProvider.getInstance().addSpec('page:preview', PreviewEditorBlockSpecs);
|
||||
SpecProvider.getInstance().addSpec(
|
||||
'edgeless:preview',
|
||||
PreviewEdgelessEditorBlockSpecs
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user