refactor(editor): remove global types in edgeless (#10092)
Closes: [BS-2553](https://linear.app/affine-design/issue/BS-2553/remove-global-types-in-edgeless)
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import type { SurfaceElementModelMap } from '@blocksuite/affine-model';
|
||||||
import { EditPropsStore } from '@blocksuite/affine-shared/services';
|
import { EditPropsStore } from '@blocksuite/affine-shared/services';
|
||||||
import { type BlockStdScope, StdIdentifier } from '@blocksuite/block-std';
|
import { type BlockStdScope, StdIdentifier } from '@blocksuite/block-std';
|
||||||
import {
|
import {
|
||||||
@@ -62,13 +63,13 @@ export class EdgelessCRUDExtension extends Extension {
|
|||||||
};
|
};
|
||||||
|
|
||||||
addBlock = (
|
addBlock = (
|
||||||
flavour: BlockSuite.EdgelessModelKeys | string,
|
flavour: string,
|
||||||
props: Record<string, unknown>,
|
props: Record<string, unknown>,
|
||||||
parentId?: string | BlockModel,
|
parentId?: string | BlockModel,
|
||||||
parentIndex?: number
|
parentIndex?: number
|
||||||
) => {
|
) => {
|
||||||
const gfx = this.std.get(GfxControllerIdentifier);
|
const gfx = this.std.get(GfxControllerIdentifier);
|
||||||
const key = getLastPropsKey(flavour as BlockSuite.EdgelessModelKeys, props);
|
const key = getLastPropsKey(flavour, props);
|
||||||
if (key) {
|
if (key) {
|
||||||
props = this.std.get(EditPropsStore).applyLastProps(key, props);
|
props = this.std.get(EditPropsStore).applyLastProps(key, props);
|
||||||
}
|
}
|
||||||
@@ -94,7 +95,7 @@ export class EdgelessCRUDExtension extends Extension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const gfx = this.std.get(GfxControllerIdentifier);
|
const gfx = this.std.get(GfxControllerIdentifier);
|
||||||
const key = getLastPropsKey(type as BlockSuite.EdgelessModelKeys, props);
|
const key = getLastPropsKey(type, props);
|
||||||
if (key) {
|
if (key) {
|
||||||
props = this.std.get(EditPropsStore).applyLastProps(key, props) as T;
|
props = this.std.get(EditPropsStore).applyLastProps(key, props) as T;
|
||||||
}
|
}
|
||||||
@@ -117,10 +118,10 @@ export class EdgelessCRUDExtension extends Extension {
|
|||||||
|
|
||||||
const element = this._surface.getElementById(id);
|
const element = this._surface.getElementById(id);
|
||||||
if (element) {
|
if (element) {
|
||||||
const key = getLastPropsKey(
|
const key = getLastPropsKey(element.type, {
|
||||||
element.type as BlockSuite.EdgelessModelKeys,
|
...element.yMap.toJSON(),
|
||||||
{ ...element.yMap.toJSON(), ...props }
|
...props,
|
||||||
);
|
});
|
||||||
key && this.std.get(EditPropsStore).recordLastProps(key, props);
|
key && this.std.get(EditPropsStore).recordLastProps(key, props);
|
||||||
this._surface.updateElement(id, props);
|
this._surface.updateElement(id, props);
|
||||||
return;
|
return;
|
||||||
@@ -128,10 +129,10 @@ export class EdgelessCRUDExtension extends Extension {
|
|||||||
|
|
||||||
const block = this.std.store.getBlockById(id);
|
const block = this.std.store.getBlockById(id);
|
||||||
if (block) {
|
if (block) {
|
||||||
const key = getLastPropsKey(
|
const key = getLastPropsKey(block.flavour, {
|
||||||
block.flavour as BlockSuite.EdgelessModelKeys,
|
...block.yBlock.toJSON(),
|
||||||
{ ...block.yBlock.toJSON(), ...props }
|
...props,
|
||||||
);
|
});
|
||||||
key && this.std.get(EditPropsStore).recordLastProps(key, props);
|
key && this.std.get(EditPropsStore).recordLastProps(key, props);
|
||||||
this.std.store.updateBlock(block, props);
|
this.std.store.updateBlock(block, props);
|
||||||
}
|
}
|
||||||
@@ -142,17 +143,13 @@ export class EdgelessCRUDExtension extends Extension {
|
|||||||
if (!surface) {
|
if (!surface) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const el =
|
const el = surface.getElementById(id) ?? this.std.store.getBlockById(id);
|
||||||
surface.getElementById(id) ??
|
return el as GfxModel | null;
|
||||||
(this.std.store.getBlockById(
|
|
||||||
id
|
|
||||||
) as BlockSuite.EdgelessBlockModelType | null);
|
|
||||||
return el;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getElementsByType<K extends keyof BlockSuite.SurfaceElementModelMap>(
|
getElementsByType<K extends keyof SurfaceElementModelMap>(
|
||||||
type: K
|
type: K
|
||||||
): BlockSuite.SurfaceElementModelMap[K][] {
|
): SurfaceElementModelMap[K][] {
|
||||||
if (!this._surface) {
|
if (!this._surface) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,11 @@ import {
|
|||||||
type LocalConnectorElementModel,
|
type LocalConnectorElementModel,
|
||||||
} from '@blocksuite/affine-model';
|
} from '@blocksuite/affine-model';
|
||||||
import { ThemeProvider } from '@blocksuite/affine-shared/services';
|
import { ThemeProvider } from '@blocksuite/affine-shared/services';
|
||||||
import type { GfxController, GfxModel } from '@blocksuite/block-std/gfx';
|
import type {
|
||||||
|
GfxController,
|
||||||
|
GfxLocalElementModel,
|
||||||
|
GfxModel,
|
||||||
|
} from '@blocksuite/block-std/gfx';
|
||||||
import type { IBound, IVec, IVec3 } from '@blocksuite/global/utils';
|
import type { IBound, IVec, IVec3 } from '@blocksuite/global/utils';
|
||||||
import {
|
import {
|
||||||
almostEqual,
|
almostEqual,
|
||||||
@@ -70,9 +74,7 @@ export const ConnectorEndpointLocationsOnTriangle: IVec[] = [
|
|||||||
[0.25, 0.5],
|
[0.25, 0.5],
|
||||||
];
|
];
|
||||||
|
|
||||||
export function isConnectorWithLabel(
|
export function isConnectorWithLabel(model: GfxModel | GfxLocalElementModel) {
|
||||||
model: GfxModel | BlockSuite.SurfaceLocalModel
|
|
||||||
) {
|
|
||||||
return model instanceof ConnectorElementModel && model.hasLabel();
|
return model instanceof ConnectorElementModel && model.hasLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
import type { GfxPrimitiveElementModel } from '@blocksuite/block-std/gfx';
|
||||||
import type { IBound } from '@blocksuite/global/utils';
|
import type { IBound } from '@blocksuite/global/utils';
|
||||||
|
|
||||||
import type { RoughCanvas, SurfaceElementModel } from '../../index.js';
|
import type { RoughCanvas } from '../../index.js';
|
||||||
import type { CanvasRenderer } from '../canvas-renderer.js';
|
import type { CanvasRenderer } from '../canvas-renderer.js';
|
||||||
import { brush } from './brush/index.js';
|
import { brush } from './brush/index.js';
|
||||||
import { connector } from './connector/index.js';
|
import { connector } from './connector/index.js';
|
||||||
@@ -11,7 +12,7 @@ import { text } from './text/index.js';
|
|||||||
export { normalizeShapeBound } from './shape/utils.js';
|
export { normalizeShapeBound } from './shape/utils.js';
|
||||||
|
|
||||||
export type ElementRenderer<
|
export type ElementRenderer<
|
||||||
T extends BlockSuite.SurfaceElementModel = SurfaceElementModel,
|
T extends GfxPrimitiveElementModel = GfxPrimitiveElementModel,
|
||||||
> = (
|
> = (
|
||||||
model: T,
|
model: T,
|
||||||
ctx: CanvasRenderingContext2D,
|
ctx: CanvasRenderingContext2D,
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import type { ConnectorElementModel } from '@blocksuite/affine-model';
|
import type {
|
||||||
|
ConnectorElementModel,
|
||||||
|
SurfaceElementModelMap,
|
||||||
|
} from '@blocksuite/affine-model';
|
||||||
import type { SurfaceBlockProps } from '@blocksuite/block-std/gfx';
|
import type { SurfaceBlockProps } from '@blocksuite/block-std/gfx';
|
||||||
import { SurfaceBlockModel as BaseSurfaceModel } from '@blocksuite/block-std/gfx';
|
import { SurfaceBlockModel as BaseSurfaceModel } from '@blocksuite/block-std/gfx';
|
||||||
import { DisposableGroup } from '@blocksuite/global/utils';
|
import { DisposableGroup } from '@blocksuite/global/utils';
|
||||||
@@ -55,11 +58,9 @@ export class SurfaceBlockModel extends BaseSurfaceModel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
override getElementsByType<K extends keyof BlockSuite.SurfaceElementModelMap>(
|
override getElementsByType<K extends keyof SurfaceElementModelMap>(
|
||||||
type: K
|
type: K
|
||||||
): BlockSuite.SurfaceElementModelMap[K][] {
|
): SurfaceElementModelMap[K][] {
|
||||||
return super.getElementsByType(
|
return super.getElementsByType(type) as SurfaceElementModelMap[K][];
|
||||||
type
|
|
||||||
) as BlockSuite.SurfaceElementModelMap[K][];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ import { TelemetryProvider } from '@blocksuite/affine-shared/services';
|
|||||||
import type { NoteChildrenFlavour } from '@blocksuite/affine-shared/types';
|
import type { NoteChildrenFlavour } from '@blocksuite/affine-shared/types';
|
||||||
import { handleNativeRangeAtPoint } from '@blocksuite/affine-shared/utils';
|
import { handleNativeRangeAtPoint } from '@blocksuite/affine-shared/utils';
|
||||||
import type { BlockStdScope } from '@blocksuite/block-std';
|
import type { BlockStdScope } from '@blocksuite/block-std';
|
||||||
import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';
|
import {
|
||||||
|
type GfxBlockElementModel,
|
||||||
|
GfxControllerIdentifier,
|
||||||
|
} from '@blocksuite/block-std/gfx';
|
||||||
import {
|
import {
|
||||||
type IPoint,
|
type IPoint,
|
||||||
type Point,
|
type Point,
|
||||||
@@ -117,7 +120,7 @@ export function addNote(
|
|||||||
const blocks =
|
const blocks =
|
||||||
(doc.root?.children.filter(
|
(doc.root?.children.filter(
|
||||||
child => child.flavour === 'affine:note'
|
child => child.flavour === 'affine:note'
|
||||||
) as BlockSuite.EdgelessBlockModelType[]) ?? [];
|
) as GfxBlockElementModel[]) ?? [];
|
||||||
const element = blocks.find(b => b.id === noteId);
|
const element = blocks.find(b => b.id === noteId);
|
||||||
if (element) {
|
if (element) {
|
||||||
gfx.selection.set({
|
gfx.selection.set({
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { NodePropsSchema } from '@blocksuite/affine-shared/utils';
|
|||||||
const LastPropsSchema = NodePropsSchema;
|
const LastPropsSchema = NodePropsSchema;
|
||||||
|
|
||||||
export function getLastPropsKey(
|
export function getLastPropsKey(
|
||||||
modelType: BlockSuite.EdgelessModelKeys,
|
modelType: string,
|
||||||
modelProps: Partial<LastProps[LastPropsKey]>
|
modelProps: Partial<LastProps[LastPropsKey]>
|
||||||
): LastPropsKey | null {
|
): LastPropsKey | null {
|
||||||
if (modelType === 'shape') {
|
if (modelType === 'shape') {
|
||||||
|
|||||||
@@ -88,11 +88,3 @@ export const AttachmentBlockSchema = defineBlockSchema({
|
|||||||
export class AttachmentBlockModel
|
export class AttachmentBlockModel
|
||||||
extends GfxCompatible<AttachmentBlockProps>(BlockModel)
|
extends GfxCompatible<AttachmentBlockProps>(BlockModel)
|
||||||
implements GfxElementGeometry {}
|
implements GfxElementGeometry {}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface EdgelessBlockModelMap {
|
|
||||||
'affine:attachment': AttachmentBlockModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -57,11 +57,3 @@ export const BookmarkBlockSchema = defineBlockSchema({
|
|||||||
export class BookmarkBlockModel
|
export class BookmarkBlockModel
|
||||||
extends GfxCompatible<BookmarkBlockProps>(BlockModel)
|
extends GfxCompatible<BookmarkBlockProps>(BlockModel)
|
||||||
implements GfxElementGeometry {}
|
implements GfxElementGeometry {}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface EdgelessBlockModelMap {
|
|
||||||
'affine:bookmark': BookmarkBlockModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -79,15 +79,3 @@ export const EdgelessTextBlockSchema = defineBlockSchema({
|
|||||||
export class EdgelessTextBlockModel
|
export class EdgelessTextBlockModel
|
||||||
extends GfxCompatible<EdgelessTextProps>(BlockModel)
|
extends GfxCompatible<EdgelessTextProps>(BlockModel)
|
||||||
implements GfxElementGeometry {}
|
implements GfxElementGeometry {}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface EdgelessBlockModelMap {
|
|
||||||
'affine:edgeless-text': EdgelessTextBlockModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface EdgelessTextModelMap {
|
|
||||||
'edgeless-text': EdgelessTextBlockModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -19,11 +19,3 @@ export type EmbedFigmaBlockProps = {
|
|||||||
export class EmbedFigmaModel extends defineEmbedModel<EmbedFigmaBlockProps>(
|
export class EmbedFigmaModel extends defineEmbedModel<EmbedFigmaBlockProps>(
|
||||||
BlockModel
|
BlockModel
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface EdgelessBlockModelMap {
|
|
||||||
'affine:embed-figma': EmbedFigmaModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -33,11 +33,3 @@ export type EmbedGithubBlockProps = {
|
|||||||
export class EmbedGithubModel extends defineEmbedModel<EmbedGithubBlockProps>(
|
export class EmbedGithubModel extends defineEmbedModel<EmbedGithubBlockProps>(
|
||||||
BlockModel
|
BlockModel
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface EdgelessBlockModelMap {
|
|
||||||
'affine:embed-github': EmbedGithubModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -15,11 +15,3 @@ export type EmbedHtmlBlockProps = {
|
|||||||
export class EmbedHtmlModel extends defineEmbedModel<EmbedHtmlBlockProps>(
|
export class EmbedHtmlModel extends defineEmbedModel<EmbedHtmlBlockProps>(
|
||||||
BlockModel
|
BlockModel
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface EdgelessBlockModelMap {
|
|
||||||
'affine:embed-html': EmbedHtmlModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -20,11 +20,3 @@ export type EmbedLinkedDocBlockProps = {
|
|||||||
export class EmbedLinkedDocModel extends defineEmbedModel<EmbedLinkedDocBlockProps>(
|
export class EmbedLinkedDocModel extends defineEmbedModel<EmbedLinkedDocBlockProps>(
|
||||||
BlockModel
|
BlockModel
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface EdgelessBlockModelMap {
|
|
||||||
'affine:embed-linked-doc': EmbedLinkedDocModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -21,11 +21,3 @@ export type EmbedLoomBlockProps = {
|
|||||||
export class EmbedLoomModel extends defineEmbedModel<EmbedLoomBlockProps>(
|
export class EmbedLoomModel extends defineEmbedModel<EmbedLoomBlockProps>(
|
||||||
BlockModel
|
BlockModel
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface EdgelessBlockModelMap {
|
|
||||||
'affine:embed-loom': EmbedLoomModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -15,11 +15,3 @@ export type EmbedSyncedDocBlockProps = {
|
|||||||
export class EmbedSyncedDocModel extends defineEmbedModel<EmbedSyncedDocBlockProps>(
|
export class EmbedSyncedDocModel extends defineEmbedModel<EmbedSyncedDocBlockProps>(
|
||||||
BlockModel
|
BlockModel
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface EdgelessBlockModelMap {
|
|
||||||
'affine:embed-synced-doc': EmbedSyncedDocModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -24,11 +24,3 @@ export type EmbedYoutubeBlockProps = {
|
|||||||
export class EmbedYoutubeModel extends defineEmbedModel<EmbedYoutubeBlockProps>(
|
export class EmbedYoutubeModel extends defineEmbedModel<EmbedYoutubeBlockProps>(
|
||||||
BlockModel
|
BlockModel
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface EdgelessBlockModelMap {
|
|
||||||
'affine:embed-youtube': EmbedYoutubeModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -144,11 +144,3 @@ export class FrameBlockModel
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface EdgelessBlockModelMap {
|
|
||||||
'affine:frame': FrameBlockModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -42,11 +42,3 @@ export const ImageBlockSchema = defineBlockSchema({
|
|||||||
export class ImageBlockModel
|
export class ImageBlockModel
|
||||||
extends GfxCompatible<ImageBlockProps>(BlockModel)
|
extends GfxCompatible<ImageBlockProps>(BlockModel)
|
||||||
implements GfxElementGeometry {}
|
implements GfxElementGeometry {}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface EdgelessBlockModelMap {
|
|
||||||
'affine:image': ImageBlockModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -37,11 +37,3 @@ export const LatexBlockSchema = defineBlockSchema({
|
|||||||
export class LatexBlockModel
|
export class LatexBlockModel
|
||||||
extends GfxCompatible<LatexProps>(BlockModel)
|
extends GfxCompatible<LatexProps>(BlockModel)
|
||||||
implements GfxElementGeometry {}
|
implements GfxElementGeometry {}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface EdgelessBlockModelMap {
|
|
||||||
'affine:latex': LatexBlockModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -155,11 +155,3 @@ export class NoteBlockModel
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface EdgelessBlockModelMap {
|
|
||||||
'affine:note': NoteBlockModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -224,11 +224,3 @@ export class BrushElementModel extends GfxPrimitiveElementModel<BrushProps> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Instance = GfxPrimitiveElementModel<BrushProps> & BrushProps;
|
type Instance = GfxPrimitiveElementModel<BrushProps> & BrushProps;
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface SurfaceElementModelMap {
|
|
||||||
brush: BrushElementModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -508,14 +508,3 @@ export class ConnectorElementModel extends GfxPrimitiveElementModel<ConnectorEle
|
|||||||
@local()
|
@local()
|
||||||
accessor xywh: SerializedXYWH = '[0,0,0,0]';
|
accessor xywh: SerializedXYWH = '[0,0,0,0]';
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface SurfaceElementModelMap {
|
|
||||||
connector: ConnectorElementModel;
|
|
||||||
}
|
|
||||||
interface EdgelessTextModelMap {
|
|
||||||
connector: ConnectorElementModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -56,11 +56,3 @@ export class LocalConnectorElementModel extends GfxLocalElementModel {
|
|||||||
return 'connector';
|
return 'connector';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface SurfaceLocalModelMap {
|
|
||||||
connector: LocalConnectorElementModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -119,15 +119,3 @@ export class GroupElementModel extends GfxGroupLikeElementModel<GroupElementProp
|
|||||||
@field()
|
@field()
|
||||||
accessor title: Y.Text = new Y.Text();
|
accessor title: Y.Text = new Y.Text();
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface SurfaceGroupLikeModelMap {
|
|
||||||
group: GroupElementModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface SurfaceElementModelMap {
|
|
||||||
group: GroupElementModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,32 @@
|
|||||||
|
import type { EdgelessTextBlockModel } from '../blocks/edgeless-text/edgeless-text-model.js';
|
||||||
|
import type { BrushElementModel } from './brush/index.js';
|
||||||
|
import type { ConnectorElementModel } from './connector/index.js';
|
||||||
|
import type { GroupElementModel } from './group/index.js';
|
||||||
|
import type { MindmapElementModel } from './mindmap/index.js';
|
||||||
|
import type { ShapeElementModel } from './shape/index.js';
|
||||||
|
import type { TextElementModel } from './text/index.js';
|
||||||
|
|
||||||
export * from './brush/index.js';
|
export * from './brush/index.js';
|
||||||
export * from './connector/index.js';
|
export * from './connector/index.js';
|
||||||
export * from './group/index.js';
|
export * from './group/index.js';
|
||||||
export * from './mindmap/index.js';
|
export * from './mindmap/index.js';
|
||||||
export * from './shape/index.js';
|
export * from './shape/index.js';
|
||||||
export * from './text/index.js';
|
export * from './text/index.js';
|
||||||
|
|
||||||
|
export type SurfaceElementModelMap = {
|
||||||
|
brush: BrushElementModel;
|
||||||
|
connector: ConnectorElementModel;
|
||||||
|
group: GroupElementModel;
|
||||||
|
mindmap: MindmapElementModel;
|
||||||
|
shape: ShapeElementModel;
|
||||||
|
text: TextElementModel;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SurfaceTextModelMap = {
|
||||||
|
text: TextElementModel;
|
||||||
|
connector: ConnectorElementModel;
|
||||||
|
shape: ShapeElementModel;
|
||||||
|
'edgeless-text': EdgelessTextBlockModel;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SurfaceTextModel = SurfaceTextModelMap[keyof SurfaceTextModelMap];
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type {
|
import type {
|
||||||
BaseElementProps,
|
BaseElementProps,
|
||||||
GfxModel,
|
GfxModel,
|
||||||
|
GfxPrimitiveElementModel,
|
||||||
PointTestOptions,
|
PointTestOptions,
|
||||||
SerializedElement,
|
SerializedElement,
|
||||||
} from '@blocksuite/block-std/gfx';
|
} from '@blocksuite/block-std/gfx';
|
||||||
@@ -44,7 +45,7 @@ export type MindmapNode = {
|
|||||||
id: string;
|
id: string;
|
||||||
detail: NodeDetail;
|
detail: NodeDetail;
|
||||||
|
|
||||||
element: BlockSuite.SurfaceElementModel;
|
element: GfxPrimitiveElementModel;
|
||||||
children: MindmapNode[];
|
children: MindmapNode[];
|
||||||
|
|
||||||
parent: MindmapNode | null;
|
parent: MindmapNode | null;
|
||||||
@@ -836,7 +837,7 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const stashed = new Set<BlockSuite.SurfaceElementModel>();
|
const stashed = new Set<GfxPrimitiveElementModel>();
|
||||||
const traverse = (node: MindmapNode) => {
|
const traverse = (node: MindmapNode) => {
|
||||||
node.element.stash('xywh');
|
node.element.stash('xywh');
|
||||||
stashed.add(node.element);
|
stashed.add(node.element);
|
||||||
@@ -975,11 +976,3 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
|
|||||||
@field()
|
@field()
|
||||||
accessor style: MindmapStyle = MindmapStyle.ONE;
|
accessor style: MindmapStyle = MindmapStyle.ONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface SurfaceGroupLikeModelMap {
|
|
||||||
mindmap: MindmapElementModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -261,15 +261,3 @@ export class LocalShapeElementModel extends GfxLocalElementModel {
|
|||||||
@prop()
|
@prop()
|
||||||
accessor textVerticalAlign: TextVerticalAlign = TextVerticalAlign.Center;
|
accessor textVerticalAlign: TextVerticalAlign = TextVerticalAlign.Center;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface SurfaceElementModelMap {
|
|
||||||
shape: ShapeElementModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface EdgelessTextModelMap {
|
|
||||||
shape: ShapeElementModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -90,15 +90,3 @@ export class TextElementModel extends GfxPrimitiveElementModel<TextElementProps>
|
|||||||
@field()
|
@field()
|
||||||
accessor xywh: SerializedXYWH = '[0,0,16,16]';
|
accessor xywh: SerializedXYWH = '[0,0,16,16]';
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface SurfaceElementModelMap {
|
|
||||||
text: TextElementModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface EdgelessTextModelMap {
|
|
||||||
text: TextElementModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
import type {
|
|
||||||
GfxBlockElementModel,
|
|
||||||
GfxGroupLikeElementModel,
|
|
||||||
GfxLocalElementModel,
|
|
||||||
GfxPrimitiveElementModel,
|
|
||||||
} from '@blocksuite/block-std/gfx';
|
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface EdgelessBlockModelMap {}
|
|
||||||
type EdgelessBlockModelKeyType = keyof EdgelessBlockModelMap;
|
|
||||||
type EdgelessBlockModelType =
|
|
||||||
| EdgelessBlockModelMap[EdgelessBlockModelKeyType]
|
|
||||||
| GfxBlockElementModel;
|
|
||||||
|
|
||||||
interface EdgelessTextModelMap {}
|
|
||||||
type EdgelessTextModelKeyType = keyof EdgelessTextModelMap;
|
|
||||||
type EdgelessTextModelType = EdgelessTextModelMap[EdgelessTextModelKeyType];
|
|
||||||
|
|
||||||
interface SurfaceElementModelMap {}
|
|
||||||
type SurfaceElementModelKeys = keyof SurfaceElementModelMap;
|
|
||||||
type SurfaceElementModel =
|
|
||||||
| SurfaceElementModelMap[SurfaceElementModelKeys]
|
|
||||||
| GfxPrimitiveElementModel;
|
|
||||||
|
|
||||||
interface SurfaceGroupLikeModelMap {}
|
|
||||||
type SurfaceGroupLikeModelKeys = keyof SurfaceGroupLikeModelMap;
|
|
||||||
type SurfaceGroupLikeModel =
|
|
||||||
| SurfaceGroupLikeModelMap[SurfaceGroupLikeModelKeys]
|
|
||||||
| GfxGroupLikeElementModel;
|
|
||||||
|
|
||||||
interface SurfaceLocalModelMap {}
|
|
||||||
type SurfaceLocalModelKeys = keyof SurfaceLocalModelMap;
|
|
||||||
type SurfaceLocalModel =
|
|
||||||
| SurfaceLocalModelMap[SurfaceLocalModelKeys]
|
|
||||||
| GfxLocalElementModel;
|
|
||||||
|
|
||||||
// not include local model
|
|
||||||
type SurfaceModel = SurfaceElementModel | SurfaceGroupLikeModel;
|
|
||||||
type SurfaceModelKeyType =
|
|
||||||
| SurfaceElementModelKeys
|
|
||||||
| SurfaceGroupLikeModelKeys;
|
|
||||||
|
|
||||||
type EdgelessModelKeys = EdgelessBlockModelKeyType | SurfaceModelKeyType;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
export * from './enum.js';
|
export * from './enum.js';
|
||||||
export * from './global.js';
|
|
||||||
export * from './helper.js';
|
export * from './helper.js';
|
||||||
export * from './types.js';
|
export * from './types.js';
|
||||||
|
|||||||
@@ -22,7 +22,10 @@ import {
|
|||||||
type EditorHost,
|
type EditorHost,
|
||||||
StdIdentifier,
|
StdIdentifier,
|
||||||
} from '@blocksuite/block-std';
|
} from '@blocksuite/block-std';
|
||||||
import type { GfxBlockElementModel } from '@blocksuite/block-std/gfx';
|
import type {
|
||||||
|
GfxBlockElementModel,
|
||||||
|
GfxPrimitiveElementModel,
|
||||||
|
} from '@blocksuite/block-std/gfx';
|
||||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||||
import type { IBound } from '@blocksuite/global/utils';
|
import type { IBound } from '@blocksuite/global/utils';
|
||||||
import { Bound } from '@blocksuite/global/utils';
|
import { Bound } from '@blocksuite/global/utils';
|
||||||
@@ -410,7 +413,7 @@ export class ExportManager {
|
|||||||
bound: IBound,
|
bound: IBound,
|
||||||
edgeless?: EdgelessRootBlockComponent,
|
edgeless?: EdgelessRootBlockComponent,
|
||||||
nodes?: GfxBlockElementModel[],
|
nodes?: GfxBlockElementModel[],
|
||||||
surfaces?: BlockSuite.SurfaceElementModel[],
|
surfaces?: GfxPrimitiveElementModel[],
|
||||||
edgelessBackground?: {
|
edgelessBackground?: {
|
||||||
zoom: number;
|
zoom: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
SurfaceGroupLikeModel,
|
SurfaceGroupLikeModel,
|
||||||
TextUtils,
|
TextUtils,
|
||||||
} from '@blocksuite/affine-block-surface';
|
} from '@blocksuite/affine-block-surface';
|
||||||
import type { Connection } from '@blocksuite/affine-model';
|
import type { Connection, ShapeElementModel } from '@blocksuite/affine-model';
|
||||||
import {
|
import {
|
||||||
BookmarkStyles,
|
BookmarkStyles,
|
||||||
DEFAULT_NOTE_HEIGHT,
|
DEFAULT_NOTE_HEIGHT,
|
||||||
@@ -40,8 +40,10 @@ import type {
|
|||||||
} from '@blocksuite/block-std';
|
} from '@blocksuite/block-std';
|
||||||
import {
|
import {
|
||||||
compareLayer,
|
compareLayer,
|
||||||
|
type GfxBlockElementModel,
|
||||||
type GfxCompatibleProps,
|
type GfxCompatibleProps,
|
||||||
type GfxModel,
|
type GfxModel,
|
||||||
|
type GfxPrimitiveElementModel,
|
||||||
type SerializedElement,
|
type SerializedElement,
|
||||||
SortOrder,
|
SortOrder,
|
||||||
} from '@blocksuite/block-std/gfx';
|
} from '@blocksuite/block-std/gfx';
|
||||||
@@ -313,7 +315,7 @@ export class EdgelessClipboardController extends PageClipboard {
|
|||||||
.get(EmbedOptionProvider)
|
.get(EmbedOptionProvider)
|
||||||
.getEmbedBlockOptions(url);
|
.getEmbedBlockOptions(url);
|
||||||
if (embedOptions) {
|
if (embedOptions) {
|
||||||
flavour = embedOptions.flavour as BlockSuite.EdgelessModelKeys;
|
flavour = embedOptions.flavour;
|
||||||
style = embedOptions.styles[0];
|
style = embedOptions.styles[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -605,7 +607,7 @@ export class EdgelessClipboardController extends PageClipboard {
|
|||||||
segment: 'toolbar',
|
segment: 'toolbar',
|
||||||
type: clipboardData.type as string,
|
type: clipboardData.type as string,
|
||||||
});
|
});
|
||||||
const element = this.crud.getElementById(id) as BlockSuite.SurfaceModel;
|
const element = this.crud.getElementById(id) as GfxPrimitiveElementModel;
|
||||||
assertExists(element);
|
assertExists(element);
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
@@ -882,8 +884,8 @@ export class EdgelessClipboardController extends PageClipboard {
|
|||||||
private async _edgelessToCanvas(
|
private async _edgelessToCanvas(
|
||||||
edgeless: EdgelessRootBlockComponent,
|
edgeless: EdgelessRootBlockComponent,
|
||||||
bound: IBound,
|
bound: IBound,
|
||||||
nodes?: BlockSuite.EdgelessBlockModelType[],
|
nodes?: GfxBlockElementModel[],
|
||||||
canvasElements: BlockSuite.SurfaceModel[] = [],
|
canvasElements: GfxPrimitiveElementModel[] = [],
|
||||||
{
|
{
|
||||||
background,
|
background,
|
||||||
padding = IMAGE_PADDING,
|
padding = IMAGE_PADDING,
|
||||||
@@ -961,7 +963,7 @@ export class EdgelessClipboardController extends PageClipboard {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const _drawTopLevelBlock = async (
|
const _drawTopLevelBlock = async (
|
||||||
block: BlockSuite.EdgelessBlockModelType,
|
block: GfxBlockElementModel,
|
||||||
isInFrame = false
|
isInFrame = false
|
||||||
) => {
|
) => {
|
||||||
const blockComponent = this.std.view.getBlock(block.id);
|
const blockComponent = this.std.view.getBlock(block.id);
|
||||||
@@ -992,19 +994,19 @@ export class EdgelessClipboardController extends PageClipboard {
|
|||||||
nodes ??
|
nodes ??
|
||||||
(edgeless.service.gfx.getElementsByBound(bound, {
|
(edgeless.service.gfx.getElementsByBound(bound, {
|
||||||
type: 'block',
|
type: 'block',
|
||||||
}) as BlockSuite.EdgelessBlockModelType[]);
|
}) as GfxBlockElementModel[]);
|
||||||
for (const nodeElement of nodeElements) {
|
for (const nodeElement of nodeElements) {
|
||||||
await _drawTopLevelBlock(nodeElement);
|
await _drawTopLevelBlock(nodeElement);
|
||||||
|
|
||||||
if (matchModels(nodeElement, [FrameBlockModel])) {
|
if (matchModels(nodeElement, [FrameBlockModel])) {
|
||||||
const blocksInsideFrame: BlockSuite.EdgelessBlockModelType[] = [];
|
const blocksInsideFrame: GfxBlockElementModel[] = [];
|
||||||
this.edgeless.service.frame
|
this.edgeless.service.frame
|
||||||
.getElementsInFrameBound(nodeElement, false)
|
.getElementsInFrameBound(nodeElement, false)
|
||||||
.forEach(ele => {
|
.forEach(ele => {
|
||||||
if (isTopLevelBlock(ele)) {
|
if (isTopLevelBlock(ele)) {
|
||||||
blocksInsideFrame.push(ele as BlockSuite.EdgelessBlockModelType);
|
blocksInsideFrame.push(ele as GfxBlockElementModel);
|
||||||
} else {
|
} else {
|
||||||
canvasElements.push(ele as BlockSuite.SurfaceModel);
|
canvasElements.push(ele as GfxPrimitiveElementModel);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1245,8 +1247,8 @@ export class EdgelessClipboardController extends PageClipboard {
|
|||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
const blockModels: BlockSuite.EdgelessBlockModelType[] = [];
|
const blockModels: GfxBlockElementModel[] = [];
|
||||||
const canvasElements: BlockSuite.SurfaceModel[] = [];
|
const canvasElements: GfxPrimitiveElementModel[] = [];
|
||||||
const allElements: GfxModel[] = [];
|
const allElements: GfxModel[] = [];
|
||||||
|
|
||||||
for (const data of elementsRawData) {
|
for (const data of elementsRawData) {
|
||||||
@@ -1283,7 +1285,7 @@ export class EdgelessClipboardController extends PageClipboard {
|
|||||||
const block = this.doc.getBlock(newId);
|
const block = this.doc.getBlock(newId);
|
||||||
if (!block) continue;
|
if (!block) continue;
|
||||||
|
|
||||||
assertType<BlockSuite.EdgelessBlockModelType>(block.model);
|
assertType<GfxBlockElementModel>(block.model);
|
||||||
blockModels.push(block.model);
|
blockModels.push(block.model);
|
||||||
allElements.push(block.model);
|
allElements.push(block.model);
|
||||||
context.oldToNewIdMap.set(oldId, newId);
|
context.oldToNewIdMap.set(oldId, newId);
|
||||||
@@ -1343,8 +1345,8 @@ export class EdgelessClipboardController extends PageClipboard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async toCanvas(
|
async toCanvas(
|
||||||
blocks: BlockSuite.EdgelessBlockModelType[],
|
blocks: GfxBlockElementModel[],
|
||||||
shapes: BlockSuite.SurfaceModel[],
|
shapes: ShapeElementModel[],
|
||||||
options?: CanvasExportOptions
|
options?: CanvasExportOptions
|
||||||
) {
|
) {
|
||||||
blocks.sort(compareLayer);
|
blocks.sort(compareLayer);
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import {
|
|||||||
GfxControllerIdentifier,
|
GfxControllerIdentifier,
|
||||||
GfxExtensionIdentifier,
|
GfxExtensionIdentifier,
|
||||||
type GfxModel,
|
type GfxModel,
|
||||||
|
type GfxPrimitiveElementModel,
|
||||||
} from '@blocksuite/block-std/gfx';
|
} from '@blocksuite/block-std/gfx';
|
||||||
import type {
|
import type {
|
||||||
Disposable,
|
Disposable,
|
||||||
@@ -891,7 +892,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent<
|
|||||||
areAllConnectors = false;
|
areAllConnectors = false;
|
||||||
areAllShapes = false;
|
areAllShapes = false;
|
||||||
} else {
|
} else {
|
||||||
assertType<BlockSuite.SurfaceElementModel>(element);
|
assertType<GfxPrimitiveElementModel>(element);
|
||||||
if (element.type === CanvasElementType.CONNECTOR) {
|
if (element.type === CanvasElementType.CONNECTOR) {
|
||||||
const connector = element as ConnectorElementModel;
|
const connector = element as ConnectorElementModel;
|
||||||
areAllIndependentConnectors &&= !(
|
areAllIndependentConnectors &&= !(
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import { matchModels } from '@blocksuite/affine-shared/utils';
|
|||||||
import { SurfaceSelection, TextSelection } from '@blocksuite/block-std';
|
import { SurfaceSelection, TextSelection } from '@blocksuite/block-std';
|
||||||
import {
|
import {
|
||||||
GfxBlockElementModel,
|
GfxBlockElementModel,
|
||||||
|
type GfxPrimitiveElementModel,
|
||||||
type GfxToolsMap,
|
type GfxToolsMap,
|
||||||
type GfxToolsOption,
|
type GfxToolsOption,
|
||||||
isGfxGroupCompatibleModel,
|
isGfxGroupCompatibleModel,
|
||||||
@@ -573,7 +574,7 @@ export class EdgelessPageKeyboardManager extends PageKeyboardManager {
|
|||||||
const node = mindmapNodes[0];
|
const node = mindmapNodes[0];
|
||||||
const mindmap = node.group as MindmapElementModel;
|
const mindmap = node.group as MindmapElementModel;
|
||||||
const nodeDirection = mindmap.getLayoutDir(node.id);
|
const nodeDirection = mindmap.getLayoutDir(node.id);
|
||||||
let targetNode: BlockSuite.SurfaceElementModel | null = null;
|
let targetNode: GfxPrimitiveElementModel | null = null;
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'ArrowUp':
|
case 'ArrowUp':
|
||||||
|
|||||||
@@ -491,11 +491,7 @@ export function getBlocksInFrameBound(
|
|||||||
if (!surface) return [];
|
if (!surface) return [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
getNotesInFrameBound(
|
getNotesInFrameBound(doc, model, fullyContained) as GfxBlockElementModel[]
|
||||||
doc,
|
|
||||||
model,
|
|
||||||
fullyContained
|
|
||||||
) as BlockSuite.EdgelessBlockModelType[]
|
|
||||||
).concat(
|
).concat(
|
||||||
surface.children.filter(ele => {
|
surface.children.filter(ele => {
|
||||||
if (ele.id === model.id) return false;
|
if (ele.id === model.id) return false;
|
||||||
@@ -507,6 +503,6 @@ export function getBlocksInFrameBound(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}) as BlockSuite.EdgelessBlockModelType[]
|
}) as GfxBlockElementModel[]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
import type { PointerEventState } from '@blocksuite/block-std';
|
import type { PointerEventState } from '@blocksuite/block-std';
|
||||||
import {
|
import {
|
||||||
type GfxModel,
|
type GfxModel,
|
||||||
|
type GfxPrimitiveElementModel,
|
||||||
isGfxGroupCompatibleModel,
|
isGfxGroupCompatibleModel,
|
||||||
} from '@blocksuite/block-std/gfx';
|
} from '@blocksuite/block-std/gfx';
|
||||||
import type { Bound, IVec } from '@blocksuite/global/utils';
|
import type { Bound, IVec } from '@blocksuite/global/utils';
|
||||||
@@ -352,7 +353,7 @@ export class MindMapExt extends DefaultToolExt {
|
|||||||
) {
|
) {
|
||||||
const OPACITY = 0.3;
|
const OPACITY = 0.3;
|
||||||
const updatedNodes = new Set<
|
const updatedNodes = new Set<
|
||||||
BlockSuite.SurfaceElementModel | LocalConnectorElementModel
|
GfxPrimitiveElementModel | LocalConnectorElementModel
|
||||||
>();
|
>();
|
||||||
const traverse = (node: MindmapNode, parent: MindmapNode | null) => {
|
const traverse = (node: MindmapNode, parent: MindmapNode | null) => {
|
||||||
node.element.opacity = OPACITY;
|
node.element.opacity = OPACITY;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export class EditPropsMiddlewareBuilder extends SurfaceMiddlewareBuilder {
|
|||||||
middleware: SurfaceMiddleware = ctx => {
|
middleware: SurfaceMiddleware = ctx => {
|
||||||
if (ctx.type === 'beforeAdd') {
|
if (ctx.type === 'beforeAdd') {
|
||||||
const { type, props } = ctx.payload;
|
const { type, props } = ctx.payload;
|
||||||
const key = getLastPropsKey(type as BlockSuite.EdgelessModelKeys, props);
|
const key = getLastPropsKey(type, props);
|
||||||
const nProps = key
|
const nProps = key
|
||||||
? this.std.get(EditPropsStore).applyLastProps(key, ctx.payload.props)
|
? this.std.get(EditPropsStore).applyLastProps(key, ctx.payload.props)
|
||||||
: null;
|
: null;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import type {
|
|||||||
FrameBlockProps,
|
FrameBlockProps,
|
||||||
ImageBlockModel,
|
ImageBlockModel,
|
||||||
NoteBlockModel,
|
NoteBlockModel,
|
||||||
|
ShapeElementModel,
|
||||||
} from '@blocksuite/affine-model';
|
} from '@blocksuite/affine-model';
|
||||||
import { getElementsWithoutGroup } from '@blocksuite/affine-shared/utils';
|
import { getElementsWithoutGroup } from '@blocksuite/affine-shared/utils';
|
||||||
import {
|
import {
|
||||||
@@ -72,7 +73,7 @@ export const splitElements = (elements: GfxModel[]) => {
|
|||||||
return 'shapes';
|
return 'shapes';
|
||||||
}) as {
|
}) as {
|
||||||
notes: NoteBlockModel[];
|
notes: NoteBlockModel[];
|
||||||
shapes: BlockSuite.SurfaceModel[];
|
shapes: ShapeElementModel[];
|
||||||
frames: FrameBlockModel[];
|
frames: FrameBlockModel[];
|
||||||
images: ImageBlockModel[];
|
images: ImageBlockModel[];
|
||||||
edgelessTexts: EdgelessTextBlockModel[];
|
edgelessTexts: EdgelessTextBlockModel[];
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
getTopElements,
|
getTopElements,
|
||||||
GfxBlockElementModel,
|
GfxBlockElementModel,
|
||||||
type GfxModel,
|
type GfxModel,
|
||||||
|
type GfxPrimitiveElementModel,
|
||||||
isGfxGroupCompatibleModel,
|
isGfxGroupCompatibleModel,
|
||||||
type SerializedElement,
|
type SerializedElement,
|
||||||
} from '@blocksuite/block-std/gfx';
|
} from '@blocksuite/block-std/gfx';
|
||||||
@@ -225,7 +226,7 @@ export function mapMindmapIds(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getElementProps(
|
export function getElementProps(
|
||||||
element: BlockSuite.SurfaceModel,
|
element: GfxPrimitiveElementModel,
|
||||||
ids: Map<string, string>
|
ids: Map<string, string>
|
||||||
) {
|
) {
|
||||||
if (element instanceof ConnectorElementModel) {
|
if (element instanceof ConnectorElementModel) {
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ import {
|
|||||||
FontWeight,
|
FontWeight,
|
||||||
resolveColor,
|
resolveColor,
|
||||||
ShapeElementModel,
|
ShapeElementModel,
|
||||||
|
type SurfaceTextModel,
|
||||||
|
type SurfaceTextModelMap,
|
||||||
TextAlign,
|
TextAlign,
|
||||||
TextElementModel,
|
TextElementModel,
|
||||||
type TextStyleProps,
|
type TextStyleProps,
|
||||||
@@ -76,14 +78,14 @@ const TEXT_ALIGN_CHOOSE: [TextAlign, () => TemplateResult<1>][] = [
|
|||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
function countByField<K extends keyof Omit<TextStyleProps, 'color'>>(
|
function countByField<K extends keyof Omit<TextStyleProps, 'color'>>(
|
||||||
elements: BlockSuite.EdgelessTextModelType[],
|
elements: SurfaceTextModel[],
|
||||||
field: K
|
field: K
|
||||||
) {
|
) {
|
||||||
return countBy(elements, element => extractField(element, field));
|
return countBy(elements, element => extractField(element, field));
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractField<K extends keyof Omit<TextStyleProps, 'color'>>(
|
function extractField<K extends keyof Omit<TextStyleProps, 'color'>>(
|
||||||
element: BlockSuite.EdgelessTextModelType,
|
element: SurfaceTextModel,
|
||||||
field: K
|
field: K
|
||||||
) {
|
) {
|
||||||
//TODO: It's not a very good handling method.
|
//TODO: It's not a very good handling method.
|
||||||
@@ -101,23 +103,23 @@ function extractField<K extends keyof Omit<TextStyleProps, 'color'>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getMostCommonValue<K extends keyof Omit<TextStyleProps, 'color'>>(
|
function getMostCommonValue<K extends keyof Omit<TextStyleProps, 'color'>>(
|
||||||
elements: BlockSuite.EdgelessTextModelType[],
|
elements: SurfaceTextModel[],
|
||||||
field: K
|
field: K
|
||||||
) {
|
) {
|
||||||
const values = countByField(elements, field);
|
const values = countByField(elements, field);
|
||||||
return maxBy(Object.entries(values), ([_k, count]) => count);
|
return maxBy(Object.entries(values), ([_k, count]) => count);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMostCommonAlign(elements: BlockSuite.EdgelessTextModelType[]) {
|
function getMostCommonAlign(elements: SurfaceTextModel[]) {
|
||||||
const max = getMostCommonValue(elements, 'textAlign');
|
const max = getMostCommonValue(elements, 'textAlign');
|
||||||
return max ? (max[0] as TextAlign) : TextAlign.Left;
|
return max ? (max[0] as TextAlign) : TextAlign.Left;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMostCommonColor(
|
function getMostCommonColor(
|
||||||
elements: BlockSuite.EdgelessTextModelType[],
|
elements: SurfaceTextModel[],
|
||||||
colorScheme: ColorScheme
|
colorScheme: ColorScheme
|
||||||
): string {
|
): string {
|
||||||
const colors = countBy(elements, (ele: BlockSuite.EdgelessTextModelType) => {
|
const colors = countBy(elements, (ele: SurfaceTextModel) => {
|
||||||
const color =
|
const color =
|
||||||
ele instanceof ConnectorElementModel ? ele.labelStyle.color : ele.color;
|
ele instanceof ConnectorElementModel ? ele.labelStyle.color : ele.color;
|
||||||
return resolveColor(color, colorScheme);
|
return resolveColor(color, colorScheme);
|
||||||
@@ -128,28 +130,28 @@ function getMostCommonColor(
|
|||||||
: resolveColor(DefaultTheme.textColor, colorScheme);
|
: resolveColor(DefaultTheme.textColor, colorScheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMostCommonFontFamily(elements: BlockSuite.EdgelessTextModelType[]) {
|
function getMostCommonFontFamily(elements: SurfaceTextModel[]) {
|
||||||
const max = getMostCommonValue(elements, 'fontFamily');
|
const max = getMostCommonValue(elements, 'fontFamily');
|
||||||
return max ? (max[0] as FontFamily) : FontFamily.Inter;
|
return max ? (max[0] as FontFamily) : FontFamily.Inter;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMostCommonFontSize(elements: BlockSuite.EdgelessTextModelType[]) {
|
function getMostCommonFontSize(elements: SurfaceTextModel[]) {
|
||||||
const max = getMostCommonValue(elements, 'fontSize');
|
const max = getMostCommonValue(elements, 'fontSize');
|
||||||
return max ? Number(max[0]) : FONT_SIZE_LIST[0].value;
|
return max ? Number(max[0]) : FONT_SIZE_LIST[0].value;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMostCommonFontStyle(elements: BlockSuite.EdgelessTextModelType[]) {
|
function getMostCommonFontStyle(elements: SurfaceTextModel[]) {
|
||||||
const max = getMostCommonValue(elements, 'fontStyle');
|
const max = getMostCommonValue(elements, 'fontStyle');
|
||||||
return max ? (max[0] as FontStyle) : FontStyle.Normal;
|
return max ? (max[0] as FontStyle) : FontStyle.Normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMostCommonFontWeight(elements: BlockSuite.EdgelessTextModelType[]) {
|
function getMostCommonFontWeight(elements: SurfaceTextModel[]) {
|
||||||
const max = getMostCommonValue(elements, 'fontWeight');
|
const max = getMostCommonValue(elements, 'fontWeight');
|
||||||
return max ? (max[0] as FontWeight) : FontWeight.Regular;
|
return max ? (max[0] as FontWeight) : FontWeight.Regular;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildProps(
|
function buildProps(
|
||||||
element: BlockSuite.EdgelessTextModelType,
|
element: SurfaceTextModel,
|
||||||
props: { [K in keyof TextStyleProps]?: TextStyleProps[K] }
|
props: { [K in keyof TextStyleProps]?: TextStyleProps[K] }
|
||||||
) {
|
) {
|
||||||
if (element instanceof ConnectorElementModel) {
|
if (element instanceof ConnectorElementModel) {
|
||||||
@@ -236,9 +238,7 @@ export class EdgelessChangeTextMenu extends WithDisposable(LitElement) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly _updateElementBound = (
|
private readonly _updateElementBound = (element: SurfaceTextModel) => {
|
||||||
element: BlockSuite.EdgelessTextModelType
|
|
||||||
) => {
|
|
||||||
const elementType = this.elementType;
|
const elementType = this.elementType;
|
||||||
if (elementType === 'text' && element instanceof TextElementModel) {
|
if (elementType === 'text' && element instanceof TextElementModel) {
|
||||||
// the change of font family will change the bound of the text
|
// the change of font family will change the bound of the text
|
||||||
@@ -506,10 +506,10 @@ export class EdgelessChangeTextMenu extends WithDisposable(LitElement) {
|
|||||||
accessor edgeless!: EdgelessRootBlockComponent;
|
accessor edgeless!: EdgelessRootBlockComponent;
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
accessor elements!: BlockSuite.EdgelessTextModelType[];
|
accessor elements!: SurfaceTextModel[];
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
accessor elementType!: BlockSuite.EdgelessTextModelKeyType;
|
accessor elementType!: keyof SurfaceTextModelMap;
|
||||||
|
|
||||||
@query('edgeless-color-picker-button.text-color')
|
@query('edgeless-color-picker-button.text-color')
|
||||||
accessor textColorButton!: EdgelessColorPickerButton;
|
accessor textColorButton!: EdgelessColorPickerButton;
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ export class EdgelessElementToolbarWidget extends WidgetComponent<
|
|||||||
return 'edgelessText';
|
return 'edgelessText';
|
||||||
}
|
}
|
||||||
|
|
||||||
return (model as BlockSuite.SurfaceElementModel).type;
|
return model.type;
|
||||||
});
|
});
|
||||||
return result as CategorizedElements;
|
return result as CategorizedElements;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import type {
|
|||||||
EdgelessRootBlockComponent,
|
EdgelessRootBlockComponent,
|
||||||
GroupElementModel,
|
GroupElementModel,
|
||||||
NoteBlockModel,
|
NoteBlockModel,
|
||||||
|
SurfaceElementModel,
|
||||||
} from '@blocksuite/blocks';
|
} from '@blocksuite/blocks';
|
||||||
import type { BlockModel, Store } from '@blocksuite/store';
|
import type { BlockModel, Store } from '@blocksuite/store';
|
||||||
import { beforeEach, describe, expect, test } from 'vitest';
|
import { beforeEach, describe, expect, test } from 'vitest';
|
||||||
@@ -852,7 +853,7 @@ test('the actual rendering z-index should satisfy the logic order of their index
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('index generator', () => {
|
describe('index generator', () => {
|
||||||
let preinsertedShape: BlockSuite.SurfaceElementModel;
|
let preinsertedShape: SurfaceElementModel;
|
||||||
let preinsertedNote: NoteBlockModel;
|
let preinsertedNote: NoteBlockModel;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@@ -863,7 +864,7 @@ describe('index generator', () => {
|
|||||||
|
|
||||||
preinsertedShape = service.crud.getElementById(
|
preinsertedShape = service.crud.getElementById(
|
||||||
shapeId
|
shapeId
|
||||||
)! as BlockSuite.SurfaceElementModel;
|
)! as SurfaceElementModel;
|
||||||
preinsertedNote = service.crud.getElementById(noteId)! as NoteBlockModel;
|
preinsertedNote = service.crud.getElementById(noteId)! as NoteBlockModel;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -34,12 +34,3 @@ export const AIChatBlockSchema = defineBlockSchema({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export class AIChatBlockModel extends GfxCompatible<AIChatProps>(BlockModel) {}
|
export class AIChatBlockModel extends GfxCompatible<AIChatProps>(BlockModel) {}
|
||||||
|
|
||||||
declare global {
|
|
||||||
// oxlint-disable-next-line @typescript-eslint/no-namespace
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface EdgelessBlockModelMap {
|
|
||||||
'affine:embed-ai-chat': AIChatBlockModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { getCopilotHistoriesQuery, RequestOptions } from '@affine/graphql';
|
import type { getCopilotHistoriesQuery, RequestOptions } from '@affine/graphql';
|
||||||
import type { EditorHost } from '@blocksuite/affine/block-std';
|
import type { EditorHost } from '@blocksuite/affine/block-std';
|
||||||
|
import type { GfxModel } from '@blocksuite/affine/block-std/gfx';
|
||||||
import type { BlockModel } from '@blocksuite/affine/store';
|
import type { BlockModel } from '@blocksuite/affine/store';
|
||||||
|
|
||||||
import type { DocContext } from '../chat-panel/chat-context';
|
import type { DocContext } from '../chat-panel/chat-context';
|
||||||
@@ -72,7 +73,7 @@ declare global {
|
|||||||
|
|
||||||
// internal context
|
// internal context
|
||||||
host: EditorHost;
|
host: EditorHost;
|
||||||
models?: (BlockModel | BlockSuite.SurfaceElementModel)[];
|
models?: (BlockModel | GfxModel)[];
|
||||||
control: TrackerControl;
|
control: TrackerControl;
|
||||||
where: TrackerWhere;
|
where: TrackerWhere;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import { AIProvider } from '@affine/core/blocksuite/presets/ai';
|
import { AIProvider } from '@affine/core/blocksuite/presets/ai';
|
||||||
import { mixpanel, track } from '@affine/track';
|
import { mixpanel, track } from '@affine/track';
|
||||||
import type { EditorHost } from '@blocksuite/affine/block-std';
|
import type { EditorHost } from '@blocksuite/affine/block-std';
|
||||||
|
import type { GfxPrimitiveElementModel } from '@blocksuite/affine/block-std/gfx';
|
||||||
import type { BlockModel } from '@blocksuite/affine/store';
|
import type { BlockModel } from '@blocksuite/affine/store';
|
||||||
import { lowerCase, omit } from 'lodash-es';
|
import { lowerCase, omit } from 'lodash-es';
|
||||||
|
|
||||||
type ElementModel = BlockSuite.SurfaceElementModel;
|
type ElementModel = GfxPrimitiveElementModel;
|
||||||
|
|
||||||
type AIActionEventName =
|
type AIActionEventName =
|
||||||
| 'AI action invoked'
|
| 'AI action invoked'
|
||||||
|
|||||||
Reference in New Issue
Block a user