From 92d93239d67333ec0f2575ab71ffeb1d42d0e1bb Mon Sep 17 00:00:00 2001 From: Lovefields Date: Sun, 2 Jul 2023 10:23:23 +0900 Subject: [PATCH] fix: block data --- package.json | 2 +- .../core/components/editor/TextBlock.vue | 48 +++++++++++++++---- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index f8edbf7..6d01af9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dragon-editor", - "version": "2.0.0-beta.2.1", + "version": "2.0.0-beta.2.1.1", "description": "WYSIWYG editor on Nuxt.js", "repository": { "type": "git", diff --git a/src/runtime/core/components/editor/TextBlock.vue b/src/runtime/core/components/editor/TextBlock.vue index b157482..db71c9d 100644 --- a/src/runtime/core/components/editor/TextBlock.vue +++ b/src/runtime/core/components/editor/TextBlock.vue @@ -49,16 +49,41 @@ function updateBlockData() { // 커서위치 재지정 if ($block.value.innerHTML.length > 0) { - const cursorData = getArrangementCursorData(props.cursorData); - - data.value.content = $block.value.innerHTML; - emit("update:modelValue", data.value); - - setTimeout(() => { + if (props.cursorData.endOffset !== null) { + const cursorData = getArrangementCursorData(props.cursorData); + + data.value.content = $block.value.innerHTML; + emit("update:modelValue", data.value); + + setTimeout(() => { + if ($block.value) { + setCursor($block.value.childNodes[cursorData.childCount], cursorData.length); + + // 구조 검수 + $block.value.childNodes.forEach((child: ChildNode) => { + const $child = child as HTMLElement; + + if (child.constructor.name !== "Text") { + // 텍스트가 아닐경우 + if (child.constructor.name !== "HTMLBRElement") { + // br 태그 유지 + if (child.textContent === "") { + // 빈 태그 삭제 + child.remove(); + } else if ($child.classList.length === 0) { + // 클레스 없는 엘리먼트 처리 + $child.insertAdjacentHTML("afterend", $child.innerHTML); + child.remove(); + } + } else { + $child.removeAttribute("class"); + } + } + }); + } + }, 100); + } else { if ($block.value) { - setCursor($block.value.childNodes[cursorData.childCount], cursorData.length); - - // 구조 검수 $block.value.childNodes.forEach((child: ChildNode) => { const $child = child as HTMLElement; @@ -79,8 +104,11 @@ function updateBlockData() { } } }); + + data.value.content = $block.value.innerHTML; + emit("update:modelValue", data.value); } - }, 100); + } } else { emit("update:modelValue", data.value); }