dragon-editor 2.0.0-beta.1.1 → 2.0.0-beta.1.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.
Files changed (36) hide show
  1. package/dist/module.json +1 -1
  2. package/dist/module.mjs +1 -1
  3. package/dist/runtime/core/components/SvgIcon.vue +166 -0
  4. package/dist/runtime/core/components/editor/TextBlock.vue +92 -0
  5. package/dist/runtime/core/components/icon/AlignCenter.vue +6 -0
  6. package/dist/runtime/core/components/icon/AlignLeft.vue +6 -0
  7. package/dist/runtime/core/components/icon/AlignRight.vue +6 -0
  8. package/dist/runtime/core/components/icon/CodeBlock.vue +6 -0
  9. package/dist/runtime/core/components/icon/DecorationBold.vue +6 -0
  10. package/dist/runtime/core/components/icon/DecorationItalic.vue +6 -0
  11. package/dist/runtime/core/components/icon/DecorationStrikethrough.vue +6 -0
  12. package/dist/runtime/core/components/icon/DecorationUnderline.vue +6 -0
  13. package/dist/runtime/core/components/icon/ImageBlock.vue +5 -0
  14. package/dist/runtime/core/components/icon/LinkPath.vue +6 -0
  15. package/dist/runtime/core/components/icon/OlBlock.vue +6 -0
  16. package/dist/runtime/core/components/icon/QuotationBlock.vue +6 -0
  17. package/dist/runtime/core/components/icon/TableBlock.vue +8 -0
  18. package/dist/runtime/core/components/icon/TextBlock.vue +5 -0
  19. package/dist/runtime/core/components/icon/UlBlock.vue +6 -0
  20. package/dist/runtime/core/style/common.css +190 -0
  21. package/dist/runtime/core/style/main.d.ts +1 -0
  22. package/dist/runtime/core/style/main.mjs +24 -0
  23. package/dist/runtime/core/utils/cursor.d.ts +4 -0
  24. package/dist/runtime/core/utils/cursor.mjs +72 -0
  25. package/dist/runtime/core/utils/element.d.ts +2 -0
  26. package/dist/runtime/core/utils/element.mjs +25 -0
  27. package/dist/runtime/core/utils/index.d.ts +7 -0
  28. package/dist/runtime/core/utils/index.mjs +26 -0
  29. package/dist/runtime/core/utils/keyboard.d.ts +6 -0
  30. package/dist/runtime/core/utils/keyboard.mjs +98 -0
  31. package/dist/runtime/core/utils/style.d.ts +2 -0
  32. package/dist/runtime/core/utils/style.mjs +264 -0
  33. package/dist/runtime/shared/components/DragonEditor.vue +361 -0
  34. package/dist/runtime/shared/components/DragonEditorComment.vue +129 -0
  35. package/dist/runtime/shared/components/DragonEditorViewer.vue +3 -0
  36. package/package.json +1 -1
