vue-devui 1.6.29 → 1.6.31

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.
@@ -1597,7 +1597,7 @@ var lodash = { exports: {} };
1597
1597
  if (typeof func != "function") {
1598
1598
  throw new TypeError(FUNC_ERROR_TEXT);
1599
1599
  }
1600
- return setTimeout(function() {
1600
+ return setTimeout2(function() {
1601
1601
  func.apply(undefined$1, args);
1602
1602
  }, wait);
1603
1603
  }
@@ -3428,7 +3428,7 @@ var lodash = { exports: {} };
3428
3428
  return object[key];
3429
3429
  }
3430
3430
  var setData = shortOut(baseSetData);
3431
- var setTimeout = ctxSetTimeout || function(func, wait) {
3431
+ var setTimeout2 = ctxSetTimeout || function(func, wait) {
3432
3432
  return root.setTimeout(func, wait);
3433
3433
  };
3434
3434
  var setToString = shortOut(baseSetToString);
@@ -4220,7 +4220,7 @@ var lodash = { exports: {} };
4220
4220
  }
4221
4221
  function leadingEdge(time) {
4222
4222
  lastInvokeTime = time;
4223
- timerId = setTimeout(timerExpired, wait);
4223
+ timerId = setTimeout2(timerExpired, wait);
4224
4224
  return leading ? invokeFunc(time) : result2;
4225
4225
  }
4226
4226
  function remainingWait(time) {
@@ -4236,7 +4236,7 @@ var lodash = { exports: {} };
4236
4236
  if (shouldInvoke(time)) {
4237
4237
  return trailingEdge(time);
4238
4238
  }
4239
- timerId = setTimeout(timerExpired, remainingWait(time));
4239
+ timerId = setTimeout2(timerExpired, remainingWait(time));
4240
4240
  }
4241
4241
  function trailingEdge(time) {
4242
4242
  timerId = undefined$1;
@@ -4267,12 +4267,12 @@ var lodash = { exports: {} };
4267
4267
  }
4268
4268
  if (maxing) {
4269
4269
  clearTimeout(timerId);
4270
- timerId = setTimeout(timerExpired, wait);
4270
+ timerId = setTimeout2(timerExpired, wait);
4271
4271
  return invokeFunc(lastCallTime);
4272
4272
  }
4273
4273
  }
4274
4274
  if (timerId === undefined$1) {
4275
- timerId = setTimeout(timerExpired, wait);
4275
+ timerId = setTimeout2(timerExpired, wait);
4276
4276
  }
4277
4277
  return result2;
4278
4278
  }
@@ -6954,6 +6954,22 @@ function addCommentCheckedForSingle(trNode, leftMinNum, leftMaxNum, rightMinNum,
6954
6954
  }
6955
6955
  return result;
6956
6956
  }
