dragon-editor 3.2.1 → 3.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "dragon-editor",
3
3
  "configKey": "dragon-editor",
4
- "version": "3.2.1"
4
+ "version": "3.2.3"
5
5
  }
package/dist/module.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { defineNuxtModule, createResolver, addComponent, addTypeTemplate, installModule } from '@nuxt/kit';
1
+ import { defineNuxtModule, createResolver, addComponent, addTypeTemplate, installModule, addPluginTemplate } from '@nuxt/kit';
2
2
 
3
3
  const module = defineNuxtModule({
4
4
  meta: {
@@ -20,6 +20,11 @@ const module = defineNuxtModule({
20
20
  write: true
21
21
  });
22
22
  await installModule("@pinia/nuxt");
23
+ addPluginTemplate({
24
+ src: resolver.resolve("./runtime/plugin.mjs"),
25
+ filename: "hljs.plugin.mjs"
26
+ });
27
+ nuxt.options.build.transpile.push("highlight.js");
23
28
  }
24
29
  });
25
30
 
@@ -85,21 +85,21 @@
85
85
  </div>
86
86
  </div>
87
87
 
88
- <div class="de-control-bar" :class="{ '--active': editorStore.controlBar.active === true }" :style="{ top: `${editorStore.controlBar.y}px`, left: `${editorStore.controlBar.x}px` }" ref="$controlBar">
88
+ <div v-if="editorStore.$currentBlock !== null" class="de-control-bar" :class="{ '--active': editorStore.controlBar.active === true }" :style="{ top: `${editorStore.controlBar.y}px`, left: `${editorStore.controlBar.x}px` }" ref="$controlBar">
89
89
  <div v-if="['code'].includes(curruntType) === true" class="de-col">
90
90
  <p class="de-name">Theme :</p>
91
91
  <select class="de-selector" v-model="codeBlockTheme" @change="codeBlockThemeChangeEvent">
92
92
  <option v-for="(item, i) in _getCodeBlockTheme()" :value="item.code" :key="`codeBlockTheme-${i}`">{{ item.text }}</option>
93
93
  </select>
94
94
  </div>
95
- <!--
95
+
96
96
  <div v-if="['code'].includes(curruntType) === true" class="de-col">
97
97
  <p class="de-name">Language :</p>
98
98
  <select class="de-selector" v-model="codeblockLanguage" @change="codeblockLanguageChangeEvent">
99
99
  <option v-for="(item, i) in _getCodeBlockLanguage()" :value="item.code" :key="`codeBlockLanuage-${i}`">{{ item.text }}</option>
100
100
  </select>
101
101
  </div>
102
- -->
102
+
103
103
  <div v-if="['list'].includes(curruntType) === true" class="de-col">
104
104
  <p class="de-name">List Style :</p>
105
105
  <select class="de-selector" v-model="listBlockStyle" @change="listBlockStyleChangeEvent">
@@ -133,7 +133,7 @@ import { _findScrollingElement, _findContentEditableElement } from "../utils/ele
133
133
  import { _elementKeyEvent, _hotKeyEvent, _copyEvent, _pasteEvent } from "../utils/keyboardEvent";
134
134
  import { _getBlockType, _createTextBlock, _createHeadingBlock, _createListBlock, _createImageBlock, _createCustomBlock, _createCodeBlock } from "../utils/block";
135
135
  import { _setNodeStyle, _setTextAlign } from "../utils/style";
136
- import { _setCursorData, _clenupCursor } from "../utils/cursor";
136
+ import { _setCursor, _setCursorData, _clenupCursor } from "../utils/cursor";
137
137
  import { _getContentData, _setContentData } from "../utils/convertor";
138
138
  import { _addBlockToContent } from "../utils/content";
139
139
  import "../type.d.ts";
