dragon-editor 2.0.0-beta.1.4 → 2.0.0-beta.2

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 (29) hide show
  1. package/README.md +72 -135
  2. package/README_en.md +14 -62
  3. package/dist/module.json +1 -1
  4. package/dist/module.mjs +8 -0
  5. package/dist/runtime/core/components/SvgIcon.vue +30 -21
  6. package/dist/runtime/core/components/editor/ImageBlock.vue +174 -0
  7. package/dist/runtime/core/components/editor/TextBlock.vue +76 -31
  8. package/dist/runtime/core/components/icon/Accept.vue +5 -0
  9. package/dist/runtime/core/components/icon/ArrowDown.vue +3 -0
  10. package/dist/runtime/core/components/icon/ArrowUp.vue +3 -0
  11. package/dist/runtime/core/components/icon/Cancel.vue +5 -0
  12. package/dist/runtime/core/components/icon/Delete.vue +3 -0
  13. package/dist/runtime/core/style/common.css +260 -31
  14. package/dist/runtime/core/style/viewer.css +191 -0
  15. package/dist/runtime/core/utils/cursor.d.ts +1 -1
  16. package/dist/runtime/core/utils/cursor.mjs +16 -4
  17. package/dist/runtime/core/utils/element.mjs +8 -4
  18. package/dist/runtime/core/utils/index.d.ts +2 -3
  19. package/dist/runtime/core/utils/index.mjs +47 -6
  20. package/dist/runtime/core/utils/keyboard.d.ts +1 -1
  21. package/dist/runtime/core/utils/keyboard.mjs +264 -40
  22. package/dist/runtime/core/utils/style.d.ts +6 -2
  23. package/dist/runtime/core/utils/style.mjs +125 -30
  24. package/dist/runtime/shared/components/DragonEditor.vue +356 -157
  25. package/dist/runtime/shared/components/DragonEditorComment.vue +33 -11
  26. package/dist/runtime/shared/components/DragonEditorViewer.vue +28 -2
  27. package/package.json +1 -1
  28. package/dist/runtime/core/style/main.d.ts +0 -1
  29. package/dist/runtime/core/style/main.mjs +0 -24
