-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8007e5e
commit 06d7465
Showing
9 changed files
with
227 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<template> | ||
<div> | ||
Comment! | ||
|
||
<button @click="addOption">옵션!</button> | ||
<button @click="getStatus">상태!</button> | ||
<div class="editor"> | ||
<DragonEditorComment v-model="contentData" ref="editor" /> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { ref, onMounted } from "#imports"; | ||
const contentData = ref({ | ||
type: "comment", | ||
classList: [], | ||
content: "" | ||
}); | ||
const editor = ref(); | ||
function addOption() { | ||
editor.value.setStyles("font-3322"); | ||
getStatus(); | ||
} | ||
function getStatus() { | ||
console.log(editor.value.getCursorClassList()); | ||
} | ||
</script> | ||
|
||
<style> | ||
.editor { | ||
width: 800px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import {defineNuxtModule, addComponentsDir, createResolver} from '@nuxt/kit' | ||
import {defineNuxtModule, addComponentsDir, createResolver} from "@nuxt/kit" | ||
|
||
export default defineNuxtModule({ | ||
meta: { | ||
name: 'dragon-editor', | ||
name: "dragon-editor", | ||
}, | ||
setup(options, nuxt) { | ||
const resolver = createResolver(import.meta.url) | ||
|
||
addComponentsDir(resolver.resolve('./shared/components')); | ||
addComponentsDir(resolver.resolve("./shared/components")); | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,129 @@ | ||
<template></template> | ||
<template> | ||
<div class="dragon-editor"> | ||
<p class="d-text-block" :class="data.classList" contenteditable v-html="data.content" @keydown="textKeyboardEvent" | ||
@paste="pasteEvent" ref="$block"></p> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { ref, unref } from "#imports"; | ||
import { | ||
keyboardEvent, | ||
setCursor, | ||
pasteText, | ||
styleSettings, | ||
getArrangementCursorData, | ||
getClipboardData, | ||
getCursor, | ||
findEditableElement | ||
} from "../../core/utils/index"; | ||
import { commentBlock } from "../../types/index"; | ||
const $block = ref(); | ||
const data = ref<commentBlock>({ | ||
type: "comment", | ||
classList: [], | ||
content: "", | ||
}); | ||
const props = defineProps<{ modelValue: commentBlock }>(); | ||
const emit = defineEmits<{ | ||
(e: "update:modelValue", modelValue: commentBlock): void; | ||
}>(); | ||
data.value = unref(props.modelValue) as commentBlock; | ||
function textKeyboardEvent(e: KeyboardEvent) { | ||
keyboardEvent("comment", e, emit); | ||
} | ||
function pasteEvent(e: ClipboardEvent) { | ||
e.preventDefault(); | ||
const data = getClipboardData(e.clipboardData as DataTransfer); | ||
if (data.type === "text") { | ||
pasteText("text", data.value as string); | ||
} | ||
} | ||
// export event | ||
function updateBlockData() { | ||
// 데이터 정규화 및 검수 | ||
const blockClassList = [...$block.value.classList]; | ||
blockClassList.splice(0, 1); | ||
const pushList = blockClassList.filter( | ||
(item) => data.value.classList.indexOf(item) === -1 | ||
); | ||
data.value.classList = data.value.classList.concat(pushList); | ||
// 커서위치 재지정 | ||
if ($block.value.innerHTML.length > 0) { | ||
const cursorData = getArrangementCursorData(); | ||
data.value.content = $block.value.innerHTML; | ||
emit("update:modelValue", data.value); | ||
setTimeout(() => { | ||
setCursor( | ||
$block.value.childNodes[cursorData.childCount], | ||
cursorData.length | ||
); | ||
// 빈 태그 삭제 | ||
$block.value.childNodes.forEach((child: ChildNode) => { | ||
if ( | ||
child.constructor.name !== "Text" && | ||
child.textContent === "" | ||
) { | ||
child.remove(); | ||
} | ||
}); | ||
}, 100); | ||
} else { | ||
emit("update:modelValue", data.value); | ||
} | ||
} | ||
function focus() { | ||
setCursor($block.value, 0); | ||
} | ||
function setStyles(kind: string) { | ||
data.value = styleSettings(kind, data.value, $block.value); | ||
setTimeout(() => { | ||
updateBlockData(); | ||
}, 250); | ||
} | ||
function getCursorClassList(className: string) { | ||
const cursorData = getCursor(); | ||
let value: string[] = []; | ||
if (cursorData.type === "Caret") { | ||
const type = (cursorData.startNode as Node).constructor.name; | ||
const editableElement = findEditableElement(cursorData.startNode as Node); | ||
let $target = cursorData.startNode as HTMLElement; | ||
if (type === "Text") { | ||
$target = (cursorData.startNode as HTMLElement).parentNode as HTMLElement; | ||
} | ||
if ($target !== editableElement) { | ||
value = [...$target.classList]; | ||
} | ||
} | ||
return value; | ||
} | ||
defineExpose({ | ||
updateBlockData, | ||
focus, | ||
setStyles, | ||
getCursorClassList | ||
}); | ||
</script> | ||
|
||
<style> | ||
@import "../../core/style/common.css"; | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters