mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-11 20:08:37 +00:00
refactor: add docsService for blocksuite to change and observe doc mode (#7200)
This PR provide `DocModeService` to manage document mode, which is used by blocksuite. ### What Changed? - Add document mode apis from `DocService` and `DocsService` - Remove useless `pageService.getEditorMode` and `pageService.slots.editorModeSwitch` api [Related PR in blocksuite](https://github.com/toeverything/blocksuite/pull/7288) [Bump Blocksuite](https://github.com/toeverything/AFFiNE/pull/7209) > ## Features > * [feat(presets): support different tracker control for actions blocksuite#7285](https://github.com/toeverything/blocksuite/pull/7285) @donteatfriedrice > * [feat(edgeless): add default color and editing border for edgeless text blocksuite#7278](https://github.com/toeverything/blocksuite/pull/7278) @Flrande > * [feat(blocks): center peek entries blocksuite#7275](https://github.com/toeverything/blocksuite/pull/7275) @pengx17 > > ## Bugfix > * [fix(blocks): affine-embed-synced-doc-block peek on dblclick blocksuite#7284](https://github.com/toeverything/blocksuite/pull/7284) @pengx17 > * [fix(edgeless): edgeless text rect should automatically update when changing font blocksuite#7292](https://github.com/toeverything/blocksuite/pull/7292) @Flrande > * [fix(edgeless): align panel not work blocksuite#7293](https://github.com/toeverything/blocksuite/pull/7293) @Flrande > * [fix(blocks): filterable list unexpected hover style blocksuite#7291](https://github.com/toeverything/blocksuite/pull/7291) @golok727 > * [fix(blocks): slash menu unexpected hover style blocksuite#7290](https://github.com/toeverything/blocksuite/pull/7290) @golok727 > * [fix(blocks): bookmark block error on undo or delete while loading blocksuite#7276](https://github.com/toeverything/blocksuite/pull/7276) @golok727 > * [fix(presets): chat input max-height blocksuite#7283](https://github.com/toeverything/blocksuite/pull/7283) @fundon > * [fix(presets): get image blob from selection blocksuite#7286](https://github.com/toeverything/blocksuite/pull/7286) @donteatfriedrice > * [fix(blocks): connectors resize and rotate blocksuite#7256](https://github.com/toeverything/blocksuite/pull/7256) @fundon > > ## Refactor > * [refactor: add DocModeService for doc mode get, set, toogle and observe change blocksuite#7288](https://github.com/toeverything/blocksuite/pull/7288) @akumatus > * [refactor(edgeless): rewrite auto-connect component as a widget blocksuite#7287](https://github.com/toeverything/blocksuite/pull/7287) @doouding > > ## Misc > * [test: fix flaky blocksuite#7295](https://github.com/toeverything/blocksuite/pull/7295) @L-Sun > * [style(page): adjust heading font-weight and letter-spacing blocksuite#7277](https://github.com/toeverything/blocksuite/pull/7277) @CatsJuice > * [chore: apply member ordering rule blocksuite#7279](https://github.com/toeverything/blocksuite/pull/7279) @Saul-Mirone ---
This commit is contained in:
4
packages/common/env/package.json
vendored
4
packages/common/env/package.json
vendored
@@ -3,8 +3,8 @@
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@blocksuite/global": "0.15.0-canary-202406111431-81a6bee",
|
||||
"@blocksuite/store": "0.15.0-canary-202406111431-81a6bee",
|
||||
"@blocksuite/global": "0.15.0-canary-202406121423-a4241b5",
|
||||
"@blocksuite/store": "0.15.0-canary-202406121423-a4241b5",
|
||||
"react": "18.3.1",
|
||||
"react-dom": "18.3.1",
|
||||
"vitest": "1.6.0"
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
"@affine/debug": "workspace:*",
|
||||
"@affine/env": "workspace:*",
|
||||
"@affine/templates": "workspace:*",
|
||||
"@blocksuite/blocks": "0.15.0-canary-202406111431-81a6bee",
|
||||
"@blocksuite/global": "0.15.0-canary-202406111431-81a6bee",
|
||||
"@blocksuite/store": "0.15.0-canary-202406111431-81a6bee",
|
||||
"@blocksuite/blocks": "0.15.0-canary-202406121423-a4241b5",
|
||||
"@blocksuite/global": "0.15.0-canary-202406121423-a4241b5",
|
||||
"@blocksuite/store": "0.15.0-canary-202406121423-a4241b5",
|
||||
"@datastructures-js/binary-search-tree": "^5.3.2",
|
||||
"foxact": "^0.2.33",
|
||||
"jotai": "^2.8.0",
|
||||
@@ -29,8 +29,8 @@
|
||||
"devDependencies": {
|
||||
"@affine-test/fixtures": "workspace:*",
|
||||
"@affine/templates": "workspace:*",
|
||||
"@blocksuite/block-std": "0.15.0-canary-202406111431-81a6bee",
|
||||
"@blocksuite/presets": "0.15.0-canary-202406111431-81a6bee",
|
||||
"@blocksuite/block-std": "0.15.0-canary-202406121423-a4241b5",
|
||||
"@blocksuite/presets": "0.15.0-canary-202406121423-a4241b5",
|
||||
"@testing-library/react": "^16.0.0",
|
||||
"async-call-rpc": "^6.4.0",
|
||||
"react": "^18.2.0",
|
||||
|
||||
@@ -19,10 +19,18 @@ export class Doc extends Entity {
|
||||
readonly title$ = this.record.title$;
|
||||
|
||||
setMode(mode: DocMode) {
|
||||
this.record.setMode(mode);
|
||||
return this.record.setMode(mode);
|
||||
}
|
||||
|
||||
getMode() {
|
||||
return this.record.getMode();
|
||||
}
|
||||
|
||||
toggleMode() {
|
||||
this.record.toggleMode();
|
||||
return this.record.toggleMode();
|
||||
}
|
||||
|
||||
observeMode() {
|
||||
return this.record.observeMode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { map } from 'rxjs';
|
||||
import { Entity } from '../../../framework';
|
||||
import { LiveData } from '../../../livedata';
|
||||
import type { DocsStore } from '../stores/docs';
|
||||
import { DocRecord } from './record';
|
||||
import { type DocMode, DocRecord } from './record';
|
||||
|
||||
export class DocRecordList extends Entity {
|
||||
constructor(private readonly store: DocsStore) {
|
||||
@@ -37,4 +37,22 @@ export class DocRecordList extends Entity {
|
||||
public doc$(id: string) {
|
||||
return this.docs$.map(record => record.find(record => record.id === id));
|
||||
}
|
||||
|
||||
public setMode(id: string, mode: DocMode) {
|
||||
return this.store.setDocModeSetting(id, mode);
|
||||
}
|
||||
|
||||
public getMode(id: string) {
|
||||
return this.store.getDocModeSetting(id);
|
||||
}
|
||||
|
||||
public toggleMode(id: string) {
|
||||
const mode = this.getMode(id) === 'edgeless' ? 'page' : 'edgeless';
|
||||
this.setMode(id, mode);
|
||||
return this.getMode(id);
|
||||
}
|
||||
|
||||
public observeMode(id: string) {
|
||||
return this.store.watchDocModeSetting(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,12 +33,21 @@ export class DocRecord extends Entity<{ id: string }> {
|
||||
).map(mode => (mode === 'edgeless' ? 'edgeless' : 'page'));
|
||||
|
||||
setMode(mode: DocMode) {
|
||||
this.docsStore.setDocModeSetting(this.id, mode);
|
||||
return this.docsStore.setDocModeSetting(this.id, mode);
|
||||
}
|
||||
|
||||
getMode() {
|
||||
return this.docsStore.getDocModeSetting(this.id);
|
||||
}
|
||||
|
||||
toggleMode() {
|
||||
this.setMode(this.mode$.value === 'edgeless' ? 'page' : 'edgeless');
|
||||
return this.mode$.value;
|
||||
const mode = this.getMode() === 'edgeless' ? 'page' : 'edgeless';
|
||||
this.setMode(mode);
|
||||
return this.getMode();
|
||||
}
|
||||
|
||||
observeMode() {
|
||||
return this.docsStore.watchDocModeSetting(this.id);
|
||||
}
|
||||
|
||||
title$ = this.meta$.map(meta => meta.title ?? '');
|
||||
|
||||
@@ -76,7 +76,11 @@ export class DocsStore extends Store {
|
||||
}
|
||||
|
||||
setDocModeSetting(id: string, mode: DocMode) {
|
||||
this.localState.set(`page:${id}:mode`, mode);
|
||||
return this.localState.set(`page:${id}:mode`, mode);
|
||||
}
|
||||
|
||||
getDocModeSetting(id: string) {
|
||||
return this.localState.get<DocMode>(`page:${id}:mode`);
|
||||
}
|
||||
|
||||
watchDocModeSetting(id: string) {
|
||||
|
||||
Reference in New Issue
Block a user