1
1
import * as ko from "knockout" ;
2
- import { SurveyHelper , editorLocalization } from ' ../entries' ;
2
+ import { SurveyHelper , editorLocalization } from " ../entries" ;
3
3
import "./pages-editor.scss" ;
4
4
import { PagesEditor } from "../pages-editor" ;
5
5
import { StylesManager } from "../stylesmanager" ;
@@ -18,9 +18,7 @@ export class PagesEditorViewModel {
18
18
".svd-pages"
19
19
) ;
20
20
if ( ! ! pagesElement ) {
21
- this . hasScroller (
22
- pagesElement . scrollWidth > pagesElement . offsetWidth
23
- ) ;
21
+ this . hasScroller ( pagesElement . scrollWidth > pagesElement . offsetWidth ) ;
24
22
}
25
23
} , 100 ) ;
26
24
@@ -55,7 +53,7 @@ export class PagesEditorViewModel {
55
53
pagesElement . offsetLeft -
56
54
pagesElement . offsetWidth / 2 ;
57
55
this . updateMenuPosition ( ) ;
58
- }
56
+ } ;
59
57
60
58
onWheel ( model , event ) {
61
59
var pagesElement = model . element . querySelector ( ".svd-pages" ) ;
@@ -86,7 +84,9 @@ export class PagesEditorViewModel {
86
84
87
85
getPageClass = ( page ) => {
88
86
var result =
89
- page === this . model . selectedPage ( ) ? "svd_selected_page svd-light-bg-color" : "" ;
87
+ page === this . model . selectedPage ( )
88
+ ? "svd_selected_page svd-light-bg-color"
89
+ : "" ;
90
90
91
91
if ( this . model . pages . indexOf ( page ) !== this . model . pages . length - 1 ) {
92
92
result += " svd-border-right-none" ;
@@ -96,7 +96,8 @@ export class PagesEditorViewModel {
96
96
} ;
97
97
98
98
getPageMenuIconClass = ( page ) => {
99
- var baseIconName = StylesManager . currentTheme ( ) === "modern" ? "dots" : "gear" ;
99
+ var baseIconName =
100
+ StylesManager . currentTheme ( ) === "modern" ? "dots" : "gear" ;
100
101
return page === this . model . selectedPage ( ) && this . model . isActive ( )
101
102
? "icon-" + baseIconName + "active"
102
103
: "icon-" + baseIconName ;
@@ -110,12 +111,14 @@ export class PagesEditorViewModel {
110
111
} ;
111
112
112
113
public movingPage = null ;
114
+ private movedFrom : number = - 1 ;
113
115
get sortableOptions ( ) {
114
116
return {
115
117
handle : ".svd-page-name" ,
116
118
animation : 150 ,
117
119
onStart : ( ) => {
118
120
this . movingPage = null ;
121
+ this . movedFrom = - 1 ;
119
122
this . model . creator . undoRedoManager . startTransaction (
120
123
"pages drag drop transaction"
121
124
) ;
@@ -126,12 +129,17 @@ export class PagesEditorViewModel {
126
129
this . model . blockPagesRebuilt ( false ) ;
127
130
this . model . creator . undoRedoManager . stopTransaction ( ) ;
128
131
if ( ! ! this . movingPage ) {
129
- this . model . selectedPage ( this . movingPage ) ;
132
+ this . model . movePage ( this . movingPage , this . movedFrom ) ;
130
133
}
131
134
} ,
132
135
onUpdate : ( evt , itemV ) => {
133
136
this . movingPage = itemV ;
134
- if ( SurveyHelper . moveItemInArray ( this . model . pages , itemV , evt . newIndex ) ) {
137
+ if ( this . movedFrom < 0 ) {
138
+ this . movedFrom = this . model . pages . indexOf ( this . movingPage ) ;
139
+ }
140
+ if (
141
+ SurveyHelper . moveItemInArray ( this . model . pages , itemV , evt . newIndex )
142
+ ) {
135
143
// Remove sortables "unbound" element
136
144
evt . item . parentNode . removeChild ( evt . item ) ;
137
145
}
0 commit comments