@douyinfe/semi-json-viewer-core 2.72.0-beta.0 → 2.72.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.
- package/lib/index.js +111 -124
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -192,6 +192,22 @@ var SelectionModel = class {
|
|
|
192
192
|
row = lineElement.lineNumber || 1;
|
|
193
193
|
return { row, col: col + 1 };
|
|
194
194
|
}
|
|
195
|
+
savePreviousSelection() {
|
|
196
|
+
this.preStartRow = this.startRow;
|
|
197
|
+
this.preStartCol = this.startCol;
|
|
198
|
+
this.preEndRow = this.endRow;
|
|
199
|
+
this.preEndCol = this.endCol;
|
|
200
|
+
}
|
|
201
|
+
restorePreviousSelection() {
|
|
202
|
+
this.startRow = this.preStartRow;
|
|
203
|
+
this.startCol = this.preStartCol;
|
|
204
|
+
this.endRow = this.preEndRow;
|
|
205
|
+
this.endCol = this.preEndCol;
|
|
206
|
+
this._jsonModel.lastChangeBufferPos = {
|
|
207
|
+
lineNumber: this.startRow,
|
|
208
|
+
column: this.startCol
|
|
209
|
+
};
|
|
210
|
+
}
|
|
195
211
|
};
|
|
196
212
|
|
|
197
213
|
// src/worker/jsonWorkerManager.ts
|
|
@@ -644,6 +660,7 @@ function onEnter(beforeText, afterText, previousLineText) {
|
|
|
644
660
|
var EditWidget = class {
|
|
645
661
|
constructor(view, jsonModel, selectionModel, foldingModel, _jsonWorkerManager = getJsonWorkerManager()) {
|
|
646
662
|
this._jsonWorkerManager = _jsonWorkerManager;
|
|
663
|
+
this._isComposition = false;
|
|
647
664
|
this._autoClosingPairs = {
|
|
648
665
|
"{": "}",
|
|
649
666
|
"[": "]",
|
|
@@ -667,13 +684,17 @@ var EditWidget = class {
|
|
|
667
684
|
this._view.contentDom.addEventListener("beforeinput", (e) => {
|
|
668
685
|
this._handleBeforeInput(e);
|
|
669
686
|
});
|
|
687
|
+
this._view.contentDom.addEventListener("compositionstart", (e) => {
|
|
688
|
+
this._handleCompositionStart(e);
|
|
689
|
+
});
|
|
690
|
+
this._view.contentDom.addEventListener("compositionend", (e) => {
|
|
691
|
+
this._handleCompositionEnd(e);
|
|
692
|
+
});
|
|
670
693
|
this._view.contentDom.addEventListener("keydown", (e) => {
|
|
671
694
|
this._handleKeyDown(e);
|
|
672
695
|
});
|
|
673
696
|
}
|
|
674
|
-
|
|
675
|
-
e.preventDefault();
|
|
676
|
-
this._selectionModel.updateFromSelection();
|
|
697
|
+
buildBaseOperation(type = "insert") {
|
|
677
698
|
const startRow = this._selectionModel.startRow;
|
|
678
699
|
const startCol = this._selectionModel.startCol;
|
|
679
700
|
const endRow = this._selectionModel.endRow;
|
|
@@ -681,7 +702,7 @@ var EditWidget = class {
|
|
|
681
702
|
const startOffset = this._jsonModel.getOffsetAt(startRow, startCol);
|
|
682
703
|
const endOffset = this._jsonModel.getOffsetAt(endRow, endCol);
|
|
683
704
|
const op = {
|
|
684
|
-
type
|
|
705
|
+
type,
|
|
685
706
|
range: {
|
|
686
707
|
startLineNumber: startRow,
|
|
687
708
|
startColumn: startCol,
|
|
@@ -690,9 +711,47 @@ var EditWidget = class {
|
|
|
690
711
|
},
|
|
691
712
|
rangeOffset: startOffset,
|
|
692
713
|
rangeLength: endOffset - startOffset,
|
|
693
|
-
oldText:
|
|
714
|
+
oldText: this._jsonModel.getValueInRange({
|
|
715
|
+
startLineNumber: startRow,
|
|
716
|
+
startColumn: startCol,
|
|
717
|
+
endLineNumber: endRow,
|
|
718
|
+
endColumn: endCol
|
|
719
|
+
}),
|
|
694
720
|
newText: ""
|
|
695
721
|
};
|
|
722
|
+
if (this._selectionModel.isSelectedAll) {
|
|
723
|
+
op.range = {
|
|
724
|
+
startLineNumber: 1,
|
|
725
|
+
startColumn: 1,
|
|
726
|
+
endLineNumber: this._jsonModel.getLineCount(),
|
|
727
|
+
endColumn: this._jsonModel.getLineLength(this._jsonModel.getLineCount()) + 1
|
|
728
|
+
};
|
|
729
|
+
op.rangeOffset = 0;
|
|
730
|
+
op.rangeLength = this._jsonModel.getValue().length;
|
|
731
|
+
op.oldText = this._jsonModel.getValue();
|
|
732
|
+
}
|
|
733
|
+
return op;
|
|
734
|
+
}
|
|
735
|
+
_handleCompositionStart(e) {
|
|
736
|
+
e.preventDefault();
|
|
737
|
+
this._isComposition = true;
|
|
738
|
+
this._selectionModel.savePreviousSelection();
|
|
739
|
+
}
|
|
740
|
+
_handleCompositionEnd(e) {
|
|
741
|
+
e.preventDefault();
|
|
742
|
+
this._isComposition = false;
|
|
743
|
+
this._selectionModel.restorePreviousSelection();
|
|
744
|
+
const op = this.buildBaseOperation("replace");
|
|
745
|
+
op.newText = e.data || "";
|
|
746
|
+
this._selectionModel.isSelectedAll = false;
|
|
747
|
+
this._jsonModel.applyOperation(op);
|
|
748
|
+
}
|
|
749
|
+
_handleBeforeInput(e) {
|
|
750
|
+
if (this._isComposition) return;
|
|
751
|
+
e.preventDefault();
|
|
752
|
+
this._selectionModel.updateFromSelection();
|
|
753
|
+
const op = this.buildBaseOperation();
|
|
754
|
+
const { startLineNumber, startColumn, endLineNumber, endColumn } = op.range;
|
|
696
755
|
switch (e.inputType) {
|
|
697
756
|
case "insertText":
|
|
698
757
|
if (this._selectionModel.isCollapsed) {
|
|
@@ -701,37 +760,31 @@ var EditWidget = class {
|
|
|
701
760
|
op.type = "replace";
|
|
702
761
|
}
|
|
703
762
|
op.newText = e.data || "";
|
|
704
|
-
op.oldText = this._jsonModel.getValueInRange({
|
|
705
|
-
startLineNumber: startRow,
|
|
706
|
-
startColumn: startCol,
|
|
707
|
-
endLineNumber: endRow,
|
|
708
|
-
endColumn: endCol
|
|
709
|
-
});
|
|
710
763
|
if (this._autoClosingPairs[op.newText]) {
|
|
711
764
|
op.newText += this._autoClosingPairs[op.newText];
|
|
712
765
|
op.keepPosition = {
|
|
713
|
-
lineNumber:
|
|
714
|
-
column:
|
|
766
|
+
lineNumber: startLineNumber,
|
|
767
|
+
column: startColumn + 1
|
|
715
768
|
};
|
|
716
769
|
}
|
|
717
770
|
break;
|
|
718
771
|
case "insertParagraph":
|
|
719
772
|
op.newText = "\n";
|
|
720
773
|
op.keepPosition = {
|
|
721
|
-
lineNumber:
|
|
774
|
+
lineNumber: startLineNumber + 1,
|
|
722
775
|
column: 1
|
|
723
776
|
};
|
|
724
777
|
const enterAction = processJsonEnterAction(this._jsonModel, {
|
|
725
|
-
startLineNumber
|
|
726
|
-
startColumn
|
|
727
|
-
endLineNumber
|
|
728
|
-
endColumn
|
|
778
|
+
startLineNumber,
|
|
779
|
+
startColumn,
|
|
780
|
+
endLineNumber,
|
|
781
|
+
endColumn
|
|
729
782
|
});
|
|
730
783
|
if (enterAction) {
|
|
731
784
|
if (enterAction.indentAction === 1 /* Indent */) {
|
|
732
785
|
op.newText = "\n" + this.normalizeIndentation(enterAction.appendText + enterAction.indentation) || "";
|
|
733
786
|
op.keepPosition = {
|
|
734
|
-
lineNumber:
|
|
787
|
+
lineNumber: startLineNumber + 1,
|
|
735
788
|
column: enterAction.appendText.length + enterAction.indentation.length + 1
|
|
736
789
|
};
|
|
737
790
|
} else {
|
|
@@ -739,65 +792,39 @@ var EditWidget = class {
|
|
|
739
792
|
const increasedIndent = this.normalizeIndentation(enterAction.indentation + enterAction.appendText);
|
|
740
793
|
op.newText = "\n" + increasedIndent + "\n" + normalIndent;
|
|
741
794
|
op.keepPosition = {
|
|
742
|
-
lineNumber:
|
|
795
|
+
lineNumber: startLineNumber + 1,
|
|
743
796
|
column: increasedIndent.length + 1
|
|
744
797
|
};
|
|
745
798
|
}
|
|
746
799
|
} else {
|
|
747
|
-
const lineText = this._jsonModel.getLineContent(
|
|
748
|
-
const indentation = getLeadingWhitespace(lineText).substring(0,
|
|
800
|
+
const lineText = this._jsonModel.getLineContent(startLineNumber);
|
|
801
|
+
const indentation = getLeadingWhitespace(lineText).substring(0, startColumn - 1);
|
|
749
802
|
op.newText = "\n" + this.normalizeIndentation(indentation) || "";
|
|
750
803
|
op.keepPosition = {
|
|
751
|
-
lineNumber:
|
|
804
|
+
lineNumber: startLineNumber + 1,
|
|
752
805
|
column: indentation.length + 1
|
|
753
806
|
};
|
|
754
807
|
}
|
|
755
808
|
break;
|
|
756
809
|
case "deleteContentBackward":
|
|
757
|
-
let oldText = "";
|
|
758
810
|
if (this._selectionModel.isCollapsed) {
|
|
759
|
-
op.rangeOffset
|
|
760
|
-
oldText = this._jsonModel.getValueInRange({
|
|
761
|
-
startLineNumber
|
|
762
|
-
startColumn:
|
|
763
|
-
endLineNumber
|
|
764
|
-
endColumn
|
|
765
|
-
});
|
|
766
|
-
} else {
|
|
767
|
-
oldText = this._jsonModel.getValueInRange({
|
|
768
|
-
startLineNumber: startRow,
|
|
769
|
-
startColumn: startCol,
|
|
770
|
-
endLineNumber: endRow,
|
|
771
|
-
endColumn: endCol
|
|
811
|
+
op.rangeOffset -= 1;
|
|
812
|
+
op.oldText = this._jsonModel.getValueInRange({
|
|
813
|
+
startLineNumber,
|
|
814
|
+
startColumn: startColumn - 1,
|
|
815
|
+
endLineNumber,
|
|
816
|
+
endColumn
|
|
772
817
|
});
|
|
773
818
|
}
|
|
774
|
-
op.oldText = oldText;
|
|
775
819
|
op.type = "delete";
|
|
776
|
-
op.rangeLength = oldText.length;
|
|
820
|
+
op.rangeLength = op.oldText.length;
|
|
777
821
|
break;
|
|
778
822
|
case "insertFromPaste":
|
|
779
823
|
const pasteData = e.dataTransfer?.getData("text/plain");
|
|
780
824
|
op.type = "replace";
|
|
781
825
|
op.newText = pasteData || "";
|
|
782
|
-
op.oldText = this._jsonModel.getValueInRange({
|
|
783
|
-
startLineNumber: startRow,
|
|
784
|
-
startColumn: startCol,
|
|
785
|
-
endLineNumber: endRow,
|
|
786
|
-
endColumn: endCol
|
|
787
|
-
});
|
|
788
826
|
break;
|
|
789
827
|
}
|
|
790
|
-
if (this._selectionModel.isSelectedAll) {
|
|
791
|
-
op.range = {
|
|
792
|
-
startLineNumber: 1,
|
|
793
|
-
startColumn: 1,
|
|
794
|
-
endLineNumber: this._jsonModel.getLineCount(),
|
|
795
|
-
endColumn: this._jsonModel.getLineLength(this._jsonModel.getLineCount())
|
|
796
|
-
};
|
|
797
|
-
op.rangeOffset = 0;
|
|
798
|
-
op.rangeLength = this._jsonModel.getValue().length;
|
|
799
|
-
op.oldText = this._jsonModel.getValue();
|
|
800
|
-
}
|
|
801
828
|
this._selectionModel.isSelectedAll = false;
|
|
802
829
|
this._jsonModel.applyOperation(op);
|
|
803
830
|
}
|
|
@@ -867,6 +894,7 @@ var EditWidget = class {
|
|
|
867
894
|
const endCol = this._selectionModel.endCol;
|
|
868
895
|
const startOffset = this._jsonModel.getOffsetAt(startRow, startCol);
|
|
869
896
|
const endOffset = this._jsonModel.getOffsetAt(endRow, endCol);
|
|
897
|
+
const op = this.buildBaseOperation();
|
|
870
898
|
switch (e.key) {
|
|
871
899
|
case "Tab":
|
|
872
900
|
if (this._view.completeWidget.isVisible) {
|
|
@@ -884,19 +912,7 @@ var EditWidget = class {
|
|
|
884
912
|
} else {
|
|
885
913
|
insertText = " ";
|
|
886
914
|
}
|
|
887
|
-
|
|
888
|
-
type: "insert",
|
|
889
|
-
range: {
|
|
890
|
-
startLineNumber: startRow,
|
|
891
|
-
startColumn: startCol,
|
|
892
|
-
endLineNumber: endRow,
|
|
893
|
-
endColumn: endCol
|
|
894
|
-
},
|
|
895
|
-
rangeOffset: startOffset,
|
|
896
|
-
rangeLength: endOffset - startOffset,
|
|
897
|
-
oldText: "",
|
|
898
|
-
newText: insertText
|
|
899
|
-
};
|
|
915
|
+
op.newText = insertText;
|
|
900
916
|
this._jsonModel.applyOperation(op);
|
|
901
917
|
break;
|
|
902
918
|
case "f":
|
|
@@ -947,61 +963,22 @@ var EditWidget = class {
|
|
|
947
963
|
}
|
|
948
964
|
}
|
|
949
965
|
_cutHandler() {
|
|
950
|
-
const
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
const op = {
|
|
957
|
-
type: "replace",
|
|
958
|
-
range: {
|
|
959
|
-
startLineNumber: startRow,
|
|
960
|
-
startColumn: startCol,
|
|
961
|
-
endLineNumber: endRow,
|
|
962
|
-
endColumn: endCol
|
|
963
|
-
},
|
|
964
|
-
rangeOffset: 0,
|
|
965
|
-
rangeLength: 0,
|
|
966
|
-
oldText: "",
|
|
967
|
-
newText: ""
|
|
968
|
-
};
|
|
969
|
-
if (!this._selectionModel.isCollapsed) {
|
|
970
|
-
oldText = this._jsonModel.getValueInRange({
|
|
971
|
-
startLineNumber: startRow,
|
|
972
|
-
startColumn: startCol,
|
|
973
|
-
endLineNumber: endRow,
|
|
974
|
-
endColumn: endCol
|
|
975
|
-
});
|
|
976
|
-
startOffset = this._jsonModel.getOffsetAt(startRow, startCol);
|
|
977
|
-
} else {
|
|
978
|
-
oldText = this._jsonModel.getValueInRange({
|
|
979
|
-
startLineNumber: startRow,
|
|
966
|
+
const op = this.buildBaseOperation("replace");
|
|
967
|
+
if (this._selectionModel.isCollapsed) {
|
|
968
|
+
const { startLineNumber, endLineNumber } = op.range;
|
|
969
|
+
op.rangeOffset = this._jsonModel.getOffsetAt(startLineNumber, 1);
|
|
970
|
+
op.oldText = this._jsonModel.getValueInRange({
|
|
971
|
+
startLineNumber,
|
|
980
972
|
startColumn: 1,
|
|
981
|
-
endLineNumber
|
|
982
|
-
endColumn: this._jsonModel.getLineLength(
|
|
973
|
+
endLineNumber,
|
|
974
|
+
endColumn: this._jsonModel.getLineLength(endLineNumber) + 1
|
|
983
975
|
});
|
|
984
976
|
op.range = {
|
|
985
|
-
startLineNumber
|
|
986
|
-
startColumn: 1,
|
|
987
|
-
endLineNumber: endRow,
|
|
988
|
-
endColumn: this._jsonModel.getLineLength(endRow) + 1
|
|
989
|
-
};
|
|
990
|
-
startOffset = this._jsonModel.getOffsetAt(startRow, 1);
|
|
991
|
-
}
|
|
992
|
-
op.oldText = oldText;
|
|
993
|
-
op.rangeOffset = startOffset;
|
|
994
|
-
op.rangeLength = oldText.length;
|
|
995
|
-
if (this._selectionModel.isSelectedAll) {
|
|
996
|
-
op.range = {
|
|
997
|
-
startLineNumber: 1,
|
|
977
|
+
startLineNumber,
|
|
998
978
|
startColumn: 1,
|
|
999
|
-
endLineNumber
|
|
1000
|
-
endColumn: this._jsonModel.getLineLength(
|
|
979
|
+
endLineNumber,
|
|
980
|
+
endColumn: this._jsonModel.getLineLength(endLineNumber) + 1
|
|
1001
981
|
};
|
|
1002
|
-
op.rangeOffset = 0;
|
|
1003
|
-
op.rangeLength = this._jsonModel.getValue().length;
|
|
1004
|
-
op.oldText = this._jsonModel.getValue();
|
|
1005
982
|
}
|
|
1006
983
|
navigator.clipboard.writeText(op.oldText);
|
|
1007
984
|
this._jsonModel.applyOperation(op);
|
|
@@ -1011,6 +988,7 @@ var EditWidget = class {
|
|
|
1011
988
|
// src/view/fold/foldWidget.ts
|
|
1012
989
|
var FoldWidget = class {
|
|
1013
990
|
constructor(view, foldingModel) {
|
|
991
|
+
this._isMouseOver = false;
|
|
1014
992
|
this._view = view;
|
|
1015
993
|
this._foldingModel = foldingModel;
|
|
1016
994
|
this._attachEventListeners();
|
|
@@ -1025,11 +1003,14 @@ var FoldWidget = class {
|
|
|
1025
1003
|
}
|
|
1026
1004
|
_handleLineNumberHover(e) {
|
|
1027
1005
|
this._showFoldingIcon();
|
|
1006
|
+
this._isMouseOver = true;
|
|
1028
1007
|
}
|
|
1029
1008
|
_handleLineNumberContainerLeave() {
|
|
1030
1009
|
this.removeAllFoldingIcons();
|
|
1010
|
+
this._isMouseOver = false;
|
|
1031
1011
|
}
|
|
1032
1012
|
_showFoldingIcon() {
|
|
1013
|
+
if (this._isMouseOver) return;
|
|
1033
1014
|
const lineNumberElement = this._view.lineScrollDom.children;
|
|
1034
1015
|
for (let i = 0; i < lineNumberElement.length; i++) {
|
|
1035
1016
|
const element = lineNumberElement[i];
|
|
@@ -1079,6 +1060,7 @@ var FoldWidget = class {
|
|
|
1079
1060
|
this._foldingModel.toggleFoldingRange(lineNumber);
|
|
1080
1061
|
this._view.scalingCellSizeAndPositionManager.resetCell(0);
|
|
1081
1062
|
this._view.layout();
|
|
1063
|
+
this._isMouseOver = false;
|
|
1082
1064
|
});
|
|
1083
1065
|
return foldingIcon;
|
|
1084
1066
|
}
|
|
@@ -3188,6 +3170,7 @@ var CompleteWidget = class {
|
|
|
3188
3170
|
).join("");
|
|
3189
3171
|
}
|
|
3190
3172
|
hide() {
|
|
3173
|
+
if (!this.isVisible) return;
|
|
3191
3174
|
this.isVisible = false;
|
|
3192
3175
|
this._container.style.display = "none";
|
|
3193
3176
|
this._suggestions = [];
|
|
@@ -3362,19 +3345,23 @@ var View = class {
|
|
|
3362
3345
|
});
|
|
3363
3346
|
this._contentDom.addEventListener("click", (e) => {
|
|
3364
3347
|
e.preventDefault();
|
|
3348
|
+
this._completeWidget.hide();
|
|
3365
3349
|
this._selectionModel.isSelectedAll = false;
|
|
3366
3350
|
this._selectionModel.updateFromSelection();
|
|
3367
3351
|
});
|
|
3368
3352
|
this.emitter.on("contentChanged", () => {
|
|
3369
3353
|
this.resetScalingManagerConfigAndCell(0);
|
|
3354
|
+
if (this._jsonModel.lastChangeBufferPos.lineNumber >= this.visibleLineCount + this.startLineNumber) {
|
|
3355
|
+
this.scrollToLine(
|
|
3356
|
+
this._jsonModel.lastChangeBufferPos.lineNumber - this.visibleLineCount + 1
|
|
3357
|
+
);
|
|
3358
|
+
return;
|
|
3359
|
+
}
|
|
3370
3360
|
this.layout();
|
|
3371
3361
|
});
|
|
3372
3362
|
}
|
|
3373
3363
|
getLineElement(lineNumber) {
|
|
3374
|
-
|
|
3375
|
-
if (visibleLineNumber > this.visibleLineCount + this.startLineNumber || visibleLineNumber < this.startLineNumber)
|
|
3376
|
-
return null;
|
|
3377
|
-
return this._scrollDom.children[visibleLineNumber - this._foldingModel.getVisibleLineNumber(this.startLineNumber)];
|
|
3364
|
+
return this.scrollDom.querySelector(`[data-line-number="${lineNumber}"]`);
|
|
3378
3365
|
}
|
|
3379
3366
|
updateVisibleRange(start, end) {
|
|
3380
3367
|
this.startLineNumber = start;
|
|
@@ -3468,7 +3455,7 @@ var View = class {
|
|
|
3468
3455
|
const scrollEl = elt("div", "lines-content");
|
|
3469
3456
|
setStyles(scrollEl, {
|
|
3470
3457
|
position: "relative",
|
|
3471
|
-
overflow: "
|
|
3458
|
+
overflow: "hidden",
|
|
3472
3459
|
top: "0",
|
|
3473
3460
|
left: "0",
|
|
3474
3461
|
tabSize: (this._options?.formatOptions?.tabSize || 4).toString(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@douyinfe/semi-json-viewer-core",
|
|
3
|
-
"version": "2.72.0
|
|
3
|
+
"version": "2.72.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
],
|
|
54
54
|
"author": "",
|
|
55
55
|
"license": "MIT",
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "66267e4192e4ef74683aaf53e4e721908b1cea0d"
|
|
57
57
|
}
|