@team-monolith/cds 0.29.17 → 0.29.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
-
import { useCallback, useEffect, useRef } from "react";
|
|
11
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
12
12
|
import { createReactEditorJS } from "react-editor-js";
|
|
13
13
|
import Layout from "./Layout";
|
|
14
14
|
import TOOLS from "./tools";
|
|
@@ -17,10 +17,13 @@ export function ReactEditorJS(props) {
|
|
|
17
17
|
const { className, readOnly = false, blocks, onChange, onError, onInitialize, } = props;
|
|
18
18
|
const ReactEditorJS = createReactEditorJS();
|
|
19
19
|
const editorCore = useRef(null);
|
|
20
|
+
const [isInitialized, setIsInitialized] = useState(false);
|
|
20
21
|
const handleInitialize = useCallback((instance) => __awaiter(this, void 0, void 0, function* () {
|
|
21
22
|
try {
|
|
23
|
+
setIsInitialized(false);
|
|
22
24
|
yield instance.dangerouslyLowLevelInstance.isReady;
|
|
23
25
|
editorCore.current = instance;
|
|
26
|
+
setIsInitialized(true);
|
|
24
27
|
onInitialize === null || onInitialize === void 0 ? void 0 : onInitialize(instance);
|
|
25
28
|
}
|
|
26
29
|
catch (e) {
|
|
@@ -49,13 +52,13 @@ export function ReactEditorJS(props) {
|
|
|
49
52
|
// 따라서, highly recommended인 "defaultValue" 사용을 유지하고 blocks가 변경될 때마다
|
|
50
53
|
// useEffect를 사용하여 editorCore의 render 메서드를 호출하여 리렌더링을 수행하도록 구현합니다.
|
|
51
54
|
useEffect(() => {
|
|
52
|
-
if (!editorCore.current || !readOnly) {
|
|
55
|
+
if (!isInitialized || !editorCore.current || !readOnly) {
|
|
53
56
|
return;
|
|
54
57
|
}
|
|
55
58
|
editorCore.current.render({
|
|
56
59
|
blocks,
|
|
57
60
|
});
|
|
58
|
-
}, [blocks, readOnly]);
|
|
61
|
+
}, [blocks, readOnly, isInitialized]);
|
|
59
62
|
// readOnly가 변경되면 ReactEditorJS를 다시 마운트하기 위해 key를 변경합니다.
|
|
60
63
|
// readOnly 모드에서는 onChange를 전달할 수 없어서 케이스를 분리합니다.
|
|
61
64
|
if (readOnly) {
|