11<script setup>
2- import VueDiff from ' vue-diff' ;
3- import ' vue-diff/dist/index.css' ;
4- import { app } from ' @/main' ;
52import { useCoreStore } from ' @/stores/core' ;
6- import { computed } from ' vue' ;
7- app .use (VueDiff);
3+ import { computed , ref , watch } from ' vue' ;
4+ import " @git-diff-view/vue/styles/diff-view.css" ;
5+ import { DiffView , DiffModeEnum } from " @git-diff-view/vue" ;
6+ import { generateDiffFile } from " @git-diff-view/file" ;
87
98const props = defineProps ([' column' , ' record' , ' meta' , ' resource' , ' adminUser' ]);
109const coreStore = useCoreStore ();
11- const theme = computed (() => coreStore .theme );;
12- const isMobile = computed (() => navigator .userAgent .match (/ Android/ i ) || navigator .userAgent .match (/ iPhone| iPad| iPod/ i ));
10+ const theme = computed (() => coreStore .theme );
11+ const isMobile = computed (() => / (Android| iPhone| iPad| iPod)/ i .test (navigator .userAgent ));
12+ const mode = computed (() => isMobile .value ? DiffModeEnum .Unified : DiffModeEnum .Split );
13+
14+ const oldContent = JSON .stringify (props .record [props .meta .resourceColumns .resourceDataColumnName ].oldRecord , null , 2 )
15+ const newContent = JSON .stringify (props .record [props .meta .resourceColumns .resourceDataColumnName ].newRecord , null , 2 )
16+
17+ const diffFile = ref ();
18+
19+ function initDiffFile () {
20+ const file = generateDiffFile (
21+ ' diff.json' ,
22+ oldContent,
23+ ' diff.json' ,
24+ newContent,
25+ ' json' ,
26+ ' json'
27+ );
28+ file .initTheme (theme .value === ' dark' ? ' dark' : ' light' );
29+ file .init ();
30+ if (mode .value === DiffModeEnum .Split ) {
31+ file .buildSplitDiffLines ();
32+ } else {
33+ file .buildUnifiedDiffLines ();
34+ }
35+ diffFile .value = file;
36+ }
37+
38+ initDiffFile ();
39+
40+ watch ([mode, theme], ([m , t ]) => {
41+ if (! diffFile .value ) return ;
42+ diffFile .value .initTheme (t === ' dark' ? ' dark' : ' light' );
43+ if (m === DiffModeEnum .Split ) {
44+ diffFile .value .buildSplitDiffLines ();
45+ } else {
46+ diffFile .value .buildUnifiedDiffLines ();
47+ }
48+ });
1349
1450 </script >
1551
1652<template >
17- <Diff
18- :mode =" isMobile ? 'unified' : 'split'"
19- :theme =" theme"
20- :language =" 'JSON'"
21- :prev =" JSON.stringify(props.record[props.meta.resourceColumns.resourceDataColumnName].oldRecord, null, 2)"
22- :current =" JSON.stringify(props.record[props.meta.resourceColumns.resourceDataColumnName].newRecord, null, 2)"
23- />
53+ <DiffView
54+ :diff-file =" diffFile"
55+ :diff-view-mode =" mode"
56+ :diff-view-theme =" theme === 'dark' ? 'dark' : 'light'"
57+ :diff-view-highlight =" true"
58+ :diff-view-wrap =" true"
59+ :diff-view-font-size =" 14"
60+ />
2461</template >
2562
0 commit comments