|
1 | 1 | /** @jsx jsx */
|
2 | 2 | /** @jsxRuntime classic */
|
3 | 3 | import { jsx, css, SerializedStyles } from '@emotion/react';
|
4 |
| -import { useEffect, useRef, FormEvent, KeyboardEvent } from 'react'; |
| 4 | +import { useEffect, useRef, FormEvent, KeyboardEvent, useState } from 'react'; |
5 | 5 | import { useRecoilState, useRecoilValue } from 'recoil';
|
6 | 6 |
|
7 | 7 | import { blockRefState, throttleState, blockMapState } from '@/stores';
|
8 | 8 | import { Block, BlockType } from '@/schemes';
|
| 9 | +import { updateBlock } from '@/utils'; |
9 | 10 | import {
|
10 | 11 | regex,
|
11 | 12 | fontSize,
|
@@ -57,6 +58,7 @@ function BlockContent(blockDTO: Block) {
|
57 | 58 | const caretRef = useRef(0);
|
58 | 59 | const listCnt = useRef(1);
|
59 | 60 | const [Dispatcher] = useCommand();
|
| 61 | + const [isBlur, setIsBlur] = useState(false); |
60 | 62 |
|
61 | 63 | const indexInSibling: number = blockMap[
|
62 | 64 | blockDTO.parentId
|
@@ -165,6 +167,13 @@ function BlockContent(blockDTO: Block) {
|
165 | 167 | }
|
166 | 168 | };
|
167 | 169 |
|
| 170 | + useEffect(() => { |
| 171 | + (async () => { |
| 172 | + const { block: updatedBlock } = await updateBlock(blockDTO); |
| 173 | + setBlockMap({ ...blockMap, [blockDTO.id]: updatedBlock }); |
| 174 | + })(); |
| 175 | + }, [isBlur]); |
| 176 | + |
168 | 177 | useEffect(() => {
|
169 | 178 | blockRefState[blockDTO.id] = contentEditableRef;
|
170 | 179 | return () => {
|
@@ -208,6 +217,7 @@ function BlockContent(blockDTO: Block) {
|
208 | 217 | placeholder={placeHolder[blockDTO.type]}
|
209 | 218 | onInput={handleValue}
|
210 | 219 | onKeyUp={handleKeyUp}
|
| 220 | + onBlur={() => setIsBlur(!isBlur)} |
211 | 221 | >
|
212 | 222 | {blockDTO.value}
|
213 | 223 | </div>
|
|
0 commit comments