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.
@@ -1,4 +1,4 @@
1
- import { watch, onUnmounted, defineComponent, toRefs, createVNode, Transition, mergeProps, ref, computed, nextTick, unref, withModifiers, Comment, Text, Fragment, h, inject, withDirectives, cloneVNode, onMounted, provide, Teleport, createTextVNode, onBeforeUnmount, vShow } from "vue";
1
+ import { watch, onUnmounted, defineComponent, toRefs, createVNode, Transition, mergeProps, ref, computed, nextTick, unref, withModifiers, Comment, Text, Fragment, h, inject, withDirectives, cloneVNode, onMounted, provide, Teleport, createTextVNode, vShow } from "vue";
2
2
  import { offset, flip, arrow, computePosition } from "@floating-ui/dom";
3
3
  import Clipboard from "clipboard";
4
4
  import * as Diff2Html from "diff2html";
@@ -6804,6 +6804,15 @@ function findReferenceDomForDoubleColumn(parentNode, lineNumber, lineSide) {
6804
6804
  }
6805
6805
  }
6806
6806
  }
6807
+ function findParentTrNode(node) {
6808
+ if (!node) {
6809
+ return null;
6810
+ }
6811
+ if (node.tagName === "TR") {
6812
+ return node;
6813
+ }
6814
+ return findParentTrNode(node.parentElement);
6815
+ }
6807
6816
  function useCodeReviewExpand(reviewContentRef, props) {
6808
6817
  const { outputFormat, expandThreshold, expandLoader } = toRefs(props);
6809
6818
  const processSideBySide = () => {
@@ -7031,25 +7040,161 @@ function useCodeReviewFold(props, ctx) {
7031
7040
  });
7032
7041
  return { isFold, toggleFold };
7033
7042
  }
