vditor 3.9.1 → 3.9.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 -0
- package/dist/index.css +1 -1
- package/dist/index.min.js +1 -1
- package/dist/js/i18n/fr_FR.js +2 -2
- package/dist/method.min.js +1 -1
- package/dist/ts/constants.d.ts +1 -0
- package/dist/ts/wysiwyg/highlightToolbarWYSIWYG.d.ts +2 -2
- package/dist/types/index.d.ts +70 -18
- package/package.json +1 -1
- package/src/ts/constants.ts +1 -0
- package/src/ts/markdown/highlightRender.ts +72 -68
- package/src/ts/markdown/speechRender.ts +1 -1
- package/src/ts/util/fixBrowserBehavior.ts +4 -0
- package/src/ts/util/processCode.ts +0 -4
- package/src/ts/wysiwyg/highlightToolbarWYSIWYG.ts +53 -41
- package/src/ts/wysiwyg/processKeydown.ts +2 -2
- package/src/ts/wysiwyg/toolbarEvent.ts +2 -2
|
@@ -489,7 +489,12 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
489
489
|
event.preventDefault();
|
|
490
490
|
return;
|
|
491
491
|
}
|
|
492
|
-
removeBlockElement(vditor, event)
|
|
492
|
+
if (removeBlockElement(vditor, event)) {
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
if (focusToElement(event, range)) {
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
493
498
|
};
|
|
494
499
|
|
|
495
500
|
const input2Wrap = document.createElement("span");
|
|
@@ -517,7 +522,12 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
517
522
|
event.preventDefault();
|
|
518
523
|
return;
|
|
519
524
|
}
|
|
520
|
-
removeBlockElement(vditor, event)
|
|
525
|
+
if (removeBlockElement(vditor, event)) {
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
if (focusToElement(event, range)) {
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
521
531
|
};
|
|
522
532
|
|
|
523
533
|
genUp(range, tableElement, vditor);
|
|
@@ -541,7 +551,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
541
551
|
// link ref popover
|
|
542
552
|
const linkRefElement = hasClosestByAttribute(typeElement, "data-type", "link-ref");
|
|
543
553
|
if (linkRefElement) {
|
|
544
|
-
genLinkRefPopover(vditor, linkRefElement);
|
|
554
|
+
genLinkRefPopover(vditor, linkRefElement, range);
|
|
545
555
|
}
|
|
546
556
|
|
|
547
557
|
// footnote popover
|
|
@@ -569,19 +579,12 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
569
579
|
if (event.isComposing) {
|
|
570
580
|
return;
|
|
571
581
|
}
|
|
572
|
-
if (
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
event.key === "Enter"
|
|
577
|
-
) {
|
|
578
|
-
range.selectNodeContents(footnotesRefElement);
|
|
579
|
-
range.collapse(false);
|
|
580
|
-
setSelectionFocus(range);
|
|
581
|
-
event.preventDefault();
|
|
582
|
+
if (removeBlockElement(vditor, event)) {
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
if (focusToElement(event, range)) {
|
|
582
586
|
return;
|
|
583
587
|
}
|
|
584
|
-
removeBlockElement(vditor, event);
|
|
585
588
|
};
|
|
586
589
|
|
|
587
590
|
genClose(footnotesRefElement, vditor);
|
|
@@ -660,17 +663,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
660
663
|
return;
|
|
661
664
|
}
|
|
662
665
|
vditor.hint.select(event, vditor);
|
|
663
|
-
|
|
664
|
-
!isCtrl(event) &&
|
|
665
|
-
!event.shiftKey &&
|
|
666
|
-
event.key === "Enter"
|
|
667
|
-
) {
|
|
668
|
-
range.setStart(codeElement.firstChild, 0);
|
|
669
|
-
range.collapse(true);
|
|
670
|
-
setSelectionFocus(range);
|
|
671
|
-
event.preventDefault();
|
|
672
|
-
event.stopPropagation();
|
|
673
|
-
}
|
|
666
|
+
focusToElement(event, range);
|
|
674
667
|
};
|
|
675
668
|
language.onkeyup = (event: KeyboardEvent) => {
|
|
676
669
|
if (
|
|
@@ -720,19 +713,12 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
720
713
|
if (event.isComposing) {
|
|
721
714
|
return;
|
|
722
715
|
}
|
|
723
|
-
if (
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
event.key === "Enter"
|
|
728
|
-
) {
|
|
729
|
-
range.selectNodeContents(headingElement);
|
|
730
|
-
range.collapse(false);
|
|
731
|
-
setSelectionFocus(range);
|
|
732
|
-
event.preventDefault();
|
|
716
|
+
if (removeBlockElement(vditor, event)) {
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
if (focusToElement(event, range)) {
|
|
733
720
|
return;
|
|
734
721
|
}
|
|
735
|
-
removeBlockElement(vditor, event);
|
|
736
722
|
};
|
|
737
723
|
|
|
738
724
|
genUp(range, headingElement, vditor);
|
|
@@ -744,7 +730,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
744
730
|
|
|
745
731
|
// a popover
|
|
746
732
|
if (aElement) {
|
|
747
|
-
genAPopover(vditor, aElement);
|
|
733
|
+
genAPopover(vditor, aElement, range);
|
|
748
734
|
}
|
|
749
735
|
|
|
750
736
|
if (
|
|
@@ -802,9 +788,8 @@ const setPopoverPosition = (vditor: IVditor, element: HTMLElement) => {
|
|
|
802
788
|
vditor.wysiwyg.popover.setAttribute("data-top", (targetElement.offsetTop - 21).toString());
|
|
803
789
|
};
|
|
804
790
|
|
|
805
|
-
export const genLinkRefPopover = (vditor: IVditor, linkRefElement: HTMLElement) => {
|
|
791
|
+
export const genLinkRefPopover = (vditor: IVditor, linkRefElement: HTMLElement, range = getSelection().getRangeAt(0)) => {
|
|
806
792
|
vditor.wysiwyg.popover.innerHTML = "";
|
|
807
|
-
|
|
808
793
|
const updateLinkRef = () => {
|
|
809
794
|
if (input.value.trim() !== "") {
|
|
810
795
|
if (linkRefElement.tagName === "IMG") {
|
|
@@ -836,6 +821,9 @@ export const genLinkRefPopover = (vditor: IVditor, linkRefElement: HTMLElement)
|
|
|
836
821
|
if (removeBlockElement(vditor, event)) {
|
|
837
822
|
return;
|
|
838
823
|
}
|
|
824
|
+
if (focusToElement(event, range)) {
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
839
827
|
linkHotkey(vditor, linkRefElement, event, input1);
|
|
840
828
|
};
|
|
841
829
|
|
|
@@ -854,6 +842,9 @@ export const genLinkRefPopover = (vditor: IVditor, linkRefElement: HTMLElement)
|
|
|
854
842
|
if (removeBlockElement(vditor, event)) {
|
|
855
843
|
return;
|
|
856
844
|
}
|
|
845
|
+
if (focusToElement(event, range)) {
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
857
848
|
linkHotkey(vditor, linkRefElement, event, input);
|
|
858
849
|
};
|
|
859
850
|
|
|
@@ -932,7 +923,7 @@ const genClose = (element: HTMLElement, vditor: IVditor) => {
|
|
|
932
923
|
element.remove();
|
|
933
924
|
afterRenderEvent(vditor);
|
|
934
925
|
highlightToolbarWYSIWYG(vditor);
|
|
935
|
-
if (["H1", "H2", "H3", "H4", "H5"
|
|
926
|
+
if (["H1", "H2", "H3", "H4", "H5", "H6"].includes(element.tagName)) {
|
|
936
927
|
renderToc(vditor);
|
|
937
928
|
}
|
|
938
929
|
};
|
|
@@ -970,7 +961,7 @@ const linkHotkey = (
|
|
|
970
961
|
}
|
|
971
962
|
};
|
|
972
963
|
|
|
973
|
-
export const genAPopover = (vditor: IVditor, aElement: HTMLElement) => {
|
|
964
|
+
export const genAPopover = (vditor: IVditor, aElement: HTMLElement, range: Range) => {
|
|
974
965
|
vditor.wysiwyg.popover.innerHTML = "";
|
|
975
966
|
|
|
976
967
|
const updateA = () => {
|
|
@@ -1001,6 +992,9 @@ export const genAPopover = (vditor: IVditor, aElement: HTMLElement) => {
|
|
|
1001
992
|
if (removeBlockElement(vditor, event)) {
|
|
1002
993
|
return;
|
|
1003
994
|
}
|
|
995
|
+
if (focusToElement(event, range)) {
|
|
996
|
+
return;
|
|
997
|
+
}
|
|
1004
998
|
linkHotkey(vditor, aElement, event, input1);
|
|
1005
999
|
};
|
|
1006
1000
|
|
|
@@ -1019,6 +1013,9 @@ export const genAPopover = (vditor: IVditor, aElement: HTMLElement) => {
|
|
|
1019
1013
|
if (removeBlockElement(vditor, event)) {
|
|
1020
1014
|
return;
|
|
1021
1015
|
}
|
|
1016
|
+
if (focusToElement(event, range)) {
|
|
1017
|
+
return;
|
|
1018
|
+
}
|
|
1022
1019
|
linkHotkey(vditor, aElement, event, input2);
|
|
1023
1020
|
};
|
|
1024
1021
|
|
|
@@ -1038,6 +1035,9 @@ export const genAPopover = (vditor: IVditor, aElement: HTMLElement) => {
|
|
|
1038
1035
|
if (removeBlockElement(vditor, event)) {
|
|
1039
1036
|
return;
|
|
1040
1037
|
}
|
|
1038
|
+
if (focusToElement(event, range)) {
|
|
1039
|
+
return;
|
|
1040
|
+
}
|
|
1041
1041
|
linkHotkey(vditor, aElement, event, input);
|
|
1042
1042
|
};
|
|
1043
1043
|
|
|
@@ -1109,3 +1109,15 @@ export const genImagePopover = (event: Event, vditor: IVditor) => {
|
|
|
1109
1109
|
|
|
1110
1110
|
setPopoverPosition(vditor, imgElement);
|
|
1111
1111
|
};
|
|
1112
|
+
|
|
1113
|
+
|
|
1114
|
+
const focusToElement = (event: KeyboardEvent, range: Range) => {
|
|
1115
|
+
if ((!isCtrl(event) && !event.shiftKey && event.key === "Enter") || event.key === "Escape") {
|
|
1116
|
+
if (range) {
|
|
1117
|
+
setSelectionFocus(range);
|
|
1118
|
+
}
|
|
1119
|
+
event.preventDefault();
|
|
1120
|
+
event.stopPropagation();
|
|
1121
|
+
return true;
|
|
1122
|
+
}
|
|
1123
|
+
};
|
|
@@ -356,8 +356,8 @@ export const removeBlockElement = (vditor: IVditor, event: KeyboardEvent) => {
|
|
|
356
356
|
const itemElement: HTMLElement = vditor.wysiwyg.popover.querySelector('[data-type="remove"]');
|
|
357
357
|
if (itemElement) {
|
|
358
358
|
itemElement.click();
|
|
359
|
-
event.preventDefault();
|
|
360
|
-
return true;
|
|
361
359
|
}
|
|
360
|
+
event.preventDefault();
|
|
361
|
+
return true;
|
|
362
362
|
}
|
|
363
363
|
};
|
|
@@ -216,7 +216,7 @@ export const toolbarEvent = (vditor: IVditor, actionBtn: Element, event: Event)
|
|
|
216
216
|
range.insertNode(aElement);
|
|
217
217
|
range.setStart(aElement.firstChild, 1);
|
|
218
218
|
range.collapse(true);
|
|
219
|
-
genAPopover(vditor, aElement);
|
|
219
|
+
genAPopover(vditor, aElement, range);
|
|
220
220
|
const textInputElement = vditor.wysiwyg.popover.querySelector("input");
|
|
221
221
|
textInputElement.value = "";
|
|
222
222
|
textInputElement.focus();
|
|
@@ -228,7 +228,7 @@ export const toolbarEvent = (vditor: IVditor, actionBtn: Element, event: Event)
|
|
|
228
228
|
range.surroundContents(node);
|
|
229
229
|
range.insertNode(node);
|
|
230
230
|
setSelectionFocus(range);
|
|
231
|
-
genAPopover(vditor, node);
|
|
231
|
+
genAPopover(vditor, node, range);
|
|
232
232
|
const textInputElements = vditor.wysiwyg.popover.querySelectorAll("input");
|
|
233
233
|
textInputElements[0].value = node.innerText;
|
|
234
234
|
textInputElements[1].focus();
|