From ea53793162e957ee3cd5ac59bf490680a577e1a5 Mon Sep 17 00:00:00 2001 From: Hongtao Lye Date: Mon, 9 Dec 2024 22:58:54 +0800 Subject: [PATCH] feat: expand button --- .../src/renderer/elements/mindmap.ts | 10 +- .../model/src/elements/mindmap/mindmap.ts | 121 ++++++++---------- .../model/src/elements/mindmap/style.ts | 6 +- .../affine/model/src/elements/shape/shape.ts | 2 +- 4 files changed, 64 insertions(+), 75 deletions(-) diff --git a/packages/affine/block-surface/src/renderer/elements/mindmap.ts b/packages/affine/block-surface/src/renderer/elements/mindmap.ts index 2da67ebb27034..6058c46a64704 100644 --- a/packages/affine/block-surface/src/renderer/elements/mindmap.ts +++ b/packages/affine/block-surface/src/renderer/elements/mindmap.ts @@ -23,13 +23,17 @@ export function mindmap( model.traverse((to, from) => { if (from) { - const connector = model.getConnector(from, to); - if (!connector) return; + const result = model.getConnector(from, to); + if (!result) return; + const { connector, outdated } = result; const elementGetter = (id: string) => model.surface.getElementById(id) ?? (model.surface.doc.getBlockById(id) as GfxModel); - ConnectorPathGenerator.updatePath(connector, null, elementGetter); + + if (outdated) { + ConnectorPathGenerator.updatePath(connector, null, elementGetter); + } const dx = connector.x - bound.x; const dy = connector.y - bound.y; diff --git a/packages/affine/model/src/elements/mindmap/mindmap.ts b/packages/affine/model/src/elements/mindmap/mindmap.ts index 7c8c21bab0804..a727036c1af51 100644 --- a/packages/affine/model/src/elements/mindmap/mindmap.ts +++ b/packages/affine/model/src/elements/mindmap/mindmap.ts @@ -25,7 +25,7 @@ import { DocCollection, type Y } from '@blocksuite/store'; import { generateKeyBetween } from 'fractional-indexing'; import { z } from 'zod'; -import type { ConnectorStyle, MindmapStyleGetter } from './style.js'; +import type { MindmapStyleGetter } from './style.js'; import { LayoutType, MindmapStyle } from '../../consts/mindmap.js'; import { LocalConnectorElementModel } from '../connector/local-connector.js'; @@ -251,12 +251,12 @@ export class MindmapElementModel extends GfxGroupLikeElementModel { - // @ts-ignore - connector[key as unknown] = value; - }); - - return connector; - } - addNode( /** * The parent node id of the new node. If it's null, the node will be the root node @@ -553,7 +501,6 @@ export class MindmapElementModel extends GfxGroupLikeElementModel { if (Object.hasOwn(collapseButton, key)) { @@ -582,27 +528,32 @@ export class MindmapElementModel extends GfxGroupLikeElementModel { - collapseButton.opacity = 1; + const latestNode = this.getNode(node.id); + if (latestNode && latestNode.children.length > 0) { + collapseButton.opacity = 1; + } }; collapseButton.onPointerLeave = () => { collapseButton.opacity = 0; }; collapseButton.onClick = () => { - const nodeDetail = this.children.get(node.id); + const latestNode = this.getNode(node.id); - if (nodeDetail) { + if (latestNode && latestNode.children.length > 0) { this.surface.doc.transact(() => { this.children.set(node.id, { - ...nodeDetail, - collapsed: nodeDetail.collapsed ? false : true, + ...latestNode.detail, + collapsed: latestNode.detail.collapsed ? false : true, }); }); } @@ -617,12 +568,44 @@ export class MindmapElementModel extends GfxGroupLikeElementModel { + // @ts-ignore + connector[key as unknown] = value; + }); + } + + return { outdated, connector }; } getLayoutDir(node: string | MindmapNode): LayoutType { diff --git a/packages/affine/model/src/elements/mindmap/style.ts b/packages/affine/model/src/elements/mindmap/style.ts index 351820d682259..fd7e4dface5c6 100644 --- a/packages/affine/model/src/elements/mindmap/style.ts +++ b/packages/affine/model/src/elements/mindmap/style.ts @@ -137,7 +137,7 @@ export class StyleOne extends MindmapStyleGetter { fillColor: '--affine-white', strokeColor: color, - strokeWidth: 2, + strokeWidth: 3, }, expandButton: { width: 24, @@ -148,7 +148,9 @@ export class StyleOne extends MindmapStyleGetter { fillColor: color, strokeColor: color, - strokeWidth: 2, + strokeWidth: 0, + + padding: [4, 0], color: '--affine-white', diff --git a/packages/affine/model/src/elements/shape/shape.ts b/packages/affine/model/src/elements/shape/shape.ts index b20b6687a278b..49810dcf8f97c 100644 --- a/packages/affine/model/src/elements/shape/shape.ts +++ b/packages/affine/model/src/elements/shape/shape.ts @@ -199,7 +199,7 @@ export class LocalShapeElementModel extends GfxLocalElementModel { fontFamily: string = FontFamily.Inter; - fontSize!: number; + fontSize: number = 16; fontStyle: FontStyle = FontStyle.Normal;