vue-devui 1.6.30 → 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.
@@ -4,5 +4,6 @@ import type { CodeReviewProps, IExpandLineNumberInfo } from '../code-review-type
4
4
  export declare function useCodeReview(props: CodeReviewProps, ctx: SetupContext, reviewContentRef: Ref<HTMLElement>, updateLineNumberMap: (expandLineNumberInfo: IExpandLineNumberInfo, newCode: string, direction: 'up' | 'down') => void, updateCheckedLine: (expandLineNumberInfo: IExpandLineNumberInfo, direction: 'up' | 'down') => void): {
5
5
  renderHtml: Ref<string>;
6
6
  diffFile: Ref<DiffFile[]>;
7
+ selectionSide: Ref<string>;
7
8
  onContentClick: (e: Event) => void;
8
9
  };
@@ -41,3 +41,4 @@ export declare function getSingleCheckedNumberAndCode(checkedTdNodes: HTMLElemen
41
41
  };
42
42
  export declare function addCommentCheckedForDouble(trNode: HTMLElement, leftMinNum: number, leftMaxNum: number, rightMinNum: number, rightMaxNum: number): HTMLElement[];
43
43
  export declare function addCommentCheckedForSingle(trNode: HTMLElement, leftMinNum: number, leftMaxNum: number, rightMinNum: number, rightMaxNum: number): HTMLElement[];
44
+ export declare function getSelectionParent(el: HTMLElement): any;
package/vue-devui.es.js CHANGED
@@ -17664,6 +17664,22 @@ function addCommentCheckedForSingle(trNode, leftMinNum, leftMaxNum, rightMinNum,
17664
17664
  }
17665
17665
  return result2;
17666
17666
  }
