vue-devui 1.6.23 → 1.6.24

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.
@@ -3,19 +3,11 @@ import type { LineSide, CodeReviewProps } from '../code-review-types';
3
3
  export declare function useCodeReviewComment(reviewContentRef: Ref<HTMLElement>, props: CodeReviewProps, ctx: SetupContext): {
4
4
  commentLeft: Ref<number>;
5
5
  commentTop: Ref<number>;
6
- mouseEvent: {
7
- onMousemove: (e: MouseEvent) => void;
8
- onMouseleave: (e: MouseEvent) => void;
9
- } | {
10
- onMousemove?: undefined;
11
- onMouseleave?: undefined;
12
- };
6
+ mouseEvent: Record<string, (e: MouseEvent) => void>;
13
7
  updateCheckedLineClass: () => void;
14
8
  clearCheckedLines: () => void;
15
9
  onCommentMouseLeave: (e: MouseEvent) => void;
16
10
  onCommentIconClick: (e: Event) => void;
17
- onCommentKeyDown: () => void;
18
- unCommentKeyDown: () => void;
19
11
  insertComment: (lineNumber: number, lineSide: LineSide, commentDom: HTMLElement) => void;
20
12
  removeComment: (lineNumber: number, lineSide: LineSide) => void;
21
13
  };
@@ -0,0 +1,5 @@
1
+ import type { Ref } from 'vue';
2
+ import type { CodeReviewProps } from '../code-review-types';
3
+ export declare function useCodeReviewLineSelection(reviewContentRef: Ref<HTMLElement>, props: CodeReviewProps, mouseMoveCb: () => void, mouseupCb: () => void): {
4
+ onMousedown: (e: MouseEvent) => void;
5
+ };
@@ -18,3 +18,4 @@ export declare function addCommentToPageForSingleColumn(lineHost: HTMLElement, c
18
18
  export declare function addCommentToPageForDoubleColumn(lineHost: HTMLElement, commentDom: HTMLElement, lineSide: LineSide): void;
19
19
  export declare function findReferenceDomForSingleColumn(parentNode: HTMLElement, lineNumber: number, lineSide: LineSide): HTMLTableRowElement | undefined;
20
20
  export declare function findReferenceDomForDoubleColumn(parentNode: HTMLElement, lineNumber: number, lineSide: LineSide): HTMLTableRowElement | undefined;
21
+ export declare function findParentTrNode(node: HTMLElement | null): any;
package/vue-devui.es.js CHANGED
@@ -17514,6 +17514,15 @@ function findReferenceDomForDoubleColumn(parentNode, lineNumber, lineSide) {
17514
17514
  }
17515
17515
  }
17516
17516
  }
17517
+ function findParentTrNode(node) {
17518
+ if (!node) {
17519
+ return null;
17520
+ }
17521
+ if (node.tagName === "TR") {
17522
+ return node;
17523
+ }
17524
+ return findParentTrNode(node.parentElement);
17525
+ }
17517
17526
  function useCodeReviewExpand(reviewContentRef, props) {
17518
17527
  const { outputFormat, expandThreshold, expandLoader } = toRefs(props);
17519
17528
  const processSideBySide = () => {
@@ -17741,25 +17750,161 @@ function useCodeReviewFold(props, ctx2) {
17741
17750
  });
17742
17751
  return { isFold, toggleFold };
17743
17752
  }
