vue-devui 1.6.23 → 1.6.25

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