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

Function SubHeaderBlock

packages/blocks/src/SubHeaderBlock.tsx:15–183  ·  view source on GitHub ↗
({ blockId } : Props)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected