@@ -21,21 +21,6 @@ function computeVmIndex(vNodes, htmlElement) {
2121 return index ;
2222}
2323
24- function computeIndexes (
25- vNodes ,
26- domChildren ,
27- { transitionMode, offsets : { footer : footerOffset } }
28- ) {
29- const domChildrenFromNodes = vNodes . map ( ( { el } ) => el ) ;
30- const footerIndex = domChildren . length - footerOffset ;
31- const rawIndexes = [ ...domChildren ] . map ( ( elt , idx ) =>
32- idx >= footerIndex
33- ? domChildrenFromNodes . length
34- : domChildrenFromNodes . indexOf ( elt )
35- ) ;
36- return transitionMode ? rawIndexes . filter ( ind => ind !== - 1 ) : rawIndexes ;
37- }
38-
3924function emit ( evtName , evtData ) {
4025 nextTick ( ( ) => this . $emit ( evtName . toLowerCase ( ) , evtData ) ) ;
4126}
@@ -98,14 +83,10 @@ const draggableComponent = defineComponent({
9883 props,
9984
10085 render ( ) {
101- const { $slots, $attrs, tag, componentData } = this ;
102- const componentStructure = computeComponentStructure ( {
103- $slots,
104- tag
105- } ) . checkCoherence ( ) ;
86+ const { $slots, $attrs, tag, componentData, $el } = this ;
87+ const componentStructure = computeComponentStructure ( { $slots, tag, $el } ) ;
10688 this . componentStructure = componentStructure ;
10789 const attributes = getComponentAttributes ( { $attrs, componentData } ) ;
108-
10990 return h ( componentStructure . tag , attributes , componentStructure . children ) ;
11091 } ,
11192
@@ -118,7 +99,8 @@ const draggableComponent = defineComponent({
11899 } ,
119100
120101 mounted ( ) {
121- const { $attrs, rootContainer } = this ;
102+ const { $attrs, $el, componentStructure } = this ;
103+ componentStructure . setHtmlRoot ( $el ) ;
122104
123105 const sortableOptions = createSortableOption ( {
124106 $attrs,
@@ -128,7 +110,9 @@ const draggableComponent = defineComponent({
128110 manage : event => manage . call ( this , event )
129111 }
130112 } ) ;
131-
113+ const {
114+ componentStructure : { rootContainer }
115+ } = this ;
132116 this . _sortable = new Sortable ( rootContainer , sortableOptions ) ;
133117 rootContainer . __draggable_component__ = this ;
134118 this . computeIndexes ( ) ;
@@ -139,22 +123,6 @@ const draggableComponent = defineComponent({
139123 } ,
140124
141125 computed : {
142- rootContainer ( ) {
143- const {
144- $el,
145- componentStructure : { transitionMode }
146- } = this ;
147- if ( ! transitionMode ) {
148- return $el ;
149- }
150- const { children } = $el ;
151- if ( children . length !== 1 ) {
152- return $el ;
153- }
154- const firstChild = children . item ( 0 ) ;
155- return ! ! firstChild . __vnode . transition ? $el : firstChild ;
156- } ,
157-
158126 realList ( ) {
159127 return this . list ? this . list : this . modelValue ;
160128 }
@@ -174,58 +142,22 @@ const draggableComponent = defineComponent({
174142 } ,
175143
176144 methods : {
177- getIsFunctional ( ) {
178- return typeof this . mainNode . type === "function" ;
179- } ,
180-
181145 updateOptions ( newOptionValue ) {
182146 const { _sortable } = this ;
183147 getValidSortableEntries ( newOptionValue ) . forEach ( ( [ key , value ] ) => {
184148 _sortable . option ( key , value ) ;
185149 } ) ;
186150 } ,
187151
188- getChildrenNodes ( ) {
189- const {
190- componentStructure : {
191- noneFunctional,
192- transitionMode,
193- nodes : { default : defaultNodes }
194- }
195- } = this ;
196- if ( noneFunctional ) {
197- //TODO check
198- return defaultNodes [ 0 ] . children ;
199- //return this.$children[0].$slots.default();
200- }
201-
202- if ( transitionMode ) {
203- const [ { children } ] = defaultNodes ;
204- if ( Array . isArray ( children ) ) {
205- return children ;
206- }
207- return [ ...this . rootContainer . children ]
208- . map ( c => c . __vnode )
209- . filter ( node => ! ! node . transition ) ;
210- }
211-
212- return defaultNodes . length === 1 && defaultNodes [ 0 ] . el . nodeType === 3
213- ? defaultNodes [ 0 ] . children
214- : defaultNodes ;
215- } ,
216-
217152 computeIndexes ( ) {
218153 nextTick ( ( ) => {
219- this . visibleIndexes = computeIndexes (
220- this . getChildrenNodes ( ) ,
221- this . rootContainer . children ,
222- this . componentStructure
223- ) ;
154+ this . visibleIndexes = this . componentStructure . computeIndexes ( ) ;
224155 } ) ;
225156 } ,
226157
227158 getUnderlyingVm ( htmlElement ) {
228- const index = computeVmIndex ( this . getChildrenNodes ( ) , htmlElement ) ;
159+ const childrenNodes = this . componentStructure . getChildrenNodes ( ) ;
160+ const index = computeVmIndex ( childrenNodes , htmlElement ) ;
229161 if ( index === - 1 ) {
230162 //Edge case during move callback: related element might be
231163 //an element different from collection
@@ -307,7 +239,10 @@ const draggableComponent = defineComponent({
307239 } ,
308240
309241 onDragRemove ( evt ) {
310- insertNodeAt ( this . rootContainer , evt . item , evt . oldIndex ) ;
242+ const {
243+ componentStructure : { rootContainer }
244+ } = this ;
245+ insertNodeAt ( rootContainer , evt . item , evt . oldIndex ) ;
311246 if ( evt . pullMode === "clone" ) {
312247 removeNode ( evt . clone ) ;
313248 return ;
0 commit comments