mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-08 04:36:13 +08:00
refactor(editor): remove block models global type (#10086)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { FrameIcon } from '@blocksuite/affine-components/icons';
|
||||
import { MindmapElementModel } from '@blocksuite/affine-model';
|
||||
import { TelemetryProvider } from '@blocksuite/affine-shared/services';
|
||||
import type { GfxModel } from '@blocksuite/block-std/gfx';
|
||||
import { Bound, WithDisposable } from '@blocksuite/global/utils';
|
||||
import { css, html, LitElement, nothing } from 'lit';
|
||||
import { property } from 'lit/decorators.js';
|
||||
@@ -48,7 +49,7 @@ export class EdgelessAddFrameButton extends WithDisposable(LitElement) {
|
||||
|
||||
export function renderAddFrameButton(
|
||||
edgeless: EdgelessRootBlockComponent,
|
||||
elements: BlockSuite.EdgelessModel[]
|
||||
elements: GfxModel[]
|
||||
) {
|
||||
if (elements.length < 2) return nothing;
|
||||
if (elements.some(e => e.group instanceof MindmapElementModel))
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
GroupElementModel,
|
||||
MindmapElementModel,
|
||||
} from '@blocksuite/affine-model';
|
||||
import type { GfxModel } from '@blocksuite/block-std/gfx';
|
||||
import { WithDisposable } from '@blocksuite/global/utils';
|
||||
import { css, html, LitElement, nothing } from 'lit';
|
||||
import { property } from 'lit/decorators.js';
|
||||
@@ -39,7 +40,7 @@ export class EdgelessAddGroupButton extends WithDisposable(LitElement) {
|
||||
|
||||
export function renderAddGroupButton(
|
||||
edgeless: EdgelessRootBlockComponent,
|
||||
elements: BlockSuite.EdgelessModel[]
|
||||
elements: GfxModel[]
|
||||
) {
|
||||
if (elements.length < 2) return nothing;
|
||||
if (elements[0] instanceof GroupElementModel) return nothing;
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
SmallArrowDownIcon,
|
||||
} from '@blocksuite/affine-components/icons';
|
||||
import { MindmapElementModel } from '@blocksuite/affine-model';
|
||||
import type { GfxModel } from '@blocksuite/block-std/gfx';
|
||||
import { Bound, WithDisposable } from '@blocksuite/global/utils';
|
||||
import { AutoTidyUpIcon, ResizeTidyUpIcon } from '@blocksuite/icons/lit';
|
||||
import { css, html, LitElement, nothing, type TemplateResult } from 'lit';
|
||||
@@ -271,7 +272,7 @@ export class EdgelessAlignButton extends WithDisposable(LitElement) {
|
||||
});
|
||||
}
|
||||
|
||||
private _updateXYWH(ele: BlockSuite.EdgelessModel, bound: Bound) {
|
||||
private _updateXYWH(ele: GfxModel, bound: Bound) {
|
||||
const { updateElement } = this.edgeless.std.get(EdgelessCRUDIdentifier);
|
||||
const { updateBlock } = this.edgeless.doc;
|
||||
updateXYWH(ele, bound, updateElement, updateBlock);
|
||||
@@ -333,7 +334,7 @@ export class EdgelessAlignButton extends WithDisposable(LitElement) {
|
||||
|
||||
export function renderAlignButton(
|
||||
edgeless: EdgelessRootBlockComponent,
|
||||
elements: BlockSuite.EdgelessModel[]
|
||||
elements: GfxModel[]
|
||||
) {
|
||||
if (elements.length < 2) return nothing;
|
||||
if (elements.some(e => e.group instanceof MindmapElementModel))
|
||||
|
||||
@@ -25,7 +25,7 @@ import {
|
||||
} from '@blocksuite/affine-model';
|
||||
import { FeatureFlagService } from '@blocksuite/affine-shared/services';
|
||||
import type { ColorEvent } from '@blocksuite/affine-shared/utils';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import { matchModels } from '@blocksuite/affine-shared/utils';
|
||||
import { GfxExtensionIdentifier } from '@blocksuite/block-std/gfx';
|
||||
import {
|
||||
countBy,
|
||||
@@ -93,7 +93,7 @@ export class EdgelessChangeFrameButton extends WithDisposable(LitElement) {
|
||||
const rootModel = this.edgeless.doc.root;
|
||||
const notes = rootModel.children.filter(
|
||||
model =>
|
||||
matchFlavours(model, [NoteBlockModel]) &&
|
||||
matchModels(model, [NoteBlockModel]) &&
|
||||
model.displayMode !== NoteDisplayMode.EdgelessOnly
|
||||
);
|
||||
const lastNote = notes[notes.length - 1];
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
NoteBlockModel,
|
||||
NoteDisplayMode,
|
||||
} from '@blocksuite/affine-model';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import { matchModels } from '@blocksuite/affine-shared/utils';
|
||||
import {
|
||||
deserializeXYWH,
|
||||
serializeXYWH,
|
||||
@@ -31,7 +31,7 @@ export class EdgelessChangeGroupButton extends WithDisposable(LitElement) {
|
||||
const rootModel = this.edgeless.doc.root;
|
||||
const notes = rootModel.children.filter(
|
||||
model =>
|
||||
matchFlavours(model, [NoteBlockModel]) &&
|
||||
matchModels(model, [NoteBlockModel]) &&
|
||||
model.displayMode !== NoteDisplayMode.EdgelessOnly
|
||||
);
|
||||
const lastNote = notes[notes.length - 1];
|
||||
|
||||
@@ -35,7 +35,7 @@ import {
|
||||
SidebarExtensionIdentifier,
|
||||
ThemeProvider,
|
||||
} from '@blocksuite/affine-shared/services';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import { matchModels } from '@blocksuite/affine-shared/utils';
|
||||
import {
|
||||
Bound,
|
||||
countBy,
|
||||
@@ -158,7 +158,7 @@ export class EdgelessChangeNoteButton extends WithDisposable(LitElement) {
|
||||
this._pageBlockEnabled &&
|
||||
this.notes.length === 1 &&
|
||||
this.notes[0].parent?.children.find(child =>
|
||||
matchFlavours(child, [NoteBlockModel])
|
||||
matchModels(child, [NoteBlockModel])
|
||||
) === this.notes[0]
|
||||
);
|
||||
}
|
||||
@@ -340,7 +340,7 @@ export class EdgelessChangeNoteButton extends WithDisposable(LitElement) {
|
||||
const isFirstNote =
|
||||
onlyOne &&
|
||||
note.parent?.children.find(child =>
|
||||
matchFlavours(child, [NoteBlockModel])
|
||||
matchModels(child, [NoteBlockModel])
|
||||
) === note;
|
||||
const theme = this.edgeless.std.get(ThemeProvider).theme;
|
||||
const buttons = [
|
||||
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
import { ThemeProvider } from '@blocksuite/affine-shared/services';
|
||||
import { requestConnectedFrame } from '@blocksuite/affine-shared/utils';
|
||||
import { WidgetComponent } from '@blocksuite/block-std';
|
||||
import type { GfxModel } from '@blocksuite/block-std/gfx';
|
||||
import {
|
||||
atLeastNMatches,
|
||||
clamp,
|
||||
@@ -85,7 +86,7 @@ type CategorizedElements = {
|
||||
|
||||
type CustomEntry = {
|
||||
render: (edgeless: EdgelessRootBlockComponent) => TemplateResult | null;
|
||||
when: (model: BlockSuite.EdgelessModel[]) => boolean;
|
||||
when: (model: GfxModel[]) => boolean;
|
||||
};
|
||||
|
||||
export const EDGELESS_ELEMENT_TOOLBAR_WIDGET =
|
||||
@@ -461,7 +462,7 @@ export class EdgelessElementToolbarWidget extends WidgetComponent<
|
||||
@state()
|
||||
private accessor _registeredEntries: {
|
||||
render: (edgeless: EdgelessRootBlockComponent) => TemplateResult | null;
|
||||
when: (model: BlockSuite.EdgelessModel[]) => boolean;
|
||||
when: (model: GfxModel[]) => boolean;
|
||||
}[] = [];
|
||||
|
||||
@property({ attribute: false })
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { MenuItemGroup } from '@blocksuite/affine-components/toolbar';
|
||||
import { renderGroups } from '@blocksuite/affine-components/toolbar';
|
||||
import type { GfxModel } from '@blocksuite/block-std/gfx';
|
||||
import { WithDisposable } from '@blocksuite/global/utils';
|
||||
import { MoreHorizontalIcon, MoreVerticalIcon } from '@blocksuite/icons/lit';
|
||||
import { html, LitElement } from 'lit';
|
||||
@@ -39,7 +40,7 @@ export class EdgelessMoreButton extends WithDisposable(LitElement) {
|
||||
accessor edgeless!: EdgelessRootBlockComponent;
|
||||
|
||||
@property({ attribute: false })
|
||||
accessor elements: BlockSuite.EdgelessModel[] = [];
|
||||
accessor elements: GfxModel[] = [];
|
||||
|
||||
@property({ attribute: false })
|
||||
accessor groups!: MenuItemGroup<ElementToolbarMoreMenuContext>[];
|
||||
|
||||
+4
-12
@@ -4,7 +4,7 @@ import { NoteDisplayMode } from '@blocksuite/affine-model';
|
||||
import { DocModeProvider } from '@blocksuite/affine-shared/services';
|
||||
import { getBlockProps } from '@blocksuite/affine-shared/utils';
|
||||
import type { EditorHost } from '@blocksuite/block-std';
|
||||
import { GfxBlockElementModel } from '@blocksuite/block-std/gfx';
|
||||
import { GfxBlockElementModel, type GfxModel } from '@blocksuite/block-std/gfx';
|
||||
import { type BlockModel, type Store, Text } from '@blocksuite/store';
|
||||
|
||||
import {
|
||||
@@ -17,11 +17,7 @@ import { isFrameBlock } from '../../../edgeless/utils/query.js';
|
||||
function addBlocksToDoc(targetDoc: Store, model: BlockModel, parentId: string) {
|
||||
// Add current block to linked doc
|
||||
const blockProps = getBlockProps(model);
|
||||
const newModelId = targetDoc.addBlock(
|
||||
model.flavour as BlockSuite.Flavour,
|
||||
blockProps,
|
||||
parentId
|
||||
);
|
||||
const newModelId = targetDoc.addBlock(model.flavour, blockProps, parentId);
|
||||
// Add children to linked doc, parent is the new model
|
||||
const children = model.children;
|
||||
if (children.length > 0) {
|
||||
@@ -64,7 +60,7 @@ export function createLinkedDocFromNote(
|
||||
|
||||
export function createLinkedDocFromEdgelessElements(
|
||||
host: EditorHost,
|
||||
elements: BlockSuite.EdgelessModel[],
|
||||
elements: GfxModel[],
|
||||
docTitle?: string
|
||||
) {
|
||||
const linkedDoc = host.doc.workspace.createDoc({});
|
||||
@@ -93,11 +89,7 @@ export function createLinkedDocFromEdgelessElements(
|
||||
mapFrameIds(blockProps as unknown as FrameBlockModel, ids);
|
||||
}
|
||||
|
||||
newId = linkedDoc.addBlock(
|
||||
model.flavour as BlockSuite.Flavour,
|
||||
blockProps,
|
||||
surfaceId
|
||||
);
|
||||
newId = linkedDoc.addBlock(model.flavour, blockProps, surfaceId);
|
||||
}
|
||||
} else {
|
||||
const props = getElementProps(model, ids);
|
||||
|
||||
Reference in New Issue
Block a user