File tree Expand file tree Collapse file tree 2 files changed +18
-22
lines changed Expand file tree Collapse file tree 2 files changed +18
-22
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,10 @@ class ComponentStructure {
40
40
this . _checkCoherence ( ) ;
41
41
}
42
42
43
+ get _domChildrenFromNodes ( ) {
44
+ return this . _getChildrenNodes ( ) . map ( getHtmlElementFromNode ) ;
45
+ }
46
+
43
47
_checkCoherence ( ) {
44
48
if ( this . noneFunctional && this . transitionMode ) {
45
49
throw new Error (
@@ -48,7 +52,7 @@ class ComponentStructure {
48
52
}
49
53
}
50
54
51
- getChildrenNodes ( ) {
55
+ _getChildrenNodes ( ) {
52
56
const {
53
57
noneFunctional,
54
58
transitionMode,
@@ -77,19 +81,17 @@ class ComponentStructure {
77
81
78
82
computeIndexes ( ) {
79
83
const {
84
+ _domChildrenFromNodes,
80
85
transitionMode,
81
86
offsets : { footer : footerOffset }
82
87
} = this ;
83
88
84
- const domChildrenFromNodes = this . getChildrenNodes ( ) . map (
85
- getHtmlElementFromNode
86
- ) ;
87
89
const domChildren = this . rootContainer . children ;
88
90
const footerIndex = domChildren . length - footerOffset ;
89
91
const rawIndexes = [ ...domChildren ] . map ( ( elt , idx ) =>
90
92
idx >= footerIndex
91
- ? domChildrenFromNodes . length
92
- : domChildrenFromNodes . indexOf ( elt )
93
+ ? _domChildrenFromNodes . length
94
+ : _domChildrenFromNodes . indexOf ( elt )
93
95
) ;
94
96
return transitionMode ? rawIndexes . filter ( ind => ind !== - 1 ) : rawIndexes ;
95
97
}
@@ -102,6 +104,10 @@ class ComponentStructure {
102
104
this . rootContainer = getRootContainer ( this ) ;
103
105
return this ;
104
106
}
107
+
108
+ computeVmIndex ( htmlElement ) {
109
+ return this . _domChildrenFromNodes . indexOf ( htmlElement ) ;
110
+ }
105
111
}
106
112
107
113
export { ComponentStructure } ;
Original file line number Diff line number Diff line change @@ -9,18 +9,6 @@ import {
9
9
import { computeComponentStructure } from "./core/renderHelper" ;
10
10
import { h , defineComponent , nextTick } from "vue" ;
11
11
12
- function computeVmIndex ( vNodes , htmlElement ) {
13
- const domElements = vNodes . map ( ( { el } ) => el ) ;
14
- const index = domElements . indexOf ( htmlElement ) ;
15
- if ( index === - 1 ) {
16
- throw new Error ( "node not found" , {
17
- nodes : domElements ,
18
- htmlElement
19
- } ) ;
20
- }
21
- return index ;
22
- }
23
-
24
12
function emit ( evtName , evtData ) {
25
13
nextTick ( ( ) => this . $emit ( evtName . toLowerCase ( ) , evtData ) ) ;
26
14
}
@@ -136,8 +124,11 @@ const draggableComponent = defineComponent({
136
124
deep : true
137
125
} ,
138
126
139
- realList ( ) {
140
- this . computeIndexes ( ) ;
127
+ realList : {
128
+ handler ( ) {
129
+ this . computeIndexes ( ) ;
130
+ } ,
131
+ deep : true
141
132
}
142
133
} ,
143
134
@@ -156,8 +147,7 @@ const draggableComponent = defineComponent({
156
147
} ,
157
148
158
149
getUnderlyingVm ( htmlElement ) {
159
- const childrenNodes = this . componentStructure . getChildrenNodes ( ) ;
160
- const index = computeVmIndex ( childrenNodes , htmlElement ) ;
150
+ const index = this . componentStructure . computeVmIndex ( htmlElement ) ;
161
151
if ( index === - 1 ) {
162
152
//Edge case during move callback: related element might be
163
153
//an element different from collection
You can’t perform that action at this time.
0 commit comments