dragon-editor 4.0.3 → 4.0.4

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
@@ -4,7 +4,7 @@
4
4
  "nuxt": ">=3.0.0"
5
5
  },
6
6
  "configKey": "dragon-editor",
7
- "version": "4.0.3",
7
+ "version": "4.0.4",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
@@ -64,10 +64,9 @@
64
64
 
65
65
  <script setup>
66
66
  import { useEditorStore } from "../../store/editor";
67
- import { ref, computed, nextTick } from "vue";
67
+ import { ref, computed, nextTick, onMounted } from "vue";
68
68
  import { onClickOutside } from "@vueuse/core";
69
69
  import { _moveCodeBlockEvent, _codeBlockShiftEnterEvent, _codeBlockTabEvent, _normalPasteEvent } from "../../utils/event";
70
- import { _highlightingCode } from "../../utils/data";
71
70
  const editorStore = useEditorStore();
72
71
  const props = defineProps({
73
72
  data: { type: null, required: true },
@@ -161,11 +160,12 @@ function contentKeydownEvent(event) {
161
160
  async function setLanguageEvent(lang) {
162
161
  if ($content.value !== null) {
163
162
  const textContent = $content.value.textContent;
163
+ const highlights = hljs.highlight(textContent, { language: lang });
164
164
  const newData = JSON.parse(JSON.stringify(props.data));
165
165
  isLanguageListActive.value = false;
166
166
  abortEdit();
167
167
  newData.language = lang;
168
- newData.textContent = _highlightingCode(textContent, lang);
168
+ newData.textContent = highlights.value;
169
169
  emit("update", newData);
170
170
  await nextTick();
171
171
  setEdit();
@@ -174,8 +174,9 @@ async function setLanguageEvent(lang) {
174
174
  function setStyleEvent() {
175
175
  if ($content.value !== null) {
176
176
  const textContent = $content.value.textContent;
177
+ const highlights = hljs.highlight(textContent, { language: props.data.language });
177
178
  const newData = JSON.parse(JSON.stringify(props.data));
178
- newData.textContent = _highlightingCode(textContent, props.data.language);
179
+ newData.textContent = highlights.value;
179
180
  emit("update", newData);
180
181
  }
181
182
  }
@@ -188,4 +189,12 @@ onClickOutside(
188
189
  ignore: [$btnLanguageList]
189
190
  }
190
191
  );
192
+ onMounted(() => {
193
+ if (window.hljs === void 0) {
194
+ const script = document.createElement("script");
195
+ script.src = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/highlight.min.js";
196
+ script.async = true;
197
+ document.head.appendChild(script);
198
+ }
199
+ });
191
200
  </script>
@@ -1,4 +1,3 @@
1
- export declare function _highlightingCode(text: string, language: string): string;
2
1
  export declare function _arrangementNodeList(list: Node[], cursorStartNode: Node | null, cursorStartNodeOffset: number, cursorEndNode: Node | null, cursorEndNodeOffset: number): {
3
2
  list: Node[];
4
3
  cursorStartNode: Node | null;
@@ -1,8 +1,4 @@
1
- import * as hljs from "highlight.js";
2
1
  import { _isStrictlyEqualArrays } from "./index.js";
3
- export function _highlightingCode(text, language) {
4
- return hljs.default.highlight(text, { language }).value;
5
- }
6
2
  export function _arrangementNodeList(list, cursorStartNode, cursorStartNodeOffset, cursorEndNode, cursorEndNodeOffset) {
7
3
  const arrangementNodeList = [];
8
4
  list.forEach((node) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dragon-editor",
3
- "version": "4.0.3",
3
+ "version": "4.0.4",
4
4
  "description": "Javascript WYSIWYG editor in Nuxt!",
5
5
  "repository": {
6
6
  "type": "git",