7043
+ function useCodeReviewLineSelection(reviewContentRef, props, mouseMoveCb, mouseupCb) {
7044
+ const ns2 = useNamespace("code-review");
7045
+ let dragging = false;
7046
+ let startTrNode;
7047
+ let trNodes;
7048
+ let isClickedLeft;
7049
+ let shouldClear;
7050
+ let isMouseMoved;
7051
+ const onMousedown = (e) => {
7052
+ if (e.button === 0) {
7053
+ const composedPath = e.composedPath();
7054
+ const lineNumberBox = composedPath.find(
7055
+ (item) => {
7056
+ var _a, _b;
7057
+ return ((_a = item.classList) == null ? void 0 : _a.contains("comment-icon-hover")) || ((_b = item.classList) == null ? void 0 : _b.contains("comment-icon"));
7058
+ }
7059
+ );
7060
+ trNodes = Array.from(reviewContentRef.value.querySelectorAll("tr")).filter((item) => {
7061
+ var _a;
7062
+ return !((_a = item.classList) == null ? void 0 : _a.contains("expand-line"));
7063
+ });
7064
+ if (!lineNumberBox) {
7065
+ return;
7066
+ }
7067
+ const parentTrNode = findParentTrNode(e.target);
7068
+ if (parentTrNode && (parentTrNode == null ? void 0 : parentTrNode.classList.contains("expand-line"))) {
7069
+ return;
7070
+ }
7071
+ startTrNode = parentTrNode;
7072
+ if (props.outputFormat === "side-by-side") {
7073
+ isClickedLeft = composedPath.some((item) => {
7074
+ var _a;
7075
+ return (_a = item.classList) == null ? void 0 : _a.contains("d-code-left");
7076
+ });
7077
+ } else {
7078
+ isClickedLeft = void 0;
7079
+ }
7080
+ dragging = true;
7081
+ shouldClear = true;
7082
+ isMouseMoved = false;
7083
+ e.preventDefault();
7084
+ e.stopPropagation();
7085
+ document.addEventListener("mousemove", onMousemove);
7086
+ document.addEventListener("mouseup", onMouseup);
7087
+ }
7088
+ };
7089
+ function onMousemove(e) {
7090
+ if (!dragging) {
7091
+ return;
7092
+ }
7093
+ isMouseMoved = true;
7094
+ if (shouldClear) {
7095
+ clearCommentChecked();
7096
+ shouldClear = false;
7097
+ }
7098
+ const composedPath = e.composedPath();
7099
+ const inReviewContent = composedPath.some((item) => {
7100
+ var _a;
7101
+ return (_a = item.classList) == null ? void 0 : _a.contains(ns2.e("content"));
7102
+ });
7103
+ if (!inReviewContent) {
7104
+ return;
7105
+ }
7106
+ const endTrNode = findParentTrNode(e.target);
7107
+ if (!endTrNode) {
7108
+ return;
7109
+ }
7110
+ let startIndex = trNodes.indexOf(startTrNode);
7111
+ let endIndex = trNodes.indexOf(endTrNode);
7112
+ if (endIndex === -1) {
7113
+ return;
7114
+ }
7115
+ mouseMoveCb();
7116
+ if (startIndex > endIndex) {
7117
+ [startIndex, endIndex] = [endIndex, startIndex];
7118
+ }
7119
+ let position;
7120
+ if (isClickedLeft === void 0) {
7121
+ position = "all";
7122
+ } else if (isClickedLeft) {
7123
+ position = "left";
7124
+ } else {
7125
+ position = "right";
7126
+ }
7127
+ for (let i = 0; i < trNodes.length; i++) {
7128
+ if (i >= startIndex && i <= endIndex) {
7129
+ toggleCommentCheckedClass(trNodes[i], true, position);
7130
+ } else {
7131
+ toggleCommentCheckedClass(trNodes[i], false, position);
7132
+ }
7133
+ }
7134
+ }
7135
+ function onMouseup() {
7136
+ dragging = false;
7137
+ if (isMouseMoved) {
7138
+ mouseupCb();
7139
+ }
7140
+ document.removeEventListener("mouseup", onMouseup);
7141
+ document.removeEventListener("mousemove", onMousemove);
7142
+ }
7143
+ function clearCommentChecked() {
7144
+ for (let i = 0; i < trNodes.length; i++) {
7145
+ toggleCommentCheckedClass(trNodes[i], false, "all");
7146
+ }
7147
+ }
7148
+ function toggleCommentCheckedClass(trNode, isAddClass, position) {
7149
+ var _a;
7150
+ const tdNodes = Array.from(trNode.children);
7151
+ let toDoNodes;
7152
+ if (position === "all") {
7153
+ toDoNodes = tdNodes;
7154
+ } else if (position === "left") {
7155
+ toDoNodes = tdNodes.slice(0, 2);
7156
+ } else {
7157
+ toDoNodes = tdNodes.slice(2);
7158
+ }
7159
+ if ((position === "left" || position === "right") && isNaN(parseInt((_a = toDoNodes[0]) == null ? void 0 : _a.innerHTML))) {
7160
+ return;
7161
+ }
7162
+ toDoNodes.forEach((item) => {
7163
+ if (item.tagName === "TD") {
7164
+ if (isAddClass) {
7165
+ item.classList.add("comment-checked");
7166
+ } else {
7167
+ item.classList.remove("comment-checked");
7168
+ }
7169
+ }
7170
+ });
7171
+ }
7172
+ return { onMousedown };
7173
+ }
7034
7174
  function useCodeReviewComment(reviewContentRef, props, ctx) {
7035
7175
  const { outputFormat, allowComment, allowChecked } = toRefs(props);
7036
7176
  const ns2 = useNamespace("code-review");
7177
+ const { onMousedown } = useCodeReviewLineSelection(reviewContentRef, props, updateLineNumbers, afterCheckLines);
7037
7178
  const commentLeft = ref(-100);
7038
7179
  const commentTop = ref(-100);
7039
7180
  let currentLeftLineNumber = -1;
7040
7181
  let currentRightLineNumber = -1;
7041
7182
  let lastLineNumberContainer;
7042
7183
  let checkedLineNumberContainer = [];
7043
- let isShift = false;
7044
7184
  let currentLeftLineNumbers = [];
7045
7185
  let currentRightLineNumbers = [];
7046
7186
  let checkedLineCodeString = {};
7047
- watch(() => outputFormat.value, () => {
7048
- checkedLineNumberContainer = [];
7049
- currentLeftLineNumbers = [];
7050
- currentRightLineNumbers = [];
7051
- checkedLineCodeString = [];
7052
- });
7187
+ let allTrNodes = [];
7188
+ let afterCheckLinesEmitData;
7189
+ watch(
7190
+ () => outputFormat.value,
7191
+ () => {
7192
+ checkedLineNumberContainer = [];
7193
+ currentLeftLineNumbers = [];
7194
+ currentRightLineNumbers = [];
7195
+ checkedLineCodeString = [];
7196
+ }
7197
+ );
7053
7198
  const resetLeftTop = () => {
7054
7199
  commentLeft.value = -100;
7055
7200
  commentTop.value = -100;
@@ -7132,30 +7277,7 @@ function useCodeReviewComment(reviewContentRef, props, ctx) {
7132
7277
  resetLeftTop();
7133
7278
  }
7134
7279
  };
7135
- function commentKeyDown(e) {
7136
- switch (e.key) {
7137
- case "Shift":
7138
- isShift = true;
7139
- break;
7140
- }
7141
- }
7142
- function commentKeyUp(e) {
7143
- e.preventDefault();
7144
- switch (e.key) {
7145
- case "Shift":
7146
- isShift = false;
7147
- break;
7148
- }
7149
- }
7150
- const unCommentKeyDown = () => {
7151
- document.removeEventListener("keydown", commentKeyDown);
7152
- document.removeEventListener("keyup", commentKeyUp);
7153
- };
7154
- const onCommentKeyDown = () => {
7155
- document.addEventListener("keydown", commentKeyDown);
7156
- document.addEventListener("keyup", commentKeyUp);
7157
- };
7158
- const getLineNumbers = (currentNumber, currentNumbers, e) => {
7280
+ const getLineNumbers = (currentNumber, currentNumbers) => {
7159
7281
  if (currentNumber === -1) {
7160
7282
  return currentNumbers;
7161
7283
  }
@@ -7164,26 +7286,27 @@ function useCodeReviewComment(reviewContentRef, props, ctx) {
7164
7286
  }
7165
7287
  const numbers = [...currentNumbers];
7166
7288
  let max = Math.max(...numbers);
7167
- const min = Math.min(...numbers);
7289
+ let min = Math.min(...numbers);
7290
+ if (currentNumber < min) {
7291
+ min = currentNumber;
7292
+ }
7168
7293
  if (currentNumber > max) {
7169
7294
  max = currentNumber;
7170
7295
  }
7171
7296
  return Array.from({ length: max - min + 1 }, (_, i) => i + min);
7172
7297
  };
7173
- const getCommonClassAndJudge = (side) => {
7174
- const lineClassName = side === "line-by-line" ? ".d2h-code-linenumber" : ".d2h-code-side-linenumber";
7175
- const linenumberDom = reviewContentRef.value.querySelectorAll(lineClassName);
7298
+ const getCommonClassAndJudge = () => {
7176
7299
  const checkedLine = [currentLeftLineNumbers, currentRightLineNumbers];
7177
7300
  return {
7178
- linenumberDom,
7301
+ linenumberDom: allTrNodes,
7179
7302
  checkedLine
7180
7303
  };
7181
7304
  };
7182
7305
  const addCommentCheckedClass = (Dom) => {
7183
7306
  !Dom.classList.contains("comment-checked") && Dom.classList.add("comment-checked");
7184
7307
  };
7185
- const addCommentClassSingle = (side) => {
7186
- const { linenumberDom, checkedLine } = getCommonClassAndJudge(side);
7308
+ function getSingleCheckedLineCode(shouldRenderClass) {
7309
+ const { linenumberDom, checkedLine } = getCommonClassAndJudge();
7187
7310
  const checkedCodeContent = [];
7188
7311
  for (let i = 0; i < linenumberDom.length; i++) {
7189
7312
  const lineNumberDomLeft = linenumberDom[i].children[0];
@@ -7193,25 +7316,29 @@ function useCodeReviewComment(reviewContentRef, props, ctx) {
7193
7316
  const codeLineNumberRight = parseInt(lineNumberDomRight == null ? void 0 : lineNumberDomRight.innerText);
7194
7317
  if (checkedLine[0].includes(codeLineNumberLeft) || checkedLine[1].includes(codeLineNumberRight)) {
7195
7318
  checkedLineNumberContainer.push(linenumberDom[i]);
7196
- const codeNode = linenumberDom[i].nextSibling.nodeName === "#text" ? linenumberDom[i].nextSibling.nextSibling : linenumberDom[i].nextSibling;
7319
+ const codeNode = linenumberDom[i].nextElementSibling;
7197
7320
  checkedCodeContent.push(codeNode == null ? void 0 : codeNode.innerText);
7198
- addCommentCheckedClass(linenumberDom[i]);
7199
- addCommentCheckedClass(codeNode);
7321
+ if (shouldRenderClass) {
7322
+ addCommentCheckedClass(linenumberDom[i]);
7323
+ addCommentCheckedClass(codeNode);
7324
+ }
7200
7325
  }
7201
7326
  }
7202
7327
  }
7203
7328
  checkedLineCodeString = checkedCodeContent;
7204
- };
7205
- const addCommentClassDouble = (side) => {
7329
+ }
7330
+ function getDoubleCheckedLineCode(shouldRenderClass) {
7206
7331
  var _a;
7207
- const { linenumberDom, checkedLine } = getCommonClassAndJudge(side);
7332
+ const { linenumberDom, checkedLine } = getCommonClassAndJudge();
7208
7333
  const checkedCodeContentLeft = [];
7209
7334
  const checkedCodeContentRight = [];
7210
7335
  function checkedFunc(Dom) {
7211
7336
  checkedLineNumberContainer.push(Dom);
7212
- const codeNode = Dom.nextSibling.nodeName === "#text" ? Dom.nextSibling.nextSibling : Dom.nextSibling;
7213
- addCommentCheckedClass(Dom);
7214
- addCommentCheckedClass(codeNode);
7337
+ const codeNode = Dom.nextElementSibling;
7338
+ if (shouldRenderClass) {
7339
+ addCommentCheckedClass(Dom);
7340
+ addCommentCheckedClass(codeNode);
7341
+ }
7215
7342
  return codeNode == null ? void 0 : codeNode.innerText;
7216
7343
  }
7217
7344
  for (let i = 0; i < linenumberDom.length; i++) {
@@ -7227,38 +7354,53 @@ function useCodeReviewComment(reviewContentRef, props, ctx) {
7227
7354
  }
7228
7355
  }
7229
7356
  checkedLineCodeString = { leftCode: checkedCodeContentLeft, rightCode: checkedCodeContentRight };
7230
- };
7231
- const updateCheckedLineClass = () => {
7232
- if (outputFormat.value === "line-by-line") {
7233
- addCommentClassSingle(outputFormat.value);
7234
- return;
7357
+ }
7358
+ function getCheckedLineCode(shouldRenderClass) {
7359
+ if (props.outputFormat === "line-by-line") {
7360
+ return getSingleCheckedLineCode(shouldRenderClass);
7235
7361
  }
7236
- addCommentClassDouble(outputFormat.value);
7362
+ getDoubleCheckedLineCode(shouldRenderClass);
7363
+ }
7364
+ function updateLineNumbers() {
7365
+ currentLeftLineNumbers = currentLeftLineNumber === -1 ? currentLeftLineNumbers : getLineNumbers(currentLeftLineNumber, currentLeftLineNumbers);
7366
+ currentRightLineNumbers = currentRightLineNumber === -1 ? currentRightLineNumbers : getLineNumbers(currentRightLineNumber, currentRightLineNumbers);
7367
+ getCheckedLineCode(false);
7368
+ afterCheckLinesEmitData = {
7369
+ left: currentLeftLineNumber,
7370
+ right: currentRightLineNumber,
7371
+ details: {
7372
+ lefts: currentLeftLineNumbers,
7373
+ rights: currentRightLineNumbers,
7374
+ codes: checkedLineCodeString
7375
+ }
7376
+ };
7377
+ }
7378
+ const updateCheckedLineClass = () => {
7379
+ getCheckedLineCode(true);
7237
7380
  };
7238
7381
  const resetCommentClass = () => {
7239
7382
  for (let i = 0; i < checkedLineNumberContainer.length; i++) {
7240
7383
  checkedLineNumberContainer[i].classList.remove("comment-checked");
7241
- const codeNode = checkedLineNumberContainer[i].nextSibling.nodeName === "#text" ? checkedLineNumberContainer[i].nextSibling.nextSibling : checkedLineNumberContainer[i].nextSibling;
7384
+ const codeNode = checkedLineNumberContainer[i].nextElementSibling;
7242
7385
  codeNode == null ? void 0 : codeNode.classList.remove("comment-checked");
7243
7386
  }
7244
7387
  checkedLineNumberContainer = [];
7245
7388
  };
7246
- const commentShiftClick = (e) => {
7247
- currentLeftLineNumbers = currentLeftLineNumber === -1 ? currentLeftLineNumbers : getLineNumbers(currentLeftLineNumber, currentLeftLineNumbers);
7248
- currentRightLineNumbers = currentRightLineNumber === -1 ? currentRightLineNumbers : getLineNumbers(currentRightLineNumber, currentRightLineNumbers);
7249
- updateCheckedLineClass();
7250
- };
7251
- const commentClick = (e) => {
7389
+ const commentClick = () => {
7252
7390
  let obj = { left: currentLeftLineNumber, right: currentRightLineNumber };
7253
- if (currentLeftLineNumbers.length >= 1 || currentRightLineNumbers.length >= 1 && allowChecked.value) {
7391
+ if ((currentLeftLineNumbers.length >= 1 || currentRightLineNumbers.length >= 1) && allowChecked.value) {
7254
7392
  const maxCurrentLeftLineNumber = currentLeftLineNumbers[currentLeftLineNumbers.length - 1];
7255
7393
  const maxCurrentRightLineNumber = currentRightLineNumbers[currentRightLineNumbers.length - 1];
7256
7394
  if (maxCurrentLeftLineNumber === currentLeftLineNumber || maxCurrentRightLineNumber === currentRightLineNumber) {
7257
- obj = { left: currentLeftLineNumber, right: currentRightLineNumber, details: {
7258
- lefts: currentLeftLineNumbers,
7259
- rights: currentRightLineNumbers,
7260
- codes: checkedLineCodeString
7261
- } };
7395
+ obj = {
7396
+ left: currentLeftLineNumber,
7397
+ right: currentRightLineNumber,
7398
+ details: {
7399
+ lefts: currentLeftLineNumbers,
7400
+ rights: currentRightLineNumbers,
7401
+ codes: checkedLineCodeString
7402
+ }
7403
+ };
7262
7404
  } else {
7263
7405
  currentLeftLineNumbers = [];
7264
7406
  currentRightLineNumbers = [];
@@ -7267,6 +7409,9 @@ function useCodeReviewComment(reviewContentRef, props, ctx) {
7267
7409
  }
7268
7410
  ctx.emit("addComment", obj);
7269
7411
  };
7412
+ function afterCheckLines() {
7413
+ ctx.emit("afterCheckLines", afterCheckLinesEmitData);
7414
+ }
7270
7415
  const onCommentIconClick = (e) => {
7271
7416
  if (e) {
7272
7417
  const composedPath = e.composedPath();
@@ -7280,10 +7425,6 @@ function useCodeReviewComment(reviewContentRef, props, ctx) {
7280
7425
  return;
7281
7426
  }
7282
7427
  }
7283
- if (isShift && allowChecked.value) {
7284
- commentShiftClick();
7285
- return;
7286
- }
7287
7428
  commentClick();
7288
7429
  };
7289
7430
  const insertComment = (lineNumber, lineSide, commentDom) => {
@@ -7330,7 +7471,19 @@ function useCodeReviewComment(reviewContentRef, props, ctx) {
7330
7471
  checkedLineCodeString = [];
7331
7472
  resetCommentClass();
7332
7473
  };
7333
- const mouseEvent = allowComment.value ? { onMousemove: onMouseMove, onMouseleave } : {};
7474
+ const handleMouseDown = (e) => {
7475
+ const lineClassName = props.outputFormat === "line-by-line" ? ".d2h-code-linenumber" : ".d2h-code-side-linenumber";
7476
+ allTrNodes = reviewContentRef.value.querySelectorAll(lineClassName);
7477
+ onMousedown(e);
7478
+ };
7479
+ const mouseEvent = {};
7480
+ if (allowComment.value) {
7481
+ mouseEvent.onMousemove = onMouseMove;
7482
+ mouseEvent.onMouseleave = onMouseleave;
7483
+ }
7484
+ if (props.allowChecked) {
7485
+ mouseEvent.onMousedown = handleMouseDown;
7486
+ }
7334
7487
  window.addEventListener("scroll", resetLeftTop);
7335
7488
  onUnmounted(() => {
7336
7489
  window.removeEventListener("scroll", resetLeftTop);
@@ -7343,8 +7496,6 @@ function useCodeReviewComment(reviewContentRef, props, ctx) {
7343
7496
  clearCheckedLines,
7344
7497
  onCommentMouseLeave,
7345
7498
  onCommentIconClick,
7346
- onCommentKeyDown,
7347
- unCommentKeyDown,
7348
7499
  insertComment,
7349
7500
  removeComment
7350
7501
  };
@@ -7353,7 +7504,7 @@ var codeReview = "";
7353
7504
  var CodeReview = defineComponent({
7354
7505
  name: "DCodeReview",
7355
7506
  props: codeReviewProps,
7356
- emits: ["foldChange", "addComment", "afterViewInit", "contentRefresh"],
7507
+ emits: ["foldChange", "addComment", "afterViewInit", "contentRefresh", "afterCheckLines"],
7357
7508
  setup(props, ctx) {
7358
7509
  const ns2 = useNamespace("code-review");
7359
7510
  const {
@@ -7375,8 +7526,6 @@ var CodeReview = defineComponent({
7375
7526
  mouseEvent,
7376
7527
  onCommentMouseLeave,
7377
7528
  onCommentIconClick,
7378
- onCommentKeyDown,
7379
- unCommentKeyDown,
7380
7529
  insertComment,
7381
7530
  removeComment,
7382
7531
  updateCheckedLineClass,
@@ -7390,10 +7539,6 @@ var CodeReview = defineComponent({
7390
7539
  updateCheckedLineClass,
7391
7540
  clearCheckedLines
7392
7541
  });
7393
- onCommentKeyDown();
7394
- });
7395
- onBeforeUnmount(() => {
7396
- unCommentKeyDown();
7397
7542
  });
7398
7543
  provide(CodeReviewInjectionKey, {
7399
7544
  diffType,