17753
+ function useCodeReviewLineSelection(reviewContentRef, props, mouseMoveCb, mouseupCb) {
17754
+ const ns2 = useNamespace$1("code-review");
17755
+ let dragging = false;
17756
+ let startTrNode;
17757
+ let trNodes;
17758
+ let isClickedLeft;
17759
+ let shouldClear;
17760
+ let isMouseMoved;
17761
+ const onMousedown2 = (e) => {
17762
+ if (e.button === 0) {
17763
+ const composedPath = e.composedPath();
17764
+ const lineNumberBox = composedPath.find(
17765
+ (item) => {
17766
+ var _a, _b;
17767
+ return ((_a = item.classList) == null ? void 0 : _a.contains("comment-icon-hover")) || ((_b = item.classList) == null ? void 0 : _b.contains("comment-icon"));
17768
+ }
17769
+ );
17770
+ trNodes = Array.from(reviewContentRef.value.querySelectorAll("tr")).filter((item) => {
17771
+ var _a;
17772
+ return !((_a = item.classList) == null ? void 0 : _a.contains("expand-line"));
17773
+ });
17774
+ if (!lineNumberBox) {
17775
+ return;
17776
+ }
17777
+ const parentTrNode = findParentTrNode(e.target);
17778
+ if (parentTrNode && (parentTrNode == null ? void 0 : parentTrNode.classList.contains("expand-line"))) {
17779
+ return;
17780
+ }
17781
+ startTrNode = parentTrNode;
17782
+ if (props.outputFormat === "side-by-side") {
17783
+ isClickedLeft = composedPath.some((item) => {
17784
+ var _a;
17785
+ return (_a = item.classList) == null ? void 0 : _a.contains("d-code-left");
17786
+ });
17787
+ } else {
17788
+ isClickedLeft = void 0;
17789
+ }
17790
+ dragging = true;
17791
+ shouldClear = true;
17792
+ isMouseMoved = false;
17793
+ e.preventDefault();
17794
+ e.stopPropagation();
17795
+ document.addEventListener("mousemove", onMousemove);
17796
+ document.addEventListener("mouseup", onMouseup);
17797
+ }
17798
+ };
17799
+ function onMousemove(e) {
17800
+ if (!dragging) {
17801
+ return;
17802
+ }
17803
+ isMouseMoved = true;
17804
+ if (shouldClear) {
17805
+ clearCommentChecked();
17806
+ shouldClear = false;
17807
+ }
17808
+ const composedPath = e.composedPath();
17809
+ const inReviewContent = composedPath.some((item) => {
17810
+ var _a;
17811
+ return (_a = item.classList) == null ? void 0 : _a.contains(ns2.e("content"));
17812
+ });
17813
+ if (!inReviewContent) {
17814
+ return;
17815
+ }
17816
+ const endTrNode = findParentTrNode(e.target);
17817
+ if (!endTrNode) {
17818
+ return;
17819
+ }
17820
+ let startIndex = trNodes.indexOf(startTrNode);
17821
+ let endIndex = trNodes.indexOf(endTrNode);
17822
+ if (endIndex === -1) {
17823
+ return;
17824
+ }
17825
+ mouseMoveCb();
17826
+ if (startIndex > endIndex) {
17827
+ [startIndex, endIndex] = [endIndex, startIndex];
17828
+ }
17829
+ let position;
17830
+ if (isClickedLeft === void 0) {
17831
+ position = "all";
17832
+ } else if (isClickedLeft) {
17833
+ position = "left";
17834
+ } else {
17835
+ position = "right";
17836
+ }
17837
+ for (let i = 0; i < trNodes.length; i++) {
17838
+ if (i >= startIndex && i <= endIndex) {
17839
+ toggleCommentCheckedClass(trNodes[i], true, position);
17840
+ } else {
17841
+ toggleCommentCheckedClass(trNodes[i], false, position);
17842
+ }
17843
+ }
17844
+ }
17845
+ function onMouseup() {
17846
+ dragging = false;
17847
+ if (isMouseMoved) {
17848
+ mouseupCb();
17849
+ }
17850
+ document.removeEventListener("mouseup", onMouseup);
17851
+ document.removeEventListener("mousemove", onMousemove);
17852
+ }
17853
+ function clearCommentChecked() {
17854
+ for (let i = 0; i < trNodes.length; i++) {
17855
+ toggleCommentCheckedClass(trNodes[i], false, "all");
17856
+ }
17857
+ }
17858
+ function toggleCommentCheckedClass(trNode, isAddClass, position) {
17859
+ var _a;
17860
+ const tdNodes = Array.from(trNode.children);
17861
+ let toDoNodes;
17862
+ if (position === "all") {
17863
+ toDoNodes = tdNodes;
17864
+ } else if (position === "left") {
17865
+ toDoNodes = tdNodes.slice(0, 2);
17866
+ } else {
17867
+ toDoNodes = tdNodes.slice(2);
17868
+ }
17869
+ if ((position === "left" || position === "right") && isNaN(parseInt((_a = toDoNodes[0]) == null ? void 0 : _a.innerHTML))) {
17870
+ return;
17871
+ }
17872
+ toDoNodes.forEach((item) => {
17873
+ if (item.tagName === "TD") {
17874
+ if (isAddClass) {
17875
+ item.classList.add("comment-checked");
17876
+ } else {
17877
+ item.classList.remove("comment-checked");
17878
+ }
17879
+ }
17880
+ });
17881
+ }
17882
+ return { onMousedown: onMousedown2 };
17883
+ }
17744
17884
  function useCodeReviewComment(reviewContentRef, props, ctx2) {
17745
17885
  const { outputFormat, allowComment, allowChecked } = toRefs(props);
17746
17886
  const ns2 = useNamespace$1("code-review");
17887
+ const { onMousedown: onMousedown2 } = useCodeReviewLineSelection(reviewContentRef, props, updateLineNumbers, afterCheckLines);
17747
17888
  const commentLeft = ref(-100);
17748
17889
  const commentTop = ref(-100);
17749
17890
  let currentLeftLineNumber = -1;
17750
17891
  let currentRightLineNumber = -1;
17751
17892
  let lastLineNumberContainer;
17752
17893
  let checkedLineNumberContainer = [];
17753
- let isShift = false;
17754
17894
  let currentLeftLineNumbers = [];
17755
17895
  let currentRightLineNumbers = [];
17756
17896
  let checkedLineCodeString = {};
17757
- watch(() => outputFormat.value, () => {
17758
- checkedLineNumberContainer = [];
17759
- currentLeftLineNumbers = [];
17760
- currentRightLineNumbers = [];
17761
- checkedLineCodeString = [];
17762
- });
17897
+ let allTrNodes = [];
17898
+ let afterCheckLinesEmitData;
17899
+ watch(
17900
+ () => outputFormat.value,
17901
+ () => {
17902
+ checkedLineNumberContainer = [];
17903
+ currentLeftLineNumbers = [];
17904
+ currentRightLineNumbers = [];
17905
+ checkedLineCodeString = [];
17906
+ }
17907
+ );
17763
17908
  const resetLeftTop = () => {
17764
17909
  commentLeft.value = -100;
17765
17910
  commentTop.value = -100;
@@ -17842,30 +17987,7 @@ function useCodeReviewComment(reviewContentRef, props, ctx2) {
17842
17987
  resetLeftTop();
17843
17988
  }
17844
17989
  };
17845
- function commentKeyDown(e) {
17846
- switch (e.key) {
17847
- case "Shift":
17848
- isShift = true;
17849
- break;
17850
- }
17851
- }
17852
- function commentKeyUp(e) {
17853
- e.preventDefault();
17854
- switch (e.key) {
17855
- case "Shift":
17856
- isShift = false;
17857
- break;
17858
- }
17859
- }
17860
- const unCommentKeyDown = () => {
17861
- document.removeEventListener("keydown", commentKeyDown);
17862
- document.removeEventListener("keyup", commentKeyUp);
17863
- };
17864
- const onCommentKeyDown = () => {
17865
- document.addEventListener("keydown", commentKeyDown);
17866
- document.addEventListener("keyup", commentKeyUp);
17867
- };
17868
- const getLineNumbers = (currentNumber, currentNumbers, e) => {
17990
+ const getLineNumbers = (currentNumber, currentNumbers) => {
17869
17991
  if (currentNumber === -1) {
17870
17992
  return currentNumbers;
17871
17993
  }
@@ -17874,26 +17996,27 @@ function useCodeReviewComment(reviewContentRef, props, ctx2) {
17874
17996
  }
17875
17997
  const numbers = [...currentNumbers];
17876
17998
  let max = Math.max(...numbers);
17877
- const min = Math.min(...numbers);
17999
+ let min = Math.min(...numbers);
18000
+ if (currentNumber < min) {
18001
+ min = currentNumber;
18002
+ }
17878
18003
  if (currentNumber > max) {
17879
18004
  max = currentNumber;
17880
18005
  }
17881
18006
  return Array.from({ length: max - min + 1 }, (_, i) => i + min);
17882
18007
  };
17883
- const getCommonClassAndJudge = (side) => {
17884
- const lineClassName = side === "line-by-line" ? ".d2h-code-linenumber" : ".d2h-code-side-linenumber";
17885
- const linenumberDom = reviewContentRef.value.querySelectorAll(lineClassName);
18008
+ const getCommonClassAndJudge = () => {
17886
18009
  const checkedLine = [currentLeftLineNumbers, currentRightLineNumbers];
17887
18010
  return {
17888
- linenumberDom,
18011
+ linenumberDom: allTrNodes,
17889
18012
  checkedLine
17890
18013
  };
17891
18014
  };
17892
18015
  const addCommentCheckedClass = (Dom) => {
17893
18016
  !Dom.classList.contains("comment-checked") && Dom.classList.add("comment-checked");
17894
18017
  };
17895
- const addCommentClassSingle = (side) => {
17896
- const { linenumberDom, checkedLine } = getCommonClassAndJudge(side);
18018
+ function getSingleCheckedLineCode(shouldRenderClass) {
18019
+ const { linenumberDom, checkedLine } = getCommonClassAndJudge();
17897
18020
  const checkedCodeContent = [];
17898
18021
  for (let i = 0; i < linenumberDom.length; i++) {
17899
18022
  const lineNumberDomLeft = linenumberDom[i].children[0];
@@ -17903,25 +18026,29 @@ function useCodeReviewComment(reviewContentRef, props, ctx2) {
17903
18026
  const codeLineNumberRight = parseInt(lineNumberDomRight == null ? void 0 : lineNumberDomRight.innerText);
17904
18027
  if (checkedLine[0].includes(codeLineNumberLeft) || checkedLine[1].includes(codeLineNumberRight)) {
17905
18028
  checkedLineNumberContainer.push(linenumberDom[i]);
17906
- const codeNode = linenumberDom[i].nextSibling.nodeName === "#text" ? linenumberDom[i].nextSibling.nextSibling : linenumberDom[i].nextSibling;
18029
+ const codeNode = linenumberDom[i].nextElementSibling;
17907
18030
  checkedCodeContent.push(codeNode == null ? void 0 : codeNode.innerText);
17908
- addCommentCheckedClass(linenumberDom[i]);
17909
- addCommentCheckedClass(codeNode);
18031
+ if (shouldRenderClass) {
18032
+ addCommentCheckedClass(linenumberDom[i]);
18033
+ addCommentCheckedClass(codeNode);
18034
+ }
17910
18035
  }
17911
18036
  }
17912
18037
  }
17913
18038
  checkedLineCodeString = checkedCodeContent;
17914
- };
17915
- const addCommentClassDouble = (side) => {
18039
+ }
18040
+ function getDoubleCheckedLineCode(shouldRenderClass) {
17916
18041
  var _a;
17917
- const { linenumberDom, checkedLine } = getCommonClassAndJudge(side);
18042
+ const { linenumberDom, checkedLine } = getCommonClassAndJudge();
17918
18043
  const checkedCodeContentLeft = [];
17919
18044
  const checkedCodeContentRight = [];
17920
18045
  function checkedFunc(Dom) {
17921
18046
  checkedLineNumberContainer.push(Dom);
17922
- const codeNode = Dom.nextSibling.nodeName === "#text" ? Dom.nextSibling.nextSibling : Dom.nextSibling;
17923
- addCommentCheckedClass(Dom);
17924
- addCommentCheckedClass(codeNode);
18047
+ const codeNode = Dom.nextElementSibling;
18048
+ if (shouldRenderClass) {
18049
+ addCommentCheckedClass(Dom);
18050
+ addCommentCheckedClass(codeNode);
18051
+ }
17925
18052
  return codeNode == null ? void 0 : codeNode.innerText;
17926
18053
  }
17927
18054
  for (let i = 0; i < linenumberDom.length; i++) {
@@ -17937,38 +18064,53 @@ function useCodeReviewComment(reviewContentRef, props, ctx2) {
17937
18064
  }
17938
18065
  }
17939
18066
  checkedLineCodeString = { leftCode: checkedCodeContentLeft, rightCode: checkedCodeContentRight };
17940
- };
17941
- const updateCheckedLineClass = () => {
17942
- if (outputFormat.value === "line-by-line") {
17943
- addCommentClassSingle(outputFormat.value);
17944
- return;
18067
+ }
18068
+ function getCheckedLineCode(shouldRenderClass) {
18069
+ if (props.outputFormat === "line-by-line") {
18070
+ return getSingleCheckedLineCode(shouldRenderClass);
17945
18071
  }
17946
- addCommentClassDouble(outputFormat.value);
18072
+ getDoubleCheckedLineCode(shouldRenderClass);
18073
+ }
18074
+ function updateLineNumbers() {
18075
+ currentLeftLineNumbers = currentLeftLineNumber === -1 ? currentLeftLineNumbers : getLineNumbers(currentLeftLineNumber, currentLeftLineNumbers);
18076
+ currentRightLineNumbers = currentRightLineNumber === -1 ? currentRightLineNumbers : getLineNumbers(currentRightLineNumber, currentRightLineNumbers);
18077
+ getCheckedLineCode(false);
18078
+ afterCheckLinesEmitData = {
18079
+ left: currentLeftLineNumber,
18080
+ right: currentRightLineNumber,
18081
+ details: {
18082
+ lefts: currentLeftLineNumbers,
18083
+ rights: currentRightLineNumbers,
18084
+ codes: checkedLineCodeString
18085
+ }
18086
+ };
18087
+ }
18088
+ const updateCheckedLineClass = () => {
18089
+ getCheckedLineCode(true);
17947
18090
  };
17948
18091
  const resetCommentClass = () => {
17949
18092
  for (let i = 0; i < checkedLineNumberContainer.length; i++) {
17950
18093
  checkedLineNumberContainer[i].classList.remove("comment-checked");
17951
- const codeNode = checkedLineNumberContainer[i].nextSibling.nodeName === "#text" ? checkedLineNumberContainer[i].nextSibling.nextSibling : checkedLineNumberContainer[i].nextSibling;
18094
+ const codeNode = checkedLineNumberContainer[i].nextElementSibling;
17952
18095
  codeNode == null ? void 0 : codeNode.classList.remove("comment-checked");
17953
18096
  }
17954
18097
  checkedLineNumberContainer = [];
17955
18098
  };
17956
- const commentShiftClick = (e) => {
17957
- currentLeftLineNumbers = currentLeftLineNumber === -1 ? currentLeftLineNumbers : getLineNumbers(currentLeftLineNumber, currentLeftLineNumbers);
17958
- currentRightLineNumbers = currentRightLineNumber === -1 ? currentRightLineNumbers : getLineNumbers(currentRightLineNumber, currentRightLineNumbers);
17959
- updateCheckedLineClass();
17960
- };
17961
- const commentClick = (e) => {
18099
+ const commentClick = () => {
17962
18100
  let obj = { left: currentLeftLineNumber, right: currentRightLineNumber };
17963
- if (currentLeftLineNumbers.length >= 1 || currentRightLineNumbers.length >= 1 && allowChecked.value) {
18101
+ if ((currentLeftLineNumbers.length >= 1 || currentRightLineNumbers.length >= 1) && allowChecked.value) {
17964
18102
  const maxCurrentLeftLineNumber = currentLeftLineNumbers[currentLeftLineNumbers.length - 1];
17965
18103
  const maxCurrentRightLineNumber = currentRightLineNumbers[currentRightLineNumbers.length - 1];
17966
18104
  if (maxCurrentLeftLineNumber === currentLeftLineNumber || maxCurrentRightLineNumber === currentRightLineNumber) {
17967
- obj = { left: currentLeftLineNumber, right: currentRightLineNumber, details: {
17968
- lefts: currentLeftLineNumbers,
17969
- rights: currentRightLineNumbers,
17970
- codes: checkedLineCodeString
17971
- } };
18105
+ obj = {
18106
+ left: currentLeftLineNumber,
18107
+ right: currentRightLineNumber,
18108
+ details: {
18109
+ lefts: currentLeftLineNumbers,
18110
+ rights: currentRightLineNumbers,
18111
+ codes: checkedLineCodeString
18112
+ }
18113
+ };
17972
18114
  } else {
17973
18115
  currentLeftLineNumbers = [];
17974
18116
  currentRightLineNumbers = [];
@@ -17977,6 +18119,9 @@ function useCodeReviewComment(reviewContentRef, props, ctx2) {
17977
18119
  }
17978
18120
  ctx2.emit("addComment", obj);
17979
18121
  };
18122
+ function afterCheckLines() {
18123
+ ctx2.emit("afterCheckLines", afterCheckLinesEmitData);
18124
+ }
17980
18125
  const onCommentIconClick = (e) => {
17981
18126
  if (e) {
17982
18127
  const composedPath = e.composedPath();
@@ -17990,10 +18135,6 @@ function useCodeReviewComment(reviewContentRef, props, ctx2) {
17990
18135
  return;
17991
18136
  }
17992
18137
  }
17993
- if (isShift && allowChecked.value) {
17994
- commentShiftClick();
17995
- return;
17996
- }
17997
18138
  commentClick();
17998
18139
  };
17999
18140
  const insertComment = (lineNumber, lineSide, commentDom) => {
@@ -18040,7 +18181,19 @@ function useCodeReviewComment(reviewContentRef, props, ctx2) {
18040
18181
  checkedLineCodeString = [];
18041
18182
  resetCommentClass();
18042
18183
  };
18043
- const mouseEvent = allowComment.value ? { onMousemove: onMouseMove, onMouseleave } : {};
18184
+ const handleMouseDown = (e) => {
18185
+ const lineClassName = props.outputFormat === "line-by-line" ? ".d2h-code-linenumber" : ".d2h-code-side-linenumber";
18186
+ allTrNodes = reviewContentRef.value.querySelectorAll(lineClassName);
18187
+ onMousedown2(e);
18188
+ };
18189
+ const mouseEvent = {};
18190
+ if (allowComment.value) {
18191
+ mouseEvent.onMousemove = onMouseMove;
18192
+ mouseEvent.onMouseleave = onMouseleave;
18193
+ }
18194
+ if (props.allowChecked) {
18195
+ mouseEvent.onMousedown = handleMouseDown;
18196
+ }
18044
18197
  window.addEventListener("scroll", resetLeftTop);
18045
18198
  onUnmounted(() => {
18046
18199
  window.removeEventListener("scroll", resetLeftTop);
@@ -18053,8 +18206,6 @@ function useCodeReviewComment(reviewContentRef, props, ctx2) {
18053
18206
  clearCheckedLines,
18054
18207
  onCommentMouseLeave,
18055
18208
  onCommentIconClick,
18056
- onCommentKeyDown,
18057
- unCommentKeyDown,
18058
18209
  insertComment,
18059
18210
  removeComment
18060
18211
  };
@@ -18063,7 +18214,7 @@ var codeReview = "";
18063
18214
  var CodeReview = defineComponent({
18064
18215
  name: "DCodeReview",
18065
18216
  props: codeReviewProps,
18066
- emits: ["foldChange", "addComment", "afterViewInit", "contentRefresh"],
18217
+ emits: ["foldChange", "addComment", "afterViewInit", "contentRefresh", "afterCheckLines"],
18067
18218
  setup(props, ctx2) {
18068
18219
  const ns2 = useNamespace$1("code-review");
18069
18220
  const {
@@ -18085,8 +18236,6 @@ var CodeReview = defineComponent({
18085
18236
  mouseEvent,
18086
18237
  onCommentMouseLeave,
18087
18238
  onCommentIconClick,
18088
- onCommentKeyDown,
18089
- unCommentKeyDown,
18090
18239
  insertComment,
18091
18240
  removeComment,
18092
18241
  updateCheckedLineClass,
@@ -18100,10 +18249,6 @@ var CodeReview = defineComponent({
18100
18249
  updateCheckedLineClass,
18101
18250
  clearCheckedLines
18102
18251
  });
18103
- onCommentKeyDown();
18104
- });
18105
- onBeforeUnmount(() => {
18106
- unCommentKeyDown();
18107
18252
  });
18108
18253
  provide(CodeReviewInjectionKey, {
18109
18254
  diffType,
@@ -54140,7 +54285,7 @@ const installs = [
54140
54285
  VirtualListInstall
54141
54286
  ];
54142
54287
  var vueDevui = {
54143
- version: "1.6.23",
54288
+ version: "1.6.24",
54144
54289
  install(app) {
54145
54290
  installs.forEach((p) => app.use(p));
54146
54291
  }