Commit Graph

902 Commits

Author SHA1 Message Date
Saul-Mirone
12bf866dc5 fix(editor): remove replaceRichTextWithSvgElement (#11843) 2025-04-21 10:04:05 +00:00
Saul-Mirone
92ac8e3cad feat(editor): embed extension (#11848)
Closes: BS-3195
2025-04-21 09:22:12 +00:00
Saul-Mirone
15a5264352 feat(editor): divider and edgeless text extensions (#11846)
Closes: BS-3193
Closes: BS-3194
2025-04-21 09:22:12 +00:00
Saul-Mirone
652d42ba1e feat(editor): scaffolding store and view manager in affine (#11840)
Closes: BS-3254
2025-04-21 09:22:11 +00:00
Saul-Mirone
5244ff9b98 feat(editor): data view and database extension (#11837)
Closes: BS-3191
Closes: BS-3192
2025-04-21 09:22:11 +00:00
fundon
e60d5483ad refactor(editor): add attachments (#11842)
Closes: [BS-3256](https://linear.app/affine-design/issue/BS-3256/重构-add-attachments-方法)
2025-04-21 09:07:02 +00:00
L-Sun
61ce1123ae refactor(editor): split synced-doc-block tests to serveral files (#11845)
This PR splits `synced-doc-block.spec.ts` into multiple files for better organization.
2025-04-21 08:54:04 +00:00
doufa
b036ff5a45 fix(web): export png split text error with comment out rich text replacement in export process (#11834)
Co-authored-by: Mirone <Saul-Mirone@outlook.com>
2025-04-21 14:50:03 +08:00
Saul-Mirone
93b7c288cb feat(editor): callout and code extension (#11827)
Closes: BS-3243
Closes: BS-3190
2025-04-21 04:27:19 +00:00
Saul-Mirone
a6d0894ce1 feat(editor): bookmark and attachment extension (#11824)
Closes: BS-3188
Closes: BS-3189
2025-04-21 04:27:18 +00:00
Saul-Mirone
70ddae15ef feat(editor): affine extension provider and manager (#11822)
Closes: BS-3186

# @blocksuite/affine-ext-loader

Blocksuite extension loader system for AFFiNE, providing a structured way to manage and load extensions in different contexts.

## Usage

### Basic Extension Provider

```typescript
import { BaseExtensionProvider } from '@blocksuite/affine-ext-loader';
import { z } from 'zod';

// Create a custom provider with options
class MyProvider extends BaseExtensionProvider<'my-scope', { enabled: boolean }> {
  name = 'MyProvider';

  schema = z.object({
    enabled: z.boolean(),
  });

  setup(context: Context<'my-scope'>, options?: { enabled: boolean }) {
    super.setup(context, options);
    // Custom setup logic
  }
}
```

### Store Extensions

```typescript
import { StoreExtensionProvider, StoreExtensionManager } from '@blocksuite/affine-ext-loader';
import { z } from 'zod';

// Create a store provider with custom options
class MyStoreProvider extends StoreExtensionProvider<{ cacheSize: number }> {
  override name = 'MyStoreProvider';

  override schema = z.object({
    cacheSize: z.number().min(0),
  });

  override setup(context: StoreExtensionContext, options?: { cacheSize: number }) {
    super.setup(context, options);
    context.register([Ext1, Ext2, Ext3]);
  }
}

// Create and use the store extension manager
const manager = new StoreExtensionManager([MyStoreProvider]);
manager.configure(MyStoreProvider, { cacheSize: 100 });
const extensions = manager.get('store');
```

### View Extensions

```typescript
import { ViewExtensionProvider, ViewExtensionManager } from '@blocksuite/affine-ext-loader';
import { z } from 'zod';

// Create a view provider with custom options
class MyViewProvider extends ViewExtensionProvider<{ theme: string }> {
  override name = 'MyViewProvider';

  override schema = z.object({
    theme: z.enum(['light', 'dark']),
  });

  override setup(context: ViewExtensionContext, options?: { theme: string }) {
    super.setup(context, options);

    context.register([CommonExt]);
    if (context.scope === 'page') {
      context.register([PageExt]);
    } else if (context.scope === 'edgeless') {
      context.register([EdgelessExt]);
    }
    if (options?.theme === 'dark') {
      context.register([DarkModeExt]);
    }
  }

  // Override effect to run one-time initialization logic
  override effect() {
    // This will only run once per provider class
    console.log('Initializing MyViewProvider');
    // Register lit elements
    this.registerLitElements();
  }
}

// Create and use the view extension manager
const manager = new ViewExtensionManager([MyViewProvider]);
manager.configure(MyViewProvider, { theme: 'dark' });

// Get extensions for different view scopes
const pageExtensions = manager.get('page');
const edgelessExtensions = manager.get('edgeless');
```

### One-time Initialization with Effect

View extensions support one-time initialization through the `effect` method. This method is called automatically during setup, but only once per provider class. It's useful for:

- Initializing global state
- Registering lit elements
- Setting up shared resources

```typescript
class MyViewProvider extends ViewExtensionProvider {
  override effect() {
    // This will only run once, even if multiple instances are created
    initializeGlobalState();
    registerLitElements();
    setupGlobalEventListeners();
  }
}
```

### Available View Scopes

The view extension system supports the following scopes:

- `page` - Standard page view
- `edgeless` - Edgeless (whiteboard) view
- `preview-page` - Page preview view
- `preview-edgeless` - Edgeless preview view
- `mobile-page` - Mobile page view
- `mobile-edgeless` - Mobile edgeless view

### Extension Configuration

Extensions can be configured using the `configure` method:

```typescript
// Set configuration directly
manager.configure(MyProvider, { enabled: true });

// Update configuration using a function
manager.configure(MyProvider, prev => {
  if (!prev) return prev;
  return {
    ...prev,
    enabled: !prev.enabled,
  };
});

// Remove configuration
manager.configure(MyProvider, undefined);
```

### Dependency Injection

Both store and view extension managers support dependency injection:

```typescript
// Access the manager through the di container
const viewManager = std.get(ViewExtensionManagerIdentifier);
const pagePreviewExtension = viewManager.get('preview-page');
```
2025-04-21 04:27:18 +00:00
doodlewind
1146f4d5a9 fix(editor): prototype polluting in gfx util (#11831)
This fixes the security edge case where the font key happens to be `__proto__` or `constructor`
2025-04-21 04:00:59 +00:00
L-Sun
6d7cd6dd99 fix(editor): banner of blookmark not shown in edgeless (#11796)
Close [BS-2651](https://app.graphite.dev/github/pr/toeverything/AFFiNE/11797/chore(editor)-add-feature-flag-to-embed-doc-with-alias)
### What Changes:
- Fixed banner of edgeless embed bookmark is not shown
- Add fallback bookmark creation with embed creation modal when there is not a `QuickSearchProvider` in blocksuite playground
- Add tests for embed blookmark and embed github block in edgeless
2025-04-21 03:33:18 +00:00
Saul-Mirone
c74b5dc214 fix(editor): convert note to linked doc from edgeless (#11828)
Closes: BS-3244
2025-04-21 03:18:14 +00:00
fundon
67832aab09 chore(editor): update file icons (#11826) 2025-04-21 09:18:29 +08:00
L-Sun
f16bcdbe2b fix(editor): edgeless selected block is missing in the return of getSelectedBlockCommand (#11813) 2025-04-18 13:52:43 +00:00
L-Sun
5fcf34d848 refactor(editor): adjust parameters of duplicate block command (#11812) 2025-04-18 13:52:43 +00:00
fundon
c0ff567a2a fix(editor): get block props (#11807)
Closes: [BS-3184](https://linear.app/affine-design/issue/BS-3184/duplicate-图片,一直在loading)
2025-04-18 10:59:31 +00:00
L-Sun
3264e65980 chore(editor): add feature flag to embed doc with alias (#11797) 2025-04-18 07:39:16 +00:00
fundon
9c02512d7c fix(editor): chevron down icon on toolbar (#11803)
Uniform size: 16x16
2025-04-18 07:10:01 +00:00
donteatfriedrice
a555df0200 fix(editor): footnote popup style and position issues (#11771)
Close [BS-3049](https://linear.app/affine-design/issue/BS-3049/chat引用的样式坏了) [BS-3024](https://linear.app/affine-design/issue/BS-3024/footnote-在容器边缘时,hover-抽搐)
2025-04-18 02:44:21 +00:00
pengx17
75df27a145 fix(core): transcription block styls (#11772)
1. collapsed transcript block by default
2. summary block should be able to have list paragraphs
2025-04-17 12:41:52 +00:00
fundon
a46bb446e2 fix(editor): should keep color on custom color button (#11773)
Closes: [BS-3167](https://linear.app/affine-design/issue/BS-3167/自定义按钮显示错误)
2025-04-17 12:21:39 +00:00
donteatfriedrice
d6287fd7b0 fix(editor): clicking footnote node should not open doc when readonly (#11749) 2025-04-17 08:52:17 +00:00
L-Sun
fa28554b66 chore(editor): improve highlight of toc card (#11766)
Close [BS-3166](https://linear.app/affine-design/issue/BS-3166/toc-hover有时会出现两个阴影)

https://github.com/user-attachments/assets/842a69bc-e299-4b84-8780-ff2b54c30bab
2025-04-17 08:10:50 +00:00
pengx17
ebf1d5476d feat(core): add summary to transcription block (#11753)
fix AF-2523
2025-04-17 06:33:04 +00:00
L-Sun
98899b4eea feat(editor): affine to blocksuite doc dnd with prefered card view (#11748)
Close [BS-3070](https://linear.app/affine-design/issue/BS-3070/文档拖动进入edgeless,形成引用时,默认形成embeded的引用,但是记录上次选择)
2025-04-17 04:06:50 +00:00
donteatfriedrice
022e5f2c93 fix(editor): update embed iframe block event tracker (#11736)
Close [BS-3151](https://linear.app/affine-design/issue/BS-3151/埋一下-reload-link-成功失败)
2025-04-16 09:53:38 +00:00
Yifeng Wang
16f7be7f0b perf(editor): avoid redundant dom query when editing single block (#11732) 2025-04-16 17:52:22 +08:00
doodlewind
b21864cf63 perf(editor): dispose input event handler for removed blocks (#11734) 2025-04-16 09:05:47 +00:00
donteatfriedrice
212c13f843 fix(editor): add code block clipboard extension (#11731)
Close [BS-3109](https://linear.app/affine-design/issue/BS-3109/code-block-不支援-markdown-語法)
2025-04-16 08:32:00 +00:00
pengx17
79c9425df6 fix(editor): link popover title overflow (#11704)
fix AF-2506
2025-04-16 04:40:59 +00:00
donteatfriedrice
bfec5dd594 fix(editor): markdown html and image import (#11712)
Close
[BS-3145](https://linear.app/affine-design/issue/BS-3145/markdown-adapter-html-标签导入成-code-block)
[BS-3154](https://linear.app/affine-design/issue/BS-3154/[bug]-使用-markdown-with-files-导入到-affine-图片丢失)
2025-04-16 04:27:39 +00:00
Saul-Mirone
828215f45a refactor(editor): remove unused modal widget (#11713) 2025-04-16 04:13:58 +00:00
Saul-Mirone
3ebac1d39d refactor(editor): remove dead code (#11709) 2025-04-15 12:40:36 +00:00
donteatfriedrice
96e58316f7 feat(editor): add footnote node click handler (#11699)
Close [BS-3114](https://linear.app/affine-design/issue/BS-3114/点击-footnote-node-行为更新)
2025-04-15 12:22:43 +00:00
Saul-Mirone
b5c9741f18 feat(editor): extract keyboard toolbar widget (#11707) 2025-04-15 12:06:50 +00:00
fundon
8ca675b2ec fix(editor): improve pdf embed viewer UX (#11641)
Closes: [BS-3101](https://linear.app/affine-design/issue/BS-3101/pdf-embed-模式的选中框选-和点开看详情有比较大的问题)

### What's Changed!

* Fixed disable pointer event in native pdf viewer by dragging
* Disable opening peek view with pdf viewer in readonly and sharing modes
2025-04-15 08:51:02 +00:00
yoyoyohamapi
0df584bd5e refactor(core): add keyPress event to fix IME space detection (#11700)
### TL;DR
Refactor space-triggered AI Widget activation logic from `keydown` to `keypress` event listeners

### Background

The `keydown` event triggered by a space may originate from:
1. Normal space insertion
2. Space triggered by input method confirming candidate words

In scenarios like (2), some browsers (see [ISSUE](https://github.com/toeverything/AFFiNE/issues/11541)) and input method callbacks produce events identical to scenario (1),making it impossible to distinguish between the two.

To fix this, the space-activated AI listener uses the `keypress` event:
In scenario 2, `event.which !== 32` (may be `30430` or other values) can be used to differentiate from scenario 1.

> CLOSE BS-3081
2025-04-15 08:37:27 +00:00
Flrande
fd6c34cfa3 fix(editor): v-element may get undefined inline editor (#11697) 2025-04-15 08:22:39 +00:00
L-Sun
6f35021f22 chore(editor): update github block ui (#11690)
Close [BS-2651](https://linear.app/affine-design/issue/BS-2651/github-embed-block的样式修复)
2025-04-15 04:15:00 +00:00
Yifeng Wang
760a689c07 Merge branch 'canary' into 0414/vtr_test_layout 2025-04-15 09:20:25 +08:00
doodlewind
b8967a8a7b test(editor): add tests for turbo renderer state machine (#11659) 2025-04-14 15:54:02 +00:00
Yifeng Wang
e9d04de399 test(editor): add tests for turbo renderer layout cache 2025-04-14 17:06:13 +08:00
Yifeng Wang
e68947c792 fix(editor): integration vitest config warning 2025-04-14 17:04:57 +08:00
Yifeng Wang
2cd0e75810 fix: flaky 2025-04-14 17:04:22 +08:00
doodlewind
6457c979f5 test(editor): add tests for turbo renderer state machine (#11659) 2025-04-14 17:01:27 +08:00
donteatfriedrice
7aa87de5f7 fix(editor): markdown code preprocessor should handle link correctly (#11671)
Close [BS-3117](https://linear.app/affine-design/issue/BS-3117/代码粘贴后出现多余的-和-符号)
2025-04-14 08:28:43 +00:00
L-Sun
e1cb8198f1 fix(editor): android bs keyboard provider error (#11647)
### What Changes
- fixed keyboard service can not be initialized since a anonymous `BSKeyboardWithActionService` class was provider to di
- fixed tool panel was not closed when focus on other pragraph by clicking
- optimized code structure of fallback `show` and `hide` of keyboard
2025-04-13 09:59:24 +00:00
L-Sun
076c5ba044 fix(editor): repeat trigger keys of at-menu was added (#11631)
Close [BS-2716](https://linear.app/affine-design/issue/BS-2716/移动端通过toolpanel唤起的at-menu,出现两个)
2025-04-13 06:46:37 +00:00