vue-devui 1.5.7 → 1.5.9

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.
Files changed (106) hide show
  1. package/alert/index.es.js +13 -3
  2. package/alert/index.umd.js +11 -1
  3. package/auto-complete/index.es.js +7 -1
  4. package/auto-complete/index.umd.js +7 -7
  5. package/auto-complete/style.css +1 -1
  6. package/avatar/index.es.js +10 -2
  7. package/avatar/index.umd.js +9 -1
  8. package/checkbox/index.es.js +7 -1
  9. package/checkbox/index.umd.js +13 -13
  10. package/checkbox/style.css +1 -1
  11. package/code-editor/index.es.js +13 -12
  12. package/code-editor/index.umd.js +5 -5
  13. package/code-review/index.es.js +589 -21
  14. package/code-review/index.umd.js +76 -19
  15. package/code-review/style.css +1 -1
  16. package/date-picker-pro/index.es.js +7 -1
  17. package/date-picker-pro/index.umd.js +8 -8
  18. package/date-picker-pro/style.css +1 -1
  19. package/dragdrop/index.es.js +158 -0
  20. package/dragdrop/index.umd.js +1 -0
  21. package/dragdrop/package.json +8 -0
  22. package/editor-md/style.css +1 -1
  23. package/form/index.es.js +7 -1
  24. package/form/index.umd.js +7 -7
  25. package/form/style.css +1 -1
  26. package/git-graph/index.es.js +6061 -0
  27. package/git-graph/index.umd.js +32 -0
  28. package/git-graph/package.json +8 -0
  29. package/global.d.ts +2 -0
  30. package/input/index.es.js +7 -1
  31. package/input/index.umd.js +6 -6
  32. package/input/style.css +1 -1
  33. package/input-number/index.es.js +7 -1
  34. package/input-number/index.umd.js +10 -10
  35. package/input-number/style.css +1 -1
  36. package/mention/index.es.js +7 -1
  37. package/mention/index.umd.js +9 -9
  38. package/mention/style.css +1 -1
  39. package/modal/index.es.js +2 -1
  40. package/modal/index.umd.js +1 -1
  41. package/nuxt/components/GitGraph.js +2 -0
  42. package/nuxt/components/gitGraphProps.js +2 -0
  43. package/package.json +2 -1
  44. package/pagination/index.es.js +14 -2
  45. package/pagination/index.umd.js +13 -7
  46. package/pagination/style.css +1 -1
  47. package/radio/index.es.js +7 -1
  48. package/radio/index.umd.js +13 -13
  49. package/radio/style.css +1 -1
  50. package/search/index.es.js +7 -1
  51. package/search/index.umd.js +8 -8
  52. package/search/style.css +1 -1
  53. package/select/index.es.js +14 -2
  54. package/select/index.umd.js +11 -5
  55. package/select/style.css +1 -1
  56. package/splitter/index.es.js +14 -3
  57. package/splitter/index.umd.js +12 -12
  58. package/style.css +1 -1
  59. package/switch/index.es.js +7 -1
  60. package/switch/index.umd.js +14 -14
  61. package/switch/style.css +1 -1
  62. package/table/index.es.js +7 -1
  63. package/table/index.umd.js +5 -5
  64. package/table/style.css +1 -1
  65. package/textarea/index.es.js +7 -1
  66. package/textarea/index.umd.js +12 -12
  67. package/textarea/style.css +1 -1
  68. package/time-picker/index.es.js +7 -1
  69. package/time-picker/index.umd.js +7 -7
  70. package/time-picker/style.css +1 -1
  71. package/time-select/index.es.js +14 -2
  72. package/time-select/index.umd.js +11 -5
  73. package/time-select/style.css +1 -1
  74. package/tree/index.es.js +7 -1
  75. package/tree/index.umd.js +7 -7
  76. package/tree/style.css +1 -1
  77. package/types/avatar/src/components/icon-body.d.ts +1 -1
  78. package/types/code-editor/src/code-editor-types.d.ts +1 -1
  79. package/types/code-editor/src/code-editor.d.ts +1 -1
  80. package/types/code-editor/src/composables/use-code-editor.d.ts +2 -2
  81. package/types/code-review/src/code-review-types.d.ts +20 -0
  82. package/types/code-review/src/code-review.d.ts +16 -1
  83. package/types/code-review/src/components/code-review-icons.d.ts +4 -0
  84. package/types/code-review/src/composables/use-code-review-comment.d.ts +13 -0
  85. package/types/code-review/src/composables/use-code-review-expand.d.ts +6 -0
  86. package/types/code-review/src/composables/use-code-review-fold.d.ts +6 -0
  87. package/types/code-review/src/composables/use-code-review.d.ts +6 -3
  88. package/types/code-review/src/const.d.ts +2 -0
  89. package/types/code-review/src/utils.d.ts +15 -0
  90. package/types/dragdrop/src/const.d.ts +0 -1
  91. package/types/dragdrop/src/draggable-directive.d.ts +1 -18
  92. package/types/dragdrop/src/droppable-directive.d.ts +1 -14
  93. package/types/dragdrop/src/sortable-directive.d.ts +1 -15
  94. package/types/dragdrop/src/utils.d.ts +2 -80
  95. package/types/form/src/form-types.d.ts +4 -0
  96. package/types/form/src/form.d.ts +9 -0
  97. package/types/git-graph/index.d.ts +11 -0
  98. package/types/git-graph/src/git-graph-class.d.ts +43 -0
  99. package/types/git-graph/src/git-graph-types.d.ts +84 -0
  100. package/types/git-graph/src/git-graph.d.ts +10 -0
  101. package/types/git-graph/src/use-git-graph.d.ts +6 -0
  102. package/types/modal/src/modal-types.d.ts +1 -1
  103. package/types/modal/src/modal.d.ts +2 -1
  104. package/types/vue-devui.d.ts +2 -1
  105. package/vue-devui.es.js +1411 -225
  106. package/vue-devui.umd.js +140 -60
