Skip to content
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

Merged
merged 1 commit into from
Dec 18, 2024

Conversation

doouding
Copy link
Member

@doouding doouding commented Dec 5, 2024

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:

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.

Copy link

changeset-bot bot commented Dec 5, 2024

⚠️ No Changeset found

Latest commit: 10a4437

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Dec 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
blocksuite ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 18, 2024 2:39am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
blocksuite-docs ⬜️ Ignored (Inspect) Visit Preview Dec 18, 2024 2:39am

Copy link

graphite-app bot commented Dec 5, 2024

Your org has enabled the Graphite merge queue for merging into master

Add 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.

Copy link
Member Author

doouding commented Dec 5, 2024


How to use the Graphite Merge Queue

Add 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.

Copy link

nx-cloud bot commented Dec 5, 2024

☁️ Nx Cloud Report

CI 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 target

Sent with 💌 from NxCloud.

Copy link
Contributor

github-actions bot commented Dec 12, 2024

size-limit report 📦

Path Size
@blocksuite/affine 13 B (0%)
@blocksuite/affine/effects 2.1 MB (+0.01% 🔺)
@blocksuite/affine/block-std 158.05 KB (+0.48% 🔺)
@blocksuite/affine/block-std/gfx 81.86 KB (+0.75% 🔺)
@blocksuite/affine/global 13 B (0%)
@blocksuite/affine/global/utils 13.88 KB (0%)
@blocksuite/affine/global/env 217 B (0%)
@blocksuite/affine/global/exceptions 562 B (0%)
@blocksuite/affine/global/di 1.65 KB (0%)
@blocksuite/affine/global/types 13 B (0%)
@blocksuite/affine/store 78.66 KB (0%)
@blocksuite/affine/inline 32.66 KB (0%)
@blocksuite/affine/inline/consts 242 B (0%)
@blocksuite/affine/inline/types 13 B (0%)
@blocksuite/affine/presets 1.9 MB (+0.07% 🔺)
@blocksuite/affine/blocks 1.99 MB (+0.03% 🔺)
@blocksuite/affine/blocks/schemas 89.85 KB (+0.63% 🔺)

Copy link

graphite-app bot commented Dec 18, 2024

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.
@doouding doouding force-pushed the 12-05-feat_add_local_element_support branch from a61fbb6 to 10a4437 Compare December 18, 2024 02:37
@graphite-app graphite-app bot merged commit 10a4437 into master Dec 18, 2024
36 checks passed
@graphite-app graphite-app bot deleted the 12-05-feat_add_local_element_support branch December 18, 2024 02:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

2 participants