-
-
Notifications
You must be signed in to change notification settings - Fork 425
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
feat(edgeless): improve local element support #8869
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. |
How to use the Graphite Merge QueueAdd the label merge to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
packages/framework/block-std/src/gfx/model/surface/local-element-model.ts
Show resolved
Hide resolved
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 10a4437. 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. |
8cf2b40
to
1feb37d
Compare
08bab64
to
760c08f
Compare
1feb37d
to
286432a
Compare
f4d2fb7
to
5e26e5b
Compare
3268c13
to
de7bbc7
Compare
packages/framework/block-std/src/gfx/model/surface/local-element-model.ts
Show resolved
Hide resolved
size-limit report 📦
|
fdd053d
to
02b4245
Compare
6d487de
to
a61fbb6
Compare
Merge activity
|
### Defining a New Local Element To define a local element, create a class that extends `GfxLocalElementModel`, and use the `@prop` decorator on any field that you want to track changes for via `localElementUpdated`. Note: Do **not** use any Yjs data structures, as local elements are intended for local data only. Example: ```typescript import { GfxLocalElementModel, prop } from '@blocksuite/block-std/gfx'; export class LocalTextElement extends GfxLocalElementModel { get type() { return 'text' } @prop() accessor text: string = ''; } ``` Once the class is defined, create an instance with `const localText = new LocalTextElement(surfaceModel)`. You can then use its render function to manually render the model. To watch `@prop` decorated property changes, use `surface.localElementUpdated` to listen for updates. ### Adding to surface model Add instances to the surface using the `surface.addLocalElement` method. This enables event support and automatic rendering—there’s no need to call the render function manually. When the element is no longer needed, remove it from the surface with `surface.deleteLocalElement`. Calling `addLocalElement` and `deleteLocalElement` will trigger `localElementAdded` and `localElementDeleted` slot respectively. Note: Adding to the surface is **not** required if a local instance is sufficient for your needs.
a61fbb6
to
10a4437
Compare
Defining a New Local Element
To define a local element, create a class that extends
GfxLocalElementModel
, and use the@prop
decorator on any field that you want to track changes for vialocalElementUpdated
.Note: Do not use any Yjs data structures, as local elements are intended for local data only.
Example:
Once the class is defined, create an instance with
const localText = new LocalTextElement(surfaceModel)
. You can then use its render function to manually render the model.To watch
@prop
decorated property changes, usesurface.localElementUpdated
to listen for updates.Adding to surface model
Add instances to the surface using the
surface.addLocalElement
method. This enables event support and automatic rendering—there’s no need to call the render function manually.When the element is no longer needed, remove it from the surface with
surface.deleteLocalElement
.Calling
addLocalElement
anddeleteLocalElement
will triggerlocalElementAdded
andlocalElementDeleted
slot respectively.Note: Adding to the surface is not required if a local instance is sufficient for your needs.