6957
+ function getSelectionParent(el) {
6958
+ if (el.tagName === "TR") {
6959
+ return;
6960
+ }
6961
+ if (el.tagName === "TD" && (el.classList.contains("d-code-left") || el.classList.contains("d-code-right"))) {
6962
+ if (el.classList.contains("d-code-left")) {
6963
+ return "left";
6964
+ }
6965
+ if (el.classList.contains("d-code-right")) {
6966
+ return "right";
6967
+ }
6968
+ }
6969
+ if (el.parentElement) {
6970
+ return getSelectionParent(el.parentElement);
6971
+ }
6972
+ }
6957
6973
  function useCodeReviewExpand(reviewContentRef, props, updateLineNumberMap, updateCheckedLine) {
6958
6974
  const { outputFormat, expandThreshold, expandLoader } = toRefs(props);
6959
6975
  const processSideBySide = () => {
@@ -7146,6 +7162,8 @@ function useCodeReview(props, ctx, reviewContentRef, updateLineNumberMap, update
7146
7162
  const { diff, outputFormat, allowExpand, showBlob } = toRefs(props);
7147
7163
  const renderHtml = ref("");
7148
7164
  const diffFile = ref([]);
7165
+ const ns2 = useNamespace("code-review");
7166
+ const selectionSide = ref("");
7149
7167
  const { insertExpandButton, onExpandButtonClick } = useCodeReviewExpand(reviewContentRef, props, updateLineNumberMap, updateCheckedLine);
7150
7168
  const initDiffContent = () => {
7151
7169
  diffFile.value = Diff2Html.parse(diff.value);
@@ -7160,10 +7178,69 @@ function useCodeReview(props, ctx, reviewContentRef, updateLineNumberMap, update
7160
7178
  const onContentClick = (e) => {
7161
7179
  onExpandButtonClick(e, props.options);
7162
7180
  };
7181
+ function onSelectionChange() {
7182
+ if (selectionSide.value) {
7183
+ return;
7184
+ }
7185
+ if (typeof window === "undefined") {
7186
+ return;
7187
+ }
7188
+ const selection = window.getSelection();
7189
+ if ((selection == null ? void 0 : selection.toString()) && (selection == null ? void 0 : selection.anchorNode)) {
7190
+ const side = getSelectionParent(selection.anchorNode);
7191
+ if (side) {
7192
+ selectionSide.value = side;
7193
+ }
7194
+ }
7195
+ }
7196
+ function onMousedown(e) {
7197
+ if (typeof window === "undefined") {
7198
+ return;
7199
+ }
7200
+ const selection = window.getSelection();
7201
+ const composedPath = e.composedPath();
7202
+ const isLineNumber = composedPath.some((item) => {
7203
+ var _a;
7204
+ return (_a = item.classList) == null ? void 0 : _a.contains("d2h-code-side-linenumber");
7205
+ });
7206
+ const isClickInner = composedPath.some((item) => {
7207
+ var _a;
7208
+ return (_a = item.classList) == null ? void 0 : _a.contains(ns2.e("content"));
7209
+ });
7210
+ const clickSide = getSelectionParent(e.target);
7211
+ if (selection && selection.toString()) {
7212
+ const isInRange = selection == null ? void 0 : selection.getRangeAt(0).intersectsNode(e.target);
7213
+ if (!isInRange || !isClickInner || clickSide === "left" && selectionSide.value === "right" || clickSide === "right" && selectionSide.value === "left" || isLineNumber) {
7214
+ setTimeout(() => {
7215
+ selectionSide.value = "";
7216
+ selection.removeAllRanges();
7217
+ });
7218
+ }
7219
+ } else {
7220
+ selectionSide.value = "";
7221
+ }
7222
+ }
7163
7223
  watch(showBlob, initDiffContent);
7164
7224
  watch(outputFormat, initDiffContent);
7165
7225
  watch(diff, initDiffContent, { immediate: true });
7166
- return { renderHtml, diffFile, onContentClick };
7226
+ watch(
7227
+ () => props.outputFormat,
7228
+ (val) => {
7229
+ if (val === "side-by-side") {
7230
+ document.addEventListener("selectionchange", onSelectionChange);
7231
+ document.addEventListener("mousedown", onMousedown, true);
7232
+ } else {
7233
+ document.removeEventListener("selectionchange", onSelectionChange);
7234
+ document.removeEventListener("mousedown", onMousedown, true);
7235
+ }
7236
+ },
7237
+ { immediate: true }
7238
+ );
7239
+ onUnmounted(() => {
7240
+ document.removeEventListener("selectionchange", onSelectionChange);
7241
+ document.removeEventListener("mousedown", onMousedown, true);
7242
+ });
7243
+ return { renderHtml, diffFile, selectionSide, onContentClick };
7167
7244
  }
7168
7245
  function useCodeReviewFold(props, ctx) {
7169
7246
  const { fold } = toRefs(props);
@@ -7631,6 +7708,7 @@ var CodeReview = defineComponent({
7631
7708
  const {
7632
7709
  renderHtml,
7633
7710
  diffFile,
7711
+ selectionSide,
7634
7712
  onContentClick
7635
7713
  } = useCodeReview(props, ctx, reviewContentRef, updateLineNumberMap, updateCheckedLine);
7636
7714
  const {
@@ -7655,7 +7733,9 @@ var CodeReview = defineComponent({
7655
7733
  return () => {
7656
7734
  var _a, _b;
7657
7735
  return createVNode("div", {
7658
- "class": ns2.b()
7736
+ "class": [ns2.b(), {
7737
+ [ns2.m(`${selectionSide.value}-selected`)]: Boolean(selectionSide.value)
7738
+ }]
7659
7739
  }, [createVNode(CodeReviewHeader, {
7660
7740
  "onClick": () => isFold.value = !isFold.value
7661
7741
  }, null), withDirectives(createVNode("div", null, [props.showBlob ? (_b = (_a = ctx.slots).blob) == null ? void 0 : _b.call(_a) : createVNode("div", mergeProps({