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

Function SubSubHeaderBlock

packages/blocks/src/SubSubHeaderBlock.tsx:14–182  ·  view source on GitHub ↗
({ blockId } : Props)

Source from the content-addressed store, hash-verified

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