mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-17 01:56:27 +08:00
@@ -132,25 +132,31 @@ export const NumberedView = ({ block, editor }: CreateView) => {
|
||||
|
||||
// Move children to new block
|
||||
const children = await block.children();
|
||||
await block.removeChildren();
|
||||
|
||||
const next_node = await editor.createBlock(
|
||||
const nextBlock = await editor.createBlock(
|
||||
Protocol.Block.Type.numbered
|
||||
);
|
||||
if (!next_node) {
|
||||
if (!nextBlock) {
|
||||
throw new Error('Failed to create todo block');
|
||||
}
|
||||
await next_node.append(...children);
|
||||
await next_node.setProperties({
|
||||
if (editor.getRootBlockId() === block.id) {
|
||||
// If the block is the root block,
|
||||
// new block can not append as next sibling,
|
||||
// all new blocks should be append as children.
|
||||
await block.insert(0, [nextBlock]);
|
||||
editor.selectionManager.activeNodeByNodeId(nextBlock.id);
|
||||
return true;
|
||||
}
|
||||
await block.removeChildren();
|
||||
await nextBlock.append(...children);
|
||||
await nextBlock.setProperties({
|
||||
text: { value: after } as ContentColumnValue,
|
||||
});
|
||||
await block.setProperties({
|
||||
text: { value: before } as ContentColumnValue,
|
||||
});
|
||||
await block.after(next_node);
|
||||
|
||||
editor.selectionManager.activeNodeByNodeId(next_node.id);
|
||||
|
||||
await block.after(nextBlock);
|
||||
editor.selectionManager.activeNodeByNodeId(nextBlock.id);
|
||||
return true;
|
||||
};
|
||||
const on_tab: TextProps['handleTab'] = async ({ isShiftKey }) => {
|
||||
|
||||
@@ -88,13 +88,21 @@ export const TodoView = ({ block, editor }: CreateView) => {
|
||||
Boolean
|
||||
) as AsyncBlock[];
|
||||
|
||||
const next_node = await editor.createBlock(Protocol.Block.Type.todo);
|
||||
if (!next_node) {
|
||||
const nextBlock = await editor.createBlock(Protocol.Block.Type.todo);
|
||||
if (!nextBlock) {
|
||||
throw new Error('Failed to create todo block');
|
||||
}
|
||||
if (editor.getRootBlockId() === block.id) {
|
||||
// If the block is the root block,
|
||||
// new block can not append as next sibling,
|
||||
// all new blocks should be append as children.
|
||||
await block.insert(0, [nextBlock]);
|
||||
editor.selectionManager.activeNodeByNodeId(nextBlock.id);
|
||||
return true;
|
||||
}
|
||||
await block.removeChildren();
|
||||
await next_node.append(...children);
|
||||
await next_node.setProperties({
|
||||
await nextBlock.append(...children);
|
||||
await nextBlock.setProperties({
|
||||
text: { value: after } as ContentColumnValue,
|
||||
});
|
||||
|
||||
@@ -102,9 +110,9 @@ export const TodoView = ({ block, editor }: CreateView) => {
|
||||
text: { value: before } as ContentColumnValue,
|
||||
collapsed: { value: false },
|
||||
});
|
||||
await block.after(next_node);
|
||||
await block.after(nextBlock);
|
||||
|
||||
editor.selectionManager.activeNodeByNodeId(next_node.id);
|
||||
editor.selectionManager.activeNodeByNodeId(nextBlock.id);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { genErrorObj } from '@toeverything/utils';
|
||||
import { createContext, PropsWithChildren, useContext } from 'react';
|
||||
import type { ComponentType, PropsWithChildren } from 'react';
|
||||
import { createContext, useContext } from 'react';
|
||||
import { RenderBlockProps } from './RenderBlock';
|
||||
|
||||
type BlockRenderProps = {
|
||||
blockRender: (args: RenderBlockProps) => JSX.Element;
|
||||
blockRender: ComponentType<RenderBlockProps>;
|
||||
};
|
||||
|
||||
export const BlockRenderContext = createContext<BlockRenderProps>(
|
||||
|
||||
Reference in New Issue
Block a user