dragon-editor 3.8.6 → 4.0.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 (91) hide show
  1. package/README.md +10 -9
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +9 -7
  4. package/dist/runtime/components/Block/Code.d.vue.ts +13 -0
  5. package/dist/runtime/components/Block/Code.vue +193 -0
  6. package/dist/runtime/components/Block/Code.vue.d.ts +13 -0
  7. package/dist/runtime/components/Block/Custom.d.vue.ts +9 -0
  8. package/dist/runtime/components/Block/Custom.vue +28 -0
  9. package/dist/runtime/components/Block/Custom.vue.d.ts +9 -0
  10. package/dist/runtime/components/Block/Divider.d.vue.ts +9 -0
  11. package/dist/runtime/components/Block/Divider.vue +27 -0
  12. package/dist/runtime/components/Block/Divider.vue.d.ts +9 -0
  13. package/dist/runtime/components/Block/Heading.d.vue.ts +13 -0
  14. package/dist/runtime/components/Block/Heading.vue +84 -0
  15. package/dist/runtime/components/Block/Heading.vue.d.ts +13 -0
  16. package/dist/runtime/components/Block/Image.d.vue.ts +13 -0
  17. package/dist/runtime/components/Block/Image.vue +146 -0
  18. package/dist/runtime/components/Block/Image.vue.d.ts +13 -0
  19. package/dist/runtime/components/Block/List.d.vue.ts +13 -0
  20. package/dist/runtime/components/Block/List.vue +170 -0
  21. package/dist/runtime/components/Block/List.vue.d.ts +13 -0
  22. package/dist/runtime/components/Block/Text.d.vue.ts +13 -0
  23. package/dist/runtime/components/Block/Text.vue +84 -0
  24. package/dist/runtime/components/Block/Text.vue.d.ts +13 -0
  25. package/dist/runtime/components/DragonEditor.d.vue.ts +28 -22
  26. package/dist/runtime/components/DragonEditor.vue +75 -1225
  27. package/dist/runtime/components/DragonEditor.vue.d.ts +28 -22
  28. package/dist/runtime/components/DragonEditorViewer.d.vue.ts +13 -5
  29. package/dist/runtime/components/DragonEditorViewer.vue +17 -813
  30. package/dist/runtime/components/DragonEditorViewer.vue.d.ts +13 -5
  31. package/dist/runtime/components/MenuBar.d.vue.ts +3 -0
  32. package/dist/runtime/components/MenuBar.vue +385 -0
  33. package/dist/runtime/components/MenuBar.vue.d.ts +3 -0
  34. package/dist/runtime/scss/editor.css +237 -283
  35. package/dist/runtime/scss/viewer.css +184 -210
  36. package/dist/runtime/store/editor.d.ts +2 -0
  37. package/dist/runtime/store/editor.js +59 -0
  38. package/dist/runtime/type.d.mts +101 -124
  39. package/dist/runtime/utils/data/block.d.ts +20 -0
  40. package/dist/runtime/utils/data/block.js +663 -0
  41. package/dist/runtime/utils/data/cursor.d.ts +9 -0
  42. package/dist/runtime/utils/data/cursor.js +137 -0
  43. package/dist/runtime/utils/data/index.d.ts +5 -0
  44. package/dist/runtime/utils/data/index.js +17 -0
  45. package/dist/runtime/utils/data/node.d.ts +9 -0
  46. package/dist/runtime/utils/data/node.js +101 -0
  47. package/dist/runtime/utils/event/cursor.d.ts +3 -6
  48. package/dist/runtime/utils/event/cursor.js +52 -105
  49. package/dist/runtime/utils/event/index.d.ts +2 -6
  50. package/dist/runtime/utils/event/index.js +48 -6
  51. package/dist/runtime/utils/event/keyboard.d.ts +22 -7
  52. package/dist/runtime/utils/event/keyboard.js +910 -1406
  53. package/dist/runtime/utils/layout/body.d.ts +3 -4
  54. package/dist/runtime/utils/layout/body.js +83 -51
  55. package/dist/runtime/utils/layout/icon.d.ts +1 -2
  56. package/dist/runtime/utils/layout/icon.js +64 -67
  57. package/dist/runtime/utils/layout/index.d.ts +0 -3
  58. package/dist/runtime/utils/layout/index.js +0 -3
  59. package/dist/runtime/utils/node/element.d.ts +4 -6
  60. package/dist/runtime/utils/node/element.js +58 -71
  61. package/dist/runtime/utils/node/index.d.ts +1 -1
  62. package/dist/runtime/utils/node/index.js +1 -1
  63. package/dist/runtime/utils/node/style.d.ts +5 -0
  64. package/dist/runtime/utils/node/style.js +702 -0
  65. package/package.json +31 -17
  66. package/dist/runtime/utils/event/block.d.ts +0 -7
  67. package/dist/runtime/utils/event/block.js +0 -110
  68. package/dist/runtime/utils/event/data.d.ts +0 -8
  69. package/dist/runtime/utils/event/data.js +0 -379
  70. package/dist/runtime/utils/event/mouse.d.ts +0 -11
  71. package/dist/runtime/utils/event/mouse.js +0 -85
  72. package/dist/runtime/utils/event/scroll.d.ts +0 -3
  73. package/dist/runtime/utils/event/scroll.js +0 -29
  74. package/dist/runtime/utils/event/touch.d.ts +0 -5
  75. package/dist/runtime/utils/event/touch.js +0 -10
  76. package/dist/runtime/utils/event/window.d.ts +0 -5
  77. package/dist/runtime/utils/event/window.js +0 -47
  78. package/dist/runtime/utils/layout/block.d.ts +0 -7
  79. package/dist/runtime/utils/layout/block.js +0 -123
  80. package/dist/runtime/utils/layout/controlbar.d.ts +0 -3
  81. package/dist/runtime/utils/layout/controlbar.js +0 -99
  82. package/dist/runtime/utils/layout/menuBar.d.ts +0 -3
  83. package/dist/runtime/utils/layout/menuBar.js +0 -408
  84. package/dist/runtime/utils/node/block.d.ts +0 -19
  85. package/dist/runtime/utils/node/block.js +0 -256
  86. package/dist/runtime/utils/style/anchor.d.ts +0 -5
  87. package/dist/runtime/utils/style/anchor.js +0 -245
  88. package/dist/runtime/utils/style/decoration.d.ts +0 -4
  89. package/dist/runtime/utils/style/decoration.js +0 -378
  90. package/dist/runtime/utils/style/index.d.ts +0 -2
  91. package/dist/runtime/utils/style/index.js +0 -2
