3030 </section >
3131</template >
3232
33- <script >
33+ <script lang="ts">
34+ import Vue from ' vue'
3435import PrevDiff from ' ./buttons/prevDiff.vue'
3536import ToggleInSync from ' ./buttons/toggleInSync.vue'
3637import NextDiff from ' ./buttons/nextDiff.vue'
3738import CopyLink from ' ./buttons/copyLink.vue'
3839import { putToClipboard } from ' ~/helpers/utils'
39- export default {
40+ import { DiffActionBarData } from ' ~/helpers/types'
41+ export default Vue .extend ({
4042 components: { PrevDiff , NextDiff , ToggleInSync , CopyLink },
41- data () {
43+ data(): DiffActionBarData {
4244 return {
43- copied: this .copied ,
45+ copied: false ,
46+ comparator: null ,
47+ comparer: null ,
48+ treeWalker: null ,
4449 }
4550 },
46- beforeCreate () {
47- this .copied = false
48- },
4951 mounted() {
5052 const lhsDiffNode = document .getElementById (' lhsDiff' )
5153 const rhsDiffNode = document .getElementById (' rhsDiff' )
@@ -65,11 +67,14 @@ export default {
6567 comparer ,
6668 NodeFilter .SHOW_ELEMENT ,
6769 {
68- acceptNode : (node ) => {
69- return (
70- node .classList .contains (' bg-red-200' ) ||
71- node .classList .contains (' bg-green-200' )
72- )
70+ acceptNode : (node : Node ) => {
71+ if (
72+ (node as HTMLDivElement ).classList .contains (' bg-red-200' ) ||
73+ (node as HTMLDivElement ).classList .contains (' bg-green-200' )
74+ ) {
75+ return NodeFilter .FILTER_ACCEPT
76+ }
77+ return NodeFilter .FILTER_REJECT
7378 },
7479 }
7580 )
@@ -91,56 +96,67 @@ export default {
9196 this .$store .commit (' scrollInSync/toggle' )
9297 },
9398 goToNextDiff() {
94- const currentNode = this .treeWalker .currentNode
95- const nextNode = this .treeWalker .nextNode ()
99+ const currentNode = this .treeWalker ? .currentNode
100+ const nextNode = this .treeWalker ? .nextNode ()
96101 if (nextNode ) {
97102 const currentNodeIndex = Array .prototype .indexOf .call (
98- currentNode .parentElement .children ,
103+ currentNode ? .parentElement ? .children ,
99104 currentNode
100105 )
101106 const nextNodeIndex = Array .prototype .indexOf .call (
102- nextNode .parentElement .children ,
107+ nextNode .parentElement ? .children ,
103108 nextNode
104109 )
105- const comparatorCurrentNode = this .comparator .children [currentNodeIndex]
106- const comparatorNextNode = this .comparator .children [nextNodeIndex]
110+ const comparatorCurrentNode =
111+ this .comparator ?.children [currentNodeIndex ]
112+ const comparatorNextNode = this .comparator ?.children [nextNodeIndex ]
107113 this .toggleDiffHunkAndScrollIntoView (
108- [currentNode, comparatorCurrentNode],
109- [nextNode, comparatorNextNode]
114+ [
115+ currentNode as HTMLDivElement ,
116+ comparatorCurrentNode as HTMLDivElement ,
117+ ],
118+ [nextNode as HTMLDivElement , comparatorNextNode as HTMLDivElement ]
110119 )
111120 }
112121 },
113122 goToPreviousDiff() {
114- const currentNode = this .treeWalker .currentNode
115- const prevNode = this .treeWalker .previousNode ()
123+ const currentNode = this .treeWalker ? .currentNode
124+ const prevNode = this .treeWalker ? .previousNode ()
116125 if (prevNode ) {
117126 const currentNodeIndex = Array .prototype .indexOf .call (
118- currentNode .parentElement .children ,
127+ currentNode ? .parentElement ? .children ,
119128 currentNode
120129 )
121130 const prevNodeIndex = Array .prototype .indexOf .call (
122- prevNode .parentElement .children ,
131+ prevNode .parentElement ? .children ,
123132 prevNode
124133 )
125- const comparatorCurrentNode = this .comparator .children [currentNodeIndex]
126- const comparatorPrevNode = this .comparator .children [prevNodeIndex]
134+ const comparatorCurrentNode =
135+ this .comparator ?.children [currentNodeIndex ]
136+ const comparatorPrevNode = this .comparator ?.children [prevNodeIndex ]
127137 this .toggleDiffHunkAndScrollIntoView (
128- [currentNode, comparatorCurrentNode],
129- [prevNode, comparatorPrevNode]
138+ [
139+ currentNode as HTMLDivElement ,
140+ comparatorCurrentNode as HTMLDivElement ,
141+ ],
142+ [prevNode as HTMLDivElement , comparatorPrevNode as HTMLDivElement ]
130143 )
131144 }
132145 },
133- toggleDiffHunkAndScrollIntoView (unselectedNodes , selectedNodes ) {
146+ toggleDiffHunkAndScrollIntoView(
147+ unselectedNodes : Array <HTMLDivElement | undefined > = [],
148+ selectedNodes : Array <HTMLDivElement | undefined > = []
149+ ) {
134150 unselectedNodes .forEach ((element ) => {
135- element .querySelector (' p' ).classList .remove (' selected' )
151+ element ? .querySelector (' p' )? .classList .remove (' selected' )
136152 })
137153 selectedNodes .forEach ((element ) => {
138- element .querySelector (' p' ).classList .add (' selected' )
139- element .scrollIntoView ()
154+ element ? .querySelector (' p' )? .classList .add (' selected' )
155+ element ? .scrollIntoView ()
140156 })
141157 },
142158 },
143- }
159+ })
144160 </script >
145161<style lang="scss">
146162.copy-uri-button :hover svg {
0 commit comments