@@ -0,0 +1,191 @@
1
+ .dragon-editor-viewer {
2
+ width: 100%;
3
+ padding: 10px;
4
+ line-height: 1.6;
5
+ }
6
+ .dragon-editor-viewer h1,
7
+ .dragon-editor-viewer h2,
8
+ .dragon-editor-viewer h3,
9
+ .dragon-editor-viewer h4,
10
+ .dragon-editor-viewer h5,
11
+ .dragon-editor-viewer h6,
12
+ .dragon-editor-viewer p,
13
+ .dragon-editor-viewer blockquote,
14
+ .dragon-editor-viewer pre,
15
+ .dragon-editor-viewer dl,
16
+ .dragon-editor-viewer dd,
17
+ .dragon-editor-viewer ol,
18
+ .dragon-editor-viewer ul,
19
+ .dragon-editor-viewer fieldset,
20
+ .dragon-editor-viewer legend,
21
+ .dragon-editor-viewer figure,
22
+ .dragon-editor-viewer menu {
23
+ margin: 0;
24
+ padding: 0;
25
+ border: 0;
26
+ }
27
+ .dragon-editor-viewer table,
28
+ .dragon-editor-viewer th,
29
+ .dragon-editor-viewer td {
30
+ border-spacing: 0;
31
+ border-collapse: collapse;
32
+ }
33
+ .dragon-editor-viewer ol,
34
+ .dragon-editor-viewer ul,
35
+ .dragon-editor-viewer li {
36
+ list-style: none;
37
+ }
38
+ .dragon-editor-viewer h1,
39
+ .dragon-editor-viewer h2,
40
+ .dragon-editor-viewer h3,
41
+ .dragon-editor-viewer h4,
42
+ .dragon-editor-viewer h5,
43
+ .dragon-editor-viewer h6 {
44
+ font-size: 1em;
45
+ font-weight: normal;
46
+ }
47
+ .dragon-editor-viewer input,
48
+ .dragon-editor-viewer textarea,
49
+ .dragon-editor-viewer select,
50
+ .dragon-editor-viewer button {
51
+ margin: 0;
52
+ padding: 0;
53
+ border-radius: 0;
54
+ outline: 0;
55
+ vertical-align: middle;
56
+ }
57
+ .dragon-editor-viewer a,
58
+ .dragon-editor-viewer button,
59
+ .dragon-editor-viewer input[type=submit],
60
+ .dragon-editor-viewer input[type=button],
61
+ .dragon-editor-viewer input[type=reset] {
62
+ border: 0;
63
+ background: transparent;
64
+ cursor: pointer;
65
+ }
66
+ .dragon-editor-viewer img {
67
+ border: 0;
68
+ vertical-align: top;
69
+ }
70
+ .dragon-editor-viewer .d-align-left {
71
+ text-align: left;
72
+ }
73
+ .dragon-editor-viewer .d-align-center {
74
+ text-align: center;
75
+ }
76
+ .dragon-editor-viewer .d-align-right {
77
+ text-align: right;
78
+ }
79
+ .dragon-editor-viewer .d-deco-bold {
80
+ font-weight: bold;
81
+ }
82
+ .dragon-editor-viewer .d-deco-italic {
83
+ font-style: italic;
84
+ }
85
+ .dragon-editor-viewer .d-deco-underline {
86
+ text-decoration: underline;
87
+ }
88
+ .dragon-editor-viewer .d-deco-underline.d-deco-through {
89
+ text-decoration: underline line-through;
90
+ }
91
+ .dragon-editor-viewer .d-deco-through {
92
+ text-decoration: line-through;
93
+ }
94
+ .dragon-editor-viewer .d-deco-through.d-deco-underline, .dragon-editor-viewer .d-deco-through.d-deco-link {
95
+ text-decoration: line-through underline;
96
+ }
97
+ .dragon-editor-viewer .d-deco-code {
98
+ padding: 2px 5px;
99
+ margin: 0 2px;
100
+ background: #f1f1f1;
101
+ color: #c52e2e;
102
+ border-radius: 2px;
103
+ font-family: Inconsolata, monospace, sans-serif;
104
+ }
105
+ .dragon-editor-viewer .d-deco-link {
106
+ color: inherit;
107
+ }
108
+ .dragon-editor-viewer .d-text-block:empty {
109
+ min-height: 1.6em;
110
+ }
111
+ .dragon-editor-viewer .d-image-block {
112
+ display: flex;
113
+ flex-direction: column;
114
+ align-items: center;
115
+ row-gap: 5px;
116
+ }
117
+ .dragon-editor-viewer .d-image-block.d-align-left {
118
+ align-items: flex-start;
119
+ }
120
+ .dragon-editor-viewer .d-image-block.d-align-right {
121
+ align-items: flex-end;
122
+ }
123
+ .dragon-editor-viewer .d-image-block.--1 .d-image-area {
124
+ width: 5%;
125
+ }
126
+ .dragon-editor-viewer .d-image-block.--2 .d-image-area {
127
+ width: 10%;
128
+ }
129
+ .dragon-editor-viewer .d-image-block.--3 .d-image-area {
130
+ width: 15%;
131
+ }
132
+ .dragon-editor-viewer .d-image-block.--4 .d-image-area {
133
+ width: 20%;
134
+ }
135
+ .dragon-editor-viewer .d-image-block.--5 .d-image-area {
136
+ width: 25%;
137
+ }
138
+ .dragon-editor-viewer .d-image-block.--6 .d-image-area {
139
+ width: 30%;
140
+ }
141
+ .dragon-editor-viewer .d-image-block.--7 .d-image-area {
142
+ width: 35%;
143
+ }
144
+ .dragon-editor-viewer .d-image-block.--8 .d-image-area {
145
+ width: 40%;
146
+ }
147
+ .dragon-editor-viewer .d-image-block.--9 .d-image-area {
148
+ width: 45%;
149
+ }
150
+ .dragon-editor-viewer .d-image-block.--10 .d-image-area {
151
+ width: 50%;
152
+ }
153
+ .dragon-editor-viewer .d-image-block.--11 .d-image-area {
154
+ width: 55%;
155
+ }
156
+ .dragon-editor-viewer .d-image-block.--12 .d-image-area {
157
+ width: 60%;
158
+ }
159
+ .dragon-editor-viewer .d-image-block.--13 .d-image-area {
160
+ width: 65%;
161
+ }
162
+ .dragon-editor-viewer .d-image-block.--14 .d-image-area {
163
+ width: 70%;
164
+ }
165
+ .dragon-editor-viewer .d-image-block.--15 .d-image-area {
166
+ width: 75%;
167
+ }
168
+ .dragon-editor-viewer .d-image-block.--16 .d-image-area {
169
+ width: 80%;
170
+ }
171
+ .dragon-editor-viewer .d-image-block.--17 .d-image-area {
172
+ width: 85%;
173
+ }
174
+ .dragon-editor-viewer .d-image-block.--18 .d-image-area {
175
+ width: 90%;
176
+ }
177
+ .dragon-editor-viewer .d-image-block.--19 .d-image-area {
178
+ width: 95%;
179
+ }
180
+ .dragon-editor-viewer .d-image-block.--20 .d-image-area {
181
+ width: 100%;
182
+ }
183
+ .dragon-editor-viewer .d-image-block .d-image-area .d-img {
184
+ width: 100%;
185
+ height: auto;
186
+ }
187
+ .dragon-editor-viewer .d-image-block .d-caption {
188
+ width: 100%;
189
+ color: #ccc;
190
+ font-size: 1rem;
191
+ }
@@ -1,4 +1,4 @@
1
1
  import type { cursorSelection, arrangementCursorData } from "../../../types";