@@ -306,7 +306,18 @@ function checkOthersideClick(event: MouseEvent) {
306
306
  // 블럭 삭제
307
307
  function deleteBlock() {
308
308
  if (editorStore.$currentBlock !== null) {
309
+ const childCount: number = editorStore.$content?.childElementCount ?? 1;
310
+
309
311
  editorStore.$currentBlock.remove();
312
+ editorStore.setCurrentBlock(null);
313
+
314
+ if (childCount < 2) {
315
+ // 모든 엘리먼트를 지우려는 경우
316
+ const $block = _createTextBlock();
317
+
318
+ editorStore.$content?.insertAdjacentElement("beforeend", $block);
319
+ _setCursor($block, 0);
320
+ }
310
321
  }
311
322
  }
312
323
 
@@ -0,0 +1,2 @@
1
+ declare function _default(nuxtApp: any): void;
2
+ export default _default;
@@ -0,0 +1,6 @@
1
+ import hljs from "highlight.js";
2
+
3
+ export default (nuxtApp) => {
4
+ nuxtApp.vueApp.provide("hljs", hljs);
5
+ nuxtApp.provide("hljs", hljs);
6
+ };
@@ -4,7 +4,7 @@ export declare const useEditorStore: import("pinia").StoreDefinition<"editorStor
4
4
  setContentElement(value: HTMLDivElement): void;
5
5
  setParentWrapElement(value: HTMLElement | Window): void;
6
6
  setCursorData(data: DEditorCursor): void;
7
- setCurrentBlock(block: HTMLElement): void;
7
+ setCurrentBlock(block: HTMLElement | null): void;
8
8
  setContrulBar(value: HTMLDivElement): void;
9
9
  controlBarActive(): void;
10
10
  controlBarDeactive(): void;
@@ -37,10 +37,12 @@ export const useEditorStore = defineStore("editorStore", {
37
37
  this.controlBar.$element = value;
38
38
  },
39
39
  controlBarActive() {
40
- const currentRect = this.$currentBlock.getBoundingClientRect();
41
- this.controlBar.active = true;
42
- this.controlBar.x = Math.floor(currentRect.x + currentRect.width / 2);
43
- this.controlBar.y = Math.floor(currentRect.y - 50);
40
+ if (this.$currentBlock !== null) {
41
+ const currentRect = this.$currentBlock.getBoundingClientRect();
42
+ this.controlBar.active = true;
43
+ this.controlBar.x = Math.floor(currentRect.x + currentRect.width / 2);
44
+ this.controlBar.y = Math.floor(currentRect.y - 50);
45
+ }
44
46
  },
45
47
  controlBarDeactive() {
46
48
  this.controlBar.active = false;
@@ -1,4 +1,5 @@
1
1
  import { _getBlockType } from "./block.mjs";
2
+ import hljs from "highlight.js";
2
3
  import "../type.d.ts";
3
4
  export function _getCodeBlockTheme() {
4
5
  return [
@@ -134,6 +135,9 @@ export function _setCodeBlockLanguage(store, lang) {
134
135
  if (type === "code") {
135
136
  const $langText = $element.querySelector(".de-language");
136
137
  const $code = $element.querySelector(".de-code-content");
138
+ const convert = hljs.highlight($code.textContent ?? "", { language: lang });
139
+ $langText.textContent = convert._top.name ?? "";
140
+ $code.innerHTML = convert.value;
137
141
  }
138
142
  }
139
143
  }
@@ -28,7 +28,7 @@ export function _elementKeyEvent(event, store) {
28
28
  keyEventCount += 1;
29
29
  setTimeout(() => {
30
30
  keyEventCount = 0;
31
- }, 150);
31
+ }, 200);
32
32
  break;
33
33
  case "Backspace":
34
34
  elementBackspaceEvent(event, store);
@@ -44,7 +44,7 @@ export function _elementKeyEvent(event, store) {
44
44
  keyEventCount += 1;
45
45
  setTimeout(() => {
46
46
  keyEventCount = 0;
47
- }, 150);
47
+ }, 200);
48
48
  break;
49
49
  case "Space":
50
50
  break;
@@ -187,12 +187,15 @@ function defaultBlockEnterEvent(store, $element) {
187
187
  const text = node.textContent;
188
188
  const preSpan = document.createElement("span");
189
189
  const nextSpan = document.createElement("span");
190
+ const nextText = text.slice(store.cursorData.startOffset);
190
191
  preSpan.classList.add(...originalClassList);
191
192
  preSpan.textContent = text.slice(0, store.cursorData.startOffset);
192
193
  preStructure.push(preSpan);
193
- nextSpan.classList.add(...originalClassList);
194
- nextSpan.textContent = text.slice(store.cursorData.startOffset);
195
- nextStructure.push(nextSpan);
194
+ if (nextText !== "") {
195
+ nextSpan.classList.add(...originalClassList);
196
+ nextSpan.textContent = nextText;
197
+ nextStructure.push(nextSpan);
198
+ }
196
199
  }
197
200
  }
198
201
  });