@@ -1,7 +1,8 @@
1
- import { watch, onUnmounted, defineComponent, toRefs, createVNode, Transition, mergeProps, ref, unref, nextTick, withModifiers, Comment, Text, h, Fragment, inject, withDirectives, cloneVNode, computed, onMounted, provide, Teleport, createTextVNode, onBeforeMount } from "vue";
1
+ import { watch, onUnmounted, defineComponent, toRefs, createVNode, Transition, mergeProps, ref, unref, nextTick, withModifiers, Comment, Text, h, Fragment, inject, withDirectives, cloneVNode, computed, onMounted, provide, Teleport, createTextVNode } from "vue";
2
2
  import { offset, autoPlacement, arrow, shift, computePosition } from "@floating-ui/dom";
3
3
  import Clipboard from "clipboard";
4
4
  import * as Diff2Html from "diff2html";
5
+ import { Diff2HtmlUI } from "diff2html/lib/ui/js/diff2html-ui";
5
6
  const fixedOverlayProps = {
6
7
  modelValue: {
7
8
  type: Boolean,
@@ -6106,6 +6107,88 @@ function CopyIcon() {
6106
6107
  "fill-rule": "nonzero"
6107
6108
  }, null)])]);
6108
6109
  }
6110
+ function CommentIcon() {
6111
+ return createVNode("svg", {
6112
+ "width": "12px",
6113
+ "height": "12px",
6114
+ "viewBox": "0 0 16 16",
6115
+ "version": "1.1",
6116
+ "xmlns": "http://www.w3.org/2000/svg"
6117
+ }, [createVNode("g", {
6118
+ "stroke": "none",
6119
+ "stroke-width": "1",
6120
+ "fill": "none",
6121
+ "fill-rule": "evenodd"
6122
+ }, [createVNode("path", {
6123
+ "d": `M14,1 C15.1045695,1 16,1.8954305 16,3 L16,11 C16,12.1045695 15.1045695,13 14,13 L11,13 L8,16 L5,13 L2,13
6124
+ C0.8954305,13 0,12.1045695 0,11 L0,3 C0,1.8954305 0.8954305,1 2,1 L14,1 Z M14,3 L2,3 L2,11 L5,11 C5.47149598,11
6125
+ 5.92582641,11.1664898 6.28439337,11.4669131 L6.41421356,11.5857864 L8,13.171 L9.58578644,11.5857864
6126
+ C9.91918444,11.2523884 10.3581707,11.0488544 10.8241472,11.0077406 L11,11 L14,11 L14,3 Z M8,6 C8.55228475,6
6127
+ 9,6.44771525 9,7 C9,7.55228475 8.55228475,8 8,8 C7.44771525,8 7,7.55228475 7,7 C7,6.44771525 7.44771525,6
6128
+ 8,6 Z M11,6 C11.5522847,6 12,6.44771525 12,7 C12,7.55228475 11.5522847,8 11,8 C10.4477153,8 10,7.55228475
6129
+ 10,7 C10,6.44771525 10.4477153,6 11,6 Z M5,6 C5.55228475,6 6,6.44771525 6,7 C6,7.55228475 5.55228475,8
6130
+ 5,8 C4.44771525,8 4,7.55228475 4,7 C4,6.44771525 4.44771525,6 5,6 Z`,
6131
+ "fill": "#5e7ce0",
6132
+ "fill-rule": "nonzero"
6133
+ }, null)])]);
6134
+ }
6135
+ function UpExpandIcon() {
6136
+ return `<svg width="16px" height="16px" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg">
6137
+ <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
6138
+ <g transform="translate(-1365.000000,-11.000000)">
6139
+ <g transform="translate(1365.000000,11.000000)">
6140
+ <rect x="0" y="0" width="16" height="16"></rect>
6141
+ <g
6142
+ transform="translate(8.000000, 8.000000) scale(1, -1) translate(-8.000000, -8.000000) translate(1.000000, 4.000000)"
6143
+ fill="#71757F">
6144
+ <path
6145
+ d='M0.5,0 L13.5,0 C13.7761424,0 14,0.223857625 14,0.5 C14,0.776142375 13.7761424,1 13.5,1 L0.5,1 C0.223857625,1
6146
+ 0,0.776142375 0,0.5 C0,0.223857625 0.223857625,0 0.5,0 Z'></path>
6147
+ <polygon
6148
+ transform="translate(7.000000, 5.5000000) scale(1, -1) translate(-7.000000, -5.5000000)"
6149
+ points="7 3 10 8 4 8"></polygon>
6150
+ </g>
6151
+ </g>
6152
+ </g>
6153
+ </g>
6154
+ </svg>`;
6155
+ }
6156
+ function DownExpandIcon() {
6157
+ return `<svg width="16px" height="16px" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg">
6158
+ <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
6159
+ <g transform="translate(-1344.000000,-11.000000)">
6160
+ <g transform="translate(1344.000000,11.000000)">
6161
+ <rect x="0" y="0" width="16" height="16"></rect>
6162
+ <g transform="translate(1.000000, 5.000000)" fill="#71757F">
6163
+ <path
6164
+ d="M0.5,0 L13.5,0 C13.7761424,0 14,0.223857625 14,0.5 C14,0.776142375 13.7761424,1 13.5,1 L0.5,1 C0.223857625,1
6165
+ 0,0.776142375 0,0.5 C0,0.223857625 0.223857625,0 0.5,0 Z"></path>
6166
+ <polygon
6167
+ transform="translate(7.000000,5.500000) scale(1, -1) translate(-7.000000, -5.500000)"
6168
+ points="7 3 10 8 4 8"></polygon>
6169
+ </g>
6170
+ </g>
6171
+ </g>
6172
+ </g>
6173
+ </svg>`;
6174
+ }
6175
+ function AllExpandIcon() {
6176
+ return `<svg width="16px" height="16px" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg">
6177
+ <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
6178
+ <g transform="translate(-1301.000000,-11.000000)">
6179
+ <rect x="1301" y="11" width="16" height="16"></rect>
6180
+ <path
6181
+ d="M1302.5,18 L1315.5,18 C1315.77614,18 1316,18.2238576 1316,18.5 1316,18.7761424 1315.77614,19 1315.5,19 L1302.5,19
6182
+ C1302.22386,19 1302,18.7761424 1302,18.5 C1302,18.2238576 1302.22386,18 1302.5,18 Z" fill="#71757F"></path>
6183
+ <polygon fill="#71757F" points="1309 11 1312 16 1306 16"></polygon>
6184
+ <polygon
6185
+ fill="#71757F"
6186
+ transform="translate(1309.000000, 23.500000) scale(1, -1) translate(-1309.000000, -23.500000)"
6187
+ points="1309 21 1312 26 1306 26"></polygon>
6188
+ </g>
6189
+ </g>
6190
+ </svg>`;
6191
+ }
6109
6192
  const codeReviewProps = {
6110
6193
  diff: {
6111
6194
  type: String,
@@ -6119,6 +6202,13 @@ const codeReviewProps = {
6119
6202
  outputFormat: {
6120
6203
  type: String,
6121
6204
  default: "line-by-line"
6205
+ },
6206
+ expandAllThreshold: {
6207
+ type: Number,
6208
+ default: 50
6209
+ },
6210
+ codeLoader: {
6211
+ type: Function
6122
6212
  }
6123
6213
  };
6124
6214
  const CodeReviewInjectionKey = Symbol("d-code-review");
@@ -6208,18 +6298,369 @@ var CodeReviewHeader = defineComponent({
6208
6298
  }, [rootCtx.slots.headOperate()])]);
