Skip to content

Commit

Permalink
fix: add missing type
Browse files Browse the repository at this point in the history
  • Loading branch information
lovefields committed Aug 23, 2024
1 parent 4530440 commit 82deb60
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 16 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": "3.0.1",
"version": "3.0.2",
"description": "Javascript WYSIWYG editor in Nuxt3!",
"repository": {
"type": "git",
Expand Down
5 changes: 0 additions & 5 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ export default defineNuxtModule({
filePath: resolver.resolve("./runtime/components/DragonEditor"),
});

// addComponent({
// name: 'DragonEditorComment',
// filePath: resolver.resolve('./runtime/components/DragonEditorComment')
// });

addComponent({
name: "DragonEditorViewer",
filePath: resolver.resolve("./runtime/components/DragonEditorViewer"),
Expand Down
5 changes: 3 additions & 2 deletions src/runtime/components/DragonEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,16 @@ function setDecoration(type: string) {
_setNodeStyle(`de-${type}`, editorStore);
}
function getContentData() {
function getContentData(): DEContentData {
if (editorStore.$content !== null) {
return _getContentData(editorStore.$content);
} else {
console.error("[DragonEditor] Con't find content Element.");
return [];
}
}
function setContentData(data: any[]) {
function setContentData(data: DEContentData) {
_setContentData(data, editorStore);
}
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/components/DragonEditorViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<script setup lang="ts">
const props = defineProps<{
content: any[];
content: DEContentData;
}>();
</script>

Expand Down
27 changes: 27 additions & 0 deletions src/runtime/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,30 @@ interface DEArrangeCursorData {
endNodeIdx: number;
endOffset: number;
}

interface DETextBlock {
type: "text";
textContent: string;
}

interface DEHeadingBlock {
type: "heading";
level: number;
id: string;
textContent: string;
}

interface DEUListBlock {
type: "ul";
child: string[];
}

interface DEOListBlock {
type: "ol";
pattern: "a" | "i" | "1" | "A" | "I";
child: string[];
}

type DEContent = DETextBlock | DEHeadingBlock | DEUListBlock | DEOListBlock;

type DEContentData = DEContent[];
15 changes: 8 additions & 7 deletions src/runtime/utils/convertor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { _createTextBlock, _createHeadingBlock, _createListBlock } from "./block";

export function _getContentData($content: HTMLDivElement): any[] {
// 화면을 데이터로 변환
export function _getContentData($content: HTMLDivElement): DEContentData {
const childList: HTMLCollection = $content.children;
const data: any[] = [];
const data: DEContentData = [];

[...childList].forEach(($child: Element) => {
const tagName: string = $child.tagName;
Expand Down Expand Up @@ -64,15 +65,15 @@ export function _setContentData(data: any[], store: any) {
}

// 일반 텍스트 변환
function converteParagraphToData($child: HTMLParagraphElement) {
function converteParagraphToData($child: HTMLParagraphElement): DETextBlock {
return {
type: "text",
textContent: $child.innerHTML,
};
}

// 제목 텍스트 변환
function converteHeadingToData($child: HTMLHeadingElement, level: number) {
function converteHeadingToData($child: HTMLHeadingElement, level: number): DEHeadingBlock {
return {
type: "heading",
level: level,
Expand All @@ -82,7 +83,7 @@ function converteHeadingToData($child: HTMLHeadingElement, level: number) {
}

// 순서 없는 리스트 변환
function converteUListToData($child: HTMLUListElement) {
function converteUListToData($child: HTMLUListElement): DEUListBlock {
return {
type: "ul",
child: [...$child.children].map(($li: Element) => {
Expand All @@ -92,10 +93,10 @@ function converteUListToData($child: HTMLUListElement) {
}

// 순서 있는 리스트 변환
function converteOListToData($child: HTMLOListElement) {
function converteOListToData($child: HTMLOListElement): DEOListBlock {
return {
type: "ol",
pattern: $child.type,
pattern: $child.type as "a" | "i" | "1" | "A" | "I",
child: [...$child.children].map(($li: Element) => {
return $li.innerHTML;
}),
Expand Down

0 comments on commit 82deb60

Please sign in to comment.