@@ -0,0 +1,663 @@
1
+ import { nextTick } from "#imports";
2
+ import { useEditorStore } from "../../store/editor.js";
3
+ import { _setCursorPosition } from "../event/index.js";
4
+ import { _generateId, _getEditorbleCursorPosition } from "../data/index.js";
5
+ import { _findEditableElement, _findEditableParent, _findParentBlock } from "../node/index.js";
6
+ export function _arrangementContentData(data) {
7
+ const editorStore = useEditorStore();
8
+ data.forEach((block) => {
9
+ switch (block.type) {
10
+ case "text":
11
+ if (block.textContent === "<br>") {
12
+ block.textContent = "";
13
+ }
14
+ break;
15
+ case "heading":
16
+ if (block.textContent === "<br>") {
17
+ block.textContent = "";
18
+ }
19
+ break;
20
+ case "list":
21
+ if ("classList" in block) {
22
+ delete block.classList;
23
+ }
24
+ if ("style" in block) {
25
+ delete block.style;
26
+ }
27
+ block.child.forEach((child) => {
28
+ if (child.textContent === "<br>") {
29
+ child.textContent = "";
30
+ }
31
+ });
32
+ break;
33
+ case "image":
34
+ if ("width" in block) {
35
+ delete block.width;
36
+ }
37
+ if ("height" in block) {
38
+ delete block.height;
39
+ }
40
+ if (editorStore.option.mediaHostURL !== "") {
41
+ block.src = block.src.replace(editorStore.option.mediaHostURL, "");
42
+ }
43
+ if (block.caption === "<br>") {
44
+ block.caption = "";
45
+ }
46
+ break;
47
+ case "code":
48
+ if ("classList" in block) {
49
+ delete block.classList;
50
+ }
51
+ if ("theme" in block) {
52
+ delete block.theme;
53
+ }
54
+ if (block.filename === "<br>") {
55
+ block.filename = "";
56
+ }
57
+ if (block.textContent === "<br>") {
58
+ block.textContent = "";
59
+ }
60
+ break;
61
+ case "custom":
62
+ if ("classList" in block) {
63
+ delete block.classList;
64
+ }
65
+ break;
66
+ }
67
+ });
68
+ return data;
69
+ }
70
+ export function _createTextBlockData(textContent = "") {
71
+ return {
72
+ id: _generateId(),
73
+ classList: [],
74
+ type: "text",
75
+ textContent
76
+ };
77
+ }
78
+ export function _createHeadingBlockData(level, textContent = "") {
79
+ return {
80
+ id: _generateId(),
81
+ type: "heading",
82
+ classList: [],
83
+ level,
84
+ textContent
85
+ };
86
+ }
87
+ export function _createListBlockData(element, childList = [_createListBlockChildData()]) {
88
+ return {
89
+ id: _generateId(),
90
+ type: "list",
91
+ element,
92
+ child: childList
93
+ };
94
+ }
95
+ export function _createListBlockChildData(textContent = "", depth = 0) {
96
+ return { id: _generateId(), classList: [], depth: depth === 0 ? void 0 : depth, textContent };
97
+ }
98
+ export function _createImageBlockData(src, caption = "", useHost = true) {
99
+ const editorStore = useEditorStore();
100
+ return {
101
+ id: _generateId(),
102
+ type: "image",
103
+ classList: [],
104
+ maxWidth: 50,
105
+ src: useHost === true ? editorStore.option.mediaHostURL + src : src,
106
+ caption
107
+ };
108
+ }
109
+ export function _createCodeBlockData(language = "text", textContent = "", filename = "") {
110
+ return {
111
+ id: _generateId(),
112
+ type: "code",
113
+ language,
114
+ filename,
115
+ textContent
116
+ };
117
+ }
118
+ export function _createDividerBlockData() {
119
+ return {
120
+ id: _generateId(),
121
+ type: "divider"
122
+ };
123
+ }
124
+ export function _createCustomBlockData(textContent = "") {
125
+ return {
126
+ id: _generateId(),
127
+ type: "custom",
128
+ textContent
129
+ };
130
+ }
131
+ export function _getBlockType($block) {
132
+ let type = "text";
133
+ switch (true) {
134
+ case $block.classList.contains("de-text-block"):
135
+ type = "text";
136
+ break;
137
+ case $block.classList.contains("de-heading-block"):
138
+ type = "heading";
139
+ break;
140
+ case $block.classList.contains("de-list-block"):
141
+ type = "list";
142
+ break;
143
+ case $block.classList.contains("de-image-block"):
144
+ type = "image";
145
+ break;
146
+ case $block.classList.contains("de-code-block"):
147
+ type = "code";
148
+ break;
149
+ case $block.classList.contains("de-custom-block"):
150
+ type = "custom";
151
+ break;
152
+ case $block.classList.contains("de-divider-block"):
153
+ type = "divider";
154
+ break;
155
+ }
156
+ return type;
157
+ }
158
+ export async function _addBlock(name, textContent = "") {
159
+ const editorStore = useEditorStore();
160
+ const newData = JSON.parse(JSON.stringify(editorStore.data));
161
+ let newBlock = _createTextBlockData(textContent);
162
+ let targetIndex = editorStore.selectedBlockIndex;
163
+ if (editorStore.fn.updateEditorData !== null && editorStore.element.body !== null) {
164
+ switch (name) {
165
+ case "text":
166
+ newBlock = _createTextBlockData(textContent);
167
+ break;
168
+ case "heading1":
169
+ newBlock = _createHeadingBlockData(1, textContent);
170
+ break;
171
+ case "heading2":
172
+ newBlock = _createHeadingBlockData(2, textContent);
173
+ break;
174
+ case "heading3":
175
+ newBlock = _createHeadingBlockData(3, textContent);
176
+ break;
177
+ case "unordered-list":
178
+ newBlock = _createListBlockData("ul", [_createListBlockChildData(textContent)]);
179
+ break;
180
+ case "ordered-list":
181
+ newBlock = _createListBlockData("ol", [_createListBlockChildData(textContent)]);
182
+ break;
183
+ case "code":
184
+ newBlock = _createCodeBlockData("text", textContent);
185
+ break;
186
+ case "custom":
187
+ newBlock = _createCustomBlockData(textContent);
188
+ break;
189
+ case "divider":
190
+ newBlock = _createDividerBlockData();
191
+ break;
192
+ }
193
+ if (targetIndex === -1) {
194
+ newData.push(newBlock);
195
+ targetIndex = newData.length - 1;
196
+ } else {
197
+ newData.splice(editorStore.selectedBlockIndex + 1, 0, newBlock);
198
+ targetIndex = editorStore.selectedBlockIndex + 1;
199
+ }
200
+ editorStore.fn.updateEditorData(newData);
201
+ await nextTick();
202
+ const $targetBlock = editorStore.element.body.children[targetIndex];
203
+ if ($targetBlock !== void 0) {
204
+ const $targetNode = _findEditableElement($targetBlock, "down");
205
+ if ($targetNode !== null) {
206
+ $targetNode.focus();
207
+ $targetNode.dispatchEvent(new Event("input"));
208
+ }
209
+ }
210
+ }
211
+ }
212
+ export async function _addImageBlock(src, caption = "") {
213
+ const editorStore = useEditorStore();
214
+ const newData = JSON.parse(JSON.stringify(editorStore.data));
215
+ const imageBlock = _createImageBlockData(src, caption);
216
+ let targetIndex = editorStore.selectedBlockIndex;
217
+ if (editorStore.fn.updateEditorData !== null && editorStore.element.body !== null) {
218
+ if (targetIndex === -1) {
219
+ newData.push(imageBlock);
220
+ targetIndex = newData.length - 1;
221
+ } else {
222
+ newData.splice(editorStore.selectedBlockIndex + 1, 0, imageBlock);
223
+ targetIndex = editorStore.selectedBlockIndex + 1;
224
+ }
225
+ editorStore.fn.updateEditorData(newData);
226
+ await nextTick();
227
+ const $targetBlock = editorStore.element.body.children[targetIndex];
228
+ if ($targetBlock !== void 0) {
229
+ const $targetNode = _findEditableElement($targetBlock, "down");
230
+ if ($targetNode !== null) {
231
+ $targetNode.focus();
232
+ $targetNode.dispatchEvent(new Event("input"));
233
+ }
234
+ }
235
+ }
236
+ }
237
+ export async function _convertMarkdownToEditor(textDataList) {
238
+ const editorStore = useEditorStore();
239
+ const blockList = [];
240
+ const unorderListReg = new RegExp("^( +)?(\\+|\\*|-)(?= )( )");
241
+ const orderListReg = new RegExp("^( +)?(\\d+.)(?= )( )");
242
+ const codeBlockReg = new RegExp("^```");
243
+ let tempData = null;
244
+ let isCodeBlock = false;
245
+ textDataList.forEach(async (blockData, lineIndex) => {
246
+ switch (true) {
247
+ case new RegExp("^(---|___|\\*\\*\\*)").test(blockData):
248
+ blockList.push(_createDividerBlockData());
249
+ break;
250
+ case (codeBlockReg.test(blockData) || isCodeBlock === true):
251
+ if (isCodeBlock === false) {
252
+ const startLineText = blockData.split("```");
253
+ let codeBlockLang = "text";
254
+ isCodeBlock = true;
255
+ if (startLineText[1] in editorStore.codeBlockLnaguageList === true) {
256
+ codeBlockLang = startLineText[1];
257
+ }
258
+ tempData = {
259
+ id: _generateId(),
260
+ type: "code",
261
+ filename: "",
262
+ language: codeBlockLang,
263
+ textContent: ""
264
+ };
265
+ } else {
266
+ if (tempData !== null) {
267
+ if (codeBlockReg.test(blockData) !== true) {
268
+ if (tempData.type === "code") {
269
+ tempData.textContent += `${blockData}
270
+ `;
271
+ }
272
+ } else {
273
+ if (tempData.type === "code") {
274
+ tempData.textContent = tempData.textContent.trim();
275
+ blockList.push(tempData);
276
+ isCodeBlock = false;
277
+ tempData = null;
278
+ }
279
+ }
280
+ }
281
+ }
282
+ break;
283
+ case orderListReg.test(blockData):
284
+ const olSplitText = blockData.split(new RegExp("\\d+.(?= )"));
285
+ const olDepth = Math.floor(olSplitText[0].length / 4);
286
+ if (tempData === null) {
287
+ tempData = _createListBlockData("ol", [_createListBlockChildData(convertMarkdownTextToEditorText(olSplitText[1].trim()), olDepth)]);
288
+ } else {
289
+ if (tempData.type === "list") {
290
+ const nextLine = textDataList[lineIndex + 1];
291
+ tempData.child.push(_createListBlockChildData(convertMarkdownTextToEditorText(olSplitText[1].trim()), olDepth));
292
+ if (nextLine !== void 0) {
293
+ if (orderListReg.test(nextLine) === false) {
294
+ blockList.push(tempData);
295
+ tempData = null;
296
+ }
297
+ } else {
298
+ blockList.push(tempData);
299
+ tempData = null;
300
+ }
301
+ }
302
+ }
303
+ break;
304
+ case unorderListReg.test(blockData):
305
+ const ulSplitText = blockData.split(new RegExp("\\+|\\*|-"));
306
+ const ulDepth = Math.floor(ulSplitText[0].length / 4);
307
+ if (tempData === null) {
308
+ tempData = _createListBlockData("ul", [_createListBlockChildData(convertMarkdownTextToEditorText(ulSplitText[1].trim()), ulDepth)]);
309
+ } else {
310
+ if (tempData.type === "list") {
311
+ const nextLine = textDataList[lineIndex + 1];
312
+ tempData.child.push(_createListBlockChildData(convertMarkdownTextToEditorText(ulSplitText[1].trim()), ulDepth));
313
+ if (nextLine !== void 0) {
314
+ if (unorderListReg.test(nextLine) === false) {
315
+ blockList.push(tempData);
316
+ tempData = null;
317
+ }
318
+ } else {
319
+ blockList.push(tempData);
320
+ tempData = null;
321
+ }
322
+ }
323
+ }
324
+ break;
325
+ case new RegExp("^###(?= )").test(blockData):
326
+ blockList.push(_createHeadingBlockData(3, convertMarkdownTextToEditorText(blockData.substring(4).trim())));
327
+ break;
328
+ case new RegExp("^##(?= )").test(blockData):
329
+ blockList.push(_createHeadingBlockData(2, convertMarkdownTextToEditorText(blockData.substring(3).trim())));
330
+ break;
331
+ case new RegExp("^#(?= )").test(blockData):
332
+ blockList.push(_createHeadingBlockData(1, convertMarkdownTextToEditorText(blockData.substring(2).trim())));
333
+ break;
334
+ case new RegExp("^\\!\\[.*(?=\\))").test(blockData):
335
+ const caption = blockData.match(new RegExp("^\\!\\[(.*)(?=\\])\\]\\(([^ ]*)(\\)?)"))[1];
336
+ const src = blockData.match(new RegExp("^\\!\\[(.*)(?=\\])\\]\\(([^ ]*)(\\)?)"))[2];
337
+ if (caption !== void 0 && src !== void 0) {
338
+ blockList.push(_createImageBlockData(src.replace(")", ""), caption, false));
339
+ }
340
+ break;
341
+ default:
342
+ blockList.push(_createTextBlockData(convertMarkdownTextToEditorText(blockData)));
343
+ break;
344
+ }
345
+ });
346
+ return blockList;
347
+ }
348
+ function convertMarkdownTextToEditorText(text) {
349
+ const convertText = text.replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll(new RegExp("(`)([^`]+)(`)", "g"), `<span class="de-code">$2</span>`).replaceAll(new RegExp("(\\*\\*)([^\\*]+)(?=\\*\\*)(\\*\\*)", "g"), `<span class="de-bold">$2</span>`).replaceAll(new RegExp("(\\_\\_)([^\\_]+)(?=\\_\\_)(\\_\\_)", "g"), `<span class="de-bold">$2</span>`).replaceAll(new RegExp("(\\~\\~)([^\\~]+)(?=\\~\\~)(\\~\\~)", "g"), `<span class="de-strikethrough">$2</span>`).replaceAll(new RegExp("(\\*)([^\\*]+)(?=\\*)(\\*)", "g"), `<span class="de-italic">$2</span>`).replaceAll(new RegExp("(\\_)([^\\_]+)(?=\\_)(\\_)", "g"), `<span class="de-italic">$2</span>`).replaceAll(new RegExp("(\\[)([^\\[\\]]+)(\\])(?=\\()(\\()([^\\(\\)]+)(?=\\))(\\))", "g"), `<a class="de-link" href="$5" target="_blank">$2</a>`);
350
+ const $block = document.createElement("p");
351
+ $block.innerHTML = convertText;
352
+ const newNodes = [];
353
+ Array.from($block.childNodes).forEach((child) => __collectLeafNodes(child));
354
+ $block.innerHTML = "";
355
+ newNodes.forEach((node) => {
356
+ $block.appendChild(node);
357
+ });
358
+ return $block.innerHTML;
359
+ function __collectLeafNodes(node) {
360
+ if (node.nodeType === Node.TEXT_NODE) {
361
+ if (node.textContent === "") {
362
+ return;
363
+ }
364
+ let current = node.parentNode;
365
+ const classes = [];
366
+ let href = "";
367
+ let target = "";
368
+ while (current !== null && current !== $block) {
369
+ if (current.nodeType === Node.ELEMENT_NODE) {
370
+ const el = current;
371
+ el.classList.forEach((cls) => {
372
+ if (classes.includes(cls) === false) {
373
+ classes.push(cls);
374
+ }
375
+ });
376
+ if (el.tagName === "A") {
377
+ href = el.getAttribute("href") || "";
378
+ target = el.getAttribute("target") || "";
379
+ }
380
+ }
381
+ current = current.parentNode;
382
+ }
383
+ if (href !== "") {
384
+ const $a = document.createElement("a");
385
+ $a.setAttribute("href", href);
386
+ if (target !== "") {
387
+ $a.setAttribute("target", target);
388
+ }
389
+ classes.forEach((cls) => $a.classList.add(cls));
390
+ $a.textContent = node.textContent;
391
+ newNodes.push($a);
392
+ } else if (classes.length > 0) {
393
+ const $span = document.createElement("span");
394
+ classes.forEach((cls) => $span.classList.add(cls));
395
+ $span.textContent = node.textContent;
396
+ newNodes.push($span);
397
+ } else {
398
+ newNodes.push(document.createTextNode(node.textContent || ""));
399
+ }
400
+ } else {
401
+ const children = Array.from(node.childNodes);
402
+ children.forEach((child) => __collectLeafNodes(child));
403
+ }
404
+ }
405
+ }
406
+ export async function _moveBlockIndex(duration) {
407
+ const editorStore = useEditorStore();
408
+ if (editorStore.selectedBlockIndex !== -1 && editorStore.fn.updateEditorData !== null && editorStore.element.body !== null) {
409
+ const newData = JSON.parse(JSON.stringify(editorStore.data));
410
+ const curruntData = newData[editorStore.selectedBlockIndex];
411
+ if (curruntData !== void 0) {
412
+ switch (duration) {
413
+ case "first":
414
+ newData.splice(editorStore.selectedBlockIndex, 1);
415
+ newData.splice(0, 0, curruntData);
416
+ editorStore.selectedBlockIndex = 0;
417
+ break;
418
+ case "up":
419
+ newData.splice(editorStore.selectedBlockIndex, 1);
420
+ newData.splice(editorStore.selectedBlockIndex - 1, 0, curruntData);
421
+ editorStore.selectedBlockIndex = editorStore.selectedBlockIndex - 1;
422
+ break;
423
+ case "down":
424
+ newData.splice(editorStore.selectedBlockIndex, 1);
425
+ newData.splice(editorStore.selectedBlockIndex + 1, 0, curruntData);
426
+ editorStore.selectedBlockIndex = editorStore.selectedBlockIndex + 1;
427
+ break;
428
+ case "last":
429
+ newData.splice(editorStore.selectedBlockIndex, 1);
430
+ newData.push(curruntData);
431
+ editorStore.selectedBlockIndex = newData.length - 1;
432
+ break;
433
+ }
434
+ editorStore.fn.updateEditorData(newData);
435
+ await nextTick();
436
+ const $block = editorStore.element.body.children[editorStore.selectedBlockIndex];
437
+ if ($block !== void 0) {
438
+ const $editableElement = _findEditableElement($block, "down");
439
+ if ($editableElement !== null && curruntData.type !== "custom" && curruntData.type !== "divider") {
440
+ $editableElement.focus();
441
+ $editableElement.dispatchEvent(new Event("input"));
442
+ }
443
+ }
444
+ }
445
+ }
446
+ }
447
+ export function _checkCanUseIndent() {
448
+ const editorStore = useEditorStore();
449
+ let suitable = false;
450
+ if (editorStore.selectedBlockIndex > -1) {
451
+ const blockData = editorStore.data[editorStore.selectedBlockIndex];
452
+ if (blockData !== void 0) {
453
+ if (["text", "heading", "list"].includes(blockData.type) === true) {
454
+ suitable = true;
455
+ }
456
+ }
457
+ }
458
+ return suitable;
459
+ }
460
+ export async function _setIndentData(type) {
461
+ const editorStore = useEditorStore();
462
+ const newData = JSON.parse(JSON.stringify(editorStore.data));
463
+ const blockData = newData[editorStore.selectedBlockIndex];
464
+ if (blockData !== void 0 && editorStore.fn.updateEditorData !== null && editorStore.cursorSelection !== null && editorStore.element.body !== null) {
465
+ const $editableElement = _findEditableParent(editorStore.cursorSelection.anchorNode);
466
+ if ($editableElement !== null) {
467
+ const offset = _getEditorbleCursorPosition($editableElement);
468
+ if (blockData.type === "list") {
469
+ if (blockData.child.length > 1) {
470
+ const $block = _findParentBlock($editableElement);
471
+ let indentType = "plus";
472
+ if ($block !== null) {
473
+ const $childList = $block.querySelectorAll(".de-item-text");
474
+ let childIndex = -1;
475
+ for (let i = 0; i < $childList.length; i += 1) {
476
+ const $child = $childList[i];
477
+ if ($child === $editableElement) {
478
+ childIndex = i;
479
+ break;
480
+ }
481
+ }
482
+ const curruntChildData = blockData.child[childIndex];
483
+ if (curruntChildData !== void 0) {
484
+ if (type === "increase") {
485
+ const preChildData = blockData.child[childIndex - 1];
486
+ if (curruntChildData.depth === void 0) {
487
+ curruntChildData.depth = 1;
488
+ } else {
489
+ curruntChildData.depth += 1;
490
+ }
491
+ if (curruntChildData.depth > 5) {
492
+ curruntChildData.depth = 5;
493
+ }
494
+ if (preChildData !== void 0 && curruntChildData.depth > (preChildData.depth || 0)) {
495
+ curruntChildData.depth = (preChildData.depth || 0) + 1;
496
+ }
497
+ } else {
498
+ indentType = "minus";
499
+ if (curruntChildData.depth !== void 0) {
500
+ curruntChildData.depth -= 1;
501
+ if (curruntChildData.depth <= 0) {
502
+ delete curruntChildData.depth;
503
+ }
504
+ }
505
+ }
506
+ blockData.child[childIndex] = curruntChildData;
507
+ for (let i = 0; i < blockData.child.length; i += 1) {
508
+ const child = blockData.child[i];
509
+ if (i > childIndex && child !== void 0) {
510
+ if ((child.depth || 0) <= (curruntChildData.depth || 0) - 1 || (curruntChildData.depth || 0) === 0) {
511
+ break;
512
+ } else {
513
+ if (indentType === "plus") {
514
+ if (child.depth === void 0) {
515
+ child.depth = 1;
516
+ } else {
517
+ child.depth += 1;
518
+ }
519
+ if (child.depth > 5) {
520
+ child.depth = 5;
521
+ }
522
+ } else {
523
+ if (child.depth !== void 0) {
524
+ child.depth -= 1;
525
+ if (child.depth <= 0) {
526
+ delete child.depth;
527
+ }
528
+ }
529
+ }
530
+ }
531
+ }
532
+ }
533
+ editorStore.selectedBlockId = "";
534
+ newData[editorStore.selectedBlockIndex] = blockData;
535
+ editorStore.fn.updateEditorData(newData);
536
+ await nextTick();
537
+ const $parentBlock = editorStore.element.body.children[editorStore.selectedBlockIndex];
538
+ if ($parentBlock !== void 0) {
539
+ const $textArea = $parentBlock.querySelectorAll(".de-item-text");
540
+ const $targetTextArea = $textArea[childIndex];
541
+ if ($targetTextArea !== void 0) {
542
+ const $node = $targetTextArea.childNodes[offset.nodeIndex];
543
+ $targetTextArea.dispatchEvent(new Event("blur"));
544
+ if ($node !== void 0) {
545
+ _setCursorPosition($node, offset.offset);
546
+ } else {
547
+ _setCursorPosition($targetTextArea, 0);
548
+ }
549
+ }
550
+ }
551
+ }
552
+ }
553
+ }
554
+ } else {
555
+ if (type === "increase") {
556
+ if (blockData.depth === void 0) {
557
+ blockData.depth = 1;
558
+ } else {
559
+ blockData.depth += 1;
560
+ }
561
+ if (blockData.depth > 5) {
562
+ blockData.depth = 5;
563
+ }
564
+ } else {
565
+ if (blockData.depth !== void 0) {
566
+ blockData.depth -= 1;
567
+ if (blockData.depth <= 0) {
568
+ delete blockData.depth;
569
+ }
570
+ }
571
+ }
572
+ editorStore.selectedBlockId = "";
573
+ newData.splice(editorStore.selectedBlockIndex, 1, blockData);
574
+ editorStore.fn.updateEditorData(newData);
575
+ await nextTick();
576
+ const $block = editorStore.element.body.children[editorStore.selectedBlockIndex];
577
+ if ($block !== void 0) {
578
+ const $node = $block.childNodes[offset.nodeIndex];
579
+ if ($node !== void 0) {
580
+ $block.dispatchEvent(new Event("input"));
581
+ _setCursorPosition($node, offset.offset);
582
+ }
583
+ }
584
+ }
585
+ }
586
+ }
587
+ }
588
+ export function _checkCanUseAlign() {
589
+ const editorStore = useEditorStore();
590
+ let suitable = false;
591
+ if (editorStore.selectedBlockIndex > -1) {
592
+ const blockData = editorStore.data[editorStore.selectedBlockIndex];
593
+ if (blockData !== void 0) {
594
+ if (["text", "heading", "list", "image"].includes(blockData.type) === true) {
595
+ suitable = true;
596
+ }
597
+ }
598
+ }
599
+ return suitable;
600
+ }
601
+ export function _checkCanUseDecoration() {
602
+ const editorStore = useEditorStore();
603
+ let suitable = false;
604
+ if (editorStore.selectedBlockIndex > -1) {
605
+ const blockData = editorStore.data[editorStore.selectedBlockIndex];
606
+ if (blockData !== void 0) {
607
+ if (["text", "heading", "list"].includes(blockData.type) === true) {
608
+ suitable = true;
609
+ }
610
+ }
611
+ }
612
+ return suitable;
613
+ }
614
+ export function _checkDataIsEmpty(data) {
615
+ const editorStore = useEditorStore();
616
+ let suitable = true;
617
+ if (data === void 0) {
618
+ data = editorStore.data;
619
+ }
620
+ data.forEach((blockData) => {
621
+ switch (blockData.type) {
622
+ case "text":
623
+ if (blockData.textContent !== "") {
624
+ suitable = false;
625
+ }
626
+ break;
627
+ case "heading":
628
+ if (blockData.textContent !== "") {
629
+ suitable = false;
630
+ }
631
+ break;
632
+ case "image":
633
+ if (blockData.caption !== "") {
634
+ suitable = false;
635
+ }
636
+ break;
637
+ case "list":
638
+ blockData.child.forEach((child) => {
639
+ if (child.textContent !== "") {
640
+ suitable = false;
641
+ }
642
+ });
643
+ break;
644
+ case "code":
645
+ if (blockData.filename !== "") {
646
+ suitable = false;
647
+ }
648
+ if (blockData.textContent !== "") {
649
+ suitable = false;
650
+ }
651
+ break;
652
+ case "divider":
653
+ suitable = false;
654
+ break;
655
+ case "custom":
656
+ if (blockData.textContent !== "") {
657
+ suitable = false;
658
+ }
659
+ break;
660
+ }
661
+ });
662
+ return suitable;
663
+ }
@@ -0,0 +1,9 @@
1
+ import type { DELinePosition, DECurSorPosition, DECursorOffset } from "../../type.mjs.js";
2
+ export declare function _getMultilinePosition(element: HTMLElement): DELinePosition;
3
+ export declare function _getBeforeAndAfterHTMLOfCursor($target: HTMLElement): {
4
+ beforeHTML: string;
5
+ afterHTML: string;
6
+ };
7
+ export declare function _isCursorAtLineBoundary(): DECurSorPosition;
8
+ export declare function _getEditorbleEndPosition($element: HTMLElement): DECursorOffset;
9
+ export declare function _getEditorbleCursorPosition($element: HTMLElement): DECursorOffset;