From ff87cbb3e5e82df87aab4232cdee2dad681d7381 Mon Sep 17 00:00:00 2001 From: Hongtao Lye Date: Fri, 19 Apr 2024 14:45:56 +0800 Subject: [PATCH 1/7] fix: layout button text --- .../widgets/element-toolbar/change-mindmap-button.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/blocks/src/root-block/widgets/element-toolbar/change-mindmap-button.ts b/packages/blocks/src/root-block/widgets/element-toolbar/change-mindmap-button.ts index 6fbd539326ee..1e6697428731 100644 --- a/packages/blocks/src/root-block/widgets/element-toolbar/change-mindmap-button.ts +++ b/packages/blocks/src/root-block/widgets/element-toolbar/change-mindmap-button.ts @@ -126,7 +126,7 @@ export class EdgelessChangeMindmapButton extends WithDisposable(LitElement) { return html`
{ @@ -153,7 +153,7 @@ export class EdgelessChangeMindmapButton extends WithDisposable(LitElement) { { @@ -276,9 +276,9 @@ class EdgelessChangeMindmapLayoutPanel extends LitElement { `; static mindmapLayouts = [ - [LayoutType.LEFT, MindmapLeftLayoutIcon, 'Left layout'], - [LayoutType.RIGHT, MindmapRightLayoutIcon, 'Right layout'], - [LayoutType.BALANCE, MindmapBalanceLayoutIcon, 'Balance layout'], + [LayoutType.LEFT, MindmapLeftLayoutIcon, 'Left'], + [LayoutType.RIGHT, MindmapRightLayoutIcon, 'Right'], + [LayoutType.BALANCE, MindmapBalanceLayoutIcon, 'Radial'], ]; @property({ attribute: false }) From ffdc1db2a8f25bc665eae080433f05b50278234c Mon Sep 17 00:00:00 2001 From: Hongtao Lye Date: Fri, 19 Apr 2024 15:29:05 +0800 Subject: [PATCH 2/7] fix: allow to change focus on between mindmap node --- .../root-block/edgeless/edgeless-keyboard.ts | 45 +++++++++++++++++- .../surface-block/element-model/mindmap.ts | 46 +++++++++++++++++++ 2 files changed, 89 insertions(+), 2 deletions(-) diff --git a/packages/blocks/src/root-block/edgeless/edgeless-keyboard.ts b/packages/blocks/src/root-block/edgeless/edgeless-keyboard.ts index 85e7b7b6eb76..6aefc6513f27 100644 --- a/packages/blocks/src/root-block/edgeless/edgeless-keyboard.ts +++ b/packages/blocks/src/root-block/edgeless/edgeless-keyboard.ts @@ -2,8 +2,11 @@ import { IS_MAC } from '@blocksuite/global/env'; import { type EdgelessTool, LassoMode } from '../../_common/types.js'; import { matchFlavours } from '../../_common/utils/model.js'; -import type { MindmapElementModel } from '../../surface-block/element-model/mindmap.js'; -import type { ShapeElementModel } from '../../surface-block/index.js'; +import { MindmapElementModel } from '../../surface-block/element-model/mindmap.js'; +import type { + ElementModel, + ShapeElementModel, +} from '../../surface-block/index.js'; import { Bound, ConnectorElementModel, @@ -455,6 +458,44 @@ export class EdgelessPageKeyboardManager extends PageKeyboardManager { if (edgeless.service.selection.editing) return; const { elements } = edgeless.service.selection; const inc = shift ? 10 : 1; + const mindmapNodes = elements.filter( + el => el.group instanceof MindmapElementModel + ); + + if (mindmapNodes.length > 0) { + const node = mindmapNodes[0]; + const mindmap = node.group as MindmapElementModel; + let targetNode: ElementModel | null = null; + + switch (key) { + case 'ArrowUp': + case 'ArrowDown': + targetNode = mindmap.getSiblingNode( + node.id, + key === 'ArrowDown' ? 'next' : 'prev' + ); + break; + case 'ArrowLeft': + targetNode = mindmap.getParentNode(node.id); + break; + case 'ArrowRight': + { + const children = mindmap.getChildNodes(node.id); + + targetNode = children[0] ?? null; + } + break; + } + + if (targetNode) { + edgeless.service.selection.set({ + elements: [targetNode.id], + editing: false, + }); + } + + return; + } elements.forEach(element => { const bound = Bound.deserialize(element.xywh).clone(); diff --git a/packages/blocks/src/surface-block/element-model/mindmap.ts b/packages/blocks/src/surface-block/element-model/mindmap.ts index b46f13e1a1cd..8772efd950f6 100644 --- a/packages/blocks/src/surface-block/element-model/mindmap.ts +++ b/packages/blocks/src/surface-block/element-model/mindmap.ts @@ -261,6 +261,18 @@ export class MindmapElementModel extends GroupLikeModel { return node?.parent ? this.surface.getElementById(node.parent) : null; } + /** + * Path is an array of indexes that represent the path from the root node to the target node. + * The first element of the array is always 0, which represents the root node. + * @param element + * @returns + * + * @example + * ```ts + * const path = mindmap.getPath('nodeId'); + * // [0, 1, 2] + * ``` + */ getPath(element: string | MindmapNode) { let node = this._nodeMap.get( typeof element === 'string' ? element : element.id @@ -563,4 +575,38 @@ export class MindmapElementModel extends GroupLikeModel { }); }); } + + getSiblingNode(id: string, direction: 'prev' | 'next' = 'next') { + const node = this._nodeMap.get(id); + + if (!node) { + return null; + } + + const parent = this._nodeMap.get(node.detail.parent!); + + if (!parent) { + return null; + } + + const idx = parent.children.indexOf(node); + if (idx === -1) { + return null; + } + + return ( + parent?.children[direction === 'next' ? idx + 1 : idx - 1]?.element ?? + null + ); + } + + getChildNodes(id: string) { + const node = this._nodeMap.get(id); + + if (!node) { + return []; + } + + return node.children.map(child => child.element); + } } From e92b4d157c59588ad6493249fa787a2b17f587cf Mon Sep 17 00:00:00 2001 From: Hongtao Lye Date: Fri, 19 Apr 2024 17:07:26 +0800 Subject: [PATCH 3/7] fix: brush element points --- packages/blocks/src/surface-block/utils/math-utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/blocks/src/surface-block/utils/math-utils.ts b/packages/blocks/src/surface-block/utils/math-utils.ts index e3a1db73657f..daf1c7408361 100644 --- a/packages/blocks/src/surface-block/utils/math-utils.ts +++ b/packages/blocks/src/surface-block/utils/math-utils.ts @@ -148,7 +148,7 @@ export function getBoundsFromPoints(points: IVec[], rotation = 0): TLBounds { let maxX = -Infinity; let maxY = -Infinity; - if (points.length < 2) { + if (points.length < 1) { minX = 0; minY = 0; maxX = 1; From 6feea99554a1a768b004e6b52270c13d6b9cc71a Mon Sep 17 00:00:00 2001 From: Hongtao Lye Date: Mon, 22 Apr 2024 14:21:03 +0800 Subject: [PATCH 4/7] fix: memory limitation --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 55c88775a805..5f2cca93ae0d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -43,7 +43,7 @@ jobs: - name: Run type check run: pnpm build:packages && pnpm build:playground env: - NODE_OPTIONS: --max-old-space-size=8192 + NODE_OPTIONS: --max-old-space-size=6144 - name: Run ESLint # ESLint will save the cache files on cwd by default, From 6ae6a0401b18d120251590c490be78aac7f6fdf3 Mon Sep 17 00:00:00 2001 From: Hongtao Lye Date: Mon, 22 Apr 2024 14:39:28 +0800 Subject: [PATCH 5/7] Revert "fix: memory limitation" This reverts commit 6feea99554a1a768b004e6b52270c13d6b9cc71a. --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 5f2cca93ae0d..55c88775a805 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -43,7 +43,7 @@ jobs: - name: Run type check run: pnpm build:packages && pnpm build:playground env: - NODE_OPTIONS: --max-old-space-size=6144 + NODE_OPTIONS: --max-old-space-size=8192 - name: Run ESLint # ESLint will save the cache files on cwd by default, From efb382fae84e800f54e27c27a44ae58653e5f773 Mon Sep 17 00:00:00 2001 From: Hongtao Lye Date: Mon, 22 Apr 2024 14:42:54 +0800 Subject: [PATCH 6/7] fix: build memory limitation --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 48c356a1b432..a7a6ef569ef6 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "test:integration": "pnpm --filter @blocksuite/presets test", "test:node": "node --experimental-specifier-resolution=node --loader ts-node/esm ./scripts/node-import-test.ts", "format": "prettier --write --cache packages tests", - "build": "pnpm build:packages && pnpm build:playground", + "build": "NODE_OPTIONS=\"--max-old-space-size=6144\" pnpm build:packages && pnpm build:playground", "build:packages": "pnpm --filter=@blocksuite/presets build", "build:playground": "pnpm --filter @blocksuite/playground build", "build:docs": "pnpm --filter @blocksuite/docs build", From 836bdb73f02d8ae86048f95d1f8df2b1b6211bad Mon Sep 17 00:00:00 2001 From: Hongtao Lye Date: Mon, 22 Apr 2024 14:50:10 +0800 Subject: [PATCH 7/7] Revert "fix: build memory limitation" This reverts commit efb382fae84e800f54e27c27a44ae58653e5f773. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a7a6ef569ef6..48c356a1b432 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "test:integration": "pnpm --filter @blocksuite/presets test", "test:node": "node --experimental-specifier-resolution=node --loader ts-node/esm ./scripts/node-import-test.ts", "format": "prettier --write --cache packages tests", - "build": "NODE_OPTIONS=\"--max-old-space-size=6144\" pnpm build:packages && pnpm build:playground", + "build": "pnpm build:packages && pnpm build:playground", "build:packages": "pnpm --filter=@blocksuite/presets build", "build:playground": "pnpm --filter @blocksuite/playground build", "build:docs": "pnpm --filter @blocksuite/docs build",