Commit Graph

85 Commits

Author SHA1 Message Date
Saul-Mirone
773db7860a feat(editor): not sync selection from awareness (#11420) 2025-04-03 09:22:26 +00:00
Saul-Mirone
0a8d8e0a6b feat: seperate createDoc and createStore (#11182) 2025-03-26 11:03:47 +00:00
Saul-Mirone
e84c60f53d feat(editor): add provider for base adapter (#11169) 2025-03-25 12:09:23 +00:00
Saul-Mirone
258c70cf07 refactor(editor): store should not rely on inline (#11017) 2025-03-20 01:33:29 +00:00
Saul-Mirone
5cb2abab76 docs(editor): add doc for reactive types in store (#10958) 2025-03-18 09:07:42 +00:00
Saul-Mirone
ef00a158fc docs(editor): improve documentation for store class (#10949) 2025-03-18 07:57:58 +00:00
Saul-Mirone
9f3cf271e3 feat(editor): support user provided role and role schema (#10939)
Let me analyze the key changes in this diff:

1. **Role System Changes**:
- Changed from a fixed enum of roles (`root`, `hub`, `content`) to a more flexible string-based system
- Removed strict role hierarchy validation rules (hub/content/root relationships)
- Added support for role-based matching using `@` prefix (e.g., `@root`, `@content`)

2. **Schema Validation Updates**:
- Added new `_matchFlavourOrRole` method to handle both flavour and role-based matching
- Updated `_validateParent` to consider both roles and flavours when validating parent-child relationships
- Simplified `_validateRole` by removing specific role hierarchy constraints

3. **Block Schema Changes**:
- Updated parent/children references in various block schemas to use the new `@` prefix notation
- Changed parent definitions from `['affine:page']` to `['@root']` in several blocks
- Updated children definitions to use role-based references (e.g., `['@content']`)

4. **Test Updates**:
- Added new test cases for role-based schema validation
- Introduced new test block schemas (`TestRoleBlockSchema`, `TestParagraphBlockSchema`) to verify role-based functionality

This appears to be a significant architectural change that makes the block schema system more flexible by:
1. Moving away from hardcoded role hierarchies
2. Introducing a more dynamic role-based relationship system
3. Supporting both flavour-based and role-based parent-child relationships
4. Using the `@` prefix convention to distinguish role references from flavour references

The changes make the system more extensible while maintaining backward compatibility with existing flavour-based relationships.
2025-03-18 01:58:59 +00:00
Saul-Mirone
3de7d85eea feat(editor): improve api for store, and add docs (#10941) 2025-03-17 16:30:59 +00:00
Saul-Mirone
1d04438049 docs(editor): scaffolding docs generator (#10925) 2025-03-17 12:51:08 +00:00
doodlewind
81af7a0571 docs(editor): add guide for extension usage (#10911)
The guide is baed on #10847 to improve the code quality for migrating extensions using LLM.
2025-03-17 05:38:10 +00:00
Saul-Mirone
808c053c3c feat(editor): add block meta for table block (#10915) 2025-03-17 05:20:10 +00:00
Saul-Mirone
26285f7dcb feat(editor): unify block props api (#10888)
Closes: [BS-2707](https://linear.app/affine-design/issue/BS-2707/统一使用props获取和更新block-prop)
2025-03-16 05:48:34 +00:00
Saul-Mirone
5566632b30 refactor(editor): improve the implementation of flat proxy (#10872) 2025-03-14 23:25:47 +09:00
Saul-Mirone
517817e66f refactor(editor): separate yjs subscribe logic of flat model (#10863) 2025-03-14 23:09:31 +09:00
Saul-Mirone
a3ce67a59d refactor(editor): separate init logic of flat model (#10862) 2025-03-14 23:09:31 +09:00
Saul-Mirone
1ce290094e refactor(editor): improve implementation of flat model (#10848) 2025-03-14 13:18:03 +00:00
EYHN
05200ad7b7 feat(nbstore): add blob sync storage (#10752) 2025-03-14 18:05:54 +08:00
Saul-Mirone
250f3f1efd feat(editor): add isLocal flag in blockUpdated subject (#10799) 2025-03-13 05:33:06 +00:00
Mirone
cd63e0ed8b feat(editor): replace slot with rxjs subject (#10768) 2025-03-12 11:29:24 +09:00
Saul-Mirone
9cfd1c321e fix(editor): missing re-subscription for slots on store (#10750) 2025-03-11 04:07:06 +00:00
Saul-Mirone
dc047aa1a4 feat(editor): allow undefined default props (#10701)
Closes: [BS-2771](https://linear.app/affine-design/issue/BS-2771/%E6%84%9F%E8%A7%89%E5%BE%97%E6%94%AF%E6%8C%81%E5%8F%AF%E9%80%89%E5%AD%97%E6%AE%B5[mirone]1f862b1b-8523-4487-a948-fef9174e8825)
2025-03-07 15:57:12 +00:00
Saul-Mirone
8d10b40b72 feat(editor): add loaded and disposed hook for store extension (#10669) 2025-03-06 13:31:09 +00:00
Saul-Mirone
84e2dda3f8 refactor(editor): separate lit and slot in global (#10666) 2025-03-06 10:24:59 +00:00
EYHN
5c8b81581c feat(core): doc level awareness (#10646) 2025-03-06 06:05:45 +00:00
Saul-Mirone
b8ecfbdae6 refactor(editor): remove assertExists (#10615) 2025-03-05 00:13:08 +00:00
Saul-Mirone
22924c767c fix(editor): onChange notification for flat model (#10589)
The primary purpose of this PR appears to be:
1. Simplifying the change notification API by removing the redundant value parameter from callbacks
2. Improving the reactive system's handling of specialized types (Text and Boxed) in flat data
3. Adding better test coverage for text handling in the flat data model
2025-03-04 05:57:06 +00:00
Saul-Mirone
a587abca85 feat(editor): add block meta service (#10561) 2025-03-03 06:13:06 +00:00
Saul-Mirone
e90c00c3b7 refactor(editor): perf optimization of flat data (#10494)
The new code should be more efficient as it:
- Avoids unnecessary iterations when objects aren't empty
- Has clearer path management
- Reduces redundant object traversals
2025-02-28 04:51:54 +00:00
Saul-Mirone
b19c1df43e fix: table collab (#10489)
[Screen Recording 2025-02-27 at 20.24.15.mov <span class="graphite__hidden">(uploaded via Graphite)</span> <img class="graphite__hidden" src="https://app.graphite.dev/api/v1/graphite/video/thumbnail/EUhyG5TOGVlHZ0Suk1wH/b3ac681f-a14d-483a-820c-53c584f0fb44.mov" />](https://app.graphite.dev/media/video/EUhyG5TOGVlHZ0Suk1wH/b3ac681f-a14d-483a-820c-53c584f0fb44.mov)
2025-02-27 12:37:57 +00:00
Saul-Mirone
4c736bc190 feat(editor): type safe draft model and transformer (#10486) 2025-02-27 09:19:49 +00:00
Saul-Mirone
d57ef5c5b3 fix(editor): transform to draftmodel first when get snapshot (#10477) 2025-02-27 07:52:18 +00:00
zzj3720
18dfad28d7 fix(editor): toDraftModal supports flat data structures (#10466)
fix: PD-2374
fix: BS-2703
2025-02-27 05:16:10 +00:00
Saul-Mirone
fd6d96a38e refactor(editor): use transformer from store when possible (#10453) 2025-02-26 14:15:04 +00:00
Saul-Mirone
ce87dcf58e feat(editor): schema extension (#10447)
1. **Major Architectural Change: Schema Management**
   - Moved from `workspace.schema` to `store.schema` throughout the codebase
   - Removed schema property from Workspace and Doc interfaces
   - Added `BlockSchemaExtension` pattern across multiple block types

2. **Block Schema Extensions Added**
   - Added new `BlockSchemaExtension` to numerous block types including:
     - DataView, Surface, Attachment, Bookmark, Code
     - Database, Divider, EdgelessText, Embed blocks (Figma, Github, HTML, etc.)
     - Frame, Image, Latex, List, Note, Paragraph
     - Root, Surface Reference, Table blocks

3. **Import/Export System Updates**
   - Updated import functions to accept `schema` parameter:
     - `importHTMLToDoc`
     - `importHTMLZip`
     - `importMarkdownToDoc`
     - `importMarkdownZip`
     - `importNotionZip`
   - Modified export functions to use new schema pattern

4. **Test Infrastructure Updates**
   - Updated test files to use new schema extensions
   - Modified test document creation to include schema extensions
   - Removed direct schema registration in favor of extensions

5. **Service Layer Changes**
   - Updated various services to use `getAFFiNEWorkspaceSchema()`
   - Modified transformer initialization to use document schema
   - Updated collection initialization patterns

6. **Version Management**
   - Removed version-related properties and methods from:
     - `WorkspaceMetaImpl`
     - `TestMeta`
     - `DocImpl`
   - Removed `blockVersions` and `workspaceVersion/pageVersion`

7. **Store and Extension Updates**
   - Added new store extensions and adapters
   - Updated store initialization patterns
   - Added new schema-related functionality in store extension

This PR represents a significant architectural shift in how schemas are managed, moving from a workspace-centric to a store-centric approach, while introducing a more extensible block schema system through `BlockSchemaExtension`. The changes touch multiple layers of the application including core functionality, services, testing infrastructure, and import/export capabilities.
2025-02-26 11:31:29 +00:00
CatsJuice
e1fd8f5d80 fix(core): correctly toggle visibility of starter-bar based on doc.isEmpty (#10439) 2025-02-26 07:49:51 +00:00
Saul-Mirone
faf6e2c79f refactor(editor): optimize store map (#10246) 2025-02-18 13:30:09 +00:00
doouding
eed00e0b26 fix: mindmap ai preview (#10222) 2025-02-17 12:45:20 +00:00
Saul-Mirone
9321ce94a7 refactor(editor): remove global types in config (#10143)
Closes: [BS-2554](https://linear.app/affine-design/issue/BS-2554/remove-global-types-in-block-config)
2025-02-13 04:35:35 +00:00
doouding
f89fcf82f8 feat: edgeless dnd (#9988)
### Changed
- Support edgelss dnd
- Simplify the drag-handle state
2025-02-12 12:37:06 +00:00
Saul-Mirone
39eb8625d6 refactor(editor): remove block models global type (#10086) 2025-02-11 11:00:57 +00:00
Saul-Mirone
652865c7cf refactor(editor): remove global types in model (#10082)
Closes: [BS-2249](https://linear.app/affine-design/issue/BS-2249/remove-global-types-in-model)

```ts
// before
matchFlavours(model, ['affine:page']);
// after
matchFlavours(model, [PageBlockModel]);
```
2025-02-11 08:18:57 +00:00
Saul-Mirone
c6b8f2b584 refactor(editor): flat data for table block (#10010)
close: BS-2548
2025-02-10 19:09:33 +00:00
Saul-Mirone
5b750bbba4 feat(editor): support delete in flat block proxy (#9994) 2025-02-06 16:30:06 +00:00
doouding
02122098c7 fix: drag block issue (#9902)
### Changed
- Added support for changing the preview offset during dragging.
- Fixed the preview rendering for embed block and surface-ref block
- Resolved an issue where the host element might be reused in certain cases, which could cause unexpected behavior
- Moved viewport-related constants and methods to a more appropriate location
2025-02-05 07:25:53 +00:00
Saul-Mirone
1858947e0c feat(editor): flat block data (#9854)
Flat block data.

A new block type to flatten the block data

```typescript
// For developers
type Model = {
  blocks: Record<string, {
    flavour: string;
    cells: Record<string, {
      rowId: string;
      colId: string;
      text: Text;
    }>;
    cols: Record<string, {
      align: string;
    }>
    rows: Record<string, {
      backgroundColor: string;
    }>
  }>
}

// How it's saved in yjs
const yData = {
  blocks: {
    'blockId1': {
      flavour: 'affine:table',
      'prop:rows:row1:backgroundColor': 'white',
      'prop:cols:col1:align': 'left',
      'prop:cells:cell1:rowId': 'row1',
      'prop:cells:cell1:colId': 'col1',
      'prop:cells:cell1:text': YText,
      prop:children: []
    },
  }
}
```
2025-01-25 12:57:21 +00:00
L-Sun
351816b343 fix(editor): prevent errors when moving a block to its own position (#9887) 2025-01-24 12:55:55 +00:00
Saul-Mirone
5783580054 fix(editor): y reactive deep watch (#9818)
Closes: [BS-2193](https://linear.app/affine-design/issue/BS-2193/fix-deep-watcher-of-reactive-yjs-data)
2025-01-21 08:08:01 +00:00
Saul-Mirone
f744002808 refactor(editor): add schema on block model (#9815) 2025-01-21 03:56:10 +00:00
EYHN
a2ffdb4047 feat(core): new worker workspace engine (#9257) 2025-01-16 16:22:18 +00:00
doouding
99717196c5 refactor: rewrite blocksuite dnd (#9595)
### Changed

- Refactored BlockSuite drag-and-drop using @atlaskit/pragmatic-drag-and-drop/element/adapter.
- Updated block dragging to use the new drag-and-drop infrastructure.

### BlockSuite DND API

Access the BlockSuite drag-and-drop API via `std.dnd`. This is a lightweight wrapper around pragmatic-drag-and-drop, offering convenient generic types and more intuitive option names.

#### Drag payload structure
There's some constrain about drag payload. The whole drag payload looks like this:

```typescript
type DragPayload = {
  entity: {
    type: string
  },
  from: {
    at: 'blocksuite',
    docId: string
  }
}
```
- The `from` field is auto-generated—no need for manual handling.
- The `entity` field is customizable, but it must include a `type`.

All drag-and-drop methods accept a generic type for entity, ensuring more accurate payloads in event handlers.

```typescript
type BlockEntity = {
  type: 'blocks',
  blockIds: string[]
}

dnd.draggable<BlockEntity>({
  element: someElement,
  setDragData: () => {
    // the return type must satisfy the generic type
    // in this case, it's BlockEntity
    return {
      type: 'blocks',
      blockIds: []
    }
  }
});

dnd.monitor<BlockEntity>({
  // the arguments is same for other event handler
  onDrag({ source }) {
    // the type of this is BlockEntity
    source.data.entity
  }
})
```

#### Drop payload
When hover on droppable target. You can set drop payload as well. All drag-and-drop methods accept a second generic type for drop payload.

The drop payload is customizable. Additionally, the DND system will add an `edge` field to the final payload object, indicating the nearest edge of the drop target relative to the current drag position.

```typescript
type DropPayload = {
  blockId: string;
}

dnd.dropTarget<BlockEntity, DropPayload>({
  getData() {
    // the type should be DropPayload
    return {
      blockId: 'someId'
    }
  }
});

dnd.monitor<BlockEntity, DropPayload>({
  // drag over on drop target
  onDrag({ location }) {
    const target = location.current.dropTargets[0];

    // the type is DropPayload
    target.data;
    // retrieve the nearest edge of the drop target relative to the current drop position.
    target.data.edge;
  }
})
```
2025-01-16 12:36:58 +00:00