@@ -132,25 +132,31 @@ export const NumberedView = ({ block, editor }: CreateView) => {
|
|||||||
|
|
||||||
// Move children to new block
|
// Move children to new block
|
||||||
const children = await block.children();
|
const children = await block.children();
|
||||||
await block.removeChildren();
|
|
||||||
|
|
||||||
const next_node = await editor.createBlock(
|
const nextBlock = await editor.createBlock(
|
||||||
Protocol.Block.Type.numbered
|
Protocol.Block.Type.numbered
|
||||||
);
|
);
|
||||||
if (!next_node) {
|
if (!nextBlock) {
|
||||||
throw new Error('Failed to create todo block');
|
throw new Error('Failed to create todo block');
|
||||||
}
|
}
|
||||||
await next_node.append(...children);
|
if (editor.getRootBlockId() === block.id) {
|
||||||
await next_node.setProperties({
|
// 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,
|
text: { value: after } as ContentColumnValue,
|
||||||
});
|
});
|
||||||
await block.setProperties({
|
await block.setProperties({
|
||||||
text: { value: before } as ContentColumnValue,
|
text: { value: before } as ContentColumnValue,
|
||||||
});
|
});
|
||||||
await block.after(next_node);
|
await block.after(nextBlock);
|
||||||
|
editor.selectionManager.activeNodeByNodeId(nextBlock.id);
|
||||||
editor.selectionManager.activeNodeByNodeId(next_node.id);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
const on_tab: TextProps['handleTab'] = async ({ isShiftKey }) => {
|
const on_tab: TextProps['handleTab'] = async ({ isShiftKey }) => {
|
||||||
|
|||||||
@@ -88,13 +88,21 @@ export const TodoView = ({ block, editor }: CreateView) => {
|
|||||||
Boolean
|
Boolean
|
||||||
) as AsyncBlock[];
|
) as AsyncBlock[];
|
||||||
|
|
||||||
const next_node = await editor.createBlock(Protocol.Block.Type.todo);
|
const nextBlock = await editor.createBlock(Protocol.Block.Type.todo);
|
||||||
if (!next_node) {
|
if (!nextBlock) {
|
||||||
throw new Error('Failed to create todo block');
|
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 block.removeChildren();
|
||||||
await next_node.append(...children);
|
await nextBlock.append(...children);
|
||||||
await next_node.setProperties({
|
await nextBlock.setProperties({
|
||||||
text: { value: after } as ContentColumnValue,
|
text: { value: after } as ContentColumnValue,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -102,9 +110,9 @@ export const TodoView = ({ block, editor }: CreateView) => {
|
|||||||
text: { value: before } as ContentColumnValue,
|
text: { value: before } as ContentColumnValue,
|
||||||
collapsed: { value: false },
|
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;
|
return true;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { genErrorObj } from '@toeverything/utils';
|
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';
|
import { RenderBlockProps } from './RenderBlock';
|
||||||
|
|
||||||
type BlockRenderProps = {
|
type BlockRenderProps = {
|
||||||
blockRender: (args: RenderBlockProps) => JSX.Element;
|
blockRender: ComponentType<RenderBlockProps>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const BlockRenderContext = createContext<BlockRenderProps>(
|
export const BlockRenderContext = createContext<BlockRenderProps>(
|
||||||
|
|||||||
Reference in New Issue
Block a user