@@ -0,0 +1,24 @@
1
+ /******/ (() => { // webpackBootstrap
2
+ /******/ "use strict";
3
+ /******/ // The require scope
4
+ /******/ var __webpack_require__ = {};
5
+ /******/
6
+ /************************************************************************/
7
+ /******/ /* webpack/runtime/make namespace object */
8
+ /******/ (() => {
9
+ /******/ // define __esModule on exports
10
+ /******/ __webpack_require__.r = (exports) => {
11
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
12
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
13
+ /******/ }
14
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
15
+ /******/ };
16
+ /******/ })();
17
+ /******/
18
+ /************************************************************************/
19
+ var __webpack_exports__ = {};
20
+ __webpack_require__.r(__webpack_exports__);
21
+ // extracted by mini-css-extract-plugin
22
+
23
+ /******/ })()
24
+ ;
@@ -0,0 +1,4 @@
1
+ import type { cursorSelection, arrangementCursorData } from "../../../types";
2
+ export declare function setCursor(target: Node, idx: number): void;
3
+ export declare function getCursor(): cursorSelection;
4
+ export declare function getArrangementCursorData(): arrangementCursorData;
@@ -0,0 +1,72 @@
1
+ import { findEditableElement } from "./element.mjs";
2
+ export function setCursor(target, idx) {
3
+ if (target) {
4
+ let $target;
5
+ if (target.constructor.name === "Text") {
6
+ $target = target;
7
+ } else {
8
+ $target = target.childNodes.length > 0 ? target.childNodes[0] : target;
9
+ }
10
+ const select = window.getSelection();
11
+ const range = document.createRange();
12
+ range.setStart($target, idx);
13
+ range.collapse(true);
14
+ select.removeAllRanges();
15
+ select.addRange(range);
16
+ }
17
+ }
18
+ export function getCursor() {
19
+ const select = window.getSelection();
20
+ return {
21
+ type: select.type,
22
+ startNode: select.anchorNode,
23
+ startOffset: select.anchorOffset,
24
+ endNode: select.focusNode,
25
+ endOffset: select.focusOffset
26
+ };
27
+ }
28
+ export function getArrangementCursorData() {
29
+ const cursorData = getCursor();
30
+ const startNode = cursorData.startNode;
31
+ const editableElement = findEditableElement(startNode);
32
+ let childNode;
33
+ let childIdx = -1;
34
+ let fixIdx = 0;
35
+ let preNodeType = "";
36
+ let childLength = 0;
37
+ if (startNode.parentNode === editableElement) {
38
+ childNode = startNode;
39
+ } else {
40
+ childNode = startNode.parentNode;
41
+ }
42
+ editableElement.childNodes.forEach((child, count) => {
43
+ if (child === childNode) {
44
+ childIdx = count;
45
+ }
46
+ });
47
+ editableElement.childNodes.forEach((child, count) => {
48
+ if (count <= childIdx + fixIdx) {
49
+ const type = child.constructor.name;
50
+ if (preNodeType !== type) {
51
+ childLength = 0;
52
+ }
53
+ if (type === "Text") {
54
+ if (preNodeType === type) {
55
+ childIdx -= 1;
56
+ fixIdx += 1;
57
+ childLength += child.textContent?.length ?? 0;
58
+ } else {
59
+ childLength = child.textContent?.length ?? 0;
60
+ }
61
+ } else {
62
+ childLength = child.textContent?.length ?? 0;
63
+ }
64
+ preNodeType = type;
65
+ }
66
+ });
67
+ return {
68
+ editableNode: editableElement,
69
+ childCount: childIdx,
70
+ length: childLength
71
+ };
72
+ }
@@ -0,0 +1,2 @@
1
+ export declare function findEditableElement(node: Node): (HTMLElement | null);
2
+ export declare function findChildNumber(parent: HTMLElement, child: Node): number;
@@ -0,0 +1,25 @@
1
+ export function findEditableElement(node) {
2
+ if (node) {
3
+ if (node.constructor.name === "Text") {
4
+ return findEditableElement(node.parentNode);
5
+ } else {
6
+ const hasAttr = node.getAttribute("contenteditable") !== null;
7
+ if (hasAttr) {
8
+ return node;
9
+ } else {
10
+ return findEditableElement(node.parentNode);
11
+ }
12
+ }
13
+ } else {
14
+ return null;
15
+ }
16
+ }
17
+ export function findChildNumber(parent, child) {
18
+ let idx = 0;
19
+ parent.childNodes.forEach((item, count) => {
20
+ if (item === child) {
21
+ idx = count;
22
+ }
23
+ });
24
+ return idx;
25
+ }
@@ -0,0 +1,7 @@
1
+ import { textBlock } from "../../../types/index";
2
+ export declare function createTextBlock(): textBlock;
3
+ export declare function createBlock(name: string): textBlock;
4
+ export * from "./keyboard";
5
+ export * from "./cursor";
6
+ export * from "./style";
7
+ export * from "./element";
@@ -0,0 +1,26 @@
1
+ function generateId() {
2
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
3
+ let str = "";
4
+ for (let i = 0; i < 20; i++) {
5
+ str += chars.charAt(Math.floor(Math.random() * chars.length));
6
+ }
7
+ return str;
8
+ }
9
+ export function createTextBlock() {
10
+ return {
11
+ type: "text",
12
+ id: generateId(),
13
+ classList: [],
14
+ content: ""
15
+ };
16
+ }
17
+ export function createBlock(name) {
18
+ switch (name) {
19
+ default:
20
+ return createTextBlock();
21
+ }
22
+ }
23
+ export * from "./keyboard.mjs";
24
+ export * from "./cursor.mjs";
25
+ export * from "./style.mjs";
26
+ export * from "./element.mjs";
@@ -0,0 +1,6 @@
1
+ export declare function keyboardEvent(type: string, event: KeyboardEvent, addAction: Function): void;
2
+ export declare function getClipboardData(data: DataTransfer): {
3
+ type: any;
4
+ value: any;
5
+ };
6
+ export declare function pasteText(type: string, value: string): void;
@@ -0,0 +1,98 @@
1
+ import { getCursor, setCursor } from "./cursor.mjs";
2
+ import { findEditableElement, findChildNumber } from "./element.mjs";
3
+ let enterCount = 0;
4
+ function enterEvent(type, event, addAction) {
5
+ if (event.code === "Enter") {
6
+ if (enterCount === 0) {
7
+ enterCount += 1;
8
+ const useShift = event.shiftKey;
9
+ switch (type) {
10
+ case "comment":
11
+ event.preventDefault();
12
+ addBrEvent();
13
+ break;
14
+ default:
15
+ if (useShift === false) {
16
+ event.preventDefault();
17
+ addAction("addBlock", "text");
18
+ }
19
+ }
20
+ setTimeout(() => {
21
+ enterCount = 0;
22
+ }, 150);
23
+ } else {
24
+ event.preventDefault();
25
+ setTimeout(() => {
26
+ enterCount = 0;
27
+ }, 150);
28
+ }
29
+ }
30
+ }
31
+ export function keyboardEvent(type, event, addAction) {
32
+ enterEvent(type, event, addAction);
33
+ }
34
+ export function getClipboardData(data) {
35
+ let type, clipboardData;
36
+ if (!data) {
37
+ type = null;
38
+ }
39
+ const items = data.items;
40
+ if (items === void 0) {
41
+ type = null;
42
+ }
43
+ const count = items.length;
44
+ for (let i = 0; i < count; i += 1) {
45
+ if (items[i].type.indexOf("image") === 0) {
46
+ type = "image";
47
+ clipboardData = items[i].getAsFile();
48
+ break;
49
+ }
50
+ type = "text";
51
+ }
52
+ if (type === "text") {
53
+ clipboardData = data.getData("text");
54
+ }
55
+ return {
56
+ type,
57
+ value: clipboardData
58
+ };
59
+ }
60
+ export function pasteText(type, value) {
61
+ const selection = window.getSelection();
62
+ const range = document.createRange();
63
+ let textNode;
64
+ if (type !== "codeBlock") {
65
+ textNode = document.createTextNode(value.replaceAll("\n", "").replaceAll(/ +/g, " "));
66
+ } else {
67
+ textNode = document.createTextNode(value);
68
+ }
69
+ selection.deleteFromDocument();
70
+ selection.getRangeAt(0).insertNode(textNode);
71
+ range.setStart(textNode, textNode.length);
72
+ range.collapse(true);
73
+ selection.removeAllRanges();
74
+ selection.addRange(range);
75
+ }
76
+ function addBrEvent() {
77
+ const brTag = document.createElement("br");
78
+ const selection = window.getSelection();
79
+ const range = document.createRange();
80
+ selection.deleteFromDocument();
81
+ selection.getRangeAt(0).insertNode(brTag);
82
+ range.setStart(brTag, 0);
83
+ range.collapse(true);
84
+ selection.removeAllRanges();
85
+ selection.addRange(range);
86
+ const cursorData = getCursor();
87
+ if (cursorData.startNode.constructor.name !== "Text") {
88
+ const editableElement = findEditableElement(cursorData.startNode);
89
+ const childList = editableElement.childNodes;
90
+ const childIdx = findChildNumber(editableElement, cursorData.startNode);
91
+ if (childList[childList.length - 1].textContent?.length === 0) {
92
+ childList[childIdx].insertAdjacentHTML("beforebegin", "<br>");
93
+ childList[childList.length - 1].remove();
94
+ } else {
95
+ setCursor(childList[childIdx + 1], 0);
96
+ }
97
+ }
98
+ }
@@ -0,0 +1,2 @@
1
+ import type { allBlock } from "../../../types";
2
+ export declare function styleSettings(type: string, blockData: allBlock, $target: HTMLElement): allBlock;
@@ -0,0 +1,264 @@
1
+ import { getCursor, setCursor } from "./cursor.mjs";
2
+ import { findEditableElement, findChildNumber } from "./element.mjs";
3
+ const alignClassList = ["d-align-left", "d-align-center", "d-align-right"];
4
+ function arrangementAlignClass(originList, className) {
5
+ const hasClass = originList.indexOf(className) > -1;
6
+ let array = originList;
7
+ if (hasClass) {
8
+ originList.splice(originList.indexOf(className), 1);
9
+ array = originList;
10
+ } else {
11
+ array = originList.filter((item) => alignClassList.indexOf(item) === -1);
12
+ array.push(className);
13
+ }
14
+ return array;
15
+ }
16
+ function getNextNode($target, node) {
17
+ const childNode = $target.childNodes;
18
+ let idx = -1;
19
+ childNode.forEach((item, index) => {
20
+ if (item === node) {
21
+ idx = index;
22
+ }
23
+ });
24
+ return childNode[idx + 1];
25
+ }
26
+ function warpStyleNode(node, startOffset, endOffset, className) {
27
+ const text = node.textContent;
28
+ const textLength = text.length;
29
+ let startIdx = startOffset;
30
+ let endIdx = endOffset;
31
+ if (endOffset < startOffset) {
32
+ startIdx = endOffset;
33
+ endIdx = startOffset;
34
+ }
35
+ return `${text.substring(0, startIdx)}<span class="${className}">${text.substring(startIdx, endIdx)}</span>${text.substring(endIdx, textLength)}`;
36
+ }
37
+ function defaultDecorationMake(originData, $target, className) {
38
+ const cursorData = getCursor();
39
+ const startNode = cursorData.startNode;
40
+ const endNode = cursorData.endNode;
41
+ if (startNode !== null) {
42
+ const editableElement = findEditableElement(startNode);
43
+ if (cursorData.type === "Range") {
44
+ if (startNode === endNode) {
45
+ const parentNode = startNode.parentNode;
46
+ let startOffset = cursorData.startOffset;
47
+ let endOffset = cursorData.endOffset;
48
+ if (startOffset > endOffset) {
49
+ startOffset = cursorData.endOffset;
50
+ endOffset = cursorData.startOffset;
51
+ }
52
+ if (parentNode === editableElement) {
53
+ const childNumber = findChildNumber(editableElement, startNode);
54
+ const wrpStructure = warpStyleNode(parentNode.childNodes[childNumber], startOffset, endOffset, className);
55
+ let htmlStructure = "";
56
+ parentNode.childNodes.forEach((child, count) => {
57
+ if (count === childNumber) {
58
+ htmlStructure += wrpStructure;
59
+ } else {
60
+ if (child.constructor.name === "Text") {
61
+ htmlStructure += child.textContent;
62
+ } else {
63
+ htmlStructure += child.outerHTML;
64
+ }
65
+ }
66
+ });
67
+ parentNode.innerHTML = htmlStructure;
68
+ setTimeout(() => {
69
+ let $cursorTarget = editableElement.childNodes[childNumber + 1];
70
+ if (!$cursorTarget) {
71
+ $cursorTarget = editableElement.childNodes[childNumber];
72
+ }
73
+ const cursorLength = $cursorTarget.textContent.length;
74
+ setCursor($cursorTarget, cursorLength);
75
+ }, 100);
76
+ } else {
77
+ const childNumber = findChildNumber(editableElement, parentNode);
78
+ const classList = [...parentNode.classList];
79
+ const text = parentNode.textContent;
80
+ const hasClassIdx = classList.indexOf(className);
81
+ let startOffset2 = cursorData.startOffset;
82
+ let endOffset2 = cursorData.endOffset;
83
+ let htmlStructure = "";
84
+ if (startOffset2 > endOffset2) {
85
+ startOffset2 = cursorData.endOffset;
86
+ endOffset2 = cursorData.startOffset;
87
+ }
88
+ if (hasClassIdx > -1) {
89
+ const middleClassList = [...parentNode.classList];
90
+ middleClassList.splice(hasClassIdx, 1);
91
+ htmlStructure = `<span class="${classList.join(" ")}">${text.substring(0, startOffset2)}</span><span class="${middleClassList.join(" ")}">${text.substring(startOffset2, endOffset2)}</span><span class="${classList.join(" ")}">${text.substring(endOffset2, text.length)}</span>`;
92
+ } else {
93
+ htmlStructure = `<span class="${classList.join(" ")}">${text.substring(0, startOffset2)}</span><span class="${classList.join(" ")} ${className}">${text.substring(startOffset2, endOffset2)}</span><span class="${classList.join(" ")}">${text.substring(endOffset2, text.length)}</span>`;
94
+ }
95
+ parentNode.insertAdjacentHTML("afterend", htmlStructure);
96
+ parentNode.remove();
97
+ setTimeout(() => {
98
+ setCursor(editableElement.childNodes[childNumber + 1], text.substring(startOffset2, endOffset2).length);
99
+ }, 100);
100
+ }
101
+ } else {
102
+ let startChild = startNode;
103
+ let endChild = endNode;
104
+ if (startNode.parentNode !== editableElement) {
105
+ startChild = startNode.parentNode;
106
+ }
107
+ if (endNode.parentNode !== editableElement) {
108
+ endChild = endNode.parentNode;
109
+ }
110
+ const startChildIdx = findChildNumber(editableElement, startChild);
111
+ const endChildIdx = findChildNumber(editableElement, endChild);
112
+ let startIdx = 0;
113
+ let endIdx = 0;
114
+ let startOffset = 0;
115
+ let endOffset = 0;
116
+ let hasClassName = true;
117
+ let htmlStructure = "";
118
+ if (startChildIdx > endChildIdx) {
119
+ startIdx = endChildIdx;
120
+ endIdx = startChildIdx;
121
+ startOffset = cursorData.endOffset;
122
+ endOffset = cursorData.startOffset;
123
+ } else {
124
+ startIdx = startChildIdx;
125
+ endIdx = endChildIdx;
126
+ startOffset = cursorData.startOffset;
127
+ endOffset = cursorData.endOffset;
128
+ }
129
+ editableElement.childNodes.forEach((item, count) => {
130
+ if (count >= startIdx && count <= endIdx) {
131
+ if (item.constructor.name === "Text") {
132
+ hasClassName = false;
133
+ } else {
134
+ if ([...item.classList].indexOf(className) === -1) {
135
+ hasClassName = false;
136
+ }
137
+ }
138
+ }
139
+ });
140
+ editableElement.childNodes.forEach((child, count) => {
141
+ const type = child.constructor.name;
142
+ const text = child.textContent;
143
+ if (count > startIdx && count < endIdx) {
144
+ if (type === "Text") {
145
+ htmlStructure += `<span class="${className}">${child.textContent}</span>`;
146
+ } else {
147
+ if (hasClassName) {
148
+ if (child.classList.length === 1) {
149
+ htmlStructure += child.textContent;
150
+ } else {
151
+ child.classList.remove(className);
152
+ htmlStructure += child.outerHTML;
153
+ }
154
+ } else {
155
+ child.classList.add(className);
156
+ htmlStructure += child.outerHTML;
157
+ }
158
+ }
159
+ } else if (count === startIdx) {
160
+ if (type === "Text") {
161
+ htmlStructure += `${text.substring(0, startOffset)}<span class="${className}">${text.substring(startOffset, text.length)}</span>`;
162
+ } else {
163
+ const childClassList = [...child.classList];
164
+ if (hasClassName) {
165
+ if (childClassList.length === 1) {
166
+ htmlStructure += `<span class="${className}">${text.substring(0, startOffset)}</span>${text.substring(startOffset, text.length)}`;
167
+ } else {
168
+ const classIdx = childClassList.indexOf(className);
169
+ htmlStructure += `<span class="${childClassList.join(" ")}">${text.substring(0, startOffset)}</span>`;
170
+ childClassList.splice(classIdx, 1);
171
+ htmlStructure += `<span class="${childClassList.join(" ")}">${text.substring(startOffset, text.length)}</span>`;
172
+ }
173
+ } else {
174
+ htmlStructure += `<span class="${childClassList.join(" ")}">${text.substring(0, startOffset)}</span>`;
175
+ htmlStructure += `<span class="${childClassList.join(" ")} ${className}">${text.substring(startOffset, text.length)}</span>`;
176
+ }
177
+ }
178
+ } else if (count === endIdx) {
179
+ if (type === "Text") {
180
+ htmlStructure += `<span class="${className}">${text.substring(0, endOffset)}</span>${text.substring(endOffset, text.length)}`;
181
+ } else {
182
+ const childClassList = [...child.classList];
183
+ if (hasClassName) {
184
+ if (childClassList.length === 1) {
185
+ htmlStructure += `${text.substring(0, endOffset)}<span class="${className}">${text.substring(endOffset, text.length)}</span>`;
186
+ } else {
187
+ const classIdx = childClassList.indexOf(className);
188
+ const newClassList = [...child.classList];
189
+ newClassList.splice(classIdx, 1);
190
+ htmlStructure += `<span class="${newClassList.join(" ")}">${text.substring(0, endOffset)}</span>`;
191
+ htmlStructure += `<span class="${childClassList.join(" ")}">${text.substring(endOffset, text.length)}</span>`;
192
+ }
193
+ } else {
194
+ htmlStructure += `<span class="${childClassList.join(" ")} ${className}">${text.substring(0, endOffset)}</span>`;
195
+ htmlStructure += `<span class="${childClassList.join(" ")}">${text.substring(endOffset, text.length)}</span>`;
196
+ }
197
+ }
198
+ } else {
199
+ if (type === "Text") {
200
+ htmlStructure += child.textContent;
201
+ } else {
202
+ htmlStructure += child.outerHTML;
203
+ }
204
+ }
205
+ });
206
+ editableElement.innerHTML = htmlStructure;
207
+ setTimeout(() => {
208
+ const $target2 = editableElement.childNodes[endIdx + 1];
209
+ const length = $target2.textContent.length;
210
+ setCursor($target2, length);
211
+ }, 100);
212
+ }
213
+ } else {
214
+ if (startNode.constructor.name === "Text") {
215
+ const parentNode = startNode.parentNode;
216
+ const parentNodeClassList = [...parentNode.classList];
217
+ if (parentNodeClassList.indexOf(className) > -1) {
218
+ if (parentNodeClassList.length === 1) {
219
+ const textContent = parentNode.textContent;
220
+ parentNode.insertAdjacentText("afterend", textContent);
221
+ setCursor(getNextNode($target, parentNode), textContent.length);
222
+ parentNode.remove();
223
+ } else {
224
+ parentNode.classList.remove(className);
225
+ }
226
+ } else {
227
+ parentNode.classList.add(className);
228
+ }
229
+ } else {
230
+ startNode.classList.toggle(className);
231
+ }
232
+ }
233
+ }
234
+ return originData;
235
+ }
236
+ export function styleSettings(type, blockData, $target) {
237
+ let rawData = blockData;
238
+ switch (type) {
239
+ case "alignLeft":
240
+ rawData.classList = arrangementAlignClass(rawData.classList, "d-align-left");
241
+ break;
242
+ case "alignCenter":
243
+ rawData.classList = arrangementAlignClass(rawData.classList, "d-align-center");
244
+ break;
245
+ case "alignRight":
246
+ rawData.classList = arrangementAlignClass(rawData.classList, "d-align-right");
247
+ break;
248
+ case "decorationBold":
249
+ rawData = defaultDecorationMake(rawData, $target, "d-deco-bold");
250
+ break;
251
+ case "decorationItalic":
252
+ rawData = defaultDecorationMake(rawData, $target, "d-deco-italic");
253
+ break;
254
+ case "decorationUnderline":
255
+ rawData = defaultDecorationMake(rawData, $target, "d-deco-underline");
256
+ break;
257
+ case "decorationStrikethrough":
258
+ rawData = defaultDecorationMake(rawData, $target, "d-deco-through");
259
+ break;
260
+ default:
261
+ rawData = defaultDecorationMake(rawData, $target, type);
262
+ }
263
+ return rawData;
264
+ }