6
6
Delete ,
7
7
EditorAction ,
8
8
EditorActionEvent ,
9
+ getReference ,
9
10
isCreate ,
10
11
isDelete ,
11
12
isMove ,
@@ -17,6 +18,7 @@ import {
17
18
newLogEvent ,
18
19
newValidateEvent ,
19
20
OpenDocEvent ,
21
+ SCLTag ,
20
22
SimpleAction ,
21
23
Update ,
22
24
} from './foundation.js' ;
@@ -72,6 +74,12 @@ export function Editing<TBase extends LitElementConstructor>(Base: TBase) {
72
74
private onCreate ( action : Create ) {
73
75
if ( ! this . checkCreateValidity ( action ) ) return false ;
74
76
77
+ if ( action . new . reference === undefined )
78
+ action . new . reference = getReference (
79
+ action . new . parent ,
80
+ < SCLTag > action . new . element . tagName
81
+ ) ;
82
+
75
83
action . new . parent . insertBefore ( action . new . element , action . new . reference ) ;
76
84
return true ;
77
85
}
@@ -89,6 +97,9 @@ export function Editing<TBase extends LitElementConstructor>(Base: TBase) {
89
97
}
90
98
91
99
private onDelete ( action : Delete ) {
100
+ if ( ! action . old . reference )
101
+ action . old . reference = action . old . element . nextSibling ;
102
+
92
103
action . old . element . remove ( ) ;
93
104
return true ;
94
105
}
@@ -138,6 +149,15 @@ export function Editing<TBase extends LitElementConstructor>(Base: TBase) {
138
149
private onMove ( action : Move ) {
139
150
if ( ! this . checkMoveValidity ( action ) ) return false ;
140
151
152
+ if ( ! action . old . reference )
153
+ action . old . reference = action . old . element . nextSibling ;
154
+
155
+ if ( action . new . reference === undefined )
156
+ action . new . reference = getReference (
157
+ action . new . parent ,
158
+ < SCLTag > action . old . element . tagName
159
+ ) ;
160
+
141
161
action . new . parent . insertBefore ( action . old . element , action . new . reference ) ;
142
162
return true ;
143
163
}
0 commit comments