@@ -292,7 +295,7 @@ function defaultBlockEnterEvent(store, $element) {
292
295
  }
293
296
  });
294
297
  }
295
- const $nextBlock = _createTextBlock(store);
298
+ const $nextBlock = _createTextBlock({ type: "text", classList: [], textContent: "" });
296
299
  $textBlock.insertAdjacentElement("afterend", $nextBlock);
297
300
  $textBlock.replaceChildren(...preStructure);
298
301
  $nextBlock.replaceChildren(...nextStructure);
@@ -40,7 +40,7 @@ export function _setNodeStyle(className, store) {
40
40
  _setCursor($element.childNodes[targetIdx], cursorOffset);
41
41
  } else {
42
42
  if ($parentElement.tagName === "SPAN") {
43
- const classList = [...$parentElement.classList];
43
+ const classList = $parentElement.classList.value.split(" ");
44
44
  const classIdx = classList.indexOf(className);
45
45
  if (classIdx === -1) {
46
46
  $parentElement.classList.add(className);
@@ -92,7 +92,7 @@ export function _setNodeStyle(className, store) {
92
92
  } else {
93
93
  const $target = cursorData.startNode;
94
94
  if ($target.tagName !== "A") {
95
- const classList = [...$target.classList];
95
+ const classList = $target.classList.value.split(" ");
96
96
  const classIdx = classList.indexOf(className);
97
97
  if (classIdx === -1) {
98
98
  if (cursorData.startOffset !== 0) {
@@ -157,7 +157,7 @@ export function _setNodeStyle(className, store) {
157
157
  isDuble = true;
158
158
  }
159
159
  } else {
160
- const classList = [...$elementNode.classList];
160
+ const classList = $elementNode.classList.value.split(" ");
161
161
  const classIdx = classList.indexOf(className);
162
162
  if ($elementNode.tagName === "SPAN") {
163
163
  if (classIdx === -1) {
@@ -196,7 +196,7 @@ export function _setNodeStyle(className, store) {
196
196
  structureArray.push(childNode.textContent);
197
197
  }
198
198
  } else {
199
- const classList = [...$elementNode.classList];
199
+ const classList = $elementNode.classList.value.split(" ");
200
200
  const classIdx = classList.indexOf(className);
201
201
  if ($elementNode.tagName === "SPAN") {
202
202
  if (isWrap === true) {
@@ -236,7 +236,7 @@ export function _setNodeStyle(className, store) {
236
236
  structureArray.push(childNode.textContent);
237
237
  }
238
238
  } else {
239
- const classList = [...$elementNode.classList];
239
+ const classList = $elementNode.classList.value.split(" ");
240
240
  const classIdx = classList.indexOf(className);
241
241
  if ($elementNode.tagName === "SPAN") {
242
242
  if (isWrap === true) {
@@ -351,12 +351,15 @@ export function _setTextAlign(type, store) {
351
351
  if ($element.classList.contains(className) === true) {
352
352
  $element.classList.remove(className);
353
353
  } else {
354
- const curruntClassname = alignClassList.filter((text) => [...$element.classList].includes(text) === true)[0];
354
+ const curruntClassname = alignClassList.filter((text) => $element.classList.contains(text) === true)[0];
355
355
  if (curruntClassname !== void 0) {
356
356
  $element.classList.remove(curruntClassname);
357
357
  }
358
358
  $element.classList.add(className);
359
359
  }
360
+ if (store.$currentBlock.classList.contains("de-image-block") !== true) {
361
+ _setCursor($element, 0);
362
+ }
360
363
  }
361
364
  }
362
365
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dragon-editor",
3
- "version": "3.2.1",
3
+ "version": "3.2.3",
4
4
  "description": "Javascript WYSIWYG editor in Nuxt3!",
5
5
  "repository": {
6
6
  "type": "git",