2
2
  export declare function setCursor(target: Node, idx: number): void;
3
3
  export declare function getCursor(): cursorSelection;
4
- export declare function getArrangementCursorData(): arrangementCursorData;
4
+ export declare function getArrangementCursorData(parentCursorData: any): arrangementCursorData;
@@ -9,6 +9,10 @@ export function setCursor(target, idx) {
9
9
  }
10
10
  const select = window.getSelection();
11
11
  const range = document.createRange();
12
+ const realLength = $target.textContent?.length;
13
+ if (realLength < idx) {
14
+ idx = realLength;
15
+ }
12
16
  range.setStart($target, idx);
13
17
  range.collapse(true);
14
18
  select.removeAllRanges();
@@ -25,10 +29,18 @@ export function getCursor() {
25
29
  endOffset: select.focusOffset
26
30
  };
27
31
  }
28
- export function getArrangementCursorData() {
29
- const cursorData = getCursor();
30
- const startNode = cursorData.startNode;
31
- const editableElement = findEditableElement(startNode);
32
+ export function getArrangementCursorData(parentCursorData) {
33
+ let cursorData = getCursor();
34
+ if (cursorData.startNode === null) {
35
+ cursorData = parentCursorData;
36
+ }
37
+ let startNode = cursorData.startNode;
38
+ let editableElement = findEditableElement(startNode);
39
+ if (editableElement === null) {
40
+ cursorData = parentCursorData;
41
+ startNode = cursorData.startNode;
42
+ editableElement = findEditableElement(startNode);
43
+ }
32
44
  let childNode;
33
45
  let childIdx = -1;
34
46
  let fixIdx = 0;
@@ -3,11 +3,15 @@ export function findEditableElement(node) {
3
3
  if (node.constructor.name === "Text") {
4
4
  return findEditableElement(node.parentNode);
5
5
  } else {
6
- const hasAttr = node.getAttribute("contenteditable") !== null;
7
- if (hasAttr) {
8
- return node;
6
+ if (node.getAttribute) {
7
+ const hasAttr = node.getAttribute("contenteditable") !== null;
8
+ if (hasAttr) {
9
+ return node;
10
+ } else {
11
+ return findEditableElement(node.parentNode);
12
+ }
9
13
  } else {
10
- return findEditableElement(node.parentNode);
14
+ return null;
11
15
  }
12
16
  }
13
17
  } else {
@@ -1,6 +1,5 @@
1
- import { textBlock } from "../../../types/index";
2
- export declare function createTextBlock(): textBlock;
3
- export declare function createBlock(name: string): textBlock;
1
+ import { allBlock } from "../../../types/index";
2
+ export declare function createBlock(name: string, value?: object): allBlock;
4
3
  export * from "./keyboard";
5
4
  export * from "./cursor";
6
5
  export * from "./style";
@@ -6,19 +6,60 @@ function generateId() {
6
6
  }
7
7
  return str;
8
8
  }
9
- export function createTextBlock() {
9
+ function createTextBlock(data) {
10
+ if (data) {
11
+ return {
12
+ type: "text",
13
+ id: generateId(),
14
+ classList: data.classList,
15
+ content: data.content
16
+ };
17
+ } else {
18
+ return {
19
+ type: "text",
20
+ id: generateId(),
21
+ classList: [],
22
+ content: ""
23
+ };
24
+ }
25
+ }
26
+ function createImageBlock(data) {
27
+ const totalSize = data.width + data.height;
28
+ const w = Math.round(100 / totalSize * data.width);
29
+ const h = Math.round(100 / totalSize * data.height);
30
+ const contrast = w - h;
31
+ let classList = ["d-align-center"];
32
+ switch (true) {
33
+ case contrast < -40:
34
+ classList.push("--5");
35
+ break;
36
+ case contrast < -15:
37
+ classList.push("--10");
38
+ break;
39
+ default:
40
+ classList.push("--20");
41
+ }
10
42
  return {
11
- type: "text",
43
+ type: "image",
12
44
  id: generateId(),
13
- classList: [],
14
- content: ""
45
+ classList,
46
+ src: data.src,
47
+ width: data.width,
48
+ height: data.height,
49
+ webp: data.webp,
50
+ caption: data.caption
15
51
  };
16
52
  }
17
- export function createBlock(name) {
53
+ export function createBlock(name, value) {
54
+ let blockData;
18
55
  switch (name) {
56
+ case "image":
57
+ blockData = createImageBlock(value);
58
+ break;
19
59
  default:
20
- return createTextBlock();
60
+ blockData = createTextBlock(value);
21
61
  }
62
+ return blockData;
22
63
  }
23
64
  export * from "./keyboard.mjs";
24
65
  export * from "./cursor.mjs";
@@ -1,4 +1,4 @@
1
- export declare function keyboardEvent(type: string, event: KeyboardEvent, addAction: Function): void;
1
+ export declare function keyboardEvent(type: string, event: KeyboardEvent, action: Function, update: Function): void;
2
2
  export declare function getClipboardData(data: DataTransfer): {
3
3
  type: any;
4
4
  value: any;
@@ -1,35 +1,150 @@
1
1
  import { getCursor, setCursor } from "./cursor.mjs";
2
2
  import { findEditableElement, findChildNumber } from "./element.mjs";
3
+ import { getTagName } from "./style.mjs";
3
4
  let enterCount = 0;
4
- function enterEvent(type, event, addAction) {
5
+ function enterEvent(type, event, action) {
5
6
  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();
7
+ event.preventDefault();
8
+ const useShift = event.shiftKey;
9
+ switch (type) {
10
+ case "image":
11
+ action("addBlock", {
12
+ name: "text"
13
+ });
14
+ break;
15
+ case "comment":
16
+ addBrEvent();
17
+ break;
18
+ default:
19
+ if (useShift === false) {
20
+ if (enterCount == 0) {
21
+ textEnterEvent(event, action);
22
+ }
23
+ } else {
12
24
  addBrEvent();
13
- break;
14
- default:
15
- if (useShift === false) {
16
- event.preventDefault();
17
- addAction("addBlock", "text");
25
+ }
26
+ }
27
+ enterCount += 1;
28
+ setTimeout(() => {
29
+ enterCount = 0;
30
+ }, 150);
31
+ }
32
+ }
33
+ function textEnterEvent(event, action) {
34
+ const cursorData = getCursor();
35
+ if (cursorData.startNode) {
36
+ const editableElement = findEditableElement(cursorData.startNode);
37
+ const editableElementClassList = [...editableElement.classList].slice(0, 1);
38
+ const startNode = cursorData.startNode;
39
+ const endNode = cursorData.endNode;
40
+ let startChild = startNode;
41
+ let endChild = endNode;
42
+ if (startNode.parentNode !== editableElement) {
43
+ startChild = startNode.parentNode;
44
+ }
45
+ if (endNode.parentNode !== editableElement) {
46
+ endChild = endNode.parentNode;
47
+ }
48
+ const startChildIdx = findChildNumber(editableElement, startChild);
49
+ const endChildIdx = findChildNumber(editableElement, endChild);
50
+ let startIdx = 0;
51
+ let endIdx = 0;
52
+ let startOffset = 0;
53
+ let endOffset = 0;
54
+ let preHTMLStructor = "";
55
+ let nextHTMLStructor = "";
56
+ if (startChildIdx > endChildIdx) {
57
+ startIdx = endChildIdx;
58
+ endIdx = startChildIdx;
59
+ startOffset = cursorData.endOffset;
60
+ endOffset = cursorData.startOffset;
61
+ } else {
62
+ startIdx = startChildIdx;
63
+ endIdx = endChildIdx;
64
+ startOffset = cursorData.startOffset;
65
+ endOffset = cursorData.endOffset;
66
+ }
67
+ if (editableElement.childNodes.length === 0 || endChildIdx === editableElement.childNodes.length - 1 && editableElement.childNodes[endChildIdx].textContent.length === endOffset) {
68
+ action("addBlock", {
69
+ name: "text"
70
+ });
71
+ } else {
72
+ editableElement.childNodes.forEach((child, count) => {
73
+ const text = child.textContent;
74
+ if (count < startChildIdx) {
75
+ if (child.constructor.name === "Text") {
76
+ preHTMLStructor += child.textContent;
77
+ } else {
78
+ preHTMLStructor += child.outerHTML;
79
+ }
80
+ } else if (count > endChildIdx) {
81
+ if (child.constructor.name === "Text") {
82
+ nextHTMLStructor += child.textContent;
83
+ } else {
84
+ nextHTMLStructor += child.outerHTML;
18
85
  }
86
+ } else {
87
+ if (startChildIdx === endChildIdx) {
88
+ if (child.constructor.name === "Text") {
89
+ preHTMLStructor += text.substring(0, startOffset);
90
+ nextHTMLStructor += text.substring(endOffset, text.length);
91
+ } else {
92
+ const childClassList = [...child.classList];
93
+ const originTag = getTagName(child);
94
+ preHTMLStructor += `<${originTag.name} ${originTag.href ? `href="${originTag.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(0, startOffset)}</${originTag.name}>`;
95
+ nextHTMLStructor += `<${originTag.name} ${originTag.href ? `href="${originTag.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(endOffset, text.length)}</${originTag.name}>`;
96
+ }
97
+ } else {
98
+ if (count === startChildIdx) {
99
+ if (child.constructor.name === "Text") {
100
+ preHTMLStructor += text.substring(0, startOffset);
101
+ } else {
102
+ const childClassList = [...child.classList];
103
+ const originTag = getTagName(child);
104
+ preHTMLStructor += `<${originTag.name} ${originTag.href ? `href="${originTag.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(0, startOffset)}</${originTag.name}>`;
105
+ }
106
+ } else if (count === endChildIdx) {
107
+ if (child.constructor.name === "Text") {
108
+ nextHTMLStructor += text.substring(endOffset, text.length);
109
+ } else {
110
+ const childClassList = [...child.classList];
111
+ const originTag = getTagName(child);
112
+ nextHTMLStructor += `<${originTag.name} ${originTag.href ? `href="${originTag.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(endOffset, text.length)}</${originTag.name}>`;
113
+ }
114
+ }
115
+ }
116
+ }
117
+ });
118
+ editableElement.innerHTML = preHTMLStructor;
119
+ action("addBlock", {
120
+ name: "text",
121
+ value: { classList: editableElementClassList, content: nextHTMLStructor }
122
+ });
123
+ }
124
+ }
125
+ }
126
+ function backspaceEvent(type, event, action, update) {
127
+ if (event.code === "Backspace") {
128
+ if (type === "text") {
129
+ const cursorData = getCursor();
130
+ if (cursorData.type === "Caret" && cursorData.startOffset === 0) {
131
+ const editableElement = findEditableElement(cursorData.startNode);
132
+ let $target = cursorData.startNode;
133
+ if ($target.constructor.name === "Text") {
134
+ $target = $target.parentNode;
135
+ }
136
+ if ($target === editableElement) {
137
+ update();
138
+ event.preventDefault();
139
+ action("deleteBlockLocal");
140
+ }
19
141
  }
20
- setTimeout(() => {
21
- enterCount = 0;
22
- }, 150);
23
- } else {
24
- event.preventDefault();
25
- setTimeout(() => {
26
- enterCount = 0;
27
- }, 150);
28
142
  }
29
143
  }
30
144
  }
31
- export function keyboardEvent(type, event, addAction) {
32
- enterEvent(type, event, addAction);
145
+ export function keyboardEvent(type, event, action, update) {
146
+ enterEvent(type, event, action);
147
+ backspaceEvent(type, event, action, update);
33
148
  }
34
149
  export function getClipboardData(data) {
35
150
  let type, clipboardData;
@@ -62,7 +177,7 @@ export function pasteText(type, value) {
62
177
  const range = document.createRange();
63
178
  let textNode;
64
179
  if (type !== "codeBlock") {
65
- textNode = document.createTextNode(value.replaceAll("\n", "").replaceAll(/ +/g, " "));
180
+ textNode = document.createTextNode(value.replace("\n", "").replace(/ +/g, " "));
66
181
  } else {
67
182
  textNode = document.createTextNode(value);
68
183
  }
@@ -74,25 +189,134 @@ export function pasteText(type, value) {
74
189
  selection.addRange(range);
75
190
  }
76
191
  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
192
  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();
193
+ if (cursorData.startNode) {
194
+ let $target = cursorData.startNode;
195
+ const preEditableElement = findEditableElement($target);
196
+ if ($target.constructor.name === "Text") {
197
+ $target = $target.parentNode;
198
+ }
199
+ if (preEditableElement !== $target && $target.constructor.name !== "HTMLBRElement") {
200
+ let startNode = cursorData.startNode;
201
+ let endNode = cursorData.endNode;
202
+ let startChild = startNode;
203
+ let endChild = endNode;
204
+ if (startNode.parentNode !== preEditableElement) {
205
+ startChild = startNode.parentNode;
206
+ }
207
+ if (endNode.parentNode !== preEditableElement) {
208
+ endChild = endNode.parentNode;
209
+ }
210
+ const startChildIdx = findChildNumber(preEditableElement, startChild);
211
+ const endChildIdx = findChildNumber(preEditableElement, endChild);
212
+ let startIdx = 0;
213
+ let endIdx = 0;
214
+ let startOffset = 0;
215
+ let endOffset = 0;
216
+ let htmlStructure = "";
217
+ if (startChildIdx > endChildIdx) {
218
+ startIdx = endChildIdx;
219
+ endIdx = startChildIdx;
220
+ startOffset = cursorData.endOffset;
221
+ endOffset = cursorData.startOffset;
222
+ } else {
223
+ startIdx = startChildIdx;
224
+ endIdx = endChildIdx;
225
+ startOffset = cursorData.startOffset;
226
+ endOffset = cursorData.endOffset;
227
+ }
228
+ if (enterCount === 1) {
229
+ const text = startChild.textContent;
230
+ startChild.textContent = text.substring(1, text.length);
231
+ setCursor(startChild, 0);
232
+ } else {
233
+ if (startNode === endNode) {
234
+ const text = startChild.textContent;
235
+ const childClassList = [...startChild.classList];
236
+ const tagData = getTagName(startChild);
237
+ htmlStructure += `<${tagData.name} ${tagData.href ? `href="${tagData.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(0, startOffset)}</${tagData.name}>`;
238
+ htmlStructure += `<br>`;
239
+ htmlStructure += `<${tagData.name} ${tagData.href ? `href="${tagData.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(endOffset, text.length)}</${tagData.name}>`;
240
+ startChild.insertAdjacentHTML("beforebegin", htmlStructure);
241
+ setCursor(preEditableElement.childNodes[startChildIdx + 2], 0);
242
+ startChild.remove();
243
+ } else {
244
+ preEditableElement.childNodes.forEach((child, count) => {
245
+ const type = child.constructor.name;
246
+ const text = child.textContent;
247
+ if (count > startIdx && count < endIdx) {
248
+ } else if (count === startIdx) {
249
+ if (type === "Text") {
250
+ htmlStructure += text.substring(0, startOffset);
251
+ } else {
252
+ const childClassList = [...child.classList];
253
+ const tagData = getTagName(child);
254
+ htmlStructure += `<${tagData.name} ${tagData.href ? `href="${tagData.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(0, startOffset)}</${tagData.name}><br>`;
255
+ }
256
+ } else if (count === endIdx) {
257
+ if (type === "Text") {
258
+ htmlStructure += text.substring(endOffset, text.length);
259
+ } else {
260
+ const childClassList = [...child.classList];
261
+ const tagData = getTagName(child);
262
+ htmlStructure += `<${tagData.name} ${tagData.href ? `href="${tagData.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(endOffset, text.length)}</${tagData.name}><br>`;
263
+ }
264
+ } else {
265
+ if (type === "Text") {
266
+ htmlStructure += child.textContent;
267
+ } else {
268
+ htmlStructure += child.outerHTML;
269
+ }
270
+ }
271
+ });
272
+ preEditableElement.innerHTML = htmlStructure;
273
+ }
274
+ }
94
275
  } else {
95
- setCursor(childList[childIdx + 1], 0);
276
+ const brTag = document.createElement("br");
277
+ const selection = window.getSelection();
278
+ const range = document.createRange();
279
+ if (enterCount === 1) {
280
+ const nextCursorData = getCursor();
281
+ const editableElement = findEditableElement(nextCursorData.startNode);
282
+ const childList = editableElement.childNodes;
283
+ const childIdx = findChildNumber(editableElement, nextCursorData.startNode);
284
+ setCursor(childList[childIdx + 2], 0);
285
+ } else {
286
+ selection.deleteFromDocument();
287
+ selection.getRangeAt(0).insertNode(brTag);
288
+ range.setStart(brTag, 0);
289
+ range.collapse(true);
290
+ selection.removeAllRanges();
291
+ selection.addRange(range);
292
+ const nextCursorData = getCursor();
293
+ const editableElement = findEditableElement(nextCursorData.startNode);
294
+ const childList = editableElement.childNodes;
295
+ const childIdx = findChildNumber(editableElement, nextCursorData.startNode);
296
+ let hasText = false;
297
+ childList.forEach((row) => {
298
+ if (row.constructor.name === "Text") {
299
+ hasText = true;
300
+ }
301
+ });
302
+ if (hasText) {
303
+ if (childList[childIdx + 1].textContent?.length === 0) {
304
+ if (childList[childIdx + 2]) {
305
+ if (childList[childIdx + 2].constructor.name == "HTMLBRElement") {
306
+ setCursor(childList[childIdx + 1], 0);
307
+ } else {
308
+ childList[childIdx].insertAdjacentHTML("beforebegin", "<br>");
309
+ }
310
+ } else {
311
+ childList[childIdx].insertAdjacentHTML("beforebegin", "<br>");
312
+ }
313
+ } else {
314
+ setCursor(childList[childIdx + 1], 0);
315
+ }
316
+ } else {
317
+ childList[childIdx].insertAdjacentHTML("beforebegin", "<br>");
318
+ }
319
+ }
96
320
  }
97
321
  }
98
322
  }
@@ -1,2 +1,6 @@
1
- import type { allBlock } from "../../../types";
2
- export declare function styleSettings(type: string, blockData: allBlock, $target: HTMLElement): allBlock;
1
+ import type { allBlock, styleUtilArgument } from "../../../types";
2
+ export declare function styleSettings({ kind, blockData, $target, url, cursorData }: styleUtilArgument): allBlock;
3
+ export declare function getTagName(node: HTMLElement): {
4
+ name: string;
5
+ href: string | null;
6
+ };