MCPcopy Create free account
hub / github.com/PatoSala/react-native-blocks / insertBlock

Function insertBlock

packages/core/src/components/BlocksContext.tsx:97–111  ·  view source on GitHub ↗

* Inserts a block into the content array of the parent block. If a position object is provided, the block will be inserted at the specified position.

(newBlock: Block, position?: { prevBlockId?: string | undefined, nextBlockId?: string | undefined })

Source from the content-addressed store, hash-verified

95 * Inserts a block into the content array of the parent block. If a position object is provided, the block will be inserted at the specified position.
96 */
97 function insertBlock(newBlock: Block, position?: { prevBlockId?: string | undefined, nextBlockId?: string | undefined }) {
98 const updatedBlock = updateBlockData(blocksRef.current[newBlock.parent], {
99 content: insertBlockIdIntoContent(blocksRef.current[newBlock.parent].content, newBlock.id, {
100 prevBlockId: position?.prevBlockId,
101 nextBlockId: position?.nextBlockId
102 })
103 });
104 blocksRef.current[newBlock.parent] = updatedBlock;
105 blocksRef.current[newBlock.id] = newBlock;
106
107 setBlocksOrder(prevState => [
108 rootContent[0],
109 ...blocksRef.current[rootContent[0]].content
110 ]);
111 }
112
113 function insertBlockV2(newBlock: Block, position?: { prevBlockId?: string | undefined, nextBlockId?: string | undefined }) {
114 const updatedBlock = updateBlockData(blocksRef.current[newBlock.parent], {

Callers 11

handleSubmitEditingFunction · 0.85
handleSubmitEditingFunction · 0.85
handleSubmitEditingFunction · 0.85
handleSubmitEditingFunction · 0.85
handleSubmitEditingFunction · 0.85
handleSubmitEditingFunction · 0.85
handleSubmitEditingFunction · 0.85
handleSubmitEditingFunction · 0.85
handleSubmitEditingFunction · 0.85
handleInsertBlockFunction · 0.85
AppFunction · 0.85

Calls 2

updateBlockDataFunction · 0.90
insertBlockIdIntoContentFunction · 0.90

Tested by

no test coverage detected