mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-26 18:55:57 +08:00
refactor(editor): remove dependency of command global types (#9903)
Closes: [BS-2216](https://linear.app/affine-design/issue/BS-2216/remove-global-types-in-command)
This commit is contained in:
@@ -1,17 +1,11 @@
|
|||||||
import {
|
import { BlockViewExtension, FlavourExtension } from '@blocksuite/block-std';
|
||||||
BlockViewExtension,
|
|
||||||
CommandExtension,
|
|
||||||
FlavourExtension,
|
|
||||||
} from '@blocksuite/block-std';
|
|
||||||
import type { ExtensionType } from '@blocksuite/store';
|
import type { ExtensionType } from '@blocksuite/store';
|
||||||
import { literal } from 'lit/static-html.js';
|
import { literal } from 'lit/static-html.js';
|
||||||
|
|
||||||
import { BookmarkBlockAdapterExtensions } from './adapters/extension.js';
|
import { BookmarkBlockAdapterExtensions } from './adapters/extension.js';
|
||||||
import { commands } from './commands/index.js';
|
|
||||||
|
|
||||||
export const BookmarkBlockSpec: ExtensionType[] = [
|
export const BookmarkBlockSpec: ExtensionType[] = [
|
||||||
FlavourExtension('affine:bookmark'),
|
FlavourExtension('affine:bookmark'),
|
||||||
CommandExtension(commands),
|
|
||||||
BlockViewExtension('affine:bookmark', model => {
|
BlockViewExtension('affine:bookmark', model => {
|
||||||
return model.parent?.flavour === 'affine:surface'
|
return model.parent?.flavour === 'affine:surface'
|
||||||
? literal`affine-edgeless-bookmark`
|
? literal`affine-edgeless-bookmark`
|
||||||
|
|||||||
@@ -1,9 +1,2 @@
|
|||||||
import type { BlockCommands } from '@blocksuite/block-std';
|
export { insertBookmarkCommand } from './insert-bookmark.js';
|
||||||
|
export { insertLinkByQuickSearchCommand } from './insert-link-by-quick-search.js';
|
||||||
import { insertBookmarkCommand } from './insert-bookmark.js';
|
|
||||||
import { insertLinkByQuickSearchCommand } from './insert-link-by-quick-search.js';
|
|
||||||
|
|
||||||
export const commands: BlockCommands = {
|
|
||||||
insertBookmark: insertBookmarkCommand,
|
|
||||||
insertLinkByQuickSearch: insertLinkByQuickSearchCommand,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -5,11 +5,7 @@ import type { EmbedCardStyle } from '@blocksuite/affine-model';
|
|||||||
import { EmbedOptionProvider } from '@blocksuite/affine-shared/services';
|
import { EmbedOptionProvider } from '@blocksuite/affine-shared/services';
|
||||||
import type { Command } from '@blocksuite/block-std';
|
import type { Command } from '@blocksuite/block-std';
|
||||||
|
|
||||||
export const insertBookmarkCommand: Command<
|
export const insertBookmarkCommand: Command<{ url: string }> = (ctx, next) => {
|
||||||
never,
|
|
||||||
'insertedLinkType',
|
|
||||||
{ url: string }
|
|
||||||
> = (ctx, next) => {
|
|
||||||
const { url, std } = ctx;
|
const { url, std } = ctx;
|
||||||
const embedOptions = std.get(EmbedOptionProvider).getEmbedBlockOptions(url);
|
const embedOptions = std.get(EmbedOptionProvider).getEmbedBlockOptions(url);
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
import type { InsertedLinkType } from '@blocksuite/affine-block-embed';
|
import {
|
||||||
|
type InsertedLinkType,
|
||||||
|
insertEmbedLinkedDocCommand,
|
||||||
|
} from '@blocksuite/affine-block-embed';
|
||||||
import { QuickSearchProvider } from '@blocksuite/affine-shared/services';
|
import { QuickSearchProvider } from '@blocksuite/affine-shared/services';
|
||||||
import type { Command } from '@blocksuite/block-std';
|
import type { Command } from '@blocksuite/block-std';
|
||||||
|
|
||||||
|
import { insertBookmarkCommand } from './insert-bookmark';
|
||||||
|
|
||||||
export const insertLinkByQuickSearchCommand: Command<
|
export const insertLinkByQuickSearchCommand: Command<
|
||||||
never,
|
{},
|
||||||
'insertedLinkType'
|
{ insertedLinkType: Promise<InsertedLinkType> }
|
||||||
> = (ctx, next) => {
|
> = (ctx, next) => {
|
||||||
const { std } = ctx;
|
const { std } = ctx;
|
||||||
const quickSearchService = std.getOptional(QuickSearchProvider);
|
const quickSearchService = std.getOptional(QuickSearchProvider);
|
||||||
@@ -20,7 +25,7 @@ export const insertLinkByQuickSearchCommand: Command<
|
|||||||
|
|
||||||
// add linked doc
|
// add linked doc
|
||||||
if ('docId' in result) {
|
if ('docId' in result) {
|
||||||
std.command.exec('insertEmbedLinkedDoc', {
|
std.command.exec(insertEmbedLinkedDocCommand, {
|
||||||
docId: result.docId,
|
docId: result.docId,
|
||||||
params: result.params,
|
params: result.params,
|
||||||
});
|
});
|
||||||
@@ -31,7 +36,7 @@ export const insertLinkByQuickSearchCommand: Command<
|
|||||||
|
|
||||||
// add normal link;
|
// add normal link;
|
||||||
if ('externalUrl' in result) {
|
if ('externalUrl' in result) {
|
||||||
std.command.exec('insertBookmark', { url: result.externalUrl });
|
std.command.exec(insertBookmarkCommand, { url: result.externalUrl });
|
||||||
return {
|
return {
|
||||||
flavour: 'affine:bookmark',
|
flavour: 'affine:bookmark',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import { BookmarkBlockComponent } from './bookmark-block';
|
import { BookmarkBlockComponent } from './bookmark-block';
|
||||||
import { BookmarkEdgelessBlockComponent } from './bookmark-edgeless-block';
|
import { BookmarkEdgelessBlockComponent } from './bookmark-edgeless-block';
|
||||||
import type { insertBookmarkCommand } from './commands/insert-bookmark';
|
|
||||||
import type { insertLinkByQuickSearchCommand } from './commands/insert-link-by-quick-search';
|
|
||||||
import { BookmarkCard } from './components/bookmark-card';
|
import { BookmarkCard } from './components/bookmark-card';
|
||||||
import {
|
import {
|
||||||
EmbedCardCreateModal,
|
EmbedCardCreateModal,
|
||||||
@@ -24,12 +22,3 @@ export function effects() {
|
|||||||
EmbedCardEditCaptionEditModal
|
EmbedCardEditCaptionEditModal
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface Commands {
|
|
||||||
insertBookmark: typeof insertBookmarkCommand;
|
|
||||||
insertLinkByQuickSearch: typeof insertLinkByQuickSearchCommand;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
export * from './adapters';
|
export * from './adapters';
|
||||||
export * from './bookmark-block';
|
export * from './bookmark-block';
|
||||||
export * from './bookmark-spec';
|
export * from './bookmark-spec';
|
||||||
|
export * from './commands';
|
||||||
export * from './components';
|
export * from './components';
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
|
import { deleteTextCommand } from '@blocksuite/affine-components/rich-text';
|
||||||
import {
|
import {
|
||||||
HtmlAdapter,
|
HtmlAdapter,
|
||||||
pasteMiddleware,
|
pasteMiddleware,
|
||||||
PlainTextAdapter,
|
PlainTextAdapter,
|
||||||
} from '@blocksuite/affine-shared/adapters';
|
} from '@blocksuite/affine-shared/adapters';
|
||||||
|
import {
|
||||||
|
getBlockIndexCommand,
|
||||||
|
getBlockSelectionsCommand,
|
||||||
|
getTextSelectionCommand,
|
||||||
|
} from '@blocksuite/affine-shared/commands';
|
||||||
import {
|
import {
|
||||||
type BlockComponent,
|
type BlockComponent,
|
||||||
Clipboard,
|
Clipboard,
|
||||||
@@ -40,13 +46,13 @@ export class CodeClipboardController {
|
|||||||
this._std.command
|
this._std.command
|
||||||
.chain()
|
.chain()
|
||||||
.try(cmd => [
|
.try(cmd => [
|
||||||
cmd.getTextSelection().inline<'currentSelectionPath'>((ctx, next) => {
|
cmd.pipe(getTextSelectionCommand).pipe((ctx, next) => {
|
||||||
const textSelection = ctx.currentTextSelection;
|
const textSelection = ctx.currentTextSelection;
|
||||||
if (!textSelection) return;
|
if (!textSelection) return;
|
||||||
const end = textSelection.to ?? textSelection.from;
|
const end = textSelection.to ?? textSelection.from;
|
||||||
next({ currentSelectionPath: end.blockId });
|
next({ currentSelectionPath: end.blockId });
|
||||||
}),
|
}),
|
||||||
cmd.getBlockSelections().inline<'currentSelectionPath'>((ctx, next) => {
|
cmd.pipe(getBlockSelectionsCommand).pipe((ctx, next) => {
|
||||||
const currentBlockSelections = ctx.currentBlockSelections;
|
const currentBlockSelections = ctx.currentBlockSelections;
|
||||||
if (!currentBlockSelections) return;
|
if (!currentBlockSelections) return;
|
||||||
const blockSelection = currentBlockSelections.at(-1);
|
const blockSelection = currentBlockSelections.at(-1);
|
||||||
@@ -54,9 +60,9 @@ export class CodeClipboardController {
|
|||||||
next({ currentSelectionPath: blockSelection.blockId });
|
next({ currentSelectionPath: blockSelection.blockId });
|
||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
.getBlockIndex()
|
.pipe(getBlockIndexCommand)
|
||||||
.try(cmd => [cmd.getTextSelection().deleteText()])
|
.try(cmd => [cmd.pipe(getTextSelectionCommand).pipe(deleteTextCommand)])
|
||||||
.inline((ctx, next) => {
|
.pipe((ctx, next) => {
|
||||||
if (!ctx.parentBlock) {
|
if (!ctx.parentBlock) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { DatabaseBlockModel } from '@blocksuite/affine-model';
|
import type { DatabaseBlockModel } from '@blocksuite/affine-model';
|
||||||
import type { BlockCommands, Command } from '@blocksuite/block-std';
|
import type { Command } from '@blocksuite/block-std';
|
||||||
import type { BlockModel, Store } from '@blocksuite/store';
|
import type { BlockModel, Store } from '@blocksuite/store';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -8,12 +8,14 @@ import {
|
|||||||
} from './data-source';
|
} from './data-source';
|
||||||
|
|
||||||
export const insertDatabaseBlockCommand: Command<
|
export const insertDatabaseBlockCommand: Command<
|
||||||
'selectedModels',
|
|
||||||
'insertedDatabaseBlockId',
|
|
||||||
{
|
{
|
||||||
|
selectedModels?: BlockModel[];
|
||||||
viewType: string;
|
viewType: string;
|
||||||
place?: 'after' | 'before';
|
place?: 'after' | 'before';
|
||||||
removeEmptyLine?: boolean;
|
removeEmptyLine?: boolean;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
insertedDatabaseBlockId: string;
|
||||||
}
|
}
|
||||||
> = (ctx, next) => {
|
> = (ctx, next) => {
|
||||||
const { selectedModels, viewType, place, removeEmptyLine, std } = ctx;
|
const { selectedModels, viewType, place, removeEmptyLine, std } = ctx;
|
||||||
@@ -65,7 +67,3 @@ export const initDatabaseBlock = (
|
|||||||
doc.addBlock('affine:paragraph', {}, parent.id);
|
doc.addBlock('affine:paragraph', {}, parent.id);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const commands: BlockCommands = {
|
|
||||||
insertDatabaseBlock: insertDatabaseBlockCommand,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import type {
|
|||||||
ColumnUpdater,
|
ColumnUpdater,
|
||||||
DatabaseBlockModel,
|
DatabaseBlockModel,
|
||||||
} from '@blocksuite/affine-model';
|
} from '@blocksuite/affine-model';
|
||||||
|
import { getSelectedModelsCommand } from '@blocksuite/affine-shared/commands';
|
||||||
import { FeatureFlagService } from '@blocksuite/affine-shared/services';
|
import { FeatureFlagService } from '@blocksuite/affine-shared/services';
|
||||||
import {
|
import {
|
||||||
insertPositionToIndex,
|
insertPositionToIndex,
|
||||||
@@ -517,12 +518,9 @@ export const databaseViewInitTemplate = (
|
|||||||
datasource.viewManager.viewAdd(viewType);
|
datasource.viewManager.viewAdd(viewType);
|
||||||
};
|
};
|
||||||
export const convertToDatabase = (host: EditorHost, viewType: string) => {
|
export const convertToDatabase = (host: EditorHost, viewType: string) => {
|
||||||
const [_, ctx] = host.std.command
|
const [_, ctx] = host.std.command.exec(getSelectedModelsCommand, {
|
||||||
.chain()
|
types: ['block', 'text'],
|
||||||
.getSelectedModels({
|
});
|
||||||
types: ['block', 'text'],
|
|
||||||
})
|
|
||||||
.run();
|
|
||||||
const { selectedModels } = ctx;
|
const { selectedModels } = ctx;
|
||||||
const firstModel = selectedModels?.[0];
|
const firstModel = selectedModels?.[0];
|
||||||
if (!firstModel) return;
|
if (!firstModel) return;
|
||||||
|
|||||||
@@ -1,17 +1,11 @@
|
|||||||
import {
|
import { BlockViewExtension, FlavourExtension } from '@blocksuite/block-std';
|
||||||
BlockViewExtension,
|
|
||||||
CommandExtension,
|
|
||||||
FlavourExtension,
|
|
||||||
} from '@blocksuite/block-std';
|
|
||||||
import type { ExtensionType } from '@blocksuite/store';
|
import type { ExtensionType } from '@blocksuite/store';
|
||||||
import { literal } from 'lit/static-html.js';
|
import { literal } from 'lit/static-html.js';
|
||||||
|
|
||||||
import { DatabaseBlockAdapterExtensions } from './adapters/extension.js';
|
import { DatabaseBlockAdapterExtensions } from './adapters/extension.js';
|
||||||
import { commands } from './commands.js';
|
|
||||||
|
|
||||||
export const DatabaseBlockSpec: ExtensionType[] = [
|
export const DatabaseBlockSpec: ExtensionType[] = [
|
||||||
FlavourExtension('affine:database'),
|
FlavourExtension('affine:database'),
|
||||||
CommandExtension(commands),
|
|
||||||
BlockViewExtension('affine:database', literal`affine-database`),
|
BlockViewExtension('affine:database', literal`affine-database`),
|
||||||
DatabaseBlockAdapterExtensions,
|
DatabaseBlockAdapterExtensions,
|
||||||
].flat();
|
].flat();
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import type { insertDatabaseBlockCommand } from './commands';
|
|
||||||
import { CenterPeek } from './components/layout';
|
import { CenterPeek } from './components/layout';
|
||||||
import { DatabaseTitle } from './components/title';
|
import { DatabaseTitle } from './components/title';
|
||||||
import type { DatabaseOptionsConfig } from './config';
|
import type { DatabaseOptionsConfig } from './config';
|
||||||
@@ -44,20 +43,5 @@ declare global {
|
|||||||
interface BlockConfigs {
|
interface BlockConfigs {
|
||||||
'affine:database': Partial<DatabaseOptionsConfig>;
|
'affine:database': Partial<DatabaseOptionsConfig>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CommandContext {
|
|
||||||
insertedDatabaseBlockId?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Commands {
|
|
||||||
/**
|
|
||||||
* insert a database block after or before the current block selection
|
|
||||||
* @param latex the LaTeX content. A input dialog will be shown if not provided
|
|
||||||
* @param removeEmptyLine remove the current block if it is empty
|
|
||||||
* @param place where to insert the LaTeX block
|
|
||||||
* @returns the id of the inserted LaTeX block
|
|
||||||
*/
|
|
||||||
insertDatabaseBlock: typeof insertDatabaseBlockCommand;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
import type * as CommandType from '@blocksuite/affine-shared/commands';
|
|
||||||
|
|
||||||
declare type _GLOBAL_ = typeof CommandType;
|
|
||||||
|
|
||||||
export * from './adapters';
|
export * from './adapters';
|
||||||
|
export * from './commands';
|
||||||
export type { DatabaseOptionsConfig } from './config';
|
export type { DatabaseOptionsConfig } from './config';
|
||||||
export * from './data-source';
|
export * from './data-source';
|
||||||
export * from './database-block';
|
export * from './database-block';
|
||||||
|
|||||||
@@ -65,12 +65,4 @@ export class DatabaseSelection extends BaseSelection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface Selection {
|
|
||||||
database: typeof DatabaseSelection;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const DatabaseSelectionExtension = SelectionExtension(DatabaseSelection);
|
export const DatabaseSelectionExtension = SelectionExtension(DatabaseSelection);
|
||||||
|
|||||||
@@ -1,7 +1 @@
|
|||||||
import type { BlockCommands } from '@blocksuite/block-std';
|
export { insertEdgelessTextCommand } from './insert-edgeless-text.js';
|
||||||
|
|
||||||
import { insertEdgelessTextCommand } from './insert-edgeless-text.js';
|
|
||||||
|
|
||||||
export const commands: BlockCommands = {
|
|
||||||
insertEdgelessText: insertEdgelessTextCommand,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -14,11 +14,12 @@ import {
|
|||||||
} from '../edgeless-text-block.js';
|
} from '../edgeless-text-block.js';
|
||||||
|
|
||||||
export const insertEdgelessTextCommand: Command<
|
export const insertEdgelessTextCommand: Command<
|
||||||
never,
|
|
||||||
'textId',
|
|
||||||
{
|
{
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
textId: string;
|
||||||
}
|
}
|
||||||
> = (ctx, next) => {
|
> = (ctx, next) => {
|
||||||
const { std, x, y } = ctx;
|
const { std, x, y } = ctx;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { TextUtils } from '@blocksuite/affine-block-surface';
|
import { TextUtils } from '@blocksuite/affine-block-surface';
|
||||||
|
import { formatBlockCommand } from '@blocksuite/affine-components/rich-text';
|
||||||
import type { EdgelessTextBlockModel } from '@blocksuite/affine-model';
|
import type { EdgelessTextBlockModel } from '@blocksuite/affine-model';
|
||||||
import { ThemeProvider } from '@blocksuite/affine-shared/services';
|
import { ThemeProvider } from '@blocksuite/affine-shared/services';
|
||||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||||
@@ -98,21 +99,21 @@ export class EdgelessTextBlockComponent extends GfxBlockComponent<EdgelessTextBl
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (key === 'fontStyle') {
|
if (key === 'fontStyle') {
|
||||||
command.exec('formatBlock', {
|
command.exec(formatBlockCommand, {
|
||||||
blockSelections,
|
blockSelections,
|
||||||
styles: {
|
styles: {
|
||||||
italic: null,
|
italic: null,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else if (key === 'color') {
|
} else if (key === 'color') {
|
||||||
command.exec('formatBlock', {
|
command.exec(formatBlockCommand, {
|
||||||
blockSelections,
|
blockSelections,
|
||||||
styles: {
|
styles: {
|
||||||
color: null,
|
color: null,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else if (key === 'fontWeight') {
|
} else if (key === 'fontWeight') {
|
||||||
command.exec('formatBlock', {
|
command.exec(formatBlockCommand, {
|
||||||
blockSelections,
|
blockSelections,
|
||||||
styles: {
|
styles: {
|
||||||
bold: null,
|
bold: null,
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
import { BlockViewExtension, CommandExtension } from '@blocksuite/block-std';
|
import { BlockViewExtension } from '@blocksuite/block-std';
|
||||||
import type { ExtensionType } from '@blocksuite/store';
|
import type { ExtensionType } from '@blocksuite/store';
|
||||||
import { literal } from 'lit/static-html.js';
|
import { literal } from 'lit/static-html.js';
|
||||||
|
|
||||||
import { commands } from './commands/index.js';
|
|
||||||
|
|
||||||
export const EdgelessTextBlockSpec: ExtensionType[] = [
|
export const EdgelessTextBlockSpec: ExtensionType[] = [
|
||||||
CommandExtension(commands),
|
|
||||||
BlockViewExtension('affine:edgeless-text', literal`affine-edgeless-text`),
|
BlockViewExtension('affine:edgeless-text', literal`affine-edgeless-text`),
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,17 +1,5 @@
|
|||||||
import type { insertEdgelessTextCommand } from './commands/insert-edgeless-text';
|
|
||||||
import { EdgelessTextBlockComponent } from './edgeless-text-block';
|
import { EdgelessTextBlockComponent } from './edgeless-text-block';
|
||||||
|
|
||||||
export function effects() {
|
export function effects() {
|
||||||
customElements.define('affine-edgeless-text', EdgelessTextBlockComponent);
|
customElements.define('affine-edgeless-text', EdgelessTextBlockComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface CommandContext {
|
|
||||||
textId?: string;
|
|
||||||
}
|
|
||||||
interface Commands {
|
|
||||||
insertEdgelessText: typeof insertEdgelessTextCommand;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
import type * as CommandType from '@blocksuite/affine-shared/commands';
|
export * from './commands';
|
||||||
|
|
||||||
declare type _GLOBAL_ = typeof CommandType;
|
|
||||||
|
|
||||||
export * from './edgeless-text-block.js';
|
export * from './edgeless-text-block.js';
|
||||||
export * from './edgeless-text-spec.js';
|
export * from './edgeless-text-spec.js';
|
||||||
|
|||||||
@@ -12,10 +12,6 @@ import { EmbedHtmlBlockComponent } from './embed-html-block';
|
|||||||
import { EmbedHtmlFullscreenToolbar } from './embed-html-block/components/fullscreen-toolbar';
|
import { EmbedHtmlFullscreenToolbar } from './embed-html-block/components/fullscreen-toolbar';
|
||||||
import { EmbedEdgelessHtmlBlockComponent } from './embed-html-block/embed-edgeless-html-block';
|
import { EmbedEdgelessHtmlBlockComponent } from './embed-html-block/embed-edgeless-html-block';
|
||||||
import { EmbedLinkedDocBlockComponent } from './embed-linked-doc-block';
|
import { EmbedLinkedDocBlockComponent } from './embed-linked-doc-block';
|
||||||
import type {
|
|
||||||
InsertedLinkType,
|
|
||||||
insertEmbedLinkedDocCommand,
|
|
||||||
} from './embed-linked-doc-block/commands/insert-embed-linked-doc';
|
|
||||||
import { EmbedEdgelessLinkedDocBlockComponent } from './embed-linked-doc-block/embed-edgeless-linked-doc-block';
|
import { EmbedEdgelessLinkedDocBlockComponent } from './embed-linked-doc-block/embed-edgeless-linked-doc-block';
|
||||||
import {
|
import {
|
||||||
EmbedLoomBlockComponent,
|
EmbedLoomBlockComponent,
|
||||||
@@ -119,12 +115,5 @@ declare global {
|
|||||||
'affine:embed-loom': EmbedLoomBlockService;
|
'affine:embed-loom': EmbedLoomBlockService;
|
||||||
'affine:embed-youtube': EmbedYoutubeBlockService;
|
'affine:embed-youtube': EmbedYoutubeBlockService;
|
||||||
}
|
}
|
||||||
interface CommandContext {
|
|
||||||
insertedLinkType?: Promise<InsertedLinkType>;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Commands {
|
|
||||||
insertEmbedLinkedDoc: typeof insertEmbedLinkedDocCommand;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1 @@
|
|||||||
import type { BlockCommands } from '@blocksuite/block-std';
|
export * from './insert-embed-linked-doc';
|
||||||
|
|
||||||
import { insertEmbedLinkedDocCommand } from './insert-embed-linked-doc.js';
|
|
||||||
|
|
||||||
export const commands: BlockCommands = {
|
|
||||||
insertEmbedLinkedDoc: insertEmbedLinkedDocCommand,
|
|
||||||
};
|
|
||||||
|
|
||||||
export type { InsertedLinkType } from './insert-embed-linked-doc';
|
|
||||||
|
|||||||
@@ -7,14 +7,10 @@ export type InsertedLinkType = {
|
|||||||
flavour?: 'affine:bookmark' | 'affine:embed-linked-doc';
|
flavour?: 'affine:bookmark' | 'affine:embed-linked-doc';
|
||||||
} | null;
|
} | null;
|
||||||
|
|
||||||
export const insertEmbedLinkedDocCommand: Command<
|
export const insertEmbedLinkedDocCommand: Command<{
|
||||||
never,
|
docId: string;
|
||||||
'insertedLinkType',
|
params?: ReferenceParams;
|
||||||
{
|
}> = (ctx, next) => {
|
||||||
docId: string;
|
|
||||||
params?: ReferenceParams;
|
|
||||||
}
|
|
||||||
> = (ctx, next) => {
|
|
||||||
const { docId, params, std } = ctx;
|
const { docId, params, std } = ctx;
|
||||||
const flavour = 'affine:embed-linked-doc';
|
const flavour = 'affine:embed-linked-doc';
|
||||||
const targetStyle: EmbedCardStyle = 'vertical';
|
const targetStyle: EmbedCardStyle = 'vertical';
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import { EdgelessCRUDIdentifier } from '@blocksuite/affine-block-surface';
|
import {
|
||||||
|
EdgelessCRUDIdentifier,
|
||||||
|
reassociateConnectorsCommand,
|
||||||
|
} from '@blocksuite/affine-block-surface';
|
||||||
import {
|
import {
|
||||||
EMBED_CARD_HEIGHT,
|
EMBED_CARD_HEIGHT,
|
||||||
EMBED_CARD_WIDTH,
|
EMBED_CARD_WIDTH,
|
||||||
@@ -51,7 +54,7 @@ export class EmbedEdgelessLinkedDocBlockComponent extends toEdgelessEmbedBlock(
|
|||||||
surface
|
surface
|
||||||
);
|
);
|
||||||
|
|
||||||
this.std.command.exec('reassociateConnectors', {
|
this.std.command.exec(reassociateConnectorsCommand, {
|
||||||
oldId: id,
|
oldId: id,
|
||||||
newId,
|
newId,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
import { BlockViewExtension, CommandExtension } from '@blocksuite/block-std';
|
import { BlockViewExtension } from '@blocksuite/block-std';
|
||||||
import type { ExtensionType } from '@blocksuite/store';
|
import type { ExtensionType } from '@blocksuite/store';
|
||||||
import { literal } from 'lit/static-html.js';
|
import { literal } from 'lit/static-html.js';
|
||||||
|
|
||||||
import { EmbedLinkedDocBlockAdapterExtensions } from './adapters/extension.js';
|
import { EmbedLinkedDocBlockAdapterExtensions } from './adapters/extension.js';
|
||||||
import { commands } from './commands/index.js';
|
|
||||||
|
|
||||||
export const EmbedLinkedDocBlockSpec: ExtensionType[] = [
|
export const EmbedLinkedDocBlockSpec: ExtensionType[] = [
|
||||||
CommandExtension(commands),
|
|
||||||
BlockViewExtension('affine:embed-linked-doc', model => {
|
BlockViewExtension('affine:embed-linked-doc', model => {
|
||||||
return model.parent?.flavour === 'affine:surface'
|
return model.parent?.flavour === 'affine:surface'
|
||||||
? literal`affine-embed-edgeless-linked-doc-block`
|
? literal`affine-embed-edgeless-linked-doc-block`
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export * from './adapters';
|
export * from './adapters';
|
||||||
export type { InsertedLinkType } from './commands';
|
export * from './commands';
|
||||||
export * from './embed-linked-doc-block';
|
export * from './embed-linked-doc-block';
|
||||||
export * from './embed-linked-doc-spec';
|
export * from './embed-linked-doc-spec';
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import { EdgelessCRUDIdentifier } from '@blocksuite/affine-block-surface';
|
import {
|
||||||
|
EdgelessCRUDIdentifier,
|
||||||
|
reassociateConnectorsCommand,
|
||||||
|
} from '@blocksuite/affine-block-surface';
|
||||||
import type { AliasInfo } from '@blocksuite/affine-model';
|
import type { AliasInfo } from '@blocksuite/affine-model';
|
||||||
import {
|
import {
|
||||||
EMBED_CARD_HEIGHT,
|
EMBED_CARD_HEIGHT,
|
||||||
@@ -144,7 +147,7 @@ export class EmbedEdgelessSyncedDocBlockComponent extends toEdgelessEmbedBlock(
|
|||||||
surface
|
surface
|
||||||
);
|
);
|
||||||
|
|
||||||
this.std.command.exec('reassociateConnectors', {
|
this.std.command.exec(reassociateConnectorsCommand, {
|
||||||
oldId: id,
|
oldId: id,
|
||||||
newId,
|
newId,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
"author": "toeverything",
|
"author": "toeverything",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@blocksuite/affine-block-note": "workspace:*",
|
||||||
|
"@blocksuite/affine-block-surface": "workspace:*",
|
||||||
"@blocksuite/affine-components": "workspace:*",
|
"@blocksuite/affine-components": "workspace:*",
|
||||||
"@blocksuite/affine-model": "workspace:*",
|
"@blocksuite/affine-model": "workspace:*",
|
||||||
"@blocksuite/affine-shared": "workspace:*",
|
"@blocksuite/affine-shared": "workspace:*",
|
||||||
|
|||||||
@@ -1,9 +1 @@
|
|||||||
import { getImageSelectionsCommand } from '@blocksuite/affine-shared/commands';
|
export { insertImagesCommand } from './insert-images.js';
|
||||||
import type { BlockCommands } from '@blocksuite/block-std';
|
|
||||||
|
|
||||||
import { insertImagesCommand } from './insert-images.js';
|
|
||||||
|
|
||||||
export const commands: BlockCommands = {
|
|
||||||
getImageSelections: getImageSelectionsCommand,
|
|
||||||
insertImages: insertImagesCommand,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,12 +1,18 @@
|
|||||||
import { getImageFilesFromLocal } from '@blocksuite/affine-shared/utils';
|
import { getImageFilesFromLocal } from '@blocksuite/affine-shared/utils';
|
||||||
import type { Command } from '@blocksuite/block-std';
|
import type { Command } from '@blocksuite/block-std';
|
||||||
|
import type { BlockModel } from '@blocksuite/store';
|
||||||
|
|
||||||
import { addSiblingImageBlock } from '../utils.js';
|
import { addSiblingImageBlock } from '../utils.js';
|
||||||
|
|
||||||
export const insertImagesCommand: Command<
|
export const insertImagesCommand: Command<
|
||||||
'selectedModels',
|
{
|
||||||
'insertedImageIds',
|
selectedModels?: BlockModel[];
|
||||||
{ removeEmptyLine?: boolean; place?: 'after' | 'before' }
|
removeEmptyLine?: boolean;
|
||||||
|
place?: 'after' | 'before';
|
||||||
|
},
|
||||||
|
{
|
||||||
|
insertedImageIds: Promise<string[]>;
|
||||||
|
}
|
||||||
> = (ctx, next) => {
|
> = (ctx, next) => {
|
||||||
const { selectedModels, place, removeEmptyLine, std } = ctx;
|
const { selectedModels, place, removeEmptyLine, std } = ctx;
|
||||||
if (!selectedModels) return;
|
if (!selectedModels) return;
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
|
import { focusBlockEnd, focusBlockStart } from '@blocksuite/affine-block-note';
|
||||||
|
import {
|
||||||
|
getNextBlockCommand,
|
||||||
|
getPrevBlockCommand,
|
||||||
|
} from '@blocksuite/affine-shared/commands';
|
||||||
import { ImageSelection } from '@blocksuite/affine-shared/selection';
|
import { ImageSelection } from '@blocksuite/affine-shared/selection';
|
||||||
import type { UIEventStateContext } from '@blocksuite/block-std';
|
import type {
|
||||||
|
BlockComponent,
|
||||||
|
UIEventStateContext,
|
||||||
|
} from '@blocksuite/block-std';
|
||||||
import {
|
import {
|
||||||
BlockSelection,
|
BlockSelection,
|
||||||
ShadowlessElement,
|
ShadowlessElement,
|
||||||
@@ -136,15 +144,14 @@ export class ImageBlockPageComponent extends WithDisposable(ShadowlessElement) {
|
|||||||
|
|
||||||
std.command
|
std.command
|
||||||
.chain()
|
.chain()
|
||||||
.getNextBlock({ path: this.block.blockId })
|
.pipe(getNextBlockCommand, { path: this.block.blockId })
|
||||||
.inline((ctx, next) => {
|
.pipe<{ focusBlock: BlockComponent }>((ctx, next) => {
|
||||||
const { nextBlock } = ctx;
|
const { nextBlock } = ctx;
|
||||||
if (!nextBlock) return;
|
if (!nextBlock) return;
|
||||||
|
|
||||||
return next({ focusBlock: nextBlock });
|
return next({ focusBlock: nextBlock });
|
||||||
})
|
})
|
||||||
// @ts-expect-error FIXME(command): BS-2216
|
.pipe(focusBlockStart)
|
||||||
.focusBlockStart()
|
|
||||||
.run();
|
.run();
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
@@ -162,15 +169,14 @@ export class ImageBlockPageComponent extends WithDisposable(ShadowlessElement) {
|
|||||||
|
|
||||||
std.command
|
std.command
|
||||||
.chain()
|
.chain()
|
||||||
.getPrevBlock({ path: this.block.blockId })
|
.pipe(getPrevBlockCommand, { path: this.block.blockId })
|
||||||
.inline((ctx, next) => {
|
.pipe<{ focusBlock: BlockComponent }>((ctx, next) => {
|
||||||
const { prevBlock } = ctx;
|
const { prevBlock } = ctx;
|
||||||
if (!prevBlock) return;
|
if (!prevBlock) return;
|
||||||
|
|
||||||
return next({ focusBlock: prevBlock });
|
return next({ focusBlock: prevBlock });
|
||||||
})
|
})
|
||||||
// @ts-expect-error FIXME(command): BS-2216
|
.pipe(focusBlockEnd)
|
||||||
.focusBlockEnd()
|
|
||||||
.run();
|
.run();
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
import type { getImageSelectionsCommand } from '@blocksuite/affine-shared/commands';
|
|
||||||
|
|
||||||
import type { insertImagesCommand } from './commands/insert-images.js';
|
|
||||||
import { ImageBlockFallbackCard } from './components/image-block-fallback.js';
|
import { ImageBlockFallbackCard } from './components/image-block-fallback.js';
|
||||||
import { ImageBlockPageComponent } from './components/page-image-block.js';
|
import { ImageBlockPageComponent } from './components/page-image-block.js';
|
||||||
import { ImageBlockComponent } from './image-block.js';
|
import { ImageBlockComponent } from './image-block.js';
|
||||||
@@ -16,21 +13,6 @@ export function effects() {
|
|||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
namespace BlockSuite {
|
namespace BlockSuite {
|
||||||
interface CommandContext {
|
|
||||||
insertedImageIds?: Promise<string[]>;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Commands {
|
|
||||||
getImageSelections: typeof getImageSelectionsCommand;
|
|
||||||
/**
|
|
||||||
* open file dialog to insert images before or after the current block selection
|
|
||||||
* @param removeEmptyLine remove the current block if it is empty
|
|
||||||
* @param place where to insert the images
|
|
||||||
* @returns a promise that resolves to the inserted image ids
|
|
||||||
*/
|
|
||||||
insertImages: typeof insertImagesCommand;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface BlockServices {
|
interface BlockServices {
|
||||||
'affine:image': ImageBlockService;
|
'affine:image': ImageBlockService;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
BlockViewExtension,
|
BlockViewExtension,
|
||||||
CommandExtension,
|
|
||||||
FlavourExtension,
|
FlavourExtension,
|
||||||
WidgetViewMapExtension,
|
WidgetViewMapExtension,
|
||||||
} from '@blocksuite/block-std';
|
} from '@blocksuite/block-std';
|
||||||
@@ -8,13 +7,11 @@ import type { ExtensionType } from '@blocksuite/store';
|
|||||||
import { literal } from 'lit/static-html.js';
|
import { literal } from 'lit/static-html.js';
|
||||||
|
|
||||||
import { ImageBlockAdapterExtensions } from './adapters/extension.js';
|
import { ImageBlockAdapterExtensions } from './adapters/extension.js';
|
||||||
import { commands } from './commands/index.js';
|
|
||||||
import { ImageBlockService, ImageDropOption } from './image-service.js';
|
import { ImageBlockService, ImageDropOption } from './image-service.js';
|
||||||
|
|
||||||
export const ImageBlockSpec: ExtensionType[] = [
|
export const ImageBlockSpec: ExtensionType[] = [
|
||||||
FlavourExtension('affine:image'),
|
FlavourExtension('affine:image'),
|
||||||
ImageBlockService,
|
ImageBlockService,
|
||||||
CommandExtension(commands),
|
|
||||||
BlockViewExtension('affine:image', model => {
|
BlockViewExtension('affine:image', model => {
|
||||||
const parent = model.doc.getParent(model.id);
|
const parent = model.doc.getParent(model.id);
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import type * as SurfaceEffects from '@blocksuite/affine-block-surface/effects';
|
|||||||
declare type _GLOBAL_ = typeof SurfaceEffects;
|
declare type _GLOBAL_ = typeof SurfaceEffects;
|
||||||
|
|
||||||
export * from './adapters';
|
export * from './adapters';
|
||||||
|
export * from './commands';
|
||||||
export * from './image-block';
|
export * from './image-block';
|
||||||
export * from './image-edgeless-block';
|
export * from './image-edgeless-block';
|
||||||
export * from './image-service';
|
export * from './image-service';
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { autoResizeElementsCommand } from '@blocksuite/affine-block-surface';
|
||||||
import { toast } from '@blocksuite/affine-components/toast';
|
import { toast } from '@blocksuite/affine-components/toast';
|
||||||
import type {
|
import type {
|
||||||
AttachmentBlockProps,
|
AttachmentBlockProps,
|
||||||
@@ -516,7 +517,7 @@ export async function addImages(
|
|||||||
editing: false,
|
editing: false,
|
||||||
});
|
});
|
||||||
if (isMultipleFiles) {
|
if (isMultipleFiles) {
|
||||||
std.command.exec('autoResizeElements');
|
std.command.exec(autoResizeElementsCommand);
|
||||||
}
|
}
|
||||||
return blockIds;
|
return blockIds;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
},
|
},
|
||||||
"include": ["./src"],
|
"include": ["./src"],
|
||||||
"references": [
|
"references": [
|
||||||
|
{ "path": "../block-note" },
|
||||||
|
{ "path": "../block-surface" },
|
||||||
{ "path": "../components" },
|
{ "path": "../components" },
|
||||||
{ "path": "../model" },
|
{ "path": "../model" },
|
||||||
{ "path": "../shared" },
|
{ "path": "../shared" },
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
import type { LatexProps } from '@blocksuite/affine-model';
|
import type { LatexProps } from '@blocksuite/affine-model';
|
||||||
import type { BlockCommands, Command } from '@blocksuite/block-std';
|
import type { Command } from '@blocksuite/block-std';
|
||||||
import { assertInstanceOf } from '@blocksuite/global/utils';
|
import { assertInstanceOf } from '@blocksuite/global/utils';
|
||||||
|
import type { BlockModel } from '@blocksuite/store';
|
||||||
|
|
||||||
import { LatexBlockComponent } from './latex-block.js';
|
import { LatexBlockComponent } from './latex-block.js';
|
||||||
|
|
||||||
export const insertLatexBlockCommand: Command<
|
export const insertLatexBlockCommand: Command<
|
||||||
'selectedModels',
|
|
||||||
'insertedLatexBlockId',
|
|
||||||
{
|
{
|
||||||
latex?: string;
|
latex?: string;
|
||||||
place?: 'after' | 'before';
|
place?: 'after' | 'before';
|
||||||
removeEmptyLine?: boolean;
|
removeEmptyLine?: boolean;
|
||||||
|
selectedModels?: BlockModel[];
|
||||||
|
},
|
||||||
|
{
|
||||||
|
insertedLatexBlockId: Promise<string>;
|
||||||
}
|
}
|
||||||
> = (ctx, next) => {
|
> = (ctx, next) => {
|
||||||
const { selectedModels, latex, place, removeEmptyLine, std } = ctx;
|
const { selectedModels, latex, place, removeEmptyLine, std } = ctx;
|
||||||
@@ -51,7 +54,3 @@ export const insertLatexBlockCommand: Command<
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const commands: BlockCommands = {
|
|
||||||
insertLatexBlock: insertLatexBlockCommand,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,25 +1,5 @@
|
|||||||
import type { insertLatexBlockCommand } from './commands';
|
|
||||||
import { LatexBlockComponent } from './latex-block';
|
import { LatexBlockComponent } from './latex-block';
|
||||||
|
|
||||||
export function effects() {
|
export function effects() {
|
||||||
customElements.define('affine-latex', LatexBlockComponent);
|
customElements.define('affine-latex', LatexBlockComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface CommandContext {
|
|
||||||
insertedLatexBlockId?: Promise<string>;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Commands {
|
|
||||||
/**
|
|
||||||
* insert a LaTeX block after or before the current block selection
|
|
||||||
* @param latex the LaTeX content. A input dialog will be shown if not provided
|
|
||||||
* @param place where to insert the LaTeX block
|
|
||||||
* @param removeEmptyLine remove the current block if it is empty
|
|
||||||
* @returns the id of the inserted LaTeX block
|
|
||||||
*/
|
|
||||||
insertLatexBlock: typeof insertLatexBlockCommand;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
import type * as NoteType from '@blocksuite/affine-block-note/effects';
|
|
||||||
import type * as CommandsType from '@blocksuite/affine-shared/commands';
|
|
||||||
import type * as RemarkMathType from 'remark-math';
|
import type * as RemarkMathType from 'remark-math';
|
||||||
|
|
||||||
export * from './adapters';
|
export * from './adapters';
|
||||||
|
export * from './commands';
|
||||||
export * from './latex-block';
|
export * from './latex-block';
|
||||||
export * from './latex-spec';
|
export * from './latex-spec';
|
||||||
|
|
||||||
// Global types
|
// Global types
|
||||||
declare type _GLOBAl =
|
declare type _GLOBAl = typeof RemarkMathType;
|
||||||
| typeof NoteType
|
|
||||||
| typeof CommandsType
|
|
||||||
| typeof RemarkMathType;
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { selectBlock } from '@blocksuite/affine-block-note';
|
||||||
import { CaptionedBlockComponent } from '@blocksuite/affine-components/caption';
|
import { CaptionedBlockComponent } from '@blocksuite/affine-components/caption';
|
||||||
import { createLitPortal } from '@blocksuite/affine-components/portal';
|
import { createLitPortal } from '@blocksuite/affine-components/portal';
|
||||||
import type { LatexBlockModel } from '@blocksuite/affine-model';
|
import type { LatexBlockModel } from '@blocksuite/affine-model';
|
||||||
@@ -96,7 +97,7 @@ export class LatexBlockComponent extends CaptionedBlockComponent<LatexBlockModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
selectBlock() {
|
selectBlock() {
|
||||||
this.host.command.exec('selectBlock', {
|
this.host.command.exec(selectBlock, {
|
||||||
focusBlock: this,
|
focusBlock: this,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
import { BlockViewExtension, CommandExtension } from '@blocksuite/block-std';
|
import { BlockViewExtension } from '@blocksuite/block-std';
|
||||||
import type { ExtensionType } from '@blocksuite/store';
|
import type { ExtensionType } from '@blocksuite/store';
|
||||||
import { literal } from 'lit/static-html.js';
|
import { literal } from 'lit/static-html.js';
|
||||||
|
|
||||||
import { LatexBlockAdapterExtensions } from './adapters/extension.js';
|
import { LatexBlockAdapterExtensions } from './adapters/extension.js';
|
||||||
import { commands } from './commands.js';
|
|
||||||
|
|
||||||
export const LatexBlockSpec: ExtensionType[] = [
|
export const LatexBlockSpec: ExtensionType[] = [
|
||||||
BlockViewExtension('affine:latex', literal`affine-latex`),
|
BlockViewExtension('affine:latex', literal`affine-latex`),
|
||||||
CommandExtension(commands),
|
|
||||||
LatexBlockAdapterExtensions,
|
LatexBlockAdapterExtensions,
|
||||||
].flat();
|
].flat();
|
||||||
|
|||||||
@@ -2,12 +2,13 @@ import { toNumberedList } from '@blocksuite/affine-shared/utils';
|
|||||||
import type { Command, EditorHost } from '@blocksuite/block-std';
|
import type { Command, EditorHost } from '@blocksuite/block-std';
|
||||||
|
|
||||||
export const convertToNumberedListCommand: Command<
|
export const convertToNumberedListCommand: Command<
|
||||||
never,
|
|
||||||
'listConvertedId',
|
|
||||||
{
|
{
|
||||||
id: string;
|
id: string;
|
||||||
order: number; // This parameter may not correspond to the final order.
|
order: number; // This parameter may not correspond to the final order.
|
||||||
stopCapturing?: boolean;
|
stopCapturing?: boolean;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
listConvertedId: string;
|
||||||
}
|
}
|
||||||
> = (ctx, next) => {
|
> = (ctx, next) => {
|
||||||
const { std, id, order, stopCapturing = true } = ctx;
|
const { std, id, order, stopCapturing = true } = ctx;
|
||||||
|
|||||||
@@ -5,9 +5,10 @@ import { type Command, TextSelection } from '@blocksuite/block-std';
|
|||||||
import { correctNumberedListsOrderToPrev } from './utils.js';
|
import { correctNumberedListsOrderToPrev } from './utils.js';
|
||||||
|
|
||||||
export const canDedentListCommand: Command<
|
export const canDedentListCommand: Command<
|
||||||
never,
|
Partial<Omit<IndentContext, 'flavour' | 'type'>>,
|
||||||
'indentContext',
|
{
|
||||||
Partial<Omit<IndentContext, 'flavour' | 'type'>>
|
indentContext: IndentContext;
|
||||||
|
}
|
||||||
> = (ctx, next) => {
|
> = (ctx, next) => {
|
||||||
let { blockId, inlineIndex } = ctx;
|
let { blockId, inlineIndex } = ctx;
|
||||||
const { std } = ctx;
|
const { std } = ctx;
|
||||||
@@ -91,7 +92,9 @@ export const canDedentListCommand: Command<
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const dedentListCommand: Command<'indentContext'> = (ctx, next) => {
|
export const dedentListCommand: Command<{
|
||||||
|
indentContext: IndentContext;
|
||||||
|
}> = (ctx, next) => {
|
||||||
const { indentContext: dedentContext, std } = ctx;
|
const { indentContext: dedentContext, std } = ctx;
|
||||||
const { store, selection, range, host } = std;
|
const { store, selection, range, host } = std;
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,10 @@ import { type Command, TextSelection } from '@blocksuite/block-std';
|
|||||||
import { correctNumberedListsOrderToPrev } from './utils.js';
|
import { correctNumberedListsOrderToPrev } from './utils.js';
|
||||||
|
|
||||||
export const canIndentListCommand: Command<
|
export const canIndentListCommand: Command<
|
||||||
never,
|
Partial<Omit<IndentContext, 'type' | 'flavour'>>,
|
||||||
'indentContext',
|
{
|
||||||
Partial<Omit<IndentContext, 'type' | 'flavour'>>
|
indentContext: IndentContext;
|
||||||
|
}
|
||||||
> = (ctx, next) => {
|
> = (ctx, next) => {
|
||||||
let { blockId, inlineIndex } = ctx;
|
let { blockId, inlineIndex } = ctx;
|
||||||
const { std } = ctx;
|
const { std } = ctx;
|
||||||
@@ -84,10 +85,9 @@ export const canIndentListCommand: Command<
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const indentListCommand: Command<'indentContext', never> = (
|
export const indentListCommand: Command<{
|
||||||
ctx,
|
indentContext: IndentContext;
|
||||||
next
|
}> = (ctx, next) => {
|
||||||
) => {
|
|
||||||
const { indentContext, std } = ctx;
|
const { indentContext, std } = ctx;
|
||||||
if (
|
if (
|
||||||
!indentContext ||
|
!indentContext ||
|
||||||
|
|||||||
@@ -1,17 +1,5 @@
|
|||||||
import type { BlockCommands } from '@blocksuite/block-std';
|
export { convertToNumberedListCommand } from './convert-to-numbered-list.js';
|
||||||
|
export { canDedentListCommand, dedentListCommand } from './dedent-list.js';
|
||||||
import { convertToNumberedListCommand } from './convert-to-numbered-list.js';
|
export { canIndentListCommand, indentListCommand } from './indent-list.js';
|
||||||
import { canDedentListCommand, dedentListCommand } from './dedent-list.js';
|
export { listToParagraphCommand } from './list-to-paragraph.js';
|
||||||
import { canIndentListCommand, indentListCommand } from './indent-list.js';
|
export { splitListCommand } from './split-list.js';
|
||||||
import { listToParagraphCommand } from './list-to-paragraph.js';
|
|
||||||
import { splitListCommand } from './split-list.js';
|
|
||||||
|
|
||||||
export const commands: BlockCommands = {
|
|
||||||
convertToNumberedList: convertToNumberedListCommand,
|
|
||||||
listToParagraph: listToParagraphCommand,
|
|
||||||
splitList: splitListCommand,
|
|
||||||
canIndentList: canIndentListCommand,
|
|
||||||
indentList: indentListCommand,
|
|
||||||
canDedentList: canDedentListCommand,
|
|
||||||
dedentList: dedentListCommand,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
|||||||
import type { Command } from '@blocksuite/block-std';
|
import type { Command } from '@blocksuite/block-std';
|
||||||
|
|
||||||
export const listToParagraphCommand: Command<
|
export const listToParagraphCommand: Command<
|
||||||
never,
|
|
||||||
'listConvertedId',
|
|
||||||
{
|
{
|
||||||
id: string;
|
id: string;
|
||||||
stopCapturing?: boolean;
|
stopCapturing?: boolean;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
listConvertedId: string;
|
||||||
}
|
}
|
||||||
> = (ctx, next) => {
|
> = (ctx, next) => {
|
||||||
const { id, stopCapturing = true } = ctx;
|
const { id, stopCapturing = true } = ctx;
|
||||||
|
|||||||
@@ -5,16 +5,13 @@ import {
|
|||||||
} from '@blocksuite/affine-shared/utils';
|
} from '@blocksuite/affine-shared/utils';
|
||||||
import type { Command, EditorHost } from '@blocksuite/block-std';
|
import type { Command, EditorHost } from '@blocksuite/block-std';
|
||||||
|
|
||||||
|
import { canDedentListCommand, dedentListCommand } from './dedent-list.js';
|
||||||
import { correctNumberedListsOrderToPrev } from './utils.js';
|
import { correctNumberedListsOrderToPrev } from './utils.js';
|
||||||
|
|
||||||
export const splitListCommand: Command<
|
export const splitListCommand: Command<{
|
||||||
never,
|
blockId: string;
|
||||||
never,
|
inlineIndex: number;
|
||||||
{
|
}> = (ctx, next) => {
|
||||||
blockId: string;
|
|
||||||
inlineIndex: number;
|
|
||||||
}
|
|
||||||
> = (ctx, next) => {
|
|
||||||
const { blockId, inlineIndex, std } = ctx;
|
const { blockId, inlineIndex, std } = ctx;
|
||||||
const host = std.host as EditorHost;
|
const host = std.host as EditorHost;
|
||||||
const doc = host.doc;
|
const doc = host.doc;
|
||||||
@@ -100,11 +97,11 @@ export const splitListCommand: Command<
|
|||||||
if (parent.role === 'content') {
|
if (parent.role === 'content') {
|
||||||
host.command
|
host.command
|
||||||
.chain()
|
.chain()
|
||||||
.canDedentList({
|
.pipe(canDedentListCommand, {
|
||||||
blockId,
|
blockId,
|
||||||
inlineIndex: 0,
|
inlineIndex: 0,
|
||||||
})
|
})
|
||||||
.dedentList()
|
.pipe(dedentListCommand)
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
next();
|
next();
|
||||||
|
|||||||
@@ -1,16 +1,3 @@
|
|||||||
import type { IndentContext } from '@blocksuite/affine-shared/types';
|
|
||||||
|
|
||||||
import type { convertToNumberedListCommand } from './commands/convert-to-numbered-list.js';
|
|
||||||
import type {
|
|
||||||
canDedentListCommand,
|
|
||||||
dedentListCommand,
|
|
||||||
} from './commands/dedent-list.js';
|
|
||||||
import type {
|
|
||||||
canIndentListCommand,
|
|
||||||
indentListCommand,
|
|
||||||
} from './commands/indent-list.js';
|
|
||||||
import type { listToParagraphCommand } from './commands/list-to-paragraph.js';
|
|
||||||
import type { splitListCommand } from './commands/split-list.js';
|
|
||||||
import { ListBlockComponent } from './list-block.js';
|
import { ListBlockComponent } from './list-block.js';
|
||||||
|
|
||||||
export function effects() {
|
export function effects() {
|
||||||
@@ -18,23 +5,6 @@ export function effects() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
namespace BlockSuite {
|
|
||||||
interface CommandContext {
|
|
||||||
listConvertedId?: string;
|
|
||||||
indentContext?: IndentContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Commands {
|
|
||||||
convertToNumberedList: typeof convertToNumberedListCommand;
|
|
||||||
canDedentList: typeof canDedentListCommand;
|
|
||||||
canIndentList: typeof canIndentListCommand;
|
|
||||||
dedentList: typeof dedentListCommand;
|
|
||||||
indentList: typeof indentListCommand;
|
|
||||||
listToParagraph: typeof listToParagraphCommand;
|
|
||||||
splitList: typeof splitListCommand;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface HTMLElementTagNameMap {
|
interface HTMLElementTagNameMap {
|
||||||
'affine-list': ListBlockComponent;
|
'affine-list': ListBlockComponent;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
export * from './adapters/index.js';
|
export * from './adapters/index.js';
|
||||||
|
export * from './commands';
|
||||||
export { correctNumberedListsOrderToPrev } from './commands/utils';
|
export { correctNumberedListsOrderToPrev } from './commands/utils';
|
||||||
export * from './list-block.js';
|
export * from './list-block.js';
|
||||||
export * from './list-spec.js';
|
export * from './list-spec.js';
|
||||||
|
|||||||
@@ -3,9 +3,20 @@ import {
|
|||||||
textKeymap,
|
textKeymap,
|
||||||
} from '@blocksuite/affine-components/rich-text';
|
} from '@blocksuite/affine-components/rich-text';
|
||||||
import { ListBlockSchema } from '@blocksuite/affine-model';
|
import { ListBlockSchema } from '@blocksuite/affine-model';
|
||||||
|
import { getSelectedModelsCommand } from '@blocksuite/affine-shared/commands';
|
||||||
import { KeymapExtension, TextSelection } from '@blocksuite/block-std';
|
import { KeymapExtension, TextSelection } from '@blocksuite/block-std';
|
||||||
import { IS_MAC } from '@blocksuite/global/env';
|
import { IS_MAC } from '@blocksuite/global/env';
|
||||||
|
|
||||||
|
import {
|
||||||
|
canDedentListCommand,
|
||||||
|
dedentListCommand,
|
||||||
|
} from './commands/dedent-list.js';
|
||||||
|
import {
|
||||||
|
canIndentListCommand,
|
||||||
|
indentListCommand,
|
||||||
|
} from './commands/indent-list.js';
|
||||||
|
import { listToParagraphCommand } from './commands/list-to-paragraph.js';
|
||||||
|
import { splitListCommand } from './commands/split-list.js';
|
||||||
import { forwardDelete } from './utils/forward-delete.js';
|
import { forwardDelete } from './utils/forward-delete.js';
|
||||||
|
|
||||||
export const ListKeymapExtension = KeymapExtension(
|
export const ListKeymapExtension = KeymapExtension(
|
||||||
@@ -16,10 +27,13 @@ export const ListKeymapExtension = KeymapExtension(
|
|||||||
if (!text) return false;
|
if (!text) return false;
|
||||||
|
|
||||||
ctx.get('keyboardState').raw.preventDefault();
|
ctx.get('keyboardState').raw.preventDefault();
|
||||||
std.command.exec('splitList', {
|
std.command
|
||||||
blockId: text.from.blockId,
|
.chain()
|
||||||
inlineIndex: text.from.index,
|
.pipe(splitListCommand, {
|
||||||
});
|
blockId: text.from.blockId,
|
||||||
|
inlineIndex: text.from.index,
|
||||||
|
})
|
||||||
|
.run();
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
'Mod-Enter': ctx => {
|
'Mod-Enter': ctx => {
|
||||||
@@ -27,16 +41,22 @@ export const ListKeymapExtension = KeymapExtension(
|
|||||||
if (!text) return false;
|
if (!text) return false;
|
||||||
|
|
||||||
ctx.get('keyboardState').raw.preventDefault();
|
ctx.get('keyboardState').raw.preventDefault();
|
||||||
std.command.exec('splitList', {
|
std.command
|
||||||
blockId: text.from.blockId,
|
.chain()
|
||||||
inlineIndex: text.from.index,
|
.pipe(splitListCommand, {
|
||||||
});
|
blockId: text.from.blockId,
|
||||||
|
inlineIndex: text.from.index,
|
||||||
|
})
|
||||||
|
.run();
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
Tab: ctx => {
|
Tab: ctx => {
|
||||||
const { selectedModels } = std.command.exec('getSelectedModels', {
|
const [_, { selectedModels }] = std.command
|
||||||
types: ['text'],
|
.chain()
|
||||||
});
|
.pipe(getSelectedModelsCommand, {
|
||||||
|
types: ['text'],
|
||||||
|
})
|
||||||
|
.run();
|
||||||
if (selectedModels?.length !== 1) {
|
if (selectedModels?.length !== 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -46,18 +66,21 @@ export const ListKeymapExtension = KeymapExtension(
|
|||||||
ctx.get('keyboardState').raw.preventDefault();
|
ctx.get('keyboardState').raw.preventDefault();
|
||||||
std.command
|
std.command
|
||||||
.chain()
|
.chain()
|
||||||
.canIndentList({
|
.pipe(canIndentListCommand, {
|
||||||
blockId: text.from.blockId,
|
blockId: text.from.blockId,
|
||||||
inlineIndex: text.from.index,
|
inlineIndex: text.from.index,
|
||||||
})
|
})
|
||||||
.indentList()
|
.pipe(indentListCommand)
|
||||||
.run();
|
.run();
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
'Shift-Tab': ctx => {
|
'Shift-Tab': ctx => {
|
||||||
const { selectedModels } = std.command.exec('getSelectedModels', {
|
const [_, { selectedModels }] = std.command
|
||||||
types: ['text'],
|
.chain()
|
||||||
});
|
.pipe(getSelectedModelsCommand, {
|
||||||
|
types: ['text'],
|
||||||
|
})
|
||||||
|
.run();
|
||||||
if (selectedModels?.length !== 1) {
|
if (selectedModels?.length !== 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -67,11 +90,11 @@ export const ListKeymapExtension = KeymapExtension(
|
|||||||
ctx.get('keyboardState').raw.preventDefault();
|
ctx.get('keyboardState').raw.preventDefault();
|
||||||
std.command
|
std.command
|
||||||
.chain()
|
.chain()
|
||||||
.canDedentList({
|
.pipe(canDedentListCommand, {
|
||||||
blockId: text.from.blockId,
|
blockId: text.from.blockId,
|
||||||
inlineIndex: text.from.index,
|
inlineIndex: text.from.index,
|
||||||
})
|
})
|
||||||
.dedentList()
|
.pipe(dedentListCommand)
|
||||||
.run();
|
.run();
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
@@ -83,7 +106,12 @@ export const ListKeymapExtension = KeymapExtension(
|
|||||||
if (!isStart) return false;
|
if (!isStart) return false;
|
||||||
|
|
||||||
ctx.get('keyboardState').raw.preventDefault();
|
ctx.get('keyboardState').raw.preventDefault();
|
||||||
std.command.exec('listToParagraph', { id: text.from.blockId });
|
std.command
|
||||||
|
.chain()
|
||||||
|
.pipe(listToParagraphCommand, {
|
||||||
|
id: text.from.blockId,
|
||||||
|
})
|
||||||
|
.run();
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
'Control-d': ctx => {
|
'Control-d': ctx => {
|
||||||
|
|||||||
@@ -1,18 +1,12 @@
|
|||||||
import {
|
import { BlockViewExtension, FlavourExtension } from '@blocksuite/block-std';
|
||||||
BlockViewExtension,
|
|
||||||
CommandExtension,
|
|
||||||
FlavourExtension,
|
|
||||||
} from '@blocksuite/block-std';
|
|
||||||
import type { ExtensionType } from '@blocksuite/store';
|
import type { ExtensionType } from '@blocksuite/store';
|
||||||
import { literal } from 'lit/static-html.js';
|
import { literal } from 'lit/static-html.js';
|
||||||
|
|
||||||
import { ListBlockAdapterExtensions } from './adapters/extension.js';
|
import { ListBlockAdapterExtensions } from './adapters/extension.js';
|
||||||
import { commands } from './commands/index.js';
|
|
||||||
import { ListKeymapExtension, ListTextKeymapExtension } from './list-keymap.js';
|
import { ListKeymapExtension, ListTextKeymapExtension } from './list-keymap.js';
|
||||||
|
|
||||||
export const ListBlockSpec: ExtensionType[] = [
|
export const ListBlockSpec: ExtensionType[] = [
|
||||||
FlavourExtension('affine:list'),
|
FlavourExtension('affine:list'),
|
||||||
CommandExtension(commands),
|
|
||||||
BlockViewExtension('affine:list', literal`affine-list`),
|
BlockViewExtension('affine:list', literal`affine-list`),
|
||||||
ListKeymapExtension,
|
ListKeymapExtension,
|
||||||
ListTextKeymapExtension,
|
ListTextKeymapExtension,
|
||||||
|
|||||||
@@ -3,12 +3,18 @@ import {
|
|||||||
focusTextModel,
|
focusTextModel,
|
||||||
onModelTextUpdated,
|
onModelTextUpdated,
|
||||||
} from '@blocksuite/affine-components/rich-text';
|
} from '@blocksuite/affine-components/rich-text';
|
||||||
|
import {
|
||||||
|
getBlockSelectionsCommand,
|
||||||
|
getSelectedBlocksCommand,
|
||||||
|
getTextSelectionCommand,
|
||||||
|
} from '@blocksuite/affine-shared/commands';
|
||||||
import {
|
import {
|
||||||
matchFlavours,
|
matchFlavours,
|
||||||
mergeToCodeModel,
|
mergeToCodeModel,
|
||||||
transformModel,
|
transformModel,
|
||||||
} from '@blocksuite/affine-shared/utils';
|
} from '@blocksuite/affine-shared/utils';
|
||||||
import {
|
import {
|
||||||
|
type BlockComponent,
|
||||||
BlockSelection,
|
BlockSelection,
|
||||||
type Command,
|
type Command,
|
||||||
TextSelection,
|
TextSelection,
|
||||||
@@ -21,9 +27,12 @@ type UpdateBlockConfig = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const updateBlockType: Command<
|
export const updateBlockType: Command<
|
||||||
'selectedBlocks',
|
UpdateBlockConfig & {
|
||||||
'updatedBlocks',
|
selectedBlocks?: BlockComponent[];
|
||||||
UpdateBlockConfig
|
},
|
||||||
|
{
|
||||||
|
updatedBlocks: BlockModel[];
|
||||||
|
}
|
||||||
> = (ctx, next) => {
|
> = (ctx, next) => {
|
||||||
const { std, flavour, props } = ctx;
|
const { std, flavour, props } = ctx;
|
||||||
const host = std.host;
|
const host = std.host;
|
||||||
@@ -35,8 +44,11 @@ export const updateBlockType: Command<
|
|||||||
if (selectedBlocks == null) {
|
if (selectedBlocks == null) {
|
||||||
const [result, ctx] = std.command
|
const [result, ctx] = std.command
|
||||||
.chain()
|
.chain()
|
||||||
.tryAll(chain => [chain.getTextSelection(), chain.getBlockSelections()])
|
.tryAll(chain => [
|
||||||
.getSelectedBlocks({ types: ['text', 'block'] })
|
chain.pipe(getTextSelectionCommand),
|
||||||
|
chain.pipe(getBlockSelectionsCommand),
|
||||||
|
])
|
||||||
|
.pipe(getSelectedBlocksCommand, { types: ['text', 'block'] })
|
||||||
.run();
|
.run();
|
||||||
if (result) {
|
if (result) {
|
||||||
selectedBlocks = ctx.selectedBlocks;
|
selectedBlocks = ctx.selectedBlocks;
|
||||||
@@ -60,7 +72,10 @@ export const updateBlockType: Command<
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const mergeToCode: Command<never, 'updatedBlocks'> = (_, next) => {
|
const mergeToCode: Command<{}, { updatedBlocks: BlockModel[] }> = (
|
||||||
|
_,
|
||||||
|
next
|
||||||
|
) => {
|
||||||
if (flavour !== 'affine:code') return;
|
if (flavour !== 'affine:code') return;
|
||||||
const id = mergeToCodeModel(blockModels);
|
const id = mergeToCodeModel(blockModels);
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
@@ -72,7 +87,10 @@ export const updateBlockType: Command<
|
|||||||
}).catch(console.error);
|
}).catch(console.error);
|
||||||
return next({ updatedBlocks: [model] });
|
return next({ updatedBlocks: [model] });
|
||||||
};
|
};
|
||||||
const appendDivider: Command<never, 'updatedBlocks'> = (_, next) => {
|
const appendDivider: Command<{}, { updatedBlocks: BlockModel[] }> = (
|
||||||
|
_,
|
||||||
|
next
|
||||||
|
) => {
|
||||||
if (flavour !== 'affine:divider') {
|
if (flavour !== 'affine:divider') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -99,7 +117,7 @@ export const updateBlockType: Command<
|
|||||||
return next({ updatedBlocks: [newModel] });
|
return next({ updatedBlocks: [newModel] });
|
||||||
};
|
};
|
||||||
|
|
||||||
const focusText: Command<'updatedBlocks'> = (ctx, next) => {
|
const focusText: Command<{ updatedBlocks: BlockModel[] }> = (ctx, next) => {
|
||||||
const { updatedBlocks } = ctx;
|
const { updatedBlocks } = ctx;
|
||||||
if (!updatedBlocks || updatedBlocks.length === 0) {
|
if (!updatedBlocks || updatedBlocks.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
@@ -139,7 +157,7 @@ export const updateBlockType: Command<
|
|||||||
return next();
|
return next();
|
||||||
};
|
};
|
||||||
|
|
||||||
const focusBlock: Command<'updatedBlocks'> = (ctx, next) => {
|
const focusBlock: Command<{ updatedBlocks: BlockModel[] }> = (ctx, next) => {
|
||||||
const { updatedBlocks } = ctx;
|
const { updatedBlocks } = ctx;
|
||||||
if (!updatedBlocks || updatedBlocks.length === 0) {
|
if (!updatedBlocks || updatedBlocks.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
@@ -165,15 +183,15 @@ export const updateBlockType: Command<
|
|||||||
|
|
||||||
const [result, resultCtx] = std.command
|
const [result, resultCtx] = std.command
|
||||||
.chain()
|
.chain()
|
||||||
.inline((_, next) => {
|
.pipe((_, next) => {
|
||||||
doc.captureSync();
|
doc.captureSync();
|
||||||
return next();
|
return next();
|
||||||
})
|
})
|
||||||
// update block type
|
// update block type
|
||||||
.try<'updatedBlocks'>(chain => [
|
.try<{ updatedBlocks: BlockModel[] }>(chain => [
|
||||||
chain.inline<'updatedBlocks'>(mergeToCode),
|
chain.pipe(mergeToCode),
|
||||||
chain.inline<'updatedBlocks'>(appendDivider),
|
chain.pipe(appendDivider),
|
||||||
chain.inline<'updatedBlocks'>((_, next) => {
|
chain.pipe((_, next) => {
|
||||||
const newModels: BlockModel[] = [];
|
const newModels: BlockModel[] = [];
|
||||||
blockModels.forEach(model => {
|
blockModels.forEach(model => {
|
||||||
if (
|
if (
|
||||||
@@ -204,15 +222,15 @@ export const updateBlockType: Command<
|
|||||||
])
|
])
|
||||||
// focus
|
// focus
|
||||||
.try(chain => [
|
.try(chain => [
|
||||||
chain.inline((_, next) => {
|
chain.pipe((_, next) => {
|
||||||
if (['affine:code', 'affine:divider'].includes(flavour)) {
|
if (['affine:code', 'affine:divider'].includes(flavour)) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}),
|
}),
|
||||||
chain.inline(focusText),
|
chain.pipe(focusText),
|
||||||
chain.inline(focusBlock),
|
chain.pipe(focusBlock),
|
||||||
chain.inline((_, next) => next()),
|
chain.pipe((_, next) => next()),
|
||||||
])
|
])
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ import { NoteDisplayMode } from '@blocksuite/affine-model';
|
|||||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||||
import type { Command } from '@blocksuite/block-std';
|
import type { Command } from '@blocksuite/block-std';
|
||||||
|
|
||||||
export const changeNoteDisplayMode: Command<
|
export const changeNoteDisplayMode: Command<{
|
||||||
never,
|
noteId: string;
|
||||||
never,
|
mode: NoteDisplayMode;
|
||||||
{ noteId: string; mode: NoteDisplayMode; stopCapture?: boolean }
|
stopCapture?: boolean;
|
||||||
> = (ctx, next) => {
|
}> = (ctx, next) => {
|
||||||
const { std, noteId, mode, stopCapture } = ctx;
|
const { std, noteId, mode, stopCapture } = ctx;
|
||||||
|
|
||||||
const noteBlockModel = std.store.getBlock(noteId)?.model;
|
const noteBlockModel = std.store.getBlock(noteId)?.model;
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||||
import type { Command } from '@blocksuite/block-std';
|
import type { Command } from '@blocksuite/block-std';
|
||||||
|
|
||||||
export const dedentBlockToRoot: Command<
|
import { dedentBlock } from './dedent-block';
|
||||||
never,
|
|
||||||
never,
|
export const dedentBlockToRoot: Command<{
|
||||||
{
|
blockId?: string;
|
||||||
blockId?: string;
|
stopCapture?: boolean;
|
||||||
stopCapture?: boolean;
|
}> = (ctx, next) => {
|
||||||
}
|
|
||||||
> = (ctx, next) => {
|
|
||||||
let { blockId } = ctx;
|
let { blockId } = ctx;
|
||||||
const { std, stopCapture = true } = ctx;
|
const { std, stopCapture = true } = ctx;
|
||||||
const { store } = std;
|
const { store } = std;
|
||||||
@@ -27,7 +25,7 @@ export const dedentBlockToRoot: Command<
|
|||||||
if (stopCapture) store.captureSync();
|
if (stopCapture) store.captureSync();
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
std.command.exec('dedentBlock', { blockId: model.id, stopCapture: true });
|
std.command.exec(dedentBlock, { blockId: model.id, stopCapture: true });
|
||||||
parent = store.getParent(model);
|
parent = store.getParent(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,14 +20,10 @@ import type { Command } from '@blocksuite/block-std';
|
|||||||
* - ddd
|
* - ddd
|
||||||
* - eee
|
* - eee
|
||||||
*/
|
*/
|
||||||
export const dedentBlock: Command<
|
export const dedentBlock: Command<{
|
||||||
never,
|
blockId?: string;
|
||||||
never,
|
stopCapture?: boolean;
|
||||||
{
|
}> = (ctx, next) => {
|
||||||
blockId?: string;
|
|
||||||
stopCapture?: boolean;
|
|
||||||
}
|
|
||||||
> = (ctx, next) => {
|
|
||||||
let { blockId } = ctx;
|
let { blockId } = ctx;
|
||||||
const { std, stopCapture = true } = ctx;
|
const { std, stopCapture = true } = ctx;
|
||||||
const { store } = std;
|
const { store } = std;
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||||
import { type Command, TextSelection } from '@blocksuite/block-std';
|
import { type Command, TextSelection } from '@blocksuite/block-std';
|
||||||
|
|
||||||
export const dedentBlocksToRoot: Command<
|
import { dedentBlockToRoot } from './dedent-block-to-root';
|
||||||
never,
|
|
||||||
never,
|
export const dedentBlocksToRoot: Command<{
|
||||||
{
|
blockIds?: string[];
|
||||||
blockIds?: string[];
|
stopCapture?: boolean;
|
||||||
stopCapture?: boolean;
|
}> = (ctx, next) => {
|
||||||
}
|
|
||||||
> = (ctx, next) => {
|
|
||||||
let { blockIds } = ctx;
|
let { blockIds } = ctx;
|
||||||
const { std, stopCapture = true } = ctx;
|
const { std, stopCapture = true } = ctx;
|
||||||
const { store } = std;
|
const { store } = std;
|
||||||
@@ -33,7 +31,7 @@ export const dedentBlocksToRoot: Command<
|
|||||||
const model = blockIds[i];
|
const model = blockIds[i];
|
||||||
const parent = store.getParent(model);
|
const parent = store.getParent(model);
|
||||||
if (parent && !matchFlavours(parent, ['affine:note'])) {
|
if (parent && !matchFlavours(parent, ['affine:note'])) {
|
||||||
std.command.exec('dedentBlockToRoot', {
|
std.command.exec(dedentBlockToRoot, {
|
||||||
blockId: model,
|
blockId: model,
|
||||||
stopCapture: false,
|
stopCapture: false,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,14 +4,12 @@ import {
|
|||||||
} from '@blocksuite/affine-shared/utils';
|
} from '@blocksuite/affine-shared/utils';
|
||||||
import { type Command, TextSelection } from '@blocksuite/block-std';
|
import { type Command, TextSelection } from '@blocksuite/block-std';
|
||||||
|
|
||||||
export const dedentBlocks: Command<
|
import { dedentBlock } from './dedent-block';
|
||||||
never,
|
|
||||||
never,
|
export const dedentBlocks: Command<{
|
||||||
{
|
blockIds?: string[];
|
||||||
blockIds?: string[];
|
stopCapture?: boolean;
|
||||||
stopCapture?: boolean;
|
}> = (ctx, next) => {
|
||||||
}
|
|
||||||
> = (ctx, next) => {
|
|
||||||
let { blockIds } = ctx;
|
let { blockIds } = ctx;
|
||||||
const { std, stopCapture = true } = ctx;
|
const { std, stopCapture = true } = ctx;
|
||||||
const { store, selection, range, host } = std;
|
const { store, selection, range, host } = std;
|
||||||
@@ -72,7 +70,7 @@ export const dedentBlocks: Command<
|
|||||||
.slice(firstDedentIndex)
|
.slice(firstDedentIndex)
|
||||||
.filter(id => !collapsedIds.includes(id));
|
.filter(id => !collapsedIds.includes(id));
|
||||||
dedentIds.reverse().forEach(id => {
|
dedentIds.reverse().forEach(id => {
|
||||||
std.command.exec('dedentBlock', { blockId: id, stopCapture: false });
|
std.command.exec(dedentBlock, { blockId: id, stopCapture: false });
|
||||||
});
|
});
|
||||||
|
|
||||||
const textSelection = selection.find(TextSelection);
|
const textSelection = selection.find(TextSelection);
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
import { type Command, TextSelection } from '@blocksuite/block-std';
|
import {
|
||||||
|
type BlockComponent,
|
||||||
|
type Command,
|
||||||
|
TextSelection,
|
||||||
|
} from '@blocksuite/block-std';
|
||||||
|
|
||||||
export const focusBlockEnd: Command<'focusBlock'> = (ctx, next) => {
|
export const focusBlockEnd: Command<{
|
||||||
|
focusBlock?: BlockComponent;
|
||||||
|
}> = (ctx, next) => {
|
||||||
const { focusBlock, std } = ctx;
|
const { focusBlock, std } = ctx;
|
||||||
if (!focusBlock || !focusBlock.model.text) return;
|
if (!focusBlock || !focusBlock.model.text) return;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
import { type Command, TextSelection } from '@blocksuite/block-std';
|
import {
|
||||||
|
type BlockComponent,
|
||||||
|
type Command,
|
||||||
|
TextSelection,
|
||||||
|
} from '@blocksuite/block-std';
|
||||||
|
|
||||||
export const focusBlockStart: Command<'focusBlock'> = (ctx, next) => {
|
export const focusBlockStart: Command<{
|
||||||
|
focusBlock?: BlockComponent;
|
||||||
|
}> = (ctx, next) => {
|
||||||
const { focusBlock, std } = ctx;
|
const { focusBlock, std } = ctx;
|
||||||
if (!focusBlock || !focusBlock.model.text) return;
|
if (!focusBlock || !focusBlock.model.text) return;
|
||||||
|
|
||||||
|
|||||||
@@ -21,14 +21,10 @@ import type { Command } from '@blocksuite/block-std';
|
|||||||
* - ddd
|
* - ddd
|
||||||
* - eee
|
* - eee
|
||||||
*/
|
*/
|
||||||
export const indentBlock: Command<
|
export const indentBlock: Command<{
|
||||||
never,
|
blockId?: string;
|
||||||
never,
|
stopCapture?: boolean;
|
||||||
{
|
}> = (ctx, next) => {
|
||||||
blockId?: string;
|
|
||||||
stopCapture?: boolean;
|
|
||||||
}
|
|
||||||
> = (ctx, next) => {
|
|
||||||
let { blockId } = ctx;
|
let { blockId } = ctx;
|
||||||
const { std, stopCapture = true } = ctx;
|
const { std, stopCapture = true } = ctx;
|
||||||
const { store } = std;
|
const { store } = std;
|
||||||
|
|||||||
@@ -5,14 +5,12 @@ import {
|
|||||||
} from '@blocksuite/affine-shared/utils';
|
} from '@blocksuite/affine-shared/utils';
|
||||||
import { type Command, TextSelection } from '@blocksuite/block-std';
|
import { type Command, TextSelection } from '@blocksuite/block-std';
|
||||||
|
|
||||||
export const indentBlocks: Command<
|
import { indentBlock } from './indent-block';
|
||||||
never,
|
|
||||||
never,
|
export const indentBlocks: Command<{
|
||||||
{
|
blockIds?: string[];
|
||||||
blockIds?: string[];
|
stopCapture?: boolean;
|
||||||
stopCapture?: boolean;
|
}> = (ctx, next) => {
|
||||||
}
|
|
||||||
> = (ctx, next) => {
|
|
||||||
let { blockIds } = ctx;
|
let { blockIds } = ctx;
|
||||||
const { std, stopCapture = true } = ctx;
|
const { std, stopCapture = true } = ctx;
|
||||||
const { store, selection, range, host } = std;
|
const { store, selection, range, host } = std;
|
||||||
@@ -95,7 +93,7 @@ export const indentBlocks: Command<
|
|||||||
}
|
}
|
||||||
|
|
||||||
indentIds.forEach(id => {
|
indentIds.forEach(id => {
|
||||||
std.command.exec('indentBlock', { blockId: id, stopCapture: false });
|
std.command.exec(indentBlock, { blockId: id, stopCapture: false });
|
||||||
});
|
});
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,42 +1,12 @@
|
|||||||
import {
|
export { updateBlockType } from './block-type.js';
|
||||||
getBlockIndexCommand,
|
export { changeNoteDisplayMode } from './change-note-display-mode.js';
|
||||||
getBlockSelectionsCommand,
|
export { dedentBlock } from './dedent-block.js';
|
||||||
getNextBlockCommand,
|
export { dedentBlockToRoot } from './dedent-block-to-root.js';
|
||||||
getPrevBlockCommand,
|
export { dedentBlocks } from './dedent-blocks.js';
|
||||||
getSelectedBlocksCommand,
|
export { dedentBlocksToRoot } from './dedent-blocks-to-root.js';
|
||||||
} from '@blocksuite/affine-shared/commands';
|
export { focusBlockEnd } from './focus-block-end.js';
|
||||||
import type { BlockCommands } from '@blocksuite/block-std';
|
export { focusBlockStart } from './focus-block-start.js';
|
||||||
|
export { indentBlock } from './indent-block.js';
|
||||||
import { updateBlockType } from './block-type.js';
|
export { indentBlocks } from './indent-blocks.js';
|
||||||
import { changeNoteDisplayMode } from './change-note-display-mode.js';
|
export { selectBlock } from './select-block.js';
|
||||||
import { dedentBlock } from './dedent-block.js';
|
export { selectBlocksBetween } from './select-blocks-between.js';
|
||||||
import { dedentBlockToRoot } from './dedent-block-to-root.js';
|
|
||||||
import { dedentBlocks } from './dedent-blocks.js';
|
|
||||||
import { dedentBlocksToRoot } from './dedent-blocks-to-root.js';
|
|
||||||
import { focusBlockEnd } from './focus-block-end.js';
|
|
||||||
import { focusBlockStart } from './focus-block-start.js';
|
|
||||||
import { indentBlock } from './indent-block.js';
|
|
||||||
import { indentBlocks } from './indent-blocks.js';
|
|
||||||
import { selectBlock } from './select-block.js';
|
|
||||||
import { selectBlocksBetween } from './select-blocks-between.js';
|
|
||||||
|
|
||||||
export const commands: BlockCommands = {
|
|
||||||
// block
|
|
||||||
getBlockIndex: getBlockIndexCommand,
|
|
||||||
getPrevBlock: getPrevBlockCommand,
|
|
||||||
getNextBlock: getNextBlockCommand,
|
|
||||||
getSelectedBlocks: getSelectedBlocksCommand,
|
|
||||||
getBlockSelections: getBlockSelectionsCommand,
|
|
||||||
selectBlock,
|
|
||||||
selectBlocksBetween,
|
|
||||||
focusBlockStart,
|
|
||||||
focusBlockEnd,
|
|
||||||
updateBlockType,
|
|
||||||
indentBlock,
|
|
||||||
dedentBlock,
|
|
||||||
indentBlocks,
|
|
||||||
dedentBlocks,
|
|
||||||
dedentBlockToRoot,
|
|
||||||
dedentBlocksToRoot,
|
|
||||||
changeNoteDisplayMode,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
import { BlockSelection, type Command } from '@blocksuite/block-std';
|
import {
|
||||||
|
type BlockComponent,
|
||||||
|
BlockSelection,
|
||||||
|
type Command,
|
||||||
|
} from '@blocksuite/block-std';
|
||||||
|
|
||||||
export const selectBlock: Command<'focusBlock'> = (ctx, next) => {
|
export const selectBlock: Command<{
|
||||||
|
focusBlock?: BlockComponent;
|
||||||
|
}> = (ctx, next) => {
|
||||||
const { focusBlock, std } = ctx;
|
const { focusBlock, std } = ctx;
|
||||||
if (!focusBlock) {
|
if (!focusBlock) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
import { BlockSelection, type Command } from '@blocksuite/block-std';
|
import {
|
||||||
|
type BlockComponent,
|
||||||
|
BlockSelection,
|
||||||
|
type Command,
|
||||||
|
} from '@blocksuite/block-std';
|
||||||
|
|
||||||
export const selectBlocksBetween: Command<
|
export const selectBlocksBetween: Command<{
|
||||||
'focusBlock' | 'anchorBlock',
|
focusBlock?: BlockComponent;
|
||||||
never,
|
anchorBlock?: BlockComponent;
|
||||||
{ tail: boolean }
|
tail: boolean;
|
||||||
> = (ctx, next) => {
|
}> = (ctx, next) => {
|
||||||
const { focusBlock, anchorBlock, tail } = ctx;
|
const { focusBlock, anchorBlock, tail } = ctx;
|
||||||
if (!focusBlock || !anchorBlock) {
|
if (!focusBlock || !anchorBlock) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,18 +1,3 @@
|
|||||||
import type { BlockComponent } from '@blocksuite/block-std';
|
|
||||||
import type { BlockModel } from '@blocksuite/store';
|
|
||||||
|
|
||||||
import type { updateBlockType } from './commands/block-type';
|
|
||||||
import type { changeNoteDisplayMode } from './commands/change-note-display-mode';
|
|
||||||
import type { dedentBlock } from './commands/dedent-block';
|
|
||||||
import type { dedentBlockToRoot } from './commands/dedent-block-to-root';
|
|
||||||
import type { dedentBlocks } from './commands/dedent-blocks';
|
|
||||||
import type { dedentBlocksToRoot } from './commands/dedent-blocks-to-root';
|
|
||||||
import type { focusBlockEnd } from './commands/focus-block-end';
|
|
||||||
import type { focusBlockStart } from './commands/focus-block-start';
|
|
||||||
import type { indentBlock } from './commands/indent-block';
|
|
||||||
import type { indentBlocks } from './commands/indent-blocks';
|
|
||||||
import type { selectBlock } from './commands/select-block';
|
|
||||||
import type { selectBlocksBetween } from './commands/select-blocks-between';
|
|
||||||
import type { NoteConfig } from './config';
|
import type { NoteConfig } from './config';
|
||||||
import { NoteBlockComponent } from './note-block';
|
import { NoteBlockComponent } from './note-block';
|
||||||
import {
|
import {
|
||||||
@@ -29,25 +14,6 @@ export function effects() {
|
|||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
namespace BlockSuite {
|
namespace BlockSuite {
|
||||||
interface Commands {
|
|
||||||
selectBlock: typeof selectBlock;
|
|
||||||
selectBlocksBetween: typeof selectBlocksBetween;
|
|
||||||
focusBlockStart: typeof focusBlockStart;
|
|
||||||
focusBlockEnd: typeof focusBlockEnd;
|
|
||||||
indentBlocks: typeof indentBlocks;
|
|
||||||
dedentBlock: typeof dedentBlock;
|
|
||||||
dedentBlocksToRoot: typeof dedentBlocksToRoot;
|
|
||||||
dedentBlocks: typeof dedentBlocks;
|
|
||||||
indentBlock: typeof indentBlock;
|
|
||||||
updateBlockType: typeof updateBlockType;
|
|
||||||
dedentBlockToRoot: typeof dedentBlockToRoot;
|
|
||||||
changeNoteDisplayMode: typeof changeNoteDisplayMode;
|
|
||||||
}
|
|
||||||
interface CommandContext {
|
|
||||||
focusBlock?: BlockComponent | null;
|
|
||||||
anchorBlock?: BlockComponent | null;
|
|
||||||
updatedBlocks?: BlockModel[];
|
|
||||||
}
|
|
||||||
interface BlockServices {
|
interface BlockServices {
|
||||||
'affine:note': NoteBlockService;
|
'affine:note': NoteBlockService;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,34 @@
|
|||||||
import { textConversionConfigs } from '@blocksuite/affine-components/rich-text';
|
import { textConversionConfigs } from '@blocksuite/affine-components/rich-text';
|
||||||
import { NoteBlockSchema } from '@blocksuite/affine-model';
|
import { NoteBlockSchema } from '@blocksuite/affine-model';
|
||||||
|
import {
|
||||||
|
getBlockSelectionsCommand,
|
||||||
|
getNextBlockCommand,
|
||||||
|
getPrevBlockCommand,
|
||||||
|
getTextSelectionCommand,
|
||||||
|
} from '@blocksuite/affine-shared/commands';
|
||||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||||
import {
|
import {
|
||||||
type BlockComponent,
|
type BlockComponent,
|
||||||
BlockSelection,
|
BlockSelection,
|
||||||
BlockService,
|
BlockService,
|
||||||
type BlockStdScope,
|
type BlockStdScope,
|
||||||
|
type Chain,
|
||||||
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, BlockModel } from '@blocksuite/store';
|
||||||
|
|
||||||
|
import {
|
||||||
|
dedentBlocks,
|
||||||
|
dedentBlocksToRoot,
|
||||||
|
focusBlockEnd,
|
||||||
|
focusBlockStart,
|
||||||
|
indentBlocks,
|
||||||
|
selectBlock,
|
||||||
|
selectBlocksBetween,
|
||||||
|
updateBlockType,
|
||||||
|
} from './commands';
|
||||||
import { moveBlockConfigs } from './move-block';
|
import { moveBlockConfigs } from './move-block';
|
||||||
import { quickActionConfig } from './quick-action';
|
import { quickActionConfig } from './quick-action';
|
||||||
|
|
||||||
@@ -76,13 +93,13 @@ export class NoteBlockService extends BlockService {
|
|||||||
ctx.get('defaultState').event.preventDefault();
|
ctx.get('defaultState').event.preventDefault();
|
||||||
const [result] = this._std.command
|
const [result] = this._std.command
|
||||||
.chain()
|
.chain()
|
||||||
.updateBlockType({
|
.pipe(updateBlockType, {
|
||||||
flavour: item.flavour,
|
flavour: item.flavour,
|
||||||
props: {
|
props: {
|
||||||
type: item.type,
|
type: item.type,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.inline((ctx, next) => {
|
.pipe((ctx, next) => {
|
||||||
const newModels = ctx.updatedBlocks;
|
const newModels = ctx.updatedBlocks;
|
||||||
if (!newModels) {
|
if (!newModels) {
|
||||||
return;
|
return;
|
||||||
@@ -145,7 +162,7 @@ export class NoteBlockService extends BlockService {
|
|||||||
|
|
||||||
const [result] = this._std.command
|
const [result] = this._std.command
|
||||||
.chain()
|
.chain()
|
||||||
.inline((_, next) => {
|
.pipe((_, next) => {
|
||||||
this._reset();
|
this._reset();
|
||||||
return next();
|
return next();
|
||||||
})
|
})
|
||||||
@@ -154,16 +171,16 @@ export class NoteBlockService extends BlockService {
|
|||||||
// 1. is paragraph, list, code block - follow the default behavior
|
// 1. is paragraph, list, code block - follow the default behavior
|
||||||
// 2. is not - select the next block (use block selection instead of text selection)
|
// 2. is not - select the next block (use block selection instead of text selection)
|
||||||
cmd
|
cmd
|
||||||
.getTextSelection()
|
.pipe(getTextSelectionCommand)
|
||||||
.inline<'currentSelectionPath'>((ctx, next) => {
|
.pipe<{ currentSelectionPath: string }>((ctx, next) => {
|
||||||
const currentTextSelection = ctx.currentTextSelection;
|
const currentTextSelection = ctx.currentTextSelection;
|
||||||
if (!currentTextSelection) {
|
if (!currentTextSelection) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return next({ currentSelectionPath: currentTextSelection.blockId });
|
return next({ currentSelectionPath: currentTextSelection.blockId });
|
||||||
})
|
})
|
||||||
.getNextBlock()
|
.pipe(getNextBlockCommand)
|
||||||
.inline((ctx, next) => {
|
.pipe((ctx, next) => {
|
||||||
const { nextBlock } = ctx;
|
const { nextBlock } = ctx;
|
||||||
|
|
||||||
if (!nextBlock) {
|
if (!nextBlock) {
|
||||||
@@ -177,13 +194,9 @@ export class NoteBlockService extends BlockService {
|
|||||||
'affine:code',
|
'affine:code',
|
||||||
])
|
])
|
||||||
) {
|
) {
|
||||||
this._std.command
|
this._std.command.exec(selectBlock, {
|
||||||
.chain()
|
focusBlock: nextBlock,
|
||||||
.with({
|
});
|
||||||
focusBlock: nextBlock,
|
|
||||||
})
|
|
||||||
.selectBlock()
|
|
||||||
.run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return next({});
|
return next({});
|
||||||
@@ -193,8 +206,8 @@ export class NoteBlockService extends BlockService {
|
|||||||
// 1. is paragraph, list, code block - focus it
|
// 1. is paragraph, list, code block - focus it
|
||||||
// 2. is not - select it using block selection
|
// 2. is not - select it using block selection
|
||||||
cmd
|
cmd
|
||||||
.getBlockSelections()
|
.pipe(getBlockSelectionsCommand)
|
||||||
.inline<'currentSelectionPath'>((ctx, next) => {
|
.pipe<{ currentSelectionPath: string }>((ctx, next) => {
|
||||||
const currentBlockSelections = ctx.currentBlockSelections;
|
const currentBlockSelections = ctx.currentBlockSelections;
|
||||||
const blockSelection = currentBlockSelections?.at(-1);
|
const blockSelection = currentBlockSelections?.at(-1);
|
||||||
if (!blockSelection) {
|
if (!blockSelection) {
|
||||||
@@ -202,8 +215,8 @@ export class NoteBlockService extends BlockService {
|
|||||||
}
|
}
|
||||||
return next({ currentSelectionPath: blockSelection.blockId });
|
return next({ currentSelectionPath: blockSelection.blockId });
|
||||||
})
|
})
|
||||||
.getNextBlock()
|
.pipe(getNextBlockCommand)
|
||||||
.inline<'focusBlock'>((ctx, next) => {
|
.pipe<{ focusBlock: BlockComponent }>((ctx, next) => {
|
||||||
const { nextBlock } = ctx;
|
const { nextBlock } = ctx;
|
||||||
if (!nextBlock) {
|
if (!nextBlock) {
|
||||||
return;
|
return;
|
||||||
@@ -217,18 +230,15 @@ export class NoteBlockService extends BlockService {
|
|||||||
'affine:code',
|
'affine:code',
|
||||||
])
|
])
|
||||||
) {
|
) {
|
||||||
this._std.command
|
this._std.command.exec(focusBlockStart, {
|
||||||
.chain()
|
focusBlock: nextBlock,
|
||||||
.focusBlockStart({ focusBlock: nextBlock })
|
});
|
||||||
.run();
|
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
this._std.command
|
this._std.command.exec(selectBlock, {
|
||||||
.chain()
|
focusBlock: nextBlock,
|
||||||
.with({ focusBlock: nextBlock })
|
});
|
||||||
.selectBlock()
|
|
||||||
.run();
|
|
||||||
return next();
|
return next();
|
||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
@@ -242,7 +252,7 @@ export class NoteBlockService extends BlockService {
|
|||||||
|
|
||||||
const [result] = this._std.command
|
const [result] = this._std.command
|
||||||
.chain()
|
.chain()
|
||||||
.inline((_, next) => {
|
.pipe((_, next) => {
|
||||||
this._reset();
|
this._reset();
|
||||||
return next();
|
return next();
|
||||||
})
|
})
|
||||||
@@ -251,16 +261,16 @@ export class NoteBlockService extends BlockService {
|
|||||||
// 1. is paragraph, list, code block - follow the default behavior
|
// 1. is paragraph, list, code block - follow the default behavior
|
||||||
// 2. is not - select the previous block (use block selection instead of text selection)
|
// 2. is not - select the previous block (use block selection instead of text selection)
|
||||||
cmd
|
cmd
|
||||||
.getTextSelection()
|
.pipe(getTextSelectionCommand)
|
||||||
.inline<'currentSelectionPath'>((ctx, next) => {
|
.pipe<{ currentSelectionPath: string }>((ctx, next) => {
|
||||||
const currentTextSelection = ctx.currentTextSelection;
|
const currentTextSelection = ctx.currentTextSelection;
|
||||||
if (!currentTextSelection) {
|
if (!currentTextSelection) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return next({ currentSelectionPath: currentTextSelection.blockId });
|
return next({ currentSelectionPath: currentTextSelection.blockId });
|
||||||
})
|
})
|
||||||
.getPrevBlock()
|
.pipe(getPrevBlockCommand)
|
||||||
.inline((ctx, next) => {
|
.pipe((ctx, next) => {
|
||||||
const { prevBlock } = ctx;
|
const { prevBlock } = ctx;
|
||||||
|
|
||||||
if (!prevBlock) {
|
if (!prevBlock) {
|
||||||
@@ -274,23 +284,19 @@ export class NoteBlockService extends BlockService {
|
|||||||
'affine:code',
|
'affine:code',
|
||||||
])
|
])
|
||||||
) {
|
) {
|
||||||
this._std.command
|
this._std.command.exec(selectBlock, {
|
||||||
.chain()
|
focusBlock: prevBlock,
|
||||||
.with({
|
});
|
||||||
focusBlock: prevBlock,
|
|
||||||
})
|
|
||||||
.selectBlock()
|
|
||||||
.run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return next({});
|
return next();
|
||||||
}),
|
}),
|
||||||
// block selection - select the previous block
|
// block selection - select the previous block
|
||||||
// 1. is paragraph, list, code block - focus it
|
// 1. is paragraph, list, code block - focus it
|
||||||
// 2. is not - select it using block selection
|
// 2. is not - select it using block selection
|
||||||
cmd
|
cmd
|
||||||
.getBlockSelections()
|
.pipe(getBlockSelectionsCommand)
|
||||||
.inline<'currentSelectionPath'>((ctx, next) => {
|
.pipe<{ currentSelectionPath: string }>((ctx, next) => {
|
||||||
const currentBlockSelections = ctx.currentBlockSelections;
|
const currentBlockSelections = ctx.currentBlockSelections;
|
||||||
const blockSelection = currentBlockSelections?.at(-1);
|
const blockSelection = currentBlockSelections?.at(-1);
|
||||||
if (!blockSelection) {
|
if (!blockSelection) {
|
||||||
@@ -298,8 +304,8 @@ export class NoteBlockService extends BlockService {
|
|||||||
}
|
}
|
||||||
return next({ currentSelectionPath: blockSelection.blockId });
|
return next({ currentSelectionPath: blockSelection.blockId });
|
||||||
})
|
})
|
||||||
.getPrevBlock()
|
.pipe(getPrevBlockCommand)
|
||||||
.inline<'focusBlock'>((ctx, next) => {
|
.pipe((ctx, next) => {
|
||||||
const { prevBlock } = ctx;
|
const { prevBlock } = ctx;
|
||||||
if (!prevBlock) {
|
if (!prevBlock) {
|
||||||
return;
|
return;
|
||||||
@@ -313,18 +319,15 @@ export class NoteBlockService extends BlockService {
|
|||||||
])
|
])
|
||||||
) {
|
) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this._std.command
|
this._std.command.exec(focusBlockEnd, {
|
||||||
.chain()
|
focusBlock: prevBlock,
|
||||||
.focusBlockEnd({ focusBlock: prevBlock })
|
});
|
||||||
.run();
|
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
this._std.command
|
this._std.command.exec(selectBlock, {
|
||||||
.chain()
|
focusBlock: prevBlock,
|
||||||
.with({ focusBlock: prevBlock })
|
});
|
||||||
.selectBlock()
|
|
||||||
.run();
|
|
||||||
return next();
|
return next();
|
||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
@@ -333,34 +336,36 @@ export class NoteBlockService extends BlockService {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly _onBlockShiftDown = (cmd: BlockSuite.CommandChain) => {
|
private readonly _onBlockShiftDown = (cmd: Chain) => {
|
||||||
return cmd
|
return cmd
|
||||||
.getBlockSelections()
|
.pipe(getBlockSelectionsCommand)
|
||||||
.inline<'currentSelectionPath' | 'anchorBlock'>((ctx, next) => {
|
.pipe<{ currentSelectionPath: string; anchorBlock: BlockComponent }>(
|
||||||
const blockSelections = ctx.currentBlockSelections;
|
(ctx, next) => {
|
||||||
if (!blockSelections) {
|
const blockSelections = ctx.currentBlockSelections;
|
||||||
return;
|
if (!blockSelections) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this._anchorSel) {
|
if (!this._anchorSel) {
|
||||||
this._anchorSel = blockSelections.at(-1) ?? null;
|
this._anchorSel = blockSelections.at(-1) ?? null;
|
||||||
}
|
}
|
||||||
if (!this._anchorSel) {
|
if (!this._anchorSel) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const anchorBlock = ctx.std.view.getBlock(this._anchorSel.blockId);
|
const anchorBlock = ctx.std.view.getBlock(this._anchorSel.blockId);
|
||||||
if (!anchorBlock) {
|
if (!anchorBlock) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
return next({
|
||||||
|
anchorBlock,
|
||||||
|
currentSelectionPath:
|
||||||
|
this._focusBlock?.blockId ?? anchorBlock?.blockId,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return next({
|
)
|
||||||
anchorBlock,
|
.pipe(getNextBlockCommand)
|
||||||
currentSelectionPath:
|
.pipe<{ focusBlock: BlockComponent }>((ctx, next) => {
|
||||||
this._focusBlock?.blockId ?? anchorBlock?.blockId,
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.getNextBlock({})
|
|
||||||
.inline<'focusBlock'>((ctx, next) => {
|
|
||||||
const nextBlock = ctx.nextBlock;
|
const nextBlock = ctx.nextBlock;
|
||||||
if (!nextBlock) {
|
if (!nextBlock) {
|
||||||
return;
|
return;
|
||||||
@@ -370,35 +375,37 @@ export class NoteBlockService extends BlockService {
|
|||||||
focusBlock: this._focusBlock,
|
focusBlock: this._focusBlock,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.selectBlocksBetween({ tail: true });
|
.pipe(selectBlocksBetween, { tail: true });
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly _onBlockShiftUp = (cmd: BlockSuite.CommandChain) => {
|
private readonly _onBlockShiftUp = (cmd: Chain) => {
|
||||||
return cmd
|
return cmd
|
||||||
.getBlockSelections()
|
.pipe(getBlockSelectionsCommand)
|
||||||
.inline<'currentSelectionPath' | 'anchorBlock'>((ctx, next) => {
|
.pipe<{ currentSelectionPath: string; anchorBlock: BlockComponent }>(
|
||||||
const blockSelections = ctx.currentBlockSelections;
|
(ctx, next) => {
|
||||||
if (!blockSelections) {
|
const blockSelections = ctx.currentBlockSelections;
|
||||||
return;
|
if (!blockSelections) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!this._anchorSel) {
|
||||||
|
this._anchorSel = blockSelections.at(0) ?? null;
|
||||||
|
}
|
||||||
|
if (!this._anchorSel) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const anchorBlock = ctx.std.view.getBlock(this._anchorSel.blockId);
|
||||||
|
if (!anchorBlock) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return next({
|
||||||
|
anchorBlock,
|
||||||
|
currentSelectionPath:
|
||||||
|
this._focusBlock?.blockId ?? anchorBlock?.blockId,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (!this._anchorSel) {
|
)
|
||||||
this._anchorSel = blockSelections.at(0) ?? null;
|
.pipe(getPrevBlockCommand)
|
||||||
}
|
.pipe((ctx, next) => {
|
||||||
if (!this._anchorSel) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const anchorBlock = ctx.std.view.getBlock(this._anchorSel.blockId);
|
|
||||||
if (!anchorBlock) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return next({
|
|
||||||
anchorBlock,
|
|
||||||
currentSelectionPath:
|
|
||||||
this._focusBlock?.blockId ?? anchorBlock?.blockId,
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.getPrevBlock({})
|
|
||||||
.inline((ctx, next) => {
|
|
||||||
const prevBlock = ctx.prevBlock;
|
const prevBlock = ctx.prevBlock;
|
||||||
if (!prevBlock) {
|
if (!prevBlock) {
|
||||||
return;
|
return;
|
||||||
@@ -408,15 +415,15 @@ export class NoteBlockService extends BlockService {
|
|||||||
focusBlock: this._focusBlock,
|
focusBlock: this._focusBlock,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.selectBlocksBetween({ tail: false });
|
.pipe(selectBlocksBetween, { tail: false });
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly _onEnter = (ctx: UIEventStateContext) => {
|
private readonly _onEnter = (ctx: UIEventStateContext) => {
|
||||||
const event = ctx.get('defaultState').event;
|
const event = ctx.get('defaultState').event;
|
||||||
const [result] = this._std.command
|
const [result] = this._std.command
|
||||||
.chain()
|
.chain()
|
||||||
.getBlockSelections()
|
.pipe(getBlockSelectionsCommand)
|
||||||
.inline((ctx, next) => {
|
.pipe((ctx, next) => {
|
||||||
const blockSelection = ctx.currentBlockSelections?.at(-1);
|
const blockSelection = ctx.currentBlockSelections?.at(-1);
|
||||||
if (!blockSelection) {
|
if (!blockSelection) {
|
||||||
return;
|
return;
|
||||||
@@ -466,8 +473,8 @@ export class NoteBlockService extends BlockService {
|
|||||||
private readonly _onEsc = () => {
|
private readonly _onEsc = () => {
|
||||||
const [result] = this._std.command
|
const [result] = this._std.command
|
||||||
.chain()
|
.chain()
|
||||||
.getBlockSelections()
|
.pipe(getBlockSelectionsCommand)
|
||||||
.inline((ctx, next) => {
|
.pipe((ctx, next) => {
|
||||||
const blockSelection = ctx.currentBlockSelections?.at(-1);
|
const blockSelection = ctx.currentBlockSelections?.at(-1);
|
||||||
if (!blockSelection) {
|
if (!blockSelection) {
|
||||||
return;
|
return;
|
||||||
@@ -556,7 +563,7 @@ export class NoteBlockService extends BlockService {
|
|||||||
...this._bindQuickActionHotKey(),
|
...this._bindQuickActionHotKey(),
|
||||||
...this._bindTextConversionHotKey(),
|
...this._bindTextConversionHotKey(),
|
||||||
Tab: ctx => {
|
Tab: ctx => {
|
||||||
const { success } = this.std.command.exec('indentBlocks');
|
const [success] = this.std.command.exec(indentBlocks);
|
||||||
|
|
||||||
if (!success) return;
|
if (!success) return;
|
||||||
|
|
||||||
@@ -564,7 +571,7 @@ export class NoteBlockService extends BlockService {
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
'Shift-Tab': ctx => {
|
'Shift-Tab': ctx => {
|
||||||
const { success } = this.std.command.exec('dedentBlocks');
|
const [success] = this.std.command.exec(dedentBlocks);
|
||||||
|
|
||||||
if (!success) return;
|
if (!success) return;
|
||||||
|
|
||||||
@@ -572,7 +579,7 @@ export class NoteBlockService extends BlockService {
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
'Mod-Backspace': ctx => {
|
'Mod-Backspace': ctx => {
|
||||||
const { success } = this.std.command.exec('dedentBlocksToRoot');
|
const [success] = this.std.command.exec(dedentBlocksToRoot);
|
||||||
|
|
||||||
if (!success) return;
|
if (!success) return;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
import {
|
import { BlockViewExtension, FlavourExtension } from '@blocksuite/block-std';
|
||||||
BlockViewExtension,
|
|
||||||
CommandExtension,
|
|
||||||
FlavourExtension,
|
|
||||||
} from '@blocksuite/block-std';
|
|
||||||
import type { ExtensionType } from '@blocksuite/store';
|
import type { ExtensionType } from '@blocksuite/store';
|
||||||
import { literal } from 'lit/static-html.js';
|
import { literal } from 'lit/static-html.js';
|
||||||
|
|
||||||
@@ -10,13 +6,11 @@ import {
|
|||||||
DocNoteBlockAdapterExtensions,
|
DocNoteBlockAdapterExtensions,
|
||||||
EdgelessNoteBlockAdapterExtensions,
|
EdgelessNoteBlockAdapterExtensions,
|
||||||
} from './adapters/index.js';
|
} from './adapters/index.js';
|
||||||
import { commands } from './commands/index.js';
|
|
||||||
import { NoteBlockService } from './note-service.js';
|
import { NoteBlockService } from './note-service.js';
|
||||||
|
|
||||||
export const NoteBlockSpec: ExtensionType[] = [
|
export const NoteBlockSpec: ExtensionType[] = [
|
||||||
FlavourExtension('affine:note'),
|
FlavourExtension('affine:note'),
|
||||||
NoteBlockService,
|
NoteBlockService,
|
||||||
CommandExtension(commands),
|
|
||||||
BlockViewExtension('affine:note', literal`affine-note`),
|
BlockViewExtension('affine:note', literal`affine-note`),
|
||||||
DocNoteBlockAdapterExtensions,
|
DocNoteBlockAdapterExtensions,
|
||||||
].flat();
|
].flat();
|
||||||
@@ -24,7 +18,6 @@ export const NoteBlockSpec: ExtensionType[] = [
|
|||||||
export const EdgelessNoteBlockSpec: ExtensionType[] = [
|
export const EdgelessNoteBlockSpec: ExtensionType[] = [
|
||||||
FlavourExtension('affine:note'),
|
FlavourExtension('affine:note'),
|
||||||
NoteBlockService,
|
NoteBlockService,
|
||||||
CommandExtension(commands),
|
|
||||||
BlockViewExtension('affine:note', literal`affine-edgeless-note`),
|
BlockViewExtension('affine:note', literal`affine-edgeless-note`),
|
||||||
EdgelessNoteBlockAdapterExtensions,
|
EdgelessNoteBlockAdapterExtensions,
|
||||||
].flat();
|
].flat();
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ import {
|
|||||||
notifyDocCreated,
|
notifyDocCreated,
|
||||||
promptDocTitle,
|
promptDocTitle,
|
||||||
} from '@blocksuite/affine-block-embed';
|
} from '@blocksuite/affine-block-embed';
|
||||||
|
import {
|
||||||
|
draftSelectedModelsCommand,
|
||||||
|
getSelectedModelsCommand,
|
||||||
|
} from '@blocksuite/affine-shared/commands';
|
||||||
import type { BlockStdScope } from '@blocksuite/block-std';
|
import type { BlockStdScope } from '@blocksuite/block-std';
|
||||||
|
|
||||||
export interface QuickActionConfig {
|
export interface QuickActionConfig {
|
||||||
@@ -18,23 +22,20 @@ export const quickActionConfig: QuickActionConfig[] = [
|
|||||||
id: 'convert-to-linked-doc',
|
id: 'convert-to-linked-doc',
|
||||||
hotkey: `Mod-Shift-l`,
|
hotkey: `Mod-Shift-l`,
|
||||||
showWhen: std => {
|
showWhen: std => {
|
||||||
const [_, ctx] = std.command
|
const [_, ctx] = std.command.exec(getSelectedModelsCommand, {
|
||||||
.chain()
|
types: ['block'],
|
||||||
.getSelectedModels({
|
});
|
||||||
types: ['block'],
|
|
||||||
})
|
|
||||||
.run();
|
|
||||||
const { selectedModels } = ctx;
|
const { selectedModels } = ctx;
|
||||||
return !!selectedModels && selectedModels.length > 0;
|
return !!selectedModels && selectedModels.length > 0;
|
||||||
},
|
},
|
||||||
action: std => {
|
action: std => {
|
||||||
const [_, ctx] = std.command
|
const [_, ctx] = std.command
|
||||||
.chain()
|
.chain()
|
||||||
.getSelectedModels({
|
.pipe(getSelectedModelsCommand, {
|
||||||
types: ['block'],
|
types: ['block'],
|
||||||
mode: 'flat',
|
mode: 'flat',
|
||||||
})
|
})
|
||||||
.draftSelectedModels()
|
.pipe(draftSelectedModelsCommand)
|
||||||
.run();
|
.run();
|
||||||
const { selectedModels, draftedModels } = ctx;
|
const { selectedModels, draftedModels } = ctx;
|
||||||
if (!selectedModels) return;
|
if (!selectedModels) return;
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ import { type Command, TextSelection } from '@blocksuite/block-std';
|
|||||||
* Add a paragraph next to the current block.
|
* Add a paragraph next to the current block.
|
||||||
*/
|
*/
|
||||||
export const addParagraphCommand: Command<
|
export const addParagraphCommand: Command<
|
||||||
never,
|
|
||||||
'paragraphConvertedId',
|
|
||||||
{
|
{
|
||||||
blockId?: string;
|
blockId?: string;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
paragraphConvertedId: string;
|
||||||
}
|
}
|
||||||
> = (ctx, next) => {
|
> = (ctx, next) => {
|
||||||
const { std } = ctx;
|
const { std } = ctx;
|
||||||
|
|||||||
@@ -6,11 +6,10 @@ import { Text } from '@blocksuite/store';
|
|||||||
/**
|
/**
|
||||||
* Append a paragraph block at the end of the whole page.
|
* Append a paragraph block at the end of the whole page.
|
||||||
*/
|
*/
|
||||||
export const appendParagraphCommand: Command<
|
export const appendParagraphCommand: Command<{ text?: string }> = (
|
||||||
never,
|
ctx,
|
||||||
never,
|
next
|
||||||
{ text?: string }
|
) => {
|
||||||
> = (ctx, next) => {
|
|
||||||
const { std, text = '' } = ctx;
|
const { std, text = '' } = ctx;
|
||||||
const { store } = std;
|
const { store } = std;
|
||||||
if (!store.root) return;
|
if (!store.root) return;
|
||||||
|
|||||||
@@ -6,9 +6,10 @@ import {
|
|||||||
import { type Command, TextSelection } from '@blocksuite/block-std';
|
import { type Command, TextSelection } from '@blocksuite/block-std';
|
||||||
|
|
||||||
export const canDedentParagraphCommand: Command<
|
export const canDedentParagraphCommand: Command<
|
||||||
never,
|
Partial<Omit<IndentContext, 'flavour' | 'type'>>,
|
||||||
'indentContext',
|
{
|
||||||
Partial<Omit<IndentContext, 'flavour' | 'type'>>
|
indentContext: IndentContext;
|
||||||
|
}
|
||||||
> = (ctx, next) => {
|
> = (ctx, next) => {
|
||||||
let { blockId, inlineIndex } = ctx;
|
let { blockId, inlineIndex } = ctx;
|
||||||
const { std } = ctx;
|
const { std } = ctx;
|
||||||
@@ -56,7 +57,9 @@ export const canDedentParagraphCommand: Command<
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const dedentParagraphCommand: Command<'indentContext'> = (ctx, next) => {
|
export const dedentParagraphCommand: Command<{
|
||||||
|
indentContext: IndentContext;
|
||||||
|
}> = (ctx, next) => {
|
||||||
const { indentContext: dedentContext, std } = ctx;
|
const { indentContext: dedentContext, std } = ctx;
|
||||||
const { store, selection, range, host } = std;
|
const { store, selection, range, host } = std;
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,10 @@ import {
|
|||||||
import { type Command, TextSelection } from '@blocksuite/block-std';
|
import { type Command, TextSelection } from '@blocksuite/block-std';
|
||||||
|
|
||||||
export const canIndentParagraphCommand: Command<
|
export const canIndentParagraphCommand: Command<
|
||||||
never,
|
Partial<Omit<IndentContext, 'flavour' | 'type'>>,
|
||||||
'indentContext',
|
{
|
||||||
Partial<Omit<IndentContext, 'flavour' | 'type'>>
|
indentContext: IndentContext;
|
||||||
|
}
|
||||||
> = (cxt, next) => {
|
> = (cxt, next) => {
|
||||||
let { blockId, inlineIndex } = cxt;
|
let { blockId, inlineIndex } = cxt;
|
||||||
const { std } = cxt;
|
const { std } = cxt;
|
||||||
@@ -60,7 +61,9 @@ export const canIndentParagraphCommand: Command<
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const indentParagraphCommand: Command<'indentContext'> = (ctx, next) => {
|
export const indentParagraphCommand: Command<{
|
||||||
|
indentContext: IndentContext;
|
||||||
|
}> = (ctx, next) => {
|
||||||
const { indentContext, std } = ctx;
|
const { indentContext, std } = ctx;
|
||||||
const { store, selection, host, range } = std;
|
const { store, selection, host, range } = std;
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +1,11 @@
|
|||||||
import type { BlockCommands } from '@blocksuite/block-std';
|
export { addParagraphCommand } from './add-paragraph.js';
|
||||||
|
export { appendParagraphCommand } from './append-paragraph.js';
|
||||||
import { addParagraphCommand } from './add-paragraph.js';
|
export {
|
||||||
import { appendParagraphCommand } from './append-paragraph.js';
|
|
||||||
import {
|
|
||||||
canDedentParagraphCommand,
|
canDedentParagraphCommand,
|
||||||
dedentParagraphCommand,
|
dedentParagraphCommand,
|
||||||
} from './dedent-paragraph.js';
|
} from './dedent-paragraph.js';
|
||||||
import {
|
export {
|
||||||
canIndentParagraphCommand,
|
canIndentParagraphCommand,
|
||||||
indentParagraphCommand,
|
indentParagraphCommand,
|
||||||
} from './indent-paragraph.js';
|
} from './indent-paragraph.js';
|
||||||
import { splitParagraphCommand } from './split-paragraph.js';
|
export { splitParagraphCommand } from './split-paragraph.js';
|
||||||
|
|
||||||
export const commands: BlockCommands = {
|
|
||||||
appendParagraph: appendParagraphCommand,
|
|
||||||
splitParagraph: splitParagraphCommand,
|
|
||||||
addParagraph: addParagraphCommand,
|
|
||||||
canIndentParagraph: canIndentParagraphCommand,
|
|
||||||
canDedentParagraph: canDedentParagraphCommand,
|
|
||||||
indentParagraph: indentParagraphCommand,
|
|
||||||
dedentParagraph: dedentParagraphCommand,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -6,10 +6,11 @@ import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
|||||||
import { type Command, TextSelection } from '@blocksuite/block-std';
|
import { type Command, TextSelection } from '@blocksuite/block-std';
|
||||||
|
|
||||||
export const splitParagraphCommand: Command<
|
export const splitParagraphCommand: Command<
|
||||||
never,
|
|
||||||
'paragraphConvertedId',
|
|
||||||
{
|
{
|
||||||
blockId?: string;
|
blockId?: string;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
paragraphConvertedId: string;
|
||||||
}
|
}
|
||||||
> = (ctx, next) => {
|
> = (ctx, next) => {
|
||||||
const { std } = ctx;
|
const { std } = ctx;
|
||||||
|
|||||||
@@ -1,16 +1,3 @@
|
|||||||
import type { IndentContext } from '@blocksuite/affine-shared/types';
|
|
||||||
|
|
||||||
import type { addParagraphCommand } from './commands/add-paragraph.js';
|
|
||||||
import type { appendParagraphCommand } from './commands/append-paragraph.js';
|
|
||||||
import type {
|
|
||||||
canDedentParagraphCommand,
|
|
||||||
dedentParagraphCommand,
|
|
||||||
} from './commands/dedent-paragraph.js';
|
|
||||||
import type {
|
|
||||||
canIndentParagraphCommand,
|
|
||||||
indentParagraphCommand,
|
|
||||||
} from './commands/indent-paragraph.js';
|
|
||||||
import type { splitParagraphCommand } from './commands/split-paragraph.js';
|
|
||||||
import { effects as ParagraphHeadingIconEffects } from './heading-icon.js';
|
import { effects as ParagraphHeadingIconEffects } from './heading-icon.js';
|
||||||
import { ParagraphBlockComponent } from './paragraph-block.js';
|
import { ParagraphBlockComponent } from './paragraph-block.js';
|
||||||
import type { ParagraphBlockService } from './paragraph-service.js';
|
import type { ParagraphBlockService } from './paragraph-service.js';
|
||||||
@@ -25,19 +12,6 @@ declare global {
|
|||||||
interface BlockServices {
|
interface BlockServices {
|
||||||
'affine:paragraph': ParagraphBlockService;
|
'affine:paragraph': ParagraphBlockService;
|
||||||
}
|
}
|
||||||
interface Commands {
|
|
||||||
addParagraph: typeof addParagraphCommand;
|
|
||||||
appendParagraph: typeof appendParagraphCommand;
|
|
||||||
canIndentParagraph: typeof canIndentParagraphCommand;
|
|
||||||
canDedentParagraph: typeof canDedentParagraphCommand;
|
|
||||||
dedentParagraph: typeof dedentParagraphCommand;
|
|
||||||
indentParagraph: typeof indentParagraphCommand;
|
|
||||||
splitParagraph: typeof splitParagraphCommand;
|
|
||||||
}
|
|
||||||
interface CommandContext {
|
|
||||||
paragraphConvertedId?: string;
|
|
||||||
indentContext?: IndentContext;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
interface HTMLElementTagNameMap {
|
interface HTMLElementTagNameMap {
|
||||||
'affine-paragraph': ParagraphBlockComponent;
|
'affine-paragraph': ParagraphBlockComponent;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
export * from './adapters/index.js';
|
export * from './adapters/index.js';
|
||||||
|
export * from './commands';
|
||||||
export * from './paragraph-block.js';
|
export * from './paragraph-block.js';
|
||||||
export * from './paragraph-service.js';
|
export * from './paragraph-service.js';
|
||||||
export * from './paragraph-spec.js';
|
export * from './paragraph-spec.js';
|
||||||
|
|||||||
@@ -12,6 +12,16 @@ import {
|
|||||||
import { KeymapExtension, TextSelection } from '@blocksuite/block-std';
|
import { KeymapExtension, TextSelection } from '@blocksuite/block-std';
|
||||||
import { IS_MAC } from '@blocksuite/global/env';
|
import { IS_MAC } from '@blocksuite/global/env';
|
||||||
|
|
||||||
|
import { addParagraphCommand } from './commands/add-paragraph.js';
|
||||||
|
import {
|
||||||
|
canDedentParagraphCommand,
|
||||||
|
dedentParagraphCommand,
|
||||||
|
} from './commands/dedent-paragraph.js';
|
||||||
|
import {
|
||||||
|
canIndentParagraphCommand,
|
||||||
|
indentParagraphCommand,
|
||||||
|
} from './commands/indent-paragraph.js';
|
||||||
|
import { splitParagraphCommand } from './commands/split-paragraph.js';
|
||||||
import { forwardDelete } from './utils/forward-delete.js';
|
import { forwardDelete } from './utils/forward-delete.js';
|
||||||
import { mergeWithPrev } from './utils/merge-with-prev.js';
|
import { mergeWithPrev } from './utils/merge-with-prev.js';
|
||||||
|
|
||||||
@@ -46,7 +56,11 @@ export const ParagraphKeymapExtension = KeymapExtension(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std.command.chain().canDedentParagraph().dedentParagraph().run();
|
std.command
|
||||||
|
.chain()
|
||||||
|
.pipe(canDedentParagraphCommand)
|
||||||
|
.pipe(dedentParagraphCommand)
|
||||||
|
.run();
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
'Mod-Enter': ctx => {
|
'Mod-Enter': ctx => {
|
||||||
@@ -73,7 +87,7 @@ export const ParagraphKeymapExtension = KeymapExtension(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std.command.exec('addParagraph');
|
std.command.chain().pipe(addParagraphCommand).run();
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
Enter: ctx => {
|
Enter: ctx => {
|
||||||
@@ -113,7 +127,7 @@ export const ParagraphKeymapExtension = KeymapExtension(
|
|||||||
raw.preventDefault();
|
raw.preventDefault();
|
||||||
store.captureSync();
|
store.captureSync();
|
||||||
model.text.delete(range.index - 1, 1);
|
model.text.delete(range.index - 1, 1);
|
||||||
std.command.exec('addParagraph');
|
std.command.chain().pipe(addParagraphCommand).run();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -146,11 +160,11 @@ export const ParagraphKeymapExtension = KeymapExtension(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isEnd) {
|
if (isEnd) {
|
||||||
std.command.exec('addParagraph');
|
std.command.chain().pipe(addParagraphCommand).run();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std.command.exec('splitParagraph');
|
std.command.chain().pipe(splitParagraphCommand).run();
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
Delete: ctx => {
|
Delete: ctx => {
|
||||||
@@ -189,8 +203,8 @@ export const ParagraphKeymapExtension = KeymapExtension(
|
|||||||
Tab: ctx => {
|
Tab: ctx => {
|
||||||
const [success] = std.command
|
const [success] = std.command
|
||||||
.chain()
|
.chain()
|
||||||
.canIndentParagraph()
|
.pipe(canIndentParagraphCommand)
|
||||||
.indentParagraph()
|
.pipe(indentParagraphCommand)
|
||||||
.run();
|
.run();
|
||||||
if (!success) {
|
if (!success) {
|
||||||
return;
|
return;
|
||||||
@@ -201,8 +215,8 @@ export const ParagraphKeymapExtension = KeymapExtension(
|
|||||||
'Shift-Tab': ctx => {
|
'Shift-Tab': ctx => {
|
||||||
const [success] = std.command
|
const [success] = std.command
|
||||||
.chain()
|
.chain()
|
||||||
.canDedentParagraph()
|
.pipe(canDedentParagraphCommand)
|
||||||
.dedentParagraph()
|
.pipe(dedentParagraphCommand)
|
||||||
.run();
|
.run();
|
||||||
if (!success) {
|
if (!success) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,13 +1,8 @@
|
|||||||
import {
|
import { BlockViewExtension, FlavourExtension } from '@blocksuite/block-std';
|
||||||
BlockViewExtension,
|
|
||||||
CommandExtension,
|
|
||||||
FlavourExtension,
|
|
||||||
} from '@blocksuite/block-std';
|
|
||||||
import type { ExtensionType } from '@blocksuite/store';
|
import type { ExtensionType } from '@blocksuite/store';
|
||||||
import { literal } from 'lit/static-html.js';
|
import { literal } from 'lit/static-html.js';
|
||||||
|
|
||||||
import { ParagraphBlockAdapterExtensions } from './adapters/extension.js';
|
import { ParagraphBlockAdapterExtensions } from './adapters/extension.js';
|
||||||
import { commands } from './commands/index.js';
|
|
||||||
import {
|
import {
|
||||||
ParagraphKeymapExtension,
|
ParagraphKeymapExtension,
|
||||||
ParagraphTextKeymapExtension,
|
ParagraphTextKeymapExtension,
|
||||||
@@ -17,7 +12,6 @@ import { ParagraphBlockService } from './paragraph-service.js';
|
|||||||
export const ParagraphBlockSpec: ExtensionType[] = [
|
export const ParagraphBlockSpec: ExtensionType[] = [
|
||||||
FlavourExtension('affine:paragraph'),
|
FlavourExtension('affine:paragraph'),
|
||||||
ParagraphBlockService,
|
ParagraphBlockService,
|
||||||
CommandExtension(commands),
|
|
||||||
BlockViewExtension('affine:paragraph', literal`affine-paragraph`),
|
BlockViewExtension('affine:paragraph', literal`affine-paragraph`),
|
||||||
ParagraphTextKeymapExtension,
|
ParagraphTextKeymapExtension,
|
||||||
ParagraphKeymapExtension,
|
ParagraphKeymapExtension,
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
import { getSurfaceBlock } from '@blocksuite/affine-block-surface';
|
import { getSurfaceBlock } from '@blocksuite/affine-block-surface';
|
||||||
import type { SurfaceRefProps } from '@blocksuite/affine-model';
|
import type { SurfaceRefProps } from '@blocksuite/affine-model';
|
||||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||||
import type { BlockCommands, Command } from '@blocksuite/block-std';
|
import type { Command } from '@blocksuite/block-std';
|
||||||
|
import type { BlockModel } from '@blocksuite/store';
|
||||||
|
|
||||||
export const insertSurfaceRefBlockCommand: Command<
|
export const insertSurfaceRefBlockCommand: Command<
|
||||||
'selectedModels',
|
|
||||||
'insertedSurfaceRefBlockId',
|
|
||||||
{
|
{
|
||||||
reference: string;
|
reference: string;
|
||||||
place: 'after' | 'before';
|
place: 'after' | 'before';
|
||||||
removeEmptyLine?: boolean;
|
removeEmptyLine?: boolean;
|
||||||
|
selectedModels?: BlockModel[];
|
||||||
|
},
|
||||||
|
{
|
||||||
|
insertedSurfaceRefBlockId: string;
|
||||||
}
|
}
|
||||||
> = (ctx, next) => {
|
> = (ctx, next) => {
|
||||||
const { selectedModels, reference, place, removeEmptyLine, std } = ctx;
|
const { selectedModels, reference, place, removeEmptyLine, std } = ctx;
|
||||||
@@ -57,7 +60,3 @@ export const insertSurfaceRefBlockCommand: Command<
|
|||||||
insertedSurfaceRefBlockId: result[0],
|
insertedSurfaceRefBlockId: result[0],
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const commands: BlockCommands = {
|
|
||||||
insertSurfaceRefBlock: insertSurfaceRefBlockCommand,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import type { insertSurfaceRefBlockCommand } from './commands.js';
|
|
||||||
import { SurfaceRefGenericBlockPortal } from './portal/generic-block.js';
|
import { SurfaceRefGenericBlockPortal } from './portal/generic-block.js';
|
||||||
import { SurfaceRefNotePortal } from './portal/note.js';
|
import { SurfaceRefNotePortal } from './portal/note.js';
|
||||||
import { SurfaceRefBlockComponent } from './surface-ref-block.js';
|
import { SurfaceRefBlockComponent } from './surface-ref-block.js';
|
||||||
@@ -16,22 +15,3 @@ export function effects() {
|
|||||||
);
|
);
|
||||||
customElements.define('surface-ref-note-portal', SurfaceRefNotePortal);
|
customElements.define('surface-ref-note-portal', SurfaceRefNotePortal);
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface CommandContext {
|
|
||||||
insertedSurfaceRefBlockId?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Commands {
|
|
||||||
/**
|
|
||||||
* insert a SurfaceRef block after or before the current block selection
|
|
||||||
* @param reference the reference block id. The block should be group or frame
|
|
||||||
* @param place where to insert the LaTeX block
|
|
||||||
* @param removeEmptyLine remove the current block if it is empty
|
|
||||||
* @returns the id of the inserted SurfaceRef block
|
|
||||||
*/
|
|
||||||
insertSurfaceRefBlock: typeof insertSurfaceRefBlockCommand;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import '@blocksuite/affine-shared/commands';
|
export * from './commands.js';
|
||||||
|
|
||||||
export * from './surface-ref-block.js';
|
export * from './surface-ref-block.js';
|
||||||
export * from './surface-ref-block-edgeless.js';
|
export * from './surface-ref-block-edgeless.js';
|
||||||
export {
|
export {
|
||||||
|
|||||||
@@ -1,17 +1,13 @@
|
|||||||
import {
|
import {
|
||||||
BlockViewExtension,
|
BlockViewExtension,
|
||||||
CommandExtension,
|
|
||||||
FlavourExtension,
|
FlavourExtension,
|
||||||
WidgetViewMapExtension,
|
WidgetViewMapExtension,
|
||||||
} from '@blocksuite/block-std';
|
} from '@blocksuite/block-std';
|
||||||
import type { ExtensionType } from '@blocksuite/store';
|
import type { ExtensionType } from '@blocksuite/store';
|
||||||
import { literal } from 'lit/static-html.js';
|
import { literal } from 'lit/static-html.js';
|
||||||
|
|
||||||
import { commands } from './commands.js';
|
|
||||||
|
|
||||||
export const PageSurfaceRefBlockSpec: ExtensionType[] = [
|
export const PageSurfaceRefBlockSpec: ExtensionType[] = [
|
||||||
FlavourExtension('affine:surface-ref'),
|
FlavourExtension('affine:surface-ref'),
|
||||||
CommandExtension(commands),
|
|
||||||
BlockViewExtension('affine:surface-ref', literal`affine-surface-ref`),
|
BlockViewExtension('affine:surface-ref', literal`affine-surface-ref`),
|
||||||
WidgetViewMapExtension('affine:surface-ref', {
|
WidgetViewMapExtension('affine:surface-ref', {
|
||||||
surfaceToolbar: literal`affine-surface-ref-toolbar`,
|
surfaceToolbar: literal`affine-surface-ref-toolbar`,
|
||||||
|
|||||||
@@ -24,10 +24,7 @@ import { updateXYWH } from '../utils/update-xywh.js';
|
|||||||
/**
|
/**
|
||||||
* Automatically arrange elements according to fixed row and column rules
|
* Automatically arrange elements according to fixed row and column rules
|
||||||
*/
|
*/
|
||||||
export const autoArrangeElementsCommand: Command<never, never, {}> = (
|
export const autoArrangeElementsCommand: Command = (ctx, next) => {
|
||||||
ctx,
|
|
||||||
next
|
|
||||||
) => {
|
|
||||||
const { updateBlock } = ctx.std.store;
|
const { updateBlock } = ctx.std.store;
|
||||||
const gfx = ctx.std.get(GfxControllerIdentifier);
|
const gfx = ctx.std.get(GfxControllerIdentifier);
|
||||||
|
|
||||||
@@ -42,10 +39,7 @@ export const autoArrangeElementsCommand: Command<never, never, {}> = (
|
|||||||
/**
|
/**
|
||||||
* Adjust the height of the selected element to a fixed value and arrange the elements
|
* Adjust the height of the selected element to a fixed value and arrange the elements
|
||||||
*/
|
*/
|
||||||
export const autoResizeElementsCommand: Command<never, never, {}> = (
|
export const autoResizeElementsCommand: Command = (ctx, next) => {
|
||||||
ctx,
|
|
||||||
next
|
|
||||||
) => {
|
|
||||||
const { updateBlock } = ctx.std.store;
|
const { updateBlock } = ctx.std.store;
|
||||||
const gfx = ctx.std.get(GfxControllerIdentifier);
|
const gfx = ctx.std.get(GfxControllerIdentifier);
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,5 @@
|
|||||||
import type { BlockCommands } from '@blocksuite/block-std';
|
export {
|
||||||
|
|
||||||
import {
|
|
||||||
autoArrangeElementsCommand,
|
autoArrangeElementsCommand,
|
||||||
autoResizeElementsCommand,
|
autoResizeElementsCommand,
|
||||||
} from './auto-align.js';
|
} from './auto-align.js';
|
||||||
import { reassociateConnectorsCommand } from './reassociate-connectors.js';
|
export { reassociateConnectorsCommand } from './reassociate-connectors.js';
|
||||||
|
|
||||||
export const commands: BlockCommands = {
|
|
||||||
reassociateConnectors: reassociateConnectorsCommand,
|
|
||||||
autoArrangeElements: autoArrangeElementsCommand,
|
|
||||||
autoResizeElements: autoResizeElementsCommand,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -6,11 +6,10 @@ import type { Command } from '@blocksuite/block-std';
|
|||||||
* @param oldId - the old block id
|
* @param oldId - the old block id
|
||||||
* @param newId - the new block id
|
* @param newId - the new block id
|
||||||
*/
|
*/
|
||||||
export const reassociateConnectorsCommand: Command<
|
export const reassociateConnectorsCommand: Command<{
|
||||||
never,
|
oldId: string;
|
||||||
never,
|
newId: string;
|
||||||
{ oldId: string; newId: string }
|
}> = (ctx, next) => {
|
||||||
> = (ctx, next) => {
|
|
||||||
const { oldId, newId } = ctx;
|
const { oldId, newId } = ctx;
|
||||||
const service = ctx.std.getService('affine:surface');
|
const service = ctx.std.getService('affine:surface');
|
||||||
if (!oldId || !newId || !service) {
|
if (!oldId || !newId || !service) {
|
||||||
|
|||||||
@@ -1,8 +1,3 @@
|
|||||||
import type {
|
|
||||||
autoArrangeElementsCommand,
|
|
||||||
autoResizeElementsCommand,
|
|
||||||
} from './commands/auto-align.js';
|
|
||||||
import type { reassociateConnectorsCommand } from './commands/reassociate-connectors.js';
|
|
||||||
import { SurfaceBlockComponent } from './surface-block.js';
|
import { SurfaceBlockComponent } from './surface-block.js';
|
||||||
import { SurfaceBlockVoidComponent } from './surface-block-void.js';
|
import { SurfaceBlockVoidComponent } from './surface-block-void.js';
|
||||||
import type { SurfaceBlockModel } from './surface-model.js';
|
import type { SurfaceBlockModel } from './surface-model.js';
|
||||||
@@ -21,10 +16,5 @@ declare global {
|
|||||||
interface BlockModels {
|
interface BlockModels {
|
||||||
'affine:surface': SurfaceBlockModel;
|
'affine:surface': SurfaceBlockModel;
|
||||||
}
|
}
|
||||||
interface Commands {
|
|
||||||
reassociateConnectors: typeof reassociateConnectorsCommand;
|
|
||||||
autoArrangeElements: typeof autoArrangeElementsCommand;
|
|
||||||
autoResizeElements: typeof autoResizeElementsCommand;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,3 +116,5 @@ export const MindmapUtils = {
|
|||||||
hideNodeConnector,
|
hideNodeConnector,
|
||||||
containsNode,
|
containsNode,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export * from './commands';
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
import {
|
import { BlockViewExtension, FlavourExtension } from '@blocksuite/block-std';
|
||||||
BlockViewExtension,
|
|
||||||
CommandExtension,
|
|
||||||
FlavourExtension,
|
|
||||||
} from '@blocksuite/block-std';
|
|
||||||
import type { ExtensionType } from '@blocksuite/store';
|
import type { ExtensionType } from '@blocksuite/store';
|
||||||
import { literal } from 'lit/static-html.js';
|
import { literal } from 'lit/static-html.js';
|
||||||
|
|
||||||
@@ -10,7 +6,6 @@ import {
|
|||||||
EdgelessSurfaceBlockAdapterExtensions,
|
EdgelessSurfaceBlockAdapterExtensions,
|
||||||
SurfaceBlockAdapterExtensions,
|
SurfaceBlockAdapterExtensions,
|
||||||
} from './adapters/extension';
|
} from './adapters/extension';
|
||||||
import { commands } from './commands';
|
|
||||||
import {
|
import {
|
||||||
EdgelessCRUDExtension,
|
EdgelessCRUDExtension,
|
||||||
EdgelessLegacySlotExtension,
|
EdgelessLegacySlotExtension,
|
||||||
@@ -21,7 +16,6 @@ import { MindMapView } from './view/mindmap';
|
|||||||
const CommonSurfaceBlockSpec: ExtensionType[] = [
|
const CommonSurfaceBlockSpec: ExtensionType[] = [
|
||||||
FlavourExtension('affine:surface'),
|
FlavourExtension('affine:surface'),
|
||||||
SurfaceBlockService,
|
SurfaceBlockService,
|
||||||
CommandExtension(commands),
|
|
||||||
MindMapView,
|
MindMapView,
|
||||||
EdgelessCRUDExtension,
|
EdgelessCRUDExtension,
|
||||||
EdgelessLegacySlotExtension,
|
EdgelessLegacySlotExtension,
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
import '@blocksuite/affine-shared/commands';
|
|
||||||
|
|
||||||
import { TableModelFlavour } from '@blocksuite/affine-model';
|
import { TableModelFlavour } from '@blocksuite/affine-model';
|
||||||
import { generateFractionalIndexingKeyBetween } from '@blocksuite/affine-shared/utils';
|
import { generateFractionalIndexingKeyBetween } from '@blocksuite/affine-shared/utils';
|
||||||
import type { BlockCommands, Command } from '@blocksuite/block-std';
|
import type { Command } from '@blocksuite/block-std';
|
||||||
import { nanoid, Text } from '@blocksuite/store';
|
import { type BlockModel, nanoid, Text } from '@blocksuite/store';
|
||||||
export const insertTableBlockCommand: Command<
|
export const insertTableBlockCommand: Command<
|
||||||
'selectedModels',
|
|
||||||
'insertedTableBlockId',
|
|
||||||
{
|
{
|
||||||
place?: 'after' | 'before';
|
place?: 'after' | 'before';
|
||||||
removeEmptyLine?: boolean;
|
removeEmptyLine?: boolean;
|
||||||
|
selectedModels?: BlockModel[];
|
||||||
|
},
|
||||||
|
{
|
||||||
|
insertedTableBlockId: string;
|
||||||
}
|
}
|
||||||
> = (ctx, next) => {
|
> = (ctx, next) => {
|
||||||
const { selectedModels, place, removeEmptyLine, std } = ctx;
|
const { selectedModels, place, removeEmptyLine, std } = ctx;
|
||||||
@@ -61,7 +61,3 @@ export const insertTableBlockCommand: Command<
|
|||||||
|
|
||||||
next({ insertedTableBlockId: blockId });
|
next({ insertedTableBlockId: blockId });
|
||||||
};
|
};
|
||||||
|
|
||||||
export const tableCommands: BlockCommands = {
|
|
||||||
insertTableBlock: insertTableBlockCommand,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { AddButton } from './add-button';
|
import { AddButton } from './add-button';
|
||||||
import type { insertTableBlockCommand } from './commands';
|
|
||||||
import { SelectionLayer } from './selection-layer';
|
import { SelectionLayer } from './selection-layer';
|
||||||
import { TableBlockComponent } from './table-block';
|
import { TableBlockComponent } from './table-block';
|
||||||
import { TableCell } from './table-cell';
|
import { TableCell } from './table-cell';
|
||||||
@@ -10,15 +9,3 @@ export function effects() {
|
|||||||
customElements.define('affine-table-add-button', AddButton);
|
customElements.define('affine-table-add-button', AddButton);
|
||||||
customElements.define('affine-table-selection-layer', SelectionLayer);
|
customElements.define('affine-table-selection-layer', SelectionLayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface CommandContext {
|
|
||||||
insertedTableBlockId?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Commands {
|
|
||||||
insertTableBlock: typeof insertTableBlockCommand;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -107,12 +107,4 @@ export class TableSelection extends BaseSelection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface Selection {
|
|
||||||
table: typeof TableSelection;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const TableSelectionExtension = SelectionExtension(TableSelection);
|
export const TableSelectionExtension = SelectionExtension(TableSelection);
|
||||||
|
|||||||
@@ -1,18 +1,12 @@
|
|||||||
import { TableModelFlavour } from '@blocksuite/affine-model';
|
import { TableModelFlavour } from '@blocksuite/affine-model';
|
||||||
import {
|
import { BlockViewExtension, FlavourExtension } from '@blocksuite/block-std';
|
||||||
BlockViewExtension,
|
|
||||||
CommandExtension,
|
|
||||||
FlavourExtension,
|
|
||||||
} from '@blocksuite/block-std';
|
|
||||||
import type { ExtensionType } from '@blocksuite/store';
|
import type { ExtensionType } from '@blocksuite/store';
|
||||||
import { literal } from 'lit/static-html.js';
|
import { literal } from 'lit/static-html.js';
|
||||||
|
|
||||||
import { TableBlockAdapterExtensions } from './adapters/extension.js';
|
import { TableBlockAdapterExtensions } from './adapters/extension.js';
|
||||||
import { tableCommands } from './commands.js';
|
|
||||||
|
|
||||||
export const TableBlockSpec: ExtensionType[] = [
|
export const TableBlockSpec: ExtensionType[] = [
|
||||||
FlavourExtension(TableModelFlavour),
|
FlavourExtension(TableModelFlavour),
|
||||||
CommandExtension(tableCommands),
|
|
||||||
BlockViewExtension(TableModelFlavour, literal`affine-table`),
|
BlockViewExtension(TableModelFlavour, literal`affine-table`),
|
||||||
TableBlockAdapterExtensions,
|
TableBlockAdapterExtensions,
|
||||||
].flat();
|
].flat();
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
/// <reference types="@blocksuite/affine-shared/commands" />
|
import {
|
||||||
|
getBlockSelectionsCommand,
|
||||||
|
getSelectedBlocksCommand,
|
||||||
|
getTextSelectionCommand,
|
||||||
|
} from '@blocksuite/affine-shared/commands';
|
||||||
import type {
|
import type {
|
||||||
BlockComponent,
|
BlockComponent,
|
||||||
Command,
|
Command,
|
||||||
@@ -10,15 +14,22 @@ import { isPeekable, peek } from './peekable.js';
|
|||||||
const getSelectedPeekableBlocks = (cmd: InitCommandCtx) => {
|
const getSelectedPeekableBlocks = (cmd: InitCommandCtx) => {
|
||||||
const [result, ctx] = cmd.std.command
|
const [result, ctx] = cmd.std.command
|
||||||
.chain()
|
.chain()
|
||||||
.tryAll(chain => [chain.getTextSelection(), chain.getBlockSelections()])
|
.tryAll(chain => [
|
||||||
.getSelectedBlocks({ types: ['text', 'block'] })
|
chain.pipe(getTextSelectionCommand),
|
||||||
|
chain.pipe(getBlockSelectionsCommand),
|
||||||
|
])
|
||||||
|
.pipe(getSelectedBlocksCommand, { types: ['text', 'block'] })
|
||||||
.run();
|
.run();
|
||||||
return ((result ? ctx.selectedBlocks : []) || []).filter(isPeekable);
|
return ((result ? ctx.selectedBlocks : []) || []).filter(isPeekable);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getSelectedPeekableBlocksCommand: Command<
|
export const getSelectedPeekableBlocksCommand: Command<
|
||||||
'selectedBlocks',
|
{
|
||||||
'selectedPeekableBlocks'
|
selectedBlocks: BlockComponent[];
|
||||||
|
},
|
||||||
|
{
|
||||||
|
selectedPeekableBlocks: BlockComponent[];
|
||||||
|
}
|
||||||
> = (ctx, next) => {
|
> = (ctx, next) => {
|
||||||
const selectedPeekableBlocks = getSelectedPeekableBlocks(ctx);
|
const selectedPeekableBlocks = getSelectedPeekableBlocks(ctx);
|
||||||
if (selectedPeekableBlocks.length > 0) {
|
if (selectedPeekableBlocks.length > 0) {
|
||||||
@@ -26,10 +37,9 @@ export const getSelectedPeekableBlocksCommand: Command<
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const peekSelectedBlockCommand: Command<'selectedBlocks'> = (
|
export const peekSelectedBlockCommand: Command<{
|
||||||
ctx,
|
selectedBlocks: BlockComponent[];
|
||||||
next
|
}> = (ctx, next) => {
|
||||||
) => {
|
|
||||||
const peekableBlocks = getSelectedPeekableBlocks(ctx);
|
const peekableBlocks = getSelectedPeekableBlocks(ctx);
|
||||||
// if there are multiple blocks, peek the first one
|
// if there are multiple blocks, peek the first one
|
||||||
const block = peekableBlocks.at(0);
|
const block = peekableBlocks.at(0);
|
||||||
@@ -39,17 +49,3 @@ export const peekSelectedBlockCommand: Command<'selectedBlocks'> = (
|
|||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace BlockSuite {
|
|
||||||
interface CommandContext {
|
|
||||||
selectedPeekableBlocks?: BlockComponent[];
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Commands {
|
|
||||||
peekSelectedBlock: typeof peekSelectedBlockCommand;
|
|
||||||
getSelectedPeekableBlocks: typeof getSelectedPeekableBlocksCommand;
|
|
||||||
// todo: add command for peek an inline element?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,21 +1,3 @@
|
|||||||
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
|
||||||
|
|
||||||
import type { deleteTextCommand } from './format/delete-text.js';
|
|
||||||
import type { formatBlockCommand } from './format/format-block.js';
|
|
||||||
import type { formatNativeCommand } from './format/format-native.js';
|
|
||||||
import type { formatTextCommand } from './format/format-text.js';
|
|
||||||
import type { insertInlineLatex } from './format/insert-inline-latex.js';
|
|
||||||
import type {
|
|
||||||
getTextStyle,
|
|
||||||
isTextStyleActive,
|
|
||||||
toggleBold,
|
|
||||||
toggleCode,
|
|
||||||
toggleItalic,
|
|
||||||
toggleLink,
|
|
||||||
toggleStrike,
|
|
||||||
toggleTextStyleCommand,
|
|
||||||
toggleUnderline,
|
|
||||||
} from './format/text-style.js';
|
|
||||||
import {
|
import {
|
||||||
AffineFootnoteNode,
|
AffineFootnoteNode,
|
||||||
AffineLink,
|
AffineLink,
|
||||||
@@ -64,25 +46,4 @@ declare global {
|
|||||||
'latex-editor-menu': LatexEditorMenu;
|
'latex-editor-menu': LatexEditorMenu;
|
||||||
'link-popup': LinkPopup;
|
'link-popup': LinkPopup;
|
||||||
}
|
}
|
||||||
namespace BlockSuite {
|
|
||||||
interface CommandContext {
|
|
||||||
textStyle?: AffineTextAttributes;
|
|
||||||
}
|
|
||||||
interface Commands {
|
|
||||||
deleteText: typeof deleteTextCommand;
|
|
||||||
formatBlock: typeof formatBlockCommand;
|
|
||||||
formatNative: typeof formatNativeCommand;
|
|
||||||
formatText: typeof formatTextCommand;
|
|
||||||
toggleBold: typeof toggleBold;
|
|
||||||
toggleItalic: typeof toggleItalic;
|
|
||||||
toggleUnderline: typeof toggleUnderline;
|
|
||||||
toggleStrike: typeof toggleStrike;
|
|
||||||
toggleCode: typeof toggleCode;
|
|
||||||
toggleLink: typeof toggleLink;
|
|
||||||
toggleTextStyle: typeof toggleTextStyleCommand;
|
|
||||||
getTextStyle: typeof getTextStyle;
|
|
||||||
isTextStyleActive: typeof isTextStyleActive;
|
|
||||||
insertInlineLatex: typeof insertInlineLatex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,15 @@ import {
|
|||||||
StrikethroughIcon,
|
StrikethroughIcon,
|
||||||
UnderlineIcon,
|
UnderlineIcon,
|
||||||
} from '../../icons/index.js';
|
} from '../../icons/index.js';
|
||||||
|
import {
|
||||||
|
isTextStyleActive,
|
||||||
|
toggleBold,
|
||||||
|
toggleCode,
|
||||||
|
toggleItalic,
|
||||||
|
toggleLink,
|
||||||
|
toggleStrike,
|
||||||
|
toggleUnderline,
|
||||||
|
} from './text-style.js';
|
||||||
|
|
||||||
export interface TextFormatConfig {
|
export interface TextFormatConfig {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -28,12 +37,12 @@ export const textFormatConfigs: TextFormatConfig[] = [
|
|||||||
activeWhen: host => {
|
activeWhen: host => {
|
||||||
const [result] = host.std.command
|
const [result] = host.std.command
|
||||||
.chain()
|
.chain()
|
||||||
.isTextStyleActive({ key: 'bold' })
|
.pipe(isTextStyleActive, { key: 'bold' })
|
||||||
.run();
|
.run();
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
action: host => {
|
action: host => {
|
||||||
host.std.command.chain().toggleBold().run();
|
host.std.command.chain().pipe(toggleBold).run();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -44,12 +53,12 @@ export const textFormatConfigs: TextFormatConfig[] = [
|
|||||||
activeWhen: host => {
|
activeWhen: host => {
|
||||||
const [result] = host.std.command
|
const [result] = host.std.command
|
||||||
.chain()
|
.chain()
|
||||||
.isTextStyleActive({ key: 'italic' })
|
.pipe(isTextStyleActive, { key: 'italic' })
|
||||||
.run();
|
.run();
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
action: host => {
|
action: host => {
|
||||||
host.std.command.chain().toggleItalic().run();
|
host.std.command.chain().pipe(toggleItalic).run();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -60,12 +69,12 @@ export const textFormatConfigs: TextFormatConfig[] = [
|
|||||||
activeWhen: host => {
|
activeWhen: host => {
|
||||||
const [result] = host.std.command
|
const [result] = host.std.command
|
||||||
.chain()
|
.chain()
|
||||||
.isTextStyleActive({ key: 'underline' })
|
.pipe(isTextStyleActive, { key: 'underline' })
|
||||||
.run();
|
.run();
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
action: host => {
|
action: host => {
|
||||||
host.std.command.chain().toggleUnderline().run();
|
host.std.command.chain().pipe(toggleUnderline).run();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -76,12 +85,12 @@ export const textFormatConfigs: TextFormatConfig[] = [
|
|||||||
activeWhen: host => {
|
activeWhen: host => {
|
||||||
const [result] = host.std.command
|
const [result] = host.std.command
|
||||||
.chain()
|
.chain()
|
||||||
.isTextStyleActive({ key: 'strike' })
|
.pipe(isTextStyleActive, { key: 'strike' })
|
||||||
.run();
|
.run();
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
action: host => {
|
action: host => {
|
||||||
host.std.command.chain().toggleStrike().run();
|
host.std.command.chain().pipe(toggleStrike).run();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -92,12 +101,12 @@ export const textFormatConfigs: TextFormatConfig[] = [
|
|||||||
activeWhen: host => {
|
activeWhen: host => {
|
||||||
const [result] = host.std.command
|
const [result] = host.std.command
|
||||||
.chain()
|
.chain()
|
||||||
.isTextStyleActive({ key: 'code' })
|
.pipe(isTextStyleActive, { key: 'code' })
|
||||||
.run();
|
.run();
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
action: host => {
|
action: host => {
|
||||||
host.std.command.chain().toggleCode().run();
|
host.std.command.chain().pipe(toggleCode).run();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -108,12 +117,12 @@ export const textFormatConfigs: TextFormatConfig[] = [
|
|||||||
activeWhen: host => {
|
activeWhen: host => {
|
||||||
const [result] = host.std.command
|
const [result] = host.std.command
|
||||||
.chain()
|
.chain()
|
||||||
.isTextStyleActive({ key: 'link' })
|
.pipe(isTextStyleActive, { key: 'link' })
|
||||||
.run();
|
.run();
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
action: host => {
|
action: host => {
|
||||||
host.std.command.chain().toggleLink().run();
|
host.std.command.chain().pipe(toggleLink).run();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -2,13 +2,10 @@ import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
|||||||
import { type Command, TextSelection } from '@blocksuite/block-std';
|
import { type Command, TextSelection } from '@blocksuite/block-std';
|
||||||
import type { Text } from '@blocksuite/store';
|
import type { Text } from '@blocksuite/store';
|
||||||
|
|
||||||
export const deleteTextCommand: Command<
|
export const deleteTextCommand: Command<{
|
||||||
'currentTextSelection',
|
currentTextSelection?: TextSelection;
|
||||||
never,
|
textSelection?: TextSelection;
|
||||||
{
|
}> = (ctx, next) => {
|
||||||
textSelection?: TextSelection;
|
|
||||||
}
|
|
||||||
> = (ctx, next) => {
|
|
||||||
const textSelection = ctx.textSelection ?? ctx.currentTextSelection;
|
const textSelection = ctx.textSelection ?? ctx.currentTextSelection;
|
||||||
if (!textSelection) return;
|
if (!textSelection) return;
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { getSelectedBlocksCommand } from '@blocksuite/affine-shared/commands';
|
||||||
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
||||||
import type { BlockSelection, Command } from '@blocksuite/block-std';
|
import type { BlockSelection, Command } from '@blocksuite/block-std';
|
||||||
import { assertExists } from '@blocksuite/global/utils';
|
import { assertExists } from '@blocksuite/global/utils';
|
||||||
@@ -6,15 +7,12 @@ import { INLINE_ROOT_ATTR, type InlineRootElement } from '@blocksuite/inline';
|
|||||||
import { FORMAT_BLOCK_SUPPORT_FLAVOURS } from './consts.js';
|
import { FORMAT_BLOCK_SUPPORT_FLAVOURS } from './consts.js';
|
||||||
|
|
||||||
// for block selection
|
// for block selection
|
||||||
export const formatBlockCommand: Command<
|
export const formatBlockCommand: Command<{
|
||||||
'currentBlockSelections',
|
currentBlockSelections?: BlockSelection[];
|
||||||
never,
|
blockSelections?: BlockSelection[];
|
||||||
{
|
styles: AffineTextAttributes;
|
||||||
blockSelections?: BlockSelection[];
|
mode?: 'replace' | 'merge';
|
||||||
styles: AffineTextAttributes;
|
}> = (ctx, next) => {
|
||||||
mode?: 'replace' | 'merge';
|
|
||||||
}
|
|
||||||
> = (ctx, next) => {
|
|
||||||
const blockSelections = ctx.blockSelections ?? ctx.currentBlockSelections;
|
const blockSelections = ctx.blockSelections ?? ctx.currentBlockSelections;
|
||||||
assertExists(
|
assertExists(
|
||||||
blockSelections,
|
blockSelections,
|
||||||
@@ -28,7 +26,7 @@ export const formatBlockCommand: Command<
|
|||||||
|
|
||||||
const success = ctx.std.command
|
const success = ctx.std.command
|
||||||
.chain()
|
.chain()
|
||||||
.getSelectedBlocks({
|
.pipe(getSelectedBlocksCommand, {
|
||||||
blockSelections,
|
blockSelections,
|
||||||
filter: el =>
|
filter: el =>
|
||||||
FORMAT_BLOCK_SUPPORT_FLAVOURS.includes(
|
FORMAT_BLOCK_SUPPORT_FLAVOURS.includes(
|
||||||
@@ -36,7 +34,7 @@ export const formatBlockCommand: Command<
|
|||||||
),
|
),
|
||||||
types: ['block'],
|
types: ['block'],
|
||||||
})
|
})
|
||||||
.inline((ctx, next) => {
|
.pipe((ctx, next) => {
|
||||||
const { selectedBlocks } = ctx;
|
const { selectedBlocks } = ctx;
|
||||||
assertExists(selectedBlocks);
|
assertExists(selectedBlocks);
|
||||||
|
|
||||||
|
|||||||
@@ -9,15 +9,11 @@ import { INLINE_ROOT_ATTR, type InlineRootElement } from '@blocksuite/inline';
|
|||||||
import { FORMAT_NATIVE_SUPPORT_FLAVOURS } from './consts.js';
|
import { FORMAT_NATIVE_SUPPORT_FLAVOURS } from './consts.js';
|
||||||
|
|
||||||
// for native range
|
// for native range
|
||||||
export const formatNativeCommand: Command<
|
export const formatNativeCommand: Command<{
|
||||||
never,
|
range?: Range;
|
||||||
never,
|
styles: AffineTextAttributes;
|
||||||
{
|
mode?: 'replace' | 'merge';
|
||||||
range?: Range;
|
}> = (ctx, next) => {
|
||||||
styles: AffineTextAttributes;
|
|
||||||
mode?: 'replace' | 'merge';
|
|
||||||
}
|
|
||||||
> = (ctx, next) => {
|
|
||||||
const { styles, mode = 'merge' } = ctx;
|
const { styles, mode = 'merge' } = ctx;
|
||||||
|
|
||||||
let range = ctx.range;
|
let range = ctx.range;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { getSelectedBlocksCommand } from '@blocksuite/affine-shared/commands';
|
||||||
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
||||||
import type { Command, TextSelection } from '@blocksuite/block-std';
|
import type { Command, TextSelection } from '@blocksuite/block-std';
|
||||||
import { INLINE_ROOT_ATTR, type InlineRootElement } from '@blocksuite/inline';
|
import { INLINE_ROOT_ATTR, type InlineRootElement } from '@blocksuite/inline';
|
||||||
@@ -6,15 +7,12 @@ import { FORMAT_TEXT_SUPPORT_FLAVOURS } from './consts.js';
|
|||||||
import { clearMarksOnDiscontinuousInput } from './utils.js';
|
import { clearMarksOnDiscontinuousInput } from './utils.js';
|
||||||
|
|
||||||
// for text selection
|
// for text selection
|
||||||
export const formatTextCommand: Command<
|
export const formatTextCommand: Command<{
|
||||||
'currentTextSelection',
|
currentTextSelection?: TextSelection;
|
||||||
never,
|
textSelection?: TextSelection;
|
||||||
{
|
styles: AffineTextAttributes;
|
||||||
textSelection?: TextSelection;
|
mode?: 'replace' | 'merge';
|
||||||
styles: AffineTextAttributes;
|
}> = (ctx, next) => {
|
||||||
mode?: 'replace' | 'merge';
|
|
||||||
}
|
|
||||||
> = (ctx, next) => {
|
|
||||||
const { styles, mode = 'merge' } = ctx;
|
const { styles, mode = 'merge' } = ctx;
|
||||||
|
|
||||||
const textSelection = ctx.textSelection ?? ctx.currentTextSelection;
|
const textSelection = ctx.textSelection ?? ctx.currentTextSelection;
|
||||||
@@ -22,7 +20,7 @@ export const formatTextCommand: Command<
|
|||||||
|
|
||||||
const success = ctx.std.command
|
const success = ctx.std.command
|
||||||
.chain()
|
.chain()
|
||||||
.getSelectedBlocks({
|
.pipe(getSelectedBlocksCommand, {
|
||||||
textSelection,
|
textSelection,
|
||||||
filter: el =>
|
filter: el =>
|
||||||
FORMAT_TEXT_SUPPORT_FLAVOURS.includes(
|
FORMAT_TEXT_SUPPORT_FLAVOURS.includes(
|
||||||
@@ -30,7 +28,7 @@ export const formatTextCommand: Command<
|
|||||||
),
|
),
|
||||||
types: ['text'],
|
types: ['text'],
|
||||||
})
|
})
|
||||||
.inline((ctx, next) => {
|
.pipe((ctx, next) => {
|
||||||
const { selectedBlocks } = ctx;
|
const { selectedBlocks } = ctx;
|
||||||
if (!selectedBlocks) return;
|
if (!selectedBlocks) return;
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,16 @@
|
|||||||
import { getTextSelectionCommand } from '@blocksuite/affine-shared/commands';
|
|
||||||
import type { BlockCommands } from '@blocksuite/block-std';
|
|
||||||
|
|
||||||
import { deleteTextCommand } from './delete-text.js';
|
|
||||||
export type { TextFormatConfig } from './config.js';
|
export type { TextFormatConfig } from './config.js';
|
||||||
export { textFormatConfigs } from './config.js';
|
export { textFormatConfigs } from './config.js';
|
||||||
import { formatBlockCommand } from './format-block.js';
|
|
||||||
export {
|
export {
|
||||||
FORMAT_BLOCK_SUPPORT_FLAVOURS,
|
FORMAT_BLOCK_SUPPORT_FLAVOURS,
|
||||||
FORMAT_NATIVE_SUPPORT_FLAVOURS,
|
FORMAT_NATIVE_SUPPORT_FLAVOURS,
|
||||||
FORMAT_TEXT_SUPPORT_FLAVOURS,
|
FORMAT_TEXT_SUPPORT_FLAVOURS,
|
||||||
} from './consts.js';
|
} from './consts.js';
|
||||||
import { formatNativeCommand } from './format-native.js';
|
export { deleteTextCommand } from './delete-text.js';
|
||||||
import { formatTextCommand } from './format-text.js';
|
export { formatBlockCommand } from './format-block.js';
|
||||||
import { insertInlineLatex } from './insert-inline-latex.js';
|
export { formatNativeCommand } from './format-native.js';
|
||||||
import {
|
export { formatTextCommand } from './format-text.js';
|
||||||
|
export { insertInlineLatex } from './insert-inline-latex.js';
|
||||||
|
export {
|
||||||
getTextStyle,
|
getTextStyle,
|
||||||
isTextStyleActive,
|
isTextStyleActive,
|
||||||
toggleBold,
|
toggleBold,
|
||||||
@@ -29,21 +26,3 @@ export {
|
|||||||
insertContent,
|
insertContent,
|
||||||
isFormatSupported,
|
isFormatSupported,
|
||||||
} from './utils.js';
|
} from './utils.js';
|
||||||
|
|
||||||
export const textCommands: BlockCommands = {
|
|
||||||
deleteText: deleteTextCommand,
|
|
||||||
formatBlock: formatBlockCommand,
|
|
||||||
formatNative: formatNativeCommand,
|
|
||||||
formatText: formatTextCommand,
|
|
||||||
toggleBold: toggleBold,
|
|
||||||
toggleItalic: toggleItalic,
|
|
||||||
toggleUnderline: toggleUnderline,
|
|
||||||
toggleStrike: toggleStrike,
|
|
||||||
toggleCode: toggleCode,
|
|
||||||
toggleLink: toggleLink,
|
|
||||||
toggleTextStyle: toggleTextStyleCommand,
|
|
||||||
isTextStyleActive: isTextStyleActive,
|
|
||||||
getTextStyle: getTextStyle,
|
|
||||||
getTextSelection: getTextSelectionCommand,
|
|
||||||
insertInlineLatex: insertInlineLatex,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
import type { Command, TextSelection } from '@blocksuite/block-std';
|
import type { Command, TextSelection } from '@blocksuite/block-std';
|
||||||
|
|
||||||
export const insertInlineLatex: Command<
|
export const insertInlineLatex: Command<{
|
||||||
'currentTextSelection',
|
currentTextSelection?: TextSelection;
|
||||||
never,
|
textSelection?: TextSelection;
|
||||||
{
|
}> = (ctx, next) => {
|
||||||
textSelection?: TextSelection;
|
|
||||||
}
|
|
||||||
> = (ctx, next) => {
|
|
||||||
const textSelection = ctx.textSelection ?? ctx.currentTextSelection;
|
const textSelection = ctx.textSelection ?? ctx.currentTextSelection;
|
||||||
if (!textSelection || !textSelection.isCollapsed()) return;
|
if (!textSelection || !textSelection.isCollapsed()) return;
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user