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

Function BulletBlock

packages/blocks/src/BulletBlock.tsx:17–202  ·  view source on GitHub ↗
({ blockId } : Props)

Source from the content-addressed store, hash-verified

15}
16
17export function BulletBlock({ blockId } : Props) {
18 const { getTextInputProps, getValue, getSelection } = useTextInput(blockId);
19 const { inputRefs, textBasedBlocks } = useTextBlocksContext();
20 const {
21 blocks,
22 insertBlock,
23 updateBlock,
24 updateBlockV2,
25 removeBlock
26 } = useBlocksContext();
27
28 const handleSubmitEditing = () => {
29 const value = getValue();
30 const selection = getSelection();
31
32 if (value.length === 0) {
33 inputRefs.current["ghostInput"]?.current.focus();
34
35 setTimeout(() => {
36 updateBlockV2(blockId, {
37 type: "text",
38 properties: {
39 title: value
40 }
41 });
42 requestAnimationFrame(() => {
43 inputRefs.current[blockId]?.current.focus(); // Maybe the "ghostTextInput" hack should be done inside this function.
44 });
45 }, 0);
46 return;
47 }
48
49 if (selection.start === 0 && selection.end === 0) {
50 const newBlock = createBlock({
51 type: "bullet",
52 properties: {
53 title: ""
54 },
55 parent: blocks[blockId].parent,
56 content: []
57 });
58
59 insertBlock(newBlock, {
60 nextBlockId: blockId
61 });
62 return;
63 }
64
65 if (selection.start === value.length && selection.end === value.length) {
66 const newBlock = createBlock({
67 type: "bullet",
68 properties: {
69 title: ""
70 },
71 parent: blocks[blockId].parent,
72 content: []
73 });
74

Callers

nothing calls this directly

Calls 4

useTextInputFunction · 0.90
useTextBlocksContextFunction · 0.90
useBlocksContextFunction · 0.90
getTextInputPropsFunction · 0.85

Tested by

no test coverage detected