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

Function QuoteBlock

packages/blocks/src/QuoteBlock.tsx:8–150  ·  view source on GitHub ↗
({ blockId } : Props)

Source from the content-addressed store, hash-verified

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

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