dragon-editor 3.4.4 → 3.5.0

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.
Files changed (70) hide show
  1. package/README.md +9 -15
  2. package/dist/module.d.mts +5 -0
  3. package/dist/module.json +8 -1
  4. package/dist/module.mjs +5 -3
  5. package/dist/runtime/components/DragonEditor.vue +252 -720
  6. package/dist/runtime/components/DragonEditorViewer.vue +59 -45
  7. package/dist/runtime/scss/editor.css +83 -34
  8. package/dist/runtime/scss/viewer.css +31 -4
  9. package/dist/runtime/type.d.ts +78 -23
  10. package/dist/runtime/utils/event/block.d.ts +0 -0
  11. package/dist/runtime/utils/event/block.js +78 -0
  12. package/dist/runtime/utils/event/cursor.d.ts +0 -0
  13. package/dist/runtime/utils/{cursor.mjs → event/cursor.js} +4 -16
  14. package/dist/runtime/utils/event/data.d.ts +0 -0
  15. package/dist/runtime/utils/event/data.js +342 -0
  16. package/dist/runtime/utils/event/index.d.ts +8 -0
  17. package/dist/runtime/utils/event/index.js +8 -0
  18. package/dist/runtime/utils/event/keyboard.d.ts +0 -0
  19. package/dist/runtime/utils/event/keyboard.js +1368 -0
  20. package/dist/runtime/utils/event/mouse.d.ts +0 -0
  21. package/dist/runtime/utils/event/mouse.js +70 -0
  22. package/dist/runtime/utils/event/scroll.d.ts +0 -0
  23. package/dist/runtime/utils/event/scroll.js +29 -0
  24. package/dist/runtime/utils/event/touch.d.ts +0 -0
  25. package/dist/runtime/utils/event/touch.js +10 -0
  26. package/dist/runtime/utils/event/window.d.ts +0 -0
  27. package/dist/runtime/utils/event/window.js +32 -0
  28. package/dist/runtime/utils/layout/block.d.ts +0 -0
  29. package/dist/runtime/utils/layout/block.js +105 -0
  30. package/dist/runtime/utils/layout/body.d.ts +0 -0
  31. package/dist/runtime/utils/layout/body.js +22 -0
  32. package/dist/runtime/utils/layout/controlbar.d.ts +0 -0
  33. package/dist/runtime/utils/layout/controlbar.js +99 -0
  34. package/dist/runtime/utils/layout/icon.d.ts +0 -0
  35. package/dist/runtime/utils/layout/icon.js +156 -0
  36. package/dist/runtime/utils/layout/index.d.ts +5 -0
  37. package/dist/runtime/utils/layout/index.js +5 -0
  38. package/dist/runtime/utils/layout/menuBar.d.ts +0 -0
  39. package/dist/runtime/utils/layout/menuBar.js +358 -0
  40. package/dist/runtime/utils/node/block.d.ts +0 -0
  41. package/dist/runtime/utils/node/block.js +235 -0
  42. package/dist/runtime/utils/{element.d.ts → node/element.d.ts} +1 -0
  43. package/dist/runtime/utils/{element.mjs → node/element.js} +19 -4
  44. package/dist/runtime/utils/node/index.d.ts +2 -0
  45. package/dist/runtime/utils/node/index.js +2 -0
  46. package/dist/runtime/utils/style/anchor.d.ts +0 -0
  47. package/dist/runtime/utils/style/anchor.js +240 -0
  48. package/dist/runtime/utils/style/decoration.d.ts +0 -0
  49. package/dist/runtime/utils/style/decoration.js +378 -0
  50. package/dist/runtime/utils/style/index.d.ts +2 -0
  51. package/dist/runtime/utils/style/index.js +2 -0
  52. package/dist/types.d.mts +7 -0
  53. package/dist/types.d.ts +3 -3
  54. package/package.json +15 -16
  55. package/dist/runtime/store.d.ts +0 -11
  56. package/dist/runtime/store.mjs +0 -51
  57. package/dist/runtime/utils/block.d.ts +0 -13
  58. package/dist/runtime/utils/block.mjs +0 -144
  59. package/dist/runtime/utils/content.d.ts +0 -2
  60. package/dist/runtime/utils/content.mjs +0 -19
  61. package/dist/runtime/utils/controlBar.d.ts +0 -9
  62. package/dist/runtime/utils/controlBar.mjs +0 -172
  63. package/dist/runtime/utils/convertor.d.ts +0 -3
  64. package/dist/runtime/utils/convertor.mjs +0 -138
  65. package/dist/runtime/utils/cursor.d.ts +0 -6
  66. package/dist/runtime/utils/keyboardEvent.d.ts +0 -10
  67. package/dist/runtime/utils/keyboardEvent.mjs +0 -978
  68. package/dist/runtime/utils/style.d.ts +0 -5
  69. package/dist/runtime/utils/style.mjs +0 -617
  70. /package/dist/runtime/{plugin.mjs → plugin.js} +0 -0
