@@ -24,24 +24,21 @@ export class CarouselOptionPlugin extends Plugin {
24
24
getActions ( ) {
25
25
return {
26
26
addSlide : {
27
- apply : ( { editingElement } ) =>
28
- new Promise ( ( resolve ) => {
29
- resolve ( this . addSlide ( editingElement ) ) ;
30
- } ) ,
27
+ load : ( { editingElement } ) => this . addSlide ( editingElement ) ,
28
+ apply : ( { loadResult : toApply } ) => toApply ( ) ,
31
29
} ,
32
30
slideCarousel : {
33
- apply : async ( { editingElement, direction } ) => {
34
- await this . slide ( direction , editingElement ) ;
35
- } ,
31
+ load : ( { editingElement, direction } ) => this . slide ( direction , editingElement ) ,
32
+ apply : ( { loadResult : toApply } ) => toApply ( ) ,
36
33
} ,
37
34
} ;
38
35
}
39
36
40
- addSlide ( editingElement ) {
37
+ async addSlide ( editingElement ) {
41
38
const activeCarouselItem = editingElement . querySelector ( ".carousel-item.active" ) ;
42
39
this . dependencies . clone . cloneElement ( activeCarouselItem ) ;
43
-
44
- return this . slide ( "next" , editingElement ) ;
40
+ const toApply = await this . slide ( "next" , editingElement ) ;
41
+ return toApply ;
45
42
}
46
43
47
44
/**
@@ -65,28 +62,36 @@ export class CarouselOptionPlugin extends Plugin {
65
62
) ;
66
63
67
64
return new Promise ( ( resolve ) => {
68
- editingElement . addEventListener ( "slid.bs.carousel" , ( ) => {
69
- // slid.bs.carousel is most of the time fired too soon by bootstrap
70
- // since it emulates the transitionEnd with a setTimeout. We wait
71
- // here an extra 20% of the time before retargeting edition, which
72
- // should be enough...
73
- const slideDuration = window . performance . now ( ) - this . slideTimestamp ;
74
- setTimeout ( ( ) => {
75
- // Setting the active indicator manually, as Bootstrap could
76
- // not do it because the `data-bs-slide-to` attribute is not
77
- // here in edit mode anymore.
78
- const activeSlide = editingElement . querySelector ( ".carousel-item.active" ) ;
79
- const indicatorsEl = editingElement . querySelector ( ".carousel-indicators" ) ;
80
- const activeIndex = [ ...activeSlide . parentElement . children ] . indexOf (
81
- activeSlide
82
- ) ;
83
- const activeIndicatorEl = [ ...indicatorsEl . children ] [ activeIndex ] ;
84
- activeIndicatorEl . classList . add ( "active" ) ;
85
- activeIndicatorEl . setAttribute ( "aria-current" , "true" ) ;
86
-
87
- resolve ( ) ;
88
- } , 0.2 * slideDuration ) ;
89
- } ) ;
65
+ editingElement . addEventListener (
66
+ "slid.bs.carousel" ,
67
+ ( ) => {
68
+ // slid.bs.carousel is most of the time fired too soon by bootstrap
69
+ // since it emulates the transitionEnd with a setTimeout. We wait
70
+ // here an extra 20% of the time before retargeting edition, which
71
+ // should be enough...
72
+ const slideDuration = window . performance . now ( ) - this . slideTimestamp ;
73
+ setTimeout ( ( ) => {
74
+ const toApply = ( ) => {
75
+ // Setting the active indicator manually, as Bootstrap could
76
+ // not do it because the `data-bs-slide-to` attribute is not
77
+ // here in edit mode anymore.
78
+ const activeSlide =
79
+ editingElement . querySelector ( ".carousel-item.active" ) ;
80
+ const indicatorsEl =
81
+ editingElement . querySelector ( ".carousel-indicators" ) ;
82
+ const activeIndex = [ ...activeSlide . parentElement . children ] . indexOf (
83
+ activeSlide
84
+ ) ;
85
+ const activeIndicatorEl = [ ...indicatorsEl . children ] [ activeIndex ] ;
86
+ activeIndicatorEl . classList . add ( "active" ) ;
87
+ activeIndicatorEl . setAttribute ( "aria-current" , "true" ) ;
88
+ } ;
89
+
90
+ resolve ( toApply ) ;
91
+ } , 0.2 * slideDuration ) ;
92
+ } ,
93
+ { once : true }
94
+ ) ;
90
95
91
96
// rewrite the jquery interface in carousel.js
92
97
const carouselInstance = window . Carousel . getOrCreateInstance ( editingElement ) ;
0 commit comments