From fa5e6e1f45be4dbd166648c9aa25c8ec9259255b Mon Sep 17 00:00:00 2001 From: Saul-Mirone Date: Mon, 20 Jan 2025 09:41:06 +0000 Subject: [PATCH] fix: remove bs shared and components in affine (#9792) --- blocksuite/blocks/src/index.ts | 14 ++++++- packages/frontend/apps/ios/package.json | 1 - .../frontend/apps/ios/src/bs-menu-config.tsx | 2 +- packages/frontend/apps/ios/tsconfig.json | 1 - packages/frontend/core/package.json | 2 - .../presets/ai/chat-panel/chat-panel-input.ts | 7 +++- .../ai/chat-panel/components/file-chip.ts | 2 +- .../src/blocksuite/presets/ai/utils/image.ts | 2 +- .../blocksuite-editor-container.tsx | 37 +------------------ .../specs/custom/database-block.ts | 2 +- .../specs/custom/root-block.ts | 10 ++--- .../specs/custom/widgets/toolbar.ts | 3 +- .../hooks/affine/use-reference-link-helper.ts | 2 +- .../editor/edgeless/snapshot.tsx | 2 +- .../pages/workspace/detail-page/tabs/chat.tsx | 2 +- .../ai-button/services/network-search.ts | 2 +- .../modules/at-menu-config/services/index.ts | 2 +- .../core/src/modules/doc/services/docs.ts | 7 +++- .../modules/docs-search/worker/in-worker.ts | 2 +- .../editor-setting/entities/editor-setting.ts | 6 +-- .../core/src/modules/editor-setting/schema.ts | 2 +- packages/frontend/core/tsconfig.json | 5 --- tools/utils/src/workspace.gen.ts | 6 --- yarn.lock | 3 -- 24 files changed, 44 insertions(+), 80 deletions(-) diff --git a/blocksuite/blocks/src/index.ts b/blocksuite/blocks/src/index.ts index 003ecf9ec7..5a20fd6418 100644 --- a/blocksuite/blocks/src/index.ts +++ b/blocksuite/blocks/src/index.ts @@ -58,7 +58,11 @@ export { PaymentRequiredError, UnauthorizedError, } from '@blocksuite/affine-components/ai-item'; -export { type MenuOptions } from '@blocksuite/affine-components/context-menu'; +export { + menu, + type MenuOptions, + onMenuOpen, +} from '@blocksuite/affine-components/context-menu'; export { HoverController, whenHover, @@ -97,6 +101,7 @@ export { AttachmentAdapter, AttachmentAdapterFactoryExtension, AttachmentAdapterFactoryIdentifier, + FetchUtils, HtmlAdapter, HtmlAdapterFactoryExtension, HtmlAdapterFactoryIdentifier, @@ -124,11 +129,15 @@ export { FontFamilyVariables, SizeVariables, StyleVariables, + unsafeCSSVarV2, } from '@blocksuite/affine-shared/theme'; +export { type AffineTextAttributes } from '@blocksuite/affine-shared/types'; export { createButtonPopper, createDefaultDoc, + createSignalFromObservable, findNoteBlockModel, + getLastNoteBlock, isInsideEdgelessEditor, isInsidePageEditor, matchFlavours, @@ -136,6 +145,9 @@ export { once, openFileOrFiles, printToPdf, + referenceToNode, + type Signal, + SpecProvider, } from '@blocksuite/affine-shared/utils'; export type { DragBlockPayload } from '@blocksuite/affine-widget-drag-handle'; diff --git a/packages/frontend/apps/ios/package.json b/packages/frontend/apps/ios/package.json index dedce498eb..934c9b59b5 100644 --- a/packages/frontend/apps/ios/package.json +++ b/packages/frontend/apps/ios/package.json @@ -16,7 +16,6 @@ "@affine/i18n": "workspace:*", "@affine/nbstore": "workspace:*", "@blocksuite/affine": "workspace:*", - "@blocksuite/affine-components": "workspace:*", "@blocksuite/icons": "2.2.2", "@capacitor/app": "^6.0.2", "@capacitor/browser": "^6.0.4", diff --git a/packages/frontend/apps/ios/src/bs-menu-config.tsx b/packages/frontend/apps/ios/src/bs-menu-config.tsx index fa8967cf10..521fe8ea7f 100644 --- a/packages/frontend/apps/ios/src/bs-menu-config.tsx +++ b/packages/frontend/apps/ios/src/bs-menu-config.tsx @@ -1,5 +1,5 @@ import { NavigationGestureService } from '@affine/core/mobile/modules/navigation-gesture'; -import { onMenuOpen } from '@blocksuite/affine-components/context-menu'; +import { onMenuOpen } from '@blocksuite/affine/blocks'; import { useService } from '@toeverything/infra'; import { type PropsWithChildren, useCallback, useEffect, useRef } from 'react'; diff --git a/packages/frontend/apps/ios/tsconfig.json b/packages/frontend/apps/ios/tsconfig.json index 75776033f9..a9a09593ae 100644 --- a/packages/frontend/apps/ios/tsconfig.json +++ b/packages/frontend/apps/ios/tsconfig.json @@ -12,7 +12,6 @@ { "path": "../../i18n" }, { "path": "../../../common/nbstore" }, { "path": "../../../../blocksuite/affine/all" }, - { "path": "../../../../blocksuite/affine/components" }, { "path": "../../../common/infra" }, { "path": "../../native" } ] diff --git a/packages/frontend/core/package.json b/packages/frontend/core/package.json index f272d2eae9..33126bb145 100644 --- a/packages/frontend/core/package.json +++ b/packages/frontend/core/package.json @@ -18,8 +18,6 @@ "@affine/templates": "workspace:*", "@affine/track": "workspace:*", "@blocksuite/affine": "workspace:*", - "@blocksuite/affine-components": "workspace:*", - "@blocksuite/affine-shared": "workspace:*", "@blocksuite/icons": "2.2.2", "@capacitor/app": "^6.0.2", "@capacitor/browser": "^6.0.4", diff --git a/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-panel-input.ts b/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-panel-input.ts index 53b3399e1d..225e8d55fb 100644 --- a/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-panel-input.ts +++ b/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-panel-input.ts @@ -1,12 +1,15 @@ import { stopPropagation } from '@affine/core/utils'; import type { EditorHost } from '@blocksuite/affine/block-std'; -import { type AIError, openFileOrFiles } from '@blocksuite/affine/blocks'; +import { + type AIError, + openFileOrFiles, + unsafeCSSVarV2, +} from '@blocksuite/affine/blocks'; import { assertExists, SignalWatcher, WithDisposable, } from '@blocksuite/affine/global/utils'; -import { unsafeCSSVarV2 } from '@blocksuite/affine-shared/theme'; import { ImageIcon, PublishIcon } from '@blocksuite/icons/lit'; import { css, html, LitElement, nothing } from 'lit'; import { property, query, state } from 'lit/decorators.js'; diff --git a/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/components/file-chip.ts b/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/components/file-chip.ts index 7897507906..7ba56f1e03 100644 --- a/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/components/file-chip.ts +++ b/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/components/file-chip.ts @@ -1,6 +1,6 @@ import { ShadowlessElement } from '@blocksuite/affine/block-std'; +import { getAttachmentFileIcons } from '@blocksuite/affine/blocks'; import { SignalWatcher, WithDisposable } from '@blocksuite/affine/global/utils'; -import { getAttachmentFileIcons } from '@blocksuite/affine-components/icons'; import { html } from 'lit'; import { property } from 'lit/decorators.js'; diff --git a/packages/frontend/core/src/blocksuite/presets/ai/utils/image.ts b/packages/frontend/core/src/blocksuite/presets/ai/utils/image.ts index 3a652ce7d3..4997275b81 100644 --- a/packages/frontend/core/src/blocksuite/presets/ai/utils/image.ts +++ b/packages/frontend/core/src/blocksuite/presets/ai/utils/image.ts @@ -1,5 +1,5 @@ +import { FetchUtils } from '@blocksuite/affine/blocks'; import { assertExists } from '@blocksuite/affine/global/utils'; -import { FetchUtils } from '@blocksuite/affine-shared/adapters'; export async function fetchImageToFile( url: string, diff --git a/packages/frontend/core/src/components/blocksuite/block-suite-editor/blocksuite-editor-container.tsx b/packages/frontend/core/src/components/blocksuite/block-suite-editor/blocksuite-editor-container.tsx index 747d6984b9..bd0b97ab67 100644 --- a/packages/frontend/core/src/components/blocksuite/block-suite-editor/blocksuite-editor-container.tsx +++ b/packages/frontend/core/src/components/blocksuite/block-suite-editor/blocksuite-editor-container.tsx @@ -1,8 +1,4 @@ -import { - type DocMode, - type NoteBlockModel, - NoteDisplayMode, -} from '@blocksuite/affine/blocks'; +import { type DocMode, getLastNoteBlock } from '@blocksuite/affine/blocks'; import { Slot } from '@blocksuite/affine/global/utils'; import type { AffineEditorContainer, @@ -10,7 +6,7 @@ import type { EdgelessEditor, PageEditor, } from '@blocksuite/affine/presets'; -import { type BlockModel, type Store } from '@blocksuite/affine/store'; +import { type Store } from '@blocksuite/affine/store'; import clsx from 'clsx'; import type React from 'react'; import { @@ -189,32 +185,3 @@ export const BlocksuiteEditorContainer = forwardRef< ); }); - -// copy from '@blocksuite/affine-shared/utils' -export function getLastNoteBlock(doc: Store) { - let note: NoteBlockModel | null = null; - if (!doc.root) return null; - const { children } = doc.root; - for (let i = children.length - 1; i >= 0; i--) { - const child = children[i]; - if ( - matchFlavours(child, ['affine:note']) && - child.displayMode !== NoteDisplayMode.EdgelessOnly - ) { - note = child as NoteBlockModel; - break; - } - } - return note; -} -export function matchFlavours( - model: BlockModel | null, - expected: Key -): model is BlockSuite.BlockModels[Key[number]] { - return ( - !!model && - expected.some( - key => (model.flavour as keyof BlockSuite.BlockModels) === key - ) - ); -} diff --git a/packages/frontend/core/src/components/blocksuite/block-suite-editor/specs/custom/database-block.ts b/packages/frontend/core/src/components/blocksuite/block-suite-editor/specs/custom/database-block.ts index 4165159680..d12a13f128 100644 --- a/packages/frontend/core/src/components/blocksuite/block-suite-editor/specs/custom/database-block.ts +++ b/packages/frontend/core/src/components/blocksuite/block-suite-editor/specs/custom/database-block.ts @@ -12,7 +12,7 @@ import type { DatabaseBlockModel, MenuOptions, } from '@blocksuite/affine/blocks'; -import { menu } from '@blocksuite/affine-components/context-menu'; +import { menu } from '@blocksuite/affine/blocks'; import { LinkIcon } from '@blocksuite/icons/lit'; import type { FrameworkProvider } from '@toeverything/infra'; diff --git a/packages/frontend/core/src/components/blocksuite/block-suite-editor/specs/custom/root-block.ts b/packages/frontend/core/src/components/blocksuite/block-suite-editor/specs/custom/root-block.ts index 2b0babc2f3..b7e84d7387 100644 --- a/packages/frontend/core/src/components/blocksuite/block-suite-editor/specs/custom/root-block.ts +++ b/packages/frontend/core/src/components/blocksuite/block-suite-editor/specs/custom/root-block.ts @@ -18,6 +18,7 @@ import type { DocDisplayMetaExtension, DocDisplayMetaParams, RootBlockConfig, + Signal, SpecBuilder, TelemetryEventMap, ThemeExtension, @@ -25,21 +26,18 @@ import type { import { CodeBlockSpec, ColorScheme, + createSignalFromObservable, DocDisplayMetaProvider, EditorSettingExtension, ImageBlockSpec, ParagraphBlockSpec, + referenceToNode, + SpecProvider, TelemetryProvider, ThemeExtensionIdentifier, } from '@blocksuite/affine/blocks'; import type { Container } from '@blocksuite/affine/global/di'; import type { ExtensionType } from '@blocksuite/affine/store'; -import { - createSignalFromObservable, - referenceToNode, - type Signal, - SpecProvider, -} from '@blocksuite/affine-shared/utils'; import { LinkedPageIcon, PageIcon } from '@blocksuite/icons/lit'; import { type FrameworkProvider } from '@toeverything/infra'; import type { TemplateResult } from 'lit'; diff --git a/packages/frontend/core/src/components/blocksuite/block-suite-editor/specs/custom/widgets/toolbar.ts b/packages/frontend/core/src/components/blocksuite/block-suite-editor/specs/custom/widgets/toolbar.ts index 1afbe6b031..78b3e591ae 100644 --- a/packages/frontend/core/src/components/blocksuite/block-suite-editor/specs/custom/widgets/toolbar.ts +++ b/packages/frontend/core/src/components/blocksuite/block-suite-editor/specs/custom/widgets/toolbar.ts @@ -12,8 +12,7 @@ import type { GfxBlockElementModel, GfxPrimitiveElementModel, } from '@blocksuite/affine/block-std/gfx'; -import { type MenuContext } from '@blocksuite/affine/blocks'; -import type { MenuItemGroup } from '@blocksuite/affine-components/toolbar'; +import type { MenuContext, MenuItemGroup } from '@blocksuite/affine/blocks'; import { LinkIcon } from '@blocksuite/icons/lit'; import type { FrameworkProvider } from '@toeverything/infra'; diff --git a/packages/frontend/core/src/components/hooks/affine/use-reference-link-helper.ts b/packages/frontend/core/src/components/hooks/affine/use-reference-link-helper.ts index 98ad23f14f..e3c34f4a9a 100644 --- a/packages/frontend/core/src/components/hooks/affine/use-reference-link-helper.ts +++ b/packages/frontend/core/src/components/hooks/affine/use-reference-link-helper.ts @@ -1,6 +1,6 @@ +import type { AffineTextAttributes } from '@blocksuite/affine/blocks'; import type { DeltaInsert } from '@blocksuite/affine/inline'; import { Text, type Workspace } from '@blocksuite/affine/store'; -import type { AffineTextAttributes } from '@blocksuite/affine-shared/types'; import { useCallback } from 'react'; export function useReferenceLinkHelper(docCollection: Workspace) { diff --git a/packages/frontend/core/src/desktop/dialogs/setting/general-setting/editor/edgeless/snapshot.tsx b/packages/frontend/core/src/desktop/dialogs/setting/general-setting/editor/edgeless/snapshot.tsx index 01d4f094e3..a917435ea4 100644 --- a/packages/frontend/core/src/desktop/dialogs/setting/general-setting/editor/edgeless/snapshot.tsx +++ b/packages/frontend/core/src/desktop/dialogs/setting/general-setting/editor/edgeless/snapshot.tsx @@ -15,13 +15,13 @@ import type { } from '@blocksuite/affine/blocks'; import { ColorScheme, + createSignalFromObservable, SpecProvider, ThemeExtensionIdentifier, } from '@blocksuite/affine/blocks'; import type { Container } from '@blocksuite/affine/global/di'; import { Bound } from '@blocksuite/affine/global/utils'; import type { Block, Store } from '@blocksuite/affine/store'; -import { createSignalFromObservable } from '@blocksuite/affine-shared/utils'; import type { Signal } from '@preact/signals-core'; import type { FrameworkProvider } from '@toeverything/infra'; import { useFramework } from '@toeverything/infra'; diff --git a/packages/frontend/core/src/desktop/pages/workspace/detail-page/tabs/chat.tsx b/packages/frontend/core/src/desktop/pages/workspace/detail-page/tabs/chat.tsx index d0a70520e2..5400a1990b 100644 --- a/packages/frontend/core/src/desktop/pages/workspace/detail-page/tabs/chat.tsx +++ b/packages/frontend/core/src/desktop/pages/workspace/detail-page/tabs/chat.tsx @@ -3,11 +3,11 @@ import { AINetworkSearchService } from '@affine/core/modules/ai-button/services/ import { DocDisplayMetaService } from '@affine/core/modules/doc-display-meta'; import { WorkspaceService } from '@affine/core/modules/workspace'; import { + createSignalFromObservable, DocModeProvider, RefNodeSlotsProvider, } from '@blocksuite/affine/blocks'; import type { AffineEditorContainer } from '@blocksuite/affine/presets'; -import { createSignalFromObservable } from '@blocksuite/affine-shared/utils'; import { useFramework } from '@toeverything/infra'; import { forwardRef, useEffect, useRef } from 'react'; diff --git a/packages/frontend/core/src/modules/ai-button/services/network-search.ts b/packages/frontend/core/src/modules/ai-button/services/network-search.ts index 73574159ed..9fa2f2ebcc 100644 --- a/packages/frontend/core/src/modules/ai-button/services/network-search.ts +++ b/packages/frontend/core/src/modules/ai-button/services/network-search.ts @@ -1,7 +1,7 @@ import { createSignalFromObservable, type Signal, -} from '@blocksuite/affine-shared/utils'; +} from '@blocksuite/affine/blocks'; import { LiveData, Service } from '@toeverything/infra'; import type { FeatureFlagService } from '../../feature-flag'; diff --git a/packages/frontend/core/src/modules/at-menu-config/services/index.ts b/packages/frontend/core/src/modules/at-menu-config/services/index.ts index 2295a92743..27d8e20b96 100644 --- a/packages/frontend/core/src/modules/at-menu-config/services/index.ts +++ b/packages/frontend/core/src/modules/at-menu-config/services/index.ts @@ -4,6 +4,7 @@ import track from '@affine/track'; import type { EditorHost } from '@blocksuite/affine/block-std'; import { type AffineInlineEditor, + createSignalFromObservable, type DocMode, type LinkedMenuGroup, type LinkedMenuItem, @@ -12,7 +13,6 @@ import { } from '@blocksuite/affine/blocks'; import type { DocMeta } from '@blocksuite/affine/store'; import { Text } from '@blocksuite/affine/store'; -import { createSignalFromObservable } from '@blocksuite/affine-shared/utils'; import { DateTimeIcon, NewXxxEdgelessIcon, diff --git a/packages/frontend/core/src/modules/doc/services/docs.ts b/packages/frontend/core/src/modules/doc/services/docs.ts index 035375f831..91312f6b1c 100644 --- a/packages/frontend/core/src/modules/doc/services/docs.ts +++ b/packages/frontend/core/src/modules/doc/services/docs.ts @@ -1,9 +1,12 @@ import { DebugLogger } from '@affine/debug'; import { Unreachable } from '@affine/env/constant'; -import { type DocMode, replaceIdMiddleware } from '@blocksuite/affine/blocks'; +import { + type AffineTextAttributes, + type DocMode, + replaceIdMiddleware, +} from '@blocksuite/affine/blocks'; import type { DeltaInsert } from '@blocksuite/affine/inline'; import { Slice, Text, Transformer } from '@blocksuite/affine/store'; -import type { AffineTextAttributes } from '@blocksuite/affine-shared/types'; import { LiveData, ObjectPool, Service } from '@toeverything/infra'; import { omitBy } from 'lodash-es'; import { combineLatest, map } from 'rxjs'; diff --git a/packages/frontend/core/src/modules/docs-search/worker/in-worker.ts b/packages/frontend/core/src/modules/docs-search/worker/in-worker.ts index d8504df438..3b5c710cdf 100644 --- a/packages/frontend/core/src/modules/docs-search/worker/in-worker.ts +++ b/packages/frontend/core/src/modules/docs-search/worker/in-worker.ts @@ -1,4 +1,5 @@ import type { + AffineTextAttributes, AttachmentBlockModel, BookmarkBlockModel, EmbedBlockModel, @@ -18,7 +19,6 @@ import { type TransformerMiddleware, type YBlock, } from '@blocksuite/affine/store'; -import type { AffineTextAttributes } from '@blocksuite/affine-shared/types'; import type { DeltaInsert } from '@blocksuite/inline'; import { Document } from '@toeverything/infra'; import { toHexString } from 'lib0/buffer.js'; diff --git a/packages/frontend/core/src/modules/editor-setting/entities/editor-setting.ts b/packages/frontend/core/src/modules/editor-setting/entities/editor-setting.ts index bd8104ee52..c22831996b 100644 --- a/packages/frontend/core/src/modules/editor-setting/entities/editor-setting.ts +++ b/packages/frontend/core/src/modules/editor-setting/entities/editor-setting.ts @@ -1,8 +1,8 @@ -import type { DeepPartial } from '@blocksuite/affine/global/utils'; import { createSignalFromObservable, type Signal, -} from '@blocksuite/affine-shared/utils'; +} from '@blocksuite/affine/blocks'; +import type { DeepPartial } from '@blocksuite/affine/global/utils'; import { Entity, LiveData } from '@toeverything/infra'; import { isObject, merge } from 'lodash-es'; import type { Observable } from 'rxjs'; @@ -14,7 +14,7 @@ import { EditorSettingSchema } from '../schema'; type SettingItem = { readonly value: T; set: (value: T) => void; - // eslint-disable-next-line rxjs/finnish + $: LiveData; }; diff --git a/packages/frontend/core/src/modules/editor-setting/schema.ts b/packages/frontend/core/src/modules/editor-setting/schema.ts index 4d09552776..bcfc106cc7 100644 --- a/packages/frontend/core/src/modules/editor-setting/schema.ts +++ b/packages/frontend/core/src/modules/editor-setting/schema.ts @@ -1,4 +1,4 @@ -import { GeneralSettingSchema } from '@blocksuite/affine-shared/services'; +import { GeneralSettingSchema } from '@blocksuite/affine/blocks'; import { z } from 'zod'; export const BSEditorSettingSchema = GeneralSettingSchema; diff --git a/packages/frontend/core/tsconfig.json b/packages/frontend/core/tsconfig.json index 6e4743c910..d3e9b2d732 100644 --- a/packages/frontend/core/tsconfig.json +++ b/packages/frontend/core/tsconfig.json @@ -16,11 +16,6 @@ { "path": "../../common/nbstore" }, { "path": "../track" }, { "path": "../../../blocksuite/affine/all" }, - { "path": "../../../blocksuite/affine/components" }, - { "path": "../../../blocksuite/affine/shared" }, - { "path": "../../../blocksuite/framework/block-std" }, - { "path": "../../../blocksuite/framework/global" }, - { "path": "../../../blocksuite/framework/store" }, { "path": "../../common/infra" } ] } diff --git a/tools/utils/src/workspace.gen.ts b/tools/utils/src/workspace.gen.ts index 12eae061dd..6999702617 100644 --- a/tools/utils/src/workspace.gen.ts +++ b/tools/utils/src/workspace.gen.ts @@ -540,7 +540,6 @@ export const PackageList = [ 'packages/frontend/i18n', 'packages/common/nbstore', 'blocksuite/affine/all', - 'blocksuite/affine/components', 'packages/common/infra', 'packages/frontend/native', ], @@ -593,11 +592,6 @@ export const PackageList = [ 'packages/frontend/templates', 'packages/frontend/track', 'blocksuite/affine/all', - 'blocksuite/affine/components', - 'blocksuite/affine/shared', - 'blocksuite/framework/block-std', - 'blocksuite/framework/global', - 'blocksuite/framework/store', 'packages/common/infra', ], }, diff --git a/yarn.lock b/yarn.lock index 0ef3663b24..a1a85feb09 100644 --- a/yarn.lock +++ b/yarn.lock @@ -360,8 +360,6 @@ __metadata: "@affine/templates": "workspace:*" "@affine/track": "workspace:*" "@blocksuite/affine": "workspace:*" - "@blocksuite/affine-components": "workspace:*" - "@blocksuite/affine-shared": "workspace:*" "@blocksuite/icons": "npm:2.2.2" "@capacitor/app": "npm:^6.0.2" "@capacitor/browser": "npm:^6.0.4" @@ -605,7 +603,6 @@ __metadata: "@affine/native": "workspace:*" "@affine/nbstore": "workspace:*" "@blocksuite/affine": "workspace:*" - "@blocksuite/affine-components": "workspace:*" "@blocksuite/icons": "npm:2.2.2" "@capacitor/app": "npm:^6.0.2" "@capacitor/browser": "npm:^6.0.4"