@@ -0,0 +1,78 @@
1
+ import { _updateModelData } from "./index.js";
2
+ import { _updateCurrentBlock } from "../node/index.js";
3
+ export function _imageResizeEventStart(event, store) {
4
+ const $target = event.target;
5
+ if ($target !== null) {
6
+ const $block = $target.closest(".de-block");
7
+ if ($block !== null && $block.classList.contains("de-image-block") === true && $target.classList.contains("de-btn") === true) {
8
+ _updateCurrentBlock(event, store);
9
+ store.value.activeStatus.imageResizeEvent = true;
10
+ if (event.type === "touchstart") {
11
+ store.value.eventStatus.imageResizeEventStartX = event.touches[0].clientX;
12
+ } else {
13
+ store.value.eventStatus.imageResizeEventStartX = event.clientX;
14
+ }
15
+ if ($target.classList.contains("de-btn-left") === true) {
16
+ store.value.eventStatus.imageResizeEventType = "left";
17
+ } else {
18
+ store.value.eventStatus.imageResizeEventType = "right";
19
+ }
20
+ const $imgArea = $block.querySelector(".de-image-area");
21
+ store.value.eventStatus.imageResizeEventEndX = store.value.eventStatus.imageResizeEventStartX;
22
+ store.value.eventStatus.imageResizeCurrentWidth = parseInt($imgArea.dataset["maxwidth"] ?? "25");
23
+ }
24
+ }
25
+ }
26
+ export function _imageResizeEvent(event, store) {
27
+ if (store.value.activeStatus.imageResizeEvent === true && store.value.controlStatus.$currentBlock !== null && store.value.$body !== null) {
28
+ const $imgArea = store.value.controlStatus.$currentBlock.querySelector(".de-image-area");
29
+ const contentWidth = store.value.$body.offsetWidth / 2;
30
+ let gap = 0;
31
+ if (event.type === "touchmove") {
32
+ store.value.eventStatus.imageResizeEventEndX = event.touches[0].clientX;
33
+ } else {
34
+ store.value.eventStatus.imageResizeEventEndX = event.clientX;
35
+ }
36
+ if (store.value.eventStatus.imageResizeEventType === "right") {
37
+ gap = Math.floor(store.value.eventStatus.imageResizeEventStartX - store.value.eventStatus.imageResizeEventEndX);
38
+ } else {
39
+ gap = Math.floor(store.value.eventStatus.imageResizeEventEndX - store.value.eventStatus.imageResizeEventStartX);
40
+ }
41
+ const percent = 100 / contentWidth * gap;
42
+ let value = Math.floor(store.value.eventStatus.imageResizeCurrentWidth - percent);
43
+ if (value < 25) {
44
+ value = 25;
45
+ }
46
+ if (value > 100) {
47
+ value = 100;
48
+ }
49
+ $imgArea.dataset["maxwidth"] = String(value);
50
+ }
51
+ }
52
+ export function _imageResizeEventEnd(event, store) {
53
+ if (store.value.activeStatus.imageResizeEvent === true) {
54
+ store.value.activeStatus.imageResizeEvent = false;
55
+ _updateModelData(store);
56
+ }
57
+ }
58
+ export function _moveBlock(type, store) {
59
+ if (store.value.controlStatus.$currentBlock !== null) {
60
+ const $block = store.value.controlStatus.$currentBlock;
61
+ let $target;
62
+ if (type === "up") {
63
+ $target = $block.previousElementSibling;
64
+ } else {
65
+ $target = $block.nextElementSibling;
66
+ }
67
+ if ($target !== null) {
68
+ $target.insertAdjacentHTML(type === "up" ? "beforebegin" : "afterend", $block.outerHTML);
69
+ $block.remove();
70
+ if (type === "up") {
71
+ store.value.controlStatus.$currentBlock = $target.previousElementSibling;
72
+ } else {
73
+ store.value.controlStatus.$currentBlock = $target.nextElementSibling;
74
+ }
75
+ }
76
+ _updateModelData(store);
77
+ }
78
+ }
File without changes
@@ -1,14 +1,13 @@
1
- import "../type.d.ts";
2
- export function _setCursorData(store) {
1
+ export function _updateCursorData(store) {
3
2
  const selection = window.getSelection();
4
3
  if (selection.type !== "None") {
5
- store.setCursorData({
4
+ store.value.cursorData = {
6
5
  type: selection.type,
7
6
  startNode: selection.anchorNode,
8
7
  startOffset: selection.anchorOffset,
9
8
  endNode: selection.focusNode,
10
9
  endOffset: selection.focusOffset
11
- });
10
+ };
12
11
  }
13
12
  }
14
13
  export function _setCursor($target, startIdx) {
@@ -62,18 +61,7 @@ export function _setRangeCursor($startTarget, $endTarget, startIdx, endIdx) {
62
61
  selection.removeAllRanges();
63
62
  selection.addRange(range);
64
63
  }
65
- export function _clenupCursor(store) {
66
- _setCursorData(store);
67
- if (store.cursorData.startNode !== store.cursorData.endNode || store.cursorData.startOffset !== store.cursorData.endOffset) {
68
- } else {
69
- if (store.cursorData.startNode.hasChildNodes() === true) {
70
- _setCursor(store.cursorData.startNode.childNodes[store.cursorData.startOffset], 0);
71
- } else {
72
- _setCursor(store.cursorData.startNode, store.cursorData.startOffset);
73
- }
74
- }
75
- }
76
- export function _soltingCursorDataOnElement(cursorData, $element) {
64
+ export function _sortingCursorDataOnElement(cursorData, $element) {
77
65
  const childList = $element.childNodes;
78
66
  let startNode = cursorData.startNode;
79
67
  let startIdx = -1;
File without changes
@@ -0,0 +1,342 @@
1
+ import { _getCurrentBlock } from "../node/index.js";
2
+ export const CODEBLOCKLANG = [
3
+ {
4
+ text: "Plain Text",
5
+ code: "text"
6
+ },
7
+ {
8
+ text: "Bash",
9
+ code: "bash"
10
+ },
11
+ {
12
+ text: "C#",
13
+ code: "csharp"
14
+ },
15
+ {
16
+ text: "C",
17
+ code: "c"
18
+ },
19
+ {
20
+ text: "C++",
21
+ code: "cpp"
22
+ },
23
+ {
24
+ text: "CSS",
25
+ code: "css"
26
+ },
27
+ {
28
+ text: "Django",
29
+ code: "django"
30
+ },
31
+ {
32
+ text: "Dockerfile",
33
+ code: "dockerfile"
34
+ },
35
+ {
36
+ text: "Go",
37
+ code: "go"
38
+ },
39
+ {
40
+ text: "HTML, XML",
41
+ code: "html"
42
+ },
43
+ {
44
+ text: "JSON",
45
+ code: "json"
46
+ },
47
+ {
48
+ text: "Java",
49
+ code: "java"
50
+ },
51
+ {
52
+ text: "JavaScript",
53
+ code: "js"
54
+ },
55
+ {
56
+ text: "TypeScript",
57
+ code: "ts"
58
+ },
59
+ {
60
+ text: "Kotlin",
61
+ code: "kotlin"
62
+ },
63
+ {
64
+ text: "Lua",
65
+ code: "lua"
66
+ },
67
+ {
68
+ text: "Markdown",
69
+ code: "md"
70
+ },
71
+ {
72
+ text: "Nginx",
73
+ code: "nginx"
74
+ },
75
+ {
76
+ text: "PHP",
77
+ code: "php"
78
+ },
79
+ {
80
+ text: "Python",
81
+ code: "python"
82
+ },
83
+ {
84
+ text: "Ruby",
85
+ code: "ruby"
86
+ },
87
+ {
88
+ text: "SCSS",
89
+ code: "scss"
90
+ },
91
+ {
92
+ text: "SQL",
93
+ code: "sql"
94
+ },
95
+ {
96
+ text: "Shell",
97
+ code: "shell"
98
+ },
99
+ {
100
+ text: "Swift",
101
+ code: "swift"
102
+ },
103
+ {
104
+ text: "YAML",
105
+ code: "yml"
106
+ }
107
+ ];
108
+ export function _updateModelData(store) {
109
+ const $body = store.value.$body;
110
+ if ($body !== null) {
111
+ const $blockList = $body.querySelectorAll(".de-block");
112
+ const workList = [];
113
+ $blockList.forEach(($el) => {
114
+ let classListText = $el.classList.value.replaceAll("de-block", "");
115
+ let classList = "";
116
+ switch (true) {
117
+ case $el.classList.contains("de-text-block"):
118
+ workList.push(
119
+ new Promise((done) => {
120
+ classList = classListText.replaceAll("de-text-block", "").trim();
121
+ const textBlockDepth = $el.dataset["depth"];
122
+ let textBlockData = {
123
+ type: "text",
124
+ classList: classList === "" ? [] : classList.split(" "),
125
+ textContent: $el.innerHTML
126
+ };
127
+ if (textBlockDepth !== void 0) {
128
+ textBlockData.depth = parseInt(textBlockDepth);
129
+ }
130
+ done(textBlockData);
131
+ })
132
+ );
133
+ break;
134
+ case $el.classList.contains("de-heading-block"):
135
+ workList.push(
136
+ new Promise((done) => {
137
+ classList = classListText.replaceAll("de-heading-block", "").trim();
138
+ const headingBlockDepth = $el.dataset["depth"];
139
+ let headingBlockData = {
140
+ type: "heading",
141
+ id: $el.id,
142
+ level: parseInt($el.dataset["level"] ?? "3"),
143
+ classList: classList === "" ? [] : classList.split(" "),
144
+ textContent: $el.innerHTML
145
+ };
146
+ if (headingBlockDepth !== void 0) {
147
+ headingBlockData.depth = parseInt(headingBlockDepth);
148
+ }
149
+ done(headingBlockData);
150
+ })
151
+ );
152
+ break;
153
+ case $el.classList.contains("de-list-block"):
154
+ workList.push(
155
+ new Promise((done) => {
156
+ const $li = $el.querySelectorAll(".de-item");
157
+ const liList = [];
158
+ classList = classListText.replaceAll("de-list-block", "").trim();
159
+ $li.forEach(($child) => {
160
+ let childClassName = $child.classList.value.replace("de-item", "");
161
+ liList.push({
162
+ classList: childClassName === "" ? [] : childClassName.split(" "),
163
+ textContent: $child.innerHTML
164
+ });
165
+ });
166
+ const listBlockDepth = $el.dataset["depth"];
167
+ let listBlockData = {
168
+ type: "list",
169
+ element: $el.tagName.toLowerCase(),
170
+ style: $el.dataset["style"],
171
+ child: liList
172
+ };
173
+ if (listBlockDepth !== void 0) {
174
+ listBlockData.depth = parseInt(listBlockDepth);
175
+ }
176
+ done(listBlockData);
177
+ })
178
+ );
179
+ break;
180
+ case $el.classList.contains("de-image-block"):
181
+ workList.push(
182
+ new Promise((done) => {
183
+ const $imageArea = $el.querySelector(".de-image-area");
184
+ const $img = $el.querySelector(".de-img");
185
+ const $caption = $el.querySelector(".de-caption");
186
+ classList = classListText.replaceAll("de-image-block", "").trim();
187
+ if ($img.complete === false) {
188
+ $img.onload = () => {
189
+ done({
190
+ type: "image",
191
+ src: $img.src.replace(store.value.imageHostURL, ""),
192
+ maxWidth: parseInt($imageArea.dataset["maxwidth"] ?? "25"),
193
+ width: $img.width,
194
+ height: $img.height,
195
+ caption: $caption?.textContent ?? "",
196
+ classList: classList === "" ? [] : classList.split(" ")
197
+ });
198
+ };
199
+ } else {
200
+ done({
201
+ type: "image",
202
+ src: $img.src.replace(store.value.imageHostURL, ""),
203
+ maxWidth: parseInt($imageArea.dataset["maxwidth"] ?? "25"),
204
+ width: $img.width,
205
+ height: $img.height,
206
+ caption: $caption?.textContent ?? "",
207
+ classList: classList === "" ? [] : classList.split(" ")
208
+ });
209
+ }
210
+ })
211
+ );
212
+ break;
213
+ case $el.classList.contains("de-code-block"):
214
+ workList.push(
215
+ new Promise((done) => {
216
+ const $language = $el.querySelector(".de-language");
217
+ const $fileName = $el.querySelector(".de-filename");
218
+ const $codeBlock = $el.querySelector(".de-code-content");
219
+ let language = "text";
220
+ classList = classListText.replaceAll("de-code-block", "").trim();
221
+ if ($language !== null) {
222
+ const value = $language.textContent ?? "";
223
+ const targetValue = CODEBLOCKLANG.find((item) => item.text === value);
224
+ if (targetValue !== void 0) {
225
+ language = targetValue.code;
226
+ }
227
+ }
228
+ done({
229
+ type: "code",
230
+ theme: $el.dataset["theme"],
231
+ filename: $fileName?.textContent || "",
232
+ language,
233
+ textContent: $codeBlock === null ? "" : $codeBlock.innerHTML
234
+ });
235
+ })
236
+ );
237
+ break;
238
+ default:
239
+ workList.push(
240
+ new Promise((done) => {
241
+ classList = classListText.replaceAll("de-custom-block", "").trim();
242
+ done({
243
+ type: "custom",
244
+ classList: classList === "" ? [] : classList.split(" "),
245
+ textContent: $el.innerHTML
246
+ });
247
+ })
248
+ );
249
+ }
250
+ });
251
+ Promise.all(workList).then((data) => {
252
+ store.value.emit("update:modelValue", data);
253
+ });
254
+ }
255
+ }
256
+ export function _getDefaultBlockData(type) {
257
+ let data = { type: "text", classList: [], textContent: "" };
258
+ switch (type) {
259
+ case "heading1":
260
+ case "heading2":
261
+ case "heading3":
262
+ data = {
263
+ type: "heading",
264
+ level: parseInt(type.replace("heading", "")),
265
+ id: _generateId(),
266
+ classList: [],
267
+ textContent: ""
268
+ };
269
+ break;
270
+ case "ol":
271
+ case "ul":
272
+ data = {
273
+ type: "list",
274
+ element: type,
275
+ style: type === "ol" ? "decimal" : "disc",
276
+ child: [
277
+ {
278
+ classList: [],
279
+ textContent: ""
280
+ }
281
+ ]
282
+ };
283
+ break;
284
+ case "code":
285
+ data = {
286
+ type: "code",
287
+ language: "text",
288
+ theme: "github",
289
+ filename: "",
290
+ textContent: ""
291
+ };
292
+ break;
293
+ }
294
+ return data;
295
+ }
296
+ export function _generateId() {
297
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
298
+ let str = "";
299
+ for (let i = 0; i < 6; i += 1) {
300
+ str += chars.charAt(Math.floor(Math.random() * chars.length));
301
+ }
302
+ return str;
303
+ }
304
+ export function _updateControlBarStatus(store) {
305
+ if (store.value.controlStatus.$currentBlock !== null) {
306
+ const { type } = _getCurrentBlock(store.value.controlStatus.$currentBlock);
307
+ const allowTypeList = ["code", "ol", "ul"];
308
+ if (allowTypeList.includes(type) === true) {
309
+ switch (type) {
310
+ case "code":
311
+ __updateCodeBlockStyle(store);
312
+ break;
313
+ case "ol":
314
+ case "ul":
315
+ __updateListBlockStyle(store);
316
+ break;
317
+ }
318
+ }
319
+ }
320
+ }
321
+ function __updateCodeBlockStyle(store) {
322
+ if (store.value.controlStatus.$currentBlock !== null) {
323
+ const $block = store.value.controlStatus.$currentBlock;
324
+ const $language = $block.querySelector(".de-language");
325
+ let language = "text";
326
+ if ($language !== null) {
327
+ const value = $language.textContent ?? "";
328
+ const targetValue = CODEBLOCKLANG.find((item) => item.text === value);
329
+ if (targetValue !== void 0) {
330
+ language = targetValue.code;
331
+ }
332
+ }
333
+ store.value.controlStatus.codeBlockTheme = $block.dataset["theme"] ?? "github";
334
+ store.value.controlStatus.codeBlockLang = language;
335
+ }
336
+ }
337
+ function __updateListBlockStyle(store) {
338
+ if (store.value.controlStatus.$currentBlock !== null) {
339
+ const $block = store.value.controlStatus.$currentBlock;
340
+ store.value.controlStatus.listBlockStyle = $block.dataset["style"] ?? "disc";
341
+ }
342
+ }
@@ -0,0 +1,8 @@
1
+ export * from "./keyboard.js";
2
+ export * from "./mouse.js";
3
+ export * from "./touch.js";
4
+ export * from "./data.js";
5
+ export * from "./window.js";
6
+ export * from "./scroll.js";
7
+ export * from "./cursor.js";
8
+ export * from "./block.js";
@@ -0,0 +1,8 @@
1
+ export * from "./keyboard.js";
2
+ export * from "./mouse.js";
3
+ export * from "./touch.js";
4
+ export * from "./data.js";
5
+ export * from "./window.js";
6
+ export * from "./scroll.js";
7
+ export * from "./cursor.js";
8
+ export * from "./block.js";
File without changes