refactor(editor): remove note block service (#11015)
This commit is contained in:
@@ -4,5 +4,4 @@ export * from './components/edgeless-note-background';
|
|||||||
export * from './config';
|
export * from './config';
|
||||||
export * from './note-block';
|
export * from './note-block';
|
||||||
export * from './note-edgeless-block';
|
export * from './note-edgeless-block';
|
||||||
export * from './note-service';
|
|
||||||
export * from './note-spec';
|
export * from './note-spec';
|
||||||
|
|||||||
@@ -2,12 +2,7 @@ import type { NoteBlockModel } from '@blocksuite/affine-model';
|
|||||||
import { BlockComponent } from '@blocksuite/block-std';
|
import { BlockComponent } from '@blocksuite/block-std';
|
||||||
import { css, html } from 'lit';
|
import { css, html } from 'lit';
|
||||||
|
|
||||||
import type { NoteBlockService } from './note-service.js';
|
export class NoteBlockComponent extends BlockComponent<NoteBlockModel> {
|
||||||
|
|
||||||
export class NoteBlockComponent extends BlockComponent<
|
|
||||||
NoteBlockModel,
|
|
||||||
NoteBlockService
|
|
||||||
> {
|
|
||||||
static override styles = css`
|
static override styles = css`
|
||||||
.affine-note-block-container {
|
.affine-note-block-container {
|
||||||
display: flow-root;
|
display: flow-root;
|
||||||
|
|||||||
@@ -14,18 +14,21 @@ import {
|
|||||||
getPrevBlockCommand,
|
getPrevBlockCommand,
|
||||||
getTextSelectionCommand,
|
getTextSelectionCommand,
|
||||||
} from '@blocksuite/affine-shared/commands';
|
} from '@blocksuite/affine-shared/commands';
|
||||||
import { matchModels } from '@blocksuite/affine-shared/utils';
|
import {
|
||||||
|
asyncGetBlockComponent,
|
||||||
|
matchModels,
|
||||||
|
} from '@blocksuite/affine-shared/utils';
|
||||||
import {
|
import {
|
||||||
type BlockComponent,
|
type BlockComponent,
|
||||||
BlockSelection,
|
BlockSelection,
|
||||||
BlockService,
|
|
||||||
type BlockStdScope,
|
type BlockStdScope,
|
||||||
type Chain,
|
type Chain,
|
||||||
|
KeymapExtension,
|
||||||
TextSelection,
|
TextSelection,
|
||||||
type UIEventHandler,
|
type UIEventHandler,
|
||||||
type UIEventStateContext,
|
type UIEventStateContext,
|
||||||
} from '@blocksuite/block-std';
|
} from '@blocksuite/block-std';
|
||||||
import type { BaseSelection, BlockModel } from '@blocksuite/store';
|
import type { BaseSelection } from '@blocksuite/store';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
dedentBlocks,
|
dedentBlocks,
|
||||||
@@ -38,8 +41,8 @@ import {
|
|||||||
import { moveBlockConfigs } from './move-block';
|
import { moveBlockConfigs } from './move-block';
|
||||||
import { quickActionConfig } from './quick-action';
|
import { quickActionConfig } from './quick-action';
|
||||||
|
|
||||||
export class NoteBlockService extends BlockService {
|
class NoteKeymap {
|
||||||
static override readonly flavour = NoteBlockSchema.model.flavour;
|
constructor(readonly std: BlockStdScope) {}
|
||||||
|
|
||||||
private _anchorSel: BlockSelection | null = null;
|
private _anchorSel: BlockSelection | null = null;
|
||||||
|
|
||||||
@@ -116,18 +119,23 @@ export class NoteBlockService extends BlockService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const [codeModel] = newModels;
|
const [codeModel] = newModels;
|
||||||
onModelElementUpdated(ctx.std, codeModel, codeElement => {
|
asyncGetBlockComponent(ctx.std.host, codeModel.id)
|
||||||
this._std.selection.setGroup('note', [
|
.then(codeElement => {
|
||||||
this._std.selection.create(TextSelection, {
|
if (!codeElement) {
|
||||||
from: {
|
return;
|
||||||
blockId: codeElement.blockId,
|
}
|
||||||
index: 0,
|
this._std.selection.setGroup('note', [
|
||||||
length: codeModel.text?.length ?? 0,
|
this._std.selection.create(TextSelection, {
|
||||||
},
|
from: {
|
||||||
to: null,
|
blockId: codeElement.blockId,
|
||||||
}),
|
index: 0,
|
||||||
]);
|
length: codeModel.text?.length ?? 0,
|
||||||
}).catch(console.error);
|
},
|
||||||
|
to: null,
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
})
|
||||||
|
.catch(console.error);
|
||||||
|
|
||||||
next();
|
next();
|
||||||
})
|
})
|
||||||
@@ -468,6 +476,7 @@ export class NoteBlockService extends BlockService {
|
|||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
selection.setGroup('note', [sel]);
|
selection.setGroup('note', [sel]);
|
||||||
|
this._reset();
|
||||||
|
|
||||||
return next();
|
return next();
|
||||||
})
|
})
|
||||||
@@ -554,17 +563,8 @@ export class NoteBlockService extends BlockService {
|
|||||||
return this.std;
|
return this.std;
|
||||||
}
|
}
|
||||||
|
|
||||||
override mounted() {
|
get hotKeys(): Record<string, UIEventHandler> {
|
||||||
super.mounted();
|
return {
|
||||||
this.handleEvent('keyDown', ctx => {
|
|
||||||
const state = ctx.get('keyboardState');
|
|
||||||
if (['Control', 'Meta', 'Shift'].includes(state.raw.key)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this._reset();
|
|
||||||
});
|
|
||||||
|
|
||||||
this.bindHotKey({
|
|
||||||
...this._bindMoveBlockHotKey(),
|
...this._bindMoveBlockHotKey(),
|
||||||
...this._bindQuickActionHotKey(),
|
...this._bindQuickActionHotKey(),
|
||||||
...this._bindTextConversionHotKey(),
|
...this._bindTextConversionHotKey(),
|
||||||
@@ -599,22 +599,13 @@ export class NoteBlockService extends BlockService {
|
|||||||
Escape: this._onEsc,
|
Escape: this._onEsc,
|
||||||
Enter: this._onEnter,
|
Enter: this._onEnter,
|
||||||
'Mod-a': this._onSelectAll,
|
'Mod-a': this._onSelectAll,
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onModelElementUpdated(
|
export const NoteKeymapExtension = KeymapExtension(
|
||||||
std: BlockStdScope,
|
std => new NoteKeymap(std).hotKeys,
|
||||||
model: BlockModel,
|
{
|
||||||
callback: (block: BlockComponent) => void
|
flavour: NoteBlockSchema.model.flavour,
|
||||||
) {
|
}
|
||||||
const page = model.doc;
|
);
|
||||||
if (!page.root) return;
|
|
||||||
|
|
||||||
const rootComponent = std.view.getBlock(page.root.id);
|
|
||||||
if (!rootComponent) return;
|
|
||||||
await rootComponent.updateComplete;
|
|
||||||
|
|
||||||
const element = std.view.getBlock(model.id);
|
|
||||||
if (element) callback(element);
|
|
||||||
}
|
|
||||||
@@ -9,23 +9,23 @@ import {
|
|||||||
} from './adapters/index';
|
} from './adapters/index';
|
||||||
import { NoteSlashMenuConfigExtension } from './configs/slash-menu';
|
import { NoteSlashMenuConfigExtension } from './configs/slash-menu';
|
||||||
import { createBuiltinToolbarConfigExtension } from './configs/toolbar';
|
import { createBuiltinToolbarConfigExtension } from './configs/toolbar';
|
||||||
import { NoteBlockService } from './note-service';
|
import { NoteKeymapExtension } from './note-keymap.js';
|
||||||
|
|
||||||
const flavour = NoteBlockSchema.model.flavour;
|
const flavour = NoteBlockSchema.model.flavour;
|
||||||
|
|
||||||
export const NoteBlockSpec: ExtensionType[] = [
|
export const NoteBlockSpec: ExtensionType[] = [
|
||||||
FlavourExtension(flavour),
|
FlavourExtension(flavour),
|
||||||
NoteBlockService,
|
|
||||||
BlockViewExtension(flavour, literal`affine-note`),
|
BlockViewExtension(flavour, literal`affine-note`),
|
||||||
DocNoteBlockAdapterExtensions,
|
DocNoteBlockAdapterExtensions,
|
||||||
NoteSlashMenuConfigExtension,
|
NoteSlashMenuConfigExtension,
|
||||||
|
NoteKeymapExtension,
|
||||||
].flat();
|
].flat();
|
||||||
|
|
||||||
export const EdgelessNoteBlockSpec: ExtensionType[] = [
|
export const EdgelessNoteBlockSpec: ExtensionType[] = [
|
||||||
FlavourExtension(flavour),
|
FlavourExtension(flavour),
|
||||||
NoteBlockService,
|
|
||||||
BlockViewExtension(flavour, literal`affine-edgeless-note`),
|
BlockViewExtension(flavour, literal`affine-edgeless-note`),
|
||||||
EdgelessNoteBlockAdapterExtensions,
|
EdgelessNoteBlockAdapterExtensions,
|
||||||
NoteSlashMenuConfigExtension,
|
NoteSlashMenuConfigExtension,
|
||||||
createBuiltinToolbarConfigExtension(flavour),
|
createBuiltinToolbarConfigExtension(flavour),
|
||||||
|
NoteKeymapExtension,
|
||||||
].flat();
|
].flat();
|
||||||
|
|||||||
Reference in New Issue
Block a user