4
4
} from '../../parsers/template'
5
5
6
6
import {
7
+ extend ,
7
8
extractContent ,
8
9
replace ,
9
10
remove ,
@@ -15,60 +16,46 @@ import {
15
16
// instance being stored as `$options._content` during
16
17
// the transclude phase.
17
18
18
- export default {
19
+ // We are exporting two versions, one for named and one
20
+ // for unnamed, because the unnamed slots must be compiled
21
+ // AFTER all named slots have selected their content. So
22
+ // we need to give them different priorities in the compilation
23
+ // process. (See #1965)
19
24
20
- priority : 1750 ,
25
+ export const slot = {
21
26
22
- params : [ 'name' ] ,
27
+ priority : 1750 ,
23
28
24
29
bind ( ) {
25
30
var host = this . vm
26
31
var raw = host . $options . _content
27
- var content
28
32
if ( ! raw ) {
29
33
this . fallback ( )
30
34
return
31
35
}
32
36
var context = host . _context
33
- var slotName = this . params . name
37
+ var slotName = this . params && this . params . name
34
38
if ( ! slotName ) {
35
- // Default content
36
- var self = this
37
- var compileDefaultContent = function ( ) {
38
- var content = extractFragment ( raw . childNodes , raw , true )
39
- if ( content . hasChildNodes ( ) ) {
40
- self . compile ( content , context , host )
41
- } else {
42
- self . fallback ( )
43
- }
44
- }
45
- if ( ! host . _isCompiled ) {
46
- // defer until the end of instance compilation,
47
- // because the default outlet must wait until all
48
- // other possible outlets with selectors have picked
49
- // out their contents.
50
- host . $once ( 'hook:compiled' , compileDefaultContent )
51
- } else {
52
- compileDefaultContent ( )
53
- }
39
+ // Default slot
40
+ this . tryCompile ( extractFragment ( raw . childNodes , raw , true ) , context , host )
54
41
} else {
42
+ // Named slot
55
43
var selector = '[slot="' + slotName + '"]'
56
44
var nodes = raw . querySelectorAll ( selector )
57
45
if ( nodes . length ) {
58
- content = extractFragment ( nodes , raw )
59
- if ( content . hasChildNodes ( ) ) {
60
- this . compile ( content , context , host )
61
- } else {
62
- this . fallback ( )
63
- }
46
+ this . tryCompile ( extractFragment ( nodes , raw ) , context , host )
64
47
} else {
65
48
this . fallback ( )
66
49
}
67
50
}
68
51
} ,
69
52
70
- fallback ( ) {
71
- this . compile ( extractContent ( this . el , true ) , this . vm )
53
+ tryCompile ( content , context , host ) {
54
+ if ( content . hasChildNodes ( ) ) {
55
+ this . compile ( content , context , host )
56
+ } else {
57
+ this . fallback ( )
58
+ }
72
59
} ,
73
60
74
61
compile ( content , context , host ) {
@@ -87,13 +74,22 @@ export default {
87
74
}
88
75
} ,
89
76
77
+ fallback ( ) {
78
+ this . compile ( extractContent ( this . el , true ) , this . vm )
79
+ } ,
80
+
90
81
unbind ( ) {
91
82
if ( this . unlink ) {
92
83
this . unlink ( )
93
84
}
94
85
}
95
86
}
96
87
88
+ export const namedSlot = extend ( extend ( { } , slot ) , {
89
+ priority : slot . priority + 1 ,
90
+ params : [ 'name' ]
91
+ } )
92
+
97
93
/**
98
94
* Extract qualified content nodes from a node list.
99
95
*
0 commit comments