From 82deb607fc4ac53962d28586f820d46cdbb8ceb8 Mon Sep 17 00:00:00 2001 From: lovefield Date: Fri, 23 Aug 2024 14:39:08 +0900 Subject: [PATCH] fix: add missing type --- package.json | 2 +- src/module.ts | 5 ---- src/runtime/components/DragonEditor.vue | 5 ++-- src/runtime/components/DragonEditorViewer.vue | 2 +- src/runtime/type.d.ts | 27 +++++++++++++++++++ src/runtime/utils/convertor.ts | 15 ++++++----- 6 files changed, 40 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index b26c8cc..dcdaf5f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dragon-editor", - "version": "3.0.1", + "version": "3.0.2", "description": "Javascript WYSIWYG editor in Nuxt3!", "repository": { "type": "git", diff --git a/src/module.ts b/src/module.ts index aa4af33..509278e 100644 --- a/src/module.ts +++ b/src/module.ts @@ -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"), diff --git a/src/runtime/components/DragonEditor.vue b/src/runtime/components/DragonEditor.vue index 112e4a2..b34d9b5 100644 --- a/src/runtime/components/DragonEditor.vue +++ b/src/runtime/components/DragonEditor.vue @@ -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); } diff --git a/src/runtime/components/DragonEditorViewer.vue b/src/runtime/components/DragonEditorViewer.vue index cff035e..f5775c0 100644 --- a/src/runtime/components/DragonEditorViewer.vue +++ b/src/runtime/components/DragonEditorViewer.vue @@ -22,7 +22,7 @@ diff --git a/src/runtime/type.d.ts b/src/runtime/type.d.ts index 5247b6b..42e0b13 100644 --- a/src/runtime/type.d.ts +++ b/src/runtime/type.d.ts @@ -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[]; diff --git a/src/runtime/utils/convertor.ts b/src/runtime/utils/convertor.ts index f12fc72..6df4517 100644 --- a/src/runtime/utils/convertor.ts +++ b/src/runtime/utils/convertor.ts @@ -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; @@ -64,7 +65,7 @@ export function _setContentData(data: any[], store: any) { } // 일반 텍스트 변환 -function converteParagraphToData($child: HTMLParagraphElement) { +function converteParagraphToData($child: HTMLParagraphElement): DETextBlock { return { type: "text", textContent: $child.innerHTML, @@ -72,7 +73,7 @@ function converteParagraphToData($child: HTMLParagraphElement) { } // 제목 텍스트 변환 -function converteHeadingToData($child: HTMLHeadingElement, level: number) { +function converteHeadingToData($child: HTMLHeadingElement, level: number): DEHeadingBlock { return { type: "heading", level: level, @@ -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) => { @@ -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; }),