6209
6299
  }
6210
6300
  });
6301
+ const ExpandLineReg = /^@@ -(\d+),(\d+) \+(\d+),(\d+) @@/;
6302
+ const FirstLineReg = /^@@ -[0,1](?!\d)/;
6303
+ function notEmptyNode(node) {
6304
+ const classes = node.classList;
6305
+ return !classes.contains("d2h-info") && !classes.contains("d2h-emptyplaceholder") && !classes.contains("comment-cell");
6306
+ }
6307
+ function insertIncrementLineToPage(referenceDom, trNodes, direction) {
6308
+ const trNodesToBeInserted = trNodes.filter((element) => element.children[0].children.length === 2);
6309
+ if (direction === "up") {
6310
+ const nextSibling = referenceDom.nextElementSibling;
6311
+ trNodesToBeInserted.forEach((item) => {
6312
+ var _a;
6313
+ (_a = referenceDom.parentNode) == null ? void 0 : _a.insertBefore(item, nextSibling);
6314
+ });
6315
+ } else {
6316
+ trNodesToBeInserted.forEach((item) => {
6317
+ var _a;
6318
+ (_a = referenceDom.parentNode) == null ? void 0 : _a.insertBefore(item, referenceDom);
6319
+ });
6320
+ }
6321
+ }
6322
+ function ifRemoveExpandLine(expandDom, newExpandDom, direction) {
6323
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
6324
+ const matches = newExpandDom.children[1].innerText.trim().match(ExpandLineReg);
6325
+ if (!matches) {
6326
+ return true;
6327
+ }
6328
+ const leftLineNumber = parseInt(matches[1]);
6329
+ const addedLine = parseInt(matches[2]);
6330
+ const rightLineNumber = parseInt(matches[3]);
6331
+ if (direction === "up") {
6332
+ const prevSibling = expandDom.previousElementSibling;
6333
+ if (!prevSibling) {
6334
+ if (leftLineNumber === 1 && rightLineNumber === 1) {
6335
+ expandDom == null ? void 0 : expandDom.remove();
6336
+ return true;
6337
+ }
6338
+ } else {
6339
+ const prevLeftLineNumber = parseInt((_c = (_b = (_a = prevSibling.children) == null ? void 0 : _a[0].children) == null ? void 0 : _b[0]) == null ? void 0 : _c.innerText);
6340
+ const prevRightLineNumber = parseInt((_f = (_e = (_d = prevSibling.children) == null ? void 0 : _d[0].children) == null ? void 0 : _e[1]) == null ? void 0 : _f.innerText);
6341
+ if (leftLineNumber === prevLeftLineNumber + 1 && rightLineNumber === prevRightLineNumber + 1) {
6342
+ expandDom.remove();
6343
+ return true;
6344
+ }
6345
+ }
6346
+ } else {
6347
+ const nextSibling = expandDom.nextElementSibling;
6348
+ const nextLeftLineNumber = parseInt((_i = (_h = (_g = nextSibling == null ? void 0 : nextSibling.children) == null ? void 0 : _g[0].children) == null ? void 0 : _h[0]) == null ? void 0 : _i.innerText);
6349
+ const nextRightLineNumber = parseInt((_l = (_k = (_j = nextSibling == null ? void 0 : nextSibling.children) == null ? void 0 : _j[0].children) == null ? void 0 : _k[1]) == null ? void 0 : _l.innerText);
6350
+ if (leftLineNumber + addedLine === nextLeftLineNumber && rightLineNumber + addedLine === nextRightLineNumber) {
6351
+ expandDom.remove();
6352
+ return true;
6353
+ }
6354
+ }
6355
+ return false;
6356
+ }
6357
+ function updateExpandLineCount(expandDom, newExpandDom) {
6358
+ if (!expandDom.nextElementSibling) {
6359
+ return;
6360
+ }
6361
+ const curMatches = expandDom.children[1].innerText.trim().match(ExpandLineReg);
6362
+ const newMatches = newExpandDom.children[1].innerText.trim().match(ExpandLineReg);
6363
+ const newChangedNumLeft = parseInt((curMatches == null ? void 0 : curMatches[2]) || "") + parseInt((newMatches == null ? void 0 : newMatches[2]) || "");
6364
+ const newChangedNumRight = parseInt((curMatches == null ? void 0 : curMatches[4]) || "") + parseInt((newMatches == null ? void 0 : newMatches[4]) || "");
6365
+ expandDom.children[1].children[0].innerText = `@@ -${(newMatches == null ? void 0 : newMatches[1]) || 0},${newChangedNumLeft} +${(newMatches == null ? void 0 : newMatches[3]) || 0},${newChangedNumRight} @@`;
6366
+ }
6367
+ function parseDiffCode(container, code, outputFormat) {
6368
+ const diff2HtmlUi = new Diff2HtmlUI(container, code, {
6369
+ drawFileList: false,
6370
+ matching: "lines",
6371
+ outputFormat,
6372
+ highlight: true
6373
+ });
6374
+ diff2HtmlUi.draw();
6375
+ diff2HtmlUi.highlightCode();
6376
+ }
6377
+ function setLineNumberInDataset(trNode, prevL, prevR, nextL, nextR) {
6378
+ if (trNode) {
6379
+ trNode.classList.add("expand-line");
6380
+ trNode.dataset.prevL = String(prevL);
6381
+ trNode.dataset.prevR = String(prevR);
6382
+ trNode.dataset.nextL = String(nextL);
6383
+ trNode.dataset.nextR = String(nextR);
6384
+ }
6385
+ }
6386
+ function updateExpandUpDownButton(trNode) {
6387
+ trNode.children[0].children[0].remove();
6388
+ trNode.children[0].children[0].classList.remove("up-expand");
6389
+ trNode.children[0].children[0].classList.add("all-expand");
6390
+ trNode.children[0].children[0].innerHTML = AllExpandIcon();
6391
+ }
6392
+ function updateLineNumberInDataset(trNode, expandAllThreshold, position, updateExpandButton = false) {
6393
+ let nextL;
6394
+ let prevL;
6395
+ let nextR;
6396
+ let prevR;
6397
+ if (position === "top") {
6398
+ const nextLineNode = trNode.nextElementSibling;
6399
+ nextL = parseInt(nextLineNode.children[0].children[0].innerText) - 1;
6400
+ prevL = Math.max(nextL - expandAllThreshold + 1, 1);
6401
+ nextR = parseInt(nextLineNode.children[0].children[1].innerText) - 1;
6402
+ prevR = Math.max(nextR - expandAllThreshold + 1, 1);
6403
+ } else if (position === "bottom") {
6404
+ const prevLineNode = trNode.previousElementSibling;
6405
+ prevL = parseInt(prevLineNode.children[0].children[0].innerText) + 1;
6406
+ nextL = prevL + expandAllThreshold - 1;
6407
+ prevR = parseInt(prevLineNode.children[0].children[1].innerText) + 1;
6408
+ nextR = prevR + expandAllThreshold - 1;
6409
+ } else {
6410
+ const prevLineNode = trNode.previousElementSibling;
6411
+ const nextLineNode = trNode.nextElementSibling;
6412
+ const prevLineNumber = parseInt(prevLineNode.children[0].children[0].innerText);
6413
+ const nextLineNumber = parseInt(nextLineNode.children[0].children[0].innerText);
6414
+ prevL = prevLineNumber + 1;
6415
+ prevR = parseInt(prevLineNode.children[0].children[1].innerText) + 1;
6416
+ nextL = nextLineNumber - 1;
6417
+ nextR = parseInt(nextLineNode.children[0].children[1].innerText) - 1;
6418
+ const isExpandAll = nextLineNumber - prevLineNumber <= expandAllThreshold;
6419
+ if (isExpandAll && updateExpandButton) {
6420
+ updateExpandUpDownButton(trNode);
6421
+ }
6422
+ }
6423
+ setLineNumberInDataset(trNode, prevL, prevR, nextL, nextR);
6424
+ }
6425
+ function getLineNumberFormDataset(expandDom, expandAllThreshold) {
6426
+ var _a, _b, _c;
6427
+ const attrsMap = (_b = (_a = expandDom.parentElement) == null ? void 0 : _a.parentElement) == null ? void 0 : _b.dataset;
6428
+ const prevL = Number(attrsMap == null ? void 0 : attrsMap.prevL);
6429
+ const nextL = Number(attrsMap == null ? void 0 : attrsMap.nextL);
6430
+ const prevR = Number(attrsMap == null ? void 0 : attrsMap.prevR);
6431
+ const nextR = Number(attrsMap == null ? void 0 : attrsMap.nextR);
6432
+ let leftLineStart, leftLineEnd, rightLineStart, rightLineEnd;
6433
+ if (prevL && nextL && prevR && nextR) {
6434
+ const buttonClasses = Array.from(expandDom.classList);
6435
+ const direction = (_c = buttonClasses.find((item) => item.endsWith("expand"))) == null ? void 0 : _c.split("-")[0];
6436
+ if (direction === "up") {
6437
+ leftLineEnd = nextL;
6438
+ leftLineStart = Math.max(leftLineEnd - expandAllThreshold + 1, prevL);
6439
+ rightLineEnd = nextR;
6440
+ rightLineStart = Math.max(rightLineEnd - expandAllThreshold + 1, prevR);
6441
+ } else if (direction === "down") {
6442
+ leftLineStart = prevL;
6443
+ leftLineEnd = Math.min(leftLineStart + expandAllThreshold - 1, nextL);
6444
+ rightLineStart = prevR;
6445
+ rightLineEnd = Math.min(rightLineStart + expandAllThreshold - 1, nextR);
6446
+ } else {
6447
+ leftLineStart = prevL;
6448
+ leftLineEnd = nextL;
6449
+ rightLineStart = prevR;
6450
+ rightLineEnd = nextR;
6451
+ }
6452
+ }
6453
+ return [leftLineStart, leftLineEnd, rightLineStart, rightLineEnd];
6454
+ }
6455
+ function insertNode(parent, child) {
6456
+ if (parent.firstChild) {
6457
+ parent.insertBefore(child, parent.firstChild);
6458
+ } else {
6459
+ parent.appendChild(child);
6460
+ }
6461
+ }
6462
+ function addExpandButton(parentNode, className, icon) {
6463
+ const expandButton = document.createElement("div");
6464
+ expandButton.innerHTML = icon;
6465
+ expandButton.classList.add("expand-icon");
6466
+ expandButton.classList.add(className);
6467
+ insertNode(parentNode, expandButton);
6468
+ }
6469
+ function attachExpandUpDownButton(parentNode, direction) {
6470
+ var _a;
6471
+ const expandDirectionMap = {
6472
+ up: "up-expand",
6473
+ down: "down-expand",
6474
+ all: "all-expand"
6475
+ };
6476
+ const expandDirectionIconMap = {
6477
+ up: UpExpandIcon,
6478
+ down: DownExpandIcon,
6479
+ all: AllExpandIcon
6480
+ };
6481
+ parentNode.classList.add("expand-icon-wrapper");
6482
+ if (direction === "updown") {
6483
+ addExpandButton(parentNode, "up-expand", UpExpandIcon());
6484
+ addExpandButton(parentNode, "down-expand", DownExpandIcon());
6485
+ } else {
6486
+ addExpandButton(parentNode, expandDirectionMap[direction], (_a = expandDirectionIconMap[direction]) == null ? void 0 : _a.call(expandDirectionIconMap));
6487
+ }
6488
+ }
6489
+ function addCommentToPage(lineHost, commentDom, lineSide) {
6490
+ var _a, _b;
6491
+ const newLine = document.createElement("tr");
6492
+ const newCell = document.createElement("td");
6493
+ newCell.classList.add("comment-cell");
6494
+ newCell.style.width = "100%";
6495
+ newCell.setAttribute("colspan", "2");
6496
+ newCell.appendChild(commentDom);
6497
+ newLine.classList.add("comment-block");
6498
+ newLine.classList.add(lineSide);
6499
+ newLine.appendChild(newCell);
6500
+ if (lineHost.nextElementSibling) {
6501
+ (_a = lineHost.parentElement) == null ? void 0 : _a.insertBefore(newLine, lineHost.nextElementSibling);
6502
+ } else {
6503
+ (_b = lineHost.parentElement) == null ? void 0 : _b.appendChild(newLine);
6504
+ }
6505
+ }
6506
+ function useCodeReviewExpand(reviewContentRef, props) {
6507
+ const { outputFormat, expandAllThreshold, codeLoader } = toRefs(props);
6508
+ const processSideBySide = () => {
6509
+ const [leftTable, rightTable] = reviewContentRef.value.querySelectorAll("table");
6510
+ const trNodes = Array.from(leftTable.querySelectorAll("tr"));
6511
+ const totalLines = trNodes.length;
6512
+ for (const index2 in trNodes) {
6513
+ const lineIndex = parseInt(index2);
6514
+ const lineChildren = Array.from(trNodes[lineIndex].children);
6515
+ const lineNumberBox = lineChildren[0];
6516
+ const lineContentBox = lineChildren[1];
6517
+ const lineClassList = lineContentBox.classList.value;
6518
+ const lineContent = lineContentBox.innerText.trim();
6519
+ if (lineContent.match(ExpandLineReg) && !FirstLineReg.test(lineContent) && lineClassList && lineClassList.includes("d2h-info")) {
6520
+ const nextLineIndex = lineIndex + 1;
6521
+ const prevLineIndex = lineIndex - 1;
6522
+ if (lineIndex === 0 && nextLineIndex in trNodes) {
6523
+ attachExpandUpDownButton(lineNumberBox, "up");
6524
+ } else if (lineIndex > 0 && lineIndex < totalLines - 1 && nextLineIndex in trNodes && prevLineIndex in trNodes) {
6525
+ const preLineChildren = Array.from(trNodes[prevLineIndex].children);
6526
+ const nextLineChildren = Array.from(trNodes[nextLineIndex].children);
6527
+ const isExpandAll = parseInt(nextLineChildren[0].innerText) - parseInt(preLineChildren[0].innerText) - 1 < expandAllThreshold.value;
6528
+ attachExpandUpDownButton(lineNumberBox, isExpandAll ? "all" : "updown");
6529
+ }
6530
+ }
6531
+ }
6532
+ const endLine = trNodes[0].cloneNode(true);
6533
+ if (Object.prototype.hasOwnProperty.call(endLine.children[0].children, 0)) {
6534
+ endLine.children[0].removeChild(endLine.children[0].children[0]);
6535
+ }
6536
+ endLine.children[1].innerText = "";
6537
+ const leftEndLine = endLine.cloneNode(true);
6538
+ const rightEndLint = endLine.cloneNode(true);
6539
+ attachExpandUpDownButton(leftEndLine.children[0], "down");
6540
+ leftTable.tBodies[0].appendChild(leftEndLine);
6541
+ rightTable.tBodies[0].appendChild(rightEndLint);
6542
+ };
6543
+ const processLineByLine = () => {
6544
+ var _a;
6545
+ const trNodes = Array.from(reviewContentRef.value.querySelectorAll("tr"));
6546
+ const totalLines = trNodes.length;
6547
+ for (const index2 in trNodes) {
6548
+ const lineIndex = parseInt(index2);
6549
+ const tdNodes = Array.from(trNodes[lineIndex].children);
6550
+ const lineNumberBox = tdNodes[0];
6551
+ const lineContentBox = tdNodes[1];
6552
+ if (!lineContentBox) {
6553
+ continue;
6554
+ }
6555
+ const lineClassList = lineContentBox.classList.value;
6556
+ const lineContent = lineContentBox.innerText.trim();
6557
+ if (lineContent.match(ExpandLineReg) && !FirstLineReg.test(lineContent) && lineClassList && lineClassList.includes("d2h-info")) {
6558
+ const nextLineIndex = lineIndex + 1;
6559
+ const prevLineIndex = lineIndex - 1;
6560
+ if (lineIndex === 0 && nextLineIndex in trNodes) {
6561
+ updateLineNumberInDataset(trNodes[lineIndex], expandAllThreshold.value, "top");
6562
+ attachExpandUpDownButton(lineNumberBox, "up");
6563
+ } else if (lineIndex > 0 && lineIndex < totalLines - 1 && nextLineIndex in trNodes && prevLineIndex in trNodes) {
6564
+ const prevTdNodes = Array.from(trNodes[prevLineIndex].children);
6565
+ const prevLineNumber = parseInt(prevTdNodes[0].children[0].innerText);
6566
+ const nextTdNodes = Array.from(trNodes[nextLineIndex].children);
6567
+ const nextLineNumber = parseInt(nextTdNodes[0].children[0].innerText);
6568
+ updateLineNumberInDataset(trNodes[lineIndex], expandAllThreshold.value, "middle");
6569
+ const isExpandAll = nextLineNumber - prevLineNumber <= expandAllThreshold.value;
6570
+ attachExpandUpDownButton(lineNumberBox, isExpandAll ? "all" : "updown");
6571
+ }
6572
+ }
6573
+ }
6574
+ const loadMoreLine = trNodes[0].cloneNode(true);
6575
+ loadMoreLine.children[0].removeChild(loadMoreLine.children[0].children[0]);
6576
+ loadMoreLine.children[1].innerText = "";
6577
+ (_a = trNodes[0].parentElement) == null ? void 0 : _a.appendChild(loadMoreLine);
6578
+ updateLineNumberInDataset(loadMoreLine, expandAllThreshold.value, "bottom");
6579
+ attachExpandUpDownButton(loadMoreLine.children[0], "down");
6580
+ };
6581
+ const insertIncrementCode = (code, direction, referenceDom) => {
6582
+ if (!referenceDom) {
6583
+ return;
6584
+ }
6585
+ if (!code) {
6586
+ return referenceDom == null ? void 0 : referenceDom.remove();
6587
+ }
6588
+ const prefix = "--- updated_at Jan 1, 2019, 0:0:0 AM\n+++ updated_at Jan 1, 2019, 0:0:0 AM\n";
6589
+ const container = document.createElement("div");
6590
+ parseDiffCode(container, prefix + code, outputFormat.value);
6591
+ const trNodes = Array.from(container.querySelectorAll("tr"));
6592
+ const expandLine = trNodes.find((element) => {
6593
+ var _a;
6594
+ return (_a = element.children[1]) == null ? void 0 : _a.innerText.trim().match(ExpandLineReg);
6595
+ });
6596
+ if (!expandLine) {
6597
+ return;
6598
+ }
6599
+ insertIncrementLineToPage(referenceDom, trNodes, direction);
6600
+ const removedExpandLine = ifRemoveExpandLine(referenceDom, expandLine, direction);
6601
+ if (removedExpandLine) {
6602
+ return;
6603
+ }
6604
+ updateExpandLineCount(referenceDom, expandLine);
6605
+ if (direction === "up") {
6606
+ if (!referenceDom.previousElementSibling) {
6607
+ updateLineNumberInDataset(referenceDom, expandAllThreshold.value, "top");
6608
+ } else {
6609
+ updateLineNumberInDataset(referenceDom, expandAllThreshold.value, "middle", true);
6610
+ }
6611
+ } else {
6612
+ if (referenceDom.nextElementSibling) {
6613
+ updateLineNumberInDataset(referenceDom, expandAllThreshold.value, "middle", true);
6614
+ } else {
6615
+ updateLineNumberInDataset(referenceDom, expandAllThreshold.value, "bottom");
6616
+ }
6617
+ }
6618
+ };
6619
+ const onExpandButtonClick = (e) => {
6620
+ var _a, _b;
6621
+ const composedPath = e.composedPath();
6622
+ const expandIconDom = composedPath.find((element) => {
6623
+ var _a2;
6624
+ return (_a2 = element.classList) == null ? void 0 : _a2.contains("expand-icon");
6625
+ });
6626
+ if (expandIconDom) {
6627
+ const expandDirection = (_a = Array.from(expandIconDom.classList).find((item) => item.endsWith("expand"))) == null ? void 0 : _a.split("-")[0];
6628
+ const direction = expandDirection === "up" || expandDirection === "all" ? "up" : "down";
6629
+ const [leftLineStart, leftLineEnd, rightLineStart, rightLineEnd] = getLineNumberFormDataset(expandIconDom, expandAllThreshold.value);
6630
+ (_b = codeLoader == null ? void 0 : codeLoader.value) == null ? void 0 : _b.call(codeLoader, [leftLineStart, leftLineEnd, rightLineStart, rightLineEnd], (code) => {
6631
+ var _a2;
6632
+ insertIncrementCode(code, direction, (_a2 = expandIconDom.parentElement) == null ? void 0 : _a2.parentElement);
6633
+ });
6634
+ }
6635
+ };
6636
+ const insertExpandButton = () => {
6637
+ outputFormat.value === "side-by-side" ? processSideBySide() : processLineByLine();
6638
+ };
6639
+ return { insertExpandButton, onExpandButtonClick };
6640
+ }
6211
6641
  function useCodeReview(props, ctx) {
6212
- const { diff, fold, outputFormat } = toRefs(props);
6642
+ const { diff, outputFormat } = toRefs(props);
6213
6643
  const renderHtml = ref("");
6214
- const isFold = ref(fold.value);
6215
- const diffFile = Diff2Html.parse(diff.value);
6644
+ const reviewContentRef = ref();
6645
+ const diffFile = ref([]);
6646
+ const { insertExpandButton, onExpandButtonClick } = useCodeReviewExpand(reviewContentRef, props);
6216
6647
  const initDiffContent = () => {
6217
- renderHtml.value = Diff2Html.html(diffFile, {
6218
- drawFileList: false,
6219
- matching: "lines",
6220
- outputFormat: outputFormat.value
6648
+ diffFile.value = Diff2Html.parse(diff.value);
6649
+ nextTick(() => {
6650
+ parseDiffCode(reviewContentRef.value, diff.value, outputFormat.value);
6651
+ insertExpandButton();
6652
+ ctx.emit("contentRefresh", JSON.parse(JSON.stringify(diffFile.value)));
6221
6653
  });
6222
6654
  };
6655
+ const onContentClick = (e) => {
6656
+ onExpandButtonClick(e);
6657
+ };
6658
+ watch(diff, initDiffContent, { immediate: true });
6659
+ return { renderHtml, reviewContentRef, diffFile, onContentClick };
6660
+ }
6661
+ function useCodeReviewFold(props, ctx) {
6662
+ const { fold } = toRefs(props);
6663
+ const isFold = ref(fold.value);
6223
6664
  const toggleFold = (status) => {
6224
6665
  if (status !== void 0) {
6225
6666
  isFold.value = status;
@@ -6231,31 +6672,145 @@ function useCodeReview(props, ctx) {
6231
6672
  isFold.value = val;
6232
6673
  });
6233
6674
  watch(isFold, () => {
6234
- if (!isFold.value && renderHtml.value === "") {
6235
- initDiffContent();
6236
- }
6237
6675
  ctx.emit("foldChange", isFold.value);
6238
6676
  });
6239
- onBeforeMount(() => {
6240
- if (!isFold.value) {
6241
- initDiffContent();
6677
+ return { isFold, toggleFold };
6678
+ }
6679
+ function useCodeReviewComment(reviewContentRef, ctx) {
6680
+ const ns2 = useNamespace("code-review");
6681
+ const commentLeft = ref(-100);
6682
+ const commentTop = ref(-100);
6683
+ let currentLeftLineNumber = -1;
6684
+ let currentRightLineNumber = -1;
6685
+ const resetLeftTop = () => {
6686
+ commentLeft.value = -100;
6687
+ commentTop.value = -100;
6688
+ currentLeftLineNumber = -1;
6689
+ currentRightLineNumber = -1;
6690
+ };
6691
+ const onMouseEnter = (e) => {
6692
+ e.currentTarget.getBoundingClientRect();
6693
+ };
6694
+ const onMouseMove = (e) => {
6695
+ var _a, _b;
6696
+ const composedPath = e.composedPath();
6697
+ const trNode = composedPath.find((item) => item.tagName === "TR");
6698
+ if (trNode) {
6699
+ const lineNumberContainer = Array.from(trNode.children)[0];
6700
+ if (notEmptyNode(lineNumberContainer)) {
6701
+ const { top, left } = lineNumberContainer.getBoundingClientRect();
6702
+ commentLeft.value = left;
6703
+ commentTop.value = top;
6704
+ currentLeftLineNumber = parseInt((_a = lineNumberContainer.children[0]) == null ? void 0 : _a.innerText) || -1;
6705
+ currentRightLineNumber = parseInt((_b = lineNumberContainer.children[1]) == null ? void 0 : _b.innerText) || -1;
6706
+ } else {
6707
+ resetLeftTop();
6708
+ }
6709
+ }
6710
+ };
6711
+ const onMouseleave = (e) => {
6712
+ var _a;
6713
+ if (!((_a = e.relatedTarget) == null ? void 0 : _a.classList.contains("comment-icon"))) {
6714
+ resetLeftTop();
6715
+ }
6716
+ };
6717
+ const onCommentMouseLeave = (e) => {
6718
+ var _a;
6719
+ if (!((_a = e.relatedTarget) == null ? void 0 : _a.classList.contains(ns2.e("content")))) {
6720
+ resetLeftTop();
6721
+ }
6722
+ };
6723
+ const onCommentIconClick = () => {
6724
+ ctx.emit("addComment", { left: currentLeftLineNumber, right: currentRightLineNumber });
6725
+ };
6726
+ const findReferenceDom = (lineNumber, lineSide) => {
6727
+ var _a, _b, _c, _d;
6728
+ const trNodes = Array.from(reviewContentRef.value.querySelectorAll("tr"));
6729
+ for (const index2 in trNodes) {
6730
+ const lineIndex = parseInt(index2);
6731
+ const lineNumberBox = Array.from(trNodes[lineIndex].children)[0];
6732
+ if (notEmptyNode(lineNumberBox)) {
6733
+ const oldLineNumber = parseInt((_b = (_a = lineNumberBox.children[0]) == null ? void 0 : _a.innerText) != null ? _b : -1);
6734
+ const newLineNumber = parseInt((_d = (_c = lineNumberBox.children[1]) == null ? void 0 : _c.innerText) != null ? _d : -1);
6735
+ if (lineSide === "left" && oldLineNumber === lineNumber || lineSide === "right" && newLineNumber === lineNumber) {
6736
+ return trNodes[lineIndex];
6737
+ }
6738
+ }
6739
+ }
6740
+ };
6741
+ const insertComment = (lineNumber, lineSide, commentDom) => {
6742
+ const lineHost = findReferenceDom(lineNumber, lineSide);
6743
+ lineHost && addCommentToPage(lineHost, commentDom, lineSide);
6744
+ };
6745
+ const removeComment = (lineNumber, lineSide) => {
6746
+ const lineHost = findReferenceDom(lineNumber, lineSide);
6747
+ let nextLineHost = lineHost == null ? void 0 : lineHost.nextElementSibling;
6748
+ while (nextLineHost) {
6749
+ const classList = nextLineHost == null ? void 0 : nextLineHost.classList;
6750
+ if ((classList == null ? void 0 : classList.contains("comment-block")) && classList.contains(lineSide)) {
6751
+ nextLineHost.remove();
6752
+ return;
6753
+ }
6754
+ nextLineHost = nextLineHost.nextElementSibling;
6242
6755
  }
6756
+ };
6757
+ window.addEventListener("scroll", resetLeftTop);
6758
+ onUnmounted(() => {
6759
+ window.removeEventListener("scroll", resetLeftTop);
6243
6760
  });
6244
- provide(CodeReviewInjectionKey, { diffInfo: diffFile[0], isFold, rootCtx: ctx });
6245
- ctx.expose({ toggleFold });
6246
- return { renderHtml, isFold };
6761
+ return {
6762
+ commentLeft,
6763
+ commentTop,
6764
+ onMouseEnter,
6765
+ onMouseMove,
6766
+ onMouseleave,
6767
+ onCommentMouseLeave,
6768
+ onCommentIconClick,
6769
+ insertComment,
6770
+ removeComment
6771
+ };
6247
6772
  }
6248
6773
  var codeReview = "";
6249
6774
  var CodeReview = defineComponent({
6250
6775
  name: "DCodeReview",
6251
6776
  props: codeReviewProps,
6252
- emits: ["foldChange"],
6777
+ emits: ["foldChange", "addComment", "afterViewInit", "contentRefresh"],
6253
6778
  setup(props, ctx) {
6254
6779
  const ns2 = useNamespace("code-review");
6255
6780
  const {
6256
6781
  renderHtml,
6257
- isFold
6782
+ reviewContentRef,
6783
+ diffFile,
6784
+ onContentClick
6258
6785
  } = useCodeReview(props, ctx);
6786
+ const {
6787
+ isFold,
6788
+ toggleFold
6789
+ } = useCodeReviewFold(props, ctx);
6790
+ const {
6791
+ commentLeft,
6792
+ commentTop,
6793
+ onMouseEnter,
6794
+ onMouseMove,
6795
+ onMouseleave,
6796
+ onCommentMouseLeave,
6797
+ onCommentIconClick,
6798
+ insertComment,
6799
+ removeComment
6800
+ } = useCodeReviewComment(reviewContentRef, ctx);
6801
+ onMounted(() => {
6802
+ ctx.emit("afterViewInit", {
6803
+ toggleFold,
6804
+ insertComment,
6805
+ removeComment
6806
+ });
6807
+ });
6808
+ provide(CodeReviewInjectionKey, {
6809
+ reviewContentRef,
6810
+ diffInfo: diffFile.value[0],
6811
+ isFold,
6812
+ rootCtx: ctx
6813
+ });
6259
6814
  return () => createVNode("div", {
6260
6815
  "class": ns2.b()
6261
6816
  }, [createVNode(CodeReviewHeader, {
@@ -6264,8 +6819,21 @@ var CodeReview = defineComponent({
6264
6819
  "class": [ns2.e("content"), {
6265
6820
  "hide-content": isFold.value
6266
6821
  }],
6267
- "innerHTML": renderHtml.value
6268
- }, null)]);
6822
+ "innerHTML": renderHtml.value,
6823
+ "ref": reviewContentRef,
6824
+ "onClick": onContentClick,
6825
+ "onMouseenter": onMouseEnter,
6826
+ "onMousemove": onMouseMove,
6827
+ "onMouseleave": onMouseleave
6828
+ }, null), createVNode("div", {
6829
+ "class": "comment-icon",
6830
+ "style": {
6831
+ left: commentLeft.value + "px",
6832
+ top: commentTop.value + "px"
6833
+ },
6834
+ "onClick": onCommentIconClick,
6835
+ "onMouseleave": onCommentMouseLeave
6836
+ }, [createVNode(CommentIcon, null, null)])]);
6269
6837
  }
6270
6838
  });
6271
6839
  var index = {