@@ -54,16 +54,17 @@ export class XmlPatcher implements patch.IPatcher {
5454 return false ;
5555 }
5656
57+ notsupported ( patch : patch . IPatch ) : boolean {
58+ console . log ( "operation not supported: " + patch . op + " " + patch . path ) ;
59+ return false ;
60+ }
61+
5762 remove ( xml : Document , select : any , patch : patch . IPatch ) : boolean {
5863 var arrayOperation = this . detectArrayOperation ( patch . path ) ;
59- console . log ( JSON . stringify ( arrayOperation ) ) ;
6064 if ( arrayOperation . isArrayOperation ) {
6165 if ( arrayOperation . append ) {
6266 var node = < SVGSVGElement > select ( arrayOperation . path , xml , true ) ;
6367 node . removeChild ( node . lastChild ) ;
64- console . log ( 'arrayOperation.path' ) ;
65- console . log ( node ) ;
66- console . log ( 'remove lastchild' ) ;
6768 return true ;
6869 } else {
6970 var node = < SVGSVGElement > select ( arrayOperation . path , xml , true ) ;
@@ -88,14 +89,20 @@ export class XmlPatcher implements patch.IPatcher {
8889 }
8990
9091 move ( xml : Document , select : any , patch : patch . IPatch ) : boolean {
91- var fromNode = < SVGSVGElement > select ( patch . from , xml , true ) ;
92- var toNode = < SVGSVGElement > select ( patch . path , xml , true ) ;
93- if ( fromNode ) {
94- patch . value = fromNode . textContent ;
95- this . remove ( xml , select , { op : 'remove' , path : patch . from } ) ;
96- return this . replace ( xml , select , patch ) ;
92+ var arrayOperation = this . detectArrayOperation ( patch . path ) ;
93+ var arrayOperationFrom = this . detectArrayOperation ( patch . from ) ;
94+ if ( arrayOperation . isArrayOperation || arrayOperationFrom . isArrayOperation ) {
95+ return this . notsupported ( patch ) ;
9796 } else {
98- return this . notfound ( patch ) ;
97+ var fromNode = < SVGSVGElement > select ( patch . from , xml , true ) ;
98+ var toNode = < SVGSVGElement > select ( patch . path , xml , true ) ;
99+ if ( fromNode ) {
100+ patch . value = fromNode . textContent ;
101+ this . remove ( xml , select , { op : 'remove' , path : patch . from } ) ;
102+ return this . replace ( xml , select , patch ) ;
103+ } else {
104+ return this . notfound ( patch ) ;
105+ }
99106 }
100107 }
101108
@@ -112,18 +119,16 @@ export class XmlPatcher implements patch.IPatcher {
112119
113120 add ( xml : Document , select : any , patch : patch . IPatch ) : boolean {
114121 var arrayOperation = this . detectArrayOperation ( patch . path ) ;
115- console . log ( JSON . stringify ( arrayOperation ) ) ;
116122 if ( arrayOperation . isArrayOperation ) {
117123 if ( arrayOperation . append ) {
118124 var node = < SVGSVGElement > select ( arrayOperation . path , xml , true ) ;
119- var newNode = xml . createElement ( patch . value ) ;
125+ var newNode = < HTMLElement > xml . createElement ( patch . value ) ;
120126 node . appendChild ( newNode ) ;
121127 return true ;
122128 } else {
123129 var node = < SVGSVGElement > select ( arrayOperation . path , xml , true ) ;
124- var newNode = xml . createElement ( patch . value ) ;
130+ var newNode = < HTMLElement > xml . createElement ( patch . value ) ;
125131 node . insertBefore ( newNode , node . childNodes [ arrayOperation . index ] )
126- node . appendChild ( newNode ) ;
127132 return true ;
128133 }
129134 }
@@ -154,18 +159,28 @@ export class XmlPatcher implements patch.IPatcher {
154159 }
155160
156161 replace ( xml : Document , select : any , patch : patch . IPatch ) : boolean {
157- var node = < SVGSVGElement > select ( patch . path , xml , true ) ;
158- if ( node ) {
159- var parentPath = this . getParentPath ( patch . path ) ;
160- var parentNode = < SVGSVGElement > select ( parentPath . path , xml , true ) ;
161- if ( parentPath . isAttribute ) {
162- parentNode . setAttribute ( parentPath . nodeName , patch . value ) ;
163- } else {
164- node . textContent = patch . value ;
165- }
162+ var arrayOperation = this . detectArrayOperation ( patch . path ) ;
163+ if ( arrayOperation . isArrayOperation ) {
164+ var node = < SVGSVGElement > select ( arrayOperation . path , xml , true ) ;
165+ var childNode = node . childNodes [ arrayOperation . index ] ;
166+ var newNode = < HTMLElement > xml . createElement ( patch . value ) ;
167+ node . insertBefore ( newNode , childNode )
168+ node . removeChild ( childNode ) ;
166169 return true ;
167170 } else {
168- return this . add ( xml , select , patch ) ;
171+ var node = < SVGSVGElement > select ( patch . path , xml , true ) ;
172+ if ( node ) {
173+ var parentPath = this . getParentPath ( patch . path ) ;
174+ var parentNode = < SVGSVGElement > select ( parentPath . path , xml , true ) ;
175+ if ( parentPath . isAttribute ) {
176+ parentNode . setAttribute ( parentPath . nodeName , patch . value ) ;
177+ } else {
178+ node . textContent = patch . value ;
179+ }
180+ return true ;
181+ } else {
182+ return this . add ( xml , select , patch ) ;
183+ }
169184 }
170185 }
171186
0 commit comments