dragon-editor 3.0.0 → 3.0.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.
- package/README.md +1 -1
- package/dist/module.json +1 -1
- package/dist/runtime/components/DragonEditor.vue +3 -2
- package/dist/runtime/components/DragonEditorViewer.vue +1 -1
- package/dist/runtime/type.d.ts +27 -0
- package/dist/runtime/utils/convertor.d.ts +1 -1
- package/dist/runtime/utils/keyboardEvent.mjs +154 -37
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/module.json
CHANGED
|
@@ -156,15 +156,16 @@ function setDecoration(type: string) {
|
|
|
156
156
|
_setNodeStyle(`de-${type}`, editorStore);
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
function getContentData() {
|
|
159
|
+
function getContentData(): DEContentData {
|
|
160
160
|
if (editorStore.$content !== null) {
|
|
161
161
|
return _getContentData(editorStore.$content);
|
|
162
162
|
} else {
|
|
163
163
|
console.error("[DragonEditor] Con't find content Element.");
|
|
164
|
+
return [];
|
|
164
165
|
}
|
|
165
166
|
}
|
|
166
167
|
|
|
167
|
-
function setContentData(data:
|
|
168
|
+
function setContentData(data: DEContentData) {
|
|
168
169
|
_setContentData(data, editorStore);
|
|
169
170
|
}
|
|
170
171
|
|
package/dist/runtime/type.d.ts
CHANGED
|
@@ -22,3 +22,30 @@ interface DEArrangeCursorData {
|
|
|
22
22
|
endNodeIdx: number;
|
|
23
23
|
endOffset: number;
|
|
24
24
|
}
|
|
25
|
+
|
|
26
|
+
interface DETextBlock {
|
|
27
|
+
type: "text";
|
|
28
|
+
textContent: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface DEHeadingBlock {
|
|
32
|
+
type: "heading";
|
|
33
|
+
level: number;
|
|
34
|
+
id: string;
|
|
35
|
+
textContent: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface DEUListBlock {
|
|
39
|
+
type: "ul";
|
|
40
|
+
child: string[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface DEOListBlock {
|
|
44
|
+
type: "ol";
|
|
45
|
+
pattern: "a" | "i" | "1" | "A" | "I";
|
|
46
|
+
child: string[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
type DEContent = DETextBlock | DEHeadingBlock | DEUListBlock | DEOListBlock;
|
|
50
|
+
|
|
51
|
+
type DEContentData = DEContent[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function _getContentData($content: HTMLDivElement):
|
|
1
|
+
export declare function _getContentData($content: HTMLDivElement): DEContentData;
|
|
2
2
|
export declare function _setContentData(data: any[], store: any): void;
|
|
@@ -82,10 +82,21 @@ function elementBackspaceEvent(e, store) {
|
|
|
82
82
|
case "heading":
|
|
83
83
|
defaultBlockBackspaceEvent(e, store, $element);
|
|
84
84
|
break;
|
|
85
|
+
case "list":
|
|
86
|
+
listBlockBackspaceEvent(e, store, $element);
|
|
87
|
+
break;
|
|
85
88
|
default:
|
|
86
89
|
console.log("// TODO : \uB2E4\uB978 \uD0C0\uC785 \uBE14\uB7ED \uBC31\uC2A4\uD398\uC774\uC2A4 \uC774\uBCA4\uD2B8", type);
|
|
87
90
|
}
|
|
88
91
|
}
|
|
92
|
+
function elementTabEvent(e, store) {
|
|
93
|
+
const { $element, type } = _getBlockType(e.target);
|
|
94
|
+
switch (type) {
|
|
95
|
+
case "text":
|
|
96
|
+
defaultTabEvent(e.shiftKey, $element);
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
89
100
|
function defaultBlockEnterEvent(store, $element) {
|
|
90
101
|
const $textBlock = $element;
|
|
91
102
|
if (store.cursorData.type === "Caret") {
|
|
@@ -579,21 +590,12 @@ function defaultBlockShiftEnterEvent(store, $element) {
|
|
|
579
590
|
_setCursor($textBlock.childNodes[startNodeIdx + 2], 0);
|
|
580
591
|
}
|
|
581
592
|
}
|
|
582
|
-
function elementTabEvent(e, store) {
|
|
583
|
-
const { $element, type } = _getBlockType(e.target);
|
|
584
|
-
switch (type) {
|
|
585
|
-
case "text":
|
|
586
|
-
defaultTabEvent(e.shiftKey, $element);
|
|
587
|
-
break;
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
593
|
function defaultBlockBackspaceEvent(e, store, $element) {
|
|
591
594
|
const $textBlock = $element;
|
|
592
|
-
const childList = store.
|
|
593
|
-
const childLength = childList.length;
|
|
595
|
+
const childList = store.$content.querySelectorAll(".de-block");
|
|
594
596
|
const $target = _getParentElementIfNodeIsText(store.cursorData.startNode, $textBlock);
|
|
595
597
|
let elementIdx = -1;
|
|
596
|
-
for (let i = 0;
|
|
598
|
+
for (let i = 0; childList.length > i; i += 1) {
|
|
597
599
|
if (childList[i] === $element) {
|
|
598
600
|
elementIdx = i;
|
|
599
601
|
break;
|
|
@@ -618,39 +620,35 @@ function defaultBlockBackspaceEvent(e, store, $element) {
|
|
|
618
620
|
if ($textBlock.hasChildNodes() === false) {
|
|
619
621
|
e.preventDefault();
|
|
620
622
|
const $preBlock = $textBlock.previousElementSibling;
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
if (
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
_setCursor($preBlock, 0);
|
|
631
|
-
}
|
|
623
|
+
const { type: preBlockType } = _getBlockType($preBlock);
|
|
624
|
+
$textBlock.remove();
|
|
625
|
+
if (preBlockType === "text" || preBlockType === "heading") {
|
|
626
|
+
if ($preBlock.hasChildNodes() === true) {
|
|
627
|
+
const textBlockChildList = $preBlock.childNodes;
|
|
628
|
+
const textBlockTargetChild = textBlockChildList[textBlockChildList.length - 1];
|
|
629
|
+
_setCursor(textBlockTargetChild, textBlockTargetChild.textContent.length);
|
|
630
|
+
} else {
|
|
631
|
+
_setCursor($preBlock, 0);
|
|
632
632
|
}
|
|
633
633
|
}
|
|
634
634
|
} else {
|
|
635
635
|
if (store.cursorData.startOffset === 0 && ($textBlock.childNodes[0] === store.cursorData.startNode || $textBlock.childNodes[0] === $target)) {
|
|
636
636
|
e.preventDefault();
|
|
637
637
|
const $preBlock = $textBlock.previousElementSibling;
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
if (
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
_setCursor($preBlock, 0);
|
|
651
|
-
}
|
|
652
|
-
$textBlock.remove();
|
|
638
|
+
const { type: preBlockType } = _getBlockType($preBlock);
|
|
639
|
+
if (preBlockType === "text" || preBlockType === "heading") {
|
|
640
|
+
if ($preBlock.hasChildNodes() === true) {
|
|
641
|
+
const textBlockChildList = $preBlock.childNodes;
|
|
642
|
+
const textBlockTargetChildIdx = textBlockChildList.length - 1;
|
|
643
|
+
const textBlockTargetCursorIdx = textBlockChildList[textBlockTargetChildIdx].textContent.length;
|
|
644
|
+
const thisBlockHTML = $textBlock.innerHTML;
|
|
645
|
+
$preBlock.innerHTML = $preBlock.innerHTML + thisBlockHTML;
|
|
646
|
+
_setCursor($preBlock.childNodes[textBlockTargetChildIdx], textBlockTargetCursorIdx);
|
|
647
|
+
} else {
|
|
648
|
+
$preBlock.innerHTML = $textBlock.innerHTML;
|
|
649
|
+
_setCursor($preBlock, 0);
|
|
653
650
|
}
|
|
651
|
+
$textBlock.remove();
|
|
654
652
|
}
|
|
655
653
|
}
|
|
656
654
|
}
|
|
@@ -675,6 +673,125 @@ function defaultBlockBackspaceEvent(e, store, $element) {
|
|
|
675
673
|
}
|
|
676
674
|
_setCursorData(store);
|
|
677
675
|
}
|
|
676
|
+
function listBlockBackspaceEvent(e, store, $element) {
|
|
677
|
+
const $listBlock = $element;
|
|
678
|
+
const $targetItem = _findContentEditableElement(store.cursorData.startNode);
|
|
679
|
+
const liList = $listBlock.querySelectorAll(".de-item");
|
|
680
|
+
const $target = _getParentElementIfNodeIsText(store.cursorData.startNode, $targetItem);
|
|
681
|
+
let liIdx = -1;
|
|
682
|
+
for (let i = 0; liList.length > i; i += 1) {
|
|
683
|
+
if (liList[i] === $targetItem) {
|
|
684
|
+
liIdx = i;
|
|
685
|
+
break;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
if (liList.length === 1) {
|
|
689
|
+
if ($targetItem.textContent === "") {
|
|
690
|
+
e.preventDefault();
|
|
691
|
+
const $preBlock = $listBlock.previousElementSibling;
|
|
692
|
+
const { type: preBlockType } = _getBlockType($preBlock);
|
|
693
|
+
$listBlock.remove();
|
|
694
|
+
if (preBlockType === "text" || preBlockType === "heading") {
|
|
695
|
+
if ($preBlock.hasChildNodes() === true) {
|
|
696
|
+
const textBlockChildList = $preBlock.childNodes;
|
|
697
|
+
const textBlockTargetChild = textBlockChildList[textBlockChildList.length - 1];
|
|
698
|
+
_setCursor(textBlockTargetChild, textBlockTargetChild.textContent.length);
|
|
699
|
+
} else {
|
|
700
|
+
_setCursor($preBlock, 0);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
} else {
|
|
704
|
+
if (store.cursorData.startOffset === 0 && ($targetItem.childNodes[0] === store.cursorData.startNode || $targetItem.childNodes[0] === $target)) {
|
|
705
|
+
e.preventDefault();
|
|
706
|
+
const $preBlock = $listBlock.previousElementSibling;
|
|
707
|
+
const { type: preBlockType } = _getBlockType($preBlock);
|
|
708
|
+
if (preBlockType === "text" || preBlockType === "heading") {
|
|
709
|
+
if ($preBlock.hasChildNodes() === true) {
|
|
710
|
+
const textBlockChildList = $preBlock.childNodes;
|
|
711
|
+
const textBlockTargetChildIdx = textBlockChildList.length - 1;
|
|
712
|
+
const textBlockTargetCursorIdx = textBlockChildList[textBlockTargetChildIdx].textContent.length;
|
|
713
|
+
const thisBlockHTML = $targetItem.innerHTML;
|
|
714
|
+
$preBlock.innerHTML = $preBlock.innerHTML + thisBlockHTML;
|
|
715
|
+
_setCursor($preBlock.childNodes[textBlockTargetChildIdx], textBlockTargetCursorIdx);
|
|
716
|
+
} else {
|
|
717
|
+
$preBlock.innerHTML = $targetItem.innerHTML;
|
|
718
|
+
_setCursor($preBlock, 0);
|
|
719
|
+
}
|
|
720
|
+
$targetItem.remove();
|
|
721
|
+
$listBlock.remove();
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
} else {
|
|
726
|
+
if (liIdx === 0) {
|
|
727
|
+
if ($targetItem.textContent === "") {
|
|
728
|
+
e.preventDefault();
|
|
729
|
+
const $preBlock = $listBlock.previousElementSibling;
|
|
730
|
+
const { type: preBlockType } = _getBlockType($preBlock);
|
|
731
|
+
$targetItem.remove();
|
|
732
|
+
if (preBlockType === "text" || preBlockType === "heading") {
|
|
733
|
+
if ($preBlock.hasChildNodes() === true) {
|
|
734
|
+
const textBlockChildList = $preBlock.childNodes;
|
|
735
|
+
const textBlockTargetChild = textBlockChildList[textBlockChildList.length - 1];
|
|
736
|
+
_setCursor(textBlockTargetChild, textBlockTargetChild.textContent.length);
|
|
737
|
+
} else {
|
|
738
|
+
_setCursor($preBlock, 0);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
} else {
|
|
742
|
+
if (store.cursorData.startOffset === 0 && ($targetItem.childNodes[0] === store.cursorData.startNode || $targetItem.childNodes[0] === $target)) {
|
|
743
|
+
e.preventDefault();
|
|
744
|
+
const $preBlock = $listBlock.previousElementSibling;
|
|
745
|
+
const { type: preBlockType } = _getBlockType($preBlock);
|
|
746
|
+
if (preBlockType === "text" || preBlockType === "heading") {
|
|
747
|
+
if ($preBlock.hasChildNodes() === true) {
|
|
748
|
+
const textBlockChildList = $preBlock.childNodes;
|
|
749
|
+
const textBlockTargetChildIdx = textBlockChildList.length - 1;
|
|
750
|
+
const textBlockTargetCursorIdx = textBlockChildList[textBlockTargetChildIdx].textContent.length;
|
|
751
|
+
const thisBlockHTML = $targetItem.innerHTML;
|
|
752
|
+
$preBlock.innerHTML = $preBlock.innerHTML + thisBlockHTML;
|
|
753
|
+
_setCursor($preBlock.childNodes[textBlockTargetChildIdx], textBlockTargetCursorIdx);
|
|
754
|
+
} else {
|
|
755
|
+
$preBlock.innerHTML = $targetItem.innerHTML;
|
|
756
|
+
_setCursor($preBlock, 0);
|
|
757
|
+
}
|
|
758
|
+
$targetItem.remove();
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
} else {
|
|
763
|
+
if ($targetItem.textContent === "") {
|
|
764
|
+
e.preventDefault();
|
|
765
|
+
const $preBlock = liList[liIdx - 1];
|
|
766
|
+
$targetItem.remove();
|
|
767
|
+
if ($preBlock.hasChildNodes() === true) {
|
|
768
|
+
const textBlockChildList = $preBlock.childNodes;
|
|
769
|
+
const textBlockTargetChild = textBlockChildList[textBlockChildList.length - 1];
|
|
770
|
+
_setCursor(textBlockTargetChild, textBlockTargetChild.textContent.length);
|
|
771
|
+
} else {
|
|
772
|
+
_setCursor($preBlock, 0);
|
|
773
|
+
}
|
|
774
|
+
} else {
|
|
775
|
+
if (store.cursorData.startOffset === 0 && ($targetItem.childNodes[0] === store.cursorData.startNode || $targetItem.childNodes[0] === $target)) {
|
|
776
|
+
e.preventDefault();
|
|
777
|
+
const $preBlock = liList[liIdx - 1];
|
|
778
|
+
if ($preBlock.hasChildNodes() === true) {
|
|
779
|
+
const textBlockChildList = $preBlock.childNodes;
|
|
780
|
+
const textBlockTargetChildIdx = textBlockChildList.length - 1;
|
|
781
|
+
const textBlockTargetCursorIdx = textBlockChildList[textBlockTargetChildIdx].textContent.length;
|
|
782
|
+
const thisBlockHTML = $targetItem.innerHTML;
|
|
783
|
+
$preBlock.innerHTML = $preBlock.innerHTML + thisBlockHTML;
|
|
784
|
+
_setCursor($preBlock.childNodes[textBlockTargetChildIdx], textBlockTargetCursorIdx);
|
|
785
|
+
} else {
|
|
786
|
+
$preBlock.innerHTML = $targetItem.innerHTML;
|
|
787
|
+
_setCursor($preBlock, 0);
|
|
788
|
+
}
|
|
789
|
+
$targetItem.remove();
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
}
|
|
678
795
|
function defaultTabEvent(useShiftKey, $element) {
|
|
679
796
|
const $target = $element;
|
|
680
797
|
let value = $target.dataset["depth"] === void 0 ? 0 : parseInt($target.dataset["depth"]);
|