mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 05:14:54 +00:00
This PR performs a significant architectural refactoring by extracting rich text functionality into a dedicated package. Here are the key changes: 1. **New Package Creation** - Created a new package `@blocksuite/affine-rich-text` to house rich text related functionality - Moved rich text components, utilities, and types from `@blocksuite/affine-components` to this new package 2. **Dependency Updates** - Updated multiple block packages to include the new `@blocksuite/affine-rich-text` as a direct dependency: - block-callout - block-code - block-database - block-edgeless-text - block-embed - block-list - block-note - block-paragraph 3. **Import Path Updates** - Refactored all imports that previously referenced rich text functionality from `@blocksuite/affine-components/rich-text` to now use `@blocksuite/affine-rich-text` - Updated imports for components like: - DefaultInlineManagerExtension - RichText types and interfaces - Text manipulation utilities (focusTextModel, textKeymap, etc.) - Reference node components and providers 4. **Build Configuration Updates** - Added references to the new rich text package in the `tsconfig.json` files of all affected packages - Maintained workspace dependencies using the `workspace:*` version specifier The primary motivation appears to be: 1. Better separation of concerns by isolating rich text functionality 2. Improved maintainability through more modular package structure 3. Clearer dependencies between packages 4. Potential for better tree-shaking and bundle optimization This is primarily an architectural improvement that should make the codebase more maintainable and better organized.
131 lines
3.1 KiB
TypeScript
131 lines
3.1 KiB
TypeScript
import type {
|
|
MindmapElementModel,
|
|
MindmapNode,
|
|
ShapeElementModel,
|
|
} from '@blocksuite/blocks';
|
|
import type { Page } from '@playwright/test';
|
|
|
|
import { clickView } from './actions/click.js';
|
|
|
|
export async function createMindMap(page: Page, coords: [number, number]) {
|
|
await page.keyboard.press('m');
|
|
await clickView(page, coords);
|
|
|
|
const id = await page.evaluate(() => {
|
|
const edgelessBlock = document.querySelector('affine-edgeless-root');
|
|
if (!edgelessBlock) {
|
|
throw new Error('edgeless block not found');
|
|
}
|
|
const mindmaps = edgelessBlock.gfx.gfxElements.filter(
|
|
el => 'type' in el && el.type === 'mindmap'
|
|
);
|
|
|
|
return mindmaps[mindmaps.length - 1].id;
|
|
});
|
|
|
|
return id;
|
|
}
|
|
|
|
export async function getMindMapNode(
|
|
page: Page,
|
|
mindmapId: string,
|
|
pathOrId: number[] | string
|
|
) {
|
|
return page.evaluate(
|
|
({ mindmapId, pathOrId }) => {
|
|
const edgelessBlock = document.querySelector('affine-edgeless-root');
|
|
if (!edgelessBlock) {
|
|
throw new Error('edgeless block not found');
|
|
}
|
|
|
|
const mindmap = edgelessBlock.gfx.getElementById(
|
|
mindmapId
|
|
) as MindmapElementModel;
|
|
if (!mindmap) {
|
|
throw new Error(`Mindmap not found: ${mindmapId}`);
|
|
}
|
|
|
|
const node = Array.isArray(pathOrId)
|
|
? mindmap.getNodeByPath(pathOrId)
|
|
: mindmap.getNode(pathOrId);
|
|
if (!node) {
|
|
throw new Error(`Mindmap node not found at: ${pathOrId}`);
|
|
}
|
|
|
|
const rect = edgelessBlock.gfx.viewport.toViewBound(
|
|
node.element.elementBound
|
|
);
|
|
|
|
return {
|
|
path: mindmap.getPath(node),
|
|
id: node.id,
|
|
text: (node.element as ShapeElementModel).text?.toString() ?? '',
|
|
rect: {
|
|
x: rect.x,
|
|
y: rect.y,
|
|
w: rect.w,
|
|
h: rect.h,
|
|
},
|
|
};
|
|
},
|
|
{
|
|
mindmapId,
|
|
pathOrId,
|
|
}
|
|
);
|
|
}
|
|
|
|
type NewNodeInfo = {
|
|
text: string;
|
|
children?: NewNodeInfo[];
|
|
};
|
|
|
|
export async function addMindmapNodes(
|
|
page: Page,
|
|
mindmapId: string,
|
|
path: number[],
|
|
newNode: NewNodeInfo
|
|
) {
|
|
return page.evaluate(
|
|
({ mindmapId, path, newNode }) => {
|
|
const edgelessBlock = document.querySelector('affine-edgeless-root');
|
|
if (!edgelessBlock) {
|
|
throw new Error('edgeless block not found');
|
|
}
|
|
|
|
const mindmap = edgelessBlock.gfx.getElementById(
|
|
mindmapId
|
|
) as MindmapElementModel;
|
|
if (!mindmap) {
|
|
throw new Error(`Mindmap not found: ${mindmapId}`);
|
|
}
|
|
|
|
const parent = mindmap.getNodeByPath(path);
|
|
if (!parent) {
|
|
throw new Error(`Mindmap node not found at: ${path}`);
|
|
}
|
|
|
|
const addNode = (
|
|
mindmap: MindmapElementModel,
|
|
node: NewNodeInfo,
|
|
parent: MindmapNode
|
|
) => {
|
|
const newNodeId = mindmap.addNode(parent, undefined, undefined, {
|
|
text: node.text,
|
|
});
|
|
|
|
if (node.children) {
|
|
node.children.forEach(child => {
|
|
addNode(mindmap, child, mindmap.getNode(newNodeId)!);
|
|
});
|
|
}
|
|
|
|
return newNodeId;
|
|
};
|
|
|
|
return addNode(mindmap, newNode, parent);
|
|
},
|
|
{ mindmapId, path, newNode }
|
|
);
|
|
}
|