-
-
Notifications
You must be signed in to change notification settings - Fork 415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: migrating legacy tools #8471
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
|
Your org has enabled the Graphite merge queue for merging into masterAdd the label “merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link. |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 65fbde6. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
69247c7
to
a4b887f
Compare
41e7fa5
to
bf1aa32
Compare
a7c9afc
to
00e4a25
Compare
The `EdgelessToolManager` has been renamed to `GfxToolController`. All the legacy tools will be rewrited using the new infra. #### How to add a new tool Let's take an example of pan tool. ```typescript import { BaseTool } from '@blocksuite/block-std/gfx'; // extend the BaseTool export class PanTool extends BaseTool { // every tool class should have static toolName static override toolName = 'pan'; dragStart(e) { this._lastPoint = [e.x, e.y]; } dragEnd(e) { this._lastPoint = null; } dragMove(e) { if (!this._lastPoint) return; const { viewport } = this._service; const { zoom } = viewport; const [lastX, lastY] = this._lastPoint; const deltaX = lastX - e.x; const deltaY = lastY - e.y; this._lastPoint = [e.x, e.y]; this.gfx.viewport.applyDeltaCenter(deltaX / zoom, deltaY / zoom); } } ``` Once you finish defining the tool, just append it to the spec array. ```typescript // edgeless-spec.ts file import { PanTool } from '../tools/pan-tool.ts'; export const EdgelessSpec = [ // .... omit the other part of spec // append it to the array PanTool ] ``` Continue in #8471
887e8ea
to
27561d0
Compare
Merge activity
|
48c697c
to
34a6a69
Compare
34a6a69
to
45abe5c
Compare
size-limit report 📦
|
Continue #8438 There're some depended modules that need to be refactor also during migration. I'll list them here. ### GfxExtension Used to extend the `GfxController`. The `GfxExtension` can perform tasks during the life cycle of `GfxController`. ```typescript import { GfxExtension } from '@blocksuite/std/gfx'; export class ExampleExtension extends GfxExtension { // the key is required static override key = 'example'; // you can access this.gfx inside the class context mounted() { // called when gfx has mounted } unmounted() { // called when gfx has unmounted } } // edgeless-spec.ts export const edgelessSpec = [ // append it on the spec list ExampleExtension ] ``` ### KeyboardController `KeyboardController` provide the pressing status of common key such as shift, space. So that you don't have to maintain thoese status everywhere. Now you can access it through `gfx.keyboard`. ### EdgelessSelectionManager The legacy `EdgelessSelectionManager` has move to `block-std/gfx` and become a first-party supported module. Now you can access it through `gfx.selection`. ### OverlayExtension The legacy overlay has to be instantiated and added manually, which is a bit of a hassle. The newly refactored overlay utilizes the new Extension infra to automatically instantiate and add itself to the overlay renderer. ```typescript import { Overlay } from './renderer/overlay.js'; export class ExampleOverlay extends Overlay { static override overlayName = 'example'; // the methods remain the same } // edgeless-spec.ts import { ExampleOverlay } from './example-overlay.js' export const edgelessSpec = [ // append it on the spec list ExampleOverlay ] ``` When you need to get the instance of that overlay, just use the `std.get(OverlayIdentifier(theOverlayName)`. ```typescript import { OverlayIdentifier } from './renderer/overlay.js'; const exampleOverlayInst = std.get(OverlayIdentifier('example'); ``` Note that you don’t have to use the OverlayExtension if you only need a local overlay. You can still create and add it to the renderer manually. ### SurfaceMiddlewareExtesion The new surface middleware is aimed to extend the functionality of `addElement`, `deleteElement` and `updateElement`. It's a pure local infra which is helpful when you need to do something when the previously mentioned methods are called. You can load the middleware manually using `surfaceModel.applyMiddlewares` method. But we provide a more common way to extend the middleware using the Extension infra. ```typescript import { type SurfaceMiddlewareBuilder } from '@blocksuite/block-std/gfx'; export const ExampleMiddlewareBuilder: SurfaceMiddlewareBuilder = (std: BlockStdScope) => { /** * you can access std here * the builder must return a middleware function which will be apply to surface model **/ return (ctx: MiddlewareCtx) => { // this middleware function will be executed every time when the surface methods get called. } } // edgeless-spec.ts import { SurfaceMiddlewareExtension } from '@blocksuite/block-std/gfx'; import { ExampleMiddlewareBuilder } from './middlewares.js' export const edgelessSpec = [ // ... // the surface builder should be wrapped in the `SurfaceMiddlewareExtension` function to get injected SurfaceMiddlewareExtension([ExampleMiddlewareBuilder]) ] ``` ### Review guide This PR is a bit huge, but most of changes are just migration from legacy implementation. Here the list that worth attention. - Every change under block-std package - New extendable overlay under block-surface/src/renderer/overlay.ts
6d9bba0
to
65fbde6
Compare
## Feat - feat(blocks): add more html transformer apis (#8573) - feat(blocks): support more markdown transformer api (#8564) - feat(blocks): add abort controller to peekviewservice (#8558) - feat: add docLinkMiddleware for linked doc export (#8553) ## Fix - fix: mind map dragging issue (#8563) - fix(database): can't use horizontal scrollbar (#8576) - fix: note width is less than minimum width after resize and arrange (#8550) - fix: newly created note alignments cannot be stored persistently (#8551) - fix: inline range calculation not expected (#8552) - fix(database): avoid filter bar flickering (#8562) - fix(database): drag and drop block into database block (#8561) - fix(blocks): split paragraphs based on newlines (#8556) - fix(database): incorrect delete row logic (#8544) - fix: note height less than minimum height (#8542) ## Chore - chore: add changelog generating script (#8582) - chore: optimize zip transformer api (#8580) - chore: adjust attachment click events, like image, to support opening in peek view (#8579) - chore: remove useless import (#8571) ## Refactor - refactor: convert built-in component to widget (#8577) - refactor: migrating legacy tools (#8471) - refactor: edgeless tool manager (#8438) - refactor(playground): organize export and import menu items into submenus in the debug menu (#8557) - refactor: combine unsafeCSS and cssVar (#8545) ## Perf - perf(edgeless): use css var to place collaboration cursors-n-selections on board zoom change (#8543)
Continue #8438
There're some depended modules that need to be refactor also during migration. I'll list them here.
GfxExtension
Used to extend the
GfxController
. TheGfxExtension
can perform tasks during the life cycle ofGfxController
.KeyboardController
KeyboardController
provide the pressing status of common key such as shift, space. So that you don't have to maintain thoese status everywhere. Now you can access it throughgfx.keyboard
.EdgelessSelectionManager
The legacy
EdgelessSelectionManager
has move toblock-std/gfx
and become a first-party supported module. Now you can access it throughgfx.selection
.OverlayExtension
The legacy overlay has to be instantiated and added manually, which is a bit of a hassle. The newly refactored overlay utilizes the new Extension infra to automatically instantiate and add itself to the overlay renderer.
When you need to get the instance of that overlay, just use the
std.get(OverlayIdentifier(theOverlayName)
.Note that you don’t have to use the OverlayExtension if you only need a local overlay. You can still create and add it to the renderer manually.
SurfaceMiddlewareExtesion
The new surface middleware is aimed to extend the functionality of
addElement
,deleteElement
andupdateElement
. It's a pure local infra which is helpful when you need to do something when the previously mentioned methods are called.You can load the middleware manually using
surfaceModel.applyMiddlewares
method. But we provide a more common way to extend the middleware using the Extension infra.Review guide
This PR is a bit huge, but most of changes are just migration from legacy implementation. Here the list that worth attention.