mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-25 18:26:05 +08:00
refactor: move doc-title and ai-chat-block components (#10316)
### TL;DR Moved doc title and AI chat block components to more appropriate locations while removing unused backlink functionality. ### What changed? - Relocated doc title component from presets to affine-components - Moved AI chat block from presets/blocks to blocks directory - Removed unused backlink-related code and components - Updated imports across files to reference new component locations - Consolidated AI-related exports through a single entry point ### How to test? 1. Verify doc title still renders correctly in documents 2. Confirm AI chat functionality works as expected 3. Check that no backlink-related features are accessible 4. Ensure all AI features continue to work through the new import paths ### Why make this change? This reorganization improves code organization by: - Placing components closer to their related functionality - Removing dead/unused code around backlinks - Simplifying the import structure for AI-related features - Making the codebase more maintainable by consolidating related components
This commit is contained in:
@@ -3,8 +3,8 @@ import { Peekable } from '@blocksuite/affine/blocks';
|
||||
import { computed } from '@preact/signals-core';
|
||||
import { html } from 'lit';
|
||||
|
||||
import { type AIChatBlockModel, ChatMessagesSchema } from '../../../blocks';
|
||||
import { ChatWithAIIcon } from '../_common/icon';
|
||||
import { ChatWithAIIcon } from './components/icon';
|
||||
import { type AIChatBlockModel, ChatMessagesSchema } from './model';
|
||||
import { AIChatBlockStyles } from './styles';
|
||||
|
||||
@Peekable({
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { TextRendererOptions } from '@affine/core/blocksuite/presets';
|
||||
import type { EditorHost } from '@blocksuite/affine/block-std';
|
||||
import type { AffineAIPanelState } from '@blocksuite/affine/blocks';
|
||||
import { css, html, LitElement } from 'lit';
|
||||
@@ -5,8 +6,7 @@ import { property } from 'lit/decorators.js';
|
||||
import { classMap } from 'lit/directives/class-map.js';
|
||||
import { repeat } from 'lit/directives/repeat.js';
|
||||
|
||||
import type { ChatMessage, MessageRole } from '../../../../blocks';
|
||||
import type { TextRendererOptions } from '../../../_common/components/text-renderer';
|
||||
import type { ChatMessage, MessageRole } from '../model';
|
||||
import { UserInfoTemplate } from './user-info';
|
||||
|
||||
export class AIChatMessage extends LitElement {
|
||||
@@ -1,9 +1,10 @@
|
||||
import { LoadingIcon } from '@blocksuite/affine/blocks';
|
||||
import { css, html, LitElement, nothing } from 'lit';
|
||||
import { property } from 'lit/decorators.js';
|
||||
import { choose } from 'lit/directives/choose.js';
|
||||
import { repeat } from 'lit/directives/repeat.js';
|
||||
|
||||
import { ImageLoadingFailedIcon, LoadingIcon } from '../../_common/icon';
|
||||
import { ImageLoadingFailedIcon } from './icon';
|
||||
|
||||
export class ChatImage extends LitElement {
|
||||
static override styles = css`
|
||||
@@ -57,35 +57,6 @@ export const ImageLoadingFailedIcon = html`<svg
|
||||
/>
|
||||
</svg>`;
|
||||
|
||||
export const LoadingIcon = html`<svg
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 16 16"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<style xmlns="http://www.w3.org/2000/svg">
|
||||
.spinner {
|
||||
transform-origin: center;
|
||||
animation: spinner_animate 0.75s infinite linear;
|
||||
}
|
||||
@keyframes spinner_animate {
|
||||
100% {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<path
|
||||
d="M14.6666 8.00004C14.6666 11.6819 11.6818 14.6667 7.99992 14.6667C4.31802 14.6667 1.33325 11.6819 1.33325 8.00004C1.33325 4.31814 4.31802 1.33337 7.99992 1.33337C11.6818 1.33337 14.6666 4.31814 14.6666 8.00004ZM3.30003 8.00004C3.30003 10.5957 5.40424 12.6999 7.99992 12.6999C10.5956 12.6999 12.6998 10.5957 12.6998 8.00004C12.6998 5.40436 10.5956 3.30015 7.99992 3.30015C5.40424 3.30015 3.30003 5.40436 3.30003 8.00004Z"
|
||||
fill="black"
|
||||
fill-opacity="0.1"
|
||||
/>
|
||||
<path
|
||||
d="M13.6833 8.00004C14.2263 8.00004 14.674 7.55745 14.5942 7.02026C14.5142 6.48183 14.3684 5.954 14.1591 5.44882C13.8241 4.63998 13.333 3.90505 12.714 3.286C12.0949 2.66694 11.36 2.17588 10.5511 1.84084C10.046 1.63159 9.51812 1.48576 8.9797 1.40576C8.44251 1.32595 7.99992 1.77363 7.99992 2.31671C7.99992 2.85979 8.44486 3.28974 8.9761 3.40253C9.25681 3.46214 9.53214 3.54746 9.79853 3.65781C10.3688 3.894 10.8869 4.2402 11.3233 4.67664C11.7598 5.11307 12.106 5.6312 12.3422 6.20143C12.4525 6.46782 12.5378 6.74315 12.5974 7.02386C12.7102 7.5551 13.1402 8.00004 13.6833 8.00004Z"
|
||||
fill="#1C9EE4"
|
||||
class="spinner"
|
||||
/>
|
||||
</svg>`;
|
||||
|
||||
export const SmallHintIcon = html`<svg
|
||||
width="16"
|
||||
height="16"
|
||||
@@ -2,8 +2,8 @@ import { baseTheme } from '@toeverything/theme';
|
||||
import { css, html, LitElement, type TemplateResult, unsafeCSS } from 'lit';
|
||||
import { property } from 'lit/decorators.js';
|
||||
|
||||
import type { MessageRole, MessageUserInfo } from '../../../../blocks';
|
||||
import { AffineAIIcon } from '../../_common/icon';
|
||||
import type { MessageRole, MessageUserInfo } from '../model';
|
||||
import { AffineAIIcon } from './icon';
|
||||
|
||||
export class UserInfo extends LitElement {
|
||||
static override styles = css`
|
||||
@@ -1,3 +1,2 @@
|
||||
export * from './ai-chat-model';
|
||||
export * from './consts';
|
||||
export * from './types';
|
||||
export * from './ai-chat-spec';
|
||||
export * from './model';
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from './ai-chat-model';
|
||||
export * from './consts';
|
||||
export * from './types';
|
||||
@@ -14,16 +14,6 @@ export interface DocProps {
|
||||
paragraph?: Partial<ParagraphProps>;
|
||||
}
|
||||
|
||||
export function initEmptyDoc(doc: Store, title?: string) {
|
||||
doc.load(() => {
|
||||
initDocFromProps(doc, {
|
||||
page: {
|
||||
title: new Text(title),
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function initDocFromProps(doc: Store, props?: DocProps) {
|
||||
doc.load(() => {
|
||||
const pageBlockId = doc.addBlock(
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { CopilotContextDoc, CopilotContextFile } from '@affine/graphql';
|
||||
import { LoadingIcon } from '@blocksuite/affine/blocks';
|
||||
import { WarningIcon } from '@blocksuite/icons/lit';
|
||||
import { type TemplateResult } from 'lit';
|
||||
|
||||
import { LoadingIcon } from '../../../blocks/_common/icon';
|
||||
import type { ChatChip, ChipState, DocChip, FileChip } from '../chat-context';
|
||||
|
||||
export function getChipTooltip(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from './_common/config';
|
||||
export * from './actions/index';
|
||||
export * from './ai-spec';
|
||||
export { ChatPanel } from './chat-panel/index';
|
||||
@@ -6,3 +7,4 @@ export * from './entries/index';
|
||||
export * from './messages/index';
|
||||
export { AIChatBlockPeekViewTemplate } from './peek-view/chat-block-peek-view';
|
||||
export * from './provider';
|
||||
export * from './utils/edgeless';
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
export * from './ai-chat-block.js';
|
||||
export * from './ai-chat-edgeless-block.js';
|
||||
export * from './ai-chat-spec.js';
|
||||
@@ -1,2 +0,0 @@
|
||||
export { AIChatMessages } from './ai-chat-block/components/ai-chat-messages.js';
|
||||
export * from './ai-chat-block/index.js';
|
||||
@@ -1,3 +1,15 @@
|
||||
import { AIChatBlockComponent } from '../blocks/ai-chat-block/ai-chat-block';
|
||||
import { EdgelessAIChatBlockComponent } from '../blocks/ai-chat-block/ai-chat-edgeless-block';
|
||||
import {
|
||||
AIChatMessage,
|
||||
AIChatMessages,
|
||||
} from '../blocks/ai-chat-block/components/ai-chat-messages';
|
||||
import {
|
||||
ChatImage,
|
||||
ChatImages,
|
||||
} from '../blocks/ai-chat-block/components/chat-images';
|
||||
import { ImagePlaceholder } from '../blocks/ai-chat-block/components/image-placeholder';
|
||||
import { UserInfo } from '../blocks/ai-chat-block/components/user-info';
|
||||
import { TextRenderer } from './_common/components/text-renderer';
|
||||
import { AskAIButton } from './ai/_common/components/ask-ai-button';
|
||||
import { AskAIIcon } from './ai/_common/components/ask-ai-icon';
|
||||
@@ -29,18 +41,6 @@ import { registerMiniMindmapBlocks } from './ai/mini-mindmap';
|
||||
import { ChatBlockInput } from './ai/peek-view/chat-block-input';
|
||||
import { AIChatBlockPeekView } from './ai/peek-view/chat-block-peek-view';
|
||||
import { DateTime } from './ai/peek-view/date-time';
|
||||
import { AIChatBlockComponent } from './blocks/ai-chat-block/ai-chat-block';
|
||||
import { EdgelessAIChatBlockComponent } from './blocks/ai-chat-block/ai-chat-edgeless-block';
|
||||
import {
|
||||
AIChatMessage,
|
||||
AIChatMessages,
|
||||
} from './blocks/ai-chat-block/components/ai-chat-messages';
|
||||
import {
|
||||
ChatImage,
|
||||
ChatImages,
|
||||
} from './blocks/ai-chat-block/components/chat-images';
|
||||
import { ImagePlaceholder } from './blocks/ai-chat-block/components/image-placeholder';
|
||||
import { UserInfo } from './blocks/ai-chat-block/components/user-info';
|
||||
|
||||
export function registerBlocksuitePresetsCustomComponents() {
|
||||
registerMiniMindmapBlocks();
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
export * from './_common/components/text-renderer';
|
||||
export * from './_common';
|
||||
export * from './ai';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AIProvider } from '@affine/core/blocksuite/presets/ai';
|
||||
import { AIProvider } from '@affine/core/blocksuite/presets';
|
||||
import { assertExists } from '@blocksuite/affine/global/utils';
|
||||
import { partition } from 'lodash-es';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AIProvider } from '@affine/core/blocksuite/presets/ai';
|
||||
import { AIProvider } from '@affine/core/blocksuite/presets';
|
||||
import { toggleGeneralAIOnboarding } from '@affine/core/components/affine/ai-onboarding/apis';
|
||||
import type { GlobalDialogService } from '@affine/core/modules/dialogs';
|
||||
import {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AIProvider } from '@affine/core/blocksuite/presets/ai';
|
||||
import { AIProvider } from '@affine/core/blocksuite/presets';
|
||||
import { mixpanel, track } from '@affine/track';
|
||||
import type { EditorHost } from '@blocksuite/affine/block-std';
|
||||
import type { GfxPrimitiveElementModel } from '@blocksuite/affine/block-std/gfx';
|
||||
|
||||
@@ -2,12 +2,12 @@ import { FeatureFlagService } from '@affine/core/modules/feature-flag';
|
||||
import {
|
||||
appendParagraphCommand,
|
||||
type DocMode,
|
||||
type DocTitle,
|
||||
focusBlockEnd,
|
||||
getLastNoteBlock,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import type {
|
||||
AffineEditorContainer,
|
||||
DocTitle,
|
||||
EdgelessEditor,
|
||||
PageEditor,
|
||||
} from '@blocksuite/affine/presets';
|
||||
|
||||
@@ -20,17 +20,14 @@ import track from '@affine/track';
|
||||
import {
|
||||
codeToolbarWidget,
|
||||
type DocMode,
|
||||
DocTitle,
|
||||
embedCardToolbarWidget,
|
||||
formatBarWidget,
|
||||
imageToolbarWidget,
|
||||
slashMenuWidget,
|
||||
surfaceRefToolbarWidget,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import {
|
||||
DocTitle,
|
||||
EdgelessEditor,
|
||||
PageEditor,
|
||||
} from '@blocksuite/affine/presets';
|
||||
import { EdgelessEditor, PageEditor } from '@blocksuite/affine/presets';
|
||||
import type { Store } from '@blocksuite/affine/store';
|
||||
import {
|
||||
useFramework,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { AIChatBlockSpec } from '@affine/core/blocksuite/blocks';
|
||||
import {
|
||||
AICodeBlockSpec,
|
||||
AIImageBlockSpec,
|
||||
AIParagraphBlockSpec,
|
||||
} from '@affine/core/blocksuite/presets/ai';
|
||||
import { AIChatBlockSpec } from '@affine/core/blocksuite/presets/blocks/ai-chat-block';
|
||||
} from '@affine/core/blocksuite/presets';
|
||||
import {
|
||||
AdapterFactoryExtensions,
|
||||
AttachmentBlockSpec,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { AIChatBlockSpec } from '@affine/core/blocksuite/blocks';
|
||||
import {
|
||||
AICodeBlockSpec,
|
||||
AIImageBlockSpec,
|
||||
AIParagraphBlockSpec,
|
||||
} from '@affine/core/blocksuite/presets/ai';
|
||||
import { AIChatBlockSpec } from '@affine/core/blocksuite/presets/blocks';
|
||||
} from '@affine/core/blocksuite/presets';
|
||||
import { DocService, DocsService } from '@affine/core/modules/doc';
|
||||
import { DocDisplayMetaService } from '@affine/core/modules/doc-display-meta';
|
||||
import { EditorSettingService } from '@affine/core/modules/editor-setting';
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import { notify } from '@affine/component';
|
||||
import {
|
||||
isMindmapChild,
|
||||
isMindMapRoot,
|
||||
} from '@affine/core/blocksuite/presets/ai/utils/edgeless';
|
||||
import { isMindmapChild, isMindMapRoot } from '@affine/core/blocksuite/presets';
|
||||
import { EditorService } from '@affine/core/modules/editor';
|
||||
import { apis } from '@affine/electron-api';
|
||||
import { I18n } from '@affine/i18n';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { createAIEdgelessRootBlockSpec } from '@affine/core/blocksuite/presets/ai';
|
||||
import { createAIEdgelessRootBlockSpec } from '@affine/core/blocksuite/presets';
|
||||
import { FeatureFlagService } from '@affine/core/modules/feature-flag';
|
||||
import { builtInTemplates as builtInEdgelessTemplates } from '@affine/templates/edgeless';
|
||||
import { builtInTemplates as builtInStickersTemplates } from '@affine/templates/stickers';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { createAIPageRootBlockSpec } from '@affine/core/blocksuite/presets/ai';
|
||||
import { createAIPageRootBlockSpec } from '@affine/core/blocksuite/presets';
|
||||
import { FeatureFlagService } from '@affine/core/modules/feature-flag';
|
||||
import {
|
||||
PageRootBlockSpec,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AIChatBlockSpec } from '@affine/core/blocksuite/presets/blocks/ai-chat-block';
|
||||
import { AIChatBlockSpec } from '@affine/core/blocksuite/blocks';
|
||||
import { PeekViewService } from '@affine/core/modules/peek-view/services/peek-view';
|
||||
import { AppThemeService } from '@affine/core/modules/theme';
|
||||
import {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { handleInlineAskAIAction } from '@affine/core/blocksuite/presets/ai';
|
||||
import { pageAIGroups } from '@affine/core/blocksuite/presets/ai/_common/config';
|
||||
import {
|
||||
handleInlineAskAIAction,
|
||||
pageAIGroups,
|
||||
} from '@affine/core/blocksuite/presets';
|
||||
import { DocsService } from '@affine/core/modules/doc';
|
||||
import { EditorService } from '@affine/core/modules/editor';
|
||||
import { FeatureFlagService } from '@affine/core/modules/feature-flag';
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
pushGlobalLoadingEventAtom,
|
||||
resolveGlobalLoadingEventAtom,
|
||||
} from '@affine/component/global-loading';
|
||||
import { AIProvider } from '@affine/core/blocksuite/presets/ai';
|
||||
import { AIProvider } from '@affine/core/blocksuite/presets';
|
||||
import { SyncAwareness } from '@affine/core/components/affine/awareness';
|
||||
import { useRegisterFindInPageCommands } from '@affine/core/components/hooks/affine/use-register-find-in-page-commands';
|
||||
import { useRegisterWorkspaceCommands } from '@affine/core/components/hooks/use-register-workspace-commands';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Scrollable } from '@affine/component';
|
||||
import { PageDetailSkeleton } from '@affine/component/page-detail-skeleton';
|
||||
import type { ChatPanel } from '@affine/core/blocksuite/presets/ai';
|
||||
import { AIProvider } from '@affine/core/blocksuite/presets/ai';
|
||||
import type { ChatPanel } from '@affine/core/blocksuite/presets';
|
||||
import { AIProvider } from '@affine/core/blocksuite/presets';
|
||||
import { PageAIOnboarding } from '@affine/core/components/affine/ai-onboarding';
|
||||
import { EditorOutlineViewer } from '@affine/core/components/blocksuite/outline-viewer';
|
||||
import { DocPropertySidebar } from '@affine/core/components/doc-properties/sidebar';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ChatPanel } from '@affine/core/blocksuite/presets/ai';
|
||||
import { ChatPanel } from '@affine/core/blocksuite/presets';
|
||||
import { createPageModePreviewSpecs } from '@affine/core/components/blocksuite/block-suite-editor/specs/preview';
|
||||
import { AINetworkSearchService } from '@affine/core/modules/ai-button/services/network-search';
|
||||
import { DocDisplayMetaService } from '@affine/core/modules/doc-display-meta';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AIProvider } from '@affine/core/blocksuite/presets/ai';
|
||||
import { AIProvider } from '@affine/core/blocksuite/presets';
|
||||
import type { OAuthProviderType } from '@affine/graphql';
|
||||
import { track } from '@affine/track';
|
||||
import { OnEvent, Service } from '@toeverything/infra';
|
||||
|
||||
@@ -2,14 +2,12 @@ import type { DefaultOpenProperty } from '@affine/core/components/doc-properties
|
||||
import { GfxControllerIdentifier } from '@blocksuite/affine/block-std/gfx';
|
||||
import {
|
||||
type DocMode,
|
||||
type DocTitle,
|
||||
FeatureFlagService as BSFeatureFlagService,
|
||||
HighlightSelection,
|
||||
type ReferenceParams,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import type {
|
||||
AffineEditorContainer,
|
||||
DocTitle,
|
||||
} from '@blocksuite/affine/presets';
|
||||
import type { AffineEditorContainer } from '@blocksuite/affine/presets';
|
||||
import type { InlineEditor } from '@blocksuite/inline';
|
||||
import { effect } from '@preact/signals-core';
|
||||
import { Entity, LiveData } from '@toeverything/infra';
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { toReactNode } from '@affine/component';
|
||||
import { AIChatBlockPeekViewTemplate } from '@affine/core/blocksuite/presets/ai';
|
||||
import { AIChatBlockPeekViewTemplate } from '@affine/core/blocksuite/presets';
|
||||
import { AINetworkSearchService } from '@affine/core/modules/ai-button/services/network-search';
|
||||
import type { EditorHost } from '@blocksuite/affine/block-std';
|
||||
import { useFramework } from '@toeverything/infra';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import type { AIChatBlockModel } from '../../../../blocksuite/blocks/ai-chat-block/ai-chat-model';
|
||||
import type { AIChatBlockModel } from '../../../../blocksuite/blocks/ai-chat-block/model/ai-chat-model';
|
||||
import { createPageModePreviewSpecs } from '../../../../components/blocksuite/block-suite-editor/specs/preview';
|
||||
|
||||
export type AIChatBlockPeekViewProps = {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Scrollable } from '@affine/component';
|
||||
import { PageDetailSkeleton } from '@affine/component/page-detail-skeleton';
|
||||
import { AIProvider } from '@affine/core/blocksuite/presets/ai';
|
||||
import { AIProvider } from '@affine/core/blocksuite/presets';
|
||||
import { AffineErrorBoundary } from '@affine/core/components/affine/affine-error-boundary';
|
||||
import { EditorOutlineViewer } from '@affine/core/components/blocksuite/outline-viewer';
|
||||
import { PageNotFound } from '@affine/core/desktop/pages/404';
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { AIChatBlockSchema } from '@affine/core/blocksuite/blocks/ai-chat-block/model';
|
||||
import { AffineSchemas } from '@blocksuite/affine/blocks/schemas';
|
||||
import { Schema } from '@blocksuite/affine/store';
|
||||
|
||||
import { AIChatBlockSchema } from '../../blocksuite/blocks';
|
||||
|
||||
let _schema: Schema | null = null;
|
||||
export function getAFFiNEWorkspaceSchema() {
|
||||
if (!_schema) {
|
||||
|
||||
Reference in New Issue
Block a user