@wyttime04/react-vditor 1.0.1 → 1.0.2
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.
- package/dist/VditorPreview.js +5 -2
- package/package.json +1 -1
package/dist/VditorPreview.js
CHANGED
|
@@ -20,11 +20,14 @@ export const VditorPreview = props => {
|
|
|
20
20
|
// 選項常常是每次 render 都新建的物件;用內容比較,避免每次 render 都重新渲染
|
|
21
21
|
const optionsKey = JSON.stringify(options);
|
|
22
22
|
React.useEffect(() => {
|
|
23
|
-
|
|
23
|
+
// 每次渲染使用新的子元素,隔離前一次 Vditor.preview 未完成的非同步處理(如程式碼上色)
|
|
24
|
+
const target = document.createElement("div");
|
|
25
|
+
elementRef.current.replaceChildren(target);
|
|
26
|
+
VditorCore.preview(target, value, previewOptions(options));
|
|
24
27
|
}, [value, optionsKey]); // options 以內容比較(optionsKey),不放物件本身
|
|
25
28
|
|
|
26
29
|
// 主題只看外層容器的 class(index.css 裡局部化的樣式),換主題不用重新渲染;
|
|
27
|
-
//
|
|
30
|
+
// 內層的子元素交給 Vditor.preview,它會在上面加 vditor-reset
|
|
28
31
|
const wrapperClassName = ["react-vditor-preview", themeClassName(theme), className].filter(Boolean).join(" ");
|
|
29
32
|
return /*#__PURE__*/React.createElement("div", {
|
|
30
33
|
className: wrapperClassName,
|