Skip to content

Commit

Permalink
fix: block data
Browse files Browse the repository at this point in the history
  • Loading branch information
lovefields committed Jul 2, 2023
1 parent 1d572d1 commit 92d9323
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
48 changes: 38 additions & 10 deletions src/runtime/core/components/editor/TextBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -79,8 +104,11 @@ function updateBlockData() {
}
}
});
data.value.content = $block.value.innerHTML;
emit("update:modelValue", data.value);
}
}, 100);
}
} else {
emit("update:modelValue", data.value);
}
Expand Down

0 comments on commit 92d9323

Please sign in to comment.