17667
+ function getSelectionParent(el) {
17668
+ if (el.tagName === "TR") {
17669
+ return;
17670
+ }
17671
+ if (el.tagName === "TD" && (el.classList.contains("d-code-left") || el.classList.contains("d-code-right"))) {
17672
+ if (el.classList.contains("d-code-left")) {
17673
+ return "left";
17674
+ }
17675
+ if (el.classList.contains("d-code-right")) {
17676
+ return "right";
17677
+ }
17678
+ }
17679
+ if (el.parentElement) {
17680
+ return getSelectionParent(el.parentElement);
17681
+ }
17682
+ }
17667
17683
  function useCodeReviewExpand(reviewContentRef, props, updateLineNumberMap, updateCheckedLine) {
17668
17684
  const { outputFormat, expandThreshold, expandLoader } = toRefs(props);
17669
17685
  const processSideBySide = () => {
@@ -17856,6 +17872,8 @@ function useCodeReview(props, ctx2, reviewContentRef, updateLineNumberMap, updat
17856
17872
  const { diff, outputFormat, allowExpand, showBlob } = toRefs(props);
17857
17873
  const renderHtml = ref("");
17858
17874
  const diffFile = ref([]);
17875
+ const ns2 = useNamespace$1("code-review");
17876
+ const selectionSide = ref("");
17859
17877
  const { insertExpandButton, onExpandButtonClick } = useCodeReviewExpand(reviewContentRef, props, updateLineNumberMap, updateCheckedLine);
17860
17878
  const initDiffContent = () => {
17861
17879
  diffFile.value = Diff2Html.parse(diff.value);
@@ -17870,10 +17888,69 @@ function useCodeReview(props, ctx2, reviewContentRef, updateLineNumberMap, updat
17870
17888
  const onContentClick = (e) => {
17871
17889
  onExpandButtonClick(e, props.options);
17872
17890
  };
17891
+ function onSelectionChange() {
17892
+ if (selectionSide.value) {
17893
+ return;
17894
+ }
17895
+ if (typeof window === "undefined") {
17896
+ return;
17897
+ }
17898
+ const selection = window.getSelection();
17899
+ if ((selection == null ? void 0 : selection.toString()) && (selection == null ? void 0 : selection.anchorNode)) {
17900
+ const side = getSelectionParent(selection.anchorNode);
17901
+ if (side) {
17902
+ selectionSide.value = side;
17903
+ }
17904
+ }
17905
+ }
17906
+ function onMousedown2(e) {
17907
+ if (typeof window === "undefined") {
17908
+ return;
17909
+ }
17910
+ const selection = window.getSelection();
17911
+ const composedPath = e.composedPath();
17912
+ const isLineNumber = composedPath.some((item) => {
17913
+ var _a;
17914
+ return (_a = item.classList) == null ? void 0 : _a.contains("d2h-code-side-linenumber");
17915
+ });
17916
+ const isClickInner = composedPath.some((item) => {
17917
+ var _a;
17918
+ return (_a = item.classList) == null ? void 0 : _a.contains(ns2.e("content"));
17919
+ });
17920
+ const clickSide = getSelectionParent(e.target);
17921
+ if (selection && selection.toString()) {
17922
+ const isInRange = selection == null ? void 0 : selection.getRangeAt(0).intersectsNode(e.target);
17923
+ if (!isInRange || !isClickInner || clickSide === "left" && selectionSide.value === "right" || clickSide === "right" && selectionSide.value === "left" || isLineNumber) {
17924
+ setTimeout(() => {
17925
+ selectionSide.value = "";
17926
+ selection.removeAllRanges();
17927
+ });
17928
+ }
17929
+ } else {
17930
+ selectionSide.value = "";
17931
+ }
17932
+ }
17873
17933
  watch(showBlob, initDiffContent);
17874
17934
  watch(outputFormat, initDiffContent);
17875
17935
  watch(diff, initDiffContent, { immediate: true });
17876
- return { renderHtml, diffFile, onContentClick };
17936
+ watch(
17937
+ () => props.outputFormat,
17938
+ (val) => {
17939
+ if (val === "side-by-side") {
17940
+ document.addEventListener("selectionchange", onSelectionChange);
17941
+ document.addEventListener("mousedown", onMousedown2, true);
17942
+ } else {
17943
+ document.removeEventListener("selectionchange", onSelectionChange);
17944
+ document.removeEventListener("mousedown", onMousedown2, true);
17945
+ }
17946
+ },
17947
+ { immediate: true }
17948
+ );
17949
+ onUnmounted(() => {
17950
+ document.removeEventListener("selectionchange", onSelectionChange);
17951
+ document.removeEventListener("mousedown", onMousedown2, true);
17952
+ });
17953
+ return { renderHtml, diffFile, selectionSide, onContentClick };
17877
17954
  }
17878
17955
  function useCodeReviewFold(props, ctx2) {
17879
17956
  const { fold } = toRefs(props);
@@ -18341,6 +18418,7 @@ var CodeReview = defineComponent({
18341
18418
  const {
18342
18419
  renderHtml,
18343
18420
  diffFile,
18421
+ selectionSide,
18344
18422
  onContentClick
18345
18423
  } = useCodeReview(props, ctx2, reviewContentRef, updateLineNumberMap, updateCheckedLine);
18346
18424
  const {
@@ -18365,7 +18443,9 @@ var CodeReview = defineComponent({
18365
18443
  return () => {
18366
18444
  var _a, _b;
18367
18445
  return createVNode("div", {
18368
- "class": ns2.b()
18446
+ "class": [ns2.b(), {
18447
+ [ns2.m(`${selectionSide.value}-selected`)]: Boolean(selectionSide.value)
18448
+ }]
18369
18449
  }, [createVNode(CodeReviewHeader, {
18370
18450
  "onClick": () => isFold.value = !isFold.value
18371
18451
  }, null), withDirectives(createVNode("div", null, [props.showBlob ? (_b = (_a = ctx2.slots).blob) == null ? void 0 : _b.call(_a) : createVNode("div", mergeProps({
@@ -54454,7 +54534,7 @@ const installs = [
54454
54534
  VirtualListInstall
54455
54535
  ];
54456
54536
  var vueDevui = {
54457
- version: "1.6.30",
54537
+ version: "1.6.31",
54458
54538
  install(app) {
54459
54539
  installs.forEach((p) => app.use(p));
54460
54540
  }